conf_sap.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright 2002-2024 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. free(settings.appname);
  36. }
  37. #endif
  38. int ossl_config_int(const OPENSSL_INIT_SETTINGS *settings)
  39. {
  40. int ret = 0;
  41. #if defined(OPENSSL_INIT_DEBUG) || !defined(OPENSSL_SYS_UEFI)
  42. const char *filename;
  43. const char *appname;
  44. unsigned long flags;
  45. #endif
  46. if (openssl_configured)
  47. return 1;
  48. #if defined(OPENSSL_INIT_DEBUG) || !defined(OPENSSL_SYS_UEFI)
  49. filename = settings ? settings->filename : NULL;
  50. appname = settings ? settings->appname : NULL;
  51. flags = settings ? settings->flags : DEFAULT_CONF_MFLAGS;
  52. #endif
  53. #ifdef OPENSSL_INIT_DEBUG
  54. fprintf(stderr, "OPENSSL_INIT: ossl_config_int(%s, %s, %lu)\n",
  55. filename, appname, flags);
  56. #endif
  57. #ifndef OPENSSL_SYS_UEFI
  58. ret = CONF_modules_load_file_ex(OSSL_LIB_CTX_get0_global_default(),
  59. filename, appname, flags);
  60. #else
  61. ret = 1;
  62. #endif
  63. openssl_configured = 1;
  64. return ret;
  65. }
  66. void ossl_no_config_int(void)
  67. {
  68. openssl_configured = 1;
  69. }