]> diplodocus.org Git - nmh/commitdiff
Add a "file-nopermcheck" credential entry.
authorKen Hornstein <kenh@pobox.com>
Sun, 11 Sep 2016 04:41:18 +0000 (00:41 -0400)
committerKen Hornstein <kenh@pobox.com>
Sun, 11 Sep 2016 04:41:18 +0000 (00:41 -0400)
config/config.c
h/mh.h
man/mh-profile.man
sbr/credentials.c
sbr/ruserpass.c

index 28436d9..e1c4e5b 100644 (file)
@@ -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 3c493a1..d88df07 100644 (file)
--- 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;
index 8cb8526..9a873a0 100644 (file)
@@ -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"
index ff4ee84..9b5dd53 100644 (file)
@@ -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
index 7038cf5..7892cbf 100644 (file)
@@ -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. */