1 /* $NetBSD: cfparse.y,v 1.36 2009/01/23 08:23:51 tteras 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>
46 #include <arpa/inet.h>
68 #include "cfparse_proto.h"
69 #include "cftoken_proto.h"
70 #include "algorithm.h"
71 #include "localconf.h"
76 #include "remoteconf.h"
77 #include "grabmyaddr.h"
78 #include "isakmp_var.h"
81 #include "nattraversal.h"
82 #include "isakmp_frag.h"
85 #include "isakmp_unity.h"
86 #include "isakmp_xauth.h"
87 #include "isakmp_cfg.h"
89 #include "ipsec_doi.h"
97 #include "crypto_openssl.h"
102 int strength
; /* for isakmp/ipsec */
103 int encklen
; /* for isakmp/ipsec */
104 time_t lifetime
; /* for isakmp */
105 int lifebyte
; /* for isakmp */
106 int proto_id
; /* for ipsec (isakmp?) */
107 int ipsec_level
; /* for ipsec */
108 int encmode
; /* for ipsec */
109 int vendorid
; /* for isakmp */
111 struct sockaddr
*remote
;
112 int algclass
[MAXALGCLASS
];
114 struct secprotospec
*next
; /* the tail is the most prefiered. */
115 struct secprotospec
*prev
;
118 static int num2dhgroup
[] = {
120 OAKLEY_ATTR_GRP_DESC_MODP768
,
121 OAKLEY_ATTR_GRP_DESC_MODP1024
,
122 OAKLEY_ATTR_GRP_DESC_EC2N155
,
123 OAKLEY_ATTR_GRP_DESC_EC2N185
,
124 OAKLEY_ATTR_GRP_DESC_MODP1536
,
133 OAKLEY_ATTR_GRP_DESC_MODP2048
,
134 OAKLEY_ATTR_GRP_DESC_MODP3072
,
135 OAKLEY_ATTR_GRP_DESC_MODP4096
,
136 OAKLEY_ATTR_GRP_DESC_MODP6144
,
137 OAKLEY_ATTR_GRP_DESC_MODP8192
140 static struct remoteconf
*cur_rmconf
;
141 static int tmpalgtype
[MAXALGCLASS
];
142 static struct sainfo
*cur_sainfo
;
143 static int cur_algclass
;
144 static int oldloglevel
= LLV_BASE
;
146 static struct secprotospec
*newspspec __P
((void));
147 static void insspspec __P
((struct remoteconf
*, struct secprotospec
*));
148 static void adminsock_conf __P
((vchar_t
*, vchar_t
*, vchar_t
*, int));
150 static int set_isakmp_proposal __P
((struct remoteconf
*));
151 static void clean_tmpalgtype __P
((void));
152 static int expand_isakmpspec __P
((int, int, int *,
153 int, int, time_t, int, int, int, char *, struct remoteconf
*));
155 void freeetypes
(struct etypes
**etypes
);
157 static int load_x509
(const char *file
, char **filenameptr
,
162 getpathname
(path
, sizeof
(path
), LC_PATHTYPE_CERT
, file
);
163 *certptr
= eay_get_x509cert
(path
);
164 if
(*certptr
== NULL
)
167 *filenameptr
= racoon_strdup
(file
);
168 STRDUP_FATAL
(*filenameptr
);
178 struct remoteconf
*rmconf
;
179 struct sockaddr
*saddr
;
180 struct sainfoalg
*alg
;
184 %token PRIVSEP USER GROUP CHROOT
192 %token LOGGING LOGLEV
194 %token PADDING PAD_RANDOMIZE PAD_RANDOMIZELEN PAD_MAXLEN PAD_STRICT PAD_EXCLTAIL
196 %token LISTEN X_ISAKMP X_ISAKMP_NATT X_ADMIN STRICT_ADDRESS ADMINSOCK DISABLED
198 %token LDAPCFG LDAP_HOST LDAP_PORT LDAP_PVER LDAP_BASE LDAP_BIND_DN LDAP_BIND_PW LDAP_SUBTREE
199 %token LDAP_ATTR_USER LDAP_ATTR_ADDR LDAP_ATTR_MASK LDAP_ATTR_GROUP LDAP_ATTR_MEMBER
201 %token RADCFG RAD_AUTH RAD_ACCT RAD_TIMEOUT RAD_RETRIES
203 %token MODECFG CFG_NET4 CFG_MASK4 CFG_DNS4 CFG_NBNS4 CFG_DEFAULT_DOMAIN
204 %token CFG_AUTH_SOURCE CFG_AUTH_GROUPS CFG_SYSTEM CFG_RADIUS CFG_PAM CFG_LDAP CFG_LOCAL CFG_NONE
205 %token CFG_GROUP_SOURCE CFG_ACCOUNTING CFG_CONF_SOURCE CFG_MOTD CFG_POOL_SIZE CFG_AUTH_THROTTLE
206 %token CFG_SPLIT_NETWORK CFG_SPLIT_LOCAL CFG_SPLIT_INCLUDE CFG_SPLIT_DNS
207 %token CFG_PFS_GROUP CFG_SAVE_PASSWD
210 %token RETRY RETRY_COUNTER RETRY_INTERVAL RETRY_PERSEND
211 %token RETRY_PHASE1 RETRY_PHASE2 NATT_KA
213 %token ALGORITHM_CLASS ALGORITHMTYPE STRENGTHTYPE
217 %token REMOTE ANONYMOUS CLIENTADDR INHERIT REMOTE_ADDRESS
218 %token EXCHANGE_MODE EXCHANGETYPE DOI DOITYPE SITUATION SITUATIONTYPE
219 %token CERTIFICATE_TYPE CERTTYPE PEERS_CERTFILE CA_TYPE
220 %token VERIFY_CERT SEND_CERT SEND_CR MATCH_EMPTY_CR
221 %token IDENTIFIERTYPE IDENTIFIERQUAL MY_IDENTIFIER
222 %token PEERS_IDENTIFIER VERIFY_IDENTIFIER
223 %token DNSSEC CERT_X509 CERT_PLAINRSA
224 %token NONCE_SIZE DH_GROUP KEEPALIVE PASSIVE INITIAL_CONTACT
225 %token NAT_TRAVERSAL REMOTE_FORCE_LEVEL
226 %token PROPOSAL_CHECK PROPOSAL_CHECK_LEVEL
227 %token GENERATE_POLICY GENERATE_LEVEL SUPPORT_PROXY
229 %token EXEC_PATH EXEC_COMMAND EXEC_SUCCESS EXEC_FAILURE
230 %token GSS_ID GSS_ID_ENC GSS_ID_ENCTYPE
231 %token COMPLEX_BUNDLE
232 %token DPD DPD_DELAY DPD_RETRY DPD_MAXFAIL
234 %token XAUTH_LOGIN WEAK_PHASE1_CHECK
237 %token PREFIX PORT PORTANY UL_PROTO ANY IKE_FRAG ESP_FRAG MODE_CFG
238 %token PFS_GROUP LIFETIME LIFETYPE_TIME LIFETYPE_BYTE STRENGTH REMOTEID
240 %token SCRIPT PHASE1_UP PHASE1_DOWN
242 %token NUMBER SWITCH BOOLEAN
243 %token HEXSTRING QUOTEDSTRING ADDRSTRING ADDRRANGE
244 %token UNITTYPE_BYTE UNITTYPE_KBYTES UNITTYPE_MBYTES UNITTYPE_TBYTES
245 %token UNITTYPE_SEC UNITTYPE_MIN UNITTYPE_HOUR
246 %token EOS BOC EOC COMMA
248 %type
<num
> NUMBER BOOLEAN SWITCH keylength
249 %type
<num
> PATHTYPE IDENTIFIERTYPE IDENTIFIERQUAL LOGLEV GSS_ID_ENCTYPE
250 %type
<num
> ALGORITHM_CLASS dh_group_num
251 %type
<num
> ALGORITHMTYPE STRENGTHTYPE
252 %type
<num
> PREFIX prefix PORT port ike_port
253 %type
<num
> ul_proto UL_PROTO
254 %type
<num
> EXCHANGETYPE DOITYPE SITUATIONTYPE
255 %type
<num
> CERTTYPE CERT_X509 CERT_PLAINRSA PROPOSAL_CHECK_LEVEL REMOTE_FORCE_LEVEL GENERATE_LEVEL
256 %type
<num
> unittype_time unittype_byte
257 %type
<val
> QUOTEDSTRING HEXSTRING ADDRSTRING ADDRRANGE sainfo_id
258 %type
<val
> identifierstring
259 %type
<saddr
> remote_index ike_addrinfo_port
260 %type
<alg
> algorithm
266 | statements statement
288 : PRIVSEP BOC privsep_stmts EOC
292 | privsep_stmts privsep_stmt
299 if
((pw
= getpwnam
($2->v
)) == NULL
) {
300 yyerror("unknown user \"%s\"", $2->v
);
303 lcconf
->uid
= pw
->pw_uid
;
306 | USER NUMBER
{ lcconf
->uid
= $2; } EOS
311 if
((gr
= getgrnam
($2->v
)) == NULL
) {
312 yyerror("unknown group \"%s\"", $2->v
);
315 lcconf
->gid
= gr
->gr_gid
;
318 | GROUP NUMBER
{ lcconf
->gid
= $2; } EOS
319 | CHROOT QUOTEDSTRING
{ lcconf
->chroot
= $2->v
; } EOS
324 : PATH PATHTYPE QUOTEDSTRING
326 if
($2 >= LC_PATHTYPE_MAX
) {
327 yyerror("invalid path type %d", $2);
331 /* free old pathinfo */
332 if
(lcconf
->pathinfo
[$2])
333 racoon_free
(lcconf
->pathinfo
[$2]);
335 /* set new pathinfo */
336 lcconf
->pathinfo
[$2] = racoon_strdup
($3->v
);
337 STRDUP_FATAL
(lcconf
->pathinfo
[$2]);
345 : COMPLEX_BUNDLE SWITCH
{ lcconf
->complex_bundle
= $2; } EOS
350 : INCLUDE QUOTEDSTRING EOS
352 char path
[MAXPATHLEN
];
354 getpathname
(path
, sizeof
(path
),
355 LC_PATHTYPE_INCLUDE
, $2->v
);
357 if
(yycf_switch_buffer
(path
) != 0)
364 : PFKEY_BUFFER NUMBER EOS
366 lcconf
->pfkey_buffer_size
= $2;
371 : GSS_ID_ENC GSS_ID_ENCTYPE EOS
373 if
($2 >= LC_GSSENC_MAX
) {
374 yyerror("invalid GSS ID encoding %d", $2);
377 lcconf
->gss_id_enc
= $2;
383 : LOGGING log_level EOS
389 * set the loglevel to the value specified
390 * in the configuration file plus the number
391 * of -d options specified on the command line
393 loglevel
+= $1 - oldloglevel
;
400 : PADDING BOC padding_stmts EOC
404 | padding_stmts padding_stmt
407 : PAD_RANDOMIZE SWITCH
{ lcconf
->pad_random
= $2; } EOS
408 | PAD_RANDOMIZELEN SWITCH
{ lcconf
->pad_randomlen
= $2; } EOS
409 | PAD_MAXLEN NUMBER
{ lcconf
->pad_maxsize
= $2; } EOS
410 | PAD_STRICT SWITCH
{ lcconf
->pad_strict
= $2; } EOS
411 | PAD_EXCLTAIL SWITCH
{ lcconf
->pad_excltail
= $2; } EOS
416 : LISTEN BOC listen_stmts EOC
420 | listen_stmts listen_stmt
423 : X_ISAKMP ike_addrinfo_port
425 myaddr_listen
($2, FALSE
);
428 | X_ISAKMP_NATT ike_addrinfo_port
431 myaddr_listen
($2, TRUE
);
433 yyerror("NAT-T support not compiled in.");
437 | ADMINSOCK QUOTEDSTRING QUOTEDSTRING QUOTEDSTRING NUMBER
439 #ifdef ENABLE_ADMINPORT
440 adminsock_conf
($2, $3, $4, $5);
442 yywarn
("admin port support not compiled in");
446 | ADMINSOCK QUOTEDSTRING
448 #ifdef ENABLE_ADMINPORT
449 adminsock_conf
($2, NULL
, NULL
, -1);
451 yywarn
("admin port support not compiled in");
457 #ifdef ENABLE_ADMINPORT
458 adminsock_path
= NULL
;
460 yywarn
("admin port support not compiled in");
464 | STRICT_ADDRESS
{ lcconf
->strict_address
= TRUE
; } EOS
467 : ADDRSTRING ike_port
471 snprintf
(portbuf
, sizeof
(portbuf
), "%ld", $2);
472 $$
= str2saddr
($1->v
, portbuf
);
479 : /* nothing */ { $$
= PORT_ISAKMP
; }
483 /* radius configuration */
486 #ifndef ENABLE_HYBRID
487 yyerror("racoon not configured with --enable-hybrid");
490 #ifndef HAVE_LIBRADIUS
491 yyerror("racoon not configured with --with-libradius");
495 #ifdef HAVE_LIBRADIUS
496 xauth_rad_config.timeout
= 3;
497 xauth_rad_config.retries
= 3;
500 } BOC radcfg_stmts EOC
504 | radcfg_stmts radcfg_stmt
507 : RAD_AUTH QUOTEDSTRING QUOTEDSTRING
510 #ifdef HAVE_LIBRADIUS
511 int i
= xauth_rad_config.auth_server_count
;
512 if
(i
== RADIUS_MAX_SERVERS
) {
513 yyerror("maximum radius auth servers exceeded");
517 xauth_rad_config.auth_server_list
[i
].host
= vdup
($2);
518 xauth_rad_config.auth_server_list
[i
].secret
= vdup
($3);
519 xauth_rad_config.auth_server_list
[i
].port
= 0; // default port
520 xauth_rad_config.auth_server_count
++;
525 | RAD_AUTH QUOTEDSTRING NUMBER QUOTEDSTRING
528 #ifdef HAVE_LIBRADIUS
529 int i
= xauth_rad_config.auth_server_count
;
530 if
(i
== RADIUS_MAX_SERVERS
) {
531 yyerror("maximum radius auth servers exceeded");
535 xauth_rad_config.auth_server_list
[i
].host
= vdup
($2);
536 xauth_rad_config.auth_server_list
[i
].secret
= vdup
($4);
537 xauth_rad_config.auth_server_list
[i
].port
= $3;
538 xauth_rad_config.auth_server_count
++;
543 | RAD_ACCT QUOTEDSTRING QUOTEDSTRING
546 #ifdef HAVE_LIBRADIUS
547 int i
= xauth_rad_config.acct_server_count
;
548 if
(i
== RADIUS_MAX_SERVERS
) {
549 yyerror("maximum radius account servers exceeded");
553 xauth_rad_config.acct_server_list
[i
].host
= vdup
($2);
554 xauth_rad_config.acct_server_list
[i
].secret
= vdup
($3);
555 xauth_rad_config.acct_server_list
[i
].port
= 0; // default port
556 xauth_rad_config.acct_server_count
++;
561 | RAD_ACCT QUOTEDSTRING NUMBER QUOTEDSTRING
564 #ifdef HAVE_LIBRADIUS
565 int i
= xauth_rad_config.acct_server_count
;
566 if
(i
== RADIUS_MAX_SERVERS
) {
567 yyerror("maximum radius account servers exceeded");
571 xauth_rad_config.acct_server_list
[i
].host
= vdup
($2);
572 xauth_rad_config.acct_server_list
[i
].secret
= vdup
($4);
573 xauth_rad_config.acct_server_list
[i
].port
= $3;
574 xauth_rad_config.acct_server_count
++;
582 #ifdef HAVE_LIBRADIUS
583 xauth_rad_config.timeout
= $2;
591 #ifdef HAVE_LIBRADIUS
592 xauth_rad_config.retries
= $2;
599 /* ldap configuration */
602 #ifndef ENABLE_HYBRID
603 yyerror("racoon not configured with --enable-hybrid");
607 yyerror("racoon not configured with --with-libldap");
610 } BOC ldapcfg_stmts EOC
614 | ldapcfg_stmts ldapcfg_stmt
622 yyerror("invalid ldap protocol version (2|3)");
623 xauth_ldap_config.pver
= $2;
628 | LDAP_HOST QUOTEDSTRING
632 if
(xauth_ldap_config.host
!= NULL
)
633 vfree
(xauth_ldap_config.host
);
634 xauth_ldap_config.host
= vdup
($2);
643 xauth_ldap_config.port
= $2;
648 | LDAP_BASE QUOTEDSTRING
652 if
(xauth_ldap_config.base
!= NULL
)
653 vfree
(xauth_ldap_config.base
);
654 xauth_ldap_config.base
= vdup
($2);
659 | LDAP_SUBTREE SWITCH
663 xauth_ldap_config.subtree
= $2;
668 | LDAP_BIND_DN QUOTEDSTRING
672 if
(xauth_ldap_config.bind_dn
!= NULL
)
673 vfree
(xauth_ldap_config.bind_dn
);
674 xauth_ldap_config.bind_dn
= vdup
($2);
679 | LDAP_BIND_PW QUOTEDSTRING
683 if
(xauth_ldap_config.bind_pw
!= NULL
)
684 vfree
(xauth_ldap_config.bind_pw
);
685 xauth_ldap_config.bind_pw
= vdup
($2);
690 | LDAP_ATTR_USER QUOTEDSTRING
694 if
(xauth_ldap_config.attr_user
!= NULL
)
695 vfree
(xauth_ldap_config.attr_user
);
696 xauth_ldap_config.attr_user
= vdup
($2);
701 | LDAP_ATTR_ADDR QUOTEDSTRING
705 if
(xauth_ldap_config.attr_addr
!= NULL
)
706 vfree
(xauth_ldap_config.attr_addr
);
707 xauth_ldap_config.attr_addr
= vdup
($2);
712 | LDAP_ATTR_MASK QUOTEDSTRING
716 if
(xauth_ldap_config.attr_mask
!= NULL
)
717 vfree
(xauth_ldap_config.attr_mask
);
718 xauth_ldap_config.attr_mask
= vdup
($2);
723 | LDAP_ATTR_GROUP QUOTEDSTRING
727 if
(xauth_ldap_config.attr_group
!= NULL
)
728 vfree
(xauth_ldap_config.attr_group
);
729 xauth_ldap_config.attr_group
= vdup
($2);
734 | LDAP_ATTR_MEMBER QUOTEDSTRING
738 if
(xauth_ldap_config.attr_member
!= NULL
)
739 vfree
(xauth_ldap_config.attr_member
);
740 xauth_ldap_config.attr_member
= vdup
($2);
749 : MODECFG BOC modecfg_stmts EOC
753 | modecfg_stmts modecfg_stmt
756 : CFG_NET4 ADDRSTRING
759 if
(inet_pton
(AF_INET
, $2->v
,
760 &isakmp_cfg_config.network4
) != 1)
761 yyerror("bad IPv4 network address.");
763 yyerror("racoon not configured with --enable-hybrid");
767 | CFG_MASK4 ADDRSTRING
770 if
(inet_pton
(AF_INET
, $2->v
,
771 &isakmp_cfg_config.netmask4
) != 1)
772 yyerror("bad IPv4 netmask address.");
774 yyerror("racoon not configured with --enable-hybrid");
778 | CFG_DNS4 addrdnslist
780 | CFG_NBNS4 addrwinslist
782 | CFG_SPLIT_NETWORK CFG_SPLIT_LOCAL splitnetlist
785 isakmp_cfg_config.splitnet_type
= UNITY_LOCAL_LAN
;
787 yyerror("racoon not configured with --enable-hybrid");
791 | CFG_SPLIT_NETWORK CFG_SPLIT_INCLUDE splitnetlist
794 isakmp_cfg_config.splitnet_type
= UNITY_SPLIT_INCLUDE
;
796 yyerror("racoon not configured with --enable-hybrid");
800 | CFG_SPLIT_DNS splitdnslist
802 #ifndef ENABLE_HYBRID
803 yyerror("racoon not configured with --enable-hybrid");
807 | CFG_DEFAULT_DOMAIN QUOTEDSTRING
810 strncpy
(&isakmp_cfg_config.default_domain
[0],
812 isakmp_cfg_config.default_domain
[MAXPATHLEN
] = '\0';
815 yyerror("racoon not configured with --enable-hybrid");
819 | CFG_AUTH_SOURCE CFG_SYSTEM
822 isakmp_cfg_config.authsource
= ISAKMP_CFG_AUTH_SYSTEM
;
824 yyerror("racoon not configured with --enable-hybrid");
828 | CFG_AUTH_SOURCE CFG_RADIUS
831 #ifdef HAVE_LIBRADIUS
832 isakmp_cfg_config.authsource
= ISAKMP_CFG_AUTH_RADIUS
;
833 #else /* HAVE_LIBRADIUS */
834 yyerror("racoon not configured with --with-libradius");
835 #endif /* HAVE_LIBRADIUS */
836 #else /* ENABLE_HYBRID */
837 yyerror("racoon not configured with --enable-hybrid");
838 #endif /* ENABLE_HYBRID */
841 | CFG_AUTH_SOURCE CFG_PAM
845 isakmp_cfg_config.authsource
= ISAKMP_CFG_AUTH_PAM
;
846 #else /* HAVE_LIBPAM */
847 yyerror("racoon not configured with --with-libpam");
848 #endif /* HAVE_LIBPAM */
849 #else /* ENABLE_HYBRID */
850 yyerror("racoon not configured with --enable-hybrid");
851 #endif /* ENABLE_HYBRID */
854 | CFG_AUTH_SOURCE CFG_LDAP
858 isakmp_cfg_config.authsource
= ISAKMP_CFG_AUTH_LDAP
;
859 #else /* HAVE_LIBLDAP */
860 yyerror("racoon not configured with --with-libldap");
861 #endif /* HAVE_LIBLDAP */
862 #else /* ENABLE_HYBRID */
863 yyerror("racoon not configured with --enable-hybrid");
864 #endif /* ENABLE_HYBRID */
867 | CFG_AUTH_GROUPS authgrouplist
869 #ifndef ENABLE_HYBRID
870 yyerror("racoon not configured with --enable-hybrid");
874 | CFG_GROUP_SOURCE CFG_SYSTEM
877 isakmp_cfg_config.groupsource
= ISAKMP_CFG_GROUP_SYSTEM
;
879 yyerror("racoon not configured with --enable-hybrid");
883 | CFG_GROUP_SOURCE CFG_LDAP
887 isakmp_cfg_config.groupsource
= ISAKMP_CFG_GROUP_LDAP
;
888 #else /* HAVE_LIBLDAP */
889 yyerror("racoon not configured with --with-libldap");
890 #endif /* HAVE_LIBLDAP */
891 #else /* ENABLE_HYBRID */
892 yyerror("racoon not configured with --enable-hybrid");
893 #endif /* ENABLE_HYBRID */
896 | CFG_ACCOUNTING CFG_NONE
899 isakmp_cfg_config.accounting
= ISAKMP_CFG_ACCT_NONE
;
901 yyerror("racoon not configured with --enable-hybrid");
905 | CFG_ACCOUNTING CFG_SYSTEM
908 isakmp_cfg_config.accounting
= ISAKMP_CFG_ACCT_SYSTEM
;
910 yyerror("racoon not configured with --enable-hybrid");
914 | CFG_ACCOUNTING CFG_RADIUS
917 #ifdef HAVE_LIBRADIUS
918 isakmp_cfg_config.accounting
= ISAKMP_CFG_ACCT_RADIUS
;
919 #else /* HAVE_LIBRADIUS */
920 yyerror("racoon not configured with --with-libradius");
921 #endif /* HAVE_LIBRADIUS */
922 #else /* ENABLE_HYBRID */
923 yyerror("racoon not configured with --enable-hybrid");
924 #endif /* ENABLE_HYBRID */
927 | CFG_ACCOUNTING CFG_PAM
931 isakmp_cfg_config.accounting
= ISAKMP_CFG_ACCT_PAM
;
932 #else /* HAVE_LIBPAM */
933 yyerror("racoon not configured with --with-libpam");
934 #endif /* HAVE_LIBPAM */
935 #else /* ENABLE_HYBRID */
936 yyerror("racoon not configured with --enable-hybrid");
937 #endif /* ENABLE_HYBRID */
940 | CFG_POOL_SIZE NUMBER
943 if
(isakmp_cfg_resize_pool
($2) != 0)
944 yyerror("cannot allocate memory for pool");
945 #else /* ENABLE_HYBRID */
946 yyerror("racoon not configured with --enable-hybrid");
947 #endif /* ENABLE_HYBRID */
950 | CFG_PFS_GROUP NUMBER
953 isakmp_cfg_config.pfs_group
= $2;
954 #else /* ENABLE_HYBRID */
955 yyerror("racoon not configured with --enable-hybrid");
956 #endif /* ENABLE_HYBRID */
959 | CFG_SAVE_PASSWD SWITCH
962 isakmp_cfg_config.save_passwd
= $2;
963 #else /* ENABLE_HYBRID */
964 yyerror("racoon not configured with --enable-hybrid");
965 #endif /* ENABLE_HYBRID */
968 | CFG_AUTH_THROTTLE NUMBER
971 isakmp_cfg_config.auth_throttle
= $2;
972 #else /* ENABLE_HYBRID */
973 yyerror("racoon not configured with --enable-hybrid");
974 #endif /* ENABLE_HYBRID */
977 | CFG_CONF_SOURCE CFG_LOCAL
980 isakmp_cfg_config.confsource
= ISAKMP_CFG_CONF_LOCAL
;
981 #else /* ENABLE_HYBRID */
982 yyerror("racoon not configured with --enable-hybrid");
983 #endif /* ENABLE_HYBRID */
986 | CFG_CONF_SOURCE CFG_RADIUS
989 #ifdef HAVE_LIBRADIUS
990 isakmp_cfg_config.confsource
= ISAKMP_CFG_CONF_RADIUS
;
991 #else /* HAVE_LIBRADIUS */
992 yyerror("racoon not configured with --with-libradius");
993 #endif /* HAVE_LIBRADIUS */
994 #else /* ENABLE_HYBRID */
995 yyerror("racoon not configured with --enable-hybrid");
996 #endif /* ENABLE_HYBRID */
999 | CFG_CONF_SOURCE CFG_LDAP
1001 #ifdef ENABLE_HYBRID
1003 isakmp_cfg_config.confsource
= ISAKMP_CFG_CONF_LDAP
;
1004 #else /* HAVE_LIBLDAP */
1005 yyerror("racoon not configured with --with-libldap");
1006 #endif /* HAVE_LIBLDAP */
1007 #else /* ENABLE_HYBRID */
1008 yyerror("racoon not configured with --enable-hybrid");
1009 #endif /* ENABLE_HYBRID */
1012 | CFG_MOTD QUOTEDSTRING
1014 #ifdef ENABLE_HYBRID
1015 strncpy
(&isakmp_cfg_config.motd
[0], $2->v
, MAXPATHLEN
);
1016 isakmp_cfg_config.motd
[MAXPATHLEN
] = '\0';
1019 yyerror("racoon not configured with --enable-hybrid");
1027 | addrdns COMMA addrdnslist
1032 #ifdef ENABLE_HYBRID
1033 struct isakmp_cfg_config
*icc
= &isakmp_cfg_config
;
1035 if
(icc
->dns4_index
> MAXNS
)
1036 yyerror("No more than %d DNS", MAXNS
);
1037 if
(inet_pton
(AF_INET
, $1->v
,
1038 &icc
->dns4
[icc
->dns4_index
++]) != 1)
1039 yyerror("bad IPv4 DNS address.");
1041 yyerror("racoon not configured with --enable-hybrid");
1048 | addrwins COMMA addrwinslist
1053 #ifdef ENABLE_HYBRID
1054 struct isakmp_cfg_config
*icc
= &isakmp_cfg_config
;
1056 if
(icc
->nbns4_index
> MAXWINS
)
1057 yyerror("No more than %d WINS", MAXWINS
);
1058 if
(inet_pton
(AF_INET
, $1->v
,
1059 &icc
->nbns4
[icc
->nbns4_index
++]) != 1)
1060 yyerror("bad IPv4 WINS address.");
1062 yyerror("racoon not configured with --enable-hybrid");
1069 | splitnetlist COMMA splitnet
1074 #ifdef ENABLE_HYBRID
1075 struct isakmp_cfg_config
*icc
= &isakmp_cfg_config
;
1076 struct unity_network network
;
1077 memset
(&network
,0,sizeof
(network
));
1079 if
(inet_pton
(AF_INET
, $1->v
, &network.addr4
) != 1)
1080 yyerror("bad IPv4 SPLIT address.");
1082 /* Turn $2 (the prefix) into a subnet mask */
1083 network.mask4.s_addr
= ($2) ? htonl
(~
((1 << (32 - $2)) - 1)) : 0;
1085 /* add the network to our list */
1086 if
(splitnet_list_add
(&icc
->splitnet_list
, &network
,&icc
->splitnet_count
))
1087 yyerror("Unable to allocate split network");
1089 yyerror("racoon not configured with --enable-hybrid");
1096 | authgroup COMMA authgrouplist
1101 #ifdef ENABLE_HYBRID
1102 char * groupname
= NULL
;
1103 char ** grouplist
= NULL
;
1104 struct isakmp_cfg_config
*icc
= &isakmp_cfg_config
;
1106 grouplist
= racoon_realloc
(icc
->grouplist
,
1107 sizeof
(char**)*(icc
->groupcount
+1));
1108 if
(grouplist
== NULL
) {
1109 yyerror("unable to allocate auth group list");
1113 groupname
= racoon_malloc
($1->l
+1);
1114 if
(groupname
== NULL
) {
1115 yyerror("unable to allocate auth group name");
1119 memcpy
(groupname
,$1->v
,$1->l
);
1121 grouplist
[icc
->groupcount
]=groupname
;
1122 icc
->grouplist
= grouplist
;
1127 yyerror("racoon not configured with --enable-hybrid");
1134 | splitdns COMMA splitdnslist
1139 #ifdef ENABLE_HYBRID
1140 struct isakmp_cfg_config
*icc
= &isakmp_cfg_config
;
1142 if
(!icc
->splitdns_len
)
1144 icc
->splitdns_list
= racoon_malloc
($1->l
);
1145 if
(icc
->splitdns_list
== NULL
) {
1146 yyerror("error allocating splitdns list buffer");
1149 memcpy
(icc
->splitdns_list
,$1->v
,$1->l
);
1150 icc
->splitdns_len
= $1->l
;
1154 int len
= icc
->splitdns_len
+ $1->l
+ 1;
1155 icc
->splitdns_list
= racoon_realloc
(icc
->splitdns_list
,len
);
1156 if
(icc
->splitdns_list
== NULL
) {
1157 yyerror("error allocating splitdns list buffer");
1160 icc
->splitdns_list
[icc
->splitdns_len
] = ',';
1161 memcpy
(icc
->splitdns_list
+ icc
->splitdns_len
+ 1, $1->v
, $1->l
);
1162 icc
->splitdns_len
= len
;
1166 yyerror("racoon not configured with --enable-hybrid");
1174 : RETRY BOC timer_stmts EOC
1178 | timer_stmts timer_stmt
1181 : RETRY_COUNTER NUMBER
1183 lcconf
->retry_counter
= $2;
1186 | RETRY_INTERVAL NUMBER unittype_time
1188 lcconf
->retry_interval
= $2 * $3;
1191 | RETRY_PERSEND NUMBER
1193 lcconf
->count_persend
= $2;
1196 | RETRY_PHASE1 NUMBER unittype_time
1198 lcconf
->retry_checkph1
= $2 * $3;
1201 | RETRY_PHASE2 NUMBER unittype_time
1203 lcconf
->wait_ph2complete
= $2 * $3;
1206 | NATT_KA NUMBER unittype_time
1209 if
(libipsec_opt
& LIBIPSEC_OPT_NATT
)
1210 lcconf
->natt_ka_interval
= $2 * $3;
1212 yyerror("libipsec lacks NAT-T support");
1214 yyerror("NAT-T support not compiled in.");
1224 cur_sainfo
= newsainfo
();
1225 if
(cur_sainfo
== NULL
) {
1226 yyerror("failed to allocate sainfo");
1230 sainfo_name sainfo_param BOC sainfo_specs
1232 struct sainfo
*check
;
1235 if
(cur_sainfo
->algs
[algclass_ipsec_enc
] == 0) {
1236 yyerror("no encryption algorithm at %s",
1237 sainfo2str
(cur_sainfo
));
1240 if
(cur_sainfo
->algs
[algclass_ipsec_auth
] == 0) {
1241 yyerror("no authentication algorithm at %s",
1242 sainfo2str
(cur_sainfo
));
1245 if
(cur_sainfo
->algs
[algclass_ipsec_comp
] == 0) {
1246 yyerror("no compression algorithm at %s",
1247 sainfo2str
(cur_sainfo
));
1251 /* duplicate check */
1252 check
= getsainfo
(cur_sainfo
->idsrc
,
1256 cur_sainfo
->remoteid
);
1258 if
(check
&& ((check
->idsrc
!= SAINFO_ANONYMOUS
) &&
1259 (cur_sainfo
->idsrc
!= SAINFO_ANONYMOUS
))) {
1260 yyerror("duplicated sainfo: %s",
1261 sainfo2str
(cur_sainfo
));
1265 inssainfo
(cur_sainfo
);
1272 cur_sainfo
->idsrc
= SAINFO_ANONYMOUS
;
1273 cur_sainfo
->iddst
= SAINFO_ANONYMOUS
;
1275 | ANONYMOUS CLIENTADDR
1277 cur_sainfo
->idsrc
= SAINFO_ANONYMOUS
;
1278 cur_sainfo
->iddst
= SAINFO_CLIENTADDR
;
1280 | ANONYMOUS sainfo_id
1282 cur_sainfo
->idsrc
= SAINFO_ANONYMOUS
;
1283 cur_sainfo
->iddst
= $2;
1285 | sainfo_id ANONYMOUS
1287 cur_sainfo
->idsrc
= $1;
1288 cur_sainfo
->iddst
= SAINFO_ANONYMOUS
;
1290 | sainfo_id CLIENTADDR
1292 cur_sainfo
->idsrc
= $1;
1293 cur_sainfo
->iddst
= SAINFO_CLIENTADDR
;
1295 | sainfo_id sainfo_id
1297 cur_sainfo
->idsrc
= $1;
1298 cur_sainfo
->iddst
= $2;
1302 : IDENTIFIERTYPE ADDRSTRING prefix port ul_proto
1305 struct sockaddr
*saddr
;
1307 if
(($5 == IPPROTO_ICMP ||
$5 == IPPROTO_ICMPV6
)
1308 && ($4 != IPSEC_PORT_ANY ||
$4 != IPSEC_PORT_ANY
)) {
1309 yyerror("port number must be \"any\".");
1313 snprintf
(portbuf
, sizeof
(portbuf
), "%lu", $4);
1314 saddr
= str2saddr
($2->v
, portbuf
);
1319 switch
(saddr
->sa_family
) {
1321 if
($5 == IPPROTO_ICMPV6
) {
1322 yyerror("upper layer protocol mismatched.\n");
1326 $$
= ipsecdoi_sockaddr2id
(saddr
,
1327 $3 == ~
0 ?
(sizeof
(struct in_addr
) << 3): $3,
1332 if
($5 == IPPROTO_ICMP
) {
1333 yyerror("upper layer protocol mismatched.\n");
1337 $$
= ipsecdoi_sockaddr2id
(saddr
,
1338 $3 == ~
0 ?
(sizeof
(struct in6_addr
) << 3): $3,
1343 yyerror("invalid family: %d", saddr
->sa_family
);
1351 | IDENTIFIERTYPE ADDRSTRING ADDRRANGE prefix port ul_proto
1354 struct sockaddr
*laddr
= NULL
, *haddr
= NULL
;
1357 if
(($6 == IPPROTO_ICMP ||
$6 == IPPROTO_ICMPV6
)
1358 && ($5 != IPSEC_PORT_ANY ||
$5 != IPSEC_PORT_ANY
)) {
1359 yyerror("port number must be \"any\".");
1363 snprintf
(portbuf
, sizeof
(portbuf
), "%lu", $5);
1365 laddr
= str2saddr
($2->v
, portbuf
);
1366 if
(laddr
== NULL
) {
1370 haddr
= str2saddr
($3->v
, portbuf
);
1371 if
(haddr
== NULL
) {
1377 switch
(laddr
->sa_family
) {
1379 if
($6 == IPPROTO_ICMPV6
) {
1380 yyerror("upper layer protocol mismatched.\n");
1387 $$
= ipsecdoi_sockrange2id
(laddr
, haddr
,
1392 if
($6 == IPPROTO_ICMP
) {
1393 yyerror("upper layer protocol mismatched.\n");
1400 $$
= ipsecdoi_sockrange2id
(laddr
, haddr
,
1405 yyerror("invalid family: %d", laddr
->sa_family
);
1416 | IDENTIFIERTYPE QUOTEDSTRING
1418 struct ipsecdoi_id_b
*id_b
;
1420 if
($1 == IDTYPE_ASN1DN
) {
1421 yyerror("id type forbidden: %d", $1);
1428 $$
= vmalloc
(sizeof
(*id_b
) + $2->l
);
1430 yyerror("failed to allocate identifier");
1434 id_b
= (struct ipsecdoi_id_b
*)$$
->v
;
1435 id_b
->type
= idtype2doi
($1);
1440 memcpy
($$
->v
+ sizeof
(*id_b
), $2->v
, $2->l
);
1446 cur_sainfo
->id_i
= NULL
;
1448 | FROM IDENTIFIERTYPE identifierstring
1450 struct ipsecdoi_id_b
*id_b
;
1453 if
(set_identifier
(&idv
, $2, $3) != 0) {
1454 yyerror("failed to set identifer.\n");
1457 cur_sainfo
->id_i
= vmalloc
(sizeof
(*id_b
) + idv
->l
);
1458 if
(cur_sainfo
->id_i
== NULL
) {
1459 yyerror("failed to allocate identifier");
1463 id_b
= (struct ipsecdoi_id_b
*)cur_sainfo
->id_i
->v
;
1464 id_b
->type
= idtype2doi
($2);
1469 memcpy
(cur_sainfo
->id_i
->v
+ sizeof
(*id_b
),
1473 | GROUP QUOTEDSTRING
1475 #ifdef ENABLE_HYBRID
1476 if
((cur_sainfo
->group
= vdup
($2)) == NULL
) {
1477 yyerror("failed to set sainfo xauth group.\n");
1481 yyerror("racoon not configured with --enable-hybrid");
1488 | sainfo_specs sainfo_spec
1491 : PFS_GROUP dh_group_num
1493 cur_sainfo
->pfs_group
= $2;
1498 cur_sainfo
->remoteid
= $2;
1501 | LIFETIME LIFETYPE_TIME NUMBER unittype_time
1503 cur_sainfo
->lifetime
= $3 * $4;
1506 | LIFETIME LIFETYPE_BYTE NUMBER unittype_byte
1509 yyerror("byte lifetime support is deprecated");
1512 cur_sainfo
->lifebyte
= fix_lifebyte
($3 * $4);
1513 if
(cur_sainfo
->lifebyte
== 0)
1527 inssainfoalg
(&cur_sainfo
->algs
[cur_algclass
], $1);
1531 inssainfoalg
(&cur_sainfo
->algs
[cur_algclass
], $1);
1536 : ALGORITHMTYPE keylength
1540 $$
= newsainfoalg
();
1542 yyerror("failed to get algorithm allocation");
1546 $$
->alg
= algtype2doi
(cur_algclass
, $1);
1547 if
($$
->alg
== -1) {
1548 yyerror("algorithm mismatched");
1554 defklen
= default_keylen
(cur_algclass
, $1);
1557 yyerror("keylen not allowed");
1563 if
($2 && check_keylen
(cur_algclass
, $1, $2) < 0) {
1564 yyerror("invalid keylen %d", $2);
1574 $$
->encklen
= defklen
;
1576 /* check if it's supported algorithm by kernel */
1577 if
(!(cur_algclass
== algclass_ipsec_auth
&& $1 == algtype_non_auth
)
1578 && pk_checkalg
(cur_algclass
, $1, $$
->encklen
)) {
1579 int a
= algclass2doi
(cur_algclass
);
1580 int b
= algtype2doi
(cur_algclass
, $1);
1581 if
(a
== IPSECDOI_ATTR_AUTH
)
1582 a
= IPSECDOI_PROTO_IPSEC_AH
;
1583 yyerror("algorithm %s not supported by the kernel (missing module?)",
1584 s_ipsecdoi_trns
(a
, b
));
1592 : /* nothing */ { $$
= ~
0; }
1593 | PREFIX
{ $$
= $1; }
1596 : /* nothing */ { $$
= IPSEC_PORT_ANY
; }
1598 | PORTANY
{ $$
= IPSEC_PORT_ANY
; }
1601 : NUMBER
{ $$
= $1; }
1602 | UL_PROTO
{ $$
= $1; }
1603 | ANY
{ $$
= IPSEC_ULPROTO_ANY
; }
1606 : /* nothing */ { $$
= 0; }
1607 | NUMBER
{ $$
= $1; }
1612 : REMOTE QUOTEDSTRING INHERIT QUOTEDSTRING
1614 struct remoteconf
*from
, *new
;
1616 if
(getrmconf_by_name
($2->v
) != NULL
) {
1617 yyerror("named remoteconf \"%s\" already exists.");
1621 from
= getrmconf_by_name
($4->v
);
1623 yyerror("named parent remoteconf \"%s\" does not exist.",
1628 new
= duprmconf
(from
);
1630 yyerror("failed to duplicate remoteconf from \"%s\".",
1635 new
->name
= racoon_strdup
($2->v
);
1642 | REMOTE QUOTEDSTRING
1644 struct remoteconf
*new
;
1646 if
(getrmconf_by_name
($2->v
) != NULL
) {
1647 yyerror("Named remoteconf \"%s\" already exists.");
1653 yyerror("failed to get new remoteconf.");
1656 new
->name
= racoon_strdup
($2->v
);
1662 | REMOTE remote_index INHERIT remote_index
1664 struct remoteconf
*from
, *new
;
1666 from
= getrmconf
($4, GETRMCONF_F_NO_ANONYMOUS
);
1668 yyerror("failed to get remoteconf for %s.",
1673 new
= duprmconf
(from
);
1675 yyerror("failed to duplicate remoteconf from %s.",
1684 | REMOTE remote_index
1686 struct remoteconf
*new
;
1690 yyerror("failed to get new remoteconf.");
1701 : BOC remote_specs EOC
1703 /* check a exchange mode */
1704 if
(cur_rmconf
->etypes
== NULL
) {
1705 yyerror("no exchange mode specified.\n");
1709 if
(cur_rmconf
->idvtype
== IDTYPE_UNDEFINED
)
1710 cur_rmconf
->idvtype
= IDTYPE_ADDRESS
;
1712 if
(cur_rmconf
->idvtype
== IDTYPE_ASN1DN
) {
1713 if
(cur_rmconf
->mycertfile
) {
1714 if
(cur_rmconf
->idv
)
1715 yywarn
("Both CERT and ASN1 ID "
1716 "are set. Hope this is OK.\n");
1717 /* TODO: Preparse the DN here */
1718 } else if
(cur_rmconf
->idv
) {
1719 /* OK, using asn1dn without X.509. */
1721 yyerror("ASN1 ID not specified "
1722 "and no CERT defined!\n");
1727 if
(cur_rmconf
->spspec
== NULL
&&
1728 cur_rmconf
->inherited_from
!= NULL
) {
1729 cur_rmconf
->spspec
= cur_rmconf
->inherited_from
->spspec
;
1731 if
(set_isakmp_proposal
(cur_rmconf
) != 0)
1734 /* DH group settting if aggressive mode is there. */
1735 if
(check_etypeok
(cur_rmconf
, (void*) ISAKMP_ETYPE_AGG
)) {
1740 for
(p
= cur_rmconf
->proposal
; p
; p
= p
->next
) {
1741 if
(b
== 0 ||
(b
&& b
== p
->dh_group
)) {
1745 yyerror("DH group must be equal "
1747 "when aggressive mode is "
1751 cur_rmconf
->dh_group
= b
;
1753 if
(cur_rmconf
->dh_group
== 0) {
1754 yyerror("DH group must be set in the proposal.\n");
1758 /* DH group settting if PFS is required. */
1759 if
(oakley_setdhgroup
(cur_rmconf
->dh_group
,
1760 &cur_rmconf
->dhgrp
) < 0) {
1761 yyerror("failed to set DH value.\n");
1766 insrmconf
(cur_rmconf
);
1770 : ANONYMOUS ike_port
1772 $$
= newsaddr
(sizeof
(struct sockaddr
));
1773 $$
->sa_family
= AF_UNSPEC
;
1774 ((struct sockaddr_in
*)$$
)->sin_port
= htons
($2);
1780 yyerror("failed to allocate sockaddr");
1787 | remote_specs remote_spec
1790 : REMOTE_ADDRESS ike_addrinfo_port
1792 if
(cur_rmconf
->remote
!= NULL
) {
1793 yyerror("remote_address already specified");
1796 cur_rmconf
->remote
= $2;
1801 cur_rmconf
->etypes
= NULL
;
1804 | DOI DOITYPE
{ cur_rmconf
->doitype
= $2; } EOS
1805 | SITUATION SITUATIONTYPE
{ cur_rmconf
->sittype
= $2; } EOS
1806 | CERTIFICATE_TYPE cert_spec
1807 | PEERS_CERTFILE QUOTEDSTRING
1809 yywarn
("This directive without certtype will be removed!\n");
1810 yywarn
("Please use 'peers_certfile x509 \"%s\";' instead\n", $2->v
);
1812 if
(cur_rmconf
->peerscert
!= NULL
) {
1813 yyerror("peers_certfile already defined\n");
1817 if
(load_x509
($2->v
, &cur_rmconf
->peerscertfile
,
1818 &cur_rmconf
->peerscert
)) {
1819 yyerror("failed to load certificate \"%s\"\n",
1827 | PEERS_CERTFILE CERT_X509 QUOTEDSTRING
1829 if
(cur_rmconf
->peerscert
!= NULL
) {
1830 yyerror("peers_certfile already defined\n");
1834 if
(load_x509
($3->v
, &cur_rmconf
->peerscertfile
,
1835 &cur_rmconf
->peerscert
)) {
1836 yyerror("failed to load certificate \"%s\"\n",
1844 | PEERS_CERTFILE CERT_PLAINRSA QUOTEDSTRING
1846 char path
[MAXPATHLEN
];
1849 if
(cur_rmconf
->peerscert
!= NULL
) {
1850 yyerror("peers_certfile already defined\n");
1854 cur_rmconf
->peerscert
= vmalloc
(1);
1855 if
(cur_rmconf
->peerscert
== NULL
) {
1856 yyerror("failed to allocate peerscert");
1859 cur_rmconf
->peerscert
->v
[0] = ISAKMP_CERT_PLAINRSA
;
1861 getpathname
(path
, sizeof
(path
),
1862 LC_PATHTYPE_CERT
, $3->v
);
1863 if
(rsa_parse_file
(cur_rmconf
->rsa_public
, path
,
1865 yyerror("Couldn't parse keyfile.\n", path
);
1868 plog
(LLV_DEBUG
, LOCATION
, NULL
,
1869 "Public PlainRSA keyfile parsed: %s\n", path
);
1874 | PEERS_CERTFILE DNSSEC
1876 if
(cur_rmconf
->peerscert
!= NULL
) {
1877 yyerror("peers_certfile already defined\n");
1880 cur_rmconf
->peerscert
= vmalloc
(1);
1881 if
(cur_rmconf
->peerscert
== NULL
) {
1882 yyerror("failed to allocate peerscert");
1885 cur_rmconf
->peerscert
->v
[0] = ISAKMP_CERT_DNS
;
1888 | CA_TYPE CERT_X509 QUOTEDSTRING
1890 if
(cur_rmconf
->cacert
!= NULL
) {
1891 yyerror("ca_type already defined\n");
1895 if
(load_x509
($3->v
, &cur_rmconf
->cacertfile
,
1896 &cur_rmconf
->cacert
)) {
1897 yyerror("failed to load certificate \"%s\"\n",
1905 | VERIFY_CERT SWITCH
{ cur_rmconf
->verify_cert
= $2; } EOS
1906 | SEND_CERT SWITCH
{ cur_rmconf
->send_cert
= $2; } EOS
1907 | SEND_CR SWITCH
{ cur_rmconf
->send_cr
= $2; } EOS
1908 | MATCH_EMPTY_CR SWITCH
{ cur_rmconf
->match_empty_cr
= $2; } EOS
1909 | MY_IDENTIFIER IDENTIFIERTYPE identifierstring
1911 if
(set_identifier
(&cur_rmconf
->idv
, $2, $3) != 0) {
1912 yyerror("failed to set identifer.\n");
1915 cur_rmconf
->idvtype
= $2;
1918 | MY_IDENTIFIER IDENTIFIERTYPE IDENTIFIERQUAL identifierstring
1920 if
(set_identifier_qual
(&cur_rmconf
->idv
, $2, $4, $3) != 0) {
1921 yyerror("failed to set identifer.\n");
1924 cur_rmconf
->idvtype
= $2;
1927 | XAUTH_LOGIN identifierstring
1929 #ifdef ENABLE_HYBRID
1930 /* formerly identifier type login */
1931 if
(xauth_rmconf_used
(&cur_rmconf
->xauth
) == -1) {
1932 yyerror("failed to allocate xauth state\n");
1935 if
((cur_rmconf
->xauth
->login
= vdup
($2)) == NULL
) {
1936 yyerror("failed to set identifer.\n");
1940 yyerror("racoon not configured with --enable-hybrid");
1944 | PEERS_IDENTIFIER IDENTIFIERTYPE identifierstring
1949 yyerror("failed to allocate idspec");
1952 if
(set_identifier
(&id
->id
, $2, $3) != 0) {
1953 yyerror("failed to set identifer.\n");
1958 genlist_append
(cur_rmconf
->idvl_p
, id
);
1961 | PEERS_IDENTIFIER IDENTIFIERTYPE IDENTIFIERQUAL identifierstring
1966 yyerror("failed to allocate idspec");
1969 if
(set_identifier_qual
(&id
->id
, $2, $4, $3) != 0) {
1970 yyerror("failed to set identifer.\n");
1975 genlist_append
(cur_rmconf
->idvl_p
, id
);
1978 | VERIFY_IDENTIFIER SWITCH
{ cur_rmconf
->verify_identifier
= $2; } EOS
1979 | NONCE_SIZE NUMBER
{ cur_rmconf
->nonce_size
= $2; } EOS
1982 yyerror("dh_group cannot be defined here.");
1986 | PASSIVE SWITCH
{ cur_rmconf
->passive
= $2; } EOS
1987 | IKE_FRAG SWITCH
{ cur_rmconf
->ike_frag
= $2; } EOS
1988 | IKE_FRAG REMOTE_FORCE_LEVEL
{ cur_rmconf
->ike_frag
= ISAKMP_FRAG_FORCE
; } EOS
1990 #ifdef SADB_X_EXT_NAT_T_FRAG
1991 if
(libipsec_opt
& LIBIPSEC_OPT_FRAG
)
1992 cur_rmconf
->esp_frag
= $2;
1994 yywarn
("libipsec lacks IKE frag support");
1996 yywarn
("Your kernel does not support esp_frag");
1999 | SCRIPT QUOTEDSTRING PHASE1_UP
{
2000 if
(cur_rmconf
->script
[SCRIPT_PHASE1_UP
] != NULL
)
2001 vfree
(cur_rmconf
->script
[SCRIPT_PHASE1_UP
]);
2003 cur_rmconf
->script
[SCRIPT_PHASE1_UP
] =
2004 script_path_add
(vdup
($2));
2006 | SCRIPT QUOTEDSTRING PHASE1_DOWN
{
2007 if
(cur_rmconf
->script
[SCRIPT_PHASE1_DOWN
] != NULL
)
2008 vfree
(cur_rmconf
->script
[SCRIPT_PHASE1_DOWN
]);
2010 cur_rmconf
->script
[SCRIPT_PHASE1_DOWN
] =
2011 script_path_add
(vdup
($2));
2013 | MODE_CFG SWITCH
{ cur_rmconf
->mode_cfg
= $2; } EOS
2014 | WEAK_PHASE1_CHECK SWITCH
{
2015 cur_rmconf
->weak_phase1_check
= $2;
2017 | GENERATE_POLICY SWITCH
{ cur_rmconf
->gen_policy
= $2; } EOS
2018 | GENERATE_POLICY GENERATE_LEVEL
{ cur_rmconf
->gen_policy
= $2; } EOS
2019 | SUPPORT_PROXY SWITCH
{ cur_rmconf
->support_proxy
= $2; } EOS
2020 | INITIAL_CONTACT SWITCH
{ cur_rmconf
->ini_contact
= $2; } EOS
2021 | NAT_TRAVERSAL SWITCH
2024 if
(libipsec_opt
& LIBIPSEC_OPT_NATT
)
2025 cur_rmconf
->nat_traversal
= $2;
2027 yyerror("libipsec lacks NAT-T support");
2029 yyerror("NAT-T support not compiled in.");
2032 | NAT_TRAVERSAL REMOTE_FORCE_LEVEL
2035 if
(libipsec_opt
& LIBIPSEC_OPT_NATT
)
2036 cur_rmconf
->nat_traversal
= NATT_FORCE
;
2038 yyerror("libipsec lacks NAT-T support");
2040 yyerror("NAT-T support not compiled in.");
2046 cur_rmconf
->dpd
= $2;
2048 yyerror("DPD support not compiled in.");
2054 cur_rmconf
->dpd_interval
= $2;
2056 yyerror("DPD support not compiled in.");
2063 cur_rmconf
->dpd_retry
= $2;
2065 yyerror("DPD support not compiled in.");
2069 | DPD_MAXFAIL NUMBER
2072 cur_rmconf
->dpd_maxfails
= $2;
2074 yyerror("DPD support not compiled in.");
2078 | REKEY SWITCH
{ cur_rmconf
->rekey
= $2; } EOS
2079 | REKEY REMOTE_FORCE_LEVEL
{ cur_rmconf
->rekey
= REKEY_FORCE
; } EOS
2082 cur_rmconf
->ph1id
= $2;
2085 | LIFETIME LIFETYPE_TIME NUMBER unittype_time
2087 cur_rmconf
->lifetime
= $3 * $4;
2090 | PROPOSAL_CHECK PROPOSAL_CHECK_LEVEL
{ cur_rmconf
->pcheck_level
= $2; } EOS
2091 | LIFETIME LIFETYPE_BYTE NUMBER unittype_byte
2094 yyerror("byte lifetime support is deprecated in Phase1");
2097 yywarn
("the lifetime of bytes in phase 1 "
2098 "will be ignored at the moment.");
2099 cur_rmconf
->lifebyte
= fix_lifebyte
($3 * $4);
2100 if
(cur_rmconf
->lifebyte
== 0)
2107 struct secprotospec
*spspec
;
2109 spspec
= newspspec
();
2112 insspspec
(cur_rmconf
, spspec
);
2114 BOC isakmpproposal_specs EOC
2118 | exchange_types EXCHANGETYPE
2121 new
= racoon_malloc
(sizeof
(struct etypes
));
2123 yyerror("failed to allocate etypes");
2128 if
(cur_rmconf
->etypes
== NULL
)
2129 cur_rmconf
->etypes
= new
;
2132 for
(p
= cur_rmconf
->etypes
;
2141 : CERT_X509 QUOTEDSTRING QUOTEDSTRING
2143 if
(cur_rmconf
->mycert
!= NULL
) {
2144 yyerror("certificate_type already defined\n");
2148 if
(load_x509
($2->v
, &cur_rmconf
->mycertfile
,
2149 &cur_rmconf
->mycert
)) {
2150 yyerror("failed to load certificate \"%s\"\n",
2155 cur_rmconf
->myprivfile
= racoon_strdup
($3->v
);
2156 STRDUP_FATAL
(cur_rmconf
->myprivfile
);
2162 | CERT_PLAINRSA QUOTEDSTRING
2164 char path
[MAXPATHLEN
];
2167 if
(cur_rmconf
->mycert
!= NULL
) {
2168 yyerror("certificate_type already defined\n");
2172 cur_rmconf
->mycert
= vmalloc
(1);
2173 if
(cur_rmconf
->mycert
== NULL
) {
2174 yyerror("failed to allocate mycert");
2177 cur_rmconf
->mycert
->v
[0] = ISAKMP_CERT_PLAINRSA
;
2179 getpathname
(path
, sizeof
(path
),
2180 LC_PATHTYPE_CERT
, $2->v
);
2181 cur_rmconf
->send_cr
= FALSE
;
2182 cur_rmconf
->send_cert
= FALSE
;
2183 cur_rmconf
->verify_cert
= FALSE
;
2184 if
(rsa_parse_file
(cur_rmconf
->rsa_private
, path
,
2185 RSA_TYPE_PRIVATE
)) {
2186 yyerror("Couldn't parse keyfile.\n", path
);
2189 plog
(LLV_DEBUG
, LOCATION
, NULL
,
2190 "Private PlainRSA keyfile parsed: %s\n", path
);
2198 $$
= algtype2doi
(algclass_isakmp_dh
, $1);
2200 yyerror("must be DH group");
2206 if
(ARRAYLEN
(num2dhgroup
) > $1 && num2dhgroup
[$1] != 0) {
2207 $$
= num2dhgroup
[$1];
2209 yyerror("must be DH group");
2216 : /* nothing */ { $$
= NULL
; }
2217 | ADDRSTRING
{ $$
= $1; }
2218 | QUOTEDSTRING
{ $$
= $1; }
2220 isakmpproposal_specs
2222 | isakmpproposal_specs isakmpproposal_spec
2225 : LIFETIME LIFETYPE_TIME NUMBER unittype_time
2227 cur_rmconf
->spspec
->lifetime
= $3 * $4;
2230 | LIFETIME LIFETYPE_BYTE NUMBER unittype_byte
2233 yyerror("byte lifetime support is deprecated");
2236 cur_rmconf
->spspec
->lifebyte
= fix_lifebyte
($3 * $4);
2237 if
(cur_rmconf
->spspec
->lifebyte
== 0)
2242 | DH_GROUP dh_group_num
2244 cur_rmconf
->spspec
->algclass
[algclass_isakmp_dh
] = $2;
2247 | GSS_ID QUOTEDSTRING
2249 if
(cur_rmconf
->spspec
->vendorid
!= VENDORID_GSSAPI
) {
2250 yyerror("wrong Vendor ID for gssapi_id");
2253 if
(cur_rmconf
->spspec
->gssid
!= NULL
)
2254 racoon_free
(cur_rmconf
->spspec
->gssid
);
2255 cur_rmconf
->spspec
->gssid
=
2256 racoon_strdup
($2->v
);
2257 STRDUP_FATAL
(cur_rmconf
->spspec
->gssid
);
2260 | ALGORITHM_CLASS ALGORITHMTYPE keylength
2265 doi
= algtype2doi
($1, $2);
2267 yyerror("algorithm mismatched 1");
2272 case algclass_isakmp_enc
:
2273 /* reject suppressed algorithms */
2274 #ifndef HAVE_OPENSSL_RC5_H
2275 if
($2 == algtype_rc5
) {
2276 yyerror("algorithm %s not supported",
2277 s_attr_isakmp_enc
(doi
));
2281 #ifndef HAVE_OPENSSL_IDEA_H
2282 if
($2 == algtype_idea
) {
2283 yyerror("algorithm %s not supported",
2284 s_attr_isakmp_enc
(doi
));
2289 cur_rmconf
->spspec
->algclass
[algclass_isakmp_enc
] = doi
;
2290 defklen
= default_keylen
($1, $2);
2293 yyerror("keylen not allowed");
2297 if
($3 && check_keylen
($1, $2, $3) < 0) {
2298 yyerror("invalid keylen %d", $3);
2303 cur_rmconf
->spspec
->encklen
= $3;
2305 cur_rmconf
->spspec
->encklen
= defklen
;
2307 case algclass_isakmp_hash
:
2308 cur_rmconf
->spspec
->algclass
[algclass_isakmp_hash
] = doi
;
2310 case algclass_isakmp_ameth
:
2311 cur_rmconf
->spspec
->algclass
[algclass_isakmp_ameth
] = doi
;
2313 * We may have to set the Vendor ID for the
2314 * authentication method we're using.
2317 case algtype_gssapikrb
:
2318 if
(cur_rmconf
->spspec
->vendorid
!=
2320 yyerror("Vendor ID mismatch "
2325 * For interoperability with Win2k,
2326 * we set the Vendor ID to "GSSAPI".
2328 cur_rmconf
->spspec
->vendorid
=
2331 case algtype_rsasig
:
2332 if
(oakley_get_certtype
(cur_rmconf
->peerscert
) == ISAKMP_CERT_PLAINRSA
) {
2333 if
(rsa_list_count
(cur_rmconf
->rsa_private
) == 0) {
2334 yyerror ("Private PlainRSA key not set. "
2335 "Use directive 'certificate_type plainrsa ...'\n");
2338 if
(rsa_list_count
(cur_rmconf
->rsa_public
) == 0) {
2339 yyerror ("Public PlainRSA keys not set. "
2340 "Use directive 'peers_certfile plainrsa ...'\n");
2350 yyerror("algorithm mismatched 2");
2358 : UNITTYPE_SEC
{ $$
= 1; }
2359 | UNITTYPE_MIN
{ $$
= 60; }
2360 | UNITTYPE_HOUR
{ $$
= (60 * 60); }
2363 : UNITTYPE_BYTE
{ $$
= 1; }
2364 | UNITTYPE_KBYTES
{ $$
= 1024; }
2365 | UNITTYPE_MBYTES
{ $$
= (1024 * 1024); }
2366 | UNITTYPE_TBYTES
{ $$
= (1024 * 1024 * 1024); }
2370 static struct secprotospec
*
2373 struct secprotospec
*new
;
2375 new
= racoon_calloc
(1, sizeof
(*new
));
2377 yyerror("failed to allocate spproto");
2381 new
->encklen
= 0; /*XXX*/
2384 * Default to "uknown" vendor -- we will override this
2385 * as necessary. When we send a Vendor ID payload, an
2386 * "unknown" will be translated to a KAME/racoon ID.
2388 new
->vendorid
= VENDORID_UNKNOWN
;
2394 * insert into head of list.
2397 insspspec
(rmconf
, spspec
)
2398 struct remoteconf
*rmconf
;
2399 struct secprotospec
*spspec
;
2401 if
(rmconf
->spspec
!= NULL
)
2402 rmconf
->spspec
->prev
= spspec
;
2403 spspec
->next
= rmconf
->spspec
;
2404 rmconf
->spspec
= spspec
;
2407 /* set final acceptable proposal */
2409 set_isakmp_proposal
(rmconf
)
2410 struct remoteconf
*rmconf
;
2412 struct secprotospec
*s
;
2415 int32_t types
[MAXALGCLASS
];
2417 /* mandatory check */
2418 if
(rmconf
->spspec
== NULL
) {
2419 yyerror("no remote specification found: %s.\n",
2420 saddr2str
(rmconf
->remote
));
2423 for
(s
= rmconf
->spspec
; s
!= NULL
; s
= s
->next
) {
2424 /* XXX need more to check */
2425 if
(s
->algclass
[algclass_isakmp_enc
] == 0) {
2426 yyerror("encryption algorithm required.");
2429 if
(s
->algclass
[algclass_isakmp_hash
] == 0) {
2430 yyerror("hash algorithm required.");
2433 if
(s
->algclass
[algclass_isakmp_dh
] == 0) {
2434 yyerror("DH group required.");
2437 if
(s
->algclass
[algclass_isakmp_ameth
] == 0) {
2438 yyerror("authentication method required.");
2443 /* skip to last part */
2444 for
(s
= rmconf
->spspec
; s
->next
!= NULL
; s
= s
->next
)
2448 plog
(LLV_DEBUG2
, LOCATION
, NULL
,
2449 "lifetime = %ld\n", (long)
2450 (s
->lifetime ? s
->lifetime
: rmconf
->lifetime
));
2451 plog
(LLV_DEBUG2
, LOCATION
, NULL
,
2453 s
->lifebyte ? s
->lifebyte
: rmconf
->lifebyte
);
2454 plog
(LLV_DEBUG2
, LOCATION
, NULL
,
2455 "encklen=%d\n", s
->encklen
);
2457 memset
(types
, 0, ARRAYLEN
(types
));
2458 types
[algclass_isakmp_enc
] = s
->algclass
[algclass_isakmp_enc
];
2459 types
[algclass_isakmp_hash
] = s
->algclass
[algclass_isakmp_hash
];
2460 types
[algclass_isakmp_dh
] = s
->algclass
[algclass_isakmp_dh
];
2461 types
[algclass_isakmp_ameth
] =
2462 s
->algclass
[algclass_isakmp_ameth
];
2464 /* expanding spspec */
2466 trns_no
= expand_isakmpspec
(prop_no
, trns_no
, types
,
2467 algclass_isakmp_enc
, algclass_isakmp_ameth
+ 1,
2468 s
->lifetime ? s
->lifetime
: rmconf
->lifetime
,
2469 s
->lifebyte ? s
->lifebyte
: rmconf
->lifebyte
,
2470 s
->encklen
, s
->vendorid
, s
->gssid
,
2472 if
(trns_no
== -1) {
2473 plog
(LLV_ERROR
, LOCATION
, NULL
,
2474 "failed to expand isakmp proposal.\n");
2481 if
(rmconf
->proposal
== NULL
) {
2482 plog
(LLV_ERROR
, LOCATION
, NULL
,
2483 "no proposal found.\n");
2494 for
(i
= 0; i
< MAXALGCLASS
; i
++)
2495 tmpalgtype
[i
] = 0; /* means algorithm undefined. */
2499 expand_isakmpspec
(prop_no
, trns_no
, types
,
2500 class
, last
, lifetime
, lifebyte
, encklen
, vendorid
, gssid
,
2502 int prop_no
, trns_no
;
2503 int *types
, class
, last
;
2509 struct remoteconf
*rmconf
;
2511 struct isakmpsa
*new
;
2517 plog
(LLV_DEBUG2
, LOCATION
, NULL
,
2518 "p:%d t:%d\n", prop_no
, trns_no
);
2519 for
(j
= class
; j
< MAXALGCLASS
; j
++) {
2520 snprintf
(tb
, sizeof
(tb
), "%d", types
[j
]);
2521 plog
(LLV_DEBUG2
, LOCATION
, NULL
,
2523 s_algtype
(j
, types
[j
]),
2524 types
[j
] ?
"(" : "",
2525 tb
[0] == '0' ?
"" : tb
,
2526 types
[j
] ?
")" : "");
2528 plog
(LLV_DEBUG2
, LOCATION
, NULL
, "\n");
2531 #define TMPALGTYPE2STR(n) \
2532 s_algtype
(algclass_isakmp_
##n, types[algclass_isakmp_##n])
2533 /* check mandatory values */
2534 if
(types
[algclass_isakmp_enc
] == 0
2535 || types
[algclass_isakmp_ameth
] == 0
2536 || types
[algclass_isakmp_hash
] == 0
2537 || types
[algclass_isakmp_dh
] == 0) {
2538 yyerror("few definition of algorithm "
2539 "enc=%s ameth=%s hash=%s dhgroup=%s.\n",
2540 TMPALGTYPE2STR
(enc
),
2541 TMPALGTYPE2STR
(ameth
),
2542 TMPALGTYPE2STR
(hash
),
2543 TMPALGTYPE2STR
(dh
));
2546 #undef TMPALGTYPE2STR
2549 new
= newisakmpsa
();
2551 yyerror("failed to allocate isakmp sa");
2554 new
->prop_no
= prop_no
;
2555 new
->trns_no
= trns_no
++;
2556 new
->lifetime
= lifetime
;
2557 new
->lifebyte
= lifebyte
;
2558 new
->enctype
= types
[algclass_isakmp_enc
];
2559 new
->encklen
= encklen
;
2560 new
->authmethod
= types
[algclass_isakmp_ameth
];
2561 new
->hashtype
= types
[algclass_isakmp_hash
];
2562 new
->dh_group
= types
[algclass_isakmp_dh
];
2563 new
->vendorid
= vendorid
;
2565 if
(new
->authmethod
== OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB
) {
2566 if
(gssid
!= NULL
) {
2567 if
((new
->gssid
= vmalloc
(strlen
(gssid
))) == NULL
) {
2569 yyerror("failed to allocate gssid");
2572 memcpy
(new
->gssid
->v
, gssid
, new
->gssid
->l
);
2576 * Allocate the default ID so that it gets put
2577 * into a GSS ID attribute during the Phase 1
2580 new
->gssid
= gssapi_get_default_gss_id
();
2584 insisakmpsa
(new
, rmconf
);
2592 * Must be more than 1024B because its unit is kilobytes.
2593 * That is defined RFC2407.
2600 yyerror("byte size should be more than 1024B.");
2615 if
(yycf_switch_buffer
(lcconf
->racoon_conf
) != 0) {
2616 plog
(LLV_ERROR
, LOCATION
, NULL
,
2617 "could not read configuration file \"%s\"\n",
2618 lcconf
->racoon_conf
);
2625 plog
(LLV_ERROR
, LOCATION
, NULL
,
2626 "fatal parse failure (%d errors)\n",
2629 plog
(LLV_ERROR
, LOCATION
, NULL
,
2630 "fatal parse failure.\n");
2635 if
(error == 0 && yyerrorcount
) {
2636 plog
(LLV_ERROR
, LOCATION
, NULL
,
2637 "parse error is nothing, but yyerrorcount is %d.\n",
2642 yycf_clean_buffer
();
2644 plog
(LLV_DEBUG2
, LOCATION
, NULL
, "parse successed.\n");
2660 #ifdef ENABLE_ADMINPORT
2662 adminsock_conf
(path
, owner
, group
, mode_dec
)
2668 struct passwd
*pw
= NULL
;
2669 struct group
*gr
= NULL
;
2675 adminsock_path
= path
->v
;
2681 uid
= atoi
(owner
->v
);
2683 if
(((pw
= getpwnam
(owner
->v
)) == NULL
) && !isnum
)
2684 yyerror("User \"%s\" does not exist", owner
->v
);
2687 adminsock_owner
= pw
->pw_uid
;
2689 adminsock_owner
= uid
;
2695 gid
= atoi
(group
->v
);
2697 if
(((gr
= getgrnam
(group
->v
)) == NULL
) && !isnum
)
2698 yyerror("Group \"%s\" does not exist", group
->v
);
2701 adminsock_group
= gr
->gr_gid
;
2703 adminsock_group
= gid
;
2709 yyerror("Mode 0%03o is invalid", mode_dec
);
2710 if
(mode_dec
>= 400) { mode
+= 0400; mode_dec
-= 400; }
2711 if
(mode_dec
>= 200) { mode
+= 0200; mode_dec
-= 200; }
2712 if
(mode_dec
>= 100) { mode
+= 0200; mode_dec
-= 100; }
2715 yyerror("Mode 0%03o is invalid", mode_dec
);
2716 if
(mode_dec
>= 40) { mode
+= 040; mode_dec
-= 40; }
2717 if
(mode_dec
>= 20) { mode
+= 020; mode_dec
-= 20; }
2718 if
(mode_dec
>= 10) { mode
+= 020; mode_dec
-= 10; }
2721 yyerror("Mode 0%03o is invalid", mode_dec
);
2722 if
(mode_dec
>= 4) { mode
+= 04; mode_dec
-= 4; }
2723 if
(mode_dec
>= 2) { mode
+= 02; mode_dec
-= 2; }
2724 if
(mode_dec
>= 1) { mode
+= 02; mode_dec
-= 1; }
2726 adminsock_mode
= mode
;