Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 7 Sep 2006 15:15:28 GMT
From:      Todd Miller <millert@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 105796 for review
Message-ID:  <200609071515.k87FFSfR024341@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=105796

Change 105796 by millert@millert_g5tower on 2006/09/07 15:14:35

	o Enable failure messages in getmntopts().
	o Enhance mac_label_opt() to support concatenation of multiple
	    '-o label=foo' options.
	o Minor mount(8) modifications.
	o Fix label= option parsing in mount_XXX(8) help utilities.

Affected files ...

.. //depot/projects/trustedbsd/sedarwin8/darwin/diskdev_cmds/disklib/getmntopts.c#2 edit
.. //depot/projects/trustedbsd/sedarwin8/darwin/diskdev_cmds/disklib/maclabel.c#2 edit
.. //depot/projects/trustedbsd/sedarwin8/darwin/diskdev_cmds/disklib/maclabel.h#2 edit
.. //depot/projects/trustedbsd/sedarwin8/darwin/diskdev_cmds/mount.tproj/mount.8#2 edit
.. //depot/projects/trustedbsd/sedarwin8/darwin/diskdev_cmds/mount.tproj/mount.c#2 edit
.. //depot/projects/trustedbsd/sedarwin8/darwin/diskdev_cmds/mount.tproj/mount_ufs.c#2 edit
.. //depot/projects/trustedbsd/sedarwin8/darwin/diskdev_cmds/mount_cd9660.tproj/mount_cd9660.c#2 edit
.. //depot/projects/trustedbsd/sedarwin8/darwin/diskdev_cmds/mount_devfs.tproj/mount_devfs.c#2 edit
.. //depot/projects/trustedbsd/sedarwin8/darwin/diskdev_cmds/mount_fdesc.tproj/Makefile#2 edit
.. //depot/projects/trustedbsd/sedarwin8/darwin/diskdev_cmds/mount_fdesc.tproj/mount_fdesc.c#2 edit
.. //depot/projects/trustedbsd/sedarwin8/darwin/diskdev_cmds/mount_hfs.tproj/mount_hfs.c#2 edit
.. //depot/projects/trustedbsd/sedarwin8/darwin/diskdev_cmds/mount_nfs.tproj/mount_nfs.c#2 edit

Differences ...

==== //depot/projects/trustedbsd/sedarwin8/darwin/diskdev_cmds/disklib/getmntopts.c#2 (text+ko) ====

@@ -65,7 +65,7 @@
 
 #include "mntopts.h"
 
-int getmnt_silent = 1;
+int getmnt_silent = 0;
 
 void
 getmntopts(options, m0, flagp, altflagp)

==== //depot/projects/trustedbsd/sedarwin8/darwin/diskdev_cmds/disklib/maclabel.c#2 (text+ko) ====

@@ -25,6 +25,7 @@
  */
 
 #include <sys/types.h>
+#include <stdlib.h>
 #include <stddef.h>
 #include <string.h>
 
@@ -35,14 +36,43 @@
  * replacing the ':' delimiter with a ','.
  */
 int
-mac_label_opt(void * optarg, mac_t mac)
+mac_label_opt(char *optarg, mac_t mac)
 {
-	char *lstr = NULL;
+	char *ch, *lstr, *ostr;
+	int len;
+
+	/* Prepare for surgery */
+	ostr = strdup(optarg);
+	if (ostr == NULL)
+		return (-1);
+
+	/* Find location of first char after 'label=' */
+	lstr = strcasestr(ostr, "label=");
+	if (lstr == NULL) {
+		free(ostr);
+		return (-1);
+	}
+	lstr += 6;
+
+	/* Terminate after label string */
+	if ((ch = strchr(ostr, ',')) != NULL)
+		*ch = '\0';
+
 	/* Convert the label separator to internal form. */
-	while ((lstr = strchr(optarg, ':')) != NULL)
-		*lstr = ',';
-	lstr = strchr(optarg, '=') + 1;
-	mac->m_buflen = strlen(lstr) + 1;
-	strncpy(mac->m_string, lstr, MAC_MAX_LABEL_BUF_LEN);
+	while ((ch = strchr(lstr, ':')) != NULL)
+		*ch = ',';
+
+	/* Add separator */
+	len = strlen(mac->m_string);
+	if (len > 0) {
+		strncat(mac->m_string, ",", MAC_MAX_LABEL_BUF_LEN - len);
+		len++;
+	}
+		
+	/* Concatenate new label with existing */
+	strncat(mac->m_string, lstr, MAC_MAX_LABEL_BUF_LEN - len);
+	mac->m_buflen = strlen(mac->m_string) + 1;
+
+	free(ostr);
 	return (0);
 }

