Home | History | Annotate | Line # | Download | only in nfsd
nfsd.c revision 1.23
      1 /*	$NetBSD: nfsd.c,v 1.23 1997/10/17 11:53:30 lukem Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1989, 1993, 1994
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * This code is derived from software contributed to Berkeley by
      8  * Rick Macklem at The University of Guelph.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *	This product includes software developed by the University of
     21  *	California, Berkeley and its contributors.
     22  * 4. Neither the name of the University nor the names of its contributors
     23  *    may be used to endorse or promote products derived from this software
     24  *    without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     36  * SUCH DAMAGE.
     37  */
     38 
     39 #include <sys/cdefs.h>
     40 #ifndef lint
     41 __COPYRIGHT("@(#) Copyright (c) 1989, 1993, 1994\n\
     42 	The Regents of the University of California.  All rights reserved.\n");
     43 #endif not lint
     44 
     45 #ifndef lint
     46 #if 0
     47 static char sccsid[] = "@(#)nfsd.c	8.9 (Berkeley) 3/29/95";
     48 #else
     49 __RCSID("$NetBSD: nfsd.c,v 1.23 1997/10/17 11:53:30 lukem Exp $");
     50 #endif
     51 #endif /* not lint */
     52 
     53 #include <sys/param.h>
     54 #include <sys/ioctl.h>
     55 #include <sys/stat.h>
     56 #include <sys/wait.h>
     57 #include <sys/uio.h>
     58 #include <sys/ucred.h>
     59 #include <sys/mount.h>
     60 #include <sys/socket.h>
     61 #include <sys/socketvar.h>
     62 
     63 #include <rpc/rpc.h>
     64 #include <rpc/pmap_clnt.h>
     65 #include <rpc/pmap_prot.h>
     66 
     67 #ifdef ISO
     68 #include <netiso/iso.h>
     69 #endif
     70 #include <nfs/rpcv2.h>
     71 #include <nfs/nfsproto.h>
     72 #include <nfs/nfs.h>
     73 
     74 #ifdef NFSKERB
     75 #include <kerberosIV/des.h>
     76 #include <kerberosIV/krb.h>
     77 #endif
     78 
     79 #include <err.h>
     80 #include <errno.h>
     81 #include <fcntl.h>
     82 #include <grp.h>
     83 #include <pwd.h>
     84 #include <signal.h>
     85 #include <stdio.h>
     86 #include <stdlib.h>
     87 #include <strings.h>
     88 #include <syslog.h>
     89 #include <unistd.h>
     90 
     91 /* Global defs */
     92 #ifdef DEBUG
     93 #define	syslog(e, s)	fprintf(stderr,(s))
     94 int	debug = 1;
     95 #else
     96 int	debug = 0;
     97 #endif
     98 
     99 struct	nfsd_srvargs nsd;
    100 
    101 #ifdef NFSKERB
    102 char		lnam[ANAME_SZ];
    103 KTEXT_ST	kt;
    104 AUTH_DAT	kauth;
    105 char		inst[INST_SZ];
    106 struct nfsrpc_fullblock kin, kout;
    107 struct nfsrpc_fullverf kverf;
    108 NFSKERBKEY_T	kivec;
    109 struct timeval	ktv;
    110 NFSKERBKEYSCHED_T kerb_keysched;
    111 #endif
    112 
    113 int	main __P((int, char **));
    114 void	nonfs __P((int));
    115 void	reapchild __P((int));
    116 void	usage __P((void));
    117 
    118 /*
    119  * Nfs server daemon mostly just a user context for nfssvc()
    120  *
    121  * 1 - do file descriptor and signal cleanup
    122  * 2 - fork the nfsd(s)
    123  * 3 - create server socket(s)
    124  * 4 - register socket with portmap
    125  *
    126  * For connectionless protocols, just pass the socket into the kernel via.
    127  * nfssvc().
    128  * For connection based sockets, loop doing accepts. When you get a new
    129  * socket from accept, pass the msgsock into the kernel via. nfssvc().
    130  * The arguments are:
    131  *	-c - support iso cltp clients
    132  *	-r - reregister with portmapper
    133  *	-t - support tcp nfs clients
    134  *	-u - support udp nfs clients
    135  * followed by "n" which is the number of nfsds' to fork off
    136  */
    137 int
    138 main(argc, argv)
    139 	int argc;
    140 	char *argv[];
    141 {
    142 	struct nfsd_args nfsdargs;
    143 	struct sockaddr_in inetaddr, inetpeer;
    144 #ifdef ISO
    145 	struct sockaddr_iso isoaddr, isopeer;
    146 #endif
    147 	fd_set ready, sockbits;
    148 	int ch, cltpflag, connect_type_cnt, i, len, maxsock, msgsock;
    149 	int nfsdcnt, nfssvc_flag, on, reregister, sock, tcpflag, tcpsock;
    150 	int tp4cnt, tp4flag, tpipcnt, tpipflag, udpflag;
    151 #ifdef NFSKERB
    152 	struct group *grp;
    153 	struct passwd *pwd;
    154 	struct ucred *cr;
    155 	struct timeval ktv;
    156 	int tp4sock, tpipsock;
    157 	char *cp, **cpp;
    158 #endif
    159 
    160 #define	MAXNFSDCNT	20
    161 #define	DEFNFSDCNT	 4
    162 	nfsdcnt = DEFNFSDCNT;
    163 	cltpflag = reregister = tcpflag = tp4cnt = tp4flag = tpipcnt = 0;
    164 	tpipflag = udpflag = 0;
    165 	maxsock = tcpsock = 0;
    166 #ifdef ISO
    167 #define	GETOPT	"cn:rtu"
    168 #define	USAGE	"[-crtu] [-n num_servers]"
    169 #else
    170 #define	GETOPT	"n:rtu"
    171 #define	USAGE	"[-rtu] [-n num_servers]"
    172 #endif
    173 	while ((ch = getopt(argc, argv, GETOPT)) != -1)
    174 		switch (ch) {
    175 		case 'n':
    176 			nfsdcnt = atoi(optarg);
    177 			if (nfsdcnt < 1 || nfsdcnt > MAXNFSDCNT) {
    178 				warnx("nfsd count %d; reset to %d", nfsdcnt, DEFNFSDCNT);
    179 				nfsdcnt = DEFNFSDCNT;
    180 			}
    181 			break;
    182 		case 'r':
    183 			reregister = 1;
    184 			break;
    185 		case 't':
    186 			tcpflag = 1;
    187 			break;
    188 		case 'u':
    189 			udpflag = 1;
    190 			break;
    191 #ifdef ISO
    192 		case 'c':
    193 			cltpflag = 1;
    194 			break;
    195 #ifdef notyet
    196 		case 'i':
    197 			tp4cnt = 1;
    198 			break;
    199 		case 'p':
    200 			tpipcnt = 1;
    201 			break;
    202 #endif /* notyet */
    203 #endif /* ISO */
    204 		default:
    205 		case '?':
    206 			usage();
    207 		};
    208 	argv += optind;
    209 	argc -= optind;
    210 
    211 	/*
    212 	 * XXX
    213 	 * Backward compatibility, trailing number is the count of daemons.
    214 	 */
    215 	if (argc > 1)
    216 		usage();
    217 	if (argc == 1) {
    218 		nfsdcnt = atoi(argv[0]);
    219 		if (nfsdcnt < 1 || nfsdcnt > MAXNFSDCNT) {
    220 			warnx("nfsd count %d; reset to %d", nfsdcnt, DEFNFSDCNT);
    221 			nfsdcnt = DEFNFSDCNT;
    222 		}
    223 	}
    224 
    225 	if (debug == 0) {
    226 		daemon(0, 0);
    227 		(void)signal(SIGHUP, SIG_IGN);
    228 		(void)signal(SIGINT, SIG_IGN);
    229 		(void)signal(SIGQUIT, SIG_IGN);
    230 		(void)signal(SIGSYS, nonfs);
    231 		(void)signal(SIGTERM, SIG_IGN);
    232 	}
    233 	(void)signal(SIGCHLD, reapchild);
    234 
    235 	if (reregister) {
    236 		if (udpflag &&
    237 		    (!pmap_set(RPCPROG_NFS, 2, IPPROTO_UDP, NFS_PORT) ||
    238 		     !pmap_set(RPCPROG_NFS, 3, IPPROTO_UDP, NFS_PORT)))
    239 			err(1, "can't register with portmap for UDP.");
    240 		if (tcpflag &&
    241 		    (!pmap_set(RPCPROG_NFS, 2, IPPROTO_TCP, NFS_PORT) ||
    242 		     !pmap_set(RPCPROG_NFS, 3, IPPROTO_TCP, NFS_PORT)))
    243 			err(1, "can't register with portmap for TCP.");
    244 		exit(0);
    245 	}
    246 	openlog("nfsd:", LOG_PID, LOG_DAEMON);
    247 
    248 	for (i = 0; i < nfsdcnt; i++) {
    249 		switch (fork()) {
    250 		case -1:
    251 			syslog(LOG_ERR, "fork: %m");
    252 			exit (1);
    253 		case 0:
    254 			break;
    255 		default:
    256 			continue;
    257 		}
    258 
    259 		setproctitle("server");
    260 		nfssvc_flag = NFSSVC_NFSD;
    261 		nsd.nsd_nfsd = NULL;
    262 #ifdef NFSKERB
    263 		if (sizeof (struct nfsrpc_fullverf) != RPCX_FULLVERF ||
    264 		    sizeof (struct nfsrpc_fullblock) != RPCX_FULLBLOCK)
    265 		    syslog(LOG_ERR, "Yikes NFSKERB structs not packed!");
    266 		nsd.nsd_authstr = (u_char *)&kt;
    267 		nsd.nsd_authlen = sizeof (kt);
    268 		nsd.nsd_verfstr = (u_char *)&kverf;
    269 		nsd.nsd_verflen = sizeof (kverf);
    270 #endif
    271 		while (nfssvc(nfssvc_flag, &nsd) < 0) {
    272 			if (errno != ENEEDAUTH) {
    273 				syslog(LOG_ERR, "nfssvc: %m");
    274 				exit(1);
    275 			}
    276 			nfssvc_flag = NFSSVC_NFSD | NFSSVC_AUTHINFAIL;
    277 #ifdef NFSKERB
    278 			/*
    279 			 * Get the Kerberos ticket out of the authenticator
    280 			 * verify it and convert the principal name to a user
    281 			 * name. The user name is then converted to a set of
    282 			 * user credentials via the password and group file.
    283 			 * Finally, decrypt the timestamp and validate it.
    284 			 * For more info see the IETF Draft "Authentication
    285 			 * in ONC RPC".
    286 			 */
    287 			kt.length = ntohl(kt.length);
    288 			if (gettimeofday(&ktv, (struct timezone *)0) == 0 &&
    289 			    kt.length > 0 && kt.length <=
    290 			    (RPCAUTH_MAXSIZ - 3 * NFSX_UNSIGNED)) {
    291 			    kin.w1 = NFS_KERBW1(kt);
    292 			    kt.mbz = 0;
    293 			    (void)strcpy(inst, "*");
    294 			    if (krb_rd_req(&kt, NFS_KERBSRV,
    295 				inst, nsd.nsd_haddr, &kauth, "") == RD_AP_OK &&
    296 				krb_kntoln(&kauth, lnam) == KSUCCESS &&
    297 				(pwd = getpwnam(lnam)) != NULL) {
    298 				cr = &nsd.nsd_cr;
    299 				cr->cr_uid = pwd->pw_uid;
    300 				cr->cr_groups[0] = pwd->pw_gid;
    301 				cr->cr_ngroups = 1;
    302 				setgrent();
    303 				while ((grp = getgrent()) != NULL) {
    304 					if (grp->gr_gid == cr->cr_groups[0])
    305 						continue;
    306 					for (cpp = grp->gr_mem;
    307 					    *cpp != NULL; ++cpp)
    308 						if (!strcmp(*cpp, lnam))
    309 							break;
    310 					if (*cpp == NULL)
    311 						continue;
    312 					cr->cr_groups[cr->cr_ngroups++]
    313 					    = grp->gr_gid;
    314 					if (cr->cr_ngroups == NGROUPS)
    315 						break;
    316 				}
    317 				endgrent();
    318 
    319 				/*
    320 				 * Get the timestamp verifier out of the
    321 				 * authenticator and verifier strings.
    322 				 */
    323 				kin.t1 = kverf.t1;
    324 				kin.t2 = kverf.t2;
    325 				kin.w2 = kverf.w2;
    326 				bzero((caddr_t)kivec, sizeof (kivec));
    327 				bcopy((caddr_t)kauth.session,
    328 				    (caddr_t)nsd.nsd_key,sizeof(kauth.session));
    329 
    330 				/*
    331 				 * Decrypt the timestamp verifier in CBC mode.
    332 				 */
    333 				XXX
    334 
    335 				/*
    336 				 * Validate the timestamp verifier, to
    337 				 * check that the session key is ok.
    338 				 */
    339 				nsd.nsd_timestamp.tv_sec = ntohl(kout.t1);
    340 				nsd.nsd_timestamp.tv_usec = ntohl(kout.t2);
    341 				nsd.nsd_ttl = ntohl(kout.w1);
    342 				if ((nsd.nsd_ttl - 1) == ntohl(kout.w2))
    343 				    nfssvc_flag = NFSSVC_NFSD | NFSSVC_AUTHIN;
    344 			}
    345 #endif /* NFSKERB */
    346 		}
    347 		exit(0);
    348 	}
    349 
    350 	/* If we are serving udp, set up the socket. */
    351 	if (udpflag) {
    352 		if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
    353 			syslog(LOG_ERR, "can't create udp socket");
    354 			exit(1);
    355 		}
    356 		inetaddr.sin_family = AF_INET;
    357 		inetaddr.sin_addr.s_addr = INADDR_ANY;
    358 		inetaddr.sin_port = htons(NFS_PORT);
    359 		inetaddr.sin_len = sizeof(inetaddr);
    360 		memset(inetaddr.sin_zero, 0, sizeof(inetaddr.sin_zero));
    361 		if (bind(sock,
    362 		    (struct sockaddr *)&inetaddr, sizeof(inetaddr)) < 0) {
    363 			syslog(LOG_ERR, "can't bind udp addr");
    364 			exit(1);
    365 		}
    366 		if (!pmap_set(RPCPROG_NFS, 2, IPPROTO_UDP, NFS_PORT) ||
    367 		    !pmap_set(RPCPROG_NFS, 3, IPPROTO_UDP, NFS_PORT)) {
    368 			syslog(LOG_ERR, "can't register with udp portmap");
    369 			exit(1);
    370 		}
    371 		nfsdargs.sock = sock;
    372 		nfsdargs.name = NULL;
    373 		nfsdargs.namelen = 0;
    374 		if (nfssvc(NFSSVC_ADDSOCK, &nfsdargs) < 0) {
    375 			syslog(LOG_ERR, "can't Add UDP socket");
    376 			exit(1);
    377 		}
    378 		(void)close(sock);
    379 	}
    380 
    381 #ifdef ISO
    382 	/* If we are serving cltp, set up the socket. */
    383 	if (cltpflag) {
    384 		if ((sock = socket(AF_ISO, SOCK_DGRAM, 0)) < 0) {
    385 			syslog(LOG_ERR, "can't create cltp socket");
    386 			exit(1);
    387 		}
    388 		memset(&isoaddr, 0, sizeof(isoaddr));
    389 		isoaddr.siso_family = AF_ISO;
    390 		isoaddr.siso_tlen = 2;
    391 		cp = TSEL(&isoaddr);
    392 		*cp++ = (NFS_PORT >> 8);
    393 		*cp = (NFS_PORT & 0xff);
    394 		isoaddr.siso_len = sizeof(isoaddr);
    395 		if (bind(sock,
    396 		    (struct sockaddr *)&isoaddr, sizeof(isoaddr)) < 0) {
    397 			syslog(LOG_ERR, "can't bind cltp addr");
    398 			exit(1);
    399 		}
    400 #ifdef notyet
    401 		/*
    402 		 * XXX
    403 		 * Someday this should probably use "rpcbind", the son of
    404 		 * portmap.
    405 		 */
    406 		if (!pmap_set(RPCPROG_NFS, NFS_VER2, IPPROTO_UDP, NFS_PORT)) {
    407 			syslog(LOG_ERR, "can't register with udp portmap");
    408 			exit(1);
    409 		}
    410 #endif /* notyet */
    411 		nfsdargs.sock = sock;
    412 		nfsdargs.name = NULL;
    413 		nfsdargs.namelen = 0;
    414 		if (nfssvc(NFSSVC_ADDSOCK, &nfsdargs) < 0) {
    415 			syslog(LOG_ERR, "can't add UDP socket");
    416 			exit(1);
    417 		}
    418 		close(sock);
    419 	}
    420 #endif /* ISO */
    421 
    422 	/* Now set up the master server socket waiting for tcp connections. */
    423 	on = 1;
    424 	FD_ZERO(&sockbits);
    425 	connect_type_cnt = 0;
    426 	if (tcpflag) {
    427 		if ((tcpsock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    428 			syslog(LOG_ERR, "can't create tcp socket");
    429 			exit(1);
    430 		}
    431 		if (setsockopt(tcpsock,
    432 		    SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0)
    433 			syslog(LOG_ERR, "setsockopt SO_REUSEADDR: %m");
    434 		inetaddr.sin_family = AF_INET;
    435 		inetaddr.sin_addr.s_addr = INADDR_ANY;
    436 		inetaddr.sin_port = htons(NFS_PORT);
    437 		inetaddr.sin_len = sizeof(inetaddr);
    438 		memset(inetaddr.sin_zero, 0, sizeof(inetaddr.sin_zero));
    439 		if (bind(tcpsock,
    440 		    (struct sockaddr *)&inetaddr, sizeof (inetaddr)) < 0) {
    441 			syslog(LOG_ERR, "can't bind tcp addr");
    442 			exit(1);
    443 		}
    444 		if (listen(tcpsock, 5) < 0) {
    445 			syslog(LOG_ERR, "listen failed");
    446 			exit(1);
    447 		}
    448 		if (!pmap_set(RPCPROG_NFS, 2, IPPROTO_TCP, NFS_PORT) ||
    449 		    !pmap_set(RPCPROG_NFS, 3, IPPROTO_TCP, NFS_PORT)) {
    450 			syslog(LOG_ERR, "can't register tcp with portmap");
    451 			exit(1);
    452 		}
    453 		FD_SET(tcpsock, &sockbits);
    454 		maxsock = tcpsock;
    455 		connect_type_cnt++;
    456 	}
    457 
    458 #ifdef notyet
    459 	/* Now set up the master server socket waiting for tp4 connections. */
    460 	if (tp4flag) {
    461 		if ((tp4sock = socket(AF_ISO, SOCK_SEQPACKET, 0)) < 0) {
    462 			syslog(LOG_ERR, "can't create tp4 socket");
    463 			exit(1);
    464 		}
    465 		if (setsockopt(tp4sock,
    466 		    SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0)
    467 			syslog(LOG_ERR, "setsockopt SO_REUSEADDR: %m");
    468 		memset(&isoaddr, 0, sizeof(isoaddr));
    469 		isoaddr.siso_family = AF_ISO;
    470 		isoaddr.siso_tlen = 2;
    471 		cp = TSEL(&isoaddr);
    472 		*cp++ = (NFS_PORT >> 8);
    473 		*cp = (NFS_PORT & 0xff);
    474 		isoaddr.siso_len = sizeof(isoaddr);
    475 		if (bind(tp4sock,
    476 		    (struct sockaddr *)&isoaddr, sizeof(isoaddr)) < 0) {
    477 			syslog(LOG_ERR, "can't bind tp4 addr");
    478 			exit(1);
    479 		}
    480 		if (listen(tp4sock, 5) < 0) {
    481 			syslog(LOG_ERR, "listen failed");
    482 			exit(1);
    483 		}
    484 		/*
    485 		 * XXX
    486 		 * Someday this should probably use "rpcbind", the son of
    487 		 * portmap.
    488 		 */
    489 		if (!pmap_set(RPCPROG_NFS, NFS_VER2, IPPROTO_TCP, NFS_PORT)) {
    490 			syslog(LOG_ERR, "can't register tcp with portmap");
    491 			exit(1);
    492 		}
    493 		FD_SET(tp4sock, &sockbits);
    494 		maxsock = tp4sock;
    495 		connect_type_cnt++;
    496 	}
    497 
    498 	/* Now set up the master server socket waiting for tpip connections. */
    499 	if (tpipflag) {
    500 		if ((tpipsock = socket(AF_INET, SOCK_SEQPACKET, 0)) < 0) {
    501 			syslog(LOG_ERR, "can't create tpip socket");
    502 			exit(1);
    503 		}
    504 		if (setsockopt(tpipsock,
    505 		    SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0)
    506 			syslog(LOG_ERR, "setsockopt SO_REUSEADDR: %m");
    507 		inetaddr.sin_family = AF_INET;
    508 		inetaddr.sin_addr.s_addr = INADDR_ANY;
    509 		inetaddr.sin_port = htons(NFS_PORT);
    510 		inetaddr.sin_len = sizeof(inetaddr);
    511 		memset(inetaddr.sin_zero, 0, sizeof(inetaddr.sin_zero));
    512 		if (bind(tpipsock,
    513 		    (struct sockaddr *)&inetaddr, sizeof (inetaddr)) < 0) {
    514 			syslog(LOG_ERR, "can't bind tcp addr");
    515 			exit(1);
    516 		}
    517 		if (listen(tpipsock, 5) < 0) {
    518 			syslog(LOG_ERR, "listen failed");
    519 			exit(1);
    520 		}
    521 		/*
    522 		 * XXX
    523 		 * Someday this should probably use "rpcbind", the son of
    524 		 * portmap.
    525 		 */
    526 		if (!pmap_set(RPCPROG_NFS, NFS_VER2, IPPROTO_TCP, NFS_PORT)) {
    527 			syslog(LOG_ERR, "can't register tcp with portmap");
    528 			exit(1);
    529 		}
    530 		FD_SET(tpipsock, &sockbits);
    531 		maxsock = tpipsock;
    532 		connect_type_cnt++;
    533 	}
    534 #endif /* notyet */
    535 
    536 	if (connect_type_cnt == 0)
    537 		exit(0);
    538 
    539 	setproctitle("master");
    540 
    541 	/*
    542 	 * Loop forever accepting connections and passing the sockets
    543 	 * into the kernel for the mounts.
    544 	 */
    545 	for (;;) {
    546 		ready = sockbits;
    547 		if (connect_type_cnt > 1) {
    548 			if (select(maxsock + 1,
    549 			    &ready, NULL, NULL, NULL) < 1) {
    550 				syslog(LOG_ERR, "select failed: %m");
    551 				exit(1);
    552 			}
    553 		}
    554 		if (tcpflag && FD_ISSET(tcpsock, &ready)) {
    555 			len = sizeof(inetpeer);
    556 			if ((msgsock = accept(tcpsock,
    557 			    (struct sockaddr *)&inetpeer, &len)) < 0) {
    558 				syslog(LOG_ERR, "accept failed: %m");
    559 				exit(1);
    560 			}
    561 			memset(inetpeer.sin_zero, 0, sizeof(inetpeer.sin_zero));
    562 			if (setsockopt(msgsock, SOL_SOCKET,
    563 			    SO_KEEPALIVE, (char *)&on, sizeof(on)) < 0)
    564 				syslog(LOG_ERR,
    565 				    "setsockopt SO_KEEPALIVE: %m");
    566 			nfsdargs.sock = msgsock;
    567 			nfsdargs.name = (caddr_t)&inetpeer;
    568 			nfsdargs.namelen = sizeof(inetpeer);
    569 			nfssvc(NFSSVC_ADDSOCK, &nfsdargs);
    570 			(void)close(msgsock);
    571 		}
    572 #ifdef notyet
    573 		if (tp4flag && FD_ISSET(tp4sock, &ready)) {
    574 			len = sizeof(isopeer);
    575 			if ((msgsock = accept(tp4sock,
    576 			    (struct sockaddr *)&isopeer, &len)) < 0) {
    577 				syslog(LOG_ERR, "accept failed: %m");
    578 				exit(1);
    579 			}
    580 			if (setsockopt(msgsock, SOL_SOCKET,
    581 			    SO_KEEPALIVE, (char *)&on, sizeof(on)) < 0)
    582 				syslog(LOG_ERR,
    583 				    "setsockopt SO_KEEPALIVE: %m");
    584 			nfsdargs.sock = msgsock;
    585 			nfsdargs.name = (caddr_t)&isopeer;
    586 			nfsdargs.namelen = len;
    587 			nfssvc(NFSSVC_ADDSOCK, &nfsdargs);
    588 			(void)close(msgsock);
    589 		}
    590 		if (tpipflag && FD_ISSET(tpipsock, &ready)) {
    591 			len = sizeof(inetpeer);
    592 			if ((msgsock = accept(tpipsock,
    593 			    (struct sockaddr *)&inetpeer, &len)) < 0) {
    594 				syslog(LOG_ERR, "Accept failed: %m");
    595 				exit(1);
    596 			}
    597 			if (setsockopt(msgsock, SOL_SOCKET,
    598 			    SO_KEEPALIVE, (char *)&on, sizeof(on)) < 0)
    599 				syslog(LOG_ERR, "setsockopt SO_KEEPALIVE: %m");
    600 			nfsdargs.sock = msgsock;
    601 			nfsdargs.name = (caddr_t)&inetpeer;
    602 			nfsdargs.namelen = len;
    603 			nfssvc(NFSSVC_ADDSOCK, &nfsdargs);
    604 			(void)close(msgsock);
    605 		}
    606 #endif /* notyet */
    607 	}
    608 }
    609 
    610 void
    611 usage()
    612 {
    613 	(void)fprintf(stderr, "usage: nfsd %s\n", USAGE);
    614 	exit(1);
    615 }
    616 
    617 void
    618 nonfs(signo)
    619 	int signo;
    620 {
    621 
    622 	syslog(LOG_ERR, "missing system call: NFS not available.");
    623 }
    624 
    625 void
    626 reapchild(signo)
    627 	int signo;
    628 {
    629 
    630 	while (wait3(NULL, WNOHANG, NULL) > 0);
    631 }
    632