ref: 46aac917d3c93f4246f3b6e661225f9114c7d381
parent: 00317de870888e39b22f75f177407405bf3a6ae6
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sat Dec 19 13:02:37 EST 2020
libauth: change programs to use the new procsetuser() function
--- a/sys/src/cmd/auth/none.c
+++ b/sys/src/cmd/auth/none.c
@@ -43,13 +43,8 @@
usage();
}ARGEND
- fd = open("#c/user", OWRITE);- if(fd < 0)
- sysfatal("can't open #c/user: %r");- if(write(fd, "none", strlen("none")) < 0)+ if(procsetuser("none") < 0) sysfatal("can't become none: %r");- close(fd);
-
if(newns("none", namespace) < 0) sysfatal("can't build namespace: %r");--- a/sys/src/cmd/aux/listen.c
+++ b/sys/src/cmd/aux/listen.c
@@ -338,12 +338,8 @@
void
becomenone(void)
{- int fd;
-
- fd = open("#c/user", OWRITE);- if(fd < 0 || write(fd, "none", strlen("none")) < 0)+ if(procsetuser("none") < 0) error("can't become none");- close(fd);
if(newns("none", namespace) < 0) error("can't build namespace");}
--- a/sys/src/cmd/aux/listen1.c
+++ b/sys/src/cmd/aux/listen1.c
@@ -18,12 +18,8 @@
void
becomenone(void)
{- int fd;
-
- fd = open("#c/user", OWRITE);- if(fd < 0 || write(fd, "none", strlen("none")) < 0)+ if(procsetuser("none") < 0) sysfatal("can't become none: %r");- close(fd);
if(newns("none", nsfile) < 0) sysfatal("can't build namespace: %r");}
--- a/sys/src/cmd/ip/httpd/httpd.c
+++ b/sys/src/cmd/ip/httpd/httpd.c
@@ -129,16 +129,12 @@
static void
becomenone(char *namespace)
{- int fd;
-
- fd = open("#c/user", OWRITE);- if(fd < 0 || write(fd, "none", strlen("none")) < 0)- sysfatal("can't become none");- close(fd);
+ if(procsetuser("none") < 0)+ sysfatal("can't become none: %r"); if(newns("none", nil) < 0)- sysfatal("can't build normal namespace");+ sysfatal("can't build normal namespace: %r"); if(addns("none", namespace) < 0)- sysfatal("can't build httpd namespace");+ sysfatal("can't build httpd namespace: %r");}
static HConnect*
--- a/sys/src/cmd/mount.c
+++ b/sys/src/cmd/mount.c
@@ -83,8 +83,7 @@
}
if(asnone){- rv = open("#c/user", OWRITE);- if(rv < 0 || write(rv, "none", 4) != 4){+ if(procsetuser("none") < 0){if(qflag)
exits(0);
fprint(2, "%s: can't become none: %r\n", argv0);
--- a/sys/src/cmd/srv.c
+++ b/sys/src/cmd/srv.c
@@ -202,12 +202,11 @@
exits(0);
if(asnone){- try = open("#c/user", OWRITE);- if(try < 0 || write(try, "none", 4) != 4){+ if(procsetuser("none") < 0){fprint(2, "srv %s: can't become none: %r\n", dest);
exits("becomenone");}
- try = 0;
+ try = 0; /* no retry */
}
if((!doauth && mount(fd, -1, mtpt, mountflag, "") == -1)
--- a/sys/src/cmd/upas/common/become.c
+++ b/sys/src/cmd/upas/common/become.c
@@ -8,17 +8,13 @@
int
become(char **, char *who)
{- int fd;
-
if(strcmp(who, "none") == 0) {- fd = open("#c/user", OWRITE);- if(fd < 0 || write(fd, "none", strlen("none")) < 0) {- werrstr("can't become none");+ if(procsetuser("none") < 0) {+ werrstr("can't become none: %r");return -1;
}
- close(fd);
- if(newns("none", 0)) {- werrstr("can't set new namespace");+ if(newns("none", nil) < 0) {+ werrstr("can't set new namespace: %r");return -1;
}
}
--
⑨