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