<commit_before>/*
 * auth.c:  routines that drive "authenticator" objects received from RA.
 *
 * ====================================================================
 * Copyright (c) 2000-2001 CollabNet.  All rights reserved.
 *
 * This software is licensed as described in the file COPYING, which
 * you should have received as part of this distribution.  The terms
 * are also available at http://subversion.tigris.org/license-1.html.
 * If newer versions of this license are posted there, you may use a
 * newer version instead, at your option.
 *
 * This software consists of voluntary contributions made by many
 * individuals.  For exact contribution history, see the revision
 * history and logs, available at http://subversion.tigris.org/.
 * ====================================================================
 */

/* ==================================================================== */




/*** Includes. ***/

#include <apr_strings.h>
#include <apr_pools.h>
#include "svn_client.h"
#include "svn_ra.h"
#include "svn_wc.h"
#include "svn_error.h"
#include "svn_io.h"
#include "svn_path.h"

#include "client.h"


/*-----------------------------------------------------------------------*/


/* Callback routines that RA libraries use to pull or store auth info. */



static svn_error_t *
open_admin_tmp_file (apr_file_t **fp,
                     void *callback_baton)
{
  svn_client_auth_baton_t *cb =
    (svn_client_auth_baton_t *) callback_baton;

  SVN_ERR (svn_wc_create_tmp_file (fp, cb->path, cb->pool));

  return SVN_NO_ERROR;
}


static svn_error_t *
open_tmp_file (apr_file_t **fp,
               void *callback_baton)
{
  svn_client_auth_baton_t *cb = (svn_client_auth_baton_t *) callback_baton;
  svn_stringbuf_t *truepath = svn_stringbuf_dup (cb->path, cb->pool);
  svn_stringbuf_t *ignored_filename;

  /* Tack on a made-up filename. */
  svn_path_add_component_nts (truepath, "tempfile", svn_path_local_style);

  /* Open a unique file;  use APR_DELONCLOSE. */
  SVN_ERR (svn_io_open_unique_file (fp, &ignored_filename,
                                    truepath, ".tmp", TRUE, cb->pool));

  return SVN_NO_ERROR;
}


static svn_error_t *
get_username (char **username,
              void *auth_baton,
              apr_pool_t *pool)
{
  svn_error_t *err;
  svn_stringbuf_t *uname;

  svn_client_auth_baton_t *ab =
    (svn_client_auth_baton_t *) auth_baton;

  /* Does auth_baton already have the value, received from
     the application (probably from argv[])? */
  if (ab->username)
    {
      *username = apr_pstrdup (pool, ab->username);

      /* Since we got new totally new info, it's okay to overwrite
         any cached info in the working copy (later on). */
      ab->overwrite = TRUE;
    }

  else  /* else get it from file cached in working copy. */
    {
      err = svn_wc_get_auth_file (ab->path,
                                  SVN_CLIENT_AUTH_USERNAME,
                                  &uname, pool);
      if (! err)
        *username = uname->data;

      else
        {
          /* No file cache?  Then just use the process owner. */
          char *un;
          apr_uid_t uid;
          apr_gid_t gid;
          apr_status_t status;

          status = apr_current_userid (&uid, &gid, pool);
          if (status)
            return
              svn_error_createf(status, 0, NULL, pool,
                                "Error getting UID of process.");

          status = apr_get_username (&un, uid, pool);
          if (status)
            return svn_error_createf(status, 0, NULL, pool,
                                     "Error in UID->username.");
          *username = un;
        }
    }

  return SVN_NO_ERROR;
}



static svn_error_t *
get_password (char **password,
              char *username,
              void *auth_baton,
              apr_pool_t *pool)
{
  svn_error_t *err;
  svn_stringbuf_t *pword;

  svn_client_auth_baton_t *ab =
    (svn_client_auth_baton_t *) auth_baton;

  /* Does auth_baton already have the value, received from
     the application (probably from argv[])? */
  if (ab->password)
    {
      *password = apr_pstrdup (pool, ab->password);

      /* Since we got new totally new info, it's okay to overwrite
         any cached info in the working copy (later on). */
      ab->overwrite = TRUE;
    }

  else  /* else get it from file cached in working copy. */
    {
      err = svn_wc_get_auth_file (ab->path,
                                  SVN_CLIENT_AUTH_PASSWORD,
                                  &pword, pool);
      if (! err)
        *password = pword->data;

      else
        {
          char promptbuf[100];

          snprintf(promptbuf, 100, "%s's password: ", username);

          /* No file cache?  Then prompt the user. */
          SVN_ERR (ab->prompt_callback (password, promptbuf,
                                        TRUE, /* don't echo to the screen */
                                        ab->prompt_baton, pool));

          /* Since we got new totally new info, it's okay to overwrite
             any cached info in the working copy (later on). */
          ab->overwrite = TRUE;
        }
    }

  return SVN_NO_ERROR;
}



