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