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