#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
*
* 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
return ( char * )pdn;
}
+#endif /* SLAP_DN_MIGRATION */
+
int
dnExtractRdn(
strcpy( ptr, parent_dn->bv_val );
}
-#endif /* SLAP_DN_MIGRATION */
/*
* dnIsSuffix - tells whether suffix is a suffix of dn.
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 */
}
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;
}
}
* 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;
}