Home | History | Annotate | Line # | Download | only in nfsd
nfsd.c revision 1.45
      1  1.45     lukem /*	$NetBSD: nfsd.c,v 1.45 2005/06/02 06:54:02 lukem Exp $	*/
      2  1.16       cgd 
      3   1.1       cgd /*
      4  1.11   mycroft  * Copyright (c) 1989, 1993, 1994
      5  1.11   mycroft  *	The Regents of the University of California.  All rights reserved.
      6   1.1       cgd  *
      7   1.1       cgd  * This code is derived from software contributed to Berkeley by
      8   1.1       cgd  * Rick Macklem at The University of Guelph.
      9   1.1       cgd  *
     10   1.1       cgd  * Redistribution and use in source and binary forms, with or without
     11   1.1       cgd  * modification, are permitted provided that the following conditions
     12   1.1       cgd  * are met:
     13   1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     14   1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     15   1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     17   1.1       cgd  *    documentation and/or other materials provided with the distribution.
     18  1.43       agc  * 3. Neither the name of the University nor the names of its contributors
     19   1.1       cgd  *    may be used to endorse or promote products derived from this software
     20   1.1       cgd  *    without specific prior written permission.
     21   1.1       cgd  *
     22   1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23   1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24   1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25   1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26   1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27   1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28   1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29   1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30   1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31   1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32   1.1       cgd  * SUCH DAMAGE.
     33   1.1       cgd  */
     34   1.1       cgd 
     35  1.23     lukem #include <sys/cdefs.h>
     36   1.1       cgd #ifndef lint
     37  1.23     lukem __COPYRIGHT("@(#) Copyright (c) 1989, 1993, 1994\n\
     38  1.23     lukem 	The Regents of the University of California.  All rights reserved.\n");
     39  1.35       cgd #endif /* not lint */
     40   1.1       cgd 
     41   1.1       cgd #ifndef lint
     42  1.16       cgd #if 0
     43  1.18      fvdl static char sccsid[] = "@(#)nfsd.c	8.9 (Berkeley) 3/29/95";
     44  1.16       cgd #else
     45  1.45     lukem __RCSID("$NetBSD: nfsd.c,v 1.45 2005/06/02 06:54:02 lukem Exp $");
     46  1.16       cgd #endif
     47  1.18      fvdl #endif /* not lint */
     48   1.1       cgd 
     49  1.11   mycroft #include <sys/param.h>
     50   1.1       cgd #include <sys/ioctl.h>
     51   1.1       cgd #include <sys/stat.h>
     52   1.1       cgd #include <sys/wait.h>
     53  1.11   mycroft #include <sys/uio.h>
     54  1.11   mycroft #include <sys/ucred.h>
     55   1.1       cgd #include <sys/mount.h>
     56   1.1       cgd #include <sys/socket.h>
     57   1.1       cgd #include <sys/socketvar.h>
     58  1.39    itojun #include <poll.h>
     59  1.11   mycroft 
     60   1.1       cgd #include <rpc/rpc.h>
     61   1.1       cgd #include <rpc/pmap_clnt.h>
     62   1.1       cgd #include <rpc/pmap_prot.h>
     63  1.11   mycroft 
     64  1.11   mycroft #ifdef ISO
     65  1.11   mycroft #include <netiso/iso.h>
     66  1.11   mycroft #endif
     67   1.1       cgd #include <nfs/rpcv2.h>
     68  1.18      fvdl #include <nfs/nfsproto.h>
     69  1.11   mycroft #include <nfs/nfs.h>
     70  1.11   mycroft 
     71  1.18      fvdl #ifdef NFSKERB
     72  1.42    itojun #include <des.h>
     73  1.11   mycroft #include <kerberosIV/krb.h>
     74  1.11   mycroft #endif
     75  1.11   mycroft 
     76  1.11   mycroft #include <err.h>
     77  1.11   mycroft #include <errno.h>
     78  1.11   mycroft #include <fcntl.h>
     79  1.11   mycroft #include <grp.h>
     80  1.11   mycroft #include <pwd.h>
     81  1.11   mycroft #include <signal.h>
     82  1.11   mycroft #include <stdio.h>
     83  1.11   mycroft #include <stdlib.h>
     84  1.25     perry #include <string.h>
     85  1.19   mycroft #include <syslog.h>
     86  1.11   mycroft #include <unistd.h>
     87  1.32      fvdl #include <netdb.h>
     88   1.1       cgd 
     89   1.1       cgd /* Global defs */
     90   1.1       cgd #ifdef DEBUG
     91   1.1       cgd #define	syslog(e, s)	fprintf(stderr,(s))
     92   1.1       cgd int	debug = 1;
     93   1.1       cgd #else
     94   1.1       cgd int	debug = 0;
     95   1.1       cgd #endif
     96  1.11   mycroft 
     97  1.11   mycroft struct	nfsd_srvargs nsd;
     98  1.11   mycroft 
     99  1.18      fvdl #ifdef NFSKERB
    100  1.11   mycroft char		lnam[ANAME_SZ];
    101  1.11   mycroft KTEXT_ST	kt;
    102  1.18      fvdl AUTH_DAT	kauth;
    103  1.11   mycroft char		inst[INST_SZ];
    104  1.18      fvdl struct nfsrpc_fullblock kin, kout;
    105  1.18      fvdl struct nfsrpc_fullverf kverf;
    106  1.18      fvdl NFSKERBKEY_T	kivec;
    107  1.18      fvdl struct timeval	ktv;
    108  1.18      fvdl NFSKERBKEYSCHED_T kerb_keysched;
    109  1.11   mycroft #endif
    110  1.11   mycroft 
    111  1.23     lukem int	main __P((int, char **));
    112  1.11   mycroft void	nonfs __P((int));
    113  1.11   mycroft void	reapchild __P((int));
    114  1.11   mycroft void	usage __P((void));
    115   1.1       cgd 
    116   1.1       cgd /*
    117   1.1       cgd  * Nfs server daemon mostly just a user context for nfssvc()
    118  1.11   mycroft  *
    119   1.1       cgd  * 1 - do file descriptor and signal cleanup
    120  1.11   mycroft  * 2 - fork the nfsd(s)
    121  1.11   mycroft  * 3 - create server socket(s)
    122  1.11   mycroft  * 4 - register socket with portmap
    123  1.11   mycroft  *
    124  1.28     lukem  * For connectionless protocols, just pass the socket into the kernel via
    125  1.11   mycroft  * nfssvc().
    126  1.11   mycroft  * For connection based sockets, loop doing accepts. When you get a new
    127  1.28     lukem  * socket from accept, pass the msgsock into the kernel via nfssvc().
    128   1.1       cgd  * The arguments are:
    129  1.11   mycroft  *	-c - support iso cltp clients
    130  1.11   mycroft  *	-r - reregister with portmapper
    131  1.11   mycroft  *	-t - support tcp nfs clients
    132  1.11   mycroft  *	-u - support udp nfs clients
    133  1.11   mycroft  * followed by "n" which is the number of nfsds' to fork off
    134   1.1       cgd  */
    135  1.11   mycroft int
    136  1.23     lukem main(argc, argv)
    137   1.1       cgd 	int argc;
    138  1.23     lukem 	char *argv[];
    139   1.1       cgd {
    140  1.11   mycroft 	struct nfsd_args nfsdargs;
    141  1.32      fvdl 	struct addrinfo *ai_udp, *ai_tcp, *ai_udp6, *ai_tcp6, hints;
    142  1.32      fvdl 	struct netconfig *nconf_udp, *nconf_tcp, *nconf_udp6, *nconf_tcp6;
    143  1.32      fvdl 	struct netbuf nb_udp, nb_tcp, nb_udp6, nb_tcp6;
    144  1.32      fvdl 	struct sockaddr_in inetpeer;
    145  1.32      fvdl 	struct sockaddr_in6 inet6peer;
    146  1.11   mycroft #ifdef ISO
    147  1.11   mycroft 	struct sockaddr_iso isoaddr, isopeer;
    148  1.11   mycroft #endif
    149  1.37   mycroft 	struct pollfd set[4];
    150  1.11   mycroft 	int ch, cltpflag, connect_type_cnt, i, len, maxsock, msgsock;
    151  1.32      fvdl 	int nfsdcnt, nfssvc_flag, on = 1, reregister, sock, tcpflag, tcpsock;
    152  1.32      fvdl 	int tcp6sock, ip6flag;
    153  1.32      fvdl 	int tp4cnt, tp4flag, tpipcnt, tpipflag, udpflag, ecode, s;
    154  1.23     lukem #ifdef NFSKERB
    155  1.23     lukem 	struct group *grp;
    156  1.23     lukem 	struct passwd *pwd;
    157  1.23     lukem 	struct ucred *cr;
    158  1.23     lukem 	struct timeval ktv;
    159  1.23     lukem 	int tp4sock, tpipsock;
    160  1.11   mycroft 	char *cp, **cpp;
    161  1.23     lukem #endif
    162  1.11   mycroft 
    163  1.44  jonathan #define	MAXNFSDCNT	1024
    164  1.11   mycroft #define	DEFNFSDCNT	 4
    165  1.11   mycroft 	nfsdcnt = DEFNFSDCNT;
    166  1.11   mycroft 	cltpflag = reregister = tcpflag = tp4cnt = tp4flag = tpipcnt = 0;
    167  1.32      fvdl 	tpipflag = udpflag = ip6flag = 0;
    168  1.45     lukem 	nconf_udp = nconf_tcp = nconf_udp6 = nconf_tcp6 = NULL;
    169  1.45     lukem 	maxsock = 0;
    170  1.45     lukem 	tcpsock = tcp6sock = -1;
    171  1.11   mycroft #ifdef ISO
    172  1.32      fvdl #define	GETOPT	"6cn:rtu"
    173  1.11   mycroft #define	USAGE	"[-crtu] [-n num_servers]"
    174  1.11   mycroft #else
    175  1.32      fvdl #define	GETOPT	"6n:rtu"
    176  1.11   mycroft #define	USAGE	"[-rtu] [-n num_servers]"
    177  1.11   mycroft #endif
    178  1.30   thorpej 	while ((ch = getopt(argc, argv, GETOPT)) != -1) {
    179  1.11   mycroft 		switch (ch) {
    180  1.32      fvdl 		case '6':
    181  1.32      fvdl 			ip6flag = 1;
    182  1.32      fvdl 			s = socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP);
    183  1.32      fvdl 			if (s < 0 && (errno == EPROTONOSUPPORT ||
    184  1.32      fvdl 			    errno == EPFNOSUPPORT || errno == EAFNOSUPPORT))
    185  1.32      fvdl 				ip6flag = 0;
    186  1.32      fvdl 			else
    187  1.32      fvdl 				close(s);
    188  1.32      fvdl 			break;
    189  1.11   mycroft 		case 'n':
    190  1.11   mycroft 			nfsdcnt = atoi(optarg);
    191  1.11   mycroft 			if (nfsdcnt < 1 || nfsdcnt > MAXNFSDCNT) {
    192  1.21      fvdl 				warnx("nfsd count %d; reset to %d", nfsdcnt, DEFNFSDCNT);
    193  1.11   mycroft 				nfsdcnt = DEFNFSDCNT;
    194  1.11   mycroft 			}
    195  1.11   mycroft 			break;
    196   1.1       cgd 		case 'r':
    197  1.11   mycroft 			reregister = 1;
    198   1.1       cgd 			break;
    199   1.1       cgd 		case 't':
    200  1.11   mycroft 			tcpflag = 1;
    201   1.1       cgd 			break;
    202   1.1       cgd 		case 'u':
    203  1.11   mycroft 			udpflag = 1;
    204  1.11   mycroft 			break;
    205  1.11   mycroft #ifdef ISO
    206  1.11   mycroft 		case 'c':
    207  1.11   mycroft 			cltpflag = 1;
    208   1.1       cgd 			break;
    209  1.11   mycroft #ifdef notyet
    210  1.11   mycroft 		case 'i':
    211  1.11   mycroft 			tp4cnt = 1;
    212  1.11   mycroft 			break;
    213  1.11   mycroft 		case 'p':
    214  1.11   mycroft 			tpipcnt = 1;
    215  1.11   mycroft 			break;
    216  1.11   mycroft #endif /* notyet */
    217  1.11   mycroft #endif /* ISO */
    218   1.1       cgd 		default:
    219   1.1       cgd 		case '?':
    220   1.1       cgd 			usage();
    221  1.11   mycroft 		};
    222  1.30   thorpej 	}
    223  1.11   mycroft 	argv += optind;
    224  1.11   mycroft 	argc -= optind;
    225   1.1       cgd 
    226   1.1       cgd 	/*
    227  1.11   mycroft 	 * XXX
    228  1.11   mycroft 	 * Backward compatibility, trailing number is the count of daemons.
    229   1.1       cgd 	 */
    230  1.11   mycroft 	if (argc > 1)
    231  1.11   mycroft 		usage();
    232  1.11   mycroft 	if (argc == 1) {
    233  1.11   mycroft 		nfsdcnt = atoi(argv[0]);
    234  1.11   mycroft 		if (nfsdcnt < 1 || nfsdcnt > MAXNFSDCNT) {
    235  1.21      fvdl 			warnx("nfsd count %d; reset to %d", nfsdcnt, DEFNFSDCNT);
    236  1.11   mycroft 			nfsdcnt = DEFNFSDCNT;
    237  1.11   mycroft 		}
    238   1.1       cgd 	}
    239  1.31     soren 
    240  1.31     soren 	/*
    241  1.31     soren 	 * If none of TCP or UDP are specified, default to UDP only.
    242  1.31     soren 	 */
    243  1.31     soren 	if (tcpflag == 0 && udpflag == 0)
    244  1.31     soren 		udpflag = 1;
    245   1.1       cgd 
    246   1.1       cgd 	if (debug == 0) {
    247   1.1       cgd 		daemon(0, 0);
    248  1.11   mycroft 		(void)signal(SIGHUP, SIG_IGN);
    249  1.11   mycroft 		(void)signal(SIGINT, SIG_IGN);
    250  1.11   mycroft 		(void)signal(SIGQUIT, SIG_IGN);
    251  1.11   mycroft 		(void)signal(SIGSYS, nonfs);
    252   1.1       cgd 	}
    253  1.11   mycroft 	(void)signal(SIGCHLD, reapchild);
    254  1.11   mycroft 
    255  1.32      fvdl 	if (udpflag) {
    256  1.32      fvdl 		memset(&hints, 0, sizeof hints);
    257  1.32      fvdl 		hints.ai_flags = AI_PASSIVE;
    258  1.32      fvdl 		hints.ai_family = PF_INET;
    259  1.32      fvdl 		hints.ai_socktype = SOCK_DGRAM;
    260  1.32      fvdl 		hints.ai_protocol = IPPROTO_UDP;
    261  1.32      fvdl 
    262  1.32      fvdl 		ecode = getaddrinfo(NULL, "nfs", &hints, &ai_udp);
    263  1.32      fvdl 		if (ecode != 0) {
    264  1.32      fvdl 			syslog(LOG_ERR, "getaddrinfo udp: %s",
    265  1.32      fvdl 			    gai_strerror(ecode));
    266  1.32      fvdl 			exit(1);
    267  1.32      fvdl 		}
    268  1.32      fvdl 
    269  1.32      fvdl 		nconf_udp = getnetconfigent("udp");
    270  1.32      fvdl 
    271  1.32      fvdl 		if (nconf_udp == NULL)
    272  1.32      fvdl 			err(1, "getnetconfigent udp failed");
    273  1.32      fvdl 
    274  1.32      fvdl 		nb_udp.buf = ai_udp->ai_addr;
    275  1.32      fvdl 		nb_udp.len = nb_udp.maxlen = ai_udp->ai_addrlen;
    276  1.32      fvdl 		if (reregister)
    277  1.32      fvdl 			if (!rpcb_set(RPCPROG_NFS, 2, nconf_udp, &nb_udp))
    278  1.32      fvdl 				err(1, "rpcb_set udp failed");
    279  1.32      fvdl 	}
    280  1.32      fvdl 
    281  1.32      fvdl 	if (tcpflag) {
    282  1.32      fvdl 		memset(&hints, 0, sizeof hints);
    283  1.32      fvdl 		hints.ai_flags = AI_PASSIVE;
    284  1.32      fvdl 		hints.ai_family = PF_INET;
    285  1.32      fvdl 		hints.ai_socktype = SOCK_STREAM;
    286  1.32      fvdl 		hints.ai_protocol = IPPROTO_TCP;
    287  1.32      fvdl 
    288  1.32      fvdl 		ecode = getaddrinfo(NULL, "nfs", &hints, &ai_tcp);
    289  1.32      fvdl 		if (ecode != 0) {
    290  1.32      fvdl 			syslog(LOG_ERR, "getaddrinfo udp: %s",
    291  1.32      fvdl 			    gai_strerror(ecode));
    292  1.32      fvdl 			exit(1);
    293  1.32      fvdl 		}
    294  1.32      fvdl 
    295  1.32      fvdl 		nconf_tcp = getnetconfigent("tcp");
    296  1.32      fvdl 
    297  1.32      fvdl 		if (nconf_tcp == NULL)
    298  1.32      fvdl 			err(1, "getnetconfigent tcp failed");
    299  1.32      fvdl 
    300  1.32      fvdl 		nb_tcp.buf = ai_tcp->ai_addr;
    301  1.32      fvdl 		nb_tcp.len = nb_tcp.maxlen = ai_tcp->ai_addrlen;
    302  1.32      fvdl 		if (reregister)
    303  1.32      fvdl 			if (!rpcb_set(RPCPROG_NFS, 2, nconf_tcp, &nb_tcp))
    304  1.32      fvdl 				err(1, "rpcb_set tcp failed");
    305  1.32      fvdl 	}
    306  1.32      fvdl 
    307  1.32      fvdl 	if (udpflag && ip6flag) {
    308  1.32      fvdl 		memset(&hints, 0, sizeof hints);
    309  1.32      fvdl 		hints.ai_flags = AI_PASSIVE;
    310  1.32      fvdl 		hints.ai_family = PF_INET6;
    311  1.32      fvdl 		hints.ai_socktype = SOCK_DGRAM;
    312  1.32      fvdl 		hints.ai_protocol = IPPROTO_UDP;
    313  1.32      fvdl 
    314  1.32      fvdl 		ecode = getaddrinfo(NULL, "nfs", &hints, &ai_udp6);
    315  1.32      fvdl 		if (ecode != 0) {
    316  1.32      fvdl 			syslog(LOG_ERR, "getaddrinfo udp: %s",
    317  1.32      fvdl 			    gai_strerror(ecode));
    318  1.32      fvdl 			exit(1);
    319  1.32      fvdl 		}
    320  1.32      fvdl 
    321  1.32      fvdl 		nconf_udp6 = getnetconfigent("udp6");
    322  1.32      fvdl 
    323  1.32      fvdl 		if (nconf_udp6 == NULL)
    324  1.32      fvdl 			err(1, "getnetconfigent udp6 failed");
    325  1.32      fvdl 
    326  1.32      fvdl 		nb_udp6.buf = ai_udp6->ai_addr;
    327  1.32      fvdl 		nb_udp6.len = nb_udp6.maxlen = ai_udp6->ai_addrlen;
    328  1.32      fvdl 		if (reregister)
    329  1.32      fvdl 			if (!rpcb_set(RPCPROG_NFS, 2, nconf_udp6, &nb_udp6))
    330  1.32      fvdl 				err(1, "rpcb_set udp6 failed");
    331  1.32      fvdl 	}
    332  1.32      fvdl 
    333  1.32      fvdl 	if (tcpflag && ip6flag) {
    334  1.32      fvdl 		memset(&hints, 0, sizeof hints);
    335  1.32      fvdl 		hints.ai_flags = AI_PASSIVE;
    336  1.32      fvdl 		hints.ai_family = PF_INET6;
    337  1.32      fvdl 		hints.ai_socktype = SOCK_STREAM;
    338  1.32      fvdl 		hints.ai_protocol = IPPROTO_TCP;
    339  1.32      fvdl 
    340  1.32      fvdl 		ecode = getaddrinfo(NULL, "nfs", &hints, &ai_tcp6);
    341  1.32      fvdl 		if (ecode != 0) {
    342  1.32      fvdl 			syslog(LOG_ERR, "getaddrinfo udp: %s",
    343  1.32      fvdl 			    gai_strerror(ecode));
    344  1.32      fvdl 			exit(1);
    345  1.32      fvdl 		}
    346  1.32      fvdl 
    347  1.32      fvdl 		nconf_tcp6 = getnetconfigent("tcp6");
    348  1.32      fvdl 
    349  1.32      fvdl 		if (nconf_tcp6 == NULL)
    350  1.32      fvdl 			err(1, "getnetconfigent tcp6 failed");
    351  1.32      fvdl 
    352  1.32      fvdl 		nb_tcp6.buf = ai_tcp6->ai_addr;
    353  1.32      fvdl 		nb_tcp6.len = nb_tcp6.maxlen = ai_tcp6->ai_addrlen;
    354  1.32      fvdl 		if (reregister)
    355  1.32      fvdl 			if (!rpcb_set(RPCPROG_NFS, 2, nconf_tcp6, &nb_tcp6))
    356  1.32      fvdl 				err(1, "rpcb_set tcp6 failed");
    357   1.8       cgd 	}
    358  1.32      fvdl 
    359  1.33     lukem 	openlog("nfsd", LOG_PID, LOG_DAEMON);
    360  1.11   mycroft 
    361  1.11   mycroft 	for (i = 0; i < nfsdcnt; i++) {
    362  1.11   mycroft 		switch (fork()) {
    363  1.11   mycroft 		case -1:
    364  1.11   mycroft 			syslog(LOG_ERR, "fork: %m");
    365  1.11   mycroft 			exit (1);
    366  1.11   mycroft 		case 0:
    367  1.11   mycroft 			break;
    368  1.11   mycroft 		default:
    369  1.11   mycroft 			continue;
    370   1.1       cgd 		}
    371  1.11   mycroft 
    372  1.13   mycroft 		setproctitle("server");
    373  1.11   mycroft 		nfssvc_flag = NFSSVC_NFSD;
    374  1.11   mycroft 		nsd.nsd_nfsd = NULL;
    375  1.18      fvdl #ifdef NFSKERB
    376  1.18      fvdl 		if (sizeof (struct nfsrpc_fullverf) != RPCX_FULLVERF ||
    377  1.18      fvdl 		    sizeof (struct nfsrpc_fullblock) != RPCX_FULLBLOCK)
    378  1.34     lukem 			syslog(LOG_ERR, "Yikes NFSKERB structs not packed!");
    379  1.18      fvdl 		nsd.nsd_authstr = (u_char *)&kt;
    380  1.18      fvdl 		nsd.nsd_authlen = sizeof (kt);
    381  1.18      fvdl 		nsd.nsd_verfstr = (u_char *)&kverf;
    382  1.18      fvdl 		nsd.nsd_verflen = sizeof (kverf);
    383  1.11   mycroft #endif
    384  1.11   mycroft 		while (nfssvc(nfssvc_flag, &nsd) < 0) {
    385  1.11   mycroft 			if (errno != ENEEDAUTH) {
    386  1.11   mycroft 				syslog(LOG_ERR, "nfssvc: %m");
    387  1.11   mycroft 				exit(1);
    388  1.11   mycroft 			}
    389  1.11   mycroft 			nfssvc_flag = NFSSVC_NFSD | NFSSVC_AUTHINFAIL;
    390  1.18      fvdl #ifdef NFSKERB
    391  1.18      fvdl 			/*
    392  1.18      fvdl 			 * Get the Kerberos ticket out of the authenticator
    393  1.18      fvdl 			 * verify it and convert the principal name to a user
    394  1.18      fvdl 			 * name. The user name is then converted to a set of
    395  1.18      fvdl 			 * user credentials via the password and group file.
    396  1.18      fvdl 			 * Finally, decrypt the timestamp and validate it.
    397  1.18      fvdl 			 * For more info see the IETF Draft "Authentication
    398  1.18      fvdl 			 * in ONC RPC".
    399  1.18      fvdl 			 */
    400  1.18      fvdl 			kt.length = ntohl(kt.length);
    401  1.18      fvdl 			if (gettimeofday(&ktv, (struct timezone *)0) == 0 &&
    402  1.18      fvdl 			    kt.length > 0 && kt.length <=
    403  1.18      fvdl 			    (RPCAUTH_MAXSIZ - 3 * NFSX_UNSIGNED)) {
    404  1.30   thorpej 				kin.w1 = NFS_KERBW1(kt);
    405  1.30   thorpej 				kt.mbz = 0;
    406  1.30   thorpej 				(void)strcpy(inst, "*");
    407  1.30   thorpej 				if (krb_rd_req(&kt, NFS_KERBSRV,
    408  1.30   thorpej 				     inst, nsd.nsd_haddr, &kauth, "") ==
    409  1.30   thorpej 				     RD_AP_OK &&
    410  1.30   thorpej 				    krb_kntoln(&kauth, lnam) == KSUCCESS &&
    411  1.30   thorpej 				    (pwd = getpwnam(lnam)) != NULL) {
    412  1.30   thorpej 					cr = &nsd.nsd_cr;
    413  1.30   thorpej 					cr->cr_uid = pwd->pw_uid;
    414  1.30   thorpej 					cr->cr_groups[0] = pwd->pw_gid;
    415  1.30   thorpej 					cr->cr_ngroups = 1;
    416  1.30   thorpej 					setgrent();
    417  1.30   thorpej 					while ((grp = getgrent()) != NULL) {
    418  1.30   thorpej 						if (grp->gr_gid ==
    419  1.30   thorpej 						    cr->cr_groups[0])
    420  1.30   thorpej 							continue;
    421  1.30   thorpej 						for (cpp = grp->gr_mem;
    422  1.30   thorpej 						    *cpp != NULL; ++cpp)
    423  1.30   thorpej 							if (!strcmp(*cpp, lnam))
    424  1.30   thorpej 								break;
    425  1.30   thorpej 						if (*cpp == NULL)
    426  1.30   thorpej 							continue;
    427  1.30   thorpej 						cr->cr_groups[cr->cr_ngroups++]
    428  1.30   thorpej 						    = grp->gr_gid;
    429  1.30   thorpej 						if (cr->cr_ngroups == NGROUPS)
    430  1.11   mycroft 							break;
    431  1.30   thorpej 					}
    432  1.30   thorpej 					endgrent();
    433  1.30   thorpej 
    434  1.30   thorpej 					/*
    435  1.30   thorpej 					 * Get the timestamp verifier out of
    436  1.30   thorpej 					 * the authenticator and verifier
    437  1.30   thorpej 					 * strings.
    438  1.30   thorpej 					 */
    439  1.30   thorpej 					kin.t1 = kverf.t1;
    440  1.30   thorpej 					kin.t2 = kverf.t2;
    441  1.30   thorpej 					kin.w2 = kverf.w2;
    442  1.30   thorpej 					memset((caddr_t)kivec, 0,
    443  1.30   thorpej 					    sizeof(kivec));
    444  1.30   thorpej 					memmove((caddr_t)nsd.nsd_key,
    445  1.30   thorpej 					    (caddr_t)kauth.session,
    446  1.30   thorpej 					    sizeof(kauth.session));
    447  1.30   thorpej 
    448  1.30   thorpej 					/*
    449  1.30   thorpej 					 * Decrypt the timestamp verifier
    450  1.30   thorpej 					 * in CBC mode.
    451  1.30   thorpej 					 */
    452  1.30   thorpej 					XXX
    453  1.30   thorpej 
    454  1.30   thorpej 					/*
    455  1.30   thorpej 					 * Validate the timestamp verifier, to
    456  1.30   thorpej 					 * check that the session key is ok.
    457  1.30   thorpej 					 */
    458  1.30   thorpej 					nsd.nsd_timestamp.tv_sec =
    459  1.30   thorpej 					    ntohl(kout.t1);
    460  1.30   thorpej 					nsd.nsd_timestamp.tv_usec =
    461  1.30   thorpej 					    ntohl(kout.t2);
    462  1.30   thorpej 					nsd.nsd_ttl = ntohl(kout.w1);
    463  1.30   thorpej 					if ((nsd.nsd_ttl - 1) == ntohl(kout.w2))
    464  1.30   thorpej 					    nfssvc_flag =
    465  1.30   thorpej 					        NFSSVC_NFSD | NFSSVC_AUTHIN;
    466  1.11   mycroft 				}
    467  1.11   mycroft 			}
    468  1.18      fvdl #endif /* NFSKERB */
    469   1.1       cgd 		}
    470   1.1       cgd 		exit(0);
    471   1.1       cgd 	}
    472  1.11   mycroft 
    473  1.11   mycroft 	/* If we are serving udp, set up the socket. */
    474   1.1       cgd 	if (udpflag) {
    475  1.32      fvdl 		if ((sock = socket(ai_udp->ai_family, ai_udp->ai_socktype,
    476  1.32      fvdl 		    ai_udp->ai_protocol)) < 0) {
    477  1.11   mycroft 			syslog(LOG_ERR, "can't create udp socket");
    478   1.1       cgd 			exit(1);
    479   1.1       cgd 		}
    480  1.32      fvdl 		if (bind(sock, ai_udp->ai_addr, ai_udp->ai_addrlen) < 0) {
    481  1.32      fvdl 			syslog(LOG_ERR, "can't bind udp addr");
    482  1.32      fvdl 			exit(1);
    483  1.32      fvdl 		}
    484  1.32      fvdl 		if (!rpcb_set(RPCPROG_NFS, 2, nconf_udp, &nb_udp) ||
    485  1.32      fvdl 		    !rpcb_set(RPCPROG_NFS, 3, nconf_udp, &nb_udp)) {
    486  1.32      fvdl 			syslog(LOG_ERR, "can't register with udp portmap");
    487  1.32      fvdl 			exit(1);
    488  1.32      fvdl 		}
    489  1.32      fvdl 		nfsdargs.sock = sock;
    490  1.32      fvdl 		nfsdargs.name = NULL;
    491  1.32      fvdl 		nfsdargs.namelen = 0;
    492  1.32      fvdl 		if (nfssvc(NFSSVC_ADDSOCK, &nfsdargs) < 0) {
    493  1.32      fvdl 			syslog(LOG_ERR, "can't add UDP socket");
    494  1.32      fvdl 			exit(1);
    495  1.32      fvdl 		}
    496  1.32      fvdl 		(void)close(sock);
    497  1.32      fvdl 	}
    498  1.32      fvdl 
    499  1.32      fvdl 	if (udpflag &&ip6flag) {
    500  1.32      fvdl 		if ((sock = socket(ai_udp6->ai_family, ai_udp6->ai_socktype,
    501  1.32      fvdl 		    ai_udp6->ai_protocol)) < 0) {
    502  1.32      fvdl 			syslog(LOG_ERR, "can't create udp socket");
    503  1.32      fvdl 			exit(1);
    504  1.32      fvdl 		}
    505  1.36    itojun 		if (setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY,
    506  1.32      fvdl 		    &on, sizeof on) < 0) {
    507  1.32      fvdl 			syslog(LOG_ERR, "can't set v6-only binding for udp6 "
    508  1.32      fvdl 					"socket: %m");
    509  1.32      fvdl 			exit(1);
    510  1.32      fvdl 		}
    511  1.32      fvdl 		if (bind(sock, ai_udp6->ai_addr, ai_udp6->ai_addrlen) < 0) {
    512  1.11   mycroft 			syslog(LOG_ERR, "can't bind udp addr");
    513   1.1       cgd 			exit(1);
    514   1.1       cgd 		}
    515  1.32      fvdl 		if (!rpcb_set(RPCPROG_NFS, 2, nconf_udp6, &nb_udp6) ||
    516  1.32      fvdl 		    !rpcb_set(RPCPROG_NFS, 3, nconf_udp6, &nb_udp6)) {
    517  1.11   mycroft 			syslog(LOG_ERR, "can't register with udp portmap");
    518  1.11   mycroft 			exit(1);
    519  1.11   mycroft 		}
    520  1.11   mycroft 		nfsdargs.sock = sock;
    521  1.11   mycroft 		nfsdargs.name = NULL;
    522  1.11   mycroft 		nfsdargs.namelen = 0;
    523  1.11   mycroft 		if (nfssvc(NFSSVC_ADDSOCK, &nfsdargs) < 0) {
    524  1.32      fvdl 			syslog(LOG_ERR, "can't add UDP6 socket");
    525  1.11   mycroft 			exit(1);
    526  1.11   mycroft 		}
    527  1.11   mycroft 		(void)close(sock);
    528  1.11   mycroft 	}
    529  1.11   mycroft 
    530  1.11   mycroft #ifdef ISO
    531  1.11   mycroft 	/* If we are serving cltp, set up the socket. */
    532  1.11   mycroft 	if (cltpflag) {
    533  1.11   mycroft 		if ((sock = socket(AF_ISO, SOCK_DGRAM, 0)) < 0) {
    534  1.11   mycroft 			syslog(LOG_ERR, "can't create cltp socket");
    535  1.11   mycroft 			exit(1);
    536  1.11   mycroft 		}
    537  1.11   mycroft 		memset(&isoaddr, 0, sizeof(isoaddr));
    538  1.11   mycroft 		isoaddr.siso_family = AF_ISO;
    539  1.11   mycroft 		isoaddr.siso_tlen = 2;
    540  1.11   mycroft 		cp = TSEL(&isoaddr);
    541  1.11   mycroft 		*cp++ = (NFS_PORT >> 8);
    542  1.11   mycroft 		*cp = (NFS_PORT & 0xff);
    543  1.11   mycroft 		isoaddr.siso_len = sizeof(isoaddr);
    544  1.11   mycroft 		if (bind(sock,
    545  1.11   mycroft 		    (struct sockaddr *)&isoaddr, sizeof(isoaddr)) < 0) {
    546  1.11   mycroft 			syslog(LOG_ERR, "can't bind cltp addr");
    547   1.1       cgd 			exit(1);
    548   1.1       cgd 		}
    549  1.11   mycroft #ifdef notyet
    550   1.1       cgd 		/*
    551  1.11   mycroft 		 * XXX
    552  1.11   mycroft 		 * Someday this should probably use "rpcbind", the son of
    553  1.11   mycroft 		 * portmap.
    554   1.1       cgd 		 */
    555  1.11   mycroft 		if (!pmap_set(RPCPROG_NFS, NFS_VER2, IPPROTO_UDP, NFS_PORT)) {
    556  1.11   mycroft 			syslog(LOG_ERR, "can't register with udp portmap");
    557  1.11   mycroft 			exit(1);
    558  1.11   mycroft 		}
    559  1.11   mycroft #endif /* notyet */
    560  1.11   mycroft 		nfsdargs.sock = sock;
    561  1.11   mycroft 		nfsdargs.name = NULL;
    562  1.11   mycroft 		nfsdargs.namelen = 0;
    563  1.11   mycroft 		if (nfssvc(NFSSVC_ADDSOCK, &nfsdargs) < 0) {
    564  1.11   mycroft 			syslog(LOG_ERR, "can't add UDP socket");
    565  1.11   mycroft 			exit(1);
    566  1.11   mycroft 		}
    567   1.1       cgd 		close(sock);
    568   1.1       cgd 	}
    569  1.11   mycroft #endif /* ISO */
    570   1.1       cgd 
    571  1.11   mycroft 	/* Now set up the master server socket waiting for tcp connections. */
    572  1.11   mycroft 	on = 1;
    573  1.11   mycroft 	connect_type_cnt = 0;
    574   1.1       cgd 	if (tcpflag) {
    575  1.32      fvdl 		if ((tcpsock = socket(ai_tcp->ai_family, ai_tcp->ai_socktype,
    576  1.32      fvdl 		    ai_tcp->ai_protocol)) < 0) {
    577  1.11   mycroft 			syslog(LOG_ERR, "can't create tcp socket");
    578  1.11   mycroft 			exit(1);
    579  1.11   mycroft 		}
    580  1.11   mycroft 		if (setsockopt(tcpsock,
    581  1.11   mycroft 		    SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0)
    582  1.11   mycroft 			syslog(LOG_ERR, "setsockopt SO_REUSEADDR: %m");
    583  1.32      fvdl 		if (bind(tcpsock, ai_tcp->ai_addr, ai_tcp->ai_addrlen) < 0) {
    584  1.11   mycroft 			syslog(LOG_ERR, "can't bind tcp addr");
    585  1.11   mycroft 			exit(1);
    586  1.11   mycroft 		}
    587  1.11   mycroft 		if (listen(tcpsock, 5) < 0) {
    588  1.11   mycroft 			syslog(LOG_ERR, "listen failed");
    589  1.11   mycroft 			exit(1);
    590  1.11   mycroft 		}
    591  1.32      fvdl 		if (!rpcb_set(RPCPROG_NFS, 2, nconf_tcp, &nb_tcp) ||
    592  1.32      fvdl 		    !rpcb_set(RPCPROG_NFS, 3, nconf_tcp, &nb_tcp)) {
    593  1.32      fvdl 			syslog(LOG_ERR, "can't register tcp with rpcbind");
    594  1.11   mycroft 			exit(1);
    595  1.11   mycroft 		}
    596  1.37   mycroft 		set[0].fd = tcpsock;
    597  1.37   mycroft 		set[0].events = POLLIN;
    598  1.11   mycroft 		connect_type_cnt++;
    599  1.37   mycroft 	} else
    600  1.38   mycroft 		set[0].fd = -1;
    601   1.1       cgd 
    602  1.32      fvdl 	if (tcpflag && ip6flag) {
    603  1.32      fvdl 		if ((tcp6sock = socket(ai_tcp6->ai_family, ai_tcp6->ai_socktype,
    604  1.32      fvdl 		    ai_tcp6->ai_protocol)) < 0) {
    605  1.32      fvdl 			syslog(LOG_ERR, "can't create tcp socket");
    606  1.32      fvdl 			exit(1);
    607  1.32      fvdl 		}
    608  1.32      fvdl 		if (setsockopt(tcp6sock,
    609  1.32      fvdl 		    SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0)
    610  1.32      fvdl 			syslog(LOG_ERR, "setsockopt SO_REUSEADDR: %m");
    611  1.36    itojun 		if (setsockopt(tcp6sock, IPPROTO_IPV6, IPV6_V6ONLY,
    612  1.32      fvdl 		    &on, sizeof on) < 0) {
    613  1.32      fvdl 			syslog(LOG_ERR, "can't set v6-only binding for tcp6 "
    614  1.32      fvdl 					"socket: %m");
    615  1.32      fvdl 			exit(1);
    616  1.32      fvdl 		}
    617  1.32      fvdl 		if (bind(tcp6sock, ai_tcp6->ai_addr, ai_tcp6->ai_addrlen) < 0) {
    618  1.32      fvdl 			syslog(LOG_ERR, "can't bind tcp6 addr");
    619  1.32      fvdl 			exit(1);
    620  1.32      fvdl 		}
    621  1.32      fvdl 		if (listen(tcp6sock, 5) < 0) {
    622  1.32      fvdl 			syslog(LOG_ERR, "listen failed");
    623  1.32      fvdl 			exit(1);
    624  1.32      fvdl 		}
    625  1.32      fvdl 		if (!rpcb_set(RPCPROG_NFS, 2, nconf_tcp6, &nb_tcp6) ||
    626  1.32      fvdl 		    !rpcb_set(RPCPROG_NFS, 3, nconf_tcp6, &nb_tcp6)) {
    627  1.32      fvdl 			syslog(LOG_ERR, "can't register tcp6 with rpcbind");
    628  1.32      fvdl 			exit(1);
    629  1.32      fvdl 		}
    630  1.37   mycroft 		set[1].fd = tcp6sock;
    631  1.37   mycroft 		set[1].events = POLLIN;
    632  1.32      fvdl 		connect_type_cnt++;
    633  1.37   mycroft 	} else
    634  1.38   mycroft 		set[1].fd = -1;
    635  1.32      fvdl 
    636  1.11   mycroft #ifdef notyet
    637  1.11   mycroft 	/* Now set up the master server socket waiting for tp4 connections. */
    638  1.11   mycroft 	if (tp4flag) {
    639  1.11   mycroft 		if ((tp4sock = socket(AF_ISO, SOCK_SEQPACKET, 0)) < 0) {
    640  1.11   mycroft 			syslog(LOG_ERR, "can't create tp4 socket");
    641   1.1       cgd 			exit(1);
    642   1.1       cgd 		}
    643  1.11   mycroft 		if (setsockopt(tp4sock,
    644  1.11   mycroft 		    SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0)
    645   1.1       cgd 			syslog(LOG_ERR, "setsockopt SO_REUSEADDR: %m");
    646  1.11   mycroft 		memset(&isoaddr, 0, sizeof(isoaddr));
    647  1.11   mycroft 		isoaddr.siso_family = AF_ISO;
    648  1.11   mycroft 		isoaddr.siso_tlen = 2;
    649  1.11   mycroft 		cp = TSEL(&isoaddr);
    650  1.11   mycroft 		*cp++ = (NFS_PORT >> 8);
    651  1.11   mycroft 		*cp = (NFS_PORT & 0xff);
    652  1.11   mycroft 		isoaddr.siso_len = sizeof(isoaddr);
    653  1.11   mycroft 		if (bind(tp4sock,
    654  1.12   mycroft 		    (struct sockaddr *)&isoaddr, sizeof(isoaddr)) < 0) {
    655  1.11   mycroft 			syslog(LOG_ERR, "can't bind tp4 addr");
    656   1.1       cgd 			exit(1);
    657   1.1       cgd 		}
    658  1.11   mycroft 		if (listen(tp4sock, 5) < 0) {
    659  1.11   mycroft 			syslog(LOG_ERR, "listen failed");
    660   1.1       cgd 			exit(1);
    661   1.1       cgd 		}
    662  1.11   mycroft 		/*
    663  1.11   mycroft 		 * XXX
    664  1.11   mycroft 		 * Someday this should probably use "rpcbind", the son of
    665  1.11   mycroft 		 * portmap.
    666  1.11   mycroft 		 */
    667   1.1       cgd 		if (!pmap_set(RPCPROG_NFS, NFS_VER2, IPPROTO_TCP, NFS_PORT)) {
    668  1.11   mycroft 			syslog(LOG_ERR, "can't register tcp with portmap");
    669  1.11   mycroft 			exit(1);
    670  1.11   mycroft 		}
    671  1.37   mycroft 		set[2].fd = tp4sock;
    672  1.37   mycroft 		set[2].events = POLLIN;
    673  1.11   mycroft 		connect_type_cnt++;
    674  1.37   mycroft 	} else
    675  1.38   mycroft 		set[2].fd = -1;
    676  1.11   mycroft 
    677  1.11   mycroft 	/* Now set up the master server socket waiting for tpip connections. */
    678  1.11   mycroft 	if (tpipflag) {
    679  1.11   mycroft 		if ((tpipsock = socket(AF_INET, SOCK_SEQPACKET, 0)) < 0) {
    680  1.11   mycroft 			syslog(LOG_ERR, "can't create tpip socket");
    681  1.11   mycroft 			exit(1);
    682  1.11   mycroft 		}
    683  1.11   mycroft 		if (setsockopt(tpipsock,
    684  1.11   mycroft 		    SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0)
    685  1.11   mycroft 			syslog(LOG_ERR, "setsockopt SO_REUSEADDR: %m");
    686  1.11   mycroft 		inetaddr.sin_family = AF_INET;
    687  1.11   mycroft 		inetaddr.sin_addr.s_addr = INADDR_ANY;
    688  1.11   mycroft 		inetaddr.sin_port = htons(NFS_PORT);
    689  1.11   mycroft 		inetaddr.sin_len = sizeof(inetaddr);
    690  1.20   mycroft 		memset(inetaddr.sin_zero, 0, sizeof(inetaddr.sin_zero));
    691  1.11   mycroft 		if (bind(tpipsock,
    692  1.11   mycroft 		    (struct sockaddr *)&inetaddr, sizeof (inetaddr)) < 0) {
    693  1.11   mycroft 			syslog(LOG_ERR, "can't bind tcp addr");
    694  1.11   mycroft 			exit(1);
    695  1.11   mycroft 		}
    696  1.11   mycroft 		if (listen(tpipsock, 5) < 0) {
    697  1.11   mycroft 			syslog(LOG_ERR, "listen failed");
    698   1.1       cgd 			exit(1);
    699   1.1       cgd 		}
    700   1.1       cgd 		/*
    701  1.11   mycroft 		 * XXX
    702  1.11   mycroft 		 * Someday this should probably use "rpcbind", the son of
    703  1.11   mycroft 		 * portmap.
    704   1.1       cgd 		 */
    705  1.11   mycroft 		if (!pmap_set(RPCPROG_NFS, NFS_VER2, IPPROTO_TCP, NFS_PORT)) {
    706  1.11   mycroft 			syslog(LOG_ERR, "can't register tcp with portmap");
    707  1.11   mycroft 			exit(1);
    708  1.11   mycroft 		}
    709  1.37   mycroft 		set[3].fd = tpipsock;
    710  1.37   mycroft 		set[3].events = POLLIN;
    711  1.11   mycroft 		connect_type_cnt++;
    712  1.37   mycroft 	} else
    713  1.38   mycroft 		set[3].fd = -1;
    714  1.37   mycroft #else
    715  1.38   mycroft 	set[2].fd = -1;
    716  1.38   mycroft 	set[3].fd = -1;
    717  1.11   mycroft #endif /* notyet */
    718  1.11   mycroft 
    719  1.11   mycroft 	if (connect_type_cnt == 0)
    720  1.11   mycroft 		exit(0);
    721  1.11   mycroft 
    722  1.13   mycroft 	setproctitle("master");
    723  1.11   mycroft 
    724  1.11   mycroft 	/*
    725  1.11   mycroft 	 * Loop forever accepting connections and passing the sockets
    726  1.11   mycroft 	 * into the kernel for the mounts.
    727  1.11   mycroft 	 */
    728  1.11   mycroft 	for (;;) {
    729  1.41   mycroft 		if (poll(set, 4, INFTIM) < 1) {
    730  1.41   mycroft 			syslog(LOG_ERR, "select failed: %m");
    731  1.41   mycroft 			exit(1);
    732  1.11   mycroft 		}
    733  1.38   mycroft 
    734  1.37   mycroft 		if (set[0].revents & POLLIN) {
    735  1.11   mycroft 			len = sizeof(inetpeer);
    736  1.11   mycroft 			if ((msgsock = accept(tcpsock,
    737  1.11   mycroft 			    (struct sockaddr *)&inetpeer, &len)) < 0) {
    738  1.11   mycroft 				syslog(LOG_ERR, "accept failed: %m");
    739   1.1       cgd 				exit(1);
    740   1.1       cgd 			}
    741  1.11   mycroft 			memset(inetpeer.sin_zero, 0, sizeof(inetpeer.sin_zero));
    742  1.11   mycroft 			if (setsockopt(msgsock, SOL_SOCKET,
    743  1.11   mycroft 			    SO_KEEPALIVE, (char *)&on, sizeof(on)) < 0)
    744  1.11   mycroft 				syslog(LOG_ERR,
    745  1.11   mycroft 				    "setsockopt SO_KEEPALIVE: %m");
    746  1.11   mycroft 			nfsdargs.sock = msgsock;
    747  1.11   mycroft 			nfsdargs.name = (caddr_t)&inetpeer;
    748  1.11   mycroft 			nfsdargs.namelen = sizeof(inetpeer);
    749  1.11   mycroft 			nfssvc(NFSSVC_ADDSOCK, &nfsdargs);
    750  1.11   mycroft 			(void)close(msgsock);
    751  1.11   mycroft 		}
    752  1.32      fvdl 
    753  1.37   mycroft 		if (set[1].revents & POLLIN) {
    754  1.32      fvdl 			len = sizeof(inet6peer);
    755  1.32      fvdl 			if ((msgsock = accept(tcp6sock,
    756  1.32      fvdl 			    (struct sockaddr *)&inet6peer, &len)) < 0) {
    757  1.32      fvdl 				syslog(LOG_ERR, "accept failed: %m");
    758  1.32      fvdl 				exit(1);
    759  1.32      fvdl 			}
    760  1.32      fvdl 			if (setsockopt(msgsock, SOL_SOCKET,
    761  1.32      fvdl 			    SO_KEEPALIVE, (char *)&on, sizeof(on)) < 0)
    762  1.32      fvdl 				syslog(LOG_ERR,
    763  1.32      fvdl 				    "setsockopt SO_KEEPALIVE: %m");
    764  1.32      fvdl 			nfsdargs.sock = msgsock;
    765  1.32      fvdl 			nfsdargs.name = (caddr_t)&inet6peer;
    766  1.32      fvdl 			nfsdargs.namelen = sizeof(inet6peer);
    767  1.32      fvdl 			nfssvc(NFSSVC_ADDSOCK, &nfsdargs);
    768  1.32      fvdl 			(void)close(msgsock);
    769  1.32      fvdl 		}
    770  1.32      fvdl 
    771  1.11   mycroft #ifdef notyet
    772  1.37   mycroft 		if (set[2].revents & POLLIN) {
    773  1.11   mycroft 			len = sizeof(isopeer);
    774  1.11   mycroft 			if ((msgsock = accept(tp4sock,
    775  1.11   mycroft 			    (struct sockaddr *)&isopeer, &len)) < 0) {
    776  1.11   mycroft 				syslog(LOG_ERR, "accept failed: %m");
    777  1.11   mycroft 				exit(1);
    778   1.1       cgd 			}
    779  1.11   mycroft 			if (setsockopt(msgsock, SOL_SOCKET,
    780  1.11   mycroft 			    SO_KEEPALIVE, (char *)&on, sizeof(on)) < 0)
    781  1.11   mycroft 				syslog(LOG_ERR,
    782  1.11   mycroft 				    "setsockopt SO_KEEPALIVE: %m");
    783  1.11   mycroft 			nfsdargs.sock = msgsock;
    784  1.11   mycroft 			nfsdargs.name = (caddr_t)&isopeer;
    785  1.11   mycroft 			nfsdargs.namelen = len;
    786  1.11   mycroft 			nfssvc(NFSSVC_ADDSOCK, &nfsdargs);
    787  1.11   mycroft 			(void)close(msgsock);
    788  1.11   mycroft 		}
    789  1.38   mycroft 
    790  1.37   mycroft 		if (set[3].revents & POLLIN) {
    791  1.11   mycroft 			len = sizeof(inetpeer);
    792  1.11   mycroft 			if ((msgsock = accept(tpipsock,
    793  1.11   mycroft 			    (struct sockaddr *)&inetpeer, &len)) < 0) {
    794  1.41   mycroft 				syslog(LOG_ERR, "accept failed: %m");
    795   1.1       cgd 				exit(1);
    796   1.1       cgd 			}
    797  1.11   mycroft 			if (setsockopt(msgsock, SOL_SOCKET,
    798  1.11   mycroft 			    SO_KEEPALIVE, (char *)&on, sizeof(on)) < 0)
    799  1.11   mycroft 				syslog(LOG_ERR, "setsockopt SO_KEEPALIVE: %m");
    800  1.11   mycroft 			nfsdargs.sock = msgsock;
    801  1.11   mycroft 			nfsdargs.name = (caddr_t)&inetpeer;
    802  1.11   mycroft 			nfsdargs.namelen = len;
    803  1.11   mycroft 			nfssvc(NFSSVC_ADDSOCK, &nfsdargs);
    804  1.11   mycroft 			(void)close(msgsock);
    805   1.1       cgd 		}
    806  1.11   mycroft #endif /* notyet */
    807   1.1       cgd 	}
    808   1.1       cgd }
    809   1.1       cgd 
    810  1.11   mycroft void
    811   1.1       cgd usage()
    812   1.1       cgd {
    813  1.26       mrg 
    814  1.15   mycroft 	(void)fprintf(stderr, "usage: nfsd %s\n", USAGE);
    815   1.1       cgd 	exit(1);
    816   1.1       cgd }
    817   1.1       cgd 
    818   1.1       cgd void
    819  1.11   mycroft nonfs(signo)
    820  1.11   mycroft 	int signo;
    821   1.1       cgd {
    822  1.15   mycroft 
    823  1.11   mycroft 	syslog(LOG_ERR, "missing system call: NFS not available.");
    824   1.1       cgd }
    825   1.4     glass 
    826  1.11   mycroft void
    827  1.11   mycroft reapchild(signo)
    828  1.11   mycroft 	int signo;
    829   1.4     glass {
    830  1.11   mycroft 
    831  1.18      fvdl 	while (wait3(NULL, WNOHANG, NULL) > 0);
    832   1.4     glass }
    833