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