yppush.c revision ace1a5f11236a072fca1b5e0ea1416a083a9f2aa
/*
* 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 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T
* All Rights Reserved
*
* Portions of this source code were derived from Berkeley
* 4.3 BSD under license from the Regents of the University of
* California.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#define _SVID_GETTOD
extern int gettimeofday(struct timeval *);
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <errno.h>
#include <signal.h>
#include <limits.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <dirent.h>
#include <rpc/rpcb_prot.h>
#include <rpc/rpcb_clnt.h>
#include <sys/systeminfo.h>
#include "ypsym.h"
#include "ypdefs.h"
#include "yp_b.h"
#include "shim.h"
#include "yptol.h"
#ifdef DEBUG
#endif
/* responses from ypxfrs, yes */
/* virginia yp map transfers */
/* can take a long time, we */
/* only worry if the slave */
/* crashes ... */
static char *pusage;
static char default_domain_name[YPMAXDOMAIN];
/* used in sysv filesystems */
/* used in sysv filesystems */
int grace_period = GRACE_PERIOD;
INTER_TRY, /* Seconds */
0 /* Microseconds */
};
TIMEOUT, /* Seconds */
0 /* Microseconds */
};
static SVCXPRT *transport4;
static SVCXPRT *transport6;
struct server {
struct dom_binding domb;
unsigned long xactid;
unsigned short state;
unsigned long status;
bool oldvers;
int start_time;
};
/* State values for server.state field */
#define SSTAT_INIT 0
#define SSTAT_CALLED 1
#define SSTAT_RESPONDED 2
#define SSTAT_PROGNOTREG 3
#define SSTAT_RPC 4
#define SSTAT_RSCRC 5
#define SSTAT_SYSTEM 6
static char err_usage[] =
"Usage:\n\typpush [-p <par>] [-d <domainname>] [-h <hostname>] [-v] map\n";
static char err_bad_args[] =
"The %s argument is bad.\n";
static char err_cant_get_kname[] =
"Can't get %s from system call.\n";
static char err_null_kname[] =
"The %s hasn't been set on this machine.\n";
static char err_bad_domainname[] = "domainname";
static char err_cant_bind[] =
"Can't find a yp server for domain %s. Reason: %s.\n";
static char err_cant_build_serverlist[] =
"Can't build server list from map \"ypservers\". Reason: %s.\n";
static char err_cant_find_host[] =
"Can't find host %s in map \"ypservers\".\n";
/*
* State_duple table. All messages should take 1 arg - the node name.
*/
struct state_duple {
int state;
char *state_msg;
};
static struct state_duple state_duples[] = {
{SSTAT_INIT, "Internal error trying to talk to %s."},
{SSTAT_CALLED, "%s has been called."},
{SSTAT_RESPONDED, "%s (v1 ypserv) sent an old-style request."},
{SSTAT_PROGNOTREG, "nis server not registered at %s."},
{SSTAT_RPC, "RPC error to %s: "},
{SSTAT_RSCRC, "Local resource allocation failure - can't talk to %s."},
{SSTAT_SYSTEM, "System error talking to %s: "},
{0, (char *)NULL}
};
/*
* Status_duple table. No messages should require any args.
*/
static struct status_duple {
long status;
char *status_msg;
};
static struct status_duple status_duples[] = {
{YPPUSH_SUCC, "Map successfully transferred."},
"Transfer not done: master's version isn't newer."},
{YPPUSH_NOMAP, "Failed - ypxfr there can't find a server for map."},
{YPPUSH_NODOM, "Failed - domain isn't supported."},
{YPPUSH_RSRC, "Failed - local resource allocation failure."},
{YPPUSH_RPC, "Failed - ypxfr had an RPC failure"},
{YPPUSH_MADDR, "Failed - ypxfr couldn't get the map master's address."},
{YPPUSH_YPERR, "Failed - nis server or map format error."},
{YPPUSH_BADARGS, "Failed - args to ypxfr were bad."},
{YPPUSH_DBM, "Failed - dbm operation on map failed."},
{YPPUSH_FILE, "Failed - file I/O operation on map failed"},
{YPPUSH_SKEW, "Failed - map version skew during transfer."},
"Map successfully transferred, but ypxfr \
couldn't send \"Clear map\" to ypserv "},
"Failed - no local order number in map - use -f flag to ypxfr."},
{YPPUSH_XFRERR, "Failed - ypxfr internal error."},
{YPPUSH_REFUSED, "Failed - Transfer request refused."},
{0, (char *)NULL}
};
/*
* rpcerr_duple table
*/
static struct rpcerr_duple {
char *rpc_msg;
};
static struct rpcerr_duple rpcerr_duples[] = {
{RPC_SUCCESS, "RPC success"},
{RPC_CANTENCODEARGS, "RPC Can't encode args"},
{RPC_CANTDECODERES, "RPC Can't decode results"},
{RPC_CANTSEND, "RPC Can't send"},
{RPC_CANTRECV, "RPC Can't recv"},
{RPC_TIMEDOUT, "NIS server registered, but does not respond"},
{RPC_VERSMISMATCH, "RPC version mismatch"},
{RPC_AUTHERROR, "RPC auth error"},
{RPC_PROGUNAVAIL, "RPC remote program unavailable"},
{RPC_PROGVERSMISMATCH, "RPC program mismatch"},
{RPC_PROCUNAVAIL, "RPC unknown procedure"},
{RPC_CANTDECODEARGS, "RPC Can't decode args"},
{RPC_UNKNOWNHOST, "unknown host"},
{RPC_RPCBFAILURE, "rpcbind failure (host is down?)"},
{RPC_PROGNOTREGISTERED, "RPC prog not registered"},
{RPC_SYSTEMERROR, "RPC system error"},
/* unused in list-end */
/* entry */
};
static void get_default_domain_name(void);
static void make_server_list(void);
static void one_host_list(void);
static int generate_callback(unsigned long *program);
static void xactid_seed(unsigned long *xactid);
static void print_state_msg(struct server *s, long e);
static void print_callback_msg(struct server *s);
static void rpcerr_msg(enum clnt_stat e);
#ifdef SYSVCONFIG
extern void sysvconfig(void);
#endif
extern int getdomainname(char *, int);
extern struct rpc_createerr rpc_createerr;
extern CLIENT *__yp_clnt_create_rsvdport();
int
{
unsigned long program;
if (!domain) {
}
#ifdef SYSVCONFIG
sysvconfig();
#endif
/* check to see if the map exists in this domain */
if (is_yptol_mode())
else
exit(1);
}
if (onehost) {
} else {
}
/*
* All process exits after the call to generate_callback should be
* through listener_exit(program, status), not exit(status), so the
* transient server can get unregistered with the portmapper.
*/
if (!generate_callback(&program)) {
}
listener_exit(program, 0);
/* NOTREACHED */
return (0);
}
/*
* This does the command line parsing.
*/
static void
{
argv++;
if (argc < 2) {
exit(1);
}
while (--argc) {
if ((*argv)[0] == '-') {
switch ((*argv)[1]) {
case 'v':
argv++;
break;
case 'd':
if (argc > 1) {
argv++;
argc--;
argv++;
YPMAXDOMAIN) {
exit(1);
}
} else {
exit(1);
}
break;
case 'h':
if (argc > 1) {
argv++;
argc--;
argv++;
} else {
exit(1);
}
break;
case 'p':
if (argc > 1) {
argv++;
argc--;
exit(1);
}
argv++;
if (curpar < 1) {
exit(1);
}
} else {
exit(1);
}
break;
default:
exit(1);
}
} else {
if (!map) {
} else {
exit(1);
}
argv++;
}
}
if (!map) {
exit(1);
}
}
/*
* This gets the local kernel domainname, and sets the global domain to it.
*/
static void
get_default_domain_name(void)
{
} else {
exit(1);
}
exit(1);
}
}
/*
* This verifies that the hostname supplied by the user is in the map
* "ypservers" then calls add_server to make it the only entry on the
* list of servers.
*/
static void
one_host_list(void)
{
char *key;
int keylen;
char *val;
int vallen;
int err;
char *ypservers = "ypservers";
if (verbose) {
}
exit(1);
}
exit(1);
}
}
/*
* This uses yp operations to retrieve each server name in the map
* "ypservers". add_server is called for each one to add it to the list of
* servers.
*/
static void
make_server_list(void)
{
char *key;
int keylen;
char *outkey;
int outkeylen;
char *val;
int vallen;
int err;
char *ypservers = "ypservers";
int count;
if (verbose) {
printf("Finding YP servers: ");
count = 4;
}
exit(1);
}
exit(1);
}
for (;;) {
if (verbose) {
if (count++ == 8) {
printf("\n");
count = 0;
}
}
if (err == YPERR_NOMORE) {
break;
} else {
yperr_string(err));
exit(1);
}
}
}
if (count != 0) {
if (verbose)
printf("\n");
}
}
/*
* This adds a single server to the server list.
*/
static void
{
static unsigned long seq;
static unsigned long xactid = 0;
return;
if (xactid == 0) {
}
perror("yppush: malloc failure");
exit(1);
}
server_list = ps;
}
/*
* This sets the base range for the transaction ids used in speaking the the
* server ypxfr processes.
*/
static void
xactid_seed(unsigned long *xactid)
{
struct timeval t;
if (gettimeofday(&t) == -1) {
perror("yppush gettimeofday failure");
*xactid = 1234567;
} else {
}
}
/*
* This generates the channel which will be used as the listener process'
* service rendezvous point, and comes up with a transient program number
* for the use of the RPC messages from the ypxfr processes.
*/
static int
generate_callback(unsigned long *program)
{
union {
unsigned long p;
unsigned char b[sizeof (unsigned long)];
} u;
int ret, i;
"yppush: Could not get udp or udp6 netconfig entry\n");
exit(1);
}
if (transport4 == 0 && transport6 == 0) {
exit(1);
}
/* Find the maximum possible program number using an unsigned long */
for (i = 0; i < sizeof (u.b); i++)
u.b[i] = 0xff;
maxprognum = u.p;
if (transport4 != 0) {
trans = transport4;
} else {
trans = transport6;
}
prognum++;
if (ret == 0) {
exit(1);
} else {
&transport6->xp_ltaddr);
if (ret == 0) {
"yppush: Could not create udp6 callback service\n");
exit(1);
}
}
}
return (ret);
}
/*
* This is the main loop. Send messages to each server,
* and then wait for a response.
*/
{
ps = server_list;
return (0);
active_list = ps;
return (1);
}
{
struct server *p;
struct server *n;
if (in == active_list) {
return (1);
}
p = active_list;
for (n = active_list; n; n = n->pnext) {
if (in == n) {
return (0);
}
p = n;
}
return (-1);
}
void
unsigned long program;
{
int npollfds = 0;
int pollret;
long error;
int hpar; /* this times par count */
int i;
int j;
int time_now;
int docb;
int actives = 0;
int dead = 0;
if (grace_period < MIN_GRACE)
if (transport4 != 0) {
listener_dispatch, 0)) {
"Can't set up transient udp callback server.\n");
}
}
if (transport6 != 0) {
listener_dispatch, 0)) {
"Can't set up transient udp6 callback server.\n");
}
}
for (;;) {
if (server_list == NULL) {
actives = 0;
dead = 0;
actives++;
else
dead++;
}
if (actives == 0) {
if (verbose) {
}
>= grace_period) {
if (verbose) {
"no response from %s -- grace of %d seconds expired.\n",
}
}
}
break;
}
}
actives = 0;
< grace_period) {
actives++;
if (verbose) {
}
}
} else {
if (verbose) {
printf("Deactivating %s\n",
}
}
}
/* add someone to the active list keep up with curpar */
if (add_to_active()) {
ps = active_list;
else
}
}
docb = 0;
docb = 1;
break;
}
if (docb == 0) {
if (verbose) {
printf("No one to wait for this pass.\n");
}
continue; /* try curpar more */
}
if (npollfds != svc_max_pollfd) {
sizeof (pollfd_t) * svc_max_pollfd);
}
/*
* Get existing array of pollfd's, should really compress
* this but it shouldn't get very large (or sparse).
*/
sizeof (pollfd_t) * svc_max_pollfd);
errno = 0;
case -1:
(void) perror("main loop select");
}
break;
case 0:
if (verbose) {
(void) printf("timeout in main loop select.\n");
}
break;
default:
break;
} /* switch */
} /* for */
}
/*
* This does the listener process cleanup and process exit.
*/
static void
{
}
/*
* This is the listener process' RPC service dispatcher.
*/
static void
{
case YPPUSHPROC_NULL:
}
break;
case YPPUSHPROC_XFRRESP:
break;
default:
break;
}
}
/*
* This dumps a server state message to stdout. It is called in cases where
* we have no expectation of receiving a callback from the remote ypxfr.
*/
static void
print_state_msg(struct server *s, long e)
{
struct state_duple *sd;
if (s->state == SSTAT_SYSTEM)
return; /* already printed */
s->state == SSTAT_CALLED))
return;
rpcerr_msg((enum clnt_stat) e);
}
printf("\n");
return;
}
}
}
/*
* This dumps a transfer status message to stdout. It is called in
* response to a received RPC message from the called ypxfr.
*/
static void
print_callback_msg(struct server *s)
{
register struct status_duple *sd;
if (!verbose &&
(s->status == YPPUSH_AGE) ||
(s->status == YPPUSH_SUCC))
return;
printf("Status received from ypxfr on %s:\n\t%s\n",
return;
}
}
"status (value %d) from ypxfr on %s.\n",
}
/*
* This dumps an RPC error message to stdout. This is basically a rewrite
* of clnt_perrno, but writes to stdout instead of stderr.
*/
static void
rpcerr_msg(enum clnt_stat e)
{
struct rpcerr_duple *rd;
return;
}
}
}
/*
* This picks up the response from the ypxfr process which has been started
* up on the remote node. The response status must be non-zero, otherwise
* the status will be set to "ypxfr error".
*/
static void
{
struct yppushresp_xfr resp;
register struct server *s;
return;
}
}
for (s = active_list; s; s = s->pnext) {
s->state = SSTAT_RESPONDED;
return;
}
}
}
/*
* This sends a message to a single ypserv process. The return value is
* a state value. If the RPC call fails because of a version
* mismatch, we'll assume that we're talking to a version 1 ypserv process,
* and will send him an old "YPPROC_GET" request, as was defined in the
* earlier version of yp_prot.h
*/
static unsigned short
{
struct ypreq_newxfr req;
enum clnt_stat s;
(char *)NULL,
0, 0)) == NULL) {
return (SSTAT_PROGNOTREG);
} else {
printf("\n");
return (SSTAT_SYSTEM);
}
}
return (SSTAT_RSCRC);
}
if (!oldxfr) {
req.ypxfr_ordernum = 0;
/*
* the creation of field req.name, instead of ypreq_xfr (old)
* req.port, does not make any sense. it doesn't give any
* information to receiving ypserv except its own name !!
* new ypserv duplicates work for YPPROC_XFR and YPPROC_NEWXFR
*/
}
if (s == RPC_PROCUNAVAIL) {
oldreq.ypxfr_ordernum = 0;
}
if (s == RPC_SUCCESS) {
return (SSTAT_CALLED);
} else {
return (SSTAT_RPC);
}
/*NOTREACHED*/
}
/*
* FUNCTION: is_yptol_mode();
*
* DESCRIPTION: Determines if we should run in N2L or traditional mode based
* on the presence of the N2L mapping file.
*
* This is a copy of a function from libnisdb. If more than this
* one function become required it may be worth linking the
* entire lib.
*
* INPUTS: Nothing
*
* OUTPUTS: TRUE = Run in N2L mode
* FALSE = Run in traditional mode.
*/
{
return (TRUE);
return (FALSE);
}