changeset: 7078:915ba3928d49
user:      Kevin McCarthy <ke...@8t8.us>
date:      Tue Jun 06 18:38:41 2017 -0700
link:      http://dev.mutt.org/hg/mutt/rev/915ba3928d49

Restore setenv function.

Partially revert fa1192803257, restoring setenv.  It turns out we
still need the function.

changeset: 7079:02ff4277259e
user:      Kevin McCarthy <ke...@8t8.us>
date:      Tue Jun 06 18:38:46 2017 -0700
link:      http://dev.mutt.org/hg/mutt/rev/02ff4277259e

Move setting of GPG_TTY to mutt_init(). (see #3948)

This allows other programs mutt runs to use the ncurses pinentry if needed.

changeset: 7080:cf90bf5989f3
user:      Kevin McCarthy <ke...@8t8.us>
date:      Tue Jun 06 18:38:47 2017 -0700
link:      http://dev.mutt.org/hg/mutt/rev/cf90bf5989f3

Add a mutt_endwin() before invoking $sendmail. (closes #3948)

This is to support invoking a program such as msmtp that can use gpg
to decrypt a password.  The ncurses pinentry can corrupt the screen
unless we exit curses.

diffs (157 lines):

diff -r a11770c2137b -r cf90bf5989f3 configure.ac
--- a/configure.ac      Fri Jun 02 13:17:40 2017 -0700
+++ b/configure.ac      Tue Jun 06 18:38:47 2017 -0700
@@ -374,7 +374,7 @@
 
 AC_CHECK_FUNCS(fgetpos memmove setegid srand48 strerror)
 
-AC_REPLACE_FUNCS([strcasecmp strdup strsep strtok_r wcscasecmp])
+AC_REPLACE_FUNCS([setenv strcasecmp strdup strsep strtok_r wcscasecmp])
 AC_REPLACE_FUNCS([strcasestr mkdtemp])
 
 AC_CHECK_FUNC(getopt)
diff -r a11770c2137b -r cf90bf5989f3 init.c
--- a/init.c    Fri Jun 02 13:17:40 2017 -0700
+++ b/init.c    Tue Jun 06 18:38:47 2017 -0700
@@ -3317,6 +3317,7 @@
   char *domain = NULL;
   int i, need_pause = 0;
   BUFFER err;
+  char *tty;
 
   mutt_buffer_init (&err);
   err.dsize = STRING;
@@ -3510,6 +3511,20 @@
     unset_option (OPTSUSPEND);
 #endif
 
+  /* GPG_TTY is used by the ncurses pinentry program for GPG.  GPG is
+   * sometimes also used to decrypt passwords in programs launched by
+   * mutt, such as using msmtp as $sendmail, so we set it here as
+   * opposed to inside pgp.c
+   *
+   * We also call setenv() because send_msg() is not converted to use
+   * the mutt envlist.
+   */
+  if ((tty = ttyname(0)))
+  {
+    setenv("GPG_TTY", tty, 0);
+    mutt_envlist_set ("GPG_TTY", tty, 0);
+  }
+
   mutt_init_history ();
 
   /* RFC2368, "4. Unsafe headers"
diff -r a11770c2137b -r cf90bf5989f3 m4/gettext.m4
--- a/m4/gettext.m4     Fri Jun 02 13:17:40 2017 -0700
+++ b/m4/gettext.m4     Tue Jun 06 18:38:47 2017 -0700
@@ -318,7 +318,7 @@
    AC_CHECK_HEADERS([argz.h limits.h locale.h nl_types.h malloc.h stddef.h \
 stdlib.h string.h unistd.h sys/param.h])
    AC_CHECK_FUNCS([feof_unlocked fgets_unlocked getcwd getegid geteuid \
-getgid getuid mempcpy munmap putenv setlocale stpcpy strchr strcasecmp \
+getgid getuid mempcpy munmap putenv setenv setlocale stpcpy strchr strcasecmp \
 strdup strtoul tsearch __argz_count __argz_stringify __argz_next])
 
    MUTT_AM_ICONV
diff -r a11770c2137b -r cf90bf5989f3 pgp.c
--- a/pgp.c     Fri Jun 02 13:17:40 2017 -0700
+++ b/pgp.c     Tue Jun 06 18:38:47 2017 -0700
@@ -105,18 +105,13 @@
   mutt_message _("PGP passphrase forgotten.");
 }
 
+/* This function used to do more: check GPG_AGENT_INFO,
+ * set GPG_TTY.  GPG_AGENT_INFO is no longer exported, and GPG_TTY
+ * is now set in mutt_init().
+ */
 int pgp_use_gpg_agent (void)
 {
-  char *tty;
-
-  /* GnuPG 2.1 no longer exports GPG_AGENT_INFO */
-  if (!option (OPTUSEGPGAGENT))
-    return 0;
-
-  if ((tty = ttyname(0)))
-    mutt_envlist_set ("GPG_TTY", tty, 0);
-
-  return 1;
+  return option (OPTUSEGPGAGENT);
 }
 
 static pgp_key_t _pgp_parent(pgp_key_t k)
diff -r a11770c2137b -r cf90bf5989f3 protos.h
--- a/protos.h  Fri Jun 02 13:17:40 2017 -0700
+++ b/protos.h  Tue Jun 06 18:38:47 2017 -0700
@@ -543,6 +543,10 @@
 
 /* prototypes for compatibility functions */
 
+#ifndef HAVE_SETENV
+int setenv (const char *, const char *, int);
+#endif
+
 #ifndef HAVE_STRCASECMP
 int strcasecmp (char *, char *);
 int strncasecmp (char *, char *, size_t);
diff -r a11770c2137b -r cf90bf5989f3 sendlib.c
--- a/sendlib.c Fri Jun 02 13:17:40 2017 -0700
+++ b/sendlib.c Tue Jun 06 18:38:47 2017 -0700
@@ -2446,6 +2446,7 @@
 
   args[argslen++] = NULL;
 
+  mutt_endwin (NULL);
   if ((i = send_msg (path, args, msg, option(OPTNOCURSES) ? NULL : &childout)) 
!= (EX_OK & 0xff))
   {
     if (i != S_BKG)
diff -r a11770c2137b -r cf90bf5989f3 setenv.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/setenv.c  Tue Jun 06 18:38:47 2017 -0700
@@ -0,0 +1,45 @@
+/*  Replacement for a missing setenv.
+**
+**  Written by Russ Allbery <r...@stanford.edu>
+**  This work is hereby placed in the public domain by its author.
+**
+**  Provides the same functionality as the standard library routine setenv
+**  for those platforms that don't have it.
+*/
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+int
+setenv(const char *name, const char *value, int overwrite)
+{
+    char *envstring;
+
+    if (!overwrite && getenv(name) != NULL)
+        return 0;
+
+    /* Allocate memory for the environment string.  We intentionally don't
+       use concat here, or the xmalloc family of allocation routines, since
+       the intention is to provide a replacement for the standard library
+       function which sets errno and returns in the event of a memory
+       allocation failure. */
+    envstring = malloc(strlen(name) + 1 + strlen(value) + 1); /* 
__MEM_CHECKED__ */
+    if (envstring == NULL)
+        return -1;
+
+    /* Build the environment string and add it to the environment using
+       putenv.  Systems without putenv lose, but XPG4 requires it. */
+    strcpy(envstring, name);  /* __STRCPY_CHECKED__ */
+    strcat(envstring, "=");   /* __STRCAT_CHECKED__ */
+    strcat(envstring, value); /* __STRCAT_CHECKED__ */
+    return putenv(envstring);
+
+    /* Note that the memory allocated is not freed.  This is intentional;
+       many implementations of putenv assume that the string passed to
+       putenv will never be freed and don't make a copy of it.  Repeated use
+       of this function will therefore leak memory, since most
+       implementations of putenv also don't free strings removed from the
+       environment (due to being overwritten). */
+}

Reply via email to