aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Andree <matthias.andree@gmx.de>2022-05-31 20:39:40 +0200
committerMatthias Andree <matthias.andree@gmx.de>2022-06-04 22:32:37 +0200
commitc89909b0d4e3fc914045bc5bacf029699c1d2420 (patch)
tree2154702efff4a2a4c5418ae25ec4bd6e06a6f3a4
parenta6294bdb72c1a158cda906b611ad21d1198dad79 (diff)
downloadfetchmail-c89909b0d4e3fc914045bc5bacf029699c1d2420.tar.gz
fetchmail-c89909b0d4e3fc914045bc5bacf029699c1d2420.tar.bz2
fetchmail-c89909b0d4e3fc914045bc5bacf029699c1d2420.zip
netrc: fix error routing and add I/O error checks
-rw-r--r--NEWS8
-rw-r--r--netrc.c38
-rw-r--r--netrc.h2
-rw-r--r--po/de.po21
4 files changed, 51 insertions, 18 deletions
diff --git a/NEWS b/NEWS
index 817aa5b0..0c49e6e1 100644
--- a/NEWS
+++ b/NEWS
@@ -93,6 +93,14 @@ removed from a 6.5.0 or newer release.)
translations had been sent out already.
--------------------------------------------------------------------------------
+fetchmail-6.4.31 (not yet release):
+
+# BUG FIXES:
+* The netrc parser now reports its errors to syslog or logfile when appropriate,
+ previously it would always log to stderr.
+* Add error checking to .netrc parser.
+
+--------------------------------------------------------------------------------
fetchmail-6.4.30 (released 2022-04-26, 31666 LoC):
# BREAKING CHANGES:
diff --git a/netrc.c b/netrc.c
index 661da361..dadcae2f 100644
--- a/netrc.c
+++ b/netrc.c
@@ -17,6 +17,7 @@
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
+#include <errno.h>
#include "netrc.h"
#include "i18n.h"
@@ -84,6 +85,7 @@ parse_netrc (char *file)
const char *premature_token;
netrc_entry *current, *retval;
int ln;
+ int error_flag = 0;
/* The latest token we've seen in the file. */
enum
@@ -97,6 +99,9 @@ parse_netrc (char *file)
if (!fp)
{
/* Just return NULL if we can't open the file. */
+ if (ENOENT != errno) {
+ report(stderr, "%s: cannot open file for reading: %s\n", file, strerror(errno));
+ }
return NULL;
}
@@ -216,7 +221,7 @@ parse_netrc (char *file)
if (premature_token)
{
- fprintf (stderr,
+ report(stderr,
GT_("%s:%d: warning: found \"%s\" before any host names\n"),
file, ln, premature_token);
premature_token = NULL;
@@ -255,19 +260,33 @@ parse_netrc (char *file)
else
{
- fprintf (stderr, GT_("%s:%d: warning: unknown token \"%s\"\n"),
+ report(stderr, GT_("%s:%d: warning: unknown token \"%s\"\n"),
file, ln, tok);
}
}
}
}
- fclose (fp);
+ if (ferror(fp)) {
+ report(stderr, GT_("%s: error reading file (%s).\n"), file, strerror(errno));
+ error_flag = 1;
+ clearerr(fp);
+ }
+
+ if (fclose(fp)) {
+ report(stderr, GT_("%s: error reading file (%s).\n"), file, strerror(errno));
+ error_flag = 1;
+ }
/* Finalize the last machine entry we found. */
maybe_add_to_list (&current, &retval);
free (current);
+ if (error_flag) {
+ free_netrc(retval);
+ return NULL;
+ }
+
/* Reverse the order of the list so that it appears in file order. */
current = retval;
retval = NULL;
@@ -345,21 +364,22 @@ int main (int argc, char **argv)
case 4:
break;
default:
- fprintf (stderr, "Usage: %s <file> [<host> <login>]\n", argv[0]);
+ fprintf(stderr, "Usage: %s <file> [<host> <login>]\n", argv[0]);
exit(EXIT_FAILURE);
}
- if (stat (file, &sb))
+ report_init(1);
+
+ if (stat(file, &sb))
{
- fprintf (stderr, "%s: cannot stat %s: %s\n", argv[0], file,
+ fprintf(stderr, "PRE-CHECK for %s: cannot stat %s: %s\n", argv[0], file,
strerror (errno));
- exit (1);
}
- head = parse_netrc (file);
+ head = parse_netrc(file);
if (!head)
{
- fprintf (stderr, "%s: no entries found in %s\n", argv[0], file);
+ fprintf(stderr, "%s: read error or no entries found in %s\n", argv[0], file);
exit (1);
}
diff --git a/netrc.h b/netrc.h
index c69316a8..5342c783 100644
--- a/netrc.h
+++ b/netrc.h
@@ -40,7 +40,7 @@ typedef struct _netrc_entry {
__BEGIN_DECLS
/* Parse FILE as a .netrc file (as described in ftp(1)), and return a
list of entries. NULL is returned if the file could not be
- parsed. */
+ parsed. Diagnostic messages are through report(), except for fopen() errors with ENOENT. */
netrc_entry *parse_netrc __P((char *file));
/* Return the netrc entry from LIST corresponding to HOST. NULL is
diff --git a/po/de.po b/po/de.po
index f4b0347e..44a3289d 100644
--- a/po/de.po
+++ b/po/de.po
@@ -8,8 +8,8 @@ msgid ""
msgstr ""
"Project-Id-Version: fetchmail 6.4.25\n"
"Report-Msgid-Bugs-To: fetchmail-devel@lists.sourceforge.net\n"
-"POT-Creation-Date: 2022-04-23 10:08+0200\n"
-"PO-Revision-Date: 2021-11-21 00:30+0100\n"
+"POT-Creation-Date: 2022-05-31 20:42+0200\n"
+"PO-Revision-Date: 2022-05-31 20:43+0200\n"
"Last-Translator: Matthias Andree <matthias.andree@gmx.de>\n"
"Language-Team: German <kde-i18n-de@kde.org>\n"
"Language: de\n"
@@ -205,8 +205,8 @@ msgstr "fetchmail beobachtet wiederholte Zeitüberschreitungen"
#: driver.c:931
#, c-format
msgid ""
-"Fetchmail saw more than %d timeouts while attempting to get mail from %s@"
-"%s.\n"
+"Fetchmail saw more than %d timeouts while attempting to get mail from "
+"%s@%s.\n"
msgstr ""
"Fetchmail hat mehr als %d Zeitüberschreitungen erlitten beim Versuch, Mail "
"von %s@%s abzuholen.\n"
@@ -1022,8 +1022,8 @@ msgstr "Warnung: Server %s mehrmals in der Konfigurationsdatei vorhanden\n"
#: fetchmail.c:1203
msgid ""
-"fetchmail: Error: multiple \"defaults\" records in config file, or \"defaults"
-"\" is not the first record.\n"
+"fetchmail: Error: multiple \"defaults\" records in config file, or "
+"\"defaults\" is not the first record.\n"
msgstr ""
"fetchmail: Fehler: mehrere „defaults”-Einträge in Konfigurationsdatei, oder "
"„defaults” ist nicht der erste Eintrag.\n"
@@ -2243,16 +2243,21 @@ msgstr "fetchmail: Lock-Herstellung fehlgeschlagen, pidfile \"%s\": %s\n"
msgid "fetchmail: cannot remove or truncate pidfile \"%s\": %s\n"
msgstr "fetchmail: kann Lockdatei „%s” weder entfernen noch löschen: %s\n"
-#: netrc.c:220
+#: netrc.c:225
#, c-format
msgid "%s:%d: warning: found \"%s\" before any host names\n"
msgstr "%s:%d: Warnung: fand „%s“ vor irgendwelchen Hostnamen\n"
-#: netrc.c:258
+#: netrc.c:263
#, c-format
msgid "%s:%d: warning: unknown token \"%s\"\n"
msgstr "%s:%d: Warnung: unbekanntes Token „%s“\n"
+#: netrc.c:271 netrc.c:277
+#, c-format
+msgid "%s: error reading file (%s).\n"
+msgstr "%s: Fehler beim Lesen der Datei (%s).\n"
+
#: ntlmsubr.c:35
msgid "Warning: received malformed challenge to \"AUTH(ENTICATE) NTLM\"!\n"
msgstr "Warnung: Unpassende Challenge für \"AUTH(ENTICATE) NTLM\" empfangen!\n"