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