subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmpil...@apache.org
Subject svn commit: r1359680 - in /subversion/branches/master-passphrase/subversion: libsvn_subr/auth_store.c libsvn_subr/auth_store.h libsvn_subr/config_auth_store.c libsvn_subr/pathetic_auth_store.c tests/libsvn_subr/crypto-test.c
Date Tue, 10 Jul 2012 14:05:41 GMT
Author: cmpilato
Date: Tue Jul 10 14:05:41 2012
New Revision: 1359680

URL: http://svn.apache.org/viewvc?rev=1359680&view=rev
Log:
On the 'master-passphrase' branch, begin exploring the idea of
cleanly abstracting away authn storage from the provider logic.

* subversion/libsvn_subr/auth_store.h
  (svn_auth__store_cb_open_t, svn_auth__store_cb_close_t,
   svn_auth__store_cb_delete_t, svn_auth__store_cb_fetch_t,
   svn_auth__store_cb_store_t): New callback types.
  (svn_auth__store_create, svn_auth__store_set_baton,
   svn_auth__store_set_open, svn_auth__store_set_close,
   svn_auth__store_set_delete, svn_auth__store_set_fetch,
   svn_auth__store_set_store, svn_auth__store_fetch_creds,
   svn_auth__store_store_creds): New functions.
  (svn_auth__store_open, svn_auth__store_close, svn_auth__store_delete):
    Recycle these functions names for new uses.
  (svn_auth__pathetic_store_get, svn_auth__config_store_get): New functions.
 
* subversion/libsvn_subr/auth_store.c
  New file with implementations of the generic functions defined in
  auth_store.h.

* subversion/libsvn_subr/config_auth_store.c
  New file implementing the current runtime-config-based auth store.

* subversion/libsvn_subr/pathetic_auth_store.c
  Rework the contents of this file as an implementation of the generic
  auth store framework.

* subversion/tests/libsvn_subr/crypto-test.c
  (create_ephemeral_auth_store, test_auth_store_basic,
   test_auth_store_get_set): Update to the new auth store interfaces.

Added:
    subversion/branches/master-passphrase/subversion/libsvn_subr/auth_store.c   (with props)
    subversion/branches/master-passphrase/subversion/libsvn_subr/config_auth_store.c   (with
props)
Modified:
    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

