Skip to content

Commit

Permalink
Make doctools + wallet optional
Browse files Browse the repository at this point in the history
REVIEW: 125616
  • Loading branch information
christoph-cullmann committed Oct 18, 2015
1 parent b3929bc commit 9861d5d
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 9 deletions.
17 changes: 14 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ find_package(KF5CoreAddons ${KF5_DEP_VERSION} REQUIRED)
find_package(KF5DBusAddons ${KF5_DEP_VERSION} REQUIRED)
find_package(KF5I18n ${KF5_DEP_VERSION} REQUIRED)
find_package(KF5Service ${KF5_DEP_VERSION} REQUIRED)
find_package(KF5DocTools ${KF5_DEP_VERSION} REQUIRED)
find_package(KF5DocTools ${KF5_DEP_VERSION})
find_package(KF5Solid ${KF5_DEP_VERSION} REQUIRED) # for kio_trash

if (NOT KIOCORE_ONLY)
Expand All @@ -54,6 +54,12 @@ find_package(KF5WidgetsAddons ${KF5_DEP_VERSION} REQUIRED)
find_package(KF5WindowSystem ${KF5_DEP_VERSION} REQUIRED)
endif()

# tell what is missing without doctools
set_package_properties(KF5DocTools PROPERTIES DESCRIPTION "Provides tools to generate documentation in various format from DocBook files"
TYPE OPTIONAL
PURPOSE "Required to build help ioslave and documentation"
)

