]> git.sur5r.net Git - openldap/commitdiff
lots of migration to struct berval; unfortunately it seems to be broken
authorPierangelo Masarati <ando@openldap.org>
Thu, 3 Jan 2002 16:29:38 +0000 (16:29 +0000)
committerPierangelo Masarati <ando@openldap.org>
Thu, 3 Jan 2002 16:29:38 +0000 (16:29 +0000)
servers/slapd/back-meta/add.c
servers/slapd/back-meta/attribute.c
servers/slapd/back-meta/bind.c
servers/slapd/back-meta/compare.c
servers/slapd/back-meta/config.c
servers/slapd/back-meta/dncache.c
servers/slapd/back-meta/group.c
servers/slapd/back-meta/modify.c
servers/slapd/back-meta/search.c

index f061f443c452431124ec82808a6bea88bc6a30d7..11309a336d483d57646fa980af478300db01d4bd 100644 (file)
@@ -89,7 +89,7 @@ meta_back_add(
        int i, candidate = -1;
        Attribute *a;
        LDAPMod **attrs;
-       char *mdn = NULL, *mapped;
+       struct berval mdn = { 0, NULL }, mapped;
 
 #ifdef NEW_LOGGING
        LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY, "meta_back_add: %s\n",
@@ -113,19 +113,21 @@ meta_back_add(
         * Rewrite the add dn, if needed
         */
        switch ( rewrite_session( li->targets[ candidate ]->rwinfo,
-                               "addDn", e->e_dn, conn, &mdn )) {
+                               "addDn", e->e_dn, conn, &mdn.bv_val )) {
        case REWRITE_REGEXEC_OK:
-               if ( mdn == NULL ) {
-                       mdn = e->e_dn;
+               if ( mdn.bv_val != NULL && mdn.bv_val[ 0 ] != '\0' ) {
+                       mdn.bv_len = strlen( mdn.bv_val );
+               } else {
+                       mdn = e->e_name;
                }
 
 #ifdef NEW_LOGGING
                LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
                                "[rw] addDn: \"%s\" -> \"%s\"\n",
-                               e->e_dn, mdn ));
+                               e->e_dn, mdn.bv_val ));
 #else /* !NEW_LOGGING */
                Debug( LDAP_DEBUG_ARGS, "rw> addDn: \"%s\" -> \"%s\"\n%s", 
-                               e->e_dn, mdn, "" );
+                               e->e_dn, mdn.bv_val, "" );
 #endif /* !NEW_LOGGING */
                break;
                
@@ -166,9 +168,9 @@ meta_back_add(
                }
 #endif
                
