subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r894053 - in /subversion/trunk/subversion/libsvn_ra_serf: auth.c ra_serf.h serf.c util.c
Date Sun, 27 Dec 2009 10:57:41 GMT
Author: lgo
Date: Sun Dec 27 10:57:39 2009
New Revision: 894053

URL: http://svn.apache.org/viewvc?rev=894053&view=rev
Log:
ra_serf: Use the new serf API for serf-based authentication. Remove support for
Basic authentication, as serf will handle that now.

Requires serf r1289 (when building svn with serf trunk).

* subversion/libsvn_ra_serf/ra_serf.h
  (svn_ra_serf__credentials_callback): New declaration.

* subversion/libsvn_ra_serf/serf.c
  (load_config): Load list of enabled authentication types. Define credentials
   callback for serf. TODO: define enabled authn types for serf.

* subversion/libsvn_ra_serf/auth.c
  (serf_auth_protocols): Disable Basic authentication in ra_serf as serf will 
   handle it now.

* subversion/libsvn_ra_serf/util.c
  (svn_ra_serf__credentials_callback): New function, provides credentials for 
   Basic and Digest authentication to serf.

Modified:
    subversion/trunk/subversion/libsvn_ra_serf/auth.c
    subversion/trunk/subversion/libsvn_ra_serf/ra_serf.h
    subversion/trunk/subversion/libsvn_ra_serf/serf.c
    subversion/trunk/subversion/libsvn_ra_serf/util.c

Modified: subversion/trunk/subversion/libsvn_ra_serf/auth.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_ra_serf/auth.c?rev=894053&r1=894052&r2=894053&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_ra_serf/auth.c (original)
+++ subversion/trunk/subversion/libsvn_ra_serf/auth.c Sun Dec 27 10:57:39 2009
@@ -33,6 +33,7 @@
 
 /*** Forward declarations. ***/
 
+#if ! SERF_VERSION_AT_LEAST(0, 4, 0)
 static svn_error_t *
 handle_basic_auth(svn_ra_serf__handler_t *ctx,
                   serf_request_t *request,
@@ -51,6 +52,7 @@
                          const char *method,
                          const char *uri,
                          serf_bucket_t *hdrs_bkt);
