]> git.sur5r.net Git - openldap/blob - servers/slapd/slap.h
af09fec6d601aa9b1806eb41f5414b7f6161d5eb
[openldap] / servers / slapd / slap.h
1 /* slap.h - stand alone ldap server include file */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2002 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 "ldap_pvt_thread.h"
36 #include "ldap_queue.h"
37
38 #define SLAP_EXTENDED_SCHEMA 1
39
40 LDAP_BEGIN_DECL
41 /*
42  * SLAPD Memory allocation macros
43  *
44  * Unlike ch_*() routines, these routines do not assert() upon
45  * allocation error.  They are intended to be used instead of
46  * ch_*() routines where the caller has implemented proper
47  * checking for and handling of allocation errors.
48  *
49  * Patches to convert ch_*() calls to SLAP_*() calls welcomed.
50  */
51 #define SLAP_MALLOC(s)      ber_memalloc((s))
52 #define SLAP_CALLOC(n,s)    ber_memcalloc((n),(s))
53 #define SLAP_REALLOC(p,s)   ber_memrealloc((p),(s))
54 #define SLAP_FREE(p)        ber_memfree((p))
55 #define SLAP_VFREE(v)       ber_memvfree((void**)(v))
56 #define SLAP_STRDUP(s)      ber_strdup((s))
57 #define SLAP_STRNDUP(s,l)   ber_strndup((s),(l))
58
59 #ifdef f_next
60 #undef f_next /* name conflict between sys/file.h on SCO and struct filter */
61 #endif
62
63 #define SERVICE_NAME  OPENLDAP_PACKAGE "-slapd"
64 #define SLAPD_ANONYMOUS "cn=anonymous"
65
66 /* LDAPMod.mod_op value ===> Must be kept in sync with ldap.h!
67  *
68  * This is a value used internally by the backends. It is needed to allow
69  * adding values that already exist without getting an error as required by
70  * modrdn when the new rdn was already an attribute value itself.
71  * JCG 05/1999 (gomez@engr.sgi.com)
72  */
73 #define SLAP_MOD_SOFTADD        0x1000
74
75 #define MAXREMATCHES (100)
76
77 #define SLAP_MAX_WORKER_THREADS         (32)
78
79 #define SLAP_SB_MAX_INCOMING_DEFAULT ((1<<18) - 1)
80 #define SLAP_SB_MAX_INCOMING_AUTH ((1<<24) - 1)
81
82 #define SLAP_TEXT_BUFLEN (256)
83
84 /* psuedo error code indicating abandoned operation */
85 #define SLAPD_ABANDON (-1)
86
87 /* psuedo error code indicating disconnect */
88 #define SLAPD_DISCONNECT (-2)
89
90
91 /* We assume "C" locale, that is US-ASCII */
92 #define ASCII_SPACE(c)  ( (c) == ' ' )
93 #define ASCII_LOWER(c)  ( (c) >= 'a' && (c) <= 'z' )
94 #define ASCII_UPPER(c)  ( (c) >= 'A' && (c) <= 'Z' )
95 #define ASCII_ALPHA(c)  ( ASCII_LOWER(c) || ASCII_UPPER(c) )
96 #define ASCII_DIGIT(c)  ( (c) >= '0' && (c) <= '9' )
97 #define ASCII_ALNUM(c)  ( ASCII_ALPHA(c) || ASCII_DIGIT(c) )
98 #define ASCII_PRINTABLE(c) ( (c) >= ' ' && (c) <= '~' )
99
100 #define SLAP_NIBBLE(c) ((c)&0x0f)
101 #define SLAP_ESCAPE_CHAR ('\\')
102 #define SLAP_ESCAPE_LO(c) ( "0123456789ABCDEF"[SLAP_NIBBLE(c)] )
103 #define SLAP_ESCAPE_HI(c) ( SLAP_ESCAPE_LO((c)>>4) )
104
105 #define FILTER_ESCAPE(c) ( (c) == '*' || (c) == '\\' \
106         || (c) == '(' || (c) == ')' || !ASCII_PRINTABLE(c) )
107
108 #define DN_ESCAPE(c)    ((c) == SLAP_ESCAPE_CHAR)
109 #define DN_SEPARATOR(c) ((c) == ',' || (c) == ';')
110 #define RDN_ATTRTYPEANDVALUE_SEPARATOR(c) ((c) == '+') /* RFC 2253 */
111 #define RDN_SEPARATOR(c) (DN_SEPARATOR(c) || RDN_ATTRTYPEANDVALUE_SEPARATOR(c))
112 #define RDN_NEEDSESCAPE(c)      ((c) == '\\' || (c) == '"')
113
114 #define DESC_LEADCHAR(c)        ( ASCII_ALPHA(c) )
115 #define DESC_CHAR(c)    ( ASCII_ALNUM(c) || (c) == '-' )
116 #define OID_LEADCHAR(c) ( ASCII_DIGIT(c) )
117 #define OID_SEPARATOR(c)        ( (c) == '.' )
118 #define OID_CHAR(c)     ( OID_LEADCHAR(c) || OID_SEPARATOR(c) )
119
120 #define ATTR_LEADCHAR(c)        ( DESC_LEADCHAR(c) || OID_LEADCHAR(c) )
121 #define ATTR_CHAR(c)    ( DESC_CHAR((c)) || (c) == '.' )
122
123 #define AD_LEADCHAR(c)  ( ATTR_CHAR(c) )
124 #define AD_CHAR(c)              ( ATTR_CHAR(c) || (c) == ';' )
125
126 #define SLAP_NUMERIC(c) ( ASCII_DIGIT(c) || ASCII_SPACE(c) )
127
128 #define SLAP_PRINTABLE(c)       ( ASCII_ALNUM(c) || (c) == '\'' || \
129         (c) == '(' || (c) == ')' || (c) == '+' || (c) == ',' || \
130         (c) == '-' || (c) == '.' || (c) == '/' || (c) == ':' || \
131         (c) == '?' || (c) == ' ' || (c) == '=' )
132 #define SLAP_PRINTABLES(c)      ( SLAP_PRINTABLE(c) || (c) == '$' )
133
134 /* must match in schema_init.c */
135 #define SLAPD_DN_SYNTAX                 "1.3.6.1.4.1.1466.115.121.1.12"
136 #define SLAPD_NAMEUID_SYNTAX    "1.3.6.1.4.1.1466.115.121.1.34"
137 #define SLAPD_GROUP_ATTR                "member"
138 #define SLAPD_GROUP_CLASS               "groupOfNames"
139 #define SLAPD_ROLE_ATTR                 "roleOccupant"
140 #define SLAPD_ROLE_CLASS                "organizationalRole"
141
142 #ifdef SLAPD_ACI_ENABLED
143 #define SLAPD_ACI_SYNTAX                "1.3.6.1.4.1.4203.666.2.1"
144 #endif
145
146 #define SLAPD_OCTETSTRING_SYNTAX "1.3.6.1.4.1.1466.115.121.1.40"
147
148 /* change this to "OpenLDAPset" */
149 #define SLAPD_ACI_SET_ATTR              "template"
150
151 #define SLAPD_TOP_OID                   "2.5.6.0"
152
153 LDAP_SLAPD_V (int) slap_debug;
154
155 typedef unsigned long slap_mask_t;
156
157 /* Security Strength Factor */
158 typedef unsigned slap_ssf_t;
159
160 typedef struct slap_ssf_set {
161         slap_ssf_t sss_ssf;
162         slap_ssf_t sss_transport;
163         slap_ssf_t sss_tls;
164         slap_ssf_t sss_sasl;
165         slap_ssf_t sss_update_ssf;
166         slap_ssf_t sss_update_transport;
167         slap_ssf_t sss_update_tls;
168         slap_ssf_t sss_update_sasl;
169         slap_ssf_t sss_simple_bind;
170 } slap_ssf_set_t;
171
172
173 /* Flags for telling slap_sasl_getdn() what type of identity is being passed */
174 #define SLAP_GETDN_AUTHCID 2
175 #define SLAP_GETDN_AUTHZID 4
176
177 /*
178  * Index types
179  */
180 #define SLAP_INDEX_TYPE           0x00FFUL
181 #define SLAP_INDEX_UNDEFINED      0x0001UL
182 #define SLAP_INDEX_PRESENT        0x0002UL
183 #define SLAP_INDEX_EQUALITY       0x0004UL
184 #define SLAP_INDEX_APPROX         0x0008UL
185 #define SLAP_INDEX_SUBSTR         0x0010UL
186 #define SLAP_INDEX_EXTENDED               0x0020UL
187
188 #define SLAP_INDEX_DEFAULT        SLAP_INDEX_EQUALITY
189
190 #define IS_SLAP_INDEX(mask, type)       (((mask) & (type)) == (type))
191
192 #define SLAP_INDEX_SUBSTR_TYPE    0x0F00UL
193
194 #define SLAP_INDEX_SUBSTR_INITIAL ( SLAP_INDEX_SUBSTR | 0x0100UL ) 
195 #define SLAP_INDEX_SUBSTR_ANY     ( SLAP_INDEX_SUBSTR | 0x0200UL )
196 #define SLAP_INDEX_SUBSTR_FINAL   ( SLAP_INDEX_SUBSTR | 0x0400UL )
197 #define SLAP_INDEX_SUBSTR_DEFAULT \
198         ( SLAP_INDEX_SUBSTR \
199         | SLAP_INDEX_SUBSTR_INITIAL \
200         | SLAP_INDEX_SUBSTR_ANY \
201         | SLAP_INDEX_SUBSTR_FINAL )
202
203 #define SLAP_INDEX_SUBSTR_MINLEN        2
204 #define SLAP_INDEX_SUBSTR_MAXLEN        4
205 #define SLAP_INDEX_SUBSTR_STEP  2
206
207 #define SLAP_INDEX_FLAGS         0xF000UL
208 #define SLAP_INDEX_NOSUBTYPES    0x1000UL /* don't use index w/ subtypes */
209 #define SLAP_INDEX_NOLANG        0x2000UL /* don't use index w/ lang */
210
211 /*
212  * there is a single index for each attribute.  these prefixes ensure
213  * that there is no collision among keys.
214  */
215 #define SLAP_INDEX_EQUALITY_PREFIX      '='     /* prefix for equality keys     */
216 #define SLAP_INDEX_APPROX_PREFIX        '~'             /* prefix for approx keys       */
217 #define SLAP_INDEX_SUBSTR_PREFIX        '*'             /* prefix for substring keys    */
218 #define SLAP_INDEX_SUBSTR_INITIAL_PREFIX '^'
219 #define SLAP_INDEX_SUBSTR_FINAL_PREFIX '$'
220 #define SLAP_INDEX_CONT_PREFIX          '.'             /* prefix for continuation keys */
221
222 #define SLAP_SYNTAX_MATCHINGRULES_OID    "1.3.6.1.4.1.1466.115.121.1.30"
223 #define SLAP_SYNTAX_ATTRIBUTETYPES_OID   "1.3.6.1.4.1.1466.115.121.1.3"
224 #define SLAP_SYNTAX_OBJECTCLASSES_OID    "1.3.6.1.4.1.1466.115.121.1.37"
225 #define SLAP_SYNTAX_MATCHINGRULEUSES_OID "1.3.6.1.4.1.1466.115.121.1.31"
226 #define SLAP_SYNTAX_CONTENTRULE_OID              "1.3.6.1.4.1.1466.115.121.1.16"
227
228 #ifdef LDAP_CLIENT_UPDATE
229 #define LCUP_COOKIE_OID "1.3.6.1.4.1.4203.666.10.1"
230 #endif /* LDAP_CLIENT_UPDATE */
231
232 /*
233  * represents schema information for a database
234  */
235 #define SLAP_SCHERR_OUTOFMEM                    1
236 #define SLAP_SCHERR_CLASS_NOT_FOUND             2
237 #define SLAP_SCHERR_CLASS_BAD_USAGE             3
238 #define SLAP_SCHERR_CLASS_BAD_SUP               4
239 #define SLAP_SCHERR_CLASS_DUP                   5
240 #define SLAP_SCHERR_ATTR_NOT_FOUND              6
241 #define SLAP_SCHERR_ATTR_BAD_MR                 7
242 #define SLAP_SCHERR_ATTR_BAD_USAGE              8
243 #define SLAP_SCHERR_ATTR_BAD_SUP                9
244 #define SLAP_SCHERR_ATTR_INCOMPLETE             10
245 #define SLAP_SCHERR_ATTR_DUP                    11
246 #define SLAP_SCHERR_MR_NOT_FOUND                12
247 #define SLAP_SCHERR_MR_INCOMPLETE               13
248 #define SLAP_SCHERR_MR_DUP                              14
249 #define SLAP_SCHERR_SYN_NOT_FOUND               15
250 #define SLAP_SCHERR_SYN_DUP                             16
251 #define SLAP_SCHERR_NO_NAME                             17
252 #define SLAP_SCHERR_NOT_SUPPORTED               18
253 #define SLAP_SCHERR_BAD_DESCR                   19
254 #define SLAP_SCHERR_OIDM                                20
255 #define SLAP_SCHERR_CR_DUP                              21
256 #define SLAP_SCHERR_CR_BAD_STRUCT               22
257 #define SLAP_SCHERR_CR_BAD_AUX                  23
258 #define SLAP_SCHERR_CR_BAD_AT                   24
259 #define SLAP_SCHERR_LAST                                SLAP_SCHERR_CR_BAD_AT
260
261 typedef union slap_sockaddr {
262         struct sockaddr sa_addr;
263         struct sockaddr_in sa_in_addr;
264 #ifdef LDAP_PF_INET6
265         struct sockaddr_storage sa_storage;
266         struct sockaddr_in6 sa_in6_addr;
267 #endif
268 #ifdef LDAP_PF_LOCAL
269         struct sockaddr_un sa_un_addr;
270 #endif
271 } Sockaddr;
272
273 #ifdef LDAP_PF_INET6
274 extern int slap_inet4or6;
275 #endif
276
277 typedef struct slap_oid_macro {
278         struct berval som_oid;
279         char **som_names;
280         struct slap_oid_macro *som_next;
281 } OidMacro;
282
283 /* forward declarations */
284 struct slap_syntax;
285 struct slap_matching_rule;
286
287 typedef int slap_syntax_validate_func LDAP_P((
288         struct slap_syntax *syntax,
289         struct berval * in));
290
291 typedef int slap_syntax_transform_func LDAP_P((
292         struct slap_syntax *syntax,
293         struct berval * in,
294         struct berval * out));
295
296 typedef struct slap_syntax {
297         LDAPSyntax                      ssyn_syn;
298 #define ssyn_oid                ssyn_syn.syn_oid
299 #define ssyn_desc               ssyn_syn.syn_desc
300 #define ssyn_extensions         ssyn_syn.syn_extensions
301         /*
302          * Note: the former
303         ber_len_t       ssyn_oidlen;
304          * has been replaced by a struct berval that uses the value
305          * provided by ssyn_syn.syn_oid; a macro that expands to
306          * the bv_len field of the berval is provided for backward
307          * compatibility.  CAUTION: NEVER FREE THE BERVAL
308          */
309         struct berval   ssyn_bvoid;
310 #define ssyn_oidlen     ssyn_bvoid.bv_len
311
312         unsigned int ssyn_flags;
313
314 #define SLAP_SYNTAX_NONE        0x0000U
315 #define SLAP_SYNTAX_BLOB        0x0001U /* syntax treated as blob (audio) */
316 #define SLAP_SYNTAX_BINARY      0x0002U /* binary transfer required (certificate) */
317 #define SLAP_SYNTAX_BER         0x0004U /* stored in BER encoding (certificate) */
318 #define SLAP_SYNTAX_HIDE        0x8000U /* hide (do not publish) */
319
320         slap_syntax_validate_func       *ssyn_validate;
321         slap_syntax_transform_func      *ssyn_normalize;
322         slap_syntax_transform_func      *ssyn_pretty;
323
324 #ifdef SLAPD_BINARY_CONVERSION
325         /* convert to and from binary */
326         slap_syntax_transform_func      *ssyn_ber2str;
327         slap_syntax_transform_func      *ssyn_str2ber;
328 #endif
329
330         struct slap_syntax              *ssyn_next;
331 } Syntax;
332
333 #define slap_syntax_is_flag(s,flag) ((int)((s)->ssyn_flags & (flag)) ? 1 : 0)
334 #define slap_syntax_is_blob(s)          slap_syntax_is_flag((s),SLAP_SYNTAX_BLOB)
335 #define slap_syntax_is_binary(s)        slap_syntax_is_flag((s),SLAP_SYNTAX_BINARY)
336 #define slap_syntax_is_ber(s)           slap_syntax_is_flag((s),SLAP_SYNTAX_BER)
337 #define slap_syntax_is_hidden(s)        slap_syntax_is_flag((s),SLAP_SYNTAX_HIDE)
338
339 typedef struct slap_syntax_defs_rec {
340         char *sd_desc;
341         int sd_flags;
342         slap_syntax_validate_func *sd_validate;
343         slap_syntax_transform_func *sd_normalize;
344         slap_syntax_transform_func *sd_pretty;
345 #ifdef SLAPD_BINARY_CONVERSION
346         slap_syntax_transform_func *sd_ber2str;
347         slap_syntax_transform_func *sd_str2ber;
348 #endif
349 } slap_syntax_defs_rec;
350
351 /* X -> Y Converter */
352 typedef int slap_mr_convert_func LDAP_P((
353         struct berval * in,
354         struct berval * out ));
355
356 /* Normalizer */
357 typedef int slap_mr_normalize_func LDAP_P((
358         slap_mask_t use,
359         struct slap_syntax *syntax, /* NULL if in is asserted value */
360         struct slap_matching_rule *mr,
361         struct berval * in,
362         struct berval * out ));
363
364 /* Match (compare) function */
365 typedef int slap_mr_match_func LDAP_P((
366         int *match,
367         slap_mask_t use,
368         struct slap_syntax *syntax,     /* syntax of stored value */
369         struct slap_matching_rule *mr,
370         struct berval * value,
371         void * assertValue ));
372
373 /* Index generation function */
374 typedef int slap_mr_indexer_func LDAP_P((
375         slap_mask_t use,
376         slap_mask_t mask,
377         struct slap_syntax *syntax,     /* syntax of stored value */
378         struct slap_matching_rule *mr,
379         struct berval *prefix,
380         BerVarray values,
381         BerVarray *keys ));
382
383 /* Filter index function */
384 typedef int slap_mr_filter_func LDAP_P((
385         slap_mask_t use,
386         slap_mask_t mask,
387         struct slap_syntax *syntax,     /* syntax of stored value */
388         struct slap_matching_rule *mr,
389         struct berval *prefix,
390         void * assertValue,
391         BerVarray *keys ));
392
393 typedef struct slap_matching_rule_use MatchingRuleUse;
394
395 typedef struct slap_matching_rule {
396         LDAPMatchingRule                smr_mrule;
397         MatchingRuleUse                 *smr_mru;
398         /* RFC2252 string representation */
399         struct berval                   smr_str;
400         /*
401          * Note: the former
402         ber_len_t       smr_oidlen;
403          * has been replaced by a struct berval that uses the value
404          * provided by smr_mrule.mr_oid; a macro that expands to
405          * the bv_len field of the berval is provided for backward
406          * compatibility.  CAUTION: NEVER FREE THE BERVAL
407          */
408         struct berval                   smr_bvoid;
409 #define smr_oidlen                      smr_bvoid.bv_len
410
411         slap_mask_t                             smr_usage;
412
413 #define SLAP_MR_HIDE                    0x8000U
414
415 #define SLAP_MR_TYPE_MASK               0x0F00U
416 #define SLAP_MR_SUBTYPE_MASK    0x00F0U
417 #define SLAP_MR_USAGE                   0x000FU
418
419 #define SLAP_MR_NONE                    0x0000U
420 #define SLAP_MR_EQUALITY                0x0100U
421 #define SLAP_MR_ORDERING                0x0200U
422 #define SLAP_MR_SUBSTR                  0x0400U
423 #define SLAP_MR_EXT                             0x0800U /* implicitly extensible */
424
425 #define SLAP_MR_EQUALITY_APPROX ( SLAP_MR_EQUALITY | 0x0010U )
426 #define SLAP_MR_DN_FOLD                 0x0008U
427
428 #define SLAP_MR_SUBSTR_INITIAL  ( SLAP_MR_SUBSTR | 0x0010U )
429 #define SLAP_MR_SUBSTR_ANY              ( SLAP_MR_SUBSTR | 0x0020U )
430 #define SLAP_MR_SUBSTR_FINAL    ( SLAP_MR_SUBSTR | 0x0040U )
431
432 /*
433  * normally the provided value is expected to conform to
434  * assertion syntax specified in the matching rule, however
435  * at times (such as during individual value modification),
436  * the provided value is expected to conform to the
437  * attribute's value syntax.
438  */
439 #define SLAP_MR_ASSERTION_SYNTAX_MATCH                  0x0000U
440 #define SLAP_MR_VALUE_SYNTAX_MATCH                              0x0001U
441 #define SLAP_MR_VALUE_SYNTAX_CONVERTED_MATCH    0x0003U
442
443 #define SLAP_IS_MR_ASSERTION_SYNTAX_MATCH( usage ) \
444         (!((usage) & SLAP_MR_VALUE_SYNTAX_MATCH))
445 #define SLAP_IS_MR_VALUE_SYNTAX_MATCH( usage ) \
446         ((usage) & SLAP_MR_VALUE_SYNTAX_MATCH)
447
448 #define SLAP_IS_MR_VALUE_SYNTAX_CONVERTED_MATCH( usage ) \
449         (((usage) & SLAP_MR_VALUE_SYNTAX_CONVERTED_MATCH) \
450                 == SLAP_MR_VALUE_SYNTAX_CONVERTED_MATCH)
451 #define SLAP_IS_MR_VALUE_SYNTAX_NONCONVERTED_MATCH( usage ) \
452         (((usage) & SLAP_MR_VALUE_SYNTAX_CONVERTED_MATCH) \
453                 == SLAP_MR_VALUE_SYNTAX_MATCH)
454
455         Syntax                                  *smr_syntax;
456         slap_mr_convert_func    *smr_convert;
457         slap_mr_normalize_func  *smr_normalize;
458         slap_mr_match_func              *smr_match;
459         slap_mr_indexer_func    *smr_indexer;
460         slap_mr_filter_func             *smr_filter;
461
462         /*
463          * null terminated list of syntaxes compatible with this syntax
464          * note: when MS_EXT is set, this MUST NOT contain the assertion
465          * syntax of the rule.  When MS_EXT is not set, it MAY.
466          */
467         Syntax                                  **smr_compat_syntaxes;
468
469         struct slap_matching_rule       *smr_associated;
470         struct slap_matching_rule       *smr_next;
471
472 #define smr_oid                         smr_mrule.mr_oid
473 #define smr_names                       smr_mrule.mr_names
474 #define smr_desc                        smr_mrule.mr_desc
475 #define smr_obsolete            smr_mrule.mr_obsolete
476 #define smr_syntax_oid          smr_mrule.mr_syntax_oid
477 #define smr_extensions          smr_mrule.mr_extensions
478 } MatchingRule;
479
480 struct slap_matching_rule_use {
481         LDAPMatchingRuleUse             smru_mruleuse;
482         MatchingRule                    *smru_mr;
483         /* RFC2252 string representation */
484         struct berval                   smru_str;
485
486         struct slap_matching_rule_use   *smru_next;
487
488 #define smru_oid                        smru_mruleuse.mru_oid
489 #define smru_names                      smru_mruleuse.mru_names
490 #define smru_desc                       smru_mruleuse.mru_desc
491 #define smru_obsolete                   smru_mruleuse.mru_obsolete
492 #define smru_applies_oids               smru_mruleuse.mru_applies_oids
493
494 #define smru_usage                      smru_mr->smr_usage
495 } /* MatchingRuleUse */ ;
496
497 typedef struct slap_mrule_defs_rec {
498         char *                                          mrd_desc;
499         slap_mask_t                                     mrd_usage;
500         char **                                         mrd_compat_syntaxes;
501         slap_mr_convert_func *          mrd_convert;
502         slap_mr_normalize_func *        mrd_normalize;
503         slap_mr_match_func *            mrd_match;
504         slap_mr_indexer_func *          mrd_indexer;
505         slap_mr_filter_func *           mrd_filter;
506
507         char *                                          mrd_associated;
508 } slap_mrule_defs_rec;
509
510 struct slap_backend_db;
511 struct slap_entry;
512 struct slap_attr;
513
514 typedef int (AttributeTypeSchemaCheckFN)(
515         struct slap_backend_db *be,
516         struct slap_entry *e,
517         struct slap_attr *attr,
518         const char** text,
519         char *textbuf, size_t textlen );
520
521 typedef struct slap_attribute_type {
522         LDAPAttributeType               sat_atype;
523         struct berval                   sat_cname;
524         struct slap_attribute_type      *sat_sup;
525         struct slap_attribute_type      **sat_subtypes;
526         MatchingRule                    *sat_equality;
527         MatchingRule                    *sat_approx;
528         MatchingRule                    *sat_ordering;
529         MatchingRule                    *sat_substr;
530         Syntax                                  *sat_syntax;
531
532         AttributeTypeSchemaCheckFN      *sat_check;
533
534 #define SLAP_AT_NONE            0x0000U
535 #define SLAP_AT_ABSTRACT        0x0100U /* cannot be instantiated */
536 #define SLAP_AT_FINAL           0x0200U /* cannot be subtyped */
537 #define SLAP_AT_HIDE            0x8000U /* hide attribute */
538         slap_mask_t                                     sat_flags;
539
540         struct slap_attribute_type      *sat_next;
541
542 #define sat_oid                         sat_atype.at_oid
543 #define sat_names                       sat_atype.at_names
544 #define sat_desc                        sat_atype.at_desc
545 #define sat_obsolete            sat_atype.at_obsolete
546 #define sat_sup_oid                     sat_atype.at_sup_oid
547 #define sat_equality_oid        sat_atype.at_equality_oid
548 #define sat_ordering_oid        sat_atype.at_ordering_oid
549 #define sat_substr_oid          sat_atype.at_substr_oid
550 #define sat_syntax_oid          sat_atype.at_syntax_oid
551 #define sat_single_value        sat_atype.at_single_value
552 #define sat_collective          sat_atype.at_collective
553 #define sat_no_user_mod         sat_atype.at_no_user_mod
554 #define sat_usage                       sat_atype.at_usage
555 #define sat_extensions          sat_atype.at_extensions
556
557         struct slap_attr_desc           *sat_ad;
558         ldap_pvt_thread_mutex_t         sat_ad_mutex;
559 } AttributeType;
560
561 #define is_at_operational(at)   ((at)->sat_usage)
562 #define is_at_single_value(at)  ((at)->sat_single_value)
563 #define is_at_collective(at)    ((at)->sat_collective)
564 #define is_at_obsolete(at)              ((at)->sat_obsolete)
565 #define is_at_no_user_mod(at)   ((at)->sat_no_user_mod)
566
567 struct slap_object_class;
568
569 typedef int (ObjectClassSchemaCheckFN)(
570         struct slap_backend_db *be,
571         struct slap_entry *e,
572         struct slap_object_class *oc,
573         const char** text,
574         char *textbuf, size_t textlen );
575
576 typedef struct slap_object_class {
577         LDAPObjectClass                 soc_oclass;
578         struct berval                   soc_cname;
579         struct slap_object_class        **soc_sups;
580         AttributeType                           **soc_required;
581         AttributeType                           **soc_allowed;
582         ObjectClassSchemaCheckFN        *soc_check;
583         slap_mask_t                                     soc_flags;
584 #define soc_oid                         soc_oclass.oc_oid
585 #define soc_names                       soc_oclass.oc_names
586 #define soc_desc                        soc_oclass.oc_desc
587 #define soc_obsolete            soc_oclass.oc_obsolete
588 #define soc_sup_oids            soc_oclass.oc_sup_oids
589 #define soc_kind                        soc_oclass.oc_kind
590 #define soc_at_oids_must        soc_oclass.oc_at_oids_must
591 #define soc_at_oids_may         soc_oclass.oc_at_oids_may
592 #define soc_extensions          soc_oclass.oc_extensions
593
594         struct slap_object_class        *soc_next;
595 } ObjectClass;
596
597 #define SLAP_OC_ALIAS           0x0001
598 #define SLAP_OC_REFERRAL        0x0002
599 #define SLAP_OC_SUBENTRY        0x0004
600 #define SLAP_OC_DYNAMICOBJECT   0x0008
601 #define SLAP_OC_COLLECTIVEATTRIBUTESUBENTRY     0x0010
602 #define SLAP_OC__MASK           0x001F
603 #define SLAP_OC__END            0x0020
604 #define SLAP_OC_OPERATIONAL     0x4000
605 #define SLAP_OC_HIDE            0x8000
606
607 /*
608  * DIT content rule
609  */
610 typedef struct slap_content_rule {
611         LDAPContentRule         scr_crule;
612         ObjectClass                     *scr_sclass;
613         ObjectClass                     **scr_auxiliaries;      /* optional */
614         AttributeType           **scr_required;         /* optional */
615         AttributeType           **scr_allowed;          /* optional */
616         AttributeType           **scr_precluded;        /* optional */
617 #define scr_oid                         scr_crule.cr_oid
618 #define scr_names                       scr_crule.cr_names
619 #define scr_desc                        scr_crule.cr_desc
620 #define scr_obsolete            scr_crule.cr_obsolete
621 #define scr_oc_oids_aux         scr_crule.cr_oc_oids_aux
622 #define scr_at_oids_must        scr_crule.cr_at_oids_must
623 #define scr_at_oids_may         scr_crule.cr_at_oids_may
624 #define scr_at_oids_not         scr_crule.cr_at_oids_not
625
626         struct slap_content_rule *scr_next;
627 } ContentRule;
628
629 /*
630  * represents a recognized attribute description ( type + options )
631  */
632 typedef struct slap_attr_desc {
633         struct slap_attr_desc *ad_next;
634         AttributeType *ad_type;         /* attribute type, must be specified */
635         struct berval ad_cname;         /* canonical name, must be specified */
636         struct berval ad_lang;          /* empty if no language tags */
637         unsigned ad_flags;
638 #define SLAP_DESC_NONE                  0x00U
639 #define SLAP_DESC_BINARY                0x01U
640 #define SLAP_DESC_LANG_RANGE    0x80U
641 } AttributeDescription;
642
643 typedef struct slap_attr_name {
644         struct berval an_name;
645         AttributeDescription *an_desc;
646         ObjectClass *an_oc;
647 } AttributeName;
648
649 #define slap_ad_is_lang(ad)                     ( (ad)->ad_lang.bv_len != 0 )
650 #define slap_ad_is_lang_range(ad)       \
651         ( ((ad)->ad_flags & SLAP_DESC_LANG_RANGE) ? 1 : 0 )
652 #define slap_ad_is_binary(ad)           \
653         ( ((ad)->ad_flags & SLAP_DESC_BINARY) ? 1 : 0 )
654
655 /*
656  * pointers to schema elements used internally
657  */
658 struct slap_internal_schema {
659         /* objectClass */
660         ObjectClass *si_oc_top;
661         ObjectClass *si_oc_extensibleObject;
662         ObjectClass *si_oc_alias;
663         ObjectClass *si_oc_referral;
664         ObjectClass *si_oc_rootdse;
665         ObjectClass *si_oc_subentry;
666         ObjectClass *si_oc_subschema;
667         ObjectClass *si_oc_monitor;
668         ObjectClass *si_oc_collectiveAttributeSubentry;
669         ObjectClass *si_oc_dynamicObject;
670
671         /* objectClass attribute descriptions */
672         AttributeDescription *si_ad_objectClass;
673
674         /* operational attribute descriptions */
675         AttributeDescription *si_ad_structuralObjectClass;
676         AttributeDescription *si_ad_creatorsName;
677         AttributeDescription *si_ad_createTimestamp;
678         AttributeDescription *si_ad_modifiersName;
679         AttributeDescription *si_ad_modifyTimestamp;
680         AttributeDescription *si_ad_hasSubordinates;
681         AttributeDescription *si_ad_subschemaSubentry;
682         AttributeDescription *si_ad_collectiveSubentries;
683         AttributeDescription *si_ad_collectiveExclusions;
684         AttributeDescription *si_ad_entryUUID;
685         AttributeDescription *si_ad_entryCSN;
686         AttributeDescription *si_ad_superiorUUID;
687
688         /* root DSE attribute descriptions */
689         AttributeDescription *si_ad_altServer;
690         AttributeDescription *si_ad_namingContexts;
691         AttributeDescription *si_ad_supportedControl;
692         AttributeDescription *si_ad_supportedExtension;
693         AttributeDescription *si_ad_supportedLDAPVersion;
694         AttributeDescription *si_ad_supportedSASLMechanisms;
695         AttributeDescription *si_ad_supportedFeatures;
696         AttributeDescription *si_ad_monitorContext;
697         AttributeDescription *si_ad_vendorName;
698         AttributeDescription *si_ad_vendorVersion;
699
700         /* subentry attribute descriptions */
701         AttributeDescription *si_ad_administrativeRole;
702         AttributeDescription *si_ad_subtreeSpecification;
703
704         /* subschema subentry attribute descriptions */
705         AttributeDescription *si_ad_ditStructureRules;
706         AttributeDescription *si_ad_ditContentRules;
707         AttributeDescription *si_ad_nameForms;
708         AttributeDescription *si_ad_objectClasses;
709         AttributeDescription *si_ad_attributeTypes;
710         AttributeDescription *si_ad_ldapSyntaxes;
711         AttributeDescription *si_ad_matchingRules;
712         AttributeDescription *si_ad_matchingRuleUse;
713
714         /* Aliases & Referrals */
715         AttributeDescription *si_ad_aliasedObjectName;
716         AttributeDescription *si_ad_ref;
717
718         /* Access Control Internals */
719         AttributeDescription *si_ad_entry;
720         AttributeDescription *si_ad_children;
721         AttributeDescription *si_ad_saslAuthzTo;
722         AttributeDescription *si_ad_saslAuthzFrom;
723 #ifdef SLAPD_ACI_ENABLED
724         AttributeDescription *si_ad_aci;
725 #endif
726
727         /* dynamic entries */
728         AttributeDescription *si_ad_entryTtl;
729         AttributeDescription *si_ad_dynamicSubtrees;
730
731         /* Other attributes descriptions */
732         AttributeDescription *si_ad_distinguishedName;
733         AttributeDescription *si_ad_name;
734         AttributeDescription *si_ad_cn;
735         AttributeDescription *si_ad_userPassword;
736 #ifdef SLAPD_AUTHPASSWD
737         AttributeDescription *si_ad_authPassword;
738 #endif
739 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
740         AttributeDescription *si_ad_krbName;
741 #endif
742
743         /* Undefined Attribute Type */
744         AttributeType   *si_at_undefined;
745
746         /* Matching Rules */
747         MatchingRule    *si_mr_distinguishedNameMatch;
748         MatchingRule    *si_mr_integerMatch;
749
750         /* Syntaxes */
751         Syntax          *si_syn_octetString;
752         Syntax          *si_syn_distinguishedName;
753         Syntax          *si_syn_integer;
754 };
755
756 typedef struct slap_attr_assertion {
757         AttributeDescription    *aa_desc;
758         struct berval aa_value;
759 } AttributeAssertion;
760
761 typedef struct slap_ss_assertion {
762         AttributeDescription    *sa_desc;
763         struct berval           sa_initial;
764         struct berval           *sa_any;
765         struct berval           sa_final;
766 } SubstringsAssertion;
767
768 typedef struct slap_mr_assertion {
769         MatchingRule            *ma_rule;       /* optional */
770         struct berval           ma_rule_text;  /* optional */
771         AttributeDescription    *ma_desc;       /* optional */
772         int                                             ma_dnattrs; /* boolean */
773         struct berval           ma_value;       /* required */
774 } MatchingRuleAssertion;
775
776 /*
777  * represents a search filter
778  */
779 typedef struct slap_filter {
780         ber_tag_t       f_choice;       /* values taken from ldap.h, plus: */
781 #define SLAPD_FILTER_COMPUTED   ((ber_tag_t) -1)
782 #define SLAPD_FILTER_DN_ONE             ((ber_tag_t) -2)
783 #define SLAPD_FILTER_DN_SUBTREE ((ber_tag_t) -3)
784
785         union f_un_u {
786                 /* precomputed result */
787                 ber_int_t f_un_result;
788
789                 /* DN */
790                 struct berval *f_un_dn;
791
792                 /* present */
793                 AttributeDescription *f_un_desc;
794
795                 /* simple value assertion */
796                 AttributeAssertion *f_un_ava;
797
798                 /* substring assertion */
799                 SubstringsAssertion *f_un_ssa;
800
801                 /* matching rule assertion */
802                 MatchingRuleAssertion *f_un_mra;
803
804 #define f_dn                    f_un.f_un_dn
805 #define f_desc                  f_un.f_un_desc
806 #define f_ava                   f_un.f_un_ava
807 #define f_av_desc               f_un.f_un_ava->aa_desc
808 #define f_av_value              f_un.f_un_ava->aa_value
809 #define f_sub                   f_un.f_un_ssa
810 #define f_sub_desc              f_un.f_un_ssa->sa_desc
811 #define f_sub_initial   f_un.f_un_ssa->sa_initial
812 #define f_sub_any               f_un.f_un_ssa->sa_any
813 #define f_sub_final             f_un.f_un_ssa->sa_final
814 #define f_mra                   f_un.f_un_mra
815 #define f_mr_rule               f_un.f_un_mra->ma_rule
816 #define f_mr_rule_text  f_un.f_un_mra->ma_rule_text
817 #define f_mr_desc               f_un.f_un_mra->ma_desc
818 #define f_mr_value              f_un.f_un_mra->ma_value
819 #define f_mr_dnattrs    f_un.f_un_mra->ma_dnattrs
820
821                 /* and, or, not */
822                 struct slap_filter *f_un_complex;
823         } f_un;
824
825 #define f_result        f_un.f_un_result
826 #define f_and           f_un.f_un_complex
827 #define f_or            f_un.f_un_complex
828 #define f_not           f_un.f_un_complex
829 #define f_list          f_un.f_un_complex
830
831         struct slap_filter      *f_next;
832 } Filter;
833
834 /* compare routines can return undefined */
835 #define SLAPD_COMPARE_UNDEFINED ((ber_int_t) -1)
836
837 typedef struct slap_valuesreturnfilter {
838         ber_tag_t       f_choice;
839
840         union vrf_un_u {
841                 /* precomputed result */
842                 ber_int_t f_un_result;
843
844                 /* DN */
845                 char *f_un_dn;
846
847                 /* present */
848                 AttributeDescription *f_un_desc;
849
850                 /* simple value assertion */
851                 AttributeAssertion *f_un_ava;
852
853                 /* substring assertion */
854                 SubstringsAssertion *f_un_ssa;
855
856                 /* matching rule assertion */
857                 MatchingRuleAssertion *f_un_mra;
858         } f_un;
859
860         struct slap_valuesreturnfilter  *f_next;
861 } ValuesReturnFilter;
862
863 /*
864  * represents an attribute (description + values)
865  */
866 typedef struct slap_attr {
867         AttributeDescription *a_desc;
868         BerVarray       a_vals;
869         struct slap_attr        *a_next;
870         unsigned a_flags;
871 #define SLAP_ATTR_IXADD         0x1U
872 #define SLAP_ATTR_IXDEL         0x2U
873 } Attribute;
874
875
876 /*
877  * the id used in the indexes to refer to an entry
878  */
879 typedef unsigned long   ID;
880 #define NOID    ((ID)~0)
881
882 /*
883  * represents an entry in core
884  */
885 typedef struct slap_entry {
886         /*
887          * The ID field should only be changed before entry is
888          * inserted into a cache.  The ID value is backend
889          * specific.
890          */
891         ID              e_id;
892
893         struct berval e_name;   /* name (DN) of this entry */
894         struct berval e_nname;  /* normalized name (DN) of this entry */
895
896         /* for migration purposes */
897 #define e_dn e_name.bv_val
898 #define e_ndn e_nname.bv_val
899
900         Attribute       *e_attrs;       /* list of attributes + values */
901
902         slap_mask_t     e_ocflags;
903
904         struct berval   e_bv;           /* For entry_encode/entry_decode */
905
906         /* for use by the backend for any purpose */
907         void*   e_private;
908 } Entry;
909
910 /*
911  * A list of LDAPMods
912  */
913 typedef struct slap_mod {
914         int sm_op;
915         AttributeDescription *sm_desc;
916         struct berval sm_type;
917         BerVarray sm_bvalues;
918 } Modification;
919
920 typedef struct slap_mod_list {
921         Modification sml_mod;
922 #define sml_op          sml_mod.sm_op
923 #define sml_desc        sml_mod.sm_desc
924 #define sml_type        sml_mod.sm_type
925 #define sml_bvalues     sml_mod.sm_bvalues
926         struct slap_mod_list *sml_next;
927 } Modifications;
928
929 typedef struct slap_ldap_modlist {
930         LDAPMod ml_mod;
931         struct slap_ldap_modlist *ml_next;
932 #define ml_op           ml_mod.mod_op
933 #define ml_type         ml_mod.mod_type
934 #define ml_values       ml_mod.mod_values
935 #define ml_bvalues      ml_mod.mod_bvalues
936 } LDAPModList;
937
938 /*
939  * represents an access control list
940  */
941 typedef enum slap_access_e {
942         ACL_INVALID_ACCESS = -1,
943         ACL_NONE = 0,
944         ACL_AUTH,
945         ACL_COMPARE,
946         ACL_SEARCH,
947         ACL_READ,
948         ACL_WRITE
949 } slap_access_t;
950
951 typedef enum slap_control_e {
952         ACL_INVALID_CONTROL     = 0,
953         ACL_STOP,
954         ACL_CONTINUE,
955         ACL_BREAK
956 } slap_control_t;
957
958 typedef enum slap_style_e {
959         ACL_STYLE_REGEX = 0,
960         ACL_STYLE_BASE,
961         ACL_STYLE_ONE,
962         ACL_STYLE_SUBTREE,
963         ACL_STYLE_CHILDREN,
964         ACL_STYLE_ATTROF,
965
966         /* alternate names */
967         ACL_STYLE_EXACT = ACL_STYLE_BASE
968 } slap_style_t;
969
970 typedef struct slap_authz_info {
971         ber_tag_t       sai_method;             /* LDAP_AUTH_* from <ldap.h> */
972         struct berval   sai_mech;               /* SASL Mechanism */
973         struct berval   sai_dn;                 /* DN for reporting purposes */
974         struct berval   sai_ndn;                /* Normalized DN */
975
976         /* Security Strength Factors */
977         slap_ssf_t      sai_ssf;                        /* Overall SSF */
978         slap_ssf_t      sai_transport_ssf;      /* Transport SSF */
979         slap_ssf_t      sai_tls_ssf;            /* TLS SSF */
980         slap_ssf_t      sai_sasl_ssf;           /* SASL SSF */
981 } AuthorizationInformation;
982
983 /* the "by" part */
984 typedef struct slap_access {
985         slap_control_t a_type;
986
987 #define ACL_ACCESS2PRIV(access) (0x01U << (access))
988
989 #define ACL_PRIV_NONE                   ACL_ACCESS2PRIV( ACL_NONE )
990 #define ACL_PRIV_AUTH                   ACL_ACCESS2PRIV( ACL_AUTH )
991 #define ACL_PRIV_COMPARE                ACL_ACCESS2PRIV( ACL_COMPARE )
992 #define ACL_PRIV_SEARCH                 ACL_ACCESS2PRIV( ACL_SEARCH )
993 #define ACL_PRIV_READ                   ACL_ACCESS2PRIV( ACL_READ )
994 #define ACL_PRIV_WRITE                  ACL_ACCESS2PRIV( ACL_WRITE )
995
996 #define ACL_PRIV_MASK                   0x00ffUL
997
998 /* priv flags */
999 #define ACL_PRIV_LEVEL                  0x1000UL
1000 #define ACL_PRIV_ADDITIVE               0x2000UL
1001 #define ACL_PRIV_SUBSTRACTIVE   0x4000UL
1002
1003 /* invalid privs */
1004 #define ACL_PRIV_INVALID                0x0UL
1005
1006 #define ACL_PRIV_ISSET(m,p)             (((m) & (p)) == (p))
1007 #define ACL_PRIV_ASSIGN(m,p)    do { (m)  =  (p); } while(0)
1008 #define ACL_PRIV_SET(m,p)               do { (m) |=  (p); } while(0)
1009 #define ACL_PRIV_CLR(m,p)               do { (m) &= ~(p); } while(0)
1010
1011 #define ACL_INIT(m)                             ACL_PRIV_ASSIGN(m, ACL_PRIV_NONE)
1012 #define ACL_INVALIDATE(m)               ACL_PRIV_ASSIGN(m, ACL_PRIV_INVALID)
1013
1014 #define ACL_GRANT(m,a)                  ACL_PRIV_ISSET((m),ACL_ACCESS2PRIV(a))
1015
1016 #define ACL_IS_INVALID(m)               ((m) == ACL_PRIV_INVALID)
1017
1018 #define ACL_IS_LEVEL(m)                 ACL_PRIV_ISSET((m),ACL_PRIV_LEVEL)
1019 #define ACL_IS_ADDITIVE(m)              ACL_PRIV_ISSET((m),ACL_PRIV_ADDITIVE)
1020 #define ACL_IS_SUBTRACTIVE(m)   ACL_PRIV_ISSET((m),ACL_PRIV_SUBSTRACTIVE)
1021
1022 #define ACL_LVL_NONE                    (ACL_PRIV_NONE|ACL_PRIV_LEVEL)
1023 #define ACL_LVL_AUTH                    (ACL_PRIV_AUTH|ACL_LVL_NONE)
1024 #define ACL_LVL_COMPARE                 (ACL_PRIV_COMPARE|ACL_LVL_AUTH)
1025 #define ACL_LVL_SEARCH                  (ACL_PRIV_SEARCH|ACL_LVL_COMPARE)
1026 #define ACL_LVL_READ                    (ACL_PRIV_READ|ACL_LVL_SEARCH)
1027 #define ACL_LVL_WRITE                   (ACL_PRIV_WRITE|ACL_LVL_READ)
1028
1029 #define ACL_LVL(m,l)                    (((m)&ACL_PRIV_MASK) == ((l)&ACL_PRIV_MASK))
1030 #define ACL_LVL_IS_NONE(m)              ACL_LVL((m),ACL_LVL_NONE)
1031 #define ACL_LVL_IS_AUTH(m)              ACL_LVL((m),ACL_LVL_AUTH)
1032 #define ACL_LVL_IS_COMPARE(m)   ACL_LVL((m),ACL_LVL_COMPARE)
1033 #define ACL_LVL_IS_SEARCH(m)    ACL_LVL((m),ACL_LVL_SEARCH)
1034 #define ACL_LVL_IS_READ(m)              ACL_LVL((m),ACL_LVL_READ)
1035 #define ACL_LVL_IS_WRITE(m)             ACL_LVL((m),ACL_LVL_WRITE)
1036
1037 #define ACL_LVL_ASSIGN_NONE(m)          ACL_PRIV_ASSIGN((m),ACL_LVL_NONE)
1038 #define ACL_LVL_ASSIGN_AUTH(m)          ACL_PRIV_ASSIGN((m),ACL_LVL_AUTH)
1039 #define ACL_LVL_ASSIGN_COMPARE(m)       ACL_PRIV_ASSIGN((m),ACL_LVL_COMPARE)
1040 #define ACL_LVL_ASSIGN_SEARCH(m)        ACL_PRIV_ASSIGN((m),ACL_LVL_SEARCH)
1041 #define ACL_LVL_ASSIGN_READ(m)          ACL_PRIV_ASSIGN((m),ACL_LVL_READ)
1042 #define ACL_LVL_ASSIGN_WRITE(m)         ACL_PRIV_ASSIGN((m),ACL_LVL_WRITE)
1043
1044         slap_mask_t     a_access_mask;
1045
1046         AuthorizationInformation        a_authz;
1047 #define a_dn_pat        a_authz.sai_dn
1048
1049         slap_style_t a_dn_style;
1050         AttributeDescription    *a_dn_at;
1051         int                     a_dn_self;
1052         int                     a_dn_expand;
1053
1054         slap_style_t a_peername_style;
1055         struct berval   a_peername_pat;
1056         slap_style_t a_sockname_style;
1057         struct berval   a_sockname_pat;
1058
1059         slap_style_t a_domain_style;
1060         struct berval   a_domain_pat;
1061         int             a_domain_expand;
1062
1063         slap_style_t a_sockurl_style;
1064         struct berval   a_sockurl_pat;
1065         slap_style_t a_set_style;
1066         struct berval   a_set_pat;
1067
1068 #ifdef SLAPD_ACI_ENABLED
1069         AttributeDescription    *a_aci_at;
1070 #endif
1071
1072         /* ACL Groups */
1073         slap_style_t a_group_style;
1074         struct berval   a_group_pat;
1075         ObjectClass                             *a_group_oc;
1076         AttributeDescription    *a_group_at;
1077
1078         struct slap_access      *a_next;
1079 } Access;
1080
1081 /* the "to" part */
1082 typedef struct slap_acl {
1083         /* "to" part: the entries this acl applies to */
1084         Filter          *acl_filter;
1085         slap_style_t acl_dn_style;
1086         regex_t         acl_dn_re;
1087         struct berval   acl_dn_pat;
1088         AttributeName   *acl_attrs;
1089
1090         /* "by" part: list of who has what access to the entries */
1091         Access  *acl_access;
1092
1093         struct slap_acl *acl_next;
1094 } AccessControl;
1095
1096 typedef struct slap_acl_state {
1097         unsigned as_recorded;
1098 #define ACL_STATE_NOT_RECORDED                  0x0
1099 #define ACL_STATE_RECORDED_VD                   0x1
1100 #define ACL_STATE_RECORDED_NV                   0x2
1101 #define ACL_STATE_RECORDED                              0x3
1102
1103         /* Access state */
1104         AccessControl *as_vd_acl;
1105         slap_mask_t as_vd_acl_mask;
1106         regmatch_t as_vd_acl_matches[MAXREMATCHES];
1107         int as_vd_acl_count;
1108
1109         Access *as_vd_access;
1110         int as_vd_access_count;
1111
1112         int as_result;
1113 } AccessControlState;
1114 #define ACL_STATE_INIT { ACL_STATE_NOT_RECORDED, NULL, 0UL, { { 0, 0 } }, 0, NULL, 0, 0 }
1115
1116 /*
1117  * replog moddn param structure
1118  */
1119 struct slap_replog_moddn {
1120         struct berval *newrdn;
1121         int     deloldrdn;
1122         struct berval *newsup;
1123 };
1124
1125 /*
1126  * Backend-info
1127  * represents a backend 
1128  */
1129
1130 typedef struct slap_backend_info BackendInfo;   /* per backend type */
1131 typedef struct slap_backend_db BackendDB;               /* per backend database */
1132
1133 LDAP_SLAPD_V (int) nBackendInfo;
1134 LDAP_SLAPD_V (int) nBackendDB;
1135 LDAP_SLAPD_V (BackendInfo *) backendInfo;
1136 LDAP_SLAPD_V (BackendDB *) backendDB;
1137
1138 LDAP_SLAPD_V (int) slapMode;    
1139 #define SLAP_UNDEFINED_MODE     0x0000
1140 #define SLAP_SERVER_MODE        0x0001
1141 #define SLAP_TOOL_MODE          0x0002
1142 #define SLAP_MODE                       0x0003
1143
1144 #define SLAP_TRUNCATE_MODE      0x0100
1145
1146 struct slap_replica_info {
1147         char *ri_host;                          /* supersedes be_replica */
1148         BerVarray ri_nsuffix;   /* array of suffixes this replica accepts */
1149         AttributeName *ri_attrs;        /* attrs to replicate, NULL=all */
1150         int ri_exclude;                 /* 1 => exclude ri_attrs */
1151 };
1152
1153 struct slap_limits_set {
1154         /* time limits */
1155         int     lms_t_soft;
1156         int     lms_t_hard;
1157
1158         /* size limits */
1159         int     lms_s_soft;
1160         int     lms_s_hard;
1161         int     lms_s_unchecked;
1162         int     lms_s_pr;
1163         int     lms_s_pr_hide;
1164 };
1165
1166 struct slap_limits {
1167         int     lm_type;        /* type of pattern */
1168 #define SLAP_LIMITS_UNDEFINED   0x0000
1169 #define SLAP_LIMITS_EXACT       0x0001
1170 #define SLAP_LIMITS_BASE        SLAP_LIMITS_EXACT
1171 #define SLAP_LIMITS_ONE         0x0002
1172 #define SLAP_LIMITS_SUBTREE     0x0003
1173 #define SLAP_LIMITS_CHILDREN    0x0004
1174 #define SLAP_LIMITS_REGEX       0x0005
1175 #define SLAP_LIMITS_ANONYMOUS   0x0006
1176 #define SLAP_LIMITS_USERS       0x0007
1177 #define SLAP_LIMITS_ANY         0x0008
1178         regex_t lm_dn_regex;            /* regex data for REGEX */
1179
1180         /*
1181          * normalized DN for EXACT, BASE, ONE, SUBTREE, CHILDREN;
1182          * pattern for REGEX; NULL for ANONYMOUS, USERS
1183          */
1184         struct berval lm_dn_pat;
1185
1186         struct slap_limits_set  lm_limits;
1187 };
1188
1189 /* temporary aliases */
1190 typedef BackendDB Backend;
1191 #define nbackends nBackendDB
1192 #define backends backendDB
1193
1194 struct slap_backend_db {
1195         BackendInfo     *bd_info;       /* pointer to shared backend info */
1196
1197         /* BackendInfo accessors */
1198 #define         be_config       bd_info->bi_db_config
1199 #define         be_type         bd_info->bi_type
1200
1201 #define         be_bind         bd_info->bi_op_bind
1202 #define         be_unbind       bd_info->bi_op_unbind
1203 #define         be_add          bd_info->bi_op_add
1204 #define         be_compare      bd_info->bi_op_compare
1205 #define         be_delete       bd_info->bi_op_delete
1206 #define         be_modify       bd_info->bi_op_modify
1207 #define         be_modrdn       bd_info->bi_op_modrdn
1208 #define         be_search       bd_info->bi_op_search
1209
1210 #define         be_extended     bd_info->bi_extended
1211
1212 #define         be_release      bd_info->bi_entry_release_rw
1213 #define         be_chk_referrals        bd_info->bi_chk_referrals
1214 #define         be_group        bd_info->bi_acl_group
1215 #define         be_attribute    bd_info->bi_acl_attribute
1216 #define         be_operational  bd_info->bi_operational
1217
1218 /*
1219  * define to honor hasSubordinates operational attribute in search filters
1220  * (in previous use there was a flaw with back-bdb and back-ldbm; now it 
1221  * is fixed).
1222  */
1223
1224 #define         be_has_subordinates bd_info->bi_has_subordinates
1225
1226 #define         be_controls     bd_info->bi_controls
1227
1228 #define         be_connection_init      bd_info->bi_connection_init
1229 #define         be_connection_destroy   bd_info->bi_connection_destroy
1230
1231 #ifdef SLAPD_TOOLS
1232 #define         be_entry_open bd_info->bi_tool_entry_open
1233 #define         be_entry_close bd_info->bi_tool_entry_close
1234 #define         be_entry_first bd_info->bi_tool_entry_first
1235 #define         be_entry_next bd_info->bi_tool_entry_next
1236 #define         be_entry_reindex bd_info->bi_tool_entry_reindex
1237 #define         be_entry_get bd_info->bi_tool_entry_get
1238 #define         be_entry_put bd_info->bi_tool_entry_put
1239 #define         be_sync bd_info->bi_tool_sync
1240 #endif
1241
1242 #define SLAP_BFLAG_NOLASTMOD            0x0001U
1243 #define SLAP_BFLAG_GLUE_INSTANCE        0x0010U /* a glue backend */
1244 #define SLAP_BFLAG_GLUE_SUBORDINATE     0x0020U /* child of a glue hierarchy */
1245 #define SLAP_BFLAG_GLUE_LINKED          0x0040U /* child is connected to parent */
1246 #define SLAP_BFLAG_ALIASES              0x0100U
1247 #define SLAP_BFLAG_REFERRALS    0x0200U
1248 #define SLAP_BFLAG_SUBENTRIES   0x0400U
1249 #define SLAP_BFLAG_MONITOR              0x1000U
1250 #define SLAP_BFLAG_DYNAMIC              0x2000U
1251         slap_mask_t     be_flags;
1252 #define SLAP_LASTMOD(be)        (!((be)->be_flags & SLAP_BFLAG_NOLASTMOD))
1253 #define SLAP_ALIASES(be)        ((be)->be_flags & SLAP_BFLAG_ALIASES)
1254 #define SLAP_REFERRALS(be)      ((be)->be_flags & SLAP_BFLAG_REFERRALS)
1255 #define SLAP_SUBENTRIES(be)     ((be)->be_flags & SLAP_BFLAG_SUBENTRIES)
1256 #define SLAP_MONITOR(be)        ((be)->be_flags & SLAP_BFLAG_MONITOR)
1257 #define SLAP_DYNAMIC(be)        ((be)->be_flags & SLAP_BFLAG_DYNAMIC)
1258
1259         slap_mask_t     be_restrictops;         /* restriction operations */
1260 #define SLAP_RESTRICT_OP_ADD            0x0001U
1261 #define SLAP_RESTRICT_OP_BIND           0x0002U
1262 #define SLAP_RESTRICT_OP_COMPARE        0x0004U
1263 #define SLAP_RESTRICT_OP_DELETE         0x0008U
1264 #define SLAP_RESTRICT_OP_EXTENDED       0x0010U
1265 #define SLAP_RESTRICT_OP_MODIFY         0x0020U
1266 #define SLAP_RESTRICT_OP_RENAME         0x0040U
1267 #define SLAP_RESTRICT_OP_SEARCH         0x0080U
1268
1269 #define SLAP_RESTRICT_OP_READS  \
1270         ( SLAP_RESTRICT_OP_COMPARE      \
1271         | SLAP_RESTRICT_OP_SEARCH )
1272 #define SLAP_RESTRICT_OP_WRITES \
1273         ( SLAP_RESTRICT_OP_ADD    \
1274         | SLAP_RESTRICT_OP_DELETE \
1275         | SLAP_RESTRICT_OP_MODIFY \
1276         | SLAP_RESTRICT_OP_RENAME )
1277
1278 #define SLAP_ALLOW_BIND_V2                      0x0001U /* LDAPv2 bind */
1279 #define SLAP_ALLOW_BIND_ANON_CRED       0x0002U /* cred should be empty */
1280 #define SLAP_ALLOW_BIND_ANON_DN         0x0004U /* dn should be empty */
1281
1282 #define SLAP_ALLOW_UPDATE_ANON          0x0008U /* allow anonymous updates */
1283
1284 #define SLAP_DISALLOW_BIND_ANON         0x0001U /* no anonymous */
1285 #define SLAP_DISALLOW_BIND_SIMPLE       0x0002U /* simple authentication */
1286 #define SLAP_DISALLOW_BIND_SIMPLE_UNPROTECTED \
1287                                                                         0x0004U /* unprotected simple auth */
1288 #define SLAP_DISALLOW_BIND_KRBV4        0x0008U /* Kerberos V4 authentication */
1289
1290 #define SLAP_DISALLOW_TLS_2_ANON        0x0010U /* StartTLS -> Anonymous */
1291 #define SLAP_DISALLOW_TLS_AUTHC         0x0020U /* TLS while authenticated */
1292
1293 #define SLAP_DISALLOW_AUX_WO_CR         0x4000U
1294
1295         slap_mask_t     be_requires;    /* pre-operation requirements */
1296 #define SLAP_REQUIRE_BIND               0x0001U /* bind before op */
1297 #define SLAP_REQUIRE_LDAP_V3    0x0002U /* LDAPv3 before op */
1298 #define SLAP_REQUIRE_AUTHC              0x0004U /* authentication before op */
1299 #define SLAP_REQUIRE_SASL               0x0008U /* SASL before op  */
1300 #define SLAP_REQUIRE_STRONG             0x0010U /* strong authentication before op */
1301
1302         /* Required Security Strength Factor */
1303         slap_ssf_set_t be_ssf_set;
1304
1305         /* these should be renamed from be_ to bd_ */
1306         BerVarray       be_suffix;      /* the DN suffixes of data in this backend */
1307         BerVarray       be_nsuffix;     /* the normalized DN suffixes in this backend */
1308         BerVarray       be_suffixAlias; /* pairs of DN suffix aliases and deref values */
1309         struct berval be_schemadn;      /* per-backend subschema subentry DN */
1310         struct berval be_schemandn;     /* normalized subschema DN */
1311         struct berval be_rootdn;        /* the magic "root" name (DN) for this db */
1312         struct berval be_rootndn;       /* the magic "root" normalized name (DN) for this db */
1313         struct berval be_rootpw;        /* the magic "root" password for this db        */
1314         unsigned int be_max_deref_depth; /* limit for depth of an alias deref  */
1315 #define be_sizelimit    be_def_limit.lms_s_soft
1316 #define be_timelimit    be_def_limit.lms_t_soft
1317         struct slap_limits_set be_def_limit; /* default limits */
1318         struct slap_limits **be_limits; /* regex-based size and time limits */
1319         AccessControl *be_acl;  /* access control list for this backend    */
1320         slap_access_t   be_dfltaccess;  /* access given if no acl matches          */
1321         struct slap_replica_info **be_replica;  /* replicas of this backend (in master) */
1322         char    *be_replogfile; /* replication log file (in master)        */
1323         struct berval be_update_ndn;    /* allowed to make changes (in replicas) */
1324         BerVarray       be_update_refs; /* where to refer modifying clients to */
1325         char    *be_realm;
1326         void    *be_private;    /* anything the backend database needs     */
1327 };
1328
1329 struct slap_conn;
1330 struct slap_op;
1331
1332 /* Backend function typedefs */
1333 typedef int (BI_init) LDAP_P((BackendInfo *bi));
1334 typedef int (BI_config) LDAP_P((BackendInfo *bi,
1335         const char *fname, int lineno,
1336         int argc, char **argv));
1337 typedef int (BI_open) LDAP_P((BackendInfo *bi));
1338 typedef int (BI_close) LDAP_P((BackendInfo *bi));
1339 typedef int (BI_destroy) LDAP_P((BackendInfo *bi));
1340
1341 typedef int (BI_db_init) LDAP_P((Backend *bd));
1342 typedef int (BI_db_config) LDAP_P((Backend *bd,
1343         const char *fname, int lineno,
1344         int argc, char **argv));
1345 typedef int (BI_db_open) LDAP_P((Backend *bd));
1346 typedef int (BI_db_close) LDAP_P((Backend *bd));
1347 typedef int (BI_db_destroy) LDAP_P((Backend *bd));
1348
1349 typedef int (BI_op_bind)  LDAP_P(( BackendDB *bd,
1350                 struct slap_conn *c, struct slap_op *o,
1351                 struct berval *dn, struct berval *ndn, int method,
1352                 struct berval *cred, struct berval *edn ));
1353 typedef int (BI_op_unbind) LDAP_P((BackendDB *bd,
1354                 struct slap_conn *c, struct slap_op *o ));
1355 typedef int (BI_op_search) LDAP_P((BackendDB *bd,
1356                 struct slap_conn *c, struct slap_op *o,
1357                 struct berval *base, struct berval *nbase,
1358                 int scope, int deref,
1359                 int slimit, int tlimit,
1360                 Filter *f, struct berval *filterstr,
1361                 AttributeName *attrs, int attrsonly));
1362 typedef int (BI_op_compare)LDAP_P((BackendDB *bd,
1363                 struct slap_conn *c, struct slap_op *o,
1364                 struct berval *dn, struct berval *ndn,
1365                 AttributeAssertion *ava));
1366 typedef int (BI_op_modify) LDAP_P((BackendDB *bd,
1367                 struct slap_conn *c, struct slap_op *o,
1368                 struct berval *dn, struct berval *ndn,
1369                 Modifications *m));
1370 typedef int (BI_op_modrdn) LDAP_P((BackendDB *bd,
1371                 struct slap_conn *c, struct slap_op *o,
1372                 struct berval *dn, struct berval *ndn,
1373                 struct berval *newrdn, struct berval *nnewrdn,
1374                 int deleteoldrdn,
1375                 struct berval *newSup, struct berval *nnewSup ));
1376 typedef int (BI_op_add)    LDAP_P((BackendDB *bd,
1377                 struct slap_conn *c, struct slap_op *o,
1378                 Entry *e));
1379 typedef int (BI_op_delete) LDAP_P((BackendDB *bd,
1380                 struct slap_conn *c, struct slap_op *o,
1381                 struct berval *dn, struct berval *ndn));
1382 typedef int (BI_op_abandon) LDAP_P((BackendDB *bd,
1383                 struct slap_conn *c, struct slap_op *o,
1384                 ber_int_t msgid));
1385
1386 typedef int (BI_op_extended) LDAP_P((
1387         BackendDB               *be,
1388         struct slap_conn        *conn,
1389         struct slap_op          *op,
1390         const char              *reqoid,
1391         struct berval * reqdata,
1392         char            **rspoid,
1393         struct berval ** rspdata,
1394         LDAPControl *** rspctrls,
1395         const char **   text,
1396         BerVarray *refs ));
1397
1398 typedef int (BI_entry_release_rw) LDAP_P((BackendDB *bd,
1399                 struct slap_conn *c, struct slap_op *o,
1400                 Entry *e, int rw));
1401
1402 typedef int (BI_chk_referrals) LDAP_P((BackendDB *bd,
1403                 struct slap_conn *c, struct slap_op *o,
1404                 struct berval *dn, struct berval *ndn,
1405                 const char **text ));
1406
1407 typedef int (BI_acl_group)  LDAP_P((Backend *bd,
1408                 struct slap_conn *c, struct slap_op *o,
1409                 Entry *e,
1410                 struct berval *bdn,
1411                 struct berval *edn,
1412                 ObjectClass *group_oc,
1413                 AttributeDescription *group_at ));
1414
1415 typedef int (BI_acl_attribute)  LDAP_P((Backend *bd,
1416                 struct slap_conn *c, struct slap_op *o,
1417                 Entry *e, struct berval *edn,
1418                 AttributeDescription *entry_at,
1419                 BerVarray *vals ));
1420
1421 typedef int (BI_operational)  LDAP_P((Backend *bd,
1422                 struct slap_conn *c, struct slap_op *o,
1423                 Entry *e, AttributeName *attrs, int opattrs, Attribute **a ));
1424
1425 typedef int (BI_has_subordinates) LDAP_P((Backend *bd,
1426                 struct slap_conn *c, struct slap_op *o,
1427                 Entry *e, int *has_subordinates ));
1428
1429 typedef int (BI_connection_init) LDAP_P((BackendDB *bd,
1430                 struct slap_conn *c));
1431 typedef int (BI_connection_destroy) LDAP_P((BackendDB *bd,
1432                 struct slap_conn *c));
1433
1434 typedef int (BI_tool_entry_open) LDAP_P(( BackendDB *be, int mode ));
1435 typedef int (BI_tool_entry_close) LDAP_P(( BackendDB *be ));
1436 typedef ID (BI_tool_entry_first) LDAP_P(( BackendDB *be ));
1437 typedef ID (BI_tool_entry_next) LDAP_P(( BackendDB *be ));
1438 typedef Entry* (BI_tool_entry_get) LDAP_P(( BackendDB *be, ID id ));
1439 typedef ID (BI_tool_entry_put) LDAP_P(( BackendDB *be, Entry *e, 
1440                         struct berval *text ));
1441 typedef int (BI_tool_entry_reindex) LDAP_P(( BackendDB *be, ID id ));
1442 typedef int (BI_tool_sync) LDAP_P(( BackendDB *be ));
1443
1444 struct slap_backend_info {
1445         char    *bi_type; /* type of backend */
1446
1447         /*
1448          * per backend type routines:
1449          * bi_init: called to allocate a backend_info structure,
1450          *              called once BEFORE configuration file is read.
1451          *              bi_init() initializes this structure hence is
1452          *              called directly from be_initialize()
1453          * bi_config: called per 'backend' specific option
1454          *              all such options must before any 'database' options
1455          *              bi_config() is called only from read_config()
1456          * bi_open: called to open each database, called
1457          *              once AFTER configuration file is read but
1458          *              BEFORE any bi_db_open() calls.
1459          *              bi_open() is called from backend_startup()
1460          * bi_close: called to close each database, called
1461          *              once during shutdown after all bi_db_close calls.
1462          *              bi_close() is called from backend_shutdown()
1463          * bi_destroy: called to destroy each database, called
1464          *              once during shutdown after all bi_db_destroy calls.
1465          *              bi_destory() is called from backend_destroy()
1466          */
1467         BI_init *bi_init;
1468         BI_config       *bi_config;
1469         BI_open *bi_open;
1470         BI_close        *bi_close;
1471         BI_destroy      *bi_destroy;
1472
1473         /*
1474          * per database routines:
1475          * bi_db_init: called to initialize each database,
1476          *      called upon reading 'database <type>' 
1477          *      called only from backend_db_init()
1478          * bi_db_config: called to configure each database,
1479          *  called per database to handle per database options
1480          *      called only from read_config()
1481          * bi_db_open: called to open each database
1482          *      called once per database immediately AFTER bi_open()
1483          *      calls but before daemon startup.
1484          *  called only by backend_startup()
1485          * bi_db_close: called to close each database
1486          *      called once per database during shutdown but BEFORE
1487          *  any bi_close call.
1488          *  called only by backend_shutdown()
1489          * bi_db_destroy: called to destroy each database
1490          *  called once per database during shutdown AFTER all
1491          *  bi_close calls but before bi_destory calls.
1492          *  called only by backend_destory()
1493          */
1494         BI_db_init      *bi_db_init;
1495         BI_db_config    *bi_db_config;
1496         BI_db_open      *bi_db_open;
1497         BI_db_close     *bi_db_close;
1498         BI_db_destroy   *bi_db_destroy;
1499
1500         /* LDAP Operations Handling Routines */
1501         BI_op_bind      *bi_op_bind;
1502         BI_op_unbind    *bi_op_unbind;
1503         BI_op_search    *bi_op_search;
1504         BI_op_compare   *bi_op_compare;
1505         BI_op_modify    *bi_op_modify;
1506         BI_op_modrdn    *bi_op_modrdn;
1507         BI_op_add       *bi_op_add;
1508         BI_op_delete    *bi_op_delete;
1509         BI_op_abandon   *bi_op_abandon;
1510
1511         /* Extended Operations Helper */
1512         BI_op_extended  *bi_extended;
1513
1514         /* Auxilary Functions */
1515         BI_entry_release_rw     *bi_entry_release_rw;
1516         BI_chk_referrals        *bi_chk_referrals;
1517
1518         BI_acl_group    *bi_acl_group;
1519         BI_acl_attribute        *bi_acl_attribute;
1520
1521         BI_operational  *bi_operational;
1522         BI_has_subordinates     *bi_has_subordinates;
1523
1524         BI_connection_init      *bi_connection_init;
1525         BI_connection_destroy   *bi_connection_destroy;
1526
1527         /* hooks for slap tools */
1528         BI_tool_entry_open      *bi_tool_entry_open;
1529         BI_tool_entry_close     *bi_tool_entry_close;
1530         BI_tool_entry_first     *bi_tool_entry_first;
1531         BI_tool_entry_next      *bi_tool_entry_next;
1532         BI_tool_entry_get       *bi_tool_entry_get;
1533         BI_tool_entry_put       *bi_tool_entry_put;
1534         BI_tool_entry_reindex   *bi_tool_entry_reindex;
1535         BI_tool_sync            *bi_tool_sync;
1536
1537 #define SLAP_INDEX_ADD_OP               0x0001
1538 #define SLAP_INDEX_DELETE_OP    0x0002
1539
1540         char **bi_controls;             /* supported controls */
1541
1542         unsigned int bi_nDB;    /* number of databases of this type */
1543         void    *bi_private;    /* anything the backend type needs */
1544 };
1545
1546 #define c_authtype      c_authz.sai_method
1547 #define c_authmech      c_authz.sai_mech
1548 #define c_dn            c_authz.sai_dn
1549 #define c_ndn           c_authz.sai_ndn
1550 #define c_ssf                   c_authz.sai_ssf
1551 #define c_transport_ssf c_authz.sai_transport_ssf
1552 #define c_tls_ssf               c_authz.sai_tls_ssf
1553 #define c_sasl_ssf              c_authz.sai_sasl_ssf
1554
1555 #define o_authtype      o_authz.sai_method
1556 #define o_authmech      o_authz.sai_mech
1557 #define o_dn            o_authz.sai_dn
1558 #define o_ndn           o_authz.sai_ndn
1559 #define o_ssf                   o_authz.sai_ssf
1560 #define o_transport_ssf o_authz.sai_transport_ssf
1561 #define o_tls_ssf               o_authz.sai_tls_ssf
1562 #define o_sasl_ssf              o_authz.sai_sasl_ssf
1563
1564 typedef void (slap_response)( struct slap_conn *, struct slap_op *,
1565         ber_tag_t, ber_int_t, ber_int_t, const char *, const char *,
1566         BerVarray, const char *, struct berval *,
1567         struct berval *, LDAPControl ** );
1568
1569 typedef void (slap_sresult)( struct slap_conn *, struct slap_op *,
1570         ber_int_t, const char *, const char *, BerVarray,
1571         LDAPControl **, int nentries);
1572
1573 typedef int (slap_sendentry)( BackendDB *, struct slap_conn *,
1574         struct slap_op *, Entry *, AttributeName *, int, LDAPControl **);
1575
1576 typedef struct slap_callback {
1577         slap_response *sc_response;
1578         slap_sresult *sc_sresult;
1579         slap_sendentry *sc_sendentry;
1580         void *sc_private;
1581 } slap_callback;
1582
1583 /*
1584  * Paged Results state
1585  */
1586 typedef unsigned long PagedResultsCookie;
1587 typedef struct slap_paged_state {
1588         Backend *ps_be;
1589         PagedResultsCookie ps_cookie;
1590         ID ps_id;
1591 } PagedResultsState;
1592
1593
1594 #ifdef LDAP_CLIENT_UPDATE
1595 #define LCUP_PSEARCH_BY_ADD 0x01
1596 #define LCUP_PSEARCH_BY_DELETE 0x02
1597 #define LCUP_PSEARCH_BY_PREMODIFY 0x03
1598 #define LCUP_PSEARCH_BY_MODIFY 0x04
1599 #define LCUP_PSEARCH_BY_SCOPEOUT 0x05
1600
1601 struct lcup_search_spec {
1602         struct slap_op  *op;
1603         struct berval   *base;
1604         struct berval   *nbase;
1605         int             scope;
1606         int             deref;
1607         int             slimit;
1608         int             tlimit;
1609         Filter          *filter;
1610         struct berval   *filterstr;
1611         AttributeName   *attrs;
1612         int             attrsonly;
1613         struct lcup_entry *elist;
1614         ldap_pvt_thread_mutex_t elist_mutex;
1615         int             entry_count;
1616         LDAP_LIST_ENTRY(lcup_search_spec) link;
1617 };
1618
1619 struct psid_entry {
1620         struct lcup_search_spec* ps;
1621         LDAP_LIST_ENTRY(psid_entry) link;
1622 };
1623 #endif /* LDAP_CLIENT_UPDATE */
1624
1625
1626 /*
1627  * represents an operation pending from an ldap client
1628  */
1629 typedef struct slap_op {
1630         unsigned long o_opid;   /* id of this operation */
1631         unsigned long o_connid; /* id of conn initiating this op */
1632         struct slap_conn *o_conn;       /* connection spawning this op */
1633
1634         ber_int_t       o_msgid;        /* msgid of the request */
1635         ber_int_t       o_protocol;     /* version of the LDAP protocol used by client */
1636         ber_tag_t       o_tag;          /* tag of the request */
1637         time_t          o_time;         /* time op was initiated */
1638
1639         char *          o_extendedop;   /* extended operation OID */
1640
1641         ldap_pvt_thread_t       o_tid;  /* thread handling this op */
1642
1643         volatile sig_atomic_t o_abandon;        /* abandon flag */
1644
1645         char o_do_not_cache;    /* don't cache from this op */
1646
1647 #define SLAP_NO_CONTROL 0
1648 #define SLAP_NONCRITICAL_CONTROL 1
1649 #define SLAP_CRITICAL_CONTROL 2
1650         char o_managedsait;
1651         char o_noop;
1652         char o_proxy_authz;
1653         char o_subentries;
1654         char o_subentries_visibility;
1655         char o_valuesreturnfilter;
1656
1657         char o_pagedresults;
1658         ber_int_t o_pagedresults_size;
1659         PagedResultsState o_pagedresults_state;
1660
1661 #ifdef LDAP_CLIENT_UPDATE
1662         char o_clientupdate;
1663         char o_clientupdate_type;
1664 #define SLAP_LCUP_NONE                          (0x0)
1665 #define SLAP_LCUP_SYNC                          (0x1)
1666 #define SLAP_LCUP_PERSIST                       (0x2)
1667 #define SLAP_LCUP_SYNC_AND_PERSIST      (0x3)
1668         ber_int_t o_clientupdate_interval;
1669         struct berval o_clientupdate_state;
1670         LDAP_LIST_HEAD(lss, lcup_search_spec) psearch_spec;
1671         LDAP_LIST_HEAD(pe, psid_entry) premodify_list;
1672         LDAP_LIST_ENTRY(slap_op) link;
1673 #endif /* LDAP_CLIENT_UPDATE */
1674
1675 #ifdef LDAP_CONNECTIONLESS
1676         Sockaddr        o_peeraddr;     /* UDP peer address               */
1677 #endif
1678         AuthorizationInformation o_authz;
1679
1680         BerElement      *o_ber;         /* ber of the request             */
1681         slap_callback   *o_callback;    /* callback pointers */
1682         LDAPControl     **o_ctrls;       /* controls */
1683
1684         void    *o_threadctx;           /* thread pool thread context */
1685         void    *o_private;     /* anything the backend needs */
1686
1687         LDAP_STAILQ_ENTRY(slap_op)      o_next; /* next operation in list         */
1688         ValuesReturnFilter *vrFilter; /* Structure represents ValuesReturnFilter */
1689 } Operation;
1690
1691 #define get_manageDSAit(op)                             ((int)(op)->o_managedsait)
1692 #define get_subentries(op)                              ((int)(op)->o_subentries)
1693 #define get_subentries_visibility(op)   ((int)(op)->o_subentries_visibility)
1694 #define get_pagedresults(op)                    ((int)(op)->o_pagedresults)
1695
1696
1697 /*
1698  * Caches the result of a backend_group check for ACL evaluation
1699  */
1700 typedef struct slap_gacl {
1701         struct slap_gacl *ga_next;
1702         Backend *ga_be;
1703         ObjectClass *ga_oc;
1704         AttributeDescription *ga_at;
1705         int ga_res;
1706         ber_len_t ga_len;
1707         char ga_ndn[1];
1708 } GroupAssertion;
1709
1710 typedef struct slap_listener Listener;
1711
1712 /*
1713  * represents a connection from an ldap client
1714  */
1715 typedef struct slap_conn {
1716         int                     c_struct_state; /* structure management state */
1717         int                     c_conn_state;   /* connection state */
1718
1719         ldap_pvt_thread_mutex_t c_mutex; /* protect the connection */
1720         Sockbuf         *c_sb;                  /* ber connection stuff           */
1721
1722         /* only can be changed by connect_init */
1723         time_t          c_starttime;    /* when the connection was opened */
1724         time_t          c_activitytime; /* when the connection was last used */
1725         unsigned long           c_connid;       /* id of this connection for stats*/
1726
1727         struct berval   c_peer_domain;  /* DNS name of client */
1728         struct berval   c_peer_name;    /* peer name (trans=addr:port) */
1729         Listener        *c_listener;
1730 #define c_listener_url c_listener->sl_url       /* listener URL */
1731 #define c_sock_name c_listener->sl_name /* sock name (trans=addr:port) */
1732
1733         /* only can be changed by binding thread */
1734         int             c_sasl_bind_in_progress;        /* multi-op bind in progress */
1735         struct berval   c_sasl_bind_mech;                       /* mech in progress */
1736         struct berval   c_sasl_dn;      /* temporary storage */
1737
1738         /* authorization backend */
1739         Backend *c_authz_backend;
1740
1741         AuthorizationInformation c_authz;
1742         GroupAssertion *c_groups;
1743
1744         ber_int_t       c_protocol;     /* version of the LDAP protocol used by client */
1745
1746         LDAP_STAILQ_HEAD(c_o, slap_op) c_ops;   /* list of operations being processed */
1747         LDAP_STAILQ_HEAD(c_po, slap_op) c_pending_ops;  /* list of pending operations */
1748
1749         ldap_pvt_thread_mutex_t c_write_mutex;  /* only one pdu written at a time */
1750         ldap_pvt_thread_cond_t  c_write_cv;             /* used to wait for sd write-ready*/
1751
1752         BerElement      *c_currentber;  /* ber we're attempting to read */
1753         int             c_writewaiter;  /* true if writer is waiting */
1754
1755 #ifdef LDAP_CONNECTIONLESS
1756         int     c_is_udp;               /* true if this is (C)LDAP over UDP */
1757 #endif
1758 #ifdef HAVE_TLS
1759         int     c_is_tls;               /* true if this LDAP over raw TLS */
1760         int     c_needs_tls_accept;     /* true if SSL_accept should be called */
1761 #endif
1762         int             c_sasl_layers;   /* true if we need to install SASL i/o handlers */
1763         void    *c_sasl_context;        /* SASL session context */
1764         void    *c_sasl_extra;          /* SASL session extra stuff */
1765         struct slap_op  *c_sasl_bindop; /* set to current op if it's a bind */
1766
1767         PagedResultsState c_pagedresults_state; /* paged result state */
1768
1769         long    c_n_ops_received;       /* num of ops received (next op_id) */
1770         long    c_n_ops_executing;      /* num of ops currently executing */
1771         long    c_n_ops_pending;        /* num of ops pending execution */
1772         long    c_n_ops_completed;      /* num of ops completed */
1773
1774         long    c_n_get;                /* num of get calls */
1775         long    c_n_read;               /* num of read calls */
1776         long    c_n_write;              /* num of write calls */
1777 } Connection;
1778
1779 #if defined(LDAP_SYSLOG) && defined(LDAP_DEBUG)
1780 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 )  \
1781         do { \
1782                 if ( ldap_debug & (level) ) \
1783                         fprintf( stderr, (fmt), (connid), (opid), (arg1), (arg2), (arg3) );\
1784                 if ( ldap_syslog & (level) ) \
1785                         syslog( ldap_syslog_level, (fmt), (connid), (opid), (arg1), \
1786                                 (arg2), (arg3) ); \
1787         } while (0)
1788 #else
1789 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 )
1790 #endif
1791
1792 /*
1793  * listener; need to access it from monitor backend
1794  */
1795 struct slap_listener {
1796         struct berval sl_url;
1797         struct berval sl_name;
1798         mode_t  sl_perms;
1799 #ifdef HAVE_TLS
1800         int             sl_is_tls;
1801 #endif
1802 #ifdef LDAP_CONNECTIONLESS
1803         int     sl_is_udp;              /* UDP listener is also data port */
1804 #endif
1805         ber_socket_t sl_sd;
1806         Sockaddr sl_sa;
1807 #define sl_addr sl_sa.sa_in_addr
1808 };
1809
1810 #ifdef SLAPD_MONITOR
1811 /*
1812  * Operation indices
1813  */
1814 enum {
1815         SLAP_OP_BIND = 0,
1816         SLAP_OP_UNBIND,
1817         SLAP_OP_ADD,
1818         SLAP_OP_DELETE,
1819         SLAP_OP_MODRDN,
1820         SLAP_OP_MODIFY,
1821         SLAP_OP_COMPARE,
1822         SLAP_OP_SEARCH,
1823         SLAP_OP_ABANDON,
1824         SLAP_OP_EXTENDED,
1825         SLAP_OP_LAST
1826 };
1827 #endif /* SLAPD_MONITOR */
1828
1829 /*
1830  * Better know these all around slapd
1831  */
1832 #define SLAP_LDAPDN_PRETTY 0x1
1833 #define SLAP_LDAPDN_MAXLEN 8192
1834
1835 /*
1836  * Macros for LCUP
1837  */
1838 #ifdef LDAP_CLIENT_UPDATE
1839 #define SLAP_LCUP_STATE_UPDATE_TRUE     1
1840 #define SLAP_LCUP_STATE_UPDATE_FALSE    0
1841 #define SLAP_LCUP_ENTRY_DELETED_TRUE    1
1842 #define SLAP_LCUP_ENTRY_DELETED_FALSE   0
1843 #endif /* LDAP_CLIENT_UPDATE */
1844
1845 LDAP_END_DECL
1846
1847 #include "proto-slap.h"
1848
1849 #endif /* _SLAP_H_ */