Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(94)

Side by Side Diff: subversion/libsvn_auth_kwallet/kwallet.cpp

Issue 989: kwallet final branch SVN Base: http://svn.collab.net/repos/svn/trunk
Patch Set: Created 3 months, 3 weeks ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
Property Changes:
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
OLDNEW
(Empty)
1 /*
2 * kwallet.cpp: KWallet provider for SVN_AUTH_CRED_SIMPLE
3 *
4 * ====================================================================
5 * Copyright (c) 2008 CollabNet. All rights reserved.
6 *
7 * This software is licensed as described in the file COPYING, which
8 * you should have received as part of this distribution. The terms
9 * are also available at http://subversion.tigris.org/license-1.html.
10 * If newer versions of this license are posted there, you may use a
11 * newer version instead, at your option.
12 *
13 * This software consists of voluntary contributions made by many
14 * individuals. For exact contribution history, see the revision
15 * history and logs, available at http://subversion.tigris.org/.
16 * ====================================================================
17 */
18
19 /* ==================================================================== */
20
21
22
23 /*** Includes. ***/
24
25 #include <apr_pools.h>
26 #include "svn_auth.h"
27 #include "svn_auth_kwallet.h"
28 #include "svn_error.h"
29 #include "svn_version.h"
30
31 #include "private/svn_auth_private.h"
32
33 #include "svn_private_config.h"
34
35 #include <QtCore/QString>
36 #include <QtGui/QWidget>
37
38 #include <kapplication.h>
39 #include <kcmdlineargs.h>
40 #include <kwallet.h>
41
42 #define SVN_AUTH__KWALLET_PASSWORD_TYPE "kwallet"
43
44 /*-----------------------------------------------------------------------*/
45 /* KWallet simple provider, puts passwords in KWallet */
46 /*-----------------------------------------------------------------------*/
47
48 /* Implementation of svn_auth__password_get_t that retrieves
49 the password from KWallet. */
50 static svn_boolean_t
51 kwallet_password_get(const char **password,
52 apr_hash_t *creds,
53 const char *realmstring,
54 const char *username,
55 svn_boolean_t non_interactive,
56 apr_pool_t *pool)
57 {
58 if (non_interactive)
sussman 2008/05/15 15:14:41 This routine has a few 'if' blocks where the curly
59 {
60 return FALSE;
61 }
62
63 if (! KWallet::Wallet::isEnabled())
64 {
65 return FALSE;
66 }
67
68 KCmdLineArgs::init(1,
69 (char *[1]) { "svn" },
70 "Subversion",
71 "subversion",
72 ki18n("Subversion"),
73 SVN_VER_NUMBER,
74 ki18n("Version control system"),
75 KCmdLineArgs::CmdLineArgKDE);
76 KApplication application;
77 QWidget widget;
78 WId wid = widget.winId();
79 svn_boolean_t ret = FALSE;
80 QString wallet_name = KWallet::Wallet::NetworkWallet();
81 QString folder = QString::fromUtf8("Subversion");
82 QString key = QString::fromUtf8(username) + "@" + QString::fromUtf8(realmstrin g);
sussman 2008/05/15 15:14:41 Line is > 80 columns.
83 if (! KWallet::Wallet::keyDoesNotExist(wallet_name, folder, key))
84 {
85 KWallet::Wallet *wallet = KWallet::Wallet::openWallet(wallet_name, wid, KW allet::Wallet::Synchronous);
sussman 2008/05/15 15:14:41 Same here.
86 if (wallet)
87 {
88 if (wallet->hasFolder(folder))
89 {
90 if (wallet->setFolder(folder))
91 {
92 QString q_password;
93 if (wallet->readPassword(key, q_password) == 0);
94 {
95 *password = apr_pstrmemdup(pool, q_password.toUtf8().data( ), q_password.size());
sussman 2008/05/15 15:14:41 Same here.
96 ret = TRUE;
97 }
98 }
99 }
100 }
101 }
102 KWallet::Wallet::closeWallet(wallet_name, false);
103 return ret;
104 }
105
106 /* Implementation of svn_auth__password_set_t that stores
107 the password in KWallet. */
108 static svn_boolean_t
109 kwallet_password_set(apr_hash_t *creds,
110 const char *realmstring,
111 const char *username,
112 const char *password,
113 svn_boolean_t non_interactive,
114 apr_pool_t *pool)
115 {
116 if (non_interactive)
sussman 2008/05/15 15:14:41 This function also has curly-brace indentation pro
117 {
118 return FALSE;
119 }
120
121 if (! KWallet::Wallet::isEnabled())
122 {
123 return FALSE;
124 }
125
126 KCmdLineArgs::init(1,
127 (char *[1]) { "svn" },
128 "Subversion",
129 "subversion",
130 ki18n("Subversion"),
131 SVN_VER_NUMBER,
132 ki18n("Version control system"),
133 KCmdLineArgs::CmdLineArgKDE);
134 KApplication application;
135 QWidget widget;
136 WId wid = widget.winId();
137 svn_boolean_t ret = FALSE;
138 QString q_password = QString::fromUtf8(password);
139 QString wallet_name = KWallet::Wallet::NetworkWallet();
140 QString folder = QString::fromUtf8("Subversion");
141 KWallet::Wallet *wallet = KWallet::Wallet::openWallet(wallet_name, wid, KWalle t::Wallet::Synchronous);
sussman 2008/05/15 15:14:41 Line >80 columns.
142 if (wallet)
143 {
144 if (! wallet->hasFolder(folder))
145 {
146 wallet->createFolder(folder);
147 }
148 if (wallet->hasFolder(folder))
149 {
150 if (wallet->setFolder(folder))
151 {
152 QString key = QString::fromUtf8(username) + "@" + QString::fromUtf 8(realmstring);
sussman 2008/05/15 15:14:41 Same here.
153 if (wallet->writePassword(key, q_password) == 0)
154 {
155 ret = TRUE;
156 }
157 }
158 }
159 }
160 KWallet::Wallet::closeWallet(wallet_name, false);
161 return ret;
162 }
163
164 /* Get cached encrypted credentials from the simple provider's cache. */
165 static svn_error_t *
166 kwallet_simple_first_creds(void **credentials,
167 void **iter_baton,
168 void *provider_baton,
169 apr_hash_t *parameters,
170 const char *realmstring,
171 apr_pool_t *pool)
172 {
173 return svn_auth__simple_first_creds_helper(credentials,
174 iter_baton,
175 provider_baton,
176 parameters,
177 realmstring,
178 kwallet_password_get,
179 SVN_AUTH__KWALLET_PASSWORD_TYPE,
180 pool);
181 }
182
183 /* Save encrypted credentials to the simple provider's cache. */
184 static svn_error_t *
185 kwallet_simple_save_creds(svn_boolean_t *saved,
186 void *credentials,
187 void *provider_baton,
188 apr_hash_t *parameters,
189 const char *realmstring,
190 apr_pool_t *pool)
191 {
192 return svn_auth__simple_save_creds_helper(saved, credentials,
193 provider_baton,
194 parameters,
195 realmstring,
196 kwallet_password_set,
197 SVN_AUTH__KWALLET_PASSWORD_TYPE,
198 pool);
199 }
200
201 static const svn_auth_provider_t kwallet_simple_provider = {
202 SVN_AUTH_CRED_SIMPLE,
203 kwallet_simple_first_creds,
204 NULL,
205 kwallet_simple_save_creds
206 };
207
208 /* Public API */
209 extern "C" {
210 void
211 svn_auth_get_kwallet_simple_provider(svn_auth_provider_object_t **provider,
212 apr_pool_t *pool)
213 {
214 svn_auth_provider_object_t *po =
215 static_cast<svn_auth_provider_object_t *> (apr_pcalloc(pool, sizeof(*po)));
216
217 po->vtable = &kwallet_simple_provider;
218 *provider = po;
219 }
220 }
OLDNEW

Powered by Google App Engine
This is Rietveld r305