CONF_modules_load_file.pod 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 cutomized using B<flags>.
  16. CONF_modules_load() is idential 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. Applications should call these functions after loading builtin modules using
  33. OPENSSL_load_builtin_modules(), any ENGINEs for example using
  34. ENGINE_load_builtin_engines(), any algorithms for example
  35. OPENSSL_add_all_algorithms() and (if the application uses libssl)
  36. SSL_library_init().
  37. By using CONF_modules_load_file() with appropriate flags an application can
  38. customise application configuration to best suit its needs. In some cases the
  39. use of a configuration file is optional and its absence is not an error: in
  40. this case B<CONF_MFLAGS_IGNORE_MISSING_FILE> would be set.
  41. Errors during configuration may also be handled differently by different
  42. applications. For example in some cases an error may simply print out a warning
  43. message and the application continue. In other cases an application might
  44. consider a configuration file error as fatal and exit immediately.
  45. Applications can use the CONF_modules_load() function if they wish to load a
  46. configuration file themselves and have finer control over how errors are
  47. treated.
  48. =head1 EXAMPLES
  49. Load a configuration file and print out any errors and exit (missing file
  50. considered fatal):
  51. if (CONF_modules_load_file(NULL, NULL, 0) <= 0) {
  52. fprintf(stderr, "FATAL: error loading configuration file\n");
  53. ERR_print_errors_fp(stderr);
  54. exit(1);
  55. }
  56. Load default configuration file using the section indicated by "myapp",
  57. tolerate missing files, but exit on other errors:
  58. if (CONF_modules_load_file(NULL, "myapp",
  59. CONF_MFLAGS_IGNORE_MISSING_FILE) <= 0) {
  60. fprintf(stderr, "FATAL: error loading configuration file\n");
  61. ERR_print_errors_fp(stderr);
  62. exit(1);
  63. }
  64. Load custom configuration file and section, only print warnings on error,
  65. missing configuration file ignored:
  66. if (CONF_modules_load_file("/something/app.cnf", "myapp",
  67. CONF_MFLAGS_IGNORE_MISSING_FILE) <= 0) {
  68. fprintf(stderr, "WARNING: error loading configuration file\n");
  69. ERR_print_errors_fp(stderr);
  70. }
  71. Load and parse configuration file manually, custom error handling:
  72. FILE *fp;
  73. CONF *cnf = NULL;
  74. long eline;
  75. fp = fopen("/somepath/app.cnf", "r");
  76. if (fp == NULL) {
  77. fprintf(stderr, "Error opening configuration file\n");
  78. /* Other missing configuration file behaviour */
  79. } else {
  80. cnf = NCONF_new(NULL);
  81. if (NCONF_load_fp(cnf, fp, &eline) == 0) {
  82. fprintf(stderr, "Error on line %ld of configuration file\n", eline);
  83. ERR_print_errors_fp(stderr);
  84. /* Other malformed configuration file behaviour */
  85. } else if (CONF_modules_load(cnf, "appname", 0) <= 0) {
  86. fprintf(stderr, "Error configuring application\n");
  87. ERR_print_errors_fp(stderr);
  88. /* Other configuration error behaviour */
  89. }
  90. fclose(fp);
  91. NCONF_free(cnf);
  92. }
  93. =head1 RETURN VALUES
  94. These functions return 1 for success and a zero or negative value for
  95. failure. If module errors are not ignored the return code will reflect the
  96. return value of the failing module (this will always be zero or negative).
  97. =head1 SEE ALSO
  98. L<conf(5)|conf(5)>, L<OPENSSL_config(3)|OPENSSL_config(3)>,
  99. L<CONF_free(3)|CONF_free(3)>, L<err(3)|err(3)>
  100. =head1 HISTORY
  101. CONF_modules_load_file and CONF_modules_load first appeared in OpenSSL 0.9.7.
  102. =cut