plan9fox/sys/src/libauth/procsetuser.c
cinap_lenrek fc5070c600 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().
2020-12-19 17:46:55 +01:00

21 lines
261 B
C

#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;
}