conf_sap.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright 2002-2023 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #include <stdio.h>
  10. #include <openssl/crypto.h>
  11. #include "internal/cryptlib.h"
  12. #include "internal/conf.h"
  13. #include "conf_local.h"
  14. #include <openssl/x509.h>
  15. #include <openssl/asn1.h>
  16. #include <openssl/engine.h>
  17. #if defined(_WIN32) && !defined(__BORLANDC__)
  18. # define strdup _strdup
  19. #endif
  20. /*
  21. * This is the automatic configuration loader: it is called automatically by
  22. * OpenSSL when any of a number of standard initialisation functions are
  23. * called, unless this is overridden by calling OPENSSL_no_config()
  24. */
  25. static int openssl_configured = 0;
  26. #ifndef OPENSSL_NO_DEPRECATED_1_1_0
  27. void OPENSSL_config(const char *appname)
  28. {
  29. OPENSSL_INIT_SETTINGS settings;
  30. memset(&settings, 0, sizeof(settings));
  31. if (appname != NULL)
  32. settings.appname = strdup(appname);
  33. settings.flags = DEFAULT_CONF_MFLAGS;
  34. OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG, &settings);
  35. }
  36. #endif
  37. int ossl_config_int(const OPENSSL_INIT_SETTINGS *settings)
  38. {
  39. int ret = 0;
  40. #if defined(OPENSSL_INIT_DEBUG) || !defined(OPENSSL_SYS_UEFI)
  41. const char *filename;
  42. const char *appname;
  43. unsigned long flags;
  44. #endif
  45. if (openssl_configured)
  46. return 1;
  47. #if defined(OPENSSL_INIT_DEBUG) || !defined(OPENSSL_SYS_UEFI)
  48. filename = settings ? settings->filename : NULL;
  49. appname = settings ? settings->appname : NULL;
  50. flags = settings ? settings->flags : DEFAULT_CONF_MFLAGS;
  51. #endif
  52. #ifdef OPENSSL_INIT_DEBUG
  53. fprintf(stderr, "OPENSSL_INIT: ossl_config_int(%s, %s, %lu)\n",
  54. filename, appname, flags);
  55. #endif
  56. #ifndef OPENSSL_SYS_UEFI
  57. ret = CONF_modules_load_file_ex(OSSL_LIB_CTX_get0_global_default(),
  58. filename, appname, flags);
  59. #else
  60. ret = 1;
  61. #endif
  62. openssl_configured = 1;
  63. return ret;
  64. }
  65. void ossl_no_config_int(void)
  66. {
  67. openssl_configured = 1;
  68. }