summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2020-12-23 13:10:30 +0100
committercinap_lenrek <cinap_lenrek@felloff.net>2020-12-23 13:10:30 +0100
commit874e71c8dc489b820c9a6066d13c470a34d7f83f (patch)
tree2b61bc88e42fb2677eaf51f1c67ee0efcf70eae4
parentab103ba3496b359f040afa845065976514392071 (diff)
downloadplan9front-874e71c8dc489b820c9a6066d13c470a34d7f83f.tar.xz
libauth: re-implement procsetuser() to use /proc instead of #c/user
-rw-r--r--sys/src/libauth/procsetuser.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/sys/src/libauth/procsetuser.c b/sys/src/libauth/procsetuser.c
index f9cac306b..f3aad38d8 100644
--- 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;
}