CONF_modules_load_file.pod 5.1 KB

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