+#endif
 
 static svn_error_t *
 handle_proxy_basic_auth(svn_ra_serf__handler_t *ctx,
@@ -82,6 +84,8 @@
 
 /*** Global variables. ***/
 static const svn_ra_serf__auth_protocol_t serf_auth_protocols[] = {
+#if ! SERF_VERSION_AT_LEAST(0, 4, 0)
+  /* serf handles Basic authentication. */
   {
     401,
     "Basic",
@@ -91,6 +95,7 @@
     setup_request_basic_auth,
     default_auth_response_handler,
   },
+#endif
   {
     407,
     "Basic",
@@ -356,6 +361,7 @@
   return SVN_NO_ERROR;
 }
 
+#if ! SERF_VERSION_AT_LEAST(0, 4, 0)
 static svn_error_t *
 handle_basic_auth(svn_ra_serf__handler_t *ctx,
                   serf_request_t *request,
@@ -496,6 +502,7 @@
 
   return SVN_NO_ERROR;
 }
+#endif
 
 static svn_error_t *
 handle_proxy_basic_auth(svn_ra_serf__handler_t *ctx,

Modified: subversion/trunk/subversion/libsvn_ra_serf/ra_serf.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_ra_serf/ra_serf.h?rev=894053&r1=894052&r2=894053&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_ra_serf/ra_serf.h (original)
+++ subversion/trunk/subversion/libsvn_ra_serf/ra_serf.h Sun Dec 27 10:57:39 2009
@@ -1402,6 +1402,16 @@
 /*** Authentication handler declarations ***/
 
 /**
+ * Callback function that loads the credentials for Basic and Digest
+ * authentications, both for server and proxy authentication.
+ */
+apr_status_t
+svn_ra_serf__credentials_callback(char **username, char **password,
+                                  serf_request_t *request, void *baton,
+                                  int code, const char *authn_type,
+                                  const char *realm,
+                                  apr_pool_t *pool);
+/**
  * For each authentication protocol we need a handler function of type
  * svn_serf__auth_handler_func_t. This function will be called when an
  * authentication challenge is received in a session.

Modified: subversion/trunk/subversion/libsvn_ra_serf/serf.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_ra_serf/serf.c?rev=894053&r1=894052&r2=894053&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_ra_serf/serf.c (original)
+++ subversion/trunk/subversion/libsvn_ra_serf/serf.c Sun Dec 27 10:57:39 2009
@@ -303,9 +303,13 @@
   else
     session->using_proxy = FALSE;
 
-  /* Load the list of support authn types. */
-   SVN_ERR(load_http_auth_types(pool, config, server_group,
-           &session->authn_types));
+  /* Setup authentication. */
+  SVN_ERR(load_http_auth_types(pool, config, server_group,
+                               &session->authn_types));
+  /* TODO: convert string authn types to SERF_AUTHN bitmask.
+     serf_config_authn_types(session->context, session->authn_types);*/
+  serf_config_credentials_callback(session->context,
+                                   svn_ra_serf__credentials_callback);
 
   return SVN_NO_ERROR;
 }

Modified: subversion/trunk/subversion/libsvn_ra_serf/util.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_ra_serf/util.c?rev=894053&r1=894052&r2=894053&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_ra_serf/util.c (original)
+++ subversion/trunk/subversion/libsvn_ra_serf/util.c Sun Dec 27 10:57:39 2009
@@ -1171,6 +1171,74 @@
   return server_err.error;
 }
 
+apr_status_t
+svn_ra_serf__credentials_callback(char **username, char **password,
+                                  serf_request_t *request, void *baton,
+                                  int code, const char *authn_type,
+                                  const char *realm,
+                                  apr_pool_t *pool)
+{
+  svn_ra_serf__handler_t *ctx = baton;
+  svn_ra_serf__session_t *session = ctx->session;
+  void *creds;
+  svn_auth_cred_simple_t *simple_creds;
+  svn_error_t *err;
+
+  if (code == 401)
+    {
+      /* Use svn_auth_first_credentials if this is the first time we ask for
+         credentials during this session OR if the last time we asked
+         session->auth_state wasn't set (eg. if the credentials provider was
+         cancelled by the user). */
+      if (!session->auth_state)
+        {
+          err = svn_auth_first_credentials(&creds,
+                                           &session->auth_state,
+                                           SVN_AUTH_CRED_SIMPLE,
+                                           realm,
+                                           session->wc_callbacks->auth_baton,
+                                           session->pool);
+        }
+      else
+        {
+          err = svn_auth_next_credentials(&creds,
+                                          session->auth_state,
+                                          session->pool);
+        }
+
+      if (err)
+        {
+          ctx->session->pending_error = err;
+          return err->apr_err;
+        }
+
+      session->auth_attempts++;
+
+      if (!creds || session->auth_attempts > 4)
+        {
+          /* No more credentials. */
+          ctx->session->pending_error =
+            svn_error_create(SVN_ERR_AUTHN_FAILED, NULL,
+                             "No more credentials or we tried too many times.\n"
+                             "Authentication failed");
+          return SVN_ERR_AUTHN_FAILED;
+        }
+
+      simple_creds = creds;
+      *username = apr_pstrdup(pool, simple_creds->username);
+      *password = apr_pstrdup(pool, simple_creds->password);
+    }
+  else
+    {
+      *username = apr_pstrdup(pool, session->proxy_username);
+      *password = apr_pstrdup(pool, session->proxy_password);
+    }
+
+  ctx->conn->last_status_code = code;
+
+  return APR_SUCCESS;
+}
+
 /* Implements the serf_response_handler_t interface.  Wait for HTTP
    response status and headers, and invoke CTX->response_handler() to
    carry out operation-specific processing.  Afterwards, check for



Mime
View raw message