• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kleopatra

  • sources
  • kde-4.12
  • kdepim
  • kleopatra
  • selftest
gpgconfcheck.cpp
Go to the documentation of this file.
1 /* -*- mode: c++; c-basic-offset:4 -*-
2  selftest/gpgconfcheck.cpp
3 
4  This file is part of Kleopatra, the KDE keymanager
5  Copyright (c) 2008 Klarälvdalens Datakonsult AB
6 
7  Kleopatra is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  Kleopatra is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21  In addition, as a special exception, the copyright holders give
22  permission to link the code of this program with any edition of
23  the Qt library by Trolltech AS, Norway (or with modified versions
24  of Qt that use the same license as Qt), and distribute linked
25  combinations including the two. You must obey the GNU General
26  Public License in all respects for all of the code used other than
27  Qt. If you modify this file, you may extend this exception to
28  your version of the file, but you are not obligated to do so. If
29  you do not wish to do so, delete this exception statement from
30  your version.
31 */
32 
33 #include <config-kleopatra.h>
34 
35 #include "gpgconfcheck.h"
36 
37 #include "implementation_p.h"
38 
39 #include <utils/gnupg-helper.h>
40 #include <utils/hex.h>
41 
42 #include <KDebug>
43 #include <KLocale>
44 
45 #include <QProcess>
46 #include <QDir>
47 
48 #include <boost/shared_ptr.hpp>
49 
50 #include <cassert>
51 
52 using namespace Kleo;
53 using namespace Kleo::_detail;
54 using namespace boost;
55 
56 namespace {
57 
58  class GpgConfCheck : public SelfTestImplementation {
59  QString m_component;
60  public:
61  explicit GpgConfCheck( const char * component )
62  : SelfTestImplementation( i18nc("@title", "%1 Configuration Check", component && *component ? QLatin1String(component) : QLatin1String("gpgconf") ) ),
63  m_component( QLatin1String(component) )
64  {
65  runTest();
66  }
67 
68  QStringList arguments() const {
69  if ( m_component.isEmpty() )
70  return QStringList() << QLatin1String("--check-config");
71  else
72  return QStringList() << QLatin1String("--check-options") << m_component ;
73  }
74 
75  bool canRun() {
76  if ( !ensureEngineVersion( GpgME::GpgConfEngine, 2, 0, 10 ) )
77  return false;
78 
79  if ( !m_component.isEmpty() )
80  return true;
81 
82  QProcess gpgconf;
83  gpgconf.setReadChannel( QProcess::StandardOutput );
84  gpgconf.start( gpgConfPath(), QStringList() << QLatin1String("--list-dirs"), QIODevice::ReadOnly );
85  gpgconf.waitForFinished();
86  if ( gpgconf.exitStatus() != QProcess::NormalExit || gpgconf.exitCode() != 0 ) {
87  kDebug() << "GpgConfCheck: \"gpgconf --list-dirs\" gives error, disabling";
88  return false;
89  }
90  const QList<QByteArray> lines = gpgconf.readAll().split( '\n' );
91  Q_FOREACH( const QByteArray & line, lines )
92  if ( line.startsWith( "sysconfdir:" ) ) //krazy:exclude=strings
93  try {
94  return QDir( QFile::decodeName( hexdecode( line.mid( strlen( "sysconfdir:" ) ) ) ) ).exists( QLatin1String("gpgconf.conf") );
95  } catch ( ... ) { return false; }
96  kDebug() << "GpgConfCheck: \"gpgconf --list-dirs\" has no sysconfdir entry";
97  return false;
98  }
99 
100  void runTest() {
101 
102  if ( !canRun() ) {
103  if ( !m_skipped )
104  m_passed = true;
105  return;
106  }
107 
108  QProcess process;
109  process.setProcessChannelMode( QProcess::MergedChannels );
110 
111  process.start( gpgConfPath(), arguments(), QIODevice::ReadOnly );
112 
113  process.waitForFinished();
114 
115  const QString output = QString::fromUtf8( process.readAll() );
116  const QString message = process.exitStatus() == QProcess::CrashExit ? i18n( "The process terminated prematurely" ) : process.errorString() ;
117 
118  if ( process.exitStatus() != QProcess::NormalExit ||
119  process.error() != QProcess::UnknownError ) {
120  m_passed = false;
121  m_error = i18nc("self-test did not pass", "Failed");
122  m_explaination =
123  i18n( "There was an error executing the GnuPG configuration self-check for %2:\n"
124  " %1\n"
125  "You might want to execute \"gpgconf %3\" on the command line.\n",
126  message, m_component.isEmpty() ? QLatin1String("GnuPG") : m_component, arguments().join(QLatin1String(" ") ) );
127  if ( !output.trimmed().isEmpty() )
128  m_explaination += QLatin1Char('\n') + i18n("Diagnostics:") + QLatin1Char('\n') + output ;
129 
130  m_proposedFix.clear();
131  } else if ( process.exitCode() ) {
132  m_passed = false;
133  m_error = i18nc("self-check did not pass", "Failed");
134  m_explaination = !output.trimmed().isEmpty()
135  ? i18nc("Self-test did not pass",
136  "The GnuPG configuration self-check failed.\n"
137  "\n"
138  "Error code: %1\n"
139  "Diagnostics:", process.exitCode() ) + QLatin1Char('\n') + output
140  : i18nc("self-check did not pass",
141  "The GnuPG configuration self-check failed with error code %1.\n"
142  "No output was received.", process.exitCode() );
143  m_proposedFix.clear();
144  } else {
145  m_passed = true;
146  }
147  }
148 
149  };
150 }
151 
152 shared_ptr<SelfTest> Kleo::makeGpgConfCheckConfigurationSelfTest( const char * component ) {
153  return shared_ptr<SelfTest>( new GpgConfCheck( component ) );
154 }
boost::shared_ptr
Definition: encryptemailcontroller.h:51
process
static QString process(const Dir &dir, bool *fatal)
Definition: createchecksumscontroller.cpp:532
hex.h
gpgconfcheck.h
gnupg-helper.h
Kleo::makeGpgConfCheckConfigurationSelfTest
boost::shared_ptr< SelfTest > makeGpgConfCheckConfigurationSelfTest(const char *component=0)
Definition: gpgconfcheck.cpp:152
Kleo::gpgConfPath
QString gpgConfPath()
Definition: gnupg-helper.cpp:78
implementation_p.h
Kleo::_detail::SelfTestImplementation
Definition: implementation_p.h:45
Kleo::hexdecode
std::string hexdecode(const char *s)
Definition: hex.cpp:117
QList
Definition: commands/command.h:46
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:56:41 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kleopatra

Skip menu "kleopatra"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal