diff --git a/ChangeLog b/ChangeLog index de82d1b1..66a0bcb6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2007-12-29 Nicolas François + + * NEWS, src/newusers.c: Added support for gshadow. + 2007-12-29 Nicolas François * NEWS, src/newusers.c: Do not add the new user to the group's diff --git a/NEWS b/NEWS index c07867a4..da9d44b6 100644 --- a/NEWS +++ b/NEWS @@ -31,6 +31,7 @@ shadow-4.1.0 -> shadow-4.1.1 UNRELEASED - 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. + * Added support for gshadow. shadow-4.0.18.2 -> shadow-4.1.0 09-12-2008 diff --git a/src/newusers.c b/src/newusers.c index 4d95f754..26a34967 100644 --- a/src/newusers.c +++ b/src/newusers.c @@ -53,6 +53,7 @@ #include "groupio.h" #include "nscd.h" #include "pwio.h" +#include "sgroupio.h" #include "shadowio.h" /* * Global variables @@ -65,6 +66,9 @@ static char *crypt_method = NULL; static long sha_rounds = 5000; static int is_shadow; +#ifdef SHADOWGRP +static int is_shadow_grp; +#endif /* local function prototypes */ static void usage (void); @@ -110,6 +114,9 @@ static int add_group (const char *name, const char *gid, gid_t * ngid) struct group grent; char *members[1]; int i; +#ifdef SHADOWGRP + const struct sgrp *sg; +#endif /* * Start by seeing if the named group already exists. This will be @@ -119,6 +126,7 @@ static int add_group (const char *name, const char *gid, gid_t * ngid) if (NULL != grp) { /* The user will use this ID for her primary group */ *ngid = grp->gr_gid; + /* Don't check gshadow */ return 0; } @@ -152,6 +160,7 @@ static int add_group (const char *name, const char *gid, gid_t * ngid) /* The user will use this ID for her * primary group */ *ngid = grp->gr_gid; + /* Don't check gshadow */ return 0; } } @@ -191,7 +200,42 @@ static int add_group (const char *name, const char *gid, gid_t * ngid) grent.gr_mem = members; *ngid = grent.gr_gid; - return !gr_update (&grent); + +#ifdef SHADOWGRP + if (is_shadow_grp) { + sg = sgr_locate (grp->gr_name); + + if (NULL != sg) { + fprintf (stderr, + _("%s: group %s is a shadow group, but does not exist in /etc/group\n"), + Prog, grp->gr_name); + return -1; + } + } +#endif + + if (gr_update (&grent) == 0) { + return -1; + } + +#ifdef SHADOWGRP + if (is_shadow_grp) { + struct sgrp sgrent; + sgrent.sg_name = grent.gr_name; + sgrent.sg_passwd = "*"; /* XXX warning: const */ + sgrent.sg_adm = NULL; + sgrent.sg_mem = members; + + if (sgr_update (&sgrent) == 0) { + fprintf (stderr, + _("%s: group %s created, failure during the creation of the corresponding gshadow group\n"), + Prog, grent.gr_name); + return -1; + } + } +#endif + + return 0; } /* @@ -557,6 +601,10 @@ int main (int argc, char **argv) is_shadow = spw_file_present (); +#ifdef SHADOWGRP + is_shadow_grp = sgr_file_present (); +#endif + open_files (); /*