2 * rlm_eap.c contains handles that are called from modules.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * Copyright 2000,2001 The FreeRADIUS server project
21 * Copyright 2001 hereUare Communications, Inc. <raghud@hereuare.com>
28 static CONF_PARSER module_config[] = {
29 { "default_eap_type", PW_TYPE_STRING_PTR, offsetof(EAP_CONF, default_eap_type), NULL, "md5" },
30 { "timer_expire", PW_TYPE_INTEGER, offsetof(EAP_CONF, timer_limit), NULL, "60"},
32 { NULL, -1, 0, NULL, NULL } /* end the list */
35 static int eap_init(void)
42 * read the config section and load all the eap authentication types present.
44 static int eap_instantiate(CONF_SECTION *cs, void **instance)
50 rlm_eap_t **eap_stuff;
52 eap_stuff = (rlm_eap_t **)instance;
57 conf = (EAP_CONF *)malloc(sizeof(EAP_CONF));
59 radlog(L_ERR, "rlm_eap: out of memory");
62 if (cf_section_parse(cs, conf, module_config) < 0) {
67 /* Load all the configured EAP-Types */
68 for(scs=cf_subsection_find_next(cs, NULL, NULL);
70 scs=cf_subsection_find_next(cs, scs, NULL)) {
72 auth_type = cf_section_name1(scs);
74 if (!auth_type) continue;
76 if (eaptype_load(&types, auth_type, scs) < 0) {
83 free(conf->default_eap_type);
84 conf->default_eap_type = NULL;
90 *eap_stuff = (rlm_eap_t *)malloc(sizeof(rlm_eap_t));
92 (*eap_stuff)->typelist = types;
93 (*eap_stuff)->echolist = NULL;
94 (*eap_stuff)->conf = conf;
96 radlog(L_ERR, "rlm_eap: out of memory");
97 eaptype_freelist(&types);
98 free(conf->default_eap_type);
99 conf->default_eap_type = NULL;
105 /* Generate a state key, specific to eap */
111 * delete all the allocated space by eap module
113 static int eap_detach(void *instance)
116 t = (rlm_eap_t *)instance;
118 eaplist_free(&(t->echolist));
119 eaptype_freelist(&(t->typelist));
121 free(t->conf->default_eap_type);
131 * Assumption: Any one of the Authorization module should
132 * get the configured password for any valid user.
133 * If not, Authentication fails to validate.
135 * All EAP types will be handled in their respective sub modules.
137 * To Handle EAP-response, we keep track of the EAP-request we send.
138 * When Success or Failure or when timed out, we delete them.
140 static int eap_authenticate(void *instance, REQUEST *request)
142 EAP_HANDLER *handler;
143 rlm_eap_t *eap_stuff;
144 eap_packet_t *eap_packet;
147 eap_stuff = (rlm_eap_t *)instance;
150 * Always, clean the list first as it is not timer based
151 * FIXME: Appropriate cleaning mechanism.
153 eaplist_clean(&(eap_stuff->echolist), (time_t)eap_stuff->conf->timer_limit);
156 * Incase if EAP is not configured in autz block
157 * or eap_authorize is not invoked
159 status = eap_start(request);
162 return RLM_MODULE_NOOP;
164 return RLM_MODULE_FAIL;
166 return RLM_MODULE_OK;
172 /* get the eap packet to start with */
173 eap_packet = eap_attribute(request->packet->vps);
174 if (eap_packet == NULL) {
175 radlog(L_ERR, "rlm_eap: Malformed EAP Message");
176 return RLM_MODULE_FAIL;
180 * create the eap handler
182 handler = eap_handler(&(eap_stuff->echolist), &eap_packet, request);
183 if (handler == NULL) {
184 return RLM_MODULE_INVALID;
188 * No User-Name, No authentication
190 if (handler->username == NULL) {
191 radlog(L_ERR, "rlm_eap: Unknown User, authentication failed");
192 eap_fail(request, handler->eap_ds->request);
193 eap_handler_free(&handler);
194 return RLM_MODULE_REJECT;
198 * Select the appropriate eap_type or default to the configured one
200 if (eaptype_select(eap_stuff->typelist, handler,
201 eap_stuff->conf->default_eap_type) == EAP_INVALID) {
203 eap_fail(request, handler->eap_ds->request);
204 eap_handler_free(&handler);
205 return RLM_MODULE_INVALID;
209 * We are done, wrap the EAP-request in RADIUS to send
210 * with all other required radius attributes
212 eap_compose(request, handler->eap_ds->request);
215 * Add to the list only if it is EAP-Request
217 if ((handler->eap_ds->request->code == PW_EAP_REQUEST) &&
218 (handler->eap_ds->request->type.type >= PW_EAP_MD5)) {
220 handler->id = eap_generateid(request, (u_char)handler->eap_ds->request->id);
221 if (handler->id == NULL) {
222 radlog(L_ERR, "rlm_eap: problem in generating ID, Present EAP is no more Valid");
223 eap_handler_free(&handler);
225 eaplist_add(&(eap_stuff->echolist), handler);
228 /* handler is no more required, free it now */
229 eap_handler_free(&handler);
231 return RLM_MODULE_OK;
235 * EAP authorization DEPENDS on other rlm authorizations,
236 * to check for user existance & get their configured values.
237 * It Handles EAP-START Messages, User-Name initilization.
239 static int eap_authorize(void *instance, REQUEST *request)
241 VALUE_PAIR *atype, *vp;
242 rlm_eap_t *eap_stuff;
243 eap_packet_t *eap_packet;
247 eap_stuff = (rlm_eap_t *)instance;
249 /* Authorization not valid for proxies */
250 if (request->proxy != NULL)
251 return RLM_MODULE_NOOP;
254 * For EAP_START, send Access-Challenge with EAP Identity request.
255 * even when we have to proxy this request
257 status = eap_start(request);
260 return RLM_MODULE_NOOP;
262 return RLM_MODULE_FAIL;
264 return RLM_MODULE_HANDLED;
271 * We should have User-Name to proceed further
273 if (request->username == NULL) {
275 /* get the eap packet */
276 eap_packet = eap_attribute(request->packet->vps);
277 if (eap_packet == NULL) {
278 radlog(L_ERR, "rlm_eap: Malformed EAP Message");
279 return RLM_MODULE_FAIL;
282 id = eap_regenerateid(request, eap_packet->id);
284 radlog(L_ERR, "rlm_eap: User-Name cannot be obtained");
286 return RLM_MODULE_FAIL;
289 request->username = eap_useridentity(eap_stuff->echolist, eap_packet, id);
290 if (request->username == NULL) {
291 radlog(L_ERR, "rlm_eap: Unknown User, authorization failed");
294 return RLM_MODULE_FAIL;
301 * Enforce EAP authentication
303 * Auth-type(s) already set? overide it with EAP
304 * If EAP-Message is present in RADIUS, then EAP authentication is MUST.
306 * TODO: When Multiple authentications are supported in RADIUS,
307 * then prioritize EAP by prepending it before all Auth-Types
310 atype = pairfind(request->config_items, PW_AUTHTYPE);
311 if ((atype == NULL) ||
312 ((atype->lvalue != PW_AUTHTYPE_EAP) &&
313 (atype->lvalue != PW_AUTHTYPE_ACCEPT) &&
314 (atype->lvalue != PW_AUTHTYPE_REJECT))) {
316 vp = pairmake("Auth-Type", "EAP", T_OP_EQ);
318 return RLM_MODULE_FAIL;
321 pairdelete(&request->config_items, PW_AUTHTYPE);
322 pairadd(&request->config_items, vp);
325 vp->next = request->config_items;
326 request->config_items = vp;
330 return RLM_MODULE_UPDATED;
334 * The module name should be the only globally exported symbol.
335 * That is, everything else should be 'static'.
339 RLM_TYPE_THREAD_UNSAFE, /* type */
340 eap_init, /* initialization */
341 eap_instantiate, /* instantiation */
343 eap_authenticate, /* authentication */
344 eap_authorize, /* authorization */
345 NULL, /* preaccounting */
346 NULL, /* accounting */
347 NULL /* checksimul */
349 eap_detach, /* detach */