From 41adecad14af8a4255bfd47a79b86b6834a1b5d6 Mon Sep 17 00:00:00 2001 From: Simon Kelley Date: Sat, 1 Jan 2022 22:15:16 +0000 Subject: [PATCH] Include client address if TFTP file-not-found errors. --- CHANGELOG | 4 ++++ po/de.po | 4 ++-- po/es.po | 4 ++-- po/fi.po | 2 +- po/fr.po | 4 ++-- po/id.po | 4 ++-- po/it.po | 2 +- po/no.po | 4 ++-- po/pl.po | 4 ++-- po/pt_BR.po | 2 +- po/ro.po | 4 ++-- src/tftp.c | 26 ++++++++++++-------------- 12 files changed, 33 insertions(+), 31 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 195a696..fc2cf5e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -27,6 +27,10 @@ version 2.87 over a pattern consisting of a decimal number which was interpreted 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 Handle DHCPREBIND requests in the DHCPv6 server code. diff --git a/po/de.po b/po/de.po index 9cd48ee..1f1c058 100644 --- a/po/de.po +++ b/po/de.po @@ -2145,8 +2145,8 @@ msgstr "nicht unterstützte Anfrage von %s" #: tftp.c:512 #, c-format -msgid "file %s not found" -msgstr "Datei %s nicht gefunden" +msgid "file %s not found for %s" +msgstr "Datei %s nicht gefunden für %s" #: tftp.c:602 #, c-format diff --git a/po/es.po b/po/es.po index 9bd61fc..d5defc9 100644 --- a/po/es.po +++ b/po/es.po @@ -2213,8 +2213,8 @@ msgstr "pedido no-soportado desde %s" #: tftp.c:512 #, fuzzy, c-format -msgid "file %s not found" -msgstr "archivo %s no encontrado" +msgid "file %s not found for %s" +msgstr "archivo %s no encontrado por %s" #: tftp.c:602 #, c-format diff --git a/po/fi.po b/po/fi.po index f414461..8439233 100644 --- a/po/fi.po +++ b/po/fi.po @@ -2114,7 +2114,7 @@ msgstr "" #: tftp.c:512 #, c-format -msgid "file %s not found" +msgid "file %s not found for %s" msgstr "" #: tftp.c:602 diff --git a/po/fr.po b/po/fr.po index a97dc2f..9512739 100644 --- a/po/fr.po +++ b/po/fr.po @@ -2197,8 +2197,8 @@ msgstr "requ #: tftp.c:512 #, c-format -msgid "file %s not found" -msgstr "fichier %s non trouvé" +msgid "file %s not found for %s" +msgstr "fichier %s non trouvé pour %s" #: tftp.c:602 #, c-format diff --git a/po/id.po b/po/id.po index 11aa042..9549205 100644 --- a/po/id.po +++ b/po/id.po @@ -2460,8 +2460,8 @@ msgstr "" # OK #: tftp.c:512 #, fuzzy, c-format -msgid "file %s not found" -msgstr "lease tak ditemukan" +msgid "file %s not found for %s" +msgstr "file %s tidak ditemukan untuk %s" #: tftp.c:602 #, c-format diff --git a/po/it.po b/po/it.po index 6ed0010..e9ab318 100644 --- a/po/it.po +++ b/po/it.po @@ -2114,7 +2114,7 @@ msgstr "" #: tftp.c:512 #, c-format -msgid "file %s not found" +msgid "file %s not found for %s" msgstr "" #: tftp.c:602 diff --git a/po/no.po b/po/no.po index 33e80b8..892f7cc 100644 --- a/po/no.po +++ b/po/no.po @@ -2194,8 +2194,8 @@ msgstr "" #: tftp.c:512 #, fuzzy, c-format -msgid "file %s not found" -msgstr "leie ikke funnet" +msgid "file %s not found for %s" +msgstr "fil %s ikke funnet for %s" #: tftp.c:602 #, c-format diff --git a/po/pl.po b/po/pl.po index 29b9165..c98ed5d 100644 --- a/po/pl.po +++ b/po/pl.po @@ -2149,8 +2149,8 @@ msgstr "nieobsÅ‚ugiwane żądanie od komputera %s" #: tftp.c:512 #, c-format -msgid "file %s not found" -msgstr "plik %s nie zostaÅ‚ znaleziony" +msgid "file %s not found for %s" +msgstr "plik %s nie zostaÅ‚ znaleziony dla %s" #: tftp.c:602 #, c-format diff --git a/po/pt_BR.po b/po/pt_BR.po index a07a9ce..e57bd24 100644 --- a/po/pt_BR.po +++ b/po/pt_BR.po @@ -2114,7 +2114,7 @@ msgstr "" #: tftp.c:512 #, c-format -msgid "file %s not found" +msgid "file %s not found for %s" msgstr "" #: tftp.c:602 diff --git a/po/ro.po b/po/ro.po index 295e629..075ed7e 100644 --- a/po/ro.po +++ b/po/ro.po @@ -2195,8 +2195,8 @@ msgstr "" #: tftp.c:512 #, fuzzy, c-format -msgid "file %s not found" -msgstr "împrumutul nu a fost găsit" +msgid "file %s not found for %s" +msgstr "fiÈ™ier %s nu a fost găsit pentru %s" #: tftp.c:602 #, c-format diff --git a/src/tftp.c b/src/tftp.c index 3d87523..e8474d9 100644 --- a/src/tftp.c +++ b/src/tftp.c @@ -19,9 +19,9 @@ #ifdef HAVE_TFTP 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 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 get_block(char *packet, struct tftp_transfer *transfer); static char *next(char **p, char *end); @@ -362,7 +362,7 @@ void tftp_request(struct listener *listen, time_t now) !(mode = next(&p, end)) || (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; } else @@ -472,7 +472,7 @@ void tftp_request(struct listener *listen, time_t now) strncat(daemon->namebuff, filename, (MAXDNAME-1) - strlen(daemon->namebuff)); /* 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) 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; struct tftp_file *file; @@ -509,7 +509,7 @@ static struct tftp_file *check_tftp_fileperm(ssize_t *len, char *prefix) { 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; } else if (errno == EACCES) @@ -562,8 +562,7 @@ static struct tftp_file *check_tftp_fileperm(ssize_t *len, char *prefix) return file; perm: - errno = EACCES; - *len = tftp_err(ERR_PERM, packet, _("cannot access %s: %s"), namebuff); + *len = tftp_err(ERR_PERM, packet, _("cannot access %s: %s"), namebuff, strerror(EACCES)); if (fd != -1) close(fd); return NULL; @@ -599,7 +598,7 @@ void check_tftp_listeners(time_t now) { /* Wrong source address. See rfc1350 para 4. */ 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)))); } } @@ -743,22 +742,21 @@ static void sanitise(char *buf) } #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 { unsigned short op, err; char message[]; } *mess = (struct errmess *)packet; ssize_t len, ret = 4; - char *errstr = strerror(errno); - + memset(packet, 0, daemon->packet_buff_sz); if (file) sanitise(file); mess->op = htons(OP_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 */ 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 */ if (file != daemon->namebuff) 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. */