diff options
-rw-r--r-- | Makefile.in | 5 | ||||
-rw-r--r-- | NEWS | 1 | ||||
-rw-r--r-- | fetchmail.c | 10 | ||||
-rw-r--r-- | netrc.c | 53 | ||||
-rw-r--r-- | netrc.h | 2 |
5 files changed, 33 insertions, 38 deletions
diff --git a/Makefile.in b/Makefile.in index 07e2fce4..f2b6887a 100644 --- a/Makefile.in +++ b/Makefile.in @@ -124,6 +124,11 @@ rfc822: rfc822.c unmime: unmime.c base64.c rfc822.c xmalloc.c error.c $(CC) -DSTANDALONE -DHAVE_CONFIG_H -I. -g -o $@ $^ + +# Stand-alone netrc tester +netrc: netrc.c xmalloc.o error.o + $(CC) -DSTANDALONE -DHAVE_CONFIG_H -I. -g -o $@ $^ + .c.o: $(CC) $(defines) -c $(CPFLAGS) -I$(srcdir) -I. $(CEFLAGS) $(CFLAGS) $< @@ -14,6 +14,7 @@ fetchmail-5.0.0 (): * Spanish-language update by Javier Kohen. * Danish summary and description for specgen.sh. * Henrik Storner's fix for the PGP/mimedecode problem. +* Fix netrc search code to be able to search >1 host entry per file. There are 267 people on fetchmail-friends and 365 on fetchmail-announce. diff --git a/fetchmail.c b/fetchmail.c index 685389fb..54e54405 100644 --- a/fetchmail.c +++ b/fetchmail.c @@ -428,9 +428,8 @@ int main (int argc, char **argv) netrc_entry *p; /* look up the pollname and account in the .netrc file. */ - p = search_netrc(netrc_list, ctl->server.pollname); - while (p && strcmp(p->account, ctl->remotename)) - p = search_netrc(p->next, ctl->remotename); + p = search_netrc(netrc_list, + ctl->server.pollname, ctl->remotename); /* if we find a matching entry with a password, use it */ if (p && p->password) ctl->password = xstrdup(p->password); @@ -438,9 +437,8 @@ int main (int argc, char **argv) /* otherwise try with "via" name if there is one */ else if (ctl->server.via) { - p = search_netrc(netrc_list, ctl->server.via); - while (p && strcmp(p->account, ctl->remotename)) - p = search_netrc(p->next, ctl->remotename); + p = search_netrc(netrc_list, + ctl->server.via, ctl->remotename); if (p && p->password) ctl->password = xstrdup(p->password); } @@ -23,6 +23,8 @@ /* Normally defined in xmalloc.c */ # define xmalloc malloc # define xrealloc realloc + +char *program_name = "netrc"; #endif /* Maybe add NEWENTRY to the account information list, LIST. NEWENTRY is @@ -289,9 +291,9 @@ parse_netrc (file) /* Return the netrc entry from LIST corresponding to HOST. NULL is returned if no such entry exists. */ netrc_entry * -search_netrc (list, host) +search_netrc (list, host, account) netrc_entry *list; - char *host; + char *host, *account; { /* Look for the HOST in LIST. */ while (list) @@ -300,9 +302,10 @@ search_netrc (list, host) /* We hit the default entry. */ break; - else if (!strcmp (list->host, host)) - /* We found a matching entry. */ - break; + else if (!strcmp(list->host, host)) + if (!list->account || !strcmp(list->account, account)) + /* We found a matching entry. */ + break; list = list->next; } @@ -324,18 +327,13 @@ main (argc, argv) char **argv; { struct stat sb; - char *program_name, *file, *target; + char *program_name, *file, *host, *account; netrc_entry *head, *a; - if (argc < 2) - { - fprintf (stderr, "Usage: %s NETRC [HOSTNAME]...\n", argv[0]); - exit (1); - } - program_name = argv[0]; file = argv[1]; - target = argv[2]; + host = argv[2]; + account = argv[3]; if (stat (file, &sb)) { @@ -351,32 +349,25 @@ main (argc, argv) exit (1); } - if (argc > 2) + if (host && account) { int i, status; status = 0; - for (i = 2; i < argc; i++) - { - /* Print out the host that we are checking for. */ - fputs (argv[i], stdout); - a = search_netrc (head, argv[i]); - if (a) + printf("Host: %s, Account: %s\n", host, account); + + a = search_netrc (head, host, account); + if (a) + { + /* Print out the password (if any). */ + if (a->password) { - /* Print out the account and password (if any). */ fputc (' ', stdout); - fputs (a->account, stdout); - if (a->password) - { - fputc (' ', stdout); - fputs (a->password, stdout); - } + fputs (a->password, stdout); } - else - status = 1; - - fputc ('\n', stdout); } + fputc ('\n', stdout); + exit (status); } @@ -59,7 +59,7 @@ netrc_entry *parse_netrc __P((char *file)); /* Return the netrc entry from LIST corresponding to HOST. NULL is returned if no such entry exists. */ -netrc_entry *search_netrc __P((netrc_entry *list, char *host)); +netrc_entry *search_netrc __P((netrc_entry *list, char *host, char *account)); __END_DECLS #endif /* _NETRC_H_ */ |