summaryrefslogtreecommitdiffstats
path: root/bin/ls
diff options
context:
space:
mode:
authorgreen <green@FreeBSD.org>2001-11-26 22:21:15 +0000
committergreen <green@FreeBSD.org>2001-11-26 22:21:15 +0000
commitd741ed6f56790f6d4459cd3edc5ca52989829373 (patch)
treec1032133ec49d0a5bd94f26101cdf04f6159d448 /bin/ls
parentd60fa5f434d39572b6ea9de4953a228e3b87d41d (diff)
downloadFreeBSD-src-d741ed6f56790f6d4459cd3edc5ca52989829373.zip
FreeBSD-src-d741ed6f56790f6d4459cd3edc5ca52989829373.tar.gz
Add LOMAC options (the "Z" flag in both cases) to display extra information
in ls(1) and ps(1). Sponsored by: DARPA, NAI Labs
Diffstat (limited to 'bin/ls')
-rw-r--r--bin/ls/Makefile2
-rw-r--r--bin/ls/lomac.c151
-rw-r--r--bin/ls/lomac.h40
-rw-r--r--bin/ls/ls.111
-rw-r--r--bin/ls/ls.c42
-rw-r--r--bin/ls/ls.h3
-rw-r--r--bin/ls/print.c2
-rw-r--r--bin/ls/util.c4
8 files changed, 242 insertions, 13 deletions
diff --git a/bin/ls/Makefile b/bin/ls/Makefile
index a865e7f..a4345ff 100644
--- a/bin/ls/Makefile
+++ b/bin/ls/Makefile
@@ -3,7 +3,7 @@
PROG= ls
-SRCS= cmp.c ls.c print.c util.c
+SRCS= cmp.c ls.c print.c util.c lomac.c
.if !defined(RELEASE_CRUNCH)
CFLAGS+= -DCOLORLS
diff --git a/bin/ls/lomac.c b/bin/ls/lomac.c
new file mode 100644
index 0000000..8dbd76c
--- /dev/null
+++ b/bin/ls/lomac.c
@@ -0,0 +1,151 @@
+/*-
+ * Copyright (c) 2001 Networks Associates Technologies, Inc.
+ * All rights reserved.
+ *
+ * This software was developed for the FreeBSD Project by NAI Labs, the
+ * Security Research Division of Network Associates, Inc. under
+ * DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA
+ * CHATS research program.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id: lomac.c,v 1.5 2001/11/26 19:25:52 bfeldman Exp $
+ * $FreeBSD$
+ */
+
+/*
+ * This file encapsulates ls's use of LOMAC's ioctl interface. ls uses
+ * this interface to determine the LOMAC attributes of files.
+ */
+
+#include <sys/types.h>
+#include <sys/lomacio.h>
+
+#include <err.h>
+#include <fts.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "lomac.h"
+
+#define LOMAC_DEVICE "/dev/lomac"
+
+int devlomac; /* file descriptor for LOMAC_DEVICE */
+struct lomac_fioctl2 ioctl_args;
+
+/* lomac_start()
+ *
+ * in: nothing
+ * out: nothing
+ * return: nothing
+ *
+ * Makes `devlomac' a fd to LOMAC_DEVICE
+ */
+
+void
+lomac_start(void) {
+
+ if ((devlomac = open(LOMAC_DEVICE, O_RDWR)) == -1)
+ err(1, "cannot open %s", LOMAC_DEVICE);
+}
+
+/* lomac_stop()
+ *
+ * in: nothing
+ * out: nothing
+ * return: nothing
+ *
+ * Closes `devlomac', the fd to LOMAC_DEVICE.
+ */
+
+void
+lomac_stop(void) {
+
+ if (close(devlomac) == -1)
+ err(1, "cannot close %s", LOMAC_DEVICE);
+}
+
+/* get_lattr()
+ *
+ * in: ent - FTSENT describing file whose LOMAC attributes we wish to know
+ * out: nothing
+ * return: a string describing `ent's LOMAC attributes
+ *
+ * This function uses LOMAC's ioctl interface to determine the LOMAC
+ * attributes of the file described by `ent'.
+ *
+ * This function dynamically allocates memory for the attribute strings.
+ * The caller is responsible for eventually deallocating these strings.
+ */
+
+char *
+get_lattr(FTSENT *ent) {
+ char *lattr;
+
+#ifdef NOT_NOW
+ printf("p%d n%d\n", ent->fts_pathlen, ent->fts_namelen);
+ printf("ftscycle %x\n", ent->fts_cycle);
+ printf("ftsparent %x\n", ent->fts_parent);
+ printf("ftslink %x\n", ent->fts_link);
+ printf("ftsnumber %x\n", ent->fts_number);
+ printf("ftslevel %x\n", ent->fts_level);
+ if (ent->fts_pathlen > 0)
+ printf("%x : %s\n", ent->fts_path, ent->fts_path);
+ else
+ printf("length 0 path\n");
+ if (ent->fts_namelen > 0)
+ printf("%x : %s\n", ent->fts_name, ent->fts_name);
+ else
+ printf("length 0 name\n");
+#endif
+ /*
+ * We use ent->fts_level to determine whether or not ent->fts_path
+ * is valid. This is a hack, but the FTS code doesn't seem to
+ * NULL the first byte of fts_path or zero fts_pathlen when fts_path
+ * is invalid, so there didn't seem to be a better way of doing it.
+ */
+ if (ent->fts_level > 0) {
+ strncpy(ioctl_args.path, ent->fts_path, MAXPATHLEN - 1);
+ strncat(ioctl_args.path, "/",
+ MAXPATHLEN - strlen(ioctl_args.path) - 1);
+ strncat(ioctl_args.path, ent->fts_accpath,
+ MAXPATHLEN - strlen(ioctl_args.path) - 1);
+ } else
+ strncpy(ioctl_args.path, ent->fts_accpath, MAXPATHLEN - 1);
+ if (ioctl(devlomac, LIOGETFLATTR, &ioctl_args) == -1)
+ err(1, NULL);
+
+ /* we use ioctl_args.path as scratch space to build lattr */
+ if (ioctl_args.flags != 0)
+ asprintf(&lattr, "%d.%x", ioctl_args.level, ioctl_args.flags);
+ else
+ asprintf(&lattr, "%d", ioctl_args.level);
+
+ if (lattr == NULL)
+ err(1, NULL);
+ return (lattr);
+}
diff --git a/bin/ls/lomac.h b/bin/ls/lomac.h
new file mode 100644
index 0000000..8998bd7
--- /dev/null
+++ b/bin/ls/lomac.h
@@ -0,0 +1,40 @@
+/*-
+ * Copyright (c) 2001 Networks Associates Technologies, Inc.
+ * All rights reserved.
+ *
+ * This software was developed for the FreeBSD Project by NAI Labs, the
+ * Security Research Division of Network Associates, Inc. under
+ * DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA
+ * CHATS research program.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id: lomac.h,v 1.3 2001/11/26 19:23:02 bfeldman Exp $
+ * $FreeBSD$
+ */
+
+void lomac_start(void);
+void lomac_stop(void);
+char *get_lattr(FTSENT *);
diff --git a/bin/ls/ls.1 b/bin/ls/ls.1
index 8175980..7d1c04c 100644
--- a/bin/ls/ls.1
+++ b/bin/ls/ls.1
@@ -43,7 +43,7 @@
.Nd list directory contents
.Sh SYNOPSIS
.Nm
-.Op Fl ABCFGHLPRTWabcdfgiklnoqrstu1
+.Op Fl ABCFGHLPRTWZabcdfgiklnoqrstu1
.Op Ar
.Sh DESCRIPTION
For each operand that names a
@@ -122,6 +122,8 @@ Display complete time information for the file, including
month, day, hour, minute, second, and year.
.It Fl W
Display whiteouts when scanning directories.
+.It Fl Z
+Display each file's LOMAC level.
.It Fl a
Include directory entries whose names begin with a
dot (.).
@@ -245,6 +247,7 @@ option is given, the following information
is displayed for each file:
file mode,
number of links, owner name, group name,
+LOMAC level,
number of bytes in the file, abbreviated
month, day-of-month file was last modified,
hour file last modified, minute file last
@@ -535,6 +538,11 @@ The group field is now automatically included in the long listing for
files in order to be compatible with the
.St -p1003.2
specification.
+.Sh FILES
+.Bl -tag -width /dev/lomac -compact
+.It Pa /dev/lomac
+interface used to query the LOMAC LKM
+.El
.Sh SEE ALSO
.Xr chflags 1 ,
.Xr chmod 1 ,
@@ -542,6 +550,7 @@ specification.
.Xr xterm 1 ,
.Xr termcap 5 ,
.Xr symlink 7 ,
+.Xr lomac 4 ,
.Xr sticky 8
.Sh HISTORY
An
diff --git a/bin/ls/ls.c b/bin/ls/ls.c
index 9070205..86253d7 100644
--- a/bin/ls/ls.c
+++ b/bin/ls/ls.c
@@ -70,6 +70,7 @@ static const char rcsid[] =
#include "ls.h"
#include "extern.h"
+#include "lomac.h"
/*
* Upward approximation of the maximum number of characters needed to
@@ -113,6 +114,7 @@ int f_statustime; /* use time of last mode change */
int f_timesort; /* sort by time vice name */
int f_type; /* add type character for non-regular files */
int f_whiteout; /* show whiteout entries */
+int f_lomac; /* show LOMAC attributes */
#ifdef COLORLS
int f_color; /* add type in color for non-regular files */
@@ -163,7 +165,7 @@ main(argc, argv)
f_listdot = 1;
fts_options = FTS_PHYSICAL;
- while ((ch = getopt(argc, argv, "1ABCFGHLPRTWabcdfgiklnoqrstu")) != -1) {
+ while ((ch = getopt(argc, argv, "1ABCFGHLPRTWZabcdfgiklnoqrstu")) != -1) {
switch (ch) {
/*
* The -1, -C and -l options all override each other so shell
@@ -269,6 +271,9 @@ main(argc, argv)
f_octal = 0;
f_octal_escape = 1;
break;
+ case 'Z':
+ f_lomac = 1;
+ break;
default:
case '?':
usage();
@@ -468,11 +473,11 @@ display(p, list)
FTSENT *cur;
NAMES *np;
u_quad_t maxsize;
- u_long btotal, maxblock, maxinode, maxlen, maxnlink;
- int bcfile, flen, glen, ulen, maxflags, maxgroup, maxuser;
+ u_long btotal, maxblock, maxinode, maxlen, maxnlink, maxlattr;
+ int bcfile, flen, glen, ulen, lattrlen, maxflags, maxgroup, maxuser;
char *initmax;
int entries, needstats;
- char *user, *group, *flags;
+ char *user, *group, *flags, *lattr;
char buf[STRBUF_SIZEOF(u_quad_t) + 1];
char ngroup[STRBUF_SIZEOF(uid_t) + 1];
char nuser[STRBUF_SIZEOF(gid_t) + 1];
@@ -517,9 +522,9 @@ display(p, list)
if (initmax2[-1] == ':') strcpy(initmax2, "0");
ninitmax = sscanf(jinitmax,
- " %lu : %lu : %lu : %i : %i : %i : %qu : %lu ",
+ " %lu : %lu : %lu : %i : %i : %i : %qu : %lu : %lu ",
&maxinode, &maxblock, &maxnlink, &maxuser,
- &maxgroup, &maxflags, &maxsize, &maxlen);
+ &maxgroup, &maxflags, &maxsize, &maxlen, &maxlattr);
f_notabs = 1;
switch (ninitmax) {
case 0: maxinode = 0;
@@ -530,6 +535,7 @@ display(p, list)
case 5: maxflags = 0;
case 6: maxsize = 0;
case 7: maxlen = 0;
+ case 8: maxlattr = 0;
#ifdef COLORLS
if (!f_color)
#endif
@@ -540,8 +546,10 @@ display(p, list)
maxnlink = makenines(maxnlink);
maxsize = makenines(maxsize);
} else if (initmax == NULL || *initmax == '\0')
- maxblock = maxinode = maxlen = maxnlink =
+ maxlattr = maxblock = maxinode = maxlen = maxnlink =
maxuser = maxgroup = maxflags = maxsize = 0;
+ if (f_lomac)
+ lomac_start();
bcfile = 0;
flags = NULL;
for (cur = list, entries = 0; cur; cur = cur->fts_link) {
@@ -616,9 +624,16 @@ display(p, list)
maxflags = flen;
} else
flen = 0;
+ if (f_lomac) {
+ lattr = get_lattr(cur);
+ lattrlen = strlen(lattr);
+ if (lattrlen > maxlattr)
+ maxlattr = lattrlen;
+ } else
+ lattrlen = 0;
- if ((np = malloc(sizeof(NAMES) +
- ulen + glen + flen + 3)) == NULL)
+ if ((np = malloc(sizeof(NAMES) + lattrlen +
+ ulen + glen + flen + 4)) == NULL)
err(1, NULL);
np->user = &np->data[0];
@@ -635,6 +650,12 @@ display(p, list)
(void)strcpy(np->flags, flags);
free(flags);
}
+ if (f_lomac) {
+ np->lattr = &np->data[ulen + glen + 2
+ + (f_flags ? flen + 1 : 0)];
+ (void)strcpy(np->lattr, lattr);
+ free(lattr);
+ }
cur->fts_pointer = np;
}
}
@@ -653,6 +674,7 @@ display(p, list)
(void)snprintf(buf, sizeof(buf), "%lu", maxblock);
d.s_block = strlen(buf);
d.s_flags = maxflags;
+ d.s_lattr = maxlattr;
d.s_group = maxgroup;
(void)snprintf(buf, sizeof(buf), "%lu", maxinode);
d.s_inode = strlen(buf);
@@ -669,6 +691,8 @@ display(p, list)
if (f_longform)
for (cur = list; cur; cur = cur->fts_link)
free(cur->fts_pointer);
+ if (f_lomac)
+ lomac_stop();
}
/*
diff --git a/bin/ls/ls.h b/bin/ls/ls.h
index 3f929e7..fd75306 100644
--- a/bin/ls/ls.h
+++ b/bin/ls/ls.h
@@ -44,6 +44,7 @@ extern long blocksize; /* block size units */
extern int f_accesstime; /* use time of last access */
extern int f_flags; /* show flags associated with a file */
+extern int f_lomac; /* show LOMAC attributes */
extern int f_inode; /* print inode */
extern int f_longform; /* long listing format */
extern int f_octal; /* print unprintables in octal */
@@ -66,6 +67,7 @@ typedef struct {
int maxlen;
int s_block;
int s_flags;
+ int s_lattr;
int s_group;
int s_inode;
int s_nlink;
@@ -77,5 +79,6 @@ typedef struct {
char *user;
char *group;
char *flags;
+ char *lattr;
char data[1];
} NAMES;
diff --git a/bin/ls/print.c b/bin/ls/print.c
index 6b410a3..dd586cc 100644
--- a/bin/ls/print.c
+++ b/bin/ls/print.c
@@ -159,6 +159,8 @@ printlong(dp)
np->group);
if (f_flags)
(void)printf("%-*s ", dp->s_flags, np->flags);
+ if (f_lomac)
+ (void)printf("%-*s ", dp->s_lattr, np->lattr);
if (S_ISCHR(sp->st_mode) || S_ISBLK(sp->st_mode))
if (minor(sp->st_rdev) > 255 || minor(sp->st_rdev) < 0)
(void)printf("%3d, 0x%08x ",
diff --git a/bin/ls/util.c b/bin/ls/util.c
index 56339c8..84d106e 100644
--- a/bin/ls/util.c
+++ b/bin/ls/util.c
@@ -162,9 +162,9 @@ usage()
{
(void)fprintf(stderr,
#ifdef COLORLS
- "usage: ls [-ABCFGHLPRTWabcdfgiklnoqrstu1]"
+ "usage: ls [-ABCFGHLPRTWZabcdfgiklnoqrstu1]"
#else
- "usage: ls [-ABCFHLPRTWabcdfgiklnoqrstu1]"
+ "usage: ls [-ABCFHLPRTWZabcdfgiklnoqrstu1]"
#endif
" [file ...]\n");
exit(1);
OpenPOWER on IntegriCloud