]> git.sur5r.net Git - openldap/blob - servers/slapd/slap.h
Changes from HEAD for beta
[openldap] / servers / slapd / slap.h
1 /* slap.h - stand alone ldap server include file */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7
8 #ifndef _SLAP_H_
9 #define _SLAP_H_
10
11 #include "ldap_defaults.h"
12
13 #include <stdio.h>
14 #include <ac/stdlib.h>
15
16 #include <sys/types.h>
17 #include <ac/syslog.h>
18 #include <ac/regex.h>
19 #include <ac/signal.h>
20 #include <ac/socket.h>
21 #include <ac/time.h>
22 #include <ac/param.h>
23
24 #include "avl.h"
25
26 #ifndef ldap_debug
27 #define ldap_debug slap_debug
28 #endif
29
30 #include "ldap_log.h"
31
32 #include <ldap.h>
33 #include <ldap_schema.h>
34
35 #include "lber_pvt.h"
36 #include "ldap_pvt_thread.h"
37 #include "ldap_queue.h"
38
39 #define SLAP_EXTENDED_SCHEMA 1
40
41 LDAP_BEGIN_DECL
42 /*
43  * SLAPD Memory allocation macros
44  *
45  * Unlike ch_*() routines, these routines do not assert() upon
46  * allocation error.  They are intended to be used instead of
47  * ch_*() routines where the caller has implemented proper
48  * checking for and handling of allocation errors.
49  *
50  * Patches to convert ch_*() calls to SLAP_*() calls welcomed.
51  */
52 #define SLAP_MALLOC(s)      ber_memalloc((s))
53 #define SLAP_CALLOC(n,s)    ber_memcalloc((n),(s))
54 #define SLAP_REALLOC(p,s)   ber_memrealloc((p),(s))
55 #define SLAP_FREE(p)        ber_memfree((p))
56 #define SLAP_VFREE(v)       ber_memvfree((void**)(v))
57 #define SLAP_STRDUP(s)      ber_strdup((s))
58 #define SLAP_STRNDUP(s,l)   ber_strndup((s),(l))
59
60 #ifdef f_next
61 #undef f_next /* name conflict between sys/file.h on SCO and struct filter */
62 #endif
63
64 #define SERVICE_NAME  OPENLDAP_PACKAGE "-slapd"
65 #define SLAPD_ANONYMOUS "cn=anonymous"
66
67 /* LDAPMod.mod_op value ===> Must be kept in sync with ldap.h!
68  * This is a value used internally by the backends. It is needed to allow
69  * adding values that already exist without getting an error as required by
70  * modrdn when the new rdn was already an attribute value itself.
71  */
72 #define SLAP_MOD_SOFTADD        0x1000
73
74 #define MAXREMATCHES (100)
75
76 #define SLAP_MAX_WORKER_THREADS         (16)
77
78 #define SLAP_MAX_SYNCREPL_THREADS       (8)
79
80 #define SLAP_SB_MAX_INCOMING_DEFAULT ((1<<18) - 1)
81 #define SLAP_SB_MAX_INCOMING_AUTH ((1<<24) - 1)
82
83 #define SLAP_CONN_MAX_PENDING_DEFAULT   100
84 #define SLAP_CONN_MAX_PENDING_AUTH      1000
85
86 #define SLAP_TEXT_BUFLEN (256)
87
88 /* psuedo error code indicating abandoned operation */
89 #define SLAPD_ABANDON (-1)
90
91 /* psuedo error code indicating disconnect */
92 #define SLAPD_DISCONNECT (-2)
93
94
95 /* We assume "C" locale, that is US-ASCII */
96 #define ASCII_SPACE(c)  ( (c) == ' ' )
97 #define ASCII_LOWER(c)  ( (c) >= 'a' && (c) <= 'z' )
98 #define ASCII_UPPER(c)  ( (c) >= 'A' && (c) <= 'Z' )
99 #define ASCII_ALPHA(c)  ( ASCII_LOWER(c) || ASCII_UPPER(c) )
100 #define ASCII_DIGIT(c)  ( (c) >= '0' && (c) <= '9' )
101 #define ASCII_ALNUM(c)  ( ASCII_ALPHA(c) || ASCII_DIGIT(c) )
102 #define ASCII_PRINTABLE(c) ( (c) >= ' ' && (c) <= '~' )
103
104 #define SLAP_NIBBLE(c) ((c)&0x0f)
105 #define SLAP_ESCAPE_CHAR ('\\')
106 #define SLAP_ESCAPE_LO(c) ( "0123456789ABCDEF"[SLAP_NIBBLE(c)] )
107 #define SLAP_ESCAPE_HI(c) ( SLAP_ESCAPE_LO((c)>>4) )
108
109 #define FILTER_ESCAPE(c) ( (c) == '*' || (c) == '\\' \
110         || (c) == '(' || (c) == ')' || !ASCII_PRINTABLE(c) )
111
112 #define DN_ESCAPE(c)    ((c) == SLAP_ESCAPE_CHAR)
113 #define DN_SEPARATOR(c) ((c) == ',' || (c) == ';')
114 #define RDN_ATTRTYPEANDVALUE_SEPARATOR(c) ((c) == '+') /* RFC 2253 */
115 #define RDN_SEPARATOR(c) (DN_SEPARATOR(c) || RDN_ATTRTYPEANDVALUE_SEPARATOR(c))
116 #define RDN_NEEDSESCAPE(c)      ((c) == '\\' || (c) == '"')
117
118 #define DESC_LEADCHAR(c)        ( ASCII_ALPHA(c) )
119 #define DESC_CHAR(c)    ( ASCII_ALNUM(c) || (c) == '-' )
120 #define OID_LEADCHAR(c) ( ASCII_DIGIT(c) )
121 #define OID_SEPARATOR(c)        ( (c) == '.' )
122 #define OID_CHAR(c)     ( OID_LEADCHAR(c) || OID_SEPARATOR(c) )
123
124 #define ATTR_LEADCHAR(c)        ( DESC_LEADCHAR(c) || OID_LEADCHAR(c) )
125 #define ATTR_CHAR(c)    ( DESC_CHAR((c)) || (c) == '.' )
126
127 #define AD_LEADCHAR(c)  ( ATTR_CHAR(c) )
128 #define AD_CHAR(c)              ( ATTR_CHAR(c) || (c) == ';' )
129
130 #define SLAP_NUMERIC(c) ( ASCII_DIGIT(c) || ASCII_SPACE(c) )
131
132 #define SLAP_PRINTABLE(c)       ( ASCII_ALNUM(c) || (c) == '\'' || \
133         (c) == '(' || (c) == ')' || (c) == '+' || (c) == ',' || \
134         (c) == '-' || (c) == '.' || (c) == '/' || (c) == ':' || \
135         (c) == '?' || (c) == ' ' || (c) == '=' )
136 #define SLAP_PRINTABLES(c)      ( SLAP_PRINTABLE(c) || (c) == '$' )
137
138 /* must match in schema_init.c */
139 #define SLAPD_DN_SYNTAX                 "1.3.6.1.4.1.1466.115.121.1.12"
140 #define SLAPD_NAMEUID_SYNTAX    "1.3.6.1.4.1.1466.115.121.1.34"
141 #define SLAPD_INTEGER_SYNTAX    "1.3.6.1.4.1.1466.115.121.1.27"
142 #define SLAPD_GROUP_ATTR                "member"
143 #define SLAPD_GROUP_CLASS               "groupOfNames"
144 #define SLAPD_ROLE_ATTR                 "roleOccupant"
145 #define SLAPD_ROLE_CLASS                "organizationalRole"
146
147 #ifdef SLAPD_ACI_ENABLED
148 #define SLAPD_ACI_SYNTAX                "1.3.6.1.4.1.4203.666.2.1"
149 #endif
150
151 /* change this to "OpenLDAPset" */
152 #define SLAPD_ACI_SET_ATTR              "template"
153
154 #define SLAPD_TOP_OID                   "2.5.6.0"
155
156 LDAP_SLAPD_V (int) slap_debug;
157
158 typedef unsigned long slap_mask_t;
159
160 /* Security Strength Factor */
161 typedef unsigned slap_ssf_t;
162
163 typedef struct slap_ssf_set {
164         slap_ssf_t sss_ssf;
165         slap_ssf_t sss_transport;
166         slap_ssf_t sss_tls;
167         slap_ssf_t sss_sasl;
168         slap_ssf_t sss_update_ssf;
169         slap_ssf_t sss_update_transport;
170         slap_ssf_t sss_update_tls;
171         slap_ssf_t sss_update_sasl;
172         slap_ssf_t sss_simple_bind;
173 } slap_ssf_set_t;
174
175 /* Flags for telling slap_sasl_getdn() what type of identity is being passed */
176 #define SLAP_GETDN_AUTHCID 2
177 #define SLAP_GETDN_AUTHZID 4
178
179 /*
180  * Index types
181  */
182 #define SLAP_INDEX_TYPE           0x00FFUL
183 #define SLAP_INDEX_UNDEFINED      0x0001UL
184 #define SLAP_INDEX_PRESENT        0x0002UL
185 #define SLAP_INDEX_EQUALITY       0x0004UL
186 #define SLAP_INDEX_APPROX         0x0008UL
187 #define SLAP_INDEX_SUBSTR         0x0010UL
188 #define SLAP_INDEX_EXTENDED               0x0020UL
189
190 #define SLAP_INDEX_DEFAULT        SLAP_INDEX_EQUALITY
191
192 #define IS_SLAP_INDEX(mask, type)       (((mask) & (type)) == (type))
193
194 #define SLAP_INDEX_SUBSTR_TYPE    0x0F00UL
195
196 #define SLAP_INDEX_SUBSTR_INITIAL ( SLAP_INDEX_SUBSTR | 0x0100UL ) 
197 #define SLAP_INDEX_SUBSTR_ANY     ( SLAP_INDEX_SUBSTR | 0x0200UL )
198 #define SLAP_INDEX_SUBSTR_FINAL   ( SLAP_INDEX_SUBSTR | 0x0400UL )
199 #define SLAP_INDEX_SUBSTR_DEFAULT \
200         ( SLAP_INDEX_SUBSTR \
201         | SLAP_INDEX_SUBSTR_INITIAL \
202         | SLAP_INDEX_SUBSTR_ANY \
203         | SLAP_INDEX_SUBSTR_FINAL )
204
205 #define SLAP_INDEX_SUBSTR_MINLEN        2
206 #define SLAP_INDEX_SUBSTR_MAXLEN        4
207 #define SLAP_INDEX_SUBSTR_STEP  2
208
209 #define SLAP_INDEX_FLAGS         0xF000UL
210 #define SLAP_INDEX_NOSUBTYPES    0x1000UL /* don't use index w/ subtypes */
211 #define SLAP_INDEX_NOTAGS        0x2000UL /* don't use index w/ tags */
212
213 /*
214  * there is a single index for each attribute.  these prefixes ensure
215  * that there is no collision among keys.
216  */
217 #define SLAP_INDEX_EQUALITY_PREFIX      '='     /* prefix for equality keys     */
218 #define SLAP_INDEX_APPROX_PREFIX        '~'             /* prefix for approx keys       */
219 #define SLAP_INDEX_SUBSTR_PREFIX        '*'             /* prefix for substring keys    */
220 #define SLAP_INDEX_SUBSTR_INITIAL_PREFIX '^'
221 #define SLAP_INDEX_SUBSTR_FINAL_PREFIX '$'
222 #define SLAP_INDEX_CONT_PREFIX          '.'             /* prefix for continuation keys */
223
224 #define SLAP_SYNTAX_MATCHINGRULES_OID    "1.3.6.1.4.1.1466.115.121.1.30"
225 #define SLAP_SYNTAX_ATTRIBUTETYPES_OID   "1.3.6.1.4.1.1466.115.121.1.3"
226 #define SLAP_SYNTAX_OBJECTCLASSES_OID    "1.3.6.1.4.1.1466.115.121.1.37"
227 #define SLAP_SYNTAX_MATCHINGRULEUSES_OID "1.3.6.1.4.1.1466.115.121.1.31"
228 #define SLAP_SYNTAX_CONTENTRULE_OID              "1.3.6.1.4.1.1466.115.121.1.16"
229
230 /*
231  * represents schema information for a database
232  */
233 #define SLAP_SCHERR_OUTOFMEM                    1
234 #define SLAP_SCHERR_CLASS_NOT_FOUND             2
235 #define SLAP_SCHERR_CLASS_BAD_USAGE             3
236 #define SLAP_SCHERR_CLASS_BAD_SUP               4
237 #define SLAP_SCHERR_CLASS_DUP                   5
238 #define SLAP_SCHERR_ATTR_NOT_FOUND              6
239 #define SLAP_SCHERR_ATTR_BAD_MR                 7
240 #define SLAP_SCHERR_ATTR_BAD_USAGE              8
241 #define SLAP_SCHERR_ATTR_BAD_SUP                9
242 #define SLAP_SCHERR_ATTR_INCOMPLETE             10
243 #define SLAP_SCHERR_ATTR_DUP                    11
244 #define SLAP_SCHERR_MR_NOT_FOUND                12
245 #define SLAP_SCHERR_MR_INCOMPLETE               13
246 #define SLAP_SCHERR_MR_DUP                              14
247 #define SLAP_SCHERR_SYN_NOT_FOUND               15
248 #define SLAP_SCHERR_SYN_DUP                             16
249 #define SLAP_SCHERR_NO_NAME                             17
250 #define SLAP_SCHERR_NOT_SUPPORTED               18
251 #define SLAP_SCHERR_BAD_DESCR                   19
252 #define SLAP_SCHERR_OIDM                                20
253 #define SLAP_SCHERR_CR_DUP                              21
254 #define SLAP_SCHERR_CR_BAD_STRUCT               22
255 #define SLAP_SCHERR_CR_BAD_AUX                  23
256 #define SLAP_SCHERR_CR_BAD_AT                   24
257 #define SLAP_SCHERR_LAST                                SLAP_SCHERR_CR_BAD_AT
258
259 typedef union slap_sockaddr {
260         struct sockaddr sa_addr;
261         struct sockaddr_in sa_in_addr;
262 #ifdef LDAP_PF_INET6
263         struct sockaddr_storage sa_storage;
264         struct sockaddr_in6 sa_in6_addr;
265 #endif
266 #ifdef LDAP_PF_LOCAL
267         struct sockaddr_un sa_un_addr;
268 #endif
269 } Sockaddr;
270
271 #ifdef LDAP_PF_INET6
272 extern int slap_inet4or6;
273 #endif
274
275 typedef struct slap_oid_macro {
276         struct berval som_oid;
277         char **som_names;
278         LDAP_SLIST_ENTRY(slap_oid_macro) som_next;
279 } OidMacro;
280
281 /* forward declarations */
282 struct slap_syntax;
283 struct slap_matching_rule;
284
285 typedef int slap_syntax_validate_func LDAP_P((
286         struct slap_syntax *syntax,
287         struct berval * in));
288
289 typedef int slap_syntax_transform_func LDAP_P((
290         struct slap_syntax *syntax,
291         struct berval * in,
292         struct berval * out,
293         void *memctx));
294
295 typedef struct slap_syntax {
296         LDAPSyntax                      ssyn_syn;
297 #define ssyn_oid                ssyn_syn.syn_oid
298 #define ssyn_desc               ssyn_syn.syn_desc
299 #define ssyn_extensions ssyn_syn.syn_extensions
300         /*
301          * Note: the former
302         ber_len_t       ssyn_oidlen;
303          * has been replaced by a struct berval that uses the value
304          * provided by ssyn_syn.syn_oid; a macro that expands to
305          * the bv_len field of the berval is provided for backward
306          * compatibility.  CAUTION: NEVER FREE THE BERVAL
307          */
308         struct berval   ssyn_bvoid;
309 #define ssyn_oidlen     ssyn_bvoid.bv_len
310
311         unsigned int ssyn_flags;
312
313 #define SLAP_SYNTAX_NONE        0x0000U
314 #define SLAP_SYNTAX_BLOB        0x0001U /* syntax treated as blob (audio) */
315 #define SLAP_SYNTAX_BINARY      0x0002U /* binary transfer required (certificate) */
316 #define SLAP_SYNTAX_BER         0x0004U /* stored in BER encoding (certificate) */
317 #ifdef LDAP_DEVEL
318 #define SLAP_SYNTAX_HIDE        0x0000U /* publish everything */
319 #else
320 #define SLAP_SYNTAX_HIDE        0x8000U /* hide (do not publish) */
321 #endif
322
323         slap_syntax_validate_func       *ssyn_validate;
324         slap_syntax_transform_func      *ssyn_pretty;
325
326 #ifdef SLAPD_BINARY_CONVERSION
327         /* convert to and from binary */
328         slap_syntax_transform_func      *ssyn_ber2str;
329         slap_syntax_transform_func      *ssyn_str2ber;
330 #endif
331
332         LDAP_SLIST_ENTRY(slap_syntax) ssyn_next;
333 } Syntax;
334
335 #define slap_syntax_is_flag(s,flag) ((int)((s)->ssyn_flags & (flag)) ? 1 : 0)
336 #define slap_syntax_is_blob(s)          slap_syntax_is_flag((s),SLAP_SYNTAX_BLOB)
337 #define slap_syntax_is_binary(s)        slap_syntax_is_flag((s),SLAP_SYNTAX_BINARY)
338 #define slap_syntax_is_ber(s)           slap_syntax_is_flag((s),SLAP_SYNTAX_BER)
339 #define slap_syntax_is_hidden(s)        slap_syntax_is_flag((s),SLAP_SYNTAX_HIDE)
340
341 typedef struct slap_syntax_defs_rec {
342         char *sd_desc;
343         int sd_flags;
344         slap_syntax_validate_func *sd_validate;
345         slap_syntax_transform_func *sd_pretty;
346 #ifdef SLAPD_BINARY_CONVERSION
347         slap_syntax_transform_func *sd_ber2str;
348         slap_syntax_transform_func *sd_str2ber;
349 #endif
350 } slap_syntax_defs_rec;
351
352 /* X -> Y Converter */
353 typedef int slap_mr_convert_func LDAP_P((
354         struct berval * in,
355         struct berval * out,
356         void *memctx ));
357
358 /* Normalizer */
359 typedef int slap_mr_normalize_func LDAP_P((
360         slap_mask_t use,
361         struct slap_syntax *syntax, /* NULL if in is asserted value */
362         struct slap_matching_rule *mr,
363         struct berval * in,
364         struct berval * out,
365         void *memctx ));
366
367 /* Match (compare) function */
368 typedef int slap_mr_match_func LDAP_P((
369         int *match,
370         slap_mask_t use,
371         struct slap_syntax *syntax,     /* syntax of stored value */
372         struct slap_matching_rule *mr,
373         struct berval * value,
374         void * assertValue ));
375
376 /* Index generation function */
377 typedef int slap_mr_indexer_func LDAP_P((
378         slap_mask_t use,
379         slap_mask_t mask,
380         struct slap_syntax *syntax,     /* syntax of stored value */
381         struct slap_matching_rule *mr,
382         struct berval *prefix,
383         BerVarray values,
384         BerVarray *keys,
385         void *memctx ));
386
387 /* Filter index function */
388 typedef int slap_mr_filter_func LDAP_P((
389         slap_mask_t use,
390         slap_mask_t mask,
391         struct slap_syntax *syntax,     /* syntax of stored value */
392         struct slap_matching_rule *mr,
393         struct berval *prefix,
394         void * assertValue,
395         BerVarray *keys,
396         void *memctx ));
397
398 typedef struct slap_matching_rule_use MatchingRuleUse;
399
400 typedef struct slap_matching_rule {
401         LDAPMatchingRule                smr_mrule;
402         MatchingRuleUse                 *smr_mru;
403         /* RFC2252 string representation */
404         struct berval                   smr_str;
405         /*
406          * Note: the former
407          *                      ber_len_t       smr_oidlen;
408          * has been replaced by a struct berval that uses the value
409          * provided by smr_mrule.mr_oid; a macro that expands to
410          * the bv_len field of the berval is provided for backward
411          * compatibility.  CAUTION: NEVER FREE THE BERVAL
412          */
413         struct berval                   smr_bvoid;
414 #define smr_oidlen                      smr_bvoid.bv_len
415
416         slap_mask_t                             smr_usage;
417
418 #ifdef LDAP_DEVEL
419 #define SLAP_MR_HIDE                    0x0000U
420 #else
421 #define SLAP_MR_HIDE                    0x8000U
422 #endif
423
424 #define SLAP_MR_TYPE_MASK               0x0F00U
425 #define SLAP_MR_SUBTYPE_MASK    0x00F0U
426 #define SLAP_MR_USAGE                   0x000FU
427
428 #define SLAP_MR_NONE                    0x0000U
429 #define SLAP_MR_EQUALITY                0x0100U
430 #define SLAP_MR_ORDERING                0x0200U
431 #define SLAP_MR_SUBSTR                  0x0400U
432 #define SLAP_MR_EXT                             0x0800U /* implicitly extensible */
433
434 #define SLAP_MR_EQUALITY_APPROX ( SLAP_MR_EQUALITY | 0x0010U )
435
436 #define SLAP_MR_SUBSTR_INITIAL  ( SLAP_MR_SUBSTR | 0x0010U )
437 #define SLAP_MR_SUBSTR_ANY              ( SLAP_MR_SUBSTR | 0x0020U )
438 #define SLAP_MR_SUBSTR_FINAL    ( SLAP_MR_SUBSTR | 0x0040U )
439
440
441 /*
442  * The asserted value, depending on the particular usage,
443  * is expected to conform to either the assertion syntax
444  * or the attribute syntax.   In some cases, the syntax of
445  * the value is known.  If so, these flags indicate which
446  * syntax the value is expected to conform to.  If not,
447  * neither of these flags is set (until the syntax of the
448  * provided value is determined).  If the value is of the
449  * attribute syntax, the flag is changed once a value of
450  * the assertion syntax is derived from the provided value.
451  */
452 #define SLAP_MR_VALUE_OF_ASSERTION_SYNTAX       0x0001U
453 #define SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX       0x0002U
454
455 #define SLAP_MR_IS_VALUE_OF_ATTRIBUTE_SYNTAX( usage ) \
456         ((usage) & SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX )
457 #define SLAP_MR_IS_VALUE_OF_ASSERTION_SYNTAX( usage ) \
458         ((usage) & SLAP_MR_VALUE_OF_ASSERTION_SYNTAX )
459
460 /* either or both the asserted value or attribute value
461  * may be provided in normalized form
462  */
463 #define SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH         0x0004U
464 #define SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH        0x0008U
465
466 #define SLAP_IS_MR_ASSERTION_SYNTAX_MATCH( usage ) \
467         (!((usage) & SLAP_MR_ATTRIBUTE_SYNTAX_MATCH))
468 #define SLAP_IS_MR_ATTRIBUTE_SYNTAX_MATCH( usage ) \
469         ((usage) & SLAP_MR_ATTRIBUTE_SYNTAX_MATCH)
470
471 #define SLAP_IS_MR_ATTRIBUTE_SYNTAX_CONVERTED_MATCH( usage ) \
472         (((usage) & SLAP_MR_ATTRIBUTE_SYNTAX_CONVERTED_MATCH) \
473                 == SLAP_MR_ATTRIBUTE_SYNTAX_CONVERTED_MATCH)
474 #define SLAP_IS_MR_ATTRIBUTE_SYNTAX_NONCONVERTED_MATCH( usage ) \
475         (((usage) & SLAP_MR_ATTRIBUTE_SYNTAX_CONVERTED_MATCH) \
476                 == SLAP_MR_ATTRIBUTE_SYNTAX_MATCH)
477
478 #define SLAP_IS_MR_ASSERTED_VALUE_NORMALIZED_MATCH( usage ) \
479         ((usage) & SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH )
480 #define SLAP_IS_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH( usage ) \
481         ((usage) & SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH )
482
483         Syntax                                  *smr_syntax;
484         slap_mr_convert_func    *smr_convert;
485         slap_mr_normalize_func  *smr_normalize;
486         slap_mr_match_func              *smr_match;
487         slap_mr_indexer_func    *smr_indexer;
488         slap_mr_filter_func             *smr_filter;
489
490         /*
491          * null terminated array of syntaxes compatible with this syntax
492          * note: when MS_EXT is set, this MUST NOT contain the assertion
493          * syntax of the rule.  When MS_EXT is not set, it MAY.
494          */
495         Syntax                                  **smr_compat_syntaxes;
496
497         /*
498          * For equality rules, refers to an associated approximate rule.
499          * For non-equality rules, refers to an associated equality rule.
500          */
501         struct slap_matching_rule       *smr_associated;
502
503 #define SLAP_MR_ASSOCIATED(mr,amr)      (((mr) == (amr)) || \
504         ((mr)->smr_associated == (amr)))
505
506         LDAP_SLIST_ENTRY(slap_matching_rule)smr_next;
507
508 #define smr_oid                         smr_mrule.mr_oid
509 #define smr_names                       smr_mrule.mr_names
510 #define smr_desc                        smr_mrule.mr_desc
511 #define smr_obsolete            smr_mrule.mr_obsolete
512 #define smr_syntax_oid          smr_mrule.mr_syntax_oid
513 #define smr_extensions          smr_mrule.mr_extensions
514 } MatchingRule;
515
516 struct slap_matching_rule_use {
517         LDAPMatchingRuleUse             smru_mruleuse;
518         MatchingRule                    *smru_mr;
519         /* RFC2252 string representation */
520         struct berval                   smru_str;
521
522         LDAP_SLIST_ENTRY(slap_matching_rule_use) smru_next;
523
524 #define smru_oid                        smru_mruleuse.mru_oid
525 #define smru_names                      smru_mruleuse.mru_names
526 #define smru_desc                       smru_mruleuse.mru_desc
527 #define smru_obsolete                   smru_mruleuse.mru_obsolete
528 #define smru_applies_oids               smru_mruleuse.mru_applies_oids
529
530 #define smru_usage                      smru_mr->smr_usage
531 } /* MatchingRuleUse */ ;
532
533 typedef struct slap_mrule_defs_rec {
534         char *                                          mrd_desc;
535         slap_mask_t                                     mrd_usage;
536         char **                                         mrd_compat_syntaxes;
537         slap_mr_convert_func *          mrd_convert;
538         slap_mr_normalize_func *        mrd_normalize;
539         slap_mr_match_func *            mrd_match;
540         slap_mr_indexer_func *          mrd_indexer;
541         slap_mr_filter_func *           mrd_filter;
542
543         /* For equality rule, this may refer to an associated approximate rule */
544         /* For non-equality rule, this may refer to an associated equality rule */
545         char *                                          mrd_associated;
546 } slap_mrule_defs_rec;
547
548 struct slap_backend_db;
549 struct slap_entry;
550 struct slap_attr;
551
552 typedef int (AttributeTypeSchemaCheckFN)(
553         struct slap_backend_db *be,
554         struct slap_entry *e,
555         struct slap_attr *attr,
556         const char** text,
557         char *textbuf, size_t textlen );
558
559 typedef struct slap_attribute_type {
560         LDAPAttributeType               sat_atype;
561         struct berval                   sat_cname;
562         struct slap_attribute_type      *sat_sup;
563         struct slap_attribute_type      **sat_subtypes;
564         MatchingRule                    *sat_equality;
565         MatchingRule                    *sat_approx;
566         MatchingRule                    *sat_ordering;
567         MatchingRule                    *sat_substr;
568         Syntax                                  *sat_syntax;
569
570         AttributeTypeSchemaCheckFN      *sat_check;
571
572 #define SLAP_AT_NONE            0x0000U
573 #define SLAP_AT_ABSTRACT        0x0100U /* cannot be instantiated */
574 #define SLAP_AT_FINAL           0x0200U /* cannot be subtyped */
575 #ifdef LDAP_DEVEL
576 #define SLAP_AT_HIDE            0x0000U /* publish everything */
577 #else
578 #define SLAP_AT_HIDE            0x8000U /* hide attribute */
579 #endif
580         slap_mask_t                                     sat_flags;
581
582         LDAP_SLIST_ENTRY(slap_attribute_type) sat_next;
583
584 #define sat_oid                         sat_atype.at_oid
585 #define sat_names                       sat_atype.at_names
586 #define sat_desc                        sat_atype.at_desc
587 #define sat_obsolete            sat_atype.at_obsolete
588 #define sat_sup_oid                     sat_atype.at_sup_oid
589 #define sat_equality_oid        sat_atype.at_equality_oid
590 #define sat_ordering_oid        sat_atype.at_ordering_oid
591 #define sat_substr_oid          sat_atype.at_substr_oid
592 #define sat_syntax_oid          sat_atype.at_syntax_oid
593 #define sat_single_value        sat_atype.at_single_value
594 #define sat_collective          sat_atype.at_collective
595 #define sat_no_user_mod         sat_atype.at_no_user_mod
596 #define sat_usage                       sat_atype.at_usage
597 #define sat_extensions          sat_atype.at_extensions
598
599         struct slap_attr_desc           *sat_ad;
600         ldap_pvt_thread_mutex_t         sat_ad_mutex;
601 } AttributeType;
602
603 #define is_at_operational(at)   ((at)->sat_usage)
604 #define is_at_single_value(at)  ((at)->sat_single_value)
605 #define is_at_collective(at)    ((at)->sat_collective)
606 #define is_at_obsolete(at)              ((at)->sat_obsolete)
607 #define is_at_no_user_mod(at)   ((at)->sat_no_user_mod)
608
609 struct slap_object_class;
610
611 typedef int (ObjectClassSchemaCheckFN)(
612         struct slap_backend_db *be,
613         struct slap_entry *e,
614         struct slap_object_class *oc,
615         const char** text,
616         char *textbuf, size_t textlen );
617
618 typedef struct slap_object_class {
619         LDAPObjectClass                 soc_oclass;
620         struct berval                   soc_cname;
621         struct slap_object_class        **soc_sups;
622         AttributeType                           **soc_required;
623         AttributeType                           **soc_allowed;
624         ObjectClassSchemaCheckFN        *soc_check;
625         slap_mask_t                                     soc_flags;
626 #define soc_oid                         soc_oclass.oc_oid
627 #define soc_names                       soc_oclass.oc_names
628 #define soc_desc                        soc_oclass.oc_desc
629 #define soc_obsolete            soc_oclass.oc_obsolete
630 #define soc_sup_oids            soc_oclass.oc_sup_oids
631 #define soc_kind                        soc_oclass.oc_kind
632 #define soc_at_oids_must        soc_oclass.oc_at_oids_must
633 #define soc_at_oids_may         soc_oclass.oc_at_oids_may
634 #define soc_extensions          soc_oclass.oc_extensions
635
636         LDAP_SLIST_ENTRY(slap_object_class) soc_next;
637 } ObjectClass;
638
639 #define SLAP_OC_ALIAS           0x0001
640 #define SLAP_OC_REFERRAL        0x0002
641 #define SLAP_OC_SUBENTRY        0x0004
642 #define SLAP_OC_DYNAMICOBJECT   0x0008
643 #define SLAP_OC_COLLECTIVEATTRIBUTESUBENTRY     0x0010
644 #define SLAP_OC_GLUE            0x0020
645 #define SLAP_OC_SYNCPROVIDERSUBENTRY            0x0040
646 #define SLAP_OC_SYNCCONSUMERSUBENTRY            0x0080
647 #define SLAP_OC__MASK           0x00FF
648 #define SLAP_OC__END            0x0100
649 #define SLAP_OC_OPERATIONAL     0x4000
650 #ifdef LDAP_DEVEL
651 #define SLAP_OC_HIDE            0x0000
652 #else
653 #define SLAP_OC_HIDE            0x8000
654 #endif
655
656 /*
657  * DIT content rule
658  */
659 typedef struct slap_content_rule {
660         LDAPContentRule         scr_crule;
661         ObjectClass                     *scr_sclass;
662         ObjectClass                     **scr_auxiliaries;      /* optional */
663         AttributeType           **scr_required;         /* optional */
664         AttributeType           **scr_allowed;          /* optional */
665         AttributeType           **scr_precluded;        /* optional */
666 #define scr_oid                         scr_crule.cr_oid
667 #define scr_names                       scr_crule.cr_names
668 #define scr_desc                        scr_crule.cr_desc
669 #define scr_obsolete            scr_crule.cr_obsolete
670 #define scr_oc_oids_aux         scr_crule.cr_oc_oids_aux
671 #define scr_at_oids_must        scr_crule.cr_at_oids_must
672 #define scr_at_oids_may         scr_crule.cr_at_oids_may
673 #define scr_at_oids_not         scr_crule.cr_at_oids_not
674
675         LDAP_SLIST_ENTRY( slap_content_rule ) scr_next;
676 } ContentRule;
677
678 /* Represents a recognized attribute description ( type + options ). */
679 typedef struct slap_attr_desc {
680         struct slap_attr_desc *ad_next;
681         AttributeType *ad_type;         /* attribute type, must be specified */
682         struct berval ad_cname;         /* canonical name, must be specified */
683         struct berval ad_tags;          /* empty if no tagging options */
684         unsigned ad_flags;
685 #define SLAP_DESC_NONE                  0x00U
686 #define SLAP_DESC_BINARY                0x01U
687 #define SLAP_DESC_TAG_RANGE             0x80U
688 } AttributeDescription;
689
690 typedef struct slap_attr_name {
691         struct berval an_name;
692         AttributeDescription *an_desc;
693         ObjectClass *an_oc;
694 } AttributeName;
695
696 #define slap_ad_is_tagged(ad)                   ( (ad)->ad_tags.bv_len != 0 )
697 #define slap_ad_is_tag_range(ad)        \
698         ( ((ad)->ad_flags & SLAP_DESC_TAG_RANGE) ? 1 : 0 )
699 #define slap_ad_is_binary(ad)           \
700         ( ((ad)->ad_flags & SLAP_DESC_BINARY) ? 1 : 0 )
701
702 /*
703  * pointers to schema elements used internally
704  */
705 struct slap_internal_schema {
706         /* objectClass */
707         ObjectClass *si_oc_top;
708         ObjectClass *si_oc_extensibleObject;
709         ObjectClass *si_oc_alias;
710         ObjectClass *si_oc_referral;
711         ObjectClass *si_oc_rootdse;
712         ObjectClass *si_oc_subentry;
713         ObjectClass *si_oc_subschema;
714         ObjectClass *si_oc_collectiveAttributeSubentry;
715         ObjectClass *si_oc_dynamicObject;
716
717         ObjectClass *si_oc_glue;
718         ObjectClass *si_oc_syncConsumerSubentry;
719         ObjectClass *si_oc_syncProviderSubentry;
720
721         /* objectClass attribute descriptions */
722         AttributeDescription *si_ad_objectClass;
723
724         /* operational attribute descriptions */
725         AttributeDescription *si_ad_structuralObjectClass;
726         AttributeDescription *si_ad_creatorsName;
727         AttributeDescription *si_ad_createTimestamp;
728         AttributeDescription *si_ad_modifiersName;
729         AttributeDescription *si_ad_modifyTimestamp;
730         AttributeDescription *si_ad_hasSubordinates;
731         AttributeDescription *si_ad_subschemaSubentry;
732         AttributeDescription *si_ad_collectiveSubentries;
733         AttributeDescription *si_ad_collectiveExclusions;
734         AttributeDescription *si_ad_entryUUID;
735         AttributeDescription *si_ad_entryCSN;
736         AttributeDescription *si_ad_namingCSN;
737         AttributeDescription *si_ad_superiorUUID;
738
739         /* LDAP cache specific operational attribute */
740         AttributeDescription *si_ad_queryid;
741
742         AttributeDescription *si_ad_dseType;
743         AttributeDescription *si_ad_syncreplCookie;
744         AttributeDescription *si_ad_contextCSN;
745
746         /* root DSE attribute descriptions */
747         AttributeDescription *si_ad_altServer;
748         AttributeDescription *si_ad_namingContexts;
749         AttributeDescription *si_ad_supportedControl;
750         AttributeDescription *si_ad_supportedExtension;
751         AttributeDescription *si_ad_supportedLDAPVersion;
752         AttributeDescription *si_ad_supportedSASLMechanisms;
753         AttributeDescription *si_ad_supportedFeatures;
754         AttributeDescription *si_ad_monitorContext;
755         AttributeDescription *si_ad_vendorName;
756         AttributeDescription *si_ad_vendorVersion;
757
758         /* subentry attribute descriptions */
759         AttributeDescription *si_ad_administrativeRole;
760         AttributeDescription *si_ad_subtreeSpecification;
761
762         /* subschema subentry attribute descriptions */
763         AttributeDescription *si_ad_ditStructureRules;
764         AttributeDescription *si_ad_ditContentRules;
765         AttributeDescription *si_ad_nameForms;
766         AttributeDescription *si_ad_objectClasses;
767         AttributeDescription *si_ad_attributeTypes;
768         AttributeDescription *si_ad_ldapSyntaxes;
769         AttributeDescription *si_ad_matchingRules;
770         AttributeDescription *si_ad_matchingRuleUse;
771
772         /* Aliases & Referrals */
773         AttributeDescription *si_ad_aliasedObjectName;
774         AttributeDescription *si_ad_ref;
775
776         /* Access Control Internals */
777         AttributeDescription *si_ad_entry;
778         AttributeDescription *si_ad_children;
779         AttributeDescription *si_ad_saslAuthzTo;
780         AttributeDescription *si_ad_saslAuthzFrom;
781 #ifdef SLAPD_ACI_ENABLED
782         AttributeDescription *si_ad_aci;
783 #endif
784
785         /* dynamic entries */
786         AttributeDescription *si_ad_entryTtl;
787         AttributeDescription *si_ad_dynamicSubtrees;
788
789         /* Other attributes descriptions */
790         AttributeDescription *si_ad_distinguishedName;
791         AttributeDescription *si_ad_name;
792         AttributeDescription *si_ad_cn;
793         AttributeDescription *si_ad_userPassword;
794 #ifdef SLAPD_AUTHPASSWD
795         AttributeDescription *si_ad_authPassword;
796 #endif
797 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
798         AttributeDescription *si_ad_krbName;
799 #endif
800         
801         /* Undefined Attribute Type */
802         AttributeType   *si_at_undefined;
803
804         /* Matching Rules */
805         MatchingRule    *si_mr_distinguishedNameMatch;
806         MatchingRule    *si_mr_caseExactMatch;
807         MatchingRule    *si_mr_caseExactSubstringsMatch;
808         MatchingRule    *si_mr_caseExactIA5Match;
809         MatchingRule    *si_mr_integerMatch;
810         MatchingRule    *si_mr_integerFirstComponentMatch;
811         MatchingRule    *si_mr_objectIdentifierFirstComponentMatch;
812
813         /* Syntaxes */
814         Syntax          *si_syn_directoryString;
815         Syntax          *si_syn_distinguishedName;
816         Syntax          *si_syn_integer;
817         Syntax          *si_syn_octetString;
818 };
819
820 typedef struct slap_attr_assertion {
821         AttributeDescription    *aa_desc;
822         struct berval aa_value;
823 } AttributeAssertion;
824
825 typedef struct slap_ss_assertion {
826         AttributeDescription    *sa_desc;
827         struct berval           sa_initial;
828         struct berval           *sa_any;
829         struct berval           sa_final;
830 } SubstringsAssertion;
831
832 typedef struct slap_mr_assertion {
833         MatchingRule            *ma_rule;       /* optional */
834         struct berval           ma_rule_text;  /* optional */
835         AttributeDescription    *ma_desc;       /* optional */
836         int                                             ma_dnattrs; /* boolean */
837         struct berval           ma_value;       /* required */
838 } MatchingRuleAssertion;
839
840 /*
841  * represents a search filter
842  */
843 typedef struct slap_filter {
844         ber_tag_t       f_choice;       /* values taken from ldap.h, plus: */
845 #define SLAPD_FILTER_COMPUTED   ((ber_tag_t) -1)
846 #define SLAPD_FILTER_DN_ONE             ((ber_tag_t) -2)
847 #define SLAPD_FILTER_DN_SUBTREE ((ber_tag_t) -3)
848
849         union f_un_u {
850                 /* precomputed result */
851                 ber_int_t f_un_result;
852
853                 /* DN */
854                 struct berval *f_un_dn;
855
856                 /* present */
857                 AttributeDescription *f_un_desc;
858
859                 /* simple value assertion */
860                 AttributeAssertion *f_un_ava;
861
862                 /* substring assertion */
863                 SubstringsAssertion *f_un_ssa;
864
865                 /* matching rule assertion */
866                 MatchingRuleAssertion *f_un_mra;
867
868 #define f_dn                    f_un.f_un_dn
869 #define f_desc                  f_un.f_un_desc
870 #define f_ava                   f_un.f_un_ava
871 #define f_av_desc               f_un.f_un_ava->aa_desc
872 #define f_av_value              f_un.f_un_ava->aa_value
873 #define f_sub                   f_un.f_un_ssa
874 #define f_sub_desc              f_un.f_un_ssa->sa_desc
875 #define f_sub_initial   f_un.f_un_ssa->sa_initial
876 #define f_sub_any               f_un.f_un_ssa->sa_any
877 #define f_sub_final             f_un.f_un_ssa->sa_final
878 #define f_mra                   f_un.f_un_mra
879 #define f_mr_rule               f_un.f_un_mra->ma_rule
880 #define f_mr_rule_text  f_un.f_un_mra->ma_rule_text
881 #define f_mr_desc               f_un.f_un_mra->ma_desc
882 #define f_mr_value              f_un.f_un_mra->ma_value
883 #define f_mr_dnattrs    f_un.f_un_mra->ma_dnattrs
884
885                 /* and, or, not */
886                 struct slap_filter *f_un_complex;
887         } f_un;
888
889 #define f_result        f_un.f_un_result
890 #define f_and           f_un.f_un_complex
891 #define f_or            f_un.f_un_complex
892 #define f_not           f_un.f_un_complex
893 #define f_list          f_un.f_un_complex
894
895         struct slap_filter      *f_next;
896 } Filter;
897
898 /* compare routines can return undefined */
899 #define SLAPD_COMPARE_UNDEFINED ((ber_int_t) -1)
900
901 typedef struct slap_valuesreturnfilter {
902         ber_tag_t       vrf_choice;
903
904         union vrf_un_u {
905                 /* precomputed result */
906                 ber_int_t vrf_un_result;
907
908                 /* DN */
909                 char *vrf_un_dn;
910
911                 /* present */
912                 AttributeDescription *vrf_un_desc;
913
914                 /* simple value assertion */
915                 AttributeAssertion *vrf_un_ava;
916
917                 /* substring assertion */
918                 SubstringsAssertion *vrf_un_ssa;
919
920                 /* matching rule assertion */
921                 MatchingRuleAssertion *vrf_un_mra;
922
923 #define vrf_result              vrf_un.vrf_un_result
924 #define vrf_dn                  vrf_un.vrf_un_dn
925 #define vrf_desc                vrf_un.vrf_un_desc
926 #define vrf_ava                 vrf_un.vrf_un_ava
927 #define vrf_av_desc             vrf_un.vrf_un_ava->aa_desc
928 #define vrf_av_value    vrf_un.vrf_un_ava->aa_value
929 #define vrf_ssa                 vrf_un.vrf_un_ssa
930 #define vrf_sub                 vrf_un.vrf_un_ssa
931 #define vrf_sub_desc    vrf_un.vrf_un_ssa->sa_desc
932 #define vrf_sub_initial vrf_un.vrf_un_ssa->sa_initial
933 #define vrf_sub_any             vrf_un.vrf_un_ssa->sa_any
934 #define vrf_sub_final   vrf_un.vrf_un_ssa->sa_final
935 #define vrf_mra                 vrf_un.vrf_un_mra
936 #define vrf_mr_rule             vrf_un.vrf_un_mra->ma_rule
937 #define vrf_mr_rule_text        vrf_un.vrf_un_mra->ma_rule_text
938 #define vrf_mr_desc             vrf_un.vrf_un_mra->ma_desc
939 #define vrf_mr_value            vrf_un.vrf_un_mra->ma_value
940 #define vrf_mr_dnattrs  vrf_un.vrf_un_mra->ma_dnattrs
941
942
943         } vrf_un;
944
945         struct slap_valuesreturnfilter  *vrf_next;
946 } ValuesReturnFilter;
947
948 /*
949  * represents an attribute (description + values)
950  */
951 typedef struct slap_attr {
952         AttributeDescription *a_desc;
953         BerVarray       a_vals;         /* preserved values */
954         BerVarray       a_nvals;        /* normalized values */
955         struct slap_attr *a_next;
956         unsigned a_flags;
957 #define SLAP_ATTR_IXADD         0x1U
958 #define SLAP_ATTR_IXDEL         0x2U
959 } Attribute;
960
961
962 /*
963  * the id used in the indexes to refer to an entry
964  */
965 typedef unsigned long   ID;
966 #define NOID    ((ID)~0)
967
968 /*
969  * represents an entry in core
970  */
971 typedef struct slap_entry {
972         /*
973          * The ID field should only be changed before entry is
974          * inserted into a cache.  The ID value is backend
975          * specific.
976          */
977         ID              e_id;
978
979         struct berval e_name;   /* name (DN) of this entry */
980         struct berval e_nname;  /* normalized name (DN) of this entry */
981
982         /* for migration purposes */
983 #define e_dn e_name.bv_val
984 #define e_ndn e_nname.bv_val
985
986         Attribute       *e_attrs;       /* list of attributes + values */
987
988         slap_mask_t     e_ocflags;
989
990         struct berval   e_bv;           /* For entry_encode/entry_decode */
991
992         /* for use by the backend for any purpose */
993         void*   e_private;
994 } Entry;
995
996 /*
997  * A list of LDAPMods
998  */
999 typedef struct slap_mod {
1000         int sm_op;
1001         AttributeDescription *sm_desc;
1002         struct berval sm_type;
1003         BerVarray sm_values;
1004 #define sm_bvalues sm_values
1005         BerVarray sm_nvalues;
1006 } Modification;
1007
1008 typedef struct slap_mod_list {
1009         Modification sml_mod;
1010 #define sml_op          sml_mod.sm_op
1011 #define sml_desc        sml_mod.sm_desc
1012 #define sml_type        sml_mod.sm_type
1013 #define sml_bvalues     sml_mod.sm_values
1014 #define sml_values      sml_mod.sm_values
1015 #define sml_nvalues     sml_mod.sm_nvalues
1016         struct slap_mod_list *sml_next;
1017 } Modifications;
1018
1019 typedef struct slap_ldap_modlist {
1020         LDAPMod ml_mod;
1021         struct slap_ldap_modlist *ml_next;
1022 #define ml_op           ml_mod.mod_op
1023 #define ml_type         ml_mod.mod_type
1024 #define ml_values       ml_mod.mod_values
1025 #define ml_bvalues      ml_mod.mod_values
1026 } LDAPModList;
1027
1028 /*
1029  * represents an access control list
1030  */
1031 typedef enum slap_access_e {
1032         ACL_INVALID_ACCESS = -1,
1033         ACL_NONE = 0,
1034         ACL_AUTH,
1035         ACL_COMPARE,
1036         ACL_SEARCH,
1037         ACL_READ,
1038         ACL_WRITE
1039 } slap_access_t;
1040
1041 typedef enum slap_control_e {
1042         ACL_INVALID_CONTROL     = 0,
1043         ACL_STOP,
1044         ACL_CONTINUE,
1045         ACL_BREAK
1046 } slap_control_t;
1047
1048 typedef enum slap_style_e {
1049         ACL_STYLE_REGEX = 0,
1050         ACL_STYLE_BASE,
1051         ACL_STYLE_ONE,
1052         ACL_STYLE_SUBTREE,
1053         ACL_STYLE_CHILDREN,
1054         ACL_STYLE_ATTROF
1055 } slap_style_t;
1056
1057 typedef struct slap_authz_info {
1058         ber_tag_t       sai_method;             /* LDAP_AUTH_* from <ldap.h> */
1059         struct berval   sai_mech;               /* SASL Mechanism */
1060         struct berval   sai_dn;                 /* DN for reporting purposes */
1061         struct berval   sai_ndn;                /* Normalized DN */
1062
1063         /* Security Strength Factors */
1064         slap_ssf_t      sai_ssf;                        /* Overall SSF */
1065         slap_ssf_t      sai_transport_ssf;      /* Transport SSF */
1066         slap_ssf_t      sai_tls_ssf;            /* TLS SSF */
1067         slap_ssf_t      sai_sasl_ssf;           /* SASL SSF */
1068 } AuthorizationInformation;
1069
1070 /* the "by" part */
1071 typedef struct slap_access {
1072         slap_control_t a_type;
1073
1074 #define ACL_ACCESS2PRIV(access) (0x01U << (access))
1075
1076 #define ACL_PRIV_NONE                   ACL_ACCESS2PRIV( ACL_NONE )
1077 #define ACL_PRIV_AUTH                   ACL_ACCESS2PRIV( ACL_AUTH )
1078 #define ACL_PRIV_COMPARE                ACL_ACCESS2PRIV( ACL_COMPARE )
1079 #define ACL_PRIV_SEARCH                 ACL_ACCESS2PRIV( ACL_SEARCH )
1080 #define ACL_PRIV_READ                   ACL_ACCESS2PRIV( ACL_READ )
1081 #define ACL_PRIV_WRITE                  ACL_ACCESS2PRIV( ACL_WRITE )
1082
1083 #define ACL_PRIV_MASK                   0x00ffUL
1084
1085 /* priv flags */
1086 #define ACL_PRIV_LEVEL                  0x1000UL
1087 #define ACL_PRIV_ADDITIVE               0x2000UL
1088 #define ACL_PRIV_SUBSTRACTIVE   0x4000UL
1089
1090 /* invalid privs */
1091 #define ACL_PRIV_INVALID                0x0UL
1092
1093 #define ACL_PRIV_ISSET(m,p)             (((m) & (p)) == (p))
1094 #define ACL_PRIV_ASSIGN(m,p)    do { (m)  =  (p); } while(0)
1095 #define ACL_PRIV_SET(m,p)               do { (m) |=  (p); } while(0)
1096 #define ACL_PRIV_CLR(m,p)               do { (m) &= ~(p); } while(0)
1097
1098 #define ACL_INIT(m)                             ACL_PRIV_ASSIGN(m, ACL_PRIV_NONE)
1099 #define ACL_INVALIDATE(m)               ACL_PRIV_ASSIGN(m, ACL_PRIV_INVALID)
1100
1101 #define ACL_GRANT(m,a)                  ACL_PRIV_ISSET((m),ACL_ACCESS2PRIV(a))
1102
1103 #define ACL_IS_INVALID(m)               ((m) == ACL_PRIV_INVALID)
1104
1105 #define ACL_IS_LEVEL(m)                 ACL_PRIV_ISSET((m),ACL_PRIV_LEVEL)
1106 #define ACL_IS_ADDITIVE(m)              ACL_PRIV_ISSET((m),ACL_PRIV_ADDITIVE)
1107 #define ACL_IS_SUBTRACTIVE(m)   ACL_PRIV_ISSET((m),ACL_PRIV_SUBSTRACTIVE)
1108
1109 #define ACL_LVL_NONE                    (ACL_PRIV_NONE|ACL_PRIV_LEVEL)
1110 #define ACL_LVL_AUTH                    (ACL_PRIV_AUTH|ACL_LVL_NONE)
1111 #define ACL_LVL_COMPARE                 (ACL_PRIV_COMPARE|ACL_LVL_AUTH)
1112 #define ACL_LVL_SEARCH                  (ACL_PRIV_SEARCH|ACL_LVL_COMPARE)
1113 #define ACL_LVL_READ                    (ACL_PRIV_READ|ACL_LVL_SEARCH)
1114 #define ACL_LVL_WRITE                   (ACL_PRIV_WRITE|ACL_LVL_READ)
1115
1116 #define ACL_LVL(m,l)                    (((m)&ACL_PRIV_MASK) == ((l)&ACL_PRIV_MASK))
1117 #define ACL_LVL_IS_NONE(m)              ACL_LVL((m),ACL_LVL_NONE)
1118 #define ACL_LVL_IS_AUTH(m)              ACL_LVL((m),ACL_LVL_AUTH)
1119 #define ACL_LVL_IS_COMPARE(m)   ACL_LVL((m),ACL_LVL_COMPARE)
1120 #define ACL_LVL_IS_SEARCH(m)    ACL_LVL((m),ACL_LVL_SEARCH)
1121 #define ACL_LVL_IS_READ(m)              ACL_LVL((m),ACL_LVL_READ)
1122 #define ACL_LVL_IS_WRITE(m)             ACL_LVL((m),ACL_LVL_WRITE)
1123
1124 #define ACL_LVL_ASSIGN_NONE(m)          ACL_PRIV_ASSIGN((m),ACL_LVL_NONE)
1125 #define ACL_LVL_ASSIGN_AUTH(m)          ACL_PRIV_ASSIGN((m),ACL_LVL_AUTH)
1126 #define ACL_LVL_ASSIGN_COMPARE(m)       ACL_PRIV_ASSIGN((m),ACL_LVL_COMPARE)
1127 #define ACL_LVL_ASSIGN_SEARCH(m)        ACL_PRIV_ASSIGN((m),ACL_LVL_SEARCH)
1128 #define ACL_LVL_ASSIGN_READ(m)          ACL_PRIV_ASSIGN((m),ACL_LVL_READ)
1129 #define ACL_LVL_ASSIGN_WRITE(m)         ACL_PRIV_ASSIGN((m),ACL_LVL_WRITE)
1130
1131         slap_mask_t     a_access_mask;
1132
1133         AuthorizationInformation        a_authz;
1134 #define a_dn_pat        a_authz.sai_dn
1135
1136         slap_style_t a_dn_style;
1137         AttributeDescription    *a_dn_at;
1138         int                     a_dn_self;
1139         int                     a_dn_expand;
1140
1141         slap_style_t a_peername_style;
1142         struct berval   a_peername_pat;
1143         slap_style_t a_sockname_style;
1144         struct berval   a_sockname_pat;
1145
1146         slap_style_t a_domain_style;
1147         struct berval   a_domain_pat;
1148         int             a_domain_expand;
1149
1150         slap_style_t a_sockurl_style;
1151         struct berval   a_sockurl_pat;
1152         slap_style_t a_set_style;
1153         struct berval   a_set_pat;
1154
1155 #ifdef SLAPD_ACI_ENABLED
1156         AttributeDescription    *a_aci_at;
1157 #endif
1158
1159         /* ACL Groups */
1160         slap_style_t a_group_style;
1161         struct berval   a_group_pat;
1162         ObjectClass                             *a_group_oc;
1163         AttributeDescription    *a_group_at;
1164
1165         struct slap_access      *a_next;
1166 } Access;
1167
1168 /* the "to" part */
1169 typedef struct slap_acl {
1170         /* "to" part: the entries this acl applies to */
1171         Filter          *acl_filter;
1172         slap_style_t acl_dn_style;
1173         regex_t         acl_dn_re;
1174         struct berval   acl_dn_pat;
1175         AttributeName   *acl_attrs;
1176
1177         /* "by" part: list of who has what access to the entries */
1178         Access  *acl_access;
1179
1180         struct slap_acl *acl_next;
1181 } AccessControl;
1182
1183 typedef struct slap_acl_state {
1184         unsigned as_recorded;
1185 #define ACL_STATE_NOT_RECORDED                  0x0
1186 #define ACL_STATE_RECORDED_VD                   0x1
1187 #define ACL_STATE_RECORDED_NV                   0x2
1188 #define ACL_STATE_RECORDED                              0x3
1189
1190         /* Access state */
1191         AccessControl *as_vd_acl;
1192         AccessControl *as_vi_acl;
1193         slap_mask_t as_vd_acl_mask;
1194         regmatch_t as_vd_acl_matches[MAXREMATCHES];
1195         int as_vd_acl_count;
1196
1197         Access *as_vd_access;
1198         int as_vd_access_count;
1199
1200         int as_result;
1201         AttributeDescription *as_vd_ad;
1202 } AccessControlState;
1203 #define ACL_STATE_INIT { ACL_STATE_NOT_RECORDED, NULL, NULL, 0UL, \
1204         { { 0, 0 } }, 0, NULL, 0, 0, NULL }
1205
1206 /*
1207  * Backend-info
1208  * represents a backend 
1209  */
1210
1211 typedef struct slap_backend_info BackendInfo;   /* per backend type */
1212 typedef struct slap_backend_db BackendDB;               /* per backend database */
1213
1214 LDAP_SLAPD_V (int) nBackendInfo;
1215 LDAP_SLAPD_V (int) nBackendDB;
1216 LDAP_SLAPD_V (BackendInfo *) backendInfo;
1217 LDAP_SLAPD_V (BackendDB *) backendDB;
1218
1219 LDAP_SLAPD_V (int) slapMode;    
1220 #define SLAP_UNDEFINED_MODE     0x0000
1221 #define SLAP_SERVER_MODE        0x0001
1222 #define SLAP_TOOL_MODE          0x0002
1223 #define SLAP_MODE                       0x0003
1224
1225 #define SLAP_TRUNCATE_MODE      0x0100
1226 #define SLAP_TOOL_READMAIN      0x0200
1227 #define SLAP_TOOL_READONLY      0x0400
1228
1229 struct slap_replica_info {
1230         char *ri_host;                          /* supersedes be_replica */
1231         BerVarray ri_nsuffix;   /* array of suffixes this replica accepts */
1232         AttributeName *ri_attrs;        /* attrs to replicate, NULL=all */
1233         int ri_exclude;                 /* 1 => exclude ri_attrs */
1234 };
1235
1236 struct slap_limits_set {
1237         /* time limits */
1238         int     lms_t_soft;
1239         int     lms_t_hard;
1240
1241         /* size limits */
1242         int     lms_s_soft;
1243         int     lms_s_hard;
1244         int     lms_s_unchecked;
1245         int     lms_s_pr;
1246         int     lms_s_pr_hide;
1247 };
1248
1249 struct slap_limits {
1250         int     lm_type;        /* type of pattern */
1251 #define SLAP_LIMITS_UNDEFINED   0x0000
1252 #define SLAP_LIMITS_EXACT       0x0001
1253 #define SLAP_LIMITS_BASE        SLAP_LIMITS_EXACT
1254 #define SLAP_LIMITS_ONE         0x0002
1255 #define SLAP_LIMITS_SUBTREE     0x0003
1256 #define SLAP_LIMITS_CHILDREN    0x0004
1257 #define SLAP_LIMITS_REGEX       0x0005
1258 #define SLAP_LIMITS_ANONYMOUS   0x0006
1259 #define SLAP_LIMITS_USERS       0x0007
1260 #define SLAP_LIMITS_ANY         0x0008
1261         regex_t lm_dn_regex;            /* regex data for REGEX */
1262
1263         /*
1264          * normalized DN for EXACT, BASE, ONE, SUBTREE, CHILDREN;
1265          * pattern for REGEX; NULL for ANONYMOUS, USERS
1266          */
1267         struct berval lm_dn_pat;
1268
1269         struct slap_limits_set  lm_limits;
1270 };
1271
1272 /* temporary aliases */
1273 typedef BackendDB Backend;
1274 #define nbackends nBackendDB
1275 #define backends backendDB
1276
1277 struct nonpresent_entry {
1278         struct berval *dn;
1279         struct berval *ndn;
1280         LDAP_LIST_ENTRY(nonpresent_entry) np_link;
1281 };
1282
1283  /*
1284   * syncinfo structure for syncrepl
1285   */
1286 typedef struct syncinfo_s {
1287         struct slap_conn *conn;
1288         struct slap_backend_db *be;
1289         struct slap_entry *e;
1290         void                    *ctx;
1291         int                             id;
1292         char                    *provideruri;
1293         BerVarray               provideruri_bv;
1294 #define TLS_OFF                 0
1295 #define TLS_ON                  1
1296 #define TLS_CRITICAL    2
1297         int                             tls;
1298                 struct berval   updatedn;       
1299         int                             bindmethod;
1300         char                    *binddn;
1301         char                    *passwd;
1302         char                    *saslmech;
1303         char                    *secprops;
1304         char                    *realm;
1305         char                    *authcId;
1306         char                    *authzId;
1307         char                    *srvtab;
1308                 int                             schemachecking;
1309         Filter                  *filter;
1310         char                    *filterstr;
1311         char                    *base;
1312         int                             scope;
1313         int                             attrsonly;
1314         char                    **attrs;
1315         int                             type;
1316         time_t                  interval;
1317         struct berval   *syncCookie;
1318         int                             manageDSAit;
1319         int                             slimit;
1320                 int                             tlimit;
1321         struct berval   *syncUUID;
1322                 struct berval   *syncUUID_ndn;
1323         Avlnode                 *presentlist;
1324                 int                             sync_mode;
1325                 LDAP_LIST_HEAD(np, nonpresent_entry) nonpresentlist;
1326 } syncinfo_t;
1327
1328 struct slap_backend_db {
1329         BackendInfo     *bd_info;       /* pointer to shared backend info */
1330
1331         /* BackendInfo accessors */
1332 #define         be_config       bd_info->bi_db_config
1333 #define         be_type         bd_info->bi_type
1334
1335 #define         be_bind         bd_info->bi_op_bind
1336 #define         be_unbind       bd_info->bi_op_unbind
1337 #define         be_add          bd_info->bi_op_add
1338 #define         be_compare      bd_info->bi_op_compare
1339 #define         be_delete       bd_info->bi_op_delete
1340 #define         be_modify       bd_info->bi_op_modify
1341 #define         be_modrdn       bd_info->bi_op_modrdn
1342 #define         be_search       bd_info->bi_op_search
1343 #define         be_abandon      bd_info->bi_op_abandon
1344 #define         be_cancel       bd_info->bi_op_cancel
1345
1346 #define         be_extended     bd_info->bi_extended
1347
1348 #define         be_fetch        bd_info->bi_entry_get_rw
1349 #define         be_release      bd_info->bi_entry_release_rw
1350 #define         be_chk_referrals        bd_info->bi_chk_referrals
1351 #define         be_group        bd_info->bi_acl_group
1352 #define         be_attribute    bd_info->bi_acl_attribute
1353 #define         be_operational  bd_info->bi_operational
1354
1355 /*
1356  * define to honor hasSubordinates operational attribute in search filters
1357  * (in previous use there was a flaw with back-bdb and back-ldbm; now it 
1358  * is fixed).
1359  */
1360 #define         be_has_subordinates bd_info->bi_has_subordinates
1361
1362 #define         be_controls     bd_info->bi_controls
1363
1364 #define         be_connection_init      bd_info->bi_connection_init
1365 #define         be_connection_destroy   bd_info->bi_connection_destroy
1366
1367 #ifdef SLAPD_TOOLS
1368 #define         be_entry_open bd_info->bi_tool_entry_open
1369 #define         be_entry_close bd_info->bi_tool_entry_close
1370 #define         be_entry_first bd_info->bi_tool_entry_first
1371 #define         be_entry_next bd_info->bi_tool_entry_next
1372 #define         be_entry_reindex bd_info->bi_tool_entry_reindex
1373 #define         be_entry_get bd_info->bi_tool_entry_get
1374 #define         be_entry_put bd_info->bi_tool_entry_put
1375 #define         be_sync bd_info->bi_tool_sync
1376 #define         be_dn2id_get bd_info->bi_tool_dn2id_get
1377 #define         be_id2entry_get bd_info->bi_tool_id2entry_get
1378 #define         be_entry_modify bd_info->bi_tool_entry_modify
1379 #endif
1380
1381 #define SLAP_BFLAG_NOLASTMOD            0x0001U
1382 #define SLAP_BFLAG_NO_SCHEMA_CHECK      0x0002U
1383 #define SLAP_BFLAG_GLUE_INSTANCE        0x0010U /* a glue backend */
1384 #define SLAP_BFLAG_GLUE_SUBORDINATE     0x0020U /* child of a glue hierarchy */
1385 #define SLAP_BFLAG_GLUE_LINKED          0x0040U /* child is connected to parent */
1386 #define SLAP_BFLAG_MONITOR                      0x0080U /* a monitor backend */
1387 #define SLAP_BFLAG_INCREMENT            0x0100U
1388 #define SLAP_BFLAG_ALIASES                      0x1000U
1389 #define SLAP_BFLAG_REFERRALS            0x2000U
1390 #define SLAP_BFLAG_SUBENTRIES           0x4000U
1391 #define SLAP_BFLAG_DYNAMIC                      0x8000U
1392         slap_mask_t     be_flags;
1393 #define SLAP_LASTMOD(be)        (!((be)->be_flags & SLAP_BFLAG_NOLASTMOD))
1394 #define SLAP_NO_SCHEMA_CHECK(be)        (((be)->be_flags & SLAP_BFLAG_NO_SCHEMA_CHECK))
1395 #define SLAP_GLUE_INSTANCE(be)  ((be)->be_flags & SLAP_BFLAG_GLUE_INSTANCE)
1396 #define SLAP_GLUE_SUBORDINATE(be) \
1397         ((be)->be_flags & SLAP_BFLAG_GLUE_SUBORDINATE)
1398 #define SLAP_GLUE_LINKED(be)    ((be)->be_flags & SLAP_BFLAG_GLUE_LINKED)
1399
1400 #define SLAP_MONITOR(be)        ((be)->be_flags & SLAP_BFLAG_MONITOR)
1401 #define SLAP_INCREMENT(be)      ((be)->be_flags & SLAP_BFLAG_INCREMENT)
1402
1403 #define SLAP_ALIASES(be)        ((be)->be_flags & SLAP_BFLAG_ALIASES)
1404 #define SLAP_REFERRALS(be)      ((be)->be_flags & SLAP_BFLAG_REFERRALS)
1405 #define SLAP_SUBENTRIES(be)     ((be)->be_flags & SLAP_BFLAG_SUBENTRIES)
1406 #define SLAP_DYNAMIC(be)        ((be)->be_flags & SLAP_BFLAG_DYNAMIC)
1407
1408
1409         slap_mask_t     be_restrictops;         /* restriction operations */
1410 #define SLAP_RESTRICT_OP_ADD            0x0001U
1411 #define SLAP_RESTRICT_OP_BIND           0x0002U
1412 #define SLAP_RESTRICT_OP_COMPARE        0x0004U
1413 #define SLAP_RESTRICT_OP_DELETE         0x0008U
1414 #define SLAP_RESTRICT_OP_EXTENDED       0x0010U
1415 #define SLAP_RESTRICT_OP_MODIFY         0x0020U
1416 #define SLAP_RESTRICT_OP_RENAME         0x0040U
1417 #define SLAP_RESTRICT_OP_SEARCH         0x0080U
1418
1419 #define SLAP_RESTRICT_OP_READS  \
1420         ( SLAP_RESTRICT_OP_COMPARE      \
1421         | SLAP_RESTRICT_OP_SEARCH )
1422 #define SLAP_RESTRICT_OP_WRITES \
1423         ( SLAP_RESTRICT_OP_ADD    \
1424         | SLAP_RESTRICT_OP_DELETE \
1425         | SLAP_RESTRICT_OP_MODIFY \
1426         | SLAP_RESTRICT_OP_RENAME )
1427
1428 #define SLAP_ALLOW_BIND_V2                      0x0001U /* LDAPv2 bind */
1429 #define SLAP_ALLOW_BIND_ANON_CRED       0x0002U /* cred should be empty */
1430 #define SLAP_ALLOW_BIND_ANON_DN         0x0004U /* dn should be empty */
1431
1432 #define SLAP_ALLOW_UPDATE_ANON          0x0008U /* allow anonymous updates */
1433
1434 #define SLAP_DISALLOW_BIND_ANON         0x0001U /* no anonymous */
1435 #define SLAP_DISALLOW_BIND_SIMPLE       0x0002U /* simple authentication */
1436 #define SLAP_DISALLOW_BIND_KRBV4        0x0004U /* Kerberos V4 authentication */
1437
1438 #define SLAP_DISALLOW_TLS_2_ANON        0x0010U /* StartTLS -> Anonymous */
1439 #define SLAP_DISALLOW_TLS_AUTHC         0x0020U /* TLS while authenticated */
1440
1441 #define SLAP_DISALLOW_AUX_WO_CR         0x4000U
1442
1443         slap_mask_t     be_requires;    /* pre-operation requirements */
1444 #define SLAP_REQUIRE_BIND               0x0001U /* bind before op */
1445 #define SLAP_REQUIRE_LDAP_V3    0x0002U /* LDAPv3 before op */
1446 #define SLAP_REQUIRE_AUTHC              0x0004U /* authentication before op */
1447 #define SLAP_REQUIRE_SASL               0x0008U /* SASL before op  */
1448 #define SLAP_REQUIRE_STRONG             0x0010U /* strong authentication before op */
1449
1450         /* Required Security Strength Factor */
1451         slap_ssf_set_t be_ssf_set;
1452
1453         /* these should be renamed from be_ to bd_ */
1454         BerVarray       be_suffix;      /* the DN suffixes of data in this backend */
1455         BerVarray       be_nsuffix;     /* the normalized DN suffixes in this backend */
1456         struct berval be_schemadn;      /* per-backend subschema subentry DN */
1457         struct berval be_schemandn;     /* normalized subschema DN */
1458         struct berval be_rootdn;        /* the magic "root" name (DN) for this db */
1459         struct berval be_rootndn;       /* the magic "root" normalized name (DN) for this db */
1460         struct berval be_rootpw;        /* the magic "root" password for this db        */
1461         unsigned int be_max_deref_depth; /* limit for depth of an alias deref  */
1462 #define be_sizelimit    be_def_limit.lms_s_soft
1463 #define be_timelimit    be_def_limit.lms_t_soft
1464         struct slap_limits_set be_def_limit; /* default limits */
1465         struct slap_limits **be_limits; /* regex-based size and time limits */
1466         AccessControl *be_acl;  /* access control list for this backend    */
1467         slap_access_t   be_dfltaccess;  /* access given if no acl matches          */
1468         struct slap_replica_info **be_replica;  /* replicas of this backend (in master) */
1469         char    *be_replogfile; /* replication log file (in master)        */
1470         struct berval be_update_ndn;    /* allowed to make changes (in replicas) */
1471         BerVarray       be_update_refs; /* where to refer modifying clients to */
1472         char    *be_realm;
1473         void    *be_private;    /* anything the backend database needs     */
1474
1475         void    *be_pb;         /* Netscape plugin */
1476         LDAP_TAILQ_HEAD( pcl, slap_csn_entry )  be_pending_csn_list;
1477         ldap_pvt_thread_mutex_t                                 be_pcl_mutex;
1478         struct berval                                                   be_context_csn;
1479         ldap_pvt_thread_mutex_t                                 be_context_csn_mutex;
1480         syncinfo_t      *syncinfo;      /* For syncrepl */
1481 };
1482
1483 struct slap_conn;
1484 struct slap_op;
1485
1486 /* Backend function typedefs */
1487 typedef int (BI_init) LDAP_P((BackendInfo *bi));
1488 typedef int (BI_config) LDAP_P((BackendInfo *bi,
1489         const char *fname, int lineno,
1490         int argc, char **argv));
1491 typedef int (BI_open) LDAP_P((BackendInfo *bi));
1492 typedef int (BI_close) LDAP_P((BackendInfo *bi));
1493 typedef int (BI_destroy) LDAP_P((BackendInfo *bi));
1494
1495 typedef int (BI_db_init) LDAP_P((Backend *bd));
1496 typedef int (BI_db_config) LDAP_P((Backend *bd,
1497         const char *fname, int lineno,
1498         int argc, char **argv));
1499 typedef int (BI_db_open) LDAP_P((Backend *bd));
1500 typedef int (BI_db_close) LDAP_P((Backend *bd));
1501 typedef int (BI_db_destroy) LDAP_P((Backend *bd));
1502
1503 typedef struct req_bind_s {
1504         int rb_method;
1505         struct berval rb_cred;
1506         struct berval rb_edn;
1507         slap_ssf_t rb_ssf;
1508 } req_bind_s;
1509
1510 typedef struct req_search_s {
1511         int rs_scope;
1512         int rs_deref;
1513         int rs_slimit;
1514         int rs_tlimit;
1515         int rs_attrsonly;
1516         AttributeName *rs_attrs;
1517         Filter *rs_filter;
1518         struct berval rs_filterstr;
1519 } req_search_s;
1520
1521 typedef struct req_compare_s {
1522         AttributeAssertion *rs_ava;
1523 } req_compare_s;
1524
1525 typedef struct req_modify_s {
1526         Modifications *rs_modlist;
1527 } req_modify_s;
1528
1529 typedef struct req_modrdn_s {
1530         struct berval rs_newrdn;
1531         struct berval rs_nnewrdn;
1532         struct berval *rs_newSup;
1533         struct berval *rs_nnewSup;
1534         int rs_deleteoldrdn;
1535 } req_modrdn_s;
1536
1537 typedef struct req_add_s {
1538         Entry *rs_e;
1539 } req_add_s;
1540
1541 typedef struct req_abandon_s {
1542         ber_int_t rs_msgid;
1543 } req_abandon_s;
1544
1545 typedef struct req_extended_s {
1546         struct berval rs_reqoid;
1547         struct berval *rs_reqdata;
1548 } req_extended_s;
1549
1550 typedef enum slap_reply_e {
1551         REP_RESULT,
1552         REP_SASL,
1553         REP_EXTENDED,
1554         REP_SEARCH,
1555         REP_SEARCHREF,
1556         REP_INTERMEDIATE
1557 } slap_reply_t;
1558
1559 typedef struct rep_sasl_s {
1560         struct berval *r_sasldata;
1561 } rep_sasl_s;
1562
1563 typedef struct rep_extended_s {
1564         const char *r_rspoid;
1565         struct berval *r_rspdata;
1566 } rep_extended_s;
1567
1568 typedef struct rep_search_s {
1569         Entry *r_entry;
1570         AttributeName *r_attrs;
1571         int r_nentries;
1572         BerVarray r_v2ref;
1573 } rep_search_s;
1574
1575 typedef struct slap_rep {
1576         slap_reply_t sr_type;
1577         ber_tag_t sr_tag;
1578         ber_int_t sr_msgid;
1579         ber_int_t sr_err;
1580         const char *sr_matched;
1581         const char *sr_text;
1582         BerVarray sr_ref;
1583         LDAPControl **sr_ctrls;
1584         union sr_u {
1585                 rep_sasl_s sru_sasl;
1586                 rep_extended_s sru_extended;
1587                 rep_search_s sru_search;
1588         } sr_un;
1589 } SlapReply;
1590
1591 /* short hands for response members */
1592 #define sr_attrs sr_un.sru_search.r_attrs
1593 #define sr_entry sr_un.sru_search.r_entry
1594 #define sr_v2ref sr_un.sru_search.r_v2ref
1595 #define sr_nentries sr_un.sru_search.r_nentries
1596 #define sr_rspoid sr_un.sru_extended.r_rspoid
1597 #define sr_rspdata sr_un.sru_extended.r_rspdata
1598 #define sr_sasldata sr_un.sru_sasl.r_sasldata
1599
1600 typedef int (BI_op_bind) LDAP_P(( struct slap_op *op, struct slap_rep *rs ));
1601 typedef int (BI_op_unbind) LDAP_P(( struct slap_op *op, struct slap_rep *rs ));
1602 typedef int (BI_op_search) LDAP_P(( struct slap_op *op, struct slap_rep *rs ));
1603 typedef int (BI_op_compare) LDAP_P(( struct slap_op *op, struct slap_rep *rs ));
1604 typedef int (BI_op_modify) LDAP_P(( struct slap_op *op, struct slap_rep *rs ));
1605 typedef int (BI_op_modrdn) LDAP_P(( struct slap_op *op, struct slap_rep *rs ));
1606 typedef int (BI_op_add) LDAP_P(( struct slap_op *op, struct slap_rep *rs ));
1607 typedef int (BI_op_delete) LDAP_P(( struct slap_op *op, struct slap_rep *rs ));
1608 typedef int (BI_op_abandon) LDAP_P(( struct slap_op *op, struct slap_rep *rs ));
1609 typedef int (BI_op_cancel) LDAP_P(( struct slap_op *op, struct slap_rep *rs ));
1610 typedef int (BI_op_extended) LDAP_P(( struct slap_op *op, struct slap_rep *rs ));
1611 typedef int (BI_entry_release_rw) LDAP_P(( struct slap_op *op, Entry *e, int rw ));
1612 typedef int (BI_entry_get_rw) LDAP_P(( struct slap_op *op, struct berval *ndn,
1613         ObjectClass *oc, AttributeDescription *at, int rw, Entry **e ));
1614 typedef int (BI_chk_referrals) LDAP_P(( struct slap_op *op, struct slap_rep *rs ));
1615 typedef int (BI_operational) LDAP_P(( struct slap_op *op, struct slap_rep *rs, int opattrs, Attribute **ap ));
1616 typedef int (BI_has_subordinates) LDAP_P(( struct slap_op *op, Entry *e, int *hasSubs ));
1617
1618 typedef int (BI_connection_init) LDAP_P((BackendDB *bd,
1619                 struct slap_conn *c));
1620 typedef int (BI_connection_destroy) LDAP_P((BackendDB *bd,
1621                 struct slap_conn *c));
1622
1623 typedef int (BI_tool_entry_open) LDAP_P(( BackendDB *be, int mode ));
1624 typedef int (BI_tool_entry_close) LDAP_P(( BackendDB *be ));
1625 typedef ID (BI_tool_entry_first) LDAP_P(( BackendDB *be ));
1626 typedef ID (BI_tool_entry_next) LDAP_P(( BackendDB *be ));
1627 typedef Entry* (BI_tool_entry_get) LDAP_P(( BackendDB *be, ID id ));
1628 typedef ID (BI_tool_entry_put) LDAP_P(( BackendDB *be, Entry *e, 
1629                         struct berval *text ));
1630 typedef int (BI_tool_entry_reindex) LDAP_P(( BackendDB *be, ID id ));
1631 typedef int (BI_tool_sync) LDAP_P(( BackendDB *be ));
1632 typedef ID (BI_tool_dn2id_get) LDAP_P(( BackendDB *be, struct berval *dn ));
1633 typedef int (BI_tool_id2entry_get) LDAP_P(( BackendDB *be, ID id, Entry **e ));
1634 typedef ID (BI_tool_entry_modify) LDAP_P(( BackendDB *be, Entry *e, 
1635                         struct berval *text ));
1636
1637 struct slap_backend_info {
1638         char    *bi_type; /* type of backend */
1639
1640         /*
1641          * per backend type routines:
1642          * bi_init: called to allocate a backend_info structure,
1643          *              called once BEFORE configuration file is read.
1644          *              bi_init() initializes this structure hence is
1645          *              called directly from be_initialize()
1646          * bi_config: called per 'backend' specific option
1647          *              all such options must before any 'database' options
1648          *              bi_config() is called only from read_config()
1649          * bi_open: called to open each database, called
1650          *              once AFTER configuration file is read but
1651          *              BEFORE any bi_db_open() calls.
1652          *              bi_open() is called from backend_startup()
1653          * bi_close: called to close each database, called
1654          *              once during shutdown after all bi_db_close calls.
1655          *              bi_close() is called from backend_shutdown()
1656          * bi_destroy: called to destroy each database, called
1657          *              once during shutdown after all bi_db_destroy calls.
1658          *              bi_destory() is called from backend_destroy()
1659          */
1660         BI_init *bi_init;
1661         BI_config       *bi_config;
1662         BI_open *bi_open;
1663         BI_close        *bi_close;
1664         BI_destroy      *bi_destroy;
1665
1666         /*
1667          * per database routines:
1668          * bi_db_init: called to initialize each database,
1669          *      called upon reading 'database <type>' 
1670          *      called only from backend_db_init()
1671          * bi_db_config: called to configure each database,
1672          *  called per database to handle per database options
1673          *      called only from read_config()
1674          * bi_db_open: called to open each database
1675          *      called once per database immediately AFTER bi_open()
1676          *      calls but before daemon startup.
1677          *  called only by backend_startup()
1678          * bi_db_close: called to close each database
1679          *      called once per database during shutdown but BEFORE
1680          *  any bi_close call.
1681          *  called only by backend_shutdown()
1682          * bi_db_destroy: called to destroy each database
1683          *  called once per database during shutdown AFTER all
1684          *  bi_close calls but before bi_destory calls.
1685          *  called only by backend_destory()
1686          */
1687         BI_db_init      *bi_db_init;
1688         BI_db_config    *bi_db_config;
1689         BI_db_open      *bi_db_open;
1690         BI_db_close     *bi_db_close;
1691         BI_db_destroy   *bi_db_destroy;
1692
1693         /* LDAP Operations Handling Routines */
1694         BI_op_bind      *bi_op_bind;
1695         BI_op_unbind    *bi_op_unbind;
1696         BI_op_search    *bi_op_search;
1697         BI_op_compare   *bi_op_compare;
1698         BI_op_modify    *bi_op_modify;
1699         BI_op_modrdn    *bi_op_modrdn;
1700         BI_op_add       *bi_op_add;
1701         BI_op_delete    *bi_op_delete;
1702         BI_op_abandon   *bi_op_abandon;
1703         BI_op_cancel    *bi_op_cancel;
1704
1705         /* Extended Operations Helper */
1706         BI_op_extended  *bi_extended;
1707
1708         /* Auxilary Functions */
1709         BI_entry_get_rw         *bi_entry_get_rw;
1710         BI_entry_release_rw     *bi_entry_release_rw;
1711         BI_chk_referrals        *bi_chk_referrals;
1712
1713         BI_operational  *bi_operational;
1714         BI_has_subordinates     *bi_has_subordinates;
1715
1716         BI_connection_init      *bi_connection_init;
1717         BI_connection_destroy   *bi_connection_destroy;
1718
1719         /* hooks for slap tools */
1720         BI_tool_entry_open              *bi_tool_entry_open;
1721         BI_tool_entry_close             *bi_tool_entry_close;
1722         BI_tool_entry_first             *bi_tool_entry_first;
1723         BI_tool_entry_next              *bi_tool_entry_next;
1724         BI_tool_entry_get               *bi_tool_entry_get;
1725         BI_tool_entry_put               *bi_tool_entry_put;
1726         BI_tool_entry_reindex   *bi_tool_entry_reindex;
1727         BI_tool_sync                    *bi_tool_sync;
1728         BI_tool_dn2id_get               *bi_tool_dn2id_get;
1729         BI_tool_id2entry_get    *bi_tool_id2entry_get;
1730         BI_tool_entry_modify    *bi_tool_entry_modify;
1731
1732 #define SLAP_INDEX_ADD_OP               0x0001
1733 #define SLAP_INDEX_DELETE_OP    0x0002
1734
1735         char **bi_controls;             /* supported controls */
1736
1737         unsigned int bi_nDB;    /* number of databases of this type */
1738         void    *bi_private;    /* anything the backend type needs */
1739 };
1740
1741 #define c_authtype      c_authz.sai_method
1742 #define c_authmech      c_authz.sai_mech
1743 #define c_dn            c_authz.sai_dn
1744 #define c_ndn           c_authz.sai_ndn
1745 #define c_ssf                   c_authz.sai_ssf
1746 #define c_transport_ssf c_authz.sai_transport_ssf
1747 #define c_tls_ssf               c_authz.sai_tls_ssf
1748 #define c_sasl_ssf              c_authz.sai_sasl_ssf
1749
1750 #define o_authtype      o_authz.sai_method
1751 #define o_authmech      o_authz.sai_mech
1752 #define o_dn            o_authz.sai_dn
1753 #define o_ndn           o_authz.sai_ndn
1754 #define o_ssf                   o_authz.sai_ssf
1755 #define o_transport_ssf o_authz.sai_transport_ssf
1756 #define o_tls_ssf               o_authz.sai_tls_ssf
1757 #define o_sasl_ssf              o_authz.sai_sasl_ssf
1758
1759 typedef int (slap_response)( struct slap_op *, struct slap_rep * );
1760
1761 typedef struct slap_callback {
1762         slap_response *sc_response;
1763         void *sc_private;
1764 } slap_callback;
1765
1766 struct slap_overinfo;
1767
1768 typedef struct slap_overinst {
1769         BackendInfo on_bi;
1770         slap_response *on_response;
1771         struct slap_overinfo *on_info;
1772         struct slap_overinst *on_next;
1773 } slap_overinst;
1774
1775 typedef struct slap_overinfo {
1776         BackendInfo oi_bi;
1777         BackendDB oi_bd;
1778         slap_overinst *oi_list;
1779 } slap_overinfo;
1780
1781 /* Should successive callbacks in a chain be processed? */
1782 #define SLAP_CB_CONTINUE        0x8000
1783
1784 /*
1785  * Paged Results state
1786  */
1787 typedef unsigned long PagedResultsCookie;
1788 typedef struct slap_paged_state {
1789         Backend *ps_be;
1790         PagedResultsCookie ps_cookie;
1791         ID ps_id;
1792 } PagedResultsState;
1793
1794
1795 #define LDAP_PSEARCH_BY_ADD                     0x01
1796 #define LDAP_PSEARCH_BY_DELETE          0x02
1797 #define LDAP_PSEARCH_BY_PREMODIFY       0x03
1798 #define LDAP_PSEARCH_BY_MODIFY          0x04
1799 #define LDAP_PSEARCH_BY_SCOPEOUT        0x05
1800
1801 struct psid_entry {
1802         struct slap_op *ps_op;
1803         LDAP_LIST_ENTRY(psid_entry) ps_link;
1804 };
1805
1806 struct slap_csn_entry {
1807         struct berval *csn;
1808         unsigned long opid;
1809         unsigned long connid;
1810 #define SLAP_CSN_PENDING        1
1811 #define SLAP_CSN_COMMIT         2
1812         long state;
1813         LDAP_TAILQ_ENTRY (slap_csn_entry) csn_link;
1814 };
1815
1816 /*
1817  * represents an operation pending from an ldap client
1818  */
1819 typedef struct slap_op {
1820         unsigned long o_opid;   /* id of this operation */
1821         unsigned long o_connid; /* id of conn initiating this op */
1822         struct slap_conn *o_conn;       /* connection spawning this op */
1823         BackendDB       *o_bd;  /* backend DB processing this op */
1824
1825         ber_int_t       o_msgid;        /* msgid of the request */
1826         ber_int_t       o_protocol;     /* version of the LDAP protocol used by client */
1827         ber_tag_t       o_tag;          /* tag of the request */
1828         time_t          o_time;         /* time op was initiated */
1829
1830         struct berval   o_req_dn;       /* DN of target of request */
1831         struct berval   o_req_ndn;
1832
1833         union o_req_u {
1834                 req_add_s oq_add;
1835                 req_bind_s oq_bind;
1836                 req_compare_s oq_compare;
1837                 req_modify_s oq_modify;
1838                 req_modrdn_s oq_modrdn;
1839                 req_search_s oq_search;
1840                 req_abandon_s oq_abandon;
1841                 req_abandon_s oq_cancel;
1842                 req_extended_s oq_extended;
1843         } o_request;
1844
1845 /* short hands for union members */
1846 #define oq_add o_request.oq_add
1847 #define oq_bind o_request.oq_bind
1848 #define oq_compare o_request.oq_compare
1849 #define oq_modify o_request.oq_modify
1850 #define oq_modrdn o_request.oq_modrdn
1851 #define oq_search o_request.oq_search
1852 #define oq_abandon o_request.oq_abandon
1853 #define oq_cancel o_request.oq_cancel
1854 #define oq_extended o_request.oq_extended
1855
1856 /* short hands for inner request members */
1857 #define orb_method oq_bind.rb_method
1858 #define orb_cred oq_bind.rb_cred
1859 #define orb_edn oq_bind.rb_edn
1860 #define orb_ssf oq_bind.rb_ssf
1861
1862 #define ors_scope oq_search.rs_scope
1863 #define ors_deref oq_search.rs_deref
1864 #define ors_slimit oq_search.rs_slimit
1865 #define ors_tlimit oq_search.rs_tlimit
1866 #define ors_attrsonly oq_search.rs_attrsonly
1867 #define ors_attrs oq_search.rs_attrs
1868 #define ors_filter oq_search.rs_filter
1869 #define ors_filterstr oq_search.rs_filterstr
1870
1871 #define orr_newrdn oq_modrdn.rs_newrdn
1872 #define orr_nnewrdn oq_modrdn.rs_nnewrdn
1873 #define orr_newSup oq_modrdn.rs_newSup
1874 #define orr_nnewSup oq_modrdn.rs_nnewSup
1875 #define orr_deleteoldrdn oq_modrdn.rs_deleteoldrdn
1876
1877 #define orc_ava oq_compare.rs_ava
1878 #define ora_e oq_add.rs_e
1879 #define orn_msgid oq_abandon.rs_msgid
1880 #define orm_modlist oq_modify.rs_modlist
1881
1882 #define ore_reqoid oq_extended.rs_reqoid
1883 #define ore_reqdata oq_extended.rs_reqdata
1884
1885         ldap_pvt_thread_t       o_tid;  /* thread handling this op */
1886
1887         volatile sig_atomic_t o_abandon;        /* abandon flag */
1888         volatile sig_atomic_t o_cancel;         /* cancel flag */
1889 #define SLAP_CANCEL_NONE                                0x00
1890 #define SLAP_CANCEL_REQ                                 0x01
1891 #define SLAP_CANCEL_ACK                                 0x02
1892 #define SLAP_CANCEL_DONE                                0x03
1893
1894         char o_do_not_cache;    /* don't cache from this op */
1895         char o_is_auth_check;   /* authorization in progress */
1896
1897 #define SLAP_NO_CONTROL 0
1898 #define SLAP_NONCRITICAL_CONTROL 1
1899 #define SLAP_CRITICAL_CONTROL 2
1900         char o_managedsait;
1901 #define get_manageDSAit(op)                             ((int)(op)->o_managedsait)
1902
1903         char o_noop;
1904         char o_proxy_authz;
1905
1906         char o_subentries;
1907 #define get_subentries(op)                              ((int)(op)->o_subentries)
1908         char o_subentries_visibility;
1909 #define get_subentries_visibility(op)   ((int)(op)->o_subentries_visibility)
1910
1911         char o_assert;
1912 #define get_assert(op)                                  ((int)(op)->o_assert)
1913
1914         char o_valuesreturnfilter;
1915
1916 #ifdef LDAP_CONTROL_X_PERMISSIVE_MODIFY
1917         char o_permissive_modify;
1918 #define get_permissiveModify(op)                ((int)(op)->o_permissive_modify)
1919 #else
1920 #define get_permissiveModify(op)                (0)
1921 #endif
1922
1923 #ifdef LDAP_CONTROL_X_DOMAIN_SCOPE
1924         char o_domain_scope;
1925 #define get_domainScope(op)                             ((int)(op)->o_domain_scope)
1926 #else
1927 #define get_domainScope(op)                             (0)
1928 #endif
1929
1930         char o_preread;
1931         char o_postread;
1932         AttributeName *o_preread_attrs;
1933         AttributeName *o_postread_attrs;
1934
1935 #ifdef LDAP_CONTROL_PAGEDRESULTS
1936         char o_pagedresults;
1937 #define get_pagedresults(op)                    ((int)(op)->o_pagedresults)
1938         ber_int_t o_pagedresults_size;
1939         PagedResultsState o_pagedresults_state;
1940 #else
1941 #define get_pagedresults(op)                    (0)
1942 #endif
1943
1944         char o_sync;
1945         char o_sync_mode;
1946 #define SLAP_SYNC_NONE                          (0x0)
1947 #define SLAP_SYNC_REFRESH                       (0x1)
1948 #define SLAP_SYNC_PERSIST                       (0x2)
1949 #define SLAP_SYNC_REFRESH_AND_PERSIST           (0x3)
1950         struct berval o_sync_state;
1951
1952         int o_ps_entries;
1953         LDAP_LIST_ENTRY(slap_op) o_ps_link;
1954         LDAP_LIST_HEAD(pe, psid_entry) o_pm_list;
1955
1956         AuthorizationInformation o_authz;
1957
1958         BerElement      *o_ber;         /* ber of the request */
1959         BerElement      *o_res_ber;     /* ber of the CLDAP reply or readback control */
1960         slap_callback *o_callback;      /* callback pointers */
1961         LDAPControl     **o_ctrls;       /* controls */
1962
1963         void    *o_threadctx;           /* thread pool thread context */
1964         void    *o_tmpmemctx;           /* slab malloc context */
1965         BerMemoryFunctions *o_tmpmfuncs;
1966 #define o_tmpalloc      o_tmpmfuncs->bmf_malloc
1967 #define o_tmpcalloc     o_tmpmfuncs->bmf_calloc
1968 #define o_tmprealloc    o_tmpmfuncs->bmf_realloc
1969 #define o_tmpfree       o_tmpmfuncs->bmf_free
1970         void    *o_private;     /* anything the backend needs */
1971
1972         LDAP_STAILQ_ENTRY(slap_op)      o_next; /* next operation in list         */
1973
1974         Filter *o_assertion; /* Assert control filter */
1975 #define get_assertion(op)                               ((op)->o_assertion)
1976
1977         ValuesReturnFilter *o_vrFilter; /* ValuesReturnFilter */
1978
1979         syncinfo_t*     o_si;
1980
1981 #ifdef LDAP_SLAPI
1982         void    *o_pb;                  /* NS-SLAPI plugin */
1983         void    *o_extensions;          /* NS-SLAPI plugin */
1984 #endif
1985 } Operation;
1986
1987 #define send_ldap_error( op, rs, err, text ) do { \
1988                 (rs)->sr_err = err; (rs)->sr_text = text; \
1989                 (op->o_conn->c_send_ldap_result)( op, rs ); \
1990         } while (0)
1991 #define send_ldap_discon( op, rs, err, text ) do { \
1992                 (rs)->sr_err = err; (rs)->sr_text = text; \
1993                 send_ldap_disconnect( op, rs ); \
1994         } while (0)
1995
1996 typedef void (SEND_LDAP_RESULT)(
1997         struct slap_op *op, struct slap_rep *rs);
1998 typedef int (SEND_SEARCH_ENTRY)(
1999         struct slap_op *op, struct slap_rep *rs);
2000 typedef int (SEND_SEARCH_REFERENCE)(
2001         struct slap_op *op, struct slap_rep *rs);
2002 typedef void (SEND_LDAP_EXTENDED)(
2003         struct slap_op *op, struct slap_rep *rs);
2004 typedef void (SEND_LDAP_INTERMEDIATE)(
2005         struct slap_op *op, struct slap_rep *rs);
2006
2007 #define send_ldap_result( op, rs ) \
2008         (op->o_conn->c_send_ldap_result)( op, rs )
2009 #define send_search_entry( op, rs ) \
2010         (op->o_conn->c_send_search_entry)( op, rs )
2011 #define send_search_reference( op, rs ) \
2012         (op->o_conn->c_send_search_reference)( op, rs )
2013 #define send_ldap_extended( op, rs ) \
2014         (op->o_conn->c_send_ldap_extended)( op, rs )
2015 #define send_ldap_intermediate( op, rs ) \
2016         (op->o_conn->c_send_ldap_intermediate)( op, rs )
2017
2018 /*
2019  * Caches the result of a backend_group check for ACL evaluation
2020  */
2021 typedef struct slap_gacl {
2022         struct slap_gacl *ga_next;
2023         Backend *ga_be;
2024         ObjectClass *ga_oc;
2025         AttributeDescription *ga_at;
2026         int ga_res;
2027         ber_len_t ga_len;
2028         char ga_ndn[1];
2029 } GroupAssertion;
2030
2031 typedef struct slap_listener Listener;
2032
2033 /*
2034  * represents a connection from an ldap client
2035  */
2036 typedef struct slap_conn {
2037         int                     c_struct_state; /* structure management state */
2038         int                     c_conn_state;   /* connection state */
2039
2040         ldap_pvt_thread_mutex_t c_mutex; /* protect the connection */
2041         Sockbuf         *c_sb;                  /* ber connection stuff           */
2042
2043         /* only can be changed by connect_init */
2044         time_t          c_starttime;    /* when the connection was opened */
2045         time_t          c_activitytime; /* when the connection was last used */
2046         unsigned long           c_connid;       /* id of this connection for stats*/
2047
2048         struct berval   c_peer_domain;  /* DNS name of client */
2049         struct berval   c_peer_name;    /* peer name (trans=addr:port) */
2050         Listener        *c_listener;
2051 #define c_listener_url c_listener->sl_url       /* listener URL */
2052 #define c_sock_name c_listener->sl_name /* sock name (trans=addr:port) */
2053
2054         /* only can be changed by binding thread */
2055         int             c_sasl_bind_in_progress;        /* multi-op bind in progress */
2056         struct berval   c_sasl_bind_mech;                       /* mech in progress */
2057         struct berval   c_sasl_dn;      /* temporary storage */
2058
2059         /* authorization backend */
2060         Backend *c_authz_backend;
2061
2062         AuthorizationInformation c_authz;
2063         GroupAssertion *c_groups;
2064
2065         ber_int_t       c_protocol;     /* version of the LDAP protocol used by client */
2066
2067         LDAP_STAILQ_HEAD(c_o, slap_op) c_ops;   /* list of operations being processed */
2068         LDAP_STAILQ_HEAD(c_po, slap_op) c_pending_ops;  /* list of pending operations */
2069
2070         ldap_pvt_thread_mutex_t c_write_mutex;  /* only one pdu written at a time */
2071         ldap_pvt_thread_cond_t  c_write_cv;             /* used to wait for sd write-ready*/
2072
2073         BerElement      *c_currentber;  /* ber we're attempting to read */
2074         int             c_writewaiter;  /* true if writer is waiting */
2075
2076 #ifdef LDAP_CONNECTIONLESS
2077         int     c_is_udp;               /* true if this is (C)LDAP over UDP */
2078 #endif
2079 #ifdef HAVE_TLS
2080         int     c_is_tls;               /* true if this LDAP over raw TLS */
2081         int     c_needs_tls_accept;     /* true if SSL_accept should be called */
2082 #endif
2083         int             c_sasl_layers;   /* true if we need to install SASL i/o handlers */
2084         int     c_sasl_done;            /* SASL completed once */
2085         void    *c_sasl_authctx;        /* SASL authentication context */
2086         void    *c_sasl_sockctx;        /* SASL security layer context */
2087         void    *c_sasl_extra;          /* SASL session extra stuff */
2088         struct slap_op  *c_sasl_bindop; /* set to current op if it's a bind */
2089
2090         PagedResultsState c_pagedresults_state; /* paged result state */
2091
2092         long    c_n_ops_received;       /* num of ops received (next op_id) */
2093         long    c_n_ops_executing;      /* num of ops currently executing */
2094         long    c_n_ops_pending;        /* num of ops pending execution */
2095         long    c_n_ops_completed;      /* num of ops completed */
2096
2097         long    c_n_get;                /* num of get calls */
2098         long    c_n_read;               /* num of read calls */
2099         long    c_n_write;              /* num of write calls */
2100
2101         void    *c_pb;                  /* Netscape plugin */
2102         void    *c_extensions;          /* Netscape plugin */
2103
2104         /*
2105          * These are the "callbacks" that are available for back-ends to
2106          * supply data back to connected clients that are connected
2107          * through the "front-end".
2108          */
2109         SEND_LDAP_RESULT *c_send_ldap_result;
2110         SEND_SEARCH_ENTRY *c_send_search_entry;
2111         SEND_SEARCH_REFERENCE *c_send_search_reference;
2112         SEND_LDAP_EXTENDED *c_send_ldap_extended;
2113 #ifdef LDAP_RES_INTERMEDIATE
2114         SEND_LDAP_INTERMEDIATE *c_send_ldap_intermediate;
2115 #endif
2116
2117 } Connection;
2118
2119 #if defined(LDAP_SYSLOG) && defined(LDAP_DEBUG)
2120 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 )  \
2121         do { \
2122                 if ( ldap_debug & (level) ) \
2123                         fprintf( stderr, (fmt), (connid), (opid), (arg1), (arg2), (arg3) );\
2124                 if ( ldap_syslog & (level) ) \
2125                         syslog( ldap_syslog_level, (fmt), (connid), (opid), (arg1), \
2126                                 (arg2), (arg3) ); \
2127         } while (0)
2128 #define StatslogTest( level ) ((ldap_debug | ldap_syslog) & (level))
2129 #elif defined(LDAP_DEBUG)
2130 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 )  \
2131         do { \
2132                 if ( ldap_debug & (level) ) \
2133                         fprintf( stderr, (fmt), (connid), (opid), (arg1), (arg2), (arg3) );\
2134         } while (0)
2135 #define StatslogTest( level ) (ldap_debug & (level))
2136 #else
2137 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 )
2138 #define StatslogTest( level ) (0)
2139 #endif
2140
2141 /*
2142  * listener; need to access it from monitor backend
2143  */
2144 struct slap_listener {
2145         struct berval sl_url;
2146         struct berval sl_name;
2147         mode_t  sl_perms;
2148 #ifdef HAVE_TLS
2149         int             sl_is_tls;
2150 #endif
2151 #ifdef LDAP_CONNECTIONLESS
2152         int     sl_is_udp;              /* UDP listener is also data port */
2153 #endif
2154         int     sl_is_mute;     /* Listening is temporarily disabled */
2155         ber_socket_t sl_sd;
2156         Sockaddr sl_sa;
2157 #define sl_addr sl_sa.sa_in_addr
2158 };
2159
2160 #ifdef SLAPD_MONITOR
2161 /*
2162  * Operation indices
2163  */
2164 enum {
2165         SLAP_OP_BIND = 0,
2166         SLAP_OP_UNBIND,
2167         SLAP_OP_ADD,
2168         SLAP_OP_DELETE,
2169         SLAP_OP_MODRDN,
2170         SLAP_OP_MODIFY,
2171         SLAP_OP_COMPARE,
2172         SLAP_OP_SEARCH,
2173         SLAP_OP_ABANDON,
2174         SLAP_OP_EXTENDED,
2175         SLAP_OP_LAST
2176 };
2177 #endif /* SLAPD_MONITOR */
2178
2179 /*
2180  * Better know these all around slapd
2181  */
2182 #define SLAP_LDAPDN_PRETTY 0x1
2183 #define SLAP_LDAPDN_MAXLEN 8192
2184
2185 /* number of response controls supported */
2186 #define SLAP_MAX_RESPONSE_CONTROLS   6
2187
2188 #ifdef LDAP_DEVEL
2189 #define SLAP_CTRL_HIDE                          0x00000000U
2190 #else
2191 #define SLAP_CTRL_HIDE                          0x80000000U
2192 #endif
2193
2194 #define SLAP_CTRL_FRONTEND                      0x00800000U
2195 #define SLAP_CTRL_FRONTEND_SEARCH       0x00010000U     /* for NOOP */
2196
2197 #define SLAP_CTRL_OPFLAGS                       0x0000FFFFU
2198 #define SLAP_CTRL_ABANDON                       0x00000001U
2199 #define SLAP_CTRL_ADD                           0x00002002U
2200 #define SLAP_CTRL_BIND                          0x00000004U
2201 #define SLAP_CTRL_COMPARE                       0x00001008U
2202 #define SLAP_CTRL_DELETE                        0x00002010U
2203 #define SLAP_CTRL_MODIFY                        0x00002020U
2204 #define SLAP_CTRL_RENAME                        0x00002040U
2205 #define SLAP_CTRL_SEARCH                        0x00001080U
2206 #define SLAP_CTRL_UNBIND                        0x00000100U
2207
2208 #define SLAP_CTRL_INTROGATE     (SLAP_CTRL_COMPARE|SLAP_CTRL_SEARCH)
2209 #define SLAP_CTRL_UPDATE \
2210         (SLAP_CTRL_ADD|SLAP_CTRL_DELETE|SLAP_CTRL_MODIFY|SLAP_CTRL_RENAME)
2211 #define SLAP_CTRL_ACCESS        (SLAP_CTRL_INTROGATE|SLAP_CTRL_UPDATE)
2212
2213 typedef int (SLAP_CTRL_PARSE_FN) LDAP_P((
2214         Operation *op,
2215         SlapReply *rs,
2216         LDAPControl *ctrl ));
2217
2218 LDAP_END_DECL
2219
2220 #include "proto-slap.h"
2221
2222 #endif /* _SLAP_H_ */