1 /* slap.h - stand alone ldap server include file */
4 * Copyright 1998-1999 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
57 #undef LDAP_MOD_BVALUES /* we always use BVALUES */
63 #define MAXREMATCHES 10
65 /* psuedo error code to indicating abandoned operation */
66 #define SLAPD_ABANDON -1
68 /* We assume "C" locale, that is US-ASCII */
69 #define ASCII_SPACE(c) ( (c) == ' ' )
70 #define ASCII_LOWER(c) ( (c) >= 'a' && (c) <= 'z' )
71 #define ASCII_UPPER(c) ( (c) >= 'A' && (c) <= 'Z' )
72 #define ASCII_ALPHA(c) ( ASCII_LOWER(c) || ASCII_UPPER(c) )
73 #define ASCII_DIGIT(c) ( (c) >= '0' && (c) <= '9' )
74 #define ASCII_ALNUM(c) ( ASCII_ALPHA(c) || ASCII_DIGIT(c) )
76 #define DN_SEPARATOR(c) ((c) == ',' || (c) == ';')
77 #define RDN_SEPARATOR(c) ((c) == ',' || (c) == ';' || (c) == '+')
78 #define RDN_NEEDSESCAPE(c) ((c) == '\\' || (c) == '"')
80 #define DESC_LEADCHAR(c) ( ASCII_ALPHA(c) )
81 #define DESC_CHAR(c) ( ASCII_ALNUM(c) || (c) == '-' )
82 #define OID_LEADCHAR(c) ( ASCII_DIGIT(c) )
83 #define OID_CHAR(c) ( ASCII_DIGIT(c) || (c) == '.' )
85 #define ATTR_LEADCHAR(c) ( DESC_LEADCHAR(c) || OID_LEADCHAR(c) )
86 #define ATTR_CHAR(c) ( DESC_CHAR((c)) || (c) == '.' )
88 #define AD_LEADCHAR(c) ( ATTR_CHAR(c) )
89 #define AD_CHAR(c) ( ATTR_CHAR(c) || (c) == ';' )
91 #define SLAPD_ACI_DEFAULT_ATTR "aci"
93 /* schema needed by slapd */
94 #define SLAPD_OID_DN_SYNTAX "1.3.6.1.4.1.1466.115.121.1.12"
95 #define SLAPD_OID_ACI_SYNTAX "1.3.6.1.4.1.4203.666.2.1" /* experimental */
97 LIBSLAPD_F (int) slap_debug;
102 #define SLAP_INDEX_PRESENCE 0x0001U
103 #define SLAP_INDEX_EQUALITY 0x0002U
104 #define SLAP_INDEX_APPROX 0x0004U
105 #define SLAP_INDEX_SUB 0x0008U
106 #define SLAP_INDEX_UNKNOWN 0x0010U
107 #define SLAP_INDEX_FROMINIT 0x8000U /* psuedo type */
111 * represents schema information for a database
113 #define SLAP_SCHERR_OUTOFMEM 1
114 #define SLAP_SCHERR_CLASS_NOT_FOUND 2
115 #define SLAP_SCHERR_ATTR_NOT_FOUND 3
116 #define SLAP_SCHERR_DUP_CLASS 4
117 #define SLAP_SCHERR_DUP_ATTR 5
118 #define SLAP_SCHERR_DUP_SYNTAX 6
119 #define SLAP_SCHERR_DUP_RULE 7
120 #define SLAP_SCHERR_NO_NAME 8
121 #define SLAP_SCHERR_ATTR_INCOMPLETE 9
122 #define SLAP_SCHERR_MR_NOT_FOUND 10
123 #define SLAP_SCHERR_SYN_NOT_FOUND 11
124 #define SLAP_SCHERR_MR_INCOMPLETE 12
126 typedef struct slap_oid_macro {
127 struct berval som_oid;
129 struct slap_oid_macro *som_next;
132 /* forward declarations */
134 struct slap_matching_rule;
136 typedef int slap_syntax_validate_func LDAP_P((
137 struct slap_syntax *syntax,
138 struct berval * in));
140 typedef int slap_syntax_transform_func LDAP_P((
141 struct slap_syntax *syntax,
143 struct berval ** out));
145 typedef struct slap_syntax {
146 LDAP_SYNTAX ssyn_syn;
149 #define SLAP_SYNTAX_NONE 0x0U
150 #define SLAP_SYNTAX_BINARY 0x1U
152 slap_syntax_validate_func *ssyn_validate;
154 /* convert to and from binary */
155 slap_syntax_transform_func *ssyn_ber2str;
156 slap_syntax_transform_func *ssyn_str2ber;
158 struct slap_syntax *ssyn_next;
159 #define ssyn_oid ssyn_syn.syn_oid
160 #define ssyn_desc ssyn_syn.syn_desc
163 /* XXX -> UCS-2 Converter */
164 typedef int slap_mr_convert_func LDAP_P((
166 struct berval ** out ));
169 typedef int slap_mr_normalize_func LDAP_P((
171 struct slap_syntax *syntax, /* NULL if in is asserted value */
172 struct slap_matching_rule *mr,
174 struct berval ** out ));
176 /* Match (compare) function */
177 typedef int slap_mr_match_func LDAP_P((
179 struct slap_syntax *syntax, /* syntax of stored value */
180 struct slap_matching_rule *mr,
181 struct berval * value,
182 void * assertValue ));
184 /* Index generation function */
185 typedef int slap_mr_indexer_func LDAP_P((
187 struct slap_syntax *syntax, /* syntax of stored value */
188 struct slap_matching_rule *mr,
189 struct berval **values,
190 struct berval **keys ));
192 struct slap_filter; /* forward declaration */
194 /* Filter index function */
195 typedef int slap_mr_filter_func LDAP_P((
197 struct slap_syntax *syntax, /* syntax of stored value */
198 struct slap_matching_rule *mr,
199 struct slap_filter *filter,
200 struct berval **keys ));
202 typedef struct slap_matching_rule {
203 LDAP_MATCHING_RULE smr_mrule;
205 #define SLAP_MR_NONE 0x00U
206 #define SLAP_MR_EQUALITY 0x01U
207 #define SLAP_MR_APPROX 0x02U
208 #define SLAP_MR_ORDERING 0x04U
209 #define SLAP_MR_SUBSTR 0x08U
210 #define SLAP_MR_EXT 0x10U
212 slap_mr_convert_func *smr_convert;
213 slap_mr_normalize_func *smr_normalize;
214 slap_mr_match_func *smr_match;
215 slap_mr_indexer_func *smr_indexer;
216 slap_mr_filter_func *smr_filter;
217 struct slap_matching_rule *smr_next;
218 #define smr_oid smr_mrule.mr_oid
219 #define smr_names smr_mrule.mr_names
220 #define smr_desc smr_mrule.mr_desc
221 #define smr_obsolete smr_mrule.mr_obsolete
222 #define smr_syntax_oid smr_mrule.mr_syntax_oid
225 typedef struct slap_attribute_type {
226 #ifdef SLAPD_SCHEMA_NOT_COMPAT
229 LDAP_ATTRIBUTE_TYPE sat_atype;
230 struct slap_attribute_type *sat_sup;
231 struct slap_attribute_type **sat_subtypes;
232 MatchingRule *sat_equality;
233 MatchingRule *sat_ordering;
234 MatchingRule *sat_substr;
236 #ifndef SLAPD_SCHEMA_NOT_COMPAT
237 /* The next one is created to help in the transition */
238 int sat_syntax_compat;
240 struct slap_attribute_type *sat_next;
241 #define sat_oid sat_atype.at_oid
242 #define sat_names sat_atype.at_names
243 #define sat_desc sat_atype.at_desc
244 #define sat_obsolete sat_atype.at_obsolete
245 #define sat_sup_oid sat_atype.at_sup_oid
246 #define sat_equality_oid sat_atype.at_equality_oid
247 #define sat_ordering_oid sat_atype.at_ordering_oid
248 #define sat_substr_oid sat_atype.at_substr_oid
249 #define sat_syntax_oid sat_atype.at_syntax_oid
250 #define sat_single_value sat_atype.at_single_value
251 #define sat_collective sat_atype.at_collective
252 #define sat_no_user_mod sat_atype.at_no_user_mod
253 #define sat_usage sat_atype.at_usage
256 #define is_at_operational(at) ((at)->sat_usage)
257 #define is_at_single_value(at) ((at)->sat_single_value)
258 #define is_at_collective(at) ((at)->sat_collective)
259 #define is_at_no_user_mod(at) ((at)->sat_no_user_mod)
261 typedef struct slap_object_class {
262 LDAP_OBJECT_CLASS soc_oclass;
263 struct slap_object_class **soc_sups;
264 AttributeType **soc_required;
265 AttributeType **soc_allowed;
266 struct slap_object_class *soc_next;
267 #define soc_oid soc_oclass.oc_oid
268 #define soc_names soc_oclass.oc_names
269 #define soc_desc soc_oclass.oc_desc
270 #define soc_obsolete soc_oclass.oc_obsolete
271 #define soc_sup_oids soc_oclass.oc_sup_oids
272 #define soc_kind soc_oclass.oc_kind
273 #define soc_at_oids_must soc_oclass.oc_at_oids_must
274 #define soc_at_oids_may soc_oclass.oc_at_oids_may
278 #ifdef SLAPD_SCHEMA_NOT_COMPAT
280 * represents a recognized attribute description ( type + options )
282 typedef struct slap_attr_desc {
283 struct berval *ad_cname; /* canonical name */
284 AttributeType *ad_type; /* NULL if unknown */
285 char *ad_lang; /* NULL if no language tags */
287 #define SLAP_DESC_NONE 0x0U
288 #define SLAP_DESC_BINARY 0x1U
289 } AttributeDescription;
291 typedef struct slap_attr_assertion {
292 AttributeDescription *aa_desc;
293 struct berval *aa_value;
294 } AttributeAssertion;
296 typedef struct slap_ss_assertion {
297 AttributeDescription *sa_desc;
298 struct berval *sa_initial;
299 struct berval **sa_any;
300 struct berval *sa_final;
301 } SubstringAssertion;
303 typedef struct slap_mr_assertion {
304 char *ma_rule; /* optional */
305 AttributeDescription *ma_desc; /* optional */
306 int ma_dnattrs; /* boolean */
307 struct berval *ma_value; /* required */
308 } MatchingRuleAssertion;
313 * represents an attribute value assertion (i.e., attr;option=value)
315 typedef struct slap_ava {
316 char *ava_type; /* attribute description */
317 struct berval ava_value;
321 * represents an matching rule assertion
323 typedef struct slap_mra {
324 char *mra_rule; /* optional */
325 char *mra_type; /* attribute description -- optional */
327 struct berval *mra_value;
333 * represents a search filter
335 typedef struct slap_filter {
336 ber_tag_t f_choice; /* values taken from ldap.h */
339 #ifdef SLAPD_SCHEMA_NOT_COMPAT
344 AttributeDescription *f_un_desc;
346 /* simple value assertion */
347 AttributeAssertion *f_un_ava;
349 /* substring assertion */
350 SubstringAssertion *f_un_ssa;
352 /* matching rule assertion */
353 MatchingRuleAssertion *f_un_mra;
356 struct slap_filter *f_un_complex;
358 #define f_dn f_un.f_un_dn
359 #define f_desc f_un.f_un_desc
360 #define f_ava f_un.f_un_ava
361 #define f_av_desc f_un.f_un_ava->aa_desc
362 #define f_av_value f_un.f_un_ava->aa_value
363 #define f_sub f_un.f_un_ssa
364 #define f_sub_desc f_un.f_un_ssa->sa_desc
365 #define f_sub_initial f_un.f_un_ssa->sa_initial
366 #define f_sub_any f_un.f_un_ssa->sa_any
367 #define f_sub_final f_un.f_un_ssa->sa_final
368 #define f_mra f_un.f_un_mra
369 #define f_mr_rule f_un.f_un_mra->ma_rule
370 #define f_mr_desc f_un.f_un_mra->ma_desc
371 #define f_mr_value f_un.f_un_mra->ma_value
372 #define f_mr_dnaddrs f_un.f_un_mra->ma_dnattrs
377 /* equality, lessorequal, greaterorequal, approx */
383 /* and, or, not, list */
384 struct slap_filter *f_un_complex;
390 struct berval *f_un_sub_initial;
391 struct berval **f_un_sub_any;
392 struct berval *f_un_sub_final;
395 #define f_dn f_un.f_un_type /* used for DN indices */
396 #define f_type f_un.f_un_type
397 #define f_ava f_un.f_un_ava
398 #define f_avtype f_un.f_un_ava.ava_type
399 #define f_avvalue f_un.f_un_ava.ava_value
400 #define f_mra f_un.f_un_mra
401 #define f_mrtype f_un.f_un_mra.mra_type
402 #define f_mrvalue f_un.f_un_mra.mra_value
403 #define f_mrdnaddrs f_un.f_un_mra.mra_dnattrs
404 #define f_sub f_un.f_un_sub
405 #define f_sub_type f_un.f_un_sub.f_un_sub_type
406 #define f_sub_initial f_un.f_un_sub.f_un_sub_initial
407 #define f_sub_any f_un.f_un_sub.f_un_sub_any
408 #define f_sub_final f_un.f_un_sub.f_un_sub_final
412 #define f_and f_un.f_un_complex
413 #define f_or f_un.f_un_complex
414 #define f_not f_un.f_un_complex
415 #define f_list f_un.f_un_complex
417 struct slap_filter *f_next;
421 * represents an attribute (description + values)
423 typedef struct slap_attr {
424 #ifdef SLAPD_SCHEMA_NOT_COMPAT
425 AttributeDescription a_desc;
427 char *a_type; /* description */
430 struct berval **a_vals;
431 struct slap_attr *a_next;
434 #ifndef SLAPD_SCHEMA_NOT_COMPAT
436 * the attr_syntax() routine returns one of these values
437 * telling what kind of syntax an attribute supports.
439 #define SYNTAX_CIS 0x01 /* case insensitive string */
440 #define SYNTAX_CES 0x02 /* case sensitive string */
441 #define SYNTAX_BIN 0x04 /* binary data */
442 #define SYNTAX_TEL 0x08 /* telephone number string */
443 #define SYNTAX_DN 0x10 /* dn string */
447 * the id used in the indexes to refer to an entry
449 typedef unsigned long ID;
450 #define NOID ((ID)~0)
453 * represents an entry in core
455 typedef struct slap_entry {
457 * The ID field should only be changed before entry is
458 * inserted into a cache. The ID value is backend
463 char *e_dn; /* DN of this entry */
464 char *e_ndn; /* normalized DN of this entry */
465 Attribute *e_attrs; /* list of attributes + values */
467 /* for use by the backend for any purpose */
474 #ifdef SLAPD_SCHEMA_NOT_COMPAT
475 typedef struct slap_mod {
477 AttributeDescription sm_desc;
478 struct berval **sm_bvalues;
481 #define Modification LDAPMod
483 #define sm_desc mod_type
484 #define sm_type mod_type
485 #define sm_bvalues mod_bvalues
488 typedef struct slap_mod_list {
489 Modification sml_mod;
490 #define sml_op sml_mod.sm_op
491 #define sml_desc sml_mod.sm_desc
492 #define sml_bvalues sml_mod.sm_bvalues
493 #ifndef SLAPD_SCHEMA_NOT_COMPAT
494 #define sml_type sml_mod.sm_type
496 struct slap_mod_list *sml_next;
499 #ifdef SLAPD_SCHEMA_NOT_COMPAT
500 typedef struct slap_ldap_modlist {
502 struct slap_ldap_modlist *ml_next;
503 #define ml_op ml_mod.mod_op
504 #define ml_type ml_mod.mod_type
505 #define ml_values ml_mod.mod_values
506 #define ml_bvalues ml_mod.mod_bvalues
509 #define LDAPModList Modifications
510 #define ml_mod sml_mod
511 #define ml_op sml_mod.mod_op
512 #define ml_type sml_mod.mod_type
513 #define ml_values sml_mod.mod_values
514 #define ml_bvalues sml_mod.mod_bvalues
515 #define ml_next sml_next
519 * represents an access control list
522 typedef enum slap_access_e {
523 ACL_INVALID_ACCESS = -1,
532 typedef enum slap_control_e {
533 ACL_INVALID_CONTROL = 0,
539 typedef unsigned long slap_access_mask_t;
542 typedef struct slap_access {
543 slap_control_t a_type;
545 #define ACL_ACCESS2PRIV(access) (0x01U << (access))
547 #define ACL_PRIV_NONE ACL_ACCESS2PRIV( ACL_NONE )
548 #define ACL_PRIV_AUTH ACL_ACCESS2PRIV( ACL_AUTH )
549 #define ACL_PRIV_COMPARE ACL_ACCESS2PRIV( ACL_COMPARE )
550 #define ACL_PRIV_SEARCH ACL_ACCESS2PRIV( ACL_SEARCH )
551 #define ACL_PRIV_READ ACL_ACCESS2PRIV( ACL_READ )
552 #define ACL_PRIV_WRITE ACL_ACCESS2PRIV( ACL_WRITE )
554 #define ACL_PRIV_MASK 0x00ffUL
557 #define ACL_PRIV_LEVEL 0x1000UL
558 #define ACL_PRIV_ADDITIVE 0x2000UL
559 #define ACL_PRIV_SUBSTRACTIVE 0x4000UL
562 #define ACL_PRIV_INVALID 0x0UL
564 #define ACL_PRIV_ISSET(m,p) (((m) & (p)) == (p))
565 #define ACL_PRIV_ASSIGN(m,p) do { (m) = (p); } while(0)
566 #define ACL_PRIV_SET(m,p) do { (m) |= (p); } while(0)
567 #define ACL_PRIV_CLR(m,p) do { (m) &= ~(p); } while(0)
569 #define ACL_INIT(m) ACL_PRIV_ASSIGN(m, ACL_PRIV_NONE)
570 #define ACL_INVALIDATE(m) ACL_PRIV_ASSIGN(m, ACL_PRIV_INVALID)
572 #define ACL_GRANT(m,a) ACL_PRIV_ISSET((m),ACL_ACCESS2PRIV(a))
574 #define ACL_IS_INVALID(m) ((m) == ACL_PRIV_INVALID)
576 #define ACL_IS_LEVEL(m) ACL_PRIV_ISSET((m),ACL_PRIV_LEVEL)
577 #define ACL_IS_ADDITIVE(m) ACL_PRIV_ISSET((m),ACL_PRIV_ADDITIVE)
578 #define ACL_IS_SUBTRACTIVE(m) ACL_PRIV_ISSET((m),ACL_PRIV_SUBSTRACTIVE)
580 #define ACL_LVL_NONE (ACL_PRIV_NONE|ACL_PRIV_LEVEL)
581 #define ACL_LVL_AUTH (ACL_PRIV_AUTH|ACL_LVL_NONE)
582 #define ACL_LVL_COMPARE (ACL_PRIV_COMPARE|ACL_LVL_AUTH)
583 #define ACL_LVL_SEARCH (ACL_PRIV_SEARCH|ACL_LVL_COMPARE)
584 #define ACL_LVL_READ (ACL_PRIV_READ|ACL_LVL_SEARCH)
585 #define ACL_LVL_WRITE (ACL_PRIV_WRITE|ACL_LVL_READ)
587 #define ACL_LVL(m,l) (((m)&ACL_PRIV_MASK) == ((l)&ACL_PRIV_MASK))
588 #define ACL_LVL_IS_NONE(m) ACL_LVL((m),ACL_LVL_NONE)
589 #define ACL_LVL_IS_AUTH(m) ACL_LVL((m),ACL_LVL_AUTH)
590 #define ACL_LVL_IS_COMPARE(m) ACL_LVL((m),ACL_LVL_COMPARE)
591 #define ACL_LVL_IS_SEARCH(m) ACL_LVL((m),ACL_LVL_SEARCH)
592 #define ACL_LVL_IS_READ(m) ACL_LVL((m),ACL_LVL_READ)
593 #define ACL_LVL_IS_WRITE(m) ACL_LVL((m),ACL_LVL_WRITE)
595 #define ACL_LVL_ASSIGN_NONE(m) ACL_PRIV_ASSIGN((m),ACL_LVL_NONE)
596 #define ACL_LVL_ASSIGN_AUTH(m) ACL_PRIV_ASSIGN((m),ACL_LVL_AUTH)
597 #define ACL_LVL_ASSIGN_COMPARE(m) ACL_PRIV_ASSIGN((m),ACL_LVL_COMPARE)
598 #define ACL_LVL_ASSIGN_SEARCH(m) ACL_PRIV_ASSIGN((m),ACL_LVL_SEARCH)
599 #define ACL_LVL_ASSIGN_READ(m) ACL_PRIV_ASSIGN((m),ACL_LVL_READ)
600 #define ACL_LVL_ASSIGN_WRITE(m) ACL_PRIV_ASSIGN((m),ACL_LVL_WRITE)
602 slap_access_mask_t a_mask;
605 #ifdef SLAPD_SCHEMA_NOT_COMPAT
606 AttributeDescription *a_dn_at;
612 char *a_peername_pat;
613 char *a_sockname_pat;
618 #ifdef SLAPD_ACI_ENABLED
619 #ifdef SLAPD_SCHEMA_NOT_COMPAT
620 AttributeDescription *a_aci_at;
629 #ifdef SLAPD_SCHEMA_NOT_COMPAT
630 AttributeDescription *a_group_at;
635 struct slap_access *a_next;
639 typedef struct slap_acl {
640 /* "to" part: the entries this acl applies to */
646 /* "by" part: list of who has what access to the entries */
649 struct slap_acl *acl_next;
653 * replog moddn param structure
655 struct replog_moddn {
663 * represents a backend
666 typedef struct slap_backend_info BackendInfo; /* per backend type */
667 typedef struct slap_backend_db BackendDB; /* per backend database */
669 LIBSLAPD_F (int) nBackendInfo;
670 LIBSLAPD_F (int) nBackendDB;
671 LIBSLAPD_F (BackendInfo *) backendInfo;
672 LIBSLAPD_F (BackendDB *) backendDB;
674 LIBSLAPD_F (int) slapMode;
675 #define SLAP_UNDEFINED_MODE 0x0000
676 #define SLAP_SERVER_MODE 0x0001
677 #define SLAP_TOOL_MODE 0x0002
678 #define SLAP_MODE 0x0003
680 #define SLAP_TRUNCATE_MODE 0x0100
682 #define SLAP_TIMED_MODE 0x1000
684 #define SLAP_TOOLID_MODE 4
686 /* temporary aliases */
687 typedef BackendDB Backend;
688 #define nbackends nBackendDB
689 #define backends backendDB
691 struct slap_backend_db {
692 BackendInfo *bd_info; /* pointer to shared backend info */
694 /* BackendInfo accessors */
695 #define be_config bd_info->bi_db_config
696 #define be_type bd_info->bi_type
698 #define be_bind bd_info->bi_op_bind
699 #define be_unbind bd_info->bi_op_unbind
700 #define be_add bd_info->bi_op_add
701 #define be_compare bd_info->bi_op_compare
702 #define be_delete bd_info->bi_op_delete
703 #define be_modify bd_info->bi_op_modify
704 #define be_modrdn bd_info->bi_op_modrdn
705 #define be_search bd_info->bi_op_search
707 #define be_extended bd_info->bi_extended
709 #define be_release bd_info->bi_entry_release_rw
710 #define be_group bd_info->bi_acl_group
712 #define be_controls bd_info->bi_controls
714 #define be_connection_init bd_info->bi_connection_init
715 #define be_connection_destroy bd_info->bi_connection_destroy
718 #define be_entry_open bd_info->bi_tool_entry_open
719 #define be_entry_close bd_info->bi_tool_entry_close
720 #define be_entry_first bd_info->bi_tool_entry_first
721 #define be_entry_next bd_info->bi_tool_entry_next
722 #define be_entry_get bd_info->bi_tool_entry_get
723 #define be_entry_put bd_info->bi_tool_entry_put
724 #define be_index_attr bd_info->bi_tool_index_attr
725 #define be_index_change bd_info->bi_tool_index_change
726 #define be_sync bd_info->bi_tool_sync
729 #ifdef HAVE_CYRUS_SASL
730 #define be_sasl_authorize bd_info->bi_sasl_authorize
731 #define be_sasl_getsecret bd_info->bi_sasl_getsecret
732 #define be_sasl_putsecret bd_info->bi_sasl_putsecret
735 /* these should be renamed from be_ to bd_ */
736 char **be_suffix; /* the DN suffixes of data in this backend */
737 char **be_nsuffix; /* the normalized DN suffixes in this backend */
738 char **be_suffixAlias; /* pairs of DN suffix aliases and deref values */
739 char *be_root_dn; /* the magic "root" dn for this db */
740 char *be_root_ndn; /* the magic "root" normalized dn for this db */
741 struct berval be_root_pw; /* the magic "root" password for this db */
742 int be_readonly; /* 1 => db is in "read only" mode */
743 unsigned int be_max_deref_depth; /* limit for depth of an alias deref */
744 int be_sizelimit; /* size limit for this backend */
745 int be_timelimit; /* time limit for this backend */
746 AccessControl *be_acl; /* access control list for this backend */
747 slap_access_t be_dfltaccess; /* access given if no acl matches */
748 char **be_replica; /* replicas of this backend (in master) */
749 char *be_replogfile; /* replication log file (in master) */
750 char *be_update_ndn; /* allowed to make changes (in replicas) */
751 struct berval **be_update_refs; /* where to refer modifying clients to */
752 int be_lastmod; /* keep track of lastmodified{by,time} */
756 void *be_private; /* anything the backend database needs */
762 typedef int (*SLAP_EXTENDED_FN) LDAP_P((
764 struct slap_conn *conn,
767 struct berval * reqdata,
769 struct berval ** rspdata,
770 LDAPControl *** rspctrls,
772 struct berval *** refs ));
774 struct slap_backend_info {
775 char *bi_type; /* type of backend */
778 * per backend type routines:
779 * bi_init: called to allocate a backend_info structure,
780 * called once BEFORE configuration file is read.
781 * bi_init() initializes this structure hence is
782 * called directly from be_initialize()
783 * bi_config: called per 'backend' specific option
784 * all such options must before any 'database' options
785 * bi_config() is called only from read_config()
786 * bi_open: called to open each database, called
787 * once AFTER configuration file is read but
788 * BEFORE any bi_db_open() calls.
789 * bi_open() is called from backend_startup()
790 * bi_close: called to close each database, called
791 * once during shutdown after all bi_db_close calls.
792 * bi_close() is called from backend_shutdown()
793 * bi_destroy: called to destroy each database, called
794 * once during shutdown after all bi_db_destroy calls.
795 * bi_destory() is called from backend_destroy()
797 int (*bi_init) LDAP_P((BackendInfo *bi));
798 int (*bi_config) LDAP_P((BackendInfo *bi,
799 const char *fname, int lineno, int argc, char **argv ));
800 int (*bi_open) LDAP_P((BackendInfo *bi));
801 int (*bi_close) LDAP_P((BackendInfo *bi));
802 int (*bi_destroy) LDAP_P((BackendInfo *bi));
805 * per database routines:
806 * bi_db_init: called to initialize each database,
807 * called upon reading 'database <type>'
808 * called only from backend_db_init()
809 * bi_db_config: called to configure each database,
810 * called per database to handle per database options
811 * called only from read_config()
812 * bi_db_open: called to open each database
813 * called once per database immediately AFTER bi_open()
814 * calls but before daemon startup.
815 * called only by backend_startup()
816 * bi_db_close: called to close each database
817 * called once per database during shutdown but BEFORE
819 * called only by backend_shutdown()
820 * bi_db_destroy: called to destroy each database
821 * called once per database during shutdown AFTER all
822 * bi_close calls but before bi_destory calls.
823 * called only by backend_destory()
825 int (*bi_db_init) LDAP_P((Backend *bd));
826 int (*bi_db_config) LDAP_P((Backend *bd,
827 const char *fname, int lineno, int argc, char **argv ));
828 int (*bi_db_open) LDAP_P((Backend *bd));
829 int (*bi_db_close) LDAP_P((Backend *bd));
830 int (*bi_db_destroy) LDAP_P((Backend *db));
832 /* LDAP Operations Handling Routines */
833 int (*bi_op_bind) LDAP_P(( BackendDB *bd,
834 struct slap_conn *c, struct slap_op *o,
835 char *dn, char *ndn, int method, char* mechanism,
836 struct berval *cred, char** edn ));
837 int (*bi_op_unbind) LDAP_P((BackendDB *bd,
838 struct slap_conn *c, struct slap_op *o ));
839 int (*bi_op_search) LDAP_P((BackendDB *bd,
840 struct slap_conn *c, struct slap_op *o,
841 char *base, char *nbase, int scope, int deref,
842 int slimit, int tlimit,
843 Filter *f, char *filterstr, char **attrs,
845 #ifdef SLAPD_SCHEMA_NOT_COMPAT
846 int (*bi_op_compare)LDAP_P((BackendDB *bd,
847 struct slap_conn *c, struct slap_op *o,
848 char *dn, char *ndn, AttributeAssertion *ava));
850 int (*bi_op_compare)LDAP_P((BackendDB *bd,
851 struct slap_conn *c, struct slap_op *o,
852 char *dn, char *ndn, Ava *ava));
854 int (*bi_op_modify) LDAP_P((BackendDB *bd,
855 struct slap_conn *c, struct slap_op *o,
856 char *dn, char *ndn, Modifications *m));
857 int (*bi_op_modrdn) LDAP_P((BackendDB *bd,
858 struct slap_conn *c, struct slap_op *o,
859 char *dn, char *ndn, char *newrdn, int deleteoldrdn,
861 int (*bi_op_add) LDAP_P((BackendDB *bd,
862 struct slap_conn *c, struct slap_op *o,
864 int (*bi_op_delete) LDAP_P((BackendDB *bd,
865 struct slap_conn *c, struct slap_op *o,
866 char *dn, char *ndn));
867 int (*bi_op_abandon) LDAP_P((BackendDB *bd,
868 struct slap_conn *c, struct slap_op *o,
871 /* Extended Operations Helper */
872 SLAP_EXTENDED_FN bi_extended;
874 /* Auxilary Functions */
875 int (*bi_entry_release_rw) LDAP_P((BackendDB *bd, Entry *e, int rw));
877 #ifdef SLAPD_SCHEMA_NOT_COMPAT
878 int (*bi_acl_group) LDAP_P((Backend *bd,
879 Entry *e, const char *bdn, const char *edn,
880 const char *objectclassValue,
881 AttributeDescription *group_at ));
883 int (*bi_acl_group) LDAP_P((Backend *bd,
884 Entry *e, const char *bdn, const char *edn,
885 const char *objectclassValue,
886 const char *group_at ));
889 int (*bi_connection_init) LDAP_P((BackendDB *bd,
890 struct slap_conn *c));
891 int (*bi_connection_destroy) LDAP_P((BackendDB *bd,
892 struct slap_conn *c));
894 /* hooks for slap tools */
895 int (*bi_tool_entry_open) LDAP_P(( BackendDB *be, int mode ));
896 int (*bi_tool_entry_close) LDAP_P(( BackendDB *be ));
897 ID (*bi_tool_entry_first) LDAP_P(( BackendDB *be ));
898 ID (*bi_tool_entry_next) LDAP_P(( BackendDB *be ));
899 Entry* (*bi_tool_entry_get) LDAP_P(( BackendDB *be, ID id ));
900 ID (*bi_tool_entry_put) LDAP_P(( BackendDB *be, Entry *e ));
901 int (*bi_tool_index_attr) LDAP_P(( BackendDB *be, char* type ));
902 int (*bi_tool_index_change) LDAP_P(( BackendDB *be, char* type,
903 struct berval **bv, ID id, int op ));
904 int (*bi_tool_sync) LDAP_P(( BackendDB *be ));
906 #ifdef HAVE_CYRUS_SASL
907 int (*bi_sasl_authorize) LDAP_P(( BackendDB *be,
908 const char *authnid, const char *authzid,
909 const char **canon_authzid, const char **errstr ));
910 int (*bi_sasl_getsecret) LDAP_P(( BackendDB *be,
911 const char *mechanism, const char *authzid,
912 const char *realm, sasl_secret_t **secret ));
913 int (*bi_sasl_putsecret) LDAP_P(( BackendDB *be,
914 const char *mechanism, const char *auth_identity,
915 const char *realm, const sasl_secret_t *secret ));
916 #endif /* HAVE_CYRUS_SASL */
918 #define SLAP_INDEX_ADD_OP 0x0001
919 #define SLAP_INDEX_DELETE_OP 0x0002
921 char **bi_controls; /* supported controls */
923 unsigned int bi_nDB; /* number of databases of this type */
924 void *bi_private; /* anything the backend type needs */
928 * represents an operation pending from an ldap client
931 typedef struct slap_op {
932 ber_int_t o_opid; /* id of this operation */
933 ber_int_t o_msgid; /* msgid of the request */
935 ldap_pvt_thread_t o_tid; /* thread handling this op */
937 BerElement *o_ber; /* ber of the request */
939 ber_tag_t o_tag; /* tag of the request */
940 time_t o_time; /* time op was initiated */
942 int o_bind_in_progress; /* multi-step bind in progress */
944 /* should only be used for reporting purposes */
945 char *o_authc_dn; /* authentication DN */
947 /* should be used as the DN of the User */
948 char *o_authz_dn; /* authorization DN */
949 char *o_authz_ndn; /* authorizaiton NDN */
952 char *o_dn; /* dn bound when op was initiated */
953 char *o_ndn; /* normalized dn bound when op was initiated */
956 ber_int_t o_protocol; /* version of the LDAP protocol used by client */
957 ber_tag_t o_authtype; /* auth method used to bind dn */
958 /* values taken from ldap.h */
960 char *o_authmech; /* SASL mechanism used to bind dn */
962 LDAPControl **o_ctrls; /* controls */
964 unsigned long o_connid; /* id of conn initiating this op */
966 #ifdef LDAP_CONNECTIONLESS
967 int o_cldap; /* != 0 if this came in via CLDAP */
968 struct sockaddr o_clientaddr; /* client address if via CLDAP */
969 char o_searchbase; /* search base if via CLDAP */
972 ldap_pvt_thread_mutex_t o_abandonmutex; /* protects o_abandon */
973 int o_abandon; /* abandon flag */
975 struct slap_op *o_next; /* next operation in list */
976 void *o_private; /* anything the backend needs */
980 * represents a connection from an ldap client
983 typedef struct slap_conn {
984 int c_struct_state; /* structure management state */
985 int c_conn_state; /* connection state */
987 ldap_pvt_thread_mutex_t c_mutex; /* protect the connection */
988 Sockbuf *c_sb; /* ber connection stuff */
990 /* only can be changed by connect_init */
991 time_t c_starttime; /* when the connection was opened */
992 time_t c_activitytime; /* when the connection was last used */
993 unsigned long c_connid; /* id of this connection for stats*/
995 char *c_listener_url; /* listener URL */
996 char *c_peer_domain; /* DNS name of client */
997 char *c_peer_name; /* peer name (trans=addr:port) */
998 char *c_sock_name; /* sock name (trans=addr:port) */
1000 /* only can be changed by binding thread */
1001 int c_bind_in_progress; /* multi-op bind in progress */
1002 #ifdef HAVE_CYRUS_SASL
1003 sasl_conn_t *c_sasl_context;
1005 void *c_authstate; /* SASL state data */
1007 Backend *c_authc_backend;
1009 /* authorization backend */
1010 Backend *c_authz_backend;
1013 /* authentication backend */
1014 /* should only be used for reporting purposes */
1015 char *c_authc_dn; /* authentication DN */
1017 /* should be used as the DN of the User */
1018 char *c_authz_dn; /* authorization DN */
1019 char *c_authz_ndn; /* authorization NDN */
1022 char *c_cdn; /* DN provided by the client */
1023 char *c_dn; /* DN bound to this conn */
1026 ber_int_t c_protocol; /* version of the LDAP protocol used by client */
1027 ber_tag_t c_authtype;/* auth method used to bind c_dn */
1028 char *c_authmech; /* SASL mechanism used to bind c_dn */
1030 Operation *c_ops; /* list of operations being processed */
1031 Operation *c_pending_ops; /* list of pending operations */
1033 ldap_pvt_thread_mutex_t c_write_mutex; /* only one pdu written at a time */
1034 ldap_pvt_thread_cond_t c_write_cv; /* used to wait for sd write-ready*/
1036 BerElement *c_currentber; /* ber we're attempting to read */
1037 int c_writewaiter; /* true if writer is waiting */
1040 int c_is_tls; /* true if this LDAP over raw TLS */
1041 int c_needs_tls_accept; /* true if SSL_accept should be called */
1044 long c_n_ops_received; /* num of ops received (next op_id) */
1045 long c_n_ops_executing; /* num of ops currently executing */
1046 long c_n_ops_pending; /* num of ops pending execution */
1047 long c_n_ops_completed; /* num of ops completed */
1049 long c_n_get; /* num of get calls */
1050 long c_n_read; /* num of read calls */
1051 long c_n_write; /* num of write calls */
1054 #if defined(LDAP_SYSLOG) && defined(LDAP_DEBUG)
1055 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 ) \
1057 if ( ldap_debug & (level) ) \
1058 fprintf( stderr, (fmt), (connid), (opid), (arg1), (arg2), (arg3) );\
1059 if ( ldap_syslog & (level) ) \
1060 syslog( ldap_syslog_level, (fmt), (connid), (opid), (arg1), \
1064 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 )
1069 #include "proto-slap.h"
1071 #endif /* _slap_h_ */