1 /* translucent.c - translucent proxy module */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2004-2008 The OpenLDAP Foundation.
6 * Portions Copyright 2005 Symas Corporation.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
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>.
18 * This work was initially developed by Symas Corp. for inclusion in
19 * OpenLDAP Software. This work was sponsored by Hewlett-Packard.
24 #ifdef SLAPD_OVER_TRANSLUCENT
28 #include <ac/string.h>
29 #include <ac/socket.h>
37 typedef struct translucent_info {
38 BackendDB db; /* captive backend */
39 AttributeName *local; /* valid attrs for local filters */
40 AttributeName *remote; /* valid attrs for remote filters */
47 static ConfigLDAPadd translucent_ldadd;
48 static ConfigCfAdd translucent_cfadd;
50 static ConfigDriver translucent_cf_gen;
57 static ConfigTable translucentcfg[] = {
58 { "translucent_strict", "on|off", 1, 2, 0,
59 ARG_ON_OFF|ARG_OFFSET,
60 (void *)offsetof(translucent_info, strict),
61 "( OLcfgOvAt:14.1 NAME 'olcTranslucentStrict' "
62 "DESC 'Reveal attribute deletion constraint violations' "
63 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
64 { "translucent_no_glue", "on|off", 1, 2, 0,
65 ARG_ON_OFF|ARG_OFFSET,
66 (void *)offsetof(translucent_info, no_glue),
67 "( OLcfgOvAt:14.2 NAME 'olcTranslucentNoGlue' "
68 "DESC 'Disable automatic glue records for ADD and MODRDN' "
69 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
70 { "translucent_local", "attr[,attr...]", 1, 2, 0,
71 ARG_MAGIC|TRANS_LOCAL,
73 "( OLcfgOvAt:14.3 NAME 'olcTranslucentLocal' "
74 "DESC 'Attributes to use in local search filter' "
75 "SYNTAX OMsDirectoryString )", NULL, NULL },
76 { "translucent_remote", "attr[,attr...]", 1, 2, 0,
77 ARG_MAGIC|TRANS_REMOTE,
79 "( OLcfgOvAt:14.4 NAME 'olcTranslucentRemote' "
80 "DESC 'Attributes to use in remote search filter' "
81 "SYNTAX OMsDirectoryString )", NULL, NULL },
82 { "translucent_bind_local", "on|off", 1, 2, 0,
83 ARG_ON_OFF|ARG_OFFSET,
84 (void *)offsetof(translucent_info, bind_local),
85 "( OLcfgOvAt:14.5 NAME 'olcTranslucentBindLocal' "
86 "DESC 'Enable local bind' "
87 "SYNTAX OMsBoolean SINGLE-VALUE)", NULL, NULL },
88 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
91 static ConfigTable transdummy[] = {
92 { "", "", 0, 0, 0, ARG_IGNORED,
93 NULL, "( OLcfgGlAt:13 NAME 'olcDatabase' "
94 "DESC 'The backend type for a database instance' "
95 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
96 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
99 static ConfigOCs translucentocs[] = {
100 { "( OLcfgOvOc:14.1 "
101 "NAME 'olcTranslucentConfig' "
102 "DESC 'Translucent configuration' "
103 "SUP olcOverlayConfig "
104 "MAY ( olcTranslucentStrict $ olcTranslucentNoGlue $"
105 " olcTranslucentLocal $ olcTranslucentRemote $"
106 " olcTranslucentBindLocal ) )",
107 Cft_Overlay, translucentcfg, NULL, translucent_cfadd },
108 { "( OLcfgOvOc:14.2 "
109 "NAME 'olcTranslucentDatabase' "
110 "DESC 'Translucent target database configuration' "
111 "AUXILIARY )", Cft_Misc, transdummy, translucent_ldadd },
114 /* for translucent_init() */
117 translucent_ldadd_cleanup( ConfigArgs *ca )
119 slap_overinst *on = ca->ca_private;
120 translucent_info *ov = on->on_bi.bi_private;
122 ov->defer_db_open = 0;
123 return backend_startup_one( ca->be, &ca->reply );
127 translucent_ldadd( CfEntryInfo *cei, Entry *e, ConfigArgs *ca )
130 translucent_info *ov;
132 Debug(LDAP_DEBUG_TRACE, "==> translucent_ldadd\n", 0, 0, 0);
134 if ( cei->ce_type != Cft_Overlay || !cei->ce_bi ||
135 cei->ce_bi->bi_cf_ocs != translucentocs )
136 return LDAP_CONSTRAINT_VIOLATION;
138 on = (slap_overinst *)cei->ce_bi;
139 ov = on->on_bi.bi_private;
142 if ( CONFIG_ONLINE_ADD( ca ))
143 ca->cleanup = translucent_ldadd_cleanup;
145 ov->defer_db_open = 0;
151 translucent_cfadd( Operation *op, SlapReply *rs, Entry *e, ConfigArgs *ca )
153 CfEntryInfo *cei = e->e_private;
154 slap_overinst *on = (slap_overinst *)cei->ce_bi;
155 translucent_info *ov = on->on_bi.bi_private;
158 Debug(LDAP_DEBUG_TRACE, "==> translucent_cfadd\n", 0, 0, 0);
160 /* FIXME: should not hardcode "olcDatabase" here */
161 bv.bv_len = snprintf( ca->cr_msg, sizeof( ca->cr_msg ),
162 "olcDatabase=%s", ov->db.bd_info->bi_type );
163 if ( bv.bv_len < 0 || bv.bv_len >= sizeof( ca->cr_msg ) ) {
166 bv.bv_val = ca->cr_msg;
168 ov->defer_db_open = 0;
170 /* We can only create this entry if the database is table-driven
172 if ( ov->db.bd_info->bi_cf_ocs )
173 config_build_entry( op, rs, cei, ca, &bv,
174 ov->db.bd_info->bi_cf_ocs,
175 &translucentocs[1] );
181 translucent_cf_gen( ConfigArgs *c )
183 slap_overinst *on = (slap_overinst *)c->bi;
184 translucent_info *ov = on->on_bi.bi_private;
185 AttributeName **an, *a2;
188 if ( c->type == TRANS_LOCAL )
193 if ( c->op == SLAP_CONFIG_EMIT ) {
196 for ( i = 0; !BER_BVISNULL(&(*an)[i].an_name); i++ ) {
197 value_add_one( &c->rvalue_vals, &(*an)[i].an_name );
200 } else if ( c->op == LDAP_MOD_DELETE ) {
202 anlist_free( *an, 1, NULL );
206 ch_free( (*an)[i].an_name.bv_val );
208 (*an)[i] = (*an)[i+1];
209 } while ( !BER_BVISNULL( &(*an)[i].an_name ));
213 a2 = str2anlist( *an, c->argv[1], "," );
215 snprintf( c->cr_msg, sizeof( c->cr_msg ), "%s unable to parse attribute %s",
216 c->argv[0], c->argv[1] );
217 Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE,
218 "%s: %s\n", c->log, c->cr_msg, 0 );
225 static slap_overinst translucent;
229 ** call syncrepl_add_glue() with the parent suffix;
233 static struct berval glue[] = { BER_BVC("top"), BER_BVC("glue"), BER_BVNULL };
235 void glue_parent(Operation *op) {
237 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
238 struct berval ndn = BER_BVNULL;
243 dnParent( &op->o_req_ndn, &pdn );
244 ber_dupbv_x( &ndn, &pdn, op->o_tmpmemctx );
246 Debug(LDAP_DEBUG_TRACE, "=> glue_parent: fabricating glue for <%s>\n", ndn.bv_val, 0, 0);
250 ber_dupbv(&e->e_name, &ndn);
251 ber_dupbv(&e->e_nname, &ndn);
253 a = attr_alloc( slap_schema.si_ad_objectClass );
255 a->a_vals = ch_malloc(sizeof(struct berval) * 3);
256 ber_dupbv(&a->a_vals[0], &glue[0]);
257 ber_dupbv(&a->a_vals[1], &glue[1]);
258 ber_dupbv(&a->a_vals[2], &glue[2]);
259 a->a_nvals = a->a_vals;
260 a->a_next = e->e_attrs;
263 a = attr_alloc( slap_schema.si_ad_structuralObjectClass );
265 a->a_vals = ch_malloc(sizeof(struct berval) * 2);
266 ber_dupbv(&a->a_vals[0], &glue[1]);
267 ber_dupbv(&a->a_vals[1], &glue[2]);
268 a->a_nvals = a->a_vals;
269 a->a_next = e->e_attrs;
276 nop.o_bd->bd_info = (BackendInfo *) on->on_info->oi_orig;
277 syncrepl_add_glue(&nop, e);
278 nop.o_bd->bd_info = (BackendInfo *) on;
280 op->o_tmpfree( ndn.bv_val, op->o_tmpmemctx );
290 BerVarray dup_bervarray(BerVarray b) {
293 for(len = 0; b[len].bv_val; len++);
294 nb = ch_malloc((len+1) * sizeof(BerValue));
295 for(i = 0; i < len; i++) ber_dupbv(&nb[i], &b[i]);
296 nb[len].bv_val = NULL;
303 ** free only the Attribute*, not the contents;
306 void free_attr_chain(Attribute *b) {
308 for(a=b; a; a=a->a_next) {
318 ** if not bound as root, send ACCESS error;
319 ** if glue, glue_parent();
324 static int translucent_add(Operation *op, SlapReply *rs) {
325 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
326 translucent_info *ov = on->on_bi.bi_private;
327 Debug(LDAP_DEBUG_TRACE, "==> translucent_add: %s\n",
328 op->o_req_dn.bv_val, 0, 0);
330 op->o_bd->bd_info = (BackendInfo *) on->on_info;
331 send_ldap_error(op, rs, LDAP_INSUFFICIENT_ACCESS,
332 "user modification of overlay database not permitted");
333 op->o_bd->bd_info = (BackendInfo *) on;
336 if(!ov->no_glue) glue_parent(op);
337 return(SLAP_CB_CONTINUE);
341 ** translucent_modrdn()
342 ** if not bound as root, send ACCESS error;
343 ** if !glue, glue_parent();
344 ** else return CONTINUE;
348 static int translucent_modrdn(Operation *op, SlapReply *rs) {
349 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
350 translucent_info *ov = on->on_bi.bi_private;
351 Debug(LDAP_DEBUG_TRACE, "==> translucent_modrdn: %s -> %s\n",
352 op->o_req_dn.bv_val, op->orr_newrdn.bv_val, 0);
354 op->o_bd->bd_info = (BackendInfo *) on->on_info;
355 send_ldap_error(op, rs, LDAP_INSUFFICIENT_ACCESS,
356 "user modification of overlay database not permitted");
357 op->o_bd->bd_info = (BackendInfo *) on;
361 op->o_tag = LDAP_REQ_ADD;
363 op->o_tag = LDAP_REQ_MODRDN;
365 return(SLAP_CB_CONTINUE);
369 ** translucent_delete()
370 ** if not bound as root, send ACCESS error;
371 ** else return CONTINUE;
375 static int translucent_delete(Operation *op, SlapReply *rs) {
376 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
377 Debug(LDAP_DEBUG_TRACE, "==> translucent_delete: %s\n",
378 op->o_req_dn.bv_val, 0, 0);
380 op->o_bd->bd_info = (BackendInfo *) on->on_info;
381 send_ldap_error(op, rs, LDAP_INSUFFICIENT_ACCESS,
382 "user modification of overlay database not permitted");
383 op->o_bd->bd_info = (BackendInfo *) on;
386 return(SLAP_CB_CONTINUE);
390 translucent_tag_cb( Operation *op, SlapReply *rs )
392 op->o_tag = LDAP_REQ_MODIFY;
393 op->orm_modlist = op->o_callback->sc_private;
394 rs->sr_tag = slap_req2res( op->o_tag );
396 return SLAP_CB_CONTINUE;
400 ** translucent_modify()
401 ** modify in local backend if exists in both;
402 ** otherwise, add to local backend;
403 ** fail if not defined in captive backend;
407 static int translucent_modify(Operation *op, SlapReply *rs) {
408 SlapReply nrs = { REP_RESULT };
410 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
411 translucent_info *ov = on->on_bi.bi_private;
412 Entry *e = NULL, *re = NULL;
414 Modifications *m, **mm;
416 int del, rc, erc = 0;
417 slap_callback cb = { 0 };
419 Debug(LDAP_DEBUG_TRACE, "==> translucent_modify: %s\n",
420 op->o_req_dn.bv_val, 0, 0);
422 if(ov->defer_db_open) {
423 send_ldap_error(op, rs, LDAP_UNAVAILABLE,
424 "remote DB not available");
428 ** fetch entry from the captive backend;
429 ** if it did not exist, fail;
430 ** release it, if captive backend supports this;
436 rc = ov->db.bd_info->bi_entry_get_rw(op, &op->o_req_ndn, NULL, NULL, 0, &re);
437 if(rc != LDAP_SUCCESS || re == NULL ) {
438 send_ldap_error((op), rs, LDAP_NO_SUCH_OBJECT,
439 "attempt to modify nonexistent local record");
444 ** fetch entry from local backend;
446 ** foreach Modification:
447 ** if attr not present in local:
448 ** if Mod == LDAP_MOD_DELETE:
449 ** if remote attr not present, return NO_SUCH;
450 ** if remote attr present, drop this Mod;
451 ** else force this Mod to LDAP_MOD_ADD;
456 op->o_bd->bd_info = (BackendInfo *) on->on_info;
457 rc = be_entry_get_rw(op, &op->o_req_ndn, NULL, NULL, 0, &e);
458 op->o_bd->bd_info = (BackendInfo *) on;
460 if(e && rc == LDAP_SUCCESS) {
461 Debug(LDAP_DEBUG_TRACE, "=> translucent_modify: found local entry\n", 0, 0, 0);
462 for(mm = &op->orm_modlist; *mm; ) {
464 for(a = e->e_attrs; a; a = a->a_next)
465 if(a->a_desc == m->sml_desc) break;
468 continue; /* found local attr */
470 if(m->sml_op == LDAP_MOD_DELETE) {
471 for(a = re->e_attrs; a; a = a->a_next)
472 if(a->a_desc == m->sml_desc) break;
473 /* not found remote attr */
475 erc = LDAP_NO_SUCH_ATTRIBUTE;
479 erc = LDAP_CONSTRAINT_VIOLATION;
482 Debug(LDAP_DEBUG_TRACE,
483 "=> translucent_modify: silently dropping delete: %s\n",
484 m->sml_desc->ad_cname.bv_val, 0, 0);
487 slap_mods_free(m, 1);
490 m->sml_op = LDAP_MOD_ADD;
493 erc = SLAP_CB_CONTINUE;
496 if(ov->db.bd_info->bi_entry_release_rw) {
498 ov->db.bd_info->bi_entry_release_rw(op, re, 0);
503 op->o_bd->bd_info = (BackendInfo *) on->on_info;
504 be_entry_release_r(op, e);
505 op->o_bd->bd_info = (BackendInfo *) on;
506 if(erc == SLAP_CB_CONTINUE) {
509 send_ldap_error(op, rs, erc,
510 "attempt to delete nonexistent attribute");
515 /* don't leak remote entry copy */
517 if(ov->db.bd_info->bi_entry_release_rw) {
519 ov->db.bd_info->bi_entry_release_rw(op, re, 0);
525 ** foreach Modification:
526 ** if MOD_ADD or MOD_REPLACE, add Attribute;
527 ** if no Modifications were suitable:
528 ** if strict, throw CONSTRAINT_VIOLATION;
529 ** else, return early SUCCESS;
530 ** fabricate Entry with new Attribute chain;
531 ** glue_parent() for this Entry;
532 ** call bi_op_add() in local backend;
536 Debug(LDAP_DEBUG_TRACE, "=> translucent_modify: fabricating local add\n", 0, 0, 0);
538 for(del = 0, ax = NULL, m = op->orm_modlist; m; m = m->sml_next) {
540 if(((m->sml_op & LDAP_MOD_OP) != LDAP_MOD_ADD) &&
541 ((m->sml_op & LDAP_MOD_OP) != LDAP_MOD_REPLACE)) {
542 Debug(LDAP_DEBUG_ANY,
543 "=> translucent_modify: silently dropped modification(%d): %s\n",
544 m->sml_op, m->sml_desc->ad_cname.bv_val, 0);
545 if((m->sml_op & LDAP_MOD_OP) == LDAP_MOD_DELETE) del++;
548 atmp.a_desc = m->sml_desc;
549 atmp.a_vals = m->sml_values;
550 atmp.a_nvals = m->sml_nvalues ? m->sml_nvalues : atmp.a_vals;
551 atmp.a_numvals = m->sml_numvals;
553 a = attr_dup( &atmp );
558 if(del && ov->strict) {
560 send_ldap_error(op, rs, LDAP_CONSTRAINT_VIOLATION,
561 "attempt to delete attributes from local database");
567 send_ldap_error(op, rs, LDAP_CONSTRAINT_VIOLATION,
568 "modification contained other than ADD or REPLACE");
571 /* rs->sr_text = "no valid modification found"; */
572 rs->sr_err = LDAP_SUCCESS;
573 send_ldap_result(op, rs);
578 ber_dupbv( &e->e_name, &op->o_req_dn );
579 ber_dupbv( &e->e_nname, &op->o_req_ndn );
582 op->o_tag = LDAP_REQ_ADD;
583 cb.sc_response = translucent_tag_cb;
584 cb.sc_private = op->orm_modlist;
589 cb.sc_next = op->o_callback;
590 op->o_callback = &cb;
591 rc = on->on_info->oi_orig->bi_op_add(op, &nrs);
592 if ( op->ora_e == e )
594 op->o_callback = cb.sc_next;
599 static int translucent_compare(Operation *op, SlapReply *rs) {
600 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
601 translucent_info *ov = on->on_bi.bi_private;
602 AttributeAssertion *ava = op->orc_ava;
607 Debug(LDAP_DEBUG_TRACE, "==> translucent_compare: <%s> %s:%s\n",
608 op->o_req_dn.bv_val, ava->aa_desc->ad_cname.bv_val, ava->aa_value.bv_val);
611 ** if the local backend has an entry for this attribute:
612 ** CONTINUE and let it do the compare;
615 rc = overlay_entry_get_ov(op, &op->o_req_ndn, NULL, ava->aa_desc, 0, &e, on);
616 if(rc == LDAP_SUCCESS && e) {
617 overlay_entry_release_ov(op, e, 0, on);
618 return(SLAP_CB_CONTINUE);
621 if(ov->defer_db_open) {
622 send_ldap_error(op, rs, LDAP_UNAVAILABLE,
623 "remote DB not available");
627 ** call compare() in the captive backend;
628 ** return the result;
633 rc = ov->db.bd_info->bi_op_compare(op, rs);
640 ** translucent_search_cb()
641 ** merge local data with remote data
644 ** 1: remote search, no local filter
645 ** merge data and send immediately
646 ** 2: remote search, with local filter
647 ** merge data and save
648 ** 3: local search, no remote filter
649 ** merge data and send immediately
650 ** 4: local search, with remote filter
651 ** check list, merge, send, delete
658 typedef struct trans_ctx {
666 static int translucent_search_cb(Operation *op, SlapReply *rs) {
670 translucent_info *ov;
672 Attribute *a, *ax, *an, *as = NULL;
676 tc = op->o_callback->sc_private;
678 /* Don't let the op complete while we're gathering data */
679 if ( rs->sr_type == REP_RESULT && ( tc->step & USE_LIST ))
682 if(!op || !rs || rs->sr_type != REP_SEARCH || !rs->sr_entry)
683 return(SLAP_CB_CONTINUE);
685 Debug(LDAP_DEBUG_TRACE, "==> translucent_search_cb: %s\n",
686 rs->sr_entry->e_name.bv_val, 0, 0);
689 ov = on->on_bi.bi_private;
694 /* If we have local, get remote */
695 if ( tc->step & LCL_SIDE ) {
697 /* If entry is already on list, use it */
698 if ( tc->step & USE_LIST ) {
699 re = tavl_delete( &tc->list, le, entry_dn_cmp );
701 if ( rs->sr_flags & REP_ENTRY_MUSTRELEASE ) {
702 rs->sr_flags ^= REP_ENTRY_MUSTRELEASE;
703 be_entry_release_r( op, rs->sr_entry );
705 if ( rs->sr_flags & REP_ENTRY_MUSTBEFREED ) {
706 rs->sr_flags ^= REP_ENTRY_MUSTBEFREED;
707 entry_free( rs->sr_entry );
709 rc = test_filter( op, re, tc->orig );
710 if ( rc == LDAP_COMPARE_TRUE ) {
711 rs->sr_flags |= REP_ENTRY_MUSTBEFREED;
713 return SLAP_CB_CONTINUE;
722 rc = be_entry_get_rw( op, &rs->sr_entry->e_nname, NULL, NULL, 0, &re );
723 if ( rc == LDAP_SUCCESS && re ) {
724 Entry *tmp = entry_dup( re );
725 be_entry_release_r( op, re );
730 /* Else we have remote, get local */
732 rc = overlay_entry_get_ov(op, &rs->sr_entry->e_nname, NULL, NULL, 0, &le, on);
733 if ( rc == LDAP_SUCCESS && le ) {
734 re = entry_dup( rs->sr_entry );
735 if ( rs->sr_flags & REP_ENTRY_MUSTRELEASE ) {
736 rs->sr_flags ^= REP_ENTRY_MUSTRELEASE;
737 be_entry_release_r( op, rs->sr_entry );
739 if ( rs->sr_flags & REP_ENTRY_MUSTBEFREED ) {
740 rs->sr_flags ^= REP_ENTRY_MUSTBEFREED;
741 entry_free( rs->sr_entry );
749 ** if we got remote and local entry:
750 ** foreach local attr:
751 ** foreach remote attr:
752 ** if match, remote attr with local attr;
753 ** if new local, add to list;
754 ** append new local attrs to remote;
759 for(ax = le->e_attrs; ax; ax = ax->a_next) {
760 for(a = re->e_attrs; a; a = a->a_next) {
761 if(a->a_desc == ax->a_desc) {
762 if(a->a_vals != a->a_nvals)
763 ber_bvarray_free(a->a_nvals);
764 ber_bvarray_free(a->a_vals);
765 a->a_vals = dup_bervarray(ax->a_vals);
766 a->a_nvals = (ax->a_vals == ax->a_nvals) ?
767 a->a_vals : dup_bervarray(ax->a_nvals);
776 /* Dispose of local entry */
777 if ( tc->step & LCL_SIDE ) {
778 if ( rs->sr_flags & REP_ENTRY_MUSTRELEASE ) {
779 rs->sr_flags ^= REP_ENTRY_MUSTRELEASE;
780 be_entry_release_r( op, rs->sr_entry );
782 if ( rs->sr_flags & REP_ENTRY_MUSTBEFREED ) {
783 rs->sr_flags ^= REP_ENTRY_MUSTBEFREED;
784 entry_free( rs->sr_entry );
787 overlay_entry_release_ov(op, le, 0, on);
790 /* literally append, so locals are always last */
793 for(ax = re->e_attrs; ax->a_next; ax = ax->a_next);
799 /* If both filters, save entry for later */
800 if ( tc->step == (USE_LIST|RMT_SIDE) ) {
801 tavl_insert( &tc->list, re, entry_dn_cmp, avl_dup_error );
807 rs->sr_flags |= REP_ENTRY_MUSTBEFREED;
809 rc = test_filter( op, rs->sr_entry, tc->orig );
810 if ( rc == LDAP_COMPARE_TRUE ) {
811 rc = SLAP_CB_CONTINUE;
816 rc = SLAP_CB_CONTINUE;
820 /* Only a local entry: remote was deleted
821 * Ought to delete the local too...
824 } else if ( tc->step & USE_LIST ) {
825 /* Only a remote entry, but both filters:
826 * Test the complete filter
828 rc = test_filter( op, rs->sr_entry, tc->orig );
829 if ( rc == LDAP_COMPARE_TRUE ) {
830 rc = SLAP_CB_CONTINUE;
835 /* Only a remote entry, only remote filter:
838 rc = SLAP_CB_CONTINUE;
845 /* Dup the filter, excluding invalid elements */
847 trans_filter_dup(Operation *op, Filter *f, AttributeName *an)
854 switch( f->f_choice & SLAPD_FILTER_MASK ) {
855 case SLAPD_FILTER_COMPUTED:
856 n = op->o_tmpalloc( sizeof(Filter), op->o_tmpmemctx );
857 n->f_choice = f->f_choice;
858 n->f_result = f->f_result;
862 case LDAP_FILTER_PRESENT:
863 if ( ad_inlist( f->f_desc, an )) {
864 n = op->o_tmpalloc( sizeof(Filter), op->o_tmpmemctx );
865 n->f_choice = f->f_choice;
866 n->f_desc = f->f_desc;
871 case LDAP_FILTER_EQUALITY:
874 case LDAP_FILTER_APPROX:
875 case LDAP_FILTER_SUBSTRINGS:
876 case LDAP_FILTER_EXT:
877 if ( !f->f_av_desc || ad_inlist( f->f_av_desc, an )) {
878 n = op->o_tmpalloc( sizeof(Filter), op->o_tmpmemctx );
879 n->f_choice = f->f_choice;
885 case LDAP_FILTER_AND:
887 case LDAP_FILTER_NOT: {
890 n = op->o_tmpalloc( sizeof(Filter), op->o_tmpmemctx );
891 n->f_choice = f->f_choice;
894 for ( p = &n->f_list, f = f->f_list; f; f = f->f_next ) {
895 *p = trans_filter_dup( op, f, an );
900 /* nothing valid in this list */
902 op->o_tmpfree( n, op->o_tmpmemctx );
905 /* Only 1 element in this list */
906 if ((n->f_choice & SLAPD_FILTER_MASK) != LDAP_FILTER_NOT &&
907 !n->f_list->f_next ) {
910 op->o_tmpfree( f, op->o_tmpmemctx );
919 trans_filter_free( Operation *op, Filter *f )
921 Filter *n, *p, *next;
923 f->f_choice &= SLAPD_FILTER_MASK;
925 switch( f->f_choice ) {
926 case LDAP_FILTER_AND:
928 case LDAP_FILTER_NOT:
929 /* Free in reverse order */
931 for ( p = f->f_list; p; p = next ) {
936 for ( p = n; p; p = next ) {
938 trans_filter_free( op, p );
944 op->o_tmpfree( f, op->o_tmpmemctx );
948 ** translucent_search()
949 ** search via captive backend;
950 ** override results with any local data;
954 static int translucent_search(Operation *op, SlapReply *rs) {
955 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
956 translucent_info *ov = on->on_bi.bi_private;
957 slap_callback cb = { NULL, NULL, NULL, NULL };
963 Debug(LDAP_DEBUG_TRACE, "==> translucent_search: <%s> %s\n",
964 op->o_req_dn.bv_val, op->ors_filterstr.bv_val, 0);
966 if(ov->defer_db_open) {
967 send_ldap_error(op, rs, LDAP_UNAVAILABLE,
968 "remote DB not available");
972 fr = ov->remote ? trans_filter_dup( op, op->ors_filter, ov->remote ) : NULL;
973 fl = ov->local ? trans_filter_dup( op, op->ors_filter, ov->local ) : NULL;
974 cb.sc_response = (slap_response *) translucent_search_cb;
976 cb.sc_next = op->o_callback;
980 tc.orig = op->ors_filter;
983 fbv = op->ors_filterstr;
985 op->o_callback = &cb;
993 filter2bv_x( op, fr, &op->ors_filterstr );
995 rc = ov->db.bd_info->bi_op_search(op, rs);
998 op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
1002 tc.step |= LCL_SIDE;
1003 op->ors_filter = fl;
1004 filter2bv_x( op, fl, &op->ors_filterstr );
1005 rc = overlay_op_walk( op, rs, op_search, on->on_info, on->on_next );
1006 op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
1008 op->ors_filterstr = fbv;
1009 op->ors_filter = tc.orig;
1010 op->o_callback = cb.sc_next;
1011 /* Send out anything remaining on the list and finish */
1012 if ( tc.step & USE_LIST ) {
1016 av = tavl_end( tc.list, TAVL_DIR_LEFT );
1018 rs->sr_entry = av->avl_data;
1019 rc = test_filter( op, rs->sr_entry, op->ors_filter );
1020 if ( rc == LDAP_COMPARE_TRUE ) {
1021 rs->sr_flags = REP_ENTRY_MUSTBEFREED;
1022 rc = send_search_entry( op, rs );
1025 entry_free( rs->sr_entry );
1027 av = tavl_next( av, TAVL_DIR_RIGHT );
1029 tavl_free( tc.list, NULL );
1030 rs->sr_entry = NULL;
1032 send_ldap_result( op, rs );
1035 /* Free in reverse order */
1037 trans_filter_free( op, fl );
1039 trans_filter_free( op, fr );
1046 ** translucent_bind()
1047 ** pass bind request to captive backend;
1051 static int translucent_bind(Operation *op, SlapReply *rs) {
1052 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
1053 translucent_info *ov = on->on_bi.bi_private;
1055 slap_callback sc = { 0 }, *save_cb;
1058 Debug(LDAP_DEBUG_TRACE, "translucent_bind: <%s> method %d\n",
1059 op->o_req_dn.bv_val, op->orb_method, 0);
1061 if(ov->defer_db_open) {
1062 send_ldap_error(op, rs, LDAP_UNAVAILABLE,
1063 "remote DB not available");
1067 if (ov->bind_local) {
1068 sc.sc_response = slap_null_cb;
1069 save_cb = op->o_callback;
1070 op->o_callback = ≻
1075 rc = ov->db.bd_info->bi_op_bind(op, rs);
1078 if (ov->bind_local) {
1079 op->o_callback = save_cb;
1080 if (rc != LDAP_SUCCESS) {
1081 rc = SLAP_CB_CONTINUE;
1089 ** translucent_connection_destroy()
1090 ** pass disconnect notification to captive backend;
1094 static int translucent_connection_destroy(BackendDB *be, Connection *conn) {
1095 slap_overinst *on = (slap_overinst *) be->bd_info;
1096 translucent_info *ov = on->on_bi.bi_private;
1099 Debug(LDAP_DEBUG_TRACE, "translucent_connection_destroy\n", 0, 0, 0);
1101 rc = ov->db.bd_info->bi_connection_destroy(&ov->db, conn);
1107 ** translucent_db_config()
1108 ** pass config directives to captive backend;
1109 ** parse unrecognized directives ourselves;
1113 static int translucent_db_config(
1121 slap_overinst *on = (slap_overinst *) be->bd_info;
1122 translucent_info *ov = on->on_bi.bi_private;
1124 Debug(LDAP_DEBUG_TRACE, "==> translucent_db_config: %s\n",
1125 argc ? argv[0] : "", 0, 0);
1127 /* Something for the captive database? */
1128 if ( ov->db.bd_info && ov->db.bd_info->bi_db_config )
1129 return ov->db.bd_info->bi_db_config( &ov->db, fname, lineno,
1131 return SLAP_CONF_UNKNOWN;
1135 ** translucent_db_init()
1136 ** initialize the captive backend;
1140 static int translucent_db_init(BackendDB *be, ConfigReply *cr) {
1141 slap_overinst *on = (slap_overinst *) be->bd_info;
1142 translucent_info *ov;
1144 Debug(LDAP_DEBUG_TRACE, "==> translucent_db_init\n", 0, 0, 0);
1146 ov = ch_calloc(1, sizeof(translucent_info));
1147 on->on_bi.bi_private = ov;
1149 ov->db.be_private = NULL;
1150 ov->db.be_pcl_mutexp = &ov->db.be_pcl_mutex;
1151 ov->defer_db_open = 1;
1153 if ( !backend_db_init( "ldap", &ov->db, -1, NULL )) {
1154 Debug( LDAP_DEBUG_CONFIG, "translucent: unable to open captive back-ldap\n", 0, 0, 0);
1157 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_NO_SCHEMA_CHECK;
1158 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_NOLASTMOD;
1164 ** translucent_db_open()
1165 ** if the captive backend has an open() method, call it;
1169 static int translucent_db_open(BackendDB *be, ConfigReply *cr) {
1170 slap_overinst *on = (slap_overinst *) be->bd_info;
1171 translucent_info *ov = on->on_bi.bi_private;
1174 Debug(LDAP_DEBUG_TRACE, "==> translucent_db_open\n", 0, 0, 0);
1176 /* need to inherit something from the original database... */
1177 ov->db.be_def_limit = be->be_def_limit;
1178 ov->db.be_limits = be->be_limits;
1179 ov->db.be_acl = be->be_acl;
1180 ov->db.be_dfltaccess = be->be_dfltaccess;
1182 if ( ov->defer_db_open )
1185 rc = backend_startup_one( &ov->db, cr );
1187 if(rc) Debug(LDAP_DEBUG_TRACE,
1188 "translucent: bi_db_open() returned error %d\n", rc, 0, 0);
1194 ** translucent_db_close()
1195 ** if the captive backend has a close() method, call it
1200 translucent_db_close( BackendDB *be, ConfigReply *cr )
1202 slap_overinst *on = (slap_overinst *) be->bd_info;
1203 translucent_info *ov = on->on_bi.bi_private;
1206 Debug(LDAP_DEBUG_TRACE, "==> translucent_db_close\n", 0, 0, 0);
1208 if ( ov && ov->db.bd_info && ov->db.bd_info->bi_db_close ) {
1209 rc = ov->db.bd_info->bi_db_close(&ov->db, NULL);
1216 ** translucent_db_destroy()
1217 ** if the captive backend has a db_destroy() method, call it;
1218 ** free any config data
1223 translucent_db_destroy( BackendDB *be, ConfigReply *cr )
1225 slap_overinst *on = (slap_overinst *) be->bd_info;
1226 translucent_info *ov = on->on_bi.bi_private;
1229 Debug(LDAP_DEBUG_TRACE, "==> translucent_db_destroy\n", 0, 0, 0);
1233 anlist_free( ov->remote, 1, NULL );
1235 anlist_free( ov->local, 1, NULL );
1236 if ( ov->db.be_private != NULL ) {
1237 backend_stopdown_one( &ov->db );
1241 on->on_bi.bi_private = NULL;
1248 ** translucent_initialize()
1249 ** initialize the slap_overinst with our entry points;
1253 int translucent_initialize() {
1257 Debug(LDAP_DEBUG_TRACE, "==> translucent_initialize\n", 0, 0, 0);
1259 translucent.on_bi.bi_type = "translucent";
1260 translucent.on_bi.bi_db_init = translucent_db_init;
1261 translucent.on_bi.bi_db_config = translucent_db_config;
1262 translucent.on_bi.bi_db_open = translucent_db_open;
1263 translucent.on_bi.bi_db_close = translucent_db_close;
1264 translucent.on_bi.bi_db_destroy = translucent_db_destroy;
1265 translucent.on_bi.bi_op_bind = translucent_bind;
1266 translucent.on_bi.bi_op_add = translucent_add;
1267 translucent.on_bi.bi_op_modify = translucent_modify;
1268 translucent.on_bi.bi_op_modrdn = translucent_modrdn;
1269 translucent.on_bi.bi_op_delete = translucent_delete;
1270 translucent.on_bi.bi_op_search = translucent_search;
1271 translucent.on_bi.bi_op_compare = translucent_compare;
1272 translucent.on_bi.bi_connection_destroy = translucent_connection_destroy;
1274 translucent.on_bi.bi_cf_ocs = translucentocs;
1275 rc = config_register_schema ( translucentcfg, translucentocs );
1276 if ( rc ) return rc;
1278 return(overlay_register(&translucent));
1281 #if SLAPD_OVER_TRANSLUCENT == SLAPD_MOD_DYNAMIC && defined(PIC)
1282 int init_module(int argc, char *argv[]) {
1283 return translucent_initialize();
1287 #endif /* SLAPD_OVER_TRANSLUCENT */