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>


  10  * or http://www.opensolaris.org/os/licensing.
  11  * See the License for the specific language governing permissions
  12  * and limitations under the License.
  13  *
  14  * When distributing Covered Code, include this CDDL HEADER in each
  15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16  * If applicable, add the following below this CDDL HEADER, with the
  17  * fields enclosed by brackets "[]" replaced with your own identifying
  18  * information: Portions Copyright [yyyy] [name of copyright owner]
  19  *
  20  * CDDL HEADER END
  21  */
  22 /*
  23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T     */
  28 /*        All Rights Reserved   */
  29 
  30 
  31 #pragma ident   "%Z%%M% %I%     %E% SMI"

  32 
  33 #include        <sys/types.h>

  34 #include        <stdio.h>
  35 #include        <stdlib.h>
  36 #include        <ctype.h>
  37 #include        <limits.h>
  38 #include        <userdefs.h>
  39 #include        <users.h>
  40 #include        <errno.h>

  41 #include        "messages.h"
  42 
  43 extern int errmsg();
  44 extern gid_t findnextgid();
  45 extern int valid_gid(), add_group();
  46 
  47 /*
  48  *  groupadd [-g gid [-o]] group
  49  *
  50  *      This command adds new groups to the system.  Arguments are:
  51  *
  52  *      gid - a gid_t less than MAXUID
  53  *      group - a string of printable characters excluding colon(:) and less
  54  *              than MAXGLEN characters long.
  55  */
  56 
  57 char *cmdname = "groupadd";
  58 
  59 int
  60 main(int argc, char *argv[])
  61 {
  62         int ch;                         /* return from getopt */
  63         gid_t gid;                      /* group id */
  64         int oflag = 0;  /* flags */


 119 
 120                 case NOTUNIQUE:
 121                         if (!oflag) {
 122                                 errmsg(M_GRP_USED, gidstr);
 123                                 exit(EX_ID_EXISTS);
 124                         }
 125                         break;
 126 
 127                 case INVALID:
 128                         errmsg(M_GID_INVALID, gidstr);
 129                         exit(EX_BADARG);
 130 
 131                 case TOOBIG:
 132                         errmsg(M_TOOBIG, gid);
 133                         exit(EX_BADARG);
 134 
 135                 }
 136 
 137         } else {
 138 
 139                 if ((gid = findnextgid()) < 0) {
 140                         errmsg(M_GID_INVALID, "default id");
 141                         exit(EX_ID_EXISTS);
 142                 }
 143 
 144         }
 145 
 146         if ((rc = add_group(grpname, gid)) != EX_SUCCESS)
 147                 errmsg(M_UPDATE, "created");
 148 
 149         return (rc);
 150 }


  10  * or http://www.opensolaris.org/os/licensing.
  11  * See the License for the specific language governing permissions
  12  * and limitations under the License.
  13  *
  14  * When distributing Covered Code, include this CDDL HEADER in each
  15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16  * If applicable, add the following below this CDDL HEADER, with the
  17  * fields enclosed by brackets "[]" replaced with your own identifying
  18  * information: Portions Copyright [yyyy] [name of copyright owner]
  19  *
  20  * CDDL HEADER END
  21  */
  22 /*
  23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T     */
  28 /*        All Rights Reserved   */
  29 
  30 /*
  31  * Copyright (c) 2013 RackTop Systems.
  32  */
  33 
  34 #include        <sys/types.h>
  35 #include        <sys/param.h>
  36 #include        <stdio.h>
  37 #include        <stdlib.h>
  38 #include        <ctype.h>
  39 #include        <limits.h>
  40 #include        <userdefs.h>
  41 #include        <users.h>
  42 #include        <errno.h>
  43 #include        <libcmdutils.h>
  44 #include        "messages.h"
  45 
  46 extern int errmsg();

  47 extern int valid_gid(), add_group();
  48 
  49 /*
  50  *  groupadd [-g gid [-o]] group
  51  *
  52  *      This command adds new groups to the system.  Arguments are:
  53  *
  54  *      gid - a gid_t less than MAXUID
  55  *      group - a string of printable characters excluding colon(:) and less
  56  *              than MAXGLEN characters long.
  57  */
  58 
  59 char *cmdname = "groupadd";
  60 
  61 int
  62 main(int argc, char *argv[])
  63 {
  64         int ch;                         /* return from getopt */
  65         gid_t gid;                      /* group id */
  66         int oflag = 0;  /* flags */


 121 
 122                 case NOTUNIQUE:
 123                         if (!oflag) {
 124                                 errmsg(M_GRP_USED, gidstr);
 125                                 exit(EX_ID_EXISTS);
 126                         }
 127                         break;
 128 
 129                 case INVALID:
 130                         errmsg(M_GID_INVALID, gidstr);
 131                         exit(EX_BADARG);
 132 
 133                 case TOOBIG:
 134                         errmsg(M_TOOBIG, gid);
 135                         exit(EX_BADARG);
 136 
 137                 }
 138 
 139         } else {
 140 
 141                 if (findnextgid(DEFRID+1, MAXUID, &gid) != 0) {
 142                         errmsg(M_GID_INVALID, "default id");
 143                         exit(EX_ID_EXISTS);
 144                 }
 145 
 146         }
 147 
 148         if ((rc = add_group(grpname, gid)) != EX_SUCCESS)
 149                 errmsg(M_UPDATE, "created");
 150 
 151         return (rc);
 152 }