]> git.sur5r.net Git - openldap/blob - servers/slapd/overlays/translucent.c
13e37ff9be714ff3a53e75b3f07bb5181f5640ad
[openldap] / servers / slapd / overlays / translucent.c
1 /* translucent.c - translucent proxy module */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2004-2005 The OpenLDAP Foundation.
6  * Portions Copyright 2005 Symas Corporation.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted only as authorized by the OpenLDAP
11  * Public License.
12  *
13  * A copy of this license is available in the file LICENSE in the
14  * top-level directory of the distribution or, alternatively, at
15  * <http://www.OpenLDAP.org/license.html>.
16  */
17 /* ACKNOWLEDGEMENTS:
18  * This work was initially developed by Symas Corp. for inclusion in
19  * OpenLDAP Software.  This work was sponsored by Hewlett-Packard.
20  */
21
22 #include "portable.h"
23
24 #ifdef SLAPD_OVER_TRANSLUCENT
25
26 #include <stdio.h>
27
28 #include <ac/string.h>
29 #include <ac/socket.h>
30
31 #include "slap.h"
32
33 /* config block */
34
35 typedef struct translucent_configuration {
36         int debug;
37         int strict;
38         int no_add;
39         int glue;
40 } translucent_configuration;
41
42 /* stack of captive backends */
43
44 typedef struct overlay_stack {
45         BackendInfo *info;                      /* captive backend */
46         void *private;                          /* local backend_private */
47         translucent_configuration *config;      /* our_private: configuration */
48 } overlay_stack;
49
50 /* for translucent_init() */
51
52 static slap_overinst translucent;
53
54 /*
55 ** glue_parent()
56 **      call syncrepl_add_glue() with the parent suffix;
57 **
58 */
59
60 static struct berval glue[] = { BER_BVC("top"), BER_BVC("glue"), BER_BVNULL };
61
62 void glue_parent(Operation *op) {
63         Operation nop = *op;
64         slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
65         struct berval dn = { 0, NULL };
66         Attribute *a;
67         Entry *e;
68         struct berval   pdn;
69
70         dnParent( &op->o_req_ndn, &pdn );
71         ber_dupbv( &dn, &pdn );
72
73         Debug(LDAP_DEBUG_TRACE, "=> glue_parent: fabricating glue for <%s>\n", dn.bv_val, 0, 0);
74
75         e = ch_calloc(1, sizeof(Entry));
76         e->e_id = NOID;
77         ber_dupbv(&e->e_name, &dn);
78         ber_dupbv(&e->e_nname, &dn);
79
80         a = ch_calloc(1, sizeof(Attribute));
81         a->a_desc = slap_schema.si_ad_objectClass;
82         a->a_vals = ch_malloc(sizeof(struct berval) * 3);
83         ber_dupbv(&a->a_vals[0], &glue[0]);
84         ber_dupbv(&a->a_vals[1], &glue[1]);
85         ber_dupbv(&a->a_vals[2], &glue[2]);
86         a->a_nvals = a->a_vals;
87         a->a_next = e->e_attrs;
88         e->e_attrs = a;
89
90         a = ch_calloc(1, sizeof(Attribute));
91         a->a_desc = slap_schema.si_ad_structuralObjectClass;
92         a->a_vals = ch_malloc(sizeof(struct berval) * 2);
93         ber_dupbv(&a->a_vals[0], &glue[1]);
94         ber_dupbv(&a->a_vals[1], &glue[2]);
95         a->a_nvals = a->a_vals;
96         a->a_next = e->e_attrs;
97         e->e_attrs = a;
98
99         nop.o_req_dn = dn;
100         nop.o_req_ndn = dn;
101         nop.ora_e = e;
102         nop.o_bd->bd_info = (BackendInfo *) on->on_info->oi_orig;
103
104         syncrepl_add_glue(&nop, e);
105         return;
106 }
107
108 /*
109 ** dup_bervarray()
110 **      copy a BerVarray;
111 */
112
113 BerVarray dup_bervarray(BerVarray b) {
114         int i, len;
115         BerVarray nb;
116         for(len = 0; b[len].bv_val; len++);
117         nb = ch_malloc((len+1) * sizeof(BerValue));
118         for(i = 0; i < len; i++) ber_dupbv(&nb[i], &b[i]);
119         nb[len].bv_val = NULL;
120         nb[len].bv_len = 0;
121         return(nb);
122 }
123
124 /*
125 ** free_attr_chain()
126 **      free only the Attribute*, not the contents;
127 **
128 */
129 void free_attr_chain(Attribute *a) {
130         Attribute *ax;
131         for(ax = NULL; a; a = a->a_next) {
132                 if(ax) ch_free(ax);
133                 ax = a;
134         }
135         return;
136 }
137
138 /*
139 ** translucent_add()
140 **      if not bound as root, send ACCESS error;
141 **      if config.glue, glue_parent();
142 **      return CONTINUE;
143 **
144 */
145
146 static int translucent_add(Operation *op, SlapReply *rs) {
147         slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
148         overlay_stack *ov = on->on_bi.bi_private;
149         Debug(LDAP_DEBUG_TRACE, "==> translucent_add: %s\n",
150                 op->o_req_dn.bv_val, 0, 0);
151         if(!be_isroot(op)) {
152                 op->o_bd->bd_info = (BackendInfo *) on->on_info;
153                 send_ldap_error(op, rs, LDAP_INSUFFICIENT_ACCESS,
154                         "user modification of overlay database not permitted");
155                 return(rs->sr_err);
156         }
157         if(!ov->config->glue) glue_parent(op);
158         return(SLAP_CB_CONTINUE);
159 }
160
161 /*
162 ** translucent_modrdn()
163 **      if not bound as root, send ACCESS error;
164 **      if !config.glue, glue_parent();
165 **      else return CONTINUE;
166 **
167 */
168
169 static int translucent_modrdn(Operation *op, SlapReply *rs) {
170         slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
171         overlay_stack *ov = on->on_bi.bi_private;
172         Debug(LDAP_DEBUG_TRACE, "==> translucent_modrdn: %s -> %s\n",
173                 op->o_req_dn.bv_val, op->orr_newrdn.bv_val, 0);
174         if(!be_isroot(op)) {
175                 op->o_bd->bd_info = (BackendInfo *) on->on_info;
176                 send_ldap_error(op, rs, LDAP_INSUFFICIENT_ACCESS,
177                         "user modification of overlay database not permitted");
178                 return(rs->sr_err);
179         }
180         if(!ov->config->glue) glue_parent(op);
181         return(SLAP_CB_CONTINUE);
182 }
183
184 /*
185 ** translucent_delete()
186 **      if not bound as root, send ACCESS error;
187 **      else return CONTINUE;
188 **
189 */
190
191 static int translucent_delete(Operation *op, SlapReply *rs) {
192         slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
193         Debug(LDAP_DEBUG_TRACE, "==> translucent_delete: %s\n",
194                 op->o_req_dn.bv_val, 0, 0);
195         if(!be_isroot(op)) {
196                 op->o_bd->bd_info = (BackendInfo *) on->on_info;
197                 send_ldap_error(op, rs, LDAP_INSUFFICIENT_ACCESS,
198                         "user modification of overlay database not permitted");
199                 return(rs->sr_err);
200         }
201         return(SLAP_CB_CONTINUE);
202 }
203
204 static int
205 translucent_tag_cb( Operation *op, SlapReply *rs )
206 {
207         op->o_tag = (ber_tag_t)op->o_callback->sc_private;
208         rs->sr_tag = slap_req2res( op->o_tag );
209
210         return SLAP_CB_CONTINUE;
211 }
212
213 /*
214 ** translucent_modify()
215 **      modify in local backend if exists in both;
216 **      otherwise, add to local backend;
217 **      fail if not defined in captive backend;
218 **
219 */
220
221 static int translucent_modify(Operation *op, SlapReply *rs) {
222         SlapReply nrs = { REP_RESULT };
223         Operation nop = *op;
224
225         slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
226         overlay_stack *ov = on->on_bi.bi_private;
227         void *private = op->o_bd->be_private;
228         Entry ne, *e, *re = NULL;
229         Attribute *a, *ax;
230         Modifications *m, *mm;
231         int del, rc, erc = 0;
232         slap_callback cb = { 0 }, *save_cb;
233
234         Debug(LDAP_DEBUG_TRACE, "==> translucent_modify: %s\n",
235                 op->o_req_dn.bv_val, 0, 0);
236
237 /*
238 ** fetch entry from the captive backend;
239 ** if it did not exist, fail;
240 ** release it, if captive backend supports this;
241 **
242 */
243
244         op->o_bd->bd_info = (BackendInfo *) on->on_info;
245         op->o_bd->be_private = ov->private;
246         rc = ov->info->bi_entry_get_rw(op, &op->o_req_ndn, NULL, NULL, 0, &re);
247         op->o_bd->be_private = private;
248
249         /* if(ov->config->no_add && (!re || rc != LDAP_SUCCESS)) */
250         if(!re || rc != LDAP_SUCCESS) {
251                 send_ldap_error(op, rs, LDAP_NO_SUCH_OBJECT,
252                         "attempt to modify nonexistent local record");
253                 return(rs->sr_err);
254         }
255
256 /*
257 ** fetch entry from local backend;
258 ** if it exists:
259 **      foreach Modification:
260 **          if attr not present in local:
261 **              if Mod == LDAP_MOD_DELETE:
262 **                  if remote attr not present, return NO_SUCH;
263 **                  if remote attr present, drop this Mod;
264 **              else force this Mod to LDAP_MOD_ADD;
265 **      return CONTINUE;
266 **
267 */
268
269         rc = be_entry_get_rw(op, &op->o_req_ndn, NULL, NULL, 0, &e);
270
271         if(e && rc == LDAP_SUCCESS) {
272                 Debug(LDAP_DEBUG_TRACE, "=> translucent_modify: found local entry\n", 0, 0, 0);
273                 for(m = op->orm_modlist; m; m = m->sml_next) {
274                         for(a = e->e_attrs; a; a = a->a_next)
275                                 if(a->a_desc == m->sml_desc) break;
276                         if(a) continue;         /* found local attr */
277                         if(m->sml_op == LDAP_MOD_DELETE) {
278                                 for(a = re->e_attrs; a; a = a->a_next)
279                                         if(a->a_desc == m->sml_desc) break;
280                                 /* not found remote attr */
281                                 if(!a) {
282                                         erc = LDAP_NO_SUCH_ATTRIBUTE;
283                                         goto release;
284                                 }
285                                 if(ov->config->strict) {
286                                         erc = LDAP_CONSTRAINT_VIOLATION;
287                                         goto release;
288                                 }
289                                 Debug(LDAP_DEBUG_TRACE,
290                                         "=> translucent_modify: silently dropping delete: %s\n",
291                                         m->sml_desc->ad_cname.bv_val, 0, 0);
292                                 for(mm = op->orm_modlist; mm->sml_next != m; mm = mm->sml_next);
293                                 mm->sml_next = m->sml_next;
294                                 mm = m;
295                                 m = m->sml_next;
296                                 mm->sml_next = NULL;            /* hack */
297                                 slap_mods_free(mm, 1);
298                                 if(m) continue;
299                         }
300                         m->sml_op = LDAP_MOD_ADD;
301                 }
302                 erc = SLAP_CB_CONTINUE;
303 release:
304                 if(re) {
305                         op->o_bd->be_private = ov->private;
306                         if(ov->info->bi_entry_release_rw)
307                                 ov->info->bi_entry_release_rw(op, re, 0);
308                         else
309                                 entry_free(re);
310                         op->o_bd->be_private = private;
311                 }
312                 be_entry_release_r(op, e);
313                 if(erc == SLAP_CB_CONTINUE) {
314                         op->o_bd->bd_info = (BackendInfo *) on;
315                         return(erc);
316                 } else if(erc) {
317                         send_ldap_error(op, rs, erc,
318                                 "attempt to delete nonexistent attribute");
319                         return(erc);
320                 }
321         }
322
323 /*
324 ** foreach Modification:
325 **      if MOD_ADD or MOD_REPLACE, add Attribute;
326 ** if no Modifications were suitable:
327 **      if config.strict, throw CONSTRAINT_VIOLATION;
328 **      else, return early SUCCESS;
329 ** fabricate Entry with new Attribute chain;
330 ** glue_parent() for this Entry;
331 ** call bi_op_add() in local backend;
332 **
333 */
334
335         Debug(LDAP_DEBUG_TRACE, "=> translucent_modify: fabricating local add\n", 0, 0, 0);
336         a = NULL;
337         for(del = 0, ax = NULL, m = op->orm_modlist; m; m = m->sml_next) {
338                 if(((m->sml_op & LDAP_MOD_OP) != LDAP_MOD_ADD) &&
339                    ((m->sml_op & LDAP_MOD_OP) != LDAP_MOD_REPLACE)) {
340                         Debug(LDAP_DEBUG_ANY,
341                                 "=> translucent_modify: silently dropped modification(%d): %s\n",
342                                 m->sml_op, m->sml_desc->ad_cname.bv_val, 0);
343                         if((m->sml_op & LDAP_MOD_OP) == LDAP_MOD_DELETE) del++;
344                         continue;
345                 }
346                 a = ch_calloc(1, sizeof(Attribute));
347                 a->a_desc  = m->sml_desc;
348                 a->a_vals  = m->sml_values;
349                 a->a_nvals = m->sml_nvalues;
350                 a->a_next  = ax;
351                 ax = a;
352         }
353
354         if(del && ov->config->strict) {
355                 free_attr_chain(a);
356                 send_ldap_error(op, rs, LDAP_CONSTRAINT_VIOLATION,
357                         "attempt to delete attributes from local database");
358                 return(rs->sr_err);
359         }
360
361         if(!ax) {
362                 if(ov->config->strict) {
363                         send_ldap_error(op, rs, LDAP_CONSTRAINT_VIOLATION,
364                                 "modification contained other than ADD or REPLACE");
365                         return(rs->sr_err);
366                 }
367                 op->o_bd->bd_info = (BackendInfo *) on;
368                 /* rs->sr_text = "no valid modification found"; */
369                 rs->sr_err = LDAP_SUCCESS;
370                 send_ldap_result(op, rs);
371                 return(rs->sr_err);
372         }
373
374         ne.e_id         = NOID;
375         ne.e_name       = op->o_req_dn;
376         ne.e_nname      = op->o_req_ndn;
377         ne.e_attrs      = a;
378         ne.e_ocflags    = 0;
379         ne.e_bv.bv_len  = 0;
380         ne.e_bv.bv_val  = NULL;
381         ne.e_private    = NULL;
382
383         nop.o_tag       = LDAP_REQ_ADD;
384         nop.oq_add.rs_e = &ne;
385
386         op->o_bd->bd_info = (BackendInfo *) on;
387         glue_parent(&nop);
388
389         save_cb = op->o_callback;
390         cb.sc_response = translucent_tag_cb;
391         cb.sc_private = (void *)LDAP_REQ_MODIFY;
392         cb.sc_next = nop.o_callback;
393         nop.o_callback = &cb;
394         rc = on->on_info->oi_orig->bi_op_add(&nop, &nrs);
395         nop.o_callback = save_cb;
396         free_attr_chain(a);
397
398         return(rc);
399 }
400
401 static int translucent_compare(Operation *op, SlapReply *rs) {
402         slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
403         overlay_stack *ov = on->on_bi.bi_private;
404         void *private = op->o_bd->be_private;
405
406         AttributeAssertion *ava = op->orc_ava;
407         Entry *e;
408         int rc;
409
410         Debug(LDAP_DEBUG_TRACE, "==> translucent_compare: <%s> %s:%s\n",
411                 op->o_req_dn.bv_val, ava->aa_desc->ad_cname.bv_val, ava->aa_value.bv_val);
412
413 /*
414 ** if the local backend has an entry for this attribute:
415 **      CONTINUE and let it do the compare;
416 **
417 */
418
419         op->o_bd->bd_info = (BackendInfo *) on->on_info;
420         rc = be_entry_get_rw(op, &op->o_req_ndn, NULL, ava->aa_desc, 0, &e);
421         if(e && rc == LDAP_SUCCESS) {
422                 be_entry_release_r(op, e);
423                 op->o_bd->bd_info = (BackendInfo *) on;
424                 return(SLAP_CB_CONTINUE);
425         }
426
427 /*
428 ** call compare() in the captive backend;
429 ** return the result;
430 **
431 */
432
433         op->o_bd->be_private = ov->private;
434         rc = ov->info->bi_op_compare(op, rs);
435         op->o_bd->be_private = private;
436         op->o_bd->bd_info = (BackendInfo *) on;
437         return(rc);
438 }
439
440 /*
441 ** translucent_search_cb()
442 **      merge local data with the search result
443 **
444 */
445
446 static int translucent_search_cb(Operation *op, SlapReply *rs) {
447         slap_overinst *on;
448         Entry *e, *re = NULL;
449         Attribute *a, *ax, *an, *as = NULL;
450         void *private;
451         int rc;
452
453         if(!op || !rs || rs->sr_type != REP_SEARCH || !rs->sr_entry)
454                 return(SLAP_CB_CONTINUE);
455
456         Debug(LDAP_DEBUG_TRACE, "==> tranclucent_search_cb: %s\n",
457                 rs->sr_entry->e_name.bv_val, 0, 0);
458
459         on = (slap_overinst *) op->o_bd->bd_info;
460         op->o_bd->bd_info = (BackendInfo *) on->on_info;
461
462         private = op->o_bd->be_private;
463         op->o_bd->be_private = op->o_callback->sc_private;
464
465         rc = be_entry_get_rw(op, &rs->sr_entry->e_nname, NULL, NULL, 0, &e);
466
467 /*
468 ** if we got an entry from local backend:
469 **      make a copy of this search result;
470 **      foreach local attr:
471 **              foreach search result attr:
472 **                      if match, result attr with local attr;
473 **                      if new local, add to list;
474 **      append new local attrs to search result;
475 **
476 */
477
478         if(e && rc == LDAP_SUCCESS) {
479                 re = entry_dup(rs->sr_entry);
480                 for(ax = e->e_attrs; ax; ax = ax->a_next) {
481 #if 0
482                         if(is_at_operational(ax->a_desc->ad_type)) continue;
483 #endif
484                         for(a = re->e_attrs; a; a = a->a_next) {
485                                 if(a->a_desc == ax->a_desc) {
486                                         if(a->a_vals != a->a_nvals)
487                                                 ber_bvarray_free(a->a_nvals);
488                                         ber_bvarray_free(a->a_vals);
489                                         a->a_vals = dup_bervarray(ax->a_vals);
490                                         a->a_nvals = (ax->a_vals == ax->a_nvals) ?
491                                                 a->a_vals : dup_bervarray(ax->a_nvals);
492                                         break;
493                                 }
494                         }
495                         if(a) continue;
496                         an = attr_dup(ax);
497                         an->a_next = as;
498                         as = an;
499                 }
500                 be_entry_release_r(op, e);
501
502                 /* literally append, so locals are always last */
503                 if(as) {
504                         if(re->e_attrs) {
505                                 for(ax = re->e_attrs; ax->a_next; ax = ax->a_next);
506                                 ax->a_next = as;
507                         } else {
508                                 re->e_attrs = as;
509                         }
510                 }
511                 rs->sr_entry = re;
512                 rs->sr_flags |= REP_ENTRY_MUSTBEFREED;
513         }
514
515         op->o_bd->be_private = private;
516         op->o_bd->bd_info = (BackendInfo *) on;
517
518         return(SLAP_CB_CONTINUE);
519 }
520
521 /*
522 ** translucent_search()
523 **      search via captive backend;
524 **      override results with any local data;
525 **
526 */
527
528 static int translucent_search(Operation *op, SlapReply *rs) {
529         Operation nop = *op;
530
531         slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
532         slap_callback cb = { NULL, NULL, NULL, NULL };
533         overlay_stack *ov = on->on_bi.bi_private;
534         void *private = op->o_bd->be_private;
535         int rc;
536
537         Debug(LDAP_DEBUG_TRACE, "==> translucent_search: <%s> %s\n",
538                 op->o_req_dn.bv_val, op->ors_filterstr.bv_val, 0);
539         cb.sc_response = (slap_response *) translucent_search_cb;
540         cb.sc_private = private;
541
542         cb.sc_next = nop.o_callback;
543         nop.o_callback = &cb;
544
545         op->o_bd->be_private = ov->private;
546         rc = ov->info->bi_op_search(&nop, rs);
547         op->o_bd->be_private = private;
548
549         return(rs->sr_err);
550 }
551
552
553 /*
554 ** translucent_bind()
555 **      pass bind request to captive backend;
556 **
557 */
558
559 static int translucent_bind(Operation *op, SlapReply *rs) {
560         slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
561         overlay_stack *ov = on->on_bi.bi_private;
562         void *private = op->o_bd->be_private;
563         int rc = 0;
564
565         Debug(LDAP_DEBUG_TRACE, "translucent_bind: <%s> method %d\n",
566                 op->o_req_dn.bv_val, op->orb_method, 0);
567
568         op->o_bd->be_private = ov->private;
569         rc = ov->info->bi_op_bind(op, rs);
570         op->o_bd->be_private = private;
571
572         return(rc);
573 }
574
575 /*
576 ** translucent_config()
577 **      pass config directives to captive backend;
578 **      parse unrecognized directives ourselves;
579 **
580 */
581
582 static int translucent_config(
583         BackendDB       *be,
584         const char      *fname,
585         int             lineno,
586         int             argc,
587         char            **argv
588 )
589 {
590         slap_overinst *on = (slap_overinst *) be->bd_info;
591         overlay_stack *ov = on->on_bi.bi_private;
592         void *private = be->be_private;
593         void *be_cf_ocs = be->be_cf_ocs;
594         int rc;
595
596         /* "this should never happen" */
597         if(!ov->info) {
598                 fprintf(stderr, "fatal: captive backend not initialized");
599                 return(1);
600         }
601
602         be->be_private = ov->private;
603         be->be_cf_ocs = ov->info->bi_cf_ocs;
604         rc = ov->info->bi_db_config ? ov->info->bi_db_config(be, fname, lineno, argc, argv) : 0;
605         be->be_private = private;
606         be->be_cf_ocs = be_cf_ocs;
607
608         /* pass okay or error up, SLAP_CONF_UNKNOWN might be ours */
609         if(rc == 0 || rc == 1) return(rc);
610
611         rc = 0;
612         if(!strcasecmp(*argv, "translucent_strict")) {
613                 ov->config->strict++;
614         } else if(!strcasecmp(*argv, "translucent_no_add")) {
615                 ov->config->no_add++;
616         } else if(!strcasecmp(*argv, "translucent_no_glue")) {
617                 ov->config->glue++;
618         } else if(!strcasecmp(*argv, "translucent_debug")) {
619                 if(argc == 1) {
620                         ov->config->debug = 0xFFFF;
621                         rc = 0;
622                 } else if(argc == 2) {
623                         ov->config->debug = atoi(argv[1]);
624                         rc = 0;
625                 } else {
626                         fprintf(stderr, "%s: line %d: too many arguments (%d) to debug\n",
627                                 fname, lineno, argc);
628                         rc = 1;
629                 }
630         } else {
631                 fprintf(stderr, "%s: line %d: unknown keyword %s\n",
632                         fname, lineno, *argv);
633                 rc = SLAP_CONF_UNKNOWN;
634         }
635         return(rc);
636 }
637
638 /*
639 ** translucent_db_init()
640 **      initialize the captive backend;
641 **
642 */
643
644 static int translucent_db_init(BackendDB *be) {
645         slap_overinst *on = (slap_overinst *) be->bd_info;
646         void *private = be->be_private;
647         overlay_stack *ov;
648         int rc;
649
650         Debug(LDAP_DEBUG_TRACE, "==> translucent_init\n", 0, 0, 0);
651
652         ov = ch_calloc(1, sizeof(overlay_stack));
653         ov->config = ch_calloc(1, sizeof(translucent_configuration));
654         ov->info = backend_info("ldap");
655
656         if(!ov->info) {
657                 Debug(LDAP_DEBUG_ANY, "translucent: backend_info failed!\n", 0, 0, 0);
658                 return(1);
659         }
660
661         /* forcibly disable schema checking on the local backend */
662         SLAP_DBFLAGS(be) |= SLAP_DBFLAG_NO_SCHEMA_CHECK;
663
664         be->be_private = NULL;
665         rc = ov->info->bi_db_init ? ov->info->bi_db_init(be) : 0;
666
667         if(rc) Debug(LDAP_DEBUG_TRACE,
668                 "translucent: bi_db_init() returned error %d\n", rc, 0, 0);
669
670         ov->private = be->be_private;
671         be->be_private = private;
672         on->on_bi.bi_private = ov;
673         return(rc);
674 }
675
676 /*
677 ** translucent_open()
678 **      if the captive backend has an open() method, call it;
679 **
680 */
681
682 static int translucent_open(BackendDB *be) {
683         slap_overinst *on = (slap_overinst *) be->bd_info;
684         overlay_stack *ov = on->on_bi.bi_private;
685         void *private = be->be_private;
686         int rc;
687
688         /* "should never happen" */
689         if(!ov->info) {
690                 Debug(LDAP_DEBUG_ANY, "translucent_open() called with bad ov->info\n", 0, 0, 0);
691                 return(LDAP_OTHER);
692         }
693
694         Debug(LDAP_DEBUG_TRACE, "translucent_open\n", 0, 0, 0);
695
696         be->be_private = ov->private;
697         rc = ov->info->bi_db_open ? ov->info->bi_db_open(be) : 0;
698         be->be_private = private;
699
700         if(rc) Debug(LDAP_DEBUG_TRACE,
701                 "translucent: bi_db_open() returned error %d\n", rc, 0, 0);
702
703         return(rc);
704 }
705
706 /*
707 ** translucent_close()
708 **      if the captive backend has a close() method, call it;
709 **      free any config data;
710 **
711 */
712
713 static int translucent_close(BackendDB *be) {
714         slap_overinst *on = (slap_overinst *) be->bd_info;
715         overlay_stack *ov = on->on_bi.bi_private;
716         void *private = be->be_private;
717         int rc;
718
719         be->be_private = ov->private;
720         rc = (ov->info && ov->info->bi_db_close) ? ov->info->bi_db_close(be) : 0;
721         be->be_private = private;
722         if(ov->config) ch_free(ov->config);
723         ch_free(ov);
724         return(rc);
725 }
726
727 /*
728 ** translucent_init()
729 **      initialize the slap_overinst with our entry points;
730 **
731 */
732
733 int translucent_init() {
734
735         translucent.on_bi.bi_type       = "translucent";
736         translucent.on_bi.bi_db_init    = translucent_db_init;
737         translucent.on_bi.bi_db_config  = translucent_config;
738         translucent.on_bi.bi_db_open    = translucent_open;
739         translucent.on_bi.bi_db_close   = translucent_close;
740         translucent.on_bi.bi_op_bind    = translucent_bind;
741         translucent.on_bi.bi_op_add     = translucent_add;
742         translucent.on_bi.bi_op_modify  = translucent_modify;
743         translucent.on_bi.bi_op_modrdn  = translucent_modrdn;
744         translucent.on_bi.bi_op_delete  = translucent_delete;
745         translucent.on_bi.bi_op_search  = translucent_search;
746         translucent.on_bi.bi_op_compare = translucent_compare;
747
748         return(overlay_register(&translucent));
749 }
750
751 #if SLAPD_OVER_TRANSLUCENT == SLAPD_MOD_DYNAMIC && defined(PIC)
752 int init_module(int argc, char *argv[]) {
753         return translucent_init();
754 }
755 #endif
756
757 #endif /* SLAPD_OVER_TRANSLUCENT */
758