backport from HEAD
[freeradius.git] / src / modules / rlm_eap / rlm_eap.h
1 /*
2  * rlm_eap.h    Local Header file.
3  *
4  * Version:     $Id$
5  *
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.
10  *
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.
15  *
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
19  *
20  * Copyright 2001  hereUare Communications, Inc. <raghud@hereuare.com>
21  * Copyright 2003  Alan DeKok <aland@freeradius.org>
22  */
23 #ifndef _RLM_EAP_H
24 #define _RLM_EAP_H
25
26 #include <ltdl.h>
27 #include "eap.h"
28 #include "eap_types.h"
29
30 /*
31  * Keep track of which sub modules we've loaded.
32  */
33 typedef struct eap_types_t {
34         const char      *typename;
35         EAP_TYPE        *type;
36         lt_dlhandle     handle;
37         CONF_SECTION    *cs;
38         void            *type_data;
39 } EAP_TYPES;
40
41 /*
42  * This structure contains eap's persistent data.
43  * sessions[] = EAP_HANDLERS, keyed by the first octet of the State
44  *              attribute, and composed of a linked list, ordered from
45  *              oldest to newest.
46  * types = All supported EAP-Types
47  * mutex = ensure only one thread is updating the sessions[] struct
48  */
49 typedef struct rlm_eap_t {
50         EAP_HANDLER     *sessions[256];
51         EAP_TYPES       *types[PW_EAP_MAX_TYPES + 1];
52
53         /*
54          *      Configuration items.
55          */
56         char            *default_eap_type_name;
57         int             timer_limit;
58         int             default_eap_type;
59         int             ignore_unknown_eap_types;
60         int             cisco_accounting_username_bug;
61
62 #ifdef HAVE_PTHREAD_H
63         pthread_mutex_t session_mutex;
64         pthread_mutex_t module_mutex;
65 #endif
66 } rlm_eap_t;
67
68 /* function definitions */
69 /* EAP-Type */
70 int             eaptype_load(EAP_TYPES **type, int eap_type, CONF_SECTION *cs);
71 int             eaptype_select(rlm_eap_t *inst, EAP_HANDLER *h);
72 void            eaptype_free(EAP_TYPES *tl);
73
74 /* EAP */
75 int             eap_start(rlm_eap_t *inst, REQUEST *request);
76 void            eap_fail(EAP_HANDLER *handler);
77 void            eap_success(EAP_HANDLER *handler);
78 int             eap_compose(EAP_HANDLER *handler);
79 EAP_HANDLER     *eap_handler(rlm_eap_t *inst, eap_packet_t **eap_msg, REQUEST *request);
80
81 /* Memory Management */
82 EAP_PACKET      *eap_packet_alloc(void);
83 EAP_DS          *eap_ds_alloc(void);
84 EAP_HANDLER     *eap_handler_alloc(void);
85 void            eap_packet_free(EAP_PACKET **eap_packet);
86 void            eap_ds_free(EAP_DS **eap_ds);
87 void            eap_handler_free(EAP_HANDLER **handler);
88
89 int             eaplist_add(rlm_eap_t *inst, EAP_HANDLER *handler);
90 void            eaplist_free(rlm_eap_t *inst);
91 EAP_HANDLER     *eaplist_find(rlm_eap_t *inst, REQUEST *request,
92                               eap_packet_t *eap_packet);
93
94 /* State */
95 void            generate_key(void);
96 VALUE_PAIR      *generate_state(time_t timestamp);
97 int             verify_state(VALUE_PAIR *state, time_t timestamp);
98
99 #endif /*_RLM_EAP_H*/