From c5078085249b5b4ae8f5fbdd18fd9c9c67e1da37 Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Wed, 10 Mar 2004 21:41:02 +0000 Subject: [PATCH] add "searchFilterAttrDN" rewrite context, and allow filterstring rewrite --- servers/slapd/overlays/rwm.c | 4 +- servers/slapd/overlays/rwmconf.c | 6 +-- servers/slapd/overlays/rwmdn.c | 15 ++++--- servers/slapd/overlays/rwmmap.c | 75 ++++++++++++++++++++++++++++++-- 4 files changed, 85 insertions(+), 15 deletions(-) diff --git a/servers/slapd/overlays/rwm.c b/servers/slapd/overlays/rwm.c index 162695c929..2901f6b133 100644 --- a/servers/slapd/overlays/rwm.c +++ b/servers/slapd/overlays/rwm.c @@ -376,7 +376,7 @@ rwm_matched( Operation *op, SlapReply *rs ) #ifdef ENABLE_REWRITE dc.conn = op->o_conn; dc.rs = rs; - dc.ctx = "matchedDn"; + dc.ctx = "matchedDN"; #else dc.tofrom = 0; dc.normalized = 0; @@ -419,7 +419,7 @@ rwm_send_entry( Operation *op, SlapReply *rs ) #ifdef ENABLE_REWRITE dc.conn = op->o_conn; dc.rs = NULL; - dc.ctx = "searchResultDN"; + dc.ctx = "searchResult"; #else dc.tofrom = 0; dc.normalized = 0; diff --git a/servers/slapd/overlays/rwmconf.c b/servers/slapd/overlays/rwmconf.c index d225483bfe..4bc782e88c 100644 --- a/servers/slapd/overlays/rwmconf.c +++ b/servers/slapd/overlays/rwmconf.c @@ -304,7 +304,7 @@ rwm_suffix_massage_config( ch_free( rargv[ 2 ] ); rargv[ 0 ] = "rewriteContext"; - rargv[ 1 ] = "searchResultDN"; + rargv[ 1 ] = "searchResult"; rargv[ 2 ] = NULL; rewrite_parse( info, "", ++line, 2, rargv ); @@ -320,14 +320,14 @@ rwm_suffix_massage_config( rargv[ 0 ] = "rewriteContext"; rargv[ 1 ] = "matchedDN"; rargv[ 2 ] = "alias"; - rargv[ 3 ] = "searchResultDN"; + rargv[ 3 ] = "searchResult"; rargv[ 4 ] = NULL; rewrite_parse( info, "", ++line, 4, rargv ); rargv[ 0 ] = "rewriteContext"; rargv[ 1 ] = "searchAttrDN"; rargv[ 2 ] = "alias"; - rargv[ 3 ] = "searchResultDN"; + rargv[ 3 ] = "searchResult"; rargv[ 4 ] = NULL; rewrite_parse( info, "", ++line, 4, rargv ); diff --git a/servers/slapd/overlays/rwmdn.c b/servers/slapd/overlays/rwmdn.c index bd9595a772..e45ffff18e 100644 --- a/servers/slapd/overlays/rwmdn.c +++ b/servers/slapd/overlays/rwmdn.c @@ -46,10 +46,10 @@ rwm_dn_massage( { int rc = 0; - switch ( rewrite_session( dc->rwmap->rwm_rw, dc->ctx, - (dn->bv_len ? dn->bv_val : ""), - dc->conn, &res->bv_val ) ) - { + rc = rewrite_session( dc->rwmap->rwm_rw, dc->ctx, + ( dn->bv_len ? dn->bv_val : "" ), + dc->conn, &res->bv_val ); + switch ( rc ) { case REWRITE_REGEXEC_OK: if ( res->bv_val != NULL ) { res->bv_len = strlen( res->bv_val ); @@ -58,10 +58,12 @@ rwm_dn_massage( } #ifdef NEW_LOGGING LDAP_LOG( BACK_LDAP, DETAIL1, - "[rw] %s: \"%s\" -> \"%s\"\n", dc->ctx, dn->bv_val, res->bv_val ); + "[rw] %s: \"%s\" -> \"%s\"\n", + dc->ctx, dn->bv_val, res->bv_val ); #else /* !NEW_LOGGING */ Debug( LDAP_DEBUG_ARGS, - "[rw] %s: \"%s\" -> \"%s\"\n", dc->ctx, dn->bv_val, res->bv_val ); + "[rw] %s: \"%s\" -> \"%s\"\n", + dc->ctx, dn->bv_val, res->bv_val ); #endif /* !NEW_LOGGING */ rc = LDAP_SUCCESS; break; @@ -82,6 +84,7 @@ rwm_dn_massage( rc = LDAP_OTHER; break; } + return rc; } diff --git a/servers/slapd/overlays/rwmmap.c b/servers/slapd/overlays/rwmmap.c index 5ecb959f1d..c1f1d49d35 100644 --- a/servers/slapd/overlays/rwmmap.c +++ b/servers/slapd/overlays/rwmmap.c @@ -198,7 +198,7 @@ map_attr_value( dncookie fdc = *dc; #ifdef ENABLE_REWRITE - fdc.ctx = "searchFilter"; + fdc.ctx = "searchFilterAttrDN"; #endif switch ( rwm_dn_massage( &fdc, value, &vtmp ) ) { @@ -236,8 +236,8 @@ map_attr_value( return 0; } -int -rwm_filter_map_rewrite( +static int +rwm_int_filter_map_rewrite( dncookie *dc, Filter *f, struct berval *fstr, @@ -420,7 +420,7 @@ rwm_filter_map_rewrite( for ( p = f->f_list; p != NULL; p = p->f_next ) { len = fstr->bv_len; - if ( rwm_filter_map_rewrite( dc, p, &vtmp, remap ) ) + if ( rwm_int_filter_map_rewrite( dc, p, &vtmp, remap ) ) { return -1; } @@ -497,6 +497,73 @@ rwm_filter_map_rewrite( return 0; } +int +rwm_filter_map_rewrite( + dncookie *dc, + Filter *f, + struct berval *fstr, + int remap ) +{ + int rc; + dncookie fdc; + struct berval ftmp; + + rc = rwm_int_filter_map_rewrite( dc, f, fstr, remap ); + +#ifdef ENABLE_REWRITE + if ( rc != LDAP_SUCCESS ) { + return rc; + } + + fdc = *dc; + ftmp = *fstr; + + fdc.ctx = "searchFilter"; + + switch ( rewrite_session( fdc.rwmap->rwm_rw, fdc.ctx, + ( ftmp.bv_len ? ftmp.bv_val : "" ), + fdc.conn, &fstr->bv_val )) { + case REWRITE_REGEXEC_OK: + if ( fstr->bv_val != NULL ) { + fstr->bv_len = strlen( fstr->bv_val ); + free( ftmp.bv_val ); + } else { + *fstr = ftmp; + } + +#ifdef NEW_LOGGING + LDAP_LOG( BACK_LDAP, DETAIL1, + "[rw] %s: \"%s\" -> \"%s\"\n", + dc->ctx, ftmp.bv_val, fstr->bv_val ); +#else /* !NEW_LOGGING */ + Debug( LDAP_DEBUG_ARGS, + "[rw] %s: \"%s\" -> \"%s\"\n", + dc->ctx, ftmp.bv_val, fstr->bv_val ); +#endif /* !NEW_LOGGING */ + rc = LDAP_SUCCESS; + break; + + case REWRITE_REGEXEC_UNWILLING: + if ( fdc.rs ) { + fdc.rs->sr_err = LDAP_UNWILLING_TO_PERFORM; + fdc.rs->sr_text = "Operation not allowed"; + } + rc = LDAP_UNWILLING_TO_PERFORM; + break; + + case REWRITE_REGEXEC_ERR: + if ( fdc.rs ) { + fdc.rs->sr_err = LDAP_OTHER; + fdc.rs->sr_text = "Rewrite error"; + } + rc = LDAP_OTHER; + break; + } + +#endif /* ENABLE_REWRITE */ + return rc; +} + /* * I don't like this much, but we need two different * functions because different heap managers may be -- 2.39.5