code: plan9front

Download patch

ref: eb1dfed9abb054e4708fcb13ac6d8d537914ac77
parent: fc5070c60057b6e02490e83f5d675786e8b8d83c
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;
 		}
 	}