summaryrefslogtreecommitdiff
path: root/src/libstddjb/prot_grps.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstddjb/prot_grps.c')
-rw-r--r--src/libstddjb/prot_grps.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/libstddjb/prot_grps.c b/src/libstddjb/prot_grps.c
index cc4ba0d..c5ea35b 100644
--- a/src/libstddjb/prot_grps.c
+++ b/src/libstddjb/prot_grps.c
@@ -2,16 +2,26 @@
/* MT-unsafe */
-#include <skalibs/nonposix.h>
#include <unistd.h>
+#include <pwd.h>
#include <grp.h>
#include <limits.h>
+#include <errno.h>
#include <skalibs/setgroups.h>
#include <skalibs/djbunix.h>
int prot_grps (char const *name)
{
gid_t tab[NGROUPS_MAX] ;
+ struct passwd *pw ;
int n = prot_readgroups(name, tab, NGROUPS_MAX) ;
- return n < 0 ? -1 : setgroups(n, tab) ;
+ if (n < 0) return n ;
+ errno = 0 ;
+ pw = getpwnam(name) ;
+ if (!pw)
+ {
+ if (!errno) errno = ENOENT ;
+ return -1 ;
+ }
+ return setgroups_and_gid(pw->pw_gid, n, tab) ;
}