s6

Mirror/fork of https://skarnet.org/software/s6/
git clone https://ccx.te2000.cz/git/s6
Log | Files | Refs | README | LICENSE

commit 6b47e7d8a9c1f55f36fadc7ad9061fc69488f934
parent 57695697a8959927c760b5b52401604f596ad33f
Author: Laurent Bercot <ska-skaware@skarnet.org>
Date:   Wed,  1 Aug 2018 20:29:17 +0000

 Include prot_readgroups() into s6-envuidgid

Diffstat:
Msrc/daemontools-extras/s6-envuidgid.c | 20++++++++++++++++++++
1 file changed, 20 insertions(+), 0 deletions(-)

diff --git 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 ;