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.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 */
193 /* Filter index function */
194 typedef int slap_mr_filter_func LDAP_P((
196 struct slap_syntax *syntax, /* syntax of stored value */
197 struct slap_matching_rule *mr,
198 struct slap_filter *filter,
199 struct berval **keys ));
201 typedef struct slap_matching_rule {
202 LDAP_MATCHING_RULE smr_mrule;
204 #define SLAP_MR_NONE 0x00U
205 #define SLAP_MR_EQUALITY 0x01U
206 #define SLAP_MR_APPROX 0x02U
207 #define SLAP_MR_ORDERING 0x04U
208 #define SLAP_MR_SUBSTR 0x08U
209 #define SLAP_MR_EXT 0x10U
211 slap_mr_convert_func *smr_convert;
212 slap_mr_normalize_func *smr_normalize;
213 slap_mr_match_func *smr_match;
214 slap_mr_indexer_func *smr_indexer;
215 slap_mr_filter_func *smr_filter;
216 struct slap_matching_rule *smr_next;
217 #define smr_oid smr_mrule.mr_oid
218 #define smr_names smr_mrule.mr_names
219 #define smr_desc smr_mrule.mr_desc
220 #define smr_obsolete smr_mrule.mr_obsolete
221 #define smr_syntax_oid smr_mrule.mr_syntax_oid
224 typedef struct slap_attribute_type {
225 #ifdef SLAPD_SCHEMA_NOT_COMPAT
228 LDAP_ATTRIBUTE_TYPE sat_atype;
229 struct slap_attribute_type *sat_sup;
230 struct slap_attribute_type **sat_subtypes;
231 MatchingRule *sat_equality;
232 MatchingRule *sat_ordering;
233 MatchingRule *sat_substr;
235 #ifndef SLAPD_SCHEMA_NOT_COMPAT
236 /* The next one is created to help in the transition */
237 int sat_syntax_compat;
239 struct slap_attribute_type *sat_next;
240 #define sat_oid sat_atype.at_oid
241 #define sat_names sat_atype.at_names
242 #define sat_desc sat_atype.at_desc
243 #define sat_obsolete sat_atype.at_obsolete
244 #define sat_sup_oid sat_atype.at_sup_oid
245 #define sat_equality_oid sat_atype.at_equality_oid
246 #define sat_ordering_oid sat_atype.at_ordering_oid
247 #define sat_substr_oid sat_atype.at_substr_oid
248 #define sat_syntax_oid sat_atype.at_syntax_oid
249 #define sat_single_value sat_atype.at_single_value
250 #define sat_collective sat_atype.at_collective
251 #define sat_no_user_mod sat_atype.at_no_user_mod
252 #define sat_usage sat_atype.at_usage
255 #define is_at_operational(at) ((at)->sat_usage)
256 #define is_at_single_value(at) ((at)->sat_single_value)
257 #define is_at_collective(at) ((at)->sat_collective)
258 #define is_at_no_user_mod(at) ((at)->sat_no_user_mod)
260 typedef struct slap_object_class {
261 LDAP_OBJECT_CLASS soc_oclass;
262 struct slap_object_class **soc_sups;
263 AttributeType **soc_required;
264 AttributeType **soc_allowed;
265 struct slap_object_class *soc_next;
266 #define soc_oid soc_oclass.oc_oid
267 #define soc_names soc_oclass.oc_names
268 #define soc_desc soc_oclass.oc_desc
269 #define soc_obsolete soc_oclass.oc_obsolete
270 #define soc_sup_oids soc_oclass.oc_sup_oids
271 #define soc_kind soc_oclass.oc_kind
272 #define soc_at_oids_must soc_oclass.oc_at_oids_must
273 #define soc_at_oids_may soc_oclass.oc_at_oids_may
277 #ifdef SLAPD_SCHEMA_NOT_COMPAT
279 * represents a recognized attribute description ( type + options )
281 typedef struct slap_attr_desc {
282 struct berval *ad_cname; /* canonical name */
283 AttributeType *ad_type; /* NULL if unknown */
284 char *ad_lang; /* NULL if no language tags */
286 #define SLAP_DESC_NONE 0x0U
287 #define SLAP_DESC_BINARY 0x1U
288 } AttributeDescription;
290 typedef struct slap_attr_assertion {
291 AttributeDescription *aa_desc;
292 struct berval *aa_value;
293 } AttributeAssertion;
295 typedef struct slap_ss_assertion {
296 AttributeDescription *sa_desc;
297 struct berval *sa_initial;
298 struct berval **sa_any;
299 struct berval *sa_final;
300 } SubstringAssertion;
302 typedef struct slap_mr_assertion {
303 char *ma_rule; /* optional */
304 AttributeDescription *ma_desc; /* optional */
305 int ma_dnattrs; /* boolean */
306 struct berval *ma_value; /* required */
307 } MatchingRuleAssertion;
312 * represents an attribute value assertion (i.e., attr;option=value)
314 typedef struct slap_ava {
315 char *ava_type; /* attribute description */
316 struct berval ava_value;
320 * represents an matching rule assertion
322 typedef struct slap_mra {
323 char *mra_rule; /* optional */
324 char *mra_type; /* attribute description -- optional */
326 struct berval *mra_value;
332 * represents a search filter
334 typedef struct slap_filter {
335 ber_tag_t f_choice; /* values taken from ldap.h */
338 #ifdef SLAPD_SCHEMA_NOT_COMPAT
343 AttributeDescription *f_un_desc;
345 /* simple value assertion */
346 AttributeAssertion *f_un_ava;
348 /* substring assertion */
349 SubstringAssertion *f_un_ssa;
351 /* matching rule assertion */
352 MatchingRuleAssertion *f_un_mra;
355 struct slap_filter *f_un_complex;
357 #define f_dn f_un.f_un_dn
358 #define f_desc f_un.f_un_desc
359 #define f_ava f_un.f_un_ava
360 #define f_av_desc f_un.f_un_ava->aa_desc
361 #define f_av_value f_un.f_un_ava->aa_value
362 #define f_sub f_un.f_un_ssa
363 #define f_sub_desc f_un.f_un_ssa->sa_desc
364 #define f_sub_initial f_un.f_un_ssa->sa_initial
365 #define f_sub_any f_un.f_un_ssa->sa_any
366 #define f_sub_final f_un.f_un_ssa->sa_final
367 #define f_mra f_un.f_un_mra
368 #define f_mr_rule f_un.f_un_mra->ma_rule
369 #define f_mr_desc f_un.f_un_mra->ma_desc
370 #define f_mr_value f_un.f_un_mra->ma_value
371 #define f_mr_dnaddrs f_un.f_un_mra->ma_dnattrs
376 /* equality, lessorequal, greaterorequal, approx */
382 /* and, or, not, list */
383 struct slap_filter *f_un_complex;
389 struct berval *f_un_sub_initial;
390 struct berval **f_un_sub_any;
391 struct berval *f_un_sub_final;
394 #define f_dn f_un.f_un_type /* used for DN indices */
395 #define f_type f_un.f_un_type
396 #define f_ava f_un.f_un_ava
397 #define f_avtype f_un.f_un_ava.ava_type
398 #define f_avvalue f_un.f_un_ava.ava_value
399 #define f_mra f_un.f_un_mra
400 #define f_mrtype f_un.f_un_mra.mra_type
401 #define f_mrvalue f_un.f_un_mra.mra_value
402 #define f_mrdnaddrs f_un.f_un_mra.mra_dnattrs
403 #define f_sub f_un.f_un_sub
404 #define f_sub_type f_un.f_un_sub.f_un_sub_type
405 #define f_sub_initial f_un.f_un_sub.f_un_sub_initial
406 #define f_sub_any f_un.f_un_sub.f_un_sub_any
407 #define f_sub_final f_un.f_un_sub.f_un_sub_final
411 #define f_and f_un.f_un_complex
412 #define f_or f_un.f_un_complex
413 #define f_not f_un.f_un_complex
414 #define f_list f_un.f_un_complex
416 struct slap_filter *f_next;
420 * represents an attribute (description + values)
422 typedef struct slap_attr {
423 #ifdef SLAPD_SCHEMA_NOT_COMPAT
424 AttributeDescription a_desc;
426 char *a_type; /* description */
429 struct berval **a_vals;
430 struct slap_attr *a_next;
433 #ifndef SLAPD_SCHEMA_NOT_COMPAT
435 * the attr_syntax() routine returns one of these values
436 * telling what kind of syntax an attribute supports.
438 #define SYNTAX_CIS 0x01 /* case insensitive string */
439 #define SYNTAX_CES 0x02 /* case sensitive string */
440 #define SYNTAX_BIN 0x04 /* binary data */
441 #define SYNTAX_TEL 0x08 /* telephone number string */
442 #define SYNTAX_DN 0x10 /* dn string */
446 * the id used in the indexes to refer to an entry
448 typedef unsigned long ID;
449 #define NOID ((ID)~0)
452 * represents an entry in core
454 typedef struct slap_entry {
456 * The ID field should only be changed before entry is
457 * inserted into a cache. The ID value is backend
462 char *e_dn; /* DN of this entry */
463 char *e_ndn; /* normalized DN of this entry */
464 Attribute *e_attrs; /* list of attributes + values */
466 /* for use by the backend for any purpose */
473 #ifdef SLAPD_SCHEMA_NOT_COMPAT
474 typedef struct slap_mod {
476 AttributeDescription sm_desc;
477 struct berval **sm_bvalues;
480 #define Modification LDAPMod
483 typedef struct slap_mod_list {
484 Modification sml_mod;
485 #ifdef SLAPD_SCHEMA_NOT_COMPAT
486 #define sml_op sml_mod.sm_op
487 #define sml_desc sml_mod.sm_desc
488 #define sml_bvalues sml_mod.sm_bvalues
490 #define sml_op sml_mod.mod_op
491 #define sml_type sml_mod.mod_type
492 #define sml_values sml_mod.mod_values
493 #define sml_bvalues sml_mod.mod_bvalues
495 struct slap_mod_list *sml_next;
498 #ifdef SLAPD_SCHEMA_NOT_COMPAT
499 typedef struct slap_ldap_modlist {
501 struct slap_ldap_modlist *ml_next;
502 #define ml_op ml_mod.mod_op
503 #define ml_type ml_mod.mod_type
504 #define ml_values ml_mod.mod_values
505 #define ml_bvalues ml_mod.mod_bvalues
508 #define LDAPModList Modifications
509 #define ml_mod sml_mod
510 #define ml_op sml_mod.mod_op
511 #define ml_type sml_mod.mod_type
512 #define ml_values sml_mod.mod_values
513 #define ml_bvalues sml_mod.mod_bvalues
514 #define ml_next sml_next
518 * represents an access control list
521 typedef enum slap_access_e {
522 ACL_INVALID_ACCESS = -1,
531 typedef enum slap_control_e {
532 ACL_INVALID_CONTROL = 0,
538 typedef unsigned long slap_access_mask_t;
541 typedef struct slap_access {
542 slap_control_t a_type;
544 #define ACL_ACCESS2PRIV(access) (0x01U << (access))
546 #define ACL_PRIV_NONE ACL_ACCESS2PRIV( ACL_NONE )
547 #define ACL_PRIV_AUTH ACL_ACCESS2PRIV( ACL_AUTH )
548 #define ACL_PRIV_COMPARE ACL_ACCESS2PRIV( ACL_COMPARE )
549 #define ACL_PRIV_SEARCH ACL_ACCESS2PRIV( ACL_SEARCH )
550 #define ACL_PRIV_READ ACL_ACCESS2PRIV( ACL_READ )
551 #define ACL_PRIV_WRITE ACL_ACCESS2PRIV( ACL_WRITE )
553 #define ACL_PRIV_MASK 0x00ffUL
556 #define ACL_PRIV_LEVEL 0x1000UL
557 #define ACL_PRIV_ADDITIVE 0x2000UL
558 #define ACL_PRIV_SUBSTRACTIVE 0x4000UL
561 #define ACL_PRIV_INVALID 0x0UL
563 #define ACL_PRIV_ISSET(m,p) (((m) & (p)) == (p))
564 #define ACL_PRIV_ASSIGN(m,p) do { (m) = (p); } while(0)
565 #define ACL_PRIV_SET(m,p) do { (m) |= (p); } while(0)
566 #define ACL_PRIV_CLR(m,p) do { (m) &= ~(p); } while(0)
568 #define ACL_INIT(m) ACL_PRIV_ASSIGN(m, ACL_PRIV_NONE)
569 #define ACL_INVALIDATE(m) ACL_PRIV_ASSIGN(m, ACL_PRIV_INVALID)
571 #define ACL_GRANT(m,a) ACL_PRIV_ISSET((m),ACL_ACCESS2PRIV(a))
573 #define ACL_IS_INVALID(m) ((m) == ACL_PRIV_INVALID)
575 #define ACL_IS_LEVEL(m) ACL_PRIV_ISSET((m),ACL_PRIV_LEVEL)
576 #define ACL_IS_ADDITIVE(m) ACL_PRIV_ISSET((m),ACL_PRIV_ADDITIVE)
577 #define ACL_IS_SUBTRACTIVE(m) ACL_PRIV_ISSET((m),ACL_PRIV_SUBSTRACTIVE)
579 #define ACL_LVL_NONE (ACL_PRIV_NONE|ACL_PRIV_LEVEL)
580 #define ACL_LVL_AUTH (ACL_PRIV_AUTH|ACL_LVL_NONE)
581 #define ACL_LVL_COMPARE (ACL_PRIV_COMPARE|ACL_LVL_AUTH)
582 #define ACL_LVL_SEARCH (ACL_PRIV_SEARCH|ACL_LVL_COMPARE)
583 #define ACL_LVL_READ (ACL_PRIV_READ|ACL_LVL_SEARCH)
584 #define ACL_LVL_WRITE (ACL_PRIV_WRITE|ACL_LVL_READ)
586 #define ACL_LVL(m,l) (((m)&ACL_PRIV_MASK) == ((l)&ACL_PRIV_MASK))
587 #define ACL_LVL_IS_NONE(m) ACL_LVL((m),ACL_LVL_NONE)
588 #define ACL_LVL_IS_AUTH(m) ACL_LVL((m),ACL_LVL_AUTH)
589 #define ACL_LVL_IS_COMPARE(m) ACL_LVL((m),ACL_LVL_COMPARE)
590 #define ACL_LVL_IS_SEARCH(m) ACL_LVL((m),ACL_LVL_SEARCH)
591 #define ACL_LVL_IS_READ(m) ACL_LVL((m),ACL_LVL_READ)
592 #define ACL_LVL_IS_WRITE(m) ACL_LVL((m),ACL_LVL_WRITE)
594 #define ACL_LVL_ASSIGN_NONE(m) ACL_PRIV_ASSIGN((m),ACL_LVL_NONE)
595 #define ACL_LVL_ASSIGN_AUTH(m) ACL_PRIV_ASSIGN((m),ACL_LVL_AUTH)
596 #define ACL_LVL_ASSIGN_COMPARE(m) ACL_PRIV_ASSIGN((m),ACL_LVL_COMPARE)
597 #define ACL_LVL_ASSIGN_SEARCH(m) ACL_PRIV_ASSIGN((m),ACL_LVL_SEARCH)
598 #define ACL_LVL_ASSIGN_READ(m) ACL_PRIV_ASSIGN((m),ACL_LVL_READ)
599 #define ACL_LVL_ASSIGN_WRITE(m) ACL_PRIV_ASSIGN((m),ACL_LVL_WRITE)
601 slap_access_mask_t a_mask;
604 #ifdef SLAPD_SCHEMA_NOT_COMPAT
605 AttributeDescription *a_dn_at;
611 char *a_peername_pat;
612 char *a_sockname_pat;
617 #ifdef SLAPD_ACI_ENABLED
618 #ifdef SLAPD_SCHEMA_NOT_COMPAT
619 AttributeDescription *a_aci_at;
628 #ifdef SLAPD_SCHEMA_NOT_COMPAT
629 AttributeDescription *a_group_at;
634 struct slap_access *a_next;
638 typedef struct slap_acl {
639 /* "to" part: the entries this acl applies to */
645 /* "by" part: list of who has what access to the entries */
648 struct slap_acl *acl_next;
652 * replog moddn param structure
654 struct replog_moddn {
662 * represents a backend
665 typedef struct slap_backend_info BackendInfo; /* per backend type */
666 typedef struct slap_backend_db BackendDB; /* per backend database */
668 LIBSLAPD_F (int) nBackendInfo;
669 LIBSLAPD_F (int) nBackendDB;
670 LIBSLAPD_F (BackendInfo *) backendInfo;
671 LIBSLAPD_F (BackendDB *) backendDB;
673 LIBSLAPD_F (int) slapMode;
674 #define SLAP_UNDEFINED_MODE 0x0000
675 #define SLAP_SERVER_MODE 0x0001
676 #define SLAP_TOOL_MODE 0x0002
677 #define SLAP_MODE 0x0003
679 #define SLAP_TRUNCATE_MODE 0x0100
681 #define SLAP_TIMED_MODE 0x1000
683 #define SLAP_TOOLID_MODE 4
685 /* temporary aliases */
686 typedef BackendDB Backend;
687 #define nbackends nBackendDB
688 #define backends backendDB
690 struct slap_backend_db {
691 BackendInfo *bd_info; /* pointer to shared backend info */
693 /* BackendInfo accessors */
694 #define be_config bd_info->bi_db_config
695 #define be_type bd_info->bi_type
697 #define be_bind bd_info->bi_op_bind
698 #define be_unbind bd_info->bi_op_unbind
699 #define be_add bd_info->bi_op_add
700 #define be_compare bd_info->bi_op_compare
701 #define be_delete bd_info->bi_op_delete
702 #define be_modify bd_info->bi_op_modify
703 #define be_modrdn bd_info->bi_op_modrdn
704 #define be_search bd_info->bi_op_search
706 #define be_extended bd_info->bi_extended
708 #define be_release bd_info->bi_entry_release_rw
709 #define be_group bd_info->bi_acl_group
711 #define be_controls bd_info->bi_controls
713 #define be_connection_init bd_info->bi_connection_init
714 #define be_connection_destroy bd_info->bi_connection_destroy
717 #define be_entry_open bd_info->bi_tool_entry_open
718 #define be_entry_close bd_info->bi_tool_entry_close
719 #define be_entry_first bd_info->bi_tool_entry_first
720 #define be_entry_next bd_info->bi_tool_entry_next
721 #define be_entry_get bd_info->bi_tool_entry_get
722 #define be_entry_put bd_info->bi_tool_entry_put
723 #define be_index_attr bd_info->bi_tool_index_attr
724 #define be_index_change bd_info->bi_tool_index_change
725 #define be_sync bd_info->bi_tool_sync
728 #ifdef HAVE_CYRUS_SASL
729 #define be_sasl_authorize bd_info->bi_sasl_authorize
730 #define be_sasl_getsecret bd_info->bi_sasl_getsecret
731 #define be_sasl_putsecret bd_info->bi_sasl_putsecret
734 /* these should be renamed from be_ to bd_ */
735 char **be_suffix; /* the DN suffixes of data in this backend */
736 char **be_nsuffix; /* the normalized DN suffixes in this backend */
737 char **be_suffixAlias; /* pairs of DN suffix aliases and deref values */
738 char *be_root_dn; /* the magic "root" dn for this db */
739 char *be_root_ndn; /* the magic "root" normalized dn for this db */
740 struct berval be_root_pw; /* the magic "root" password for this db */
741 int be_readonly; /* 1 => db is in "read only" mode */
742 unsigned int be_max_deref_depth; /* limit for depth of an alias deref */
743 int be_sizelimit; /* size limit for this backend */
744 int be_timelimit; /* time limit for this backend */
745 AccessControl *be_acl; /* access control list for this backend */
746 slap_access_t be_dfltaccess; /* access given if no acl matches */
747 char **be_replica; /* replicas of this backend (in master) */
748 char *be_replogfile; /* replication log file (in master) */
749 char *be_update_ndn; /* allowed to make changes (in replicas) */
750 struct berval **be_update_refs; /* where to refer modifying clients to */
751 int be_lastmod; /* keep track of lastmodified{by,time} */
755 void *be_private; /* anything the backend database needs */
761 typedef int (*SLAP_EXTENDED_FN) LDAP_P((
763 struct slap_conn *conn,
766 struct berval * reqdata,
768 struct berval ** rspdata,
769 LDAPControl *** rspctrls,
771 struct berval *** refs ));
773 struct slap_backend_info {
774 char *bi_type; /* type of backend */
777 * per backend type routines:
778 * bi_init: called to allocate a backend_info structure,
779 * called once BEFORE configuration file is read.
780 * bi_init() initializes this structure hence is
781 * called directly from be_initialize()
782 * bi_config: called per 'backend' specific option
783 * all such options must before any 'database' options
784 * bi_config() is called only from read_config()
785 * bi_open: called to open each database, called
786 * once AFTER configuration file is read but
787 * BEFORE any bi_db_open() calls.
788 * bi_open() is called from backend_startup()
789 * bi_close: called to close each database, called
790 * once during shutdown after all bi_db_close calls.
791 * bi_close() is called from backend_shutdown()
792 * bi_destroy: called to destroy each database, called
793 * once during shutdown after all bi_db_destroy calls.
794 * bi_destory() is called from backend_destroy()
796 int (*bi_init) LDAP_P((BackendInfo *bi));
797 int (*bi_config) LDAP_P((BackendInfo *bi,
798 const char *fname, int lineno, int argc, char **argv ));
799 int (*bi_open) LDAP_P((BackendInfo *bi));
800 int (*bi_close) LDAP_P((BackendInfo *bi));
801 int (*bi_destroy) LDAP_P((BackendInfo *bi));
804 * per database routines:
805 * bi_db_init: called to initialize each database,
806 * called upon reading 'database <type>'
807 * called only from backend_db_init()
808 * bi_db_config: called to configure each database,
809 * called per database to handle per database options
810 * called only from read_config()
811 * bi_db_open: called to open each database
812 * called once per database immediately AFTER bi_open()
813 * calls but before daemon startup.
814 * called only by backend_startup()
815 * bi_db_close: called to close each database
816 * called once per database during shutdown but BEFORE
818 * called only by backend_shutdown()
819 * bi_db_destroy: called to destroy each database
820 * called once per database during shutdown AFTER all
821 * bi_close calls but before bi_destory calls.
822 * called only by backend_destory()
824 int (*bi_db_init) LDAP_P((Backend *bd));
825 int (*bi_db_config) LDAP_P((Backend *bd,
826 const char *fname, int lineno, int argc, char **argv ));
827 int (*bi_db_open) LDAP_P((Backend *bd));
828 int (*bi_db_close) LDAP_P((Backend *bd));
829 int (*bi_db_destroy) LDAP_P((Backend *db));
831 /* LDAP Operations Handling Routines */
832 int (*bi_op_bind) LDAP_P(( BackendDB *bd,
833 struct slap_conn *c, struct slap_op *o,
834 char *dn, char *ndn, int method, char* mechanism,
835 struct berval *cred, char** edn ));
836 int (*bi_op_unbind) LDAP_P((BackendDB *bd,
837 struct slap_conn *c, struct slap_op *o ));
838 int (*bi_op_search) LDAP_P((BackendDB *bd,
839 struct slap_conn *c, struct slap_op *o,
840 char *base, char *nbase, int scope, int deref,
841 int slimit, int tlimit,
842 Filter *f, char *filterstr, char **attrs,
844 #ifdef SLAPD_SCHEMA_NOT_COMPAT
845 int (*bi_op_compare)LDAP_P((BackendDB *bd,
846 struct slap_conn *c, struct slap_op *o,
847 char *dn, char *ndn, AttributeAssertion *ava));
849 int (*bi_op_compare)LDAP_P((BackendDB *bd,
850 struct slap_conn *c, struct slap_op *o,
851 char *dn, char *ndn, Ava *ava));
853 int (*bi_op_modify) LDAP_P((BackendDB *bd,
854 struct slap_conn *c, struct slap_op *o,
855 char *dn, char *ndn, Modifications *m));
856 int (*bi_op_modrdn) LDAP_P((BackendDB *bd,
857 struct slap_conn *c, struct slap_op *o,
858 char *dn, char *ndn, char *newrdn, int deleteoldrdn,
860 int (*bi_op_add) LDAP_P((BackendDB *bd,
861 struct slap_conn *c, struct slap_op *o,
863 int (*bi_op_delete) LDAP_P((BackendDB *bd,
864 struct slap_conn *c, struct slap_op *o,
865 char *dn, char *ndn));
866 int (*bi_op_abandon) LDAP_P((BackendDB *bd,
867 struct slap_conn *c, struct slap_op *o,
870 /* Extended Operations Helper */
871 SLAP_EXTENDED_FN bi_extended;
873 /* Auxilary Functions */
874 int (*bi_entry_release_rw) LDAP_P((BackendDB *bd, Entry *e, int rw));
876 #ifdef SLAPD_SCHEMA_NOT_COMPAT
877 int (*bi_acl_group) LDAP_P((Backend *bd,
878 Entry *e, const char *bdn, const char *edn,
879 const char *objectclassValue,
880 AttributeDescription *group_at ));
882 int (*bi_acl_group) LDAP_P((Backend *bd,
883 Entry *e, const char *bdn, const char *edn,
884 const char *objectclassValue,
885 const char *group_at ));
888 int (*bi_connection_init) LDAP_P((BackendDB *bd,
889 struct slap_conn *c));
890 int (*bi_connection_destroy) LDAP_P((BackendDB *bd,
891 struct slap_conn *c));
893 /* hooks for slap tools */
894 int (*bi_tool_entry_open) LDAP_P(( BackendDB *be, int mode ));
895 int (*bi_tool_entry_close) LDAP_P(( BackendDB *be ));
896 ID (*bi_tool_entry_first) LDAP_P(( BackendDB *be ));
897 ID (*bi_tool_entry_next) LDAP_P(( BackendDB *be ));
898 Entry* (*bi_tool_entry_get) LDAP_P(( BackendDB *be, ID id ));
899 ID (*bi_tool_entry_put) LDAP_P(( BackendDB *be, Entry *e ));
900 int (*bi_tool_index_attr) LDAP_P(( BackendDB *be, char* type ));
901 int (*bi_tool_index_change) LDAP_P(( BackendDB *be, char* type,
902 struct berval **bv, ID id, int op ));
903 int (*bi_tool_sync) LDAP_P(( BackendDB *be ));
905 #ifdef HAVE_CYRUS_SASL
906 int (*bi_sasl_authorize) LDAP_P(( BackendDB *be,
907 const char *authnid, const char *authzid,
908 const char **canon_authzid, const char **errstr ));
909 int (*bi_sasl_getsecret) LDAP_P(( BackendDB *be,
910 const char *mechanism, const char *authzid,
911 const char *realm, sasl_secret_t **secret ));
912 int (*bi_sasl_putsecret) LDAP_P(( BackendDB *be,
913 const char *mechanism, const char *auth_identity,
914 const char *realm, const sasl_secret_t *secret ));
915 #endif /* HAVE_CYRUS_SASL */
917 #define SLAP_INDEX_ADD_OP 0x0001
918 #define SLAP_INDEX_DELETE_OP 0x0002
920 char **bi_controls; /* supported controls */
922 unsigned int bi_nDB; /* number of databases of this type */
923 void *bi_private; /* anything the backend type needs */
927 * represents an operation pending from an ldap client
930 typedef struct slap_op {
931 ber_int_t o_opid; /* id of this operation */
932 ber_int_t o_msgid; /* msgid of the request */
934 ldap_pvt_thread_t o_tid; /* thread handling this op */
936 BerElement *o_ber; /* ber of the request */
938 ber_tag_t o_tag; /* tag of the request */
939 time_t o_time; /* time op was initiated */
941 int o_bind_in_progress; /* multi-step bind in progress */
943 /* should only be used for reporting purposes */
944 char *o_authc_dn; /* authentication DN */
946 /* should be used as the DN of the User */
947 char *o_authz_dn; /* authorization DN */
948 char *o_authz_ndn; /* authorizaiton NDN */
951 char *o_dn; /* dn bound when op was initiated */
952 char *o_ndn; /* normalized dn bound when op was initiated */
955 ber_int_t o_protocol; /* version of the LDAP protocol used by client */
956 ber_tag_t o_authtype; /* auth method used to bind dn */
957 /* values taken from ldap.h */
959 char *o_authmech; /* SASL mechanism used to bind dn */
961 LDAPControl **o_ctrls; /* controls */
963 unsigned long o_connid; /* id of conn initiating this op */
965 #ifdef LDAP_CONNECTIONLESS
966 int o_cldap; /* != 0 if this came in via CLDAP */
967 struct sockaddr o_clientaddr; /* client address if via CLDAP */
968 char o_searchbase; /* search base if via CLDAP */
971 ldap_pvt_thread_mutex_t o_abandonmutex; /* protects o_abandon */
972 int o_abandon; /* abandon flag */
974 struct slap_op *o_next; /* next operation in list */
975 void *o_private; /* anything the backend needs */
979 * represents a connection from an ldap client
982 typedef struct slap_conn {
983 int c_struct_state; /* structure management state */
984 int c_conn_state; /* connection state */
986 ldap_pvt_thread_mutex_t c_mutex; /* protect the connection */
987 Sockbuf *c_sb; /* ber connection stuff */
989 /* only can be changed by connect_init */
990 time_t c_starttime; /* when the connection was opened */
991 time_t c_activitytime; /* when the connection was last used */
992 unsigned long c_connid; /* id of this connection for stats*/
994 char *c_listener_url; /* listener URL */
995 char *c_peer_domain; /* DNS name of client */
996 char *c_peer_name; /* peer name (trans=addr:port) */
997 char *c_sock_name; /* sock name (trans=addr:port) */
999 /* only can be changed by binding thread */
1000 int c_bind_in_progress; /* multi-op bind in progress */
1001 #ifdef HAVE_CYRUS_SASL
1002 sasl_conn_t *c_sasl_context;
1004 void *c_authstate; /* SASL state data */
1006 Backend *c_authc_backend;
1008 /* authorization backend */
1009 Backend *c_authz_backend;
1012 /* authentication backend */
1013 /* should only be used for reporting purposes */
1014 char *c_authc_dn; /* authentication DN */
1016 /* should be used as the DN of the User */
1017 char *c_authz_dn; /* authorization DN */
1018 char *c_authz_ndn; /* authorization NDN */
1021 char *c_cdn; /* DN provided by the client */
1022 char *c_dn; /* DN bound to this conn */
1025 ber_int_t c_protocol; /* version of the LDAP protocol used by client */
1026 ber_tag_t c_authtype;/* auth method used to bind c_dn */
1027 char *c_authmech; /* SASL mechanism used to bind c_dn */
1029 Operation *c_ops; /* list of operations being processed */
1030 Operation *c_pending_ops; /* list of pending operations */
1032 ldap_pvt_thread_mutex_t c_write_mutex; /* only one pdu written at a time */
1033 ldap_pvt_thread_cond_t c_write_cv; /* used to wait for sd write-ready*/
1035 BerElement *c_currentber; /* ber we're attempting to read */
1036 int c_writewaiter; /* true if writer is waiting */
1039 int c_is_tls; /* true if this LDAP over raw TLS */
1040 int c_needs_tls_accept; /* true if SSL_accept should be called */
1043 long c_n_ops_received; /* num of ops received (next op_id) */
1044 long c_n_ops_executing; /* num of ops currently executing */
1045 long c_n_ops_pending; /* num of ops pending execution */
1046 long c_n_ops_completed; /* num of ops completed */
1048 long c_n_get; /* num of get calls */
1049 long c_n_read; /* num of read calls */
1050 long c_n_write; /* num of write calls */
1053 #if defined(LDAP_SYSLOG) && defined(LDAP_DEBUG)
1054 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 ) \
1056 if ( ldap_debug & (level) ) \
1057 fprintf( stderr, (fmt), (connid), (opid), (arg1), (arg2), (arg3) );\
1058 if ( ldap_syslog & (level) ) \
1059 syslog( ldap_syslog_level, (fmt), (connid), (opid), (arg1), \
1063 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 )
1068 #include "proto-slap.h"
1070 #endif /* _slap_h_ */