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