Commit db0b4afa authored by Rolf Eike Beer's avatar Rolf Eike Beer Committed by Rolf Eike Beer
Browse files

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
parent c97530d3
......@@ -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());
......
......@@ -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
......
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment