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