Do not add the new user to the group's members, because the group is already
the primary group of the new user.
This commit is contained in:
parent
67b9c423fe
commit
098173e1df
@ -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>
|
2007-12-29 Nicolas François <nicolas.francois@centraliens.net>
|
||||||
|
|
||||||
newusers cleanups
|
newusers cleanups
|
||||||
|
3
NEWS
3
NEWS
@ -28,6 +28,9 @@ shadow-4.1.0 -> shadow-4.1.1 UNRELEASED
|
|||||||
- vipw/vigr
|
- vipw/vigr
|
||||||
* Recommend editing the shadowed (resp. regular) file if the regular (resp.
|
* Recommend editing the shadowed (resp. regular) file if the regular (resp.
|
||||||
shadowed) file was edited.
|
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
|
shadow-4.0.18.2 -> shadow-4.1.0 09-12-2008
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ static int add_group (const char *name, const char *gid, gid_t * ngid)
|
|||||||
const struct passwd *pwd;
|
const struct passwd *pwd;
|
||||||
const struct group *grp;
|
const struct group *grp;
|
||||||
struct group grent;
|
struct group grent;
|
||||||
char *members[2];
|
char *members[1];
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -117,21 +117,9 @@ static int add_group (const char *name, const char *gid, gid_t * ngid)
|
|||||||
*/
|
*/
|
||||||
grp = gr_locate (gid);
|
grp = gr_locate (gid);
|
||||||
if (NULL != grp) {
|
if (NULL != grp) {
|
||||||
add_member:
|
/* The user will use this ID for her primary group */
|
||||||
grent = *grp;
|
*ngid = grp->gr_gid;
|
||||||
*ngid = grent.gr_gid;
|
return 0;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -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')) {
|
} else if ((gid[0] >= '0') && (gid[0] <= '9')) {
|
||||||
/*
|
/*
|
||||||
* The GID is a number, which means either this is a brand
|
* The GID is a number, which means either this is a brand
|
||||||
* new group, or an existing group. For existing groups I
|
* new group, or an existing group.
|
||||||
* just add myself as a member, just like I did earlier.
|
|
||||||
*/
|
*/
|
||||||
i = atoi (gid);
|
i = atoi (gid);
|
||||||
for (gr_rewind (); (grp = gr_next ());) {
|
for (gr_rewind (); (grp = gr_next ());) {
|
||||||
if (grp->gr_gid == (unsigned int)i) {
|
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 {
|
} 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_passwd = "x"; /* XXX warning: const */
|
||||||
grent.gr_gid = i;
|
grent.gr_gid = i;
|
||||||
members[0] = xstrdup (name);
|
members[0] = NULL;
|
||||||
members[1] = (char *) 0;
|
|
||||||
grent.gr_mem = members;
|
grent.gr_mem = members;
|
||||||
|
|
||||||
*ngid = grent.gr_gid;
|
*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
|
* Now the fields are processed one by one. The first field
|
||||||
* to be processed is the group name. A new group will be
|
* to be processed is the group name. A new group will be
|
||||||
* created if the group name is non-numeric and does not
|
* 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
|
* 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
|
* be figured out and that value will be a candidate for a
|
||||||
* new group, if that group ID exists, a whole new group ID
|
* new group, if that group ID exists, a whole new group ID
|
||||||
|
Loading…
Reference in New Issue
Block a user