No empty .Rs/.Re
[netbsd-mini2440.git] / crypto / dist / ipsec-tools / src / racoon / cftoken.l
blob89f87bfc8ead2cc7985f4d481679a442ea5d6cb2
1 /*      $NetBSD: cftoken.l,v 1.19 2009/01/05 06:03:58 tteras Exp $      */
3 /* Id: cftoken.l,v 1.53 2006/08/22 18:17:17 manubsd Exp */
5 %{
6 /*
7  * Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002 and 2003 WIDE Project.
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. Neither the name of the project nor the names of its contributors
19  *    may be used to endorse or promote products derived from this software
20  *    without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  */
35 #include "config.h"
37 #include <sys/types.h>
38 #include <sys/param.h>
39 #include <sys/socket.h>
41 #include <netinet/in.h>
42 #include PATH_IPSEC_H
44 #include <stdlib.h>
45 #include <stdio.h>
46 #include <string.h>
47 #include <errno.h>
48 #include <limits.h>
49 #include <ctype.h>
50 #include <glob.h>
51 #ifdef HAVE_STDARG_H
52 #include <stdarg.h>
53 #else
54 #include <varargs.h>
55 #endif
57 #include "var.h"
58 #include "misc.h"
59 #include "vmbuf.h"
60 #include "plog.h"
61 #include "debug.h"
63 #include "algorithm.h"
64 #include "cfparse_proto.h"
65 #include "cftoken_proto.h"
66 #include "localconf.h"
67 #include "oakley.h"
68 #include "isakmp_var.h"
69 #include "isakmp.h"
70 #include "ipsec_doi.h"
71 #include "policy.h"
72 #include "proposal.h"
73 #include "remoteconf.h"
74 #ifdef GC
75 #include "gcmalloc.h"
76 #endif
78 #include "cfparse.h"
80 int yyerrorcount = 0;
82 #if defined(YIPS_DEBUG)
83 #  define YYDB plog(LLV_DEBUG2, LOCATION, NULL,                                \
84                 "begin <%d>%s\n", yy_start, yytext);
85 #  define YYD {                                                                \
86         plog(LLV_DEBUG2, LOCATION, NULL, "<%d>%s",                             \
87             yy_start, loglevel >= LLV_DEBUG2 ? "\n" : "");                     \
89 #else
90 #  define YYDB
91 #  define YYD
92 #endif /* defined(YIPS_DEBUG) */
94 #define MAX_INCLUDE_DEPTH 10
96 static struct include_stack {
97         char *path;
98         FILE *fp;
99         YY_BUFFER_STATE prevstate;
100         int lineno;
101         glob_t matches;
102         int matchon;
103 } incstack[MAX_INCLUDE_DEPTH];
104 static int incstackp = 0;
106 static int yy_first_time = 1;
109 /* common seciton */
110 nl              \n
111 ws              [ \t]+
112 digit           [0-9]
113 letter          [A-Za-z]
114 hexdigit        [0-9A-Fa-f]
115 /*octet         (([01]?{digit}?{digit})|((2([0-4]{digit}))|(25[0-5]))) */
116 special         [()+\|\?\*]
117 comma           \,
118 dot             \.
119 slash           \/
120 bcl             \{
121 ecl             \}
122 blcl            \[
123 elcl            \]
124 hyphen          \-
125 percent         \%
126 semi            \;
127 comment         \#.*
128 ccomment        "/*"
129 bracketstring   \<[^>]*\>
130 quotedstring    \"[^"]*\"
131 addrstring      [a-fA-F0-9:]([a-fA-F0-9:\.]*|[a-fA-F0-9:\.]*%[a-zA-Z0-9]*)
132 decstring       {digit}+
133 hexstring       0x{hexdigit}+
135 %s S_INI S_PRIV S_PTH S_LOG S_PAD S_LST S_RTRY S_CFG S_LDAP S_RAD
136 %s S_ALGST S_ALGCL
137 %s S_SAINF S_SAINFS
138 %s S_RMT S_RMTS S_RMTP
139 %s S_SA
140 %s S_GSSENC
144         if (yy_first_time) {
145                 BEGIN S_INI;
146                 yy_first_time = 0;
147         }
150         /* privsep */
151 <S_INI>privsep          { BEGIN S_PRIV; YYDB; return(PRIVSEP); }
152 <S_PRIV>{bcl}           { return(BOC); }
153 <S_PRIV>user            { YYD; return(USER); }
154 <S_PRIV>group           { YYD; return(GROUP); }
155 <S_PRIV>chroot          { YYD; return(CHROOT); }
156 <S_PRIV>{ecl}           { BEGIN S_INI; return(EOC); }
158         /* path */
159 <S_INI>path             { BEGIN S_PTH; YYDB; return(PATH); }
160 <S_PTH>include          { YYD; yylval.num = LC_PATHTYPE_INCLUDE;
161                                 return(PATHTYPE); }
162 <S_PTH>pre_shared_key   { YYD; yylval.num = LC_PATHTYPE_PSK;
163                                 return(PATHTYPE); }
164 <S_PTH>certificate      { YYD; yylval.num = LC_PATHTYPE_CERT;
165                                 return(PATHTYPE); }
166 <S_PTH>script           { YYD; yylval.num = LC_PATHTYPE_SCRIPT;
167                                 return(PATHTYPE); }
168 <S_PTH>backupsa         { YYD; yylval.num = LC_PATHTYPE_BACKUPSA;
169                                 return(PATHTYPE); }
170 <S_PTH>pidfile          { YYD; yylval.num = LC_PATHTYPE_PIDFILE;
171                                 return(PATHTYPE); }
172 <S_PTH>{semi}           { BEGIN S_INI; YYDB; return(EOS); }
174         /* include */
175 <S_INI>include          { YYDB; return(INCLUDE); }
177     /* pfkey_buffer */
178 <S_INI>pfkey_buffer { YYDB; return(PFKEY_BUFFER); }
180         /* special */
181 <S_INI>complex_bundle   { YYDB; return(COMPLEX_BUNDLE); }
183         /* logging */
184 <S_INI>log              { BEGIN S_LOG; YYDB; return(LOGGING); }
185 <S_LOG>error            { YYD; yylval.num = LLV_ERROR; return(LOGLEV); }
186 <S_LOG>warning          { YYD; yylval.num = LLV_WARNING; return(LOGLEV); }
187 <S_LOG>notify           { YYD; yylval.num = LLV_NOTIFY; return(LOGLEV); }
188 <S_LOG>info             { YYD; yylval.num = LLV_INFO; return(LOGLEV); }
189 <S_LOG>debug            { YYD; yylval.num = LLV_DEBUG; return(LOGLEV); }
190 <S_LOG>debug2           { YYD; yylval.num = LLV_DEBUG2; return(LOGLEV); }
191 <S_LOG>{semi}           { BEGIN S_INI; return(EOS); }
193         /* padding */
194 <S_INI>padding          { BEGIN S_PAD; YYDB; return(PADDING); }
195 <S_PAD>{bcl}            { return(BOC); }
196 <S_PAD>randomize        { YYD; return(PAD_RANDOMIZE); }
197 <S_PAD>randomize_length { YYD; return(PAD_RANDOMIZELEN); }
198 <S_PAD>maximum_length   { YYD; return(PAD_MAXLEN); }
199 <S_PAD>strict_check     { YYD; return(PAD_STRICT); }
200 <S_PAD>exclusive_tail   { YYD; return(PAD_EXCLTAIL); }
201 <S_PAD>{ecl}            { BEGIN S_INI; return(EOC); }
203         /* listen */
204 <S_INI>listen           { BEGIN S_LST; YYDB; return(LISTEN); }
205 <S_LST>{bcl}            { return(BOC); }
206 <S_LST>isakmp           { YYD; return(X_ISAKMP); }
207 <S_LST>isakmp_natt      { YYD; return(X_ISAKMP_NATT); }
208 <S_LST>admin            { YYD; return(X_ADMIN); }
209 <S_LST>adminsock        { YYD; return(ADMINSOCK); }
210 <S_LST>disabled         { YYD; return(DISABLED); }
211 <S_LST>strict_address   { YYD; return(STRICT_ADDRESS); }
212 <S_LST>{ecl}            { BEGIN S_INI; return(EOC); }
214         /* radius config */
215 <S_INI>radiuscfg        { BEGIN S_RAD; YYDB; return(RADCFG); }
216 <S_RAD>{bcl}            { return(BOC); }
217 <S_RAD>auth             { YYD; return(RAD_AUTH); }
218 <S_RAD>acct             { YYD; return(RAD_ACCT); }
219 <S_RAD>timeout          { YYD; return(RAD_TIMEOUT); }
220 <S_RAD>retries          { YYD; return(RAD_RETRIES); }
221 <S_RAD>{ecl}            { BEGIN S_INI; return(EOC); }
223         /* ldap config */
224 <S_INI>ldapcfg          { BEGIN S_LDAP; YYDB; return(LDAPCFG); }
225 <S_LDAP>{bcl}           { return(BOC); }
226 <S_LDAP>version         { YYD; return(LDAP_PVER); }
227 <S_LDAP>host            { YYD; return(LDAP_HOST); }
228 <S_LDAP>port            { YYD; return(LDAP_PORT); }
229 <S_LDAP>base            { YYD; return(LDAP_BASE); }
230 <S_LDAP>subtree         { YYD; return(LDAP_SUBTREE); }
231 <S_LDAP>bind_dn         { YYD; return(LDAP_BIND_DN); }
232 <S_LDAP>bind_pw         { YYD; return(LDAP_BIND_PW); }
233 <S_LDAP>attr_user       { YYD; return(LDAP_ATTR_USER); }
234 <S_LDAP>attr_addr       { YYD; return(LDAP_ATTR_ADDR); }
235 <S_LDAP>attr_mask       { YYD; return(LDAP_ATTR_MASK); }
236 <S_LDAP>attr_group      { YYD; return(LDAP_ATTR_GROUP); }
237 <S_LDAP>attr_member     { YYD; return(LDAP_ATTR_MEMBER); }
238 <S_LDAP>{ecl}           { BEGIN S_INI; return(EOC); }
240         /* mode_cfg */
241 <S_INI>mode_cfg         { BEGIN S_CFG; YYDB; return(MODECFG); }
242 <S_CFG>{bcl}            { return(BOC); }
243 <S_CFG>network4         { YYD; return(CFG_NET4); }
244 <S_CFG>netmask4         { YYD; return(CFG_MASK4); }
245 <S_CFG>dns4             { YYD; return(CFG_DNS4); }
246 <S_CFG>nbns4            { YYD; return(CFG_NBNS4); }
247 <S_CFG>wins4            { YYD; return(CFG_NBNS4); }
248 <S_CFG>default_domain   { YYD; return(CFG_DEFAULT_DOMAIN); }
249 <S_CFG>auth_source      { YYD; return(CFG_AUTH_SOURCE); }
250 <S_CFG>auth_groups      { YYD; return(CFG_AUTH_GROUPS); }
251 <S_CFG>group_source     { YYD; return(CFG_GROUP_SOURCE); }
252 <S_CFG>conf_source      { YYD; return(CFG_CONF_SOURCE); }
253 <S_CFG>accounting       { YYD; return(CFG_ACCOUNTING); }
254 <S_CFG>system           { YYD; return(CFG_SYSTEM); }
255 <S_CFG>local            { YYD; return(CFG_LOCAL); }
256 <S_CFG>none             { YYD; return(CFG_NONE); }
257 <S_CFG>radius           { YYD; return(CFG_RADIUS); }
258 <S_CFG>pam              { YYD; return(CFG_PAM); }
259 <S_CFG>ldap             { YYD; return(CFG_LDAP); }
260 <S_CFG>pool_size        { YYD; return(CFG_POOL_SIZE); }
261 <S_CFG>banner           { YYD; return(CFG_MOTD); }
262 <S_CFG>auth_throttle    { YYD; return(CFG_AUTH_THROTTLE); }
263 <S_CFG>split_network    { YYD; return(CFG_SPLIT_NETWORK); }
264 <S_CFG>local_lan        { YYD; return(CFG_SPLIT_LOCAL); }
265 <S_CFG>include          { YYD; return(CFG_SPLIT_INCLUDE); }
266 <S_CFG>split_dns        { YYD; return(CFG_SPLIT_DNS); }
267 <S_CFG>pfs_group        { YYD; return(CFG_PFS_GROUP); }
268 <S_CFG>save_passwd      { YYD; return(CFG_SAVE_PASSWD); }
269 <S_CFG>{comma}          { YYD; return(COMMA); }
270 <S_CFG>{ecl}            { BEGIN S_INI; return(EOC); }
272         /* timer */
273 <S_INI>timer            { BEGIN S_RTRY; YYDB; return(RETRY); }
274 <S_RTRY>{bcl}           { return(BOC); }
275 <S_RTRY>counter         { YYD; return(RETRY_COUNTER); }
276 <S_RTRY>interval        { YYD; return(RETRY_INTERVAL); }
277 <S_RTRY>persend         { YYD; return(RETRY_PERSEND); }
278 <S_RTRY>phase1          { YYD; return(RETRY_PHASE1); }
279 <S_RTRY>phase2          { YYD; return(RETRY_PHASE2); }
280 <S_RTRY>natt_keepalive  { YYD; return(NATT_KA); }
281 <S_RTRY>{ecl}           { BEGIN S_INI; return(EOC); }
283         /* sainfo */
284 <S_INI>sainfo           { BEGIN S_SAINF; YYDB; return(SAINFO); }
285 <S_SAINF>anonymous      { YYD; return(ANONYMOUS); }
286 <S_SAINF>clientaddr     { YYD; return(CLIENTADDR); }
287 <S_SAINF>{blcl}any{elcl}        { YYD; return(PORTANY); }
288 <S_SAINF>any            { YYD; return(ANY); }
289 <S_SAINF>from           { YYD; return(FROM); }
290 <S_SAINF>group          { YYD; return(GROUP); }
291         /* sainfo spec */
292 <S_SAINF>{bcl}          { BEGIN S_SAINFS; return(BOC); }
293 <S_SAINF>{semi}         { BEGIN S_INI; return(EOS); }
294 <S_SAINFS>{ecl}         { BEGIN S_INI; return(EOC); }
295 <S_SAINFS>pfs_group     { YYD; return(PFS_GROUP); }
296 <S_SAINFS>remoteid      { YYD; return(REMOTEID); }
297 <S_SAINFS>my_identifier { YYD; return(MY_IDENTIFIER); }
298 <S_SAINFS>lifetime      { YYD; return(LIFETIME); }
299 <S_SAINFS>time          { YYD; return(LIFETYPE_TIME); }
300 <S_SAINFS>byte          { YYD; return(LIFETYPE_BYTE); }
301 <S_SAINFS>encryption_algorithm { YYD; yylval.num = algclass_ipsec_enc; return(ALGORITHM_CLASS); }
302 <S_SAINFS>authentication_algorithm { YYD; yylval.num = algclass_ipsec_auth; return(ALGORITHM_CLASS); }
303 <S_SAINFS>compression_algorithm { YYD; yylval.num = algclass_ipsec_comp; return(ALGORITHM_CLASS); }
304 <S_SAINFS>{comma}       { YYD; return(COMMA); }
306         /* remote */
307 <S_INI>remote           { BEGIN S_RMT; YYDB; return(REMOTE); }
308 <S_RMT>anonymous        { YYD; return(ANONYMOUS); }
309 <S_RMT>inherit          { YYD; return(INHERIT); }
310         /* remote spec */
311 <S_RMT>{bcl}            { BEGIN S_RMTS; return(BOC); }
312 <S_RMTS>{ecl}           { BEGIN S_INI; return(EOC); }
313 <S_RMTS>remote_address  { YYD; return(REMOTE_ADDRESS); }
314 <S_RMTS>exchange_mode   { YYD; return(EXCHANGE_MODE); }
315 <S_RMTS>{comma}         { YYD; /* XXX ignored, but to be handled. */ ; }
316 <S_RMTS>base            { YYD; yylval.num = ISAKMP_ETYPE_BASE; return(EXCHANGETYPE); }
317 <S_RMTS>main            { YYD; yylval.num = ISAKMP_ETYPE_IDENT; return(EXCHANGETYPE); }
318 <S_RMTS>aggressive      { YYD; yylval.num = ISAKMP_ETYPE_AGG; return(EXCHANGETYPE); }
319 <S_RMTS>doi             { YYD; return(DOI); }
320 <S_RMTS>ipsec_doi       { YYD; yylval.num = IPSEC_DOI; return(DOITYPE); }
321 <S_RMTS>situation       { YYD; return(SITUATION); }
322 <S_RMTS>identity_only   { YYD; yylval.num = IPSECDOI_SIT_IDENTITY_ONLY; return(SITUATIONTYPE); }
323 <S_RMTS>secrecy         { YYD; yylval.num = IPSECDOI_SIT_SECRECY; return(SITUATIONTYPE); }
324 <S_RMTS>integrity       { YYD; yylval.num = IPSECDOI_SIT_INTEGRITY; return(SITUATIONTYPE); }
325 <S_RMTS>my_identifier   { YYD; return(MY_IDENTIFIER); }
326 <S_RMTS>xauth_login     { YYD; return(XAUTH_LOGIN); /* formerly identifier type login */ }
327 <S_RMTS>peers_identifier        { YYD; return(PEERS_IDENTIFIER); }
328 <S_RMTS>verify_identifier       { YYD; return(VERIFY_IDENTIFIER); }
329 <S_RMTS>certificate_type        { YYD; return(CERTIFICATE_TYPE); }
330 <S_RMTS>ca_type         { YYD; return(CA_TYPE); }
331 <S_RMTS>x509            { YYD; yylval.num = ISAKMP_CERT_X509SIGN; return(CERT_X509); }
332 <S_RMTS>plain_rsa       { YYD; yylval.num = ISAKMP_CERT_PLAINRSA; return(CERT_PLAINRSA); }
333 <S_RMTS>peers_certfile  { YYD; return(PEERS_CERTFILE); }
334 <S_RMTS>dnssec          { YYD; return(DNSSEC); }
335 <S_RMTS>verify_cert     { YYD; return(VERIFY_CERT); }
336 <S_RMTS>send_cert       { YYD; return(SEND_CERT); }
337 <S_RMTS>send_cr         { YYD; return(SEND_CR); }
338 <S_RMTS>match_empty_cr  { YYD; return(MATCH_EMPTY_CR); }
339 <S_RMTS>dh_group        { YYD; return(DH_GROUP); }
340 <S_RMTS>nonce_size      { YYD; return(NONCE_SIZE); }
341 <S_RMTS>generate_policy { YYD; return(GENERATE_POLICY); }
342 <S_RMTS>unique          { YYD; yylval.num = GENERATE_POLICY_UNIQUE; return(GENERATE_LEVEL); }
343 <S_RMTS>require         { YYD; yylval.num = GENERATE_POLICY_REQUIRE; return(GENERATE_LEVEL); }
344 <S_RMTS>support_proxy   { YYD; return(SUPPORT_PROXY); }
345 <S_RMTS>initial_contact { YYD; return(INITIAL_CONTACT); }
346 <S_RMTS>nat_traversal   { YYD; return(NAT_TRAVERSAL); }
347 <S_RMTS>force           { YYD; return(REMOTE_FORCE_LEVEL); }
348 <S_RMTS>proposal_check  { YYD; return(PROPOSAL_CHECK); }
349 <S_RMTS>obey            { YYD; yylval.num = PROP_CHECK_OBEY; return(PROPOSAL_CHECK_LEVEL); }
350 <S_RMTS>strict          { YYD; yylval.num = PROP_CHECK_STRICT; return(PROPOSAL_CHECK_LEVEL); }
351 <S_RMTS>exact           { YYD; yylval.num = PROP_CHECK_EXACT; return(PROPOSAL_CHECK_LEVEL); }
352 <S_RMTS>claim           { YYD; yylval.num = PROP_CHECK_CLAIM; return(PROPOSAL_CHECK_LEVEL); }
353 <S_RMTS>keepalive       { YYD; return(KEEPALIVE); }
354 <S_RMTS>passive         { YYD; return(PASSIVE); }
355 <S_RMTS>lifetime        { YYD; return(LIFETIME); }
356 <S_RMTS>time            { YYD; return(LIFETYPE_TIME); }
357 <S_RMTS>byte            { YYD; return(LIFETYPE_BYTE); }
358 <S_RMTS>dpd                     { YYD; return(DPD); }
359 <S_RMTS>dpd_delay       { YYD; return(DPD_DELAY); }
360 <S_RMTS>dpd_retry       { YYD; return(DPD_RETRY); }
361 <S_RMTS>dpd_maxfail     { YYD; return(DPD_MAXFAIL); }
362 <S_RMTS>ph1id           { YYD; return(PH1ID); }
363 <S_RMTS>ike_frag        { YYD; return(IKE_FRAG); }
364 <S_RMTS>esp_frag        { YYD; return(ESP_FRAG); }
365 <S_RMTS>script          { YYD; return(SCRIPT); }
366 <S_RMTS>phase1_up       { YYD; return(PHASE1_UP); }
367 <S_RMTS>phase1_down     { YYD; return(PHASE1_DOWN); }
368 <S_RMTS>mode_cfg        { YYD; return(MODE_CFG); }
369 <S_RMTS>weak_phase1_check { YYD; return(WEAK_PHASE1_CHECK); }
370 <S_RMTS>rekey           { YYD; return(REKEY); }
371         /* remote proposal */
372 <S_RMTS>proposal        { BEGIN S_RMTP; YYDB; return(PROPOSAL); }
373 <S_RMTP>{bcl}           { return(BOC); }
374 <S_RMTP>{ecl}           { BEGIN S_RMTS; return(EOC); }
375 <S_RMTP>lifetime        { YYD; return(LIFETIME); }
376 <S_RMTP>time            { YYD; return(LIFETYPE_TIME); }
377 <S_RMTP>byte            { YYD; return(LIFETYPE_BYTE); }
378 <S_RMTP>encryption_algorithm { YYD; yylval.num = algclass_isakmp_enc; return(ALGORITHM_CLASS); }
379 <S_RMTP>authentication_method { YYD; yylval.num = algclass_isakmp_ameth; return(ALGORITHM_CLASS); }
380 <S_RMTP>hash_algorithm  { YYD; yylval.num = algclass_isakmp_hash; return(ALGORITHM_CLASS); }
381 <S_RMTP>dh_group        { YYD; return(DH_GROUP); }
382 <S_RMTP>gss_id          { YYD; return(GSS_ID); }
383 <S_RMTP>gssapi_id       { YYD; return(GSS_ID); } /* for back compatibility */
385         /* GSS ID encoding type (global) */
386 <S_INI>gss_id_enc       { BEGIN S_GSSENC; YYDB; return(GSS_ID_ENC); }
387 <S_GSSENC>latin1        { YYD; yylval.num = LC_GSSENC_LATIN1;
388                                 return(GSS_ID_ENCTYPE); }
389 <S_GSSENC>utf-16le      { YYD; yylval.num = LC_GSSENC_UTF16LE;
390                                 return(GSS_ID_ENCTYPE); }
391 <S_GSSENC>{semi}        { BEGIN S_INI; YYDB; return(EOS); }
393         /* parameter */
394 on              { YYD; yylval.num = TRUE; return(SWITCH); }
395 off             { YYD; yylval.num = FALSE; return(SWITCH); }
397         /* prefix */
398 {slash}{digit}{1,3} {
399                         YYD;
400                         yytext++;
401                         yylval.num = atoi(yytext);
402                         return(PREFIX);
403                 }
405         /* port number */
406 {blcl}{decstring}{elcl} {
407                         char *p = yytext;
408                         YYD;
409                         while (*++p != ']') ;
410                         *p = 0;
411                         yytext++;
412                         yylval.num = atoi(yytext);
413                         return(PORT);
414                 }
416         /* address range */
417 {hyphen}{addrstring} {
418                         YYD;
419                         yytext++;
420                         yylval.val = vmalloc(yyleng + 1);
421                         if (yylval.val == NULL) {
422                                 yyerror("vmalloc failed");
423                                 return -1;
424                         }
425                         memcpy(yylval.val->v, yytext, yylval.val->l);
426                         return(ADDRRANGE);
427                 } 
429         /* upper protocol */
430 esp             { YYD; yylval.num = IPPROTO_ESP; return(UL_PROTO); }
431 ah              { YYD; yylval.num = IPPROTO_AH; return(UL_PROTO); }
432 ipcomp          { YYD; yylval.num = IPPROTO_IPCOMP; return(UL_PROTO); }
433 icmp            { YYD; yylval.num = IPPROTO_ICMP; return(UL_PROTO); }
434 icmp6           { YYD; yylval.num = IPPROTO_ICMPV6; return(UL_PROTO); }
435 tcp             { YYD; yylval.num = IPPROTO_TCP; return(UL_PROTO); }
436 udp             { YYD; yylval.num = IPPROTO_UDP; return(UL_PROTO); }
437 gre             { YYD; yylval.num = IPPROTO_GRE; return(UL_PROTO); }
439         /* algorithm type */
440 des_iv64        { YYD; yylval.num = algtype_des_iv64;   return(ALGORITHMTYPE); }
441 des             { YYD; yylval.num = algtype_des;        return(ALGORITHMTYPE); }
442 3des            { YYD; yylval.num = algtype_3des;       return(ALGORITHMTYPE); }
443 rc5             { YYD; yylval.num = algtype_rc5;        return(ALGORITHMTYPE); }
444 idea            { YYD; yylval.num = algtype_idea;       return(ALGORITHMTYPE); }
445 cast128         { YYD; yylval.num = algtype_cast128;    return(ALGORITHMTYPE); }
446 blowfish        { YYD; yylval.num = algtype_blowfish;   return(ALGORITHMTYPE); }
447 3idea           { YYD; yylval.num = algtype_3idea;      return(ALGORITHMTYPE); }
448 des_iv32        { YYD; yylval.num = algtype_des_iv32;   return(ALGORITHMTYPE); }
449 rc4             { YYD; yylval.num = algtype_rc4;        return(ALGORITHMTYPE); }
450 null_enc        { YYD; yylval.num = algtype_null_enc;   return(ALGORITHMTYPE); }
451 null            { YYD; yylval.num = algtype_null_enc;   return(ALGORITHMTYPE); }
452 aes             { YYD; yylval.num = algtype_aes;        return(ALGORITHMTYPE); }
453 rijndael        { YYD; yylval.num = algtype_aes;        return(ALGORITHMTYPE); }
454 twofish         { YYD; yylval.num = algtype_twofish;    return(ALGORITHMTYPE); }
455 camellia        { YYD; yylval.num = algtype_camellia;   return(ALGORITHMTYPE); }
456 non_auth        { YYD; yylval.num = algtype_non_auth;   return(ALGORITHMTYPE); }
457 hmac_md5        { YYD; yylval.num = algtype_hmac_md5;   return(ALGORITHMTYPE); }
458 hmac_sha1       { YYD; yylval.num = algtype_hmac_sha1;  return(ALGORITHMTYPE); }
459 hmac_sha2_256   { YYD; yylval.num = algtype_hmac_sha2_256;      return(ALGORITHMTYPE); }
460 hmac_sha256     { YYD; yylval.num = algtype_hmac_sha2_256;      return(ALGORITHMTYPE); }
461 hmac_sha2_384   { YYD; yylval.num = algtype_hmac_sha2_384;      return(ALGORITHMTYPE); }
462 hmac_sha384     { YYD; yylval.num = algtype_hmac_sha2_384;      return(ALGORITHMTYPE); }
463 hmac_sha2_512   { YYD; yylval.num = algtype_hmac_sha2_512;      return(ALGORITHMTYPE); }
464 hmac_sha512     { YYD; yylval.num = algtype_hmac_sha2_512;      return(ALGORITHMTYPE); }
465 des_mac         { YYD; yylval.num = algtype_des_mac;    return(ALGORITHMTYPE); }
466 kpdk            { YYD; yylval.num = algtype_kpdk;       return(ALGORITHMTYPE); }
467 md5             { YYD; yylval.num = algtype_md5;        return(ALGORITHMTYPE); }
468 sha1            { YYD; yylval.num = algtype_sha1;       return(ALGORITHMTYPE); }
469 tiger           { YYD; yylval.num = algtype_tiger;      return(ALGORITHMTYPE); }
470 sha2_256        { YYD; yylval.num = algtype_sha2_256;   return(ALGORITHMTYPE); }
471 sha256          { YYD; yylval.num = algtype_sha2_256;   return(ALGORITHMTYPE); }
472 sha2_384        { YYD; yylval.num = algtype_sha2_384;   return(ALGORITHMTYPE); }
473 sha384          { YYD; yylval.num = algtype_sha2_384;   return(ALGORITHMTYPE); }
474 sha2_512        { YYD; yylval.num = algtype_sha2_512;   return(ALGORITHMTYPE); }
475 sha512          { YYD; yylval.num = algtype_sha2_512;   return(ALGORITHMTYPE); }
476 oui             { YYD; yylval.num = algtype_oui;        return(ALGORITHMTYPE); }
477 deflate         { YYD; yylval.num = algtype_deflate;    return(ALGORITHMTYPE); }
478 lzs             { YYD; yylval.num = algtype_lzs;        return(ALGORITHMTYPE); }
479 modp768         { YYD; yylval.num = algtype_modp768;    return(ALGORITHMTYPE); }
480 modp1024        { YYD; yylval.num = algtype_modp1024;   return(ALGORITHMTYPE); }
481 modp1536        { YYD; yylval.num = algtype_modp1536;   return(ALGORITHMTYPE); }
482 ec2n155         { YYD; yylval.num = algtype_ec2n155;    return(ALGORITHMTYPE); }
483 ec2n185         { YYD; yylval.num = algtype_ec2n185;    return(ALGORITHMTYPE); }
484 modp2048        { YYD; yylval.num = algtype_modp2048;   return(ALGORITHMTYPE); }
485 modp3072        { YYD; yylval.num = algtype_modp3072;   return(ALGORITHMTYPE); }
486 modp4096        { YYD; yylval.num = algtype_modp4096;   return(ALGORITHMTYPE); }
487 modp6144        { YYD; yylval.num = algtype_modp6144;   return(ALGORITHMTYPE); }
488 modp8192        { YYD; yylval.num = algtype_modp8192;   return(ALGORITHMTYPE); }
489 pre_shared_key  { YYD; yylval.num = algtype_psk;        return(ALGORITHMTYPE); }
490 rsasig          { YYD; yylval.num = algtype_rsasig;     return(ALGORITHMTYPE); }
491 dsssig          { YYD; yylval.num = algtype_dsssig;     return(ALGORITHMTYPE); }
492 rsaenc          { YYD; yylval.num = algtype_rsaenc;     return(ALGORITHMTYPE); }
493 rsarev          { YYD; yylval.num = algtype_rsarev;     return(ALGORITHMTYPE); }
494 gssapi_krb      { YYD; yylval.num = algtype_gssapikrb;  return(ALGORITHMTYPE); }
495 hybrid_rsa_server {
496 #ifdef ENABLE_HYBRID
497         YYD; yylval.num = algtype_hybrid_rsa_s; return(ALGORITHMTYPE);
498 #else
499         yyerror("racoon not configured with --enable-hybrid");
500 #endif
502 hybrid_dss_server {
503 #ifdef ENABLE_HYBRID
504         YYD; yylval.num = algtype_hybrid_dss_s; return(ALGORITHMTYPE);
505 #else
506         yyerror("racoon not configured with --enable-hybrid");
507 #endif
509 hybrid_rsa_client {
510 #ifdef ENABLE_HYBRID
511         YYD; yylval.num = algtype_hybrid_rsa_c; return(ALGORITHMTYPE);
512 #else
513         yyerror("racoon not configured with --enable-hybrid");
514 #endif
516 hybrid_dss_client {
517 #ifdef ENABLE_HYBRID
518         YYD; yylval.num = algtype_hybrid_dss_c; return(ALGORITHMTYPE);
519 #else
520         yyerror("racoon not configured with --enable-hybrid");
521 #endif
523 xauth_psk_server {
524 #ifdef ENABLE_HYBRID
525         YYD; yylval.num = algtype_xauth_psk_s; return(ALGORITHMTYPE);
526 #else
527         yyerror("racoon not configured with --enable-hybrid");
528 #endif
530 xauth_psk_client {
531 #ifdef ENABLE_HYBRID
532         YYD; yylval.num = algtype_xauth_psk_c; return(ALGORITHMTYPE);
533 #else
534         yyerror("racoon not configured with --enable-hybrid");
535 #endif
537 xauth_rsa_server {
538 #ifdef ENABLE_HYBRID
539         YYD; yylval.num = algtype_xauth_rsa_s; return(ALGORITHMTYPE);
540 #else
541         yyerror("racoon not configured with --enable-hybrid");
542 #endif
544 xauth_rsa_client {
545 #ifdef ENABLE_HYBRID
546         YYD; yylval.num = algtype_xauth_rsa_c; return(ALGORITHMTYPE);
547 #else
548         yyerror("racoon not configured with --enable-hybrid");
549 #endif
553         /* identifier type */
554 user_fqdn       { YYD; yylval.num = IDTYPE_USERFQDN; return(IDENTIFIERTYPE); }
555 fqdn            { YYD; yylval.num = IDTYPE_FQDN; return(IDENTIFIERTYPE); }
556 keyid           { YYD; yylval.num = IDTYPE_KEYID; return(IDENTIFIERTYPE); }
557 address         { YYD; yylval.num = IDTYPE_ADDRESS; return(IDENTIFIERTYPE); }
558 subnet          { YYD; yylval.num = IDTYPE_SUBNET; return(IDENTIFIERTYPE); }
559 asn1dn          { YYD; yylval.num = IDTYPE_ASN1DN; return(IDENTIFIERTYPE); }
561         /* identifier qualifier */
562 tag             { YYD; yylval.num = IDQUAL_TAG;  return(IDENTIFIERQUAL); }
563 file            { YYD; yylval.num = IDQUAL_FILE; return(IDENTIFIERQUAL); }
565         /* units */
566 B|byte|bytes            { YYD; return(UNITTYPE_BYTE); }
567 KB                      { YYD; return(UNITTYPE_KBYTES); }
568 MB                      { YYD; return(UNITTYPE_MBYTES); }
569 TB                      { YYD; return(UNITTYPE_TBYTES); }
570 sec|secs|second|seconds { YYD; return(UNITTYPE_SEC); }
571 min|mins|minute|minutes { YYD; return(UNITTYPE_MIN); }
572 hour|hours              { YYD; return(UNITTYPE_HOUR); }
574         /* boolean */
575 yes             { YYD; yylval.num = TRUE; return(BOOLEAN); }
576 no              { YYD; yylval.num = FALSE; return(BOOLEAN); }
578 {decstring}     {
579                         char *bp;
581                         YYD;
582                         yylval.num = strtol(yytext, &bp, 10);
583                         return(NUMBER);
584                 }
586 {hexstring}     {
587                         char *p;
589                         YYD; 
590                         yylval.val = vmalloc(yyleng + (yyleng & 1) + 1);
591                         if (yylval.val == NULL) {
592                                 yyerror("vmalloc failed");
593                                 return -1;
594                         }
596                         p = yylval.val->v;
597                         *p++ = '0';
598                         *p++ = 'x';
600                         /* fixed string if length is odd. */
601                         if (yyleng & 1)
602                                 *p++ = '0';
603                         memcpy(p, &yytext[2], yyleng - 1);
605                         return(HEXSTRING);
606                 }
608 {quotedstring}  {
609                         char *p = yytext;
611                         YYD;
612                         while (*++p != '"') ;
613                         *p = '\0';
615                         yylval.val = vmalloc(yyleng - 1);
616                         if (yylval.val == NULL) {
617                                 yyerror("vmalloc failed");
618                                 return -1;
619                         }
620                         memcpy(yylval.val->v, &yytext[1], yylval.val->l);
622                         return(QUOTEDSTRING);
623                 }
625 {addrstring}    {
626                         YYD;
628                         yylval.val = vmalloc(yyleng + 1);
629                         if (yylval.val == NULL) {
630                                 yyerror("vmalloc failed");
631                                 return -1;
632                         }
633                         memcpy(yylval.val->v, yytext, yylval.val->l);
635                         return(ADDRSTRING);
636                 }
638 <<EOF>>         {
639                         yy_delete_buffer(YY_CURRENT_BUFFER);
640                         incstackp--;
641     nextfile:
642                         if (incstack[incstackp].matchon <
643                             incstack[incstackp].matches.gl_pathc) {
644                                 char* filepath = incstack[incstackp].matches.gl_pathv[incstack[incstackp].matchon];
645                                 incstack[incstackp].matchon++;
646                                 incstackp++;
647                                 if (yycf_set_buffer(filepath) != 0) {
648                                         incstackp--;
649                                         goto nextfile;
650                                 }
651                                 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
652                                 BEGIN(S_INI);
653                         } else {
654                                 globfree(&incstack[incstackp].matches);
655                                 if (incstackp == 0)
656                                         yyterminate();
657                                 else
658                                         yy_switch_to_buffer(incstack[incstackp].prevstate);
659                         }
660                 }
662         /* ... */
663 {ws}            { ; }
664 {nl}            { incstack[incstackp].lineno++; }
665 {comment}       { YYD; }
666 {semi}          { return(EOS); }
667 .               { yymore(); }
671 void
672 yyerror(char *s, ...)
674         char fmt[512];
676         va_list ap;
677 #ifdef HAVE_STDARG_H
678         va_start(ap, s);
679 #else
680         va_start(ap);
681 #endif
682         snprintf(fmt, sizeof(fmt), "%s:%d: \"%s\" %s\n",
683                 incstack[incstackp].path, incstack[incstackp].lineno,
684                 yytext, s);
685         plogv(LLV_ERROR, LOCATION, NULL, fmt, ap);
686         va_end(ap);
688         yyerrorcount++;
691 void
692 yywarn(char *s, ...)
694         char fmt[512];
696         va_list ap;
697 #ifdef HAVE_STDARG_H
698         va_start(ap, s);
699 #else
700         va_start(ap);
701 #endif
702         snprintf(fmt, sizeof(fmt), "%s:%d: \"%s\" %s\n",
703                 incstack[incstackp].path, incstack[incstackp].lineno,
704                 yytext, s);
705         plogv(LLV_WARNING, LOCATION, NULL, fmt, ap);
706         va_end(ap);
710 yycf_switch_buffer(path)
711         char *path;
713         char *filepath = NULL;
715         /* got the include file name */
716         if (incstackp >= MAX_INCLUDE_DEPTH) {
717                 plog(LLV_ERROR, LOCATION, NULL,
718                         "Includes nested too deeply");
719                 return -1;
720         }
722         if (glob(path, GLOB_TILDE, NULL, &incstack[incstackp].matches) != 0 ||
723             incstack[incstackp].matches.gl_pathc == 0) {
724                 plog(LLV_ERROR, LOCATION, NULL,
725                         "glob found no matches for path \"%s\"\n", path);
726                 return -1;
727         }
728         incstack[incstackp].matchon = 0;
729         incstack[incstackp].prevstate = YY_CURRENT_BUFFER;
731     nextmatch:
732         if (incstack[incstackp].matchon >= incstack[incstackp].matches.gl_pathc)
733                 return -1;
734         filepath =
735             incstack[incstackp].matches.gl_pathv[incstack[incstackp].matchon];
736         incstack[incstackp].matchon++;
737         incstackp++;
739         if (yycf_set_buffer(filepath) != 0) {
740               incstackp--;
741               goto nextmatch;
742         }
744         yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
746         BEGIN(S_INI);
748         return 0;
752 yycf_set_buffer(path)
753         char *path;
755         yyin = fopen(path, "r");
756         if (yyin == NULL) {
757                 fprintf(stderr, "failed to open file %s (%s)\n",
758                         path, strerror(errno));
759                 plog(LLV_ERROR, LOCATION, NULL,
760                         "failed to open file %s (%s)\n",
761                         path, strerror(errno));
762                 return -1;
763         }
765         /* initialize */
766         incstack[incstackp].fp = yyin;
767         if (incstack[incstackp].path != NULL)
768                 racoon_free(incstack[incstackp].path);
769         incstack[incstackp].path = racoon_strdup(path);
770         STRDUP_FATAL(incstack[incstackp].path);
771         incstack[incstackp].lineno = 1;
772         plog(LLV_DEBUG, LOCATION, NULL,
773                 "reading config file %s\n", path);
775         return 0;
778 void
779 yycf_init_buffer()
781         int i;
783         for (i = 0; i < MAX_INCLUDE_DEPTH; i++)
784                 memset(&incstack[i], 0, sizeof(incstack[i]));
785         incstackp = 0;
788 void
789 yycf_clean_buffer()
791         int i;
793         for (i = 0; i < MAX_INCLUDE_DEPTH; i++) {
794                 if (incstack[i].path != NULL) {
795                         fclose(incstack[i].fp);
796                         racoon_free(incstack[i].path);
797                         incstack[i].path = NULL;
798                 }
799         }