Deleted Added
full compact
nfsd.c (192993) nfsd.c (194880)
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

--- 27 unchanged lines hidden (view full) ---

36 The Regents of the University of California. All rights reserved.\n";
37#endif /* not lint */
38
39#ifndef lint
40#if 0
41static char sccsid[] = "@(#)nfsd.c 8.9 (Berkeley) 3/29/95";
42#endif
43static const char rcsid[] =
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

--- 27 unchanged lines hidden (view full) ---

36 The Regents of the University of California. All rights reserved.\n";
37#endif /* not lint */
38
39#ifndef lint
40#if 0
41static char sccsid[] = "@(#)nfsd.c 8.9 (Berkeley) 3/29/95";
42#endif
43static const char rcsid[] =
44 "$FreeBSD: head/usr.sbin/nfsd/nfsd.c 192993 2009-05-28 20:28:13Z rmacklem $";
44 "$FreeBSD: head/usr.sbin/nfsd/nfsd.c 194880 2009-06-24 18:42:21Z dfr $";
45#endif /* not lint */
46
47#include <sys/param.h>
48#include <sys/syslog.h>
49#include <sys/wait.h>
50#include <sys/mount.h>
51#include <sys/fcntl.h>
52#include <sys/linker.h>
53#include <sys/module.h>
54
55#include <rpc/rpc.h>
56#include <rpc/pmap_clnt.h>
45#endif /* not lint */
46
47#include <sys/param.h>
48#include <sys/syslog.h>
49#include <sys/wait.h>
50#include <sys/mount.h>
51#include <sys/fcntl.h>
52#include <sys/linker.h>
53#include <sys/module.h>
54
55#include <rpc/rpc.h>
56#include <rpc/pmap_clnt.h>
57#include <rpcsvc/nfs_prot.h>
57
58#include <netdb.h>
59#include <arpa/inet.h>
58
59#include <netdb.h>
60#include <arpa/inet.h>
60#include <nfs/rpcv2.h>
61#include <nfs/nfsproto.h>
62#include <nfsserver/nfs.h>
63#include <nfs/nfssvc.h>
64
65#include <err.h>
66#include <errno.h>
67#include <signal.h>
68#include <stdio.h>
69#include <stdlib.h>

--- 193 unchanged lines hidden (view full) ---

263 ecode = getaddrinfo(NULL, "nfs", &hints, &ai_udp);
264 if (ecode != 0)
265 err(1, "getaddrinfo udp: %s", gai_strerror(ecode));
266 nconf_udp = getnetconfigent("udp");
267 if (nconf_udp == NULL)
268 err(1, "getnetconfigent udp failed");
269 nb_udp.buf = ai_udp->ai_addr;
270 nb_udp.len = nb_udp.maxlen = ai_udp->ai_addrlen;
61#include <nfsserver/nfs.h>
62#include <nfs/nfssvc.h>
63
64#include <err.h>
65#include <errno.h>
66#include <signal.h>
67#include <stdio.h>
68#include <stdlib.h>

--- 193 unchanged lines hidden (view full) ---

