]> git.sur5r.net Git - openldap/blob - servers/slapd/slap.h
Mirroring changes related to indexing to db2 backend...
[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 /* LDAPMod.mod_op value ===> Must be kept in sync with ldap.h!
32  *
33  * This is a value used internally by the backends. It is needed to allow
34  * adding values that already exist without getting an error as required by
35  * modrdn when the new rdn was already an attribute value itself.
36  * JCG 05/1999 (gomez@engr.sgi.com)
37  */
38 #define LDAP_MOD_SOFTADD        0x04
39
40 #define DN_DNS  0
41 #define DN_X500 1
42
43 #define ON      1
44 #define OFF     (-1)
45 #define UNDEFINED 0
46
47 #define MAXREMATCHES 10
48
49 #define DNSEPARATOR(c)  ((c) == ',' || (c) == ';')
50 #define SEPARATOR(c)    ((c) == ',' || (c) == ';' || (c) == '+')
51 #define SPACE(c)        ((c) == ' ' || (c) == '\n')
52 #define NEEDSESCAPE(c)  ((c) == '\\' || (c) == '"')
53
54 LDAP_BEGIN_DECL
55
56 extern int slap_debug;
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         /*
141          * The ID field should only be changed before entry is
142          * inserted into a cache.  The ID value is backend
143          * specific.
144          */
145         ID              e_id;
146
147         char            *e_dn;          /* DN of this entry */
148         char            *e_ndn;         /* normalized DN of this entry */
149         Attribute       *e_attrs;       /* list of attributes + values */
150
151         /* for use by the backend for any purpose */
152         void*   e_private;
153 } Entry;
154
155 /*
156  * represents an access control list
157  */
158
159 /* the "by" part */
160 struct access {
161 #define ACL_NONE        0x01
162 #define ACL_COMPARE     0x02
163 #define ACL_SEARCH      0x04
164 #define ACL_READ        0x08
165 #define ACL_WRITE       0x10
166 #define ACL_SELF        0x40
167         int                     a_access;
168
169         char            *a_dnpat;
170         char            *a_addrpat;
171         char            *a_domainpat;
172         char            *a_dnattr;
173
174 #ifdef SLAPD_ACLGROUPS
175         char            *a_group;
176         char            *a_objectclassvalue;
177         char            *a_groupattrname;
178 #endif
179         struct access   *a_next;
180 };
181
182 /* the "to" part */
183 struct acl {
184         /* "to" part: the entries this acl applies to */
185         Filter          *acl_filter;
186         regex_t         acl_dnre;
187         char            *acl_dnpat;
188         char            **acl_attrs;
189
190         /* "by" part: list of who has what access to the entries */
191         struct access   *acl_access;
192
193         struct acl      *acl_next;
194 };
195
196 /*
197  * A list of LDAPMods
198  */
199 typedef struct ldapmodlist {
200         struct ldapmod ml_mod;
201         struct ldapmodlist *ml_next;
202 #define ml_op           ml_mod.mod_op
203 #define ml_type         ml_mod.mod_type
204 #define ml_values       ml_mod.mod_values
205 #define ml_bvalues      ml_mod.mod_bvalues
206 } LDAPModList;
207
208 /*
209  * represents schema information for a database
210  */
211
212 struct objclass {
213         char            *oc_name;
214         char            **oc_required;
215         char            **oc_allowed;
216         struct objclass *oc_next;
217 };
218
219 /*
220  * Backend-info
221  * represents a backend 
222  */
223
224 typedef struct backend_info BackendInfo;        /* per backend type */
225 typedef struct backend_db BackendDB;            /* per backend database */
226
227 extern int nBackendInfo;
228 extern int nBackendDB;
229 extern BackendInfo      *backendInfo;
230 extern BackendDB        *backendDB;
231
232 extern int                      slapMode;       
233 #define SLAP_UNDEFINED_MODE     0
234 #define SLAP_SERVER_MODE        1
235 #define SLAP_TOOL_MODE          2
236 #ifdef SLAPD_BDB2
237 #  define SLAP_TIMEDSERVER_MODE  3
238 #  define SLAP_TOOLID_MODE       4
239 #endif
240
241 /* temporary aliases */
242 typedef BackendDB Backend;
243 #define nbackends nBackendDB
244 #define backends backendDB
245
246 struct backend_db {
247         BackendInfo     *bd_info;       /* pointer to shared backend info */
248
249         /* BackendInfo accessors */
250 #define         be_config       bd_info->bi_db_config
251 #define         be_type         bd_info->bi_type
252
253 #define         be_bind         bd_info->bi_op_bind
254 #define         be_unbind       bd_info->bi_op_unbind
255 #define         be_add          bd_info->bi_op_add
256 #define         be_compare      bd_info->bi_op_compare
257 #define         be_delete       bd_info->bi_op_delete
258 #define         be_modify       bd_info->bi_op_modify
259 #define         be_modrdn       bd_info->bi_op_modrdn
260 #define         be_search       bd_info->bi_op_search
261
262 #define         be_release      bd_info->bi_entry_release_rw
263 #define         be_group        bd_info->bi_acl_group
264
265         /* these should be renamed from be_ to bd_ */
266         char    **be_suffix;    /* the DN suffixes of data in this backend */
267         char    **be_nsuffix;   /* the normalized DN suffixes in this backend */
268         char    **be_suffixAlias;       /* the DN suffix aliases of data in this backend */
269         char    *be_root_dn;    /* the magic "root" dn for this db      */
270         char    *be_root_ndn;   /* the magic "root" normalized dn for this db   */
271         char    *be_root_pw;    /* the magic "root" password for this db        */
272         int     be_readonly;    /* 1 => db is in "read only" mode          */
273         int     be_maxDerefDepth;       /* limit for depth of an alias deref  */
274         int     be_sizelimit;   /* size limit for this backend             */
275         int     be_timelimit;   /* time limit for this backend             */
276         struct acl *be_acl;     /* access control list for this backend    */
277         int     be_dfltaccess;  /* access given if no acl matches          */
278         char    **be_replica;   /* replicas of this backend (in master)    */
279         char    *be_replogfile; /* replication log file (in master)        */
280         char    *be_update_ndn; /* allowed to make changes (in replicas)   */
281         int     be_lastmod;     /* keep track of lastmodified{by,time}     */
282
283         void    *be_private;    /* anything the backend database needs     */
284 };
285
286 struct backend_info {
287         char    *bi_type;       /* type of backend */
288
289         /*
290          * per backend type routines:
291          * bi_init: called to allocate a backend_info structure,
292          *              called once BEFORE configuration file is read.
293          *              bi_init() initializes this structure hence is
294          *              called directly from be_initialize()
295          * bi_config: called per 'backend' specific option
296          *              all such options must before any 'database' options
297          *              bi_config() is called only from read_config()
298          * bi_open: called to open each database, called
299          *              once AFTER configuration file is read but
300          *              BEFORE any bi_db_open() calls.
301          *              bi_open() is called from backend_startup()
302          * bi_close: called to close each database, called
303          *              once during shutdown after all bi_db_close calls.
304          *              bi_close() is called from backend_shutdown()
305          * bi_destroy: called to destroy each database, called
306          *              once during shutdown after all bi_db_destroy calls.
307          *              bi_destory() is called from backend_destroy()
308          */
309         int (*bi_init)  LDAP_P((BackendInfo *bi));
310         int     (*bi_config) LDAP_P((BackendInfo *bi,
311                 char *fname, int lineno, int argc, char **argv ));
312         int (*bi_open) LDAP_P((BackendInfo *bi));
313         int (*bi_close) LDAP_P((BackendInfo *bi));
314         int (*bi_destroy) LDAP_P((BackendInfo *bi));
315
316         /*
317          * per database routines:
318          * bi_db_init: called to initialize each database,
319          *      called upon reading 'database <type>' 
320          *      called only from backend_db_init()
321          * bi_db_config: called to configure each database,
322          *  called per database to handle per database options
323          *      called only from read_config()
324          * bi_db_open: called to open each database
325          *      called once per database immediately AFTER bi_open()
326          *      calls but before daemon startup.
327          *  called only by backend_startup()
328          * bi_db_close: called to close each database
329          *      called once per database during shutdown but BEFORE
330          *  any bi_close call.
331          *  called only by backend_shutdown()
332          * bi_db_destroy: called to destroy each database
333          *  called once per database during shutdown AFTER all
334          *  bi_close calls but before bi_destory calls.
335          *  called only by backend_destory()
336          */
337         int (*bi_db_init) LDAP_P((Backend *bd));
338         int     (*bi_db_config) LDAP_P((Backend *bd,
339                 char *fname, int lineno, int argc, char **argv ));
340         int (*bi_db_open) LDAP_P((Backend *bd));
341         int (*bi_db_close) LDAP_P((Backend *bd));
342         int (*bi_db_destroy) LDAP_P((Backend *db));
343
344         /* LDAP Operations Handling Routines */
345         int     (*bi_op_bind)  LDAP_P(( BackendDB *bd,
346                 struct slap_conn *c, struct slap_op *o,
347                 char *dn, int method, struct berval *cred, char** edn ));
348         int (*bi_op_unbind) LDAP_P((BackendDB *bd,
349                 struct slap_conn *c, struct slap_op *o ));
350         int     (*bi_op_search) LDAP_P((BackendDB *bd,
351                 struct slap_conn *c, struct slap_op *o,
352                 char *base, int scope, int deref, int slimit, int tlimit,
353                 Filter *f, char *filterstr, char **attrs, int attrsonly));
354         int     (*bi_op_compare)LDAP_P((BackendDB *bd,
355                 struct slap_conn *c, struct slap_op *o,
356                 char *dn, Ava *ava));
357         int     (*bi_op_modify) LDAP_P((BackendDB *bd,
358                 struct slap_conn *c, struct slap_op *o,
359                 char *dn, LDAPModList *m));
360         int     (*bi_op_modrdn) LDAP_P((BackendDB *bd,
361                 struct slap_conn *c, struct slap_op *o,
362                 char *dn, char *newrdn, int deleteoldrdn,
363                 char *newSuperior));
364         int     (*bi_op_add)    LDAP_P((BackendDB *bd,
365                 struct slap_conn *c, struct slap_op *o,
366                 Entry *e));
367         int     (*bi_op_delete) LDAP_P((BackendDB *bd,
368                 struct slap_conn *c, struct slap_op *o,
369                 char *dn));
370         /* Bug: be_op_abandon in unused! */
371         int     (*bi_op_abandon) LDAP_P((BackendDB *bd,
372                 struct slap_conn *c, struct slap_op *o,
373                 int msgid));
374
375         /* Auxilary Functions */
376         int     (*bi_entry_release_rw) LDAP_P((BackendDB *bd, Entry *e, int rw));
377 #ifdef SLAPD_ACLGROUPS
378         int     (*bi_acl_group)  LDAP_P((Backend *bd,
379                 Entry *e, char *bdn, char *edn,
380                 char *objectclassValue, char *groupattrName ));
381 #endif
382
383         unsigned int bi_nDB;    /* number of databases of this type */
384         void    *bi_private;    /* anything the backend type needs */
385 };
386
387 /*
388  * represents an operation pending from an ldap client
389  */
390
391 typedef struct slap_op {
392         long    o_opid;         /* id of this operation           */
393         long    o_msgid;        /* msgid of the request           */
394
395         ldap_pvt_thread_t       o_tid;          /* thread handling this op        */
396
397         BerElement      *o_ber;         /* ber of the request             */
398
399         unsigned long   o_tag;          /* tag of the request             */
400         time_t          o_time;         /* time op was initiated          */
401         char            *o_dn;          /* dn bound when op was initiated */
402         char            *o_ndn;         /* normalized dn bound when op was initiated */
403         int                     o_authtype;     /* auth method used to bind dn    */
404                                         /* values taken from ldap.h       */
405                                         /* LDAP_AUTH_*                    */
406
407 /*       long   o_connid;       *//* id of conn initiating this op  */
408
409 #ifdef LDAP_CONNECTIONLESS
410         int             o_cldap;        /* != 0 if this came in via CLDAP */
411         struct sockaddr o_clientaddr;   /* client address if via CLDAP    */
412         char            o_searchbase;   /* search base if via CLDAP       */
413 #endif
414
415         ldap_pvt_thread_mutex_t o_abandonmutex; /* protects o_abandon  */
416         int             o_abandon;      /* abandon flag */
417
418         struct slap_op  *o_next;        /* next operation in list         */
419         void    *o_private;     /* anything the backend needs     */
420 } Operation;
421
422 /*
423  * represents a connection from an ldap client
424  */
425
426 typedef struct slap_conn {
427         int                     c_struct_state; /* structure management state */
428         int                     c_conn_state;   /* connection state */
429
430         ldap_pvt_thread_mutex_t c_mutex; /* protect the connection */
431         Sockbuf         *c_sb;                  /* ber connection stuff           */
432
433         /* only can be changed by connect_init */
434         time_t          c_starttime;    /* when the connection was opened */
435         long            c_connid;       /* id of this connection for stats*/
436         char            *c_client_addr; /* address of client */
437         char            *c_client_name; /* name of client */
438
439         /* only can be changed by binding thread */
440         char    *c_cdn;         /* DN provided by the client */
441         char    *c_dn;          /* DN bound to this conn  */
442         int             c_protocol;     /* version of the LDAP protocol used by client */
443         int             c_authtype;     /* auth method used to bind c_dn  */
444 #ifdef LDAP_COMPAT
445         int             c_version;      /* for compatibility w/ U-Mich 2.0 & 3.0 */
446 #endif
447
448         Operation       *c_ops;                 /* list of operations being processed */
449         Operation       *c_pending_ops; /* list of pending operations */
450
451         ldap_pvt_thread_mutex_t c_write_mutex;  /* only one pdu written at a time */
452         ldap_pvt_thread_cond_t  c_write_cv;             /* used to wait for sd write-ready*/
453
454         BerElement      *c_currentber;  /* ber we're attempting to read */
455         int             c_writewaiter;  /* true if writer is waiting */
456
457         long    c_n_ops_received;               /* num of ops received (next op_id) */
458         long    c_n_ops_executing;      /* num of ops currently executing */
459         long    c_n_ops_pending;                /* num of ops pending execution */
460         long    c_n_ops_completed;      /* num of ops completed */
461 } Connection;
462
463 #if defined(LDAP_SYSLOG) && defined(LDAP_DEBUG)
464 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 )  \
465         do { \
466                 if ( ldap_debug & (level) ) \
467                         fprintf( stderr, (fmt), (connid), (opid), (arg1), (arg2), (arg3) );\
468                 if ( ldap_syslog & (level) ) \
469                         syslog( ldap_syslog_level, (fmt), (connid), (opid), (arg1), \
470                                 (arg2), (arg3) ); \
471         } while (0)
472 #else
473 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 )
474 #endif
475
476 #include "proto-slap.h"
477
478 LDAP_END_DECL
479
480 #endif /* _slap_h_ */