Print this page
Remove include userdefs.h where not needed
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libcmdutils/common/uid.c
+++ new/usr/src/lib/libcmdutils/common/uid.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 *
20 20 * CDDL HEADER END
21 21 */
22 22 /*
23 23 * Copyright (c) 1997-2001 by Sun Microsystems, Inc.
24 24 * All rights reserved.
25 25 */
26 26
↓ open down ↓ |
26 lines elided |
↑ open up ↑ |
27 27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 28 /* All Rights Reserved */
29 29
30 30 /*
31 31 * Copyright (c) 2013 RackTop Systems.
32 32 */
33 33
34 34 #include <errno.h>
35 35 #include <sys/types.h>
36 36 #include <stdio.h>
37 -#include <userdefs.h>
38 37 #include <pwd.h>
39 38 #include <libcmdutils.h>
40 39
41 40 static int findunuseduid(uid_t start, uid_t stop, uid_t *ret);
42 41 static boolean_t isreserveduid(uid_t uid);
43 42
44 43 /*
45 44 * Find the highest unused uid. If the highest unused uid is "stop",
46 45 * then attempt to find a hole in the range. Returns 0 on success.
47 46 */
48 47 int
49 48 findnextuid(uid_t start, uid_t stop, uid_t *ret)
50 49 {
51 50 uid_t uid = start;
52 51 struct passwd *pwd;
53 52 boolean_t overflow = B_FALSE;
54 53
55 54 setpwent();
56 55 for (pwd = getpwent(); pwd != NULL; pwd = getpwent()) {
57 56 if (isreserveduid(pwd->pw_uid)) /* Skip reserved IDs */
58 57 continue;
59 58 if (pwd->pw_uid >= uid) {
60 59 if (pwd->pw_uid == stop) { /* Overflow check */
61 60 overflow = B_TRUE;
62 61 break;
63 62 }
64 63 uid = pwd->pw_uid + 1;
65 64 }
66 65 }
67 66 if (pwd == NULL && errno != 0) {
68 67 endpwent();
69 68 return (-1);
70 69 }
71 70 endpwent();
72 71 if (overflow == B_TRUE) /* Find a hole */
73 72 return (findunuseduid(start, stop, ret));
74 73 while (isreserveduid(uid) && uid < stop) /* Skip reserved IDs */
75 74 uid++;
76 75 *ret = uid;
77 76 return (0);
78 77 }
79 78
80 79 /*
81 80 * Check to see whether the uid is a reserved uid
82 81 * -- nobody, noaccess or nobody4
83 82 */
84 83 static boolean_t
85 84 isreserveduid(uid_t uid)
86 85 {
87 86 return (uid == 60001 || uid == 60002 || uid == 65534);
88 87 }
89 88
90 89 /*
91 90 * findunuseduid() attempts to return the next valid usable id between the
92 91 * supplied upper and lower limits. Returns 0 on success.
93 92 */
94 93 static int
95 94 findunuseduid(uid_t start, uid_t stop, uid_t *ret)
96 95 {
97 96 uid_t uid;
98 97
99 98 for (uid = start; uid <= stop; uid++) {
100 99 if (isreserveduid(uid))
101 100 continue;
102 101 if (getpwuid(uid) == NULL) {
103 102 if (errno != 0)
104 103 return (-1);
105 104 break;
106 105 }
107 106 }
108 107 if (uid > stop)
109 108 return (-1);
110 109 *ret = uid;
111 110 return (0);
112 111 }
↓ open down ↓ |
65 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX