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