From owner-trustedbsd-cvs@FreeBSD.ORG Thu Sep 7 15:15:59 2006 Return-Path: X-Original-To: trustedbsd-cvs@freebsd.org Delivered-To: trustedbsd-cvs@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id A82BB16A4DE for ; Thu, 7 Sep 2006 15:15:59 +0000 (UTC) (envelope-from owner-perforce@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [209.31.154.42]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5A2CA43D6E for ; Thu, 7 Sep 2006 15:15:42 +0000 (GMT) (envelope-from owner-perforce@freebsd.org) Received: from mx2.freebsd.org (mx2.freebsd.org [216.136.204.119]) by cyrus.watson.org (Postfix) with ESMTP id CCD1046D92 for ; Thu, 7 Sep 2006 11:15:40 -0400 (EDT) Received: from hub.freebsd.org (hub.freebsd.org [216.136.204.18]) by mx2.freebsd.org (Postfix) with ESMTP id ACBCD57CB2; Thu, 7 Sep 2006 15:15:36 +0000 (GMT) (envelope-from owner-perforce@freebsd.org) Received: by hub.freebsd.org (Postfix, from userid 32767) id A477416A4EB; Thu, 7 Sep 2006 15:15:36 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7C80716A4E8 for ; Thu, 7 Sep 2006 15:15:36 +0000 (UTC) (envelope-from millert@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 74D9043D7C for ; Thu, 7 Sep 2006 15:15:28 +0000 (GMT) (envelope-from millert@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.6/8.13.6) with ESMTP id k87FFSN7024344 for ; Thu, 7 Sep 2006 15:15:28 GMT (envelope-from millert@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id k87FFSfR024341 for perforce@freebsd.org; Thu, 7 Sep 2006 15:15:28 GMT (envelope-from millert@freebsd.org) Date: Thu, 7 Sep 2006 15:15:28 GMT Message-Id: <200609071515.k87FFSfR024341@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to millert@freebsd.org using -f From: Todd Miller To: Perforce Change Reviews Cc: Subject: PERFORCE change 105796 for review X-BeenThere: trustedbsd-cvs@FreeBSD.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: TrustedBSD CVS and Perforce commit message list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Sep 2006 15:15:59 -0000 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 +#include #include #include @@ -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 #include +#include + #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 #include +#include + #include #include #include @@ -68,9 +70,11 @@ #include #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 */