33 #include <config-kleopatra.h>
39 #include <gpgme++/engineinfo.h>
42 #include <KStandardDirs>
50 #include <gpg-error.h>
61 const QByteArray gnupgHome = qgetenv(
"GNUPGHOME" );
62 if ( !gnupgHome.isEmpty() )
63 return QFile::decodeName( gnupgHome );
65 return QDir::homePath() + QLatin1String(
"/.gnupg");
70 return gpg_error( static_cast<gpg_err_code_t>( code ) );
73 static QString
findGpgExe( GpgME::Engine engine,
const QString & exe ) {
74 const GpgME::EngineInfo info = GpgME::engineInfo( engine );
75 return info.fileName() ? QFile::decodeName( info.fileName() ) : KStandardDirs::findExe( exe ) ;
79 return findGpgExe( GpgME::GpgConfEngine, QLatin1String(
"gpgconf") );
83 return findGpgExe( GpgME::GpgSMEngine, QLatin1String(
"gpgsm") );
87 return findGpgExe( GpgME::GpgEngine, QLatin1String(
"gpg") );
92 << QLatin1String(
"dirmngr-cache.d")
93 << QLatin1String(
"S.uiserver")
94 << QLatin1String(
"S.gpg-agent")
95 << QLatin1String(
"random_seed")
96 << QLatin1String(
"*~")
97 << QLatin1String(
"*.bak")
98 << QLatin1String(
"*.lock")
99 << QLatin1String(
"*.tmp")
100 << QLatin1String(
"reader_*.status")
113 if ( ERROR_SUCCESS!=RegOpenKeyExW ( HKEY_LOCAL_MACHINE, L
"Software\\GNU\\GnuPG", 0, KEY_READ, &hKey ) ){
117 if ( ERROR_SUCCESS!=RegQueryValueExW ( hKey, L
"Install Directory", NULL, NULL, NULL, &dwSize ) ){
121 lszValue =
new TCHAR[dwSize];
123 if ( ERROR_SUCCESS!=RegQueryValueExW ( hKey,L
"Install Directory", NULL, &dwType, ( LPBYTE ) lszValue, &dwSize ) ) {
127 RegCloseKey ( hKey );
129 QString res = QString::fromUtf16 ( (
const ushort* ) lszValue );
137 if ( !which || !*which )
140 if ( gpgConfPath.isEmpty() )
143 kDebug() <<
"gpgConfListDir: starting " << qPrintable( gpgConfPath ) <<
" --list-dirs";
144 gpgConf.start( gpgConfPath, QStringList() << QLatin1String(
"--list-dirs" ) );
145 if ( !gpgConf.waitForFinished() ) {
146 kDebug() <<
"gpgConfListDir(): failed to execute gpgconf: " << qPrintable( gpgConf.errorString() );
147 kDebug() <<
"output was:" << endl << gpgConf.readAllStandardError().constData();
151 Q_FOREACH(
const QByteArray & line, lines )
152 if ( line.startsWith( which ) && line[qstrlen(which)] ==
':' ) {
153 const int begin = qstrlen(which) + 1;
154 int end = line.size();
155 while ( end && ( line[end-1] ==
'\n' || line[end-1] ==
'\r' ) )
157 const QString result = QDir::fromNativeSeparators( QFile::decodeName(
hexdecode( line.mid( begin, end - begin ) ) ) );
158 kDebug() <<
"gpgConfListDir: found " << qPrintable( result )
159 <<
" for '" << which <<
"'entry";
162 kDebug() <<
"gpgConfListDir(): didn't find '" << which <<
"'"
163 <<
"entry in output:" << endl << gpgConf.readAllStandardError().constData();
QString gnupgHomeDirectory()
static QString findGpgExe(GpgME::Engine engine, const QString &exe)
char * default_homedir(void)
QString gpgConfListDir(const char *which)
QStringList gnupgFileBlacklist()
static QString gpgConfPath()
int makeGnuPGError(int code)
QString gpg4winInstallPath()
std::string hexdecode(const char *s)