]> diplodocus.org Git - nmh/commitdiff
Fixed inc(1) and %(me) to not obey Local-Mailbox profile component.
authorDavid Levine <levinedl@acm.org>
Sun, 9 Jun 2019 14:58:11 +0000 (10:58 -0400)
committerDavid Levine <levinedl@acm.org>
Sun, 9 Jun 2019 14:58:11 +0000 (10:58 -0400)
Thanks to Martin McCormick for reporting and Ken for diagnosing.

12 files changed:
docs/pending-release-notes
h/mts.h
sbr/addrsbr.c
sbr/credentials.c
sbr/fmt_compile.c
sbr/mts.c
test/format/test-mymbox
uip/mhparse.c
uip/msgchk.c
uip/rcvtty.c
uip/sendsbr.c
uip/slocal.c

index 7167be06a30556f579fc68bf262f3caa603ae256..3db7924dab1f75c27b1a4fead548bc532176d937 100644 (file)
@@ -35,3 +35,5 @@ BUG FIXES
 
 - An -attendee switch has been added to mhical(1), for use when more than one
   (or zero) attendees match a user's mailbox.
+- Fixed inc(1) and %(me) function escape to not obey Local-Mailbox profile
+  component.
diff --git a/h/mts.h b/h/mts.h
index d0fa4f05c575567681b8117832d8319f4f1caad7..1e3b9c8393710071df137854ba0cfe1106708cb9 100644 (file)
--- a/h/mts.h
+++ b/h/mts.h
@@ -17,9 +17,9 @@ extern char *uucplfil;
 extern char *spoollocking;
 
 #define        MAILDIR (mmdfldir && *mmdfldir ? mmdfldir : getenv ("HOME"))
-#define        MAILFIL (mmdflfil && *mmdflfil ? mmdflfil : getusername ())
+#define        MAILFIL (mmdflfil && *mmdflfil ? mmdflfil : getusername (1))
 
-char *getusername(void);
+char *getusername(int);
 char *getfullname(void);
 char *getlocalmbox(void);
 
