The FreeRADIUS server $Id: a4e7f8c94e8038b7627bcf52356b7ed15955c1d7 $
Loading...
Searching...
No Matches
proto_ldap_sync_ldap.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: 2f37b5df4f840ca7a99880e4ac3fa9426f6d7902 $
19 * @file proto_ldap_sync_ldap.c
20 * @brief LDAP sync handler.
21 *
22 * @copyright 2022 Network RADIUS SAS (legal@networkradius.com)
23 */
25
26#define LOG_PREFIX "proto_ldap_sync_ldap"
27
28#include <freeradius-devel/protocol/freeradius/freeradius.internal.h>
29#include <freeradius-devel/internal/internal.h>
30#include <freeradius-devel/server/request.h>
31#include <freeradius-devel/io/listen.h>
32#include <freeradius-devel/unlang/call.h>
33#include <freeradius-devel/util/dbuff.h>
34#include <freeradius-devel/ldap/base.h>
35#include <freeradius-devel/ldap/conf.h>
36
38#include "rfc4533.h"
39#include "persistent_search.h"
40#include "active_directory.h"
41
43
46
47/*
48 * Same names as the "connection" section of a connection pool.
49 */
51 { FR_CONF_OFFSET("connect_timeout", connection_conf_t, connection_timeout), .dflt = "10.0", .func = cf_parse_time_delta_bounded, .uctx = &cf_time_delta_bounds_int_msec },
52 { FR_CONF_OFFSET("reconnect_delay", connection_conf_t, reconnection_delay), .dflt = "10" },
53
55};
56
58 /*
59 * LDAP server definition
60 */
62
63 /*
64 * Common LDAP conf parsers
65 */
67
69
70 /*
71 * Network tunable parameters
72 */
73 { FR_CONF_OFFSET_IS_SET("recv_buff", FR_TYPE_UINT32, 0, proto_ldap_sync_ldap_t, recv_buff) },
74 { FR_CONF_OFFSET("max_outstanding", proto_ldap_sync_ldap_t, max_outstanding), .dflt = "65536" },
75
77};
78
81
84 { .out = &dict_ldap_sync, .proto = "ldap" },
85 { .out = &dict_freeradius, .proto = "freeradius" },
87};
88
97
100 { .out = &attr_ldap_sync_packet_id, .name = "Sync-Packet-ID", .type = FR_TYPE_UINT32, .dict = &dict_ldap_sync },
101 { .out = &attr_ldap_sync_cookie, .name = "LDAP-Sync.Cookie", .type = FR_TYPE_OCTETS, .dict = &dict_ldap_sync },
102 { .out = &attr_ldap_sync_entry_dn, .name = "LDAP-Sync.Entry-DN", .type = FR_TYPE_STRING, .dict = &dict_ldap_sync },
103 { .out = &attr_ldap_sync_entry_uuid, .name = "LDAP-Sync.Entry-UUID", .type = FR_TYPE_OCTETS, .dict = &dict_ldap_sync },
104 { .out = &attr_ldap_sync_orig_dn, .name = "LDAP-Sync.Original-DN", .type = FR_TYPE_STRING, .dict = &dict_ldap_sync },
105 { .out = &attr_ldap_sync_root_dn, .name = "LDAP-Sync.Directory-Root-DN", .type = FR_TYPE_STRING, .dict = &dict_ldap_sync },
106 { .out = &attr_packet_type, .name = "Packet-Type", .type = FR_TYPE_UINT32, .dict = &dict_ldap_sync },
107 { .out = &attr_ldap_sync_base_dn, .name = "LDAP-Sync-Base-DN", .type = FR_TYPE_STRING, .dict = &dict_freeradius },
109};
110
116
117/** Operations performed on entries
118 */
120 { L("add"), SYNC_OP_ADD },
121 { L("delete"), SYNC_OP_DELETE },
122 { L("modify"), SYNC_OP_MODIFY },
123 { L("present"), SYNC_OP_PRESENT },
124};
126
127/** Context used when looking up Directory types
128 */
135
136/** Context for "load Cookie" retry timed event
137 */
143
144/** Compare two sync state structures on msgid
145 *
146 * @param[in] one first sync to compare.
147 * @param[in] two second sync to compare.
148 * @return CMP(one, two)
149 */
150fr_cmp_ret_t sync_state_cmp(void const *one, void const *two)
151{
152 sync_state_t const *a = one, *b = two;
153
154 return CMP(a->msgid, b->msgid);
155}
156
157/** Tell the remote server to stop the sync
158 *
159 * Terminates the search informing the remote server that we no longer want to receive results
160 * for this sync. A RFC 4511 abandon request is used to inform the server.
161 *
162 * This allows individual syncs to be stopped without destroying the underlying connection.
163 *
164 * Removes the sync's msgid from the tree of msgids associated with the connection.
165 *
166 * @param[in] sync to abandon.
167 * @return 0
168 */
170{
171 fr_ldap_connection_t *conn = talloc_get_type_abort(sync->conn, fr_ldap_connection_t);
172 fr_rb_tree_t *tree = talloc_get_type_abort(conn->uctx, fr_rb_tree_t);
173
174 DEBUG3("Abandoning sync base dn \"%s\", filter \"%s\"", sync->config->base_dn, sync->config->filter);
175
176 trigger(unlang_interpret_get_thread_default(), sync->config->cs, NULL, "modules.ldap_sync.stop", true, &sync->trigger_args, sync);
177
178 if (!sync->conn->handle) return 0; /* Handled already closed? */
179
180 /*
181 * Tell the remote server to stop sending results
182 */
183 if (sync->msgid >= 0) ldap_abandon_ext(sync->conn->handle, sync->msgid, NULL, NULL);
184 fr_rb_delete(tree, &(sync_state_t){.msgid = sync->msgid});
185
186 return 0;
187}
188
189/** Allocate a sync state
190 *
191 * @param[in] ctx to allocate the sync state in.
192 * @param[in] conn which the sync will run on.
193 * @param[in] inst module instance for the sync.
194 * @param[in] sync_no number of the sync in the array of configs.
195 * @param[in] config for the sync.
196 * @return new sync state.
197 */
199 size_t sync_no, sync_config_t const *config)
200{
201 sync_state_t *sync;
202 fr_pair_t *vp;
203
204 MEM(sync = talloc_zero(ctx, sync_state_t));
205 sync->conn = conn;
206 sync->inst = inst;
207 sync->config = config;
208 sync->sync_no = sync_no;
209 sync->phase = SYNC_PHASE_INIT;
210
212
213 /*
214 * Create arguments to pass to triggers
215 */
218 talloc_strlen(config->base_dn), false);
219
220 /*
221 * If the connection is freed, all the sync state is also freed
222 */
223 talloc_set_destructor(sync, sync_state_free);
224
225 return sync;
226}
227
228/** Add a new cookie packet ctx to the pending list
229 *
230 * Does not actually send the packet.
231 *
232 * @param[in] sync the cookie was received for.
233 * @param[in] refresh the sync after storing this cookie.
234 * @return
235 * - 0 on success.
236 * - -1 on failure
237 */
238int ldap_sync_cookie_store(sync_state_t *sync, bool refresh)
239{
240 sync_packet_ctx_t *sync_packet_ctx = NULL;
241 uint8_t *cookie = sync->cookie;
242
243 MEM(sync_packet_ctx = talloc_zero(sync, sync_packet_ctx_t));
244 sync_packet_ctx->sync = sync;
245
246 sync_packet_ctx->type = SYNC_PACKET_TYPE_COOKIE;
247 if (cookie) sync_packet_ctx->cookie = talloc_memdup(sync_packet_ctx, cookie, talloc_array_length(cookie));
248 sync_packet_ctx->refresh = refresh;
249
250 if (fr_dlist_insert_tail(&sync->pending, sync_packet_ctx) < 0) {
251 talloc_free(sync_packet_ctx);
252 return -1;
253 }
254 sync->pending_cookies++;
255
256 return 0;
257}
258
259/** Event to handle storing of cookies on a timed basis
260 *
261 * Looks at the head of the list of pending sync packets for a cookie.
262 * A cookie at the head says that all the previous changes have been
263 * completed, so the cookie can be sent.
264 */
266{
267 sync_state_t *sync = talloc_get_type_abort(uctx, sync_state_t);
268 sync_packet_ctx_t *sync_packet_ctx;
269
270 if (sync->pending_cookies == 0) goto finish;
271
272 /*
273 * Check the head entry in the list - is it a pending cookie
274 */
275 sync_packet_ctx = fr_dlist_head(&sync->pending);
276 if ((sync_packet_ctx->type != SYNC_PACKET_TYPE_COOKIE) ||
277 (sync_packet_ctx->status != SYNC_PACKET_PENDING)) goto finish;
278
279 ldap_sync_cookie_send(sync_packet_ctx);
280
281finish:
282 (void) fr_timer_in(sync, tl, &sync->cookie_ev, sync->inst->cookie_interval,
283 false, ldap_sync_cookie_event, sync);
284}
285
286/** Enqueue a new cookie store packet
287 *
288 * Create a new internal packet containing the cookie we received from the LDAP server.
289 * This allows the administrator to store the cookie and provide it on a future call to
290 * load Cookie.
291 *
292 * @param[in] sync_packet_ctx packet context containing the cookie to store.
293 * @return
294 * - 0 on success.
295 * - -1 on failure.
296*/
298{
299 sync_state_t *sync = sync_packet_ctx->sync;
300 proto_ldap_sync_ldap_thread_t *thread = talloc_get_type_abort(sync->config->user_ctx, proto_ldap_sync_ldap_thread_t);
301 fr_dbuff_t *dbuff;
302 fr_pair_list_t pairs;
303 fr_pair_t *vp;
304 TALLOC_CTX *local = NULL;
305 uint8_t *cookie = sync_packet_ctx->cookie;
306
307 if (sync_packet_ctx->status != SYNC_PACKET_PENDING) return 0;
308 sync_packet_ctx->status = SYNC_PACKET_PREPARING;
309
310 FR_DBUFF_TALLOC_THREAD_LOCAL(&dbuff, 1024, 4096);
311
312 local = talloc_new(NULL);
313 fr_pair_list_init(&pairs);
314 if (fr_pair_list_copy(local, &pairs, &sync->config->sync_pairs) < 0) {
315 error:
316 talloc_free(local);
317 return -1;
318 }
319
321 if (!vp) goto error;
322
324 if (!vp) goto error;
325
326 /*
327 * Add the cookie to the packet, if set.
328 * If the server has indicated a refresh is required it can do so
329 * with no cookie set - so we store a blank cookie to clear anything
330 * which was previously stored.
331 */
332 if (cookie) {
334 cookie, talloc_array_length(cookie), true);
335 if (!vp) goto error;
336 }
337
338 if (fr_internal_encode_list(dbuff, &pairs, &encode_ctx) < 0) goto error;
339 talloc_free(local);
340
341 if (fr_network_listen_send_packet(thread->nr, thread->li, thread->li, fr_dbuff_buff(dbuff),
342 fr_dbuff_used(dbuff), fr_time(), sync_packet_ctx) < 0) {
343 sync_packet_ctx->status = SYNC_PACKET_PENDING;
344 return -1;
345 }
346
347 sync_packet_ctx->status = SYNC_PACKET_PROCESSING;
348
349 return 0;
350}
351
352/** Send a change packet to the workers
353 *
354 * Called each time a change packet is received and also from a
355 * timer event retrying packets which previously failed to send.
356 *
357 * @param sync_packet_ctx Packet to send
358 * @return
359 * - 0 on success.
360 * - -1 on failure.
361 */
363{
364 proto_ldap_sync_ldap_thread_t *thread = talloc_get_type_abort(sync_packet_ctx->sync->config->user_ctx,
366 fr_dbuff_t *dbuff;
367
368 FR_DBUFF_TALLOC_THREAD_LOCAL(&dbuff, 1024, 4096);
369
370 if (fr_internal_encode_list(dbuff, &sync_packet_ctx->pairs, &encode_ctx) < 0) return -1;
371 if (fr_network_listen_send_packet(thread->nr, thread->li, thread->li, fr_dbuff_buff(dbuff),
372 fr_dbuff_used(dbuff), fr_time(), sync_packet_ctx) < 0) return -1;
373
374 sync_packet_ctx->status = SYNC_PACKET_PROCESSING;
375 fr_pair_list_free(&sync_packet_ctx->pairs);
376
377 return 0;
378}
379
380/** Event to handle sending of any change packets which failed to send.
381 *
382 * Looks at the head of the list of pending sync packets for unsent
383 * change packets and sends any up to the first cookie.
384 */
385static void ldap_sync_retry_event(fr_timer_list_t *tl, UNUSED fr_time_t now, void *uctx)
386{
387 sync_state_t *sync = talloc_get_type_abort(uctx, sync_state_t);
388 sync_packet_ctx_t *sync_packet_ctx = NULL;
389
390 while ((sync_packet_ctx = fr_dlist_next(&sync->pending, sync_packet_ctx))) {
391 if (sync_packet_ctx->type != SYNC_PACKET_TYPE_CHANGE) break;
392 if (sync_packet_ctx->status != SYNC_PACKET_PENDING) continue;
393
394 /*
395 * Retry sending packet. Don't try any more if it fails.
396 */
397 if (ldap_sync_entry_send_network(sync_packet_ctx) < 0) break;
398 }
399
400 /*
401 * We didn't run through the whole list, so there may be other pending
402 * packets - reschedule a retry event.
403 */
404 if (sync_packet_ctx) {
405 (void) fr_timer_in(sync, tl, &sync->retry_ev, sync->inst->retry_interval,
406 false, ldap_sync_retry_event, sync);
407 }
408}
409
416
417/** Enqueue a new entry change packet.
418 *
419 * @param[in] sync notification has arrived for.
420 * @param[in] uuid of the entry (RFC 4533 only).
421 * @param[in] orig_dn original DN of the entry - provided by those directories
422 * implementing persistent search, when an entry is renamed.
423 * @param[in] msg containing the entry.
424 * @param[in] op The type of modification we need to perform to our
425 * representation of the entry.
426 * @return
427 * - 0 on success.
428 * - -1 on failure.
429 */
430int ldap_sync_entry_send(sync_state_t *sync, uint8_t const uuid[SYNC_UUID_LENGTH], struct berval *orig_dn,
431 LDAPMessage *msg, sync_op_t op)
432{
434 fr_pair_list_t *pairs;
435 fr_pair_t *vp;
436 sync_packet_ctx_t *sync_packet_ctx = NULL;
437
438 MEM(sync_packet_ctx = talloc_zero(sync, sync_packet_ctx_t));
439 sync_packet_ctx->sync = sync;
440
441 fr_pair_list_init(&sync_packet_ctx->pairs);
442 pairs = &sync_packet_ctx->pairs;
443
444 if (fr_pair_list_copy(sync_packet_ctx, pairs, &sync->config->sync_pairs) < 0) {
445 error:
446 if (msg) ldap_msgfree(msg);
447 talloc_free(sync_packet_ctx);
448 return -1;
449 }
450
451 pcode = sync_packet_code_table[op];
452
453 fr_pair_list_append_by_da(sync_packet_ctx, vp, pairs, attr_packet_type, (uint32_t)pcode, false);
454 if (!vp) goto error;
455
456 fr_pair_list_append_by_da(sync_packet_ctx, vp, pairs, attr_ldap_sync_packet_id, (uint32_t)sync->sync_no, false);
457 if (!vp) goto error;
458
459 /*
460 * Add the UUID if provided
461 */
462 if (uuid) {
464 uuid, SYNC_UUID_LENGTH, true);
465 if (!vp) goto error;
466 }
467
468 /*
469 * Add the original DN if provided
470 */
471 if (orig_dn && (orig_dn->bv_len > 0)) {
473 orig_dn->bv_val, orig_dn->bv_len, true);
474 if (!vp) goto error;
475 }
476
477 /*
478 * Add the entry DN if there is an LDAP message to read
479 */
480 if (msg) {
481 char *entry_dn = ldap_get_dn(sync->conn->handle, msg);
482 map_t const *map = NULL;
483 struct berval **values;
484 int count, i;
485
487 entry_dn, strlen(entry_dn), true);
488 if (!vp) goto error;
489
490 ldap_memfree(entry_dn);
491
492 /*
493 * Map LDAP returned attributes to pairs as per update map
494 */
495 while ((map = map_list_next(&sync->config->entry_map, map))) {
496 values = ldap_get_values_len(fr_ldap_handle_thread_local(), msg, map->rhs->name);
497 if (!values) goto next;
498
499 count = ldap_count_values_len(values);
500
501 for (i = 0; i < count; i++) {
502 if (values[i]->bv_len == 0) continue;
503
504 if (pair_append_by_tmpl_parent(sync_packet_ctx, &vp, pairs, map->lhs, true) < 0) break;
505 if (fr_value_box_from_str(vp, &vp->data, vp->vp_type, NULL, values[i]->bv_val,
506 values[i]->bv_len, NULL) < 0) {
507 fr_pair_remove(pairs, vp);
509 }
510
511 /* Only += operator adds multiple values */
512 if (map->op != T_OP_ADD_EQ) break;
513 }
514 next:
515 ldap_value_free_len(values);
516 }
517 }
518
519 if (fr_dlist_insert_tail(&sync->pending, sync_packet_ctx) < 0) goto error;
520
521 ldap_msgfree(msg);
522
523 /*
524 * Send the packet and if it fails to send add a retry event
525 */
526 if ((ldap_sync_entry_send_network(sync_packet_ctx) < 0) &&
527 (fr_timer_in(sync, sync->conn->conn->el->tl, &sync->retry_ev,
528 sync->inst->retry_interval, false, ldap_sync_retry_event, sync) < 0)) {
529 PERROR("Inserting LDAP sync retry timer failed");
530 }
531
532 return 0;
533}
534
536 UNUSED connection_state_t state, void *uctx);
537
539 UNUSED connection_state_t state, void *uctx);
540
541/** Attempt to (re)initialise a connection
542 *
543 * Performs complete re-initialization of a connection. Called during socket_open
544 * to create the initial connection and again any time we need to reopen the connection.
545 *
546 * @param[in] tl the event list managing listen event.
547 * @param[in] now current time.
548 * @param[in] user_ctx Listener.
549 */
550static void proto_ldap_connection_init(fr_timer_list_t *tl, UNUSED fr_time_t now, void *user_ctx)
551{
552 fr_listen_instance_t *listen = talloc_get_type_abort(user_ctx, fr_listen_instance_t);
553 proto_ldap_sync_ldap_thread_t *thread = talloc_get_type_abort(listen->thread_instance, proto_ldap_sync_ldap_thread_t);
555
556 if (thread->conn) talloc_free(thread->conn);
557
558 /*
559 * Allocate an outbound LDAP connection
560 */
561 thread->conn = connection_alloc(thread, thread->el,
563 .init = fr_ldap_connection_init,
564 .close = fr_ldap_connection_close
565 },
566 &inst->conn_conf, "ldap_sync", &inst->handle_config);
567
568 if (!thread->conn) {
569 PERROR("Failed (re)initialising connection, will retry in %pV seconds",
570 fr_box_time_delta(inst->conn_conf.reconnection_delay));
571
572 if (fr_timer_in(thread, tl, &thread->conn_retry_ev,
573 inst->conn_conf.reconnection_delay,
574 false, proto_ldap_connection_init, listen) < 0) {
575 FATAL("Failed inserting event: %s", fr_strerror());
576 }
577 }
578
579 /*
580 * Add watch functions on the LDAP connection
581 */
583 _proto_ldap_socket_init, true, thread);
584
587
588 /*
589 * Signal the connection to start
590 */
592
593 return;
594}
595
596/** Child listener mod_close
597 *
598 * Ensures the LDAP connection is signalled to close gracefully when
599 * the listener is closed.
600 */
602{
604
606 return 0;
607}
608
609/** LDAP sync mod_read for child listener
610 *
611 * Called when there is data to read on the LDAP connection
612 *
613 * Actual packets are created by the various callbacks since a single LDAP
614 * message can result in multiple packets to process e.g.:
615 *
616 * - Sync Info Message with syncInfoValue of syncIdSet can reference
617 * multiple directory entries.
618 * - Various sync related messages can include a new cookie in
619 * addition to their other data.
620 */
622 UNUSED fr_time_t *recv_time_p,
623 UNUSED uint8_t *buffer, UNUSED size_t buffer_len, UNUSED size_t *leftover)
624{
626 fr_ldap_connection_t *conn = talloc_get_type_abort(thread->conn->h, fr_ldap_connection_t);
627 struct timeval poll = { 1, 0 };
628 LDAPMessage *msg = NULL;
629 int ret = 0;
630 fr_ldap_rcode_t rcode;
631 sync_state_t *sync = NULL;
632 fr_rb_tree_t *tree;
633 int type, msgid;
634 LDAPControl **ctrls = NULL;
635 sync_msg_t callback = NULL;
636
637 fr_assert(conn);
638
639 /*
640 * If there are already too many outstanding requests just return.
641 * This will (potentially) cause the TCP buffer to fill and push the
642 * backpressure back to the LDAP server.
643 */
644 if (fr_network_listen_outstanding(thread->nr, li) >= thread->inst->max_outstanding) return 0;
645
646 tree = talloc_get_type_abort(conn->uctx, fr_rb_tree_t);
647
648 /*
649 * Pull the next outstanding message from this connection.
650 * We process one message at a time so that the message can be
651 * passed to the worker, and freed once the request has been
652 * handled.
653 */
654 ret = ldap_result(conn->handle, LDAP_RES_ANY, LDAP_MSG_ONE, &poll, &msg);
655
656 switch (ret) {
657 case 0: /*
658 * Timeout - this has been observed if changes are being
659 * processed slowly, the TCP receive buffer fills and
660 * the LDAP directory pauses sending data for a period.
661 * Then all pending changes are processed and the receive buffer
662 * is emptied.
663 * The situation resolves when the directory starts sending
664 * data again.
665 */
666 return 0;
667
668 case -1:
669 rcode = fr_ldap_error_check(NULL, conn, NULL, NULL);
670 if (rcode == LDAP_PROC_BAD_CONN) return -2;
671 return -1;
672
673 default:
674 break;
675 }
676
677 /*
678 * De-multiplex based on msgid
679 */
680 if (!msg) return 0;
681
682 msgid = ldap_msgid(msg);
683 type = ldap_msgtype(msg);
684
685 ret = 0;
686 if (msgid == 0) {
687 WARN("Ignoring unsolicited %s message",
689 free_msg:
690 if (ctrls) ldap_controls_free(ctrls);
691 ldap_msgfree(msg);
692 return ret;
693 }
694
695 fr_rb_find((void **)&sync, tree, &(sync_state_t){.msgid = msgid});
696 if (!sync) {
697 WARN("Ignoring msgid %i, doesn't match any outstanding syncs", msgid);
698 goto free_msg;
699 }
700
701 /*
702 * Check for errors contained within the message.
703 * This has to be per message, as multiple syncs
704 * are multiplexed together on one connection.
705 */
706 switch (fr_ldap_error_check(&ctrls, conn, msg, sync->config->base_dn)) {
708 break;
709
710 /*
711 * The e-syncRefresRequired result code is the server informing us that
712 * the query needs to be restarted for a new refresh phase to run.
713 * It is sent as the result code for a SearchResultsDone message.
714 */
716 if (type != LDAP_RES_SEARCH_RESULT) {
717 PERROR("e-syncRefreshRequired result code received on wrong message type");
718 ret = -1;
719 goto free_msg;
720 }
721
722 DEBUG2("LDAP Server returned e-syncRefreshRequired");
723 if (sync->config->refresh) {
724 return sync->config->refresh(sync, msg, ctrls);
725 }
726 goto free_msg;
727
728 /*
729 * Don't think this should happen... but libldap
730 * is wonky sometimes...
731 */
733 PERROR("Connection unusable");
734 ret = -2;
735 goto free_msg;
736
737 default:
738 PERROR("Sync error");
739 ret = -1;
740 goto free_msg;
741 }
742
743 DEBUG3("Got %s message for sync (msgid %i)",
745
746 switch (type) {
747 case LDAP_RES_SEARCH_REFERENCE:
748 case LDAP_RES_SEARCH_ENTRY:
749 callback = sync->config->entry;
750 break;
751
752 case LDAP_RES_INTERMEDIATE:
753 callback = sync->config->intermediate;
754 break;
755
756 default:
757 WARN("Ignoring unexpected message type (%i)", type);
758 ret = 0;
759 goto free_msg;
760 }
761
762 if (callback) {
763 ret = callback(sync, msg, ctrls);
764 if (ret < 0) PERROR("Sync callback error");
765 } else {
766 /*
767 * Callbacks are responsible for freeing the msg
768 * so if there is no callback, free it.
769 */
770 ldap_msgfree(msg);
771 }
772
773 ldap_controls_free(ctrls);
774
775 return ret;
776}
777
778/** Send a fake packet to run the "load Cookie" section
779 *
780 * @param ctx Context to allocate temporary pairs in.
781 * @param inst LDAP sync configuration.
782 * @param sync_no Id of the sync whose.
783 * @param thread Thread specific LDAP sync data.
784 * @return
785 * - 0 on success
786 * - -1 on failure
787 */
788static int proto_ldap_cookie_load_send(TALLOC_CTX *ctx, proto_ldap_sync_ldap_t const *inst, size_t sync_no,
790 size_t len;
791 sync_config_t *config = inst->parent->sync_config[sync_no];
792 fr_pair_list_t pairs;
793 fr_pair_t *vp;
794 fr_dbuff_t *dbuff;
795 fr_ldap_connection_t *ldap_conn = thread->conn->h;
796
797 fr_pair_list_init(&pairs);
798 if (unlikely(fr_pair_list_copy(ctx, &pairs, &config->sync_pairs) < 0)) return -1;
799
800 /*
801 * Ensure we have access to the thread instance
802 * in for the demux callbacks
803 */
804 inst->parent->sync_config[sync_no]->user_ctx = thread;
805
806 /*
807 * Assess the namingContext which applies to this sync
808 */
809 if (ldap_conn->directory->naming_contexts) {
810 char const * const *contexts = ldap_conn->directory->naming_contexts;
811 size_t j, num = talloc_str_array_len(contexts);
812 size_t base_dn_len = talloc_strlen(config->base_dn);
813
814 for (j = 0; j < num; j++) {
815 len = talloc_strlen(contexts[j]);
816 if (base_dn_len < len) continue;
817
818 if (strncasecmp(&config->base_dn[base_dn_len - len], contexts[j], len) == 0) {
819 config->root_dn = contexts[j];
820 break;
821 }
822 }
823 }
824
825 /*
826 * Set up callbacks based on directory type.
827 */
828 switch (ldap_conn->directory->sync_type) {
832 config->intermediate = rfc4533_sync_intermediate;
834 break;
835
839 break;
840
844 break;
845
846 default:
847 fr_assert(0);
848 }
849
852 if (!vp) return -1;
853 fr_pair_list_append_by_da(ctx, vp, &pairs, attr_ldap_sync_packet_id, (uint32_t)sync_no, false);
854 if (!vp) return -1;
855
856 if (config->root_dn) {
858 config->root_dn, strlen(config->root_dn), false);
859 if (!vp) return -1;
860 }
861
862 FR_DBUFF_TALLOC_THREAD_LOCAL(&dbuff, 1024, 4096);
863
864 if (fr_internal_encode_list(dbuff, &pairs, &encode_ctx) < 0) return -1;
865
866 if (fr_network_listen_send_packet(thread->nr, thread->li, thread->li,
867 fr_dbuff_buff(dbuff), fr_dbuff_used(dbuff),
868 fr_time(), NULL) < 0) return -1;
869 fr_pair_list_free(&pairs);
870 return 0;
871}
872
873/** Timer event to retry running "load Cookie" on failures
874 *
875 */
877{
878 proto_ldap_cookie_load_retry_ctx *retry_ctx = talloc_get_type_abort(uctx, proto_ldap_cookie_load_retry_ctx);
879
880 DEBUG2("Retrying \"load Cookie\" for sync no %zu", retry_ctx->sync_no);
881 if (proto_ldap_cookie_load_send(retry_ctx, retry_ctx->inst, retry_ctx->sync_no,
882 retry_ctx->thread) < 0) {
883 ERROR("Failed retrying \"load Cookie\". Will try again in %pV seconds",
885 (void) fr_timer_in(retry_ctx->thread->conn->h, tl,
886 &retry_ctx->inst->parent->sync_config[retry_ctx->sync_no]->ev,
888 false, proto_ldap_cookie_load_retry, retry_ctx);
889 return;
890 }
891 talloc_free(retry_ctx);
892}
893
894/** LDAP sync mod_write for child listener
895 *
896 * Handle any returned data after the worker has processed the packet and,
897 * for packets where tracking structures were used, ensure they are freed.
898 */
900 uint8_t *buffer, size_t buffer_len, UNUSED size_t written)
901{
904 fr_dbuff_t dbuff;
906 uint32_t packet_id;
907 fr_pair_list_t tmp;
908 fr_pair_t *vp = NULL;
909 ssize_t ret;
910 TALLOC_CTX *local;
911 sync_packet_ctx_t *sync_packet_ctx = NULL;
912
913 local = talloc_new(NULL);
914 fr_dbuff_init(&dbuff, buffer, buffer_len);
915
916 if (packet_ctx) sync_packet_ctx = talloc_get_type_abort(packet_ctx, sync_packet_ctx_t);
917
918 /*
919 * Extract returned attributes into a temporary list
920 */
921 fr_pair_list_init(&tmp);
922
923 ret = fr_internal_decode_list_dbuff(local, &tmp, fr_dict_root(dict_ldap_sync), &dbuff, NULL);
924 if (ret < 0) goto finish;
925
926 /*
927 * There should always be a packet ID and code
928 */
930 fr_assert(vp);
931 packet_id = vp->vp_uint32;
932
934 fr_assert(vp);
935 pcode = vp->vp_uint32;
936
937 switch (pcode) {
939 {
940 uint8_t *cookie = NULL;
941
942 /*
943 * If the received packet ID is greater than the number of syncs
944 * we have then something very bad has happened
945 */
946 fr_assert (packet_id < talloc_array_length(inst->parent->sync_config));
947
948 /*
949 * Look for the returned cookie.
950 */
952 if (vp) cookie = talloc_memdup(inst, vp->vp_octets, vp->vp_length);
953
954 if (inst->parent->sync_config[packet_id]->init(thread->conn->h, packet_id, inst->parent, cookie) < 0) {
955 ret = -1;
956 goto finish;
957 }
958 }
959 break;
960
962 break;
963
965 {
966 sync_config_t const *sync_config;
967
968 if (!sync_packet_ctx || !sync_packet_ctx->refresh) break;
969
970 /*
971 * Abandon the old sync and start a new one with the relevant cookie.
972 */
973 sync_config = sync_packet_ctx->sync->config;
974 DEBUG3("Restarting sync with base %s", sync_config->base_dn);
975 talloc_free(sync_packet_ctx->sync);
976 if (inst->parent->sync_config[packet_id]->init(thread->conn->h, packet_id, inst->parent,
977 sync_packet_ctx->cookie) < 0) {
978 ret = -1;
979 goto finish;
980 }
981 }
982 break;
983
985 {
987
988 ERROR("Load Cookie failed for sync %" PRIu32 ", retrying in %pV seconds", packet_id,
989 fr_box_time_delta(inst->conn_conf.reconnection_delay));
990
991 MEM(retry_ctx = talloc(thread, proto_ldap_cookie_load_retry_ctx));
993 .thread = thread,
994 .inst = inst,
995 .sync_no = packet_id,
996 };
997
998 (void) fr_timer_in(thread->conn->h, thread->el->tl, &inst->parent->sync_config[packet_id]->ev,
999 inst->conn_conf.reconnection_delay,
1000 false, proto_ldap_cookie_load_retry, retry_ctx);
1001 }
1002 break;
1003
1004 default:
1005 ERROR("Invalid packet type returned %u", pcode);
1006 break;
1007 }
1008
1009 if (sync_packet_ctx) {
1010 sync_state_t *sync = sync_packet_ctx->sync;
1012 proto_ldap_sync_t *ldap_sync = inst->parent;
1013
1014 sync_packet_ctx->status = SYNC_PACKET_COMPLETE;
1015
1016 /*
1017 * A cookie has been stored, reset the counter of changes
1018 */
1019 if (sync_packet_ctx->type == SYNC_PACKET_TYPE_COOKIE) sync->changes_since_cookie = 0;
1020
1021 /*
1022 * Pop any processed updates from the head of the list
1023 */
1024 while ((pc = fr_dlist_head(&sync->pending))) {
1025 /*
1026 * If the head entry in the list is a pending cookie but we have
1027 * not processed enough entries and there are more pending
1028 * cookies, mark this one as processed.
1029 */
1030 if ((pc->type == SYNC_PACKET_TYPE_COOKIE) && (pc->status == SYNC_PACKET_PENDING) &&
1031 (sync->changes_since_cookie < ldap_sync->cookie_changes) &&
1032 (sync->pending_cookies > 1)) pc->status = SYNC_PACKET_COMPLETE;
1033
1034 if (pc->status != SYNC_PACKET_COMPLETE) break;
1035
1036 /*
1037 * Update counters depending on entry type
1038 */
1039 if (pc->type == SYNC_PACKET_TYPE_COOKIE) {
1040 sync->pending_cookies--;
1041 } else {
1042 sync->changes_since_cookie++;
1043 }
1044 pc = fr_dlist_pop_head(&sync->pending);
1045 talloc_free(pc);
1046 }
1047
1048 /*
1049 * If the head of the list is a cookie which has not yet
1050 * been processed and sufficient changes have been recorded
1051 * send the cookie.
1052 */
1053 if (pc && (pc->type == SYNC_PACKET_TYPE_COOKIE) && (pc->status == SYNC_PACKET_PENDING) &&
1055 }
1056
1057finish:
1058 fr_pair_list_free(&tmp);
1059 talloc_free(local);
1060
1061 return ret;
1062}
1063
1064/** Callback for socket errors when running initial root query
1065 */
1067 UNUSED int fd_errno, void *uctx)
1068{
1069 proto_ldap_dir_ctx *dir_ctx = talloc_get_type_abort(uctx, proto_ldap_dir_ctx);
1070 fr_ldap_connection_t *ldap_conn = talloc_get_type_abort(dir_ctx->conn->h, fr_ldap_connection_t);
1071
1072 talloc_free(dir_ctx);
1073 fr_ldap_state_error(ldap_conn);
1074}
1075
1076/** Callback to process results of initial root query, identifying directory type
1077 */
1078static void _proto_ldap_socket_open_read(fr_event_list_t *el, int fd, UNUSED int flags, void *uctx)
1079{
1080 proto_ldap_dir_ctx *dir_ctx = talloc_get_type_abort(uctx, proto_ldap_dir_ctx);
1081 fr_ldap_connection_t *ldap_conn = talloc_get_type_abort(dir_ctx->conn->h, fr_ldap_connection_t);
1082 fr_listen_t const *listen = dir_ctx->main_listen->listen;
1085 proto_ldap_sync_ldap_thread_t *thread = talloc_get_type_abort(dir_ctx->main_listen->thread_instance,
1087 fr_ldap_rcode_t status;
1088 LDAPMessage *result;
1089
1090 size_t i;
1091 TALLOC_CTX *local = NULL;
1092
1093 /*
1094 * The event loop calls this handler when the fd is readable. fr_ldap_result()
1095 * returns LDAP_PROC_PENDING until it has read the final message.
1096 */
1097 status = fr_ldap_result(&result, NULL, ldap_conn, dir_ctx->msgid, LDAP_MSG_ALL, NULL, fr_time_delta_from_msec(0));
1098 switch (status) {
1099 case LDAP_PROC_PENDING:
1100 return;
1101
1102 case LDAP_PROC_SUCCESS:
1103 break;
1104
1105 default:
1106 PERROR("Failed querying for directory type");
1107 if (result) ldap_msgfree(result);
1108 error:
1109 talloc_free(dir_ctx);
1110 if (local) talloc_free(local);
1112 return;
1113 }
1114
1115 fr_ldap_directory_result_parse(ldap_conn->directory, ldap_conn->handle, result, ldap_conn->config->name);
1116 ldap_msgfree(result);
1117
1118 /*
1119 * If the server does not support any of the relevant controls, we just
1120 * tidy up - no point in signalling to reconnect.
1121 */
1122 if (ldap_conn->directory->sync_type == FR_LDAP_SYNC_NONE) {
1123 ERROR("LDAP sync configured for directory which does not support any suitable control");
1124 talloc_free(dir_ctx);
1125 connection_signal_halt(ldap_conn->conn);
1126 return;
1127 }
1128
1129 /*
1130 * We've done all the preparation work on the LDAP connection, now
1131 * use normal network event listeners.
1132 */
1134 if (unlikely(fr_network_listen_add(thread->nr, thread->li) < 0)) {
1135 PERROR("Failed adding listener");
1136 goto error; /* retry? */
1137 }
1138
1139 DEBUG2("Starting sync(s)");
1140
1141 local = talloc_new(NULL);
1142
1143 /*
1144 * Sync operations start by sending a fake packet to run
1145 * the load Cookie section in order to retrieve the cookie
1146 */
1147 for (i = 0; i < talloc_array_length(inst->parent->sync_config); i++) {
1148 if (proto_ldap_cookie_load_send(local, inst, i, thread) < 0) goto error;
1149 }
1150
1151 talloc_free(dir_ctx);
1152 talloc_free(local);
1153}
1154
1155/** Allocate a child listener
1156 *
1157 * Called as a watch function when the LDAP connection enters the INIT state
1158 */
1160 UNUSED connection_state_t state, void *uctx)
1161{
1162 proto_ldap_sync_ldap_thread_t *thread = talloc_get_type_abort(uctx, proto_ldap_sync_ldap_thread_t);
1164
1165 MEM(li = fr_listen_instance_alloc(conn, thread->child_listen));
1166
1167 thread->li = li;
1168 li->thread_instance = thread;
1169 li->name = li->listen->app_io->common.name;
1170}
1171
1172/** Callback for closure of LDAP connection
1173 *
1174 * Schedules re-start of the connection if appropriate
1175 */
1177 UNUSED connection_state_t state, void *uctx)
1178{
1179 fr_listen_instance_t *listen = talloc_get_type_abort(uctx, fr_listen_instance_t);
1180 proto_ldap_sync_ldap_thread_t *thread = talloc_get_type_abort(listen->thread_instance, proto_ldap_sync_ldap_thread_t);
1181 proto_ldap_sync_ldap_t const *inst = thread->inst;
1182
1183 if (fr_event_loop_exiting(thread->el)) return;
1184
1185 if (prev == CONNECTION_STATE_CONNECTED) {
1186 ERROR("LDAP connection closed. Scheduling restart in %pVs",
1187 fr_box_time_delta(inst->conn_conf.reconnection_delay));
1188 if (fr_timer_in(thread, thread->el->tl, &thread->conn_retry_ev,
1189 inst->conn_conf.reconnection_delay,
1190 false, proto_ldap_connection_init, listen) < 0) {
1191 FATAL("Failed inserting event: %s", fr_strerror());
1192 }
1193 }
1194}
1195
1196/** Query an LDAP server to establish its type
1197 *
1198 * Called as a watch function once the LDAP connection enters the CONNECTED state
1199 *
1200 * There are three different forms of LDAP sync/persistent search - so we need
1201 * to know what we're dealing with, and whether the relevant options have been enabled.
1202 */
1204 UNUSED connection_state_t state, void *uctx)
1205{
1206 proto_ldap_sync_ldap_thread_t *thread = talloc_get_type_abort(uctx, proto_ldap_sync_ldap_thread_t);
1207 fr_listen_instance_t *listen = talloc_get_type_abort(thread->parent, fr_listen_instance_t);
1210 fr_ldap_connection_t *ldap_conn = talloc_get_type_abort(conn->h, fr_ldap_connection_t);
1211
1212 proto_ldap_dir_ctx *dir_ctx;
1213
1214 if (ldap_conn->fd < 0) {
1215 connection_failed:
1216 if (fr_timer_in(thread, thread->el->tl, &thread->conn_retry_ev,
1217 inst->conn_conf.reconnection_delay,
1218 false, proto_ldap_connection_init, listen) < 0) {
1219 FATAL("Failed inserting event: %s", fr_strerror());
1220 }
1221 return;
1222 }
1223
1224 thread->li->fd = ldap_conn->fd;
1225
1226 MEM(dir_ctx = talloc_zero(inst, proto_ldap_dir_ctx));
1227 if (!dir_ctx) goto connection_failed;
1228
1229 dir_ctx->main_listen = listen;
1230 dir_ctx->conn = conn;
1231 dir_ctx->child_listen = thread->li;
1232
1233#ifdef SO_RCVBUF
1234 if (inst->recv_buff_is_set) {
1235 int opt;
1236
1237 opt = inst->recv_buff;
1238 if (setsockopt(ldap_conn->fd, SOL_SOCKET, SO_RCVBUF, &opt, sizeof(int)) < 0) {
1239 WARN("Failed setting 'recv_buff': %s", fr_syserror(errno));
1240 }
1241 }
1242#endif
1243
1244 /*
1245 * Set the callback which will handle the results of this query
1246 */
1247 if (fr_event_fd_insert(conn, NULL, conn->el, ldap_conn->fd,
1249 NULL,
1251 dir_ctx) < 0) {
1252 goto connection_failed;
1253 }
1254
1255 /*
1256 * Allocate the directory structure and send the query
1257 */
1258 dir_ctx->msgid = fr_ldap_conn_directory_alloc_async(ldap_conn);
1259 if (dir_ctx->msgid < 0) {
1260 talloc_free(dir_ctx);
1261 goto connection_failed;
1262 }
1263
1264 /*
1265 * Add a watch to catch closed LDAP connections
1266 */
1268 _proto_ldap_socket_closed, true, listen);
1269}
1270
1271/** Callback triggered when parent listener app_io has its event list set
1272 *
1273 * Initiates the actual outbound LDAP connection
1274 *
1275 * @param[in] li The parent listener.
1276 * @param[in] el Event list for this listener.
1277 * @param[in] nr Network handler.
1278 */
1280{
1284
1285 /*
1286 * Set up thread data
1287 */
1288 thread->name = inst->handle_config.name;
1289 thread->parent = li;
1290 thread->el = el;
1291 thread->nr = nr;
1292 thread->inst = inst;
1293
1294 /*
1295 * The I/O path for the connection. Each connection made,
1296 * and re-made, is a socket of this one listener. It uses
1297 * the app from the parent listener to reach the encoder
1298 * and decoder.
1299 */
1300 MEM(thread->child_listen = fr_listen_alloc(thread, li->listen->cs, inst->parent->server_cs,
1301 li->listen->app, li->listen->app_instance,
1302 &proto_ldap_sync_child, NULL));
1304
1305 /*
1306 * Initialise the connection
1307 */
1309}
1310
1311static int mod_instantiate(module_inst_ctx_t const *mctx)
1312{
1313 proto_ldap_sync_ldap_t *inst = talloc_get_type_abort(mctx->mi->data, proto_ldap_sync_ldap_t);
1314 CONF_SECTION *conf = mctx->mi->conf;
1315 char const *server;
1316
1317 /*
1318 * Verify that the LDAP server configuration is valid, either
1319 * distinct server and port or an LDAP url.
1320 */
1321 fr_assert(inst->server);
1322
1323 inst->parent = talloc_get_type_abort(mctx->mi->parent->data, proto_ldap_sync_t);
1324 inst->cs = conf;
1325
1326 if (inst->recv_buff_is_set) {
1327 FR_INTEGER_BOUND_CHECK("recv_buff", inst->recv_buff, >=, 32);
1328 FR_INTEGER_BOUND_CHECK("recv_buff", inst->recv_buff, <=, INT_MAX);
1329 }
1330
1331 server = inst->server;
1332 inst->handle_config.server = talloc_strdup(inst, "");
1333
1334 if (ldap_is_ldap_url(server)) {
1335 if (fr_ldap_server_url_check(&inst->handle_config, server, conf) < 0) return -1;
1336 } else {
1337 if (fr_ldap_server_config_check(&inst->handle_config, server, conf) < 0) return -1;
1338 }
1339
1340 inst->handle_config.server[talloc_strlen(inst->handle_config.server)] = '\0';
1341
1342 inst->handle_config.name = talloc_typed_asprintf(inst, "proto_ldap_conn (%s)",
1344
1345 return 0;
1346}
1347
1349 .common = {
1350 .magic = MODULE_MAGIC_INIT,
1351 .name = "ldap_sync_child"
1352 },
1356
1357 .default_message_size = 4096,
1358 .track_duplicates = false,
1359};
1360
1362 .common = {
1363 .magic = MODULE_MAGIC_INIT,
1364 .name = "ldap_sync_ldap",
1366 .inst_size = sizeof(proto_ldap_sync_ldap_t),
1367 .thread_inst_size = sizeof(proto_ldap_sync_ldap_thread_t),
1368 .instantiate = mod_instantiate
1369 },
1370
1371 .default_message_size = 4096,
1372 .track_duplicates = false,
1373
1374 .event_list_set = mod_event_list_set,
1375};
int active_directory_sync_state_init(fr_ldap_connection_t *conn, size_t sync_no, proto_ldap_sync_t const *inst, UNUSED uint8_t const *cookie)
Allocate a sync state structure and issue the search.
int active_directory_sync_search_entry(sync_state_t *sync, LDAPMessage *msg, UNUSED LDAPControl **ctrls)
Handle a LDAP_RES_SEARCH_ENTRY (SearchResultEntry) response.
static int const char char buffer[256]
Definition acutest.h:641
log_entry msg
Definition acutest.h:947
module_t common
Common fields to all loadable modules.
Definition app_io.h:34
size_t default_message_size
Usually maximum message size.
Definition app_io.h:39
Public structure describing an I/O path for a protocol.
Definition app_io.h:33
static int packet_ctx
the tests pass only the address of packet_ctx
#define USES_APPLE_DEPRECATED_API
Definition build.h:590
#define L(_str)
Helper for initialising arrays of string literals.
Definition build.h:245
#define CMP(_a, _b)
Same as CMP_PREFER_SMALLER use when you don't really care about ordering, you just want an ordering.
Definition build.h:130
#define unlikely(_x)
Definition build.h:486
#define UNUSED
Definition build.h:415
#define NUM_ELEMENTS(_t)
Definition build.h:437
fr_cmp_ret_t
Result of an ordering comparison.
Definition build.h:113
cf_time_delta_bounds_t const cf_time_delta_bounds_int_msec
Bounds which keep a time delta within an int of milliseconds, for libraries which take one.
Definition cf_parse.c:1885
int cf_parse_time_delta_bounded(TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
Parse a time delta, and force it within the bounds passed as the rule's uctx.
Definition cf_parse.c:1909
#define CONF_PARSER_TERMINATOR
Definition cf_parse.h:722
cf_parse_t func
Override default parsing behaviour for the specified type with a custom parsing function.
Definition cf_parse.h:666
#define FR_INTEGER_BOUND_CHECK(_name, _var, _op, _bound)
Definition cf_parse.h:572
#define FR_CONF_OFFSET(_name, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
Definition cf_parse.h:280
@ CONF_FLAG_REQUIRED
Error out if no matching CONF_PAIR is found, and no dflt value is set.
Definition cf_parse.h:466
#define FR_CONF_OFFSET_IS_SET(_name, _type, _flags, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct,...
Definition cf_parse.h:294
#define FR_CONF_OFFSET_FLAGS(_name, _flags, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
Definition cf_parse.h:268
#define FR_CONF_OFFSET_SUBSECTION(_name, _flags, _struct, _field, _subcs)
conf_parser_t which populates a sub-struct using a CONF_SECTION
Definition cf_parse.h:309
Defines a CONF_PAIR to C data type mapping.
Definition cf_parse.h:649
A section grouping multiple CONF_PAIR.
Definition cf_priv.h:106
CONF_SECTION * cf_item_to_section(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_SECTION.
Definition cf_util.c:671
char const * cf_section_name(CONF_SECTION const *cs)
Return name2 if set, else name1.
Definition cf_util.c:1417
#define cf_parent(_cf)
Definition cf_util.h:115
static uint64_t max_outstanding
#define fr_dbuff_used(_dbuff_or_marker)
Return the number of bytes remaining between the start of the dbuff or marker and the current positio...
Definition dbuff.h:819
#define fr_dbuff_init(_out, _start, _len_or_end)
Initialise an dbuff for encoding or decoding.
Definition dbuff.h:387
#define fr_dbuff_buff(_dbuff_or_marker)
Return the underlying buffer in a dbuff or one of marker.
Definition dbuff.h:934
#define FR_DBUFF_TALLOC_THREAD_LOCAL(_out, _init, _max)
Create a function local and thread local extensible dbuff.
Definition dbuff.h:598
#define MEM(x)
Definition debug.h:38
#define ERROR(fmt,...)
Definition dhcpclient.c:40
fr_dict_attr_t const * fr_dict_root(fr_dict_t const *dict)
Return the root attribute of a dictionary.
Definition dict_util.c:2717
fr_dict_attr_t const ** out
Where to write a pointer to the resolved fr_dict_attr_t.
Definition dict.h:316
fr_dict_t const ** out
Where to write a pointer to the loaded/resolved fr_dict_t.
Definition dict.h:329
#define DICT_AUTOLOAD_TERMINATOR
Definition dict.h:335
Specifies an attribute which must be present for the module to function.
Definition dict.h:315
Specifies a dictionary which must be loaded/loadable for the module to function.
Definition dict.h:328
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
Definition dl_module.h:63
static void * fr_dlist_head(fr_dlist_head_t const *list_head)
Return the HEAD item of a list or NULL if the list is empty.
Definition dlist.h:468
static void * fr_dlist_pop_head(fr_dlist_head_t *list_head)
Remove the head item in a list.
Definition dlist.h:654
static int fr_dlist_insert_tail(fr_dlist_head_t *list_head, void *ptr)
Insert an item into the tail of a list.
Definition dlist.h:360
#define fr_dlist_talloc_init(_head, _type, _field)
Initialise the head structure of a doubly linked list.
Definition dlist.h:257
static void * fr_dlist_next(fr_dlist_head_t const *list_head, void const *ptr)
Get the next item in a list.
Definition dlist.h:537
#define fr_event_fd_insert(...)
Definition event.h:247
@ FR_EVENT_FILTER_IO
Combined filter for read/write functions/.
Definition event.h:83
#define GLOBAL_LIB_TERMINATOR
Definition global_lib.h:51
Structure to define how to initialise libraries with global configuration.
Definition global_lib.h:38
talloc_free(hp)
bool allow_name_only
Allow name only pairs.
Definition internal.h:36
unlang_interpret_t * unlang_interpret_get_thread_default(void)
Get the default interpreter for this thread.
Definition interpret.c:2801
ssize_t fr_network_listen_outstanding(fr_network_t *nr, fr_listen_instance_t *li)
Get the number of outstanding packets.
Definition network.c:778
int fr_network_listen_send_packet(fr_network_t *nr, fr_listen_instance_t *parent, fr_listen_instance_t *li, const uint8_t *buffer, size_t buflen, fr_time_t recv_time, void *packet_ctx)
Send a packet to the worker.
Definition network.c:736
int fr_network_listen_add(fr_network_t *nr, fr_listen_instance_t *li)
Add a fr_listen_instance_t to a network.
Definition network.c:199
int fr_ldap_conn_directory_alloc_async(fr_ldap_connection_t *ldap_conn)
Asynchronously extract useful information from the rootDSE of the LDAP server.
Definition directory.c:447
fr_ldap_sync_type_t sync_type
What kind of LDAP sync this directory supports.
Definition base.h:211
LDAP * handle
libldap handle.
Definition base.h:327
fr_ldap_directory_t * directory
The type of directory we're connected to.
Definition base.h:336
int fd
File descriptor for this connection.
Definition base.h:343
void fr_ldap_state_error(fr_ldap_connection_t *c)
Signal that there's been an error on the connection.
Definition state.c:153
int fr_ldap_server_url_check(fr_ldap_config_t *handle_config, char const *server, CONF_SECTION const *cs)
Check an LDAP server entry in URL format is valid.
Definition util.c:998
fr_ldap_config_t const * config
rlm_ldap connection configuration.
Definition base.h:338
int fr_ldap_server_config_check(fr_ldap_config_t *handle_config, char const *server, CONF_SECTION *cs)
Check an LDAP server config in server:port format is valid.
Definition util.c:1095
char const * name
Name of the module that created this connection.
Definition base.h:231
int fr_ldap_directory_result_parse(fr_ldap_directory_t *directory, LDAP *handle, LDAPMessage *result, char const *name)
Definition directory.c:68
void * uctx
User data associated with the handle.
Definition base.h:348
fr_ldap_rcode_t
Codes returned by fr_ldap internal functions.
Definition base.h:567
@ LDAP_PROC_SUCCESS
Operation was successful.
Definition base.h:572
@ LDAP_PROC_BAD_CONN
Transitory error, caller should retry the operation with a new connection.
Definition base.h:576
@ LDAP_PROC_PENDING
fr_ldap_result() was polling and hasn't read the final message yet.
Definition base.h:568
@ LDAP_PROC_REFRESH_REQUIRED
Don't continue with the current refresh phase, exit, and retry the operation with a NULL cookie.
Definition base.h:591
@ FR_LDAP_SYNC_NONE
No support for LDAP sync.
Definition base.h:157
@ FR_LDAP_SYNC_ACTIVE_DIRECTORY
Directory supports AD style persistent search.
Definition base.h:159
@ FR_LDAP_SYNC_PERSISTENT_SEARCH
Directory supports persistent search.
Definition base.h:160
@ FR_LDAP_SYNC_RFC4533
Directory supports RFC 4533.
Definition base.h:158
connection_t * conn
Connection state handle.
Definition base.h:339
char const ** naming_contexts
NULL terminated array of databases served by this directory.
Definition base.h:217
Tracks the state of a libldap connection handle.
Definition base.h:326
#define FR_LDAP_COMMON_CONF(_conf)
Definition conf.h:19
fr_ldap_rcode_t fr_ldap_error_check(LDAPControl ***ctrls, fr_ldap_connection_t const *conn, LDAPMessage *msg, char const *dn)
Perform basic parsing of multiple types of messages, checking for error conditions.
Definition base.c:174
LDAP * fr_ldap_handle_thread_local(void)
Get a thread local dummy LDAP handle.
Definition base.c:1104
global_lib_autoinst_t fr_libldap_global_config
Definition base.c:134
fr_ldap_rcode_t fr_ldap_result(LDAPMessage **result, LDAPControl ***ctrls, fr_ldap_connection_t const *conn, int msgid, int all, char const *dn, fr_time_delta_t timeout)
Parse response from LDAP server dealing with any errors.
Definition base.c:409
#define PERROR(_fmt,...)
Definition log.h:233
#define FATAL(_fmt,...)
Definition log.h:229
#define DEBUG3(_fmt,...)
Definition log.h:271
fr_time_t fr_event_list_time(fr_event_list_t *el)
Get the current server time according to the event list.
Definition event.c:581
#define fr_time()
Definition event.c:58
bool fr_event_loop_exiting(fr_event_list_t *el)
Check to see whether the event loop is in the process of exiting.
Definition event.c:2434
int fr_event_fd_delete(fr_event_list_t *el, int fd, fr_event_filter_t filter)
Remove a file descriptor from the event loop.
Definition event.c:1204
Stores all information relating to an event list.
Definition event.c:375
fr_listen_t * fr_listen_alloc(TALLOC_CTX *ctx, CONF_SECTION *listen_cs, CONF_SECTION *server_cs, fr_app_t const *app, void const *app_instance, fr_app_io_t const *app_io, void const *app_io_instance)
Allocate a listener, and give it its id.
Definition listen.c:78
fr_listen_instance_t * fr_listen_instance_alloc(TALLOC_CTX *ctx, fr_listen_t *listen)
Allocate a socket of a listener.
Definition listen.c:111
char const * name
printable name for this socket - set by open
Definition listen.h:68
fr_listen_t * listen
the listener this is a socket of.
Definition listen.h:65
int fd
file descriptor for this socket - set by open
Definition listen.h:67
fr_app_io_t const * app_io
I/O path functions.
Definition listen.h:33
fr_app_t const * app
Definition listen.h:36
void const * app_instance
Definition listen.h:37
void const * app_io_instance
I/O path configuration context.
Definition listen.h:34
CONF_SECTION * cs
of this listener
Definition listen.h:39
void * thread_instance
thread / socket context
Definition listen.h:69
size_t default_message_size
copied from app_io, but may be changed
Definition listen.h:53
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_UINT32
32 Bit unsigned integer.
@ FR_TYPE_OCTETS
Raw octets.
unsigned int uint32_t
long int ssize_t
unsigned char uint8_t
int strncasecmp(char *s1, char *s2, int n)
Definition missing.c:35
module_instance_t * mi
Instance of the module being instantiated.
Definition module_ctx.h:51
Temporary structure to hold arguments for instantiation calls.
Definition module_ctx.h:50
int fr_pair_list_copy(TALLOC_CTX *ctx, fr_pair_list_t *to, fr_pair_list_t const *from)
Duplicate a list of pairs.
Definition pair.c:2312
fr_pair_t * fr_pair_find_by_da_nested(fr_pair_list_t const *list, fr_dict_attr_t const *da)
Find a pair with a matching fr_dict_attr_t, by walking the nested fr_dict_attr_t tree.
Definition pair.c:791
fr_pair_t * fr_pair_find_by_da(fr_pair_list_t const *list, fr_pair_t const *prev, fr_dict_attr_t const *da)
Find the first pair with a matching da.
Definition pair.c:716
void fr_pair_list_init(fr_pair_list_t *list)
Initialise a pair list header.
Definition pair.c:47
int persistent_sync_search_entry(sync_state_t *sync, LDAPMessage *msg, LDAPControl **ctrls)
Handle a SearchResultEntry response from Persistent Search LDAP servers.
int persistent_sync_state_init(fr_ldap_connection_t *conn, size_t sync_no, proto_ldap_sync_t const *inst, UNUSED uint8_t const *cookie)
Allocate and initialise sync queries for persistent searches.
static const conf_parser_t config[]
Definition base.c:162
char const * filter
Filter to retrieve only user objects.
fr_timer_t * ev
Event for retrying cookie load.
sync_config_t ** sync_config
DNs and filters to monitor.
int(* sync_msg_t)(sync_state_t *sync, LDAPMessage *msg, LDAPControl **ctrls)
Received an LDAP message related to a sync.
char const * base_dn
DN to search for users under.
sync_msg_t entry
Called when we receive a searchEntry message.
sync_msg_t refresh
Called when we receive a eSyncRefreshRequired code.
CONF_SECTION * cs
Config section where this sync was defined.
sync_msg_t intermediate
Called when we receive a syncIntermediate message.
map_list_t entry_map
How to convert attributes in entries to FreeRADIUS attributes.
fr_pair_list_t sync_pairs
Pairs representing the sync config sent to the worker with each request.
fr_time_delta_t cookie_interval
Interval between storing cookies.
sync_op_t
Operations to perform on entries.
@ SYNC_OP_ADD
Entry should be added to our copy.
@ SYNC_OP_MODIFY
Entry should be updated in our copy.
@ SYNC_OP_DELETE
Entry should be deleted from our copy.
@ SYNC_OP_PRESENT
Entry is present and unchanged on the server.
uint32_t cookie_changes
Number of LDAP changes to process between each cookie store operation.
fr_time_delta_t retry_interval
Interval between retrying failed change packets.
void * user_ctx
User ctx to pass to the callbacks.
An instance of a proto_ldap_sync listen section.
Areas of the directory to receive notifications for.
fr_listen_instance_t * main_listen
int ldap_sync_cookie_send(sync_packet_ctx_t *sync_packet_ctx)
Enqueue a new cookie store packet.
fr_app_io_t proto_ldap_sync_ldap
static conf_parser_t const proto_ldap_sync_ldap_connection_config[]
static void _proto_ldap_socket_closed(UNUSED connection_t *conn, connection_state_t prev, UNUSED connection_state_t state, void *uctx)
Callback for closure of LDAP connection.
static fr_dict_attr_t const * attr_packet_type
static fr_ldap_sync_packet_code_t const sync_packet_code_table[4]
static int proto_ldap_cookie_load_send(TALLOC_CTX *ctx, proto_ldap_sync_ldap_t const *inst, size_t sync_no, proto_ldap_sync_ldap_thread_t *thread)
Send a fake packet to run the "load Cookie" section.
global_lib_autoinst_t const * proto_ldap_sync_ldap_lib[]
static int proto_ldap_child_mod_close(fr_listen_instance_t *li)
Child listener mod_close.
static fr_dict_attr_t const * attr_ldap_sync_packet_id
static void ldap_sync_retry_event(fr_timer_list_t *tl, UNUSED fr_time_t now, void *uctx)
Event to handle sending of any change packets which failed to send.
static fr_dict_t const * dict_ldap_sync
proto_ldap_sync_ldap_t const * inst
static ssize_t proto_ldap_child_mod_read(fr_listen_instance_t *li, UNUSED void **packet_ctx, UNUSED fr_time_t *recv_time_p, UNUSED uint8_t *buffer, UNUSED size_t buffer_len, UNUSED size_t *leftover)
LDAP sync mod_read for child listener.
static fr_dict_attr_t const * attr_ldap_sync_entry_dn
int ldap_sync_cookie_store(sync_state_t *sync, bool refresh)
Add a new cookie packet ctx to the pending list.
static int sync_state_free(sync_state_t *sync)
Tell the remote server to stop the sync.
static fr_dict_t const * dict_freeradius
static fr_dict_attr_t const * attr_ldap_sync_base_dn
void ldap_sync_cookie_event(fr_timer_list_t *tl, UNUSED fr_time_t now, void *uctx)
Event to handle storing of cookies on a timed basis.
static fr_dict_attr_t const * attr_ldap_sync_orig_dn
static ssize_t proto_ldap_child_mod_write(fr_listen_instance_t *li, void *packet_ctx, UNUSED fr_time_t request_time, uint8_t *buffer, size_t buffer_len, UNUSED size_t written)
LDAP sync mod_write for child listener.
fr_app_io_t proto_ldap_sync_child
static conf_parser_t const proto_ldap_sync_ldap_config[]
static void _proto_ldap_socket_open_error(UNUSED fr_event_list_t *el, UNUSED int fd, UNUSED int flags, UNUSED int fd_errno, void *uctx)
Callback for socket errors when running initial root query.
int ldap_sync_entry_send(sync_state_t *sync, uint8_t const uuid[SYNC_UUID_LENGTH], struct berval *orig_dn, LDAPMessage *msg, sync_op_t op)
Enqueue a new entry change packet.
size_t sync_op_table_len
fr_table_num_sorted_t const sync_op_table[]
Operations performed on entries.
static fr_dict_attr_t const * attr_ldap_sync_root_dn
static void mod_event_list_set(fr_listen_instance_t *li, fr_event_list_t *el, void *nr)
Callback triggered when parent listener app_io has its event list set.
static fr_internal_encode_ctx_t encode_ctx
static int ldap_sync_entry_send_network(sync_packet_ctx_t *sync_packet_ctx)
Send a change packet to the workers.
static void proto_ldap_connection_init(fr_timer_list_t *tl, UNUSED fr_time_t now, void *user_ctx)
Attempt to (re)initialise a connection.
static fr_dict_attr_t const * attr_ldap_sync_entry_uuid
static void _proto_ldap_socket_init(connection_t *conn, UNUSED connection_state_t prev, UNUSED connection_state_t state, void *uctx)
Allocate a child listener.
sync_state_t * sync_state_alloc(TALLOC_CTX *ctx, fr_ldap_connection_t *conn, proto_ldap_sync_t const *inst, size_t sync_no, sync_config_t const *config)
Allocate a sync state.
fr_dict_attr_autoload_t proto_ldap_sync_ldap_dict_attr[]
fr_cmp_ret_t sync_state_cmp(void const *one, void const *two)
Compare two sync state structures on msgid.
fr_listen_instance_t * child_listen
static void proto_ldap_cookie_load_retry(fr_timer_list_t *tl, UNUSED fr_time_t now, void *uctx)
Timer event to retry running "load Cookie" on failures.
static fr_dict_attr_t const * attr_ldap_sync_cookie
proto_ldap_sync_ldap_thread_t * thread
fr_dict_autoload_t proto_ldap_sync_ldap_dict[]
static int mod_instantiate(module_inst_ctx_t const *mctx)
static void _proto_ldap_socket_open_read(fr_event_list_t *el, int fd, UNUSED int flags, void *uctx)
Callback to process results of initial root query, identifying directory type.
static void _proto_ldap_socket_open_connected(connection_t *conn, UNUSED connection_state_t prev, UNUSED connection_state_t state, void *uctx)
Query an LDAP server to establish its type.
Context used when looking up Directory types.
fr_listen_t * child_listen
I/O path, every connection made is a socket of it.
@ SYNC_PACKET_TYPE_CHANGE
Packet is an entry change.
@ SYNC_PACKET_TYPE_COOKIE
uint32_t pending_cookies
How many cookies are in the pending heap.
uint8_t * cookie
Opaque cookie, used to resume synchronisation.
size_t sync_no
Array position of config for this sync.
sync_phases_t phase
Phase this sync is in.
uint32_t max_outstanding
Maximum number of outstanding packets.
int msgid
The unique identifier for this sync session.
uint8_t * cookie
Cookie to store - can be NULL.
fr_timer_t * retry_ev
Timer event for retrying failed changes.
fr_pair_list_t pairs
Pairs to send with change packets.
fr_dlist_head_t pending
List of pending changes in progress.
@ SYNC_PACKET_PREPARING
Packet being prepared.
@ SYNC_PACKET_PENDING
Packet not yet sent.
@ SYNC_PACKET_PROCESSING
Packet sent to worker.
@ SYNC_PACKET_COMPLETE
Packet response received from worker.
sync_config_t const * config
Configuration for this sync.
static fr_table_num_sorted_t const sync_ldap_msg_table[]
Types of LDAP messages relevant to LDAP sync.
sync_state_t * sync
Sync packet relates to.
fr_listen_instance_t * parent
master IO handler.
sync_packet_status_t status
Status of this packet.
fr_listen_instance_t * li
Our listener.
fr_timer_t * cookie_ev
Timer event for sending cookies.
connection_t * conn
Our connection to the LDAP directory.
proto_ldap_sync_t const * inst
Module instance for this sync.
connection_conf_t conn_conf
Connect timeout and reconnect delay.
fr_network_t * nr
Network handler.
#define SYNC_UUID_LENGTH
proto_ldap_sync_t * parent
The module that spawned us.
bool refresh
Does the sync require a refresh.
sync_packet_type_t type
Type of packet.
uint32_t changes_since_cookie
How many changes have been added since the last cookie was stored.
fr_ldap_connection_t * conn
Connection the sync is running on.
fr_pair_list_t trigger_args
Arguments to make available in triggers.
@ SYNC_PHASE_INIT
We haven't entered any of the refresh phases.
fr_event_list_t * el
Network side event list.
fr_timer_t * conn_retry_ev
When to retry re-establishing the conn.
proto_ldap_sync_ldap_t const * inst
instance data
Tracking structure for ldap sync packets.
State of an individual sync.
ssize_t fr_internal_decode_list_dbuff(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent, fr_dbuff_t *dbuff, void *decode_ctx)
Retrieve all pairs from the dbuff.
Definition decode.c:316
ssize_t fr_internal_encode_list(fr_dbuff_t *dbuff, fr_pair_list_t const *list, void *encode_ctx)
Encode a list of pairs using the internal encoder.
Definition encode.c:304
#define fr_assert(_expr)
Definition rad_assert.h:37
#define DEBUG2(fmt,...)
#define WARN(fmt,...)
static rs_t * conf
Definition radsniff.c:52
int fr_rb_find(void **found, fr_rb_tree_t const *tree, void const *data)
Find an element in the tree, returning the data, not the node.
Definition rb.c:586
int fr_rb_delete(fr_rb_tree_t *tree, void const *data)
Remove node and free data (if a free function was specified)
Definition rb.c:767
The main red black tree structure.
Definition rb.h:71
int rfc4533_sync_refresh_required(sync_state_t *sync, LDAPMessage *msg, LDAPControl **ctrls)
Handle result code of e-syncRefreshRequired.
Definition rfc4533.c:719
int rfc4533_sync_search_entry(sync_state_t *sync, LDAPMessage *msg, LDAPControl **ctrls)
Handle a SearchResultEntry or SearchResultReference response from an RFC 4533 server.
Definition rfc4533.c:260
int rfc4533_sync_init(fr_ldap_connection_t *conn, size_t sync_no, proto_ldap_sync_t const *inst, uint8_t const *cookie)
Allocate and initialise RFC 4533 sync queries.
Definition rfc4533.c:74
int rfc4533_sync_intermediate(sync_state_t *sync, LDAPMessage *msg, UNUSED LDAPControl **ctrls)
Handle a LDAP_RES_INTERMEDIATE (SyncInfo) response.
Definition rfc4533.c:452
void connection_signal_shutdown(connection_t *conn)
Shuts down a connection gracefully.
void connection_signal_halt(connection_t *conn)
Shuts down a connection ungracefully.
void connection_signal_reconnect(connection_t *conn, connection_reason_t reason)
Asynchronously signal the connection should be reconnected.
void connection_signal_init(connection_t *conn)
Asynchronously signal a halted connection to start.
connection_t * connection_alloc(TALLOC_CTX *ctx, fr_event_list_t *el, connection_funcs_t const *funcs, connection_conf_t const *conf, char const *log_prefix, void const *uctx)
Allocate a new connection.
connection_watch_entry_t * connection_add_watch_post(connection_t *conn, connection_state_t state, connection_watch_t watch, bool oneshot, void const *uctx)
Add a callback to be executed after a state function has been called.
Definition connection.c:517
@ CONNECTION_FAILED
Connection is being reconnected because it failed.
Definition connection.h:89
connection_state_t
Definition connection.h:47
@ CONNECTION_STATE_CLOSED
Connection has been closed.
Definition connection.h:57
@ CONNECTION_STATE_CONNECTED
File descriptor is open (ready for writing).
Definition connection.h:54
@ CONNECTION_STATE_INIT
Init state, sets up connection.
Definition connection.h:51
fr_time_delta_t reconnection_delay
How long to wait after failures.
Definition connection.h:99
Holds a complete set of functions for a connection.
Definition connection.h:199
CONF_SECTION * conf
Module's instance configuration.
Definition module.h:355
void * data
Module's instance data.
Definition module.h:297
module_instance_t const * parent
Parent module's instance (if any).
Definition module.h:363
conf_parser_t const * config
How to convert a CONF_SECTION to a module instance.
Definition module.h:207
int pair_append_by_tmpl_parent(TALLOC_CTX *ctx, fr_pair_t **out, fr_pair_list_t *list, tmpl_t const *vpt, bool skip_list))
Allocate and insert a leaf vp from a tmpl_t, building the parent vps if needed.
Definition tmpl_eval.c:863
return count
Definition module.c:155
eap_aka_sim_process_conf_t * inst
fr_aka_sim_id_type_t type
fr_pair_t * vp
Value pair map.
Definition map.h:77
fr_token_t op
The operator that controls insertion of the dst attribute.
Definition map.h:82
tmpl_t * lhs
Typically describes the attribute to add, modify or compare.
Definition map.h:78
tmpl_t * rhs
Typically describes a literal value or a src attribute to copy or compare.
Definition map.h:79
Stores an attribute, a value and various bits of other data.
Definition pair.h:68
fr_ldap_sync_packet_code_t
Types of the internal packets for processing LDAP sync messages.
Definition sync.h:31
@ 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_MODIFY
Object has been modified.
Definition sync.h:38
char const * fr_syserror(int num)
Guaranteed to be thread-safe version of strerror.
Definition syserror.c:243
#define fr_table_str_by_value(_table, _number, _def)
Convert an integer to a string.
Definition table.h:804
An element in a lexicographically sorted array of name to num mappings.
Definition table.h:49
char * talloc_typed_asprintf(TALLOC_CTX *ctx, char const *fmt,...)
Call talloc vasprintf, setting the type on the new chunk correctly.
Definition talloc.c:621
#define talloc_get_type_abort_const
Definition talloc.h:117
static size_t talloc_str_array_len(char const *const *strings)
Return the number of strings a NULL terminated string array was sized for.
Definition talloc.h:280
#define talloc_strdup(_ctx, _str)
Definition talloc.h:149
static size_t talloc_strlen(char const *s)
Returns the length of a talloc array containing a string.
Definition talloc.h:143
static fr_time_delta_t fr_time_delta_from_msec(int64_t msec)
Definition time.h:584
"server local" time.
Definition time.h:69
An event timer list.
Definition timer.c:65
#define fr_timer_in(...)
Definition timer.h:87
@ T_OP_ADD_EQ
Definition token.h:67
int trigger(unlang_interpret_t *intp, CONF_SECTION const *cs, CONF_PAIR **trigger_cp, char const *name, bool rate_limit, fr_pair_list_t *args, void const *uctx)
Execute a trigger - call an executable to process an event.
Definition trigger.c:160
static fr_event_list_t * el
#define fr_pair_list_append_by_da_len(_ctx, _vp, _list, _attr, _val, _len, _tainted)
Append a pair to a list, assigning its value.
Definition pair.h:333
fr_pair_t * fr_pair_remove(fr_pair_list_t *list, fr_pair_t *vp)
Remove fr_pair_t from a list without freeing.
Definition pair_inline.c:93
void fr_pair_list_free(fr_pair_list_t *list)
Free memory used by a valuepair list.
#define fr_pair_list_append_by_da(_ctx, _vp, _list, _attr, _val, _tainted)
Append a pair to a list, assigning its value.
Definition pair.h:310
#define fr_pair_list_append_by_da_parent_len(_ctx, _vp, _list, _attr, _val, _len, _tainted)
Definition pair.h:355
char const * fr_strerror(void)
Get the last library error.
Definition strerror.c:558
fr_slen_t fr_value_box_from_str(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_type_t dst_type, fr_dict_attr_t const *dst_enumv, char const *in, size_t inlen, fr_sbuff_unescape_rules_t const *erules)
Definition value.c:6256
static fr_sbuff_err_t char size_t * len
Definition value.h:1061
#define fr_box_time_delta(_val)
Definition value.h:397