aboutsummaryrefslogtreecommitdiffstats
path: root/fetchmail.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>1997-01-07 03:03:00 +0000
committerEric S. Raymond <esr@thyrsus.com>1997-01-07 03:03:00 +0000
commit08d9413c8e440aa38d7cee33dc035b2a2cd232c8 (patch)
tree4e7233d99a8993d0ffb5b67c823b89c3f6ba3493 /fetchmail.c
parent6c847c7569654682cc3d14e4a14d3afbf207f63c (diff)
downloadfetchmail-08d9413c8e440aa38d7cee33dc035b2a2cd232c8.tar.gz
fetchmail-08d9413c8e440aa38d7cee33dc035b2a2cd232c8.tar.bz2
fetchmail-08d9413c8e440aa38d7cee33dc035b2a2cd232c8.zip
Add netrc parsing.
svn path=/trunk/; revision=715
Diffstat (limited to 'fetchmail.c')
-rw-r--r--fetchmail.c37
1 files changed, 31 insertions, 6 deletions
diff --git a/fetchmail.c b/fetchmail.c
index 37ceb0d8..e21b7b65 100644
--- a/fetchmail.c
+++ b/fetchmail.c
@@ -37,6 +37,7 @@
#include "tunable.h"
#include "smtp.h"
#include "getopt.h"
+#include "netrc.h"
#define DROPDEAD 6 /* maximum bad socket opens */
@@ -94,6 +95,8 @@ int main (int argc, char **argv)
struct passwd *pw;
struct query *ctl;
FILE *lockfp;
+ netrc_entry *netrc_list;
+ char *netrc_file;
pid_t pid;
if ((program_name = strrchr(argv[0], '/')) != NULL)
@@ -291,22 +294,44 @@ int main (int argc, char **argv)
}
}
+ /* parse the ~/.netrc file, for future password lookups. */
+ netrc_file = (char *) xmalloc (strlen (home) + 8);
+ strcpy (netrc_file, home);
+ strcat (netrc_file, "/.netrc");
+
+ netrc_list = parse_netrc (netrc_file);
+
/* pick up interactively any passwords we need but don't have */
for (ctl = querylist; ctl; ctl = ctl->next)
if (ctl->active && !(implicitmode && ctl->skip) && !ctl->password[0])
{
if (ctl->authenticate == A_KERBEROS)
- /* Server won't care what the password is, but there
- must be some non-null string here. */
- (void) strncpy(ctl->password,
- ctl->remotename, PASSWORDLEN-1);
+ /* Server won't care what the password is, but there
+ must be some non-null string here. */
+ (void) strncpy(ctl->password,
+ ctl->remotename, PASSWORDLEN-1);
else
- {
+ {
+ /* Look up the host and account in the .netrc file. */
+ netrc_entry *p = search_netrc(netrc_list,ctl->servernames->id);
+ while (p && strcmp (p->account, ctl->remotename))
+ p = search_netrc (p->next, ctl->remotename);
+
+ if (p)
+ {
+ /* We found the entry, so use the password. */
+ (void) strncpy (ctl->password, p->password,
+ PASSWORDLEN - 1);
+ }
+ }
+
+ if (!ctl->password[0])
+ {
(void) sprintf(tmpbuf, "Enter password for %s@%s: ",
ctl->remotename, ctl->servernames->id);
(void) strncpy(ctl->password,
(char *)getpassword(tmpbuf),PASSWORDLEN-1);
- }
+ }
}
/*