1 /* $NetBSD: nfsd.c,v 1.31 1999/08/31 23:28:34 soren 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.31 1999/08/31 23:28:34 soren 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 /* 227 * If none of TCP or UDP are specified, default to UDP only. 228 */ 229 if (tcpflag == 0 && udpflag == 0) 230 udpflag = 1; 231 232 if (debug == 0) { 233 daemon(0, 0); 234 (void)signal(SIGHUP, SIG_IGN); 235 (void)signal(SIGINT, SIG_IGN); 236 (void)signal(SIGQUIT, SIG_IGN); 237 (void)signal(SIGSYS, nonfs); 238 } 239 (void)signal(SIGCHLD, reapchild); 240 241 if (reregister) { 242 if (udpflag && 243 (!pmap_set(RPCPROG_NFS, 2, IPPROTO_UDP, NFS_PORT) || 244 !pmap_set(RPCPROG_NFS, 3, IPPROTO_UDP, NFS_PORT))) 245 err(1, "can't register with portmap for UDP."); 246 if (tcpflag && 247 (!pmap_set(RPCPROG_NFS, 2, IPPROTO_TCP, NFS_PORT) || 248 !pmap_set(RPCPROG_NFS, 3, IPPROTO_TCP, NFS_PORT))) 249 err(1, "can't register with portmap for TCP."); 250 exit(0); 251 } 252 openlog("nfsd:", LOG_PID, LOG_DAEMON); 253 254 for (i = 0; i < nfsdcnt; i++) { 255 switch (fork()) { 256 case -1: 257 syslog(LOG_ERR, "fork: %m"); 258 exit (1); 259 case 0: 260 break; 261 default: 262 continue; 263 } 264 265 setproctitle("server"); 266 nfssvc_flag = NFSSVC_NFSD; 267 nsd.nsd_nfsd = NULL; 268 #ifdef NFSKERB 269 if (sizeof (struct nfsrpc_fullverf) != RPCX_FULLVERF || 270 sizeof (struct nfsrpc_fullblock) != RPCX_FULLBLOCK) 271 syslog(LOG_ERR, "Yikes NFSKERB structs not packed!"); 272 nsd.nsd_authstr = (u_char *)&kt; 273 nsd.nsd_authlen = sizeof (kt); 274 nsd.nsd_verfstr = (u_char *)&kverf; 275 nsd.nsd_verflen = sizeof (kverf); 276 #endif 277 while (nfssvc(nfssvc_flag, &nsd) < 0) { 278 if (errno != ENEEDAUTH) { 279 syslog(LOG_ERR, "nfssvc: %m"); 280 exit(1); 281 } 282 nfssvc_flag = NFSSVC_NFSD | NFSSVC_AUTHINFAIL; 283 #ifdef NFSKERB 284 /* 285 * Get the Kerberos ticket out of the authenticator 286 * verify it and convert the principal name to a user 287 * name. The user name is then converted to a set of 288 * user credentials via the password and group file. 289 * Finally, decrypt the timestamp and validate it. 290 * For more info see the IETF Draft "Authentication 291 * in ONC RPC". 292 */ 293 kt.length = ntohl(kt.length); 294 if (gettimeofday(&ktv, (struct timezone *)0) == 0 && 295 kt.length > 0 && kt.length <= 296 (RPCAUTH_MAXSIZ - 3 * NFSX_UNSIGNED)) { 297 kin.w1 = NFS_KERBW1(kt); 298 kt.mbz = 0; 299 (void)strcpy(inst, "*"); 300 if (krb_rd_req(&kt, NFS_KERBSRV, 301 inst, nsd.nsd_haddr, &kauth, "") == 302 RD_AP_OK && 303 krb_kntoln(&kauth, lnam) == KSUCCESS && 304 (pwd = getpwnam(lnam)) != NULL) { 305 cr = &nsd.nsd_cr; 306 cr->cr_uid = pwd->pw_uid; 307 cr->cr_groups[0] = pwd->pw_gid; 308 cr->cr_ngroups = 1; 309 setgrent(); 310 while ((grp = getgrent()) != NULL) { 311 if (grp->gr_gid == 312 cr->cr_groups[0]) 313 continue; 314 for (cpp = grp->gr_mem; 315 *cpp != NULL; ++cpp) 316 if (!strcmp(*cpp, lnam)) 317 break; 318 if (*cpp == NULL) 319 continue; 320 cr->cr_groups[cr->cr_ngroups++] 321 = grp->gr_gid; 322 if (cr->cr_ngroups == NGROUPS) 323 break; 324 } 325 endgrent(); 326 327 /* 328 * Get the timestamp verifier out of 329 * the authenticator and verifier 330 * strings. 331 */ 332 kin.t1 = kverf.t1; 333 kin.t2 = kverf.t2; 334 kin.w2 = kverf.w2; 335 memset((caddr_t)kivec, 0, 336 sizeof(kivec)); 337 memmove((caddr_t)nsd.nsd_key, 338 (caddr_t)kauth.session, 339 sizeof(kauth.session)); 340 341 /* 342 * Decrypt the timestamp verifier 343 * in CBC mode. 344 */ 345 XXX 346 347 /* 348 * Validate the timestamp verifier, to 349 * check that the session key is ok. 350 */ 351 nsd.nsd_timestamp.tv_sec = 352 ntohl(kout.t1); 353 nsd.nsd_timestamp.tv_usec = 354 ntohl(kout.t2); 355 nsd.nsd_ttl = ntohl(kout.w1); 356 if ((nsd.nsd_ttl - 1) == ntohl(kout.w2)) 357 nfssvc_flag = 358 NFSSVC_NFSD | NFSSVC_AUTHIN; 359 } 360 } 361 #endif /* NFSKERB */ 362 } 363 exit(0); 364 } 365 366 /* If we are serving udp, set up the socket. */ 367 if (udpflag) { 368 if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { 369 syslog(LOG_ERR, "can't create udp socket"); 370 exit(1); 371 } 372 inetaddr.sin_family = AF_INET; 373 inetaddr.sin_addr.s_addr = INADDR_ANY; 374 inetaddr.sin_port = htons(NFS_PORT); 375 inetaddr.sin_len = sizeof(inetaddr); 376 memset(inetaddr.sin_zero, 0, sizeof(inetaddr.sin_zero)); 377 if (bind(sock, 378 (struct sockaddr *)&inetaddr, sizeof(inetaddr)) < 0) { 379 syslog(LOG_ERR, "can't bind udp addr"); 380 exit(1); 381 } 382 if (!pmap_set(RPCPROG_NFS, 2, IPPROTO_UDP, NFS_PORT) || 383 !pmap_set(RPCPROG_NFS, 3, IPPROTO_UDP, NFS_PORT)) { 384 syslog(LOG_ERR, "can't register with udp portmap"); 385 exit(1); 386 } 387 nfsdargs.sock = sock; 388 nfsdargs.name = NULL; 389 nfsdargs.namelen = 0; 390 if (nfssvc(NFSSVC_ADDSOCK, &nfsdargs) < 0) { 391 syslog(LOG_ERR, "can't Add UDP socket"); 392 exit(1); 393 } 394 (void)close(sock); 395 } 396 397 #ifdef ISO 398 /* If we are serving cltp, set up the socket. */ 399 if (cltpflag) { 400 if ((sock = socket(AF_ISO, SOCK_DGRAM, 0)) < 0) { 401 syslog(LOG_ERR, "can't create cltp socket"); 402 exit(1); 403 } 404 memset(&isoaddr, 0, sizeof(isoaddr)); 405 isoaddr.siso_family = AF_ISO; 406 isoaddr.siso_tlen = 2; 407 cp = TSEL(&isoaddr); 408 *cp++ = (NFS_PORT >> 8); 409 *cp = (NFS_PORT & 0xff); 410 isoaddr.siso_len = sizeof(isoaddr); 411 if (bind(sock, 412 (struct sockaddr *)&isoaddr, sizeof(isoaddr)) < 0) { 413 syslog(LOG_ERR, "can't bind cltp addr"); 414 exit(1); 415 } 416 #ifdef notyet 417 /* 418 * XXX 419 * Someday this should probably use "rpcbind", the son of 420 * portmap. 421 */ 422 if (!pmap_set(RPCPROG_NFS, NFS_VER2, IPPROTO_UDP, NFS_PORT)) { 423 syslog(LOG_ERR, "can't register with udp portmap"); 424 exit(1); 425 } 426 #endif /* notyet */ 427 nfsdargs.sock = sock; 428 nfsdargs.name = NULL; 429 nfsdargs.namelen = 0; 430 if (nfssvc(NFSSVC_ADDSOCK, &nfsdargs) < 0) { 431 syslog(LOG_ERR, "can't add UDP socket"); 432 exit(1); 433 } 434 close(sock); 435 } 436 #endif /* ISO */ 437 438 /* Now set up the master server socket waiting for tcp connections. */ 439 on = 1; 440 FD_ZERO(&sockbits); 441 connect_type_cnt = 0; 442 if (tcpflag) { 443 if ((tcpsock = socket(AF_INET, SOCK_STREAM, 0)) < 0) { 444 syslog(LOG_ERR, "can't create tcp socket"); 445 exit(1); 446 } 447 if (setsockopt(tcpsock, 448 SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0) 449 syslog(LOG_ERR, "setsockopt SO_REUSEADDR: %m"); 450 inetaddr.sin_family = AF_INET; 451 inetaddr.sin_addr.s_addr = INADDR_ANY; 452 inetaddr.sin_port = htons(NFS_PORT); 453 inetaddr.sin_len = sizeof(inetaddr); 454 memset(inetaddr.sin_zero, 0, sizeof(inetaddr.sin_zero)); 455 if (bind(tcpsock, 456 (struct sockaddr *)&inetaddr, sizeof (inetaddr)) < 0) { 457 syslog(LOG_ERR, "can't bind tcp addr"); 458 exit(1); 459 } 460 if (listen(tcpsock, 5) < 0) { 461 syslog(LOG_ERR, "listen failed"); 462 exit(1); 463 } 464 if (!pmap_set(RPCPROG_NFS, 2, IPPROTO_TCP, NFS_PORT) || 465 !pmap_set(RPCPROG_NFS, 3, IPPROTO_TCP, NFS_PORT)) { 466 syslog(LOG_ERR, "can't register tcp with portmap"); 467 exit(1); 468 } 469 FD_SET(tcpsock, &sockbits); 470 maxsock = tcpsock; 471 connect_type_cnt++; 472 } 473 474 #ifdef notyet 475 /* Now set up the master server socket waiting for tp4 connections. */ 476 if (tp4flag) { 477 if ((tp4sock = socket(AF_ISO, SOCK_SEQPACKET, 0)) < 0) { 478 syslog(LOG_ERR, "can't create tp4 socket"); 479 exit(1); 480 } 481 if (setsockopt(tp4sock, 482 SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0) 483 syslog(LOG_ERR, "setsockopt SO_REUSEADDR: %m"); 484 memset(&isoaddr, 0, sizeof(isoaddr)); 485 isoaddr.siso_family = AF_ISO; 486 isoaddr.siso_tlen = 2; 487 cp = TSEL(&isoaddr); 488 *cp++ = (NFS_PORT >> 8); 489 *cp = (NFS_PORT & 0xff); 490 isoaddr.siso_len = sizeof(isoaddr); 491 if (bind(tp4sock, 492 (struct sockaddr *)&isoaddr, sizeof(isoaddr)) < 0) { 493 syslog(LOG_ERR, "can't bind tp4 addr"); 494 exit(1); 495 } 496 if (listen(tp4sock, 5) < 0) { 497 syslog(LOG_ERR, "listen failed"); 498 exit(1); 499 } 500 /* 501 * XXX 502 * Someday this should probably use "rpcbind", the son of 503 * portmap. 504 */ 505 if (!pmap_set(RPCPROG_NFS, NFS_VER2, IPPROTO_TCP, NFS_PORT)) { 506 syslog(LOG_ERR, "can't register tcp with portmap"); 507 exit(1); 508 } 509 FD_SET(tp4sock, &sockbits); 510 maxsock = tp4sock; 511 connect_type_cnt++; 512 } 513 514 /* Now set up the master server socket waiting for tpip connections. */ 515 if (tpipflag) { 516 if ((tpipsock = socket(AF_INET, SOCK_SEQPACKET, 0)) < 0) { 517 syslog(LOG_ERR, "can't create tpip socket"); 518 exit(1); 519 } 520 if (setsockopt(tpipsock, 521 SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0) 522 syslog(LOG_ERR, "setsockopt SO_REUSEADDR: %m"); 523 inetaddr.sin_family = AF_INET; 524 inetaddr.sin_addr.s_addr = INADDR_ANY; 525 inetaddr.sin_port = htons(NFS_PORT); 526 inetaddr.sin_len = sizeof(inetaddr); 527 memset(inetaddr.sin_zero, 0, sizeof(inetaddr.sin_zero)); 528 if (bind(tpipsock, 529 (struct sockaddr *)&inetaddr, sizeof (inetaddr)) < 0) { 530 syslog(LOG_ERR, "can't bind tcp addr"); 531 exit(1); 532 } 533 if (listen(tpipsock, 5) < 0) { 534 syslog(LOG_ERR, "listen failed"); 535 exit(1); 536 } 537 /* 538 * XXX 539 * Someday this should probably use "rpcbind", the son of 540 * portmap. 541 */ 542 if (!pmap_set(RPCPROG_NFS, NFS_VER2, IPPROTO_TCP, NFS_PORT)) { 543 syslog(LOG_ERR, "can't register tcp with portmap"); 544 exit(1); 545 } 546 FD_SET(tpipsock, &sockbits); 547 maxsock = tpipsock; 548 connect_type_cnt++; 549 } 550 #endif /* notyet */ 551 552 if (connect_type_cnt == 0) 553 exit(0); 554 555 setproctitle("master"); 556 557 /* 558 * Loop forever accepting connections and passing the sockets 559 * into the kernel for the mounts. 560 */ 561 for (;;) { 562 ready = sockbits; 563 if (connect_type_cnt > 1) { 564 if (select(maxsock + 1, 565 &ready, NULL, NULL, NULL) < 1) { 566 syslog(LOG_ERR, "select failed: %m"); 567 exit(1); 568 } 569 } 570 if (tcpflag && FD_ISSET(tcpsock, &ready)) { 571 len = sizeof(inetpeer); 572 if ((msgsock = accept(tcpsock, 573 (struct sockaddr *)&inetpeer, &len)) < 0) { 574 syslog(LOG_ERR, "accept failed: %m"); 575 exit(1); 576 } 577 memset(inetpeer.sin_zero, 0, sizeof(inetpeer.sin_zero)); 578 if (setsockopt(msgsock, SOL_SOCKET, 579 SO_KEEPALIVE, (char *)&on, sizeof(on)) < 0) 580 syslog(LOG_ERR, 581 "setsockopt SO_KEEPALIVE: %m"); 582 nfsdargs.sock = msgsock; 583 nfsdargs.name = (caddr_t)&inetpeer; 584 nfsdargs.namelen = sizeof(inetpeer); 585 nfssvc(NFSSVC_ADDSOCK, &nfsdargs); 586 (void)close(msgsock); 587 } 588 #ifdef notyet 589 if (tp4flag && FD_ISSET(tp4sock, &ready)) { 590 len = sizeof(isopeer); 591 if ((msgsock = accept(tp4sock, 592 (struct sockaddr *)&isopeer, &len)) < 0) { 593 syslog(LOG_ERR, "accept failed: %m"); 594 exit(1); 595 } 596 if (setsockopt(msgsock, SOL_SOCKET, 597 SO_KEEPALIVE, (char *)&on, sizeof(on)) < 0) 598 syslog(LOG_ERR, 599 "setsockopt SO_KEEPALIVE: %m"); 600 nfsdargs.sock = msgsock; 601 nfsdargs.name = (caddr_t)&isopeer; 602 nfsdargs.namelen = len; 603 nfssvc(NFSSVC_ADDSOCK, &nfsdargs); 604 (void)close(msgsock); 605 } 606 if (tpipflag && FD_ISSET(tpipsock, &ready)) { 607 len = sizeof(inetpeer); 608 if ((msgsock = accept(tpipsock, 609 (struct sockaddr *)&inetpeer, &len)) < 0) { 610 syslog(LOG_ERR, "Accept failed: %m"); 611 exit(1); 612 } 613 if (setsockopt(msgsock, SOL_SOCKET, 614 SO_KEEPALIVE, (char *)&on, sizeof(on)) < 0) 615 syslog(LOG_ERR, "setsockopt SO_KEEPALIVE: %m"); 616 nfsdargs.sock = msgsock; 617 nfsdargs.name = (caddr_t)&inetpeer; 618 nfsdargs.namelen = len; 619 nfssvc(NFSSVC_ADDSOCK, &nfsdargs); 620 (void)close(msgsock); 621 } 622 #endif /* notyet */ 623 } 624 } 625 626 void 627 usage() 628 { 629 630 (void)fprintf(stderr, "usage: nfsd %s\n", USAGE); 631 exit(1); 632 } 633 634 void 635 nonfs(signo) 636 int signo; 637 { 638 639 syslog(LOG_ERR, "missing system call: NFS not available."); 640 } 641 642 void 643 reapchild(signo) 644 int signo; 645 { 646 647 while (wait3(NULL, WNOHANG, NULL) > 0); 648 } 649