]>
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 AK |
83 | |
84 | int 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 | ||
48479fc7 TA |
129 | enum nss_status |
130 | get_local_group(const char *name, struct group *grp, char *buffer, size_t buflen, int *errnop) | |
131 | { | |
30fb3957 AK |
132 | static const char *fct_name = "getgrnam_r"; |
133 | static service_user *startp = NULL; | |
134 | static void *fct_start = NULL; | |
135 | enum nss_status status; | |
136 | service_user *nip; | |
137 | union { | |
138 | enum nss_status (*l)(const char *name, struct group *grp, | |
139 | char *buffer, size_t buflen, int *errnop); | |
140 | void *ptr; | |
141 | } fct; | |
48479fc7 | 142 | struct group gbuf; |
30fb3957 | 143 | int n; |
48479fc7 | 144 | int old_errno = errno; |
c1812233 AK |
145 | |
146 | int len = sysconf(_SC_GETGR_R_SIZE_MAX); | |
48479fc7 TA |
147 | char *buf = malloc(len); |
148 | if (buf == NULL) { | |
149 | *errnop = ENOMEM; | |
150 | errno = old_errno; | |
151 | return NSS_STATUS_TRYAGAIN; | |
152 | } | |
1e78305d | 153 | |
30fb3957 AK |
154 | if (fct_start == NULL && |
155 | __nss_group_lookup(&startp, fct_name, &fct_start) != 0) { | |
156 | free(buf); | |
157 | return NSS_STATUS_UNAVAIL; | |
158 | } | |
159 | nip = startp; | |
160 | fct.ptr = fct_start; | |
161 | do { | |
d905b369 | 162 | morebuf: |
c1812233 AK |
163 | if (fct.l == _nss_nonlocal_getgrnam_r) |
164 | status = NSS_STATUS_NOTFOUND; | |
165 | else | |
c5e25ab7 | 166 | status = DL_CALL_FCT(fct.l, (name, &gbuf, buf, len, errnop)); |
d905b369 AK |
167 | if (status == NSS_STATUS_TRYAGAIN && *errnop == ERANGE) { |
168 | free(buf); | |
169 | len *= 2; | |
170 | buf = malloc(len); | |
171 | if (buf == NULL) { | |
172 | *errnop = ENOMEM; | |
173 | errno = old_errno; | |
174 | return NSS_STATUS_TRYAGAIN; | |
175 | } | |
176 | goto morebuf; | |
177 | } | |
30fb3957 AK |
178 | } while (__nss_next(&nip, fct_name, &fct.ptr, status, 0) == 0); |
179 | ||
f943c4ed AK |
180 | if (status != NSS_STATUS_SUCCESS) |
181 | goto get_local_group_done; | |
182 | ||
183 | n = snprintf(buffer, buflen, "%s", gbuf.gr_name); | |
184 | if (n < 0 || n >= buflen) { | |
185 | *errnop = ERANGE; | |
186 | status = NSS_STATUS_TRYAGAIN; | |
187 | goto get_local_group_done; | |
188 | } | |
189 | grp->gr_name = buffer; | |
190 | buffer += n; | |
191 | buflen -= n; | |
192 | ||
193 | n = snprintf(buffer, buflen, "%s", gbuf.gr_passwd); | |
194 | if (n < 0 || n >= buflen) { | |
195 | *errnop = ERANGE; | |
196 | status = NSS_STATUS_TRYAGAIN; | |
197 | goto get_local_group_done; | |
198 | } | |
199 | grp->gr_passwd = buffer; | |
200 | buffer += n; | |
201 | buflen -= n; | |
202 | ||
203 | grp->gr_gid = gbuf.gr_gid; | |
204 | ||
205 | if (buflen < sizeof(void *)) { | |
206 | *errnop = ERANGE; | |
207 | status = NSS_STATUS_TRYAGAIN; | |
208 | goto get_local_group_done; | |
48479fc7 | 209 | } |
f943c4ed AK |
210 | *(void **)buffer = NULL; |
211 | buffer += sizeof(void *); | |
212 | buflen -= sizeof(void *); | |
30fb3957 | 213 | |
1e78305d | 214 | get_local_group_done: |
48479fc7 | 215 | free(buf); |
48479fc7 TA |
216 | return status; |
217 | } | |
f6903667 AK |
218 | |
219 | static service_user *grent_nip = NULL; | |
220 | static void *grent_fct_start; | |
221 | static union { | |
222 | enum nss_status (*l)(struct group *grp, char *buffer, size_t buflen, | |
223 | int *errnop); | |
224 | void *ptr; | |
225 | } grent_fct; | |
226 | static const char *grent_fct_name = "getgrent_r"; | |
227 | ||
228 | enum nss_status | |
229 | _nss_nonlocal_setgrent(int stayopen) | |
230 | { | |
231 | static const char *fct_name = "setgrent"; | |
232 | static void *fct_start = NULL; | |
233 | enum nss_status status; | |
234 | service_user *nip; | |
235 | union { | |
236 | enum nss_status (*l)(int stayopen); | |
237 | void *ptr; | |
238 | } fct; | |
239 | ||
240 | nip = nss_group_nonlocal_database(); | |
241 | if (nip == NULL) | |
242 | return NSS_STATUS_UNAVAIL; | |
243 | if (fct_start == NULL) | |
244 | fct_start = __nss_lookup_function(nip, fct_name); | |
245 | fct.ptr = fct_start; | |
246 | do { | |
247 | if (fct.ptr == NULL) | |
248 | status = NSS_STATUS_UNAVAIL; | |
249 | else | |
250 | status = DL_CALL_FCT(fct.l, (stayopen)); | |
251 | } while (__nss_next(&nip, fct_name, &fct.ptr, status, 0) == 0); | |
252 | if (status != NSS_STATUS_SUCCESS) | |
253 | return status; | |
254 | ||
255 | grent_nip = nip; | |
256 | if (grent_fct_start == NULL) | |
257 | grent_fct_start = __nss_lookup_function(nip, grent_fct_name); | |
258 | grent_fct.ptr = grent_fct_start; | |
259 | return NSS_STATUS_SUCCESS; | |
260 | } | |
261 | ||
262 | enum nss_status | |
263 | _nss_nonlocal_endgrent(void) | |
264 | { | |
265 | static const char *fct_name = "endgrent"; | |
266 | static void *fct_start = NULL; | |
267 | enum nss_status status; | |
268 | service_user *nip; | |
269 | union { | |
270 | enum nss_status (*l)(void); | |
271 | void *ptr; | |
272 | } fct; | |
273 | ||
274 | grent_nip = NULL; | |
275 | ||
276 | nip = nss_group_nonlocal_database(); | |
277 | if (nip == NULL) | |
278 | return NSS_STATUS_UNAVAIL; | |
279 | if (fct_start == NULL) | |
280 | fct_start = __nss_lookup_function(nip, fct_name); | |
281 | fct.ptr = fct_start; | |
282 | do { | |
283 | if (fct.ptr == NULL) | |
284 | status = NSS_STATUS_UNAVAIL; | |
285 | else | |
286 | status = DL_CALL_FCT(fct.l, ()); | |
287 | } while (__nss_next(&nip, fct_name, &fct.ptr, status, 0) == 0); | |
288 | return status; | |
289 | } | |
290 | ||
291 | enum nss_status | |
292 | _nss_nonlocal_getgrent_r(struct group *grp, char *buffer, size_t buflen, | |
293 | int *errnop) | |
294 | { | |
295 | enum nss_status status; | |
a360549e TA |
296 | |
297 | char *nonlocal_ignore = getenv(NONLOCAL_IGNORE_ENV); | |
c1812233 | 298 | if (nonlocal_ignore != NULL && nonlocal_ignore[0] != '\0') |
a360549e TA |
299 | return NSS_STATUS_UNAVAIL; |
300 | ||
f6903667 AK |
301 | if (grent_nip == NULL) { |
302 | status = _nss_nonlocal_setgrent(0); | |
303 | if (status != NSS_STATUS_SUCCESS) | |
304 | return status; | |
305 | } | |
306 | do { | |
307 | if (grent_fct.ptr == NULL) | |
308 | status = NSS_STATUS_UNAVAIL; | |
309 | else { | |
310 | int nonlocal_errno; | |
311 | do | |
312 | status = DL_CALL_FCT(grent_fct.l, (grp, buffer, buflen, errnop)); | |
313 | while (status == NSS_STATUS_SUCCESS && | |
314 | check_nonlocal_gid("(unknown)", grp->gr_gid, &nonlocal_errno) != NSS_STATUS_SUCCESS); | |
315 | } | |
316 | if (status == NSS_STATUS_TRYAGAIN && *errnop == ERANGE) | |
317 | return status; | |
318 | ||
319 | if (status == NSS_STATUS_SUCCESS) | |
320 | return NSS_STATUS_SUCCESS; | |
321 | } while (__nss_next(&grent_nip, grent_fct_name, &grent_fct.ptr, status, 0) == 0); | |
322 | ||
323 | grent_nip = NULL; | |
324 | return NSS_STATUS_NOTFOUND; | |
325 | } | |
326 | ||
327 | ||
328 | enum nss_status | |
329 | _nss_nonlocal_getgrnam_r(const char *name, struct group *grp, | |
330 | char *buffer, size_t buflen, int *errnop) | |
331 | { | |
332 | static const char *fct_name = "getgrnam_r"; | |
333 | static void *fct_start = NULL; | |
334 | enum nss_status status; | |
335 | service_user *nip; | |
336 | union { | |
337 | enum nss_status (*l)(const char *name, struct group *grp, | |
338 | char *buffer, size_t buflen, int *errnop); | |
339 | void *ptr; | |
340 | } fct; | |
341 | ||
a360549e | 342 | char *nonlocal_ignore = getenv(NONLOCAL_IGNORE_ENV); |
c1812233 | 343 | if (nonlocal_ignore != NULL && nonlocal_ignore[0] != '\0') |
48479fc7 TA |
344 | return NSS_STATUS_UNAVAIL; |
345 | ||
f6903667 AK |
346 | nip = nss_group_nonlocal_database(); |
347 | if (nip == NULL) | |
348 | return NSS_STATUS_UNAVAIL; | |
349 | if (fct_start == NULL) | |
350 | fct_start = __nss_lookup_function(nip, fct_name); | |
351 | fct.ptr = fct_start; | |
352 | do { | |
353 | if (fct.ptr == NULL) | |
354 | status = NSS_STATUS_UNAVAIL; | |
355 | else | |
356 | status = DL_CALL_FCT(fct.l, (name, grp, buffer, buflen, errnop)); | |
357 | if (status == NSS_STATUS_TRYAGAIN && *errnop == ERANGE) | |
358 | break; | |
359 | } while (__nss_next(&nip, fct_name, &fct.ptr, status, 0) == 0); | |
360 | if (status != NSS_STATUS_SUCCESS) | |
361 | return status; | |
362 | ||
363 | return check_nonlocal_gid(name, grp->gr_gid, errnop); | |
364 | } | |
365 | ||
366 | enum nss_status | |
367 | _nss_nonlocal_getgrgid_r(gid_t gid, struct group *grp, | |
368 | char *buffer, size_t buflen, int *errnop) | |
369 | { | |
370 | static const char *fct_name = "getgrgid_r"; | |
371 | static void *fct_start = NULL; | |
372 | enum nss_status status; | |
373 | service_user *nip; | |
374 | union { | |
375 | enum nss_status (*l)(gid_t gid, struct group *grp, | |
376 | char *buffer, size_t buflen, int *errnop); | |
377 | void *ptr; | |
378 | } fct; | |
379 | ||
a360549e | 380 | char *nonlocal_ignore = getenv(NONLOCAL_IGNORE_ENV); |
c1812233 | 381 | if (nonlocal_ignore != NULL && nonlocal_ignore[0] != '\0') |
f6903667 AK |
382 | return NSS_STATUS_UNAVAIL; |
383 | ||
384 | nip = nss_group_nonlocal_database(); | |
385 | if (nip == NULL) | |
386 | return NSS_STATUS_UNAVAIL; | |
387 | if (fct_start == NULL) | |
388 | fct_start = __nss_lookup_function(nip, fct_name); | |
389 | fct.ptr = fct_start; | |
390 | do { | |
391 | if (fct.ptr == NULL) | |
392 | status = NSS_STATUS_UNAVAIL; | |
393 | else | |
394 | status = DL_CALL_FCT(fct.l, (gid, grp, buffer, buflen, errnop)); | |
395 | if (status == NSS_STATUS_TRYAGAIN && *errnop == ERANGE) | |
396 | break; | |
397 | } while (__nss_next(&nip, fct_name, &fct.ptr, status, 0) == 0); | |
398 | if (status != NSS_STATUS_SUCCESS) | |
399 | return status; | |
400 | ||
401 | return check_nonlocal_gid(grp->gr_name, grp->gr_gid, errnop); | |
402 | } | |
403 | ||
404 | enum nss_status | |
405 | _nss_nonlocal_initgroups_dyn(const char *user, gid_t group, long int *start, | |
406 | long int *size, gid_t **groupsp, long int limit, | |
407 | int *errnop) | |
408 | { | |
409 | static const char *fct_name = "initgroups_dyn"; | |
410 | static void *fct_start = NULL; | |
411 | enum nss_status status; | |
412 | service_user *nip; | |
413 | union { | |
414 | enum nss_status (*l)(const char *user, gid_t group, long int *start, | |
415 | long int *size, gid_t **groupsp, long int limit, | |
416 | int *errnop); | |
417 | void *ptr; | |
418 | } fct; | |
1e78305d AK |
419 | |
420 | struct group local_users_group, nonlocal_users_group; | |
421 | gid_t local_users_gid, gid; | |
48479fc7 | 422 | int is_local = 0; |
1e78305d AK |
423 | int buflen; |
424 | char *buffer; | |
48479fc7 | 425 | |
1e78305d | 426 | /* Check that the user is a nonlocal user before adding any groups. */ |
48479fc7 | 427 | status = check_nonlocal_user(user, errnop); |
5879a696 | 428 | if (status == NSS_STATUS_TRYAGAIN) |
48479fc7 | 429 | return status; |
5879a696 AK |
430 | else if (status != NSS_STATUS_SUCCESS) |
431 | is_local = 1; | |
48479fc7 | 432 | |
1e78305d AK |
433 | int old_errno = errno; |
434 | ||
435 | buflen = sysconf(_SC_GETGR_R_SIZE_MAX); | |
436 | buffer = malloc(buflen); | |
48479fc7 TA |
437 | if (buffer == NULL) { |
438 | *errnop = ENOMEM; | |
1e78305d | 439 | errno = old_errno; |
48479fc7 TA |
440 | return NSS_STATUS_TRYAGAIN; |
441 | } | |
48479fc7 TA |
442 | status = get_local_group(MAGIC_LOCAL_GROUPNAME, |
443 | &local_users_group, buffer, buflen, errnop); | |
5879a696 AK |
444 | if (status == NSS_STATUS_SUCCESS) { |
445 | local_users_gid = local_users_group.gr_gid; | |
446 | } else if (status == NSS_STATUS_TRYAGAIN) { | |
dc94c928 | 447 | free(buffer); |
5879a696 AK |
448 | return status; |
449 | } else { | |
48479fc7 TA |
450 | syslog(LOG_WARNING, "nss_nonlocal: Group %s does not exist locally!", |
451 | MAGIC_LOCAL_GROUPNAME); | |
1e78305d | 452 | local_users_gid = -1; |
5879a696 | 453 | } |
1e78305d AK |
454 | free(buffer); |
455 | ||
456 | if (is_local) { | |
457 | gid = local_users_gid; | |
458 | } else { | |
459 | buflen = sysconf(_SC_GETGR_R_SIZE_MAX); | |
460 | buffer = malloc(buflen); | |
461 | if (buffer == NULL) { | |
462 | *errnop = ENOMEM; | |
463 | errno = old_errno; | |
464 | return NSS_STATUS_TRYAGAIN; | |
48479fc7 | 465 | } |
1e78305d AK |
466 | status = get_local_group(MAGIC_NONLOCAL_GROUPNAME, |
467 | &nonlocal_users_group, buffer, buflen, errnop); | |
5879a696 AK |
468 | if (status == NSS_STATUS_SUCCESS) { |
469 | gid = nonlocal_users_group.gr_gid; | |
470 | } else if (status == NSS_STATUS_TRYAGAIN) { | |
dc94c928 | 471 | free(buffer); |
5879a696 AK |
472 | return status; |
473 | } else { | |
1e78305d AK |
474 | syslog(LOG_WARNING, "nss_nonlocal: Group %s does not exist locally!", |
475 | MAGIC_NONLOCAL_GROUPNAME); | |
476 | gid = -1; | |
5879a696 | 477 | } |
1e78305d | 478 | free(buffer); |
48479fc7 | 479 | } |
1e78305d AK |
480 | |
481 | if (gid != -1) { | |
482 | int i; | |
483 | for (i = 0; i < *start; ++i) | |
484 | if ((*groupsp)[i] == gid) | |
485 | break; | |
486 | if (i >= *start) { | |
487 | if (*start + 1 > *size) { | |
488 | gid_t *newgroups; | |
489 | long int newsize = 2 * *size; | |
490 | if (limit > 0) { | |
491 | if (*size >= limit) | |
492 | return NSS_STATUS_SUCCESS; | |
493 | if (newsize > limit) | |
494 | newsize = limit; | |
495 | } | |
ad0399bd | 496 | newgroups = realloc(*groupsp, newsize * sizeof((*groupsp)[0])); |
1e78305d AK |
497 | if (newgroups == NULL) { |
498 | *errnop = ENOMEM; | |
499 | errno = old_errno; | |
500 | return NSS_STATUS_TRYAGAIN; | |
501 | } | |
502 | *groupsp = newgroups; | |
503 | *size = newsize; | |
504 | } | |
505 | (*groupsp)[(*start)++] = gid; | |
506 | } | |
48479fc7 | 507 | } |
f6903667 | 508 | |
1e78305d AK |
509 | if (is_local) |
510 | return NSS_STATUS_SUCCESS; | |
511 | ||
512 | int in = *start, out = *start, i; | |
513 | ||
f6903667 AK |
514 | nip = nss_group_nonlocal_database(); |
515 | if (nip == NULL) | |
516 | return NSS_STATUS_UNAVAIL; | |
517 | if (fct_start == NULL) | |
518 | fct_start = __nss_lookup_function(nip, fct_name); | |
519 | fct.ptr = fct_start; | |
520 | ||
521 | do { | |
522 | if (fct.ptr == NULL) | |
523 | status = NSS_STATUS_UNAVAIL; | |
524 | else | |
525 | status = DL_CALL_FCT(fct.l, (user, group, start, size, groupsp, limit, errnop)); | |
526 | if (status == NSS_STATUS_TRYAGAIN && *errnop == ERANGE) | |
527 | break; | |
528 | } while (__nss_next(&nip, fct_name, &fct.ptr, status, 0) == 0); | |
529 | if (status != NSS_STATUS_SUCCESS) | |
530 | return status; | |
531 | ||
532 | for (; in < *start; ++in) { | |
533 | int nonlocal_errno = *errnop; | |
534 | ||
535 | for (i = 0; i < out; ++i) | |
536 | if ((*groupsp)[i] == (*groupsp)[in]) | |
537 | break; | |
538 | if (i < out) | |
539 | continue; | |
540 | ||
1e78305d AK |
541 | /* Don't let users get into MAGIC_LOCAL_GROUPNAME from nonlocal reasons. */ |
542 | if (local_users_gid == (*groupsp)[in]) { | |
543 | syslog(LOG_WARNING, "nss_nonlocal: Nonlocal user %s removed from special local users group %s", | |
544 | user, MAGIC_LOCAL_GROUPNAME); | |
545 | continue; | |
546 | } | |
547 | ||
f6903667 AK |
548 | status = check_nonlocal_gid(user, (*groupsp)[in], &nonlocal_errno); |
549 | if (status == NSS_STATUS_SUCCESS) { | |
1e78305d | 550 | (*groupsp)[out++] = (*groupsp)[in]; |
5879a696 | 551 | } else if (status == NSS_STATUS_TRYAGAIN) { |
f6903667 AK |
552 | *start = out; |
553 | *errnop = nonlocal_errno; | |
554 | return status; | |
555 | } | |
556 | } | |
557 | ||
558 | *start = out; | |
559 | return NSS_STATUS_SUCCESS; | |
560 | } |