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