diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2020-12-19 17:46:55 +0100 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2020-12-19 17:46:55 +0100 |
commit | fc5070c60057b6e02490e83f5d675786e8b8d83c (patch) | |
tree | aa53401ba8b9b435b0908ee0fda353f998b0d4a6 /sys/src | |
parent | daccd2b226ff71c251931103403a982d2796061a (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')
-rw-r--r-- | sys/src/ape/lib/auth/mkfile | 1 | ||||
-rw-r--r-- | sys/src/libauth/mkfile | 1 | ||||
-rw-r--r-- | sys/src/libauth/procsetuser.c | 20 |
3 files changed, 22 insertions, 0 deletions
diff --git a/sys/src/ape/lib/auth/mkfile b/sys/src/ape/lib/auth/mkfile index 4c292db38..a7a07ee87 100644 --- a/sys/src/ape/lib/auth/mkfile +++ b/sys/src/ape/lib/auth/mkfile @@ -18,6 +18,7 @@ OFILES=\ login.$O\ newns.$O\ noworld.$O\ + procsetuser.$O\ passtokey.$O\ HFILES=\ 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; +} |