Date: Wed, 5 Nov 2003 10:59:14 -0800 (PST) From: Andrew Reisse <areisse@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 41470 for review Message-ID: <200311051859.hA5IxEp6026726@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=41470 Change 41470 by areisse@areisse_ibook on 2003/11/05 10:58:27 ls -lZ prints labels Affected files ... .. //depot/projects/trustedbsd/sedarwin/apsl/file_cmds/ls/Makefile#2 edit .. //depot/projects/trustedbsd/sedarwin/apsl/file_cmds/ls/ls.c#2 edit .. //depot/projects/trustedbsd/sedarwin/apsl/file_cmds/ls/ls.h#2 edit .. //depot/projects/trustedbsd/sedarwin/apsl/file_cmds/ls/print.c#2 edit Differences ... ==== //depot/projects/trustedbsd/sedarwin/apsl/file_cmds/ls/Makefile#2 (text+ko) ==== @@ -18,12 +18,11 @@ OTHERSRCS = Makefile Makefile.preamble Makefile.postamble ls.1 - MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles CODE_GEN_STYLE = DYNAMIC MAKEFILE = tool.make NEXTSTEP_INSTALLDIR = /bin -LIBS = +LIBS = ../../../libmac/libmac.a DEBUG_LIBS = $(LIBS) PROF_LIBS = $(LIBS) ==== //depot/projects/trustedbsd/sedarwin/apsl/file_cmds/ls/ls.c#2 (text+ko) ==== @@ -54,6 +54,7 @@ #include <sys/stat.h> #include <sys/ioctl.h> #include <sys/param.h> +#include <sys/mac.h> #include <dirent.h> #include <err.h> @@ -106,6 +107,7 @@ int f_statustime; /* use time of last mode change */ int f_type; /* add type character for non-regular files */ int f_whiteout; /* show whiteout entries */ +int f_label = 0; /* show labels */ int main(argc, argv) @@ -134,7 +136,7 @@ f_listdot = 1; fts_options = FTS_PHYSICAL; - while ((ch = getopt(argc, argv, "1ACFLRSTWacdfgiklnoqrstuxv")) != -1) { + while ((ch = getopt(argc, argv, "1ACFLRSTWacdfgiklZnoqrstuxv")) != -1) { switch (ch) { /* * The -1, -C, -l and -x options all override each other so @@ -228,6 +230,9 @@ case 'v': f_nonprint = 0; break; + case 'Z': + f_label = 1; + break; default: case '?': usage(); @@ -412,11 +417,12 @@ u_int64_t btotal, maxblock, maxsize; int maxinode, maxnlink, maxmajor, maxminor; int bcfile, entries, flen, glen, ulen, maxflags, maxgroup, maxlen; - int maxuser, needstats; + int maxuser, maxlabelstr, needstats, labelstrlen; const char *user, *group; char ubuf[21]="", gbuf[21]="", buf[21]; /* 64 bits == 20 digits, +1 for NUL */ char nuser[12], ngroup[12]; char *flags = NULL; + char *labelstr = NULL; #ifdef __GNUC__ /* This outrageous construct just to shut up a GCC warning. */ @@ -439,7 +445,7 @@ bcfile = 0; maxuser = maxgroup = maxflags = maxlen = 0; btotal = maxblock = maxsize = 0; - maxmajor = maxminor = 0; + maxmajor = maxminor = maxlabelstr = 0; for (cur = list, entries = 0; cur; cur = cur->fts_link) { if (cur->fts_info == FTS_ERR || cur->fts_info == FTS_NS) { warnx("%s: %s", @@ -516,19 +522,85 @@ } else flen = 0; - if ((np = malloc(sizeof(NAMES) + - ulen + glen + flen + 3)) == NULL) - err(1, "%s", ""); + if (f_label) + { + char name[PATH_MAX + 1]; + mac_t label; + int error; + + error = mac_prepare_file_label(&label); + if (error == -1) { + warn("MAC label for %s/%s", + cur->fts_parent->fts_path, + cur->fts_name); + goto label_out; + } + + if (cur->fts_level == FTS_ROOTLEVEL) + snprintf(name, sizeof(name), + "%s", cur->fts_name); + else + snprintf(name, sizeof(name), + "%s/%s", cur->fts_parent->fts_accpath, cur->fts_name); + + /*if (options & FTS_LOGICAL) + error = mac_get_file(name, + label); + else*/ + error = mac_get_link(name, + label); + if (error == -1) { + warn("MAC label for %s/%s", + cur->fts_parent->fts_path, + cur->fts_name); + mac_free(label); + goto label_out; + } + + error = mac_to_text(label, + &labelstr); + if (error == -1) { + warn("MAC label for %s/%s", + cur->fts_parent->fts_path, + cur->fts_name); + mac_free(label); + goto label_out; + } + mac_free(label); +label_out: + if (labelstr == NULL) + labelstr = strdup("-"); + labelstrlen = strlen(labelstr); + if (labelstrlen > maxlabelstr) + maxlabelstr = labelstrlen; + } else + labelstrlen = 0; + + if ((np = malloc(sizeof(NAMES) + labelstrlen + + ulen + glen + flen + 4)) == NULL) + err(1, "malloc"); np->user = &np->data[0]; (void)strcpy(np->user, user); np->group = &np->data[ulen + 1]; (void)strcpy(np->group, group); + if (S_ISCHR(sp->st_mode) || + S_ISBLK(sp->st_mode)) + bcfile = 1; + if (f_flags) { np->flags = &np->data[ulen + glen + 2]; - (void)strcpy(np->flags, flags); + (void)strcpy(np->flags, flags); + free(flags); + } + if (f_label) { + np->label = &np->data[ulen + glen + 2 + + (f_flags ? flen + 1 : 0)]; + (void)strcpy(np->label, labelstr); + free(labelstr); } + cur->fts_pointer = np; } } @@ -541,6 +613,7 @@ d.list = list; d.entries = entries; d.maxlen = maxlen; + d.s_label = maxlabelstr; if (needstats) { d.btotal = btotal; (void)snprintf(buf, sizeof(buf), "%qu", (long long)maxblock); ==== //depot/projects/trustedbsd/sedarwin/apsl/file_cmds/ls/ls.h#2 (text+ko) ==== @@ -51,6 +51,7 @@ extern int f_size; /* list size in short listing */ extern int f_statustime; /* use time of last mode change */ extern int f_type; /* add type character for non-regular files */ +extern int f_label; /* show labels */ typedef struct { FTSENT *list; @@ -66,11 +67,13 @@ int s_user; int s_major; int s_minor; + int s_label; } DISPLAY; typedef struct { char *user; char *group; char *flags; + char *label; char data[1]; } NAMES; ==== //depot/projects/trustedbsd/sedarwin/apsl/file_cmds/ls/print.c#2 (text+ko) ==== @@ -117,6 +117,8 @@ (void)printf("%s %*u %-*s %-*s ", buf, dp->s_nlink, sp->st_nlink, dp->s_user, np->user, dp->s_group, np->group); + if (f_label && np->label) + printf ("%-*s ", dp->s_label, np->label); if (f_flags) (void)printf("%-*s ", dp->s_flags, np->flags); if (S_ISCHR(sp->st_mode) || S_ISBLK(sp->st_mode))
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200311051859.hA5IxEp6026726>