# TODO: Remove these
remove_definitions(-DQT_NO_CAST_FROM_ASCII)
remove_definitions(-DQT_NO_CAST_FROM_BYTEARRAY)
Expand Down Expand Up @@ -82,11 +88,16 @@ endif()
add_definitions(-DTRANSLATION_DOMAIN=\"kio5\")
if (IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/po")
ki18n_install(po)
kdoctools_install(po)

if (KF5DocTools_FOUND)
kdoctools_install(po)
endif()
endif()

if (KF5DocTools_FOUND)
add_subdirectory(docs)
add_subdirectory(docs)
endif()

include(CheckLibraryExists)
add_subdirectory(src)
add_subdirectory(autotests)
Expand Down
4 changes: 4 additions & 0 deletions src/ioslaves/help/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# kio_help only buildable if doc tools around
if (KF5DocTools_FOUND)

project(kioslave-help)

remove_definitions(-DQT_NO_CAST_FROM_ASCII)
Expand Down Expand Up @@ -86,3 +89,4 @@ install(TARGETS kio_ghelp DESTINATION ${KDE_INSTALL_PLUGINDIR}/kf5/kio)

install( FILES help.protocol ghelp.protocol DESTINATION ${KDE_INSTALL_KSERVICES5DIR} )

endif()
12 changes: 11 additions & 1 deletion src/kpasswdserver/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
find_package(KF5Wallet ${KF5_DEP_VERSION} REQUIRED)
find_package(KF5Wallet ${KF5_DEP_VERSION})

# tell what is missing without wallet
set_package_properties(KF5Wallet PROPERTIES DESCRIPTION "Safe desktop-wide storage for passwords"
TYPE OPTIONAL
PURPOSE "Required to have permanent storage of passwords for kpasswdserver"
)

if (KF5Wallet_FOUND)
add_definitions (-DHAVE_KF5WALLET)
endif()

add_subdirectory(autotests)

Expand Down
34 changes: 30 additions & 4 deletions src/kpasswdserver/kpasswdserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@

#include <kmessagebox.h>
#include <kpassworddialog.h>
#include <kwallet.h>
#include <kwindowsystem.h>
#include <kusertimestamp.h>
#include <klocalizedstring.h>

#ifdef HAVE_KF5WALLET
#include <kwallet.h>
#endif

#include <QPushButton>
#include <QTimer>
#include <ctime>
Expand Down Expand Up @@ -100,9 +103,14 @@ KPasswdServer::~KPasswdServer()
qDeleteAll(m_authDict);
qDeleteAll(m_authInProgress);
qDeleteAll(m_authRetryInProgress);

#ifdef HAVE_KF5WALLET
delete m_wallet;
#endif
}

#ifdef HAVE_KF5WALLET

// Helper - returns the wallet key to use for read/store/checking for existence.
static QString makeWalletKey( const QString& key, const QString& realm )
{
Expand Down Expand Up @@ -152,7 +160,6 @@ static bool storeInWallet( KWallet::Wallet* wallet, const QString& key, const KI
return true;
}


static bool readFromWallet( KWallet::Wallet* wallet, const QString& key, const QString& realm, QString& username, QString& password, bool userReadOnly, QMap<QString,QString>& knownLogins )
{
//qCDebug(category) << "key =" << key << " username =" << username << " password =" /*<< password*/ << " userReadOnly =" << userReadOnly << " realm =" << realm;
Expand Down Expand Up @@ -193,6 +200,8 @@ static bool readFromWallet( KWallet::Wallet* wallet, const QString& key, const Q
return false;
}

#endif

bool KPasswdServer::hasPendingQuery(const QString &key, const KIO::AuthInfo &info)
{
const QString path2 (info.url.path().left(info.url.path().indexOf('/')+1));
Expand Down Expand Up @@ -244,6 +253,7 @@ QByteArray KPasswdServer::checkAuthInfo(const QByteArray &data, qlonglong window
const AuthInfoContainer *result = findAuthInfoItem(key, info);
if (!result || result->isCanceled)
{
#ifdef HAVE_KF5WALLET
if (!result &&
!m_walletDisabled &&
(info.username.isEmpty() || info.password.isEmpty()) &&
Expand All @@ -263,6 +273,9 @@ QByteArray KPasswdServer::checkAuthInfo(const QByteArray &data, qlonglong window
} else {
info.setModified(false);
}
#else
info.setModified(false);
#endif
} else {
qCDebug(category) << "Found cached authentication for" << key;
updateAuthExpire(key, result, windowId, false);
Expand Down Expand Up @@ -306,6 +319,7 @@ qlonglong KPasswdServer::checkAuthInfoAsync(KIO::AuthInfo info, qlonglong window
const AuthInfoContainer *result = findAuthInfoItem(key, info);
if (!result || result->isCanceled)
{
#ifdef HAVE_KF5WALLET
if (!result &&
!m_walletDisabled &&
(info.username.isEmpty() || info.password.isEmpty()) &&
Expand All @@ -325,6 +339,9 @@ qlonglong KPasswdServer::checkAuthInfoAsync(KIO::AuthInfo info, qlonglong window
} else {
info.setModified(false);
}
#else
info.setModified(false);
#endif
} else {
// qCDebug(category) << "Found cached authentication for" << key;
updateAuthExpire(key, result, windowId, false);
Expand Down Expand Up @@ -426,6 +443,7 @@ KPasswdServer::addAuthInfo(const KIO::AuthInfo &info, qlonglong windowId)

m_seqNr++;

#ifdef HAVE_KF5WALLET
if (!m_walletDisabled && openWallet(windowId) && storeInWallet(m_wallet, key, info)) {
// Since storing the password in the wallet succeeded, make sure the
// password information is stored in memory only for the duration the
Expand All @@ -435,6 +453,7 @@ KPasswdServer::addAuthInfo(const KIO::AuthInfo &info, qlonglong windowId)
addAuthInfoItem(key, authToken, windowId, m_seqNr, false);
return;
}
#endif

addAuthInfoItem(key, info, windowId, m_seqNr, false);
}
Expand Down Expand Up @@ -478,6 +497,7 @@ KPasswdServer::removeAuthInfo(const QString& host, const QString& protocol, cons
}
}

#ifdef HAVE_KF5WALLET
bool
KPasswdServer::openWallet( qlonglong windowId )
{
Expand All @@ -490,6 +510,7 @@ KPasswdServer::openWallet( qlonglong windowId )
KWallet::Wallet::NetworkWallet(), (WId)(windowId));
return m_wallet != 0;
}
#endif

void
KPasswdServer::processRequest()
Expand Down Expand Up @@ -788,13 +809,13 @@ KPasswdServer::removeAuthForWindowId(qlonglong windowId)
void KPasswdServer::showPasswordDialog (KPasswdServer::Request* request)
{
KIO::AuthInfo &info = request->info;
const bool bypassCacheAndKWallet = info.getExtraField(AUTHINFO_EXTRAFIELD_BYPASS_CACHE_AND_KWALLET).toBool();

QString username = info.username;
QString password = info.password;
bool hasWalletData = false;
QMap<QString, QString> knownLogins;

#ifdef HAVE_KF5WALLET
const bool bypassCacheAndKWallet = info.getExtraField(AUTHINFO_EXTRAFIELD_BYPASS_CACHE_AND_KWALLET).toBool();
if ( !bypassCacheAndKWallet
&& ( username.isEmpty() || password.isEmpty() )
&& !m_walletDisabled
Expand All @@ -804,6 +825,7 @@ void KPasswdServer::showPasswordDialog (KPasswdServer::Request* request)
if ( openWallet( request->windowId ) )
hasWalletData = readFromWallet( m_wallet, request->key, info.realmValue, username, password, info.readOnly, knownLogins );
}
#endif

// assemble dialog-flags
KPasswordDialog::KPasswordDialogFlags dialogFlags;
Expand All @@ -827,10 +849,12 @@ void KPasswdServer::showPasswordDialog (KPasswdServer::Request* request)
dialogFlags |= KPasswordDialog::ShowUsernameLine;
}

#ifdef HAVE_KF5WALLET
// If wallet is not enabled and the caller explicitly requested for it,
// do not show the keep password checkbox.
if (info.keepPassword && KWallet::Wallet::isEnabled())
dialogFlags |= KPasswordDialog::ShowKeepPassword;
#endif

// instantiate dialog
#ifndef Q_WS_WIN
Expand Down Expand Up @@ -995,12 +1019,14 @@ void KPasswdServer::passwordDialogDone(int result)
updateCachedRequestKey(m_authWait, oldKey, request->key);
}

#ifdef HAVE_KF5WALLET
const bool skipAutoCaching = info.getExtraField(AUTHINFO_EXTRAFIELD_SKIP_CACHING_ON_QUERY).toBool();
if (!skipAutoCaching && info.keepPassword && openWallet(request->windowId)) {
if ( storeInWallet( m_wallet, request->key, info ) )
// password is in wallet, don't keep it in memory after window is closed
info.keepPassword = false;
}
#endif
addAuthInfoItem(request->key, info, request->windowId, m_seqNr, false);
}
info.setModified( true );
Expand Down
4 changes: 3 additions & 1 deletion src/kpasswdserver/kpasswdserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,10 @@ private Q_SLOTS:
void addAuthInfoItem(const QString &key, const KIO::AuthInfo &info, qlonglong windowId, qlonglong seqNr, bool canceled);
void copyAuthInfo(const AuthInfoContainer*, KIO::AuthInfo&);
void updateAuthExpire(const QString &key, const AuthInfoContainer *, qlonglong windowId, bool keep);
int findWalletEntry( const QMap<QString,QString>& map, const QString& username );

#ifdef HAVE_KF5WALLET
bool openWallet( qlonglong windowId );
#endif

bool hasPendingQuery(const QString &key, const KIO::AuthInfo &info);
void sendResponse (Request* request);
Expand Down

0 comments on commit 9861d5d

Please sign in to comment.