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"
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 static struct remoteconf *cur_rmconf;
129 static int tmpalgtype[MAXALGCLASS];
130 static struct sainfo *cur_sainfo;
131 static int cur_algclass;
132 static int oldloglevel = LLV_BASE;
134 static struct proposalspec *newprspec __P((void));
135 static void insprspec __P((struct proposalspec *, struct proposalspec **));
136 static struct secprotospec *newspspec __P((void));
137 static void insspspec __P((struct secprotospec *, struct proposalspec **));
138 static void adminsock_conf __P((vchar_t *, vchar_t *, vchar_t *, int));
140 static int set_isakmp_proposal
141 __P((struct remoteconf *, struct proposalspec *));
142 static void clean_tmpalgtype __P((void));
143 static int expand_isakmpspec __P((int, int, int *,
144 int, int, time_t, int, int, int, char *, struct remoteconf *));
145 static int listen_addr __P((struct sockaddr *addr, int udp_encap));
147 void freeetypes (struct etypes **etypes);
150 static int fix_lifebyte __P((u_long));
157 struct remoteconf *rmconf;
158 struct sockaddr *saddr;
159 struct sainfoalg *alg;
163 %token PRIVSEP USER GROUP CHROOT
168 /* self information */
169 %token IDENTIFIER VENDORID
171 %token LOGGING LOGLEV
173 %token PADDING PAD_RANDOMIZE PAD_RANDOMIZELEN PAD_MAXLEN PAD_STRICT PAD_EXCLTAIL
175 %token LISTEN X_ISAKMP X_ISAKMP_NATT X_ADMIN STRICT_ADDRESS ADMINSOCK DISABLED
177 %token MODECFG CFG_NET4 CFG_MASK4 CFG_DNS4 CFG_NBNS4 CFG_DEFAULT_DOMAIN
178 %token CFG_AUTH_SOURCE CFG_AUTH_GROUPS CFG_SYSTEM CFG_RADIUS CFG_PAM CFG_LDAP CFG_LOCAL CFG_NONE
179 %token CFG_GROUP_SOURCE CFG_ACCOUNTING CFG_CONF_SOURCE CFG_MOTD CFG_POOL_SIZE CFG_AUTH_THROTTLE
180 %token CFG_SPLIT_NETWORK CFG_SPLIT_LOCAL CFG_SPLIT_INCLUDE CFG_SPLIT_DNS
181 %token CFG_PFS_GROUP CFG_SAVE_PASSWD
183 %token RETRY RETRY_COUNTER RETRY_INTERVAL RETRY_PERSEND
184 %token RETRY_PHASE1 RETRY_PHASE2 NATT_KA AUTO_EXIT_DELAY
186 %token ALGORITHM_CLASS ALGORITHMTYPE STRENGTHTYPE
190 %token REMOTE ANONYMOUS INHERIT
191 %token EXCHANGE_MODE EXCHANGETYPE DOI DOITYPE SITUATION SITUATIONTYPE
192 %token CERTIFICATE_TYPE CERTTYPE PEERS_CERTFILE CA_TYPE
193 %token VERIFY_CERT SEND_CERT SEND_CR
194 %token IDENTIFIERTYPE IDENTIFIERQUAL MY_IDENTIFIER
195 %token PEERS_IDENTIFIER VERIFY_IDENTIFIER
196 %token SHARED_SECRET SECRETTYPE
197 %token OPEN_DIR_AUTH_GROUP IN_KEYCHAIN
198 %token CERTIFICATE_VERIFICATION VERIFICATION_MODULE VERIFICATION_OPTION
199 %token DNSSEC CERT_X509 CERT_PLAINRSA
200 %token NONCE_SIZE DH_GROUP KEEPALIVE PASSIVE INITIAL_CONTACT
201 %token NAT_TRAVERSAL REMOTE_FORCE_LEVEL NAT_TRAVERSAL_LEVEL NAT_TRAVERSAL_MULTI_USER NAT_TRAVERSAL_KEEPALIVE
202 %token PROPOSAL_CHECK PROPOSAL_CHECK_LEVEL
203 %token GENERATE_POLICY GENERATE_LEVEL SUPPORT_PROXY
205 %token EXEC_PATH EXEC_COMMAND EXEC_SUCCESS EXEC_FAILURE
206 %token GSS_ID GSS_ID_ENC GSS_ID_ENCTYPE
207 %token COMPLEX_BUNDLE
208 %token DPD DPD_DELAY DPD_RETRY DPD_MAXFAIL DPD_ALGORITHM
209 %token DISCONNECT_ON_IDLE IDLE_TIMEOUT IDLE_DIRECTION
210 %token XAUTH_LOGIN WEAK_PHASE1_CHECK
212 %token PREFIX PORT PORTANY UL_PROTO ANY IKE_FRAG ESP_FRAG MODE_CFG
213 %token PFS_GROUP LIFETIME LIFETYPE_TIME LIFETYPE_BYTE STRENGTH REMOTEID
215 %token SCRIPT PHASE1_UP PHASE1_DOWN
217 %token NUMBER SWITCH BOOLEAN
218 %token HEXSTRING QUOTEDSTRING ADDRSTRING ADDRRANGE
219 %token UNITTYPE_BYTE UNITTYPE_KBYTES UNITTYPE_MBYTES UNITTYPE_TBYTES
220 %token UNITTYPE_SEC UNITTYPE_MIN UNITTYPE_HOUR
221 %token EOS BOC EOC COMMA
222 %token DPD_ALGO_TYPE_DEFAULT DPD_ALGO_TYPE_INBOUND DPD_ALGO_TYPE_BLACKHOLE
223 %token IDLE_DIRECTION_IN IDLE_DIRECTION_OUT IDLE_DIRECTION_ANY
225 %type <num> NUMBER BOOLEAN SWITCH keylength
226 %type <num> PATHTYPE IDENTIFIERTYPE IDENTIFIERQUAL LOGLEV GSS_ID_ENCTYPE
227 %type <num> SECRETTYPE
228 %type <num> ALGORITHM_CLASS dh_group_num
229 %type <num> ALGORITHMTYPE STRENGTHTYPE
230 %type <num> PREFIX prefix PORT port ike_port
231 %type <num> ul_proto UL_PROTO
232 %type <num> EXCHANGETYPE DOITYPE SITUATIONTYPE
233 %type <num> CERTTYPE CERT_X509 CERT_PLAINRSA PROPOSAL_CHECK_LEVEL NAT_TRAVERSAL_LEVEL GENERATE_LEVEL
234 %type <num> VERIFICATION_MODULE VERIFICATION_OPTION
235 %type <num> unittype_time unittype_byte
236 %type <val> QUOTEDSTRING HEXSTRING ADDRSTRING ADDRRANGE sainfo_id
237 %type <val> identifierstring
238 %type <saddr> remote_index ike_addrinfo_port
239 %type <alg> algorithm
240 %type <num> dpd_algo_type
241 %type <num> idle_dir_type
247 | statements statement
254 | identifier_statement
267 : PRIVSEP BOC privsep_stmts EOC
271 | privsep_stmts privsep_stmt
278 if ((pw = getpwnam($2->v)) == NULL) {
279 yyerror("unknown user \"%s\"", $2->v);
282 lcconf->uid = pw->pw_uid;
285 | USER NUMBER { lcconf->uid = $2; } EOS
290 if ((gr = getgrnam($2->v)) == NULL) {
291 yyerror("unknown group \"%s\"", $2->v);
294 lcconf->gid = gr->gr_gid;
297 | GROUP NUMBER { lcconf->gid = $2; } EOS
298 | CHROOT QUOTEDSTRING { lcconf->chroot = $2->v; } EOS
303 : PATH PATHTYPE QUOTEDSTRING
305 if ($2 >= LC_PATHTYPE_MAX) {
306 yyerror("invalid path type %d", $2);
310 /* free old pathinfo */
311 if (lcconf->pathinfo[$2])
312 racoon_free(lcconf->pathinfo[$2]);
314 /* set new pathinfo */
315 lcconf->pathinfo[$2] = racoon_strdup($3->v);
316 STRDUP_FATAL(lcconf->pathinfo[$2]);
324 : COMPLEX_BUNDLE SWITCH { lcconf->complex_bundle = $2; } EOS
329 : INCLUDE QUOTEDSTRING EOS
331 char path[MAXPATHLEN];
333 getpathname(path, sizeof(path),
334 LC_PATHTYPE_INCLUDE, $2->v);
336 if (yycf_switch_buffer(path) != 0)
343 : GSS_ID_ENC GSS_ID_ENCTYPE EOS
345 if ($2 >= LC_GSSENC_MAX) {
346 yyerror("invalid GSS ID encoding %d", $2);
349 lcconf->gss_id_enc = $2;
353 /* self information */
355 : IDENTIFIER identifier_stmt
360 /*XXX to be deleted */
363 | IDENTIFIERTYPE QUOTEDSTRING
365 /*XXX to be deleted */
366 $2->l--; /* nuke '\0' */
367 lcconf->ident[$1] = $2;
368 if (lcconf->ident[$1] == NULL) {
369 yyerror("failed to set my ident: %s",
379 : LOGGING log_level EOS
385 * XXX ignore it because this specification
388 yywarn("see racoon.conf(5), such a log specification will be obsoleted.");
394 * set the loglevel to the value specified
395 * in the configuration file plus the number
396 * of -d options specified on the command line
398 loglevel += $1 - oldloglevel;
405 : PADDING BOC padding_stmts EOC
409 | padding_stmts padding_stmt
412 : PAD_RANDOMIZE SWITCH { lcconf->pad_random = $2; } EOS
413 | PAD_RANDOMIZELEN SWITCH { lcconf->pad_randomlen = $2; } EOS
414 | PAD_MAXLEN NUMBER { lcconf->pad_maxsize = $2; } EOS
415 | PAD_STRICT SWITCH { lcconf->pad_strict = $2; } EOS
416 | PAD_EXCLTAIL SWITCH { lcconf->pad_excltail = $2; } EOS
421 : LISTEN BOC listen_stmts EOC
425 | listen_stmts listen_stmt
428 : X_ISAKMP ike_addrinfo_port
433 | X_ISAKMP_NATT ike_addrinfo_port
438 yyerror("NAT-T support not compiled in.");
444 yyerror("admin directive is obsoleted.");
447 | ADMINSOCK QUOTEDSTRING QUOTEDSTRING QUOTEDSTRING NUMBER
449 #ifdef ENABLE_ADMINPORT
450 adminsock_conf($2, $3, $4, $5);
452 yywarn("admin port support not compiled in");
456 | ADMINSOCK QUOTEDSTRING
458 #ifdef ENABLE_ADMINPORT
459 adminsock_conf($2, NULL, NULL, -1);
461 yywarn("admin port support not compiled in");
467 #ifdef ENABLE_ADMINPORT
468 adminsock_path = NULL;
470 yywarn("admin port support not compiled in");
474 | STRICT_ADDRESS { lcconf->strict_address = TRUE; } EOS
477 : ADDRSTRING ike_port
481 snprintf(portbuf, sizeof(portbuf), "%ld", $2);
482 $$ = str2saddr($1->v, portbuf);
489 : /* nothing */ { $$ = PORT_ISAKMP; }
494 : MODECFG BOC modecfg_stmts EOC
498 | modecfg_stmts modecfg_stmt
501 : CFG_NET4 ADDRSTRING
504 if (inet_pton(AF_INET, $2->v,
505 &isakmp_cfg_config.network4) != 1)
506 yyerror("bad IPv4 network address.");
509 yyerror("racoon not configured with --enable-hybrid");
513 | CFG_MASK4 ADDRSTRING
516 if (inet_pton(AF_INET, $2->v,
517 &isakmp_cfg_config.netmask4) != 1)
518 yyerror("bad IPv4 netmask address.");
521 yyerror("racoon not configured with --enable-hybrid");
525 | CFG_DNS4 addrdnslist
527 | CFG_NBNS4 addrwinslist
529 | CFG_SPLIT_NETWORK CFG_SPLIT_LOCAL splitnetlist
532 isakmp_cfg_config.splitnet_type = UNITY_LOCAL_LAN;
534 yyerror("racoon not configured with --enable-hybrid");
538 | CFG_SPLIT_NETWORK CFG_SPLIT_INCLUDE splitnetlist
541 isakmp_cfg_config.splitnet_type = UNITY_SPLIT_INCLUDE;
543 yyerror("racoon not configured with --enable-hybrid");
547 | CFG_SPLIT_DNS splitdnslist
549 #ifndef ENABLE_HYBRID
550 yyerror("racoon not configured with --enable-hybrid");
554 | CFG_DEFAULT_DOMAIN QUOTEDSTRING
557 strlcpy(&isakmp_cfg_config.default_domain[0],
558 $2->v, sizeof(isakmp_cfg_config.default_domain));
561 yyerror("racoon not configured with --enable-hybrid");
565 | CFG_AUTH_SOURCE CFG_SYSTEM
568 isakmp_cfg_config.authsource = ISAKMP_CFG_AUTH_SYSTEM;
570 yyerror("racoon not configured with --enable-hybrid");
574 | CFG_AUTH_SOURCE CFG_RADIUS
577 #ifdef HAVE_LIBRADIUS
578 isakmp_cfg_config.authsource = ISAKMP_CFG_AUTH_RADIUS;
579 #else /* HAVE_LIBRADIUS */
580 yyerror("racoon not configured with --with-libradius");
581 #endif /* HAVE_LIBRADIUS */
582 #else /* ENABLE_HYBRID */
583 yyerror("racoon not configured with --enable-hybrid");
584 #endif /* ENABLE_HYBRID */
587 | CFG_AUTH_SOURCE CFG_PAM
591 isakmp_cfg_config.authsource = ISAKMP_CFG_AUTH_PAM;
592 #else /* HAVE_LIBPAM */
593 yyerror("racoon not configured with --with-libpam");
594 #endif /* HAVE_LIBPAM */
595 #else /* ENABLE_HYBRID */
596 yyerror("racoon not configured with --enable-hybrid");
597 #endif /* ENABLE_HYBRID */
600 | CFG_AUTH_SOURCE CFG_LDAP
604 isakmp_cfg_config.authsource = ISAKMP_CFG_AUTH_LDAP;
605 #else /* HAVE_LIBLDAP */
606 yyerror("racoon not configured with --with-libldap");
607 #endif /* HAVE_LIBLDAP */
608 #else /* ENABLE_HYBRID */
609 yyerror("racoon not configured with --enable-hybrid");
610 #endif /* ENABLE_HYBRID */
613 | CFG_AUTH_GROUPS authgrouplist
615 #ifndef ENABLE_HYBRID
616 yyerror("racoon not configured with --enable-hybrid");
620 | CFG_GROUP_SOURCE CFG_SYSTEM
623 isakmp_cfg_config.groupsource = ISAKMP_CFG_GROUP_SYSTEM;
625 yyerror("racoon not configured with --enable-hybrid");
629 | CFG_GROUP_SOURCE CFG_LDAP
633 isakmp_cfg_config.groupsource = ISAKMP_CFG_GROUP_LDAP;
634 #else /* HAVE_LIBLDAP */
635 yyerror("racoon not configured with --with-libldap");
636 #endif /* HAVE_LIBLDAP */
637 #else /* ENABLE_HYBRID */
638 yyerror("racoon not configured with --enable-hybrid");
639 #endif /* ENABLE_HYBRID */
642 | CFG_ACCOUNTING CFG_NONE
645 isakmp_cfg_config.accounting = ISAKMP_CFG_ACCT_NONE;
647 yyerror("racoon not configured with --enable-hybrid");
651 | CFG_ACCOUNTING CFG_SYSTEM
654 isakmp_cfg_config.accounting = ISAKMP_CFG_ACCT_SYSTEM;
656 yyerror("racoon not configured with --enable-hybrid");
660 | CFG_ACCOUNTING CFG_RADIUS
663 #ifdef HAVE_LIBRADIUS
664 isakmp_cfg_config.accounting = ISAKMP_CFG_ACCT_RADIUS;
665 #else /* HAVE_LIBRADIUS */
666 yyerror("racoon not configured with --with-libradius");
667 #endif /* HAVE_LIBRADIUS */
668 #else /* ENABLE_HYBRID */
669 yyerror("racoon not configured with --enable-hybrid");
670 #endif /* ENABLE_HYBRID */
673 | CFG_ACCOUNTING CFG_PAM
677 isakmp_cfg_config.accounting = ISAKMP_CFG_ACCT_PAM;
678 #else /* HAVE_LIBPAM */
679 yyerror("racoon not configured with --with-libpam");
680 #endif /* HAVE_LIBPAM */
681 #else /* ENABLE_HYBRID */
682 yyerror("racoon not configured with --enable-hybrid");
683 #endif /* ENABLE_HYBRID */
686 | CFG_POOL_SIZE NUMBER
689 if (isakmp_cfg_resize_pool($2) != 0)
690 yyerror("cannot allocate memory for pool");
691 #else /* ENABLE_HYBRID */
692 yyerror("racoon not configured with --enable-hybrid");
693 #endif /* ENABLE_HYBRID */
696 | CFG_PFS_GROUP NUMBER
699 isakmp_cfg_config.pfs_group = $2;
700 #else /* ENABLE_HYBRID */
701 yyerror("racoon not configured with --enable-hybrid");
702 #endif /* ENABLE_HYBRID */
705 | CFG_SAVE_PASSWD SWITCH
708 isakmp_cfg_config.save_passwd = $2;
709 #else /* ENABLE_HYBRID */
710 yyerror("racoon not configured with --enable-hybrid");
711 #endif /* ENABLE_HYBRID */
714 | CFG_AUTH_THROTTLE NUMBER
717 isakmp_cfg_config.auth_throttle = $2;
718 #else /* ENABLE_HYBRID */
719 yyerror("racoon not configured with --enable-hybrid");
720 #endif /* ENABLE_HYBRID */
723 | CFG_CONF_SOURCE CFG_LOCAL
726 isakmp_cfg_config.confsource = ISAKMP_CFG_CONF_LOCAL;
727 #else /* ENABLE_HYBRID */
728 yyerror("racoon not configured with --enable-hybrid");
729 #endif /* ENABLE_HYBRID */
732 | CFG_CONF_SOURCE CFG_RADIUS
735 #ifdef HAVE_LIBRADIUS
736 isakmp_cfg_config.confsource = ISAKMP_CFG_CONF_RADIUS;
737 #else /* HAVE_LIBRADIUS */
738 yyerror("racoon not configured with --with-libradius");
739 #endif /* HAVE_LIBRADIUS */
740 #else /* ENABLE_HYBRID */
741 yyerror("racoon not configured with --enable-hybrid");
742 #endif /* ENABLE_HYBRID */
745 | CFG_CONF_SOURCE CFG_LDAP
749 isakmp_cfg_config.confsource = ISAKMP_CFG_CONF_LDAP;
750 #else /* HAVE_LIBLDAP */
751 yyerror("racoon not configured with --with-libldap");
752 #endif /* HAVE_LIBLDAP */
753 #else /* ENABLE_HYBRID */
754 yyerror("racoon not configured with --enable-hybrid");
755 #endif /* ENABLE_HYBRID */
758 | CFG_MOTD QUOTEDSTRING
761 strlcpy(&isakmp_cfg_config.motd[0], $2->v, sizeof(isakmp_cfg_config.motd));
764 yyerror("racoon not configured with --enable-hybrid");
772 | addrdns COMMA addrdnslist
778 struct isakmp_cfg_config *icc = &isakmp_cfg_config;
780 if (icc->dns4_index > MAXNS)
781 yyerror("No more than %d DNS", MAXNS);
782 if (inet_pton(AF_INET, $1->v,
783 &icc->dns4[icc->dns4_index++]) != 1)
784 yyerror("bad IPv4 DNS address.");
788 yyerror("racoon not configured with --enable-hybrid");
795 | addrwins COMMA addrwinslist
801 struct isakmp_cfg_config *icc = &isakmp_cfg_config;
803 if (icc->nbns4_index > MAXWINS)
804 yyerror("No more than %d WINS", MAXWINS);
805 if (inet_pton(AF_INET, $1->v,
806 &icc->nbns4[icc->nbns4_index++]) != 1)
807 yyerror("bad IPv4 WINS address.");
811 yyerror("racoon not configured with --enable-hybrid");
818 | splitnetlist COMMA splitnet
824 struct isakmp_cfg_config *icc = &isakmp_cfg_config;
825 struct unity_network network;
827 if (inet_pton(AF_INET, $1->v, &network.addr4) != 1)
828 yyerror("bad IPv4 SPLIT address.");
830 /* Turn $2 (the prefix) into a subnet mask */
831 network.mask4.s_addr = ($2) ? htonl(~((1 << (32 - $2)) - 1)) : 0;
833 /* add the network to our list */
834 if (splitnet_list_add(&icc->splitnet_list, &network,&icc->splitnet_count))
835 yyerror("Unable to allocate split network");
839 yyerror("racoon not configured with --enable-hybrid");
846 | authgroup COMMA authgrouplist
852 char * groupname = NULL;
853 char ** grouplist = NULL;
854 struct isakmp_cfg_config *icc = &isakmp_cfg_config;
856 grouplist = racoon_realloc(icc->grouplist,
857 sizeof(char**)*(icc->groupcount+1));
858 if (grouplist == NULL)
859 yyerror("unable to allocate auth group list");
861 groupname = racoon_malloc($1->l+1);
862 if (groupname == NULL)
863 yyerror("unable to allocate auth group name");
865 memcpy(groupname,$1->v,$1->l);
867 grouplist[icc->groupcount]=groupname;
868 icc->grouplist = grouplist;
873 yyerror("racoon not configured with --enable-hybrid");
880 | splitdns COMMA splitdnslist
886 struct isakmp_cfg_config *icc = &isakmp_cfg_config;
888 if (!icc->splitdns_len)
890 icc->splitdns_list = racoon_malloc($1->l);
891 if(icc->splitdns_list == NULL)
892 yyerror("error allocating splitdns list buffer");
893 memcpy(icc->splitdns_list,$1->v,$1->l);
894 icc->splitdns_len = $1->l;
898 int len = icc->splitdns_len + $1->l + 1;
899 icc->splitdns_list = racoon_realloc(icc->splitdns_list,len);
900 if(icc->splitdns_list == NULL)
901 yyerror("error allocating splitdns list buffer");
902 icc->splitdns_list[icc->splitdns_len] = ',';
903 memcpy(icc->splitdns_list + icc->splitdns_len + 1, $1->v, $1->l);
904 icc->splitdns_len = len;
908 yyerror("racoon not configured with --enable-hybrid");
916 : RETRY BOC timer_stmts EOC
920 | timer_stmts timer_stmt
923 : RETRY_COUNTER NUMBER
925 lcconf->retry_counter = $2;
928 | RETRY_INTERVAL NUMBER unittype_time
930 lcconf->retry_interval = $2 * $3;
933 | RETRY_PERSEND NUMBER
935 lcconf->count_persend = $2;
938 | RETRY_PHASE1 NUMBER unittype_time
940 lcconf->retry_checkph1 = $2 * $3;
943 | RETRY_PHASE2 NUMBER unittype_time
945 lcconf->wait_ph2complete = $2 * $3;
948 | AUTO_EXIT_DELAY NUMBER unittype_time
950 lcconf->auto_exit_delay = $2 * $3;
951 lcconf->auto_exit_state |= LC_AUTOEXITSTATE_SET;
955 | NATT_KA NUMBER unittype_time
958 lcconf->natt_ka_interval = $2 * $3;
960 yyerror("NAT-T support not compiled in.");
970 cur_sainfo = newsainfo();
971 if (cur_sainfo == NULL) {
972 yyerror("failed to allocate sainfo");
976 sainfo_name sainfo_param BOC sainfo_specs
978 struct sainfo *check;
981 if (cur_sainfo->algs[algclass_ipsec_enc] == 0) {
982 yyerror("no encryption algorithm at %s",
983 sainfo2str(cur_sainfo));
986 if (cur_sainfo->algs[algclass_ipsec_auth] == 0) {
987 yyerror("no authentication algorithm at %s",
988 sainfo2str(cur_sainfo));
991 if (cur_sainfo->algs[algclass_ipsec_comp] == 0) {
992 yyerror("no compression algorithm at %s",
993 sainfo2str(cur_sainfo));
997 /* duplicate check */
998 check = getsainfo(cur_sainfo->idsrc,
1000 cur_sainfo->id_i, 0);
1001 if (check && (!check->idsrc && !cur_sainfo->idsrc)) {
1002 yyerror("duplicated sainfo: %s",
1003 sainfo2str(cur_sainfo));
1006 inssainfo(cur_sainfo);
1013 cur_sainfo->idsrc = NULL;
1014 cur_sainfo->iddst = NULL;
1016 | ANONYMOUS sainfo_id
1018 cur_sainfo->idsrc = NULL;
1019 cur_sainfo->iddst = $2;
1021 | sainfo_id ANONYMOUS
1023 cur_sainfo->idsrc = $1;
1024 cur_sainfo->iddst = NULL;
1026 | sainfo_id sainfo_id
1028 cur_sainfo->idsrc = $1;
1029 cur_sainfo->iddst = $2;
1033 : IDENTIFIERTYPE ADDRSTRING prefix port ul_proto
1036 struct sockaddr *saddr;
1038 if (($5 == IPPROTO_ICMP || $5 == IPPROTO_ICMPV6)
1039 && ($4 != IPSEC_PORT_ANY || $4 != IPSEC_PORT_ANY)) {
1040 yyerror("port number must be \"any\".");
1044 snprintf(portbuf, sizeof(portbuf), "%lu", $4);
1045 saddr = str2saddr($2->v, portbuf);
1050 switch (saddr->sa_family) {
1052 if ($5 == IPPROTO_ICMPV6) {
1053 yyerror("upper layer protocol mismatched.\n");
1057 $$ = ipsecdoi_sockaddr2id(saddr,
1058 $3 == ~0 ? (sizeof(struct in_addr) << 3): $3,
1063 if ($5 == IPPROTO_ICMP) {
1064 yyerror("upper layer protocol mismatched.\n");
1068 $$ = ipsecdoi_sockaddr2id(saddr,
1069 $3 == ~0 ? (sizeof(struct in6_addr) << 3): $3,
1074 yyerror("invalid family: %d", saddr->sa_family);
1082 | IDENTIFIERTYPE ADDRSTRING ADDRRANGE prefix port ul_proto
1085 struct sockaddr *laddr = NULL, *haddr = NULL;
1088 if (($6 == IPPROTO_ICMP || $6 == IPPROTO_ICMPV6)
1089 && ($5 != IPSEC_PORT_ANY || $5 != IPSEC_PORT_ANY)) {
1090 yyerror("port number must be \"any\".");
1094 snprintf(portbuf, sizeof(portbuf), "%lu", $5);
1096 laddr = str2saddr($2->v, portbuf);
1097 if (laddr == NULL) {
1101 haddr = str2saddr($3->v, portbuf);
1102 if (haddr == NULL) {
1108 switch (laddr->sa_family) {
1110 if ($6 == IPPROTO_ICMPV6) {
1111 yyerror("upper layer protocol mismatched.\n");
1118 $$ = ipsecdoi_sockrange2id(laddr, haddr,
1123 if ($6 == IPPROTO_ICMP) {
1124 yyerror("upper layer protocol mismatched.\n");
1131 $$ = ipsecdoi_sockrange2id(laddr, haddr,
1136 yyerror("invalid family: %d", laddr->sa_family);
1147 | IDENTIFIERTYPE QUOTEDSTRING
1149 struct ipsecdoi_id_b *id_b;
1151 if ($1 == IDTYPE_ASN1DN) {
1152 yyerror("id type forbidden: %d", $1);
1159 $$ = vmalloc(sizeof(*id_b) + $2->l);
1161 yyerror("failed to allocate identifier");
1165 id_b = (struct ipsecdoi_id_b *)$$->v;
1166 id_b->type = idtype2doi($1);
1171 memcpy($$->v + sizeof(*id_b), $2->v, $2->l);
1177 cur_sainfo->id_i = NULL;
1180 | FROM IDENTIFIERTYPE identifierstring
1182 struct ipsecdoi_id_b *id_b;
1185 if (set_identifier(&idv, $2, $3) != 0) {
1186 yyerror("failed to set identifer.\n");
1189 cur_sainfo->id_i = vmalloc(sizeof(*id_b) + idv->l);
1190 if (cur_sainfo->id_i == NULL) {
1191 yyerror("failed to allocate identifier");
1195 id_b = (struct ipsecdoi_id_b *)cur_sainfo->id_i->v;
1196 id_b->type = idtype2doi($2);
1201 memcpy(cur_sainfo->id_i->v + sizeof(*id_b),
1205 | GROUP QUOTEDSTRING
1207 #ifdef ENABLE_HYBRID
1208 if ((cur_sainfo->group = vdup($2)) == NULL) {
1209 yyerror("failed to set sainfo xauth group.\n");
1213 yyerror("racoon not configured with --enable-hybrid");
1220 | sainfo_specs sainfo_spec
1223 : PFS_GROUP dh_group_num
1225 cur_sainfo->pfs_group = $2;
1228 | LIFETIME LIFETYPE_TIME NUMBER unittype_time
1230 cur_sainfo->lifetime = $3 * $4;
1233 | LIFETIME LIFETYPE_BYTE NUMBER unittype_byte
1236 yyerror("byte lifetime support is deprecated");
1239 cur_sainfo->lifebyte = fix_lifebyte($3 * $4);
1240 if (cur_sainfo->lifebyte == 0)
1249 | IDENTIFIER IDENTIFIERTYPE
1251 yyerror("it's deprecated to specify a identifier in phase 2");
1254 | MY_IDENTIFIER IDENTIFIERTYPE QUOTEDSTRING
1256 yyerror("it's deprecated to specify a identifier in phase 2");
1264 inssainfoalg(&cur_sainfo->algs[cur_algclass], $1);
1268 inssainfoalg(&cur_sainfo->algs[cur_algclass], $1);
1273 : ALGORITHMTYPE keylength
1277 $$ = newsainfoalg();
1279 yyerror("failed to get algorithm allocation");
1283 $$->alg = algtype2doi(cur_algclass, $1);
1284 if ($$->alg == -1) {
1285 yyerror("algorithm mismatched");
1291 defklen = default_keylen(cur_algclass, $1);
1294 yyerror("keylen not allowed");
1300 if ($2 && check_keylen(cur_algclass, $1, $2) < 0) {
1301 yyerror("invalid keylen %d", $2);
1311 $$->encklen = defklen;
1313 /* check if it's supported algorithm by kernel */
1314 if (!(cur_algclass == algclass_ipsec_auth && $1 == algtype_non_auth)
1315 && pk_checkalg(cur_algclass, $1, $$->encklen)) {
1316 int a = algclass2doi(cur_algclass);
1317 int b = algtype2doi(cur_algclass, $1);
1318 if (a == IPSECDOI_ATTR_AUTH)
1319 a = IPSECDOI_PROTO_IPSEC_AH;
1320 yyerror("algorithm %s not supported by the kernel (missing module?)",
1321 s_ipsecdoi_trns(a, b));
1329 : /* nothing */ { $$ = ~0; }
1330 | PREFIX { $$ = $1; }
1333 : /* nothing */ { $$ = IPSEC_PORT_ANY; }
1335 | PORTANY { $$ = IPSEC_PORT_ANY; }
1338 : NUMBER { $$ = $1; }
1339 | UL_PROTO { $$ = $1; }
1340 | ANY { $$ = IPSEC_ULPROTO_ANY; }
1343 : /* nothing */ { $$ = 0; }
1344 | NUMBER { $$ = $1; }
1349 : REMOTE remote_index INHERIT remote_index
1351 struct remoteconf *new;
1352 struct proposalspec *prspec;
1354 new = copyrmconf($4);
1356 yyerror("failed to get remoteconf for %s.", saddr2str ($4));
1361 new->inherited_from = getrmconf_strict($4, 1);
1362 new->proposal = NULL;
1366 prspec = newprspec();
1367 if (prspec == NULL || !cur_rmconf->inherited_from
1368 || !cur_rmconf->inherited_from->proposal)
1370 prspec->lifetime = cur_rmconf->inherited_from->proposal->lifetime;
1371 prspec->lifebyte = cur_rmconf->inherited_from->proposal->lifebyte;
1372 insprspec(prspec, &cur_rmconf->prhead);
1375 | REMOTE remote_index
1377 struct remoteconf *new;
1378 struct proposalspec *prspec;
1382 yyerror("failed to get new remoteconf.");
1389 prspec = newprspec();
1392 prspec->lifetime = oakley_get_defaultlifetime();
1393 insprspec(prspec, &cur_rmconf->prhead);
1399 : BOC remote_specs EOC
1401 /* check a exchange mode */
1402 if (cur_rmconf->etypes == NULL) {
1403 yyerror("no exchange mode specified.\n");
1407 if (cur_rmconf->idvtype == IDTYPE_UNDEFINED)
1408 cur_rmconf->idvtype = IDTYPE_ADDRESS;
1411 if (cur_rmconf->idvtype == IDTYPE_ASN1DN) {
1412 if (cur_rmconf->mycertfile
1414 || cur_rmconf->identity_in_keychain)
1417 if (cur_rmconf->idv)
1418 yywarn("Both CERT and ASN1 ID "
1419 "are set. Hope this is OK.\n");
1420 /* TODO: Preparse the DN here */
1421 } else if (cur_rmconf->idv) {
1422 /* OK, using asn1dn without X.509. */
1424 yyerror("ASN1 ID not specified "
1425 "and no CERT defined!\n");
1431 if (cur_rmconf->cert_verification_option == VERIFICATION_OPTION_PEERS_IDENTIFIER) {
1432 struct genlist_entry *gpb;
1433 if (genlist_next(cur_rmconf->idvl_p, &gpb) == NULL) {
1434 yyerror("peers_identifier required for specified certificate "
1435 "verification option.\n");
1441 if (cur_rmconf->prhead->spspec == NULL
1442 && cur_rmconf->inherited_from
1443 && cur_rmconf->inherited_from->prhead) {
1444 cur_rmconf->prhead->spspec = cur_rmconf->inherited_from->prhead->spspec;
1446 if (set_isakmp_proposal(cur_rmconf, cur_rmconf->prhead) != 0)
1449 /* DH group settting if aggressive mode is there. */
1450 if (check_etypeok(cur_rmconf, ISAKMP_ETYPE_AGG) != NULL) {
1455 for (p = cur_rmconf->proposal; p; p = p->next) {
1456 if (b == 0 || (b && b == p->dh_group)) {
1460 yyerror("DH group must be equal "
1462 "when aggressive mode is "
1466 cur_rmconf->dh_group = b;
1468 if (cur_rmconf->dh_group == 0) {
1469 yyerror("DH group must be set in the proposal.\n");
1473 /* DH group settting if PFS is required. */
1474 if (oakley_setdhgroup(cur_rmconf->dh_group,
1475 &cur_rmconf->dhgrp) < 0) {
1476 yyerror("failed to set DH value.\n");
1481 insrmconf(cur_rmconf);
1485 : ANONYMOUS ike_port
1487 $$ = newsaddr(sizeof(struct sockaddr));
1488 $$->sa_family = AF_UNSPEC;
1489 ((struct sockaddr_in *)$$)->sin_port = htons($2);
1495 yyerror("failed to allocate sockaddr");
1502 | remote_specs remote_spec
1507 cur_rmconf->etypes = NULL;
1510 | DOI DOITYPE { cur_rmconf->doitype = $2; } EOS
1511 | SITUATION SITUATIONTYPE { cur_rmconf->sittype = $2; } EOS
1512 | CERTIFICATE_TYPE cert_spec
1513 | PEERS_CERTFILE QUOTEDSTRING
1515 yywarn("This directive without certtype will be removed!\n");
1516 yywarn("Please use 'peers_certfile x509 \"%s\";' instead\n", $2->v);
1517 cur_rmconf->getcert_method = ISAKMP_GETCERT_LOCALFILE;
1519 if (cur_rmconf->peerscertfile != NULL)
1520 racoon_free(cur_rmconf->peerscertfile);
1521 cur_rmconf->peerscertfile = racoon_strdup($2->v);
1522 STRDUP_FATAL(cur_rmconf->peerscertfile);
1526 | CA_TYPE CERT_X509 QUOTEDSTRING
1528 cur_rmconf->cacerttype = $2;
1529 cur_rmconf->getcacert_method = ISAKMP_GETCERT_LOCALFILE;
1530 if (cur_rmconf->cacertfile != NULL)
1531 racoon_free(cur_rmconf->cacertfile);
1532 cur_rmconf->cacertfile = racoon_strdup($3->v);
1533 STRDUP_FATAL(cur_rmconf->cacertfile);
1537 | PEERS_CERTFILE CERT_X509 QUOTEDSTRING
1539 cur_rmconf->getcert_method = ISAKMP_GETCERT_LOCALFILE;
1540 if (cur_rmconf->peerscertfile != NULL)
1541 racoon_free(cur_rmconf->peerscertfile);
1542 cur_rmconf->peerscertfile = racoon_strdup($3->v);
1543 STRDUP_FATAL(cur_rmconf->peerscertfile);
1547 | PEERS_CERTFILE CERT_PLAINRSA QUOTEDSTRING
1549 char path[MAXPATHLEN];
1552 getpathname(path, sizeof(path),
1553 LC_PATHTYPE_CERT, $3->v);
1556 if (cur_rmconf->getcert_method == ISAKMP_GETCERT_DNS) {
1557 yyerror("Different peers_certfile method "
1558 "already defined: %d!\n",
1559 cur_rmconf->getcert_method);
1562 cur_rmconf->getcert_method = ISAKMP_GETCERT_LOCALFILE;
1563 if (rsa_parse_file(cur_rmconf->rsa_public, path, RSA_TYPE_PUBLIC)) {
1564 yyerror("Couldn't parse keyfile.\n", path);
1567 plog(LLV_DEBUG, LOCATION, NULL, "Public PlainRSA keyfile parsed: %s\n", path);
1570 | PEERS_CERTFILE DNSSEC
1572 if (cur_rmconf->getcert_method) {
1573 yyerror("Different peers_certfile method already defined!\n");
1576 cur_rmconf->getcert_method = ISAKMP_GETCERT_DNS;
1577 cur_rmconf->peerscertfile = NULL;
1580 | VERIFY_CERT SWITCH { cur_rmconf->verify_cert = $2; } EOS
1581 | SEND_CERT SWITCH { cur_rmconf->send_cert = $2; } EOS
1582 | SEND_CR SWITCH { cur_rmconf->send_cr = $2; } EOS
1583 | CERTIFICATE_VERIFICATION VERIFICATION_MODULE
1586 cur_rmconf->cert_verification = $2;
1588 yyerror("Apple specific features not compiled in.");
1592 | CERTIFICATE_VERIFICATION VERIFICATION_MODULE VERIFICATION_OPTION
1595 cur_rmconf->cert_verification = $2;
1596 cur_rmconf->cert_verification_option = $3;
1598 yyerror("Apple specific features not compiled in.");
1603 | OPEN_DIR_AUTH_GROUP QUOTEDSTRING
1605 #if defined(__APPLE__) && HAVE_OPENDIR
1606 cur_rmconf->open_dir_auth_group = $2;
1608 yyerror("Apple specific features not compiled in.");
1612 | MY_IDENTIFIER IDENTIFIERTYPE identifierstring
1614 if (set_identifier(&cur_rmconf->idv, $2, $3) != 0) {
1615 yyerror("failed to set identifer.\n");
1616 vfree($3); //%%% BUG FIX - memory leak
1619 vfree($3); //%%% BUG FIX - memory leak
1620 cur_rmconf->idvtype = $2;
1623 | MY_IDENTIFIER IDENTIFIERTYPE IDENTIFIERQUAL identifierstring
1625 if (set_identifier_qual(&cur_rmconf->idv, $2, $4, $3) != 0) {
1626 yyerror("failed to set identifer.\n");
1629 cur_rmconf->idvtype = $2;
1632 | XAUTH_LOGIN identifierstring
1634 #ifdef ENABLE_HYBRID
1635 /* formerly identifier type login */
1636 if (xauth_rmconf_used(&cur_rmconf->xauth) == -1) {
1637 yyerror("failed to allocate xauth state\n");
1640 if ((cur_rmconf->xauth->login = vdup($2)) == NULL) {
1641 yyerror("failed to set identifer.\n");
1644 vfree($2); //%%% BUG FIX - memory leak
1646 yyerror("racoon not configured with --enable-hybrid");
1650 | PEERS_IDENTIFIER IDENTIFIERTYPE identifierstring
1655 yyerror("failed to allocate idspec");
1658 if (set_identifier(&id->id, $2, $3) != 0) {
1659 yyerror("failed to set identifer.\n");
1661 vfree($3); //%%% BUG FIX - memory leak
1664 vfree($3); //%%% BUG FIX - memory leak
1666 genlist_append (cur_rmconf->idvl_p, id);
1669 | PEERS_IDENTIFIER IDENTIFIERTYPE IDENTIFIERQUAL identifierstring
1674 yyerror("failed to allocate idspec");
1677 if (set_identifier_qual(&id->id, $2, $4, $3) != 0) {
1678 yyerror("failed to set identifer.\n");
1683 genlist_append (cur_rmconf->idvl_p, id);
1686 | VERIFY_IDENTIFIER SWITCH { cur_rmconf->verify_identifier = $2; } EOS
1687 | SHARED_SECRET SECRETTYPE QUOTEDSTRING
1690 cur_rmconf->secrettype = $2;
1691 cur_rmconf->shared_secret = $3;
1693 yyerror("Apple specific features not compiled in.");
1697 | SHARED_SECRET SECRETTYPE
1700 if ($2 != SECRETTYPE_KEYCHAIN_BY_ID) {
1701 yyerror("shared secret value missing.\n");
1704 cur_rmconf->secrettype = $2;
1706 yyerror("Apple specific features not compiled in.");
1711 | NONCE_SIZE NUMBER { cur_rmconf->nonce_size = $2; } EOS
1714 yyerror("dh_group cannot be defined here.");
1718 | PASSIVE SWITCH { cur_rmconf->passive = $2; } EOS
1719 | IKE_FRAG SWITCH { cur_rmconf->ike_frag = $2; } EOS
1720 | IKE_FRAG REMOTE_FORCE_LEVEL { cur_rmconf->ike_frag = ISAKMP_FRAG_FORCE; } EOS
1722 #ifdef SADB_X_EXT_NAT_T_FRAG
1723 if (libipsec_opt & LIBIPSEC_OPT_FRAG)
1724 cur_rmconf->esp_frag = $2;
1726 yywarn("libipsec lacks IKE frag support");
1728 yywarn("Your kernel does not support esp_frag");
1731 | SCRIPT QUOTEDSTRING PHASE1_UP {
1732 if (cur_rmconf->script[SCRIPT_PHASE1_UP] != NULL)
1733 vfree(cur_rmconf->script[SCRIPT_PHASE1_UP]);
1735 cur_rmconf->script[SCRIPT_PHASE1_UP] =
1736 script_path_add(vdup($2));
1738 | SCRIPT QUOTEDSTRING PHASE1_DOWN {
1739 if (cur_rmconf->script[SCRIPT_PHASE1_DOWN] != NULL)
1740 vfree(cur_rmconf->script[SCRIPT_PHASE1_DOWN]);
1742 cur_rmconf->script[SCRIPT_PHASE1_DOWN] =
1743 script_path_add(vdup($2));
1745 | MODE_CFG SWITCH { cur_rmconf->mode_cfg = $2; } EOS
1746 | WEAK_PHASE1_CHECK SWITCH {
1747 cur_rmconf->weak_phase1_check = $2;
1749 | GENERATE_POLICY SWITCH { cur_rmconf->gen_policy = $2; } EOS
1750 | GENERATE_POLICY GENERATE_LEVEL { cur_rmconf->gen_policy = $2; } EOS
1751 | SUPPORT_PROXY SWITCH { cur_rmconf->support_proxy = $2; } EOS
1752 | INITIAL_CONTACT SWITCH { cur_rmconf->ini_contact = $2; } EOS
1753 | NAT_TRAVERSAL SWITCH
1756 cur_rmconf->nat_traversal = $2;
1758 yyerror("NAT-T support not compiled in.");
1761 | NAT_TRAVERSAL NAT_TRAVERSAL_LEVEL
1764 cur_rmconf->nat_traversal = $2;
1766 yyerror("NAT-T support not compiled in.");
1769 | NAT_TRAVERSAL_MULTI_USER SWITCH
1773 cur_rmconf->natt_multiple_user = $2;
1775 yyerror("Apple specific features not compiled in.");
1778 yyerror("NAT-T support not compiled in.");
1781 | NAT_TRAVERSAL_KEEPALIVE SWITCH
1785 cur_rmconf->natt_keepalive = $2;
1787 yyerror("Apple specific features not compiled in.");
1790 yyerror("NAT-T support not compiled in.");
1796 cur_rmconf->dpd = $2;
1798 yyerror("DPD support not compiled in.");
1804 cur_rmconf->dpd_interval = $2;
1806 yyerror("DPD support not compiled in.");
1813 cur_rmconf->dpd_retry = $2;
1815 yyerror("DPD support not compiled in.");
1819 | DPD_MAXFAIL NUMBER
1822 cur_rmconf->dpd_maxfails = $2;
1824 yyerror("DPD support not compiled in.");
1828 | DPD_ALGORITHM dpd_algo_type
1831 cur_rmconf->dpd_algo = $2;
1833 yyerror("DPD support not compiled in.");
1837 | DISCONNECT_ON_IDLE IDLE_TIMEOUT NUMBER IDLE_DIRECTION idle_dir_type
1839 cur_rmconf->idle_timeout = $3;
1840 cur_rmconf->idle_timeout_dir = $5;
1843 | LIFETIME LIFETYPE_TIME NUMBER unittype_time
1845 cur_rmconf->prhead->lifetime = $3 * $4;
1848 | PROPOSAL_CHECK PROPOSAL_CHECK_LEVEL { cur_rmconf->pcheck_level = $2; } EOS
1849 | LIFETIME LIFETYPE_BYTE NUMBER unittype_byte
1852 yyerror("byte lifetime support is deprecated in Phase1");
1855 yywarn("the lifetime of bytes in phase 1 "
1856 "will be ignored at the moment.");
1857 cur_rmconf->prhead->lifebyte = fix_lifebyte($3 * $4);
1858 if (cur_rmconf->prhead->lifebyte == 0)
1865 struct secprotospec *spspec;
1867 spspec = newspspec();
1870 insspspec(spspec, &cur_rmconf->prhead);
1872 BOC isakmpproposal_specs EOC
1876 | exchange_types EXCHANGETYPE
1879 new = racoon_malloc(sizeof(struct etypes));
1881 yyerror("failed to allocate etypes");
1886 if (cur_rmconf->etypes == NULL)
1887 cur_rmconf->etypes = new;
1890 for (p = cur_rmconf->etypes;
1899 : CERT_X509 QUOTEDSTRING QUOTEDSTRING
1901 cur_rmconf->certtype = $1;
1902 if (cur_rmconf->mycertfile != NULL)
1903 racoon_free(cur_rmconf->mycertfile);
1904 cur_rmconf->mycertfile = racoon_strdup($2->v);
1905 STRDUP_FATAL(cur_rmconf->mycertfile);
1907 if (cur_rmconf->myprivfile != NULL)
1908 racoon_free(cur_rmconf->myprivfile);
1909 cur_rmconf->myprivfile = racoon_strdup($3->v);
1910 STRDUP_FATAL(cur_rmconf->myprivfile);
1914 | CERT_X509 IN_KEYCHAIN
1917 cur_rmconf->certtype = $1;
1918 cur_rmconf->identity_in_keychain = 1;
1919 cur_rmconf->keychainCertRef = NULL;
1924 | CERT_X509 IN_KEYCHAIN QUOTEDSTRING
1928 cur_rmconf->certtype = $1;
1929 cur_rmconf->identity_in_keychain = 1;
1930 cur_rmconf->keychainCertRef = $3;
1935 | CERT_PLAINRSA QUOTEDSTRING
1937 char path[MAXPATHLEN];
1940 getpathname(path, sizeof(path),
1941 LC_PATHTYPE_CERT, $2->v);
1944 cur_rmconf->certtype = $1;
1945 cur_rmconf->send_cr = FALSE;
1946 cur_rmconf->send_cert = FALSE;
1947 cur_rmconf->verify_cert = FALSE;
1948 if (rsa_parse_file(cur_rmconf->rsa_private, path, RSA_TYPE_PRIVATE)) {
1949 yyerror("Couldn't parse keyfile.\n", path);
1952 plog(LLV_DEBUG, LOCATION, NULL, "Private PlainRSA keyfile parsed: %s\n", path);
1959 $$ = algtype2doi(algclass_isakmp_dh, $1);
1961 yyerror("must be DH group");
1967 if (ARRAYLEN(num2dhgroup) > $1 && num2dhgroup[$1] != 0) {
1968 $$ = num2dhgroup[$1];
1970 yyerror("must be DH group");
1977 : /* nothing */ { $$ = NULL; }
1978 | ADDRSTRING { $$ = $1; }
1979 | QUOTEDSTRING { $$ = $1; }
1981 isakmpproposal_specs
1983 | isakmpproposal_specs isakmpproposal_spec
1988 yyerror("strength directive is obsoleted.");
1990 | LIFETIME LIFETYPE_TIME NUMBER unittype_time
1992 cur_rmconf->prhead->spspec->lifetime = $3 * $4;
1995 | LIFETIME LIFETYPE_BYTE NUMBER unittype_byte
1998 yyerror("byte lifetime support is deprecated");
2001 cur_rmconf->prhead->spspec->lifebyte = fix_lifebyte($3 * $4);
2002 if (cur_rmconf->prhead->spspec->lifebyte == 0)
2007 | DH_GROUP dh_group_num
2009 cur_rmconf->prhead->spspec->algclass[algclass_isakmp_dh] = $2;
2012 | GSS_ID QUOTEDSTRING
2014 if (cur_rmconf->prhead->spspec->vendorid != VENDORID_GSSAPI) {
2015 yyerror("wrong Vendor ID for gssapi_id");
2018 if (cur_rmconf->prhead->spspec->gssid != NULL)
2019 racoon_free(cur_rmconf->prhead->spspec->gssid);
2020 cur_rmconf->prhead->spspec->gssid =
2021 racoon_strdup($2->v);
2022 STRDUP_FATAL(cur_rmconf->prhead->spspec->gssid);
2025 | ALGORITHM_CLASS ALGORITHMTYPE keylength
2030 doi = algtype2doi($1, $2);
2032 yyerror("algorithm mismatched 1");
2037 case algclass_isakmp_enc:
2038 /* reject suppressed algorithms */
2039 #ifndef HAVE_OPENSSL_RC5_H
2040 if ($2 == algtype_rc5) {
2041 yyerror("algorithm %s not supported",
2042 s_attr_isakmp_enc(doi));
2046 #ifndef HAVE_OPENSSL_IDEA_H
2047 if ($2 == algtype_idea) {
2048 yyerror("algorithm %s not supported",
2049 s_attr_isakmp_enc(doi));
2054 cur_rmconf->prhead->spspec->algclass[algclass_isakmp_enc] = doi;
2055 defklen = default_keylen($1, $2);
2058 yyerror("keylen not allowed");
2062 if ($3 && check_keylen($1, $2, $3) < 0) {
2063 yyerror("invalid keylen %d", $3);
2068 cur_rmconf->prhead->spspec->encklen = $3;
2070 cur_rmconf->prhead->spspec->encklen = defklen;
2072 case algclass_isakmp_hash:
2073 cur_rmconf->prhead->spspec->algclass[algclass_isakmp_hash] = doi;
2075 case algclass_isakmp_ameth:
2076 cur_rmconf->prhead->spspec->algclass[algclass_isakmp_ameth] = doi;
2078 * We may have to set the Vendor ID for the
2079 * authentication method we're using.
2082 case algtype_gssapikrb:
2083 if (cur_rmconf->prhead->spspec->vendorid !=
2085 yyerror("Vendor ID mismatch "
2090 * For interoperability with Win2k,
2091 * we set the Vendor ID to "GSSAPI".
2093 cur_rmconf->prhead->spspec->vendorid =
2096 case algtype_rsasig:
2097 if (cur_rmconf->certtype == ISAKMP_CERT_PLAINRSA) {
2098 if (rsa_list_count(cur_rmconf->rsa_private) == 0) {
2099 yyerror ("Private PlainRSA key not set. "
2100 "Use directive 'certificate_type plainrsa ...'\n");
2103 if (rsa_list_count(cur_rmconf->rsa_public) == 0) {
2104 yyerror ("Public PlainRSA keys not set. "
2105 "Use directive 'peers_certfile plainrsa ...'\n");
2115 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 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 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 yyerror("no remote specification found: %s.\n",
2232 saddr2str(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 yyerror("encryption algorithm required.");
2241 if (s->algclass[algclass_isakmp_hash] == 0) {
2242 yyerror("hash algorithm required.");
2245 if (s->algclass[algclass_isakmp_dh] == 0) {
2246 yyerror("DH group required.");
2249 if (s->algclass[algclass_isakmp_ameth] == 0) {
2250 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 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 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 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 *addr, int udp_encap)
2408 yyerror("failed to allocate myaddrs");
2412 if (p->addr == NULL) {
2413 yyerror("failed to copy sockaddr ");
2417 p->udp_encap = udp_encap;
2419 /* These need to be initialized for Apple modifications
2420 * to open code for isakmp sockets
2426 insmyaddr(p, &lcconf->myaddrs);
2428 lcconf->autograbaddr = 0;
2435 * Must be more than 1024B because its unit is kilobytes.
2436 * That is defined RFC2407.
2443 yyerror("byte size should be more than 1024B.");
2456 plog(LLV_DEBUG, LOCATION, NULL, "===== parse config\n");
2460 if (yycf_switch_buffer(lcconf->racoon_conf) != 0) {
2461 IPSECCONFIGTRACEREVENT(CONSTSTR(lcconf->racoon_conf),
2462 IPSECCONFIGEVENTCODE_PARSE_ERROR,
2463 CONSTSTR("could not read configuration file"),
2464 CONSTSTR("cfparse: yycf_switch_buffer erred"));
2465 plog(LLV_ERROR, LOCATION, NULL,
2466 "could not read configuration file \"%s\"\n",
2467 lcconf->racoon_conf);
2474 plog(LLV_ERROR, LOCATION, NULL,
2475 "fatal parse failure (%d errors)\n",
2478 plog(LLV_ERROR, LOCATION, NULL,
2479 "fatal parse failure.\n");
2481 IPSECCONFIGTRACEREVENT(CONSTSTR(lcconf->racoon_conf),
2482 IPSECCONFIGEVENTCODE_PARSE_ERROR,
2483 CONSTSTR("fatal parse failure"),
2484 CONSTSTR("cfparse: yyparse erred"));
2485 yycf_clean_buffer();
2489 if (error == 0 && yyerrorcount) {
2490 plog(LLV_ERROR, LOCATION, NULL,
2491 "parse error is nothing, but yyerrorcount is %d.\n",
2493 IPSECCONFIGTRACEREVENT(CONSTSTR(lcconf->racoon_conf),
2494 IPSECCONFIGEVENTCODE_PARSE_ERROR,
2495 CONSTSTR("ambivalent error code"),
2496 CONSTSTR("cfparse: error == 0 && yerrorcount"));
2497 yycf_clean_buffer();
2501 yycf_clean_buffer();
2503 plog(LLV_DEBUG2, LOCATION, NULL, "parse successed.\n");
2511 int ignore_established_handles = (sig == SIGUSR1);
2513 if (sig >= 0 && sig < NSIG) {
2514 plog(LLV_DEBUG, LOCATION, NULL, "==== Got %s signal - re-parsing.\n", sys_signame[sig]);
2516 plog(LLV_ERROR, LOCATION, NULL, "==== Got Unknown signal - re-parsing.\n");
2517 IPSECCONFIGTRACEREVENT(CONSTSTR("reparse"),
2518 IPSECCONFIGEVENTCODE_REPARSE_ERROR,
2519 CONSTSTR("Unknown signal"),
2520 CONSTSTR("cfreparse: triggered by unknown signal"));
2523 flushph2(ignore_established_handles);
2524 flushph1(ignore_established_handles);
2531 check_auto_exit(); /* check/change state of auto exit */
2538 #ifdef ENABLE_ADMINPORT
2540 adminsock_conf(path, owner, group, mode_dec)
2546 struct passwd *pw = NULL;
2547 struct group *gr = NULL;
2553 adminsock_path = path->v;
2559 uid = atoi(owner->v);
2561 if (((pw = getpwnam(owner->v)) == NULL) && !isnum)
2562 yyerror("User \"%s\" does not exist", owner->v);
2565 adminsock_owner = pw->pw_uid;
2567 adminsock_owner = uid;
2573 gid = atoi(group->v);
2575 if (((gr = getgrnam(group->v)) == NULL) && !isnum)
2576 yyerror("Group \"%s\" does not exist", group->v);
2579 adminsock_group = gr->gr_gid;
2581 adminsock_group = gid;
2587 yyerror("Mode 0%03o is invalid", mode_dec);
2588 if (mode_dec >= 400) { mode += 0400; mode_dec -= 400; }
2589 if (mode_dec >= 200) { mode += 0200; mode_dec -= 200; }
2590 if (mode_dec >= 100) { mode += 0200; mode_dec -= 100; }
2593 yyerror("Mode 0%03o is invalid", mode_dec);
2594 if (mode_dec >= 40) { mode += 040; mode_dec -= 40; }
2595 if (mode_dec >= 20) { mode += 020; mode_dec -= 20; }
2596 if (mode_dec >= 10) { mode += 020; mode_dec -= 10; }
2599 yyerror("Mode 0%03o is invalid", mode_dec);
2600 if (mode_dec >= 4) { mode += 04; mode_dec -= 4; }
2601 if (mode_dec >= 2) { mode += 02; mode_dec -= 2; }
2602 if (mode_dec >= 1) { mode += 02; mode_dec -= 1; }
2604 adminsock_mode = mode;