diff options
| author | Laurent Bercot <ska-skaware@skarnet.org> | 2019-09-21 21:17:34 +0000 |
|---|---|---|
| committer | Laurent Bercot <ska-skaware@skarnet.org> | 2019-09-21 21:17:34 +0000 |
| commit | 426039bdd70a5502d56fbc2a9dcde5817b145c1c (patch) | |
| tree | d796c9013d131297819b9d7637bea628d9c117d7 /src/libnsss/nsss_unix_getgrouplist.c | |
| parent | ce150eb99b4af0f509e86c0e077abb5203253049 (diff) | |
| download | nsss-426039bdd70a5502d56fbc2a9dcde5817b145c1c.tar.gz | |
Add getgrouplist() support (stubbed in nsssd-nslcd)
Diffstat (limited to 'src/libnsss/nsss_unix_getgrouplist.c')
| -rw-r--r-- | src/libnsss/nsss_unix_getgrouplist.c | 34 |
1 files changed, 5 insertions, 29 deletions
diff --git a/src/libnsss/nsss_unix_getgrouplist.c b/src/libnsss/nsss_unix_getgrouplist.c index e9a11ab..83a8aeb 100644 --- a/src/libnsss/nsss_unix_getgrouplist.c +++ b/src/libnsss/nsss_unix_getgrouplist.c @@ -1,43 +1,19 @@ /* ISC license. */ -#include <string.h> -#include <unistd.h> +#include <stddef.h> #include <errno.h> -#include <limits.h> -#include <skalibs/stralloc.h> -#include <skalibs/genalloc.h> -#include <skalibs/skamisc.h> - -#include <nsss/grp-def.h> -#include <nsss/grp-unix.h> #include <nsss/nsss-unix.h> -#include "nsss-unix-internal.h" +#include <nsss/grp-unix.h> +#include "nsss-internal.h" int nsss_unix_getgrouplist (char const *user, gid_t gid, gid_t *gids, int *ngids) { - nsss_unix_t a = NSSS_UNIX_ZERO ; - stralloc sa = STRALLOC_ZERO ; - genalloc ga = GENALLOC_ZERO ; /* char * */ int e = errno ; size_t r = 0 ; size_t n ; if (*ngids < 0) return (errno = EINVAL, -1) ; n = *ngids ; - if (!nsss_unix_grp_start(&a)) return -1 ; - if (!nsss_unix_grp_getlist(&a, gids, n, &r, &sa, &ga, user)) return -1 ; - nsss_unix_grp_end(&a) ; - if (r > INT_MAX) return (errno = EMSGSIZE, -1) ; - if (r > n) return (*ngids = (int)r, errno = ENOBUFS, -1) ; - for (size_t i = 0 ; i < r ; i++) - if (gid == gids[i]) goto ok ; - r++ ; - if (r > INT_MAX) return (errno = EMSGSIZE, -1) ; - if (r > n) return (*ngids = (int)r, errno = ENOBUFS, -1) ; - memmove(gids + 1, gids, (r-1) * sizeof(gid_t)) ; - gids[0] = gid ; - ok: - *ngids = (int)r ; - errno = e ; - return (int)n ; + if (!nsss_unix_getgrouplist_preadjust(user, gids, n, &r)) return -1 ; + return nsss_grouplist_adjust(n, r, gid, gids, ngids, e) ; } |
