26
26
#include "svn_dirent_uri.h"
27
27
#include "svn_hash.h"
28
28
#include "svn_io.h"
29
#include "svn_pools.h"
30
30
#include "config_impl.h"
32
34
#include "svn_private_config.h"
36
#include "private/svn_auth_private.h"
34
38
/* Helper for svn_config_{read|write}_auth_data. Return a path to a
35
39
file within ~/.subversion/auth/ that holds CRED_KIND credentials
36
40
within REALMSTRING. If no path is available *PATH will be set to
39
auth_file_path(const char **path,
40
const char *cred_kind,
41
const char *realmstring,
42
const char *config_dir,
43
svn_auth__file_path(const char **path,
44
const char *cred_kind,
45
const char *realmstring,
46
const char *config_dir,
45
49
const char *authdir_path, *hexname;
46
50
svn_checksum_t *checksum;
118
122
svn_stream_t *stream;
119
123
const char *auth_path;
121
SVN_ERR(auth_file_path(&auth_path, cred_kind, realmstring, config_dir,
125
SVN_ERR(svn_auth__file_path(&auth_path, cred_kind, realmstring, config_dir,
124
128
return svn_error_create(SVN_ERR_NO_AUTH_FILE_PATH, NULL,
125
129
_("Unable to locate auth file"));
127
131
/* Add the realmstring to the hash, so programs (or users) can
128
132
verify exactly which set of credentials this file holds. */
129
apr_hash_set(hash, SVN_CONFIG_REALMSTRING_KEY, APR_HASH_KEY_STRING,
130
svn_string_create(realmstring, pool));
133
svn_hash_sets(hash, SVN_CONFIG_REALMSTRING_KEY,
134
svn_string_create(realmstring, pool));
132
136
SVN_ERR_W(svn_io_file_open(&authfile, auth_path,
133
137
(APR_WRITE | APR_CREATE | APR_TRUNCATE
145
149
/* To be nice, remove the realmstring from the hash again, just in
146
150
case the caller wants their hash unchanged. */
147
apr_hash_set(hash, SVN_CONFIG_REALMSTRING_KEY, APR_HASH_KEY_STRING, NULL);
151
svn_hash_sets(hash, SVN_CONFIG_REALMSTRING_KEY, NULL);
158
svn_config_walk_auth_data(const char *config_dir,
159
svn_config_auth_walk_func_t walk_func,
161
apr_pool_t *scratch_pool)
164
apr_pool_t *iterpool;
165
svn_boolean_t finished = FALSE;
166
const char *cred_kinds[] =
168
SVN_AUTH_CRED_SIMPLE,
169
SVN_AUTH_CRED_USERNAME,
170
SVN_AUTH_CRED_SSL_CLIENT_CERT,
171
SVN_AUTH_CRED_SSL_CLIENT_CERT_PW,
172
SVN_AUTH_CRED_SSL_SERVER_TRUST,
176
iterpool = svn_pool_create(scratch_pool);
177
for (i = 0; cred_kinds[i]; i++)
179
const char *item_path;
180
const char *dir_path;
183
apr_pool_t *itempool;
184
apr_hash_index_t *hi;
186
svn_pool_clear(iterpool);
191
SVN_ERR(svn_auth__file_path(&item_path, cred_kinds[i], "!", config_dir,
194
dir_path = svn_dirent_dirname(item_path, iterpool);
196
err = svn_io_get_dirents3(&nodes, dir_path, TRUE, iterpool, iterpool);
199
if (!APR_STATUS_IS_ENOENT(err->apr_err)
200
&& !SVN__APR_STATUS_IS_ENOTDIR(err->apr_err))
201
return svn_error_trace(err);
203
svn_error_clear(err);
207
itempool = svn_pool_create(iterpool);
208
for (hi = apr_hash_first(iterpool, nodes); hi; hi = apr_hash_next(hi))
210
svn_io_dirent2_t *dirent = svn__apr_hash_index_val(hi);
211
svn_stream_t *stream;
212
apr_hash_t *creds_hash;
213
const svn_string_t *realm;
214
svn_boolean_t delete_file = FALSE;
219
if (dirent->kind != svn_node_file)
222
svn_pool_clear(itempool);
224
item_path = svn_dirent_join(dir_path, svn__apr_hash_index_key(hi),
227
err = svn_stream_open_readonly(&stream, item_path,
231
/* Ignore this file. There are no credentials in it anyway */
232
svn_error_clear(err);
236
creds_hash = apr_hash_make(itempool);
237
err = svn_hash_read2(creds_hash, stream,
238
SVN_HASH_TERMINATOR, itempool);
239
err = svn_error_compose_create(err, svn_stream_close(stream));
242
/* Ignore this file. There are no credentials in it anyway */
243
svn_error_clear(err);
247
realm = svn_hash_gets(creds_hash, SVN_CONFIG_REALMSTRING_KEY);
249
continue; /* Not an auth file */
251
err = walk_func(&delete_file, walk_baton, cred_kinds[i],
252
realm->data, creds_hash, itempool);
253
if (err && err->apr_err == SVN_ERR_CEASE_INVOCATION)
255
svn_error_clear(err);
263
/* Delete the file on disk */
264
SVN_ERR(svn_io_remove_file2(item_path, TRUE, itempool));
269
svn_pool_destroy(iterpool);
149
270
return SVN_NO_ERROR;