summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRolf Eike Beer <kde@opensource.sf-tec.de>2011-10-23 19:14:02 (GMT)
committerRolf Eike Beer <eike-kernel@sf-tec.de>2011-10-24 06:29:50 (GMT)
commitdb0b4afa84317182f48b6d8c3f603b0c96f5aff3 (patch)
treedd0f34555fafec7981a9eeb98cc69ec73c907482
parentc97530d36fc24221b8ce99abd54b79ebfff495fb (diff)
check for GnuPG errors on startup
If GnuPG cannot run (e.g. because of configuration errors) everything bad can happen. Explicitely check for this on startup and tell the user to fix his GnuPG first. BUG:269459 FIXED-IN:4.7.3,4.8.0 CCMAIL:kde-i18n-doc@kde.org
-rw-r--r--kgpg.cpp6
-rw-r--r--kgpginterface.cpp19
-rw-r--r--kgpginterface.h7
3 files changed, 32 insertions, 0 deletions
diff --git a/kgpg.cpp b/kgpg.cpp
index 560c7c6..af8a777 100644
--- a/kgpg.cpp
+++ b/kgpg.cpp
@@ -76,6 +76,12 @@ int KGpgApp::newInstance()
if (KUrl::fromPath(gpgPath).directory(KUrl::AppendTrailingSlash) != (QDir::homePath() + QLatin1String( "/.gnupg/" )))
setenv("GNUPGHOME", KUrl::fromPath(gpgPath).directory(KUrl::AppendTrailingSlash).toAscii(), 1);
+ const QString gpgError = KgpgInterface::getGpgStartupError(KGpgSettings::gpgBinaryPath());
+ if (!gpgError.isEmpty()) {
+ KMessageBox::detailedError(0, i18n("GnuPG failed to start.<br />You must fix the GnuPG error first before running KGpg."), gpgError, i18n("GnuPG error"));
+ KApplication::quit();
+ }
+
s_keyManager = new KeysManager();
w = new KGpgExternalActions(s_keyManager, s_keyManager->getModel());
diff --git a/kgpginterface.cpp b/kgpginterface.cpp
index 108c73f..4290cee 100644
--- a/kgpginterface.cpp
+++ b/kgpginterface.cpp
@@ -105,6 +105,25 @@ QString KgpgInterface::getGpgProcessHome(const QString &binary)
return QString();
}
+QString KgpgInterface::getGpgStartupError(const QString &binary)
+{
+ GPGProc process(0, binary);
+ process << QLatin1String( "--version" );
+ process.start();
+ process.waitForFinished(-1);
+
+ QString result;
+
+ while (process.hasLineStandardError()) {
+ QByteArray tmp;
+ process.readLineStandardError(&tmp);
+ tmp += '\n';
+ result += QString::fromUtf8(tmp);
+ }
+
+ return result;
+}
+
QString KgpgInterface::getGpgHome(const QString &binary)
{
// First try: if environment is set GnuPG will use that directory
diff --git a/kgpginterface.h b/kgpginterface.h
index c8dc753..57540d5 100644
--- a/kgpginterface.h
+++ b/kgpginterface.h
@@ -120,6 +120,13 @@ public:
*/
static int sendPassphrase(const QString &text, KProcess *process, const bool isnew = true, QWidget *widget = NULL);
+ /**
+ * @brief run GnuPG and check if it complains about anything
+ * @param binary the GnuPG binary to run
+ * @return the error message GnuPG gave out (if any)
+ */
+ static QString getGpgStartupError(const QString &binary);
+
private:
static QString getGpgProcessHome(const QString &binary);