nfsd.c revision 24359
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
38static 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
44static char sccsid[] = "@(#)nfsd.c	8.9 (Berkeley) 3/29/95";
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 <kerberosIV/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))
89int	debug = 1;
90#else
91int	debug = 0;
92#endif
93
94struct	nfsd_srvargs nsd;
95#ifdef OLD_SETPROCTITLE
96char	**Argv = NULL;		/* pointer to argument vector */
97char	*LastArg = NULL;	/* end of argv */
98#endif
99
100#ifdef NFSKERB
101char		lnam[ANAME_SZ];
102KTEXT_ST	kt;
103AUTH_DAT	kauth;
104char		inst[INST_SZ];
105struct nfsrpc_fullblock kin, kout;
106struct nfsrpc_fullverf kverf;
107NFSKERBKEY_T	kivec;
108struct timeval	ktv;
109NFSKERBKEYSCHED_T kerb_keysched;
110#endif
111
112void	nonfs __P((int));
113void	reapchild __P((int));
114#ifdef OLD_SETPROCTITLE
115#ifdef __FreeBSD__
116void	setproctitle __P((char *));
117#endif
118#endif
119void	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 */
140int
141main(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	int error;
163
164	error = getvfsbyname("nfs", &vfc);
165	if (error && vfsisloadable("nfs")) {
166		if (vfsload("nfs"))
167			err(1, "vfsload(nfs)");
168		endvfsent();	/* flush cache */
169		error = getvfsbyname("nfs", &vfc);
170	}
171	if (error)
172		errx(1, "NFS is not available in the running kernel");
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)) != -1)
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 (!tcpflag && !udpflag)
233		udpflag = 1;
234	argv += optind;
235	argc -= optind;
236
237	/*
238	 * XXX
239	 * Backward compatibility, trailing number is the count of daemons.
240	 */
241	if (argc > 1)
242		usage();
243	if (argc == 1) {
244		nfsdcnt = atoi(argv[0]);
245		if (nfsdcnt < 1 || nfsdcnt > MAXNFSDCNT) {
246			warnx("nfsd count %d; reset to %d", 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
633void
634usage()
635{
636	(void)fprintf(stderr, "usage: nfsd %s\n", USAGE);
637	exit(1);
638}
639
640void
641nonfs(signo)
642	int signo;
643{
644	syslog(LOG_ERR, "missing system call: NFS not available.");
645}
646
647void
648reapchild(signo)
649	int signo;
650{
651
652	while (wait3(NULL, WNOHANG, NULL) > 0);
653}
654
655#ifdef OLD_SETPROCTITLE
656#ifdef __FreeBSD__
657void
658setproctitle(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