The FreeRADIUS server $Id: a4e7f8c94e8038b7627bcf52356b7ed15955c1d7 $
Loading...
Searching...
No Matches
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: abf81a2fc886e055dc7fa0d69543acb8677d71ef $
19 * @file src/process/crl/base.c
20 * @brief State machine for CRL coordinator thread
21 *
22 * @copyright 2026 Network RADIUS SAS (legal@networkradius.com)
23 */
24#ifdef WITH_TLS
25#include <freeradius-devel/crl/crl.h>
26#include <freeradius-devel/io/coord_pair.h>
27#include <freeradius-devel/server/main_config.h>
28#include <freeradius-devel/tls/strerror.h>
29#include <freeradius-devel/tls/utils.h>
30#include <freeradius-devel/unlang/interpret.h>
31#include <freeradius-devel/util/debug.h>
32
33#include <openssl/x509.h>
34#include <openssl/x509v3.h>
35#include <openssl/asn1.h>
36
37static fr_dict_t const *dict_crl;
38static fr_dict_t const *dict_freeradius;
39
40extern fr_dict_autoload_t process_crl_dict[];
41fr_dict_autoload_t process_crl_dict[] = {
42 { .out = &dict_crl, .proto = "crl" },
43 { .out = &dict_freeradius, .proto = "freeradius" },
45};
46
49static fr_dict_attr_t const *attr_base_crl;
50static fr_dict_attr_t const *attr_crl_data;
51static fr_dict_attr_t const *attr_crl_num;
52static fr_dict_attr_t const *attr_delta_crl;
53static fr_dict_attr_t const *attr_last_update;
54static fr_dict_attr_t const *attr_next_update;
55static fr_dict_attr_t const *attr_worker_id;
56
57extern fr_dict_attr_autoload_t process_crl_dict_attr[];
58fr_dict_attr_autoload_t process_crl_dict_attr[] = {
59 { .out = &attr_packet_type, .name = "Packet-Type", .type = FR_TYPE_UINT32, .dict = &dict_crl },
60 { .out = &attr_crl_cdp_url, .name = "CDP-URL", .type = FR_TYPE_STRING, .dict = &dict_crl },
61 { .out = &attr_base_crl, .name = "Base-CRL", .type = FR_TYPE_STRING, .dict = &dict_crl },
62 { .out = &attr_crl_data, .name = "CRL-Data", .type = FR_TYPE_OCTETS, .dict = &dict_crl },
63 { .out = &attr_crl_num, .name = "CRL-Num", .type = FR_TYPE_UINT64, .dict = &dict_crl },
64 { .out = &attr_delta_crl, .name = "Delta-CRL", .type = FR_TYPE_STRING, .dict = &dict_crl },
65 { .out = &attr_last_update, .name = "Last-Update", .type = FR_TYPE_DATE, .dict = &dict_crl },
66 { .out = &attr_next_update, .name = "Next-Update", .type = FR_TYPE_DATE, .dict = &dict_crl },
67 { .out = &attr_worker_id, .name = "Worker-Id", .type = FR_TYPE_INT32, .dict = &dict_freeradius },
68
70};
71
72typedef struct {
73 uint64_t nothing; // so that the next field isn't at offset 0
74
75 CONF_SECTION *crl_fetch;
76 CONF_SECTION *fetch_ok;
77 CONF_SECTION *fetch_fail;
78 CONF_SECTION *do_not_respond;
79} process_crl_sections_t;
80
81typedef struct {
82 fr_rb_tree_t crls; //!< Fetched CRL data.
83 fr_dlist_head_t fetching; //!< List of CRLs currently being fetched.
84} process_crl_mutable_t;
85
86typedef struct {
87 process_crl_sections_t sections; //!< Pointers to various config sections
88 ///< we need to execute
89
90 fr_time_delta_t force_refresh; //!< Force refresh of CRLs after this time
91 bool force_refresh_is_set;
92 fr_time_delta_t force_delta_refresh; //!< Force refresh of delta CRLs after this time
93 bool force_delta_refresh_is_set;
94 fr_time_delta_t early_refresh; //!< Time interval before nextUpdate to refresh
95 fr_time_delta_t retry_delay; //!< Delay between retries of failed refreshes.
96 char const *ca_file; //!< File containing certs for verifying CRL signatures.
97 char const *ca_path; //!< Directory containing certs for verifying CRL signatures.
98
99 bool allow_expired; //!< Will CRLs be accepted after nextUpdate
100 bool allow_not_yet_valid; //!< Will CRLs be accepted before lastUpdate
101
102 X509_STORE *verify_store; //!< Store of certificates to verify CRL signatures;
103
104 process_crl_mutable_t *mutable; //!< Mutable data
105} process_crl_t;
106
107typedef struct {
108 fr_event_list_t *el; //!< Event list for CRL refresh events.
109} process_thread_crl_t;
110
111static const conf_parser_t config[] = {
112 { FR_CONF_OFFSET_IS_SET("force_refresh", FR_TYPE_TIME_DELTA, 0, process_crl_t, force_refresh) },
113 { FR_CONF_OFFSET_IS_SET("force_delta_refresh", FR_TYPE_TIME_DELTA, 0, process_crl_t, force_delta_refresh) },
114 { FR_CONF_OFFSET("early_refresh", process_crl_t, early_refresh) },
115 { FR_CONF_OFFSET("retry_delay", process_crl_t, retry_delay), .dflt = "30s" },
116 { FR_CONF_OFFSET("ca_file", process_crl_t, ca_file) },
117 { FR_CONF_OFFSET("ca_path", process_crl_t, ca_path) },
118 { FR_CONF_OFFSET("allow_expired", process_crl_t, allow_expired) },
119 { FR_CONF_OFFSET("allow_not_yet_valid", process_crl_t, allow_not_yet_valid) },
121};
122
123typedef enum : uint8_t {
124 CRL_TYPE_BASE,
125 CRL_TYPE_DELTA
126} crl_type_t;
127
128/** A single CRL in the list of CRLs
129 */
130typedef struct {
131 fr_value_box_t const *cdp_url; //!< The URL of the CRL.
132 crl_type_t type; //!< What type of CRL is this.
133 uint8_t *crl_data; //!< The CRL data.
134 time_t last_update; //!< Last update value extracted from the CRL.
135 time_t next_update; //!< Next update value extracted from the CRL.
136 ASN1_INTEGER *crl_num; //!< The CRL number.
137 fr_rb_node_t node; //!< The node in the tree of CRLs;
138 fr_time_t refresh; //!< Refresh time of the CRL.
139 union {
140 fr_value_box_list_t delta_urls; //!< URLs from which a delta CRL can be retrieved
141 fr_value_box_t const *base_url; //!< Base URL if this is a delta
142 };
143 process_crl_t *inst; //!< Module instance this entry is associated with.
144 fr_coord_pair_t *coord_pair; //!< The coord_pair which requested this CRL.
145 fr_timer_t *ev; //!< Timer event for renewal.
147
148/** An entry in the list of CRLs currently being fetched.
149 */
150typedef struct {
151 fr_value_box_t const *cdp_url; //!< URL being fetched.
152 bool *workers; //!< True for each worker waiting for a response.
153 fr_dlist_t entry; //!< Entry in list of CRLs being fetched.
154} crl_fetch_t;
155
156/** An entry in the list of CRL requests pending a currently running fetch
157 */
158typedef struct {
160 int32_t worker_id;
161 fr_dlist_t entry;
162} crl_pending_request_t;
163
164/** Compare two CRLs in the list of entries by URL
165 */
166static fr_cmp_ret_t crl_cmp(void const *a, void const *b)
167{
168 crl_entry_t const *crl_a = (crl_entry_t const *)a;
169 crl_entry_t const *crl_b = (crl_entry_t const *)b;
170
171 return fr_value_box_cmp(crl_a->cdp_url, crl_b->cdp_url);
172}
173
174/** Resume context for CRL requests */
175typedef struct {
176 unlang_result_t result; //!< Where process section results are written to
177 int32_t worker_id; //!< The worker which sent the data leading to this request.
178 fr_value_box_t const *cdp_url; //!< The URL of the CRL being requested.
179 crl_entry_t *crl_entry; //!< The existing instance a CRL, if previously fetched.
180 crl_entry_t *base_crl; //!< The base CRL a delta CRL is related to.
181 bool cached; //!< This is a cached response.
182 bool refresh; //!< Is this a refresh request.
183} process_crl_rctx_t;
184
185#define FR_CRL_PACKET_CODE_VALID(_code) (((_code) > 0) && ((_code) < FR_CRL_CODE_MAX))
186#define FR_CRL_PROCESS_CODE_VALID(_code) (FR_CRL_PACKET_CODE_VALID(_code) || (_code == FR_CRL_DO_NOT_RESPOND))
187
188#define PROCESS_PACKET_TYPE fr_crl_packet_code_t
189#define PROCESS_CODE_MAX FR_CRL_CODE_MAX
190#define PROCESS_CODE_DO_NOT_RESPOND FR_CRL_DO_NOT_RESPOND
191#define PROCESS_PACKET_CODE_VALID FR_CRL_PROCESS_CODE_VALID
192#define PROCESS_INST process_crl_t
193#define PROCESS_RCTX process_crl_rctx_t
194
195#include <freeradius-devel/server/process.h>
196
197RECV(crl_fetch);
198RECV(crl_refresh);
199
200/** Common setup used by both CRL-Fetch and CRL-Refresh
201 */
202static unlang_action_t fetch_setup_common(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request,
203 fr_pair_t *vp, process_crl_rctx_t *rctx)
204{
205 process_crl_t *inst = talloc_get_type_abort(mctx->mi->data, process_crl_t);
206 crl_fetch_t *fetch;
207
208 /*
209 * Check to see if we're already fetching this URL. If so, record
210 * that this worker wants the reply, and just Do Not Respond.
211 */
212 fr_dlist_foreach(&inst->mutable->fetching, crl_fetch_t, fetching) {
213 if (fr_value_box_cmp(fetching->cdp_url, &vp->data) == 0) {
214 if (rctx->worker_id >= 0) fetching->workers[rctx->worker_id] = true;
215 RDEBUG2("CRL already being fetched");
216 return CALL_SEND_TYPE(FR_CRL_DO_NOT_RESPOND);
217 }
218 }
219
220 /*
221 * Cache the URI / Base CRL incase the pair gets altered / deleted in the process section.
222 */
223 MEM(rctx->cdp_url = fr_value_box_acopy(rctx, &vp->data));
224
225 vp = fr_pair_find_by_da(&request->request_pairs, NULL, attr_base_crl);
226 if (vp) {
227 crl_entry_t find;
228 find.cdp_url = &vp->data;
229 fr_rb_find((void **)&rctx->base_crl, &inst->mutable->crls, &find);
230 }
231
232 /*
233 * Record what CRL we're fetching in the list.
234 */
235 MEM(fetch = talloc(inst->mutable, crl_fetch_t));
236 fetch->cdp_url = rctx->cdp_url;
237 fetch->workers = talloc_zero_array(fetch, bool, main_config->max_workers);
238 fr_dlist_insert_tail(&inst->mutable->fetching, fetch);
239
240 return CALL_RECV(generic);
241}
242
243/** Build reply pairs from a CRL
244 *
245 * Pairs are marked as immutable to prevent changes when run through send Fetch-OK
246 */
247static int crl_build_reply(request_t *request, crl_entry_t *crl_entry)
248{
249 fr_pair_t *vp;
250
251 if (pair_update_reply(&vp, attr_crl_cdp_url) < 0) return -1;
253 if (unlikely(fr_value_box_copy(vp, &vp->data, crl_entry->cdp_url) < 0)) return -1;
255
256 if (fr_pair_append_by_da(request->reply_ctx, &vp, &request->reply_pairs, attr_crl_num)< 0) return -1;
257 ASN1_INTEGER_get_uint64(&vp->vp_uint64, crl_entry->crl_num);
259
260 if (crl_entry->type == CRL_TYPE_BASE) {
261 fr_value_box_list_foreach(&crl_entry->delta_urls, delta_url) {
262 if (fr_pair_append_by_da(request->reply_ctx, &vp, &request->reply_pairs,
263 attr_delta_crl) < 0) return -1;
264 if (unlikely(fr_value_box_copy(vp, &vp->data, delta_url) < 0)) {
265 fr_pair_remove(&request->reply_pairs, vp);
267 }
269 }
270 }
271
272 if (fr_pair_append_by_da(request->reply_ctx, &vp, &request->reply_pairs, attr_last_update) < 0) return -1;
273 vp->vp_date = fr_unix_time_from_sec(crl_entry->last_update);
275
276 if (fr_pair_append_by_da(request->reply_ctx, &vp, &request->reply_pairs, attr_next_update) < 0) return -1;
277 vp->vp_date = fr_unix_time_from_sec(crl_entry->next_update);
279
280 return 0;
281}
282
283/** CRL-Fetch packets are sent from workers to the coordinator.
284 *
285 * They can reply with cached data if it exists, otherwise a fetch will
286 * be initiated.
287 *
288 * Replies will always be sent back.
289 */
290RECV(crl_fetch)
291{
292 process_crl_t *inst = talloc_get_type_abort(mctx->mi->data, process_crl_t);
293 process_crl_rctx_t *rctx = talloc_get_type_abort(mctx->rctx, process_crl_rctx_t);
294 fr_pair_t *vp = fr_pair_find_by_da(&request->request_pairs, NULL, attr_worker_id);
295 crl_entry_t find, *crl_entry;
296
297 if (!vp) return UNLANG_ACTION_FAIL;
298 rctx->worker_id = vp->vp_int32;
299
300 vp = fr_pair_find_by_da(&request->request_pairs, NULL, attr_crl_cdp_url);
301 if (!vp) return UNLANG_ACTION_FAIL;
302
303 find.cdp_url = &vp->data;
304 fr_rb_find((void **)&crl_entry, &inst->mutable->crls, &find);
305 rctx->crl_entry = crl_entry;
306
307 /*
308 * If we found the data, send it back without running the process section as long as it's not expired.
309 */
310 if (crl_entry && (inst->allow_expired || fr_time_gt(fr_time_from_sec(crl_entry->next_update),
311 fr_time_from_sec(time(NULL))))) {
312 if (fr_pair_append_by_da(request->reply_ctx, &vp, &request->reply_pairs,
313 attr_crl_data) < 0) return CALL_SEND_TYPE(FR_CRL_FETCH_FAIL);
314 fr_value_box_memdup_buffer(vp, &vp->data, NULL, crl_entry->crl_data, false);
316
317 if (crl_build_reply(request, crl_entry) < 0) return CALL_SEND_TYPE(FR_CRL_FETCH_FAIL);
318
319 rctx->cached = true;
320 return CALL_SEND_TYPE(FR_CRL_FETCH_OK);
321 }
322
323 return fetch_setup_common(p_result, mctx, request, vp, rctx);
324}
325
326/** CRL-Refresh packets are generated within the coordinator by refresh timer events
327 *
328 * Fetching of CRL data is run through the recv Fetch-CRL process section.
329 * Data will only be sent to workers if the refresh fetched a newer CRL.
330 */
331RECV(crl_refresh) {
332 process_crl_t *inst = talloc_get_type_abort(mctx->mi->data, process_crl_t);
333 process_crl_rctx_t *rctx = talloc_get_type_abort(mctx->rctx, process_crl_rctx_t);
334 fr_pair_t *vp = fr_pair_find_by_da(&request->request_pairs, NULL, attr_crl_cdp_url);
335 crl_entry_t find;
336
337 if (!vp) return UNLANG_ACTION_FAIL;
338
339 find.cdp_url = &vp->data;
340 fr_rb_find((void **)&rctx->crl_entry, &inst->mutable->crls, &find);
341 if (rctx->crl_entry) rctx->refresh = true;
342
343 return fetch_setup_common(p_result, mctx, request, vp, rctx);
344}
345
346/** Tidy up CRL entries when freeing.
347 */
348static int _crl_entry_free(crl_entry_t *to_free)
349{
350 if (to_free->crl_num) ASN1_INTEGER_free(to_free->crl_num);
351
352 /*
353 * Ensure the entry is no-longer in the tree.
354 */
355 if (fr_rb_node_inline_in_tree(&to_free->node)) fr_rb_remove(NULL, &to_free->inst->mutable->crls, to_free);
356
357 /*
358 * If the entry referenced deltas, those must be removed as well.
359 */
360 if ((to_free->type == CRL_TYPE_BASE) && fr_value_box_list_initialised(&to_free->delta_urls)) {
361 fr_value_box_list_foreach(&to_free->delta_urls, delta) {
362 crl_entry_t find, *delta_crl;
363
364 find.cdp_url = delta;
365 fr_rb_find((void **)&delta_crl, &to_free->inst->mutable->crls, &find);
366 if (!delta_crl) continue;
367
368 fr_rb_remove(NULL, &to_free->inst->mutable->crls, delta_crl);
369 talloc_free(delta_crl);
370 }
371 }
372
373 return 0;
374}
375
376/** Event callback to trigger the refresh of a CRL
377 */
378static void crl_refresh_event(fr_timer_list_t *tl, fr_time_t now, void *uctx)
379{
380 crl_entry_t *crl_entry = talloc_get_type_abort(uctx, crl_entry_t);
381 fr_pair_list_t list;
382 fr_pair_t *vp;
383 TALLOC_CTX *local = talloc_new(NULL);
384
385 DEBUG2("Refreshing CRL from CDP %pV", crl_entry->cdp_url);
386
387 fr_pair_list_init(&list);
389 if (!vp) {
390 fail:
391 talloc_free(local);
392 return;
393 }
394
395 if (fr_pair_append_by_da(local, &vp, &list, attr_crl_cdp_url) < 0) goto fail;
396 if (fr_value_box_copy(vp, &vp->data, crl_entry->cdp_url) < 0) goto fail;
397
398 if (crl_entry->type == CRL_TYPE_DELTA) {
399 if (fr_pair_append_by_da(local, &vp, &list, attr_base_crl) < 0) goto fail;
400 if (fr_value_box_copy(vp, &vp->data, crl_entry->base_url) < 0) goto fail;
401 }
402
403 if (fr_coord_pair_coord_request_start(crl_entry->coord_pair, &list, now) < 0) {
404 ERROR("Failed to initialise CRL refresh request");
405 if (fr_timer_in(crl_entry, tl, &crl_entry->ev, crl_entry->inst->retry_delay, false,
406 crl_refresh_event, crl_entry) <0) {
407 ERROR("Failed to set timer to retry CRL refresh");
408 }
409 }
410
411 talloc_free(local);
412}
413
414static inline void crl_fetching_entry_remove(fr_dlist_head_t *fetching, fr_value_box_t const *cdp_url) {
415 fr_dlist_foreach(fetching, crl_fetch_t, fetch) {
416 if (fr_value_box_cmp(fetch->cdp_url, cdp_url) == 0) {
417 fr_dlist_remove(fetching, fetch);
418 talloc_free(fetch);
419 return;
420 }
421 }
422}
423
424RESUME(crl_fetch)
425{
426 process_crl_t *inst = talloc_get_type_abort(mctx->mi->data, process_crl_t);
427 process_thread_crl_t *thread = talloc_get_type_abort(mctx->thread, process_thread_crl_t);
428 process_crl_rctx_t *rctx = talloc_get_type_abort(mctx->rctx, process_crl_rctx_t);
429 crl_entry_t *crl_entry = NULL;
430 fr_pair_t *crl_data;
431 uint8_t const *data;
432 X509_CRL *crl;
433 X509_STORE_CTX *verify_ctx = NULL;
434 X509_OBJECT *xobj;
435 EVP_PKEY *pkey;
436 STACK_OF(DIST_POINT) *dps;
437 int i;
438 fr_time_t now = fr_time();
439 fr_time_delta_t refresh_delta;
440
441 switch (RESULT_RCODE) {
443 return CALL_RESUME(recv_generic);
444 default:
445 break;
446 }
447
448 /*
449 * If no CRL data was returned, that's a failure
450 */
451 crl_data = fr_pair_find_by_da(&request->reply_pairs, NULL, attr_crl_data);
452 if (!crl_data) {
453 RERROR("No %s found", attr_crl_data->name);
454 return CALL_SEND_TYPE(FR_CRL_FETCH_FAIL);
455 }
456 fr_pair_immutable(crl_data);
457
458 /*
459 * Parse the CRL data and verify it is correctly signed
460 */
461 data = crl_data->vp_octets;
462 crl = d2i_X509_CRL(NULL, (const unsigned char **)&data, crl_data->vp_size);
463 if (!crl) {
464 fr_tls_strerror_printf("Failed to parse CRL from %pV", rctx->cdp_url);
465 return CALL_SEND_TYPE(FR_CRL_FETCH_FAIL);
466 }
467
468 verify_ctx = X509_STORE_CTX_new();
469 if (!verify_ctx || !X509_STORE_CTX_init(verify_ctx, inst->verify_store, NULL, NULL)) {
470 fr_tls_strerror_printf("Error initialising X509 store");
471 error:
472 if (verify_ctx) X509_STORE_CTX_free(verify_ctx);
473 RPERROR("Error verifying CRL");
474 X509_CRL_free(crl);
475 talloc_free(crl_entry);
476 return CALL_SEND_TYPE(FR_CRL_FETCH_FAIL);
477 }
478
479 xobj = X509_STORE_CTX_get_obj_by_subject(verify_ctx, X509_LU_X509, X509_CRL_get_issuer(crl));
480 if (!xobj) {
481 fr_tls_strerror_printf("CRL issuer certificate not in trusted store");
482 goto error;
483 }
484 pkey = X509_get_pubkey(X509_OBJECT_get0_X509(xobj));
485 X509_OBJECT_free(xobj);
486 if (!pkey) {
487 fr_tls_strerror_printf("Error getting CRL issuer public key");
488 goto error;
489 }
490 i = X509_CRL_verify(crl, pkey);
491 EVP_PKEY_free(pkey);
492
493 if (i < 0) {
494 fr_tls_strerror_printf("Could not verify CRL signature");
495 goto error;
496 }
497 if (i == 0) {
498 fr_tls_strerror_printf("CRL certificate signature failed");
499 goto error;
500 }
501
502 /*
503 * Now we have a verified CRL, start building the entry for the global list
504 */
505 MEM(crl_entry = talloc_zero(inst->mutable, crl_entry_t));
506 crl_entry->inst = inst;
507
508 /*
509 * If we're passed a base_crl, then this is a delta.
510 */
511 crl_entry->type = rctx->base_crl ? CRL_TYPE_DELTA : CRL_TYPE_BASE;
512 talloc_set_destructor(crl_entry, _crl_entry_free);
513
514 if (fr_tls_utils_asn1time_to_epoch(&crl_entry->next_update, X509_CRL_get0_nextUpdate(crl)) < 0) {
515 RPERROR("Failed to parse nextUpdate from CRL");
516 goto error;
517 }
518
519 if (!inst->allow_expired && fr_time_lt(fr_time_from_sec(crl_entry->next_update),
520 fr_time_from_sec(time(NULL)))) {
521 RPERROR("Fetched CRL expired at %pV", fr_box_time(fr_time_from_sec(crl_entry->next_update)));
522 goto error;
523 }
524
525 crl_entry->crl_num = X509_CRL_get_ext_d2i(crl, NID_crl_number, &i, NULL);
526 if (!crl_entry->crl_num) {
527 fr_tls_strerror_printf("Missing CRL number");
528 goto error;
529 }
530
531 /*
532 * If there is existing data for this CRL, the it should only be updated if the number has increased.
533 */
534 if (rctx->crl_entry) {
535 if (ASN1_INTEGER_cmp(crl_entry->crl_num, rctx->crl_entry->crl_num) == 0) {
536 uint64_t new_num;
537 ASN1_INTEGER_get_uint64(&new_num, crl_entry->crl_num);
538 RDEBUG3("Refresh returned the same CRL number (%"PRIu64") as the existing entry", new_num);
539 goto use_old;
540 }
541 if (ASN1_INTEGER_cmp(crl_entry->crl_num, rctx->crl_entry->crl_num) < 0) {
542 uint64_t old_num, new_num;
543 ASN1_INTEGER_get_uint64(&old_num, rctx->crl_entry->crl_num);
544 ASN1_INTEGER_get_uint64(&new_num, crl_entry->crl_num);
545 RERROR("Got CRL number %"PRIu64" which is less than current number %"PRIu64,
546 new_num, old_num);
547 use_old:
548 crl_fetching_entry_remove(&inst->mutable->fetching, rctx->cdp_url);
549 talloc_free(crl_entry);
550 crl_entry = rctx->crl_entry;
551
552 if (rctx->refresh) {
553 /*
554 * A refresh which didn't produce updated data means noop.
555 */
556 rctx->result.rcode = RLM_MODULE_NOOP;
557 } else {
558 /*
559 * CRL-Fetch requests expect a response.
560 */
561 if (crl_build_reply(request, crl_entry) < 0) goto error;
562 }
563 goto timer;
564 }
565
566 /*
567 * The fetched entry data is newer, free the old entry.
568 * This will also remove it from the tree and clear any
569 * related deltas.
570 */
571 TALLOC_FREE(rctx->crl_entry);
572 }
573
574 /*
575 * The fetched CRL is now validated and newer than the old
576 * entry, complete building the entry.
577 */
578 MEM(crl_entry->cdp_url = fr_value_box_acopy(crl_entry, rctx->cdp_url));
579 crl_entry->crl_data = talloc_typed_memdup(crl_entry, crl_data->vp_octets, crl_data->vp_length);
580 crl_entry->coord_pair = fr_coord_pair_request_coord_pair(request);
581
582 /*
583 * If this is a delta check it relates to the correct base.
584 */
585 if (crl_entry->type == CRL_TYPE_DELTA) {
586 ASN1_INTEGER *base_num = X509_CRL_get_ext_d2i(crl, NID_delta_crl, &i, NULL);
587
588#ifdef __clang_analyzer__
589 /*
590 * type is set to CRL_TYPE_DELTA by the presence of a base_crl
591 * but the analysers don't detect this.
592 */
593 if (unlikely(!rctx->base_crl)) goto error;
594#endif
595 fr_assert(rctx->base_crl);
596 if (!base_num) {
597 RERROR("Delta CRL missing Delta CRL Indicator extension");
598 goto error;
599 }
600 if (ASN1_INTEGER_cmp(base_num, rctx->base_crl->crl_num) > 0) {
601 uint64_t delta_base, crl_num;
602 ASN1_INTEGER_get_uint64(&delta_base, base_num);
603 ASN1_INTEGER_get_uint64(&crl_num, rctx->base_crl->crl_num);
604 RERROR("Delta CRL referrs to base CRL number %"PRIu64", current base is %"PRIu64,
605 delta_base, crl_num);
606 ASN1_INTEGER_free(base_num);
607 goto error;
608 }
609 ASN1_INTEGER_free(base_num);
610 if (ASN1_INTEGER_cmp(crl_entry->crl_num, rctx->base_crl->crl_num) < 0) {
611 uint64_t delta_num, crl_num;
612 ASN1_INTEGER_get_uint64(&delta_num, crl_entry->crl_num);
613 ASN1_INTEGER_get_uint64(&crl_num, rctx->base_crl->crl_num);
614 RERROR("Delta CRL number %"PRIu64" is less than base CRL number %"PRIu64, delta_num, crl_num);
615 goto error;
616 }
617 MEM(crl_entry->base_url = fr_value_box_acopy(crl_entry, rctx->base_crl->cdp_url));
618 }
619
620 if (fr_tls_utils_asn1time_to_epoch(&crl_entry->last_update, X509_CRL_get0_lastUpdate(crl)) < 0) {
621 RPERROR("Failed to parse lastUpdate from CRL");
622 goto error;
623 }
624
625 if (!inst->allow_not_yet_valid && fr_time_gt(fr_time_from_sec(crl_entry->last_update),
626 fr_time_from_sec(time(NULL)))) {
627 RPERROR("Fetched CRL is not valid until %pV", fr_box_time(fr_time_from_sec(crl_entry->last_update)));
628 goto error;
629 }
630
631 /*
632 * Check if this CRL has a Freshest CRL extension - the list of URIs to get deltas from
633 */
634 if ((crl_entry->type == CRL_TYPE_BASE) && (dps = X509_CRL_get_ext_d2i(crl, NID_freshest_crl, NULL, NULL))) {
635 DIST_POINT *dp;
636 STACK_OF(GENERAL_NAME) *names;
637 GENERAL_NAME *name;
638 int j;
639 fr_value_box_t *vb;
640
641 fr_value_box_list_init(&crl_entry->delta_urls);
642DIAG_OFF_OPTIONAL(used-but-marked-unused) /* fix spurious warnings for sk macros */
643 for (i = 0; i < sk_DIST_POINT_num(dps); i++) {
644 dp = sk_DIST_POINT_value(dps, i);
645 names = dp->distpoint->name.fullname;
646 for (j = 0; j < sk_GENERAL_NAME_num(names); j++) {
647 name = sk_GENERAL_NAME_value(names, j);
648 if (name->type != GEN_URI) continue;
649 MEM(vb = fr_value_box_alloc_null(crl_entry));
650 fr_value_box_bstrndup(vb, vb, NULL,
651 (char const *)ASN1_STRING_get0_data(name->d.uniformResourceIdentifier),
652 fr_tls_asn1_string_length(name->d.uniformResourceIdentifier), true);
653 RDEBUG3("CRL references delta URI %pV", vb);
654 fr_value_box_list_insert_tail(&crl_entry->delta_urls, vb);
655 }
656 }
657DIAG_ON_OPTIONAL(used-but-marked-unused)
658 CRL_DIST_POINTS_free(dps);
659
660 /*
661 * If the CRL has a delta then fetch it. An updated CRL means the
662 * delta must be updated or it's invalid as it will point to the wrong
663 * version of the base CRL.
664 */
665 if (fr_value_box_list_num_elements(&crl_entry->delta_urls) > 0) {
666 fr_pair_list_t list;
667 fr_pair_t *vp;
668 TALLOC_CTX *local = talloc_new(NULL);
669
670 fr_pair_list_init(&list);
672 if (!vp) goto free_local;
673
674 fr_value_box_list_foreach(&crl_entry->delta_urls, delta) {
675 if (fr_pair_append_by_da(local, &vp, &list, attr_crl_cdp_url) < 0) goto free_local;
676 if (unlikely(fr_value_box_copy(vp, &vp->data, delta) < 0)) goto free_local;
677 }
678
679 if (fr_pair_append_by_da(local, &vp, &list, attr_base_crl) < 0) goto free_local;
680 if (unlikely(fr_value_box_copy(vp, &vp->data, rctx->cdp_url) < 0)) goto free_local;
681
682 if (fr_coord_pair_coord_request_start(crl_entry->coord_pair, &list, now) < 0) {
683 RERROR("Failed to start fetch of delta CRL");
684 }
685
686 free_local:
687 talloc_free(local);
688 }
689 }
690
691 if (fr_rb_insert(&inst->mutable->crls, crl_entry) != 0) {
692 RERROR("Failed storing CRL");
693 goto error;
694 }
695
696 if (crl_build_reply(request, crl_entry) < 0) goto error;
697
698timer:
699 /*
700 * Setup a timer to refresh the CRL
701 */
702 crl_entry->refresh = fr_time_from_sec(crl_entry->next_update);
703 refresh_delta = fr_time_delta_sub(fr_time_sub(crl_entry->refresh, now), inst->early_refresh);
704 if (rctx->base_crl && inst->force_delta_refresh_is_set) {
705 if (fr_time_delta_cmp(refresh_delta, inst->force_delta_refresh)) refresh_delta = inst->force_delta_refresh;
706 } else {
707 if (inst->force_refresh_is_set &&
708 (fr_time_delta_cmp(refresh_delta, inst->force_refresh) > 0)) refresh_delta = inst->force_refresh;
709 }
710
711 /*
712 * A negative expiry time will occur if a refresh fails to fetch a newer CRL
713 * or the CRL has already expired. In that case use retry_delay to rate limit retrys.
714 */
715 if (fr_time_delta_isneg(refresh_delta)) refresh_delta = inst->retry_delay;
716
717 RDEBUG2("CRL from %pV will refresh in %pVs", rctx->cdp_url, fr_box_time_delta(refresh_delta));
718
719 if (fr_timer_in(crl_entry, thread->el->tl, &crl_entry->ev, refresh_delta, false, crl_refresh_event, crl_entry) <0) {
720 RERROR("Failed to set timer to refresh CRL");
721 }
722
723 X509_STORE_CTX_free(verify_ctx);
724 X509_CRL_free(crl);
725
726 return CALL_RESUME(recv_generic);
727}
728
729RESUME_FLAG(send_crl_ok, UNUSED,)
730{
731 process_crl_t *inst = talloc_get_type_abort(mctx->mi->data, process_crl_t);
732 process_crl_rctx_t *rctx = talloc_get_type_abort(mctx->rctx, process_crl_rctx_t);
733
734 /*
735 * Remove the fetching entry. We use broadcast for the reply after
736 * a fetch so no need to individually send to workers.
737 */
738 crl_fetching_entry_remove(&inst->mutable->fetching, rctx->cdp_url);
739
740 if (rctx->cached) {
741 /*
742 * Cached replies are only sent to the worker which requested the data.
743 */
744 RDEBUG3("Sending cached CRL to worker %d", rctx->worker_id);
745 fr_coord_to_worker_reply_send(request, rctx->worker_id);
746 } else {
747 /*
748 * Successful update of a CRL is broadcast to all clients.
749 */
750 RDEBUG3("Sending updated CRL to all workers");
752 }
753
755}
756
757RESUME(send_crl_fail)
758{
759 process_crl_t *inst = talloc_get_type_abort(mctx->mi->data, process_crl_t);
760 process_thread_crl_t *thread = talloc_get_type_abort(mctx->thread, process_thread_crl_t);
761 process_crl_rctx_t *rctx = talloc_get_type_abort(mctx->rctx, process_crl_rctx_t);
762 fr_pair_t *vp;
763
764 if (rctx->refresh) {
765 crl_fetching_entry_remove(&inst->mutable->fetching, rctx->cdp_url);
766
767 /*
768 * Set up retry of failed refresh.
769 */
770 RDEBUG2("Refresh of CRL from %pV will retry in %pVs", rctx->cdp_url, fr_box_time_delta(inst->retry_delay));
771
772 if (fr_timer_in(rctx->crl_entry, thread->el->tl, &rctx->crl_entry->ev, inst->retry_delay,
773 false, crl_refresh_event, rctx->crl_entry) <0) {
774 RERROR("Failed to set timer to retry CRL fetch");
775 }
776
777 /*
778 * Refresh requests are local to the coordinator, so there
779 * is nothing to send back on a failure, unless the CRL has
780 * expired and expired CRLs are not allowed.
781 */
782 if (inst->allow_expired || fr_time_gt(fr_time_from_sec(rctx->crl_entry->next_update),
783 fr_time_from_sec(time(NULL)))) {
785 }
786
787 /*
788 * A refresh failed on an expired CRL, notify all workers with a CRL-Expire reply.
789 */
790 fr_pair_list_free(&request->reply_pairs);
791 if (fr_pair_append_by_da(request->reply_ctx, &vp, &request->reply_pairs,
793 vp->vp_uint32 = FR_CRL_CRL_EXPIRE;
794
795 if (fr_pair_append_by_da(request->reply_ctx, &vp, &request->reply_pairs,
797 if (unlikely(fr_value_box_copy(vp, &vp->data, rctx->cdp_url) < 0)) RETURN_UNLANG_FAIL;
798
800
802 }
803
804 /*
805 * The fetch failed, ensure we don't send CRL data back
806 */
808
810 if (unlikely(fr_value_box_copy(vp, &vp->data, rctx->cdp_url) < 0)) RETURN_UNLANG_FAIL;
811
812 RDEBUG3("Sending fail to worker %d", rctx->worker_id);
813 fr_coord_to_worker_reply_send(request, rctx->worker_id);
814
815 /*
816 * If any other workers were waiting for this CRL, send them
817 * the failure as well.
818 */
819 fr_dlist_foreach(&inst->mutable->fetching, crl_fetch_t, fetch) {
820 if (fr_value_box_cmp(fetch->cdp_url, rctx->cdp_url) == 0) {
821 uint32_t i;
822 fr_dlist_remove(&inst->mutable->fetching, fetch);
823 for (i = 0; i < main_config->max_workers; i++) {
824 if (fetch->workers[i]) {
826 RDEBUG3("Sending fail to worker %" PRIu32, i);
827 }
828 }
829 talloc_free(fetch);
830 break;
831 }
832 }
833
835}
836
838{
839 fr_process_state_t const *state;
840
842
843 (void)talloc_get_type_abort_const(mctx->mi->data, process_crl_t);
844 fr_assert(FR_CRL_PACKET_CODE_VALID(request->packet->code));
845
846 request->component = "crl";
847 request->module = NULL;
848 fr_assert(request->proto_dict == dict_crl);
849
850 UPDATE_STATE(packet);
851
852 if (!state->recv) {
853 REDEBUG("Invalid packet type (%u)", request->packet->code);
855 }
856
857 log_request_pair_list(L_DBG_LVL_1, request, NULL, &request->request_pairs, NULL);
858
859 return state->recv(p_result, mctx, request);
860}
861
862static int mod_instantiate(module_inst_ctx_t const *mctx)
863{
864 process_crl_t *inst = talloc_get_type_abort(mctx->mi->data, process_crl_t);
865
866 MEM(inst->mutable = talloc_zero(NULL, process_crl_mutable_t));
867
868 fr_rb_inline_init(&inst->mutable->crls, crl_entry_t, node, crl_cmp, NULL);
869 fr_dlist_init(&inst->mutable->fetching, crl_fetch_t, entry);
870
871 inst->verify_store = X509_STORE_new();
872 if (!X509_STORE_load_locations(inst->verify_store, inst->ca_file, inst->ca_path)) {
873 cf_log_err(mctx->mi->conf, "Failed reading Trusted root CA file \"%s\" and path \"%s\"",
874 inst->ca_file, inst->ca_path);
875 return -1;
876 }
877
878 X509_STORE_set_purpose(inst->verify_store, X509_PURPOSE_SSL_CLIENT);
879
880 return 0;
881}
882
883static int mod_detach(module_detach_ctx_t const *mctx)
884{
885 process_crl_t *inst = talloc_get_type_abort(mctx->mi->data, process_crl_t);
886
887 if (inst->verify_store) X509_STORE_free(inst->verify_store);
888 talloc_free(inst->mutable);
889
890 return 0;
891}
892
894{
895 process_thread_crl_t *t = talloc_get_type_abort(mctx->thread, process_thread_crl_t);
896
897 t->el = mctx->el;
898 return 0;
899}
900
901static fr_process_state_t const process_state[] = {
902 /*
903 * Fetch a CRL
904 */
905 [ FR_CRL_CRL_FETCH ] = {
906 .packet_type = {
916 },
917 .default_rcode = RLM_MODULE_NOOP,
918 .recv = recv_crl_fetch,
919 .resume = resume_crl_fetch,
920 .section_offset = offsetof(process_crl_sections_t, crl_fetch),
921 },
922 [ FR_CRL_CRL_REFRESH ] = {
923 .packet_type = {
933 },
934 .default_rcode = RLM_MODULE_NOOP,
935 .recv = recv_crl_refresh,
936 .resume = resume_crl_fetch,
937 .section_offset = offsetof(process_crl_sections_t, crl_fetch),
938 },
939 [ FR_CRL_FETCH_OK ] = {
940 .packet_type = {
946 },
947 .default_rcode = RLM_MODULE_NOOP,
948 .result_rcode = RLM_MODULE_OK,
949 .send = send_generic,
950 .resume = resume_send_crl_ok,
951 .section_offset = offsetof(process_crl_sections_t, fetch_ok),
952 },
953 [ FR_CRL_FETCH_FAIL ] = {
954 .packet_type = {
960 },
961 .default_rcode = RLM_MODULE_NOOP,
962 .result_rcode = RLM_MODULE_REJECT,
963 .send = send_generic,
964 .resume = resume_send_crl_fail,
965 .section_offset = offsetof(process_crl_sections_t, fetch_fail),
966 },
968 .packet_type = {
973
980 },
981 .default_rcode = RLM_MODULE_NOOP,
982 .result_rcode = RLM_MODULE_HANDLED,
983 .send = send_generic,
984 .resume = resume_send_generic,
985 .section_offset = offsetof(process_crl_sections_t, do_not_respond),
986 }
987};
988
990 {
991 .section = SECTION_NAME("recv", "CRL-Fetch"),
992 .actions = &mod_actions_authenticate,
993 .offset = PROCESS_CONF_OFFSET(crl_fetch),
994 },
995 {
996 .section = SECTION_NAME("send", "Fetch-OK"),
998 .offset = PROCESS_CONF_OFFSET(fetch_ok),
999 },
1000 {
1001 .section = SECTION_NAME("send", "Fetch-Fail"),
1003 .offset = PROCESS_CONF_OFFSET(fetch_fail),
1004 },
1005 {
1006 .section = SECTION_NAME("send", "Do-Not-Respond"),
1008 .offset = PROCESS_CONF_OFFSET(do_not_respond),
1009 },
1010
1012};
1013
1014extern fr_process_module_t process_crl;
1015fr_process_module_t process_crl = {
1016 .common = {
1017 .magic = MODULE_MAGIC_INIT,
1018 .name = "crl",
1019 .config = config,
1020 MODULE_INST(process_crl_t),
1021 MODULE_RCTX(process_crl_rctx_t),
1022 .instantiate = mod_instantiate,
1023 .detach = mod_detach,
1024 MODULE_THREAD_INST(process_thread_crl_t),
1025 .thread_instantiate = mod_thread_instantiate
1026 },
1027 .process = mod_process,
1028 .compile_list = compile_list,
1029 .dict = &dict_crl,
1030 .packet_type = &attr_packet_type
1031};
1032#endif
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
Definition action.h:35
@ UNLANG_ACTION_FAIL
Encountered an unexpected error.
Definition action.h:36
@ UNLANG_ACTION_CALCULATE_RESULT
Calculate a new section rlm_rcode_t value.
Definition action.h:38
static uint8_t request[4]
#define DIAG_OFF_OPTIONAL(_x)
Definition build.h:577
#define unlikely(_x)
Definition build.h:486
#define UNUSED
Definition build.h:415
#define DIAG_ON_OPTIONAL(_x)
Definition build.h:578
fr_cmp_ret_t
Result of an ordering comparison.
Definition build.h:113
#define CONF_PARSER_TERMINATOR
Definition cf_parse.h:722
#define FR_CONF_OFFSET(_name, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
Definition cf_parse.h:280
#define FR_CONF_OFFSET_IS_SET(_name, _type, _flags, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct,...
Definition cf_parse.h:294
Defines a CONF_PAIR to C data type mapping.
Definition cf_parse.h:649
A section grouping multiple CONF_PAIR.
Definition cf_priv.h:106
#define cf_log_err(_cf, _fmt,...)
Definition cf_util.h:340
int fr_coord_to_worker_reply_broadcast(request_t *request)
Send a reply list from a coordinator to all workers.
Definition coord_pair.c:792
int fr_coord_to_worker_reply_send(request_t *request, uint32_t worker_id)
Send a reply list from a coordinator to a worker.
Definition coord_pair.c:764
fr_coord_pair_t * fr_coord_pair_request_coord_pair(request_t *request)
Return the coord_pair associated with a coord_pair internal request.
Definition coord_pair.c:883
int fr_coord_pair_coord_request_start(fr_coord_pair_t *coord_pair, fr_pair_list_t *list, fr_time_t now)
Start a coordinator request to run through a coord_pair process module.
Definition coord_pair.c:898
@ FR_CRL_CRL_REFRESH
Definition crl.h:33
@ FR_CRL_FETCH_OK
Definition crl.h:34
@ FR_CRL_CRL_EXPIRE
Definition crl.h:36
@ FR_CRL_CRL_FETCH
Definition crl.h:32
@ FR_CRL_DO_NOT_RESPOND
Definition crl.h:38
@ FR_CRL_FETCH_FAIL
Definition crl.h:35
#define MEM(x)
Definition debug.h:38
#define ERROR(fmt,...)
Definition dhcpclient.c:40
fr_dict_attr_t const ** out
Where to write a pointer to the resolved fr_dict_attr_t.
Definition dict.h:316
fr_dict_t const ** out
Where to write a pointer to the loaded/resolved fr_dict_t.
Definition dict.h:329
#define DICT_AUTOLOAD_TERMINATOR
Definition dict.h:335
Specifies an attribute which must be present for the module to function.
Definition dict.h:315
Specifies a dictionary which must be loaded/loadable for the module to function.
Definition dict.h:328
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
Definition dl_module.h:63
#define fr_dlist_init(_head, _type, _field)
Initialise the head structure of a doubly linked list.
Definition dlist.h:242
#define fr_dlist_foreach(_list_head, _type, _iter)
Iterate over the contents of a list.
Definition dlist.h:98
static void * fr_dlist_remove(fr_dlist_head_t *list_head, void *ptr)
Remove an item from the list.
Definition dlist.h:620
static int fr_dlist_insert_tail(fr_dlist_head_t *list_head, void *ptr)
Insert an item into the tail of a list.
Definition dlist.h:360
Head of a doubly linked list.
Definition dlist.h:51
Entry in a doubly linked list.
Definition dlist.h:41
talloc_free(hp)
static fr_dict_t const * dict_freeradius
Definition base.c:37
fr_dict_attr_t const * attr_packet_type
Definition base.c:91
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:831
#define RDEBUG3(fmt,...)
Definition log.h:360
#define RERROR(fmt,...)
Definition log.h:315
#define RPERROR(fmt,...)
Definition log.h:319
#define fr_time()
Definition event.c:58
Stores all information relating to an event list.
Definition event.c:375
@ L_DBG_LVL_1
Highest priority debug messages (-x).
Definition log.h:67
main_config_t const * main_config
Main server configuration.
Definition main_config.c:56
uint32_t max_workers
for the scheduler
@ FR_TYPE_TIME_DELTA
A period of time measured in nanoseconds.
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_DATE
Unix time stamp, always has value >2^31.
@ FR_TYPE_UINT32
32 Bit unsigned integer.
@ FR_TYPE_INT32
32 Bit signed integer.
@ FR_TYPE_UINT64
64 Bit unsigned integer.
@ FR_TYPE_OCTETS
Raw octets.
unsigned int uint32_t
unsigned char uint8_t
static size_t used
unlang_mod_actions_t const mod_actions_authenticate
Definition mod_action.c:29
unlang_mod_action_t actions[RLM_MODULE_NUMCODES]
Definition mod_action.h:69
module_instance_t const * mi
Instance of the module being instantiated.
Definition module_ctx.h:42
void * thread
Thread specific instance data.
Definition module_ctx.h:43
void * rctx
Resume ctx that a module previously set.
Definition module_ctx.h:45
fr_event_list_t * el
Event list to register any IO handlers and timers against.
Definition module_ctx.h:68
module_instance_t * mi
Module instance to detach.
Definition module_ctx.h:57
void * thread
Thread instance data.
Definition module_ctx.h:67
module_instance_t * mi
Instance of the module being instantiated.
Definition module_ctx.h:51
Temporary structure to hold arguments for module calls.
Definition module_ctx.h:41
Temporary structure to hold arguments for detach calls.
Definition module_ctx.h:56
Temporary structure to hold arguments for instantiation calls.
Definition module_ctx.h:50
Temporary structure to hold arguments for thread_instantiation calls.
Definition module_ctx.h:63
int fr_pair_append_by_da(TALLOC_CTX *ctx, fr_pair_t **out, fr_pair_list_t *list, fr_dict_attr_t const *da)
Alloc a new fr_pair_t (and append)
Definition pair.c:1425
fr_pair_t * fr_pair_find_by_da(fr_pair_list_t const *list, fr_pair_t const *prev, fr_dict_attr_t const *da)
Find the first pair with a matching da.
Definition pair.c:716
int fr_pair_delete_by_da(fr_pair_list_t *list, fr_dict_attr_t const *da)
Delete matching pairs from the specified list.
Definition pair.c:1650
void fr_pair_list_init(fr_pair_list_t *list)
Initialise a pair list header.
Definition pair.c:47
bool fr_pair_immutable(fr_pair_t const *vp)
Definition pair.c:2265
static unlang_action_t mod_process(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
Definition base.c:170
static const virtual_server_compile_t compile_list[]
Definition base.c:194
static fr_process_state_t const process_state[]
Definition base.c:70
RECV(for_any_server)
Validate a solicit/rebind/confirm message.
Definition base.c:348
static int mod_instantiate(module_inst_ctx_t const *mctx)
Definition base.c:214
RESUME_FLAG(access_accept, UNUSED,)
Definition base.c:475
static const conf_parser_t config[]
Definition base.c:162
static fr_dict_attr_t const * attr_worker_id
Definition base.c:45
#define PROCESS_TRACE
Trace each state function as it's entered.
Definition process.h:55
#define PROCESS_CONF_OFFSET(_x)
Definition process.h:79
module_t common
Common fields for all loadable modules.
Common public symbol definition for all process modules.
#define fr_assert(_expr)
Definition rad_assert.h:37
#define REDEBUG(fmt,...)
#define RDEBUG2(fmt,...)
#define DEBUG2(fmt,...)
static fr_schedule_worker_t workers[MAX_WORKERS]
int fr_rb_remove(void **removed, fr_rb_tree_t *tree, void const *data)
Remove an entry from the tree, without freeing the data.
Definition rb.c:718
int fr_rb_find(void **found, fr_rb_tree_t const *tree, void const *data)
Find an element in the tree, returning the data, not the node.
Definition rb.c:586
int fr_rb_insert(fr_rb_tree_t *tree, void const *data)
Insert data into a tree.
Definition rb.c:637
static bool fr_rb_node_inline_in_tree(fr_rb_node_t const *node)
Check to see if an item is in a tree by examining its inline fr_rb_node_t.
Definition rb.h:312
#define fr_rb_inline_init(_tree, _type, _field, _data_cmp, _data_free)
Initialises a red black tree.
Definition rb.h:178
The main red black tree structure.
Definition rb.h:71
@ RLM_MODULE_INVALID
The module considers the request invalid.
Definition rcode.h:51
@ RLM_MODULE_OK
The module is OK, continue.
Definition rcode.h:49
@ RLM_MODULE_FAIL
Module failed, don't reply.
Definition rcode.h:48
@ RLM_MODULE_DISALLOW
Reject the request (user is locked out).
Definition rcode.h:52
@ RLM_MODULE_REJECT
Immediately reject the request.
Definition rcode.h:47
@ RLM_MODULE_TIMEOUT
Module (or section) timed out.
Definition rcode.h:56
@ RLM_MODULE_NOTFOUND
User not found.
Definition rcode.h:53
@ RLM_MODULE_UPDATED
OK (pairs modified).
Definition rcode.h:55
@ RLM_MODULE_NOOP
Module succeeded without doing anything.
Definition rcode.h:54
@ RLM_MODULE_HANDLED
The module handled the request, so stop.
Definition rcode.h:50
#define RLM_MODULE_USER_SECTION_REJECT
Rcodes that translate to a user configurable section failing overall.
Definition rcode.h:85
#define RETURN_UNLANG_FAIL
Definition rcode.h:69
static int mod_detach(module_detach_ctx_t const *mctx)
Definition rlm_always.c:136
static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx)
static fr_dict_attr_t const * attr_delta_crl
Definition rlm_crl.c:114
fr_value_box_list_t delta_urls
URLs from which a delta CRL can be retrieved.
Definition rlm_crl.c:59
static fr_dict_attr_t const * attr_base_crl
Definition rlm_crl.c:113
fr_rb_node_t node
The node in the tree.
Definition rlm_crl.c:58
static fr_dict_attr_t const * attr_crl_cdp_url
Definition rlm_crl.c:112
fr_value_box_t const * cdp_url
The URL of the CRL.
Definition rlm_crl.c:57
static fr_dict_t const * dict_crl
Definition rlm_crl.c:103
static fr_dict_attr_t const * attr_crl_data
Definition rlm_crl.c:111
A single CRL in the thread specific list of CRLs.
Definition rlm_crl.c:55
static char const * name
static _Thread_local int worker_id
Internal ID of the current worker thread.
Definition schedule.c:105
#define SECTION_NAME(_name1, _name2)
Define a section name consisting of a verb and a noun.
Definition section.h:39
#define MODULE_THREAD_INST(_ctype)
Definition module.h:261
CONF_SECTION * conf
Module's instance configuration.
Definition module.h:355
void * data
Module's instance data.
Definition module.h:297
#define MODULE_RCTX(_ctype)
Definition module.h:262
#define MODULE_INST(_ctype)
Definition module.h:260
conf_parser_t const * config
How to convert a CONF_SECTION to a module instance.
Definition module.h:207
#define pair_update_reply(_attr, _da)
Return or allocate a fr_pair_t in the reply list.
Definition pair.h:129
eap_aka_sim_process_conf_t * inst
#define RESUME(_x)
fr_aka_sim_id_type_t type
fr_pair_t * vp
Stores an attribute, a value and various bits of other data.
Definition pair.h:68
uint8_t * talloc_typed_memdup(TALLOC_CTX *ctx, uint8_t const *in, size_t inlen)
Call talloc_memdup, setting the type on the new chunk correctly.
Definition talloc.c:521
#define talloc_get_type_abort_const
Definition talloc.h:117
static const char * names[8]
Definition time.c:618
#define fr_time_delta_isneg(_a)
Definition time.h:291
static fr_unix_time_t fr_unix_time_from_sec(int64_t sec)
Definition time.h:449
static fr_time_t fr_time_from_sec(time_t when)
Convert a time_t (wallclock time) to a fr_time_t (internal time)
Definition time.h:876
static fr_cmp_ret_t fr_time_delta_cmp(fr_time_delta_t a, fr_time_delta_t b)
Compare two fr_time_delta_t values.
Definition time.h:948
#define fr_time_gt(_a, _b)
Definition time.h:237
static fr_time_delta_t fr_time_delta_sub(fr_time_delta_t a, fr_time_delta_t b)
Definition time.h:261
#define fr_time_sub(_a, _b)
Subtract one time from another.
Definition time.h:229
#define fr_time_lt(_a, _b)
Definition time.h:239
A time delta, a difference in time measured in nanoseconds.
Definition time.h:80
"server local" time.
Definition time.h:69
An event timer list.
Definition timer.c:65
A timer event.
Definition timer.c:100
#define fr_timer_in(...)
Definition timer.h:87
static fr_event_list_t * el
fr_pair_t * fr_pair_remove(fr_pair_list_t *list, fr_pair_t *vp)
Remove fr_pair_t from a list without freeing.
Definition pair_inline.c:93
void fr_pair_list_free(fr_pair_list_t *list)
Free memory used by a valuepair list.
#define fr_pair_list_append_by_da(_ctx, _vp, _list, _attr, _val, _tainted)
Append a pair to a list, assigning its value.
Definition pair.h:310
static void fr_pair_set_immutable(fr_pair_t *vp)
Definition pair.h:712
int fr_tls_utils_asn1time_to_epoch(time_t *out, ASN1_TIME const *asn1)
Convert OpenSSL's ASN1_TIME to an epoch time.
Definition utils.c:128
fr_cmp_ret_t fr_value_box_cmp(fr_value_box_t const *a, fr_value_box_t const *b)
Compare two values.
Definition value.c:770
int fr_value_box_memdup_buffer(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, uint8_t const *src, bool tainted)
Copy a talloced buffer to a fr_value_box_t.
Definition value.c:5317
int fr_value_box_copy(TALLOC_CTX *ctx, fr_value_box_t *dst, const fr_value_box_t *src)
Copy value data verbatim duplicating any buffers.
Definition value.c:4526
void fr_value_box_clear_value(fr_value_box_t *data)
Clear/free any existing value.
Definition value.c:4461
int fr_value_box_bstrndup(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, char const *src, size_t len, bool tainted)
Copy a string to to a fr_value_box_t.
Definition value.c:5014
static fr_slen_t data
Definition value.h:1366
static fr_value_box_t * fr_value_box_acopy(TALLOC_CTX *ctx, fr_value_box_t const *src)
Copy an existing box, allocating a new box to hold its contents.
Definition value.h:775
#define fr_box_time_delta(_val)
Definition value.h:397
#define fr_value_box_alloc_null(_ctx)
Allocate a value box for later use with a value assignment function.
Definition value.h:679
#define fr_box_time(_val)
Definition value.h:380
#define fr_value_box_list_foreach(_list_head, _iter)
Definition value.h:253
section_name_t const * section
Identifier for the section.
#define COMPILE_TERMINATOR
Processing sections which are allowed in this virtual server.