The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
transaction.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: dc081b90d02db18862a3f053b5fa7df81df76f5e $
19 *
20 * @file unlang/transaction.c
21 * @brief Allows for edit transactions
22 *
23 * @copyright 2023 Network RADIUS SAS (legal@networkradius.com)
24 */
25
26RCSID("$Id: dc081b90d02db18862a3f053b5fa7df81df76f5e $")
27
28#include <freeradius-devel/util/syserror.h>
29#include <freeradius-devel/server/rcode.h>
30#include "transaction.h"
31#include "transaction_priv.h"
32
33/** Signal a transaction to abort.
34 *
35 * @param[in] request The current request.
36 * @param[in] frame being signalled.
37 * @param[in] action to signal.
38 */
40{
41 unlang_frame_state_transaction_t *state = talloc_get_type_abort(frame->state,
43
44 /*
45 * Ignore everything except cancel.
46 */
47 if (action != FR_SIGNAL_CANCEL) return;
48
49 fr_edit_list_abort(state->el);
50 state->el = NULL;
51}
52
53/** Commit a successful transaction.
54 *
55 */
58{
59 unlang_frame_state_transaction_t *state = talloc_get_type_abort(frame->state,
61
62 fr_assert(state->el != NULL);
63
64 /*
65 * p_result contains OUR result, we want the section
66 * result from what was just executed on the stack.
67 */
68 switch (state->result.rcode) {
70 case RLM_MODULE_FAIL:
75 fr_edit_list_abort(state->el);
76 break;
77
78 case RLM_MODULE_OK:
80 case RLM_MODULE_NOOP:
83 fr_edit_list_commit(state->el);
84 break;
85
86 case RLM_MODULE_NUMCODES: /* Do not add default: */
87 fr_assert(0);
88 return UNLANG_ACTION_FAIL;
89 }
90
91 /*
92 * Allow the interpreter to access
93 * the result of the child section
94 */
95 *p_result = state->result;
96
98}
99
113
115{
117 unlang_stack_t *stack = request->stack;
118 int i, depth = stack->depth;
119
120 if (depth == 1) return NULL;
121
122 for (i = depth - 1; i > 0; i--) {
124
125 frame = &stack->frame[i];
126 if (frame->instruction->type != UNLANG_TYPE_TRANSACTION) continue;
127
128 state = talloc_get_type_abort(frame->state, unlang_frame_state_transaction_t);
129 fr_assert(state->el != NULL);
130
131 return state->el;
132 }
133
134 return NULL;
135}
136
138{
140 &(unlang_op_t){
141 .name = "transaction",
142 .interpret = unlang_transaction,
144 .frame_state_size = sizeof(unlang_frame_state_transaction_t),
145 .frame_state_type = "unlang_frame_state_transaction_t",
147 });
148}
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:37
#define RCSID(id)
Definition build.h:485
#define UNUSED
Definition build.h:317
#define MEM(x)
Definition debug.h:36
unlang_action_t unlang_interpret_push_children(unlang_result_t *p_result, request_t *request, rlm_rcode_t default_rcode, bool do_next_sibling)
Push the children of the current frame onto a new frame onto the stack.
Definition interpret.c:389
rlm_rcode_t rcode
The current rcode, from executing the instruction or merging the result from a frame.
Definition interpret.h:134
void unlang_register(int type, unlang_op_t *op)
Register an operation with the interpreter.
Definition base.c:63
static char * stack[MAX_STACK]
Definition radmin.c:159
static uint8_t depth(fr_minmax_heap_index_t i)
Definition minmax_heap.c:83
#define fr_assert(_expr)
Definition rad_assert.h:38
@ 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_TIMEOUT
Module (or section) timed out.
Definition rcode.h:50
@ RLM_MODULE_NOTFOUND
User not found.
Definition rcode.h:47
@ RLM_MODULE_UPDATED
OK (pairs modified).
Definition rcode.h:49
@ RLM_MODULE_NOT_SET
Error resolving rcode (should not be returned by modules).
Definition rcode.h:52
@ RLM_MODULE_NOOP
Module succeeded without doing anything.
Definition rcode.h:48
@ RLM_MODULE_NUMCODES
How many valid return codes there are.
Definition rcode.h:51
@ RLM_MODULE_HANDLED
The module handled the request, so stop.
Definition rcode.h:44
fr_signal_t
Signals that can be generated/processed by request signal handlers.
Definition signal.h:38
@ FR_SIGNAL_CANCEL
Request has been cancelled.
Definition signal.h:40
void unlang_transaction_init(void)
static unlang_action_t unlang_transaction(UNUSED unlang_result_t *p_result, request_t *request, unlang_stack_frame_t *frame)
static unlang_action_t unlang_transaction_final(UNUSED unlang_result_t *p_result, UNUSED request_t *request, unlang_stack_frame_t *frame)
Commit a successful transaction.
Definition transaction.c:56
fr_edit_list_t * unlang_interpret_edit_list(request_t *request)
static void unlang_transaction_signal(UNUSED request_t *request, unlang_stack_frame_t *frame, fr_signal_t action)
Signal a transaction to abort.
Definition transaction.c:39
Declarations for unlang transactions.
Declarations for unlang transactions.
fr_edit_list_t * el
my edit list
A transaction stack entry.
#define UNLANG_NEXT_SIBLING
Definition unlang_priv.h:98
void * state
Stack frame specialisations.
@ UNLANG_TYPE_TRANSACTION
transactions for editing lists
Definition unlang_priv.h:74
static void frame_repeat(unlang_stack_frame_t *frame, unlang_process_t process)
Mark the current stack frame up for repeat, and set a new process function.
unlang_t const * instruction
The unlang node we're evaluating.
@ UNLANG_OP_FLAG_DEBUG_BRACES
Print debug braces.
unlang_type_t type
The specialisation of this node.
An unlang operation.
Our interpreter stack, as distinct from the C stack.
An unlang stack associated with a request.
void fr_edit_list_commit(fr_edit_list_t *el)
Commit an edit list.
Definition edit.c:845
void fr_edit_list_abort(fr_edit_list_t *el)
Abort the entries in an edit list.
Definition edit.c:193
fr_edit_list_t * fr_edit_list_alloc(TALLOC_CTX *ctx, int hint, fr_edit_list_t *parent)
Allocate an edit list.
Definition edit.c:794
Track a series of edits.
Definition edit.c:101
static fr_slen_t parent
Definition pair.h:839