The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
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: 8c2713d23fe3d6ee0d099fc8b4f1d0f4d93a3b0a $
19 * @file src/process/ldap_sync/base.c
20 * @brief LDAP sync process module
21 *
22 * @copyright 2022 NetworkRADIUS SARL (legal@networkradius.com)
23 */
24#define LOG_PREFIX "process_ldap_sync"
25
26#include <freeradius-devel/unlang/interpret.h>
27#include <freeradius-devel/server/protocol.h>
28#include <freeradius-devel/util/debug.h>
29#include <freeradius-devel/ldap/sync.h>
30
32
38
40
47
49 "<INVALID>", //!< 0
50 "Present",
51 "Add",
52 "Modify",
53 "Delete",
54 "Entry-Response",
55 "Cookie-Load",
56 "Cookie-Load-Response",
57 "Cookie-Load-Fail",
58 "Cookie-Store",
59 "Cookie-Store-Response",
60};
61
62static void ldap_sync_packet_debug(request_t *request, fr_packet_t *packet, fr_pair_list_t *list, bool received)
63{
64
65 if (!packet) return;
66 if (!RDEBUG_ENABLED) return;
67
68 log_request(L_DBG, L_DBG_LVL_1, request, __FILE__, __LINE__, "%s %s",
69 received ? "Received" : "Sending",
71 );
72
73 if (received) {
74 log_request_pair_list(L_DBG_LVL_1, request, NULL, list, NULL);
75 } else {
76 /*
77 * At higher debug levels, log returned data as well.
78 */
79 log_request_pair_list(L_DBG_LVL_2, request, NULL, list, NULL);
80 }
81
82}
83
94
98
99#define PROCESS_PACKET_TYPE fr_ldap_sync_packet_code_t
100#define PROCESS_CODE_MAX FR_LDAP_SYNC_CODE_MAX
101#define PROCESS_PACKET_CODE_VALID FR_LDAP_SYNC_PACKET_CODE_VALID
102#define PROCESS_INST process_ldap_sync_t
103#include <freeradius-devel/server/process.h>
104
105
106static unlang_action_t mod_process(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
107{
108 fr_process_state_t const *state;
109
111
113
114 fr_assert(FR_LDAP_SYNC_PACKET_CODE_VALID(request->packet->code));
115
116 request->component = "ldap_sync";
117 request->module = NULL;
118 fr_assert(request->proto_dict == dict_ldap_sync);
119
120 UPDATE_STATE(packet);
121
122 ldap_sync_packet_debug(request, request->packet, &request->request_pairs, true);
123
124 return state->recv(p_result, mctx, request);
125}
126
127static fr_process_state_t const process_state[] = {
129 .default_reply = FR_LDAP_SYNC_CODE_ENTRY_RESPONSE,
130 .default_rcode = RLM_MODULE_NOOP,
131 .recv = recv_generic,
132 .resume = resume_recv_generic,
133 .section_offset = offsetof(process_ldap_sync_sections_t, recv_present),
134 },
136 .default_reply = FR_LDAP_SYNC_CODE_ENTRY_RESPONSE,
137 .default_rcode = RLM_MODULE_NOOP,
138 .recv = recv_generic,
139 .resume = resume_recv_generic,
140 .section_offset = offsetof(process_ldap_sync_sections_t, recv_add)
141 },
143 .default_reply = FR_LDAP_SYNC_CODE_ENTRY_RESPONSE,
144 .default_rcode = RLM_MODULE_NOOP,
145 .recv = recv_generic,
146 .resume = resume_recv_generic,
147 .section_offset = offsetof(process_ldap_sync_sections_t, recv_delete),
148 },
150 .default_reply = FR_LDAP_SYNC_CODE_ENTRY_RESPONSE,
151 .default_rcode = RLM_MODULE_NOOP,
152 .recv = recv_generic,
153 .resume = resume_recv_generic,
154 .section_offset = offsetof(process_ldap_sync_sections_t, recv_modify),
155 },
157 .default_rcode = RLM_MODULE_NOOP,
158 .send = send_generic,
159 .resume = resume_send_generic,
160 },
162 .packet_type = {
168 },
170 .default_rcode = RLM_MODULE_NOOP,
171 .recv = recv_generic,
172 .resume = resume_recv_generic,
173 .section_offset = offsetof(process_ldap_sync_sections_t, load_cookie),
174 },
176 .default_rcode = RLM_MODULE_NOOP,
177 .send = send_generic,
178 .resume = resume_send_generic,
179 },
181 .default_rcode = RLM_MODULE_NOOP,
182 .send = send_generic,
183 .resume = resume_send_generic
184 },
187 .default_rcode = RLM_MODULE_NOOP,
188 .recv = recv_generic,
189 .resume = resume_recv_generic,
190 .section_offset = offsetof(process_ldap_sync_sections_t, store_cookie),
191 },
193 .default_rcode = RLM_MODULE_NOOP,
194 .send = send_generic,
195 .resume = resume_send_generic,
196 }
197};
198
200 {
201 .section = SECTION_NAME("load", "Cookie"),
202 .actions = &mod_actions_authorize,
203 .offset = PROCESS_CONF_OFFSET(load_cookie)
204 },
205 {
206 .section = SECTION_NAME("store", "Cookie"),
208 .offset = PROCESS_CONF_OFFSET(store_cookie)
209 },
210 {
211 .section = SECTION_NAME("recv", "Add"),
213 .offset = PROCESS_CONF_OFFSET(recv_add)
214 },
215 {
216 .section = SECTION_NAME("recv", "Present"),
218 .offset = PROCESS_CONF_OFFSET(recv_present)
219 },
220 {
221 .section = SECTION_NAME("recv", "Delete"),
223 .offset = PROCESS_CONF_OFFSET(recv_delete)
224 },
225 {
226 .section = SECTION_NAME("recv", "Modify"),
228 .offset = PROCESS_CONF_OFFSET(recv_modify)
229 },
230
232};
233
236 .common = {
237 .magic = MODULE_MAGIC_INIT,
238 .name = "process_ldap_sync",
240 MODULE_RCTX(process_rctx_t)
241 },
242
243 .process = mod_process,
244 .compile_list = compile_list,
245 .dict = &dict_ldap_sync,
246 .packet_type = &attr_packet_type
247};
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:101
fr_dict_attr_t const ** out
Where to write a pointer to the resolved fr_dict_attr_t.
Definition dict.h:292
fr_dict_t const ** out
Where to write a pointer to the loaded/resolved fr_dict_t.
Definition dict.h:305
#define DICT_AUTOLOAD_TERMINATOR
Definition dict.h:311
Specifies an attribute which must be present for the module to function.
Definition dict.h:291
Specifies a dictionary which must be loaded/loadable for the module to function.
Definition dict.h:304
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
Definition dl_module.h:63
fr_dict_attr_t const * attr_packet_type
Definition base.c:91
void log_request(fr_log_type_t type, fr_log_lvl_t lvl, request_t *request, char const *file, int line, char const *fmt,...)
Marshal variadic log arguments into a va_list and pass to normal logging functions.
Definition log.c:610
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
@ L_DBG_LVL_1
Highest priority debug messages (-x).
Definition log.h:67
@ L_DBG_LVL_2
2nd highest priority debug messages (-xx | -X).
Definition log.h:68
@ L_DBG
Only displayed when debugging is enabled.
Definition log.h:56
@ FR_TYPE_UINT32
32 Bit unsigned integer.
unlang_mod_actions_t const mod_actions_authorize
Definition mod_action.c:45
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
Temporary structure to hold arguments for module calls.
Definition module_ctx.h:41
static unlang_action_t mod_process(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
Definition base.c:188
static const virtual_server_compile_t compile_list[]
Definition base.c:214
static fr_process_state_t const process_state[]
Definition base.c:69
CONF_SECTION * recv_delete
Definition base.c:91
fr_dict_autoload_t process_ldap_sync_dict[]
Definition base.c:34
static fr_dict_t const * dict_ldap_sync
Definition base.c:31
CONF_SECTION * recv_modify
Definition base.c:92
process_ldap_sync_sections_t sections
Definition base.c:96
fr_dict_attr_autoload_t process_ldap_sync_dict_attr[]
Definition base.c:42
static char const * ldap_sync_message_types[FR_LDAP_SYNC_CODE_MAX]
Definition base.c:48
CONF_SECTION * recv_add
Definition base.c:89
static void ldap_sync_packet_debug(request_t *request, fr_packet_t *packet, fr_pair_list_t *list, bool received)
Definition base.c:62
CONF_SECTION * store_cookie
Definition base.c:88
fr_process_module_t process_ldap_sync
Definition base.c:235
CONF_SECTION * recv_present
Definition base.c:90
CONF_SECTION * load_cookie
Definition base.c:87
#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 RDEBUG_ENABLED()
@ RLM_MODULE_INVALID
The module considers the request invalid.
Definition rcode.h:51
@ 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_NOOP
Module succeeded without doing anything.
Definition rcode.h:54
#define SECTION_NAME(_name1, _name2)
Define a section name consisting of a verb and a noun.
Definition section.h:39
void * data
Module's instance data.
Definition module.h:293
#define MODULE_RCTX(_ctype)
Definition module.h:259
#define MODULE_INST(_ctype)
Definition module.h:257
#define FR_LDAP_SYNC_PACKET_CODE_VALID(_code)
Definition sync.h:58
@ FR_LDAP_SYNC_CODE_PRESENT
LDAP server indicates a particular object is present and unchanged.
Definition sync.h:33
@ FR_LDAP_SYNC_CODE_COOKIE_STORE_RESPONSE
Response to storing the new cookie.
Definition sync.h:52
@ FR_LDAP_SYNC_CODE_ENTRY_RESPONSE
Response packet to present / add / modify / delete.
Definition sync.h:42
@ FR_LDAP_SYNC_CODE_COOKIE_LOAD_FAIL
Response when coolie load fails.
Definition sync.h:48
@ FR_LDAP_SYNC_CODE_ADD
Object has been added to the LDAP directory.
Definition sync.h:36
@ FR_LDAP_SYNC_CODE_COOKIE_STORE
The server has sent a new cookie.
Definition sync.h:50
@ FR_LDAP_SYNC_CODE_COOKIE_LOAD_RESPONSE
Response with the returned cookie.
Definition sync.h:46
@ FR_LDAP_SYNC_CODE_DELETE
Object has been deleted.
Definition sync.h:40
@ FR_LDAP_SYNC_CODE_COOKIE_LOAD
Before the sync starts, request any previously stored cookie.
Definition sync.h:44
@ FR_LDAP_SYNC_CODE_MAX
Definition sync.h:54
@ FR_LDAP_SYNC_CODE_MODIFY
Object has been modified.
Definition sync.h:38
#define talloc_get_type_abort_const
Definition talloc.h:110
unsigned int code
Packet code (type).
Definition packet.h:61
section_name_t const * section
Identifier for the section.
#define COMPILE_TERMINATOR
Processing sections which are allowed in this virtual server.