Home | History | Annotate | Line # | Download | only in nfsd
nfsd.c revision 1.30
      1 /*	$NetBSD: nfsd.c,v 1.30 1999/06/07 06:13:41 thorpej 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.30 1999/06/07 06:13:41 thorpej 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 <string.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 	}
    209 	argv += optind;
    210 	argc -= optind;
    211 
    212 	/*
    213 	 * XXX
    214 	 * Backward compatibility, trailing number is the count of daemons.
    215 	 */
    216 	if (argc > 1)
    217 		usage();
    218 	if (argc == 1) {
    219 		nfsdcnt = atoi(argv[0]);
    220 		if (nfsdcnt < 1 || nfsdcnt > MAXNFSDCNT) {
    221 			warnx("nfsd count %d; reset to %d", nfsdcnt, DEFNFSDCNT);
    222 			nfsdcnt = DEFNFSDCNT;
    223 		}
    224 	}
    225 
    226 	if (debug == 0) {
    227 		daemon(0, 0);
    228 		(void)signal(SIGHUP, SIG_IGN);
    229 		(void)signal(SIGINT, SIG_IGN);
    230 		(void)signal(SIGQUIT, SIG_IGN);
    231 		(void)signal(SIGSYS, nonfs);
    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, "") ==
    296 				     RD_AP_OK &&
    297 				    krb_kntoln(&kauth, lnam) == KSUCCESS &&
    298 				    (pwd = getpwnam(lnam)) != NULL) {
    299 					cr = &nsd.nsd_cr;
    300 					cr->cr_uid = pwd->pw_uid;
    301 					cr->cr_groups[0] = pwd->pw_gid;
    302 					cr->cr_ngroups = 1;
    303 					setgrent();
    304 					while ((grp = getgrent()) != NULL) {
    305 						if (grp->gr_gid ==
    306 						    cr->cr_groups[0])
    307 							continue;
    308 						for (cpp = grp->gr_mem;
    309 						    *cpp != NULL; ++cpp)
    310 							if (!strcmp(*cpp, lnam))
    311 								break;
    312 						if (*cpp == NULL)
    313 							continue;
    314 						cr->cr_groups[cr->cr_ngroups++]
    315 						    = grp->gr_gid;
    316 						if (cr->cr_ngroups == NGROUPS)
    317 							break;
    318 					}
    319 					endgrent();
    320 
    321 					/*
    322 					 * Get the timestamp verifier out of
    323 					 * the authenticator and verifier
    324 					 * strings.
    325 					 */
    326 					kin.t1 = kverf.t1;
    327 					kin.t2 = kverf.t2;
    328 					kin.w2 = kverf.w2;
    329 					memset((caddr_t)kivec, 0,
    330 					    sizeof(kivec));
    331 					memmove((caddr_t)nsd.nsd_key,
    332 					    (caddr_t)kauth.session,
    333 					    sizeof(kauth.session));
    334 
    335 					/*
    336 					 * Decrypt the timestamp verifier
    337 					 * in CBC mode.
    338 					 */
    339 					XXX
    340 
    341 					/*
    342 					 * Validate the timestamp verifier, to
    343 					 * check that the session key is ok.
    344 					 */
    345 					nsd.nsd_timestamp.tv_sec =
    346 					    ntohl(kout.t1);
    347 					nsd.nsd_timestamp.tv_usec =
    348 					    ntohl(kout.t2);
    349 					nsd.nsd_ttl = ntohl(kout.w1);
    350 					if ((nsd.nsd_ttl - 1) == ntohl(kout.w2))
    351 					    nfssvc_flag =
    352 					        NFSSVC_NFSD | NFSSVC_AUTHIN;
    353 				}
    354 			}
    355 #endif /* NFSKERB */
    356 		}
    357 		exit(0);
    358 	}
    359 
    360 	/* If we are serving udp, set up the socket. */
    361 	if (udpflag) {
    362 		if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
    363 			syslog(LOG_ERR, "can't create udp socket");
    364 			exit(1);
    365 		}
    366 		inetaddr.sin_family = AF_INET;
    367 		inetaddr.sin_addr.s_addr = INADDR_ANY;
    368 		inetaddr.sin_port = htons(NFS_PORT);
    369 		inetaddr.sin_len = sizeof(inetaddr);
    370 		memset(inetaddr.sin_zero, 0, sizeof(inetaddr.sin_zero));
    371 		if (bind(sock,
    372 		    (struct sockaddr *)&inetaddr, sizeof(inetaddr)) < 0) {
    373 			syslog(LOG_ERR, "can't bind udp addr");
    374 			exit(1);
    375 		}
    376 		if (!pmap_set(RPCPROG_NFS, 2, IPPROTO_UDP, NFS_PORT) ||
    377 		    !pmap_set(RPCPROG_NFS, 3, IPPROTO_UDP, NFS_PORT)) {
    378 			syslog(LOG_ERR, "can't register with udp portmap");
    379 			exit(1);
    380 		}
    381 		nfsdargs.sock = sock;
    382 		nfsdargs.name = NULL;
    383 		nfsdargs.namelen = 0;
    384 		if (nfssvc(NFSSVC_ADDSOCK, &nfsdargs) < 0) {
    385 			syslog(LOG_ERR, "can't Add UDP socket");
    386 			exit(1);
    387 		}
    388 		(void)close(sock);
    389 	}
    390 
    391 #ifdef ISO
    392 	/* If we are serving cltp, set up the socket. */
    393 	if (cltpflag) {
    394 		if ((sock = socket(AF_ISO, SOCK_DGRAM, 0)) < 0) {
    395 			syslog(LOG_ERR, "can't create cltp socket");
    396 			exit(1);
    397 		}
    398 		memset(&isoaddr, 0, sizeof(isoaddr));
    399 		isoaddr.siso_family = AF_ISO;
    400 		isoaddr.siso_tlen = 2;
    401 		cp = TSEL(&isoaddr);
    402 		*cp++ = (NFS_PORT >> 8);
    403 		*cp = (NFS_PORT & 0xff);
    404 		isoaddr.siso_len = sizeof(isoaddr);
    405 		if (bind(sock,
    406 		    (struct sockaddr *)&isoaddr, sizeof(isoaddr)) < 0) {
    407 			syslog(LOG_ERR, "can't bind cltp addr");
    408 			exit(1);
    409 		}
    410 #ifdef notyet
    411 		/*
    412 		 * XXX
    413 		 * Someday this should probably use "rpcbind", the son of
    414 		 * portmap.
    415 		 */
    416 		if (!pmap_set(RPCPROG_NFS, NFS_VER2, IPPROTO_UDP, NFS_PORT)) {
    417 			syslog(LOG_ERR, "can't register with udp portmap");
    418 			exit(1);
    419 		}
    420 #endif /* notyet */
    421 		nfsdargs.sock = sock;
    422 		nfsdargs.name = NULL;
    423 		nfsdargs.namelen = 0;
    424 		if (nfssvc(NFSSVC_ADDSOCK, &nfsdargs) < 0) {
    425 			syslog(LOG_ERR, "can't add UDP socket");
    426 			exit(1);
    427 		}
    428 		close(sock);
    429 	}
    430 #endif /* ISO */
    431 
    432 	/* Now set up the master server socket waiting for tcp connections. */
    433 	on = 1;
    434 	FD_ZERO(&sockbits);
    435 	connect_type_cnt = 0;
    436 	if (tcpflag) {
    437 		if ((tcpsock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    438 			syslog(LOG_ERR, "can't create tcp socket");
    439 			exit(1);
    440 		}
    441 		if (setsockopt(tcpsock,
    442 		    SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0)
    443 			syslog(LOG_ERR, "setsockopt SO_REUSEADDR: %m");
    444 		inetaddr.sin_family = AF_INET;
    445 		inetaddr.sin_addr.s_addr = INADDR_ANY;
    446 		inetaddr.sin_port = htons(NFS_PORT);
    447 		inetaddr.sin_len = sizeof(inetaddr);
    448 		memset(inetaddr.sin_zero, 0, sizeof(inetaddr.sin_zero));
    449 		if (bind(tcpsock,
    450 		    (struct sockaddr *)&inetaddr, sizeof (inetaddr)) < 0) {
    451 			syslog(LOG_ERR, "can't bind tcp addr");
    452 			exit(1);
    453 		}
    454 		if (listen(tcpsock, 5) < 0) {
    455 			syslog(LOG_ERR, "listen failed");
    456 			exit(1);
    457 		}
    458 		if (!pmap_set(RPCPROG_NFS, 2, IPPROTO_TCP, NFS_PORT) ||
    459 		    !pmap_set(RPCPROG_NFS, 3, IPPROTO_TCP, NFS_PORT)) {
    460 			syslog(LOG_ERR, "can't register tcp with portmap");
    461 			exit(1);
    462 		}
    463 		FD_SET(tcpsock, &sockbits);
    464 		maxsock = tcpsock;
    465 		connect_type_cnt++;
    466 	}
    467 
    468 #ifdef notyet
    469 	/* Now set up the master server socket waiting for tp4 connections. */
    470 	if (tp4flag) {
    471 		if ((tp4sock = socket(AF_ISO, SOCK_SEQPACKET, 0)) < 0) {
    472 			syslog(LOG_ERR, "can't create tp4 socket");
    473 			exit(1);
    474 		}
    475 		if (setsockopt(tp4sock,
    476 		    SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0)
    477 			syslog(LOG_ERR, "setsockopt SO_REUSEADDR: %m");
    478 		memset(&isoaddr, 0, sizeof(isoaddr));
    479 		isoaddr.siso_family = AF_ISO;
    480 		isoaddr.siso_tlen = 2;
    481 		cp = TSEL(&isoaddr);
    482 		*cp++ = (NFS_PORT >> 8);
    483 		*cp = (NFS_PORT & 0xff);
    484 		isoaddr.siso_len = sizeof(isoaddr);
    485 		if (bind(tp4sock,
    486 		    (struct sockaddr *)&isoaddr, sizeof(isoaddr)) < 0) {
    487 			syslog(LOG_ERR, "can't bind tp4 addr");
    488 			exit(1);
    489 		}
    490 		if (listen(tp4sock, 5) < 0) {
    491 			syslog(LOG_ERR, "listen failed");
    492 			exit(1);
    493 		}
    494 		/*
    495 		 * XXX
    496 		 * Someday this should probably use "rpcbind", the son of
    497 		 * portmap.
    498 		 */
    499 		if (!pmap_set(RPCPROG_NFS, NFS_VER2, IPPROTO_TCP, NFS_PORT)) {
    500 			syslog(LOG_ERR, "can't register tcp with portmap");
    501 			exit(1);
    502 		}
    503 		FD_SET(tp4sock, &sockbits);
    504 		maxsock = tp4sock;
    505 		connect_type_cnt++;
    506 	}
    507 
    508 	/* Now set up the master server socket waiting for tpip connections. */
    509 	if (tpipflag) {
    510 		if ((tpipsock = socket(AF_INET, SOCK_SEQPACKET, 0)) < 0) {
    511 			syslog(LOG_ERR, "can't create tpip socket");
    512 			exit(1);
    513 		}
    514 		if (setsockopt(tpipsock,
    515 		    SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0)
    516 			syslog(LOG_ERR, "setsockopt SO_REUSEADDR: %m");
    517 		inetaddr.sin_family = AF_INET;
    518 		inetaddr.sin_addr.s_addr = INADDR_ANY;
    519 		inetaddr.sin_port = htons(NFS_PORT);
    520 		inetaddr.sin_len = sizeof(inetaddr);
    521 		memset(inetaddr.sin_zero, 0, sizeof(inetaddr.sin_zero));
    522 		if (bind(tpipsock,
    523 		    (struct sockaddr *)&inetaddr, sizeof (inetaddr)) < 0) {
    524 			syslog(LOG_ERR, "can't bind tcp addr");
    525 			exit(1);
    526 		}
    527 		if (listen(tpipsock, 5) < 0) {
    528 			syslog(LOG_ERR, "listen failed");
    529 			exit(1);
    530 		}
    531 		/*
    532 		 * XXX
    533 		 * Someday this should probably use "rpcbind", the son of
    534 		 * portmap.
    535 		 */
    536 		if (!pmap_set(RPCPROG_NFS, NFS_VER2, IPPROTO_TCP, NFS_PORT)) {
    537 			syslog(LOG_ERR, "can't register tcp with portmap");
    538 			exit(1);
    539 		}
    540 		FD_SET(tpipsock, &sockbits);
    541 		maxsock = tpipsock;
    542 		connect_type_cnt++;
    543 	}
    544 #endif /* notyet */
    545 
    546 	if (connect_type_cnt == 0)
    547 		exit(0);
    548 
    549 	setproctitle("master");
    550 
    551 	/*
    552 	 * Loop forever accepting connections and passing the sockets
    553 	 * into the kernel for the mounts.
    554 	 */
    555 	for (;;) {
    556 		ready = sockbits;
    557 		if (connect_type_cnt > 1) {
    558 			if (select(maxsock + 1,
    559 			    &ready, NULL, NULL, NULL) < 1) {
    560 				syslog(LOG_ERR, "select failed: %m");
    561 				exit(1);
    562 			}
    563 		}
    564 		if (tcpflag && FD_ISSET(tcpsock, &ready)) {
    565 			len = sizeof(inetpeer);
    566 			if ((msgsock = accept(tcpsock,
    567 			    (struct sockaddr *)&inetpeer, &len)) < 0) {
    568 				syslog(LOG_ERR, "accept failed: %m");
    569 				exit(1);
    570 			}
    571 			memset(inetpeer.sin_zero, 0, sizeof(inetpeer.sin_zero));
    572 			if (setsockopt(msgsock, SOL_SOCKET,
    573 			    SO_KEEPALIVE, (char *)&on, sizeof(on)) < 0)
    574 				syslog(LOG_ERR,
    575 				    "setsockopt SO_KEEPALIVE: %m");
    576 			nfsdargs.sock = msgsock;
    577 			nfsdargs.name = (caddr_t)&inetpeer;
    578 			nfsdargs.namelen = sizeof(inetpeer);
    579 			nfssvc(NFSSVC_ADDSOCK, &nfsdargs);
    580 			(void)close(msgsock);
    581 		}
    582 #ifdef notyet
    583 		if (tp4flag && FD_ISSET(tp4sock, &ready)) {
    584 			len = sizeof(isopeer);
    585 			if ((msgsock = accept(tp4sock,
    586 			    (struct sockaddr *)&isopeer, &len)) < 0) {
    587 				syslog(LOG_ERR, "accept failed: %m");
    588 				exit(1);
    589 			}
    590 			if (setsockopt(msgsock, SOL_SOCKET,
    591 			    SO_KEEPALIVE, (char *)&on, sizeof(on)) < 0)
    592 				syslog(LOG_ERR,
    593 				    "setsockopt SO_KEEPALIVE: %m");
    594 			nfsdargs.sock = msgsock;
    595 			nfsdargs.name = (caddr_t)&isopeer;
    596 			nfsdargs.namelen = len;
    597 			nfssvc(NFSSVC_ADDSOCK, &nfsdargs);
    598 			(void)close(msgsock);
    599 		}
    600 		if (tpipflag && FD_ISSET(tpipsock, &ready)) {
    601 			len = sizeof(inetpeer);
    602 			if ((msgsock = accept(tpipsock,
    603 			    (struct sockaddr *)&inetpeer, &len)) < 0) {
    604 				syslog(LOG_ERR, "Accept failed: %m");
    605 				exit(1);
    606 			}
    607 			if (setsockopt(msgsock, SOL_SOCKET,
    608 			    SO_KEEPALIVE, (char *)&on, sizeof(on)) < 0)
    609 				syslog(LOG_ERR, "setsockopt SO_KEEPALIVE: %m");
    610 			nfsdargs.sock = msgsock;
    611 			nfsdargs.name = (caddr_t)&inetpeer;
    612 			nfsdargs.namelen = len;
    613 			nfssvc(NFSSVC_ADDSOCK, &nfsdargs);
    614 			(void)close(msgsock);
    615 		}
    616 #endif /* notyet */
    617 	}
    618 }
    619 
    620 void
    621 usage()
    622 {
    623 
    624 	(void)fprintf(stderr, "usage: nfsd %s\n", USAGE);
    625 	exit(1);
    626 }
    627 
    628 void
    629 nonfs(signo)
    630 	int signo;
    631 {
    632 
    633 	syslog(LOG_ERR, "missing system call: NFS not available.");
    634 }
    635 
    636 void
    637 reapchild(signo)
    638 	int signo;
    639 {
    640 
    641 	while (wait3(NULL, WNOHANG, NULL) > 0);
    642 }
    643