Added support for gshadow.
authornekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Sat, 29 Dec 2007 17:26:28 +0000 (17:26 +0000)
committernekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Sat, 29 Dec 2007 17:26:28 +0000 (17:26 +0000)
ChangeLog
NEWS
src/newusers.c

index de82d1b1c49b1e0407bf8648ba1d40b14452e6a6..66a0bcb6acd026e56d8d5d315f3afc283af3e102 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2007-12-29  Nicolas François  <nicolas.francois@centraliens.net>
+
+       * NEWS, src/newusers.c: Added support for gshadow.
+
 2007-12-29  Nicolas François  <nicolas.francois@centraliens.net>
 
        * NEWS, src/newusers.c: Do not add the new user to the group's
diff --git a/NEWS b/NEWS
index c07867a497f340304db5328bd4622db3eaef3ec7..da9d44b603f4844a515394f5659dc90f5ba80acc 100644 (file)
--- 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
 
index 4d95f7549bcac6330b482edc1bf0294ac700f584..26a349674a5ea0bdc2bbb7bb51ca941b7b9b1e53 100644 (file)
@@ -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 ();
 
        /*