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