Switch to automatic initialization via atomics, as suggested by Bert.

This revert's r1307538, r1307559, r1307564, and r1307747 to main.c.

Some includes were added to crypt.[ch] to enable building.

* subverison/libsvn_subr/crypto.h:
  (...): include svn_types.h and svn_string.h

* subversion/libsvn_subr/crypto.c:
  (...): include svn_types and svn_private_conig to fix the build.
    include the atomics.
  (crypto_init_state): our atomic to determine if we have initialized
    APR's crypto subsystem.
  (CRYPTO_INIT): handy macro to init the subsystem
  (crypto_init): svn_atomic handler to init APR
  (svn_crypt__context_create): call CRYPTO_INIT()

* subverison/svn/main.c:
  (...): remove various includes
  (crypto_init): removed
  (main): remove call to crypto_init()


git-svn-id: https://svn.apache.org/repos/asf/subversion/trunk@1307903 13f79535-47bb-0310-9956-ffa450edef68
Use a private crypto context, so we don't leak APR'isms out to the
interface. This also sets us up for moving the crypto-crandom context
into this shared structure.

* subversion/libsvn_subr/crypto.h:
  (...): remove apr_crypto.h from the public interface. wrap the C++/C
    guard around the declarations.
  (svn_crypto__ctx_t): new opaque type
  (svn_crypto__context_create, svn_crypto__encrypt_cstring,
      svn_crypto__decrypt_cstring): use new ctx type

* subversion/libsvn_subr/crypto.c:
  (...): include apr_crypto.h here
  (svn_crypto__ctx_t): define our internal context type
  (svn_crypto__context_create): rework for internal ctx type
  (svn_crypto__encrypt_cstring): rejigger for new ctx type
  (svn_crypto__decrypt_cstring): tweak decl for new ctx type


git-svn-id: https://svn.apache.org/repos/asf/subversion/trunk@1307913 13f79535-47bb-0310-9956-ffa450edef68
Solve Daniel's review of apr_random_t usage (need entropy) by using
APR's other interface for generating random bytes.

* subversion/libsvn_subr/crypto.c:
  (svn_crypto__ctx_t): note possible future use of apr_random_t
  (get_random_bytes): take a CTX, rename to RESULT_POOL. rejigger the
    code to use apr_generate_random_bytes()
  (svn_crypto__context_create): note possible apr_random_t usage
  (svn_crypto__encrypt_cstring): pass the CTX to get_random_bytes()


git-svn-id: https://svn.apache.org/repos/asf/subversion/trunk@1307917 13f79535-47bb-0310-9956-ffa450edef68
Incorporate Daniel's suggestions around error handling.

* subversion/libsvn_subr/crypto.c:
  (crypto_error_create): new helper function to untwist the various
    error APIs and semantics from APR's crypto stuff
  (svn_crypto__context_create): be wary of a NULL value for DRIVER
    even when we get APR_SUCCESS (bug sent to dev@apr)
  (svn_crypto__encrypt_string): use crypto_error_create


git-svn-id: https://svn.apache.org/repos/asf/subversion/trunk@1307923 13f79535-47bb-0310-9956-ffa450edef68
Revamp the signatures: these functions are designed specifically for
password encryption using a master password. They are not arbitrary
crypto functions, so don't pretend they are.

* subversion/libsvn_subr/crypto.h:
  (svn_crypto__encrypt_cstring): renamed to ...
  (svn_crypto__encrypt_password): ... this. many types adjusted.
  (svn_crypto__decrypt_cstring): renamed to ...
  (svn_crypto__decrypt_password): ... this. many types adjusted.

* subversion/libsvn_subr/crypto.c:
  (NUM_ITERATIONS): constant for our PBKDF2 usage
  (get_random_bytes): constify the output, and make them unsigned char
  (wrap_as_string): helper to alloc an svn_string_t and initialize it
  (svn_crypto__encrypt_cstring): renamed to ...
  (svn_crypto__encrypt_password): ... this. adjust the implementation
    for the new svn_string_t parameters. turn off padding (as this can
    cause a decrypt error, per the OpenSSL docs); we'll manually pad.
    other adjustments and tweaks for our APR crypto calls.
  (svn_crypto__decrypt_cstring): renamed to ...
  (svn_crypto__decrypt_password): ... this


git-svn-id: https://svn.apache.org/repos/asf/subversion/trunk@1307940 13f79535-47bb-0310-9956-ffa450edef68
* subversion/libsvn_wc/wc_db.c (scan_deletion_txn): Avoid a duplicate SQL reset.

Found by: rhuijben


git-svn-id: https://svn.apache.org/repos/asf/subversion/trunk@1308264 13f79535-47bb-0310-9956-ffa450edef68
* subversion/bindings/swig/perl/native/t/3client.t: Try getwpuid() before
   getlogin() because the former gives the expected result even if tests
   are run after su(1). Should resolve spurious failures on the OpenBSD
   buildbot.

Suggested by: philip


git-svn-id: https://svn.apache.org/repos/asf/subversion/trunk@1308299 13f79535-47bb-0310-9956-ffa450edef68
Follow-up to r1308299:

* subversion/bindings/swig/perl/native/t/3client.t: Don't try to use getpwuid()
   on Windows because it is not implemented there. (If somebody knows a better
   way of doing this, like catching the error and retrying, please help).


