conf.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
  1. /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  2. * All rights reserved.
  3. *
  4. * This package is an SSL implementation written
  5. * by Eric Young (eay@cryptsoft.com).
  6. * The implementation was written so as to conform with Netscapes SSL.
  7. *
  8. * This library is free for commercial and non-commercial use as long as
  9. * the following conditions are aheared to. The following conditions
  10. * apply to all code found in this distribution, be it the RC4, RSA,
  11. * lhash, DES, etc., code; not just the SSL code. The SSL documentation
  12. * included with this distribution is covered by the same copyright terms
  13. * except that the holder is Tim Hudson (tjh@cryptsoft.com).
  14. *
  15. * Copyright remains Eric Young's, and as such any Copyright notices in
  16. * the code are not to be removed.
  17. * If this package is used in a product, Eric Young should be given attribution
  18. * as the author of the parts of the library used.
  19. * This can be in the form of a textual message at program startup or
  20. * in documentation (online or textual) provided with the package.
  21. *
  22. * Redistribution and use in source and binary forms, with or without
  23. * modification, are permitted provided that the following conditions
  24. * are met:
  25. * 1. Redistributions of source code must retain the copyright
  26. * notice, this list of conditions and the following disclaimer.
  27. * 2. Redistributions in binary form must reproduce the above copyright
  28. * notice, this list of conditions and the following disclaimer in the
  29. * documentation and/or other materials provided with the distribution.
  30. * 3. All advertising materials mentioning features or use of this software
  31. * must display the following acknowledgement:
  32. * "This product includes cryptographic software written by
  33. * Eric Young (eay@cryptsoft.com)"
  34. * The word 'cryptographic' can be left out if the rouines from the library
  35. * being used are not cryptographic related :-).
  36. * 4. If you include any Windows specific code (or a derivative thereof) from
  37. * the apps directory (application code) you must include an acknowledgement:
  38. * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
  39. *
  40. * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
  41. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  42. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  43. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  44. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  45. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  46. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  47. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  48. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  49. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  50. * SUCH DAMAGE.
  51. *
  52. * The licence and distribution terms for any publically available version or
  53. * derivative of this code cannot be changed. i.e. this code cannot simply be
  54. * copied and put under another distribution licence
  55. * [including the GNU Public Licence.] */
  56. #include <openssl/conf.h>
  57. #include <string.h>
  58. #include <ctype.h>
  59. #include <openssl/bio.h>
  60. #include <openssl/buf.h>
  61. #include <openssl/err.h>
  62. #include <openssl/mem.h>
  63. #include "conf_def.h"
  64. #include "internal.h"
  65. #include "../internal.h"
  66. static uint32_t conf_value_hash(const CONF_VALUE *v) {
  67. return (lh_strhash(v->section) << 2) ^ lh_strhash(v->name);
  68. }
  69. static int conf_value_cmp(const CONF_VALUE *a, const CONF_VALUE *b) {
  70. int i;
  71. if (a->section != b->section) {
  72. i = strcmp(a->section, b->section);
  73. if (i) {
  74. return i;
  75. }
  76. }
  77. if (a->name != NULL && b->name != NULL) {
  78. return strcmp(a->name, b->name);
  79. } else if (a->name == b->name) {
  80. return 0;
  81. } else {
  82. return (a->name == NULL) ? -1 : 1;
  83. }
  84. }
  85. CONF *NCONF_new(void *method) {
  86. CONF *conf;
  87. if (method != NULL) {
  88. return NULL;
  89. }
  90. conf = OPENSSL_malloc(sizeof(CONF));
  91. if (conf == NULL) {
  92. return NULL;
  93. }
  94. conf->data = lh_CONF_VALUE_new(conf_value_hash, conf_value_cmp);
  95. if (conf->data == NULL) {
  96. OPENSSL_free(conf);
  97. return NULL;
  98. }
  99. return conf;
  100. }
  101. CONF_VALUE *CONF_VALUE_new(void) {
  102. CONF_VALUE *v = OPENSSL_malloc(sizeof(CONF_VALUE));
  103. if (!v) {
  104. OPENSSL_PUT_ERROR(CONF, ERR_R_MALLOC_FAILURE);
  105. return NULL;
  106. }
  107. OPENSSL_memset(v, 0, sizeof(CONF_VALUE));
  108. return v;
  109. }
  110. static void value_free_contents(CONF_VALUE *value) {
  111. if (value->section) {
  112. OPENSSL_free(value->section);
  113. }
  114. if (value->name) {
  115. OPENSSL_free(value->name);
  116. if (value->value) {
  117. OPENSSL_free(value->value);
  118. }
  119. } else {
  120. if (value->value) {
  121. sk_CONF_VALUE_free((STACK_OF(CONF_VALUE)*)value->value);
  122. }
  123. }
  124. }
  125. static void value_free(CONF_VALUE *value) {
  126. value_free_contents(value);
  127. OPENSSL_free(value);
  128. }
  129. void NCONF_free(CONF *conf) {
  130. if (conf == NULL || conf->data == NULL) {
  131. return;
  132. }
  133. lh_CONF_VALUE_doall(conf->data, value_free);
  134. lh_CONF_VALUE_free(conf->data);
  135. OPENSSL_free(conf);
  136. }
  137. static CONF_VALUE *NCONF_new_section(const CONF *conf, const char *section) {
  138. STACK_OF(CONF_VALUE) *sk = NULL;
  139. int ok = 0;
  140. CONF_VALUE *v = NULL, *old_value;
  141. sk = sk_CONF_VALUE_new_null();
  142. v = CONF_VALUE_new();
  143. if (sk == NULL || v == NULL) {
  144. goto err;
  145. }
  146. v->section = OPENSSL_strdup(section);
  147. if (v->section == NULL) {
  148. goto err;
  149. }
  150. v->name = NULL;
  151. v->value = (char *)sk;
  152. if (!lh_CONF_VALUE_insert(conf->data, &old_value, v)) {
  153. goto err;
  154. }
  155. if (old_value) {
  156. value_free(old_value);
  157. }
  158. ok = 1;
  159. err:
  160. if (!ok) {
  161. if (sk != NULL) {
  162. sk_CONF_VALUE_free(sk);
  163. }
  164. if (v != NULL) {
  165. OPENSSL_free(v);
  166. }
  167. v = NULL;
  168. }
  169. return v;
  170. }
  171. static int str_copy(CONF *conf, char *section, char **pto, char *from) {
  172. int q, r, rr = 0, to = 0, len = 0;
  173. char *s, *e, *rp, *rrp, *np, *cp, v;
  174. const char *p;
  175. BUF_MEM *buf;
  176. buf = BUF_MEM_new();
  177. if (buf == NULL) {
  178. return 0;
  179. }
  180. len = strlen(from) + 1;
  181. if (!BUF_MEM_grow(buf, len)) {
  182. goto err;
  183. }
  184. for (;;) {
  185. if (IS_QUOTE(conf, *from)) {
  186. q = *from;
  187. from++;
  188. while (!IS_EOF(conf, *from) && (*from != q)) {
  189. if (IS_ESC(conf, *from)) {
  190. from++;
  191. if (IS_EOF(conf, *from)) {
  192. break;
  193. }
  194. }
  195. buf->data[to++] = *(from++);
  196. }
  197. if (*from == q) {
  198. from++;
  199. }
  200. } else if (IS_DQUOTE(conf, *from)) {
  201. q = *from;
  202. from++;
  203. while (!IS_EOF(conf, *from)) {
  204. if (*from == q) {
  205. if (*(from + 1) == q) {
  206. from++;
  207. } else {
  208. break;
  209. }
  210. }
  211. buf->data[to++] = *(from++);
  212. }
  213. if (*from == q) {
  214. from++;
  215. }
  216. } else if (IS_ESC(conf, *from)) {
  217. from++;
  218. v = *(from++);
  219. if (IS_EOF(conf, v)) {
  220. break;
  221. } else if (v == 'r') {
  222. v = '\r';
  223. } else if (v == 'n') {
  224. v = '\n';
  225. } else if (v == 'b') {
  226. v = '\b';
  227. } else if (v == 't') {
  228. v = '\t';
  229. }
  230. buf->data[to++] = v;
  231. } else if (IS_EOF(conf, *from)) {
  232. break;
  233. } else if (*from == '$') {
  234. /* try to expand it */
  235. rrp = NULL;
  236. s = &(from[1]);
  237. if (*s == '{') {
  238. q = '}';
  239. } else if (*s == '(') {
  240. q = ')';
  241. } else {
  242. q = 0;
  243. }
  244. if (q) {
  245. s++;
  246. }
  247. cp = section;
  248. e = np = s;
  249. while (IS_ALPHA_NUMERIC(conf, *e)) {
  250. e++;
  251. }
  252. if (e[0] == ':' && e[1] == ':') {
  253. cp = np;
  254. rrp = e;
  255. rr = *e;
  256. *rrp = '\0';
  257. e += 2;
  258. np = e;
  259. while (IS_ALPHA_NUMERIC(conf, *e)) {
  260. e++;
  261. }
  262. }
  263. r = *e;
  264. *e = '\0';
  265. rp = e;
  266. if (q) {
  267. if (r != q) {
  268. OPENSSL_PUT_ERROR(CONF, CONF_R_NO_CLOSE_BRACE);
  269. goto err;
  270. }
  271. e++;
  272. }
  273. /* So at this point we have
  274. * np which is the start of the name string which is
  275. * '\0' terminated.
  276. * cp which is the start of the section string which is
  277. * '\0' terminated.
  278. * e is the 'next point after'.
  279. * r and rr are the chars replaced by the '\0'
  280. * rp and rrp is where 'r' and 'rr' came from. */
  281. p = NCONF_get_string(conf, cp, np);
  282. if (rrp != NULL) {
  283. *rrp = rr;
  284. }
  285. *rp = r;
  286. if (p == NULL) {
  287. OPENSSL_PUT_ERROR(CONF, CONF_R_VARIABLE_HAS_NO_VALUE);
  288. goto err;
  289. }
  290. BUF_MEM_grow_clean(buf, (strlen(p) + buf->length - (e - from)));
  291. while (*p) {
  292. buf->data[to++] = *(p++);
  293. }
  294. /* Since we change the pointer 'from', we also have
  295. to change the perceived length of the string it
  296. points at. /RL */
  297. len -= e - from;
  298. from = e;
  299. /* In case there were no braces or parenthesis around
  300. the variable reference, we have to put back the
  301. character that was replaced with a '\0'. /RL */
  302. *rp = r;
  303. } else {
  304. buf->data[to++] = *(from++);
  305. }
  306. }
  307. buf->data[to] = '\0';
  308. if (*pto != NULL) {
  309. OPENSSL_free(*pto);
  310. }
  311. *pto = buf->data;
  312. OPENSSL_free(buf);
  313. return 1;
  314. err:
  315. if (buf != NULL) {
  316. BUF_MEM_free(buf);
  317. }
  318. return 0;
  319. }
  320. static CONF_VALUE *get_section(const CONF *conf, const char *section) {
  321. CONF_VALUE template;
  322. OPENSSL_memset(&template, 0, sizeof(template));
  323. template.section = (char *) section;
  324. return lh_CONF_VALUE_retrieve(conf->data, &template);
  325. }
  326. STACK_OF(CONF_VALUE) *NCONF_get_section(const CONF *conf, const char *section) {
  327. CONF_VALUE *section_value = get_section(conf, section);
  328. if (section_value == NULL) {
  329. return NULL;
  330. }
  331. return (STACK_OF(CONF_VALUE)*) section_value->value;
  332. }
  333. const char *NCONF_get_string(const CONF *conf, const char *section,
  334. const char *name) {
  335. CONF_VALUE template, *value;
  336. OPENSSL_memset(&template, 0, sizeof(template));
  337. template.section = (char *) section;
  338. template.name = (char *) name;
  339. value = lh_CONF_VALUE_retrieve(conf->data, &template);
  340. if (value == NULL) {
  341. return NULL;
  342. }
  343. return value->value;
  344. }
  345. static int add_string(const CONF *conf, CONF_VALUE *section,
  346. CONF_VALUE *value) {
  347. STACK_OF(CONF_VALUE) *section_stack = (STACK_OF(CONF_VALUE)*) section->value;
  348. CONF_VALUE *old_value;
  349. value->section = OPENSSL_strdup(section->section);
  350. if (!sk_CONF_VALUE_push(section_stack, value)) {
  351. return 0;
  352. }
  353. if (!lh_CONF_VALUE_insert(conf->data, &old_value, value)) {
  354. return 0;
  355. }
  356. if (old_value != NULL) {
  357. (void)sk_CONF_VALUE_delete_ptr(section_stack, old_value);
  358. value_free(old_value);
  359. }
  360. return 1;
  361. }
  362. static char *eat_ws(CONF *conf, char *p) {
  363. while (IS_WS(conf, *p) && !IS_EOF(conf, *p)) {
  364. p++;
  365. }
  366. return p;
  367. }
  368. #define scan_esc(conf, p) (((IS_EOF((conf), (p)[1])) ? ((p) + 1) : ((p) + 2)))
  369. static char *eat_alpha_numeric(CONF *conf, char *p) {
  370. for (;;) {
  371. if (IS_ESC(conf, *p)) {
  372. p = scan_esc(conf, p);
  373. continue;
  374. }
  375. if (!IS_ALPHA_NUMERIC_PUNCT(conf, *p)) {
  376. return p;
  377. }
  378. p++;
  379. }
  380. }
  381. static char *scan_quote(CONF *conf, char *p) {
  382. int q = *p;
  383. p++;
  384. while (!IS_EOF(conf, *p) && *p != q) {
  385. if (IS_ESC(conf, *p)) {
  386. p++;
  387. if (IS_EOF(conf, *p)) {
  388. return p;
  389. }
  390. }
  391. p++;
  392. }
  393. if (*p == q) {
  394. p++;
  395. }
  396. return p;
  397. }
  398. static char *scan_dquote(CONF *conf, char *p) {
  399. int q = *p;
  400. p++;
  401. while (!(IS_EOF(conf, *p))) {
  402. if (*p == q) {
  403. if (*(p + 1) == q) {
  404. p++;
  405. } else {
  406. break;
  407. }
  408. }
  409. p++;
  410. }
  411. if (*p == q) {
  412. p++;
  413. }
  414. return p;
  415. }
  416. static void clear_comments(CONF *conf, char *p) {
  417. for (;;) {
  418. if (IS_FCOMMENT(conf, *p)) {
  419. *p = '\0';
  420. return;
  421. }
  422. if (!IS_WS(conf, *p)) {
  423. break;
  424. }
  425. p++;
  426. }
  427. for (;;) {
  428. if (IS_COMMENT(conf, *p)) {
  429. *p = '\0';
  430. return;
  431. }
  432. if (IS_DQUOTE(conf, *p)) {
  433. p = scan_dquote(conf, p);
  434. continue;
  435. }
  436. if (IS_QUOTE(conf, *p)) {
  437. p = scan_quote(conf, p);
  438. continue;
  439. }
  440. if (IS_ESC(conf, *p)) {
  441. p = scan_esc(conf, p);
  442. continue;
  443. }
  444. if (IS_EOF(conf, *p)) {
  445. return;
  446. } else {
  447. p++;
  448. }
  449. }
  450. }
  451. static int def_load_bio(CONF *conf, BIO *in, long *out_error_line) {
  452. static const size_t CONFBUFSIZE = 512;
  453. int bufnum = 0, i, ii;
  454. BUF_MEM *buff = NULL;
  455. char *s, *p, *end;
  456. int again;
  457. long eline = 0;
  458. char btmp[DECIMAL_SIZE(eline) + 1];
  459. CONF_VALUE *v = NULL, *tv;
  460. CONF_VALUE *sv = NULL;
  461. char *section = NULL, *buf;
  462. char *start, *psection, *pname;
  463. if ((buff = BUF_MEM_new()) == NULL) {
  464. OPENSSL_PUT_ERROR(CONF, ERR_R_BUF_LIB);
  465. goto err;
  466. }
  467. section = OPENSSL_strdup("default");
  468. if (section == NULL) {
  469. OPENSSL_PUT_ERROR(CONF, ERR_R_MALLOC_FAILURE);
  470. goto err;
  471. }
  472. sv = NCONF_new_section(conf, section);
  473. if (sv == NULL) {
  474. OPENSSL_PUT_ERROR(CONF, CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
  475. goto err;
  476. }
  477. bufnum = 0;
  478. again = 0;
  479. for (;;) {
  480. if (!BUF_MEM_grow(buff, bufnum + CONFBUFSIZE)) {
  481. OPENSSL_PUT_ERROR(CONF, ERR_R_BUF_LIB);
  482. goto err;
  483. }
  484. p = &(buff->data[bufnum]);
  485. *p = '\0';
  486. BIO_gets(in, p, CONFBUFSIZE - 1);
  487. p[CONFBUFSIZE - 1] = '\0';
  488. ii = i = strlen(p);
  489. if (i == 0 && !again) {
  490. break;
  491. }
  492. again = 0;
  493. while (i > 0) {
  494. if ((p[i - 1] != '\r') && (p[i - 1] != '\n')) {
  495. break;
  496. } else {
  497. i--;
  498. }
  499. }
  500. /* we removed some trailing stuff so there is a new
  501. * line on the end. */
  502. if (ii && i == ii) {
  503. again = 1; /* long line */
  504. } else {
  505. p[i] = '\0';
  506. eline++; /* another input line */
  507. }
  508. /* we now have a line with trailing \r\n removed */
  509. /* i is the number of bytes */
  510. bufnum += i;
  511. v = NULL;
  512. /* check for line continuation */
  513. if (bufnum >= 1) {
  514. /* If we have bytes and the last char '\\' and
  515. * second last char is not '\\' */
  516. p = &(buff->data[bufnum - 1]);
  517. if (IS_ESC(conf, p[0]) && ((bufnum <= 1) || !IS_ESC(conf, p[-1]))) {
  518. bufnum--;
  519. again = 1;
  520. }
  521. }
  522. if (again) {
  523. continue;
  524. }
  525. bufnum = 0;
  526. buf = buff->data;
  527. clear_comments(conf, buf);
  528. s = eat_ws(conf, buf);
  529. if (IS_EOF(conf, *s)) {
  530. continue; /* blank line */
  531. }
  532. if (*s == '[') {
  533. char *ss;
  534. s++;
  535. start = eat_ws(conf, s);
  536. ss = start;
  537. again:
  538. end = eat_alpha_numeric(conf, ss);
  539. p = eat_ws(conf, end);
  540. if (*p != ']') {
  541. if (*p != '\0' && ss != p) {
  542. ss = p;
  543. goto again;
  544. }
  545. OPENSSL_PUT_ERROR(CONF, CONF_R_MISSING_CLOSE_SQUARE_BRACKET);
  546. goto err;
  547. }
  548. *end = '\0';
  549. if (!str_copy(conf, NULL, &section, start)) {
  550. goto err;
  551. }
  552. if ((sv = get_section(conf, section)) == NULL) {
  553. sv = NCONF_new_section(conf, section);
  554. }
  555. if (sv == NULL) {
  556. OPENSSL_PUT_ERROR(CONF, CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
  557. goto err;
  558. }
  559. continue;
  560. } else {
  561. pname = s;
  562. psection = NULL;
  563. end = eat_alpha_numeric(conf, s);
  564. if ((end[0] == ':') && (end[1] == ':')) {
  565. *end = '\0';
  566. end += 2;
  567. psection = pname;
  568. pname = end;
  569. end = eat_alpha_numeric(conf, end);
  570. }
  571. p = eat_ws(conf, end);
  572. if (*p != '=') {
  573. OPENSSL_PUT_ERROR(CONF, CONF_R_MISSING_EQUAL_SIGN);
  574. goto err;
  575. }
  576. *end = '\0';
  577. p++;
  578. start = eat_ws(conf, p);
  579. while (!IS_EOF(conf, *p)) {
  580. p++;
  581. }
  582. p--;
  583. while ((p != start) && (IS_WS(conf, *p))) {
  584. p--;
  585. }
  586. p++;
  587. *p = '\0';
  588. if (!(v = CONF_VALUE_new())) {
  589. goto err;
  590. }
  591. if (psection == NULL) {
  592. psection = section;
  593. }
  594. v->name = OPENSSL_strdup(pname);
  595. if (v->name == NULL) {
  596. OPENSSL_PUT_ERROR(CONF, ERR_R_MALLOC_FAILURE);
  597. goto err;
  598. }
  599. if (!str_copy(conf, psection, &(v->value), start)) {
  600. goto err;
  601. }
  602. if (strcmp(psection, section) != 0) {
  603. if ((tv = get_section(conf, psection)) == NULL) {
  604. tv = NCONF_new_section(conf, psection);
  605. }
  606. if (tv == NULL) {
  607. OPENSSL_PUT_ERROR(CONF, CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
  608. goto err;
  609. }
  610. } else {
  611. tv = sv;
  612. }
  613. if (add_string(conf, tv, v) == 0) {
  614. OPENSSL_PUT_ERROR(CONF, ERR_R_MALLOC_FAILURE);
  615. goto err;
  616. }
  617. v = NULL;
  618. }
  619. }
  620. if (buff != NULL) {
  621. BUF_MEM_free(buff);
  622. }
  623. if (section != NULL) {
  624. OPENSSL_free(section);
  625. }
  626. return 1;
  627. err:
  628. if (buff != NULL) {
  629. BUF_MEM_free(buff);
  630. }
  631. if (section != NULL) {
  632. OPENSSL_free(section);
  633. }
  634. if (out_error_line != NULL) {
  635. *out_error_line = eline;
  636. }
  637. BIO_snprintf(btmp, sizeof btmp, "%ld", eline);
  638. ERR_add_error_data(2, "line ", btmp);
  639. if (v != NULL) {
  640. if (v->name != NULL) {
  641. OPENSSL_free(v->name);
  642. }
  643. if (v->value != NULL) {
  644. OPENSSL_free(v->value);
  645. }
  646. if (v != NULL) {
  647. OPENSSL_free(v);
  648. }
  649. }
  650. return 0;
  651. }
  652. int NCONF_load(CONF *conf, const char *filename, long *out_error_line) {
  653. BIO *in = BIO_new_file(filename, "rb");
  654. int ret;
  655. if (in == NULL) {
  656. OPENSSL_PUT_ERROR(CONF, ERR_R_SYS_LIB);
  657. return 0;
  658. }
  659. ret = def_load_bio(conf, in, out_error_line);
  660. BIO_free(in);
  661. return ret;
  662. }
  663. int NCONF_load_bio(CONF *conf, BIO *bio, long *out_error_line) {
  664. return def_load_bio(conf, bio, out_error_line);
  665. }
  666. int CONF_parse_list(const char *list, char sep, int remove_whitespace,
  667. int (*list_cb)(const char *elem, int len, void *usr),
  668. void *arg) {
  669. int ret;
  670. const char *lstart, *tmpend, *p;
  671. if (list == NULL) {
  672. OPENSSL_PUT_ERROR(CONF, CONF_R_LIST_CANNOT_BE_NULL);
  673. return 0;
  674. }
  675. lstart = list;
  676. for (;;) {
  677. if (remove_whitespace) {
  678. while (*lstart && isspace((unsigned char)*lstart)) {
  679. lstart++;
  680. }
  681. }
  682. p = strchr(lstart, sep);
  683. if (p == lstart || !*lstart) {
  684. ret = list_cb(NULL, 0, arg);
  685. } else {
  686. if (p) {
  687. tmpend = p - 1;
  688. } else {
  689. tmpend = lstart + strlen(lstart) - 1;
  690. }
  691. if (remove_whitespace) {
  692. while (isspace((unsigned char)*tmpend)) {
  693. tmpend--;
  694. }
  695. }
  696. ret = list_cb(lstart, tmpend - lstart + 1, arg);
  697. }
  698. if (ret <= 0) {
  699. return ret;
  700. }
  701. if (p == NULL) {
  702. return 1;
  703. }
  704. lstart = p + 1;
  705. }
  706. }
  707. int CONF_modules_load_file(CONF_MUST_BE_NULL *filename, const char *appname,
  708. unsigned long flags) {
  709. return 1;
  710. }
  711. void CONF_modules_free(void) {}
  712. void OPENSSL_config(CONF_MUST_BE_NULL *config_name) {}
  713. void OPENSSL_no_config(void) {}