From: David Lamparter Date: Tue, 15 Sep 2015 09:26:44 +0000 (-0700) Subject: lib: add getgrouplist() for Solaris X-Git-Tag: frr-2.0-rc1~977 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=4a9ea50e1b7d0d4172accd3acac46f9cb2e4d531;p=matthieu%2Ffrr.git lib: add getgrouplist() for Solaris Of course Solaris doesn't have getgrouplist()... Signed-off-by: David Lamparter --- diff --git a/configure.ac b/configure.ac index 8f8859a3f1..718bd2d03c 100755 --- a/configure.ac +++ b/configure.ac @@ -830,7 +830,7 @@ AC_CHECK_FUNCS([dup2 ftruncate getcwd gethostbyname getpagesize gettimeofday \ strtol strtoul strlcat strlcpy \ daemon snprintf vsnprintf \ if_nametoindex if_indextoname getifaddrs \ - uname fcntl]) + uname fcntl getgrouplist]) dnl ------------------------------------ dnl Determine routing get and set method diff --git a/lib/privs.c b/lib/privs.c index ff0be2fe12..0ca8783dcc 100644 --- a/lib/privs.c +++ b/lib/privs.c @@ -622,6 +622,41 @@ zprivs_state_null (void) return zprivs_null_state; } +#ifndef HAVE_GETGROUPLIST +/* Solaris 11 has no getgrouplist() */ +static int +getgrouplist(const char *user, gid_t group, gid_t *groups, int *ngroups) +{ + struct group *grp; + size_t usridx; + int pos = 0, ret; + + if (pos < *ngroups) + groups[pos] = group; + pos++; + + setgrent(); + while ((grp = getgrent())) + { + if (grp->gr_gid == group) + continue; + for (usridx = 0; grp->gr_mem[usridx] != NULL; usridx++) + if (!strcmp (grp->gr_mem[usridx], user)) + { + if (pos < *ngroups) + groups[pos] = grp->gr_gid; + pos++; + break; + } + } + endgrent(); + + ret = (pos <= *ngroups) ? pos : -1; + *ngroups = pos; + return ret; +} +#endif /* HAVE_GETGROUPLIST */ + void zprivs_init(struct zebra_privs_t *zprivs) {