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