ref: 874e71c8dc489b820c9a6066d13c470a34d7f83f
parent: ab103ba3496b359f040afa845065976514392071
author: cinap_lenrek <[email protected]>
date: Wed Dec 23 08:10:30 EST 2020
libauth: re-implement procsetuser() to use /proc instead of #c/user
--- a/sys/src/libauth/procsetuser.c
+++ b/sys/src/libauth/procsetuser.c
@@ -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;
}