shithub: riscv

Download patch

ref: 065c3557af8de1b20d94c2e86a4a29c5d33ccc67
parent: c458216121d622858916387071cd9c13df31820a
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun Oct 7 22:11:36 EDT 2018

ip/dhcpd, ip/tftpd: change default for tftp homedir to /

--- a/sys/man/8/dhcpd
+++ b/sys/man/8/dhcpd
@@ -5,8 +5,10 @@
 .PP
 .B ip/dhcpd
 .RB [ -dmnprsSZ ]
+.RB [ -h
+.IR homedir ]
 .RB [ -f
-.IR ndb-file ]
+.IR ndbfile ]
 .RB [ -M
 .IR secs ]
 .RB [ -x
@@ -23,7 +25,7 @@
 .B ip/dhcp6d
 .RB [ -d ]
 .RB [ -f
-.IR ndb-file ]
+.IR ndbfile ]
 .RB [ -x
 .IR netmtpt ]
 .PP
@@ -177,6 +179,18 @@
 .B d
 Print debugging to standard output.
 .TP
+.B h
+Change directory to
+.IR homedir .
+The default is
+.BR / .
+This should match the
+.I homedir
+setting of
+.I tftpd
+so that the existence check of non-rooted file names
+is consistent.
+.TP
 .B f
 Specify a file other than
 .B /lib/ndb/local
@@ -277,9 +291,12 @@
 Change directory to
 .IR homedir .
 The default is
-.BR /lib/tftpd .
+.BR / .
 All requests for files with non-rooted file names are served starting at this
-directory.
+directory. This needs to be consistent with the
+.I homedir
+setting of
+.IR dhcpd .
 .I Tftpd
 supports only octet mode.
 .TP
--- a/sys/src/cmd/ip/dhcpd/dhcpd.c
+++ b/sys/src/cmd/ip/dhcpd/dhcpd.c
@@ -49,9 +49,8 @@
 	uchar buf[2*1024];		/* message buffer */
 };
 
-#define TFTP "/lib/tftpd"
-
 char	*blog = "ipboot";
+char	*homedir = "/";
 char	*mysysname;
 Ipifc	*ipifcs;
 int	debug;
@@ -209,7 +208,7 @@
 void
 usage(void)
 {
-	fprint(2, "usage: dhcp [-dmnprsSZ] [-f directory] [-M minlease] "
+	fprint(2, "usage: dhcp [-dmnprsSZ] [-h homedir] [-f ndbfile] [-M minlease] "
 		"[-x netmtpt] [-Z staticlease] addr n [addr n] ...\n");
 	exits("usage");
 }
@@ -239,6 +238,9 @@
 	case 'f':
 		ndbfile = EARGF(usage());
 		break;
+	case 'h':
+		homedir = EARGF(usage());
+		break;
 	case 'm':
 		mute = 1;
 		break;
@@ -305,8 +307,8 @@
 		exits(0);
 	}
 
-	if (chdir(TFTP) < 0)
-		warning("can't change directory to %s: %r", TFTP);
+	if (chdir(homedir) < 0)
+		warning("can't change to directory %s: %r", homedir);
 	fd = openlisten(net);
 
 	for(;;){
@@ -956,7 +958,7 @@
 	}
 
 	/* ignore if the file is unreadable */
-	if((!rp->genrequest) && bp->file[0] && access(bp->file, 4) < 0){
+	if(!rp->genrequest && bp->file[0] && access(bp->file, 4) < 0){
 		warning("inaccessible bootfile1 %s", bp->file);
 		return;
 	}
--- a/sys/src/cmd/ip/tftpd.c
+++ b/sys/src/cmd/ip/tftpd.c
@@ -90,9 +90,9 @@
 char	bigbuf[32768];
 char	raddr[64];
 
-char	*dir = "/lib/tftpd";
 char	*dirsl;
 int	dirsllen;
+char	*homedir = "/";
 char	flog[] = "ipboot";
 char	net[Maxpath];
 
@@ -127,7 +127,7 @@
 		dbg++;
 		break;
 	case 'h':
-		dir = EARGF(usage());
+		homedir = EARGF(usage());
 		break;
 	case 'r':
 		restricted = 1;
@@ -142,9 +142,10 @@
 		usage();
 	}ARGEND
 
-	snprint(buf, sizeof buf, "%s/", dir);
-	dirsl = strdup(buf);
-	dirsllen = strlen(dirsl);
+	dirsllen = strlen(homedir);
+	while(dirsllen > 0 && homedir[dirsllen-1] == '/')
+		dirsllen--;
+	dirsl = smprint("%.*s/", dirsllen, homedir);
 
 	fmtinstall('E', eipfmt);
 	fmtinstall('I', eipfmt);
@@ -154,8 +155,8 @@
 	 * "cd /usr/$user", so call setuser before chdir.
 	 */
 	setuser();
-	if(chdir(dir) < 0)
-		sysfatal("can't get to directory %s: %r", dir);
+	if(chdir(homedir) < 0)
+		sysfatal("can't get to directory %s: %r", homedir);
 
 	if(!dbg)
 		switch(rfork(RFNOTEG|RFPROC|RFFDG)) {