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/group/groupadd.c
+++ new/usr/src/cmd/oamuser/group/groupadd.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License, Version 1.0 only
6 6 * (the "License"). You may not use this file except in compliance
7 7 * with the License.
8 8 *
9 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 * or http://www.opensolaris.org/os/licensing.
11 11 * See the License for the specific language governing permissions
12 12 * and limitations under the License.
13 13 *
14 14 * When distributing Covered Code, include this CDDL HEADER in each
15 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 16 * If applicable, add the following below this CDDL HEADER, with the
17 17 * fields enclosed by brackets "[]" replaced with your own identifying
18 18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 19 *
↓ open down ↓ |
19 lines elided |
↑ open up ↑ |
20 20 * CDDL HEADER END
21 21 */
22 22 /*
23 23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 28 /* All Rights Reserved */
29 29
30 -
31 -#pragma ident "%Z%%M% %I% %E% SMI"
30 +/*
31 + * Copyright (c) 2013 RackTop Systems.
32 + */
32 33
33 34 #include <sys/types.h>
35 +#include <sys/param.h>
34 36 #include <stdio.h>
35 37 #include <stdlib.h>
36 38 #include <ctype.h>
37 39 #include <limits.h>
38 40 #include <userdefs.h>
39 41 #include <users.h>
40 42 #include <errno.h>
43 +#include <libcmdutils.h>
41 44 #include "messages.h"
42 45
43 46 extern int errmsg();
44 -extern gid_t findnextgid();
45 47 extern int valid_gid(), add_group();
46 48
47 49 /*
48 50 * groupadd [-g gid [-o]] group
49 51 *
50 52 * This command adds new groups to the system. Arguments are:
51 53 *
52 54 * gid - a gid_t less than MAXUID
53 55 * group - a string of printable characters excluding colon(:) and less
54 56 * than MAXGLEN characters long.
55 57 */
56 58
57 59 char *cmdname = "groupadd";
58 60
59 61 int
60 62 main(int argc, char *argv[])
61 63 {
62 64 int ch; /* return from getopt */
63 65 gid_t gid; /* group id */
64 66 int oflag = 0; /* flags */
65 67 int rc;
66 68 char *gidstr = NULL; /* gid from command line */
67 69 char *grpname; /* group name from command line */
68 70 int warning;
69 71
70 72 while ((ch = getopt(argc, argv, "g:o")) != EOF)
71 73 switch (ch) {
72 74 case 'g':
73 75 gidstr = optarg;
74 76 break;
75 77 case 'o':
76 78 oflag++;
77 79 break;
78 80 case '?':
79 81 errmsg(M_AUSAGE);
80 82 exit(EX_SYNTAX);
81 83 }
82 84
83 85 if ((oflag && !gidstr) || optind != argc - 1) {
84 86 errmsg(M_AUSAGE);
85 87 exit(EX_SYNTAX);
86 88 }
87 89
88 90 grpname = argv[optind];
89 91
90 92 switch (valid_gname(grpname, NULL, &warning)) {
91 93 case INVALID:
92 94 errmsg(M_GRP_INVALID, grpname);
93 95 exit(EX_BADARG);
94 96 /*NOTREACHED*/
95 97 case NOTUNIQUE:
96 98 errmsg(M_GRP_USED, grpname);
97 99 exit(EX_NAME_EXISTS);
98 100 /*NOTREACHED*/
99 101 }
100 102 if (warning)
101 103 warningmsg(warning, grpname);
102 104
103 105 if (gidstr) {
104 106 /* Given a gid string - validate it */
105 107 char *ptr;
106 108
107 109 errno = 0;
108 110 gid = (gid_t)strtol(gidstr, &ptr, 10);
109 111
110 112 if (*ptr || errno == ERANGE) {
111 113 errmsg(M_GID_INVALID, gidstr);
112 114 exit(EX_BADARG);
113 115 }
114 116
115 117 switch (valid_gid(gid, NULL)) {
116 118 case RESERVED:
117 119 errmsg(M_RESERVED, gid);
118 120 break;
119 121
120 122 case NOTUNIQUE:
121 123 if (!oflag) {
122 124 errmsg(M_GRP_USED, gidstr);
123 125 exit(EX_ID_EXISTS);
124 126 }
125 127 break;
126 128
127 129 case INVALID:
128 130 errmsg(M_GID_INVALID, gidstr);
↓ open down ↓ |
74 lines elided |
↑ open up ↑ |
129 131 exit(EX_BADARG);
130 132
131 133 case TOOBIG:
132 134 errmsg(M_TOOBIG, gid);
133 135 exit(EX_BADARG);
134 136
135 137 }
136 138
137 139 } else {
138 140
139 - if ((gid = findnextgid()) < 0) {
141 + if (findnextgid(DEFRID+1, MAXUID, &gid) != 0) {
140 142 errmsg(M_GID_INVALID, "default id");
141 143 exit(EX_ID_EXISTS);
142 144 }
143 145
144 146 }
145 147
146 148 if ((rc = add_group(grpname, gid)) != EX_SUCCESS)
147 149 errmsg(M_UPDATE, "created");
148 150
149 151 return (rc);
150 152 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX