From 4f14f5e39d7687ddb252f5a7560724179635c944 Mon Sep 17 00:00:00 2001 From: Kamil Dudka
Date: Tue, 22 Jul 2008 12:53:00 +0200 Subject: [PATCH] --color now highlights files with capabilities, too * configure.ac: --disable-libcap configure parameter, check for libcap usability * src/Makefile.am: libcap library linking * src/ls.c (has_capability): new function for capability detection * src/dircolors.c: updated color lists * src/dircolors.hin: brief description of CAPABILITY color attribute (print_color_indicator): colorize file with capability * tests/Makefile.am: added new test ls/capability * tests/ls/capability: test for ls - colorize file with capability (root only) * NEWS: mentioned the change --- NEWS | 2 ++ configure.ac | 13 +++++++++++++ src/Makefile.am | 6 +++--- src/dircolors.c | 4 ++-- src/dircolors.hin | 1 + src/ls.c | 43 +++++++++++++++++++++++++++++++++++++++++-- tests/Makefile.am | 1 + tests/ls/capability | 43 +++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 106 insertions(+), 7 deletions(-) create mode 100644 tests/ls/capability diff --git a/NEWS b/NEWS index d6ed89e..16b721e 100644 --- a/NEWS +++ b/NEWS @@ -27,6 +27,8 @@ GNU coreutils NEWS -*- outline -*- represents the maximum number of inputs that will be merged at once. When processing more than NMERGE inputs, sort uses temporary files. + ls now colorizes files with capabilities if libcap is available + ** Bug fixes chcon --verbose now prints a newline after each message diff --git a/configure.ac b/configure.ac index ac93e1c..96b2fda 100644 --- a/configure.ac +++ b/configure.ac @@ -44,6 +44,19 @@ gl_EARLY gl_INIT coreutils_MACROS +dnl Check whether libcap is usable +AC_ARG_ENABLE([libcap], + AC_HELP_STRING([--disable-libcap], [disable libcap support]), + AC_MSG_WARN([libcap support disabled by user]), + [AC_CHECK_LIB([cap], [cap_get_file], + [AC_CHECK_HEADER([sys/capability.h], + [LIB_CAP="-lcap" AC_DEFINE(HAVE_CAP, 1, [libcap usability])], + [AC_MSG_WARN([header sys/capability.h was not found, support for libcap will not be built])] + )], + [AC_MSG_WARN([libcap library was not found or not usable, support for libcap will not be built])]) + ]) +AC_SUBST([LIB_CAP]) + AC_FUNC_FORK optional_bin_progs= diff --git a/src/Makefile.am b/src/Makefile.am index 65b20a2..41e3273 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -101,15 +101,15 @@ __LDADD = $(LDADD) $(LIB_EACCESS) # for clock_gettime and fdatasync dd_LDADD = $(LDADD) $(LIB_GETHRXTIME) $(LIB_FDATASYNC) -dir_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME) $(LIB_SELINUX) +dir_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME) $(LIB_SELINUX) $(LIB_CAP) id_LDADD = $(LDADD) $(LIB_SELINUX) -ls_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME) $(LIB_SELINUX) +ls_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME) $(LIB_SELINUX) $(LIB_CAP) mktemp_LDADD = $(LDADD) $(LIB_GETHRXTIME) pr_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME) shred_LDADD = $(LDADD) $(LIB_GETHRXTIME) $(LIB_FDATASYNC) shuf_LDADD = $(LDADD) $(LIB_GETHRXTIME) tac_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME) -vdir_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME) $(LIB_SELINUX) +vdir_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME) $(LIB_SELINUX) $(LIB_CAP) ## If necessary, add -lm to resolve use of pow in lib/strtod.c. sort_LDADD = $(LDADD) $(POW_LIB) $(LIB_GETHRXTIME) diff --git a/src/dircolors.c b/src/dircolors.c index 56194f7..79109b9 100644 --- a/src/dircolors.c +++ b/src/dircolors.c @@ -63,14 +63,14 @@ static const char *const slack_codes[] = "SYMLINK", "ORPHAN", "MISSING", "FIFO", "PIPE", "SOCK", "BLK", "BLOCK", "CHR", "CHAR", "DOOR", "EXEC", "LEFT", "LEFTCODE", "RIGHT", "RIGHTCODE", "END", "ENDCODE", "SUID", "SETUID", "SGID", "SETGID", "STICKY", - "OTHER_WRITABLE", "OWR", "STICKY_OTHER_WRITABLE", "OWT", NULL + "OTHER_WRITABLE", "OWR", "STICKY_OTHER_WRITABLE", "OWT", "CAPABILITY", NULL }; static const char *const ls_codes[] = { "no", "no", "fi", "rs", "di", "ln", "ln", "ln", "or", "mi", "pi", "pi", "so", "bd", "bd", "cd", "cd", "do", "ex", "lc", "lc", "rc", "rc", "ec", "ec", - "su", "su", "sg", "sg", "st", "ow", "ow", "tw", "tw", NULL + "su", "su", "sg", "sg", "st", "ow", "ow", "tw", "tw", "ca", NULL }; #define array_len(Array) (sizeof (Array) / sizeof *(Array)) verify (array_len (slack_codes) == array_len (ls_codes)); diff --git a/src/dircolors.hin b/src/dircolors.hin index 38914c8..b3aba38 100644 --- a/src/dircolors.hin +++ b/src/dircolors.hin @@ -77,6 +77,7 @@ CHR 40;33;01 # character device driver ORPHAN 40;31;01 # symlink to nonexistent file, or non-stat'able file SETUID 37;41 # file that is setuid (u+s) SETGID 30;43 # file that is setgid (g+s) +CAPABILITY 30;41 # file with capability STICKY_OTHER_WRITABLE 30;42 # dir that is sticky and other-writable (+t,o+w) OTHER_WRITABLE 34;42 # dir that is other-writable (o+w) and not sticky STICKY 37;44 # dir with the sticky bit set (+t) and not other-writable diff --git a/src/ls.c b/src/ls.c index 4b69f7d..9bc66a1 100644 --- a/src/ls.c +++ b/src/ls.c @@ -38,6 +38,10 @@ #include