1 |
+ |
/* $MidnightBSD$ */ |
2 |
|
/*- |
3 |
|
* Copyright (c) 2003 Networks Associates Technology, Inc. |
4 |
|
* All rights reserved. |
32 |
|
* |
33 |
|
*/ |
34 |
|
#include <sys/cdefs.h> |
35 |
< |
__MBSDID("$MidnightBSD$"); |
35 |
> |
__FBSDID("$FreeBSD: stable/10/lib/libc/gen/getgrent.c 328943 2018-02-06 19:09:49Z mckusick $"); |
36 |
|
|
37 |
|
#include "namespace.h" |
38 |
|
#include <sys/param.h> |
434 |
|
{ |
435 |
|
int ret, dupc; |
436 |
|
|
437 |
< |
for (dupc = 0; dupc < MIN(maxgrp, *grpcnt); dupc++) { |
437 |
> |
for (dupc = 1; dupc < MIN(maxgrp, *grpcnt); dupc++) { |
438 |
|
if (groups[dupc] == gid) |
439 |
|
return 1; |
440 |
|
} |
660 |
|
NS_FALLBACK_CB(getgroupmembership_fallback) |
661 |
|
{ NULL, NULL, NULL } |
662 |
|
}; |
662 |
– |
int rv; |
663 |
|
|
664 |
|
assert(uname != NULL); |
665 |
|
/* groups may be NULL if just sizing when invoked with maxgrp = 0 */ |
666 |
|
assert(grpcnt != NULL); |
667 |
|
|
668 |
|
*grpcnt = 0; |
669 |
< |
rv = _nsdispatch(NULL, dtab, NSDB_GROUP, "getgroupmembership", |
669 |
> |
(void)_nsdispatch(NULL, dtab, NSDB_GROUP, "getgroupmembership", |
670 |
|
defaultsrc, uname, agroup, groups, maxgrp, grpcnt); |
671 |
|
|
672 |
|
/* too many groups found? */ |
810 |
|
if (st->fp != NULL) |
811 |
|
rewind(st->fp); |
812 |
|
else if (stayopen) |
813 |
< |
st->fp = fopen(_PATH_GROUP, "r"); |
813 |
> |
st->fp = fopen(_PATH_GROUP, "re"); |
814 |
|
break; |
815 |
|
case ENDGRENT: |
816 |
|
if (st->fp != NULL) { |
861 |
|
if (*errnop != 0) |
862 |
|
return (NS_UNAVAIL); |
863 |
|
if (st->fp == NULL && |
864 |
< |
((st->fp = fopen(_PATH_GROUP, "r")) == NULL)) { |
864 |
> |
((st->fp = fopen(_PATH_GROUP, "re")) == NULL)) { |
865 |
|
*errnop = errno; |
866 |
|
return (NS_UNAVAIL); |
867 |
|
} |
1251 |
|
if (st->fp != NULL) |
1252 |
|
rewind(st->fp); |
1253 |
|
else if (stayopen) |
1254 |
< |
st->fp = fopen(_PATH_GROUP, "r"); |
1254 |
> |
st->fp = fopen(_PATH_GROUP, "re"); |
1255 |
|
set_setent(dtab, mdata); |
1256 |
|
(void)_nsdispatch(NULL, dtab, NSDB_GROUP_COMPAT, "setgrent", |
1257 |
|
compatsrc, 0); |
1335 |
|
if (*errnop != 0) |
1336 |
|
return (NS_UNAVAIL); |
1337 |
|
if (st->fp == NULL && |
1338 |
< |
((st->fp = fopen(_PATH_GROUP, "r")) == NULL)) { |
1338 |
> |
((st->fp = fopen(_PATH_GROUP, "re")) == NULL)) { |
1339 |
|
*errnop = errno; |
1340 |
|
rv = NS_UNAVAIL; |
1341 |
|
goto fin; |