CONF_modules_load_file.pod 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. =pod
  2. =head1 NAME
  3. CONF_modules_load_file_ex, CONF_modules_load_file, CONF_modules_load
  4. - OpenSSL configuration functions
  5. =head1 SYNOPSIS
  6. #include <openssl/conf.h>
  7. int CONF_modules_load_file_ex(OSSL_LIB_CTX *libctx, const char *filename,
  8. const char *appname, unsigned long flags);
  9. int CONF_modules_load_file(const char *filename, const char *appname,
  10. unsigned long flags);
  11. int CONF_modules_load(const CONF *cnf, const char *appname,
  12. unsigned long flags);
  13. =head1 DESCRIPTION
  14. The function CONF_modules_load_file_ex() configures OpenSSL using
  15. library context B<libctx> file B<filename> and application name B<appname>.
  16. If B<filename> is NULL the standard OpenSSL configuration file is used.
  17. If B<appname> is NULL the standard OpenSSL application name B<openssl_conf> is
  18. used.
  19. The behaviour can be customized using B<flags>. Note that, the error suppressing
  20. can be overriden by B<config_diagnostics> as described in L<config(5)>.
  21. CONF_modules_load_file() is the same as CONF_modules_load_file_ex() but
  22. has a NULL library context.
  23. CONF_modules_load() is identical to CONF_modules_load_file() except it
  24. reads configuration information from B<cnf>.
  25. =head1 NOTES
  26. The following B<flags> are currently recognized:
  27. If B<CONF_MFLAGS_IGNORE_ERRORS> is set errors returned by individual
  28. configuration modules are ignored. If not set the first module error is
  29. considered fatal and no further modules are loaded.
  30. Normally any modules errors will add error information to the error queue. If
  31. B<CONF_MFLAGS_SILENT> is set no error information is added.
  32. If B<CONF_MFLAGS_IGNORE_RETURN_CODES> is set the function unconditionally
  33. returns success.
  34. This is used by default in L<OPENSSL_init_crypto(3)> to ignore any errors in
  35. the default system-wide configuration file, as having all OpenSSL applications
  36. fail to start when there are potentially minor issues in the file is too risky.
  37. Applications calling B<CONF_modules_load_file_ex> explicitly should not
  38. generally set this flag.
  39. If B<CONF_MFLAGS_NO_DSO> is set configuration module loading from DSOs is
  40. disabled.
  41. B<CONF_MFLAGS_IGNORE_MISSING_FILE> if set will make CONF_load_modules_file()
  42. ignore missing configuration files. Normally a missing configuration file
  43. return an error.
  44. B<CONF_MFLAGS_DEFAULT_SECTION> if set and B<appname> is not NULL will use the
  45. default section pointed to by B<openssl_conf> if B<appname> does not exist.
  46. By using CONF_modules_load_file_ex() with appropriate flags an
  47. application can customise application configuration to best suit its needs.
  48. In some cases the use of a configuration file is optional and its absence is not
  49. an error: in this case B<CONF_MFLAGS_IGNORE_MISSING_FILE> would be set.
  50. Errors during configuration may also be handled differently by different
  51. applications. For example in some cases an error may simply print out a warning
  52. message and the application continue. In other cases an application might
  53. consider a configuration file error as fatal and exit immediately.
  54. Applications can use the CONF_modules_load() function if they wish to load a
  55. configuration file themselves and have finer control over how errors are
  56. treated.
  57. =head1 RETURN VALUES
  58. These functions return 1 for success and a zero or negative value for
  59. failure. If module errors are not ignored the return code will reflect the
  60. return value of the failing module (this will always be zero or negative).
  61. =head1 EXAMPLES
  62. Load a configuration file and print out any errors and exit (missing file
  63. considered fatal):
  64. if (CONF_modules_load_file_ex(libctx, NULL, NULL, 0) <= 0) {
  65. fprintf(stderr, "FATAL: error loading configuration file\n");
  66. ERR_print_errors_fp(stderr);
  67. exit(1);
  68. }
  69. Load default configuration file using the section indicated by "myapp",
  70. tolerate missing files, but exit on other errors:
  71. if (CONF_modules_load_file_ex(NULL, NULL, "myapp",
  72. CONF_MFLAGS_IGNORE_MISSING_FILE) <= 0) {
  73. fprintf(stderr, "FATAL: error loading configuration file\n");
  74. ERR_print_errors_fp(stderr);
  75. exit(1);
  76. }
  77. Load custom configuration file and section, only print warnings on error,
  78. missing configuration file ignored:
  79. if (CONF_modules_load_file_ex(NULL, "/something/app.cnf", "myapp",
  80. CONF_MFLAGS_IGNORE_MISSING_FILE) <= 0) {
  81. fprintf(stderr, "WARNING: error loading configuration file\n");
  82. ERR_print_errors_fp(stderr);
  83. }
  84. Load and parse configuration file manually, custom error handling:
  85. FILE *fp;
  86. CONF *cnf = NULL;
  87. long eline;
  88. fp = fopen("/somepath/app.cnf", "r");
  89. if (fp == NULL) {
  90. fprintf(stderr, "Error opening configuration file\n");
  91. /* Other missing configuration file behaviour */
  92. } else {
  93. cnf = NCONF_new_ex(libctx, NULL);
  94. if (NCONF_load_fp(cnf, fp, &eline) == 0) {
  95. fprintf(stderr, "Error on line %ld of configuration file\n", eline);
  96. ERR_print_errors_fp(stderr);
  97. /* Other malformed configuration file behaviour */
  98. } else if (CONF_modules_load(cnf, "appname", 0) <= 0) {
  99. fprintf(stderr, "Error configuring application\n");
  100. ERR_print_errors_fp(stderr);
  101. /* Other configuration error behaviour */
  102. }
  103. fclose(fp);
  104. NCONF_free(cnf);
  105. }
  106. =head1 SEE ALSO
  107. L<config(5)>,
  108. L<OPENSSL_config(3)>,
  109. L<NCONF_new_ex(3)>
  110. =head1 COPYRIGHT
  111. Copyright 2004-2020 The OpenSSL Project Authors. All Rights Reserved.
  112. Licensed under the Apache License 2.0 (the "License"). You may not use
  113. this file except in compliance with the License. You can obtain a copy
  114. in the file LICENSE in the source distribution or at
  115. L<https://www.openssl.org/source/license.html>.
  116. =cut