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 #pragma ident "%Z%%M% %I% %E% SMI"
33 #include <sys/types.h>
44 * groupmod -g gid [-o] | -n name group
46 * This command modifies groups on the system. Arguments are:
48 * gid - a gid_t less than UID_MAX
49 * name - a string of printable characters excluding colon (:) and less
50 * than MAXGLEN characters long.
51 * group - a string of printable characters excluding colon(:) and less
52 * than MAXGLEN characters long.
55 extern int valid_gid(), mod_group();
58 char *cmdname
= "groupmod";
61 main(int argc
, char *argv
[])
63 int ch
; /* return from getopt */
64 gid_t gid
; /* group id */
65 int oflag
= 0; /* flags */
66 int valret
; /* return from valid_gid() */
67 char *gidstr
= NULL
; /* gid from command line */
68 char *newname
= NULL
; /* new group name with -n option */
69 char *grpname
; /* group name from command line */
72 oflag
= 0; /* flags */
74 while ((ch
= getopt(argc
, argv
, "g:on:")) != EOF
) {
91 if ((oflag
&& !gidstr
) || optind
!= argc
- 1) {
96 grpname
= argv
[optind
];
99 /* convert gidstr to integer */
103 gid
= (gid_t
)strtol(gidstr
, &ptr
, 10);
105 if (*ptr
|| errno
== ERANGE
) {
106 errmsg(M_GID_INVALID
, gidstr
);
110 switch (valid_gid(gid
, NULL
)) {
112 errmsg(M_RESERVED
, gid
);
117 errmsg(M_GRP_USED
, gidstr
);
123 errmsg(M_GID_INVALID
, gidstr
);
128 errmsg(M_TOOBIG
, gid
);
137 switch (valid_gname(newname
, NULL
, &warning
)) {
139 errmsg(M_GRP_INVALID
, newname
);
142 errmsg(M_GRP_USED
, newname
);
143 exit(EX_NAME_EXISTS
);
146 warningmsg(warning
, newname
);
149 if ((valret
= mod_group(grpname
, gid
, newname
)) != EX_SUCCESS
) {
150 if (valret
== EX_NAME_NOT_EXIST
)
151 errmsg(M_NO_GROUP
, grpname
);
153 errmsg(M_UPDATE
, "modified");