bug-hurd
[Top][All Lists]
Advanced

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

Re: patch for sysv-style group behaviour


From: Marcus Brinkmann
Subject: Re: patch for sysv-style group behaviour
Date: Tue, 30 Apr 2002 06:40:54 +0200
User-agent: Mutt/1.3.28i

On Mon, Apr 29, 2002 at 09:06:31PM -0400, Roland McGrath wrote:
> Give the option a meaningful name like --[no-]inherit-directory-group; 
> make aliases for the linux mount option names grpid/bsdgroups and
> nogrpid/sysvgroups.  

Good idea, done.  How about this (I used dir instead directory for
briefness)?

Marcus

Index: ChangeLog
===================================================================
RCS file: /cvsroot/hurd/hurd/libdiskfs/ChangeLog,v
retrieving revision 1.171
diff -u -r1.171 ChangeLog
--- ChangeLog   26 Mar 2002 19:06:57 -0000      1.171
+++ ChangeLog   30 Apr 2002 04:30:02 -0000
@@ -1,3 +1,21 @@
+2002-04-30  Marcus Brinkmann  <marcus@gnu.org>
+
+       * priv.h: Add OPT_NO_INHERIT_DIR_GROUP and OPT_INHERIT_DIR_GROUP.
+       (_diskfs_noinheritdirgroup): New declaration.
+       * node-create.c (_diskfs_noinheritdirgroup): New variable.
+       (diskfs_create_node): Implement SysV group behaviour.
+       * opts-common.c (diskfs_common_options): Add
+       --no-inherit-dir-group (--nogrpdir, --sysvgroups) and
+       --inherit-dir-group (--grpdir, --bsdgroups).
+       * opts-append-std.c (diskfs_append_std_options): Add
+       --no-inherit-dir-group if set.
+       * opts-std-startup.c (parse_startup_opt): Add toggle for
+       _diskfs_noinheritdirgroup.
+       * opts-std-runtime.c (struct parse_hook): Add noinheritdirgroup.
+       (set_opts): Handle H->noinheritdirgroup.
+       (parse_opt): Initialize H->noinheritdirgroup.  Handle
+       OPT_NO_INHERIT_DIR_GROUP and OPT_INHERIT_DIR_GROUP.
+
 2002-03-23  James A. Morrison  <ja2morri@uwaterloo.ca>
 
        * init-startup.c (_diskfs_init_completed): Use error, not
Index: node-create.c
===================================================================
RCS file: /cvsroot/hurd/hurd/libdiskfs/node-create.c,v
retrieving revision 1.16
diff -u -r1.16 node-create.c
--- node-create.c       15 Apr 2001 22:44:03 -0000      1.16
+++ node-create.c       30 Apr 2002 04:30:02 -0000
@@ -17,6 +17,11 @@
 
 #include "priv.h"
 
+/* This enables SysV style group behaviour.  New nodes inherit the GID
+   of the user creating them unless the SGID bit is set of the parent
+   directory.  */
+int _diskfs_no_inherit_dir_group;
+
 /* Create a new node. Give it MODE; if that includes IFDIR, also
    initialize `.' and `..' in the new directory.  Return the node in NPP.
    CRED identifies the user responsible for the call.  If NAME is nonzero,
@@ -70,9 +75,40 @@
   if (np->author_tracks_uid)
     np->dn_stat.st_author = newuid;
 
-  newgid = dir->dn_stat.st_gid;
-  if (!idvec_contains (cred->user->gids, newgid))
-    mode &= ~S_ISGID;
+  if (!_diskfs_no_inherit_dir_group)
+    {
+      newgid = dir->dn_stat.st_gid;
+      if (!idvec_contains (cred->user->gids, newgid))
+       mode &= ~S_ISGID;
+    }
+  else
+    {
+      if (dir->dn_stat.st_mode & S_ISGID)
+       {
+         /* If the parent dir has the sgid bit set, inherit its gid.
+            If the new node is a directory, also inherit the sgid bit
+            set.  */
+         newgid = dir->dn_stat.st_gid;
+         if (S_ISDIR (mode))
+           mode |= S_ISGID;
+         else
+           {
+             if (!idvec_contains (cred->user->gids, newgid))
+               mode &= ~S_ISGID;
+           }
+       }
+      else
+       {
+         if (cred->user->gids->num)
+           newgid = cred->user->gids->ids[0];
+         else
+           {
+             newgid = dir->dn_stat.st_gid;
+             mode &= ~S_ISGID;
+           }
+       }
+    }
+
   err = diskfs_validate_group_change (np, newgid);
   if (err)
     goto change_err;
Index: opts-append-std.c
===================================================================
RCS file: /cvsroot/hurd/hurd/libdiskfs/opts-append-std.c,v
retrieving revision 1.8
diff -u -r1.8 opts-append-std.c
--- opts-append-std.c   12 Mar 2002 01:50:49 -0000      1.8
+++ opts-append-std.c   30 Apr 2002 04:30:02 -0000
@@ -42,6 +42,8 @@
     err = argz_add (argz, argz_len, "--no-exec");
   if (!err && _diskfs_noatime)
     err = argz_add (argz, argz_len, "--no-atime");
+  if (!err && _diskfs_noinheritdirgroup)
+    err = argz_add (argz, argz_len, "--no-inherit-dir-group");
 
   if (! err)
     {
Index: opts-common.c
===================================================================
RCS file: /cvsroot/hurd/hurd/libdiskfs/opts-common.c,v
retrieving revision 1.5
diff -u -r1.5 opts-common.c
--- opts-common.c       14 May 2000 20:35:53 -0000      1.5
+++ opts-common.c       30 Apr 2002 04:30:02 -0000
@@ -47,5 +47,13 @@
    "Do not update file access times on disk for reads"},
   {"noatime",  0,   0, OPTION_ALIAS | OPTION_HIDDEN},
   {"atime", OPT_ATIME, 0, 0, "Do update file access times for reads normally"},
