]> git.sur5r.net Git - openldap/blob - servers/slapd/slap.h
For ITS#158: keep mixed-case backend suffix in addition to upcased suffix.
[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 #include <sys/types.h>
9 #include <ac/syslog.h>
10 #include <ac/regex.h>
11 #include <ac/socket.h>                  /* needed by LDAP_CONNECTIONLESS */
12
13 #include "avl.h"
14
15 #ifndef ldap_debug
16 #define ldap_debug slap_debug
17 #endif
18
19
20 #include "ldap_log.h"
21
22 #include "lber.h"
23 #include "ldap.h"
24
25 #include "ldap_pvt_thread.h"
26 #include "ldif.h"
27 #ifdef f_next
28 #undef f_next /* name conflict between sys/file.h on SCO and struct filter */
29 #endif
30
31 #define DN_DNS  0
32 #define DN_X500 1
33
34 #define ON      1
35 #define OFF     (-1)
36 #define UNDEFINED 0
37
38 #define MAXREMATCHES 10
39
40 #define DNSEPARATOR(c)  ((c) == ',' || (c) == ';')
41 #define SEPARATOR(c)    ((c) == ',' || (c) == ';' || (c) == '+')
42 #define SPACE(c)        ((c) == ' ' || (c) == '\n')
43 #define NEEDSESCAPE(c)  ((c) == '\\' || (c) == '"')
44
45 LDAP_BEGIN_DECL
46
47 extern int slap_debug;
48
49 struct slap_op;
50 struct slap_conn;
51
52 /*
53  * represents an attribute value assertion (i.e., attr=value)
54  */
55 typedef struct ava {
56         char            *ava_type;
57         struct berval   ava_value;
58 } Ava;
59
60 /*
61  * represents a search filter
62  */
63 typedef struct filter {
64         unsigned long   f_choice;       /* values taken from ldap.h */
65
66         union {
67                 /* present */
68                 char            *f_un_type;
69
70                 /* equality, lessorequal, greaterorequal, approx */
71                 Ava             f_un_ava;
72
73                 /* and, or, not */
74                 struct filter   *f_un_complex;
75
76                 /* substrings */
77                 struct sub {
78                         char    *f_un_sub_type;
79                         char    *f_un_sub_initial;
80                         char    **f_un_sub_any;
81                         char    *f_un_sub_final;
82                 } f_un_sub;
83         } f_un;
84 #define f_type          f_un.f_un_type
85 #define f_ava           f_un.f_un_ava
86 #define f_avtype        f_un.f_un_ava.ava_type
87 #define f_avvalue       f_un.f_un_ava.ava_value
88 #define f_and           f_un.f_un_complex
89 #define f_or            f_un.f_un_complex
90 #define f_not           f_un.f_un_complex
91 #define f_list          f_un.f_un_complex
92 #define f_sub           f_un.f_un_sub
93 #define f_sub_type      f_un.f_un_sub.f_un_sub_type
94 #define f_sub_initial   f_un.f_un_sub.f_un_sub_initial
95 #define f_sub_any       f_un.f_un_sub.f_un_sub_any
96 #define f_sub_final     f_un.f_un_sub.f_un_sub_final
97
98         struct filter   *f_next;
99 } Filter;
100
101 /*
102  * represents an attribute (type + values + syntax)
103  */
104 typedef struct attr {
105         char            *a_type;
106         struct berval   **a_vals;
107         int             a_syntax;
108         struct attr     *a_next;
109 } Attribute;
110
111 /*
112  * the attr_syntax() routine returns one of these values
113  * telling what kind of syntax an attribute supports.
114  */
115 #define SYNTAX_CIS      0x01    /* case insensitive string              */
116 #define SYNTAX_CES      0x02    /* case sensitive string                */
117 #define SYNTAX_BIN      0x04    /* binary data                          */
118 #define SYNTAX_TEL      0x08    /* telephone number string              */
119 #define SYNTAX_DN       0x10    /* dn string                            */
120
121 /*
122  * the id used in the indexes to refer to an entry
123  */
124 typedef unsigned long   ID;
125 #define NOID    ((unsigned long)-1)
126
127 /*
128  * represents an entry in core
129  */
130 typedef struct entry {
131         /*
132          * The ID field should only be changed before entry is
133          * inserted into a cache.  The ID value is backend
134          * specific.
135          */
136         ID              e_id;
137
138         char            *e_dn;          /* DN of this entry */
139         char            *e_ndn;         /* normalized DN of this entry */
140         Attribute       *e_attrs;       /* list of attributes + values */
141
142         /* for use by the backend for any purpose */
143         void*   e_private;
144 } Entry;
145
146 /*
147  * represents an access control list
148  */
149
150 /* the "by" part */
151 struct access {
152 #define ACL_NONE        0x01
153 #define ACL_COMPARE     0x02
154 #define ACL_SEARCH      0x04
155 #define ACL_READ        0x08
156 #define ACL_WRITE       0x10
157 #define ACL_SELF        0x40
158         int                     a_access;
159
160         char            *a_dnpat;
161         char            *a_addrpat;
162         char            *a_domainpat;
163         char            *a_dnattr;
164
165 #ifdef SLAPD_ACLGROUPS
166         char            *a_group;
167         char            *a_objectclassvalue;
168         char            *a_groupattrname;
169 #endif
170         struct access   *a_next;
171 };
172
173 /* the "to" part */
174 struct acl {
175         /* "to" part: the entries this acl applies to */
176         Filter          *acl_filter;
177         regex_t         acl_dnre;
178         char            *acl_dnpat;
179         char            **acl_attrs;
180
181         /* "by" part: list of who has what access to the entries */
182         struct access   *acl_access;
183
184         struct acl      *acl_next;
185 };
186
187 /*
188  * A list of LDAPMods
189  */
190 typedef struct ldapmodlist {
191         struct ldapmod ml_mod;
192         struct ldapmodlist *ml_next;
193 #define ml_op           ml_mod.mod_op
194 #define ml_type         ml_mod.mod_type
195 #define ml_values       ml_mod.mod_values
196 #define ml_bvalues      ml_mod.mod_bvalues
197 } LDAPModList;
198
199 /*
200  * represents schema information for a database
201  */
202
203 struct objclass {
204         char            *oc_name;
205         char            **oc_required;
206         char            **oc_allowed;
207         struct objclass *oc_next;
208 };
209
210 /*
211  * Backend-info
212  * represents a backend 
213  */
214
215 typedef struct backend_info BackendInfo;        /* per backend type */
216 typedef struct backend_db BackendDB;            /* per backend database */
217
218 extern int nBackendInfo;
219 extern int nBackendDB;
220 extern BackendInfo      *backendInfo;
221 extern BackendDB        *backendDB;
222
223 extern int                      slapMode;       
224 #define SLAP_UNDEFINED_MODE     0
225 #define SLAP_SERVER_MODE        1
226 #define SLAP_TOOL_MODE          2
227 #ifdef SLAPD_BDB2
228 #  define SLAP_TIMEDSERVER_MODE  3
229 #  define SLAP_TOOLID_MODE       4
230 #endif
231
232 /* temporary aliases */
233 typedef BackendDB Backend;
234 #define nbackends nBackendDB
235 #define backends backendDB
236
237 struct backend_db {
238         BackendInfo     *bd_info;       /* pointer to shared backend info */
239
240         /* BackendInfo accessors */
241 #define         be_config       bd_info->bi_db_config
242 #define         be_type         bd_info->bi_type
243
244 #define         be_bind         bd_info->bi_op_bind
245 #define         be_unbind       bd_info->bi_op_unbind
246 #define         be_add          bd_info->bi_op_add
247 #define         be_compare      bd_info->bi_op_compare
248 #define         be_delete       bd_info->bi_op_delete
249 #define         be_modify       bd_info->bi_op_modify
250 #define         be_modrdn       bd_info->bi_op_modrdn
251 #define         be_search       bd_info->bi_op_search
252
253 #define         be_release      bd_info->bi_entry_release_rw
254 #define         be_group        bd_info->bi_acl_group
255
256         /* these should be renamed from be_ to bd_ */
257         char    **be_suffix;    /* the DN suffixes of data in this backend */
258         char    **be_nsuffix;   /* the normalized DN suffixes in this backend */
259         char    **be_suffixAlias;       /* the DN suffix aliases of data in this backend */
260         char    *be_root_dn;    /* the magic "root" dn for this db      */
261         char    *be_root_ndn;   /* the magic "root" normalized dn for this db   */
262         char    *be_root_pw;    /* the magic "root" password for this db        */
263         int     be_readonly;    /* 1 => db is in "read only" mode          */
264         int     be_maxDerefDepth;       /* limit for depth of an alias deref  */
265         int     be_sizelimit;   /* size limit for this backend             */
266         int     be_timelimit;   /* time limit for this backend             */
267         struct acl *be_acl;     /* access control list for this backend    */
268         int     be_dfltaccess;  /* access given if no acl matches          */
269         char    **be_replica;   /* replicas of this backend (in master)    */
270         char    *be_replogfile; /* replication log file (in master)        */
271         char    *be_update_ndn; /* allowed to make changes (in replicas)   */
272         int     be_lastmod;     /* keep track of lastmodified{by,time}     */
273
274         void    *be_private;    /* anything the backend database needs     */
275 };
276
277 struct backend_info {
278         char    *bi_type;       /* type of backend */
279
280         /*
281          * per backend type routines:
282          * bi_init: called to allocate a backend_info structure,
283          *              called once BEFORE configuration file is read.
284          *              bi_init() initializes this structure hence is
285          *              called directly from be_initialize()
286          * bi_config: called per 'backend' specific option
287          *              all such options must before any 'database' options
288          *              bi_config() is called only from read_config()
289          * bi_open: called to open each database, called
290          *              once AFTER configuration file is read but
291          *              BEFORE any bi_db_open() calls.
292          *              bi_open() is called from backend_startup()
293          * bi_close: called to close each database, called
294          *              once during shutdown after all bi_db_close calls.
295          *              bi_close() is called from backend_shutdown()
296          * bi_destroy: called to destroy each database, called
297          *              once during shutdown after all bi_db_destroy calls.
298          *              bi_destory() is called from backend_destroy()
299          */
300         int (*bi_init)  LDAP_P((BackendInfo *bi));
301         int     (*bi_config) LDAP_P((BackendInfo *bi,
302                 char *fname, int lineno, int argc, char **argv ));
303         int (*bi_open) LDAP_P((BackendInfo *bi));
304         int (*bi_close) LDAP_P((BackendInfo *bi));
305         int (*bi_destroy) LDAP_P((BackendInfo *bi));
306
307         /*
308          * per database routines:
309          * bi_db_init: called to initialize each database,
310          *      called upon reading 'database <type>' 
311          *      called only from backend_db_init()
312          * bi_db_config: called to configure each database,
313          *  called per database to handle per database options
314          *      called only from read_config()
315          * bi_db_open: called to open each database
316          *      called once per database immediately AFTER bi_open()
317          *      calls but before daemon startup.
318          *  called only by backend_startup()
319          * bi_db_close: called to close each database
320          *      called once per database during shutdown but BEFORE
321          *  any bi_close call.
322          *  called only by backend_shutdown()
323          * bi_db_destroy: called to destroy each database
324          *  called once per database during shutdown AFTER all
325          *  bi_close calls but before bi_destory calls.
326          *  called only by backend_destory()
327          */
328         int (*bi_db_init) LDAP_P((Backend *bd));
329         int     (*bi_db_config) LDAP_P((Backend *bd,
330                 char *fname, int lineno, int argc, char **argv ));
331         int (*bi_db_open) LDAP_P((Backend *bd));
332         int (*bi_db_close) LDAP_P((Backend *bd));
333         int (*bi_db_destroy) LDAP_P((Backend *db));
334
335         /* LDAP Operations Handling Routines */
336         int     (*bi_op_bind)  LDAP_P(( BackendDB *bd,
337                 struct slap_conn *c, struct slap_op *o,
338                 char *dn, int method, struct berval *cred, char** edn ));
339         int (*bi_op_unbind) LDAP_P((BackendDB *bd,
340                 struct slap_conn *c, struct slap_op *o ));
341         int     (*bi_op_search) LDAP_P((BackendDB *bd,
342                 struct slap_conn *c, struct slap_op *o,
343                 char *base, int scope, int deref, int slimit, int tlimit,
344                 Filter *f, char *filterstr, char **attrs, int attrsonly));
345         int     (*bi_op_compare)LDAP_P((BackendDB *bd,
346                 struct slap_conn *c, struct slap_op *o,
347                 char *dn, Ava *ava));
348         int     (*bi_op_modify) LDAP_P((BackendDB *bd,
349                 struct slap_conn *c, struct slap_op *o,
350                 char *dn, LDAPModList *m));
351         int     (*bi_op_modrdn) LDAP_P((BackendDB *bd,
352                 struct slap_conn *c, struct slap_op *o,
353                 char *dn, char *newrdn, int deleteoldrdn,
354                 char *newSuperior));
355         int     (*bi_op_add)    LDAP_P((BackendDB *bd,
356                 struct slap_conn *c, struct slap_op *o,
357                 Entry *e));
358         int     (*bi_op_delete) LDAP_P((BackendDB *bd,
359                 struct slap_conn *c, struct slap_op *o,
360                 char *dn));
361         /* Bug: be_op_abandon in unused! */
362         int     (*bi_op_abandon) LDAP_P((BackendDB *bd,
363                 struct slap_conn *c, struct slap_op *o,
364                 int msgid));
365
366         /* Auxilary Functions */
367         int     (*bi_entry_release_rw) LDAP_P((BackendDB *bd, Entry *e, int rw));
368 #ifdef SLAPD_ACLGROUPS
369         int     (*bi_acl_group)  LDAP_P((Backend *bd,
370                 Entry *e, char *bdn, char *edn,
371                 char *objectclassValue, char *groupattrName ));
372 #endif
373
374         unsigned int bi_nDB;    /* number of databases of this type */
375         void    *bi_private;    /* anything the backend type needs */
376 };
377
378 /*
379  * represents an operation pending from an ldap client
380  */
381
382 typedef struct slap_op {
383         long    o_opid;         /* id of this operation           */
384         long    o_msgid;        /* msgid of the request           */
385
386         ldap_pvt_thread_t       o_tid;          /* thread handling this op        */
387
388         BerElement      *o_ber;         /* ber of the request             */
389
390         unsigned long   o_tag;          /* tag of the request             */
391         time_t          o_time;         /* time op was initiated          */
392         char            *o_dn;          /* dn bound when op was initiated */
393         char            *o_ndn;         /* normalized dn bound when op was initiated */
394         int                     o_authtype;     /* auth method used to bind dn    */
395                                         /* values taken from ldap.h       */
396                                         /* LDAP_AUTH_*                    */
397
398 /*       long   o_connid;       *//* id of conn initiating this op  */
399
400 #ifdef LDAP_CONNECTIONLESS
401         int             o_cldap;        /* != 0 if this came in via CLDAP */
402         struct sockaddr o_clientaddr;   /* client address if via CLDAP    */
403         char            o_searchbase;   /* search base if via CLDAP       */
404 #endif
405
406         ldap_pvt_thread_mutex_t o_abandonmutex; /* protects o_abandon  */
407         int             o_abandon;      /* abandon flag */
408
409         struct slap_op  *o_next;        /* next operation in list         */
410         void    *o_private;     /* anything the backend needs     */
411 } Operation;
412
413 /*
414  * represents a connection from an ldap client
415  */
416
417 typedef struct slap_conn {
418         int                     c_struct_state; /* structure management state */
419         int                     c_conn_state;   /* connection state */
420
421         ldap_pvt_thread_mutex_t c_mutex; /* protect the connection */
422         Sockbuf         *c_sb;                  /* ber connection stuff           */
423
424         /* only can be changed by connect_init */
425         time_t          c_starttime;    /* when the connection was opened */
426         long            c_connid;       /* id of this connection for stats*/
427         char            *c_client_addr; /* address of client */
428         char            *c_client_name; /* name of client */
429
430         /* only can be changed by binding thread */
431         char    *c_cdn;         /* DN provided by the client */
432         char    *c_dn;          /* DN bound to this conn  */
433         int             c_protocol;     /* version of the LDAP protocol used by client */
434         int             c_authtype;     /* auth method used to bind c_dn  */
435 #ifdef LDAP_COMPAT
436         int             c_version;      /* for compatibility w/ U-Mich 2.0 & 3.0 */
437 #endif
438
439         Operation       *c_ops;                 /* list of operations being processed */
440         Operation       *c_pending_ops; /* list of pending operations */
441
442         ldap_pvt_thread_mutex_t c_write_mutex;  /* only one pdu written at a time */
443         ldap_pvt_thread_cond_t  c_write_cv;             /* used to wait for sd write-ready*/
444
445         BerElement      *c_currentber;  /* ber we're attempting to read */
446         int             c_writewaiter;  /* true if writer is waiting */
447
448         long    c_n_ops_received;               /* num of ops received (next op_id) */
449         long    c_n_ops_executing;      /* num of ops currently executing */
450         long    c_n_ops_pending;                /* num of ops pending execution */
451         long    c_n_ops_completed;      /* num of ops completed */
452 } Connection;
453
454 #if defined(LDAP_SYSLOG) && defined(LDAP_DEBUG)
455 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 )  \
456         do { \
457                 if ( ldap_debug & (level) ) \
458                         fprintf( stderr, (fmt), (connid), (opid), (arg1), (arg2), (arg3) );\
459                 if ( ldap_syslog & (level) ) \
460                         syslog( ldap_syslog_level, (fmt), (connid), (opid), (arg1), \
461                                 (arg2), (arg3) ); \
462         } while (0)
463 #else
464 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 )
465 #endif
466
467 #include "proto-slap.h"
468
469 LDAP_END_DECL
470
471 #endif /* _slap_h_ */