1 /* slap.h - stand alone ldap server include file */
4 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
11 #include "ldap_defaults.h"
13 #include <ac/stdlib.h>
15 #include <sys/types.h>
16 #include <ac/syslog.h>
18 #include <ac/socket.h>
22 #ifdef HAVE_CYRUS_SASL
29 #define ldap_debug slap_debug
36 #include <ldap_schema.h>
38 #include "ldap_pvt_thread.h"
44 #undef f_next /* name conflict between sys/file.h on SCO and struct filter */
47 #define SERVICE_NAME OPENLDAP_PACKAGE "-slapd"
49 /* LDAPMod.mod_op value ===> Must be kept in sync with ldap.h!
51 * This is a value used internally by the backends. It is needed to allow
52 * adding values that already exist without getting an error as required by
53 * modrdn when the new rdn was already an attribute value itself.
54 * JCG 05/1999 (gomez@engr.sgi.com)
56 #define SLAP_MOD_SOFTADD 0x1000
62 #define MAXREMATCHES 10
64 /* psuedo error code indicating disconnect */
65 #define SLAPD_DISCONNECT -1
67 /* psuedo error code indicating abandoned operation */
68 #define SLAPD_ABANDON -2
71 /* We assume "C" locale, that is US-ASCII */
72 #define ASCII_SPACE(c) ( (c) == ' ' )
73 #define ASCII_LOWER(c) ( (c) >= 'a' && (c) <= 'z' )
74 #define ASCII_UPPER(c) ( (c) >= 'A' && (c) <= 'Z' )
75 #define ASCII_ALPHA(c) ( ASCII_LOWER(c) || ASCII_UPPER(c) )
76 #define ASCII_DIGIT(c) ( (c) >= '0' && (c) <= '9' )
77 #define ASCII_ALNUM(c) ( ASCII_ALPHA(c) || ASCII_DIGIT(c) )
79 #define DN_SEPARATOR(c) ((c) == ',' || (c) == ';')
80 #define RDN_SEPARATOR(c) ((c) == ',' || (c) == ';' || (c) == '+')
81 #define RDN_NEEDSESCAPE(c) ((c) == '\\' || (c) == '"')
83 #define DESC_LEADCHAR(c) ( ASCII_ALPHA(c) )
84 #define DESC_CHAR(c) ( ASCII_ALNUM(c) || (c) == '-' )
85 #define OID_LEADCHAR(c) ( ASCII_DIGIT(c) )
86 #define OID_CHAR(c) ( ASCII_DIGIT(c) || (c) == '.' )
88 #define ATTR_LEADCHAR(c) ( DESC_LEADCHAR(c) || OID_LEADCHAR(c) )
89 #define ATTR_CHAR(c) ( DESC_CHAR((c)) || (c) == '.' )
91 #define AD_LEADCHAR(c) ( ATTR_CHAR(c) )
92 #define AD_CHAR(c) ( ATTR_CHAR(c) || (c) == ';' )
94 #define SLAPD_ACI_DEFAULT_ATTR "aci"
96 /* schema needed by slapd */
97 #define SLAPD_OID_DN_SYNTAX "1.3.6.1.4.1.1466.115.121.1.12"
98 #define SLAPD_OID_ACI_SYNTAX "1.3.6.1.4.1.4203.666.2.1" /* experimental */
100 LIBSLAPD_F (int) slap_debug;
105 #define SLAP_INDEX_PRESENCE 0x0001U
106 #define SLAP_INDEX_EQUALITY 0x0002U
107 #define SLAP_INDEX_APPROX 0x0004U
108 #define SLAP_INDEX_SUBSTR 0x0008U
109 #define SLAP_INDEX_EXTENDED 0x0010U
110 #define SLAP_INDEX_UNDEFINED 0x1000U
111 #define SLAP_INDEX_FROMINIT 0x8000U /* psuedo type */
114 * represents schema information for a database
116 #define SLAP_SCHERR_OUTOFMEM 1
117 #define SLAP_SCHERR_CLASS_NOT_FOUND 2
118 #define SLAP_SCHERR_ATTR_NOT_FOUND 3
119 #define SLAP_SCHERR_DUP_CLASS 4
120 #define SLAP_SCHERR_DUP_ATTR 5
121 #define SLAP_SCHERR_DUP_SYNTAX 6
122 #define SLAP_SCHERR_DUP_RULE 7
123 #define SLAP_SCHERR_NO_NAME 8
124 #define SLAP_SCHERR_ATTR_INCOMPLETE 9
125 #define SLAP_SCHERR_MR_NOT_FOUND 10
126 #define SLAP_SCHERR_SYN_NOT_FOUND 11
127 #define SLAP_SCHERR_MR_INCOMPLETE 12
129 typedef struct slap_oid_macro {
130 struct berval som_oid;
132 struct slap_oid_macro *som_next;
135 /* forward declarations */
137 struct slap_matching_rule;
139 typedef int slap_syntax_validate_func LDAP_P((
140 struct slap_syntax *syntax,
141 struct berval * in));
143 typedef int slap_syntax_transform_func LDAP_P((
144 struct slap_syntax *syntax,
146 struct berval ** out));
148 typedef struct slap_syntax {
149 LDAP_SYNTAX ssyn_syn;
150 #define ssyn_oid ssyn_syn.syn_oid
151 #define ssyn_desc ssyn_syn.syn_desc
152 #define ssyn_extensions ssyn_syn.syn_extensions
156 #define SLAP_SYNTAX_NONE 0x0U
157 #define SLAP_SYNTAX_BLOB 0x1U /* syntax treated as blob (audio) */
158 #define SLAP_SYNTAX_BINARY 0x2U /* binary transfer required (certificate) */
159 #define SLAP_SYNTAX_BER 0x4U /* stored using BER encoding (binary,certificate) */
161 slap_syntax_validate_func *ssyn_validate;
163 #ifdef SLAPD_BINARY_CONVERSION
164 /* convert to and from binary */
165 slap_syntax_transform_func *ssyn_ber2str;
166 slap_syntax_transform_func *ssyn_str2ber;
169 struct slap_syntax *ssyn_next;
172 #define slap_syntax_is_flag(s,flag) ((int)((s)->ssyn_flags & (flag)) ? 1 : 0)
173 #define slap_syntax_is_blob(s) slap_syntax_is_flag((s),SLAP_SYNTAX_BLOB)
174 #define slap_syntax_is_binary(s) slap_syntax_is_flag((s),SLAP_SYNTAX_BINARY)
175 #define slap_syntax_is_ber(s) slap_syntax_is_flag((s),SLAP_SYNTAX_BER)
177 /* XXX -> UCS-2 Converter */
178 typedef int slap_mr_convert_func LDAP_P((
180 struct berval ** out ));
183 typedef int slap_mr_normalize_func LDAP_P((
185 struct slap_syntax *syntax, /* NULL if in is asserted value */
186 struct slap_matching_rule *mr,
188 struct berval ** out ));
190 /* Match (compare) function */
191 typedef int slap_mr_match_func LDAP_P((
193 struct slap_syntax *syntax, /* syntax of stored value */
194 struct slap_matching_rule *mr,
195 struct berval * value,
196 void * assertValue ));
198 /* Index generation function */
199 typedef int slap_mr_indexer_func LDAP_P((
201 struct slap_syntax *syntax, /* syntax of stored value */
202 struct slap_matching_rule *mr,
203 struct berval **values,
204 struct berval **keys ));
206 struct slap_filter; /* forward declaration */
208 /* Filter index function */
209 typedef int slap_mr_filter_func LDAP_P((
211 struct slap_syntax *syntax, /* syntax of stored value */
212 struct slap_matching_rule *mr,
213 struct slap_filter *filter,
214 struct berval **keys ));
216 typedef struct slap_matching_rule {
217 LDAP_MATCHING_RULE smr_mrule;
220 #define SLAP_MR_TYPE_MASK 0xFF00U
221 #define SLAP_MR_SUBTYPE_MASK 0x00FFU
223 #define SLAP_MR_NONE 0x0000U
224 #define SLAP_MR_EQUALITY 0x0100U
225 #define SLAP_MR_ORDERING 0x0200U
226 #define SLAP_MR_SUBSTR 0x0400U
227 #define SLAP_MR_EXT 0x0800U
229 #define SLAP_MR_EQUALITY_APPROX ( SLAP_MR_EQUALITY | 0x0001U )
231 #define SLAP_MR_SUBSTR_INITIAL ( SLAP_MR_SUBSTR | 0x0001U )
232 #define SLAP_MR_SUBSTR_ANY ( SLAP_MR_SUBSTR | 0x0002U )
233 #define SLAP_MR_SUBSTR_FINAL ( SLAP_MR_SUBSTR | 0x0004U )
236 slap_mr_convert_func *smr_convert;
237 slap_mr_normalize_func *smr_normalize;
238 slap_mr_match_func *smr_match;
239 slap_mr_indexer_func *smr_indexer;
240 slap_mr_filter_func *smr_filter;
241 struct slap_matching_rule *smr_next;
242 #define smr_oid smr_mrule.mr_oid
243 #define smr_names smr_mrule.mr_names
244 #define smr_desc smr_mrule.mr_desc
245 #define smr_obsolete smr_mrule.mr_obsolete
246 #define smr_syntax_oid smr_mrule.mr_syntax_oid
247 #define smr_extensions smr_mrule.mr_extensions
250 typedef struct slap_attribute_type {
251 #ifdef SLAPD_SCHEMA_NOT_COMPAT
254 LDAP_ATTRIBUTE_TYPE sat_atype;
255 struct slap_attribute_type *sat_sup;
256 struct slap_attribute_type **sat_subtypes;
257 MatchingRule *sat_equality;
258 MatchingRule *sat_ordering;
259 MatchingRule *sat_substr;
261 #ifndef SLAPD_SCHEMA_NOT_COMPAT
262 /* The next one is created to help in the transition */
263 int sat_syntax_compat;
265 struct slap_attribute_type *sat_next;
266 #define sat_oid sat_atype.at_oid
267 #define sat_names sat_atype.at_names
268 #define sat_desc sat_atype.at_desc
269 #define sat_obsolete sat_atype.at_obsolete
270 #define sat_sup_oid sat_atype.at_sup_oid
271 #define sat_equality_oid sat_atype.at_equality_oid
272 #define sat_ordering_oid sat_atype.at_ordering_oid
273 #define sat_substr_oid sat_atype.at_substr_oid
274 #define sat_syntax_oid sat_atype.at_syntax_oid
275 #define sat_single_value sat_atype.at_single_value
276 #define sat_collective sat_atype.at_collective
277 #define sat_no_user_mod sat_atype.at_no_user_mod
278 #define sat_usage sat_atype.at_usage
279 #define sat_extensions sat_atype.at_extensions
282 #define is_at_operational(at) ((at)->sat_usage)
283 #define is_at_single_value(at) ((at)->sat_single_value)
284 #define is_at_collective(at) ((at)->sat_collective)
285 #define is_at_no_user_mod(at) ((at)->sat_no_user_mod)
287 typedef struct slap_object_class {
288 LDAP_OBJECT_CLASS soc_oclass;
289 struct slap_object_class **soc_sups;
290 AttributeType **soc_required;
291 AttributeType **soc_allowed;
292 struct slap_object_class *soc_next;
293 #define soc_oid soc_oclass.oc_oid
294 #define soc_names soc_oclass.oc_names
295 #define soc_desc soc_oclass.oc_desc
296 #define soc_obsolete soc_oclass.oc_obsolete
297 #define soc_sup_oids soc_oclass.oc_sup_oids
298 #define soc_kind soc_oclass.oc_kind
299 #define soc_at_oids_must soc_oclass.oc_at_oids_must
300 #define soc_at_oids_may soc_oclass.oc_at_oids_may
301 #define soc_extensions soc_oclass.oc_extensions
305 #ifdef SLAPD_SCHEMA_NOT_COMPAT
307 * represents a recognized attribute description ( type + options )
309 typedef struct slap_attr_desc {
310 struct berval *ad_cname; /* canonical name */
311 AttributeType *ad_type; /* NULL if unknown */
312 char *ad_lang; /* NULL if no language tags */
314 #define SLAP_DESC_NONE 0x0U
315 #define SLAP_DESC_BINARY 0x1U
316 } AttributeDescription;
318 #define slap_ad_is_binary(ad) ( (int)((ad)->ad_flags & SLAP_DESC_BINARY) ? 1 : 0 )
321 * pointers to schema elements used internally
323 struct slap_internal_schema {
325 ObjectClass *si_oc_alias;
326 ObjectClass *si_oc_referral;
328 /* objectClass attribute */
329 AttributeDescription *si_ad_objectClass;
331 /* operational attributes */
332 AttributeDescription *si_ad_creatorsName;
333 AttributeDescription *si_ad_createTimestamp;
334 AttributeDescription *si_ad_modifiersName;
335 AttributeDescription *si_ad_modifyTimestamp;
336 AttributeDescription *si_ad_subschemaSubentry;
338 /* root DSE attributes */
339 AttributeDescription *si_ad_namingContexts;
340 AttributeDescription *si_ad_supportedControl;
341 AttributeDescription *si_ad_supportedExtension;
342 AttributeDescription *si_ad_supportedLDAPVersion;
343 AttributeDescription *si_ad_supportedSASLMechanisms;
345 /* subschema subentry attributes */
346 AttributeDescription *si_ad_objectClasses;
347 AttributeDescription *si_ad_attributeTypes;
348 AttributeDescription *si_ad_ldapSyntaxes;
349 AttributeDescription *si_ad_matchingRules;
350 AttributeDescription *si_ad_matchingRulesUse;
352 /* Aliases & Referrals */
353 AttributeDescription *si_ad_aliasedObjectName;
354 AttributeDescription *si_ad_ref;
357 AttributeDescription *si_ad_entry;
358 AttributeDescription *si_ad_children;
361 AttributeDescription *si_ad_userPassword;
362 AttributeDescription *si_ad_authPassword;
363 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
364 AttributeDescription *si_ad_krbName;
368 typedef struct slap_attr_assertion {
369 AttributeDescription *aa_desc;
370 struct berval *aa_value;
371 } AttributeAssertion;
373 typedef struct slap_ss_assertion {
374 AttributeDescription *sa_desc;
375 struct berval *sa_initial;
376 struct berval **sa_any;
377 struct berval *sa_final;
378 } SubstringAssertion;
380 typedef struct slap_mr_assertion {
381 char *ma_rule; /* optional */
382 AttributeDescription *ma_desc; /* optional */
383 int ma_dnattrs; /* boolean */
384 struct berval *ma_value; /* required */
385 } MatchingRuleAssertion;
390 * represents an attribute value assertion (i.e., attr;option=value)
392 typedef struct slap_ava {
393 char *ava_type; /* attribute description */
394 struct berval ava_value;
398 * represents an matching rule assertion
400 typedef struct slap_mra {
401 char *mra_rule; /* optional */
402 char *mra_type; /* attribute description -- optional */
404 struct berval *mra_value;
410 * represents a search filter
413 typedef struct slap_filter {
414 ber_tag_t f_choice; /* values taken from ldap.h, plus: */
415 #define SLAPD_FILTER_COMPUTED ((ber_tag_t) 0x01U)
418 /* precomputed result */
419 ber_int_t f_un_result;
421 #ifdef SLAPD_SCHEMA_NOT_COMPAT
426 AttributeDescription *f_un_desc;
428 /* simple value assertion */
429 AttributeAssertion *f_un_ava;
431 /* substring assertion */
432 SubstringAssertion *f_un_ssa;
434 /* matching rule assertion */
435 MatchingRuleAssertion *f_un_mra;
437 #define f_dn f_un.f_un_dn
438 #define f_desc f_un.f_un_desc
439 #define f_ava f_un.f_un_ava
440 #define f_av_desc f_un.f_un_ava->aa_desc
441 #define f_av_value f_un.f_un_ava->aa_value
442 #define f_sub f_un.f_un_ssa
443 #define f_sub_desc f_un.f_un_ssa->sa_desc
444 #define f_sub_initial f_un.f_un_ssa->sa_initial
445 #define f_sub_any f_un.f_un_ssa->sa_any
446 #define f_sub_final f_un.f_un_ssa->sa_final
447 #define f_mra f_un.f_un_mra
448 #define f_mr_rule f_un.f_un_mra->ma_rule
449 #define f_mr_desc f_un.f_un_mra->ma_desc
450 #define f_mr_value f_un.f_un_mra->ma_value
451 #define f_mr_dnaddrs f_un.f_un_mra->ma_dnattrs
456 /* equality, lessorequal, greaterorequal, approx */
466 struct berval *f_un_sub_initial;
467 struct berval **f_un_sub_any;
468 struct berval *f_un_sub_final;
471 #define f_dn f_un.f_un_type /* used for DN indices */
472 #define f_type f_un.f_un_type
473 #define f_ava f_un.f_un_ava
474 #define f_avtype f_un.f_un_ava.ava_type
475 #define f_avvalue f_un.f_un_ava.ava_value
476 #define f_mra f_un.f_un_mra
477 #define f_mrtype f_un.f_un_mra.mra_type
478 #define f_mrvalue f_un.f_un_mra.mra_value
479 #define f_mrdnaddrs f_un.f_un_mra.mra_dnattrs
480 #define f_sub f_un.f_un_sub
481 #define f_sub_type f_un.f_un_sub.f_un_sub_type
482 #define f_sub_initial f_un.f_un_sub.f_un_sub_initial
483 #define f_sub_any f_un.f_un_sub.f_un_sub_any
484 #define f_sub_final f_un.f_un_sub.f_un_sub_final
488 struct slap_filter *f_un_complex;
491 #define f_result f_un.f_un_result
492 #define f_and f_un.f_un_complex
493 #define f_or f_un.f_un_complex
494 #define f_not f_un.f_un_complex
495 #define f_list f_un.f_un_complex
497 struct slap_filter *f_next;
500 /* compare routines can return undefined */
501 #define SLAPD_COMPARE_UNDEFINED ((ber_tag_t) -1)
504 * represents an attribute (description + values)
506 typedef struct slap_attr {
507 #ifdef SLAPD_SCHEMA_NOT_COMPAT
508 AttributeDescription *a_desc;
510 char *a_type; /* description */
513 struct berval **a_vals;
514 struct slap_attr *a_next;
517 #ifndef SLAPD_SCHEMA_NOT_COMPAT
519 * the attr_syntax() routine returns one of these values
520 * telling what kind of syntax an attribute supports.
522 #define SYNTAX_CIS 0x01 /* case insensitive string */
523 #define SYNTAX_CES 0x02 /* case sensitive string */
524 #define SYNTAX_BIN 0x04 /* binary data */
525 #define SYNTAX_TEL 0x08 /* telephone number string */
526 #define SYNTAX_DN 0x10 /* dn string */
530 * the id used in the indexes to refer to an entry
532 typedef unsigned long ID;
533 #define NOID ((ID)~0)
536 * represents an entry in core
538 typedef struct slap_entry {
540 * The ID field should only be changed before entry is
541 * inserted into a cache. The ID value is backend
546 char *e_dn; /* DN of this entry */
547 char *e_ndn; /* normalized DN of this entry */
548 Attribute *e_attrs; /* list of attributes + values */
550 /* for use by the backend for any purpose */
557 #ifdef SLAPD_SCHEMA_NOT_COMPAT
558 typedef struct slap_mod {
560 AttributeDescription *sm_desc;
561 struct berval **sm_bvalues;
564 #define Modification LDAPMod
566 #define sm_desc mod_type
567 #define sm_bvalues mod_bvalues
570 typedef struct slap_mod_list {
571 Modification sml_mod;
572 #define sml_op sml_mod.sm_op
573 #define sml_desc sml_mod.sm_desc
574 #define sml_bvalues sml_mod.sm_bvalues
575 #ifndef SLAPD_SCHEMA_NOT_COMPAT
576 #define sml_type sml_mod.sm_desc
578 struct slap_mod_list *sml_next;
581 #ifdef SLAPD_SCHEMA_NOT_COMPAT
582 typedef struct slap_ldap_modlist {
584 struct slap_ldap_modlist *ml_next;
585 #define ml_op ml_mod.mod_op
586 #define ml_type ml_mod.mod_type
587 #define ml_values ml_mod.mod_values
588 #define ml_bvalues ml_mod.mod_bvalues
591 #define LDAPModList Modifications
592 #define ml_mod sml_mod
593 #define ml_op sml_mod.mod_op
594 #define ml_type sml_mod.mod_type
595 #define ml_values sml_mod.mod_values
596 #define ml_bvalues sml_mod.mod_bvalues
597 #define ml_next sml_next
601 * represents an access control list
604 typedef enum slap_access_e {
605 ACL_INVALID_ACCESS = -1,
614 typedef enum slap_control_e {
615 ACL_INVALID_CONTROL = 0,
621 typedef unsigned long slap_access_mask_t;
624 typedef struct slap_access {
625 slap_control_t a_type;
627 #define ACL_ACCESS2PRIV(access) (0x01U << (access))
629 #define ACL_PRIV_NONE ACL_ACCESS2PRIV( ACL_NONE )
630 #define ACL_PRIV_AUTH ACL_ACCESS2PRIV( ACL_AUTH )
631 #define ACL_PRIV_COMPARE ACL_ACCESS2PRIV( ACL_COMPARE )
632 #define ACL_PRIV_SEARCH ACL_ACCESS2PRIV( ACL_SEARCH )
633 #define ACL_PRIV_READ ACL_ACCESS2PRIV( ACL_READ )
634 #define ACL_PRIV_WRITE ACL_ACCESS2PRIV( ACL_WRITE )
636 #define ACL_PRIV_MASK 0x00ffUL
639 #define ACL_PRIV_LEVEL 0x1000UL
640 #define ACL_PRIV_ADDITIVE 0x2000UL
641 #define ACL_PRIV_SUBSTRACTIVE 0x4000UL
644 #define ACL_PRIV_INVALID 0x0UL
646 #define ACL_PRIV_ISSET(m,p) (((m) & (p)) == (p))
647 #define ACL_PRIV_ASSIGN(m,p) do { (m) = (p); } while(0)
648 #define ACL_PRIV_SET(m,p) do { (m) |= (p); } while(0)
649 #define ACL_PRIV_CLR(m,p) do { (m) &= ~(p); } while(0)
651 #define ACL_INIT(m) ACL_PRIV_ASSIGN(m, ACL_PRIV_NONE)
652 #define ACL_INVALIDATE(m) ACL_PRIV_ASSIGN(m, ACL_PRIV_INVALID)
654 #define ACL_GRANT(m,a) ACL_PRIV_ISSET((m),ACL_ACCESS2PRIV(a))
656 #define ACL_IS_INVALID(m) ((m) == ACL_PRIV_INVALID)
658 #define ACL_IS_LEVEL(m) ACL_PRIV_ISSET((m),ACL_PRIV_LEVEL)
659 #define ACL_IS_ADDITIVE(m) ACL_PRIV_ISSET((m),ACL_PRIV_ADDITIVE)
660 #define ACL_IS_SUBTRACTIVE(m) ACL_PRIV_ISSET((m),ACL_PRIV_SUBSTRACTIVE)
662 #define ACL_LVL_NONE (ACL_PRIV_NONE|ACL_PRIV_LEVEL)
663 #define ACL_LVL_AUTH (ACL_PRIV_AUTH|ACL_LVL_NONE)
664 #define ACL_LVL_COMPARE (ACL_PRIV_COMPARE|ACL_LVL_AUTH)
665 #define ACL_LVL_SEARCH (ACL_PRIV_SEARCH|ACL_LVL_COMPARE)
666 #define ACL_LVL_READ (ACL_PRIV_READ|ACL_LVL_SEARCH)
667 #define ACL_LVL_WRITE (ACL_PRIV_WRITE|ACL_LVL_READ)
669 #define ACL_LVL(m,l) (((m)&ACL_PRIV_MASK) == ((l)&ACL_PRIV_MASK))
670 #define ACL_LVL_IS_NONE(m) ACL_LVL((m),ACL_LVL_NONE)
671 #define ACL_LVL_IS_AUTH(m) ACL_LVL((m),ACL_LVL_AUTH)
672 #define ACL_LVL_IS_COMPARE(m) ACL_LVL((m),ACL_LVL_COMPARE)
673 #define ACL_LVL_IS_SEARCH(m) ACL_LVL((m),ACL_LVL_SEARCH)
674 #define ACL_LVL_IS_READ(m) ACL_LVL((m),ACL_LVL_READ)
675 #define ACL_LVL_IS_WRITE(m) ACL_LVL((m),ACL_LVL_WRITE)
677 #define ACL_LVL_ASSIGN_NONE(m) ACL_PRIV_ASSIGN((m),ACL_LVL_NONE)
678 #define ACL_LVL_ASSIGN_AUTH(m) ACL_PRIV_ASSIGN((m),ACL_LVL_AUTH)
679 #define ACL_LVL_ASSIGN_COMPARE(m) ACL_PRIV_ASSIGN((m),ACL_LVL_COMPARE)
680 #define ACL_LVL_ASSIGN_SEARCH(m) ACL_PRIV_ASSIGN((m),ACL_LVL_SEARCH)
681 #define ACL_LVL_ASSIGN_READ(m) ACL_PRIV_ASSIGN((m),ACL_LVL_READ)
682 #define ACL_LVL_ASSIGN_WRITE(m) ACL_PRIV_ASSIGN((m),ACL_LVL_WRITE)
684 slap_access_mask_t a_mask;
687 #ifdef SLAPD_SCHEMA_NOT_COMPAT
688 AttributeDescription *a_dn_at;
694 char *a_peername_pat;
695 char *a_sockname_pat;
700 #ifdef SLAPD_ACI_ENABLED
701 #ifdef SLAPD_SCHEMA_NOT_COMPAT
702 AttributeDescription *a_aci_at;
711 #ifdef SLAPD_SCHEMA_NOT_COMPAT
712 AttributeDescription *a_group_at;
717 struct slap_access *a_next;
721 typedef struct slap_acl {
722 /* "to" part: the entries this acl applies to */
728 /* "by" part: list of who has what access to the entries */
731 struct slap_acl *acl_next;
735 * replog moddn param structure
737 struct replog_moddn {
745 * represents a backend
748 typedef struct slap_backend_info BackendInfo; /* per backend type */
749 typedef struct slap_backend_db BackendDB; /* per backend database */
751 LIBSLAPD_F (int) nBackendInfo;
752 LIBSLAPD_F (int) nBackendDB;
753 LIBSLAPD_F (BackendInfo *) backendInfo;
754 LIBSLAPD_F (BackendDB *) backendDB;
756 LIBSLAPD_F (int) slapMode;
757 #define SLAP_UNDEFINED_MODE 0x0000
758 #define SLAP_SERVER_MODE 0x0001
759 #define SLAP_TOOL_MODE 0x0002
760 #define SLAP_MODE 0x0003
762 #define SLAP_TRUNCATE_MODE 0x0100
764 #define SLAP_TIMED_MODE 0x1000
767 /* temporary aliases */
768 typedef BackendDB Backend;
769 #define nbackends nBackendDB
770 #define backends backendDB
772 struct slap_backend_db {
773 BackendInfo *bd_info; /* pointer to shared backend info */
775 /* BackendInfo accessors */
776 #define be_config bd_info->bi_db_config
777 #define be_type bd_info->bi_type
779 #define be_bind bd_info->bi_op_bind
780 #define be_unbind bd_info->bi_op_unbind
781 #define be_add bd_info->bi_op_add
782 #define be_compare bd_info->bi_op_compare
783 #define be_delete bd_info->bi_op_delete
784 #define be_modify bd_info->bi_op_modify
785 #define be_modrdn bd_info->bi_op_modrdn
786 #define be_search bd_info->bi_op_search
788 #define be_extended bd_info->bi_extended
790 #define be_release bd_info->bi_entry_release_rw
791 #define be_group bd_info->bi_acl_group
793 #define be_controls bd_info->bi_controls
795 #define be_connection_init bd_info->bi_connection_init
796 #define be_connection_destroy bd_info->bi_connection_destroy
799 #define be_entry_open bd_info->bi_tool_entry_open
800 #define be_entry_close bd_info->bi_tool_entry_close
801 #define be_entry_first bd_info->bi_tool_entry_first
802 #define be_entry_next bd_info->bi_tool_entry_next
803 #define be_entry_get bd_info->bi_tool_entry_get
804 #define be_entry_put bd_info->bi_tool_entry_put
805 #define be_index_attr bd_info->bi_tool_index_attr
806 #define be_index_change bd_info->bi_tool_index_change
807 #define be_sync bd_info->bi_tool_sync
810 #ifdef HAVE_CYRUS_SASL
811 #define be_sasl_authorize bd_info->bi_sasl_authorize
812 #define be_sasl_getsecret bd_info->bi_sasl_getsecret
813 #define be_sasl_putsecret bd_info->bi_sasl_putsecret
816 /* these should be renamed from be_ to bd_ */
817 char **be_suffix; /* the DN suffixes of data in this backend */
818 char **be_nsuffix; /* the normalized DN suffixes in this backend */
819 char **be_suffixAlias; /* pairs of DN suffix aliases and deref values */
820 char *be_root_dn; /* the magic "root" dn for this db */
821 char *be_root_ndn; /* the magic "root" normalized dn for this db */
822 struct berval be_root_pw; /* the magic "root" password for this db */
823 int be_readonly; /* 1 => db is in "read only" mode */
824 unsigned int be_max_deref_depth; /* limit for depth of an alias deref */
825 int be_sizelimit; /* size limit for this backend */
826 int be_timelimit; /* time limit for this backend */
827 AccessControl *be_acl; /* access control list for this backend */
828 slap_access_t be_dfltaccess; /* access given if no acl matches */
829 char **be_replica; /* replicas of this backend (in master) */
830 char *be_replogfile; /* replication log file (in master) */
831 char *be_update_ndn; /* allowed to make changes (in replicas) */
832 struct berval **be_update_refs; /* where to refer modifying clients to */
833 int be_lastmod; /* keep track of lastmodified{by,time} */
837 void *be_private; /* anything the backend database needs */
843 typedef int (*SLAP_EXTENDED_FN) LDAP_P((
845 struct slap_conn *conn,
848 struct berval * reqdata,
850 struct berval ** rspdata,
851 LDAPControl *** rspctrls,
853 struct berval *** refs ));
855 struct slap_backend_info {
856 char *bi_type; /* type of backend */
859 * per backend type routines:
860 * bi_init: called to allocate a backend_info structure,
861 * called once BEFORE configuration file is read.
862 * bi_init() initializes this structure hence is
863 * called directly from be_initialize()
864 * bi_config: called per 'backend' specific option
865 * all such options must before any 'database' options
866 * bi_config() is called only from read_config()
867 * bi_open: called to open each database, called
868 * once AFTER configuration file is read but
869 * BEFORE any bi_db_open() calls.
870 * bi_open() is called from backend_startup()
871 * bi_close: called to close each database, called
872 * once during shutdown after all bi_db_close calls.
873 * bi_close() is called from backend_shutdown()
874 * bi_destroy: called to destroy each database, called
875 * once during shutdown after all bi_db_destroy calls.
876 * bi_destory() is called from backend_destroy()
878 int (*bi_init) LDAP_P((BackendInfo *bi));
879 int (*bi_config) LDAP_P((BackendInfo *bi,
880 const char *fname, int lineno, int argc, char **argv ));
881 int (*bi_open) LDAP_P((BackendInfo *bi));
882 int (*bi_close) LDAP_P((BackendInfo *bi));
883 int (*bi_destroy) LDAP_P((BackendInfo *bi));
886 * per database routines:
887 * bi_db_init: called to initialize each database,
888 * called upon reading 'database <type>'
889 * called only from backend_db_init()
890 * bi_db_config: called to configure each database,
891 * called per database to handle per database options
892 * called only from read_config()
893 * bi_db_open: called to open each database
894 * called once per database immediately AFTER bi_open()
895 * calls but before daemon startup.
896 * called only by backend_startup()
897 * bi_db_close: called to close each database
898 * called once per database during shutdown but BEFORE
900 * called only by backend_shutdown()
901 * bi_db_destroy: called to destroy each database
902 * called once per database during shutdown AFTER all
903 * bi_close calls but before bi_destory calls.
904 * called only by backend_destory()
906 int (*bi_db_init) LDAP_P((Backend *bd));
907 int (*bi_db_config) LDAP_P((Backend *bd,
908 const char *fname, int lineno, int argc, char **argv ));
909 int (*bi_db_open) LDAP_P((Backend *bd));
910 int (*bi_db_close) LDAP_P((Backend *bd));
911 int (*bi_db_destroy) LDAP_P((Backend *db));
913 /* LDAP Operations Handling Routines */
914 int (*bi_op_bind) LDAP_P(( BackendDB *bd,
915 struct slap_conn *c, struct slap_op *o,
916 const char *dn, const char *ndn, int method,
917 struct berval *cred, char** edn ));
918 int (*bi_op_unbind) LDAP_P((BackendDB *bd,
919 struct slap_conn *c, struct slap_op *o ));
920 int (*bi_op_search) LDAP_P((BackendDB *bd,
921 struct slap_conn *c, struct slap_op *o,
922 const char *base, const char *nbase,
923 int scope, int deref,
924 int slimit, int tlimit,
925 Filter *f, const char *filterstr,
926 char **attrs, int attrsonly));
927 #ifdef SLAPD_SCHEMA_NOT_COMPAT
928 int (*bi_op_compare)LDAP_P((BackendDB *bd,
929 struct slap_conn *c, struct slap_op *o,
930 const char *dn, const char *ndn,
931 AttributeAssertion *ava));
933 int (*bi_op_compare)LDAP_P((BackendDB *bd,
934 struct slap_conn *c, struct slap_op *o,
935 const char *dn, const char *ndn,
938 int (*bi_op_modify) LDAP_P((BackendDB *bd,
939 struct slap_conn *c, struct slap_op *o,
940 const char *dn, const char *ndn, Modifications *m));
941 int (*bi_op_modrdn) LDAP_P((BackendDB *bd,
942 struct slap_conn *c, struct slap_op *o,
943 const char *dn, const char *ndn,
944 const char *newrdn, int deleteoldrdn,
945 const char *newSuperior));
946 int (*bi_op_add) LDAP_P((BackendDB *bd,
947 struct slap_conn *c, struct slap_op *o,
949 int (*bi_op_delete) LDAP_P((BackendDB *bd,
950 struct slap_conn *c, struct slap_op *o,
951 const char *dn, const char *ndn));
952 int (*bi_op_abandon) LDAP_P((BackendDB *bd,
953 struct slap_conn *c, struct slap_op *o,
956 /* Extended Operations Helper */
957 SLAP_EXTENDED_FN bi_extended;
959 /* Auxilary Functions */
960 int (*bi_entry_release_rw) LDAP_P((BackendDB *bd, Entry *e, int rw));
962 #ifdef SLAPD_SCHEMA_NOT_COMPAT
963 int (*bi_acl_group) LDAP_P((Backend *bd,
964 Entry *e, const char *bdn, const char *edn,
965 const char *objectclassValue,
966 AttributeDescription *group_at ));
968 int (*bi_acl_group) LDAP_P((Backend *bd,
969 Entry *e, const char *bdn, const char *edn,
970 const char *objectclassValue,
971 const char *group_at ));
974 int (*bi_connection_init) LDAP_P((BackendDB *bd,
975 struct slap_conn *c));
976 int (*bi_connection_destroy) LDAP_P((BackendDB *bd,
977 struct slap_conn *c));
979 /* hooks for slap tools */
980 int (*bi_tool_entry_open) LDAP_P(( BackendDB *be, int mode ));
981 int (*bi_tool_entry_close) LDAP_P(( BackendDB *be ));
982 ID (*bi_tool_entry_first) LDAP_P(( BackendDB *be ));
983 ID (*bi_tool_entry_next) LDAP_P(( BackendDB *be ));
984 Entry* (*bi_tool_entry_get) LDAP_P(( BackendDB *be, ID id ));
985 ID (*bi_tool_entry_put) LDAP_P(( BackendDB *be, Entry *e ));
986 #ifdef SLAPD_SCHEMA_NOT_COMPAT
987 int (*bi_tool_index_attr) LDAP_P(( BackendDB *be,
988 AttributeDescription *desc ));
989 int (*bi_tool_index_change) LDAP_P(( BackendDB *be,
990 AttributeDescription *desc,
991 struct berval **bv, ID id, int op ));
993 int (*bi_tool_index_attr) LDAP_P(( BackendDB *be,
995 int (*bi_tool_index_change) LDAP_P(( BackendDB *be,
997 struct berval **bv, ID id, int op ));
999 int (*bi_tool_sync) LDAP_P(( BackendDB *be ));
1001 #ifdef HAVE_CYRUS_SASL
1002 int (*bi_sasl_authorize) LDAP_P(( BackendDB *be,
1003 const char *authnid, const char *authzid,
1004 const char **canon_authzid, const char **errstr ));
1005 int (*bi_sasl_getsecret) LDAP_P(( BackendDB *be,
1006 const char *mechanism, const char *authzid,
1007 const char *realm, sasl_secret_t **secret ));
1008 int (*bi_sasl_putsecret) LDAP_P(( BackendDB *be,
1009 const char *mechanism, const char *auth_identity,
1010 const char *realm, const sasl_secret_t *secret ));
1011 #endif /* HAVE_CYRUS_SASL */
1013 #define SLAP_INDEX_ADD_OP 0x0001
1014 #define SLAP_INDEX_DELETE_OP 0x0002
1016 char **bi_controls; /* supported controls */
1018 unsigned int bi_nDB; /* number of databases of this type */
1019 void *bi_private; /* anything the backend type needs */
1023 * represents an operation pending from an ldap client
1026 typedef struct slap_op {
1027 ber_int_t o_opid; /* id of this operation */
1028 ber_int_t o_msgid; /* msgid of the request */
1030 ldap_pvt_thread_t o_tid; /* thread handling this op */
1032 BerElement *o_ber; /* ber of the request */
1034 ber_tag_t o_tag; /* tag of the request */
1035 time_t o_time; /* time op was initiated */
1038 /* should only be used for reporting purposes */
1039 char *o_authc_dn; /* authentication DN */
1041 /* should be used as the DN of the User */
1042 char *o_authz_dn; /* authorization DN */
1043 char *o_authz_ndn; /* authorizaiton NDN */
1046 char *o_dn; /* dn bound when op was initiated */
1047 char *o_ndn; /* normalized dn bound when op was initiated */
1050 ber_int_t o_protocol; /* version of the LDAP protocol used by client */
1051 ber_tag_t o_authtype; /* auth method used to bind dn */
1052 /* values taken from ldap.h */
1054 char *o_authmech; /* SASL mechanism used to bind dn */
1056 LDAPControl **o_ctrls; /* controls */
1058 unsigned long o_connid; /* id of conn initiating this op */
1060 #ifdef LDAP_CONNECTIONLESS
1061 int o_cldap; /* != 0 if this came in via CLDAP */
1062 struct sockaddr o_clientaddr; /* client address if via CLDAP */
1063 char o_searchbase; /* search base if via CLDAP */
1066 ldap_pvt_thread_mutex_t o_abandonmutex; /* protects o_abandon */
1067 int o_abandon; /* abandon flag */
1069 struct slap_op *o_next; /* next operation in list */
1070 void *o_private; /* anything the backend needs */
1074 * represents a connection from an ldap client
1077 typedef struct slap_conn {
1078 int c_struct_state; /* structure management state */
1079 int c_conn_state; /* connection state */
1081 ldap_pvt_thread_mutex_t c_mutex; /* protect the connection */
1082 Sockbuf *c_sb; /* ber connection stuff */
1084 /* only can be changed by connect_init */
1085 time_t c_starttime; /* when the connection was opened */
1086 time_t c_activitytime; /* when the connection was last used */
1087 unsigned long c_connid; /* id of this connection for stats*/
1089 char *c_listener_url; /* listener URL */
1090 char *c_peer_domain; /* DNS name of client */
1091 char *c_peer_name; /* peer name (trans=addr:port) */
1092 char *c_sock_name; /* sock name (trans=addr:port) */
1094 /* only can be changed by binding thread */
1095 int c_sasl_bind_in_progress; /* multi-op bind in progress */
1096 char *c_sasl_bind_mech; /* mech in progress */
1097 #ifdef HAVE_CYRUS_SASL
1098 sasl_conn_t *c_sasl_bind_context; /* Cyrus SASL state data */
1101 /* authentication backend */
1102 Backend *c_authc_backend;
1104 /* authorization backend - normally same as c_authc_backend */
1105 Backend *c_authz_backend;
1108 /* authentication backend */
1109 /* should only be used for reporting purposes */
1110 char *c_authc_dn; /* authentication DN */
1112 /* should be used as the DN of the User */
1113 char *c_authz_dn; /* authorization DN */
1114 char *c_authz_ndn; /* authorization NDN */
1117 char *c_cdn; /* DN provided by the client */
1118 char *c_dn; /* DN bound to this conn */
1121 ber_int_t c_protocol; /* version of the LDAP protocol used by client */
1122 ber_tag_t c_authtype;/* auth method used to bind c_dn */
1123 char *c_authmech; /* SASL mechanism used to bind c_dn */
1125 Operation *c_ops; /* list of operations being processed */
1126 Operation *c_pending_ops; /* list of pending operations */
1128 ldap_pvt_thread_mutex_t c_write_mutex; /* only one pdu written at a time */
1129 ldap_pvt_thread_cond_t c_write_cv; /* used to wait for sd write-ready*/
1131 BerElement *c_currentber; /* ber we're attempting to read */
1132 int c_writewaiter; /* true if writer is waiting */
1135 int c_is_tls; /* true if this LDAP over raw TLS */
1136 int c_needs_tls_accept; /* true if SSL_accept should be called */
1139 long c_n_ops_received; /* num of ops received (next op_id) */
1140 long c_n_ops_executing; /* num of ops currently executing */
1141 long c_n_ops_pending; /* num of ops pending execution */
1142 long c_n_ops_completed; /* num of ops completed */
1144 long c_n_get; /* num of get calls */
1145 long c_n_read; /* num of read calls */
1146 long c_n_write; /* num of write calls */
1149 #if defined(LDAP_SYSLOG) && defined(LDAP_DEBUG)
1150 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 ) \
1152 if ( ldap_debug & (level) ) \
1153 fprintf( stderr, (fmt), (connid), (opid), (arg1), (arg2), (arg3) );\
1154 if ( ldap_syslog & (level) ) \
1155 syslog( ldap_syslog_level, (fmt), (connid), (opid), (arg1), \
1159 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 )
1164 #include "proto-slap.h"
1166 #endif /* _SLAP_H_ */