1996-01-12 07:03:33 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1995
|
|
|
|
* Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Bill Paul.
|
|
|
|
* 4. Neither the name of the author nor the names of any co-contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2003-05-03 21:06:42 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
1997-11-03 07:53:44 +00:00
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <signal.h>
|
1996-01-12 07:03:33 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2006-08-13 19:57:32 +00:00
|
|
|
#include <strings.h>
|
1996-01-12 07:03:33 +00:00
|
|
|
#include <time.h>
|
1997-11-03 07:53:44 +00:00
|
|
|
#include <unistd.h>
|
1996-01-12 07:03:33 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <rpc/rpc.h>
|
|
|
|
#include <rpc/clnt.h>
|
|
|
|
#include <rpc/pmap_clnt.h>
|
|
|
|
#include <rpcsvc/yp.h>
|
|
|
|
#include <rpcsvc/ypclnt.h>
|
|
|
|
#include "ypxfr_extern.h"
|
|
|
|
#include "yppush_extern.h"
|
|
|
|
|
|
|
|
char *progname = "yppush";
|
|
|
|
int debug = 1;
|
|
|
|
int _rpcpmstart = 0;
|
|
|
|
char *yp_dir = _PATH_YP;
|
|
|
|
|
2015-07-28 02:32:40 +00:00
|
|
|
static char *yppush_mapname = NULL; /* Map to transfer. */
|
|
|
|
static char *yppush_domain = NULL; /* Domain in which map resides. */
|
|
|
|
static char *yppush_master = NULL; /* Master NIS server for said domain. */
|
|
|
|
static int skip_master = 0; /* Do not attempt to push map to master. */
|
|
|
|
static int verbose = 0; /* Toggle verbose mode. */
|
|
|
|
static unsigned long yppush_transid = 0;
|
|
|
|
static int yppush_timeout = 80; /* Default timeout. */
|
|
|
|
static int yppush_jobs = 1; /* Number of allowed concurrent jobs. */
|
|
|
|
static int yppush_running_jobs = 0; /* Number of currently running jobs. */
|
1996-01-12 07:03:33 +00:00
|
|
|
|
|
|
|
/* Structure for holding information about a running job. */
|
|
|
|
struct jobs {
|
|
|
|
unsigned long tid;
|
|
|
|
int port;
|
|
|
|
ypxfrstat stat;
|
|
|
|
unsigned long prognum;
|
|
|
|
char *server;
|
|
|
|
char *map;
|
|
|
|
int polled;
|
|
|
|
struct jobs *next;
|
|
|
|
};
|
|
|
|
|
2015-07-28 02:32:40 +00:00
|
|
|
static struct jobs *yppush_joblist; /* Linked list of running jobs. */
|
2006-08-16 12:58:41 +00:00
|
|
|
static int yppush_svc_run(int);
|
|
|
|
|
1996-01-12 07:03:33 +00:00
|
|
|
/*
|
|
|
|
* Local error messages.
|
|
|
|
*/
|
2002-04-16 22:08:35 +00:00
|
|
|
static const char *
|
2002-02-06 15:26:07 +00:00
|
|
|
yppusherr_string(int err)
|
1996-01-12 07:03:33 +00:00
|
|
|
{
|
2002-02-06 13:30:31 +00:00
|
|
|
switch (err) {
|
2002-04-16 22:08:35 +00:00
|
|
|
case YPPUSH_TIMEDOUT:
|
|
|
|
return("transfer or callback timed out");
|
|
|
|
case YPPUSH_YPSERV:
|
|
|
|
return("failed to contact ypserv");
|
|
|
|
case YPPUSH_NOHOST:
|
|
|
|
return("no such host");
|
|
|
|
case YPPUSH_PMAP:
|
|
|
|
return("portmapper failure");
|
|
|
|
default:
|
|
|
|
return("unknown error code");
|
1996-01-12 07:03:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Report state of a job.
|
|
|
|
*/
|
2002-02-06 15:26:07 +00:00
|
|
|
static int
|
|
|
|
yppush_show_status(ypxfrstat status, unsigned long tid)
|
1996-01-12 07:03:33 +00:00
|
|
|
{
|
|
|
|
struct jobs *job;
|
|
|
|
|
|
|
|
job = yppush_joblist;
|
|
|
|
|
2006-08-16 12:58:41 +00:00
|
|
|
while (job != NULL) {
|
1996-01-12 07:03:33 +00:00
|
|
|
if (job->tid == tid)
|
|
|
|
break;
|
|
|
|
job = job->next;
|
|
|
|
}
|
|
|
|
|
2006-08-16 12:58:41 +00:00
|
|
|
if (job == NULL) {
|
|
|
|
yp_error("warning: received callback with invalid transaction ID: %lu",
|
|
|
|
tid);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1996-01-12 07:03:33 +00:00
|
|
|
if (job->polled) {
|
2006-08-16 12:58:41 +00:00
|
|
|
yp_error("warning: received callback with duplicate transaction ID: %lu",
|
|
|
|
tid);
|
|
|
|
return (0);
|
1996-01-12 07:03:33 +00:00
|
|
|
}
|
|
|
|
|
2006-08-16 12:58:41 +00:00
|
|
|
if (verbose > 1) {
|
1997-11-03 07:53:44 +00:00
|
|
|
yp_error("checking return status: transaction ID: %lu",
|
1996-01-12 07:03:33 +00:00
|
|
|
job->tid);
|
2006-08-16 12:58:41 +00:00
|
|
|
}
|
|
|
|
|
2015-05-31 20:45:35 +00:00
|
|
|
if (status != YPXFR_SUCC || verbose) {
|
1997-11-03 07:53:44 +00:00
|
|
|
yp_error("transfer of map %s to server %s %s",
|
2015-05-31 20:45:35 +00:00
|
|
|
job->map, job->server, status == YPXFR_SUCC ?
|
1996-01-12 07:03:33 +00:00
|
|
|
"succeeded" : "failed");
|
2015-05-31 20:45:35 +00:00
|
|
|
yp_error("status returned by ypxfr: %s", status > YPXFR_AGE ?
|
2002-02-06 13:30:31 +00:00
|
|
|
yppusherr_string(status) :
|
1996-01-12 07:03:33 +00:00
|
|
|
ypxfrerr_string(status));
|
|
|
|
}
|
|
|
|
|
|
|
|
job->polled = 1;
|
|
|
|
|
|
|
|
svc_unregister(job->prognum, 1);
|
2002-02-06 13:30:31 +00:00
|
|
|
|
1996-01-12 07:03:33 +00:00
|
|
|
yppush_running_jobs--;
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Exit routine. */
|
2002-02-06 15:26:07 +00:00
|
|
|
static void
|
|
|
|
yppush_exit(int now)
|
1996-01-12 07:03:33 +00:00
|
|
|
{
|
|
|
|
struct jobs *jptr;
|
1996-01-31 15:15:47 +00:00
|
|
|
int still_pending = 1;
|
1996-01-12 07:03:33 +00:00
|
|
|
|
|
|
|
/* Let all the information trickle in. */
|
2002-02-06 13:30:31 +00:00
|
|
|
while (!now && still_pending) {
|
1996-01-12 07:03:33 +00:00
|
|
|
jptr = yppush_joblist;
|
|
|
|
still_pending = 0;
|
|
|
|
while (jptr) {
|
|
|
|
if (jptr->polled == 0) {
|
|
|
|
still_pending++;
|
|
|
|
if (verbose > 1)
|
|
|
|
yp_error("%s has not responded",
|
|
|
|
jptr->server);
|
|
|
|
} else {
|
|
|
|
if (verbose > 1)
|
|
|
|
yp_error("%s has responded",
|
|
|
|
jptr->server);
|
|
|
|
}
|
|
|
|
jptr = jptr->next;
|
|
|
|
}
|
|
|
|
if (still_pending) {
|
|
|
|
if (verbose > 1)
|
|
|
|
yp_error("%d transfer%sstill pending",
|
|
|
|
still_pending,
|
|
|
|
still_pending > 1 ? "s " : " ");
|
2006-08-16 12:58:41 +00:00
|
|
|
if (yppush_svc_run (YPPUSH_RESPONSE_TIMEOUT) == 0) {
|
1996-01-31 15:15:47 +00:00
|
|
|
yp_error("timed out");
|
|
|
|
now = 1;
|
|
|
|
}
|
1996-01-12 07:03:33 +00:00
|
|
|
} else {
|
|
|
|
if (verbose)
|
|
|
|
yp_error("all transfers complete");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* All stats collected and reported -- kill all the stragglers. */
|
|
|
|
jptr = yppush_joblist;
|
2002-02-06 13:30:31 +00:00
|
|
|
while (jptr) {
|
1996-01-12 07:03:33 +00:00
|
|
|
if (!jptr->polled)
|
|
|
|
yp_error("warning: exiting with transfer \
|
1997-11-03 07:53:44 +00:00
|
|
|
to %s (transid = %lu) still pending", jptr->server, jptr->tid);
|
1996-01-12 07:03:33 +00:00
|
|
|
svc_unregister(jptr->prognum, 1);
|
|
|
|
jptr = jptr->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handler for 'normal' signals.
|
|
|
|
*/
|
|
|
|
|
2002-02-06 15:26:07 +00:00
|
|
|
static void
|
|
|
|
handler(int sig)
|
1996-01-12 07:03:33 +00:00
|
|
|
{
|
2006-08-16 12:58:41 +00:00
|
|
|
yppush_exit (1);
|
1996-01-12 07:03:33 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Dispatch loop for callback RPC services.
|
2006-08-16 12:58:41 +00:00
|
|
|
* Return value:
|
|
|
|
* -1 error
|
|
|
|
* 0 timeout
|
|
|
|
* >0 request serviced
|
1996-01-12 07:03:33 +00:00
|
|
|
*/
|
2006-08-16 12:58:41 +00:00
|
|
|
static int
|
|
|
|
yppush_svc_run(int timeout_secs)
|
1996-01-12 07:03:33 +00:00
|
|
|
{
|
2006-08-16 12:58:41 +00:00
|
|
|
int rc;
|
1996-01-12 07:03:33 +00:00
|
|
|
fd_set readfds;
|
|
|
|
struct timeval timeout;
|
|
|
|
|
|
|
|
timeout.tv_usec = 0;
|
2006-08-16 12:58:41 +00:00
|
|
|
timeout.tv_sec = timeout_secs;
|
1996-01-12 07:03:33 +00:00
|
|
|
|
|
|
|
retry:
|
|
|
|
readfds = svc_fdset;
|
2006-08-16 12:58:41 +00:00
|
|
|
rc = select(svc_maxfd + 1, &readfds, NULL, NULL, &timeout);
|
|
|
|
switch (rc) {
|
1996-01-12 07:03:33 +00:00
|
|
|
case -1:
|
|
|
|
if (errno == EINTR)
|
|
|
|
goto retry;
|
|
|
|
yp_error("select failed: %s", strerror(errno));
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
yp_error("select() timed out");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
svc_getreqset(&readfds);
|
|
|
|
break;
|
|
|
|
}
|
2006-08-16 12:58:41 +00:00
|
|
|
return rc;
|
1996-01-12 07:03:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1996-01-31 15:15:47 +00:00
|
|
|
* RPC service routines for callbacks.
|
1996-01-12 07:03:33 +00:00
|
|
|
*/
|
|
|
|
void *
|
|
|
|
yppushproc_null_1_svc(void *argp, struct svc_req *rqstp)
|
|
|
|
{
|
|
|
|
static char * result;
|
|
|
|
/* Do nothing -- RPC conventions call for all a null proc. */
|
|
|
|
return((void *) &result);
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
yppushproc_xfrresp_1_svc(yppushresp_xfr *argp, struct svc_req *rqstp)
|
|
|
|
{
|
|
|
|
static char * result;
|
|
|
|
yppush_show_status(argp->status, argp->transid);
|
|
|
|
return((void *) &result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Transmit a YPPROC_XFR request to ypserv.
|
2002-02-06 13:30:31 +00:00
|
|
|
*/
|
2002-02-06 15:26:07 +00:00
|
|
|
static int
|
|
|
|
yppush_send_xfr(struct jobs *job)
|
1996-01-12 07:03:33 +00:00
|
|
|
{
|
|
|
|
ypreq_xfr req;
|
|
|
|
/* ypresp_xfr *resp; */
|
|
|
|
DBT key, data;
|
|
|
|
CLIENT *clnt;
|
|
|
|
struct rpc_err err;
|
|
|
|
struct timeval timeout;
|
|
|
|
|
|
|
|
timeout.tv_usec = 0;
|
|
|
|
timeout.tv_sec = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The ypreq_xfr structure has a member of type map_parms,
|
|
|
|
* which seems to require the order number of the map.
|
|
|
|
* It isn't actually used at the other end (at least the
|
|
|
|
* FreeBSD ypserv doesn't use it) but we fill it in here
|
|
|
|
* for the sake of completeness.
|
|
|
|
*/
|
|
|
|
key.data = "YP_LAST_MODIFIED";
|
|
|
|
key.size = sizeof ("YP_LAST_MODIFIED") - 1;
|
|
|
|
|
|
|
|
if (yp_get_record(yppush_domain, yppush_mapname, &key, &data,
|
|
|
|
1) != YP_TRUE) {
|
|
|
|
yp_error("failed to read order number from %s: %s: %s",
|
|
|
|
yppush_mapname, yperr_string(yp_errno),
|
|
|
|
strerror(errno));
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fill in the request arguments */
|
|
|
|
req.map_parms.ordernum = atoi(data.data);
|
|
|
|
req.map_parms.domain = yppush_domain;
|
|
|
|
req.map_parms.peer = yppush_master;
|
|
|
|
req.map_parms.map = job->map;
|
|
|
|
req.transid = job->tid;
|
|
|
|
req.prog = job->prognum;
|
|
|
|
req.port = job->port;
|
|
|
|
|
|
|
|
/* Get a handle to the remote ypserv. */
|
|
|
|
if ((clnt = clnt_create(job->server, YPPROG, YPVERS, "udp")) == NULL) {
|
|
|
|
yp_error("%s: %s",job->server,clnt_spcreateerror("couldn't \
|
|
|
|
create udp handle to NIS server"));
|
2002-02-06 13:30:31 +00:00
|
|
|
switch (rpc_createerr.cf_stat) {
|
1996-01-12 07:03:33 +00:00
|
|
|
case RPC_UNKNOWNHOST:
|
|
|
|
job->stat = YPPUSH_NOHOST;
|
|
|
|
break;
|
|
|
|
case RPC_PMAPFAILURE:
|
|
|
|
job->stat = YPPUSH_PMAP;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
job->stat = YPPUSH_RPC;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reduce timeout to nothing since we may not
|
|
|
|
* get a response from ypserv and we don't want to block.
|
|
|
|
*/
|
|
|
|
if (clnt_control(clnt, CLSET_TIMEOUT, (char *)&timeout) == FALSE)
|
|
|
|
yp_error("failed to set timeout on ypproc_xfr call");
|
|
|
|
|
|
|
|
/* Invoke the ypproc_xfr service. */
|
|
|
|
if (ypproc_xfr_2(&req, clnt) == NULL) {
|
|
|
|
clnt_geterr(clnt, &err);
|
|
|
|
if (err.re_status != RPC_SUCCESS &&
|
|
|
|
err.re_status != RPC_TIMEDOUT) {
|
|
|
|
yp_error("%s: %s", job->server, clnt_sperror(clnt,
|
|
|
|
"yp_xfr failed"));
|
|
|
|
job->stat = YPPUSH_YPSERV;
|
|
|
|
clnt_destroy(clnt);
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
clnt_destroy(clnt);
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Main driver function. Register the callback service, add the transfer
|
|
|
|
* request to the internal list, send the YPPROC_XFR request to ypserv
|
|
|
|
* do other magic things.
|
|
|
|
*/
|
2015-05-31 20:45:35 +00:00
|
|
|
static int
|
2002-02-06 15:26:07 +00:00
|
|
|
yp_push(char *server, char *map, unsigned long tid)
|
1996-01-12 07:03:33 +00:00
|
|
|
{
|
|
|
|
unsigned long prognum;
|
|
|
|
int sock = RPC_ANYSOCK;
|
|
|
|
SVCXPRT *xprt;
|
|
|
|
struct jobs *job;
|
|
|
|
|
2006-08-16 12:58:41 +00:00
|
|
|
/* Register the job in our linked list of jobs. */
|
|
|
|
|
|
|
|
/* First allocate job structure */
|
|
|
|
if ((job = (struct jobs *)malloc(sizeof (struct jobs))) == NULL) {
|
|
|
|
yp_error("malloc failed");
|
|
|
|
yppush_exit (1);
|
|
|
|
}
|
|
|
|
|
1996-01-12 07:03:33 +00:00
|
|
|
/*
|
2006-08-16 12:58:41 +00:00
|
|
|
* Register the callback service on the first free transient
|
|
|
|
* program number.
|
1996-01-12 07:03:33 +00:00
|
|
|
*/
|
|
|
|
xprt = svcudp_create(sock);
|
1996-04-29 05:24:26 +00:00
|
|
|
for (prognum = 0x40000000; prognum < 0x5FFFFFFF; prognum++) {
|
1996-01-12 07:03:33 +00:00
|
|
|
if (svc_register(xprt, prognum, 1,
|
|
|
|
yppush_xfrrespprog_1, IPPROTO_UDP) == TRUE)
|
|
|
|
break;
|
|
|
|
}
|
2006-08-16 12:58:41 +00:00
|
|
|
if (prognum == 0x5FFFFFFF) {
|
|
|
|
yp_error ("can't register yppush_xfrrespprog_1");
|
|
|
|
yppush_exit (1);
|
1996-01-12 07:03:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the info for this job. */
|
|
|
|
job->stat = 0;
|
|
|
|
job->tid = tid;
|
|
|
|
job->port = xprt->xp_port;
|
|
|
|
job->server = strdup(server);
|
|
|
|
job->map = strdup(map);
|
|
|
|
job->prognum = prognum;
|
|
|
|
job->polled = 0;
|
|
|
|
job->next = yppush_joblist;
|
|
|
|
yppush_joblist = job;
|
|
|
|
|
|
|
|
if (verbose) {
|
|
|
|
yp_error("initiating transfer: %s -> %s (transid = %lu)",
|
|
|
|
yppush_mapname, server, tid);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send the XFR request to ypserv. We don't have to wait for
|
2006-08-16 12:58:41 +00:00
|
|
|
* a response here since we handle them asynchronously.
|
1996-01-12 07:03:33 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (yppush_send_xfr(job)){
|
|
|
|
/* Transfer request blew up. */
|
|
|
|
yppush_show_status(job->stat ? job->stat :
|
|
|
|
YPPUSH_YPSERV,job->tid);
|
|
|
|
} else {
|
|
|
|
if (verbose > 1)
|
|
|
|
yp_error("%s has been called", server);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called for each entry in the ypservers map from yp_get_map(), which
|
|
|
|
* is our private yp_all() routine.
|
|
|
|
*/
|
2015-05-31 20:45:35 +00:00
|
|
|
static int
|
2002-02-06 15:26:07 +00:00
|
|
|
yppush_foreach(int status, char *key, int keylen, char *val, int vallen,
|
|
|
|
char *data)
|
1996-01-12 07:03:33 +00:00
|
|
|
{
|
|
|
|
char server[YPMAXRECORD + 2];
|
|
|
|
|
|
|
|
if (status != YP_TRUE)
|
|
|
|
return (status);
|
|
|
|
|
|
|
|
snprintf(server, sizeof(server), "%.*s", vallen, val);
|
2006-08-13 19:57:32 +00:00
|
|
|
if (skip_master && strcasecmp(server, yppush_master) == 0)
|
|
|
|
return (0);
|
1996-01-12 07:03:33 +00:00
|
|
|
|
|
|
|
/*
|
2006-08-16 12:58:41 +00:00
|
|
|
* Restrict the number of concurrent jobs: if yppush_jobs number
|
1996-01-12 07:03:33 +00:00
|
|
|
* of jobs have already been dispatched and are still pending,
|
|
|
|
* wait for one of them to finish so we can reuse its slot.
|
|
|
|
*/
|
2006-08-16 12:58:41 +00:00
|
|
|
while (yppush_running_jobs >= yppush_jobs && (yppush_svc_run (yppush_timeout) > 0))
|
|
|
|
;
|
1996-01-12 07:03:33 +00:00
|
|
|
|
|
|
|
/* Cleared for takeoff: set everything in motion. */
|
2002-04-28 15:18:50 +00:00
|
|
|
if (yp_push(server, yppush_mapname, yppush_transid))
|
1996-01-12 07:03:33 +00:00
|
|
|
return(yp_errno);
|
|
|
|
|
|
|
|
/* Bump the job counter and transaction ID. */
|
|
|
|
yppush_running_jobs++;
|
|
|
|
yppush_transid++;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2015-07-28 02:32:40 +00:00
|
|
|
static void
|
|
|
|
usage()
|
1996-01-12 07:03:33 +00:00
|
|
|
{
|
1997-11-03 07:53:44 +00:00
|
|
|
fprintf (stderr, "%s\n%s\n",
|
|
|
|
"usage: yppush [-d domain] [-t timeout] [-j #parallel jobs] [-h host]",
|
|
|
|
" [-p path] mapname");
|
1996-01-12 07:03:33 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Entry point. (About time!)
|
|
|
|
*/
|
1997-11-03 07:53:44 +00:00
|
|
|
int
|
2002-02-06 15:26:07 +00:00
|
|
|
main(int argc, char *argv[])
|
1996-01-12 07:03:33 +00:00
|
|
|
{
|
|
|
|
int ch;
|
|
|
|
DBT key, data;
|
|
|
|
char myname[MAXHOSTNAMELEN];
|
|
|
|
struct hostlist {
|
|
|
|
char *name;
|
|
|
|
struct hostlist *next;
|
|
|
|
};
|
|
|
|
struct hostlist *yppush_hostlist = NULL;
|
|
|
|
struct hostlist *tmp;
|
|
|
|
|
1997-03-31 05:11:47 +00:00
|
|
|
while ((ch = getopt(argc, argv, "d:j:p:h:t:v")) != -1) {
|
2002-02-06 13:30:31 +00:00
|
|
|
switch (ch) {
|
1996-01-12 07:03:33 +00:00
|
|
|
case 'd':
|
|
|
|
yppush_domain = optarg;
|
|
|
|
break;
|
|
|
|
case 'j':
|
|
|
|
yppush_jobs = atoi(optarg);
|
|
|
|
if (yppush_jobs <= 0)
|
|
|
|
yppush_jobs = 1;
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
yp_dir = optarg;
|
|
|
|
break;
|
|
|
|
case 'h': /* we can handle multiple hosts */
|
|
|
|
if ((tmp = (struct hostlist *)malloc(sizeof(struct hostlist))) == NULL) {
|
1997-11-03 07:53:44 +00:00
|
|
|
yp_error("malloc failed");
|
1996-01-12 07:03:33 +00:00
|
|
|
yppush_exit(1);
|
|
|
|
}
|
|
|
|
tmp->name = strdup(optarg);
|
|
|
|
tmp->next = yppush_hostlist;
|
|
|
|
yppush_hostlist = tmp;
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
yppush_timeout = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
verbose++;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
yppush_mapname = argv[0];
|
|
|
|
|
|
|
|
if (yppush_mapname == NULL) {
|
|
|
|
/* "No guts, no glory." */
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If no domain was specified, try to find the default
|
|
|
|
* domain. If we can't find that, we're doomed and must bail.
|
|
|
|
*/
|
|
|
|
if (yppush_domain == NULL) {
|
|
|
|
char *yppush_check_domain;
|
|
|
|
if (!yp_get_default_domain(&yppush_check_domain) &&
|
|
|
|
!_yp_check(&yppush_check_domain)) {
|
|
|
|
yp_error("no domain specified and NIS not running");
|
|
|
|
usage();
|
|
|
|
} else
|
|
|
|
yp_get_default_domain(&yppush_domain);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check to see that we are the master for this map. */
|
|
|
|
|
|
|
|
if (gethostname ((char *)&myname, sizeof(myname))) {
|
|
|
|
yp_error("failed to get name of local host: %s",
|
|
|
|
strerror(errno));
|
|
|
|
yppush_exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
key.data = "YP_MASTER_NAME";
|
|
|
|
key.size = sizeof("YP_MASTER_NAME") - 1;
|
|
|
|
|
|
|
|
if (yp_get_record(yppush_domain, yppush_mapname,
|
|
|
|
&key, &data, 1) != YP_TRUE) {
|
|
|
|
yp_error("couldn't open %s map: %s", yppush_mapname,
|
|
|
|
strerror(errno));
|
|
|
|
yppush_exit(1);
|
|
|
|
}
|
|
|
|
|
2006-08-13 19:57:32 +00:00
|
|
|
if (strncasecmp(myname, data.data, data.size) == 0) {
|
|
|
|
/* I am master server, and no explicit host list was
|
|
|
|
specified: do not push map to myself -- this will
|
|
|
|
fail with YPPUSH_AGE anyway. */
|
|
|
|
if (yppush_hostlist == NULL)
|
|
|
|
skip_master = 1;
|
|
|
|
} else {
|
1996-04-03 03:24:03 +00:00
|
|
|
yp_error("warning: this host is not the master for %s",
|
|
|
|
yppush_mapname);
|
|
|
|
#ifdef NITPICKY
|
1996-01-12 07:03:33 +00:00
|
|
|
yppush_exit(1);
|
1996-04-03 03:24:03 +00:00
|
|
|
#endif
|
1996-01-12 07:03:33 +00:00
|
|
|
}
|
|
|
|
|
1996-06-09 07:34:27 +00:00
|
|
|
yppush_master = malloc(data.size + 1);
|
|
|
|
strncpy(yppush_master, data.data, data.size);
|
1996-01-12 07:03:33 +00:00
|
|
|
yppush_master[data.size] = '\0';
|
|
|
|
|
|
|
|
/* Install some handy handlers. */
|
|
|
|
signal(SIGTERM, handler);
|
|
|
|
signal(SIGINT, handler);
|
|
|
|
|
|
|
|
/* set initial transaction ID */
|
1998-06-29 18:15:21 +00:00
|
|
|
yppush_transid = time((time_t *)NULL);
|
1996-01-12 07:03:33 +00:00
|
|
|
|
|
|
|
if (yppush_hostlist) {
|
|
|
|
/*
|
|
|
|
* Host list was specified on the command line:
|
|
|
|
* kick off the transfers by hand.
|
|
|
|
*/
|
|
|
|
tmp = yppush_hostlist;
|
2002-02-06 13:30:31 +00:00
|
|
|
while (tmp) {
|
1996-01-12 07:03:33 +00:00
|
|
|
yppush_foreach(YP_TRUE, NULL, 0, tmp->name,
|
2002-02-06 15:26:07 +00:00
|
|
|
strlen(tmp->name), NULL);
|
1996-01-12 07:03:33 +00:00
|
|
|
tmp = tmp->next;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Do a yp_all() on the ypservers map and initiate a ypxfr
|
|
|
|
* for each one.
|
|
|
|
*/
|
|
|
|
ypxfr_get_map("ypservers", yppush_domain,
|
|
|
|
"localhost", yppush_foreach);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (verbose > 1)
|
|
|
|
yp_error("all jobs dispatched");
|
|
|
|
|
|
|
|
/* All done -- normal exit. */
|
|
|
|
yppush_exit(0);
|
|
|
|
|
|
|
|
/* Just in case. */
|
|
|
|
exit(0);
|
|
|
|
}
|