Home | History | Annotate | Line # | Download | only in nfsd
nfsd.c revision 1.19
      1 /*	$NetBSD: nfsd.c,v 1.19 1996/02/18 23:18:56 mycroft 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 #ifndef lint
     40 static char copyright[] =
     41 "@(#) 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 static char rcsid[] = "$NetBSD: nfsd.c,v 1.19 1996/02/18 23:18:56 mycroft 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 void	nonfs __P((int));
    114 void	reapchild __P((int));
    115 void	usage __P((void));
    116 
    117 /*
    118  * Nfs server daemon mostly just a user context for nfssvc()
    119  *
    120  * 1 - do file descriptor and signal cleanup
    121  * 2 - fork the nfsd(s)
    122  * 3 - create server socket(s)
    123  * 4 - register socket with portmap
    124  *
    125  * For connectionless protocols, just pass the socket into the kernel via.
    126  * nfssvc().
    127  * For connection based sockets, loop doing accepts. When you get a new
    128  * socket from accept, pass the msgsock into the kernel via. nfssvc().
    129  * The arguments are:
    130  *	-c - support iso cltp clients
    131  *	-r - reregister with portmapper
    132  *	-t - support tcp nfs clients
    133  *	-u - support udp nfs clients
    134  * followed by "n" which is the number of nfsds' to fork off
    135  */
    136 int
    137 main(argc, argv, envp)
    138 	int argc;
    139 	char *argv[], *envp[];
    140 {
    141 	extern int optind;
    142 	struct group *grp;
    143 	struct nfsd_args nfsdargs;
    144 	struct passwd *pwd;
    145 	struct ucred *cr;
    146 	struct sockaddr_in inetaddr, inetpeer;
    147 #ifdef ISO
    148 	struct sockaddr_iso isoaddr, isopeer;
    149 #endif
    150 	struct timeval ktv;
    151 	fd_set ready, sockbits;
    152 	int ch, cltpflag, connect_type_cnt, i, len, maxsock, msgsock;
    153 	int nfsdcnt, nfssvc_flag, on, reregister, sock, tcpflag, tcpsock;
    154 	int tp4cnt, tp4flag, tp4sock, tpipcnt, tpipflag, tpipsock, udpflag;
    155 	char *cp, **cpp;
    156 
    157 #define	MAXNFSDCNT	20
    158 #define	DEFNFSDCNT	 4
    159 	nfsdcnt = DEFNFSDCNT;
    160 	cltpflag = reregister = tcpflag = tp4cnt = tp4flag = tpipcnt = 0;
    161 	tpipflag = udpflag = 0;
    162 #ifdef ISO
    163 #define	GETOPT	"cn:rtu"
    164 #define	USAGE	"[-crtu] [-n num_servers]"
    165 #else
    166 #define	GETOPT	"n:rtu"
    167 #define	USAGE	"[-rtu] [-n num_servers]"
    168 #endif
    169 	while ((ch = getopt(argc, argv, GETOPT)) != EOF)
    170 		switch (ch) {
    171 		case 'n':
    172 			nfsdcnt = atoi(optarg);
    173 			if (nfsdcnt < 1 || nfsdcnt > MAXNFSDCNT) {
    174 				warnx("nfsd count %d; reset to %d", DEFNFSDCNT);
    175 				nfsdcnt = DEFNFSDCNT;
    176 			}
    177 			break;
    178 		case 'r':
    179 			reregister = 1;
    180 			break;
    181 		case 't':
    182 			tcpflag = 1;
    183 			break;
    184 		case 'u':
    185 			udpflag = 1;
    186 			break;
    187 #ifdef ISO
    188 		case 'c':
    189 			cltpflag = 1;
    190 			break;
    191 #ifdef notyet
    192 		case 'i':
    193 			tp4cnt = 1;
    194 			break;
    195 		case 'p':
    196 			tpipcnt = 1;
    197 			break;
    198 #endif /* notyet */
    199 #endif /* ISO */
    200 		default:
    201 		case '?':
    202 			usage();
    203 		};
    204 	argv += optind;
    205 	argc -= optind;
    206 
    207 	/*
    208 	 * XXX
    209 	 * Backward compatibility, trailing number is the count of daemons.
    210 	 */
    211 	if (argc > 1)
    212 		usage();
    213 	if (argc == 1) {
    214 		nfsdcnt = atoi(argv[0]);
    215 		if (nfsdcnt < 1 || nfsdcnt > MAXNFSDCNT) {
    216 			warnx("nfsd count %d; reset to %d", DEFNFSDCNT);
    217 			nfsdcnt = DEFNFSDCNT;
    218 		}
    219 	}
    220 
    221 	if (debug == 0) {
    222 		daemon(0, 0);
    223 		(void)signal(SIGHUP, SIG_IGN);
    224 		(void)signal(SIGINT, SIG_IGN);
    225 		(void)signal(SIGQUIT, SIG_IGN);
    226 		(void)signal(SIGSYS, nonfs);
    227 		(void)signal(SIGTERM, SIG_IGN);
    228 	}
    229 	(void)signal(SIGCHLD, reapchild);
    230 
    231 	if (reregister) {
    232 		if (udpflag &&
    233 		    (!pmap_set(RPCPROG_NFS, 2, IPPROTO_UDP, NFS_PORT) ||
    234 		     !pmap_set(RPCPROG_NFS, 3, IPPROTO_UDP, NFS_PORT)))
    235 			err(1, "can't register with portmap for UDP.");
    236 		if (tcpflag &&
    237 		    (!pmap_set(RPCPROG_NFS, 2, IPPROTO_TCP, NFS_PORT) ||
    238 		     !pmap_set(RPCPROG_NFS, 3, IPPROTO_TCP, NFS_PORT)))
    239 			err(1, "can't register with portmap for TCP.");
    240 		exit(0);
    241 	}
    242 	openlog("nfsd:", LOG_PID, LOG_DAEMON);
    243 
    244 	for (i = 0; i < nfsdcnt; i++) {
    245 		switch (fork()) {
    246 		case -1:
    247 			syslog(LOG_ERR, "fork: %m");
    248 			exit (1);
    249 		case 0:
    250 			break;
    251 		default:
    252 			continue;
    253 		}
    254 
    255 		setproctitle("server");
    256 		nfssvc_flag = NFSSVC_NFSD;
    257 		nsd.nsd_nfsd = NULL;
    258 #ifdef NFSKERB
    259 		if (sizeof (struct nfsrpc_fullverf) != RPCX_FULLVERF ||
    260 		    sizeof (struct nfsrpc_fullblock) != RPCX_FULLBLOCK)
    261 		    syslog(LOG_ERR, "Yikes NFSKERB structs not packed!");
    262 		nsd.nsd_authstr = (u_char *)&kt;
    263 		nsd.nsd_authlen = sizeof (kt);
    264 		nsd.nsd_verfstr = (u_char *)&kverf;
    265 		nsd.nsd_verflen = sizeof (kverf);
    266 #endif
    267 		while (nfssvc(nfssvc_flag, &nsd) < 0) {
    268 			if (errno != ENEEDAUTH) {
    269 				syslog(LOG_ERR, "nfssvc: %m");
    270 				exit(1);
    271 			}
    272 			nfssvc_flag = NFSSVC_NFSD | NFSSVC_AUTHINFAIL;
    273 #ifdef NFSKERB
    274 			/*
    275 			 * Get the Kerberos ticket out of the authenticator
    276 			 * verify it and convert the principal name to a user
    277 			 * name. The user name is then converted to a set of
    278 			 * user credentials via the password and group file.
    279 			 * Finally, decrypt the timestamp and validate it.
    280 			 * For more info see the IETF Draft "Authentication
    281 			 * in ONC RPC".
    282 			 */
    283 			kt.length = ntohl(kt.length);
    284 			if (gettimeofday(&ktv, (struct timezone *)0) == 0 &&
    285 			    kt.length > 0 && kt.length <=
    286 			    (RPCAUTH_MAXSIZ - 3 * NFSX_UNSIGNED)) {
    287 			    kin.w1 = NFS_KERBW1(kt);
    288 			    kt.mbz = 0;
    289 			    (void)strcpy(inst, "*");
    290 			    if (krb_rd_req(&kt, NFS_KERBSRV,
    291 				inst, nsd.nsd_haddr, &kauth, "") == RD_AP_OK &&
    292 				krb_kntoln(&kauth, lnam) == KSUCCESS &&
    293 				(pwd = getpwnam(lnam)) != NULL) {
    294 				cr = &nsd.nsd_cr;
    295 				cr->cr_uid = pwd->pw_uid;
    296 				cr->cr_groups[0] = pwd->pw_gid;
    297 				cr->cr_ngroups = 1;
    298 				setgrent();
    299 				while ((grp = getgrent()) != NULL) {
    300 					if (grp->gr_gid == cr->cr_groups[0])
    301 						continue;
    302 					for (cpp = grp->gr_mem;
    303 					    *cpp != NULL; ++cpp)
    304 						if (!strcmp(*cpp, lnam))
    305 							break;
    306 					if (*cpp == NULL)
    307 						continue;
    308 					cr->cr_groups[cr->cr_ngroups++]
    309 					    = grp->gr_gid;
    310 					if (cr->cr_ngroups == NGROUPS)
    311 						break;
    312 				}
    313 				endgrent();
    314 
    315 				/*
    316 				 * Get the timestamp verifier out of the
    317 				 * authenticator and verifier strings.
    318 				 */
    319 				kin.t1 = kverf.t1;
    320 				kin.t2 = kverf.t2;
    321 				kin.w2 = kverf.w2;
    322 				bzero((caddr_t)kivec, sizeof (kivec));
    323 				bcopy((caddr_t)kauth.session,
    324 				    (caddr_t)nsd.nsd_key,sizeof(kauth.session));
    325 
    326 				/*
    327 				 * Decrypt the timestamp verifier in CBC mode.
    328 				 */
    329 				XXX
    330 
    331 				/*
    332 				 * Validate the timestamp verifier, to
    333 				 * check that the session key is ok.
    334 				 */
    335 				nsd.nsd_timestamp.tv_sec = ntohl(kout.t1);
    336 				nsd.nsd_timestamp.tv_usec = ntohl(kout.t2);
    337 				nsd.nsd_ttl = ntohl(kout.w1);
    338 				if ((nsd.nsd_ttl - 1) == ntohl(kout.w2))
    339 				    nfssvc_flag = NFSSVC_NFSD | NFSSVC_AUTHIN;
    340 			}
    341 #endif /* NFSKERB */
    342 		}
    343 		exit(0);
    344 	}
    345 
    346 	/* If we are serving udp, set up the socket. */
    347 	if (udpflag) {
    348 		if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
    349 			syslog(LOG_ERR, "can't create udp socket");
    350 			exit(1);
    351 		}
    352 		inetaddr.sin_family = AF_INET;
    353 		inetaddr.sin_addr.s_addr = INADDR_ANY;
    354 		inetaddr.sin_port = htons(NFS_PORT);
    355 		inetaddr.sin_len = sizeof(inetaddr);
    356 		if (bind(sock,
    357 		    (struct sockaddr *)&inetaddr, sizeof(inetaddr)) < 0) {
    358 			syslog(LOG_ERR, "can't bind udp addr");
    359 			exit(1);
    360 		}
    361 		if (!pmap_set(RPCPROG_NFS, 2, IPPROTO_UDP, NFS_PORT) ||
    362 		    !pmap_set(RPCPROG_NFS, 3, IPPROTO_UDP, NFS_PORT)) {
    363 			syslog(LOG_ERR, "can't register with udp portmap");
    364 			exit(1);
    365 		}
    366 		nfsdargs.sock = sock;
    367 		nfsdargs.name = NULL;
    368 		nfsdargs.namelen = 0;
    369 		if (nfssvc(NFSSVC_ADDSOCK, &nfsdargs) < 0) {
    370 			syslog(LOG_ERR, "can't Add UDP socket");
    371 			exit(1);
    372 		}
    373 		(void)close(sock);
    374 	}
    375 
    376 #ifdef ISO
    377 	/* If we are serving cltp, set up the socket. */
    378 	if (cltpflag) {
    379 		if ((sock = socket(AF_ISO, SOCK_DGRAM, 0)) < 0) {
    380 			syslog(LOG_ERR, "can't create cltp socket");
    381 			exit(1);
    382 		}
    383 		memset(&isoaddr, 0, sizeof(isoaddr));
    384 		isoaddr.siso_family = AF_ISO;
    385 		isoaddr.siso_tlen = 2;
    386 		cp = TSEL(&isoaddr);
    387 		*cp++ = (NFS_PORT >> 8);
    388 		*cp = (NFS_PORT & 0xff);
    389 		isoaddr.siso_len = sizeof(isoaddr);
    390 		if (bind(sock,
    391 		    (struct sockaddr *)&isoaddr, sizeof(isoaddr)) < 0) {
    392 			syslog(LOG_ERR, "can't bind cltp addr");
    393 			exit(1);
    394 		}
    395 #ifdef notyet
    396 		/*
    397 		 * XXX
    398 		 * Someday this should probably use "rpcbind", the son of
    399 		 * portmap.
    400 		 */
    401 		if (!pmap_set(RPCPROG_NFS, NFS_VER2, IPPROTO_UDP, NFS_PORT)) {
    402 			syslog(LOG_ERR, "can't register with udp portmap");
    403 			exit(1);
    404 		}
    405 #endif /* notyet */
    406 		nfsdargs.sock = sock;
    407 		nfsdargs.name = NULL;
    408 		nfsdargs.namelen = 0;
    409 		if (nfssvc(NFSSVC_ADDSOCK, &nfsdargs) < 0) {
    410 			syslog(LOG_ERR, "can't add UDP socket");
    411 			exit(1);
    412 		}
    413 		close(sock);
    414 	}
    415 #endif /* ISO */
    416 
    417 	/* Now set up the master server socket waiting for tcp connections. */
    418 	on = 1;
    419 	FD_ZERO(&sockbits);
    420 	connect_type_cnt = 0;
    421 	if (tcpflag) {
    422 		if ((tcpsock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    423 			syslog(LOG_ERR, "can't create tcp socket");
    424 			exit(1);
    425 		}
    426 		if (setsockopt(tcpsock,
    427 		    SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0)
    428 			syslog(LOG_ERR, "setsockopt SO_REUSEADDR: %m");
    429 		inetaddr.sin_family = AF_INET;
    430 		inetaddr.sin_addr.s_addr = INADDR_ANY;
    431 		inetaddr.sin_port = htons(NFS_PORT);
    432 		inetaddr.sin_len = sizeof(inetaddr);
    433 		if (bind(tcpsock,
    434 		    (struct sockaddr *)&inetaddr, sizeof (inetaddr)) < 0) {
    435 			syslog(LOG_ERR, "can't bind tcp addr");
    436 			exit(1);
    437 		}
    438 		if (listen(tcpsock, 5) < 0) {
    439 			syslog(LOG_ERR, "listen failed");
    440 			exit(1);
    441 		}
    442 		if (!pmap_set(RPCPROG_NFS, 2, IPPROTO_TCP, NFS_PORT) ||
    443 		    !pmap_set(RPCPROG_NFS, 3, IPPROTO_TCP, NFS_PORT)) {
    444 			syslog(LOG_ERR, "can't register tcp with portmap");
    445 			exit(1);
    446 		}
    447 		FD_SET(tcpsock, &sockbits);
    448 		maxsock = tcpsock;
    449 		connect_type_cnt++;
    450 	}
    451 
    452 #ifdef notyet
    453 	/* Now set up the master server socket waiting for tp4 connections. */
    454 	if (tp4flag) {
    455 		if ((tp4sock = socket(AF_ISO, SOCK_SEQPACKET, 0)) < 0) {
    456 			syslog(LOG_ERR, "can't create tp4 socket");
    457 			exit(1);
    458 		}
    459 		if (setsockopt(tp4sock,
    460 		    SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0)
    461 			syslog(LOG_ERR, "setsockopt SO_REUSEADDR: %m");
    462 		memset(&isoaddr, 0, sizeof(isoaddr));
    463 		isoaddr.siso_family = AF_ISO;
    464 		isoaddr.siso_tlen = 2;
    465 		cp = TSEL(&isoaddr);
    466 		*cp++ = (NFS_PORT >> 8);
    467 		*cp = (NFS_PORT & 0xff);
    468 		isoaddr.siso_len = sizeof(isoaddr);
    469 		if (bind(tp4sock,
    470 		    (struct sockaddr *)&isoaddr, sizeof(isoaddr)) < 0) {
    471 			syslog(LOG_ERR, "can't bind tp4 addr");
    472 			exit(1);
    473 		}
    474 		if (listen(tp4sock, 5) < 0) {
    475 			syslog(LOG_ERR, "listen failed");
    476 			exit(1);
    477 		}
    478 		/*
    479 		 * XXX
    480 		 * Someday this should probably use "rpcbind", the son of
    481 		 * portmap.
    482 		 */
    483 		if (!pmap_set(RPCPROG_NFS, NFS_VER2, IPPROTO_TCP, NFS_PORT)) {
    484 			syslog(LOG_ERR, "can't register tcp with portmap");
    485 			exit(1);
    486 		}
    487 		FD_SET(tp4sock, &sockbits);
    488 		maxsock = tp4sock;
    489 		connect_type_cnt++;
    490 	}
    491 
    492 	/* Now set up the master server socket waiting for tpip connections. */
    493 	if (tpipflag) {
    494 		if ((tpipsock = socket(AF_INET, SOCK_SEQPACKET, 0)) < 0) {
    495 			syslog(LOG_ERR, "can't create tpip socket");
    496 			exit(1);
    497 		}
    498 		if (setsockopt(tpipsock,
    499 		    SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0)
    500 			syslog(LOG_ERR, "setsockopt SO_REUSEADDR: %m");
    501 		inetaddr.sin_family = AF_INET;
    502 		inetaddr.sin_addr.s_addr = INADDR_ANY;
    503 		inetaddr.sin_port = htons(NFS_PORT);
    504 		inetaddr.sin_len = sizeof(inetaddr);
    505 		if (bind(tpipsock,
    506 		    (struct sockaddr *)&inetaddr, sizeof (inetaddr)) < 0) {
    507 			syslog(LOG_ERR, "can't bind tcp addr");
    508 			exit(1);
    509 		}
    510 		if (listen(tpipsock, 5) < 0) {
    511 			syslog(LOG_ERR, "listen failed");
    512 			exit(1);
    513 		}
    514 		/*
    515 		 * XXX
    516 		 * Someday this should probably use "rpcbind", the son of
    517 		 * portmap.
    518 		 */
    519 		if (!pmap_set(RPCPROG_NFS, NFS_VER2, IPPROTO_TCP, NFS_PORT)) {
    520 			syslog(LOG_ERR, "can't register tcp with portmap");
    521 			exit(1);
    522 		}
    523 		FD_SET(tpipsock, &sockbits);
    524 		maxsock = tpipsock;
    525 		connect_type_cnt++;
    526 	}
    527 #endif /* notyet */
    528 
    529 	if (connect_type_cnt == 0)
    530 		exit(0);
    531 
    532 	setproctitle("master");
    533 
    534 	/*
    535 	 * Loop forever accepting connections and passing the sockets
    536 	 * into the kernel for the mounts.
    537 	 */
    538 	for (;;) {
    539 		ready = sockbits;
    540 		if (connect_type_cnt > 1) {
    541 			if (select(maxsock + 1,
    542 			    &ready, NULL, NULL, NULL) < 1) {
    543 				syslog(LOG_ERR, "select failed: %m");
    544 				exit(1);
    545 			}
    546 		}
    547 		if (tcpflag && FD_ISSET(tcpsock, &ready)) {
    548 			len = sizeof(inetpeer);
    549 			if ((msgsock = accept(tcpsock,
    550 			    (struct sockaddr *)&inetpeer, &len)) < 0) {
    551 				syslog(LOG_ERR, "accept failed: %m");
    552 				exit(1);
    553 			}
    554 			memset(inetpeer.sin_zero, 0, sizeof(inetpeer.sin_zero));
    555 			if (setsockopt(msgsock, SOL_SOCKET,
    556 			    SO_KEEPALIVE, (char *)&on, sizeof(on)) < 0)
    557 				syslog(LOG_ERR,
    558 				    "setsockopt SO_KEEPALIVE: %m");
    559 			nfsdargs.sock = msgsock;
    560 			nfsdargs.name = (caddr_t)&inetpeer;
    561 			nfsdargs.namelen = sizeof(inetpeer);
    562 			nfssvc(NFSSVC_ADDSOCK, &nfsdargs);
    563 			(void)close(msgsock);
    564 		}
    565 #ifdef notyet
    566 		if (tp4flag && FD_ISSET(tp4sock, &ready)) {
    567 			len = sizeof(isopeer);
    568 			if ((msgsock = accept(tp4sock,
    569 			    (struct sockaddr *)&isopeer, &len)) < 0) {
    570 				syslog(LOG_ERR, "accept failed: %m");
    571 				exit(1);
    572 			}
    573 			if (setsockopt(msgsock, SOL_SOCKET,
    574 			    SO_KEEPALIVE, (char *)&on, sizeof(on)) < 0)
    575 				syslog(LOG_ERR,
    576 				    "setsockopt SO_KEEPALIVE: %m");
    577 			nfsdargs.sock = msgsock;
    578 			nfsdargs.name = (caddr_t)&isopeer;
    579 			nfsdargs.namelen = len;
    580 			nfssvc(NFSSVC_ADDSOCK, &nfsdargs);
    581 			(void)close(msgsock);
    582 		}
    583 		if (tpipflag && FD_ISSET(tpipsock, &ready)) {
    584 			len = sizeof(inetpeer);
    585 			if ((msgsock = accept(tpipsock,
    586 			    (struct sockaddr *)&inetpeer, &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, "setsockopt SO_KEEPALIVE: %m");
    593 			nfsdargs.sock = msgsock;
    594 			nfsdargs.name = (caddr_t)&inetpeer;
    595 			nfsdargs.namelen = len;
    596 			nfssvc(NFSSVC_ADDSOCK, &nfsdargs);
    597 			(void)close(msgsock);
    598 		}
    599 #endif /* notyet */
    600 	}
    601 }
    602 
    603 void
    604 usage()
    605 {
    606 	(void)fprintf(stderr, "usage: nfsd %s\n", USAGE);
    607 	exit(1);
    608 }
    609 
    610 void
    611 nonfs(signo)
    612 	int signo;
    613 {
    614 
    615 	syslog(LOG_ERR, "missing system call: NFS not available.");
    616 }
    617 
    618 void
    619 reapchild(signo)
    620 	int signo;
    621 {
    622 
    623 	while (wait3(NULL, WNOHANG, NULL) > 0);
    624 }
    625