static svn_error_t *
get_user_and_pass (char **username,
                   char **password,
                   void *auth_baton,
                   apr_pool_t *pool)
{
  SVN_ERR (get_username (username, auth_baton, pool));
  SVN_ERR (get_password (password, *username, auth_baton, pool));

  return SVN_NO_ERROR;
}
<commit_msg>Let's be careful out there.<commit_after>/*
 * auth.c:  routines that drive "authenticator" objects received from RA.
 *
 * ====================================================================
 * Copyright (c) 2000-2001 CollabNet.  All rights reserved.
 *
 * This software is licensed as described in the file COPYING, which
 * you should have received as part of this distribution.  The terms
 * are also available at http://subversion.tigris.org/license-1.html.
 * If newer versions of this license are posted there, you may use a
 * newer version instead, at your option.
 *
 * This software consists of voluntary contributions made by many
 * individuals.  For exact contribution history, see the revision
 * history and logs, available at http://subversion.tigris.org/.
 * ====================================================================
 */

/* ==================================================================== */




/*** Includes. ***/

#include <apr_strings.h>
#include <apr_pools.h>
#include "svn_client.h"
#include "svn_ra.h"
#include "svn_wc.h"
#include "svn_error.h"
#include "svn_io.h"
#include "svn_path.h"

#include "client.h"


/*-----------------------------------------------------------------------*/


/* Callback routines that RA libraries use to pull or store auth info. */



static svn_error_t *
open_admin_tmp_file (apr_file_t **fp,
                     void *callback_baton)
{
  svn_client_auth_baton_t *cb =
    (svn_client_auth_baton_t *) callback_baton;

  SVN_ERR (svn_wc_create_tmp_file (fp, cb->path, cb->pool));

  return SVN_NO_ERROR;
}


static svn_error_t *
open_tmp_file (apr_file_t **fp,
               void *callback_baton)
{
  svn_client_auth_baton_t *cb = (svn_client_auth_baton_t *) callback_baton;
  svn_stringbuf_t *truepath = svn_stringbuf_dup (cb->path, cb->pool);
  svn_stringbuf_t *ignored_filename;

  /* Tack on a made-up filename. */
  svn_path_add_component_nts (truepath, "tempfile", svn_path_local_style);

  /* Open a unique file;  use APR_DELONCLOSE. */
  SVN_ERR (svn_io_open_unique_file (fp, &ignored_filename,
                                    truepath, ".tmp", TRUE, cb->pool));

  return SVN_NO_ERROR;
}


static svn_error_t *
get_username (char **username,
              void *auth_baton,
              apr_pool_t *pool)
{
  svn_error_t *err;
  svn_stringbuf_t *uname;

  svn_client_auth_baton_t *ab =
    (svn_client_auth_baton_t *) auth_baton;

  /* Does auth_baton already have the value, received from
     the application (probably from argv[])? */
  if (ab->username)
    {
      *username = apr_pstrdup (pool, ab->username);

      /* Since we got new totally new info, it's okay to overwrite
         any cached info in the working copy (later on). */
      ab->overwrite = TRUE;
    }

  else  /* else get it from file cached in working copy. */
    {
      err = svn_wc_get_auth_file (ab->path,
                                  SVN_CLIENT_AUTH_USERNAME,
                                  &uname, pool);
      if (! err)
        *username = uname->data;

      else
        {
          /* No file cache?  Then just use the process owner. */
          char *un;
          apr_uid_t uid;
          apr_gid_t gid;
          apr_status_t status;

          status = apr_current_userid (&uid, &gid, pool);
          if (status)
            return
              svn_error_createf(status, 0, NULL, pool,
                                "Error getting UID of process.");

          status = apr_get_username (&un, uid, pool);
          if (status)
            return svn_error_createf(status, 0, NULL, pool,
                                     "Error in UID->username.");
          *username = un;
        }
    }

  return SVN_NO_ERROR;
}



static svn_error_t *
get_password (char **password,
              char *username,
              void *auth_baton,
              apr_pool_t *pool)
{
  svn_error_t *err;
  svn_stringbuf_t *pword;

  svn_client_auth_baton_t *ab =
    (svn_client_auth_baton_t *) auth_baton;

  /* Does auth_baton already have the value, received from
     the application (probably from argv[])? */
  if (ab->password)
    {
      *password = apr_pstrdup (pool, ab->password);

      /* Since we got new totally new info, it's okay to overwrite
         any cached info in the working copy (later on). */
      ab->overwrite = TRUE;
    }

  else  /* else get it from file cached in working copy. */
    {
      err = svn_wc_get_auth_file (ab->path,
                                  SVN_CLIENT_AUTH_PASSWORD,
                                  &pword, pool);
      if (! err)
        *password = <PASSWORD>;

      else
        {
          char *prompt = apr_psprintf (pool, "%s's password: ", username);

          /* No file cache?  Then prompt the user. */
          SVN_ERR (ab->prompt_callback (password, prompt,
                                        TRUE, /* don't echo to the screen */
                                        ab->prompt_baton, pool));

          /* Since we got new totally new info, it's okay to overwrite
             any cached info in the working copy (later on). */
          ab->overwrite = TRUE;
        }
    }

  return SVN_NO_ERROR;
}



static svn_error_t *
get_user_and_pass (char **username,
                   char **password,
                   void *auth_baton,
                   apr_pool_t *pool)
{
  SVN_ERR (get_username (username, auth_baton, pool));
  SVN_ERR (get_password (password, *username, auth_baton, pool));

  return SVN_NO_ERROR;
}

{'fraction_non_alphanumeric': 0.1437932289770659, 'fraction_numerical': 0.0025482344375682563, 'mean_word_length': 2.1424077780955106, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2624091', 'n_tokens_mistral': 3496, 'n_tokens_neox': 3325, 'n_words': 934}