conf_sap.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright 2002-2023 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the OpenSSL license (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 <openssl/x509.h>
  14. #include <openssl/asn1.h>
  15. #include <openssl/engine.h>
  16. #ifdef _WIN32
  17. # define strdup _strdup
  18. #endif
  19. /*
  20. * This is the automatic configuration loader: it is called automatically by
  21. * OpenSSL when any of a number of standard initialisation functions are
  22. * called, unless this is overridden by calling OPENSSL_no_config()
  23. */
  24. static int openssl_configured = 0;
  25. #if OPENSSL_API_COMPAT < 0x10100000L
  26. void OPENSSL_config(const char *appname)
  27. {
  28. OPENSSL_INIT_SETTINGS settings;
  29. memset(&settings, 0, sizeof(settings));
  30. if (appname != NULL)
  31. settings.appname = strdup(appname);
  32. settings.flags = DEFAULT_CONF_MFLAGS;
  33. OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG, &settings);
  34. }
  35. #endif
  36. int openssl_config_int(const OPENSSL_INIT_SETTINGS *settings)
  37. {
  38. int ret = 0;
  39. #if defined(OPENSSL_INIT_DEBUG) || !defined(OPENSSL_SYS_UEFI)
  40. const char *filename;
  41. const char *appname;
  42. unsigned long flags;
  43. #endif
  44. if (openssl_configured)
  45. return 1;
  46. #if defined(OPENSSL_INIT_DEBUG) || !defined(OPENSSL_SYS_UEFI)
  47. filename = settings ? settings->filename : NULL;
  48. appname = settings ? settings->appname : NULL;
  49. flags = settings ? settings->flags : DEFAULT_CONF_MFLAGS;
  50. #endif
  51. #ifdef OPENSSL_INIT_DEBUG
  52. fprintf(stderr, "OPENSSL_INIT: openssl_config_int(%s, %s, %lu)\n",
  53. filename, appname, flags);
  54. #endif
  55. OPENSSL_load_builtin_modules();
  56. #ifndef OPENSSL_NO_ENGINE
  57. /* Need to load ENGINEs */
  58. ENGINE_load_builtin_engines();
  59. #endif
  60. ERR_clear_error();
  61. #ifndef OPENSSL_SYS_UEFI
  62. ret = CONF_modules_load_file(filename, appname, flags);
  63. #endif
  64. openssl_configured = 1;
  65. return ret;
  66. }
  67. void openssl_no_config_int(void)
  68. {
  69. openssl_configured = 1;
  70. }