]> git.sur5r.net Git - openldap/blob - servers/slapd/slap.h
Change slapd/delete stats message for consistency.
[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 #include <ac/time.h>
16
17 #undef NDEBUG
18 #include <assert.h>
19
20 #include "avl.h"
21 #include "lber.h"
22 #include "ldap.h"
23
24 #include "ldap_pvt_thread.h"
25
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    /* Just make sure value is there */
39
40
41
42 #define DN_DNS  0
43 #define DN_X500 1
44
45 #define ON      1
46 #define OFF     (-1)
47 #define UNDEFINED 0
48
49 #define MAXREMATCHES 10
50
51 #define DNSEPARATOR(c)  ((c) == ',' || (c) == ';')
52 #define SEPARATOR(c)    ((c) == ',' || (c) == ';' || (c) == '+')
53 #define SPACE(c)        ((c) == ' ' || (c) == '\n')
54 #define NEEDSESCAPE(c)  ((c) == '\\' || (c) == '"')
55
56 LDAP_BEGIN_DECL
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         char            *e_dn;          /* DN of this entry               */
141         char            *e_ndn;         /* normalized DN of this entry    */
142         Attribute       *e_attrs;       /* list of attributes + values    */
143
144         ID              e_id;           /* id of this entry - this should */
145                                         /* really be private to back-ldbm */
146         char            e_state;        /* for the cache                  */
147
148         ldap_pvt_thread_rdwr_t  e_rdwr; /* reader/writer lock             */
149
150 #define ENTRY_STATE_DELETED     1
151 #define ENTRY_STATE_CREATING    2
152         int             e_refcnt;       /* # threads ref'ing this entry   */
153         struct entry    *e_lrunext;     /* for cache lru list             */
154         struct entry    *e_lruprev;
155 } Entry;
156
157 /*
158  * represents an access control list
159  */
160
161 /* the "by" part */
162 struct access {
163         char            *a_dnpat;
164         char            *a_addrpat;
165         char            *a_domainpat;
166         char            *a_dnattr;
167         long            a_access;
168
169 #ifdef SLAPD_ACLGROUPS
170         char            *a_group;
171         char            *a_objectclassvalue;
172         char            *a_groupattrname;
173 #endif
174
175 #define ACL_NONE        0x01
176 #define ACL_COMPARE     0x02
177 #define ACL_SEARCH      0x04
178 #define ACL_READ        0x08
179 #define ACL_WRITE       0x10
180 #define ACL_SELF        0x40
181         struct access   *a_next;
182 };
183
184 /* the "to" part */
185 struct acl {
186         /* "to" part: the entries this acl applies to */
187         Filter          *acl_filter;
188         regex_t         acl_dnre;
189         char            *acl_dnpat;
190         char            **acl_attrs;
191
192         /* "by" part: list of who has what access to the entries */
193         struct access   *acl_access;
194
195         struct acl      *acl_next;
196 };
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  * represents a "database"
211  */
212
213 typedef struct backend Backend;
214 struct backend {
215         char    **be_suffix;    /* the DN suffixes of data in this backend */
216         char    **be_suffixAlias;       /* the DN suffix aliases of data in this backend */
217         char    *be_root_dn;    /* the magic "root" dn for this db      */
218         char    *be_root_ndn;   /* the magic "root" normalized dn for this db   */
219         char    *be_root_pw;    /* the magic "root" password for this db        */
220         int     be_readonly;    /* 1 => db is in "read only" mode          */
221         int     be_maxDerefDepth;       /* limit for depth of an alias deref  */
222         int     be_sizelimit;   /* size limit for this backend             */
223         int     be_timelimit;   /* time limit for this backend             */
224         struct acl *be_acl;     /* access control list for this backend    */
225         int     be_dfltaccess;  /* access given if no acl matches          */
226         char    **be_replica;   /* replicas of this backend (in master)    */
227         char    *be_replogfile; /* replication log file (in master)        */
228         char    *be_update_ndn; /* allowed to make changes (in replicas)   */
229         int     be_lastmod;     /* keep track of lastmodified{by,time}     */
230         char    *be_type;       /* type of database                        */
231
232         void    *be_private;    /* anything the backend needs              */
233
234         /* backend routines */
235         int     (*be_bind)   LDAP_P((Backend *be,
236                 struct slap_conn *c, struct slap_op *o,
237                 char *dn, int method, struct berval *cred, char** edn ));
238         void    (*be_unbind) LDAP_P((Backend *be,
239                 struct slap_conn *c, struct slap_op *o ));
240         int     (*be_search) LDAP_P((Backend *be,
241                 struct slap_conn *c, struct slap_op *o,
242                 char *base, int scope, int deref, int slimit, int tlimit,
243                 Filter *f, char *filterstr, char **attrs, int attrsonly));
244         int     (*be_compare)LDAP_P((Backend *be,
245                 struct slap_conn *c, struct slap_op *o,
246                 char *dn, Ava *ava));
247         int     (*be_modify) LDAP_P((Backend *be,
248                 struct slap_conn *c, struct slap_op *o,
249                 char *dn, LDAPMod *m));
250         int     (*be_modrdn) LDAP_P((Backend *be,
251                 struct slap_conn *c, struct slap_op *o,
252                 char *dn, char *newrdn, int deleteoldrdn ));
253         int     (*be_add)    LDAP_P((Backend *be,
254                 struct slap_conn *c, struct slap_op *o,
255                 Entry *e));
256         int     (*be_delete) LDAP_P((Backend *be,
257                 struct slap_conn *c, struct slap_op *o,
258                 char *dn));
259         /* Bug: be_abandon in unused! */
260         void    (*be_abandon)LDAP_P((Backend *be,
261                 struct slap_conn *c, struct slap_op *o,
262                 int msgid));
263         void    (*be_config) LDAP_P((Backend *be,
264                 char *fname, int lineno, int argc, char **argv ));
265         void    (*be_init)   LDAP_P((Backend *be));
266         void    (*be_close)  LDAP_P((Backend *be));
267
268 #ifdef SLAPD_ACLGROUPS
269         int     (*be_group)  LDAP_P((Backend *be, Entry *e,
270                 char *bdn, char *edn,
271                 char *objectclassValue, char *groupattrName ));
272 #endif
273 };
274
275 /*
276  * represents an operation pending from an ldap client
277  */
278
279 typedef struct slap_op {
280         BerElement      *o_ber;         /* ber of the request             */
281         long            o_msgid;        /* msgid of the request           */
282         unsigned long   o_tag;          /* tag of the request             */
283         time_t          o_time;         /* time op was initiated          */
284         char            *o_dn;          /* dn bound when op was initiated */
285         char            *o_ndn;         /* normalized dn bound when op was initiated */
286         int             o_authtype;     /* auth method used to bind dn    */
287                                         /* values taken from ldap.h       */
288                                         /* LDAP_AUTH_*                    */
289         int             o_opid;         /* id of this operation           */
290         int             o_connid;       /* id of conn initiating this op  */
291 #ifdef LDAP_CONNECTIONLESS
292         int             o_cldap;        /* != 0 if this came in via CLDAP */
293         struct sockaddr o_clientaddr;   /* client address if via CLDAP    */
294         char            o_searchbase;   /* search base if via CLDAP       */
295 #endif
296         struct slap_op  *o_next;        /* next operation pending         */
297         ldap_pvt_thread_t       o_tid;          /* thread handling this op        */
298         int             o_abandon;      /* signals op has been abandoned  */
299         ldap_pvt_thread_mutex_t o_abandonmutex; /* signals op has been abandoned  */
300
301         void    *o_private;     /* anything the backend needs     */
302 } Operation;
303
304 /*
305  * represents a connection from an ldap client
306  */
307
308 typedef struct slap_conn {
309         Sockbuf         c_sb;           /* ber connection stuff           */
310         char            *c_cdn;         /* DN provided by the client */
311         char            *c_dn;          /* DN bound to this conn  */
312         ldap_pvt_thread_mutex_t c_dnmutex;      /* mutex for c_dn field           */
313         int             c_authtype;     /* auth method used to bind c_dn  */
314 #ifdef LDAP_COMPAT
315         int             c_version;      /* for compatibility w/2.0, 3.0   */
316 #endif
317         char            *c_addr;        /* address of client on this conn */
318         char            *c_domain;      /* domain of client on this conn  */
319         Operation       *c_ops;         /* list of pending operations     */
320         ldap_pvt_thread_mutex_t c_opsmutex;     /* mutex for c_ops list & stats   */
321         ldap_pvt_thread_mutex_t c_pdumutex;     /* only one pdu written at a time */
322         ldap_pvt_thread_cond_t  c_wcv;          /* used to wait for sd write-ready*/
323         int             c_gettingber;   /* in the middle of ber_get_next  */
324         BerElement      *c_currentber;  /* ber we're getting              */
325         int             c_writewaiter;  /* signals write-ready sd waiter  */
326         int             c_pduwaiters;   /* signals threads waiting 4 pdu  */
327         time_t          c_starttime;    /* when the connection was opened */
328         int             c_connid;       /* id of this connection for stats*/
329         int             c_opsinitiated; /* # ops initiated/next op id     */
330         int             c_opscompleted; /* # ops completed                */
331 } Connection;
332
333 #if defined(LDAP_SYSLOG) && defined(LDAP_DEBUG)
334 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 )  \
335         { \
336                 if ( ldap_debug & level ) \
337                         fprintf( stderr, fmt, connid, opid, arg1, arg2, arg3 );\
338                 if ( ldap_syslog & level ) \
339                         syslog( ldap_syslog_level, fmt, connid, opid, arg1, \
340                             arg2, arg3 ); \
341         }
342 #else
343 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 )
344 #endif
345
346 #include "proto-slap.h"
347
348 LDAP_END_DECL
349
350 #endif /* _slap_h_ */