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