]> git.sur5r.net Git - openldap/blob - servers/slapd/slap.h
Use LDAP_MOD_SOFTADD instead of LDAP_MOD_ADD when adding the new rdn as
[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 #ifndef LDAP_SYSLOG
9 #define LDAP_SYSLOG 1
10 #endif
11
12 #include <sys/types.h>
13 #include <ac/syslog.h>
14 #include <ac/regex.h>
15
16 #undef NDEBUG
17 #include <assert.h>
18
19 #include "avl.h"
20 #include "lber.h"
21 #include "ldap.h"
22
23 #include "ldap_pvt_thread.h"
24
25 #include "ldif.h"
26 #ifdef f_next
27 #undef f_next /* name conflict between sys/file.h on SCO and struct filter */
28 #endif
29
30 /* LDAPMod.mod_op value ===> Must be kept in sync with ldap.h!
31  *
32  * This is a value used internally by the backends. It is needed to allow
33  * adding values that already exist without getting an error as required by
34  * modrdn when the new rdn was already an attribute value itself.
35  * JCG 05/1999 (gomez@engr.sgi.com)
36  */
37 #define LDAP_MOD_SOFTADD        0x04    /* Just make sure value is there */
38
39
40
41 #define DN_DNS  0
42 #define DN_X500 1
43
44 #define ON      1
45 #define OFF     (-1)
46 #define UNDEFINED 0
47
48 #define MAXREMATCHES 10
49
50 #define DNSEPARATOR(c)  ((c) == ',' || (c) == ';')
51 #define SEPARATOR(c)    ((c) == ',' || (c) == ';' || (c) == '+')
52 #define SPACE(c)        ((c) == ' ' || (c) == '\n')
53 #define NEEDSESCAPE(c)  ((c) == '\\' || (c) == '"')
54
55 LDAP_BEGIN_DECL
56
57 struct slap_op;
58 struct slap_conn;
59
60 /*
61  * represents an attribute value assertion (i.e., attr=value)
62  */
63 typedef struct ava {
64         char            *ava_type;
65         struct berval   ava_value;
66 } Ava;
67
68 /*
69  * represents a search filter
70  */
71 typedef struct filter {
72         unsigned long   f_choice;       /* values taken from ldap.h */
73
74         union {
75                 /* present */
76                 char            *f_un_type;
77
78                 /* equality, lessorequal, greaterorequal, approx */
79                 Ava             f_un_ava;
80
81                 /* and, or, not */
82                 struct filter   *f_un_complex;
83
84                 /* substrings */
85                 struct sub {
86                         char    *f_un_sub_type;
87                         char    *f_un_sub_initial;
88                         char    **f_un_sub_any;
89                         char    *f_un_sub_final;
90                 } f_un_sub;
91         } f_un;
92 #define f_type          f_un.f_un_type
93 #define f_ava           f_un.f_un_ava
94 #define f_avtype        f_un.f_un_ava.ava_type
95 #define f_avvalue       f_un.f_un_ava.ava_value
96 #define f_and           f_un.f_un_complex
97 #define f_or            f_un.f_un_complex
98 #define f_not           f_un.f_un_complex
99 #define f_list          f_un.f_un_complex
100 #define f_sub           f_un.f_un_sub
101 #define f_sub_type      f_un.f_un_sub.f_un_sub_type
102 #define f_sub_initial   f_un.f_un_sub.f_un_sub_initial
103 #define f_sub_any       f_un.f_un_sub.f_un_sub_any
104 #define f_sub_final     f_un.f_un_sub.f_un_sub_final
105
106         struct filter   *f_next;
107 } Filter;
108
109 /*
110  * represents an attribute (type + values + syntax)
111  */
112 typedef struct attr {
113         char            *a_type;
114         struct berval   **a_vals;
115         int             a_syntax;
116         struct attr     *a_next;
117 } Attribute;
118
119 /*
120  * the attr_syntax() routine returns one of these values
121  * telling what kind of syntax an attribute supports.
122  */
123 #define SYNTAX_CIS      0x01    /* case insensitive string              */
124 #define SYNTAX_CES      0x02    /* case sensitive string                */
125 #define SYNTAX_BIN      0x04    /* binary data                          */
126 #define SYNTAX_TEL      0x08    /* telephone number string              */
127 #define SYNTAX_DN       0x10    /* dn string                            */
128
129 /*
130  * the id used in the indexes to refer to an entry
131  */
132 typedef unsigned long   ID;
133 #define NOID    ((unsigned long)-1)
134
135 /*
136  * represents an entry in core
137  */
138 typedef struct entry {
139         char            *e_dn;          /* DN of this entry               */
140         char            *e_ndn;         /* normalized DN of this entry    */
141         Attribute       *e_attrs;       /* list of attributes + values    */
142
143         ID              e_id;           /* id of this entry - this should */
144                                         /* really be private to back-ldbm */
145         char            e_state;        /* for the cache                  */
146
147         ldap_pvt_thread_rdwr_t  e_rdwr; /* reader/writer lock             */
148
149 #define ENTRY_STATE_DELETED     1
150 #define ENTRY_STATE_CREATING    2
151         int             e_refcnt;       /* # threads ref'ing this entry   */
152         struct entry    *e_lrunext;     /* for cache lru list             */
153         struct entry    *e_lruprev;
154 } Entry;
155
156 /*
157  * represents an access control list
158  */
159
160 /* the "by" part */
161 struct access {
162         char            *a_dnpat;
163         char            *a_addrpat;
164         char            *a_domainpat;
165         char            *a_dnattr;
166         long            a_access;
167
168 #ifdef SLAPD_ACLGROUPS
169         char            *a_group;
170         char            *a_objectclassvalue;
171         char            *a_groupattrname;
172 #endif
173
174 #define ACL_NONE        0x01
175 #define ACL_COMPARE     0x02
176 #define ACL_SEARCH      0x04
177 #define ACL_READ        0x08
178 #define ACL_WRITE       0x10
179 #define ACL_SELF        0x40
180         struct access   *a_next;
181 };
182
183 /* the "to" part */
184 struct acl {
185         /* "to" part: the entries this acl applies to */
186         Filter          *acl_filter;
187         regex_t         acl_dnre;
188         char            *acl_dnpat;
189         char            **acl_attrs;
190
191         /* "by" part: list of who has what access to the entries */
192         struct access   *acl_access;
193
194         struct acl      *acl_next;
195 };
196
197 /*
198  * represents schema information for a database
199  */
200
201 struct objclass {
202         char            *oc_name;
203         char            **oc_required;
204         char            **oc_allowed;
205         struct objclass *oc_next;
206 };
207
208 /*
209  * represents a "database"
210  */
211
212 typedef struct backend Backend;
213 struct backend {
214         char    **be_suffix;    /* the DN suffixes of data in this backend */
215         char    **be_suffixAlias;       /* the DN suffix aliases of data in this backend */
216         char    *be_root_dn;    /* the magic "root" dn for this db      */
217         char    *be_root_ndn;   /* the magic "root" normalized dn for this db   */
218         char    *be_root_pw;    /* the magic "root" password for this db        */
219         int     be_readonly;    /* 1 => db is in "read only" mode          */
220         int     be_maxDerefDepth;       /* limit for depth of an alias deref  */
221         int     be_sizelimit;   /* size limit for this backend             */
222         int     be_timelimit;   /* time limit for this backend             */
223         struct acl *be_acl;     /* access control list for this backend    */
224         int     be_dfltaccess;  /* access given if no acl matches          */
225         char    **be_replica;   /* replicas of this backend (in master)    */
226         char    *be_replogfile; /* replication log file (in master)        */
227         char    *be_update_ndn; /* allowed to make changes (in replicas)   */
228         int     be_lastmod;     /* keep track of lastmodified{by,time}     */
229         char    *be_type;       /* type of database                        */
230
231         void    *be_private;    /* anything the backend needs              */
232
233         /* backend routines */
234         int     (*be_bind)   LDAP_P((Backend *be,
235                 struct slap_conn *c, struct slap_op *o,
236                 char *dn, int method, struct berval *cred, char** edn ));
237         void    (*be_unbind) LDAP_P((Backend *be,
238                 struct slap_conn *c, struct slap_op *o ));
239         int     (*be_search) LDAP_P((Backend *be,
240                 struct slap_conn *c, struct slap_op *o,
241                 char *base, int scope, int deref, int slimit, int tlimit,
242                 Filter *f, char *filterstr, char **attrs, int attrsonly));
243         int     (*be_compare)LDAP_P((Backend *be,
244                 struct slap_conn *c, struct slap_op *o,
245                 char *dn, Ava *ava));
246         int     (*be_modify) LDAP_P((Backend *be,
247                 struct slap_conn *c, struct slap_op *o,
248                 char *dn, LDAPMod *m));
249         int     (*be_modrdn) LDAP_P((Backend *be,
250                 struct slap_conn *c, struct slap_op *o,
251                 char *dn, char *newrdn, int deleteoldrdn ));
252         int     (*be_add)    LDAP_P((Backend *be,
253                 struct slap_conn *c, struct slap_op *o,
254                 Entry *e));
255         int     (*be_delete) LDAP_P((Backend *be,
256                 struct slap_conn *c, struct slap_op *o,
257                 char *dn));
258         /* Bug: be_abandon in unused! */
259         void    (*be_abandon)LDAP_P((Backend *be,
260                 struct slap_conn *c, struct slap_op *o,
261                 int msgid));
262         void    (*be_config) LDAP_P((Backend *be,
263                 char *fname, int lineno, int argc, char **argv ));
264         void    (*be_init)   LDAP_P((Backend *be));
265         void    (*be_close)  LDAP_P((Backend *be));
266
267 #ifdef SLAPD_ACLGROUPS
268         int     (*be_group)  LDAP_P((Backend *be, Entry *e,
269                 char *bdn, char *edn,
270                 char *objectclassValue, char *groupattrName ));
271 #endif
272 };
273
274 /*
275  * represents an operation pending from an ldap client
276  */
277
278 typedef struct slap_op {
279         BerElement      *o_ber;         /* ber of the request             */
280         long            o_msgid;        /* msgid of the request           */
281         unsigned long   o_tag;          /* tag of the request             */
282         time_t          o_time;         /* time op was initiated          */
283         char            *o_dn;          /* dn bound when op was initiated */
284         char            *o_ndn;         /* normalized dn bound when op was initiated */
285         int             o_authtype;     /* auth method used to bind dn    */
286                                         /* values taken from ldap.h       */
287                                         /* LDAP_AUTH_*                    */
288         int             o_opid;         /* id of this operation           */
289         int             o_connid;       /* id of conn initiating this op  */
290 #ifdef LDAP_CONNECTIONLESS
291         int             o_cldap;        /* != 0 if this came in via CLDAP */
292         struct sockaddr o_clientaddr;   /* client address if via CLDAP    */
293         char            o_searchbase;   /* search base if via CLDAP       */
294 #endif
295         struct slap_op  *o_next;        /* next operation pending         */
296         ldap_pvt_thread_t       o_tid;          /* thread handling this op        */
297         int             o_abandon;      /* signals op has been abandoned  */
298         ldap_pvt_thread_mutex_t o_abandonmutex; /* signals op has been abandoned  */
299
300         void    *o_private;     /* anything the backend needs     */
301 } Operation;
302
303 /*
304  * represents a connection from an ldap client
305  */
306
307 typedef struct slap_conn {
308         Sockbuf         c_sb;           /* ber connection stuff           */
309         char            *c_cdn;         /* DN provided by the client */
310         char            *c_dn;          /* DN bound to this conn  */
311         ldap_pvt_thread_mutex_t c_dnmutex;      /* mutex for c_dn field           */
312         int             c_authtype;     /* auth method used to bind c_dn  */
313 #ifdef LDAP_COMPAT
314         int             c_version;      /* for compatibility w/2.0, 3.0   */
315 #endif
316         char            *c_addr;        /* address of client on this conn */
317         char            *c_domain;      /* domain of client on this conn  */
318         Operation       *c_ops;         /* list of pending operations     */
319         ldap_pvt_thread_mutex_t c_opsmutex;     /* mutex for c_ops list & stats   */
320         ldap_pvt_thread_mutex_t c_pdumutex;     /* only one pdu written at a time */
321         ldap_pvt_thread_cond_t  c_wcv;          /* used to wait for sd write-ready*/
322         int             c_gettingber;   /* in the middle of ber_get_next  */
323         BerElement      *c_currentber;  /* ber we're getting              */
324         int             c_writewaiter;  /* signals write-ready sd waiter  */
325         int             c_pduwaiters;   /* signals threads waiting 4 pdu  */
326         time_t          c_starttime;    /* when the connection was opened */
327         int             c_connid;       /* id of this connection for stats*/
328         int             c_opsinitiated; /* # ops initiated/next op id     */
329         int             c_opscompleted; /* # ops completed                */
330 } Connection;
331
332 #if defined(LDAP_SYSLOG) && defined(LDAP_DEBUG)
333 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 )  \
334         { \
335                 if ( ldap_debug & level ) \
336                         fprintf( stderr, fmt, connid, opid, arg1, arg2, arg3 );\
337                 if ( ldap_syslog & level ) \
338                         syslog( ldap_syslog_level, fmt, connid, opid, arg1, \
339                             arg2, arg3 ); \
340         }
341 #else
342 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 )
343 #endif
344
345 #include "proto-slap.h"
346
347 LDAP_END_DECL
348
349 #endif /* _slap_h_ */