bug-coreutils
[Top][All Lists]
Advanced

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

modechange.c: support for GNU/Hurd fourth permission triplet


From: ivan
Subject: modechange.c: support for GNU/Hurd fourth permission triplet
Date: Tue, 27 May 2003 03:56:19 +0700

        This patch allows one to set GNU/Hurd fourth permission
        triplet as mentioned in
        http://www.gnu.org/software/hurd/faq.en.html.  I just added
        fourth category `O' that accepts usual `rwx' bits and `s'
        (S_IUSEUNK) bit.  The most important application for this
        feature is (IMO):

root# chmod a=rwxt,O=s /tmp/

        Hope that code is self-explanatory.

-------
--- lib/modechange.c    26 May 2003 17:23:45 -0000      1.1.1.1
+++ lib/modechange.c    26 May 2003 19:52:28 -0000      1.2
@@ -101,6 +101,36 @@
 #ifndef S_IXOTH
 # define S_IXOTH XOTH
 #endif
+
+#ifndef S_IRUNK
+# ifdef __USE_GNU
+#  define S_IRUNK (S_IREAD  << S_IUNKSHIFT)
+# else
+#  define S_IRUNK 0
+# endif
+#endif
+#ifndef S_IWUNK
+# ifdef __USE_GNU
+#  define S_IWUNK (S_IWRITE << S_IUNKSHIFT)
+# else
+#  define S_IWUNK 0
+# endif
+#endif
+#ifndef S_IXUNK
+# ifdef __USE_GNU
+#  define S_IXUNK (S_IEXEC  << S_IUNKSHIFT)
+# else
+#  define S_IXUNK 0
+# endif
+#endif
+
+#ifndef S_IUSEUNK
+# define S_IUSEUNK 0
+#endif
+#ifndef S_UNKNOWN
+# define S_UNKNOWN 0
+#endif
+
 #ifndef S_IRWXU
 # define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
 #endif
@@ -110,10 +140,19 @@
 #ifndef S_IRWXO
 # define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
 #endif
+#ifndef S_IRWXN
+# define S_IRWXN (S_IRUNK | S_IWUNK | S_IXUNK)
+#endif
+
+#define EVERY_R (S_IRUSR | S_IRGRP | S_IROTH | S_IRUNK)
+#define EVERY_W (S_IWUSR | S_IWGRP | S_IWOTH | S_IWUNK)
+#define EVERY_X (S_IXUSR | S_IXGRP | S_IXOTH | S_IXUNK)
 
 /* All the mode bits that can be affected by chmod.  */
 #define CHMOD_MODE_BITS \
-  (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO)
+  (S_UNKNOWN | S_IUSEUNK | \
+   S_ISUID | S_ISGID | S_ISVTX | \
+   S_IRWXU | S_IRWXG | S_IRWXO)
 
 /* Return newly allocated memory to hold one element of type TYPE. */
 #define talloc(type) ((type *) malloc (sizeof (type)))
@@ -245,6 +284,9 @@
          case 'o':
            affected_bits |= S_ISVTX | S_IRWXO;
            break;
+         case 'O':
+           affected_bits |= S_IUSEUNK | S_IUNKNOWN;
+           break;
          case 'a':
            affected_bits |= CHMOD_MODE_BITS;
            break;
