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