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