]> granicus.if.org Git - shadow/commitdiff
Do not add the new user to the group's members, because the group is already
authornekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Sat, 29 Dec 2007 17:05:13 +0000 (17:05 +0000)
committernekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Sat, 29 Dec 2007 17:05:13 +0000 (17:05 +0000)
the primary group of the new user.

ChangeLog
NEWS
src/newusers.c

index a6dfe87f5ae224e156fcb917943bf2e03c414021..de82d1b1c49b1e0407bf8648ba1d40b14452e6a6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2007-12-29  Nicolas François  <nicolas.francois@centraliens.net>
+
+       * NEWS, src/newusers.c: Do not add the new user to the group's
+       members, because the group is already the primary group of the new
+       user.
+
 2007-12-29  Nicolas François  <nicolas.francois@centraliens.net>
 
        newusers cleanups
diff --git a/NEWS b/NEWS
index f2c6487226379716331503f314b7b2b8840fb2c2..c07867a497f340304db5328bd4622db3eaef3ec7 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -28,6 +28,9 @@ shadow-4.1.0 -> shadow-4.1.1                                          UNRELEASED
 - vipw/vigr
   * Recommend editing the shadowed (resp. regular) file if the regular (resp.
     shadowed) file was edited.
+- newusers
+  * The new users are no more added to the list of members of their groups
+    because the membership is already set by their primary group.
 
 shadow-4.0.18.2 -> shadow-4.1.0                                                09-12-2008
 
index 80ddac9ec48ec834fb02f7bc71011f708d204114..4d95f7549bcac6330b482edc1bf0294ac700f584 100644 (file)
@@ -108,7 +108,7 @@ static int add_group (const char *name, const char *gid, gid_t * ngid)
        const struct passwd *pwd;
        const struct group *grp;
        struct group grent;
-       char *members[2];
+       char *members[1];
        int i;
 
        /*
@@ -117,21 +117,9 @@ static int add_group (const char *name, const char *gid, gid_t * ngid)
         */
        grp = gr_locate (gid);
        if (NULL != grp) {
-             add_member:
-               grent = *grp;
-               *ngid = grent.gr_gid;
-               for (i = 0; grent.gr_mem[i] != (char *) 0; i++) {
-                       if (strcmp (grent.gr_mem[i], name) == 0) {
-                               return 0;
-                       }
-               }
-
-               grent.gr_mem = (char **) xmalloc (sizeof (char *) * (i + 2));
-               memcpy (grent.gr_mem, grp->gr_mem, sizeof (char *) * (i + 2));
-               grent.gr_mem[i] = xstrdup (name);
-               grent.gr_mem[i + 1] = (char *) 0;
-
-               return !gr_update (&grent);
+               /* The user will use this ID for her primary group */
+               *ngid = grp->gr_gid;
+               return 0;
        }
 
        /*
@@ -156,13 +144,15 @@ static int add_group (const char *name, const char *gid, gid_t * ngid)
        } else if ((gid[0] >= '0') && (gid[0] <= '9')) {
                /*
                 * The GID is a number, which means either this is a brand
-                * new group, or an existing group. For existing groups I
-                * just add myself as a member, just like I did earlier.
+                * new group, or an existing group.
                 */
                i = atoi (gid);
                for (gr_rewind (); (grp = gr_next ());) {
                        if (grp->gr_gid == (unsigned int)i) {
-                               goto add_member;
+                               /* The user will use this ID for her
+                                * primary group */
+                               *ngid = grp->gr_gid;
+                               return 0;
                        }
                }
        } else {
@@ -197,8 +187,7 @@ static int add_group (const char *name, const char *gid, gid_t * ngid)
 
        grent.gr_passwd = "x";  /* XXX warning: const */
        grent.gr_gid = i;
-       members[0] = xstrdup (name);
-       members[1] = (char *) 0;
+       members[0] = NULL;
        grent.gr_mem = members;
 
        *ngid = grent.gr_gid;
@@ -615,7 +604,10 @@ int main (int argc, char **argv)
                 * Now the fields are processed one by one. The first field
                 * to be processed is the group name. A new group will be
                 * created if the group name is non-numeric and does not
-                * already exist. The named user will be the only member. If
+                * already exist. If the group name is a number (which is not
+                * an existing GID), a group with the same name as the user
+                * will be created, with the given GID. The given or created
+                * group will be the primary group of the user. If
                 * there is no named group to be a member of, the UID will
                 * be figured out and that value will be a candidate for a
                 * new group, if that group ID exists, a whole new group ID