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