conf.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. #ifndef HEADER_CONF_H
  10. # define HEADER_CONF_H
  11. # include <openssl/bio.h>
  12. # include <openssl/lhash.h>
  13. # include <openssl/stack.h>
  14. # include <openssl/safestack.h>
  15. # include <openssl/e_os2.h>
  16. # include <openssl/ossl_typ.h>
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. typedef struct {
  21. char *section;
  22. char *name;
  23. char *value;
  24. } CONF_VALUE;
  25. DEFINE_STACK_OF(CONF_VALUE)
  26. DEFINE_LHASH_OF(CONF_VALUE);
  27. struct conf_st;
  28. struct conf_method_st;
  29. typedef struct conf_method_st CONF_METHOD;
  30. struct conf_method_st {
  31. const char *name;
  32. CONF *(*create) (CONF_METHOD *meth);
  33. int (*init) (CONF *conf);
  34. int (*destroy) (CONF *conf);
  35. int (*destroy_data) (CONF *conf);
  36. int (*load_bio) (CONF *conf, BIO *bp, long *eline);
  37. int (*dump) (const CONF *conf, BIO *bp);
  38. int (*is_number) (const CONF *conf, char c);
  39. int (*to_int) (const CONF *conf, char c);
  40. int (*load) (CONF *conf, const char *name, long *eline);
  41. };
  42. /* Module definitions */
  43. typedef struct conf_imodule_st CONF_IMODULE;
  44. typedef struct conf_module_st CONF_MODULE;
  45. DEFINE_STACK_OF(CONF_MODULE)
  46. DEFINE_STACK_OF(CONF_IMODULE)
  47. /* DSO module function typedefs */
  48. typedef int conf_init_func (CONF_IMODULE *md, const CONF *cnf);
  49. typedef void conf_finish_func (CONF_IMODULE *md);
  50. # define CONF_MFLAGS_IGNORE_ERRORS 0x1
  51. # define CONF_MFLAGS_IGNORE_RETURN_CODES 0x2
  52. # define CONF_MFLAGS_SILENT 0x4
  53. # define CONF_MFLAGS_NO_DSO 0x8
  54. # define CONF_MFLAGS_IGNORE_MISSING_FILE 0x10
  55. # define CONF_MFLAGS_DEFAULT_SECTION 0x20
  56. int CONF_set_default_method(CONF_METHOD *meth);
  57. void CONF_set_nconf(CONF *conf, LHASH_OF(CONF_VALUE) *hash);
  58. LHASH_OF(CONF_VALUE) *CONF_load(LHASH_OF(CONF_VALUE) *conf, const char *file,
  59. long *eline);
  60. # ifndef OPENSSL_NO_STDIO
  61. LHASH_OF(CONF_VALUE) *CONF_load_fp(LHASH_OF(CONF_VALUE) *conf, FILE *fp,
  62. long *eline);
  63. # endif
  64. LHASH_OF(CONF_VALUE) *CONF_load_bio(LHASH_OF(CONF_VALUE) *conf, BIO *bp,
  65. long *eline);
  66. STACK_OF(CONF_VALUE) *CONF_get_section(LHASH_OF(CONF_VALUE) *conf,
  67. const char *section);
  68. char *CONF_get_string(LHASH_OF(CONF_VALUE) *conf, const char *group,
  69. const char *name);
  70. long CONF_get_number(LHASH_OF(CONF_VALUE) *conf, const char *group,
  71. const char *name);
  72. void CONF_free(LHASH_OF(CONF_VALUE) *conf);
  73. #ifndef OPENSSL_NO_STDIO
  74. int CONF_dump_fp(LHASH_OF(CONF_VALUE) *conf, FILE *out);
  75. #endif
  76. int CONF_dump_bio(LHASH_OF(CONF_VALUE) *conf, BIO *out);
  77. DEPRECATEDIN_1_1_0(void OPENSSL_config(const char *config_name))
  78. #if OPENSSL_API_COMPAT < 0x10100000L
  79. # define OPENSSL_no_config() \
  80. OPENSSL_init_crypto(OPENSSL_INIT_NO_LOAD_CONFIG, NULL)
  81. #endif
  82. /*
  83. * New conf code. The semantics are different from the functions above. If
  84. * that wasn't the case, the above functions would have been replaced
  85. */
  86. struct conf_st {
  87. CONF_METHOD *meth;
  88. void *meth_data;
  89. LHASH_OF(CONF_VALUE) *data;
  90. };
  91. CONF *NCONF_new(CONF_METHOD *meth);
  92. CONF_METHOD *NCONF_default(void);
  93. CONF_METHOD *NCONF_WIN32(void);
  94. void NCONF_free(CONF *conf);
  95. void NCONF_free_data(CONF *conf);
  96. int NCONF_load(CONF *conf, const char *file, long *eline);
  97. # ifndef OPENSSL_NO_STDIO
  98. int NCONF_load_fp(CONF *conf, FILE *fp, long *eline);
  99. # endif
  100. int NCONF_load_bio(CONF *conf, BIO *bp, long *eline);
  101. STACK_OF(CONF_VALUE) *NCONF_get_section(const CONF *conf,
  102. const char *section);
  103. char *NCONF_get_string(const CONF *conf, const char *group, const char *name);
  104. int NCONF_get_number_e(const CONF *conf, const char *group, const char *name,
  105. long *result);
  106. #ifndef OPENSSL_NO_STDIO
  107. int NCONF_dump_fp(const CONF *conf, FILE *out);
  108. #endif
  109. int NCONF_dump_bio(const CONF *conf, BIO *out);
  110. #define NCONF_get_number(c,g,n,r) NCONF_get_number_e(c,g,n,r)
  111. /* Module functions */
  112. int CONF_modules_load(const CONF *cnf, const char *appname,
  113. unsigned long flags);
  114. int CONF_modules_load_file(const char *filename, const char *appname,
  115. unsigned long flags);
  116. void CONF_modules_unload(int all);
  117. void CONF_modules_finish(void);
  118. #if OPENSSL_API_COMPAT < 0x10100000L
  119. # define CONF_modules_free() while(0) continue
  120. #endif
  121. int CONF_module_add(const char *name, conf_init_func *ifunc,
  122. conf_finish_func *ffunc);
  123. const char *CONF_imodule_get_name(const CONF_IMODULE *md);
  124. const char *CONF_imodule_get_value(const CONF_IMODULE *md);
  125. void *CONF_imodule_get_usr_data(const CONF_IMODULE *md);
  126. void CONF_imodule_set_usr_data(CONF_IMODULE *md, void *usr_data);
  127. CONF_MODULE *CONF_imodule_get_module(const CONF_IMODULE *md);
  128. unsigned long CONF_imodule_get_flags(const CONF_IMODULE *md);
  129. void CONF_imodule_set_flags(CONF_IMODULE *md, unsigned long flags);
  130. void *CONF_module_get_usr_data(CONF_MODULE *pmod);
  131. void CONF_module_set_usr_data(CONF_MODULE *pmod, void *usr_data);
  132. char *CONF_get1_default_config_file(void);
  133. int CONF_parse_list(const char *list, int sep, int nospc,
  134. int (*list_cb) (const char *elem, int len, void *usr),
  135. void *arg);
  136. void OPENSSL_load_builtin_modules(void);
  137. /* BEGIN ERROR CODES */
  138. /*
  139. * The following lines are auto generated by the script mkerr.pl. Any changes
  140. * made after this point may be overwritten when the script is next run.
  141. */
  142. int ERR_load_CONF_strings(void);
  143. /* Error codes for the CONF functions. */
  144. /* Function codes. */
  145. # define CONF_F_CONF_DUMP_FP 104
  146. # define CONF_F_CONF_LOAD 100
  147. # define CONF_F_CONF_LOAD_FP 103
  148. # define CONF_F_CONF_PARSE_LIST 119
  149. # define CONF_F_DEF_LOAD 120
  150. # define CONF_F_DEF_LOAD_BIO 121
  151. # define CONF_F_MODULE_INIT 115
  152. # define CONF_F_MODULE_LOAD_DSO 117
  153. # define CONF_F_MODULE_RUN 118
  154. # define CONF_F_NCONF_DUMP_BIO 105
  155. # define CONF_F_NCONF_DUMP_FP 106
  156. # define CONF_F_NCONF_GET_NUMBER_E 112
  157. # define CONF_F_NCONF_GET_SECTION 108
  158. # define CONF_F_NCONF_GET_STRING 109
  159. # define CONF_F_NCONF_LOAD 113
  160. # define CONF_F_NCONF_LOAD_BIO 110
  161. # define CONF_F_NCONF_LOAD_FP 114
  162. # define CONF_F_NCONF_NEW 111
  163. # define CONF_F_STR_COPY 101
  164. /* Reason codes. */
  165. # define CONF_R_ERROR_LOADING_DSO 110
  166. # define CONF_R_LIST_CANNOT_BE_NULL 115
  167. # define CONF_R_MISSING_CLOSE_SQUARE_BRACKET 100
  168. # define CONF_R_MISSING_EQUAL_SIGN 101
  169. # define CONF_R_MISSING_INIT_FUNCTION 112
  170. # define CONF_R_MODULE_INITIALIZATION_ERROR 109
  171. # define CONF_R_NO_CLOSE_BRACE 102
  172. # define CONF_R_NO_CONF 105
  173. # define CONF_R_NO_CONF_OR_ENVIRONMENT_VARIABLE 106
  174. # define CONF_R_NO_SECTION 107
  175. # define CONF_R_NO_SUCH_FILE 114
  176. # define CONF_R_NO_VALUE 108
  177. # define CONF_R_UNABLE_TO_CREATE_NEW_SECTION 103
  178. # define CONF_R_UNKNOWN_MODULE_NAME 113
  179. # define CONF_R_VARIABLE_EXPANSION_TOO_LONG 116
  180. # define CONF_R_VARIABLE_HAS_NO_VALUE 104
  181. # ifdef __cplusplus
  182. }
  183. # endif
  184. #endif