aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSaturneric <[email protected]>2023-04-04 16:15:54 +0000
committerSaturneric <[email protected]>2023-04-04 16:15:54 +0000
commitbef01eeb99351570d01a06e3db65cbd0cea5b102 (patch)
tree1eab214d697c214aad995816445bac8248ea85f9 /src
parentfeat: remove gnupg settings from general tab (diff)
downloadGpgFrontend-bef01eeb99351570d01a06e3db65cbd0cea5b102.tar.gz
GpgFrontend-bef01eeb99351570d01a06e3db65cbd0cea5b102.zip
feat: add custom gpgconf path support in context
Diffstat (limited to 'src')
-rw-r--r--src/core/GpgContext.cpp8
-rw-r--r--src/core/GpgContext.h5
-rw-r--r--src/core/GpgCoreInit.cpp38
3 files changed, 50 insertions, 1 deletions
diff --git a/src/core/GpgContext.cpp b/src/core/GpgContext.cpp
index f8dbebc6..47ff77c4 100644
--- a/src/core/GpgContext.cpp
+++ b/src/core/GpgContext.cpp
@@ -77,6 +77,14 @@ GpgContext::GpgContext(const GpgContextInitArgs &args) : args_(args) {
assert(check_gpg_error_2_err_code(err) == GPG_ERR_NO_ERROR);
}
+ if (args.custom_gpgconf && !args.custom_gpgconf_path.empty()) {
+ SPDLOG_DEBUG("set custom gpgconf path: {}", args.custom_gpgconf_path);
+ auto err =
+ gpgme_ctx_set_engine_info(_ctx_ref.get(), GPGME_PROTOCOL_GPGCONF,
+ args.custom_gpgconf_path.c_str(), nullptr);
+ assert(check_gpg_error_2_err_code(err) == GPG_ERR_NO_ERROR);
+ }
+
// set context offline mode
SPDLOG_DEBUG("gpg context offline mode: {}", args_.offline_mode);
gpgme_set_offline(_ctx_ref.get(), args_.offline_mode ? 1 : 0);
diff --git a/src/core/GpgContext.h b/src/core/GpgContext.h
index 2ff87e6b..a199e62d 100644
--- a/src/core/GpgContext.h
+++ b/src/core/GpgContext.h
@@ -47,13 +47,18 @@ struct GpgContextInitArgs {
// make no sense for gpg2
bool independent_database = false; ///<
std::string db_path = {};
+
bool gpg_alone = false;
std::string gpg_path = {};
+
bool test_mode = false;
bool ascii = true;
bool offline_mode = false;
bool auto_import_missing_key = false;
+ bool custom_gpgconf = false;
+ std::string custom_gpgconf_path;
+
GpgContextInitArgs() = default;
};
diff --git a/src/core/GpgCoreInit.cpp b/src/core/GpgCoreInit.cpp
index 9395bac7..48883048 100644
--- a/src/core/GpgCoreInit.cpp
+++ b/src/core/GpgCoreInit.cpp
@@ -32,6 +32,8 @@
#include <spdlog/sinks/rotating_file_sink.h>
#include <spdlog/sinks/stdout_color_sinks.h>
+#include <filesystem>
+
#include "GpgFunctionObject.h"
#include "core/GpgContext.h"
#include "core/function/GlobalSettingStation.h"
@@ -150,6 +152,34 @@ void init_gpgfrontend_core() {
SPDLOG_DEBUG("core loaded custom key databse path: {}",
custom_key_database_path);
+ bool use_custom_gnupg_install_path = false;
+ try {
+ use_custom_gnupg_install_path =
+ settings.lookup("general.use_custom_gnupg_install_path");
+ } catch (...) {
+ SPDLOG_ERROR("setting operation error: use_custom_gnupg_install_path");
+ }
+
+ // read from settings file
+ std::filesystem::path custom_gnupg_install_path;
+ try {
+ custom_gnupg_install_path = std::filesystem::path(static_cast<std::string>(
+ settings.lookup("general.custom_gnupg_install_path")));
+
+ } catch (...) {
+ SPDLOG_ERROR("setting operation error: custom_gnupg_install_path");
+ }
+
+ // check gpgconf path
+ if (!custom_gnupg_install_path.is_absolute()) {
+ use_custom_gnupg_install_path = false;
+ SPDLOG_ERROR("core loaded custom gpgconf path error: {}",
+ custom_gnupg_install_path.u8string());
+ } else {
+ SPDLOG_DEBUG("core loaded custom gpgconf path: {}",
+ custom_gnupg_install_path.u8string());
+ }
+
// init default channel
auto& default_ctx = GpgFrontend::GpgContext::CreateInstance(
GPGFRONTEND_DEFAULT_CHANNEL, [=]() -> std::unique_ptr<ChannelObject> {
@@ -163,13 +193,19 @@ void init_gpgfrontend_core() {
args.offline_mode = forbid_all_gnupg_connection;
args.auto_import_missing_key = auto_import_missing_key;
+ if (use_custom_gnupg_install_path) {
+ args.custom_gpgconf = true;
+ args.custom_gpgconf_path =
+ (custom_gnupg_install_path / "gpgconf").u8string();
+ }
+
return std::unique_ptr<ChannelObject>(new GpgContext(args));
});
// exit if failed
if (!default_ctx.good()) {
SPDLOG_ERROR("default gpgme context init error, exit.");
- QCoreApplication::exit();
+ return;
};
// async init no-ascii channel