/opensource.apple.com/source/OpenSSL096/OpenSSL096-15/openssl/crypto/conf/conf_def.c

# · C · 730 lines · 618 code · 51 blank · 61 comment · 65 complexity · fd8668154382c15e2e576a758714e741 MD5 · raw file

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