The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
proto_ldap_sync_ldap.h
Go to the documentation of this file.
1 # pragma once
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16  */
17 
18 /*
19  * $Id: 05a4f0d1c77ead6b6bda4cc51dd548ceda2ba431 $
20  *
21  * @file proto_ldap_sync_ldap.h
22  * @brief Callback routines for the LDAP Sync protocol
23  *
24  * @copyright 2022 Network RADIUS SAS (legal@networkradius.com)
25  */
27 
28 #include "proto_ldap_sync.h"
29 #include <lber.h>
30 
31 #define SYNC_UUID_LENGTH 16
32 
33 /** Phases of the initial refresh stage for RFC 4533 servers
34  */
35 typedef enum {
36  SYNC_PHASE_INIT = 0, //!< We haven't entered any of the refresh phases.
37  SYNC_PHASE_PRESENT = 1, //!< Currently in the present phase.
38  SYNC_PHASE_DELETE = 2, //!< Currently in the delete phase.
39  SYNC_PHASE_DONE = 3 //!< Refresh phase is complete.
41 
42 /** State of an individual sync
43  */
44 struct sync_state_s {
45  fr_rb_node_t node; //!< Entry in the tree of nodes.
46 
47  fr_ldap_connection_t *conn; //!< Connection the sync is running on.
48 
49  sync_config_t const *config; //!< Configuration for this sync
50 
51  int msgid; //!< The unique identifier for this sync session.
52 
53  size_t sync_no; //!< Array position of config for this sync.
54 
55  uint8_t *cookie; //!< Opaque cookie, used to resume synchronisation.
56 
57  sync_phases_t phase; //!< Phase this sync is in.
58 
59  fr_dlist_head_t *filter; //!< Parsed filter to be applied on the network side
60  //!< before passing packets to the worker.
61  //!< Predominantly to overcome Active Directory's lack
62  //!< of filtering in persistent searches.
63 
64  proto_ldap_sync_t const *inst; //!< Module instance for this sync.
65 
66  fr_dlist_head_t pending; //!< List of pending changes in progress.
67 
68  uint32_t pending_cookies; //!< How many cookies are in the pending heap
69  uint32_t changes_since_cookie; //!< How many changes have been added since
70  //!< the last cookie was stored.
71 
72  fr_event_timer_t const *cookie_ev; //!< Timer event for sending cookies.
73  fr_event_timer_t const *retry_ev; //!< Timer event for retrying failed changes.
74 
75  fr_pair_list_t trigger_args; //!< Arguments to make available in triggers.
76 };
77 
78 typedef struct sync_state_s sync_state_t;
79 
80 /** Types of LDAP messages relevant to LDAP sync
81  */
83  { L("intermediateResponse"), LDAP_RES_INTERMEDIATE },
84  { L("searchRes"), LDAP_RES_SEARCH_RESULT },
85  { L("searchResEntry"), LDAP_RES_SEARCH_ENTRY },
86  { L("searchResReference"), LDAP_RES_SEARCH_REFERENCE }
87 };
89 
90 typedef struct {
91  CONF_SECTION *cs; //!< our configuration
92 
93  proto_ldap_sync_t *parent; //!< The module that spawned us.
94 
95  fr_ldap_config_t handle_config; //!< Connection configuration instance
96 
97  char const *server; //!< Server string from the config. LDAP sync needs to
98  //!< remain against a single server so this is used rather
99  //!< than the server_str array in fr_ldap_config_t.
100 
101  char const *tls_random_file; //!< Path to the random file if /dev/random
102  //!< and /dev/urandom are unavailable.
103 
104  uint32_t ldap_debug; //!< Debug flag for the SDK.
105 
106  uint32_t recv_buff; //!< How big the kernel's receive buffer should be
107  bool recv_buff_is_set; //!< Whether we were provided with a recv_buff
108 
109  uint32_t max_outstanding; //!< Maximum number of outstanding packets.
111 
112 typedef struct {
113  char const *name; //!< socket name
114  proto_ldap_sync_ldap_t const *inst; //!< instance data
115 
116  fr_event_list_t *el; //!< Network side event list.
117  fr_network_t *nr; //!< Network handler.
118  fr_listen_t *parent; //!< master IO handler.
119  fr_listen_t *li; //!< Our listener.
120 
121  fr_event_timer_t const *conn_retry_ev; //!< When to retry re-establishing the conn.
122 
123  fr_connection_t *conn; //!< Our connection to the LDAP directory.
125 
126 typedef enum {
127  SYNC_PACKET_PENDING = 0, //!< Packet not yet sent.
128  SYNC_PACKET_PREPARING, //!< Packet being prepared.
129  SYNC_PACKET_PROCESSING, //!< Packet sent to worker.
130  SYNC_PACKET_COMPLETE, //!< Packet response received from worker.
132 
133 typedef enum {
134  SYNC_PACKET_TYPE_CHANGE = 0, //!< Packet is an entry change.
137 
138 /** Tracking structure for ldap sync packets
139  */
141  sync_packet_type_t type; //!< Type of packet.
142  sync_packet_status_t status; //!< Status of this packet.
143  sync_state_t *sync; //!< Sync packet relates to.
144 
145  fr_pair_list_t pairs; //!< Pairs to send with change packets.
146 
147  uint8_t *cookie; //!< Cookie to store - can be NULL.
148  bool refresh; //!< Does the sync require a refresh.
149 
150  fr_dlist_t entry; //!< Entry in list of pending packets.
151 };
152 
153 typedef struct sync_packet_ctx_s sync_packet_ctx_t;
154 
155 extern fr_table_num_sorted_t const sync_op_table[];
156 extern size_t sync_op_table_len;
157 
158 int8_t sync_state_cmp(void const *one, void const *two);
159 
161  size_t sync_no, sync_config_t const *config);
162 
164 
166 
167 int ldap_sync_cookie_send(sync_packet_ctx_t *sync_packet_ctx);
168 
169 int ldap_sync_entry_send(sync_state_t *sync, uint8_t const uuid[SYNC_UUID_LENGTH], struct berval *orig_dn,
170  LDAPMessage *msg, sync_op_t op);
log_entry msg
Definition: acutest.h:794
#define USES_APPLE_DEPRECATED_API
Definition: build.h:431
#define L(_str)
Helper for initialising arrays of string literals.
Definition: build.h:207
#define NUM_ELEMENTS(_t)
Definition: build.h:335
A section grouping multiple CONF_PAIR.
Definition: cf_priv.h:89
Head of a doubly linked list.
Definition: dlist.h:51
Entry in a doubly linked list.
Definition: dlist.h:41
Connection configuration.
Definition: base.h:219
Tracks the state of a libldap connection handle.
Definition: base.h:330
Stores all information relating to an event list.
Definition: event.c:411
A timer event.
Definition: event.c:102
unsigned int uint32_t
Definition: merged_model.c:33
unsigned char uint8_t
Definition: merged_model.c:30
static const conf_parser_t config[]
Definition: base.c:188
sync_op_t
Operations to perform on entries.
An instance of a proto_ldap_sync listen section.
Areas of the directory to receive notifications for.
int ldap_sync_cookie_send(sync_packet_ctx_t *sync_packet_ctx)
Enqueue a new cookie store packet.
fr_dlist_head_t * filter
Parsed filter to be applied on the network side before passing packets to the worker.
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_packet_type_t
@ SYNC_PACKET_TYPE_CHANGE
Packet is an entry change.
@ SYNC_PACKET_TYPE_COOKIE
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.
fr_connection_t * conn
Our connection to the LDAP directory.
uint8_t * cookie
Cookie to store - can be NULL.
uint32_t ldap_debug
Debug flag for the SDK.
fr_pair_list_t pairs
Pairs to send with change packets.
char const * tls_random_file
Path to the random file if /dev/random and /dev/urandom are unavailable.
fr_dlist_head_t pending
List of pending changes in progress.
static size_t const sync_ldap_msg_table_len
int ldap_sync_cookie_store(sync_state_t *sync, bool refresh)
Add a new cookie packet ctx to the pending list.
void ldap_sync_cookie_event(fr_event_list_t *el, fr_time_t now, void *uctx)
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_dlist_t entry
Entry in list of pending packets.
fr_rb_node_t node
Entry in the tree of nodes.
sync_packet_status_t status
Status of this packet.
fr_event_timer_t const * conn_retry_ev
When to retry re-establishing the conn.
sync_packet_status_t
@ 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.
fr_listen_t * li
Our listener.
bool recv_buff_is_set
Whether we were provided with a recv_buff.
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.
proto_ldap_sync_t const * inst
Module instance for this sync.
size_t sync_op_table_len
fr_table_num_sorted_t const sync_op_table[]
Operations performed on entries.
uint32_t recv_buff
How big the kernel's receive buffer should be.
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_ldap_config_t handle_config
Connection configuration instance.
fr_network_t * nr
Network handler.
int8_t sync_state_cmp(void const *one, void const *two)
Compare two sync state structures on msgid.
fr_listen_t * parent
master IO handler.
#define SYNC_UUID_LENGTH
proto_ldap_sync_t * parent
The module that spawned us.
bool refresh
Does the sync require a refresh.
sync_phases_t
Phases of the initial refresh stage for RFC 4533 servers.
@ SYNC_PHASE_DELETE
Currently in the delete phase.
@ SYNC_PHASE_DONE
Refresh phase is complete.
@ SYNC_PHASE_INIT
We haven't entered any of the refresh phases.
@ SYNC_PHASE_PRESENT
Currently in the present phase.
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.
char const * server
Server string from the config.
fr_event_timer_t const * cookie_ev
Timer event for sending cookies.
fr_ldap_connection_t * conn
Connection the sync is running on.
CONF_SECTION * cs
our configuration
fr_pair_list_t trigger_args
Arguments to make available in triggers.
fr_event_timer_t const * retry_ev
Timer event for retrying failed changes.
fr_event_list_t * el
Network side event list.
proto_ldap_sync_ldap_t const * inst
instance data
Tracking structure for ldap sync packets.
State of an individual sync.
eap_aka_sim_process_conf_t * inst
An element in a lexicographically sorted array of name to num mappings.
Definition: table.h:45
"server local" time.
Definition: time.h:69
static fr_event_list_t * el