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