diff options
author | Matthias Andree <matthias.andree@gmx.de> | 2022-05-31 20:39:40 +0200 |
---|---|---|
committer | Matthias Andree <matthias.andree@gmx.de> | 2022-06-04 22:32:37 +0200 |
commit | c89909b0d4e3fc914045bc5bacf029699c1d2420 (patch) | |
tree | 2154702efff4a2a4c5418ae25ec4bd6e06a6f3a4 | |
parent | a6294bdb72c1a158cda906b611ad21d1198dad79 (diff) | |
download | fetchmail-c89909b0d4e3fc914045bc5bacf029699c1d2420.tar.gz fetchmail-c89909b0d4e3fc914045bc5bacf029699c1d2420.tar.bz2 fetchmail-c89909b0d4e3fc914045bc5bacf029699c1d2420.zip |
netrc: fix error routing and add I/O error checks
-rw-r--r-- | NEWS | 8 | ||||
-rw-r--r-- | netrc.c | 38 | ||||
-rw-r--r-- | netrc.h | 2 | ||||
-rw-r--r-- | po/de.po | 21 |
4 files changed, 51 insertions, 18 deletions
@@ -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: @@ -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 (¤t, &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); } @@ -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 @@ -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" |