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