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