1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 28*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate /* 31*7c478bd9Sstevel@tonic-gate * Portions of this source code were derived from Berkeley 4.3 BSD 32*7c478bd9Sstevel@tonic-gate * under license from the Regents of the University of California. 33*7c478bd9Sstevel@tonic-gate */ 34*7c478bd9Sstevel@tonic-gate 35*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 36*7c478bd9Sstevel@tonic-gate 37*7c478bd9Sstevel@tonic-gate /* 38*7c478bd9Sstevel@tonic-gate * This contains the mainline code for the YP server. Data 39*7c478bd9Sstevel@tonic-gate * structures which are process-global are also in this module. 40*7c478bd9Sstevel@tonic-gate */ 41*7c478bd9Sstevel@tonic-gate 42*7c478bd9Sstevel@tonic-gate /* this is so that ypserv will compile under 5.5 */ 43*7c478bd9Sstevel@tonic-gate #define _SVID_GETTOD 44*7c478bd9Sstevel@tonic-gate #include <sys/time.h> 45*7c478bd9Sstevel@tonic-gate extern int gettimeofday(struct timeval *); 46*7c478bd9Sstevel@tonic-gate 47*7c478bd9Sstevel@tonic-gate #include "ypsym.h" 48*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 49*7c478bd9Sstevel@tonic-gate #include <sys/wait.h> 50*7c478bd9Sstevel@tonic-gate #include <fcntl.h> 51*7c478bd9Sstevel@tonic-gate #include <rpc/rpc.h> 52*7c478bd9Sstevel@tonic-gate #include <netconfig.h> 53*7c478bd9Sstevel@tonic-gate #include <netdir.h> 54*7c478bd9Sstevel@tonic-gate #include <sys/select.h> 55*7c478bd9Sstevel@tonic-gate #include <stdlib.h> 56*7c478bd9Sstevel@tonic-gate #include <unistd.h> 57*7c478bd9Sstevel@tonic-gate #include <stdio.h> 58*7c478bd9Sstevel@tonic-gate #include <stdarg.h> 59*7c478bd9Sstevel@tonic-gate #include <signal.h> 60*7c478bd9Sstevel@tonic-gate #include "shim.h" 61*7c478bd9Sstevel@tonic-gate #include "yptol.h" 62*7c478bd9Sstevel@tonic-gate #include <syslog.h> 63*7c478bd9Sstevel@tonic-gate 64*7c478bd9Sstevel@tonic-gate static char register_failed[] = "ypserv: Unable to register service for "; 65*7c478bd9Sstevel@tonic-gate bool silent = TRUE; 66*7c478bd9Sstevel@tonic-gate 67*7c478bd9Sstevel@tonic-gate /* 68*7c478bd9Sstevel@tonic-gate * client_setup_failure will be TRUE, if setup of the 69*7c478bd9Sstevel@tonic-gate * connection to rpc.nisd_resolv failed 70*7c478bd9Sstevel@tonic-gate */ 71*7c478bd9Sstevel@tonic-gate bool client_setup_failure = FALSE; 72*7c478bd9Sstevel@tonic-gate 73*7c478bd9Sstevel@tonic-gate /* N2L options */ 74*7c478bd9Sstevel@tonic-gate bool init_dit = FALSE; 75*7c478bd9Sstevel@tonic-gate bool init_containers = FALSE; 76*7c478bd9Sstevel@tonic-gate bool init_maps = FALSE; 77*7c478bd9Sstevel@tonic-gate char **ldapCLA = NULL; 78*7c478bd9Sstevel@tonic-gate 79*7c478bd9Sstevel@tonic-gate /* For DNS forwarding command line option (-d) */ 80*7c478bd9Sstevel@tonic-gate bool dnsforward = FALSE; 81*7c478bd9Sstevel@tonic-gate int resolv_pid = 0; 82*7c478bd9Sstevel@tonic-gate CLIENT *resolv_client = NULL; 83*7c478bd9Sstevel@tonic-gate char *resolv_tp = "ticots"; 84*7c478bd9Sstevel@tonic-gate 85*7c478bd9Sstevel@tonic-gate #ifdef MINUS_C_OPTION 86*7c478bd9Sstevel@tonic-gate /* For cluster support (-c) */ 87*7c478bd9Sstevel@tonic-gate bool multiflag = FALSE; 88*7c478bd9Sstevel@tonic-gate #endif 89*7c478bd9Sstevel@tonic-gate 90*7c478bd9Sstevel@tonic-gate static char logfile[] = "/var/yp/ypserv.log"; 91*7c478bd9Sstevel@tonic-gate void logprintf(char *format, ...); 92*7c478bd9Sstevel@tonic-gate 93*7c478bd9Sstevel@tonic-gate static void ypexit(void); 94*7c478bd9Sstevel@tonic-gate static void ypinit(int argc, char **argv); 95*7c478bd9Sstevel@tonic-gate static void ypdispatch(struct svc_req *rqstp, SVCXPRT *transp); 96*7c478bd9Sstevel@tonic-gate static void ypolddispatch(struct svc_req *rqstp, SVCXPRT *transp); 97*7c478bd9Sstevel@tonic-gate static void ypget_command_line_args(int argc, char **argv); 98*7c478bd9Sstevel@tonic-gate extern void setup_resolv(bool *fwding, int *child, 99*7c478bd9Sstevel@tonic-gate CLIENT **client, char *tp_type, long prognum); 100*7c478bd9Sstevel@tonic-gate static void cleanup_resolv(int); 101*7c478bd9Sstevel@tonic-gate 102*7c478bd9Sstevel@tonic-gate /* 103*7c478bd9Sstevel@tonic-gate * This is the main line code for the yp server. 104*7c478bd9Sstevel@tonic-gate */ 105*7c478bd9Sstevel@tonic-gate int 106*7c478bd9Sstevel@tonic-gate main(int argc, char **argv) 107*7c478bd9Sstevel@tonic-gate { 108*7c478bd9Sstevel@tonic-gate if (geteuid() != 0) { 109*7c478bd9Sstevel@tonic-gate fprintf(stderr, "must be root to run %s\n", argv[0]); 110*7c478bd9Sstevel@tonic-gate exit(1); 111*7c478bd9Sstevel@tonic-gate } 112*7c478bd9Sstevel@tonic-gate 113*7c478bd9Sstevel@tonic-gate /* Set up shop */ 114*7c478bd9Sstevel@tonic-gate ypinit(argc, argv); 115*7c478bd9Sstevel@tonic-gate 116*7c478bd9Sstevel@tonic-gate /* If requested set up the N2L maps. May take a while */ 117*7c478bd9Sstevel@tonic-gate if (init_dit) 118*7c478bd9Sstevel@tonic-gate if (FAILURE == dump_maps_to_dit(init_containers)) { 119*7c478bd9Sstevel@tonic-gate fprintf(stderr, "Fatal error dumping maps to DIT." 120*7c478bd9Sstevel@tonic-gate " See syslog and LDAP server logs for details.\n"); 121*7c478bd9Sstevel@tonic-gate exit(1); 122*7c478bd9Sstevel@tonic-gate } 123*7c478bd9Sstevel@tonic-gate 124*7c478bd9Sstevel@tonic-gate if (init_maps) 125*7c478bd9Sstevel@tonic-gate if (FAILURE == dump_dit_to_maps()) { 126*7c478bd9Sstevel@tonic-gate fprintf(stderr, "Fatal error dumping DIT to maps." 127*7c478bd9Sstevel@tonic-gate " See syslog and LDAP server logs for details.\n"); 128*7c478bd9Sstevel@tonic-gate exit(1); 129*7c478bd9Sstevel@tonic-gate } 130*7c478bd9Sstevel@tonic-gate 131*7c478bd9Sstevel@tonic-gate /* 132*7c478bd9Sstevel@tonic-gate * If we were asked to init the maps now exit. User will then use 133*7c478bd9Sstevel@tonic-gate * ypstart to restart ypserv and all the other NIS daemons. 134*7c478bd9Sstevel@tonic-gate */ 135*7c478bd9Sstevel@tonic-gate if (init_dit || init_maps) { 136*7c478bd9Sstevel@tonic-gate printf("Map setup complete. Please now restart NIS daemons " 137*7c478bd9Sstevel@tonic-gate "with ypstart.\n"); 138*7c478bd9Sstevel@tonic-gate exit(0); 139*7c478bd9Sstevel@tonic-gate } 140*7c478bd9Sstevel@tonic-gate 141*7c478bd9Sstevel@tonic-gate svc_run(); 142*7c478bd9Sstevel@tonic-gate 143*7c478bd9Sstevel@tonic-gate /* 144*7c478bd9Sstevel@tonic-gate * This is stupid, but the compiler likes to warn us about the 145*7c478bd9Sstevel@tonic-gate * absence of returns from main() 146*7c478bd9Sstevel@tonic-gate */ 147*7c478bd9Sstevel@tonic-gate return (0); 148*7c478bd9Sstevel@tonic-gate } 149*7c478bd9Sstevel@tonic-gate 150*7c478bd9Sstevel@tonic-gate typedef struct { 151*7c478bd9Sstevel@tonic-gate char *netid; 152*7c478bd9Sstevel@tonic-gate int fd; 153*7c478bd9Sstevel@tonic-gate int olddispatch; /* Register on protocol version 1 ? */ 154*7c478bd9Sstevel@tonic-gate int class; /* Other services that must succeed */ 155*7c478bd9Sstevel@tonic-gate SVCXPRT *xprt; 156*7c478bd9Sstevel@tonic-gate int ok; /* Registered successfully ? */ 157*7c478bd9Sstevel@tonic-gate } ypservice_t; 158*7c478bd9Sstevel@tonic-gate 159*7c478bd9Sstevel@tonic-gate ypservice_t service[] = { 160*7c478bd9Sstevel@tonic-gate { "udp", -1, 1, 4, 0, 0 }, 161*7c478bd9Sstevel@tonic-gate { "tcp", -1, 1, 4, 0, 0 }, 162*7c478bd9Sstevel@tonic-gate { "udp6", -1, 0, 6, 0, 0 }, 163*7c478bd9Sstevel@tonic-gate { "tcp6", -1, 0, 6, 0, 0 } 164*7c478bd9Sstevel@tonic-gate }; 165*7c478bd9Sstevel@tonic-gate 166*7c478bd9Sstevel@tonic-gate #define MAXSERVICES (sizeof (service)/sizeof (service[0])) 167*7c478bd9Sstevel@tonic-gate 168*7c478bd9Sstevel@tonic-gate int service_classes[MAXSERVICES]; 169*7c478bd9Sstevel@tonic-gate 170*7c478bd9Sstevel@tonic-gate /* 171*7c478bd9Sstevel@tonic-gate * Does startup processing for the yp server. 172*7c478bd9Sstevel@tonic-gate */ 173*7c478bd9Sstevel@tonic-gate static void 174*7c478bd9Sstevel@tonic-gate ypinit(int argc, char **argv) 175*7c478bd9Sstevel@tonic-gate { 176*7c478bd9Sstevel@tonic-gate int pid; 177*7c478bd9Sstevel@tonic-gate int stat, t; 178*7c478bd9Sstevel@tonic-gate struct sigaction act; 179*7c478bd9Sstevel@tonic-gate int ufd, tfd; 180*7c478bd9Sstevel@tonic-gate SVCXPRT *utransp, *ttransp; 181*7c478bd9Sstevel@tonic-gate struct netconfig *nconf; 182*7c478bd9Sstevel@tonic-gate int connmaxrec = RPC_MAXDATASIZE; 183*7c478bd9Sstevel@tonic-gate int i, j, services = 0; 184*7c478bd9Sstevel@tonic-gate 185*7c478bd9Sstevel@tonic-gate 186*7c478bd9Sstevel@tonic-gate /* 187*7c478bd9Sstevel@tonic-gate * Init yptol flags. Will get redone by init_lock_system() but we need 188*7c478bd9Sstevel@tonic-gate * to know if we should parse yptol cmd line options. 189*7c478bd9Sstevel@tonic-gate */ 190*7c478bd9Sstevel@tonic-gate init_yptol_flag(); 191*7c478bd9Sstevel@tonic-gate 192*7c478bd9Sstevel@tonic-gate ypget_command_line_args(argc, argv); 193*7c478bd9Sstevel@tonic-gate 194*7c478bd9Sstevel@tonic-gate if (silent) { 195*7c478bd9Sstevel@tonic-gate pid = (int)fork(); 196*7c478bd9Sstevel@tonic-gate 197*7c478bd9Sstevel@tonic-gate if (pid == -1) { 198*7c478bd9Sstevel@tonic-gate logprintf("ypserv: ypinit fork failure.\n"); 199*7c478bd9Sstevel@tonic-gate ypexit(); 200*7c478bd9Sstevel@tonic-gate } 201*7c478bd9Sstevel@tonic-gate 202*7c478bd9Sstevel@tonic-gate if (pid != 0) { 203*7c478bd9Sstevel@tonic-gate exit(0); 204*7c478bd9Sstevel@tonic-gate } 205*7c478bd9Sstevel@tonic-gate } 206*7c478bd9Sstevel@tonic-gate 207*7c478bd9Sstevel@tonic-gate if (!init_lock_system(FALSE)) { 208*7c478bd9Sstevel@tonic-gate ypexit(); 209*7c478bd9Sstevel@tonic-gate } 210*7c478bd9Sstevel@tonic-gate 211*7c478bd9Sstevel@tonic-gate get_secure_nets(argv[0]); 212*7c478bd9Sstevel@tonic-gate 213*7c478bd9Sstevel@tonic-gate if (silent) { 214*7c478bd9Sstevel@tonic-gate closelog(); 215*7c478bd9Sstevel@tonic-gate closefrom(3); 216*7c478bd9Sstevel@tonic-gate } 217*7c478bd9Sstevel@tonic-gate 218*7c478bd9Sstevel@tonic-gate if (yptol_mode) { 219*7c478bd9Sstevel@tonic-gate stat = parseConfig(ldapCLA, NTOL_MAP_FILE); 220*7c478bd9Sstevel@tonic-gate if (stat == 1) { 221*7c478bd9Sstevel@tonic-gate logprintf("NIS to LDAP mapping inactive.\n"); 222*7c478bd9Sstevel@tonic-gate } else if (stat != 0) { 223*7c478bd9Sstevel@tonic-gate logprintf("Aborting after NIS to LDAP mapping " 224*7c478bd9Sstevel@tonic-gate "error.\n"); 225*7c478bd9Sstevel@tonic-gate fflush(stderr); 226*7c478bd9Sstevel@tonic-gate exit(-1); 227*7c478bd9Sstevel@tonic-gate } 228*7c478bd9Sstevel@tonic-gate } 229*7c478bd9Sstevel@tonic-gate 230*7c478bd9Sstevel@tonic-gate if (silent) { 231*7c478bd9Sstevel@tonic-gate freopen("/dev/null", "r", stdin); 232*7c478bd9Sstevel@tonic-gate if (access(logfile, _IOWRT)) { 233*7c478bd9Sstevel@tonic-gate freopen("/dev/null", "w", stdout); 234*7c478bd9Sstevel@tonic-gate freopen("/dev/null", "w", stderr); 235*7c478bd9Sstevel@tonic-gate } else { 236*7c478bd9Sstevel@tonic-gate freopen(logfile, "a", stdout); 237*7c478bd9Sstevel@tonic-gate freopen(logfile, "a", stderr); 238*7c478bd9Sstevel@tonic-gate } 239*7c478bd9Sstevel@tonic-gate 240*7c478bd9Sstevel@tonic-gate t = open("/dev/tty", 2); 241*7c478bd9Sstevel@tonic-gate 242*7c478bd9Sstevel@tonic-gate setpgrp(); 243*7c478bd9Sstevel@tonic-gate } 244*7c478bd9Sstevel@tonic-gate 245*7c478bd9Sstevel@tonic-gate #ifdef SYSVCONFIG 246*7c478bd9Sstevel@tonic-gate sigset(SIGHUP, (void (*)())sysvconfig); 247*7c478bd9Sstevel@tonic-gate #else 248*7c478bd9Sstevel@tonic-gate sigset(SIGHUP, SIG_IGN); 249*7c478bd9Sstevel@tonic-gate #endif 250*7c478bd9Sstevel@tonic-gate 251*7c478bd9Sstevel@tonic-gate /* 252*7c478bd9Sstevel@tonic-gate * Setting disposition to SIG_IGN will not create zombies when child 253*7c478bd9Sstevel@tonic-gate * processes terminate. 254*7c478bd9Sstevel@tonic-gate */ 255*7c478bd9Sstevel@tonic-gate sigset(SIGCHLD, SIG_IGN); 256*7c478bd9Sstevel@tonic-gate 257*7c478bd9Sstevel@tonic-gate act.sa_handler = cleanup_resolv; 258*7c478bd9Sstevel@tonic-gate sigemptyset(&act.sa_mask); 259*7c478bd9Sstevel@tonic-gate act.sa_flags = SA_RESETHAND; 260*7c478bd9Sstevel@tonic-gate sigaction(SIGTERM, &act, (struct sigaction *)NULL); 261*7c478bd9Sstevel@tonic-gate sigaction(SIGQUIT, &act, (struct sigaction *)NULL); 262*7c478bd9Sstevel@tonic-gate sigaction(SIGABRT, &act, (struct sigaction *)NULL); 263*7c478bd9Sstevel@tonic-gate sigaction(SIGBUS, &act, (struct sigaction *)NULL); 264*7c478bd9Sstevel@tonic-gate sigaction(SIGSEGV, &act, (struct sigaction *)NULL); 265*7c478bd9Sstevel@tonic-gate 266*7c478bd9Sstevel@tonic-gate /* 267*7c478bd9Sstevel@tonic-gate * Set non-blocking mode and maximum record size for 268*7c478bd9Sstevel@tonic-gate * connection oriented RPC transports. 269*7c478bd9Sstevel@tonic-gate */ 270*7c478bd9Sstevel@tonic-gate if (!rpc_control(RPC_SVC_CONNMAXREC_SET, &connmaxrec)) { 271*7c478bd9Sstevel@tonic-gate logprintf("unable to set maximum RPC record size"); 272*7c478bd9Sstevel@tonic-gate } 273*7c478bd9Sstevel@tonic-gate 274*7c478bd9Sstevel@tonic-gate svc_unreg(YPPROG, YPVERS); 275*7c478bd9Sstevel@tonic-gate svc_unreg(YPPROG, YPVERS_ORIG); 276*7c478bd9Sstevel@tonic-gate 277*7c478bd9Sstevel@tonic-gate for (i = 0; i < sizeof (service)/sizeof (ypservice_t); i++) { 278*7c478bd9Sstevel@tonic-gate 279*7c478bd9Sstevel@tonic-gate service_classes[i] = -1; 280*7c478bd9Sstevel@tonic-gate 281*7c478bd9Sstevel@tonic-gate if ((nconf = getnetconfigent(service[i].netid)) == NULL) { 282*7c478bd9Sstevel@tonic-gate logprintf("getnetconfigent(\"%s\") failed\n", 283*7c478bd9Sstevel@tonic-gate service[i].netid); 284*7c478bd9Sstevel@tonic-gate continue; 285*7c478bd9Sstevel@tonic-gate } 286*7c478bd9Sstevel@tonic-gate 287*7c478bd9Sstevel@tonic-gate if ((service[i].fd = t_open(nconf->nc_device, O_RDWR, NULL)) < 288*7c478bd9Sstevel@tonic-gate 0) { 289*7c478bd9Sstevel@tonic-gate logprintf("t_open failed for %s\n", service[i].netid); 290*7c478bd9Sstevel@tonic-gate freenetconfigent(nconf); 291*7c478bd9Sstevel@tonic-gate continue; 292*7c478bd9Sstevel@tonic-gate } 293*7c478bd9Sstevel@tonic-gate 294*7c478bd9Sstevel@tonic-gate if (netdir_options(nconf, ND_SET_RESERVEDPORT, service[i].fd, 295*7c478bd9Sstevel@tonic-gate NULL) < 0) { 296*7c478bd9Sstevel@tonic-gate logprintf("could not set reserved port for %s\n", 297*7c478bd9Sstevel@tonic-gate service[i].netid); 298*7c478bd9Sstevel@tonic-gate (void) close(service[i].fd); 299*7c478bd9Sstevel@tonic-gate service[i].fd = -1; 300*7c478bd9Sstevel@tonic-gate freenetconfigent(nconf); 301*7c478bd9Sstevel@tonic-gate continue; 302*7c478bd9Sstevel@tonic-gate } 303*7c478bd9Sstevel@tonic-gate 304*7c478bd9Sstevel@tonic-gate if ((service[i].xprt = svc_tli_create(service[i].fd, nconf, 305*7c478bd9Sstevel@tonic-gate NULL, 0, 0)) == NULL) { 306*7c478bd9Sstevel@tonic-gate logprintf("svc_tli_create failed for %s\n", 307*7c478bd9Sstevel@tonic-gate service[i].netid); 308*7c478bd9Sstevel@tonic-gate (void) close(service[i].fd); 309*7c478bd9Sstevel@tonic-gate service[i].fd = -1; 310*7c478bd9Sstevel@tonic-gate freenetconfigent(nconf); 311*7c478bd9Sstevel@tonic-gate continue; 312*7c478bd9Sstevel@tonic-gate } 313*7c478bd9Sstevel@tonic-gate 314*7c478bd9Sstevel@tonic-gate if (!svc_reg(service[i].xprt, YPPROG, YPVERS, ypdispatch, 315*7c478bd9Sstevel@tonic-gate nconf)) { 316*7c478bd9Sstevel@tonic-gate logprintf("%s %s\n", service[i].netid, register_failed); 317*7c478bd9Sstevel@tonic-gate svc_destroy(service[i].xprt); 318*7c478bd9Sstevel@tonic-gate service[i].xprt = 0; 319*7c478bd9Sstevel@tonic-gate (void) close(service[i].fd); 320*7c478bd9Sstevel@tonic-gate service[i].fd = -1; 321*7c478bd9Sstevel@tonic-gate freenetconfigent(nconf); 322*7c478bd9Sstevel@tonic-gate continue; 323*7c478bd9Sstevel@tonic-gate } 324*7c478bd9Sstevel@tonic-gate 325*7c478bd9Sstevel@tonic-gate if (service[i].olddispatch && !svc_reg(service[i].xprt, YPPROG, 326*7c478bd9Sstevel@tonic-gate YPVERS_ORIG, ypolddispatch, nconf)) { 327*7c478bd9Sstevel@tonic-gate logprintf("old %s %s\n", 328*7c478bd9Sstevel@tonic-gate service[i].netid, register_failed); 329*7c478bd9Sstevel@tonic-gate /* Can only unregister prognum/versnum */ 330*7c478bd9Sstevel@tonic-gate svc_destroy(service[i].xprt); 331*7c478bd9Sstevel@tonic-gate service[i].xprt = 0; 332*7c478bd9Sstevel@tonic-gate (void) close(service[i].fd); 333*7c478bd9Sstevel@tonic-gate service[i].fd = -1; 334*7c478bd9Sstevel@tonic-gate freenetconfigent(nconf); 335*7c478bd9Sstevel@tonic-gate continue; 336*7c478bd9Sstevel@tonic-gate } 337*7c478bd9Sstevel@tonic-gate 338*7c478bd9Sstevel@tonic-gate services++; 339*7c478bd9Sstevel@tonic-gate service[i].ok = 1; 340*7c478bd9Sstevel@tonic-gate service_classes[i] = service[i].class; 341*7c478bd9Sstevel@tonic-gate 342*7c478bd9Sstevel@tonic-gate freenetconfigent(nconf); 343*7c478bd9Sstevel@tonic-gate 344*7c478bd9Sstevel@tonic-gate } 345*7c478bd9Sstevel@tonic-gate 346*7c478bd9Sstevel@tonic-gate /* 347*7c478bd9Sstevel@tonic-gate * Check if we managed to register enough services to continue. 348*7c478bd9Sstevel@tonic-gate * It's OK if we managed to register all IPv4 services but no 349*7c478bd9Sstevel@tonic-gate * IPv6, or the other way around, but not if we (say) registered 350*7c478bd9Sstevel@tonic-gate * IPv4 UDP but not TCP. 351*7c478bd9Sstevel@tonic-gate */ 352*7c478bd9Sstevel@tonic-gate if (services > 0) { 353*7c478bd9Sstevel@tonic-gate for (j = 0; j < MAXSERVICES; j++) { 354*7c478bd9Sstevel@tonic-gate if (service_classes[j] >= 0) { 355*7c478bd9Sstevel@tonic-gate /* 356*7c478bd9Sstevel@tonic-gate * Must have all services of this class 357*7c478bd9Sstevel@tonic-gate * registered. 358*7c478bd9Sstevel@tonic-gate */ 359*7c478bd9Sstevel@tonic-gate for (i = 0; i < MAXSERVICES; i++) { 360*7c478bd9Sstevel@tonic-gate if (service[i].ok == 0 && 361*7c478bd9Sstevel@tonic-gate service[i].class == 362*7c478bd9Sstevel@tonic-gate service_classes[j]) { 363*7c478bd9Sstevel@tonic-gate logprintf( 364*7c478bd9Sstevel@tonic-gate "unable to register all services for class %d\n", 365*7c478bd9Sstevel@tonic-gate service[i].class); 366*7c478bd9Sstevel@tonic-gate ypexit(); 367*7c478bd9Sstevel@tonic-gate } 368*7c478bd9Sstevel@tonic-gate } 369*7c478bd9Sstevel@tonic-gate } 370*7c478bd9Sstevel@tonic-gate } 371*7c478bd9Sstevel@tonic-gate } else { 372*7c478bd9Sstevel@tonic-gate logprintf("unable to register any services\n"); 373*7c478bd9Sstevel@tonic-gate ypexit(); 374*7c478bd9Sstevel@tonic-gate } 375*7c478bd9Sstevel@tonic-gate 376*7c478bd9Sstevel@tonic-gate /* Now we setup circuit_n or yp_all() and yp_update() will not work */ 377*7c478bd9Sstevel@tonic-gate if (!svc_create(ypdispatch, YPPROG, YPVERS, "circuit_n")) { 378*7c478bd9Sstevel@tonic-gate logprintf("circuit_n %s\n", register_failed); 379*7c478bd9Sstevel@tonic-gate ypexit(); 380*7c478bd9Sstevel@tonic-gate } 381*7c478bd9Sstevel@tonic-gate 382*7c478bd9Sstevel@tonic-gate if (dnsforward) { 383*7c478bd9Sstevel@tonic-gate setup_resolv(&dnsforward, &resolv_pid, 384*7c478bd9Sstevel@tonic-gate &resolv_client, resolv_tp, 0); 385*7c478bd9Sstevel@tonic-gate if (resolv_client == NULL) 386*7c478bd9Sstevel@tonic-gate client_setup_failure = TRUE; 387*7c478bd9Sstevel@tonic-gate } 388*7c478bd9Sstevel@tonic-gate } 389*7c478bd9Sstevel@tonic-gate 390*7c478bd9Sstevel@tonic-gate void 391*7c478bd9Sstevel@tonic-gate cleanup_resolv(int sig) 392*7c478bd9Sstevel@tonic-gate { 393*7c478bd9Sstevel@tonic-gate if (resolv_pid) 394*7c478bd9Sstevel@tonic-gate kill(resolv_pid, sig); 395*7c478bd9Sstevel@tonic-gate 396*7c478bd9Sstevel@tonic-gate kill(getpid(), sig); 397*7c478bd9Sstevel@tonic-gate } 398*7c478bd9Sstevel@tonic-gate 399*7c478bd9Sstevel@tonic-gate /* 400*7c478bd9Sstevel@tonic-gate * This picks up any command line args passed from the process invocation. 401*7c478bd9Sstevel@tonic-gate */ 402*7c478bd9Sstevel@tonic-gate static void 403*7c478bd9Sstevel@tonic-gate ypget_command_line_args(int argc, char **argv) 404*7c478bd9Sstevel@tonic-gate { 405*7c478bd9Sstevel@tonic-gate for (argv++; --argc; argv++) { 406*7c478bd9Sstevel@tonic-gate 407*7c478bd9Sstevel@tonic-gate if ((*argv)[0] == '-') { 408*7c478bd9Sstevel@tonic-gate 409*7c478bd9Sstevel@tonic-gate switch ((*argv)[1]) { 410*7c478bd9Sstevel@tonic-gate #ifdef MINUS_C_OPTION 411*7c478bd9Sstevel@tonic-gate case 'c': 412*7c478bd9Sstevel@tonic-gate multiflag = TRUE; 413*7c478bd9Sstevel@tonic-gate break; 414*7c478bd9Sstevel@tonic-gate #endif 415*7c478bd9Sstevel@tonic-gate case 'd': 416*7c478bd9Sstevel@tonic-gate if (access("/etc/resolv.conf", F_OK) == -1) { 417*7c478bd9Sstevel@tonic-gate fprintf(stderr, 418*7c478bd9Sstevel@tonic-gate "No /etc/resolv.conf file, -d option ignored\n"); 419*7c478bd9Sstevel@tonic-gate } else { 420*7c478bd9Sstevel@tonic-gate dnsforward = TRUE; 421*7c478bd9Sstevel@tonic-gate } 422*7c478bd9Sstevel@tonic-gate break; 423*7c478bd9Sstevel@tonic-gate case 'I': 424*7c478bd9Sstevel@tonic-gate init_containers = TRUE; 425*7c478bd9Sstevel@tonic-gate /* ... and also do -i stuff */ 426*7c478bd9Sstevel@tonic-gate case 'i': 427*7c478bd9Sstevel@tonic-gate if (yptol_mode) { 428*7c478bd9Sstevel@tonic-gate init_dit = TRUE; 429*7c478bd9Sstevel@tonic-gate } else { 430*7c478bd9Sstevel@tonic-gate fprintf(stderr, "-%c option is illegal " 431*7c478bd9Sstevel@tonic-gate "if not in NIS to LDAP mode. Exiting\n", 432*7c478bd9Sstevel@tonic-gate (*argv)[1]); 433*7c478bd9Sstevel@tonic-gate fflush(stderr); 434*7c478bd9Sstevel@tonic-gate exit(-1); 435*7c478bd9Sstevel@tonic-gate } 436*7c478bd9Sstevel@tonic-gate 437*7c478bd9Sstevel@tonic-gate /* Handle -ir */ 438*7c478bd9Sstevel@tonic-gate if ('r' != (*argv)[2]) 439*7c478bd9Sstevel@tonic-gate break; 440*7c478bd9Sstevel@tonic-gate 441*7c478bd9Sstevel@tonic-gate case 'r': 442*7c478bd9Sstevel@tonic-gate if (yptol_mode) { 443*7c478bd9Sstevel@tonic-gate init_maps = TRUE; 444*7c478bd9Sstevel@tonic-gate } else { 445*7c478bd9Sstevel@tonic-gate fprintf(stderr, "-r option is illegal " 446*7c478bd9Sstevel@tonic-gate "if not in NIS to LDAP mode. " 447*7c478bd9Sstevel@tonic-gate "Exiting\n"); 448*7c478bd9Sstevel@tonic-gate fflush(stderr); 449*7c478bd9Sstevel@tonic-gate exit(-1); 450*7c478bd9Sstevel@tonic-gate } 451*7c478bd9Sstevel@tonic-gate break; 452*7c478bd9Sstevel@tonic-gate case 'v': 453*7c478bd9Sstevel@tonic-gate silent = FALSE; 454*7c478bd9Sstevel@tonic-gate break; 455*7c478bd9Sstevel@tonic-gate } 456*7c478bd9Sstevel@tonic-gate } 457*7c478bd9Sstevel@tonic-gate } 458*7c478bd9Sstevel@tonic-gate 459*7c478bd9Sstevel@tonic-gate /* If setting up don't run silent or demonize */ 460*7c478bd9Sstevel@tonic-gate if (init_dit || init_maps) 461*7c478bd9Sstevel@tonic-gate silent = FALSE; 462*7c478bd9Sstevel@tonic-gate 463*7c478bd9Sstevel@tonic-gate } 464*7c478bd9Sstevel@tonic-gate 465*7c478bd9Sstevel@tonic-gate /* 466*7c478bd9Sstevel@tonic-gate * This dispatches to server action routines based on the input procedure 467*7c478bd9Sstevel@tonic-gate * number. ypdispatch is called from the RPC function svc_run. 468*7c478bd9Sstevel@tonic-gate */ 469*7c478bd9Sstevel@tonic-gate static void 470*7c478bd9Sstevel@tonic-gate ypdispatch(struct svc_req *rqstp, SVCXPRT *transp) 471*7c478bd9Sstevel@tonic-gate { 472*7c478bd9Sstevel@tonic-gate sigset_t set, oset; 473*7c478bd9Sstevel@tonic-gate 474*7c478bd9Sstevel@tonic-gate 475*7c478bd9Sstevel@tonic-gate #ifdef SYSVCONFIG 476*7c478bd9Sstevel@tonic-gate /* prepare to answer questions about system v filesystem aliases */ 477*7c478bd9Sstevel@tonic-gate sysvconfig(); 478*7c478bd9Sstevel@tonic-gate #endif 479*7c478bd9Sstevel@tonic-gate 480*7c478bd9Sstevel@tonic-gate sigemptyset(&set); 481*7c478bd9Sstevel@tonic-gate sigaddset(&set, SIGCHLD); 482*7c478bd9Sstevel@tonic-gate sigprocmask(SIG_BLOCK, &set, &oset); 483*7c478bd9Sstevel@tonic-gate 484*7c478bd9Sstevel@tonic-gate switch (rqstp->rq_proc) { 485*7c478bd9Sstevel@tonic-gate 486*7c478bd9Sstevel@tonic-gate case YPPROC_NULL: 487*7c478bd9Sstevel@tonic-gate 488*7c478bd9Sstevel@tonic-gate if (!svc_sendreply(transp, xdr_void, 0)) 489*7c478bd9Sstevel@tonic-gate logprintf("ypserv: Can't reply to rpc call.\n"); 490*7c478bd9Sstevel@tonic-gate break; 491*7c478bd9Sstevel@tonic-gate 492*7c478bd9Sstevel@tonic-gate case YPPROC_DOMAIN: 493*7c478bd9Sstevel@tonic-gate ypdomain(transp, TRUE); 494*7c478bd9Sstevel@tonic-gate break; 495*7c478bd9Sstevel@tonic-gate 496*7c478bd9Sstevel@tonic-gate case YPPROC_DOMAIN_NONACK: 497*7c478bd9Sstevel@tonic-gate ypdomain(transp, FALSE); 498*7c478bd9Sstevel@tonic-gate break; 499*7c478bd9Sstevel@tonic-gate 500*7c478bd9Sstevel@tonic-gate case YPPROC_MATCH: 501*7c478bd9Sstevel@tonic-gate ypmatch(transp, rqstp); 502*7c478bd9Sstevel@tonic-gate break; 503*7c478bd9Sstevel@tonic-gate 504*7c478bd9Sstevel@tonic-gate case YPPROC_FIRST: 505*7c478bd9Sstevel@tonic-gate ypfirst(transp); 506*7c478bd9Sstevel@tonic-gate break; 507*7c478bd9Sstevel@tonic-gate 508*7c478bd9Sstevel@tonic-gate case YPPROC_NEXT: 509*7c478bd9Sstevel@tonic-gate ypnext(transp); 510*7c478bd9Sstevel@tonic-gate break; 511*7c478bd9Sstevel@tonic-gate 512*7c478bd9Sstevel@tonic-gate case YPPROC_XFR: 513*7c478bd9Sstevel@tonic-gate ypxfr(transp, YPPROC_XFR); 514*7c478bd9Sstevel@tonic-gate break; 515*7c478bd9Sstevel@tonic-gate 516*7c478bd9Sstevel@tonic-gate case YPPROC_NEWXFR: 517*7c478bd9Sstevel@tonic-gate ypxfr(transp, YPPROC_NEWXFR); 518*7c478bd9Sstevel@tonic-gate break; 519*7c478bd9Sstevel@tonic-gate 520*7c478bd9Sstevel@tonic-gate case YPPROC_CLEAR: 521*7c478bd9Sstevel@tonic-gate ypclr_current_map(); 522*7c478bd9Sstevel@tonic-gate 523*7c478bd9Sstevel@tonic-gate if (!svc_sendreply(transp, xdr_void, 0)) 524*7c478bd9Sstevel@tonic-gate logprintf("ypserv: Can't reply to rpc call.\n"); 525*7c478bd9Sstevel@tonic-gate break; 526*7c478bd9Sstevel@tonic-gate 527*7c478bd9Sstevel@tonic-gate case YPPROC_ALL: 528*7c478bd9Sstevel@tonic-gate ypall(transp); 529*7c478bd9Sstevel@tonic-gate break; 530*7c478bd9Sstevel@tonic-gate 531*7c478bd9Sstevel@tonic-gate case YPPROC_MASTER: 532*7c478bd9Sstevel@tonic-gate ypmaster(transp); 533*7c478bd9Sstevel@tonic-gate break; 534*7c478bd9Sstevel@tonic-gate 535*7c478bd9Sstevel@tonic-gate case YPPROC_ORDER: 536*7c478bd9Sstevel@tonic-gate yporder(transp); 537*7c478bd9Sstevel@tonic-gate break; 538*7c478bd9Sstevel@tonic-gate 539*7c478bd9Sstevel@tonic-gate case YPPROC_MAPLIST: 540*7c478bd9Sstevel@tonic-gate ypmaplist(transp); 541*7c478bd9Sstevel@tonic-gate break; 542*7c478bd9Sstevel@tonic-gate 543*7c478bd9Sstevel@tonic-gate default: 544*7c478bd9Sstevel@tonic-gate svcerr_noproc(transp); 545*7c478bd9Sstevel@tonic-gate break; 546*7c478bd9Sstevel@tonic-gate 547*7c478bd9Sstevel@tonic-gate } 548*7c478bd9Sstevel@tonic-gate 549*7c478bd9Sstevel@tonic-gate sigprocmask(SIG_SETMASK, &oset, (sigset_t *)NULL); 550*7c478bd9Sstevel@tonic-gate 551*7c478bd9Sstevel@tonic-gate } 552*7c478bd9Sstevel@tonic-gate 553*7c478bd9Sstevel@tonic-gate static void 554*7c478bd9Sstevel@tonic-gate ypolddispatch(struct svc_req *rqstp, SVCXPRT *transp) 555*7c478bd9Sstevel@tonic-gate { 556*7c478bd9Sstevel@tonic-gate sigset_t set, oset; 557*7c478bd9Sstevel@tonic-gate 558*7c478bd9Sstevel@tonic-gate sigemptyset(&set); 559*7c478bd9Sstevel@tonic-gate sigaddset(&set, SIGCHLD); 560*7c478bd9Sstevel@tonic-gate sigprocmask(SIG_BLOCK, &set, &oset); 561*7c478bd9Sstevel@tonic-gate 562*7c478bd9Sstevel@tonic-gate switch (rqstp->rq_proc) { 563*7c478bd9Sstevel@tonic-gate 564*7c478bd9Sstevel@tonic-gate case YPOLDPROC_NULL: 565*7c478bd9Sstevel@tonic-gate if (!svc_sendreply(transp, xdr_void, 0)) 566*7c478bd9Sstevel@tonic-gate logprintf("ypserv: Can't replay to rpc call.\n"); 567*7c478bd9Sstevel@tonic-gate break; 568*7c478bd9Sstevel@tonic-gate 569*7c478bd9Sstevel@tonic-gate case YPOLDPROC_DOMAIN: 570*7c478bd9Sstevel@tonic-gate ypdomain(transp, TRUE); 571*7c478bd9Sstevel@tonic-gate break; 572*7c478bd9Sstevel@tonic-gate 573*7c478bd9Sstevel@tonic-gate case YPOLDPROC_DOMAIN_NONACK: 574*7c478bd9Sstevel@tonic-gate ypdomain(transp, FALSE); 575*7c478bd9Sstevel@tonic-gate break; 576*7c478bd9Sstevel@tonic-gate 577*7c478bd9Sstevel@tonic-gate case YPOLDPROC_MATCH: 578*7c478bd9Sstevel@tonic-gate ypoldmatch(transp, rqstp); 579*7c478bd9Sstevel@tonic-gate break; 580*7c478bd9Sstevel@tonic-gate 581*7c478bd9Sstevel@tonic-gate case YPOLDPROC_FIRST: 582*7c478bd9Sstevel@tonic-gate ypoldfirst(transp); 583*7c478bd9Sstevel@tonic-gate break; 584*7c478bd9Sstevel@tonic-gate 585*7c478bd9Sstevel@tonic-gate case YPOLDPROC_NEXT: 586*7c478bd9Sstevel@tonic-gate ypoldnext(transp); 587*7c478bd9Sstevel@tonic-gate break; 588*7c478bd9Sstevel@tonic-gate 589*7c478bd9Sstevel@tonic-gate case YPOLDPROC_POLL: 590*7c478bd9Sstevel@tonic-gate ypoldpoll(transp); 591*7c478bd9Sstevel@tonic-gate break; 592*7c478bd9Sstevel@tonic-gate 593*7c478bd9Sstevel@tonic-gate case YPOLDPROC_PUSH: 594*7c478bd9Sstevel@tonic-gate ypoldpush(transp); 595*7c478bd9Sstevel@tonic-gate break; 596*7c478bd9Sstevel@tonic-gate 597*7c478bd9Sstevel@tonic-gate case YPOLDPROC_PULL: 598*7c478bd9Sstevel@tonic-gate ypoldpull(transp); 599*7c478bd9Sstevel@tonic-gate break; 600*7c478bd9Sstevel@tonic-gate 601*7c478bd9Sstevel@tonic-gate case YPOLDPROC_GET: 602*7c478bd9Sstevel@tonic-gate ypoldget(transp); 603*7c478bd9Sstevel@tonic-gate 604*7c478bd9Sstevel@tonic-gate default: 605*7c478bd9Sstevel@tonic-gate svcerr_noproc(transp); 606*7c478bd9Sstevel@tonic-gate break; 607*7c478bd9Sstevel@tonic-gate } 608*7c478bd9Sstevel@tonic-gate 609*7c478bd9Sstevel@tonic-gate sigprocmask(SIG_SETMASK, &oset, (sigset_t *)NULL); 610*7c478bd9Sstevel@tonic-gate } 611*7c478bd9Sstevel@tonic-gate 612*7c478bd9Sstevel@tonic-gate /* 613*7c478bd9Sstevel@tonic-gate * This flushes output to stderr, then aborts the server process to leave a 614*7c478bd9Sstevel@tonic-gate * core dump. 615*7c478bd9Sstevel@tonic-gate */ 616*7c478bd9Sstevel@tonic-gate static void 617*7c478bd9Sstevel@tonic-gate ypexit(void) 618*7c478bd9Sstevel@tonic-gate { 619*7c478bd9Sstevel@tonic-gate fflush(stderr); 620*7c478bd9Sstevel@tonic-gate abort(); 621*7c478bd9Sstevel@tonic-gate } 622*7c478bd9Sstevel@tonic-gate 623*7c478bd9Sstevel@tonic-gate /* 624*7c478bd9Sstevel@tonic-gate * This constructs a logging record. 625*7c478bd9Sstevel@tonic-gate */ 626*7c478bd9Sstevel@tonic-gate void 627*7c478bd9Sstevel@tonic-gate logprintf(char *format, ...) 628*7c478bd9Sstevel@tonic-gate { 629*7c478bd9Sstevel@tonic-gate va_list ap; 630*7c478bd9Sstevel@tonic-gate struct timeval t; 631*7c478bd9Sstevel@tonic-gate 632*7c478bd9Sstevel@tonic-gate va_start(ap, format); 633*7c478bd9Sstevel@tonic-gate 634*7c478bd9Sstevel@tonic-gate if (silent) { 635*7c478bd9Sstevel@tonic-gate gettimeofday(&t); 636*7c478bd9Sstevel@tonic-gate fseek(stderr, 0, 2); 637*7c478bd9Sstevel@tonic-gate fprintf(stderr, "%19.19s: ", ctime(&t.tv_sec)); 638*7c478bd9Sstevel@tonic-gate } 639*7c478bd9Sstevel@tonic-gate 640*7c478bd9Sstevel@tonic-gate vfprintf(stderr, format, ap); 641*7c478bd9Sstevel@tonic-gate va_end(ap); 642*7c478bd9Sstevel@tonic-gate fflush(stderr); 643*7c478bd9Sstevel@tonic-gate } 644