| OLD | NEW |
| 1 /* conf_api.c */ | 1 /* conf_api.c */ |
| 2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 * All rights reserved. | 3 * All rights reserved. |
| 4 * | 4 * |
| 5 * This package is an SSL implementation written | 5 * This package is an SSL implementation written |
| 6 * by Eric Young (eay@cryptsoft.com). | 6 * by Eric Young (eay@cryptsoft.com). |
| 7 * The implementation was written so as to conform with Netscapes SSL. | 7 * The implementation was written so as to conform with Netscapes SSL. |
| 8 * | 8 * |
| 9 * This library is free for commercial and non-commercial use as long as | 9 * This library is free for commercial and non-commercial use as long as |
| 10 * the following conditions are aheared to. The following conditions | 10 * the following conditions are aheared to. The following conditions |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 */ | 57 */ |
| 58 | 58 |
| 59 /* Part of the code in here was originally in conf.c, which is now removed */ | 59 /* Part of the code in here was originally in conf.c, which is now removed */ |
| 60 | 60 |
| 61 #ifndef CONF_DEBUG | 61 #ifndef CONF_DEBUG |
| 62 # undef NDEBUG /* avoid conflicting definitions */ | 62 # undef NDEBUG /* avoid conflicting definitions */ |
| 63 # define NDEBUG | 63 # define NDEBUG |
| 64 #endif | 64 #endif |
| 65 | 65 |
| 66 #include <assert.h> | 66 #include <assert.h> |
| 67 #include <stdlib.h> |
| 67 #include <string.h> | 68 #include <string.h> |
| 68 #include <openssl/conf.h> | 69 #include <openssl/conf.h> |
| 69 #include <openssl/conf_api.h> | 70 #include <openssl/conf_api.h> |
| 70 #include "e_os.h" | 71 #include "e_os.h" |
| 71 | 72 |
| 72 static void value_free_hash(CONF_VALUE *a, LHASH *conf); | 73 static void value_free_hash_doall_arg(CONF_VALUE *a, |
| 73 static void value_free_stack(CONF_VALUE *a,LHASH *conf); | 74 » » » » LHASH_OF(CONF_VALUE) *conf); |
| 74 static IMPLEMENT_LHASH_DOALL_ARG_FN(value_free_hash, CONF_VALUE *, LHASH *) | 75 static void value_free_stack_doall(CONF_VALUE *a); |
| 75 static IMPLEMENT_LHASH_DOALL_ARG_FN(value_free_stack, CONF_VALUE *, LHASH *) | 76 static IMPLEMENT_LHASH_DOALL_ARG_FN(value_free_hash, CONF_VALUE, |
| 76 /* We don't use function pointer casting or wrapper functions - but cast each | 77 » » » » LHASH_OF(CONF_VALUE)) |
| 77 * callback parameter inside the callback functions. */ | 78 static IMPLEMENT_LHASH_DOALL_FN(value_free_stack, CONF_VALUE) |
| 78 /* static unsigned long hash(CONF_VALUE *v); */ | |
| 79 static unsigned long hash(const void *v_void); | |
| 80 /* static int cmp_conf(CONF_VALUE *a,CONF_VALUE *b); */ | |
| 81 static int cmp_conf(const void *a_void,const void *b_void); | |
| 82 | 79 |
| 83 /* Up until OpenSSL 0.9.5a, this was get_section */ | 80 /* Up until OpenSSL 0.9.5a, this was get_section */ |
| 84 CONF_VALUE *_CONF_get_section(const CONF *conf, const char *section) | 81 CONF_VALUE *_CONF_get_section(const CONF *conf, const char *section) |
| 85 { | 82 { |
| 86 CONF_VALUE *v,vv; | 83 CONF_VALUE *v,vv; |
| 87 | 84 |
| 88 if ((conf == NULL) || (section == NULL)) return(NULL); | 85 if ((conf == NULL) || (section == NULL)) return(NULL); |
| 89 vv.name=NULL; | 86 vv.name=NULL; |
| 90 vv.section=(char *)section; | 87 vv.section=(char *)section; |
| 91 » v=(CONF_VALUE *)lh_retrieve(conf->data,&vv); | 88 » v=lh_CONF_VALUE_retrieve(conf->data,&vv); |
| 92 return(v); | 89 return(v); |
| 93 } | 90 } |
| 94 | 91 |
| 95 /* Up until OpenSSL 0.9.5a, this was CONF_get_section */ | 92 /* Up until OpenSSL 0.9.5a, this was CONF_get_section */ |
| 96 STACK_OF(CONF_VALUE) *_CONF_get_section_values(const CONF *conf, | 93 STACK_OF(CONF_VALUE) *_CONF_get_section_values(const CONF *conf, |
| 97 const char *section) | 94 const char *section) |
| 98 { | 95 { |
| 99 CONF_VALUE *v; | 96 CONF_VALUE *v; |
| 100 | 97 |
| 101 v=_CONF_get_section(conf,section); | 98 v=_CONF_get_section(conf,section); |
| 102 if (v != NULL) | 99 if (v != NULL) |
| 103 return((STACK_OF(CONF_VALUE) *)v->value); | 100 return((STACK_OF(CONF_VALUE) *)v->value); |
| 104 else | 101 else |
| 105 return(NULL); | 102 return(NULL); |
| 106 } | 103 } |
| 107 | 104 |
| 108 int _CONF_add_string(CONF *conf, CONF_VALUE *section, CONF_VALUE *value) | 105 int _CONF_add_string(CONF *conf, CONF_VALUE *section, CONF_VALUE *value) |
| 109 { | 106 { |
| 110 CONF_VALUE *v = NULL; | 107 CONF_VALUE *v = NULL; |
| 111 STACK_OF(CONF_VALUE) *ts; | 108 STACK_OF(CONF_VALUE) *ts; |
| 112 | 109 |
| 113 ts = (STACK_OF(CONF_VALUE) *)section->value; | 110 ts = (STACK_OF(CONF_VALUE) *)section->value; |
| 114 | 111 |
| 115 value->section=section->section; | 112 value->section=section->section; |
| 116 if (!sk_CONF_VALUE_push(ts,value)) | 113 if (!sk_CONF_VALUE_push(ts,value)) |
| 117 { | 114 { |
| 118 return 0; | 115 return 0; |
| 119 } | 116 } |
| 120 | 117 |
| 121 » v = (CONF_VALUE *)lh_insert(conf->data, value); | 118 » v = lh_CONF_VALUE_insert(conf->data, value); |
| 122 if (v != NULL) | 119 if (v != NULL) |
| 123 { | 120 { |
| 124 (void)sk_CONF_VALUE_delete_ptr(ts,v); | 121 (void)sk_CONF_VALUE_delete_ptr(ts,v); |
| 125 OPENSSL_free(v->name); | 122 OPENSSL_free(v->name); |
| 126 OPENSSL_free(v->value); | 123 OPENSSL_free(v->value); |
| 127 OPENSSL_free(v); | 124 OPENSSL_free(v); |
| 128 } | 125 } |
| 129 return 1; | 126 return 1; |
| 130 } | 127 } |
| 131 | 128 |
| 132 char *_CONF_get_string(const CONF *conf, const char *section, const char *name) | 129 char *_CONF_get_string(const CONF *conf, const char *section, const char *name) |
| 133 { | 130 { |
| 134 CONF_VALUE *v,vv; | 131 CONF_VALUE *v,vv; |
| 135 char *p; | 132 char *p; |
| 136 | 133 |
| 137 if (name == NULL) return(NULL); | 134 if (name == NULL) return(NULL); |
| 138 if (conf != NULL) | 135 if (conf != NULL) |
| 139 { | 136 { |
| 140 if (section != NULL) | 137 if (section != NULL) |
| 141 { | 138 { |
| 142 vv.name=(char *)name; | 139 vv.name=(char *)name; |
| 143 vv.section=(char *)section; | 140 vv.section=(char *)section; |
| 144 » » » v=(CONF_VALUE *)lh_retrieve(conf->data,&vv); | 141 » » » v=lh_CONF_VALUE_retrieve(conf->data,&vv); |
| 145 if (v != NULL) return(v->value); | 142 if (v != NULL) return(v->value); |
| 146 if (strcmp(section,"ENV") == 0) | 143 if (strcmp(section,"ENV") == 0) |
| 147 { | 144 { |
| 148 » » » » p=Getenv(name); | 145 » » » » p=getenv(name); |
| 149 if (p != NULL) return(p); | 146 if (p != NULL) return(p); |
| 150 } | 147 } |
| 151 } | 148 } |
| 152 vv.section="default"; | 149 vv.section="default"; |
| 153 vv.name=(char *)name; | 150 vv.name=(char *)name; |
| 154 » » v=(CONF_VALUE *)lh_retrieve(conf->data,&vv); | 151 » » v=lh_CONF_VALUE_retrieve(conf->data,&vv); |
| 155 if (v != NULL) | 152 if (v != NULL) |
| 156 return(v->value); | 153 return(v->value); |
| 157 else | 154 else |
| 158 return(NULL); | 155 return(NULL); |
| 159 } | 156 } |
| 160 else | 157 else |
| 161 » » return(Getenv(name)); | 158 » » return(getenv(name)); |
| 162 } | 159 } |
| 163 | 160 |
| 164 #if 0 /* There's no way to provide error checking with this function, so | 161 #if 0 /* There's no way to provide error checking with this function, so |
| 165 force implementors of the higher levels to get a string and read | 162 force implementors of the higher levels to get a string and read |
| 166 the number themselves. */ | 163 the number themselves. */ |
| 167 long _CONF_get_number(CONF *conf, char *section, char *name) | 164 long _CONF_get_number(CONF *conf, char *section, char *name) |
| 168 { | 165 { |
| 169 char *str; | 166 char *str; |
| 170 long ret=0; | 167 long ret=0; |
| 171 | 168 |
| 172 str=_CONF_get_string(conf,section,name); | 169 str=_CONF_get_string(conf,section,name); |
| 173 if (str == NULL) return(0); | 170 if (str == NULL) return(0); |
| 174 for (;;) | 171 for (;;) |
| 175 { | 172 { |
| 176 if (conf->meth->is_number(conf, *str)) | 173 if (conf->meth->is_number(conf, *str)) |
| 177 ret=ret*10+conf->meth->to_int(conf, *str); | 174 ret=ret*10+conf->meth->to_int(conf, *str); |
| 178 else | 175 else |
| 179 return(ret); | 176 return(ret); |
| 180 str++; | 177 str++; |
| 181 } | 178 } |
| 182 } | 179 } |
| 183 #endif | 180 #endif |
| 184 | 181 |
| 182 static unsigned long conf_value_hash(const CONF_VALUE *v) |
| 183 { |
| 184 return (lh_strhash(v->section)<<2)^lh_strhash(v->name); |
| 185 } |
| 186 static IMPLEMENT_LHASH_HASH_FN(conf_value, CONF_VALUE) |
| 187 |
| 188 static int conf_value_cmp(const CONF_VALUE *a, const CONF_VALUE *b) |
| 189 { |
| 190 int i; |
| 191 |
| 192 if (a->section != b->section) |
| 193 { |
| 194 i=strcmp(a->section,b->section); |
| 195 if (i) return(i); |
| 196 } |
| 197 |
| 198 if ((a->name != NULL) && (b->name != NULL)) |
| 199 { |
| 200 i=strcmp(a->name,b->name); |
| 201 return(i); |
| 202 } |
| 203 else if (a->name == b->name) |
| 204 return(0); |
| 205 else |
| 206 return((a->name == NULL)?-1:1); |
| 207 } |
| 208 static IMPLEMENT_LHASH_COMP_FN(conf_value, CONF_VALUE) |
| 209 |
| 185 int _CONF_new_data(CONF *conf) | 210 int _CONF_new_data(CONF *conf) |
| 186 { | 211 { |
| 187 if (conf == NULL) | 212 if (conf == NULL) |
| 188 { | 213 { |
| 189 return 0; | 214 return 0; |
| 190 } | 215 } |
| 191 if (conf->data == NULL) | 216 if (conf->data == NULL) |
| 192 » » if ((conf->data = lh_new(hash, cmp_conf)) == NULL) | 217 » » if ((conf->data = lh_CONF_VALUE_new()) == NULL) |
| 193 { | 218 { |
| 194 return 0; | 219 return 0; |
| 195 } | 220 } |
| 196 return 1; | 221 return 1; |
| 197 } | 222 } |
| 198 | 223 |
| 199 void _CONF_free_data(CONF *conf) | 224 void _CONF_free_data(CONF *conf) |
| 200 { | 225 { |
| 201 if (conf == NULL || conf->data == NULL) return; | 226 if (conf == NULL || conf->data == NULL) return; |
| 202 | 227 |
| 203 » conf->data->down_load=0; /* evil thing to make sure the 'OPENSSL_free()' | 228 » lh_CONF_VALUE_down_load(conf->data)=0; /* evil thing to make |
| 204 » » » » * works as expected */ | 229 » » » » * sure the 'OPENSSL_free()' works as |
| 205 » lh_doall_arg(conf->data, LHASH_DOALL_ARG_FN(value_free_hash), | 230 » » » » * expected */ |
| 206 » » » conf->data); | 231 » lh_CONF_VALUE_doall_arg(conf->data, |
| 232 » » » » LHASH_DOALL_ARG_FN(value_free_hash), |
| 233 » » » » LHASH_OF(CONF_VALUE), conf->data); |
| 207 | 234 |
| 208 /* We now have only 'section' entries in the hash table. | 235 /* We now have only 'section' entries in the hash table. |
| 209 * Due to problems with */ | 236 * Due to problems with */ |
| 210 | 237 |
| 211 » lh_doall_arg(conf->data, LHASH_DOALL_ARG_FN(value_free_stack), | 238 » lh_CONF_VALUE_doall(conf->data, LHASH_DOALL_FN(value_free_stack)); |
| 212 » » » conf->data); | 239 » lh_CONF_VALUE_free(conf->data); |
| 213 » lh_free(conf->data); | |
| 214 } | 240 } |
| 215 | 241 |
| 216 static void value_free_hash(CONF_VALUE *a, LHASH *conf) | 242 static void value_free_hash_doall_arg(CONF_VALUE *a, LHASH_OF(CONF_VALUE) *conf) |
| 217 { | 243 { |
| 218 if (a->name != NULL) | 244 if (a->name != NULL) |
| 219 » » { | 245 » » (void)lh_CONF_VALUE_delete(conf,a); |
| 220 » » a=(CONF_VALUE *)lh_delete(conf,a); | |
| 221 » » } | |
| 222 } | 246 } |
| 223 | 247 |
| 224 static void value_free_stack(CONF_VALUE *a, LHASH *conf) | 248 static void value_free_stack_doall(CONF_VALUE *a) |
| 225 { | 249 { |
| 226 CONF_VALUE *vv; | 250 CONF_VALUE *vv; |
| 227 » STACK *sk; | 251 » STACK_OF(CONF_VALUE) *sk; |
| 228 int i; | 252 int i; |
| 229 | 253 |
| 230 if (a->name != NULL) return; | 254 if (a->name != NULL) return; |
| 231 | 255 |
| 232 » sk=(STACK *)a->value; | 256 » sk=(STACK_OF(CONF_VALUE) *)a->value; |
| 233 » for (i=sk_num(sk)-1; i>=0; i--) | 257 » for (i=sk_CONF_VALUE_num(sk)-1; i>=0; i--) |
| 234 { | 258 { |
| 235 » » vv=(CONF_VALUE *)sk_value(sk,i); | 259 » » vv=sk_CONF_VALUE_value(sk,i); |
| 236 OPENSSL_free(vv->value); | 260 OPENSSL_free(vv->value); |
| 237 OPENSSL_free(vv->name); | 261 OPENSSL_free(vv->name); |
| 238 OPENSSL_free(vv); | 262 OPENSSL_free(vv); |
| 239 } | 263 } |
| 240 » if (sk != NULL) sk_free(sk); | 264 » if (sk != NULL) sk_CONF_VALUE_free(sk); |
| 241 OPENSSL_free(a->section); | 265 OPENSSL_free(a->section); |
| 242 OPENSSL_free(a); | 266 OPENSSL_free(a); |
| 243 } | 267 } |
| 244 | 268 |
| 245 /* static unsigned long hash(CONF_VALUE *v) */ | |
| 246 static unsigned long hash(const void *v_void) | |
| 247 { | |
| 248 CONF_VALUE *v = (CONF_VALUE *)v_void; | |
| 249 return((lh_strhash(v->section)<<2)^lh_strhash(v->name)); | |
| 250 } | |
| 251 | |
| 252 /* static int cmp_conf(CONF_VALUE *a, CONF_VALUE *b) */ | |
| 253 static int cmp_conf(const void *a_void,const void *b_void) | |
| 254 { | |
| 255 int i; | |
| 256 CONF_VALUE *a = (CONF_VALUE *)a_void; | |
| 257 CONF_VALUE *b = (CONF_VALUE *)b_void; | |
| 258 | |
| 259 if (a->section != b->section) | |
| 260 { | |
| 261 i=strcmp(a->section,b->section); | |
| 262 if (i) return(i); | |
| 263 } | |
| 264 | |
| 265 if ((a->name != NULL) && (b->name != NULL)) | |
| 266 { | |
| 267 i=strcmp(a->name,b->name); | |
| 268 return(i); | |
| 269 } | |
| 270 else if (a->name == b->name) | |
| 271 return(0); | |
| 272 else | |
| 273 return((a->name == NULL)?-1:1); | |
| 274 } | |
| 275 | |
| 276 /* Up until OpenSSL 0.9.5a, this was new_section */ | 269 /* Up until OpenSSL 0.9.5a, this was new_section */ |
| 277 CONF_VALUE *_CONF_new_section(CONF *conf, const char *section) | 270 CONF_VALUE *_CONF_new_section(CONF *conf, const char *section) |
| 278 { | 271 { |
| 279 » STACK *sk=NULL; | 272 » STACK_OF(CONF_VALUE) *sk=NULL; |
| 280 int ok=0,i; | 273 int ok=0,i; |
| 281 CONF_VALUE *v=NULL,*vv; | 274 CONF_VALUE *v=NULL,*vv; |
| 282 | 275 |
| 283 » if ((sk=sk_new_null()) == NULL) | 276 » if ((sk=sk_CONF_VALUE_new_null()) == NULL) |
| 284 goto err; | 277 goto err; |
| 285 » if ((v=(CONF_VALUE *)OPENSSL_malloc(sizeof(CONF_VALUE))) == NULL) | 278 » if ((v=OPENSSL_malloc(sizeof(CONF_VALUE))) == NULL) |
| 286 goto err; | 279 goto err; |
| 287 i=strlen(section)+1; | 280 i=strlen(section)+1; |
| 288 » if ((v->section=(char *)OPENSSL_malloc(i)) == NULL) | 281 » if ((v->section=OPENSSL_malloc(i)) == NULL) |
| 289 goto err; | 282 goto err; |
| 290 | 283 |
| 291 memcpy(v->section,section,i); | 284 memcpy(v->section,section,i); |
| 292 v->name=NULL; | 285 v->name=NULL; |
| 293 v->value=(char *)sk; | 286 v->value=(char *)sk; |
| 294 | 287 |
| 295 » vv=(CONF_VALUE *)lh_insert(conf->data,v); | 288 » vv=lh_CONF_VALUE_insert(conf->data,v); |
| 296 » assert(vv == NULL); | 289 » OPENSSL_assert(vv == NULL); |
| 297 ok=1; | 290 ok=1; |
| 298 err: | 291 err: |
| 299 if (!ok) | 292 if (!ok) |
| 300 { | 293 { |
| 301 » » if (sk != NULL) sk_free(sk); | 294 » » if (sk != NULL) sk_CONF_VALUE_free(sk); |
| 302 if (v != NULL) OPENSSL_free(v); | 295 if (v != NULL) OPENSSL_free(v); |
| 303 v=NULL; | 296 v=NULL; |
| 304 } | 297 } |
| 305 return(v); | 298 return(v); |
| 306 } | 299 } |
| 307 | 300 |
| 308 IMPLEMENT_STACK_OF(CONF_VALUE) | 301 IMPLEMENT_STACK_OF(CONF_VALUE) |
| OLD | NEW |