diff options
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | lr.1 | 10 | ||||
-rw-r--r-- | lr.c | 38 |
3 files changed, 49 insertions, 0 deletions
diff --git a/README.md b/README.md index 7057611..117cee9 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,7 @@ Over ls: * `%e`: number of entries in directories (only with `-D`). * `%t`: total size used by accepted files in directories (only with `-D`). * `%Y`: type of the filesystem the file resides on. +* `%x`: Linux-only: `#` for files with security capabilities, `+` for files with an ACL, `@` for files with other extended attributes, a single space else. ## Sort order diff --git a/lr.1 b/lr.1 index 3488a28..b755c1f 100644 --- a/lr.1 +++ b/lr.1 @@ -163,6 +163,16 @@ Total size used by accepted files in directories (only with .Fl D ) .It Ic \&%Y Type of the filesystem the file resides on +.It Ic \&%x +Linux-only: +Print +.Sq Li \&# +for files with security capabilities, +.Sq Li \&+ +for files with an ACL, +.Sq Li \&@ +for files with other extended attributes, +or a single space else. .El .Sh SORT ORDER Sort order is string consisting of the following letters. diff --git a/lr.c b/lr.c index de451fa..d9edc95 100644 --- a/lr.c +++ b/lr.c @@ -35,6 +35,10 @@ #include <sys/stat.h> #include <sys/types.h> +#ifdef __linux__ +#include <attr/xattr.h> +#endif + #include <ctype.h> #include <dirent.h> #include <errno.h> @@ -1337,6 +1341,39 @@ color_name_on(const char *f, mode_t m) fg256(154); } +static char +xattr_char(const char *f) +{ +#ifdef __linux__ + char xattr[1024]; + int c, i, r; + + if (Lflag) + r = listxattr(f, xattr, sizeof xattr); + else + r = llistxattr(f, xattr, sizeof xattr); + if (r < 0 && errno == ERANGE) { + /* just look at prefix */ + r = sizeof xattr; + xattr[r-1] = 0; + } + // ignoring ENOTSUP or r == 0 + + for (i = 0, c = 0; i < r; i += strlen(xattr+i) + 1) + if (strcmp(xattr+i, "security.capability") == 0) { + if (c < 3) c = 3; + } else if (strcmp(xattr+i, "system.posix_acl_access") == 0) { + if (c < 2) c = 2; + } else { + if (c < 1) c = 1; + } + + return " @+#"[c]; +#else + return ' '; // No support for xattrs on this platform. +#endif +} + void print_format(struct fileinfo *fi) { @@ -1466,6 +1503,7 @@ print_format(struct fileinfo *fi) case 'e': printf("%ld", (long)fi->entries); break; case 't': printf("%jd", (intmax_t)fi->total); break; case 'Y': printf("%*s", -fwid, fstype(fi->sb.st_dev)); break; + case 'x': putchar(xattr_char(fi->fpath)); break; default: putchar('%'); putchar(*s); |