From 3bfab4699e19d4d7595c129b89d0dd2048e812bc Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Wed, 16 Jan 2002 03:01:19 +0000 Subject: [PATCH] Remove last uses of dn_validate() --- servers/slapd/dn.c | 39 +-------------- servers/slapd/referral.c | 104 +++++++++++++++++++++------------------ 2 files changed, 57 insertions(+), 86 deletions(-) diff --git a/servers/slapd/dn.c b/servers/slapd/dn.c index c90dffaf6d..47e69d80f4 100644 --- a/servers/slapd/dn.c +++ b/servers/slapd/dn.c @@ -556,7 +556,6 @@ dnMatch( #ifdef SLAP_DN_MIGRATION /* * these routines are provided for migration purposes only! - * dn_validate is deprecated in favor of dnValidate * dn_normalize is deprecated in favor of dnNormalize * strcmp/strcasecmp for DNs is deprecated in favor of dnMatch * @@ -564,41 +563,6 @@ dnMatch( * replacement functions. */ -/* - * dn_validate - validate and compress dn. the dn is - * compressed in place are returned if valid. - * Deprecated in favor of dnValidate() - */ -char * -dn_validate( char *dn ) -{ - struct berval val; - struct berval *pretty = NULL; - int rc; - - if ( dn == NULL || dn[0] == '\0' ) { - return dn; - } - - val.bv_val = dn; - val.bv_len = strlen( dn ); - - rc = dnPretty( NULL, &val, &pretty ); - if ( rc != LDAP_SUCCESS ) { - return NULL; - } - - if ( val.bv_len < pretty->bv_len ) { - ber_bvfree( pretty ); - return NULL; - } - - AC_MEMCPY( dn, pretty->bv_val, pretty->bv_len + 1 ); - ber_bvfree( pretty ); - - return dn; -} - /* * dn_normalize - put dn into a canonical form suitable for storing * in a hash database. this involves normalizing the case as well as @@ -703,6 +667,8 @@ dn_parent( return ( char * )pdn; } +#endif /* SLAP_DN_MIGRATION */ + int dnExtractRdn( @@ -860,7 +826,6 @@ build_new_dn( struct berval * new_dn, strcpy( ptr, parent_dn->bv_val ); } -#endif /* SLAP_DN_MIGRATION */ /* * dnIsSuffix - tells whether suffix is a suffix of dn. diff --git a/servers/slapd/referral.c b/servers/slapd/referral.c index 57e5d2de13..1293c32a35 100644 --- a/servers/slapd/referral.c +++ b/servers/slapd/referral.c @@ -30,10 +30,11 @@ static char * referral_dn_muck( const char * baseDN, const char * targetDN ) { - char *tmp; - char *nrefDN = NULL; - char *nbaseDN = NULL; - char *ntargetDN = NULL; + int rc; + struct berval bvin; + struct berval nrefDN = { 0, NULL }; + struct berval nbaseDN = { 0, NULL }; + struct berval ntargetDN = { 0, NULL }; if( !baseDN ) { /* no base, return target */ @@ -41,10 +42,12 @@ static char * referral_dn_muck( } if( refDN ) { - nrefDN = dn_validate( tmp = ch_strdup( refDN ) ); - if( !nrefDN ) { + bvin.bv_val = (char *)refDN; + bvin.bv_len = strlen( refDN ); + + rc = dnPretty2( NULL, &bvin, &nrefDN ); + if( rc != LDAP_SUCCESS ) { /* Invalid refDN */ - ch_free( tmp ); return NULL; } } @@ -54,71 +57,74 @@ static char * referral_dn_muck( * if refDN present return refDN * else return baseDN */ - return nrefDN ? nrefDN : ch_strdup( baseDN ); + return nrefDN.bv_len ? nrefDN.bv_val : ch_strdup( baseDN ); } - ntargetDN = dn_validate( tmp = ch_strdup( targetDN ) ); - if( !ntargetDN ) { - ch_free( tmp ); - ch_free( nrefDN ); + bvin.bv_val = (char *)targetDN; + bvin.bv_len = strlen( targetDN ); + + rc = dnPretty2( NULL, &bvin, &ntargetDN ); + if( rc != LDAP_SUCCESS ) { + /* Invalid targetDN */ + ch_free( nrefDN.bv_val ); return NULL; } - if( nrefDN ) { - nbaseDN = dn_validate( tmp = ch_strdup( baseDN ) ); - if( !nbaseDN ) { + if( nrefDN.bv_len ) { + bvin.bv_val = (char *)baseDN; + bvin.bv_len = strlen( baseDN ); + + rc = dnPretty2( NULL, &bvin, &nbaseDN ); + if( rc != LDAP_SUCCESS ) { /* Invalid baseDN */ - ch_free( ntargetDN ); - ch_free( nrefDN ); - ch_free( tmp ); + ch_free( nrefDN.bv_val ); + ch_free( ntargetDN.bv_val ); return NULL; } - if( strcasecmp( nbaseDN, nrefDN ) == 0 ) { - ch_free( nrefDN ); - ch_free( nbaseDN ); - return ntargetDN; + if( dn_match( &nbaseDN, &nrefDN ) == 0 ) { + ch_free( nrefDN.bv_val ); + ch_free( nbaseDN.bv_val ); + return ntargetDN.bv_val; } { - /* - * FIXME: string based mucking - */ - char *muck; - size_t reflen, baselen, targetlen, mucklen; - - reflen = strlen( nrefDN ); - baselen = strlen( nbaseDN ); - targetlen = strlen( ntargetDN ); - - if( targetlen < baselen ) { - ch_free( nrefDN ); - ch_free( nbaseDN ); - return ntargetDN; + struct berval muck; + + if( ntargetDN.bv_len < nbaseDN.bv_len ) { + ch_free( nrefDN.bv_val ); + ch_free( nbaseDN.bv_val ); + return ntargetDN.bv_val; } - if( strcasecmp( &ntargetDN[targetlen-baselen], nbaseDN ) ) { + rc = strcasecmp( + &ntargetDN.bv_val[ntargetDN.bv_len-nbaseDN.bv_len], + nbaseDN.bv_val ); + if( rc ) { /* target not subordinate to base */ - ch_free( nrefDN ); - ch_free( nbaseDN ); - return ntargetDN; + ch_free( nrefDN.bv_val ); + ch_free( nbaseDN.bv_val ); + return ntargetDN.bv_val; } - mucklen = targetlen + reflen - baselen; - muck = ch_malloc( 1 + mucklen ); + muck.bv_len = ntargetDN.bv_len + nrefDN.bv_len - nbaseDN.bv_len; + muck.bv_val = ch_malloc( muck.bv_len + 1 ); - strncpy( muck, ntargetDN, targetlen-baselen ); - strcpy( &muck[targetlen-baselen], nrefDN ); + strncpy( muck.bv_val, ntargetDN.bv_val, + ntargetDN.bv_len-nbaseDN.bv_len ); + strcpy( &muck.bv_val[ntargetDN.bv_len-nbaseDN.bv_len], + nrefDN.bv_val ); - ch_free( nrefDN ); - ch_free( nbaseDN ); - ch_free( ntargetDN ); + ch_free( nrefDN.bv_val ); + ch_free( nbaseDN.bv_val ); + ch_free( ntargetDN.bv_val ); - return muck; + return muck.bv_val; } } - return ntargetDN; + ch_free( nrefDN.bv_val ); + return ntargetDN.bv_val; } -- 2.39.5