==== //depot/projects/trustedbsd/sedarwin8/darwin/diskdev_cmds/disklib/maclabel.h#2 (text+ko) ====

@@ -24,4 +24,4 @@
  * SUCH DAMAGE.
  */
 
-int	mac_label_opt(void * optarg, mac_t mac);
+int	mac_label_opt(char *optarg, mac_t mac);

==== //depot/projects/trustedbsd/sedarwin8/darwin/diskdev_cmds/mount.tproj/mount.8#2 (text+ko) ====

@@ -39,7 +39,7 @@
 .Nd mount file systems
 .Sh SYNOPSIS
 .Nm mount
-.Op Fl adfruvw
+.Op Fl Zadfruvw
 .Op Fl t Ar ufs | lfs | external_type
 .Nm mount
 .Op Fl dfruvw
@@ -74,6 +74,9 @@
 .Pp
 The options are as follows:
 .Bl -tag -width indent
+.It Fl Z 
+Display each mount point's MAC label; see
+.Xr maclabel 7 .
 .It Fl a
 All the filesystems described in
 .Xr fstab 5

==== //depot/projects/trustedbsd/sedarwin8/darwin/diskdev_cmds/mount.tproj/mount.c#2 (text+ko) ====

@@ -68,9 +68,11 @@
 #include <string.h>
 #include <unistd.h>
 
+#include <security/mac.h>
+
 #include "pathnames.h"
 
-int debug, verbose;
+int debug, verbose, prlabels;
 
 int	checkvfsname __P((const char *, const char **));
 char   *catopt __P((char *, const char *));
@@ -83,7 +85,7 @@
 void	mangle __P((char *, int *, const char **));
 int	mountfs __P((const char *, const char *, const char *,
 			int, const char *, const char *));
-void	prmount __P((struct statfs *));
+void	prmount __P((struct statfs *, char *));
 void	usage __P((void));
 
 /* From mount_ufs.c. */
@@ -119,6 +121,7 @@
 	const char *mntfromname, **vfslist, *vfstype;
 	struct fstab *fs;
 	struct statfs *mntbuf;
+	mac_t *macbuf;
 	FILE *mountdfp;
 	pid_t pid;
 	int all, ch, i, init_flags, mntsize, rval;
@@ -129,7 +132,7 @@
 	options = NULL;
 	vfslist = NULL;
 	vfstype = "ufs";
-	while ((ch = getopt(argc, argv, "adfo:rwt:uv")) != EOF)
+	while ((ch = getopt(argc, argv, "adfo:rwt:uvZ")) != EOF)
 		switch (ch) {
 		case 'a':
 			all = 1;
@@ -162,6 +165,9 @@
 		case 'w':
 			init_flags &= ~MNT_RDONLY;
 			break;
+		case 'Z':
+			prlabels = 1;
+			break;
 		case '?':
 		default:
 			usage();
@@ -200,12 +206,21 @@
 			}
 			endfsent();
         	} else {
-			if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0)
-				err(1, "getmntinfo");
+			if (prlabels) {
+				if ((mntsize = mac_getmntinfo(&mntbuf, &macbuf, MNT_NOWAIT)) == 0)
+					err(1, "mac_getmntinfo");
+			} else {
+				if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0)
+					err(1, "getmntinfo");
+			}
 			for (i = 0; i < mntsize; i++) {
 				if (checkvfsname(mntbuf[i].f_fstypename, vfslist))
 					continue;
-				prmount(&mntbuf[i]);
+				if (prlabels) {
+					prmount(&mntbuf[i], macbuf[i]->m_string);
+					mac_free(macbuf[i]);
+				} else
+					prmount(&mntbuf[i], NULL);
 			}
 		}
 		exit(rval);
