From: Howard Chu Date: Mon, 24 Dec 2001 16:29:18 +0000 (+0000) Subject: Changed suffix_alias() to use struct berval * in-place. X-Git-Tag: LDBM_PRE_GIANT_RWLOCK~549 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=70194f9ad68109fed8ce538f902d6f1c549755c5;p=openldap Changed suffix_alias() to use struct berval * in-place. --- diff --git a/servers/slapd/bind.c b/servers/slapd/bind.c index 0a2cb3f3f9..da436aa3c5 100644 --- a/servers/slapd/bind.c +++ b/servers/slapd/bind.c @@ -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, diff --git a/servers/slapd/compare.c b/servers/slapd/compare.c index 686457b412..fda1f04518 100644 --- a/servers/slapd/compare.c +++ b/servers/slapd/compare.c @@ -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 ); diff --git a/servers/slapd/delete.c b/servers/slapd/delete.c index 9272c44a27..3acbd05c48 100644 --- a/servers/slapd/delete.c +++ b/servers/slapd/delete.c @@ -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) diff --git a/servers/slapd/modify.c b/servers/slapd/modify.c index 2e43ae3cd0..58e2d9acb4 100644 --- a/servers/slapd/modify.c +++ b/servers/slapd/modify.c @@ -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) diff --git a/servers/slapd/modrdn.c b/servers/slapd/modrdn.c index 45431bad52..e1f5e2129f 100644 --- a/servers/slapd/modrdn.c +++ b/servers/slapd/modrdn.c @@ -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; } diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index d61d63ea73..dc338a64b4 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -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 diff --git a/servers/slapd/repl.c b/servers/slapd/repl.c index 92b1f44275..b6e35f1b84 100644 --- a/servers/slapd/repl.c +++ b/servers/slapd/repl.c @@ -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 ); diff --git a/servers/slapd/saslauthz.c b/servers/slapd/saslauthz.c index a487139a47..1b00a6923b 100644 --- a/servers/slapd/saslauthz.c +++ b/servers/slapd/saslauthz.c @@ -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(®, searchbase, REG_EXTENDED|REG_ICASE|REG_NOSUB); + dn_normalize( searchbase.bv_val ); + rc = regcomp(®, searchbase.bv_val, REG_EXTENDED|REG_ICASE|REG_NOSUB); if ( rc == 0 ) { rc = regexec(®, assertDN, 0, NULL, 0); regfree( ® ); @@ -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 ); diff --git a/servers/slapd/search.c b/servers/slapd/search.c index 803fe40e75..6d07293a95 100644 --- a/servers/slapd/search.c +++ b/servers/slapd/search.c @@ -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 ) { diff --git a/servers/slapd/suffixalias.c b/servers/slapd/suffixalias.c index 7c79c16581..dd6aa3a209 100644 --- a/servers/slapd/suffixalias.c +++ b/servers/slapd/suffixalias.c @@ -28,16 +28,16 @@ * 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; }