| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: user.c,v 1.121 2009/03/11 14:18:03 christos Exp $ */ | | 1 | /* $NetBSD: user.c,v 1.122 2009/03/18 04:59:45 mike Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1999 Alistair G. Crooks. All rights reserved. | | 4 | * Copyright (c) 1999 Alistair G. Crooks. All rights reserved. |
5 | * Copyright (c) 2005 Liam J. Foy. All rights reserved. | | 5 | * Copyright (c) 2005 Liam J. Foy. All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -23,27 +23,27 @@ | | | @@ -23,27 +23,27 @@ |
23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE | | 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
25 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 25 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | | 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | | 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | #include <sys/cdefs.h> | | 31 | #include <sys/cdefs.h> |
32 | | | 32 | |
33 | #ifndef lint | | 33 | #ifndef lint |
34 | __COPYRIGHT("@(#) Copyright (c) 1999\ | | 34 | __COPYRIGHT("@(#) Copyright (c) 1999\ |
35 | The NetBSD Foundation, Inc. All rights reserved."); | | 35 | The NetBSD Foundation, Inc. All rights reserved."); |
36 | __RCSID("$NetBSD: user.c,v 1.121 2009/03/11 14:18:03 christos Exp $"); | | 36 | __RCSID("$NetBSD: user.c,v 1.122 2009/03/18 04:59:45 mike Exp $"); |
37 | #endif | | 37 | #endif |
38 | | | 38 | |
39 | #include <sys/types.h> | | 39 | #include <sys/types.h> |
40 | #include <sys/param.h> | | 40 | #include <sys/param.h> |
41 | #include <sys/stat.h> | | 41 | #include <sys/stat.h> |
42 | | | 42 | |
43 | #include <ctype.h> | | 43 | #include <ctype.h> |
44 | #include <dirent.h> | | 44 | #include <dirent.h> |
45 | #include <err.h> | | 45 | #include <err.h> |
46 | #include <fcntl.h> | | 46 | #include <fcntl.h> |
47 | #include <grp.h> | | 47 | #include <grp.h> |
48 | #ifdef EXTENSIONS | | 48 | #ifdef EXTENSIONS |
49 | #include <login_cap.h> | | 49 | #include <login_cap.h> |
| @@ -2340,26 +2340,30 @@ groupmod(int argc, char **argv) | | | @@ -2340,26 +2340,30 @@ groupmod(int argc, char **argv) |
2340 | } | | 2340 | } |
2341 | argc -= optind; | | 2341 | argc -= optind; |
2342 | argv += optind; | | 2342 | argv += optind; |
2343 | if (argc != 1) { | | 2343 | if (argc != 1) { |
2344 | usermgmt_usage("groupmod"); | | 2344 | usermgmt_usage("groupmod"); |
2345 | } | | 2345 | } |
2346 | checkeuid(); | | 2346 | checkeuid(); |
2347 | if (gid < 0 && newname == NULL) { | | 2347 | if (gid < 0 && newname == NULL) { |
2348 | errx(EXIT_FAILURE, "Nothing to change"); | | 2348 | errx(EXIT_FAILURE, "Nothing to change"); |
2349 | } | | 2349 | } |
2350 | if (dupgid && gid < 0) { | | 2350 | if (dupgid && gid < 0) { |
2351 | errx(EXIT_FAILURE, "Duplicate which gid?"); | | 2351 | errx(EXIT_FAILURE, "Duplicate which gid?"); |
2352 | } | | 2352 | } |
| | | 2353 | if (!dupgid && getgrgid((gid_t) gid) != NULL) { |
| | | 2354 | errx(EXIT_FAILURE, "Can't modify group: gid %d is a duplicate", |
| | | 2355 | gid); |
| | | 2356 | } |
2353 | if ((grp = find_group_info(*argv)) == NULL) { | | 2357 | if ((grp = find_group_info(*argv)) == NULL) { |
2354 | errx(EXIT_FAILURE, "Can't find group `%s' to modify", *argv); | | 2358 | errx(EXIT_FAILURE, "Can't find group `%s' to modify", *argv); |
2355 | } | | 2359 | } |
2356 | if (!is_local(*argv, _PATH_GROUP)) { | | 2360 | if (!is_local(*argv, _PATH_GROUP)) { |
2357 | errx(EXIT_FAILURE, "Group `%s' must be a local group", *argv); | | 2361 | errx(EXIT_FAILURE, "Group `%s' must be a local group", *argv); |
2358 | } | | 2362 | } |
2359 | if (newname != NULL && !valid_group(newname)) { | | 2363 | if (newname != NULL && !valid_group(newname)) { |
2360 | warnx("Invalid group name `%s'", newname); | | 2364 | warnx("Invalid group name `%s'", newname); |
2361 | } | | 2365 | } |
2362 | cc = snprintf(buf, sizeof(buf), "%s:%s:%d:", | | 2366 | cc = snprintf(buf, sizeof(buf), "%s:%s:%d:", |
2363 | (newname) ? newname : grp->gr_name, | | 2367 | (newname) ? newname : grp->gr_name, |
2364 | grp->gr_passwd, | | 2368 | grp->gr_passwd, |
2365 | (gid < 0) ? grp->gr_gid : gid); | | 2369 | (gid < 0) ? grp->gr_gid : gid); |