libauth: change programs to use the new procsetuser() function

This commit is contained in:
cinap_lenrek 2020-12-19 18:02:37 +01:00
parent fc5070c600
commit eb1dfed9ab
7 changed files with 14 additions and 37 deletions

View file

@ -43,13 +43,8 @@ main(int argc, char *argv[])
usage(); usage();
}ARGEND }ARGEND
fd = open("#c/user", OWRITE); if(procsetuser("none") < 0)
if(fd < 0)
sysfatal("can't open #c/user: %r");
if(write(fd, "none", strlen("none")) < 0)
sysfatal("can't become none: %r"); sysfatal("can't become none: %r");
close(fd);
if(newns("none", namespace) < 0) if(newns("none", namespace) < 0)
sysfatal("can't build namespace: %r"); sysfatal("can't build namespace: %r");

View file

@ -338,12 +338,8 @@ scandir(char *proto, char *protodir, char *addr, char *dname)
void void
becomenone(void) becomenone(void)
{ {
int fd; if(procsetuser("none") < 0)
fd = open("#c/user", OWRITE);
if(fd < 0 || write(fd, "none", strlen("none")) < 0)
error("can't become none"); error("can't become none");
close(fd);
if(newns("none", namespace) < 0) if(newns("none", namespace) < 0)
error("can't build namespace"); error("can't build namespace");
} }

View file

@ -18,12 +18,8 @@ usage(void)
void void
becomenone(void) becomenone(void)
{ {
int fd; if(procsetuser("none") < 0)
fd = open("#c/user", OWRITE);
if(fd < 0 || write(fd, "none", strlen("none")) < 0)
sysfatal("can't become none: %r"); sysfatal("can't become none: %r");
close(fd);
if(newns("none", nsfile) < 0) if(newns("none", nsfile) < 0)
sysfatal("can't build namespace: %r"); sysfatal("can't build namespace: %r");
} }

View file

@ -129,16 +129,12 @@ main(int argc, char **argv)
static void static void
becomenone(char *namespace) becomenone(char *namespace)
{ {
int fd; if(procsetuser("none") < 0)
sysfatal("can't become none: %r");
fd = open("#c/user", OWRITE);
if(fd < 0 || write(fd, "none", strlen("none")) < 0)
sysfatal("can't become none");
close(fd);
if(newns("none", nil) < 0) if(newns("none", nil) < 0)
sysfatal("can't build normal namespace"); sysfatal("can't build normal namespace: %r");
if(addns("none", namespace) < 0) if(addns("none", namespace) < 0)
sysfatal("can't build httpd namespace"); sysfatal("can't build httpd namespace: %r");
} }
static HConnect* static HConnect*

View file

@ -83,8 +83,7 @@ main(int argc, char *argv[])
} }
if(asnone){ if(asnone){
rv = open("#c/user", OWRITE); if(procsetuser("none") < 0){
if(rv < 0 || write(rv, "none", 4) != 4){
if(qflag) if(qflag)
exits(0); exits(0);
fprint(2, "%s: can't become none: %r\n", argv0); fprint(2, "%s: can't become none: %r\n", argv0);

View file

@ -202,12 +202,11 @@ Mount:
exits(0); exits(0);
if(asnone){ if(asnone){
try = open("#c/user", OWRITE); if(procsetuser("none") < 0){
if(try < 0 || write(try, "none", 4) != 4){
fprint(2, "srv %s: can't become none: %r\n", dest); fprint(2, "srv %s: can't become none: %r\n", dest);
exits("becomenone"); exits("becomenone");
} }
try = 0; try = 0; /* no retry */
} }
if((!doauth && mount(fd, -1, mtpt, mountflag, "") == -1) if((!doauth && mount(fd, -1, mtpt, mountflag, "") == -1)

View file

@ -8,17 +8,13 @@
int int
become(char **, char *who) become(char **, char *who)
{ {
int fd;
if(strcmp(who, "none") == 0) { if(strcmp(who, "none") == 0) {
fd = open("#c/user", OWRITE); if(procsetuser("none") < 0) {
if(fd < 0 || write(fd, "none", strlen("none")) < 0) { werrstr("can't become none: %r");
werrstr("can't become none");
return -1; return -1;
} }
close(fd); if(newns("none", nil) < 0) {
if(newns("none", 0)) { werrstr("can't set new namespace: %r");
werrstr("can't set new namespace");
return -1; return -1;
} }
} }