[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
patch for sysv-style group behaviour
From: |
Marcus Brinkmann |
Subject: |
patch for sysv-style group behaviour |
Date: |
Mon, 29 Apr 2002 20:38:27 -0400 |
User-agent: |
Mutt/1.3.25i |
Hi,
here is a patch for sysv style group behaviour. New nodes are created
with a gid:
* If the parent dir is sgid:
+ The node inherits the group of the parent dir.
+ If the node is a dir, it inherits the sgid bit.
+ If the node is not a dir, and user is not in the group,
deny a requested sgid bit (this is the old default).
* If the parent dir is not sgid:
+ If the user has gids, the node is created with the first gid.
+ If the user has no gids, the node inherits the gid of the parent
dir, and a requested sgid bit is denied. This is the old behaviour.
I hope this is correct, I did not verify it against the Linux kernel
behaviour yet. And I think that for the no-user, the old default was
good enough. I gave it some basic testing. The option is named
--sysv-groups. It can be switched off with --bsd-groups (as
--no-sysv-groups is quite lame). Or maybe we should have
--group-style=bsd|sysv?
Please let me know what you think,
Marcus
Index: ChangeLog
===================================================================
RCS file: /cvsroot/hurd/hurd/libdiskfs/ChangeLog,v
retrieving revision 1.171
diff -u -p -r1.171 ChangeLog
--- ChangeLog 26 Mar 2002 19:06:57 -0000 1.171
+++ ChangeLog 30 Apr 2002 00:26:24 -0000
@@ -1,3 +1,20 @@
+2002-04-30 Marcus Brinkmann <marcus@gnu.org>
+
+ * priv.h: Add OPT_SYSV_GROUPS and OPT_BSD_GROUPS.
+ (_diskfs_sysv_groups): New declaration.
+ * node-create.c (_diskfs_sysv_groups): New variable.
+ (diskfs_create_node): Implement SysV group behaviour.
+ * opts-common.c (diskfs_common_options): Add --sysv-groups and
+ --bsd-groups.
+ * opts-append-std.c (diskfs_append_std_options): Add --sysv-groups
+ if set.
+ * opts-std-startup.c (parse_startup_opt): Add toggle for
+ _diskfs_sysv_groups.
+ * opts-std-runtime.c (struct parse_hook): Add sysvgroups.
+ (set_opts): Handle H->sysvgroups.
+ (parse_opt): Initialize H->sysvgroups. Handle OPT_SYSV_GROUPS and
+ OPT_BSD_GROUPS.
+
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 -p -r1.16 node-create.c
--- node-create.c 15 Apr 2001 22:44:03 -0000 1.16
+++ node-create.c 30 Apr 2002 00:26:24 -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_sysv_groups;
+
/* 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 @@ diskfs_create_node (struct node *dir,
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_sysv_groups)
+ {
+ 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 -p -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 00:26:25 -0000
@@ -42,6 +42,8 @@ diskfs_append_std_options (char **argz,
err = argz_add (argz, argz_len, "--no-exec");
if (!err && _diskfs_noatime)
err = argz_add (argz, argz_len, "--no-atime");
+ if (!err && _diskfs_sysv_groups)
+ err = argz_add (argz, argz_len, "--sysv-groups");
if (! err)
{
Index: opts-common.c
===================================================================
RCS file: /cvsroot/hurd/hurd/libdiskfs/opts-common.c,v
retrieving revision 1.5
diff -u -p -r1.5 opts-common.c
--- opts-common.c 14 May 2000 20:35:53 -0000 1.5
+++ opts-common.c 30 Apr 2002 00:26:25 -0000
@@ -47,5 +47,8 @@ const struct argp_option diskfs_common_o
"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"},
+ {"sysv-groups", OPT_SYSV_GROUPS, 0, 0, "Create new nodes with gid of user"},
+ {"bsd-groups", OPT_BSD_GROUPS, 0, 0,
+ "Create new nodes with gid of parent dir (default)"},
{0, 0}
};
Index: opts-std-runtime.c
===================================================================
RCS file: /cvsroot/hurd/hurd/libdiskfs/opts-std-runtime.c,v
retrieving revision 1.10
diff -u -p -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 00:26:25 -0000
@@ -32,7 +32,8 @@ std_runtime_options[] =
struct parse_hook
{
- int readonly, sync, sync_interval, remount, nosuid, noexec, noatime;
+ int readonly, sync, sync_interval, remount, nosuid, noexec, noatime,
+ sysvgroups;
};
/* Implement the options in H, and free H. */
@@ -79,6 +80,8 @@ set_opts (struct parse_hook *h)
_diskfs_noexec = h->noexec;
if (h->noatime != -1)
_diskfs_noatime = h->noatime;
+ if (h->sysvgroups != -1)
+ _diskfs_sysv_groups = h->sysvgroups;
free (h);
@@ -101,6 +104,8 @@ parse_opt (int opt, char *arg, struct ar
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_SYSV_GROUPS: h->sysvgroups = 1; break;
+ case OPT_BSD_GROUPS: h->sysvgroups = 0; break;
case 'n': h->sync_interval = 0; h->sync = 0; break;
case 's':
if (arg)
@@ -124,7 +129,7 @@ parse_opt (int opt, char *arg, struct ar
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->sysvgroups = -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 -p -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 00:26:26 -0000
@@ -82,6 +82,7 @@ parse_startup_opt (int opt, char *arg, s
TOGGLE (_diskfs_nosuid, 'S', OPT_SUID_OK);
TOGGLE (_diskfs_noexec, 'E', OPT_EXEC_OK);
TOGGLE (_diskfs_noatime, 'A', OPT_ATIME);
+ TOGGLE (_diskfs_sysv_groups, OPT_SYSV_GROUPS, OPT_BSD_GROUPS);
#undef TOGGLE
case 's':
Index: priv.h
===================================================================
RCS file: /cvsroot/hurd/hurd/libdiskfs/priv.h,v
retrieving revision 1.44
diff -u -p -r1.44 priv.h
--- priv.h 6 May 2001 00:49:27 -0000 1.44
+++ priv.h 30 Apr 2002 00:26:26 -0000
@@ -35,6 +35,11 @@ extern int _diskfs_nosuid, _diskfs_noexe
/* 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_sysv_groups;
+
/* This is the -C argument value. */
extern char *_diskfs_chroot_directory;
@@ -51,6 +56,8 @@ extern const struct argp_option diskfs_c
#define OPT_SUID_OK 600 /* --suid-ok */
#define OPT_EXEC_OK 601 /* --exec-ok */
#define OPT_ATIME 602 /* --atime */
+#define OPT_SYSV_GROUPS 603 /* --sysv-groups */
+#define OPT_BSD_GROUPS 604 /* --bsd-groups */
/* Common value for diskfs_common_options and diskfs_default_sync_interval. */
#define DEFAULT_SYNC_INTERVAL 5
- patch for sysv-style group behaviour,
Marcus Brinkmann <=