Return-Path: Delivered-To: apmail-subversion-commits-archive@minotaur.apache.org Received: (qmail 6234 invoked from network); 27 Dec 2009 10:58:06 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 27 Dec 2009 10:58:06 -0000 Received: (qmail 81433 invoked by uid 500); 27 Dec 2009 10:58:06 -0000 Delivered-To: apmail-subversion-commits-archive@subversion.apache.org Received: (qmail 81381 invoked by uid 500); 27 Dec 2009 10:58:06 -0000 Mailing-List: contact commits-help@subversion.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@subversion.apache.org, commits@subversion.apache.org Delivered-To: mailing list commits@subversion.apache.org Received: (qmail 81373 invoked by uid 99); 27 Dec 2009 10:58:05 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 27 Dec 2009 10:58:05 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 27 Dec 2009 10:58:03 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 415D623889B8; Sun, 27 Dec 2009 10:57:42 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@subversion.apache.org From: lgo@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20091227105742.415D623889B8@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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