CONF_modules_load_file.pod 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. B<CONF_MFLAGS_IGNORE_ERRORS> if 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_NO_DSO> is set configuration module loading from DSOs is
  26. disabled.
  27. B<CONF_MFLAGS_IGNORE_MISSING_FILE> if set will make CONF_load_modules_file()
  28. ignore missing configuration files. Normally a missing configuration file
  29. return an error.
  30. B<CONF_MFLAGS_DEFAULT_SECTION> if set and B<appname> is not NULL will use the
  31. default section pointed to by B<openssl_conf> if B<appname> does not exist.
  32. By using CONF_modules_load_file() with appropriate flags an application can
  33. customise application configuration to best suit its needs. In some cases the
  34. use of a configuration file is optional and its absence is not an error: in
  35. this case B<CONF_MFLAGS_IGNORE_MISSING_FILE> would be set.
  36. Errors during configuration may also be handled differently by different
  37. applications. For example in some cases an error may simply print out a warning
  38. message and the application continue. In other cases an application might
  39. consider a configuration file error as fatal and exit immediately.
  40. Applications can use the CONF_modules_load() function if they wish to load a
  41. configuration file themselves and have finer control over how errors are
  42. treated.
  43. =head1 EXAMPLES
  44. Load a configuration file and print out any errors and exit (missing file
  45. considered fatal):
  46. if (CONF_modules_load_file(NULL, NULL, 0) <= 0) {
  47. fprintf(stderr, "FATAL: error loading configuration file\n");
  48. ERR_print_errors_fp(stderr);
  49. exit(1);
  50. }
  51. Load default configuration file using the section indicated by "myapp",
  52. tolerate missing files, but exit on other errors:
  53. if (CONF_modules_load_file(NULL, "myapp",
  54. CONF_MFLAGS_IGNORE_MISSING_FILE) <= 0) {
  55. fprintf(stderr, "FATAL: error loading configuration file\n");
  56. ERR_print_errors_fp(stderr);
  57. exit(1);
  58. }
  59. Load custom configuration file and section, only print warnings on error,
  60. missing configuration file ignored:
  61. if (CONF_modules_load_file("/something/app.cnf", "myapp",
  62. CONF_MFLAGS_IGNORE_MISSING_FILE) <= 0) {
  63. fprintf(stderr, "WARNING: error loading configuration file\n");
  64. ERR_print_errors_fp(stderr);
  65. }
  66. Load and parse configuration file manually, custom error handling:
  67. FILE *fp;
  68. CONF *cnf = NULL;
  69. long eline;
  70. fp = fopen("/somepath/app.cnf", "r");
  71. if (fp == NULL) {
  72. fprintf(stderr, "Error opening configuration file\n");
  73. /* Other missing configuration file behaviour */
  74. } else {
  75. cnf = NCONF_new(NULL);
  76. if (NCONF_load_fp(cnf, fp, &eline) == 0) {
  77. fprintf(stderr, "Error on line %ld of configuration file\n", eline);
  78. ERR_print_errors_fp(stderr);
  79. /* Other malformed configuration file behaviour */
  80. } else if (CONF_modules_load(cnf, "appname", 0) <= 0) {
  81. fprintf(stderr, "Error configuring application\n");
  82. ERR_print_errors_fp(stderr);
  83. /* Other configuration error behaviour */
  84. }
  85. fclose(fp);
  86. NCONF_free(cnf);
  87. }
  88. =head1 RETURN VALUES
  89. These functions return 1 for success and a zero or negative value for
  90. failure. If module errors are not ignored the return code will reflect the
  91. return value of the failing module (this will always be zero or negative).
  92. =head1 SEE ALSO
  93. L<config(5)>, L<OPENSSL_config(3)>
  94. =head1 COPYRIGHT
  95. Copyright 2004-2017 The OpenSSL Project Authors. All Rights Reserved.
  96. Licensed under the OpenSSL license (the "License"). You may not use
  97. this file except in compliance with the License. You can obtain a copy
  98. in the file LICENSE in the source distribution or at
  99. L<https://www.openssl.org/source/license.html>.
  100. =cut