summaryrefslogtreecommitdiff
path: root/libc/sysdeps/linux/common/setegid.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2003-11-02 10:03:23 +0000
committerEric Andersen <andersen@codepoet.org>2003-11-02 10:03:23 +0000
commit44ecacea6b45d7ae5d5eb70fe01d7ade4b90c525 (patch)
treef142bea472c41532b8d3eddfb3694cd16e31551f /libc/sysdeps/linux/common/setegid.c
parent733eb3f9b3e3d1586c726c8db19ae721a84e125f (diff)
Both setegid and seteuid were implemented suboptimally, such that
we were unable to switch back to the original saved group/user ID. -Erik
Diffstat (limited to 'libc/sysdeps/linux/common/setegid.c')
-rw-r--r--libc/sysdeps/linux/common/setegid.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/libc/sysdeps/linux/common/setegid.c b/libc/sysdeps/linux/common/setegid.c
index 90928c247..100a34568 100644
--- a/libc/sysdeps/linux/common/setegid.c
+++ b/libc/sysdeps/linux/common/setegid.c
@@ -1,8 +1,28 @@
-#include <stdlib.h>
+#define _GNU_SOURCE
#include <unistd.h>
+#include <stdio.h>
+#include <errno.h>
+#include <grp.h>
#include <sys/types.h>
+#include <sys/syscall.h>
int setegid(gid_t gid)
{
- return setregid(-1, gid);
+ int result;
+
+ if (gid == (gid_t) ~0)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+#ifdef __NR_setresgid
+ result = setresgid(-1, gid, -1);
+ if (result == -1 && errno == ENOSYS)
+ /* Will also set the saved group ID if egid != gid,
+ * making it impossible to switch back...*/
+#endif
+ result = setregid(-1, gid);
+
+ return result;
}