Print this page
4078 groupadd execs getent unnecessarily
Reviewed by: Rich Lowe <richlowe@richlowe.net>
Reviewed by: Gary Mills <gary_mills@fastmail.fm>
Reviewed by: Milan Jurik <milan.jurik@xylab.cz>
Reviewed by: Gordon Ross <Gordon.W.Ross@gmail.com>

@@ -24,10 +24,13 @@
  */
 
 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
 /*        All Rights Reserved   */
 
+/*
+ * Copyright (c) 2013 RackTop Systems.
+ */
 
 #include        <sys/types.h>
 #include        <sys/stat.h>
 #include        <sys/param.h>
 #include        <stdio.h>

@@ -38,10 +41,11 @@
 #include        <userdefs.h>
 #include        <errno.h>
 #include        <project.h>
 #include        <unistd.h>
 #include        <user_attr.h>
+#include        <libcmdutils.h>
 #include        "users.h"
 #include        "messages.h"
 #include        "userdisp.h"
 #include        "funcs.h"
 

@@ -80,11 +84,10 @@
 extern struct userdefs *getusrdef();
 extern void dispusrdef();
 
 static void cleanup();
 
-extern uid_t findnextuid(void);
 extern int check_perm(), valid_expire();
 extern int putusrdef(), valid_uid();
 extern int call_passmgmt(), edit_group(), create_home();
 extern int edit_project();
 extern int **valid_lgroup();

@@ -130,12 +133,12 @@
 int
 main(argc, argv)
 int argc;
 char *argv[];
 {
-        int ch, ret, mflag = 0, oflag = 0, Dflag = 0, **gidlist;
-        projid_t **projlist;
+        int ch, ret, mflag = 0, oflag = 0, Dflag = 0, **gidlist = NULL;
+        projid_t **projlist = NULL;
         char *ptr;                      /* loc in a str, may be set by strtol */
         struct group *g_ptr;
         struct project p_ptr;
         char mybuf[PROJECT_BUFSZ];
         struct stat statbuf;            /* status buffer for stat */

@@ -423,11 +426,11 @@
                         break;
                 }
 
         } else {
 
-                if ((uid = findnextuid()) < 0) {
+                if (findnextuid(DEFRID+1, MAXUID, &uid) != 0) {
                         errmsg(M_INVALID, "default id", "user id");
                         exit(EX_ID_EXISTS);
                 }
         }
 

@@ -632,11 +635,11 @@
                          */
                         if (uidstr != NULL) {
                                 errmsg(M_UID_USED, uid);
                                 exit(EX_ID_EXISTS);
                         } else {
-                                if ((uid = findnextuid()) < 0) {
+                                if (findnextuid(DEFRID+1, MAXUID, &uid) != 0) {
                                         errmsg(M_INVALID, "default id",
                                             "user id");
                                         exit(EX_ID_EXISTS);
                                 }
                                 (void) sprintf(uidstring, "%u", uid);