summaryrefslogtreecommitdiff
path: root/sys/src/libauth/procsetuser.c
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2020-12-19 17:46:55 +0100
committercinap_lenrek <cinap_lenrek@felloff.net>2020-12-19 17:46:55 +0100
commitfc5070c60057b6e02490e83f5d675786e8b8d83c (patch)
treeaa53401ba8b9b435b0908ee0fda353f998b0d4a6 /sys/src/libauth/procsetuser.c
parentdaccd2b226ff71c251931103403a982d2796061a (diff)
libauth: add procsetuser() function to change user id of the calling process
Provide a central function to change the user id of the calling process. This is mostly used by programs to become the none user, followed by a call to newns().
Diffstat (limited to 'sys/src/libauth/procsetuser.c')
-rw-r--r--sys/src/libauth/procsetuser.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/sys/src/libauth/procsetuser.c b/sys/src/libauth/procsetuser.c
new file mode 100644
index 000000000..f9cac306b
--- /dev/null
+++ b/sys/src/libauth/procsetuser.c
@@ -0,0 +1,20 @@
+#include <u.h>
+#include <libc.h>
+#include <auth.h>
+
+int
+procsetuser(char *user)
+{
+ int fd, n;
+
+ fd = open("#c/user", OWRITE|OCEXEC);
+ if(fd < 0)
+ return -1;
+ n = strlen(user);
+ if(write(fd, user, n) != n){
+ close(fd);
+ return -1;
+ }
+ close(fd);
+ return 0;
+}