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