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