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