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*8200fe25Srmesta * Common Development and Distribution License (the "License").
6*8200fe25Srmesta * 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*8200fe25Srmesta * 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 #pragma ident "%Z%%M% %I% %E% SMI"
277c478bd9Sstevel@tonic-gate
287c478bd9Sstevel@tonic-gate #include <stdio.h>
297c478bd9Sstevel@tonic-gate #include <stdlib.h>
307c478bd9Sstevel@tonic-gate #include <stropts.h>
317c478bd9Sstevel@tonic-gate #include <signal.h>
327c478bd9Sstevel@tonic-gate #include <fcntl.h>
337c478bd9Sstevel@tonic-gate #include <door.h>
34*8200fe25Srmesta #include <thread.h>
357c478bd9Sstevel@tonic-gate #include <priv_utils.h>
367c478bd9Sstevel@tonic-gate #include <locale.h>
377c478bd9Sstevel@tonic-gate #include <strings.h>
387c478bd9Sstevel@tonic-gate #include <syslog.h>
397c478bd9Sstevel@tonic-gate #include <unistd.h>
407c478bd9Sstevel@tonic-gate #include <nfs/nfs4.h>
417c478bd9Sstevel@tonic-gate #include <nfs/nfsid_map.h>
427c478bd9Sstevel@tonic-gate #include <rpcsvc/daemon_utils.h>
437c478bd9Sstevel@tonic-gate #include <arpa/nameser.h>
447c478bd9Sstevel@tonic-gate #include <nfs/nfssys.h>
457c478bd9Sstevel@tonic-gate #include <errno.h>
467c478bd9Sstevel@tonic-gate #include <pwd.h>
477c478bd9Sstevel@tonic-gate #include <grp.h>
487c478bd9Sstevel@tonic-gate
497c478bd9Sstevel@tonic-gate extern struct group *_uncached_getgrgid_r(gid_t, struct group *, char *, int);
507c478bd9Sstevel@tonic-gate extern struct group *_uncached_getgrnam_r(const char *, struct group *,
517c478bd9Sstevel@tonic-gate char *, int);
527c478bd9Sstevel@tonic-gate extern struct passwd *_uncached_getpwuid_r(uid_t, struct passwd *, char *, int);
537c478bd9Sstevel@tonic-gate extern struct passwd *_uncached_getpwnam_r(const char *, struct passwd *,
547c478bd9Sstevel@tonic-gate char *, int);
557c478bd9Sstevel@tonic-gate
567c478bd9Sstevel@tonic-gate /*
577c478bd9Sstevel@tonic-gate * seconds to cache nfsmapid domain info
587c478bd9Sstevel@tonic-gate */
597c478bd9Sstevel@tonic-gate #define NFSCFG_DEFAULT_DOMAIN_TMOUT (5 * 60)
607c478bd9Sstevel@tonic-gate #define NFSMAPID_DOOR "/var/run/nfsmapid_door"
617c478bd9Sstevel@tonic-gate
627c478bd9Sstevel@tonic-gate extern void nfsmapid_func(void *, char *, size_t, door_desc_t *, uint_t);
637c478bd9Sstevel@tonic-gate
647c478bd9Sstevel@tonic-gate extern void check_domain(int);
657c478bd9Sstevel@tonic-gate extern void idmap_kcall(int);
667c478bd9Sstevel@tonic-gate extern void open_diag_file(void);
677c478bd9Sstevel@tonic-gate
687c478bd9Sstevel@tonic-gate size_t pwd_buflen = 0;
697c478bd9Sstevel@tonic-gate size_t grp_buflen = 0;
707c478bd9Sstevel@tonic-gate thread_t sig_thread;
717c478bd9Sstevel@tonic-gate static char *MyName;
727c478bd9Sstevel@tonic-gate
737c478bd9Sstevel@tonic-gate /*
747c478bd9Sstevel@tonic-gate * nfscfg_domain_tmout is used by nfsv4-test scripts to query
757c478bd9Sstevel@tonic-gate * the nfsmapid daemon for the proper timeout. Don't delete !
767c478bd9Sstevel@tonic-gate */
777c478bd9Sstevel@tonic-gate time_t nfscfg_domain_tmout = NFSCFG_DEFAULT_DOMAIN_TMOUT;
787c478bd9Sstevel@tonic-gate
797c478bd9Sstevel@tonic-gate /*
807c478bd9Sstevel@tonic-gate * Processing for daemonization
817c478bd9Sstevel@tonic-gate */
827c478bd9Sstevel@tonic-gate static void
daemonize(void)837c478bd9Sstevel@tonic-gate daemonize(void)
847c478bd9Sstevel@tonic-gate {
857c478bd9Sstevel@tonic-gate switch (fork()) {
867c478bd9Sstevel@tonic-gate case -1:
877c478bd9Sstevel@tonic-gate perror("nfsmapid: can't fork");
887c478bd9Sstevel@tonic-gate exit(2);
897c478bd9Sstevel@tonic-gate /* NOTREACHED */
907c478bd9Sstevel@tonic-gate case 0: /* child */
917c478bd9Sstevel@tonic-gate break;
927c478bd9Sstevel@tonic-gate
937c478bd9Sstevel@tonic-gate default: /* parent */
947c478bd9Sstevel@tonic-gate _exit(0);
957c478bd9Sstevel@tonic-gate }
967c478bd9Sstevel@tonic-gate
977c478bd9Sstevel@tonic-gate if (chdir("/") < 0)
987c478bd9Sstevel@tonic-gate syslog(LOG_ERR, gettext("chdir /: %m"));
997c478bd9Sstevel@tonic-gate
1007c478bd9Sstevel@tonic-gate /*
1017c478bd9Sstevel@tonic-gate * Close stdin, stdout, and stderr.
1027c478bd9Sstevel@tonic-gate * Open again to redirect input+output
1037c478bd9Sstevel@tonic-gate */
1047c478bd9Sstevel@tonic-gate (void) close(0);
1057c478bd9Sstevel@tonic-gate (void) close(1);
1067c478bd9Sstevel@tonic-gate (void) close(2);
1077c478bd9Sstevel@tonic-gate (void) open("/dev/null", O_RDONLY);
1087c478bd9Sstevel@tonic-gate (void) open("/dev/null", O_WRONLY);
1097c478bd9Sstevel@tonic-gate (void) dup(1);
1107c478bd9Sstevel@tonic-gate (void) setsid();
1117c478bd9Sstevel@tonic-gate }
1127c478bd9Sstevel@tonic-gate
1137c478bd9Sstevel@tonic-gate /* ARGSUSED */
1147c478bd9Sstevel@tonic-gate static void *
sig_handler(void * arg)1157c478bd9Sstevel@tonic-gate sig_handler(void *arg)
1167c478bd9Sstevel@tonic-gate {
1177c478bd9Sstevel@tonic-gate siginfo_t si;
1187c478bd9Sstevel@tonic-gate sigset_t sigset;
1197c478bd9Sstevel@tonic-gate struct timespec tmout;
1207c478bd9Sstevel@tonic-gate int ret;
1217c478bd9Sstevel@tonic-gate
1227c478bd9Sstevel@tonic-gate tmout.tv_nsec = 0;
1237c478bd9Sstevel@tonic-gate (void) sigemptyset(&sigset);
1247c478bd9Sstevel@tonic-gate (void) sigaddset(&sigset, SIGHUP);
1257c478bd9Sstevel@tonic-gate (void) sigaddset(&sigset, SIGTERM);
1267c478bd9Sstevel@tonic-gate #ifdef DEBUG
1277c478bd9Sstevel@tonic-gate (void) sigaddset(&sigset, SIGINT);
1287c478bd9Sstevel@tonic-gate #endif
1297c478bd9Sstevel@tonic-gate
1307c478bd9Sstevel@tonic-gate /*CONSTCOND*/
1317c478bd9Sstevel@tonic-gate while (1) {
132*8200fe25Srmesta tmout.tv_sec = nfscfg_domain_tmout;
1337c478bd9Sstevel@tonic-gate if ((ret = sigtimedwait(&sigset, &si, &tmout)) != 0) {
1347c478bd9Sstevel@tonic-gate /*
1357c478bd9Sstevel@tonic-gate * EAGAIN: no signals arrived during timeout.
1367c478bd9Sstevel@tonic-gate * check/update config files and continue.
1377c478bd9Sstevel@tonic-gate */
1387c478bd9Sstevel@tonic-gate if (ret == -1 && errno == EAGAIN) {
1397c478bd9Sstevel@tonic-gate check_domain(0);
1407c478bd9Sstevel@tonic-gate continue;
1417c478bd9Sstevel@tonic-gate }
1427c478bd9Sstevel@tonic-gate
1437c478bd9Sstevel@tonic-gate switch (si.si_signo) {
1447c478bd9Sstevel@tonic-gate case SIGHUP:
1457c478bd9Sstevel@tonic-gate check_domain(1);
1467c478bd9Sstevel@tonic-gate break;
1477c478bd9Sstevel@tonic-gate #ifdef DEBUG
1487c478bd9Sstevel@tonic-gate case SIGINT:
1497c478bd9Sstevel@tonic-gate exit(0);
1507c478bd9Sstevel@tonic-gate #endif
1517c478bd9Sstevel@tonic-gate case SIGTERM:
1527c478bd9Sstevel@tonic-gate default:
1537c478bd9Sstevel@tonic-gate exit(si.si_signo);
1547c478bd9Sstevel@tonic-gate }
1557c478bd9Sstevel@tonic-gate }
1567c478bd9Sstevel@tonic-gate }
1577c478bd9Sstevel@tonic-gate /*NOTREACHED*/
1587c478bd9Sstevel@tonic-gate return (NULL);
1597c478bd9Sstevel@tonic-gate }
1607c478bd9Sstevel@tonic-gate
1617c478bd9Sstevel@tonic-gate /*
1627c478bd9Sstevel@tonic-gate * Thread initialization. Mask out all signals we want our
1637c478bd9Sstevel@tonic-gate * signal handler to handle for us from any other threads.
1647c478bd9Sstevel@tonic-gate */
1657c478bd9Sstevel@tonic-gate static void
thr_init(void)1667c478bd9Sstevel@tonic-gate thr_init(void)
1677c478bd9Sstevel@tonic-gate {
1687c478bd9Sstevel@tonic-gate sigset_t sigset;
1697c478bd9Sstevel@tonic-gate long thr_flags = (THR_NEW_LWP|THR_DAEMON|THR_SUSPENDED);
1707c478bd9Sstevel@tonic-gate
1717c478bd9Sstevel@tonic-gate /*
1727c478bd9Sstevel@tonic-gate * Before we kick off any other threads, mask out desired
1737c478bd9Sstevel@tonic-gate * signals from main thread so that any subsequent threads
1747c478bd9Sstevel@tonic-gate * don't receive said signals.
1757c478bd9Sstevel@tonic-gate */
1767c478bd9Sstevel@tonic-gate (void) thr_sigsetmask(NULL, NULL, &sigset);
1777c478bd9Sstevel@tonic-gate (void) sigaddset(&sigset, SIGHUP);
1787c478bd9Sstevel@tonic-gate (void) sigaddset(&sigset, SIGTERM);
1797c478bd9Sstevel@tonic-gate #ifdef DEBUG
1807c478bd9Sstevel@tonic-gate (void) sigaddset(&sigset, SIGINT);
1817c478bd9Sstevel@tonic-gate #endif
1827c478bd9Sstevel@tonic-gate (void) thr_sigsetmask(SIG_SETMASK, &sigset, NULL);
1837c478bd9Sstevel@tonic-gate
1847c478bd9Sstevel@tonic-gate /*
1857c478bd9Sstevel@tonic-gate * Create the signal handler thread suspended ! We do things
1867c478bd9Sstevel@tonic-gate * this way at setup time to minimize the probability of
1877c478bd9Sstevel@tonic-gate * introducing any race conditions _if_ the process were to
1887c478bd9Sstevel@tonic-gate * get a SIGHUP signal while creating a new DNS query thread
1897c478bd9Sstevel@tonic-gate * in get_dns_txt_domain().
1907c478bd9Sstevel@tonic-gate */
1917c478bd9Sstevel@tonic-gate if (thr_create(NULL, 0, sig_handler, 0, thr_flags, &sig_thread)) {
1927c478bd9Sstevel@tonic-gate syslog(LOG_ERR,
1937c478bd9Sstevel@tonic-gate gettext("Failed to create signal handling thread"));
1947c478bd9Sstevel@tonic-gate exit(4);
1957c478bd9Sstevel@tonic-gate }
1967c478bd9Sstevel@tonic-gate }
1977c478bd9Sstevel@tonic-gate
1987c478bd9Sstevel@tonic-gate static void
daemon_init(void)1997c478bd9Sstevel@tonic-gate daemon_init(void)
2007c478bd9Sstevel@tonic-gate {
2017c478bd9Sstevel@tonic-gate struct passwd pwd;
2027c478bd9Sstevel@tonic-gate struct group grp;
2037c478bd9Sstevel@tonic-gate char *pwd_buf;
2047c478bd9Sstevel@tonic-gate char *grp_buf;
2057c478bd9Sstevel@tonic-gate
2067c478bd9Sstevel@tonic-gate /*
2077c478bd9Sstevel@tonic-gate * passwd/group reentrant interfaces limits
2087c478bd9Sstevel@tonic-gate */
2097c478bd9Sstevel@tonic-gate pwd_buflen = (size_t)sysconf(_SC_GETPW_R_SIZE_MAX);
2107c478bd9Sstevel@tonic-gate grp_buflen = (size_t)sysconf(_SC_GETGR_R_SIZE_MAX);
2117c478bd9Sstevel@tonic-gate
2127c478bd9Sstevel@tonic-gate /*
2137c478bd9Sstevel@tonic-gate * MT initialization is done first so that if there is the
2147c478bd9Sstevel@tonic-gate * need to fire an additional thread to continue to query
2157c478bd9Sstevel@tonic-gate * DNS, that thread is started off with the main thread's
2167c478bd9Sstevel@tonic-gate * sigmask.
2177c478bd9Sstevel@tonic-gate */
2187c478bd9Sstevel@tonic-gate thr_init();
2197c478bd9Sstevel@tonic-gate
2207c478bd9Sstevel@tonic-gate /*
2217c478bd9Sstevel@tonic-gate * Determine nfsmapid domain.
2227c478bd9Sstevel@tonic-gate */
2237c478bd9Sstevel@tonic-gate check_domain(0);
2247c478bd9Sstevel@tonic-gate
2257c478bd9Sstevel@tonic-gate /*
2267c478bd9Sstevel@tonic-gate * In the case of nfsmapid running diskless, it is important
2277c478bd9Sstevel@tonic-gate * to get the initial connections to the nameservices
2287c478bd9Sstevel@tonic-gate * established to prevent problems like opening a devfs
2297c478bd9Sstevel@tonic-gate * node to contact a nameservice being blocked by the
2307c478bd9Sstevel@tonic-gate * resolution of an active devfs lookup.
2317c478bd9Sstevel@tonic-gate * First issue a set*ent to "open" the databases and then
2327c478bd9Sstevel@tonic-gate * get an entry and finally lookup a bogus entry to trigger
2337c478bd9Sstevel@tonic-gate * any lazy opens.
2347c478bd9Sstevel@tonic-gate */
2357c478bd9Sstevel@tonic-gate setpwent();
2367c478bd9Sstevel@tonic-gate setgrent();
2377c478bd9Sstevel@tonic-gate (void) getpwent();
2387c478bd9Sstevel@tonic-gate (void) getgrent();
2397c478bd9Sstevel@tonic-gate if ((pwd_buf = malloc(pwd_buflen)) == NULL)
2407c478bd9Sstevel@tonic-gate return;
2417c478bd9Sstevel@tonic-gate
2427c478bd9Sstevel@tonic-gate (void) _uncached_getpwnam_r("NF21dmvP", &pwd, pwd_buf, pwd_buflen);
2437c478bd9Sstevel@tonic-gate (void) _uncached_getpwuid_r(1181794, &pwd, pwd_buf, pwd_buflen);
2447c478bd9Sstevel@tonic-gate
2457c478bd9Sstevel@tonic-gate if ((grp_buf = realloc(pwd_buf, grp_buflen)) == NULL) {
2467c478bd9Sstevel@tonic-gate free(pwd_buf);
2477c478bd9Sstevel@tonic-gate return;
2487c478bd9Sstevel@tonic-gate }
2497c478bd9Sstevel@tonic-gate
2507c478bd9Sstevel@tonic-gate (void) _uncached_getgrnam_r("NF21dmvP", &grp, grp_buf, grp_buflen);
2517c478bd9Sstevel@tonic-gate (void) _uncached_getgrgid_r(1181794, &grp, grp_buf, grp_buflen);
2527c478bd9Sstevel@tonic-gate free(grp_buf);
2537c478bd9Sstevel@tonic-gate }
2547c478bd9Sstevel@tonic-gate
2557c478bd9Sstevel@tonic-gate static int
start_svcs(void)2567c478bd9Sstevel@tonic-gate start_svcs(void)
2577c478bd9Sstevel@tonic-gate {
2587c478bd9Sstevel@tonic-gate int doorfd = -1;
2597c478bd9Sstevel@tonic-gate #ifdef DEBUG
2607c478bd9Sstevel@tonic-gate int dfd;
2617c478bd9Sstevel@tonic-gate #endif
2627c478bd9Sstevel@tonic-gate
2637c478bd9Sstevel@tonic-gate if ((doorfd = door_create(nfsmapid_func, NULL,
2647c478bd9Sstevel@tonic-gate DOOR_REFUSE_DESC | DOOR_NO_CANCEL)) == -1) {
2657c478bd9Sstevel@tonic-gate syslog(LOG_ERR, "Unable to create door: %m\n");
2667c478bd9Sstevel@tonic-gate return (1);
2677c478bd9Sstevel@tonic-gate }
2687c478bd9Sstevel@tonic-gate
2697c478bd9Sstevel@tonic-gate #ifdef DEBUG
2707c478bd9Sstevel@tonic-gate /*
2717c478bd9Sstevel@tonic-gate * Create a file system path for the door
2727c478bd9Sstevel@tonic-gate */
2737c478bd9Sstevel@tonic-gate if ((dfd = open(NFSMAPID_DOOR, O_RDWR|O_CREAT|O_TRUNC,
2747c478bd9Sstevel@tonic-gate S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) == -1) {
2757c478bd9Sstevel@tonic-gate syslog(LOG_ERR, "Unable to open %s: %m\n", NFSMAPID_DOOR);
2767c478bd9Sstevel@tonic-gate (void) close(doorfd);
2777c478bd9Sstevel@tonic-gate return (1);
2787c478bd9Sstevel@tonic-gate }
2797c478bd9Sstevel@tonic-gate
2807c478bd9Sstevel@tonic-gate /*
2817c478bd9Sstevel@tonic-gate * Clean up any stale associations
2827c478bd9Sstevel@tonic-gate */
2837c478bd9Sstevel@tonic-gate (void) fdetach(NFSMAPID_DOOR);
2847c478bd9Sstevel@tonic-gate
2857c478bd9Sstevel@tonic-gate /*
2867c478bd9Sstevel@tonic-gate * Register in namespace to pass to the kernel to door_ki_open
2877c478bd9Sstevel@tonic-gate */
2887c478bd9Sstevel@tonic-gate if (fattach(doorfd, NFSMAPID_DOOR) == -1) {
2897c478bd9Sstevel@tonic-gate syslog(LOG_ERR, "Unable to fattach door: %m\n");
2907c478bd9Sstevel@tonic-gate (void) close(dfd);
2917c478bd9Sstevel@tonic-gate (void) close(doorfd);
2927c478bd9Sstevel@tonic-gate return (1);
2937c478bd9Sstevel@tonic-gate }
2947c478bd9Sstevel@tonic-gate (void) close(dfd);
2957c478bd9Sstevel@tonic-gate #endif
2967c478bd9Sstevel@tonic-gate
2977c478bd9Sstevel@tonic-gate /*
2987c478bd9Sstevel@tonic-gate * Now that we're actually running, go
2997c478bd9Sstevel@tonic-gate * ahead and flush the kernel flushes
3007c478bd9Sstevel@tonic-gate * Pass door name to kernel for door_ki_open
3017c478bd9Sstevel@tonic-gate */
3027c478bd9Sstevel@tonic-gate idmap_kcall(doorfd);
3037c478bd9Sstevel@tonic-gate
3047c478bd9Sstevel@tonic-gate /*
3057c478bd9Sstevel@tonic-gate * Wait for incoming calls
3067c478bd9Sstevel@tonic-gate */
3077c478bd9Sstevel@tonic-gate /*CONSTCOND*/
3087c478bd9Sstevel@tonic-gate while (1)
3097c478bd9Sstevel@tonic-gate (void) pause();
3107c478bd9Sstevel@tonic-gate
3117c478bd9Sstevel@tonic-gate syslog(LOG_ERR, gettext("Door server exited"));
3127c478bd9Sstevel@tonic-gate return (10);
3137c478bd9Sstevel@tonic-gate }
3147c478bd9Sstevel@tonic-gate
3157c478bd9Sstevel@tonic-gate /* ARGSUSED */
3167c478bd9Sstevel@tonic-gate int
main(int argc,char ** argv)3177c478bd9Sstevel@tonic-gate main(int argc, char **argv)
3187c478bd9Sstevel@tonic-gate {
3197c478bd9Sstevel@tonic-gate MyName = argv[0];
3207c478bd9Sstevel@tonic-gate
3217c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, "");
3227c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN);
3237c478bd9Sstevel@tonic-gate
3247c478bd9Sstevel@tonic-gate /* _check_services() framework setup */
3257c478bd9Sstevel@tonic-gate (void) _create_daemon_lock(NFSMAPID, DAEMON_UID, DAEMON_GID);
3267c478bd9Sstevel@tonic-gate
3277c478bd9Sstevel@tonic-gate /*
3287c478bd9Sstevel@tonic-gate * Open diag file in /var/run while we've got the perms
3297c478bd9Sstevel@tonic-gate */
3307c478bd9Sstevel@tonic-gate open_diag_file();
3317c478bd9Sstevel@tonic-gate
3327c478bd9Sstevel@tonic-gate /*
3337c478bd9Sstevel@tonic-gate * Initialize the daemon to basic + sys_nfs
3347c478bd9Sstevel@tonic-gate */
335*8200fe25Srmesta #ifndef DEBUG
3367c478bd9Sstevel@tonic-gate if (__init_daemon_priv(PU_RESETGROUPS|PU_CLEARLIMITSET,
3377c478bd9Sstevel@tonic-gate DAEMON_UID, DAEMON_GID, PRIV_SYS_NFS, (char *)NULL) == -1) {
3387c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s PRIV_SYS_NFS privilege "
3397c478bd9Sstevel@tonic-gate "missing\n"), MyName);
3407c478bd9Sstevel@tonic-gate exit(1);
3417c478bd9Sstevel@tonic-gate }
342*8200fe25Srmesta #endif
3437c478bd9Sstevel@tonic-gate
3447c478bd9Sstevel@tonic-gate /*
3457c478bd9Sstevel@tonic-gate * Take away a subset of basic, while this is not the absolute
3467c478bd9Sstevel@tonic-gate * minimum, it is important that it is unique among other
3477c478bd9Sstevel@tonic-gate * daemons to insure that we get a unique cred that will
3487c478bd9Sstevel@tonic-gate * result in a unique open_owner. If not, we run the risk
3497c478bd9Sstevel@tonic-gate * of a diskless client deadlocking with a thread holding
3507c478bd9Sstevel@tonic-gate * the open_owner seqid lock while upcalling the daemon.
3517c478bd9Sstevel@tonic-gate * XXX This restriction will go away once we stop holding
3527c478bd9Sstevel@tonic-gate * XXX open_owner lock across rfscalls!
3537c478bd9Sstevel@tonic-gate */
3547c478bd9Sstevel@tonic-gate (void) priv_set(PRIV_OFF, PRIV_PERMITTED,
3557c478bd9Sstevel@tonic-gate PRIV_FILE_LINK_ANY, PRIV_PROC_SESSION,
3567c478bd9Sstevel@tonic-gate (char *)NULL);
3577c478bd9Sstevel@tonic-gate
3587c478bd9Sstevel@tonic-gate #ifndef DEBUG
3597c478bd9Sstevel@tonic-gate daemonize();
3607c478bd9Sstevel@tonic-gate switch (_enter_daemon_lock(NFSMAPID)) {
3617c478bd9Sstevel@tonic-gate case 0:
3627c478bd9Sstevel@tonic-gate break;
3637c478bd9Sstevel@tonic-gate
3647c478bd9Sstevel@tonic-gate case -1:
3657c478bd9Sstevel@tonic-gate syslog(LOG_ERR, "error locking for %s: %s", NFSMAPID,
3667c478bd9Sstevel@tonic-gate strerror(errno));
3677c478bd9Sstevel@tonic-gate exit(3);
3687c478bd9Sstevel@tonic-gate
3697c478bd9Sstevel@tonic-gate default:
3707c478bd9Sstevel@tonic-gate /* daemon was already running */
3717c478bd9Sstevel@tonic-gate exit(0);
3727c478bd9Sstevel@tonic-gate }
3737c478bd9Sstevel@tonic-gate #endif
3747c478bd9Sstevel@tonic-gate openlog(MyName, LOG_PID | LOG_NDELAY, LOG_DAEMON);
3757c478bd9Sstevel@tonic-gate
3767c478bd9Sstevel@tonic-gate /* Initialize daemon subsystems */
3777c478bd9Sstevel@tonic-gate daemon_init();
3787c478bd9Sstevel@tonic-gate
3797c478bd9Sstevel@tonic-gate /* start services */
3807c478bd9Sstevel@tonic-gate return (start_svcs());
3817c478bd9Sstevel@tonic-gate }
382