Thu Apr 23 00:22:01 2020 UTC ()
Rename debug to mountd_debug to avoid overlap in rump tests


(joerg)
diff -r1.2 -r1.3 src/usr.sbin/mountd/get_net.c
diff -r1.130 -r1.131 src/usr.sbin/mountd/mountd.c
diff -r1.3 -r1.4 src/usr.sbin/mountd/mountd.h

cvs diff -r1.2 -r1.3 src/usr.sbin/mountd/get_net.c (expand / switch to unified diff)

--- src/usr.sbin/mountd/get_net.c 2015/12/24 01:41:19 1.2
+++ src/usr.sbin/mountd/get_net.c 2020/04/23 00:22:01 1.3
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: get_net.c,v 1.2 2015/12/24 01:41:19 christos Exp $ */ 1/* $NetBSD: get_net.c,v 1.3 2020/04/23 00:22:01 joerg Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1989, 1993 4 * Copyright (c) 1989, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Herb Hasler and Rick Macklem at The University of Guelph. 8 * Herb Hasler and Rick Macklem at The University of Guelph.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -23,46 +23,46 @@ @@ -23,46 +23,46 @@
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE. 32 * SUCH DAMAGE.
33 */ 33 */
34 34
35#include <sys/cdefs.h> 35#include <sys/cdefs.h>
36__RCSID("$NetBSD: get_net.c,v 1.2 2015/12/24 01:41:19 christos Exp $"); 36__RCSID("$NetBSD: get_net.c,v 1.3 2020/04/23 00:22:01 joerg Exp $");
37 37
38#include <sys/types.h> 38#include <sys/types.h>
39#include <netdb.h> 39#include <netdb.h>
40#include <stdio.h> 40#include <stdio.h>
41#include <limits.h> 41#include <limits.h>
42#include <errno.h> 42#include <errno.h>
43#include <string.h> 43#include <string.h>
44#include <stdlib.h> 44#include <stdlib.h>
45#include <unistd.h> 45#include <unistd.h>
46#include <util.h> 46#include <util.h>
47#include <arpa/inet.h> 47#include <arpa/inet.h>
48#include <netinet/in.h> 48#include <netinet/in.h>
49 49
50#include "mountd.h" 50#include "mountd.h"
51 51
52#ifdef TEST 52#ifdef TEST
53int opt_flags; 53int opt_flags;
54const int ninumeric = NI_NUMERICHOST; 54const int ninumeric = NI_NUMERICHOST;
55int debug = 1; 55int mountd_debug = 1;
56#endif 56#endif
57 57
58static int  58static int
59isdottedquad(const char *cp) 59isdottedquad(const char *cp)
60{ 60{
61 for (;;) 61 for (;;)
62 switch (*cp++) { 62 switch (*cp++) {
63 case '\0': 63 case '\0':
64 return 1; 64 return 1;
65 case '.': 65 case '.':
66 case '0': case '1': case '2': case '3': case '4': 66 case '0': case '1': case '2': case '3': case '4':
67 case '5': case '6': case '7': case '8': case '9': 67 case '5': case '6': case '7': case '8': case '9':
68 continue; 68 continue;
@@ -135,27 +135,27 @@ get_net(char *cp, struct netmsk *net, in @@ -135,27 +135,27 @@ get_net(char *cp, struct netmsk *net, in
135 sin.sin_family = AF_INET; 135 sin.sin_family = AF_INET;
136 sin.sin_len = sizeof sin; 136 sin.sin_len = sizeof sin;
137 sin.sin_addr = inet_makeaddr(np->n_net, 0); 137 sin.sin_addr = inet_makeaddr(np->n_net, 0);
138 sa = (struct sockaddr *)&sin; 138 sa = (struct sockaddr *)&sin;
139 } else if (isdottedquad(cp)) { 139 } else if (isdottedquad(cp)) {
140 /* 140 /*
141 * Handle dotted quad [or less than quad] notation specially 141 * Handle dotted quad [or less than quad] notation specially
142 * because getaddrinfo() will parse them in the old style: 142 * because getaddrinfo() will parse them in the old style:
143 * i.e. 1.2.3 -> 1.2.0.3 not 1.2.3.0 143 * i.e. 1.2.3 -> 1.2.0.3 not 1.2.3.0
144 */ 144 */
145 sin.sin_family = AF_INET; 145 sin.sin_family = AF_INET;
146 sin.sin_len = sizeof sin; 146 sin.sin_len = sizeof sin;
147 sin.sin_addr = inet_makeaddr(inet_network(cp), 0); 147 sin.sin_addr = inet_makeaddr(inet_network(cp), 0);
148 if (debug) 148 if (mountd_debug)
149 fprintf(stderr, "get_net: '%s' v4 addr %x\n", 149 fprintf(stderr, "get_net: '%s' v4 addr %x\n",
150 cp, sin.sin_addr.s_addr); 150 cp, sin.sin_addr.s_addr);
151 sa = (struct sockaddr *)&sin; 151 sa = (struct sockaddr *)&sin;
152 } else { 152 } else {
153 memset(&hints, 0, sizeof hints); 153 memset(&hints, 0, sizeof hints);
154 hints.ai_family = AF_UNSPEC; 154 hints.ai_family = AF_UNSPEC;
155 hints.ai_flags = AI_NUMERICHOST; 155 hints.ai_flags = AI_NUMERICHOST;
156 if (getaddrinfo(cp, NULL, &hints, &ai) == 0) 156 if (getaddrinfo(cp, NULL, &hints, &ai) == 0)
157 sa = ai->ai_addr; 157 sa = ai->ai_addr;
158 else 158 else
159 goto fail; 159 goto fail;
160 } 160 }
161 161

cvs diff -r1.130 -r1.131 src/usr.sbin/mountd/mountd.c (expand / switch to unified diff)

--- src/usr.sbin/mountd/mountd.c 2018/01/09 03:31:13 1.130
+++ src/usr.sbin/mountd/mountd.c 2020/04/23 00:22:01 1.131
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: mountd.c,v 1.130 2018/01/09 03:31:13 christos Exp $ */ 1/* $NetBSD: mountd.c,v 1.131 2020/04/23 00:22:01 joerg Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1989, 1993 4 * Copyright (c) 1989, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Herb Hasler and Rick Macklem at The University of Guelph. 8 * Herb Hasler and Rick Macklem at The University of Guelph.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -32,27 +32,27 @@ @@ -32,27 +32,27 @@
32 * SUCH DAMAGE. 32 * SUCH DAMAGE.
33 */ 33 */
34 34
35#include <sys/cdefs.h> 35#include <sys/cdefs.h>
36#ifndef lint 36#ifndef lint
37__COPYRIGHT("@(#) Copyright (c) 1989, 1993\ 37__COPYRIGHT("@(#) Copyright (c) 1989, 1993\
38 The Regents of the University of California. All rights reserved."); 38 The Regents of the University of California. All rights reserved.");
39#endif /* not lint */ 39#endif /* not lint */
40 40
41#ifndef lint 41#ifndef lint
42#if 0 42#if 0
43static char sccsid[] = "@(#)mountd.c 8.15 (Berkeley) 5/1/95"; 43static char sccsid[] = "@(#)mountd.c 8.15 (Berkeley) 5/1/95";
44#else 44#else
45__RCSID("$NetBSD: mountd.c,v 1.130 2018/01/09 03:31:13 christos Exp $"); 45__RCSID("$NetBSD: mountd.c,v 1.131 2020/04/23 00:22:01 joerg Exp $");
46#endif 46#endif
47#endif /* not lint */ 47#endif /* not lint */
48 48
49#include <sys/param.h> 49#include <sys/param.h>
50#include <sys/file.h> 50#include <sys/file.h>
51#include <sys/ioctl.h> 51#include <sys/ioctl.h>
52#include <sys/mount.h> 52#include <sys/mount.h>
53#include <sys/socket.h> 53#include <sys/socket.h>
54#include <sys/stat.h> 54#include <sys/stat.h>
55#include <syslog.h> 55#include <syslog.h>
56#include <sys/ucred.h> 56#include <sys/ucred.h>
57 57
58#include <rpc/rpc.h> 58#include <rpc/rpc.h>
@@ -228,27 +228,27 @@ static struct grouplist *grphead; @@ -228,27 +228,27 @@ static struct grouplist *grphead;
228static const char *exname; 228static const char *exname;
229static struct uucred def_anon = { 229static struct uucred def_anon = {
230 1, 230 1,
231 (uid_t) -2, 231 (uid_t) -2,
232 (gid_t) -2, 232 (gid_t) -2,
233 0, 233 0,
234 { 0 } 234 { 0 }
235}; 235};
236 236
237int opt_flags; 237int opt_flags;
238static int have_v6 = 1; 238static int have_v6 = 1;
239const int ninumeric = NI_NUMERICHOST; 239const int ninumeric = NI_NUMERICHOST;
240 240
241int debug = DEBUGGING; 241int mountd_debug = DEBUGGING;
242#if 0 242#if 0
243static void SYSLOG(int, const char *,...); 243static void SYSLOG(int, const char *,...);
244#endif 244#endif
245 245
246/* 246/*
247 * If this is non-zero, -noresvport and -noresvmnt are implied for 247 * If this is non-zero, -noresvport and -noresvmnt are implied for
248 * each export. 248 * each export.
249 */ 249 */
250static int noprivports; 250static int noprivports;
251 251
252#ifdef MOUNTD_RUMP 252#ifdef MOUNTD_RUMP
253#define C2FD(_c_) ((int)(uintptr_t)(_c_)) 253#define C2FD(_c_) ((int)(uintptr_t)(_c_))
254static int 254static int
@@ -359,27 +359,27 @@ main(int argc, char **argv) @@ -359,27 +359,27 @@ main(int argc, char **argv)
359 while ((c = getopt(argc, argv, "dNnrp:" ADDOPTS)) != -1) 359 while ((c = getopt(argc, argv, "dNnrp:" ADDOPTS)) != -1)
360 switch (c) { 360 switch (c) {
361#ifdef IPSEC 361#ifdef IPSEC
362 case 'P': 362 case 'P':
363 if (ipsecsetup_test(policy = optarg)) 363 if (ipsecsetup_test(policy = optarg))
364 errx(1, "Invalid ipsec policy `%s'", policy); 364 errx(1, "Invalid ipsec policy `%s'", policy);
365 break; 365 break;
366#endif 366#endif
367 case 'p': 367 case 'p':
368 /* A forced port "0" will dynamically allocate a port */ 368 /* A forced port "0" will dynamically allocate a port */
369 forcedport = atoi(optarg); 369 forcedport = atoi(optarg);
370 break; 370 break;
371 case 'd': 371 case 'd':
372 debug = 1; 372 mountd_debug = 1;
373 break; 373 break;
374 case 'N': 374 case 'N':
375 noprivports = 1; 375 noprivports = 1;
376 break; 376 break;
377 /* Compatibility */ 377 /* Compatibility */
378 case 'n': 378 case 'n':
379 case 'r': 379 case 'r':
380 break; 380 break;
381 default: 381 default:
382 fprintf(stderr, "Usage: %s [-dN]" 382 fprintf(stderr, "Usage: %s [-dN]"
383#ifdef IPSEC 383#ifdef IPSEC
384 " [-P policy]" 384 " [-P policy]"
385#endif 385#endif
@@ -404,36 +404,36 @@ main(int argc, char **argv) @@ -404,36 +404,36 @@ main(int argc, char **argv)
404 pthread_t ptdummy; 404 pthread_t ptdummy;
405  405
406 svc_fdset_init(SVC_FDSET_MT); 406 svc_fdset_init(SVC_FDSET_MT);
407 407
408 sem_init(&exportsem, 0, 0); 408 sem_init(&exportsem, 0, 0);
409 pthread_create(&ptdummy, NULL, exportlist_thread, NULL); 409 pthread_create(&ptdummy, NULL, exportlist_thread, NULL);
410 exname = _PATH_EXPORTS; 410 exname = _PATH_EXPORTS;
411 have_v6 = 0; 411 have_v6 = 0;
412 (void)signal(SIGHUP, signal_get_exportlist); 412 (void)signal(SIGHUP, signal_get_exportlist);
413#endif 413#endif
414 grphead = NULL; 414 grphead = NULL;
415 exphead = NULL; 415 exphead = NULL;
416 mlhead = NULL; 416 mlhead = NULL;
417 openlog("mountd", LOG_PID | (debug ? LOG_PERROR : 0), LOG_DAEMON); 417 openlog("mountd", LOG_PID | (mountd_debug ? LOG_PERROR : 0), LOG_DAEMON);
418 (void)signal(SIGSYS, no_nfs); 418 (void)signal(SIGSYS, no_nfs);
419 419
420 if (debug) 420 if (mountd_debug)
421 (void)fprintf(stderr, "Getting export list.\n"); 421 (void)fprintf(stderr, "Getting export list.\n");
422 get_exportlist(0); 422 get_exportlist(0);
423 if (debug) 423 if (mountd_debug)
424 (void)fprintf(stderr, "Getting mount list.\n"); 424 (void)fprintf(stderr, "Getting mount list.\n");
425 get_mountlist(); 425 get_mountlist();
426 if (debug) 426 if (mountd_debug)
427 (void)fprintf(stderr, "Here we go.\n"); 427 (void)fprintf(stderr, "Here we go.\n");
428 (void)signal(SIGTERM, send_umntall); 428 (void)signal(SIGTERM, send_umntall);
429 429
430 rpcb_unset(RPCPROG_MNT, RPCMNT_VER1, NULL); 430 rpcb_unset(RPCPROG_MNT, RPCMNT_VER1, NULL);
431 rpcb_unset(RPCPROG_MNT, RPCMNT_VER3, NULL); 431 rpcb_unset(RPCPROG_MNT, RPCMNT_VER3, NULL);
432 432
433 udpsock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); 433 udpsock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
434 tcpsock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); 434 tcpsock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
435 udp6sock = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP); 435 udp6sock = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
436 tcp6sock = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP); 436 tcp6sock = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
437 437
438 /* 438 /*
439 * We're doing host-based access checks here, so don't allow 439 * We're doing host-based access checks here, so don't allow
@@ -537,27 +537,27 @@ main(int argc, char **argv) @@ -537,27 +537,27 @@ main(int argc, char **argv)
537 syslog(LOG_WARNING, "can't register TCP6 service"); 537 syslog(LOG_WARNING, "can't register TCP6 service");
538 else 538 else
539 xcreated++; 539 xcreated++;
540 } else 540 } else
541 syslog(LOG_WARNING, "can't create TCP6 service"); 541 syslog(LOG_WARNING, "can't create TCP6 service");
542  542
543 } 543 }
544 544
545 if (xcreated == 0) { 545 if (xcreated == 0) {
546 syslog(LOG_ERR, "could not create any services"); 546 syslog(LOG_ERR, "could not create any services");
547 exit(1); 547 exit(1);
548 } 548 }
549 549
550 if (debug == 0) { 550 if (mountd_debug == 0) {
551 daemon(0, 0); 551 daemon(0, 0);
552 (void)signal(SIGINT, SIG_IGN); 552 (void)signal(SIGINT, SIG_IGN);
553 (void)signal(SIGQUIT, SIG_IGN); 553 (void)signal(SIGQUIT, SIG_IGN);
554 } 554 }
555 pidfile(NULL); 555 pidfile(NULL);
556#ifdef MOUNTD_RUMP 556#ifdef MOUNTD_RUMP
557 sem_post(&gensem); 557 sem_post(&gensem);
558#endif 558#endif
559 svc_run(); 559 svc_run();
560 syslog(LOG_ERR, "Mountd died"); 560 syslog(LOG_ERR, "Mountd died");
561 exit(1); 561 exit(1);
562} 562}
563 563
@@ -602,60 +602,60 @@ mntsrv(struct svc_req *rqstp, SVCXPRT *t @@ -602,60 +602,60 @@ mntsrv(struct svc_req *rqstp, SVCXPRT *t
602 } 602 }
603 lookup_failed = getnameinfo(saddr, saddr->sa_len, host, sizeof host,  603 lookup_failed = getnameinfo(saddr, saddr->sa_len, host, sizeof host,
604 NULL, 0, 0); 604 NULL, 0, 0);
605 if (getnameinfo(saddr, saddr->sa_len, numerichost, 605 if (getnameinfo(saddr, saddr->sa_len, numerichost,
606 sizeof numerichost, NULL, 0, ninumeric) != 0) 606 sizeof numerichost, NULL, 0, ninumeric) != 0)
607 strlcpy(numerichost, "?", sizeof(numerichost)); 607 strlcpy(numerichost, "?", sizeof(numerichost));
608 ret = 0; 608 ret = 0;
609 switch (rqstp->rq_proc) { 609 switch (rqstp->rq_proc) {
610 case NULLPROC: 610 case NULLPROC:
611 if (!svc_sendreply(transp, (xdrproc_t)xdr_void, NULL)) 611 if (!svc_sendreply(transp, (xdrproc_t)xdr_void, NULL))
612 syslog(LOG_ERR, "Can't send reply"); 612 syslog(LOG_ERR, "Can't send reply");
613 return; 613 return;
614 case MOUNTPROC_MNT: 614 case MOUNTPROC_MNT:
615 if (debug) 615 if (mountd_debug)
616 fprintf(stderr, 616 fprintf(stderr,
617 "got mount request from %s\n", numerichost); 617 "got mount request from %s\n", numerichost);
618 if (!svc_getargs(transp, xdr_dir, rpcpath)) { 618 if (!svc_getargs(transp, xdr_dir, rpcpath)) {
619 if (debug) 619 if (mountd_debug)
620 fprintf(stderr, "-> garbage args\n"); 620 fprintf(stderr, "-> garbage args\n");
621 svcerr_decode(transp); 621 svcerr_decode(transp);
622 return; 622 return;
623 } 623 }
624 if (debug) 624 if (mountd_debug)
625 fprintf(stderr, 625 fprintf(stderr,
626 "-> rpcpath: %s\n", rpcpath); 626 "-> rpcpath: %s\n", rpcpath);
627 /* 627 /*
628 * Get the real pathname and make sure it is a file or 628 * Get the real pathname and make sure it is a file or
629 * directory that exists. 629 * directory that exists.
630 */ 630 */
631 if ( 631 if (
632#ifndef MOUNTD_RUMP 632#ifndef MOUNTD_RUMP
633 realpath(rpcpath, rdirpath) == NULL || 633 realpath(rpcpath, rdirpath) == NULL ||
634#else 634#else
635 strcpy(rdirpath, rpcpath) == NULL || 635 strcpy(rdirpath, rpcpath) == NULL ||
636#endif 636#endif
637 stat(rdirpath, &stb) < 0 || 637 stat(rdirpath, &stb) < 0 ||
638 (!S_ISDIR(stb.st_mode) && !S_ISREG(stb.st_mode)) || 638 (!S_ISDIR(stb.st_mode) && !S_ISREG(stb.st_mode)) ||
639 statvfs1(rdirpath, &fsb, ST_WAIT) < 0) { 639 statvfs1(rdirpath, &fsb, ST_WAIT) < 0) {
640 (void)chdir("/"); /* Just in case realpath doesn't */ 640 (void)chdir("/"); /* Just in case realpath doesn't */
641 if (debug) 641 if (mountd_debug)
642 (void)fprintf(stderr, "-> stat failed on %s\n", 642 (void)fprintf(stderr, "-> stat failed on %s\n",
643 rdirpath); 643 rdirpath);
644 if (!svc_sendreply(transp, (xdrproc_t)xdr_long, (caddr_t) &bad)) 644 if (!svc_sendreply(transp, (xdrproc_t)xdr_long, (caddr_t) &bad))
645 syslog(LOG_ERR, "Can't send reply"); 645 syslog(LOG_ERR, "Can't send reply");
646 return; 646 return;
647 } 647 }
648 if (debug) 648 if (mountd_debug)
649 fprintf(stderr, 649 fprintf(stderr,
650 "-> dirpath: %s\n", rdirpath); 650 "-> dirpath: %s\n", rdirpath);
651 /* Check in the exports list */ 651 /* Check in the exports list */
652 (void)sigprocmask(SIG_BLOCK, &sighup_mask, NULL); 652 (void)sigprocmask(SIG_BLOCK, &sighup_mask, NULL);
653 ep = ex_search(&fsb.f_fsidx); 653 ep = ex_search(&fsb.f_fsidx);
654 hostset = defset = 0; 654 hostset = defset = 0;
655 if (ep && (chk_host(ep->ex_defdir, saddr, &defset, 655 if (ep && (chk_host(ep->ex_defdir, saddr, &defset,
656 &hostset) || ((dp = dirp_search(ep->ex_dirl, rdirpath)) && 656 &hostset) || ((dp = dirp_search(ep->ex_dirl, rdirpath)) &&
657 chk_host(dp, saddr, &defset, &hostset)) || 657 chk_host(dp, saddr, &defset, &hostset)) ||
658 (defset && scan_tree(ep->ex_defdir, saddr) == 0 && 658 (defset && scan_tree(ep->ex_defdir, saddr) == 0 &&
659 scan_tree(ep->ex_dirl, saddr) == 0))) { 659 scan_tree(ep->ex_dirl, saddr) == 0))) {
660 if ((hostset & DP_HOSTSET) == 0) { 660 if ((hostset & DP_HOSTSET) == 0) {
661 hostset = defset; 661 hostset = defset;
@@ -686,27 +686,27 @@ mntsrv(struct svc_req *rqstp, SVCXPRT *t @@ -686,27 +686,27 @@ mntsrv(struct svc_req *rqstp, SVCXPRT *t
686 bad = EINVAL; /* XXX */ 686 bad = EINVAL; /* XXX */
687 if (!svc_sendreply(transp, (xdrproc_t)xdr_long, 687 if (!svc_sendreply(transp, (xdrproc_t)xdr_long,
688 (char *)&bad)) 688 (char *)&bad))
689 syslog(LOG_ERR, "Can't send reply"); 689 syslog(LOG_ERR, "Can't send reply");
690 goto out; 690 goto out;
691 } 691 }
692 fhr.fhr_fhsize = fh_size; 692 fhr.fhr_fhsize = fh_size;
693 if (!svc_sendreply(transp, (xdrproc_t)xdr_fhs, (char *) &fhr)) 693 if (!svc_sendreply(transp, (xdrproc_t)xdr_fhs, (char *) &fhr))
694 syslog(LOG_ERR, "Can't send reply"); 694 syslog(LOG_ERR, "Can't send reply");
695 if (!lookup_failed) 695 if (!lookup_failed)
696 add_mlist(host, rdirpath, hostset); 696 add_mlist(host, rdirpath, hostset);
697 else 697 else
698 add_mlist(numerichost, rdirpath, hostset); 698 add_mlist(numerichost, rdirpath, hostset);
699 if (debug) 699 if (mountd_debug)
700 (void)fprintf(stderr, "Mount successful.\n"); 700 (void)fprintf(stderr, "Mount successful.\n");
701 } else { 701 } else {
702 if (!svc_sendreply(transp, (xdrproc_t)xdr_long, (caddr_t) &bad)) 702 if (!svc_sendreply(transp, (xdrproc_t)xdr_long, (caddr_t) &bad))
703 syslog(LOG_ERR, "Can't send reply"); 703 syslog(LOG_ERR, "Can't send reply");
704 } 704 }
705out: 705out:
706 (void)sigprocmask(SIG_UNBLOCK, &sighup_mask, NULL); 706 (void)sigprocmask(SIG_UNBLOCK, &sighup_mask, NULL);
707 return; 707 return;
708 case MOUNTPROC_DUMP: 708 case MOUNTPROC_DUMP:
709 if (!svc_sendreply(transp, (xdrproc_t)xdr_mlist, NULL)) 709 if (!svc_sendreply(transp, (xdrproc_t)xdr_mlist, NULL))
710 syslog(LOG_ERR, "Can't send reply"); 710 syslog(LOG_ERR, "Can't send reply");
711 return; 711 return;
712 case MOUNTPROC_UMNT: 712 case MOUNTPROC_UMNT:
@@ -982,32 +982,32 @@ parse_directory(const char *line, size_t @@ -982,32 +982,32 @@ parse_directory(const char *line, size_t
982 line, (unsigned long)lineno); 982 line, (unsigned long)lineno);
983 return 0; 983 return 0;
984 } 984 }
985 } else { 985 } else {
986 /* 986 /*
987 * See if this directory is already 987 * See if this directory is already
988 * in the list. 988 * in the list.
989 */ 989 */
990 *ep = ex_search(&fsp->f_fsidx); 990 *ep = ex_search(&fsp->f_fsidx);
991 if (*ep == NULL) { 991 if (*ep == NULL) {
992 *ep = get_exp(); 992 *ep = get_exp();
993 (*ep)->ex_fs = fsp->f_fsidx; 993 (*ep)->ex_fs = fsp->f_fsidx;
994 (*ep)->ex_fsdir = estrdup(fsp->f_mntonname); 994 (*ep)->ex_fsdir = estrdup(fsp->f_mntonname);
995 if (debug) 995 if (mountd_debug)
996 (void)fprintf(stderr, 996 (void)fprintf(stderr,
997 "Making new ep fs=0x%x,0x%x\n", 997 "Making new ep fs=0x%x,0x%x\n",
998 fsp->f_fsidx.__fsid_val[0], fsp->f_fsidx.__fsid_val[1]); 998 fsp->f_fsidx.__fsid_val[0], fsp->f_fsidx.__fsid_val[1]);
999 } else { 999 } else {
1000 if (debug) 1000 if (mountd_debug)
1001 (void)fprintf(stderr, 1001 (void)fprintf(stderr,
1002 "Found ep fs=0x%x,0x%x\n", 1002 "Found ep fs=0x%x,0x%x\n",
1003 fsp->f_fsidx.__fsid_val[0], fsp->f_fsidx.__fsid_val[1]); 1003 fsp->f_fsidx.__fsid_val[0], fsp->f_fsidx.__fsid_val[1]);
1004 } 1004 }
1005 } 1005 }
1006 1006
1007 return 1; 1007 return 1;
1008} 1008}
1009 1009
1010 1010
1011/* 1011/*
1012 * Get the export list 1012 * Get the export list
1013 */ 1013 */
@@ -1068,34 +1068,34 @@ get_exportlist(int n) @@ -1068,34 +1068,34 @@ get_exportlist(int n)
1068 1068
1069 fsp++; 1069 fsp++;
1070 } 1070 }
1071 1071
1072 /* 1072 /*
1073 * Read in the exports file and build the list, calling 1073 * Read in the exports file and build the list, calling
1074 * mount() as we go along to push the export rules into the kernel. 1074 * mount() as we go along to push the export rules into the kernel.
1075 */ 1075 */
1076 if ((exp_file = fopen(exname, "r")) == NULL) { 1076 if ((exp_file = fopen(exname, "r")) == NULL) {
1077 /* 1077 /*
1078 * Don't exit here; we can still reload the config 1078 * Don't exit here; we can still reload the config
1079 * after a SIGHUP. 1079 * after a SIGHUP.
1080 */ 1080 */
1081 if (debug) 1081 if (mountd_debug)
1082 (void)fprintf(stderr, "Can't open %s: %s\n", exname, 1082 (void)fprintf(stderr, "Can't open %s: %s\n", exname,
1083 strerror(errno)); 1083 strerror(errno));
1084 return; 1084 return;
1085 } 1085 }
1086 dirhead = NULL; 1086 dirhead = NULL;
1087 while ((line = fparseln(exp_file, &len, &lineno, NULL, 0)) != NULL) { 1087 while ((line = fparseln(exp_file, &len, &lineno, NULL, 0)) != NULL) {
1088 if (debug) 1088 if (mountd_debug)
1089 (void)fprintf(stderr, "Got line %s\n", line); 1089 (void)fprintf(stderr, "Got line %s\n", line);
1090 cp = line; 1090 cp = line;
1091 nextfield(&cp, &endcp); 1091 nextfield(&cp, &endcp);
1092 if (cp == endcp) 1092 if (cp == endcp)
1093 goto nextline; /* skip empty line */ 1093 goto nextline; /* skip empty line */
1094 /* 1094 /*
1095 * Set defaults. 1095 * Set defaults.
1096 */ 1096 */
1097 has_host = FALSE; 1097 has_host = FALSE;
1098 anon = def_anon; 1098 anon = def_anon;
1099 exflags = MNT_EXPORTED; 1099 exflags = MNT_EXPORTED;
1100 got_nondir = 0; 1100 got_nondir = 0;
1101 opt_flags = 0; 1101 opt_flags = 0;
@@ -1120,27 +1120,27 @@ get_exportlist(int n) @@ -1120,27 +1120,27 @@ get_exportlist(int n)
1120 goto badline; 1120 goto badline;
1121 } 1121 }
1122 switch (*cp) { 1122 switch (*cp) {
1123 case '-': 1123 case '-':
1124 /* 1124 /*
1125 * Option 1125 * Option
1126 */ 1126 */
1127 if (ep == NULL) { 1127 if (ep == NULL) {
1128 syslog(LOG_ERR, 1128 syslog(LOG_ERR,
1129 "\"%s\", line %ld: No current export list", 1129 "\"%s\", line %ld: No current export list",
1130 line, (unsigned long)lineno); 1130 line, (unsigned long)lineno);
1131 goto badline; 1131 goto badline;
1132 } 1132 }
1133 if (debug) 1133 if (mountd_debug)
1134 (void)fprintf(stderr, "doing opt %s\n", 1134 (void)fprintf(stderr, "doing opt %s\n",
1135 cp); 1135 cp);
1136 got_nondir = 1; 1136 got_nondir = 1;
1137 if (do_opt(line, lineno, &cp, &endcp, ep, grp, 1137 if (do_opt(line, lineno, &cp, &endcp, ep, grp,
1138 &has_host, &exflags, &anon)) 1138 &has_host, &exflags, &anon))
1139 goto badline; 1139 goto badline;
1140 break; 1140 break;
1141 1141
1142 case '/': 1142 case '/':
1143 /* 1143 /*
1144 * Directory 1144 * Directory
1145 */ 1145 */
1146 savedc = *endcp; 1146 savedc = *endcp;
@@ -1174,27 +1174,27 @@ get_exportlist(int n) @@ -1174,27 +1174,27 @@ get_exportlist(int n)
1174 *endcp = savedc; 1174 *endcp = savedc;
1175 break; 1175 break;
1176 } 1176 }
1177 1177
1178 cp = endcp; 1178 cp = endcp;
1179 nextfield(&cp, &endcp); 1179 nextfield(&cp, &endcp);
1180 len = endcp - cp; 1180 len = endcp - cp;
1181 } 1181 }
1182 if (check_options(line, lineno, dirhead)) 1182 if (check_options(line, lineno, dirhead))
1183 goto badline; 1183 goto badline;
1184 1184
1185 if (!has_host) { 1185 if (!has_host) {
1186 grp->gr_type = GT_HOST; 1186 grp->gr_type = GT_HOST;
1187 if (debug) 1187 if (mountd_debug)
1188 (void)fprintf(stderr, 1188 (void)fprintf(stderr,
1189 "Adding a default entry\n"); 1189 "Adding a default entry\n");
1190 /* add a default group and make the grp list NULL */ 1190 /* add a default group and make the grp list NULL */
1191 ai = emalloc(sizeof(struct addrinfo)); 1191 ai = emalloc(sizeof(struct addrinfo));
1192 ai->ai_flags = 0; 1192 ai->ai_flags = 0;
1193 ai->ai_family = AF_INET; /* XXXX */ 1193 ai->ai_family = AF_INET; /* XXXX */
1194 ai->ai_socktype = SOCK_DGRAM; 1194 ai->ai_socktype = SOCK_DGRAM;
1195 /* setting the length to 0 will match anything */ 1195 /* setting the length to 0 will match anything */
1196 ai->ai_addrlen = 0; 1196 ai->ai_addrlen = 0;
1197 ai->ai_flags = AI_CANONNAME; 1197 ai->ai_flags = AI_CANONNAME;
1198 ai->ai_canonname = estrdup("Default"); 1198 ai->ai_canonname = estrdup("Default");
1199 ai->ai_addr = NULL; 1199 ai->ai_addr = NULL;
1200 ai->ai_next = NULL; 1200 ai->ai_next = NULL;
@@ -1472,27 +1472,27 @@ dirp_search(struct dirlist *dp, char *di @@ -1472,27 +1472,27 @@ dirp_search(struct dirlist *dp, char *di
1472 * order (big endian). 1472 * order (big endian).
1473 */ 1473 */
1474static int 1474static int
1475bitcmp(void *dst, void *src, int bitlen) 1475bitcmp(void *dst, void *src, int bitlen)
1476{ 1476{
1477 int i; 1477 int i;
1478 u_int8_t *p1 = dst, *p2 = src; 1478 u_int8_t *p1 = dst, *p2 = src;
1479 u_int8_t bitmask; 1479 u_int8_t bitmask;
1480 int bytelen, bitsleft; 1480 int bytelen, bitsleft;
1481 1481
1482 bytelen = bitlen / 8; 1482 bytelen = bitlen / 8;
1483 bitsleft = bitlen % 8; 1483 bitsleft = bitlen % 8;
1484 1484
1485 if (debug) { 1485 if (mountd_debug) {
1486 printf("comparing:\n"); 1486 printf("comparing:\n");
1487 for (i = 0; i < (bitsleft ? bytelen + 1 : bytelen); i++) 1487 for (i = 0; i < (bitsleft ? bytelen + 1 : bytelen); i++)
1488 printf("%02x", p1[i]); 1488 printf("%02x", p1[i]);
1489 printf("\n"); 1489 printf("\n");
1490 for (i = 0; i < (bitsleft ? bytelen + 1 : bytelen); i++) 1490 for (i = 0; i < (bitsleft ? bytelen + 1 : bytelen); i++)
1491 printf("%02x", p2[i]); 1491 printf("%02x", p2[i]);
1492 printf("\n"); 1492 printf("\n");
1493 } 1493 }
1494 1494
1495 for (i = 0; i < bytelen; i++) { 1495 for (i = 0; i < bytelen; i++) {
1496 if (*p1 != *p2) 1496 if (*p1 != *p2)
1497 return 1; 1497 return 1;
1498 p1++; 1498 p1++;
@@ -1745,27 +1745,27 @@ do_opt(const char *line, size_t lineno,  @@ -1745,27 +1745,27 @@ do_opt(const char *line, size_t lineno,
1745 } else if (cpoptarg && (!strcmp(cpopt, "mask") || 1745 } else if (cpoptarg && (!strcmp(cpopt, "mask") ||
1746 !strcmp(cpopt, "m"))) { 1746 !strcmp(cpopt, "m"))) {
1747 if (get_net(cpoptarg, &grp->gr_ptr.gt_net, 1)) { 1747 if (get_net(cpoptarg, &grp->gr_ptr.gt_net, 1)) {
1748 syslog(LOG_ERR, 1748 syslog(LOG_ERR,
1749 "\"%s\", line %ld: Bad mask: %s", 1749 "\"%s\", line %ld: Bad mask: %s",
1750 line, (unsigned long)lineno, cpoptarg); 1750 line, (unsigned long)lineno, cpoptarg);
1751 return (1); 1751 return (1);
1752 } 1752 }
1753 usedarg++; 1753 usedarg++;
1754 opt_flags |= OP_MASK; 1754 opt_flags |= OP_MASK;
1755 } else if (cpoptarg && (!strcmp(cpopt, "network") || 1755 } else if (cpoptarg && (!strcmp(cpopt, "network") ||
1756 !strcmp(cpopt, "n"))) { 1756 !strcmp(cpopt, "n"))) {
1757 if (strchr(cpoptarg, '/') != NULL) { 1757 if (strchr(cpoptarg, '/') != NULL) {
1758 if (debug) 1758 if (mountd_debug)
1759 fprintf(stderr, "setting OP_MASKLEN\n"); 1759 fprintf(stderr, "setting OP_MASKLEN\n");
1760 opt_flags |= OP_MASKLEN; 1760 opt_flags |= OP_MASKLEN;
1761 } 1761 }
1762 if (grp->gr_type != GT_NULL) { 1762 if (grp->gr_type != GT_NULL) {
1763 syslog(LOG_ERR, 1763 syslog(LOG_ERR,
1764 "\"%s\", line %ld: Network/host conflict", 1764 "\"%s\", line %ld: Network/host conflict",
1765 line, (unsigned long)lineno); 1765 line, (unsigned long)lineno);
1766 return (1); 1766 return (1);
1767 } else if (get_net(cpoptarg, &grp->gr_ptr.gt_net, 0)) { 1767 } else if (get_net(cpoptarg, &grp->gr_ptr.gt_net, 0)) {
1768 syslog(LOG_ERR, 1768 syslog(LOG_ERR,
1769 "\"%s\", line %ld: Bad net: %s", 1769 "\"%s\", line %ld: Bad net: %s",
1770 line, (unsigned long)lineno, cpoptarg); 1770 line, (unsigned long)lineno, cpoptarg);
1771 return (1); 1771 return (1);
@@ -1840,27 +1840,27 @@ get_host(const char *line, size_t lineno @@ -1840,27 +1840,27 @@ get_host(const char *line, size_t lineno
1840 return 1; 1840 return 1;
1841 } 1841 }
1842 grp->gr_type = GT_HOST; 1842 grp->gr_type = GT_HOST;
1843 grp->gr_ptr.gt_addrinfo = ai; 1843 grp->gr_ptr.gt_addrinfo = ai;
1844 while (ai != NULL) { 1844 while (ai != NULL) {
1845 if (ai->ai_canonname == NULL) { 1845 if (ai->ai_canonname == NULL) {
1846 if (getnameinfo(ai->ai_addr, ai->ai_addrlen, host, 1846 if (getnameinfo(ai->ai_addr, ai->ai_addrlen, host,
1847 sizeof host, NULL, 0, ninumeric) != 0) 1847 sizeof host, NULL, 0, ninumeric) != 0)
1848 strlcpy(host, "?", sizeof(host)); 1848 strlcpy(host, "?", sizeof(host));
1849 ai->ai_canonname = estrdup(host); 1849 ai->ai_canonname = estrdup(host);
1850 ai->ai_flags |= AI_CANONNAME; 1850 ai->ai_flags |= AI_CANONNAME;
1851 } else 1851 } else
1852 ai->ai_flags &= ~AI_CANONNAME; 1852 ai->ai_flags &= ~AI_CANONNAME;
1853 if (debug) 1853 if (mountd_debug)
1854 (void)fprintf(stderr, "got host %s\n", ai->ai_canonname); 1854 (void)fprintf(stderr, "got host %s\n", ai->ai_canonname);
1855 ai = ai->ai_next; 1855 ai = ai->ai_next;
1856 } 1856 }
1857 return (0); 1857 return (0);
1858} 1858}
1859 1859
1860/* 1860/*
1861 * Free up an exports list component 1861 * Free up an exports list component
1862 */ 1862 */
1863static void 1863static void
1864free_exp(struct exportlist *ep) 1864free_exp(struct exportlist *ep)
1865{ 1865{
1866 1866
@@ -2268,27 +2268,27 @@ free_grp(struct grouplist *grp) @@ -2268,27 +2268,27 @@ free_grp(struct grouplist *grp)
2268 free(grp->gr_ptr.gt_net.nt_name); 2268 free(grp->gr_ptr.gt_net.nt_name);
2269 } 2269 }
2270 free(grp); 2270 free(grp);
2271} 2271}
2272 2272
2273#if 0 2273#if 0
2274static void 2274static void
2275SYSLOG(int pri, const char *fmt,...) 2275SYSLOG(int pri, const char *fmt,...)
2276{ 2276{
2277 va_list ap; 2277 va_list ap;
2278 2278
2279 va_start(ap, fmt); 2279 va_start(ap, fmt);
2280 2280
2281 if (debug) 2281 if (mountd_debug)
2282 vfprintf(stderr, fmt, ap); 2282 vfprintf(stderr, fmt, ap);
2283 else 2283 else
2284 vsyslog(pri, fmt, ap); 2284 vsyslog(pri, fmt, ap);
2285 2285
2286 va_end(ap); 2286 va_end(ap);
2287} 2287}
2288#endif 2288#endif
2289 2289
2290/* 2290/*
2291 * Check options for consistency. 2291 * Check options for consistency.
2292 */ 2292 */
2293static int 2293static int
2294check_options(const char *line, size_t lineno, struct dirlist *dp) 2294check_options(const char *line, size_t lineno, struct dirlist *dp)

cvs diff -r1.3 -r1.4 src/usr.sbin/mountd/mountd.h (expand / switch to unified diff)

--- src/usr.sbin/mountd/mountd.h 2015/12/29 04:30:43 1.3
+++ src/usr.sbin/mountd/mountd.h 2020/04/23 00:22:01 1.4
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: mountd.h,v 1.3 2015/12/29 04:30:43 pgoyette Exp $ */ 1/* $NetBSD: mountd.h,v 1.4 2020/04/23 00:22:01 joerg Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1989, 1993 4 * Copyright (c) 1989, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Herb Hasler and Rick Macklem at The University of Guelph. 8 * Herb Hasler and Rick Macklem at The University of Guelph.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -33,23 +33,23 @@ @@ -33,23 +33,23 @@
33 */ 33 */
34 34
35#define OP_MAPROOT 0x001 35#define OP_MAPROOT 0x001
36#define OP_MAPALL 0x002 36#define OP_MAPALL 0x002
37#define OP_KERB 0x004 37#define OP_KERB 0x004
38#define OP_MASK 0x008 38#define OP_MASK 0x008
39#define OP_NET 0x010 39#define OP_NET 0x010
40#define OP_ALLDIRS 0x040 40#define OP_ALLDIRS 0x040
41#define OP_NORESPORT 0x080 41#define OP_NORESPORT 0x080
42#define OP_NORESMNT 0x100 42#define OP_NORESMNT 0x100
43#define OP_MASKLEN 0x200 43#define OP_MASKLEN 0x200
44 44
45extern int opt_flags; 45extern int opt_flags;
46extern int debug; 46extern int mountd_debug;
47extern const int ninumeric; 47extern const int ninumeric;
48 48
49struct netmsk { 49struct netmsk {
50 struct sockaddr_storage nt_net; 50 struct sockaddr_storage nt_net;
51 int nt_len; 51 int nt_len;
52 char *nt_name; 52 char *nt_name;
53}; 53};
54 54
55int get_net(char *, struct netmsk *, int); 55int get_net(char *, struct netmsk *, int);