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