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>
27 static CONF_PARSER module_config[] = {
28 { "default_eap_type", PW_TYPE_STRING_PTR, offsetof(EAP_CONF, default_eap_type), NULL, "md5" },
29 { "timer_expire", PW_TYPE_INTEGER, offsetof(EAP_CONF, timer_limit), NULL, "60"},
31 { NULL, -1, 0, NULL, NULL } /* end the list */
34 static int eap_init(void)
41 * read the config section and load all the eap authentication types present.
43 static int eap_instantiate(CONF_SECTION *cs, void **instance)
49 rlm_eap_t **eap_stuff;
51 eap_stuff = (rlm_eap_t **)instance;
56 conf = (EAP_CONF *)malloc(sizeof(EAP_CONF));
58 radlog(L_ERR, "rlm_eap: out of memory");
61 if (cf_section_parse(cs, conf, module_config) < 0) {
66 for(scs=cf_subsection_find_next(cs, NULL, NULL);
68 scs=cf_subsection_find_next(cs, scs, NULL)) {
69 auth_name = cf_section_name1(scs);
71 if (!auth_name) continue;
72 eaptype_load(&types, auth_name, scs);
76 free(conf->default_eap_type);
77 conf->default_eap_type = NULL;
83 *eap_stuff = (rlm_eap_t *)malloc(sizeof(rlm_eap_t));
85 (*eap_stuff)->typelist = types;
86 (*eap_stuff)->echolist = NULL;
87 (*eap_stuff)->conf = conf;
89 radlog(L_ERR, "rlm_eap: out of memory");
90 eaptype_freelist(&types);
94 /* Generate a state key, specific to eap */
100 * delete all the allocated space by eap module
102 static int eap_detach(void *instance)
105 t = (rlm_eap_t *)instance;
107 eaplist_free(&(t->echolist));
108 eaptype_freelist(&(t->typelist));
110 free(t->conf->default_eap_type);
119 * Assumption: Any one of the Authorization module should
120 * get the configured password for any valid user.
121 * If not, Authentication fails to validate.
123 * All EAP types will be handled in their respective sub modules.
125 * To Handle EAP-response, we keep track of the EAP-request we send.
126 * When Success or Failure or when timed out, we delete them.
128 static int eap_authenticate(void *instance, REQUEST *request)
130 EAP_HANDLER *handler;
131 rlm_eap_t *eap_stuff;
132 eap_packet_t *eap_packet;
135 eap_stuff = (rlm_eap_t *)instance;
138 * Always, clean the list first as it is not timer based
139 * FIXME: Appropriate cleaning mechanism.
141 eaplist_clean(&(eap_stuff->echolist), (time_t)eap_stuff->conf->timer_limit);
144 * Incase if EAP is not configured in autz block
145 * or eap_authorize is not invoked
147 status = eap_start(request);
150 return RLM_MODULE_NOOP;
152 return RLM_MODULE_FAIL;
154 return RLM_MODULE_OK;
160 /* get the eap packet to start with */
161 eap_packet = eap_attribute(request->packet->vps);
162 if (eap_packet == NULL) {
163 radlog(L_ERR, "rlm_eap: Malformed EAP Message");
164 return RLM_MODULE_FAIL;
168 * create the eap handler
170 handler = eap_handler(&(eap_stuff->echolist), &eap_packet, request);
171 if (handler == NULL) {
172 return RLM_MODULE_INVALID;
176 * No User-Name, No authentication
178 if (request->username == NULL) {
179 radlog(L_ERR, "rlm_eap: Unknown User, authentication failed");
180 return RLM_MODULE_REJECT;
184 * Always get the configured values, for each user.
185 * to pass it to the specific EAP-Type
187 handler->configured = paircopy(request->config_items);
188 if (handler->configured == NULL) {
189 radlog(L_INFO, "rlm_eap: No configured information for this user");
192 * FIXME: I think at least one item should be configured for any user
193 * If nothing is configured, then atleast
194 * config_items should provide the same username
195 * if the user is present in the database
198 eap_fail(request, handler->eap_ds->request);
199 eap_handler_free(&handler);
200 return RLM_MODULE_INVALID;
206 * Select the appropriate eap_type or default to the configured one
208 if (eaptype_select(eap_stuff->typelist, handler,
209 eap_stuff->conf->default_eap_type) == EAP_INVALID) {
211 eap_fail(request, handler->eap_ds->request);
212 eap_handler_free(&handler);
213 return RLM_MODULE_INVALID;
217 * We are done, wrap the EAP-request in RADIUS to send
218 * with all other required radius attributes
220 eap_compose(request, handler->eap_ds->request);
223 * Add to the list only if it is EAP-Request
225 if ((handler->eap_ds->request->code == PW_EAP_REQUEST) &&
226 (handler->eap_ds->request->type.type >= PW_EAP_MD5)) {
228 handler->id = eap_generateid(request, (u_char)handler->eap_ds->request->id);
229 if (handler->id == NULL) {
230 radlog(L_ERR, "rlm_eap: problem in generating ID, Present EAP is no more Valid");
231 eap_handler_free(&handler);
233 eaplist_add(&(eap_stuff->echolist), handler);
236 /* handler is no more required, free it now */
237 eap_handler_free(&handler);
239 return RLM_MODULE_OK;
243 * EAP authorization DEPENDS on other rlm authorizations,
244 * to check for user existance & get their configured values.
245 * It Handles EAP-START Messages, User-Name initilization.
247 static int eap_authorize(void *instance, REQUEST *request)
249 VALUE_PAIR *atype, *vp;
250 rlm_eap_t *eap_stuff;
251 eap_packet_t *eap_packet;
255 eap_stuff = (rlm_eap_t *)instance;
257 /* Authorization not valid for proxies */
258 if (request->proxy != NULL)
259 return RLM_MODULE_NOOP;
262 * For EAP_START, send Access-Challenge with EAP Identity request.
263 * even when we have to proxy this request
265 status = eap_start(request);
268 return RLM_MODULE_NOOP;
270 return RLM_MODULE_FAIL;
272 return RLM_MODULE_HANDLED;
279 * We should have User-Name to proceed further
281 if (request->username == NULL) {
283 /* get the eap packet */
284 eap_packet = eap_attribute(request->packet->vps);
285 if (eap_packet == NULL) {
286 radlog(L_ERR, "rlm_eap: Malformed EAP Message");
287 return RLM_MODULE_FAIL;
290 id = eap_regenerateid(request, eap_packet->id);
292 radlog(L_ERR, "rlm_eap: User-Name cannot be obtained");
294 return RLM_MODULE_FAIL;
297 request->username = eap_useridentity(eap_stuff->echolist, eap_packet, id);
298 if (request->username == NULL) {
299 radlog(L_ERR, "rlm_eap: Unknown User, authorization failed");
302 return RLM_MODULE_FAIL;
309 * Enforce EAP authentication
311 * Auth-type(s) already set? overide it with EAP
312 * If EAP-Message is present in RADIUS, then EAP authentication is MUST.
314 * TODO: When Multiple authentications are supported in RADIUS,
315 * then prioritize EAP by prepending it before all Auth-Types
318 atype = pairfind(request->config_items, PW_AUTHTYPE);
319 if ((atype == NULL) ||
320 ((atype->lvalue != PW_AUTHTYPE_EAP) &&
321 (atype->lvalue != PW_AUTHTYPE_ACCEPT) &&
322 (atype->lvalue != PW_AUTHTYPE_REJECT))) {
324 vp = pairmake("Auth-Type", "EAP", T_OP_EQ);
326 return RLM_MODULE_FAIL;
329 pairdelete(&request->config_items, PW_AUTHTYPE);
330 pairadd(&request->config_items, vp);
333 vp->next = request->config_items;
334 request->config_items = vp;
338 return RLM_MODULE_UPDATED;
342 * The module name should be the only globally exported symbol.
343 * That is, everything else should be 'static'.
347 RLM_TYPE_THREAD_UNSAFE, /* type */
348 eap_init, /* initialization */
349 eap_instantiate, /* instantiation */
351 eap_authenticate, /* authentication */
352 eap_authorize, /* authorization */
353 NULL, /* preaccounting */
354 NULL, /* accounting */
355 NULL /* checksimul */
357 eap_detach, /* detach */