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"
90 #include "isakmp_unity.h"
91 #include "isakmp_xauth.h"
92 #include "isakmp_cfg.h"
94 #include "ipsec_doi.h"
100 #include "vendorid.h"
104 #include "ipsecConfigTracer.h"
105 #include "ipsecMessageTracer.h"
108 static int num2dhgroup[] = {
110 OAKLEY_ATTR_GRP_DESC_MODP768,
111 OAKLEY_ATTR_GRP_DESC_MODP1024,
112 OAKLEY_ATTR_GRP_DESC_EC2N155,
113 OAKLEY_ATTR_GRP_DESC_EC2N185,
114 OAKLEY_ATTR_GRP_DESC_MODP1536,
123 OAKLEY_ATTR_GRP_DESC_MODP2048,
124 OAKLEY_ATTR_GRP_DESC_MODP3072,
125 OAKLEY_ATTR_GRP_DESC_MODP4096,
126 OAKLEY_ATTR_GRP_DESC_MODP6144,
127 OAKLEY_ATTR_GRP_DESC_MODP8192
130 static struct remoteconf *cur_rmconf;
131 static int tmpalgtype[MAXALGCLASS];
132 static struct sainfo *cur_sainfo;
133 static int cur_algclass;
134 static int oldloglevel = LLV_BASE;
136 static struct proposalspec *newprspec __P((void));
137 static void insprspec __P((struct proposalspec *, struct proposalspec **));
138 static struct secprotospec *newspspec __P((void));
139 static void insspspec __P((struct secprotospec *, struct proposalspec **));
140 static void adminsock_conf __P((vchar_t *, vchar_t *, vchar_t *, int));
142 static int set_isakmp_proposal
143 __P((struct remoteconf *, struct proposalspec *));
144 static void clean_tmpalgtype __P((void));
145 static int expand_isakmpspec __P((int, int, int *,
146 int, int, time_t, int, int, int, char *, struct remoteconf *));
147 static int listen_addr __P((struct sockaddr *addr, int udp_encap));
149 void freeetypes (struct etypes **etypes);
152 static int fix_lifebyte __P((u_long));
159 struct remoteconf *rmconf;
160 struct sockaddr *saddr;
161 struct sainfoalg *alg;
165 %token PRIVSEP USER GROUP CHROOT
170 /* self information */
171 %token IDENTIFIER VENDORID
173 %token LOGGING LOGLEV
175 %token PADDING PAD_RANDOMIZE PAD_RANDOMIZELEN PAD_MAXLEN PAD_STRICT PAD_EXCLTAIL
177 %token LISTEN X_ISAKMP X_ISAKMP_NATT X_ADMIN STRICT_ADDRESS ADMINSOCK DISABLED
179 %token MODECFG CFG_NET4 CFG_MASK4 CFG_DNS4 CFG_NBNS4 CFG_DEFAULT_DOMAIN
180 %token CFG_AUTH_SOURCE CFG_AUTH_GROUPS CFG_SYSTEM CFG_RADIUS CFG_PAM CFG_LDAP CFG_LOCAL CFG_NONE
181 %token CFG_GROUP_SOURCE CFG_ACCOUNTING CFG_CONF_SOURCE CFG_MOTD CFG_POOL_SIZE CFG_AUTH_THROTTLE
182 %token CFG_SPLIT_NETWORK CFG_SPLIT_LOCAL CFG_SPLIT_INCLUDE CFG_SPLIT_DNS
183 %token CFG_PFS_GROUP CFG_SAVE_PASSWD
185 %token RETRY RETRY_COUNTER RETRY_INTERVAL RETRY_PERSEND
186 %token RETRY_PHASE1 RETRY_PHASE2 NATT_KA AUTO_EXIT_DELAY
188 %token ALGORITHM_CLASS ALGORITHMTYPE STRENGTHTYPE
192 %token REMOTE ANONYMOUS INHERIT
193 %token EXCHANGE_MODE EXCHANGETYPE DOI DOITYPE SITUATION SITUATIONTYPE
194 %token CERTIFICATE_TYPE CERTTYPE PEERS_CERTFILE CA_TYPE
195 %token VERIFY_CERT SEND_CERT SEND_CR
196 %token IDENTIFIERTYPE IDENTIFIERQUAL MY_IDENTIFIER
197 %token PEERS_IDENTIFIER VERIFY_IDENTIFIER
198 %token SHARED_SECRET SECRETTYPE
199 %token OPEN_DIR_AUTH_GROUP IN_KEYCHAIN
200 %token CERTIFICATE_VERIFICATION VERIFICATION_MODULE VERIFICATION_OPTION
201 %token DNSSEC CERT_X509 CERT_PLAINRSA
202 %token NONCE_SIZE DH_GROUP KEEPALIVE PASSIVE INITIAL_CONTACT
203 %token NAT_TRAVERSAL REMOTE_FORCE_LEVEL NAT_TRAVERSAL_LEVEL NAT_TRAVERSAL_MULTI_USER NAT_TRAVERSAL_KEEPALIVE
204 %token PROPOSAL_CHECK PROPOSAL_CHECK_LEVEL
205 %token GENERATE_POLICY GENERATE_LEVEL SUPPORT_PROXY
207 %token EXEC_PATH EXEC_COMMAND EXEC_SUCCESS EXEC_FAILURE
208 %token GSS_ID GSS_ID_ENC GSS_ID_ENCTYPE
209 %token COMPLEX_BUNDLE
210 %token DPD DPD_DELAY DPD_RETRY DPD_MAXFAIL DPD_ALGORITHM
211 %token DISCONNECT_ON_IDLE IDLE_TIMEOUT IDLE_DIRECTION
212 %token XAUTH_LOGIN WEAK_PHASE1_CHECK
214 %token PREFIX PORT PORTANY UL_PROTO ANY IKE_FRAG ESP_FRAG MODE_CFG
215 %token PFS_GROUP LIFETIME LIFETYPE_TIME LIFETYPE_BYTE STRENGTH REMOTEID
217 %token SCRIPT PHASE1_UP PHASE1_DOWN
219 %token NUMBER SWITCH BOOLEAN
220 %token HEXSTRING QUOTEDSTRING ADDRSTRING ADDRRANGE
221 %token UNITTYPE_BYTE UNITTYPE_KBYTES UNITTYPE_MBYTES UNITTYPE_TBYTES
222 %token UNITTYPE_SEC UNITTYPE_MIN UNITTYPE_HOUR
223 %token EOS BOC EOC COMMA
224 %token DPD_ALGO_TYPE_DEFAULT DPD_ALGO_TYPE_INBOUND DPD_ALGO_TYPE_BLACKHOLE
225 %token IDLE_DIRECTION_IN IDLE_DIRECTION_OUT IDLE_DIRECTION_ANY
227 %type <num> NUMBER BOOLEAN SWITCH keylength
228 %type <num> PATHTYPE IDENTIFIERTYPE IDENTIFIERQUAL LOGLEV GSS_ID_ENCTYPE
229 %type <num> SECRETTYPE
230 %type <num> ALGORITHM_CLASS dh_group_num
231 %type <num> ALGORITHMTYPE STRENGTHTYPE
232 %type <num> PREFIX prefix PORT port ike_port
233 %type <num> ul_proto UL_PROTO
234 %type <num> EXCHANGETYPE DOITYPE SITUATIONTYPE
235 %type <num> CERTTYPE CERT_X509 CERT_PLAINRSA PROPOSAL_CHECK_LEVEL NAT_TRAVERSAL_LEVEL GENERATE_LEVEL
236 %type <num> VERIFICATION_MODULE VERIFICATION_OPTION
237 %type <num> unittype_time unittype_byte
238 %type <val> QUOTEDSTRING HEXSTRING ADDRSTRING ADDRRANGE sainfo_id
239 %type <val> identifierstring
240 %type <saddr> remote_index ike_addrinfo_port
241 %type <alg> algorithm
242 %type <num> dpd_algo_type
243 %type <num> idle_dir_type
249 | statements statement
256 | identifier_statement
269 : PRIVSEP BOC privsep_stmts EOC
273 | privsep_stmts privsep_stmt
280 if ((pw = getpwnam($2->v)) == NULL) {
281 yyerror("unknown user \"%s\"", $2->v);
284 lcconf->uid = pw->pw_uid;
287 | USER NUMBER { lcconf->uid = $2; } EOS
292 if ((gr = getgrnam($2->v)) == NULL) {
293 yyerror("unknown group \"%s\"", $2->v);
296 lcconf->gid = gr->gr_gid;
299 | GROUP NUMBER { lcconf->gid = $2; } EOS
300 | CHROOT QUOTEDSTRING { lcconf->chroot = $2->v; } EOS
305 : PATH PATHTYPE QUOTEDSTRING
307 if ($2 >= LC_PATHTYPE_MAX) {
308 yyerror("invalid path type %d", $2);
312 /* free old pathinfo */
313 if (lcconf->pathinfo[$2])
314 racoon_free(lcconf->pathinfo[$2]);
316 /* set new pathinfo */
317 lcconf->pathinfo[$2] = racoon_strdup($3->v);
318 STRDUP_FATAL(lcconf->pathinfo[$2]);
326 : COMPLEX_BUNDLE SWITCH { lcconf->complex_bundle = $2; } EOS
331 : INCLUDE QUOTEDSTRING EOS
333 char path[MAXPATHLEN];
335 getpathname(path, sizeof(path),
336 LC_PATHTYPE_INCLUDE, $2->v);
338 if (yycf_switch_buffer(path) != 0)
345 : GSS_ID_ENC GSS_ID_ENCTYPE EOS
347 if ($2 >= LC_GSSENC_MAX) {
348 yyerror("invalid GSS ID encoding %d", $2);
351 lcconf->gss_id_enc = $2;
355 /* self information */
357 : IDENTIFIER identifier_stmt
362 /*XXX to be deleted */
365 | IDENTIFIERTYPE QUOTEDSTRING
367 /*XXX to be deleted */
368 $2->l--; /* nuke '\0' */
369 lcconf->ident[$1] = $2;
370 if (lcconf->ident[$1] == NULL) {
371 yyerror("failed to set my ident: %s",
381 : LOGGING log_level EOS
387 * XXX ignore it because this specification
390 yywarn("see racoon.conf(5), such a log specification will be obsoleted.");
396 * set the loglevel to the value specified
397 * in the configuration file plus the number
398 * of -d options specified on the command line
400 loglevel += $1 - oldloglevel;
407 : PADDING BOC padding_stmts EOC
411 | padding_stmts padding_stmt
414 : PAD_RANDOMIZE SWITCH { lcconf->pad_random = $2; } EOS
415 | PAD_RANDOMIZELEN SWITCH { lcconf->pad_randomlen = $2; } EOS
416 | PAD_MAXLEN NUMBER { lcconf->pad_maxsize = $2; } EOS
417 | PAD_STRICT SWITCH { lcconf->pad_strict = $2; } EOS
418 | PAD_EXCLTAIL SWITCH { lcconf->pad_excltail = $2; } EOS
423 : LISTEN BOC listen_stmts EOC
427 | listen_stmts listen_stmt
430 : X_ISAKMP ike_addrinfo_port
435 | X_ISAKMP_NATT ike_addrinfo_port
440 yyerror("NAT-T support not compiled in.");
446 yyerror("admin directive is obsoleted.");
449 | ADMINSOCK QUOTEDSTRING QUOTEDSTRING QUOTEDSTRING NUMBER
451 #ifdef ENABLE_ADMINPORT
452 adminsock_conf($2, $3, $4, $5);
454 yywarn("admin port support not compiled in");
458 | ADMINSOCK QUOTEDSTRING
460 #ifdef ENABLE_ADMINPORT
461 adminsock_conf($2, NULL, NULL, -1);
463 yywarn("admin port support not compiled in");
469 #ifdef ENABLE_ADMINPORT
470 adminsock_path = NULL;
472 yywarn("admin port support not compiled in");
476 | STRICT_ADDRESS { lcconf->strict_address = TRUE; } EOS
479 : ADDRSTRING ike_port
483 snprintf(portbuf, sizeof(portbuf), "%ld", $2);
484 $$ = str2saddr($1->v, portbuf);
491 : /* nothing */ { $$ = PORT_ISAKMP; }
496 : MODECFG BOC modecfg_stmts EOC
500 | modecfg_stmts modecfg_stmt
503 : CFG_NET4 ADDRSTRING
506 if (inet_pton(AF_INET, $2->v,
507 &isakmp_cfg_config.network4) != 1)
508 yyerror("bad IPv4 network address.");
511 yyerror("racoon not configured with --enable-hybrid");
515 | CFG_MASK4 ADDRSTRING
518 if (inet_pton(AF_INET, $2->v,
519 &isakmp_cfg_config.netmask4) != 1)
520 yyerror("bad IPv4 netmask address.");
523 yyerror("racoon not configured with --enable-hybrid");
527 | CFG_DNS4 addrdnslist
529 | CFG_NBNS4 addrwinslist
531 | CFG_SPLIT_NETWORK CFG_SPLIT_LOCAL splitnetlist
534 isakmp_cfg_config.splitnet_type = UNITY_LOCAL_LAN;
536 yyerror("racoon not configured with --enable-hybrid");
540 | CFG_SPLIT_NETWORK CFG_SPLIT_INCLUDE splitnetlist
543 isakmp_cfg_config.splitnet_type = UNITY_SPLIT_INCLUDE;
545 yyerror("racoon not configured with --enable-hybrid");
549 | CFG_SPLIT_DNS splitdnslist
551 #ifndef ENABLE_HYBRID
552 yyerror("racoon not configured with --enable-hybrid");
556 | CFG_DEFAULT_DOMAIN QUOTEDSTRING
559 strlcpy(&isakmp_cfg_config.default_domain[0],
560 $2->v, sizeof(isakmp_cfg_config.default_domain));
563 yyerror("racoon not configured with --enable-hybrid");
567 | CFG_AUTH_SOURCE CFG_SYSTEM
570 isakmp_cfg_config.authsource = ISAKMP_CFG_AUTH_SYSTEM;
572 yyerror("racoon not configured with --enable-hybrid");
576 | CFG_AUTH_SOURCE CFG_RADIUS
579 #ifdef HAVE_LIBRADIUS
580 isakmp_cfg_config.authsource = ISAKMP_CFG_AUTH_RADIUS;
581 #else /* HAVE_LIBRADIUS */
582 yyerror("racoon not configured with --with-libradius");
583 #endif /* HAVE_LIBRADIUS */
584 #else /* ENABLE_HYBRID */
585 yyerror("racoon not configured with --enable-hybrid");
586 #endif /* ENABLE_HYBRID */
589 | CFG_AUTH_SOURCE CFG_PAM
593 isakmp_cfg_config.authsource = ISAKMP_CFG_AUTH_PAM;
594 #else /* HAVE_LIBPAM */
595 yyerror("racoon not configured with --with-libpam");
596 #endif /* HAVE_LIBPAM */
597 #else /* ENABLE_HYBRID */
598 yyerror("racoon not configured with --enable-hybrid");
599 #endif /* ENABLE_HYBRID */
602 | CFG_AUTH_SOURCE CFG_LDAP
606 isakmp_cfg_config.authsource = ISAKMP_CFG_AUTH_LDAP;
607 #else /* HAVE_LIBLDAP */
608 yyerror("racoon not configured with --with-libldap");
609 #endif /* HAVE_LIBLDAP */
610 #else /* ENABLE_HYBRID */
611 yyerror("racoon not configured with --enable-hybrid");
612 #endif /* ENABLE_HYBRID */
615 | CFG_AUTH_GROUPS authgrouplist
617 #ifndef ENABLE_HYBRID
618 yyerror("racoon not configured with --enable-hybrid");
622 | CFG_GROUP_SOURCE CFG_SYSTEM
625 isakmp_cfg_config.groupsource = ISAKMP_CFG_GROUP_SYSTEM;
627 yyerror("racoon not configured with --enable-hybrid");
631 | CFG_GROUP_SOURCE CFG_LDAP
635 isakmp_cfg_config.groupsource = ISAKMP_CFG_GROUP_LDAP;
636 #else /* HAVE_LIBLDAP */
637 yyerror("racoon not configured with --with-libldap");
638 #endif /* HAVE_LIBLDAP */
639 #else /* ENABLE_HYBRID */
640 yyerror("racoon not configured with --enable-hybrid");
641 #endif /* ENABLE_HYBRID */
644 | CFG_ACCOUNTING CFG_NONE
647 isakmp_cfg_config.accounting = ISAKMP_CFG_ACCT_NONE;
649 yyerror("racoon not configured with --enable-hybrid");
653 | CFG_ACCOUNTING CFG_SYSTEM
656 isakmp_cfg_config.accounting = ISAKMP_CFG_ACCT_SYSTEM;
658 yyerror("racoon not configured with --enable-hybrid");
662 | CFG_ACCOUNTING CFG_RADIUS
665 #ifdef HAVE_LIBRADIUS
666 isakmp_cfg_config.accounting = ISAKMP_CFG_ACCT_RADIUS;
667 #else /* HAVE_LIBRADIUS */
668 yyerror("racoon not configured with --with-libradius");
669 #endif /* HAVE_LIBRADIUS */
670 #else /* ENABLE_HYBRID */
671 yyerror("racoon not configured with --enable-hybrid");
672 #endif /* ENABLE_HYBRID */
675 | CFG_ACCOUNTING CFG_PAM
679 isakmp_cfg_config.accounting = ISAKMP_CFG_ACCT_PAM;
680 #else /* HAVE_LIBPAM */
681 yyerror("racoon not configured with --with-libpam");
682 #endif /* HAVE_LIBPAM */
683 #else /* ENABLE_HYBRID */
684 yyerror("racoon not configured with --enable-hybrid");
685 #endif /* ENABLE_HYBRID */
688 | CFG_POOL_SIZE NUMBER
691 if (isakmp_cfg_resize_pool($2) != 0)
692 yyerror("cannot allocate memory for pool");
693 #else /* ENABLE_HYBRID */
694 yyerror("racoon not configured with --enable-hybrid");
695 #endif /* ENABLE_HYBRID */
698 | CFG_PFS_GROUP NUMBER
701 isakmp_cfg_config.pfs_group = $2;
703 if (isakmp_cfg_config.pfs_group != OAKLEY_ATTR_GRP_DESC_MODP1024
704 && isakmp_cfg_config.pfs_group != OAKLEY_ATTR_GRP_DESC_MODP1536) {
705 yyerror("PFS group must be 2 or 5");
709 #else /* ENABLE_HYBRID */
710 yyerror("racoon not configured with --enable-hybrid");
711 #endif /* ENABLE_HYBRID */
714 | CFG_SAVE_PASSWD SWITCH
717 isakmp_cfg_config.save_passwd = $2;
718 #else /* ENABLE_HYBRID */
719 yyerror("racoon not configured with --enable-hybrid");
720 #endif /* ENABLE_HYBRID */
723 | CFG_AUTH_THROTTLE NUMBER
726 isakmp_cfg_config.auth_throttle = $2;
727 #else /* ENABLE_HYBRID */
728 yyerror("racoon not configured with --enable-hybrid");
729 #endif /* ENABLE_HYBRID */
732 | CFG_CONF_SOURCE CFG_LOCAL
735 isakmp_cfg_config.confsource = ISAKMP_CFG_CONF_LOCAL;
736 #else /* ENABLE_HYBRID */
737 yyerror("racoon not configured with --enable-hybrid");
738 #endif /* ENABLE_HYBRID */
741 | CFG_CONF_SOURCE CFG_RADIUS
744 #ifdef HAVE_LIBRADIUS
745 isakmp_cfg_config.confsource = ISAKMP_CFG_CONF_RADIUS;
746 #else /* HAVE_LIBRADIUS */
747 yyerror("racoon not configured with --with-libradius");
748 #endif /* HAVE_LIBRADIUS */
749 #else /* ENABLE_HYBRID */
750 yyerror("racoon not configured with --enable-hybrid");
751 #endif /* ENABLE_HYBRID */
754 | CFG_CONF_SOURCE CFG_LDAP
758 isakmp_cfg_config.confsource = ISAKMP_CFG_CONF_LDAP;
759 #else /* HAVE_LIBLDAP */
760 yyerror("racoon not configured with --with-libldap");
761 #endif /* HAVE_LIBLDAP */
762 #else /* ENABLE_HYBRID */
763 yyerror("racoon not configured with --enable-hybrid");
764 #endif /* ENABLE_HYBRID */
767 | CFG_MOTD QUOTEDSTRING
770 strlcpy(&isakmp_cfg_config.motd[0], $2->v, sizeof(isakmp_cfg_config.motd));
773 yyerror("racoon not configured with --enable-hybrid");
781 | addrdns COMMA addrdnslist
787 struct isakmp_cfg_config *icc = &isakmp_cfg_config;
789 if (icc->dns4_index > MAXNS)
790 yyerror("No more than %d DNS", MAXNS);
791 if (inet_pton(AF_INET, $1->v,
792 &icc->dns4[icc->dns4_index++]) != 1)
793 yyerror("bad IPv4 DNS address.");
797 yyerror("racoon not configured with --enable-hybrid");
804 | addrwins COMMA addrwinslist
810 struct isakmp_cfg_config *icc = &isakmp_cfg_config;
812 if (icc->nbns4_index > MAXWINS)
813 yyerror("No more than %d WINS", MAXWINS);
814 if (inet_pton(AF_INET, $1->v,
815 &icc->nbns4[icc->nbns4_index++]) != 1)
816 yyerror("bad IPv4 WINS address.");
820 yyerror("racoon not configured with --enable-hybrid");
827 | splitnetlist COMMA splitnet
833 struct isakmp_cfg_config *icc = &isakmp_cfg_config;
834 struct unity_network network;
836 if (inet_pton(AF_INET, $1->v, &network.addr4) != 1)
837 yyerror("bad IPv4 SPLIT address.");
839 /* Turn $2 (the prefix) into a subnet mask */
840 network.mask4.s_addr = ($2) ? htonl(~((1 << (32 - $2)) - 1)) : 0;
842 /* add the network to our list */
843 if (splitnet_list_add(&icc->splitnet_list, &network,&icc->splitnet_count))
844 yyerror("Unable to allocate split network");
848 yyerror("racoon not configured with --enable-hybrid");
855 | authgroup COMMA authgrouplist
861 char * groupname = NULL;
862 char ** grouplist = NULL;
863 struct isakmp_cfg_config *icc = &isakmp_cfg_config;
865 grouplist = racoon_realloc(icc->grouplist,
866 sizeof(char**)*(icc->groupcount+1));
867 if (grouplist == NULL)
868 yyerror("unable to allocate auth group list");
870 groupname = racoon_malloc($1->l+1);
871 if (groupname == NULL)
872 yyerror("unable to allocate auth group name");
874 memcpy(groupname,$1->v,$1->l);
876 grouplist[icc->groupcount]=groupname;
877 icc->grouplist = grouplist;
882 yyerror("racoon not configured with --enable-hybrid");
889 | splitdns COMMA splitdnslist
895 struct isakmp_cfg_config *icc = &isakmp_cfg_config;
897 if (!icc->splitdns_len)
899 icc->splitdns_list = racoon_malloc($1->l);
900 if(icc->splitdns_list == NULL)
901 yyerror("error allocating splitdns list buffer");
902 memcpy(icc->splitdns_list,$1->v,$1->l);
903 icc->splitdns_len = $1->l;
907 int len = icc->splitdns_len + $1->l + 1;
908 icc->splitdns_list = racoon_realloc(icc->splitdns_list,len);
909 if(icc->splitdns_list == NULL)
910 yyerror("error allocating splitdns list buffer");
911 icc->splitdns_list[icc->splitdns_len] = ',';
912 memcpy(icc->splitdns_list + icc->splitdns_len + 1, $1->v, $1->l);
913 icc->splitdns_len = len;
917 yyerror("racoon not configured with --enable-hybrid");
925 : RETRY BOC timer_stmts EOC
929 | timer_stmts timer_stmt
932 : RETRY_COUNTER NUMBER
934 lcconf->retry_counter = $2;
937 | RETRY_INTERVAL NUMBER unittype_time
939 lcconf->retry_interval = $2 * $3;
942 | RETRY_PERSEND NUMBER
944 lcconf->count_persend = $2;
947 | RETRY_PHASE1 NUMBER unittype_time
949 lcconf->retry_checkph1 = $2 * $3;
952 | RETRY_PHASE2 NUMBER unittype_time
954 lcconf->wait_ph2complete = $2 * $3;
957 | AUTO_EXIT_DELAY NUMBER unittype_time
959 lcconf->auto_exit_delay = $2 * $3;
960 lcconf->auto_exit_state |= LC_AUTOEXITSTATE_SET;
964 | NATT_KA NUMBER unittype_time
967 lcconf->natt_ka_interval = $2 * $3;
969 yyerror("NAT-T support not compiled in.");
979 cur_sainfo = newsainfo();
980 if (cur_sainfo == NULL) {
981 yyerror("failed to allocate sainfo");
985 sainfo_name sainfo_param BOC sainfo_specs
987 struct sainfo *check;
990 if (cur_sainfo->algs[algclass_ipsec_enc] == 0) {
991 yyerror("no encryption algorithm at %s",
992 sainfo2str(cur_sainfo));
995 if (cur_sainfo->algs[algclass_ipsec_auth] == 0) {
996 yyerror("no authentication algorithm at %s",
997 sainfo2str(cur_sainfo));
1000 if (cur_sainfo->algs[algclass_ipsec_comp] == 0) {
1001 yyerror("no compression algorithm at %s",
1002 sainfo2str(cur_sainfo));
1006 /* duplicate check */
1007 check = getsainfo(cur_sainfo->idsrc,
1009 cur_sainfo->id_i, 0);
1010 if (check && (!check->idsrc && !cur_sainfo->idsrc)) {
1011 yyerror("duplicated sainfo: %s",
1012 sainfo2str(cur_sainfo));
1015 inssainfo(cur_sainfo);
1022 cur_sainfo->idsrc = NULL;
1023 cur_sainfo->iddst = NULL;
1025 | ANONYMOUS sainfo_id
1027 cur_sainfo->idsrc = NULL;
1028 cur_sainfo->iddst = $2;
1030 | sainfo_id ANONYMOUS
1032 cur_sainfo->idsrc = $1;
1033 cur_sainfo->iddst = NULL;
1035 | sainfo_id sainfo_id
1037 cur_sainfo->idsrc = $1;
1038 cur_sainfo->iddst = $2;
1042 : IDENTIFIERTYPE ADDRSTRING prefix port ul_proto
1045 struct sockaddr *saddr;
1047 if (($5 == IPPROTO_ICMP || $5 == IPPROTO_ICMPV6)
1048 && ($4 != IPSEC_PORT_ANY || $4 != IPSEC_PORT_ANY)) {
1049 yyerror("port number must be \"any\".");
1053 snprintf(portbuf, sizeof(portbuf), "%lu", $4);
1054 saddr = str2saddr($2->v, portbuf);
1059 switch (saddr->sa_family) {
1061 if ($5 == IPPROTO_ICMPV6) {
1062 yyerror("upper layer protocol mismatched.\n");
1066 $$ = ipsecdoi_sockaddr2id(saddr,
1067 $3 == ~0 ? (sizeof(struct in_addr) << 3): $3,
1072 if ($5 == IPPROTO_ICMP) {
1073 yyerror("upper layer protocol mismatched.\n");
1077 $$ = ipsecdoi_sockaddr2id(saddr,
1078 $3 == ~0 ? (sizeof(struct in6_addr) << 3): $3,
1083 yyerror("invalid family: %d", saddr->sa_family);
1091 | IDENTIFIERTYPE ADDRSTRING ADDRRANGE prefix port ul_proto
1094 struct sockaddr *laddr = NULL, *haddr = NULL;
1097 if (($6 == IPPROTO_ICMP || $6 == IPPROTO_ICMPV6)
1098 && ($5 != IPSEC_PORT_ANY || $5 != IPSEC_PORT_ANY)) {
1099 yyerror("port number must be \"any\".");
1103 snprintf(portbuf, sizeof(portbuf), "%lu", $5);
1105 laddr = str2saddr($2->v, portbuf);
1106 if (laddr == NULL) {
1110 haddr = str2saddr($3->v, portbuf);
1111 if (haddr == NULL) {
1117 switch (laddr->sa_family) {
1119 if ($6 == IPPROTO_ICMPV6) {
1120 yyerror("upper layer protocol mismatched.\n");
1127 $$ = ipsecdoi_sockrange2id(laddr, haddr,
1132 if ($6 == IPPROTO_ICMP) {
1133 yyerror("upper layer protocol mismatched.\n");
1140 $$ = ipsecdoi_sockrange2id(laddr, haddr,
1145 yyerror("invalid family: %d", laddr->sa_family);
1156 | IDENTIFIERTYPE QUOTEDSTRING
1158 struct ipsecdoi_id_b *id_b;
1160 if ($1 == IDTYPE_ASN1DN) {
1161 yyerror("id type forbidden: %d", $1);
1168 $$ = vmalloc(sizeof(*id_b) + $2->l);
1170 yyerror("failed to allocate identifier");
1174 id_b = (struct ipsecdoi_id_b *)$$->v;
1175 id_b->type = idtype2doi($1);
1180 memcpy($$->v + sizeof(*id_b), $2->v, $2->l);
1186 cur_sainfo->id_i = NULL;
1189 | FROM IDENTIFIERTYPE identifierstring
1191 struct ipsecdoi_id_b *id_b;
1194 if (set_identifier(&idv, $2, $3) != 0) {
1195 yyerror("failed to set identifer.\n");
1198 cur_sainfo->id_i = vmalloc(sizeof(*id_b) + idv->l);
1199 if (cur_sainfo->id_i == NULL) {
1200 yyerror("failed to allocate identifier");
1204 id_b = (struct ipsecdoi_id_b *)cur_sainfo->id_i->v;
1205 id_b->type = idtype2doi($2);
1210 memcpy(cur_sainfo->id_i->v + sizeof(*id_b),
1214 | GROUP QUOTEDSTRING
1216 #ifdef ENABLE_HYBRID
1217 if ((cur_sainfo->group = vdup($2)) == NULL) {
1218 yyerror("failed to set sainfo xauth group.\n");
1222 yyerror("racoon not configured with --enable-hybrid");
1229 | sainfo_specs sainfo_spec
1232 : PFS_GROUP dh_group_num
1234 cur_sainfo->pfs_group = $2;
1235 #ifndef HAVE_OPENSSL
1236 if (cur_sainfo->pfs_group != OAKLEY_ATTR_GRP_DESC_MODP1024
1237 && cur_sainfo->pfs_group != OAKLEY_ATTR_GRP_DESC_MODP1536) {
1238 yyerror("PFS group must be 2 or 5");
1244 | LIFETIME LIFETYPE_TIME NUMBER unittype_time
1246 cur_sainfo->lifetime = $3 * $4;
1249 | LIFETIME LIFETYPE_BYTE NUMBER unittype_byte
1252 yyerror("byte lifetime support is deprecated");
1255 cur_sainfo->lifebyte = fix_lifebyte($3 * $4);
1256 if (cur_sainfo->lifebyte == 0)
1265 | IDENTIFIER IDENTIFIERTYPE
1267 yyerror("it's deprecated to specify a identifier in phase 2");
1270 | MY_IDENTIFIER IDENTIFIERTYPE QUOTEDSTRING
1272 yyerror("it's deprecated to specify a identifier in phase 2");
1280 inssainfoalg(&cur_sainfo->algs[cur_algclass], $1);
1284 inssainfoalg(&cur_sainfo->algs[cur_algclass], $1);
1289 : ALGORITHMTYPE keylength
1293 $$ = newsainfoalg();
1295 yyerror("failed to get algorithm allocation");
1299 $$->alg = algtype2doi(cur_algclass, $1);
1300 if ($$->alg == -1) {
1301 yyerror("algorithm mismatched");
1307 defklen = default_keylen(cur_algclass, $1);
1310 yyerror("keylen not allowed");
1316 if ($2 && check_keylen(cur_algclass, $1, $2) < 0) {
1317 yyerror("invalid keylen %d", $2);
1327 $$->encklen = defklen;
1329 /* check if it's supported algorithm by kernel */
1330 if (!(cur_algclass == algclass_ipsec_auth && $1 == algtype_non_auth)
1331 && pk_checkalg(cur_algclass, $1, $$->encklen)) {
1332 int a = algclass2doi(cur_algclass);
1333 int b = algtype2doi(cur_algclass, $1);
1334 if (a == IPSECDOI_ATTR_AUTH)
1335 a = IPSECDOI_PROTO_IPSEC_AH;
1336 yyerror("algorithm %s not supported by the kernel (missing module?)",
1337 s_ipsecdoi_trns(a, b));
1345 : /* nothing */ { $$ = ~0; }
1346 | PREFIX { $$ = $1; }
1349 : /* nothing */ { $$ = IPSEC_PORT_ANY; }
1351 | PORTANY { $$ = IPSEC_PORT_ANY; }
1354 : NUMBER { $$ = $1; }
1355 | UL_PROTO { $$ = $1; }
1356 | ANY { $$ = IPSEC_ULPROTO_ANY; }
1359 : /* nothing */ { $$ = 0; }
1360 | NUMBER { $$ = $1; }
1365 : REMOTE remote_index INHERIT remote_index
1367 struct remoteconf *new;
1368 struct proposalspec *prspec;
1370 new = copyrmconf($4);
1372 yyerror("failed to get remoteconf for %s.", saddr2str ($4));
1377 new->inherited_from = getrmconf_strict($4, 1);
1378 new->proposal = NULL;
1382 prspec = newprspec();
1383 if (prspec == NULL || !cur_rmconf->inherited_from
1384 || !cur_rmconf->inherited_from->proposal)
1386 prspec->lifetime = cur_rmconf->inherited_from->proposal->lifetime;
1387 prspec->lifebyte = cur_rmconf->inherited_from->proposal->lifebyte;
1388 insprspec(prspec, &cur_rmconf->prhead);
1391 | REMOTE remote_index
1393 struct remoteconf *new;
1394 struct proposalspec *prspec;
1398 yyerror("failed to get new remoteconf.");
1405 prspec = newprspec();
1408 prspec->lifetime = oakley_get_defaultlifetime();
1409 insprspec(prspec, &cur_rmconf->prhead);
1415 : BOC remote_specs EOC
1417 /* check a exchange mode */
1418 if (cur_rmconf->etypes == NULL) {
1419 yyerror("no exchange mode specified.\n");
1423 if (cur_rmconf->idvtype == IDTYPE_UNDEFINED)
1424 cur_rmconf->idvtype = IDTYPE_ADDRESS;
1427 if (cur_rmconf->idvtype == IDTYPE_ASN1DN) {
1428 if (cur_rmconf->mycertfile
1429 || cur_rmconf->identity_in_keychain)
1431 if (cur_rmconf->idv)
1432 yywarn("Both CERT and ASN1 ID "
1433 "are set. Hope this is OK.\n");
1434 /* TODO: Preparse the DN here */
1435 } else if (cur_rmconf->idv) {
1436 /* OK, using asn1dn without X.509. */
1438 yyerror("ASN1 ID not specified "
1439 "and no CERT defined!\n");
1444 if (cur_rmconf->cert_verification_option == VERIFICATION_OPTION_PEERS_IDENTIFIER) {
1445 struct genlist_entry *gpb;
1446 if (genlist_next(cur_rmconf->idvl_p, &gpb) == NULL) {
1447 yyerror("peers_identifier required for specified certificate "
1448 "verification option.\n");
1453 if (cur_rmconf->prhead->spspec == NULL
1454 && cur_rmconf->inherited_from
1455 && cur_rmconf->inherited_from->prhead) {
1456 cur_rmconf->prhead->spspec = cur_rmconf->inherited_from->prhead->spspec;
1458 if (set_isakmp_proposal(cur_rmconf, cur_rmconf->prhead) != 0)
1461 /* DH group settting if aggressive mode is there. */
1462 if (check_etypeok(cur_rmconf, ISAKMP_ETYPE_AGG) != NULL) {
1467 for (p = cur_rmconf->proposal; p; p = p->next) {
1468 if (b == 0 || (b && b == p->dh_group)) {
1472 yyerror("DH group must be equal "
1474 "when aggressive mode is "
1478 cur_rmconf->dh_group = b;
1480 if (cur_rmconf->dh_group == 0) {
1481 yyerror("DH group must be set in the proposal.\n");
1485 /* DH group settting if PFS is required. */
1486 if (oakley_setdhgroup(cur_rmconf->dh_group,
1487 &cur_rmconf->dhgrp) < 0) {
1488 yyerror("failed to set DH value.\n");
1493 insrmconf(cur_rmconf);
1497 : ANONYMOUS ike_port
1499 $$ = newsaddr(sizeof(struct sockaddr));
1500 $$->sa_family = AF_UNSPEC;
1501 ((struct sockaddr_in *)$$)->sin_port = htons($2);
1507 yyerror("failed to allocate sockaddr");
1514 | remote_specs remote_spec
1519 cur_rmconf->etypes = NULL;
1522 | DOI DOITYPE { cur_rmconf->doitype = $2; } EOS
1523 | SITUATION SITUATIONTYPE { cur_rmconf->sittype = $2; } EOS
1524 | CERTIFICATE_TYPE cert_spec
1525 | PEERS_CERTFILE QUOTEDSTRING
1528 yywarn("This directive without certtype will be removed!\n");
1529 yywarn("Please use 'peers_certfile x509 \"%s\";' instead\n", $2->v);
1530 cur_rmconf->getcert_method = ISAKMP_GETCERT_LOCALFILE;
1532 if (cur_rmconf->peerscertfile != NULL)
1533 racoon_free(cur_rmconf->peerscertfile);
1534 cur_rmconf->peerscertfile = racoon_strdup($2->v);
1535 STRDUP_FATAL(cur_rmconf->peerscertfile);
1538 yyerror("cert files not supported.\n");
1543 | CA_TYPE CERT_X509 QUOTEDSTRING
1546 cur_rmconf->cacerttype = $2;
1547 cur_rmconf->getcacert_method = ISAKMP_GETCERT_LOCALFILE;
1548 if (cur_rmconf->cacertfile != NULL)
1549 racoon_free(cur_rmconf->cacertfile);
1550 cur_rmconf->cacertfile = racoon_strdup($3->v);
1551 STRDUP_FATAL(cur_rmconf->cacertfile);
1554 yyerror("cert files not supported.\n");
1560 | PEERS_CERTFILE CERT_X509 QUOTEDSTRING
1563 cur_rmconf->getcert_method = ISAKMP_GETCERT_LOCALFILE;
1564 if (cur_rmconf->peerscertfile != NULL)
1565 racoon_free(cur_rmconf->peerscertfile);
1566 cur_rmconf->peerscertfile = racoon_strdup($3->v);
1567 STRDUP_FATAL(cur_rmconf->peerscertfile);
1570 yyerror("cert files not supported.\n");
1576 | PEERS_CERTFILE CERT_PLAINRSA QUOTEDSTRING
1579 char path[MAXPATHLEN];
1582 getpathname(path, sizeof(path),
1583 LC_PATHTYPE_CERT, $3->v);
1586 if (cur_rmconf->getcert_method == ISAKMP_GETCERT_DNS) {
1587 yyerror("Different peers_certfile method "
1588 "already defined: %d!\n",
1589 cur_rmconf->getcert_method);
1592 cur_rmconf->getcert_method = ISAKMP_GETCERT_LOCALFILE;
1593 if (rsa_parse_file(cur_rmconf->rsa_public, path, RSA_TYPE_PUBLIC)) {
1594 yyerror("Couldn't parse keyfile.\n", path);
1597 plog(LLV_DEBUG, LOCATION, NULL, "Public PlainRSA keyfile parsed: %s\n", path);
1599 yyerror("plainrsa not supported.\n");
1604 | PEERS_CERTFILE DNSSEC
1606 if (cur_rmconf->getcert_method) {
1607 yyerror("Different peers_certfile method already defined!\n");
1610 cur_rmconf->getcert_method = ISAKMP_GETCERT_DNS;
1611 cur_rmconf->peerscertfile = NULL;
1614 | VERIFY_CERT SWITCH { cur_rmconf->verify_cert = $2; } EOS
1615 | SEND_CERT SWITCH { cur_rmconf->send_cert = $2; } EOS
1616 | SEND_CR SWITCH { cur_rmconf->send_cr = $2; } EOS
1617 | CERTIFICATE_VERIFICATION VERIFICATION_MODULE
1619 cur_rmconf->cert_verification = $2;
1621 | CERTIFICATE_VERIFICATION VERIFICATION_MODULE VERIFICATION_OPTION
1623 cur_rmconf->cert_verification = $2;
1624 cur_rmconf->cert_verification_option = $3;
1627 | OPEN_DIR_AUTH_GROUP QUOTEDSTRING
1630 cur_rmconf->open_dir_auth_group = $2;
1632 yyerror("Apple specific features not compiled in.");
1636 | MY_IDENTIFIER IDENTIFIERTYPE identifierstring
1638 if (set_identifier(&cur_rmconf->idv, $2, $3) != 0) {
1639 yyerror("failed to set identifer.\n");
1640 vfree($3); //%%% BUG FIX - memory leak
1643 vfree($3); //%%% BUG FIX - memory leak
1644 cur_rmconf->idvtype = $2;
1647 | MY_IDENTIFIER IDENTIFIERTYPE IDENTIFIERQUAL identifierstring
1649 if (set_identifier_qual(&cur_rmconf->idv, $2, $4, $3) != 0) {
1650 yyerror("failed to set identifer.\n");
1653 cur_rmconf->idvtype = $2;
1656 | XAUTH_LOGIN identifierstring
1658 #ifdef ENABLE_HYBRID
1659 /* formerly identifier type login */
1660 if (xauth_rmconf_used(&cur_rmconf->xauth) == -1) {
1661 yyerror("failed to allocate xauth state\n");
1664 if ((cur_rmconf->xauth->login = vdup($2)) == NULL) {
1665 yyerror("failed to set identifer.\n");
1668 vfree($2); //%%% BUG FIX - memory leak
1670 yyerror("racoon not configured with --enable-hybrid");
1674 | PEERS_IDENTIFIER IDENTIFIERTYPE identifierstring
1679 yyerror("failed to allocate idspec");
1682 if (set_identifier(&id->id, $2, $3) != 0) {
1683 yyerror("failed to set identifer.\n");
1685 vfree($3); //%%% BUG FIX - memory leak
1688 vfree($3); //%%% BUG FIX - memory leak
1690 genlist_append (cur_rmconf->idvl_p, id);
1693 | PEERS_IDENTIFIER IDENTIFIERTYPE IDENTIFIERQUAL identifierstring
1698 yyerror("failed to allocate idspec");
1701 if (set_identifier_qual(&id->id, $2, $4, $3) != 0) {
1702 yyerror("failed to set identifer.\n");
1707 genlist_append (cur_rmconf->idvl_p, id);
1710 | VERIFY_IDENTIFIER SWITCH { cur_rmconf->verify_identifier = $2; } EOS
1711 | SHARED_SECRET SECRETTYPE QUOTEDSTRING
1713 cur_rmconf->secrettype = $2;
1714 cur_rmconf->shared_secret = $3;
1716 | SHARED_SECRET SECRETTYPE
1718 if ($2 != SECRETTYPE_KEYCHAIN_BY_ID) {
1719 yyerror("shared secret value missing.\n");
1722 cur_rmconf->secrettype = $2;
1724 | NONCE_SIZE NUMBER { cur_rmconf->nonce_size = $2; } EOS
1727 yyerror("dh_group cannot be defined here.");
1731 | PASSIVE SWITCH { cur_rmconf->passive = $2; } EOS
1732 | IKE_FRAG SWITCH { cur_rmconf->ike_frag = $2; } EOS
1733 | IKE_FRAG REMOTE_FORCE_LEVEL { cur_rmconf->ike_frag = ISAKMP_FRAG_FORCE; } EOS
1735 #ifdef SADB_X_EXT_NAT_T_FRAG
1736 if (libipsec_opt & LIBIPSEC_OPT_FRAG)
1737 cur_rmconf->esp_frag = $2;
1739 yywarn("libipsec lacks IKE frag support");
1741 yywarn("Your kernel does not support esp_frag");
1744 | SCRIPT QUOTEDSTRING PHASE1_UP {
1745 if (cur_rmconf->script[SCRIPT_PHASE1_UP] != NULL)
1746 vfree(cur_rmconf->script[SCRIPT_PHASE1_UP]);
1748 cur_rmconf->script[SCRIPT_PHASE1_UP] =
1749 script_path_add(vdup($2));
1751 | SCRIPT QUOTEDSTRING PHASE1_DOWN {
1752 if (cur_rmconf->script[SCRIPT_PHASE1_DOWN] != NULL)
1753 vfree(cur_rmconf->script[SCRIPT_PHASE1_DOWN]);
1755 cur_rmconf->script[SCRIPT_PHASE1_DOWN] =
1756 script_path_add(vdup($2));
1758 | MODE_CFG SWITCH { cur_rmconf->mode_cfg = $2; } EOS
1759 | WEAK_PHASE1_CHECK SWITCH {
1760 cur_rmconf->weak_phase1_check = $2;
1762 | GENERATE_POLICY SWITCH { cur_rmconf->gen_policy = $2; } EOS
1763 | GENERATE_POLICY GENERATE_LEVEL { cur_rmconf->gen_policy = $2; } EOS
1764 | SUPPORT_PROXY SWITCH { cur_rmconf->support_proxy = $2; } EOS
1765 | INITIAL_CONTACT SWITCH { cur_rmconf->ini_contact = $2; } EOS
1766 | NAT_TRAVERSAL SWITCH
1769 cur_rmconf->nat_traversal = $2;
1771 yyerror("NAT-T support not compiled in.");
1774 | NAT_TRAVERSAL NAT_TRAVERSAL_LEVEL
1777 cur_rmconf->nat_traversal = $2;
1779 yyerror("NAT-T support not compiled in.");
1782 | NAT_TRAVERSAL_MULTI_USER SWITCH
1785 cur_rmconf->natt_multiple_user = $2;
1787 yyerror("NAT-T support not compiled in.");
1790 | NAT_TRAVERSAL_KEEPALIVE SWITCH
1793 cur_rmconf->natt_keepalive = $2;
1795 yyerror("NAT-T support not compiled in.");
1801 cur_rmconf->dpd = $2;
1803 yyerror("DPD support not compiled in.");
1809 cur_rmconf->dpd_interval = $2;
1811 yyerror("DPD support not compiled in.");
1818 cur_rmconf->dpd_retry = $2;
1820 yyerror("DPD support not compiled in.");
1824 | DPD_MAXFAIL NUMBER
1827 cur_rmconf->dpd_maxfails = $2;
1829 yyerror("DPD support not compiled in.");
1833 | DPD_ALGORITHM dpd_algo_type
1836 cur_rmconf->dpd_algo = $2;
1838 yyerror("DPD support not compiled in.");
1842 | DISCONNECT_ON_IDLE IDLE_TIMEOUT NUMBER IDLE_DIRECTION idle_dir_type
1844 cur_rmconf->idle_timeout = $3;
1845 cur_rmconf->idle_timeout_dir = $5;
1848 | LIFETIME LIFETYPE_TIME NUMBER unittype_time
1850 cur_rmconf->prhead->lifetime = $3 * $4;
1853 | PROPOSAL_CHECK PROPOSAL_CHECK_LEVEL { cur_rmconf->pcheck_level = $2; } EOS
1854 | LIFETIME LIFETYPE_BYTE NUMBER unittype_byte
1857 yyerror("byte lifetime support is deprecated in Phase1");
1860 yywarn("the lifetime of bytes in phase 1 "
1861 "will be ignored at the moment.");
1862 cur_rmconf->prhead->lifebyte = fix_lifebyte($3 * $4);
1863 if (cur_rmconf->prhead->lifebyte == 0)
1870 struct secprotospec *spspec;
1872 spspec = newspspec();
1875 insspspec(spspec, &cur_rmconf->prhead);
1877 BOC isakmpproposal_specs EOC
1881 | exchange_types EXCHANGETYPE
1884 new = racoon_malloc(sizeof(struct etypes));
1886 yyerror("failed to allocate etypes");
1891 if (cur_rmconf->etypes == NULL)
1892 cur_rmconf->etypes = new;
1895 for (p = cur_rmconf->etypes;
1904 : CERT_X509 QUOTEDSTRING QUOTEDSTRING
1906 cur_rmconf->certtype = $1;
1907 if (cur_rmconf->mycertfile != NULL)
1908 racoon_free(cur_rmconf->mycertfile);
1909 cur_rmconf->mycertfile = racoon_strdup($2->v);
1910 STRDUP_FATAL(cur_rmconf->mycertfile);
1912 if (cur_rmconf->myprivfile != NULL)
1913 racoon_free(cur_rmconf->myprivfile);
1914 cur_rmconf->myprivfile = racoon_strdup($3->v);
1915 STRDUP_FATAL(cur_rmconf->myprivfile);
1919 | CERT_X509 IN_KEYCHAIN
1921 cur_rmconf->certtype = $1;
1922 cur_rmconf->identity_in_keychain = 1;
1923 cur_rmconf->keychainCertRef = NULL;
1927 | CERT_X509 IN_KEYCHAIN QUOTEDSTRING
1929 cur_rmconf->certtype = $1;
1930 cur_rmconf->identity_in_keychain = 1;
1931 cur_rmconf->keychainCertRef = $3;
1935 | CERT_PLAINRSA QUOTEDSTRING
1938 char path[MAXPATHLEN];
1941 getpathname(path, sizeof(path),
1942 LC_PATHTYPE_CERT, $2->v);
1945 cur_rmconf->certtype = $1;
1946 cur_rmconf->send_cr = FALSE;
1947 cur_rmconf->send_cert = FALSE;
1948 cur_rmconf->verify_cert = FALSE;
1949 if (rsa_parse_file(cur_rmconf->rsa_private, path, RSA_TYPE_PRIVATE)) {
1950 yyerror("Couldn't parse keyfile.\n", path);
1953 plog(LLV_DEBUG, LOCATION, NULL, "Private PlainRSA keyfile parsed: %s\n", path);
1955 yyerror("plainrsa not supported.\n");
1964 $$ = algtype2doi(algclass_isakmp_dh, $1);
1966 yyerror("must be DH group");
1969 #ifndef HAVE_OPENSSL
1970 if ($$ != OAKLEY_ATTR_GRP_DESC_MODP1024 && $$ != OAKLEY_ATTR_GRP_DESC_MODP1536) {
1971 yyerror("DH group must be 2 or 5");
1978 if (ARRAYLEN(num2dhgroup) > $1 && num2dhgroup[$1] != 0) {
1979 $$ = num2dhgroup[$1];
1981 yyerror("must be DH group");
1985 #ifndef HAVE_OPENSSL
1986 if ($$ != OAKLEY_ATTR_GRP_DESC_MODP1024 && $$ != OAKLEY_ATTR_GRP_DESC_MODP1536) {
1987 yyerror("DH group must be 2 or 5");
1994 : /* nothing */ { $$ = NULL; }
1995 | ADDRSTRING { $$ = $1; }
1996 | QUOTEDSTRING { $$ = $1; }
1998 isakmpproposal_specs
2000 | isakmpproposal_specs isakmpproposal_spec
2005 yyerror("strength directive is obsoleted.");
2007 | LIFETIME LIFETYPE_TIME NUMBER unittype_time
2009 cur_rmconf->prhead->spspec->lifetime = $3 * $4;
2012 | LIFETIME LIFETYPE_BYTE NUMBER unittype_byte
2015 yyerror("byte lifetime support is deprecated");
2018 cur_rmconf->prhead->spspec->lifebyte = fix_lifebyte($3 * $4);
2019 if (cur_rmconf->prhead->spspec->lifebyte == 0)
2024 | DH_GROUP dh_group_num
2026 cur_rmconf->prhead->spspec->algclass[algclass_isakmp_dh] = $2;
2029 | GSS_ID QUOTEDSTRING
2031 if (cur_rmconf->prhead->spspec->vendorid != VENDORID_GSSAPI) {
2032 yyerror("wrong Vendor ID for gssapi_id");
2035 if (cur_rmconf->prhead->spspec->gssid != NULL)
2036 racoon_free(cur_rmconf->prhead->spspec->gssid);
2037 cur_rmconf->prhead->spspec->gssid =
2038 racoon_strdup($2->v);
2039 STRDUP_FATAL(cur_rmconf->prhead->spspec->gssid);
2042 | ALGORITHM_CLASS ALGORITHMTYPE keylength
2047 doi = algtype2doi($1, $2);
2049 yyerror("algorithm mismatched 1");
2054 case algclass_isakmp_enc:
2055 /* reject suppressed algorithms */
2056 #ifndef HAVE_OPENSSL_RC5_H
2057 if ($2 == algtype_rc5) {
2058 yyerror("algorithm %s not supported",
2059 s_attr_isakmp_enc(doi));
2063 #ifndef HAVE_OPENSSL_IDEA_H
2064 if ($2 == algtype_idea) {
2065 yyerror("algorithm %s not supported",
2066 s_attr_isakmp_enc(doi));
2071 cur_rmconf->prhead->spspec->algclass[algclass_isakmp_enc] = doi;
2072 defklen = default_keylen($1, $2);
2075 yyerror("keylen not allowed");
2079 if ($3 && check_keylen($1, $2, $3) < 0) {
2080 yyerror("invalid keylen %d", $3);
2085 cur_rmconf->prhead->spspec->encklen = $3;
2087 cur_rmconf->prhead->spspec->encklen = defklen;
2089 case algclass_isakmp_hash:
2090 cur_rmconf->prhead->spspec->algclass[algclass_isakmp_hash] = doi;
2092 case algclass_isakmp_ameth:
2093 cur_rmconf->prhead->spspec->algclass[algclass_isakmp_ameth] = doi;
2095 * We may have to set the Vendor ID for the
2096 * authentication method we're using.
2099 case algtype_gssapikrb:
2100 if (cur_rmconf->prhead->spspec->vendorid !=
2102 yyerror("Vendor ID mismatch "
2107 * For interoperability with Win2k,
2108 * we set the Vendor ID to "GSSAPI".
2110 cur_rmconf->prhead->spspec->vendorid =
2114 case algtype_rsasig:
2115 if (cur_rmconf->certtype == ISAKMP_CERT_PLAINRSA) {
2116 if (rsa_list_count(cur_rmconf->rsa_private) == 0) {
2117 yyerror ("Private PlainRSA key not set. "
2118 "Use directive 'certificate_type plainrsa ...'\n");
2121 if (rsa_list_count(cur_rmconf->rsa_public) == 0) {
2122 yyerror ("Public PlainRSA keys not set. "
2123 "Use directive 'peers_certfile plainrsa ...'\n");
2134 yyerror("algorithm mismatched 2");
2142 : UNITTYPE_SEC { $$ = 1; }
2143 | UNITTYPE_MIN { $$ = 60; }
2144 | UNITTYPE_HOUR { $$ = (60 * 60); }
2147 : UNITTYPE_BYTE { $$ = 1; }
2148 | UNITTYPE_KBYTES { $$ = 1024; }
2149 | UNITTYPE_MBYTES { $$ = (1024 * 1024); }
2150 | UNITTYPE_TBYTES { $$ = (1024 * 1024 * 1024); }
2153 : DPD_ALGO_TYPE_DEFAULT { $$ = DPD_ALGO_DEFAULT; }
2154 | DPD_ALGO_TYPE_INBOUND { $$ = DPD_ALGO_INBOUND_DETECT; }
2155 | DPD_ALGO_TYPE_BLACKHOLE { $$ = DPD_ALGO_BLACKHOLE_DETECT; }
2158 : IDLE_DIRECTION_ANY { $$ = IPSEC_DIR_ANY; }
2159 | IDLE_DIRECTION_IN { $$ = IPSEC_DIR_INBOUND; }
2160 | IDLE_DIRECTION_OUT { $$ = IPSEC_DIR_OUTBOUND; }
2164 static struct proposalspec *
2167 struct proposalspec *new;
2169 new = racoon_calloc(1, sizeof(*new));
2171 yyerror("failed to allocate proposal");
2177 * insert into head of list.
2180 insprspec(prspec, head)
2181 struct proposalspec *prspec;
2182 struct proposalspec **head;
2185 (*head)->prev = prspec;
2186 prspec->next = *head;
2190 static struct secprotospec *
2193 struct secprotospec *new;
2195 new = racoon_calloc(1, sizeof(*new));
2197 yyerror("failed to allocate spproto");
2201 new->encklen = 0; /*XXX*/
2204 * Default to "uknown" vendor -- we will override this
2205 * as necessary. When we send a Vendor ID payload, an
2206 * "unknown" will be translated to a KAME/racoon ID.
2208 new->vendorid = VENDORID_UNKNOWN;
2214 * insert into head of list.
2217 insspspec(spspec, head)
2218 struct secprotospec *spspec;
2219 struct proposalspec **head;
2221 spspec->back = *head;
2223 if ((*head)->spspec != NULL)
2224 (*head)->spspec->prev = spspec;
2225 spspec->next = (*head)->spspec;
2226 (*head)->spspec = spspec;
2229 /* set final acceptable proposal */
2231 set_isakmp_proposal(rmconf, prspec)
2232 struct remoteconf *rmconf;
2233 struct proposalspec *prspec;
2235 struct proposalspec *p;
2236 struct secprotospec *s;
2239 int32_t types[MAXALGCLASS];
2243 plog(LLV_ERROR, LOCATION, NULL,
2244 "multiple proposal definition.\n");
2248 /* mandatory check */
2249 if (p->spspec == NULL) {
2250 yyerror("no remote specification found: %s.\n",
2251 saddr2str(rmconf->remote));
2254 for (s = p->spspec; s != NULL; s = s->next) {
2255 /* XXX need more to check */
2256 if (s->algclass[algclass_isakmp_enc] == 0) {
2257 yyerror("encryption algorithm required.");
2260 if (s->algclass[algclass_isakmp_hash] == 0) {
2261 yyerror("hash algorithm required.");
2264 if (s->algclass[algclass_isakmp_dh] == 0) {
2265 yyerror("DH group required.");
2268 if (s->algclass[algclass_isakmp_ameth] == 0) {
2269 yyerror("authentication method required.");
2274 /* skip to last part */
2275 for (s = p->spspec; s->next != NULL; s = s->next)
2279 plog(LLV_DEBUG2, LOCATION, NULL,
2280 "lifetime = %ld\n", (long)
2281 (s->lifetime ? s->lifetime : p->lifetime));
2282 plog(LLV_DEBUG2, LOCATION, NULL,
2284 s->lifebyte ? s->lifebyte : p->lifebyte);
2285 plog(LLV_DEBUG2, LOCATION, NULL,
2286 "encklen=%d\n", s->encklen);
2288 memset(types, 0, ARRAYLEN(types));
2289 types[algclass_isakmp_enc] = s->algclass[algclass_isakmp_enc];
2290 types[algclass_isakmp_hash] = s->algclass[algclass_isakmp_hash];
2291 types[algclass_isakmp_dh] = s->algclass[algclass_isakmp_dh];
2292 types[algclass_isakmp_ameth] =
2293 s->algclass[algclass_isakmp_ameth];
2295 /* expanding spspec */
2297 trns_no = expand_isakmpspec(prop_no, trns_no, types,
2298 algclass_isakmp_enc, algclass_isakmp_ameth + 1,
2299 s->lifetime ? s->lifetime : p->lifetime,
2300 s->lifebyte ? s->lifebyte : p->lifebyte,
2301 s->encklen, s->vendorid, s->gssid,
2303 if (trns_no == -1) {
2304 plog(LLV_ERROR, LOCATION, NULL,
2305 "failed to expand isakmp proposal.\n");
2312 if (rmconf->proposal == NULL) {
2313 plog(LLV_ERROR, LOCATION, NULL,
2314 "no proposal found.\n");
2325 for (i = 0; i < MAXALGCLASS; i++)
2326 tmpalgtype[i] = 0; /* means algorithm undefined. */
2330 expand_isakmpspec(prop_no, trns_no, types,
2331 class, last, lifetime, lifebyte, encklen, vendorid, gssid,
2333 int prop_no, trns_no;
2334 int *types, class, last;
2340 struct remoteconf *rmconf;
2342 struct isakmpsa *new;
2348 plog(LLV_DEBUG2, LOCATION, NULL,
2349 "p:%d t:%d\n", prop_no, trns_no);
2350 for (j = class; j < MAXALGCLASS; j++) {
2351 snprintf(tb, sizeof(tb), "%d", types[j]);
2352 plog(LLV_DEBUG2, LOCATION, NULL,
2354 s_algtype(j, types[j]),
2355 types[j] ? "(" : "",
2356 tb[0] == '0' ? "" : tb,
2357 types[j] ? ")" : "");
2359 plog(LLV_DEBUG2, LOCATION, NULL, "\n");
2362 #define TMPALGTYPE2STR(n) \
2363 s_algtype(algclass_isakmp_##n, types[algclass_isakmp_##n])
2364 /* check mandatory values */
2365 if (types[algclass_isakmp_enc] == 0
2366 || types[algclass_isakmp_ameth] == 0
2367 || types[algclass_isakmp_hash] == 0
2368 || types[algclass_isakmp_dh] == 0) {
2369 yyerror("few definition of algorithm "
2370 "enc=%s ameth=%s hash=%s dhgroup=%s.\n",
2371 TMPALGTYPE2STR(enc),
2372 TMPALGTYPE2STR(ameth),
2373 TMPALGTYPE2STR(hash),
2374 TMPALGTYPE2STR(dh));
2377 #undef TMPALGTYPE2STR
2380 new = newisakmpsa();
2382 yyerror("failed to allocate isakmp sa");
2385 new->prop_no = prop_no;
2386 new->trns_no = trns_no++;
2387 new->lifetime = lifetime;
2388 new->lifebyte = lifebyte;
2389 new->enctype = types[algclass_isakmp_enc];
2390 new->encklen = encklen;
2391 new->authmethod = types[algclass_isakmp_ameth];
2392 new->hashtype = types[algclass_isakmp_hash];
2393 new->dh_group = types[algclass_isakmp_dh];
2394 new->vendorid = vendorid;
2396 if (new->authmethod == OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB) {
2397 if (gssid != NULL) {
2398 if ((new->gssid = vmalloc(strlen(gssid))) == NULL) {
2400 yyerror("failed to allocate gssid");
2403 memcpy(new->gssid->v, gssid, new->gssid->l);
2407 * Allocate the default ID so that it gets put
2408 * into a GSS ID attribute during the Phase 1
2411 new->gssid = gssapi_get_default_gss_id();
2415 insisakmpsa(new, rmconf);
2421 listen_addr (struct sockaddr *addr, int udp_encap)
2427 yyerror("failed to allocate myaddrs");
2431 if (p->addr == NULL) {
2432 yyerror("failed to copy sockaddr ");
2436 p->udp_encap = udp_encap;
2437 /* These need to be initialized for Apple modifications
2438 * to open code for isakmp sockets
2443 insmyaddr(p, &lcconf->myaddrs);
2445 lcconf->autograbaddr = 0;
2452 * Must be more than 1024B because its unit is kilobytes.
2453 * That is defined RFC2407.
2460 yyerror("byte size should be more than 1024B.");
2473 plog(LLV_DEBUG, LOCATION, NULL, "===== parse config\n");
2477 if (yycf_switch_buffer(lcconf->racoon_conf) != 0) {
2478 IPSECCONFIGTRACEREVENT(CONSTSTR(lcconf->racoon_conf),
2479 IPSECCONFIGEVENTCODE_PARSE_ERROR,
2480 CONSTSTR("could not read configuration file"),
2481 CONSTSTR("cfparse: yycf_switch_buffer erred"));
2482 plog(LLV_ERROR, LOCATION, NULL,
2483 "could not read configuration file \"%s\"\n",
2484 lcconf->racoon_conf);
2491 plog(LLV_ERROR, LOCATION, NULL,
2492 "fatal parse failure (%d errors)\n",
2495 plog(LLV_ERROR, LOCATION, NULL,
2496 "fatal parse failure.\n");
2498 IPSECCONFIGTRACEREVENT(CONSTSTR(lcconf->racoon_conf),
2499 IPSECCONFIGEVENTCODE_PARSE_ERROR,
2500 CONSTSTR("fatal parse failure"),
2501 CONSTSTR("cfparse: yyparse erred"));
2502 yycf_clean_buffer();
2506 if (error == 0 && yyerrorcount) {
2507 plog(LLV_ERROR, LOCATION, NULL,
2508 "parse error is nothing, but yyerrorcount is %d.\n",
2510 IPSECCONFIGTRACEREVENT(CONSTSTR(lcconf->racoon_conf),
2511 IPSECCONFIGEVENTCODE_PARSE_ERROR,
2512 CONSTSTR("ambivalent error code"),
2513 CONSTSTR("cfparse: error == 0 && yerrorcount"));
2514 yycf_clean_buffer();
2518 yycf_clean_buffer();
2520 plog(LLV_DEBUG2, LOCATION, NULL, "parse successed.\n");
2528 int ignore_estab_or_assert_handles = (sig == SIGUSR1);
2530 if (sig >= 0 && sig < NSIG) {
2531 plog(LLV_DEBUG, LOCATION, NULL, "==== Got %s signal - re-parsing.\n", sys_signame[sig]);
2533 plog(LLV_ERROR, LOCATION, NULL, "==== Got Unknown signal - re-parsing.\n");
2534 IPSECCONFIGTRACEREVENT(CONSTSTR("reparse"),
2535 IPSECCONFIGEVENTCODE_REPARSE_ERROR,
2536 CONSTSTR("Unknown signal"),
2537 CONSTSTR("cfreparse: triggered by unknown signal"));
2540 flushph2(ignore_estab_or_assert_handles);
2541 flushph1(ignore_estab_or_assert_handles);
2548 check_auto_exit(); /* check/change state of auto exit */
2555 #ifdef ENABLE_ADMINPORT
2557 adminsock_conf(path, owner, group, mode_dec)
2563 struct passwd *pw = NULL;
2564 struct group *gr = NULL;
2570 adminsock_path = path->v;
2576 uid = atoi(owner->v);
2578 if (((pw = getpwnam(owner->v)) == NULL) && !isnum)
2579 yyerror("User \"%s\" does not exist", owner->v);
2582 adminsock_owner = pw->pw_uid;
2584 adminsock_owner = uid;
2590 gid = atoi(group->v);
2592 if (((gr = getgrnam(group->v)) == NULL) && !isnum)
2593 yyerror("Group \"%s\" does not exist", group->v);
2596 adminsock_group = gr->gr_gid;
2598 adminsock_group = gid;
2604 yyerror("Mode 0%03o is invalid", mode_dec);
2605 if (mode_dec >= 400) { mode += 0400; mode_dec -= 400; }
2606 if (mode_dec >= 200) { mode += 0200; mode_dec -= 200; }
2607 if (mode_dec >= 100) { mode += 0200; mode_dec -= 100; }
2610 yyerror("Mode 0%03o is invalid", mode_dec);
2611 if (mode_dec >= 40) { mode += 040; mode_dec -= 40; }
2612 if (mode_dec >= 20) { mode += 020; mode_dec -= 20; }
2613 if (mode_dec >= 10) { mode += 020; mode_dec -= 10; }
2616 yyerror("Mode 0%03o is invalid", mode_dec);
2617 if (mode_dec >= 4) { mode += 04; mode_dec -= 4; }
2618 if (mode_dec >= 2) { mode += 02; mode_dec -= 2; }
2619 if (mode_dec >= 1) { mode += 02; mode_dec -= 1; }
2621 adminsock_mode = mode;