1 /* translucent.c - translucent proxy module */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2004-2007 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 */
46 static ConfigLDAPadd translucent_ldadd;
47 static ConfigCfAdd translucent_cfadd;
49 static ConfigDriver translucent_cf_gen;
56 static ConfigTable translucentcfg[] = {
57 { "translucent_strict", "on|off", 1, 2, 0,
58 ARG_ON_OFF|ARG_OFFSET,
59 (void *)offsetof(translucent_info, strict),
60 "( OLcfgOvAt:14.1 NAME 'olcTranslucentStrict' "
61 "DESC 'Reveal attribute deletion constraint violations' "
62 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
63 { "translucent_no_glue", "on|off", 1, 2, 0,
64 ARG_ON_OFF|ARG_OFFSET,
65 (void *)offsetof(translucent_info, no_glue),
66 "( OLcfgOvAt:14.2 NAME 'olcTranslucentNoGlue' "
67 "DESC 'Disable automatic glue records for ADD and MODRDN' "
68 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
69 { "translucent_local", "attr[,attr...]", 1, 2, 0,
70 ARG_STRING|ARG_MAGIC|TRANS_LOCAL,
72 "( OLcfgOvAt:14.3 NAME 'olcTranslucentLocal' "
73 "DESC 'Attributes to use in local search filter' "
74 "SYNTAX OMsDirectoryString )", NULL, NULL },
75 { "translucent_remote", "attr[,attr...]", 1, 2, 0,
76 ARG_STRING|ARG_MAGIC|TRANS_REMOTE,
78 "( OLcfgOvAt:14.4 NAME 'olcTranslucentRemote' "
79 "DESC 'Attributes to use in remote search filter' "
80 "SYNTAX OMsDirectoryString )", NULL, NULL },
81 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
84 static ConfigTable transdummy[] = {
85 { "", "", 0, 0, 0, ARG_IGNORED,
86 NULL, "( OLcfgGlAt:13 NAME 'olcDatabase' "
87 "DESC 'The backend type for a database instance' "
88 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
89 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
92 static ConfigOCs translucentocs[] = {
94 "NAME 'olcTranslucentConfig' "
95 "DESC 'Translucent configuration' "
96 "SUP olcOverlayConfig "
97 "MAY ( olcTranslucentStrict $ olcTranslucentNoGlue ) )",
98 Cft_Overlay, translucentcfg, NULL, translucent_cfadd },
100 "NAME 'olcTranslucentDatabase' "
101 "DESC 'Translucent target database configuration' "
102 "AUXILIARY )", Cft_Misc, transdummy, translucent_ldadd },
105 /* for translucent_init() */
108 translucent_ldadd_cleanup( ConfigArgs *ca )
110 slap_overinst *on = ca->private;
111 translucent_info *ov = on->on_bi.bi_private;
113 ov->defer_db_open = 0;
114 return backend_startup_one( ca->be, &ca->reply );
118 translucent_ldadd( CfEntryInfo *cei, Entry *e, ConfigArgs *ca )
121 translucent_info *ov;
123 Debug(LDAP_DEBUG_TRACE, "==> translucent_ldadd\n", 0, 0, 0);
125 if ( cei->ce_type != Cft_Overlay || !cei->ce_bi ||
126 cei->ce_bi->bi_cf_ocs != translucentocs )
127 return LDAP_CONSTRAINT_VIOLATION;
129 on = (slap_overinst *)cei->ce_bi;
130 ov = on->on_bi.bi_private;
133 if ( CONFIG_ONLINE_ADD( ca ))
134 ca->cleanup = translucent_ldadd_cleanup;
136 ov->defer_db_open = 0;
142 translucent_cfadd( Operation *op, SlapReply *rs, Entry *e, ConfigArgs *ca )
144 CfEntryInfo *cei = e->e_private;
145 slap_overinst *on = (slap_overinst *)cei->ce_bi;
146 translucent_info *ov = on->on_bi.bi_private;
149 Debug(LDAP_DEBUG_TRACE, "==> translucent_cfadd\n", 0, 0, 0);
151 /* FIXME: should not hardcode "olcDatabase" here */
152 bv.bv_len = snprintf( ca->cr_msg, sizeof( ca->cr_msg ),
153 "olcDatabase=%s", ov->db.bd_info->bi_type );
154 if ( bv.bv_len < 0 || bv.bv_len >= sizeof( ca->cr_msg ) ) {
157 bv.bv_val = ca->cr_msg;
159 ov->defer_db_open = 0;
161 /* We can only create this entry if the database is table-driven
163 if ( ov->db.bd_info->bi_cf_ocs )
164 config_build_entry( op, rs, cei, ca, &bv,
165 ov->db.bd_info->bi_cf_ocs,
166 &translucentocs[1] );
172 translucent_cf_gen( ConfigArgs *c )
174 slap_overinst *on = (slap_overinst *)c->bi;
175 translucent_info *ov = on->on_bi.bi_private;
176 AttributeName **an, *a2;
179 if ( c->type == TRANS_LOCAL )
184 if ( c->op == SLAP_CONFIG_EMIT ) {
185 for ( i = 0; !BER_BVISNULL(&(*an)[i].an_name); i++ ) {
186 value_add_one( &c->rvalue_vals, &(*an)[i].an_name );
189 } else if ( c->op == LDAP_MOD_DELETE ) {
191 anlist_free( *an, 1, NULL );
195 ch_free( (*an)[i].an_name.bv_val );
197 (*an)[i] = (*an)[i+1];
198 } while ( !BER_BVISNULL( &(*an)[i].an_name ));
202 a2 = str2anlist( *an, c->argv[1], "," );
204 snprintf( c->cr_msg, sizeof( c->cr_msg ), "%s unable to parse attribute %s",
205 c->argv[0], c->argv[1] );
206 Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE,
207 "%s: %s\n", c->log, c->cr_msg, 0 );
214 static slap_overinst translucent;
218 ** call syncrepl_add_glue() with the parent suffix;
222 static struct berval glue[] = { BER_BVC("top"), BER_BVC("glue"), BER_BVNULL };
224 void glue_parent(Operation *op) {
226 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
227 struct berval ndn = BER_BVNULL;
232 dnParent( &op->o_req_ndn, &pdn );
233 ber_dupbv_x( &ndn, &pdn, op->o_tmpmemctx );
235 Debug(LDAP_DEBUG_TRACE, "=> glue_parent: fabricating glue for <%s>\n", ndn.bv_val, 0, 0);
239 ber_dupbv(&e->e_name, &ndn);
240 ber_dupbv(&e->e_nname, &ndn);
242 a = attr_alloc( slap_schema.si_ad_objectClass );
244 a->a_vals = ch_malloc(sizeof(struct berval) * 3);
245 ber_dupbv(&a->a_vals[0], &glue[0]);
246 ber_dupbv(&a->a_vals[1], &glue[1]);
247 ber_dupbv(&a->a_vals[2], &glue[2]);
248 a->a_nvals = a->a_vals;
249 a->a_next = e->e_attrs;
252 a = attr_alloc( slap_schema.si_ad_structuralObjectClass );
254 a->a_vals = ch_malloc(sizeof(struct berval) * 2);
255 ber_dupbv(&a->a_vals[0], &glue[1]);
256 ber_dupbv(&a->a_vals[1], &glue[2]);
257 a->a_nvals = a->a_vals;
258 a->a_next = e->e_attrs;
265 nop.o_bd->bd_info = (BackendInfo *) on->on_info->oi_orig;
266 syncrepl_add_glue(&nop, e);
267 nop.o_bd->bd_info = (BackendInfo *) on;
269 op->o_tmpfree( ndn.bv_val, op->o_tmpmemctx );
279 BerVarray dup_bervarray(BerVarray b) {
282 for(len = 0; b[len].bv_val; len++);
283 nb = ch_malloc((len+1) * sizeof(BerValue));
284 for(i = 0; i < len; i++) ber_dupbv(&nb[i], &b[i]);
285 nb[len].bv_val = NULL;
292 ** free only the Attribute*, not the contents;
295 void free_attr_chain(Attribute *b) {
297 for(a=b; a; a=a->a_next) {
307 ** if not bound as root, send ACCESS error;
308 ** if glue, glue_parent();
313 static int translucent_add(Operation *op, SlapReply *rs) {
314 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
315 translucent_info *ov = on->on_bi.bi_private;
316 Debug(LDAP_DEBUG_TRACE, "==> translucent_add: %s\n",
317 op->o_req_dn.bv_val, 0, 0);
319 op->o_bd->bd_info = (BackendInfo *) on->on_info;
320 send_ldap_error(op, rs, LDAP_INSUFFICIENT_ACCESS,
321 "user modification of overlay database not permitted");
322 op->o_bd->bd_info = (BackendInfo *) on;
325 if(!ov->no_glue) glue_parent(op);
326 return(SLAP_CB_CONTINUE);
330 ** translucent_modrdn()
331 ** if not bound as root, send ACCESS error;
332 ** if !glue, glue_parent();
333 ** else return CONTINUE;
337 static int translucent_modrdn(Operation *op, SlapReply *rs) {
338 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
339 translucent_info *ov = on->on_bi.bi_private;
340 Debug(LDAP_DEBUG_TRACE, "==> translucent_modrdn: %s -> %s\n",
341 op->o_req_dn.bv_val, op->orr_newrdn.bv_val, 0);
343 op->o_bd->bd_info = (BackendInfo *) on->on_info;
344 send_ldap_error(op, rs, LDAP_INSUFFICIENT_ACCESS,
345 "user modification of overlay database not permitted");
346 op->o_bd->bd_info = (BackendInfo *) on;
350 op->o_tag = LDAP_REQ_ADD;
352 op->o_tag = LDAP_REQ_MODRDN;
354 return(SLAP_CB_CONTINUE);
358 ** translucent_delete()
359 ** if not bound as root, send ACCESS error;
360 ** else return CONTINUE;
364 static int translucent_delete(Operation *op, SlapReply *rs) {
365 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
366 Debug(LDAP_DEBUG_TRACE, "==> translucent_delete: %s\n",
367 op->o_req_dn.bv_val, 0, 0);
369 op->o_bd->bd_info = (BackendInfo *) on->on_info;
370 send_ldap_error(op, rs, LDAP_INSUFFICIENT_ACCESS,
371 "user modification of overlay database not permitted");
372 op->o_bd->bd_info = (BackendInfo *) on;
375 return(SLAP_CB_CONTINUE);
379 translucent_tag_cb( Operation *op, SlapReply *rs )
381 op->o_tag = LDAP_REQ_MODIFY;
382 op->orm_modlist = op->o_callback->sc_private;
383 rs->sr_tag = slap_req2res( op->o_tag );
385 return SLAP_CB_CONTINUE;
389 ** translucent_modify()
390 ** modify in local backend if exists in both;
391 ** otherwise, add to local backend;
392 ** fail if not defined in captive backend;
396 static int translucent_modify(Operation *op, SlapReply *rs) {
397 SlapReply nrs = { REP_RESULT };
399 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
400 translucent_info *ov = on->on_bi.bi_private;
401 Entry *e = NULL, *re = NULL;
403 Modifications *m, **mm;
405 int del, rc, erc = 0;
406 slap_callback cb = { 0 };
408 Debug(LDAP_DEBUG_TRACE, "==> translucent_modify: %s\n",
409 op->o_req_dn.bv_val, 0, 0);
411 if(ov->defer_db_open) {
412 send_ldap_error(op, rs, LDAP_UNAVAILABLE,
413 "remote DB not available");
417 ** fetch entry from the captive backend;
418 ** if it did not exist, fail;
419 ** release it, if captive backend supports this;
425 rc = ov->db.bd_info->bi_entry_get_rw(op, &op->o_req_ndn, NULL, NULL, 0, &re);
426 if(rc != LDAP_SUCCESS || re == NULL ) {
427 send_ldap_error((op), rs, LDAP_NO_SUCH_OBJECT,
428 "attempt to modify nonexistent local record");
433 ** fetch entry from local backend;
435 ** foreach Modification:
436 ** if attr not present in local:
437 ** if Mod == LDAP_MOD_DELETE:
438 ** if remote attr not present, return NO_SUCH;
439 ** if remote attr present, drop this Mod;
440 ** else force this Mod to LDAP_MOD_ADD;
445 op->o_bd->bd_info = (BackendInfo *) on->on_info;
446 rc = be_entry_get_rw(op, &op->o_req_ndn, NULL, NULL, 0, &e);
447 op->o_bd->bd_info = (BackendInfo *) on;
449 if(e && rc == LDAP_SUCCESS) {
450 Debug(LDAP_DEBUG_TRACE, "=> translucent_modify: found local entry\n", 0, 0, 0);
451 for(mm = &op->orm_modlist; *mm; ) {
453 for(a = e->e_attrs; a; a = a->a_next)
454 if(a->a_desc == m->sml_desc) break;
457 continue; /* found local attr */
459 if(m->sml_op == LDAP_MOD_DELETE) {
460 for(a = re->e_attrs; a; a = a->a_next)
461 if(a->a_desc == m->sml_desc) break;
462 /* not found remote attr */
464 erc = LDAP_NO_SUCH_ATTRIBUTE;
468 erc = LDAP_CONSTRAINT_VIOLATION;
471 Debug(LDAP_DEBUG_TRACE,
472 "=> translucent_modify: silently dropping delete: %s\n",
473 m->sml_desc->ad_cname.bv_val, 0, 0);
476 slap_mods_free(m, 1);
479 m->sml_op = LDAP_MOD_ADD;
482 erc = SLAP_CB_CONTINUE;
485 if(ov->db.bd_info->bi_entry_release_rw) {
487 ov->db.bd_info->bi_entry_release_rw(op, re, 0);
492 op->o_bd->bd_info = (BackendInfo *) on->on_info;
493 be_entry_release_r(op, e);
494 op->o_bd->bd_info = (BackendInfo *) on;
495 if(erc == SLAP_CB_CONTINUE) {
498 send_ldap_error(op, rs, erc,
499 "attempt to delete nonexistent attribute");
504 /* don't leak remote entry copy */
506 if(ov->db.bd_info->bi_entry_release_rw) {
508 ov->db.bd_info->bi_entry_release_rw(op, re, 0);
514 ** foreach Modification:
515 ** if MOD_ADD or MOD_REPLACE, add Attribute;
516 ** if no Modifications were suitable:
517 ** if strict, throw CONSTRAINT_VIOLATION;
518 ** else, return early SUCCESS;
519 ** fabricate Entry with new Attribute chain;
520 ** glue_parent() for this Entry;
521 ** call bi_op_add() in local backend;
525 Debug(LDAP_DEBUG_TRACE, "=> translucent_modify: fabricating local add\n", 0, 0, 0);
527 for(del = 0, ax = NULL, m = op->orm_modlist; m; m = m->sml_next) {
529 if(((m->sml_op & LDAP_MOD_OP) != LDAP_MOD_ADD) &&
530 ((m->sml_op & LDAP_MOD_OP) != LDAP_MOD_REPLACE)) {
531 Debug(LDAP_DEBUG_ANY,
532 "=> translucent_modify: silently dropped modification(%d): %s\n",
533 m->sml_op, m->sml_desc->ad_cname.bv_val, 0);
534 if((m->sml_op & LDAP_MOD_OP) == LDAP_MOD_DELETE) del++;
537 atmp.a_desc = m->sml_desc;
538 atmp.a_vals = m->sml_values;
539 atmp.a_nvals = m->sml_nvalues ? m->sml_nvalues : atmp.a_vals;
540 atmp.a_numvals = m->sml_numvals;
542 a = attr_dup( &atmp );
547 if(del && ov->strict) {
549 send_ldap_error(op, rs, LDAP_CONSTRAINT_VIOLATION,
550 "attempt to delete attributes from local database");
556 send_ldap_error(op, rs, LDAP_CONSTRAINT_VIOLATION,
557 "modification contained other than ADD or REPLACE");
560 /* rs->sr_text = "no valid modification found"; */
561 rs->sr_err = LDAP_SUCCESS;
562 send_ldap_result(op, rs);
567 ber_dupbv( &e->e_name, &op->o_req_dn );
568 ber_dupbv( &e->e_nname, &op->o_req_ndn );
571 op->o_tag = LDAP_REQ_ADD;
572 cb.sc_response = translucent_tag_cb;
573 cb.sc_private = op->orm_modlist;
578 cb.sc_next = op->o_callback;
579 op->o_callback = &cb;
580 rc = on->on_info->oi_orig->bi_op_add(op, &nrs);
581 if ( op->ora_e == e )
583 op->o_callback = cb.sc_next;
588 static int translucent_compare(Operation *op, SlapReply *rs) {
589 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
590 translucent_info *ov = on->on_bi.bi_private;
591 AttributeAssertion *ava = op->orc_ava;
596 Debug(LDAP_DEBUG_TRACE, "==> translucent_compare: <%s> %s:%s\n",
597 op->o_req_dn.bv_val, ava->aa_desc->ad_cname.bv_val, ava->aa_value.bv_val);
600 ** if the local backend has an entry for this attribute:
601 ** CONTINUE and let it do the compare;
604 rc = overlay_entry_get_ov(op, &op->o_req_ndn, NULL, ava->aa_desc, 0, &e, on);
605 if(e && rc == LDAP_SUCCESS) {
606 overlay_entry_release_ov(op, e, 0, on);
607 return(SLAP_CB_CONTINUE);
610 if(ov->defer_db_open) {
611 send_ldap_error(op, rs, LDAP_UNAVAILABLE,
612 "remote DB not available");
616 ** call compare() in the captive backend;
617 ** return the result;
622 rc = ov->db.bd_info->bi_op_compare(op, rs);
629 ** translucent_search_cb()
630 ** merge local data with remote data
633 ** 1: remote search, no local filter
634 ** merge data and send immediately
635 ** 2: remote search, with local filter
636 ** merge data and save
637 ** 3: local search, no remote filter
638 ** merge data and send immediately
639 ** 4: local search, with remote filter
640 ** check list, merge, send, delete
647 typedef struct trans_ctx {
655 static int translucent_search_cb(Operation *op, SlapReply *rs) {
659 translucent_info *ov;
661 Attribute *a, *ax, *an, *as = NULL;
664 tc = op->o_callback->sc_private;
666 /* Don't let the op complete while we're gathering data */
667 if ( rs->sr_type == REP_RESULT && ( tc->step & USE_LIST ))
670 if(!op || !rs || rs->sr_type != REP_SEARCH || !rs->sr_entry)
671 return(SLAP_CB_CONTINUE);
673 Debug(LDAP_DEBUG_TRACE, "==> translucent_search_cb: %s\n",
674 rs->sr_entry->e_name.bv_val, 0, 0);
677 ov = on->on_bi.bi_private;
682 /* If we have local, get remote */
683 if ( tc->step & LCL_SIDE ) {
685 /* If entry is already on list, use it */
686 if ( tc->step & USE_LIST ) {
687 re = tavl_delete( &tc->list, le, entry_dn_cmp );
689 if ( rs->sr_flags & REP_ENTRY_MUSTRELEASE ) {
690 rs->sr_flags ^= REP_ENTRY_MUSTRELEASE;
691 be_entry_release_r( op, rs->sr_entry );
693 if ( rs->sr_flags & REP_ENTRY_MUSTBEFREED ) {
694 rs->sr_flags ^= REP_ENTRY_MUSTBEFREED;
695 entry_free( rs->sr_entry );
697 rc = test_filter( op, re, tc->orig );
698 if ( rc == LDAP_COMPARE_TRUE ) {
699 rs->sr_flags |= REP_ENTRY_MUSTBEFREED;
701 return SLAP_CB_CONTINUE;
710 rc = be_entry_get_rw( op, &rs->sr_entry->e_nname, NULL, NULL, 0, &re );
711 if ( rc == LDAP_SUCCESS && re ) {
712 Entry *tmp = entry_dup( re );
713 be_entry_release_r( op, re );
717 /* Else we have remote, get local */
719 rc = overlay_entry_get_ov(op, &rs->sr_entry->e_nname, NULL, NULL, 0, &le, on);
720 if ( rc == LDAP_SUCCESS && le ) {
721 re = entry_dup( rs->sr_entry );
722 if ( rs->sr_flags & REP_ENTRY_MUSTRELEASE ) {
723 rs->sr_flags ^= REP_ENTRY_MUSTRELEASE;
724 be_entry_release_r( op, rs->sr_entry );
726 if ( rs->sr_flags & REP_ENTRY_MUSTBEFREED ) {
727 rs->sr_flags ^= REP_ENTRY_MUSTBEFREED;
728 entry_free( rs->sr_entry );
736 ** if we got remote and local entry:
737 ** foreach local attr:
738 ** foreach remote attr:
739 ** if match, remote attr with local attr;
740 ** if new local, add to list;
741 ** append new local attrs to remote;
746 for(ax = le->e_attrs; ax; ax = ax->a_next) {
747 for(a = re->e_attrs; a; a = a->a_next) {
748 if(a->a_desc == ax->a_desc) {
749 if(a->a_vals != a->a_nvals)
750 ber_bvarray_free(a->a_nvals);
751 ber_bvarray_free(a->a_vals);
752 a->a_vals = dup_bervarray(ax->a_vals);
753 a->a_nvals = (ax->a_vals == ax->a_nvals) ?
754 a->a_vals : dup_bervarray(ax->a_nvals);
763 /* Dispose of local entry */
764 if ( tc->step & LCL_SIDE ) {
765 if ( rs->sr_flags & REP_ENTRY_MUSTRELEASE ) {
766 rs->sr_flags ^= REP_ENTRY_MUSTRELEASE;
767 be_entry_release_r( op, rs->sr_entry );
769 if ( rs->sr_flags & REP_ENTRY_MUSTBEFREED ) {
770 rs->sr_flags ^= REP_ENTRY_MUSTBEFREED;
771 entry_free( rs->sr_entry );
774 overlay_entry_release_ov(op, le, 0, on);
777 /* literally append, so locals are always last */
780 for(ax = re->e_attrs; ax->a_next; ax = ax->a_next);
786 if ( tc->step == (USE_LIST|RMT_SIDE) ) {
787 rc = test_filter( op, re, tc->orig );
788 if ( rc == LDAP_COMPARE_TRUE ) {
789 tavl_insert( &tc->list, re, entry_dn_cmp, avl_dup_error );
797 rs->sr_flags |= REP_ENTRY_MUSTBEFREED;
798 rc = SLAP_CB_CONTINUE;
801 /* Only a local entry: remote was deleted
802 * Ought to delete the local too...
805 } else if ( tc->step & USE_LIST ) {
806 /* Only a remote entry, but both filters:
807 * Test the complete filter
809 rc = test_filter( op, rs->sr_entry, tc->orig );
810 if ( rc == LDAP_COMPARE_TRUE ) {
811 rc = SLAP_CB_CONTINUE;
816 /* Only a remote entry, only remote filter:
819 rc = SLAP_CB_CONTINUE;
826 /* Dup the filter, excluding invalid elements */
828 trans_filter_dup(Operation *op, Filter *f, AttributeName *an)
835 switch( f->f_choice & SLAPD_FILTER_MASK ) {
836 case SLAPD_FILTER_COMPUTED:
837 n = op->o_tmpalloc( sizeof(Filter), op->o_tmpmemctx );
838 n->f_choice = f->f_choice;
839 n->f_result = f->f_result;
843 case LDAP_FILTER_PRESENT:
844 if ( ad_inlist( f->f_desc, an )) {
845 n = op->o_tmpalloc( sizeof(Filter), op->o_tmpmemctx );
846 n->f_choice = f->f_choice;
847 n->f_desc = f->f_desc;
852 case LDAP_FILTER_EQUALITY:
855 case LDAP_FILTER_APPROX:
856 case LDAP_FILTER_SUBSTRINGS:
857 case LDAP_FILTER_EXT:
858 if ( !f->f_av_desc || ad_inlist( f->f_av_desc, an )) {
859 n = op->o_tmpalloc( sizeof(Filter), op->o_tmpmemctx );
860 n->f_choice = f->f_choice;
866 case LDAP_FILTER_AND:
868 case LDAP_FILTER_NOT: {
871 n = op->o_tmpalloc( sizeof(Filter), op->o_tmpmemctx );
872 n->f_choice = f->f_choice;
875 for ( p = &n->f_list, f = f->f_list; f; f = f->f_next ) {
876 *p = trans_filter_dup( op, f, an );
881 /* nothing valid in this list */
883 op->o_tmpfree( n, op->o_tmpmemctx );
886 /* Only 1 element in this list */
887 if ((n->f_choice & SLAPD_FILTER_MASK) != LDAP_FILTER_NOT &&
888 !n->f_list->f_next ) {
891 op->o_tmpfree( f, op->o_tmpmemctx );
900 trans_filter_free( Operation *op, Filter *f )
902 Filter *n, *p, *next;
904 f->f_choice &= SLAPD_FILTER_MASK;
906 switch( f->f_choice ) {
907 case LDAP_FILTER_AND:
909 case LDAP_FILTER_NOT:
910 /* Free in reverse order */
912 for ( p = f->f_list; p; p = next ) {
917 for ( p = n; p; p = next ) {
919 trans_filter_free( op, p );
925 op->o_tmpfree( f, op->o_tmpmemctx );
929 ** translucent_search()
930 ** search via captive backend;
931 ** override results with any local data;
935 static int translucent_search(Operation *op, SlapReply *rs) {
936 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
937 translucent_info *ov = on->on_bi.bi_private;
938 slap_callback cb = { NULL, NULL, NULL, NULL };
944 Debug(LDAP_DEBUG_TRACE, "==> translucent_search: <%s> %s\n",
945 op->o_req_dn.bv_val, op->ors_filterstr.bv_val, 0);
947 if(ov->defer_db_open) {
948 send_ldap_error(op, rs, LDAP_UNAVAILABLE,
949 "remote DB not available");
953 fr = ov->remote ? trans_filter_dup( op, op->ors_filter, ov->remote ) : NULL;
954 fl = ov->local ? trans_filter_dup( op, op->ors_filter, ov->local ) : NULL;
955 cb.sc_response = (slap_response *) translucent_search_cb;
957 cb.sc_next = op->o_callback;
961 tc.orig = op->ors_filter;
964 fbv = op->ors_filterstr;
966 op->o_callback = &cb;
974 filter2bv_x( op, fr, &op->ors_filterstr );
976 rc = ov->db.bd_info->bi_op_search(op, rs);
979 op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
985 filter2bv_x( op, fl, &op->ors_filterstr );
986 rc = overlay_op_walk( op, rs, op_search, on->on_info, on->on_next );
987 op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
989 op->ors_filterstr = fbv;
990 op->ors_filter = tc.orig;
991 op->o_callback = cb.sc_next;
992 /* Send out anything remaining on the list and finish */
993 if ( tc.step & USE_LIST ) {
997 av = tavl_end( tc.list, TAVL_DIR_LEFT );
999 rs->sr_flags = REP_ENTRY_MUSTBEFREED;
1000 rs->sr_entry = av->avl_data;
1001 rc = send_search_entry( op, rs );
1003 av = tavl_next( av, TAVL_DIR_RIGHT );
1005 tavl_free( tc.list, NULL );
1007 send_ldap_result( op, rs );
1010 /* Free in reverse order */
1012 trans_filter_free( op, fl );
1014 trans_filter_free( op, fr );
1021 ** translucent_bind()
1022 ** pass bind request to captive backend;
1026 static int translucent_bind(Operation *op, SlapReply *rs) {
1027 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
1028 translucent_info *ov = on->on_bi.bi_private;
1032 Debug(LDAP_DEBUG_TRACE, "translucent_bind: <%s> method %d\n",
1033 op->o_req_dn.bv_val, op->orb_method, 0);
1035 if(ov->defer_db_open) {
1036 send_ldap_error(op, rs, LDAP_UNAVAILABLE,
1037 "remote DB not available");
1042 rc = ov->db.bd_info->bi_op_bind(op, rs);
1048 ** translucent_connection_destroy()
1049 ** pass disconnect notification to captive backend;
1053 static int translucent_connection_destroy(BackendDB *be, Connection *conn) {
1054 slap_overinst *on = (slap_overinst *) be->bd_info;
1055 translucent_info *ov = on->on_bi.bi_private;
1058 Debug(LDAP_DEBUG_TRACE, "translucent_connection_destroy\n", 0, 0, 0);
1060 rc = ov->db.bd_info->bi_connection_destroy(&ov->db, conn);
1066 ** translucent_db_config()
1067 ** pass config directives to captive backend;
1068 ** parse unrecognized directives ourselves;
1072 static int translucent_db_config(
1080 slap_overinst *on = (slap_overinst *) be->bd_info;
1081 translucent_info *ov = on->on_bi.bi_private;
1083 Debug(LDAP_DEBUG_TRACE, "==> translucent_db_config: %s\n",
1084 argc ? argv[0] : "", 0, 0);
1086 /* Something for the captive database? */
1087 if ( ov->db.bd_info && ov->db.bd_info->bi_db_config )
1088 return ov->db.bd_info->bi_db_config( &ov->db, fname, lineno,
1090 return SLAP_CONF_UNKNOWN;
1094 ** translucent_db_init()
1095 ** initialize the captive backend;
1099 static int translucent_db_init(BackendDB *be, ConfigReply *cr) {
1100 slap_overinst *on = (slap_overinst *) be->bd_info;
1101 translucent_info *ov;
1103 Debug(LDAP_DEBUG_TRACE, "==> translucent_db_init\n", 0, 0, 0);
1105 ov = ch_calloc(1, sizeof(translucent_info));
1106 on->on_bi.bi_private = ov;
1108 ov->db.be_private = NULL;
1109 ov->db.be_pcl_mutexp = &ov->db.be_pcl_mutex;
1110 ov->defer_db_open = 1;
1112 if ( !backend_db_init( "ldap", &ov->db, -1, NULL )) {
1113 Debug( LDAP_DEBUG_CONFIG, "translucent: unable to open captive back-ldap\n", 0, 0, 0);
1116 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_NO_SCHEMA_CHECK;
1117 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_NOLASTMOD;
1123 ** translucent_db_open()
1124 ** if the captive backend has an open() method, call it;
1128 static int translucent_db_open(BackendDB *be, ConfigReply *cr) {
1129 slap_overinst *on = (slap_overinst *) be->bd_info;
1130 translucent_info *ov = on->on_bi.bi_private;
1133 Debug(LDAP_DEBUG_TRACE, "==> translucent_db_open\n", 0, 0, 0);
1135 /* need to inherit something from the original database... */
1136 ov->db.be_def_limit = be->be_def_limit;
1137 ov->db.be_limits = be->be_limits;
1138 ov->db.be_acl = be->be_acl;
1139 ov->db.be_dfltaccess = be->be_dfltaccess;
1141 if ( ov->defer_db_open )
1144 rc = backend_startup_one( &ov->db, NULL );
1146 if(rc) Debug(LDAP_DEBUG_TRACE,
1147 "translucent: bi_db_open() returned error %d\n", rc, 0, 0);
1153 ** translucent_db_close()
1154 ** if the captive backend has a close() method, call it
1159 translucent_db_close( BackendDB *be, ConfigReply *cr )
1161 slap_overinst *on = (slap_overinst *) be->bd_info;
1162 translucent_info *ov = on->on_bi.bi_private;
1165 Debug(LDAP_DEBUG_TRACE, "==> translucent_db_close\n", 0, 0, 0);
1167 if ( ov && ov->db.bd_info && ov->db.bd_info->bi_db_close ) {
1168 rc = ov->db.bd_info->bi_db_close(&ov->db, NULL);
1175 ** translucent_db_destroy()
1176 ** if the captive backend has a db_destroy() method, call it;
1177 ** free any config data
1182 translucent_db_destroy( BackendDB *be, ConfigReply *cr )
1184 slap_overinst *on = (slap_overinst *) be->bd_info;
1185 translucent_info *ov = on->on_bi.bi_private;
1188 Debug(LDAP_DEBUG_TRACE, "==> translucent_db_destroy\n", 0, 0, 0);
1192 anlist_free( ov->remote, 1, NULL );
1194 anlist_free( ov->local, 1, NULL );
1195 if ( ov->db.be_private != NULL ) {
1196 backend_stopdown_one( &ov->db );
1200 on->on_bi.bi_private = NULL;
1207 ** translucent_initialize()
1208 ** initialize the slap_overinst with our entry points;
1212 int translucent_initialize() {
1216 Debug(LDAP_DEBUG_TRACE, "==> translucent_initialize\n", 0, 0, 0);
1218 translucent.on_bi.bi_type = "translucent";
1219 translucent.on_bi.bi_db_init = translucent_db_init;
1220 translucent.on_bi.bi_db_config = translucent_db_config;
1221 translucent.on_bi.bi_db_open = translucent_db_open;
1222 translucent.on_bi.bi_db_close = translucent_db_close;
1223 translucent.on_bi.bi_db_destroy = translucent_db_destroy;
1224 translucent.on_bi.bi_op_bind = translucent_bind;
1225 translucent.on_bi.bi_op_add = translucent_add;
1226 translucent.on_bi.bi_op_modify = translucent_modify;
1227 translucent.on_bi.bi_op_modrdn = translucent_modrdn;
1228 translucent.on_bi.bi_op_delete = translucent_delete;
1229 translucent.on_bi.bi_op_search = translucent_search;
1230 translucent.on_bi.bi_op_compare = translucent_compare;
1231 translucent.on_bi.bi_connection_destroy = translucent_connection_destroy;
1233 translucent.on_bi.bi_cf_ocs = translucentocs;
1234 rc = config_register_schema ( translucentcfg, translucentocs );
1235 if ( rc ) return rc;
1237 return(overlay_register(&translucent));
1240 #if SLAPD_OVER_TRANSLUCENT == SLAPD_MOD_DYNAMIC && defined(PIC)
1241 int init_module(int argc, char *argv[]) {
1242 return translucent_initialize();
1246 #endif /* SLAPD_OVER_TRANSLUCENT */