-               mapped = ldap_back_map( &li->targets[ candidate ]->at_map,
-                               a->a_desc->ad_cname.bv_val, 0);
-               if ( mapped == NULL ) {
+               ldap_back_map( &li->targets[ candidate ]->at_map,
+                               &a->a_desc->ad_cname, &mapped, 0);
+               if ( mapped.bv_val == NULL ) {
                        continue;
                }
 
@@ -177,7 +179,7 @@ meta_back_add(
                        continue;
                }
                attrs[ i ]->mod_op = LDAP_MOD_BVALUES;
-               attrs[ i ]->mod_type = mapped;
+               attrs[ i ]->mod_type = mapped.bv_val;
 
                /*
                 * FIXME: dn-valued attrs should be rewritten
@@ -195,13 +197,13 @@ meta_back_add(
        }
        attrs[ i ] = NULL;
 
-       ldap_add_s( lc->conns[ candidate ]->ld, mdn, attrs );
+       ldap_add_s( lc->conns[ candidate ]->ld, mdn.bv_val, attrs );
        for ( --i; i >= 0; --i ) {
                free( attrs[ i ] );
        }
        free( attrs );
-       if ( mdn != e->e_dn ) {
-               free( mdn );
+       if ( mdn.bv_val != e->e_dn ) {
+               free( mdn.bv_val );
        }
        return meta_back_op_result( lc, op );
 }
index b9fcb365ba98d6db7a569ac2e339ea12edc23532..98285fb1910b1f2ed6b4f522631eaf5a3c641077 100644 (file)
@@ -91,20 +91,22 @@ meta_back_attribute(
                Entry                   *target,
                struct berval           *ndn,
                AttributeDescription    *entry_at,
-               struct berval           ***vals
+               BVarray                 *vals
 )
 {
        struct metainfo *li = ( struct metainfo * )be->be_private;    
        int rc = 1, i, j, count, is_oc, candidate;
        Attribute *attr;
-       struct berval **abv, **v;
-       char **vs, *mapped;
+       BVarray abv, v;
+       char **vs; 
+       struct berval   mapped;
        LDAPMessage     *result, *e;
        char *gattr[ 2 ];
        LDAP *ld;
 
        *vals = NULL;
-       if ( target != NULL && strcmp( target->e_ndn, ndn->bv_val ) == 0 ) {
+       if ( target != NULL && target->e_nname.bv_len == ndn->bv_len
+                       && strcmp( target->e_ndn, ndn->bv_val ) == 0 ) {
                /* we already have a copy of the entry */
                /* attribute and objectclass mapping has already been done */
                attr = attr_find( target->e_attrs, entry_at );
@@ -112,24 +114,25 @@ meta_back_attribute(
                        return 1;
                }
 
-               for ( count = 0; attr->a_vals[ count ] != NULL; count++ )
+               for ( count = 0; attr->a_vals[ count ].bv_val != NULL; count++ )
                        ;
-               v = ch_calloc( ( count + 1 ), sizeof( struct berval * ) );
-               if ( v != NULL ) {
-                       for ( j = 0, abv = attr->a_vals; --count >= 0; abv++ ) {
-                               if ( ( *abv )->bv_len > 0 ) {
-                                       v[ j ] = ber_bvdup( *abv );
-                                       if ( v[ j ] == NULL ) {
-                                               break;
-                                       }
+               v = ( BVarray )ch_calloc( ( count + 1 ), sizeof( struct berval ) );
+               if ( v == NULL ) {
+                       return 1;
+               }
+
+               for ( j = 0, abv = attr->a_vals; --count >= 0; abv++ ) {
+                       if ( abv->bv_len > 0 ) {
+                               ber_dupbv( &v[ j ], abv );
+                               if ( v[ j ].bv_val == NULL ) {
+                                       break;
                                }
                        }
-                       v[ j ] = NULL;
-                       *vals = v;
-                       rc = 0;
                }
+               v[ j ].bv_val = NULL;
+               *vals = v;
 
-               return rc;
+               return 0;
        } /* else */
 
        candidate = meta_back_select_unique_candidate( li, ndn );
@@ -137,9 +140,9 @@ meta_back_attribute(
                return 1;
        }
 
-       mapped = ldap_back_map( &li->targets[ candidate ]->at_map,
-                       entry_at->ad_cname.bv_val, 0 );
-       if ( mapped == NULL )
+       ldap_back_map( &li->targets[ candidate ]->at_map,
+                       &entry_at->ad_cname, &mapped, 0 );
+       if ( mapped.bv_val == NULL )
                return 1;
 
        rc =  ldap_initialize( &ld, li->targets[ candidate ]->uri );
@@ -153,46 +156,43 @@ meta_back_attribute(
                return 1;
        }
 
-       gattr[ 0 ] = mapped;
+       gattr[ 0 ] = mapped.bv_val;
        gattr[ 1 ] = NULL;
        if ( ldap_search_ext_s( ld, ndn->bv_val, LDAP_SCOPE_BASE, 
-                               "(objectclass=*)",
+                               "(objectClass=*)",
                                gattr, 0, NULL, NULL, LDAP_NO_LIMIT,
                                LDAP_NO_LIMIT, &result) == LDAP_SUCCESS) {
                if ( ( e = ldap_first_entry( ld, result ) ) != NULL ) {
-                       vs = ldap_get_values( ld, e, mapped );
+                       vs = ldap_get_values( ld, e, mapped.bv_val );
                        if ( vs != NULL ) {
                                for ( count = 0; vs[ count ] != NULL;
                                                count++ ) { }
-                               v = ch_calloc( ( count + 1 ),
-                                               sizeof( struct berval ) );
+                               v = ( BVarray )ch_calloc( ( count + 1 ),
+                                               sizeof( struct berval ) );
                                if ( v == NULL ) {
                                        ldap_value_free( vs );
                                } else {
-                                       is_oc = ( strcasecmp( "objectclass", mapped ) == 0 );
+                                       is_oc = ( strcasecmp( "objectclass", mapped.bv_val ) == 0 );
                                        for ( i = 0, j = 0; i < count; i++ ) {
+                                               ber_str2bv( vs[ i ], 0, 0, &v[ j ] );
                                                if ( !is_oc ) {
-                                                       v[ j ] = ber_bvstr( vs[ i ] );
-                                                       if ( v[ j ] == NULL ) {
+                                                       if ( v[ j ].bv_val == NULL ) {
                                                                ch_free( vs[ i ] );
                                                        } else {
                                                                j++;
                                                        }
                                                } else {
-                                                       mapped = ldap_back_map( &li->targets[ candidate ]->oc_map, vs[ i ], 1 );
-                                                       if ( mapped ) {
-                                                               mapped = ch_strdup( mapped );
-                                                               if ( mapped ) {
-                                                                       v[ j ] = ber_bvstr( mapped );
-                                                                       if ( v[ j ] ) {
-                                                                               j++;
-                                                                       }
+                                                       ldap_back_map( &li->targets[ candidate ]->oc_map, &v[ j ], &mapped, 1 );
+                                                       if ( mapped.bv_val ) {
+                                                               ber_dupbv( &v[ j ], &mapped );
+                                                               if ( v[ j ].bv_val ) {
+                                                                       j++;
                                                                }
                                                        }
                                                        ch_free( vs[ i ] );
                                                }
                                        }
-                                       v[ j ] = NULL;
+                                       v[ j ].bv_val = NULL;
                                        *vals = v;
                                        rc = 0;
                                        ch_free( vs );
@@ -201,7 +201,7 @@ meta_back_attribute(
                }
                ldap_msgfree( result );
        }
-       ldap_unbind(ld);
+       ldap_unbind( ld );
 
        return(rc);
 }
index b2f38977ee23f34c766fdf3fb65f925114a06830..1e5e6b8698e8994e6945cefaff3f91d4b4219d8d 100644 (file)
@@ -221,25 +221,25 @@ meta_back_do_single_bind(
                int                     candidate
 )
 {
-       char *mdn = NULL;
+       struct berval mdn = { 0, NULL };
        int rc;
        
        /*
         * Rewrite the bind dn if needed
         */
        switch ( rewrite_session( li->targets[ candidate ]->rwinfo,
-                               "bindDn", dn->bv_val, lc->conn, &mdn ) ) {
+                               "bindDn", dn->bv_val, lc->conn, &mdn.bv_val ) ) {
        case REWRITE_REGEXEC_OK:
-               if ( mdn == NULL ) {
-                       mdn = ( char * )dn->bv_val;
+               if ( mdn.bv_val == NULL ) {
+                       mdn = *dn;
                }
 #ifdef NEW_LOGGING
                LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
-                               "[rw] bindDn: \"%s\" -> \"%s\"\n", dn->bv_val, mdn ));
+                               "[rw] bindDn: \"%s\" -> \"%s\"\n", dn->bv_val, mdn.bv_val ));
 #else /* !NEW_LOGGING */
                Debug( LDAP_DEBUG_ARGS,
                                "rw> bindDn: \"%s\" -> \"%s\"\n%s",
-                               dn->bv_val, mdn, "" );
+                               dn->bv_val, mdn.bv_val, "" );
 #endif /* !NEW_LOGGING */
                break;
                
@@ -250,7 +250,7 @@ meta_back_do_single_bind(
                return LDAP_OPERATIONS_ERROR;
        }
 
-       rc = ldap_bind_s( lc->conns[ candidate ]->ld, mdn, cred->bv_val, method );
+       rc = ldap_bind_s( lc->conns[ candidate ]->ld, mdn.bv_val, cred->bv_val, method );
        if ( rc != LDAP_SUCCESS ) {
                rc = ldap_back_map_result( rc );
        } else {
@@ -261,12 +261,12 @@ meta_back_do_single_bind(
                if ( li->cache.ttl != META_DNCACHE_DISABLED
                                && ndn->bv_len != 0 ) {
                        ( void )meta_dncache_update_entry( &li->cache,
-                                       ber_bvdup( ndn ), candidate );
+                                       ndn, candidate );
                }
        }
        
-       if ( mdn != dn->bv_val ) {
-               free( mdn );
+       if ( mdn.bv_val != dn->bv_val ) {
+               free( mdn.bv_val );
        }
 
        return rc;
index b68f8c70be2d5d3f22fbabc251a44334869fd910..a4edabdb0ef2983ec1579a5c71b27b9f42f2feee 100644 (file)
@@ -109,8 +109,8 @@ meta_back_compare(
         */
        for ( i = 0, lsc = lc->conns; lsc[ 0 ] != NULL; ++i, ++lsc ) {
                char *mdn = NULL;
-               char *mapped_attr = ava->aa_desc->ad_cname.bv_val;
-               char *mapped_value = ava->aa_value.bv_val;
+               struct berval mapped_attr = ava->aa_desc->ad_cname;
+               struct berval mapped_value = ava->aa_value;
 
                if ( lsc[ 0 ]->candidate != META_CANDIDATE ) {
                        continue;
@@ -155,10 +155,10 @@ meta_back_compare(
                 */
                if ( ava->aa_desc->ad_type->sat_oid 
                        == slap_schema.si_ad_objectClass->ad_type->sat_oid ) {
-                       mapped_value = ldap_back_map( &li->targets[ i ]->oc_map,
-                                       ava->aa_value.bv_val, 0 );
+                       ldap_back_map( &li->targets[ i ]->oc_map,
+                                       &ava->aa_value, &mapped_value, 0 );
 
-                       if ( mapped_value == NULL ) {
+                       if ( mapped_value.bv_val == NULL ) {
                                lsc[ 0 ]->candidate = META_NOT_CANDIDATE;
                                continue;
                        }
@@ -166,9 +166,9 @@ meta_back_compare(
                 * else try to remap the attribute
                 */
                } else {
-                       mapped_attr = ldap_back_map( &li->targets[ i ]->at_map,
-                               ava->aa_desc->ad_cname.bv_val, 0 );
-                       if ( mapped_attr == NULL ) {
+                       ldap_back_map( &li->targets[ i ]->at_map,
+                               &ava->aa_desc->ad_cname, &mapped_attr, 0 );
+                       if ( mapped_attr.bv_val == NULL ) {
                                lsc[ 0 ]->candidate = META_NOT_CANDIDATE;
                                continue;
                        }
@@ -180,7 +180,7 @@ meta_back_compare(
                 * of the result ought to be enforced
                 */
                msgid[ i ] = ldap_compare( lc->conns[ i ]->ld, mdn,
-                               mapped_attr, mapped_value );
+                               mapped_attr.bv_val, mapped_value.bv_val );
                if ( msgid[ i ] == -1 ) {
                        lsc[ 0 ]->candidate = META_NOT_CANDIDATE;
                        continue;
@@ -189,11 +189,11 @@ meta_back_compare(
                if ( mdn != dn->bv_val ) {
                        free( mdn );
                }
-               if ( mapped_attr != ava->aa_desc->ad_cname.bv_val ) {
-                       free( mapped_attr );
+               if ( mapped_attr.bv_val != ava->aa_desc->ad_cname.bv_val ) {
+                       free( mapped_attr.bv_val );
                }
-               if ( mapped_value != ava->aa_value.bv_val ) {
-                       free( mapped_value );
+               if ( mapped_value.bv_val != ava->aa_value.bv_val ) {
+                       free( mapped_value.bv_val );
                }
 
                ++candidates;
@@ -244,7 +244,7 @@ meta_back_compare(
                                         * sending to cache ...
                                         */
                                        if ( li->cache.ttl != META_DNCACHE_DISABLED ) {
-                                               ( void )meta_dncache_update_entry( &li->cache, ber_bvdup( ndn ), i );
+                                               ( void )meta_dncache_update_entry( &li->cache, ndn, i );
                                        }
 
                                        count++;
index 1d03176f03a4afd76d614d3332ce6bcd2745d620..3c2f67bf513db319fe4281704d91e0882d0e9a97 100644 (file)
@@ -104,8 +104,8 @@ new_target( void )
                free( lt );
                return NULL;
        }
-       mapping->src = ch_strdup( "objectClass" );
-       mapping->dst = ch_strdup( "objectClass" );
+       ber_str2bv( "objectClass", 0, 1, &mapping->src );
+       ber_str2bv( "objectClass", 0, 1, &mapping->dst );
        mapping[ 1 ].src = mapping->src;
        mapping[ 1 ].dst = mapping->dst;
 
@@ -567,8 +567,8 @@ meta_back_db_config(
                                fname, lineno );
                        return 1;
                }
-               mapping->src = ch_strdup( src );
-               mapping->dst = ch_strdup( dst );
+               ber_str2bv( src, 0, 1, &mapping->src );
+               ber_str2bv( dst, 0, 1, &mapping->dst );
                if ( *dst != 0 ) {
                        mapping[ 1 ].src = mapping->dst;
                        mapping[ 1 ].dst = mapping->src;
index a37d1e7706e39956c8356ff9887f97b4a6abd0f9..f1f26073696f02f77f05d95a53bf03eba2914528 100644 (file)
@@ -77,7 +77,7 @@
  */
 
 struct metadncacheentry {
-       struct berval   *dn;
+       struct berval   dn;
        int             target;
 
        time_t          lastupdated;
@@ -99,12 +99,12 @@ meta_dncache_cmp(
        struct metadncacheentry *cc1 = ( struct metadncacheentry * )c1;
        struct metadncacheentry *cc2 = ( struct metadncacheentry * )c2;
 
-       int                     d = cc1->dn->bv_len - cc2->dn->bv_len;
+       int                     d = cc1->dn.bv_len - cc2->dn.bv_len;
        
        /*
         * case sensitive, because the dn MUST be normalized
         */
-       return d != 0 ? d : strcmp( cc1->dn->bv_val, cc2->dn->bv_val );
+       return d != 0 ? d : strcmp( cc1->dn.bv_val, cc2->dn.bv_val );
 }
 
 /*
@@ -122,13 +122,13 @@ meta_dncache_dup(
        struct metadncacheentry *cc1 = ( struct metadncacheentry * )c1;
        struct metadncacheentry *cc2 = ( struct metadncacheentry * )c2;
        
-       int                     d = cc1->dn->bv_len - cc2->dn->bv_len;
+       int                     d = cc1->dn.bv_len - cc2->dn.bv_len;
        int                     cmp;
        
        /*
         * case sensitive, because the dn MUST be normalized
         */
-       cmp = d != 0 ? d : strcmp( cc1->dn->bv_val, cc2->dn->bv_val );
+       cmp = d != 0 ? d : strcmp( cc1->dn.bv_val, cc2->dn.bv_val );
 
        return ( cmp == 0 ) ? -1 : 0;
 }
@@ -149,7 +149,10 @@ meta_dncache_get_target(
        time_t curr_time;
        int target = -1;
 
-       tmp_entry.dn = ndn;
+       assert( cache );
+       assert( ndn );
+
+       tmp_entry.dn = *ndn;
        ldap_pvt_thread_mutex_lock( &cache->mutex );
        entry = ( struct metadncacheentry * )avl_find( cache->tree,
                        ( caddr_t )&tmp_entry, meta_dncache_cmp );
@@ -197,6 +200,9 @@ meta_dncache_update_entry(
        time_t curr_time = 0L;
        int err = 0;
 
+       assert( cache );
+       assert( ndn );
+
        /*
         * if cache->ttl < 0, cache never expires;
         * if cache->ttl = 0 no cache is used; shouldn't get here
@@ -210,7 +216,7 @@ meta_dncache_update_entry(
                curr_time = time( NULL );
        }
 
-       tmp_entry.dn = ndn;
+       tmp_entry.dn = *ndn;
 
        ldap_pvt_thread_mutex_lock( &cache->mutex );
        entry = ( struct metadncacheentry * )avl_find( cache->tree,
@@ -226,8 +232,8 @@ meta_dncache_update_entry(
                        return -1;
                }
 
-               entry->dn = ber_bvdup( ndn );
-               if ( entry->dn == NULL ) {
+               ber_dupbv( &entry->dn, ndn );
+               if ( entry->dn.bv_val == NULL ) {
                        ldap_pvt_thread_mutex_unlock( &cache->mutex );
                        return -1;
                }
@@ -256,7 +262,10 @@ meta_dncache_delete_entry(
 {
        struct metadncacheentry *entry, tmp_entry;
 
-       tmp_entry.dn = ndn;
+       assert( cache );
+       assert( ndn );
+
+       tmp_entry.dn = *ndn;
 
        ldap_pvt_thread_mutex_lock( &cache->mutex );
        entry = avl_delete( &cache->tree, ( caddr_t )&tmp_entry,
@@ -283,6 +292,6 @@ meta_dncache_free(
 {
        struct metadncacheentry *entry = ( struct metadncacheentry * )e;
 
-       ber_bvfree( entry->dn );
+       free( entry->dn.bv_val );
 }
 
index bc2d63392756eaa4046b5f2af99c7bcfbc8bedb7..9651b16179b08f72919e0436716a01d339d62701 100644 (file)
@@ -98,17 +98,21 @@ meta_back_group(
        AttributeDescription *ad_objectClass = slap_schema.si_ad_objectClass;
        LDAPMessage     *result;
        char *gattr[ 2 ];
-       char *filter;
+       char *filter, *ptr;
        LDAP *ld;
-       char *mop_ndn, *mgr_ndn;
+       struct berval mop_ndn = { 0, NULL }, mgr_ndn = { 0, NULL };
 
-       char *group_oc_name = NULL;
-       char *group_at_name = group_at->ad_cname.bv_val;
+       struct berval group_oc_name = { 0, NULL };
+       struct berval group_at_name = group_at->ad_cname;
 
        if ( group_oc->soc_names && group_oc->soc_names[ 0 ] ) {
-               group_oc_name = group_oc->soc_names[ 0 ];
+               group_oc_name.bv_val = group_oc->soc_names[ 0 ];
        } else {
-               group_oc_name = group_oc->soc_oid;
+               group_oc_name.bv_val = group_oc->soc_oid;
+       }
+
+       if ( group_oc_name.bv_val ) {
+               group_oc_name.bv_len = strlen( group_oc_name.bv_val );
        }
 
        if ( target != NULL && strcmp( target->e_nname.bv_val, gr_ndn->bv_val ) == 0 ) {
@@ -152,28 +156,30 @@ meta_back_group(
 
        candidate = meta_back_select_unique_candidate( li, gr_ndn );
        if ( candidate == -1 ) {
-               return 1;
+               goto cleanup;
        }
 
        /*
         * Rewrite the op ndn if needed
         */
        switch ( rewrite_session( li->targets[ candidate ]->rwinfo, "bindDn",
-                               op_ndn->bv_val, conn, &mop_ndn ) ) {
+                               op_ndn->bv_val, conn, &mop_ndn.bv_val ) ) {
        case REWRITE_REGEXEC_OK:
-               if ( mop_ndn == NULL ) {
-                       mop_ndn = ( char * )op_ndn->bv_val;
+               if ( mop_ndn.bv_val != NULL && mop_ndn.bv_val[ 0 ] != '\0' ) {
+                       mop_ndn.bv_len = strlen( mop_ndn.bv_val );
+               } else {
+                       mop_ndn = *op_ndn;
                }
 #ifdef NEW_LOGGING
                LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
                                "[rw] bindDn (op ndn in group):"
                                 \"%s\" -> \"%s\"\n",
-                                op_ndn->bv_val, mop_ndn));
+                                op_ndn->bv_val, mop_ndn.bv_val));
 #else /* !NEW_LOGGING */
                Debug( LDAP_DEBUG_ARGS,
                                "rw> bindDn (op ndn in group):"
                                " \"%s\" -> \"%s\"\n%s",
-                               op_ndn->bv_val, mop_ndn, "" );
+                               op_ndn->bv_val, mop_ndn.bv_val, "" );
 #endif /* !NEW_LOGGING */
                break;
                
@@ -189,21 +195,23 @@ meta_back_group(
         */
        switch ( rewrite_session( li->targets[ candidate ]->rwinfo,
                                "searchBase",
-                               gr_ndn->bv_val, conn, &mgr_ndn ) ) {
+                               gr_ndn->bv_val, conn, &mgr_ndn.bv_val ) ) {
        case REWRITE_REGEXEC_OK:
-               if ( mgr_ndn == NULL ) {
-                       mgr_ndn = ( char * )gr_ndn->bv_val;
+               if ( mgr_ndn.bv_val != NULL && mgr_ndn.bv_val[ 0 ] != '\0' ) {
+                       mgr_ndn.bv_len = strlen( mgr_ndn.bv_val );
+               } else {
+                       mgr_ndn = *gr_ndn;
                }
 #ifdef NEW_LOGGING
                LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
                                "[rw] searchBase (gr ndn in group):"
                                " \"%s\" -> \"%s\"\n",
-                               gr_ndn->bv_val, mgr_ndn ));
+                               gr_ndn->bv_val, mgr_ndn.bv_val ));
 #else /* !NEW_LOGGING */
                Debug( LDAP_DEBUG_ARGS,
                                "rw> searchBase (gr ndn in group):"
                                " \"%s\" -> \"%s\"\n%s",
-                               gr_ndn->bv_val, mgr_ndn, "" );
+                               gr_ndn->bv_val, mgr_ndn.bv_val, "" );
 #endif /* !NEW_LOGGING */
                break;
                
@@ -211,24 +219,24 @@ meta_back_group(
                /* continues to next case */
                
        case REWRITE_REGEXEC_ERR:
-               return 1;
+               goto cleanup;
        }
        
-       group_oc_name = ldap_back_map( &li->targets[ candidate ]->oc_map,
-                       group_oc_name, 0 );
-       if ( group_oc_name == NULL ) {
-               return 1;
+       ldap_back_map( &li->targets[ candidate ]->oc_map,
+                       &group_oc_name, &group_oc_name, 0 );
+       if ( group_oc_name.bv_val == NULL ) {
+               goto cleanup;
        }
-       group_at_name = ldap_back_map( &li->targets[ candidate ]->at_map,
-                       group_at_name, 0 );
-       if ( group_at_name == NULL ) {
-               return 1;
+       ldap_back_map( &li->targets[ candidate ]->at_map,
+                       &group_at_name, &group_at_name, 0 );
+       if ( group_at_name.bv_val == NULL ) {
+               goto cleanup;
        }
 
        filter = ch_malloc( sizeof( "(&(objectclass=)(=))" )
-                       + strlen( group_oc_name )
-                       + strlen( group_at_name )
-                       + strlen( mop_ndn ) + 1 );
+                       + group_oc_name.bv_len
+                       + group_at_name.bv_len
+                       + mop_ndn.bv_len + 1 );
        if ( filter == NULL ) {
                goto cleanup;
        }
@@ -245,18 +253,18 @@ meta_back_group(
                goto cleanup;
        }
 
-       strcpy( filter, "(&(objectclass=" );
-       strcat( filter, group_oc_name );
-       strcat( filter, ")(" );
-       strcat( filter, group_at_name );
-       strcat( filter, "=" );
-       strcat( filter, mop_ndn );
-       strcat( filter, "))" );
+       ptr = slap_strcopy( filter, "(&(objectclass=" );
+       ptr = slap_strcopy( ptr , group_oc_name.bv_val );
+       ptr = slap_strcopy( ptr , ")(" );
+       ptr = slap_strcopy( ptr , group_at_name.bv_val );
+       ptr = slap_strcopy( ptr , "=" );
+       ptr = slap_strcopy( ptr , mop_ndn.bv_val );
+       strcpy( ptr , "))" );
 
        gattr[ 0 ] = "objectclass";
        gattr[ 1 ] = NULL;
        rc = 1;
-       if ( ldap_search_ext_s( ld, mgr_ndn, LDAP_SCOPE_BASE, filter,
+       if ( ldap_search_ext_s( ld, mgr_ndn.bv_val, LDAP_SCOPE_BASE, filter,
                                gattr, 0, NULL, NULL, LDAP_NO_LIMIT,
                                LDAP_NO_LIMIT, &result ) == LDAP_SUCCESS ) {
                if ( ldap_first_entry( ld, result ) != NULL ) {
@@ -272,11 +280,11 @@ cleanup:;
        if ( filter != NULL ) {
                ch_free( filter );
        }
-       if ( mop_ndn != op_ndn->bv_val ) {
-               free( mop_ndn );
+       if ( mop_ndn.bv_val != op_ndn->bv_val ) {
+               free( mop_ndn.bv_val );
        }
-       if ( mgr_ndn != gr_ndn->bv_val ) {
-               free( mgr_ndn );
+       if ( mgr_ndn.bv_val != gr_ndn->bv_val ) {
+               free( mgr_ndn.bv_val );
        }
 
        return rc;
index db1ee00a64ab650627c945efc1cd5716fe362e16..8a5a5f3ff6367aa04bda7e8932c7fb5249cdffe1 100644 (file)
@@ -91,7 +91,8 @@ meta_back_modify(
        LDAPMod *mods;
        Modifications *ml;
        int candidate = -1, i;
-       char *mdn, *mapped;
+       char *mdn;
+       struct berval mapped;
 
        lc = meta_back_getconn( li, conn, op, META_OP_REQUIRE_SINGLE,
                        ndn, &candidate );
@@ -167,15 +168,15 @@ meta_back_modify(
                }
 #endif
 
-               mapped = ldap_back_map( &li->targets[ candidate ]->at_map,
-                               ml->sml_desc->ad_cname.bv_val, 0 );
-               if ( mapped == NULL ) {
+               ldap_back_map( &li->targets[ candidate ]->at_map,
+                               &ml->sml_desc->ad_cname, &mapped, 0 );
+               if ( mapped.bv_val == NULL ) {
                        continue;
                }
 
                modv[ i ] = &mods[ i ];
                mods[ i ].mod_op = ml->sml_op | LDAP_MOD_BVALUES;
-               mods[ i ].mod_type = mapped;
+               mods[ i ].mod_type = mapped.bv_val;
 
                /*
                 * FIXME: dn-valued attrs should be rewritten
index 7ec8ae870749a5f945b9d4accd72c8ebde6a82b1..5567586badca6f6f02e915210fd745d2822af9c7 100644 (file)
@@ -76,6 +76,7 @@
 #include "../back-ldap/back-ldap.h"
 #include "back-meta.h"
 #include "ldap_pvt.h"
+#include "../../../libraries/libldap/ldap-int.h"
 
 static void
 meta_send_entry(
@@ -106,7 +107,7 @@ meta_back_search(
                int             slimit,
                int             tlimit,
                Filter          *filter,
-               const char      *filterstr,
+               struct berval   *filterstr,
                AttributeName   *attrs,
                int             attrsonly
 )
@@ -118,8 +119,9 @@ meta_back_search(
        LDAPMessage     *res, *e;
        int     count, rc = 0, *msgid, sres = LDAP_NO_SUCH_OBJECT;
        char *match = NULL, *err = NULL;
-       char *mbase = NULL, *mfilter = NULL, *mmatch = NULL, 
+       char *mbase = NULL, *mmatch = NULL, 
                *mapped_filter = NULL, **mapped_attrs = NULL;
+       struct berval mfilter;
                
        int i, last = 0, candidates = 0, op_type;
        struct slap_limits_set *limit = NULL;
@@ -303,22 +305,24 @@ meta_back_search(
                 */
                switch ( rewrite_session( li->targets[ i ]->rwinfo,
                                        "searchFilter",
-                                       filterstr, conn, &mfilter ) ) {
+                                       filterstr->bv_val, conn, &mfilter.bv_val ) ) {
                case REWRITE_REGEXEC_OK:
-                       if ( mfilter == NULL || mfilter[ 0 ] == '\0') {
-                               if ( mfilter != NULL ) {
-                                       free( mfilter );
+                       if ( mfilter.bv_val != NULL && mfilter.bv_val[ 0 ] != '\0') {
+                               mfilter.bv_len = strlen( mfilter.bv_val );
+                       } else {
+                               if ( mfilter.bv_val != NULL ) {
+                                       free( mfilter.bv_val );
                                }
-                               mfilter = ( char * )filterstr;
+                               mfilter = *filterstr;
                        }
 #ifdef NEW_LOGGING
                        LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
                                        "[rw] searchFilter: \"%s\" -> \"%s\"\n",
-                                       filterstr, mfilter ));
+                                       filterstr->bv_val, mfilter.bv_val ));
 #else /* !NEW_LOGGING */
                        Debug( LDAP_DEBUG_ARGS,
                                "rw> searchFilter: \"%s\" -> \"%s\"\n%s",
-                               filterstr, mfilter, "" );
+                               filterstr->bv_val, mfilter.bv_val, "" );
 #endif /* !NEW_LOGGING */
                        break;
                
@@ -339,10 +343,9 @@ meta_back_search(
                 * Maps attributes in filter
                 */
                mapped_filter = ldap_back_map_filter( &li->targets[ i ]->at_map,
-                               &li->targets[ i ]->oc_map,
-                               ( char * )mfilter, 0 );
+                               &li->targets[ i ]->oc_map, &mfilter, 0 );
                if ( mapped_filter == NULL ) {
-                       mapped_filter = ( char * )mfilter;
+                       mapped_filter = ( char * )mfilter.bv_val;
                }
        
                /*
@@ -374,13 +377,14 @@ meta_back_search(
                        free( mapped_attrs );
                        mapped_attrs = NULL;
                }
-               if ( mapped_filter != mfilter ) {
+               if ( mapped_filter != mfilter.bv_val ) {
                        free( mapped_filter );
                        mapped_filter = NULL;
                }
-               if ( mfilter != filterstr ) {
-                       free( mfilter );
-                       mfilter = NULL;
+               if ( mfilter.bv_val != filterstr->bv_val ) {
+                       free( mfilter.bv_val );
+                       mfilter.bv_val = NULL;
+                       mfilter.bv_len = 0;
                }
                if ( mbase != realbase ) {
                        free( mbase );
@@ -441,7 +445,7 @@ meta_back_search(
                                /* anything else needs be done? */
                                goto finish;
                        } else if ( rc == LDAP_RES_SEARCH_ENTRY ) {
-                               e = ldap_first_entry( lsc[ 0 ]->ld,res );
+                               e = ldap_first_entry( lsc[ 0 ]->ld, res );
                                meta_send_entry(be, op, lc, i, e, attrs,
                                                attrsonly);
                                count++;
@@ -578,20 +582,15 @@ meta_send_entry(
 )
 {
        struct metainfo         *li = ( struct metainfo * )be->be_private;
-       char                    *a, *mapped;
+       struct berval           a, mapped;
        Entry                   ent;
-       BerElement              *ber = NULL;
+       BerElement              ber = *e->lm_ber;
        Attribute               *attr, **attrp;
-       struct berval           *dummy = NULL;
-       struct berval           *bv;
+       struct berval           dummy = { 0, NULL };
+       struct berval           *bv, bdn;
        const char              *text;
-       char                    *dn, *edn = NULL;
-       struct berval           tdn;
-
-       struct metasingleconn *lsc = lc->conns[ target ];
 
-       dn = ldap_get_dn( lsc->ld, e );
-       if ( dn == NULL ) {
+       if ( ber_scanf( &ber, "{o", &bdn ) == LBER_ERROR ) {
                return;
        }
 
@@ -599,43 +598,40 @@ meta_send_entry(
         * Rewrite the dn of the result, if needed
         */
        switch ( rewrite_session( li->targets[ target ]->rwinfo,
-                               "searchResult", dn, lc->conn, &edn ) ) {
+                               "searchResult", bdn.bv_val, lc->conn, &ent.e_name.bv_val ) ) {
        case REWRITE_REGEXEC_OK:
-               if ( edn == NULL ) {
-                       edn = dn;
+               if ( ent.e_name.bv_val == NULL ) {
+                       ent.e_name = bdn;
 
                } else {
 #ifdef NEW_LOGGING
                        LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
                                        "[rw] searchResult[%d]:"
                                        " \"%s\" -> \"%s\"\n",
-                                       target, dn, edn ));
+                                       target, bdn.bv_val, ent.e_name.bv_val ));
 #else /* !NEW_LOGGING */
                        Debug( LDAP_DEBUG_ARGS, "rw> searchResult[%d]: \"%s\""
-                                       " -> \"%s\"\n", target, dn, edn );
+                                       " -> \"%s\"\n", target, bdn.bv_val, ent.e_name.bv_val );
 #endif /* !NEW_LOGGING */
-                       free( dn );
-                       dn = NULL;
+                       free( bdn.bv_val );
+                       bdn.bv_val = NULL;
+                       ent.e_name.bv_len = strlen( ent.e_name.bv_val );
                }
                break;
                
        case REWRITE_REGEXEC_ERR:
        case REWRITE_REGEXEC_UNWILLING:
-               free( dn );
                return;
        }
 
-       tdn.bv_val = edn;
-       tdn.bv_len = strlen( edn );
-
-       dnPrettyNormal( NULL, &tdn, &ent.e_name, &ent.e_nname );
+       dnNormalize2( NULL, &ent.e_name, &ent.e_nname );
 
        /*
         * cache dn
         */
        if ( li->cache.ttl != META_DNCACHE_DISABLED ) {
                ( void )meta_dncache_update_entry( &li->cache,
-                                                  ber_bvdup( &ent.e_nname ),
+                                                  &ent.e_nname,
                                                   target );
        }
 
@@ -644,12 +640,10 @@ meta_send_entry(
        ent.e_private = 0;
        attrp = &ent.e_attrs;
 
-       for ( a = ldap_first_attribute( lsc->ld, e, &ber );
-                       a != NULL;
-                       a = ldap_next_attribute( lsc->ld, e, ber ) )
-       {
-               mapped = ldap_back_map( &li->targets[ target ]->at_map, a, 1 );
-               if ( mapped == NULL ) {
+       while ( ber_scanf( &ber, "{{o", &a ) != LBER_ERROR ) {
+               ldap_back_map( &li->targets[ target ]->at_map, 
+                               &a, &mapped, 1 );
+               if ( mapped.bv_val == NULL ) {
                        continue;
                }
                attr = ( Attribute * )ch_malloc( sizeof( Attribute ) );
@@ -658,47 +652,45 @@ meta_send_entry(
                }
                attr->a_next = 0;
                attr->a_desc = NULL;
-               if ( slap_str2ad( mapped, &attr->a_desc, &text )
+               if ( slap_bv2ad( &mapped, &attr->a_desc, &text )
                                != LDAP_SUCCESS) {
-                       if (slap_str2undef_ad(mapped, &attr->a_desc, &text
+                       if ( slap_bv2undef_ad( &mapped, &attr->a_desc, &text 
                                        != LDAP_SUCCESS) {
 #ifdef NEW_LOGGING
                                LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
-                                               "slap_str2undef_ad(%s): "
-                                               "%s\n", mapped, text ));
+                                               "slap_bv2undef_ad(%s): "
+                                               "%s\n", mapped.bv_val, text ));
 #else /* !NEW_LOGGING */
                                Debug( LDAP_DEBUG_ANY,
-                                               "slap_str2undef_ad(%s): "
-                                               "%s\n%s", mapped, text, "" );
+                                               "slap_bv2undef_ad(%s): "
+                                               "%s\n%s", mapped.bv_val, text, "" );
 #endif /* !NEW_LOGGING */
-                               ch_free(attr);
+                               ch_free( attr );
                                continue;
                        }
                }
-               attr->a_vals = ldap_get_values_len( lsc->ld, e, a );
-               if ( !attr->a_vals ) {
+
+               if ( ber_scanf( &ber, "[W]", &attr->a_vals ) == LBER_ERROR ) {
                        attr->a_vals = &dummy;
-               } else if ( strcasecmp( mapped, "objectClass" ) == 0 ) {
+               } else if ( strcasecmp( mapped.bv_val, "objectClass" ) == 0 ) {
                        int i, last;
-                       for ( last = 0; attr->a_vals[ last ]; ++last ) ;
-                       for ( i = 0; ( bv = attr->a_vals[ i ] ); i++ ) {
-                               mapped = ldap_back_map(
-                                               &li->targets[ target]->oc_map,
-                                               bv->bv_val, 1 );
-                               if ( mapped == NULL ) {
-                                       ber_bvfree( attr->a_vals[ i ] );
-                                       attr->a_vals[ i ] = NULL;
+                       for ( last = 0; attr->a_vals[ last ].bv_val; ++last );
+                       for ( i = 0; ( bv = &attr->a_vals[ i ] ); i++ ) {
+                               ldap_back_map( &li->targets[ target]->oc_map,
+                                               bv, &mapped, 1 );
+                               if ( mapped.bv_val == NULL ) {
+                                       free( attr->a_vals[ i ].bv_val );
+                                       attr->a_vals[ i ].bv_val = NULL;
                                        if ( --last < 0 ) {
                                                break;
                                        }
                                        attr->a_vals[ i ] = 
                                                attr->a_vals[ last ];
-                                       attr->a_vals[ last ] = NULL;
+                                       attr->a_vals[ last ].bv_val = NULL;
                                        --i;
-                               } else if ( mapped != bv->bv_val ) {
+                               } else if ( mapped.bv_val != bv->bv_val ) {
                                        ch_free( bv->bv_val );
-                                       bv->bv_val = ch_strdup( mapped );
-                                       bv->bv_len = strlen( mapped );
+                                       ber_dupbv( bv, &mapped );
                                }
                        }
                /*
@@ -715,7 +707,7 @@ meta_send_entry(
                } else if ( strcmp( attr->a_desc->ad_type->sat_syntax->ssyn_oid,
                                        SLAPD_DN_SYNTAX ) == 0 ) {
                        int i;
-                       for ( i = 0; ( bv = attr->a_vals[ i ] ); i++ ) {
+                       for ( i = 0; ( bv = &attr->a_vals[ i ] ); i++ ) {
                                char *newval;
 
                                switch ( rewrite_session( li->targets[ target ]->rwinfo,
@@ -769,13 +761,10 @@ meta_send_entry(
                attr = ent.e_attrs;
                ent.e_attrs = attr->a_next;
                if ( attr->a_vals != &dummy ) {
-                       ber_bvecfree(attr->a_vals);
+                       bvarray_free( attr->a_vals );
                }
                free( attr );
        }
-       if ( ber ) {
-               ber_free( ber, 0 );
-       }
        
        if ( ent.e_dn ) {
                free( ent.e_dn );