9front - general discussion about 9front
 help / color / mirror / Atom feed
* [9front] git: use new /dev/drivers for privdrop
@ 2022-05-28 16:51 ori
  2022-05-28 19:23 ` unobe
  2022-05-28 21:47 ` covertusername967
  0 siblings, 2 replies; 9+ messages in thread
From: ori @ 2022-05-28 16:51 UTC (permalink / raw)
  To: 9front

This needs to be held off for a bit, but it seems
like a good idea: we shouldn't need any devices at
all for this code, so let's not keep them.

ddiff 01a6de812c2fd38c9a28036300e3c2c7dc8441f5 uncommitted
--- a/sys/src/cmd/git/serve.c
+++ b/sys/src/cmd/git/serve.c
@@ -5,7 +5,7 @@
 
 #include "git.h"
 
-char	*pathpfx = nil;
+char	*pathpfx = "/";
 int	allowwrite;
 
 int
@@ -469,6 +469,22 @@
 	return 0;
 }
 
+void
+privdrop(void)
+{
+	int fd;
+
+	if(rfork(RFNAMEG) == -1)
+		sysfatal("rfork: %r");
+	if((fd = open("#c/drivers", OWRITE)) == -1)
+		sysfatal("open drivers: %r");
+	if(bind(pathpfx, "/", MREPL) == -1)
+		sysfatal("bind: %r");
+	if(write(fd, "chdev &", strlen("chdev &")) == -1)
+		sysfatal("drop permissions: %r");
+	close(fd);
+}
+
 char*
 parsecmd(char *buf, char *cmd, int ncmd)
 {
@@ -518,15 +534,8 @@
 	}ARGEND;
 
 	gitinit();
+	privdrop();
 	interactive = 0;
-	if(rfork(RFNAMEG) == -1)
-		sysfatal("rfork: %r");
-	if(pathpfx != nil){
-		if(bind(pathpfx, "/", MREPL) == -1)
-			sysfatal("bind: %r");
-	}
-	if(rfork(RFNOMNT) == -1)
-		sysfatal("rfork: %r");
 
 	initconn(&c, 0, 1);
 	if(readpkt(&c, buf, sizeof(buf)) == -1)


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-05-29  1:03 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-28 16:51 [9front] git: use new /dev/drivers for privdrop ori
2022-05-28 19:23 ` unobe
2022-05-28 19:41   ` ori
2022-05-28 22:54     ` Jacob Moody
2022-05-29  0:23       ` Frank D. Engel, Jr.
2022-05-29  1:00         ` Jacob Moody
2022-05-28 21:47 ` covertusername967
2022-05-28 22:07   ` ori
2022-05-28 23:24     ` adr

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).