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