From 49d66bcce5aa57acc5fb71efe93f531cae9d7402 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Sat, 21 Sep 2019 06:14:58 +0000 Subject: Remove tainnow dependency in configure too --- src/libnsss/nsss_unix_getgrouplist.c | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/libnsss/nsss_unix_getgrouplist.c (limited to 'src/libnsss/nsss_unix_getgrouplist.c') diff --git a/src/libnsss/nsss_unix_getgrouplist.c b/src/libnsss/nsss_unix_getgrouplist.c new file mode 100644 index 0000000..e9a11ab --- /dev/null +++ b/src/libnsss/nsss_unix_getgrouplist.c @@ -0,0 +1,43 @@ +/* ISC license. */ + +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include "nsss-unix-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 ; +} -- cgit v1.3.1