923a60
From 1b7d1234cd22bb0fd2677d54dc670a6d2c6f8089 Mon Sep 17 00:00:00 2001
923a60
From: Lennart Poettering <lennart@poettering.net>
923a60
Date: Mon, 2 Mar 2015 20:24:11 +0100
923a60
Subject: [PATCH] import: add support for gpg2 for verifying imported images
923a60
923a60
gpg2 insists on created a trust db even if we tun off all trust db
923a60
support. Hence create a temporary home where the trust db is placed, and
923a60
remove it after use.
923a60
923a60
Cherry-picked from: 0acfdffe9417b4218e97b6d981c99a1a85e633c9
923a60
Resolves: #1284974
923a60
---
923a60
 src/import/import-common.c | 21 ++++++++++++++++++---
923a60
 1 file changed, 18 insertions(+), 3 deletions(-)
923a60
923a60
diff --git a/src/import/import-common.c b/src/import/import-common.c
923a60
index 2acf380f99..f10a453eed 100644
923a60
--- a/src/import/import-common.c
923a60
+++ b/src/import/import-common.c
923a60
@@ -281,8 +281,9 @@ int import_verify(
923a60
         _cleanup_free_ char *fn = NULL;
923a60
         _cleanup_close_ int sig_file = -1;
923a60
         const char *p, *line;
923a60
-        char sig_file_path[] = "/tmp/sigXXXXXX";
923a60
+        char sig_file_path[] = "/tmp/sigXXXXXX", gpg_home[] = "/tmp/gpghomeXXXXXX";
923a60
         _cleanup_sigkill_wait_ pid_t pid = 0;
923a60
+        bool gpg_home_created = false;
923a60
         int r;
923a60
 
923a60
         assert(main_job);
923a60
@@ -347,6 +348,13 @@ int import_verify(
923a60
                 goto finish;
923a60
         }
923a60
 
923a60
+        if (!mkdtemp(gpg_home)) {
923a60
+                r = log_error_errno(errno, "Failed to create tempory home for gpg: %m");
923a60
+                goto finish;
923a60
+        }
923a60
+
923a60
+        gpg_home_created = true;
923a60
+
923a60
         pid = fork();
923a60
         if (pid < 0)
923a60
                 return log_error_errno(errno, "Failed to fork off gpg: %m");
923a60
@@ -359,13 +367,14 @@ int import_verify(
923a60
                         "--no-auto-check-trustdb",
923a60
                         "--batch",
923a60
                         "--trust-model=always",
923a60
-                        NULL, /* keyring to use */
923a60
+                        NULL, /* --homedir=  */
923a60
+                        NULL, /* --keyring= */
923a60
                         NULL, /* --verify */
923a60
                         NULL, /* signature file */
923a60
                         NULL, /* dash */
923a60
                         NULL  /* trailing NULL */
923a60
                 };
923a60
-                unsigned k = ELEMENTSOF(cmd) - 5;
923a60
+                unsigned k = ELEMENTSOF(cmd) - 6;
923a60
                 int null_fd;
923a60
 
923a60
                 /* Child */
923a60
@@ -398,6 +407,8 @@ int import_verify(
923a60
                 if (null_fd != STDOUT_FILENO)
923a60
                         null_fd = safe_close(null_fd);
923a60
 
923a60
+                cmd[k++] = strjoina("--homedir=", gpg_home);
923a60
+
923a60
                 /* We add the user keyring only to the command line
923a60
                  * arguments, if it's around since gpg fails
923a60
                  * otherwise. */
923a60
@@ -415,6 +426,7 @@ int import_verify(
923a60
                 fd_cloexec(STDOUT_FILENO, false);
923a60
                 fd_cloexec(STDERR_FILENO, false);
923a60
 
923a60
+                execvp("gpg2", (char * const *) cmd);
923a60
                 execvp("gpg", (char * const *) cmd);
923a60
                 log_error_errno(errno, "Failed to execute gpg: %m");
923a60
                 _exit(EXIT_FAILURE);
923a60
@@ -446,6 +458,9 @@ finish:
923a60
         if (sig_file >= 0)
923a60
                 unlink(sig_file_path);
923a60
 
923a60
+        if (gpg_home_created)
923a60
+                rm_rf_dangerous(gpg_home, false, true, false);
923a60
+
923a60
         return r;
923a60
 }
923a60