summaryrefslogtreecommitdiff
path: root/sys/src/libauth
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
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')
-rw-r--r--sys/src/libauth/mkfile1
-rw-r--r--sys/src/libauth/procsetuser.c20
2 files changed, 21 insertions, 0 deletions
diff --git a/sys/src/libauth/mkfile b/sys/src/libauth/mkfile
index 2030db8f1..65505703e 100644
--- a/sys/src/libauth/mkfile
+++ b/sys/src/libauth/mkfile
@@ -17,6 +17,7 @@ OFILES=\
login.$O\
newns.$O\
noworld.$O\
+ procsetuser.$O\
HFILES=\
/sys/include/auth.h\
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;
+}