summaryrefslogtreecommitdiff
path: root/src/libstddjb/setgroups.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2017-07-16 16:52:08 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2017-07-16 16:52:08 +0000
commit8b000a20cc367c727b9f2c0d8e68372d0c9df995 (patch)
tree4b1fe6d66241ee4844a77f9dad61bf14a3bb97e2 /src/libstddjb/setgroups.c
parent61c1f79bcace61c650edd09fc4424c2d08fbf79e (diff)
downloadskalibs-8b000a20cc367c727b9f2c0d8e68372d0c9df995.tar.xz
More secure setgroups functions. (thanks muh)
Diffstat (limited to 'src/libstddjb/setgroups.c')
-rw-r--r--src/libstddjb/setgroups.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/libstddjb/setgroups.c b/src/libstddjb/setgroups.c
index c7610ab..d064ed2 100644
--- a/src/libstddjb/setgroups.c
+++ b/src/libstddjb/setgroups.c
@@ -10,10 +10,9 @@
#include <grp.h>
#include <skalibs/setgroups.h>
-int setgroups_with_egid (size_t n, gid_t const *tab)
+int setgroups_and_gid (gid_t g, size_t n, gid_t const *tab)
{
size_t i = 1 ;
- gid_t g = getegid() ;
if (!n) return setgroups(1, &g) ;
if (tab[0] == g) return setgroups(n, tab) ;
for (; i < n ; i++) if (tab[i] == g) break ;
@@ -34,6 +33,11 @@ int setgroups_with_egid (size_t n, gid_t const *tab)
}
}
+int setgroups_with_egid (size_t n, gid_t const *tab)
+{
+ return setgroups_and_gid(getegid(), n, tab) ;
+}
+
int skalibs_setgroups (size_t n, gid_t const *tab)
{
#ifdef SKALIBS_BSD_SUCKS