From owner-p4-projects@FreeBSD.ORG Wed Nov 5 10:59:16 2003 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 0BAD916A4D0; Wed, 5 Nov 2003 10:59:16 -0800 (PST) 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 BBFB716A4CE for ; Wed, 5 Nov 2003 10:59:15 -0800 (PST) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 198FC43FCB for ; Wed, 5 Nov 2003 10:59:15 -0800 (PST) (envelope-from areisse@nailabs.com) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.12.9/8.12.9) with ESMTP id hA5IxEXJ026741 for ; Wed, 5 Nov 2003 10:59:14 -0800 (PST) (envelope-from areisse@nailabs.com) Received: (from perforce@localhost) by repoman.freebsd.org (8.12.9/8.12.9/Submit) id hA5IxEp6026726 for perforce@freebsd.org; Wed, 5 Nov 2003 10:59:14 -0800 (PST) (envelope-from areisse@nailabs.com) Date: Wed, 5 Nov 2003 10:59:14 -0800 (PST) Message-Id: <200311051859.hA5IxEp6026726@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to areisse@nailabs.com using -f From: Andrew Reisse To: Perforce Change Reviews Subject: PERFORCE change 41470 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 05 Nov 2003 18:59:16 -0000 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 #include #include +#include #include #include @@ -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))