]> git.sur5r.net Git - openldap/blob - servers/slapd/back-meta/back-meta.h
cfa95ea1f7b2f291245f14fe1bbc2377611eac0a
[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 #include "cache.h"
98 LDAP_BEGIN_DECL
99
100 struct slap_conn;
101 struct slap_op;
102
103 struct metasingleconn {
104         int                     candidate;
105 #define META_NOT_CANDIDATE      0
106 #define META_CANDIDATE          1
107 #define META_LAST_CONN          -1
108         
109         LDAP                    *ld;
110         struct berval           bound_dn;
111         struct berval           cred;
112         int                     bound;
113 #define META_UNBOUND            0
114 #define META_BOUND              1
115 #define META_ANONYMOUS          2
116 };
117
118 #define META_LAST(lsc)          ((lsc)->candidate == META_LAST_CONN)
119
120 struct metaconn {
121         struct slap_conn        *conn;
122         struct rewrite_info     *rwinfo;
123         
124         /*
125          * means that the connection is bound; 
126          * of course only one target actually is ...
127          */
128         int             bound_target;
129 #define META_BOUND_NONE         -1
130 #define META_BOUND_ALL          -2
131         /* supersedes the connection stuff */
132         struct metasingleconn *conns;
133 };
134
135 struct metatarget {
136         char                    *uri;
137         struct berval           psuffix;        /* pretty suffix */
138         struct berval           suffix;         /* normalized suffix */
139         struct berval           binddn;
140         struct berval           bindpw;
141
142         struct berval           pseudorootdn;
143         struct berval           pseudorootpw;
144
145 #if 0
146         struct rewrite_info     *rwinfo;
147
148         struct ldapmap          oc_map;
149         struct ldapmap          at_map;
150 #endif
151         struct ldaprwmap        rwmap;
152 };
153
154 struct metadncache {
155         ldap_pvt_thread_mutex_t mutex;
156         Avlnode                 *tree;
157
158 #define META_DNCACHE_DISABLED   0
159 #define META_DNCACHE_FOREVER    -1
160         long int                ttl;  /* seconds; 0: no cache, -1: no expiry */
161 };
162
163 struct metainfo {
164         int                     ntargets;
165         int                     defaulttarget;
166         int                     network_timeout;
167 #define META_DEFAULT_TARGET_NONE        -1
168         struct metatarget       **targets;
169
170         struct rewrite_info     *rwinfo;
171         cache_manager           *cm; 
172         Backend                 *glue_be; 
173
174         struct metadncache      cache;
175         
176         ldap_pvt_thread_mutex_t conn_mutex;
177         Avlnode                 *conntree;
178
179         int                     savecred;
180 };
181
182 #define META_OP_ALLOW_MULTIPLE          0x00
183 #define META_OP_REQUIRE_SINGLE          0x01
184 #define META_OP_REQUIRE_ALL             0x02
185 extern struct metaconn *
186 meta_back_getconn(
187                 Operation               *op,
188                 SlapReply               *rs,
189                 int                     op_type,
190                 struct berval           *dn,
191                 int                     *candidate
192 );
193
194 extern int
195 meta_back_dobind(
196                 struct metaconn         *lc,
197                 Operation               *op
198 );
199
200 extern int
201 meta_back_is_valid(
202                 struct metaconn         *lc, 
203                 int                     candidate 
204 );
205
206 extern int
207 meta_back_op_result(
208                 struct metaconn         *lc,
209                 Operation               *op,
210                 SlapReply               *rs
211 );
212
213 extern int
214 back_meta_LTX_init_module(
215                 int                     argc,
216                 char                    *argv[]
217 );
218
219 extern int
220 meta_back_conn_cmp(
221                 const void              *c1,
222                 const void              *c2
223 );
224
225 extern int
226 meta_back_conn_dup(
227                 void                    *c1,
228                 void                    *c2
229 );
230
231 /*
232  * Candidate stuff
233  */
234 extern int
235 meta_back_is_candidate(
236                 struct berval           *nsuffix,
237                 struct berval           *ndn
238 );
239
240 extern int
241 meta_back_count_candidates(
242                 struct metainfo         *li,
243                 struct berval           *ndn
244 );
245
246 extern int
247 meta_back_is_candidate_unique(
248                 struct metainfo         *li,
249                 struct berval           *ndn
250 );
251
252 extern int
253 meta_back_select_unique_candidate(
254                 struct metainfo         *li,
255                 struct berval           *ndn
256 );
257
258 extern int
259 meta_clear_unused_candidates(
260                 struct metainfo         *li,
261                 struct metaconn         *lc,
262                 int                     candidate,
263                 int                     reallyclean
264 );
265
266 extern int
267 meta_clear_one_candidate(
268                 struct metasingleconn   *lc,
269                 int                     reallyclean
270 );
271
272 /*
273  * Dn cache stuff (experimental)
274  */
275 extern int
276 meta_dncache_cmp(
277                 const void              *c1,
278                 const void              *c2
279 );
280
281 extern int
282 meta_dncache_dup(
283                 void                    *c1,
284                 void                    *c2
285 );
286
287 extern int
288 meta_dncache_get_target(
289                 struct metadncache      *cache,
290                 struct berval           *ndn
291 );
292
293 extern int
294 meta_dncache_update_entry(
295                 struct metadncache      *cache,
296                 struct berval           *ndn,
297                 int                     target
298 );
299
300 extern int
301 meta_dncache_delete_entry(
302                 struct metadncache      *cache,
303                 struct berval           *ndn
304 );
305
306 extern void
307 meta_dncache_free(
308                 void *entry
309 );
310
311 LDAP_END_DECL
312
313 #endif /* SLAPD_META_H */
314