conf_def.c 16 KB

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