Date: Tue, 25 Nov 2003 20:50:07 -0800 (PST) From: Robert Watson <rwatson@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 43050 for review Message-ID: <200311260450.hAQ4o79h067089@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=43050 Change 43050 by rwatson@rwatson_paprika on 2003/11/25 20:49:22 Add "id -M" support; displays the MAC label of the current process in a style similar to the same argument on Trusted IRIX. Affected files ... .. //depot/projects/trustedbsd/mac/usr.bin/id/id.1#2 edit .. //depot/projects/trustedbsd/mac/usr.bin/id/id.c#6 edit Differences ... ==== //depot/projects/trustedbsd/mac/usr.bin/id/id.1#2 (text+ko) ==== @@ -48,6 +48,8 @@ .Fl G Op Fl n .Op Ar user .Nm +.Fl M +.Nm .Fl P .Op Ar user .Nm @@ -78,6 +80,8 @@ .It Fl G Display the different group IDs (effective, real and supplementary) as white-space separated numbers, in no particular order. +.It Fl M +Display the MAC label of the current prorcess. .It Fl P Display the id as a password file entry. .It Fl g ==== //depot/projects/trustedbsd/mac/usr.bin/id/id.c#6 (text+ko) ==== @@ -46,8 +46,10 @@ __FBSDID("$FreeBSD: src/usr.bin/id/id.c,v 1.19 2002/09/04 23:29:02 dwmalone Exp $"); #include <sys/param.h> +#include <sys/mac.h> #include <err.h> +#include <errno.h> #include <grp.h> #include <pwd.h> #include <stdio.h> @@ -59,6 +61,7 @@ void pline(struct passwd *); void pretty(struct passwd *); void group(struct passwd *, int); +void maclabel(void); void usage(void); void user(struct passwd *); struct passwd * @@ -71,10 +74,10 @@ { struct group *gr; struct passwd *pw; - int Gflag, Pflag, ch, gflag, id, nflag, pflag, rflag, uflag; + int Gflag, Mflag, Pflag, ch, gflag, id, nflag, pflag, rflag, uflag; const char *myname; - Gflag = Pflag = gflag = nflag = pflag = rflag = uflag = 0; + Gflag = Mflag = Pflag = gflag = nflag = pflag = rflag = uflag = 0; myname = strrchr(argv[0], '/'); myname = (myname != NULL) ? myname + 1 : argv[0]; @@ -88,11 +91,14 @@ } while ((ch = getopt(argc, argv, - (isgroups || iswhoami) ? "" : "PGgnpru")) != -1) + (isgroups || iswhoami) ? "" : "PGMgnpru")) != -1) switch(ch) { case 'G': Gflag = 1; break; + case 'M': + Mflag = 1; + break; case 'P': Pflag = 1; break; @@ -134,6 +140,9 @@ pw = *argv ? who(*argv) : NULL; + if (Mflag && pw != NULL) + usage(); + if (gflag) { id = pw ? pw->pw_gid : rflag ? getgid() : getegid(); if (nflag && (gr = getgrgid(id))) @@ -157,6 +166,11 @@ exit(0); } + if (Mflag) { + maclabel(); + exit(0); + } + if (Pflag) { pline(pw); exit(0); @@ -317,6 +331,30 @@ (void)printf("\n"); } +void +maclabel(void) +{ + char *string; + mac_t label; + int error; + + error = mac_prepare_process_label(&label); + if (error == -1) + errx(1, "mac_prepare_type: %s", strerror(errno)); + + error = mac_get_proc(label); + if (error == -1) + errx(1, "mac_get_proc: %s", strerror(errno)); + + error = mac_to_text(label, &string); + if (error == -1) + errx(1, "mac_to_text: %s", strerror(errno)); + + (void)printf("%s\n", string); + mac_free(label); + free(string); +} + struct passwd * who(char *u) { @@ -366,6 +404,7 @@ (void)fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n", "usage: id [user]", " id -G [-n] [user]", + " id -M", " id -P [user]", " id -g [-nr] [user]", " id -p [user]",
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200311260450.hAQ4o79h067089>