From: David Levine Date: Sun, 9 Jun 2019 14:58:11 +0000 (-0400) Subject: Fixed inc(1) and %(me) to not obey Local-Mailbox profile component. X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/ddf3a8574f65?ds=inline;hp=e00dc84d4ef84f1b939c8090d49729b41377421d Fixed inc(1) and %(me) to not obey Local-Mailbox profile component. Thanks to Martin McCormick for reporting and Ken for diagnosing. --- diff --git a/docs/pending-release-notes b/docs/pending-release-notes index 7167be06..3db7924d 100644 --- a/docs/pending-release-notes +++ b/docs/pending-release-notes @@ -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 d0fa4f05..1e3b9c83 100644 --- 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); diff --git a/sbr/addrsbr.c b/sbr/addrsbr.c index b7527976..af8ecd4d 100644 --- a/sbr/addrsbr.c +++ b/sbr/addrsbr.c @@ -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; diff --git a/sbr/credentials.c b/sbr/credentials.c index 910e097d..21ffe6c9 100644 --- a/sbr/credentials.c +++ b/sbr/credentials.c @@ -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)) { /* diff --git a/sbr/fmt_compile.c b/sbr/fmt_compile.c index e34dd4df..925a0634 100644 --- a/sbr/fmt_compile.c +++ b/sbr/fmt_compile.c @@ -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: diff --git a/sbr/mts.c b/sbr/mts.c index c453e1d8..b7e6571a 100644 --- 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 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* diff --git a/test/format/test-mymbox b/test/format/test-mymbox index a8f21dcb..6185e388 100755 --- a/test/format/test-mymbox +++ b/test/format/test-mymbox @@ -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 " -#### 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 diff --git a/uip/mhparse.c b/uip/mhparse.c index 4d5c0499..cb9d2799 100644 --- a/uip/mhparse.c +++ b/uip/mhparse.c @@ -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 { diff --git a/uip/msgchk.c b/uip/msgchk.c index 82541ec5..5ab5b760 100644 --- a/uip/msgchk.c +++ b/uip/msgchk.c @@ -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; diff --git a/uip/rcvtty.c b/uip/rcvtty.c index c66f3996..3563ae5f 100644 --- a/uip/rcvtty.c +++ b/uip/rcvtty.c @@ -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 diff --git a/uip/sendsbr.c b/uip/sendsbr.c index 1fe8d97f..c7d788fd 100644 --- a/uip/sendsbr.c +++ b/uip/sendsbr.c @@ -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; diff --git a/uip/slocal.c b/uip/slocal.c index f744c9e9..c86f2cee 100644 --- a/uip/slocal.c +++ b/uip/slocal.c @@ -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);