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