4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
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]
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 * Copyright (c) 2013 RackTop Systems.
34 #include <sys/types.h>
35 #include <sys/param.h>
43 #include <libcmdutils.h>
47 extern int valid_gid(), add_group();
50 * groupadd [-g gid [-o]] group
52 * This command adds new groups to the system. Arguments are:
54 * gid - a gid_t less than MAXUID
55 * group - a string of printable characters excluding colon(:) and less
56 * than MAXGLEN characters long.
59 char *cmdname
= "groupadd";
62 main(int argc
, char *argv
[])
64 int ch
; /* return from getopt */
65 gid_t gid
; /* group id */
66 int oflag
= 0; /* flags */
68 char *gidstr
= NULL
; /* gid from command line */
69 char *grpname
; /* group name from command line */
72 while ((ch
= getopt(argc
, argv
, "g:o")) != EOF
)
85 if ((oflag
&& !gidstr
) || optind
!= argc
- 1) {
90 grpname
= argv
[optind
];
92 switch (valid_gname(grpname
, NULL
, &warning
)) {
94 errmsg(M_GRP_INVALID
, grpname
);
98 errmsg(M_GRP_USED
, grpname
);
103 warningmsg(warning
, grpname
);
106 /* Given a gid string - validate it */
110 gid
= (gid_t
)strtol(gidstr
, &ptr
, 10);
112 if (*ptr
|| errno
== ERANGE
) {
113 errmsg(M_GID_INVALID
, gidstr
);
117 switch (valid_gid(gid
, NULL
)) {
119 errmsg(M_RESERVED
, gid
);
124 errmsg(M_GRP_USED
, gidstr
);
130 errmsg(M_GID_INVALID
, gidstr
);
134 errmsg(M_TOOBIG
, gid
);
141 if (findnextgid(DEFRID
+1, MAXUID
, &gid
) != 0) {
142 errmsg(M_GID_INVALID
, "default id");
148 if ((rc
= add_group(grpname
, gid
)) != EX_SUCCESS
)
149 errmsg(M_UPDATE
, "created");