From 87d9353b12f393c2cddc5a2ca9c6ba8b15be89fd Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Sat, 24 Jun 2006 01:35:35 +0000 Subject: [PATCH] Dynamic config --- servers/slapd/overlays/translucent.c | 300 +++++++++++++++------------ 1 file changed, 164 insertions(+), 136 deletions(-) diff --git a/servers/slapd/overlays/translucent.c b/servers/slapd/overlays/translucent.c index 22936a8def..0a446c83ab 100644 --- a/servers/slapd/overlays/translucent.c +++ b/servers/slapd/overlays/translucent.c @@ -31,16 +31,93 @@ #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; /* @@ -91,9 +168,10 @@ void glue_parent(Operation *op) { 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 ); @@ -147,9 +225,10 @@ static int translucent_add(Operation *op, SlapReply *rs) { 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); } @@ -170,9 +249,10 @@ static int translucent_modrdn(Operation *op, SlapReply *rs) { 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); } @@ -191,6 +271,7 @@ static int translucent_delete(Operation *op, SlapReply *rs) { 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); @@ -220,7 +301,6 @@ static int translucent_modify(Operation *op, SlapReply *rs) { 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; @@ -237,17 +317,14 @@ static int translucent_modify(Operation *op, SlapReply *rs) { ** */ - 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: @@ -261,7 +338,9 @@ static int translucent_modify(Operation *op, SlapReply *rs) { ** */ + 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); @@ -297,16 +376,15 @@ static int translucent_modify(Operation *op, SlapReply *rs) { 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, @@ -317,12 +395,10 @@ release: /* 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: @@ -368,7 +444,6 @@ release: "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); @@ -387,7 +462,6 @@ release: 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; @@ -401,10 +475,9 @@ release: } 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; @@ -417,7 +490,6 @@ static int translucent_compare(Operation *op, SlapReply *rs) { ** 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) { @@ -425,17 +497,17 @@ static int translucent_compare(Operation *op, SlapReply *rs) { 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); } @@ -449,22 +521,22 @@ static int translucent_search_cb(Operation *op, SlapReply *rs) { 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: @@ -499,7 +571,9 @@ static int translucent_search_cb(Operation *op, SlapReply *rs) { 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) { @@ -514,9 +588,6 @@ static int translucent_search_cb(Operation *op, SlapReply *rs) { rs->sr_flags |= REP_ENTRY_MUSTBEFREED; } - op->o_bd->be_private = private; - op->o_bd->bd_info = (BackendInfo *) on; - return(SLAP_CB_CONTINUE); } @@ -528,27 +599,21 @@ static int translucent_search_cb(Operation *op, SlapReply *rs) { */ 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)); } @@ -560,18 +625,14 @@ static int translucent_search(Operation *op, SlapReply *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)); } /* @@ -583,14 +644,11 @@ static int translucent_bind(Operation *op, SlapReply *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); } @@ -612,36 +670,15 @@ static int translucent_db_config( { 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; } /* @@ -652,34 +689,25 @@ static int translucent_db_config( 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; } /* @@ -691,20 +719,17 @@ static int translucent_db_init(BackendDB *be) { 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); @@ -724,12 +749,10 @@ static int translucent_db_close(BackendDB *be) { 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); @@ -746,12 +769,10 @@ static int translucent_db_destroy(BackendDB *be) { 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; } @@ -767,6 +788,10 @@ static int translucent_db_destroy(BackendDB *be) { 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; @@ -782,6 +807,10 @@ int translucent_initialize() { 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)); } @@ -792,4 +821,3 @@ int init_module(int argc, char *argv[]) { #endif #endif /* SLAPD_OVER_TRANSLUCENT */ - -- 2.39.5