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