conf_def.c 20 KB

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