aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSaturneric <[email protected]>2023-02-11 12:26:23 +0000
committerSaturneric <[email protected]>2023-02-11 12:26:23 +0000
commitc480f6bbd460af903f9dc2048fb9485dde38c573 (patch)
treeea76900452bd1675a1fa428ec06d5abe030df0f1
parentfeat: reduce logs (diff)
downloadGpgFrontend-c480f6bbd460af903f9dc2048fb9485dde38c573.tar.gz
GpgFrontend-c480f6bbd460af903f9dc2048fb9485dde38c573.zip
feat: add more gnupg operations
-rw-r--r--src/core/function/gpg/GpgAdvancedOperator.cpp79
-rw-r--r--src/core/function/gpg/GpgAdvancedOperator.h48
2 files changed, 119 insertions, 8 deletions
diff --git a/src/core/function/gpg/GpgAdvancedOperator.cpp b/src/core/function/gpg/GpgAdvancedOperator.cpp
index 3cbee45d..2a3bba42 100644
--- a/src/core/function/gpg/GpgAdvancedOperator.cpp
+++ b/src/core/function/gpg/GpgAdvancedOperator.cpp
@@ -47,7 +47,6 @@ bool GpgFrontend::GpgAdvancedOperator::ClearGpgPasswordCache() {
success = true;
}
});
-
return success;
}
@@ -65,17 +64,18 @@ bool GpgFrontend::GpgAdvancedOperator::ReloadGpgComponents() {
return;
}
});
-
return success;
}
bool GpgFrontend::GpgAdvancedOperator::RestartGpgComponents() {
bool success = false;
+
GpgFrontend::GpgCommandExecutor::GetInstance().Execute(
- ctx_.GetInfo().GpgConfPath, {"--kill", "all"},
+ ctx_.GetInfo().GpgConfPath, {"--verbose", "--kill", "all"},
[&](int exit_code, const std::string &p_out, const std::string &p_err) {
if (exit_code == 0) {
success = true;
+ return;
} else {
SPDLOG_ERROR(
"gpgconf execute error, process stderr: {}, process stdout: {}",
@@ -84,13 +84,25 @@ bool GpgFrontend::GpgAdvancedOperator::RestartGpgComponents() {
}
});
+ if (!success) return false;
+
+ success &= StartGpgAgent();
+
+ success &= StartDirmngr();
+
+ success &= StartKeyBoxd();
+
+ return success;
+}
+
+bool GpgFrontend::GpgAdvancedOperator::ResetConfigures() {
+ bool success = false;
GpgFrontend::GpgCommandExecutor::GetInstance().Execute(
- ctx_.GetInfo().GpgConfPath, {"--launch", "all"},
+ ctx_.GetInfo().GpgConfPath, {"--apply-defaults"},
[&](int exit_code, const std::string &p_out, const std::string &p_err) {
if (exit_code == 0) {
success = true;
} else {
- success = false;
SPDLOG_ERROR(
"gpgconf execute error, process stderr: {}, process stdout: {}",
p_err, p_out);
@@ -101,16 +113,67 @@ bool GpgFrontend::GpgAdvancedOperator::RestartGpgComponents() {
return success;
}
-bool GpgFrontend::GpgAdvancedOperator::ResetConfigures() {
+bool GpgFrontend::GpgAdvancedOperator::StartGpgAgent() {
bool success = false;
GpgFrontend::GpgCommandExecutor::GetInstance().Execute(
- ctx_.GetInfo().GpgConfPath, {"--apply-defaults"},
+ ctx_.GetInfo().GpgAgentPath,
+ {"--homedir", ctx_.GetInfo().GnuPGHomePath, "--daemon"},
[&](int exit_code, const std::string &p_out, const std::string &p_err) {
if (exit_code == 0) {
success = true;
+ SPDLOG_INFO("start gpg-agent successfully");
+ } else if (exit_code == 2) {
+ success = true;
+ SPDLOG_INFO("gpg-agent already started");
} else {
SPDLOG_ERROR(
- "gpgconf execute error, process stderr: {}, process stdout: {}",
+ "gpg-agent execute error, process stderr: {}, process stdout: {}",
+ p_err, p_out);
+ return;
+ }
+ });
+
+ return success;
+}
+
+bool GpgFrontend::GpgAdvancedOperator::StartDirmngr() {
+ bool success = false;
+ GpgFrontend::GpgCommandExecutor::GetInstance().Execute(
+ ctx_.GetInfo().DirmngrPath,
+ {"--homedir", ctx_.GetInfo().GnuPGHomePath, "--daemon"},
+ [&](int exit_code, const std::string &p_out, const std::string &p_err) {
+ if (exit_code == 0) {
+ success = true;
+ SPDLOG_INFO("start dirmngr successfully");
+ } else if (exit_code == 2) {
+ success = true;
+ SPDLOG_INFO("dirmngr already started");
+ } else {
+ SPDLOG_ERROR(
+ "dirmngr execute error, process stderr: {}, process stdout: {}",
+ p_err, p_out);
+ return;
+ }
+ });
+
+ return success;
+}
+
+bool GpgFrontend::GpgAdvancedOperator::StartKeyBoxd() {
+ bool success = false;
+ GpgFrontend::GpgCommandExecutor::GetInstance().Execute(
+ ctx_.GetInfo().KeyboxdPath,
+ {"--homedir", ctx_.GetInfo().GnuPGHomePath, "--daemon"},
+ [&](int exit_code, const std::string &p_out, const std::string &p_err) {
+ if (exit_code == 0) {
+ success = true;
+ SPDLOG_INFO("start keyboxd successfully");
+ } else if (exit_code == 2) {
+ success = true;
+ SPDLOG_INFO("keyboxd already started");
+ } else {
+ SPDLOG_ERROR(
+ "keyboxd execute error, process stderr: {}, process stdout: {}",
p_err, p_out);
return;
}
diff --git a/src/core/function/gpg/GpgAdvancedOperator.h b/src/core/function/gpg/GpgAdvancedOperator.h
index 267f1614..5325020a 100644
--- a/src/core/function/gpg/GpgAdvancedOperator.h
+++ b/src/core/function/gpg/GpgAdvancedOperator.h
@@ -49,14 +49,62 @@ class GPGFRONTEND_CORE_EXPORT GpgAdvancedOperator
explicit GpgAdvancedOperator(
int channel = SingletonFunctionObject::GetDefaultChannel());
+ /**
+ * @brief
+ *
+ * @return true
+ * @return false
+ */
bool ClearGpgPasswordCache();
+ /**
+ * @brief
+ *
+ * @return true
+ * @return false
+ */
bool ReloadGpgComponents();
+ /**
+ * @brief
+ *
+ * @return true
+ * @return false
+ */
bool RestartGpgComponents();
+ /**
+ * @brief
+ *
+ * @return true
+ * @return false
+ */
bool ResetConfigures();
+ /**
+ * @brief
+ *
+ * @return true
+ * @return false
+ */
+ bool StartGpgAgent();
+
+ /**
+ * @brief
+ *
+ * @return true
+ * @return false
+ */
+ bool StartDirmngr();
+
+ /**
+ * @brief
+ *
+ * @return true
+ * @return false
+ */
+ bool StartKeyBoxd();
+
private:
GpgContext& ctx_ = GpgContext::GetInstance(
SingletonFunctionObject::GetChannel()); ///< Corresponding context