CONF_modules_load_file.3ossl 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. .\" -*- mode: troff; coding: utf-8 -*-
  2. .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43)
  3. .\"
  4. .\" Standard preamble:
  5. .\" ========================================================================
  6. .de Sp \" Vertical space (when we can't use .PP)
  7. .if t .sp .5v
  8. .if n .sp
  9. ..
  10. .de Vb \" Begin verbatim text
  11. .ft CW
  12. .nf
  13. .ne \\$1
  14. ..
  15. .de Ve \" End verbatim text
  16. .ft R
  17. .fi
  18. ..
  19. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
  20. .ie n \{\
  21. . ds C` ""
  22. . ds C' ""
  23. 'br\}
  24. .el\{\
  25. . ds C`
  26. . ds C'
  27. 'br\}
  28. .\"
  29. .\" Escape single quotes in literal strings from groff's Unicode transform.
  30. .ie \n(.g .ds Aq \(aq
  31. .el .ds Aq '
  32. .\"
  33. .\" If the F register is >0, we'll generate index entries on stderr for
  34. .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
  35. .\" entries marked with X<> in POD. Of course, you'll have to process the
  36. .\" output yourself in some meaningful fashion.
  37. .\"
  38. .\" Avoid warning from groff about undefined register 'F'.
  39. .de IX
  40. ..
  41. .nr rF 0
  42. .if \n(.g .if rF .nr rF 1
  43. .if (\n(rF:(\n(.g==0)) \{\
  44. . if \nF \{\
  45. . de IX
  46. . tm Index:\\$1\t\\n%\t"\\$2"
  47. ..
  48. . if !\nF==2 \{\
  49. . nr % 0
  50. . nr F 2
  51. . \}
  52. . \}
  53. .\}
  54. .rr rF
  55. .\" ========================================================================
  56. .\"
  57. .IX Title "CONF_MODULES_LOAD_FILE 3ossl"
  58. .TH CONF_MODULES_LOAD_FILE 3ossl 2025-01-17 3.4.0 OpenSSL
  59. .\" For nroff, turn off justification. Always turn off hyphenation; it makes
  60. .\" way too many mistakes in technical documents.
  61. .if n .ad l
  62. .nh
  63. .SH NAME
  64. CONF_get1_default_config_file,
  65. CONF_modules_load_file_ex, CONF_modules_load_file, CONF_modules_load
  66. \&\- OpenSSL configuration functions
  67. .SH SYNOPSIS
  68. .IX Header "SYNOPSIS"
  69. .Vb 1
  70. \& #include <openssl/conf.h>
  71. \&
  72. \& char *CONF_get1_default_config_file(void);
  73. \& int CONF_modules_load_file_ex(OSSL_LIB_CTX *libctx, const char *filename,
  74. \& const char *appname, unsigned long flags);
  75. \& int CONF_modules_load_file(const char *filename, const char *appname,
  76. \& unsigned long flags);
  77. \& int CONF_modules_load(const CONF *cnf, const char *appname,
  78. \& unsigned long flags);
  79. .Ve
  80. .SH DESCRIPTION
  81. .IX Header "DESCRIPTION"
  82. The function \fBCONF_get1_default_config_file()\fR determines the default
  83. configuration file pathname as follows.
  84. If the \fBOPENSSL_CONF\fR environment variable is set its value is returned.
  85. Else the function returns the path obtained using
  86. \&\fBX509_get_default_cert_area\fR\|(3) with the filename \f(CW"openssl.cnf"\fR appended.
  87. The caller is responsible for freeing any string returned.
  88. .PP
  89. The function \fBCONF_modules_load_file_ex()\fR configures OpenSSL using
  90. library context \fBlibctx\fR file \fBfilename\fR and application name \fBappname\fR.
  91. If \fBfilename\fR is NULL the standard OpenSSL configuration file is used
  92. as determined by calling \fBCONF_get1_default_config_file()\fR.
  93. If \fBappname\fR is NULL the standard OpenSSL application name \fBopenssl_conf\fR is
  94. used.
  95. The behaviour can be customized using \fBflags\fR. Note that, the error suppressing
  96. can be overridden by \fBconfig_diagnostics\fR as described in \fBconfig\fR\|(5).
  97. .PP
  98. \&\fBCONF_modules_load_file()\fR is the same as \fBCONF_modules_load_file_ex()\fR but
  99. has a NULL library context.
  100. .PP
  101. \&\fBCONF_modules_load()\fR is identical to \fBCONF_modules_load_file()\fR except it
  102. reads configuration information from \fBcnf\fR.
  103. .SH NOTES
  104. .IX Header "NOTES"
  105. The following \fBflags\fR are currently recognized:
  106. .PP
  107. If \fBCONF_MFLAGS_IGNORE_ERRORS\fR is set errors returned by individual
  108. configuration modules are ignored. If not set the first module error is
  109. considered fatal and no further modules are loaded.
  110. .PP
  111. Normally any modules errors will add error information to the error queue. If
  112. \&\fBCONF_MFLAGS_SILENT\fR is set no error information is added.
  113. .PP
  114. If \fBCONF_MFLAGS_IGNORE_RETURN_CODES\fR is set the function unconditionally
  115. returns success.
  116. This is used by default in \fBOPENSSL_init_crypto\fR\|(3) to ignore any errors in
  117. the default system-wide configuration file, as having all OpenSSL applications
  118. fail to start when there are potentially minor issues in the file is too risky.
  119. Applications calling \fBCONF_modules_load_file_ex\fR explicitly should not
  120. generally set this flag.
  121. .PP
  122. If \fBCONF_MFLAGS_NO_DSO\fR is set configuration module loading from DSOs is
  123. disabled.
  124. .PP
  125. \&\fBCONF_MFLAGS_IGNORE_MISSING_FILE\fR if set will make \fBCONF_load_modules_file()\fR
  126. ignore missing configuration files. Normally a missing configuration file
  127. return an error.
  128. .PP
  129. \&\fBCONF_MFLAGS_DEFAULT_SECTION\fR if set and \fBappname\fR is not NULL will use the
  130. default section pointed to by \fBopenssl_conf\fR if \fBappname\fR does not exist.
  131. .PP
  132. By using \fBCONF_modules_load_file_ex()\fR with appropriate flags an
  133. application can customise application configuration to best suit its needs.
  134. In some cases the use of a configuration file is optional and its absence is not
  135. an error: in this case \fBCONF_MFLAGS_IGNORE_MISSING_FILE\fR would be set.
  136. .PP
  137. Errors during configuration may also be handled differently by different
  138. applications. For example in some cases an error may simply print out a warning
  139. message and the application continue. In other cases an application might
  140. consider a configuration file error as fatal and exit immediately.
  141. .PP
  142. Applications can use the \fBCONF_modules_load()\fR function if they wish to load a
  143. configuration file themselves and have finer control over how errors are
  144. treated.
  145. .SH "RETURN VALUES"
  146. .IX Header "RETURN VALUES"
  147. These functions return 1 for success and a zero or negative value for
  148. failure. If module errors are not ignored the return code will reflect the
  149. return value of the failing module (this will always be zero or negative).
  150. .SH EXAMPLES
  151. .IX Header "EXAMPLES"
  152. Load a configuration file and print out any errors and exit (missing file
  153. considered fatal):
  154. .PP
  155. .Vb 5
  156. \& if (CONF_modules_load_file_ex(libctx, NULL, NULL, 0) <= 0) {
  157. \& fprintf(stderr, "FATAL: error loading configuration file\en");
  158. \& ERR_print_errors_fp(stderr);
  159. \& exit(1);
  160. \& }
  161. .Ve
  162. .PP
  163. Load default configuration file using the section indicated by "myapp",
  164. tolerate missing files, but exit on other errors:
  165. .PP
  166. .Vb 6
  167. \& if (CONF_modules_load_file_ex(NULL, NULL, "myapp",
  168. \& CONF_MFLAGS_IGNORE_MISSING_FILE) <= 0) {
  169. \& fprintf(stderr, "FATAL: error loading configuration file\en");
  170. \& ERR_print_errors_fp(stderr);
  171. \& exit(1);
  172. \& }
  173. .Ve
  174. .PP
  175. Load custom configuration file and section, only print warnings on error,
  176. missing configuration file ignored:
  177. .PP
  178. .Vb 5
  179. \& if (CONF_modules_load_file_ex(NULL, "/something/app.cnf", "myapp",
  180. \& CONF_MFLAGS_IGNORE_MISSING_FILE) <= 0) {
  181. \& fprintf(stderr, "WARNING: error loading configuration file\en");
  182. \& ERR_print_errors_fp(stderr);
  183. \& }
  184. .Ve
  185. .PP
  186. Load and parse configuration file manually, custom error handling:
  187. .PP
  188. .Vb 3
  189. \& FILE *fp;
  190. \& CONF *cnf = NULL;
  191. \& long eline;
  192. \&
  193. \& fp = fopen("/somepath/app.cnf", "r");
  194. \& if (fp == NULL) {
  195. \& fprintf(stderr, "Error opening configuration file\en");
  196. \& /* Other missing configuration file behaviour */
  197. \& } else {
  198. \& cnf = NCONF_new_ex(libctx, NULL);
  199. \& if (NCONF_load_fp(cnf, fp, &eline) == 0) {
  200. \& fprintf(stderr, "Error on line %ld of configuration file\en", eline);
  201. \& ERR_print_errors_fp(stderr);
  202. \& /* Other malformed configuration file behaviour */
  203. \& } else if (CONF_modules_load(cnf, "appname", 0) <= 0) {
  204. \& fprintf(stderr, "Error configuring application\en");
  205. \& ERR_print_errors_fp(stderr);
  206. \& /* Other configuration error behaviour */
  207. \& }
  208. \& fclose(fp);
  209. \& NCONF_free(cnf);
  210. \& }
  211. .Ve
  212. .SH "SEE ALSO"
  213. .IX Header "SEE ALSO"
  214. \&\fBconfig\fR\|(5),
  215. \&\fBOPENSSL_config\fR\|(3),
  216. \&\fBNCONF_new_ex\fR\|(3)
  217. .SH COPYRIGHT
  218. .IX Header "COPYRIGHT"
  219. Copyright 2004\-2022 The OpenSSL Project Authors. All Rights Reserved.
  220. .PP
  221. Licensed under the Apache License 2.0 (the "License"). You may not use
  222. this file except in compliance with the License. You can obtain a copy
  223. in the file LICENSE in the source distribution or at
  224. <https://www.openssl.org/source/license.html>.