static svn_error_t * construct_auth_baton(svn_auth_baton_t **auth_baton_p, apr_pool_t *pool) { apr_array_header_t *providers; svn_auth_provider_object_t *simple_provider; svn_auth_baton_t *auth_baton; /* A bit of dancing just to pass jrandom:rayjandom. */ providers = apr_array_make(pool, 2, sizeof(svn_auth_provider_object_t *)), svn_auth_get_simple_prompt_provider(&simple_provider, aborting_simple_prompt_func, NULL, 0, pool); APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = simple_provider; svn_auth_get_username_prompt_provider(&simple_provider, aborting_username_prompt_func, NULL, 0, pool); APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = simple_provider; svn_auth_open(&auth_baton, providers, pool); svn_auth_set_parameter(auth_baton, SVN_AUTH_PARAM_DEFAULT_USERNAME, "jrandom"); svn_auth_set_parameter(auth_baton, SVN_AUTH_PARAM_DEFAULT_PASSWORD, "rayjandom"); *auth_baton_p = auth_baton; return SVN_NO_ERROR; }
JNIEXPORT void JNICALL Java_Subversion_openSession(JNIEnv * env, jobject obj, jstring repoURL) { svn_error_t * err; const char * repoURLC = (*env)->GetStringUTFChars(env, repoURL, 0); apr_initialize(); pool = svn_pool_create(0); if (!pool) abort(); err = svn_config_ensure(0, pool); if (err) barf(err); apr_hash_t * config; err = svn_config_get_config(&config, 0, pool); if (err) barf(err); /* Set up authentication info from the config files (copied from subversion/clients/cmdline/main.c). */ apr_array_header_t * providers = apr_array_make(pool, 10, sizeof (svn_auth_provider_object_t *)); svn_auth_provider_object_t * provider; svn_client_get_simple_provider(&provider, pool); APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider; svn_client_get_username_provider(&provider, pool); APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider; svn_client_get_ssl_server_trust_file_provider(&provider, pool); APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider; svn_client_get_ssl_client_cert_file_provider(&provider, pool); APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider; svn_client_get_ssl_client_cert_pw_file_provider(&provider, pool); APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider; /* Get the plugin that handles the protocol for `repoURL'. */ err = svn_ra_init_ra_libs(&ra_baton, pool); if (err) barf(err); err = svn_ra_get_ra_library(&ra_lib, ra_baton, repoURLC, pool); if (err) barf(err); memset(&callbacks, 0, sizeof callbacks); svn_auth_open(&callbacks.auth_baton, providers, pool); /* Open a session to `repoURL'. */ err = ra_lib->open(&ra_session, repoURLC, &callbacks, 0, config, pool); if (err) barf(err); (*env)->ReleaseStringUTFChars(env, repoURL, repoURLC); }
svn_error_t * nmap_update_svn_cmdline_setup_auth_baton(svn_auth_baton_t **ab, svn_boolean_t non_interactive, const char *auth_username, const char *auth_password, const char *config_dir, svn_boolean_t no_auth_cache, svn_config_t *cfg, svn_cancel_func_t cancel_func, void *cancel_baton, apr_pool_t *pool) { svn_boolean_t store_password_val = TRUE; svn_auth_provider_object_t *provider; /* The whole list of registered providers */ apr_array_header_t *providers = apr_array_make(pool, 12, sizeof(svn_auth_provider_object_t *)); /* The main disk-caching auth providers, for both 'username/password' creds and 'username' creds. */ #if defined(WIN32) && !defined(__MINGW32__) svn_auth_get_windows_simple_provider(&provider, pool); APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider; #endif #ifdef SVN_HAVE_KEYCHAIN_SERVICES svn_auth_get_keychain_simple_provider(&provider, pool); APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider; #endif svn_auth_get_simple_provider(&provider, 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. */ #if defined(WIN32) && !defined(__MINGW32__) svn_auth_get_windows_ssl_server_trust_provider(&provider, pool); APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider; #endif 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_provider(&provider, pool); APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider; if (non_interactive == FALSE) { svn_cmdline_prompt_baton_t *pb = NULL; if (cancel_func) { pb = apr_palloc(pool, sizeof(*pb)); pb->cancel_func = cancel_func; pb->cancel_baton = cancel_baton; } /* Two basic prompt providers: username/password, and just username. */ nmap_update_svn_auth_get_simple_prompt_provider(&provider, svn_cmdline_auth_simple_prompt, pb, 2, /* retry limit */ pool); APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider; svn_auth_get_username_prompt_provider (&provider, svn_cmdline_auth_username_prompt, pb, 2, /* retry limit */ pool); APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider; /* Three ssl prompt providers, for server-certs, client-certs, and client-cert-passphrases. */ svn_auth_get_ssl_server_trust_prompt_provider (&provider, svn_cmdline_auth_ssl_server_trust_prompt, pb, pool); APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider; svn_auth_get_ssl_client_cert_prompt_provider (&provider, svn_cmdline_auth_ssl_client_cert_prompt, pb, 2, pool); APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider; svn_auth_get_ssl_client_cert_pw_prompt_provider (&provider, svn_cmdline_auth_ssl_client_cert_pw_prompt, pb, 2, 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. */ if (auth_username) svn_auth_set_parameter(*ab, SVN_AUTH_PARAM_DEFAULT_USERNAME, auth_username); if (auth_password) svn_auth_set_parameter(*ab, SVN_AUTH_PARAM_DEFAULT_PASSWORD, auth_password); /* Same with the --non-interactive option. */ if (non_interactive) svn_auth_set_parameter(*ab, SVN_AUTH_PARAM_NON_INTERACTIVE, ""); if (config_dir) svn_auth_set_parameter(*ab, SVN_AUTH_PARAM_CONFIG_DIR, config_dir); SVN_ERR(svn_config_get_bool(cfg, &store_password_val, SVN_CONFIG_SECTION_AUTH, SVN_CONFIG_OPTION_STORE_PASSWORDS, TRUE)); if (! store_password_val) svn_auth_set_parameter(*ab, SVN_AUTH_PARAM_DONT_STORE_PASSWORDS, ""); /* There are two different ways the user can disable disk caching of credentials: either via --no-auth-cache, or in the config file ('store-auth-creds = no'). */ SVN_ERR(svn_config_get_bool(cfg, &store_password_val, SVN_CONFIG_SECTION_AUTH, SVN_CONFIG_OPTION_STORE_AUTH_CREDS, TRUE)); if (no_auth_cache || ! store_password_val) svn_auth_set_parameter(*ab, SVN_AUTH_PARAM_NO_AUTH_CACHE, ""); return SVN_NO_ERROR; }
int a_svn_commit (char *device_name, char *temp_working_dir, char *commit_as, apr_pool_t *apr_pool, apr_pool_t *svn_pool) /* * commit changed file to SVN repository * */ { svn_error_t* err; int int_err; apr_array_header_t *device_arr; svn_commit_info_t *commit_info = NULL; svn_auth_baton_t *auth_baton; svn_auth_provider_object_t *provider; svn_error_t *svn_err; char temp_svn_path[MAXPATH]; svn_client_ctx_t* context; temp_svn_path[0] = 0x0; svn_err = svn_client_create_context( &context, svn_pool ); if(svn_err){ a_logmsg("%s: svn error: %s",device_name,svn_err->message); a_debug_info2(DEBUGLVL5,"a_svn_commit: svn error: %s",svn_err->message); return -1; } device_arr = apr_array_make(apr_pool, 1, sizeof(const char*)); snprintf(temp_svn_path,MAXPATH,"%s/%s",temp_working_dir,device_name); *(const char**)apr_array_push(device_arr) = temp_svn_path; apr_array_header_t *providers = apr_array_make (apr_pool, 1, sizeof (svn_auth_provider_object_t *)); svn_auth_get_username_provider(&provider, svn_pool); APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider; svn_auth_open(&auth_baton, providers, svn_pool); svn_auth_set_parameter(auth_baton, SVN_AUTH_PARAM_DEFAULT_USERNAME, commit_as); (*context).auth_baton = auth_baton; svn_err = svn_client_commit4(&commit_info, device_arr, svn_depth_empty, FALSE, FALSE, NULL, NULL, context, svn_pool); if(svn_err) { a_logmsg("%s: svn error: %s",device_name,svn_err->message); a_debug_info2(DEBUGLVL5,"a_svn_commit: svn error: %s",svn_err->message); return -1; } return 1; }
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); }
int main (int argc, const char **argv) { apr_pool_t *pool; svn_error_t *err; apr_hash_t *dirents; const char *upload_file, *URL; const char *parent_URL, *basename; svn_ra_plugin_t *ra_lib; void *session, *ra_baton; svn_revnum_t rev; const svn_delta_editor_t *editor; void *edit_baton; svn_dirent_t *dirent; svn_ra_callbacks_t *cbtable; apr_hash_t *cfg_hash; svn_auth_baton_t *auth_baton; if (argc <= 2) { printf ("Usage: %s PATH URL\n", argv[0]); printf (" Uploads file at PATH to Subversion repository URL.\n"); return EXIT_FAILURE; } upload_file = argv[1]; URL = argv[2]; /* Initialize the app. Send all error messages to 'stderr'. */ if (svn_cmdline_init ("minimal_client", stderr) != EXIT_SUCCESS) return EXIT_FAILURE; /* Create top-level memory pool. Be sure to read the HACKING file to understand how to properly use/free subpools. */ pool = svn_pool_create (NULL); /* Initialize the FS library. */ err = svn_fs_initialize (pool); if (err) goto hit_error; /* Make sure the ~/.subversion run-time config files exist, and load. */ err = svn_config_ensure (NULL, pool); if (err) goto hit_error; err = svn_config_get_config (&cfg_hash, NULL, pool); if (err) goto hit_error; /* Build an authentication baton. */ { /* There are many different kinds of authentication back-end "providers". See svn_auth.h for a full overview. */ svn_auth_provider_object_t *provider; apr_array_header_t *providers = apr_array_make (pool, 4, sizeof (svn_auth_provider_object_t *)); svn_client_get_simple_prompt_provider (&provider, my_simple_prompt_callback, NULL, /* baton */ 2, /* retry limit */ pool); APR_ARRAY_PUSH (providers, svn_auth_provider_object_t *) = provider; svn_client_get_username_prompt_provider (&provider, my_username_prompt_callback, NULL, /* baton */ 2, /* 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 (&auth_baton, providers, pool); } /* Create a table of callbacks for the RA session, mostly nonexistent. */ cbtable = apr_pcalloc (pool, sizeof(*cbtable)); cbtable->auth_baton = auth_baton; cbtable->open_tmp_file = open_tmp_file; /* Now do the real work. */ /* Open an RA session to the parent URL, fetch current HEAD rev and "lock" onto that revnum for the remainder of the session. */ svn_path_split (URL, &parent_URL, &basename, pool); err = svn_ra_init_ra_libs (&ra_baton, pool); if (err) goto hit_error; err = svn_ra_get_ra_library (&ra_lib, ra_baton, parent_URL, pool); if (err) goto hit_error; err = ra_lib->open (&session, parent_URL, cbtable, NULL, cfg_hash, pool); if (err) goto hit_error; err = ra_lib->get_latest_revnum (session, &rev, pool); if (err) goto hit_error; /* Examine contents of parent dir in the rev. */ err = ra_lib->get_dir (session, "", rev, &dirents, NULL, NULL, pool); if (err) goto hit_error; /* Sanity checks. Don't let the user shoot himself *too* much. */ dirent = apr_hash_get (dirents, basename, APR_HASH_KEY_STRING); if (dirent && dirent->kind == svn_node_dir) { printf ("Sorry, a directory already exists at that URL.\n"); return EXIT_FAILURE; } if (dirent && dirent->kind == svn_node_file) { char answer[5]; printf ("\n*** WARNING ***\n\n"); printf ("You're about to overwrite r%ld of this file.\n", rev); printf ("It was last changed by user '%s',\n", dirent->last_author ? dirent->last_author : "?"); printf ("on %s.\n", svn_time_to_human_cstring (dirent->time, pool)); printf ("\nSomebody *might* have just changed the file seconds ago,\n" "and your upload would be overwriting their changes!\n\n"); err = prompt_and_read_line("Are you SURE you want to upload? [y/n]", answer, sizeof(answer)); if (err) goto hit_error; if (apr_strnatcasecmp (answer, "y")) { printf ("Operation aborted.\n"); return EXIT_SUCCESS; } } /* Fetch a commit editor (it's anchored on the parent URL, because the session is too.) */ /* ### someday add an option for a user-written commit message? */ err = ra_lib->get_commit_editor (session, &editor, &edit_baton, "File upload from 'svnput' program.", my_commit_callback, NULL, pool); if (err) goto hit_error; /* Drive the editor */ { void *root_baton, *file_baton, *handler_baton; svn_txdelta_window_handler_t handler; svn_stream_t *contents; apr_file_t *f = NULL; err = editor->open_root (edit_baton, rev, pool, &root_baton); if (err) goto hit_error; if (! dirent) { err = editor->add_file (basename, root_baton, NULL, SVN_INVALID_REVNUM, pool, &file_baton); } else { err = editor->open_file (basename, root_baton, rev, pool, &file_baton); } if (err) goto hit_error; err = editor->apply_textdelta (file_baton, NULL, pool, &handler, &handler_baton); if (err) goto hit_error; err = svn_io_file_open (&f, upload_file, APR_READ, APR_OS_DEFAULT, pool); if (err) goto hit_error; contents = svn_stream_from_aprfile (f, pool); err = svn_txdelta_send_stream (contents, handler, handler_baton, NULL, pool); if (err) goto hit_error; err = svn_io_file_close (f, pool); if (err) goto hit_error; err = editor->close_file (file_baton, NULL, pool); if (err) goto hit_error; err = editor->close_edit (edit_baton, pool); if (err) goto hit_error; } return EXIT_SUCCESS; hit_error: svn_handle_error2 (err, stderr, FALSE, "svnput: "); return EXIT_FAILURE; }
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; }
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; }
int main (int argc, const char **argv) { apr_pool_t *pool; svn_error_t *err; svn_opt_revision_t revision; apr_hash_t *dirents; apr_hash_index_t *hi; svn_client_ctx_t *ctx; const char *URL; if (argc <= 1) { printf ("Usage: %s URL\n", argv[0]); return EXIT_FAILURE; } else URL = argv[1]; /* Initialize the app. Send all error messages to 'stderr'. */ if (svn_cmdline_init ("minimal_client", stderr) != EXIT_SUCCESS) return EXIT_FAILURE; /* Create top-level memory pool. Be sure to read the HACKING file to understand how to properly use/free subpools. */ pool = svn_pool_create (NULL); /* Initialize the FS library. */ err = svn_fs_initialize (pool); if (err) { /* For functions deeper in the stack, we usually use the SVN_ERR() exception-throwing macro (see svn_error.h). At the top level, we catch & print the error with svn_handle_error2(). */ svn_handle_error2 (err, stderr, FALSE, "minimal_client: "); return EXIT_FAILURE; } /* Make sure the ~/.subversion run-time config files exist */ err = svn_config_ensure (NULL, pool); if (err) { svn_handle_error2 (err, stderr, FALSE, "minimal_client: "); return EXIT_FAILURE; } /* All clients need to fill out a client_ctx object. */ { /* Initialize and allocate the client_ctx object. */ if ((err = svn_client_create_context (&ctx, pool))) { svn_handle_error2 (err, stderr, FALSE, "minimal_client: "); return EXIT_FAILURE; } /* Load the run-time config file into a hash */ if ((err = svn_config_get_config (&(ctx->config), NULL, pool))) { svn_handle_error2 (err, stderr, FALSE, "minimal_client: "); return EXIT_FAILURE; } #ifdef WIN32 /* Set the working copy administrative directory name. */ if (getenv ("SVN_ASP_DOT_NET_HACK")) { err = svn_wc_set_adm_dir ("_svn", pool); if (err) { svn_handle_error2 (err, stderr, FALSE, "minimal_client: "); return EXIT_FAILURE; } } #endif /* Depending on what your client does, you'll want to read about (and implement) the various callback function types below. */ /* A func (& context) which receives event signals during checkouts, updates, commits, etc. */ /* ctx->notify_func = my_notification_func; ctx->notify_baton = NULL; */ /* A func (& context) which can receive log messages */ /* ctx->log_msg_func = my_log_msg_receiver_func; ctx->log_msg_baton = NULL; */ /* A func (& context) which checks whether the user cancelled */ /* ctx->cancel_func = my_cancel_checking_func; ctx->cancel_baton = NULL; */ /* Make the client_ctx capable of authenticating users */ { /* There are many different kinds of authentication back-end "providers". See svn_auth.h for a full overview. If you want to get the auth behavior of the 'svn' program, you can use svn_cmdline_setup_auth_baton, which will give you the exact set of auth providers it uses. This program doesn't use it because it's only appropriate for a command line program, and this is supposed to be a general purpose example. */ svn_auth_provider_object_t *provider; apr_array_header_t *providers = apr_array_make (pool, 4, sizeof (svn_auth_provider_object_t *)); svn_auth_get_simple_prompt_provider (&provider, my_simple_prompt_callback, NULL, /* baton */ 2, /* retry limit */ pool); APR_ARRAY_PUSH (providers, svn_auth_provider_object_t *) = provider; svn_auth_get_username_prompt_provider (&provider, my_username_prompt_callback, NULL, /* baton */ 2, /* 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); } } /* end of client_ctx setup */ /* Now do the real work. */ /* Set revision to always be the HEAD revision. It could, however, be set to a specific revision number, date, or other values. */ revision.kind = svn_opt_revision_head; /* Main call into libsvn_client does all the work. */ err = svn_client_ls (&dirents, URL, &revision, FALSE, /* no recursion */ ctx, pool); if (err) { svn_handle_error2 (err, stderr, FALSE, "minimal_client: "); return EXIT_FAILURE; } /* Print the dir entries in the hash. */ for (hi = apr_hash_first (pool, dirents); hi; hi = apr_hash_next (hi)) { const char *entryname; svn_dirent_t *val; apr_hash_this (hi, (void *) &entryname, NULL, (void *) &val); printf (" %s\n", entryname); /* 'val' is actually an svn_dirent_t structure; a more complex program would mine it for extra printable information. */ } return EXIT_SUCCESS; }
int main (int argc, const char **argv) { apr_pool_t *pool; svn_error_t *err; apr_hash_t *locks; apr_hash_index_t *hi; const char *URL; svn_ra_session_t *session; svn_ra_callbacks_t *cbtable; apr_hash_t *cfg_hash; svn_auth_baton_t *auth_baton; if (argc <= 1) { printf ("Usage: %s URL\n", argv[0]); printf (" Print all locks at or below URL.\n"); return EXIT_FAILURE; } URL = argv[1]; /* Initialize the app. Send all error messages to 'stderr'. */ if (svn_cmdline_init ("ra_test", stderr) != EXIT_SUCCESS) return EXIT_FAILURE; /* Create top-level memory pool. Be sure to read the HACKING file to understand how to properly use/free subpools. */ pool = svn_pool_create (NULL); /* Initialize the FS library. */ err = svn_fs_initialize (pool); if (err) goto hit_error; /* Make sure the ~/.subversion run-time config files exist, and load. */ err = svn_config_ensure (NULL, pool); if (err) goto hit_error; err = svn_config_get_config (&cfg_hash, NULL, pool); if (err) goto hit_error; /* Build an authentication baton. */ { /* There are many different kinds of authentication back-end "providers". See svn_auth.h for a full overview. */ svn_auth_provider_object_t *provider; apr_array_header_t *providers = apr_array_make (pool, 4, sizeof (svn_auth_provider_object_t *)); svn_client_get_simple_prompt_provider (&provider, my_simple_prompt_callback, NULL, /* baton */ 2, /* retry limit */ pool); APR_ARRAY_PUSH (providers, svn_auth_provider_object_t *) = provider; svn_client_get_username_prompt_provider (&provider, my_username_prompt_callback, NULL, /* baton */ 2, /* 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 (&auth_baton, providers, pool); } /* Create a table of callbacks for the RA session, mostly nonexistent. */ cbtable = apr_pcalloc (pool, sizeof(*cbtable)); cbtable->auth_baton = auth_baton; cbtable->open_tmp_file = open_tmp_file; /* Now do the real work. */ err = svn_ra_open (&session, URL, cbtable, NULL, cfg_hash, pool); if (err) goto hit_error; err = svn_ra_get_locks (session, &locks, "", pool); if (err) goto hit_error; err = svn_cmdline_printf (pool, "\n"); if (err) goto hit_error; for (hi = apr_hash_first (pool, locks); hi; hi = apr_hash_next (hi)) { const void *key; void *val; const char *path, *cr_date, *exp_date; svn_lock_t *lock; apr_hash_this (hi, &key, NULL, &val); path = key; lock = val; cr_date = svn_time_to_human_cstring (lock->creation_date, pool); if (lock->expiration_date) exp_date = svn_time_to_human_cstring (lock->expiration_date, pool); else exp_date = "never"; err = svn_cmdline_printf (pool, "%s\n", path); if (err) goto hit_error; err = svn_cmdline_printf (pool, " UUID Token: %s\n", lock->token); if (err) goto hit_error; err = svn_cmdline_printf (pool, " Owner: %s\n", lock->owner); if (err) goto hit_error; err = svn_cmdline_printf (pool, " Comment: %s\n", lock->comment ? lock->comment : "none"); if (err) goto hit_error; err = svn_cmdline_printf (pool, " Created: %s\n", cr_date); if (err) goto hit_error; err = svn_cmdline_printf (pool, " Expires: %s\n\n", exp_date); if (err) goto hit_error; } return EXIT_SUCCESS; hit_error: svn_handle_error2 (err, stderr, FALSE, "getlocks_test: "); return EXIT_FAILURE; }
int main (int argc, const char **argv) { apr_pool_t *pool; svn_error_t *err; const char *URL; svn_ra_session_t *session; svn_ra_callbacks2_t *cbtable; svn_revnum_t rev; apr_hash_t *cfg_hash; svn_auth_baton_t *auth_baton; if (argc <= 1) { printf ("Usage: %s URL\n", argv[0]); printf (" Print HEAD revision of URL's repository.\n"); return EXIT_FAILURE; } else URL = argv[1]; /* Initialize the app. Send all error messages to 'stderr'. */ if (svn_cmdline_init ("headrev", stderr) != EXIT_SUCCESS) return EXIT_FAILURE; /* Create top-level memory pool. Be sure to read the HACKING file to understand how to properly use/free subpools. */ pool = svn_pool_create (NULL); /* Initialize the FS library. */ err = svn_fs_initialize (pool); if (err) goto hit_error; /* Make sure the ~/.subversion run-time config files exist, and load. */ err = svn_config_ensure (NULL, pool); if (err) goto hit_error; err = svn_config_get_config (&cfg_hash, NULL, pool); if (err) goto hit_error; /* Build an authentication baton. */ { /* There are many different kinds of authentication back-end "providers". See svn_auth.h for a full overview. */ svn_auth_provider_object_t *provider; apr_array_header_t *providers = apr_array_make (pool, 4, sizeof (svn_auth_provider_object_t *)); svn_client_get_simple_prompt_provider (&provider, my_simple_prompt_callback, NULL, /* baton */ 2, /* retry limit */ pool); APR_ARRAY_PUSH (providers, svn_auth_provider_object_t *) = provider; svn_client_get_username_prompt_provider (&provider, my_username_prompt_callback, NULL, /* baton */ 2, /* 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 (&auth_baton, providers, pool); } /* Create a table of callbacks for the RA session, mostly nonexistent. */ cbtable = apr_pcalloc (pool, sizeof(*cbtable)); cbtable->auth_baton = auth_baton; cbtable->open_tmp_file = open_tmp_file; /* Now do the real work. */ err = svn_ra_open2(&session, URL, cbtable, NULL, cfg_hash, pool); if (err) goto hit_error; err = svn_ra_get_latest_revnum(session, &rev, pool); if (err) goto hit_error; printf ("The latest revision is %ld.\n", rev); return EXIT_SUCCESS; hit_error: svn_handle_error2 (err, stderr, FALSE, "headrev: "); return EXIT_FAILURE; }