Include client address if TFTP file-not-found errors.

This commit is contained in:
Simon Kelley
2022-01-01 22:15:16 +00:00
parent ea5d8c56a0
commit 41adecad14
12 changed files with 33 additions and 31 deletions

View File

@@ -27,6 +27,10 @@ version 2.87
over a pattern consisting of a decimal number which was interpreted over a pattern consisting of a decimal number which was interpreted
surprisingly. surprisingly.
Include client address in TFTP file-not-found error reports.
Thanks to Stefan Rink for the initial patch, which has been
re-worked by me (srk). All bugs mine.
version 2.86 version 2.86
Handle DHCPREBIND requests in the DHCPv6 server code. Handle DHCPREBIND requests in the DHCPv6 server code.

View File

@@ -2145,8 +2145,8 @@ msgstr "nicht unterstützte Anfrage von %s"
#: tftp.c:512 #: tftp.c:512
#, c-format #, c-format
msgid "file %s not found" msgid "file %s not found for %s"
msgstr "Datei %s nicht gefunden" msgstr "Datei %s nicht gefunden für %s"
#: tftp.c:602 #: tftp.c:602
#, c-format #, c-format

View File

@@ -2213,8 +2213,8 @@ msgstr "pedido no-soportado desde %s"
#: tftp.c:512 #: tftp.c:512
#, fuzzy, c-format #, fuzzy, c-format
msgid "file %s not found" msgid "file %s not found for %s"
msgstr "archivo %s no encontrado" msgstr "archivo %s no encontrado por %s"
#: tftp.c:602 #: tftp.c:602
#, c-format #, c-format

View File

@@ -2114,7 +2114,7 @@ msgstr ""
#: tftp.c:512 #: tftp.c:512
#, c-format #, c-format
msgid "file %s not found" msgid "file %s not found for %s"
msgstr "" msgstr ""
#: tftp.c:602 #: tftp.c:602

View File

@@ -2197,8 +2197,8 @@ msgstr "requ
#: tftp.c:512 #: tftp.c:512
#, c-format #, c-format
msgid "file %s not found" msgid "file %s not found for %s"
msgstr "fichier %s non trouv<75>" msgstr "fichier %s non trouv<75> pour %s"
#: tftp.c:602 #: tftp.c:602
#, c-format #, c-format

View File

@@ -2460,8 +2460,8 @@ msgstr ""
# OK # OK
#: tftp.c:512 #: tftp.c:512
#, fuzzy, c-format #, fuzzy, c-format
msgid "file %s not found" msgid "file %s not found for %s"
msgstr "lease tak ditemukan" msgstr "file %s tidak ditemukan untuk %s"
#: tftp.c:602 #: tftp.c:602
#, c-format #, c-format

View File

@@ -2114,7 +2114,7 @@ msgstr ""
#: tftp.c:512 #: tftp.c:512
#, c-format #, c-format
msgid "file %s not found" msgid "file %s not found for %s"
msgstr "" msgstr ""
#: tftp.c:602 #: tftp.c:602

View File

@@ -2194,8 +2194,8 @@ msgstr ""
#: tftp.c:512 #: tftp.c:512
#, fuzzy, c-format #, fuzzy, c-format
msgid "file %s not found" msgid "file %s not found for %s"
msgstr "leie ikke funnet" msgstr "fil %s ikke funnet for %s"
#: tftp.c:602 #: tftp.c:602
#, c-format #, c-format

View File

@@ -2149,8 +2149,8 @@ msgstr "nieobsługiwane żądanie od komputera %s"
#: tftp.c:512 #: tftp.c:512
#, c-format #, c-format
msgid "file %s not found" msgid "file %s not found for %s"
msgstr "plik %s nie został znaleziony" msgstr "plik %s nie został znaleziony dla %s"
#: tftp.c:602 #: tftp.c:602
#, c-format #, c-format

View File

