diff options
Diffstat (limited to 'src/m_pinentry')
| -rw-r--r-- | src/m_pinentry/CMakeLists.txt | 10 | ||||
| -rw-r--r-- | src/m_pinentry/GpgPassphraseContext.cpp | 6 | ||||
| -rw-r--r-- | src/m_pinentry/GpgPassphraseContext.h | 5 | ||||
| -rw-r--r-- | src/m_pinentry/PinentryModule.cpp | 33 | ||||
| -rw-r--r-- | src/m_pinentry/RaisePinentry.cpp | 4 | ||||
| -rw-r--r-- | src/m_pinentry/pinentry.cpp | 6 | ||||
| -rw-r--r-- | src/m_pinentry/pinentry.h | 2 | ||||
| -rw-r--r-- | src/m_pinentry/qti18n.cpp | 93 |
8 files changed, 42 insertions, 117 deletions
diff --git a/src/m_pinentry/CMakeLists.txt b/src/m_pinentry/CMakeLists.txt index bf17acd..344fc38 100644 --- a/src/m_pinentry/CMakeLists.txt +++ b/src/m_pinentry/CMakeLists.txt @@ -23,6 +23,7 @@ # # SPDX-License-Identifier: GPL-3.0-or-later +set(INTEGRATED_MODULE_SOURCE "") aux_source_directory(. INTEGRATED_MODULE_SOURCE) # capslock @@ -49,13 +50,8 @@ install(TARGETS mod_pinentry target_link_libraries(mod_pinentry PRIVATE gpgfrontend_module_sdk) -if(GPGFRONTEND_QT5_BUILD) - # link Qt core - target_link_libraries(mod_pinentry PUBLIC Qt5::Widgets) -else() - # link Qt core - target_link_libraries(mod_pinentry PUBLIC Qt6::Widgets) -endif() +# link qt +target_link_libraries(mod_pinentry PUBLIC Qt::Widgets) # using std c++ 17 target_compile_features(mod_pinentry PUBLIC cxx_std_17) diff --git a/src/m_pinentry/GpgPassphraseContext.cpp b/src/m_pinentry/GpgPassphraseContext.cpp index 4e21a20..61add57 100644 --- a/src/m_pinentry/GpgPassphraseContext.cpp +++ b/src/m_pinentry/GpgPassphraseContext.cpp @@ -54,4 +54,8 @@ auto GpgPassphraseContext::GetPassphraseInfo() const -> QString { auto GpgPassphraseContext::IsPreWasBad() const -> bool { return prev_was_bad_; } -auto GpgPassphraseContext::IsAskForNew() const -> bool { return ask_for_new_; }
\ No newline at end of file +auto GpgPassphraseContext::IsAskForNew() const -> bool { return ask_for_new_; } + +auto GpgPassphraseContext::IsSuccess() const -> bool { return success_; } + +void GpgPassphraseContext::SetSuccess(bool success) { success_ = success; }
\ No newline at end of file diff --git a/src/m_pinentry/GpgPassphraseContext.h b/src/m_pinentry/GpgPassphraseContext.h index 107307b..f021cb8 100644 --- a/src/m_pinentry/GpgPassphraseContext.h +++ b/src/m_pinentry/GpgPassphraseContext.h @@ -42,6 +42,8 @@ class GpgPassphraseContext : public QObject { void SetPassphrase(const QString& passphrase); + void SetSuccess(bool success); + [[nodiscard]] auto GetPassphrase() const -> QString; [[nodiscard]] auto GetUidsInfo() const -> QString; @@ -52,10 +54,13 @@ class GpgPassphraseContext : public QObject { [[nodiscard]] auto IsAskForNew() const -> bool; + [[nodiscard]] auto IsSuccess() const -> bool; + private: QString passphrase_info_; QString uids_info_; QString passphrase_; bool prev_was_bad_; bool ask_for_new_; + bool success_; }; diff --git a/src/m_pinentry/PinentryModule.cpp b/src/m_pinentry/PinentryModule.cpp index 5d767a9..01b2185 100644 --- a/src/m_pinentry/PinentryModule.cpp +++ b/src/m_pinentry/PinentryModule.cpp @@ -58,27 +58,38 @@ auto GFExecuteModule(GFModuleEvent *p_event) -> int { auto event = ConvertEventToMap(p_event); if (event["prev_was_bad"].isEmpty() || event["ask_for_new"].isEmpty()) { - GFModuleTriggerModuleEventCallback( - ConvertMapToEvent(event), GFGetModuleID(), - ConvertMapToParams({{"ret", "-1"}, {"passphrase", ""}})); + CB(event, GFGetModuleID(), + { + {"ret", "-1"}, + {"passphrase", ""}, + }); return -1; } QMetaObject::invokeMethod( - QApplication::instance()->thread(), [p_event, event]() -> int { + QApplication::instance()->thread(), [event]() -> int { auto *p = new RaisePinentry( nullptr, SecureCreateQSharedObject<GpgPassphraseContext>( event["uid_hint"], event["passphrase_info"], event["prev_was_bad"].toInt(), event["ask_for_new"].toInt())); - QObject::connect( - p, &RaisePinentry::SignalUserInputPassphraseCallback, p, - [event](const QSharedPointer<GpgPassphraseContext> &c) { - GFModuleTriggerModuleEventCallback( - ConvertMapToEvent(event), GFGetModuleID(), - ConvertMapToParams({{"passphrase", c->GetPassphrase()}})); - }); + QObject::connect(p, &RaisePinentry::SignalUserInputPassphraseCallback, + p, [event](QSharedPointer<GpgPassphraseContext> c) { + if (c) { + CB(event, GFGetModuleID(), + { + {"ret", "0"}, + {"passphrase", c->GetPassphrase()}, + }); + } else { + CB(event, GFGetModuleID(), + { + {"ret", "-1"}, + {"passphrase", ""}, + }); + } + }); p->Exec(); return 0; diff --git a/src/m_pinentry/RaisePinentry.cpp b/src/m_pinentry/RaisePinentry.cpp index ed9538d..e4061e6 100644 --- a/src/m_pinentry/RaisePinentry.cpp +++ b/src/m_pinentry/RaisePinentry.cpp @@ -90,12 +90,14 @@ auto RaisePinentry::Exec() -> int { bool ret = result != 0; if (!ret) { - emit SignalUserInputPassphraseCallback({}); + context_->SetSuccess(false); + emit SignalUserInputPassphraseCallback(context_); return -1; } auto pin = pinentry->pin().toUtf8(); + context_->SetSuccess(true); context_->SetPassphrase(pin); emit SignalUserInputPassphraseCallback(context_); return 0; diff --git a/src/m_pinentry/pinentry.cpp b/src/m_pinentry/pinentry.cpp index c2965a8..b46cde1 100644 --- a/src/m_pinentry/pinentry.cpp +++ b/src/m_pinentry/pinentry.cpp @@ -26,7 +26,7 @@ #include "GFModuleCommonUtils.hpp" #include "GFSDKBasic.h" -#ifdef WINDOWS +#if defined(_WIN32) || defined(WIN32) #define getpid() GetCurrentProcessId() #endif @@ -39,7 +39,7 @@ static const char *flavor_flag; /* Return a malloced copy of the commandline for PID. If this is not * possible NULL is returned. */ -#ifndef WINDOWS +#if !(defined(_WIN32) || defined(WIN32)) static char *get_cmdline(unsigned long pid) { char buffer[200]; FILE *fp; @@ -76,7 +76,7 @@ static char *get_cmdline(unsigned long pid) { * This is not as informative as get_cmdline, but it verifies that the * process does belong to the user in question. */ -#ifndef WINDOWS +#if !(defined(_WIN32) || defined(WIN32)) static char *get_pid_name_for_uid(unsigned long pid, int uid) { char buffer[400]; FILE *fp; diff --git a/src/m_pinentry/pinentry.h b/src/m_pinentry/pinentry.h index 5c38c68..c25ae0f 100644 --- a/src/m_pinentry/pinentry.h +++ b/src/m_pinentry/pinentry.h @@ -325,7 +325,7 @@ void pinentry_parse_opts(int argc, char *argv[]); /* Set the optional flag used with getinfo. */ void pinentry_set_flavor_flag(const char *string); -#ifdef WINDOWS +#if defined(_WIN32) || defined(WIN32) /* Windows declares sleep as obsolete, but provides a definition for _sleep but non for the still existing sleep. */ #define sleep(a) _sleep((a)) diff --git a/src/m_pinentry/qti18n.cpp b/src/m_pinentry/qti18n.cpp deleted file mode 100644 index 198e6cc..0000000 --- a/src/m_pinentry/qti18n.cpp +++ /dev/null @@ -1,93 +0,0 @@ -/* qti18n.cpp - Load qt translations for pinentry. - * Copyright 2021 g10 Code GmbH - * SPDX-FileCopyrightText: 2015 Lukáš Tinkl <[email protected]> - * SPDX-FileCopyrightText: 2021 Ingo Klöcker <[email protected]> - * - * Copied from k18n under the terms of LGPLv2 or later. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <https://www.gnu.org/licenses/>. - * SPDX-License-Identifier: GPL-2.0+ - */ - -#include <QCoreApplication> -#include <QDebug> -#include <QLibraryInfo> -#include <QLocale> -#include <QTranslator> - -static bool loadCatalog(const QString &catalog, const QLocale &locale) { - auto translator = new QTranslator(QCoreApplication::instance()); - - if (!translator->load(locale, catalog, QString(), - QLatin1String(":/i18n_qt"))) { - qDebug() << "Loading the" << catalog << "catalog failed for locale" - << locale; - delete translator; - return false; - } - QCoreApplication::instance()->installTranslator(translator); - return true; -} - -static bool loadCatalog(const QString &catalog, const QLocale &locale, - const QLocale &fallbackLocale) { - // try to load the catalog for locale - if (loadCatalog(catalog, locale)) { - return true; - } - // if this fails, then try the fallback locale (if it's different from locale) - if (fallbackLocale != locale) { - return loadCatalog(catalog, fallbackLocale); - } - return false; -} - -// load global Qt translation, needed in KDE e.g. by lots of builtin dialogs -// (QColorDialog, QFontDialog) that we use -static void loadTranslation(const QString &localeName, - const QString &fallbackLocaleName) { - const QLocale locale{localeName}; - const QLocale fallbackLocale{fallbackLocaleName}; - // first, try to load the qt_ meta catalog - if (loadCatalog(QStringLiteral("qt_"), locale, fallbackLocale)) { - return; - } - // if loading the meta catalog failed, then try loading the four catalogs - // it depends on, i.e. qtbase, qtscript, qtmultimedia, qtxmlpatterns, - // separately - const auto catalogs = { - QStringLiteral("qtbase_"), - /* QStringLiteral("qtscript_"), - QStringLiteral("qtmultimedia_"), - QStringLiteral("qtxmlpatterns_"), */ - }; - for (const auto &catalog : catalogs) { - loadCatalog(catalog, locale, fallbackLocale); - } -} - -static void load() { - // The way Qt translation system handles plural forms makes it necessary to - // have a translation file which contains only plural forms for `en`. That's - // why we load the `en` translation unconditionally, then load the - // translation for the current locale to overload it. - loadCatalog(QStringLiteral("qt_"), QLocale{QStringLiteral("en")}); - - const QLocale locale = QLocale::system(); - if (locale.name() != QStringLiteral("en")) { - loadTranslation(locale.name(), locale.bcp47Name()); - } -} - -Q_COREAPP_STARTUP_FUNCTION(load) |
