2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1999-2009 The OpenLDAP Foundation.
5 * Portions Copyright 2001-2003 Pierangelo Masarati.
6 * Portions Copyright 1999-2003 Howard Chu.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
13 * A copy of this license is available in the file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
18 * This work was initially developed by the Howard Chu for inclusion
19 * in OpenLDAP Software and subsequently enhanced by Pierangelo
24 #error "include servers/slapd/back-ldap/back-ldap.h before this file!"
25 #endif /* SLAPD_LDAP_H */
30 #include "proto-meta.h"
32 /* String rewrite library */
38 * Set META_BACK_PRINT_CONNTREE larger than 0 to dump the connection tree (debug only)
40 #ifndef META_BACK_PRINT_CONNTREE
41 #define META_BACK_PRINT_CONNTREE 0
42 #endif /* !META_BACK_PRINT_CONNTREE */
44 /* from back-ldap.h before rwm removal */
62 struct rewrite_info *rwm_rw;
63 #else /* !ENABLE_REWRITE */
64 /* some time the suffix massaging without librewrite
66 BerVarray rwm_suffix_massage;
67 #endif /* !ENABLE_REWRITE */
70 * Attribute/objectClass mapping
72 struct ldapmap rwm_oc;
73 struct ldapmap rwm_at;
76 /* Whatever context ldap_back_dn_massage needs... */
77 typedef struct dncookie {
78 struct metatarget_t *target;
90 int ldap_back_dn_massage(dncookie *dc, struct berval *dn,
93 extern int ldap_back_conn_cmp( const void *c1, const void *c2);
94 extern int ldap_back_conn_dup( void *c1, void *c2 );
95 extern void ldap_back_conn_free( void *c );
97 /* attributeType/objectClass mapping */
98 int mapping_cmp (const void *, const void *);
99 int mapping_dup (void *, void *);
101 void ldap_back_map_init ( struct ldapmap *lm, struct ldapmapping ** );
102 int ldap_back_mapping ( struct ldapmap *map, struct berval *s,
103 struct ldapmapping **m, int remap );
104 void ldap_back_map ( struct ldapmap *map, struct berval *s, struct berval *m,
106 #define BACKLDAP_MAP 0
107 #define BACKLDAP_REMAP 1
109 ldap_back_map_filter(
110 struct ldapmap *at_map,
111 struct ldapmap *oc_map,
117 struct ldapmap *at_map,
120 char ***mapped_attrs );
122 extern int ldap_back_map_config(
123 struct ldapmap *oc_map,
124 struct ldapmap *at_map,
131 ldap_back_filter_map_rewrite(
137 /* suffix massaging by means of librewrite */
138 #ifdef ENABLE_REWRITE
140 suffix_massage_config( struct rewrite_info *info,
144 struct berval *nrnc );
145 #endif /* ENABLE_REWRITE */
147 ldap_back_referral_result_rewrite(
155 ldap_dnattr_result_rewrite(
159 /* (end of) from back-ldap.h before rwm removal */
162 * A metasingleconn_t can be in the following, mutually exclusive states:
165 * - creating META_BACK_FCONN_CREATING
166 * - initialized META_BACK_FCONN_INITED
167 * - binding LDAP_BACK_FCONN_BINDING
168 * - bound/anonymous LDAP_BACK_FCONN_ISBOUND/LDAP_BACK_FCONN_ISANON
170 * possible modifiers are:
172 * - privileged LDAP_BACK_FCONN_ISPRIV
173 * - privileged, TLS LDAP_BACK_FCONN_ISTLS
174 * - subjected to idassert LDAP_BACK_FCONN_ISIDASR
175 * - tainted LDAP_BACK_FCONN_TAINTED
178 #define META_BACK_FCONN_INITED (0x00100000U)
179 #define META_BACK_FCONN_CREATING (0x00200000U)
181 #define META_BACK_CONN_INITED(lc) LDAP_BACK_CONN_ISSET((lc), META_BACK_FCONN_INITED)
182 #define META_BACK_CONN_INITED_SET(lc) LDAP_BACK_CONN_SET((lc), META_BACK_FCONN_INITED)
183 #define META_BACK_CONN_INITED_CLEAR(lc) LDAP_BACK_CONN_CLEAR((lc), META_BACK_FCONN_INITED)
184 #define META_BACK_CONN_INITED_CPY(lc, mlc) LDAP_BACK_CONN_CPY((lc), META_BACK_FCONN_INITED, (mlc))
185 #define META_BACK_CONN_CREATING(lc) LDAP_BACK_CONN_ISSET((lc), META_BACK_FCONN_CREATING)
186 #define META_BACK_CONN_CREATING_SET(lc) LDAP_BACK_CONN_SET((lc), META_BACK_FCONN_CREATING)
187 #define META_BACK_CONN_CREATING_CLEAR(lc) LDAP_BACK_CONN_CLEAR((lc), META_BACK_FCONN_CREATING)
188 #define META_BACK_CONN_CREATING_CPY(lc, mlc) LDAP_BACK_CONN_CPY((lc), META_BACK_FCONN_CREATING, (mlc))
192 #define META_NOT_CANDIDATE ((ber_tag_t)0x0)
193 #define META_CANDIDATE ((ber_tag_t)0x1)
194 #define META_BINDING ((ber_tag_t)0x2)
195 #define META_RETRYING ((ber_tag_t)0x4)
197 typedef struct metasingleconn_t {
198 #define META_CND_ISSET(rs,f) ( ( (rs)->sr_tag & (f) ) == (f) )
199 #define META_CND_SET(rs,f) ( (rs)->sr_tag |= (f) )
200 #define META_CND_CLEAR(rs,f) ( (rs)->sr_tag &= ~(f) )
202 #define META_CANDIDATE_RESET(rs) ( (rs)->sr_tag = 0 )
203 #define META_IS_CANDIDATE(rs) META_CND_ISSET( (rs), META_CANDIDATE )
204 #define META_CANDIDATE_SET(rs) META_CND_SET( (rs), META_CANDIDATE )
205 #define META_CANDIDATE_CLEAR(rs) META_CND_CLEAR( (rs), META_CANDIDATE )
206 #define META_IS_BINDING(rs) META_CND_ISSET( (rs), META_BINDING )
207 #define META_BINDING_SET(rs) META_CND_SET( (rs), META_BINDING )
208 #define META_BINDING_CLEAR(rs) META_CND_CLEAR( (rs), META_BINDING )
209 #define META_IS_RETRYING(rs) META_CND_ISSET( (rs), META_RETRYING )
210 #define META_RETRYING_SET(rs) META_CND_SET( (rs), META_RETRYING )
211 #define META_RETRYING_CLEAR(rs) META_CND_CLEAR( (rs), META_RETRYING )
215 struct berval msc_bound_ndn;
216 struct berval msc_cred;
217 unsigned msc_mscflags;
218 /* NOTE: lc_lcflags is redefined to msc_mscflags to reuse the macros
219 * defined for back-ldap */
220 #define lc_lcflags msc_mscflags
223 typedef struct metaconn_t {
225 #define lc_conn mc_conn
228 time_t mc_create_time;
231 struct berval mc_local_ndn;
232 /* NOTE: msc_mscflags is used to recycle the #define
233 * in metasingleconn_t */
234 unsigned msc_mscflags;
237 * means that the connection is bound;
238 * of course only one target actually is ...
241 #define META_BOUND_NONE (-1)
242 #define META_BOUND_ALL (-2)
244 struct metainfo_t *mc_info;
246 LDAP_TAILQ_ENTRY(metaconn_t) mc_q;
248 /* supersedes the connection stuff */
249 metasingleconn_t mc_conns[ 1 ];
250 /* NOTE: mc_conns must be last, because
251 * the required number of conns is malloc'ed
252 * in one block with the metaconn_t structure */
255 typedef struct metatarget_t {
257 ldap_pvt_thread_mutex_t mt_uri_mutex;
259 /* TODO: we might want to enable different strategies
260 * for different targets */
261 LDAP_REBIND_PROC *mt_rebind_f;
262 LDAP_URLLIST_PROC *mt_urllist_f;
265 BerVarray mt_subtree_exclude;
268 struct berval mt_psuffix; /* pretty suffix */
269 struct berval mt_nsuffix; /* normalized suffix */
271 struct berval mt_binddn;
272 struct berval mt_bindpw;
274 slap_idassert_t mt_idassert;
275 #define mt_idassert_mode mt_idassert.si_mode
276 #define mt_idassert_authcID mt_idassert.si_bc.sb_authcId
277 #define mt_idassert_authcDN mt_idassert.si_bc.sb_binddn
278 #define mt_idassert_passwd mt_idassert.si_bc.sb_cred
279 #define mt_idassert_authzID mt_idassert.si_bc.sb_authzId
280 #define mt_idassert_authmethod mt_idassert.si_bc.sb_method
281 #define mt_idassert_sasl_mech mt_idassert.si_bc.sb_saslmech
282 #define mt_idassert_sasl_realm mt_idassert.si_bc.sb_realm
283 #define mt_idassert_secprops mt_idassert.si_bc.sb_secprops
284 #define mt_idassert_tls mt_idassert.si_bc.sb_tls
285 #define mt_idassert_flags mt_idassert.si_flags
286 #define mt_idassert_authz mt_idassert.si_authz
289 #define META_RETRY_UNDEFINED (-2)
290 #define META_RETRY_FOREVER (-1)
291 #define META_RETRY_NEVER (0)
292 #define META_RETRY_DEFAULT (10)
294 struct ldaprwmap mt_rwmap;
296 sig_atomic_t mt_isquarantined;
297 slap_retry_info_t mt_quarantine;
298 ldap_pvt_thread_mutex_t mt_quarantine_mutex;
301 #define META_BACK_TGT_ISSET(mt,f) ( ( (mt)->mt_flags & (f) ) == (f) )
302 #define META_BACK_TGT_ISMASK(mt,m,f) ( ( (mt)->mt_flags & (m) ) == (f) )
304 #define META_BACK_TGT_SAVECRED(mt) META_BACK_TGT_ISSET( (mt), LDAP_BACK_F_SAVECRED )
306 #define META_BACK_TGT_USE_TLS(mt) META_BACK_TGT_ISSET( (mt), LDAP_BACK_F_USE_TLS )
307 #define META_BACK_TGT_PROPAGATE_TLS(mt) META_BACK_TGT_ISSET( (mt), LDAP_BACK_F_PROPAGATE_TLS )
308 #define META_BACK_TGT_TLS_CRITICAL(mt) META_BACK_TGT_ISSET( (mt), LDAP_BACK_F_TLS_CRITICAL )
310 #define META_BACK_TGT_CHASE_REFERRALS(mt) META_BACK_TGT_ISSET( (mt), LDAP_BACK_F_CHASE_REFERRALS )
312 #define META_BACK_TGT_T_F(mt) META_BACK_TGT_ISMASK( (mt), LDAP_BACK_F_T_F_MASK, LDAP_BACK_F_T_F )
313 #define META_BACK_TGT_T_F_DISCOVER(mt) META_BACK_TGT_ISMASK( (mt), LDAP_BACK_F_T_F_MASK2, LDAP_BACK_F_T_F_DISCOVER )
315 #define META_BACK_TGT_ABANDON(mt) META_BACK_TGT_ISMASK( (mt), LDAP_BACK_F_CANCEL_MASK, LDAP_BACK_F_CANCEL_ABANDON )
316 #define META_BACK_TGT_IGNORE(mt) META_BACK_TGT_ISMASK( (mt), LDAP_BACK_F_CANCEL_MASK, LDAP_BACK_F_CANCEL_IGNORE )
317 #define META_BACK_TGT_CANCEL(mt) META_BACK_TGT_ISMASK( (mt), LDAP_BACK_F_CANCEL_MASK, LDAP_BACK_F_CANCEL_EXOP )
318 #define META_BACK_TGT_CANCEL_DISCOVER(mt) META_BACK_TGT_ISMASK( (mt), LDAP_BACK_F_CANCEL_MASK2, LDAP_BACK_F_CANCEL_EXOP_DISCOVER )
319 #define META_BACK_TGT_QUARANTINE(mt) META_BACK_TGT_ISSET( (mt), LDAP_BACK_F_QUARANTINE )
321 #ifdef SLAP_CONTROL_X_SESSION_TRACKING
322 #define META_BACK_TGT_ST_REQUEST(mt) META_BACK_TGT_ISSET( (mt), LDAP_BACK_F_ST_REQUEST )
323 #define META_BACK_TGT_ST_RESPONSE(mt) META_BACK_TGT_ISSET( (mt), LDAP_BACK_F_ST_RESPONSE )
324 #endif /* SLAP_CONTROL_X_SESSION_TRACKING */
326 #define META_BACK_TGT_NOREFS(mt) META_BACK_TGT_ISSET( (mt), LDAP_BACK_F_NOREFS )
327 #define META_BACK_TGT_NOUNDEFFILTER(mt) META_BACK_TGT_ISSET( (mt), LDAP_BACK_F_NOUNDEFFILTER )
329 slap_mask_t mt_rep_flags;
332 time_t mt_network_timeout;
333 struct timeval mt_bind_timeout;
334 #define META_BIND_TIMEOUT LDAP_BACK_RESULT_UTIMEOUT
335 time_t mt_timeout[ SLAP_OP_LAST ];
338 typedef struct metadncache_t {
339 ldap_pvt_thread_mutex_t mutex;
342 #define META_DNCACHE_DISABLED (0)
343 #define META_DNCACHE_FOREVER ((time_t)(-1))
344 time_t ttl; /* seconds; 0: no cache, -1: no expiry */
347 typedef struct metacandidates_t {
349 SlapReply *mc_candidates;
353 * Hook to allow mucking with metainfo_t/metatarget_t when quarantine is over
355 typedef int (*meta_back_quarantine_f)( struct metainfo_t *, int target, void * );
357 typedef struct metainfo_t {
359 int mi_defaulttarget;
360 #define META_DEFAULT_TARGET_NONE (-1)
363 metatarget_t **mi_targets;
364 metacandidates_t *mi_candidates;
366 LDAP_REBIND_PROC *mi_rebind_f;
367 LDAP_URLLIST_PROC *mi_urllist_f;
369 metadncache_t mi_cache;
371 /* cached connections;
372 * special conns are in tailq rather than in tree */
373 ldap_avl_info_t mi_conninfo;
376 LDAP_TAILQ_HEAD(mc_conn_priv_q, metaconn_t) mic_priv;
377 } mi_conn_priv[ LDAP_BACK_PCONN_LAST ];
378 int mi_conn_priv_max;
380 /* NOTE: quarantine uses the connection mutex */
381 slap_retry_info_t mi_quarantine;
382 meta_back_quarantine_f mi_quarantine_f;
383 void *mi_quarantine_p;
386 #define li_flags mi_flags
387 /* uses flags as defined in <back-ldap/back-ldap.h> */
388 #define META_BACK_F_ONERR_STOP (0x01000000U)
389 #define META_BACK_F_ONERR_REPORT (0x02000000U)
390 #define META_BACK_F_ONERR_MASK (META_BACK_F_ONERR_STOP|META_BACK_F_ONERR_REPORT)
391 #define META_BACK_F_DEFER_ROOTDN_BIND (0x04000000U)
392 #define META_BACK_F_PROXYAUTHZ_ALWAYS (0x08000000U) /* users always proxyauthz */
393 #define META_BACK_F_PROXYAUTHZ_ANON (0x10000000U) /* anonymous always proxyauthz */
394 #define META_BACK_F_PROXYAUTHZ_NOANON (0x20000000U) /* anonymous remains anonymous */
396 #define META_BACK_ONERR_STOP(mi) LDAP_BACK_ISSET( (mi), META_BACK_F_ONERR_STOP )
397 #define META_BACK_ONERR_REPORT(mi) LDAP_BACK_ISSET( (mi), META_BACK_F_ONERR_REPORT )
398 #define META_BACK_ONERR_CONTINUE(mi) ( !LDAP_BACK_ISSET( (mi), META_BACK_F_ONERR_MASK ) )
400 #define META_BACK_DEFER_ROOTDN_BIND(mi) LDAP_BACK_ISSET( (mi), META_BACK_F_DEFER_ROOTDN_BIND )
401 #define META_BACK_PROXYAUTHZ_ALWAYS(mi) LDAP_BACK_ISSET( (mi), META_BACK_F_PROXYAUTHZ_ALWAYS )
402 #define META_BACK_PROXYAUTHZ_ANON(mi) LDAP_BACK_ISSET( (mi), META_BACK_F_PROXYAUTHZ_ANON )
403 #define META_BACK_PROXYAUTHZ_NOANON(mi) LDAP_BACK_ISSET( (mi), META_BACK_F_PROXYAUTHZ_NOANON )
405 #define META_BACK_QUARANTINE(mi) LDAP_BACK_ISSET( (mi), LDAP_BACK_F_QUARANTINE )
408 time_t mi_network_timeout;
410 time_t mi_idle_timeout;
411 struct timeval mi_bind_timeout;
412 time_t mi_timeout[ SLAP_OP_LAST ];
414 ldap_extra_t *mi_ldap_extra;
418 typedef enum meta_op_type {
419 META_OP_ALLOW_MULTIPLE = 0,
420 META_OP_REQUIRE_SINGLE,
425 meta_back_candidates_get( Operation *op );
432 ldap_back_send_t sendok );
435 meta_back_release_conn_lock(
439 #define meta_back_release_conn(mi, mc) meta_back_release_conn_lock( (mi), (mc), 1 )
447 ldap_back_send_t sendok );
453 #if META_BACK_PRINT_CONNTREE > 0
455 meta_back_print_conntree(
461 meta_back_init_one_conn(
467 ldap_back_send_t sendok,
471 meta_back_quarantine(
481 ldap_back_send_t sendok );
484 meta_back_single_dobind(
489 ldap_back_send_t sendok,
494 meta_back_proxy_authz_cred(
499 ldap_back_send_t sendok,
500 struct berval *binddn,
501 struct berval *bindcred,
511 ldap_back_send_t sendok );
521 ldap_back_send_t sendok );
524 meta_back_controls_add(
529 LDAPControl ***pctrls );
532 back_meta_LTX_init_module(
542 meta_back_conndn_cmp(
547 meta_back_conndn_dup(
555 meta_back_is_candidate(
561 meta_back_select_unique_candidate(
563 struct berval *ndn );
566 meta_clear_unused_candidates(
571 meta_clear_one_candidate(
577 * Dn cache stuff (experimental)
589 #define META_TARGET_NONE (-1)
590 #define META_TARGET_MULTIPLE (-2)
592 meta_dncache_get_target(
593 metadncache_t *cache,
594 struct berval *ndn );
597 meta_dncache_update_entry(
598 metadncache_t *cache,
603 meta_dncache_delete_entry(
604 metadncache_t *cache,
605 struct berval *ndn );
608 meta_dncache_free( void *entry );
610 extern LDAP_REBIND_PROC meta_back_default_rebind;
611 extern LDAP_URLLIST_PROC meta_back_default_urllist;
615 #endif /* SLAPD_META_H */