]> git.sur5r.net Git - openldap/commitdiff
More struct beral conversion
authorHoward Chu <hyc@openldap.org>
Fri, 28 Dec 2001 04:20:08 +0000 (04:20 +0000)
committerHoward Chu <hyc@openldap.org>
Fri, 28 Dec 2001 04:20:08 +0000 (04:20 +0000)
14 files changed:
servers/slapd/back-ldap/add.c
servers/slapd/back-ldap/attribute.c
servers/slapd/back-ldap/back-ldap.h
servers/slapd/back-ldap/bind.c
servers/slapd/back-ldap/compare.c
servers/slapd/back-ldap/config.c
servers/slapd/back-ldap/delete.c
servers/slapd/back-ldap/group.c
servers/slapd/back-ldap/init.c
servers/slapd/back-ldap/modify.c
servers/slapd/back-ldap/modrdn.c
servers/slapd/back-ldap/search.c
servers/slapd/back-ldap/suffixmassage.c
servers/slapd/back-ldap/unbind.c

index d5c3ad0cb99755811721f65b3d46447fb0358158..8d0c79b994e5d06ef05a153c6649c3ba3dde2f03 100644 (file)
@@ -58,7 +58,8 @@ ldap_back_add(
        int i;
        Attribute *a;
        LDAPMod **attrs;
-       char *mdn = NULL, *mapped;
+       char *mapped;
+       struct berval mdn = { 0, NULL };
 
 #ifdef NEW_LOGGING
        LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY, "ldap_back_add: %s\n",
@@ -76,18 +77,18 @@ ldap_back_add(
         * Rewrite the add dn, if needed
         */
 #ifdef ENABLE_REWRITE
-       switch (rewrite_session( li->rwinfo, "addDn", e->e_dn, conn, &mdn )) {
+       switch (rewrite_session( li->rwinfo, "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 = e->e_dn;
                }
 #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;
                
@@ -102,7 +103,7 @@ ldap_back_add(
                return( -1 );
        }
 #else /* !ENABLE_REWRITE */
-       mdn = ldap_back_dn_massage( li, ch_strdup( e->e_dn ), 0 );
+       ldap_back_dn_massage( li, &e->e_name, &mdn, 0, 1 );
 #endif /* !ENABLE_REWRITE */
 
        /* Count number of attributes in entry */
@@ -162,17 +163,13 @@ ldap_back_add(
        }
        attrs[i] = NULL;
 
-       ldap_add_s(lc->ld, mdn, attrs);
+       ldap_add_s(lc->ld, mdn.bv_val, attrs);
        for (--i; i>= 0; --i)
                free(attrs[i]);
        free(attrs);
-#ifdef ENABLE_REWRITE
-       if ( mdn != e->e_dn ) {
-#endif /* ENABLE_REWRITE */
-       free( mdn );
-#ifdef ENABLE_REWRITE
+       if ( mdn.bv_val != e->e_dn ) {
+               free( mdn.bv_val );
        }
-#endif /* ENABLE_REWRITE */
        
        return( ldap_back_op_result( lc, op ) );
 }
index baba6eb945575989ae74766633c652e67e3dd6c4..580d02a065ea4d33db69bf9526de30531256a150 100644 (file)
@@ -40,7 +40,8 @@ ldap_back_attribute(
        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_nname.bv_val, ndn->bv_val) == 0) {
                /* we already have a copy of the entry */
                /* attribute and objectclass mapping has already been done */
                if ((attr = attr_find(target->e_attrs, entry_at)) == NULL)
index c9c16ac716a6e0095fce059cd707ddc8c0d487d7..ed4f15fa8224c7d313687d1bc15f34877904142b 100644 (file)
@@ -53,7 +53,7 @@ struct slap_op;
 struct ldapconn {
        struct slap_conn        *conn;
        LDAP            *ld;
-       char            *bound_dn;
+       struct berval   bound_dn;
        int             bound;
 };
 
@@ -78,7 +78,7 @@ struct ldapinfo {
 #ifdef ENABLE_REWRITE
        struct rewrite_info *rwinfo;
 #else /* !ENABLE_REWRITE */
-       char **suffix_massage;
+       struct berval **suffix_massage;
 #endif /* !ENABLE_REWRITE */
 
        struct ldapmap oc_map;
@@ -92,8 +92,8 @@ int ldap_back_map_result(int err);
 int ldap_back_op_result(struct ldapconn *lc, Operation *op);
 int    back_ldap_LTX_init_module(int argc, char *argv[]);
 
-char *ldap_back_dn_massage(struct ldapinfo *li, char *dn, int normalized);
-char *ldap_back_dn_restore(struct ldapinfo *li, char *dn, int normalized);
+void ldap_back_dn_massage(struct ldapinfo *li, struct berval *dn,
+       struct berval *res, int normalized, int tofrom);
 
 extern int ldap_back_conn_cmp( const void *c1, const void *c2);
 extern int ldap_back_conn_dup( void *c1, void *c2 );
index e6df502d878821a55bf3d7bc2ba17680597de66f..582c8e40c6ea0884df7b197f2b8d59bd00db41e7 100644 (file)
@@ -64,7 +64,7 @@ ldap_back_bind(
        struct ldapinfo *li = (struct ldapinfo *) be->be_private;
        struct ldapconn *lc;
 
-       char *mdn = NULL;
+       struct berval mdn = { 0, NULL };
        int rc = 0;
 
        lc = ldap_back_getconn(li, conn, op);
@@ -76,17 +76,17 @@ ldap_back_bind(
         * Rewrite the bind dn if needed
         */
 #ifdef ENABLE_REWRITE
-       switch ( rewrite_session( li->rwinfo, "bindDn", dn->bv_val, conn, &mdn ) ) {
+       switch ( rewrite_session( li->rwinfo, "bindDn", dn->bv_val, conn, &mdn.bv_val ) ) {
        case REWRITE_REGEXEC_OK:
-               if ( mdn == NULL ) {
-                       mdn = ( char * )dn->bv_val;
+               if ( mdn.bv_val == NULL ) {
+                       mdn.bv_val = ( char * )dn->bv_val;
                }
 #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;
                
@@ -101,23 +101,19 @@ ldap_back_bind(
                return( -1 );
        }
 #else /* !ENABLE_REWRITE */
-       mdn = ldap_back_dn_massage( li, ch_strdup( dn->bv_val ), 0 );
+       ldap_back_dn_massage( li, dn, &mdn, 0, 1 );
 #endif /* !ENABLE_REWRITE */
 
-       rc = ldap_bind_s(lc->ld, mdn, cred->bv_val, method);
+       rc = ldap_bind_s(lc->ld, mdn.bv_val, cred->bv_val, method);
        if (rc != LDAP_SUCCESS) {
                rc = ldap_back_op_result( lc, op );
        } else {
                lc->bound = 1;
        }
 
-#ifdef ENABLE_REWRITE  
-       if ( mdn != dn->bv_val ) {
-#endif /* ENABLE_REWRITE */
-       free( mdn );
-#ifdef ENABLE_REWRITE
+       if ( mdn.bv_val != dn->bv_val ) {
+               free( mdn.bv_val );
        }
-#endif /* ENABLE_REWRITE */
        
        return( rc );
 }
@@ -236,13 +232,14 @@ ldap_back_getconn(struct ldapinfo *li, Connection *conn, Operation *op)
                         * Rewrite the bind dn if needed
                         */
 #ifdef ENABLE_REWRITE                  
-                       lc->bound_dn = NULL;
+                       lc->bound_dn.bv_val = NULL;
+                       lc->bound_dn.bv_len = 0;
                        switch ( rewrite_session( li->rwinfo, "bindDn",
                                                lc->conn->c_cdn, conn,
-                                               &lc->bound_dn ) ) {
+                                               &lc->bound_dn.bv_val ) ) {
                        case REWRITE_REGEXEC_OK:
-                               if ( lc->bound_dn == NULL ) {
-                                       lc->bound_dn = 
+                               if ( lc->bound_dn.bv_val == NULL ) {
+                                       lc->bound_dn.bv_val = 
                                                ch_strdup( lc->conn->c_cdn );
                                }
 #ifdef NEW_LOGGING
@@ -250,13 +247,13 @@ ldap_back_getconn(struct ldapinfo *li, Connection *conn, Operation *op)
                                                "[rw] bindDn: \"%s\" ->"
                                                " \"%s\"\n%s",
                                                lc->conn->c_cdn,
-                                               lc->bound_dn ));
+                                               lc->bound_dn.bv_val ));
 #else /* !NEW_LOGGING */
                                Debug( LDAP_DEBUG_ARGS,
                                                "rw> bindDn: \"%s\" ->"
                                                " \"%s\"\n%s",
                                                lc->conn->c_cdn,
-                                               lc->bound_dn, "" );
+                                               lc->bound_dn.bv_val, "" );
 #endif /* !NEW_LOGGING */
                                break;
                                
@@ -275,11 +272,13 @@ ldap_back_getconn(struct ldapinfo *li, Connection *conn, Operation *op)
                                return( NULL );
                        }
 #else /* !ENABLE_REWRITE */
-                       lc->bound_dn = ldap_back_dn_massage( li,
-                                       ch_strdup( lc->conn->c_cdn ), 0 );              
+                       struct berval bv;
+                       ber_str2bv( lc->conn->c_cdn, 0, 0, &bv );
+                       ldap_back_dn_massage( li, &bv, &lc->bound_dn, 0, 1 );
 #endif /* !ENABLE_REWRITE */
                } else {
-                       lc->bound_dn = NULL;
+                       lc->bound_dn.bv_val = NULL;
+                       lc->bound_dn.bv_len = 0;
                }
                lc->bound = 0;
 
@@ -340,7 +339,7 @@ ldap_back_dobind(struct ldapconn *lc, Operation *op)
                return( lc->bound );
        }
 
-       if (ldap_bind_s(lc->ld, lc->bound_dn, NULL, LDAP_AUTH_SIMPLE) !=
+       if (ldap_bind_s(lc->ld, lc->bound_dn.bv_val, NULL, LDAP_AUTH_SIMPLE) !=
                LDAP_SUCCESS) {
                ldap_back_op_result(lc, op);
                return( 0 );
index c3c76bc1ab0d99ead758ce099ce2aa6a529f0bfa..27e63dcfb8944ef7d62c7f77fce8de8cf2ebbb85 100644 (file)
@@ -57,7 +57,8 @@ ldap_back_compare(
 {
        struct ldapinfo *li = (struct ldapinfo *) be->be_private;
        struct ldapconn *lc;
-       char *mdn, *mapped_oc, *mapped_at;
+       char *mapped_oc, *mapped_at;
+       struct berval mdn = { 0, NULL };
 
        lc = ldap_back_getconn(li, conn, op);
        if (!lc || !ldap_back_dobind( lc, op ) ) {
@@ -68,18 +69,18 @@ ldap_back_compare(
         * Rewrite the compare dn, if needed
         */
 #ifdef ENABLE_REWRITE
-       switch ( rewrite_session( li->rwinfo, "compareDn", dn->bv_val, conn, &mdn ) ) {
+       switch ( rewrite_session( li->rwinfo, "compareDn", dn->bv_val, conn, &mdn.bv_val ) ) {
        case REWRITE_REGEXEC_OK:
-               if ( mdn == NULL ) {
-                       mdn = ( char * )dn->bv_val;
+               if ( mdn.bv_val == NULL ) {
+                       mdn.bv_val = ( char * )dn->bv_val;
                }
 #ifdef NEW_LOGGING
                LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
                                "[rw] compareDn: \"%s\" -> \"%s\"\n",
-                               dn->bv_val, mdn ));
+                               dn->bv_val, mdn.bv_val ));
 #else /* !NEW_LOGGING */
                Debug( LDAP_DEBUG_ARGS, "rw> compareDn: \"%s\" -> \"%s\"\n%s",
-                               dn->bv_val, mdn, "" );
+                               dn->bv_val, mdn.bv_val, "" );
 #endif /* !NEW_LOGGING */
                break;
                
@@ -94,8 +95,8 @@ ldap_back_compare(
                return( -1 );
        }
 #else /* !ENABLE_REWRITE */
-       mdn = ldap_back_dn_massage( li, ch_strdup( dn->bv_val ), 0 );
-       if ( mdn == NULL ) {
+       ldap_back_dn_massage( li, dn, &mdn, 0, 1 );
+       if ( mdn.bv_val == NULL ) {
                return -1;
        }
 #endif /* !ENABLE_REWRITE */
@@ -108,15 +109,11 @@ ldap_back_compare(
        if (mapped_at == NULL)
                return( -1 );
 
-       ldap_compare_s( lc->ld, mdn, mapped_oc, mapped_at );
+       ldap_compare_s( lc->ld, mdn.bv_val, mapped_oc, mapped_at );
 
-#ifdef ENABLE_REWRITE
-       if ( mdn != dn->bv_val ) {
-#endif /* ENABLE_REWRITE */
-               free( mdn );
-#ifdef ENABLE_REWRITE
+       if ( mdn.bv_val != dn->bv_val ) {
+               free( mdn.bv_val );
        }
-#endif /* ENABLE_REWRITE */
        
        return( ldap_back_op_result( lc, op ) );
 }
index 425ef251da78487c9e34124396592ca43d27f491..db33946cb82f858e3c16189156062471c9b96225 100644 (file)
@@ -114,7 +114,7 @@ ldap_back_db_config(
        /* dn massaging */
        } else if ( strcasecmp( argv[0], "suffixmassage" ) == 0 ) {
 #ifndef ENABLE_REWRITE
-               char *dn, *massaged_dn;
+               struct berval *bd2;
 #endif /* ENABLE_REWRITE */
                BackendDB *tmp_be;
                struct berval bdn, *ndn = NULL;
@@ -184,18 +184,17 @@ ldap_back_db_config(
                 */
                return suffix_massage_config( li->rwinfo, argc, argv );
 #else /* !ENABLE_REWRITE */
-               dn = ch_strdup( argv[1] );
-               charray_add( &li->suffix_massage, dn );
-               (void) dn_normalize( dn );
-               charray_add( &li->suffix_massage, dn );
-               
-               massaged_dn = ch_strdup( argv[2] );
-               charray_add( &li->suffix_massage, massaged_dn );
-               (void) dn_normalize( massaged_dn );
-               charray_add( &li->suffix_massage, massaged_dn );
+               bd2 = ber_bvstrdup( argv[1] );
+               ber_bvecadd( &li->suffix_massage, bd2 );
+               ndn = NULL;
+               dnNormalize( NULL, bd2, &ndn );
+               ber_bvecadd( &li->suffix_massage, ndn );
                
-               free( dn );
-               free( massaged_dn );
+               bd2 = ber_bvstrdup( argv[2] );
+               ber_bvecadd( &li->suffix_massage, bd2 );
+               ndn = NULL;
+               dnNormalize( NULL, bd2, &ndn );
+               ber_bvecadd( &li->suffix_massage, ndn );
 #endif /* !ENABLE_REWRITE */
 
 #ifdef ENABLE_REWRITE
index 3f55206d9a25cc4ead9910614989150fa7ab62bd..047ffecebc76ed306cc60f4a701560d320660338 100644 (file)
@@ -57,7 +57,7 @@ ldap_back_delete(
        struct ldapinfo *li = (struct ldapinfo *) be->be_private;
        struct ldapconn *lc;
 
-       char *mdn = NULL;
+       struct berval mdn = { 0, NULL };
 
        lc = ldap_back_getconn( li, conn, op );
        
@@ -69,17 +69,17 @@ ldap_back_delete(
         * Rewrite the compare dn, if needed
         */
 #ifdef ENABLE_REWRITE
-       switch ( rewrite_session( li->rwinfo, "deleteDn", dn->bv_val, conn, &mdn ) ) {
+       switch ( rewrite_session( li->rwinfo, "deleteDn", dn->bv_val, conn, &mdn.bv_val ) ) {
        case REWRITE_REGEXEC_OK:
-       if ( mdn == NULL ) {
-                       mdn = ( char * )dn->bv_val;
+       if ( mdn.bv_val == NULL ) {
+                       mdn.bv_val = ( char * )dn->bv_val;
                }
 #ifdef NEW_LOGGING
        LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
-                       "[rw] deleteDn: \"%s\" -> \"%s\"\n", dn->bv_val, mdn ));
+                       "[rw] deleteDn: \"%s\" -> \"%s\"\n", dn->bv_val, mdn.bv_val ));
 #else /* !NEW_LOGGING */
        Debug( LDAP_DEBUG_ARGS, "rw> deleteDn: \"%s\" -> \"%s\"\n%s",
-                       dn->bv_val, mdn, "" );
+                       dn->bv_val, mdn.bv_val, "" );
 #endif /* !NEW_LOGGING */
        break;
                
@@ -94,18 +94,14 @@ ldap_back_delete(
                return( -1 );
        }
 #else /* !ENABLE_REWRITE */
-       mdn = ldap_back_dn_massage( li, ch_strdup( dn->bv_val ), 0 );
+       ldap_back_dn_massage( li, dn, &mdn, 0, 1 );
 #endif /* !ENABLE_REWRITE */
        
-       ldap_delete_s( lc->ld, mdn );
+       ldap_delete_s( lc->ld, mdn.bv_val );
 
-#ifdef ENABLE_REWRITE
-       if ( mdn != dn->bv_val ) {
-#endif /* ENABLE_REWRITE */
-               free( mdn );
-#ifdef ENABLE_REWRITE
+       if ( mdn.bv_val != dn->bv_val ) {
+               free( mdn.bv_val );
        }
-#endif /* ENABLE_REWRITE */
        
        return( ldap_back_op_result( lc, op ) );
 }
index ce38c3ae55440462f655a8d0c0b7ec90824f551e..bd76f6be687093292e526db772901fd9afa10dfe 100644 (file)
@@ -38,9 +38,9 @@ ldap_back_group(
 
        LDAPMessage     *result;
        char *gattr[2];
-       char *filter = NULL;
+       char *filter = NULL, *ptr;
        LDAP *ld;
-       char *mop_ndn, *mgr_ndn;
+       struct berval mop_ndn = { 0, NULL }, mgr_ndn = { 0, NULL };
 
        AttributeDescription *ad_objectClass = slap_schema.si_ad_objectClass;
        char *group_oc_name = NULL;
@@ -52,7 +52,8 @@ ldap_back_group(
                group_oc_name = group_oc->soc_oid;
        }
 
-       if (target != NULL && strcmp(target->e_ndn, gr_ndn->bv_val) == 0) {
+       if (target != NULL && target->e_nname.bv_len == gr_ndn->bv_len &&
+               strcmp(target->e_nname.bv_val, gr_ndn->bv_val) == 0) {
                /* we already have a copy of the entry */
                /* attribute and objectclass mapping has already been done */
 
@@ -92,19 +93,19 @@ ldap_back_group(
         */
 #ifdef ENABLE_REWRITE
        switch ( rewrite_session( li->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 = *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 ));
+                               " \"%s\" -> \"%s\"\n", 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;
        
@@ -118,20 +119,20 @@ ldap_back_group(
         * Rewrite the gr ndn if needed
         */
         switch ( rewrite_session( li->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 = *gr_ndn;
                }
 #ifdef NEW_LOGGING
                LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
                                "[rw] searchBase (gr ndn in group):"
-                               " \"%s\" -> \"%s\"\n%s", gr_ndn->bv_val, mgr_ndn ));
+                               " \"%s\" -> \"%s\"\n%s", 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;
        
@@ -141,12 +142,12 @@ ldap_back_group(
                goto cleanup;
        }
 #else /* !ENABLE_REWRITE */
-       mop_ndn = ldap_back_dn_massage( li, ch_strdup( op_ndn ), 1 );
-       if ( mop_ndn == NULL ) {
+       ldap_back_dn_massage( li, op_ndn, &mop_ndn, 1, 1 );
+       if ( mop_ndn.bv_val == NULL ) {
                goto cleanup;
        }
-       mgr_ndn = ldap_back_dn_massage( li, ch_strdup( gr_ndn ), 1 );
-       if ( mgr_ndn == NULL ) {
+       ldap_back_dn_massage( li, gr_ndn, &mgr_ndn, 1, 1 );
+       if ( mgr_ndn.bv_val == NULL ) {
                goto cleanup;
        }
 #endif /* !ENABLE_REWRITE */
@@ -161,7 +162,7 @@ ldap_back_group(
        filter = ch_malloc(sizeof("(&(objectclass=)(=))")
                                                + strlen(group_oc_name)
                                                + strlen(group_at_name)
-                                               + strlen(mop_ndn) + 1);
+                                               + mop_ndn.bv_len + 1);
        if (filter == NULL)
                goto cleanup;
 
@@ -174,17 +175,17 @@ ldap_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);
+       ptr = slap_strcopy(ptr, ")(");
+       ptr = slap_strcopy(ptr, group_at_name);
+       ptr = slap_strcopy(ptr, "=");
+       ptr = slap_strcopy(ptr, mop_ndn.bv_val);
+       strcpy(ptr, "))");
 
        gattr[0] = "objectclass";
        gattr[1] = NULL;
-       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)
@@ -197,18 +198,11 @@ cleanup:;
                ldap_unbind(ld);
        }
        ch_free(filter);
-#ifdef ENABLE_REWRITE
-       if ( mop_ndn != op_ndn->bv_val ) {
-#endif /* ENABLE_REWRITE */
-               free( mop_ndn );
-#ifdef ENABLE_REWRITE
+       if ( mop_ndn.bv_val != op_ndn->bv_val ) {
+               free( mop_ndn.bv_val );
        }
-       if ( mgr_ndn != gr_ndn->bv_val ) {
-#endif /* ENABLE_REWRITE */
-               free( mgr_ndn );
-#ifdef ENABLE_REWRITE
+       if ( mgr_ndn.bv_val != gr_ndn->bv_val ) {
+               free( mgr_ndn.bv_val );
        }
-#endif /* ENABLE_REWRITE */
        return(rc);
 }
-
index 4b4c6975d6a823f422b8478d8ef0c659d703a432..b41b910fdd3c5947d06b7d614f015decaa64e924 100644 (file)
@@ -144,7 +144,7 @@ conn_free(
 )
 {
        ldap_unbind(lc->ld);
-       if ( lc->bound_dn) free( lc->bound_dn );
+       if ( lc->bound_dn.bv_val) free( lc->bound_dn.bv_val );
        free( lc );
 }
 
@@ -189,7 +189,7 @@ ldap_back_db_destroy(
                }
 #else /* !ENABLE_REWRITE */
                if (li->suffix_massage) {
-                       ldap_value_free( li->suffix_massage );
+                       ber_bvecfree( li->suffix_massage );
                }
 #endif /* !ENABLE_REWRITE */
 
index 547e6b8b6a88f9252a1d250aa8c0ac77a8a386d9..b449a927e411df6e2bd9a5154fd235a99d6b575b 100644 (file)
@@ -61,7 +61,8 @@ ldap_back_modify(
        LDAPMod *mods;
        Modifications *ml;
        int i;
-       char *mdn = NULL, *mapped;
+       char *mapped;
+       struct berval mdn = { 0, NULL };
 
        lc = ldap_back_getconn(li, conn, op);
        if ( !lc || !ldap_back_dobind( lc, op ) ) {
@@ -72,17 +73,17 @@ ldap_back_modify(
         * Rewrite the modify dn, if needed
         */
 #ifdef ENABLE_REWRITE
-       switch ( rewrite_session( li->rwinfo, "modifyDn", dn->bv_val, conn, &mdn ) ) {
+       switch ( rewrite_session( li->rwinfo, "modifyDn", dn->bv_val, conn, &mdn.bv_val ) ) {
        case REWRITE_REGEXEC_OK:
-               if ( mdn == NULL ) {
-                       mdn = ( char * )dn->bv_val;
+               if ( mdn.bv_val == NULL ) {
+                       mdn.bv_val = ( char * )dn->bv_val;
                }
 #ifdef NEW_LOGGING
                LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
-                               "[rw] modifyDn: \"%s\" -> \"%s\"\n", dn->bv_val, mdn ));
+                               "[rw] modifyDn: \"%s\" -> \"%s\"\n", dn->bv_val, mdn.bv_val ));
 #else /* !NEW_LOGGING */
                Debug( LDAP_DEBUG_ARGS, "rw> modifyDn: \"%s\" -> \"%s\"\n%s",
-                               dn->bv_val, mdn, "" );
+                               dn->bv_val, mdn.bv_val, "" );
 #endif /* !NEW_LOGGING */
                break;
                
@@ -97,7 +98,7 @@ ldap_back_modify(
                return( -1 );
        }
 #else /* !ENABLE_REWRITE */
-       mdn = ldap_back_dn_massage( li, ch_strdup( dn->bv_val ), 0 );
+       ldap_back_dn_massage( li, dn, &mdn, 0, 1 );
 #endif /* !ENABLE_REWRITE */
 
        for (i=0, ml=modlist; ml; i++,ml=ml->sml_next)
@@ -140,13 +141,13 @@ ldap_back_modify(
        }
        modv[i] = 0;
 
-       ldap_modify_s( lc->ld, mdn, modv );
+       ldap_modify_s( lc->ld, mdn.bv_val, modv );
 
 cleanup:;
 #ifdef ENABLE_REWRITE
-       if ( mdn != dn->bv_val ) {
+       if ( mdn.bv_val != dn->bv_val ) {
 #endif /* ENABLE_REWRITE */
-               free( mdn );
+               free( mdn.bv_val );
 #ifdef ENABLE_REWRITE
        }
 #endif /* ENABLE_REWRITE */
index cd130894253dde1328f400555787734f14746602..455cbb9eee30c03fffca2e285cf66cc798b69aa6 100644 (file)
@@ -62,7 +62,7 @@ ldap_back_modrdn(
        struct ldapinfo *li = (struct ldapinfo *) be->be_private;
        struct ldapconn *lc;
 
-       char *mdn = NULL, *mnewSuperior = NULL;
+       struct berval mdn = { 0, NULL }, mnewSuperior = { 0, NULL };
 
        lc = ldap_back_getconn( li, conn, op );
        if ( !lc || !ldap_back_dobind(lc, op) ) {
@@ -78,20 +78,20 @@ ldap_back_modrdn(
                 */
 #ifdef ENABLE_REWRITE
                switch ( rewrite_session( li->rwinfo, "newSuperiorDn",
-                                       newSuperior->bv_val, conn, &mnewSuperior ) ) {
+                                       newSuperior->bv_val, conn, &mnewSuperior.bv_val ) ) {
                case REWRITE_REGEXEC_OK:
-                       if ( mnewSuperior == NULL ) {
-                               mnewSuperior = ( char * )newSuperior;
+                       if ( mnewSuperior.bv_val == NULL ) {
+                               mnewSuperior.bv_val = ( char * )newSuperior;
                        }
 #ifdef NEW_LOGGING
                        LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
                                        "[rw] newSuperiorDn:"
                                        " \"%s\" -> \"%s\"\n",
-                                       newSuperior, mnewSuperior ));
+                                       newSuperior, mnewSuperior.bv_val ));
 #else /* !NEW_LOGGING */
                        Debug( LDAP_DEBUG_ARGS, "rw> newSuperiorDn:"
                                        " \"%s\" -> \"%s\"\n%s",
-                                       newSuperior->bv_val, mnewSuperior, "" );
+                                       newSuperior->bv_val, mnewSuperior.bv_val, "" );
 #endif /* !NEW_LOGGING */
                        break;
 
@@ -108,9 +108,8 @@ ldap_back_modrdn(
                        return( -1 );
                }
 #else /* !ENABLE_REWRITE */
-               mnewSuperior = ldap_back_dn_massage( li,
-                               ch_strdup( newSuperior->bv_val ), 0 );
-               if ( mnewSuperior == NULL ) {
+               ldap_back_dn_massage( li, newSuperior, &mnewSuperior, 0, 1 );
+               if ( mnewSuperior.bv_val == NULL ) {
                        return( -1 );
                }
 #endif /* !ENABLE_REWRITE */
@@ -120,17 +119,17 @@ ldap_back_modrdn(
        /*
         * Rewrite the modrdn dn, if required
         */
-       switch ( rewrite_session( li->rwinfo, "modrDn", dn->bv_val, conn, &mdn ) ) {
+       switch ( rewrite_session( li->rwinfo, "modrDn", dn->bv_val, conn, &mdn.bv_val ) ) {
        case REWRITE_REGEXEC_OK:
-               if ( mdn == NULL ) {
-                       mdn = ( char * )dn->bv_val;
+               if ( mdn.bv_val == NULL ) {
+                       mdn.bv_val = ( char * )dn->bv_val;
                }
 #ifdef NEW_LOGGING
                LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
-                               "[rw] modrDn: \"%s\" -> \"%s\"\n", dn->bv_val, mdn ));
+                               "[rw] modrDn: \"%s\" -> \"%s\"\n", dn->bv_val, mdn.bv_val ));
 #else /* !NEW_LOGGING */
                Debug( LDAP_DEBUG_ARGS, "rw> modrDn: \"%s\" -> \"%s\"\n%s",
-                               dn->bv_val, mdn, "" );
+                               dn->bv_val, mdn.bv_val, "" );
 #endif /* !NEW_LOGGING */
                break;
                
@@ -145,24 +144,17 @@ ldap_back_modrdn(
                return( -1 );
        }
 #else /* !ENABLE_REWRITE */
-       mdn = ldap_back_dn_massage( li, ch_strdup( dn->bv_val ), 0 );
+       ldap_back_dn_massage( li, dn, &mdn, 0, 1 );
 #endif /* !ENABLE_REWRITE */
 
-       ldap_rename2_s( lc->ld, mdn, newrdn->bv_val, mnewSuperior, deleteoldrdn );
+       ldap_rename2_s( lc->ld, mdn.bv_val, newrdn->bv_val, mnewSuperior.bv_val, deleteoldrdn );
 
-#ifdef ENABLE_REWRITE
-       if ( mdn != dn->bv_val ) {
-#endif /* ENABLE_REWRITE */
-       free( mdn );
-#ifdef ENABLE_REWRITE
+       if ( mdn.bv_val != dn->bv_val ) {
+               free( mdn.bv_val );
        }
-#endif /* ENABLE_REWRITE */
-       if ( mnewSuperior != NULL
-#ifdef ENABLE_REWRITE
-                       && mnewSuperior != newSuperior->bv_val
-#endif /* ENABLE_REWRITE */
-          ) {
-               free( mnewSuperior );
+       if ( mnewSuperior.bv_val != NULL
+               && mnewSuperior.bv_val != newSuperior->bv_val ) {
+               free( mnewSuperior.bv_val );
        }
        
        return( ldap_back_op_result( lc, op ) );
index 7fdb10973fe82c1e30c5fb2ab896ea3186bd765b..5192b013240c92f18f9dc6e1094cefd56d3b36aa 100644 (file)
@@ -72,7 +72,8 @@ ldap_back_search(
        LDAPMessage             *res, *e;
        int     count, rc = 0, msgid, sres = LDAP_SUCCESS; 
        char *match = NULL, *err = NULL;
-       char *mbase = NULL, *mapped_filter = NULL, **mapped_attrs = NULL;
+       char *mapped_filter = NULL, **mapped_attrs = NULL;
+       struct berval mbase;
 #ifdef ENABLE_REWRITE
        char *mfilter = NULL, *mmatch = NULL;
 #endif /* ENABLE_REWRITE */
@@ -143,18 +144,18 @@ ldap_back_search(
         */
 #ifdef ENABLE_REWRITE
        switch ( rewrite_session( li->rwinfo, "searchBase",
-                               base->bv_val, conn, &mbase ) ) {
+                               base->bv_val, conn, &mbase.bv_val ) ) {
        case REWRITE_REGEXEC_OK:
-               if ( mbase == NULL ) {
-                       mbase = ( char * )base->bv_val;
+               if ( mbase.bv_val == NULL ) {
+                       mbase.bv_val = ( char * )base->bv_val;
                }
 #ifdef NEW_LOGGING
                LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
                                "[rw] searchBase: \"%s\" -> \"%s\"\n%",
-                               base->bv_val, mbase ));
+                               base->bv_val, mbase.bv_val ));
 #else /* !NEW_LOGGING */
                Debug( LDAP_DEBUG_ARGS, "rw> searchBase: \"%s\" -> \"%s\"\n%s",
-                               base->bv_val, mbase, "" );
+                               base->bv_val, mbase.bv_val, "" );
 #endif /* !NEW_LOGGING */
                break;
                
@@ -202,7 +203,7 @@ ldap_back_search(
                goto finish;
        }
 #else /* !ENABLE_REWRITE */
-       mbase = ldap_back_dn_massage( li, ch_strdup( base->bv_val ), 0 );
+       ldap_back_dn_massage( li, base, &mbase, 0, 1 );
 #endif /* !ENABLE_REWRITE */
 
        mapped_filter = ldap_back_map_filter(&li->at_map, &li->oc_map,
@@ -230,7 +231,7 @@ ldap_back_search(
                mapped_attrs[count] = NULL;
        }
 
-       if ((msgid = ldap_search(lc->ld, mbase, scope, mapped_filter, mapped_attrs,
+       if ((msgid = ldap_search(lc->ld, mbase.bv_val, scope, mapped_filter, mapped_attrs,
                attrsonly)) == -1)
        {
 fail:;
@@ -351,13 +352,9 @@ finish:;
        }
 #endif /* !ENABLE_REWRITE */
        
-#ifdef ENABLE_REWRITE
-       if ( mbase != base->bv_val ) {
-#endif /* ENABLE_REWRITE */
-               free( mbase );
-#ifdef ENABLE_REWRITE
+       if ( mbase.bv_val != base->bv_val ) {
+               free( mbase.bv_val );
        }
-#endif /* ENABLE_REWRITE */
        
        return rc;
 }
@@ -378,7 +375,7 @@ ldap_send_entry(
        BerElement *ber = NULL;
        Attribute *attr, **attrp;
        struct berval *dummy = NULL;
-       struct berval *bv;
+       struct berval *bv, bdn;
        const char *text;
 
 #ifdef ENABLE_REWRITE
@@ -417,11 +414,13 @@ ldap_send_entry(
                return;
        }
 #else /* !ENABLE_REWRITE */
-       ent.e_dn = ldap_back_dn_restore( li, ldap_get_dn(lc->ld, e), 0 );
+       ber_str2bv( ldap_get_dn(lc->ld, e), 0, 0, &bdn );
+       ldap_back_dn_massage( li, &bdn, &ent.e_name, 0, 0 );
 #endif /* !ENABLE_REWRITE */
 
-       ent.e_ndn = ch_strdup( ent.e_dn );
-       (void) dn_normalize( ent.e_ndn );
+       bv = NULL;
+       dnNormalize( NULL, &ent.e_name, &bv );
+       ent.e_nname = *bv;
        ent.e_id = 0;
        ent.e_attrs = 0;
        ent.e_private = 0;
@@ -474,8 +473,7 @@ ldap_send_entry(
                                        i--;
                                } else if ( mapped != bv->bv_val ) {
                                        ch_free(bv->bv_val);
-                                       bv->bv_val = ch_strdup( mapped );
-                                       bv->bv_len = strlen( mapped );
+                                       ber_str2bv( mapped, 0, 1, bv );
                                }
                        }
 
index de771055e485843e636194286896dd775e272e52..562b547bae892cc315780f97889b845613c9bc3b 100644 (file)
  * 
  * Aliases the suffix; based on suffix_alias (servers/slapd/suffixalias.c).
  */
-char *
+void
 ldap_back_dn_massage(
        struct ldapinfo *li,
-       char *dn,
-       int normalized
+       struct berval *dn,
+       struct berval *res,
+       int normalized,
+       int tofrom
 )
 {
-       int     i, dnLength;
+       int     i, src, dst;
 
         if ( dn == NULL ) {
-               return NULL;
+               res->bv_val = NULL;
+               res->bv_len = 0;
+               return;
        }
         if ( li == NULL ) {
-               return dn;
+               *res = *dn;
+               return;
        }
 
-        dnLength = strlen ( dn );
+       if ( tofrom ) {
+               src = 0 + normalized;
+               dst = 2 + normalized;
+       } else {
+               src = 2 + normalized;
+               dst = 0 + normalized;
+       }
 
         for ( i = 0;
                 li->suffix_massage != NULL && li->suffix_massage[i] != NULL;
                 i += 4 ) {
-                int aliasLength = strlen( li->suffix_massage[i+normalized] );
-                int diff = dnLength - aliasLength;
+                int aliasLength = li->suffix_massage[i+src]->bv_len;
+                int diff = dn->bv_len - aliasLength;
 
                 if ( diff < 0 ) {
                         /* alias is longer than dn */
                         continue;
                                                                                                } else if ( diff > 0 ) {
-                        if ( normalized && ( ! DN_SEPARATOR(dn[diff-1]) ) ) {
+                        if ( normalized && ( ! DN_SEPARATOR(dn->bv_val[diff-1]) ) ) {
                                 /* boundary is not at a DN separator */
                                 continue;
                        }
@@ -80,81 +91,19 @@ ldap_back_dn_massage(
                         /* XXX or an escaped separator... oh well */
                 }
 
-                if ( !strcmp( li->suffix_massage[i+normalized], &dn[diff] ) ) {
-                        char *oldDN = dn;
-                        dn = ch_malloc( diff + strlen( li->suffix_massage[i+2+normalized] ) + 1 );
-                        strncpy( dn, oldDN, diff );
-                        strcpy( &dn[diff], li->suffix_massage[i+2+normalized] );
+                if ( !strcmp( li->suffix_massage[i+src]->bv_val, &dn->bv_val[diff] ) ) {
+                       res->bv_len = diff + li->suffix_massage[i+dst]->bv_len;
+                        res->bv_val = ch_malloc( res->bv_len + 1 );
+                        strncpy( res->bv_val, dn->bv_val, diff );
+                        strcpy( &res->bv_val[diff], li->suffix_massage[i+dst]->bv_val );
                         Debug( LDAP_DEBUG_ARGS,
                                 "ldap_back_dn_massage:"
                                " converted \"%s\" to \"%s\"\n",
-                                oldDN, dn, 0 );
-                        free( oldDN );
+                                dn->bv_val, res->bv_val, 0 );
                         break;
                 }
         }
 
-        return dn;
-}
-
-/*
- * ldap_back_dn_restore
- * 
- * Restores the original suffix;
- * based on suffix_alias (servers/slapd/suffixalias.c).
- */
-char *
-ldap_back_dn_restore(
-        struct ldapinfo *li,
-        char *dn,
-        int normalized
-       )
-{
-        int     i, dnLength;
-
-        if ( dn == NULL ) {
-                return NULL;
-        }
-        if ( li == NULL ) {
-                return dn;
-        }
-
-        dnLength = strlen ( dn );
-
-        for ( i = 0;
-                li->suffix_massage != NULL && li->suffix_massage[i] != NULL;
-                i += 4 ) {
-                int aliasLength = strlen( li->suffix_massage[i+2+normalized] );
-                int diff = dnLength - aliasLength;
-
-                if ( diff < 0 ) {
-                        /* alias is longer than dn */
-                        continue;
-
-                } else if ( diff > 0 ) {
-                        if ( normalized && ( ! DN_SEPARATOR(dn[diff-1]) ) ) {
-                                /* boundary is not at a DN separator */
-                                continue;
-                        }
-                        /* At a DN Separator */
-                        /* XXX or an escaped separator... oh well */
-                }
-
-                if ( !strcmp( li->suffix_massage[i+2+normalized], &dn[diff] ) ) {
-                        char *oldDN = dn;
-                        dn = ch_malloc( diff + strlen( li->suffix_massage[i+normalized] ) + 1 );
-                        strncpy( dn, oldDN, diff );
-                        strcpy( &dn[diff], li->suffix_massage[i+normalized] );
-                       Debug( LDAP_DEBUG_ARGS,
-                               "ldap_back_dn_restore:"
-                                " converted \"%s\" to \"%s\"\n",
-                                oldDN, dn, 0 );
-                        free( oldDN );
-                        break;
-                }
-        }
-
-        return dn;
+        return;
 }
 #endif /* !ENABLE_REWRITE */
-
index 80b3981867da1a88903552decd632f19c5eaa7f5..0918cabc5845d0abfe5af5e1853199323e7ae225 100644 (file)
@@ -88,8 +88,8 @@ ldap_back_conn_destroy(
                 * in a segmentation fault
                 */
                ldap_unbind(lc->ld);
-               if ( lc->bound_dn ) {
-                       free( lc->bound_dn );
+               if ( lc->bound_dn.bv_val ) {
+                       free( lc->bound_dn.bv_val );
                }
                free( lc );
        }