17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*004388ebScasper * Common Development and Distribution License (the "License"). 6*004388ebScasper * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*004388ebScasper * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 277c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate /* 307c478bd9Sstevel@tonic-gate * Portions of this source code were derived from Berkeley 317c478bd9Sstevel@tonic-gate * under license from the Regents of the University of 327c478bd9Sstevel@tonic-gate * California. 337c478bd9Sstevel@tonic-gate */ 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate #include <stdio.h> 38*004388ebScasper #include <stdio_ext.h> 397c478bd9Sstevel@tonic-gate #include <stdlib.h> 407c478bd9Sstevel@tonic-gate #include <signal.h> 417c478bd9Sstevel@tonic-gate #include <rpc/rpc.h> 427c478bd9Sstevel@tonic-gate #include <memory.h> 437c478bd9Sstevel@tonic-gate #include <netconfig.h> 447c478bd9Sstevel@tonic-gate #include <syslog.h> 457c478bd9Sstevel@tonic-gate #include <rpcsvc/yp_prot.h> 467c478bd9Sstevel@tonic-gate #include "yp_b.h" 477c478bd9Sstevel@tonic-gate #include <sys/resource.h> 487c478bd9Sstevel@tonic-gate #include <sys/stropts.h> 497c478bd9Sstevel@tonic-gate #include <unistd.h> 507c478bd9Sstevel@tonic-gate #include <rpc/nettype.h> 517c478bd9Sstevel@tonic-gate #include <string.h> 527c478bd9Sstevel@tonic-gate #include <tiuser.h> 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate #ifdef DEBUG 567c478bd9Sstevel@tonic-gate #define RPC_SVC_FG 577c478bd9Sstevel@tonic-gate #endif 587c478bd9Sstevel@tonic-gate 597c478bd9Sstevel@tonic-gate #define _RPCSVC_CLOSEDOWN 120 607c478bd9Sstevel@tonic-gate #define YPBIND_ERR_ERR 1 /* Internal error */ 617c478bd9Sstevel@tonic-gate #define YPBIND_ERR_NOSERV 2 /* No bound server for passed domain */ 627c478bd9Sstevel@tonic-gate #define YPBIND_ERR_RESC 3 /* System resource allocation failure */ 637c478bd9Sstevel@tonic-gate #define YPBIND_ERR_NODOMAIN 4 /* Domain doesn't exist */ 647c478bd9Sstevel@tonic-gate 657c478bd9Sstevel@tonic-gate static int _rpcpmstart; /* Started by a port monitor ? */ 667c478bd9Sstevel@tonic-gate static int _rpcsvcdirty; /* Still serving ? */ 677c478bd9Sstevel@tonic-gate int setok = YPSETNONE; /* who is allowed to ypset */ 687c478bd9Sstevel@tonic-gate int broadcast = 0; 697c478bd9Sstevel@tonic-gate int cache_okay = 0; /* if set, then bindings are cached in files */ 707c478bd9Sstevel@tonic-gate 717c478bd9Sstevel@tonic-gate extern int sigcld_event; 727c478bd9Sstevel@tonic-gate extern void broadcast_proc_exit(); 737c478bd9Sstevel@tonic-gate extern int __rpc_negotiate_uid(); 747c478bd9Sstevel@tonic-gate extern bool_t __rpcbind_is_up(); 757c478bd9Sstevel@tonic-gate extern void ypbind_init_default(); 767c478bd9Sstevel@tonic-gate static void set_signal_handlers(); 777c478bd9Sstevel@tonic-gate static void clear_bindings(); 787c478bd9Sstevel@tonic-gate static void unregister(int); 797c478bd9Sstevel@tonic-gate static int void_close(void *, int); 807c478bd9Sstevel@tonic-gate void closedown(); 817c478bd9Sstevel@tonic-gate void ypbindprog_3(); 827c478bd9Sstevel@tonic-gate void ypbindprog_2(); 837c478bd9Sstevel@tonic-gate void msgout(); 847c478bd9Sstevel@tonic-gate extern void cache_transport(); 857c478bd9Sstevel@tonic-gate extern void clean_cache(); 867c478bd9Sstevel@tonic-gate 87a506a34cSth160488 int 887c478bd9Sstevel@tonic-gate main(argc, argv) 897c478bd9Sstevel@tonic-gate int argc; 907c478bd9Sstevel@tonic-gate char **argv; 917c478bd9Sstevel@tonic-gate { 927c478bd9Sstevel@tonic-gate pid_t pid; 937c478bd9Sstevel@tonic-gate int pfd[2]; 947c478bd9Sstevel@tonic-gate char domain[256], servers[300]; 957c478bd9Sstevel@tonic-gate char **Argv = argv; 967c478bd9Sstevel@tonic-gate struct netconfig *nconf; 977c478bd9Sstevel@tonic-gate void *nc_handle; 987c478bd9Sstevel@tonic-gate int loopback_found = 0, udp_found = 0; 997c478bd9Sstevel@tonic-gate int pipe_closed = 0; 1007c478bd9Sstevel@tonic-gate struct rlimit rl; 1017c478bd9Sstevel@tonic-gate int connmaxrec = RPC_MAXDATASIZE; 1027c478bd9Sstevel@tonic-gate uint32_t inet_tpts = 0, inet6_tpts = 0; 1037c478bd9Sstevel@tonic-gate uint32_t inet_desired_tpts = 0, inet6_desired_tpts = 0; 1047c478bd9Sstevel@tonic-gate bool_t exclbind = TRUE; 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate if (geteuid() != 0) { 1077c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "must be root to run %s\n", argv[0]); 1087c478bd9Sstevel@tonic-gate exit(1); 1097c478bd9Sstevel@tonic-gate } 1107c478bd9Sstevel@tonic-gate 1117c478bd9Sstevel@tonic-gate argc--; 1127c478bd9Sstevel@tonic-gate argv++; 1137c478bd9Sstevel@tonic-gate 1147c478bd9Sstevel@tonic-gate while (argc > 0) { 1157c478bd9Sstevel@tonic-gate if (strcmp(*argv, "-ypset") == 0) { 1167c478bd9Sstevel@tonic-gate setok = YPSETALL; 1177c478bd9Sstevel@tonic-gate } else if (strcmp(*argv, "-ypsetme") == 0) { 1187c478bd9Sstevel@tonic-gate setok = YPSETLOCAL; 1197c478bd9Sstevel@tonic-gate } else if (strcmp(*argv, "-broadcast") == 0) { 1207c478bd9Sstevel@tonic-gate broadcast = TRUE; 1217c478bd9Sstevel@tonic-gate } else { 1227c478bd9Sstevel@tonic-gate fprintf(stderr, 1237c478bd9Sstevel@tonic-gate "usage: ypbind [-broadcast] [-ypset] [-ypsetme]\n"); 1247c478bd9Sstevel@tonic-gate exit(1); 1257c478bd9Sstevel@tonic-gate } 1267c478bd9Sstevel@tonic-gate argc--, 1277c478bd9Sstevel@tonic-gate argv++; 1287c478bd9Sstevel@tonic-gate } 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate if (setok == YPSETALL) { 1317c478bd9Sstevel@tonic-gate fprintf(stderr, 1327c478bd9Sstevel@tonic-gate "ypbind -ypset: allowing ypset! (this is REALLY insecure)\n"); 1337c478bd9Sstevel@tonic-gate } 1347c478bd9Sstevel@tonic-gate if (setok == YPSETLOCAL) { 1357c478bd9Sstevel@tonic-gate fprintf(stderr, 1367c478bd9Sstevel@tonic-gate "ypbind -ypsetme: allowing local ypset! (this is insecure)\n"); 1377c478bd9Sstevel@tonic-gate } 1387c478bd9Sstevel@tonic-gate if (broadcast == TRUE) { 1397c478bd9Sstevel@tonic-gate fprintf(stderr, 1407c478bd9Sstevel@tonic-gate "ypbind -broadcast: allowing broadcast! \ 1417c478bd9Sstevel@tonic-gate (insecure and transport dependent)\n"); 1427c478bd9Sstevel@tonic-gate } 1437c478bd9Sstevel@tonic-gate 1447c478bd9Sstevel@tonic-gate if (getdomainname(domain, sizeof (domain)) == 0) { 1457c478bd9Sstevel@tonic-gate sprintf(servers, "%s/%s/ypservers", BINDING, domain); 1467c478bd9Sstevel@tonic-gate if (!broadcast && access(servers, R_OK) != 0) { 1477c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 1487c478bd9Sstevel@tonic-gate "%s: no info on servers - run ypinit -c\n", Argv[0]); 1497c478bd9Sstevel@tonic-gate exit(1); 1507c478bd9Sstevel@tonic-gate } 1517c478bd9Sstevel@tonic-gate } else { 1527c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "%s: domainname not set - exiting\n", 1537c478bd9Sstevel@tonic-gate Argv[0]); 1547c478bd9Sstevel@tonic-gate exit(1); 1557c478bd9Sstevel@tonic-gate } 1567c478bd9Sstevel@tonic-gate 1577c478bd9Sstevel@tonic-gate getrlimit(RLIMIT_NOFILE, &rl); 1587c478bd9Sstevel@tonic-gate rl.rlim_cur = rl.rlim_max; 1597c478bd9Sstevel@tonic-gate setrlimit(RLIMIT_NOFILE, &rl); 1607c478bd9Sstevel@tonic-gate 161*004388ebScasper (void) enable_extended_FILE_stdio(-1, -1); 162*004388ebScasper 1637c478bd9Sstevel@tonic-gate openlog("ypbind", LOG_PID, LOG_DAEMON); 1647c478bd9Sstevel@tonic-gate 1657c478bd9Sstevel@tonic-gate /* 1667c478bd9Sstevel@tonic-gate * If stdin looks like a TLI endpoint, we assume 1677c478bd9Sstevel@tonic-gate * that we were started by a port monitor. If 1687c478bd9Sstevel@tonic-gate * t_getstate fails with TBADF, this is not a 1697c478bd9Sstevel@tonic-gate * TLI endpoint. 1707c478bd9Sstevel@tonic-gate */ 1717c478bd9Sstevel@tonic-gate _rpcpmstart = (t_getstate(0) != -1 || t_errno != TBADF); 1727c478bd9Sstevel@tonic-gate 1737c478bd9Sstevel@tonic-gate if (!__rpcbind_is_up()) { 1747c478bd9Sstevel@tonic-gate msgout("terminating: rpcbind is not running"); 1757c478bd9Sstevel@tonic-gate exit(1); 1767c478bd9Sstevel@tonic-gate } 1777c478bd9Sstevel@tonic-gate 1787c478bd9Sstevel@tonic-gate if (_rpcpmstart) { 1797c478bd9Sstevel@tonic-gate /* 1807c478bd9Sstevel@tonic-gate * We were invoked by ypbind with the request on stdin. 1817c478bd9Sstevel@tonic-gate * 1827c478bd9Sstevel@tonic-gate * XXX - This is not the normal way ypbind is used 1837c478bd9Sstevel@tonic-gate * and has never been tested. 1847c478bd9Sstevel@tonic-gate */ 1857c478bd9Sstevel@tonic-gate char *netid; 1867c478bd9Sstevel@tonic-gate struct netconfig *nconf = NULL; 1877c478bd9Sstevel@tonic-gate SVCXPRT *transp; 1887c478bd9Sstevel@tonic-gate int pmclose; 1897c478bd9Sstevel@tonic-gate extern char *getenv(); 1907c478bd9Sstevel@tonic-gate 1917c478bd9Sstevel@tonic-gate /* 1927c478bd9Sstevel@tonic-gate * Set non-blocking mode and maximum record size for 1937c478bd9Sstevel@tonic-gate * connection oriented RPC transports. 1947c478bd9Sstevel@tonic-gate */ 1957c478bd9Sstevel@tonic-gate if (!rpc_control(RPC_SVC_CONNMAXREC_SET, &connmaxrec)) { 1967c478bd9Sstevel@tonic-gate msgout("unable to set maximum RPC record size"); 1977c478bd9Sstevel@tonic-gate } 1987c478bd9Sstevel@tonic-gate 1997c478bd9Sstevel@tonic-gate clear_bindings(); 2007c478bd9Sstevel@tonic-gate if ((netid = getenv("NLSPROVIDER")) == NULL) { 2017c478bd9Sstevel@tonic-gate #ifdef DEBUG 2027c478bd9Sstevel@tonic-gate msgout("cannot get transport name"); 2037c478bd9Sstevel@tonic-gate #endif 2047c478bd9Sstevel@tonic-gate } else if ((nconf = getnetconfigent(netid)) == NULL) { 2057c478bd9Sstevel@tonic-gate #ifdef DEBUG 2067c478bd9Sstevel@tonic-gate msgout("cannot get transport info"); 2077c478bd9Sstevel@tonic-gate #endif 2087c478bd9Sstevel@tonic-gate } 2097c478bd9Sstevel@tonic-gate 2107c478bd9Sstevel@tonic-gate pmclose = (t_getstate(0) != T_DATAXFER); 2117c478bd9Sstevel@tonic-gate if ((transp = svc_tli_create(0, nconf, NULL, 0, 0)) == NULL) { 2127c478bd9Sstevel@tonic-gate msgout("cannot create server handle"); 2137c478bd9Sstevel@tonic-gate exit(1); 2147c478bd9Sstevel@tonic-gate } 2157c478bd9Sstevel@tonic-gate 2167c478bd9Sstevel@tonic-gate if (strcmp(nconf->nc_protofmly, NC_LOOPBACK) == 0) { 2177c478bd9Sstevel@tonic-gate if ((setok != YPSETNONE) && 2187c478bd9Sstevel@tonic-gate __rpc_negotiate_uid(transp->xp_fd)) { 2197c478bd9Sstevel@tonic-gate syslog(LOG_ERR, 2207c478bd9Sstevel@tonic-gate "could not negotiate with loopback tranport %s", 2217c478bd9Sstevel@tonic-gate nconf->nc_netid); 2227c478bd9Sstevel@tonic-gate } 2237c478bd9Sstevel@tonic-gate } 2247c478bd9Sstevel@tonic-gate if (nconf) 2257c478bd9Sstevel@tonic-gate freenetconfigent(nconf); 2267c478bd9Sstevel@tonic-gate if (!svc_reg(transp, YPBINDPROG, YPBINDVERS, ypbindprog_3, 0)) { 2277c478bd9Sstevel@tonic-gate msgout("unable to register (YPBINDPROG, YPBINDVERS)."); 2287c478bd9Sstevel@tonic-gate exit(1); 2297c478bd9Sstevel@tonic-gate } 2307c478bd9Sstevel@tonic-gate if (!svc_reg(transp, YPBINDPROG, YPBINDVERS_2, 2317c478bd9Sstevel@tonic-gate ypbindprog_2, 0)) { 2327c478bd9Sstevel@tonic-gate msgout( 2337c478bd9Sstevel@tonic-gate "unable to register (YPBINDPROG, YPBINDVERS_2)."); 2347c478bd9Sstevel@tonic-gate exit(1); 2357c478bd9Sstevel@tonic-gate } 2367c478bd9Sstevel@tonic-gate /* version 2 and version 1 are the same as far as we care */ 2377c478bd9Sstevel@tonic-gate if (!svc_reg(transp, YPBINDPROG, YPBINDVERS_1, 2387c478bd9Sstevel@tonic-gate ypbindprog_2, 0)) { 2397c478bd9Sstevel@tonic-gate msgout( 2407c478bd9Sstevel@tonic-gate "unable to register (YPBINDPROG, YPBINDVERS_1)."); 2417c478bd9Sstevel@tonic-gate exit(1); 2427c478bd9Sstevel@tonic-gate } 2437c478bd9Sstevel@tonic-gate set_signal_handlers(); 2447c478bd9Sstevel@tonic-gate if (pmclose) { 2457c478bd9Sstevel@tonic-gate (void) signal(SIGALRM, closedown); 2467c478bd9Sstevel@tonic-gate (void) alarm(_RPCSVC_CLOSEDOWN); 2477c478bd9Sstevel@tonic-gate } 2487c478bd9Sstevel@tonic-gate #ifdef INIT_DEFAULT 2497c478bd9Sstevel@tonic-gate ypbind_init_default(); 2507c478bd9Sstevel@tonic-gate #endif 2517c478bd9Sstevel@tonic-gate svc_run(); 2527c478bd9Sstevel@tonic-gate msgout("svc_run returned"); 2537c478bd9Sstevel@tonic-gate exit(1); 2547c478bd9Sstevel@tonic-gate /* NOTREACHED */ 2557c478bd9Sstevel@tonic-gate } 2567c478bd9Sstevel@tonic-gate #ifndef RPC_SVC_FG 2577c478bd9Sstevel@tonic-gate /* 2587c478bd9Sstevel@tonic-gate * In normal operation, ypbind forks a child to do all the work 2597c478bd9Sstevel@tonic-gate * so that it can run in background. But, if the parent exits 2607c478bd9Sstevel@tonic-gate * too soon during system startup, clients will start trying to 2617c478bd9Sstevel@tonic-gate * talk to the child ypbind before it is ready. This can cause 2627c478bd9Sstevel@tonic-gate * spurious client errors. 2637c478bd9Sstevel@tonic-gate * 2647c478bd9Sstevel@tonic-gate * To prevent these problems, the parent process creates a pipe, 2657c478bd9Sstevel@tonic-gate * which is inherited by the child, and waits for the child to 2667c478bd9Sstevel@tonic-gate * close its end. This happens explicitly before the child goes 2677c478bd9Sstevel@tonic-gate * into svc_run(), or as a side-effect of exiting. 2687c478bd9Sstevel@tonic-gate */ 2697c478bd9Sstevel@tonic-gate if (pipe(pfd) == -1) { 2707c478bd9Sstevel@tonic-gate perror("pipe"); 2717c478bd9Sstevel@tonic-gate exit(1); 2727c478bd9Sstevel@tonic-gate } 2737c478bd9Sstevel@tonic-gate pid = fork(); 2747c478bd9Sstevel@tonic-gate if (pid < 0) { 2757c478bd9Sstevel@tonic-gate perror("cannot fork"); 2767c478bd9Sstevel@tonic-gate exit(1); 2777c478bd9Sstevel@tonic-gate } 2787c478bd9Sstevel@tonic-gate if (pid) { 2797c478bd9Sstevel@tonic-gate /* 2807c478bd9Sstevel@tonic-gate * The parent waits for the child to close its end of 2817c478bd9Sstevel@tonic-gate * the pipe (to indicate that it is ready to process 2827c478bd9Sstevel@tonic-gate * requests). The read blocks until the child does 2837c478bd9Sstevel@tonic-gate * a close (the "domain" array is just a handy buffer). 2847c478bd9Sstevel@tonic-gate */ 2857c478bd9Sstevel@tonic-gate close(pfd[1]); 2867c478bd9Sstevel@tonic-gate read(pfd[0], domain, sizeof (domain)); 2877c478bd9Sstevel@tonic-gate exit(0); 2887c478bd9Sstevel@tonic-gate } 2897c478bd9Sstevel@tonic-gate /* close all files except pfd[1] */ 2907c478bd9Sstevel@tonic-gate (void) fdwalk(void_close, &pfd[1]); 2917c478bd9Sstevel@tonic-gate (void) open("/dev/null", O_RDONLY); 2927c478bd9Sstevel@tonic-gate (void) open("/dev/null", O_WRONLY); 2937c478bd9Sstevel@tonic-gate (void) dup(1); 2947c478bd9Sstevel@tonic-gate setsid(); 2957c478bd9Sstevel@tonic-gate #endif 2967c478bd9Sstevel@tonic-gate clean_cache(); /* make sure there are no left-over files */ 2977c478bd9Sstevel@tonic-gate cache_okay = cache_check(); 2987c478bd9Sstevel@tonic-gate cache_pid(); 2997c478bd9Sstevel@tonic-gate 3007c478bd9Sstevel@tonic-gate /* 3017c478bd9Sstevel@tonic-gate * Set non-blocking mode and maximum record size for 3027c478bd9Sstevel@tonic-gate * connection oriented RPC transports. 3037c478bd9Sstevel@tonic-gate */ 3047c478bd9Sstevel@tonic-gate if (!rpc_control(RPC_SVC_CONNMAXREC_SET, &connmaxrec)) { 3057c478bd9Sstevel@tonic-gate msgout("unable to set maximum RPC record size"); 3067c478bd9Sstevel@tonic-gate } 3077c478bd9Sstevel@tonic-gate 3087c478bd9Sstevel@tonic-gate /* 3097c478bd9Sstevel@tonic-gate * Prevent our non-priv udp and tcp ports bound w/wildcard addr 3107c478bd9Sstevel@tonic-gate * from being hijacked by a bind to a more specific addr. 3117c478bd9Sstevel@tonic-gate */ 3127c478bd9Sstevel@tonic-gate if (!rpc_control(__RPC_SVC_EXCLBIND_SET, &exclbind)) { 3137c478bd9Sstevel@tonic-gate msgout("warning: unable to set udp/tcp EXCLBIND"); 3147c478bd9Sstevel@tonic-gate } 3157c478bd9Sstevel@tonic-gate 3167c478bd9Sstevel@tonic-gate #ifdef INIT_DEFAULT 3177c478bd9Sstevel@tonic-gate ypbind_init_default(); 3187c478bd9Sstevel@tonic-gate #endif 3197c478bd9Sstevel@tonic-gate 3207c478bd9Sstevel@tonic-gate nc_handle = __rpc_setconf("netpath"); /* open netconfig file */ 3217c478bd9Sstevel@tonic-gate if (nc_handle == NULL) { 3227c478bd9Sstevel@tonic-gate syslog(LOG_ERR, "could not read /etc/netconfig, exiting.."); 3237c478bd9Sstevel@tonic-gate exit(1); 3247c478bd9Sstevel@tonic-gate } 3257c478bd9Sstevel@tonic-gate 3267c478bd9Sstevel@tonic-gate /* 3277c478bd9Sstevel@tonic-gate * The parent waits for the child to close its end of 3287c478bd9Sstevel@tonic-gate * the pipe (to indicate that it is ready to process 3297c478bd9Sstevel@tonic-gate * requests). Now the non-diskless client will wait because the 3307c478bd9Sstevel@tonic-gate * cache file is valid. 3317c478bd9Sstevel@tonic-gate */ 3327c478bd9Sstevel@tonic-gate if (cache_okay) { 3337c478bd9Sstevel@tonic-gate close(pfd[1]); 3347c478bd9Sstevel@tonic-gate pipe_closed = 1; 3357c478bd9Sstevel@tonic-gate } 3367c478bd9Sstevel@tonic-gate 3377c478bd9Sstevel@tonic-gate clear_bindings(); 3387c478bd9Sstevel@tonic-gate 3397c478bd9Sstevel@tonic-gate while (nconf = __rpc_getconf(nc_handle)) { 3407c478bd9Sstevel@tonic-gate SVCXPRT *xprt; 3417c478bd9Sstevel@tonic-gate 3427c478bd9Sstevel@tonic-gate if (!__rpcbind_is_up()) { 3437c478bd9Sstevel@tonic-gate msgout("terminating: rpcbind is not running"); 3447c478bd9Sstevel@tonic-gate exit(1); 3457c478bd9Sstevel@tonic-gate } 3467c478bd9Sstevel@tonic-gate if ((xprt = svc_tp_create(ypbindprog_3, 3477c478bd9Sstevel@tonic-gate YPBINDPROG, YPBINDVERS, nconf)) == NULL) { 3487c478bd9Sstevel@tonic-gate msgout("terminating: cannot create rpcbind handle"); 3497c478bd9Sstevel@tonic-gate exit(1); 3507c478bd9Sstevel@tonic-gate } 3517c478bd9Sstevel@tonic-gate 3527c478bd9Sstevel@tonic-gate cache_transport(nconf, xprt, YPBINDVERS); 3537c478bd9Sstevel@tonic-gate 3547c478bd9Sstevel@tonic-gate /* support ypbind V2 and V1, but only on udp/tcp transports */ 3557c478bd9Sstevel@tonic-gate if (((strcmp(nconf->nc_protofmly, NC_INET) == 0) || 3567c478bd9Sstevel@tonic-gate (strcmp(nconf->nc_protofmly, NC_INET6))) && 3577c478bd9Sstevel@tonic-gate ((nconf->nc_semantics == NC_TPI_CLTS) || 3587c478bd9Sstevel@tonic-gate (nconf->nc_semantics == NC_TPI_COTS_ORD))) { 3597c478bd9Sstevel@tonic-gate 3607c478bd9Sstevel@tonic-gate if (strcmp(nconf->nc_protofmly, NC_INET)) { 3617c478bd9Sstevel@tonic-gate inet_desired_tpts |= 1 >> nconf->nc_semantics; 3627c478bd9Sstevel@tonic-gate } else { 3637c478bd9Sstevel@tonic-gate inet6_desired_tpts |= 1 >> nconf->nc_semantics; 3647c478bd9Sstevel@tonic-gate } 3657c478bd9Sstevel@tonic-gate 3667c478bd9Sstevel@tonic-gate (void) rpcb_unset(YPBINDPROG, YPBINDVERS_2, nconf); 3677c478bd9Sstevel@tonic-gate if (!svc_reg(xprt, YPBINDPROG, YPBINDVERS_2, 3687c478bd9Sstevel@tonic-gate ypbindprog_2, nconf)) { 3697c478bd9Sstevel@tonic-gate syslog(LOG_INFO, 3707c478bd9Sstevel@tonic-gate "unable to register (YPBINDPROG, YPBINDVERS_2) [%s]", 3717c478bd9Sstevel@tonic-gate nconf->nc_netid); 3727c478bd9Sstevel@tonic-gate continue; 3737c478bd9Sstevel@tonic-gate } 3747c478bd9Sstevel@tonic-gate 3757c478bd9Sstevel@tonic-gate cache_transport(nconf, xprt, YPBINDVERS_2); 3767c478bd9Sstevel@tonic-gate 3777c478bd9Sstevel@tonic-gate /* For NC_INET, register v1 as well; error is fatal */ 3787c478bd9Sstevel@tonic-gate if (strcmp(nconf->nc_protofmly, NC_INET) == 0) { 3797c478bd9Sstevel@tonic-gate (void) rpcb_unset(YPBINDPROG, YPBINDVERS_1, 3807c478bd9Sstevel@tonic-gate nconf); 3817c478bd9Sstevel@tonic-gate if (!svc_reg(xprt, YPBINDPROG, YPBINDVERS_1, 3827c478bd9Sstevel@tonic-gate ypbindprog_2, nconf)) { 3837c478bd9Sstevel@tonic-gate syslog(LOG_ERR, 3847c478bd9Sstevel@tonic-gate "unable to register (YPBINDPROG, YPBINDVERS_1)."); 3857c478bd9Sstevel@tonic-gate exit(1); 3867c478bd9Sstevel@tonic-gate } 3877c478bd9Sstevel@tonic-gate } 3887c478bd9Sstevel@tonic-gate 3897c478bd9Sstevel@tonic-gate cache_transport(nconf, xprt, YPBINDVERS_1); 3907c478bd9Sstevel@tonic-gate 3917c478bd9Sstevel@tonic-gate if (nconf->nc_semantics == NC_TPI_CLTS) 3927c478bd9Sstevel@tonic-gate udp_found++; 3937c478bd9Sstevel@tonic-gate 3947c478bd9Sstevel@tonic-gate if (strcmp(nconf->nc_protofmly, NC_INET)) { 3957c478bd9Sstevel@tonic-gate inet_tpts |= 1 >> nconf->nc_semantics; 3967c478bd9Sstevel@tonic-gate } else { 3977c478bd9Sstevel@tonic-gate inet6_tpts |= 1 >> nconf->nc_semantics; 3987c478bd9Sstevel@tonic-gate } 3997c478bd9Sstevel@tonic-gate } 4007c478bd9Sstevel@tonic-gate if (strcmp(nconf->nc_protofmly, NC_LOOPBACK) == 0) { 4017c478bd9Sstevel@tonic-gate loopback_found++; 4027c478bd9Sstevel@tonic-gate if ((setok != YPSETNONE) && 4037c478bd9Sstevel@tonic-gate __rpc_negotiate_uid(xprt->xp_fd)) { 4047c478bd9Sstevel@tonic-gate syslog(LOG_ERR, 4057c478bd9Sstevel@tonic-gate "could not negotiate with loopback tranport %s", 4067c478bd9Sstevel@tonic-gate nconf->nc_netid); 4077c478bd9Sstevel@tonic-gate } 4087c478bd9Sstevel@tonic-gate /* 4097c478bd9Sstevel@tonic-gate * On a diskless client: 4107c478bd9Sstevel@tonic-gate * The parent waits for the child to close its end of 4117c478bd9Sstevel@tonic-gate * the pipe (to indicate that it is ready to process 4127c478bd9Sstevel@tonic-gate * requests). Now the diskless client will wait 4137c478bd9Sstevel@tonic-gate * only if ypbind is registered on the loopback. 4147c478bd9Sstevel@tonic-gate */ 4157c478bd9Sstevel@tonic-gate if ((!pipe_closed) && 4167c478bd9Sstevel@tonic-gate ((nconf->nc_semantics == NC_TPI_COTS) || 4177c478bd9Sstevel@tonic-gate (nconf->nc_semantics == NC_TPI_COTS_ORD))) { 4187c478bd9Sstevel@tonic-gate close(pfd[1]); 4197c478bd9Sstevel@tonic-gate pipe_closed = 1; 4207c478bd9Sstevel@tonic-gate } 4217c478bd9Sstevel@tonic-gate } 4227c478bd9Sstevel@tonic-gate } 4237c478bd9Sstevel@tonic-gate 4247c478bd9Sstevel@tonic-gate /* Did we manage to register all IPv4 or all IPv6 transports ? */ 4257c478bd9Sstevel@tonic-gate if (inet_tpts != 0 && inet_tpts != inet_desired_tpts) { 4267c478bd9Sstevel@tonic-gate syslog(LOG_ERR, 4277c478bd9Sstevel@tonic-gate "unable to register all %s transports, exiting..", 4287c478bd9Sstevel@tonic-gate NC_INET); 4297c478bd9Sstevel@tonic-gate exit(1); 4307c478bd9Sstevel@tonic-gate } else if (inet6_tpts != 0 && inet6_tpts != inet6_desired_tpts) { 4317c478bd9Sstevel@tonic-gate syslog(LOG_ERR, 4327c478bd9Sstevel@tonic-gate "unable to register all %s transports, exiting..", 4337c478bd9Sstevel@tonic-gate NC_INET6); 4347c478bd9Sstevel@tonic-gate exit(1); 4357c478bd9Sstevel@tonic-gate } 4367c478bd9Sstevel@tonic-gate 4377c478bd9Sstevel@tonic-gate if (!pipe_closed) { 4387c478bd9Sstevel@tonic-gate close(pfd[1]); 4397c478bd9Sstevel@tonic-gate pipe_closed = 1; 4407c478bd9Sstevel@tonic-gate } 4417c478bd9Sstevel@tonic-gate __rpc_endconf(nc_handle); 4427c478bd9Sstevel@tonic-gate if (!loopback_found) { 4437c478bd9Sstevel@tonic-gate syslog(LOG_ERR, 4447c478bd9Sstevel@tonic-gate "could not find loopback transports, exiting.."); 4457c478bd9Sstevel@tonic-gate exit(1); 4467c478bd9Sstevel@tonic-gate } 4477c478bd9Sstevel@tonic-gate if (!udp_found) { 4487c478bd9Sstevel@tonic-gate syslog(LOG_ERR, 4497c478bd9Sstevel@tonic-gate "could not find inet-clts (udp) transport, exiting.."); 4507c478bd9Sstevel@tonic-gate exit(1); 4517c478bd9Sstevel@tonic-gate } 4527c478bd9Sstevel@tonic-gate set_signal_handlers(); 4537c478bd9Sstevel@tonic-gate svc_run(); 4547c478bd9Sstevel@tonic-gate syslog(LOG_ERR, "svc_run returned, exiting.."); 4557c478bd9Sstevel@tonic-gate exit(1); 4567c478bd9Sstevel@tonic-gate /* NOTREACHED */ 4577c478bd9Sstevel@tonic-gate } 4587c478bd9Sstevel@tonic-gate 4597c478bd9Sstevel@tonic-gate /* 4607c478bd9Sstevel@tonic-gate * Callback function for fdwalk() to close all files. 4617c478bd9Sstevel@tonic-gate */ 4627c478bd9Sstevel@tonic-gate static int 4637c478bd9Sstevel@tonic-gate void_close(void *pfdp, int fd) 4647c478bd9Sstevel@tonic-gate { 4657c478bd9Sstevel@tonic-gate if (fd != *(int *)pfdp) 4667c478bd9Sstevel@tonic-gate (void) close(fd); 4677c478bd9Sstevel@tonic-gate return (0); 4687c478bd9Sstevel@tonic-gate } 4697c478bd9Sstevel@tonic-gate 4707c478bd9Sstevel@tonic-gate void 4717c478bd9Sstevel@tonic-gate ypbindprog_3(rqstp, transp) 4727c478bd9Sstevel@tonic-gate struct svc_req *rqstp; 4737c478bd9Sstevel@tonic-gate register SVCXPRT *transp; 4747c478bd9Sstevel@tonic-gate { 4757c478bd9Sstevel@tonic-gate union { 4767c478bd9Sstevel@tonic-gate ypbind_domain ypbindproc_domain_3_arg; 4777c478bd9Sstevel@tonic-gate ypbind_setdom ypbindproc_setdom_3_arg; 4787c478bd9Sstevel@tonic-gate } argument; 4797c478bd9Sstevel@tonic-gate char *result; 4807c478bd9Sstevel@tonic-gate bool_t (*xdr_argument)(), (*xdr_result)(); 4817c478bd9Sstevel@tonic-gate char *(*local)(); 4827c478bd9Sstevel@tonic-gate 4837c478bd9Sstevel@tonic-gate if (sigcld_event) 4847c478bd9Sstevel@tonic-gate broadcast_proc_exit(); 4857c478bd9Sstevel@tonic-gate 4867c478bd9Sstevel@tonic-gate _rpcsvcdirty = 1; 4877c478bd9Sstevel@tonic-gate switch (rqstp->rq_proc) { 4887c478bd9Sstevel@tonic-gate case YPBINDPROC_NULL: 4897c478bd9Sstevel@tonic-gate xdr_argument = xdr_void; 4907c478bd9Sstevel@tonic-gate xdr_result = xdr_void; 4917c478bd9Sstevel@tonic-gate local = (char *(*)()) ypbindproc_null_3; 4927c478bd9Sstevel@tonic-gate break; 4937c478bd9Sstevel@tonic-gate 4947c478bd9Sstevel@tonic-gate case YPBINDPROC_DOMAIN: 4957c478bd9Sstevel@tonic-gate xdr_argument = xdr_ypbind_domain; 4967c478bd9Sstevel@tonic-gate xdr_result = xdr_ypbind_resp; 4977c478bd9Sstevel@tonic-gate local = (char *(*)()) ypbindproc_domain_3; 4987c478bd9Sstevel@tonic-gate break; 4997c478bd9Sstevel@tonic-gate 5007c478bd9Sstevel@tonic-gate case YPBINDPROC_SETDOM: 5017c478bd9Sstevel@tonic-gate xdr_argument = xdr_ypbind_setdom; 5027c478bd9Sstevel@tonic-gate xdr_result = xdr_void; 5037c478bd9Sstevel@tonic-gate local = (char *(*)()) ypbindproc_setdom_3; 5047c478bd9Sstevel@tonic-gate break; 5057c478bd9Sstevel@tonic-gate 5067c478bd9Sstevel@tonic-gate default: 5077c478bd9Sstevel@tonic-gate svcerr_noproc(transp); 5087c478bd9Sstevel@tonic-gate _rpcsvcdirty = 0; 5097c478bd9Sstevel@tonic-gate return; 5107c478bd9Sstevel@tonic-gate } 5117c478bd9Sstevel@tonic-gate (void) memset((char *)&argument, 0, sizeof (argument)); 5127c478bd9Sstevel@tonic-gate if (!svc_getargs(transp, (xdrproc_t)xdr_argument, (char *)&argument)) { 5137c478bd9Sstevel@tonic-gate svcerr_decode(transp); 5147c478bd9Sstevel@tonic-gate _rpcsvcdirty = 0; 5157c478bd9Sstevel@tonic-gate return; 5167c478bd9Sstevel@tonic-gate } 5177c478bd9Sstevel@tonic-gate if (rqstp->rq_proc == YPBINDPROC_SETDOM) 5187c478bd9Sstevel@tonic-gate result = (*local)(&argument, rqstp, transp); 5197c478bd9Sstevel@tonic-gate else 5207c478bd9Sstevel@tonic-gate result = (*local)(&argument, rqstp); 5217c478bd9Sstevel@tonic-gate if (result != NULL && !svc_sendreply(transp, xdr_result, result)) { 5227c478bd9Sstevel@tonic-gate svcerr_systemerr(transp); 5237c478bd9Sstevel@tonic-gate } 5247c478bd9Sstevel@tonic-gate if (!svc_freeargs(transp, (xdrproc_t)xdr_argument, (char *)&argument)) { 5257c478bd9Sstevel@tonic-gate syslog(LOG_ERR, "unable to free arguments"); 5267c478bd9Sstevel@tonic-gate exit(1); 5277c478bd9Sstevel@tonic-gate } 5287c478bd9Sstevel@tonic-gate _rpcsvcdirty = 0; 5297c478bd9Sstevel@tonic-gate } 5307c478bd9Sstevel@tonic-gate 5317c478bd9Sstevel@tonic-gate void 5327c478bd9Sstevel@tonic-gate ypbindprog_2(rqstp, transp) 5337c478bd9Sstevel@tonic-gate struct svc_req *rqstp; 5347c478bd9Sstevel@tonic-gate register SVCXPRT *transp; 5357c478bd9Sstevel@tonic-gate { 5367c478bd9Sstevel@tonic-gate union { 5377c478bd9Sstevel@tonic-gate domainname_2 ypbindproc_domain_2_arg; 5387c478bd9Sstevel@tonic-gate ypbind_setdom_2 ypbindproc_setdom_2_arg; 5397c478bd9Sstevel@tonic-gate } argument; 5407c478bd9Sstevel@tonic-gate char *result; 5417c478bd9Sstevel@tonic-gate bool_t (*xdr_argument)(), (*xdr_result)(); 5427c478bd9Sstevel@tonic-gate char *(*local)(); 5437c478bd9Sstevel@tonic-gate 5447c478bd9Sstevel@tonic-gate if (sigcld_event) 5457c478bd9Sstevel@tonic-gate broadcast_proc_exit(); 5467c478bd9Sstevel@tonic-gate 5477c478bd9Sstevel@tonic-gate _rpcsvcdirty = 1; 5487c478bd9Sstevel@tonic-gate switch (rqstp->rq_proc) { 5497c478bd9Sstevel@tonic-gate case YPBINDPROC_NULL: 5507c478bd9Sstevel@tonic-gate xdr_argument = xdr_void; 5517c478bd9Sstevel@tonic-gate xdr_result = xdr_void; 5527c478bd9Sstevel@tonic-gate /* XXX - don't need two null procedures */ 5537c478bd9Sstevel@tonic-gate local = (char *(*)()) ypbindproc_null_3; 5547c478bd9Sstevel@tonic-gate break; 5557c478bd9Sstevel@tonic-gate 5567c478bd9Sstevel@tonic-gate case YPBINDPROC_DOMAIN: 5577c478bd9Sstevel@tonic-gate xdr_argument = (bool_t (*)())xdr_ypdomain_wrap_string; 5587c478bd9Sstevel@tonic-gate xdr_result = xdr_ypbind_resp_2; 5597c478bd9Sstevel@tonic-gate local = (char *(*)()) ypbindproc_domain_2; 5607c478bd9Sstevel@tonic-gate break; 5617c478bd9Sstevel@tonic-gate 5627c478bd9Sstevel@tonic-gate case YPBINDPROC_SETDOM: /* not supported, fall through to error */ 5637c478bd9Sstevel@tonic-gate default: 5647c478bd9Sstevel@tonic-gate svcerr_noproc(transp); 5657c478bd9Sstevel@tonic-gate _rpcsvcdirty = 0; 5667c478bd9Sstevel@tonic-gate return; 5677c478bd9Sstevel@tonic-gate } 5687c478bd9Sstevel@tonic-gate (void) memset((char *)&argument, 0, sizeof (argument)); 5697c478bd9Sstevel@tonic-gate if (!svc_getargs(transp, (xdrproc_t)xdr_argument, (char *)&argument)) { 5707c478bd9Sstevel@tonic-gate svcerr_decode(transp); 5717c478bd9Sstevel@tonic-gate _rpcsvcdirty = 0; 5727c478bd9Sstevel@tonic-gate return; 5737c478bd9Sstevel@tonic-gate } 5747c478bd9Sstevel@tonic-gate result = (*local)(&argument, rqstp); 5757c478bd9Sstevel@tonic-gate if (result != NULL && !svc_sendreply(transp, xdr_result, result)) { 5767c478bd9Sstevel@tonic-gate svcerr_systemerr(transp); 5777c478bd9Sstevel@tonic-gate } 5787c478bd9Sstevel@tonic-gate if (!svc_freeargs(transp, (xdrproc_t)xdr_argument, (char *)&argument)) { 5797c478bd9Sstevel@tonic-gate syslog(LOG_ERR, "unable to free arguments"); 5807c478bd9Sstevel@tonic-gate exit(1); 5817c478bd9Sstevel@tonic-gate } 5827c478bd9Sstevel@tonic-gate _rpcsvcdirty = 0; 5837c478bd9Sstevel@tonic-gate } 5847c478bd9Sstevel@tonic-gate 5857c478bd9Sstevel@tonic-gate /* 5867c478bd9Sstevel@tonic-gate * We clear out any old bindings that might have been 5877c478bd9Sstevel@tonic-gate * left behind. If there is already a ypbind running, 5887c478bd9Sstevel@tonic-gate * it will no longer get requests. We are in control 5897c478bd9Sstevel@tonic-gate * now. We ignore the error from rpcb_unset() because 5907c478bd9Sstevel@tonic-gate * this is just a "best effort". If the rpcb_unset() 5917c478bd9Sstevel@tonic-gate * does fail, we will get an error in svc_reg(). By 5927c478bd9Sstevel@tonic-gate * using 0 for the last argument we are telling the 5937c478bd9Sstevel@tonic-gate * portmapper to remove the bindings for all transports. 5947c478bd9Sstevel@tonic-gate */ 5957c478bd9Sstevel@tonic-gate static 5967c478bd9Sstevel@tonic-gate void 5977c478bd9Sstevel@tonic-gate clear_bindings() 5987c478bd9Sstevel@tonic-gate { 5997c478bd9Sstevel@tonic-gate rpcb_unset(YPBINDPROG, YPBINDVERS, 0); 6007c478bd9Sstevel@tonic-gate rpcb_unset(YPBINDPROG, YPBINDVERS_2, 0); 6017c478bd9Sstevel@tonic-gate rpcb_unset(YPBINDPROG, YPBINDVERS_1, 0); 6027c478bd9Sstevel@tonic-gate } 6037c478bd9Sstevel@tonic-gate 6047c478bd9Sstevel@tonic-gate /* 6057c478bd9Sstevel@tonic-gate * This routine is called when we are killed (by most signals). 6067c478bd9Sstevel@tonic-gate * It first tries to unregister with the portmapper. Then it 6077c478bd9Sstevel@tonic-gate * resets the signal handler to the default so that if we get 6087c478bd9Sstevel@tonic-gate * the same signal, we will just go away. We clean up our 6097c478bd9Sstevel@tonic-gate * children by doing a hold in SIGTERM and then killing the 6107c478bd9Sstevel@tonic-gate * process group (-getpid()) with SIGTERM. Finally, we redeliver 6117c478bd9Sstevel@tonic-gate * the signal to ourselves (the handler was reset to the default) 6127c478bd9Sstevel@tonic-gate * so that we will do the normal handling (e.g., coredump). 6137c478bd9Sstevel@tonic-gate * If we can't kill ourselves, we get drastic and just exit 6147c478bd9Sstevel@tonic-gate * after sleeping for a couple of seconds. 6157c478bd9Sstevel@tonic-gate * 6167c478bd9Sstevel@tonic-gate * This code was taken from the SunOS version of ypbind. 6177c478bd9Sstevel@tonic-gate */ 6187c478bd9Sstevel@tonic-gate static 6197c478bd9Sstevel@tonic-gate void 6207c478bd9Sstevel@tonic-gate unregister(int code) 6217c478bd9Sstevel@tonic-gate { 6227c478bd9Sstevel@tonic-gate clear_bindings(); 6237c478bd9Sstevel@tonic-gate clean_cache(); 6247c478bd9Sstevel@tonic-gate signal(code, SIG_DFL); /* to prevent recursive calls to unregister */ 6257c478bd9Sstevel@tonic-gate fprintf(stderr, "ypbind: goind down on signal %d\n", code); 6267c478bd9Sstevel@tonic-gate sighold(SIGCHLD); 6277c478bd9Sstevel@tonic-gate sighold(SIGTERM); 6287c478bd9Sstevel@tonic-gate kill(-getpid(), SIGTERM); /* kill process group (i.e., children) */ 6297c478bd9Sstevel@tonic-gate sigrelse(SIGTERM); 6307c478bd9Sstevel@tonic-gate kill(getpid(), code); /* throw signal again */ 6317c478bd9Sstevel@tonic-gate sleep(2); 6327c478bd9Sstevel@tonic-gate exit(-1); 6337c478bd9Sstevel@tonic-gate } 6347c478bd9Sstevel@tonic-gate 6357c478bd9Sstevel@tonic-gate static 6367c478bd9Sstevel@tonic-gate void 6377c478bd9Sstevel@tonic-gate set_signal_handlers() 6387c478bd9Sstevel@tonic-gate { 6397c478bd9Sstevel@tonic-gate int i; 6407c478bd9Sstevel@tonic-gate 6417c478bd9Sstevel@tonic-gate for (i = 1; i <= SIGTERM; i++) { 6427c478bd9Sstevel@tonic-gate if (i == SIGCHLD) 6437c478bd9Sstevel@tonic-gate continue; 6447c478bd9Sstevel@tonic-gate else if (i == SIGHUP) 6457c478bd9Sstevel@tonic-gate signal(i, SIG_IGN); 6467c478bd9Sstevel@tonic-gate else 6477c478bd9Sstevel@tonic-gate signal(i, unregister); 6487c478bd9Sstevel@tonic-gate } 6497c478bd9Sstevel@tonic-gate } 6507c478bd9Sstevel@tonic-gate 6517c478bd9Sstevel@tonic-gate void 6527c478bd9Sstevel@tonic-gate msgout(msg) 6537c478bd9Sstevel@tonic-gate char *msg; 6547c478bd9Sstevel@tonic-gate { 6557c478bd9Sstevel@tonic-gate #ifdef RPC_SVC_FG 6567c478bd9Sstevel@tonic-gate if (_rpcpmstart) 6577c478bd9Sstevel@tonic-gate syslog(LOG_ERR, msg); 6587c478bd9Sstevel@tonic-gate else 6597c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "%s\n", msg); 6607c478bd9Sstevel@tonic-gate #else 6617c478bd9Sstevel@tonic-gate syslog(LOG_ERR, msg); 6627c478bd9Sstevel@tonic-gate #endif 6637c478bd9Sstevel@tonic-gate } 6647c478bd9Sstevel@tonic-gate 6657c478bd9Sstevel@tonic-gate void 6667c478bd9Sstevel@tonic-gate closedown() 6677c478bd9Sstevel@tonic-gate { 6687c478bd9Sstevel@tonic-gate if (_rpcsvcdirty == 0) { 6697c478bd9Sstevel@tonic-gate int i, openfd; 6707c478bd9Sstevel@tonic-gate struct t_info tinfo; 6717c478bd9Sstevel@tonic-gate 6727c478bd9Sstevel@tonic-gate if (t_getinfo(0, &tinfo) || (tinfo.servtype == T_CLTS)) 6737c478bd9Sstevel@tonic-gate exit(0); 6747c478bd9Sstevel@tonic-gate 6757c478bd9Sstevel@tonic-gate for (i = 0, openfd = 0; i < svc_max_pollfd && openfd < 2; i++) 6767c478bd9Sstevel@tonic-gate if (svc_pollfd[i].fd >= 0) 6777c478bd9Sstevel@tonic-gate openfd++; 6787c478bd9Sstevel@tonic-gate 6797c478bd9Sstevel@tonic-gate if (openfd <= 1) 6807c478bd9Sstevel@tonic-gate exit(0); 6817c478bd9Sstevel@tonic-gate } 6827c478bd9Sstevel@tonic-gate (void) alarm(_RPCSVC_CLOSEDOWN); 6837c478bd9Sstevel@tonic-gate } 684