]>
Commit | Line | Data |
---|---|---|
f6903667 AK |
1 | /* |
2 | * nonlocal-group.c | |
3 | * group database for nss_nonlocal proxy | |
4 | * | |
48479fc7 TA |
5 | * Copyright © 2007 Anders Kaseorg <andersk@mit.edu> and Tim Abbott |
6 | * <tabbott@mit.edu> | |
f6903667 AK |
7 | * |
8 | * Permission is hereby granted, free of charge, to any person | |
9 | * obtaining a copy of this software and associated documentation | |
10 | * files (the "Software"), to deal in the Software without | |
11 | * restriction, including without limitation the rights to use, copy, | |
12 | * modify, merge, publish, distribute, sublicense, and/or sell copies | |
13 | * of the Software, and to permit persons to whom the Software is | |
14 | * furnished to do so, subject to the following conditions: | |
15 | * | |
16 | * The above copyright notice and this permission notice shall be | |
17 | * included in all copies or substantial portions of the Software. | |
18 | * | |
19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
20 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
21 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
22 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | |
23 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | |
24 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | |
25 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
26 | * SOFTWARE. | |
27 | */ | |
28 | ||
29 | #define _GNU_SOURCE | |
30 | #include <sys/types.h> | |
31 | #include <unistd.h> | |
32 | #include <stdlib.h> | |
33 | #include <stdint.h> | |
34 | #include <string.h> | |
35 | #include <dlfcn.h> | |
36 | #include <stdio.h> | |
37 | #include <syslog.h> | |
38 | #include <errno.h> | |
39 | #include <grp.h> | |
40 | #include <nss.h> | |
41 | #include "nsswitch-internal.h" | |
42 | #include "nonlocal.h" | |
43 | ||
48479fc7 TA |
44 | #define MAGIC_NONLOCAL_GROUPNAME "nss-nonlocal-users" |
45 | #define MAGIC_LOCAL_GROUPNAME "nss-local-users" | |
f7293a54 | 46 | |
f6903667 | 47 | |
c1812233 AK |
48 | enum nss_status |
49 | _nss_nonlocal_getgrnam_r(const char *name, struct group *grp, | |
50 | char *buffer, size_t buflen, int *errnop); | |
51 | ||
52 | enum nss_status | |
53 | _nss_nonlocal_getgrgid_r(gid_t gid, struct group *grp, | |
54 | char *buffer, size_t buflen, int *errnop); | |
55 | ||
56 | ||
f6903667 AK |
57 | static service_user * |
58 | nss_group_nonlocal_database(void) | |
59 | { | |
60 | static service_user *nip = NULL; | |
61 | if (nip == NULL) | |
62 | __nss_database_lookup("group_nonlocal", NULL, "", &nip); | |
48479fc7 | 63 | |
f6903667 AK |
64 | return nip; |
65 | } | |
66 | ||
67 | ||
f6903667 AK |
68 | enum nss_status |
69 | check_nonlocal_gid(const char *user, gid_t gid, int *errnop) | |
70 | { | |
30fb3957 AK |
71 | static const char *fct_name = "getgrgid_r"; |
72 | static service_user *startp = NULL; | |
73 | static void *fct_start = NULL; | |
74 | enum nss_status status; | |
75 | service_user *nip; | |
76 | union { | |
77 | enum nss_status (*l)(gid_t gid, struct group *grp, | |
78 | char *buffer, size_t buflen, int *errnop); | |
79 | void *ptr; | |
80 | } fct; | |
f7293a54 | 81 | struct group gbuf; |
f7293a54 | 82 | int old_errno = errno; |
c1812233 | 83 | |
8870ee9c | 84 | size_t buflen = sysconf(_SC_GETGR_R_SIZE_MAX); |
f7293a54 AK |
85 | char *buf = malloc(buflen); |
86 | if (buf == NULL) { | |
f6903667 | 87 | *errnop = ENOMEM; |
f7293a54 | 88 | errno = old_errno; |
f6903667 AK |
89 | return NSS_STATUS_TRYAGAIN; |
90 | } | |
30fb3957 AK |
91 | |
92 | if (fct_start == NULL && | |
93 | __nss_group_lookup(&startp, fct_name, &fct_start) != 0) { | |
94 | free(buf); | |
95 | return NSS_STATUS_UNAVAIL; | |
96 | } | |
97 | nip = startp; | |
98 | fct.ptr = fct_start; | |
99 | do { | |
d905b369 | 100 | morebuf: |
c1812233 AK |
101 | if (fct.l == _nss_nonlocal_getgrgid_r) |
102 | status = NSS_STATUS_NOTFOUND; | |
103 | else | |
104 | status = DL_CALL_FCT(fct.l, (gid, &gbuf, buf, buflen, errnop)); | |
d905b369 AK |
105 | if (status == NSS_STATUS_TRYAGAIN && *errnop == ERANGE) { |
106 | free(buf); | |
107 | buflen *= 2; | |
108 | buf = malloc(buflen); | |
109 | if (buf == NULL) { | |
110 | *errnop = ENOMEM; | |
111 | errno = old_errno; | |
112 | return NSS_STATUS_TRYAGAIN; | |
113 | } | |
114 | goto morebuf; | |
115 | } | |
30fb3957 AK |
116 | } while (__nss_next(&nip, fct_name, &fct.ptr, status, 0) == 0); |
117 | ||
118 | if (status == NSS_STATUS_SUCCESS) { | |
f7293a54 | 119 | syslog(LOG_WARNING, "nss_nonlocal: removing local group %u (%s) from non-local user %s\n", gbuf.gr_gid, gbuf.gr_name, user); |
f6903667 | 120 | status = NSS_STATUS_NOTFOUND; |
30fb3957 AK |
121 | } else if (status != NSS_STATUS_TRYAGAIN) { |
122 | status = NSS_STATUS_SUCCESS; | |
f6903667 | 123 | } |
30fb3957 | 124 | |
f7293a54 | 125 | free(buf); |
f6903667 AK |
126 | return status; |
127 | } | |
128 | ||
cf338316 AK |
129 | enum nss_status |
130 | check_nonlocal_group(const char *user, struct group *grp, int *errnop) | |
131 | { | |
a07a7616 AK |
132 | enum nss_status status = NSS_STATUS_SUCCESS; |
133 | int old_errno = errno; | |
134 | char *end; | |
135 | unsigned long gid; | |
136 | ||
137 | errno = 0; | |
138 | gid = strtoul(grp->gr_name, &end, 10); | |
139 | if (errno == 0 && *end == '\0' && (gid_t)gid == gid) | |
140 | status = check_nonlocal_gid(user, gid, errnop); | |
141 | errno = old_errno; | |
142 | if (status != NSS_STATUS_SUCCESS) | |
143 | return status; | |
144 | ||
cf338316 AK |
145 | return check_nonlocal_gid(user, grp->gr_gid, errnop); |
146 | } | |
147 | ||
48479fc7 | 148 | enum nss_status |
8aa9014e | 149 | get_local_group(const char *name, struct group *grp, char **buffer, int *errnop) |
48479fc7 | 150 | { |
30fb3957 AK |
151 | static const char *fct_name = "getgrnam_r"; |
152 | static service_user *startp = NULL; | |
153 | static void *fct_start = NULL; | |
154 | enum nss_status status; | |
155 | service_user *nip; | |
156 | union { | |
157 | enum nss_status (*l)(const char *name, struct group *grp, | |
158 | char *buffer, size_t buflen, int *errnop); | |
159 | void *ptr; | |
160 | } fct; | |
8aa9014e | 161 | size_t buflen; |
48479fc7 | 162 | int old_errno = errno; |
c1812233 | 163 | |
8aa9014e AK |
164 | buflen = sysconf(_SC_GETGR_R_SIZE_MAX); |
165 | *buffer = malloc(buflen); | |
166 | if (*buffer == NULL) { | |
48479fc7 TA |
167 | *errnop = ENOMEM; |
168 | errno = old_errno; | |
169 | return NSS_STATUS_TRYAGAIN; | |
170 | } | |
1e78305d | 171 | |
30fb3957 AK |
172 | if (fct_start == NULL && |
173 | __nss_group_lookup(&startp, fct_name, &fct_start) != 0) { | |
8aa9014e AK |
174 | free(*buffer); |
175 | *buffer = NULL; | |
30fb3957 AK |
176 | return NSS_STATUS_UNAVAIL; |
177 | } | |
178 | nip = startp; | |
179 | fct.ptr = fct_start; | |
180 | do { | |
d905b369 | 181 | morebuf: |
c1812233 AK |
182 | if (fct.l == _nss_nonlocal_getgrnam_r) |
183 | status = NSS_STATUS_NOTFOUND; | |
184 | else | |
8aa9014e | 185 | status = DL_CALL_FCT(fct.l, (name, grp, *buffer, buflen, errnop)); |
d905b369 | 186 | if (status == NSS_STATUS_TRYAGAIN && *errnop == ERANGE) { |
8aa9014e AK |
187 | free(*buffer); |
188 | buflen *= 2; | |
189 | *buffer = malloc(buflen); | |
190 | if (*buffer == NULL) { | |
d905b369 AK |
191 | *errnop = ENOMEM; |
192 | errno = old_errno; | |
193 | return NSS_STATUS_TRYAGAIN; | |
194 | } | |
195 | goto morebuf; | |
196 | } | |
30fb3957 AK |
197 | } while (__nss_next(&nip, fct_name, &fct.ptr, status, 0) == 0); |
198 | ||
8aa9014e AK |
199 | if (status != NSS_STATUS_SUCCESS) { |
200 | free(*buffer); | |
201 | *buffer = NULL; | |
48479fc7 | 202 | } |
30fb3957 | 203 | |
48479fc7 TA |
204 | return status; |
205 | } | |
f6903667 AK |
206 | |
207 | static service_user *grent_nip = NULL; | |
208 | static void *grent_fct_start; | |
209 | static union { | |
210 | enum nss_status (*l)(struct group *grp, char *buffer, size_t buflen, | |
211 | int *errnop); | |
212 | void *ptr; | |
213 | } grent_fct; | |
214 | static const char *grent_fct_name = "getgrent_r"; | |
215 | ||
216 | enum nss_status | |
217 | _nss_nonlocal_setgrent(int stayopen) | |
218 | { | |
219 | static const char *fct_name = "setgrent"; | |
220 | static void *fct_start = NULL; | |
221 | enum nss_status status; | |
222 | service_user *nip; | |
223 | union { | |
224 | enum nss_status (*l)(int stayopen); | |
225 | void *ptr; | |
226 | } fct; | |
227 | ||
228 | nip = nss_group_nonlocal_database(); | |
229 | if (nip == NULL) | |
230 | return NSS_STATUS_UNAVAIL; | |
231 | if (fct_start == NULL) | |
232 | fct_start = __nss_lookup_function(nip, fct_name); | |
233 | fct.ptr = fct_start; | |
234 | do { | |
235 | if (fct.ptr == NULL) | |
236 | status = NSS_STATUS_UNAVAIL; | |
237 | else | |
238 | status = DL_CALL_FCT(fct.l, (stayopen)); | |
239 | } while (__nss_next(&nip, fct_name, &fct.ptr, status, 0) == 0); | |
240 | if (status != NSS_STATUS_SUCCESS) | |
241 | return status; | |
242 | ||
243 | grent_nip = nip; | |
244 | if (grent_fct_start == NULL) | |
245 | grent_fct_start = __nss_lookup_function(nip, grent_fct_name); | |
246 | grent_fct.ptr = grent_fct_start; | |
247 | return NSS_STATUS_SUCCESS; | |
248 | } | |
249 | ||
250 | enum nss_status | |
251 | _nss_nonlocal_endgrent(void) | |
252 | { | |
253 | static const char *fct_name = "endgrent"; | |
254 | static void *fct_start = NULL; | |
255 | enum nss_status status; | |
256 | service_user *nip; | |
257 | union { | |
258 | enum nss_status (*l)(void); | |
259 | void *ptr; | |
260 | } fct; | |
261 | ||
262 | grent_nip = NULL; | |
263 | ||
264 | nip = nss_group_nonlocal_database(); | |
265 | if (nip == NULL) | |
266 | return NSS_STATUS_UNAVAIL; | |
267 | if (fct_start == NULL) | |
268 | fct_start = __nss_lookup_function(nip, fct_name); | |
269 | fct.ptr = fct_start; | |
270 | do { | |
271 | if (fct.ptr == NULL) | |
272 | status = NSS_STATUS_UNAVAIL; | |
273 | else | |
274 | status = DL_CALL_FCT(fct.l, ()); | |
275 | } while (__nss_next(&nip, fct_name, &fct.ptr, status, 0) == 0); | |
276 | return status; | |
277 | } | |
278 | ||
279 | enum nss_status | |
280 | _nss_nonlocal_getgrent_r(struct group *grp, char *buffer, size_t buflen, | |
281 | int *errnop) | |
282 | { | |
283 | enum nss_status status; | |
a360549e TA |
284 | |
285 | char *nonlocal_ignore = getenv(NONLOCAL_IGNORE_ENV); | |
c1812233 | 286 | if (nonlocal_ignore != NULL && nonlocal_ignore[0] != '\0') |
a360549e TA |
287 | return NSS_STATUS_UNAVAIL; |
288 | ||
f6903667 AK |
289 | if (grent_nip == NULL) { |
290 | status = _nss_nonlocal_setgrent(0); | |
291 | if (status != NSS_STATUS_SUCCESS) | |
292 | return status; | |
293 | } | |
294 | do { | |
295 | if (grent_fct.ptr == NULL) | |
296 | status = NSS_STATUS_UNAVAIL; | |
297 | else { | |
298 | int nonlocal_errno; | |
299 | do | |
300 | status = DL_CALL_FCT(grent_fct.l, (grp, buffer, buflen, errnop)); | |
301 | while (status == NSS_STATUS_SUCCESS && | |
cf338316 | 302 | check_nonlocal_group("(unknown)", grp, &nonlocal_errno) != NSS_STATUS_SUCCESS); |
f6903667 AK |
303 | } |
304 | if (status == NSS_STATUS_TRYAGAIN && *errnop == ERANGE) | |
305 | return status; | |
306 | ||
307 | if (status == NSS_STATUS_SUCCESS) | |
308 | return NSS_STATUS_SUCCESS; | |
309 | } while (__nss_next(&grent_nip, grent_fct_name, &grent_fct.ptr, status, 0) == 0); | |
310 | ||
311 | grent_nip = NULL; | |
312 | return NSS_STATUS_NOTFOUND; | |
313 | } | |
314 | ||
315 | ||
316 | enum nss_status | |
317 | _nss_nonlocal_getgrnam_r(const char *name, struct group *grp, | |
318 | char *buffer, size_t buflen, int *errnop) | |
319 | { | |
320 | static const char *fct_name = "getgrnam_r"; | |
321 | static void *fct_start = NULL; | |
322 | enum nss_status status; | |
323 | service_user *nip; | |
324 | union { | |
325 | enum nss_status (*l)(const char *name, struct group *grp, | |
326 | char *buffer, size_t buflen, int *errnop); | |
327 | void *ptr; | |
328 | } fct; | |
329 | ||
a360549e | 330 | char *nonlocal_ignore = getenv(NONLOCAL_IGNORE_ENV); |
c1812233 | 331 | if (nonlocal_ignore != NULL && nonlocal_ignore[0] != '\0') |
48479fc7 TA |
332 | return NSS_STATUS_UNAVAIL; |
333 | ||
f6903667 AK |
334 | nip = nss_group_nonlocal_database(); |
335 | if (nip == NULL) | |
336 | return NSS_STATUS_UNAVAIL; | |
337 | if (fct_start == NULL) | |
338 | fct_start = __nss_lookup_function(nip, fct_name); | |
339 | fct.ptr = fct_start; | |
340 | do { | |
341 | if (fct.ptr == NULL) | |
342 | status = NSS_STATUS_UNAVAIL; | |
343 | else | |
344 | status = DL_CALL_FCT(fct.l, (name, grp, buffer, buflen, errnop)); | |
345 | if (status == NSS_STATUS_TRYAGAIN && *errnop == ERANGE) | |
346 | break; | |
347 | } while (__nss_next(&nip, fct_name, &fct.ptr, status, 0) == 0); | |
348 | if (status != NSS_STATUS_SUCCESS) | |
349 | return status; | |
350 | ||
22562df0 AK |
351 | if (strcmp(name, grp->gr_name) != 0) { |
352 | syslog(LOG_ERR, "nss_nonlocal: discarding group %s from lookup for group %s\n", grp->gr_name, name); | |
353 | return NSS_STATUS_NOTFOUND; | |
354 | } | |
355 | ||
cf338316 | 356 | return check_nonlocal_group(name, grp, errnop); |
f6903667 AK |
357 | } |
358 | ||
359 | enum nss_status | |
360 | _nss_nonlocal_getgrgid_r(gid_t gid, struct group *grp, | |
361 | char *buffer, size_t buflen, int *errnop) | |
362 | { | |
363 | static const char *fct_name = "getgrgid_r"; | |
364 | static void *fct_start = NULL; | |
365 | enum nss_status status; | |
366 | service_user *nip; | |
367 | union { | |
368 | enum nss_status (*l)(gid_t gid, struct group *grp, | |
369 | char *buffer, size_t buflen, int *errnop); | |
370 | void *ptr; | |
371 | } fct; | |
372 | ||
a360549e | 373 | char *nonlocal_ignore = getenv(NONLOCAL_IGNORE_ENV); |
c1812233 | 374 | if (nonlocal_ignore != NULL && nonlocal_ignore[0] != '\0') |
f6903667 AK |
375 | return NSS_STATUS_UNAVAIL; |
376 | ||
377 | nip = nss_group_nonlocal_database(); | |
378 | if (nip == NULL) | |
379 | return NSS_STATUS_UNAVAIL; | |
380 | if (fct_start == NULL) | |
381 | fct_start = __nss_lookup_function(nip, fct_name); | |
382 | fct.ptr = fct_start; | |
383 | do { | |
384 | if (fct.ptr == NULL) | |
385 | status = NSS_STATUS_UNAVAIL; | |
386 | else | |
387 | status = DL_CALL_FCT(fct.l, (gid, grp, buffer, buflen, errnop)); | |
388 | if (status == NSS_STATUS_TRYAGAIN && *errnop == ERANGE) | |
389 | break; | |
390 | } while (__nss_next(&nip, fct_name, &fct.ptr, status, 0) == 0); | |
391 | if (status != NSS_STATUS_SUCCESS) | |
392 | return status; | |
393 | ||
8027fdc4 AK |
394 | if (gid != grp->gr_gid) { |
395 | syslog(LOG_ERR, "nss_nonlocal: discarding gid %d from lookup for gid %d\n", grp->gr_gid, gid); | |
396 | return NSS_STATUS_NOTFOUND; | |
397 | } | |
398 | ||
cf338316 | 399 | return check_nonlocal_group(grp->gr_name, grp, errnop); |
f6903667 AK |
400 | } |
401 | ||
402 | enum nss_status | |
403 | _nss_nonlocal_initgroups_dyn(const char *user, gid_t group, long int *start, | |
404 | long int *size, gid_t **groupsp, long int limit, | |
405 | int *errnop) | |
406 | { | |
407 | static const char *fct_name = "initgroups_dyn"; | |
408 | static void *fct_start = NULL; | |
409 | enum nss_status status; | |
410 | service_user *nip; | |
411 | union { | |
412 | enum nss_status (*l)(const char *user, gid_t group, long int *start, | |
413 | long int *size, gid_t **groupsp, long int limit, | |
414 | int *errnop); | |
415 | void *ptr; | |
416 | } fct; | |
1e78305d AK |
417 | |
418 | struct group local_users_group, nonlocal_users_group; | |
419 | gid_t local_users_gid, gid; | |
48479fc7 | 420 | int is_local = 0; |
1e78305d | 421 | char *buffer; |
d7bf1d11 AK |
422 | int old_errno; |
423 | int in, out, i; | |
48479fc7 | 424 | |
1e78305d | 425 | /* Check that the user is a nonlocal user before adding any groups. */ |
48479fc7 | 426 | status = check_nonlocal_user(user, errnop); |
5879a696 | 427 | if (status == NSS_STATUS_TRYAGAIN) |
48479fc7 | 428 | return status; |
5879a696 AK |
429 | else if (status != NSS_STATUS_SUCCESS) |
430 | is_local = 1; | |
48479fc7 | 431 | |
d7bf1d11 | 432 | old_errno = errno; |
1e78305d | 433 | |
48479fc7 | 434 | status = get_local_group(MAGIC_LOCAL_GROUPNAME, |
8aa9014e | 435 | &local_users_group, &buffer, errnop); |
5879a696 AK |
436 | if (status == NSS_STATUS_SUCCESS) { |
437 | local_users_gid = local_users_group.gr_gid; | |
dc94c928 | 438 | free(buffer); |
8aa9014e | 439 | } else if (status == NSS_STATUS_TRYAGAIN) { |
5879a696 AK |
440 | return status; |
441 | } else { | |
48479fc7 TA |
442 | syslog(LOG_WARNING, "nss_nonlocal: Group %s does not exist locally!", |
443 | MAGIC_LOCAL_GROUPNAME); | |
1e78305d | 444 | local_users_gid = -1; |
5879a696 | 445 | } |
1e78305d AK |
446 | |
447 | if (is_local) { | |
448 | gid = local_users_gid; | |
449 | } else { | |
1e78305d | 450 | status = get_local_group(MAGIC_NONLOCAL_GROUPNAME, |
8aa9014e | 451 | &nonlocal_users_group, &buffer, errnop); |
5879a696 AK |
452 | if (status == NSS_STATUS_SUCCESS) { |
453 | gid = nonlocal_users_group.gr_gid; | |
dc94c928 | 454 | free(buffer); |
8aa9014e | 455 | } else if (status == NSS_STATUS_TRYAGAIN) { |
5879a696 AK |
456 | return status; |
457 | } else { | |
1e78305d AK |
458 | syslog(LOG_WARNING, "nss_nonlocal: Group %s does not exist locally!", |
459 | MAGIC_NONLOCAL_GROUPNAME); | |
460 | gid = -1; | |
5879a696 | 461 | } |
48479fc7 | 462 | } |
1e78305d AK |
463 | |
464 | if (gid != -1) { | |
465 | int i; | |
466 | for (i = 0; i < *start; ++i) | |
467 | if ((*groupsp)[i] == gid) | |
468 | break; | |
469 | if (i >= *start) { | |
470 | if (*start + 1 > *size) { | |
471 | gid_t *newgroups; | |
472 | long int newsize = 2 * *size; | |
473 | if (limit > 0) { | |
474 | if (*size >= limit) | |
475 | return NSS_STATUS_SUCCESS; | |
476 | if (newsize > limit) | |
477 | newsize = limit; | |
478 | } | |
ad0399bd | 479 | newgroups = realloc(*groupsp, newsize * sizeof((*groupsp)[0])); |
1e78305d AK |
480 | if (newgroups == NULL) { |
481 | *errnop = ENOMEM; | |
482 | errno = old_errno; | |
483 | return NSS_STATUS_TRYAGAIN; | |
484 | } | |
485 | *groupsp = newgroups; | |
486 | *size = newsize; | |
487 | } | |
488 | (*groupsp)[(*start)++] = gid; | |
489 | } | |
48479fc7 | 490 | } |
f6903667 | 491 | |
1e78305d AK |
492 | if (is_local) |
493 | return NSS_STATUS_SUCCESS; | |
494 | ||
d7bf1d11 | 495 | in = out = *start; |
1e78305d | 496 | |
f6903667 AK |
497 | nip = nss_group_nonlocal_database(); |
498 | if (nip == NULL) | |
499 | return NSS_STATUS_UNAVAIL; | |
500 | if (fct_start == NULL) | |
501 | fct_start = __nss_lookup_function(nip, fct_name); | |
502 | fct.ptr = fct_start; | |
503 | ||
504 | do { | |
505 | if (fct.ptr == NULL) | |
506 | status = NSS_STATUS_UNAVAIL; | |
507 | else | |
508 | status = DL_CALL_FCT(fct.l, (user, group, start, size, groupsp, limit, errnop)); | |
509 | if (status == NSS_STATUS_TRYAGAIN && *errnop == ERANGE) | |
510 | break; | |
511 | } while (__nss_next(&nip, fct_name, &fct.ptr, status, 0) == 0); | |
512 | if (status != NSS_STATUS_SUCCESS) | |
513 | return status; | |
514 | ||
515 | for (; in < *start; ++in) { | |
516 | int nonlocal_errno = *errnop; | |
517 | ||
518 | for (i = 0; i < out; ++i) | |
519 | if ((*groupsp)[i] == (*groupsp)[in]) | |
520 | break; | |
521 | if (i < out) | |
522 | continue; | |
523 | ||
1e78305d AK |
524 | /* Don't let users get into MAGIC_LOCAL_GROUPNAME from nonlocal reasons. */ |
525 | if (local_users_gid == (*groupsp)[in]) { | |
526 | syslog(LOG_WARNING, "nss_nonlocal: Nonlocal user %s removed from special local users group %s", | |
527 | user, MAGIC_LOCAL_GROUPNAME); | |
528 | continue; | |
529 | } | |
530 | ||
f6903667 AK |
531 | status = check_nonlocal_gid(user, (*groupsp)[in], &nonlocal_errno); |
532 | if (status == NSS_STATUS_SUCCESS) { | |
1e78305d | 533 | (*groupsp)[out++] = (*groupsp)[in]; |
5879a696 | 534 | } else if (status == NSS_STATUS_TRYAGAIN) { |
f6903667 AK |
535 | *start = out; |
536 | *errnop = nonlocal_errno; | |
537 | return status; | |
538 | } | |
539 | } | |
540 | ||
541 | *start = out; | |
542 | return NSS_STATUS_SUCCESS; | |
543 | } |