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