[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[msmtp-users] Patch: retrieve password from /etc/netrc?
msmtp already has the capacity to read passwords from a ~/.netrc file.
However, I'd prefer to keep the password in /etc/netrc, because I have a number
of system-level daemons and cron jobs emailing me. They won't know what
user to get the password from. I propose the following patch against
msmtp 1.4.16, which tells msmtp to check for a /etc/netrc file if it
can't find one at ~/.netrc.
--- msmtp-1.4.16.orig/src/msmtp.c 2008-06-02 20:02:26.000000000 -0400
+++ msmtp-1.4.16.new/src/msmtp.c 2008-08-23 14:19:31.000000000 -0400
@@ -90,6 +90,7 @@
#define USERCONFFILE ".msmtprc"
#define NETRCFILE ".netrc"
#endif
+#define SYSNETRCFILE "netrc"
/* The name of this program */
const char *prgname;
@@ -283,6 +284,7 @@
char *msmtp_password_callback(const char *hostname, const char *user)
{
char *homedir;
+ char *sysconfdir;
char *netrc_filename;
netrc_entry *netrc_hostlist;
netrc_entry *netrc_host;
@@ -308,10 +310,24 @@
}
free_netrc_entry_list(netrc_hostlist);
}
+ if (!password)
+ {
+ sysconfdir = get_sysconfdir();
+ netrc_filename = get_filename(sysconfdir, SYSNETRCFILE);
+ free(sysconfdir);
+ if ((netrc_hostlist = parse_netrc(netrc_filename)))
+ {
+ if ((netrc_host = search_netrc(netrc_hostlist, hostname, user)))
+ {
+ password = xstrdup(netrc_host->password);
+ }
+ free_netrc_entry_list(netrc_hostlist);
+ }
+ }
free(netrc_filename);
#ifdef HAVE_KEYCHAIN
- if (SecKeychainFindInternetPassword(
+ if (!password && SecKeychainFindInternetPassword(
NULL,
strlen(hostname), hostname,
0, NULL,
--
Jim Pryor
jim@...173...