nisping.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
*
* This program will ping a server in an attempt to get it to resynchronize
* with the master NIS+ server. It also performs database checkpoints.
*/
#include <stdio.h>
extern bool_t xdr_nis_name();
extern bool_t xdr_cp_result();
#define ROOT_OBJ "root.object"
extern nis_name __nis_local_root();
#define NIS_PROG 100300
#define NIS_VERSION 3
#define NIS_CPTIME 18
#define NIS_CHECKPOINT 19
/*
* Return values (from the man page):
* -1 No servers were contacted, or the server
* specified by the -H switch could not be con-
* tacted.
*
* 0 Success.
*
* 1 Some, but not all, servers were successfully
* contacted.
*/
#define PING_SUCCESS 0
#define PING_SOME 1
#define PING_NONE -1
/*
* nis_checkpoint()
*
* This function will ask the indicated replicate to checkpoint itself
*/
static nis_error
{
/* If we can't contact it, return the safe answer */
if (! clnt) {
return (NIS_NAMEUNREACHABLE);
}
if (status != RPC_SUCCESS) {
printf("nisping: RPC error on server %s, error %s\n",
}
}
/*
* nis_cptime()
*
* This function will ask the indicated replicate for the last
* update it has seen to the given directory.
*/
static nis_error
{
/* If we can't contact it, return the safe answer */
if (! clnt) {
*utime = 0;
return (NIS_RPCERROR);
}
/* Only wait 10 seconds */
return (res);
}
static void
usage(s)
char *s;
{
}
static
int
{
return (1);
return (0);
}
extern int optind;
extern char *optarg;
int argc;
char *argv[];
{
int c;
int checkpoint_all = 0;
int chkpnt = 0;
int root_object = 0;
int tries = 0;
int successes = 0;
switch (c) {
case 'f':
force = 1;
break;
case 'u':
uponly = 1;
break;
case 'C' :
chkpnt = 1;
break;
case 'H' :
break;
case 'r' :
root_object = 1;
break;
case 'a' :
checkpoint_all = 1;
break;
default :
}
}
if (root_object)
} else
if (chkpnt == 0 && checkpoint_all)
if (root_object) {
if (chkpnt) {
"%s: no need to checkpoint root object.\n",
argv[0]);
}
domain = __nis_local_root();
if (domain == 0) {
"%s: cannot get name of root directory.\n",
argv[0]);
}
}
if (!uponly)
flag += MASTER_ONLY;
}
}
if (root_object)
else
if (host) { /* if a specific host has been specified */
for (i = 0; i < ns; ++i) {
break;
}
if (i == ns) {
}
}
/* set real target name for root object. */
if (root_object)
}
if (chkpnt)
printf("Checkpointing %s serving directory \"%s\" :\n",
else if (uponly)
else
printf("Pinging %s serving \"%s\" :\n",
if (status != NIS_SUCCESS)
printf("\tUnable to fetch update time from master server.\n");
else if (!updtm)
printf("\tNo last update time available for \"%s\".\n",
obj_desc);
else
printf("\tLast update occurred at %s\n",
/*
* Need to increment success count if -H <master> or only 1 server.
*/
(status == NIS_SUCCESS)) {
tries++;
successes++;
}
for (i = 0; i < ns; i++) {
continue;
if ((i == 0) && ! chkpnt)
continue;
if (chkpnt) {
if (checkpoint_all)
else
if (status != NIS_SUCCESS) {
printf("checkpoint failed : %s\n",
} else
printf("checkpoint scheduled on \"%s\".\n",
} else {
if (status == NIS_SUCCESS) {
if (!reptm)
"\tNo last update available for \"%s\".\n",
obj_desc);
else
printf("\tLast Update seen was %s\n",
printf("\tPinging ... \"%s\"\n",
}
} else
printf("\tUnavailable.\n\n");
}
tries++;
}
if (successes == 0)
}