The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
base.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 2 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
15  */
16 
17 /**
18  * $Id: 85a68830b1e9e73cda6866ca2a1391a2cebfa5ac $
19  * @file src/process/tls/base.c
20  * @brief TLS processing.
21  *
22  * @copyright 2021 Arran Cudbard-Bell (a.cudbardb@freeradius.org)
23  */
24 #include <freeradius-devel/server/protocol.h>
25 #include <freeradius-devel/util/debug.h>
26 #include <freeradius-devel/protocol/tls/freeradius.h>
27 
28 static fr_dict_t const *dict_tls;
29 
32  { .out = &dict_tls, .proto = "tls" },
33  { NULL }
34 };
35 
37 
40  { .out = &attr_packet_type, .name = "Packet-Type", .type = FR_TYPE_UINT32, .dict = &dict_tls},
41  { NULL }
42 };
43 
44 typedef struct {
50 
51 typedef struct {
54 
55 #define FR_TLS_PACKET_CODE_VALID(_code) (((_code) > 0) && ((_code) <= FR_PACKET_TYPE_VALUE_NOTFOUND))
56 
57 #define PROCESS_INST process_tls_t
58 #define PROCESS_PACKET_TYPE uint32_t
59 #define PROCESS_PACKET_CODE_VALID FR_TLS_PACKET_CODE_VALID
60 
61 #include <freeradius-devel/server/process.h>
62 
63 static fr_process_state_t const process_state[] = {
64  [FR_PACKET_TYPE_VALUE_LOAD_SESSION] = {
65  .packet_type = {
66  [RLM_MODULE_OK] = FR_PACKET_TYPE_VALUE_SUCCESS,
67  [RLM_MODULE_UPDATED] = FR_PACKET_TYPE_VALUE_SUCCESS,
68 
69  [RLM_MODULE_NOOP] = FR_PACKET_TYPE_VALUE_FAILURE,
70  [RLM_MODULE_REJECT] = FR_PACKET_TYPE_VALUE_FAILURE,
71  [RLM_MODULE_FAIL] = FR_PACKET_TYPE_VALUE_FAILURE,
72  [RLM_MODULE_INVALID] = FR_PACKET_TYPE_VALUE_FAILURE,
73  [RLM_MODULE_DISALLOW] = FR_PACKET_TYPE_VALUE_FAILURE,
74  [RLM_MODULE_NOTFOUND] = FR_PACKET_TYPE_VALUE_NOTFOUND,
75  },
76  .rcode = RLM_MODULE_NOOP,
77  .recv = recv_generic,
78  .resume = resume_recv_no_send,
79  .section_offset = PROCESS_CONF_OFFSET(load_session),
80  },
81  [FR_PACKET_TYPE_VALUE_STORE_SESSION] = {
82  .packet_type = {
83  [RLM_MODULE_OK] = FR_PACKET_TYPE_VALUE_SUCCESS,
84  [RLM_MODULE_UPDATED] = FR_PACKET_TYPE_VALUE_SUCCESS,
85 
86  [RLM_MODULE_NOOP] = FR_PACKET_TYPE_VALUE_FAILURE,
87  [RLM_MODULE_REJECT] = FR_PACKET_TYPE_VALUE_FAILURE,
88  [RLM_MODULE_FAIL] = FR_PACKET_TYPE_VALUE_FAILURE,
89  [RLM_MODULE_INVALID] = FR_PACKET_TYPE_VALUE_FAILURE,
90  [RLM_MODULE_DISALLOW] = FR_PACKET_TYPE_VALUE_FAILURE,
91  [RLM_MODULE_NOTFOUND] = FR_PACKET_TYPE_VALUE_NOTFOUND,
92  },
93  .rcode = RLM_MODULE_NOOP,
94  .recv = recv_generic,
95  .resume = resume_recv_no_send,
96  .section_offset = PROCESS_CONF_OFFSET(store_session),
97  },
98  [FR_PACKET_TYPE_VALUE_CLEAR_SESSION] = {
99  .packet_type = {
100  [RLM_MODULE_OK] = FR_PACKET_TYPE_VALUE_SUCCESS,
101  [RLM_MODULE_UPDATED] = FR_PACKET_TYPE_VALUE_SUCCESS,
102 
103  [RLM_MODULE_NOOP] = FR_PACKET_TYPE_VALUE_FAILURE,
104  [RLM_MODULE_REJECT] = FR_PACKET_TYPE_VALUE_FAILURE,
105  [RLM_MODULE_FAIL] = FR_PACKET_TYPE_VALUE_FAILURE,
106  [RLM_MODULE_INVALID] = FR_PACKET_TYPE_VALUE_FAILURE,
107  [RLM_MODULE_DISALLOW] = FR_PACKET_TYPE_VALUE_FAILURE,
108  [RLM_MODULE_NOTFOUND] = FR_PACKET_TYPE_VALUE_NOTFOUND,
109  },
110  .rcode = RLM_MODULE_NOOP,
111  .recv = recv_generic,
112  .resume = resume_recv_no_send,
113  .section_offset = PROCESS_CONF_OFFSET(clear_session),
114  },
115  [FR_PACKET_TYPE_VALUE_VERIFY_CERTIFICATE] = {
116  .packet_type = {
117  [RLM_MODULE_OK] = FR_PACKET_TYPE_VALUE_SUCCESS,
118  [RLM_MODULE_UPDATED] = FR_PACKET_TYPE_VALUE_SUCCESS,
119  [RLM_MODULE_NOOP] = FR_PACKET_TYPE_VALUE_SUCCESS,
120 
121  [RLM_MODULE_REJECT] = FR_PACKET_TYPE_VALUE_FAILURE,
122  [RLM_MODULE_FAIL] = FR_PACKET_TYPE_VALUE_FAILURE,
123  [RLM_MODULE_INVALID] = FR_PACKET_TYPE_VALUE_FAILURE,
124  [RLM_MODULE_DISALLOW] = FR_PACKET_TYPE_VALUE_FAILURE,
125  [RLM_MODULE_NOTFOUND] = FR_PACKET_TYPE_VALUE_NOTFOUND,
126  },
127  .rcode = RLM_MODULE_NOOP,
128  .recv = recv_generic,
129  .resume = resume_recv_no_send,
130  .section_offset = PROCESS_CONF_OFFSET(verify_certificate),
131  },
132 };
133 
134 static unlang_action_t mod_process(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
135 {
136  fr_process_state_t const *state;
137 
139 
141 
142  request->component = "tls";
143  request->module = NULL;
144  fr_assert(request->dict == dict_tls);
145 
146  UPDATE_STATE(packet);
147 
148  log_request_pair_list(L_DBG_LVL_1, request, NULL, &request->request_pairs, NULL);
149 
150  return state->recv(p_result, mctx, request);
151 }
152 
154  {
155  .name = "store",
156  .name2 = "session",
157  .component = MOD_AUTHORIZE,
158  .offset = PROCESS_CONF_OFFSET(store_session)
159  },
160  {
161  .name = "load",
162  .name2 = "session",
163  .component = MOD_AUTHORIZE,
164  .offset = PROCESS_CONF_OFFSET(load_session)
165  },
166  {
167  .name = "clear",
168  .name2 = "session",
169  .component = MOD_AUTHORIZE,
170  .offset = PROCESS_CONF_OFFSET(clear_session)
171  },
172  {
173  .name = "verify",
174  .name2 = "certificate",
175  .component = MOD_AUTHORIZE,
176  .offset = PROCESS_CONF_OFFSET(verify_certificate)
177  },
179 };
180 
181 
184  .common = {
185  .magic = MODULE_MAGIC_INIT,
186  .name = "tls",
187  .inst_size = sizeof(process_tls_t)
188  },
189  .process = mod_process,
190  .compile_list = compile_list,
191  .dict = &dict_tls,
192 };
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
Definition: action.h:35
A section grouping multiple CONF_PAIR.
Definition: cf_priv.h:89
@ MOD_AUTHORIZE
1 methods index for authorize section.
Definition: components.h:34
fr_dict_attr_t const ** out
Where to write a pointer to the resolved fr_dict_attr_t.
Definition: dict.h:250
fr_dict_t const ** out
Where to write a pointer to the loaded/resolved fr_dict_t.
Definition: dict.h:263
Specifies an attribute which must be present for the module to function.
Definition: dict.h:249
Specifies a dictionary which must be loaded/loadable for the module to function.
Definition: dict.h:262
void *_CONST data
Module instance's parsed configuration.
Definition: dl_module.h:165
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
Definition: dl_module.h:65
void log_request_pair_list(fr_log_lvl_t lvl, request_t *request, fr_pair_t const *parent, fr_pair_list_t const *vps, char const *prefix)
Print a fr_pair_list_t.
Definition: log.c:821
@ L_DBG_LVL_1
Highest priority debug messages (-x).
Definition: log.h:70
@ FR_TYPE_UINT32
32 Bit unsigned integer.
Definition: merged_model.c:99
dl_module_inst_t const * inst
Dynamic loader API handle for the module.
Definition: module_ctx.h:42
Temporary structure to hold arguments for module calls.
Definition: module_ctx.h:41
static fr_dict_attr_t const * attr_packet_type
Definition: base.c:36
static unlang_action_t mod_process(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
Definition: base.c:134
fr_process_module_t process_tls
Definition: base.c:183
static fr_dict_t const * dict_tls
Definition: base.c:28
static const virtual_server_compile_t compile_list[]
Definition: base.c:153
CONF_SECTION * store_session
Definition: base.c:46
static fr_process_state_t const process_state[]
Definition: base.c:63
fr_dict_autoload_t process_tls_dict[]
Definition: base.c:31
CONF_SECTION * load_session
Definition: base.c:45
CONF_SECTION * clear_session
Definition: base.c:47
fr_dict_attr_autoload_t process_tls_dict_attr[]
Definition: base.c:39
CONF_SECTION * verify_certificate
Definition: base.c:48
process_tls_sections_t sections
Definition: base.c:52
#define PROCESS_TRACE
Trace each state function as it's entered.
Definition: process.h:65
module_t common
Common fields for all loadable modules.
Definition: process.h:55
Common public symbol definition for all process modules.
Definition: process.h:54
rlm_rcode_t
Return codes indicating the result of the module call.
Definition: rcode.h:40
@ RLM_MODULE_INVALID
The module considers the request invalid.
Definition: rcode.h:45
@ RLM_MODULE_OK
The module is OK, continue.
Definition: rcode.h:43
@ RLM_MODULE_FAIL
Module failed, don't reply.
Definition: rcode.h:42
@ RLM_MODULE_DISALLOW
Reject the request (user is locked out).
Definition: rcode.h:46
@ RLM_MODULE_REJECT
Immediately reject the request.
Definition: rcode.h:41
@ RLM_MODULE_NOTFOUND
User not found.
Definition: rcode.h:47
@ RLM_MODULE_UPDATED
OK (pairs modified).
Definition: rcode.h:49
@ RLM_MODULE_NOOP
Module succeeded without doing anything.
Definition: rcode.h:48
fr_assert(0)
#define talloc_get_type_abort_const
Definition: talloc.h:270
#define COMPILE_TERMINATOR
char const * name
Name of the processing section, such as "recv" or "send".
Processing sections which are allowed in this virtual server.