bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: colorize more file types with dircolors ?


From: Jim Meyering
Subject: Re: colorize more file types with dircolors ?
Date: Mon, 05 Sep 2005 19:27:50 +0200

Mike Frysinger <address@hidden> wrote:
...
> done, find attached ... thanks for all the pointers

Thanks for doing that.
I've changed an expression and a couple of symbol names in ls.c to
make them more readable and added proper ChangeLog entries and a
test case:

2005-09-05  Jim Meyering  <address@hidden>

        Colorize set-user-ID and set-group-ID files and sticky,
        other-writable, and sticky-and-other-writable directories.

        * src/dircolors.c (slack_codes): Add new dircolors mode names.
        (ls_codes): Add corresponding two-letter ls mode strings.
        * src/ls.c (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.
        * src/dircolors.hin: Document the default colors for the new strings.
        From Mike Frysinger, based on a patch from Fedora.
        * tests/ls-2/tests (setuid-etc): New test, for the above.

Index: src/dircolors.c
===================================================================
RCS file: /fetish/cu/src/dircolors.c,v
retrieving revision 1.90
retrieving revision 1.91
diff -u -p -u -r1.90 -r1.91
--- src/dircolors.c     12 Aug 2005 08:06:28 -0000      1.90
+++ src/dircolors.c     5 Sep 2005 17:11:15 -0000       1.91
@@ -67,13 +67,15 @@ static const char *const slack_codes[] =
   "NORMAL", "NORM", "FILE", "DIR", "LNK", "LINK",
   "SYMLINK", "ORPHAN", "MISSING", "FIFO", "PIPE", "SOCK", "BLK", "BLOCK",
   "CHR", "CHAR", "DOOR", "EXEC", "LEFT", "LEFTCODE", "RIGHT", "RIGHTCODE",
-  "END", "ENDCODE", NULL
+  "END", "ENDCODE", "SUID", "SETUID", "SGID", "SETGID", "STICKY",
+  "OTHER_WRITABLE", "OWR", "STICKY_OTHER_WRITABLE", "OWT", NULL
 };
 
 static const char *const ls_codes[] =
 {
   "no", "no", "fi", "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
 };
 
 static struct option const long_options[] =
Index: src/dircolors.hin
===================================================================
RCS file: /fetish/cu/src/dircolors.hin,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -p -u -r1.19 -r1.20
--- src/dircolors.hin   26 Mar 2005 06:56:01 -0000      1.19
+++ src/dircolors.hin   5 Sep 2005 17:11:39 -0000       1.20
@@ -51,6 +51,11 @@ DOOR 01;35   # door
 BLK 40;33;01   # block device driver
 CHR 40;33;01   # character device driver
 ORPHAN 40;31;01 # symlink to nonexistent file
+SETUID 37;41   # file that is setuid (u+s)
+SETGID 30;43   # file that is setgid (g+s)
+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
 
 # This is for files with execute permission:
 EXEC 01;32
Index: src/ls.c
===================================================================
RCS file: /fetish/cu/src/ls.c,v
retrieving revision 1.397
retrieving revision 1.398
diff -u -p -u -r1.397 -r1.398
--- src/ls.c    14 Aug 2005 08:30:25 -0000      1.397
+++ src/ls.c    5 Sep 2005 17:12:07 -0000       1.398
@@ -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,
   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,
       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;
Index: tests/ls-2/tests
===================================================================
RCS file: /fetish/cu/tests/ls-2/tests,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -p -u -r1.22 -r1.23
--- tests/ls-2/tests    10 May 2005 06:59:24 -0000      1.22
+++ tests/ls-2/tests    5 Sep 2005 17:13:09 -0000       1.23
@@ -97,6 +97,27 @@ my @Tests =
         $mkdir, $rmdir, {EXIT => 2}],
 
      ['recursive-2', '-R d', {OUT => "d:\ne\n\nd/e:\n"}, $mkdir2, $rmdir2],
+
+     ['setuid-etc', '-1 -d --color=always owr owt setgid setuid sticky',
+        {OUT =>
+           "\e[0m\e[34;42mowr\e[0m\n"
+           . "\e[30;42mowt\e[0m\n"
+           . "\e[30;43msetgid\e[0m\n"
+           . "\e[37;41msetuid\e[0m\n"
+           . "\e[37;44msticky\e[0m\n"
+           . "\e[m"
+        },
+       {PRE => sub {
+        system
+          "touch setuid && chmod u+s setuid;"
+         ."touch setgid && chmod g+s setgid;"
+         ."mkdir sticky && chmod +t sticky;"
+         ."mkdir owt    && chmod +t,o+w owt;"
+         ."mkdir owr    && chmod o+w owr" }},
+       {POST => sub {
+         unlink qw(setuid setgid);
+        foreach my $dir (qw(owr owt sticky)) {rmdir $dir} }},
+        ],
     );
 
 my $save_temps = $ENV{SAVE_TEMPS};




reply via email to

[Prev in Thread] Current Thread [Next in Thread]