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 int
procsetuser(char *user) procsetuser(char *user)
{ {
int fd, n; char name[32];
Dir dir;
fd = open("#c/user", OWRITE|OCEXEC); nulldir(&dir);
if(fd < 0) dir.uid = user;
return -1; snprint(name, sizeof(name), "/proc/%lud/ctl", (ulong)getpid());
n = strlen(user); if(dirwstat(name, &dir) < 0){
if(write(fd, user, n) != n){ /*
* 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); close(fd);
return -1;
} }
close(fd);
return 0; return 0;
} }