]> git.sur5r.net Git - openldap/blob - servers/slapd/slap.h
96040ed185bef735b29c20352e9471d79bd2000c
[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 #define SLAP_MR_VALUE_NORMALIZED_MATCH  0x0004U
443
444 #define SLAP_IS_MR_ASSERTION_SYNTAX_MATCH( usage ) \
445         (!((usage) & SLAP_MR_VALUE_SYNTAX_MATCH))
446 #define SLAP_IS_MR_VALUE_SYNTAX_MATCH( usage ) \
447         ((usage) & SLAP_MR_VALUE_SYNTAX_MATCH)
448
449 #define SLAP_IS_MR_VALUE_SYNTAX_CONVERTED_MATCH( usage ) \
450         (((usage) & SLAP_MR_VALUE_SYNTAX_CONVERTED_MATCH) \
451                 == SLAP_MR_VALUE_SYNTAX_CONVERTED_MATCH)
452 #define SLAP_IS_MR_VALUE_SYNTAX_NONCONVERTED_MATCH( usage ) \
453         (((usage) & SLAP_MR_VALUE_SYNTAX_CONVERTED_MATCH) \
454                 == SLAP_MR_VALUE_SYNTAX_MATCH)
455
456         Syntax                                  *smr_syntax;
457         slap_mr_convert_func    *smr_convert;
458         slap_mr_normalize_func  *smr_normalize;
459         slap_mr_match_func              *smr_match;
460         slap_mr_indexer_func    *smr_indexer;
461         slap_mr_filter_func             *smr_filter;
462
463         /*
464          * null terminated list of syntaxes compatible with this syntax
465          * note: when MS_EXT is set, this MUST NOT contain the assertion
466          * syntax of the rule.  When MS_EXT is not set, it MAY.
467          */
468         Syntax                                  **smr_compat_syntaxes;
469
470         struct slap_matching_rule       *smr_associated;
471         struct slap_matching_rule       *smr_next;
472
473 #define smr_oid                         smr_mrule.mr_oid
474 #define smr_names                       smr_mrule.mr_names
475 #define smr_desc                        smr_mrule.mr_desc
476 #define smr_obsolete            smr_mrule.mr_obsolete
477 #define smr_syntax_oid          smr_mrule.mr_syntax_oid
478 #define smr_extensions          smr_mrule.mr_extensions
479 } MatchingRule;
480
481 struct slap_matching_rule_use {
482         LDAPMatchingRuleUse             smru_mruleuse;
483         MatchingRule                    *smru_mr;
484         /* RFC2252 string representation */
485         struct berval                   smru_str;
486
487         struct slap_matching_rule_use   *smru_next;
488
489 #define smru_oid                        smru_mruleuse.mru_oid
490 #define smru_names                      smru_mruleuse.mru_names
491 #define smru_desc                       smru_mruleuse.mru_desc
492 #define smru_obsolete                   smru_mruleuse.mru_obsolete
493 #define smru_applies_oids               smru_mruleuse.mru_applies_oids
494
495 #define smru_usage                      smru_mr->smr_usage
496 } /* MatchingRuleUse */ ;
497
498 typedef struct slap_mrule_defs_rec {
499         char *                                          mrd_desc;
500         slap_mask_t                                     mrd_usage;
501         char **                                         mrd_compat_syntaxes;
502         slap_mr_convert_func *          mrd_convert;
503         slap_mr_normalize_func *        mrd_normalize;
504         slap_mr_match_func *            mrd_match;
505         slap_mr_indexer_func *          mrd_indexer;
506         slap_mr_filter_func *           mrd_filter;
507
508         char *                                          mrd_associated;
509 } slap_mrule_defs_rec;
510
511 struct slap_backend_db;
512 struct slap_entry;
513 struct slap_attr;
514
515 typedef int (AttributeTypeSchemaCheckFN)(
516         struct slap_backend_db *be,
517         struct slap_entry *e,
518         struct slap_attr *attr,
519         const char** text,
520         char *textbuf, size_t textlen );
521
522 typedef struct slap_attribute_type {
523         LDAPAttributeType               sat_atype;
524         struct berval                   sat_cname;
525         struct slap_attribute_type      *sat_sup;
526         struct slap_attribute_type      **sat_subtypes;
527         MatchingRule                    *sat_equality;
528         MatchingRule                    *sat_approx;
529         MatchingRule                    *sat_ordering;
530         MatchingRule                    *sat_substr;
531         Syntax                                  *sat_syntax;
532
533         AttributeTypeSchemaCheckFN      *sat_check;
534
535 #define SLAP_AT_NONE            0x0000U
536 #define SLAP_AT_ABSTRACT        0x0100U /* cannot be instantiated */
537 #define SLAP_AT_FINAL           0x0200U /* cannot be subtyped */
538 #define SLAP_AT_HIDE            0x8000U /* hide attribute */
539         slap_mask_t                                     sat_flags;
540
541         struct slap_attribute_type      *sat_next;
542
543 #define sat_oid                         sat_atype.at_oid
544 #define sat_names                       sat_atype.at_names
545 #define sat_desc                        sat_atype.at_desc
546 #define sat_obsolete            sat_atype.at_obsolete
547 #define sat_sup_oid                     sat_atype.at_sup_oid
548 #define sat_equality_oid        sat_atype.at_equality_oid
549 #define sat_ordering_oid        sat_atype.at_ordering_oid
550 #define sat_substr_oid          sat_atype.at_substr_oid
551 #define sat_syntax_oid          sat_atype.at_syntax_oid
552 #define sat_single_value        sat_atype.at_single_value
553 #define sat_collective          sat_atype.at_collective
554 #define sat_no_user_mod         sat_atype.at_no_user_mod
555 #define sat_usage                       sat_atype.at_usage
556 #define sat_extensions          sat_atype.at_extensions
557
558         struct slap_attr_desc           *sat_ad;
559         ldap_pvt_thread_mutex_t         sat_ad_mutex;
560 } AttributeType;
561
562 #define is_at_operational(at)   ((at)->sat_usage)
563 #define is_at_single_value(at)  ((at)->sat_single_value)
564 #define is_at_collective(at)    ((at)->sat_collective)
565 #define is_at_obsolete(at)              ((at)->sat_obsolete)
566 #define is_at_no_user_mod(at)   ((at)->sat_no_user_mod)
567
568 struct slap_object_class;
569
570 typedef int (ObjectClassSchemaCheckFN)(
571         struct slap_backend_db *be,
572         struct slap_entry *e,
573         struct slap_object_class *oc,
574         const char** text,
575         char *textbuf, size_t textlen );
576
577 typedef struct slap_object_class {
578         LDAPObjectClass                 soc_oclass;
579         struct berval                   soc_cname;
580         struct slap_object_class        **soc_sups;
581         AttributeType                           **soc_required;
582         AttributeType                           **soc_allowed;
583         ObjectClassSchemaCheckFN        *soc_check;
584         slap_mask_t                                     soc_flags;
585 #define soc_oid                         soc_oclass.oc_oid
586 #define soc_names                       soc_oclass.oc_names
587 #define soc_desc                        soc_oclass.oc_desc
588 #define soc_obsolete            soc_oclass.oc_obsolete
589 #define soc_sup_oids            soc_oclass.oc_sup_oids
590 #define soc_kind                        soc_oclass.oc_kind
591 #define soc_at_oids_must        soc_oclass.oc_at_oids_must
592 #define soc_at_oids_may         soc_oclass.oc_at_oids_may
593 #define soc_extensions          soc_oclass.oc_extensions
594
595         struct slap_object_class        *soc_next;
596 } ObjectClass;
597
598 #define SLAP_OC_ALIAS           0x0001
599 #define SLAP_OC_REFERRAL        0x0002
600 #define SLAP_OC_SUBENTRY        0x0004
601 #define SLAP_OC_DYNAMICOBJECT   0x0008
602 #define SLAP_OC_COLLECTIVEATTRIBUTESUBENTRY     0x0010
603 #define SLAP_OC__MASK           0x001F
604 #define SLAP_OC__END            0x0020
605 #define SLAP_OC_OPERATIONAL     0x4000
606 #define SLAP_OC_HIDE            0x8000
607
608 /*
609  * DIT content rule
610  */
611 typedef struct slap_content_rule {
612         LDAPContentRule         scr_crule;
613         ObjectClass                     *scr_sclass;
614         ObjectClass                     **scr_auxiliaries;      /* optional */
615         AttributeType           **scr_required;         /* optional */
616         AttributeType           **scr_allowed;          /* optional */
617         AttributeType           **scr_precluded;        /* optional */
618 #define scr_oid                         scr_crule.cr_oid
619 #define scr_names                       scr_crule.cr_names
620 #define scr_desc                        scr_crule.cr_desc
621 #define scr_obsolete            scr_crule.cr_obsolete
622 #define scr_oc_oids_aux         scr_crule.cr_oc_oids_aux
623 #define scr_at_oids_must        scr_crule.cr_at_oids_must
624 #define scr_at_oids_may         scr_crule.cr_at_oids_may
625 #define scr_at_oids_not         scr_crule.cr_at_oids_not
626
627         struct slap_content_rule *scr_next;
628 } ContentRule;
629
630 /*
631  * Represents a recognized attribute description ( type + options ).
632  * Note: Tagging options/ranges are mislabeled "language options",
633  * because language options ("lang-") were implemented first.
634  */
635 typedef struct slap_attr_desc {
636         struct slap_attr_desc *ad_next;
637         AttributeType *ad_type;         /* attribute type, must be specified */
638         struct berval ad_cname;         /* canonical name, must be specified */
639         struct berval ad_lang;          /* empty if no language tags */
640         unsigned ad_flags;
641 #define SLAP_DESC_NONE                  0x00U
642 #define SLAP_DESC_BINARY                0x01U
643 #define SLAP_DESC_LANG_RANGE    0x80U
644 } AttributeDescription;
645
646 typedef struct slap_attr_name {
647         struct berval an_name;
648         AttributeDescription *an_desc;
649         ObjectClass *an_oc;
650 } AttributeName;
651
652 #define slap_ad_is_lang(ad)                     ( (ad)->ad_lang.bv_len != 0 )
653 #define slap_ad_is_lang_range(ad)       \
654         ( ((ad)->ad_flags & SLAP_DESC_LANG_RANGE) ? 1 : 0 )
655 #define slap_ad_is_binary(ad)           \
656         ( ((ad)->ad_flags & SLAP_DESC_BINARY) ? 1 : 0 )
657
658 /*
659  * pointers to schema elements used internally
660  */
661 struct slap_internal_schema {
662         /* objectClass */
663         ObjectClass *si_oc_top;
664         ObjectClass *si_oc_extensibleObject;
665         ObjectClass *si_oc_alias;
666         ObjectClass *si_oc_referral;
667         ObjectClass *si_oc_rootdse;
668         ObjectClass *si_oc_subentry;
669         ObjectClass *si_oc_subschema;
670         ObjectClass *si_oc_monitor;
671         ObjectClass *si_oc_collectiveAttributeSubentry;
672         ObjectClass *si_oc_dynamicObject;
673
674         /* objectClass attribute descriptions */
675         AttributeDescription *si_ad_objectClass;
676
677         /* operational attribute descriptions */
678         AttributeDescription *si_ad_structuralObjectClass;
679         AttributeDescription *si_ad_creatorsName;
680         AttributeDescription *si_ad_createTimestamp;
681         AttributeDescription *si_ad_modifiersName;
682         AttributeDescription *si_ad_modifyTimestamp;
683         AttributeDescription *si_ad_hasSubordinates;
684         AttributeDescription *si_ad_subschemaSubentry;
685         AttributeDescription *si_ad_collectiveSubentries;
686         AttributeDescription *si_ad_collectiveExclusions;
687         AttributeDescription *si_ad_entryUUID;
688         AttributeDescription *si_ad_entryCSN;
689         AttributeDescription *si_ad_superiorUUID;
690
691         /* root DSE attribute descriptions */
692         AttributeDescription *si_ad_altServer;
693         AttributeDescription *si_ad_namingContexts;
694         AttributeDescription *si_ad_supportedControl;
695         AttributeDescription *si_ad_supportedExtension;
696         AttributeDescription *si_ad_supportedLDAPVersion;
697         AttributeDescription *si_ad_supportedSASLMechanisms;
698         AttributeDescription *si_ad_supportedFeatures;
699         AttributeDescription *si_ad_monitorContext;
700         AttributeDescription *si_ad_vendorName;
701         AttributeDescription *si_ad_vendorVersion;
702
703         /* subentry attribute descriptions */
704         AttributeDescription *si_ad_administrativeRole;
705         AttributeDescription *si_ad_subtreeSpecification;
706
707         /* subschema subentry attribute descriptions */
708         AttributeDescription *si_ad_ditStructureRules;
709         AttributeDescription *si_ad_ditContentRules;
710         AttributeDescription *si_ad_nameForms;
711         AttributeDescription *si_ad_objectClasses;
712         AttributeDescription *si_ad_attributeTypes;
713         AttributeDescription *si_ad_ldapSyntaxes;
714         AttributeDescription *si_ad_matchingRules;
715         AttributeDescription *si_ad_matchingRuleUse;
716
717         /* Aliases & Referrals */
718         AttributeDescription *si_ad_aliasedObjectName;
719         AttributeDescription *si_ad_ref;
720
721         /* Access Control Internals */
722         AttributeDescription *si_ad_entry;
723         AttributeDescription *si_ad_children;
724         AttributeDescription *si_ad_saslAuthzTo;
725         AttributeDescription *si_ad_saslAuthzFrom;
726 #ifdef SLAPD_ACI_ENABLED
727         AttributeDescription *si_ad_aci;
728 #endif
729
730         /* dynamic entries */
731         AttributeDescription *si_ad_entryTtl;
732         AttributeDescription *si_ad_dynamicSubtrees;
733
734         /* Other attributes descriptions */
735         AttributeDescription *si_ad_distinguishedName;
736         AttributeDescription *si_ad_name;
737         AttributeDescription *si_ad_cn;
738         AttributeDescription *si_ad_userPassword;
739 #ifdef SLAPD_AUTHPASSWD
740         AttributeDescription *si_ad_authPassword;
741 #endif
742 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
743         AttributeDescription *si_ad_krbName;
744 #endif
745
746         /* Undefined Attribute Type */
747         AttributeType   *si_at_undefined;
748
749         /* Matching Rules */
750         MatchingRule    *si_mr_distinguishedNameMatch;
751         MatchingRule    *si_mr_integerMatch;
752
753         /* Syntaxes */
754         Syntax          *si_syn_octetString;
755         Syntax          *si_syn_distinguishedName;
756         Syntax          *si_syn_integer;
757 };
758
759 typedef struct slap_attr_assertion {
760         AttributeDescription    *aa_desc;
761         struct berval aa_value;
762 } AttributeAssertion;
763
764 typedef struct slap_ss_assertion {
765         AttributeDescription    *sa_desc;
766         struct berval           sa_initial;
767         struct berval           *sa_any;
768         struct berval           sa_final;
769 } SubstringsAssertion;
770
771 typedef struct slap_mr_assertion {
772         MatchingRule            *ma_rule;       /* optional */
773         struct berval           ma_rule_text;  /* optional */
774         AttributeDescription    *ma_desc;       /* optional */
775         int                                             ma_dnattrs; /* boolean */
776         struct berval           ma_value;       /* required */
777 } MatchingRuleAssertion;
778
779 /*
780  * represents a search filter
781  */
782 typedef struct slap_filter {
783         ber_tag_t       f_choice;       /* values taken from ldap.h, plus: */
784 #define SLAPD_FILTER_COMPUTED   ((ber_tag_t) -1)
785 #define SLAPD_FILTER_DN_ONE             ((ber_tag_t) -2)
786 #define SLAPD_FILTER_DN_SUBTREE ((ber_tag_t) -3)
787
788         union f_un_u {
789                 /* precomputed result */
790                 ber_int_t f_un_result;
791
792                 /* DN */
793                 struct berval *f_un_dn;
794
795                 /* present */
796                 AttributeDescription *f_un_desc;
797
798                 /* simple value assertion */
799                 AttributeAssertion *f_un_ava;
800
801                 /* substring assertion */
802                 SubstringsAssertion *f_un_ssa;
803
804                 /* matching rule assertion */
805                 MatchingRuleAssertion *f_un_mra;
806
807 #define f_dn                    f_un.f_un_dn
808 #define f_desc                  f_un.f_un_desc
809 #define f_ava                   f_un.f_un_ava
810 #define f_av_desc               f_un.f_un_ava->aa_desc
811 #define f_av_value              f_un.f_un_ava->aa_value
812 #define f_sub                   f_un.f_un_ssa
813 #define f_sub_desc              f_un.f_un_ssa->sa_desc
814 #define f_sub_initial   f_un.f_un_ssa->sa_initial
815 #define f_sub_any               f_un.f_un_ssa->sa_any
816 #define f_sub_final             f_un.f_un_ssa->sa_final
817 #define f_mra                   f_un.f_un_mra
818 #define f_mr_rule               f_un.f_un_mra->ma_rule
819 #define f_mr_rule_text  f_un.f_un_mra->ma_rule_text
820 #define f_mr_desc               f_un.f_un_mra->ma_desc
821 #define f_mr_value              f_un.f_un_mra->ma_value
822 #define f_mr_dnattrs    f_un.f_un_mra->ma_dnattrs
823
824                 /* and, or, not */
825                 struct slap_filter *f_un_complex;
826         } f_un;
827
828 #define f_result        f_un.f_un_result
829 #define f_and           f_un.f_un_complex
830 #define f_or            f_un.f_un_complex
831 #define f_not           f_un.f_un_complex
832 #define f_list          f_un.f_un_complex
833
834         struct slap_filter      *f_next;
835 } Filter;
836
837 /* compare routines can return undefined */
838 #define SLAPD_COMPARE_UNDEFINED ((ber_int_t) -1)
839
840 typedef struct slap_valuesreturnfilter {
841         ber_tag_t       f_choice;
842
843         union vrf_un_u {
844                 /* precomputed result */
845                 ber_int_t f_un_result;
846
847                 /* DN */
848                 char *f_un_dn;
849
850                 /* present */
851                 AttributeDescription *f_un_desc;
852
853                 /* simple value assertion */
854                 AttributeAssertion *f_un_ava;
855
856                 /* substring assertion */
857                 SubstringsAssertion *f_un_ssa;
858
859                 /* matching rule assertion */
860                 MatchingRuleAssertion *f_un_mra;
861         } f_un;
862
863         struct slap_valuesreturnfilter  *f_next;
864 } ValuesReturnFilter;
865
866 /*
867  * represents an attribute (description + values)
868  */
869 typedef struct slap_attr {
870         AttributeDescription *a_desc;
871         BerVarray       a_vals;
872         struct slap_attr        *a_next;
873         unsigned a_flags;
874 #define SLAP_ATTR_IXADD         0x1U
875 #define SLAP_ATTR_IXDEL         0x2U
876 } Attribute;
877
878
879 /*
880  * the id used in the indexes to refer to an entry
881  */
882 typedef unsigned long   ID;
883 #define NOID    ((ID)~0)
884
885 /*
886  * represents an entry in core
887  */
888 typedef struct slap_entry {
889         /*
890          * The ID field should only be changed before entry is
891          * inserted into a cache.  The ID value is backend
892          * specific.
893          */
894         ID              e_id;
895
896         struct berval e_name;   /* name (DN) of this entry */
897         struct berval e_nname;  /* normalized name (DN) of this entry */
898
899         /* for migration purposes */
900 #define e_dn e_name.bv_val
901 #define e_ndn e_nname.bv_val
902
903         Attribute       *e_attrs;       /* list of attributes + values */
904
905         slap_mask_t     e_ocflags;
906
907         struct berval   e_bv;           /* For entry_encode/entry_decode */
908
909         /* for use by the backend for any purpose */
910         void*   e_private;
911 } Entry;
912
913 /*
914  * A list of LDAPMods
915  */
916 typedef struct slap_mod {
917         int sm_op;
918         AttributeDescription *sm_desc;
919         struct berval sm_type;
920         BerVarray sm_bvalues;
921 } Modification;
922
923 typedef struct slap_mod_list {
924         Modification sml_mod;
925 #define sml_op          sml_mod.sm_op
926 #define sml_desc        sml_mod.sm_desc
927 #define sml_type        sml_mod.sm_type
928 #define sml_bvalues     sml_mod.sm_bvalues
929         struct slap_mod_list *sml_next;
930 } Modifications;
931
932 typedef struct slap_ldap_modlist {
933         LDAPMod ml_mod;
934         struct slap_ldap_modlist *ml_next;
935 #define ml_op           ml_mod.mod_op
936 #define ml_type         ml_mod.mod_type
937 #define ml_values       ml_mod.mod_values
938 #define ml_bvalues      ml_mod.mod_bvalues
939 } LDAPModList;
940
941 /*
942  * represents an access control list
943  */
944 typedef enum slap_access_e {
945         ACL_INVALID_ACCESS = -1,
946         ACL_NONE = 0,
947         ACL_AUTH,
948         ACL_COMPARE,
949         ACL_SEARCH,
950         ACL_READ,
951         ACL_WRITE
952 } slap_access_t;
953
954 typedef enum slap_control_e {
955         ACL_INVALID_CONTROL     = 0,
956         ACL_STOP,
957         ACL_CONTINUE,
958         ACL_BREAK
959 } slap_control_t;
960
961 typedef enum slap_style_e {
962         ACL_STYLE_REGEX = 0,
963         ACL_STYLE_BASE,
964         ACL_STYLE_ONE,
965         ACL_STYLE_SUBTREE,
966         ACL_STYLE_CHILDREN,
967         ACL_STYLE_ATTROF,
968
969         /* alternate names */
970         ACL_STYLE_EXACT = ACL_STYLE_BASE
971 } slap_style_t;
972
973 typedef struct slap_authz_info {
974         ber_tag_t       sai_method;             /* LDAP_AUTH_* from <ldap.h> */
975         struct berval   sai_mech;               /* SASL Mechanism */
976         struct berval   sai_dn;                 /* DN for reporting purposes */
977         struct berval   sai_ndn;                /* Normalized DN */
978
979         /* Security Strength Factors */
980         slap_ssf_t      sai_ssf;                        /* Overall SSF */
981         slap_ssf_t      sai_transport_ssf;      /* Transport SSF */
982         slap_ssf_t      sai_tls_ssf;            /* TLS SSF */
983         slap_ssf_t      sai_sasl_ssf;           /* SASL SSF */
984 } AuthorizationInformation;
985
986 /* the "by" part */
987 typedef struct slap_access {
988         slap_control_t a_type;
989
990 #define ACL_ACCESS2PRIV(access) (0x01U << (access))
991
992 #define ACL_PRIV_NONE                   ACL_ACCESS2PRIV( ACL_NONE )
993 #define ACL_PRIV_AUTH                   ACL_ACCESS2PRIV( ACL_AUTH )
994 #define ACL_PRIV_COMPARE                ACL_ACCESS2PRIV( ACL_COMPARE )
995 #define ACL_PRIV_SEARCH                 ACL_ACCESS2PRIV( ACL_SEARCH )
996 #define ACL_PRIV_READ                   ACL_ACCESS2PRIV( ACL_READ )
997 #define ACL_PRIV_WRITE                  ACL_ACCESS2PRIV( ACL_WRITE )
998
999 #define ACL_PRIV_MASK                   0x00ffUL
1000
1001 /* priv flags */
1002 #define ACL_PRIV_LEVEL                  0x1000UL
1003 #define ACL_PRIV_ADDITIVE               0x2000UL
1004 #define ACL_PRIV_SUBSTRACTIVE   0x4000UL
1005
1006 /* invalid privs */
1007 #define ACL_PRIV_INVALID                0x0UL
1008
1009 #define ACL_PRIV_ISSET(m,p)             (((m) & (p)) == (p))
1010 #define ACL_PRIV_ASSIGN(m,p)    do { (m)  =  (p); } while(0)
1011 #define ACL_PRIV_SET(m,p)               do { (m) |=  (p); } while(0)
1012 #define ACL_PRIV_CLR(m,p)               do { (m) &= ~(p); } while(0)
1013
1014 #define ACL_INIT(m)                             ACL_PRIV_ASSIGN(m, ACL_PRIV_NONE)
1015 #define ACL_INVALIDATE(m)               ACL_PRIV_ASSIGN(m, ACL_PRIV_INVALID)
1016
1017 #define ACL_GRANT(m,a)                  ACL_PRIV_ISSET((m),ACL_ACCESS2PRIV(a))
1018
1019 #define ACL_IS_INVALID(m)               ((m) == ACL_PRIV_INVALID)
1020
1021 #define ACL_IS_LEVEL(m)                 ACL_PRIV_ISSET((m),ACL_PRIV_LEVEL)
1022 #define ACL_IS_ADDITIVE(m)              ACL_PRIV_ISSET((m),ACL_PRIV_ADDITIVE)
1023 #define ACL_IS_SUBTRACTIVE(m)   ACL_PRIV_ISSET((m),ACL_PRIV_SUBSTRACTIVE)
1024
1025 #define ACL_LVL_NONE                    (ACL_PRIV_NONE|ACL_PRIV_LEVEL)
1026 #define ACL_LVL_AUTH                    (ACL_PRIV_AUTH|ACL_LVL_NONE)
1027 #define ACL_LVL_COMPARE                 (ACL_PRIV_COMPARE|ACL_LVL_AUTH)
1028 #define ACL_LVL_SEARCH                  (ACL_PRIV_SEARCH|ACL_LVL_COMPARE)
1029 #define ACL_LVL_READ                    (ACL_PRIV_READ|ACL_LVL_SEARCH)
1030 #define ACL_LVL_WRITE                   (ACL_PRIV_WRITE|ACL_LVL_READ)
1031
1032 #define ACL_LVL(m,l)                    (((m)&ACL_PRIV_MASK) == ((l)&ACL_PRIV_MASK))
1033 #define ACL_LVL_IS_NONE(m)              ACL_LVL((m),ACL_LVL_NONE)
1034 #define ACL_LVL_IS_AUTH(m)              ACL_LVL((m),ACL_LVL_AUTH)
1035 #define ACL_LVL_IS_COMPARE(m)   ACL_LVL((m),ACL_LVL_COMPARE)
1036 #define ACL_LVL_IS_SEARCH(m)    ACL_LVL((m),ACL_LVL_SEARCH)
1037 #define ACL_LVL_IS_READ(m)              ACL_LVL((m),ACL_LVL_READ)
1038 #define ACL_LVL_IS_WRITE(m)             ACL_LVL((m),ACL_LVL_WRITE)
1039
1040 #define ACL_LVL_ASSIGN_NONE(m)          ACL_PRIV_ASSIGN((m),ACL_LVL_NONE)
1041 #define ACL_LVL_ASSIGN_AUTH(m)          ACL_PRIV_ASSIGN((m),ACL_LVL_AUTH)
1042 #define ACL_LVL_ASSIGN_COMPARE(m)       ACL_PRIV_ASSIGN((m),ACL_LVL_COMPARE)
1043 #define ACL_LVL_ASSIGN_SEARCH(m)        ACL_PRIV_ASSIGN((m),ACL_LVL_SEARCH)
1044 #define ACL_LVL_ASSIGN_READ(m)          ACL_PRIV_ASSIGN((m),ACL_LVL_READ)
1045 #define ACL_LVL_ASSIGN_WRITE(m)         ACL_PRIV_ASSIGN((m),ACL_LVL_WRITE)
1046
1047         slap_mask_t     a_access_mask;
1048
1049         AuthorizationInformation        a_authz;
1050 #define a_dn_pat        a_authz.sai_dn
1051
1052         slap_style_t a_dn_style;
1053         AttributeDescription    *a_dn_at;
1054         int                     a_dn_self;
1055         int                     a_dn_expand;
1056
1057         slap_style_t a_peername_style;
1058         struct berval   a_peername_pat;
1059         slap_style_t a_sockname_style;
1060         struct berval   a_sockname_pat;
1061
1062         slap_style_t a_domain_style;
1063         struct berval   a_domain_pat;
1064         int             a_domain_expand;
1065
1066         slap_style_t a_sockurl_style;
1067         struct berval   a_sockurl_pat;
1068         slap_style_t a_set_style;
1069         struct berval   a_set_pat;
1070
1071 #ifdef SLAPD_ACI_ENABLED
1072         AttributeDescription    *a_aci_at;
1073 #endif
1074
1075         /* ACL Groups */
1076         slap_style_t a_group_style;
1077         struct berval   a_group_pat;
1078         ObjectClass                             *a_group_oc;
1079         AttributeDescription    *a_group_at;
1080
1081         struct slap_access      *a_next;
1082 } Access;
1083
1084 /* the "to" part */
1085 typedef struct slap_acl {
1086         /* "to" part: the entries this acl applies to */
1087         Filter          *acl_filter;
1088         slap_style_t acl_dn_style;
1089         regex_t         acl_dn_re;
1090         struct berval   acl_dn_pat;
1091         AttributeName   *acl_attrs;
1092
1093         /* "by" part: list of who has what access to the entries */
1094         Access  *acl_access;
1095
1096         struct slap_acl *acl_next;
1097 } AccessControl;
1098
1099 typedef struct slap_acl_state {
1100         unsigned as_recorded;
1101 #define ACL_STATE_NOT_RECORDED                  0x0
1102 #define ACL_STATE_RECORDED_VD                   0x1
1103 #define ACL_STATE_RECORDED_NV                   0x2
1104 #define ACL_STATE_RECORDED                              0x3
1105
1106         /* Access state */
1107         AccessControl *as_vd_acl;
1108         AccessControl *as_vi_acl;
1109         slap_mask_t as_vd_acl_mask;
1110         regmatch_t as_vd_acl_matches[MAXREMATCHES];
1111         int as_vd_acl_count;
1112
1113         Access *as_vd_access;
1114         int as_vd_access_count;
1115
1116         int as_result;
1117         AttributeDescription *as_vd_ad;
1118 } AccessControlState;
1119 #define ACL_STATE_INIT { ACL_STATE_NOT_RECORDED, NULL, NULL, 0UL, { { 0, 0 } }, 0, NULL, 0, 0, NULL }
1120
1121 /*
1122  * replog moddn param structure
1123  */
1124 struct slap_replog_moddn {
1125         struct berval *newrdn;
1126         int     deloldrdn;
1127         struct berval *newsup;
1128 };
1129
1130 /*
1131  * Backend-info
1132  * represents a backend 
1133  */
1134
1135 typedef struct slap_backend_info BackendInfo;   /* per backend type */
1136 typedef struct slap_backend_db BackendDB;               /* per backend database */
1137
1138 LDAP_SLAPD_V (int) nBackendInfo;
1139 LDAP_SLAPD_V (int) nBackendDB;
1140 LDAP_SLAPD_V (BackendInfo *) backendInfo;
1141 LDAP_SLAPD_V (BackendDB *) backendDB;
1142
1143 LDAP_SLAPD_V (int) slapMode;    
1144 #define SLAP_UNDEFINED_MODE     0x0000
1145 #define SLAP_SERVER_MODE        0x0001
1146 #define SLAP_TOOL_MODE          0x0002
1147 #define SLAP_MODE                       0x0003
1148
1149 #define SLAP_TRUNCATE_MODE      0x0100
1150
1151 struct slap_replica_info {
1152         char *ri_host;                          /* supersedes be_replica */
1153         BerVarray ri_nsuffix;   /* array of suffixes this replica accepts */
1154         AttributeName *ri_attrs;        /* attrs to replicate, NULL=all */
1155         int ri_exclude;                 /* 1 => exclude ri_attrs */
1156 };
1157
1158 struct slap_limits_set {
1159         /* time limits */
1160         int     lms_t_soft;
1161         int     lms_t_hard;
1162
1163         /* size limits */
1164         int     lms_s_soft;
1165         int     lms_s_hard;
1166         int     lms_s_unchecked;
1167         int     lms_s_pr;
1168         int     lms_s_pr_hide;
1169 };
1170
1171 struct slap_limits {
1172         int     lm_type;        /* type of pattern */
1173 #define SLAP_LIMITS_UNDEFINED   0x0000
1174 #define SLAP_LIMITS_EXACT       0x0001
1175 #define SLAP_LIMITS_BASE        SLAP_LIMITS_EXACT
1176 #define SLAP_LIMITS_ONE         0x0002
1177 #define SLAP_LIMITS_SUBTREE     0x0003
1178 #define SLAP_LIMITS_CHILDREN    0x0004
1179 #define SLAP_LIMITS_REGEX       0x0005
1180 #define SLAP_LIMITS_ANONYMOUS   0x0006
1181 #define SLAP_LIMITS_USERS       0x0007
1182 #define SLAP_LIMITS_ANY         0x0008
1183         regex_t lm_dn_regex;            /* regex data for REGEX */
1184
1185         /*
1186          * normalized DN for EXACT, BASE, ONE, SUBTREE, CHILDREN;
1187          * pattern for REGEX; NULL for ANONYMOUS, USERS
1188          */
1189         struct berval lm_dn_pat;
1190
1191         struct slap_limits_set  lm_limits;
1192 };
1193
1194 /* temporary aliases */
1195 typedef BackendDB Backend;
1196 #define nbackends nBackendDB
1197 #define backends backendDB
1198
1199 struct slap_backend_db {
1200         BackendInfo     *bd_info;       /* pointer to shared backend info */
1201
1202         /* BackendInfo accessors */
1203 #define         be_config       bd_info->bi_db_config
1204 #define         be_type         bd_info->bi_type
1205
1206 #define         be_bind         bd_info->bi_op_bind
1207 #define         be_unbind       bd_info->bi_op_unbind
1208 #define         be_add          bd_info->bi_op_add
1209 #define         be_compare      bd_info->bi_op_compare
1210 #define         be_delete       bd_info->bi_op_delete
1211 #define         be_modify       bd_info->bi_op_modify
1212 #define         be_modrdn       bd_info->bi_op_modrdn
1213 #define         be_search       bd_info->bi_op_search
1214
1215 #define         be_extended     bd_info->bi_extended
1216
1217 #define         be_release      bd_info->bi_entry_release_rw
1218 #define         be_chk_referrals        bd_info->bi_chk_referrals
1219 #define         be_group        bd_info->bi_acl_group
1220 #define         be_attribute    bd_info->bi_acl_attribute
1221 #define         be_operational  bd_info->bi_operational
1222
1223 /*
1224  * define to honor hasSubordinates operational attribute in search filters
1225  * (in previous use there was a flaw with back-bdb and back-ldbm; now it 
1226  * is fixed).
1227  */
1228
1229 #define         be_has_subordinates bd_info->bi_has_subordinates
1230
1231 #define         be_controls     bd_info->bi_controls
1232
1233 #define         be_connection_init      bd_info->bi_connection_init
1234 #define         be_connection_destroy   bd_info->bi_connection_destroy
1235
1236 #ifdef SLAPD_TOOLS
1237 #define         be_entry_open bd_info->bi_tool_entry_open
1238 #define         be_entry_close bd_info->bi_tool_entry_close
1239 #define         be_entry_first bd_info->bi_tool_entry_first
1240 #define         be_entry_next bd_info->bi_tool_entry_next
1241 #define         be_entry_reindex bd_info->bi_tool_entry_reindex
1242 #define         be_entry_get bd_info->bi_tool_entry_get
1243 #define         be_entry_put bd_info->bi_tool_entry_put
1244 #define         be_sync bd_info->bi_tool_sync
1245 #endif
1246
1247 #define SLAP_BFLAG_NOLASTMOD            0x0001U
1248 #define SLAP_BFLAG_GLUE_INSTANCE        0x0010U /* a glue backend */
1249 #define SLAP_BFLAG_GLUE_SUBORDINATE     0x0020U /* child of a glue hierarchy */
1250 #define SLAP_BFLAG_GLUE_LINKED          0x0040U /* child is connected to parent */
1251 #define SLAP_BFLAG_ALIASES              0x0100U
1252 #define SLAP_BFLAG_REFERRALS    0x0200U
1253 #define SLAP_BFLAG_SUBENTRIES   0x0400U
1254 #define SLAP_BFLAG_MONITOR              0x1000U
1255 #define SLAP_BFLAG_DYNAMIC              0x2000U
1256         slap_mask_t     be_flags;
1257 #define SLAP_LASTMOD(be)        (!((be)->be_flags & SLAP_BFLAG_NOLASTMOD))
1258 #define SLAP_ALIASES(be)        ((be)->be_flags & SLAP_BFLAG_ALIASES)
1259 #define SLAP_REFERRALS(be)      ((be)->be_flags & SLAP_BFLAG_REFERRALS)
1260 #define SLAP_SUBENTRIES(be)     ((be)->be_flags & SLAP_BFLAG_SUBENTRIES)
1261 #define SLAP_MONITOR(be)        ((be)->be_flags & SLAP_BFLAG_MONITOR)
1262 #define SLAP_DYNAMIC(be)        ((be)->be_flags & SLAP_BFLAG_DYNAMIC)
1263
1264         slap_mask_t     be_restrictops;         /* restriction operations */
1265 #define SLAP_RESTRICT_OP_ADD            0x0001U
1266 #define SLAP_RESTRICT_OP_BIND           0x0002U
1267 #define SLAP_RESTRICT_OP_COMPARE        0x0004U
1268 #define SLAP_RESTRICT_OP_DELETE         0x0008U
1269 #define SLAP_RESTRICT_OP_EXTENDED       0x0010U
1270 #define SLAP_RESTRICT_OP_MODIFY         0x0020U
1271 #define SLAP_RESTRICT_OP_RENAME         0x0040U
1272 #define SLAP_RESTRICT_OP_SEARCH         0x0080U
1273
1274 #define SLAP_RESTRICT_OP_READS  \
1275         ( SLAP_RESTRICT_OP_COMPARE      \
1276         | SLAP_RESTRICT_OP_SEARCH )
1277 #define SLAP_RESTRICT_OP_WRITES \
1278         ( SLAP_RESTRICT_OP_ADD    \
1279         | SLAP_RESTRICT_OP_DELETE \
1280         | SLAP_RESTRICT_OP_MODIFY \
1281         | SLAP_RESTRICT_OP_RENAME )
1282
1283 #define SLAP_ALLOW_BIND_V2                      0x0001U /* LDAPv2 bind */
1284 #define SLAP_ALLOW_BIND_ANON_CRED       0x0002U /* cred should be empty */
1285 #define SLAP_ALLOW_BIND_ANON_DN         0x0004U /* dn should be empty */
1286
1287 #define SLAP_ALLOW_UPDATE_ANON          0x0008U /* allow anonymous updates */
1288
1289 #define SLAP_DISALLOW_BIND_ANON         0x0001U /* no anonymous */
1290 #define SLAP_DISALLOW_BIND_SIMPLE       0x0002U /* simple authentication */
1291 #define SLAP_DISALLOW_BIND_SIMPLE_UNPROTECTED \
1292                                                                         0x0004U /* unprotected simple auth */
1293 #define SLAP_DISALLOW_BIND_KRBV4        0x0008U /* Kerberos V4 authentication */
1294
1295 #define SLAP_DISALLOW_TLS_2_ANON        0x0010U /* StartTLS -> Anonymous */
1296 #define SLAP_DISALLOW_TLS_AUTHC         0x0020U /* TLS while authenticated */
1297
1298 #define SLAP_DISALLOW_AUX_WO_CR         0x4000U
1299
1300         slap_mask_t     be_requires;    /* pre-operation requirements */
1301 #define SLAP_REQUIRE_BIND               0x0001U /* bind before op */
1302 #define SLAP_REQUIRE_LDAP_V3    0x0002U /* LDAPv3 before op */
1303 #define SLAP_REQUIRE_AUTHC              0x0004U /* authentication before op */
1304 #define SLAP_REQUIRE_SASL               0x0008U /* SASL before op  */
1305 #define SLAP_REQUIRE_STRONG             0x0010U /* strong authentication before op */
1306
1307         /* Required Security Strength Factor */
1308         slap_ssf_set_t be_ssf_set;
1309
1310         /* these should be renamed from be_ to bd_ */
1311         BerVarray       be_suffix;      /* the DN suffixes of data in this backend */
1312         BerVarray       be_nsuffix;     /* the normalized DN suffixes in this backend */
1313         BerVarray       be_suffixAlias; /* pairs of DN suffix aliases and deref values */
1314         struct berval be_schemadn;      /* per-backend subschema subentry DN */
1315         struct berval be_schemandn;     /* normalized subschema DN */
1316         struct berval be_rootdn;        /* the magic "root" name (DN) for this db */
1317         struct berval be_rootndn;       /* the magic "root" normalized name (DN) for this db */
1318         struct berval be_rootpw;        /* the magic "root" password for this db        */
1319         unsigned int be_max_deref_depth; /* limit for depth of an alias deref  */
1320 #define be_sizelimit    be_def_limit.lms_s_soft
1321 #define be_timelimit    be_def_limit.lms_t_soft
1322         struct slap_limits_set be_def_limit; /* default limits */
1323         struct slap_limits **be_limits; /* regex-based size and time limits */
1324         AccessControl *be_acl;  /* access control list for this backend    */
1325         slap_access_t   be_dfltaccess;  /* access given if no acl matches          */
1326         struct slap_replica_info **be_replica;  /* replicas of this backend (in master) */
1327         char    *be_replogfile; /* replication log file (in master)        */
1328         struct berval be_update_ndn;    /* allowed to make changes (in replicas) */
1329         BerVarray       be_update_refs; /* where to refer modifying clients to */
1330         char    *be_realm;
1331         void    *be_private;    /* anything the backend database needs     */
1332
1333         void    *be_pb;         /* Netscape plugin */
1334 };
1335
1336 struct slap_conn;
1337 struct slap_op;
1338
1339 /* Backend function typedefs */
1340 typedef int (BI_init) LDAP_P((BackendInfo *bi));
1341 typedef int (BI_config) LDAP_P((BackendInfo *bi,
1342         const char *fname, int lineno,
1343         int argc, char **argv));
1344 typedef int (BI_open) LDAP_P((BackendInfo *bi));
1345 typedef int (BI_close) LDAP_P((BackendInfo *bi));
1346 typedef int (BI_destroy) LDAP_P((BackendInfo *bi));
1347
1348 typedef int (BI_db_init) LDAP_P((Backend *bd));
1349 typedef int (BI_db_config) LDAP_P((Backend *bd,
1350         const char *fname, int lineno,
1351         int argc, char **argv));
1352 typedef int (BI_db_open) LDAP_P((Backend *bd));
1353 typedef int (BI_db_close) LDAP_P((Backend *bd));
1354 typedef int (BI_db_destroy) LDAP_P((Backend *bd));
1355
1356 typedef int (BI_op_bind)  LDAP_P(( BackendDB *bd,
1357                 struct slap_conn *c, struct slap_op *o,
1358                 struct berval *dn, struct berval *ndn, int method,
1359                 struct berval *cred, struct berval *edn ));
1360 typedef int (BI_op_unbind) LDAP_P((BackendDB *bd,
1361                 struct slap_conn *c, struct slap_op *o ));
1362 typedef int (BI_op_search) LDAP_P((BackendDB *bd,
1363                 struct slap_conn *c, struct slap_op *o,
1364                 struct berval *base, struct berval *nbase,
1365                 int scope, int deref,
1366                 int slimit, int tlimit,
1367                 Filter *f, struct berval *filterstr,
1368                 AttributeName *attrs, int attrsonly));
1369 typedef int (BI_op_compare)LDAP_P((BackendDB *bd,
1370                 struct slap_conn *c, struct slap_op *o,
1371                 struct berval *dn, struct berval *ndn,
1372                 AttributeAssertion *ava));
1373 typedef int (BI_op_modify) LDAP_P((BackendDB *bd,
1374                 struct slap_conn *c, struct slap_op *o,
1375                 struct berval *dn, struct berval *ndn,
1376                 Modifications *m));
1377 typedef int (BI_op_modrdn) LDAP_P((BackendDB *bd,
1378                 struct slap_conn *c, struct slap_op *o,
1379                 struct berval *dn, struct berval *ndn,
1380                 struct berval *newrdn, struct berval *nnewrdn,
1381                 int deleteoldrdn,
1382                 struct berval *newSup, struct berval *nnewSup ));
1383 typedef int (BI_op_add)    LDAP_P((BackendDB *bd,
1384                 struct slap_conn *c, struct slap_op *o,
1385                 Entry *e));
1386 typedef int (BI_op_delete) LDAP_P((BackendDB *bd,
1387                 struct slap_conn *c, struct slap_op *o,
1388                 struct berval *dn, struct berval *ndn));
1389 typedef int (BI_op_abandon) LDAP_P((BackendDB *bd,
1390                 struct slap_conn *c, struct slap_op *o,
1391                 ber_int_t msgid));
1392
1393 typedef int (BI_op_extended) LDAP_P((
1394         BackendDB               *be,
1395         struct slap_conn        *conn,
1396         struct slap_op          *op,
1397         const char              *reqoid,
1398         struct berval * reqdata,
1399         char            **rspoid,
1400         struct berval ** rspdata,
1401         LDAPControl *** rspctrls,
1402         const char **   text,
1403         BerVarray *refs ));
1404
1405 typedef int (BI_entry_release_rw) LDAP_P((BackendDB *bd,
1406                 struct slap_conn *c, struct slap_op *o,
1407                 Entry *e, int rw));
1408
1409 typedef int (BI_chk_referrals) LDAP_P((BackendDB *bd,
1410                 struct slap_conn *c, struct slap_op *o,
1411                 struct berval *dn, struct berval *ndn,
1412                 const char **text ));
1413
1414 typedef int (BI_acl_group)  LDAP_P((Backend *bd,
1415                 struct slap_conn *c, struct slap_op *o,
1416                 Entry *e,
1417                 struct berval *bdn,
1418                 struct berval *edn,
1419                 ObjectClass *group_oc,
1420                 AttributeDescription *group_at ));
1421
1422 typedef int (BI_acl_attribute)  LDAP_P((Backend *bd,
1423                 struct slap_conn *c, struct slap_op *o,
1424                 Entry *e, struct berval *edn,
1425                 AttributeDescription *entry_at,
1426                 BerVarray *vals ));
1427
1428 typedef int (BI_operational)  LDAP_P((Backend *bd,
1429                 struct slap_conn *c, struct slap_op *o,
1430                 Entry *e, AttributeName *attrs, int opattrs, Attribute **a ));
1431
1432 typedef int (BI_has_subordinates) LDAP_P((Backend *bd,
1433                 struct slap_conn *c, struct slap_op *o,
1434                 Entry *e, int *has_subordinates ));
1435
1436 typedef int (BI_connection_init) LDAP_P((BackendDB *bd,
1437                 struct slap_conn *c));
1438 typedef int (BI_connection_destroy) LDAP_P((BackendDB *bd,
1439                 struct slap_conn *c));
1440
1441 typedef int (BI_tool_entry_open) LDAP_P(( BackendDB *be, int mode ));
1442 typedef int (BI_tool_entry_close) LDAP_P(( BackendDB *be ));
1443 typedef ID (BI_tool_entry_first) LDAP_P(( BackendDB *be ));
1444 typedef ID (BI_tool_entry_next) LDAP_P(( BackendDB *be ));
1445 typedef Entry* (BI_tool_entry_get) LDAP_P(( BackendDB *be, ID id ));
1446 typedef ID (BI_tool_entry_put) LDAP_P(( BackendDB *be, Entry *e, 
1447                         struct berval *text ));
1448 typedef int (BI_tool_entry_reindex) LDAP_P(( BackendDB *be, ID id ));
1449 typedef int (BI_tool_sync) LDAP_P(( BackendDB *be ));
1450
1451 struct slap_backend_info {
1452         char    *bi_type; /* type of backend */
1453
1454         /*
1455          * per backend type routines:
1456          * bi_init: called to allocate a backend_info structure,
1457          *              called once BEFORE configuration file is read.
1458          *              bi_init() initializes this structure hence is
1459          *              called directly from be_initialize()
1460          * bi_config: called per 'backend' specific option
1461          *              all such options must before any 'database' options
1462          *              bi_config() is called only from read_config()
1463          * bi_open: called to open each database, called
1464          *              once AFTER configuration file is read but
1465          *              BEFORE any bi_db_open() calls.
1466          *              bi_open() is called from backend_startup()
1467          * bi_close: called to close each database, called
1468          *              once during shutdown after all bi_db_close calls.
1469          *              bi_close() is called from backend_shutdown()
1470          * bi_destroy: called to destroy each database, called
1471          *              once during shutdown after all bi_db_destroy calls.
1472          *              bi_destory() is called from backend_destroy()
1473          */
1474         BI_init *bi_init;
1475         BI_config       *bi_config;
1476         BI_open *bi_open;
1477         BI_close        *bi_close;
1478         BI_destroy      *bi_destroy;
1479
1480         /*
1481          * per database routines:
1482          * bi_db_init: called to initialize each database,
1483          *      called upon reading 'database <type>' 
1484          *      called only from backend_db_init()
1485          * bi_db_config: called to configure each database,
1486          *  called per database to handle per database options
1487          *      called only from read_config()
1488          * bi_db_open: called to open each database
1489          *      called once per database immediately AFTER bi_open()
1490          *      calls but before daemon startup.
1491          *  called only by backend_startup()
1492          * bi_db_close: called to close each database
1493          *      called once per database during shutdown but BEFORE
1494          *  any bi_close call.
1495          *  called only by backend_shutdown()
1496          * bi_db_destroy: called to destroy each database
1497          *  called once per database during shutdown AFTER all
1498          *  bi_close calls but before bi_destory calls.
1499          *  called only by backend_destory()
1500          */
1501         BI_db_init      *bi_db_init;
1502         BI_db_config    *bi_db_config;
1503         BI_db_open      *bi_db_open;
1504         BI_db_close     *bi_db_close;
1505         BI_db_destroy   *bi_db_destroy;
1506
1507         /* LDAP Operations Handling Routines */
1508         BI_op_bind      *bi_op_bind;
1509         BI_op_unbind    *bi_op_unbind;
1510         BI_op_search    *bi_op_search;
1511         BI_op_compare   *bi_op_compare;
1512         BI_op_modify    *bi_op_modify;
1513         BI_op_modrdn    *bi_op_modrdn;
1514         BI_op_add       *bi_op_add;
1515         BI_op_delete    *bi_op_delete;
1516         BI_op_abandon   *bi_op_abandon;
1517
1518         /* Extended Operations Helper */
1519         BI_op_extended  *bi_extended;
1520
1521         /* Auxilary Functions */
1522         BI_entry_release_rw     *bi_entry_release_rw;
1523         BI_chk_referrals        *bi_chk_referrals;
1524
1525         BI_acl_group    *bi_acl_group;
1526         BI_acl_attribute        *bi_acl_attribute;
1527
1528         BI_operational  *bi_operational;
1529         BI_has_subordinates     *bi_has_subordinates;
1530
1531         BI_connection_init      *bi_connection_init;
1532         BI_connection_destroy   *bi_connection_destroy;
1533
1534         /* hooks for slap tools */
1535         BI_tool_entry_open      *bi_tool_entry_open;
1536         BI_tool_entry_close     *bi_tool_entry_close;
1537         BI_tool_entry_first     *bi_tool_entry_first;
1538         BI_tool_entry_next      *bi_tool_entry_next;
1539         BI_tool_entry_get       *bi_tool_entry_get;
1540         BI_tool_entry_put       *bi_tool_entry_put;
1541         BI_tool_entry_reindex   *bi_tool_entry_reindex;
1542         BI_tool_sync            *bi_tool_sync;
1543
1544 #define SLAP_INDEX_ADD_OP               0x0001
1545 #define SLAP_INDEX_DELETE_OP    0x0002
1546
1547         char **bi_controls;             /* supported controls */
1548
1549         unsigned int bi_nDB;    /* number of databases of this type */
1550         void    *bi_private;    /* anything the backend type needs */
1551 };
1552
1553 #define c_authtype      c_authz.sai_method
1554 #define c_authmech      c_authz.sai_mech
1555 #define c_dn            c_authz.sai_dn
1556 #define c_ndn           c_authz.sai_ndn
1557 #define c_ssf                   c_authz.sai_ssf
1558 #define c_transport_ssf c_authz.sai_transport_ssf
1559 #define c_tls_ssf               c_authz.sai_tls_ssf
1560 #define c_sasl_ssf              c_authz.sai_sasl_ssf
1561
1562 #define o_authtype      o_authz.sai_method
1563 #define o_authmech      o_authz.sai_mech
1564 #define o_dn            o_authz.sai_dn
1565 #define o_ndn           o_authz.sai_ndn
1566 #define o_ssf                   o_authz.sai_ssf
1567 #define o_transport_ssf o_authz.sai_transport_ssf
1568 #define o_tls_ssf               o_authz.sai_tls_ssf
1569 #define o_sasl_ssf              o_authz.sai_sasl_ssf
1570
1571 typedef void (slap_response)( struct slap_conn *, struct slap_op *,
1572         ber_tag_t, ber_int_t, ber_int_t, const char *, const char *,
1573         BerVarray, const char *, struct berval *,
1574         struct berval *, LDAPControl ** );
1575
1576 typedef void (slap_sresult)( struct slap_conn *, struct slap_op *,
1577         ber_int_t, const char *, const char *, BerVarray,
1578         LDAPControl **, int nentries);
1579
1580 typedef int (slap_sendentry)( BackendDB *, struct slap_conn *,
1581         struct slap_op *, Entry *, AttributeName *, int, LDAPControl **);
1582
1583 typedef struct slap_callback {
1584         slap_response *sc_response;
1585         slap_sresult *sc_sresult;
1586         slap_sendentry *sc_sendentry;
1587         void *sc_private;
1588 } slap_callback;
1589
1590 /*
1591  * Paged Results state
1592  */
1593 typedef unsigned long PagedResultsCookie;
1594 typedef struct slap_paged_state {
1595         Backend *ps_be;
1596         PagedResultsCookie ps_cookie;
1597         ID ps_id;
1598 } PagedResultsState;
1599
1600
1601 #ifdef LDAP_CLIENT_UPDATE
1602 #define LCUP_PSEARCH_BY_ADD 0x01
1603 #define LCUP_PSEARCH_BY_DELETE 0x02
1604 #define LCUP_PSEARCH_BY_PREMODIFY 0x03
1605 #define LCUP_PSEARCH_BY_MODIFY 0x04
1606 #define LCUP_PSEARCH_BY_SCOPEOUT 0x05
1607
1608 struct lcup_search_spec {
1609         struct slap_op  *op;
1610         struct berval   *base;
1611         struct berval   *nbase;
1612         int             scope;
1613         int             deref;
1614         int             slimit;
1615         int             tlimit;
1616         Filter          *filter;
1617         struct berval   *filterstr;
1618         AttributeName   *attrs;
1619         int             attrsonly;
1620         struct lcup_entry *elist;
1621         ldap_pvt_thread_mutex_t elist_mutex;
1622         int             entry_count;
1623         LDAP_LIST_ENTRY(lcup_search_spec) link;
1624 };
1625
1626 struct psid_entry {
1627         struct lcup_search_spec* ps;
1628         LDAP_LIST_ENTRY(psid_entry) link;
1629 };
1630 #endif /* LDAP_CLIENT_UPDATE */
1631
1632
1633 /*
1634  * represents an operation pending from an ldap client
1635  */
1636 typedef struct slap_op {
1637         unsigned long o_opid;   /* id of this operation */
1638         unsigned long o_connid; /* id of conn initiating this op */
1639         struct slap_conn *o_conn;       /* connection spawning this op */
1640
1641         ber_int_t       o_msgid;        /* msgid of the request */
1642         ber_int_t       o_protocol;     /* version of the LDAP protocol used by client */
1643         ber_tag_t       o_tag;          /* tag of the request */
1644         time_t          o_time;         /* time op was initiated */
1645
1646         char *          o_extendedop;   /* extended operation OID */
1647
1648         ldap_pvt_thread_t       o_tid;  /* thread handling this op */
1649
1650         volatile sig_atomic_t o_abandon;        /* abandon flag */
1651
1652         char o_do_not_cache;    /* don't cache from this op */
1653
1654 #define SLAP_NO_CONTROL 0
1655 #define SLAP_NONCRITICAL_CONTROL 1
1656 #define SLAP_CRITICAL_CONTROL 2
1657         char o_managedsait;
1658         char o_noop;
1659         char o_proxy_authz;
1660         char o_subentries;
1661         char o_subentries_visibility;
1662         char o_valuesreturnfilter;
1663
1664         char o_pagedresults;
1665         ber_int_t o_pagedresults_size;
1666         PagedResultsState o_pagedresults_state;
1667
1668 #ifdef LDAP_CLIENT_UPDATE
1669         char o_clientupdate;
1670         char o_clientupdate_type;
1671 #define SLAP_LCUP_NONE                          (0x0)
1672 #define SLAP_LCUP_SYNC                          (0x1)
1673 #define SLAP_LCUP_PERSIST                       (0x2)
1674 #define SLAP_LCUP_SYNC_AND_PERSIST      (0x3)
1675         ber_int_t o_clientupdate_interval;
1676         struct berval o_clientupdate_state;
1677         LDAP_LIST_HEAD(lss, lcup_search_spec) psearch_spec;
1678         LDAP_LIST_HEAD(pe, psid_entry) premodify_list;
1679         LDAP_LIST_ENTRY(slap_op) link;
1680 #endif /* LDAP_CLIENT_UPDATE */
1681
1682 #ifdef LDAP_CONNECTIONLESS
1683         Sockaddr        o_peeraddr;     /* UDP peer address               */
1684 #endif
1685         AuthorizationInformation o_authz;
1686
1687         BerElement      *o_ber;         /* ber of the request             */
1688         slap_callback   *o_callback;    /* callback pointers */
1689         LDAPControl     **o_ctrls;       /* controls */
1690
1691         void    *o_threadctx;           /* thread pool thread context */
1692         void    *o_private;     /* anything the backend needs */
1693
1694         LDAP_STAILQ_ENTRY(slap_op)      o_next; /* next operation in list         */
1695         ValuesReturnFilter *vrFilter; /* Structure represents ValuesReturnFilter */
1696
1697         void    *o_pb;                  /* Netscape plugin */
1698
1699 } Operation;
1700
1701 #define get_manageDSAit(op)                             ((int)(op)->o_managedsait)
1702 #define get_subentries(op)                              ((int)(op)->o_subentries)
1703 #define get_subentries_visibility(op)   ((int)(op)->o_subentries_visibility)
1704 #define get_pagedresults(op)                    ((int)(op)->o_pagedresults)
1705
1706
1707
1708 typedef void (*SEND_LDAP_RESULT)(
1709                                 struct slap_conn *conn,
1710                                 struct slap_op *op,
1711                                 ber_int_t err,
1712                                 const char *matched,
1713                                 const char *text,
1714                                 BerVarray ref,
1715                                 LDAPControl **ctrls
1716                                 );
1717
1718 #define send_ldap_result( conn, op, err, matched, text, ref, ctrls  ) \
1719 (*conn->c_send_ldap_result)( conn, op, err, matched, text, ref, ctrls )
1720
1721
1722 typedef int (*SEND_SEARCH_ENTRY)(
1723                                 struct slap_backend_db *be,
1724                                 struct slap_conn *conn,
1725                                 struct slap_op *op,
1726                                 struct slap_entry *e,
1727                                 AttributeName *attrs,
1728                                 int attrsonly,
1729                                 LDAPControl **ctrls
1730                                 );
1731
1732 #define send_search_entry( be, conn, op, e, attrs, attrsonly, ctrls) \
1733 (*conn->c_send_search_entry)( be, conn, op, e, attrs, attrsonly, ctrls)
1734
1735
1736 typedef void (*SEND_SEARCH_RESULT)(
1737                                 struct slap_conn *conn,
1738                                 struct slap_op *op,
1739                                 ber_int_t err,
1740                                 const char *matched,
1741                                 const char *text,
1742                                 BerVarray   refs,
1743                                 LDAPControl **ctrls,
1744                                 int nentries
1745                                 );
1746
1747 #define send_search_result( conn, op, err, matched, text, refs, ctrls, nentries ) \
1748 (*conn->c_send_search_result)( conn, op, err, matched, text, refs, ctrls, nentries )
1749
1750
1751 typedef int (*SEND_SEARCH_REFERENCE)(
1752                                 struct slap_backend_db *be,
1753                                 struct slap_conn *conn,
1754                                 struct slap_op *op,
1755                                 struct slap_entry *e,
1756                                 BerVarray refs,
1757                                 LDAPControl **ctrls,
1758                                 BerVarray *v2refs
1759                                 );
1760
1761 #define send_search_reference( be, conn, op, e,  refs, ctrls, v2refs ) \
1762 (*conn->c_send_search_reference)( be, conn, op, e,  refs, ctrls, v2refs )
1763
1764
1765 typedef void (*SEND_LDAP_EXTENDED)(
1766                                 struct slap_conn *conn,
1767                                 struct slap_op *op,
1768                                 ber_int_t   err,
1769                                 const char  *matched,
1770                                 const char  *text,
1771                                 BerVarray   refs,
1772                                 const char      *rspoid,
1773                                 struct berval *rspdata,
1774                                 LDAPControl **ctrls
1775                                 );
1776
1777 #define send_ldap_extended( conn, op, err, matched, text, refs, rspoid, rspdata, ctrls) \
1778 (*conn->c_send_ldap_extended)( conn, op, err, matched, text, refs, rspoid, rspdata, ctrls )
1779
1780
1781 /*
1782  * Caches the result of a backend_group check for ACL evaluation
1783  */
1784 typedef struct slap_gacl {
1785         struct slap_gacl *ga_next;
1786         Backend *ga_be;
1787         ObjectClass *ga_oc;
1788         AttributeDescription *ga_at;
1789         int ga_res;
1790         ber_len_t ga_len;
1791         char ga_ndn[1];
1792 } GroupAssertion;
1793
1794 typedef struct slap_listener Listener;
1795
1796 /*
1797  * represents a connection from an ldap client
1798  */
1799 typedef struct slap_conn {
1800         int                     c_struct_state; /* structure management state */
1801         int                     c_conn_state;   /* connection state */
1802
1803         ldap_pvt_thread_mutex_t c_mutex; /* protect the connection */
1804         Sockbuf         *c_sb;                  /* ber connection stuff           */
1805
1806         /* only can be changed by connect_init */
1807         time_t          c_starttime;    /* when the connection was opened */
1808         time_t          c_activitytime; /* when the connection was last used */
1809         unsigned long           c_connid;       /* id of this connection for stats*/
1810
1811         struct berval   c_peer_domain;  /* DNS name of client */
1812         struct berval   c_peer_name;    /* peer name (trans=addr:port) */
1813         Listener        *c_listener;
1814 #define c_listener_url c_listener->sl_url       /* listener URL */
1815 #define c_sock_name c_listener->sl_name /* sock name (trans=addr:port) */
1816
1817         /* only can be changed by binding thread */
1818         int             c_sasl_bind_in_progress;        /* multi-op bind in progress */
1819         struct berval   c_sasl_bind_mech;                       /* mech in progress */
1820         struct berval   c_sasl_dn;      /* temporary storage */
1821
1822         /* authorization backend */
1823         Backend *c_authz_backend;
1824
1825         AuthorizationInformation c_authz;
1826         GroupAssertion *c_groups;
1827
1828         ber_int_t       c_protocol;     /* version of the LDAP protocol used by client */
1829
1830         LDAP_STAILQ_HEAD(c_o, slap_op) c_ops;   /* list of operations being processed */
1831         LDAP_STAILQ_HEAD(c_po, slap_op) c_pending_ops;  /* list of pending operations */
1832
1833         ldap_pvt_thread_mutex_t c_write_mutex;  /* only one pdu written at a time */
1834         ldap_pvt_thread_cond_t  c_write_cv;             /* used to wait for sd write-ready*/
1835
1836         BerElement      *c_currentber;  /* ber we're attempting to read */
1837         int             c_writewaiter;  /* true if writer is waiting */
1838
1839 #ifdef LDAP_CONNECTIONLESS
1840         int     c_is_udp;               /* true if this is (C)LDAP over UDP */
1841 #endif
1842 #ifdef HAVE_TLS
1843         int     c_is_tls;               /* true if this LDAP over raw TLS */
1844         int     c_needs_tls_accept;     /* true if SSL_accept should be called */
1845 #endif
1846         int             c_sasl_layers;   /* true if we need to install SASL i/o handlers */
1847         void    *c_sasl_context;        /* SASL session context */
1848         void    *c_sasl_extra;          /* SASL session extra stuff */
1849         struct slap_op  *c_sasl_bindop; /* set to current op if it's a bind */
1850
1851         PagedResultsState c_pagedresults_state; /* paged result state */
1852
1853         long    c_n_ops_received;       /* num of ops received (next op_id) */
1854         long    c_n_ops_executing;      /* num of ops currently executing */
1855         long    c_n_ops_pending;        /* num of ops pending execution */
1856         long    c_n_ops_completed;      /* num of ops completed */
1857
1858         long    c_n_get;                /* num of get calls */
1859         long    c_n_read;               /* num of read calls */
1860         long    c_n_write;              /* num of write calls */
1861
1862         void    *c_pb;                  /* Netscape plugin */
1863
1864     /*
1865          * These are the "callbacks" that are available for back-ends to
1866          * supply data back to connected clients that are connected
1867          * through the "front-end".
1868         */
1869         SEND_LDAP_RESULT c_send_ldap_result;
1870         SEND_SEARCH_ENTRY c_send_search_entry;
1871         SEND_SEARCH_RESULT c_send_search_result;
1872         SEND_SEARCH_REFERENCE c_send_search_reference;
1873         SEND_LDAP_EXTENDED c_send_ldap_extended;
1874         
1875 } Connection;
1876
1877 #if defined(LDAP_SYSLOG) && defined(LDAP_DEBUG)
1878 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 )  \
1879         do { \
1880                 if ( ldap_debug & (level) ) \
1881                         fprintf( stderr, (fmt), (connid), (opid), (arg1), (arg2), (arg3) );\
1882                 if ( ldap_syslog & (level) ) \
1883                         syslog( ldap_syslog_level, (fmt), (connid), (opid), (arg1), \
1884                                 (arg2), (arg3) ); \
1885         } while (0)
1886 #elif defined(LDAP_DEBUG)
1887 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 )  \
1888         do { \
1889                 if ( ldap_debug & (level) ) \
1890                         fprintf( stderr, (fmt), (connid), (opid), (arg1), (arg2), (arg3) );\
1891         } while (0)
1892 #elif defined(LDAP_SYSLOG)
1893 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 )  \
1894         do { \
1895                 if ( ldap_syslog & (level) ) \
1896                         syslog( ldap_syslog_level, (fmt), (connid), (opid), (arg1), \
1897                                 (arg2), (arg3) ); \
1898         } while (0)
1899 #else
1900 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 )
1901 #endif
1902
1903 /*
1904  * listener; need to access it from monitor backend
1905  */
1906 struct slap_listener {
1907         struct berval sl_url;
1908         struct berval sl_name;
1909         mode_t  sl_perms;
1910 #ifdef HAVE_TLS
1911         int             sl_is_tls;
1912 #endif
1913 #ifdef LDAP_CONNECTIONLESS
1914         int     sl_is_udp;              /* UDP listener is also data port */
1915 #endif
1916         ber_socket_t sl_sd;
1917         Sockaddr sl_sa;
1918 #define sl_addr sl_sa.sa_in_addr
1919 };
1920
1921 #ifdef SLAPD_MONITOR
1922 /*
1923  * Operation indices
1924  */
1925 enum {
1926         SLAP_OP_BIND = 0,
1927         SLAP_OP_UNBIND,
1928         SLAP_OP_ADD,
1929         SLAP_OP_DELETE,
1930         SLAP_OP_MODRDN,
1931         SLAP_OP_MODIFY,
1932         SLAP_OP_COMPARE,
1933         SLAP_OP_SEARCH,
1934         SLAP_OP_ABANDON,
1935         SLAP_OP_EXTENDED,
1936         SLAP_OP_LAST
1937 };
1938 #endif /* SLAPD_MONITOR */
1939
1940 /*
1941  * Better know these all around slapd
1942  */
1943 #define SLAP_LDAPDN_PRETTY 0x1
1944 #define SLAP_LDAPDN_MAXLEN 8192
1945
1946 /*
1947  * Macros for LCUP
1948  */
1949 #ifdef LDAP_CLIENT_UPDATE
1950 #define SLAP_LCUP_STATE_UPDATE_TRUE     1
1951 #define SLAP_LCUP_STATE_UPDATE_FALSE    0
1952 #define SLAP_LCUP_ENTRY_DELETED_TRUE    1
1953 #define SLAP_LCUP_ENTRY_DELETED_FALSE   0
1954 #endif /* LDAP_CLIENT_UPDATE */
1955
1956 LDAP_END_DECL
1957
1958 #include "proto-slap.h"
1959
1960 #endif /* _SLAP_H_ */