]> git.sur5r.net Git - openldap/blob - servers/slapd/slap.h
3fbf4b4b1186efc97f2b6afaa6f8dd6e329e5bb5
[openldap] / servers / slapd / slap.h
1 /* slap.h - stand alone ldap server include file */
2 /*
3  * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6
7 #ifndef _SLDAPD_H_
8 #define _SLDAPD_H_
9
10 #include <ac/stdlib.h>
11
12 #include <sys/types.h>
13 #include <ac/syslog.h>
14 #include <ac/regex.h>
15 #include <ac/socket.h>
16 #include <ac/time.h>
17
18 #ifdef HAVE_CYRUS_SASL
19 #include <sasl.h>
20 #endif
21
22 #include "avl.h"
23
24 #ifndef ldap_debug
25 #define ldap_debug slap_debug
26 #endif
27
28
29 #include "ldap_log.h"
30
31 #include <ldap.h>
32 #include <ldap_schema.h>
33
34 #include "ldap_pvt_thread.h"
35 #include "ldif.h"
36
37 LDAP_BEGIN_DECL
38
39 #ifdef f_next
40 #undef f_next /* name conflict between sys/file.h on SCO and struct filter */
41 #endif
42
43 #define SERVICE_NAME  OPENLDAP_PACKAGE "-slapd"
44
45 /* LDAPMod.mod_op value ===> Must be kept in sync with ldap.h!
46  *
47  * This is a value used internally by the backends. It is needed to allow
48  * adding values that already exist without getting an error as required by
49  * modrdn when the new rdn was already an attribute value itself.
50  * JCG 05/1999 (gomez@engr.sgi.com)
51  */
52 #define LDAP_MOD_SOFTADD        0x1000
53
54 #ifdef DNS_DN
55 #define DN_DNS  0
56 #define DN_X500 1
57 #endif
58
59 #define ON      1
60 #define OFF     (-1)
61 #define UNDEFINED 0
62
63 #define MAXREMATCHES 10
64
65 /* XXYYZ: these macros assume 'x' is an ASCII x */
66 #define DNSEPARATOR(c)  ((c) == ',' || (c) == ';')
67 #define SEPARATOR(c)    ((c) == ',' || (c) == ';' || (c) == '+')
68 #define SPACE(c)        ((c) == ' ' || (c) == '\n')
69
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) )
75
76 #define LEADKEYCHAR(c)  ( ASCII_ALPHA(c) )
77 #define KEYCHAR(c)      ( ASCII_ALNUM(c) || (c) == '-' )
78 #define LEADOIDCHAR(c)  ( ASCII_DIGIT(c) )
79 #define OIDCHAR(c)      ( ASCII_DIGIT(c) || (c) == '.' )
80
81 #define LEADATTRCHAR(c) ( LEADKEYCHAR(c) || LEADOIDCHAR(c) )
82 #define ATTRCHAR(c)     ( KEYCHAR((c)) || (c) == '.' )
83
84 #define NEEDSESCAPE(c)  ((c) == '\\' || (c) == '"')
85
86 #define SLAP_SCHERR_OUTOFMEM            1
87 #define SLAP_SCHERR_CLASS_NOT_FOUND     2
88 #define SLAP_SCHERR_ATTR_NOT_FOUND      3
89 #define SLAP_SCHERR_DUP_CLASS           4
90 #define SLAP_SCHERR_DUP_ATTR            5
91 #define SLAP_SCHERR_DUP_SYNTAX          6
92 #define SLAP_SCHERR_DUP_RULE            7
93 #define SLAP_SCHERR_NO_NAME             8
94 #define SLAP_SCHERR_ATTR_INCOMPLETE     9
95 #define SLAP_SCHERR_MR_NOT_FOUND        10
96 #define SLAP_SCHERR_SYN_NOT_FOUND       11
97 #define SLAP_SCHERR_MR_INCOMPLETE       12
98
99 #define SLAPD_ACI_DEFAULT_ATTR          "aci"
100
101 extern int slap_debug;
102
103 struct slap_op;
104 struct slap_conn;
105
106 struct replog_moddn {
107         char *newrdn;
108         int     deloldrdn;
109         char *newsup;
110 };
111
112 /*
113  * represents an attribute value assertion (i.e., attr=value)
114  */
115 typedef struct slap_ava {
116         char            *ava_type;
117         struct berval   ava_value;
118 } Ava;
119
120 typedef struct slap_mra {
121         char    *mra_rule;
122         char    *mra_type;
123         char    *mra_value;
124         int             mra_dnattrs;
125 } Mra;
126
127 /*
128  * represents a search filter
129  */
130 typedef struct slap_filter {
131         ber_tag_t       f_choice;       /* values taken from ldap.h */
132
133         union f_un_u {
134                 /* present */
135                 char            *f_un_type;
136
137                 /* equality, lessorequal, greaterorequal, approx */
138                 Ava             f_un_ava;
139
140                 /* extensible */
141                 Mra             f_un_fra;       
142
143                 /* and, or, not */
144                 struct slap_filter      *f_un_complex;
145
146                 /* substrings */
147                 struct sub {
148                         char    *f_un_sub_type;
149                         char    *f_un_sub_initial;
150                         char    **f_un_sub_any;
151                         char    *f_un_sub_final;
152                 } f_un_sub;
153         } f_un;
154
155 #define f_dn            f_un.f_un_type  /* used for DN indices */
156 #define f_type          f_un.f_un_type
157 #define f_ava           f_un.f_un_ava
158 #define f_avtype        f_un.f_un_ava.ava_type
159 #define f_avvalue       f_un.f_un_ava.ava_value
160 #define f_mra           f_un.f_un_mra
161 #define f_mrtype        f_un.f_un_mra.mra_type
162 #define f_mrvalue       f_un.f_un_mra.mra_value
163 #define f_mrdnaddrs     f_un.f_un_mra.mra_dnattrs
164 #define f_and           f_un.f_un_complex
165 #define f_or            f_un.f_un_complex
166 #define f_not           f_un.f_un_complex
167 #define f_list          f_un.f_un_complex
168 #define f_sub           f_un.f_un_sub
169 #define f_sub_type      f_un.f_un_sub.f_un_sub_type
170 #define f_sub_initial   f_un.f_un_sub.f_un_sub_initial
171 #define f_sub_any       f_un.f_un_sub.f_un_sub_any
172 #define f_sub_final     f_un.f_un_sub.f_un_sub_final
173
174         struct slap_filter      *f_next;
175 } Filter;
176
177 /*
178  * represents an attribute (type + values + syntax)
179  */
180 typedef struct slap_attr {
181         char            *a_type;
182         struct berval   **a_vals;
183         int             a_syntax;
184         struct slap_attr        *a_next;
185 } Attribute;
186
187 /*
188  * the attr_syntax() routine returns one of these values
189  * telling what kind of syntax an attribute supports.
190  */
191 #define SYNTAX_CIS      0x01    /* case insensitive string              */
192 #define SYNTAX_CES      0x02    /* case sensitive string                */
193 #define SYNTAX_BIN      0x04    /* binary data                          */
194 #define SYNTAX_TEL      0x08    /* telephone number string              */
195 #define SYNTAX_DN       0x10    /* dn string                            */
196
197 /*
198  * the id used in the indexes to refer to an entry
199  */
200 typedef unsigned long   ID;
201 #define NOID    ((ID)~0)
202
203 /*
204  * represents an entry in core
205  */
206 typedef struct slap_entry {
207         /*
208          * The ID field should only be changed before entry is
209          * inserted into a cache.  The ID value is backend
210          * specific.
211          */
212         ID              e_id;
213
214         char            *e_dn;          /* DN of this entry */
215         char            *e_ndn;         /* normalized DN of this entry */
216         Attribute       *e_attrs;       /* list of attributes + values */
217
218         /* for use by the backend for any purpose */
219         void*   e_private;
220 } Entry;
221
222 /*
223  * represents an access control list
224  */
225
226 /* the "by" part */
227 typedef struct slap_access {
228
229 #define ACL_NONE                0x0001
230 #define ACL_AUTH                0x0004
231 #define ACL_COMPARE             0x0008
232 #define ACL_SEARCH              0x0010
233 #define ACL_READ                0x0020
234 #define ACL_WRITE               0x0040
235 #define ACL_PRIV_MASK   0x00ff
236
237 #define ACL_SELF                0x4000
238 #define ACL_INVALID             (-1)
239
240 #define ACL_IS(a,lvl)   (((a) & (lvl)) == (lvl))
241
242 #define ACL_IS_NONE(a)          ACL_IS((a),ACL_SELF)
243 #define ACL_IS_AUTH(a)          ACL_IS((a),ACL_AUTH)
244 #define ACL_IS_COMPARE(a)       ACL_IS((a),ACL_COMPARE)
245 #define ACL_IS_SEARCH(a)        ACL_IS((a),ACL_SEARCH)
246 #define ACL_IS_READ(a)          ACL_IS((a),ACL_READ)
247 #define ACL_IS_WRITE(a)         ACL_IS((a),ACL_WRITE)
248 #define ACL_IS_SELF(a)          ACL_IS((a),ACL_SELF)
249 #define ACL_IS_INVALID(a)       ((a) == ACL_INVALID)
250
251 #define ACL_CLR(a)                      ((a) = 0)
252 #define ACL_SET(a,lvl)          ((a) |= (lvl))
253 #define ACL_SET_NONE(a)         ACL_SET((a),ACL_SELF)
254 #define ACL_SET_AUTH(a)         ACL_SET((a),ACL_AUTH)
255 #define ACL_SET_COMPARE(a)      ACL_SET((a),ACL_COMPARE)
256 #define ACL_SET_SEARCH(a)       ACL_SET((a),ACL_SEARCH)
257 #define ACL_SET_READ(a)         ACL_SET((a),ACL_READ)
258 #define ACL_SET_WRITE(a)        ACL_SET((a),ACL_WRITE)
259 #define ACL_SET_SELF(a)         ACL_SET((a),ACL_SELF)
260 #define ACL_SET_INVALID(a)      ((a) = ACL_INVALID)
261
262 #define ACL_PRIV(a)                     ((a) & ACL_PRIV_MASK)
263 #define ACL_GRANT(a,lvl)        (ACL_PRIV(a) >= (lvl))
264
265         int                     a_access;
266
267         char            *a_dn_pat;
268         char            *a_dn_at;
269
270         char            *a_peername_pat;
271         char            *a_sockname_pat;
272
273         char            *a_domain_pat;
274         char            *a_sockurl_pat;
275
276 #ifdef SLAPD_ACI_ENABLED
277         char            *a_aci_at;
278 #endif
279
280         /* ACL Groups */
281         char            *a_group_pat;
282         char            *a_group_oc;
283         char            *a_group_at;
284
285         struct slap_access      *a_next;
286 } Access;
287
288 /* the "to" part */
289 typedef struct slap_acl {
290         /* "to" part: the entries this acl applies to */
291         Filter          *acl_filter;
292         regex_t         acl_dn_re;
293         char            *acl_dn_pat;
294         char            **acl_attrs;
295
296         /* "by" part: list of who has what access to the entries */
297         Access  *acl_access;
298
299         struct slap_acl *acl_next;
300 } AccessControl;
301
302 /*
303  * A list of LDAPMods
304  */
305 typedef struct ldapmodlist {
306         struct ldapmod ml_mod;
307         struct ldapmodlist *ml_next;
308 #define ml_op           ml_mod.mod_op
309 #define ml_type         ml_mod.mod_type
310 #define ml_values       ml_mod.mod_values
311 #define ml_bvalues      ml_mod.mod_bvalues
312 } LDAPModList;
313
314 /*
315  * represents schema information for a database
316  */
317 typedef struct slap_oid_macro {
318         struct slap_oid_macro *next;
319         char *name;
320         char *oid;
321         int oidlen;
322 } OidMacro;
323
324 typedef int slap_syntax_check_func LDAP_P((struct berval * val));
325
326 typedef struct slap_syntax {
327         LDAP_SYNTAX                     ssyn_syn;
328         slap_syntax_check_func          *ssyn_check;
329         struct slap_syntax              *ssyn_next;
330 } Syntax;
331 #define ssyn_oid                        ssyn_syn.syn_oid
332 #define ssyn_desc                       ssyn_syn.syn_desc
333
334 typedef int slap_mr_normalize_func LDAP_P((struct berval * val, struct berval **normalized));
335 typedef int slap_mr_compare_func LDAP_P((struct berval * val1, struct berval * val2));
336
337 typedef struct slap_matching_rule {
338         LDAP_MATCHING_RULE              smr_mrule;
339         slap_mr_normalize_func          *smr_normalize;
340         slap_mr_compare_func            *smr_compare;
341         Syntax                          *smr_syntax;
342         struct slap_matching_rule       *smr_next;
343 } MatchingRule;
344 #define smr_oid                         smr_mrule.mr_oid
345 #define smr_names                       smr_mrule.mr_names
346 #define smr_desc                        smr_mrule.mr_desc
347 #define smr_obsolete                    smr_mrule.mr_obsolete
348 #define smr_syntax_oid                  smr_mrule.mr_syntax_oid
349
350 typedef struct slap_attribute_type {
351         LDAP_ATTRIBUTE_TYPE             sat_atype;
352         struct slap_attribute_type      *sat_sup;
353         struct slap_attribute_type      **sat_subtypes;
354         MatchingRule                    *sat_equality;
355         MatchingRule                    *sat_ordering;
356         MatchingRule                    *sat_substr;
357         Syntax                          *sat_syntax;
358         /* The next one is created to help in the transition */
359         int                             sat_syntax_compat;
360         struct slap_attribute_type      *sat_next;
361 } AttributeType;
362 #define sat_oid                 sat_atype.at_oid
363 #define sat_names               sat_atype.at_names
364 #define sat_desc                sat_atype.at_desc
365 #define sat_obsolete            sat_atype.at_obsolete
366 #define sat_sup_oid             sat_atype.at_sup_oid
367 #define sat_equality_oid        sat_atype.at_equality_oid
368 #define sat_ordering_oid        sat_atype.at_ordering_oid
369 #define sat_substr_oid          sat_atype.at_substr_oid
370 #define sat_syntax_oid          sat_atype.at_syntax_oid
371 #define sat_syntax_len          sat_atype.at_syntax_len
372 #define sat_single_value        sat_atype.at_single_value
373 #define sat_collective          sat_atype.at_collective
374 #define sat_no_user_mods        sat_atype.at_no_user_mods
375 #define sat_usage               sat_atype.at_usage
376
377 typedef struct slap_object_class {
378         LDAP_OBJECT_CLASS               soc_oclass;
379         struct slap_object_class        **soc_sups;
380         AttributeType                   **soc_required;
381         AttributeType                   **soc_allowed;
382         struct slap_object_class        *soc_next;
383 } ObjectClass;
384 #define soc_oid                 soc_oclass.oc_oid
385 #define soc_names               soc_oclass.oc_names
386 #define soc_desc                soc_oclass.oc_desc
387 #define soc_obsolete            soc_oclass.oc_obsolete
388 #define soc_sup_oids            soc_oclass.oc_sup_oids
389 #define soc_kind                soc_oclass.oc_kind
390 #define soc_at_oids_must        soc_oclass.oc_at_oids_must
391 #define soc_at_oids_may         soc_oclass.oc_at_oids_may
392
393 /*
394  * Backend-info
395  * represents a backend 
396  */
397
398 typedef struct slap_backend_info BackendInfo;   /* per backend type */
399 typedef struct slap_backend_db BackendDB;               /* per backend database */
400
401 extern int nBackendInfo;
402 extern int nBackendDB;
403 extern BackendInfo      *backendInfo;
404 extern BackendDB        *backendDB;
405
406 extern int slapMode;    
407 #define SLAP_UNDEFINED_MODE     0x0000
408 #define SLAP_SERVER_MODE        0x0001
409 #define SLAP_TOOL_MODE          0x0002
410 #define SLAP_MODE                       0x0003
411
412 #define SLAP_TRUNCATE_MODE      0x0100
413 #ifdef SLAPD_BDB2
414 #define SLAP_TIMED_MODE         0x1000
415 #endif
416 #define SLAP_TOOLID_MODE    4
417
418 /* temporary aliases */
419 typedef BackendDB Backend;
420 #define nbackends nBackendDB
421 #define backends backendDB
422
423 struct slap_backend_db {
424         BackendInfo     *bd_info;       /* pointer to shared backend info */
425
426         /* BackendInfo accessors */
427 #define         be_config       bd_info->bi_db_config
428 #define         be_type         bd_info->bi_type
429
430 #define         be_bind         bd_info->bi_op_bind
431 #define         be_unbind       bd_info->bi_op_unbind
432 #define         be_add          bd_info->bi_op_add
433 #define         be_compare      bd_info->bi_op_compare
434 #define         be_delete       bd_info->bi_op_delete
435 #define         be_modify       bd_info->bi_op_modify
436 #define         be_modrdn       bd_info->bi_op_modrdn
437 #define         be_search       bd_info->bi_op_search
438
439 #define         be_release      bd_info->bi_entry_release_rw
440 #define         be_group        bd_info->bi_acl_group
441
442 #define         be_connection_init      bd_info->bi_connection_init
443 #define         be_connection_destroy   bd_info->bi_connection_destroy
444
445 #ifdef SLAPD_TOOLS
446 #define         be_entry_open bd_info->bi_tool_entry_open
447 #define         be_entry_close bd_info->bi_tool_entry_close
448 #define         be_entry_first bd_info->bi_tool_entry_first
449 #define         be_entry_next bd_info->bi_tool_entry_next
450 #define         be_entry_get bd_info->bi_tool_entry_get
451 #define         be_entry_put bd_info->bi_tool_entry_put
452 #define         be_index_attr bd_info->bi_tool_index_attr
453 #define         be_index_change bd_info->bi_tool_index_change
454 #define         be_sync bd_info->bi_tool_sync
455 #endif
456
457         /* these should be renamed from be_ to bd_ */
458         char    **be_suffix;    /* the DN suffixes of data in this backend */
459         char    **be_nsuffix;   /* the normalized DN suffixes in this backend */
460         char    **be_suffixAlias; /* pairs of DN suffix aliases and deref values */
461         char    *be_root_dn;    /* the magic "root" dn for this db      */
462         char    *be_root_ndn;   /* the magic "root" normalized dn for this db   */
463         char    *be_root_pw;    /* the magic "root" password for this db        */
464         int     be_readonly;    /* 1 => db is in "read only" mode          */
465         unsigned int be_max_deref_depth;       /* limit for depth of an alias deref  */
466         int     be_sizelimit;   /* size limit for this backend             */
467         int     be_timelimit;   /* time limit for this backend             */
468         AccessControl *be_acl;  /* access control list for this backend    */
469         int     be_dfltaccess;  /* access given if no acl matches          */
470         char    **be_replica;   /* replicas of this backend (in master)    */
471         char    *be_replogfile; /* replication log file (in master)        */
472         char    *be_update_ndn; /* allowed to make changes (in replicas)   */
473         struct berval **be_update_refs; /* where to refer modifying clients to */
474         int     be_lastmod;     /* keep track of lastmodified{by,time}     */
475
476         char    *be_realm;
477
478         void    *be_private;    /* anything the backend database needs     */
479 };
480
481 struct slap_backend_info {
482         char    *bi_type;       /* type of backend */
483
484         /*
485          * per backend type routines:
486          * bi_init: called to allocate a backend_info structure,
487          *              called once BEFORE configuration file is read.
488          *              bi_init() initializes this structure hence is
489          *              called directly from be_initialize()
490          * bi_config: called per 'backend' specific option
491          *              all such options must before any 'database' options
492          *              bi_config() is called only from read_config()
493          * bi_open: called to open each database, called
494          *              once AFTER configuration file is read but
495          *              BEFORE any bi_db_open() calls.
496          *              bi_open() is called from backend_startup()
497          * bi_close: called to close each database, called
498          *              once during shutdown after all bi_db_close calls.
499          *              bi_close() is called from backend_shutdown()
500          * bi_destroy: called to destroy each database, called
501          *              once during shutdown after all bi_db_destroy calls.
502          *              bi_destory() is called from backend_destroy()
503          */
504         int (*bi_init)  LDAP_P((BackendInfo *bi));
505         int     (*bi_config) LDAP_P((BackendInfo *bi,
506                 const char *fname, int lineno, int argc, char **argv ));
507         int (*bi_open) LDAP_P((BackendInfo *bi));
508         int (*bi_close) LDAP_P((BackendInfo *bi));
509         int (*bi_destroy) LDAP_P((BackendInfo *bi));
510
511         /*
512          * per database routines:
513          * bi_db_init: called to initialize each database,
514          *      called upon reading 'database <type>' 
515          *      called only from backend_db_init()
516          * bi_db_config: called to configure each database,
517          *  called per database to handle per database options
518          *      called only from read_config()
519          * bi_db_open: called to open each database
520          *      called once per database immediately AFTER bi_open()
521          *      calls but before daemon startup.
522          *  called only by backend_startup()
523          * bi_db_close: called to close each database
524          *      called once per database during shutdown but BEFORE
525          *  any bi_close call.
526          *  called only by backend_shutdown()
527          * bi_db_destroy: called to destroy each database
528          *  called once per database during shutdown AFTER all
529          *  bi_close calls but before bi_destory calls.
530          *  called only by backend_destory()
531          */
532         int (*bi_db_init) LDAP_P((Backend *bd));
533         int     (*bi_db_config) LDAP_P((Backend *bd,
534                 const char *fname, int lineno, int argc, char **argv ));
535         int (*bi_db_open) LDAP_P((Backend *bd));
536         int (*bi_db_close) LDAP_P((Backend *bd));
537         int (*bi_db_destroy) LDAP_P((Backend *db));
538
539         /* LDAP Operations Handling Routines */
540         int     (*bi_op_bind)  LDAP_P(( BackendDB *bd,
541                 struct slap_conn *c, struct slap_op *o,
542                 char *dn, int method, char* mechanism,
543                 struct berval *cred, char** edn ));
544         int (*bi_op_unbind) LDAP_P((BackendDB *bd,
545                 struct slap_conn *c, struct slap_op *o ));
546         int     (*bi_op_search) LDAP_P((BackendDB *bd,
547                 struct slap_conn *c, struct slap_op *o,
548                 char *base, int scope, int deref,
549                 int slimit, int tlimit,
550                 Filter *f, char *filterstr, char **attrs,
551                 int attrsonly));
552         int     (*bi_op_compare)LDAP_P((BackendDB *bd,
553                 struct slap_conn *c, struct slap_op *o,
554                 char *dn, Ava *ava));
555         int     (*bi_op_modify) LDAP_P((BackendDB *bd,
556                 struct slap_conn *c, struct slap_op *o,
557                 char *dn, LDAPModList *m));
558         int     (*bi_op_modrdn) LDAP_P((BackendDB *bd,
559                 struct slap_conn *c, struct slap_op *o,
560                 char *dn, char *newrdn, int deleteoldrdn,
561                 char *newSuperior));
562         int     (*bi_op_add)    LDAP_P((BackendDB *bd,
563                 struct slap_conn *c, struct slap_op *o,
564                 Entry *e));
565         int     (*bi_op_delete) LDAP_P((BackendDB *bd,
566                 struct slap_conn *c, struct slap_op *o,
567                 char *dn));
568         int     (*bi_op_abandon) LDAP_P((BackendDB *bd,
569                 struct slap_conn *c, struct slap_op *o,
570                 ber_int_t msgid));
571
572         /* Auxilary Functions */
573         int     (*bi_entry_release_rw) LDAP_P((BackendDB *bd, Entry *e, int rw));
574
575         int     (*bi_acl_group)  LDAP_P((Backend *bd,
576                 Entry *e, const char *bdn, const char *edn,
577                 const char *objectclassValue, const char *groupattrName ));
578
579         int     (*bi_connection_init) LDAP_P((BackendDB *bd,
580                 struct slap_conn *c));
581         int     (*bi_connection_destroy) LDAP_P((BackendDB *bd,
582                 struct slap_conn *c));
583
584         /* hooks for slap tools */
585         int (*bi_tool_entry_open) LDAP_P(( BackendDB *be, int mode ));
586         int (*bi_tool_entry_close) LDAP_P(( BackendDB *be ));
587         ID (*bi_tool_entry_first) LDAP_P(( BackendDB *be ));
588         ID (*bi_tool_entry_next) LDAP_P(( BackendDB *be ));
589         Entry* (*bi_tool_entry_get) LDAP_P(( BackendDB *be, ID id ));
590         ID (*bi_tool_entry_put) LDAP_P(( BackendDB *be, Entry *e ));
591         int (*bi_tool_index_attr) LDAP_P(( BackendDB *be, char* type ));
592         int (*bi_tool_index_change) LDAP_P(( BackendDB *be, char* type,
593                 struct berval **bv, ID id, int op ));
594         int (*bi_tool_sync) LDAP_P(( BackendDB *be ));
595
596 #define SLAP_INDEX_ADD_OP               0x0001
597 #define SLAP_INDEX_DELETE_OP    0x0002
598
599         unsigned int bi_nDB;    /* number of databases of this type */
600         void    *bi_private;    /* anything the backend type needs */
601 };
602
603 /*
604  * represents an operation pending from an ldap client
605  */
606
607 typedef struct slap_op {
608         ber_int_t       o_opid;         /* id of this operation           */
609         ber_int_t       o_msgid;        /* msgid of the request           */
610
611         ldap_pvt_thread_t       o_tid;          /* thread handling this op        */
612
613         BerElement      *o_ber;         /* ber of the request             */
614
615         ber_tag_t       o_tag;          /* tag of the request             */
616         time_t          o_time;         /* time op was initiated          */
617
618         int             o_bind_in_progress;     /* multi-step bind in progress */
619
620         char            *o_dn;          /* dn bound when op was initiated */
621         char            *o_ndn;         /* normalized dn bound when op was initiated */
622         ber_int_t       o_protocol;     /* version of the LDAP protocol used by client */
623         ber_tag_t       o_authtype;     /* auth method used to bind dn    */
624                                         /* values taken from ldap.h       */
625                                         /* LDAP_AUTH_*                    */
626         char            *o_authmech; /* SASL mechanism used to bind dn */
627
628         LDAPControl     **o_ctrls;       /* controls */
629
630         unsigned long   o_connid; /* id of conn initiating this op  */
631
632 #ifdef LDAP_CONNECTIONLESS
633         int             o_cldap;        /* != 0 if this came in via CLDAP */
634         struct sockaddr o_clientaddr;   /* client address if via CLDAP    */
635         char            o_searchbase;   /* search base if via CLDAP       */
636 #endif
637
638         ldap_pvt_thread_mutex_t o_abandonmutex; /* protects o_abandon  */
639         int             o_abandon;      /* abandon flag */
640
641         struct slap_op  *o_next;        /* next operation in list         */
642         void    *o_private;     /* anything the backend needs     */
643 } Operation;
644
645 /*
646  * represents a connection from an ldap client
647  */
648
649 typedef struct slap_conn {
650         int                     c_struct_state; /* structure management state */
651         int                     c_conn_state;   /* connection state */
652
653         ldap_pvt_thread_mutex_t c_mutex; /* protect the connection */
654         Sockbuf         *c_sb;                  /* ber connection stuff           */
655
656         /* only can be changed by connect_init */
657         time_t          c_starttime;    /* when the connection was opened */
658         time_t          c_activitytime; /* when the connection was last used */
659         unsigned long           c_connid;       /* id of this connection for stats*/
660
661         char            *c_listener_url;        /* listener URL */
662         char            *c_peer_domain; /* DNS name of client */
663         char            *c_peer_name;   /* peer name (trans=addr:port) */
664         char            *c_sock_name;   /* sock name (trans=addr:port) */
665
666 #ifdef HAVE_CYRUS_SASL
667         sasl_conn_t     *c_sasl_context;
668 #endif
669
670         /* only can be changed by binding thread */
671         int             c_bind_in_progress;     /* multi-op bind in progress */
672
673         char    *c_cdn;         /* DN provided by the client */
674         char    *c_dn;          /* DN bound to this conn  */
675         ber_int_t       c_protocol;     /* version of the LDAP protocol used by client */
676         ber_tag_t       c_authtype;/* auth method used to bind c_dn  */
677         char    *c_authmech;    /* SASL mechanism used to bind c_dn */
678         void    *c_authstate;   /* SASL state data */
679
680         Operation       *c_ops;                 /* list of operations being processed */
681         Operation       *c_pending_ops; /* list of pending operations */
682
683         ldap_pvt_thread_mutex_t c_write_mutex;  /* only one pdu written at a time */
684         ldap_pvt_thread_cond_t  c_write_cv;             /* used to wait for sd write-ready*/
685
686         BerElement      *c_currentber;  /* ber we're attempting to read */
687         int             c_writewaiter;  /* true if writer is waiting */
688
689 #ifdef HAVE_TLS
690         int     c_is_tls;               /* true if this LDAP over raw TLS */
691         int     c_needs_tls_accept;     /* true if SSL_accept should be called */
692 #endif
693
694         long    c_n_ops_received;               /* num of ops received (next op_id) */
695         long    c_n_ops_executing;      /* num of ops currently executing */
696         long    c_n_ops_pending;                /* num of ops pending execution */
697         long    c_n_ops_completed;      /* num of ops completed */
698
699         long    c_n_get;                /* num of get calls */
700         long    c_n_read;               /* num of read calls */
701         long    c_n_write;              /* num of write calls */
702 } Connection;
703
704 #if defined(LDAP_SYSLOG) && defined(LDAP_DEBUG)
705 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 )  \
706         do { \
707                 if ( ldap_debug & (level) ) \
708                         fprintf( stderr, (fmt), (connid), (opid), (arg1), (arg2), (arg3) );\
709                 if ( ldap_syslog & (level) ) \
710                         syslog( ldap_syslog_level, (fmt), (connid), (opid), (arg1), \
711                                 (arg2), (arg3) ); \
712         } while (0)
713 #else
714 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 )
715 #endif
716
717 LDAP_END_DECL
718
719 #include "proto-slap.h"
720
721 #endif /* _slap_h_ */