Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/coreutils/src/gnulib/lib/userspec.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||
2 | - | |||||||||||||||||||
3 | - | |||||||||||||||||||
4 | - | |||||||||||||||||||
5 | - | |||||||||||||||||||
6 | - | |||||||||||||||||||
7 | - | |||||||||||||||||||
8 | - | |||||||||||||||||||
9 | - | |||||||||||||||||||
10 | - | |||||||||||||||||||
11 | - | |||||||||||||||||||
12 | static char const * | - | ||||||||||||||||||
13 | parse_with_separator (char const *spec, char const *separator, | - | ||||||||||||||||||
14 | uid_t *uid, gid_t *gid, | - | ||||||||||||||||||
15 | char **username, char **groupname) | - | ||||||||||||||||||
16 | { | - | ||||||||||||||||||
17 | static const char *E_invalid_user = "invalid user"; | - | ||||||||||||||||||
18 | static const char *E_invalid_group = "invalid group"; | - | ||||||||||||||||||
19 | static const char *E_bad_spec = "invalid spec"; | - | ||||||||||||||||||
20 | - | |||||||||||||||||||
21 | const char *error_msg; | - | ||||||||||||||||||
22 | struct passwd *pwd; | - | ||||||||||||||||||
23 | struct group *grp; | - | ||||||||||||||||||
24 | char *u; | - | ||||||||||||||||||
25 | char const *g; | - | ||||||||||||||||||
26 | char *gname = | - | ||||||||||||||||||
27 | ((void *)0) | - | ||||||||||||||||||
28 | ; | - | ||||||||||||||||||
29 | uid_t unum = *uid; | - | ||||||||||||||||||
30 | gid_t gnum = gid
| 44-113 | ||||||||||||||||||
31 | - | |||||||||||||||||||
32 | error_msg = | - | ||||||||||||||||||
33 | ((void *)0) | - | ||||||||||||||||||
34 | ; | - | ||||||||||||||||||
35 | if (username
| 38-119 | ||||||||||||||||||
36 | * executed 38 times by 1 test: username = *username = ((void *)0) ; Executed by:
executed 38 times by 1 test: *username = ((void *)0) ; Executed by:
| 38 | ||||||||||||||||||
37 | ((void *)0) executed 38 times by 1 test: *username = ((void *)0) ; Executed by:
| 38 | ||||||||||||||||||
38 | ; executed 38 times by 1 test: *username = ((void *)0) ; Executed by:
| 38 | ||||||||||||||||||
39 | if (groupname
| 38-119 | ||||||||||||||||||
40 | * executed 38 times by 1 test: groupname = *groupname = ((void *)0) ; Executed by:
executed 38 times by 1 test: *groupname = ((void *)0) ; Executed by:
| 38 | ||||||||||||||||||
41 | ((void *)0) executed 38 times by 1 test: *groupname = ((void *)0) ; Executed by:
| 38 | ||||||||||||||||||
42 | ; executed 38 times by 1 test: *groupname = ((void *)0) ; Executed by:
| 38 | ||||||||||||||||||
43 | - | |||||||||||||||||||
44 | - | |||||||||||||||||||
45 | - | |||||||||||||||||||
46 | - | |||||||||||||||||||
47 | - | |||||||||||||||||||
48 | u = | - | ||||||||||||||||||
49 | ((void *)0) | - | ||||||||||||||||||
50 | ; | - | ||||||||||||||||||
51 | if (separator ==
| 29-128 | ||||||||||||||||||
52 | ((void *)0)
| 29-128 | ||||||||||||||||||
53 | ) | - | ||||||||||||||||||
54 | { | - | ||||||||||||||||||
55 | if (*
| 1-127 | ||||||||||||||||||
56 | u = xstrdup (spec); executed 127 times by 2 tests: u = xstrdup (spec); Executed by:
| 127 | ||||||||||||||||||
57 | } executed 128 times by 2 tests: end of block Executed by:
| 128 | ||||||||||||||||||
58 | else | - | ||||||||||||||||||
59 | { | - | ||||||||||||||||||
60 | size_t ulen = separator - spec; | - | ||||||||||||||||||
61 | if (ulen != 0
| 13-16 | ||||||||||||||||||
62 | { | - | ||||||||||||||||||
63 | u = xmemdup (spec, ulen + 1); | - | ||||||||||||||||||
64 | u[ulen] = '\0'; | - | ||||||||||||||||||
65 | } executed 13 times by 1 test: end of block Executed by:
| 13 | ||||||||||||||||||
66 | } executed 29 times by 1 test: end of block Executed by:
| 29 | ||||||||||||||||||
67 | - | |||||||||||||||||||
68 | g = (separator ==
| 29-128 | ||||||||||||||||||
69 | ((void *)0)
| 29-128 | ||||||||||||||||||
70 | || *(
| 6-23 | ||||||||||||||||||
71 | ? | - | ||||||||||||||||||
72 | ((void *)0) | - | ||||||||||||||||||
73 | - | |||||||||||||||||||
74 | : separator + 1); | - | ||||||||||||||||||
75 | if (u !=
| 17-140 | ||||||||||||||||||
76 | ((void *)0)
| 17-140 | ||||||||||||||||||
77 | ) | - | ||||||||||||||||||
78 | { | - | ||||||||||||||||||
79 | - | |||||||||||||||||||
80 | pwd = (*
| 3-137 | ||||||||||||||||||
81 | ((void *)0) | - | ||||||||||||||||||
82 | : getpwnam (u)); | - | ||||||||||||||||||
83 | if (pwd ==
| 28-112 | ||||||||||||||||||
84 | ((void *)0)
| 28-112 | ||||||||||||||||||
85 | ) | - | ||||||||||||||||||
86 | { | - | ||||||||||||||||||
87 | - | |||||||||||||||||||
88 | _Bool | - | ||||||||||||||||||
89 | use_login_group = (separator !=
| 7-21 | ||||||||||||||||||
90 | ((void *)0)
| 7-21 | ||||||||||||||||||
91 | && g ==
| 2-5 | ||||||||||||||||||
92 | ((void *)0)
| 2-5 | ||||||||||||||||||
93 | ); | - | ||||||||||||||||||
94 | if (use_login_group
| 2-26 | ||||||||||||||||||
95 | { | - | ||||||||||||||||||
96 | - | |||||||||||||||||||
97 | - | |||||||||||||||||||
98 | error_msg = E_bad_spec; | - | ||||||||||||||||||
99 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
100 | else | - | ||||||||||||||||||
101 | { | - | ||||||||||||||||||
102 | unsigned long int tmp; | - | ||||||||||||||||||
103 | if (xstrtoul (u,
| 12-14 | ||||||||||||||||||
104 | ((void *)0)
| 12-14 | ||||||||||||||||||
105 | , 10, &tmp, "") == LONGINT_OK
| 12-14 | ||||||||||||||||||
106 | && tmp <= ((uid_t) (! (! ((uid_t) 0 < (uid_t) -1)) ? (uid_t) -1 : ((((uid_t) 1 << ((sizeof (uid_t) * 8) - 2)) - 1) * 2 + 1)))
| 0-14 | ||||||||||||||||||
107 | unum = tmp; executed 14 times by 2 tests: unum = tmp; Executed by:
| 14 | ||||||||||||||||||
108 | else | - | ||||||||||||||||||
109 | error_msg = E_invalid_user; executed 12 times by 2 tests: error_msg = E_invalid_user; Executed by:
| 12 | ||||||||||||||||||
110 | } | - | ||||||||||||||||||
111 | } | - | ||||||||||||||||||
112 | else | - | ||||||||||||||||||
113 | { | - | ||||||||||||||||||
114 | unum = pwd->pw_uid; | - | ||||||||||||||||||
115 | if (g ==
| 4-108 | ||||||||||||||||||
116 | ((void *)0)
| 4-108 | ||||||||||||||||||
117 | && separator !=
| 2-106 | ||||||||||||||||||
118 | ((void *)0)
| 2-106 | ||||||||||||||||||
119 | ) | - | ||||||||||||||||||
120 | { | - | ||||||||||||||||||
121 | - | |||||||||||||||||||
122 | - | |||||||||||||||||||
123 | char buf[((((((sizeof (uintmax_t) * 8) - (! ((__typeof__ (uintmax_t)) 0 < (__typeof__ (uintmax_t)) -1))) * 146 + 484) / 485) + (! ((__typeof__ (uintmax_t)) 0 < (__typeof__ (uintmax_t)) -1))) + 1)]; | - | ||||||||||||||||||
124 | gnum = pwd->pw_gid; | - | ||||||||||||||||||
125 | grp = getgrgid (gnum); | - | ||||||||||||||||||
126 | gname = xstrdup (grp ? grp->gr_name : umaxtostr (gnum, buf)); | - | ||||||||||||||||||
127 | endgrent (); | - | ||||||||||||||||||
128 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
129 | } executed 112 times by 2 tests: end of block Executed by:
| 112 | ||||||||||||||||||
130 | endpwent (); | - | ||||||||||||||||||
131 | } executed 140 times by 2 tests: end of block Executed by:
| 140 | ||||||||||||||||||
132 | - | |||||||||||||||||||
133 | if (g !=
| 23-134 | ||||||||||||||||||
134 | ((void *)0)
| 23-134 | ||||||||||||||||||
135 | && error_msg ==
| 0-23 | ||||||||||||||||||
136 | ((void *)0)
| 0-23 | ||||||||||||||||||
137 | ) | - | ||||||||||||||||||
138 | { | - | ||||||||||||||||||
139 | - | |||||||||||||||||||
140 | - | |||||||||||||||||||
141 | grp = (*
| 0-23 | ||||||||||||||||||
142 | ((void *)0) | - | ||||||||||||||||||
143 | : getgrnam (g)); | - | ||||||||||||||||||
144 | if (grp ==
| 6-17 | ||||||||||||||||||
145 | ((void *)0)
| 6-17 | ||||||||||||||||||
146 | ) | - | ||||||||||||||||||
147 | { | - | ||||||||||||||||||
148 | unsigned long int tmp; | - | ||||||||||||||||||
149 | if (xstrtoul (g,
| 0-17 | ||||||||||||||||||
150 | ((void *)0)
| 0-17 | ||||||||||||||||||
151 | , 10, &tmp, "") == LONGINT_OK
| 0-17 | ||||||||||||||||||
152 | && tmp <= ((gid_t) (! (! ((gid_t) 0 < (gid_t) -1)) ? (gid_t) -1 : ((((gid_t) 1 << ((sizeof (gid_t) * 8) - 2)) - 1) * 2 + 1)))
| 0-17 | ||||||||||||||||||
153 | gnum = tmp; executed 17 times by 1 test: gnum = tmp; Executed by:
| 17 | ||||||||||||||||||
154 | else | - | ||||||||||||||||||
155 | error_msg = E_invalid_group; never executed: error_msg = E_invalid_group; | 0 | ||||||||||||||||||
156 | } | - | ||||||||||||||||||
157 | else | - | ||||||||||||||||||
158 | gnum = grp->gr_gid; executed 6 times by 1 test: gnum = grp->gr_gid; Executed by:
| 6 | ||||||||||||||||||
159 | endgrent (); | - | ||||||||||||||||||
160 | gname = xstrdup (g); | - | ||||||||||||||||||
161 | } executed 23 times by 1 test: end of block Executed by:
| 23 | ||||||||||||||||||
162 | - | |||||||||||||||||||
163 | if (error_msg ==
| 14-143 | ||||||||||||||||||
164 | ((void *)0)
| 14-143 | ||||||||||||||||||
165 | ) | - | ||||||||||||||||||
166 | { | - | ||||||||||||||||||
167 | *uid = unum; | - | ||||||||||||||||||
168 | if (gid
| 32-111 | ||||||||||||||||||
169 | * executed 32 times by 1 test: gid = gnum;*gid = gnum; Executed by:
executed 32 times by 1 test: *gid = gnum; Executed by:
| 32 | ||||||||||||||||||
170 | if (username
| 27-116 | ||||||||||||||||||
171 | { | - | ||||||||||||||||||
172 | *username = u; | - | ||||||||||||||||||
173 | u = | - | ||||||||||||||||||
174 | ((void *)0) | - | ||||||||||||||||||
175 | ; | - | ||||||||||||||||||
176 | } executed 27 times by 1 test: end of block Executed by:
| 27 | ||||||||||||||||||
177 | if (groupname
| 27-116 | ||||||||||||||||||
178 | { | - | ||||||||||||||||||
179 | *groupname = gname; | - | ||||||||||||||||||
180 | gname = | - | ||||||||||||||||||
181 | ((void *)0) | - | ||||||||||||||||||
182 | ; | - | ||||||||||||||||||
183 | } executed 27 times by 1 test: end of block Executed by:
| 27 | ||||||||||||||||||
184 | } executed 143 times by 2 tests: end of block Executed by:
| 143 | ||||||||||||||||||
185 | - | |||||||||||||||||||
186 | free (u); | - | ||||||||||||||||||
187 | free (gname); | - | ||||||||||||||||||
188 | return executed 157 times by 2 tests: error_msg ? return error_msg ? dcgettext (((void *)0), error_msg , 5) : ((void *)0) ; Executed by:
executed 157 times by 2 tests: return error_msg ? dcgettext (((void *)0), error_msg , 5) : ((void *)0) ; Executed by:
| 157 | ||||||||||||||||||
189 | dcgettext (((void *)0), executed 157 times by 2 tests: return error_msg ? dcgettext (((void *)0), error_msg , 5) : ((void *)0) ; Executed by:
| 157 | ||||||||||||||||||
190 | error_msg executed 157 times by 2 tests: return error_msg ? dcgettext (((void *)0), error_msg , 5) : ((void *)0) ; Executed by:
| 157 | ||||||||||||||||||
191 | , 5) executed 157 times by 2 tests: return error_msg ? dcgettext (((void *)0), error_msg , 5) : ((void *)0) ; Executed by:
| 157 | ||||||||||||||||||
192 | : executed 157 times by 2 tests: return error_msg ? dcgettext (((void *)0), error_msg , 5) : ((void *)0) ; Executed by:
| 157 | ||||||||||||||||||
193 | ((void *)0) executed 157 times by 2 tests: return error_msg ? dcgettext (((void *)0), error_msg , 5) : ((void *)0) ; Executed by:
| 157 | ||||||||||||||||||
194 | ; executed 157 times by 2 tests: return error_msg ? dcgettext (((void *)0), error_msg , 5) : ((void *)0) ; Executed by:
| 157 | ||||||||||||||||||
195 | } | - | ||||||||||||||||||
196 | char const * | - | ||||||||||||||||||
197 | parse_user_spec (char const *spec, uid_t *uid, gid_t *gid, | - | ||||||||||||||||||
198 | char **username, char **groupname) | - | ||||||||||||||||||
199 | { | - | ||||||||||||||||||
200 | char const *colon = gid
| 35-113 | ||||||||||||||||||
201 | (__extension__ (__builtin_constant_p (
| 0-35 | ||||||||||||||||||
202 | ':'
| 0-35 | ||||||||||||||||||
203 | )
| 0-35 | ||||||||||||||||||
204 | spec
| 0-35 | ||||||||||||||||||
205 | )
| 0-35 | ||||||||||||||||||
206 | ':'
| 0-35 | ||||||||||||||||||
207 | ) == '\0'
| 0-35 | ||||||||||||||||||
208 | spec | - | ||||||||||||||||||
209 | , | - | ||||||||||||||||||
210 | ':' | - | ||||||||||||||||||
211 | ) : __builtin_strchr ( | - | ||||||||||||||||||
212 | spec | - | ||||||||||||||||||
213 | , | - | ||||||||||||||||||
214 | ':' | - | ||||||||||||||||||
215 | ))) | - | ||||||||||||||||||
216 | : | - | ||||||||||||||||||
217 | ((void *)0) | - | ||||||||||||||||||
218 | ; | - | ||||||||||||||||||
219 | char const *error_msg = | - | ||||||||||||||||||
220 | parse_with_separator (spec, colon, uid, gid, username, groupname); | - | ||||||||||||||||||
221 | - | |||||||||||||||||||
222 | if (gid
| 5-113 | ||||||||||||||||||
223 | { | - | ||||||||||||||||||
224 | - | |||||||||||||||||||
225 | - | |||||||||||||||||||
226 | - | |||||||||||||||||||
227 | - | |||||||||||||||||||
228 | - | |||||||||||||||||||
229 | - | |||||||||||||||||||
230 | char const *dot = | - | ||||||||||||||||||
231 | (__extension__ (__builtin_constant_p (
| 0-10 | ||||||||||||||||||
232 | '.'
| 0-10 | ||||||||||||||||||
233 | )
| 0-10 | ||||||||||||||||||
234 | spec
| 0-10 | ||||||||||||||||||
235 | )
| 0-10 | ||||||||||||||||||
236 | '.'
| 0-10 | ||||||||||||||||||
237 | ) == '\0'
| 0-10 | ||||||||||||||||||
238 | spec | - | ||||||||||||||||||
239 | , | - | ||||||||||||||||||
240 | '.' | - | ||||||||||||||||||
241 | ) : __builtin_strchr ( | - | ||||||||||||||||||
242 | spec | - | ||||||||||||||||||
243 | , | - | ||||||||||||||||||
244 | '.' | - | ||||||||||||||||||
245 | ))) | - | ||||||||||||||||||
246 | ; | - | ||||||||||||||||||
247 | if (dot
| 1-9 | ||||||||||||||||||
248 | && ! parse_with_separator (spec, dot, uid, gid, username, groupname)
| 1-8 | ||||||||||||||||||
249 | error_msg = executed 8 times by 1 test: error_msg = ((void *)0) ; Executed by:
| 8 | ||||||||||||||||||
250 | ((void *)0) executed 8 times by 1 test: error_msg = ((void *)0) ; Executed by:
| 8 | ||||||||||||||||||
251 | ; executed 8 times by 1 test: error_msg = ((void *)0) ; Executed by:
| 8 | ||||||||||||||||||
252 | } executed 10 times by 1 test: end of block Executed by:
| 10 | ||||||||||||||||||
253 | - | |||||||||||||||||||
254 | return executed 148 times by 2 tests: error_msg;return error_msg; Executed by:
executed 148 times by 2 tests: return error_msg; Executed by:
| 148 | ||||||||||||||||||
255 | } | - | ||||||||||||||||||
Switch to Source code | Preprocessed file |