Add two new flags: -w, which allows new files to be created,
and -U, which allows the umask to be set. Obtained from: Patton Electronics, Co.
This commit is contained in:
parent
991d64ece8
commit
eff7787706
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=129680
@ -40,9 +40,10 @@
|
||||
.Nd Internet Trivial File Transfer Protocol server
|
||||
.Sh SYNOPSIS
|
||||
.Nm /usr/libexec/tftpd
|
||||
.Op Fl cCln
|
||||
.Op Fl cClnw
|
||||
.Op Fl s Ar directory
|
||||
.Op Fl u Ar user
|
||||
.Op Fl U Ar umask
|
||||
.Op Ar directory ...
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
@ -163,6 +164,14 @@ when the
|
||||
.Fl s
|
||||
option is used.
|
||||
The user must be specified by name, not a numeric UID.
|
||||
.It Fl U Ar umask
|
||||
Set the
|
||||
.Ar umask
|
||||
for newly created files. The default is 022 (S_IWGRP|S_IWOTH).
|
||||
.It Fl w
|
||||
Allow writes requests to create new files. By default
|
||||
.Nm
|
||||
requires that the file specified in a write request exist.
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr tftp 1 ,
|
||||
|
@ -109,6 +109,8 @@ static struct dirlist {
|
||||
static int suppress_naks;
|
||||
static int logging;
|
||||
static int ipchroot;
|
||||
static int create_new = 0;
|
||||
static mode_t mask = S_IWGRP|S_IWOTH;
|
||||
|
||||
static const char *errtomsg(int);
|
||||
static void nak(int);
|
||||
@ -130,7 +132,7 @@ main(int argc, char *argv[])
|
||||
const char *chuser = "nobody";
|
||||
|
||||
openlog("tftpd", LOG_PID | LOG_NDELAY, LOG_FTP);
|
||||
while ((ch = getopt(argc, argv, "cClns:u:")) != -1) {
|
||||
while ((ch = getopt(argc, argv, "cClns:u:Uw")) != -1) {
|
||||
switch (ch) {
|
||||
case 'c':
|
||||
ipchroot = 1;
|
||||
@ -150,6 +152,12 @@ main(int argc, char *argv[])
|
||||
case 'u':
|
||||
chuser = optarg;
|
||||
break;
|
||||
case 'U':
|
||||
mask = strtol(optarg, NULL, 0);
|
||||
break;
|
||||
case 'w':
|
||||
create_new = 1;
|
||||
break;
|
||||
default:
|
||||
syslog(LOG_WARNING, "ignoring unknown option -%c", ch);
|
||||
}
|
||||
@ -176,6 +184,8 @@ main(int argc, char *argv[])
|
||||
exit(1);
|
||||
}
|
||||
|
||||
umask(mask);
|
||||
|
||||
on = 1;
|
||||
if (ioctl(0, FIONBIO, &on) < 0) {
|
||||
syslog(LOG_ERR, "ioctl(FIONBIO): %m");
|
||||
@ -553,9 +563,10 @@ validate_access(char **filep, int mode)
|
||||
err = EACCESS;
|
||||
}
|
||||
}
|
||||
if (dirp->name == NULL)
|
||||
if (dirp->name != NULL)
|
||||
*filep = filename = pathname;
|
||||
else if (mode == RRQ)
|
||||
return (err);
|
||||
*filep = filename = pathname;
|
||||
}
|
||||
if (options[OPT_TSIZE].o_request) {
|
||||
if (mode == RRQ)
|
||||
@ -565,7 +576,14 @@ validate_access(char **filep, int mode)
|
||||
options[OPT_TSIZE].o_reply =
|
||||
atoi(options[OPT_TSIZE].o_request);
|
||||
}
|
||||
fd = open(filename, mode == RRQ ? O_RDONLY : O_WRONLY|O_TRUNC);
|
||||
if (mode == RRQ)
|
||||
fd = open(filename, O_RDONLY);
|
||||
else {
|
||||
if (create_new)
|
||||
fd = open(filename, O_WRONLY|O_TRUNC|O_CREAT, 0666);
|
||||
else
|
||||
fd = open(filename, O_WRONLY|O_TRUNC);
|
||||
}
|
||||
if (fd < 0)
|
||||
return (errno + 100);
|
||||
file = fdopen(fd, (mode == RRQ)? "r":"w");
|
||||
|
Loading…
Reference in New Issue
Block a user