1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate * 22*0Sstevel@tonic-gate * Copyright 2003 Sun Microsystems, Inc. All rights reserved. 23*0Sstevel@tonic-gate * Use is subject to license terms. 24*0Sstevel@tonic-gate * 25*0Sstevel@tonic-gate * Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T 26*0Sstevel@tonic-gate * All Rights Reserved 27*0Sstevel@tonic-gate * 28*0Sstevel@tonic-gate * Portions of this source code were derived from Berkeley 29*0Sstevel@tonic-gate * 4.3 BSD under license from the Regents of the University of 30*0Sstevel@tonic-gate * California. 31*0Sstevel@tonic-gate */ 32*0Sstevel@tonic-gate 33*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 34*0Sstevel@tonic-gate 35*0Sstevel@tonic-gate #define _SVID_GETTOD 36*0Sstevel@tonic-gate #include <sys/time.h> 37*0Sstevel@tonic-gate extern int gettimeofday(struct timeval *); 38*0Sstevel@tonic-gate 39*0Sstevel@tonic-gate #include <sys/types.h> 40*0Sstevel@tonic-gate #include <stdio.h> 41*0Sstevel@tonic-gate #include <string.h> 42*0Sstevel@tonic-gate #include <malloc.h> 43*0Sstevel@tonic-gate #include <errno.h> 44*0Sstevel@tonic-gate #include <signal.h> 45*0Sstevel@tonic-gate #include <limits.h> 46*0Sstevel@tonic-gate #include <stdlib.h> 47*0Sstevel@tonic-gate #include <unistd.h> 48*0Sstevel@tonic-gate #include <sys/types.h> 49*0Sstevel@tonic-gate #include <sys/wait.h> 50*0Sstevel@tonic-gate #include <sys/stat.h> 51*0Sstevel@tonic-gate #include <ctype.h> 52*0Sstevel@tonic-gate #include <dirent.h> 53*0Sstevel@tonic-gate #include <rpc/rpc.h> 54*0Sstevel@tonic-gate #include <rpc/nettype.h> 55*0Sstevel@tonic-gate #include <rpc/rpcb_prot.h> 56*0Sstevel@tonic-gate #include <rpc/rpcb_clnt.h> 57*0Sstevel@tonic-gate #include <sys/systeminfo.h> 58*0Sstevel@tonic-gate #include <sys/select.h> 59*0Sstevel@tonic-gate #include "ypsym.h" 60*0Sstevel@tonic-gate #include "ypdefs.h" 61*0Sstevel@tonic-gate #include "yp_b.h" 62*0Sstevel@tonic-gate #include "shim.h" 63*0Sstevel@tonic-gate #include "yptol.h" 64*0Sstevel@tonic-gate 65*0Sstevel@tonic-gate 66*0Sstevel@tonic-gate #ifdef DEBUG 67*0Sstevel@tonic-gate #undef YPPROG 68*0Sstevel@tonic-gate #define YPPROG ((ulong_t)109999) 69*0Sstevel@tonic-gate #undef YPBINDPROG 70*0Sstevel@tonic-gate #define YPBINDPROG ((ulong_t)109998) 71*0Sstevel@tonic-gate #endif 72*0Sstevel@tonic-gate 73*0Sstevel@tonic-gate #define INTER_TRY 12 /* Seconds between tries */ 74*0Sstevel@tonic-gate #define PORTMAP_TIME 30 /* Seconds before decide its down */ 75*0Sstevel@tonic-gate #define TIMEOUT INTER_TRY*4 /* Total time for timeout */ 76*0Sstevel@tonic-gate #define CUR_PAR 4 /* Total parallal yppushes */ 77*0Sstevel@tonic-gate #define MIN_GRACE 25 /* select timeout and minimum grace */ 78*0Sstevel@tonic-gate #define GRACE_PERIOD 800 /* Total seconds we'll wait for */ 79*0Sstevel@tonic-gate /* responses from ypxfrs, yes */ 80*0Sstevel@tonic-gate /* virginia yp map transfers */ 81*0Sstevel@tonic-gate /* can take a long time, we */ 82*0Sstevel@tonic-gate /* only worry if the slave */ 83*0Sstevel@tonic-gate /* crashes ... */ 84*0Sstevel@tonic-gate 85*0Sstevel@tonic-gate USE_YPDBPATH 86*0Sstevel@tonic-gate static char *pusage; 87*0Sstevel@tonic-gate static char *domain = NULL; 88*0Sstevel@tonic-gate static char *host = NULL; 89*0Sstevel@tonic-gate static char my_name[YPMAXPEER +1]; 90*0Sstevel@tonic-gate static char default_domain_name[YPMAXDOMAIN]; 91*0Sstevel@tonic-gate static char domain_alias[MAXNAMLEN]; /* nickname for domain - */ 92*0Sstevel@tonic-gate /* used in sysv filesystems */ 93*0Sstevel@tonic-gate static char map_alias[MAXNAMLEN]; /* nickname for map - */ 94*0Sstevel@tonic-gate /* used in sysv filesystems */ 95*0Sstevel@tonic-gate static char *map = NULL; 96*0Sstevel@tonic-gate static bool verbose = FALSE; 97*0Sstevel@tonic-gate static bool onehost = FALSE; 98*0Sstevel@tonic-gate static bool oldxfr = FALSE; 99*0Sstevel@tonic-gate static bool callback_timeout = FALSE; /* set when a callback times out */ 100*0Sstevel@tonic-gate int grace_period = GRACE_PERIOD; 101*0Sstevel@tonic-gate int curpar = CUR_PAR; /* should be set by other stuff */ 102*0Sstevel@tonic-gate static char ypmapname[1024]; /* Used to check for map's existence */ 103*0Sstevel@tonic-gate 104*0Sstevel@tonic-gate static struct timeval intertry = { 105*0Sstevel@tonic-gate INTER_TRY, /* Seconds */ 106*0Sstevel@tonic-gate 0 /* Microseconds */ 107*0Sstevel@tonic-gate }; 108*0Sstevel@tonic-gate static struct timeval timeout = { 109*0Sstevel@tonic-gate TIMEOUT, /* Seconds */ 110*0Sstevel@tonic-gate 0 /* Microseconds */ 111*0Sstevel@tonic-gate }; 112*0Sstevel@tonic-gate static SVCXPRT *transport4; 113*0Sstevel@tonic-gate static SVCXPRT *transport6; 114*0Sstevel@tonic-gate struct server { 115*0Sstevel@tonic-gate struct server *pnext; 116*0Sstevel@tonic-gate struct dom_binding domb; 117*0Sstevel@tonic-gate char svc_name[YPMAXPEER+1]; 118*0Sstevel@tonic-gate unsigned long xactid; 119*0Sstevel@tonic-gate unsigned short state; 120*0Sstevel@tonic-gate unsigned long status; 121*0Sstevel@tonic-gate bool oldvers; 122*0Sstevel@tonic-gate int start_time; 123*0Sstevel@tonic-gate }; 124*0Sstevel@tonic-gate #define n_conf dom_binding->ypbind_nconf 125*0Sstevel@tonic-gate #define svc_addr dom_binding->ypbind_svcaddr 126*0Sstevel@tonic-gate static struct server *server_list = (struct server *)NULL; 127*0Sstevel@tonic-gate static struct server *active_list = (struct server *)NULL; 128*0Sstevel@tonic-gate 129*0Sstevel@tonic-gate /* State values for server.state field */ 130*0Sstevel@tonic-gate 131*0Sstevel@tonic-gate #define SSTAT_INIT 0 132*0Sstevel@tonic-gate #define SSTAT_CALLED 1 133*0Sstevel@tonic-gate #define SSTAT_RESPONDED 2 134*0Sstevel@tonic-gate #define SSTAT_PROGNOTREG 3 135*0Sstevel@tonic-gate #define SSTAT_RPC 4 136*0Sstevel@tonic-gate #define SSTAT_RSCRC 5 137*0Sstevel@tonic-gate #define SSTAT_SYSTEM 6 138*0Sstevel@tonic-gate 139*0Sstevel@tonic-gate static char err_usage[] = 140*0Sstevel@tonic-gate "Usage:\n\typpush [-p <par>] [-d <domainname>] [-h <hostname>] [-v] map\n"; 141*0Sstevel@tonic-gate static char err_bad_args[] = 142*0Sstevel@tonic-gate "The %s argument is bad.\n"; 143*0Sstevel@tonic-gate static char err_cant_get_kname[] = 144*0Sstevel@tonic-gate "Can't get %s from system call.\n"; 145*0Sstevel@tonic-gate static char err_null_kname[] = 146*0Sstevel@tonic-gate "The %s hasn't been set on this machine.\n"; 147*0Sstevel@tonic-gate static char err_bad_domainname[] = "domainname"; 148*0Sstevel@tonic-gate static char err_cant_bind[] = 149*0Sstevel@tonic-gate "Can't find a yp server for domain %s. Reason: %s.\n"; 150*0Sstevel@tonic-gate static char err_cant_build_serverlist[] = 151*0Sstevel@tonic-gate "Can't build server list from map \"ypservers\". Reason: %s.\n"; 152*0Sstevel@tonic-gate static char err_cant_find_host[] = 153*0Sstevel@tonic-gate "Can't find host %s in map \"ypservers\".\n"; 154*0Sstevel@tonic-gate /* 155*0Sstevel@tonic-gate * State_duple table. All messages should take 1 arg - the node name. 156*0Sstevel@tonic-gate */ 157*0Sstevel@tonic-gate struct state_duple { 158*0Sstevel@tonic-gate int state; 159*0Sstevel@tonic-gate char *state_msg; 160*0Sstevel@tonic-gate }; 161*0Sstevel@tonic-gate static struct state_duple state_duples[] = { 162*0Sstevel@tonic-gate {SSTAT_INIT, "Internal error trying to talk to %s."}, 163*0Sstevel@tonic-gate {SSTAT_CALLED, "%s has been called."}, 164*0Sstevel@tonic-gate {SSTAT_RESPONDED, "%s (v1 ypserv) sent an old-style request."}, 165*0Sstevel@tonic-gate {SSTAT_PROGNOTREG, "nis server not registered at %s."}, 166*0Sstevel@tonic-gate {SSTAT_RPC, "RPC error to %s: "}, 167*0Sstevel@tonic-gate {SSTAT_RSCRC, "Local resource allocation failure - can't talk to %s."}, 168*0Sstevel@tonic-gate {SSTAT_SYSTEM, "System error talking to %s: "}, 169*0Sstevel@tonic-gate {0, (char *)NULL} 170*0Sstevel@tonic-gate }; 171*0Sstevel@tonic-gate /* 172*0Sstevel@tonic-gate * Status_duple table. No messages should require any args. 173*0Sstevel@tonic-gate */ 174*0Sstevel@tonic-gate static struct status_duple { 175*0Sstevel@tonic-gate long status; 176*0Sstevel@tonic-gate char *status_msg; 177*0Sstevel@tonic-gate }; 178*0Sstevel@tonic-gate static struct status_duple status_duples[] = { 179*0Sstevel@tonic-gate {YPPUSH_SUCC, "Map successfully transferred."}, 180*0Sstevel@tonic-gate {YPPUSH_AGE, 181*0Sstevel@tonic-gate "Transfer not done: master's version isn't newer."}, 182*0Sstevel@tonic-gate {YPPUSH_NOMAP, "Failed - ypxfr there can't find a server for map."}, 183*0Sstevel@tonic-gate {YPPUSH_NODOM, "Failed - domain isn't supported."}, 184*0Sstevel@tonic-gate {YPPUSH_RSRC, "Failed - local resource allocation failure."}, 185*0Sstevel@tonic-gate {YPPUSH_RPC, "Failed - ypxfr had an RPC failure"}, 186*0Sstevel@tonic-gate {YPPUSH_MADDR, "Failed - ypxfr couldn't get the map master's address."}, 187*0Sstevel@tonic-gate {YPPUSH_YPERR, "Failed - nis server or map format error."}, 188*0Sstevel@tonic-gate {YPPUSH_BADARGS, "Failed - args to ypxfr were bad."}, 189*0Sstevel@tonic-gate {YPPUSH_DBM, "Failed - dbm operation on map failed."}, 190*0Sstevel@tonic-gate {YPPUSH_FILE, "Failed - file I/O operation on map failed"}, 191*0Sstevel@tonic-gate {YPPUSH_SKEW, "Failed - map version skew during transfer."}, 192*0Sstevel@tonic-gate {YPPUSH_CLEAR, 193*0Sstevel@tonic-gate "Map successfully transferred, but ypxfr \ 194*0Sstevel@tonic-gate couldn't send \"Clear map\" to ypserv "}, 195*0Sstevel@tonic-gate {YPPUSH_FORCE, 196*0Sstevel@tonic-gate "Failed - no local order number in map - use -f flag to ypxfr."}, 197*0Sstevel@tonic-gate {YPPUSH_XFRERR, "Failed - ypxfr internal error."}, 198*0Sstevel@tonic-gate {YPPUSH_REFUSED, "Failed - Transfer request refused."}, 199*0Sstevel@tonic-gate {YPPUSH_NOALIAS, 200*0Sstevel@tonic-gate "Failed - System V domain/map alias not in alias file."}, 201*0Sstevel@tonic-gate {0, (char *)NULL} 202*0Sstevel@tonic-gate }; 203*0Sstevel@tonic-gate /* 204*0Sstevel@tonic-gate * rpcerr_duple table 205*0Sstevel@tonic-gate */ 206*0Sstevel@tonic-gate static struct rpcerr_duple { 207*0Sstevel@tonic-gate enum clnt_stat rpc_stat; 208*0Sstevel@tonic-gate char *rpc_msg; 209*0Sstevel@tonic-gate }; 210*0Sstevel@tonic-gate static struct rpcerr_duple rpcerr_duples[] = { 211*0Sstevel@tonic-gate {RPC_SUCCESS, "RPC success"}, 212*0Sstevel@tonic-gate {RPC_CANTENCODEARGS, "RPC Can't encode args"}, 213*0Sstevel@tonic-gate {RPC_CANTDECODERES, "RPC Can't decode results"}, 214*0Sstevel@tonic-gate {RPC_CANTSEND, "RPC Can't send"}, 215*0Sstevel@tonic-gate {RPC_CANTRECV, "RPC Can't recv"}, 216*0Sstevel@tonic-gate {RPC_TIMEDOUT, "NIS server registered, but does not respond"}, 217*0Sstevel@tonic-gate {RPC_VERSMISMATCH, "RPC version mismatch"}, 218*0Sstevel@tonic-gate {RPC_AUTHERROR, "RPC auth error"}, 219*0Sstevel@tonic-gate {RPC_PROGUNAVAIL, "RPC remote program unavailable"}, 220*0Sstevel@tonic-gate {RPC_PROGVERSMISMATCH, "RPC program mismatch"}, 221*0Sstevel@tonic-gate {RPC_PROCUNAVAIL, "RPC unknown procedure"}, 222*0Sstevel@tonic-gate {RPC_CANTDECODEARGS, "RPC Can't decode args"}, 223*0Sstevel@tonic-gate {RPC_UNKNOWNHOST, "unknown host"}, 224*0Sstevel@tonic-gate {RPC_RPCBFAILURE, "rpcbind failure (host is down?)"}, 225*0Sstevel@tonic-gate {RPC_PROGNOTREGISTERED, "RPC prog not registered"}, 226*0Sstevel@tonic-gate {RPC_SYSTEMERROR, "RPC system error"}, 227*0Sstevel@tonic-gate {RPC_SUCCESS, (char *)NULL} /* Duplicate rpc_stat */ 228*0Sstevel@tonic-gate /* unused in list-end */ 229*0Sstevel@tonic-gate /* entry */ 230*0Sstevel@tonic-gate }; 231*0Sstevel@tonic-gate 232*0Sstevel@tonic-gate static void get_default_domain_name(void); 233*0Sstevel@tonic-gate static void get_command_line_args(int argc, char **argv); 234*0Sstevel@tonic-gate static unsigned short send_message(struct server *ps, 235*0Sstevel@tonic-gate unsigned long program, long *err); 236*0Sstevel@tonic-gate static void make_server_list(void); 237*0Sstevel@tonic-gate static void one_host_list(void); 238*0Sstevel@tonic-gate static void add_server(char *sname, int namelen); 239*0Sstevel@tonic-gate static int generate_callback(unsigned long *program); 240*0Sstevel@tonic-gate static void xactid_seed(unsigned long *xactid); 241*0Sstevel@tonic-gate static void main_loop(unsigned long program); 242*0Sstevel@tonic-gate static void listener_exit(unsigned long program, int stat); 243*0Sstevel@tonic-gate static void listener_dispatch(struct svc_req *rqstp, SVCXPRT *transp); 244*0Sstevel@tonic-gate static void print_state_msg(struct server *s, long e); 245*0Sstevel@tonic-gate static void print_callback_msg(struct server *s); 246*0Sstevel@tonic-gate static void rpcerr_msg(enum clnt_stat e); 247*0Sstevel@tonic-gate static void get_xfr_response(SVCXPRT *transp); 248*0Sstevel@tonic-gate 249*0Sstevel@tonic-gate #ifdef SYSVCONFIG 250*0Sstevel@tonic-gate extern void sysvconfig(void); 251*0Sstevel@tonic-gate #endif 252*0Sstevel@tonic-gate extern int yp_getalias(char *key, char *key_alias, int maxlen); 253*0Sstevel@tonic-gate extern int getdomainname(char *, int); 254*0Sstevel@tonic-gate 255*0Sstevel@tonic-gate extern struct rpc_createerr rpc_createerr; 256*0Sstevel@tonic-gate extern char *sys_errlist[]; 257*0Sstevel@tonic-gate extern int sys_nerr; 258*0Sstevel@tonic-gate extern CLIENT *__yp_clnt_create_rsvdport(); 259*0Sstevel@tonic-gate 260*0Sstevel@tonic-gate int 261*0Sstevel@tonic-gate main(int argc, char **argv) 262*0Sstevel@tonic-gate { 263*0Sstevel@tonic-gate unsigned long program; 264*0Sstevel@tonic-gate struct stat sbuf; 265*0Sstevel@tonic-gate 266*0Sstevel@tonic-gate get_command_line_args(argc, argv); 267*0Sstevel@tonic-gate 268*0Sstevel@tonic-gate if (!domain) { 269*0Sstevel@tonic-gate get_default_domain_name(); 270*0Sstevel@tonic-gate } 271*0Sstevel@tonic-gate 272*0Sstevel@tonic-gate #ifdef SYSVCONFIG 273*0Sstevel@tonic-gate sysvconfig(); 274*0Sstevel@tonic-gate #endif 275*0Sstevel@tonic-gate 276*0Sstevel@tonic-gate if (yp_getalias(domain, domain_alias, NAME_MAX) != 0) 277*0Sstevel@tonic-gate fprintf(stderr, "domain alias for %s not found\n", domain); 278*0Sstevel@tonic-gate if (yp_getalias(map, map_alias, MAXALIASLEN) != 0) 279*0Sstevel@tonic-gate fprintf(stderr, "map alias for %s not found\n", map); 280*0Sstevel@tonic-gate 281*0Sstevel@tonic-gate /* check to see if the map exists in this domain */ 282*0Sstevel@tonic-gate if (is_yptol_mode()) 283*0Sstevel@tonic-gate sprintf(ypmapname, "%s/%s/%s%s.dir", ypdbpath, domain_alias, 284*0Sstevel@tonic-gate NTOL_PREFIX, map_alias); 285*0Sstevel@tonic-gate else 286*0Sstevel@tonic-gate sprintf(ypmapname, "%s/%s/%s.dir", ypdbpath, domain_alias, 287*0Sstevel@tonic-gate map_alias); 288*0Sstevel@tonic-gate if (stat(ypmapname, &sbuf) < 0) { 289*0Sstevel@tonic-gate fprintf(stderr, "yppush: Map does not exist.\n"); 290*0Sstevel@tonic-gate exit(1); 291*0Sstevel@tonic-gate } 292*0Sstevel@tonic-gate 293*0Sstevel@tonic-gate if (onehost) { 294*0Sstevel@tonic-gate one_host_list(); 295*0Sstevel@tonic-gate } else { 296*0Sstevel@tonic-gate make_server_list(); 297*0Sstevel@tonic-gate } 298*0Sstevel@tonic-gate 299*0Sstevel@tonic-gate /* 300*0Sstevel@tonic-gate * All process exits after the call to generate_callback should be 301*0Sstevel@tonic-gate * through listener_exit(program, status), not exit(status), so the 302*0Sstevel@tonic-gate * transient server can get unregistered with the portmapper. 303*0Sstevel@tonic-gate */ 304*0Sstevel@tonic-gate 305*0Sstevel@tonic-gate if (!generate_callback(&program)) { 306*0Sstevel@tonic-gate fprintf(stderr, "Can't set up transient callback server.\n"); 307*0Sstevel@tonic-gate } 308*0Sstevel@tonic-gate 309*0Sstevel@tonic-gate main_loop(program); 310*0Sstevel@tonic-gate 311*0Sstevel@tonic-gate listener_exit(program, 0); 312*0Sstevel@tonic-gate 313*0Sstevel@tonic-gate /* NOTREACHED */ 314*0Sstevel@tonic-gate return (0); 315*0Sstevel@tonic-gate } 316*0Sstevel@tonic-gate 317*0Sstevel@tonic-gate /* 318*0Sstevel@tonic-gate * This does the command line parsing. 319*0Sstevel@tonic-gate */ 320*0Sstevel@tonic-gate static void 321*0Sstevel@tonic-gate get_command_line_args(int argc, char **argv) 322*0Sstevel@tonic-gate { 323*0Sstevel@tonic-gate pusage = err_usage; 324*0Sstevel@tonic-gate argv++; 325*0Sstevel@tonic-gate 326*0Sstevel@tonic-gate if (argc < 2) { 327*0Sstevel@tonic-gate fprintf(stderr, pusage); 328*0Sstevel@tonic-gate exit(1); 329*0Sstevel@tonic-gate } 330*0Sstevel@tonic-gate 331*0Sstevel@tonic-gate while (--argc) { 332*0Sstevel@tonic-gate if ((*argv)[0] == '-') { 333*0Sstevel@tonic-gate switch ((*argv)[1]) { 334*0Sstevel@tonic-gate case 'v': 335*0Sstevel@tonic-gate verbose = TRUE; 336*0Sstevel@tonic-gate argv++; 337*0Sstevel@tonic-gate break; 338*0Sstevel@tonic-gate case 'd': 339*0Sstevel@tonic-gate if (argc > 1) { 340*0Sstevel@tonic-gate argv++; 341*0Sstevel@tonic-gate argc--; 342*0Sstevel@tonic-gate domain = *argv; 343*0Sstevel@tonic-gate argv++; 344*0Sstevel@tonic-gate if (((int)strlen(domain)) > 345*0Sstevel@tonic-gate YPMAXDOMAIN) { 346*0Sstevel@tonic-gate fprintf(stderr, 347*0Sstevel@tonic-gate err_bad_args, 348*0Sstevel@tonic-gate err_bad_domainname); 349*0Sstevel@tonic-gate exit(1); 350*0Sstevel@tonic-gate } 351*0Sstevel@tonic-gate } else { 352*0Sstevel@tonic-gate fprintf(stderr, pusage); 353*0Sstevel@tonic-gate exit(1); 354*0Sstevel@tonic-gate } 355*0Sstevel@tonic-gate break; 356*0Sstevel@tonic-gate case 'h': 357*0Sstevel@tonic-gate if (argc > 1) { 358*0Sstevel@tonic-gate onehost = TRUE; 359*0Sstevel@tonic-gate argv++; 360*0Sstevel@tonic-gate argc--; 361*0Sstevel@tonic-gate host = *argv; 362*0Sstevel@tonic-gate argv++; 363*0Sstevel@tonic-gate } else { 364*0Sstevel@tonic-gate fprintf(stderr, pusage); 365*0Sstevel@tonic-gate exit(1); 366*0Sstevel@tonic-gate } 367*0Sstevel@tonic-gate break; 368*0Sstevel@tonic-gate 369*0Sstevel@tonic-gate case 'p': 370*0Sstevel@tonic-gate 371*0Sstevel@tonic-gate if (argc > 1) { 372*0Sstevel@tonic-gate argv++; 373*0Sstevel@tonic-gate argc--; 374*0Sstevel@tonic-gate if (sscanf(*argv, "%d", &curpar) != 1) { 375*0Sstevel@tonic-gate (void) fprintf(stderr, pusage); 376*0Sstevel@tonic-gate exit(1); 377*0Sstevel@tonic-gate } 378*0Sstevel@tonic-gate argv++; 379*0Sstevel@tonic-gate if (curpar < 1) { 380*0Sstevel@tonic-gate (void) fprintf(stderr, pusage); 381*0Sstevel@tonic-gate exit(1); 382*0Sstevel@tonic-gate } 383*0Sstevel@tonic-gate } else { 384*0Sstevel@tonic-gate (void) fprintf(stderr, pusage); 385*0Sstevel@tonic-gate exit(1); 386*0Sstevel@tonic-gate } 387*0Sstevel@tonic-gate break; 388*0Sstevel@tonic-gate 389*0Sstevel@tonic-gate default: 390*0Sstevel@tonic-gate fprintf(stderr, pusage); 391*0Sstevel@tonic-gate exit(1); 392*0Sstevel@tonic-gate } 393*0Sstevel@tonic-gate } else { 394*0Sstevel@tonic-gate if (!map) { 395*0Sstevel@tonic-gate map = *argv; 396*0Sstevel@tonic-gate } else { 397*0Sstevel@tonic-gate fprintf(stderr, pusage); 398*0Sstevel@tonic-gate exit(1); 399*0Sstevel@tonic-gate } 400*0Sstevel@tonic-gate argv++; 401*0Sstevel@tonic-gate } 402*0Sstevel@tonic-gate } 403*0Sstevel@tonic-gate 404*0Sstevel@tonic-gate if (!map) { 405*0Sstevel@tonic-gate fprintf(stderr, pusage); 406*0Sstevel@tonic-gate exit(1); 407*0Sstevel@tonic-gate } 408*0Sstevel@tonic-gate } 409*0Sstevel@tonic-gate 410*0Sstevel@tonic-gate /* 411*0Sstevel@tonic-gate * This gets the local kernel domainname, and sets the global domain to it. 412*0Sstevel@tonic-gate */ 413*0Sstevel@tonic-gate static void 414*0Sstevel@tonic-gate get_default_domain_name(void) 415*0Sstevel@tonic-gate { 416*0Sstevel@tonic-gate if (!getdomainname(default_domain_name, YPMAXDOMAIN)) { 417*0Sstevel@tonic-gate domain = default_domain_name; 418*0Sstevel@tonic-gate } else { 419*0Sstevel@tonic-gate fprintf(stderr, err_cant_get_kname, err_bad_domainname); 420*0Sstevel@tonic-gate exit(1); 421*0Sstevel@tonic-gate } 422*0Sstevel@tonic-gate 423*0Sstevel@tonic-gate if ((int)strlen(domain) == 0) { 424*0Sstevel@tonic-gate fprintf(stderr, err_null_kname, err_bad_domainname); 425*0Sstevel@tonic-gate exit(1); 426*0Sstevel@tonic-gate } 427*0Sstevel@tonic-gate } 428*0Sstevel@tonic-gate 429*0Sstevel@tonic-gate /* 430*0Sstevel@tonic-gate * This verifies that the hostname supplied by the user is in the map 431*0Sstevel@tonic-gate * "ypservers" then calls add_server to make it the only entry on the 432*0Sstevel@tonic-gate * list of servers. 433*0Sstevel@tonic-gate */ 434*0Sstevel@tonic-gate static void 435*0Sstevel@tonic-gate one_host_list(void) 436*0Sstevel@tonic-gate { 437*0Sstevel@tonic-gate char *key; 438*0Sstevel@tonic-gate int keylen; 439*0Sstevel@tonic-gate char *val; 440*0Sstevel@tonic-gate int vallen; 441*0Sstevel@tonic-gate int err; 442*0Sstevel@tonic-gate char *ypservers = "ypservers"; 443*0Sstevel@tonic-gate 444*0Sstevel@tonic-gate if (verbose) { 445*0Sstevel@tonic-gate printf("Verifying YP server: %s\n", host); 446*0Sstevel@tonic-gate fflush(stdout); 447*0Sstevel@tonic-gate } 448*0Sstevel@tonic-gate 449*0Sstevel@tonic-gate if (err = yp_bind(domain_alias)) { 450*0Sstevel@tonic-gate fprintf(stderr, err_cant_bind, domain, yperr_string(err)); 451*0Sstevel@tonic-gate exit(1); 452*0Sstevel@tonic-gate } 453*0Sstevel@tonic-gate 454*0Sstevel@tonic-gate keylen = strlen(host); 455*0Sstevel@tonic-gate 456*0Sstevel@tonic-gate if (yp_match(domain_alias, ypservers, host, keylen, 457*0Sstevel@tonic-gate &val, &vallen)) { 458*0Sstevel@tonic-gate fprintf(stderr, err_cant_find_host, host); 459*0Sstevel@tonic-gate exit(1); 460*0Sstevel@tonic-gate } 461*0Sstevel@tonic-gate 462*0Sstevel@tonic-gate add_server(host, keylen); 463*0Sstevel@tonic-gate } 464*0Sstevel@tonic-gate 465*0Sstevel@tonic-gate /* 466*0Sstevel@tonic-gate * This uses yp operations to retrieve each server name in the map 467*0Sstevel@tonic-gate * "ypservers". add_server is called for each one to add it to the list of 468*0Sstevel@tonic-gate * servers. 469*0Sstevel@tonic-gate */ 470*0Sstevel@tonic-gate static void 471*0Sstevel@tonic-gate make_server_list(void) 472*0Sstevel@tonic-gate { 473*0Sstevel@tonic-gate char *key; 474*0Sstevel@tonic-gate int keylen; 475*0Sstevel@tonic-gate char *outkey; 476*0Sstevel@tonic-gate int outkeylen; 477*0Sstevel@tonic-gate char *val; 478*0Sstevel@tonic-gate int vallen; 479*0Sstevel@tonic-gate int err; 480*0Sstevel@tonic-gate char *ypservers = "ypservers"; 481*0Sstevel@tonic-gate int count; 482*0Sstevel@tonic-gate 483*0Sstevel@tonic-gate if (verbose) { 484*0Sstevel@tonic-gate printf("Finding YP servers: "); 485*0Sstevel@tonic-gate fflush(stdout); 486*0Sstevel@tonic-gate count = 4; 487*0Sstevel@tonic-gate } 488*0Sstevel@tonic-gate 489*0Sstevel@tonic-gate if (err = yp_bind(domain_alias)) { 490*0Sstevel@tonic-gate fprintf(stderr, err_cant_bind, domain, yperr_string(err)); 491*0Sstevel@tonic-gate exit(1); 492*0Sstevel@tonic-gate } 493*0Sstevel@tonic-gate 494*0Sstevel@tonic-gate if (err = yp_first(domain_alias, ypservers, &outkey, &outkeylen, 495*0Sstevel@tonic-gate &val, &vallen)) { 496*0Sstevel@tonic-gate fprintf(stderr, err_cant_build_serverlist, yperr_string(err)); 497*0Sstevel@tonic-gate exit(1); 498*0Sstevel@tonic-gate } 499*0Sstevel@tonic-gate 500*0Sstevel@tonic-gate for (;;) { 501*0Sstevel@tonic-gate add_server(outkey, outkeylen); 502*0Sstevel@tonic-gate if (verbose) { 503*0Sstevel@tonic-gate printf(" %s", outkey); 504*0Sstevel@tonic-gate fflush(stdout); 505*0Sstevel@tonic-gate if (count++ == 8) { 506*0Sstevel@tonic-gate printf("\n"); 507*0Sstevel@tonic-gate count = 0; 508*0Sstevel@tonic-gate } 509*0Sstevel@tonic-gate } 510*0Sstevel@tonic-gate free(val); 511*0Sstevel@tonic-gate key = outkey; 512*0Sstevel@tonic-gate keylen = outkeylen; 513*0Sstevel@tonic-gate 514*0Sstevel@tonic-gate if (err = yp_next(domain_alias, ypservers, key, keylen, 515*0Sstevel@tonic-gate &outkey, &outkeylen, &val, &vallen)) { 516*0Sstevel@tonic-gate 517*0Sstevel@tonic-gate if (err == YPERR_NOMORE) { 518*0Sstevel@tonic-gate break; 519*0Sstevel@tonic-gate } else { 520*0Sstevel@tonic-gate fprintf(stderr, err_cant_build_serverlist, 521*0Sstevel@tonic-gate yperr_string(err)); 522*0Sstevel@tonic-gate exit(1); 523*0Sstevel@tonic-gate } 524*0Sstevel@tonic-gate } 525*0Sstevel@tonic-gate 526*0Sstevel@tonic-gate free(key); 527*0Sstevel@tonic-gate } 528*0Sstevel@tonic-gate if (count != 0) { 529*0Sstevel@tonic-gate if (verbose) 530*0Sstevel@tonic-gate printf("\n"); 531*0Sstevel@tonic-gate } 532*0Sstevel@tonic-gate } 533*0Sstevel@tonic-gate 534*0Sstevel@tonic-gate /* 535*0Sstevel@tonic-gate * This adds a single server to the server list. 536*0Sstevel@tonic-gate */ 537*0Sstevel@tonic-gate static void 538*0Sstevel@tonic-gate add_server(char *sname, int namelen) 539*0Sstevel@tonic-gate { 540*0Sstevel@tonic-gate struct server *ps; 541*0Sstevel@tonic-gate static unsigned long seq; 542*0Sstevel@tonic-gate static unsigned long xactid = 0; 543*0Sstevel@tonic-gate 544*0Sstevel@tonic-gate if (strcmp(sname, my_name) == 0) 545*0Sstevel@tonic-gate return; 546*0Sstevel@tonic-gate 547*0Sstevel@tonic-gate if (xactid == 0) { 548*0Sstevel@tonic-gate xactid_seed(&xactid); 549*0Sstevel@tonic-gate } 550*0Sstevel@tonic-gate 551*0Sstevel@tonic-gate if ((ps = (struct server *)malloc((unsigned)sizeof (struct server))) 552*0Sstevel@tonic-gate == (struct server *)NULL) { 553*0Sstevel@tonic-gate perror("yppush: malloc failure"); 554*0Sstevel@tonic-gate exit(1); 555*0Sstevel@tonic-gate } 556*0Sstevel@tonic-gate 557*0Sstevel@tonic-gate sname[namelen] = '\0'; 558*0Sstevel@tonic-gate strcpy(ps->svc_name, sname); 559*0Sstevel@tonic-gate ps->state = SSTAT_INIT; 560*0Sstevel@tonic-gate ps->status = 0; 561*0Sstevel@tonic-gate ps->oldvers = FALSE; 562*0Sstevel@tonic-gate ps->xactid = xactid + seq++; 563*0Sstevel@tonic-gate ps->pnext = server_list; 564*0Sstevel@tonic-gate server_list = ps; 565*0Sstevel@tonic-gate } 566*0Sstevel@tonic-gate 567*0Sstevel@tonic-gate /* 568*0Sstevel@tonic-gate * This sets the base range for the transaction ids used in speaking the the 569*0Sstevel@tonic-gate * server ypxfr processes. 570*0Sstevel@tonic-gate */ 571*0Sstevel@tonic-gate static void 572*0Sstevel@tonic-gate xactid_seed(unsigned long *xactid) 573*0Sstevel@tonic-gate { 574*0Sstevel@tonic-gate struct timeval t; 575*0Sstevel@tonic-gate 576*0Sstevel@tonic-gate if (gettimeofday(&t) == -1) { 577*0Sstevel@tonic-gate perror("yppush gettimeofday failure"); 578*0Sstevel@tonic-gate *xactid = 1234567; 579*0Sstevel@tonic-gate } else { 580*0Sstevel@tonic-gate *xactid = t.tv_sec; 581*0Sstevel@tonic-gate } 582*0Sstevel@tonic-gate } 583*0Sstevel@tonic-gate 584*0Sstevel@tonic-gate /* 585*0Sstevel@tonic-gate * This generates the channel which will be used as the listener process' 586*0Sstevel@tonic-gate * service rendezvous point, and comes up with a transient program number 587*0Sstevel@tonic-gate * for the use of the RPC messages from the ypxfr processes. 588*0Sstevel@tonic-gate */ 589*0Sstevel@tonic-gate static int 590*0Sstevel@tonic-gate generate_callback(unsigned long *program) 591*0Sstevel@tonic-gate { 592*0Sstevel@tonic-gate unsigned long prognum = 0x40000000, maxprognum; 593*0Sstevel@tonic-gate union { 594*0Sstevel@tonic-gate unsigned long p; 595*0Sstevel@tonic-gate unsigned char b[sizeof (unsigned long)]; 596*0Sstevel@tonic-gate } u; 597*0Sstevel@tonic-gate int ret, i; 598*0Sstevel@tonic-gate struct netconfig *nc4, *nc6, *nc; 599*0Sstevel@tonic-gate SVCXPRT *trans; 600*0Sstevel@tonic-gate 601*0Sstevel@tonic-gate nc4 = getnetconfigent("udp"); 602*0Sstevel@tonic-gate nc6 = getnetconfigent("udp6"); 603*0Sstevel@tonic-gate if (nc4 == 0 && nc6 == 0) { 604*0Sstevel@tonic-gate fprintf(stderr, 605*0Sstevel@tonic-gate "yppush: Could not get udp or udp6 netconfig entry\n"); 606*0Sstevel@tonic-gate exit(1); 607*0Sstevel@tonic-gate } 608*0Sstevel@tonic-gate 609*0Sstevel@tonic-gate transport4 = (nc4 == 0) ? 0 : svc_tli_create(RPC_ANYFD, nc4, 0, 0, 0); 610*0Sstevel@tonic-gate transport6 = (nc6 == 0) ? 0 : svc_tli_create(RPC_ANYFD, nc6, 0, 0, 0); 611*0Sstevel@tonic-gate if (transport4 == 0 && transport6 == 0) { 612*0Sstevel@tonic-gate fprintf(stderr, "yppush: Could not create server handle(s)\n"); 613*0Sstevel@tonic-gate exit(1); 614*0Sstevel@tonic-gate } 615*0Sstevel@tonic-gate 616*0Sstevel@tonic-gate /* Find the maximum possible program number using an unsigned long */ 617*0Sstevel@tonic-gate for (i = 0; i < sizeof (u.b); i++) 618*0Sstevel@tonic-gate u.b[i] = 0xff; 619*0Sstevel@tonic-gate maxprognum = u.p; 620*0Sstevel@tonic-gate 621*0Sstevel@tonic-gate if (transport4 != 0) { 622*0Sstevel@tonic-gate trans = transport4; 623*0Sstevel@tonic-gate nc = nc4; 624*0Sstevel@tonic-gate } else { 625*0Sstevel@tonic-gate trans = transport6; 626*0Sstevel@tonic-gate nc = nc6; 627*0Sstevel@tonic-gate } 628*0Sstevel@tonic-gate while (prognum < maxprognum && (ret = 629*0Sstevel@tonic-gate rpcb_set(prognum, YPPUSHVERS, nc, &trans->xp_ltaddr)) == 0) 630*0Sstevel@tonic-gate prognum++; 631*0Sstevel@tonic-gate 632*0Sstevel@tonic-gate if (ret == 0) { 633*0Sstevel@tonic-gate fprintf(stderr, "yppush: Could not create callback service\n"); 634*0Sstevel@tonic-gate exit(1); 635*0Sstevel@tonic-gate } else { 636*0Sstevel@tonic-gate if (trans == transport4 && transport6 != 0) { 637*0Sstevel@tonic-gate ret = rpcb_set(prognum, YPPUSHVERS, nc6, 638*0Sstevel@tonic-gate &transport6->xp_ltaddr); 639*0Sstevel@tonic-gate if (ret == 0) { 640*0Sstevel@tonic-gate fprintf(stderr, 641*0Sstevel@tonic-gate "yppush: Could not create udp6 callback service\n"); 642*0Sstevel@tonic-gate exit(1); 643*0Sstevel@tonic-gate } 644*0Sstevel@tonic-gate } 645*0Sstevel@tonic-gate *program = prognum; 646*0Sstevel@tonic-gate } 647*0Sstevel@tonic-gate 648*0Sstevel@tonic-gate return (ret); 649*0Sstevel@tonic-gate } 650*0Sstevel@tonic-gate 651*0Sstevel@tonic-gate /* 652*0Sstevel@tonic-gate * This is the main loop. Send messages to each server, 653*0Sstevel@tonic-gate * and then wait for a response. 654*0Sstevel@tonic-gate */ 655*0Sstevel@tonic-gate 656*0Sstevel@tonic-gate 657*0Sstevel@tonic-gate add_to_active() 658*0Sstevel@tonic-gate { 659*0Sstevel@tonic-gate struct server *ps; 660*0Sstevel@tonic-gate ps = server_list; 661*0Sstevel@tonic-gate if (ps == NULL) 662*0Sstevel@tonic-gate return (0); 663*0Sstevel@tonic-gate server_list = server_list->pnext; /* delete from server_list */ 664*0Sstevel@tonic-gate ps->pnext = active_list; 665*0Sstevel@tonic-gate active_list = ps; 666*0Sstevel@tonic-gate return (1); 667*0Sstevel@tonic-gate } 668*0Sstevel@tonic-gate 669*0Sstevel@tonic-gate delete_active(in) 670*0Sstevel@tonic-gate struct server *in; 671*0Sstevel@tonic-gate { 672*0Sstevel@tonic-gate struct server *p; 673*0Sstevel@tonic-gate struct server *n; 674*0Sstevel@tonic-gate if (in == active_list) { 675*0Sstevel@tonic-gate active_list = active_list->pnext; 676*0Sstevel@tonic-gate return (1); 677*0Sstevel@tonic-gate } 678*0Sstevel@tonic-gate p = active_list; 679*0Sstevel@tonic-gate for (n = active_list; n; n = n->pnext) { 680*0Sstevel@tonic-gate if (in == n) { 681*0Sstevel@tonic-gate p->pnext = n->pnext; 682*0Sstevel@tonic-gate return (0); 683*0Sstevel@tonic-gate 684*0Sstevel@tonic-gate } 685*0Sstevel@tonic-gate p = n; 686*0Sstevel@tonic-gate } 687*0Sstevel@tonic-gate return (-1); 688*0Sstevel@tonic-gate } 689*0Sstevel@tonic-gate 690*0Sstevel@tonic-gate void 691*0Sstevel@tonic-gate main_loop(program) 692*0Sstevel@tonic-gate unsigned long program; 693*0Sstevel@tonic-gate { 694*0Sstevel@tonic-gate pollfd_t *pollset = NULL; 695*0Sstevel@tonic-gate int npollfds = 0; 696*0Sstevel@tonic-gate int pollret; 697*0Sstevel@tonic-gate struct server *ps; 698*0Sstevel@tonic-gate long error; 699*0Sstevel@tonic-gate int hpar; /* this times par count */ 700*0Sstevel@tonic-gate int i; 701*0Sstevel@tonic-gate int j; 702*0Sstevel@tonic-gate int time_now; 703*0Sstevel@tonic-gate int docb; 704*0Sstevel@tonic-gate int actives = 0; 705*0Sstevel@tonic-gate int dead = 0; 706*0Sstevel@tonic-gate 707*0Sstevel@tonic-gate if (grace_period < MIN_GRACE) 708*0Sstevel@tonic-gate grace_period = MIN_GRACE; 709*0Sstevel@tonic-gate if (transport4 != 0) { 710*0Sstevel@tonic-gate if (!svc_reg(transport4, program, YPPUSHVERS, 711*0Sstevel@tonic-gate listener_dispatch, 0)) { 712*0Sstevel@tonic-gate fprintf(stderr, 713*0Sstevel@tonic-gate "Can't set up transient udp callback server.\n"); 714*0Sstevel@tonic-gate } 715*0Sstevel@tonic-gate } 716*0Sstevel@tonic-gate if (transport6 != 0) { 717*0Sstevel@tonic-gate if (!svc_reg(transport6, program, YPPUSHVERS, 718*0Sstevel@tonic-gate listener_dispatch, 0)) { 719*0Sstevel@tonic-gate fprintf(stderr, 720*0Sstevel@tonic-gate "Can't set up transient udp6 callback server.\n"); 721*0Sstevel@tonic-gate } 722*0Sstevel@tonic-gate } 723*0Sstevel@tonic-gate for (;;) { 724*0Sstevel@tonic-gate time_now = time(0); 725*0Sstevel@tonic-gate if (server_list == NULL) { 726*0Sstevel@tonic-gate actives = 0; 727*0Sstevel@tonic-gate dead = 0; 728*0Sstevel@tonic-gate for (ps = active_list; ps; ps = ps->pnext) 729*0Sstevel@tonic-gate if (ps->state == SSTAT_CALLED) { 730*0Sstevel@tonic-gate if ((time_now - ps->start_time) < 731*0Sstevel@tonic-gate grace_period) 732*0Sstevel@tonic-gate actives++; 733*0Sstevel@tonic-gate else 734*0Sstevel@tonic-gate dead++; 735*0Sstevel@tonic-gate } 736*0Sstevel@tonic-gate if (actives == 0) { 737*0Sstevel@tonic-gate if (verbose) { 738*0Sstevel@tonic-gate printf("terminating %d dead\n", dead); 739*0Sstevel@tonic-gate fflush(stdout); 740*0Sstevel@tonic-gate } 741*0Sstevel@tonic-gate 742*0Sstevel@tonic-gate for (ps = active_list; ps; ps = ps->pnext) 743*0Sstevel@tonic-gate if (ps->state == SSTAT_CALLED) { 744*0Sstevel@tonic-gate if ((time_now - ps->start_time) 745*0Sstevel@tonic-gate >= grace_period) { 746*0Sstevel@tonic-gate if (verbose) { 747*0Sstevel@tonic-gate printf( 748*0Sstevel@tonic-gate "no response from %s -- grace of %d seconds expired.\n", 749*0Sstevel@tonic-gate ps->svc_name, grace_period); 750*0Sstevel@tonic-gate fflush(stdout); 751*0Sstevel@tonic-gate } 752*0Sstevel@tonic-gate fprintf(stderr, 753*0Sstevel@tonic-gate "No response from ypxfr on %s\n", ps->svc_name); 754*0Sstevel@tonic-gate } 755*0Sstevel@tonic-gate } 756*0Sstevel@tonic-gate break; 757*0Sstevel@tonic-gate } 758*0Sstevel@tonic-gate } 759*0Sstevel@tonic-gate actives = 0; 760*0Sstevel@tonic-gate for (ps = active_list; ps; ps = ps->pnext) { 761*0Sstevel@tonic-gate if (ps->state == SSTAT_CALLED) { 762*0Sstevel@tonic-gate if ((time_now - ps->start_time) 763*0Sstevel@tonic-gate < grace_period) { 764*0Sstevel@tonic-gate actives++; 765*0Sstevel@tonic-gate 766*0Sstevel@tonic-gate if (verbose) { 767*0Sstevel@tonic-gate printf( 768*0Sstevel@tonic-gate "No response yet from ypxfr on %s\n", ps->svc_name); 769*0Sstevel@tonic-gate fflush(stdout); 770*0Sstevel@tonic-gate } 771*0Sstevel@tonic-gate } 772*0Sstevel@tonic-gate } else { 773*0Sstevel@tonic-gate if (verbose) { 774*0Sstevel@tonic-gate printf("Deactivating %s\n", 775*0Sstevel@tonic-gate ps->svc_name); 776*0Sstevel@tonic-gate fflush(stdout); 777*0Sstevel@tonic-gate } 778*0Sstevel@tonic-gate delete_active(ps); 779*0Sstevel@tonic-gate } 780*0Sstevel@tonic-gate } 781*0Sstevel@tonic-gate 782*0Sstevel@tonic-gate /* add someone to the active list keep up with curpar */ 783*0Sstevel@tonic-gate for (i = 0; i < (curpar - actives); i++) { 784*0Sstevel@tonic-gate if (add_to_active()) { 785*0Sstevel@tonic-gate ps = active_list; 786*0Sstevel@tonic-gate ps->state = send_message(ps, program, &error); 787*0Sstevel@tonic-gate print_state_msg(ps, error); 788*0Sstevel@tonic-gate if (ps->state != SSTAT_CALLED) 789*0Sstevel@tonic-gate delete_active(ps); /* zorch it */ 790*0Sstevel@tonic-gate else 791*0Sstevel@tonic-gate ps->start_time = time(0); /* set time */ 792*0Sstevel@tonic-gate } 793*0Sstevel@tonic-gate } 794*0Sstevel@tonic-gate docb = 0; 795*0Sstevel@tonic-gate for (ps = active_list; ps; ps = ps->pnext) 796*0Sstevel@tonic-gate if (ps->state == SSTAT_CALLED) { 797*0Sstevel@tonic-gate docb = 1; 798*0Sstevel@tonic-gate break; 799*0Sstevel@tonic-gate } 800*0Sstevel@tonic-gate if (docb == 0) { 801*0Sstevel@tonic-gate if (verbose) { 802*0Sstevel@tonic-gate printf("No one to wait for this pass.\n"); 803*0Sstevel@tonic-gate fflush(stdout); 804*0Sstevel@tonic-gate } 805*0Sstevel@tonic-gate continue; /* try curpar more */ 806*0Sstevel@tonic-gate } 807*0Sstevel@tonic-gate 808*0Sstevel@tonic-gate if (npollfds != svc_max_pollfd) { 809*0Sstevel@tonic-gate pollset = realloc(pollset, 810*0Sstevel@tonic-gate sizeof (pollfd_t) * svc_max_pollfd); 811*0Sstevel@tonic-gate npollfds = svc_max_pollfd; 812*0Sstevel@tonic-gate } 813*0Sstevel@tonic-gate 814*0Sstevel@tonic-gate /* 815*0Sstevel@tonic-gate * Get existing array of pollfd's, should really compress 816*0Sstevel@tonic-gate * this but it shouldn't get very large (or sparse). 817*0Sstevel@tonic-gate */ 818*0Sstevel@tonic-gate (void) memcpy(pollset, svc_pollfd, 819*0Sstevel@tonic-gate sizeof (pollfd_t) * svc_max_pollfd); 820*0Sstevel@tonic-gate 821*0Sstevel@tonic-gate errno = 0; 822*0Sstevel@tonic-gate switch (pollret = poll(pollset, npollfds, MIN_GRACE * 1000)) { 823*0Sstevel@tonic-gate case -1: 824*0Sstevel@tonic-gate if (errno != EINTR) { 825*0Sstevel@tonic-gate (void) perror("main loop select"); 826*0Sstevel@tonic-gate } 827*0Sstevel@tonic-gate break; 828*0Sstevel@tonic-gate 829*0Sstevel@tonic-gate case 0: 830*0Sstevel@tonic-gate if (verbose) { 831*0Sstevel@tonic-gate (void) printf("timeout in main loop select.\n"); 832*0Sstevel@tonic-gate fflush(stdout); 833*0Sstevel@tonic-gate } 834*0Sstevel@tonic-gate break; 835*0Sstevel@tonic-gate 836*0Sstevel@tonic-gate default: 837*0Sstevel@tonic-gate svc_getreq_poll(pollset, pollret); 838*0Sstevel@tonic-gate break; 839*0Sstevel@tonic-gate } /* switch */ 840*0Sstevel@tonic-gate } /* for */ 841*0Sstevel@tonic-gate } 842*0Sstevel@tonic-gate 843*0Sstevel@tonic-gate /* 844*0Sstevel@tonic-gate * This does the listener process cleanup and process exit. 845*0Sstevel@tonic-gate */ 846*0Sstevel@tonic-gate static void 847*0Sstevel@tonic-gate listener_exit(unsigned long program, int stat) 848*0Sstevel@tonic-gate { 849*0Sstevel@tonic-gate svc_unreg(program, YPPUSHVERS); 850*0Sstevel@tonic-gate exit(stat); 851*0Sstevel@tonic-gate } 852*0Sstevel@tonic-gate 853*0Sstevel@tonic-gate /* 854*0Sstevel@tonic-gate * This is the listener process' RPC service dispatcher. 855*0Sstevel@tonic-gate */ 856*0Sstevel@tonic-gate static void 857*0Sstevel@tonic-gate listener_dispatch(struct svc_req *rqstp, SVCXPRT *transp) 858*0Sstevel@tonic-gate { 859*0Sstevel@tonic-gate switch (rqstp->rq_proc) { 860*0Sstevel@tonic-gate 861*0Sstevel@tonic-gate case YPPUSHPROC_NULL: 862*0Sstevel@tonic-gate if (!svc_sendreply(transp, xdr_void, 0)) { 863*0Sstevel@tonic-gate fprintf(stderr, "Can't reply to rpc call.\n"); 864*0Sstevel@tonic-gate } 865*0Sstevel@tonic-gate break; 866*0Sstevel@tonic-gate 867*0Sstevel@tonic-gate case YPPUSHPROC_XFRRESP: 868*0Sstevel@tonic-gate get_xfr_response(transp); 869*0Sstevel@tonic-gate break; 870*0Sstevel@tonic-gate 871*0Sstevel@tonic-gate default: 872*0Sstevel@tonic-gate svcerr_noproc(transp); 873*0Sstevel@tonic-gate break; 874*0Sstevel@tonic-gate } 875*0Sstevel@tonic-gate } 876*0Sstevel@tonic-gate 877*0Sstevel@tonic-gate 878*0Sstevel@tonic-gate /* 879*0Sstevel@tonic-gate * This dumps a server state message to stdout. It is called in cases where 880*0Sstevel@tonic-gate * we have no expectation of receiving a callback from the remote ypxfr. 881*0Sstevel@tonic-gate */ 882*0Sstevel@tonic-gate static void 883*0Sstevel@tonic-gate print_state_msg(struct server *s, long e) 884*0Sstevel@tonic-gate { 885*0Sstevel@tonic-gate struct state_duple *sd; 886*0Sstevel@tonic-gate 887*0Sstevel@tonic-gate if (s->state == SSTAT_SYSTEM) 888*0Sstevel@tonic-gate return; /* already printed */ 889*0Sstevel@tonic-gate 890*0Sstevel@tonic-gate if (!verbose && (s->state == SSTAT_RESPONDED || 891*0Sstevel@tonic-gate s->state == SSTAT_CALLED)) 892*0Sstevel@tonic-gate return; 893*0Sstevel@tonic-gate 894*0Sstevel@tonic-gate for (sd = state_duples; sd->state_msg; sd++) { 895*0Sstevel@tonic-gate if (sd->state == s->state) { 896*0Sstevel@tonic-gate printf(sd->state_msg, s->svc_name); 897*0Sstevel@tonic-gate 898*0Sstevel@tonic-gate if (s->state == SSTAT_RPC) { 899*0Sstevel@tonic-gate rpcerr_msg((enum clnt_stat) e); 900*0Sstevel@tonic-gate } 901*0Sstevel@tonic-gate 902*0Sstevel@tonic-gate printf("\n"); 903*0Sstevel@tonic-gate fflush(stdout); 904*0Sstevel@tonic-gate return; 905*0Sstevel@tonic-gate } 906*0Sstevel@tonic-gate } 907*0Sstevel@tonic-gate 908*0Sstevel@tonic-gate fprintf(stderr, "yppush: Bad server state value %d.\n", s->state); 909*0Sstevel@tonic-gate } 910*0Sstevel@tonic-gate 911*0Sstevel@tonic-gate /* 912*0Sstevel@tonic-gate * This dumps a transfer status message to stdout. It is called in 913*0Sstevel@tonic-gate * response to a received RPC message from the called ypxfr. 914*0Sstevel@tonic-gate */ 915*0Sstevel@tonic-gate static void 916*0Sstevel@tonic-gate print_callback_msg(struct server *s) 917*0Sstevel@tonic-gate { 918*0Sstevel@tonic-gate register struct status_duple *sd; 919*0Sstevel@tonic-gate 920*0Sstevel@tonic-gate if (!verbose && 921*0Sstevel@tonic-gate (s->status == YPPUSH_AGE) || 922*0Sstevel@tonic-gate (s->status == YPPUSH_SUCC)) 923*0Sstevel@tonic-gate 924*0Sstevel@tonic-gate return; 925*0Sstevel@tonic-gate 926*0Sstevel@tonic-gate for (sd = status_duples; sd->status_msg; sd++) { 927*0Sstevel@tonic-gate 928*0Sstevel@tonic-gate if (sd->status == s->status) { 929*0Sstevel@tonic-gate printf("Status received from ypxfr on %s:\n\t%s\n", 930*0Sstevel@tonic-gate s->svc_name, sd->status_msg); 931*0Sstevel@tonic-gate fflush(stdout); 932*0Sstevel@tonic-gate return; 933*0Sstevel@tonic-gate } 934*0Sstevel@tonic-gate } 935*0Sstevel@tonic-gate 936*0Sstevel@tonic-gate fprintf(stderr, "yppush listener: Garbage transaction " 937*0Sstevel@tonic-gate "status (value %d) from ypxfr on %s.\n", 938*0Sstevel@tonic-gate (int)s->status, s->svc_name); 939*0Sstevel@tonic-gate } 940*0Sstevel@tonic-gate 941*0Sstevel@tonic-gate /* 942*0Sstevel@tonic-gate * This dumps an RPC error message to stdout. This is basically a rewrite 943*0Sstevel@tonic-gate * of clnt_perrno, but writes to stdout instead of stderr. 944*0Sstevel@tonic-gate */ 945*0Sstevel@tonic-gate static void 946*0Sstevel@tonic-gate rpcerr_msg(enum clnt_stat e) 947*0Sstevel@tonic-gate { 948*0Sstevel@tonic-gate struct rpcerr_duple *rd; 949*0Sstevel@tonic-gate 950*0Sstevel@tonic-gate for (rd = rpcerr_duples; rd->rpc_msg; rd++) { 951*0Sstevel@tonic-gate 952*0Sstevel@tonic-gate if (rd->rpc_stat == e) { 953*0Sstevel@tonic-gate printf(rd->rpc_msg); 954*0Sstevel@tonic-gate return; 955*0Sstevel@tonic-gate } 956*0Sstevel@tonic-gate } 957*0Sstevel@tonic-gate 958*0Sstevel@tonic-gate fprintf(stderr, "Bad error code passed to rpcerr_msg: %d.\n", e); 959*0Sstevel@tonic-gate } 960*0Sstevel@tonic-gate 961*0Sstevel@tonic-gate /* 962*0Sstevel@tonic-gate * This picks up the response from the ypxfr process which has been started 963*0Sstevel@tonic-gate * up on the remote node. The response status must be non-zero, otherwise 964*0Sstevel@tonic-gate * the status will be set to "ypxfr error". 965*0Sstevel@tonic-gate */ 966*0Sstevel@tonic-gate static void 967*0Sstevel@tonic-gate get_xfr_response(SVCXPRT *transp) 968*0Sstevel@tonic-gate { 969*0Sstevel@tonic-gate struct yppushresp_xfr resp; 970*0Sstevel@tonic-gate register struct server *s; 971*0Sstevel@tonic-gate 972*0Sstevel@tonic-gate if (!svc_getargs(transp, (xdrproc_t)xdr_yppushresp_xfr, 973*0Sstevel@tonic-gate (caddr_t)&resp)) { 974*0Sstevel@tonic-gate svcerr_decode(transp); 975*0Sstevel@tonic-gate return; 976*0Sstevel@tonic-gate } 977*0Sstevel@tonic-gate 978*0Sstevel@tonic-gate if (!svc_sendreply(transp, xdr_void, 0)) { 979*0Sstevel@tonic-gate (void) fprintf(stderr, "Can't reply to rpc call.\n"); 980*0Sstevel@tonic-gate } 981*0Sstevel@tonic-gate 982*0Sstevel@tonic-gate for (s = active_list; s; s = s->pnext) { 983*0Sstevel@tonic-gate 984*0Sstevel@tonic-gate if (s->xactid == resp.transid) { 985*0Sstevel@tonic-gate s->status = resp.status ? resp.status: YPPUSH_XFRERR; 986*0Sstevel@tonic-gate print_callback_msg(s); 987*0Sstevel@tonic-gate s->state = SSTAT_RESPONDED; 988*0Sstevel@tonic-gate return; 989*0Sstevel@tonic-gate } 990*0Sstevel@tonic-gate } 991*0Sstevel@tonic-gate } 992*0Sstevel@tonic-gate 993*0Sstevel@tonic-gate /* 994*0Sstevel@tonic-gate * This sends a message to a single ypserv process. The return value is 995*0Sstevel@tonic-gate * a state value. If the RPC call fails because of a version 996*0Sstevel@tonic-gate * mismatch, we'll assume that we're talking to a version 1 ypserv process, 997*0Sstevel@tonic-gate * and will send him an old "YPPROC_GET" request, as was defined in the 998*0Sstevel@tonic-gate * earlier version of yp_prot.h 999*0Sstevel@tonic-gate */ 1000*0Sstevel@tonic-gate static unsigned short 1001*0Sstevel@tonic-gate send_message(struct server *ps, unsigned long program, long *err) 1002*0Sstevel@tonic-gate { 1003*0Sstevel@tonic-gate struct ypreq_newxfr req; 1004*0Sstevel@tonic-gate struct ypreq_xfr oldreq; 1005*0Sstevel@tonic-gate enum clnt_stat s; 1006*0Sstevel@tonic-gate struct rpc_err rpcerr; 1007*0Sstevel@tonic-gate 1008*0Sstevel@tonic-gate if ((ps->domb.dom_client = __yp_clnt_create_rsvdport(ps->svc_name, 1009*0Sstevel@tonic-gate YPPROG, YPVERS, 1010*0Sstevel@tonic-gate (char *)NULL, 1011*0Sstevel@tonic-gate 0, 0)) == NULL) { 1012*0Sstevel@tonic-gate 1013*0Sstevel@tonic-gate if (rpc_createerr.cf_stat == RPC_PROGNOTREGISTERED) { 1014*0Sstevel@tonic-gate return (SSTAT_PROGNOTREG); 1015*0Sstevel@tonic-gate } else { 1016*0Sstevel@tonic-gate printf("Error talking to %s: ", ps->svc_name); 1017*0Sstevel@tonic-gate rpcerr_msg(rpc_createerr.cf_stat); 1018*0Sstevel@tonic-gate printf("\n"); 1019*0Sstevel@tonic-gate fflush(stdout); 1020*0Sstevel@tonic-gate return (SSTAT_SYSTEM); 1021*0Sstevel@tonic-gate } 1022*0Sstevel@tonic-gate } 1023*0Sstevel@tonic-gate 1024*0Sstevel@tonic-gate if (sysinfo(SI_HOSTNAME, my_name, sizeof (my_name)) == -1) { 1025*0Sstevel@tonic-gate return (SSTAT_RSCRC); 1026*0Sstevel@tonic-gate } 1027*0Sstevel@tonic-gate 1028*0Sstevel@tonic-gate if (!oldxfr) { 1029*0Sstevel@tonic-gate req.ypxfr_domain = domain; 1030*0Sstevel@tonic-gate req.ypxfr_map = map; 1031*0Sstevel@tonic-gate req.ypxfr_ordernum = 0; 1032*0Sstevel@tonic-gate req.ypxfr_owner = my_name; 1033*0Sstevel@tonic-gate req.name = ps->svc_name; 1034*0Sstevel@tonic-gate /* 1035*0Sstevel@tonic-gate * the creation of field req.name, instead of ypreq_xfr (old) 1036*0Sstevel@tonic-gate * req.port, does not make any sense. it doesn't give any 1037*0Sstevel@tonic-gate * information to receiving ypserv except its own name !! 1038*0Sstevel@tonic-gate * new ypserv duplicates work for YPPROC_XFR and YPPROC_NEWXFR 1039*0Sstevel@tonic-gate */ 1040*0Sstevel@tonic-gate req.transid = ps->xactid; 1041*0Sstevel@tonic-gate req.proto = program; 1042*0Sstevel@tonic-gate s = (enum clnt_stat) clnt_call(ps->domb.dom_client, 1043*0Sstevel@tonic-gate YPPROC_NEWXFR, 1044*0Sstevel@tonic-gate (xdrproc_t)xdr_ypreq_newxfr, 1045*0Sstevel@tonic-gate (caddr_t)&req, 1046*0Sstevel@tonic-gate xdr_void, 0, timeout); 1047*0Sstevel@tonic-gate } 1048*0Sstevel@tonic-gate 1049*0Sstevel@tonic-gate clnt_geterr(ps->domb.dom_client, &rpcerr); 1050*0Sstevel@tonic-gate 1051*0Sstevel@tonic-gate if (s == RPC_PROCUNAVAIL) { 1052*0Sstevel@tonic-gate oldreq.ypxfr_domain = domain; 1053*0Sstevel@tonic-gate oldreq.ypxfr_map = map; 1054*0Sstevel@tonic-gate oldreq.ypxfr_ordernum = 0; 1055*0Sstevel@tonic-gate oldreq.ypxfr_owner = my_name; 1056*0Sstevel@tonic-gate oldreq.transid = ps->xactid; 1057*0Sstevel@tonic-gate oldreq.proto = program; 1058*0Sstevel@tonic-gate oldreq.port = 0; 1059*0Sstevel@tonic-gate s = (enum clnt_stat) clnt_call(ps->domb.dom_client, 1060*0Sstevel@tonic-gate YPPROC_XFR, 1061*0Sstevel@tonic-gate (xdrproc_t)xdr_ypreq_xfr, 1062*0Sstevel@tonic-gate (caddr_t)&oldreq, 1063*0Sstevel@tonic-gate xdr_void, 0, timeout); 1064*0Sstevel@tonic-gate clnt_geterr(ps->domb.dom_client, &rpcerr); 1065*0Sstevel@tonic-gate } 1066*0Sstevel@tonic-gate 1067*0Sstevel@tonic-gate clnt_destroy(ps->domb.dom_client); 1068*0Sstevel@tonic-gate 1069*0Sstevel@tonic-gate if (s == RPC_SUCCESS) { 1070*0Sstevel@tonic-gate return (SSTAT_CALLED); 1071*0Sstevel@tonic-gate } else { 1072*0Sstevel@tonic-gate *err = (long)rpcerr.re_status; 1073*0Sstevel@tonic-gate return (SSTAT_RPC); 1074*0Sstevel@tonic-gate } 1075*0Sstevel@tonic-gate /*NOTREACHED*/ 1076*0Sstevel@tonic-gate } 1077*0Sstevel@tonic-gate 1078*0Sstevel@tonic-gate /* 1079*0Sstevel@tonic-gate * FUNCTION: is_yptol_mode(); 1080*0Sstevel@tonic-gate * 1081*0Sstevel@tonic-gate * DESCRIPTION: Determines if we should run in N2L or traditional mode based 1082*0Sstevel@tonic-gate * on the presence of the N2L mapping file. 1083*0Sstevel@tonic-gate * 1084*0Sstevel@tonic-gate * This is a copy of a function from libnisdb. If more than this 1085*0Sstevel@tonic-gate * one function become required it may be worth linking the 1086*0Sstevel@tonic-gate * entire lib. 1087*0Sstevel@tonic-gate * 1088*0Sstevel@tonic-gate * INPUTS: Nothing 1089*0Sstevel@tonic-gate * 1090*0Sstevel@tonic-gate * OUTPUTS: TRUE = Run in N2L mode 1091*0Sstevel@tonic-gate * FALSE = Run in traditional mode. 1092*0Sstevel@tonic-gate */ 1093*0Sstevel@tonic-gate bool_t 1094*0Sstevel@tonic-gate is_yptol_mode() 1095*0Sstevel@tonic-gate { 1096*0Sstevel@tonic-gate struct stat filestat; 1097*0Sstevel@tonic-gate 1098*0Sstevel@tonic-gate if (stat(NTOL_MAP_FILE, &filestat) != -1) 1099*0Sstevel@tonic-gate return (TRUE); 1100*0Sstevel@tonic-gate 1101*0Sstevel@tonic-gate return (FALSE); 1102*0Sstevel@tonic-gate } 1103