262 ecode = getaddrinfo(NULL, "nfs", &hints, &ai_udp);
263 if (ecode != 0)
264 err(1, "getaddrinfo udp: %s", gai_strerror(ecode));
265 nconf_udp = getnetconfigent("udp");
266 if (nconf_udp == NULL)
267 err(1, "getnetconfigent udp failed");
268 nb_udp.buf = ai_udp->ai_addr;
269 nb_udp.len = nb_udp.maxlen = ai_udp->ai_addrlen;
271 if ((!rpcb_set(RPCPROG_NFS, 2, nconf_udp, &nb_udp)) ||
272 (!rpcb_set(RPCPROG_NFS, 3, nconf_udp, &nb_udp)))
270 if ((!rpcb_set(NFS_PROGRAM, 2, nconf_udp, &nb_udp)) ||
271 (!rpcb_set(NFS_PROGRAM, 3, nconf_udp, &nb_udp)))
273 err(1, "rpcb_set udp failed");
274 freeaddrinfo(ai_udp);
275 }
276 if (udpflag && ip6flag) {
277 memset(&hints, 0, sizeof hints);
278 hints.ai_flags = AI_PASSIVE;
279 hints.ai_family = AF_INET6;
280 hints.ai_socktype = SOCK_DGRAM;
281 hints.ai_protocol = IPPROTO_UDP;
282 ecode = getaddrinfo(NULL, "nfs", &hints, &ai_udp6);
283 if (ecode != 0)
284 err(1, "getaddrinfo udp6: %s", gai_strerror(ecode));
285 nconf_udp6 = getnetconfigent("udp6");
286 if (nconf_udp6 == NULL)
287 err(1, "getnetconfigent udp6 failed");
288 nb_udp6.buf = ai_udp6->ai_addr;
289 nb_udp6.len = nb_udp6.maxlen = ai_udp6->ai_addrlen;
272 err(1, "rpcb_set udp failed");
273 freeaddrinfo(ai_udp);
274 }
275 if (udpflag && ip6flag) {
276 memset(&hints, 0, sizeof hints);
277 hints.ai_flags = AI_PASSIVE;
278 hints.ai_family = AF_INET6;
279 hints.ai_socktype = SOCK_DGRAM;
280 hints.ai_protocol = IPPROTO_UDP;
281 ecode = getaddrinfo(NULL, "nfs", &hints, &ai_udp6);
282 if (ecode != 0)
283 err(1, "getaddrinfo udp6: %s", gai_strerror(ecode));
284 nconf_udp6 = getnetconfigent("udp6");
285 if (nconf_udp6 == NULL)
286 err(1, "getnetconfigent udp6 failed");
287 nb_udp6.buf = ai_udp6->ai_addr;
288 nb_udp6.len = nb_udp6.maxlen = ai_udp6->ai_addrlen;
290 if ((!rpcb_set(RPCPROG_NFS, 2, nconf_udp6, &nb_udp6)) ||
291 (!rpcb_set(RPCPROG_NFS, 3, nconf_udp6, &nb_udp6)))
289 if ((!rpcb_set(NFS_PROGRAM, 2, nconf_udp6, &nb_udp6)) ||
290 (!rpcb_set(NFS_PROGRAM, 3, nconf_udp6, &nb_udp6)))
292 err(1, "rpcb_set udp6 failed");
293 freeaddrinfo(ai_udp6);
294 }
295 if (tcpflag) {
296 memset(&hints, 0, sizeof hints);
297 hints.ai_flags = AI_PASSIVE;
298 hints.ai_family = AF_INET;
299 hints.ai_socktype = SOCK_STREAM;
300 hints.ai_protocol = IPPROTO_TCP;
301 ecode = getaddrinfo(NULL, "nfs", &hints, &ai_tcp);
302 if (ecode != 0)
303 err(1, "getaddrinfo tcp: %s", gai_strerror(ecode));
304 nconf_tcp = getnetconfigent("tcp");
305 if (nconf_tcp == NULL)
306 err(1, "getnetconfigent tcp failed");
307 nb_tcp.buf = ai_tcp->ai_addr;
308 nb_tcp.len = nb_tcp.maxlen = ai_tcp->ai_addrlen;
291 err(1, "rpcb_set udp6 failed");
292 freeaddrinfo(ai_udp6);
293 }
294 if (tcpflag) {
295 memset(&hints, 0, sizeof hints);
296 hints.ai_flags = AI_PASSIVE;
297 hints.ai_family = AF_INET;
298 hints.ai_socktype = SOCK_STREAM;
299 hints.ai_protocol = IPPROTO_TCP;
300 ecode = getaddrinfo(NULL, "nfs", &hints, &ai_tcp);
301 if (ecode != 0)
302 err(1, "getaddrinfo tcp: %s", gai_strerror(ecode));
303 nconf_tcp = getnetconfigent("tcp");
304 if (nconf_tcp == NULL)
305 err(1, "getnetconfigent tcp failed");
306 nb_tcp.buf = ai_tcp->ai_addr;
307 nb_tcp.len = nb_tcp.maxlen = ai_tcp->ai_addrlen;
309 if ((!rpcb_set(RPCPROG_NFS, 2, nconf_tcp, &nb_tcp)) ||
310 (!rpcb_set(RPCPROG_NFS, 3, nconf_tcp, &nb_tcp)))
308 if ((!rpcb_set(NFS_PROGRAM, 2, nconf_tcp, &nb_tcp)) ||
309 (!rpcb_set(NFS_PROGRAM, 3, nconf_tcp, &nb_tcp)))
311 err(1, "rpcb_set tcp failed");
312 freeaddrinfo(ai_tcp);
313 }
314 if (tcpflag && ip6flag) {
315 memset(&hints, 0, sizeof hints);
316 hints.ai_flags = AI_PASSIVE;
317 hints.ai_family = AF_INET6;
318 hints.ai_socktype = SOCK_STREAM;
319 hints.ai_protocol = IPPROTO_TCP;
320 ecode = getaddrinfo(NULL, "nfs", &hints, &ai_tcp6);
321 if (ecode != 0)
322 err(1, "getaddrinfo tcp6: %s", gai_strerror(ecode));
323 nconf_tcp6 = getnetconfigent("tcp6");
324 if (nconf_tcp6 == NULL)
325 err(1, "getnetconfigent tcp6 failed");
326 nb_tcp6.buf = ai_tcp6->ai_addr;
327 nb_tcp6.len = nb_tcp6.maxlen = ai_tcp6->ai_addrlen;
310 err(1, "rpcb_set tcp failed");
311 freeaddrinfo(ai_tcp);
312 }
313 if (tcpflag && ip6flag) {
314 memset(&hints, 0, sizeof hints);
315 hints.ai_flags = AI_PASSIVE;
316 hints.ai_family = AF_INET6;
317 hints.ai_socktype = SOCK_STREAM;
318 hints.ai_protocol = IPPROTO_TCP;
319 ecode = getaddrinfo(NULL, "nfs", &hints, &ai_tcp6);
320 if (ecode != 0)
321 err(1, "getaddrinfo tcp6: %s", gai_strerror(ecode));
322 nconf_tcp6 = getnetconfigent("tcp6");
323 if (nconf_tcp6 == NULL)
324 err(1, "getnetconfigent tcp6 failed");
325 nb_tcp6.buf = ai_tcp6->ai_addr;
326 nb_tcp6.len = nb_tcp6.maxlen = ai_tcp6->ai_addrlen;
328 if ((!rpcb_set(RPCPROG_NFS, 2, nconf_tcp6, &nb_tcp6)) ||
329 (!rpcb_set(RPCPROG_NFS, 3, nconf_tcp6, &nb_tcp6)))
327 if ((!rpcb_set(NFS_PROGRAM, 2, nconf_tcp6, &nb_tcp6)) ||
328 (!rpcb_set(NFS_PROGRAM, 3, nconf_tcp6, &nb_tcp6)))
330 err(1, "rpcb_set tcp6 failed");
331 freeaddrinfo(ai_tcp6);
332 }
333 exit (0);
334 }
335 if (debug == 0) {
336 daemon(0, 0);
337 (void)signal(SIGHUP, SIG_IGN);

--- 149 unchanged lines hidden (view full) ---

487 gai_strerror(ecode));
488 nfsd_exit(1);
489 }
490 nconf_udp = getnetconfigent("udp");
491 if (nconf_udp == NULL)
492 err(1, "getnetconfigent udp failed");
493 nb_udp.buf = ai_udp->ai_addr;
494 nb_udp.len = nb_udp.maxlen = ai_udp->ai_addrlen;
329 err(1, "rpcb_set tcp6 failed");
330 freeaddrinfo(ai_tcp6);
331 }
332 exit (0);
333 }
334 if (debug == 0) {
335 daemon(0, 0);
336 (void)signal(SIGHUP, SIG_IGN);

--- 149 unchanged lines hidden (view full) ---

486 gai_strerror(ecode));
487 nfsd_exit(1);
488 }
489 nconf_udp = getnetconfigent("udp");
490 if (nconf_udp == NULL)
491 err(1, "getnetconfigent udp failed");
492 nb_udp.buf = ai_udp->ai_addr;
493 nb_udp.len = nb_udp.maxlen = ai_udp->ai_addrlen;
495 if ((!rpcb_set(RPCPROG_NFS, 2, nconf_udp, &nb_udp)) ||
496 (!rpcb_set(RPCPROG_NFS, 3, nconf_udp, &nb_udp)))
494 if ((!rpcb_set(NFS_PROGRAM, 2, nconf_udp, &nb_udp)) ||
495 (!rpcb_set(NFS_PROGRAM, 3, nconf_udp, &nb_udp)))
497 err(1, "rpcb_set udp failed");
498 freeaddrinfo(ai_udp);
499 }
500 }
501
502 /* Set up the socket for udp6 and rpcb register it. */
503 if (udpflag && ip6flag) {
504 rpcbreg = 0;

--- 51 unchanged lines hidden (view full) ---

556 gai_strerror(ecode));
557 nfsd_exit(1);
558 }
559 nconf_udp6 = getnetconfigent("udp6");
560 if (nconf_udp6 == NULL)
561 err(1, "getnetconfigent udp6 failed");
562 nb_udp6.buf = ai_udp6->ai_addr;
563 nb_udp6.len = nb_udp6.maxlen = ai_udp6->ai_addrlen;
496 err(1, "rpcb_set udp failed");
497 freeaddrinfo(ai_udp);
498 }
499 }
500
501 /* Set up the socket for udp6 and rpcb register it. */
502 if (udpflag && ip6flag) {
503 rpcbreg = 0;

--- 51 unchanged lines hidden (view full) ---

555 gai_strerror(ecode));
556 nfsd_exit(1);
557 }
558 nconf_udp6 = getnetconfigent("udp6");
559 if (nconf_udp6 == NULL)
560 err(1, "getnetconfigent udp6 failed");
561 nb_udp6.buf = ai_udp6->ai_addr;
562 nb_udp6.len = nb_udp6.maxlen = ai_udp6->ai_addrlen;
564 if ((!rpcb_set(RPCPROG_NFS, 2, nconf_udp6, &nb_udp6)) ||
565 (!rpcb_set(RPCPROG_NFS, 3, nconf_udp6, &nb_udp6)))
563 if ((!rpcb_set(NFS_PROGRAM, 2, nconf_udp6, &nb_udp6)) ||
564 (!rpcb_set(NFS_PROGRAM, 3, nconf_udp6, &nb_udp6)))
566 err(1, "rpcb_set udp6 failed");
567 freeaddrinfo(ai_udp6);
568 }
569 }
570
571 /* Set up the socket for tcp and rpcb register it. */
572 if (tcpflag) {
573 rpcbreg = 0;

--- 48 unchanged lines hidden (view full) ---

622 gai_strerror(ecode));
623 nfsd_exit(1);
624 }
625 nconf_tcp = getnetconfigent("tcp");
626 if (nconf_tcp == NULL)
627 err(1, "getnetconfigent tcp failed");
628 nb_tcp.buf = ai_tcp->ai_addr;
629 nb_tcp.len = nb_tcp.maxlen = ai_tcp->ai_addrlen;
565 err(1, "rpcb_set udp6 failed");
566 freeaddrinfo(ai_udp6);
567 }
568 }
569
570 /* Set up the socket for tcp and rpcb register it. */
571 if (tcpflag) {
572 rpcbreg = 0;

--- 48 unchanged lines hidden (view full) ---

621 gai_strerror(ecode));
622 nfsd_exit(1);
623 }
624 nconf_tcp = getnetconfigent("tcp");
625 if (nconf_tcp == NULL)
626 err(1, "getnetconfigent tcp failed");
627 nb_tcp.buf = ai_tcp->ai_addr;
628 nb_tcp.len = nb_tcp.maxlen = ai_tcp->ai_addrlen;
630 if ((!rpcb_set(RPCPROG_NFS, 2, nconf_tcp,
631 &nb_tcp)) || (!rpcb_set(RPCPROG_NFS, 3,
629 if ((!rpcb_set(NFS_PROGRAM, 2, nconf_tcp,
630 &nb_tcp)) || (!rpcb_set(NFS_PROGRAM, 3,
632 nconf_tcp, &nb_tcp)))
633 err(1, "rpcb_set tcp failed");
634 freeaddrinfo(ai_tcp);
635 }
636 }
637
638 /* Set up the socket for tcp6 and rpcb register it. */
639 if (tcpflag && ip6flag) {

--- 57 unchanged lines hidden (view full) ---

697 gai_strerror(ecode));
698 nfsd_exit(1);
699 }
700 nconf_tcp6 = getnetconfigent("tcp6");
701 if (nconf_tcp6 == NULL)
702 err(1, "getnetconfigent tcp6 failed");
703 nb_tcp6.buf = ai_tcp6->ai_addr;
704 nb_tcp6.len = nb_tcp6.maxlen = ai_tcp6->ai_addrlen;
631 nconf_tcp, &nb_tcp)))
632 err(1, "rpcb_set tcp failed");
633 freeaddrinfo(ai_tcp);
634 }
635 }
636
637 /* Set up the socket for tcp6 and rpcb register it. */
638 if (tcpflag && ip6flag) {

--- 57 unchanged lines hidden (view full) ---

696 gai_strerror(ecode));
697 nfsd_exit(1);
698 }
699 nconf_tcp6 = getnetconfigent("tcp6");
700 if (nconf_tcp6 == NULL)
701 err(1, "getnetconfigent tcp6 failed");
702 nb_tcp6.buf = ai_tcp6->ai_addr;
703 nb_tcp6.len = nb_tcp6.maxlen = ai_tcp6->ai_addrlen;
705 if ((!rpcb_set(RPCPROG_NFS, 2, nconf_tcp6, &nb_tcp6)) ||
706 (!rpcb_set(RPCPROG_NFS, 3, nconf_tcp6, &nb_tcp6)))
704 if ((!rpcb_set(NFS_PROGRAM, 2, nconf_tcp6, &nb_tcp6)) ||
705 (!rpcb_set(NFS_PROGRAM, 3, nconf_tcp6, &nb_tcp6)))
707 err(1, "rpcb_set tcp6 failed");
708 freeaddrinfo(ai_tcp6);
709 }
710 }
711
712 if (rpcbregcnt == 0) {
713 syslog(LOG_ERR, "rpcb_set() failed, nothing to do: %m");
714 nfsd_exit(1);

--- 151 unchanged lines hidden (view full) ---

866 if (pid == children[i])
867 children[i] = -1;
868 }
869}
870
871void
872unregistration()
873{
706 err(1, "rpcb_set tcp6 failed");
707 freeaddrinfo(ai_tcp6);
708 }
709 }
710
711 if (rpcbregcnt == 0) {
712 syslog(LOG_ERR, "rpcb_set() failed, nothing to do: %m");
713 nfsd_exit(1);

--- 151 unchanged lines hidden (view full) ---

865 if (pid == children[i])
866 children[i] = -1;
867 }
868}
869
870void
871unregistration()
872{
874 if ((!rpcb_unset(RPCPROG_NFS, 2, NULL)) ||
875 (!rpcb_unset(RPCPROG_NFS, 3, NULL)))
873 if ((!rpcb_unset(NFS_PROGRAM, 2, NULL)) ||
874 (!rpcb_unset(NFS_PROGRAM, 3, NULL)))
876 syslog(LOG_ERR, "rpcb_unset failed");
877}
878
879void
880killchildren()
881{
882 int i;
883

--- 90 unchanged lines hidden ---
875 syslog(LOG_ERR, "rpcb_unset failed");
876}
877
878void
879killchildren()
880{
881 int i;
882

--- 90 unchanged lines hidden ---