The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
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: 82a9602d2fc9518b56ca029bfa12932e9c46609f $
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  * @return
47  * - 0 on success.
48  * - -1 on failure.
49  */
50 unlang_action_t fr_tls_call_push(request_t *child, unlang_function_t resume,
51  fr_tls_conf_t *conf, fr_tls_session_t *tls_session)
52 {
53  fr_assert(tls_session->cache);
54 
55  /*
56  * Sets up a dispatch frame in the parent
57  * and a result processing frame in the child.
58  */
59  if (unlang_subrequest_child_push(NULL, child,
61  .enable = true,
62  .unique_ptr = tls_session
63  },
64  true, UNLANG_SUB_FRAME) < 0) {
65  return UNLANG_ACTION_FAIL;
66  }
67 
68  /*
69  * Setup a function to execute after the
70  * subrequest completes.
71  */
72  if (unlang_function_push(child, NULL, resume,
73  NULL, 0, UNLANG_SUB_FRAME, tls_session) < 0) return UNLANG_ACTION_FAIL;
74 
75  /*
76  * Now the child and parent stacks are both
77  * setup correctly, push a virtual server
78  * call into the subrequest to run the section
79  * specified by Packet-Type.
80  */
81  if (unlang_call_push(child, conf->virtual_server, UNLANG_SUB_FRAME) < 0) {
82  request_detach(child);
83  return UNLANG_ACTION_FAIL;
84  }
85 
87 }
88 #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
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
static rs_t * conf
Definition: radsniff.c:53
int request_detach(request_t *child)
Unlink a subrequest from its parent.
Definition: request.c:668
fr_assert(0)
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.