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