]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldap/back-ldap.h
ITS#4337 insert EntryInfo in proper slot
[openldap] / servers / slapd / back-ldap / back-ldap.h
1 /* back-ldap.h - ldap backend header file */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 1999-2006 The OpenLDAP Foundation.
6  * Portions Copyright 2000-2003 Pierangelo Masarati.
7  * Portions Copyright 1999-2003 Howard Chu.
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted only as authorized by the OpenLDAP
12  * Public License.
13  *
14  * A copy of this license is available in the file LICENSE in the
15  * top-level directory of the distribution or, alternatively, at
16  * <http://www.OpenLDAP.org/license.html>.
17  */
18 /* ACKNOWLEDGEMENTS:
19  * This work was initially developed by the Howard Chu for inclusion
20  * in OpenLDAP Software and subsequently enhanced by Pierangelo
21  * Masarati.
22  */
23
24 #ifndef SLAPD_LDAP_H
25 #define SLAPD_LDAP_H
26
27 #include "../back-monitor/back-monitor.h"
28
29 LDAP_BEGIN_DECL
30
31 struct ldapinfo_t;
32
33 /* stuff required for monitoring */
34 typedef struct ldap_monitor_info_t {
35         monitor_subsys_t        lmi_mss;
36         struct ldapinfo_t       *lmi_li;
37
38         struct berval           lmi_rdn;
39         struct berval           lmi_nrdn;
40         monitor_callback_t      *lmi_cb;
41         struct berval           lmi_base;
42         int                     lmi_scope;
43         struct berval           lmi_filter;
44         struct berval           lmi_more_filter;
45 } ldap_monitor_info_t;
46
47 typedef struct ldapconn_t {
48         Connection              *lc_conn;
49 #define LDAP_BACK_PCONN                 ((void *)0x0)
50 #define LDAP_BACK_PCONN_TLS             ((void *)0x1)
51 #define LDAP_BACK_PCONN_BIND            ((void *)0x2)
52 #define LDAP_BACK_PCONN_BIND_TLS        ((void *)0x3)
53 #define LDAP_BACK_PCONN_LAST            ((void *)0x4)
54 #define LDAP_BACK_PCONN_ISPRIV(lc)      ((void *)(lc)->lc_conn < LDAP_BACK_PCONN_LAST)
55 #define LDAP_BACK_PCONN_ID(lc)          (LDAP_BACK_PCONN_ISPRIV((lc)) ? ( -1 - (long)(lc)->lc_conn ): (lc)->lc_conn->c_connid )
56 #ifdef HAVE_TLS
57 #define LDAP_BACK_PCONN_SET(op)         ((op)->o_conn->c_is_tls ? LDAP_BACK_PCONN_TLS : LDAP_BACK_PCONN)
58 #define LDAP_BACK_PCONN_BIND_SET(op)    ((op)->o_conn->c_is_tls ? LDAP_BACK_PCONN_BIND_TLS : LDAP_BACK_PCONN_BIND)
59 #else /* ! HAVE_TLS */
60 #define LDAP_BACK_PCONN_SET(op)         (LDAP_BACK_PCONN)
61 #define LDAP_BACK_PCONN_BIND_SET(op)    (LDAP_BACK_PCONN_BIND)
62 #endif /* ! HAVE_TLS */
63
64         LDAP                    *lc_ld;
65         struct berval           lc_cred;
66         struct berval           lc_bound_ndn;
67         struct berval           lc_local_ndn;
68         unsigned                lc_lcflags;
69 #define LDAP_BACK_CONN_ISSET_F(fp,f)    (*(fp) & (f))
70 #define LDAP_BACK_CONN_SET_F(fp,f)      (*(fp) |= (f))
71 #define LDAP_BACK_CONN_CLEAR_F(fp,f)    (*(fp) &= ~(f))
72 #define LDAP_BACK_CONN_CPY_F(fp,f,mfp) \
73         do { \
74                 if ( ((f) & *(mfp)) == (f) ) { \
75                         *(fp) |= (f); \
76                 } else { \
77                         *(fp) &= ~(f); \
78                 } \
79         } while ( 0 )
80
81 #define LDAP_BACK_CONN_ISSET(lc,f)      LDAP_BACK_CONN_ISSET_F(&(lc)->lc_lcflags, (f))
82 #define LDAP_BACK_CONN_SET(lc,f)        LDAP_BACK_CONN_SET_F(&(lc)->lc_lcflags, (f))
83 #define LDAP_BACK_CONN_CLEAR(lc,f)      LDAP_BACK_CONN_CLEAR_F(&(lc)->lc_lcflags, (f))
84 #define LDAP_BACK_CONN_CPY(lc,f,mlc)    LDAP_BACK_CONN_CPY_F(&(lc)->lc_lcflags, (f), &(mlc)->lc_lcflags)
85
86 /* 0xFFF00000U are reserved for back-meta */
87
88 #define LDAP_BACK_FCONN_ISBOUND (0x00000001U)
89 #define LDAP_BACK_FCONN_ISANON  (0x00000002U)
90 #define LDAP_BACK_FCONN_ISBMASK (LDAP_BACK_FCONN_ISBOUND|LDAP_BACK_FCONN_ISANON)
91 #define LDAP_BACK_FCONN_ISPRIV  (0x00000004U)
92 #define LDAP_BACK_FCONN_ISTLS   (0x00000008U)
93 #define LDAP_BACK_FCONN_BINDING (0x00000010U)
94 #define LDAP_BACK_FCONN_TAINTED (0x00000020U)
95 #define LDAP_BACK_FCONN_ISIDASR (0x00000040U)
96
97 #define LDAP_BACK_CONN_ISBOUND(lc)              LDAP_BACK_CONN_ISSET((lc), LDAP_BACK_FCONN_ISBOUND)
98 #define LDAP_BACK_CONN_ISBOUND_SET(lc)          LDAP_BACK_CONN_SET((lc), LDAP_BACK_FCONN_ISBOUND)
99 #define LDAP_BACK_CONN_ISBOUND_CLEAR(lc)        LDAP_BACK_CONN_CLEAR((lc), LDAP_BACK_FCONN_ISBMASK)
100 #define LDAP_BACK_CONN_ISBOUND_CPY(lc, mlc)     LDAP_BACK_CONN_CPY((lc), LDAP_BACK_FCONN_ISBOUND, (mlc))
101 #define LDAP_BACK_CONN_ISANON(lc)               LDAP_BACK_CONN_ISSET((lc), LDAP_BACK_FCONN_ISANON)
102 #define LDAP_BACK_CONN_ISANON_SET(lc)           LDAP_BACK_CONN_SET((lc), LDAP_BACK_FCONN_ISANON)
103 #define LDAP_BACK_CONN_ISANON_CLEAR(lc)         LDAP_BACK_CONN_ISBOUND_CLEAR((lc))
104 #define LDAP_BACK_CONN_ISANON_CPY(lc, mlc)      LDAP_BACK_CONN_CPY((lc), LDAP_BACK_FCONN_ISANON, (mlc))
105 #define LDAP_BACK_CONN_ISPRIV(lc)               LDAP_BACK_CONN_ISSET((lc), LDAP_BACK_FCONN_ISPRIV)
106 #define LDAP_BACK_CONN_ISPRIV_SET(lc)           LDAP_BACK_CONN_SET((lc), LDAP_BACK_FCONN_ISPRIV)
107 #define LDAP_BACK_CONN_ISPRIV_CLEAR(lc)         LDAP_BACK_CONN_CLEAR((lc), LDAP_BACK_FCONN_ISPRIV)
108 #define LDAP_BACK_CONN_ISPRIV_CPY(lc, mlc)      LDAP_BACK_CONN_CPY((lc), LDAP_BACK_FCONN_ISPRIV, (mlc))
109 #define LDAP_BACK_CONN_ISTLS(lc)                LDAP_BACK_CONN_ISSET((lc), LDAP_BACK_FCONN_ISTLS)
110 #define LDAP_BACK_CONN_ISTLS_SET(lc)            LDAP_BACK_CONN_SET((lc), LDAP_BACK_FCONN_ISTLS)
111 #define LDAP_BACK_CONN_ISTLS_CLEAR(lc)          LDAP_BACK_CONN_CLEAR((lc), LDAP_BACK_FCONN_ISTLS)
112 #define LDAP_BACK_CONN_ISTLS_CPY(lc, mlc)       LDAP_BACK_CONN_CPY((lc), LDAP_BACK_FCONN_ISTLS, (mlc))
113 #define LDAP_BACK_CONN_BINDING(lc)              LDAP_BACK_CONN_ISSET((lc), LDAP_BACK_FCONN_BINDING)
114 #define LDAP_BACK_CONN_BINDING_SET(lc)          LDAP_BACK_CONN_SET((lc), LDAP_BACK_FCONN_BINDING)
115 #define LDAP_BACK_CONN_BINDING_CLEAR(lc)        LDAP_BACK_CONN_CLEAR((lc), LDAP_BACK_FCONN_BINDING)
116 #define LDAP_BACK_CONN_TAINTED(lc)              LDAP_BACK_CONN_ISSET((lc), LDAP_BACK_FCONN_TAINTED)
117 #define LDAP_BACK_CONN_TAINTED_SET(lc)          LDAP_BACK_CONN_SET((lc), LDAP_BACK_FCONN_TAINTED)
118 #define LDAP_BACK_CONN_TAINTED_CLEAR(lc)        LDAP_BACK_CONN_CLEAR((lc), LDAP_BACK_FCONN_TAINTED)
119 #define LDAP_BACK_CONN_ISIDASSERT(lc)           LDAP_BACK_CONN_ISSET((lc), LDAP_BACK_FCONN_ISIDASR)
120 #define LDAP_BACK_CONN_ISIDASSERT_SET(lc)       LDAP_BACK_CONN_SET((lc), LDAP_BACK_FCONN_ISIDASR)
121 #define LDAP_BACK_CONN_ISIDASSERT_CLEAR(lc)     LDAP_BACK_CONN_CLEAR((lc), LDAP_BACK_FCONN_ISIDASR)
122 #define LDAP_BACK_CONN_ISIDASSERT_CPY(lc, mlc)  LDAP_BACK_CONN_CPY((lc), LDAP_BACK_FCONN_ISIDASR, (mlc))
123
124         unsigned                lc_refcnt;
125         unsigned                lc_binding;
126         unsigned                lc_flags;
127         time_t                  lc_create_time;
128         time_t                  lc_time;
129 } ldapconn_t;
130
131 typedef struct ldap_avl_info_t {
132         ldap_pvt_thread_mutex_t         lai_mutex;
133         Avlnode                         *lai_tree;
134 } ldap_avl_info_t;
135
136 typedef struct slap_retry_info_t {
137         time_t          *ri_interval;
138         int             *ri_num;
139         int             ri_idx;
140         int             ri_count;
141         time_t          ri_last;
142
143 #define SLAP_RETRYNUM_FOREVER   (-1)            /* retry forever */
144 #define SLAP_RETRYNUM_TAIL      (-2)            /* end of retrynum array */
145 #define SLAP_RETRYNUM_VALID(n)  ((n) >= SLAP_RETRYNUM_FOREVER)  /* valid retrynum */
146 #define SLAP_RETRYNUM_FINITE(n) ((n) > SLAP_RETRYNUM_FOREVER)   /* not forever */
147 } slap_retry_info_t;
148
149 /*
150  * identity assertion modes
151  */
152 typedef enum {
153         LDAP_BACK_IDASSERT_LEGACY = 1,
154         LDAP_BACK_IDASSERT_NOASSERT,
155         LDAP_BACK_IDASSERT_ANONYMOUS,
156         LDAP_BACK_IDASSERT_SELF,
157         LDAP_BACK_IDASSERT_OTHERDN,
158         LDAP_BACK_IDASSERT_OTHERID
159 } slap_idassert_mode_t;
160
161 /* ID assert stuff */
162 typedef struct slap_idassert_t {
163         slap_idassert_mode_t    si_mode;
164 #define li_idassert_mode        li_idassert.si_mode
165
166         slap_bindconf   si_bc;
167 #define li_idassert_authcID     li_idassert.si_bc.sb_authcId
168 #define li_idassert_authcDN     li_idassert.si_bc.sb_binddn
169 #define li_idassert_passwd      li_idassert.si_bc.sb_cred
170 #define li_idassert_authzID     li_idassert.si_bc.sb_authzId
171 #define li_idassert_authmethod  li_idassert.si_bc.sb_method
172 #define li_idassert_sasl_mech   li_idassert.si_bc.sb_saslmech
173 #define li_idassert_sasl_realm  li_idassert.si_bc.sb_realm
174 #define li_idassert_secprops    li_idassert.si_bc.sb_secprops
175 #define li_idassert_tls         li_idassert.si_bc.sb_tls
176
177         unsigned        si_flags;
178 #define LDAP_BACK_AUTH_NONE                             (0x00U)
179 #define LDAP_BACK_AUTH_NATIVE_AUTHZ                     (0x01U)
180 #define LDAP_BACK_AUTH_OVERRIDE                         (0x02U)
181 #define LDAP_BACK_AUTH_PRESCRIPTIVE                     (0x04U)
182 #define LDAP_BACK_AUTH_OBSOLETE_PROXY_AUTHZ             (0x08U)
183 #define LDAP_BACK_AUTH_OBSOLETE_ENCODING_WORKAROUND     (0x10U)
184 #define LDAP_BACK_AUTH_AUTHZ_ALL                        (0x20U)
185 #define li_idassert_flags       li_idassert.si_flags
186
187         BerVarray       si_authz;
188 #define li_idassert_authz       li_idassert.si_authz
189 } slap_idassert_t;
190
191 /*
192  * Hook to allow mucking with ldapinfo_t when quarantine is over
193  */
194 typedef int (*ldap_back_quarantine_f)( struct ldapinfo_t *, void * );
195
196 typedef struct ldapinfo_t {
197         /* li_uri: the string that goes into ldap_initialize()
198          * TODO: use li_acl.sb_uri instead */
199         char                    *li_uri;
200         /* li_bvuri: an array of each single URI that is equivalent;
201          * to be checked for the presence of a certain item */
202         BerVarray               li_bvuri;
203         ldap_pvt_thread_mutex_t li_uri_mutex;
204
205         LDAP_REBIND_PROC        *li_rebind_f;
206         LDAP_URLLIST_PROC       *li_urllist_f;
207         void                    *li_urllist_p;
208
209         slap_bindconf   li_acl;
210 #define li_acl_authcID  li_acl.sb_authcId
211 #define li_acl_authcDN  li_acl.sb_binddn
212 #define li_acl_passwd   li_acl.sb_cred
213 #define li_acl_authzID  li_acl.sb_authzId
214 #define li_acl_authmethod       li_acl.sb_method
215 #define li_acl_sasl_mech        li_acl.sb_saslmech
216 #define li_acl_sasl_realm       li_acl.sb_realm
217 #define li_acl_secprops li_acl.sb_secprops
218
219         /* ID assert stuff */
220         slap_idassert_t li_idassert;
221         /* end of ID assert stuff */
222
223         int             li_nretries;
224 #define LDAP_BACK_RETRY_UNDEFINED       (-2)
225 #define LDAP_BACK_RETRY_FOREVER         (-1)
226 #define LDAP_BACK_RETRY_NEVER           (0)
227 #define LDAP_BACK_RETRY_DEFAULT         (3)
228
229         unsigned        li_flags;
230
231 /* 0xFFF00000U are reserved for back-meta */
232
233 #define LDAP_BACK_F_NONE                (0x00000000U)
234 #define LDAP_BACK_F_SAVECRED            (0x00000001U)
235 #define LDAP_BACK_F_USE_TLS             (0x00000002U)
236 #define LDAP_BACK_F_PROPAGATE_TLS       (0x00000004U)
237 #define LDAP_BACK_F_TLS_CRITICAL        (0x00000008U)
238 #define LDAP_BACK_F_TLS_USE_MASK        (LDAP_BACK_F_USE_TLS|LDAP_BACK_F_TLS_CRITICAL)
239 #define LDAP_BACK_F_TLS_PROPAGATE_MASK  (LDAP_BACK_F_PROPAGATE_TLS|LDAP_BACK_F_TLS_CRITICAL)
240 #define LDAP_BACK_F_TLS_MASK            (LDAP_BACK_F_TLS_USE_MASK|LDAP_BACK_F_TLS_PROPAGATE_MASK)
241 #define LDAP_BACK_F_CHASE_REFERRALS     (0x00000010U)
242 #define LDAP_BACK_F_PROXY_WHOAMI        (0x00000020U)
243
244 #define LDAP_BACK_F_T_F                 (0x00000040U)
245 #define LDAP_BACK_F_T_F_DISCOVER        (0x00000080U)
246 #define LDAP_BACK_F_T_F_MASK            (LDAP_BACK_F_T_F)
247 #define LDAP_BACK_F_T_F_MASK2           (LDAP_BACK_F_T_F_MASK|LDAP_BACK_F_T_F_DISCOVER)
248
249 #define LDAP_BACK_F_MONITOR             (0x00000100U)
250 #define LDAP_BACK_F_SINGLECONN          (0x00000200U)
251 #define LDAP_BACK_F_USE_TEMPORARIES     (0x00000400U)
252
253 #define LDAP_BACK_F_ISOPEN              (0x00000800U)
254
255 #define LDAP_BACK_F_CANCEL_ABANDON      (0x00000000U)
256 #define LDAP_BACK_F_CANCEL_IGNORE       (0x00001000U)
257 #define LDAP_BACK_F_CANCEL_EXOP         (0x00002000U)
258 #define LDAP_BACK_F_CANCEL_EXOP_DISCOVER        (0x00004000U)
259 #define LDAP_BACK_F_CANCEL_MASK         (LDAP_BACK_F_CANCEL_IGNORE|LDAP_BACK_F_CANCEL_EXOP)
260 #define LDAP_BACK_F_CANCEL_MASK2        (LDAP_BACK_F_CANCEL_MASK|LDAP_BACK_F_CANCEL_EXOP_DISCOVER)
261
262 #define LDAP_BACK_ISSET(li,f)           ( ( (li)->li_flags & (f) ) == (f) )
263 #define LDAP_BACK_ISMASK(li,m,f)        ( ( (li)->li_flags & (m) ) == (f) )
264
265 #define LDAP_BACK_SAVECRED(li)          LDAP_BACK_ISSET( (li), LDAP_BACK_F_SAVECRED )
266 #define LDAP_BACK_USE_TLS(li)           LDAP_BACK_ISSET( (li), LDAP_BACK_F_USE_TLS )
267 #define LDAP_BACK_PROPAGATE_TLS(li)     LDAP_BACK_ISSET( (li), LDAP_BACK_F_PROPAGATE_TLS )
268 #define LDAP_BACK_TLS_CRITICAL(li)      LDAP_BACK_ISSET( (li), LDAP_BACK_F_TLS_CRITICAL )
269 #define LDAP_BACK_CHASE_REFERRALS(li)   LDAP_BACK_ISSET( (li), LDAP_BACK_F_CHASE_REFERRALS )
270 #define LDAP_BACK_PROXY_WHOAMI(li)      LDAP_BACK_ISSET( (li), LDAP_BACK_F_PROXY_WHOAMI )
271
272 #define LDAP_BACK_T_F(li)               LDAP_BACK_ISMASK( (li), LDAP_BACK_F_T_F_MASK, LDAP_BACK_F_T_F )
273 #define LDAP_BACK_T_F_DISCOVER(li)      LDAP_BACK_ISMASK( (li), LDAP_BACK_F_T_F_MASK2, LDAP_BACK_F_T_F_DISCOVER )
274
275 #define LDAP_BACK_MONITOR(li)           LDAP_BACK_ISSET( (li), LDAP_BACK_F_MONITOR )
276 #define LDAP_BACK_SINGLECONN(li)        LDAP_BACK_ISSET( (li), LDAP_BACK_F_SINGLECONN )
277 #define LDAP_BACK_USE_TEMPORARIES(li)   LDAP_BACK_ISSET( (li), LDAP_BACK_F_USE_TEMPORARIES)
278
279 #define LDAP_BACK_ISOPEN(li)            LDAP_BACK_ISSET( (li), LDAP_BACK_F_ISOPEN )
280
281 #define LDAP_BACK_ABANDON(li)           LDAP_BACK_ISMASK( (li), LDAP_BACK_F_CANCEL_MASK, LDAP_BACK_F_CANCEL_ABANDON )
282 #define LDAP_BACK_IGNORE(li)            LDAP_BACK_ISMASK( (li), LDAP_BACK_F_CANCEL_MASK, LDAP_BACK_F_CANCEL_IGNORE )
283 #define LDAP_BACK_CANCEL(li)            LDAP_BACK_ISMASK( (li), LDAP_BACK_F_CANCEL_MASK, LDAP_BACK_F_CANCEL_EXOP )
284 #define LDAP_BACK_CANCEL_DISCOVER(li)   LDAP_BACK_ISMASK( (li), LDAP_BACK_F_CANCEL_MASK2, LDAP_BACK_F_CANCEL_EXOP_DISCOVER )
285
286         int             li_version;
287
288         ldap_avl_info_t li_conninfo;
289
290         ldap_monitor_info_t     li_monitor_info;
291
292         sig_atomic_t            li_isquarantined;
293 #define LDAP_BACK_FQ_NO         (0)
294 #define LDAP_BACK_FQ_YES        (1)
295 #define LDAP_BACK_FQ_RETRYING   (2)
296
297         slap_retry_info_t       li_quarantine;
298 #define LDAP_BACK_QUARANTINE(li)        ( (li)->li_quarantine.ri_num != NULL )
299         ldap_pvt_thread_mutex_t li_quarantine_mutex;
300         ldap_back_quarantine_f  li_quarantine_f;
301         void                    *li_quarantine_p;
302
303         time_t          li_network_timeout;
304         time_t          li_conn_ttl;
305         time_t          li_idle_timeout;
306         time_t          li_timeout[ SLAP_OP_LAST ];
307 } ldapinfo_t;
308
309 typedef enum ldap_back_send_t {
310         LDAP_BACK_DONTSEND              = 0x00,
311         LDAP_BACK_SENDOK                = 0x01,
312         LDAP_BACK_SENDERR               = 0x02,
313         LDAP_BACK_SENDRESULT            = (LDAP_BACK_SENDOK|LDAP_BACK_SENDERR),
314         LDAP_BACK_BINDING               = 0x04,
315
316         LDAP_BACK_BIND_DONTSEND         = (LDAP_BACK_BINDING),
317         LDAP_BACK_BIND_SOK              = (LDAP_BACK_BINDING|LDAP_BACK_SENDOK),
318         LDAP_BACK_BIND_SERR             = (LDAP_BACK_BINDING|LDAP_BACK_SENDERR),
319         LDAP_BACK_BIND_SRES             = (LDAP_BACK_BINDING|LDAP_BACK_SENDRESULT),
320
321         LDAP_BACK_RETRYING              = 0x08,
322         LDAP_BACK_RETRY_DONTSEND        = (LDAP_BACK_RETRYING),
323         LDAP_BACK_RETRY_SOK             = (LDAP_BACK_RETRYING|LDAP_BACK_SENDOK),
324         LDAP_BACK_RETRY_SERR            = (LDAP_BACK_RETRYING|LDAP_BACK_SENDERR),
325         LDAP_BACK_RETRY_SRES            = (LDAP_BACK_RETRYING|LDAP_BACK_SENDRESULT),
326
327         LDAP_BACK_GETCONN               = 0x10
328 } ldap_back_send_t;
329
330 /* define to use asynchronous StartTLS */
331 #define SLAP_STARTTLS_ASYNCHRONOUS
332
333 /* timeout to use when calling ldap_result() */
334 #define LDAP_BACK_RESULT_TIMEOUT        (0)
335 #define LDAP_BACK_RESULT_UTIMEOUT       (100000)
336 #define LDAP_BACK_TV_SET(tv) \
337         do { \
338                 (tv)->tv_sec = LDAP_BACK_RESULT_TIMEOUT; \
339                 (tv)->tv_usec = LDAP_BACK_RESULT_UTIMEOUT; \
340         } while ( 0 )
341
342 #ifndef LDAP_BACK_PRINT_CONNTREE
343 #define LDAP_BACK_PRINT_CONNTREE 0
344 #endif /* !LDAP_BACK_PRINT_CONNTREE */
345
346 LDAP_END_DECL
347
348 #include "proto-ldap.h"
349
350 #endif /* SLAPD_LDAP_H */