--- servers/slapd/overlays/rwm.c 2004/12/01 20:47:13 1.37 +++ servers/slapd/overlays/rwm.c 2004/12/30 21:29:58 1.37.2.1 @@ -1,5 +1,5 @@ /* rwm.c - rewrite/remap operations */ -/* $OpenLDAP: pkg/ldap/servers/slapd/overlays/rwm.c,v 1.36 2004/11/13 16:27:15 ando Exp $ */ +/* $OpenLDAP: pkg/ldap/servers/slapd/overlays/rwm.c,v 1.40 2004/12/30 16:46:38 ando Exp $ */ /* This work is part of OpenLDAP Software . * * Copyright 2003-2004 The OpenLDAP Foundation. @@ -83,7 +83,7 @@ rwm_op_dn_massage( Operation *op, SlapRe } static int -rwm_add( Operation *op, SlapReply *rs ) +rwm_op_add( Operation *op, SlapReply *rs ) { slap_overinst *on = (slap_overinst *) op->o_bd->bd_info; struct ldaprwmap *rwmap = @@ -182,7 +182,7 @@ cleanup_attr:; } static int -rwm_bind( Operation *op, SlapReply *rs ) +rwm_op_bind( Operation *op, SlapReply *rs ) { slap_overinst *on = (slap_overinst *) op->o_bd->bd_info; struct ldaprwmap *rwmap = @@ -208,7 +208,7 @@ rwm_bind( Operation *op, SlapReply *rs ) } static int -rwm_unbind( Operation *op, SlapReply *rs ) +rwm_op_unbind( Operation *op, SlapReply *rs ) { slap_overinst *on = (slap_overinst *) op->o_bd->bd_info; struct ldaprwmap *rwmap = @@ -222,7 +222,7 @@ rwm_unbind( Operation *op, SlapReply *rs } static int -rwm_compare( Operation *op, SlapReply *rs ) +rwm_op_compare( Operation *op, SlapReply *rs ) { slap_overinst *on = (slap_overinst *) op->o_bd->bd_info; struct ldaprwmap *rwmap = @@ -263,14 +263,22 @@ rwm_compare( Operation *op, SlapReply *r mapped_at = op->orc_ava->aa_desc->ad_cname; } else { - rwm_map( &rwmap->rwm_at, &op->orc_ava->aa_desc->ad_cname, - &mapped_at, RWM_MAP ); - if ( BER_BVISNULL( &mapped_at ) || BER_BVISEMPTY( &mapped_at ) ) - { - op->o_bd->bd_info = (BackendInfo *)on->on_info; - send_ldap_error( op, rs, LDAP_OTHER, "compare attributeType map error" ); - return -1; + struct ldapmapping *mapping = NULL; + AttributeDescription *ad = op->orc_ava->aa_desc; + + ( void )rwm_mapping( &rwmap->rwm_at, &op->orc_ava->aa_desc->ad_cname, + &mapping, RWM_MAP ); + if ( mapping == NULL ) { + if ( rwmap->rwm_at.drop_missing ) { + op->o_bd->bd_info = (BackendInfo *)on->on_info; + send_ldap_error( op, rs, LDAP_OTHER, "compare attributeType map error" ); + return -1; + } + + } else { + ad = mapping->m_dst_ad; } + if ( op->orc_ava->aa_desc->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName ) { struct berval *mapped_valsp[2]; @@ -295,13 +303,14 @@ rwm_compare( Operation *op, SlapReply *r op->orc_ava->aa_value = mapped_vals[0]; } + op->orc_ava->aa_desc = ad; } return SLAP_CB_CONTINUE; } static int -rwm_delete( Operation *op, SlapReply *rs ) +rwm_op_delete( Operation *op, SlapReply *rs ) { slap_overinst *on = (slap_overinst *) op->o_bd->bd_info; int rc; @@ -322,7 +331,7 @@ rwm_delete( Operation *op, SlapReply *rs } static int -rwm_modify( Operation *op, SlapReply *rs ) +rwm_op_modify( Operation *op, SlapReply *rs ) { slap_overinst *on = (slap_overinst *) op->o_bd->bd_info; struct ldaprwmap *rwmap = @@ -460,7 +469,7 @@ cleanup_mod:; } static int -rwm_modrdn( Operation *op, SlapReply *rs ) +rwm_op_modrdn( Operation *op, SlapReply *rs ) { slap_overinst *on = (slap_overinst *) op->o_bd->bd_info; struct ldaprwmap *rwmap = @@ -515,7 +524,8 @@ rwm_modrdn( Operation *op, SlapReply *rs return -1; } - /* TODO: rewrite attribute types, values of DN-valued attributes ... */ + /* TODO: rewrite newRDN, attribute types, + * values of DN-valued attributes ... */ return SLAP_CB_CONTINUE; } @@ -543,7 +553,7 @@ static int rwm_freeself( Operation *op, } static int -rwm_search( Operation *op, SlapReply *rs ) +rwm_op_search( Operation *op, SlapReply *rs ) { slap_overinst *on = (slap_overinst *) op->o_bd->bd_info; struct ldaprwmap *rwmap = @@ -984,6 +994,32 @@ rwm_operational( Operation *op, SlapRepl return SLAP_CB_CONTINUE; } +#if 0 +/* don't use this; it cannot be reverted, and leaves op->o_req_dn + * rewritten for subsequent operations; fine for plain suffixmassage, + * but destroys everything else */ +static int +rwm_chk_referrals( Operation *op, SlapReply *rs ) +{ + slap_overinst *on = (slap_overinst *) op->o_bd->bd_info; + int rc; + +#ifdef ENABLE_REWRITE + rc = rwm_op_dn_massage( op, rs, "referralCheckDN" ); +#else /* ! ENABLE_REWRITE */ + rc = 1; + rc = rwm_op_dn_massage( op, rs, &rc ); +#endif /* ! ENABLE_REWRITE */ + if ( rc != LDAP_SUCCESS ) { + op->o_bd->bd_info = (BackendInfo *)on->on_info; + send_ldap_error( op, rs, rc, "referralCheckDN massage error" ); + return -1; + } + + return SLAP_CB_CONTINUE; +} +#endif + static int rwm_rw_config( BackendDB *be, @@ -1313,16 +1349,18 @@ rwm_init(void) rwm.on_bi.bi_db_config = rwm_db_config; rwm.on_bi.bi_db_destroy = rwm_db_destroy; - rwm.on_bi.bi_op_bind = rwm_bind; - rwm.on_bi.bi_op_search = rwm_search; - rwm.on_bi.bi_op_compare = rwm_compare; - rwm.on_bi.bi_op_modify = rwm_modify; - rwm.on_bi.bi_op_modrdn = rwm_modrdn; - rwm.on_bi.bi_op_add = rwm_add; - rwm.on_bi.bi_op_delete = rwm_delete; - rwm.on_bi.bi_op_unbind = rwm_unbind; + rwm.on_bi.bi_op_bind = rwm_op_bind; + rwm.on_bi.bi_op_search = rwm_op_search; + rwm.on_bi.bi_op_compare = rwm_op_compare; + rwm.on_bi.bi_op_modify = rwm_op_modify; + rwm.on_bi.bi_op_modrdn = rwm_op_modrdn; + rwm.on_bi.bi_op_add = rwm_op_add; + rwm.on_bi.bi_op_delete = rwm_op_delete; + rwm.on_bi.bi_op_unbind = rwm_op_unbind; rwm.on_bi.bi_extended = rwm_extended; + rwm.on_bi.bi_operational = rwm_operational; + rwm.on_bi.bi_chk_referrals = 0 /* rwm_chk_referrals */ ; rwm.on_response = rwm_response;