Added: 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=1359680&view=auto
==============================================================================
--- subversion/branches/master-passphrase/subversion/libsvn_subr/auth_store.c (added)
+++ subversion/branches/master-passphrase/subversion/libsvn_subr/auth_store.c Tue Jul 10 14:05:41
2012
@@ -0,0 +1,177 @@
+/*
+ * auth_store.c: Generic authentication credential storage routines.
+ *
+ * ====================================================================
+ *    Licensed to the Apache Software Foundation (ASF) under one
+ *    or more contributor license agreements.  See the NOTICE file
+ *    distributed with this work for additional information
+ *    regarding copyright ownership.  The ASF licenses this file
+ *    to you under the Apache License, Version 2.0 (the
+ *    "License"); you may not use this file except in compliance
+ *    with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing,
+ *    software distributed under the License is distributed on an
+ *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *    KIND, either express or implied.  See the License for the
+ *    specific language governing permissions and limitations
+ *    under the License.
+ * ====================================================================
+ */
+
+#include "auth_store.h"
+
+struct svn_auth__store_t
+{
+  void *store_baton;
+  svn_boolean_t is_open;
+  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_error_t *
+svn_auth__store_create(svn_auth__store_t **auth_store,
+                       apr_pool_t *result_pool)
+{
+  *auth_store = apr_pcalloc(result_pool, sizeof(**auth_store));
+  return SVN_NO_ERROR;
+}
+
+
+svn_error_t *
+svn_auth__store_set_baton(svn_auth__store_t *auth_store,
+                          void *priv_baton)
+{
+  auth_store->store_baton = priv_baton;
+  return SVN_NO_ERROR;
+}
+
+
+svn_error_t *
+svn_auth__store_set_open(svn_auth__store_t *auth_store,
+                         svn_auth__store_cb_open_t func)
+{
+  auth_store->open_func = func;
+  return SVN_NO_ERROR;
+}
+
+
+svn_error_t *
+svn_auth__store_set_close(svn_auth__store_t *auth_store,
+                          svn_auth__store_cb_close_t func)
+{
+  auth_store->close_func = func;
+  return SVN_NO_ERROR;
+}
+
+
+svn_error_t *
+svn_auth__store_set_delete(svn_auth__store_t *auth_store,
+                           svn_auth__store_cb_delete_t func)
+{
+  auth_store->delete_func = func;
+  return SVN_NO_ERROR;
+}
+
+
+svn_error_t *
+svn_auth__store_set_fetch(svn_auth__store_t *auth_store,
+                          svn_auth__store_cb_fetch_t func)
+{
+  auth_store->fetch_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)
+{
+  auth_store->store_func = func;
+  return SVN_NO_ERROR;
+}
+
+
+svn_error_t *
+svn_auth__store_open(svn_auth__store_t *auth_store,
+                     svn_boolean_t create,
+                     apr_pool_t *scratch_pool)
+{
+  SVN_ERR_ASSERT(! auth_store->is_open);
+  if (auth_store->open_func)
+    {
+      SVN_ERR(auth_store->open_func(auth_store->store_baton, create,
+                                    scratch_pool));
+      auth_store->is_open = TRUE;
+    }
+  else
+    {
+      return svn_error_create(SVN_ERR_UNSUPPORTED_FEATURE, NULL, NULL);
+    }
+  return SVN_NO_ERROR;
+}
+                     
+
+svn_error_t *
+svn_auth__store_close(svn_auth__store_t *auth_store,
+                      apr_pool_t *scratch_pool)
+{
+  SVN_ERR_ASSERT(auth_store->is_open);
+  if (auth_store->close_func)
+    SVN_ERR(auth_store->close_func(auth_store->store_baton, scratch_pool));
+  return SVN_NO_ERROR;
+}
+
+
+svn_error_t *
+svn_auth__store_delete(svn_auth__store_t *auth_store,
+                       apr_pool_t *scratch_pool)
+{
+  SVN_ERR_ASSERT(! auth_store->is_open);
+  if (auth_store->delete_func)
+    SVN_ERR(auth_store->delete_func(auth_store->store_baton, scratch_pool));
+  else
+    return svn_error_create(SVN_ERR_UNSUPPORTED_FEATURE, NULL, NULL);
+  return SVN_NO_ERROR;
+}
+
+
+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_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));
+  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_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));
+  return SVN_NO_ERROR;
+}

