summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2024-07-31 09:55:28 +0200
committerWerner Koch <wk@gnupg.org>2024-07-31 10:25:48 +0200
commita4eefb271f40807c0d1eb30267f826cd5fb253e6 (patch)
treea908fa9835042eb7925a19ee1840a846b88a5077 /tools
parentdoc: Clarify gpgv man page synopsis. (diff)
downloadgnupg2-a4eefb271f40807c0d1eb30267f826cd5fb253e6.tar.xz
gnupg2-a4eefb271f40807c0d1eb30267f826cd5fb253e6.zip
gpg-mail-tube: Make sure GNUPGHOME is set in vsd mode.
* tools/gpg-mail-tube.c (main): Set GNUPGGHOME. (start_gpg_encrypt): Improve the "statrt gpg" diagnostic. (prepare_for_appimage): Start with cleared GNUPGHOME.
Diffstat (limited to 'tools')
-rw-r--r--tools/gpg-mail-tube.c51
1 files changed, 46 insertions, 5 deletions
diff --git a/tools/gpg-mail-tube.c b/tools/gpg-mail-tube.c
index e7ca57c1c..201989f1c 100644
--- a/tools/gpg-mail-tube.c
+++ b/tools/gpg-mail-tube.c
@@ -245,6 +245,7 @@ main (int argc, char **argv)
enum cmd_and_opt_values cmd;
strlist_t recipients = NULL;
int i;
+ const char *s;
gnupg_reopen_std ("gpg-mail-tube");
gpgrt_set_strusage (my_strusage);
@@ -314,14 +315,31 @@ main (int argc, char **argv)
}
}
- /* The remaining argumenst are the recipients - put them into a list. */
+ /* The remaining arguments are the recipients - put them into a list. */
/* TODO: Check that these are all valid mail addresses so that gpg
* will consider them as such. */
for (i=0; i < argc; i++)
add_to_strlist (&recipients, argv[i]);
if (opt.vsd)
- prepare_for_appimage ();
+ {
+ prepare_for_appimage ();
+
+ /* In VSD mode we set GNUPGHOME unless it has already been set.
+ * This is the same what the AppImage shell does. This has to
+ * be done after the appimage has been started because otherwise
+ * the AppImage won't write the run-gpgconf script. */
+ if (!(s=getenv ("GNUPGHOME")) || !*s)
+ {
+ char *tmpstr, *estr;
+
+ tmpstr = make_filename ("~/.gnupg-vsd", NULL);
+ estr = xstrconcat ("GNUPGHOME=", tmpstr, NULL);
+ xfree (tmpstr);
+ gpgrt_annotate_leaked_object (estr);
+ putenv (estr);
+ }
+ }
if (log_get_errorcount (0))
exit (2);
@@ -687,8 +705,24 @@ prepare_for_appimage (void)
{
/* Run the sleep program for 2^30 seconds (34 years). */
static const char *args[4] = { "-c", "sleep", "1073741824", NULL };
+ static char *save_gpghome;
+ static int gpghome_saved;
gpgrt_spawn_actions_t act;
+ /* Reset the GNUPGHOME so that the AppRun shell can do the Right
+ * Thing; i.e. creating a ~/.gnupg-vsd/run-gpgconf script. */
+ if (!gpghome_saved)
+ {
+ if ((save_gpghome = getenv ("GNUPGHOME")) && *save_gpghome)
+ {
+ save_gpghome = xstrconcat ("GNUPGHOME=", save_gpghome, NULL);
+ gpgrt_annotate_leaked_object (save_gpghome);
+ putenv ("GNUPGHOME=");
+ }
+ gpghome_saved = 1;
+ }
+
+ /* Note that we need to use that fixed GNUPGHOME. */
fname = make_filename ("~/.gnupg-vsd/gnupg-vs-desktop.AppImage", NULL);
err = gpgrt_spawn_actions_new (&act);
@@ -710,6 +744,8 @@ prepare_for_appimage (void)
log_info ("waiting until the AppImage has started ...\n");
gnupg_sleep (1);
}
+ if (gpgbin && gpghome_saved && save_gpghome && *save_gpghome)
+ putenv (save_gpghome);
if (opt.verbose && gpgbin)
log_info ("using AppImage gpg binary '%s'\n", gpgbin);
}
@@ -743,15 +779,20 @@ start_gpg_encrypt (estream_t *r_input, gpgrt_process_t *r_proc,
const char **argv;
gpgrt_spawn_actions_t act = NULL;
char *logfilebuf = NULL;
+ const char *s;
*r_input = NULL;
*r_proc = NULL;
es_fflush (es_stdout);
if (opt.verbose)
- log_info ("starting gpg as %u:%u with HOME=%s\n",
- (unsigned int)getuid (), (unsigned int)getgid (),
- getenv ("HOME"));
+ {
+ if (!(s = getenv ("GNUPGHOME")))
+ s = "";
+ log_info ("starting gpg as %u:%u with %s%s\n",
+ (unsigned int)getuid (), (unsigned int)getgid (),
+ *s? "GNUPGHOME=":"HOME=", *s? s : getenv ("HOME"));
+ }
ccparray_init (&ccp, 0);
ccparray_put (&ccp, "--batch");
if (opt.logfile)