]> git.sur5r.net Git - openldap/commitdiff
first cut at grouping rewrite/map stuff; needs work
authorPierangelo Masarati <ando@openldap.org>
Mon, 7 Apr 2003 17:04:14 +0000 (17:04 +0000)
committerPierangelo Masarati <ando@openldap.org>
Mon, 7 Apr 2003 17:04:14 +0000 (17:04 +0000)
12 files changed:
servers/slapd/back-meta/add.c
servers/slapd/back-meta/back-meta.h
servers/slapd/back-meta/bind.c
servers/slapd/back-meta/compare.c
servers/slapd/back-meta/config.c
servers/slapd/back-meta/conn.c
servers/slapd/back-meta/delete.c
servers/slapd/back-meta/init.c
servers/slapd/back-meta/modify.c
servers/slapd/back-meta/modrdn.c
servers/slapd/back-meta/search.c
servers/slapd/back-meta/unbind.c

index 2cf5cb4961baefdbed60ea2fd974b51914f35b0e..3b751c8f980fad281b491c4d2ac14529c563419d 100644 (file)
@@ -85,6 +85,7 @@ meta_back_add( Operation *op, SlapReply *rs )
        Attribute *a;
        LDAPMod **attrs;
        struct berval mdn = { 0, NULL }, mapped;