@@ -2114,7 +2114,7 @@ msgstr ""
#: tftp.c:512 #: tftp.c:512
#, c-format #, c-format
msgid "file %s not found" msgid "file %s not found for %s"
msgstr "" msgstr ""
#: tftp.c:602 #: tftp.c:602

View File

@@ -2195,8 +2195,8 @@ msgstr ""
#: tftp.c:512 #: tftp.c:512
#, fuzzy, c-format #, fuzzy, c-format
msgid "file %s not found" msgid "file %s not found for %s"
msgstr "împrumutul nu a fost găsit" msgstr "fișier %s nu a fost găsit pentru %s"
#: tftp.c:602 #: tftp.c:602
#, c-format #, c-format

View File

@@ -19,9 +19,9 @@
#ifdef HAVE_TFTP #ifdef HAVE_TFTP
static void handle_tftp(time_t now, struct tftp_transfer *transfer, ssize_t len); static void handle_tftp(time_t now, struct tftp_transfer *transfer, ssize_t len);
static struct tftp_file *check_tftp_fileperm(ssize_t *len, char *prefix); static struct tftp_file *check_tftp_fileperm(ssize_t *len, char *prefix, char *client);
static void free_transfer(struct tftp_transfer *transfer); static void free_transfer(struct tftp_transfer *transfer);
static ssize_t tftp_err(int err, char *packet, char *message, char *file); static ssize_t tftp_err(int err, char *packet, char *message, char *file, char *arg2);
static ssize_t tftp_err_oops(char *packet, const char *file); static ssize_t tftp_err_oops(char *packet, const char *file);
static ssize_t get_block(char *packet, struct tftp_transfer *transfer); static ssize_t get_block(char *packet, struct tftp_transfer *transfer);
static char *next(char **p, char *end); static char *next(char **p, char *end);
@@ -362,7 +362,7 @@ void tftp_request(struct listener *listen, time_t now)
!(mode = next(&p, end)) || !(mode = next(&p, end)) ||
(strcasecmp(mode, "octet") != 0 && strcasecmp(mode, "netascii") != 0)) (strcasecmp(mode, "octet") != 0 && strcasecmp(mode, "netascii") != 0))
{ {
len = tftp_err(ERR_ILL, packet, _("unsupported request from %s"), daemon->addrbuff); len = tftp_err(ERR_ILL, packet, _("unsupported request from %s"), daemon->addrbuff, NULL);
is_err = 1; is_err = 1;
} }
else else
@@ -472,7 +472,7 @@ void tftp_request(struct listener *listen, time_t now)
strncat(daemon->namebuff, filename, (MAXDNAME-1) - strlen(daemon->namebuff)); strncat(daemon->namebuff, filename, (MAXDNAME-1) - strlen(daemon->namebuff));
/* check permissions and open file */ /* check permissions and open file */
if ((transfer->file = check_tftp_fileperm(&len, prefix))) if ((transfer->file = check_tftp_fileperm(&len, prefix, daemon->addrbuff)))
{ {
if ((len = get_block(packet, transfer)) == -1) if ((len = get_block(packet, transfer)) == -1)
len = tftp_err_oops(packet, daemon->namebuff); len = tftp_err_oops(packet, daemon->namebuff);
@@ -492,7 +492,7 @@ void tftp_request(struct listener *listen, time_t now)
} }
} }
static struct tftp_file *check_tftp_fileperm(ssize_t *len, char *prefix) static struct tftp_file *check_tftp_fileperm(ssize_t *len, char *prefix, char *client)
{ {
char *packet = daemon->packet, *namebuff = daemon->namebuff; char *packet = daemon->packet, *namebuff = daemon->namebuff;
struct tftp_file *file; struct tftp_file *file;
@@ -509,7 +509,7 @@ static struct tftp_file *check_tftp_fileperm(ssize_t *len, char *prefix)
{ {
if (errno == ENOENT) if (errno == ENOENT)
{ {
*len = tftp_err(ERR_FNF, packet, _("file %s not found"), namebuff); *len = tftp_err(ERR_FNF, packet, _("file %s not found for %s"), namebuff, client);
return NULL; return NULL;
} }
else if (errno == EACCES) else if (errno == EACCES)
@@ -562,8 +562,7 @@ static struct tftp_file *check_tftp_fileperm(ssize_t *len, char *prefix)
return file; return file;
perm: perm:
errno = EACCES; *len = tftp_err(ERR_PERM, packet, _("cannot access %s: %s"), namebuff, strerror(EACCES));
*len = tftp_err(ERR_PERM, packet, _("cannot access %s: %s"), namebuff);
if (fd != -1) if (fd != -1)
close(fd); close(fd);
return NULL; return NULL;
@@ -599,7 +598,7 @@ void check_tftp_listeners(time_t now)
{ {
/* Wrong source address. See rfc1350 para 4. */ /* Wrong source address. See rfc1350 para 4. */
prettyprint_addr(&peer, daemon->addrbuff); prettyprint_addr(&peer, daemon->addrbuff);
len = tftp_err(ERR_TID, daemon->packet, _("ignoring packet from %s (TID mismatch)"), daemon->addrbuff); len = tftp_err(ERR_TID, daemon->packet, _("ignoring packet from %s (TID mismatch)"), daemon->addrbuff, NULL);
while(retry_send(sendto(transfer->sockfd, daemon->packet, len, 0, &peer.sa, sa_len(&peer)))); while(retry_send(sendto(transfer->sockfd, daemon->packet, len, 0, &peer.sa, sa_len(&peer))));
} }
} }
@@ -743,14 +742,13 @@ static void sanitise(char *buf)
} }
#define MAXMESSAGE 500 /* limit to make packet < 512 bytes and definitely smaller than buffer */ #define MAXMESSAGE 500 /* limit to make packet < 512 bytes and definitely smaller than buffer */
static ssize_t tftp_err(int err, char *packet, char *message, char *file) static ssize_t tftp_err(int err, char *packet, char *message, char *file, char *arg2)
{ {
struct errmess { struct errmess {
unsigned short op, err; unsigned short op, err;
char message[]; char message[];
} *mess = (struct errmess *)packet; } *mess = (struct errmess *)packet;
ssize_t len, ret = 4; ssize_t len, ret = 4;
char *errstr = strerror(errno);
memset(packet, 0, daemon->packet_buff_sz); memset(packet, 0, daemon->packet_buff_sz);
if (file) if (file)
@@ -758,7 +756,7 @@ static ssize_t tftp_err(int err, char *packet, char *message, char *file)
mess->op = htons(OP_ERR); mess->op = htons(OP_ERR);
mess->err = htons(err); mess->err = htons(err);
len = snprintf(mess->message, MAXMESSAGE, message, file, errstr); len = snprintf(mess->message, MAXMESSAGE, message, file, arg2);
ret += (len < MAXMESSAGE) ? len + 1 : MAXMESSAGE; /* include terminating zero */ ret += (len < MAXMESSAGE) ? len + 1 : MAXMESSAGE; /* include terminating zero */
if (err != ERR_FNF || !option_bool(OPT_QUIET_TFTP)) if (err != ERR_FNF || !option_bool(OPT_QUIET_TFTP))
@@ -772,7 +770,7 @@ static ssize_t tftp_err_oops(char *packet, const char *file)
/* May have >1 refs to file, so potentially mangle a copy of the name */ /* May have >1 refs to file, so potentially mangle a copy of the name */
if (file != daemon->namebuff) if (file != daemon->namebuff)
strcpy(daemon->namebuff, file); strcpy(daemon->namebuff, file);
return tftp_err(ERR_NOTDEF, packet, _("cannot read %s: %s"), daemon->namebuff); return tftp_err(ERR_NOTDEF, packet, _("cannot read %s: %s"), daemon->namebuff, strerror(errno));
} }
/* return -1 for error, zero for done. */ /* return -1 for error, zero for done. */