conf_sap.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright 2002-2020 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 <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. #ifndef OPENSSL_NO_DEPRECATED_1_1_0
  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. #ifndef OPENSSL_SYS_UEFI
  52. ret = CONF_modules_load_file(filename, appname, flags);
  53. #endif
  54. openssl_configured = 1;
  55. return ret;
  56. }
  57. void openssl_no_config_int(void)
  58. {
  59. openssl_configured = 1;
  60. }