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