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