Print this page
Remove include userdefs.h where not needed
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libcmdutils/common/gid.c
+++ new/usr/src/lib/libcmdutils/common/gid.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 (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
↓ open down ↓ |
25 lines elided |
↑ open up ↑ |
26 26 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
27 27 /* All Rights Reserved */
28 28
29 29 /*
30 30 * Copyright (c) 2013 RackTop Systems.
31 31 */
32 32
33 33 #include <errno.h>
34 34 #include <sys/types.h>
35 35 #include <stdio.h>
36 -#include <userdefs.h>
37 36 #include <grp.h>
38 37 #include <libcmdutils.h>
39 38
40 39 static int findunusedgid(gid_t start, gid_t stop, gid_t *ret);
41 40 static boolean_t isreservedgid(gid_t gid);
42 41
43 42 /*
44 43 * Find the highest unused uid. If the highest unused gid is "stop",
45 44 * then attempt to find a hole in the range. Returns 0 on success.
46 45 */
47 46 int
48 47 findnextgid(gid_t start, gid_t stop, gid_t *ret)
49 48 {
50 49 gid_t gid = start;
51 50 struct group *grp;
52 51 boolean_t overflow = B_FALSE;
53 52
54 53 setgrent();
55 54 for (grp = getgrent(); grp != NULL; grp = getgrent()) {
56 55 if (isreservedgid(grp->gr_gid)) /* Skip reserved IDs */
57 56 continue;
58 57 if (grp->gr_gid >= gid) {
59 58 if (grp->gr_gid == stop) { /* Overflow check */
60 59 overflow = B_TRUE;
61 60 break;
62 61 }
63 62 gid = grp->gr_gid + 1;
64 63 }
65 64 }
66 65 if (grp == NULL && errno != 0) {
67 66 endgrent();
68 67 return (-1);
69 68 }
70 69 endgrent();
71 70 if (overflow == B_TRUE) /* Find a hole */
72 71 return (findunusedgid(start, stop, ret));
73 72 while (isreservedgid(gid) && gid < stop) /* Skip reserved IDs */
74 73 gid++;
75 74 *ret = gid;
76 75 return (0);
77 76 }
78 77
79 78 /*
80 79 * Check to see whether the gid is a reserved gid
81 80 * -- nobody, noaccess or nogroup
82 81 */
83 82 static boolean_t
84 83 isreservedgid(gid_t gid)
85 84 {
86 85 return (gid == 60001 || gid == 60002 || gid == 65534);
87 86 }
88 87
89 88 /*
90 89 * findunusedgid() attempts to return the next valid usable id between the
91 90 * supplied upper and lower limits. Returns 0 on success.
92 91 */
93 92 static int
94 93 findunusedgid(gid_t start, gid_t stop, gid_t *ret)
95 94 {
96 95 gid_t gid;
97 96
98 97 for (gid = start; gid <= stop; gid++) {
99 98 if (isreservedgid(gid))
100 99 continue;
101 100 if (getgrgid(gid) == NULL) {
102 101 if (errno != 0)
103 102 return (-1);
104 103 break;
105 104 }
106 105 }
107 106 if (gid > stop)
108 107 return (-1);
109 108 *ret = gid;
110 109 return (0);
111 110 }
↓ open down ↓ |
65 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX