Index: subversion/libsvn_auth_kwallet/kwallet.cpp =================================================================== --- subversion/libsvn_auth_kwallet/kwallet.cpp (.../trunk) (revision 0) +++ subversion/libsvn_auth_kwallet/kwallet.cpp (.../branches/kwallet) (revision 31195) @@ -0,0 +1,220 @@ +/* + * kwallet.cpp: KWallet provider for SVN_AUTH_CRED_SIMPLE + * + * ==================================================================== + * Copyright (c) 2008 CollabNet. All rights reserved. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at http://subversion.tigris.org/license-1.html. + * If newer versions of this license are posted there, you may use a + * newer version instead, at your option. + * + * This software consists of voluntary contributions made by many + * individuals. For exact contribution history, see the revision + * history and logs, available at http://subversion.tigris.org/. + * ==================================================================== + */ + +/* ==================================================================== */ + + + +/*** Includes. ***/ + +#include +#include "svn_auth.h" +#include "svn_auth_kwallet.h" +#include "svn_error.h" +#include "svn_version.h" + +#include "private/svn_auth_private.h" + +#include "svn_private_config.h" + +#include +#include + +#include +#include +#include + +#define SVN_AUTH__KWALLET_PASSWORD_TYPE "kwallet" + +/*-----------------------------------------------------------------------*/ +/* KWallet simple provider, puts passwords in KWallet */ +/*-----------------------------------------------------------------------*/ + +/* Implementation of svn_auth__password_get_t that retrieves + the password from KWallet. */ +static svn_boolean_t +kwallet_password_get(const char **password, + apr_hash_t *creds, + const char *realmstring, + const char *username, + svn_boolean_t non_interactive, + apr_pool_t *pool) +{ + if (non_interactive) + { + return FALSE; + } + + if (! KWallet::Wallet::isEnabled()) + { + return FALSE; + } + + KCmdLineArgs::init(1, + (char *[1]) { "svn" }, + "Subversion", + "subversion", + ki18n("Subversion"), + SVN_VER_NUMBER, + ki18n("Version control system"), + KCmdLineArgs::CmdLineArgKDE); + KApplication application; + QWidget widget; + WId wid = widget.winId(); + svn_boolean_t ret = FALSE; + QString wallet_name = KWallet::Wallet::NetworkWallet(); + QString folder = QString::fromUtf8("Subversion"); + QString key = QString::fromUtf8(username) + "@" + QString::fromUtf8(realmstring); + if (! KWallet::Wallet::keyDoesNotExist(wallet_name, folder, key)) + { + KWallet::Wallet *wallet = KWallet::Wallet::openWallet(wallet_name, wid, KWallet::Wallet::Synchronous); + if (wallet) + { + if (wallet->hasFolder(folder)) + { + if (wallet->setFolder(folder)) + { + QString q_password; + if (wallet->readPassword(key, q_password) == 0); + { + *password = apr_pstrmemdup(pool, q_password.toUtf8().data(), q_password.size()); + ret = TRUE; + } + } + } + } + } + KWallet::Wallet::closeWallet(wallet_name, false); + return ret; +} + +/* Implementation of svn_auth__password_set_t that stores + the password in KWallet. */ +static svn_boolean_t +kwallet_password_set(apr_hash_t *creds, + const char *realmstring, + const char *username, + const char *password, + svn_boolean_t non_interactive, + apr_pool_t *pool) +{ + if (non_interactive) + { + return FALSE; + } + + if (! KWallet::Wallet::isEnabled()) + { + return FALSE; + } + + KCmdLineArgs::init(1, + (char *[1]) { "svn" }, + "Subversion", + "subversion", + ki18n("Subversion"), + SVN_VER_NUMBER, + ki18n("Version control system"), + KCmdLineArgs::CmdLineArgKDE); + KApplication application; + QWidget widget; + WId wid = widget.winId(); + svn_boolean_t ret = FALSE; + QString q_password = QString::fromUtf8(password); + QString wallet_name = KWallet::Wallet::NetworkWallet(); + QString folder = QString::fromUtf8("Subversion"); + KWallet::Wallet *wallet = KWallet::Wallet::openWallet(wallet_name, wid, KWallet::Wallet::Synchronous); + if (wallet) + { + if (! wallet->hasFolder(folder)) + { + wallet->createFolder(folder); + } + if (wallet->hasFolder(folder)) + { + if (wallet->setFolder(folder)) + { + QString key = QString::fromUtf8(username) + "@" + QString::fromUtf8(realmstring); + if (wallet->writePassword(key, q_password) == 0) + { + ret = TRUE; + } + } + } + } + KWallet::Wallet::closeWallet(wallet_name, false); + return ret; +} + +/* Get cached encrypted credentials from the simple provider's cache. */ +static svn_error_t * +kwallet_simple_first_creds(void **credentials, + void **iter_baton, + void *provider_baton, + apr_hash_t *parameters, + const char *realmstring, + apr_pool_t *pool) +{ + return svn_auth__simple_first_creds_helper(credentials, + iter_baton, + provider_baton, + parameters, + realmstring, + kwallet_password_get, + SVN_AUTH__KWALLET_PASSWORD_TYPE, + pool); +} + +/* Save encrypted credentials to the simple provider's cache. */ +static svn_error_t * +kwallet_simple_save_creds(svn_boolean_t *saved, + void *credentials, + void *provider_baton, + apr_hash_t *parameters, + const char *realmstring, + apr_pool_t *pool) +{ + return svn_auth__simple_save_creds_helper(saved, credentials, + provider_baton, + parameters, + realmstring, + kwallet_password_set, + SVN_AUTH__KWALLET_PASSWORD_TYPE, + pool); +} + +static const svn_auth_provider_t kwallet_simple_provider = { + SVN_AUTH_CRED_SIMPLE, + kwallet_simple_first_creds, + NULL, + kwallet_simple_save_creds +}; + +/* Public API */ +extern "C" { +void +svn_auth_get_kwallet_simple_provider(svn_auth_provider_object_t **provider, + apr_pool_t *pool) +{ + svn_auth_provider_object_t *po = + static_cast (apr_pcalloc(pool, sizeof(*po))); + + po->vtable = &kwallet_simple_provider; + *provider = po; +} +} Property changes on: subversion/libsvn_auth_kwallet/kwallet.cpp ___________________________________________________________________ Added: svn:mergeinfo Merged /trunk/subversion/libsvn_subr/simple_providers_cpp.cpp:r30711-31067 Merged /branches/svnserve-logging/subversion/libsvn_subr/simple_providers_cpp.cpp:r29754-30819 Merged /branches/1.5.x-r30215/subversion/libsvn_subr/simple_providers_cpp.cpp:r30238 Merged /branches/dont-save-plaintext-passwords-by-default/subversion/libsvn_subr/simple_providers_cpp.cpp:r30654-31044 Merged /branches/log-g-performance/subversion/libsvn_subr/simple_providers_cpp.cpp:r30867-30958 Merged /branches/svn-mergeinfo-enhancements/subversion/libsvn_subr/simple_providers_cpp.cpp:r30045-30214 Merged /branches/diff-callbacks3/subversion/libsvn_subr/simple_providers_cpp.cpp:r29985-30687 Added: svn:eol-style + native Property changes on: subversion/libsvn_auth_kwallet ___________________________________________________________________ Added: svn:ignore + Debug Release *.lo *.la .libs *.o *~ .*~ libsvn_auth_kwallet.def