ref: a48d7923bbff3eb78359c7fa72468230791ab403
parent: 0990cff3df2c492068ace8261b2e86c5530a8709
author: cinap_lenrek <cinap_lenrek@felloff.net>
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;
}
--
⑨