]> git.saurik.com Git - apple/network_cmds.git/blob - racoon.tproj/cftoken.l
2a465c7778dfd49d09d2f018bae8e6f8730172c1
[apple/network_cmds.git] / racoon.tproj / cftoken.l
1 /* $KAME: cftoken.l,v 1.69 2002/09/27 06:03:51 itojun Exp $ */
2
3 %{
4 #include <sys/types.h>
5 #include <sys/param.h>
6 #include <sys/socket.h>
7
8 #include <netinet/in.h>
9 #include <netinet6/ipsec.h>
10
11 #include <stdlib.h>
12 #include <stdio.h>
13 #include <string.h>
14 #include <errno.h>
15 #include <limits.h>
16 #include <ctype.h>
17 #include <glob.h>
18 #ifdef HAVE_STDARG_H
19 #include <stdarg.h>
20 #else
21 #include <varargs.h>
22 #endif
23
24 #include "var.h"
25 #include "misc.h"
26 #include "vmbuf.h"
27 #include "plog.h"
28 #include "debug.h"
29
30 #include "algorithm.h"
31 #include "cfparse.h"
32 #include "cftoken.h"
33 #include "localconf.h"
34 #include "oakley.h"
35 #include "isakmp_var.h"
36 #include "isakmp.h"
37 #include "ipsec_doi.h"
38 #include "proposal.h"
39 #ifdef GC
40 #include "gcmalloc.h"
41 #endif
42
43 /*#include "y.tab.h"*/
44
45 int yyerrorcount = 0;
46
47 #if defined(YIPS_DEBUG)
48 # define YYDB plog(LLV_DEBUG2, LOCATION, NULL, \
49 "begin <%d>%s\n", yy_start, yytext);
50 # define YYD { \
51 plog(LLV_DEBUG2, LOCATION, NULL, "<%d>%s", \
52 yy_start, loglevel >= LLV_DEBUG2 ? "\n" : ""); \
53 }
54 #else
55 # define YYDB
56 # define YYD
57 #endif /* defined(YIPS_DEBUG) */
58
59 #define MAX_INCLUDE_DEPTH 10
60
61 static struct include_stack {
62 char *path;
63 FILE *fp;
64 YY_BUFFER_STATE prevstate;
65 int lineno;
66 glob_t matches;
67 int matchon;
68 } incstack[MAX_INCLUDE_DEPTH];
69 static int incstackp = 0;
70
71 static int yy_first_time = 1;
72 %}
73
74 /* common section */
75 nl \n
76 ws [ \t]+
77 digit [0-9]
78 letter [A-Za-z]
79 hexdigit [0-9A-Fa-f]
80 /*octet (([01]?{digit}?{digit})|((2([0-4]{digit}))|(25[0-5]))) */
81 special [()+\|\?\*]
82 comma \,
83 dot \.
84 slash \/
85 bcl \{
86 ecl \}
87 blcl \[
88 elcl \]
89 percent \%
90 semi \;
91 comment \#.*
92 ccomment "/*"
93 bracketstring \<[^>]*\>
94 quotedstring \"[^"]*\"
95 addrstring [a-fA-F0-9:]([a-fA-F0-9:\.]*|[a-fA-F0-9:\.]*%[a-zA-Z0-9]*)
96 decstring {digit}+
97 hexstring 0x{hexdigit}+
98
99 %s S_INI S_PTH S_INF S_LOG S_PAD S_LST S_RTRY
100 %s S_ALGST S_ALGCL
101 %s S_SAINF S_SAINFS
102 %s S_RMT S_RMTS S_RMTP
103 %s S_SA
104
105 %%
106 %{
107 if (yy_first_time) {
108 BEGIN S_INI;
109 yy_first_time = 0;
110 }
111 %}
112
113 /* path */
114 <S_INI>path { BEGIN S_PTH; YYDB; return(PATH); }
115 <S_PTH>include { YYD; yylval.num = LC_PATHTYPE_INCLUDE;
116 return(PATHTYPE); }
117 <S_PTH>pre_shared_key { YYD; yylval.num = LC_PATHTYPE_PSK;
118 return(PATHTYPE); }
119 <S_PTH>certificate { YYD; yylval.num = LC_PATHTYPE_CERT;
120 return(PATHTYPE); }
121 <S_PTH>backupsa { YYD; yylval.num = LC_PATHTYPE_BACKUPSA;
122 return(PATHTYPE); }
123 <S_PTH>{semi} { BEGIN S_INI; YYDB; return(EOS); }
124
125 /* include */
126 <S_INI>include { YYDB; return(INCLUDE); }
127
128 /* self information */
129 <S_INI>identifier { BEGIN S_INF; YYDB; yywarn("it is obsoleted. use \"my_identifier\" in each remote directives."); return(IDENTIFIER); }
130 <S_INF>{semi} { BEGIN S_INI; return(EOS); }
131
132 /* special */
133 <S_INI>complex_bundle { YYDB; return(COMPLEX_BUNDLE); }
134
135 /* logging */
136 <S_INI>log { BEGIN S_LOG; YYDB; return(LOGGING); }
137 <S_LOG>info { YYD; yywarn("it is obsoleted. use \"notify\""); yylval.num = 0; return(LOGLEV); }
138 <S_LOG>notify { YYD; yylval.num = 0; return(LOGLEV); }
139 <S_LOG>debug { YYD; yylval.num = 1; return(LOGLEV); }
140 <S_LOG>debug2 { YYD; yylval.num = 2; return(LOGLEV); }
141 <S_LOG>debug3 { YYD; yywarn("it is osboleted. use \"debug2\""); yylval.num = 2; return(LOGLEV); }
142 <S_LOG>debug4 { YYD; yywarn("it is obsoleted. use \"debug2\""); yylval.num = 2; return(LOGLEV); }
143 <S_LOG>{semi} { BEGIN S_INI; return(EOS); }
144
145 /* padding */
146 <S_INI>padding { BEGIN S_PAD; YYDB; return(PADDING); }
147 <S_PAD>{bcl} { return(BOC); }
148 <S_PAD>randomize { YYD; return(PAD_RANDOMIZE); }
149 <S_PAD>randomize_length { YYD; return(PAD_RANDOMIZELEN); }
150 <S_PAD>maximum_length { YYD; return(PAD_MAXLEN); }
151 <S_PAD>strict_check { YYD; return(PAD_STRICT); }
152 <S_PAD>exclusive_tail { YYD; return(PAD_EXCLTAIL); }
153 <S_PAD>{ecl} { BEGIN S_INI; return(EOC); }
154
155 /* listen */
156 <S_INI>listen { BEGIN S_LST; YYDB; return(LISTEN); }
157 <S_LST>{bcl} { return(BOC); }
158 <S_LST>isakmp { YYD; return(X_ISAKMP); }
159 <S_LST>admin { YYD; return(X_ADMIN); }
160 <S_LST>strict_address { YYD; return(STRICT_ADDRESS); }
161 <S_LST>{ecl} { BEGIN S_INI; return(EOC); }
162
163 /* timer */
164 <S_INI>timer { BEGIN S_RTRY; YYDB; return(RETRY); }
165 <S_RTRY>{bcl} { return(BOC); }
166 <S_RTRY>counter { YYD; return(RETRY_COUNTER); }
167 <S_RTRY>interval { YYD; return(RETRY_INTERVAL); }
168 <S_RTRY>persend { YYD; return(RETRY_PERSEND); }
169 <S_RTRY>phase1 { YYD; return(RETRY_PHASE1); }
170 <S_RTRY>phase2 { YYD; return(RETRY_PHASE2); }
171 <S_RTRY>{ecl} { BEGIN S_INI; return(EOC); }
172
173 /* sainfo */
174 <S_INI>sainfo { BEGIN S_SAINF; YYDB; return(SAINFO); }
175 <S_SAINF>anonymous { YYD; return(ANONYMOUS); }
176 <S_SAINF>{blcl}any{elcl} { YYD; return(PORTANY); }
177 <S_SAINF>any { YYD; return(ANY); }
178 /* sainfo spec */
179 <S_SAINF>{bcl} { BEGIN S_SAINFS; return(BOC); }
180 <S_SAINF>{semi} { BEGIN S_INI; return(EOS); }
181 <S_SAINFS>{ecl} { BEGIN S_INI; return(EOC); }
182 <S_SAINFS>pfs_group { YYD; return(PFS_GROUP); }
183 <S_SAINFS>identifier { YYD; yywarn("it is obsoleted. use \"my_identifier\"."); return(IDENTIFIER); }
184 <S_SAINFS>my_identifier { YYD; return(MY_IDENTIFIER); }
185 <S_SAINFS>lifetime { YYD; return(LIFETIME); }
186 <S_SAINFS>time { YYD; return(LIFETYPE_TIME); }
187 <S_SAINFS>byte { YYD; return(LIFETYPE_BYTE); }
188 <S_SAINFS>encryption_algorithm { YYD; yylval.num = algclass_ipsec_enc; return(ALGORITHM_CLASS); }
189 <S_SAINFS>authentication_algorithm { YYD; yylval.num = algclass_ipsec_auth; return(ALGORITHM_CLASS); }
190 <S_SAINFS>compression_algorithm { YYD; yylval.num = algclass_ipsec_comp; return(ALGORITHM_CLASS); }
191 <S_SAINFS>{comma} { YYD; return(COMMA); }
192
193 /* remote */
194 <S_INI>remote { BEGIN S_RMT; YYDB; return(REMOTE); }
195 <S_RMT>anonymous { YYD; return(ANONYMOUS); }
196 /* remote spec */
197 <S_RMT>{bcl} { BEGIN S_RMTS; return(BOC); }
198 <S_RMTS>{ecl} { BEGIN S_INI; return(EOC); }
199 <S_RMTS>exchange_mode { YYD; return(EXCHANGE_MODE); }
200 <S_RMTS>{comma} { YYD; /* XXX ignored, but to be handled. */ ; }
201 <S_RMTS>base { YYD; yylval.num = ISAKMP_ETYPE_BASE; return(EXCHANGETYPE); }
202 <S_RMTS>main { YYD; yylval.num = ISAKMP_ETYPE_IDENT; return(EXCHANGETYPE); }
203 <S_RMTS>aggressive { YYD; yylval.num = ISAKMP_ETYPE_AGG; return(EXCHANGETYPE); }
204 <S_RMTS>doi { YYD; return(DOI); }
205 <S_RMTS>ipsec_doi { YYD; yylval.num = IPSEC_DOI; return(DOITYPE); }
206 <S_RMTS>situation { YYD; return(SITUATION); }
207 <S_RMTS>identity_only { YYD; yylval.num = IPSECDOI_SIT_IDENTITY_ONLY; return(SITUATIONTYPE); }
208 <S_RMTS>secrecy { YYD; yylval.num = IPSECDOI_SIT_SECRECY; return(SITUATIONTYPE); }
209 <S_RMTS>integrity { YYD; yylval.num = IPSECDOI_SIT_INTEGRITY; return(SITUATIONTYPE); }
210 <S_RMTS>identifier { YYD; yywarn("it is obsoleted. use \"my_identifier\"."); return(IDENTIFIER); }
211 <S_RMTS>my_identifier { YYD; return(MY_IDENTIFIER); }
212 <S_RMTS>peers_identifier { YYD; return(PEERS_IDENTIFIER); }
213 <S_RMTS>verify_identifier { YYD; return(VERIFY_IDENTIFIER); }
214 <S_RMTS>open_dir_auth_group { YYD; return(OPEN_DIR_AUTH_GROUP); }
215 <S_RMTS>certificate_type { YYD; return(CERTIFICATE_TYPE); }
216 <S_RMTS>shared_secret { YYD; return(SHARED_SECRET); }
217 <S_RMTS>x509 { YYD; yylval.num = ISAKMP_CERT_X509SIGN; return(CERT_X509); }
218 <S_RMTS>in_keychain { YYD; return(IN_KEYCHAIN); }
219 <S_RMTS>certificate_verification { YYD; return(CERTIFICATE_VERIFICATION); }
220 <S_RMTS>peers_certfile { YYD; return(PEERS_CERTFILE); }
221 <S_RMTS>dnssec { YYD; return(DNSSEC); }
222 <S_RMTS>verify_cert { YYD; return(VERIFY_CERT); }
223 <S_RMTS>send_cert { YYD; return(SEND_CERT); }
224 <S_RMTS>send_cr { YYD; return(SEND_CR); }
225 <S_RMTS>dh_group { YYD; return(DH_GROUP); }
226 <S_RMTS>nonce_size { YYD; return(NONCE_SIZE); }
227 <S_RMTS>generate_policy { YYD; return(GENERATE_POLICY); }
228 <S_RMTS>support_mip6 { YYD; return(SUPPORT_MIP6); }
229 <S_RMTS>initial_contact { YYD; return(INITIAL_CONTACT); }
230 <S_RMTS>proposal_check { YYD; return(PROPOSAL_CHECK); }
231 <S_RMTS>obey { YYD; yylval.num = PROP_CHECK_OBEY; return(PROPOSAL_CHECK_LEVEL); }
232 <S_RMTS>strict { YYD; yylval.num = PROP_CHECK_STRICT; return(PROPOSAL_CHECK_LEVEL); }
233 <S_RMTS>exact { YYD; yylval.num = PROP_CHECK_EXACT; return(PROPOSAL_CHECK_LEVEL); }
234 <S_RMTS>claim { YYD; yylval.num = PROP_CHECK_CLAIM; return(PROPOSAL_CHECK_LEVEL); }
235 <S_RMTS>keepalive { YYD; return(KEEPALIVE); }
236 <S_RMTS>passive { YYD; return(PASSIVE); }
237 <S_RMTS>lifetime { YYD; return(LIFETIME); }
238 <S_RMTS>time { YYD; return(LIFETYPE_TIME); }
239 <S_RMTS>byte { YYD; return(LIFETYPE_BYTE); }
240 /* remote proposal */
241 <S_RMTS>proposal { BEGIN S_RMTP; YYDB; return(PROPOSAL); }
242 <S_RMTP>{bcl} { return(BOC); }
243 <S_RMTP>{ecl} { BEGIN S_RMTS; return(EOC); }
244 <S_RMTP>lifetime { YYD; return(LIFETIME); }
245 <S_RMTP>time { YYD; return(LIFETYPE_TIME); }
246 <S_RMTP>byte { YYD; return(LIFETYPE_BYTE); }
247 <S_RMTP>encryption_algorithm { YYD; yylval.num = algclass_isakmp_enc; return(ALGORITHM_CLASS); }
248 <S_RMTP>authentication_method { YYD; yylval.num = algclass_isakmp_ameth; return(ALGORITHM_CLASS); }
249 <S_RMTP>hash_algorithm { YYD; yylval.num = algclass_isakmp_hash; return(ALGORITHM_CLASS); }
250 <S_RMTP>dh_group { YYD; return(DH_GROUP); }
251 <S_RMTP>gssapi_id { YYD; return(GSSAPI_ID); }
252
253 /* parameter */
254 on { YYD; yylval.num = TRUE; return(SWITCH); }
255 off { YYD; yylval.num = FALSE; return(SWITCH); }
256
257 /* prefix */
258 {slash}{digit}{1,3} {
259 YYD;
260 yytext++;
261 yylval.num = atoi(yytext);
262 return(PREFIX);
263 }
264
265 /* port number */
266 {blcl}{decstring}{elcl} {
267 char *p = yytext;
268 YYD;
269 while (*++p != ']') ;
270 *p = NULL;
271 yytext++;
272 yylval.num = atoi(yytext);
273 return(PORT);
274 }
275
276 /* upper protocol */
277 esp { YYD; yylval.num = IPPROTO_ESP; return(UL_PROTO); }
278 ah { YYD; yylval.num = IPPROTO_AH; return(UL_PROTO); }
279 ipcomp { YYD; yylval.num = IPPROTO_IPCOMP; return(UL_PROTO); }
280 icmp { YYD; yylval.num = IPPROTO_ICMP; return(UL_PROTO); }
281 icmp6 { YYD; yylval.num = IPPROTO_ICMPV6; return(UL_PROTO); }
282 tcp { YYD; yylval.num = IPPROTO_TCP; return(UL_PROTO); }
283 udp { YYD; yylval.num = IPPROTO_UDP; return(UL_PROTO); }
284
285 /* algorithm type */
286 des_iv64 { YYD; yylval.num = algtype_des_iv64; return(ALGORITHMTYPE); }
287 des { YYD; yylval.num = algtype_des; return(ALGORITHMTYPE); }
288 3des { YYD; yylval.num = algtype_3des; return(ALGORITHMTYPE); }
289 rc5 { YYD; yylval.num = algtype_rc5; return(ALGORITHMTYPE); }
290 idea { YYD; yylval.num = algtype_idea; return(ALGORITHMTYPE); }
291 cast128 { YYD; yylval.num = algtype_cast128; return(ALGORITHMTYPE); }
292 blowfish { YYD; yylval.num = algtype_blowfish; return(ALGORITHMTYPE); }
293 3idea { YYD; yylval.num = algtype_3idea; return(ALGORITHMTYPE); }
294 des_iv32 { YYD; yylval.num = algtype_des_iv32; return(ALGORITHMTYPE); }
295 rc4 { YYD; yylval.num = algtype_rc4; return(ALGORITHMTYPE); }
296 null_enc { YYD; yylval.num = algtype_null_enc; return(ALGORITHMTYPE); }
297 rijndael { YYD; yylval.num = algtype_rijndael; return(ALGORITHMTYPE); }
298 aes { YYD; yylval.num = algtype_rijndael; return(ALGORITHMTYPE); }
299 twofish { YYD; yylval.num = algtype_twofish; return(ALGORITHMTYPE); }
300 non_auth { YYD; yylval.num = algtype_non_auth; return(ALGORITHMTYPE); }
301 hmac_md5 { YYD; yylval.num = algtype_hmac_md5; return(ALGORITHMTYPE); }
302 hmac_sha1 { YYD; yylval.num = algtype_hmac_sha1; return(ALGORITHMTYPE); }
303 hmac_sha2_256 { YYD; yylval.num = algtype_hmac_sha2_256; return(ALGORITHMTYPE); }
304 hmac_sha2_384 { YYD; yylval.num = algtype_hmac_sha2_384; return(ALGORITHMTYPE); }
305 hmac_sha2_512 { YYD; yylval.num = algtype_hmac_sha2_512; return(ALGORITHMTYPE); }
306 des_mac { YYD; yylval.num = algtype_des_mac; return(ALGORITHMTYPE); }
307 kpdk { YYD; yylval.num = algtype_kpdk; return(ALGORITHMTYPE); }
308 md5 { YYD; yylval.num = algtype_md5; return(ALGORITHMTYPE); }
309 sha1 { YYD; yylval.num = algtype_sha1; return(ALGORITHMTYPE); }
310 tiger { YYD; yylval.num = algtype_tiger; return(ALGORITHMTYPE); }
311 sha2_256 { YYD; yylval.num = algtype_sha2_256; return(ALGORITHMTYPE); }
312 sha2_384 { YYD; yylval.num = algtype_sha2_384; return(ALGORITHMTYPE); }
313 sha2_512 { YYD; yylval.num = algtype_sha2_512; return(ALGORITHMTYPE); }
314 oui { YYD; yylval.num = algtype_oui; return(ALGORITHMTYPE); }
315 deflate { YYD; yylval.num = algtype_deflate; return(ALGORITHMTYPE); }
316 lzs { YYD; yylval.num = algtype_lzs; return(ALGORITHMTYPE); }
317 modp768 { YYD; yylval.num = algtype_modp768; return(ALGORITHMTYPE); }
318 modp1024 { YYD; yylval.num = algtype_modp1024; return(ALGORITHMTYPE); }
319 modp1536 { YYD; yylval.num = algtype_modp1536; return(ALGORITHMTYPE); }
320 ec2n155 { YYD; yylval.num = algtype_ec2n155; return(ALGORITHMTYPE); }
321 ec2n185 { YYD; yylval.num = algtype_ec2n185; return(ALGORITHMTYPE); }
322 modp2048 { YYD; yylval.num = algtype_modp2048; return(ALGORITHMTYPE); }
323 modp3072 { YYD; yylval.num = algtype_modp3072; return(ALGORITHMTYPE); }
324 modp4096 { YYD; yylval.num = algtype_modp4096; return(ALGORITHMTYPE); }
325 modp6144 { YYD; yylval.num = algtype_modp6144; return(ALGORITHMTYPE); }
326 modp8192 { YYD; yylval.num = algtype_modp8192; return(ALGORITHMTYPE); }
327 pre_shared_key { YYD; yylval.num = algtype_psk; return(ALGORITHMTYPE); }
328 rsasig { YYD; yylval.num = algtype_rsasig; return(ALGORITHMTYPE); }
329 dsssig { YYD; yylval.num = algtype_dsssig; return(ALGORITHMTYPE); }
330 rsaenc { YYD; yylval.num = algtype_rsaenc; return(ALGORITHMTYPE); }
331 rsarev { YYD; yylval.num = algtype_rsarev; return(ALGORITHMTYPE); }
332 gssapi_krb { YYD; yylval.num = algtype_gssapikrb; return(ALGORITHMTYPE); }
333
334 /* identifier type */
335 vendor_id { YYD; yywarn("it is obsoleted."); return(VENDORID); }
336 user_fqdn { YYD; yylval.num = IDTYPE_USERFQDN; return(IDENTIFIERTYPE); }
337 fqdn { YYD; yylval.num = IDTYPE_FQDN; return(IDENTIFIERTYPE); }
338 keyid { YYD; yylval.num = IDTYPE_KEYID; return(IDENTIFIERTYPE); }
339 address { YYD; yylval.num = IDTYPE_ADDRESS; return(IDENTIFIERTYPE); }
340 asn1dn { YYD; yylval.num = IDTYPE_ASN1DN; return(IDENTIFIERTYPE); }
341 certname { YYD; yywarn("certname will be obsoleted in near future."); yylval.num = IDTYPE_ASN1DN; return(IDENTIFIERTYPE); }
342
343 /* shared secret type */
344 use { YYD; yylval.num = SECRETTYPE_USE; return(SECRETTYPE); }
345 key { YYD; yylval.num = SECRETTYPE_KEY; return(SECRETTYPE); }
346 keychain { YYD; yylval.num = SECRETTYPE_KEYCHAIN; return(SECRETTYPE); }
347
348 /* certificate verification */
349 openssl { YYD; yylval.num = VERIFICATION_MODULE_OPENSSL; return(VERIFICATION_MODULE); }
350 sec_framework { YYD; yylval.num = VERIFICATION_MODULE_SEC_FRAMEWORK; return(VERIFICATION_MODULE); }
351 use_open_dir { YYD; yylval.num = VERIFICATION_OPTION_OPEN_DIR; return(VERIFICATION_OPTION); }
352 use_peers_identifier { YYD; yylval.num = VERIFICATION_OPTION_PEERS_IDENTIFIER; return(VERIFICATION_OPTION); }
353
354 /* units */
355 B|byte|bytes { YYD; return(UNITTYPE_BYTE); }
356 KB { YYD; return(UNITTYPE_KBYTES); }
357 MB { YYD; return(UNITTYPE_MBYTES); }
358 TB { YYD; return(UNITTYPE_TBYTES); }
359 sec|secs|second|seconds { YYD; return(UNITTYPE_SEC); }
360 min|mins|minute|minutes { YYD; return(UNITTYPE_MIN); }
361 hour|hours { YYD; return(UNITTYPE_HOUR); }
362
363 /* boolean */
364 yes { YYD; yylval.num = TRUE; return(BOOLEAN); }
365 no { YYD; yylval.num = FALSE; return(BOOLEAN); }
366
367 {decstring} {
368 char *bp;
369
370 YYD;
371 yylval.num = strtol(yytext, &bp, 10);
372 return(NUMBER);
373 }
374
375 {hexstring} {
376 char *p;
377
378 YYD;
379 yylval.val = vmalloc(yyleng + (yyleng & 1) + 1);
380 if (yylval.val == NULL) {
381 yyerror("vmalloc failed");
382 return -1;
383 }
384
385 p = yylval.val->v;
386 *p++ = '0';
387 *p++ = 'x';
388
389 /* fixed string if length is odd. */
390 if (yyleng & 1)
391 *p++ = '0';
392 memcpy(p, &yytext[2], yyleng - 1);
393
394 return(HEXSTRING);
395 }
396
397 {quotedstring} {
398 u_char *p = yytext;
399
400 YYD;
401 while (*++p != '"') ;
402 *p = '\0';
403
404 yylval.val = vmalloc(yyleng - 1);
405 if (yylval.val == NULL) {
406 yyerror("vmalloc failed");
407 return -1;
408 }
409 memcpy(yylval.val->v, &yytext[1], yylval.val->l);
410
411 return(QUOTEDSTRING);
412 }
413
414 {addrstring} {
415 YYD;
416
417 yylval.val = vmalloc(yyleng + 1);
418 if (yylval.val == NULL) {
419 yyerror("vmalloc failed");
420 return -1;
421 }
422 memcpy(yylval.val->v, yytext, yylval.val->l);
423
424 return(ADDRSTRING);
425 }
426
427 <<EOF>> {
428 yy_delete_buffer(YY_CURRENT_BUFFER);
429 fclose(incstack[incstackp].fp);
430 incstack[incstackp].fp = -1;
431 racoon_free(incstack[incstackp].path);
432 incstack[incstackp].path = NULL;
433 incstackp--;
434 nextfile:
435 if (incstack[incstackp].matchon < incstack[incstackp].matches.gl_pathc)
436 {
437 char* filepath = incstack[incstackp].matches.gl_pathv[incstack[incstackp].matchon];
438 incstack[incstackp].matchon++;
439 incstackp++;
440 if (yycf_set_buffer(filepath) != 0)
441 {
442 incstackp--;
443 goto nextfile;
444 }
445
446 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
447
448 BEGIN(S_INI);
449 }
450 else
451 {
452 globfree(&incstack[incstackp].matches);
453 if (incstackp == 0)
454 yyterminate();
455 else
456 yy_switch_to_buffer(incstack[incstackp].prevstate);
457 }
458 }
459
460 /* ... */
461 {ws} { ; }
462 {nl} { incstack[incstackp].lineno++; }
463 {comment} { YYD; }
464 {semi} { return(EOS); }
465 . { yymore(); }
466
467 %%
468
469 void
470 yyerror(char *s, ...)
471 {
472 char fmt[512];
473
474 va_list ap;
475 #ifdef HAVE_STDARG_H
476 va_start(ap, s);
477 #else
478 va_start(ap);
479 #endif
480 snprintf(fmt, sizeof(fmt), "%s:%d: \"%s\" %s\n",
481 incstack[incstackp].path, incstack[incstackp].lineno,
482 yytext, s);
483 plogv(LLV_ERROR, LOCATION, NULL, fmt, ap);
484 va_end(ap);
485
486 yyerrorcount++;
487 }
488
489 void
490 yywarn(char *s, ...)
491 {
492 char fmt[512];
493
494 va_list ap;
495 #ifdef HAVE_STDARG_H
496 va_start(ap, s);
497 #else
498 va_start(ap);
499 #endif
500 snprintf(fmt, sizeof(fmt), "%s:%d: \"%s\" %s\n",
501 incstack[incstackp].path, incstack[incstackp].lineno,
502 yytext, s);
503 plogv(LLV_WARNING, LOCATION, NULL, fmt, ap);
504 va_end(ap);
505 }
506
507 int
508 yycf_switch_buffer(path)
509 char *path;
510 {
511 char* filepath = NULL;
512 /* got the include file name */
513 if (incstackp >= MAX_INCLUDE_DEPTH) {
514 plog(LLV_ERROR, LOCATION, NULL,
515 "Includes nested too deeply");
516 return -1;
517 }
518
519 if (glob(path, GLOB_TILDE, NULL, &incstack[incstackp].matches) != 0 ||
520 incstack[incstackp].matches.gl_pathc == 0)
521 {
522 plog(LLV_DEBUG, LOCATION, NULL,
523 "glob found no matches for path\n");
524 return 0;
525 }
526 incstack[incstackp].matchon = 0;
527 incstack[incstackp].prevstate = YY_CURRENT_BUFFER;
528
529 nextmatch:
530 if (incstack[incstackp].matchon >= incstack[incstackp].matches.gl_pathc) return -1;
531 filepath = incstack[incstackp].matches.gl_pathv[incstack[incstackp].matchon];
532 incstack[incstackp].matchon++;
533 incstackp++;
534
535 if (yycf_set_buffer(filepath) != 0)
536 {
537 incstackp--;
538 goto nextmatch;
539 }
540
541 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
542
543 BEGIN(S_INI);
544
545 return 0;
546 }
547
548 int
549 yycf_set_buffer(path)
550 char *path;
551 {
552 yyin = fopen(path, "r");
553 if (yyin == NULL) {
554 fprintf(stderr, "failed to open file %s (%s)\n",
555 path, strerror(errno));
556 plog(LLV_ERROR, LOCATION, NULL,
557 "failed to open file %s (%s)\n",
558 path, strerror(errno));
559 return -1;
560 }
561
562 /* initialize */
563 incstack[incstackp].fp = yyin;
564 incstack[incstackp].path = strdup(path);
565 incstack[incstackp].lineno = 1;
566 plog(LLV_DEBUG, LOCATION, NULL,
567 "reading config file %s\n",
568 path, 0);
569
570 return 0;
571 }
572
573 void
574 yycf_init_buffer()
575 {
576 int i;
577
578 for (i = 0; i < MAX_INCLUDE_DEPTH; i++)
579 memset(&incstack[i], 0, sizeof(incstack[i]));
580 incstackp = 0;
581 }
582
583 void
584 yycf_clean_buffer()
585 {
586 int i;
587
588 for (i = 0; i < MAX_INCLUDE_DEPTH; i++) {
589 if (incstack[i].path != NULL) {
590 if (incstack[i].fp >= 0)
591 fclose(incstack[i].fp);
592 racoon_free(incstack[i].path);
593 incstack[i].path = NULL;
594 }
595 }
596 }
597