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