static svn_error_t * test_platform_specific_auth_providers(apr_pool_t *pool) { apr_array_header_t *providers; svn_auth_provider_object_t *provider; int number_of_providers = 0; /* Test non-available auth provider */ SVN_ERR(svn_auth_get_platform_specific_provider(&provider, "fake", "fake", pool)); if (provider) return svn_error_createf (SVN_ERR_TEST_FAILED, NULL, "svn_auth_get_platform_specific_provider('fake', 'fake') should " \ "return NULL"); /* Make sure you get appropriate number of providers when retrieving all auth providers */ SVN_ERR(svn_auth_get_platform_specific_client_providers(&providers, NULL, pool)); #ifdef SVN_HAVE_GNOME_KEYRING number_of_providers += 2; #endif #ifdef SVN_HAVE_KWALLET number_of_providers += 2; #endif #ifdef SVN_HAVE_KEYCHAIN_SERVICES number_of_providers += 2; #endif #if defined(WIN32) && !defined(__MINGW32__) number_of_providers += 2; #endif if (providers->nelts != number_of_providers) return svn_error_createf (SVN_ERR_TEST_FAILED, NULL, "svn_auth_get_platform_specific_client_providers should return " \ "an array of %d providers", number_of_providers); /* Test Keychain auth providers */ #ifdef SVN_HAVE_KEYCHAIN_SERVICES svn_auth_get_platform_specific_provider(&provider, "keychain", "simple", pool); if (!provider) return svn_error_createf (SVN_ERR_TEST_FAILED, NULL, "svn_auth_get_platform_specific_provider('keychain', 'simple') " "should not return NULL"); svn_auth_get_platform_specific_provider(&provider, "keychain", "ssl_client_cert_pw", pool); if (!provider) return svn_error_createf (SVN_ERR_TEST_FAILED, NULL, "svn_auth_get_platform_specific_provider('keychain', " \ "'ssl_client_cert_pw') should not return NULL"); /* Make sure you do not get a Windows auth provider */ svn_auth_get_platform_specific_provider(&provider, "windows", "simple", pool); if (provider) return svn_error_createf (SVN_ERR_TEST_FAILED, NULL, "svn_auth_get_platform_specific_provider('windows', 'simple') should " \ "return NULL"); #endif /* Test Windows auth providers */ #if defined(WIN32) && !defined(__MINGW32__) svn_auth_get_platform_specific_provider(&provider, "windows", "simple", pool); if (!provider) return svn_error_createf (SVN_ERR_TEST_FAILED, NULL, "svn_auth_get_platform_specific_provider('windows', 'simple') " "should not return NULL"); svn_auth_get_platform_specific_provider(&provider, "windows", "ssl_client_cert_pw", pool); if (!provider) return svn_error_createf (SVN_ERR_TEST_FAILED, NULL, "svn_auth_get_platform_specific_provider('windows', " "'ssl_client_cert_pw') should not return NULL"); svn_auth_get_platform_specific_provider(&provider, "windows", "ssl_server_trust", pool); if (!provider) return svn_error_createf (SVN_ERR_TEST_FAILED, NULL, "svn_auth_get_platform_specific_provider('windows', " "'ssl_server_trust') should not return NULL"); /* Make sure you do not get a Keychain auth provider */ svn_auth_get_platform_specific_provider(&provider, "keychain", "simple", pool); if (provider) return svn_error_createf (SVN_ERR_TEST_FAILED, NULL, "svn_auth_get_platform_specific_provider('keychain', 'simple') should " \ "return NULL"); #endif /* Test GNOME Keyring auth providers */ #ifdef SVN_HAVE_GNOME_KEYRING svn_auth_get_platform_specific_provider(&provider, "gnome_keyring", "simple", pool); if (!provider) return svn_error_createf (SVN_ERR_TEST_FAILED, NULL, "svn_auth_get_platform_specific_provider('gnome_keyring', 'simple') " "should not return NULL"); svn_auth_get_platform_specific_provider(&provider, "gnome_keyring", "ssl_client_cert_pw", pool); if (!provider) return svn_error_createf (SVN_ERR_TEST_FAILED, NULL, "svn_auth_get_platform_specific_provider('gnome_keyring', " \ "'ssl_client_cert_pw') should not return NULL"); /* Make sure you do not get a Windows auth provider */ svn_auth_get_platform_specific_provider(&provider, "windows", "simple", pool); if (provider) return svn_error_createf (SVN_ERR_TEST_FAILED, NULL, "svn_auth_get_platform_specific_provider('windows', 'simple') should " \ "return NULL"); #endif /* Test KWallet auth providers */ #ifdef SVN_HAVE_KWALLET svn_auth_get_platform_specific_provider(&provider, "kwallet", "simple", pool); if (!provider) return svn_error_createf (SVN_ERR_TEST_FAILED, NULL, "svn_auth_get_platform_specific_provider('kwallet', 'simple') " "should not return NULL"); svn_auth_get_platform_specific_provider(&provider, "kwallet", "ssl_client_cert_pw", pool); if (!provider) return svn_error_createf (SVN_ERR_TEST_FAILED, NULL, "svn_auth_get_platform_specific_provider('kwallet', " \ "'ssl_client_cert_pw') should not return NULL"); /* Make sure you do not get a Windows auth provider */ svn_auth_get_platform_specific_provider(&provider, "windows", "simple", pool); if (provider) return svn_error_createf (SVN_ERR_TEST_FAILED, NULL, "svn_auth_get_platform_specific_provider('windows', 'simple') should " \ "return NULL"); #endif return SVN_NO_ERROR; }
svn_client_ctx_t * ClientContext::getContext(CommitMessage *message, SVN::Pool &in_pool) { apr_pool_t *pool = in_pool.getPool(); svn_auth_baton_t *ab; svn_client_ctx_t *ctx = m_context; /* Make a temporary copy of ctx to restore at pool cleanup to avoid leaving references to dangling pointers. Note that this allows creating a stack of context changes if the function is invoked multiple times with different pools. */ clearctx_baton_t *bt = (clearctx_baton_t *)apr_pcalloc(pool, sizeof(*bt)); bt->ctx = ctx; bt->backup = (svn_client_ctx_t*)apr_pmemdup(pool, ctx, sizeof(*ctx)); apr_pool_cleanup_register(in_pool.getPool(), bt, clear_ctx_ptrs, clear_ctx_ptrs); if (!ctx->config) { const char *configDir = m_configDir.c_str(); if (m_configDir.empty()) configDir = NULL; SVN_JNI_ERR(svn_config_get_config(&(ctx->config), configDir, m_pool->getPool()), NULL); bt->backup->config = ctx->config; } svn_config_t *config = (svn_config_t *) apr_hash_get(ctx->config, SVN_CONFIG_CATEGORY_CONFIG, APR_HASH_KEY_STRING); /* The whole list of registered providers */ apr_array_header_t *providers; /* Populate the registered providers with the platform-specific providers */ SVN_JNI_ERR(svn_auth_get_platform_specific_client_providers(&providers, config, pool), NULL); /* Use the prompter (if available) to prompt for password and cert * caching. */ svn_auth_plaintext_prompt_func_t plaintext_prompt_func = NULL; void *plaintext_prompt_baton = NULL; svn_auth_plaintext_passphrase_prompt_func_t plaintext_passphrase_prompt_func; void *plaintext_passphrase_prompt_baton = NULL; if (m_prompter != NULL) { plaintext_prompt_func = Prompter::plaintext_prompt; plaintext_prompt_baton = m_prompter; plaintext_passphrase_prompt_func = Prompter::plaintext_passphrase_prompt; plaintext_passphrase_prompt_baton = m_prompter; } /* The main disk-caching auth providers, for both * 'username/password' creds and 'username' creds. */ svn_auth_provider_object_t *provider; svn_auth_get_simple_provider2(&provider, plaintext_prompt_func, plaintext_prompt_baton, pool); APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider; svn_auth_get_username_provider(&provider, pool); APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider; /* The server-cert, client-cert, and client-cert-password providers. */ SVN_JNI_ERR(svn_auth_get_platform_specific_provider(&provider, "windows", "ssl_server_trust", pool), NULL); if (provider) APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider; svn_auth_get_ssl_server_trust_file_provider(&provider, pool); APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider; svn_auth_get_ssl_client_cert_file_provider(&provider, pool); APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider; svn_auth_get_ssl_client_cert_pw_file_provider2(&provider, plaintext_passphrase_prompt_func, plaintext_passphrase_prompt_baton, pool); APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider; if (m_prompter != NULL) { /* Two basic prompt providers: username/password, and just username.*/ provider = m_prompter->getProviderSimple(in_pool); APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider; provider = m_prompter->getProviderUsername(in_pool); APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider; /* Three ssl prompt providers, for server-certs, client-certs, * and client-cert-passphrases. */ provider = m_prompter->getProviderServerSSLTrust(in_pool); APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider; provider = m_prompter->getProviderClientSSL(in_pool); APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider; provider = m_prompter->getProviderClientSSLPassword(in_pool); APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider; } /* Build an authentication baton to give to libsvn_client. */ svn_auth_open(&ab, providers, pool); /* Place any default --username or --password credentials into the * auth_baton's run-time parameter hash. ### Same with --no-auth-cache? */ if (!m_userName.empty()) svn_auth_set_parameter(ab, SVN_AUTH_PARAM_DEFAULT_USERNAME, apr_pstrdup(in_pool.getPool(), m_userName.c_str())); if (!m_passWord.empty()) svn_auth_set_parameter(ab, SVN_AUTH_PARAM_DEFAULT_PASSWORD, apr_pstrdup(in_pool.getPool(), m_passWord.c_str())); /* Store where to retrieve authentication data? */ if (!m_configDir.empty()) svn_auth_set_parameter(ab, SVN_AUTH_PARAM_CONFIG_DIR, apr_pstrdup(in_pool.getPool(), m_configDir.c_str())); ctx->auth_baton = ab; ctx->log_msg_baton3 = message; m_cancelOperation = false; SVN_JNI_ERR(svn_wc_context_create(&ctx->wc_ctx, NULL, in_pool.getPool(), in_pool.getPool()), NULL); return ctx; }
void QSvn::init() { svn_error_t *err = nullptr; pool = svn_pool_create(nullptr); err = svn_fs_initialize(pool); if (err) { emit error(tr("Error calling svn_fs_initialize.")); return; } err = svn_config_ensure(nullptr, pool); if (err) { emit error(tr("Error calling svn_config_ensure.")); return; } err = svn_client_create_context(&ctx, pool); if (err) { emit error(tr("Error calling svn_client_create_context.")); return; } err = svn_config_get_config(&(ctx->config), nullptr, pool); if (err) { emit error(tr("Error calling svn_config_get_config.")); return; } ctx->log_msg_func3 = log_msg_func3; ctx->log_msg_baton3 = nullptr; ctx->notify_func2 = notify_func2; ctx->notify_baton2 = this; ctx->notify_func = nullptr; ctx->notify_baton = this; ctx->conflict_func = nullptr; ctx->conflict_baton = this; ctx->conflict_func2 = conflict_func2; ctx->conflict_baton2 = this; ctx->cancel_func = cancel_func; ctx->cancel_baton = this; ctx->progress_func = progress_func; ctx->progress_baton = this; ctx->client_name = "qsvn"; svn_auth_provider_object_t *provider; apr_array_header_t *providers = apr_array_make (pool, 3, sizeof (svn_auth_provider_object_t *)); svn_auth_get_platform_specific_client_providers (&providers, nullptr, pool); svn_auth_get_simple_prompt_provider (&provider, &svn_login_callback, this, /* baton */ 3, /* retry limit */ pool); APR_ARRAY_PUSH (providers, svn_auth_provider_object_t *) = provider; /* Register the auth-providers into the context's auth_baton. */ svn_auth_open (&ctx->auth_baton, providers, pool); }
svn_auth_baton_t * OperationContext::getAuthBaton(SVN::Pool &in_pool) { svn_auth_baton_t *ab; apr_pool_t *pool = in_pool.getPool(); apr_hash_t * configData = getConfigData(); if (configData == NULL) { return NULL; } svn_config_t *config = static_cast<svn_config_t *>(apr_hash_get(configData, SVN_CONFIG_CATEGORY_CONFIG, APR_HASH_KEY_STRING)); const bool use_native_store = GlobalConfig::useNativeCredentialsStore(); /* The whole list of registered providers */ apr_array_header_t *providers; svn_auth_provider_object_t *provider; if (use_native_store) { /* Populate the registered providers with the platform-specific providers */ SVN_JNI_ERR( svn_auth_get_platform_specific_client_providers( &providers, config, pool), NULL); /* Use the prompter (if available) to prompt for password and cert * caching. */ svn_auth_plaintext_prompt_func_t plaintext_prompt_func; void *plaintext_prompt_baton; svn_auth_plaintext_passphrase_prompt_func_t plaintext_passphrase_prompt_func; void *plaintext_passphrase_prompt_baton; if (m_prompter.get()) { plaintext_prompt_func = Prompter::plaintext_prompt; plaintext_prompt_baton = m_prompter.get(); plaintext_passphrase_prompt_func = Prompter::plaintext_passphrase_prompt; plaintext_passphrase_prompt_baton = m_prompter.get(); } else { plaintext_prompt_func = NULL; plaintext_prompt_baton = NULL; plaintext_passphrase_prompt_func = NULL; plaintext_passphrase_prompt_baton = NULL; } /* The main disk-caching auth providers, for both * 'username/password' creds and 'username' creds. */ svn_auth_get_simple_provider2(&provider, plaintext_prompt_func, plaintext_prompt_baton, pool); APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider; svn_auth_get_username_provider(&provider, pool); APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider; svn_auth_get_ssl_server_trust_file_provider(&provider, pool); APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider; svn_auth_get_ssl_client_cert_file_provider(&provider, pool); APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider; svn_auth_get_ssl_client_cert_pw_file_provider2( &provider, plaintext_passphrase_prompt_func, plaintext_passphrase_prompt_baton, pool); APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider; } else { // Not using hte native credentials store, start with an empty // providers array. providers = apr_array_make(pool, 0, sizeof(svn_auth_provider_object_t *)); } if (m_prompter.get()) { /* Two basic prompt providers: username/password, and just username.*/ provider = m_prompter->get_provider_simple(in_pool); APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider; provider = m_prompter->get_provider_username(in_pool); APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider; /* Three ssl prompt providers, for server-certs, client-certs, * and client-cert-passphrases. */ provider = m_prompter->get_provider_server_ssl_trust(in_pool); APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider; provider = m_prompter->get_provider_client_ssl(in_pool); APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider; provider = m_prompter->get_provider_client_ssl_password(in_pool); APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider; } /* Build an authentication baton to give to libsvn_client. */ svn_auth_open(&ab, providers, pool); /* Place any default --username or --password credentials into the * auth_baton's run-time parameter hash. ### Same with --no-auth-cache? */ if (!m_userName.empty()) svn_auth_set_parameter(ab, SVN_AUTH_PARAM_DEFAULT_USERNAME, apr_pstrdup(in_pool.getPool(), m_userName.c_str())); if (!m_passWord.empty()) svn_auth_set_parameter(ab, SVN_AUTH_PARAM_DEFAULT_PASSWORD, apr_pstrdup(in_pool.getPool(), m_passWord.c_str())); /* Store where to retrieve authentication data? */ if (!m_configDir.empty()) svn_auth_set_parameter(ab, SVN_AUTH_PARAM_CONFIG_DIR, apr_pstrdup(in_pool.getPool(), m_configDir.c_str())); return ab; }