5d2b02d240a3f5172c7a92be1b33552f0363385a
[strongswan.git] / src / libcharon / plugins / xauth_null / xauth_null.c
1 /*
2 * Copyright (C) 2007-2008 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 #include "xauth_null.h"
17
18 #include <daemon.h>
19 #include <library.h>
20
21 typedef struct private_xauth_null_t private_xauth_null_t;
22
23 /**
24 * Private data of an xauth_null_t object.
25 */
26 struct private_xauth_null_t {
27
28 /**
29 * Public authenticator_t interface.
30 */
31 xauth_null_t public;
32
33 /**
34 * ID of the peer
35 */
36 identification_t *peer;
37 };
38
39 METHOD(xauth_method_t, process_peer, status_t,
40 private_xauth_null_t *this, cp_payload_t *in, cp_payload_t **out)
41 {
42 chunk_t user_name = chunk_from_chars('j', 'o', 's', 't');
43 chunk_t user_pass = chunk_from_chars('j', 'o', 's', 't');
44 cp_payload_t *cp;
45
46 /* TODO-IKEv1: Fetch the user/pass from an authenticator */
47 cp = cp_payload_create_type(CONFIGURATION_V1, CFG_REPLY);
48 cp->add_attribute(cp, configuration_attribute_create_chunk(
49 CONFIGURATION_ATTRIBUTE_V1, XAUTH_USER_NAME, user_name));
50 cp->add_attribute(cp, configuration_attribute_create_chunk(
51 CONFIGURATION_ATTRIBUTE_V1, XAUTH_USER_PASSWORD, user_pass));
52 *out = cp;
53 return NEED_MORE;
54 }
55
56 METHOD(xauth_method_t, initiate_peer, status_t,
57 private_xauth_null_t *this, cp_payload_t **out)
58 {
59 /* peer never initiates */
60 return FAILED;
61 }
62
63 METHOD(xauth_method_t, process_server, status_t,
64 private_xauth_null_t *this, cp_payload_t *in, cp_payload_t **out)
65 {
66 return SUCCESS;
67 }
68
69 METHOD(xauth_method_t, initiate_server, status_t,
70 private_xauth_null_t *this, cp_payload_t **out)
71 {
72 return NEED_MORE;
73 }
74
75 METHOD(xauth_method_t, destroy, void,
76 private_xauth_null_t *this)
77 {
78 this->peer->destroy(this->peer);
79 free(this);
80 }
81
82 /*
83 * Described in header.
84 */
85 xauth_null_t *xauth_null_create_peer(identification_t *server,
86 identification_t *peer)
87 {
88 private_xauth_null_t *this;
89
90 INIT(this,
91 .public = {
92 .xauth_method = {
93 .initiate = _initiate_peer,
94 .process = _process_peer,
95 .destroy = _destroy,
96 },
97 },
98 .peer = peer->clone(peer),
99 );
100
101 return &this->public;
102 }
103
104 /*
105 * Described in header.
106 */
107 xauth_null_t *xauth_null_create_server(identification_t *server,
108 identification_t *peer)
109 {
110 private_xauth_null_t *this;
111
112 INIT(this,
113 .public = {
114 .xauth_method = {
115 .initiate = _initiate_server,
116 .process = _process_server,
117 .destroy = _destroy,
118 },
119 },
120 .peer = peer->clone(peer),
121 );
122
123 return &this->public;
124 }