From: Michael Tremer Date: Fri, 30 Jul 2021 15:07:59 +0000 (+0000) Subject: keystore: Create a temporary GnuPG database X-Git-Tag: 0.9.28~1011 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2c1cca091eb501b8cf7783fcca1b7b98fae81783;p=pakfire.git keystore: Create a temporary GnuPG database Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/keystore.c b/src/libpakfire/keystore.c index 3667d4385..e49e55bd0 100644 --- a/src/libpakfire/keystore.c +++ b/src/libpakfire/keystore.c @@ -52,7 +52,8 @@ static int pakfire_init_gpgme(struct pakfire* pakfire) { } int pakfire_keystore_init(struct pakfire* pakfire, gpgme_ctx_t* ctx) { - char path[PATH_MAX]; + char path[PATH_MAX] = PAKFIRE_CACHE_PATH "/tmp/pakfire-keystore.XXXXXX"; + char* tmp = NULL; // Initialise GPGME int r = pakfire_init_gpgme(pakfire); @@ -70,20 +71,13 @@ int pakfire_keystore_init(struct pakfire* pakfire, gpgme_ctx_t* ctx) { // Set output to be ASCII armoured gpgme_set_armor(*ctx, 1); - // Set home - r = pakfire_make_path(pakfire, path, "/etc/pakfire/gnupg"); - if (r < 0) + // Create a temporary directory + tmp = pakfire_mkdtemp(path); + if (!tmp) goto ERROR; DEBUG(pakfire, "Using PGP database at %s\n", path); - // Create home - r = pakfire_mkdir(path, S_IRUSR|S_IWUSR|S_IXUSR); - if (r && errno != EEXIST) { - ERROR(pakfire, "Could not initialize the PGP database at %s: %m\n", path); - goto ERROR; - } - // Setup engine error = gpgme_ctx_set_engine_info(*ctx, GPGME_PROTOCOL_OpenPGP, NULL, path); if (gpg_err_code(error) != GPG_ERR_NO_ERROR) @@ -101,12 +95,25 @@ ERROR: gpgme_release(*ctx); *ctx = NULL; + // Cleanup temporary files + if (tmp) + pakfire_rmtree(tmp, 0); + return r; } int pakfire_keystore_destroy(struct pakfire* pakfire, gpgme_ctx_t* ctx) { + char path[PATH_MAX]; + + // Retrieve engine info + gpgme_engine_info_t engine_info = gpgme_ctx_get_engine_info(*ctx); + + // Store a copy of the home directory + pakfire_string_set(path, engine_info->home_dir); + // Free GPGME context gpgme_release(*ctx); - return 0; + // Remove home directory + return pakfire_rmtree(path, 0); }