From 6b47e7d8a9c1f55f36fadc7ad9061fc69488f934 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Wed, 1 Aug 2018 20:29:17 +0000 Subject: Include prot_readgroups() into s6-envuidgid --- src/daemontools-extras/s6-envuidgid.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/daemontools-extras') diff --git a/src/daemontools-extras/s6-envuidgid.c b/src/daemontools-extras/s6-envuidgid.c index 360c426..ec809e0 100644 --- a/src/daemontools-extras/s6-envuidgid.c +++ b/src/daemontools-extras/s6-envuidgid.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -44,6 +45,25 @@ static inline size_t scan_defaults (char const *s, uid_t *uid, gid_t *gid, size_ return 1 ; } +static int prot_readgroups (char const *name, gid_t *tab, unsigned int max) +{ + unsigned int n = 0 ; + for (;;) + { + struct group *gr ; + char **member ; + errno = 0 ; + if (n >= max) break ; + gr = getgrent() ; + if (!gr) break ; + for (member = gr->gr_mem ; *member ; member++) + if (!strcmp(name, *member)) break ; + if (*member) tab[n++] = gr->gr_gid ; + } + endgrent() ; + return errno ? -1 : n ; +} + int main (int argc, char *const *argv, char const *const *envp) { char const *user = 0 ; -- cgit 1.4.1