The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
virtual_server.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: 59daeea4b55e05bc6d8cfe6d06b63d6cbbf35e86 $
19 *
20 * @file tls/virtual_server.c
21 * @brief Calls a section in the TLS policy virtual server.
22 *
23 * @copyright 2021 Arran Cudbard-Bell (a.cudbardb@freeradius.org)
24 */
25#ifdef WITH_TLS
26#define LOG_PREFIX "tls"
27
28#include <freeradius-devel/unlang/interpret.h>
29#include <freeradius-devel/unlang/call.h>
30#include <freeradius-devel/server/virtual_servers.h>
31
32#include "attrs.h"
33#include "base.h"
34#include "cache.h"
35
36/** Push a request to perform a policy action using a virtual server
37 *
38 * This function will setup a TLS subrequest to run a virtual server section.
39 *
40 * @param[out] child to run as a subrequest of the parent.
41 * @param[in] resume Function to call after the virtual server
42 * finishes processing the request. uctx will
43 * be a pointer to the provided tls_session.
44 * @param[in] conf the tls configuration.
45 * @param[in] tls_session The current tls_session.
46 * @param[in] cache_required Does this action require the tls cache
47 * @return
48 * - 0 on success.
49 * - -1 on failure.
50 */
51unlang_action_t fr_tls_call_push(request_t *child, unlang_function_t resume,
52 fr_tls_conf_t *conf, fr_tls_session_t *tls_session,
53#ifdef NDEBUG
54 UNUSED
55#endif
56 bool cache_required)
57{
58 fr_assert(tls_session->cache || !cache_required);
59
60 /*
61 * Sets up a dispatch frame in the parent
62 * and a result processing frame in the child.
63 */
64 if (unlang_subrequest_child_push(NULL, child,
66 .enable = true,
67 .unique_ptr = tls_session
68 },
69 true, UNLANG_SUB_FRAME) < 0) {
70 return UNLANG_ACTION_FAIL;
71 }
72
73 /*
74 * Setup a function to execute after the
75 * subrequest completes.
76 */
77 if (unlang_function_push(child, NULL, resume,
78 NULL, 0, UNLANG_SUB_FRAME, tls_session) < 0) return UNLANG_ACTION_FAIL;
79
80 /*
81 * Now the child and parent stacks are both
82 * setup correctly, push a virtual server
83 * call into the subrequest to run the section
84 * specified by Packet-Type.
85 */
86 if (unlang_call_push(child, conf->virtual_server, UNLANG_SUB_FRAME) < 0) {
87 request_detach(child);
88 return UNLANG_ACTION_FAIL;
89 }
90
92}
93#endif
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
Definition action.h:35
@ UNLANG_ACTION_PUSHED_CHILD
unlang_t pushed a new child onto the stack, execute it instead of continuing.
Definition action.h:39
@ UNLANG_ACTION_FAIL
Encountered an unexpected error.
Definition action.h:36
#define UNUSED
Definition build.h:317
unlang_action_t unlang_call_push(request_t *request, CONF_SECTION *server_cs, bool top_frame)
Push a call frame onto the stack.
Definition call.c:147
unlang_action_t(* unlang_function_t)(rlm_rcode_t *p_result, int *priority, request_t *request, void *uctx)
A generic function pushed by a module or xlat to functions deeper in the C call stack to create resum...
Definition function.h:49
#define unlang_function_push(_request, _func, _repeat, _signal, _sigmask, _top_frame, _uctx)
Push a generic function onto the unlang stack.
Definition function.h:111
#define UNLANG_SUB_FRAME
Definition interpret.h:36
#define fr_assert(_expr)
Definition rad_assert.h:38
static rs_t * conf
Definition radsniff.c:53
int request_detach(request_t *child)
Unlink a subrequest from its parent.
Definition request.c:668
int unlang_subrequest_child_push(rlm_rcode_t *out, request_t *child, unlang_subrequest_session_t const *session, bool free_child, bool top_frame)
Push a pre-existing child back onto the stack as a subrequest.