git: 58fdd8509cf1 - stable/14 - mountd.c: Add warning messages for administrative controls

From: Rick Macklem <rmacklem_at_FreeBSD.org>
Date: Sun, 14 Apr 2024 01:03:45 UTC
The branch stable/14 has been updated by rmacklem:

URL: https://cgit.FreeBSD.org/src/commit/?id=58fdd8509cf1a6846cc4124c2bfa03d9343ab910

commit 58fdd8509cf1a6846cc4124c2bfa03d9343ab910
Author:     Rick Macklem <rmacklem@FreeBSD.org>
AuthorDate: 2024-03-31 19:00:08 +0000
Commit:     Rick Macklem <rmacklem@FreeBSD.org>
CommitDate: 2024-04-14 01:02:33 +0000

    mountd.c: Add warning messages for administrative controls
    
    When "administrative controls" (which are exports of subdirectories
    within a NFS server's local file system) are used, they export the
    entire local server file system. (The subdirectory only applies to
    the Mount protocol used for NFSv3 mounts.)
    
    To minimize the risk that this causes confusion w.r.t. what is exported
    to NFS client(s), this patch generates warning messages for these.
    Only one message is generated for each server local file system.
    The messages can be silenced via a new "-A" command line option.
    
    The mountd.8 man page will be patched via a separate commit.
    
    (cherry picked from commit fefb7c399b39403e1a31157e925a541f1cc24f0b)
---
 usr.sbin/mountd/mountd.c | 29 ++++++++++++++++++++++++-----
 1 file changed, 24 insertions(+), 5 deletions(-)

diff --git a/usr.sbin/mountd/mountd.c b/usr.sbin/mountd/mountd.c
index 33c19a81a0cf..6583bfbc0ffb 100644
--- a/usr.sbin/mountd/mountd.c
+++ b/usr.sbin/mountd/mountd.c
@@ -143,10 +143,11 @@ struct exportlist {
 	SLIST_ENTRY(exportlist) entries;
 };
 /* ex_flag bits */
-#define	EX_LINKED	0x1
-#define	EX_DONE		0x2
-#define	EX_DEFSET	0x4
-#define	EX_PUBLICFH	0x8
+#define	EX_LINKED	0x01
+#define	EX_DONE		0x02
+#define	EX_DEFSET	0x04
+#define	EX_PUBLICFH	0x08
+#define	EX_ADMINWARN	0x10
 
 SLIST_HEAD(exportlisthead, exportlist);
 
@@ -285,6 +286,7 @@ static char *exnames_default[2] = { _PATH_EXPORTS, NULL };
 static char **exnames;
 static char **hosts = NULL;
 static int force_v2 = 0;
+static int warn_admin = 1;
 static int resvport_only = 1;
 static int nhosts = 0;
 static int dir_only = 1;
@@ -447,11 +449,14 @@ main(int argc, char **argv)
 	else
 		close(s);
 
-	while ((c = getopt(argc, argv, "2deh:lnp:RrS")) != -1)
+	while ((c = getopt(argc, argv, "2Adeh:lnp:RrS")) != -1)
 		switch (c) {
 		case '2':
 			force_v2 = 1;
 			break;
+		case 'A':
+			warn_admin = 0;
+			break;
 		case 'e':
 			/* now a no-op, since this is the default */
 			break;
@@ -1709,6 +1714,20 @@ get_exportlist_one(int passno)
 						fsb.f_fsid.val[1]);
 				    }
 
+				    if (warn_admin != 0 &&
+					(ep->ex_flag & EX_ADMINWARN) == 0 &&
+					strcmp(unvis_dir, fsb.f_mntonname) !=
+					0) {
+					if (debug)
+					    warnx("exporting %s exports entire "
+						"%s file system", unvis_dir,
+						    fsb.f_mntonname);
+					syslog(LOG_ERR, "Warning: exporting %s "
+					    "exports entire %s file system",
+					    unvis_dir, fsb.f_mntonname);
+					ep->ex_flag |= EX_ADMINWARN;
+				    }
+
 				    /*
 				     * Add dirpath to export mount point.
 				     */