#include "slap.h"
#include "lutil.h"
+#include "config.h"
+
/* config block */
typedef struct translucent_info {
- BackendInfo *info; /* captive backend */
- void *private; /* local backend_private */
+ BackendDB db; /* captive backend */
int strict;
- int glue;
+ int no_glue;
} translucent_info;
+static ConfigLDAPadd translucent_ldadd;
+static ConfigCfAdd translucent_cfadd;
+
+static ConfigTable translucentcfg[] = {
+ { "translucent_strict", "on|off", 1, 2, 0,
+ ARG_ON_OFF|ARG_OFFSET,
+ (void *)offsetof(translucent_info, strict),
+ "( OLcfgOvAt:14.1 NAME 'olcTranslucentStrict' "
+ "DESC 'Reveal attribute deletion constraint violations' "
+ "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
+ { "translucent_no_glue", "on|off", 1, 2, 0,
+ ARG_ON_OFF|ARG_OFFSET,
+ (void *)offsetof(translucent_info, no_glue),
+ "( OLcfgOvAt:14.2 NAME 'olcTranslucentNoGlue' "
+ "DESC 'Disable automatic glue records for ADD and MODRDN' "
+ "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
+ { NULL, NULL, 0, 0, 0, ARG_IGNORED }
+};
+
+static ConfigOCs translucentocs[] = {
+ { "( OLcfgOvOc:14.1 "
+ "NAME 'olcTranslucentConfig' "
+ "DESC 'Translucent configuration' "
+ "SUP olcOverlayConfig "
+ "MAY ( olcTranslucentStrict $ olcTranslucentNoGlue ) )",
+ Cft_Overlay, translucentcfg, NULL, translucent_cfadd },
+ { "( OLcfgOvOc:14.2 "
+ "NAME 'olcTranslucentDatabase' "
+ "DESC 'Translucent target database configuration' "
+ "AUXILIARY )", Cft_Misc, translucentcfg, translucent_ldadd },
+ { NULL, 0, NULL }
+};
/* for translucent_init() */
+static int
+translucent_ldadd( CfEntryInfo *cei, Entry *e, ConfigArgs *ca )
+{
+ slap_overinst *on;
+ translucent_info *ov;
+
+ Debug(LDAP_DEBUG_TRACE, "==> translucent_ldadd\n", 0, 0, 0);
+
+ if ( cei->ce_type != Cft_Overlay || !cei->ce_bi ||
+ cei->ce_bi->bi_cf_ocs != translucentocs )
+ return LDAP_CONSTRAINT_VIOLATION;
+
+ on = (slap_overinst *)cei->ce_bi;
+ ov = on->on_bi.bi_private;
+ ca->be = &ov->db;
+ return LDAP_SUCCESS;
+}
+
+static int
+translucent_cfadd( Operation *op, SlapReply *rs, Entry *e, ConfigArgs *ca )
+{
+ CfEntryInfo *cei = e->e_private;
+ slap_overinst *on = (slap_overinst *)cei->ce_bi;
+ translucent_info *ov = on->on_bi.bi_private;
+ struct berval bv;
+
+ Debug(LDAP_DEBUG_TRACE, "==> translucent_cfadd\n", 0, 0, 0);
+
+ /* FIXME: should not hardcode "olcDatabase" here */
+ bv.bv_len = sprintf( ca->msg, "olcDatabase=%s",
+ ov->db.bd_info->bi_type );
+ bv.bv_val = ca->msg;
+ ca->be = &ov->db;
+
+ /* We can only create this entry if the database is table-driven
+ */
+ if ( ov->db.bd_info->bi_cf_ocs )
+ config_build_entry( op, rs, cei, ca, &bv,
+ ov->db.bd_info->bi_cf_ocs,
+ &translucentocs[1] );
+
+ return 0;
+}
+
static slap_overinst translucent;
/*
nop.o_req_dn = ndn;
nop.o_req_ndn = ndn;
nop.ora_e = e;
- nop.o_bd->bd_info = (BackendInfo *) on->on_info->oi_orig;
+ nop.o_bd->bd_info = (BackendInfo *) on->on_info->oi_orig;
syncrepl_add_glue(&nop, e);
+ nop.o_bd->bd_info = (BackendInfo *) on;
op->o_tmpfree( ndn.bv_val, op->o_tmpmemctx );
op->o_bd->bd_info = (BackendInfo *) on->on_info;
send_ldap_error(op, rs, LDAP_INSUFFICIENT_ACCESS,
"user modification of overlay database not permitted");
+ op->o_bd->bd_info = (BackendInfo *) on;
return(rs->sr_err);
}
- if(!ov->glue) glue_parent(op);
+ if(!ov->no_glue) glue_parent(op);
return(SLAP_CB_CONTINUE);
}
op->o_bd->bd_info = (BackendInfo *) on->on_info;
send_ldap_error(op, rs, LDAP_INSUFFICIENT_ACCESS,
"user modification of overlay database not permitted");
+ op->o_bd->bd_info = (BackendInfo *) on;
return(rs->sr_err);
}
- if(!ov->glue) glue_parent(op);
+ if(!ov->no_glue) glue_parent(op);
return(SLAP_CB_CONTINUE);
}
op->o_bd->bd_info = (BackendInfo *) on->on_info;
send_ldap_error(op, rs, LDAP_INSUFFICIENT_ACCESS,
"user modification of overlay database not permitted");
+ op->o_bd->bd_info = (BackendInfo *) on;
return(rs->sr_err);
}
return(SLAP_CB_CONTINUE);
slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
translucent_info *ov = on->on_bi.bi_private;
- void *private = op->o_bd->be_private;
Entry ne, *e = NULL, *re = NULL;
Attribute *a, *ax;
Modifications *m, *mm;
**
*/
- op->o_bd->bd_info = (BackendInfo *) on->on_info;
- op->o_bd->be_private = ov->private;
- rc = ov->info->bi_entry_get_rw(op, &op->o_req_ndn, NULL, NULL, 0, &re);
- op->o_bd->be_private = private;
-
+ nop.o_bd = &ov->db;
+ rc = ov->db.bd_info->bi_entry_get_rw(&nop, &nop.o_req_ndn, NULL, NULL, 0, &re);
if(rc != LDAP_SUCCESS || re == NULL ) {
- send_ldap_error(op, rs, LDAP_NO_SUCH_OBJECT,
+ send_ldap_error((&nop), rs, LDAP_NO_SUCH_OBJECT,
"attempt to modify nonexistent local record");
return(rs->sr_err);
}
-
+ nop = *op;
/*
** fetch entry from local backend;
** if it exists:
**
*/
+ op->o_bd->bd_info = (BackendInfo *) on->on_info;
rc = be_entry_get_rw(op, &op->o_req_ndn, NULL, NULL, 0, &e);
+ op->o_bd->bd_info = (BackendInfo *) on;
if(e && rc == LDAP_SUCCESS) {
Debug(LDAP_DEBUG_TRACE, "=> translucent_modify: found local entry\n", 0, 0, 0);
erc = SLAP_CB_CONTINUE;
release:
if(re) {
- op->o_bd->be_private = ov->private;
- if(ov->info->bi_entry_release_rw)
- ov->info->bi_entry_release_rw(op, re, 0);
+ if(ov->db.bd_info->bi_entry_release_rw)
+ ov->db.bd_info->bi_entry_release_rw(&nop, re, 0);
else
entry_free(re);
- op->o_bd->be_private = private;
}
+ op->o_bd->bd_info = (BackendInfo *) on->on_info;
be_entry_release_r(op, e);
+ op->o_bd->bd_info = (BackendInfo *) on;
if(erc == SLAP_CB_CONTINUE) {
- op->o_bd->bd_info = (BackendInfo *) on;
return(erc);
} else if(erc) {
send_ldap_error(op, rs, erc,
/* don't leak remote entry copy */
if(re) {
- op->o_bd->be_private = ov->private;
- if(ov->info->bi_entry_release_rw)
- ov->info->bi_entry_release_rw(op, re, 0);
+ if(ov->db.bd_info->bi_entry_release_rw)
+ ov->db.bd_info->bi_entry_release_rw(&nop, re, 0);
else
entry_free(re);
- op->o_bd->be_private = private;
}
/*
** foreach Modification:
"modification contained other than ADD or REPLACE");
return(rs->sr_err);
}
- op->o_bd->bd_info = (BackendInfo *) on;
/* rs->sr_text = "no valid modification found"; */
rs->sr_err = LDAP_SUCCESS;
send_ldap_result(op, rs);
nop.o_tag = LDAP_REQ_ADD;
nop.oq_add.rs_e = ≠
- op->o_bd->bd_info = (BackendInfo *) on;
glue_parent(&nop);
cb.sc_response = translucent_tag_cb;
}
static int translucent_compare(Operation *op, SlapReply *rs) {
+ Operation nop = *op;
slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
translucent_info *ov = on->on_bi.bi_private;
- void *private = op->o_bd->be_private;
-
AttributeAssertion *ava = op->orc_ava;
Entry *e;
int rc;
** CONTINUE and let it do the compare;
**
*/
-
op->o_bd->bd_info = (BackendInfo *) on->on_info;
rc = be_entry_get_rw(op, &op->o_req_ndn, NULL, ava->aa_desc, 0, &e);
if(e && rc == LDAP_SUCCESS) {
op->o_bd->bd_info = (BackendInfo *) on;
return(SLAP_CB_CONTINUE);
}
+ op->o_bd->bd_info = (BackendInfo *) on;
/*
** call compare() in the captive backend;
** return the result;
**
*/
+ nop.o_bd = &ov->db;
+ nop.o_callback = NULL;
+ rc = ov->db.bd_info->bi_op_compare(&nop, rs);
- op->o_bd->be_private = ov->private;
- rc = ov->info->bi_op_compare(op, rs);
- op->o_bd->be_private = private;
- op->o_bd->bd_info = (BackendInfo *) on;
return(rc);
}
slap_overinst *on;
Entry *e, *re = NULL;
Attribute *a, *ax, *an, *as = NULL;
- void *private;
+ Operation * original_op, local_op;
int rc;
if(!op || !rs || rs->sr_type != REP_SEARCH || !rs->sr_entry)
return(SLAP_CB_CONTINUE);
- Debug(LDAP_DEBUG_TRACE, "==> tranclucent_search_cb: %s\n",
+ Debug(LDAP_DEBUG_TRACE, "==> translucent_search_cb: %s\n",
rs->sr_entry->e_name.bv_val, 0, 0);
- on = (slap_overinst *) op->o_bd->bd_info;
- op->o_bd->bd_info = (BackendInfo *) on->on_info;
-
- private = op->o_bd->be_private;
- op->o_bd->be_private = op->o_callback->sc_private;
+ original_op = op->o_callback->sc_private;
+ on = (slap_overinst *) original_op->o_bd->bd_info;
+ local_op = *original_op;
- rc = be_entry_get_rw(op, &rs->sr_entry->e_nname, NULL, NULL, 0, &e);
+ local_op.o_bd->bd_info = (BackendInfo *) on->on_info->oi_orig;
+ rc = be_entry_get_rw(&local_op, &rs->sr_entry->e_nname, NULL, NULL, 0, &e);
+ local_op.o_bd->bd_info = (BackendInfo *) on;
/*
** if we got an entry from local backend:
an->a_next = as;
as = an;
}
- be_entry_release_r(op, e);
+ local_op.o_bd->bd_info = (BackendInfo *) on->on_info->oi_orig;
+ be_entry_release_r(&local_op, e);
+ local_op.o_bd->bd_info = (BackendInfo *) on;
/* literally append, so locals are always last */
if(as) {
rs->sr_flags |= REP_ENTRY_MUSTBEFREED;
}
- op->o_bd->be_private = private;
- op->o_bd->bd_info = (BackendInfo *) on;
-
return(SLAP_CB_CONTINUE);
}
*/
static int translucent_search(Operation *op, SlapReply *rs) {
- Operation nop = *op;
-
slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
- slap_callback cb = { NULL, NULL, NULL, NULL };
+ Operation nop = *op;
translucent_info *ov = on->on_bi.bi_private;
- void *private = op->o_bd->be_private;
- int rc;
+ slap_callback cb = { NULL, NULL, NULL, NULL };
Debug(LDAP_DEBUG_TRACE, "==> translucent_search: <%s> %s\n",
op->o_req_dn.bv_val, op->ors_filterstr.bv_val, 0);
- cb.sc_response = (slap_response *) translucent_search_cb;
- cb.sc_private = private;
+ cb.sc_response = (slap_response *) translucent_search_cb;
+ cb.sc_private = op;
cb.sc_next = nop.o_callback;
- nop.o_callback = &cb;
-
- op->o_bd->be_private = ov->private;
- rc = ov->info->bi_op_search(&nop, rs);
- op->o_bd->be_private = private;
- return(rs->sr_err);
+ nop.o_callback = &cb;
+ nop.o_bd = &ov->db;
+ return (ov->db.bd_info->bi_op_search(&nop, rs));
}
static int translucent_bind(Operation *op, SlapReply *rs) {
slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
+ Operation nop = *op;
translucent_info *ov = on->on_bi.bi_private;
- void *private = op->o_bd->be_private;
- int rc = 0;
Debug(LDAP_DEBUG_TRACE, "translucent_bind: <%s> method %d\n",
op->o_req_dn.bv_val, op->orb_method, 0);
- op->o_bd->be_private = ov->private;
- rc = ov->info->bi_op_bind(op, rs);
- op->o_bd->be_private = private;
-
- return(rc);
+ nop.o_bd = &ov->db;
+ return (ov->db.bd_info->bi_op_bind(&nop, rs));
}
/*
static int translucent_connection_destroy(BackendDB *be, Connection *conn) {
slap_overinst *on = (slap_overinst *) be->bd_info;
translucent_info *ov = on->on_bi.bi_private;
- void *private = be->be_private;
int rc = 0;
Debug(LDAP_DEBUG_TRACE, "translucent_connection_destroy\n", 0, 0, 0);
- be->be_private = ov->private;
- rc = ov->info->bi_connection_destroy(be, conn);
- be->be_private = private;
+ rc = ov->db.bd_info->bi_connection_destroy(&ov->db, conn);
return(rc);
}
{
slap_overinst *on = (slap_overinst *) be->bd_info;
translucent_info *ov = on->on_bi.bi_private;
- void *private = be->be_private;
- void *be_cf_ocs = be->be_cf_ocs;
- int rc;
- /* "this should never happen" */
- if(!ov->info) {
- fprintf(stderr, "fatal: captive backend not initialized");
- return(1);
- }
+ Debug(LDAP_DEBUG_TRACE, "==> translucent_db_config: %s\n",
+ argc ? argv[0] : "", 0, 0);
- be->be_private = ov->private;
- be->be_cf_ocs = ov->info->bi_cf_ocs;
- rc = ov->info->bi_db_config ? ov->info->bi_db_config(be, fname, lineno, argc, argv) : 0;
- be->be_private = private;
- be->be_cf_ocs = be_cf_ocs;
-
- /* pass okay or error up, SLAP_CONF_UNKNOWN might be ours */
- if(rc == 0 || rc == 1) return(rc);
-
- rc = 0;
- if(!strcasecmp(*argv, "translucent_strict")) {
- ov->strict++;
- } else if(!strcasecmp(*argv, "translucent_no_glue")) {
- ov->glue++;
- } else {
- fprintf(stderr, "%s: line %d: unknown keyword %s\n",
- fname, lineno, *argv);
- rc = SLAP_CONF_UNKNOWN;
- }
- return(rc);
+ /* Something for the captive database? */
+ if ( ov->db.bd_info && ov->db.bd_info->bi_db_config )
+ return ov->db.bd_info->bi_db_config( &ov->db, fname, lineno,
+ argc, argv );
+ return SLAP_CONF_UNKNOWN;
}
/*
static int translucent_db_init(BackendDB *be) {
slap_overinst *on = (slap_overinst *) be->bd_info;
- void *private = be->be_private;
translucent_info *ov;
int rc;
- Debug(LDAP_DEBUG_TRACE, "==> translucent_init\n", 0, 0, 0);
+ Debug(LDAP_DEBUG_TRACE, "==> translucent_db_init\n", 0, 0, 0);
ov = ch_calloc(1, sizeof(translucent_info));
- ov->info = backend_info("ldap");
+ on->on_bi.bi_private = ov;
+ ov->db = *be;
+ ov->db.be_private = NULL;
+ ov->db.be_pcl_mutexp = &ov->db.be_pcl_mutex;
- if(!ov->info) {
- ch_free( ov );
- Debug(LDAP_DEBUG_ANY, "translucent: backend_info failed!\n", 0, 0, 0);
- return(1);
+ if ( !backend_db_init( "ldap", &ov->db )) {
+ Debug( LDAP_DEBUG_CONFIG, "translucent: unable to open captive back-ldap\n", 0, 0, 0);
+ return 1;
}
-
- /* forcibly disable schema checking on the local backend */
SLAP_DBFLAGS(be) |= SLAP_DBFLAG_NO_SCHEMA_CHECK;
+ SLAP_DBFLAGS(be) |= SLAP_DBFLAG_NOLASTMOD;
- be->be_private = NULL;
- rc = ov->info->bi_db_init ? ov->info->bi_db_init(be) : 0;
-
- if(rc) Debug(LDAP_DEBUG_TRACE,
- "translucent: bi_db_init() returned error %d\n", rc, 0, 0);
-
- ov->private = be->be_private;
- be->be_private = private;
- on->on_bi.bi_private = ov;
- return(rc);
+ return 0;
}
/*
static int translucent_db_open(BackendDB *be) {
slap_overinst *on = (slap_overinst *) be->bd_info;
translucent_info *ov = on->on_bi.bi_private;
- void *private = be->be_private;
int rc;
- /* "should never happen" */
- if(!ov->info) {
- Debug(LDAP_DEBUG_ANY, "translucent_open() called with bad ov->info\n", 0, 0, 0);
- return(LDAP_OTHER);
- }
+ Debug(LDAP_DEBUG_TRACE, "==> translucent_db_open\n", 0, 0, 0);
- Debug(LDAP_DEBUG_TRACE, "translucent_open\n", 0, 0, 0);
+ /* need to inherit something from the original database... */
+ ov->db.be_def_limit = be->be_def_limit;
+ ov->db.be_limits = be->be_limits;
+ ov->db.be_acl = be->be_acl;
+ ov->db.be_dfltaccess = be->be_dfltaccess;
- be->be_private = ov->private;
- rc = ov->info->bi_db_open ? ov->info->bi_db_open(be) : 0;
- be->be_private = private;
+ rc = backend_startup_one( &ov->db );
if(rc) Debug(LDAP_DEBUG_TRACE,
"translucent: bi_db_open() returned error %d\n", rc, 0, 0);
translucent_info *ov = on->on_bi.bi_private;
int rc = 0;
- if ( ov ) {
- void *private = be->be_private;
+ Debug(LDAP_DEBUG_TRACE, "==> translucent_db_close\n", 0, 0, 0);
- be->be_private = ov->private;
- rc = (ov->info && ov->info->bi_db_close) ? ov->info->bi_db_close(be) : 0;
- be->be_private = private;
+ if ( ov ) {
+ rc = (ov->db.bd_info && ov->db.bd_info->bi_db_close) ? ov->db.bd_info->bi_db_close(&ov->db) : 0;
}
return(rc);
translucent_info *ov = on->on_bi.bi_private;
int rc = 0;
- if ( ov ) {
- void *private = be->be_private;
+ Debug(LDAP_DEBUG_TRACE, "==> translucent_db_close\n", 0, 0, 0);
- be->be_private = ov->private;
- rc = (ov->info && ov->info->bi_db_destroy) ? ov->info->bi_db_destroy(be) : 0;
- be->be_private = private;
+ if ( ov ) {
+ rc = (ov->db.bd_info && ov->db.bd_info->bi_db_destroy) ? ov->db.bd_info->bi_db_destroy(&ov->db) : 0;
ch_free(ov);
on->on_bi.bi_private = NULL;
}
int translucent_initialize() {
+ int rc;
+
+ Debug(LDAP_DEBUG_TRACE, "==> translucent_initialize\n", 0, 0, 0);
+
translucent.on_bi.bi_type = "translucent";
translucent.on_bi.bi_db_init = translucent_db_init;
translucent.on_bi.bi_db_config = translucent_db_config;
translucent.on_bi.bi_op_compare = translucent_compare;
translucent.on_bi.bi_connection_destroy = translucent_connection_destroy;
+ translucent.on_bi.bi_cf_ocs = translucentocs;
+ rc = config_register_schema ( translucentcfg, translucentocs );
+ if ( rc ) return rc;
+
return(overlay_register(&translucent));
}
#endif
#endif /* SLAPD_OVER_TRANSLUCENT */
-