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