summaryrefslogtreecommitdiff
path: root/src/libstddjb/prot.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstddjb/prot.c')
-rw-r--r--src/libstddjb/prot.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/libstddjb/prot.c b/src/libstddjb/prot.c
new file mode 100644
index 0000000..6714cfb
--- /dev/null
+++ b/src/libstddjb/prot.c
@@ -0,0 +1,19 @@
+/* ISC license. */
+
+/* MT-unsafe */
+
+#include <unistd.h>
+#include <pwd.h>
+#include <errno.h>
+#include <skalibs/djbunix.h>
+
+int prot_setuidgid (char const *name)
+{
+ struct passwd *pw = getpwnam(name) ;
+ if (!pw)
+ {
+ if (!errno) errno = ESRCH ;
+ return 0 ;
+ }
+ return !prot_grps(name) && !setgid(pw->pw_gid) && !setuid(pw->pw_uid) ;
+}