The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
proto_ldap_sync.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: 97d2b5f0ab7a34d6f542238504d98ee0a1eee47a $
20  *
21  * @file proto_ldap_sync.h
22  * @brief Structures for the LDAP Sync protocol
23  *
24  * @copyright 2022 Network RADIUS SAS (legal@networkradius.com)
25  */
26 #include <freeradius-devel/io/master.h>
27 #include <freeradius-devel/ldap/base.h>
28 #include <freeradius-devel/ldap/sync.h>
29 
30 typedef struct sync_config_s sync_config_t;
31 
32 /** An instance of a proto_ldap_sync listen section
33  *
34  */
35 typedef struct {
36  CONF_SECTION *server_cs; //!< server CS for this listener.
37  CONF_SECTION *cs; //!< my configuration.
38 
39  sync_config_t **sync_config; //!< DNs and filters to monitor.
40 
41  fr_app_t *self; //!< child / parent linking issues
42 
43  dl_module_inst_t *io_submodule; //!< As provided by the transport_parse
44  //!< callback. Broken out into the
45  //!< app_io_* fields below for convenience.
46 
47  fr_app_io_t const *app_io; //!< Easy access to the app_io handle.
48  void *app_io_instance; //!< Easy access to the app_io_instance.
49  CONF_SECTION *app_io_conf; //!< Easy access to the app_io's configuration.
50 
51  fr_dict_t *dict; //!< root dictionary
52 
53  uint32_t max_packet_size; //!< for message ring buffer
54  uint32_t num_messages; //!< for message ring buffer
55  uint32_t priority; //!< for packet processing.
56 
57  fr_time_delta_t cookie_interval; //!< Interval between storing cookies.
58  uint32_t cookie_changes; //!< Number of LDAP changes to process between
59  //!< each cookie store operation.
60  fr_time_delta_t retry_interval; //!< Interval between retrying failed change packets.
61 
63 
64  fr_listen_t *listen; //!< The listener structure which describes
65  //! the I/O path.
67 
68 /** Operations to perform on entries
69  */
70 typedef enum {
71  SYNC_OP_INVALID = -1, //!< Invalid sync operation.
72  SYNC_OP_PRESENT = 0, //!< Entry is present and unchanged on the server.
73  SYNC_OP_ADD = 1, //!< Entry should be added to our copy.
74  SYNC_OP_MODIFY = 2, //!< Entry should be updated in our copy.
75  SYNC_OP_DELETE = 3 //!< Entry should be deleted from our copy.
77 
78 typedef struct sync_state_s sync_state_t;
79 
80 /** Allocate and initialise a sync query
81  *
82  * Called at the start of the sync operation, after any cookie has been retrieved.
83  *
84  * Sends the persistent search query to the LDAP server with the appropriate
85  * controls for type of directory in use.
86  *
87  * @param[in] conn to initialise the sync on
88  * @param[in] sync_no number of the sync in the array of configs.
89  * @param[in] inst instance of ldap_sync this query relates to
90  * @param[in] cookie to send with the query (RFC 4533 only)
91  * @return
92  * - 0 on success.
93  * - -1 on error.
94  */
96  uint8_t const *cookie);
97 
98 /** Received an LDAP message related to a sync
99  *
100  * Called whenever the server returns a message, during any phase of the sync.
101  *
102  * This function is responsible for freeing the LDAP message.
103  *
104  * @param[in] sync we received the message for.
105  * @param[in] msg the LDAP message received.
106  * @param[in] ctrls received with the message.
107  * @return
108  * - 0 on success.
109  * - -1 on error.
110  */
111 typedef int (*sync_msg_t)(sync_state_t *sync, LDAPMessage *msg, LDAPControl **ctrls);
112 
113 /** Areas of the directory to receive notifications for
114  *
115  */
117  char const *filter; //!< Filter to retrieve only user objects.
118  char const *base_dn; //!< DN to search for users under.
119 
120  char const **attrs; //!< Zero terminated attribute array.
121 
122  int scope; //!< Scope as its libldap value
123  char const *scope_str; //!< Scope (sub, one, base).
124  bool changes_only; //!< Do we only want changes, or do we want a full
125  //!< directory load. Not supported by Active Directory.
126 
127  map_list_t entry_map; //!< How to convert attributes in entries
128  //!< to FreeRADIUS attributes.
129 
130  char const *root_dn; //!< The root DN for the directory.
131 
132  CONF_SECTION *cs; //!< Config section where this sync was defined.
133  //!< Used for logging.
134 
135  fr_event_timer_t const *ev; //!< Event for retrying cookie load
136 
137  /*
138  * Callbacks for various events
139  */
140  sync_init_t init; //!< Called to initialise a new search.
141 
142  sync_msg_t entry; //!< Called when we receive a searchEntry message.
143 
144  sync_msg_t reference; //!< Called when we receive a searchReference message.
145 
146  sync_msg_t intermediate; //!< Called when we receive a syncIntermediate message.
147 
148  sync_msg_t refresh; //!< Called when we receive a eSyncRefreshRequired code.
149 
150  void *user_ctx; //!< User ctx to pass to the callbacks.
151 
152  fr_pair_list_t sync_pairs; //!< Pairs representing the sync config sent to the worker
153  //!< with each request.
154 };
155 
156 int ldap_sync_conf_attr_add(sync_config_t *config, char const * attr);
log_entry msg
Definition: acutest.h:794
Public structure describing an I/O path for a protocol.
Definition: app_io.h:33
Describes a new application (protocol)
Definition: application.h:71
A section grouping multiple CONF_PAIR.
Definition: cf_priv.h:89
A module/inst tuple.
Definition: dl_module.h:162
Tracks the state of a libldap connection handle.
Definition: base.h:330
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
bool changes_only
Do we only want changes, or do we want a full directory load.
char const * filter
Filter to retrieve only user objects.
dl_module_inst_t * io_submodule
As provided by the transport_parse callback.
CONF_SECTION * server_cs
server CS for this listener.
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.
sync_init_t init
Called to initialise a new search.
uint32_t max_packet_size
for message ring buffer
int ldap_sync_conf_attr_add(sync_config_t *config, char const *attr)
Check if an attribute is in the config list and add if not present.
CONF_SECTION * app_io_conf
Easy access to the app_io's configuration.
fr_dict_t * dict
root dictionary
char const * scope_str
Scope (sub, one, base).
char const * root_dn
The root DN for the directory.
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_INVALID
Invalid sync operation.
@ SYNC_OP_DELETE
Entry should be deleted from our copy.
@ SYNC_OP_PRESENT
Entry is present and unchanged on the server.
fr_event_timer_t const * ev
Event for retrying cookie load.
char const * base_dn
DN to search for users under.
sync_msg_t entry
Called when we receive a searchEntry message.
CONF_SECTION * cs
my configuration.
sync_msg_t refresh
Called when we receive a eSyncRefreshRequired code.
int scope
Scope as its libldap value.
CONF_SECTION * cs
Config section where this sync was defined.
char const ** attrs
Zero terminated attribute array.
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.
int(* sync_init_t)(fr_ldap_connection_t *conn, size_t sync_no, proto_ldap_sync_t const *inst, uint8_t const *cookie)
Allocate and initialise a sync query.
sync_msg_t reference
Called when we receive a searchReference message.
uint32_t num_messages
for message ring buffer
void * app_io_instance
Easy access to the app_io_instance.
fr_pair_list_t sync_pairs
Pairs representing the sync config sent to the worker with each request.
uint32_t priority
for packet processing.
fr_time_delta_t cookie_interval
Interval between storing cookies.
fr_listen_t * listen
The listener structure which describes the I/O path.
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.
fr_schedule_t * sc
void * user_ctx
User ctx to pass to the callbacks.
fr_app_io_t const * app_io
Easy access to the app_io handle.
An instance of a proto_ldap_sync listen section.
Areas of the directory to receive notifications for.
uint8_t * cookie
Opaque cookie, used to resume synchronisation.
size_t sync_no
Array position of config for this sync.
fr_ldap_connection_t * conn
Connection the sync is running on.
State of an individual sync.
The scheduler.
Definition: schedule.c:125
eap_aka_sim_process_conf_t * inst
A time delta, a difference in time measured in nanoseconds.
Definition: time.h:80