index b752797657b76253772f6edcfaee0c1c86a1d4d9..af8ecd4d00f4c40acb55bc721b5cde072f62db7b 100644 (file)
@@ -293,7 +293,7 @@ ismymbox (struct mailname *np)
      */
     if (am == NULL) {
        mq.m_next = NULL;
-       mq.m_mbox = getusername ();
+       mq.m_mbox = getusername (0);
 
        if ((am = context_find ("local-mailbox"))) {
 
@@ -316,7 +316,7 @@ ismymbox (struct mailname *np)
        }
 
        if ((am = context_find ("alternate-mailboxes")) == NULL)
-           am = getusername();
+           am = getusername(0);
        else {
            mp = mq.m_next ? mq.m_next : &mq;
            oops = false;
index 910e097dd34d9b9d5df253b06f47249742adcf34..21ffe6c94a0e1ba241b75a3d4898b01363adac0c 100644 (file)
@@ -75,7 +75,7 @@ nmh_get_credentials (const char *host, const char *user)
     creds->pass = NULL;
 
     if (cred_style == NULL  ||  ! strcmp (cred_style, "legacy")) {
-       creds->user = user == NULL  ?  mh_xstrdup(getusername ())  :  mh_xstrdup(user);
+       creds->user = user == NULL  ?  mh_xstrdup(getusername (1))  :  mh_xstrdup(user);
     } else if (! strncasecmp (cred_style, "file:", 5) ||
               ! strncasecmp (cred_style, "file-nopermcheck:", 17)) {
         /*
index e34dd4df0f07cd3ad993b83b3351ad63a8c8f69d..925a06342012c2d281c82c9786708b3c645fd930 100644 (file)
@@ -663,7 +663,7 @@ do_func(char *sp)
        break;
 
     case TF_MYBOX:
-       LS(t->f_type, getusername());
+       LS(t->f_type, getusername(1));
        break;
 
     case TF_MYNAME:
index c453e1d85f2ab40e743f1ba0445a10785c840cab..b7e6571aec18b89e5c541ae852cc36744b527be2 100644 (file)
--- a/sbr/mts.c
+++ b/sbr/mts.c
@@ -51,9 +51,12 @@ char *uucplfil = "";
 
 char *spoollocking = DEFAULT_LOCKING;
 
-/* Cache the username, fullname, and mailbox of the user */
+/* Cache the username, fullname, mailbox name, and mailbox of the user */
 static char username[BUFSIZ];
 static char fullname[BUFSIZ];
+/* mboxname comes from a Local-Mailbox profile component, or if that
+   doesn't exist, the username. */
+static char mboxname[BUFSIZ];
 static char localmbox[2*BUFSIZ+3];
 
 /*
@@ -180,11 +183,11 @@ tailor_value (char *s)
 
                case 0: s--;
                    /* FALLTHRU */
-               case QUOTE: 
+               case QUOTE:
                    *bp = QUOTE;
                    break;
 
-               default: 
+               default:
                    if (!isdigit ((unsigned char) *s)) {
                        *bp++ = QUOTE;
                        *bp = *s;
@@ -291,15 +294,19 @@ SystemName (void)
 
 /*
  * Get the username of current user
+ *
+ * If flag is 0, then attempt to extract username from Local-Mailbox profile
+ *   component, if present.
+ * If flag is 1, then only use the "proper" local hostname.
  */
 
 char *
-getusername (void)
+getusername (int flag)
 {
     if (username[0] == '\0')
        getuserinfo();
 
-    return username;
+    return flag == 0 ? mboxname : username;
 }
 
 
@@ -334,7 +341,7 @@ getlocalmbox (void)
 }
 
 /*
- * Find the user's username and full name, and cache them.
+ * Find and cache the user's username, full name, and local mbox.
  */
 
 static void
@@ -352,8 +359,13 @@ getuserinfo (void)
        return;
     }
 
-
     /* username */
+    if (username[0] == '\0') {
+       strncpy (username, pw->pw_name, sizeof(username));
+    }
+    username[sizeof(username) - 1] = '\0';
+
+    /* localmbox and mboxname */
     /* If there's a Local-Mailbox profile component, try to extract
        the username from it.  But don't try very hard, this assumes
        the very simple User Name <user@name.com> form.
@@ -369,20 +381,20 @@ getuserinfo (void)
        if (left_angle_bracket  &&  at_sign  &&  right_angle_bracket) {
            if (at_sign > left_angle_bracket  &&
                at_sign - left_angle_bracket < BUFSIZ) {
-               strncpy(username, left_angle_bracket + 1,
+               strncpy(mboxname, left_angle_bracket + 1,
                        at_sign - left_angle_bracket - 1);
            }
        }
+    } else {
+       snprintf(localmbox, sizeof(localmbox), "%s <%s@%s>", fullname,
+                username, LocalName(0));
     }
-
-    if (username[0] == '\0') {
-       strncpy (username, pw->pw_name, sizeof(username));
+    localmbox[sizeof(localmbox) - 1] = '\0';
+    if (mboxname[0] == '\0') {
+       strncpy (mboxname, username, sizeof(mboxname));
     }
-
-    username[sizeof(username) - 1] = '\0';
-
-    escape_local_part(username, sizeof(username));
-
+    mboxname[sizeof(mboxname) - 1] = '\0';
+    escape_local_part(mboxname, sizeof(mboxname));
 
     /* fullname */
     np = pw->pw_gecos;
@@ -403,19 +415,8 @@ getuserinfo (void)
        strncpy (fullname, cp, sizeof(fullname));
     else if ((cp = context_find("Signature")))
        strncpy (fullname, cp, sizeof(fullname));
-
     fullname[sizeof(fullname) - 1] = '\0';
-
     escape_display_name(fullname, sizeof(fullname));
-
-
-    /* localmbox, if not using Local-Mailbox */
-    if (localmbox[0] == '\0') {
-       snprintf(localmbox, sizeof(localmbox), "%s <%s@%s>", fullname,
-                username, LocalName(0));
-    }
-
-    localmbox[sizeof(localmbox) - 1] = '\0';
 }
 
 static const char*
index a8f21dcbeb7477dbfe66e7607cbaf4cb8e0b118a..6185e38855965b508dac48decd1a4b668a92d5cd 100755 (executable)
@@ -13,11 +13,11 @@ fi
 
 setup_test
 
-#### Use ap to get the username.  That will either be what's in the
-#### Local-Mailbox profile component, which we don't use in the test
-#### suite, or the user's login name.  ap will escape (quote) it if
-#### needed.
-user=`run_prog ${MH_LIBEXEC_DIR}/ap -format '%(me)' 0`
+#### Remove existing Local-Mailbox: profile component, if any.
+grep -v 'Local-Mailbox: ' "$MH" > "$MH".new
+mv -f "$MH".new "$MH"
+
+user=`id -nu`
 set +e
 host=`${MH_OBJ_DIR}/test/getcanon`
 set -e
@@ -31,10 +31,7 @@ run_test "${MH_LIBEXEC_DIR}/ap -format %(mymbox{text}) nosuchuser@nosuchhost.bla
 
 myname="Random User <random@user.something.com>"
 
-#### Remove existing Local-Mailbox: profile component, if any.  Then
-#### add one.
-grep -v 'Local-Mailbox: ' "$MH" > "$MH".new
-mv -f "$MH".new "$MH"
+#### Add Local-Mailbox profile component.
 echo "Local-Mailbox: ${myname}" >> "$MH"
 
 run_test "echo \
@@ -42,7 +39,10 @@ run_test "echo \
          1 "Local-Mailbox test"
 
 output=`run_prog ${MH_LIBEXEC_DIR}/ap -format '%(mymbox{text})' "${user}@${host}"`
-run_test "echo $output" 0 "Local-mailbox overriding user@host test"
+run_test "echo $output" 0 "Local-Mailbox overriding user@host test"
+
+#### Test getusername() when there is a Local-Mailbox profile component.
+run_test 'fmttest -raw -format %(me) ""' "${user}"
 
 # Add an Alternate-Mailbox.  This caused ismymbox() to lose the
 # Local-Mailbox, Bug #36635: -nocc me doesn't account for
index 4d5c0499e15d0b23496d593a4eff6ac4c62c0eb7..cb9d2799e781949cc2ca6ce91fd93b0af3a67fee 100644 (file)
@@ -2374,7 +2374,7 @@ openFTP (CT ct, char **file)
 
     if (e->eb_flags) {
        user = "anonymous";
-       snprintf (buffer, sizeof(buffer), "%s@%s", getusername (),
+       snprintf (buffer, sizeof(buffer), "%s@%s", getusername (1),
                  LocalName (1));
        pass = buffer;
     } else {
index 82541ec5beeaf0203a8d19096d7002ec02e309ad..5ab5b76015c115ad3923a8295a9468ec0b4e4425 100644 (file)
@@ -254,7 +254,7 @@ main (int argc, char **argv)
                                      snoop, sasl, saslmech, tlsflag, auth_svc);
        }
     } else {
-       if (user == NULL) user = getusername ();
+       if (user == NULL) user = getusername (1);
        if (vecp == 0) {
            char *home;
 
index c66f3996b5f8db4a9dd7deadc1a11c5b9afcb263..3563ae5fe70e1e5e8e1b87720e959622b093fbdc 100644 (file)
@@ -151,9 +151,9 @@ main (int argc, char **argv)
     if ((md = vecp ? message_fd (vec) : header_fd ()) == NOTOK)
        exit(1);
 
-    user = getusername();
-
 #if HAVE_GETUTXENT
+    user = getusername(1);
+
     setutxent();
     while ((utp = getutxent()) != NULL) {
         if (utp->ut_type == USER_PROCESS && utp->ut_user[0] != 0
index 1fe8d97f0998749da75965afc0cb379756b4f78e..c7d788fdc490da8daaca9d9301fafe4d3077d0ec 100644 (file)
@@ -337,7 +337,7 @@ alert (char *file, int out)
 
            arglist = argsplit(mailproc, &program, &argp);
 
-           arglist[argp++] = getusername();
+           arglist[argp++] = getusername(1);
            arglist[argp++] = "-subject";
            arglist[argp++] = buf;
            arglist[argp] = NULL;
index f744c9e9ca2be75d243ee6458f2d805e54684e89..c86f2ceea80ba91a632c6ecc0c313a858523a824 100644 (file)
@@ -285,9 +285,9 @@ main (int argc, char **argv)
     }
 
     if (addr == NULL)
-       addr = getusername ();
+       addr = getusername (1);
     if (user == NULL) {
-       user = getusername ();
+       user = getusername (1);
     }
     if ((pw = getpwnam (user)) == NULL)
        die("no such local user as %s", user);