]> git.sur5r.net Git - openldap/commitdiff
add "searchFilterAttrDN" rewrite context, and allow filterstring rewrite
authorPierangelo Masarati <ando@openldap.org>
Wed, 10 Mar 2004 21:41:02 +0000 (21:41 +0000)
committerPierangelo Masarati <ando@openldap.org>
Wed, 10 Mar 2004 21:41:02 +0000 (21:41 +0000)
servers/slapd/overlays/rwm.c
servers/slapd/overlays/rwmconf.c
servers/slapd/overlays/rwmdn.c
servers/slapd/overlays/rwmmap.c

index 162695c929908c5932888a854d382a5a33c805f5..2901f6b1337199e327ceb0d20b59c73e9edbcbed 100644 (file)
@@ -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;
index d225483bfec3ba23f4ba0acd02b6ce416eafb877..4bc782e88c7daf78ef120d44aafc2752a4274718 100644 (file)
@@ -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, "<suffix massage>", ++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, "<suffix massage>", ++line, 4, rargv );
 
        rargv[ 0 ] = "rewriteContext";
        rargv[ 1 ] = "searchAttrDN";
        rargv[ 2 ] = "alias";
-       rargv[ 3 ] = "searchResultDN";
+       rargv[ 3 ] = "searchResult";
        rargv[ 4 ] = NULL;
        rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
 
index bd9595a77204849bdf1b167aa5b8ed9df6f74cf5..e45ffff18e810c677fb7c2aa469e0cfe9cc3d98e 100644 (file)
@@ -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;
 }
 
index 5ecb959f1d827606646bbab46131ffbb5a02e655..c1f1d49d356263bc568d9dad1fcfff1d5cab1c0f 100644 (file)
@@ -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