version 1.37.2.16, 2007/01/02 21:44:08
|
version 1.37.2.17, 2007/01/03 08:55:04
|
Line 1
|
Line 1
|
/* rwm.c - rewrite/remap operations */ |
/* rwm.c - rewrite/remap operations */ |
/* $OpenLDAP: pkg/ldap/servers/slapd/overlays/rwm.c,v 1.37.2.15 2006/01/03 22:16:25 kurt Exp $ */ |
/* $OpenLDAP: pkg/ldap/servers/slapd/overlays/rwm.c,v 1.37.2.16 2007/01/02 21:44:08 kurt Exp $ */ |
/* This work is part of OpenLDAP Software <http://www.openldap.org/>. |
/* This work is part of OpenLDAP Software <http://www.openldap.org/>. |
* |
* |
* Copyright 2003-2007 The OpenLDAP Foundation. |
* Copyright 2003-2007 The OpenLDAP Foundation. |
Line 26
|
Line 26
|
#include "slap.h" |
#include "slap.h" |
#include "rwm.h" |
#include "rwm.h" |
|
|
|
typedef struct rwm_op_state { |
|
ber_tag_t r_tag; |
|
struct berval ro_dn; |
|
struct berval ro_ndn; |
|
struct berval r_dn; |
|
struct berval r_ndn; |
|
OpRequest o_request; |
|
} rwm_op_state; |
|
|
|
static int |
|
rwm_db_destroy( BackendDB *be ); |
|
|
|
typedef struct rwm_op_cb { |
|
slap_callback cb; |
|
rwm_op_state ros; |
|
} rwm_op_cb; |
|
|
static int |
static int |
rwm_op_dn_massage( Operation *op, SlapReply *rs, void *cookie ) |
rwm_op_cleanup( Operation *op, SlapReply *rs ) |
|
{ |
|
slap_callback *cb = op->o_callback; |
|
rwm_op_state *ros = cb->sc_private; |
|
|
|
if ( rs->sr_type == REP_RESULT || rs->sr_type == REP_EXTENDED || |
|
op->o_abandon || rs->sr_err == SLAPD_ABANDON ) { |
|
|
|
op->o_req_dn = ros->ro_dn; |
|
op->o_req_ndn = ros->ro_ndn; |
|
|
|
if ( !BER_BVISEMPTY( &ros->r_dn )) ch_free( ros->r_dn.bv_val ); |
|
if ( !BER_BVISEMPTY( &ros->r_ndn )) ch_free( ros->r_ndn.bv_val ); |
|
|
|
switch( ros->r_tag ) { |
|
case LDAP_REQ_COMPARE: |
|
if ( op->orc_ava->aa_value.bv_val != ros->orc_ava->aa_value.bv_val ) |
|
op->o_tmpfree( op->orc_ava->aa_value.bv_val, op->o_tmpmemctx ); |
|
op->orc_ava = ros->orc_ava; |
|
break; |
|
case LDAP_REQ_MODIFY: |
|
slap_mods_free( op->orm_modlist, 1 ); |
|
op->orm_modlist = ros->orm_modlist; |
|
break; |
|
case LDAP_REQ_MODRDN: |
|
if ( op->orr_newSup != ros->orr_newSup ) { |
|
ch_free( op->orr_newSup->bv_val ); |
|
ch_free( op->orr_nnewSup->bv_val ); |
|
op->o_tmpfree( op->orr_newSup, op->o_tmpmemctx ); |
|
op->o_tmpfree( op->orr_nnewSup, op->o_tmpmemctx ); |
|
op->orr_newSup = ros->orr_newSup; |
|
op->orr_nnewSup = ros->orr_nnewSup; |
|
} |
|
break; |
|
case LDAP_REQ_SEARCH: |
|
ch_free( op->ors_attrs ); |
|
filter_free_x( op, op->ors_filter ); |
|
ch_free( op->ors_filterstr.bv_val ); |
|
op->ors_attrs = ros->ors_attrs; |
|
op->ors_filter = ros->ors_filter; |
|
op->ors_filterstr = ros->ors_filterstr; |
|
break; |
|
case LDAP_REQ_EXTENDED: |
|
if ( op->ore_reqdata != ros->ore_reqdata ) { |
|
ber_bvfree( op->ore_reqdata ); |
|
op->ore_reqdata = ros->ore_reqdata; |
|
} |
|
break; |
|
default: break; |
|
} |
|
op->o_callback = op->o_callback->sc_next; |
|
op->o_tmpfree( cb, op->o_tmpmemctx ); |
|
} |
|
|
|
return SLAP_CB_CONTINUE; |
|
} |
|
|
|
static rwm_op_cb * |
|
rwm_callback_get( Operation *op, SlapReply *rs ) |
|
{ |
|
rwm_op_cb *roc = NULL; |
|
|
|
roc = op->o_tmpalloc( sizeof( struct rwm_op_cb ), op->o_tmpmemctx ); |
|
roc->cb.sc_cleanup = rwm_op_cleanup; |
|
roc->cb.sc_response = NULL; |
|
roc->cb.sc_next = op->o_callback; |
|
roc->cb.sc_private = &roc->ros; |
|
roc->ros.r_tag = op->o_tag; |
|
roc->ros.ro_dn = op->o_req_dn; |
|
roc->ros.ro_ndn = op->o_req_ndn; |
|
roc->ros.o_request = op->o_request; |
|
BER_BVZERO( &roc->ros.r_dn ); |
|
BER_BVZERO( &roc->ros.r_ndn ); |
|
|
|
return roc; |
|
} |
|
|
|
static int |
|
rwm_op_dn_massage( Operation *op, SlapReply *rs, void *cookie, |
|
rwm_op_state *ros ) |
{ |
{ |
slap_overinst *on = (slap_overinst *) op->o_bd->bd_info; |
slap_overinst *on = (slap_overinst *) op->o_bd->bd_info; |
struct ldaprwmap *rwmap = |
struct ldaprwmap *rwmap = |
Line 74 rwm_op_dn_massage( Operation *op, SlapRe
|
Line 170 rwm_op_dn_massage( Operation *op, SlapRe
|
} |
} |
|
|
if ( op->o_req_dn.bv_val != op->o_req_ndn.bv_val ) { |
if ( op->o_req_dn.bv_val != op->o_req_ndn.bv_val ) { |
op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx ); |
|
op->o_req_dn = dn; |
op->o_req_dn = dn; |
|
ros->r_dn = dn; |
} else { |
} else { |
op->o_req_dn = ndn; |
op->o_req_dn = ndn; |
} |
} |
op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx ); |
ros->r_ndn = ndn; |
op->o_req_ndn = ndn; |
op->o_req_ndn = ndn; |
|
|
return LDAP_SUCCESS; |
return LDAP_SUCCESS; |
Line 98 rwm_op_add( Operation *op, SlapReply *rs
|
Line 194 rwm_op_add( Operation *op, SlapReply *rs
|
char *olddn = op->o_req_dn.bv_val; |
char *olddn = op->o_req_dn.bv_val; |
int isupdate; |
int isupdate; |
|
|
|
rwm_op_cb *roc = rwm_callback_get( op, rs ); |
|
|
#ifdef ENABLE_REWRITE |
#ifdef ENABLE_REWRITE |
rc = rwm_op_dn_massage( op, rs, "addDN" ); |
rc = rwm_op_dn_massage( op, rs, "addDN", &roc->ros ); |
#else /* ! ENABLE_REWRITE */ |
#else /* ! ENABLE_REWRITE */ |
rc = 1; |
rc = 1; |
rc = rwm_op_dn_massage( op, rs, &rc ); |
rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros ); |
#endif /* ! ENABLE_REWRITE */ |
#endif /* ! ENABLE_REWRITE */ |
if ( rc != LDAP_SUCCESS ) { |
if ( rc != LDAP_SUCCESS ) { |
op->o_bd->bd_info = (BackendInfo *)on->on_info; |
op->o_bd->bd_info = (BackendInfo *)on->on_info; |
Line 222 cleanup_attr:;
|
Line 320 cleanup_attr:;
|
attr_free( a ); |
attr_free( a ); |
} |
} |
|
|
/* TODO: map attribute types, values of DN-valued attributes ... */ |
op->o_callback = &roc->cb; |
|
|
return SLAP_CB_CONTINUE; |
return SLAP_CB_CONTINUE; |
} |
} |
|
|
Line 258 rwm_op_bind( Operation *op, SlapReply *r
|
Line 357 rwm_op_bind( Operation *op, SlapReply *r
|
slap_overinst *on = (slap_overinst *) op->o_bd->bd_info; |
slap_overinst *on = (slap_overinst *) op->o_bd->bd_info; |
int rc; |
int rc; |
|
|
|
rwm_op_cb *roc = rwm_callback_get( op, rs ); |
|
|
#ifdef ENABLE_REWRITE |
#ifdef ENABLE_REWRITE |
rc = rwm_op_dn_massage( op, rs, "bindDN" ); |
rc = rwm_op_dn_massage( op, rs, "bindDN", &roc->ros ); |
#else /* ! ENABLE_REWRITE */ |
#else /* ! ENABLE_REWRITE */ |
rc = 1; |
rc = 1; |
rc = rwm_op_dn_massage( op, rs, &rc ); |
rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros ); |
#endif /* ! ENABLE_REWRITE */ |
#endif /* ! ENABLE_REWRITE */ |
if ( rc != LDAP_SUCCESS ) { |
if ( rc != LDAP_SUCCESS ) { |
op->o_bd->bd_info = (BackendInfo *)on->on_info; |
op->o_bd->bd_info = (BackendInfo *)on->on_info; |
Line 270 rwm_op_bind( Operation *op, SlapReply *r
|
Line 371 rwm_op_bind( Operation *op, SlapReply *r
|
return -1; |
return -1; |
} |
} |
|
|
|
op->o_callback = &roc->cb; |
|
|
return SLAP_CB_CONTINUE; |
return SLAP_CB_CONTINUE; |
} |
} |
|
|
Line 295 rwm_op_compare( Operation *op, SlapReply
|
Line 398 rwm_op_compare( Operation *op, SlapReply
|
(struct ldaprwmap *)on->on_bi.bi_private; |
(struct ldaprwmap *)on->on_bi.bi_private; |
|
|
int rc; |
int rc; |
struct berval mapped_at = BER_BVNULL, |
struct berval mapped_vals[2] = { BER_BVNULL, BER_BVNULL }; |
mapped_vals[2] = { BER_BVNULL, BER_BVNULL }; |
|
|
rwm_op_cb *roc = rwm_callback_get( op, rs ); |
|
|
#ifdef ENABLE_REWRITE |
#ifdef ENABLE_REWRITE |
rc = rwm_op_dn_massage( op, rs, "compareDN" ); |
rc = rwm_op_dn_massage( op, rs, "compareDN", &roc->ros ); |
#else /* ! ENABLE_REWRITE */ |
#else /* ! ENABLE_REWRITE */ |
rc = 1; |
rc = 1; |
rc = rwm_op_dn_massage( op, rs, &rc ); |
rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros ); |
#endif /* ! ENABLE_REWRITE */ |
#endif /* ! ENABLE_REWRITE */ |
if ( rc != LDAP_SUCCESS ) { |
if ( rc != LDAP_SUCCESS ) { |
op->o_bd->bd_info = (BackendInfo *)on->on_info; |
op->o_bd->bd_info = (BackendInfo *)on->on_info; |
Line 323 rwm_op_compare( Operation *op, SlapReply
|
Line 427 rwm_op_compare( Operation *op, SlapReply
|
return -1; |
return -1; |
|
|
} else if ( mapped_vals[0].bv_val != op->orc_ava->aa_value.bv_val ) { |
} else if ( mapped_vals[0].bv_val != op->orc_ava->aa_value.bv_val ) { |
ber_bvreplace_x( &op->orc_ava->aa_value, &mapped_vals[0], op->o_tmpmemctx ); |
ber_dupbv_x( &op->orc_ava->aa_value, &mapped_vals[0], |
|
op->o_tmpmemctx ); |
} |
} |
mapped_at = op->orc_ava->aa_desc->ad_cname; |
|
|
|
} else { |
} else { |
struct ldapmapping *mapping = NULL; |
struct ldapmapping *mapping = NULL; |
Line 373 rwm_op_compare( Operation *op, SlapReply
|
Line 477 rwm_op_compare( Operation *op, SlapReply
|
* already freed the old value, so now |
* already freed the old value, so now |
* it's invalid */ |
* it's invalid */ |
ber_dupbv_x( &op->orc_ava->aa_value, &mapped_vals[0], |
ber_dupbv_x( &op->orc_ava->aa_value, &mapped_vals[0], |
op->o_tmpmemctx ); |
op->o_tmpmemctx ); |
ber_memfree_x( mapped_vals[ 0 ].bv_val, NULL ); |
ber_memfree_x( mapped_vals[ 0 ].bv_val, NULL ); |
} |
} |
} |
} |
op->orc_ava->aa_desc = ad; |
op->orc_ava->aa_desc = ad; |
} |
} |
|
|
|
op->o_callback = &roc->cb; |
|
|
return SLAP_CB_CONTINUE; |
return SLAP_CB_CONTINUE; |
} |
} |
|
|
Line 389 rwm_op_delete( Operation *op, SlapReply
|
Line 495 rwm_op_delete( Operation *op, SlapReply
|
slap_overinst *on = (slap_overinst *) op->o_bd->bd_info; |
slap_overinst *on = (slap_overinst *) op->o_bd->bd_info; |
int rc; |
int rc; |
|
|
|
rwm_op_cb *roc = rwm_callback_get( op, rs ); |
|
|
#ifdef ENABLE_REWRITE |
#ifdef ENABLE_REWRITE |
rc = rwm_op_dn_massage( op, rs, "deleteDN" ); |
rc = rwm_op_dn_massage( op, rs, "deleteDN", &roc->ros ); |
#else /* ! ENABLE_REWRITE */ |
#else /* ! ENABLE_REWRITE */ |
rc = 1; |
rc = 1; |
rc = rwm_op_dn_massage( op, rs, &rc ); |
rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros ); |
#endif /* ! ENABLE_REWRITE */ |
#endif /* ! ENABLE_REWRITE */ |
if ( rc != LDAP_SUCCESS ) { |
if ( rc != LDAP_SUCCESS ) { |
op->o_bd->bd_info = (BackendInfo *)on->on_info; |
op->o_bd->bd_info = (BackendInfo *)on->on_info; |
Line 401 rwm_op_delete( Operation *op, SlapReply
|
Line 509 rwm_op_delete( Operation *op, SlapReply
|
return -1; |
return -1; |
} |
} |
|
|
|
op->o_callback = &roc->cb; |
|
|
return SLAP_CB_CONTINUE; |
return SLAP_CB_CONTINUE; |
} |
} |
|
|
Line 415 rwm_op_modify( Operation *op, SlapReply
|
Line 525 rwm_op_modify( Operation *op, SlapReply
|
Modifications **mlp; |
Modifications **mlp; |
int rc; |
int rc; |
|
|
|
rwm_op_cb *roc = rwm_callback_get( op, rs ); |
|
|
#ifdef ENABLE_REWRITE |
#ifdef ENABLE_REWRITE |
rc = rwm_op_dn_massage( op, rs, "modifyDN" ); |
rc = rwm_op_dn_massage( op, rs, "modifyDN", &roc->ros ); |
#else /* ! ENABLE_REWRITE */ |
#else /* ! ENABLE_REWRITE */ |
rc = 1; |
rc = 1; |
rc = rwm_op_dn_massage( op, rs, &rc ); |
rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros ); |
#endif /* ! ENABLE_REWRITE */ |
#endif /* ! ENABLE_REWRITE */ |
if ( rc != LDAP_SUCCESS ) { |
if ( rc != LDAP_SUCCESS ) { |
op->o_bd->bd_info = (BackendInfo *)on->on_info; |
op->o_bd->bd_info = (BackendInfo *)on->on_info; |
Line 433 rwm_op_modify( Operation *op, SlapReply
|
Line 545 rwm_op_modify( Operation *op, SlapReply
|
Modifications *ml; |
Modifications *ml; |
struct ldapmapping *mapping = NULL; |
struct ldapmapping *mapping = NULL; |
|
|
if ( (*mlp)->sml_desc == slap_schema.si_ad_objectClass |
/* duplicate the modlist */ |
|| (*mlp)->sml_desc == slap_schema.si_ad_structuralObjectClass ) |
ml = ch_malloc( sizeof( Modifications )); |
|
*ml = **mlp; |
|
*mlp = ml; |
|
|
|
if ( ml->sml_desc == slap_schema.si_ad_objectClass |
|
|| ml->sml_desc == slap_schema.si_ad_structuralObjectClass ) |
{ |
{ |
is_oc = 1; |
is_oc = 1; |
|
|
Line 446 rwm_op_modify( Operation *op, SlapReply
|
Line 563 rwm_op_modify( Operation *op, SlapReply
|
int drop_missing; |
int drop_missing; |
|
|
drop_missing = rwm_mapping( &rwmap->rwm_at, |
drop_missing = rwm_mapping( &rwmap->rwm_at, |
&(*mlp)->sml_desc->ad_cname, |
&ml->sml_desc->ad_cname, |
&mapping, RWM_MAP ); |
&mapping, RWM_MAP ); |
if ( drop_missing || ( mapping != NULL && BER_BVISNULL( &mapping->m_dst ) ) ) |
if ( drop_missing || ( mapping != NULL && BER_BVISNULL( &mapping->m_dst ) ) ) |
{ |
{ |
Line 454 rwm_op_modify( Operation *op, SlapReply
|
Line 571 rwm_op_modify( Operation *op, SlapReply
|
} |
} |
} |
} |
|
|
if ( (*mlp)->sml_values != NULL ) { |
if ( ml->sml_values != NULL ) { |
|
int i, num; |
|
struct berval *bva; |
|
|
|
for ( num = 0; !BER_BVISNULL( &ml->sml_values[ num ] ); num++ ) |
|
/* count values */ ; |
|
|
|
bva = ch_malloc( (num+1) * sizeof( struct berval )); |
|
for (i=0; i<num; i++) |
|
ber_dupbv( &bva[i], &ml->sml_values[i] ); |
|
BER_BVZERO( &bva[i] ); |
|
ml->sml_values = bva; |
|
|
|
if ( ml->sml_nvalues ) { |
|
bva = ch_malloc( (num+1) * sizeof( struct berval )); |
|
for (i=0; i<num; i++) |
|
ber_dupbv( &bva[i], &ml->sml_nvalues[i] ); |
|
BER_BVZERO( &bva[i] ); |
|
ml->sml_nvalues = bva; |
|
} |
|
|
if ( is_oc ) { |
if ( is_oc ) { |
int last, j; |
int last, j; |
|
|
for ( last = 0; !BER_BVISNULL( &(*mlp)->sml_values[ last ] ); last++ ) |
last = num-1; |
/* count values */ ; |
|
last--; |
|
|
|
for ( j = 0; !BER_BVISNULL( &(*mlp)->sml_values[ j ] ); j++ ) { |
for ( j = 0; !BER_BVISNULL( &ml->sml_values[ j ] ); j++ ) { |
struct ldapmapping *oc_mapping = NULL; |
struct ldapmapping *oc_mapping = NULL; |
|
|
( void )rwm_mapping( &rwmap->rwm_oc, &(*mlp)->sml_values[ j ], |
( void )rwm_mapping( &rwmap->rwm_oc, &ml->sml_values[ j ], |
&oc_mapping, RWM_MAP ); |
&oc_mapping, RWM_MAP ); |
if ( oc_mapping == NULL ) { |
if ( oc_mapping == NULL ) { |
if ( rwmap->rwm_at.drop_missing ) { |
if ( rwmap->rwm_at.drop_missing ) { |
Line 473 rwm_op_modify( Operation *op, SlapReply
|
Line 608 rwm_op_modify( Operation *op, SlapReply
|
* if the resulting entry is inconsistent, that's |
* if the resulting entry is inconsistent, that's |
* the relayed database's business... |
* the relayed database's business... |
*/ |
*/ |
ch_free( (*mlp)->sml_values[ j ].bv_val ); |
|
if ( last > j ) { |
if ( last > j ) { |
(*mlp)->sml_values[ j ] = (*mlp)->sml_values[ last ]; |
ch_free( ml->sml_values[ j ].bv_val ); |
|
ml->sml_values[ j ] = ml->sml_values[ last ]; |
} |
} |
BER_BVZERO( &(*mlp)->sml_values[ last ] ); |
BER_BVZERO( &ml->sml_values[ last ] ); |
last--; |
last--; |
j--; |
j--; |
} |
} |
|
|
} else { |
} else { |
ch_free( (*mlp)->sml_values[ j ].bv_val ); |
ch_free( ml->sml_values[ j ].bv_val ); |
ber_dupbv( &(*mlp)->sml_values[ j ], &oc_mapping->m_dst ); |
ber_dupbv( &ml->sml_values[ j ], &oc_mapping->m_dst ); |
} |
} |
} |
} |
|
|
} else { |
} else { |
if ( (*mlp)->sml_desc->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName |
if ( ml->sml_desc->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName |
|| ( mapping != NULL && mapping->m_dst_ad->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName ) ) |
|| ( mapping != NULL && mapping->m_dst_ad->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName ) ) |
{ |
{ |
#ifdef ENABLE_REWRITE |
#ifdef ENABLE_REWRITE |
rc = rwm_dnattr_rewrite( op, rs, "modifyAttrDN", |
rc = rwm_dnattr_rewrite( op, rs, "modifyAttrDN", |
(*mlp)->sml_values, |
ml->sml_values, |
(*mlp)->sml_nvalues ? &(*mlp)->sml_nvalues : NULL ); |
ml->sml_nvalues ? &ml->sml_nvalues : NULL ); |
#else /* ! ENABLE_REWRITE */ |
#else /* ! ENABLE_REWRITE */ |
rc = 1; |
rc = 1; |
rc = rwm_dnattr_rewrite( op, rs, &rc, |
rc = rwm_dnattr_rewrite( op, rs, &rc, |
(*mlp)->sml_values, |
ml->sml_values, |
(*mlp)->sml_nvalues ? &(*mlp)->sml_nvalues : NULL ); |
ml->sml_nvalues ? &ml->sml_nvalues : NULL ); |
#endif /* ! ENABLE_REWRITE */ |
#endif /* ! ENABLE_REWRITE */ |
|
|
} else if ( (*mlp)->sml_desc == slap_schema.si_ad_ref ) { |
} else if ( ml->sml_desc == slap_schema.si_ad_ref ) { |
#ifdef ENABLE_REWRITE |
#ifdef ENABLE_REWRITE |
rc = rwm_referral_rewrite( op, rs, |
rc = rwm_referral_rewrite( op, rs, |
"referralAttrDN", |
"referralAttrDN", |
(*mlp)->sml_values, |
ml->sml_values, |
(*mlp)->sml_nvalues ? &(*mlp)->sml_nvalues : NULL ); |
ml->sml_nvalues ? &ml->sml_nvalues : NULL ); |
#else /* ! ENABLE_REWRITE */ |
#else /* ! ENABLE_REWRITE */ |
rc = 1; |
rc = 1; |
rc = rwm_referral_rewrite( op, rs, &rc, |
rc = rwm_referral_rewrite( op, rs, &rc, |
(*mlp)->sml_values, |
ml->sml_values, |
(*mlp)->sml_nvalues ? &(*mlp)->sml_nvalues : NULL ); |
ml->sml_nvalues ? &ml->sml_nvalues : NULL ); |
#endif /* ! ENABLE_REWRITE */ |
#endif /* ! ENABLE_REWRITE */ |
if ( rc != LDAP_SUCCESS ) { |
if ( rc != LDAP_SUCCESS ) { |
goto cleanup_mod; |
goto cleanup_mod; |
Line 530 next_mod:;
|
Line 665 next_mod:;
|
if ( mapping != NULL ) { |
if ( mapping != NULL ) { |
/* use new attribute description */ |
/* use new attribute description */ |
assert( mapping->m_dst_ad != NULL ); |
assert( mapping->m_dst_ad != NULL ); |
(*mlp)->sml_desc = mapping->m_dst_ad; |
ml->sml_desc = mapping->m_dst_ad; |
} |
} |
|
|
mlp = &(*mlp)->sml_next; |
mlp = &ml->sml_next; |
continue; |
continue; |
|
|
cleanup_mod:; |
cleanup_mod:; |
Line 543 cleanup_mod:;
|
Line 678 cleanup_mod:;
|
free( ml ); |
free( ml ); |
} |
} |
|
|
|
op->o_callback = &roc->cb; |
|
|
return SLAP_CB_CONTINUE; |
return SLAP_CB_CONTINUE; |
} |
} |
|
|
Line 555 rwm_op_modrdn( Operation *op, SlapReply
|
Line 692 rwm_op_modrdn( Operation *op, SlapReply
|
|
|
int rc; |
int rc; |
|
|
|
rwm_op_cb *roc = rwm_callback_get( op, rs ); |
|
|
if ( op->orr_newSup ) { |
if ( op->orr_newSup ) { |
dncookie dc; |
dncookie dc; |
struct berval nnewSup = BER_BVNULL; |
struct berval nnewSup = BER_BVNULL; |
Line 582 rwm_op_modrdn( Operation *op, SlapReply
|
Line 721 rwm_op_modrdn( Operation *op, SlapReply
|
} |
} |
|
|
if ( op->orr_newSup->bv_val != newSup.bv_val ) { |
if ( op->orr_newSup->bv_val != newSup.bv_val ) { |
op->o_tmpfree( op->orr_newSup->bv_val, op->o_tmpmemctx ); |
op->orr_newSup = op->o_tmpalloc( sizeof( struct berval ), |
op->o_tmpfree( op->orr_nnewSup->bv_val, op->o_tmpmemctx ); |
op->o_tmpmemctx ); |
|
op->orr_nnewSup = op->o_tmpalloc( sizeof( struct berval ), |
|
op->o_tmpmemctx ); |
*op->orr_newSup = newSup; |
*op->orr_newSup = newSup; |
*op->orr_nnewSup = nnewSup; |
*op->orr_nnewSup = nnewSup; |
} |
} |
Line 593 rwm_op_modrdn( Operation *op, SlapReply
|
Line 734 rwm_op_modrdn( Operation *op, SlapReply
|
* Rewrite the dn, if needed |
* Rewrite the dn, if needed |
*/ |
*/ |
#ifdef ENABLE_REWRITE |
#ifdef ENABLE_REWRITE |
rc = rwm_op_dn_massage( op, rs, "renameDN" ); |
rc = rwm_op_dn_massage( op, rs, "renameDN", &roc->ros ); |
#else /* ! ENABLE_REWRITE */ |
#else /* ! ENABLE_REWRITE */ |
rc = 1; |
rc = 1; |
rc = rwm_op_dn_massage( op, rs, &rc ); |
rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros ); |
#endif /* ! ENABLE_REWRITE */ |
#endif /* ! ENABLE_REWRITE */ |
if ( rc != LDAP_SUCCESS ) { |
if ( rc != LDAP_SUCCESS ) { |
op->o_bd->bd_info = (BackendInfo *)on->on_info; |
op->o_bd->bd_info = (BackendInfo *)on->on_info; |
send_ldap_error( op, rs, rc, "renameDN massage error" ); |
send_ldap_error( op, rs, rc, "renameDN massage error" ); |
|
if ( op->orr_newSup != roc->ros.orr_newSup ) { |
|
ch_free( op->orr_newSup->bv_val ); |
|
ch_free( op->orr_nnewSup->bv_val ); |
|
op->o_tmpfree( op->orr_newSup, op->o_tmpmemctx ); |
|
op->o_tmpfree( op->orr_nnewSup, op->o_tmpmemctx ); |
|
op->orr_newSup = roc->ros.orr_newSup; |
|
op->orr_nnewSup = roc->ros.orr_nnewSup; |
|
} |
return -1; |
return -1; |
} |
} |
|
|
/* TODO: rewrite newRDN, attribute types, |
/* TODO: rewrite newRDN, attribute types, |
* values of DN-valued attributes ... */ |
* values of DN-valued attributes ... */ |
return SLAP_CB_CONTINUE; |
|
} |
|
|
|
static slap_callback rwm_cb; |
op->o_callback = &roc->cb; |
|
|
static void |
return SLAP_CB_CONTINUE; |
rwm_keyfree( |
|
void *key, |
|
void *data ) |
|
{ |
|
ber_memfree_x( data, NULL ); |
|
} |
} |
|
|
static slap_callback * |
|
rwm_callback_get( Operation *op ) |
|
{ |
|
void *data = NULL; |
|
|
|
if ( op->o_threadctx == NULL ) { |
|
return &rwm_cb; |
|
} |
|
|
|
ldap_pvt_thread_pool_getkey( op->o_threadctx, |
|
rwm_keyfree, &data, NULL ); |
|
if ( data == NULL ) { |
|
data = ch_calloc( sizeof( slap_callback ), 1 ); |
|
ldap_pvt_thread_pool_setkey( op->o_threadctx, |
|
rwm_keyfree, data, rwm_keyfree ); |
|
} |
|
|
|
return (slap_callback *)data; |
|
} |
|
|
|
static int |
static int |
rwm_swap_attrs( Operation *op, SlapReply *rs ) |
rwm_swap_attrs( Operation *op, SlapReply *rs ) |
{ |
{ |
slap_callback *cb = op->o_callback; |
slap_callback *cb = op->o_callback; |
AttributeName *an = (AttributeName *)cb->sc_private; |
rwm_op_state *ros = cb->sc_private; |
|
|
rs->sr_attrs = an; |
rs->sr_attrs = ros->ors_attrs; |
|
|
return SLAP_CB_CONTINUE; |
return SLAP_CB_CONTINUE; |
} |
} |
|
|
static int |
static int |
Line 663 rwm_op_search( Operation *op, SlapReply
|
Line 786 rwm_op_search( Operation *op, SlapReply
|
struct berval fstr = BER_BVNULL; |
struct berval fstr = BER_BVNULL; |
Filter *f = NULL; |
Filter *f = NULL; |
|
|
slap_callback *cb = NULL; |
|
AttributeName *an = NULL; |
AttributeName *an = NULL; |
|
|
char *text = NULL; |
char *text = NULL; |
|
|
|
rwm_op_cb *roc = rwm_callback_get( op, rs ); |
|
|
#ifdef ENABLE_REWRITE |
#ifdef ENABLE_REWRITE |
rc = rewrite_session_var_set( rwmap->rwm_rw, op->o_conn, |
rc = rewrite_session_var_set( rwmap->rwm_rw, op->o_conn, |
"searchFilter", op->ors_filterstr.bv_val ); |
"searchFilter", op->ors_filterstr.bv_val ); |
if ( rc == LDAP_SUCCESS ) |
if ( rc == LDAP_SUCCESS ) |
rc = rwm_op_dn_massage( op, rs, "searchDN" ); |
rc = rwm_op_dn_massage( op, rs, "searchDN", &roc->ros ); |
#else /* ! ENABLE_REWRITE */ |
#else /* ! ENABLE_REWRITE */ |
rc = 1; |
rc = 1; |
rc = rwm_op_dn_massage( op, rs, &rc ); |
rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros ); |
#endif /* ! ENABLE_REWRITE */ |
#endif /* ! ENABLE_REWRITE */ |
if ( rc != LDAP_SUCCESS ) { |
if ( rc != LDAP_SUCCESS ) { |
text = "searchDN massage error"; |
text = "searchDN massage error"; |
Line 708 rwm_op_search( Operation *op, SlapReply
|
Line 832 rwm_op_search( Operation *op, SlapReply
|
goto error_return; |
goto error_return; |
} |
} |
|
|
if ( !BER_BVISNULL( &op->ors_filterstr ) ) { |
|
ch_free( op->ors_filterstr.bv_val ); |
|
} |
|
|
|
if( op->ors_filter ) { |
|
filter_free_x( op, op->ors_filter ); |
|
} |
|
|
|
op->ors_filter = f; |
op->ors_filter = f; |
op->ors_filterstr = fstr; |
op->ors_filterstr = fstr; |
|
|
Line 726 rwm_op_search( Operation *op, SlapReply
|
Line 842 rwm_op_search( Operation *op, SlapReply
|
goto error_return; |
goto error_return; |
} |
} |
|
|
cb = rwm_callback_get( op ); |
|
|
|
cb->sc_response = rwm_swap_attrs; |
|
cb->sc_cleanup = NULL; |
|
cb->sc_private = (void *)op->ors_attrs; |
|
cb->sc_next = op->o_callback; |
|
|
|
op->o_callback = cb; |
|
op->ors_attrs = an; |
op->ors_attrs = an; |
|
roc->cb.sc_response = rwm_swap_attrs; |
|
|
|
op->o_callback = &roc->cb; |
|
|
return SLAP_CB_CONTINUE; |
return SLAP_CB_CONTINUE; |
|
|
Line 751 error_return:;
|
Line 862 error_return:;
|
ch_free( fstr.bv_val ); |
ch_free( fstr.bv_val ); |
} |
} |
|
|
|
op->oq_search = roc->ros.oq_search; |
|
|
op->o_bd->bd_info = (BackendInfo *)on->on_info; |
op->o_bd->bd_info = (BackendInfo *)on->on_info; |
send_ldap_error( op, rs, rc, text ); |
send_ldap_error( op, rs, rc, text ); |
|
|
Line 759 error_return:;
|
Line 872 error_return:;
|
} |
} |
|
|
static int |
static int |
|
rwm_exop_passwd( Operation *op, SlapReply *rs ) |
|
{ |
|
slap_overinst *on = (slap_overinst *) op->o_bd->bd_info; |
|
int rc; |
|
rwm_op_cb *roc; |
|
|
|
struct berval id = BER_BVNULL, |
|
pwold = BER_BVNULL, |
|
pwnew = BER_BVNULL; |
|
BerElement *ber = NULL; |
|
|
|
if ( !BER_BVISNULL( &op->o_req_ndn ) ) { |
|
return LDAP_SUCCESS; |
|
} |
|
|
|
if ( !SLAP_ISGLOBALOVERLAY( op->o_bd ) ) { |
|
rs->sr_err = LDAP_OTHER; |
|
return rs->sr_err; |
|
} |
|
|
|
rs->sr_err = slap_passwd_parse( op->ore_reqdata, &id, |
|
&pwold, &pwnew, &rs->sr_text ); |
|
if ( rs->sr_err != LDAP_SUCCESS ) { |
|
return rs->sr_err; |
|
} |
|
|
|
if ( !BER_BVISNULL( &id ) ) { |
|
rs->sr_err = dnPrettyNormal( NULL, &id, &op->o_req_dn, |
|
&op->o_req_ndn, op->o_tmpmemctx ); |
|
if ( rs->sr_err != LDAP_SUCCESS ) { |
|
rs->sr_text = "Invalid DN"; |
|
return rs->sr_err; |
|
} |
|
|
|
} else { |
|
ber_dupbv_x( &op->o_req_dn, &op->o_dn, op->o_tmpmemctx ); |
|
ber_dupbv_x( &op->o_req_ndn, &op->o_ndn, op->o_tmpmemctx ); |
|
} |
|
|
|
roc = rwm_callback_get( op, rs ); |
|
|
|
#ifdef ENABLE_REWRITE |
|
rc = rwm_op_dn_massage( op, rs, "extendedDN", &roc->ros ); |
|
#else /* ! ENABLE_REWRITE */ |
|
rc = 1; |
|
rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros ); |
|
#endif /* ! ENABLE_REWRITE */ |
|
if ( rc != LDAP_SUCCESS ) { |
|
op->o_bd->bd_info = (BackendInfo *)on->on_info; |
|
send_ldap_error( op, rs, rc, "extendedDN massage error" ); |
|
return -1; |
|
} |
|
|
|
ber = ber_alloc_t( LBER_USE_DER ); |
|
if ( !ber ) { |
|
rs->sr_err = LDAP_OTHER; |
|
rs->sr_text = "No memory"; |
|
return rs->sr_err; |
|
} |
|
ber_printf( ber, "{" ); |
|
if ( !BER_BVISNULL( &id )) { |
|
ber_printf( ber, "tO", LDAP_TAG_EXOP_MODIFY_PASSWD_ID, |
|
&op->o_req_dn ); |
|
} |
|
if ( !BER_BVISNULL( &pwold )) { |
|
ber_printf( ber, "tO", LDAP_TAG_EXOP_MODIFY_PASSWD_OLD, &pwold ); |
|
} |
|
if ( !BER_BVISNULL( &pwnew )) { |
|
ber_printf( ber, "tO", LDAP_TAG_EXOP_MODIFY_PASSWD_NEW, &pwnew ); |
|
} |
|
ber_printf( ber, "N}" ); |
|
ber_flatten( ber, &op->ore_reqdata ); |
|
ber_free( ber, 1 ); |
|
|
|
op->o_callback = &roc->cb; |
|
|
|
return SLAP_CB_CONTINUE; |
|
} |
|
|
|
static struct exop { |
|
struct berval oid; |
|
BI_op_extended *extended; |
|
} exop_table[] = { |
|
{ BER_BVC(LDAP_EXOP_MODIFY_PASSWD), rwm_exop_passwd }, |
|
{ BER_BVNULL, NULL } |
|
}; |
|
|
|
static int |
rwm_extended( Operation *op, SlapReply *rs ) |
rwm_extended( Operation *op, SlapReply *rs ) |
{ |
{ |
slap_overinst *on = (slap_overinst *) op->o_bd->bd_info; |
slap_overinst *on = (slap_overinst *) op->o_bd->bd_info; |
int rc; |
int rc; |
|
rwm_op_cb *roc; |
|
|
|
int i; |
|
|
|
for ( i = 0; exop_table[i].extended != NULL; i++ ) { |
|
if ( bvmatch( &exop_table[i].oid, &op->oq_extended.rs_reqoid ) ) |
|
{ |
|
rc = exop_table[i].extended( op, rs ); |
|
switch ( rc ) { |
|
case LDAP_SUCCESS: |
|
break; |
|
|
|
case SLAP_CB_CONTINUE: |
|
case SLAPD_ABANDON: |
|
return rc; |
|
|
|
default: |
|
send_ldap_result( op, rs ); |
|
return rc; |
|
} |
|
break; |
|
} |
|
} |
|
|
|
roc = rwm_callback_get( op, rs ); |
|
|
#ifdef ENABLE_REWRITE |
#ifdef ENABLE_REWRITE |
rc = rwm_op_dn_massage( op, rs, "extendedDN" ); |
rc = rwm_op_dn_massage( op, rs, "extendedDN", &roc->ros ); |
#else /* ! ENABLE_REWRITE */ |
#else /* ! ENABLE_REWRITE */ |
rc = 1; |
rc = 1; |
rc = rwm_op_dn_massage( op, rs, &rc ); |
rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros ); |
#endif /* ! ENABLE_REWRITE */ |
#endif /* ! ENABLE_REWRITE */ |
if ( rc != LDAP_SUCCESS ) { |
if ( rc != LDAP_SUCCESS ) { |
op->o_bd->bd_info = (BackendInfo *)on->on_info; |
op->o_bd->bd_info = (BackendInfo *)on->on_info; |
Line 777 rwm_extended( Operation *op, SlapReply *
|
Line 1003 rwm_extended( Operation *op, SlapReply *
|
} |
} |
|
|
/* TODO: rewrite/map extended data ? ... */ |
/* TODO: rewrite/map extended data ? ... */ |
|
op->o_callback = &roc->cb; |
|
|
return SLAP_CB_CONTINUE; |
return SLAP_CB_CONTINUE; |
} |
} |
|
|
Line 1150 rwm_chk_referrals( Operation *op, SlapRe
|
Line 1378 rwm_chk_referrals( Operation *op, SlapRe
|
|
|
static int |
static int |
rwm_rw_config( |
rwm_rw_config( |
BackendDB *be, |
BackendDB *be, |
const char *fname, |
const char *fname, |
int lineno, |
int lineno, |
int argc, |
int argc, |
char **argv |
char **argv ) |
) |
|
{ |
{ |
#ifdef ENABLE_REWRITE |
#ifdef ENABLE_REWRITE |
slap_overinst *on = (slap_overinst *) be->bd_info; |
slap_overinst *on = (slap_overinst *) be->bd_info; |
Line 1175 rwm_rw_config(
|
Line 1402 rwm_rw_config(
|
|
|
static int |
static int |
rwm_suffixmassage_config( |
rwm_suffixmassage_config( |
BackendDB *be, |
BackendDB *be, |
const char *fname, |
const char *fname, |
int lineno, |
int lineno, |
int argc, |
int argc, |
char **argv |
char **argv ) |
) |
|
{ |
{ |
slap_overinst *on = (slap_overinst *) be->bd_info; |
slap_overinst *on = (slap_overinst *) be->bd_info; |
struct ldaprwmap *rwmap = |
struct ldaprwmap *rwmap = |
Line 1269 rwm_suffixmassage_config(
|
Line 1495 rwm_suffixmassage_config(
|
|
|
static int |
static int |
rwm_m_config( |
rwm_m_config( |
BackendDB *be, |
BackendDB *be, |
const char *fname, |
const char *fname, |
int lineno, |
int lineno, |
int argc, |
int argc, |
char **argv |
char **argv ) |
) |
|
{ |
{ |
slap_overinst *on = (slap_overinst *) be->bd_info; |
slap_overinst *on = (slap_overinst *) be->bd_info; |
struct ldaprwmap *rwmap = |
struct ldaprwmap *rwmap = |
Line 1301 rwm_response( Operation *op, SlapReply *
|
Line 1526 rwm_response( Operation *op, SlapReply *
|
|
|
switch( op->o_tag ) { |
switch( op->o_tag ) { |
case LDAP_REQ_SEARCH: |
case LDAP_REQ_SEARCH: |
/* Note: the operation attrs are remapped */ |
|
if ( rs->sr_type == REP_RESULT |
|
&& op->ors_attrs != NULL |
|
&& op->ors_attrs != rs->sr_attrs ) |
|
{ |
|
ch_free( op->ors_attrs ); |
|
op->ors_attrs = rs->sr_attrs; |
|
} |
|
/* fall thru */ |
|
|
|
case LDAP_REQ_BIND: |
case LDAP_REQ_BIND: |
case LDAP_REQ_ADD: |
case LDAP_REQ_ADD: |
case LDAP_REQ_DELETE: |
case LDAP_REQ_DELETE: |
Line 1352 rwm_response( Operation *op, SlapReply *
|
Line 1567 rwm_response( Operation *op, SlapReply *
|
|
|
static int |
static int |
rwm_db_config( |
rwm_db_config( |
BackendDB *be, |
BackendDB *be, |
const char *fname, |
const char *fname, |
int lineno, |
int lineno, |
int argc, |
int argc, |
char **argv |
char **argv ) |
) |
|
{ |
{ |
slap_overinst *on = (slap_overinst *) be->bd_info; |
slap_overinst *on = (slap_overinst *) be->bd_info; |
struct ldaprwmap *rwmap = |
struct ldaprwmap *rwmap = |
Line 1425 rwm_db_config(
|
Line 1639 rwm_db_config(
|
|
|
static int |
static int |
rwm_db_init( |
rwm_db_init( |
BackendDB *be |
BackendDB *be ) |
) |
|
{ |
{ |
slap_overinst *on = (slap_overinst *) be->bd_info; |
slap_overinst *on = (slap_overinst *) be->bd_info; |
struct ldapmapping *mapping = NULL; |
struct ldapmapping *mapping = NULL; |
Line 1434 rwm_db_init(
|
Line 1647 rwm_db_init(
|
#ifdef ENABLE_REWRITE |
#ifdef ENABLE_REWRITE |
char *rargv[ 3 ]; |
char *rargv[ 3 ]; |
#endif /* ENABLE_REWRITE */ |
#endif /* ENABLE_REWRITE */ |
|
int rc = 0; |
|
|
rwmap = (struct ldaprwmap *)ch_calloc( 1, sizeof( struct ldaprwmap ) ); |
rwmap = (struct ldaprwmap *)ch_calloc( 1, sizeof( struct ldaprwmap ) ); |
|
|
#ifdef ENABLE_REWRITE |
#ifdef ENABLE_REWRITE |
rwmap->rwm_rw = rewrite_info_init( REWRITE_MODE_USE_DEFAULT ); |
rwmap->rwm_rw = rewrite_info_init( REWRITE_MODE_USE_DEFAULT ); |
if ( rwmap->rwm_rw == NULL ) { |
if ( rwmap->rwm_rw == NULL ) { |
ch_free( rwmap ); |
rc = -1; |
return -1; |
goto error_return; |
} |
} |
|
|
/* this rewriteContext by default must be null; |
/* this rewriteContext by default must be null; |
Line 1460 rwm_db_init(
|
Line 1674 rwm_db_init(
|
if ( rwm_map_init( &rwmap->rwm_oc, &mapping ) != LDAP_SUCCESS || |
if ( rwm_map_init( &rwmap->rwm_oc, &mapping ) != LDAP_SUCCESS || |
rwm_map_init( &rwmap->rwm_at, &mapping ) != LDAP_SUCCESS ) |
rwm_map_init( &rwmap->rwm_at, &mapping ) != LDAP_SUCCESS ) |
{ |
{ |
return 1; |
rc = 1; |
|
goto error_return; |
} |
} |
|
|
|
error_return:; |
on->on_bi.bi_private = (void *)rwmap; |
on->on_bi.bi_private = (void *)rwmap; |
|
|
return 0; |
if ( rc ) { |
|
(void)rwm_db_destroy( be ); |
|
} |
|
|
|
return rc; |
} |
} |
|
|
static int |
static int |
rwm_db_destroy( |
rwm_db_destroy( |
BackendDB *be |
BackendDB *be ) |
) |
|
{ |
{ |
slap_overinst *on = (slap_overinst *) be->bd_info; |
slap_overinst *on = (slap_overinst *) be->bd_info; |
int rc = 0; |
int rc = 0; |
Line 1503 rwm_db_destroy(
|
Line 1722 rwm_db_destroy(
|
|
|
static slap_overinst rwm = { { NULL } }; |
static slap_overinst rwm = { { NULL } }; |
|
|
|
#if SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC |
|
static |
|
#endif /* SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC */ |
int |
int |
rwm_initialize(void) |
rwm_initialize( void ) |
{ |
{ |
memset( &rwm, 0, sizeof( slap_overinst ) ); |
memset( &rwm, 0, sizeof( slap_overinst ) ); |
|
|