]> git.sur5r.net Git - openldap/blob - servers/slapd/slap.h
Add copyright notice and a few comments here and there
[openldap] / servers / slapd / slap.h
1 /* slap.h - stand alone ldap server include file */
2 /*
3  * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6
7 #ifndef _SLDAPD_H_
8 #define _SLDAPD_H_
9
10 #include <ac/stdlib.h>
11
12 #include <sys/types.h>
13 #include <ac/syslog.h>
14 #include <ac/regex.h>
15 #include <ac/socket.h>
16 #include <ac/time.h>
17
18 #ifdef HAVE_CYRUS_SASL
19 #include <sasl.h>
20 #endif
21
22 #include "avl.h"
23
24 #ifndef ldap_debug
25 #define ldap_debug slap_debug
26 #endif
27
28
29 #include "ldap_log.h"
30
31 #include <ldap.h>
32 #include <ldap_schema.h>
33
34 #include "ldap_pvt_thread.h"
35 #include "ldif.h"
36
37 LDAP_BEGIN_DECL
38
39 #ifdef f_next
40 #undef f_next /* name conflict between sys/file.h on SCO and struct filter */
41 #endif
42
43 #define SERVICE_NAME  OPENLDAP_PACKAGE "-slapd"
44
45 /* LDAPMod.mod_op value ===> Must be kept in sync with ldap.h!
46  *
47  * This is a value used internally by the backends. It is needed to allow
48  * adding values that already exist without getting an error as required by
49  * modrdn when the new rdn was already an attribute value itself.
50  * JCG 05/1999 (gomez@engr.sgi.com)
51  */
52 #define LDAP_MOD_SOFTADD        0x1000
53
54 #ifdef DNS_DN
55 #define DN_DNS  0
56 #define DN_X500 1
57 #endif
58
59 #define ON      1
60 #define OFF     (-1)
61 #define UNDEFINED 0
62
63 #define MAXREMATCHES 10
64
65 /* XXYYZ: these macros assume 'x' is an ASCII x */
66 #define DNSEPARATOR(c)  ((c) == ',' || (c) == ';')
67 #define SEPARATOR(c)    ((c) == ',' || (c) == ';' || (c) == '+')
68 #define SPACE(c)        ((c) == ' ' || (c) == '\n')
69
70 #define ASCII_LOWER(c)  ( (c) >= 'a' && (c) <= 'z' )
71 #define ASCII_UPPER(c)  ( (c) >= 'A' && (c) <= 'Z' )
72 #define ASCII_ALPHA(c)  ( ASCII_LOWER(c) || ASCII_UPPER(c) )
73 #define ASCII_DIGIT(c)  ( (c) >= '0' && (c) <= '9' )
74 #define ASCII_ALNUM(c)  ( ASCII_ALPHA(c) || ASCII_DIGIT(c) )
75
76 #define LEADKEYCHAR(c)  ( ASCII_ALPHA(c) )
77 #define KEYCHAR(c)      ( ASCII_ALNUM(c) || (c) == '-' )
78 #define LEADOIDCHAR(c)  ( ASCII_DIGIT(c) )
79 #define OIDCHAR(c)      ( ASCII_DIGIT(c) || (c) == '.' )
80
81 #define LEADATTRCHAR(c) ( LEADKEYCHAR(c) || LEADOIDCHAR(c) )
82 #define ATTRCHAR(c)     ( KEYCHAR((c)) || (c) == '.' )
83
84 #define NEEDSESCAPE(c)  ((c) == '\\' || (c) == '"')
85
86 #define SLAP_SCHERR_OUTOFMEM            1
87 #define SLAP_SCHERR_CLASS_NOT_FOUND     2
88 #define SLAP_SCHERR_ATTR_NOT_FOUND      3
89 #define SLAP_SCHERR_DUP_CLASS           4
90 #define SLAP_SCHERR_DUP_ATTR            5
91 #define SLAP_SCHERR_DUP_SYNTAX          6
92 #define SLAP_SCHERR_DUP_RULE            7
93 #define SLAP_SCHERR_NO_NAME             8
94 #define SLAP_SCHERR_ATTR_INCOMPLETE     9
95 #define SLAP_SCHERR_MR_NOT_FOUND        10
96 #define SLAP_SCHERR_SYN_NOT_FOUND       11
97 #define SLAP_SCHERR_MR_INCOMPLETE       12
98
99 extern int slap_debug;
100
101 struct slap_op;
102 struct slap_conn;
103
104 struct replog_moddn {
105         char *newrdn;
106         int     deloldrdn;
107         char *newsup;
108 };
109
110 /*
111  * represents an attribute value assertion (i.e., attr=value)
112  */
113 typedef struct slap_ava {
114         char            *ava_type;
115         struct berval   ava_value;
116 } Ava;
117
118 typedef struct slap_mra {
119         char    *mra_rule;
120         char    *mra_type;
121         char    *mra_value;
122         int             mra_dnattrs;
123 } Mra;
124
125 /*
126  * represents a search filter
127  */
128 typedef struct slap_filter {
129         ber_tag_t       f_choice;       /* values taken from ldap.h */
130
131         union f_un_u {
132                 /* present */
133                 char            *f_un_type;
134
135                 /* equality, lessorequal, greaterorequal, approx */
136                 Ava             f_un_ava;
137
138                 /* extensible */
139                 Mra             f_un_fra;       
140
141                 /* and, or, not */
142                 struct slap_filter      *f_un_complex;
143
144                 /* substrings */
145                 struct sub {
146                         char    *f_un_sub_type;
147                         char    *f_un_sub_initial;
148                         char    **f_un_sub_any;
149                         char    *f_un_sub_final;
150                 } f_un_sub;
151         } f_un;
152 #define f_type          f_un.f_un_type
153 #define f_ava           f_un.f_un_ava
154 #define f_avtype        f_un.f_un_ava.ava_type
155 #define f_avvalue       f_un.f_un_ava.ava_value
156 #define f_mra           f_un.f_un_mra
157 #define f_mrtype        f_un.f_un_mra.mra_type
158 #define f_mrvalue       f_un.f_un_mra.mra_value
159 #define f_mrdnaddrs     f_un.f_un_mra.mra_dnattrs
160 #define f_and           f_un.f_un_complex
161 #define f_or            f_un.f_un_complex
162 #define f_not           f_un.f_un_complex
163 #define f_list          f_un.f_un_complex
164 #define f_sub           f_un.f_un_sub
165 #define f_sub_type      f_un.f_un_sub.f_un_sub_type
166 #define f_sub_initial   f_un.f_un_sub.f_un_sub_initial
167 #define f_sub_any       f_un.f_un_sub.f_un_sub_any
168 #define f_sub_final     f_un.f_un_sub.f_un_sub_final
169
170         struct slap_filter      *f_next;
171 } Filter;
172
173 /*
174  * represents an attribute (type + values + syntax)
175  */
176 typedef struct slap_attr {
177         char            *a_type;
178         struct berval   **a_vals;
179         int             a_syntax;
180         struct slap_attr        *a_next;
181 } Attribute;
182
183 /*
184  * the attr_syntax() routine returns one of these values
185  * telling what kind of syntax an attribute supports.
186  */
187 #define SYNTAX_CIS      0x01    /* case insensitive string              */
188 #define SYNTAX_CES      0x02    /* case sensitive string                */
189 #define SYNTAX_BIN      0x04    /* binary data                          */
190 #define SYNTAX_TEL      0x08    /* telephone number string              */
191 #define SYNTAX_DN       0x10    /* dn string                            */
192
193 /*
194  * the id used in the indexes to refer to an entry
195  */
196 typedef unsigned long   ID;
197 #define NOID    ((ID)~0)
198
199 /*
200  * represents an entry in core
201  */
202 typedef struct slap_entry {
203         /*
204          * The ID field should only be changed before entry is
205          * inserted into a cache.  The ID value is backend
206          * specific.
207          */
208         ID              e_id;
209
210         char            *e_dn;          /* DN of this entry */
211         char            *e_ndn;         /* normalized DN of this entry */
212         Attribute       *e_attrs;       /* list of attributes + values */
213
214         /* for use by the backend for any purpose */
215         void*   e_private;
216 } Entry;
217
218 /*
219  * represents an access control list
220  */
221
222 /* the "by" part */
223 typedef struct slap_access {
224
225 #define ACL_NONE                0x0001
226 #define ACL_AUTH                0x0004
227 #define ACL_COMPARE             0x0008
228 #define ACL_SEARCH              0x0010
229 #define ACL_READ                0x0020
230 #define ACL_WRITE               0x0040
231 #define ACL_PRIV_MASK   0x00ff
232
233 #define ACL_SELF                0x4000
234 #define ACL_INVALID             (-1)
235
236 #define ACL_IS(a,lvl)   (((a) & (lvl)) == (lvl))
237
238 #define ACL_IS_NONE(a)          ACL_IS((a),ACL_SELF)
239 #define ACL_IS_AUTH(a)          ACL_IS((a),ACL_AUTH)
240 #define ACL_IS_COMPARE(a)       ACL_IS((a),ACL_COMPARE)
241 #define ACL_IS_SEARCH(a)        ACL_IS((a),ACL_SEARCH)
242 #define ACL_IS_READ(a)          ACL_IS((a),ACL_READ)
243 #define ACL_IS_WRITE(a)         ACL_IS((a),ACL_WRITE)
244 #define ACL_IS_SELF(a)          ACL_IS((a),ACL_SELF)
245 #define ACL_IS_INVALID(a)       ((a) == ACL_INVALID)
246
247 #define ACL_CLR(a)                      ((a) = 0)
248 #define ACL_SET(a,lvl)          ((a) |= (lvl))
249 #define ACL_SET_NONE(a)         ACL_SET((a),ACL_SELF)
250 #define ACL_SET_AUTH(a)         ACL_SET((a),ACL_AUTH)
251 #define ACL_SET_COMPARE(a)      ACL_SET((a),ACL_COMPARE)
252 #define ACL_SET_SEARCH(a)       ACL_SET((a),ACL_SEARCH)
253 #define ACL_SET_READ(a)         ACL_SET((a),ACL_READ)
254 #define ACL_SET_WRITE(a)        ACL_SET((a),ACL_WRITE)
255 #define ACL_SET_SELF(a)         ACL_SET((a),ACL_SELF)
256 #define ACL_SET_INVALID(a)      ((a) = ACL_INVALID)
257
258 #define ACL_PRIV(a)                     ((a) & ACL_PRIV_MASK)
259 #define ACL_GRANT(a,lvl)        (ACL_PRIV(a) >= (lvl))
260
261         int                     a_access;
262
263         char            *a_dn_pat;
264         char            *a_dn_at;
265
266         char            *a_peername_pat;
267         char            *a_sockname_pat;
268
269         char            *a_domain_pat;
270         char            *a_sockurl_pat;
271
272         /* ACL Groups */
273         char            *a_group_pat;
274         char            *a_group_oc;
275         char            *a_group_at;
276
277         struct slap_access      *a_next;
278 } Access;
279
280 /* the "to" part */
281 typedef struct slap_acl {
282         /* "to" part: the entries this acl applies to */
283         Filter          *acl_filter;
284         regex_t         acl_dn_re;
285         char            *acl_dn_pat;
286         char            **acl_attrs;
287
288         /* "by" part: list of who has what access to the entries */
289         Access  *acl_access;
290
291         struct slap_acl *acl_next;
292 } AccessControl;
293
294 /*
295  * A list of LDAPMods
296  */
297 typedef struct ldapmodlist {
298         struct ldapmod ml_mod;
299         struct ldapmodlist *ml_next;
300 #define ml_op           ml_mod.mod_op
301 #define ml_type         ml_mod.mod_type
302 #define ml_values       ml_mod.mod_values
303 #define ml_bvalues      ml_mod.mod_bvalues
304 } LDAPModList;
305
306 /*
307  * represents schema information for a database
308  */
309 typedef int slap_syntax_check_func LDAP_P((struct berval * val));
310
311 typedef struct slap_syntax {
312         LDAP_SYNTAX                     ssyn_syn;
313         slap_syntax_check_func          *ssyn_check;
314         struct slap_syntax              *ssyn_next;
315 } Syntax;
316 #define ssyn_oid                        ssyn_syn.syn_oid
317 #define ssyn_desc                       ssyn_syn.syn_desc
318
319 typedef int slap_mr_normalize_func LDAP_P((struct berval * val, struct berval **normalized));
320 typedef int slap_mr_compare_func LDAP_P((struct berval * val1, struct berval * val2));
321
322 typedef struct slap_matching_rule {
323         LDAP_MATCHING_RULE              smr_mrule;
324         slap_mr_normalize_func          *smr_normalize;
325         slap_mr_compare_func            *smr_compare;
326         Syntax                          *smr_syntax;
327         struct slap_matching_rule       *smr_next;
328 } MatchingRule;
329 #define smr_oid                         smr_mrule.mr_oid
330 #define smr_names                       smr_mrule.mr_names
331 #define smr_desc                        smr_mrule.mr_desc
332 #define smr_obsolete                    smr_mrule.mr_obsolete
333 #define smr_syntax_oid                  smr_mrule.mr_syntax_oid
334
335 typedef struct slap_attribute_type {
336         LDAP_ATTRIBUTE_TYPE             sat_atype;
337         struct slap_attribute_type      *sat_sup;
338         struct slap_attribute_type      **sat_subtypes;
339         MatchingRule                    *sat_equality;
340         MatchingRule                    *sat_ordering;
341         MatchingRule                    *sat_substr;
342         Syntax                          *sat_syntax;
343         /* The next one is created to help in the transition */
344         int                             sat_syntax_compat;
345         struct slap_attribute_type      *sat_next;
346 } AttributeType;
347 #define sat_oid                 sat_atype.at_oid
348 #define sat_names               sat_atype.at_names
349 #define sat_desc                sat_atype.at_desc
350 #define sat_obsolete            sat_atype.at_obsolete
351 #define sat_sup_oid             sat_atype.at_sup_oid
352 #define sat_equality_oid        sat_atype.at_equality_oid
353 #define sat_ordering_oid        sat_atype.at_ordering_oid
354 #define sat_substr_oid          sat_atype.at_substr_oid
355 #define sat_syntax_oid          sat_atype.at_syntax_oid
356 #define sat_syntax_len          sat_atype.at_syntax_len
357 #define sat_single_value        sat_atype.at_single_value
358 #define sat_collective          sat_atype.at_collective
359 #define sat_no_user_mods        sat_atype.at_no_user_mods
360 #define sat_usage               sat_atype.at_usage
361
362 typedef struct slap_object_class {
363         LDAP_OBJECT_CLASS               soc_oclass;
364         struct slap_object_class        **soc_sups;
365         AttributeType                   **soc_required;
366         AttributeType                   **soc_allowed;
367         struct slap_object_class        *soc_next;
368 } ObjectClass;
369 #define soc_oid                 soc_oclass.oc_oid
370 #define soc_names               soc_oclass.oc_names
371 #define soc_desc                soc_oclass.oc_desc
372 #define soc_obsolete            soc_oclass.oc_obsolete
373 #define soc_sup_oids            soc_oclass.oc_sup_oids
374 #define soc_kind                soc_oclass.oc_kind
375 #define soc_at_oids_must        soc_oclass.oc_at_oids_must
376 #define soc_at_oids_may         soc_oclass.oc_at_oids_may
377
378 /*
379  * Backend-info
380  * represents a backend 
381  */
382
383 typedef struct slap_backend_info BackendInfo;   /* per backend type */
384 typedef struct slap_backend_db BackendDB;               /* per backend database */
385
386 extern int nBackendInfo;
387 extern int nBackendDB;
388 extern BackendInfo      *backendInfo;
389 extern BackendDB        *backendDB;
390
391 extern int                      slapMode;       
392 #define SLAP_UNDEFINED_MODE     0
393 #define SLAP_SERVER_MODE        1
394 #define SLAP_TOOL_MODE          2
395 #ifdef SLAPD_BDB2
396 #  define SLAP_TIMEDSERVER_MODE  3
397 #  define SLAP_TOOLID_MODE       4
398 #endif
399
400 /* temporary aliases */
401 typedef BackendDB Backend;
402 #define nbackends nBackendDB
403 #define backends backendDB
404
405 struct slap_backend_db {
406         BackendInfo     *bd_info;       /* pointer to shared backend info */
407
408         /* BackendInfo accessors */
409 #define         be_config       bd_info->bi_db_config
410 #define         be_type         bd_info->bi_type
411
412 #define         be_bind         bd_info->bi_op_bind
413 #define         be_unbind       bd_info->bi_op_unbind
414 #define         be_add          bd_info->bi_op_add
415 #define         be_compare      bd_info->bi_op_compare
416 #define         be_delete       bd_info->bi_op_delete
417 #define         be_modify       bd_info->bi_op_modify
418 #define         be_modrdn       bd_info->bi_op_modrdn
419 #define         be_search       bd_info->bi_op_search
420
421 #define         be_release      bd_info->bi_entry_release_rw
422 #define         be_group        bd_info->bi_acl_group
423
424 #define         be_connection_init      bd_info->bi_connection_init
425 #define         be_connection_destroy   bd_info->bi_connection_destroy
426
427
428         /* these should be renamed from be_ to bd_ */
429         char    **be_suffix;    /* the DN suffixes of data in this backend */
430         char    **be_nsuffix;   /* the normalized DN suffixes in this backend */
431         char    **be_suffixAlias; /* pairs of DN suffix aliases and deref values */
432         char    *be_root_dn;    /* the magic "root" dn for this db      */
433         char    *be_root_ndn;   /* the magic "root" normalized dn for this db   */
434         char    *be_root_pw;    /* the magic "root" password for this db        */
435         int     be_readonly;    /* 1 => db is in "read only" mode          */
436         unsigned int be_max_deref_depth;       /* limit for depth of an alias deref  */
437         int     be_sizelimit;   /* size limit for this backend             */
438         int     be_timelimit;   /* time limit for this backend             */
439         AccessControl *be_acl;  /* access control list for this backend    */
440         int     be_dfltaccess;  /* access given if no acl matches          */
441         char    **be_replica;   /* replicas of this backend (in master)    */
442         char    *be_replogfile; /* replication log file (in master)        */
443         char    *be_update_ndn; /* allowed to make changes (in replicas)   */
444         struct berval **be_update_refs; /* where to refer modifying clients to */
445         int     be_lastmod;     /* keep track of lastmodified{by,time}     */
446
447         char    *be_realm;
448
449         void    *be_private;    /* anything the backend database needs     */
450 };
451
452 struct slap_backend_info {
453         char    *bi_type;       /* type of backend */
454
455         /*
456          * per backend type routines:
457          * bi_init: called to allocate a backend_info structure,
458          *              called once BEFORE configuration file is read.
459          *              bi_init() initializes this structure hence is
460          *              called directly from be_initialize()
461          * bi_config: called per 'backend' specific option
462          *              all such options must before any 'database' options
463          *              bi_config() is called only from read_config()
464          * bi_open: called to open each database, called
465          *              once AFTER configuration file is read but
466          *              BEFORE any bi_db_open() calls.
467          *              bi_open() is called from backend_startup()
468          * bi_close: called to close each database, called
469          *              once during shutdown after all bi_db_close calls.
470          *              bi_close() is called from backend_shutdown()
471          * bi_destroy: called to destroy each database, called
472          *              once during shutdown after all bi_db_destroy calls.
473          *              bi_destory() is called from backend_destroy()
474          */
475         int (*bi_init)  LDAP_P((BackendInfo *bi));
476         int     (*bi_config) LDAP_P((BackendInfo *bi,
477                 char *fname, int lineno, int argc, char **argv ));
478         int (*bi_open) LDAP_P((BackendInfo *bi));
479         int (*bi_close) LDAP_P((BackendInfo *bi));
480         int (*bi_destroy) LDAP_P((BackendInfo *bi));
481
482         /*
483          * per database routines:
484          * bi_db_init: called to initialize each database,
485          *      called upon reading 'database <type>' 
486          *      called only from backend_db_init()
487          * bi_db_config: called to configure each database,
488          *  called per database to handle per database options
489          *      called only from read_config()
490          * bi_db_open: called to open each database
491          *      called once per database immediately AFTER bi_open()
492          *      calls but before daemon startup.
493          *  called only by backend_startup()
494          * bi_db_close: called to close each database
495          *      called once per database during shutdown but BEFORE
496          *  any bi_close call.
497          *  called only by backend_shutdown()
498          * bi_db_destroy: called to destroy each database
499          *  called once per database during shutdown AFTER all
500          *  bi_close calls but before bi_destory calls.
501          *  called only by backend_destory()
502          */
503         int (*bi_db_init) LDAP_P((Backend *bd));
504         int     (*bi_db_config) LDAP_P((Backend *bd,
505                 char *fname, int lineno, int argc, char **argv ));
506         int (*bi_db_open) LDAP_P((Backend *bd));
507         int (*bi_db_close) LDAP_P((Backend *bd));
508         int (*bi_db_destroy) LDAP_P((Backend *db));
509
510         /* LDAP Operations Handling Routines */
511         int     (*bi_op_bind)  LDAP_P(( BackendDB *bd,
512                 struct slap_conn *c, struct slap_op *o,
513                 char *dn, int method, char* mechanism,
514                 struct berval *cred, char** edn ));
515         int (*bi_op_unbind) LDAP_P((BackendDB *bd,
516                 struct slap_conn *c, struct slap_op *o ));
517         int     (*bi_op_search) LDAP_P((BackendDB *bd,
518                 struct slap_conn *c, struct slap_op *o,
519                 char *base, int scope, int deref,
520                 int slimit, int tlimit,
521                 Filter *f, char *filterstr, char **attrs,
522                 int attrsonly));
523         int     (*bi_op_compare)LDAP_P((BackendDB *bd,
524                 struct slap_conn *c, struct slap_op *o,
525                 char *dn, Ava *ava));
526         int     (*bi_op_modify) LDAP_P((BackendDB *bd,
527                 struct slap_conn *c, struct slap_op *o,
528                 char *dn, LDAPModList *m));
529         int     (*bi_op_modrdn) LDAP_P((BackendDB *bd,
530                 struct slap_conn *c, struct slap_op *o,
531                 char *dn, char *newrdn, int deleteoldrdn,
532                 char *newSuperior));
533         int     (*bi_op_add)    LDAP_P((BackendDB *bd,
534                 struct slap_conn *c, struct slap_op *o,
535                 Entry *e));
536         int     (*bi_op_delete) LDAP_P((BackendDB *bd,
537                 struct slap_conn *c, struct slap_op *o,
538                 char *dn));
539         int     (*bi_op_abandon) LDAP_P((BackendDB *bd,
540                 struct slap_conn *c, struct slap_op *o,
541                 ber_int_t msgid));
542
543         /* Auxilary Functions */
544         int     (*bi_entry_release_rw) LDAP_P((BackendDB *bd, Entry *e, int rw));
545
546         int     (*bi_acl_group)  LDAP_P((Backend *bd,
547                 Entry *e, char *bdn, char *edn,
548                 char *objectclassValue, char *groupattrName ));
549
550         int     (*bi_connection_init) LDAP_P((BackendDB *bd,
551                 struct slap_conn *c));
552         int     (*bi_connection_destroy) LDAP_P((BackendDB *bd,
553                 struct slap_conn *c));
554
555
556         unsigned int bi_nDB;    /* number of databases of this type */
557         void    *bi_private;    /* anything the backend type needs */
558 };
559
560 /*
561  * represents an operation pending from an ldap client
562  */
563
564 typedef struct slap_op {
565         ber_int_t       o_opid;         /* id of this operation           */
566         ber_int_t       o_msgid;        /* msgid of the request           */
567
568         ldap_pvt_thread_t       o_tid;          /* thread handling this op        */
569
570         BerElement      *o_ber;         /* ber of the request             */
571
572         ber_tag_t       o_tag;          /* tag of the request             */
573         time_t          o_time;         /* time op was initiated          */
574
575         int             o_bind_in_progress;     /* multi-step bind in progress */
576
577         char            *o_dn;          /* dn bound when op was initiated */
578         char            *o_ndn;         /* normalized dn bound when op was initiated */
579         ber_int_t       o_protocol;     /* version of the LDAP protocol used by client */
580         ber_tag_t       o_authtype;     /* auth method used to bind dn    */
581                                         /* values taken from ldap.h       */
582                                         /* LDAP_AUTH_*                    */
583         char            *o_authmech; /* SASL mechanism used to bind dn */
584
585         LDAPControl     **o_ctrls;       /* controls */
586
587         unsigned long   o_connid; /* id of conn initiating this op  */
588
589 #ifdef LDAP_CONNECTIONLESS
590         int             o_cldap;        /* != 0 if this came in via CLDAP */
591         struct sockaddr o_clientaddr;   /* client address if via CLDAP    */
592         char            o_searchbase;   /* search base if via CLDAP       */
593 #endif
594
595         ldap_pvt_thread_mutex_t o_abandonmutex; /* protects o_abandon  */
596         int             o_abandon;      /* abandon flag */
597
598         struct slap_op  *o_next;        /* next operation in list         */
599         void    *o_private;     /* anything the backend needs     */
600 } Operation;
601
602 /*
603  * represents a connection from an ldap client
604  */
605
606 typedef struct slap_conn {
607         int                     c_struct_state; /* structure management state */
608         int                     c_conn_state;   /* connection state */
609
610         ldap_pvt_thread_mutex_t c_mutex; /* protect the connection */
611         Sockbuf         *c_sb;                  /* ber connection stuff           */
612
613         /* only can be changed by connect_init */
614         time_t          c_starttime;    /* when the connection was opened */
615         time_t          c_activitytime; /* when the connection was last used */
616         unsigned long           c_connid;       /* id of this connection for stats*/
617
618         char            *c_listener_url;        /* listener URL */
619         char            *c_peer_domain; /* DNS name of client */
620         char            *c_peer_name;   /* peer name (trans=addr:port) */
621         char            *c_sock_name;   /* sock name (trans=addr:port) */
622
623 #ifdef HAVE_CYRUS_SASL
624         sasl_conn_t     *c_sasl_context;
625 #endif
626
627         /* only can be changed by binding thread */
628         int             c_bind_in_progress;     /* multi-op bind in progress */
629
630         char    *c_cdn;         /* DN provided by the client */
631         char    *c_dn;          /* DN bound to this conn  */
632         ber_int_t       c_protocol;     /* version of the LDAP protocol used by client */
633         ber_tag_t       c_authtype;/* auth method used to bind c_dn  */
634         char    *c_authmech;    /* SASL mechanism used to bind c_dn */
635         void    *c_authstate;   /* SASL state data */
636
637         Operation       *c_ops;                 /* list of operations being processed */
638         Operation       *c_pending_ops; /* list of pending operations */
639
640         ldap_pvt_thread_mutex_t c_write_mutex;  /* only one pdu written at a time */
641         ldap_pvt_thread_cond_t  c_write_cv;             /* used to wait for sd write-ready*/
642
643         BerElement      *c_currentber;  /* ber we're attempting to read */
644         int             c_writewaiter;  /* true if writer is waiting */
645
646 #ifdef HAVE_TLS
647         int     c_is_tls;               /* true if this LDAP over raw TLS */
648         int     c_needs_tls_accept;     /* true if SSL_accept should be called */
649 #endif
650
651         long    c_n_ops_received;               /* num of ops received (next op_id) */
652         long    c_n_ops_executing;      /* num of ops currently executing */
653         long    c_n_ops_pending;                /* num of ops pending execution */
654         long    c_n_ops_completed;      /* num of ops completed */
655
656         long    c_n_get;                /* num of get calls */
657         long    c_n_read;               /* num of read calls */
658         long    c_n_write;              /* num of write calls */
659 } Connection;
660
661 #if defined(LDAP_SYSLOG) && defined(LDAP_DEBUG)
662 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 )  \
663         do { \
664                 if ( ldap_debug & (level) ) \
665                         fprintf( stderr, (fmt), (connid), (opid), (arg1), (arg2), (arg3) );\
666                 if ( ldap_syslog & (level) ) \
667                         syslog( ldap_syslog_level, (fmt), (connid), (opid), (arg1), \
668                                 (arg2), (arg3) ); \
669         } while (0)
670 #else
671 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 )
672 #endif
673
674 LDAP_END_DECL
675
676 #include "proto-slap.h"
677
678 #endif /* _slap_h_ */