• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the OpenSSL license (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9 
10 #ifndef OPENSSL_HEADER_CONF_H
11 #define OPENSSL_HEADER_CONF_H
12 
13 #include <openssl/base.h>
14 
15 #include <openssl/stack.h>
16 #include <openssl/lhash.h>
17 
18 #if defined(__cplusplus)
19 extern "C" {
20 #endif
21 
22 
23 // Config files.
24 //
25 // This library handles OpenSSL's config files, which look like:
26 //
27 //   # Comment
28 //
29 //   # This key is in the default section.
30 //   key=value
31 //
32 //   [section_name]
33 //   key2=value2
34 //
35 // Config files are represented by a |CONF|. Use of this module is strongly
36 // discouraged. It is a remnant of the OpenSSL command-line tool. Parsing an
37 // untrusted input as a config file risks string injection and denial of service
38 // vulnerabilities.
39 
40 
41 struct conf_value_st {
42   char *section;
43   char *name;
44   char *value;
45 };
46 
47 DEFINE_STACK_OF(CONF_VALUE)
48 DECLARE_LHASH_OF(CONF_VALUE)
49 
50 
51 // NCONF_new returns a fresh, empty |CONF|, or NULL on error. The |method|
52 // argument must be NULL.
53 OPENSSL_EXPORT CONF *NCONF_new(void *method);
54 
55 // NCONF_free frees all the data owned by |conf| and then |conf| itself.
56 OPENSSL_EXPORT void NCONF_free(CONF *conf);
57 
58 // NCONF_load parses the file named |filename| and adds the values found to
59 // |conf|. It returns one on success and zero on error. In the event of an
60 // error, if |out_error_line| is not NULL, |*out_error_line| is set to the
61 // number of the line that contained the error.
62 OPENSSL_EXPORT int NCONF_load(CONF *conf, const char *filename,
63                               long *out_error_line);
64 
65 // NCONF_load_bio acts like |NCONF_load| but reads from |bio| rather than from
66 // a named file.
67 OPENSSL_EXPORT int NCONF_load_bio(CONF *conf, BIO *bio, long *out_error_line);
68 
69 // NCONF_get_section returns a stack of values for a given section in |conf|.
70 // If |section| is NULL, the default section is returned. It returns NULL on
71 // error.
72 OPENSSL_EXPORT const STACK_OF(CONF_VALUE) *NCONF_get_section(
73     const CONF *conf, const char *section);
74 
75 // NCONF_get_string returns the value of the key |name|, in section |section|.
76 // The |section| argument may be NULL to indicate the default section. It
77 // returns the value or NULL on error.
78 OPENSSL_EXPORT const char *NCONF_get_string(const CONF *conf,
79                                             const char *section,
80                                             const char *name);
81 
82 
83 // Deprecated functions
84 
85 // These defines do nothing but are provided to make old code easier to
86 // compile.
87 #define CONF_MFLAGS_DEFAULT_SECTION 0
88 #define CONF_MFLAGS_IGNORE_MISSING_FILE 0
89 
90 // CONF_modules_load_file returns one. BoringSSL is defined to have no config
91 // file options, thus loading from |filename| always succeeds by doing nothing.
92 OPENSSL_EXPORT int CONF_modules_load_file(const char *filename,
93                                           const char *appname,
94                                           unsigned long flags);
95 
96 // CONF_modules_free does nothing.
97 OPENSSL_EXPORT void CONF_modules_free(void);
98 
99 // OPENSSL_config does nothing.
100 OPENSSL_EXPORT void OPENSSL_config(const char *config_name);
101 
102 // OPENSSL_no_config does nothing.
103 OPENSSL_EXPORT void OPENSSL_no_config(void);
104 
105 
106 #if defined(__cplusplus)
107 }  // extern C
108 
109 extern "C++" {
110 
111 BSSL_NAMESPACE_BEGIN
112 
113 BORINGSSL_MAKE_DELETER(CONF, NCONF_free)
114 
115 BSSL_NAMESPACE_END
116 
117 }  // extern C++
118 
119 #endif
120 
121 #define CONF_R_LIST_CANNOT_BE_NULL 100
122 #define CONF_R_MISSING_CLOSE_SQUARE_BRACKET 101
123 #define CONF_R_MISSING_EQUAL_SIGN 102
124 #define CONF_R_NO_CLOSE_BRACE 103
125 #define CONF_R_UNABLE_TO_CREATE_NEW_SECTION 104
126 #define CONF_R_VARIABLE_HAS_NO_VALUE 105
127 #define CONF_R_VARIABLE_EXPANSION_TOO_LONG 106
128 #define CONF_R_VARIABLE_EXPANSION_NOT_SUPPORTED 107
129 
130 #endif  // OPENSSL_HEADER_THREAD_H
131