git-svn-id: https://svn.apache.org/repos/asf/subversion/trunk@1308307 13f79535-47bb-0310-9956-ffa450edef68
* tools/dev/aprerr.txt
  Add APU error codes, and set svn:eol-style to "native".


git-svn-id: https://svn.apache.org/repos/asf/subversion/trunk@1308360 13f79535-47bb-0310-9956-ffa450edef68
Some cleanups and minor tweaks to the crypto code.

* subversion/libsvn_subr/crypto.c
  (crypto_init): Remove unnecessary #if-wrapping (APU_HAVE_CRYPTO).
    While here, re-wrap (in a different sense of the word) some code.
  (get_random_bytes): Add necessary #if-wrapping (this time, APR_HAS_RANDOM).
  (svn_crypto__context_create): Drop params to apr_crypto_make() -- on
    my system, at least, this allows the function to complete with
    success rather than throwing an APR_ENOENGINE error.


git-svn-id: https://svn.apache.org/repos/asf/subversion/trunk@1308372 13f79535-47bb-0310-9956-ffa450edef68
More minor code cleanups in crypto.c.

* subversion/libsvn_subr/crypto.c
  (NEED_RANDOMER_RANDOMNESS): New #define to replace the somewhat more
    opaque "#if 0".
  (): Add a bunch of function docstrings, and purge one stale comment.


git-svn-id: https://svn.apache.org/repos/asf/subversion/trunk@1308388 13f79535-47bb-0310-9956-ffa450edef68
* subversion/tests/libsvn_subr/crypto-test.c
  (test_encrypt_decrypt_password): Was test_encrypt_decrypt(); now has
    actual content.
  (test_funcs): Update reference to the sole test, and mark it XFAIL
    for now.

git-svn-id: https://svn.apache.org/repos/asf/subversion/trunk@1308393 13f79535-47bb-0310-9956-ffa450edef68
* subversion/tests/libsvn_subr/crypto-test.c
  Use "#if APU_HAVE_CRYPTO" instead of "#ifdef APU_HAVE_CRYPTO".


git-svn-id: https://svn.apache.org/repos/asf/subversion/trunk@1308401 13f79535-47bb-0310-9956-ffa450edef68
Update function to return an error.  No functional change.

* subversion/svnsync/main.c
  (make_replay_baton): Return an error, even though we currently don't
    generate any here.
  (do_synchronize): Update caller.


git-svn-id: https://svn.apache.org/repos/asf/subversion/trunk@1308403 13f79535-47bb-0310-9956-ffa450edef68
Kill me now.

git-svn-id: https://svn.apache.org/repos/asf/subversion/trunk@1308410 13f79535-47bb-0310-9956-ffa450edef68
* subversion/tests/libsvn_subr/crypto-test.c
  Use a more appropriate #if statement.


git-svn-id: https://svn.apache.org/repos/asf/subversion/trunk@1308411 13f79535-47bb-0310-9956-ffa450edef68
Finish up the initial password encryption and decryption routines, and
stare in amazement as the tests now pass.  For me.  On my box.

* subversion/libsvn_subr/crypto.c
  (svn_crypto__encrypt_password): Per our plan, prepend the prefix to
    the password and pad up to the specified block size before
    encrypting.  Lose a seemingly unfounded assertion (that the size
    of the input will match that of the output).
  (svn_crypto__decrypt_password): Implement this function.

* subversion/tests/libsvn_subr/crypto-test.c
  (encrypt_decrypt): New function, abstracted out of ...
  (test_encrypt_decrypt_password): ...this, which now calls the helper
    function in a loop so different password lengths can be tested.
  (test_funcs): Now expect test_encrypt_decrypt_password() to pass.


git-svn-id: https://svn.apache.org/repos/asf/subversion/trunk@1308470 13f79535-47bb-0310-9956-ffa450edef68
Add a flag to configure to enable the Ev2 shims.  This is labeled as
experimental, and should be removed when Ev2 is eventually released.  Since
this won't happen in 1.8, and some of the items to support the shims might
impact performance, this allows us to enable / disable them throughout the
system much easier.

* subversion/libsvn_client/commit.c
  (get_ra_editor): Update macro name.

* subversion/libsvn_delta/compat.c
  (svn_editor__insert_shims): Same.

* configure.ac:
  Add support for '--enable-ev2-shims'.


git-svn-id: https://svn.apache.org/repos/asf/subversion/trunk@1308488 13f79535-47bb-0310-9956-ffa450edef68
Fix autogen warning.

* subversion/tests/libsvn_subr/crypto-test.c:
  svn_pools.h is not a system header (despite our hubris to the contrary).


git-svn-id: https://svn.apache.org/repos/asf/subversion/trunk@1308499 13f79535-47bb-0310-9956-ffa450edef68
Skip a test by skipping it, rather than by not-compiling it.

* subversion/tests/libsvn_subr/crypto-test.c
  (test_encrypt_decrypt_password): Rejigger ifdef's to make the test
    run and skip itself when !APU_HAVE_CRYPTO.


git-svn-id: https://svn.apache.org/repos/asf/subversion/trunk@1308503 13f79535-47bb-0310-9956-ffa450edef68