1 /* slap.h - stand alone ldap server include file */
4 * Copyright 1998-2002 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/socket.h>
26 #define ldap_debug slap_debug
32 #include <ldap_schema.h>
34 #include "ldap_pvt_thread.h"
35 #include "ldap_queue.h"
39 * SLAPD Memory allocation macros
41 * Unlike ch_*() routines, these routines do not assert() upon
42 * allocation error. They are intended to be used instead of
43 * ch_*() routines where the caller has implemented proper
44 * checking for and handling of allocation errors.
46 * Patches to convert ch_*() calls to SLAP_*() calls welcomed.
48 #define SLAP_MALLOC(s) ber_memalloc((s))
49 #define SLAP_CALLOC(n,s) ber_memcalloc((n),(s))
50 #define SLAP_REALLOC(p,s) ber_memrealloc((p),(s))
51 #define SLAP_FREE(p) ber_memfree((p))
52 #define SLAP_VFREE(v) ber_memvfree((void**)(v))
53 #define SLAP_STRDUP(s) ber_strdup((s))
54 #define SLAP_STRNDUP(s,l) ber_strndup((s),(l))
57 #undef f_next /* name conflict between sys/file.h on SCO and struct filter */
60 #define SERVICE_NAME OPENLDAP_PACKAGE "-slapd"
61 #define SLAPD_ANONYMOUS "cn=anonymous"
63 /* LDAPMod.mod_op value ===> Must be kept in sync with ldap.h!
65 * This is a value used internally by the backends. It is needed to allow
66 * adding values that already exist without getting an error as required by
67 * modrdn when the new rdn was already an attribute value itself.
68 * JCG 05/1999 (gomez@engr.sgi.com)
70 #define SLAP_MOD_SOFTADD 0x1000
72 #define MAXREMATCHES (10)
74 #define SLAP_MAX_WORKER_THREADS (32)
76 #define SLAP_TEXT_BUFLEN (256)
78 /* psuedo error code indicating abandoned operation */
79 #define SLAPD_ABANDON (-1)
81 /* psuedo error code indicating disconnect */
82 #define SLAPD_DISCONNECT (-2)
85 /* We assume "C" locale, that is US-ASCII */
86 #define ASCII_SPACE(c) ( (c) == ' ' )
87 #define ASCII_LOWER(c) ( (c) >= 'a' && (c) <= 'z' )
88 #define ASCII_UPPER(c) ( (c) >= 'A' && (c) <= 'Z' )
89 #define ASCII_ALPHA(c) ( ASCII_LOWER(c) || ASCII_UPPER(c) )
90 #define ASCII_DIGIT(c) ( (c) >= '0' && (c) <= '9' )
91 #define ASCII_ALNUM(c) ( ASCII_ALPHA(c) || ASCII_DIGIT(c) )
92 #define ASCII_PRINTABLE(c) ( (c) >= ' ' && (c) <= '~' )
94 #define SLAP_NIBBLE(c) ((c)&0x0f)
95 #define SLAP_ESCAPE_CHAR ('\\')
96 #define SLAP_ESCAPE_LO(c) ( "0123456789ABCDEF"[SLAP_NIBBLE(c)] )
97 #define SLAP_ESCAPE_HI(c) ( SLAP_ESCAPE_LO((c)>>4) )
99 #define FILTER_ESCAPE(c) ( (c) == '*' || (c) == '\\' \
100 || (c) == '(' || (c) == ')' || !ASCII_PRINTABLE(c) )
102 #define DN_ESCAPE(c) ((c) == SLAP_ESCAPE_CHAR)
103 #define DN_SEPARATOR(c) ((c) == ',' || (c) == ';')
104 #define RDN_ATTRTYPEANDVALUE_SEPARATOR(c) ((c) == '+') /* RFC 2253 */
105 #define RDN_SEPARATOR(c) (DN_SEPARATOR(c) || RDN_ATTRTYPEANDVALUE_SEPARATOR(c))
106 #define RDN_NEEDSESCAPE(c) ((c) == '\\' || (c) == '"')
108 #define DESC_LEADCHAR(c) ( ASCII_ALPHA(c) )
109 #define DESC_CHAR(c) ( ASCII_ALNUM(c) || (c) == '-' )
110 #define OID_LEADCHAR(c) ( ASCII_DIGIT(c) )
111 #define OID_SEPARATOR(c) ( (c) == '.' )
112 #define OID_CHAR(c) ( OID_LEADCHAR(c) || OID_SEPARATOR(c) )
114 #define ATTR_LEADCHAR(c) ( DESC_LEADCHAR(c) || OID_LEADCHAR(c) )
115 #define ATTR_CHAR(c) ( DESC_CHAR((c)) || (c) == '.' )
117 #define AD_LEADCHAR(c) ( ATTR_CHAR(c) )
118 #define AD_CHAR(c) ( ATTR_CHAR(c) || (c) == ';' )
120 #define SLAP_NUMERIC(c) ( ASCII_DIGIT(c) || ASCII_SPACE(c) )
122 #define SLAP_PRINTABLE(c) ( ASCII_ALNUM(c) || (c) == '\'' || \
123 (c) == '(' || (c) == ')' || (c) == '+' || (c) == ',' || \
124 (c) == '-' || (c) == '.' || (c) == '/' || (c) == ':' || \
125 (c) == '?' || (c) == ' ' || (c) == '=' )
126 #define SLAP_PRINTABLES(c) ( SLAP_PRINTABLE(c) || (c) == '$' )
128 /* must match in schema_init.c */
129 #define SLAPD_DN_SYNTAX "1.3.6.1.4.1.1466.115.121.1.12"
130 #define SLAPD_NAMEUID_SYNTAX "1.3.6.1.4.1.1466.115.121.1.34"
131 #define SLAPD_GROUP_ATTR "member"
132 #define SLAPD_GROUP_CLASS "groupOfNames"
133 #define SLAPD_ROLE_ATTR "roleOccupant"
134 #define SLAPD_ROLE_CLASS "organizationalRole"
136 #define SLAPD_ACI_SYNTAX "1.3.6.1.4.1.4203.666.2.1"
137 #define SLAPD_OCTETSTRING_SYNTAX "1.3.6.1.4.1.1466.115.121.1.40"
139 /* change this to "OpenLDAPset" */
140 #define SLAPD_ACI_SET_ATTR "template"
142 #define SLAPD_TOP_OID "2.5.6.0"
144 LDAP_SLAPD_V (int) slap_debug;
146 typedef unsigned long slap_mask_t;
148 /* Security Strength Factor */
149 typedef unsigned slap_ssf_t;
151 typedef struct slap_ssf_set {
153 slap_ssf_t sss_transport;
156 slap_ssf_t sss_update_ssf;
157 slap_ssf_t sss_update_transport;
158 slap_ssf_t sss_update_tls;
159 slap_ssf_t sss_update_sasl;
165 #define SLAP_INDEX_TYPE 0x00FFUL
166 #define SLAP_INDEX_UNDEFINED 0x0001UL
167 #define SLAP_INDEX_PRESENT 0x0002UL
168 #define SLAP_INDEX_EQUALITY 0x0004UL
169 #define SLAP_INDEX_APPROX 0x0008UL
170 #define SLAP_INDEX_SUBSTR 0x0010UL
171 #define SLAP_INDEX_EXTENDED 0x0020UL
173 #define SLAP_INDEX_DEFAULT SLAP_INDEX_EQUALITY
175 #define IS_SLAP_INDEX(mask, type) (((mask) & (type)) == (type) )
177 #define SLAP_INDEX_SUBSTR_TYPE 0x0F00UL
179 #define SLAP_INDEX_SUBSTR_INITIAL ( SLAP_INDEX_SUBSTR | 0x0100UL )
180 #define SLAP_INDEX_SUBSTR_ANY ( SLAP_INDEX_SUBSTR | 0x0200UL )
181 #define SLAP_INDEX_SUBSTR_FINAL ( SLAP_INDEX_SUBSTR | 0x0400UL )
182 #define SLAP_INDEX_SUBSTR_DEFAULT \
183 ( SLAP_INDEX_SUBSTR \
184 | SLAP_INDEX_SUBSTR_INITIAL \
185 | SLAP_INDEX_SUBSTR_ANY \
186 | SLAP_INDEX_SUBSTR_FINAL )
188 #define SLAP_INDEX_SUBSTR_MINLEN 2
189 #define SLAP_INDEX_SUBSTR_MAXLEN 4
190 #define SLAP_INDEX_SUBSTR_STEP 2
192 #define SLAP_INDEX_FLAGS 0xF000UL
193 #define SLAP_INDEX_NOSUBTYPES 0x1000UL /* don't use index w/ subtypes */
194 #define SLAP_INDEX_NOLANG 0x2000UL /* don't use index w/ lang */
197 * there is a single index for each attribute. these prefixes ensure
198 * that there is no collision among keys.
200 #define SLAP_INDEX_EQUALITY_PREFIX '=' /* prefix for equality keys */
201 #define SLAP_INDEX_APPROX_PREFIX '~' /* prefix for approx keys */
202 #define SLAP_INDEX_SUBSTR_PREFIX '*' /* prefix for substring keys */
203 #define SLAP_INDEX_SUBSTR_INITIAL_PREFIX '^'
204 #define SLAP_INDEX_SUBSTR_FINAL_PREFIX '$'
205 #define SLAP_INDEX_CONT_PREFIX '.' /* prefix for continuation keys */
206 #define SLAP_INDEX_UNKNOWN_PREFIX '?' /* prefix for unknown keys */
208 #define SLAP_SYNTAX_MATCHINGRULES_OID "1.3.6.1.4.1.1466.115.121.1.30"
209 #define SLAP_SYNTAX_ATTRIBUTETYPES_OID "1.3.6.1.4.1.1466.115.121.1.3"
210 #define SLAP_SYNTAX_OBJECTCLASSES_OID "1.3.6.1.4.1.1466.115.121.1.37"
213 * represents schema information for a database
215 #define SLAP_SCHERR_OUTOFMEM 1
216 #define SLAP_SCHERR_CLASS_NOT_FOUND 2
217 #define SLAP_SCHERR_CLASS_BAD_USAGE 3
218 #define SLAP_SCHERR_ATTR_NOT_FOUND 4
219 #define SLAP_SCHERR_ATTR_BAD_USAGE 5
220 #define SLAP_SCHERR_DUP_CLASS 6
221 #define SLAP_SCHERR_DUP_ATTR 7
222 #define SLAP_SCHERR_DUP_SYNTAX 8
223 #define SLAP_SCHERR_DUP_RULE 9
224 #define SLAP_SCHERR_NO_NAME 10
225 #define SLAP_SCHERR_ATTR_INCOMPLETE 11
226 #define SLAP_SCHERR_MR_NOT_FOUND 12
227 #define SLAP_SCHERR_SYN_NOT_FOUND 13
228 #define SLAP_SCHERR_MR_INCOMPLETE 14
229 #define SLAP_SCHERR_NOT_SUPPORTED 15
230 #define SLAP_SCHERR_BAD_DESCR 16
231 #define SLAP_SCHERR_OIDM 17
232 #define SLAP_SCHERR_LAST SLAP_SCHERR_OIDM
234 typedef union slap_sockaddr {
235 struct sockaddr sa_addr;
236 struct sockaddr_in sa_in_addr;
238 struct sockaddr_in6 sa_in6_addr;
241 struct sockaddr_un sa_un_addr;
245 typedef struct slap_oid_macro {
246 struct berval som_oid;
248 struct slap_oid_macro *som_next;
251 /* forward declarations */
253 struct slap_matching_rule;
255 typedef int slap_syntax_validate_func LDAP_P((
256 struct slap_syntax *syntax,
257 struct berval * in));
259 typedef int slap_syntax_transform_func LDAP_P((
260 struct slap_syntax *syntax,
262 struct berval * out));
264 typedef struct slap_syntax {
266 #define ssyn_oid ssyn_syn.syn_oid
267 #define ssyn_desc ssyn_syn.syn_desc
268 #define ssyn_extensions ssyn_syn.syn_extensions
269 ber_len_t ssyn_oidlen;
271 unsigned int ssyn_flags;
273 #define SLAP_SYNTAX_NONE 0x0000U
274 #define SLAP_SYNTAX_BLOB 0x0001U /* syntax treated as blob (audio) */
275 #define SLAP_SYNTAX_BINARY 0x0002U /* binary transfer required (certificate) */
276 #define SLAP_SYNTAX_BER 0x0004U /* stored in BER encoding (certificate) */
277 #define SLAP_SYNTAX_HIDE 0x8000U /* hide (do not publish) */
279 slap_syntax_validate_func *ssyn_validate;
280 slap_syntax_transform_func *ssyn_normalize;
281 slap_syntax_transform_func *ssyn_pretty;
283 #ifdef SLAPD_BINARY_CONVERSION
284 /* convert to and from binary */
285 slap_syntax_transform_func *ssyn_ber2str;
286 slap_syntax_transform_func *ssyn_str2ber;
289 struct slap_syntax *ssyn_next;
292 #define slap_syntax_is_flag(s,flag) ((int)((s)->ssyn_flags & (flag)) ? 1 : 0)
293 #define slap_syntax_is_blob(s) slap_syntax_is_flag((s),SLAP_SYNTAX_BLOB)
294 #define slap_syntax_is_binary(s) slap_syntax_is_flag((s),SLAP_SYNTAX_BINARY)
295 #define slap_syntax_is_ber(s) slap_syntax_is_flag((s),SLAP_SYNTAX_BER)
296 #define slap_syntax_is_hidden(s) slap_syntax_is_flag((s),SLAP_SYNTAX_HIDE)
298 /* X -> Y Converter */
299 typedef int slap_mr_convert_func LDAP_P((
301 struct berval * out ));
304 typedef int slap_mr_normalize_func LDAP_P((
306 struct slap_syntax *syntax, /* NULL if in is asserted value */
307 struct slap_matching_rule *mr,
309 struct berval * out ));
311 /* Match (compare) function */
312 typedef int slap_mr_match_func LDAP_P((
315 struct slap_syntax *syntax, /* syntax of stored value */
316 struct slap_matching_rule *mr,
317 struct berval * value,
318 void * assertValue ));
320 /* Index generation function */
321 typedef int slap_mr_indexer_func LDAP_P((
324 struct slap_syntax *syntax, /* syntax of stored value */
325 struct slap_matching_rule *mr,
326 struct berval *prefix,
330 /* Filter index function */
331 typedef int slap_mr_filter_func LDAP_P((
334 struct slap_syntax *syntax, /* syntax of stored value */
335 struct slap_matching_rule *mr,
336 struct berval *prefix,
340 typedef struct slap_matching_rule {
341 LDAPMatchingRule smr_mrule;
342 ber_len_t smr_oidlen;
343 slap_mask_t smr_usage;
345 #define SLAP_MR_HIDE 0x8000U
347 #define SLAP_MR_TYPE_MASK 0x0F00U
348 #define SLAP_MR_SUBTYPE_MASK 0x00F0U
349 #define SLAP_MR_USAGE 0x000FU
351 #define SLAP_MR_NONE 0x0000U
352 #define SLAP_MR_EQUALITY 0x0100U
353 #define SLAP_MR_ORDERING 0x0200U
354 #define SLAP_MR_SUBSTR 0x0400U
355 #define SLAP_MR_EXT 0x0800U
357 #define SLAP_MR_EQUALITY_APPROX ( SLAP_MR_EQUALITY | 0x0010U )
358 #define SLAP_MR_DN_FOLD 0x0008U
360 #define SLAP_MR_SUBSTR_INITIAL ( SLAP_MR_SUBSTR | 0x0010U )
361 #define SLAP_MR_SUBSTR_ANY ( SLAP_MR_SUBSTR | 0x0020U )
362 #define SLAP_MR_SUBSTR_FINAL ( SLAP_MR_SUBSTR | 0x0040U )
365 * normally the provided value is expected to conform to
366 * assertion syntax specified in the matching rule, however
367 * at times (such as during individual value modification),
368 * the provided value is expected to conform to the
369 * attribute's value syntax.
371 #define SLAP_MR_ASSERTION_SYNTAX_MATCH 0x0000U
372 #define SLAP_MR_VALUE_SYNTAX_MATCH 0x0001U
373 #define SLAP_MR_VALUE_SYNTAX_CONVERTED_MATCH 0x0003U
375 #define SLAP_IS_MR_ASSERTION_SYNTAX_MATCH( usage ) \
376 (!((usage) & SLAP_MR_VALUE_SYNTAX_MATCH))
377 #define SLAP_IS_MR_VALUE_SYNTAX_MATCH( usage ) \
378 ((usage) & SLAP_MR_VALUE_SYNTAX_MATCH)
380 #define SLAP_IS_MR_VALUE_SYNTAX_CONVERTED_MATCH( usage ) \
381 (((usage) & SLAP_MR_VALUE_SYNTAX_CONVERTED_MATCH) \
382 == SLAP_MR_VALUE_SYNTAX_CONVERTED_MATCH)
383 #define SLAP_IS_MR_VALUE_SYNTAX_NONCONVERTED_MATCH( usage ) \
384 (((usage) & SLAP_MR_VALUE_SYNTAX_CONVERTED_MATCH) \
385 == SLAP_MR_VALUE_SYNTAX_MATCH)
388 slap_mr_convert_func *smr_convert;
389 slap_mr_normalize_func *smr_normalize;
390 slap_mr_match_func *smr_match;
391 slap_mr_indexer_func *smr_indexer;
392 slap_mr_filter_func *smr_filter;
394 struct slap_matching_rule *smr_associated;
395 struct slap_matching_rule *smr_next;
397 #define smr_oid smr_mrule.mr_oid
398 #define smr_names smr_mrule.mr_names
399 #define smr_desc smr_mrule.mr_desc
400 #define smr_obsolete smr_mrule.mr_obsolete
401 #define smr_syntax_oid smr_mrule.mr_syntax_oid
402 #define smr_extensions smr_mrule.mr_extensions
405 struct slap_backend_db;
409 typedef int (AttributeTypeSchemaCheckFN)(
410 struct slap_backend_db *be,
411 struct slap_entry *e,
412 struct slap_attr *attr,
414 char *textbuf, size_t textlen );
416 typedef struct slap_attribute_type {
417 LDAPAttributeType sat_atype;
418 struct berval sat_cname;
419 struct slap_attribute_type *sat_sup;
420 struct slap_attribute_type **sat_subtypes;
421 MatchingRule *sat_equality;
422 MatchingRule *sat_approx;
423 MatchingRule *sat_ordering;
424 MatchingRule *sat_substr;
427 AttributeTypeSchemaCheckFN *sat_check;
428 slap_mask_t sat_flags;
430 struct slap_attribute_type *sat_next;
432 #define sat_oid sat_atype.at_oid
433 #define sat_names sat_atype.at_names
434 #define sat_desc sat_atype.at_desc
435 #define sat_obsolete sat_atype.at_obsolete
436 #define sat_sup_oid sat_atype.at_sup_oid
437 #define sat_equality_oid sat_atype.at_equality_oid
438 #define sat_ordering_oid sat_atype.at_ordering_oid
439 #define sat_substr_oid sat_atype.at_substr_oid
440 #define sat_syntax_oid sat_atype.at_syntax_oid
441 #define sat_single_value sat_atype.at_single_value
442 #define sat_collective sat_atype.at_collective
443 #define sat_no_user_mod sat_atype.at_no_user_mod
444 #define sat_usage sat_atype.at_usage
445 #define sat_extensions sat_atype.at_extensions
447 struct slap_attr_desc *sat_ad;
448 ldap_pvt_thread_mutex_t sat_ad_mutex;
451 #define is_at_operational(at) ((at)->sat_usage)
452 #define is_at_single_value(at) ((at)->sat_single_value)
453 #define is_at_collective(at) ((at)->sat_collective)
454 #define is_at_obsolete(at) ((at)->sat_obsolete)
455 #define is_at_no_user_mod(at) ((at)->sat_no_user_mod)
457 struct slap_object_class;
459 typedef int (ObjectClassSchemaCheckFN)(
460 struct slap_backend_db *be,
461 struct slap_entry *e,
462 struct slap_object_class *oc,
464 char *textbuf, size_t textlen );
466 typedef struct slap_object_class {
467 LDAPObjectClass soc_oclass;
468 struct slap_object_class **soc_sups;
469 AttributeType **soc_required;
470 AttributeType **soc_allowed;
471 ObjectClassSchemaCheckFN *sco_check;
472 slap_mask_t sco_flags;
473 #define soc_oid soc_oclass.oc_oid
474 #define soc_names soc_oclass.oc_names
475 #define soc_desc soc_oclass.oc_desc
476 #define soc_obsolete soc_oclass.oc_obsolete
477 #define soc_sup_oids soc_oclass.oc_sup_oids
478 #define soc_kind soc_oclass.oc_kind
479 #define soc_at_oids_must soc_oclass.oc_at_oids_must
480 #define soc_at_oids_may soc_oclass.oc_at_oids_may
481 #define soc_extensions soc_oclass.oc_extensions
483 struct slap_object_class *soc_next;
486 #ifdef LDAP_EXTENDED_SCHEMA
490 typedef struct slap_content_rule {
491 LDAPContentRule scr_crule;
492 ObjectClass *scr_sclass;
493 ObjectClass **scr_auxiliaries; /* optional */
494 AttributeType **scr_required; /* optional */
495 AttributeType **scr_allowed; /* optional */
496 AttributeType **scr_precluded; /* optional */
497 #define scr_oid scr_crule.cr_oid
498 #define scr_names scr_crule.cr_names
499 #define scr_desc scr_crule.cr_desc
500 #define scr_obsolete soc_oclass.cr_obsolete
501 #define scr_cr_oids_aux soc_oclass.cr_oc_oids_aux
502 #define scr_cr_oids_must soc_oclass.cr_at_oids_must
503 #define scr_cr_oids_may soc_oclass.cr_at_oids_may
504 #define scr_cr_oids_not soc_oclass.cr_at_oids_not
509 * represents a recognized attribute description ( type + options )
511 typedef struct slap_attr_desc {
512 struct slap_attr_desc *ad_next;
513 AttributeType *ad_type; /* attribute type, must be specified */
514 struct berval ad_cname; /* canonical name, must be specified */
515 struct berval ad_lang; /* empty if no language tags */
517 #define SLAP_DESC_NONE 0x0U
518 #define SLAP_DESC_BINARY 0x1U
519 } AttributeDescription;
521 typedef struct slap_attr_name {
522 struct berval an_name;
523 AttributeDescription *an_desc;
527 #define slap_ad_is_lang(ad) ( (ad)->ad_lang.bv_len != 0 )
528 #define slap_ad_is_binary(ad) ( (int)((ad)->ad_flags & SLAP_DESC_BINARY) ? 1 : 0 )
531 * pointers to schema elements used internally
533 struct slap_internal_schema {
535 ObjectClass *si_oc_top;
536 ObjectClass *si_oc_extensibleObject;
537 ObjectClass *si_oc_alias;
538 ObjectClass *si_oc_referral;
539 ObjectClass *si_oc_rootdse;
540 ObjectClass *si_oc_subentry;
541 ObjectClass *si_oc_subschema;
542 ObjectClass *si_oc_monitor;
543 ObjectClass *si_oc_collectiveAttributes;
544 ObjectClass *si_oc_dynamicObject;
546 /* objectClass attribute descriptions */
547 AttributeDescription *si_ad_objectClass;
549 /* operational attribute descriptions */
550 AttributeDescription *si_ad_structuralObjectClass;
551 AttributeDescription *si_ad_creatorsName;
552 AttributeDescription *si_ad_createTimestamp;
553 AttributeDescription *si_ad_modifiersName;
554 AttributeDescription *si_ad_modifyTimestamp;
555 AttributeDescription *si_ad_hasSubordinates;
556 AttributeDescription *si_ad_subschemaSubentry;
557 AttributeDescription *si_ad_collectiveSubentry;
558 AttributeDescription *si_ad_collectiveExclusions;
559 AttributeDescription *si_ad_entryUUID;
560 AttributeDescription *si_ad_entryCSN;
562 /* root DSE attribute descriptions */
563 AttributeDescription *si_ad_altServer;
564 AttributeDescription *si_ad_namingContexts;
565 AttributeDescription *si_ad_supportedControl;
566 AttributeDescription *si_ad_supportedExtension;
567 AttributeDescription *si_ad_supportedLDAPVersion;
568 AttributeDescription *si_ad_supportedSASLMechanisms;
569 AttributeDescription *si_ad_supportedFeatures;
570 AttributeDescription *si_ad_vendorName;
571 AttributeDescription *si_ad_vendorVersion;
573 /* subentry attribute descriptions */
574 AttributeDescription *si_ad_administrativeRole;
575 AttributeDescription *si_ad_subtreeSpecification;
577 /* subschema subentry attribute descriptions */
578 AttributeDescription *si_ad_ditStructureRules;
579 AttributeDescription *si_ad_ditContentRules;
580 AttributeDescription *si_ad_nameForms;
581 AttributeDescription *si_ad_objectClasses;
582 AttributeDescription *si_ad_attributeTypes;
583 AttributeDescription *si_ad_ldapSyntaxes;
584 AttributeDescription *si_ad_matchingRules;
585 AttributeDescription *si_ad_matchingRuleUse;
587 /* Aliases & Referrals */
588 AttributeDescription *si_ad_aliasedObjectName;
589 AttributeDescription *si_ad_ref;
591 /* Access Control Internals */
592 AttributeDescription *si_ad_entry;
593 AttributeDescription *si_ad_children;
594 #ifdef SLAPD_ACI_ENABLED
595 AttributeDescription *si_ad_aci;
598 /* dynamic entries */
599 AttributeDescription *si_ad_entryTtl;
600 AttributeDescription *si_ad_dynamicSubtrees;
602 /* Other attributes descriptions */
603 AttributeDescription *si_ad_distinguishedName;
604 AttributeDescription *si_ad_name;
605 AttributeDescription *si_ad_cn;
606 AttributeDescription *si_ad_userPassword;
607 #ifdef SLAPD_AUTHPASSWD
608 AttributeDescription *si_ad_authPassword;
610 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
611 AttributeDescription *si_ad_krbName;
614 /* Undefined Attribute Type */
615 AttributeType *si_at_undefined;
618 MatchingRule *si_mr_distinguishedNameMatch;
619 MatchingRule *si_mr_integerMatch;
622 Syntax *si_syn_distinguishedName;
623 Syntax *si_syn_integer;
626 typedef struct slap_attr_assertion {
627 AttributeDescription *aa_desc;
628 struct berval aa_value;
629 } AttributeAssertion;
631 typedef struct slap_ss_assertion {
632 AttributeDescription *sa_desc;
633 struct berval sa_initial;
634 struct berval *sa_any;
635 struct berval sa_final;
636 } SubstringsAssertion;
638 typedef struct slap_mr_assertion {
639 MatchingRule *ma_rule; /* optional */
640 struct berval ma_rule_text; /* optional */
641 AttributeDescription *ma_desc; /* optional */
642 int ma_dnattrs; /* boolean */
643 struct berval ma_value; /* required */
644 } MatchingRuleAssertion;
647 * represents a search filter
649 typedef struct slap_filter {
650 ber_tag_t f_choice; /* values taken from ldap.h, plus: */
651 #define SLAPD_FILTER_COMPUTED ((ber_tag_t) -1)
652 #define SLAPD_FILTER_DN_ONE ((ber_tag_t) -2)
653 #define SLAPD_FILTER_DN_SUBTREE ((ber_tag_t) -3)
656 /* precomputed result */
657 ber_int_t f_un_result;
660 struct berval *f_un_dn;
663 AttributeDescription *f_un_desc;
665 /* simple value assertion */
666 AttributeAssertion *f_un_ava;
668 /* substring assertion */
669 SubstringsAssertion *f_un_ssa;
671 /* matching rule assertion */
672 MatchingRuleAssertion *f_un_mra;
674 #define f_dn f_un.f_un_dn
675 #define f_desc f_un.f_un_desc
676 #define f_ava f_un.f_un_ava
677 #define f_av_desc f_un.f_un_ava->aa_desc
678 #define f_av_value f_un.f_un_ava->aa_value
679 #define f_sub f_un.f_un_ssa
680 #define f_sub_desc f_un.f_un_ssa->sa_desc
681 #define f_sub_initial f_un.f_un_ssa->sa_initial
682 #define f_sub_any f_un.f_un_ssa->sa_any
683 #define f_sub_final f_un.f_un_ssa->sa_final
684 #define f_mra f_un.f_un_mra
685 #define f_mr_rule f_un.f_un_mra->ma_rule
686 #define f_mr_rule_text f_un.f_un_mra->ma_rule_text
687 #define f_mr_desc f_un.f_un_mra->ma_desc
688 #define f_mr_value f_un.f_un_mra->ma_value
689 #define f_mr_dnattrs f_un.f_un_mra->ma_dnattrs
692 struct slap_filter *f_un_complex;
695 #define f_result f_un.f_un_result
696 #define f_and f_un.f_un_complex
697 #define f_or f_un.f_un_complex
698 #define f_not f_un.f_un_complex
699 #define f_list f_un.f_un_complex
701 struct slap_filter *f_next;
704 /* compare routines can return undefined */
705 #define SLAPD_COMPARE_UNDEFINED ((ber_int_t) -1)
708 * represents an attribute (description + values)
710 typedef struct slap_attr {
711 AttributeDescription *a_desc;
713 struct slap_attr *a_next;
715 #define SLAP_ATTR_IXADD 0x1U
716 #define SLAP_ATTR_IXDEL 0x2U
721 * the id used in the indexes to refer to an entry
723 typedef unsigned long ID;
724 #define NOID ((ID)~0)
727 * represents an entry in core
729 typedef struct slap_entry {
731 * The ID field should only be changed before entry is
732 * inserted into a cache. The ID value is backend
737 struct berval e_name; /* name (DN) of this entry */
738 struct berval e_nname; /* normalized name (DN) of this entry */
740 /* for migration purposes */
741 #define e_dn e_name.bv_val
742 #define e_ndn e_nname.bv_val
744 Attribute *e_attrs; /* list of attributes + values */
746 /* for use by the backend for any purpose */
753 typedef struct slap_mod {
755 AttributeDescription *sm_desc;
756 struct berval sm_type;
757 BerVarray sm_bvalues;
760 typedef struct slap_mod_list {
761 Modification sml_mod;
762 #define sml_op sml_mod.sm_op
763 #define sml_desc sml_mod.sm_desc
764 #define sml_type sml_mod.sm_type
765 #define sml_bvalues sml_mod.sm_bvalues
766 struct slap_mod_list *sml_next;
769 typedef struct slap_ldap_modlist {
771 struct slap_ldap_modlist *ml_next;
772 #define ml_op ml_mod.mod_op
773 #define ml_type ml_mod.mod_type
774 #define ml_values ml_mod.mod_values
775 #define ml_bvalues ml_mod.mod_bvalues
779 * represents an access control list
781 typedef enum slap_access_e {
782 ACL_INVALID_ACCESS = -1,
791 typedef enum slap_control_e {
792 ACL_INVALID_CONTROL = 0,
798 typedef enum slap_style_e {
806 /* alternate names */
807 ACL_STYLE_EXACT = ACL_STYLE_BASE
810 typedef struct slap_authz_info {
811 ber_tag_t sai_method; /* LDAP_AUTH_* from <ldap.h> */
812 char * sai_mech; /* SASL Mechanism */
813 struct berval sai_dn; /* DN for reporting purposes */
814 struct berval sai_ndn; /* Normalized DN */
816 /* Security Strength Factors */
817 slap_ssf_t sai_ssf; /* Overall SSF */
818 slap_ssf_t sai_transport_ssf; /* Transport SSF */
819 slap_ssf_t sai_tls_ssf; /* TLS SSF */
820 slap_ssf_t sai_sasl_ssf; /* SASL SSF */
821 } AuthorizationInformation;
824 typedef struct slap_access {
825 slap_control_t a_type;
827 #define ACL_ACCESS2PRIV(access) (0x01U << (access))
829 #define ACL_PRIV_NONE ACL_ACCESS2PRIV( ACL_NONE )
830 #define ACL_PRIV_AUTH ACL_ACCESS2PRIV( ACL_AUTH )
831 #define ACL_PRIV_COMPARE ACL_ACCESS2PRIV( ACL_COMPARE )
832 #define ACL_PRIV_SEARCH ACL_ACCESS2PRIV( ACL_SEARCH )
833 #define ACL_PRIV_READ ACL_ACCESS2PRIV( ACL_READ )
834 #define ACL_PRIV_WRITE ACL_ACCESS2PRIV( ACL_WRITE )
836 #define ACL_PRIV_MASK 0x00ffUL
839 #define ACL_PRIV_LEVEL 0x1000UL
840 #define ACL_PRIV_ADDITIVE 0x2000UL
841 #define ACL_PRIV_SUBSTRACTIVE 0x4000UL
844 #define ACL_PRIV_INVALID 0x0UL
846 #define ACL_PRIV_ISSET(m,p) (((m) & (p)) == (p))
847 #define ACL_PRIV_ASSIGN(m,p) do { (m) = (p); } while(0)
848 #define ACL_PRIV_SET(m,p) do { (m) |= (p); } while(0)
849 #define ACL_PRIV_CLR(m,p) do { (m) &= ~(p); } while(0)
851 #define ACL_INIT(m) ACL_PRIV_ASSIGN(m, ACL_PRIV_NONE)
852 #define ACL_INVALIDATE(m) ACL_PRIV_ASSIGN(m, ACL_PRIV_INVALID)
854 #define ACL_GRANT(m,a) ACL_PRIV_ISSET((m),ACL_ACCESS2PRIV(a))
856 #define ACL_IS_INVALID(m) ((m) == ACL_PRIV_INVALID)
858 #define ACL_IS_LEVEL(m) ACL_PRIV_ISSET((m),ACL_PRIV_LEVEL)
859 #define ACL_IS_ADDITIVE(m) ACL_PRIV_ISSET((m),ACL_PRIV_ADDITIVE)
860 #define ACL_IS_SUBTRACTIVE(m) ACL_PRIV_ISSET((m),ACL_PRIV_SUBSTRACTIVE)
862 #define ACL_LVL_NONE (ACL_PRIV_NONE|ACL_PRIV_LEVEL)
863 #define ACL_LVL_AUTH (ACL_PRIV_AUTH|ACL_LVL_NONE)
864 #define ACL_LVL_COMPARE (ACL_PRIV_COMPARE|ACL_LVL_AUTH)
865 #define ACL_LVL_SEARCH (ACL_PRIV_SEARCH|ACL_LVL_COMPARE)
866 #define ACL_LVL_READ (ACL_PRIV_READ|ACL_LVL_SEARCH)
867 #define ACL_LVL_WRITE (ACL_PRIV_WRITE|ACL_LVL_READ)
869 #define ACL_LVL(m,l) (((m)&ACL_PRIV_MASK) == ((l)&ACL_PRIV_MASK))
870 #define ACL_LVL_IS_NONE(m) ACL_LVL((m),ACL_LVL_NONE)
871 #define ACL_LVL_IS_AUTH(m) ACL_LVL((m),ACL_LVL_AUTH)
872 #define ACL_LVL_IS_COMPARE(m) ACL_LVL((m),ACL_LVL_COMPARE)
873 #define ACL_LVL_IS_SEARCH(m) ACL_LVL((m),ACL_LVL_SEARCH)
874 #define ACL_LVL_IS_READ(m) ACL_LVL((m),ACL_LVL_READ)
875 #define ACL_LVL_IS_WRITE(m) ACL_LVL((m),ACL_LVL_WRITE)
877 #define ACL_LVL_ASSIGN_NONE(m) ACL_PRIV_ASSIGN((m),ACL_LVL_NONE)
878 #define ACL_LVL_ASSIGN_AUTH(m) ACL_PRIV_ASSIGN((m),ACL_LVL_AUTH)
879 #define ACL_LVL_ASSIGN_COMPARE(m) ACL_PRIV_ASSIGN((m),ACL_LVL_COMPARE)
880 #define ACL_LVL_ASSIGN_SEARCH(m) ACL_PRIV_ASSIGN((m),ACL_LVL_SEARCH)
881 #define ACL_LVL_ASSIGN_READ(m) ACL_PRIV_ASSIGN((m),ACL_LVL_READ)
882 #define ACL_LVL_ASSIGN_WRITE(m) ACL_PRIV_ASSIGN((m),ACL_LVL_WRITE)
884 slap_mask_t a_access_mask;
886 AuthorizationInformation a_authz;
887 #define a_dn_pat a_authz.sai_dn
889 slap_style_t a_dn_style;
890 AttributeDescription *a_dn_at;
893 slap_style_t a_peername_style;
894 char *a_peername_pat;
895 slap_style_t a_sockname_style;
896 char *a_sockname_pat;
898 slap_style_t a_domain_style;
900 slap_style_t a_sockurl_style;
902 slap_style_t a_set_style;
903 struct berval a_set_pat;
905 #ifdef SLAPD_ACI_ENABLED
906 AttributeDescription *a_aci_at;
910 slap_style_t a_group_style;
911 struct berval a_group_pat;
912 ObjectClass *a_group_oc;
913 AttributeDescription *a_group_at;
915 struct slap_access *a_next;
919 typedef struct slap_acl {
920 /* "to" part: the entries this acl applies to */
922 slap_style_t acl_dn_style;
924 struct berval acl_dn_pat;
925 AttributeName *acl_attrs;
927 /* "by" part: list of who has what access to the entries */
930 struct slap_acl *acl_next;
934 * replog moddn param structure
936 struct slap_replog_moddn {
937 struct berval *newrdn;
939 struct berval *newsup;
944 * represents a backend
947 typedef struct slap_backend_info BackendInfo; /* per backend type */
948 typedef struct slap_backend_db BackendDB; /* per backend database */
950 LDAP_SLAPD_V (int) nBackendInfo;
951 LDAP_SLAPD_V (int) nBackendDB;
952 LDAP_SLAPD_V (BackendInfo *) backendInfo;
953 LDAP_SLAPD_V (BackendDB *) backendDB;
955 LDAP_SLAPD_V (int) slapMode;
956 #define SLAP_UNDEFINED_MODE 0x0000
957 #define SLAP_SERVER_MODE 0x0001
958 #define SLAP_TOOL_MODE 0x0002
959 #define SLAP_MODE 0x0003
961 #define SLAP_TRUNCATE_MODE 0x0100
963 struct slap_replica_info {
964 char *ri_host; /* supersedes be_replica */
965 struct berval **ri_nsuffix; /* array of suffixes this replica accepts */
968 struct slap_limits_set {
980 int lm_type; /* type of pattern */
981 #define SLAP_LIMITS_UNDEFINED 0x0000
982 #define SLAP_LIMITS_EXACT 0x0001
983 #define SLAP_LIMITS_BASE SLAP_LIMITS_EXACT
984 #define SLAP_LIMITS_ONE 0x0002
985 #define SLAP_LIMITS_SUBTREE 0x0003
986 #define SLAP_LIMITS_CHILDREN 0x0004
987 #define SLAP_LIMITS_REGEX 0x0005
988 #define SLAP_LIMITS_ANONYMOUS 0x0006
989 #define SLAP_LIMITS_USERS 0x0007
990 regex_t lm_dn_regex; /* regex data for REGEX */
993 * normalized DN for EXACT, BASE, ONE, SUBTREE, CHILDREN;
994 * pattern for REGEX; NULL for ANONYMOUS, USERS
996 struct berval lm_dn_pat;
998 struct slap_limits_set lm_limits;
1001 /* temporary aliases */
1002 typedef BackendDB Backend;
1003 #define nbackends nBackendDB
1004 #define backends backendDB
1006 struct slap_backend_db {
1007 BackendInfo *bd_info; /* pointer to shared backend info */
1009 /* BackendInfo accessors */
1010 #define be_config bd_info->bi_db_config
1011 #define be_type bd_info->bi_type
1013 #define be_bind bd_info->bi_op_bind
1014 #define be_unbind bd_info->bi_op_unbind
1015 #define be_add bd_info->bi_op_add
1016 #define be_compare bd_info->bi_op_compare
1017 #define be_delete bd_info->bi_op_delete
1018 #define be_modify bd_info->bi_op_modify
1019 #define be_modrdn bd_info->bi_op_modrdn
1020 #define be_search bd_info->bi_op_search
1022 #define be_extended bd_info->bi_extended
1024 #define be_release bd_info->bi_entry_release_rw
1025 #define be_chk_referrals bd_info->bi_chk_referrals
1026 #define be_group bd_info->bi_acl_group
1027 #define be_attribute bd_info->bi_acl_attribute
1028 #define be_operational bd_info->bi_operational
1030 #define be_controls bd_info->bi_controls
1032 #define be_connection_init bd_info->bi_connection_init
1033 #define be_connection_destroy bd_info->bi_connection_destroy
1036 #define be_entry_open bd_info->bi_tool_entry_open
1037 #define be_entry_close bd_info->bi_tool_entry_close
1038 #define be_entry_first bd_info->bi_tool_entry_first
1039 #define be_entry_next bd_info->bi_tool_entry_next
1040 #define be_entry_reindex bd_info->bi_tool_entry_reindex
1041 #define be_entry_get bd_info->bi_tool_entry_get
1042 #define be_entry_put bd_info->bi_tool_entry_put
1043 #define be_sync bd_info->bi_tool_sync
1046 #define SLAP_BFLAG_NOLASTMOD 0x0001U
1047 #define SLAP_BFLAG_GLUE_INSTANCE 0x0010U /* a glue backend */
1048 #define SLAP_BFLAG_GLUE_SUBORDINATE 0x0020U /* child of a glue hierarchy */
1049 #define SLAP_BFLAG_GLUE_LINKED 0x0040U /* child is connected to parent */
1050 #define SLAP_BFLAG_ALIASES 0x0100U
1051 #define SLAP_BFLAG_REFERRALS 0x0200U
1052 #define SLAP_BFLAG_SUBENTRIES 0x0400U
1053 #define SLAP_BFLAG_MONITOR 0x1000U
1054 #define SLAP_BFLAG_DYNAMIC 0x2000U
1055 slap_mask_t be_flags;
1056 #define SLAP_LASTMOD(be) (!((be)->be_flags & SLAP_BFLAG_NOLASTMOD))
1057 #define SLAP_ALIASES(be) ((be)->be_flags & SLAP_BFLAG_ALIASES)
1058 #define SLAP_REFERRALS(be) ((be)->be_flags & SLAP_BFLAG_REFERRALS)
1059 #define SLAP_SUBENTRIES(be) ((be)->be_flags & SLAP_BFLAG_SUBENTRIES)
1060 #define SLAP_MONITOR(be) ((be)->be_flags & SLAP_BFLAG_MONITOR)
1061 #define SLAP_DYNAMIC(be) ((be)->be_flags & SLAP_BFLAG_DYNAMIC)
1063 slap_mask_t be_restrictops; /* restriction operations */
1064 #define SLAP_RESTRICT_OP_ADD 0x0001U
1065 #define SLAP_RESTRICT_OP_BIND 0x0002U
1066 #define SLAP_RESTRICT_OP_COMPARE 0x0004U
1067 #define SLAP_RESTRICT_OP_DELETE 0x0008U
1068 #define SLAP_RESTRICT_OP_EXTENDED 0x0010U
1069 #define SLAP_RESTRICT_OP_MODIFY 0x0020U
1070 #define SLAP_RESTRICT_OP_RENAME 0x0040U
1071 #define SLAP_RESTRICT_OP_SEARCH 0x0080U
1073 #define SLAP_RESTRICT_OP_READS \
1074 ( SLAP_RESTRICT_OP_COMPARE \
1075 | SLAP_RESTRICT_OP_SEARCH )
1076 #define SLAP_RESTRICT_OP_WRITES \
1077 ( SLAP_RESTRICT_OP_ADD \
1078 | SLAP_RESTRICT_OP_DELETE \
1079 | SLAP_RESTRICT_OP_MODIFY \
1080 | SLAP_RESTRICT_OP_RENAME )
1082 #define SLAP_ALLOW_BIND_V2 0x0001U /* LDAPv2 bind */
1083 #define SLAP_ALLOW_BIND_ANON_CRED 0x0002U /* cred should be empty */
1084 #define SLAP_ALLOW_BIND_ANON_DN 0x0003U /* dn should be empty */
1086 #define SLAP_DISALLOW_BIND_ANON 0x0001U /* no anonymous */
1087 #define SLAP_DISALLOW_BIND_SIMPLE 0x0002U /* simple authentication */
1088 #define SLAP_DISALLOW_BIND_KRBV4 0x0004U /* Kerberos V4 authentication */
1090 #define SLAP_DISALLOW_TLS_2_ANON 0x0010U /* StartTLS -> Anonymous */
1091 #define SLAP_DISALLOW_TLS_AUTHC 0x0020U /* TLS while authenticated */
1093 slap_mask_t be_requires; /* pre-operation requirements */
1094 #define SLAP_REQUIRE_BIND 0x0001U /* bind before op */
1095 #define SLAP_REQUIRE_LDAP_V3 0x0002U /* LDAPv3 before op */
1096 #define SLAP_REQUIRE_AUTHC 0x0004U /* authentication before op */
1097 #define SLAP_REQUIRE_SASL 0x0008U /* SASL before op */
1098 #define SLAP_REQUIRE_STRONG 0x0010U /* strong authentication before op */
1100 /* Required Security Strength Factor */
1101 slap_ssf_set_t be_ssf_set;
1103 /* these should be renamed from be_ to bd_ */
1104 struct berval **be_suffix; /* the DN suffixes of data in this backend */
1105 struct berval **be_nsuffix; /* the normalized DN suffixes in this backend */
1106 struct berval **be_suffixAlias; /* pairs of DN suffix aliases and deref values */
1107 struct berval be_rootdn; /* the magic "root" name (DN) for this db */
1108 struct berval be_rootndn; /* the magic "root" normalized name (DN) for this db */
1109 struct berval be_rootpw; /* the magic "root" password for this db */
1110 unsigned int be_max_deref_depth; /* limit for depth of an alias deref */
1111 #define be_sizelimit be_def_limit.lms_s_soft
1112 #define be_timelimit be_def_limit.lms_t_soft
1113 struct slap_limits_set be_def_limit; /* default limits */
1114 struct slap_limits **be_limits; /* regex-based size and time limits */
1115 AccessControl *be_acl; /* access control list for this backend */
1116 slap_access_t be_dfltaccess; /* access given if no acl matches */
1117 struct slap_replica_info **be_replica; /* replicas of this backend (in master) */
1118 char *be_replogfile; /* replication log file (in master) */
1119 struct berval be_update_ndn; /* allowed to make changes (in replicas) */
1120 BerVarray be_update_refs; /* where to refer modifying clients to */
1123 void *be_private; /* anything the backend database needs */
1129 /* Backend function typedefs */
1130 typedef int (BI_init) LDAP_P((BackendInfo *bi));
1131 typedef int (BI_config) LDAP_P((BackendInfo *bi,
1132 const char *fname, int lineno,
1133 int argc, char **argv));
1134 typedef int (BI_open) LDAP_P((BackendInfo *bi));
1135 typedef int (BI_close) LDAP_P((BackendInfo *bi));
1136 typedef int (BI_destroy) LDAP_P((BackendInfo *bi));
1138 typedef int (BI_db_init) LDAP_P((Backend *bd));
1139 typedef int (BI_db_config) LDAP_P((Backend *bd,
1140 const char *fname, int lineno,
1141 int argc, char **argv));
1142 typedef int (BI_db_open) LDAP_P((Backend *bd));
1143 typedef int (BI_db_close) LDAP_P((Backend *bd));
1144 typedef int (BI_db_destroy) LDAP_P((Backend *bd));
1146 typedef int (BI_op_bind) LDAP_P(( BackendDB *bd,
1147 struct slap_conn *c, struct slap_op *o,
1148 struct berval *dn, struct berval *ndn, int method,
1149 struct berval *cred, struct berval *edn ));
1150 typedef int (BI_op_unbind) LDAP_P((BackendDB *bd,
1151 struct slap_conn *c, struct slap_op *o ));
1152 typedef int (BI_op_search) LDAP_P((BackendDB *bd,
1153 struct slap_conn *c, struct slap_op *o,
1154 struct berval *base, struct berval *nbase,
1155 int scope, int deref,
1156 int slimit, int tlimit,
1157 Filter *f, struct berval *filterstr,
1158 AttributeName *attrs, int attrsonly));
1159 typedef int (BI_op_compare)LDAP_P((BackendDB *bd,
1160 struct slap_conn *c, struct slap_op *o,
1161 struct berval *dn, struct berval *ndn,
1162 AttributeAssertion *ava));
1163 typedef int (BI_op_modify) LDAP_P((BackendDB *bd,
1164 struct slap_conn *c, struct slap_op *o,
1165 struct berval *dn, struct berval *ndn,
1167 typedef int (BI_op_modrdn) LDAP_P((BackendDB *bd,
1168 struct slap_conn *c, struct slap_op *o,
1169 struct berval *dn, struct berval *ndn,
1170 struct berval *newrdn, struct berval *nnewrdn,
1172 struct berval *newSup, struct berval *nnewSup ));
1173 typedef int (BI_op_add) LDAP_P((BackendDB *bd,
1174 struct slap_conn *c, struct slap_op *o,
1176 typedef int (BI_op_delete) LDAP_P((BackendDB *bd,
1177 struct slap_conn *c, struct slap_op *o,
1178 struct berval *dn, struct berval *ndn));
1179 typedef int (BI_op_abandon) LDAP_P((BackendDB *bd,
1180 struct slap_conn *c, struct slap_op *o,
1183 typedef int (BI_op_extended) LDAP_P((
1185 struct slap_conn *conn,
1188 struct berval * reqdata,
1190 struct berval ** rspdata,
1191 LDAPControl *** rspctrls,
1195 typedef int (BI_entry_release_rw) LDAP_P((BackendDB *bd,
1196 struct slap_conn *c, struct slap_op *o,
1199 typedef int (BI_chk_referrals) LDAP_P((BackendDB *bd,
1200 struct slap_conn *c, struct slap_op *o,
1201 struct berval *dn, struct berval *ndn,
1202 const char **text ));
1204 typedef int (BI_acl_group) LDAP_P((Backend *bd,
1205 struct slap_conn *c, struct slap_op *o,
1209 ObjectClass *group_oc,
1210 AttributeDescription *group_at ));
1212 typedef int (BI_acl_attribute) LDAP_P((Backend *bd,
1213 struct slap_conn *c, struct slap_op *o,
1214 Entry *e, struct berval *edn,
1215 AttributeDescription *entry_at,
1218 typedef int (BI_operational) LDAP_P((Backend *bd,
1219 struct slap_conn *c, struct slap_op *o,
1220 Entry *e, AttributeName *attrs, int opattrs, Attribute **a ));
1222 typedef int (BI_connection_init) LDAP_P((BackendDB *bd,
1223 struct slap_conn *c));
1224 typedef int (BI_connection_destroy) LDAP_P((BackendDB *bd,
1225 struct slap_conn *c));
1227 typedef int (BI_tool_entry_open) LDAP_P(( BackendDB *be, int mode ));
1228 typedef int (BI_tool_entry_close) LDAP_P(( BackendDB *be ));
1229 typedef ID (BI_tool_entry_first) LDAP_P(( BackendDB *be ));
1230 typedef ID (BI_tool_entry_next) LDAP_P(( BackendDB *be ));
1231 typedef Entry* (BI_tool_entry_get) LDAP_P(( BackendDB *be, ID id ));
1232 typedef ID (BI_tool_entry_put) LDAP_P(( BackendDB *be, Entry *e,
1233 struct berval *text ));
1234 typedef int (BI_tool_entry_reindex) LDAP_P(( BackendDB *be, ID id ));
1235 typedef int (BI_tool_sync) LDAP_P(( BackendDB *be ));
1237 struct slap_backend_info {
1238 char *bi_type; /* type of backend */
1241 * per backend type routines:
1242 * bi_init: called to allocate a backend_info structure,
1243 * called once BEFORE configuration file is read.
1244 * bi_init() initializes this structure hence is
1245 * called directly from be_initialize()
1246 * bi_config: called per 'backend' specific option
1247 * all such options must before any 'database' options
1248 * bi_config() is called only from read_config()
1249 * bi_open: called to open each database, called
1250 * once AFTER configuration file is read but
1251 * BEFORE any bi_db_open() calls.
1252 * bi_open() is called from backend_startup()
1253 * bi_close: called to close each database, called
1254 * once during shutdown after all bi_db_close calls.
1255 * bi_close() is called from backend_shutdown()
1256 * bi_destroy: called to destroy each database, called
1257 * once during shutdown after all bi_db_destroy calls.
1258 * bi_destory() is called from backend_destroy()
1261 BI_config *bi_config;
1264 BI_destroy *bi_destroy;
1267 * per database routines:
1268 * bi_db_init: called to initialize each database,
1269 * called upon reading 'database <type>'
1270 * called only from backend_db_init()
1271 * bi_db_config: called to configure each database,
1272 * called per database to handle per database options
1273 * called only from read_config()
1274 * bi_db_open: called to open each database
1275 * called once per database immediately AFTER bi_open()
1276 * calls but before daemon startup.
1277 * called only by backend_startup()
1278 * bi_db_close: called to close each database
1279 * called once per database during shutdown but BEFORE
1280 * any bi_close call.
1281 * called only by backend_shutdown()
1282 * bi_db_destroy: called to destroy each database
1283 * called once per database during shutdown AFTER all
1284 * bi_close calls but before bi_destory calls.
1285 * called only by backend_destory()
1287 BI_db_init *bi_db_init;
1288 BI_db_config *bi_db_config;
1289 BI_db_open *bi_db_open;
1290 BI_db_close *bi_db_close;
1291 BI_db_destroy *bi_db_destroy;
1293 /* LDAP Operations Handling Routines */
1294 BI_op_bind *bi_op_bind;
1295 BI_op_unbind *bi_op_unbind;
1296 BI_op_search *bi_op_search;
1297 BI_op_compare *bi_op_compare;
1298 BI_op_modify *bi_op_modify;
1299 BI_op_modrdn *bi_op_modrdn;
1300 BI_op_add *bi_op_add;
1301 BI_op_delete *bi_op_delete;
1302 BI_op_abandon *bi_op_abandon;
1304 /* Extended Operations Helper */
1305 BI_op_extended *bi_extended;
1307 /* Auxilary Functions */
1308 BI_entry_release_rw *bi_entry_release_rw;
1309 BI_chk_referrals *bi_chk_referrals;
1311 BI_acl_group *bi_acl_group;
1312 BI_acl_attribute *bi_acl_attribute;
1314 BI_operational *bi_operational;
1316 BI_connection_init *bi_connection_init;
1317 BI_connection_destroy *bi_connection_destroy;
1319 /* hooks for slap tools */
1320 BI_tool_entry_open *bi_tool_entry_open;
1321 BI_tool_entry_close *bi_tool_entry_close;
1322 BI_tool_entry_first *bi_tool_entry_first;
1323 BI_tool_entry_next *bi_tool_entry_next;
1324 BI_tool_entry_get *bi_tool_entry_get;
1325 BI_tool_entry_put *bi_tool_entry_put;
1326 BI_tool_entry_reindex *bi_tool_entry_reindex;
1327 BI_tool_sync *bi_tool_sync;
1329 #define SLAP_INDEX_ADD_OP 0x0001
1330 #define SLAP_INDEX_DELETE_OP 0x0002
1332 char **bi_controls; /* supported controls */
1334 unsigned int bi_nDB; /* number of databases of this type */
1335 void *bi_private; /* anything the backend type needs */
1338 #define c_authtype c_authz.sai_method
1339 #define c_authmech c_authz.sai_mech
1340 #define c_dn c_authz.sai_dn
1341 #define c_ndn c_authz.sai_ndn
1342 #define c_ssf c_authz.sai_ssf
1343 #define c_transport_ssf c_authz.sai_transport_ssf
1344 #define c_tls_ssf c_authz.sai_tls_ssf
1345 #define c_sasl_ssf c_authz.sai_sasl_ssf
1347 #define o_authtype o_authz.sai_method
1348 #define o_authmech o_authz.sai_mech
1349 #define o_dn o_authz.sai_dn
1350 #define o_ndn o_authz.sai_ndn
1351 #define o_ssf o_authz.sai_ssf
1352 #define o_transport_ssf o_authz.sai_transport_ssf
1353 #define o_tls_ssf o_authz.sai_tls_ssf
1354 #define o_sasl_ssf o_authz.sai_sasl_ssf
1356 typedef void (slap_response)( struct slap_conn *, struct slap_op *,
1357 ber_tag_t, ber_int_t, ber_int_t, const char *, const char *,
1358 BerVarray, const char *, struct berval *,
1359 struct berval *, LDAPControl ** );
1361 typedef void (slap_sresult)( struct slap_conn *, struct slap_op *,
1362 ber_int_t, const char *, const char *, BerVarray,
1363 LDAPControl **, int nentries);
1365 typedef int (slap_sendentry)( BackendDB *, struct slap_conn *,
1366 struct slap_op *, Entry *, AttributeName *, int, LDAPControl **);
1368 typedef struct slap_callback {
1369 slap_response *sc_response;
1370 slap_sresult *sc_sresult;
1371 slap_sendentry *sc_sendentry;
1376 * represents an operation pending from an ldap client
1378 typedef struct slap_op {
1379 ber_int_t o_opid; /* id of this operation */
1380 ber_int_t o_msgid; /* msgid of the request */
1381 ber_int_t o_protocol; /* version of the LDAP protocol used by client */
1382 ber_tag_t o_tag; /* tag of the request */
1383 time_t o_time; /* time op was initiated */
1384 unsigned long o_connid; /* id of conn initiating this op */
1385 ldap_pvt_thread_t o_tid; /* thread handling this op */
1387 #define SLAP_NO_CONTROL 0
1388 #define SLAP_NONCRITICAL_CONTROL 1
1389 #define SLAP_CRITICAL_CONTROL 2
1392 char o_subentries_visibility;
1394 int o_abandon; /* abandon flag */
1395 ldap_pvt_thread_mutex_t o_abandonmutex; /* protects o_abandon */
1397 #ifdef LDAP_CONNECTIONLESS
1398 Sockaddr o_peeraddr; /* UDP peer address */
1400 AuthorizationInformation o_authz;
1402 BerElement *o_ber; /* ber of the request */
1403 slap_callback *o_callback; /* callback pointers */
1404 LDAPControl **o_ctrls; /* controls */
1406 void *o_private; /* anything the backend needs */
1408 LDAP_STAILQ_ENTRY(slap_op) o_next; /* next operation in list */
1411 #define get_manageDSAit(op) ((int)(op)->o_managedsait)
1412 #define get_subentries(op) ((int)(op)->o_subentries)
1413 #define get_subentries_visibility(op) ((int)(op)->o_subentries_visibility)
1416 * Caches the result of a backend_group check for ACL evaluation
1418 typedef struct slap_gacl {
1419 struct slap_gacl *next;
1422 AttributeDescription *at;
1429 * represents a connection from an ldap client
1431 typedef struct slap_conn {
1432 int c_struct_state; /* structure management state */
1433 int c_conn_state; /* connection state */
1435 ldap_pvt_thread_mutex_t c_mutex; /* protect the connection */
1436 Sockbuf *c_sb; /* ber connection stuff */
1438 /* only can be changed by connect_init */
1439 time_t c_starttime; /* when the connection was opened */
1440 time_t c_activitytime; /* when the connection was last used */
1441 unsigned long c_connid; /* id of this connection for stats*/
1443 char *c_listener_url; /* listener URL */
1444 char *c_peer_domain; /* DNS name of client */
1445 char *c_peer_name; /* peer name (trans=addr:port) */
1446 char *c_sock_name; /* sock name (trans=addr:port) */
1448 /* only can be changed by binding thread */
1449 int c_sasl_bind_in_progress; /* multi-op bind in progress */
1450 char *c_sasl_bind_mech; /* mech in progress */
1451 struct berval c_cdn;
1453 /* authentication backend */
1454 Backend *c_authc_backend;
1456 /* authorization backend - normally same as c_authc_backend */
1457 Backend *c_authz_backend;
1459 AuthorizationInformation c_authz;
1460 GroupAssertion *c_groups;
1462 ber_int_t c_protocol; /* version of the LDAP protocol used by client */
1464 LDAP_STAILQ_HEAD(c_o, slap_op) c_ops; /* list of operations being processed */
1465 LDAP_STAILQ_HEAD(c_po, slap_op) c_pending_ops; /* list of pending operations */
1467 ldap_pvt_thread_mutex_t c_write_mutex; /* only one pdu written at a time */
1468 ldap_pvt_thread_cond_t c_write_cv; /* used to wait for sd write-ready*/
1470 BerElement *c_currentber; /* ber we're attempting to read */
1471 int c_writewaiter; /* true if writer is waiting */
1473 #ifdef LDAP_CONNECTIONLESS
1474 int c_is_udp; /* true if this is (C)LDAP over UDP */
1477 int c_is_tls; /* true if this LDAP over raw TLS */
1478 int c_needs_tls_accept; /* true if SSL_accept should be called */
1480 int c_sasl_layers; /* true if we need to install SASL i/o handlers */
1481 void *c_sasl_context; /* SASL session context */
1482 void *c_sasl_extra; /* SASL session extra stuff */
1484 long c_n_ops_received; /* num of ops received (next op_id) */
1485 long c_n_ops_executing; /* num of ops currently executing */
1486 long c_n_ops_pending; /* num of ops pending execution */
1487 long c_n_ops_completed; /* num of ops completed */
1489 long c_n_get; /* num of get calls */
1490 long c_n_read; /* num of read calls */
1491 long c_n_write; /* num of write calls */
1494 #if defined(LDAP_SYSLOG) && defined(LDAP_DEBUG)
1495 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 ) \
1497 if ( ldap_debug & (level) ) \
1498 fprintf( stderr, (fmt), (connid), (opid), (arg1), (arg2), (arg3) );\
1499 if ( ldap_syslog & (level) ) \
1500 syslog( ldap_syslog_level, (fmt), (connid), (opid), (arg1), \
1504 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 )
1508 #define SASLREGEX_REPLACE 10
1509 #define SASL_AUTHZ_SOURCE_ATTR "saslAuthzTo"
1510 #define SASL_AUTHZ_DEST_ATTR "saslAuthzFrom"
1512 typedef struct sasl_regexp {
1513 char *match; /* regexp match pattern */
1514 char *replace; /* regexp replace pattern */
1515 regex_t workspace; /* workspace for regexp engine */
1516 regmatch_t strings[SASLREGEX_REPLACE]; /* strings matching $1,$2 ... */
1517 int offset[SASLREGEX_REPLACE+2]; /* offsets of $1,$2... in *replace */
1520 /* Flags for telling slap_sasl_getdn() what type of identity is being passed */
1521 #define FLAG_GETDN_FINAL 1
1522 #define FLAG_GETDN_AUTHCID 2
1523 #define FLAG_GETDN_AUTHZID 4
1526 * listener; need to access it from monitor backend
1528 typedef struct slap_listener {
1534 #ifdef LDAP_CONNECTIONLESS
1535 int sl_is_udp; /* UDP listener is also data port */
1539 #define sl_addr sl_sa.sa_in_addr
1544 #include "proto-slap.h"
1546 #endif /* _SLAP_H_ */