@@ -453,7 +468,7 @@
 				warn("statfs %s", name);
 				return (1);
 			}
-			prmount(&sf);
+			prmount(&sf, NULL);
 		}
 		break;
 	}
@@ -462,8 +477,9 @@
 }
 
 void
-prmount(sfp)
+prmount(sfp, label)
 	struct statfs *sfp;
+	char *label;
 {
 	int flags;
 	struct opt *o;
@@ -485,6 +501,8 @@
 		else
 			(void)printf("%d", sfp->f_owner);
 	}
+	if (label)
+		(void)printf("%slabel=%s", !f++ ? " (" : ", ", label);
 	(void)printf(f ? ")\n" : "\n");
 }
 

==== //depot/projects/trustedbsd/sedarwin8/darwin/diskdev_cmds/mount.tproj/mount_ufs.c#2 (text+ko) ====

@@ -110,6 +110,12 @@
 	mac_t mlabel = NULL;
 	struct mac mac;
 	char labelstr[MAC_MAX_LABEL_BUF_LEN + 1];
+	char *p;
+
+	(void)memset(labelstr, '\0', sizeof(labelstr));
+	(void)memset(&mac, '\0', sizeof(struct mac));
+	mac.m_string = labelstr;
+	mlabel = NULL;
 
 	mntflags = 0;
 	noasync = 0;
@@ -123,11 +129,11 @@
 			if (mntflags & MNT_SYNCHRONOUS)
 				noasync = 1;
 			if (mntflags & MNT_LABEL) {
-				mac.m_string = labelstr;
-				if (mac_label_opt(optarg, &mac) == 0)
-					mlabel = &mac;
-				else
-					usage();
+				p = strcasestr(optarg, "label=");
+				if (p != NULL) {
+					if (mac_label_opt(p, &mac) != 0)
+						usage();
+				}
 			}
 			break;
 		case '?':
@@ -137,6 +143,9 @@
 	argc -= optind;
 	argv += optind;
 
+	if (mntflags & MNT_LABEL)
+		mlabel = &mac;
+
 	if (argc != 2)
 		ufs_usage();
 

==== //depot/projects/trustedbsd/sedarwin8/darwin/diskdev_cmds/mount_cd9660.tproj/mount_cd9660.c#2 (text+ko) ====

@@ -172,13 +172,20 @@
 	int ch, mntflags, opts;
 	char *dev, dir[MAXPATHLEN];
 	int altflg;
-	mac_t mlabel = NULL;
+	mac_t mlabel;
 	struct mac mac;
 	char labelstr[MAC_MAX_LABEL_BUF_LEN + 1];
+	char *p;
 	
 	mntflags = opts = 0;
 	memset(&args, 0, sizeof args);
 	args.ssector = -1;
