]> git.sur5r.net Git - openldap/commitdiff
Changed suffix_alias() to use struct berval * in-place.
authorHoward Chu <hyc@openldap.org>
Mon, 24 Dec 2001 16:29:18 +0000 (16:29 +0000)
committerHoward Chu <hyc@openldap.org>
Mon, 24 Dec 2001 16:29:18 +0000 (16:29 +0000)
servers/slapd/bind.c
servers/slapd/compare.c
servers/slapd/delete.c
servers/slapd/modify.c
servers/slapd/modrdn.c
servers/slapd/proto-slap.h
servers/slapd/repl.c
servers/slapd/saslauthz.c
servers/slapd/search.c
servers/slapd/suffixalias.c

index 0a2cb3f3f9970b11591ddcb0a9403eef4605add8..da436aa3c561ff0288e1372ff627eb367f378f56 100644 (file)
@@ -491,8 +491,7 @@ do_bind(
                char *edn = NULL;
 
                /* deref suffix alias if appropriate */
-               ndn->bv_val = suffix_alias( be, ndn->bv_val );
-               ndn->bv_len = strlen( ndn->bv_val );
+               suffix_alias( be, ndn );
 
                ret = (*be->be_bind)( be, conn, op,
                        pdn->bv_val, ndn->bv_val,
index 686457b4120ba1577f7bf5b9eeb3a79b555cba42..fda1f045183bc77b6da0a4089bff48c18eecb804 100644 (file)
@@ -281,8 +281,7 @@ do_compare(
 
 
        /* deref suffix alias if appropriate */
-       ndn->bv_val = suffix_alias( be, ndn->bv_val );
-       ndn->bv_len = strlen( ndn->bv_val );
+       suffix_alias( be, ndn );
 
        if ( be->be_compare ) {
                (*be->be_compare)( be, conn, op, pdn->bv_val, ndn->bv_val, &ava );
index 9272c44a2796d191f90fdfc9d6f59fed2496c052..3acbd05c488f89cd3eb631edbd29f7ea9d09e3b0 100644 (file)
@@ -169,8 +169,7 @@ do_delete(
        }
 
        /* deref suffix alias if appropriate */
-       ndn->bv_val = suffix_alias( be, ndn->bv_val );
-       ndn->bv_len = strlen( ndn->bv_val );
+       suffix_alias( be, ndn );
 
        /*
         * do the delete if 1 && (2 || 3)
index 2e43ae3cd05477807699b6301960d01e77ff3c32..58e2d9acb4996f5781981bcf56be1bb39f75bc27 100644 (file)
@@ -323,8 +323,7 @@ do_modify(
        }
 
        /* deref suffix alias if appropriate */
-       ndn->bv_val = suffix_alias( be, ndn->bv_val );
-       ndn->bv_len = strlen( ndn->bv_val );
+       suffix_alias( be, ndn );
 
        /*
         * do the modify if 1 && (2 || 3)
index 45431bad5220840b7da0056ad1fc6386b0a8617e..e1f5e2129f3b2b90280bfdfbf9b5b19267556892 100644 (file)
@@ -49,7 +49,7 @@ do_modrdn(
        struct berval newSuperior = { 0, NULL };
        ber_int_t       deloldrdn;
 
-       char    *ndn = NULL;
+       struct berval *ndn;
        char    *nnewSuperior = NULL;
 
        Backend *be;
@@ -190,9 +190,9 @@ do_modrdn(
                goto cleanup;
        } 
 
-       ndn = ch_strdup( dn.bv_val );
+       rc = dnNormalize( NULL, &dn, &ndn );
 
-       if( dn_normalize( ndn ) == NULL ) {
+       if( rc != LDAP_SUCCESS ) {
 #ifdef NEW_LOGGING
                LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
                        "do_modrdn: invalid dn (%s)\n", dn.bv_val ));
@@ -220,7 +220,7 @@ do_modrdn(
                goto cleanup;
        }
 
-       if( *ndn == '\0' ) {
+       if( ndn->bv_len == 0 ) {
 #ifdef NEW_LOGGING
                LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
                           "do_modrdn:  attempt to modify root DSE.\n" ));
@@ -233,7 +233,7 @@ do_modrdn(
                goto cleanup;
 
 #ifdef SLAPD_SCHEMA_DN
-       } else if ( strcasecmp( ndn, SLAPD_SCHEMA_DN ) == 0 ) {
+       } else if ( strcasecmp( ndn->bv_val, SLAPD_SCHEMA_DN ) == 0 ) {
 #ifdef NEW_LOGGING
                LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
                        "do_modrdn: attempt to modify subschema subentry\n" ));
@@ -257,7 +257,7 @@ do_modrdn(
         * appropriate one, or send a referral to our "referral server"
         * if we don't hold it.
         */
-       if ( (be = select_backend( ndn, manageDSAit, 0 )) == NULL ) {
+       if ( (be = select_backend( ndn->bv_val, manageDSAit, 0 )) == NULL ) {
                struct berval **ref = referral_rewrite( default_referral,
                        NULL, dn.bv_val, LDAP_SCOPE_DEFAULT );
 
@@ -277,7 +277,7 @@ do_modrdn(
        }
 
        /* check for referrals */
-       rc = backend_check_referrals( be, conn, op, dn.bv_val, ndn );
+       rc = backend_check_referrals( be, conn, op, dn.bv_val, ndn->bv_val );
        if ( rc != LDAP_SUCCESS ) {
                goto cleanup;
        }
@@ -297,13 +297,10 @@ do_modrdn(
 
                        goto cleanup;
                }
-
-               /* deref suffix alias if appropriate */
-               nnewSuperior = suffix_alias( be, nnewSuperior );
        }
 
        /* deref suffix alias if appropriate */
-       ndn = suffix_alias( be, ndn );
+       suffix_alias( be, ndn );
 
        /*
         * do the add if 1 && (2 || 3)
@@ -318,7 +315,7 @@ do_modrdn(
                if ( be->be_update_ndn == NULL || repl_user )
 #endif
                {
-                       if ( (*be->be_modrdn)( be, conn, op, dn.bv_val, ndn,
+                       if ( (*be->be_modrdn)( be, conn, op, dn.bv_val, ndn->bv_val,
                                newrdn.bv_val, deloldrdn, newSuperior.bv_val ) == 0
 #ifdef SLAPD_MULTIMASTER
                                && ( be->be_update_ndn == NULL || !repl_user )
@@ -329,7 +326,7 @@ do_modrdn(
                                moddn.deloldrdn = deloldrdn;
                                moddn.newsup = newSuperior.bv_val;
 
-                               replog( be, op, dn.bv_val, ndn, &moddn );
+                               replog( be, op, dn.bv_val, ndn->bv_val, &moddn );
                        }
 #ifndef SLAPD_MULTIMASTER
                } else {
@@ -355,7 +352,7 @@ cleanup:
        free( newrdn.bv_val );  
        free( newSuperior.bv_val );
 
-       if( ndn != NULL ) free( ndn );
+       if( ndn != NULL ) ber_bvfree( ndn );
        if ( nnewSuperior != NULL ) free( nnewSuperior );
        return rc;
 }
index d61d63ea73f0be5b4b6a47a512ae0c5dd0cb2a70..dc338a64b45144f84a997ea997640f3a3a4d74ab 100644 (file)
@@ -816,7 +816,7 @@ LDAP_SLAPD_F (Filter *) str2filter LDAP_P(( const char *str ));
 /*
  * suffixalias.c
  */
-LDAP_SLAPD_F (char *) suffix_alias LDAP_P(( Backend *be, char *ndn ));
+LDAP_SLAPD_F (void) suffix_alias LDAP_P(( Backend *be, struct berval *ndn ));
 
 /*
  * value.c
index 92b1f442758a9ad3c96d13f4a2d12e35a0f38729..b6e35f1b8429ca8e1bbe97dc51006c8192ec591a 100644 (file)
@@ -169,7 +169,7 @@ replog(
                            ml->sml_bvalues[i] != NULL; i++ ) {
                                char    *buf, *bufp;
 
-                               len = strlen( type );
+                               len = ml->sml_desc->ad_cname.bv_len;
                                len = LDIF_SIZE_NEEDED( len,
                                    ml->sml_bvalues[i]->bv_len ) + 1;
                                buf = (char *) ch_malloc( len );
index a487139a4773e3b1519f3a47356799b9138d33ae..1b00a6923b4eeabcd7d5dee0ae9412d5a3938287 100644 (file)
@@ -296,7 +296,8 @@ char *slap_sasl_regexp( char *saslname )
 
 char *slap_sasl2dn( char *saslname )
 {
-       char *uri=NULL, *searchbase=NULL, *DN=NULL;
+       char *uri=NULL, *DN=NULL;
+       struct berval searchbase = {0, NULL};
        int rc, scope;
        Backend *be;
        Filter *filter=NULL;
@@ -319,13 +320,14 @@ char *slap_sasl2dn( char *saslname )
        if( uri == NULL )
                goto FINISHED;
 
-       rc = slap_parseURI( uri, &searchbase, &scope, &filter );
+       rc = slap_parseURI( uri, &searchbase.bv_val, &scope, &filter );
        if( rc )
                goto FINISHED;
 
+       searchbase.bv_len = strlen( searchbase.bv_val );
        /* Massive shortcut: search scope == base */
        if( scope == LDAP_SCOPE_BASE ) {
-               DN = ch_strdup( searchbase );
+               DN = ch_strdup( searchbase.bv_val );
                goto FINISHED;
        }
 
@@ -334,24 +336,24 @@ char *slap_sasl2dn( char *saslname )
 #ifdef NEW_LOGGING
        LDAP_LOG(( "sasl", LDAP_LEVEL_DETAIL1,
                   "slap_sasl2dn: performing internal search (base=%s, scope=%d)\n",
-                  searchbase, scope ));
+                  searchbase.bv_val, scope ));
 #else
        Debug( LDAP_DEBUG_TRACE,
           "slap_sasl2dn: performing internal search (base=%s, scope=%d)\n",
-          searchbase, scope, 0 );
+          searchbase.bv_val, scope, 0 );
 #endif
 
 
-       be = select_backend( searchbase, 0, 1 );
+       be = select_backend( searchbase.bv_val, 0, 1 );
        if(( be == NULL ) || ( be->be_search == NULL))
                goto FINISHED;
-       searchbase = suffix_alias( be, searchbase );
+       suffix_alias( be, &searchbase );
 
        rc = connection_internal_open( &conn, &client, saslname );
        if( rc != LDAP_SUCCESS )
                goto FINISHED;
 
-       (*be->be_search)( be, conn, conn->c_ops, /*base=*/NULL, searchbase,
+       (*be->be_search)( be, conn, conn->c_ops, /*base=*/NULL, searchbase.bv_val,
           scope, /*deref=*/1, /*sizelimit=*/1, /*time=*/0, filter, /*fstr=*/NULL,
           /*attrs=*/NULL, /*attrsonly=*/0 );
 
@@ -378,7 +380,7 @@ char *slap_sasl2dn( char *saslname )
        DN = ldap_get_dn( client, msg );
 
 FINISHED:
-       if( searchbase ) ch_free( searchbase );
+       if( searchbase.bv_len ) ch_free( searchbase.bv_val );
        if( filter ) filter_free( filter );
        if( uri ) ch_free( uri );
        if( conn ) connection_internal_close( conn );
@@ -412,7 +414,8 @@ FINISHED:
 static
 int slap_sasl_match( char *rule, char *assertDN, char *authc )
 {
-       char *searchbase=NULL, *dn=NULL;
+       char *dn=NULL;
+       struct berval searchbase = {0, NULL};
        int rc, scope;
        Backend *be;
        Filter *filter=NULL;
@@ -431,14 +434,15 @@ int slap_sasl_match( char *rule, char *assertDN, char *authc )
 #endif
 
 
-       rc = slap_parseURI( rule, &searchbase, &scope, &filter );
+       rc = slap_parseURI( rule, &searchbase.bv_val, &scope, &filter );
        if( rc != LDAP_SUCCESS )
                goto CONCLUDED;
 
+       searchbase.bv_len = strlen( searchbase.bv_val );
        /* Massive shortcut: search scope == base */
        if( scope == LDAP_SCOPE_BASE ) {
-               dn_normalize( searchbase );
-               rc = regcomp(&reg, searchbase, REG_EXTENDED|REG_ICASE|REG_NOSUB);
+               dn_normalize( searchbase.bv_val );
+               rc = regcomp(&reg, searchbase.bv_val, REG_EXTENDED|REG_ICASE|REG_NOSUB);
                if ( rc == 0 ) {
                        rc = regexec(&reg, assertDN, 0, NULL, 0);
                        regfree( &reg );
@@ -455,27 +459,27 @@ int slap_sasl_match( char *rule, char *assertDN, char *authc )
 #ifdef NEW_LOGGING
        LDAP_LOG(( "sasl", LDAP_LEVEL_DETAIL1,
                   "slap_sasl_match: performing internal search (base=%s, scope=%d)\n",
-                  searchbase, scope ));
+                  searchbase.bv_val, scope ));
 #else
        Debug( LDAP_DEBUG_TRACE,
           "slap_sasl_match: performing internal search (base=%s, scope=%d)\n",
-          searchbase, scope, 0 );
+          searchbase.bv_val, scope, 0 );
 #endif
 
 
-       be = select_backend( searchbase, 0, 1 );
+       be = select_backend( searchbase.bv_val, 0, 1 );
        if(( be == NULL ) || ( be->be_search == NULL)) {
                rc = LDAP_INAPPROPRIATE_AUTH;
                goto CONCLUDED;
        }
-       searchbase = suffix_alias( be, searchbase );
+       suffix_alias( be, &searchbase );
 
        /* Make an internal connection on which to run the search */
        rc = connection_internal_open( &conn, &client, authc );
        if( rc != LDAP_SUCCESS )
                goto CONCLUDED;
 
-       (*be->be_search)( be, conn, conn->c_ops, /*base=*/NULL, searchbase,
+       (*be->be_search)( be, conn, conn->c_ops, /*base=*/NULL, searchbase.bv_val,
           scope, /*deref=*/1, /*sizelimit=*/0, /*time=*/0, filter, /*fstr=*/NULL,
           /*attrs=*/NULL, /*attrsonly=*/0 );
 
@@ -501,7 +505,7 @@ int slap_sasl_match( char *rule, char *assertDN, char *authc )
        rc = LDAP_INAPPROPRIATE_AUTH;
 
 CONCLUDED:
-       if( searchbase ) ch_free( searchbase );
+       if( searchbase.bv_len ) ch_free( searchbase.bv_val );
        if( filter ) filter_free( filter );
        if( conn ) connection_internal_close( conn );
        if( res ) ldap_msgfree( res );
index 803fe40e75a1a29c48a91b2d7ffc85ccc4a39c91..6d07293a95130e63f92edec8fb7a445612fcca42 100644 (file)
@@ -322,8 +322,7 @@ do_search(
        }
 
        /* deref the base if needed */
-       nbase->bv_val = suffix_alias( be, nbase->bv_val );
-       nbase->bv_len = strlen( nbase->bv_val );
+       suffix_alias( be, nbase );
 
        /* actually do the search and send the result(s) */
        if ( be->be_search ) {
index 7c79c16581448dac1c948202c67f003c7e61e876..dd6aa3a209851e6310fe05a4ec4161a7d8b81d28 100644 (file)
  * given a normalized uppercased dn (or root part),
  * return an aliased dn if any of the alias suffixes match
  */
-char *suffix_alias(
+void suffix_alias(
        Backend *be,
-       char *dn )
+       struct berval *dn )
 {
        int     i, dnLength;
 
-       if(dn == NULL) return NULL;
-       if(be == NULL) return dn;
+       if(dn == NULL || be == NULL || dn->bv_len == 0)
+               return;
 
-       dnLength = strlen ( dn );
+       dnLength = dn->bv_len;
 
        for ( i = 0;
                be->be_suffixAlias != NULL && be->be_suffixAlias[i] != NULL;
@@ -50,7 +50,7 @@ char *suffix_alias(
                        /* alias is longer than dn */
                        continue;
                } else if ( diff > 0 ) {
-                       if ( ! DN_SEPARATOR(dn[diff-1]) ) {
+                       if ( ! DN_SEPARATOR(dn->bv_val[diff-1]) ) {
                                /* boundary is not at a DN separator */
                                continue;
                        }
@@ -58,25 +58,24 @@ char *suffix_alias(
                        /* XXX or an escaped separator... oh well */
                }
 
-               if (!strcmp(be->be_suffixAlias[i]->bv_val, &dn[diff])) {
-                       char *oldDN = dn;
-                       dn = ch_malloc( diff + be->be_suffixAlias[i+1]->bv_len + 1 );
-                       strncpy( dn, oldDN, diff );
-                       strcpy( &dn[diff], be->be_suffixAlias[i+1]->bv_val );
+               if (!strcmp(be->be_suffixAlias[i]->bv_val, &dn->bv_val[diff])) {
+                       char *oldDN = dn->bv_val;
+                       dn->bv_len = diff + be->be_suffixAlias[i+1]->bv_len;
+                       dn->bv_val = ch_malloc( dn->bv_len + 1 );
+                       strncpy( dn->bv_val, oldDN, diff );
+                       strcpy( &dn->bv_val[diff], be->be_suffixAlias[i+1]->bv_val );
 #ifdef NEW_LOGGING
                        LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
                                   "suffix_alias: converted \"%s\" to \"%s\"\n",
-                                  oldDN, dn ));
+                                  oldDN, dn->bv_val ));
 #else
                        Debug( LDAP_DEBUG_ARGS,
                                "suffix_alias: converted \"%s\" to \"%s\"\n",
-                               oldDN, dn, 0);
+                               oldDN, dn->bv_val, 0);
 #endif
 
                        free (oldDN);
                        break;
                }
        }
-
-       return dn;
 }