1 /* $Id: isakmp_xauth.c,v 1.17.2.5 2005/05/20 07:31:09 manubsd Exp $ */
4 * Copyright (C) 2004-2005 Emmanuel Dreyfus
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the project nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #include <sys/types.h>
35 #include <sys/param.h>
36 #include <sys/socket.h>
37 #include <sys/queue.h>
39 #include <netinet/in.h>
49 #if TIME_WITH_SYS_TIME
50 # include <sys/time.h>
54 # include <sys/time.h>
73 #include "crypto_openssl.h"
74 #include "isakmp_var.h"
81 #include "remoteconf.h"
82 #include "isakmp_inf.h"
83 #include "isakmp_xauth.h"
84 #include "isakmp_unity.h"
85 #include "isakmp_cfg.h"
87 #include "ipsec_doi.h"
88 #include "remoteconf.h"
89 #include "localconf.h"
94 struct rad_handle
*radius_auth_state
= NULL
;
95 struct rad_handle
*radius_acct_state
= NULL
;
100 #include <pam/pam_appl.h>
102 #include <security/pam_appl.h>
105 static char *PAM_usr
= NULL
;
106 static char *PAM_pwd
= NULL
;
107 static int PAM_conv(int, const struct pam_message
**,
108 struct pam_response
**, void *);
109 static struct pam_conv PAM_chat
= { &PAM_conv
, NULL
};
115 struct ph1handle
*iph1
;
118 struct isakmp_pl_attr
*attr
;
119 struct isakmp_data
*typeattr
;
120 struct isakmp_data
*usrattr
;
121 struct isakmp_data
*pwdattr
;
122 struct xauth_state
*xst
= &iph1
->mode_cfg
->xauth
;
126 if (iph1
->status
!= PHASE1ST_ESTABLISHED
) {
127 plog(LLV_ERROR
, LOCATION
, NULL
,
128 "Xauth request while phase 1 is not completed\n");
132 if (xst
->status
!= XAUTHST_NOTYET
) {
133 plog(LLV_ERROR
, LOCATION
, NULL
,
134 "Xauth request whith Xauth state %d\n", xst
->status
);
138 plog(LLV_INFO
, LOCATION
, NULL
, "Sending Xauth request\n");
140 tlen
= sizeof(*attr
) +
141 + sizeof(*typeattr
) +
145 if ((buffer
= vmalloc(tlen
)) == NULL
) {
146 plog(LLV_ERROR
, LOCATION
, NULL
, "Cannot allocate buffer\n");
150 attr
= (struct isakmp_pl_attr
*)buffer
->v
;
151 memset(attr
, 0, tlen
);
153 attr
->h
.len
= htons(tlen
);
154 attr
->type
= ISAKMP_CFG_REQUEST
;
155 attr
->id
= htons(eay_random());
157 typeattr
= (struct isakmp_data
*)(attr
+ 1);
158 typeattr
->type
= htons(XAUTH_TYPE
| ISAKMP_GEN_TV
);
159 typeattr
->lorv
= htons(XAUTH_TYPE_GENERIC
);
161 usrattr
= (struct isakmp_data
*)(typeattr
+ 1);
162 usrattr
->type
= htons(XAUTH_USER_NAME
| ISAKMP_GEN_TLV
);
163 usrattr
->lorv
= htons(0);
165 pwdattr
= (struct isakmp_data
*)(usrattr
+ 1);
166 pwdattr
->type
= htons(XAUTH_USER_PASSWORD
| ISAKMP_GEN_TLV
);
167 pwdattr
->lorv
= htons(0);
169 isakmp_cfg_send(iph1
, buffer
,
170 ISAKMP_NPTYPE_ATTR
, ISAKMP_FLAG_E
, 1);
174 xst
->status
= XAUTHST_REQSENT
;
180 xauth_attr_reply(iph1
, attr
, id
)
181 struct ph1handle
*iph1
;
182 struct isakmp_data
*attr
;
185 char **outlet
= NULL
;
188 struct xauth_state
*xst
= &iph1
->mode_cfg
->xauth
;
190 if ((iph1
->mode_cfg
->flags
& ISAKMP_CFG_VENDORID_XAUTH
) == 0) {
191 plog(LLV_ERROR
, LOCATION
, NULL
,
192 "Xauth reply but peer did not declare "
193 "itself as Xauth capable\n");
197 if (xst
->status
!= XAUTHST_REQSENT
) {
198 plog(LLV_ERROR
, LOCATION
, NULL
,
199 "Xauth reply while Xauth state is %d\n", xst
->status
);
203 type
= ntohs(attr
->type
) & ~ISAKMP_GEN_MASK
;
206 switch (ntohs(attr
->lorv
)) {
207 case XAUTH_TYPE_GENERIC
:
208 xst
->authtype
= XAUTH_TYPE_GENERIC
;
211 plog(LLV_WARNING
, LOCATION
, NULL
,
212 "Unexpected authentication type %d\n",
218 case XAUTH_USER_NAME
:
219 outlet
= &xst
->authdata
.generic
.usr
;
222 case XAUTH_USER_PASSWORD
:
223 outlet
= &xst
->authdata
.generic
.pwd
;
227 plog(LLV_WARNING
, LOCATION
, NULL
,
228 "ignored Xauth attribute %d\n", type
);
232 if (outlet
!= NULL
) {
233 alen
= ntohs(attr
->lorv
);
235 if ((*outlet
= racoon_malloc(alen
+ 1)) == NULL
) {
236 plog(LLV_ERROR
, LOCATION
, NULL
,
237 "Cannot allocate memory for Xauth Data\n");
241 memcpy(*outlet
, attr
+ 1, alen
);
242 (*outlet
)[alen
] = '\0';
247 if ((xst
->authdata
.generic
.usr
!= NULL
) &&
248 (xst
->authdata
.generic
.pwd
!= NULL
)) {
251 char *usr
= xst
->authdata
.generic
.usr
;
252 char *pwd
= xst
->authdata
.generic
.pwd
;
253 time_t throttle_delay
= 0;
255 #if 0 /* Real debug, don't do that at home */
256 plog(LLV_DEBUG
, LOCATION
, NULL
,
257 "Got username \"%s\", password \"%s\"\n", usr
, pwd
);
259 strncpy(iph1
->mode_cfg
->login
, usr
, LOGINLEN
);
260 iph1
->mode_cfg
->login
[LOGINLEN
] = '\0';
263 if ((port
= isakmp_cfg_getport(iph1
)) == -1) {
264 plog(LLV_ERROR
, LOCATION
, NULL
,
265 "Port pool depleted\n");
269 switch (isakmp_cfg_config
.authsource
) {
270 case ISAKMP_CFG_AUTH_SYSTEM
:
271 res
= privsep_xauth_login_system(usr
, pwd
);
273 #ifdef HAVE_LIBRADIUS
274 case ISAKMP_CFG_AUTH_RADIUS
:
275 res
= xauth_login_radius(iph1
, usr
, pwd
);
279 case ISAKMP_CFG_AUTH_PAM
:
280 res
= privsep_xauth_login_pam(iph1
->mode_cfg
->port
,
281 iph1
->remote
, usr
, pwd
);
285 plog(LLV_ERROR
, LOCATION
, NULL
,
286 "Unexpected authentication source\n");
292 * On failure, throttle the connexion for the remote host
293 * in order to make password attacks more difficult.
295 throttle_delay
= throttle_host(iph1
->remote
, res
) - time(NULL
);
296 if (throttle_delay
> 0) {
299 str
= saddrwop2str(iph1
->remote
);
301 plog(LLV_ERROR
, LOCATION
, NULL
,
302 "Throttling in action for %s: delay %lds\n",
303 str
, (unsigned long)throttle_delay
);
310 if (throttle_delay
!= 0) {
311 struct xauth_reply_arg
*xra
;
313 if ((xra
= racoon_malloc(sizeof(*xra
))) == NULL
) {
314 plog(LLV_ERROR
, LOCATION
, NULL
,
315 "malloc failed, bypass throttling\n");
316 xauth_reply(iph1
, port
, id
, res
);
321 * We need to store the ph1, but it might have
322 * disapeared when xauth_reply is called, so
323 * store the index instead.
325 xra
->index
= iph1
->index
;
329 sched_new(throttle_delay
, xauth_reply_stub
, xra
);
331 xauth_reply(iph1
, port
, id
, res
);
339 xauth_reply_stub(args
)
342 struct xauth_reply_arg
*xra
= (struct xauth_reply_arg
*)args
;
343 struct ph1handle
*iph1
;
345 if ((iph1
= getph1byindex(&xra
->index
)) != NULL
)
346 xauth_reply(iph1
, xra
->port
, xra
->id
, xra
->res
);
348 plog(LLV_ERROR
, LOCATION
, NULL
,
349 "Delayed Xauth reply: phase 1 no longer exists.\n");
356 xauth_reply(iph1
, port
, id
, res
)
357 struct ph1handle
*iph1
;
361 struct xauth_state
*xst
= &iph1
->mode_cfg
->xauth
;
362 char *usr
= xst
->authdata
.generic
.usr
;
366 isakmp_cfg_putport(iph1
, port
);
368 plog(LLV_INFO
, LOCATION
, NULL
,
369 "login failed for user \"%s\"\n", usr
);
371 xauth_sendstatus(iph1
, XAUTH_STATUS_FAIL
, id
);
372 xst
->status
= XAUTHST_NOTYET
;
374 /* Delete Phase 1 SA */
375 if (iph1
->status
== PHASE1ST_ESTABLISHED
)
376 isakmp_info_send_d1(iph1
);
383 xst
->status
= XAUTHST_OK
;
384 plog(LLV_INFO
, LOCATION
, NULL
,
385 "login succeeded for user \"%s\"\n", usr
);
387 xauth_sendstatus(iph1
, XAUTH_STATUS_OK
, id
);
393 xauth_sendstatus(iph1
, status
, id
)
394 struct ph1handle
*iph1
;
399 struct isakmp_pl_attr
*attr
;
400 struct isakmp_data
*stattr
;
403 tlen
= sizeof(*attr
) +
406 if ((buffer
= vmalloc(tlen
)) == NULL
) {
407 plog(LLV_ERROR
, LOCATION
, NULL
, "Cannot allocate buffer\n");
411 attr
= (struct isakmp_pl_attr
*)buffer
->v
;
412 memset(attr
, 0, tlen
);
414 attr
->h
.len
= htons(tlen
);
415 attr
->type
= ISAKMP_CFG_SET
;
416 attr
->id
= htons(id
);
418 stattr
= (struct isakmp_data
*)(attr
+ 1);
419 stattr
->type
= htons(XAUTH_STATUS
| ISAKMP_GEN_TV
);
420 stattr
->lorv
= htons(status
);
422 isakmp_cfg_send(iph1
, buffer
,
423 ISAKMP_NPTYPE_ATTR
, ISAKMP_FLAG_E
, 1);
430 #ifdef HAVE_LIBRADIUS
432 xauth_radius_init(void)
434 /* For first time use, initialize Radius */
435 if ((isakmp_cfg_config
.authsource
== ISAKMP_CFG_AUTH_RADIUS
) &&
436 (radius_auth_state
== NULL
)) {
437 if ((radius_auth_state
= rad_auth_open()) == NULL
) {
438 plog(LLV_ERROR
, LOCATION
, NULL
,
439 "Cannot init libradius\n");
443 if (rad_config(radius_auth_state
, NULL
) != 0) {
444 plog(LLV_ERROR
, LOCATION
, NULL
,
445 "Cannot open librarius config file: %s\n",
446 rad_strerror(radius_auth_state
));
447 rad_close(radius_auth_state
);
448 radius_auth_state
= NULL
;
453 if ((isakmp_cfg_config
.accounting
== ISAKMP_CFG_ACCT_RADIUS
) &&
454 (radius_acct_state
== NULL
)) {
455 if ((radius_acct_state
= rad_auth_open()) == NULL
) {
456 plog(LLV_ERROR
, LOCATION
, NULL
,
457 "Cannot init libradius\n");
461 if (rad_config(radius_acct_state
, NULL
) != 0) {
462 plog(LLV_ERROR
, LOCATION
, NULL
,
463 "Cannot open librarius config file: %s\n",
464 rad_strerror(radius_acct_state
));
465 rad_close(radius_acct_state
);
466 radius_acct_state
= NULL
;
475 xauth_login_radius(iph1
, usr
, pwd
)
476 struct ph1handle
*iph1
;
485 if (rad_create_request(radius_auth_state
, RAD_ACCESS_REQUEST
) != 0) {
486 plog(LLV_ERROR
, LOCATION
, NULL
,
487 "rad_create_request failed: %s\n",
488 rad_strerror(radius_auth_state
));
492 if (rad_put_string(radius_auth_state
, RAD_USER_NAME
, usr
) != 0) {
493 plog(LLV_ERROR
, LOCATION
, NULL
,
494 "rad_put_string failed: %s\n",
495 rad_strerror(radius_auth_state
));
499 if (rad_put_string(radius_auth_state
, RAD_USER_PASSWORD
, pwd
) != 0) {
500 plog(LLV_ERROR
, LOCATION
, NULL
,
501 "rad_put_string failed: %s\n",
502 rad_strerror(radius_auth_state
));
506 if (isakmp_cfg_radius_common(radius_auth_state
, iph1
->mode_cfg
->port
) != 0)
509 switch (res
= rad_send_request(radius_auth_state
)) {
510 case RAD_ACCESS_ACCEPT
:
511 while ((type
= rad_get_attr(radius_auth_state
, &data
, &len
)) != 0) {
513 case RAD_FRAMED_IP_ADDRESS
:
514 iph1
->mode_cfg
->addr4
= rad_cvt_addr(data
);
515 iph1
->mode_cfg
->flags
516 |= ISAKMP_CFG_ADDR4_RADIUS
;
519 case RAD_FRAMED_IP_NETMASK
:
520 iph1
->mode_cfg
->mask4
= rad_cvt_addr(data
);
521 iph1
->mode_cfg
->flags
522 |= ISAKMP_CFG_MASK4_RADIUS
;
526 plog(LLV_INFO
, LOCATION
, NULL
,
527 "Unexpected attribute: %d\n", type
);
535 case RAD_ACCESS_REJECT
:
540 plog(LLV_ERROR
, LOCATION
, NULL
,
541 "rad_send_request failed: %s\n",
542 rad_strerror(radius_auth_state
));
546 plog(LLV_ERROR
, LOCATION
, NULL
,
547 "rad_send_request returned %d\n", res
);
558 PAM_conv(msg_count
, msg
, rsp
, dontcare
)
560 const struct pam_message
**msg
;
561 struct pam_response
**rsp
;
566 struct pam_response
*reply
= NULL
;
568 if ((reply
= racoon_malloc(sizeof(*reply
) * msg_count
)) == NULL
)
570 bzero(reply
, sizeof(*reply
) * msg_count
);
572 for (i
= 0; i
< msg_count
; i
++) {
573 switch (msg
[i
]->msg_style
) {
574 case PAM_PROMPT_ECHO_ON
:
575 /* Send the username, libpam frees resp */
576 reply
[i
].resp_retcode
= PAM_SUCCESS
;
577 reply
[i
].resp
= strdup(PAM_usr
);
580 case PAM_PROMPT_ECHO_OFF
:
581 /* Send the password, libpam frees resp */
582 reply
[i
].resp_retcode
= PAM_SUCCESS
;
583 reply
[i
].resp
= strdup(PAM_pwd
);
588 reply
[i
].resp_retcode
= PAM_SUCCESS
;
589 reply
[i
].resp
= NULL
;
607 xauth_login_pam(port
, raddr
, usr
, pwd
)
609 struct sockaddr
*raddr
;
619 pam_handle_t
*pam
= NULL
;
621 if (isakmp_cfg_config
.port_pool
== NULL
) {
622 plog(LLV_ERROR
, LOCATION
, NULL
,
623 "isakmp_cfg_config.port_pool == NULL\n");
627 if ((error
= pam_start("racoon", usr
,
628 &PAM_chat
, &isakmp_cfg_config
.port_pool
[port
].pam
)) != 0) {
629 if (isakmp_cfg_config
.port_pool
[port
].pam
== NULL
) {
630 plog(LLV_ERROR
, LOCATION
, NULL
, "pam_start failed\n");
633 plog(LLV_ERROR
, LOCATION
, NULL
,
634 "pam_start failed: %s\n",
635 pam_strerror(isakmp_cfg_config
.port_pool
[port
].pam
,
640 pam
= isakmp_cfg_config
.port_pool
[port
].pam
;
642 if ((remote
= strdup(saddrwop2str(raddr
))) == NULL
) {
643 plog(LLV_ERROR
, LOCATION
, NULL
,
644 "cannot allocate memory: %s\n", strerror(errno
));
648 if ((error
= pam_set_item(pam
, PAM_RHOST
, remote
)) != 0) {
649 plog(LLV_ERROR
, LOCATION
, NULL
,
650 "pam_set_item failed: %s\n",
651 pam_strerror(pam
, error
));
657 error
= pam_authenticate(pam
, 0);
661 plog(LLV_ERROR
, LOCATION
, NULL
,
662 "pam_authenticate failed: %s\n",
663 pam_strerror(pam
, error
));
667 if ((error
= pam_acct_mgmt(pam
, 0)) != 0) {
668 plog(LLV_ERROR
, LOCATION
, NULL
,
669 "pam_acct_mgmt failed: %s\n",
670 pam_strerror(pam
, error
));
674 if ((error
= pam_setcred(pam
, 0)) != 0) {
675 plog(LLV_ERROR
, LOCATION
, NULL
,
676 "pam_setcred failed: %s\n",
677 pam_strerror(pam
, error
));
685 isakmp_cfg_config
.port_pool
[port
].pam
= NULL
;
691 xauth_login_system(usr
, pwd
)
701 if ((spw
= getspnam(usr
)) == NULL
)
704 syscryptpwd
= spw
->sp_pwdp
;
707 if ((pw
= getpwnam(usr
)) == NULL
)
710 #ifndef HAVE_SHADOW_H
711 syscryptpwd
= pw
->pw_passwd
;
714 /* No root login. Ever. */
718 if ((cryptpwd
= crypt(pwd
, syscryptpwd
)) == NULL
)
721 if (strcmp(cryptpwd
, syscryptpwd
) == 0)
729 struct ph1handle
*iph1
;
731 struct xauth_state
*xst
= &iph1
->mode_cfg
->xauth
;
733 /* If we don't use Xauth, then we pass */
734 switch (iph1
->approval
->authmethod
) {
735 case OAKLEY_ATTR_AUTH_METHOD_HYBRID_RSA_I
:
736 case OAKLEY_ATTR_AUTH_METHOD_HYBRID_DSS_I
:
737 /* The following are not yet implemented */
738 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_PSKEY_I
:
739 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_DSSSIG_I
:
740 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSASIG_I
:
741 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAENC_I
:
742 case OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAREV_I
:
743 if ((iph1
->mode_cfg
->flags
& ISAKMP_CFG_VENDORID_XAUTH
) == 0) {
744 plog(LLV_ERROR
, LOCATION
, NULL
,
745 "Hybrid auth negotiated but peer did not "
746 "announced as Xauth capable\n");
750 if (xst
->status
!= XAUTHST_OK
) {
751 plog(LLV_ERROR
, LOCATION
, NULL
,
752 "Hybrid auth negotiated but peer did not "
753 "succeed Xauth exchange\n");
768 isakmp_xauth_req(iph1
, attr
)
769 struct ph1handle
*iph1
;
770 struct isakmp_data
*attr
;
776 vchar_t
*buffer
= NULL
;
783 if ((iph1
->mode_cfg
->flags
& ISAKMP_CFG_VENDORID_XAUTH
) == 0) {
784 plog(LLV_ERROR
, LOCATION
, NULL
,
785 "Xauth mode config request but peer "
786 "did not declare itself as Xauth capable\n");
790 type
= ntohs(attr
->type
) & ~ISAKMP_GEN_MASK
;
795 if ((ntohs(attr
->type
) & ISAKMP_GEN_TV
) == 0) {
796 plog(LLV_ERROR
, LOCATION
, NULL
,
797 "Unexpected long XAUTH_TYPE attribute\n");
800 if (ntohs(attr
->lorv
) != XAUTH_TYPE_GENERIC
) {
801 plog(LLV_ERROR
, LOCATION
, NULL
,
802 "Unsupported Xauth authentication %d\n",
808 value
= XAUTH_TYPE_GENERIC
;
811 case XAUTH_USER_NAME
:
812 if (iph1
->rmconf
->idvtype
!= IDTYPE_LOGIN
) {
813 plog(LLV_ERROR
, LOCATION
, NULL
, "Xauth performed "
814 "while identifier is not a login\n");
818 if (iph1
->rmconf
->idv
== NULL
) {
819 plog(LLV_ERROR
, LOCATION
, NULL
, "Xauth performed "
820 "with no login supplied\n");
824 dlen
= iph1
->rmconf
->idv
->l
;
827 case XAUTH_USER_PASSWORD
:
828 if (iph1
->rmconf
->idvtype
!= IDTYPE_LOGIN
)
831 if (iph1
->rmconf
->idv
== NULL
)
834 skip
= sizeof(struct ipsecdoi_id_b
);
835 if ((usr
= vmalloc(iph1
->rmconf
->idv
->l
+ skip
)) == NULL
) {
836 plog(LLV_ERROR
, LOCATION
, NULL
,
837 "Cannot allocate memory\n");
841 memset(usr
->v
, 0, skip
);
842 memcpy(usr
->v
+ skip
,
843 iph1
->rmconf
->idv
->v
,
844 iph1
->rmconf
->idv
->l
);
846 if (iph1
->rmconf
->key
) {
847 /* A key given through racoonctl */
848 pwd
= iph1
->rmconf
->key
;
850 if ((pwd
= getpskbyname(usr
)) == NULL
) {
851 plog(LLV_ERROR
, LOCATION
, NULL
,
852 "No password was found for login %s\n",
853 iph1
->rmconf
->idv
->v
);
857 /* We have to free it before returning */
867 plog(LLV_WARNING
, LOCATION
, NULL
,
868 "Ignored attribute %d\n", type
);
873 if ((buffer
= vmalloc(sizeof(*attr
) + dlen
)) == NULL
) {
874 plog(LLV_ERROR
, LOCATION
, NULL
,
875 "Cannot allocate memory\n");
879 attr
= (struct isakmp_data
*)buffer
->v
;
881 attr
->type
= htons(type
| ISAKMP_GEN_TV
);
882 attr
->lorv
= htons(value
);
886 attr
->type
= htons(type
| ISAKMP_GEN_TLV
);
887 attr
->lorv
= htons(dlen
);
888 data
= (char *)(attr
+ 1);
891 case XAUTH_USER_NAME
:
892 memcpy(data
, iph1
->rmconf
->idv
->v
, dlen
);
894 case XAUTH_USER_PASSWORD
:
895 memcpy(data
, pwd
->v
, dlen
);
909 isakmp_xauth_set(iph1
, attr
)
910 struct ph1handle
*iph1
;
911 struct isakmp_data
*attr
;
914 vchar_t
*buffer
= NULL
;
917 if ((iph1
->mode_cfg
->flags
& ISAKMP_CFG_VENDORID_XAUTH
) == 0) {
918 plog(LLV_ERROR
, LOCATION
, NULL
,
919 "Xauth mode config set but peer "
920 "did not declare itself as Xauth capable\n");
924 type
= ntohs(attr
->type
) & ~ISAKMP_GEN_MASK
;
928 /* If we got a failure, delete iph1 */
929 if (ntohs(attr
->lorv
) != XAUTH_STATUS_OK
) {
930 plog(LLV_ERROR
, LOCATION
, NULL
,
931 "Xauth authentication failed\n");
933 EVT_PUSH(iph1
->local
, iph1
->remote
,
934 EVTT_XAUTH_FAILED
, NULL
);
936 iph1
->mode_cfg
->flags
|= ISAKMP_CFG_DELETE_PH1
;
938 EVT_PUSH(iph1
->local
,
939 iph1
->remote
, EVTT_XAUTH_SUCCESS
, NULL
);
943 /* We acknowledge it */
946 plog(LLV_WARNING
, LOCATION
, NULL
,
947 "Ignored attribute %d\n", type
);
952 if ((buffer
= vmalloc(sizeof(*attr
))) == NULL
) {
953 plog(LLV_ERROR
, LOCATION
, NULL
,
954 "Cannot allocate memory\n");
958 attr
= (struct isakmp_data
*)buffer
->v
;
959 attr
->type
= htons(type
| ISAKMP_GEN_TV
);
960 attr
->lorv
= htons(0);
968 struct xauth_state
*xst
;
970 switch (xst
->authtype
) {
971 case XAUTH_TYPE_GENERIC
:
972 if (xst
->authdata
.generic
.usr
)
973 racoon_free(xst
->authdata
.generic
.usr
);
975 if (xst
->authdata
.generic
.pwd
)
976 racoon_free(xst
->authdata
.generic
.pwd
);
980 case XAUTH_TYPE_CHAP
:
982 case XAUTH_TYPE_SKEY
:
983 plog(LLV_WARNING
, LOCATION
, NULL
,
984 "Unsupported authtype %d\n", xst
->authtype
);
988 plog(LLV_WARNING
, LOCATION
, NULL
,
989 "Unexpected authtype %d\n", xst
->authtype
);