+       dncookie dc;
 
 #ifdef NEW_LOGGING
        LDAP_LOG( BACK_META, ENTRY, "meta_back_add: %s\n",
@@ -113,36 +114,13 @@ meta_back_add( Operation *op, SlapReply *rs )
        /*
         * Rewrite the add dn, if needed
         */
-       switch ( rewrite_session( li->targets[ candidate ]->rwinfo,
-                               "addDn", op->o_req_dn.bv_val, op->o_conn,
-                               &mdn.bv_val ) ) {
-       case REWRITE_REGEXEC_OK:
-               if ( mdn.bv_val != NULL && mdn.bv_val[ 0 ] != '\0' ) {
-                       mdn.bv_len = strlen( mdn.bv_val );
-               } else {
-                       mdn = op->o_req_dn;
-               }
+       dc.rwmap = &li->targets[ candidate ]->rwmap;
+       dc.conn = op->o_conn;
+       dc.rs = rs;
+       dc.ctx = "addDn";
 
-#ifdef NEW_LOGGING
-               LDAP_LOG( BACK_META, DETAIL1,
-                               "[rw] addDn: \"%s\" -> \"%s\"\n",
-                               op->o_req_dn.bv_val, mdn.bv_val, 0 );
-#else /* !NEW_LOGGING */
-               Debug( LDAP_DEBUG_ARGS, "rw> addDn: \"%s\" -> \"%s\"\n", 
-                               op->o_req_dn.bv_val, mdn.bv_val, 0 );
-#endif /* !NEW_LOGGING */
-               break;
-               
-       case REWRITE_REGEXEC_UNWILLING:
-               rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
-               rs->sr_text = "Operation not allowed";
-               send_ldap_result( op, rs );
-               return -1;
-               
-       case REWRITE_REGEXEC_ERR:
-               rs->sr_err = LDAP_OTHER;
-               rs->sr_text = "Rewrite error";
-               send_ldap_result( op, rs );
+       if ( ldap_back_dn_massage( &dc, &op->o_req_dn, &mdn ) ) {
+               send_ldap_result( op, rs );
                return -1;
        }
 
@@ -159,7 +137,7 @@ meta_back_add( Operation *op, SlapReply *rs )
                        continue;
                }
 
-               ldap_back_map( &li->targets[ candidate ]->at_map,
+               ldap_back_map( &li->targets[ candidate ]->rwmap.rwm_at,
                                &a->a_desc->ad_cname, &mapped, BACKLDAP_MAP );
                if ( mapped.bv_val == NULL || mapped.bv_val[0] == '\0' ) {
                        continue;
@@ -179,8 +157,7 @@ meta_back_add( Operation *op, SlapReply *rs )
                 */
                if ( strcmp( a->a_desc->ad_type->sat_syntax->ssyn_oid,
                                        SLAPD_DN_SYNTAX ) == 0 ) {
-                       ldap_dnattr_rewrite( li->targets[ candidate ]->rwinfo,
-                                       a->a_vals, op->o_conn );
+                       (void)ldap_dnattr_rewrite( &dc, a->a_vals );
                }
 
                for ( j = 0; a->a_vals[ j ].bv_val; j++ );
index d7d2f8592053d6323611b050e03c1b45e39df757..463fc5a7c138b55f4cc5fab58ecb9e4124a4e2ff 100644 (file)
@@ -125,10 +125,13 @@ struct metatarget {
        struct berval           pseudorootdn;
        struct berval           pseudorootpw;
 
+#if 0
        struct rewrite_info     *rwinfo;
 
        struct ldapmap          oc_map;
        struct ldapmap          at_map;
+#endif
+       struct ldaprwmap        rwmap;
 };
 
 struct metadncache {
index d990ffb98f944ee8cab2016fb65a5a0d070a5895..84cd524a64d5099c7db1b1cf716a57e8ee8a67a2 100644 (file)
@@ -236,35 +236,19 @@ meta_back_do_single_bind(
        struct metainfo *li = ( struct metainfo * )op->o_bd->be_private;
        struct berval   mdn = { 0, NULL };
        ber_int_t       msgid;
+       dncookie        dc;
        
        /*
         * Rewrite the bind dn if needed
         */
-       switch ( rewrite_session( li->targets[ candidate ]->rwinfo,
-                               "bindDn", op->o_req_dn.bv_val,
-                               lc->conn, &mdn.bv_val ) ) {
-       case REWRITE_REGEXEC_OK:
-               if ( mdn.bv_val == NULL ) {
-                       mdn = op->o_req_dn;
-               } else {
-                       mdn.bv_len = strlen( mdn.bv_val );
-               }
-#ifdef NEW_LOGGING
-               LDAP_LOG( BACK_META, DETAIL1,
-                               "[rw] bindDn: \"%s\" -> \"%s\"\n",
-                               op->o_req_dn.bv_val, mdn.bv_val, 0 );
-#else /* !NEW_LOGGING */
-               Debug( LDAP_DEBUG_ARGS,
-                               "rw> bindDn: \"%s\" -> \"%s\"\n%s",
-                               op->o_req_dn.bv_val, mdn.bv_val, "" );
-#endif /* !NEW_LOGGING */
-               break;
-               
-       case REWRITE_REGEXEC_UNWILLING:
-               return LDAP_UNWILLING_TO_PERFORM;
+       dc.rwmap = &li->targets[ candidate ]->rwmap;
+       dc.conn = op->o_conn;
+       dc.rs = rs;
+       dc.ctx = "bindDn";
 
-       case REWRITE_REGEXEC_ERR:
-               return LDAP_OTHER;
+       if ( ldap_back_dn_massage( &dc, &op->o_req_dn, &mdn ) ) {
+               send_ldap_result( op, rs );
+               return -1;
        }
 
        if ( op->o_ctrls ) {
index d272ab42dc20838b5bc06054333def8238246651..6633d1ddc1c6e11fd6ccae5dc0bc856365342374 100644 (file)
@@ -81,10 +81,12 @@ meta_back_compare( Operation *op, SlapReply *rs )
        struct metainfo *li = ( struct metainfo * )op->o_bd->be_private;
        struct metaconn *lc;
        struct metasingleconn *lsc;
-       char *match = NULL, *err = NULL, *mmatch = NULL;
+       char *match = NULL, *err = NULL;
+       struct berval mmatch = { 0, NULL };
        int candidates = 0, last = 0, i, count, rc;
                int cres = LDAP_SUCCESS, rres = LDAP_SUCCESS;
        int *msgid;
+       dncookie dc;
 
        lc = meta_back_getconn( op, rs, META_OP_ALLOW_MULTIPLE,
                        &op->o_req_ndn, NULL );
@@ -107,8 +109,12 @@ meta_back_compare( Operation *op, SlapReply *rs )
        /*
         * start an asynchronous compare for each candidate target
         */
+       dc.conn = op->o_conn;
+       dc.rs = rs;
+       dc.ctx = "compareDn";
+
        for ( i = 0, lsc = lc->conns; !META_LAST(lsc); ++i, ++lsc ) {
-               char *mdn = NULL;
+               struct berval mdn = { 0, NULL };
                struct berval mapped_attr = op->oq_compare.rs_ava->aa_desc->ad_cname;
                struct berval mapped_value = op->oq_compare.rs_ava->aa_value;
 
@@ -120,42 +126,22 @@ meta_back_compare( Operation *op, SlapReply *rs )
                /*
                 * Rewrite the compare dn, if needed
                 */
-               switch ( rewrite_session( li->targets[ i ]->rwinfo,
-                                       "compareDn", 
-                                       op->o_req_dn.bv_val, op->o_conn, &mdn ) ) {
-               case REWRITE_REGEXEC_OK:
-                       if ( mdn == NULL ) {
-                               mdn = ( char * )op->o_req_dn.bv_val;
-                       }
-#ifdef NEW_LOGGING
-                       LDAP_LOG( BACK_META, DETAIL1,
-                               "[rw] compareDn: \"%s\" -> \"%s\"\n",
-                               op->o_req_dn.bv_val, mdn, 0 );
-#else /* !NEW_LOGGING */
-                       Debug( LDAP_DEBUG_ARGS,
-                                       "rw> compareDn: \"%s\" -> \"%s\"\n",
-                                       op->o_req_dn.bv_val, mdn, 0 );
-#endif /* !NEW_LOGGING */
+               dc.rwmap = &li->targets[ i ]->rwmap;
+
+               switch ( ldap_back_dn_massage( &dc, &op->o_req_dn, &mdn ) ) {
+               case LDAP_UNWILLING_TO_PERFORM:
+                       rc = 1;
+                       goto finish;
+
+               default:
                        break;
-               
-               case REWRITE_REGEXEC_UNWILLING:
-                       rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
-                       rs->sr_text = "Operation not allowed";
-                       send_ldap_result( op, rs );
-                       return -1;
-                       
-               case REWRITE_REGEXEC_ERR:
-                       rs->sr_err = LDAP_OTHER;
-                       rs->sr_text = "Rewrite error";
-                       send_ldap_result( op, rs );
-                       return -1;
                }
 
                /*
                 * if attr is objectClass, try to remap the value
                 */
                if ( op->oq_compare.rs_ava->aa_desc == slap_schema.si_ad_objectClass ) {
-                       ldap_back_map( &li->targets[ i ]->oc_map,
+                       ldap_back_map( &li->targets[ i ]->rwmap.rwm_oc,
                                        &op->oq_compare.rs_ava->aa_value,
                                        &mapped_value, BACKLDAP_MAP );
 
@@ -166,7 +152,7 @@ meta_back_compare( Operation *op, SlapReply *rs )
                 * else try to remap the attribute
                 */
                } else {
-                       ldap_back_map( &li->targets[ i ]->at_map,
+                       ldap_back_map( &li->targets[ i ]->rwmap.rwm_at,
                                &op->oq_compare.rs_ava->aa_desc->ad_cname,
                                &mapped_attr, BACKLDAP_MAP );
                        if ( mapped_attr.bv_val == NULL || mapped_attr.bv_val[0] == '\0' ) {
@@ -179,10 +165,11 @@ meta_back_compare( Operation *op, SlapReply *rs )
                 * that returns determines the result; a constraint on unicity
                 * of the result ought to be enforced
                 */
-               msgid[ i ] = ldap_compare( lc->conns[ i ].ld, mdn,
+               msgid[ i ] = ldap_compare( lc->conns[ i ].ld, mdn.bv_val,
                                mapped_attr.bv_val, mapped_value.bv_val );
-               if ( mdn != op->o_req_dn.bv_val ) {
-                       free( mdn );
+               if ( mdn.bv_val != op->o_req_dn.bv_val ) {
+                       free( mdn.bv_val );
+                       mdn.bv_val = NULL;
                }
                if ( mapped_attr.bv_val != op->oq_compare.rs_ava->aa_desc->ad_cname.bv_val ) {
                        free( mapped_attr.bv_val );
@@ -301,56 +288,28 @@ finish:;
                 */
                rres = cres;
                
-       } else if ( match != NULL ) {
-               
                /*
                 * At least one compare failed with matched portion,
                 * and none was successful
                 */
-               switch ( rewrite_session( li->targets[ last ]->rwinfo,
-                                       "matchedDn", match, op->o_conn,
-                                       &mmatch ) ) {
-               case REWRITE_REGEXEC_OK:
-                       if ( mmatch == NULL ) {
-                               mmatch = ( char * )match;
-                       }
-#ifdef NEW_LOGGING
-                       LDAP_LOG( BACK_META, DETAIL1,
-                                       "[rw] matchedDn: \"%s\" -> \"%s\"\n",
-                                       match, mmatch, 0 );
-#else /* !NEW_LOGGING */
-                       Debug( LDAP_DEBUG_ARGS, "rw> matchedDn:"
-                                       " \"%s\" -> \"%s\"\n",
-                                       match, mmatch, 0 );
-#endif /* !NEW_LOGGING */
-                       break;
-                       
-               
-               case REWRITE_REGEXEC_UNWILLING:
-                       rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
-                       rs->sr_text = "Operation not allowed";
-                       send_ldap_result( op, rs );
-                       rc = -1;
-                       goto cleanup;
-                       
-               case REWRITE_REGEXEC_ERR:
-                       rs->sr_err = LDAP_OTHER;
-                       rs->sr_text = "Rewrite error";
-                       send_ldap_result( op, rs );
-                       rc = -1;
-                       goto cleanup;
-               }
+       } else if ( match != NULL &&  match[0] != '\0' ) {
+               struct berval matched;
+
+               matched.bv_val = match;
+               matched.bv_len = strlen( match );
+
+               dc.ctx = "matchedDn";
+               ldap_back_dn_massage( &dc, &matched, &mmatch );
        }
 
        rs->sr_err = rres;
-       rs->sr_matched = mmatch;
+       rs->sr_matched = mmatch.bv_val;
        send_ldap_result( op, rs );
        rs->sr_matched = NULL;
 
-cleanup:;
        if ( match != NULL ) {
-               if ( mmatch != match ) {
-                       free( mmatch );
+               if ( mmatch.bv_val != match ) {
+                       free( mmatch.bv_val );
                }
                free( match );
        }
index f8d3fc5d30a62ca0ef064f2bbe430045a99ed9e0..73654fb40a838a0aa4fcec90a324be247e9d8fa4 100644 (file)
@@ -88,13 +88,13 @@ new_target( void )
                return NULL;
        }
 
-       lt->rwinfo = rewrite_info_init( REWRITE_MODE_USE_DEFAULT );
-       if ( lt->rwinfo == NULL ) {
+       lt->rwmap.rwm_rw = rewrite_info_init( REWRITE_MODE_USE_DEFAULT );
+       if ( lt->rwmap.rwm_rw == NULL ) {
                free( lt );
                 return NULL;
        }
 
-       ldap_back_map_init( &lt->at_map, &mapping );
+       ldap_back_map_init( &lt->rwmap.rwm_at, &mapping );
 
        return lt;
 }
@@ -499,7 +499,7 @@ meta_back_db_config(
                 * FIXME: no extra rewrite capabilities should be added
                 * to the database
                 */
-               return suffix_massage_config( li->targets[ i ]->rwinfo,
+               return suffix_massage_config( li->targets[ i ]->rwmap.rwm_rw,
                                &pvnc, &nvnc, &prnc, &nrnc );
                
        /* rewrite stuff ... */
@@ -520,7 +520,7 @@ meta_back_db_config(
 #endif /* LDAP_CACHING */
                }
                
-               return rewrite_parse( li->targets[ i ]->rwinfo, fname, lineno,
+               return rewrite_parse( li->targets[ i ]->rwmap.rwm_rw, fname, lineno,
                                argc, argv );
 
        /* objectclass/attribute mapping */
@@ -534,8 +534,8 @@ meta_back_db_config(
                        return 1;
                }
 
-               return ldap_back_map_config( &li->targets[ i ]->oc_map
-                               &li->targets[ i ]->at_map,
+               return ldap_back_map_config( &li->targets[ i ]->rwmap.rwm_oc
+                               &li->targets[ i ]->rwmap.rwm_at,
                                fname, lineno, argc, argv );
        /* anything else */
        } else {
index 77e97225e31f010936414abe3d4e4d697f034720..ba4d50fc93c22d3b3e574a8868a07846a32f7ed9 100644 (file)
@@ -256,7 +256,7 @@ init_one_conn(
        /*
         * Sets a cookie for the rewrite session
         */
-       ( void )rewrite_session_init( lt->rwinfo, op->o_conn );
+       ( void )rewrite_session_init( lt->rwmap.rwm_rw, op->o_conn );
 
        /*
         * If the connection dn is not null, an attempt to rewrite it is made
@@ -267,7 +267,7 @@ init_one_conn(
                 * Rewrite the bind dn if needed
                 */
                lsc->bound_dn.bv_val = NULL;
-               switch ( rewrite_session( lt->rwinfo, "bindDn",
+               switch ( rewrite_session( lt->rwmap.rwm_rw, "bindDn",
                                        op->o_conn->c_dn.bv_val, op->o_conn, 
                                        &lsc->bound_dn.bv_val ) ) {
                case REWRITE_REGEXEC_OK:
index 4313bce7b92728e88b646c27c979f048eb92eef8..63d87a434da8d4fa59058a78fb2b56bf14b8a1e9 100644 (file)
@@ -81,8 +81,8 @@ meta_back_delete( Operation *op, SlapReply *rs )
        struct metainfo *li = ( struct metainfo * )op->o_bd->be_private;
        struct metaconn *lc;
        int candidate = -1;
-
-       char *mdn = NULL;
+       struct berval mdn = { 0, NULL };
+       dncookie dc;
 
        lc = meta_back_getconn( op, rs, META_OP_REQUIRE_SINGLE,
                        &op->o_req_ndn, &candidate );
@@ -101,40 +101,20 @@ meta_back_delete( Operation *op, SlapReply *rs )
        /*
         * Rewrite the compare dn, if needed
         */
-       switch ( rewrite_session( li->targets[ candidate ]->rwinfo,
-                               "deleteDn", op->o_req_dn.bv_val,
-                               op->o_conn, &mdn ) ) {
-       case REWRITE_REGEXEC_OK:
-               if ( mdn == NULL ) {
-                       mdn = ( char * )op->o_req_dn.bv_val;
-               }
-#ifdef NEW_LOGGING
-               LDAP_LOG( BACK_META, DETAIL1,
-                               "[rw] deleteDn: \"%s\" -> \"%s\"\n",
-                               op->o_req_dn.bv_val, mdn, 0 );
-#else /* !NEW_LOGGING */
-               Debug( LDAP_DEBUG_ARGS, "rw> deleteDn: \"%s\" -> \"%s\"\n",
-                               op->o_req_dn.bv_val, mdn, 0 );
-#endif /* !NEW_LOGGING */
-               break;
-               
-       case REWRITE_REGEXEC_UNWILLING:
-               rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
-               rs->sr_text = "Operation not allowed";
-               send_ldap_result( op, rs );
-               return -1;
+       dc.rwmap = &li->targets[ candidate ]->rwmap;
+       dc.conn = op->o_conn;
+       dc.rs = rs;
+       dc.ctx = "deleteDn";
 
-       case REWRITE_REGEXEC_ERR:
-               rs->sr_err = LDAP_OTHER;
-               rs->sr_text = "Rewrite error";
+       if ( ldap_back_dn_massage( &dc, &op->o_req_dn, &mdn ) ) {
                send_ldap_result( op, rs );
                return -1;
        }
-       
-       ldap_delete_s( lc->conns[ candidate ].ld, mdn );
 
-       if ( mdn != op->o_req_dn.bv_val ) {
-               free( mdn );
+       ldap_delete_s( lc->conns[ candidate ].ld, mdn.bv_val );
+
+       if ( mdn.bv_val != op->o_req_dn.bv_val ) {
+               free( mdn.bv_val );
        }
        
        return meta_back_op_result( lc, op, rs );
index 07612765c77c2c0d843ca61924dc30ec883b7430..b98d44cbab3a239affef28e6c57203663b0831bd 100644 (file)
@@ -257,13 +257,13 @@ target_free(
        if ( lt->pseudorootpw.bv_val ) {
                free( lt->pseudorootpw.bv_val );
        }
-       if ( lt->rwinfo ) {
-               rewrite_info_delete( lt->rwinfo );
+       if ( lt->rwmap.rwm_rw ) {
+               rewrite_info_delete( lt->rwmap.rwm_rw );
        }
-       avl_free( lt->oc_map.remap, NULL );
-       avl_free( lt->oc_map.map, mapping_free );
-       avl_free( lt->at_map.remap, NULL );
-       avl_free( lt->at_map.map, mapping_free );
+       avl_free( lt->rwmap.rwm_oc.remap, NULL );
+       avl_free( lt->rwmap.rwm_oc.map, mapping_free );
+       avl_free( lt->rwmap.rwm_at.remap, NULL );
+       avl_free( lt->rwmap.rwm_at.map, mapping_free );
 }
 
 int
index c6f801a24b1eec057e50163871cf271779943737..bfb1d5ca3e9e51d42597caa9bd67cc95586557a8 100644 (file)
@@ -85,8 +85,9 @@ meta_back_modify( Operation *op, SlapReply *rs )
        LDAPMod                 *mods = NULL;
        Modifications           *ml;
        int                     candidate = -1, i;
-       char                    *mdn;
+       struct berval           mdn = { 0, NULL };
        struct berval           mapped;
+       dncookie                dc;
 
        lc = meta_back_getconn( op, rs, META_OP_REQUIRE_SINGLE,
                        &op->o_req_ndn, &candidate );
@@ -105,32 +106,12 @@ meta_back_modify( Operation *op, SlapReply *rs )
        /*
         * Rewrite the modify dn, if needed
         */
-       switch ( rewrite_session( li->targets[ candidate ]->rwinfo,
-                               "modifyDn", op->o_req_dn.bv_val,
-                               op->o_conn, &mdn ) ) {
-       case REWRITE_REGEXEC_OK:
-               if ( mdn == NULL ) {
-                       mdn = ( char * )op->o_req_dn.bv_val;
-               }
-#ifdef NEW_LOGGING
-               LDAP_LOG( BACK_META, DETAIL1,
-                               "[rw] modifyDn: \"%s\" -> \"%s\"\n",
-                               op->o_req_dn.bv_val, mdn, 0 );
-#else /* !NEW_LOGGING */
-               Debug( LDAP_DEBUG_ARGS, "rw> modifyDn: \"%s\" -> \"%s\"\n",
-                               op->o_req_dn.bv_val, mdn, 0 );
-#endif /* !NEW_LOGGING */
-               break;
-               
-       case REWRITE_REGEXEC_UNWILLING:
-               rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
-               rs->sr_text = "Operation not allowed";
-               rc = -1;
-               goto cleanup;
+       dc.rwmap = &li->targets[ candidate ]->rwmap;
+       dc.conn = op->o_conn;
+       dc.rs = rs;
+       dc.ctx = "modifyDn";
 
-       case REWRITE_REGEXEC_ERR:
-               rs->sr_err = LDAP_OTHER;
-               rs->sr_text = "Rewrite error";
+       if ( ldap_back_dn_massage( &dc, &op->o_req_dn, &mdn ) ) {
                rc = -1;
                goto cleanup;
        }
@@ -151,6 +132,7 @@ meta_back_modify( Operation *op, SlapReply *rs )
                goto cleanup;
        }
 
+       dc.ctx = "modifyAttrDN";
        for ( i = 0, ml = op->oq_modify.rs_modlist; ml; ml = ml->sml_next ) {
                int j;
 
@@ -158,7 +140,7 @@ meta_back_modify( Operation *op, SlapReply *rs )
                        continue;
                }
 
-               ldap_back_map( &li->targets[ candidate ]->at_map,
+               ldap_back_map( &li->targets[ candidate ]->rwmap.rwm_at,
                                &ml->sml_desc->ad_cname, &mapped,
                                BACKLDAP_MAP );
                if ( mapped.bv_val == NULL || mapped.bv_val[0] == '\0' ) {
@@ -176,9 +158,7 @@ meta_back_modify( Operation *op, SlapReply *rs )
                 */
                if ( strcmp( ml->sml_desc->ad_type->sat_syntax->ssyn_oid,
                                        SLAPD_DN_SYNTAX ) == 0 ) {
-                       ldap_dnattr_rewrite(
-                               li->targets[ candidate ]->rwinfo,
-                               ml->sml_bvalues, op->o_conn );
+                       ( void )ldap_dnattr_rewrite( &dc, ml->sml_bvalues );
                }
 
                if ( ml->sml_bvalues != NULL ){
@@ -197,11 +177,11 @@ meta_back_modify( Operation *op, SlapReply *rs )
        }
        modv[ i ] = 0;
 
-       ldap_modify_s( lc->conns[ candidate ].ld, mdn, modv );
+       ldap_modify_s( lc->conns[ candidate ].ld, mdn.bv_val, modv );
 
 cleanup:;
-       if ( mdn != op->o_req_dn.bv_val ) {
-               free( mdn );
+       if ( mdn.bv_val != op->o_req_dn.bv_val ) {
+               free( mdn.bv_val );
        }
        if ( modv != NULL ) {
                for ( i = 0; modv[ i ]; i++) {
index 10fa1c5a183b80baec613ac45cbf7b813496653f..d7b3068ef2dcbca0d24f006e0307c2c9d85995f1 100644 (file)
@@ -141,7 +141,7 @@ meta_back_modrdn( Operation *op, SlapReply *rs )
                /*
                 * Rewrite the new superior, if defined and required
                 */
-               switch ( rewrite_session( li->targets[ nsCandidate ]->rwinfo,
+               switch ( rewrite_session( li->targets[ nsCandidate ]->rwmap.rwm_rw,
                                        "newSuperiorDn",
                                        op->oq_modrdn.rs_newSup->bv_val, 
                                        op->o_conn, 
@@ -179,7 +179,7 @@ meta_back_modrdn( Operation *op, SlapReply *rs )
        /*
         * Rewrite the modrdn dn, if required
         */
-       switch ( rewrite_session( li->targets[ candidate ]->rwinfo,
+       switch ( rewrite_session( li->targets[ candidate ]->rwmap.rwm_rw,
                                "modrDn", op->o_req_dn.bv_val,
                                op->o_conn, &mdn ) ) {
        case REWRITE_REGEXEC_OK:
index 60386ee4c98013392fae4dde00c8f00f17b83439..52f366feef3d2a39bb1a3bd07cdbfe5ede769c04 100644 (file)
@@ -111,6 +111,7 @@ meta_back_search( Operation *op, SlapReply *rs )
        int i, last = 0, candidates = 0;
        struct slap_limits_set *limit = NULL;
        int isroot = 0;
+       dncookie dc;
 
 #ifdef LDAP_CACHING
        cache_manager*  cm = li->cm;
@@ -205,15 +206,19 @@ meta_back_search( Operation *op, SlapReply *rs )
                /* negative hard limit means no limit */
        }
 
+
+       dc.conn = op->o_conn;
+       dc.rs = rs;
+
        /*
         * Inits searches
         */
        for ( i = 0, lsc = lc->conns; !META_LAST(lsc); ++i, ++lsc ) {
-               char            *realbase = ( char * )op->o_req_dn.bv_val;
+               struct berval   realbase = op->o_req_dn;
                int             realscope = op->oq_search.rs_scope;
                ber_len_t       suffixlen = 0;
-               char            *mbase = NULL
-               struct berval   mfilter = { 0L, NULL };
+               struct berval   mbase = { 0, NULL }
+               struct berval   mfilter = { 0, NULL };
                char            **mapped_attrs = NULL;
 
                if ( lsc->candidate != META_CANDIDATE ) {
@@ -235,6 +240,8 @@ meta_back_search( Operation *op, SlapReply *rs )
                                        ( void * )&op->oq_search.rs_slimit);
                }
 
+               dc.rwmap = &li->targets[ i ]->rwmap;
+
                /*
                 * modifies the base according to the scope, if required
                 */
@@ -250,7 +257,7 @@ meta_back_search( Operation *op, SlapReply *rs )
                                 */
                                if ( dnIsSuffix( &li->targets[ i ]->suffix,
                                                &op->o_req_ndn ) ) {
-                                       realbase = li->targets[ i ]->suffix.bv_val;
+                                       realbase = li->targets[ i ]->suffix;
                                } else {
                                        /*
                                         * this target is no longer candidate
@@ -269,7 +276,7 @@ meta_back_search( Operation *op, SlapReply *rs )
                                         * make the target suffix the new
                                         * base, and make scope "base"
                                         */
-                                       realbase = li->targets[ i ]->suffix.bv_val;
+                                       realbase = li->targets[ i ]->suffix;
                                        realscope = LDAP_SCOPE_BASE;
                                        break;
                                } /* else continue with the next case */
@@ -287,24 +294,11 @@ meta_back_search( Operation *op, SlapReply *rs )
                /*
                 * Rewrite the search base, if required
                 */
-               switch ( rewrite_session( li->targets[ i ]->rwinfo,
-                                       "searchBase",
-                                       realbase, op->o_conn, &mbase ) ) {
-               case REWRITE_REGEXEC_OK:
-               if ( mbase == NULL ) {
-                       mbase = realbase;
-               }
-#ifdef NEW_LOGGING
-               LDAP_LOG( BACK_META, DETAIL1,
-                       "[rw] searchBase [%d]: \"%s\" -> \"%s\"\n",
-                       i, op->o_req_dn.bv_val, mbase );
-#else /* !NEW_LOGGING */
-               Debug( LDAP_DEBUG_ARGS,
-                       "rw> searchBase [%d]: \"%s\" -> \"%s\"\n",
-                               i, op->o_req_dn.bv_val, mbase );
-#endif /* !NEW_LOGGING */
-               break;
-               
+               dc.ctx = "searchBase";
+               switch ( ldap_back_dn_massage( &dc, &realbase, &mbase ) ) {
+               default:
+                       break;
+
                case REWRITE_REGEXEC_UNWILLING:
                        rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
                        rs->sr_text = "Operation not allowed";
@@ -331,10 +325,7 @@ meta_back_search( Operation *op, SlapReply *rs )
                /*
                 * Maps filter
                 */
-               rc = ldap_back_filter_map_rewrite_( li->targets[ i ]->rwinfo,
-                               op->o_conn,
-                               &li->targets[ i ]->at_map,
-                               &li->targets[ i ]->oc_map, 
+               rc = ldap_back_filter_map_rewrite( &dc,
                                op->oq_search.rs_filter,
                                &mfilter, BACKLDAP_MAP );
                if ( rc != 0 ) {
@@ -348,7 +339,7 @@ meta_back_search( Operation *op, SlapReply *rs )
                /*
                 * Maps required attributes
                 */
-               rc = ldap_back_map_attrs( &li->targets[ i ]->at_map,
+               rc = ldap_back_map_attrs( &li->targets[ i ]->rwmap.rwm_at,
                                op->oq_search.rs_attrs, BACKLDAP_MAP,
                                &mapped_attrs );
                if ( rc != LDAP_SUCCESS ) {
@@ -359,22 +350,10 @@ meta_back_search( Operation *op, SlapReply *rs )
                        goto new_candidate;
                }
 
-#if 0
-               if ( mapped_attrs == NULL && op->oq_search.rs_attrs) {
-                       int     count;
-                       for ( count = 0; op->oq_search.rs_attrs[ count ].an_name.bv_val; count++ );
-                       mapped_attrs = ch_malloc( ( count + 1 ) * sizeof(char *));
-                       for ( count = 0; op->oq_search.rs_attrs[ count ].an_name.bv_val; count++ ) {
-                               mapped_attrs[ count ] = op->oq_search.rs_attrs[ count ].an_name.bv_val;
-                       }
-                       mapped_attrs[ count ] = NULL;
-               }
-#endif
-
                /*
                 * Starts the search
                 */
-               msgid[ i ] = ldap_search( lsc->ld, mbase, realscope,
+               msgid[ i ] = ldap_search( lsc->ld, mbase.bv_val, realscope,
                                mfilter.bv_val, mapped_attrs,
                                op->oq_search.rs_attrsonly ); 
                if ( mapped_attrs ) {
@@ -385,9 +364,9 @@ meta_back_search( Operation *op, SlapReply *rs )
                        free( mfilter.bv_val );
                        mfilter.bv_val = NULL;
                }
-               if ( mbase != realbase ) {
-                       free( mbase );
-                       mbase = NULL;
+               if ( mbase.bv_val != realbase.bv_val ) {
+                       free( mbase.bv_val );
+                       mbase.bv_val = NULL;
                }
 
                if ( msgid[ i ] == -1 ) {
@@ -592,7 +571,7 @@ new_candidate:;
         * FIXME: only the last one gets caught!
         */
        if ( match != NULL ) {
-               switch ( rewrite_session( li->targets[ last ]->rwinfo,
+               switch ( rewrite_session( li->targets[ last ]->rwmap.rwm_rw,
                                        "matchedDn", match, op->o_conn,
                                        &mmatch ) ) {
                case REWRITE_REGEXEC_OK:
@@ -673,6 +652,7 @@ meta_send_entry(
        struct berval           dummy = { 0, NULL };
        struct berval           *bv, bdn;
        const char              *text;
+       dncookie                dc;
 
        if ( ber_scanf( &ber, "{m{", &bdn ) == LBER_ERROR ) {
                return LDAP_DECODING_ERROR;
@@ -681,32 +661,14 @@ meta_send_entry(
        /*
         * Rewrite the dn of the result, if needed
         */
-       switch ( rewrite_session( li->targets[ target ]->rwinfo,
-                               "searchResult", bdn.bv_val, lc->conn,
-                               &ent.e_name.bv_val ) ) {
-       case REWRITE_REGEXEC_OK:
-               if ( ent.e_name.bv_val == NULL ) {
-                       ent.e_name = bdn;
-
-               } else {
-#ifdef NEW_LOGGING
-                       LDAP_LOG( BACK_META, DETAIL1,
-                               "[rw] searchResult[%d]: \"%s\" -> \"%s\"\n",
-                               target, bdn.bv_val, ent.e_name.bv_val );
-#else /* !NEW_LOGGING */
-                       Debug( LDAP_DEBUG_ARGS, "rw> searchResult[%d]: \"%s\""
-                                       " -> \"%s\"\n", target, bdn.bv_val,
-                                       ent.e_name.bv_val );
-#endif /* !NEW_LOGGING */
-                       ent.e_name.bv_len = strlen( ent.e_name.bv_val );
-               }
-               break;
-               
-       case REWRITE_REGEXEC_UNWILLING:
-               return LDAP_UNWILLING_TO_PERFORM;
-
-       case REWRITE_REGEXEC_ERR:
-               return LDAP_OTHER;
+       dc.rwmap = &li->targets[ target ]->rwmap;
+       dc.conn = op->o_conn;
+       dc.rs = rs;
+       dc.ctx = "searchResult";
+
+       rs->sr_err = ldap_back_dn_massage( &dc, &bdn, &ent.e_name );
+       if ( rs->sr_err != LDAP_SUCCESS) {
+               return rs->sr_err;
        }
 
        /*
@@ -725,8 +687,7 @@ meta_send_entry(
         */
        if ( li->cache.ttl != META_DNCACHE_DISABLED ) {
                ( void )meta_dncache_update_entry( &li->cache,
-                                                  &ent.e_nname,
-                                                  target );
+                               &ent.e_nname, target );
        }
 
        ent.e_id = 0;
@@ -735,7 +696,7 @@ meta_send_entry(
        attrp = &ent.e_attrs;
 
        while ( ber_scanf( &ber, "{m", &a ) != LBER_ERROR ) {
-               ldap_back_map( &li->targets[ target ]->at_map
+               ldap_back_map( &li->targets[ target ]->rwmap.rwm_at
                                &a, &mapped, BACKLDAP_REMAP );
                if ( mapped.bv_val == NULL || mapped.bv_val[0] == '\0' ) {
                        continue;
@@ -781,7 +742,7 @@ meta_send_entry(
                        for ( last = 0; attr->a_vals[ last ].bv_val; ++last );
 
                        for ( bv = attr->a_vals; bv->bv_val; bv++ ) {
-                               ldap_back_map( &li->targets[ target]->oc_map,
+                               ldap_back_map( &li->targets[ target ]->rwmap.rwm_oc,
                                                bv, &mapped, BACKLDAP_REMAP );
                                if ( mapped.bv_val == NULL || mapped.bv_val[0] == '\0') {
                                        free( bv->bv_val );
@@ -818,7 +779,7 @@ meta_send_entry(
                        for ( bv = attr->a_vals; bv->bv_val; bv++ ) {
                                char *newval;
 
-                               switch ( rewrite_session( li->targets[ target ]->rwinfo,
+                               switch ( rewrite_session( li->targets[ target ]->rwmap.rwm_rw,
                                                        "searchResult",
                                                        bv->bv_val,
                                                        lc->conn, &newval )) {
index b26dab5203e9080229df45dcc273b75e5632487d..44f56040ba6db50fbb2dda875658c70cdc99d9cd 100644 (file)
@@ -121,7 +121,7 @@ meta_back_conn_destroy(
                                continue;
                        }
 
-                       rewrite_session_delete( li->targets[ i ]->rwinfo, conn );
+                       rewrite_session_delete( li->targets[ i ]->rwmap.rwm_rw, conn );
                        meta_clear_one_candidate( &lc->conns[ i ], 1 );
                }