2
0

conf_sap.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Copyright 2002-2019 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. const char *filename;
  40. const char *appname;
  41. unsigned long flags;
  42. if (openssl_configured)
  43. return 1;
  44. filename = settings ? settings->filename : NULL;
  45. appname = settings ? settings->appname : NULL;
  46. flags = settings ? settings->flags : DEFAULT_CONF_MFLAGS;
  47. #ifdef OPENSSL_INIT_DEBUG
  48. fprintf(stderr, "OPENSSL_INIT: openssl_config_int(%s, %s, %lu)\n",
  49. filename, appname, flags);
  50. #endif
  51. OPENSSL_load_builtin_modules();
  52. #ifndef OPENSSL_NO_ENGINE
  53. /* Need to load ENGINEs */
  54. ENGINE_load_builtin_engines();
  55. #endif
  56. ERR_clear_error();
  57. #ifndef OPENSSL_SYS_UEFI
  58. ret = CONF_modules_load_file(filename, appname, flags);
  59. #endif
  60. openssl_configured = 1;
  61. return ret;
  62. }
  63. void openssl_no_config_int(void)
  64. {
  65. openssl_configured = 1;
  66. }