bug-coreutils
[Top][All Lists]
Advanced

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

Patch to colorize setuid, setgid, and sticky files/dirs


From: Chris Spiegel
Subject: Patch to colorize setuid, setgid, and sticky files/dirs
Date: Mon, 12 Jan 2004 23:36:30 -0800
User-agent: Mutt/1.4.1i

Hi,
  I've written up a patch for coreutils that allows you to set colors
for setuid/setgid executables and sticky-bit directories (this idea was
taken from FreeBSD's ls).  I admit that I don't necessarily completely
understand the code for colorization; however, this patch appears to
work just fine for me.

The patch follows.

Thanks,
Chris


diff -ru coreutils-5.0.91/src/dircolors.c coreutils-5.0.91-chris/src/dircolors.c
--- coreutils-5.0.91/src/dircolors.c    2003-07-22 04:31:04.000000000 -0700
+++ coreutils-5.0.91-chris/src/dircolors.c      2004-01-12 23:17:53.000000000 
-0800
@@ -69,14 +69,15 @@
 {
   "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
+  "CHR", "CHAR", "DOOR", "EXEC", "SUID", "SGID", "STICKY", "LEFT", "LEFTCODE",
+  "RIGHT", "RIGHTCODE", "END", "ENDCODE", 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"
+  "so", "bd", "bd", "cd", "cd", "do", "ex", "su", "sg", "st", "lc",
+  "lc", "rc", "rc", "ec", "ec"
 };
 
 static struct option const long_options[] =
diff -ru coreutils-5.0.91/src/dircolors.h coreutils-5.0.91-chris/src/dircolors.h
--- coreutils-5.0.91/src/dircolors.h    2003-04-11 05:46:31.000000000 -0700
+++ coreutils-5.0.91-chris/src/dircolors.h      2004-01-12 23:17:53.000000000 
-0800
@@ -1,13 +1,13 @@
-#define G_N_LINES 106
+#define G_N_LINES 111
 
 const size_t G_line_length[G_N_LINES] =
 {
   65, 72, 0, 59, 61, 0, 77, 10, 12, 15, 12, 14, 14, 14, 14, 13, 13, 13, 13,
   13, 13, 11, 10, 16, 17, 9, 11, 13, 10, 10, 0, 73, 64, 18, 64, 19, 72,
-  25, 72, 68, 22, 21, 70, 62, 17, 19, 17, 34, 38, 45, 0, 44, 10, 0, 70,
-  75, 48, 0, 73, 40, 11, 11, 11, 11, 0, 48, 10, 10, 10, 10, 10, 10, 10,
-  10, 10, 10, 10, 10, 0, 15, 10, 11, 10, 10, 10, 10, 10, 10, 10, 10, 10,
-  11, 10, 10, 11, 10, 10, 9, 9, 10, 10, 0, 15, 10, 10, 10
+  25, 72, 68, 22, 21, 38, 70, 62, 17, 19, 17, 34, 38, 45, 0, 44, 10, 38, 13,
+  39, 13, 0, 70, 75, 48, 0, 73, 40, 11, 11, 11, 11, 0, 48, 10, 10, 10, 10,
+  10, 10, 10, 10, 10, 10, 10, 10, 0, 15, 10, 11, 10, 10, 10, 10, 10, 10, 10,
+  10, 10, 11, 10, 10, 11, 10, 10, 9, 9, 10, 10, 0, 15, 10, 10, 10
 };
 
 const char *const G_line[G_N_LINES] =
@@ -54,6 +54,7 @@
   "NORMAL 00   # global default, although everything should be something.",
   "FILE 00             # normal file",
   "DIR 01;34   # directory",
+  "STICKY 40;34;07     # sticky-bit directory",
   "LINK 01;36  # symbolic link.  (If you set this to 'target' instead of a",
   "            # numerical value, the color is as for the file pointed to.)",
   "FIFO 40;33  # pipe",
@@ -65,6 +66,10 @@
   "",
   "# This is for files with execute permission:",
   "EXEC 01;32",
+  "# This is for set user-id executables:",
+  "SUID 40;32;07",
+  "# This is for set group-id executables:",
+  "SGID 40;32;07",
   "",
   "# List any file extensions like '.gz' or '.tar' that you would like ls",
   "# to colorize below. Put the extension, a space, and the color init 
string.",
diff -ru coreutils-5.0.91/src/ls.c coreutils-5.0.91-chris/src/ls.c
--- coreutils-5.0.91/src/ls.c   2003-07-26 23:33:36.000000000 -0700
+++ coreutils-5.0.91-chris/src/ls.c     2004-01-12 23:17:53.000000000 -0800
@@ -518,13 +518,14 @@
 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_SUID, C_SGID,
+    C_STICKY,
   };
 
 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", NULL
   };
 
 struct color_ext_type
@@ -550,7 +551,13 @@
     { 0, NULL },                       /* mi: Missing file: undefined */
     { 0, NULL },                       /* or: Orphanned 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 ("40;32;07") },     /* su: Set user-id executable:
+                                               bright green inverse */
+    { LEN_STR_PAIR ("40;32;07") },     /* sg: Set group-id executable:
+                                               bright green inverse */
+    { LEN_STR_PAIR ("40;34;07") },     /* st: Sticky bit directory:
+                                               bright blue inverse */
   };
 
 /* FIXME: comment  */
@@ -3387,7 +3394,17 @@
        type = C_DOOR;
 
       if (type == C_FILE && (mode & S_IXUGO) != 0)
-       type = C_EXEC;
+       {
+         if (mode & S_ISUID)
+           type = C_SUID;
+         else if (mode & S_ISGID)
+           type = C_SGID;
+         else
+           type = C_EXEC;
+       }
+
+      if (type == C_DIR && (mode & S_ISVTX) != 0)
+       type = C_STICKY;
 
       /* Check the file's suffix only if still classified as C_FILE.  */
       ext = NULL;




reply via email to

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