+	
+	(void)memset(labelstr, '\0', sizeof(labelstr));
+	(void)memset(&mac, '\0', sizeof(struct mac));
+	mac.m_string = labelstr;
+	mlabel = NULL;
+
 	while ((ch = getopt(argc, argv, "egjo:rs:")) != EOF)
 		switch (ch) {
 		case 'e':
@@ -193,11 +200,11 @@
 		case 'o':
 			getmntopts(optarg, mopts, &mntflags, &altflg);
 			if (mntflags & MNT_LABEL) {
-				mac.m_string = labelstr;
-				if (mac_label_opt(optarg, &mac) == 0)
-					mlabel = &mac;
-				else
-					usage();
+				p = strcasestr(optarg, "label=");
+				if (p != NULL) {
+					if (mac_label_opt(optarg, &mac) != 0)
+						usage();
+				}
 			}
 			break;
 		case 'r':
@@ -213,6 +220,9 @@
 	argc -= optind;
 	argv += optind;
 
+	if (mntflags & MNT_LABEL)
+		mlabel = &mac;
+
 	if (argc != 2)
 		usage();
 

==== //depot/projects/trustedbsd/sedarwin8/darwin/diskdev_cmds/mount_devfs.tproj/mount_devfs.c#2 (text+ko) ====

@@ -80,6 +80,7 @@
 
 struct mntopt mopts[] = {
 	MOPT_STDOPTS,
+	MOPT_UPDATE,
 	{ NULL }
 };
 
@@ -92,21 +93,28 @@
 {
 	int ch, mntflags;
 	char dir[MAXPATHLEN];
-	mac_t mlabel = NULL;
+	mac_t mlabel;
 	struct mac mac;
 	char labelstr[MAC_MAX_LABEL_BUF_LEN + 1];
+	char *p;
+
+	(void)memset(labelstr, '\0', sizeof(labelstr));
+	(void)memset(&mac, '\0', sizeof(struct mac));
+	mac.m_string = labelstr;
+	mlabel = NULL;
 
 	mntflags = 0;
+
 	while ((ch = getopt(argc, argv, "o:")) != EOF)
 		switch (ch) {
 		case 'o':
 			getmntopts(optarg, mopts, &mntflags, 0);
 			if (mntflags & MNT_LABEL) {
-				mac.m_string = labelstr;
-				if (mac_label_opt(optarg, &mac) == 0)
-					mlabel = &mac;
-				else
-					usage();
+				p = strcasestr(optarg, "label=");
+				if (p != NULL) {
+					if (mac_label_opt(p, &mac) != 0)
+						usage();
+				}
 			}
 			break;
 		case '?':
@@ -116,6 +124,9 @@
 	argc -= optind;
 	argv += optind;
 
+	if (mntflags & MNT_LABEL)
+		mlabel = &mac;
+
 	if (argc != 2)
 		usage();
 

==== //depot/projects/trustedbsd/sedarwin8/darwin/diskdev_cmds/mount_fdesc.tproj/Makefile#2 (text+ko) ====

@@ -23,7 +23,7 @@
 NEXTSTEP_INSTALLDIR = /sbin
 WINDOWS_INSTALLDIR = /sbin
 PDO_UNIX_INSTALLDIR = /sbin
-LIBS = -ldisk
+LIBS = -ldisk $(LIBMAC)
 DEBUG_LIBS = $(LIBS)
 PROF_LIBS = $(LIBS)
 

==== //depot/projects/trustedbsd/sedarwin8/darwin/diskdev_cmds/mount_fdesc.tproj/mount_fdesc.c#2 (text+ko) ====

@@ -61,6 +61,8 @@
 #include <sys/param.h>
 #include <sys/mount.h>
 
+#include <security/mac.h>
+
 #include <err.h>
 #include <unistd.h>
 #include <stdio.h>
@@ -68,9 +70,11 @@
 #include <string.h>
 
 #include "mntopts.h"
+#include "maclabel.h"
 
 struct mntopt mopts[] = {
 	MOPT_STDOPTS,
+	MOPT_UPDATE,
 	{ NULL }
 };
 
@@ -83,12 +87,28 @@
 {
 	int ch, mntflags;
 	char dir[MAXPATHLEN];
+	mac_t mlabel;
+	struct mac mac;
+	char labelstr[MAC_MAX_LABEL_BUF_LEN + 1];
+	char *p;
+
+	(void)memset(labelstr, '\0', sizeof(labelstr));
+	(void)memset(&mac, '\0', sizeof(struct mac));
+	mac.m_string = labelstr;
+	mlabel = NULL;
 
 	mntflags = 0;
 	while ((ch = getopt(argc, argv, "o:")) != EOF)
 		switch (ch) {
 		case 'o':
 			getmntopts(optarg, mopts, &mntflags, 0);
+			if (mntflags & MNT_LABEL) {
+				p = strcasestr(optarg, "label=");
+				if (p != NULL) {
+					if (mac_label_opt(p, &mac) != 0)
+						usage();
+				}
+			}
 			break;
 		case '?':
 		default:
@@ -97,13 +117,16 @@
 	argc -= optind;
 	argv += optind;
 
+	if (mntflags & MNT_LABEL)
+		mlabel = &mac;
+
 	if (argc != 2)
 		usage();
 
 	if (realpath(argv[1], dir) == NULL)
 		err(1, "realpath %s", dir);
 
-	if (mount("fdesc", dir, mntflags, NULL))
+	if (mac_mount("fdesc", dir, mntflags, NULL, mlabel))
 		err(1, NULL);
 	exit(0);
 }

==== //depot/projects/trustedbsd/sedarwin8/darwin/diskdev_cmds/mount_hfs.tproj/mount_hfs.c#2 (text+ko) ====

@@ -315,13 +315,18 @@
 	struct timeval dummy_timeval; /* gettimeofday() crashes if the first argument is NULL */
 	u_long localCreateTime;
 	struct hfs_mnt_encoding *encp;
-	mac_t mlabel = NULL;
+	mac_t mlabel;
 	struct mac mac;
 	char labelstr[MAC_MAX_LABEL_BUF_LEN + 1];
+	char *p;
 
 	mntflags = 0;
 	encp = NULL;
 	(void)memset(&args, '\0', sizeof(struct hfs_mount_args));
+	(void)memset(labelstr, '\0', sizeof(labelstr));
+	(void)memset(&mac, '\0', sizeof(struct mac));
+	mac.m_string = labelstr;
+	mlabel = NULL;
 
    	/*
    	 * For a mount update, the following args must be explictly
@@ -394,11 +399,11 @@
 #endif
 				};
 				if (mntflags & MNT_LABEL) {
-					mac.m_string = labelstr;
-					if (mac_label_opt(optarg, &mac) == 0)
-						mlabel = &mac;
-					else
-						usage();
+					p = strcasestr(optarg, "label=");
+					if (p != NULL) {
+						if (mac_label_opt(p, &mac) != 0)
+							usage();
+					}
 				}
 			}
 			break;
@@ -420,6 +425,9 @@
 	argc -= optind;
 	argv += optind;
 
+	if (mntflags & MNT_LABEL)
+		mlabel = &mac;
+
 	if (argc != 2) {
 #if DEBUG
 		printf("mount_hfs: ERROR: argc == %d != 2\n", argc);

==== //depot/projects/trustedbsd/sedarwin8/darwin/diskdev_cmds/mount_nfs.tproj/mount_nfs.c#2 (text+ko) ====

@@ -250,7 +250,7 @@
 	struct nfsd_cargs ncd;
 	int mntflags, altflags, i, nfssvc_flag, num;
 	char name[MAXPATHLEN], *p, *p2, *spec;
-	mac_t mlabel = NULL;
+	mac_t mlabel;
 	struct mac mac;
 	char labelstr[MAC_MAX_LABEL_BUF_LEN + 1];
 #ifdef NFSKERB
@@ -265,6 +265,11 @@
 		fprintf(stderr, "Yikes! NFSKERB structs not packed!!\n");
 #endif /* NFSKERB */
 
+	(void)memset(labelstr, '\0', sizeof(labelstr));
+	(void)memset(&mac, '\0', sizeof(struct mac));
+	mac.m_string = labelstr;
+	mlabel = NULL;
+
 	/* drop setuid root privs asap */
 	eff_uid = geteuid();
 	real_uid = getuid();
@@ -347,11 +352,11 @@
 		case 'o':
 			getmntopts(optarg, mopts, &mntflags, &altflags);
 			if (mntflags & MNT_LABEL) {
-				mac.m_string = labelstr;
-				if (mac_label_opt(optarg, &mac) == 0)
-					mlabel = &mac;
-				else
-					usage();
+				p = strcasestr(optarg, "label=");
+				if (p != NULL) {
+					if (mac_label_opt(p, &mac) != 0)
+						usage();
+				}
 			}
 			if(altflags & ALTF_BG)
 				opflags |= BGRND;
@@ -622,6 +627,9 @@
 	argc -= optind;
 	argv += optind;
 
+	if (mntflags & MNT_LABEL)
+		mlabel = &mac;
+
 	if (argc != 2) {
 		usage();
 		/* NOTREACHED */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200609071515.k87FFSfR024341>