summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2018-08-01 20:29:17 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2018-08-01 20:29:17 +0000
commit6b47e7d8a9c1f55f36fadc7ad9061fc69488f934 (patch)
tree9d8f8d52e96a16d90c1902067dcaa2c18922fa0e /src
parent57695697a8959927c760b5b52401604f596ad33f (diff)
downloads6-6b47e7d8a9c1f55f36fadc7ad9061fc69488f934.tar.xz
Include prot_readgroups() into s6-envuidgid
Diffstat (limited to 'src')
-rw-r--r--src/daemontools-extras/s6-envuidgid.c20
1 files changed, 20 insertions, 0 deletions
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 <string.h>
#include <pwd.h>
#include <grp.h>
+#include <errno.h>
#include <limits.h>
#include <skalibs/types.h>
#include <skalibs/sgetopt.h>
@@ -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 ;