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: edf289c8244210454a99b655fe206554e24e3728 $
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
35 { .out = &dict_ldap_sync, .proto = "ldap" },
36 { NULL }
37};
38
40
43 { .out = &attr_packet_type, .name = "Packet-Type", .type= FR_TYPE_UINT32, .dict = &dict_ldap_sync },
44
45 { NULL }
46};
47
49 "", //!< 0
50 "Present",
51 "Add",
52 "Modify",
53 "Delete",
54 "Entry-Response",
55 "Cookie-Load",
56 "Cookie-Load-Response",
57 "Cookie-Store",
58 "Cookie-Store-Response",
59};
60
61static void ldap_sync_packet_debug(request_t *request, fr_packet_t *packet, fr_pair_list_t *list, bool received)
62{
63
64 if (!packet) return;
65 if (!RDEBUG_ENABLED) return;
66
67 log_request(L_DBG, L_DBG_LVL_1, request, __FILE__, __LINE__, "%s %s",
68 received ? "Received" : "Sending",
70 );
71
72 if (received) {
73 log_request_pair_list(L_DBG_LVL_1, request, NULL, list, NULL);
74 } else {
75 /*
76 * At higher debug levels, log returned data as well.
77 */
78 log_request_pair_list(L_DBG_LVL_2, request, NULL, list, NULL);
79 }
80
81}
82
93
97
98#define PROCESS_PACKET_TYPE fr_ldap_sync_packet_code_t
99#define PROCESS_CODE_MAX FR_LDAP_SYNC_CODE_MAX
100#define PROCESS_PACKET_CODE_VALID FR_LDAP_SYNC_PACKET_CODE_VALID
101#define PROCESS_INST process_ldap_sync_t
102#include <freeradius-devel/server/process.h>
103
104
105static unlang_action_t mod_process(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
106{
107 fr_process_state_t const *state;
108
110
112
113 fr_assert(FR_LDAP_SYNC_PACKET_CODE_VALID(request->packet->code));
114
115 request->component = "ldap_sync";
116 request->module = NULL;
117 fr_assert(request->proto_dict == dict_ldap_sync);
118
119 UPDATE_STATE(packet);
120
121 ldap_sync_packet_debug(request, request->packet, &request->request_pairs, true);
122
123 return state->recv(p_result, mctx, request);
124}
125
126static fr_process_state_t const process_state[] = {
128 .default_reply = FR_LDAP_SYNC_CODE_ENTRY_RESPONSE,
129 .default_rcode = RLM_MODULE_NOOP,
130 .recv = recv_generic,
131 .resume = resume_recv_generic,
132 .section_offset = offsetof(process_ldap_sync_sections_t, recv_present),
133 },
135 .default_reply = FR_LDAP_SYNC_CODE_ENTRY_RESPONSE,
136 .default_rcode = RLM_MODULE_NOOP,
137 .recv = recv_generic,
138 .resume = resume_recv_generic,
139 .section_offset = offsetof(process_ldap_sync_sections_t, recv_add)
140 },
142 .default_reply = FR_LDAP_SYNC_CODE_ENTRY_RESPONSE,
143 .default_rcode = RLM_MODULE_NOOP,
144 .recv = recv_generic,
145 .resume = resume_recv_generic,
146 .section_offset = offsetof(process_ldap_sync_sections_t, recv_delete),
147 },
149 .default_reply = FR_LDAP_SYNC_CODE_ENTRY_RESPONSE,
150 .default_rcode = RLM_MODULE_NOOP,
151 .recv = recv_generic,
152 .resume = resume_recv_generic,
153 .section_offset = offsetof(process_ldap_sync_sections_t, recv_modify),
154 },
156 .default_rcode = RLM_MODULE_NOOP,
157 .send = send_generic,
158 .resume = resume_send_generic,
159 },
161 .packet_type = {
167 },
169 .default_rcode = RLM_MODULE_NOOP,
170 .recv = recv_generic,
171 .resume = resume_recv_generic,
172 .section_offset = offsetof(process_ldap_sync_sections_t, load_cookie),
173 },
175 .default_rcode = RLM_MODULE_NOOP,
176 .send = send_generic,
177 .resume = resume_send_generic,
178 },
180 .default_rcode = RLM_MODULE_NOOP,
181 .send = send_generic,
182 .resume = resume_send_generic
183 },
186 .default_rcode = RLM_MODULE_NOOP,
187 .recv = recv_generic,
188 .resume = resume_recv_generic,
189 .section_offset = offsetof(process_ldap_sync_sections_t, store_cookie),
190 },
192 .default_rcode = RLM_MODULE_NOOP,
193 .send = send_generic,
194 .resume = resume_send_generic,
195 }
196};
197
199 {
200 .section = SECTION_NAME("load", "Cookie"),
201 .actions = &mod_actions_authorize,
202 .offset = PROCESS_CONF_OFFSET(load_cookie)
203 },
204 {
205 .section = SECTION_NAME("store", "Cookie"),
207 .offset = PROCESS_CONF_OFFSET(store_cookie)
208 },
209 {
210 .section = SECTION_NAME("recv", "Add"),
212 .offset = PROCESS_CONF_OFFSET(recv_add)
213 },
214 {
215 .section = SECTION_NAME("recv", "Present"),
217 .offset = PROCESS_CONF_OFFSET(recv_present)
218 },
219 {
220 .section = SECTION_NAME("recv", "Delete"),
222 .offset = PROCESS_CONF_OFFSET(recv_delete)
223 },
224 {
225 .section = SECTION_NAME("recv", "Modify"),
227 .offset = PROCESS_CONF_OFFSET(recv_modify)
228 },
229
231};
232
235 .common = {
236 .magic = MODULE_MAGIC_INIT,
237 .name = "process_ldap_sync",
239 MODULE_RCTX(process_rctx_t)
240 },
241
242 .process = mod_process,
243 .compile_list = compile_list,
244 .dict = &dict_ldap_sync,
245 .packet_type = &attr_packet_type
246};
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:274
fr_dict_t const ** out
Where to write a pointer to the loaded/resolved fr_dict_t.
Definition dict.h:287
Specifies an attribute which must be present for the module to function.
Definition dict.h:273
Specifies a dictionary which must be loaded/loadable for the module to function.
Definition dict.h:286
#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:93
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:828
@ L_DBG_LVL_1
Highest priority debug messages (-x).
Definition log.h:70
@ L_DBG_LVL_2
2nd highest priority debug messages (-xx | -X).
Definition log.h:71
@ L_DBG
Only displayed when debugging is enabled.
Definition log.h:59
@ FR_TYPE_UINT32
32 Bit unsigned integer.
unlang_mod_actions_t const mod_actions_authorize
Definition mod_action.c:46
unlang_mod_action_t actions[RLM_MODULE_NUMCODES]
Definition mod_action.h:64
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:90
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:91
process_ldap_sync_sections_t sections
Definition base.c:95
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:88
static void ldap_sync_packet_debug(request_t *request, fr_packet_t *packet, fr_pair_list_t *list, bool received)
Definition base.c:61
CONF_SECTION * store_cookie
Definition base.c:87
fr_process_module_t process_ldap_sync
Definition base.c:234
CONF_SECTION * recv_present
Definition base.c:89
CONF_SECTION * load_cookie
Definition base.c:86
#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:38
#define RDEBUG_ENABLED()
Definition radclient.h:49
@ RLM_MODULE_INVALID
The module considers the request invalid.
Definition rcode.h:45
@ 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_NOOP
Module succeeded without doing anything.
Definition rcode.h:48
#define SECTION_NAME(_name1, _name2)
Define a section name consisting of a verb and a noun.
Definition section.h:40
void * data
Module's instance data.
Definition module.h:291
#define MODULE_RCTX(_ctype)
Definition module.h:257
#define MODULE_INST(_ctype)
Definition module.h:255
#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:287
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.