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