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