]> git.sur5r.net Git - openldap/blob - servers/slapd/slap.h
Stuart Lynne's UNTESTED thread patch (p1)
[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 #define LDAP_SYSLOG
7
8 #include <syslog.h>
9 #include <sys/types.h>
10 #include <regex.h>
11 #undef NDEBUG
12 #include <assert.h>
13
14 #include "avl.h"
15 #include "lber.h"
16 #include "ldap.h"
17 #include "lthread.h"
18 #include "lthread_rdwr.h"
19 #include "ldif.h"
20
21 #define DN_DNS  0
22 #define DN_X500 1
23
24 #define ON      1
25 #define OFF     (-1)
26 #define UNDEFINED 0
27
28 #define MAXREMATCHES 10
29
30 /*
31  * represents an attribute value assertion (i.e., attr=value)
32  */
33 typedef struct ava {
34         char            *ava_type;
35         struct berval   ava_value;
36 } Ava;
37
38 /*
39  * represents a search filter
40  */
41 typedef struct filter {
42         unsigned long   f_choice;       /* values taken from ldap.h */
43
44         union {
45                 /* present */
46                 char            *f_un_type;
47
48                 /* equality, lessorequal, greaterorequal, approx */
49                 Ava             f_un_ava;
50
51                 /* and, or, not */
52                 struct filter   *f_un_complex;
53
54                 /* substrings */
55                 struct sub {
56                         char    *f_un_sub_type;
57                         char    *f_un_sub_initial;
58                         char    **f_un_sub_any;
59                         char    *f_un_sub_final;
60                 } f_un_sub;
61         } f_un;
62 #define f_type          f_un.f_un_type
63 #define f_ava           f_un.f_un_ava
64 #define f_avtype        f_un.f_un_ava.ava_type
65 #define f_avvalue       f_un.f_un_ava.ava_value
66 #define f_and           f_un.f_un_complex
67 #define f_or            f_un.f_un_complex
68 #define f_not           f_un.f_un_complex
69 #define f_list          f_un.f_un_complex
70 #define f_sub           f_un.f_un_sub
71 #define f_sub_type      f_un.f_un_sub.f_un_sub_type
72 #define f_sub_initial   f_un.f_un_sub.f_un_sub_initial
73 #define f_sub_any       f_un.f_un_sub.f_un_sub_any
74 #define f_sub_final     f_un.f_un_sub.f_un_sub_final
75
76         struct filter   *f_next;
77 } Filter;
78
79 /*
80  * represents an attribute (type + values + syntax)
81  */
82 typedef struct attr {
83         char            *a_type;
84         struct berval   **a_vals;
85         int             a_syntax;
86         struct attr     *a_next;
87 } Attribute;
88
89 /*
90  * the attr_syntax() routine returns one of these values
91  * telling what kind of syntax an attribute supports.
92  */
93 #define SYNTAX_CIS      0x01    /* case insensitive string              */
94 #define SYNTAX_CES      0x02    /* case sensitive string                */
95 #define SYNTAX_BIN      0x04    /* binary data                          */
96 #define SYNTAX_TEL      0x08    /* telephone number string              */
97 #define SYNTAX_DN       0x10    /* dn string                            */
98
99 /*
100  * the id used in the indexes to refer to an entry
101  */
102 typedef unsigned long   ID;
103 #define NOID    ((unsigned long)-1)
104
105 /*
106  * represents an entry in core
107  */
108 typedef struct entry {
109         pthread_rdwr_t  e_rdwr;         /* reader/writer lock             */
110         /*struct entry    *e_nextfree;    /* for freelist                   */
111
112         char            *e_dn;          /* DN of this entry               */
113         Attribute       *e_attrs;       /* list of attributes + values    */
114
115         ID              e_id;           /* id of this entry - this should */
116                                         /* really be private to back-ldbm */
117         char            e_state;        /* for the cache                  */
118 #define ENTRY_STATE_DELETED     1
119 #define ENTRY_STATE_CREATING    2
120         int             e_refcnt;       /* # threads ref'ing this entry   */
121         struct entry    *e_lrunext;     /* for cache lru list             */
122         struct entry    *e_lruprev;
123 } Entry;
124
125 /*
126  * represents an access control list
127  */
128
129 /* the "by" part */
130 struct access {
131         char            *a_dnpat;
132         char            *a_addrpat;
133         char            *a_domainpat;
134         char            *a_dnattr;
135         long            a_access;
136
137 #ifdef ACLGROUP
138     char                *a_group;
139 #endif
140
141 #define ACL_NONE        0x01
142 #define ACL_COMPARE     0x02
143 #define ACL_SEARCH      0x04
144 #define ACL_READ        0x08
145 #define ACL_WRITE       0x10
146 #define ACL_SELF        0x40
147         struct access   *a_next;
148 };
149
150 /* the "to" part */
151 struct acl {
152         /* "to" part: the entries this acl applies to */
153         Filter          *acl_filter;
154         regex_t         acl_dnre;
155         char            *acl_dnpat;
156         char            **acl_attrs;
157
158         /* "by" part: list of who has what access to the entries */
159         struct access   *acl_access;
160
161         struct acl      *acl_next;
162 };
163
164 /*
165  * represents schema information for a database
166  */
167
168 struct objclass {
169         char            *oc_name;
170         char            **oc_required;
171         char            **oc_allowed;
172         struct objclass *oc_next;
173 };
174
175 /*
176  * represents a "database"
177  */
178
179 typedef struct backend {
180         char    **be_suffix;    /* the DN suffixes of data in this backend */
181         char    *be_rootdn;     /* the magic "root" dn for this db         */
182         char    *be_rootpw;     /* the magic "root" password for this db   */
183         int     be_readonly;    /* 1 => db is in "read only" mode          */
184         int     be_sizelimit;   /* size limit for this backend             */
185         int     be_timelimit;   /* time limit for this backend             */
186         struct acl *be_acl;     /* access control list for this backend    */
187         int     be_dfltaccess;  /* access given if no acl matches          */
188         char    **be_replica;   /* replicas of this backend (in master)    */
189         char    *be_replogfile; /* replication log file (in master)        */
190         char    *be_updatedn;   /* allowed to make changes (in replicas)   */
191         int     be_lastmod;     /* keep track of lastmodified{by,time}     */
192         char    *be_type;       /* type of database                        */
193
194         void    *be_private;    /* anything the backend needs              */
195
196         IFP     be_bind;        /* backend bind routine                    */
197         IFP     be_unbind;      /* backend unbind routine                  */
198         IFP     be_search;      /* backend search routine                  */
199         IFP     be_compare;     /* backend compare routine                 */
200         IFP     be_modify;      /* backend modify routine                  */
201         IFP     be_modrdn;      /* backend modrdn routine                  */
202         IFP     be_add;         /* backend add routine                     */
203         IFP     be_delete;      /* backend delete routine                  */
204         IFP     be_abandon;     /* backend abandon routine                 */
205         IFP     be_config;      /* backend config routine                  */
206         IFP     be_init;        /* backend init routine                    */
207         IFP     be_close;       /* backend close routine                   */
208
209 #ifdef ACLGROUP
210         IFP     be_group;       /* backend group member test               */
211 #endif
212 } Backend;
213
214 /*
215  * represents an operation pending from an ldap client
216  */
217
218 typedef struct op {
219         BerElement      *o_ber;         /* ber of the request             */
220         long            o_msgid;        /* msgid of the request           */
221         unsigned long   o_tag;          /* tag of the request             */
222         time_t          o_time;         /* time op was initiated          */
223         char            *o_dn;          /* dn bound when op was initiated */
224         int             o_authtype;     /* auth method used to bind dn    */
225                                         /* values taken from ldap.h       */
226                                         /* LDAP_AUTH_*                    */
227         int             o_opid;         /* id of this operation           */
228         int             o_connid;       /* id of conn initiating this op  */
229 #ifdef CLDAP
230         int             o_cldap;        /* != 0 if this came in via CLDAP */
231         struct sockaddr o_clientaddr;   /* client address if via CLDAP    */
232         char            o_searchbase;   /* search base if via CLDAP       */
233 #endif
234         struct op       *o_next;        /* next operation pending         */
235         pthread_t       o_tid;          /* thread handling this op        */
236         int             o_abandon;      /* signals op has been abandoned  */
237         pthread_mutex_t o_abandonmutex; /* signals op has been abandoned  */
238
239         int             o_private;      /* anything the backend needs     */
240 } Operation;
241
242 /*
243  * represents a connection from an ldap client
244  */
245
246 typedef struct conn {
247         Sockbuf         c_sb;           /* ber connection stuff           */
248         char            *c_dn;          /* current DN bound to this conn  */
249         pthread_mutex_t c_dnmutex;      /* mutex for c_dn field           */
250         int             c_authtype;     /* auth method used to bind c_dn  */
251 #ifdef COMPAT
252         int             c_version;      /* for compatibility w/2.0, 3.0   */
253 #endif
254         char            *c_addr;        /* address of client on this conn */
255         char            *c_domain;      /* domain of client on this conn  */
256         Operation       *c_ops;         /* list of pending operations     */
257         pthread_mutex_t c_opsmutex;     /* mutex for c_ops list & stats   */
258         pthread_mutex_t c_pdumutex;     /* only one pdu written at a time */
259         pthread_cond_t  c_wcv;          /* used to wait for sd write-ready*/
260         int             c_gettingber;   /* in the middle of ber_get_next  */
261         BerElement      *c_currentber;  /* ber we're getting              */
262         int             c_writewaiter;  /* signals write-ready sd waiter  */
263         int             c_pduwaiters;   /* signals threads waiting 4 pdu  */
264         time_t          c_starttime;    /* when the connection was opened */
265         int             c_connid;       /* id of this connection for stats*/
266         int             c_opsinitiated; /* # ops initiated/next op id     */
267         int             c_opscompleted; /* # ops completed                */
268 } Connection;
269
270 #if defined(LDAP_SYSLOG) && defined(LDAP_DEBUG)
271 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 )  \
272         { \
273                 if ( ldap_debug & level ) \
274                         fprintf( stderr, fmt, connid, opid, arg1, arg2, arg3 );\
275                 if ( ldap_syslog & level ) \
276                         syslog( ldap_syslog_level, fmt, connid, opid, arg1, \
277                             arg2, arg3 ); \
278         }
279 #else
280 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 )
281 #endif
282
283 #ifdef NEEDPROTOS
284 #include "proto-slap.h"
285 #endif
286
287 #endif /* _slap_h_ */