1 /* $NetBSD: isakmp_xauth.c,v 1.11.6.1 2007/08/07 04:49:24 manu Exp $ */
3 /* Id: isakmp_xauth.c,v 1.38 2006/08/22 18:17:17 manubsd Exp */
6 * Copyright (C) 2004-2005 Emmanuel Dreyfus
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the project nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #include <sys/types.h>
37 #include <sys/param.h>
38 #include <sys/socket.h>
39 #include <sys/queue.h>
41 #include <netinet/in.h>
49 #if TIME_WITH_SYS_TIME
50 # include <sys/time.h>
54 # include <sys/time.h>
78 #include "crypto_openssl.h"
79 #include "isakmp_var.h"
86 #include "remoteconf.h"
87 #include "isakmp_inf.h"
88 #include "isakmp_xauth.h"
89 #include "isakmp_unity.h"
90 #include "isakmp_cfg.h"
92 #include "ipsec_doi.h"
93 #include "remoteconf.h"
94 #include "localconf.h"
95 #include "vpn_control.h"
96 #include "vpn_control_var.h"
97 #include "ipsecSessionTracer.h"
98 #include "ipsecMessageTracer.h"
100 #ifdef HAVE_LIBRADIUS
103 struct rad_handle
*radius_auth_state
= NULL
;
104 struct rad_handle
*radius_acct_state
= NULL
;
108 #include <security/pam_appl.h>
110 static char *PAM_usr
= NULL
;
111 static char *PAM_pwd
= NULL
;
112 static int PAM_conv(int, const struct pam_message
**,
113 struct pam_response
**, void *);
114 static struct pam_conv PAM_chat
= { &PAM_conv
, NULL
};
119 #include <arpa/inet.h>
120 struct xauth_ldap_config xauth_ldap_config
;
125 struct ph1handle
*iph1
;
128 struct isakmp_pl_attr
*attr
;
129 struct isakmp_data
*typeattr
;
130 struct isakmp_data
*usrattr
;
131 struct isakmp_data
*pwdattr
;
132 struct xauth_state
*xst
= &iph1
->mode_cfg
->xauth
;
136 if (iph1
->status
!= PHASE1ST_ESTABLISHED
) {
137 plog(LLV_ERROR
, LOCATION
, NULL
,
138 "Xauth request while phase 1 is not completed\n");
142 if (xst
->status
!= XAUTHST_NOTYET
) {
143 plog(LLV_ERROR
, LOCATION
, NULL
,
144 "Xauth request whith Xauth state %d\n", xst
->status
);
148 plog(LLV_INFO
, LOCATION
, NULL
, "Sending Xauth request\n");
150 tlen
= sizeof(*attr
) +
151 + sizeof(*typeattr
) +
155 if ((buffer
= vmalloc(tlen
)) == NULL
) {
156 plog(LLV_ERROR
, LOCATION
, NULL
, "Cannot allocate buffer\n");
160 attr
= (struct isakmp_pl_attr
*)buffer
->v
;
161 memset(attr
, 0, tlen
);
163 attr
->h
.len
= htons(tlen
);
164 attr
->type
= ISAKMP_CFG_REQUEST
;
165 attr
->id
= htons(eay_random());
167 typeattr
= (struct isakmp_data
*)(attr
+ 1);
168 typeattr
->type
= htons(XAUTH_TYPE
| ISAKMP_GEN_TV
);
169 typeattr
->lorv
= htons(XAUTH_TYPE_GENERIC
);
171 usrattr
= (struct isakmp_data
*)(typeattr
+ 1);
172 usrattr
->type
= htons(XAUTH_USER_NAME
| ISAKMP_GEN_TLV
);
173 usrattr
->lorv
= htons(0);
175 pwdattr
= (struct isakmp_data
*)(usrattr
+ 1);
176 pwdattr
->type
= htons(XAUTH_USER_PASSWORD
| ISAKMP_GEN_TLV
);
177 pwdattr
->lorv
= htons(0);
179 isakmp_cfg_send(iph1
, buffer
,
180 ISAKMP_NPTYPE_ATTR
, ISAKMP_FLAG_E
, 1, 0, NULL
);
184 xst
->status
= XAUTHST_REQSENT
;
190 xauth_attr_reply(iph1
, attr
, id
)
191 struct ph1handle
*iph1
;
192 struct isakmp_data
*attr
;
195 char **outlet
= NULL
;
198 struct xauth_state
*xst
= &iph1
->mode_cfg
->xauth
;
200 if ((iph1
->mode_cfg
->flags
& ISAKMP_CFG_VENDORID_XAUTH
) == 0) {
201 plog(LLV_ERROR
, LOCATION
, NULL
,
202 "Xauth reply but peer did not declare "
203 "itself as Xauth capable\n");
207 if (xst
->status
!= XAUTHST_REQSENT
) {
208 plog(LLV_ERROR
, LOCATION
, NULL
,
209 "Xauth reply while Xauth state is %d\n", xst
->status
);
213 type
= ntohs(attr
->type
) & ~ISAKMP_GEN_MASK
;
216 switch (ntohs(attr
->lorv
)) {
217 case XAUTH_TYPE_GENERIC
:
218 xst
->authtype
= XAUTH_TYPE_GENERIC
;
221 plog(LLV_WARNING
, LOCATION
, NULL
,
222 "Unexpected authentication type %d\n",
228 case XAUTH_USER_NAME
:
229 outlet
= &xst
->authdata
.generic
.usr
;
232 case XAUTH_USER_PASSWORD
:
233 outlet
= &xst
->authdata
.generic
.pwd
;
237 plog(LLV_WARNING
, LOCATION
, NULL
,
238 "ignored Xauth attribute %d\n", type
);
242 if (outlet
!= NULL
) {
243 alen
= ntohs(attr
->lorv
);
245 if ((*outlet
= racoon_realloc(*outlet
, alen
+ 1)) == NULL
) {
246 plog(LLV_ERROR
, LOCATION
, NULL
,
247 "Cannot allocate memory for Xauth Data\n");
251 memcpy(*outlet
, attr
+ 1, alen
);
252 (*outlet
)[alen
] = '\0';
257 if ((xst
->authdata
.generic
.usr
!= NULL
) &&
258 (xst
->authdata
.generic
.pwd
!= NULL
)) {
261 char *usr
= xst
->authdata
.generic
.usr
;
262 char *pwd
= xst
->authdata
.generic
.pwd
;
263 time_t throttle_delay
= 0;
265 #if 0 /* Real debug, don't do that at home */
266 plog(LLV_DEBUG
, LOCATION
, NULL
,
267 "Got username \"%s\", password \"%s\"\n", usr
, pwd
);
269 strlcpy(iph1
->mode_cfg
->login
, usr
, sizeof(iph1
->mode_cfg
->login
));
272 if ((port
= isakmp_cfg_getport(iph1
)) == -1) {
273 plog(LLV_ERROR
, LOCATION
, NULL
,
274 "Port pool depleted\n");
278 switch (isakmp_cfg_config
.authsource
) {
279 case ISAKMP_CFG_AUTH_SYSTEM
:
281 res
= privsep_xauth_login_system(usr
, pwd
);
283 res
= xauth_login_system(usr
, pwd
);
286 #ifdef HAVE_LIBRADIUS
287 case ISAKMP_CFG_AUTH_RADIUS
:
288 res
= xauth_login_radius(iph1
, usr
, pwd
);
292 case ISAKMP_CFG_AUTH_PAM
:
293 res
= privsep_xauth_login_pam(iph1
->mode_cfg
->port
,
294 iph1
->remote
, usr
, pwd
);
298 case ISAKMP_CFG_AUTH_LDAP
:
299 res
= xauth_login_ldap(iph1
, usr
, pwd
);
303 plog(LLV_ERROR
, LOCATION
, NULL
,
304 "Unexpected authentication source\n");
310 * Optional group authentication
312 if (!res
&& (isakmp_cfg_config
.groupcount
))
313 res
= group_check(iph1
,
314 isakmp_cfg_config
.grouplist
,
315 isakmp_cfg_config
.groupcount
);
318 * On failure, throttle the connexion for the remote host
319 * in order to make password attacks more difficult.
321 throttle_delay
= throttle_host(iph1
->remote
, res
) - time(NULL
);
322 if (throttle_delay
> 0) {
325 str
= saddrwop2str(iph1
->remote
);
327 plog(LLV_ERROR
, LOCATION
, NULL
,
328 "Throttling in action for %s: delay %lds\n",
329 str
, (unsigned long)throttle_delay
);
336 if (throttle_delay
!= 0) {
337 struct xauth_reply_arg
*xra
;
339 if ((xra
= racoon_malloc(sizeof(*xra
))) == NULL
) {
340 plog(LLV_ERROR
, LOCATION
, NULL
,
341 "malloc failed, bypass throttling\n");
342 return xauth_reply(iph1
, port
, id
, res
);
346 * We need to store the ph1, but it might have
347 * disapeared when xauth_reply is called, so
348 * store the index instead.
350 xra
->index
= iph1
->index
;
354 sched_new(throttle_delay
, xauth_reply_stub
, xra
);
356 return xauth_reply(iph1
, port
, id
, res
);
364 xauth_reply_stub(args
)
367 struct xauth_reply_arg
*xra
= (struct xauth_reply_arg
*)args
;
368 struct ph1handle
*iph1
;
370 if ((iph1
= getph1byindex(&xra
->index
)) != NULL
)
371 (void)xauth_reply(iph1
, xra
->port
, xra
->id
, xra
->res
);
373 plog(LLV_ERROR
, LOCATION
, NULL
,
374 "Delayed Xauth reply: phase 1 no longer exists.\n");
381 xauth_reply(iph1
, port
, id
, res
)
382 struct ph1handle
*iph1
;
386 struct xauth_state
*xst
= &iph1
->mode_cfg
->xauth
;
387 char *usr
= xst
->authdata
.generic
.usr
;
389 if (iph1
->is_dying
) {
390 plog(LLV_INFO
, LOCATION
, NULL
,
391 "dropped login for user \"%s\"\n", usr
);
397 isakmp_cfg_putport(iph1
, port
);
399 plog(LLV_INFO
, LOCATION
, NULL
,
400 "login failed for user \"%s\"\n", usr
);
402 xauth_sendstatus(iph1
, XAUTH_STATUS_FAIL
, id
);
403 xst
->status
= XAUTHST_NOTYET
;
405 /* Delete Phase 1 SA */
406 if (iph1
->status
== PHASE1ST_ESTABLISHED
)
407 isakmp_info_send_d1(iph1
);
408 isakmp_ph1expire(iph1
);
413 xst
->status
= XAUTHST_OK
;
414 plog(LLV_INFO
, LOCATION
, NULL
,
415 "login succeeded for user \"%s\"\n", usr
);
417 xauth_sendstatus(iph1
, XAUTH_STATUS_OK
, id
);
423 xauth_sendstatus(iph1
, status
, id
)
424 struct ph1handle
*iph1
;
429 struct isakmp_pl_attr
*attr
;
430 struct isakmp_data
*stattr
;
433 tlen
= sizeof(*attr
) +
436 if ((buffer
= vmalloc(tlen
)) == NULL
) {
437 plog(LLV_ERROR
, LOCATION
, NULL
, "Cannot allocate buffer\n");
441 attr
= (struct isakmp_pl_attr
*)buffer
->v
;
442 memset(attr
, 0, tlen
);
444 attr
->h
.len
= htons(tlen
);
445 attr
->type
= ISAKMP_CFG_SET
;
446 attr
->id
= htons(id
);
448 stattr
= (struct isakmp_data
*)(attr
+ 1);
449 stattr
->type
= htons(XAUTH_STATUS
| ISAKMP_GEN_TV
);
450 stattr
->lorv
= htons(status
);
452 isakmp_cfg_send(iph1
, buffer
,
453 ISAKMP_NPTYPE_ATTR
, ISAKMP_FLAG_E
, 1, 0, NULL
);
460 #ifdef HAVE_LIBRADIUS
462 xauth_radius_init(void)
464 /* For first time use, initialize Radius */
465 if ((isakmp_cfg_config
.authsource
== ISAKMP_CFG_AUTH_RADIUS
) &&
466 (radius_auth_state
== NULL
)) {
467 if ((radius_auth_state
= rad_auth_open()) == NULL
) {
468 plog(LLV_ERROR
, LOCATION
, NULL
,
469 "Cannot init libradius\n");
473 if (rad_config(radius_auth_state
, NULL
) != 0) {
474 plog(LLV_ERROR
, LOCATION
, NULL
,
475 "Cannot open librarius config file: %s\n",
476 rad_strerror(radius_auth_state
));
477 rad_close(radius_auth_state
);
478 radius_auth_state
= NULL
;
483 if ((isakmp_cfg_config
.accounting
== ISAKMP_CFG_ACCT_RADIUS
) &&
484 (radius_acct_state
== NULL
)) {
485 if ((radius_acct_state
= rad_acct_open()) == NULL
) {
486 plog(LLV_ERROR
, LOCATION
, NULL
,
487 "Cannot init libradius\n");
491 if (rad_config(radius_acct_state
, NULL
) != 0) {
492 plog(LLV_ERROR
, LOCATION
, NULL
,
493 "Cannot open librarius config file: %s\n",
494 rad_strerror(radius_acct_state
));
495 rad_close(radius_acct_state
);
496 radius_acct_state
= NULL
;
505 xauth_login_radius(iph1
, usr
, pwd
)
506 struct ph1handle
*iph1
;
515 if (rad_create_request(radius_auth_state
, RAD_ACCESS_REQUEST
) != 0) {
516 plog(LLV_ERROR
, LOCATION
, NULL
,
517 "rad_create_request failed: %s\n",
518 rad_strerror(radius_auth_state
));
522 if (rad_put_string(radius_auth_state
, RAD_USER_NAME
, usr
) != 0) {
523 plog(LLV_ERROR
, LOCATION
, NULL
,
524 "rad_put_string failed: %s\n",
525 rad_strerror(radius_auth_state
));
529 if (rad_put_string(radius_auth_state
, RAD_USER_PASSWORD
, pwd
) != 0) {
530 plog(LLV_ERROR
, LOCATION
, NULL
,
531 "rad_put_string failed: %s\n",
532 rad_strerror(radius_auth_state
));
536 if (isakmp_cfg_radius_common(radius_auth_state
, iph1
->mode_cfg
->port
) != 0)
539 switch (res
= rad_send_request(radius_auth_state
)) {
540 case RAD_ACCESS_ACCEPT
:
541 while ((type
= rad_get_attr(radius_auth_state
, &data
, &len
)) != 0) {
543 case RAD_FRAMED_IP_ADDRESS
:
544 iph1
->mode_cfg
->addr4
= rad_cvt_addr(data
);
545 iph1
->mode_cfg
->flags
546 |= ISAKMP_CFG_ADDR4_EXTERN
;
549 case RAD_FRAMED_IP_NETMASK
:
550 iph1
->mode_cfg
->mask4
= rad_cvt_addr(data
);
551 iph1
->mode_cfg
->flags
552 |= ISAKMP_CFG_MASK4_EXTERN
;
556 plog(LLV_INFO
, LOCATION
, NULL
,
557 "Unexpected attribute: %d\n", type
);
565 case RAD_ACCESS_REJECT
:
570 plog(LLV_ERROR
, LOCATION
, NULL
,
571 "rad_send_request failed: %s\n",
572 rad_strerror(radius_auth_state
));
576 plog(LLV_ERROR
, LOCATION
, NULL
,
577 "rad_send_request returned %d\n", res
);
588 PAM_conv(msg_count
, msg
, rsp
, dontcare
)
590 const struct pam_message
**msg
;
591 struct pam_response
**rsp
;
596 struct pam_response
*reply
= NULL
;
598 if ((reply
= racoon_malloc(sizeof(*reply
) * msg_count
)) == NULL
)
600 bzero(reply
, sizeof(*reply
) * msg_count
);
602 for (i
= 0; i
< msg_count
; i
++) {
603 switch (msg
[i
]->msg_style
) {
604 case PAM_PROMPT_ECHO_ON
:
605 /* Send the username, libpam frees resp */
606 reply
[i
].resp_retcode
= PAM_SUCCESS
;
607 if ((reply
[i
].resp
= strdup(PAM_usr
)) == NULL
) {
608 plog(LLV_ERROR
, LOCATION
,
609 NULL
, "strdup failed\n");
614 case PAM_PROMPT_ECHO_OFF
:
615 /* Send the password, libpam frees resp */
616 reply
[i
].resp_retcode
= PAM_SUCCESS
;
617 if ((reply
[i
].resp
= strdup(PAM_pwd
)) == NULL
) {
618 plog(LLV_ERROR
, LOCATION
,
619 NULL
, "strdup failed\n");
626 reply
[i
].resp_retcode
= PAM_SUCCESS
;
627 reply
[i
].resp
= NULL
;
645 xauth_login_pam(port
, raddr
, usr
, pwd
)
647 struct sockaddr
*raddr
;
657 pam_handle_t
*pam
= NULL
;
659 if (isakmp_cfg_config
.port_pool
== NULL
) {
660 plog(LLV_ERROR
, LOCATION
, NULL
,
661 "isakmp_cfg_config.port_pool == NULL\n");
665 if ((error
= pam_start("racoon", usr
,
666 &PAM_chat
, &isakmp_cfg_config
.port_pool
[port
].pam
)) != 0) {
667 if (isakmp_cfg_config
.port_pool
[port
].pam
== NULL
) {
668 plog(LLV_ERROR
, LOCATION
, NULL
, "pam_start failed\n");
671 plog(LLV_ERROR
, LOCATION
, NULL
,
672 "pam_start failed: %s\n",
673 pam_strerror(isakmp_cfg_config
.port_pool
[port
].pam
,
678 pam
= isakmp_cfg_config
.port_pool
[port
].pam
;
680 if ((remote
= strdup(saddrwop2str(raddr
))) == NULL
) {
681 plog(LLV_ERROR
, LOCATION
, NULL
,
682 "cannot allocate memory: %s\n", strerror(errno
));
686 if ((error
= pam_set_item(pam
, PAM_RHOST
, remote
)) != 0) {
687 plog(LLV_ERROR
, LOCATION
, NULL
,
688 "pam_set_item failed: %s\n",
689 pam_strerror(pam
, error
));
695 error
= pam_authenticate(pam
, 0);
699 plog(LLV_ERROR
, LOCATION
, NULL
,
700 "pam_authenticate failed: %s\n",
701 pam_strerror(pam
, error
));
705 if ((error
= pam_acct_mgmt(pam
, 0)) != 0) {
706 plog(LLV_ERROR
, LOCATION
, NULL
,
707 "pam_acct_mgmt failed: %s\n",
708 pam_strerror(pam
, error
));
712 if ((error
= pam_setcred(pam
, 0)) != 0) {
713 plog(LLV_ERROR
, LOCATION
, NULL
,
714 "pam_setcred failed: %s\n",
715 pam_strerror(pam
, error
));
726 isakmp_cfg_config
.port_pool
[port
].pam
= NULL
;
735 xauth_ldap_init(void)
740 xauth_ldap_config
.pver
= 3;
741 xauth_ldap_config
.host
= NULL
;
742 xauth_ldap_config
.port
= LDAP_PORT
;
743 xauth_ldap_config
.base
= NULL
;
744 xauth_ldap_config
.subtree
= 0;
745 xauth_ldap_config
.bind_dn
= NULL
;
746 xauth_ldap_config
.bind_pw
= NULL
;
747 xauth_ldap_config
.auth_type
= LDAP_AUTH_SIMPLE
;
748 xauth_ldap_config
.attr_user
= NULL
;
749 xauth_ldap_config
.attr_addr
= NULL
;
750 xauth_ldap_config
.attr_mask
= NULL
;
751 xauth_ldap_config
.attr_group
= NULL
;
752 xauth_ldap_config
.attr_member
= NULL
;
754 /* set default host */
755 tmplen
= strlen(LDAP_DFLT_HOST
);
756 xauth_ldap_config
.host
= vmalloc(tmplen
);
757 if (xauth_ldap_config
.host
== NULL
)
759 memcpy(xauth_ldap_config
.host
->v
, LDAP_DFLT_HOST
, tmplen
);
761 /* set default user naming attribute */
762 tmplen
= strlen(LDAP_DFLT_USER
);
763 xauth_ldap_config
.attr_user
= vmalloc(tmplen
);
764 if (xauth_ldap_config
.attr_user
== NULL
)
766 memcpy(xauth_ldap_config
.attr_user
->v
, LDAP_DFLT_USER
, tmplen
);
768 /* set default address attribute */
769 tmplen
= strlen(LDAP_DFLT_ADDR
);
770 xauth_ldap_config
.attr_addr
= vmalloc(tmplen
);
771 if (xauth_ldap_config
.attr_addr
== NULL
)
773 memcpy(xauth_ldap_config
.attr_addr
->v
, LDAP_DFLT_ADDR
, tmplen
);
775 /* set default netmask attribute */
776 tmplen
= strlen(LDAP_DFLT_MASK
);
777 xauth_ldap_config
.attr_mask
= vmalloc(tmplen
);
778 if (xauth_ldap_config
.attr_mask
== NULL
)
780 memcpy(xauth_ldap_config
.attr_mask
->v
, LDAP_DFLT_MASK
, tmplen
);
782 /* set default group naming attribute */
783 tmplen
= strlen(LDAP_DFLT_GROUP
);
784 xauth_ldap_config
.attr_group
= vmalloc(tmplen
);
785 if (xauth_ldap_config
.attr_group
== NULL
)
787 memcpy(xauth_ldap_config
.attr_group
->v
, LDAP_DFLT_GROUP
, tmplen
);
789 /* set default member attribute */
790 tmplen
= strlen(LDAP_DFLT_MEMBER
);
791 xauth_ldap_config
.attr_member
= vmalloc(tmplen
);
792 if (xauth_ldap_config
.attr_member
== NULL
)
794 memcpy(xauth_ldap_config
.attr_member
->v
, LDAP_DFLT_MEMBER
, tmplen
);
799 plog(LLV_ERROR
, LOCATION
, NULL
, "cannot allocate memory\n");
805 xauth_ldap_flush(void)
807 if (xauth_ldap_config
.host
) {
808 vfree(xauth_ldap_config
.host
);
809 xauth_ldap_config
.host
= NULL
;
811 if (xauth_ldap_config
.base
) {
812 vfree(xauth_ldap_config
.base
);
813 xauth_ldap_config
.base
= NULL
;
815 if (xauth_ldap_config
.bind_dn
) {
816 vfree(xauth_ldap_config
.bind_dn
);
817 xauth_ldap_config
.bind_dn
= NULL
;
819 if (xauth_ldap_config
.bind_pw
) {
820 vfree(xauth_ldap_config
.bind_pw
);
821 xauth_ldap_config
.bind_pw
= NULL
;
823 if (xauth_ldap_config
.attr_user
) {
824 vfree(xauth_ldap_config
.attr_user
);
825 xauth_ldap_config
.attr_user
= NULL
;
827 if (xauth_ldap_config
.attr_addr
) {
828 vfree(xauth_ldap_config
.attr_addr
);
829 xauth_ldap_config
.attr_addr
= NULL
;
831 if (xauth_ldap_config
.attr_mask
) {
832 vfree(xauth_ldap_config
.attr_mask
);
833 xauth_ldap_config
.attr_mask
= NULL
;
835 if (xauth_ldap_config
.attr_group
) {
836 vfree(xauth_ldap_config
.attr_group
);
837 xauth_ldap_config
.attr_group
= NULL
;
839 if (xauth_ldap_config
.attr_member
) {
840 vfree(xauth_ldap_config
.attr_member
);
841 xauth_ldap_config
.attr_member
= NULL
;
846 xauth_login_ldap(iph1
, usr
, pwd
)
847 struct ph1handle
*iph1
;
854 LDAPMessage
*lr
= NULL
;
855 LDAPMessage
*le
= NULL
;
857 struct berval
**bv
= NULL
;
858 struct timeval timeout
;
862 int atlist_len
[sizeof(atlist
)/sizeof(__typeof__(*atlist
))];
868 int scope
= LDAP_SCOPE_ONE
;
877 /* build our initialization url */
878 tmplen
= strlen("ldap://:") + 17;
879 tmplen
+= strlen(xauth_ldap_config
.host
->v
);
880 init
= racoon_malloc(tmplen
);
882 plog(LLV_ERROR
, LOCATION
, NULL
,
883 "unable to alloc ldap init url\n");
886 snprintf(init
, tmplen
, "ldap://%s:%d",
887 xauth_ldap_config
.host
->v
,
888 xauth_ldap_config
.port
);
890 /* initialize the ldap handle */
891 res
= ldap_initialize(&ld
, init
);
892 if (res
!= LDAP_SUCCESS
) {
893 plog(LLV_ERROR
, LOCATION
, NULL
,
894 "ldap_initialize failed: %s\n",
895 ldap_err2string(res
));
899 /* initialize the protocol version */
900 ldap_set_option(ld
, LDAP_OPT_PROTOCOL_VERSION
,
901 &xauth_ldap_config
.pver
);
904 * attempt to bind to the ldap server.
905 * default to anonymous bind unless a
906 * user dn and password has been
907 * specified in our configuration
909 if ((xauth_ldap_config
.bind_dn
!= NULL
)&&
910 (xauth_ldap_config
.bind_pw
!= NULL
))
912 cred
.bv_val
= xauth_ldap_config
.bind_pw
->v
;
913 cred
.bv_len
= strlen( cred
.bv_val
);
914 res
= ldap_sasl_bind_s(ld
,
915 xauth_ldap_config
.bind_dn
->v
, NULL
, &cred
,
920 res
= ldap_sasl_bind_s(ld
,
925 if (res
!=LDAP_SUCCESS
) {
926 plog(LLV_ERROR
, LOCATION
, NULL
,
927 "ldap_sasl_bind_s (search) failed: %s\n",
928 ldap_err2string(res
));
932 /* build an ldap user search filter */
933 tmplen
= strlen(xauth_ldap_config
.attr_user
->v
);
935 tmplen
+= strlen(usr
);
937 filter
= racoon_malloc(tmplen
);
938 if (filter
== NULL
) {
939 plog(LLV_ERROR
, LOCATION
, NULL
,
940 "unable to alloc ldap search filter buffer\n");
943 snprintf(filter
, tmplen
, "%s=%s",
944 xauth_ldap_config
.attr_user
->v
, usr
);
946 /* build our return attribute list */
947 atlist_len
[0] = strlen(xauth_ldap_config
.attr_addr
->v
) + 1;
948 atlist
[0] = racoon_malloc(atlist_len
[0]);
949 atlist_len
[1] = strlen(xauth_ldap_config
.attr_mask
->v
) + 1;
950 atlist
[1] = racoon_malloc(atlist_len
[1]);
951 if ((atlist
[0] == NULL
)||(atlist
[1] == NULL
)) {
952 plog(LLV_ERROR
, LOCATION
, NULL
,
953 "unable to alloc ldap attrib list buffer\n");
956 strlcpy(atlist
[0],xauth_ldap_config
.attr_addr
->v
,atlist_len
[0]);
957 strlcpy(atlist
[1],xauth_ldap_config
.attr_mask
->v
,atlist_len
[1]);
959 /* attempt to locate the user dn */
960 if (xauth_ldap_config
.base
!= NULL
)
961 basedn
= xauth_ldap_config
.base
->v
;
962 if (xauth_ldap_config
.subtree
)
963 scope
= LDAP_SCOPE_SUBTREE
;
966 res
= ldap_search_ext_s(ld
, basedn
, scope
,
967 filter
, atlist
, 0, NULL
, NULL
,
969 if (res
!= LDAP_SUCCESS
) {
970 plog(LLV_ERROR
, LOCATION
, NULL
,
971 "ldap_search_ext_s failed: %s\n",
972 ldap_err2string(res
));
976 /* check the number of ldap entries returned */
977 ecount
= ldap_count_entries(ld
, lr
);
979 plog(LLV_WARNING
, LOCATION
, NULL
,
980 "no ldap results for filter \'%s\'\n",
985 plog(LLV_WARNING
, LOCATION
, NULL
,
986 "multiple (%i) ldap results for filter \'%s\'\n",
990 /* obtain the dn from the first result */
991 le
= ldap_first_entry(ld
, lr
);
993 plog(LLV_ERROR
, LOCATION
, NULL
,
994 "ldap_first_entry failed: invalid entry returned\n");
997 userdn
= ldap_get_dn(ld
, le
);
998 if (userdn
== NULL
) {
999 plog(LLV_ERROR
, LOCATION
, NULL
,
1000 "ldap_get_dn failed: invalid string returned\n");
1004 /* cache the user dn in the xauth state */
1005 udn_len
= strlen(userdn
)+1;
1006 iph1
->mode_cfg
->xauth
.udn
= racoon_malloc(udn_len
);
1007 strlcpy(iph1
->mode_cfg
->xauth
.udn
,userdn
,udn_len
);
1009 /* retrieve modecfg address */
1010 bv
= ldap_get_values_len(ld
, le
, xauth_ldap_config
.attr_addr
->v
);
1013 /* sanity check for address value */
1014 if ((bv
[0]->bv_len
< 7)||(bv
[0]->bv_len
> 15)) {
1015 plog(LLV_DEBUG
, LOCATION
, NULL
,
1016 "ldap returned invalid modecfg address\n");
1017 ldap_value_free_len(bv
);
1020 memcpy(tmpaddr
,bv
[0]->bv_val
,bv
[0]->bv_len
);
1021 tmpaddr
[bv
[0]->bv_len
]=0;
1022 iph1
->mode_cfg
->addr4
.s_addr
= inet_addr(tmpaddr
);
1023 iph1
->mode_cfg
->flags
|= ISAKMP_CFG_ADDR4_EXTERN
;
1024 plog(LLV_INFO
, LOCATION
, NULL
,
1025 "ldap returned modecfg address %s\n", tmpaddr
);
1026 ldap_value_free_len(bv
);
1029 /* retrieve modecfg netmask */
1030 bv
= ldap_get_values_len(ld
, le
, xauth_ldap_config
.attr_mask
->v
);
1033 /* sanity check for netmask value */
1034 if ((bv
[0]->bv_len
< 7)||(bv
[0]->bv_len
> 15)) {
1035 plog(LLV_DEBUG
, LOCATION
, NULL
,
1036 "ldap returned invalid modecfg netmask\n");
1037 ldap_value_free_len(bv
);
1040 memcpy(tmpmask
,bv
[0]->bv_val
,bv
[0]->bv_len
);
1041 tmpmask
[bv
[0]->bv_len
]=0;
1042 iph1
->mode_cfg
->mask4
.s_addr
= inet_addr(tmpmask
);
1043 iph1
->mode_cfg
->flags
|= ISAKMP_CFG_MASK4_EXTERN
;
1044 plog(LLV_INFO
, LOCATION
, NULL
,
1045 "ldap returned modecfg netmask %s\n", tmpmask
);
1046 ldap_value_free_len(bv
);
1050 * finally, use the dn and the xauth
1051 * password to check the users given
1052 * credentials by attempting to bind
1053 * to the ldap server
1055 plog(LLV_INFO
, LOCATION
, NULL
,
1056 "attempting ldap bind for dn \'%s\'\n", userdn
);
1058 cred
.bv_len
= strlen( cred
.bv_val
);
1059 res
= ldap_sasl_bind_s(ld
,
1060 userdn
, NULL
, &cred
,
1062 if(res
==LDAP_SUCCESS
)
1067 /* free ldap resources */
1069 ldap_memfree(userdn
);
1070 if (atlist
[0] != NULL
)
1071 racoon_free(atlist
[0]);
1072 if (atlist
[1] != NULL
)
1073 racoon_free(atlist
[1]);
1075 racoon_free(filter
);
1081 ldap_unbind_ext_s(ld
, NULL
, NULL
);
1087 xauth_group_ldap(udn
, grp
)
1094 LDAPMessage
*lr
= NULL
;
1095 LDAPMessage
*le
= NULL
;
1097 struct timeval timeout
;
1099 char *filter
= NULL
;
1100 char *basedn
= NULL
;
1101 char *groupdn
= NULL
;
1104 int scope
= LDAP_SCOPE_ONE
;
1106 /* build our initialization url */
1107 tmplen
= strlen("ldap://:") + 17;
1108 tmplen
+= strlen(xauth_ldap_config
.host
->v
);
1109 init
= racoon_malloc(tmplen
);
1111 plog(LLV_ERROR
, LOCATION
, NULL
,
1112 "unable to alloc ldap init url\n");
1113 goto ldap_group_end
;
1115 snprintf(init
, tmplen
, "ldap://%s:%d",
1116 xauth_ldap_config
.host
->v
,
1117 xauth_ldap_config
.port
);
1119 /* initialize the ldap handle */
1120 res
= ldap_initialize(&ld
, init
);
1121 if (res
!= LDAP_SUCCESS
) {
1122 plog(LLV_ERROR
, LOCATION
, NULL
,
1123 "ldap_initialize failed: %s\n",
1124 ldap_err2string(res
));
1125 goto ldap_group_end
;
1128 /* initialize the protocol version */
1129 ldap_set_option(ld
, LDAP_OPT_PROTOCOL_VERSION
,
1130 &xauth_ldap_config
.pver
);
1133 * attempt to bind to the ldap server.
1134 * default to anonymous bind unless a
1135 * user dn and password has been
1136 * specified in our configuration
1138 if ((xauth_ldap_config
.bind_dn
!= NULL
)&&
1139 (xauth_ldap_config
.bind_pw
!= NULL
))
1141 cred
.bv_val
= xauth_ldap_config
.bind_pw
->v
;
1142 cred
.bv_len
= strlen( cred
.bv_val
);
1143 res
= ldap_sasl_bind_s(ld
,
1144 xauth_ldap_config
.bind_dn
->v
, NULL
, &cred
,
1149 res
= ldap_sasl_bind_s(ld
,
1154 if (res
!=LDAP_SUCCESS
) {
1155 plog(LLV_ERROR
, LOCATION
, NULL
,
1156 "ldap_sasl_bind_s (search) failed: %s\n",
1157 ldap_err2string(res
));
1158 goto ldap_group_end
;
1161 /* build an ldap group search filter */
1162 tmplen
= strlen("(&(=)(=))") + 1;
1163 tmplen
+= strlen(xauth_ldap_config
.attr_group
->v
);
1164 tmplen
+= strlen(grp
);
1165 tmplen
+= strlen(xauth_ldap_config
.attr_member
->v
);
1166 tmplen
+= strlen(udn
);
1167 filter
= racoon_malloc(tmplen
);
1168 if (filter
== NULL
) {
1169 plog(LLV_ERROR
, LOCATION
, NULL
,
1170 "unable to alloc ldap search filter buffer\n");
1171 goto ldap_group_end
;
1173 snprintf(filter
, tmplen
, "(&(%s=%s)(%s=%s))",
1174 xauth_ldap_config
.attr_group
->v
, grp
,
1175 xauth_ldap_config
.attr_member
->v
, udn
);
1177 /* attempt to locate the group dn */
1178 if (xauth_ldap_config
.base
!= NULL
)
1179 basedn
= xauth_ldap_config
.base
->v
;
1180 if (xauth_ldap_config
.subtree
)
1181 scope
= LDAP_SCOPE_SUBTREE
;
1182 timeout
.tv_sec
= 15;
1183 timeout
.tv_usec
= 0;
1184 res
= ldap_search_ext_s(ld
, basedn
, scope
,
1185 filter
, NULL
, 0, NULL
, NULL
,
1187 if (res
!= LDAP_SUCCESS
) {
1188 plog(LLV_ERROR
, LOCATION
, NULL
,
1189 "ldap_search_ext_s failed: %s\n",
1190 ldap_err2string(res
));
1191 goto ldap_group_end
;
1194 /* check the number of ldap entries returned */
1195 ecount
= ldap_count_entries(ld
, lr
);
1197 plog(LLV_WARNING
, LOCATION
, NULL
,
1198 "no ldap results for filter \'%s\'\n",
1200 goto ldap_group_end
;
1206 /* obtain the dn from the first result */
1207 le
= ldap_first_entry(ld
, lr
);
1209 plog(LLV_ERROR
, LOCATION
, NULL
,
1210 "ldap_first_entry failed: invalid entry returned\n");
1211 goto ldap_group_end
;
1213 groupdn
= ldap_get_dn(ld
, le
);
1214 if (groupdn
== NULL
) {
1215 plog(LLV_ERROR
, LOCATION
, NULL
,
1216 "ldap_get_dn failed: invalid string returned\n");
1217 goto ldap_group_end
;
1220 plog(LLV_INFO
, LOCATION
, NULL
,
1221 "ldap membership group returned \'%s\'\n", groupdn
);
1224 /* free ldap resources */
1225 if (groupdn
!= NULL
)
1226 ldap_memfree(groupdn
);
1228 racoon_free(filter
);
1234 ldap_unbind_ext_s(ld
, NULL
, NULL
);
1242 xauth_login_system(usr
, pwd
)
1249 #ifdef HAVE_SHADOW_H
1252 if ((spw
= getspnam(usr
)) == NULL
)
1255 syscryptpwd
= spw
->sp_pwdp
;
1258 if ((pw
= getpwnam(usr
)) == NULL
)
1261 #ifndef HAVE_SHADOW_H
1262 syscryptpwd
= pw
->pw_passwd
;
1265 /* No root login. Ever. */
1266 if (pw
->pw_uid
== 0)
1269 if ((cryptpwd
= crypt(pwd
, syscryptpwd
)) == NULL
)
1272 if (strcmp(cryptpwd
, syscryptpwd
) == 0)
1279 xauth_group_system(usr
, grp
)
1289 plog(LLV_ERROR
, LOCATION
, NULL
,
1290 "the system group name \'%s\' is unknown\n",
1295 while ((member
= gr
->gr_mem
[index
++])!=NULL
) {
1296 if (!strcmp(member
,usr
)) {
1297 plog(LLV_INFO
, LOCATION
, NULL
,
1298 "membership validated\n");
1308 struct ph1handle
*iph1
;
1310 struct xauth_state
*xst
= &iph1
->mode_cfg
->xauth
;
1313 * Only the server side (edge device) really check for Xauth
1314 * status. It does it if the chose authmethod is using Xauth.
1315 * On the client side (roadwarrior), we don't check anything.
1317 switch (AUTHMETHOD(iph1
)) {
1318 case OAKLEY_ATTR_AUTH_METHOD_HYBRID_RSA_R
:
1319 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSASIG_R
:
1320 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_PSKEY_R
:
1321 /* The following are not yet implemented */
1322 case OAKLEY_ATTR_AUTH_METHOD_HYBRID_DSS_R
:
1323 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_DSSSIG_R
:
1324 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAENC_R
:
1325 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAREV_R
:
1326 if ((iph1
->mode_cfg
->flags
& ISAKMP_CFG_VENDORID_XAUTH
) == 0) {
1327 plog(LLV_ERROR
, LOCATION
, NULL
,
1328 "Hybrid auth negotiated but peer did not "
1329 "announced as Xauth capable\n");
1333 if (xst
->status
!= XAUTHST_OK
) {
1334 plog(LLV_ERROR
, LOCATION
, NULL
,
1335 "Hybrid auth negotiated but peer did not "
1336 "succeed Xauth exchange\n");
1351 group_check(iph1
, grp_list
, grp_count
)
1352 struct ph1handle
*iph1
;
1360 /* check for presence of modecfg data */
1362 if(iph1
->mode_cfg
== NULL
) {
1363 plog(LLV_ERROR
, LOCATION
, NULL
,
1364 "xauth group specified but modecfg not found\n");
1368 /* loop through our group list */
1370 for(; grp_index
< grp_count
; grp_index
++) {
1372 /* check for presence of xauth data */
1374 usr
= iph1
->mode_cfg
->xauth
.authdata
.generic
.usr
;
1377 plog(LLV_ERROR
, LOCATION
, NULL
,
1378 "xauth group specified but xauth not found\n");
1382 /* call appropriate group validation funtion */
1384 switch (isakmp_cfg_config
.groupsource
) {
1386 case ISAKMP_CFG_GROUP_SYSTEM
:
1387 res
= xauth_group_system(
1389 grp_list
[grp_index
]);
1393 case ISAKMP_CFG_GROUP_LDAP
:
1394 res
= xauth_group_ldap(
1395 iph1
->mode_cfg
->xauth
.udn
,
1396 grp_list
[grp_index
]);
1401 /* we should never get here */
1402 plog(LLV_ERROR
, LOCATION
, NULL
,
1403 "Unknown group auth source\n");
1408 plog(LLV_INFO
, LOCATION
, NULL
,
1409 "user \"%s\" is a member of group \"%s\"\n",
1411 grp_list
[grp_index
]);
1414 plog(LLV_INFO
, LOCATION
, NULL
,
1415 "user \"%s\" is not a member of group \"%s\"\n",
1417 grp_list
[grp_index
]);
1425 isakmp_xauth_req(iph1
, attr
)
1426 struct ph1handle
*iph1
;
1427 struct isakmp_data
*attr
;
1433 vchar_t
*buffer
= NULL
;
1435 vchar_t
*mdata
= NULL
;
1437 vchar_t
*usr
= NULL
;
1438 vchar_t
*pwd
= NULL
;
1442 if ((iph1
->mode_cfg
->flags
& ISAKMP_CFG_VENDORID_XAUTH
) == 0) {
1443 plog(LLV_ERROR
, LOCATION
, NULL
,
1444 "Xauth mode config request but peer "
1445 "did not declare itself as Xauth capable\n");
1449 type
= ntohs(attr
->type
) & ~ISAKMP_GEN_MASK
;
1454 if ((ntohs(attr
->type
) & ISAKMP_GEN_TV
) == 0) {
1455 plog(LLV_ERROR
, LOCATION
, NULL
,
1456 "Unexpected long XAUTH_TYPE attribute\n");
1459 if (ntohs(attr
->lorv
) != XAUTH_TYPE_GENERIC
) {
1460 plog(LLV_ERROR
, LOCATION
, NULL
,
1461 "Unsupported Xauth authentication %d\n",
1467 value
= XAUTH_TYPE_GENERIC
;
1470 case XAUTH_USER_NAME
:
1471 if (!iph1
->rmconf
->xauth
|| !iph1
->rmconf
->xauth
->login
) {
1472 plog(LLV_ERROR
, LOCATION
, NULL
, "Xauth performed "
1473 "with no login supplied\n");
1477 dlen
= iph1
->rmconf
->xauth
->login
->l
- 1;
1478 iph1
->rmconf
->xauth
->state
|= XAUTH_SENT_USERNAME
;
1481 case XAUTH_USER_PASSWORD
:
1482 case XAUTH_PASSCODE
:
1483 if (!iph1
->rmconf
->xauth
|| !iph1
->rmconf
->xauth
->login
)
1486 skip
= sizeof(struct ipsecdoi_id_b
);
1487 usr
= vmalloc(iph1
->rmconf
->xauth
->login
->l
- 1 + skip
);
1489 plog(LLV_ERROR
, LOCATION
, NULL
,
1490 "Cannot allocate memory\n");
1493 memset(usr
->v
, 0, skip
);
1494 memcpy(usr
->v
+ skip
,
1495 iph1
->rmconf
->xauth
->login
->v
,
1496 iph1
->rmconf
->xauth
->login
->l
- 1);
1498 if (iph1
->rmconf
->xauth
->pass
) {
1499 /* A key given through racoonctl */
1500 pwd
= iph1
->rmconf
->xauth
->pass
;
1502 if ((pwd
= getpskbyname(usr
)) == NULL
) {
1503 plog(LLV_ERROR
, LOCATION
, NULL
,
1504 "No password was found for login %s\n",
1505 iph1
->rmconf
->xauth
->login
->v
);
1509 /* We have to free it before returning */
1514 iph1
->rmconf
->xauth
->state
|= XAUTH_SENT_PASSWORD
;
1520 if ((ntohs(attr
->type
) & ISAKMP_GEN_TV
) == 0) {
1521 dlen
= ntohs(attr
->lorv
);
1523 mraw
= (char*)(attr
+ 1);
1524 if ((mdata
= vmalloc(dlen
)) == NULL
) {
1525 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
1526 "Cannot allocate memory\n");
1529 memcpy(mdata
->v
, mraw
, mdata
->l
);
1530 plog(LLV_NOTIFY
,LOCATION
, iph1
->remote
,
1531 "XAUTH Message: '%s'.\n",
1532 binsanitize(mdata
->v
, mdata
->l
));
1538 plog(LLV_WARNING
, LOCATION
, NULL
,
1539 "Ignored attribute %s\n", s_isakmp_cfg_type(type
));
1544 if ((buffer
= vmalloc(sizeof(*attr
) + dlen
)) == NULL
) {
1545 plog(LLV_ERROR
, LOCATION
, NULL
,
1546 "Cannot allocate memory\n");
1550 attr
= (struct isakmp_data
*)buffer
->v
;
1552 attr
->type
= htons(type
| ISAKMP_GEN_TV
);
1553 attr
->lorv
= htons(value
);
1557 attr
->type
= htons(type
| ISAKMP_GEN_TLV
);
1558 attr
->lorv
= htons(dlen
);
1559 data
= (char *)(attr
+ 1);
1562 case XAUTH_USER_NAME
:
1564 * iph1->rmconf->xauth->login->v is valid,
1565 * we just checked it in the previous switch case
1567 memcpy(data
, iph1
->rmconf
->xauth
->login
->v
, dlen
);
1569 case XAUTH_USER_PASSWORD
:
1570 case XAUTH_PASSCODE
:
1571 memcpy(data
, pwd
->v
, dlen
);
1585 isakmp_xauth_set(iph1
, attr
)
1586 struct ph1handle
*iph1
;
1587 struct isakmp_data
*attr
;
1590 vchar_t
*buffer
= NULL
;
1592 struct xauth_state
*xst
;
1595 vchar_t
*mdata
= NULL
;
1597 if ((iph1
->mode_cfg
->flags
& ISAKMP_CFG_VENDORID_XAUTH
) == 0) {
1598 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1599 IPSECSESSIONEVENTCODE_IKEV1_XAUTH_DROP
,
1600 CONSTSTR("XAUTH is not supported by peer"),
1601 CONSTSTR("XAUTH dropped (not supported by peer)"));
1602 plog(LLV_ERROR
, LOCATION
, NULL
,
1603 "Xauth mode config set but peer "
1604 "did not declare itself as Xauth capable\n");
1608 type
= ntohs(attr
->type
) & ~ISAKMP_GEN_MASK
;
1613 * We should only receive ISAKMP mode_cfg SET XAUTH_STATUS
1614 * when running as a client (initiator).
1616 xst
= &iph1
->mode_cfg
->xauth
;
1617 switch(AUTHMETHOD(iph1
)) {
1618 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_PSKEY_R
:
1619 if (!iph1
->is_rekey
) {
1620 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1621 IPSECSESSIONEVENTCODE_IKEV1_XAUTH_DROP
,
1622 CONSTSTR("Unexpected XAUTH Status"),
1623 CONSTSTR("Xauth dropped (unexpected Xauth status)... not a phase1 rekey"));
1624 plog(LLV_ERROR
, LOCATION
, NULL
,
1625 "Unexpected XAUTH_STATUS_OK... not a phase1 rekey\n");
1628 case OAKLEY_ATTR_AUTH_METHOD_HYBRID_RSA_I
:
1629 case FICTIVE_AUTH_METHOD_XAUTH_PSKEY_I
:
1630 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSASIG_I
:
1631 /* Not implemented ... */
1632 case OAKLEY_ATTR_AUTH_METHOD_HYBRID_DSS_I
:
1633 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_DSSSIG_I
:
1634 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAENC_I
:
1635 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAREV_I
:
1638 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1639 IPSECSESSIONEVENTCODE_IKEV1_XAUTH_DROP
,
1640 CONSTSTR("Unexpected XAUTH Status"),
1641 CONSTSTR("Xauth dropped (unexpected Xauth status)"));
1642 plog(LLV_ERROR
, LOCATION
, NULL
,
1643 "Unexpected XAUTH_STATUS_OK\n");
1648 /* If we got a failure, delete iph1 */
1649 if (ntohs(attr
->lorv
) != XAUTH_STATUS_OK
) {
1650 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1651 IPSECSESSIONEVENTCODE_IKEV1_XAUTH_FAIL
,
1652 CONSTSTR("XAUTH Status is not OK"),
1653 CONSTSTR("Xauth Failed (status not ok)"));
1654 plog(LLV_ERROR
, LOCATION
, NULL
,
1655 "Xauth authentication failed\n");
1657 EVT_PUSH(iph1
->local
, iph1
->remote
,
1658 EVTT_XAUTH_FAILED
, NULL
);
1660 vpncontrol_notify_ike_failed(VPNCTL_NTYPE_AUTHENTICATION_FAILED
, FROM_LOCAL
,
1661 ((struct sockaddr_in
*)iph1
->remote
)->sin_addr
.s_addr
, 0, NULL
);
1663 iph1
->mode_cfg
->flags
|= ISAKMP_CFG_DELETE_PH1
;
1665 IPSECLOGASLMSG("IPSec Extended Authentication Failed.\n");
1667 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1668 IPSECSESSIONEVENTCODE_IKEV1_XAUTH_SUCC
,
1669 CONSTSTR("XAUTH Status is OK"),
1671 EVT_PUSH(iph1
->local
, iph1
->remote
,
1672 EVTT_XAUTH_SUCCESS
, NULL
);
1673 if (iph1
->is_rekey
) {
1674 xst
->status
= XAUTHST_OK
;
1677 IPSECLOGASLMSG("IPSec Extended Authentication Passed.\n");
1681 /* We acknowledge it */
1684 if ((ntohs(attr
->type
) & ISAKMP_GEN_TV
) == 0) {
1685 dlen
= ntohs(attr
->lorv
);
1687 mraw
= (char*)(attr
+ 1);
1688 if ((mdata
= vmalloc(dlen
)) == NULL
) {
1689 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
1690 "Cannot allocate memory\n");
1693 memcpy(mdata
->v
, mraw
, mdata
->l
);
1694 plog(LLV_NOTIFY
,LOCATION
, iph1
->remote
,
1695 "XAUTH Message: '%s'.\n",
1696 binsanitize(mdata
->v
, mdata
->l
));
1702 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1703 IPSECSESSIONEVENTCODE_IKEV1_XAUTH_DROP
,
1704 CONSTSTR("ignored attribute"),
1705 CONSTSTR("Xauth dropped (ignored attribute)"));
1706 plog(LLV_WARNING
, LOCATION
, NULL
,
1707 "Ignored attribute %s\n", s_isakmp_cfg_type(type
));
1712 if ((buffer
= vmalloc(sizeof(*attr
))) == NULL
) {
1713 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1714 IPSECSESSIONEVENTCODE_IKEV1_XAUTH_DROP
,
1715 CONSTSTR("Failed to allocate attribute"),
1716 CONSTSTR("Xauth dropped (failed to allocate attribute)"));
1717 plog(LLV_ERROR
, LOCATION
, NULL
,
1718 "Cannot allocate memory\n");
1722 attr
= (struct isakmp_data
*)buffer
->v
;
1723 attr
->type
= htons(type
| ISAKMP_GEN_TV
);
1724 attr
->lorv
= htons(0);
1732 struct xauth_state
*xst
;
1734 switch (xst
->authtype
) {
1735 case XAUTH_TYPE_GENERIC
:
1736 if (xst
->authdata
.generic
.usr
)
1737 racoon_free(xst
->authdata
.generic
.usr
);
1739 if (xst
->authdata
.generic
.pwd
)
1740 racoon_free(xst
->authdata
.generic
.pwd
);
1744 case XAUTH_TYPE_CHAP
:
1745 case XAUTH_TYPE_OTP
:
1746 case XAUTH_TYPE_SKEY
:
1747 plog(LLV_WARNING
, LOCATION
, NULL
,
1748 "Unsupported authtype %d\n", xst
->authtype
);
1752 plog(LLV_WARNING
, LOCATION
, NULL
,
1753 "Unexpected authtype %d\n", xst
->authtype
);
1758 if (xst
->udn
!= NULL
)
1759 racoon_free(xst
->udn
);
1765 xauth_rmconf_used(xauth_rmconf
)
1766 struct xauth_rmconf
**xauth_rmconf
;
1768 if (*xauth_rmconf
== NULL
) {
1769 *xauth_rmconf
= racoon_malloc(sizeof(**xauth_rmconf
));
1770 if (*xauth_rmconf
== NULL
) {
1771 plog(LLV_ERROR
, LOCATION
, NULL
,
1772 "xauth_rmconf_used: malloc failed\n");
1776 (*xauth_rmconf
)->login
= NULL
;
1777 (*xauth_rmconf
)->pass
= NULL
;
1778 (*xauth_rmconf
)->state
= 0;
1780 if ((*xauth_rmconf
)->login
) {
1781 vfree((*xauth_rmconf
)->login
);
1782 (*xauth_rmconf
)->login
= NULL
;
1784 if ((*xauth_rmconf
)->pass
!= NULL
) {
1785 vfree((*xauth_rmconf
)->pass
);
1786 (*xauth_rmconf
)->pass
= NULL
;
1788 (*xauth_rmconf
)->state
= 0;
1795 xauth_rmconf_delete(xauth_rmconf
)
1796 struct xauth_rmconf
**xauth_rmconf
;
1798 if (*xauth_rmconf
!= NULL
) {
1799 if ((*xauth_rmconf
)->login
!= NULL
)
1800 vfree((*xauth_rmconf
)->login
);
1801 if ((*xauth_rmconf
)->pass
!= NULL
)
1802 vfree((*xauth_rmconf
)->pass
);
1804 racoon_free(*xauth_rmconf
);
1805 *xauth_rmconf
= NULL
;