]> git.sur5r.net Git - openldap/blob - servers/slapd/back-meta/back-meta.h
e6d6464080153480a3e381875c3434ca312164f7
[openldap] / servers / slapd / back-meta / back-meta.h
1 /* $OpenLDAP$ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  *
4  * Copyright 1999-2003 The OpenLDAP Foundation.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted only as authorized by the OpenLDAP
9  * Public License.
10  *
11  * A copy of this license is available in the file LICENSE in the
12  * top-level directory of the distribution or, alternatively, at
13  * <http://www.OpenLDAP.org/license.html>.
14  */
15 /* ACKNOWLEDGEMENTS:
16  * This work was initially developed by the Howard Chu for inclusion
17  * in OpenLDAP Software and subsequently enhanced by Pierangelo
18  * Masarati.
19  */
20 /* This is an altered version */
21 /*
22  * Copyright 1999, Howard Chu, All rights reserved. <hyc@highlandsun.com>
23  *
24  * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
25  *
26  * This work has been developed to fulfill the requirements
27  * of SysNet s.n.c. <http:www.sys-net.it> and it has been donated
28  * to the OpenLDAP Foundation in the hope that it may be useful
29  * to the Open Source community, but WITHOUT ANY WARRANTY.
30  *
31  * Permission is granted to anyone to use this software for any purpose
32  * on any computer system, and to alter it and redistribute it, subject
33  * to the following restrictions:
34  *
35  * 1. The author and SysNet s.n.c. are not responsible for the consequences
36  *    of use of this software, no matter how awful, even if they arise from 
37  *    flaws in it.
38  *
39  * 2. The origin of this software must not be misrepresented, either by
40  *    explicit claim or by omission.  Since few users ever read sources,
41  *    credits should appear in the documentation.
42  *
43  * 3. Altered versions must be plainly marked as such, and must not be
44  *    misrepresented as being the original software.  Since few users
45  *    ever read sources, credits should appear in the documentation.
46  *    SysNet s.n.c. cannot be responsible for the consequences of the
47  *    alterations.
48  *                         
49  * 4. This notice may not be removed or altered.
50  *
51  *
52  * This software is based on the backend back-ldap, implemented
53  * by Howard Chu <hyc@highlandsun.com>, and modified by Mark Valence
54  * <kurash@sassafras.com>, Pierangelo Masarati <ando@sys-net.it> and other
55  * contributors. The contribution of the original software to the present
56  * implementation is acknowledged in this copyright statement.
57  *
58  * A special acknowledgement goes to Howard for the overall architecture
59  * (and for borrowing large pieces of code), and to Mark, who implemented
60  * from scratch the attribute/objectclass mapping.
61  *
62  * The original copyright statement follows.
63  *
64  * Copyright 1999, Howard Chu, All rights reserved. <hyc@highlandsun.com>
65  *
66  * Permission is granted to anyone to use this software for any purpose
67  * on any computer system, and to alter it and redistribute it, subject
68  * to the following restrictions:
69  *
70  * 1. The author is not responsible for the consequences of use of this
71  *    software, no matter how awful, even if they arise from flaws in it.
72  *
73  * 2. The origin of this software must not be misrepresented, either by
74  *    explicit claim or by omission.  Since few users ever read sources,
75  *    credits should appear in the documentation.
76  *
77  * 3. Altered versions must be plainly marked as such, and must not be
78  *    misrepresented as being the original software.  Since few users
79  *    ever read sources, credits should appear in the
80  *    documentation.
81  *
82  * 4. This notice may not be removed or altered.
83  *                
84  */ 
85
86 #ifndef SLAPD_LDAP_H
87 #error "include servers/slapd/back-ldap/back-ldap.h before this file!"
88 #endif /* SLAPD_LDAP_H */
89
90 #ifndef SLAPD_META_H
91 #define SLAPD_META_H
92
93 #include "external.h"
94
95 /* String rewrite library */
96 #include "rewrite.h"
97 LDAP_BEGIN_DECL
98
99 struct slap_conn;
100 struct slap_op;
101
102 struct metasingleconn {
103         int                     candidate;
104 #define META_NOT_CANDIDATE      0
105 #define META_CANDIDATE          1
106 #define META_LAST_CONN          -1
107         
108         LDAP                    *ld;
109         struct berval           bound_dn;
110         struct berval           cred;
111         int                     bound;
112 #define META_UNBOUND            0
113 #define META_BOUND              1
114 #define META_ANONYMOUS          2
115 };
116
117 #define META_LAST(lsc)          ((lsc)->candidate == META_LAST_CONN)
118
119 struct metaconn {
120         struct slap_conn        *conn;
121         struct rewrite_info     *rwinfo;
122         
123         /*
124          * means that the connection is bound; 
125          * of course only one target actually is ...
126          */
127         int             bound_target;
128 #define META_BOUND_NONE         -1
129 #define META_BOUND_ALL          -2
130         /* supersedes the connection stuff */
131         struct metasingleconn *conns;
132 };
133
134 struct metatarget {
135         char                    *uri;
136         struct berval           psuffix;        /* pretty suffix */
137         struct berval           suffix;         /* normalized suffix */
138         struct berval           binddn;
139         struct berval           bindpw;
140
141         struct berval           pseudorootdn;
142         struct berval           pseudorootpw;
143
144 #if 0
145         struct rewrite_info     *rwinfo;
146
147         struct ldapmap          oc_map;
148         struct ldapmap          at_map;
149 #endif
150         struct ldaprwmap        rwmap;
151 };
152
153 struct metadncache {
154         ldap_pvt_thread_mutex_t mutex;
155         Avlnode                 *tree;
156
157 #define META_DNCACHE_DISABLED   0
158 #define META_DNCACHE_FOREVER    -1
159         long int                ttl;  /* seconds; 0: no cache, -1: no expiry */
160 };
161
162 struct metainfo {
163         int                     ntargets;
164         int                     defaulttarget;
165         int                     network_timeout;
166 #define META_DEFAULT_TARGET_NONE        -1
167         struct metatarget       **targets;
168
169         struct rewrite_info     *rwinfo;
170         Backend                 *glue_be; 
171
172         struct metadncache      cache;
173         
174         ldap_pvt_thread_mutex_t conn_mutex;
175         Avlnode                 *conntree;
176
177         int                     savecred;
178 };
179
180 #define META_OP_ALLOW_MULTIPLE          0x00
181 #define META_OP_REQUIRE_SINGLE          0x01
182 #define META_OP_REQUIRE_ALL             0x02
183 extern struct metaconn *
184 meta_back_getconn(
185                 Operation               *op,
186                 SlapReply               *rs,
187                 int                     op_type,
188                 struct berval           *dn,
189                 int                     *candidate
190 );
191
192 extern int
193 meta_back_dobind(
194                 struct metaconn         *lc,
195                 Operation               *op
196 );
197
198 extern int
199 meta_back_is_valid(
200                 struct metaconn         *lc, 
201                 int                     candidate 
202 );
203
204 extern int
205 meta_back_op_result(
206                 struct metaconn         *lc,
207                 Operation               *op,
208                 SlapReply               *rs
209 );
210
211 extern int
212 back_meta_LTX_init_module(
213                 int                     argc,
214                 char                    *argv[]
215 );
216
217 extern int
218 meta_back_conn_cmp(
219                 const void              *c1,
220                 const void              *c2
221 );
222
223 extern int
224 meta_back_conn_dup(
225                 void                    *c1,
226                 void                    *c2
227 );
228
229 /*
230  * Candidate stuff
231  */
232 extern int
233 meta_back_is_candidate(
234                 struct berval           *nsuffix,
235                 struct berval           *ndn
236 );
237
238 extern int
239 meta_back_count_candidates(
240                 struct metainfo         *li,
241                 struct berval           *ndn
242 );
243
244 extern int
245 meta_back_is_candidate_unique(
246                 struct metainfo         *li,
247                 struct berval           *ndn
248 );
249
250 extern int
251 meta_back_select_unique_candidate(
252                 struct metainfo         *li,
253                 struct berval           *ndn
254 );
255
256 extern int
257 meta_clear_unused_candidates(
258                 struct metainfo         *li,
259                 struct metaconn         *lc,
260                 int                     candidate,
261                 int                     reallyclean
262 );
263
264 extern int
265 meta_clear_one_candidate(
266                 struct metasingleconn   *lc,
267                 int                     reallyclean
268 );
269
270 /*
271  * Dn cache stuff (experimental)
272  */
273 extern int
274 meta_dncache_cmp(
275                 const void              *c1,
276                 const void              *c2
277 );
278
279 extern int
280 meta_dncache_dup(
281                 void                    *c1,
282                 void                    *c2
283 );
284
285 extern int
286 meta_dncache_get_target(
287                 struct metadncache      *cache,
288                 struct berval           *ndn
289 );
290
291 extern int
292 meta_dncache_update_entry(
293                 struct metadncache      *cache,
294                 struct berval           *ndn,
295                 int                     target
296 );
297
298 extern int
299 meta_dncache_delete_entry(
300                 struct metadncache      *cache,
301                 struct berval           *ndn
302 );
303
304 extern void
305 meta_dncache_free(
306                 void *entry
307 );
308
309 LDAP_END_DECL
310
311 #endif /* SLAPD_META_H */
312