]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-meta/attribute.c
use more appropriate error code
[openldap] / servers / slapd / back-meta / attribute.c
index 8d6e64677a3df32f79d867edee36ca8c347785a0..ec8df2e026e2366f9b325d432b7773a8d6fd57fc 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 1998-2001 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
  *
  * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
@@ -89,22 +89,23 @@ meta_back_attribute(
                Connection              *conn,
                Operation               *op,
                Entry                   *target,
-               const char              *ndn,
+               struct berval           *ndn,
                AttributeDescription    *entry_at,
-               struct berval           ***vals
+               BerVarray                       *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;
+       BerVarray 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 ) == 0 ) {
+       if ( target != NULL && dn_match( &target->e_nname, ndn ) ) {
                /* 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 +113,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 = ( BerVarray )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 +139,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 );
@@ -147,51 +149,49 @@ meta_back_attribute(
                return 1;
        }
 
-       rc = ldap_bind_s( ld, li->targets[ candidate ]->binddn,
-                       li->targets[ candidate ]->bindpw, LDAP_AUTH_SIMPLE );
+       rc = ldap_bind_s( ld, li->targets[ candidate ]->binddn.bv_val,
+                       li->targets[ candidate ]->bindpw.bv_val, LDAP_AUTH_SIMPLE );
        if ( rc != LDAP_SUCCESS) {
                return 1;
        }
 
-       gattr[ 0 ] = mapped;
+       gattr[ 0 ] = mapped.bv_val;
        gattr[ 1 ] = NULL;
-       if ( ldap_search_ext_s( ld, ndn, LDAP_SCOPE_BASE, "(objectclass=*)",
+       if ( ldap_search_ext_s( ld, ndn->bv_val, LDAP_SCOPE_BASE, 
+                               "(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 = ( BerVarray )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 );
@@ -200,7 +200,7 @@ meta_back_attribute(
                }
                ldap_msgfree( result );
        }
-       ldap_unbind(ld);
+       ldap_unbind( ld );
 
        return(rc);
 }