]>
Commit | Line | Data |
---|---|---|
d1e348cf A |
1 | /* $NetBSD: cfparse.y,v 1.18.4.3 2007/08/01 11:52:19 vanhu Exp $ */ |
2 | ||
3 | /* Id: cfparse.y,v 1.66 2006/08/22 18:17:17 manubsd Exp */ | |
52b7d2ce A |
4 | |
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 | */ | |
34 | ||
35 | #include "config.h" | |
36 | ||
37 | #include <sys/types.h> | |
38 | #include <sys/param.h> | |
39 | #include <sys/queue.h> | |
40 | #include <sys/socket.h> | |
41 | ||
42 | #include <netinet/in.h> | |
43 | #ifdef HAVE_NETINET6_IPSEC | |
44 | # include <netinet6/ipsec.h> | |
45 | #else | |
46 | # include <netinet/ipsec.h> | |
47 | #endif | |
48 | ||
49 | #ifdef ENABLE_HYBRID | |
50 | #include <arpa/inet.h> | |
51 | #endif | |
52 | ||
53 | #include <stdlib.h> | |
54 | #include <stdio.h> | |
55 | #include <string.h> | |
56 | #include <errno.h> | |
57 | #include <netdb.h> | |
58 | #include <pwd.h> | |
59 | #include <grp.h> | |
d1e348cf | 60 | #include <signal.h> |
52b7d2ce A |
61 | |
62 | #include "var.h" | |
63 | #include "misc.h" | |
64 | #include "vmbuf.h" | |
65 | #include "plog.h" | |
66 | #include "sockmisc.h" | |
67 | #include "str2val.h" | |
68 | #include "genlist.h" | |
69 | #include "debug.h" | |
70 | ||
52b7d2ce A |
71 | #include "cfparse_proto.h" |
72 | #include "cftoken_proto.h" | |
73 | #include "algorithm.h" | |
74 | #include "localconf.h" | |
75 | #include "policy.h" | |
76 | #include "sainfo.h" | |
77 | #include "oakley.h" | |
78 | #include "pfkey.h" | |
79 | #include "remoteconf.h" | |
80 | #include "grabmyaddr.h" | |
81 | #include "isakmp_var.h" | |
82 | #include "handler.h" | |
83 | #include "isakmp.h" | |
d1e348cf A |
84 | #include "nattraversal.h" |
85 | #include "isakmp_frag.h" | |
85f41bec | 86 | #include "session.h" |
52b7d2ce | 87 | #ifdef ENABLE_HYBRID |
d1e348cf A |
88 | #include "resolv.h" |
89 | #include "isakmp_unity.h" | |
52b7d2ce A |
90 | #include "isakmp_xauth.h" |
91 | #include "isakmp_cfg.h" | |
92 | #endif | |
93 | #include "ipsec_doi.h" | |
94 | #include "strnames.h" | |
95 | #include "gcmalloc.h" | |
52b7d2ce | 96 | #include "vendorid.h" |
d1e348cf A |
97 | #include "ipsecConfigTracer.h" |
98 | #include "ipsecMessageTracer.h" | |
52b7d2ce | 99 | |
52b7d2ce A |
100 | static int num2dhgroup[] = { |
101 | 0, | |
102 | OAKLEY_ATTR_GRP_DESC_MODP768, | |
103 | OAKLEY_ATTR_GRP_DESC_MODP1024, | |
104 | OAKLEY_ATTR_GRP_DESC_EC2N155, | |
105 | OAKLEY_ATTR_GRP_DESC_EC2N185, | |
106 | OAKLEY_ATTR_GRP_DESC_MODP1536, | |
107 | 0, | |
108 | 0, | |
109 | 0, | |
110 | 0, | |
111 | 0, | |
112 | 0, | |
113 | 0, | |
114 | 0, | |
115 | OAKLEY_ATTR_GRP_DESC_MODP2048, | |
116 | OAKLEY_ATTR_GRP_DESC_MODP3072, | |
117 | OAKLEY_ATTR_GRP_DESC_MODP4096, | |
118 | OAKLEY_ATTR_GRP_DESC_MODP6144, | |
119 | OAKLEY_ATTR_GRP_DESC_MODP8192 | |
120 | }; | |
121 | ||
85f41bec A |
122 | struct remote_index_val { |
123 | int prefix; | |
124 | struct sockaddr_storage *addr; | |
125 | }; | |
126 | ||
52b7d2ce A |
127 | static struct remoteconf *cur_rmconf; |
128 | static int tmpalgtype[MAXALGCLASS]; | |
129 | static struct sainfo *cur_sainfo; | |
130 | static int cur_algclass; | |
131 | ||
65c25746 A |
132 | static struct proposalspec *newprspec (void); |
133 | static void insprspec (struct proposalspec *, struct proposalspec **); | |
134 | static struct secprotospec *newspspec (void); | |
135 | static void insspspec (struct secprotospec *, struct proposalspec **); | |
52b7d2ce | 136 | |
65c25746 A |
137 | static int set_isakmp_proposal (struct remoteconf *, struct proposalspec *); |
138 | static void clean_tmpalgtype (void); | |
139 | static int expand_isakmpspec (int, int, int *, | |
140 | int, int, time_t, int, int, int, char *, struct remoteconf *); | |
141 | static int listen_addr (struct sockaddr_storage *addr, int udp_encap); | |
52b7d2ce A |
142 | |
143 | void freeetypes (struct etypes **etypes); | |
144 | ||
145 | #if 0 | |
65c25746 | 146 | static int fix_lifebyte (u_long); |
52b7d2ce A |
147 | #endif |
148 | %} | |
149 | ||
150 | %union { | |
151 | unsigned long num; | |
152 | vchar_t *val; | |
153 | struct remoteconf *rmconf; | |
85f41bec | 154 | struct sockaddr_storage *saddr; |
52b7d2ce | 155 | struct sainfoalg *alg; |
85f41bec | 156 | struct remote_index_val *rmidx; |
52b7d2ce A |
157 | } |
158 | ||
52b7d2ce A |
159 | /* path */ |
160 | %token PATH PATHTYPE | |
161 | /* include */ | |
162 | %token INCLUDE | |
163 | /* self information */ | |
164 | %token IDENTIFIER VENDORID | |
165 | /* logging */ | |
166 | %token LOGGING LOGLEV | |
167 | /* padding */ | |
168 | %token PADDING PAD_RANDOMIZE PAD_RANDOMIZELEN PAD_MAXLEN PAD_STRICT PAD_EXCLTAIL | |
169 | /* listen */ | |
170 | %token LISTEN X_ISAKMP X_ISAKMP_NATT X_ADMIN STRICT_ADDRESS ADMINSOCK DISABLED | |
171 | /* modecfg */ | |
d1e348cf A |
172 | %token MODECFG CFG_NET4 CFG_MASK4 CFG_DNS4 CFG_NBNS4 CFG_DEFAULT_DOMAIN |
173 | %token CFG_AUTH_SOURCE CFG_AUTH_GROUPS CFG_SYSTEM CFG_RADIUS CFG_PAM CFG_LDAP CFG_LOCAL CFG_NONE | |
174 | %token CFG_GROUP_SOURCE CFG_ACCOUNTING CFG_CONF_SOURCE CFG_MOTD CFG_POOL_SIZE CFG_AUTH_THROTTLE | |
175 | %token CFG_SPLIT_NETWORK CFG_SPLIT_LOCAL CFG_SPLIT_INCLUDE CFG_SPLIT_DNS | |
52b7d2ce A |
176 | %token CFG_PFS_GROUP CFG_SAVE_PASSWD |
177 | /* timer */ | |
178 | %token RETRY RETRY_COUNTER RETRY_INTERVAL RETRY_PERSEND | |
179 | %token RETRY_PHASE1 RETRY_PHASE2 NATT_KA AUTO_EXIT_DELAY | |
180 | /* algorithm */ | |
181 | %token ALGORITHM_CLASS ALGORITHMTYPE STRENGTHTYPE | |
182 | /* sainfo */ | |
65c25746 | 183 | %token SAINFO FROM GROUP |
52b7d2ce A |
184 | /* remote */ |
185 | %token REMOTE ANONYMOUS INHERIT | |
186 | %token EXCHANGE_MODE EXCHANGETYPE DOI DOITYPE SITUATION SITUATIONTYPE | |
187 | %token CERTIFICATE_TYPE CERTTYPE PEERS_CERTFILE CA_TYPE | |
188 | %token VERIFY_CERT SEND_CERT SEND_CR | |
d1e348cf A |
189 | %token IDENTIFIERTYPE IDENTIFIERQUAL MY_IDENTIFIER |
190 | %token PEERS_IDENTIFIER VERIFY_IDENTIFIER | |
d9c572c0 | 191 | %token LOCAL_ADDRESS |
52b7d2ce A |
192 | %token SHARED_SECRET SECRETTYPE |
193 | %token OPEN_DIR_AUTH_GROUP IN_KEYCHAIN | |
194 | %token CERTIFICATE_VERIFICATION VERIFICATION_MODULE VERIFICATION_OPTION | |
195 | %token DNSSEC CERT_X509 CERT_PLAINRSA | |
196 | %token NONCE_SIZE DH_GROUP KEEPALIVE PASSIVE INITIAL_CONTACT | |
d1e348cf | 197 | %token NAT_TRAVERSAL REMOTE_FORCE_LEVEL NAT_TRAVERSAL_LEVEL NAT_TRAVERSAL_MULTI_USER NAT_TRAVERSAL_KEEPALIVE |
52b7d2ce | 198 | %token PROPOSAL_CHECK PROPOSAL_CHECK_LEVEL |
d1e348cf | 199 | %token GENERATE_POLICY GENERATE_LEVEL SUPPORT_PROXY |
52b7d2ce A |
200 | %token PROPOSAL |
201 | %token EXEC_PATH EXEC_COMMAND EXEC_SUCCESS EXEC_FAILURE | |
202 | %token GSS_ID GSS_ID_ENC GSS_ID_ENCTYPE | |
203 | %token COMPLEX_BUNDLE | |
d1e348cf A |
204 | %token DPD DPD_DELAY DPD_RETRY DPD_MAXFAIL DPD_ALGORITHM |
205 | %token DISCONNECT_ON_IDLE IDLE_TIMEOUT IDLE_DIRECTION | |
206 | %token XAUTH_LOGIN WEAK_PHASE1_CHECK | |
52b7d2ce A |
207 | |
208 | %token PREFIX PORT PORTANY UL_PROTO ANY IKE_FRAG ESP_FRAG MODE_CFG | |
d1e348cf | 209 | %token PFS_GROUP LIFETIME LIFETYPE_TIME LIFETYPE_BYTE STRENGTH REMOTEID |
52b7d2ce | 210 | |
52b7d2ce | 211 | %token NUMBER SWITCH BOOLEAN |
d1e348cf | 212 | %token HEXSTRING QUOTEDSTRING ADDRSTRING ADDRRANGE |
52b7d2ce A |
213 | %token UNITTYPE_BYTE UNITTYPE_KBYTES UNITTYPE_MBYTES UNITTYPE_TBYTES |
214 | %token UNITTYPE_SEC UNITTYPE_MIN UNITTYPE_HOUR | |
215 | %token EOS BOC EOC COMMA | |
d1e348cf | 216 | %token DPD_ALGO_TYPE_DEFAULT DPD_ALGO_TYPE_INBOUND DPD_ALGO_TYPE_BLACKHOLE |
65c25746 | 217 | %token IDLE_DIRECTION_IN IDLE_DIRECTION_OUT IDLE_DIRECTION_ANY IKE_VERSION |
52b7d2ce A |
218 | |
219 | %type <num> NUMBER BOOLEAN SWITCH keylength | |
d1e348cf | 220 | %type <num> PATHTYPE IDENTIFIERTYPE IDENTIFIERQUAL LOGLEV GSS_ID_ENCTYPE |
52b7d2ce A |
221 | %type <num> SECRETTYPE |
222 | %type <num> ALGORITHM_CLASS dh_group_num | |
223 | %type <num> ALGORITHMTYPE STRENGTHTYPE | |
224 | %type <num> PREFIX prefix PORT port ike_port | |
225 | %type <num> ul_proto UL_PROTO | |
d9c572c0 | 226 | %type <num> EXCHANGETYPE DOITYPE SITUATIONTYPE |
d1e348cf | 227 | %type <num> CERTTYPE CERT_X509 CERT_PLAINRSA PROPOSAL_CHECK_LEVEL NAT_TRAVERSAL_LEVEL GENERATE_LEVEL |
52b7d2ce A |
228 | %type <num> VERIFICATION_MODULE VERIFICATION_OPTION |
229 | %type <num> unittype_time unittype_byte | |
d1e348cf | 230 | %type <val> QUOTEDSTRING HEXSTRING ADDRSTRING ADDRRANGE sainfo_id |
52b7d2ce | 231 | %type <val> identifierstring |
85f41bec | 232 | %type <saddr> ike_addrinfo_port |
52b7d2ce | 233 | %type <alg> algorithm |
d1e348cf A |
234 | %type <num> dpd_algo_type |
235 | %type <num> idle_dir_type | |
85f41bec | 236 | %type <rmidx> remote_index ike_addrinfo_prefix_port |
52b7d2ce A |
237 | |
238 | %% | |
239 | ||
240 | statements | |
241 | : /* nothing */ | |
242 | | statements statement | |
243 | ; | |
244 | statement | |
65c25746 | 245 | : path_statement |
52b7d2ce | 246 | | include_statement |
52b7d2ce A |
247 | | identifier_statement |
248 | | logging_statement | |
249 | | padding_statement | |
250 | | listen_statement | |
251 | | modecfg_statement | |
252 | | timer_statement | |
253 | | sainfo_statement | |
254 | | remote_statement | |
255 | | special_statement | |
256 | ; | |
257 | ||
52b7d2ce A |
258 | /* path */ |
259 | path_statement | |
260 | : PATH PATHTYPE QUOTEDSTRING | |
261 | { | |
262 | if ($2 >= LC_PATHTYPE_MAX) { | |
85f41bec | 263 | racoon_yyerror("invalid path type %d", $2); |
52b7d2ce A |
264 | return -1; |
265 | } | |
266 | ||
267 | /* free old pathinfo */ | |
268 | if (lcconf->pathinfo[$2]) | |
269 | racoon_free(lcconf->pathinfo[$2]); | |
270 | ||
271 | /* set new pathinfo */ | |
d1e348cf A |
272 | lcconf->pathinfo[$2] = racoon_strdup($3->v); |
273 | STRDUP_FATAL(lcconf->pathinfo[$2]); | |
52b7d2ce A |
274 | vfree($3); |
275 | } | |
276 | EOS | |
277 | ; | |
278 | ||
279 | /* special */ | |
280 | special_statement | |
281 | : COMPLEX_BUNDLE SWITCH { lcconf->complex_bundle = $2; } EOS | |
282 | ; | |
283 | ||
284 | /* include */ | |
285 | include_statement | |
286 | : INCLUDE QUOTEDSTRING EOS | |
287 | { | |
288 | char path[MAXPATHLEN]; | |
289 | ||
290 | getpathname(path, sizeof(path), | |
291 | LC_PATHTYPE_INCLUDE, $2->v); | |
292 | vfree($2); | |
293 | if (yycf_switch_buffer(path) != 0) | |
294 | return -1; | |
295 | } | |
296 | ; | |
297 | ||
d1e348cf | 298 | /* self information */ |
52b7d2ce A |
299 | identifier_statement |
300 | : IDENTIFIER identifier_stmt | |
301 | ; | |
302 | identifier_stmt | |
303 | : VENDORID | |
304 | { | |
305 | /*XXX to be deleted */ | |
306 | } | |
307 | QUOTEDSTRING EOS | |
308 | | IDENTIFIERTYPE QUOTEDSTRING | |
309 | { | |
310 | /*XXX to be deleted */ | |
311 | $2->l--; /* nuke '\0' */ | |
312 | lcconf->ident[$1] = $2; | |
313 | if (lcconf->ident[$1] == NULL) { | |
85f41bec | 314 | racoon_yyerror("failed to set my ident: %s", |
52b7d2ce A |
315 | strerror(errno)); |
316 | return -1; | |
317 | } | |
318 | } | |
319 | EOS | |
320 | ; | |
321 | ||
322 | /* logging */ | |
323 | logging_statement | |
324 | : LOGGING log_level EOS | |
325 | ; | |
326 | log_level | |
65c25746 | 327 | : QUOTEDSTRING |
52b7d2ce A |
328 | { |
329 | /* | |
330 | * XXX ignore it because this specification | |
331 | * will be obsoleted. | |
332 | */ | |
65c25746 | 333 | plogsetlevelquotedstr($1->v); |
52b7d2ce A |
334 | vfree($1); |
335 | } | |
336 | | LOGLEV | |
337 | { | |
65c25746 | 338 | plogsetlevel($1); |
52b7d2ce A |
339 | } |
340 | ; | |
341 | ||
342 | /* padding */ | |
343 | padding_statement | |
344 | : PADDING BOC padding_stmts EOC | |
345 | ; | |
346 | padding_stmts | |
347 | : /* nothing */ | |
348 | | padding_stmts padding_stmt | |
349 | ; | |
350 | padding_stmt | |
351 | : PAD_RANDOMIZE SWITCH { lcconf->pad_random = $2; } EOS | |
352 | | PAD_RANDOMIZELEN SWITCH { lcconf->pad_randomlen = $2; } EOS | |
353 | | PAD_MAXLEN NUMBER { lcconf->pad_maxsize = $2; } EOS | |
354 | | PAD_STRICT SWITCH { lcconf->pad_strict = $2; } EOS | |
355 | | PAD_EXCLTAIL SWITCH { lcconf->pad_excltail = $2; } EOS | |
356 | ; | |
357 | ||
358 | /* listen */ | |
359 | listen_statement | |
360 | : LISTEN BOC listen_stmts EOC | |
361 | ; | |
362 | listen_stmts | |
363 | : /* nothing */ | |
364 | | listen_stmts listen_stmt | |
365 | ; | |
366 | listen_stmt | |
367 | : X_ISAKMP ike_addrinfo_port | |
368 | { | |
369 | listen_addr ($2, 0); | |
370 | } | |
371 | EOS | |
372 | | X_ISAKMP_NATT ike_addrinfo_port | |
373 | { | |
374 | #ifdef ENABLE_NATT | |
375 | listen_addr ($2, 1); | |
376 | #else | |
85f41bec | 377 | racoon_yyerror("NAT-T support not compiled in."); |
52b7d2ce A |
378 | #endif |
379 | } | |
380 | EOS | |
381 | | X_ADMIN | |
382 | { | |
85f41bec | 383 | racoon_yyerror("admin directive is obsoleted."); |
52b7d2ce A |
384 | } |
385 | PORT EOS | |
386 | | ADMINSOCK QUOTEDSTRING QUOTEDSTRING QUOTEDSTRING NUMBER | |
387 | { | |
85f41bec | 388 | racoon_yywarn("admin port support not compiled in"); |
52b7d2ce A |
389 | } |
390 | EOS | |
391 | | ADMINSOCK QUOTEDSTRING | |
392 | { | |
85f41bec | 393 | racoon_yywarn("admin port support not compiled in"); |
52b7d2ce A |
394 | } |
395 | EOS | |
396 | | ADMINSOCK DISABLED | |
397 | { | |
85f41bec | 398 | racoon_yywarn("admin port support not compiled in"); |
52b7d2ce A |
399 | } |
400 | EOS | |
401 | | STRICT_ADDRESS { lcconf->strict_address = TRUE; } EOS | |
402 | ; | |
403 | ike_addrinfo_port | |
404 | : ADDRSTRING ike_port | |
405 | { | |
406 | char portbuf[10]; | |
407 | ||
408 | snprintf(portbuf, sizeof(portbuf), "%ld", $2); | |
409 | $$ = str2saddr($1->v, portbuf); | |
410 | vfree($1); | |
411 | if (!$$) | |
412 | return -1; | |
413 | } | |
414 | ; | |
85f41bec A |
415 | ike_addrinfo_prefix_port |
416 | : ADDRSTRING prefix ike_port | |
417 | { | |
418 | char portbuf[10]; | |
419 | struct remote_index_val *new; | |
420 | ||
421 | new = racoon_calloc(1, sizeof(*new)); | |
422 | if (new == NULL) { | |
423 | racoon_yyerror("failed to allocate remote index struct"); | |
424 | vfree($1); | |
425 | return -1; | |
426 | } | |
427 | snprintf(portbuf, sizeof(portbuf), "%ld", $3); | |
428 | new->addr = str2saddr($1->v, portbuf); | |
429 | vfree($1); | |
430 | if (!new->addr) { | |
431 | racoon_yyerror("failed to allocate sockaddr storage"); | |
432 | return -1; | |
433 | } | |
434 | new->prefix = $2; | |
435 | $$ = new; | |
436 | } | |
437 | ; | |
52b7d2ce A |
438 | ike_port |
439 | : /* nothing */ { $$ = PORT_ISAKMP; } | |
440 | | PORT { $$ = $1; } | |
441 | ; | |
442 | /* modecfg */ | |
443 | modecfg_statement | |
444 | : MODECFG BOC modecfg_stmts EOC | |
445 | ; | |
446 | modecfg_stmts | |
447 | : /* nothing */ | |
448 | | modecfg_stmts modecfg_stmt | |
449 | ; | |
450 | modecfg_stmt | |
451 | : CFG_NET4 ADDRSTRING | |
452 | { | |
453 | #ifdef ENABLE_HYBRID | |
d1e348cf A |
454 | if (inet_pton(AF_INET, $2->v, |
455 | &isakmp_cfg_config.network4) != 1) | |
85f41bec | 456 | racoon_yyerror("bad IPv4 network address."); |
d1e348cf | 457 | vfree($2); |
52b7d2ce | 458 | #else |
85f41bec | 459 | racoon_yyerror("racoon not configured with --enable-hybrid"); |
52b7d2ce A |
460 | #endif |
461 | } | |
462 | EOS | |
463 | | CFG_MASK4 ADDRSTRING | |
464 | { | |
465 | #ifdef ENABLE_HYBRID | |
466 | if (inet_pton(AF_INET, $2->v, | |
467 | &isakmp_cfg_config.netmask4) != 1) | |
85f41bec | 468 | racoon_yyerror("bad IPv4 netmask address."); |
d1e348cf | 469 | vfree($2); |
52b7d2ce | 470 | #else |
85f41bec | 471 | racoon_yyerror("racoon not configured with --enable-hybrid"); |
52b7d2ce A |
472 | #endif |
473 | } | |
474 | EOS | |
d1e348cf A |
475 | | CFG_DNS4 addrdnslist |
476 | EOS | |
477 | | CFG_NBNS4 addrwinslist | |
478 | EOS | |
479 | | CFG_SPLIT_NETWORK CFG_SPLIT_LOCAL splitnetlist | |
52b7d2ce A |
480 | { |
481 | #ifdef ENABLE_HYBRID | |
d1e348cf | 482 | isakmp_cfg_config.splitnet_type = UNITY_LOCAL_LAN; |
52b7d2ce | 483 | #else |
85f41bec | 484 | racoon_yyerror("racoon not configured with --enable-hybrid"); |
52b7d2ce A |
485 | #endif |
486 | } | |
487 | EOS | |
d1e348cf | 488 | | CFG_SPLIT_NETWORK CFG_SPLIT_INCLUDE splitnetlist |
52b7d2ce A |
489 | { |
490 | #ifdef ENABLE_HYBRID | |
d1e348cf A |
491 | isakmp_cfg_config.splitnet_type = UNITY_SPLIT_INCLUDE; |
492 | #else | |
85f41bec | 493 | racoon_yyerror("racoon not configured with --enable-hybrid"); |
d1e348cf A |
494 | #endif |
495 | } | |
496 | EOS | |
497 | | CFG_SPLIT_DNS splitdnslist | |
498 | { | |
499 | #ifndef ENABLE_HYBRID | |
85f41bec | 500 | racoon_yyerror("racoon not configured with --enable-hybrid"); |
d1e348cf A |
501 | #endif |
502 | } | |
503 | EOS | |
504 | | CFG_DEFAULT_DOMAIN QUOTEDSTRING | |
505 | { | |
506 | #ifdef ENABLE_HYBRID | |
507 | strlcpy(&isakmp_cfg_config.default_domain[0], | |
508 | $2->v, sizeof(isakmp_cfg_config.default_domain)); | |
509 | vfree($2); | |
52b7d2ce | 510 | #else |
85f41bec | 511 | racoon_yyerror("racoon not configured with --enable-hybrid"); |
52b7d2ce A |
512 | #endif |
513 | } | |
514 | EOS | |
515 | | CFG_AUTH_SOURCE CFG_SYSTEM | |
516 | { | |
517 | #ifdef ENABLE_HYBRID | |
518 | isakmp_cfg_config.authsource = ISAKMP_CFG_AUTH_SYSTEM; | |
519 | #else | |
85f41bec | 520 | racoon_yyerror("racoon not configured with --enable-hybrid"); |
52b7d2ce A |
521 | #endif |
522 | } | |
523 | EOS | |
524 | | CFG_AUTH_SOURCE CFG_RADIUS | |
525 | { | |
526 | #ifdef ENABLE_HYBRID | |
85f41bec | 527 | racoon_yyerror("racoon not configured with --with-libradius"); |
52b7d2ce | 528 | #else /* ENABLE_HYBRID */ |
85f41bec | 529 | racoon_yyerror("racoon not configured with --enable-hybrid"); |
52b7d2ce A |
530 | #endif /* ENABLE_HYBRID */ |
531 | } | |
532 | EOS | |
533 | | CFG_AUTH_SOURCE CFG_PAM | |
534 | { | |
535 | #ifdef ENABLE_HYBRID | |
85f41bec | 536 | racoon_yyerror("racoon not configured with --with-libpam"); |
d1e348cf | 537 | #else /* ENABLE_HYBRID */ |
85f41bec | 538 | racoon_yyerror("racoon not configured with --enable-hybrid"); |
d1e348cf A |
539 | #endif /* ENABLE_HYBRID */ |
540 | } | |
541 | EOS | |
542 | | CFG_AUTH_SOURCE CFG_LDAP | |
543 | { | |
544 | #ifdef ENABLE_HYBRID | |
85f41bec | 545 | racoon_yyerror("racoon not configured with --with-libldap"); |
d1e348cf | 546 | #else /* ENABLE_HYBRID */ |
85f41bec | 547 | racoon_yyerror("racoon not configured with --enable-hybrid"); |
d1e348cf A |
548 | #endif /* ENABLE_HYBRID */ |
549 | } | |
550 | EOS | |
551 | | CFG_AUTH_GROUPS authgrouplist | |
552 | { | |
553 | #ifndef ENABLE_HYBRID | |
85f41bec | 554 | racoon_yyerror("racoon not configured with --enable-hybrid"); |
d1e348cf A |
555 | #endif |
556 | } | |
557 | EOS | |
558 | | CFG_GROUP_SOURCE CFG_SYSTEM | |
559 | { | |
560 | #ifdef ENABLE_HYBRID | |
561 | isakmp_cfg_config.groupsource = ISAKMP_CFG_GROUP_SYSTEM; | |
562 | #else | |
85f41bec | 563 | racoon_yyerror("racoon not configured with --enable-hybrid"); |
d1e348cf A |
564 | #endif |
565 | } | |
566 | EOS | |
567 | | CFG_GROUP_SOURCE CFG_LDAP | |
568 | { | |
569 | #ifdef ENABLE_HYBRID | |
85f41bec | 570 | racoon_yyerror("racoon not configured with --with-libldap"); |
52b7d2ce | 571 | #else /* ENABLE_HYBRID */ |
85f41bec | 572 | racoon_yyerror("racoon not configured with --enable-hybrid"); |
52b7d2ce A |
573 | #endif /* ENABLE_HYBRID */ |
574 | } | |
575 | EOS | |
576 | | CFG_ACCOUNTING CFG_NONE | |
577 | { | |
578 | #ifdef ENABLE_HYBRID | |
579 | isakmp_cfg_config.accounting = ISAKMP_CFG_ACCT_NONE; | |
580 | #else | |
85f41bec | 581 | racoon_yyerror("racoon not configured with --enable-hybrid"); |
d1e348cf A |
582 | #endif |
583 | } | |
584 | EOS | |
585 | | CFG_ACCOUNTING CFG_SYSTEM | |
586 | { | |
587 | #ifdef ENABLE_HYBRID | |
588 | isakmp_cfg_config.accounting = ISAKMP_CFG_ACCT_SYSTEM; | |
589 | #else | |
85f41bec | 590 | racoon_yyerror("racoon not configured with --enable-hybrid"); |
52b7d2ce A |
591 | #endif |
592 | } | |
593 | EOS | |
594 | | CFG_ACCOUNTING CFG_RADIUS | |
595 | { | |
596 | #ifdef ENABLE_HYBRID | |
85f41bec | 597 | racoon_yyerror("racoon not configured with --with-libradius"); |
52b7d2ce | 598 | #else /* ENABLE_HYBRID */ |
85f41bec | 599 | racoon_yyerror("racoon not configured with --enable-hybrid"); |
52b7d2ce A |
600 | #endif /* ENABLE_HYBRID */ |
601 | } | |
602 | EOS | |
603 | | CFG_ACCOUNTING CFG_PAM | |
604 | { | |
605 | #ifdef ENABLE_HYBRID | |
85f41bec | 606 | racoon_yyerror("racoon not configured with --with-libpam"); |
52b7d2ce | 607 | #else /* ENABLE_HYBRID */ |
85f41bec | 608 | racoon_yyerror("racoon not configured with --enable-hybrid"); |
52b7d2ce A |
609 | #endif /* ENABLE_HYBRID */ |
610 | } | |
611 | EOS | |
612 | | CFG_POOL_SIZE NUMBER | |
613 | { | |
614 | #ifdef ENABLE_HYBRID | |
d1e348cf | 615 | if (isakmp_cfg_resize_pool($2) != 0) |
85f41bec | 616 | racoon_yyerror("cannot allocate memory for pool"); |
52b7d2ce | 617 | #else /* ENABLE_HYBRID */ |
85f41bec | 618 | racoon_yyerror("racoon not configured with --enable-hybrid"); |
52b7d2ce A |
619 | #endif /* ENABLE_HYBRID */ |
620 | } | |
621 | EOS | |
622 | | CFG_PFS_GROUP NUMBER | |
623 | { | |
624 | #ifdef ENABLE_HYBRID | |
625 | isakmp_cfg_config.pfs_group = $2; | |
65c25746 A |
626 | switch (isakmp_cfg_config.pfs_group) |
627 | { | |
628 | case OAKLEY_ATTR_GRP_DESC_MODP768: | |
629 | case OAKLEY_ATTR_GRP_DESC_MODP1024: | |
630 | case OAKLEY_ATTR_GRP_DESC_MODP1536: | |
631 | case OAKLEY_ATTR_GRP_DESC_MODP2048: | |
632 | case OAKLEY_ATTR_GRP_DESC_MODP3072: | |
633 | case OAKLEY_ATTR_GRP_DESC_MODP4096: | |
634 | case OAKLEY_ATTR_GRP_DESC_MODP6144: | |
635 | case OAKLEY_ATTR_GRP_DESC_MODP8192: | |
636 | break; | |
637 | default: | |
638 | racoon_yyerror("Invalid PFS group specified"); | |
639 | return -1; | |
640 | break; | |
641 | } | |
52b7d2ce | 642 | #else /* ENABLE_HYBRID */ |
85f41bec | 643 | racoon_yyerror("racoon not configured with --enable-hybrid"); |
52b7d2ce A |
644 | #endif /* ENABLE_HYBRID */ |
645 | } | |
646 | EOS | |
647 | | CFG_SAVE_PASSWD SWITCH | |
648 | { | |
649 | #ifdef ENABLE_HYBRID | |
650 | isakmp_cfg_config.save_passwd = $2; | |
651 | #else /* ENABLE_HYBRID */ | |
85f41bec | 652 | racoon_yyerror("racoon not configured with --enable-hybrid"); |
52b7d2ce A |
653 | #endif /* ENABLE_HYBRID */ |
654 | } | |
655 | EOS | |
656 | | CFG_AUTH_THROTTLE NUMBER | |
657 | { | |
658 | #ifdef ENABLE_HYBRID | |
659 | isakmp_cfg_config.auth_throttle = $2; | |
660 | #else /* ENABLE_HYBRID */ | |
85f41bec | 661 | racoon_yyerror("racoon not configured with --enable-hybrid"); |
52b7d2ce A |
662 | #endif /* ENABLE_HYBRID */ |
663 | } | |
664 | EOS | |
665 | | CFG_CONF_SOURCE CFG_LOCAL | |
666 | { | |
667 | #ifdef ENABLE_HYBRID | |
668 | isakmp_cfg_config.confsource = ISAKMP_CFG_CONF_LOCAL; | |
669 | #else /* ENABLE_HYBRID */ | |
85f41bec | 670 | racoon_yyerror("racoon not configured with --enable-hybrid"); |
52b7d2ce A |
671 | #endif /* ENABLE_HYBRID */ |
672 | } | |
673 | EOS | |
674 | | CFG_CONF_SOURCE CFG_RADIUS | |
675 | { | |
676 | #ifdef ENABLE_HYBRID | |
85f41bec | 677 | racoon_yyerror("racoon not configured with --with-libradius"); |
d1e348cf | 678 | #else /* ENABLE_HYBRID */ |
85f41bec | 679 | racoon_yyerror("racoon not configured with --enable-hybrid"); |
d1e348cf A |
680 | #endif /* ENABLE_HYBRID */ |
681 | } | |
682 | EOS | |
683 | | CFG_CONF_SOURCE CFG_LDAP | |
684 | { | |
685 | #ifdef ENABLE_HYBRID | |
85f41bec | 686 | racoon_yyerror("racoon not configured with --with-libldap"); |
52b7d2ce | 687 | #else /* ENABLE_HYBRID */ |
85f41bec | 688 | racoon_yyerror("racoon not configured with --enable-hybrid"); |
52b7d2ce A |
689 | #endif /* ENABLE_HYBRID */ |
690 | } | |
691 | EOS | |
692 | | CFG_MOTD QUOTEDSTRING | |
693 | { | |
694 | #ifdef ENABLE_HYBRID | |
d1e348cf | 695 | strlcpy(&isakmp_cfg_config.motd[0], $2->v, sizeof(isakmp_cfg_config.motd)); |
52b7d2ce A |
696 | vfree($2); |
697 | #else | |
85f41bec | 698 | racoon_yyerror("racoon not configured with --enable-hybrid"); |
52b7d2ce A |
699 | #endif |
700 | } | |
701 | EOS | |
702 | ; | |
703 | ||
d1e348cf A |
704 | addrdnslist |
705 | : addrdns | |
706 | | addrdns COMMA addrdnslist | |
707 | ; | |
708 | addrdns | |
709 | : ADDRSTRING | |
710 | { | |
711 | #ifdef ENABLE_HYBRID | |
712 | struct isakmp_cfg_config *icc = &isakmp_cfg_config; | |
713 | ||
65c25746 | 714 | if (icc->dns4_index > MAXNS) { |
85f41bec | 715 | racoon_yyerror("No more than %d DNS", MAXNS); |
65c25746 A |
716 | return -1; |
717 | } | |
d1e348cf A |
718 | if (inet_pton(AF_INET, $1->v, |
719 | &icc->dns4[icc->dns4_index++]) != 1) | |
85f41bec | 720 | racoon_yyerror("bad IPv4 DNS address."); |
d1e348cf A |
721 | |
722 | vfree($1); | |
723 | #else | |
85f41bec | 724 | racoon_yyerror("racoon not configured with --enable-hybrid"); |
d1e348cf A |
725 | #endif |
726 | } | |
727 | ; | |
728 | ||
729 | addrwinslist | |
730 | : addrwins | |
731 | | addrwins COMMA addrwinslist | |
732 | ; | |
733 | addrwins | |
734 | : ADDRSTRING | |
735 | { | |
736 | #ifdef ENABLE_HYBRID | |
737 | struct isakmp_cfg_config *icc = &isakmp_cfg_config; | |
738 | ||
65c25746 | 739 | if (icc->nbns4_index > MAXWINS) { |
85f41bec | 740 | racoon_yyerror("No more than %d WINS", MAXWINS); |
65c25746 A |
741 | return -1; |
742 | } | |
d1e348cf A |
743 | if (inet_pton(AF_INET, $1->v, |
744 | &icc->nbns4[icc->nbns4_index++]) != 1) | |
85f41bec | 745 | racoon_yyerror("bad IPv4 WINS address."); |
d1e348cf A |
746 | |
747 | vfree($1); | |
748 | #else | |
85f41bec | 749 | racoon_yyerror("racoon not configured with --enable-hybrid"); |
d1e348cf A |
750 | #endif |
751 | } | |
752 | ; | |
753 | ||
754 | splitnetlist | |
755 | : splitnet | |
756 | | splitnetlist COMMA splitnet | |
757 | ; | |
758 | splitnet | |
759 | : ADDRSTRING PREFIX | |
760 | { | |
761 | #ifdef ENABLE_HYBRID | |
762 | struct isakmp_cfg_config *icc = &isakmp_cfg_config; | |
763 | struct unity_network network; | |
764 | ||
765 | if (inet_pton(AF_INET, $1->v, &network.addr4) != 1) | |
85f41bec | 766 | racoon_yyerror("bad IPv4 SPLIT address."); |
d1e348cf A |
767 | |
768 | /* Turn $2 (the prefix) into a subnet mask */ | |
769 | network.mask4.s_addr = ($2) ? htonl(~((1 << (32 - $2)) - 1)) : 0; | |
770 | ||
771 | /* add the network to our list */ | |
772 | if (splitnet_list_add(&icc->splitnet_list, &network,&icc->splitnet_count)) | |
85f41bec | 773 | racoon_yyerror("Unable to allocate split network"); |
d1e348cf A |
774 | |
775 | vfree($1); | |
776 | #else | |
85f41bec | 777 | racoon_yyerror("racoon not configured with --enable-hybrid"); |
d1e348cf A |
778 | #endif |
779 | } | |
780 | ; | |
781 | ||
782 | authgrouplist | |
783 | : authgroup | |
784 | | authgroup COMMA authgrouplist | |
785 | ; | |
786 | authgroup | |
787 | : QUOTEDSTRING | |
788 | { | |
789 | #ifdef ENABLE_HYBRID | |
790 | char * groupname = NULL; | |
791 | char ** grouplist = NULL; | |
792 | struct isakmp_cfg_config *icc = &isakmp_cfg_config; | |
793 | ||
794 | grouplist = racoon_realloc(icc->grouplist, | |
795 | sizeof(char**)*(icc->groupcount+1)); | |
796 | if (grouplist == NULL) | |
85f41bec | 797 | racoon_yyerror("unable to allocate auth group list"); |
d1e348cf A |
798 | |
799 | groupname = racoon_malloc($1->l+1); | |
800 | if (groupname == NULL) | |
85f41bec | 801 | racoon_yyerror("unable to allocate auth group name"); |
d1e348cf A |
802 | |
803 | memcpy(groupname,$1->v,$1->l); | |
804 | groupname[$1->l]=0; | |
805 | grouplist[icc->groupcount]=groupname; | |
806 | icc->grouplist = grouplist; | |
807 | icc->groupcount++; | |
808 | ||
809 | vfree($1); | |
810 | #else | |
85f41bec | 811 | racoon_yyerror("racoon not configured with --enable-hybrid"); |
d1e348cf A |
812 | #endif |
813 | } | |
814 | ; | |
815 | ||
816 | splitdnslist | |
817 | : splitdns | |
818 | | splitdns COMMA splitdnslist | |
819 | ; | |
820 | splitdns | |
821 | : QUOTEDSTRING | |
822 | { | |
823 | #ifdef ENABLE_HYBRID | |
824 | struct isakmp_cfg_config *icc = &isakmp_cfg_config; | |
825 | ||
826 | if (!icc->splitdns_len) | |
827 | { | |
828 | icc->splitdns_list = racoon_malloc($1->l); | |
829 | if(icc->splitdns_list == NULL) | |
85f41bec | 830 | racoon_yyerror("error allocating splitdns list buffer"); |
d1e348cf A |
831 | memcpy(icc->splitdns_list,$1->v,$1->l); |
832 | icc->splitdns_len = $1->l; | |
833 | } | |
834 | else | |
835 | { | |
836 | int len = icc->splitdns_len + $1->l + 1; | |
837 | icc->splitdns_list = racoon_realloc(icc->splitdns_list,len); | |
838 | if(icc->splitdns_list == NULL) | |
85f41bec | 839 | racoon_yyerror("error allocating splitdns list buffer"); |
d1e348cf A |
840 | icc->splitdns_list[icc->splitdns_len] = ','; |
841 | memcpy(icc->splitdns_list + icc->splitdns_len + 1, $1->v, $1->l); | |
842 | icc->splitdns_len = len; | |
843 | } | |
844 | vfree($1); | |
845 | #else | |
85f41bec | 846 | racoon_yyerror("racoon not configured with --enable-hybrid"); |
d1e348cf A |
847 | #endif |
848 | } | |
849 | ; | |
850 | ||
851 | ||
52b7d2ce A |
852 | /* timer */ |
853 | timer_statement | |
854 | : RETRY BOC timer_stmts EOC | |
855 | ; | |
856 | timer_stmts | |
857 | : /* nothing */ | |
858 | | timer_stmts timer_stmt | |
859 | ; | |
860 | timer_stmt | |
861 | : RETRY_COUNTER NUMBER | |
862 | { | |
863 | lcconf->retry_counter = $2; | |
864 | } | |
865 | EOS | |
866 | | RETRY_INTERVAL NUMBER unittype_time | |
867 | { | |
868 | lcconf->retry_interval = $2 * $3; | |
869 | } | |
870 | EOS | |
871 | | RETRY_PERSEND NUMBER | |
872 | { | |
873 | lcconf->count_persend = $2; | |
874 | } | |
875 | EOS | |
876 | | RETRY_PHASE1 NUMBER unittype_time | |
877 | { | |
878 | lcconf->retry_checkph1 = $2 * $3; | |
879 | } | |
880 | EOS | |
881 | | RETRY_PHASE2 NUMBER unittype_time | |
882 | { | |
883 | lcconf->wait_ph2complete = $2 * $3; | |
884 | } | |
885 | EOS | |
886 | | AUTO_EXIT_DELAY NUMBER unittype_time | |
887 | { | |
888 | lcconf->auto_exit_delay = $2 * $3; | |
889 | lcconf->auto_exit_state |= LC_AUTOEXITSTATE_SET; | |
890 | } | |
891 | EOS | |
892 | ||
893 | | NATT_KA NUMBER unittype_time | |
894 | { | |
895 | #ifdef ENABLE_NATT | |
896 | lcconf->natt_ka_interval = $2 * $3; | |
897 | #else | |
85f41bec | 898 | racoon_yyerror("NAT-T support not compiled in."); |
52b7d2ce A |
899 | #endif |
900 | } | |
901 | EOS | |
902 | ; | |
903 | ||
904 | /* sainfo */ | |
905 | sainfo_statement | |
906 | : SAINFO | |
907 | { | |
65c25746 | 908 | cur_sainfo = create_sainfo(); |
52b7d2ce | 909 | if (cur_sainfo == NULL) { |
85f41bec | 910 | racoon_yyerror("failed to allocate sainfo"); |
52b7d2ce A |
911 | return -1; |
912 | } | |
913 | } | |
d1e348cf | 914 | sainfo_name sainfo_param BOC sainfo_specs |
52b7d2ce A |
915 | { |
916 | struct sainfo *check; | |
917 | ||
918 | /* default */ | |
919 | if (cur_sainfo->algs[algclass_ipsec_enc] == 0) { | |
85f41bec | 920 | racoon_yyerror("no encryption algorithm at %s", |
52b7d2ce A |
921 | sainfo2str(cur_sainfo)); |
922 | return -1; | |
923 | } | |
924 | if (cur_sainfo->algs[algclass_ipsec_auth] == 0) { | |
85f41bec | 925 | racoon_yyerror("no authentication algorithm at %s", |
52b7d2ce A |
926 | sainfo2str(cur_sainfo)); |
927 | return -1; | |
928 | } | |
929 | if (cur_sainfo->algs[algclass_ipsec_comp] == 0) { | |
85f41bec | 930 | racoon_yyerror("no compression algorithm at %s", |
52b7d2ce A |
931 | sainfo2str(cur_sainfo)); |
932 | return -1; | |
933 | } | |
934 | ||
935 | /* duplicate check */ | |
936 | check = getsainfo(cur_sainfo->idsrc, | |
937 | cur_sainfo->iddst, | |
05434fec | 938 | cur_sainfo->id_i, 0); |
52b7d2ce | 939 | if (check && (!check->idsrc && !cur_sainfo->idsrc)) { |
85f41bec | 940 | racoon_yyerror("duplicated sainfo: %s", |
52b7d2ce A |
941 | sainfo2str(cur_sainfo)); |
942 | return -1; | |
943 | } | |
944 | inssainfo(cur_sainfo); | |
945 | } | |
946 | EOC | |
947 | ; | |
948 | sainfo_name | |
949 | : ANONYMOUS | |
950 | { | |
951 | cur_sainfo->idsrc = NULL; | |
952 | cur_sainfo->iddst = NULL; | |
953 | } | |
d1e348cf A |
954 | | ANONYMOUS sainfo_id |
955 | { | |
956 | cur_sainfo->idsrc = NULL; | |
957 | cur_sainfo->iddst = $2; | |
958 | } | |
959 | | sainfo_id ANONYMOUS | |
960 | { | |
961 | cur_sainfo->idsrc = $1; | |
962 | cur_sainfo->iddst = NULL; | |
963 | } | |
52b7d2ce A |
964 | | sainfo_id sainfo_id |
965 | { | |
966 | cur_sainfo->idsrc = $1; | |
967 | cur_sainfo->iddst = $2; | |
968 | } | |
969 | ; | |
970 | sainfo_id | |
971 | : IDENTIFIERTYPE ADDRSTRING prefix port ul_proto | |
972 | { | |
973 | char portbuf[10]; | |
85f41bec | 974 | struct sockaddr_storage *saddr; |
52b7d2ce A |
975 | |
976 | if (($5 == IPPROTO_ICMP || $5 == IPPROTO_ICMPV6) | |
977 | && ($4 != IPSEC_PORT_ANY || $4 != IPSEC_PORT_ANY)) { | |
85f41bec | 978 | racoon_yyerror("port number must be \"any\"."); |
52b7d2ce A |
979 | return -1; |
980 | } | |
981 | ||
982 | snprintf(portbuf, sizeof(portbuf), "%lu", $4); | |
983 | saddr = str2saddr($2->v, portbuf); | |
984 | vfree($2); | |
985 | if (saddr == NULL) | |
986 | return -1; | |
987 | ||
85f41bec | 988 | switch (saddr->ss_family) { |
52b7d2ce A |
989 | case AF_INET: |
990 | if ($5 == IPPROTO_ICMPV6) { | |
85f41bec | 991 | racoon_yyerror("upper layer protocol mismatched.\n"); |
52b7d2ce A |
992 | racoon_free(saddr); |
993 | return -1; | |
994 | } | |
995 | $$ = ipsecdoi_sockaddr2id(saddr, | |
d1e348cf A |
996 | $3 == ~0 ? (sizeof(struct in_addr) << 3): $3, |
997 | $5); | |
52b7d2ce A |
998 | break; |
999 | #ifdef INET6 | |
1000 | case AF_INET6: | |
1001 | if ($5 == IPPROTO_ICMP) { | |
85f41bec | 1002 | racoon_yyerror("upper layer protocol mismatched.\n"); |
52b7d2ce A |
1003 | racoon_free(saddr); |
1004 | return -1; | |
1005 | } | |
d1e348cf A |
1006 | $$ = ipsecdoi_sockaddr2id(saddr, |
1007 | $3 == ~0 ? (sizeof(struct in6_addr) << 3): $3, | |
1008 | $5); | |
52b7d2ce A |
1009 | break; |
1010 | #endif | |
1011 | default: | |
85f41bec | 1012 | racoon_yyerror("invalid family: %d", saddr->ss_family); |
52b7d2ce A |
1013 | $$ = NULL; |
1014 | break; | |
1015 | } | |
1016 | racoon_free(saddr); | |
1017 | if ($$ == NULL) | |
1018 | return -1; | |
1019 | } | |
d1e348cf A |
1020 | | IDENTIFIERTYPE ADDRSTRING ADDRRANGE prefix port ul_proto |
1021 | { | |
1022 | char portbuf[10]; | |
85f41bec | 1023 | struct sockaddr_storage *laddr = NULL, *haddr = NULL; |
d1e348cf A |
1024 | |
1025 | if (($6 == IPPROTO_ICMP || $6 == IPPROTO_ICMPV6) | |
1026 | && ($5 != IPSEC_PORT_ANY || $5 != IPSEC_PORT_ANY)) { | |
85f41bec | 1027 | racoon_yyerror("port number must be \"any\"."); |
d1e348cf A |
1028 | return -1; |
1029 | } | |
1030 | ||
1031 | snprintf(portbuf, sizeof(portbuf), "%lu", $5); | |
1032 | ||
1033 | laddr = str2saddr($2->v, portbuf); | |
1034 | if (laddr == NULL) { | |
1035 | return -1; | |
1036 | } | |
1037 | vfree($2); | |
1038 | haddr = str2saddr($3->v, portbuf); | |
1039 | if (haddr == NULL) { | |
1040 | racoon_free(laddr); | |
1041 | return -1; | |
1042 | } | |
1043 | vfree($3); | |
1044 | ||
85f41bec | 1045 | switch (laddr->ss_family) { |
d1e348cf A |
1046 | case AF_INET: |
1047 | if ($6 == IPPROTO_ICMPV6) { | |
85f41bec | 1048 | racoon_yyerror("upper layer protocol mismatched.\n"); |
d1e348cf A |
1049 | if (laddr) |
1050 | racoon_free(laddr); | |
1051 | if (haddr) | |
1052 | racoon_free(haddr); | |
1053 | return -1; | |
1054 | } | |
1055 | $$ = ipsecdoi_sockrange2id(laddr, haddr, | |
1056 | $6); | |
1057 | break; | |
1058 | #ifdef INET6 | |
1059 | case AF_INET6: | |
1060 | if ($6 == IPPROTO_ICMP) { | |
85f41bec | 1061 | racoon_yyerror("upper layer protocol mismatched.\n"); |
d1e348cf A |
1062 | if (laddr) |
1063 | racoon_free(laddr); | |
1064 | if (haddr) | |
1065 | racoon_free(haddr); | |
1066 | return -1; | |
1067 | } | |
1068 | $$ = ipsecdoi_sockrange2id(laddr, haddr, | |
1069 | $6); | |
1070 | break; | |
1071 | #endif | |
1072 | default: | |
85f41bec | 1073 | racoon_yyerror("invalid family: %d", laddr->ss_family); |
d1e348cf A |
1074 | $$ = NULL; |
1075 | break; | |
1076 | } | |
1077 | if (laddr) | |
1078 | racoon_free(laddr); | |
1079 | if (haddr) | |
1080 | racoon_free(haddr); | |
1081 | if ($$ == NULL) | |
1082 | return -1; | |
1083 | } | |
52b7d2ce A |
1084 | | IDENTIFIERTYPE QUOTEDSTRING |
1085 | { | |
1086 | struct ipsecdoi_id_b *id_b; | |
1087 | ||
1088 | if ($1 == IDTYPE_ASN1DN) { | |
85f41bec | 1089 | racoon_yyerror("id type forbidden: %d", $1); |
52b7d2ce A |
1090 | $$ = NULL; |
1091 | return -1; | |
1092 | } | |
1093 | ||
1094 | $2->l--; | |
1095 | ||
1096 | $$ = vmalloc(sizeof(*id_b) + $2->l); | |
1097 | if ($$ == NULL) { | |
85f41bec | 1098 | racoon_yyerror("failed to allocate identifier"); |
52b7d2ce A |
1099 | return -1; |
1100 | } | |
1101 | ||
85f41bec | 1102 | id_b = ALIGNED_CAST(struct ipsecdoi_id_b *)$$->v; |
52b7d2ce A |
1103 | id_b->type = idtype2doi($1); |
1104 | ||
1105 | id_b->proto_id = 0; | |
1106 | id_b->port = 0; | |
1107 | ||
1108 | memcpy($$->v + sizeof(*id_b), $2->v, $2->l); | |
1109 | } | |
1110 | ; | |
d1e348cf | 1111 | sainfo_param |
52b7d2ce A |
1112 | : /* nothing */ |
1113 | { | |
1114 | cur_sainfo->id_i = NULL; | |
1115 | } | |
1116 | ||
1117 | | FROM IDENTIFIERTYPE identifierstring | |
1118 | { | |
1119 | struct ipsecdoi_id_b *id_b; | |
1120 | vchar_t *idv; | |
1121 | ||
1122 | if (set_identifier(&idv, $2, $3) != 0) { | |
85f41bec | 1123 | racoon_yyerror("failed to set identifer.\n"); |
52b7d2ce A |
1124 | return -1; |
1125 | } | |
1126 | cur_sainfo->id_i = vmalloc(sizeof(*id_b) + idv->l); | |
1127 | if (cur_sainfo->id_i == NULL) { | |
85f41bec | 1128 | racoon_yyerror("failed to allocate identifier"); |
52b7d2ce A |
1129 | return -1; |
1130 | } | |
1131 | ||
85f41bec | 1132 | id_b = ALIGNED_CAST(struct ipsecdoi_id_b *)cur_sainfo->id_i->v; |
52b7d2ce A |
1133 | id_b->type = idtype2doi($2); |
1134 | ||
1135 | id_b->proto_id = 0; | |
1136 | id_b->port = 0; | |
1137 | ||
1138 | memcpy(cur_sainfo->id_i->v + sizeof(*id_b), | |
1139 | idv->v, idv->l); | |
1140 | vfree(idv); | |
1141 | } | |
d1e348cf A |
1142 | | GROUP QUOTEDSTRING |
1143 | { | |
1144 | #ifdef ENABLE_HYBRID | |
1145 | if ((cur_sainfo->group = vdup($2)) == NULL) { | |
85f41bec | 1146 | racoon_yyerror("failed to set sainfo xauth group.\n"); |
d1e348cf A |
1147 | return -1; |
1148 | } | |
1149 | #else | |
85f41bec | 1150 | racoon_yyerror("racoon not configured with --enable-hybrid"); |
d1e348cf A |
1151 | return -1; |
1152 | #endif | |
1153 | } | |
52b7d2ce A |
1154 | ; |
1155 | sainfo_specs | |
1156 | : /* nothing */ | |
1157 | | sainfo_specs sainfo_spec | |
1158 | ; | |
1159 | sainfo_spec | |
1160 | : PFS_GROUP dh_group_num | |
1161 | { | |
1162 | cur_sainfo->pfs_group = $2; | |
65c25746 A |
1163 | switch (cur_sainfo->pfs_group) |
1164 | { | |
1165 | case OAKLEY_ATTR_GRP_DESC_MODP768: | |
1166 | case OAKLEY_ATTR_GRP_DESC_MODP1024: | |
1167 | case OAKLEY_ATTR_GRP_DESC_MODP1536: | |
1168 | case OAKLEY_ATTR_GRP_DESC_MODP2048: | |
1169 | case OAKLEY_ATTR_GRP_DESC_MODP3072: | |
1170 | case OAKLEY_ATTR_GRP_DESC_MODP4096: | |
1171 | case OAKLEY_ATTR_GRP_DESC_MODP6144: | |
1172 | case OAKLEY_ATTR_GRP_DESC_MODP8192: | |
1173 | break; | |
1174 | default: | |
1175 | racoon_yyerror("Invalid PFS group specified"); | |
1176 | return -1; | |
1177 | break; | |
e8d9021d | 1178 | } |
52b7d2ce A |
1179 | } |
1180 | EOS | |
1181 | | LIFETIME LIFETYPE_TIME NUMBER unittype_time | |
1182 | { | |
1183 | cur_sainfo->lifetime = $3 * $4; | |
1184 | } | |
1185 | EOS | |
1186 | | LIFETIME LIFETYPE_BYTE NUMBER unittype_byte | |
1187 | { | |
1188 | #if 1 | |
85f41bec | 1189 | racoon_yyerror("byte lifetime support is deprecated"); |
52b7d2ce A |
1190 | return -1; |
1191 | #else | |
1192 | cur_sainfo->lifebyte = fix_lifebyte($3 * $4); | |
1193 | if (cur_sainfo->lifebyte == 0) | |
1194 | return -1; | |
1195 | #endif | |
1196 | } | |
1197 | EOS | |
1198 | | ALGORITHM_CLASS { | |
1199 | cur_algclass = $1; | |
1200 | } | |
1201 | algorithms EOS | |
1202 | | IDENTIFIER IDENTIFIERTYPE | |
1203 | { | |
85f41bec | 1204 | racoon_yyerror("it's deprecated to specify a identifier in phase 2"); |
52b7d2ce A |
1205 | } |
1206 | EOS | |
1207 | | MY_IDENTIFIER IDENTIFIERTYPE QUOTEDSTRING | |
1208 | { | |
85f41bec | 1209 | racoon_yyerror("it's deprecated to specify a identifier in phase 2"); |
52b7d2ce A |
1210 | } |
1211 | EOS | |
1212 | ; | |
1213 | ||
1214 | algorithms | |
1215 | : algorithm | |
1216 | { | |
1217 | inssainfoalg(&cur_sainfo->algs[cur_algclass], $1); | |
1218 | } | |
1219 | | algorithm | |
1220 | { | |
1221 | inssainfoalg(&cur_sainfo->algs[cur_algclass], $1); | |
1222 | } | |
1223 | COMMA algorithms | |
1224 | ; | |
1225 | algorithm | |
1226 | : ALGORITHMTYPE keylength | |
1227 | { | |
1228 | int defklen; | |
1229 | ||
1230 | $$ = newsainfoalg(); | |
1231 | if ($$ == NULL) { | |
85f41bec | 1232 | racoon_yyerror("failed to get algorithm allocation"); |
52b7d2ce A |
1233 | return -1; |
1234 | } | |
1235 | ||
1236 | $$->alg = algtype2doi(cur_algclass, $1); | |
1237 | if ($$->alg == -1) { | |
85f41bec | 1238 | racoon_yyerror("algorithm mismatched"); |
52b7d2ce A |
1239 | racoon_free($$); |
1240 | $$ = NULL; | |
1241 | return -1; | |
1242 | } | |
1243 | ||
1244 | defklen = default_keylen(cur_algclass, $1); | |
1245 | if (defklen == 0) { | |
1246 | if ($2) { | |
85f41bec | 1247 | racoon_yyerror("keylen not allowed"); |
52b7d2ce A |
1248 | racoon_free($$); |
1249 | $$ = NULL; | |
1250 | return -1; | |
1251 | } | |
1252 | } else { | |
1253 | if ($2 && check_keylen(cur_algclass, $1, $2) < 0) { | |
85f41bec | 1254 | racoon_yyerror("invalid keylen %d", $2); |
52b7d2ce A |
1255 | racoon_free($$); |
1256 | $$ = NULL; | |
1257 | return -1; | |
1258 | } | |
1259 | } | |
1260 | ||
1261 | if ($2) | |
1262 | $$->encklen = $2; | |
1263 | else | |
1264 | $$->encklen = defklen; | |
1265 | ||
1266 | /* check if it's supported algorithm by kernel */ | |
1267 | if (!(cur_algclass == algclass_ipsec_auth && $1 == algtype_non_auth) | |
1268 | && pk_checkalg(cur_algclass, $1, $$->encklen)) { | |
1269 | int a = algclass2doi(cur_algclass); | |
1270 | int b = algtype2doi(cur_algclass, $1); | |
1271 | if (a == IPSECDOI_ATTR_AUTH) | |
1272 | a = IPSECDOI_PROTO_IPSEC_AH; | |
85f41bec | 1273 | racoon_yyerror("algorithm %s not supported by the kernel (missing module?)", |
52b7d2ce A |
1274 | s_ipsecdoi_trns(a, b)); |
1275 | racoon_free($$); | |
1276 | $$ = NULL; | |
1277 | return -1; | |
1278 | } | |
1279 | } | |
1280 | ; | |
1281 | prefix | |
1282 | : /* nothing */ { $$ = ~0; } | |
1283 | | PREFIX { $$ = $1; } | |
1284 | ; | |
1285 | port | |
1286 | : /* nothing */ { $$ = IPSEC_PORT_ANY; } | |
1287 | | PORT { $$ = $1; } | |
1288 | | PORTANY { $$ = IPSEC_PORT_ANY; } | |
1289 | ; | |
1290 | ul_proto | |
1291 | : NUMBER { $$ = $1; } | |
1292 | | UL_PROTO { $$ = $1; } | |
1293 | | ANY { $$ = IPSEC_ULPROTO_ANY; } | |
1294 | ; | |
1295 | keylength | |
1296 | : /* nothing */ { $$ = 0; } | |
1297 | | NUMBER { $$ = $1; } | |
1298 | ; | |
1299 | ||
1300 | /* remote */ | |
1301 | remote_statement | |
1302 | : REMOTE remote_index INHERIT remote_index | |
1303 | { | |
1304 | struct remoteconf *new; | |
1305 | struct proposalspec *prspec; | |
1306 | ||
85f41bec | 1307 | new = copyrmconf($4->addr); |
52b7d2ce | 1308 | if (new == NULL) { |
85f41bec A |
1309 | racoon_yyerror("failed to get remoteconf for %s.", saddr2str((struct sockaddr *)$4)); |
1310 | racoon_free($2->addr); | |
1311 | racoon_free($2); | |
1312 | racoon_free($4->addr); | |
1313 | racoon_free($4); | |
52b7d2ce A |
1314 | return -1; |
1315 | } | |
1316 | ||
85f41bec A |
1317 | new->remote = $2->addr; |
1318 | new->remote_prefix = ($2->prefix == ~0 ? 0 : $2->prefix); | |
1319 | new->inherited_from = getrmconf_strict($4->addr, 1); | |
52b7d2ce A |
1320 | new->proposal = NULL; |
1321 | new->prhead = NULL; | |
1322 | cur_rmconf = new; | |
85f41bec A |
1323 | racoon_free($2); |
1324 | racoon_free($4->addr); | |
1325 | racoon_free($4); | |
52b7d2ce A |
1326 | |
1327 | prspec = newprspec(); | |
1328 | if (prspec == NULL || !cur_rmconf->inherited_from | |
1329 | || !cur_rmconf->inherited_from->proposal) | |
1330 | return -1; | |
1331 | prspec->lifetime = cur_rmconf->inherited_from->proposal->lifetime; | |
1332 | prspec->lifebyte = cur_rmconf->inherited_from->proposal->lifebyte; | |
1333 | insprspec(prspec, &cur_rmconf->prhead); | |
1334 | } | |
1335 | remote_specs_block | |
1336 | | REMOTE remote_index | |
1337 | { | |
1338 | struct remoteconf *new; | |
1339 | struct proposalspec *prspec; | |
1340 | ||
65c25746 | 1341 | new = create_rmconf(); |
52b7d2ce | 1342 | if (new == NULL) { |
85f41bec A |
1343 | racoon_yyerror("failed to get new remoteconf."); |
1344 | racoon_free($2->addr); | |
1345 | racoon_free($2); | |
52b7d2ce A |
1346 | return -1; |
1347 | } | |
85f41bec A |
1348 | new->remote = $2->addr; |
1349 | new->remote_prefix = ($2->prefix == ~0 ? 0 : $2->prefix); | |
52b7d2ce | 1350 | cur_rmconf = new; |
85f41bec | 1351 | racoon_free($2); |
52b7d2ce A |
1352 | |
1353 | prspec = newprspec(); | |
1354 | if (prspec == NULL) | |
1355 | return -1; | |
1356 | prspec->lifetime = oakley_get_defaultlifetime(); | |
1357 | insprspec(prspec, &cur_rmconf->prhead); | |
1358 | } | |
1359 | remote_specs_block | |
1360 | ; | |
1361 | ||
1362 | remote_specs_block | |
1363 | : BOC remote_specs EOC | |
1364 | { | |
1365 | /* check a exchange mode */ | |
1366 | if (cur_rmconf->etypes == NULL) { | |
85f41bec | 1367 | racoon_yyerror("no exchange mode specified.\n"); |
52b7d2ce A |
1368 | return -1; |
1369 | } | |
1370 | ||
1371 | if (cur_rmconf->idvtype == IDTYPE_UNDEFINED) | |
1372 | cur_rmconf->idvtype = IDTYPE_ADDRESS; | |
1373 | ||
1374 | ||
1375 | if (cur_rmconf->idvtype == IDTYPE_ASN1DN) { | |
65c25746 | 1376 | if (cur_rmconf->identity_in_keychain) |
52b7d2ce A |
1377 | { |
1378 | if (cur_rmconf->idv) | |
85f41bec | 1379 | racoon_yywarn("Both CERT and ASN1 ID " |
52b7d2ce A |
1380 | "are set. Hope this is OK.\n"); |
1381 | /* TODO: Preparse the DN here */ | |
1382 | } else if (cur_rmconf->idv) { | |
1383 | /* OK, using asn1dn without X.509. */ | |
1384 | } else { | |
85f41bec | 1385 | racoon_yyerror("ASN1 ID not specified " |
52b7d2ce A |
1386 | "and no CERT defined!\n"); |
1387 | return -1; | |
1388 | } | |
1389 | } | |
e8d9021d | 1390 | |
52b7d2ce A |
1391 | if (cur_rmconf->cert_verification_option == VERIFICATION_OPTION_PEERS_IDENTIFIER) { |
1392 | struct genlist_entry *gpb; | |
1393 | if (genlist_next(cur_rmconf->idvl_p, &gpb) == NULL) { | |
85f41bec | 1394 | racoon_yyerror("peers_identifier required for specified certificate " |
52b7d2ce A |
1395 | "verification option.\n"); |
1396 | return -1; | |
1397 | } | |
1398 | } | |
52b7d2ce A |
1399 | |
1400 | if (cur_rmconf->prhead->spspec == NULL | |
1401 | && cur_rmconf->inherited_from | |
1402 | && cur_rmconf->inherited_from->prhead) { | |
1403 | cur_rmconf->prhead->spspec = cur_rmconf->inherited_from->prhead->spspec; | |
1404 | } | |
1405 | if (set_isakmp_proposal(cur_rmconf, cur_rmconf->prhead) != 0) | |
1406 | return -1; | |
1407 | ||
d9c572c0 A |
1408 | /* DH group setting if aggressive mode or IKEv2. */ |
1409 | if (check_etypeok(cur_rmconf, ISAKMP_ETYPE_AGG) != NULL) { | |
52b7d2ce A |
1410 | struct isakmpsa *p; |
1411 | int b = 0; | |
1412 | ||
1413 | /* DH group */ | |
1414 | for (p = cur_rmconf->proposal; p; p = p->next) { | |
1415 | if (b == 0 || (b && b == p->dh_group)) { | |
1416 | b = p->dh_group; | |
1417 | continue; | |
1418 | } | |
85f41bec | 1419 | racoon_yyerror("DH group must be equal " |
52b7d2ce A |
1420 | "in all proposals " |
1421 | "when aggressive mode is " | |
1422 | "used.\n"); | |
1423 | return -1; | |
1424 | } | |
1425 | cur_rmconf->dh_group = b; | |
1426 | ||
1427 | if (cur_rmconf->dh_group == 0) { | |
85f41bec | 1428 | racoon_yyerror("DH group must be set in the proposal.\n"); |
52b7d2ce A |
1429 | return -1; |
1430 | } | |
1431 | ||
1432 | /* DH group settting if PFS is required. */ | |
1433 | if (oakley_setdhgroup(cur_rmconf->dh_group, | |
1434 | &cur_rmconf->dhgrp) < 0) { | |
85f41bec | 1435 | racoon_yyerror("failed to set DH value.\n"); |
52b7d2ce A |
1436 | return -1; |
1437 | } | |
1438 | } | |
1439 | ||
1440 | insrmconf(cur_rmconf); | |
1441 | } | |
1442 | ; | |
1443 | remote_index | |
1444 | : ANONYMOUS ike_port | |
1445 | { | |
85f41bec A |
1446 | |
1447 | struct remote_index_val *new; | |
1448 | ||
1449 | new = racoon_calloc(1, sizeof(*new)); | |
1450 | if (new == NULL) { | |
1451 | racoon_yyerror("failed to allocate remote index struct"); | |
1452 | return -1; | |
1453 | } | |
1454 | new->addr = newsaddr(sizeof(struct sockaddr_storage)); | |
1455 | if (new->addr == NULL) { | |
1456 | racoon_yyerror("failed to allocate sockaddr storage"); | |
1457 | racoon_free(new); | |
1458 | return -1; | |
1459 | } | |
1460 | new->addr->ss_family = AF_UNSPEC; | |
1461 | (ALIGNED_CAST(struct sockaddr_in *)new->addr)->sin_port = htons($2); | |
1462 | new->prefix = ~0; | |
1463 | $$ = new; | |
1464 | } | |
1465 | | ike_addrinfo_prefix_port | |
52b7d2ce A |
1466 | { |
1467 | $$ = $1; | |
1468 | if ($$ == NULL) { | |
85f41bec | 1469 | racoon_yyerror("failed to allocate sockaddr_storage"); |
52b7d2ce A |
1470 | return -1; |
1471 | } | |
1472 | } | |
1473 | ; | |
1474 | remote_specs | |
1475 | : /* nothing */ | |
1476 | | remote_specs remote_spec | |
1477 | ; | |
1478 | remote_spec | |
1479 | : EXCHANGE_MODE | |
1480 | { | |
1481 | cur_rmconf->etypes = NULL; | |
1482 | } | |
1483 | exchange_types EOS | |
1484 | | DOI DOITYPE { cur_rmconf->doitype = $2; } EOS | |
1485 | | SITUATION SITUATIONTYPE { cur_rmconf->sittype = $2; } EOS | |
65c25746 A |
1486 | | IKE_VERSION NUMBER |
1487 | { | |
1488 | if ($2 == 1) | |
1489 | cur_rmconf->ike_version = ISAKMP_VERSION_NUMBER_IKEV1; | |
1490 | else { | |
1491 | racoon_yyerror("invalid IKE version specified.\n"); | |
1492 | return -1; | |
1493 | } | |
1494 | } EOS | |
52b7d2ce | 1495 | | CERTIFICATE_TYPE cert_spec |
52b7d2ce A |
1496 | | VERIFY_CERT SWITCH { cur_rmconf->verify_cert = $2; } EOS |
1497 | | SEND_CERT SWITCH { cur_rmconf->send_cert = $2; } EOS | |
1498 | | SEND_CR SWITCH { cur_rmconf->send_cr = $2; } EOS | |
1499 | | CERTIFICATE_VERIFICATION VERIFICATION_MODULE | |
1500 | { | |
52b7d2ce | 1501 | cur_rmconf->cert_verification = $2; |
52b7d2ce A |
1502 | } EOS |
1503 | | CERTIFICATE_VERIFICATION VERIFICATION_MODULE VERIFICATION_OPTION | |
e8d9021d | 1504 | { |
52b7d2ce A |
1505 | cur_rmconf->cert_verification = $2; |
1506 | cur_rmconf->cert_verification_option = $3; | |
52b7d2ce A |
1507 | } |
1508 | EOS | |
1509 | | OPEN_DIR_AUTH_GROUP QUOTEDSTRING | |
1510 | { | |
e8d9021d | 1511 | #if HAVE_OPENDIR |
52b7d2ce A |
1512 | cur_rmconf->open_dir_auth_group = $2; |
1513 | #else | |
85f41bec | 1514 | racoon_yyerror("Apple specific features not compiled in."); |
52b7d2ce A |
1515 | return -1; |
1516 | #endif | |
1517 | } EOS | |
1518 | | MY_IDENTIFIER IDENTIFIERTYPE identifierstring | |
1519 | { | |
1520 | if (set_identifier(&cur_rmconf->idv, $2, $3) != 0) { | |
85f41bec | 1521 | racoon_yyerror("failed to set identifer.\n"); |
52b7d2ce A |
1522 | vfree($3); //%%% BUG FIX - memory leak |
1523 | return -1; | |
1524 | } | |
1525 | vfree($3); //%%% BUG FIX - memory leak | |
1526 | cur_rmconf->idvtype = $2; | |
1527 | } | |
1528 | EOS | |
d1e348cf A |
1529 | | MY_IDENTIFIER IDENTIFIERTYPE IDENTIFIERQUAL identifierstring |
1530 | { | |
1531 | if (set_identifier_qual(&cur_rmconf->idv, $2, $4, $3) != 0) { | |
85f41bec | 1532 | racoon_yyerror("failed to set identifer.\n"); |
d1e348cf A |
1533 | return -1; |
1534 | } | |
1535 | cur_rmconf->idvtype = $2; | |
1536 | } | |
1537 | EOS | |
52b7d2ce A |
1538 | | XAUTH_LOGIN identifierstring |
1539 | { | |
1540 | #ifdef ENABLE_HYBRID | |
1541 | /* formerly identifier type login */ | |
d1e348cf | 1542 | if (xauth_rmconf_used(&cur_rmconf->xauth) == -1) { |
85f41bec | 1543 | racoon_yyerror("failed to allocate xauth state\n"); |
d1e348cf A |
1544 | return -1; |
1545 | } | |
1546 | if ((cur_rmconf->xauth->login = vdup($2)) == NULL) { | |
85f41bec | 1547 | racoon_yyerror("failed to set identifer.\n"); |
52b7d2ce A |
1548 | return -1; |
1549 | } | |
d1e348cf | 1550 | vfree($2); //%%% BUG FIX - memory leak |
52b7d2ce | 1551 | #else |
85f41bec | 1552 | racoon_yyerror("racoon not configured with --enable-hybrid"); |
52b7d2ce A |
1553 | #endif |
1554 | } | |
1555 | EOS | |
1556 | | PEERS_IDENTIFIER IDENTIFIERTYPE identifierstring | |
1557 | { | |
1558 | struct idspec *id; | |
1559 | id = newidspec(); | |
1560 | if (id == NULL) { | |
85f41bec | 1561 | racoon_yyerror("failed to allocate idspec"); |
52b7d2ce A |
1562 | return -1; |
1563 | } | |
1564 | if (set_identifier(&id->id, $2, $3) != 0) { | |
85f41bec | 1565 | racoon_yyerror("failed to set identifer.\n"); |
52b7d2ce A |
1566 | racoon_free(id); |
1567 | vfree($3); //%%% BUG FIX - memory leak | |
1568 | return -1; | |
1569 | } | |
1570 | vfree($3); //%%% BUG FIX - memory leak | |
1571 | id->idtype = $2; | |
1572 | genlist_append (cur_rmconf->idvl_p, id); | |
1573 | } | |
1574 | EOS | |
d1e348cf A |
1575 | | PEERS_IDENTIFIER IDENTIFIERTYPE IDENTIFIERQUAL identifierstring |
1576 | { | |
1577 | struct idspec *id; | |
1578 | id = newidspec(); | |
1579 | if (id == NULL) { | |
85f41bec | 1580 | racoon_yyerror("failed to allocate idspec"); |
d1e348cf A |
1581 | return -1; |
1582 | } | |
1583 | if (set_identifier_qual(&id->id, $2, $4, $3) != 0) { | |
85f41bec | 1584 | racoon_yyerror("failed to set identifer.\n"); |
d1e348cf A |
1585 | racoon_free(id); |
1586 | return -1; | |
1587 | } | |
1588 | id->idtype = $2; | |
1589 | genlist_append (cur_rmconf->idvl_p, id); | |
1590 | } | |
1591 | EOS | |
52b7d2ce | 1592 | | VERIFY_IDENTIFIER SWITCH { cur_rmconf->verify_identifier = $2; } EOS |
d9c572c0 A |
1593 | | LOCAL_ADDRESS ADDRSTRING |
1594 | { | |
1595 | struct sockaddr_storage *saddr; | |
1596 | saddr = str2saddr($2->v, NULL); | |
1597 | vfree($2); | |
1598 | if (saddr == NULL) | |
1599 | return -1; | |
1600 | cur_rmconf->forced_local = saddr; | |
1601 | } EOS | |
52b7d2ce A |
1602 | | SHARED_SECRET SECRETTYPE QUOTEDSTRING |
1603 | { | |
52b7d2ce A |
1604 | cur_rmconf->secrettype = $2; |
1605 | cur_rmconf->shared_secret = $3; | |
52b7d2ce A |
1606 | } EOS |
1607 | | SHARED_SECRET SECRETTYPE | |
1608 | { | |
52b7d2ce | 1609 | if ($2 != SECRETTYPE_KEYCHAIN_BY_ID) { |
85f41bec | 1610 | racoon_yyerror("shared secret value missing.\n"); |
52b7d2ce A |
1611 | return -1; |
1612 | } | |
1613 | cur_rmconf->secrettype = $2; | |
52b7d2ce A |
1614 | } EOS |
1615 | | NONCE_SIZE NUMBER { cur_rmconf->nonce_size = $2; } EOS | |
1616 | | DH_GROUP | |
1617 | { | |
85f41bec | 1618 | racoon_yyerror("dh_group cannot be defined here."); |
52b7d2ce A |
1619 | return -1; |
1620 | } | |
1621 | dh_group_num EOS | |
1622 | | PASSIVE SWITCH { cur_rmconf->passive = $2; } EOS | |
1623 | | IKE_FRAG SWITCH { cur_rmconf->ike_frag = $2; } EOS | |
d1e348cf | 1624 | | IKE_FRAG REMOTE_FORCE_LEVEL { cur_rmconf->ike_frag = ISAKMP_FRAG_FORCE; } EOS |
52b7d2ce A |
1625 | | ESP_FRAG NUMBER { |
1626 | #ifdef SADB_X_EXT_NAT_T_FRAG | |
d1e348cf A |
1627 | if (libipsec_opt & LIBIPSEC_OPT_FRAG) |
1628 | cur_rmconf->esp_frag = $2; | |
1629 | else | |
85f41bec | 1630 | racoon_yywarn("libipsec lacks IKE frag support"); |
52b7d2ce | 1631 | #else |
85f41bec | 1632 | racoon_yywarn("Your kernel does not support esp_frag"); |
52b7d2ce A |
1633 | #endif |
1634 | } EOS | |
52b7d2ce | 1635 | | MODE_CFG SWITCH { cur_rmconf->mode_cfg = $2; } EOS |
d1e348cf A |
1636 | | WEAK_PHASE1_CHECK SWITCH { |
1637 | cur_rmconf->weak_phase1_check = $2; | |
1638 | } EOS | |
52b7d2ce | 1639 | | GENERATE_POLICY SWITCH { cur_rmconf->gen_policy = $2; } EOS |
d1e348cf | 1640 | | GENERATE_POLICY GENERATE_LEVEL { cur_rmconf->gen_policy = $2; } EOS |
52b7d2ce A |
1641 | | SUPPORT_PROXY SWITCH { cur_rmconf->support_proxy = $2; } EOS |
1642 | | INITIAL_CONTACT SWITCH { cur_rmconf->ini_contact = $2; } EOS | |
1643 | | NAT_TRAVERSAL SWITCH | |
1644 | { | |
1645 | #ifdef ENABLE_NATT | |
1646 | cur_rmconf->nat_traversal = $2; | |
1647 | #else | |
85f41bec | 1648 | racoon_yyerror("NAT-T support not compiled in."); |
52b7d2ce A |
1649 | #endif |
1650 | } EOS | |
1651 | | NAT_TRAVERSAL NAT_TRAVERSAL_LEVEL | |
1652 | { | |
1653 | #ifdef ENABLE_NATT | |
1654 | cur_rmconf->nat_traversal = $2; | |
1655 | #else | |
85f41bec | 1656 | racoon_yyerror("NAT-T support not compiled in."); |
52b7d2ce A |
1657 | #endif |
1658 | } EOS | |
1659 | | NAT_TRAVERSAL_MULTI_USER SWITCH | |
1660 | { | |
1661 | #ifdef ENABLE_NATT | |
52b7d2ce | 1662 | cur_rmconf->natt_multiple_user = $2; |
52b7d2ce | 1663 | #else |
85f41bec | 1664 | racoon_yyerror("NAT-T support not compiled in."); |
52b7d2ce A |
1665 | #endif |
1666 | } EOS | |
d1e348cf A |
1667 | | NAT_TRAVERSAL_KEEPALIVE SWITCH |
1668 | { | |
1669 | #ifdef ENABLE_NATT | |
d1e348cf | 1670 | cur_rmconf->natt_keepalive = $2; |
d1e348cf | 1671 | #else |
85f41bec | 1672 | racoon_yyerror("NAT-T support not compiled in."); |
d1e348cf A |
1673 | #endif |
1674 | } EOS | |
1675 | | DPD SWITCH | |
52b7d2ce A |
1676 | { |
1677 | #ifdef ENABLE_DPD | |
1678 | cur_rmconf->dpd = $2; | |
1679 | #else | |
85f41bec | 1680 | racoon_yyerror("DPD support not compiled in."); |
52b7d2ce A |
1681 | #endif |
1682 | } EOS | |
1683 | | DPD_DELAY NUMBER | |
1684 | { | |
1685 | #ifdef ENABLE_DPD | |
1686 | cur_rmconf->dpd_interval = $2; | |
1687 | #else | |
85f41bec | 1688 | racoon_yyerror("DPD support not compiled in."); |
52b7d2ce A |
1689 | #endif |
1690 | } | |
1691 | EOS | |
1692 | | DPD_RETRY NUMBER | |
1693 | { | |
1694 | #ifdef ENABLE_DPD | |
1695 | cur_rmconf->dpd_retry = $2; | |
1696 | #else | |
85f41bec | 1697 | racoon_yyerror("DPD support not compiled in."); |
52b7d2ce A |
1698 | #endif |
1699 | } | |
1700 | EOS | |
1701 | | DPD_MAXFAIL NUMBER | |
1702 | { | |
1703 | #ifdef ENABLE_DPD | |
1704 | cur_rmconf->dpd_maxfails = $2; | |
1705 | #else | |
85f41bec | 1706 | racoon_yyerror("DPD support not compiled in."); |
52b7d2ce A |
1707 | #endif |
1708 | } | |
1709 | EOS | |
d1e348cf A |
1710 | | DPD_ALGORITHM dpd_algo_type |
1711 | { | |
1712 | #ifdef ENABLE_DPD | |
1713 | cur_rmconf->dpd_algo = $2; | |
1714 | #else | |
85f41bec | 1715 | racoon_yyerror("DPD support not compiled in."); |
d1e348cf A |
1716 | #endif |
1717 | } | |
1718 | EOS | |
1719 | | DISCONNECT_ON_IDLE IDLE_TIMEOUT NUMBER IDLE_DIRECTION idle_dir_type | |
1720 | { | |
1721 | cur_rmconf->idle_timeout = $3; | |
1722 | cur_rmconf->idle_timeout_dir = $5; | |
1723 | } | |
1724 | EOS | |
52b7d2ce A |
1725 | | LIFETIME LIFETYPE_TIME NUMBER unittype_time |
1726 | { | |
1727 | cur_rmconf->prhead->lifetime = $3 * $4; | |
1728 | } | |
1729 | EOS | |
1730 | | PROPOSAL_CHECK PROPOSAL_CHECK_LEVEL { cur_rmconf->pcheck_level = $2; } EOS | |
1731 | | LIFETIME LIFETYPE_BYTE NUMBER unittype_byte | |
1732 | { | |
1733 | #if 1 | |
65c25746 | 1734 | racoon_yyerror("byte lifetime support is deprecated in Phase 1"); |
52b7d2ce A |
1735 | return -1; |
1736 | #else | |
85f41bec | 1737 | racoon_yywarn("the lifetime of bytes in phase 1 " |
52b7d2ce A |
1738 | "will be ignored at the moment."); |
1739 | cur_rmconf->prhead->lifebyte = fix_lifebyte($3 * $4); | |
1740 | if (cur_rmconf->prhead->lifebyte == 0) | |
1741 | return -1; | |
1742 | #endif | |
1743 | } | |
1744 | EOS | |
1745 | | PROPOSAL | |
1746 | { | |
1747 | struct secprotospec *spspec; | |
1748 | ||
1749 | spspec = newspspec(); | |
1750 | if (spspec == NULL) | |
1751 | return -1; | |
1752 | insspspec(spspec, &cur_rmconf->prhead); | |
1753 | } | |
1754 | BOC isakmpproposal_specs EOC | |
1755 | ; | |
1756 | exchange_types | |
1757 | : /* nothing */ | |
1758 | | exchange_types EXCHANGETYPE | |
1759 | { | |
1760 | struct etypes *new; | |
1761 | new = racoon_malloc(sizeof(struct etypes)); | |
1762 | if (new == NULL) { | |
85f41bec | 1763 | racoon_yyerror("failed to allocate etypes"); |
52b7d2ce A |
1764 | return -1; |
1765 | } | |
1766 | new->type = $2; | |
1767 | new->next = NULL; | |
1768 | if (cur_rmconf->etypes == NULL) | |
1769 | cur_rmconf->etypes = new; | |
1770 | else { | |
1771 | struct etypes *p; | |
1772 | for (p = cur_rmconf->etypes; | |
1773 | p->next != NULL; | |
1774 | p = p->next) | |
1775 | ; | |
1776 | p->next = new; | |
1777 | } | |
1778 | } | |
1779 | ; | |
65c25746 A |
1780 | cert_spec |
1781 | : CERT_X509 IN_KEYCHAIN | |
52b7d2ce | 1782 | { |
52b7d2ce A |
1783 | cur_rmconf->certtype = $1; |
1784 | cur_rmconf->identity_in_keychain = 1; | |
1785 | cur_rmconf->keychainCertRef = NULL; | |
52b7d2ce A |
1786 | } |
1787 | EOS | |
1788 | ; | |
1789 | | CERT_X509 IN_KEYCHAIN QUOTEDSTRING | |
1790 | { | |
52b7d2ce A |
1791 | cur_rmconf->certtype = $1; |
1792 | cur_rmconf->identity_in_keychain = 1; | |
1793 | cur_rmconf->keychainCertRef = $3; | |
52b7d2ce A |
1794 | } |
1795 | EOS | |
1796 | ; | |
52b7d2ce A |
1797 | dh_group_num |
1798 | : ALGORITHMTYPE | |
1799 | { | |
1800 | $$ = algtype2doi(algclass_isakmp_dh, $1); | |
1801 | if ($$ == -1) { | |
85f41bec | 1802 | racoon_yyerror("must be DH group"); |
52b7d2ce A |
1803 | return -1; |
1804 | } | |
65c25746 A |
1805 | switch ($$) |
1806 | { | |
1807 | case OAKLEY_ATTR_GRP_DESC_MODP768: | |
1808 | case OAKLEY_ATTR_GRP_DESC_MODP1024: | |
1809 | case OAKLEY_ATTR_GRP_DESC_MODP1536: | |
1810 | case OAKLEY_ATTR_GRP_DESC_MODP2048: | |
1811 | case OAKLEY_ATTR_GRP_DESC_MODP3072: | |
1812 | case OAKLEY_ATTR_GRP_DESC_MODP4096: | |
1813 | case OAKLEY_ATTR_GRP_DESC_MODP6144: | |
1814 | case OAKLEY_ATTR_GRP_DESC_MODP8192: | |
1815 | break; | |
1816 | default: | |
1817 | racoon_yyerror("Invalid DH group specified"); | |
1818 | return -1; | |
1819 | break; | |
e8d9021d | 1820 | } |
52b7d2ce A |
1821 | } |
1822 | | NUMBER | |
1823 | { | |
1824 | if (ARRAYLEN(num2dhgroup) > $1 && num2dhgroup[$1] != 0) { | |
1825 | $$ = num2dhgroup[$1]; | |
1826 | } else { | |
85f41bec | 1827 | racoon_yyerror("must be DH group"); |
52b7d2ce A |
1828 | $$ = 0; |
1829 | return -1; | |
1830 | } | |
65c25746 A |
1831 | switch ($$) |
1832 | { | |
1833 | case OAKLEY_ATTR_GRP_DESC_MODP768: | |
1834 | case OAKLEY_ATTR_GRP_DESC_MODP1024: | |
1835 | case OAKLEY_ATTR_GRP_DESC_MODP1536: | |
1836 | case OAKLEY_ATTR_GRP_DESC_MODP2048: | |
1837 | case OAKLEY_ATTR_GRP_DESC_MODP3072: | |
1838 | case OAKLEY_ATTR_GRP_DESC_MODP4096: | |
1839 | case OAKLEY_ATTR_GRP_DESC_MODP6144: | |
1840 | case OAKLEY_ATTR_GRP_DESC_MODP8192: | |
1841 | break; | |
1842 | default: | |
1843 | racoon_yyerror("Invalid DH group specified"); | |
1844 | return -1; | |
1845 | break; | |
e8d9021d | 1846 | } |
65c25746 | 1847 | } |
52b7d2ce A |
1848 | ; |
1849 | identifierstring | |
1850 | : /* nothing */ { $$ = NULL; } | |
1851 | | ADDRSTRING { $$ = $1; } | |
1852 | | QUOTEDSTRING { $$ = $1; } | |
1853 | ; | |
1854 | isakmpproposal_specs | |
1855 | : /* nothing */ | |
1856 | | isakmpproposal_specs isakmpproposal_spec | |
1857 | ; | |
1858 | isakmpproposal_spec | |
1859 | : STRENGTH | |
1860 | { | |
85f41bec | 1861 | racoon_yyerror("strength directive is obsoleted."); |
52b7d2ce A |
1862 | } STRENGTHTYPE EOS |
1863 | | LIFETIME LIFETYPE_TIME NUMBER unittype_time | |
1864 | { | |
1865 | cur_rmconf->prhead->spspec->lifetime = $3 * $4; | |
1866 | } | |
1867 | EOS | |
1868 | | LIFETIME LIFETYPE_BYTE NUMBER unittype_byte | |
1869 | { | |
1870 | #if 1 | |
85f41bec | 1871 | racoon_yyerror("byte lifetime support is deprecated"); |
52b7d2ce A |
1872 | return -1; |
1873 | #else | |
1874 | cur_rmconf->prhead->spspec->lifebyte = fix_lifebyte($3 * $4); | |
1875 | if (cur_rmconf->prhead->spspec->lifebyte == 0) | |
1876 | return -1; | |
1877 | #endif | |
1878 | } | |
1879 | EOS | |
1880 | | DH_GROUP dh_group_num | |
1881 | { | |
1882 | cur_rmconf->prhead->spspec->algclass[algclass_isakmp_dh] = $2; | |
1883 | } | |
1884 | EOS | |
1885 | | GSS_ID QUOTEDSTRING | |
1886 | { | |
1887 | if (cur_rmconf->prhead->spspec->vendorid != VENDORID_GSSAPI) { | |
85f41bec | 1888 | racoon_yyerror("wrong Vendor ID for gssapi_id"); |
52b7d2ce A |
1889 | return -1; |
1890 | } | |
d1e348cf A |
1891 | if (cur_rmconf->prhead->spspec->gssid != NULL) |
1892 | racoon_free(cur_rmconf->prhead->spspec->gssid); | |
1893 | cur_rmconf->prhead->spspec->gssid = | |
1894 | racoon_strdup($2->v); | |
1895 | STRDUP_FATAL(cur_rmconf->prhead->spspec->gssid); | |
52b7d2ce A |
1896 | } |
1897 | EOS | |
1898 | | ALGORITHM_CLASS ALGORITHMTYPE keylength | |
1899 | { | |
1900 | int doi; | |
1901 | int defklen; | |
65c25746 A |
1902 | { |
1903 | doi = algtype2doi($1, $2); | |
1904 | if (doi == -1) { | |
1905 | racoon_yyerror("algorithm mismatched 1"); | |
1906 | return -1; | |
1907 | } | |
1908 | } | |
52b7d2ce A |
1909 | |
1910 | switch ($1) { | |
1911 | case algclass_isakmp_enc: | |
1912 | /* reject suppressed algorithms */ | |
52b7d2ce A |
1913 | cur_rmconf->prhead->spspec->algclass[algclass_isakmp_enc] = doi; |
1914 | defklen = default_keylen($1, $2); | |
1915 | if (defklen == 0) { | |
1916 | if ($3) { | |
85f41bec | 1917 | racoon_yyerror("keylen not allowed"); |
52b7d2ce A |
1918 | return -1; |
1919 | } | |
1920 | } else { | |
1921 | if ($3 && check_keylen($1, $2, $3) < 0) { | |
85f41bec | 1922 | racoon_yyerror("invalid keylen %d", $3); |
52b7d2ce A |
1923 | return -1; |
1924 | } | |
1925 | } | |
1926 | if ($3) | |
1927 | cur_rmconf->prhead->spspec->encklen = $3; | |
1928 | else | |
1929 | cur_rmconf->prhead->spspec->encklen = defklen; | |
1930 | break; | |
1931 | case algclass_isakmp_hash: | |
1932 | cur_rmconf->prhead->spspec->algclass[algclass_isakmp_hash] = doi; | |
1933 | break; | |
1934 | case algclass_isakmp_ameth: | |
1935 | cur_rmconf->prhead->spspec->algclass[algclass_isakmp_ameth] = doi; | |
1936 | /* | |
1937 | * We may have to set the Vendor ID for the | |
1938 | * authentication method we're using. | |
1939 | */ | |
1940 | switch ($2) { | |
1941 | case algtype_gssapikrb: | |
1942 | if (cur_rmconf->prhead->spspec->vendorid != | |
1943 | VENDORID_UNKNOWN) { | |
85f41bec | 1944 | racoon_yyerror("Vendor ID mismatch " |
52b7d2ce A |
1945 | "for auth method"); |
1946 | return -1; | |
1947 | } | |
1948 | /* | |
1949 | * For interoperability with Win2k, | |
1950 | * we set the Vendor ID to "GSSAPI". | |
1951 | */ | |
1952 | cur_rmconf->prhead->spspec->vendorid = | |
1953 | VENDORID_GSSAPI; | |
1954 | break; | |
52b7d2ce A |
1955 | default: |
1956 | break; | |
1957 | } | |
1958 | break; | |
1959 | default: | |
85f41bec | 1960 | racoon_yyerror("algorithm mismatched 2"); |
52b7d2ce A |
1961 | return -1; |
1962 | } | |
1963 | } | |
1964 | EOS | |
1965 | ; | |
1966 | ||
1967 | unittype_time | |
1968 | : UNITTYPE_SEC { $$ = 1; } | |
1969 | | UNITTYPE_MIN { $$ = 60; } | |
1970 | | UNITTYPE_HOUR { $$ = (60 * 60); } | |
1971 | ; | |
1972 | unittype_byte | |
1973 | : UNITTYPE_BYTE { $$ = 1; } | |
1974 | | UNITTYPE_KBYTES { $$ = 1024; } | |
1975 | | UNITTYPE_MBYTES { $$ = (1024 * 1024); } | |
1976 | | UNITTYPE_TBYTES { $$ = (1024 * 1024 * 1024); } | |
1977 | ; | |
d1e348cf A |
1978 | dpd_algo_type |
1979 | : DPD_ALGO_TYPE_DEFAULT { $$ = DPD_ALGO_DEFAULT; } | |
1980 | | DPD_ALGO_TYPE_INBOUND { $$ = DPD_ALGO_INBOUND_DETECT; } | |
1981 | | DPD_ALGO_TYPE_BLACKHOLE { $$ = DPD_ALGO_BLACKHOLE_DETECT; } | |
1982 | ; | |
1983 | idle_dir_type | |
1984 | : IDLE_DIRECTION_ANY { $$ = IPSEC_DIR_ANY; } | |
1985 | | IDLE_DIRECTION_IN { $$ = IPSEC_DIR_INBOUND; } | |
1986 | | IDLE_DIRECTION_OUT { $$ = IPSEC_DIR_OUTBOUND; } | |
1987 | ; | |
52b7d2ce A |
1988 | %% |
1989 | ||
1990 | static struct proposalspec * | |
1991 | newprspec() | |
1992 | { | |
1993 | struct proposalspec *new; | |
1994 | ||
1995 | new = racoon_calloc(1, sizeof(*new)); | |
1996 | if (new == NULL) | |
85f41bec | 1997 | racoon_yyerror("failed to allocate proposal"); |
52b7d2ce A |
1998 | |
1999 | return new; | |
2000 | } | |
2001 | ||
2002 | /* | |
2003 | * insert into head of list. | |
2004 | */ | |
2005 | static void | |
2006 | insprspec(prspec, head) | |
2007 | struct proposalspec *prspec; | |
2008 | struct proposalspec **head; | |
2009 | { | |
2010 | if (*head != NULL) | |
2011 | (*head)->prev = prspec; | |
2012 | prspec->next = *head; | |
2013 | *head = prspec; | |
2014 | } | |
2015 | ||
2016 | static struct secprotospec * | |
2017 | newspspec() | |
2018 | { | |
2019 | struct secprotospec *new; | |
2020 | ||
2021 | new = racoon_calloc(1, sizeof(*new)); | |
2022 | if (new == NULL) { | |
85f41bec | 2023 | racoon_yyerror("failed to allocate spproto"); |
52b7d2ce A |
2024 | return NULL; |
2025 | } | |
2026 | ||
2027 | new->encklen = 0; /*XXX*/ | |
2028 | ||
2029 | /* | |
2030 | * Default to "uknown" vendor -- we will override this | |
2031 | * as necessary. When we send a Vendor ID payload, an | |
2032 | * "unknown" will be translated to a KAME/racoon ID. | |
2033 | */ | |
2034 | new->vendorid = VENDORID_UNKNOWN; | |
2035 | ||
2036 | return new; | |
2037 | } | |
2038 | ||
2039 | /* | |
2040 | * insert into head of list. | |
2041 | */ | |
2042 | static void | |
2043 | insspspec(spspec, head) | |
2044 | struct secprotospec *spspec; | |
2045 | struct proposalspec **head; | |
2046 | { | |
2047 | spspec->back = *head; | |
2048 | ||
2049 | if ((*head)->spspec != NULL) | |
2050 | (*head)->spspec->prev = spspec; | |
2051 | spspec->next = (*head)->spspec; | |
2052 | (*head)->spspec = spspec; | |
2053 | } | |
2054 | ||
2055 | /* set final acceptable proposal */ | |
2056 | static int | |
2057 | set_isakmp_proposal(rmconf, prspec) | |
2058 | struct remoteconf *rmconf; | |
2059 | struct proposalspec *prspec; | |
2060 | { | |
2061 | struct proposalspec *p; | |
2062 | struct secprotospec *s; | |
2063 | int prop_no = 1; | |
2064 | int trns_no = 1; | |
2065 | int32_t types[MAXALGCLASS]; | |
2066 | ||
2067 | p = prspec; | |
2068 | if (p->next != 0) { | |
65c25746 | 2069 | plog(ASL_LEVEL_ERR, |
52b7d2ce A |
2070 | "multiple proposal definition.\n"); |
2071 | return -1; | |
2072 | } | |
2073 | ||
2074 | /* mandatory check */ | |
2075 | if (p->spspec == NULL) { | |
85f41bec A |
2076 | racoon_yyerror("no remote specification found: %s.\n", |
2077 | saddr2str((struct sockaddr *)rmconf->remote)); | |
52b7d2ce A |
2078 | return -1; |
2079 | } | |
2080 | for (s = p->spspec; s != NULL; s = s->next) { | |
2081 | /* XXX need more to check */ | |
2082 | if (s->algclass[algclass_isakmp_enc] == 0) { | |
85f41bec | 2083 | racoon_yyerror("encryption algorithm required."); |
52b7d2ce A |
2084 | return -1; |
2085 | } | |
2086 | if (s->algclass[algclass_isakmp_hash] == 0) { | |
65c25746 A |
2087 | racoon_yyerror("hash algorithm required."); |
2088 | return -1; | |
52b7d2ce A |
2089 | } |
2090 | if (s->algclass[algclass_isakmp_dh] == 0) { | |
85f41bec | 2091 | racoon_yyerror("DH group required."); |
52b7d2ce A |
2092 | return -1; |
2093 | } | |
2094 | if (s->algclass[algclass_isakmp_ameth] == 0) { | |
85f41bec | 2095 | racoon_yyerror("authentication method required."); |
52b7d2ce A |
2096 | return -1; |
2097 | } | |
2098 | } | |
2099 | ||
2100 | /* skip to last part */ | |
2101 | for (s = p->spspec; s->next != NULL; s = s->next) | |
2102 | ; | |
2103 | ||
2104 | while (s != NULL) { | |
65c25746 | 2105 | plog(ASL_LEVEL_DEBUG, |
52b7d2ce A |
2106 | "lifetime = %ld\n", (long) |
2107 | (s->lifetime ? s->lifetime : p->lifetime)); | |
65c25746 | 2108 | plog(ASL_LEVEL_DEBUG, |
52b7d2ce A |
2109 | "lifebyte = %d\n", |
2110 | s->lifebyte ? s->lifebyte : p->lifebyte); | |
65c25746 | 2111 | plog(ASL_LEVEL_DEBUG, |
52b7d2ce A |
2112 | "encklen=%d\n", s->encklen); |
2113 | ||
2114 | memset(types, 0, ARRAYLEN(types)); | |
2115 | types[algclass_isakmp_enc] = s->algclass[algclass_isakmp_enc]; | |
65c25746 | 2116 | types[algclass_isakmp_hash] = s->algclass[algclass_isakmp_hash]; |
52b7d2ce A |
2117 | types[algclass_isakmp_dh] = s->algclass[algclass_isakmp_dh]; |
2118 | types[algclass_isakmp_ameth] = | |
2119 | s->algclass[algclass_isakmp_ameth]; | |
2120 | ||
2121 | /* expanding spspec */ | |
2122 | clean_tmpalgtype(); | |
2123 | trns_no = expand_isakmpspec(prop_no, trns_no, types, | |
2124 | algclass_isakmp_enc, algclass_isakmp_ameth + 1, | |
2125 | s->lifetime ? s->lifetime : p->lifetime, | |
2126 | s->lifebyte ? s->lifebyte : p->lifebyte, | |
2127 | s->encklen, s->vendorid, s->gssid, | |
2128 | rmconf); | |
2129 | if (trns_no == -1) { | |
65c25746 | 2130 | plog(ASL_LEVEL_ERR, |
52b7d2ce A |
2131 | "failed to expand isakmp proposal.\n"); |
2132 | return -1; | |
2133 | } | |
2134 | ||
2135 | s = s->prev; | |
2136 | } | |
2137 | ||
2138 | if (rmconf->proposal == NULL) { | |
65c25746 | 2139 | plog(ASL_LEVEL_ERR, |
52b7d2ce A |
2140 | "no proposal found.\n"); |
2141 | return -1; | |
2142 | } | |
2143 | ||
2144 | return 0; | |
2145 | } | |
2146 | ||
2147 | static void | |
2148 | clean_tmpalgtype() | |
2149 | { | |
2150 | int i; | |
2151 | for (i = 0; i < MAXALGCLASS; i++) | |
2152 | tmpalgtype[i] = 0; /* means algorithm undefined. */ | |
2153 | } | |
2154 | ||
2155 | static int | |
2156 | expand_isakmpspec(prop_no, trns_no, types, | |
2157 | class, last, lifetime, lifebyte, encklen, vendorid, gssid, | |
2158 | rmconf) | |
2159 | int prop_no, trns_no; | |
2160 | int *types, class, last; | |
2161 | time_t lifetime; | |
2162 | int lifebyte; | |
2163 | int encklen; | |
2164 | int vendorid; | |
2165 | char *gssid; | |
2166 | struct remoteconf *rmconf; | |
2167 | { | |
2168 | struct isakmpsa *new; | |
2169 | ||
2170 | /* debugging */ | |
2171 | { | |
2172 | int j; | |
2173 | char tb[10]; | |
65c25746 | 2174 | plog(ASL_LEVEL_DEBUG, |
52b7d2ce A |
2175 | "p:%d t:%d\n", prop_no, trns_no); |
2176 | for (j = class; j < MAXALGCLASS; j++) { | |
2177 | snprintf(tb, sizeof(tb), "%d", types[j]); | |
65c25746 | 2178 | plog(ASL_LEVEL_DEBUG, |
52b7d2ce A |
2179 | "%s%s%s%s\n", |
2180 | s_algtype(j, types[j]), | |
2181 | types[j] ? "(" : "", | |
2182 | tb[0] == '0' ? "" : tb, | |
2183 | types[j] ? ")" : ""); | |
2184 | } | |
65c25746 | 2185 | plog(ASL_LEVEL_DEBUG, "\n"); |
52b7d2ce A |
2186 | } |
2187 | ||
2188 | #define TMPALGTYPE2STR(n) \ | |
2189 | s_algtype(algclass_isakmp_##n, types[algclass_isakmp_##n]) | |
2190 | /* check mandatory values */ | |
2191 | if (types[algclass_isakmp_enc] == 0 | |
2192 | || types[algclass_isakmp_ameth] == 0 | |
52b7d2ce | 2193 | || types[algclass_isakmp_dh] == 0) { |
85f41bec | 2194 | racoon_yyerror("few definition of algorithm " |
52b7d2ce A |
2195 | "enc=%s ameth=%s hash=%s dhgroup=%s.\n", |
2196 | TMPALGTYPE2STR(enc), | |
2197 | TMPALGTYPE2STR(ameth), | |
2198 | TMPALGTYPE2STR(hash), | |
2199 | TMPALGTYPE2STR(dh)); | |
2200 | return -1; | |
2201 | } | |
2202 | #undef TMPALGTYPE2STR | |
2203 | ||
2204 | /* set new sa */ | |
2205 | new = newisakmpsa(); | |
2206 | if (new == NULL) { | |
85f41bec | 2207 | racoon_yyerror("failed to allocate isakmp sa"); |
52b7d2ce A |
2208 | return -1; |
2209 | } | |
2210 | new->prop_no = prop_no; | |
2211 | new->trns_no = trns_no++; | |
2212 | new->lifetime = lifetime; | |
2213 | new->lifebyte = lifebyte; | |
2214 | new->enctype = types[algclass_isakmp_enc]; | |
2215 | new->encklen = encklen; | |
2216 | new->authmethod = types[algclass_isakmp_ameth]; | |
65c25746 A |
2217 | new->hashtype = types[algclass_isakmp_hash]; |
2218 | new->prf = types[algclass_isakmp_hash]; | |
52b7d2ce A |
2219 | new->dh_group = types[algclass_isakmp_dh]; |
2220 | new->vendorid = vendorid; | |
52b7d2ce A |
2221 | insisakmpsa(new, rmconf); |
2222 | ||
2223 | return trns_no; | |
2224 | } | |
2225 | ||
2226 | static int | |
85f41bec | 2227 | listen_addr (struct sockaddr_storage *addr, int udp_encap) |
52b7d2ce A |
2228 | { |
2229 | struct myaddrs *p; | |
2230 | ||
2231 | p = newmyaddr(); | |
2232 | if (p == NULL) { | |
85f41bec | 2233 | racoon_yyerror("failed to allocate myaddrs"); |
52b7d2ce A |
2234 | return -1; |
2235 | } | |
2236 | p->addr = addr; | |
2237 | if (p->addr == NULL) { | |
85f41bec | 2238 | racoon_yyerror("failed to copy sockaddr_storage "); |
52b7d2ce A |
2239 | delmyaddr(p); |
2240 | return -1; | |
2241 | } | |
2242 | p->udp_encap = udp_encap; | |
52b7d2ce A |
2243 | /* These need to be initialized for Apple modifications |
2244 | * to open code for isakmp sockets | |
2245 | */ | |
2246 | p->sock = -1; | |
2247 | p->in_use = 1; | |
52b7d2ce A |
2248 | |
2249 | insmyaddr(p, &lcconf->myaddrs); | |
2250 | ||
2251 | lcconf->autograbaddr = 0; | |
2252 | return 0; | |
2253 | } | |
2254 | ||
2255 | #if 0 | |
2256 | /* | |
2257 | * fix lifebyte. | |
2258 | * Must be more than 1024B because its unit is kilobytes. | |
2259 | * That is defined RFC2407. | |
2260 | */ | |
2261 | static int | |
2262 | fix_lifebyte(t) | |
2263 | unsigned long t; | |
2264 | { | |
2265 | if (t < 1024) { | |
85f41bec | 2266 | racoon_yyerror("byte size should be more than 1024B."); |
52b7d2ce A |
2267 | return 0; |
2268 | } | |
2269 | ||
2270 | return(t / 1024); | |
2271 | } | |
2272 | #endif | |
2273 | ||
2274 | int | |
2275 | cfparse() | |
2276 | { | |
2277 | int error; | |
2278 | ||
65c25746 | 2279 | plog(ASL_LEVEL_DEBUG, "===== parsing configuration\n"); |
52b7d2ce A |
2280 | |
2281 | yycf_init_buffer(); | |
2282 | ||
d1e348cf A |
2283 | if (yycf_switch_buffer(lcconf->racoon_conf) != 0) { |
2284 | IPSECCONFIGTRACEREVENT(CONSTSTR(lcconf->racoon_conf), | |
2285 | IPSECCONFIGEVENTCODE_PARSE_ERROR, | |
2286 | CONSTSTR("could not read configuration file"), | |
2287 | CONSTSTR("cfparse: yycf_switch_buffer erred")); | |
65c25746 | 2288 | plog(ASL_LEVEL_ERR, |
d1e348cf A |
2289 | "could not read configuration file \"%s\"\n", |
2290 | lcconf->racoon_conf); | |
52b7d2ce | 2291 | return -1; |
d1e348cf | 2292 | } |
52b7d2ce A |
2293 | |
2294 | error = yyparse(); | |
2295 | if (error != 0) { | |
2296 | if (yyerrorcount) { | |
65c25746 | 2297 | plog(ASL_LEVEL_ERR, |
52b7d2ce A |
2298 | "fatal parse failure (%d errors)\n", |
2299 | yyerrorcount); | |
2300 | } else { | |
65c25746 | 2301 | plog(ASL_LEVEL_ERR, |
52b7d2ce A |
2302 | "fatal parse failure.\n"); |
2303 | } | |
d1e348cf A |
2304 | IPSECCONFIGTRACEREVENT(CONSTSTR(lcconf->racoon_conf), |
2305 | IPSECCONFIGEVENTCODE_PARSE_ERROR, | |
2306 | CONSTSTR("fatal parse failure"), | |
2307 | CONSTSTR("cfparse: yyparse erred")); | |
2308 | yycf_clean_buffer(); | |
52b7d2ce A |
2309 | return -1; |
2310 | } | |
2311 | ||
2312 | if (error == 0 && yyerrorcount) { | |
65c25746 | 2313 | plog(ASL_LEVEL_ERR, |
52b7d2ce A |
2314 | "parse error is nothing, but yyerrorcount is %d.\n", |
2315 | yyerrorcount); | |
d1e348cf A |
2316 | IPSECCONFIGTRACEREVENT(CONSTSTR(lcconf->racoon_conf), |
2317 | IPSECCONFIGEVENTCODE_PARSE_ERROR, | |
2318 | CONSTSTR("ambivalent error code"), | |
2319 | CONSTSTR("cfparse: error == 0 && yerrorcount")); | |
2320 | yycf_clean_buffer(); | |
52b7d2ce A |
2321 | exit(1); |
2322 | } | |
2323 | ||
2324 | yycf_clean_buffer(); | |
2325 | ||
65c25746 | 2326 | plog(ASL_LEVEL_DEBUG, "parse succeeded.\n"); |
52b7d2ce A |
2327 | |
2328 | return 0; | |
2329 | } | |
2330 | ||
2331 | int | |
d1e348cf | 2332 | cfreparse(int sig) |
52b7d2ce | 2333 | { |
65c25746 | 2334 | int result; |
e8d9021d | 2335 | int ignore_estab_or_assert_handles = (sig == SIGUSR1); |
d1e348cf A |
2336 | |
2337 | if (sig >= 0 && sig < NSIG) { | |
65c25746 | 2338 | plog(ASL_LEVEL_DEBUG, "==== Got %s signal - re-parsing configuration.\n", sys_signame[sig]); |
d1e348cf | 2339 | } else { |
65c25746 | 2340 | plog(ASL_LEVEL_ERR, "==== Got Unknown signal - re-parsing configuration.\n"); |
d1e348cf A |
2341 | IPSECCONFIGTRACEREVENT(CONSTSTR("reparse"), |
2342 | IPSECCONFIGEVENTCODE_REPARSE_ERROR, | |
2343 | CONSTSTR("Unknown signal"), | |
2344 | CONSTSTR("cfreparse: triggered by unknown signal")); | |
2345 | } | |
65c25746 | 2346 | plog(ASL_LEVEL_DEBUG, "==== %s sessions.\n", ignore_estab_or_assert_handles? "flush negotiating" : "flush all"); |
d1e348cf | 2347 | |
65c25746 A |
2348 | ike_session_flush_all_phase2(ignore_estab_or_assert_handles); |
2349 | ike_session_flush_all_phase1(ignore_estab_or_assert_handles); | |
52b7d2ce A |
2350 | flushrmconf(); |
2351 | flushsainfo(); | |
52b7d2ce A |
2352 | check_auto_exit(); /* check/change state of auto exit */ |
2353 | clean_tmpalgtype(); | |
65c25746 A |
2354 | savelcconf(); |
2355 | result = cfparse(); | |
2356 | restorelcconf(); | |
2357 | return result; | |
52b7d2ce A |
2358 | } |
2359 | ||
2360 |