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