You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by cm...@apache.org on 2012/07/11 18:39:39 UTC
svn commit: r1360284 - in /subversion/branches/master-passphrase/subversion:
libsvn_subr/auth_store.c libsvn_subr/auth_store.h
libsvn_subr/pathetic_auth_store.c tests/libsvn_subr/crypto-test.c
Author: cmpilato
Date: Wed Jul 11 16:39:39 2012
New Revision: 1360284
URL: http://svn.apache.org/viewvc?rev=1360284&view=rev
Log:
On the 'master-passphrase' branch: Further genericize the generic auth
storage interfaces to use credential hashes rather than specific
credential structures as their currency. This may revert in the
future, but for now it's necessary -- we currently store stuff in the
~/.subversion/auth/ area that isn't carried in the credential
structures (e.g., the "ascii_cert" bits).
* subversion/libsvn_subr/auth_store.h
(svn_auth__store_cb_get_cred_hash_t, svn_auth__store_cb_set_cred_hash_t):
Were svn_auth__store_cb_fetch_t and svn_auth__store_cb_store_t,
respectively. Now use hashes instead of void * pointers for their
primary currency.
(svn_auth__store_set_get_cred_hash, svn_auth__store_set_set_cred_hash):
Were svn_auth__store_set_fetch and svn_auth__store_set_store,
respectively.
(svn_auth__store_get_cred_hash, svn_auth__store_set_cred_hash): Were
svn_auth__store_fetch_creds and svn_auth__store_store_creds,
respectively. Now use hashes instead of void * pointers for their
primary currency.
(svn_auth__store_set_username_creds, svn_auth__store_set_simple_creds):
Add 'stored' return parameter.
* subversion/libsvn_subr/auth_store.c
(struct svn_auth__store_t): Update callback types/names per changes in
auth_store.h.
(svn_auth__store_set_get_cred_hash, svn_auth__store_set_set_cred_hash,
svn_auth__store_get_cred_hash, svn_auth__store_set_cred_hash):
Rework per the changes in the APIs.
(svn_auth__store_get_username_creds, svn_auth__store_set_username_creds,
svn_auth__store_get_simple_creds, svn_auth__store_set_simple_creds):
Implement these functions as utility wrappers.
* subversion/libsvn_subr/pathetic_auth_store.c
(svn_auth__pathetic_store_get): Update calls to modified APIs.
(pathetic_store_get_cred_hash, pathetic_store_set_cred_hash): Track
API changes.
* subversion/tests/libsvn_subr/crypto-test.c
(test_auth_store_get_set): Use svn_auth__store_set_username_creds()
instead of svn_auth__store_store_creds().
Modified:
subversion/branches/master-passphrase/subversion/libsvn_subr/auth_store.c
subversion/branches/master-passphrase/subversion/libsvn_subr/auth_store.h
subversion/branches/master-passphrase/subversion/libsvn_subr/pathetic_auth_store.c
subversion/branches/master-passphrase/subversion/tests/libsvn_subr/crypto-test.c
Modified: subversion/branches/master-passphrase/subversion/libsvn_subr/auth_store.c
URL: http://svn.apache.org/viewvc/subversion/branches/master-passphrase/subversion/libsvn_subr/auth_store.c?rev=1360284&r1=1360283&r2=1360284&view=diff
==============================================================================
--- subversion/branches/master-passphrase/subversion/libsvn_subr/auth_store.c (original)
+++ subversion/branches/master-passphrase/subversion/libsvn_subr/auth_store.c Wed Jul 11 16:39:39 2012
@@ -30,8 +30,8 @@ struct svn_auth__store_t
svn_auth__store_cb_open_t open_func;
svn_auth__store_cb_close_t close_func;
svn_auth__store_cb_delete_t delete_func;
- svn_auth__store_cb_fetch_t fetch_func;
- svn_auth__store_cb_store_t store_func;
+ svn_auth__store_cb_get_cred_hash_t get_cred_hash_func;
+ svn_auth__store_cb_set_cred_hash_t set_cred_hash_func;
};
@@ -82,19 +82,19 @@ svn_auth__store_set_delete(svn_auth__sto
svn_error_t *
-svn_auth__store_set_fetch(svn_auth__store_t *auth_store,
- svn_auth__store_cb_fetch_t func)
+svn_auth__store_set_get_cred_hash(svn_auth__store_t *auth_store,
+ svn_auth__store_cb_get_cred_hash_t func)
{
- auth_store->fetch_func = func;
+ auth_store->get_cred_hash_func = func;
return SVN_NO_ERROR;
}
svn_error_t *
-svn_auth__store_set_store(svn_auth__store_t *auth_store,
- svn_auth__store_cb_store_t func)
+svn_auth__store_set_set_cred_hash(svn_auth__store_t *auth_store,
+ svn_auth__store_cb_set_cred_hash_t func)
{
- auth_store->store_func = func;
+ auth_store->set_cred_hash_func = func;
return SVN_NO_ERROR;
}
@@ -144,34 +144,147 @@ svn_auth__store_delete(svn_auth__store_t
svn_error_t *
-svn_auth__store_fetch_creds(const void **creds,
- svn_auth__store_t *auth_store,
- const char *cred_kind,
- const char *realmstring,
- apr_pool_t *result_pool,
- apr_pool_t *scratch_pool)
+svn_auth__store_get_cred_hash(apr_hash_t **cred_hash,
+ svn_auth__store_t *auth_store,
+ const char *cred_kind,
+ const char *realmstring,
+ apr_pool_t *result_pool,
+ apr_pool_t *scratch_pool)
{
SVN_ERR_ASSERT(auth_store->is_open);
- *creds = NULL;
- if (auth_store->fetch_func)
- SVN_ERR(auth_store->fetch_func(creds, auth_store->store_baton, cred_kind,
- realmstring, result_pool, scratch_pool));
+ *cred_hash = NULL;
+ if (auth_store->get_cred_hash_func)
+ SVN_ERR(auth_store->get_cred_hash_func(cred_hash, auth_store->store_baton,
+ cred_kind, realmstring,
+ result_pool, scratch_pool));
return SVN_NO_ERROR;
}
svn_error_t *
-svn_auth__store_store_creds(svn_boolean_t *stored,
- svn_auth__store_t *auth_store,
- const char *cred_kind,
- const char *realmstring,
- const void *creds,
- apr_pool_t *scratch_pool)
+svn_auth__store_set_cred_hash(svn_boolean_t *stored,
+ svn_auth__store_t *auth_store,
+ const char *cred_kind,
+ const char *realmstring,
+ apr_hash_t *cred_hash,
+ apr_pool_t *scratch_pool)
{
SVN_ERR_ASSERT(auth_store->is_open);
*stored = FALSE;
- if (auth_store->store_func)
- SVN_ERR(auth_store->store_func(stored, auth_store->store_baton, cred_kind,
- realmstring, creds, scratch_pool));
+ if (auth_store->set_cred_hash_func)
+ SVN_ERR(auth_store->set_cred_hash_func(stored, auth_store->store_baton,
+ cred_kind, realmstring, cred_hash,
+ scratch_pool));
+ return SVN_NO_ERROR;
+}
+
+
+svn_error_t *
+svn_auth__store_get_username_creds(svn_auth_cred_username_t **creds_p,
+ svn_auth__store_t *auth_store,
+ const char *realmstring,
+ apr_pool_t *result_pool,
+ apr_pool_t *scratch_pool)
+{
+ apr_hash_t *cred_hash;
+
+ *creds_p = NULL;
+ SVN_ERR(svn_auth__store_get_cred_hash(&cred_hash, auth_store,
+ SVN_AUTH_CRED_USERNAME, realmstring,
+ result_pool, scratch_pool));
+ if (cred_hash)
+ {
+ const svn_string_t *prop;
+ svn_auth_cred_username_t *creds =
+ apr_pcalloc(result_pool, sizeof(*creds));
+
+ prop = apr_hash_get(cred_hash, "username", APR_HASH_KEY_STRING);
+ if (prop)
+ creds->username = prop->data;
+ *creds_p = creds;
+ }
+
+ return SVN_NO_ERROR;
+}
+
+
+svn_error_t *
+svn_auth__store_set_username_creds(svn_boolean_t *stored,
+ svn_auth__store_t *auth_store,
+ const char *realmstring,
+ svn_auth_cred_username_t *creds,
+ apr_pool_t *scratch_pool)
+{
+ apr_hash_t *cred_hash = apr_hash_make(scratch_pool);
+
+ if (creds)
+ {
+ if (creds->username)
+ apr_hash_set(cred_hash, "username", APR_HASH_KEY_STRING,
+ svn_string_create(creds->username, scratch_pool));
+ }
+
+ SVN_ERR(svn_auth__store_set_cred_hash(stored, auth_store,
+ SVN_AUTH_CRED_USERNAME, realmstring,
+ cred_hash, scratch_pool));
+ return SVN_NO_ERROR;
+}
+
+
+svn_error_t *
+svn_auth__store_get_simple_creds(svn_auth_cred_simple_t **creds_p,
+ svn_auth__store_t *auth_store,
+ const char *realmstring,
+ apr_pool_t *result_pool,
+ apr_pool_t *scratch_pool)
+{
+ apr_hash_t *cred_hash;
+
+ *creds_p = NULL;
+ SVN_ERR(svn_auth__store_get_cred_hash(&cred_hash, auth_store,
+ SVN_AUTH_CRED_SIMPLE, realmstring,
+ result_pool, scratch_pool));
+ if (cred_hash)
+ {
+ const svn_string_t *prop;
+ svn_auth_cred_simple_t *creds
+ = apr_pcalloc(result_pool, sizeof(*creds));
+
+ prop = apr_hash_get(cred_hash, "username", APR_HASH_KEY_STRING);
+ if (prop)
+ creds->username = prop->data;
+ prop = apr_hash_get(cred_hash, "password", APR_HASH_KEY_STRING);
+ if (prop)
+ creds->password = prop->data;
+ *creds_p = creds;
+ }
+
+ return SVN_NO_ERROR;
+}
+
+
+
+svn_error_t *
+svn_auth__store_set_simple_creds(svn_boolean_t *stored,
+ svn_auth__store_t *auth_store,
+ const char *realmstring,
+ svn_auth_cred_simple_t *creds,
+ apr_pool_t *scratch_pool)
+{
+ apr_hash_t *cred_hash = apr_hash_make(scratch_pool);
+
+ if (creds)
+ {
+ if (creds->username)
+ apr_hash_set(cred_hash, "username", APR_HASH_KEY_STRING,
+ svn_string_create(creds->username, scratch_pool));
+ if (creds->password)
+ apr_hash_set(cred_hash, "password", APR_HASH_KEY_STRING,
+ svn_string_create(creds->password, scratch_pool));
+ }
+
+ SVN_ERR(svn_auth__store_set_cred_hash(stored, auth_store,
+ SVN_AUTH_CRED_SIMPLE, realmstring,
+ cred_hash, scratch_pool));
return SVN_NO_ERROR;
}
Modified: subversion/branches/master-passphrase/subversion/libsvn_subr/auth_store.h
URL: http://svn.apache.org/viewvc/subversion/branches/master-passphrase/subversion/libsvn_subr/auth_store.h?rev=1360284&r1=1360283&r2=1360284&view=diff
==============================================================================
--- subversion/branches/master-passphrase/subversion/libsvn_subr/auth_store.h (original)
+++ subversion/branches/master-passphrase/subversion/libsvn_subr/auth_store.h Wed Jul 11 16:39:39 2012
@@ -53,26 +53,27 @@ typedef svn_error_t *(*svn_auth__store_c
void *baton,
apr_pool_t *scratch_pool);
-/* Callback type: Set CREDS to the set of credentials of kind
- CRED_KIND and identified by REALMSTRING from an authentication
- store. */
-typedef svn_error_t *(*svn_auth__store_cb_fetch_t)(
- const void **creds,
+/* Callback type: Set *CRED_HASH to a hash of authentication
+ credential bits for the credentials of kind CRED_KIND and
+ identified by REALMSTRING found in AUTH_STORE. */
+typedef svn_error_t *(*svn_auth__store_cb_get_cred_hash_t)(
+ apr_hash_t **cred_hash,
void *baton,
const char *cred_kind,
const char *realmstring,
apr_pool_t *result_pool,
apr_pool_t *scratch_pool);
-/* Callback type: Store CREDS as the set of credentials of kind
- CRED_KIND and identified by REALMSTRING in an authentication store,
- setting *STORED to TRUE iff the storage occurs successfully. */
-typedef svn_error_t *(*svn_auth__store_cb_store_t)(
+/* Callback type: Store in AUTH_STORE a hash of authentication
+ credential bits (CRED_HASH) for the credentials of kind CRED_KIND
+ and identified by REALMSTRING, setting *STORED to TRUE iff the
+ storage occurs successfully. */
+typedef svn_error_t *(*svn_auth__store_cb_set_cred_hash_t)(
svn_boolean_t *stored,
void *baton,
const char *cred_kind,
const char *realmstring,
- const void *creds,
+ apr_hash_t *cred_hash,
apr_pool_t *scratch_pool);
@@ -101,15 +102,15 @@ svn_error_t *
svn_auth__store_set_delete(svn_auth__store_t *auth_store,
svn_auth__store_cb_delete_t func);
-/* Set the `fetch' callback function for AUTH_STORE to FUNC. */
+/* Set the `get_cred_hash' callback function for AUTH_STORE to FUNC. */
svn_error_t *
-svn_auth__store_set_fetch(svn_auth__store_t *auth_store,
- svn_auth__store_cb_fetch_t func);
+svn_auth__store_set_get_cred_hash(svn_auth__store_t *auth_store,
+ svn_auth__store_cb_get_cred_hash_t func);
-/* Set the `store' callback function for AUTH_STORE to FUNC. */
+/* Set the `set_cred_hash' callback function for AUTH_STORE to FUNC. */
svn_error_t *
-svn_auth__store_set_store(svn_auth__store_t *auth_store,
- svn_auth__store_cb_store_t func);
+svn_auth__store_set_set_cred_hash(svn_auth__store_t *auth_store,
+ svn_auth__store_cb_set_cred_hash_t func);
/* Open (creating if necessary and if CREATE is set) the
@@ -130,26 +131,28 @@ svn_error_t *
svn_auth__store_delete(svn_auth__store_t *auth_store,
apr_pool_t *scratch_pool);
-/* Set *CREDS to the credentials of kind CRED_KIND and identified by
- REALMSTRING found in AUTH_STORE. */
-svn_error_t *
-svn_auth__store_fetch_creds(const void **creds,
- svn_auth__store_t *auth_store,
- const char *cred_kind,
- const char *realmstring,
- apr_pool_t *result_pool,
- apr_pool_t *scratch_pool);
-
-/* Store CREDS as the credentials of kind CRED_KIND identified by
- REALMSTRING in AUTH_STORE, setting *STORED to TRUE iff the storage
- occurs successfully. */
-svn_error_t *
-svn_auth__store_store_creds(svn_boolean_t *stored,
- svn_auth__store_t *auth_store,
- const char *cred_kind,
- const char *realmstring,
- const void *creds,
- apr_pool_t *scratch_pool);
+/* Set *CRED_HASH to a hash of authentication credential bits for the
+ credentials of kind CRED_KIND and identified by REALMSTRING found
+ in AUTH_STORE. */
+svn_error_t *
+svn_auth__store_get_cred_hash(apr_hash_t **cred_hash,
+ svn_auth__store_t *auth_store,
+ const char *cred_kind,
+ const char *realmstring,
+ apr_pool_t *result_pool,
+ apr_pool_t *scratch_pool);
+
+/* Store in AUTH_STORE a hash of authentication credential bits
+ (CRED_HASH) for the credentials of kind CRED_KIND and identified by
+ REALMSTRING, setting *STORED to TRUE iff the storage occurs
+ successfully. */
+svn_error_t *
+svn_auth__store_set_cred_hash(svn_boolean_t *stored,
+ svn_auth__store_t *auth_store,
+ const char *cred_kind,
+ const char *realmstring,
+ apr_hash_t *cred_hash,
+ apr_pool_t *scratch_pool);
/* Set *AUTH_STORE_P to an object which describes the encrypted
@@ -202,12 +205,13 @@ svn_auth__store_get_username_creds(svn_a
/* Store CREDS as "username" credentials in AUTH_STORE, associated
- with REALMSTRING.
+ with REALMSTRING, setting *STORED iff the storage was successful.
NOTE: Only the 'username' member of CREDS will be stored.
*/
svn_error_t *
-svn_auth__store_set_username_creds(svn_auth__store_t *auth_store,
+svn_auth__store_set_username_creds(svn_boolean_t *stored,
+ svn_auth__store_t *auth_store,
const char *realmstring,
svn_auth_cred_username_t *creds,
apr_pool_t *scratch_pool);
@@ -228,13 +232,14 @@ svn_auth__store_get_simple_creds(svn_aut
/* Store CREDS as "simple" credentials in AUTH_STORE, associated with
- REALMSTRING.
+ REALMSTRING, setting *STORED iff the storage was successful.
NOTE: Only the 'username' and 'password' members of CREDS will be
stored.
*/
svn_error_t *
-svn_auth__store_set_simple_creds(svn_auth__store_t *auth_store,
+svn_auth__store_set_simple_creds(svn_boolean_t *stored,
+ svn_auth__store_t *auth_store,
const char *realmstring,
svn_auth_cred_simple_t *creds,
apr_pool_t *scratch_pool);
Modified: subversion/branches/master-passphrase/subversion/libsvn_subr/pathetic_auth_store.c
URL: http://svn.apache.org/viewvc/subversion/branches/master-passphrase/subversion/libsvn_subr/pathetic_auth_store.c?rev=1360284&r1=1360283&r2=1360284&view=diff
==============================================================================
--- subversion/branches/master-passphrase/subversion/libsvn_subr/pathetic_auth_store.c (original)
+++ subversion/branches/master-passphrase/subversion/libsvn_subr/pathetic_auth_store.c Wed Jul 11 16:39:39 2012
@@ -421,91 +421,36 @@ pathetic_store_delete(void *baton,
return SVN_NO_ERROR;
}
-/* Implements pathetic_store_fetch_t. */
+/* Implements pathetic_store_get_cred_hash_t. */
static svn_error_t *
-pathetic_store_fetch(const void **creds_p,
- void *baton,
- const char *cred_kind,
- const char *realmstring,
- apr_pool_t *result_pool,
- apr_pool_t *scratch_pool)
+pathetic_store_get_cred_hash(apr_hash_t **cred_hash,
+ void *baton,
+ const char *cred_kind,
+ const char *realmstring,
+ apr_pool_t *result_pool,
+ apr_pool_t *scratch_pool)
{
pathetic_auth_store_baton_t *auth_store = baton;
- apr_hash_t *cred_hash;
- const svn_string_t *prop;
- SVN_ERR(get_cred_hash(&cred_hash, auth_store, cred_kind,
+ SVN_ERR(get_cred_hash(cred_hash, auth_store, cred_kind,
realmstring, result_pool, scratch_pool));
-
- if (strcmp(cred_kind, SVN_AUTH_CRED_USERNAME) == 0)
- {
- svn_auth_cred_username_t *creds =
- apr_pcalloc(result_pool, sizeof(*creds));
- prop = apr_hash_get(cred_hash, "username", APR_HASH_KEY_STRING);
- if (prop)
- creds->username = prop->data;
- *creds_p = (const void *)creds;
- }
- else if (strcmp(cred_kind, SVN_AUTH_CRED_SIMPLE) == 0)
- {
- svn_auth_cred_simple_t *creds =
- apr_pcalloc(result_pool, sizeof(*creds));
- prop = apr_hash_get(cred_hash, "username", APR_HASH_KEY_STRING);
- if (prop)
- creds->username = prop->data;
- prop = apr_hash_get(cred_hash, "password", APR_HASH_KEY_STRING);
- if (prop)
- creds->username = prop->data;
- *creds_p = (const void *)creds;
- }
- else
- {
- *creds_p = NULL;
- }
-
return SVN_NO_ERROR;
}
-/* Implements pathetic_store_store_t. */
+/* Implements pathetic_store_set_cred_hash_t. */
static svn_error_t *
-pathetic_store_store(svn_boolean_t *stored,
- void *baton,
- const char *cred_kind,
- const char *realmstring,
- const void *generic_creds,
- apr_pool_t *scratch_pool)
+pathetic_store_set_cred_hash(svn_boolean_t *stored,
+ void *baton,
+ const char *cred_kind,
+ const char *realmstring,
+ apr_hash_t *cred_hash,
+ apr_pool_t *scratch_pool)
{
pathetic_auth_store_baton_t *auth_store = baton;
- apr_hash_t *cred_hash = NULL;
-
- *stored = FALSE;
- if (strcmp(cred_kind, SVN_AUTH_CRED_USERNAME) == 0)
- {
- const svn_auth_cred_username_t *creds = generic_creds;
- cred_hash = apr_hash_make(scratch_pool);
- if (creds->username)
- apr_hash_set(cred_hash, "username", APR_HASH_KEY_STRING,
- svn_string_create(creds->username, scratch_pool));
- }
- else if (strcmp(cred_kind, SVN_AUTH_CRED_SIMPLE) == 0)
- {
- const svn_auth_cred_simple_t *creds = generic_creds;
- cred_hash = apr_hash_make(scratch_pool);
- if (creds->username)
- apr_hash_set(cred_hash, "username", APR_HASH_KEY_STRING,
- svn_string_create(creds->username, scratch_pool));
- if (creds->password)
- apr_hash_set(cred_hash, "password", APR_HASH_KEY_STRING,
- svn_string_create(creds->password, scratch_pool));
- }
-
- if (cred_hash)
- {
- SVN_ERR(set_cred_hash(auth_store, cred_kind, realmstring,
- cred_hash, scratch_pool));
- *stored = TRUE;
- }
+ SVN_ERR(set_cred_hash(auth_store, cred_kind, realmstring,
+ cred_hash, scratch_pool));
+ *stored = TRUE;
return SVN_NO_ERROR;
}
@@ -539,8 +484,10 @@ svn_auth__pathetic_store_get(svn_auth__s
SVN_ERR(svn_auth__store_set_baton(auth_store, pathetic_store));
SVN_ERR(svn_auth__store_set_open(auth_store, pathetic_store_open));
SVN_ERR(svn_auth__store_set_delete(auth_store, pathetic_store_delete));
- SVN_ERR(svn_auth__store_set_fetch(auth_store, pathetic_store_fetch));
- SVN_ERR(svn_auth__store_set_store(auth_store, pathetic_store_store));
+ SVN_ERR(svn_auth__store_set_get_cred_hash(auth_store,
+ pathetic_store_get_cred_hash));
+ SVN_ERR(svn_auth__store_set_set_cred_hash(auth_store,
+ pathetic_store_set_cred_hash));
*auth_store_p = auth_store;
Modified: subversion/branches/master-passphrase/subversion/tests/libsvn_subr/crypto-test.c
URL: http://svn.apache.org/viewvc/subversion/branches/master-passphrase/subversion/tests/libsvn_subr/crypto-test.c?rev=1360284&r1=1360283&r2=1360284&view=diff
==============================================================================
--- subversion/branches/master-passphrase/subversion/tests/libsvn_subr/crypto-test.c (original)
+++ subversion/branches/master-passphrase/subversion/tests/libsvn_subr/crypto-test.c Wed Jul 11 16:39:39 2012
@@ -286,9 +286,9 @@ test_auth_store_get_set(apr_pool_t *pool
realmstring = usernames[i]; /* not schema-jiving */
username_creds = apr_pcalloc(iterpool, sizeof(*username_creds));
username_creds->username = usernames[i];
- SVN_ERR(svn_auth__store_store_creds(&stored, auth_store,
- SVN_AUTH_CRED_USERNAME, realmstring,
- username_creds, iterpool));
+ SVN_ERR(svn_auth__store_set_username_creds(&stored, auth_store,
+ realmstring, username_creds,
+ iterpool));
if (! stored)
return svn_error_create(SVN_ERR_TEST_FAILED, NULL,
"Error storing username credentials");
@@ -304,9 +304,9 @@ test_auth_store_get_set(apr_pool_t *pool
simple_creds = apr_pcalloc(iterpool, sizeof(*simple_creds));
simple_creds->username = usernames[i];
simple_creds->password = passwords[i];
- SVN_ERR(svn_auth__store_store_creds(&stored, auth_store,
- SVN_AUTH_CRED_SIMPLE, realmstring,
- simple_creds, iterpool));
+ SVN_ERR(svn_auth__store_set_simple_creds(&stored, auth_store,
+ realmstring, simple_creds,
+ iterpool));
if (! stored)
return svn_error_create(SVN_ERR_TEST_FAILED, NULL,
"Error storing simple credentials");