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 #ifndef SLAPD_SCHEMA_NOT_COMPAT
12 #define SLAPD_SCHEMA_COMPAT 1
15 #include "ldap_defaults.h"
17 #include <ac/stdlib.h>
19 #include <sys/types.h>
20 #include <ac/syslog.h>
22 #include <ac/socket.h>
26 #ifdef HAVE_CYRUS_SASL
33 #define ldap_debug slap_debug
40 #include <ldap_schema.h>
42 #include "ldap_pvt_thread.h"
48 #undef f_next /* name conflict between sys/file.h on SCO and struct filter */
51 #define SERVICE_NAME OPENLDAP_PACKAGE "-slapd"
53 /* LDAPMod.mod_op value ===> Must be kept in sync with ldap.h!
55 * This is a value used internally by the backends. It is needed to allow
56 * adding values that already exist without getting an error as required by
57 * modrdn when the new rdn was already an attribute value itself.
58 * JCG 05/1999 (gomez@engr.sgi.com)
60 #define LDAP_MOD_SOFTADD 0x1000
66 #define MAXREMATCHES 10
68 /* psuedo error code to indicating abandoned operation */
69 #define SLAPD_ABANDON -1
71 /* XXYYZ: these macros assume 'x' is an ASCII x */
72 #define DNSEPARATOR(c) ((c) == ',' || (c) == ';')
73 #define SEPARATOR(c) ((c) == ',' || (c) == ';' || (c) == '+')
74 #define SPACE(c) ((c) == ' ' || (c) == '\n')
76 #define ASCII_LOWER(c) ( (c) >= 'a' && (c) <= 'z' )
77 #define ASCII_UPPER(c) ( (c) >= 'A' && (c) <= 'Z' )
78 #define ASCII_ALPHA(c) ( ASCII_LOWER(c) || ASCII_UPPER(c) )
79 #define ASCII_DIGIT(c) ( (c) >= '0' && (c) <= '9' )
80 #define ASCII_ALNUM(c) ( ASCII_ALPHA(c) || ASCII_DIGIT(c) )
82 #define LEADKEYCHAR(c) ( ASCII_ALPHA(c) )
83 #define KEYCHAR(c) ( ASCII_ALNUM(c) || (c) == '-' )
84 #define LEADOIDCHAR(c) ( ASCII_DIGIT(c) )
85 #define OIDCHAR(c) ( ASCII_DIGIT(c) || (c) == '.' )
87 #define LEADATTRCHAR(c) ( LEADKEYCHAR(c) || LEADOIDCHAR(c) )
88 #define ATTRCHAR(c) ( KEYCHAR((c)) || (c) == '.' )
90 #define NEEDSESCAPE(c) ((c) == '\\' || (c) == '"')
92 #define SLAPD_ACI_DEFAULT_ATTR "aci"
94 /* schema needed by slapd */
95 #define SLAPD_OID_DN_SYNTAX "1.3.6.1.4.1.1466.115.121.1.12"
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 {
130 struct slap_oid_macro *som_next;
133 /* forward declarations */
135 struct slap_matching_rule;
138 typedef int slap_syntax_validate_func LDAP_P((
139 struct slap_syntax *syntax,
140 struct berval * in));
142 typedef int slap_syntax_transform_func LDAP_P((
143 struct slap_syntax *syntax,
145 struct berval ** out));
147 typedef struct slap_syntax {
148 LDAP_SYNTAX ssyn_syn;
151 #define SLAP_SYNTAX_NONE 0
152 #define SLAP_SYNTAX_BINARY 1
154 slap_syntax_validate_func *ssyn_validate;
156 /* convert to and from binary */
157 slap_syntax_transform_func *ssyn_ber2str;
158 slap_syntax_transform_func *ssyn_str2ber;
160 struct slap_syntax *ssyn_next;
161 #define ssyn_oid ssyn_syn.syn_oid
162 #define ssyn_desc ssyn_syn.syn_desc
165 /* XXX -> UCS-2 Converter */
166 typedef int slap_mr_convert_func LDAP_P((
168 struct berval ** out ));
171 typedef int slap_mr_normalize_func LDAP_P((
172 struct slap_syntax *syntax, /* NULL if in is asserted value */
173 struct slap_matching_rule *mr,
175 struct berval ** out ));
177 /* Match (compare) function */
178 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 struct berval * assertValue ));
184 /* Index generation function */
185 typedef int slap_mr_indexer_func LDAP_P((
186 struct slap_syntax *syntax, /* syntax of stored value */
187 struct slap_matching_rule *mr,
188 struct berval **values,
189 struct berval **keys ));
191 struct slap_filter; /* forward declaration */
192 /* Filter index function */
193 typedef int slap_mr_filter_func LDAP_P((
194 struct slap_syntax *syntax, /* syntax of stored value */
195 struct slap_matching_rule *mr,
196 struct slap_filter *filter,
197 struct berval **keys ));
199 typedef struct slap_matching_rule {
200 LDAP_MATCHING_RULE smr_mrule;
202 slap_mr_convert_func *smr_convert;
203 slap_mr_normalize_func *smr_normalize;
204 slap_mr_match_func *smr_match;
205 slap_mr_indexer_func *smr_indexer;
206 slap_mr_filter_func *smr_filter;
207 struct slap_matching_rule *smr_next;
208 #define smr_oid smr_mrule.mr_oid
209 #define smr_names smr_mrule.mr_names
210 #define smr_desc smr_mrule.mr_desc
211 #define smr_obsolete smr_mrule.mr_obsolete
212 #define smr_syntax_oid smr_mrule.mr_syntax_oid
215 typedef struct slap_attribute_type {
216 LDAP_ATTRIBUTE_TYPE sat_atype;
217 struct slap_attribute_type *sat_sup;
218 struct slap_attribute_type **sat_subtypes;
219 MatchingRule *sat_equality;
220 MatchingRule *sat_ordering;
221 MatchingRule *sat_substr;
223 /* The next one is created to help in the transition */
224 int sat_syntax_compat;
225 struct slap_attribute_type *sat_next;
226 #define sat_oid sat_atype.at_oid
227 #define sat_names sat_atype.at_names
228 #define sat_desc sat_atype.at_desc
229 #define sat_obsolete sat_atype.at_obsolete
230 #define sat_sup_oid sat_atype.at_sup_oid
231 #define sat_equality_oid sat_atype.at_equality_oid
232 #define sat_ordering_oid sat_atype.at_ordering_oid
233 #define sat_substr_oid sat_atype.at_substr_oid
234 #define sat_syntax_oid sat_atype.at_syntax_oid
235 #define sat_single_value sat_atype.at_single_value
236 #define sat_collective sat_atype.at_collective
237 #define sat_no_user_mod sat_atype.at_no_user_mod
238 #define sat_usage sat_atype.at_usage
241 typedef struct slap_object_class {
242 LDAP_OBJECT_CLASS soc_oclass;
243 struct slap_object_class **soc_sups;
244 AttributeType **soc_required;
245 AttributeType **soc_allowed;
246 struct slap_object_class *soc_next;
247 #define soc_oid soc_oclass.oc_oid
248 #define soc_names soc_oclass.oc_names
249 #define soc_desc soc_oclass.oc_desc
250 #define soc_obsolete soc_oclass.oc_obsolete
251 #define soc_sup_oids soc_oclass.oc_sup_oids
252 #define soc_kind soc_oclass.oc_kind
253 #define soc_at_oids_must soc_oclass.oc_at_oids_must
254 #define soc_at_oids_may soc_oclass.oc_at_oids_may
261 struct replog_moddn {
268 * represents an attribute value assertion (i.e., attr;option=value)
270 typedef struct slap_ava {
271 char *ava_type; /* attribute description */
272 struct berval ava_value;
276 * represents an matching rule assertion
278 typedef struct slap_mra {
279 char *mra_rule; /* optional */
280 char *mra_type; /* attribute description -- optional */
282 struct berval *mra_value;
286 * represents a search filter
288 typedef struct slap_filter {
289 ber_tag_t f_choice; /* values taken from ldap.h */
295 /* equality, lessorequal, greaterorequal, approx */
302 struct slap_filter *f_un_complex;
308 struct berval *f_un_sub_initial;
309 struct berval **f_un_sub_any;
310 struct berval *f_un_sub_final;
314 #define f_dn f_un.f_un_type /* used for DN indices */
315 #define f_type f_un.f_un_type
316 #define f_ava f_un.f_un_ava
317 #define f_avtype f_un.f_un_ava.ava_type
318 #define f_avvalue f_un.f_un_ava.ava_value
319 #define f_mra f_un.f_un_mra
320 #define f_mrtype f_un.f_un_mra.mra_type
321 #define f_mrvalue f_un.f_un_mra.mra_value
322 #define f_mrdnaddrs f_un.f_un_mra.mra_dnattrs
323 #define f_and f_un.f_un_complex
324 #define f_or f_un.f_un_complex
325 #define f_not f_un.f_un_complex
326 #define f_list f_un.f_un_complex
327 #define f_sub f_un.f_un_sub
328 #define f_sub_type f_un.f_un_sub.f_un_sub_type
329 #define f_sub_initial f_un.f_un_sub.f_un_sub_initial
330 #define f_sub_any f_un.f_un_sub.f_un_sub_any
331 #define f_sub_final f_un.f_un_sub.f_un_sub_final
333 struct slap_filter *f_next;
337 * represents an attribute (type + values + syntax)
339 typedef struct slap_attr {
340 char *a_type; /* description */
341 struct berval **a_vals;
342 #ifdef SLAPD_SCHEMA_COMPAT
345 struct slap_attr *a_next;
348 #ifdef SLAPD_SCHEMA_COMPAT
350 * the attr_syntax() routine returns one of these values
351 * telling what kind of syntax an attribute supports.
353 #define SYNTAX_CIS 0x01 /* case insensitive string */
354 #define SYNTAX_CES 0x02 /* case sensitive string */
355 #define SYNTAX_BIN 0x04 /* binary data */
356 #define SYNTAX_TEL 0x08 /* telephone number string */
357 #define SYNTAX_DN 0x10 /* dn string */
361 * the id used in the indexes to refer to an entry
363 typedef unsigned long ID;
364 #define NOID ((ID)~0)
367 * represents an entry in core
369 typedef struct slap_entry {
371 * The ID field should only be changed before entry is
372 * inserted into a cache. The ID value is backend
377 char *e_dn; /* DN of this entry */
378 char *e_ndn; /* normalized DN of this entry */
379 Attribute *e_attrs; /* list of attributes + values */
381 /* for use by the backend for any purpose */
386 * represents an access control list
389 typedef enum slap_access_e {
390 ACL_INVALID_ACCESS = -1,
399 typedef enum slap_control_e {
400 ACL_INVALID_CONTROL = 0,
406 typedef unsigned long slap_access_mask_t;
409 typedef struct slap_access {
410 slap_control_t a_type;
412 #define ACL_ACCESS2PRIV(access) (0x01U << (access))
414 #define ACL_PRIV_NONE ACL_ACCESS2PRIV( ACL_NONE )
415 #define ACL_PRIV_AUTH ACL_ACCESS2PRIV( ACL_AUTH )
416 #define ACL_PRIV_COMPARE ACL_ACCESS2PRIV( ACL_COMPARE )
417 #define ACL_PRIV_SEARCH ACL_ACCESS2PRIV( ACL_SEARCH )
418 #define ACL_PRIV_READ ACL_ACCESS2PRIV( ACL_READ )
419 #define ACL_PRIV_WRITE ACL_ACCESS2PRIV( ACL_WRITE )
421 #define ACL_PRIV_MASK 0x00ffUL
424 #define ACL_PRIV_LEVEL 0x1000UL
425 #define ACL_PRIV_ADDITIVE 0x2000UL
426 #define ACL_PRIV_SUBSTRACTIVE 0x4000UL
429 #define ACL_PRIV_INVALID 0x0UL
431 #define ACL_PRIV_ISSET(m,p) (((m) & (p)) == (p))
432 #define ACL_PRIV_ASSIGN(m,p) do { (m) = (p); } while(0)
433 #define ACL_PRIV_SET(m,p) do { (m) |= (p); } while(0)
434 #define ACL_PRIV_CLR(m,p) do { (m) &= ~(p); } while(0)
436 #define ACL_INIT(m) ACL_PRIV_ASSIGN(m, ACL_PRIV_NONE)
437 #define ACL_INVALIDATE(m) ACL_PRIV_ASSIGN(m, ACL_PRIV_INVALID)
439 #define ACL_GRANT(m,a) ACL_PRIV_ISSET((m),ACL_ACCESS2PRIV(a))
441 #define ACL_IS_INVALID(m) ((m) == ACL_PRIV_INVALID)
443 #define ACL_IS_LEVEL(m) ACL_PRIV_ISSET((m),ACL_PRIV_LEVEL)
444 #define ACL_IS_ADDITIVE(m) ACL_PRIV_ISSET((m),ACL_PRIV_ADDITIVE)
445 #define ACL_IS_SUBTRACTIVE(m) ACL_PRIV_ISSET((m),ACL_PRIV_SUBSTRACTIVE)
447 #define ACL_LVL_NONE (ACL_PRIV_NONE|ACL_PRIV_LEVEL)
448 #define ACL_LVL_AUTH (ACL_PRIV_AUTH|ACL_LVL_NONE)
449 #define ACL_LVL_COMPARE (ACL_PRIV_COMPARE|ACL_LVL_AUTH)
450 #define ACL_LVL_SEARCH (ACL_PRIV_SEARCH|ACL_LVL_COMPARE)
451 #define ACL_LVL_READ (ACL_PRIV_READ|ACL_LVL_SEARCH)
452 #define ACL_LVL_WRITE (ACL_PRIV_WRITE|ACL_LVL_READ)
454 #define ACL_LVL(m,l) (((m)&ACL_PRIV_MASK) == ((l)&ACL_PRIV_MASK))
455 #define ACL_LVL_IS_NONE(m) ACL_LVL((m),ACL_LVL_NONE)
456 #define ACL_LVL_IS_AUTH(m) ACL_LVL((m),ACL_LVL_AUTH)
457 #define ACL_LVL_IS_COMPARE(m) ACL_LVL((m),ACL_LVL_COMPARE)
458 #define ACL_LVL_IS_SEARCH(m) ACL_LVL((m),ACL_LVL_SEARCH)
459 #define ACL_LVL_IS_READ(m) ACL_LVL((m),ACL_LVL_READ)
460 #define ACL_LVL_IS_WRITE(m) ACL_LVL((m),ACL_LVL_WRITE)
462 #define ACL_LVL_ASSIGN_NONE(m) ACL_PRIV_ASSIGN((m),ACL_LVL_NONE)
463 #define ACL_LVL_ASSIGN_AUTH(m) ACL_PRIV_ASSIGN((m),ACL_LVL_AUTH)
464 #define ACL_LVL_ASSIGN_COMPARE(m) ACL_PRIV_ASSIGN((m),ACL_LVL_COMPARE)
465 #define ACL_LVL_ASSIGN_SEARCH(m) ACL_PRIV_ASSIGN((m),ACL_LVL_SEARCH)
466 #define ACL_LVL_ASSIGN_READ(m) ACL_PRIV_ASSIGN((m),ACL_LVL_READ)
467 #define ACL_LVL_ASSIGN_WRITE(m) ACL_PRIV_ASSIGN((m),ACL_LVL_WRITE)
469 slap_access_mask_t a_mask;
472 #ifdef SLAPD_SCHEMA_COMPAT
475 AttributeType *a_dn_at;
479 char *a_peername_pat;
480 char *a_sockname_pat;
485 #ifdef SLAPD_ACI_ENABLED
486 #ifdef SLAPD_SCHEMA_COMPAT
489 AttributeType *a_aci_at;
496 #ifdef SLAPD_SCHEMA_COMPAT
499 AttributeType *a_group_at;
502 struct slap_access *a_next;
506 typedef struct slap_acl {
507 /* "to" part: the entries this acl applies to */
513 /* "by" part: list of who has what access to the entries */
516 struct slap_acl *acl_next;
522 typedef struct ldapmodlist {
523 struct ldapmod ml_mod;
524 struct ldapmodlist *ml_next;
525 #define ml_op ml_mod.mod_op
526 #define ml_type ml_mod.mod_type
527 #define ml_values ml_mod.mod_values
528 #define ml_bvalues ml_mod.mod_bvalues
533 * represents a backend
536 typedef struct slap_backend_info BackendInfo; /* per backend type */
537 typedef struct slap_backend_db BackendDB; /* per backend database */
539 LIBSLAPD_F (int) nBackendInfo;
540 LIBSLAPD_F (int) nBackendDB;
541 LIBSLAPD_F (BackendInfo *) backendInfo;
542 LIBSLAPD_F (BackendDB *) backendDB;
544 LIBSLAPD_F (int) slapMode;
545 #define SLAP_UNDEFINED_MODE 0x0000
546 #define SLAP_SERVER_MODE 0x0001
547 #define SLAP_TOOL_MODE 0x0002
548 #define SLAP_MODE 0x0003
550 #define SLAP_TRUNCATE_MODE 0x0100
552 #define SLAP_TIMED_MODE 0x1000
554 #define SLAP_TOOLID_MODE 4
556 /* temporary aliases */
557 typedef BackendDB Backend;
558 #define nbackends nBackendDB
559 #define backends backendDB
561 struct slap_backend_db {
562 BackendInfo *bd_info; /* pointer to shared backend info */
564 /* BackendInfo accessors */
565 #define be_config bd_info->bi_db_config
566 #define be_type bd_info->bi_type
568 #define be_bind bd_info->bi_op_bind
569 #define be_unbind bd_info->bi_op_unbind
570 #define be_add bd_info->bi_op_add
571 #define be_compare bd_info->bi_op_compare
572 #define be_delete bd_info->bi_op_delete
573 #define be_modify bd_info->bi_op_modify
574 #define be_modrdn bd_info->bi_op_modrdn
575 #define be_search bd_info->bi_op_search
577 #define be_extended bd_info->bi_extended
579 #define be_release bd_info->bi_entry_release_rw
580 #define be_group bd_info->bi_acl_group
582 #define be_controls bd_info->bi_controls
584 #define be_connection_init bd_info->bi_connection_init
585 #define be_connection_destroy bd_info->bi_connection_destroy
588 #define be_entry_open bd_info->bi_tool_entry_open
589 #define be_entry_close bd_info->bi_tool_entry_close
590 #define be_entry_first bd_info->bi_tool_entry_first
591 #define be_entry_next bd_info->bi_tool_entry_next
592 #define be_entry_get bd_info->bi_tool_entry_get
593 #define be_entry_put bd_info->bi_tool_entry_put
594 #define be_index_attr bd_info->bi_tool_index_attr
595 #define be_index_change bd_info->bi_tool_index_change
596 #define be_sync bd_info->bi_tool_sync
599 #ifdef HAVE_CYRUS_SASL
600 #define be_sasl_authorize bd_info->bi_sasl_authorize
601 #define be_sasl_getsecret bd_info->bi_sasl_getsecret
602 #define be_sasl_putsecret bd_info->bi_sasl_putsecret
605 /* these should be renamed from be_ to bd_ */
606 char **be_suffix; /* the DN suffixes of data in this backend */
607 char **be_nsuffix; /* the normalized DN suffixes in this backend */
608 char **be_suffixAlias; /* pairs of DN suffix aliases and deref values */
609 char *be_root_dn; /* the magic "root" dn for this db */
610 char *be_root_ndn; /* the magic "root" normalized dn for this db */
611 struct berval be_root_pw; /* the magic "root" password for this db */
612 int be_readonly; /* 1 => db is in "read only" mode */
613 unsigned int be_max_deref_depth; /* limit for depth of an alias deref */
614 int be_sizelimit; /* size limit for this backend */
615 int be_timelimit; /* time limit for this backend */
616 AccessControl *be_acl; /* access control list for this backend */
617 slap_access_t be_dfltaccess; /* access given if no acl matches */
618 char **be_replica; /* replicas of this backend (in master) */
619 char *be_replogfile; /* replication log file (in master) */
620 char *be_update_ndn; /* allowed to make changes (in replicas) */
621 struct berval **be_update_refs; /* where to refer modifying clients to */
622 int be_lastmod; /* keep track of lastmodified{by,time} */
626 void *be_private; /* anything the backend database needs */
629 typedef int (*SLAP_EXTENDED_FN) LDAP_P((
631 struct slap_conn *conn,
634 struct berval * reqdata,
636 struct berval ** rspdata,
637 LDAPControl *** rspctrls,
639 struct berval *** refs ));
641 struct slap_backend_info {
642 char *bi_type; /* type of backend */
645 * per backend type routines:
646 * bi_init: called to allocate a backend_info structure,
647 * called once BEFORE configuration file is read.
648 * bi_init() initializes this structure hence is
649 * called directly from be_initialize()
650 * bi_config: called per 'backend' specific option
651 * all such options must before any 'database' options
652 * bi_config() is called only from read_config()
653 * bi_open: called to open each database, called
654 * once AFTER configuration file is read but
655 * BEFORE any bi_db_open() calls.
656 * bi_open() is called from backend_startup()
657 * bi_close: called to close each database, called
658 * once during shutdown after all bi_db_close calls.
659 * bi_close() is called from backend_shutdown()
660 * bi_destroy: called to destroy each database, called
661 * once during shutdown after all bi_db_destroy calls.
662 * bi_destory() is called from backend_destroy()
664 int (*bi_init) LDAP_P((BackendInfo *bi));
665 int (*bi_config) LDAP_P((BackendInfo *bi,
666 const char *fname, int lineno, int argc, char **argv ));
667 int (*bi_open) LDAP_P((BackendInfo *bi));
668 int (*bi_close) LDAP_P((BackendInfo *bi));
669 int (*bi_destroy) LDAP_P((BackendInfo *bi));
672 * per database routines:
673 * bi_db_init: called to initialize each database,
674 * called upon reading 'database <type>'
675 * called only from backend_db_init()
676 * bi_db_config: called to configure each database,
677 * called per database to handle per database options
678 * called only from read_config()
679 * bi_db_open: called to open each database
680 * called once per database immediately AFTER bi_open()
681 * calls but before daemon startup.
682 * called only by backend_startup()
683 * bi_db_close: called to close each database
684 * called once per database during shutdown but BEFORE
686 * called only by backend_shutdown()
687 * bi_db_destroy: called to destroy each database
688 * called once per database during shutdown AFTER all
689 * bi_close calls but before bi_destory calls.
690 * called only by backend_destory()
692 int (*bi_db_init) LDAP_P((Backend *bd));
693 int (*bi_db_config) LDAP_P((Backend *bd,
694 const char *fname, int lineno, int argc, char **argv ));
695 int (*bi_db_open) LDAP_P((Backend *bd));
696 int (*bi_db_close) LDAP_P((Backend *bd));
697 int (*bi_db_destroy) LDAP_P((Backend *db));
699 /* LDAP Operations Handling Routines */
700 int (*bi_op_bind) LDAP_P(( BackendDB *bd,
701 struct slap_conn *c, struct slap_op *o,
702 char *dn, char *ndn, int method, char* mechanism,
703 struct berval *cred, char** edn ));
704 int (*bi_op_unbind) LDAP_P((BackendDB *bd,
705 struct slap_conn *c, struct slap_op *o ));
706 int (*bi_op_search) LDAP_P((BackendDB *bd,
707 struct slap_conn *c, struct slap_op *o,
708 char *base, char *nbase, int scope, int deref,
709 int slimit, int tlimit,
710 Filter *f, char *filterstr, char **attrs,
712 int (*bi_op_compare)LDAP_P((BackendDB *bd,
713 struct slap_conn *c, struct slap_op *o,
714 char *dn, char *ndn, Ava *ava));
715 int (*bi_op_modify) LDAP_P((BackendDB *bd,
716 struct slap_conn *c, struct slap_op *o,
717 char *dn, char *ndn, LDAPModList *m));
718 int (*bi_op_modrdn) LDAP_P((BackendDB *bd,
719 struct slap_conn *c, struct slap_op *o,
720 char *dn, char *ndn, char *newrdn, int deleteoldrdn,
722 int (*bi_op_add) LDAP_P((BackendDB *bd,
723 struct slap_conn *c, struct slap_op *o,
725 int (*bi_op_delete) LDAP_P((BackendDB *bd,
726 struct slap_conn *c, struct slap_op *o,
727 char *dn, char *ndn));
728 int (*bi_op_abandon) LDAP_P((BackendDB *bd,
729 struct slap_conn *c, struct slap_op *o,
732 /* Extended Operations Helper */
733 SLAP_EXTENDED_FN bi_extended;
735 /* Auxilary Functions */
736 int (*bi_entry_release_rw) LDAP_P((BackendDB *bd, Entry *e, int rw));
738 #ifdef SLAPD_SCHEMA_NOT_COMPAT
739 int (*bi_acl_group) LDAP_P((Backend *bd,
740 Entry *e, const char *bdn, const char *edn,
741 const char *objectclassValue,
742 AttributeType *group_at ));
744 int (*bi_acl_group) LDAP_P((Backend *bd,
745 Entry *e, const char *bdn, const char *edn,
746 const char *objectclassValue,
747 const char *group_at ));
750 int (*bi_connection_init) LDAP_P((BackendDB *bd,
751 struct slap_conn *c));
752 int (*bi_connection_destroy) LDAP_P((BackendDB *bd,
753 struct slap_conn *c));
755 /* hooks for slap tools */
756 int (*bi_tool_entry_open) LDAP_P(( BackendDB *be, int mode ));
757 int (*bi_tool_entry_close) LDAP_P(( BackendDB *be ));
758 ID (*bi_tool_entry_first) LDAP_P(( BackendDB *be ));
759 ID (*bi_tool_entry_next) LDAP_P(( BackendDB *be ));
760 Entry* (*bi_tool_entry_get) LDAP_P(( BackendDB *be, ID id ));
761 ID (*bi_tool_entry_put) LDAP_P(( BackendDB *be, Entry *e ));
762 int (*bi_tool_index_attr) LDAP_P(( BackendDB *be, char* type ));
763 int (*bi_tool_index_change) LDAP_P(( BackendDB *be, char* type,
764 struct berval **bv, ID id, int op ));
765 int (*bi_tool_sync) LDAP_P(( BackendDB *be ));
767 #ifdef HAVE_CYRUS_SASL
768 int (*bi_sasl_authorize) LDAP_P(( BackendDB *be,
769 const char *authnid, const char *authzid,
770 const char **canon_authzid, const char **errstr ));
771 int (*bi_sasl_getsecret) LDAP_P(( BackendDB *be,
772 const char *mechanism, const char *authzid,
773 const char *realm, sasl_secret_t **secret ));
774 int (*bi_sasl_putsecret) LDAP_P(( BackendDB *be,
775 const char *mechanism, const char *auth_identity,
776 const char *realm, const sasl_secret_t *secret ));
777 #endif /* HAVE_CYRUS_SASL */
779 #define SLAP_INDEX_ADD_OP 0x0001
780 #define SLAP_INDEX_DELETE_OP 0x0002
782 char **bi_controls; /* supported controls */
784 unsigned int bi_nDB; /* number of databases of this type */
785 void *bi_private; /* anything the backend type needs */
789 * represents an operation pending from an ldap client
792 typedef struct slap_op {
793 ber_int_t o_opid; /* id of this operation */
794 ber_int_t o_msgid; /* msgid of the request */
796 ldap_pvt_thread_t o_tid; /* thread handling this op */
798 BerElement *o_ber; /* ber of the request */
800 ber_tag_t o_tag; /* tag of the request */
801 time_t o_time; /* time op was initiated */
803 int o_bind_in_progress; /* multi-step bind in progress */
805 /* should only be used for reporting purposes */
806 char *o_authc_dn; /* authentication DN */
808 /* should be used as the DN of the User */
809 char *o_authz_dn; /* authorization DN */
810 char *o_authz_ndn; /* authorizaiton NDN */
813 char *o_dn; /* dn bound when op was initiated */
814 char *o_ndn; /* normalized dn bound when op was initiated */
817 ber_int_t o_protocol; /* version of the LDAP protocol used by client */
818 ber_tag_t o_authtype; /* auth method used to bind dn */
819 /* values taken from ldap.h */
821 char *o_authmech; /* SASL mechanism used to bind dn */
823 LDAPControl **o_ctrls; /* controls */
825 unsigned long o_connid; /* id of conn initiating this op */
827 #ifdef LDAP_CONNECTIONLESS
828 int o_cldap; /* != 0 if this came in via CLDAP */
829 struct sockaddr o_clientaddr; /* client address if via CLDAP */
830 char o_searchbase; /* search base if via CLDAP */
833 ldap_pvt_thread_mutex_t o_abandonmutex; /* protects o_abandon */
834 int o_abandon; /* abandon flag */
836 struct slap_op *o_next; /* next operation in list */
837 void *o_private; /* anything the backend needs */
841 * represents a connection from an ldap client
844 typedef struct slap_conn {
845 int c_struct_state; /* structure management state */
846 int c_conn_state; /* connection state */
848 ldap_pvt_thread_mutex_t c_mutex; /* protect the connection */
849 Sockbuf *c_sb; /* ber connection stuff */
851 /* only can be changed by connect_init */
852 time_t c_starttime; /* when the connection was opened */
853 time_t c_activitytime; /* when the connection was last used */
854 unsigned long c_connid; /* id of this connection for stats*/
856 char *c_listener_url; /* listener URL */
857 char *c_peer_domain; /* DNS name of client */
858 char *c_peer_name; /* peer name (trans=addr:port) */
859 char *c_sock_name; /* sock name (trans=addr:port) */
861 /* only can be changed by binding thread */
862 int c_bind_in_progress; /* multi-op bind in progress */
863 #ifdef HAVE_CYRUS_SASL
864 sasl_conn_t *c_sasl_context;
866 void *c_authstate; /* SASL state data */
868 Backend *c_authc_backend;
870 /* authorization backend */
871 Backend *c_authz_backend;
874 /* authentication backend */
875 /* should only be used for reporting purposes */
876 char *c_authc_dn; /* authentication DN */
878 /* should be used as the DN of the User */
879 char *c_authz_dn; /* authorization DN */
880 char *c_authz_ndn; /* authorization NDN */
883 char *c_cdn; /* DN provided by the client */
884 char *c_dn; /* DN bound to this conn */
887 ber_int_t c_protocol; /* version of the LDAP protocol used by client */
888 ber_tag_t c_authtype;/* auth method used to bind c_dn */
889 char *c_authmech; /* SASL mechanism used to bind c_dn */
891 Operation *c_ops; /* list of operations being processed */
892 Operation *c_pending_ops; /* list of pending operations */
894 ldap_pvt_thread_mutex_t c_write_mutex; /* only one pdu written at a time */
895 ldap_pvt_thread_cond_t c_write_cv; /* used to wait for sd write-ready*/
897 BerElement *c_currentber; /* ber we're attempting to read */
898 int c_writewaiter; /* true if writer is waiting */
901 int c_is_tls; /* true if this LDAP over raw TLS */
902 int c_needs_tls_accept; /* true if SSL_accept should be called */
905 long c_n_ops_received; /* num of ops received (next op_id) */
906 long c_n_ops_executing; /* num of ops currently executing */
907 long c_n_ops_pending; /* num of ops pending execution */
908 long c_n_ops_completed; /* num of ops completed */
910 long c_n_get; /* num of get calls */
911 long c_n_read; /* num of read calls */
912 long c_n_write; /* num of write calls */
915 #if defined(LDAP_SYSLOG) && defined(LDAP_DEBUG)
916 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 ) \
918 if ( ldap_debug & (level) ) \
919 fprintf( stderr, (fmt), (connid), (opid), (arg1), (arg2), (arg3) );\
920 if ( ldap_syslog & (level) ) \
921 syslog( ldap_syslog_level, (fmt), (connid), (opid), (arg1), \
925 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 )
930 #include "proto-slap.h"
932 #endif /* _slap_h_ */