From: Ken Hornstein Date: Sun, 11 Sep 2016 04:41:18 +0000 (-0400) Subject: Add a "file-nopermcheck" credential entry. X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/cdce53212b7310f834773ed65fce9a72b8c089cc Add a "file-nopermcheck" credential entry. --- diff --git a/config/config.c b/config/config.c index 28436d93..e1c4e5b8 100644 --- a/config/config.c +++ b/config/config.c @@ -106,6 +106,9 @@ char *mh_profile = ".mh_profile"; /* name of credentials file, defaults to .netrc in either Path or $HOME. */ char *credentials_file; +/* if set to 1, do not check permissions on credentials file */ +int credentials_no_perm_check = 0; + /* name of current message "sequence" */ char *current = "cur"; diff --git a/h/mh.h b/h/mh.h index 3c493a1d..d88df07f 100644 --- a/h/mh.h +++ b/h/mh.h @@ -449,6 +449,7 @@ extern char *components; extern char *context; extern char *current; extern char *credentials_file; +extern int credentials_no_perm_check; extern char *defaultfolder; extern char *digestcomps; extern char *distcomps; diff --git a/man/mh-profile.man b/man/mh-profile.man index 8cb85260..9a873a05 100644 --- a/man/mh-profile.man +++ b/man/mh-profile.man @@ -377,8 +377,10 @@ supersedes all of this. (profile, no default) .RS 5 Indicates how the username and password credentials will be retrieved for access to external servers, such as those that provide SMTP or POP -service. The supported entry values are \*(lqlegacy\*(rq and -.RI \*(lqfile: netrc \*(rq. +service. The supported entry values are \*(lqlegacy\*(rq, +.RI \*(lqfile: netrc \*(rq, +and +.RI \*(lqfile\-nopermcheck: netrc \*(rq. With \*(lqlegacy\*(rq, or if there is no credentials entry, the username is the first of: .RS 5 @@ -466,6 +468,14 @@ with your own account information: This .I netrc file must be owned and readable only by you. +.PP +The +.RI \*(lqfile\-nopermcheck: netrc \*(rq +.B credentials +entry is identical in behavior to the \*(lqfile\*(rq entry, with the +exception that the permission checks done by +\*(lqfile\*(rq are not performed. This entry should be used with +caution and only when absolutely necessary. (profile, default: legacy) .RE .SS "Process Profile Entries" diff --git a/sbr/credentials.c b/sbr/credentials.c index ff4ee84e..9b5dd537 100644 --- a/sbr/credentials.c +++ b/sbr/credentials.c @@ -17,9 +17,10 @@ init_credentials_file () { char *hdir = getenv ("HOME"); credentials_file = concat (hdir ? hdir : ".", "/.netrc", NULL); - } else if (! strncasecmp (cred_style, "file:", 5)) { + } else if (! strncasecmp (cred_style, "file:", 5) || + ! strncasecmp (cred_style, "file-nopermcheck:", 17)) { struct stat st; - char *filename = cred_style + 5; + char *filename = strchr(cred_style, ':') + 1; while (*filename && isspace ((unsigned char) *filename)) ++filename; @@ -36,6 +37,9 @@ init_credentials_file () { } } } + + if (! strncasecmp (cred_style, "file-nopermcheck:", 17)) + credentials_no_perm_check = 1; } } } @@ -55,7 +59,8 @@ nmh_get_credentials (char *host, char *user, int sasl, nmh_creds_t creds) { /* Only inc.c and msgchk.c do this. smtp.c doesn't. */ creds->password = getusername (); } - } else if (! strncasecmp (cred_style, "file:", 5)) { + } else if (! strncasecmp (cred_style, "file:", 5) || + ! strncasecmp (cred_style, "file-nopermcheck:", 17)) { /* * Determine user using the first of: * 1) -user switch diff --git a/sbr/ruserpass.c b/sbr/ruserpass.c index 7038cf5c..7892cbfd 100644 --- a/sbr/ruserpass.c +++ b/sbr/ruserpass.c @@ -102,7 +102,8 @@ ruserpass(char *host, char **aname, char **apass) break; case PASSWD: - if (fstat(fileno(cfile), &stb) >= 0 && + if (!credentials_no_perm_check && + fstat(fileno(cfile), &stb) >= 0 && (stb.st_mode & 077) != 0) { /* We make this a fatal error to force the user to correct it. */