summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2005-09-05 17:12:07 +0000
committerJim Meyering <jim@meyering.net>2005-09-05 17:12:07 +0000
commitac46781470f3a62c0fbbbdc5304f0de83b6acfa4 (patch)
tree2382b656197a3778ed7514fc1389928a4eab7da7 /src
parentbd30058179f47fa232a8ef6d8d4b451374f89893 (diff)
downloadcoreutils-ac46781470f3a62c0fbbbdc5304f0de83b6acfa4.tar.xz
Colorize set-user-ID and set-group-ID files and sticky,
other-writable, and sticky-and-other-writable directories. (indicator_no[]): Add new symbols. (indicator_name[]): Add corresponding mode strings. (color_indicator[]): Add an entry for each new mode string. (print_color_indicator): Honor new types. From Mike Frysinger, based on a patch from Fedora.
Diffstat (limited to 'src')
-rw-r--r--src/ls.c35
1 files changed, 29 insertions, 6 deletions
diff --git a/src/ls.c b/src/ls.c
index a3d4bde71..bd648dcce 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -518,13 +518,15 @@ enum Dereference_symlink
enum indicator_no
{
C_LEFT, C_RIGHT, C_END, C_NORM, C_FILE, C_DIR, C_LINK, C_FIFO, C_SOCK,
- C_BLK, C_CHR, C_MISSING, C_ORPHAN, C_EXEC, C_DOOR
+ C_BLK, C_CHR, C_MISSING, C_ORPHAN, C_EXEC, C_DOOR, C_SETUID, C_SETGID,
+ C_STICKY, C_OTHER_WRITABLE, C_STICKY_OTHER_WRITABLE
};
static const char *const indicator_name[]=
{
"lc", "rc", "ec", "no", "fi", "di", "ln", "pi", "so",
- "bd", "cd", "mi", "or", "ex", "do", NULL
+ "bd", "cd", "mi", "or", "ex", "do", "su", "sg", "st",
+ "ow", "tw", NULL
};
struct color_ext_type
@@ -550,7 +552,12 @@ static struct bin_str color_indicator[] =
{ 0, NULL }, /* mi: Missing file: undefined */
{ 0, NULL }, /* or: Orphaned symlink: undefined */
{ LEN_STR_PAIR ("01;32") }, /* ex: Executable: bright green */
- { LEN_STR_PAIR ("01;35") } /* do: Door: bright magenta */
+ { LEN_STR_PAIR ("01;35") }, /* do: Door: bright magenta */
+ { LEN_STR_PAIR ("37;41") }, /* su: setuid: white on red */
+ { LEN_STR_PAIR ("30;43") }, /* sg: setgid: black on yellow */
+ { LEN_STR_PAIR ("37;44") }, /* st: sticky: black on blue */
+ { LEN_STR_PAIR ("34;42") }, /* ow: other-writable: blue on green */
+ { LEN_STR_PAIR ("30;42") }, /* tw: ow w/ sticky: black on green */
};
/* FIXME: comment */
@@ -3687,7 +3694,16 @@ print_color_indicator (const char *name, mode_t mode, int linkok)
else
{
if (S_ISDIR (mode))
- type = C_DIR;
+ {
+ if ((mode & S_ISVTX) && (mode & S_IWOTH))
+ type = C_STICKY_OTHER_WRITABLE;
+ else if ((mode & S_IWOTH) != 0)
+ type = C_OTHER_WRITABLE;
+ else if ((mode & S_ISVTX) != 0)
+ type = C_STICKY;
+ else
+ type = C_DIR;
+ }
else if (S_ISLNK (mode))
type = ((!linkok && color_indicator[C_ORPHAN].string)
? C_ORPHAN : C_LINK);
@@ -3702,8 +3718,15 @@ print_color_indicator (const char *name, mode_t mode, int linkok)
else if (S_ISDOOR (mode))
type = C_DOOR;
- if (type == C_FILE && (mode & S_IXUGO) != 0)
- type = C_EXEC;
+ if (type == C_FILE)
+ {
+ if ((mode & S_ISUID) != 0)
+ type = C_SETUID;
+ else if ((mode & S_ISGID) != 0)
+ type = C_SETGID;
+ else if ((mode & S_IXUGO) != 0)
+ type = C_EXEC;
+ }
/* Check the file's suffix only if still classified as C_FILE. */
ext = NULL;