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