1 /* $NetBSD: cfparse.y,v 1.18.4.3 2007/08/01 11:52:19 vanhu Exp $ */
3 /* Id: cfparse.y,v 1.66 2006/08/22 18:17:17 manubsd Exp */
7 * Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002 and 2003 WIDE Project.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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
37 #include <sys/types.h>
38 #include <sys/param.h>
39 #include <sys/queue.h>
40 #include <sys/socket.h>
42 #include <netinet/in.h>
43 #ifdef HAVE_NETINET6_IPSEC
44 # include <netinet6/ipsec.h>
46 # include <netinet/ipsec.h>
50 #include <arpa/inet.h>
73 #include "cfparse_proto.h"
74 #include "cftoken_proto.h"
75 #include "algorithm.h"
76 #include "localconf.h"
81 #include "remoteconf.h"
82 #include "grabmyaddr.h"
83 #include "isakmp_var.h"
86 #include "nattraversal.h"
87 #include "isakmp_frag.h"
91 #include "isakmp_unity.h"
92 #include "isakmp_xauth.h"
93 #include "isakmp_cfg.h"
95 #include "ipsec_doi.h"
101 #include "vendorid.h"
102 #include "ipsecConfigTracer.h"
103 #include "ipsecMessageTracer.h"
106 static int num2dhgroup[] = {
108 OAKLEY_ATTR_GRP_DESC_MODP768,
109 OAKLEY_ATTR_GRP_DESC_MODP1024,
110 OAKLEY_ATTR_GRP_DESC_EC2N155,
111 OAKLEY_ATTR_GRP_DESC_EC2N185,
112 OAKLEY_ATTR_GRP_DESC_MODP1536,
121 OAKLEY_ATTR_GRP_DESC_MODP2048,
122 OAKLEY_ATTR_GRP_DESC_MODP3072,
123 OAKLEY_ATTR_GRP_DESC_MODP4096,
124 OAKLEY_ATTR_GRP_DESC_MODP6144,
125 OAKLEY_ATTR_GRP_DESC_MODP8192
128 struct remote_index_val {
130 struct sockaddr_storage *addr;
133 static struct remoteconf *cur_rmconf;
134 static int tmpalgtype[MAXALGCLASS];
135 static struct sainfo *cur_sainfo;
136 static int cur_algclass;
137 static int oldloglevel = LLV_BASE;
139 static struct proposalspec *newprspec __P((void));
140 static void insprspec __P((struct proposalspec *, struct proposalspec **));
141 static struct secprotospec *newspspec __P((void));
142 static void insspspec __P((struct secprotospec *, struct proposalspec **));
143 static void adminsock_conf __P((vchar_t *, vchar_t *, vchar_t *, int));
145 static int set_isakmp_proposal
146 __P((struct remoteconf *, struct proposalspec *));
147 static void clean_tmpalgtype __P((void));
148 static int expand_isakmpspec __P((int, int, int *,
149 int, int, time_t, int, int, int, char *, struct remoteconf *));
150 static int listen_addr __P((struct sockaddr_storage *addr, int udp_encap));
152 void freeetypes (struct etypes **etypes);
155 static int fix_lifebyte __P((u_long));
162 struct remoteconf *rmconf;
163 struct sockaddr_storage *saddr;
164 struct sainfoalg *alg;
165 struct remote_index_val *rmidx;
169 %token PRIVSEP USER GROUP CHROOT
174 /* self information */
175 %token IDENTIFIER VENDORID
177 %token LOGGING LOGLEV
179 %token PADDING PAD_RANDOMIZE PAD_RANDOMIZELEN PAD_MAXLEN PAD_STRICT PAD_EXCLTAIL
181 %token LISTEN X_ISAKMP X_ISAKMP_NATT X_ADMIN STRICT_ADDRESS ADMINSOCK DISABLED
183 %token MODECFG CFG_NET4 CFG_MASK4 CFG_DNS4 CFG_NBNS4 CFG_DEFAULT_DOMAIN
184 %token CFG_AUTH_SOURCE CFG_AUTH_GROUPS CFG_SYSTEM CFG_RADIUS CFG_PAM CFG_LDAP CFG_LOCAL CFG_NONE
185 %token CFG_GROUP_SOURCE CFG_ACCOUNTING CFG_CONF_SOURCE CFG_MOTD CFG_POOL_SIZE CFG_AUTH_THROTTLE
186 %token CFG_SPLIT_NETWORK CFG_SPLIT_LOCAL CFG_SPLIT_INCLUDE CFG_SPLIT_DNS
187 %token CFG_PFS_GROUP CFG_SAVE_PASSWD
189 %token RETRY RETRY_COUNTER RETRY_INTERVAL RETRY_PERSEND
190 %token RETRY_PHASE1 RETRY_PHASE2 NATT_KA AUTO_EXIT_DELAY
192 %token ALGORITHM_CLASS ALGORITHMTYPE STRENGTHTYPE
196 %token REMOTE ANONYMOUS INHERIT
197 %token EXCHANGE_MODE EXCHANGETYPE DOI DOITYPE SITUATION SITUATIONTYPE
198 %token CERTIFICATE_TYPE CERTTYPE PEERS_CERTFILE CA_TYPE
199 %token VERIFY_CERT SEND_CERT SEND_CR
200 %token IDENTIFIERTYPE IDENTIFIERQUAL MY_IDENTIFIER
201 %token PEERS_IDENTIFIER VERIFY_IDENTIFIER
202 %token SHARED_SECRET SECRETTYPE
203 %token OPEN_DIR_AUTH_GROUP IN_KEYCHAIN
204 %token CERTIFICATE_VERIFICATION VERIFICATION_MODULE VERIFICATION_OPTION
205 %token DNSSEC CERT_X509 CERT_PLAINRSA
206 %token NONCE_SIZE DH_GROUP KEEPALIVE PASSIVE INITIAL_CONTACT
207 %token NAT_TRAVERSAL REMOTE_FORCE_LEVEL NAT_TRAVERSAL_LEVEL NAT_TRAVERSAL_MULTI_USER NAT_TRAVERSAL_KEEPALIVE
208 %token PROPOSAL_CHECK PROPOSAL_CHECK_LEVEL
209 %token GENERATE_POLICY GENERATE_LEVEL SUPPORT_PROXY
211 %token EXEC_PATH EXEC_COMMAND EXEC_SUCCESS EXEC_FAILURE
212 %token GSS_ID GSS_ID_ENC GSS_ID_ENCTYPE
213 %token COMPLEX_BUNDLE
214 %token DPD DPD_DELAY DPD_RETRY DPD_MAXFAIL DPD_ALGORITHM
215 %token DISCONNECT_ON_IDLE IDLE_TIMEOUT IDLE_DIRECTION
216 %token XAUTH_LOGIN WEAK_PHASE1_CHECK
218 %token PREFIX PORT PORTANY UL_PROTO ANY IKE_FRAG ESP_FRAG MODE_CFG
219 %token PFS_GROUP LIFETIME LIFETYPE_TIME LIFETYPE_BYTE STRENGTH REMOTEID
221 %token SCRIPT PHASE1_UP PHASE1_DOWN
223 %token NUMBER SWITCH BOOLEAN
224 %token HEXSTRING QUOTEDSTRING ADDRSTRING ADDRRANGE
225 %token UNITTYPE_BYTE UNITTYPE_KBYTES UNITTYPE_MBYTES UNITTYPE_TBYTES
226 %token UNITTYPE_SEC UNITTYPE_MIN UNITTYPE_HOUR
227 %token EOS BOC EOC COMMA
228 %token DPD_ALGO_TYPE_DEFAULT DPD_ALGO_TYPE_INBOUND DPD_ALGO_TYPE_BLACKHOLE
229 %token IDLE_DIRECTION_IN IDLE_DIRECTION_OUT IDLE_DIRECTION_ANY
231 %type <num> NUMBER BOOLEAN SWITCH keylength
232 %type <num> PATHTYPE IDENTIFIERTYPE IDENTIFIERQUAL LOGLEV GSS_ID_ENCTYPE
233 %type <num> SECRETTYPE
234 %type <num> ALGORITHM_CLASS dh_group_num
235 %type <num> ALGORITHMTYPE STRENGTHTYPE
236 %type <num> PREFIX prefix PORT port ike_port
237 %type <num> ul_proto UL_PROTO
238 %type <num> EXCHANGETYPE DOITYPE SITUATIONTYPE
239 %type <num> CERTTYPE CERT_X509 CERT_PLAINRSA PROPOSAL_CHECK_LEVEL NAT_TRAVERSAL_LEVEL GENERATE_LEVEL
240 %type <num> VERIFICATION_MODULE VERIFICATION_OPTION
241 %type <num> unittype_time unittype_byte
242 %type <val> QUOTEDSTRING HEXSTRING ADDRSTRING ADDRRANGE sainfo_id
243 %type <val> identifierstring
244 %type <saddr> ike_addrinfo_port
245 %type <alg> algorithm
246 %type <num> dpd_algo_type
247 %type <num> idle_dir_type
248 %type <rmidx> remote_index ike_addrinfo_prefix_port
254 | statements statement
261 | identifier_statement
274 : PRIVSEP BOC privsep_stmts EOC
278 | privsep_stmts privsep_stmt
285 if ((pw = getpwnam($2->v)) == NULL) {
286 racoon_yyerror("unknown user \"%s\"", $2->v);
289 lcconf->uid = pw->pw_uid;
292 | USER NUMBER { lcconf->uid = $2; } EOS
297 if ((gr = getgrnam($2->v)) == NULL) {
298 racoon_yyerror("unknown group \"%s\"", $2->v);
301 lcconf->gid = gr->gr_gid;
304 | GROUP NUMBER { lcconf->gid = $2; } EOS
305 | CHROOT QUOTEDSTRING { lcconf->chroot = $2->v; } EOS
310 : PATH PATHTYPE QUOTEDSTRING
312 if ($2 >= LC_PATHTYPE_MAX) {
313 racoon_yyerror("invalid path type %d", $2);
317 /* free old pathinfo */
318 if (lcconf->pathinfo[$2])
319 racoon_free(lcconf->pathinfo[$2]);
321 /* set new pathinfo */
322 lcconf->pathinfo[$2] = racoon_strdup($3->v);
323 STRDUP_FATAL(lcconf->pathinfo[$2]);
331 : COMPLEX_BUNDLE SWITCH { lcconf->complex_bundle = $2; } EOS
336 : INCLUDE QUOTEDSTRING EOS
338 char path[MAXPATHLEN];
340 getpathname(path, sizeof(path),
341 LC_PATHTYPE_INCLUDE, $2->v);
343 if (yycf_switch_buffer(path) != 0)
350 : GSS_ID_ENC GSS_ID_ENCTYPE EOS
352 if ($2 >= LC_GSSENC_MAX) {
353 racoon_yyerror("invalid GSS ID encoding %d", $2);
356 lcconf->gss_id_enc = $2;
360 /* self information */
362 : IDENTIFIER identifier_stmt
367 /*XXX to be deleted */
370 | IDENTIFIERTYPE QUOTEDSTRING
372 /*XXX to be deleted */
373 $2->l--; /* nuke '\0' */
374 lcconf->ident[$1] = $2;
375 if (lcconf->ident[$1] == NULL) {
376 racoon_yyerror("failed to set my ident: %s",
386 : LOGGING log_level EOS
392 * XXX ignore it because this specification
395 racoon_yywarn("see racoon.conf(5), such a log specification will be obsoleted.");
401 * set the loglevel to the value specified
402 * in the configuration file plus the number
403 * of -d options specified on the command line
405 loglevel += $1 - oldloglevel;
412 : PADDING BOC padding_stmts EOC
416 | padding_stmts padding_stmt
419 : PAD_RANDOMIZE SWITCH { lcconf->pad_random = $2; } EOS
420 | PAD_RANDOMIZELEN SWITCH { lcconf->pad_randomlen = $2; } EOS
421 | PAD_MAXLEN NUMBER { lcconf->pad_maxsize = $2; } EOS
422 | PAD_STRICT SWITCH { lcconf->pad_strict = $2; } EOS
423 | PAD_EXCLTAIL SWITCH { lcconf->pad_excltail = $2; } EOS
428 : LISTEN BOC listen_stmts EOC
432 | listen_stmts listen_stmt
435 : X_ISAKMP ike_addrinfo_port
440 | X_ISAKMP_NATT ike_addrinfo_port
445 racoon_yyerror("NAT-T support not compiled in.");
451 racoon_yyerror("admin directive is obsoleted.");
454 | ADMINSOCK QUOTEDSTRING QUOTEDSTRING QUOTEDSTRING NUMBER
456 #ifdef ENABLE_ADMINPORT
457 adminsock_conf($2, $3, $4, $5);
459 racoon_yywarn("admin port support not compiled in");
463 | ADMINSOCK QUOTEDSTRING
465 #ifdef ENABLE_ADMINPORT
466 adminsock_conf($2, NULL, NULL, -1);
468 racoon_yywarn("admin port support not compiled in");
474 #ifdef ENABLE_ADMINPORT
475 adminsock_path = NULL;
477 racoon_yywarn("admin port support not compiled in");
481 | STRICT_ADDRESS { lcconf->strict_address = TRUE; } EOS
484 : ADDRSTRING ike_port
488 snprintf(portbuf, sizeof(portbuf), "%ld", $2);
489 $$ = str2saddr($1->v, portbuf);
495 ike_addrinfo_prefix_port
496 : ADDRSTRING prefix ike_port
499 struct remote_index_val *new;
501 new = racoon_calloc(1, sizeof(*new));
503 racoon_yyerror("failed to allocate remote index struct");
507 snprintf(portbuf, sizeof(portbuf), "%ld", $3);
508 new->addr = str2saddr($1->v, portbuf);
511 racoon_yyerror("failed to allocate sockaddr storage");
519 : /* nothing */ { $$ = PORT_ISAKMP; }
524 : MODECFG BOC modecfg_stmts EOC
528 | modecfg_stmts modecfg_stmt
531 : CFG_NET4 ADDRSTRING
534 if (inet_pton(AF_INET, $2->v,
535 &isakmp_cfg_config.network4) != 1)
536 racoon_yyerror("bad IPv4 network address.");
539 racoon_yyerror("racoon not configured with --enable-hybrid");
543 | CFG_MASK4 ADDRSTRING
546 if (inet_pton(AF_INET, $2->v,
547 &isakmp_cfg_config.netmask4) != 1)
548 racoon_yyerror("bad IPv4 netmask address.");
551 racoon_yyerror("racoon not configured with --enable-hybrid");
555 | CFG_DNS4 addrdnslist
557 | CFG_NBNS4 addrwinslist
559 | CFG_SPLIT_NETWORK CFG_SPLIT_LOCAL splitnetlist
562 isakmp_cfg_config.splitnet_type = UNITY_LOCAL_LAN;
564 racoon_yyerror("racoon not configured with --enable-hybrid");
568 | CFG_SPLIT_NETWORK CFG_SPLIT_INCLUDE splitnetlist
571 isakmp_cfg_config.splitnet_type = UNITY_SPLIT_INCLUDE;
573 racoon_yyerror("racoon not configured with --enable-hybrid");
577 | CFG_SPLIT_DNS splitdnslist
579 #ifndef ENABLE_HYBRID
580 racoon_yyerror("racoon not configured with --enable-hybrid");
584 | CFG_DEFAULT_DOMAIN QUOTEDSTRING
587 strlcpy(&isakmp_cfg_config.default_domain[0],
588 $2->v, sizeof(isakmp_cfg_config.default_domain));
591 racoon_yyerror("racoon not configured with --enable-hybrid");
595 | CFG_AUTH_SOURCE CFG_SYSTEM
598 isakmp_cfg_config.authsource = ISAKMP_CFG_AUTH_SYSTEM;
600 racoon_yyerror("racoon not configured with --enable-hybrid");
604 | CFG_AUTH_SOURCE CFG_RADIUS
607 #ifdef HAVE_LIBRADIUS
608 isakmp_cfg_config.authsource = ISAKMP_CFG_AUTH_RADIUS;
609 #else /* HAVE_LIBRADIUS */
610 racoon_yyerror("racoon not configured with --with-libradius");
611 #endif /* HAVE_LIBRADIUS */
612 #else /* ENABLE_HYBRID */
613 racoon_yyerror("racoon not configured with --enable-hybrid");
614 #endif /* ENABLE_HYBRID */
617 | CFG_AUTH_SOURCE CFG_PAM
621 isakmp_cfg_config.authsource = ISAKMP_CFG_AUTH_PAM;
622 #else /* HAVE_LIBPAM */
623 racoon_yyerror("racoon not configured with --with-libpam");
624 #endif /* HAVE_LIBPAM */
625 #else /* ENABLE_HYBRID */
626 racoon_yyerror("racoon not configured with --enable-hybrid");
627 #endif /* ENABLE_HYBRID */
630 | CFG_AUTH_SOURCE CFG_LDAP
634 isakmp_cfg_config.authsource = ISAKMP_CFG_AUTH_LDAP;
635 #else /* HAVE_LIBLDAP */
636 racoon_yyerror("racoon not configured with --with-libldap");
637 #endif /* HAVE_LIBLDAP */
638 #else /* ENABLE_HYBRID */
639 racoon_yyerror("racoon not configured with --enable-hybrid");
640 #endif /* ENABLE_HYBRID */
643 | CFG_AUTH_GROUPS authgrouplist
645 #ifndef ENABLE_HYBRID
646 racoon_yyerror("racoon not configured with --enable-hybrid");
650 | CFG_GROUP_SOURCE CFG_SYSTEM
653 isakmp_cfg_config.groupsource = ISAKMP_CFG_GROUP_SYSTEM;
655 racoon_yyerror("racoon not configured with --enable-hybrid");
659 | CFG_GROUP_SOURCE CFG_LDAP
663 isakmp_cfg_config.groupsource = ISAKMP_CFG_GROUP_LDAP;
664 #else /* HAVE_LIBLDAP */
665 racoon_yyerror("racoon not configured with --with-libldap");
666 #endif /* HAVE_LIBLDAP */
667 #else /* ENABLE_HYBRID */
668 racoon_yyerror("racoon not configured with --enable-hybrid");
669 #endif /* ENABLE_HYBRID */
672 | CFG_ACCOUNTING CFG_NONE
675 isakmp_cfg_config.accounting = ISAKMP_CFG_ACCT_NONE;
677 racoon_yyerror("racoon not configured with --enable-hybrid");
681 | CFG_ACCOUNTING CFG_SYSTEM
684 isakmp_cfg_config.accounting = ISAKMP_CFG_ACCT_SYSTEM;
686 racoon_yyerror("racoon not configured with --enable-hybrid");
690 | CFG_ACCOUNTING CFG_RADIUS
693 #ifdef HAVE_LIBRADIUS
694 isakmp_cfg_config.accounting = ISAKMP_CFG_ACCT_RADIUS;
695 #else /* HAVE_LIBRADIUS */
696 racoon_yyerror("racoon not configured with --with-libradius");
697 #endif /* HAVE_LIBRADIUS */
698 #else /* ENABLE_HYBRID */
699 racoon_yyerror("racoon not configured with --enable-hybrid");
700 #endif /* ENABLE_HYBRID */
703 | CFG_ACCOUNTING CFG_PAM
707 isakmp_cfg_config.accounting = ISAKMP_CFG_ACCT_PAM;
708 #else /* HAVE_LIBPAM */
709 racoon_yyerror("racoon not configured with --with-libpam");
710 #endif /* HAVE_LIBPAM */
711 #else /* ENABLE_HYBRID */
712 racoon_yyerror("racoon not configured with --enable-hybrid");
713 #endif /* ENABLE_HYBRID */
716 | CFG_POOL_SIZE NUMBER
719 if (isakmp_cfg_resize_pool($2) != 0)
720 racoon_yyerror("cannot allocate memory for pool");
721 #else /* ENABLE_HYBRID */
722 racoon_yyerror("racoon not configured with --enable-hybrid");
723 #endif /* ENABLE_HYBRID */
726 | CFG_PFS_GROUP NUMBER
729 isakmp_cfg_config.pfs_group = $2;
731 if (isakmp_cfg_config.pfs_group != OAKLEY_ATTR_GRP_DESC_MODP1024
732 && isakmp_cfg_config.pfs_group != OAKLEY_ATTR_GRP_DESC_MODP1536) {
733 racoon_yyerror("PFS group must be 2 or 5");
737 #else /* ENABLE_HYBRID */
738 racoon_yyerror("racoon not configured with --enable-hybrid");
739 #endif /* ENABLE_HYBRID */
742 | CFG_SAVE_PASSWD SWITCH
745 isakmp_cfg_config.save_passwd = $2;
746 #else /* ENABLE_HYBRID */
747 racoon_yyerror("racoon not configured with --enable-hybrid");
748 #endif /* ENABLE_HYBRID */
751 | CFG_AUTH_THROTTLE NUMBER
754 isakmp_cfg_config.auth_throttle = $2;
755 #else /* ENABLE_HYBRID */
756 racoon_yyerror("racoon not configured with --enable-hybrid");
757 #endif /* ENABLE_HYBRID */
760 | CFG_CONF_SOURCE CFG_LOCAL
763 isakmp_cfg_config.confsource = ISAKMP_CFG_CONF_LOCAL;
764 #else /* ENABLE_HYBRID */
765 racoon_yyerror("racoon not configured with --enable-hybrid");
766 #endif /* ENABLE_HYBRID */
769 | CFG_CONF_SOURCE CFG_RADIUS
772 #ifdef HAVE_LIBRADIUS
773 isakmp_cfg_config.confsource = ISAKMP_CFG_CONF_RADIUS;
774 #else /* HAVE_LIBRADIUS */
775 racoon_yyerror("racoon not configured with --with-libradius");
776 #endif /* HAVE_LIBRADIUS */
777 #else /* ENABLE_HYBRID */
778 racoon_yyerror("racoon not configured with --enable-hybrid");
779 #endif /* ENABLE_HYBRID */
782 | CFG_CONF_SOURCE CFG_LDAP
786 isakmp_cfg_config.confsource = ISAKMP_CFG_CONF_LDAP;
787 #else /* HAVE_LIBLDAP */
788 racoon_yyerror("racoon not configured with --with-libldap");
789 #endif /* HAVE_LIBLDAP */
790 #else /* ENABLE_HYBRID */
791 racoon_yyerror("racoon not configured with --enable-hybrid");
792 #endif /* ENABLE_HYBRID */
795 | CFG_MOTD QUOTEDSTRING
798 strlcpy(&isakmp_cfg_config.motd[0], $2->v, sizeof(isakmp_cfg_config.motd));
801 racoon_yyerror("racoon not configured with --enable-hybrid");
809 | addrdns COMMA addrdnslist
815 struct isakmp_cfg_config *icc = &isakmp_cfg_config;
817 if (icc->dns4_index > MAXNS)
818 racoon_yyerror("No more than %d DNS", MAXNS);
819 if (inet_pton(AF_INET, $1->v,
820 &icc->dns4[icc->dns4_index++]) != 1)
821 racoon_yyerror("bad IPv4 DNS address.");
825 racoon_yyerror("racoon not configured with --enable-hybrid");
832 | addrwins COMMA addrwinslist
838 struct isakmp_cfg_config *icc = &isakmp_cfg_config;
840 if (icc->nbns4_index > MAXWINS)
841 racoon_yyerror("No more than %d WINS", MAXWINS);
842 if (inet_pton(AF_INET, $1->v,
843 &icc->nbns4[icc->nbns4_index++]) != 1)
844 racoon_yyerror("bad IPv4 WINS address.");
848 racoon_yyerror("racoon not configured with --enable-hybrid");
855 | splitnetlist COMMA splitnet
861 struct isakmp_cfg_config *icc = &isakmp_cfg_config;
862 struct unity_network network;
864 if (inet_pton(AF_INET, $1->v, &network.addr4) != 1)
865 racoon_yyerror("bad IPv4 SPLIT address.");
867 /* Turn $2 (the prefix) into a subnet mask */
868 network.mask4.s_addr = ($2) ? htonl(~((1 << (32 - $2)) - 1)) : 0;
870 /* add the network to our list */
871 if (splitnet_list_add(&icc->splitnet_list, &network,&icc->splitnet_count))
872 racoon_yyerror("Unable to allocate split network");
876 racoon_yyerror("racoon not configured with --enable-hybrid");
883 | authgroup COMMA authgrouplist
889 char * groupname = NULL;
890 char ** grouplist = NULL;
891 struct isakmp_cfg_config *icc = &isakmp_cfg_config;
893 grouplist = racoon_realloc(icc->grouplist,
894 sizeof(char**)*(icc->groupcount+1));
895 if (grouplist == NULL)
896 racoon_yyerror("unable to allocate auth group list");
898 groupname = racoon_malloc($1->l+1);
899 if (groupname == NULL)
900 racoon_yyerror("unable to allocate auth group name");
902 memcpy(groupname,$1->v,$1->l);
904 grouplist[icc->groupcount]=groupname;
905 icc->grouplist = grouplist;
910 racoon_yyerror("racoon not configured with --enable-hybrid");
917 | splitdns COMMA splitdnslist
923 struct isakmp_cfg_config *icc = &isakmp_cfg_config;
925 if (!icc->splitdns_len)
927 icc->splitdns_list = racoon_malloc($1->l);
928 if(icc->splitdns_list == NULL)
929 racoon_yyerror("error allocating splitdns list buffer");
930 memcpy(icc->splitdns_list,$1->v,$1->l);
931 icc->splitdns_len = $1->l;
935 int len = icc->splitdns_len + $1->l + 1;
936 icc->splitdns_list = racoon_realloc(icc->splitdns_list,len);
937 if(icc->splitdns_list == NULL)
938 racoon_yyerror("error allocating splitdns list buffer");
939 icc->splitdns_list[icc->splitdns_len] = ',';
940 memcpy(icc->splitdns_list + icc->splitdns_len + 1, $1->v, $1->l);
941 icc->splitdns_len = len;
945 racoon_yyerror("racoon not configured with --enable-hybrid");
953 : RETRY BOC timer_stmts EOC
957 | timer_stmts timer_stmt
960 : RETRY_COUNTER NUMBER
962 lcconf->retry_counter = $2;
965 | RETRY_INTERVAL NUMBER unittype_time
967 lcconf->retry_interval = $2 * $3;
970 | RETRY_PERSEND NUMBER
972 lcconf->count_persend = $2;
975 | RETRY_PHASE1 NUMBER unittype_time
977 lcconf->retry_checkph1 = $2 * $3;
980 | RETRY_PHASE2 NUMBER unittype_time
982 lcconf->wait_ph2complete = $2 * $3;
985 | AUTO_EXIT_DELAY NUMBER unittype_time
987 lcconf->auto_exit_delay = $2 * $3;
988 lcconf->auto_exit_state |= LC_AUTOEXITSTATE_SET;
992 | NATT_KA NUMBER unittype_time
995 lcconf->natt_ka_interval = $2 * $3;
997 racoon_yyerror("NAT-T support not compiled in.");
1007 cur_sainfo = newsainfo();
1008 if (cur_sainfo == NULL) {
1009 racoon_yyerror("failed to allocate sainfo");
1013 sainfo_name sainfo_param BOC sainfo_specs
1015 struct sainfo *check;
1018 if (cur_sainfo->algs[algclass_ipsec_enc] == 0) {
1019 racoon_yyerror("no encryption algorithm at %s",
1020 sainfo2str(cur_sainfo));
1023 if (cur_sainfo->algs[algclass_ipsec_auth] == 0) {
1024 racoon_yyerror("no authentication algorithm at %s",
1025 sainfo2str(cur_sainfo));
1028 if (cur_sainfo->algs[algclass_ipsec_comp] == 0) {
1029 racoon_yyerror("no compression algorithm at %s",
1030 sainfo2str(cur_sainfo));
1034 /* duplicate check */
1035 check = getsainfo(cur_sainfo->idsrc,
1037 cur_sainfo->id_i, 0);
1038 if (check && (!check->idsrc && !cur_sainfo->idsrc)) {
1039 racoon_yyerror("duplicated sainfo: %s",
1040 sainfo2str(cur_sainfo));
1043 inssainfo(cur_sainfo);
1050 cur_sainfo->idsrc = NULL;
1051 cur_sainfo->iddst = NULL;
1053 | ANONYMOUS sainfo_id
1055 cur_sainfo->idsrc = NULL;
1056 cur_sainfo->iddst = $2;
1058 | sainfo_id ANONYMOUS
1060 cur_sainfo->idsrc = $1;
1061 cur_sainfo->iddst = NULL;
1063 | sainfo_id sainfo_id
1065 cur_sainfo->idsrc = $1;
1066 cur_sainfo->iddst = $2;
1070 : IDENTIFIERTYPE ADDRSTRING prefix port ul_proto
1073 struct sockaddr_storage *saddr;
1075 if (($5 == IPPROTO_ICMP || $5 == IPPROTO_ICMPV6)
1076 && ($4 != IPSEC_PORT_ANY || $4 != IPSEC_PORT_ANY)) {
1077 racoon_yyerror("port number must be \"any\".");
1081 snprintf(portbuf, sizeof(portbuf), "%lu", $4);
1082 saddr = str2saddr($2->v, portbuf);
1087 switch (saddr->ss_family) {
1089 if ($5 == IPPROTO_ICMPV6) {
1090 racoon_yyerror("upper layer protocol mismatched.\n");
1094 $$ = ipsecdoi_sockaddr2id(saddr,
1095 $3 == ~0 ? (sizeof(struct in_addr) << 3): $3,
1100 if ($5 == IPPROTO_ICMP) {
1101 racoon_yyerror("upper layer protocol mismatched.\n");
1105 $$ = ipsecdoi_sockaddr2id(saddr,
1106 $3 == ~0 ? (sizeof(struct in6_addr) << 3): $3,
1111 racoon_yyerror("invalid family: %d", saddr->ss_family);
1119 | IDENTIFIERTYPE ADDRSTRING ADDRRANGE prefix port ul_proto
1122 struct sockaddr_storage *laddr = NULL, *haddr = NULL;
1124 if (($6 == IPPROTO_ICMP || $6 == IPPROTO_ICMPV6)
1125 && ($5 != IPSEC_PORT_ANY || $5 != IPSEC_PORT_ANY)) {
1126 racoon_yyerror("port number must be \"any\".");
1130 snprintf(portbuf, sizeof(portbuf), "%lu", $5);
1132 laddr = str2saddr($2->v, portbuf);
1133 if (laddr == NULL) {
1137 haddr = str2saddr($3->v, portbuf);
1138 if (haddr == NULL) {
1144 switch (laddr->ss_family) {
1146 if ($6 == IPPROTO_ICMPV6) {
1147 racoon_yyerror("upper layer protocol mismatched.\n");
1154 $$ = ipsecdoi_sockrange2id(laddr, haddr,
1159 if ($6 == IPPROTO_ICMP) {
1160 racoon_yyerror("upper layer protocol mismatched.\n");
1167 $$ = ipsecdoi_sockrange2id(laddr, haddr,
1172 racoon_yyerror("invalid family: %d", laddr->ss_family);
1183 | IDENTIFIERTYPE QUOTEDSTRING
1185 struct ipsecdoi_id_b *id_b;
1187 if ($1 == IDTYPE_ASN1DN) {
1188 racoon_yyerror("id type forbidden: %d", $1);
1195 $$ = vmalloc(sizeof(*id_b) + $2->l);
1197 racoon_yyerror("failed to allocate identifier");
1201 id_b = ALIGNED_CAST(struct ipsecdoi_id_b *)$$->v;
1202 id_b->type = idtype2doi($1);
1207 memcpy($$->v + sizeof(*id_b), $2->v, $2->l);
1213 cur_sainfo->id_i = NULL;
1216 | FROM IDENTIFIERTYPE identifierstring
1218 struct ipsecdoi_id_b *id_b;
1221 if (set_identifier(&idv, $2, $3) != 0) {
1222 racoon_yyerror("failed to set identifer.\n");
1225 cur_sainfo->id_i = vmalloc(sizeof(*id_b) + idv->l);
1226 if (cur_sainfo->id_i == NULL) {
1227 racoon_yyerror("failed to allocate identifier");
1231 id_b = ALIGNED_CAST(struct ipsecdoi_id_b *)cur_sainfo->id_i->v;
1232 id_b->type = idtype2doi($2);
1237 memcpy(cur_sainfo->id_i->v + sizeof(*id_b),
1241 | GROUP QUOTEDSTRING
1243 #ifdef ENABLE_HYBRID
1244 if ((cur_sainfo->group = vdup($2)) == NULL) {
1245 racoon_yyerror("failed to set sainfo xauth group.\n");
1249 racoon_yyerror("racoon not configured with --enable-hybrid");
1256 | sainfo_specs sainfo_spec
1259 : PFS_GROUP dh_group_num
1261 cur_sainfo->pfs_group = $2;
1262 #ifndef HAVE_OPENSSL
1263 if (cur_sainfo->pfs_group != OAKLEY_ATTR_GRP_DESC_MODP1024
1264 && cur_sainfo->pfs_group != OAKLEY_ATTR_GRP_DESC_MODP1536) {
1265 racoon_yyerror("PFS group must be 2 or 5");
1271 | LIFETIME LIFETYPE_TIME NUMBER unittype_time
1273 cur_sainfo->lifetime = $3 * $4;
1276 | LIFETIME LIFETYPE_BYTE NUMBER unittype_byte
1279 racoon_yyerror("byte lifetime support is deprecated");
1282 cur_sainfo->lifebyte = fix_lifebyte($3 * $4);
1283 if (cur_sainfo->lifebyte == 0)
1292 | IDENTIFIER IDENTIFIERTYPE
1294 racoon_yyerror("it's deprecated to specify a identifier in phase 2");
1297 | MY_IDENTIFIER IDENTIFIERTYPE QUOTEDSTRING
1299 racoon_yyerror("it's deprecated to specify a identifier in phase 2");
1307 inssainfoalg(&cur_sainfo->algs[cur_algclass], $1);
1311 inssainfoalg(&cur_sainfo->algs[cur_algclass], $1);
1316 : ALGORITHMTYPE keylength
1320 $$ = newsainfoalg();
1322 racoon_yyerror("failed to get algorithm allocation");
1326 $$->alg = algtype2doi(cur_algclass, $1);
1327 if ($$->alg == -1) {
1328 racoon_yyerror("algorithm mismatched");
1334 defklen = default_keylen(cur_algclass, $1);
1337 racoon_yyerror("keylen not allowed");
1343 if ($2 && check_keylen(cur_algclass, $1, $2) < 0) {
1344 racoon_yyerror("invalid keylen %d", $2);
1354 $$->encklen = defklen;
1356 /* check if it's supported algorithm by kernel */
1357 if (!(cur_algclass == algclass_ipsec_auth && $1 == algtype_non_auth)
1358 && pk_checkalg(cur_algclass, $1, $$->encklen)) {
1359 int a = algclass2doi(cur_algclass);
1360 int b = algtype2doi(cur_algclass, $1);
1361 if (a == IPSECDOI_ATTR_AUTH)
1362 a = IPSECDOI_PROTO_IPSEC_AH;
1363 racoon_yyerror("algorithm %s not supported by the kernel (missing module?)",
1364 s_ipsecdoi_trns(a, b));
1372 : /* nothing */ { $$ = ~0; }
1373 | PREFIX { $$ = $1; }
1376 : /* nothing */ { $$ = IPSEC_PORT_ANY; }
1378 | PORTANY { $$ = IPSEC_PORT_ANY; }
1381 : NUMBER { $$ = $1; }
1382 | UL_PROTO { $$ = $1; }
1383 | ANY { $$ = IPSEC_ULPROTO_ANY; }
1386 : /* nothing */ { $$ = 0; }
1387 | NUMBER { $$ = $1; }
1392 : REMOTE remote_index INHERIT remote_index
1394 struct remoteconf *new;
1395 struct proposalspec *prspec;
1397 new = copyrmconf($4->addr);
1399 racoon_yyerror("failed to get remoteconf for %s.", saddr2str((struct sockaddr *)$4));
1400 racoon_free($2->addr);
1402 racoon_free($4->addr);
1407 new->remote = $2->addr;
1408 new->remote_prefix = ($2->prefix == ~0 ? 0 : $2->prefix);
1409 new->inherited_from = getrmconf_strict($4->addr, 1);
1410 new->proposal = NULL;
1414 racoon_free($4->addr);
1417 prspec = newprspec();
1418 if (prspec == NULL || !cur_rmconf->inherited_from
1419 || !cur_rmconf->inherited_from->proposal)
1421 prspec->lifetime = cur_rmconf->inherited_from->proposal->lifetime;
1422 prspec->lifebyte = cur_rmconf->inherited_from->proposal->lifebyte;
1423 insprspec(prspec, &cur_rmconf->prhead);
1426 | REMOTE remote_index
1428 struct remoteconf *new;
1429 struct proposalspec *prspec;
1433 racoon_yyerror("failed to get new remoteconf.");
1434 racoon_free($2->addr);
1438 new->remote = $2->addr;
1439 new->remote_prefix = ($2->prefix == ~0 ? 0 : $2->prefix);
1443 prspec = newprspec();
1446 prspec->lifetime = oakley_get_defaultlifetime();
1447 insprspec(prspec, &cur_rmconf->prhead);
1453 : BOC remote_specs EOC
1455 /* check a exchange mode */
1456 if (cur_rmconf->etypes == NULL) {
1457 racoon_yyerror("no exchange mode specified.\n");
1461 if (cur_rmconf->idvtype == IDTYPE_UNDEFINED)
1462 cur_rmconf->idvtype = IDTYPE_ADDRESS;
1465 if (cur_rmconf->idvtype == IDTYPE_ASN1DN) {
1466 if (cur_rmconf->mycertfile
1467 || cur_rmconf->identity_in_keychain)
1469 if (cur_rmconf->idv)
1470 racoon_yywarn("Both CERT and ASN1 ID "
1471 "are set. Hope this is OK.\n");
1472 /* TODO: Preparse the DN here */
1473 } else if (cur_rmconf->idv) {
1474 /* OK, using asn1dn without X.509. */
1476 racoon_yyerror("ASN1 ID not specified "
1477 "and no CERT defined!\n");
1482 if (cur_rmconf->cert_verification_option == VERIFICATION_OPTION_PEERS_IDENTIFIER) {
1483 struct genlist_entry *gpb;
1484 if (genlist_next(cur_rmconf->idvl_p, &gpb) == NULL) {
1485 racoon_yyerror("peers_identifier required for specified certificate "
1486 "verification option.\n");
1491 if (cur_rmconf->prhead->spspec == NULL
1492 && cur_rmconf->inherited_from
1493 && cur_rmconf->inherited_from->prhead) {
1494 cur_rmconf->prhead->spspec = cur_rmconf->inherited_from->prhead->spspec;
1496 if (set_isakmp_proposal(cur_rmconf, cur_rmconf->prhead) != 0)
1499 /* DH group settting if aggressive mode is there. */
1500 if (check_etypeok(cur_rmconf, ISAKMP_ETYPE_AGG) != NULL) {
1505 for (p = cur_rmconf->proposal; p; p = p->next) {
1506 if (b == 0 || (b && b == p->dh_group)) {
1510 racoon_yyerror("DH group must be equal "
1512 "when aggressive mode is "
1516 cur_rmconf->dh_group = b;
1518 if (cur_rmconf->dh_group == 0) {
1519 racoon_yyerror("DH group must be set in the proposal.\n");
1523 /* DH group settting if PFS is required. */
1524 if (oakley_setdhgroup(cur_rmconf->dh_group,
1525 &cur_rmconf->dhgrp) < 0) {
1526 racoon_yyerror("failed to set DH value.\n");
1531 insrmconf(cur_rmconf);
1535 : ANONYMOUS ike_port
1538 struct remote_index_val *new;
1540 new = racoon_calloc(1, sizeof(*new));
1542 racoon_yyerror("failed to allocate remote index struct");
1545 new->addr = newsaddr(sizeof(struct sockaddr_storage));
1546 if (new->addr == NULL) {
1547 racoon_yyerror("failed to allocate sockaddr storage");
1551 new->addr->ss_family = AF_UNSPEC;
1552 (ALIGNED_CAST(struct sockaddr_in *)new->addr)->sin_port = htons($2);
1556 | ike_addrinfo_prefix_port
1560 racoon_yyerror("failed to allocate sockaddr_storage");
1567 | remote_specs remote_spec
1572 cur_rmconf->etypes = NULL;
1575 | DOI DOITYPE { cur_rmconf->doitype = $2; } EOS
1576 | SITUATION SITUATIONTYPE { cur_rmconf->sittype = $2; } EOS
1577 | CERTIFICATE_TYPE cert_spec
1578 | PEERS_CERTFILE QUOTEDSTRING
1581 racoon_yywarn("This directive without certtype will be removed!\n");
1582 racoon_yywarn("Please use 'peers_certfile x509 \"%s\";' instead\n", $2->v);
1583 cur_rmconf->getcert_method = ISAKMP_GETCERT_LOCALFILE;
1585 if (cur_rmconf->peerscertfile != NULL)
1586 racoon_free(cur_rmconf->peerscertfile);
1587 cur_rmconf->peerscertfile = racoon_strdup($2->v);
1588 STRDUP_FATAL(cur_rmconf->peerscertfile);
1591 racoon_yyerror("cert files not supported.\n");
1596 | CA_TYPE CERT_X509 QUOTEDSTRING
1599 cur_rmconf->cacerttype = $2;
1600 cur_rmconf->getcacert_method = ISAKMP_GETCERT_LOCALFILE;
1601 if (cur_rmconf->cacertfile != NULL)
1602 racoon_free(cur_rmconf->cacertfile);
1603 cur_rmconf->cacertfile = racoon_strdup($3->v);
1604 STRDUP_FATAL(cur_rmconf->cacertfile);
1607 racoon_yyerror("cert files not supported.\n");
1613 | PEERS_CERTFILE CERT_X509 QUOTEDSTRING
1616 cur_rmconf->getcert_method = ISAKMP_GETCERT_LOCALFILE;
1617 if (cur_rmconf->peerscertfile != NULL)
1618 racoon_free(cur_rmconf->peerscertfile);
1619 cur_rmconf->peerscertfile = racoon_strdup($3->v);
1620 STRDUP_FATAL(cur_rmconf->peerscertfile);
1623 racoon_yyerror("cert files not supported.\n");
1629 | PEERS_CERTFILE CERT_PLAINRSA QUOTEDSTRING
1631 racoon_yyerror("plainrsa not supported.\n");
1635 | PEERS_CERTFILE DNSSEC
1637 if (cur_rmconf->getcert_method) {
1638 racoon_yyerror("Different peers_certfile method already defined!\n");
1641 cur_rmconf->getcert_method = ISAKMP_GETCERT_DNS;
1642 cur_rmconf->peerscertfile = NULL;
1645 | VERIFY_CERT SWITCH { cur_rmconf->verify_cert = $2; } EOS
1646 | SEND_CERT SWITCH { cur_rmconf->send_cert = $2; } EOS
1647 | SEND_CR SWITCH { cur_rmconf->send_cr = $2; } EOS
1648 | CERTIFICATE_VERIFICATION VERIFICATION_MODULE
1650 cur_rmconf->cert_verification = $2;
1652 | CERTIFICATE_VERIFICATION VERIFICATION_MODULE VERIFICATION_OPTION
1654 cur_rmconf->cert_verification = $2;
1655 cur_rmconf->cert_verification_option = $3;
1658 | OPEN_DIR_AUTH_GROUP QUOTEDSTRING
1661 cur_rmconf->open_dir_auth_group = $2;
1663 racoon_yyerror("Apple specific features not compiled in.");
1667 | MY_IDENTIFIER IDENTIFIERTYPE identifierstring
1669 if (set_identifier(&cur_rmconf->idv, $2, $3) != 0) {
1670 racoon_yyerror("failed to set identifer.\n");
1671 vfree($3); //%%% BUG FIX - memory leak
1674 vfree($3); //%%% BUG FIX - memory leak
1675 cur_rmconf->idvtype = $2;
1678 | MY_IDENTIFIER IDENTIFIERTYPE IDENTIFIERQUAL identifierstring
1680 if (set_identifier_qual(&cur_rmconf->idv, $2, $4, $3) != 0) {
1681 racoon_yyerror("failed to set identifer.\n");
1684 cur_rmconf->idvtype = $2;
1687 | XAUTH_LOGIN identifierstring
1689 #ifdef ENABLE_HYBRID
1690 /* formerly identifier type login */
1691 if (xauth_rmconf_used(&cur_rmconf->xauth) == -1) {
1692 racoon_yyerror("failed to allocate xauth state\n");
1695 if ((cur_rmconf->xauth->login = vdup($2)) == NULL) {
1696 racoon_yyerror("failed to set identifer.\n");
1699 vfree($2); //%%% BUG FIX - memory leak
1701 racoon_yyerror("racoon not configured with --enable-hybrid");
1705 | PEERS_IDENTIFIER IDENTIFIERTYPE identifierstring
1710 racoon_yyerror("failed to allocate idspec");
1713 if (set_identifier(&id->id, $2, $3) != 0) {
1714 racoon_yyerror("failed to set identifer.\n");
1716 vfree($3); //%%% BUG FIX - memory leak
1719 vfree($3); //%%% BUG FIX - memory leak
1721 genlist_append (cur_rmconf->idvl_p, id);
1724 | PEERS_IDENTIFIER IDENTIFIERTYPE IDENTIFIERQUAL identifierstring
1729 racoon_yyerror("failed to allocate idspec");
1732 if (set_identifier_qual(&id->id, $2, $4, $3) != 0) {
1733 racoon_yyerror("failed to set identifer.\n");
1738 genlist_append (cur_rmconf->idvl_p, id);
1741 | VERIFY_IDENTIFIER SWITCH { cur_rmconf->verify_identifier = $2; } EOS
1742 | SHARED_SECRET SECRETTYPE QUOTEDSTRING
1744 cur_rmconf->secrettype = $2;
1745 cur_rmconf->shared_secret = $3;
1747 | SHARED_SECRET SECRETTYPE
1749 if ($2 != SECRETTYPE_KEYCHAIN_BY_ID) {
1750 racoon_yyerror("shared secret value missing.\n");
1753 cur_rmconf->secrettype = $2;
1755 | NONCE_SIZE NUMBER { cur_rmconf->nonce_size = $2; } EOS
1758 racoon_yyerror("dh_group cannot be defined here.");
1762 | PASSIVE SWITCH { cur_rmconf->passive = $2; } EOS
1763 | IKE_FRAG SWITCH { cur_rmconf->ike_frag = $2; } EOS
1764 | IKE_FRAG REMOTE_FORCE_LEVEL { cur_rmconf->ike_frag = ISAKMP_FRAG_FORCE; } EOS
1766 #ifdef SADB_X_EXT_NAT_T_FRAG
1767 if (libipsec_opt & LIBIPSEC_OPT_FRAG)
1768 cur_rmconf->esp_frag = $2;
1770 racoon_yywarn("libipsec lacks IKE frag support");
1772 racoon_yywarn("Your kernel does not support esp_frag");
1775 | SCRIPT QUOTEDSTRING PHASE1_UP {
1776 if (cur_rmconf->script[SCRIPT_PHASE1_UP] != NULL)
1777 vfree(cur_rmconf->script[SCRIPT_PHASE1_UP]);
1779 cur_rmconf->script[SCRIPT_PHASE1_UP] =
1780 script_path_add(vdup($2));
1782 | SCRIPT QUOTEDSTRING PHASE1_DOWN {
1783 if (cur_rmconf->script[SCRIPT_PHASE1_DOWN] != NULL)
1784 vfree(cur_rmconf->script[SCRIPT_PHASE1_DOWN]);
1786 cur_rmconf->script[SCRIPT_PHASE1_DOWN] =
1787 script_path_add(vdup($2));
1789 | MODE_CFG SWITCH { cur_rmconf->mode_cfg = $2; } EOS
1790 | WEAK_PHASE1_CHECK SWITCH {
1791 cur_rmconf->weak_phase1_check = $2;
1793 | GENERATE_POLICY SWITCH { cur_rmconf->gen_policy = $2; } EOS
1794 | GENERATE_POLICY GENERATE_LEVEL { cur_rmconf->gen_policy = $2; } EOS
1795 | SUPPORT_PROXY SWITCH { cur_rmconf->support_proxy = $2; } EOS
1796 | INITIAL_CONTACT SWITCH { cur_rmconf->ini_contact = $2; } EOS
1797 | NAT_TRAVERSAL SWITCH
1800 cur_rmconf->nat_traversal = $2;
1802 racoon_yyerror("NAT-T support not compiled in.");
1805 | NAT_TRAVERSAL NAT_TRAVERSAL_LEVEL
1808 cur_rmconf->nat_traversal = $2;
1810 racoon_yyerror("NAT-T support not compiled in.");
1813 | NAT_TRAVERSAL_MULTI_USER SWITCH
1816 cur_rmconf->natt_multiple_user = $2;
1818 racoon_yyerror("NAT-T support not compiled in.");
1821 | NAT_TRAVERSAL_KEEPALIVE SWITCH
1824 cur_rmconf->natt_keepalive = $2;
1826 racoon_yyerror("NAT-T support not compiled in.");
1832 cur_rmconf->dpd = $2;
1834 racoon_yyerror("DPD support not compiled in.");
1840 cur_rmconf->dpd_interval = $2;
1842 racoon_yyerror("DPD support not compiled in.");
1849 cur_rmconf->dpd_retry = $2;
1851 racoon_yyerror("DPD support not compiled in.");
1855 | DPD_MAXFAIL NUMBER
1858 cur_rmconf->dpd_maxfails = $2;
1860 racoon_yyerror("DPD support not compiled in.");
1864 | DPD_ALGORITHM dpd_algo_type
1867 cur_rmconf->dpd_algo = $2;
1869 racoon_yyerror("DPD support not compiled in.");
1873 | DISCONNECT_ON_IDLE IDLE_TIMEOUT NUMBER IDLE_DIRECTION idle_dir_type
1875 cur_rmconf->idle_timeout = $3;
1876 cur_rmconf->idle_timeout_dir = $5;
1879 | LIFETIME LIFETYPE_TIME NUMBER unittype_time
1881 cur_rmconf->prhead->lifetime = $3 * $4;
1884 | PROPOSAL_CHECK PROPOSAL_CHECK_LEVEL { cur_rmconf->pcheck_level = $2; } EOS
1885 | LIFETIME LIFETYPE_BYTE NUMBER unittype_byte
1888 racoon_yyerror("byte lifetime support is deprecated in Phase1");
1891 racoon_yywarn("the lifetime of bytes in phase 1 "
1892 "will be ignored at the moment.");
1893 cur_rmconf->prhead->lifebyte = fix_lifebyte($3 * $4);
1894 if (cur_rmconf->prhead->lifebyte == 0)
1901 struct secprotospec *spspec;
1903 spspec = newspspec();
1906 insspspec(spspec, &cur_rmconf->prhead);
1908 BOC isakmpproposal_specs EOC
1912 | exchange_types EXCHANGETYPE
1915 new = racoon_malloc(sizeof(struct etypes));
1917 racoon_yyerror("failed to allocate etypes");
1922 if (cur_rmconf->etypes == NULL)
1923 cur_rmconf->etypes = new;
1926 for (p = cur_rmconf->etypes;
1935 : CERT_X509 QUOTEDSTRING QUOTEDSTRING
1937 cur_rmconf->certtype = $1;
1938 if (cur_rmconf->mycertfile != NULL)
1939 racoon_free(cur_rmconf->mycertfile);
1940 cur_rmconf->mycertfile = racoon_strdup($2->v);
1941 STRDUP_FATAL(cur_rmconf->mycertfile);
1943 if (cur_rmconf->myprivfile != NULL)
1944 racoon_free(cur_rmconf->myprivfile);
1945 cur_rmconf->myprivfile = racoon_strdup($3->v);
1946 STRDUP_FATAL(cur_rmconf->myprivfile);
1950 | CERT_X509 IN_KEYCHAIN
1952 cur_rmconf->certtype = $1;
1953 cur_rmconf->identity_in_keychain = 1;
1954 cur_rmconf->keychainCertRef = NULL;
1958 | CERT_X509 IN_KEYCHAIN QUOTEDSTRING
1960 cur_rmconf->certtype = $1;
1961 cur_rmconf->identity_in_keychain = 1;
1962 cur_rmconf->keychainCertRef = $3;
1966 | CERT_PLAINRSA QUOTEDSTRING
1968 racoon_yyerror("plainrsa not supported.\n");
1976 $$ = algtype2doi(algclass_isakmp_dh, $1);
1978 racoon_yyerror("must be DH group");
1981 #ifndef HAVE_OPENSSL
1982 if ($$ != OAKLEY_ATTR_GRP_DESC_MODP1024 && $$ != OAKLEY_ATTR_GRP_DESC_MODP1536) {
1983 racoon_yyerror("DH group must be 2 or 5");
1990 if (ARRAYLEN(num2dhgroup) > $1 && num2dhgroup[$1] != 0) {
1991 $$ = num2dhgroup[$1];
1993 racoon_yyerror("must be DH group");
1997 #ifndef HAVE_OPENSSL
1998 if ($$ != OAKLEY_ATTR_GRP_DESC_MODP1024 && $$ != OAKLEY_ATTR_GRP_DESC_MODP1536) {
1999 racoon_yyerror("DH group must be 2 or 5");
2006 : /* nothing */ { $$ = NULL; }
2007 | ADDRSTRING { $$ = $1; }
2008 | QUOTEDSTRING { $$ = $1; }
2010 isakmpproposal_specs
2012 | isakmpproposal_specs isakmpproposal_spec
2017 racoon_yyerror("strength directive is obsoleted.");
2019 | LIFETIME LIFETYPE_TIME NUMBER unittype_time
2021 cur_rmconf->prhead->spspec->lifetime = $3 * $4;
2024 | LIFETIME LIFETYPE_BYTE NUMBER unittype_byte
2027 racoon_yyerror("byte lifetime support is deprecated");
2030 cur_rmconf->prhead->spspec->lifebyte = fix_lifebyte($3 * $4);
2031 if (cur_rmconf->prhead->spspec->lifebyte == 0)
2036 | DH_GROUP dh_group_num
2038 cur_rmconf->prhead->spspec->algclass[algclass_isakmp_dh] = $2;
2041 | GSS_ID QUOTEDSTRING
2043 if (cur_rmconf->prhead->spspec->vendorid != VENDORID_GSSAPI) {
2044 racoon_yyerror("wrong Vendor ID for gssapi_id");
2047 if (cur_rmconf->prhead->spspec->gssid != NULL)
2048 racoon_free(cur_rmconf->prhead->spspec->gssid);
2049 cur_rmconf->prhead->spspec->gssid =
2050 racoon_strdup($2->v);
2051 STRDUP_FATAL(cur_rmconf->prhead->spspec->gssid);
2054 | ALGORITHM_CLASS ALGORITHMTYPE keylength
2059 doi = algtype2doi($1, $2);
2061 racoon_yyerror("algorithm mismatched 1");
2066 case algclass_isakmp_enc:
2067 /* reject suppressed algorithms */
2068 cur_rmconf->prhead->spspec->algclass[algclass_isakmp_enc] = doi;
2069 defklen = default_keylen($1, $2);
2072 racoon_yyerror("keylen not allowed");
2076 if ($3 && check_keylen($1, $2, $3) < 0) {
2077 racoon_yyerror("invalid keylen %d", $3);
2082 cur_rmconf->prhead->spspec->encklen = $3;
2084 cur_rmconf->prhead->spspec->encklen = defklen;
2086 case algclass_isakmp_hash:
2087 cur_rmconf->prhead->spspec->algclass[algclass_isakmp_hash] = doi;
2089 case algclass_isakmp_ameth:
2090 cur_rmconf->prhead->spspec->algclass[algclass_isakmp_ameth] = doi;
2092 * We may have to set the Vendor ID for the
2093 * authentication method we're using.
2096 case algtype_gssapikrb:
2097 if (cur_rmconf->prhead->spspec->vendorid !=
2099 racoon_yyerror("Vendor ID mismatch "
2104 * For interoperability with Win2k,
2105 * we set the Vendor ID to "GSSAPI".
2107 cur_rmconf->prhead->spspec->vendorid =
2115 racoon_yyerror("algorithm mismatched 2");
2123 : UNITTYPE_SEC { $$ = 1; }
2124 | UNITTYPE_MIN { $$ = 60; }
2125 | UNITTYPE_HOUR { $$ = (60 * 60); }
2128 : UNITTYPE_BYTE { $$ = 1; }
2129 | UNITTYPE_KBYTES { $$ = 1024; }
2130 | UNITTYPE_MBYTES { $$ = (1024 * 1024); }
2131 | UNITTYPE_TBYTES { $$ = (1024 * 1024 * 1024); }
2134 : DPD_ALGO_TYPE_DEFAULT { $$ = DPD_ALGO_DEFAULT; }
2135 | DPD_ALGO_TYPE_INBOUND { $$ = DPD_ALGO_INBOUND_DETECT; }
2136 | DPD_ALGO_TYPE_BLACKHOLE { $$ = DPD_ALGO_BLACKHOLE_DETECT; }
2139 : IDLE_DIRECTION_ANY { $$ = IPSEC_DIR_ANY; }
2140 | IDLE_DIRECTION_IN { $$ = IPSEC_DIR_INBOUND; }
2141 | IDLE_DIRECTION_OUT { $$ = IPSEC_DIR_OUTBOUND; }
2145 static struct proposalspec *
2148 struct proposalspec *new;
2150 new = racoon_calloc(1, sizeof(*new));
2152 racoon_yyerror("failed to allocate proposal");
2158 * insert into head of list.
2161 insprspec(prspec, head)
2162 struct proposalspec *prspec;
2163 struct proposalspec **head;
2166 (*head)->prev = prspec;
2167 prspec->next = *head;
2171 static struct secprotospec *
2174 struct secprotospec *new;
2176 new = racoon_calloc(1, sizeof(*new));
2178 racoon_yyerror("failed to allocate spproto");
2182 new->encklen = 0; /*XXX*/
2185 * Default to "uknown" vendor -- we will override this
2186 * as necessary. When we send a Vendor ID payload, an
2187 * "unknown" will be translated to a KAME/racoon ID.
2189 new->vendorid = VENDORID_UNKNOWN;
2195 * insert into head of list.
2198 insspspec(spspec, head)
2199 struct secprotospec *spspec;
2200 struct proposalspec **head;
2202 spspec->back = *head;
2204 if ((*head)->spspec != NULL)
2205 (*head)->spspec->prev = spspec;
2206 spspec->next = (*head)->spspec;
2207 (*head)->spspec = spspec;
2210 /* set final acceptable proposal */
2212 set_isakmp_proposal(rmconf, prspec)
2213 struct remoteconf *rmconf;
2214 struct proposalspec *prspec;
2216 struct proposalspec *p;
2217 struct secprotospec *s;
2220 int32_t types[MAXALGCLASS];
2224 plog(LLV_ERROR, LOCATION, NULL,
2225 "multiple proposal definition.\n");
2229 /* mandatory check */
2230 if (p->spspec == NULL) {
2231 racoon_yyerror("no remote specification found: %s.\n",
2232 saddr2str((struct sockaddr *)rmconf->remote));
2235 for (s = p->spspec; s != NULL; s = s->next) {
2236 /* XXX need more to check */
2237 if (s->algclass[algclass_isakmp_enc] == 0) {
2238 racoon_yyerror("encryption algorithm required.");
2241 if (s->algclass[algclass_isakmp_hash] == 0) {
2242 racoon_yyerror("hash algorithm required.");
2245 if (s->algclass[algclass_isakmp_dh] == 0) {
2246 racoon_yyerror("DH group required.");
2249 if (s->algclass[algclass_isakmp_ameth] == 0) {
2250 racoon_yyerror("authentication method required.");
2255 /* skip to last part */
2256 for (s = p->spspec; s->next != NULL; s = s->next)
2260 plog(LLV_DEBUG2, LOCATION, NULL,
2261 "lifetime = %ld\n", (long)
2262 (s->lifetime ? s->lifetime : p->lifetime));
2263 plog(LLV_DEBUG2, LOCATION, NULL,
2265 s->lifebyte ? s->lifebyte : p->lifebyte);
2266 plog(LLV_DEBUG2, LOCATION, NULL,
2267 "encklen=%d\n", s->encklen);
2269 memset(types, 0, ARRAYLEN(types));
2270 types[algclass_isakmp_enc] = s->algclass[algclass_isakmp_enc];
2271 types[algclass_isakmp_hash] = s->algclass[algclass_isakmp_hash];
2272 types[algclass_isakmp_dh] = s->algclass[algclass_isakmp_dh];
2273 types[algclass_isakmp_ameth] =
2274 s->algclass[algclass_isakmp_ameth];
2276 /* expanding spspec */
2278 trns_no = expand_isakmpspec(prop_no, trns_no, types,
2279 algclass_isakmp_enc, algclass_isakmp_ameth + 1,
2280 s->lifetime ? s->lifetime : p->lifetime,
2281 s->lifebyte ? s->lifebyte : p->lifebyte,
2282 s->encklen, s->vendorid, s->gssid,
2284 if (trns_no == -1) {
2285 plog(LLV_ERROR, LOCATION, NULL,
2286 "failed to expand isakmp proposal.\n");
2293 if (rmconf->proposal == NULL) {
2294 plog(LLV_ERROR, LOCATION, NULL,
2295 "no proposal found.\n");
2306 for (i = 0; i < MAXALGCLASS; i++)
2307 tmpalgtype[i] = 0; /* means algorithm undefined. */
2311 expand_isakmpspec(prop_no, trns_no, types,
2312 class, last, lifetime, lifebyte, encklen, vendorid, gssid,
2314 int prop_no, trns_no;
2315 int *types, class, last;
2321 struct remoteconf *rmconf;
2323 struct isakmpsa *new;
2329 plog(LLV_DEBUG2, LOCATION, NULL,
2330 "p:%d t:%d\n", prop_no, trns_no);
2331 for (j = class; j < MAXALGCLASS; j++) {
2332 snprintf(tb, sizeof(tb), "%d", types[j]);
2333 plog(LLV_DEBUG2, LOCATION, NULL,
2335 s_algtype(j, types[j]),
2336 types[j] ? "(" : "",
2337 tb[0] == '0' ? "" : tb,
2338 types[j] ? ")" : "");
2340 plog(LLV_DEBUG2, LOCATION, NULL, "\n");
2343 #define TMPALGTYPE2STR(n) \
2344 s_algtype(algclass_isakmp_##n, types[algclass_isakmp_##n])
2345 /* check mandatory values */
2346 if (types[algclass_isakmp_enc] == 0
2347 || types[algclass_isakmp_ameth] == 0
2348 || types[algclass_isakmp_hash] == 0
2349 || types[algclass_isakmp_dh] == 0) {
2350 racoon_yyerror("few definition of algorithm "
2351 "enc=%s ameth=%s hash=%s dhgroup=%s.\n",
2352 TMPALGTYPE2STR(enc),
2353 TMPALGTYPE2STR(ameth),
2354 TMPALGTYPE2STR(hash),
2355 TMPALGTYPE2STR(dh));
2358 #undef TMPALGTYPE2STR
2361 new = newisakmpsa();
2363 racoon_yyerror("failed to allocate isakmp sa");
2366 new->prop_no = prop_no;
2367 new->trns_no = trns_no++;
2368 new->lifetime = lifetime;
2369 new->lifebyte = lifebyte;
2370 new->enctype = types[algclass_isakmp_enc];
2371 new->encklen = encklen;
2372 new->authmethod = types[algclass_isakmp_ameth];
2373 new->hashtype = types[algclass_isakmp_hash];
2374 new->dh_group = types[algclass_isakmp_dh];
2375 new->vendorid = vendorid;
2377 if (new->authmethod == OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB) {
2378 if (gssid != NULL) {
2379 if ((new->gssid = vmalloc(strlen(gssid))) == NULL) {
2381 racoon_yyerror("failed to allocate gssid");
2384 memcpy(new->gssid->v, gssid, new->gssid->l);
2388 * Allocate the default ID so that it gets put
2389 * into a GSS ID attribute during the Phase 1
2392 new->gssid = gssapi_get_default_gss_id();
2396 insisakmpsa(new, rmconf);
2402 listen_addr (struct sockaddr_storage *addr, int udp_encap)
2408 racoon_yyerror("failed to allocate myaddrs");
2412 if (p->addr == NULL) {
2413 racoon_yyerror("failed to copy sockaddr_storage ");
2417 p->udp_encap = udp_encap;
2418 /* These need to be initialized for Apple modifications
2419 * to open code for isakmp sockets
2424 insmyaddr(p, &lcconf->myaddrs);
2426 lcconf->autograbaddr = 0;
2433 * Must be more than 1024B because its unit is kilobytes.
2434 * That is defined RFC2407.
2441 racoon_yyerror("byte size should be more than 1024B.");
2454 plog(LLV_DEBUG, LOCATION, NULL, "===== parse config\n");
2458 if (yycf_switch_buffer(lcconf->racoon_conf) != 0) {
2459 IPSECCONFIGTRACEREVENT(CONSTSTR(lcconf->racoon_conf),
2460 IPSECCONFIGEVENTCODE_PARSE_ERROR,
2461 CONSTSTR("could not read configuration file"),
2462 CONSTSTR("cfparse: yycf_switch_buffer erred"));
2463 plog(LLV_ERROR, LOCATION, NULL,
2464 "could not read configuration file \"%s\"\n",
2465 lcconf->racoon_conf);
2472 plog(LLV_ERROR, LOCATION, NULL,
2473 "fatal parse failure (%d errors)\n",
2476 plog(LLV_ERROR, LOCATION, NULL,
2477 "fatal parse failure.\n");
2479 IPSECCONFIGTRACEREVENT(CONSTSTR(lcconf->racoon_conf),
2480 IPSECCONFIGEVENTCODE_PARSE_ERROR,
2481 CONSTSTR("fatal parse failure"),
2482 CONSTSTR("cfparse: yyparse erred"));
2483 yycf_clean_buffer();
2487 if (error == 0 && yyerrorcount) {
2488 plog(LLV_ERROR, LOCATION, NULL,
2489 "parse error is nothing, but yyerrorcount is %d.\n",
2491 IPSECCONFIGTRACEREVENT(CONSTSTR(lcconf->racoon_conf),
2492 IPSECCONFIGEVENTCODE_PARSE_ERROR,
2493 CONSTSTR("ambivalent error code"),
2494 CONSTSTR("cfparse: error == 0 && yerrorcount"));
2495 yycf_clean_buffer();
2499 yycf_clean_buffer();
2501 plog(LLV_DEBUG2, LOCATION, NULL, "parse successed.\n");
2509 int ignore_estab_or_assert_handles = (sig == SIGUSR1);
2511 if (sig >= 0 && sig < NSIG) {
2512 plog(LLV_DEBUG, LOCATION, NULL, "==== Got %s signal - re-parsing.\n", sys_signame[sig]);
2514 plog(LLV_ERROR, LOCATION, NULL, "==== Got Unknown signal - re-parsing.\n");
2515 IPSECCONFIGTRACEREVENT(CONSTSTR("reparse"),
2516 IPSECCONFIGEVENTCODE_REPARSE_ERROR,
2517 CONSTSTR("Unknown signal"),
2518 CONSTSTR("cfreparse: triggered by unknown signal"));
2521 flushph2(ignore_estab_or_assert_handles);
2522 flushph1(ignore_estab_or_assert_handles);
2529 check_auto_exit(); /* check/change state of auto exit */
2536 #ifdef ENABLE_ADMINPORT
2538 adminsock_conf(path, owner, group, mode_dec)
2544 struct passwd *pw = NULL;
2545 struct group *gr = NULL;
2551 adminsock_path = path->v;
2557 uid = atoi(owner->v);
2559 if (((pw = getpwnam(owner->v)) == NULL) && !isnum)
2560 racoon_yyerror("User \"%s\" does not exist", owner->v);
2563 adminsock_owner = pw->pw_uid;
2565 adminsock_owner = uid;
2571 gid = atoi(group->v);
2573 if (((gr = getgrnam(group->v)) == NULL) && !isnum)
2574 racoon_yyerror("Group \"%s\" does not exist", group->v);
2577 adminsock_group = gr->gr_gid;
2579 adminsock_group = gid;
2585 racoon_yyerror("Mode 0%03o is invalid", mode_dec);
2586 if (mode_dec >= 400) { mode += 0400; mode_dec -= 400; }
2587 if (mode_dec >= 200) { mode += 0200; mode_dec -= 200; }
2588 if (mode_dec >= 100) { mode += 0200; mode_dec -= 100; }
2591 racoon_yyerror("Mode 0%03o is invalid", mode_dec);
2592 if (mode_dec >= 40) { mode += 040; mode_dec -= 40; }
2593 if (mode_dec >= 20) { mode += 020; mode_dec -= 20; }
2594 if (mode_dec >= 10) { mode += 020; mode_dec -= 10; }
2597 racoon_yyerror("Mode 0%03o is invalid", mode_dec);
2598 if (mode_dec >= 4) { mode += 04; mode_dec -= 4; }
2599 if (mode_dec >= 2) { mode += 02; mode_dec -= 2; }
2600 if (mode_dec >= 1) { mode += 02; mode_dec -= 1; }
2602 adminsock_mode = mode;