]> granicus.if.org Git - shadow/commitdiff
find_new_gid is never called when an
authornekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Fri, 28 Dec 2007 10:30:39 +0000 (10:30 +0000)
committernekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Fri, 28 Dec 2007 10:30:39 +0000 (10:30 +0000)
GID is specified with -g. Simplify find_new_gid accordingly.

ChangeLog
src/groupadd.c

index 33f573e2af49073b407de5ee67e4e15aac6f147f..edd2f08e284d0b571c24b0e7f937c89ed7a859e2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,8 @@
        cannot exist at that time. Remove the check.
        * src/groupadd.c (find_new_gid): If oflg is set, gflg is also set.
        Use (!gflg), which is clearer than (!gflg || !oflg).
+       * src/groupadd.c (find_new_gid): find_new_gid is never called when an
+       GID is specified with -g. Simplify find_new_gid accordingly.
 
 2007-12-28  Nicolas François  <nicolas.francois@centraliens.net>
 
index 1eb56f767fa09a88bbf38847878fa289ca869136..aba4e361d588d1d14532fed404f60ff95557d17a 100644 (file)
@@ -31,6 +31,7 @@
 
 #ident "$Id$"
 
+#include <assert.h>
 #include <ctype.h>
 #include <fcntl.h>
 #include <getopt.h>
@@ -190,51 +191,33 @@ static void grp_update (void)
  * find_new_gid - find the next available GID
  *
  *     find_new_gid() locates the next highest unused GID in the group
- *     file, or checks the given group ID against the existing ones for
- *     uniqueness.
+ *     file.
  */
 static void find_new_gid (void)
 {
        const struct group *grp;
        gid_t gid_min, gid_max;
 
-       gid_min = getdef_unum ("GID_MIN", 1000);
-       gid_max = getdef_unum ("GID_MAX", 60000);
-
        /*
-        * Start with some GID value if the user didn't provide us with
-        * one already.
+        * It doesn't make sense to use find_new_uid(),
+        * if a GID is specified via "-g" option.
         */
+       assert (!gflg);
 
-       if (!gflg) {
-               group_id = gid_min;
-       }
+       gid_min = getdef_unum ("GID_MIN", 1000);
+       gid_max = getdef_unum ("GID_MAX", 60000);
 
        /*
-        * Search the entire group file, either looking for this GID (if the
-        * user specified one with -g) or looking for the largest unused
+        * Search the entire group file, looking for the largest unused
         * value.
         */
        setgrent ();
        while ((grp = getgrent ())) {
-               if (gflg && (group_id == grp->gr_gid)) {
-                       if (fflg) {
-                               /* turn off -g and search again */
-                               gflg = 0;
-                               setgrent ();
-                               continue;
-                       }
-                       fprintf (stderr, _("%s: GID %u is not unique\n"),
-                                Prog, (unsigned int) group_id);
-                       fail_exit (E_GID_IN_USE);
-               }
-               if (!gflg && (grp->gr_gid >= group_id)) {
-                       if (grp->gr_gid > gid_max)
-                               continue;
+               if ((grp->gr_gid >= group_id) && (grp->gr_gid <= gid_max)) {
                        group_id = grp->gr_gid + 1;
                }
        }
-       if (!gflg && (group_id == (gid_max + 1))) {
+       if (group_id == (gid_max + 1)) {
                for (group_id = gid_min; group_id < gid_max; group_id++) {
                        /* local, no need for xgetgrgid */
                        if (!getgrgid (group_id)) {