Propchange: subversion/branches/master-passphrase/subversion/libsvn_subr/auth_store.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: subversion/branches/master-passphrase/subversion/libsvn_subr/auth_store.c
------------------------------------------------------------------------------
    svn:mime-type = text/x-csrc

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=1359680&r1=1359679&r2=1359680&view=diff
==============================================================================
--- subversion/branches/master-passphrase/subversion/libsvn_subr/auth_store.h (original)
+++ subversion/branches/master-passphrase/subversion/libsvn_subr/auth_store.h Tue Jul 10 14:05:41
2012
@@ -33,14 +33,127 @@
 extern "C" {
 #endif /* __cplusplus */
 
-
-/* Opaque encrypted authentication credential store object. */
+/* Authentication credential store object. */
 typedef struct svn_auth__store_t svn_auth__store_t;
 
+/* Callback type: Open (creating if necessary and if CREATE is TRUE)
+   an authentication store. */
+typedef svn_error_t *(*svn_auth__store_cb_open_t)(
+  void *baton,
+  svn_boolean_t create,
+  apr_pool_t *scratch_pool);
+
+/* Callback type: Close an authentication store. */
+typedef svn_error_t *(*svn_auth__store_cb_close_t)(
+  void *baton,
+  apr_pool_t *scratch_pool);
+
+/* Callback type: Delete an authentication store. */
+typedef svn_error_t *(*svn_auth__store_cb_delete_t)(
+  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, 
+  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)(
+  svn_boolean_t *stored, 
+  void *baton,
+  const char *cred_kind,
+  const char *realmstring,
+  const void *creds,
+  apr_pool_t *scratch_pool);
+
+
+/* Create a generic authentication store object. */
+svn_error_t *
+svn_auth__store_create(svn_auth__store_t **auth_store,
+                       apr_pool_t *result_pool);
+
+/* Set the private context baton for AUTH_STORE to PRIV_BATON. */
+svn_error_t *
+svn_auth__store_set_baton(svn_auth__store_t *auth_store,
+                          void *priv_baton);
+
+/* Set the `open' callback function for AUTH_STORE to FUNC. */
+svn_error_t *
+svn_auth__store_set_open(svn_auth__store_t *auth_store,
+                         svn_auth__store_cb_open_t func);
+
+/* Set the `close' callback function for AUTH_STORE to FUNC. */
+svn_error_t *
+svn_auth__store_set_close(svn_auth__store_t *auth_store,
+                          svn_auth__store_cb_close_t func);
+
+/* Set the `delete' callback function for AUTH_STORE to FUNC. */
+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. */
+svn_error_t *
+svn_auth__store_set_fetch(svn_auth__store_t *auth_store,
+                          svn_auth__store_cb_fetch_t func);
+
+/* Set the `store' 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);
+
+
+/* Open (creating if necessary and if CREATE is set) the
+   authentication credential store identified by AUTH_STORE. */
+svn_error_t *
+svn_auth__store_open(svn_auth__store_t *auth_store,
+                     svn_boolean_t create,
+                     apr_pool_t *scratch_pool);
+                     
+/* Close the auth store represented by AUTH_STORE. */
+svn_error_t *
+svn_auth__store_close(svn_auth__store_t *auth_store,
+                      apr_pool_t *scratch_pool);
+
+
+/* Delete the on-disk auth store represented by AUTH_STORE. */
+svn_error_t *
+svn_auth__store_delete(svn_auth__store_t *auth_store,
+                       apr_pool_t *scratch_pool);
 
-/* Open (creating if necessary and if CREATE is set) an encrypted
-   authentication credential store at AUTH_STORE_PATH, and set
-   *AUTH_STORE_P to the object which describes it.
+/* 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 *AUTH_STORE_P to an object which describes the encrypted
+   authentication credential store located at AUTH_STORE_PATH.
 
    CRYPTO_CTX is the cryptographic context which the store will use
    for related functionality.
@@ -51,27 +164,28 @@ typedef struct svn_auth__store_t svn_aut
    it is validated against the passphrase self-checking information in
    the store itself.  SVN_ERR_AUTHN_FAILED will be returned if SECRET
    does not validate against an existing store's checktext.
+
+   ### TODO:  This is expected to be experimental code! ###
 */
 svn_error_t *
-svn_auth__store_open(svn_auth__store_t **auth_store_p,
-                     const char *auth_store_path,
-                     svn_crypto__ctx_t *crypto_ctx,
-                     const svn_string_t *secret,
-                     svn_boolean_t create,
-                     apr_pool_t *result_pool,
-                     apr_pool_t *scratch_pool);
-
-
-/* Close the auth store represented by AUTH_STORE. */
+svn_auth__pathetic_store_get(svn_auth__store_t **auth_store_p,
+                             const char *auth_store_path,
+                             svn_crypto__ctx_t *crypto_ctx,
+                             const svn_string_t *secret,
+                             apr_pool_t *result_pool,
+                             apr_pool_t *scratch_pool);
+
+/* Set *AUTH_STORE_P to an object which describes the
+   runtime-config-based authentication credential store located at
+   AUTH_STORE_PATH.  CFG is the configuration object with which the
+   store is associated.
+*/
 svn_error_t *
-svn_auth__store_close(svn_auth__store_t *auth_store,
-                      apr_pool_t *scratch_pool);
-
+svn_auth__config_store_get(svn_auth__store_t **auth_store_p,
+                           const svn_config_t *cfg,
+                           apr_pool_t *result_pool,
+                           apr_pool_t *scratch_pool);
 
-/* Close the on-disk auth store represented by AUTH_STORE. */
-svn_error_t *
-svn_auth__store_delete(const char *auth_store_path,
-                       apr_pool_t *scratch_pool);
 
 
 /* Set *CREDS_P to the "username" credentials from AUTH_STORE which

Added: subversion/branches/master-passphrase/subversion/libsvn_subr/config_auth_store.c
URL: http://svn.apache.org/viewvc/subversion/branches/master-passphrase/subversion/libsvn_subr/config_auth_store.c?rev=1359680&view=auto
==============================================================================
--- subversion/branches/master-passphrase/subversion/libsvn_subr/config_auth_store.c (added)
+++ subversion/branches/master-passphrase/subversion/libsvn_subr/config_auth_store.c Tue Jul
10 14:05:41 2012
@@ -0,0 +1,160 @@
+/*
+ * config_auth_store.c: Implementation of an runtime-config auth store.
+ *
+ * ====================================================================
+ *    Licensed to the Apache Software Foundation (ASF) under one
+ *    or more contributor license agreements.  See the NOTICE file
+ *    distributed with this work for additional information
+ *    regarding copyright ownership.  The ASF licenses this file
+ *    to you under the Apache License, Version 2.0 (the
+ *    "License"); you may not use this file except in compliance
+ *    with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing,
+ *    software distributed under the License is distributed on an
+ *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *    KIND, either express or implied.  See the License for the
+ *    specific language governing permissions and limitations
+ *    under the License.
+ * ====================================================================
+ */
+
+#include "svn_dirent_uri.h"
+#include "svn_hash.h"
+#include "svn_io.h"
+#include "svn_auth.h"
+#include "svn_base64.h"
+#include "private/svn_skel.h"
+
+#include "auth_store.h"
+#include "config_impl.h"
+
+#include "svn_private_config.h"
+
+
+/*** svn_auth__store_t Callback Functions ***/
+
+/* Implements svn_auth__store_cb_open_t. */
+static svn_error_t *
+config_store_open(void *baton,
+                  svn_boolean_t create,
+                  apr_pool_t *scratch_pool)
+{
+  const svn_config_t *cfg = baton;
+  return SVN_NO_ERROR;
+}
+
+/* Implements pathetic_store_fetch_t. */
+static svn_error_t *
+config_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)
+{
+  const char *config_dir = baton;
+  apr_hash_t *cred_hash;
+
+  SVN_ERR(svn_config_read_auth_data(&cred_hash, cred_kind, realmstring,
+                                    config_dir, 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. */
+static svn_error_t *
+config_store_store(svn_boolean_t *stored,
+                   void *baton,
+                   const char *cred_kind,
+                   const char *realmstring,
+                   const void *generic_creds,
+                   apr_pool_t *scratch_pool)
+{
+  const const *config_dir = 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(svn_config_write_auth_data(cred_hash, cred_kind, realmstring,
+                                         config_dir, scratch_pool));
+      *stored = TRUE;
+    }
+    
+  return SVN_NO_ERROR;
+}
+
+
+
+/*** Semi-public APIs ***/
+
+svn_error_t *
+svn_auth__config_store_get(svn_auth__store_t **auth_store_p,
+                           const char *config_dir,
+                           apr_pool_t *result_pool,
+                           apr_pool_t *scratch_pool)
+{
+  svn_auth__store_t *auth_store;
+
+  SVN_ERR(svn_auth__store_create(&auth_store, result_pool));
+  SVN_ERR(svn_auth__store_set_baton(auth_store, config_dir));
+  SVN_ERR(svn_auth__store_set_open(auth_store, pathetic_store_open));
+  SVN_ERR(svn_auth__store_set_fetch(auth_store, pathetic_store_fetch));
+  SVN_ERR(svn_auth__store_set_store(auth_store, pathetic_store_store));
+
+  *auth_store_p = auth_store;
+
+  return SVN_NO_ERROR;
+}
+
+

Propchange: subversion/branches/master-passphrase/subversion/libsvn_subr/config_auth_store.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: subversion/branches/master-passphrase/subversion/libsvn_subr/config_auth_store.c
------------------------------------------------------------------------------
    svn:mime-type = text/x-csrc

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=1359680&r1=1359679&r2=1359680&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 Tue
Jul 10 14:05:41 2012
@@ -55,7 +55,7 @@
 
 
 
-struct svn_auth__store_t
+typedef struct pathetic_auth_store_baton_t
 {
   /* On-disk path of this store. */
   const char *path;
@@ -63,8 +63,7 @@ struct svn_auth__store_t
   /* Cryptographic context. */
   svn_crypto__ctx_t *crypto_ctx;
 
-  /* Crypto secret (may be NULL if not yet provided, which will also
-     serve as our indication that the store hasn't yet been read). */
+  /* Crypto secret (may be NULL if not yet provided). */
   const svn_string_t *secret;
 
   /* Skel containing checktext bits: (CIPHERTEXT, IV, SALT,
@@ -80,13 +79,13 @@ struct svn_auth__store_t
   /* Pool for holding all this fun stuff. */
   apr_pool_t *pool;
 
-};
+} pathetic_auth_store_baton_t;
 
 
 /* Parse the contents of the auth store file represented by
    AUTH_STORE.  */
 static svn_error_t *
-read_auth_store(svn_auth__store_t *auth_store,
+read_auth_store(pathetic_auth_store_baton_t *auth_store,
                 apr_pool_t *scratch_pool)
 {
   svn_error_t *err;
@@ -150,7 +149,7 @@ read_auth_store(svn_auth__store_t *auth_
    location.  If there's no appropriate on-disk location to flush to
    (because there's no configuration directory provided), do nothing.  */
 static svn_error_t *
-write_auth_store(svn_auth__store_t *auth_store,
+write_auth_store(pathetic_auth_store_baton_t *auth_store,
                  apr_pool_t *scratch_pool)
 {
   apr_file_t *authfile = NULL;
@@ -205,7 +204,7 @@ write_auth_store(svn_auth__store_t *auth
 /* Create a pathetic auth store file at the path registered with
    the AUTH_STORE object.  */
 static svn_error_t *
-create_auth_store(svn_auth__store_t *auth_store,
+create_auth_store(pathetic_auth_store_baton_t *auth_store,
                   apr_pool_t *scratch_pool)
 {
   const svn_string_t *ciphertext, *iv, *salt;
@@ -241,7 +240,7 @@ create_auth_store(svn_auth__store_t *aut
 /* ### TODO: document  */
 static svn_error_t *
 get_cred_hash(apr_hash_t **cred_hash,
-              svn_auth__store_t *auth_store,
+              struct pathetic_auth_store_baton_t *auth_store,
               const char *cred_kind_string,
               const char *realmstring,
               apr_pool_t *result_pool,
@@ -293,7 +292,7 @@ get_cred_hash(apr_hash_t **cred_hash,
 
 /* ### TODO: document  */
 static svn_error_t *
-set_cred_hash(svn_auth__store_t *auth_store,
+set_cred_hash(struct pathetic_auth_store_baton_t *auth_store,
               const char *cred_kind_string,
               const char *realmstring,
               apr_hash_t *cred_hash,
@@ -339,32 +338,19 @@ set_cred_hash(svn_auth__store_t *auth_st
 }
 
 
-/*** Semi-public APIs ***/
+/*** svn_auth__store_t Callback Functions ***/
 
-svn_error_t *
-svn_auth__store_open(svn_auth__store_t **auth_store_p,
-                     const char *auth_store_path,
-                     svn_crypto__ctx_t *crypto_ctx,
-                     const svn_string_t *secret,
-                     svn_boolean_t create,
-                     apr_pool_t *result_pool,
-                     apr_pool_t *scratch_pool)
+/* Implements svn_auth__store_cb_open_t. */
+static svn_error_t *
+pathetic_store_open(void *baton,
+                    svn_boolean_t create,
+                    apr_pool_t *scratch_pool)
 {
-  svn_auth__store_t *auth_store;
+  pathetic_auth_store_baton_t *auth_store = baton;
   svn_error_t *err;
   svn_skel_t *cipher_skel, *iv_skel, *salt_skel, *check_skel;
   svn_boolean_t valid_secret;
 
-  if (! svn_crypto__is_available())
-    return svn_error_create(SVN_ERR_UNSUPPORTED_FEATURE, NULL,
-                            _("Encrypted auth store feature not available"));
-
-  auth_store = apr_pcalloc(result_pool, sizeof(*auth_store));
-  auth_store->pool = result_pool;
-  auth_store->path = apr_pstrdup(result_pool, auth_store_path);
-  auth_store->crypto_ctx = crypto_ctx;
-  auth_store->secret = svn_string_dup(secret, result_pool);
-
   err = read_auth_store(auth_store, scratch_pool);
   if (err)
     {
@@ -373,7 +359,6 @@ svn_auth__store_open(svn_auth__store_t *
           if (create)
             {
               svn_error_clear(err);
-              *auth_store_p = auth_store;
               return svn_error_trace(create_auth_store(auth_store,
                                                        scratch_pool));
             }
@@ -412,27 +397,18 @@ svn_auth__store_open(svn_auth__store_t *
   if (! valid_secret)
     return svn_error_create(SVN_ERR_AUTHN_FAILED, NULL, _("Invalid secret"));
 
-  *auth_store_p = auth_store;
-
   return SVN_NO_ERROR;
 }
 
-
-svn_error_t *
-svn_auth__store_close(svn_auth__store_t *auth_store,
+/* Implements pathetic_store_delete_t. */
+static svn_error_t *
+pathetic_store_delete(void *baton,
                       apr_pool_t *scratch_pool)
 {
-  return SVN_NO_ERROR;
-}
-
-
-svn_error_t *
-svn_auth__store_delete(const char *auth_store_path,
-                       apr_pool_t *scratch_pool)
-{
+  pathetic_auth_store_baton_t *auth_store = baton;
   svn_node_kind_t kind;
 
-  SVN_ERR(svn_io_check_path(auth_store_path, &kind, scratch_pool));
+  SVN_ERR(svn_io_check_path(auth_store->path, &kind, scratch_pool));
   if (kind == svn_node_none)
     return svn_error_create(SVN_ERR_NODE_NOT_FOUND, NULL,
                             _("Pathetic auth store not found"));
@@ -440,102 +416,134 @@ svn_auth__store_delete(const char *auth_
     return svn_error_create(SVN_ERR_NODE_UNEXPECTED_KIND, NULL,
                             _("Unexpected node kind for pathetic auth store"));
   
-  SVN_ERR(svn_io_remove_file2(auth_store_path, FALSE, scratch_pool));
+  SVN_ERR(svn_io_remove_file2(auth_store->path, FALSE, 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)
+/* Implements pathetic_store_fetch_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)
 {
-  svn_auth_cred_username_t *creds;
+  pathetic_auth_store_baton_t *auth_store = baton;
   apr_hash_t *cred_hash;
   const svn_string_t *prop;
 
-  *creds_p = NULL;
-
-  SVN_ERR(get_cred_hash(&cred_hash, auth_store, SVN_AUTH_CRED_USERNAME,
+  SVN_ERR(get_cred_hash(&cred_hash, auth_store, cred_kind,
                         realmstring, result_pool, scratch_pool));
   
-  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;
+  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. */
+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_auth_store_baton_t *auth_store = baton;
+  apr_hash_t *cred_hash = NULL;
 
-svn_error_t *
-svn_auth__store_set_username_creds(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->username)
-    apr_hash_set(cred_hash, "username", APR_HASH_KEY_STRING,
-                 svn_string_create(creds->username, scratch_pool));
+  *stored = FALSE;
 
-  SVN_ERR(set_cred_hash(auth_store, SVN_AUTH_CRED_USERNAME, realmstring,
-                        cred_hash, scratch_pool));
+  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;
+    }
+    
   return SVN_NO_ERROR;
 }
 
 
+
+/*** Semi-public APIs ***/
+
 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)
+svn_auth__pathetic_store_get(svn_auth__store_t **auth_store_p,
+                             const char *auth_store_path,
+                             svn_crypto__ctx_t *crypto_ctx,
+                             const svn_string_t *secret,
+                             apr_pool_t *result_pool,
+                             apr_pool_t *scratch_pool)
 {
-  svn_auth_cred_simple_t *creds;
-  apr_hash_t *cred_hash;
-  const svn_string_t *prop;
-
-  *creds_p = NULL;
+  svn_auth__store_t *auth_store;
+  pathetic_auth_store_baton_t *pathetic_store;
 
-  SVN_ERR(get_cred_hash(&cred_hash, auth_store, SVN_AUTH_CRED_SIMPLE,
-                        realmstring, result_pool, scratch_pool));
-  
-  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 = creds;
-  return SVN_NO_ERROR;
-}
+  if (! svn_crypto__is_available())
+    return svn_error_create(SVN_ERR_UNSUPPORTED_FEATURE, NULL,
+                            _("Encrypted auth store feature not available"));
 
+  pathetic_store = apr_pcalloc(result_pool, sizeof(*pathetic_store));
+  pathetic_store->pool = result_pool;
+  pathetic_store->path = apr_pstrdup(result_pool, auth_store_path);
+  pathetic_store->crypto_ctx = crypto_ctx;
+  pathetic_store->secret = svn_string_dup(secret, result_pool);
+
+  SVN_ERR(svn_auth__store_create(&auth_store, result_pool));
+  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_error_t *
-svn_auth__store_set_simple_creds(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->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));
+  *auth_store_p = auth_store;
 
-  SVN_ERR(set_cred_hash(auth_store, SVN_AUTH_CRED_SIMPLE, realmstring,
-                        cred_hash, scratch_pool));
   return SVN_NO_ERROR;
 }
 

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=1359680&r1=1359679&r2=1359680&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 Tue Jul
10 14:05:41 2012
@@ -78,9 +78,9 @@ encrypt_decrypt(svn_crypto__ctx_t *ctx,
 }
 
 
-/* Create an auth store within CONFIG_DIR, deleting any previous auth
-   store at that location, and using CRYPTO_CTX and the master
-   passphrase SECRET.  Set *AUTH_STORE_P to the resulting store
+/* Create and open an auth store within CONFIG_DIR, deleting any
+   previous auth store at that location, and using CRYPTO_CTX and the
+   master passphrase SECRET.  Set *AUTH_STORE_P to the resulting store
    object.  */
 static svn_error_t *
 create_ephemeral_auth_store(svn_auth__store_t **auth_store_p,
@@ -94,8 +94,9 @@ create_ephemeral_auth_store(svn_auth__st
                                      svn_io_file_del_on_pool_cleanup,
                                      pool, pool));
   SVN_ERR(svn_io_remove_file2(*auth_store_path, TRUE, pool));
-  SVN_ERR(svn_auth__store_open(auth_store_p, *auth_store_path, crypto_ctx,
-                               secret, TRUE, pool, pool));
+  SVN_ERR(svn_auth__pathetic_store_get(auth_store_p, *auth_store_path,
+                                       crypto_ctx, secret, pool, pool));
+  SVN_ERR(svn_auth__store_open(*auth_store_p, TRUE, pool));
   return SVN_NO_ERROR;
 }
 
@@ -217,13 +218,15 @@ test_auth_store_basic(apr_pool_t *pool)
 
   /* Close and reopen the auth store. */
   SVN_ERR(svn_auth__store_close(auth_store, pool));
-  SVN_ERR(svn_auth__store_open(&auth_store, auth_store_path, ctx,
-                               secret, FALSE, pool, pool));
+  SVN_ERR(svn_auth__pathetic_store_get(&auth_store, auth_store_path, ctx,
+                                       secret, pool, pool));
+  SVN_ERR(svn_auth__store_open(auth_store, FALSE, pool));
 
   /* Close and reopen the auth store with a bogus secret. */
   SVN_ERR(svn_auth__store_close(auth_store, pool));
-  err = svn_auth__store_open(&auth_store, auth_store_path, ctx,
-                             bad_secret, FALSE, pool, pool);
+  SVN_ERR(svn_auth__pathetic_store_get(&auth_store, auth_store_path, ctx,
+                                       bad_secret, pool, pool));
+  err = svn_auth__store_open(auth_store, FALSE, pool);
   if (! err)
     return svn_error_create(SVN_ERR_TEST_FAILED, NULL,
                             "Successfully opened auth store with the wrong "
@@ -276,24 +279,37 @@ test_auth_store_get_set(apr_pool_t *pool
   /* Store some simple and username creds. */
   for (i = 0; i < (sizeof(usernames) / sizeof(const char *)); i++)
     {
+      svn_boolean_t stored;
+
       svn_pool_clear(iterpool);
 
       realmstring = usernames[i]; /* not schema-jiving */
       username_creds = apr_pcalloc(iterpool, sizeof(*username_creds));
       username_creds->username = usernames[i];
-      SVN_ERR(svn_auth__store_set_username_creds(auth_store, realmstring,
-                                                 username_creds, iterpool));
+      SVN_ERR(svn_auth__store_store_creds(&stored, auth_store,
+                                          SVN_AUTH_CRED_USERNAME, realmstring,
+                                          username_creds, iterpool));
+      if (! stored)
+        return svn_error_create(SVN_ERR_TEST_FAILED, NULL,
+                                "Error storing username credentials");
+
     }
   for (i = 0; i < (sizeof(usernames) / sizeof(const char *)); i++)
     {
+      svn_boolean_t stored;
+
       svn_pool_clear(iterpool);
 
       realmstring = usernames[i]; /* not schema-jiving */
       simple_creds = apr_pcalloc(iterpool, sizeof(*simple_creds));
       simple_creds->username = usernames[i];
       simple_creds->password = passwords[i];
-      SVN_ERR(svn_auth__store_set_simple_creds(auth_store, realmstring,
-                                               simple_creds, iterpool));
+      SVN_ERR(svn_auth__store_store_creds(&stored, auth_store,
+                                          SVN_AUTH_CRED_SIMPLE, realmstring,
+                                          simple_creds, iterpool));
+      if (! stored)
+        return svn_error_create(SVN_ERR_TEST_FAILED, NULL,
+                                "Error storing simple credentials");
     }
 
   svn_pool_destroy(iterpool);



Mime
View raw message