+  {"no-inherit-dir-group", OPT_NO_INHERIT_DIR_GROUP, 0, 0,
+   "Create new nodes with gid of the process"},
+  {"nogrpid",    0,   0, OPTION_ALIAS | OPTION_HIDDEN},
+  {"sysvgroups", 0,   0, OPTION_ALIAS | OPTION_HIDDEN},
+  {"inherit-dir-group", OPT_INHERIT_DIR_GROUP, 0, 0,
+   "Create new nodes with gid of parent dir (default)"},
+  {"grpid",    0,   0, OPTION_ALIAS | OPTION_HIDDEN},
+  {"bsdgroups", 0,   0, OPTION_ALIAS | OPTION_HIDDEN},
   {0, 0}
 };
Index: opts-std-runtime.c
===================================================================
RCS file: /cvsroot/hurd/hurd/libdiskfs/opts-std-runtime.c,v
retrieving revision 1.10
diff -u -r1.10 opts-std-runtime.c
--- opts-std-runtime.c  12 Oct 1999 07:11:11 -0000      1.10
+++ opts-std-runtime.c  30 Apr 2002 04:30:03 -0000
@@ -32,7 +32,8 @@
 
 struct parse_hook
 {
-  int readonly, sync, sync_interval, remount, nosuid, noexec, noatime;
+  int readonly, sync, sync_interval, remount, nosuid, noexec, noatime,
+    noinheritdirgroup;
 };
 
 /* Implement the options in H, and free H.  */
@@ -79,6 +80,8 @@
     _diskfs_noexec = h->noexec;
   if (h->noatime != -1)
     _diskfs_noatime = h->noatime;
+  if (h->noinheritdirgroup != -1)
+    _diskfs_noinheritdirgroup = h->noinheritdirgroup;
 
   free (h);
 
@@ -101,6 +104,8 @@
     case OPT_SUID_OK: h->nosuid = 0; break;
     case OPT_EXEC_OK: h->noexec = 0; break;
     case OPT_ATIME: h->noatime = 0; break;
+    case OPT_NO_INHERIT_DIR_GROUP: h->noinheritdirgroup = 1; break;
+    case OPT_INHERIT_DIR_GROUP: h->noinheritdirgroup = 0; break;
     case 'n': h->sync_interval = 0; h->sync = 0; break;
     case 's':
       if (arg)
@@ -124,7 +129,7 @@
          h->sync = diskfs_synchronous;
          h->sync_interval = -1;
          h->remount = 0;
-         h->nosuid = h->noexec = h->noatime = -1;
+         h->nosuid = h->noexec = h->noatime = h->noinheritdirgroup = -1;
 
          /* We know that we have one child, with which we share our hook.  */
          state->child_inputs[0] = h;
Index: opts-std-startup.c
===================================================================
RCS file: /cvsroot/hurd/hurd/libdiskfs/opts-std-startup.c,v
retrieving revision 1.19
diff -u -r1.19 opts-std-startup.c
--- opts-std-startup.c  24 Aug 2001 02:23:57 -0000      1.19
+++ opts-std-startup.c  30 Apr 2002 04:30:03 -0000
@@ -82,6 +82,8 @@
       TOGGLE (_diskfs_nosuid, 'S', OPT_SUID_OK);
       TOGGLE (_diskfs_noexec, 'E', OPT_EXEC_OK);
       TOGGLE (_diskfs_noatime, 'A', OPT_ATIME);
+      TOGGLE (_diskfs_noinheritdirgroup, OPT_INHERIT_DIR_GROUP,
+             OPT_NO_INHERIT_DIR_GROUP);
 #undef TOGGLE
 
     case 's':
Index: priv.h
===================================================================
RCS file: /cvsroot/hurd/hurd/libdiskfs/priv.h,v
retrieving revision 1.44
diff -u -r1.44 priv.h
--- priv.h      6 May 2001 00:49:27 -0000       1.44
+++ priv.h      30 Apr 2002 04:30:03 -0000
@@ -35,6 +35,11 @@
 /* This relaxes the requirement to set `st_atime'.  */
 extern int _diskfs_noatime;
 
+/* This enables SysV style group behaviour.  New nodes inherit the GID
+   of the user creating them unless the SGID bit is set of the parent
+   directory.  */
+extern int _diskfs_noinheritdirgroup;
+
 /* This is the -C argument value.  */
 extern char *_diskfs_chroot_directory;
 
@@ -51,6 +56,8 @@
 #define OPT_SUID_OK    600     /* --suid-ok */
 #define OPT_EXEC_OK    601     /* --exec-ok */
 #define OPT_ATIME      602     /* --atime */
+#define OPT_NO_INHERIT_DIR_GROUP       603     /* --no-inherit-dir-group */
+#define OPT_INHERIT_DIR_GROUP          604     /* --inherit-dir-group */
 
 /* Common value for diskfs_common_options and diskfs_default_sync_interval. */
 #define DEFAULT_SYNC_INTERVAL 5
 

-- 
`Rhubarb is no Egyptian god.' Debian http://www.debian.org brinkmd@debian.org
Marcus Brinkmann              GNU    http://www.gnu.org    marcus@gnu.org
Marcus.Brinkmann@ruhr-uni-bochum.de
http://www.marcus-brinkmann.de



reply via email to

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