@@ -305,23 +347,21 @@
            switch (*mode_string)
              {
              case 'r':
-               change->value |= ((S_IRUSR | S_IRGRP | S_IROTH)
-                                 & affected_masked);
+               change->value |= (EVERY_R & affected_masked);
                break;
              case 'w':
-               change->value |= ((S_IWUSR | S_IWGRP | S_IWOTH)
-                                 & affected_masked);
+               change->value |= (EVERY_W & affected_masked);
                break;
              case 'X':
                change->flags |= MODE_X_IF_ANY_X;
                /* Fall through. */
              case 'x':
-               change->value |= ((S_IXUSR | S_IXGRP | S_IXOTH)
-                                 & affected_masked);
+               change->value |= (EVERY_X & affected_masked);
                break;
              case 's':
                /* Set the setuid/gid bits if `u' or `g' is selected. */
-               change->value |= (S_ISUID | S_ISGID) & affected_masked;
+               change->value |= ((S_IUSEUNK | S_ISUID | S_ISGID) &
+                                 affected_masked);
                break;
              case 't':
                /* Set the "save text image" bit if `o' is selected. */
@@ -351,6 +391,14 @@
                change->value = S_IRWXO;
                change->flags |= MODE_COPY_EXISTING;
                break;
+             case 'O':
+               /* Set the affected bits to the value of the `O' bits
+                  on the same file.  */
+               if (change->value)
+                 goto invalid;
+               change->value = S_IRWXN;
+               change->flags |= MODE_COPY_EXISTING;
+               break;
              default:
                goto no_more_values;
              }
@@ -413,19 +461,24 @@
 
          if (changes->value & S_IRWXU)
            /* Copy `u' permissions onto `g' and `o'. */
-           value |= (  (value & S_IRUSR ? S_IRGRP | S_IROTH : 0)
-                     | (value & S_IWUSR ? S_IWGRP | S_IWOTH : 0)
-                     | (value & S_IXUSR ? S_IXGRP | S_IXOTH : 0));
+           value |= (  (value & S_IRUSR ? EVERY_R ^ S_IRUSR : 0)
+                     | (value & S_IWUSR ? EVERY_W ^ S_IWUSR : 0)
+                     | (value & S_IXUSR ? EVERY_X ^ S_IXUSR : 0));
          else if (changes->value & S_IRWXG)
            /* Copy `g' permissions onto `u' and `o'. */
-           value |= (  (value & S_IRGRP ? S_IRUSR | S_IROTH : 0)
-                     | (value & S_IWGRP ? S_IWUSR | S_IWOTH : 0)
-                     | (value & S_IXGRP ? S_IXUSR | S_IXOTH : 0));
-         else
+           value |= (  (value & S_IRGRP ? EVERY_R ^ S_IRGRP : 0)
+                     | (value & S_IWGRP ? EVERY_W ^ S_IWGRP : 0)
+                     | (value & S_IXGRP ? EVERY_X ^ S_IXGRP : 0));
+         else if (changes->value & S_IRWXO)
            /* Copy `o' permissions onto `u' and `g'. */
-           value |= (  (value & S_IROTH ? S_IRUSR | S_IRGRP : 0)
-                     | (value & S_IWOTH ? S_IWUSR | S_IWGRP : 0)
-                     | (value & S_IXOTH ? S_IXUSR | S_IXGRP : 0));
+           value |= (  (value & S_IROTH ? EVERY_R ^ S_IROTH : 0)
+                     | (value & S_IWOTH ? EVERY_W ^ S_IWOTH : 0)
+                     | (value & S_IXOTH ? EVERY_X ^ S_IXOTH : 0));
+         else
+           /* Copy `O' permissions onto `u' and `g'. */
+           value |= (  (value & S_IRUNK ? EVERY_R ^ S_IRUNK : 0)
+                     | (value & S_IWUNK ? EVERY_W ^ S_IWUNK : 0)
+                     | (value & S_IXUNK ? EVERY_X ^ S_IXUNK : 0));
 
          /* In order to change only `u', `g', or `o' permissions,
             or some combination thereof, clear unselected bits.
--- src/chmod.c 26 May 2003 17:23:45 -0000      1.1.1.1
+++ src/chmod.c 26 May 2003 20:43:07 -0000      1.2
@@ -308,6 +308,9 @@
        case 'u':
        case 'g':
        case 'o':
+#ifdef __USE_GNU
+       case 'O':
+#endif
        case 'a':
        case ',':
        case '+':
-------

PS.  The patch is almost untested, but it seems to work.




reply via email to

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