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

This commit is contained in:
cinap_lenrek 2018-10-08 02:11:36 +02:00
parent c458216121
commit 065c3557af
3 changed files with 37 additions and 17 deletions

View file

@ -5,8 +5,10 @@ dhcpd, dhcp6d, dhcpleases, rarpd, tftpd \- Internet booting
.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 @@ dhcpd, dhcp6d, dhcpleases, rarpd, tftpd \- Internet booting
.B ip/dhcp6d
.RB [ -d ]
.RB [ -f
.IR ndb-file ]
.IR ndbfile ]
.RB [ -x
.IR netmtpt ]
.PP
@ -177,6 +179,18 @@ The options are:
.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 @@ The default is
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

View file

@ -49,9 +49,8 @@ struct Req
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 @@ timestamp(char *tag)
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 @@ main(int argc, char **argv)
case 'f':
ndbfile = EARGF(usage());
break;
case 'h':
homedir = EARGF(usage());
break;
case 'm':
mute = 1;
break;
@ -305,8 +307,8 @@ main(int argc, char **argv)
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 @@ bootp(Req *rp)
}
/* 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;
}

View file

@ -90,9 +90,9 @@ void doserve(int);
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 @@ main(int argc, char **argv)
dbg++;
break;
case 'h':
dir = EARGF(usage());
homedir = EARGF(usage());
break;
case 'r':
restricted = 1;
@ -142,9 +142,10 @@ main(int argc, char **argv)
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 @@ main(int argc, char **argv)
* "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)) {