libauth: re-implement procsetuser() to use /proc instead of #c/user

front
cinap_lenrek 2020-12-23 13:10:30 +01:00
parent ab103ba349
commit 874e71c8dc
1 changed files with 22 additions and 8 deletions

View File

@ -5,16 +5,30 @@
int
procsetuser(char *user)
{
int fd, n;
char name[32];
Dir dir;
fd = open("#c/user", OWRITE|OCEXEC);
if(fd < 0)
return -1;
n = strlen(user);
if(write(fd, user, n) != n){
nulldir(&dir);
dir.uid = user;
snprint(name, sizeof(name), "/proc/%lud/ctl", (ulong)getpid());
if(dirwstat(name, &dir) < 0){
/*
* this is backwards compatibility code as
* devproc initially didnt allow changing
* the user to none.
*/
int fd;
if(strcmp(user, "none") != 0)
return -1;
fd = open("#c/user", OWRITE|OCEXEC);
if(fd < 0)
return -1;
if(write(fd, "none", 4) != 4){
close(fd);
return -1;
}
close(fd);
return -1;
}
close(fd);
return 0;
}