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