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>

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/oamuser/user/useradd.c
          +++ new/usr/src/cmd/oamuser/user/useradd.c
↓ open down ↓ 18 lines elided ↑ open up ↑
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
  22   22   * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  23   23   * Use is subject to license terms.
  24   24   */
  25   25  
  26   26  /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
  27   27  /*        All Rights Reserved   */
  28   28  
       29 +/*
       30 + * Copyright (c) 2013 RackTop Systems.
       31 + */
  29   32  
  30   33  #include        <sys/types.h>
  31   34  #include        <sys/stat.h>
  32   35  #include        <sys/param.h>
  33   36  #include        <stdio.h>
  34   37  #include        <stdlib.h>
  35   38  #include        <ctype.h>
  36   39  #include        <limits.h>
  37   40  #include        <string.h>
  38   41  #include        <userdefs.h>
  39   42  #include        <errno.h>
  40   43  #include        <project.h>
  41   44  #include        <unistd.h>
  42   45  #include        <user_attr.h>
       46 +#include        <libcmdutils.h>
  43   47  #include        "users.h"
  44   48  #include        "messages.h"
  45   49  #include        "userdisp.h"
  46   50  #include        "funcs.h"
  47   51  
  48   52  /*
  49   53   *  useradd [-u uid [-o] | -g group | -G group [[, group]...] | -d dir [-m]
  50   54   *              | -s shell | -c comment | -k skel_dir | -b base_dir] ]
  51   55   *              [ -A authorization [, authorization ...]]
  52   56   *              [ -P profile [, profile ...]]
↓ open down ↓ 22 lines elided ↑ open up ↑
  75   79   *      role - One or more comma-separated role names defined in user_attr(4)
  76   80   *      project - One or more comma-separated project names or numbers
  77   81   *
  78   82   */
  79   83  
  80   84  extern struct userdefs *getusrdef();
  81   85  extern void dispusrdef();
  82   86  
  83   87  static void cleanup();
  84   88  
  85      -extern uid_t findnextuid(void);
  86   89  extern int check_perm(), valid_expire();
  87   90  extern int putusrdef(), valid_uid();
  88   91  extern int call_passmgmt(), edit_group(), create_home();
  89   92  extern int edit_project();
  90   93  extern int **valid_lgroup();
  91   94  extern projid_t **valid_lproject();
  92   95  extern void update_def(struct userdefs *);
  93   96  extern void import_def(struct userdefs *);
  94   97  
  95   98  static uid_t uid;                       /* new uid */
↓ open down ↓ 29 lines elided ↑ open up ↑
 125  128  } path_opt_t;
 126  129  
 127  130  
 128  131  static void valid_input(path_opt_t, const char *);
 129  132  
 130  133  int
 131  134  main(argc, argv)
 132  135  int argc;
 133  136  char *argv[];
 134  137  {
 135      -        int ch, ret, mflag = 0, oflag = 0, Dflag = 0, **gidlist;
 136      -        projid_t **projlist;
      138 +        int ch, ret, mflag = 0, oflag = 0, Dflag = 0, **gidlist = NULL;
      139 +        projid_t **projlist = NULL;
 137  140          char *ptr;                      /* loc in a str, may be set by strtol */
 138  141          struct group *g_ptr;
 139  142          struct project p_ptr;
 140  143          char mybuf[PROJECT_BUFSZ];
 141  144          struct stat statbuf;            /* status buffer for stat */
 142  145          int warning;
 143  146          int busy = 0;
 144  147          char **nargv;                   /* arguments for execvp of passmgmt */
 145  148          int argindex;                   /* argument index into nargv */
 146  149  
↓ open down ↓ 271 lines elided ↑ open up ↑
 418  421                          errmsg(M_RESERVED, uid);
 419  422                          break;
 420  423                  case TOOBIG:
 421  424                          errmsg(M_TOOBIG, "uid", uid);
 422  425                          exit(EX_BADARG);
 423  426                          break;
 424  427                  }
 425  428  
 426  429          } else {
 427  430  
 428      -                if ((uid = findnextuid()) < 0) {
      431 +                if (findnextuid(DEFRID+1, MAXUID, &uid) != 0) {
 429  432                          errmsg(M_INVALID, "default id", "user id");
 430  433                          exit(EX_ID_EXISTS);
 431  434                  }
 432  435          }
 433  436  
 434  437          if (group != NULL) {
 435  438                  switch (valid_group(group, &g_ptr, &warning)) {
 436  439                  case INVALID:
 437  440                          errmsg(M_INVALID, group, "group id");
 438  441                          exit(EX_BADARG);
↓ open down ↓ 188 lines elided ↑ open up ↑
 627  630                  case PEX_BADUID:
 628  631                          /*
 629  632                           * The uid has been taken. If it was specified by a
 630  633                           * user, then we must fail. Otherwise, keep trying
 631  634                           * to get a good uid until we run out of IDs.
 632  635                           */
 633  636                          if (uidstr != NULL) {
 634  637                                  errmsg(M_UID_USED, uid);
 635  638                                  exit(EX_ID_EXISTS);
 636  639                          } else {
 637      -                                if ((uid = findnextuid()) < 0) {
      640 +                                if (findnextuid(DEFRID+1, MAXUID, &uid) != 0) {
 638  641                                          errmsg(M_INVALID, "default id",
 639  642                                              "user id");
 640  643                                          exit(EX_ID_EXISTS);
 641  644                                  }
 642  645                                  (void) sprintf(uidstring, "%u", uid);
 643  646                          }
 644  647                          break;
 645  648  
 646  649                  case PEX_BADNAME:
 647  650                          /* invalid loname */
↓ open down ↓ 108 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX