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