You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

804 regels
19 KiB

  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. // The maximum length we can grow a value to after variable expansion. 64k
  67. // should be more than enough for all reasonable uses.
  68. #define MAX_CONF_VALUE_LENGTH 65536
  69. static uint32_t conf_value_hash(const CONF_VALUE *v) {
  70. return (lh_strhash(v->section) << 2) ^ lh_strhash(v->name);
  71. }
  72. static int conf_value_cmp(const CONF_VALUE *a, const CONF_VALUE *b) {
  73. int i;
  74. if (a->section != b->section) {
  75. i = strcmp(a->section, b->section);
  76. if (i) {
  77. return i;
  78. }
  79. }
  80. if (a->name != NULL && b->name != NULL) {
  81. return strcmp(a->name, b->name);
  82. } else if (a->name == b->name) {
  83. return 0;
  84. } else {
  85. return (a->name == NULL) ? -1 : 1;
  86. }
  87. }
  88. CONF *NCONF_new(void *method) {
  89. CONF *conf;
  90. if (method != NULL) {
  91. return NULL;
  92. }
  93. conf = OPENSSL_malloc(sizeof(CONF));
  94. if (conf == NULL) {
  95. return NULL;
  96. }
  97. conf->data = lh_CONF_VALUE_new(conf_value_hash, conf_value_cmp);
  98. if (conf->data == NULL) {
  99. OPENSSL_free(conf);
  100. return NULL;
  101. }
  102. return conf;
  103. }
  104. CONF_VALUE *CONF_VALUE_new(void) {
  105. CONF_VALUE *v = OPENSSL_malloc(sizeof(CONF_VALUE));
  106. if (!v) {
  107. OPENSSL_PUT_ERROR(CONF, ERR_R_MALLOC_FAILURE);
  108. return NULL;
  109. }
  110. OPENSSL_memset(v, 0, sizeof(CONF_VALUE));
  111. return v;
  112. }
  113. static void value_free_contents(CONF_VALUE *value) {
  114. if (value->section) {
  115. OPENSSL_free(value->section);
  116. }
  117. if (value->name) {
  118. OPENSSL_free(value->name);
  119. if (value->value) {
  120. OPENSSL_free(value->value);
  121. }
  122. } else {
  123. if (value->value) {
  124. sk_CONF_VALUE_free((STACK_OF(CONF_VALUE)*)value->value);
  125. }
  126. }
  127. }
  128. static void value_free(CONF_VALUE *value) {
  129. value_free_contents(value);
  130. OPENSSL_free(value);
  131. }
  132. void NCONF_free(CONF *conf) {
  133. if (conf == NULL || conf->data == NULL) {
  134. return;
  135. }
  136. lh_CONF_VALUE_doall(conf->data, value_free);
  137. lh_CONF_VALUE_free(conf->data);
  138. OPENSSL_free(conf);
  139. }
  140. static CONF_VALUE *NCONF_new_section(const CONF *conf, const char *section) {
  141. STACK_OF(CONF_VALUE) *sk = NULL;
  142. int ok = 0;
  143. CONF_VALUE *v = NULL, *old_value;
  144. sk = sk_CONF_VALUE_new_null();
  145. v = CONF_VALUE_new();
  146. if (sk == NULL || v == NULL) {
  147. goto err;
  148. }
  149. v->section = OPENSSL_strdup(section);
  150. if (v->section == NULL) {
  151. goto err;
  152. }
  153. v->name = NULL;
  154. v->value = (char *)sk;
  155. if (!lh_CONF_VALUE_insert(conf->data, &old_value, v)) {
  156. goto err;
  157. }
  158. if (old_value) {
  159. value_free(old_value);
  160. }
  161. ok = 1;
  162. err:
  163. if (!ok) {
  164. if (sk != NULL) {
  165. sk_CONF_VALUE_free(sk);
  166. }
  167. if (v != NULL) {
  168. OPENSSL_free(v);
  169. }
  170. v = NULL;
  171. }
  172. return v;
  173. }
  174. static int str_copy(CONF *conf, char *section, char **pto, char *from) {
  175. int q, r, rr = 0, to = 0, len = 0;
  176. char *s, *e, *rp, *rrp, *np, *cp, v;
  177. const char *p;
  178. BUF_MEM *buf;
  179. buf = BUF_MEM_new();
  180. if (buf == NULL) {
  181. return 0;
  182. }
  183. len = strlen(from) + 1;
  184. if (!BUF_MEM_grow(buf, len)) {
  185. goto err;
  186. }
  187. for (;;) {
  188. if (IS_QUOTE(conf, *from)) {
  189. q = *from;
  190. from++;
  191. while (!IS_EOF(conf, *from) && (*from != q)) {
  192. if (IS_ESC(conf, *from)) {
  193. from++;
  194. if (IS_EOF(conf, *from)) {
  195. break;
  196. }
  197. }
  198. buf->data[to++] = *(from++);
  199. }
  200. if (*from == q) {
  201. from++;
  202. }
  203. } else if (IS_DQUOTE(conf, *from)) {
  204. q = *from;
  205. from++;
  206. while (!IS_EOF(conf, *from)) {
  207. if (*from == q) {
  208. if (*(from + 1) == q) {
  209. from++;
  210. } else {
  211. break;
  212. }
  213. }
  214. buf->data[to++] = *(from++);
  215. }
  216. if (*from == q) {
  217. from++;
  218. }
  219. } else if (IS_ESC(conf, *from)) {
  220. from++;
  221. v = *(from++);
  222. if (IS_EOF(conf, v)) {
  223. break;
  224. } else if (v == 'r') {
  225. v = '\r';
  226. } else if (v == 'n') {
  227. v = '\n';
  228. } else if (v == 'b') {
  229. v = '\b';
  230. } else if (v == 't') {
  231. v = '\t';
  232. }
  233. buf->data[to++] = v;
  234. } else if (IS_EOF(conf, *from)) {
  235. break;
  236. } else if (*from == '$') {
  237. // try to expand it
  238. rrp = NULL;
  239. s = &(from[1]);
  240. if (*s == '{') {
  241. q = '}';
  242. } else if (*s == '(') {
  243. q = ')';
  244. } else {
  245. q = 0;
  246. }
  247. if (q) {
  248. s++;
  249. }
  250. cp = section;
  251. e = np = s;
  252. while (IS_ALPHA_NUMERIC(conf, *e)) {
  253. e++;
  254. }
  255. if (e[0] == ':' && e[1] == ':') {
  256. cp = np;
  257. rrp = e;
  258. rr = *e;
  259. *rrp = '\0';
  260. e += 2;
  261. np = e;
  262. while (IS_ALPHA_NUMERIC(conf, *e)) {
  263. e++;
  264. }
  265. }
  266. r = *e;
  267. *e = '\0';
  268. rp = e;
  269. if (q) {
  270. if (r != q) {
  271. OPENSSL_PUT_ERROR(CONF, CONF_R_NO_CLOSE_BRACE);
  272. goto err;
  273. }
  274. e++;
  275. }
  276. // So at this point we have
  277. // np which is the start of the name string which is
  278. // '\0' terminated.
  279. // cp which is the start of the section string which is
  280. // '\0' terminated.
  281. // e is the 'next point after'.
  282. // r and rr are the chars replaced by the '\0'
  283. // rp and rrp is where 'r' and 'rr' came from.
  284. p = NCONF_get_string(conf, cp, np);
  285. if (rrp != NULL) {
  286. *rrp = rr;
  287. }
  288. *rp = r;
  289. if (p == NULL) {
  290. OPENSSL_PUT_ERROR(CONF, CONF_R_VARIABLE_HAS_NO_VALUE);
  291. goto err;
  292. }
  293. size_t newsize = strlen(p) + buf->length - (e - from);
  294. if (newsize > MAX_CONF_VALUE_LENGTH) {
  295. OPENSSL_PUT_ERROR(CONF, CONF_R_VARIABLE_EXPANSION_TOO_LONG);
  296. goto err;
  297. }
  298. if (!BUF_MEM_grow_clean(buf, newsize)) {
  299. OPENSSL_PUT_ERROR(CONF, ERR_R_MALLOC_FAILURE);
  300. goto err;
  301. }
  302. while (*p) {
  303. buf->data[to++] = *(p++);
  304. }
  305. /* Since we change the pointer 'from', we also have
  306. to change the perceived length of the string it
  307. points at. /RL */
  308. len -= e - from;
  309. from = e;
  310. /* In case there were no braces or parenthesis around
  311. the variable reference, we have to put back the
  312. character that was replaced with a '\0'. /RL */
  313. *rp = r;
  314. } else {
  315. buf->data[to++] = *(from++);
  316. }
  317. }
  318. buf->data[to] = '\0';
  319. if (*pto != NULL) {
  320. OPENSSL_free(*pto);
  321. }
  322. *pto = buf->data;
  323. OPENSSL_free(buf);
  324. return 1;
  325. err:
  326. if (buf != NULL) {
  327. BUF_MEM_free(buf);
  328. }
  329. return 0;
  330. }
  331. static CONF_VALUE *get_section(const CONF *conf, const char *section) {
  332. CONF_VALUE template;
  333. OPENSSL_memset(&template, 0, sizeof(template));
  334. template.section = (char *) section;
  335. return lh_CONF_VALUE_retrieve(conf->data, &template);
  336. }
  337. STACK_OF(CONF_VALUE) *NCONF_get_section(const CONF *conf, const char *section) {
  338. CONF_VALUE *section_value = get_section(conf, section);
  339. if (section_value == NULL) {
  340. return NULL;
  341. }
  342. return (STACK_OF(CONF_VALUE)*) section_value->value;
  343. }
  344. const char *NCONF_get_string(const CONF *conf, const char *section,
  345. const char *name) {
  346. CONF_VALUE template, *value;
  347. OPENSSL_memset(&template, 0, sizeof(template));
  348. template.section = (char *) section;
  349. template.name = (char *) name;
  350. value = lh_CONF_VALUE_retrieve(conf->data, &template);
  351. if (value == NULL) {
  352. return NULL;
  353. }
  354. return value->value;
  355. }
  356. static int add_string(const CONF *conf, CONF_VALUE *section,
  357. CONF_VALUE *value) {
  358. STACK_OF(CONF_VALUE) *section_stack = (STACK_OF(CONF_VALUE)*) section->value;
  359. CONF_VALUE *old_value;
  360. value->section = OPENSSL_strdup(section->section);
  361. if (!sk_CONF_VALUE_push(section_stack, value)) {
  362. return 0;
  363. }
  364. if (!lh_CONF_VALUE_insert(conf->data, &old_value, value)) {
  365. return 0;
  366. }
  367. if (old_value != NULL) {
  368. (void)sk_CONF_VALUE_delete_ptr(section_stack, old_value);
  369. value_free(old_value);
  370. }
  371. return 1;
  372. }
  373. static char *eat_ws(CONF *conf, char *p) {
  374. while (IS_WS(conf, *p) && !IS_EOF(conf, *p)) {
  375. p++;
  376. }
  377. return p;
  378. }
  379. #define scan_esc(conf, p) (((IS_EOF((conf), (p)[1])) ? ((p) + 1) : ((p) + 2)))
  380. static char *eat_alpha_numeric(CONF *conf, char *p) {
  381. for (;;) {
  382. if (IS_ESC(conf, *p)) {
  383. p = scan_esc(conf, p);
  384. continue;
  385. }
  386. if (!IS_ALPHA_NUMERIC_PUNCT(conf, *p)) {
  387. return p;
  388. }
  389. p++;
  390. }
  391. }
  392. static char *scan_quote(CONF *conf, char *p) {
  393. int q = *p;
  394. p++;
  395. while (!IS_EOF(conf, *p) && *p != q) {
  396. if (IS_ESC(conf, *p)) {
  397. p++;
  398. if (IS_EOF(conf, *p)) {
  399. return p;
  400. }
  401. }
  402. p++;
  403. }
  404. if (*p == q) {
  405. p++;
  406. }
  407. return p;
  408. }
  409. static char *scan_dquote(CONF *conf, char *p) {
  410. int q = *p;
  411. p++;
  412. while (!(IS_EOF(conf, *p))) {
  413. if (*p == q) {
  414. if (*(p + 1) == q) {
  415. p++;
  416. } else {
  417. break;
  418. }
  419. }
  420. p++;
  421. }
  422. if (*p == q) {
  423. p++;
  424. }
  425. return p;
  426. }
  427. static void clear_comments(CONF *conf, char *p) {
  428. for (;;) {
  429. if (IS_FCOMMENT(conf, *p)) {
  430. *p = '\0';
  431. return;
  432. }
  433. if (!IS_WS(conf, *p)) {
  434. break;
  435. }
  436. p++;
  437. }
  438. for (;;) {
  439. if (IS_COMMENT(conf, *p)) {
  440. *p = '\0';
  441. return;
  442. }
  443. if (IS_DQUOTE(conf, *p)) {
  444. p = scan_dquote(conf, p);
  445. continue;
  446. }
  447. if (IS_QUOTE(conf, *p)) {
  448. p = scan_quote(conf, p);
  449. continue;
  450. }
  451. if (IS_ESC(conf, *p)) {
  452. p = scan_esc(conf, p);
  453. continue;
  454. }
  455. if (IS_EOF(conf, *p)) {
  456. return;
  457. } else {
  458. p++;
  459. }
  460. }
  461. }
  462. static int def_load_bio(CONF *conf, BIO *in, long *out_error_line) {
  463. static const size_t CONFBUFSIZE = 512;
  464. int bufnum = 0, i, ii;
  465. BUF_MEM *buff = NULL;
  466. char *s, *p, *end;
  467. int again;
  468. long eline = 0;
  469. char btmp[DECIMAL_SIZE(eline) + 1];
  470. CONF_VALUE *v = NULL, *tv;
  471. CONF_VALUE *sv = NULL;
  472. char *section = NULL, *buf;
  473. char *start, *psection, *pname;
  474. if ((buff = BUF_MEM_new()) == NULL) {
  475. OPENSSL_PUT_ERROR(CONF, ERR_R_BUF_LIB);
  476. goto err;
  477. }
  478. section = OPENSSL_strdup("default");
  479. if (section == NULL) {
  480. OPENSSL_PUT_ERROR(CONF, ERR_R_MALLOC_FAILURE);
  481. goto err;
  482. }
  483. sv = NCONF_new_section(conf, section);
  484. if (sv == NULL) {
  485. OPENSSL_PUT_ERROR(CONF, CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
  486. goto err;
  487. }
  488. bufnum = 0;
  489. again = 0;
  490. for (;;) {
  491. if (!BUF_MEM_grow(buff, bufnum + CONFBUFSIZE)) {
  492. OPENSSL_PUT_ERROR(CONF, ERR_R_BUF_LIB);
  493. goto err;
  494. }
  495. p = &(buff->data[bufnum]);
  496. *p = '\0';
  497. BIO_gets(in, p, CONFBUFSIZE - 1);
  498. p[CONFBUFSIZE - 1] = '\0';
  499. ii = i = strlen(p);
  500. if (i == 0 && !again) {
  501. break;
  502. }
  503. again = 0;
  504. while (i > 0) {
  505. if ((p[i - 1] != '\r') && (p[i - 1] != '\n')) {
  506. break;
  507. } else {
  508. i--;
  509. }
  510. }
  511. // we removed some trailing stuff so there is a new
  512. // line on the end.
  513. if (ii && i == ii) {
  514. again = 1; // long line
  515. } else {
  516. p[i] = '\0';
  517. eline++; // another input line
  518. }
  519. // we now have a line with trailing \r\n removed
  520. // i is the number of bytes
  521. bufnum += i;
  522. v = NULL;
  523. // check for line continuation
  524. if (bufnum >= 1) {
  525. // If we have bytes and the last char '\\' and
  526. // second last char is not '\\'
  527. p = &(buff->data[bufnum - 1]);
  528. if (IS_ESC(conf, p[0]) && ((bufnum <= 1) || !IS_ESC(conf, p[-1]))) {
  529. bufnum--;
  530. again = 1;
  531. }
  532. }
  533. if (again) {
  534. continue;
  535. }
  536. bufnum = 0;
  537. buf = buff->data;
  538. clear_comments(conf, buf);
  539. s = eat_ws(conf, buf);
  540. if (IS_EOF(conf, *s)) {
  541. continue; // blank line
  542. }
  543. if (*s == '[') {
  544. char *ss;
  545. s++;
  546. start = eat_ws(conf, s);
  547. ss = start;
  548. again:
  549. end = eat_alpha_numeric(conf, ss);
  550. p = eat_ws(conf, end);
  551. if (*p != ']') {
  552. if (*p != '\0' && ss != p) {
  553. ss = p;
  554. goto again;
  555. }
  556. OPENSSL_PUT_ERROR(CONF, CONF_R_MISSING_CLOSE_SQUARE_BRACKET);
  557. goto err;
  558. }
  559. *end = '\0';
  560. if (!str_copy(conf, NULL, &section, start)) {
  561. goto err;
  562. }
  563. if ((sv = get_section(conf, section)) == NULL) {
  564. sv = NCONF_new_section(conf, section);
  565. }
  566. if (sv == NULL) {
  567. OPENSSL_PUT_ERROR(CONF, CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
  568. goto err;
  569. }
  570. continue;
  571. } else {
  572. pname = s;
  573. psection = NULL;
  574. end = eat_alpha_numeric(conf, s);
  575. if ((end[0] == ':') && (end[1] == ':')) {
  576. *end = '\0';
  577. end += 2;
  578. psection = pname;
  579. pname = end;
  580. end = eat_alpha_numeric(conf, end);
  581. }
  582. p = eat_ws(conf, end);
  583. if (*p != '=') {
  584. OPENSSL_PUT_ERROR(CONF, CONF_R_MISSING_EQUAL_SIGN);
  585. goto err;
  586. }
  587. *end = '\0';
  588. p++;
  589. start = eat_ws(conf, p);
  590. while (!IS_EOF(conf, *p)) {
  591. p++;
  592. }
  593. p--;
  594. while ((p != start) && (IS_WS(conf, *p))) {
  595. p--;
  596. }
  597. p++;
  598. *p = '\0';
  599. if (!(v = CONF_VALUE_new())) {
  600. goto err;
  601. }
  602. if (psection == NULL) {
  603. psection = section;
  604. }
  605. v->name = OPENSSL_strdup(pname);
  606. if (v->name == NULL) {
  607. OPENSSL_PUT_ERROR(CONF, ERR_R_MALLOC_FAILURE);
  608. goto err;
  609. }
  610. if (!str_copy(conf, psection, &(v->value), start)) {
  611. goto err;
  612. }
  613. if (strcmp(psection, section) != 0) {
  614. if ((tv = get_section(conf, psection)) == NULL) {
  615. tv = NCONF_new_section(conf, psection);
  616. }
  617. if (tv == NULL) {
  618. OPENSSL_PUT_ERROR(CONF, CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
  619. goto err;
  620. }
  621. } else {
  622. tv = sv;
  623. }
  624. if (add_string(conf, tv, v) == 0) {
  625. OPENSSL_PUT_ERROR(CONF, ERR_R_MALLOC_FAILURE);
  626. goto err;
  627. }
  628. v = NULL;
  629. }
  630. }
  631. if (buff != NULL) {
  632. BUF_MEM_free(buff);
  633. }
  634. if (section != NULL) {
  635. OPENSSL_free(section);
  636. }
  637. return 1;
  638. err:
  639. if (buff != NULL) {
  640. BUF_MEM_free(buff);
  641. }
  642. if (section != NULL) {
  643. OPENSSL_free(section);
  644. }
  645. if (out_error_line != NULL) {
  646. *out_error_line = eline;
  647. }
  648. BIO_snprintf(btmp, sizeof btmp, "%ld", eline);
  649. ERR_add_error_data(2, "line ", btmp);
  650. if (v != NULL) {
  651. if (v->name != NULL) {
  652. OPENSSL_free(v->name);
  653. }
  654. if (v->value != NULL) {
  655. OPENSSL_free(v->value);
  656. }
  657. if (v != NULL) {
  658. OPENSSL_free(v);
  659. }
  660. }
  661. return 0;
  662. }
  663. int NCONF_load(CONF *conf, const char *filename, long *out_error_line) {
  664. BIO *in = BIO_new_file(filename, "rb");
  665. int ret;
  666. if (in == NULL) {
  667. OPENSSL_PUT_ERROR(CONF, ERR_R_SYS_LIB);
  668. return 0;
  669. }
  670. ret = def_load_bio(conf, in, out_error_line);
  671. BIO_free(in);
  672. return ret;
  673. }
  674. int NCONF_load_bio(CONF *conf, BIO *bio, long *out_error_line) {
  675. return def_load_bio(conf, bio, out_error_line);
  676. }
  677. int CONF_parse_list(const char *list, char sep, int remove_whitespace,
  678. int (*list_cb)(const char *elem, int len, void *usr),
  679. void *arg) {
  680. int ret;
  681. const char *lstart, *tmpend, *p;
  682. if (list == NULL) {
  683. OPENSSL_PUT_ERROR(CONF, CONF_R_LIST_CANNOT_BE_NULL);
  684. return 0;
  685. }
  686. lstart = list;
  687. for (;;) {
  688. if (remove_whitespace) {
  689. while (*lstart && isspace((unsigned char)*lstart)) {
  690. lstart++;
  691. }
  692. }
  693. p = strchr(lstart, sep);
  694. if (p == lstart || !*lstart) {
  695. ret = list_cb(NULL, 0, arg);
  696. } else {
  697. if (p) {
  698. tmpend = p - 1;
  699. } else {
  700. tmpend = lstart + strlen(lstart) - 1;
  701. }
  702. if (remove_whitespace) {
  703. while (isspace((unsigned char)*tmpend)) {
  704. tmpend--;
  705. }
  706. }
  707. ret = list_cb(lstart, tmpend - lstart + 1, arg);
  708. }
  709. if (ret <= 0) {
  710. return ret;
  711. }
  712. if (p == NULL) {
  713. return 1;
  714. }
  715. lstart = p + 1;
  716. }
  717. }
  718. int CONF_modules_load_file(const char *filename, const char *appname,
  719. unsigned long flags) {
  720. return 1;
  721. }
  722. void CONF_modules_free(void) {}
  723. void OPENSSL_config(const char *config_name) {}
  724. void OPENSSL_no_config(void) {}