Create new mutex for Access-Challenge debug code.
[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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  *
20  * Copyright 2001  hereUare Communications, Inc. <raghud@hereuare.com>
21  * Copyright 2003  Alan DeKok <aland@freeradius.org>
22  * Copyright 2006  The FreeRADIUS server project
23  */
24 #ifndef _RLM_EAP_H
25 #define _RLM_EAP_H
26
27 #include <freeradius-devel/ident.h>
28 RCSIDH(rlm_eap_h, "$Id$")
29
30 #include <freeradius-devel/modpriv.h>
31 #include "eap.h"
32 #include "eap_types.h"
33
34 /*
35  * Keep track of which sub modules we've loaded.
36  */
37 typedef struct eap_types_t {
38         const char      *typename;
39         EAP_TYPE        *type;
40         lt_dlhandle     handle;
41         CONF_SECTION    *cs;
42         void            *type_data;
43 } EAP_TYPES;
44
45 /*
46  * This structure contains eap's persistent data.
47  * sessions = remembered sessions, in a tree for speed.
48  * types = All supported EAP-Types
49  * mutex = ensure only one thread is updating the sessions[] struct
50  */
51 typedef struct rlm_eap_t {
52         rbtree_t        *session_tree;
53         EAP_HANDLER     *session_head, *session_tail;
54         rbtree_t        *handler_tree; /* for debugging only */
55         EAP_TYPES       *types[PW_EAP_MAX_TYPES + 1];
56
57         /*
58          *      Configuration items.
59          */
60         int             timer_limit;
61         char            *default_eap_type_name;
62         int             default_eap_type;
63         int             ignore_unknown_eap_types;
64         int             cisco_accounting_username_bug;
65         int             max_sessions;
66
67 #ifdef HAVE_PTHREAD_H
68         pthread_mutex_t session_mutex;
69         pthread_mutex_t handler_mutex;
70 #endif
71
72         const char      *xlat_name; /* no xlat's yet */
73         fr_randctx      rand_pool;
74 } rlm_eap_t;
75
76 /*
77  *      For simplicity in the rest of the code.
78  */
79 #ifndef HAVE_PTHREAD_H
80 /*
81  *      This is easier than ifdef's throughout the code.
82  */
83 #define pthread_mutex_init(_x, _y)
84 #define pthread_mutex_destroy(_x)
85 #define pthread_mutex_lock(_x)
86 #define pthread_mutex_unlock(_x)
87 #endif
88
89 /* function definitions */
90 /* EAP-Type */
91 int             eaptype_load(EAP_TYPES **type, int eap_type, CONF_SECTION *cs);
92 int             eaptype_select(rlm_eap_t *inst, EAP_HANDLER *h);
93 void            eaptype_free(EAP_TYPES *tl);
94
95 /* EAP */
96 int             eap_start(rlm_eap_t *inst, REQUEST *request);
97 void            eap_fail(EAP_HANDLER *handler);
98 void            eap_success(EAP_HANDLER *handler);
99 int             eap_compose(EAP_HANDLER *handler);
100 EAP_HANDLER     *eap_handler(rlm_eap_t *inst, eap_packet_t **eap_msg, REQUEST *request);
101
102 /* Memory Management */
103 EAP_PACKET      *eap_packet_alloc(void);
104 EAP_DS          *eap_ds_alloc(void);
105 EAP_HANDLER     *eap_handler_alloc(rlm_eap_t *inst);
106 void            eap_packet_free(EAP_PACKET **eap_packet);
107 void            eap_ds_free(EAP_DS **eap_ds);
108 void            eap_handler_free(rlm_eap_t *inst, EAP_HANDLER *handler);
109
110 int             eaplist_add(rlm_eap_t *inst, EAP_HANDLER *handler);
111 EAP_HANDLER     *eaplist_find(rlm_eap_t *inst, REQUEST *request,
112                               eap_packet_t *eap_packet);
113 void            eaplist_free(rlm_eap_t *inst);
114
115 /* State */
116 void            generate_key(void);
117 VALUE_PAIR      *generate_state(time_t timestamp);
118 int             verify_state(VALUE_PAIR *state, time_t timestamp);
119
120 #endif /*_RLM_EAP_H*/