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