/* dn.c - routines for dealing with distinguished names */
/* $OpenLDAP$ */
/*
- * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
assert( dn );
- for ( iRDN = 0; dn[ iRDN ]; iRDN++ ) {
- LDAPRDN *rdn = dn[ iRDN ][ 0 ];
+ for ( iRDN = 0; dn[ 0 ][ iRDN ]; iRDN++ ) {
+ LDAPRDN *rdn = dn[ 0 ][ iRDN ];
int iAVA;
assert( rdn );
- for ( iAVA = 0; rdn[ iAVA ]; iAVA++ ) {
- LDAPAVA *ava = rdn[ iAVA ][ 0 ];
+ for ( iAVA = 0; rdn[ 0 ][ iAVA ]; iAVA++ ) {
+ LDAPAVA *ava = rdn[ 0 ][ iAVA ];
AttributeDescription *ad;
slap_syntax_validate_func *validate = NULL;
/*
* Replace attr oid/name with the canonical name
*/
- free( ava->la_attr.bv_val );
- ber_dupbv( &ava->la_attr, &ad->ad_cname );
+ ava->la_attr = ad->ad_cname;
validate = ad->ad_type->sat_syntax->ssyn_validate;
AVA_Sort( LDAPRDN *rdn, int iAVA )
{
int i;
- LDAPAVA *ava_in = rdn[ iAVA ][ 0 ];
+ LDAPAVA *ava_in = rdn[ 0 ][ iAVA ];
assert( rdn );
assert( ava_in );
for ( i = 0; i < iAVA; i++ ) {
- LDAPAVA *ava = rdn[ i ][ 0 ];
+ LDAPAVA *ava = rdn[ 0 ][ i ];
int a, j;
assert( ava );
return;
}
- ava = rdn[ i ][ 0 ];
+ ava = rdn[ 0 ][ i ];
a = strcmp( ava_in->la_value.bv_val,
ava->la_value.bv_val );
}
* move ahead
*/
for ( j = iAVA; j > i; j-- ) {
- rdn[ j ][ 0 ] = rdn[ j - 1 ][ 0 ];
+ rdn[ 0 ][ j ] = rdn[ 0 ][ j - 1 ];
}
- rdn[ i ][ 0 ] = ava_in;
+ rdn[ 0 ][ i ] = ava_in;
return;
}
assert( dn );
- for ( iRDN = 0; dn[ iRDN ]; iRDN++ ) {
- LDAPRDN *rdn = dn[ iRDN ][ 0 ];
+ for ( iRDN = 0; dn[ 0 ][ iRDN ]; iRDN++ ) {
+ LDAPRDN *rdn = dn[ 0 ][ iRDN ];
int iAVA;
assert( rdn );
- for ( iAVA = 0; rdn[ iAVA ]; iAVA++ ) {
- LDAPAVA *ava = rdn[ iAVA ][ 0 ];
+ for ( iAVA = 0; rdn[ 0 ][ iAVA ]; iAVA++ ) {
+ LDAPAVA *ava = rdn[ 0 ][ iAVA ];
AttributeDescription *ad;
slap_syntax_transform_func *transf = NULL;
MatchingRule *mr;
- struct berval *bv = NULL;
+ struct berval bv = { 0, NULL };
+ int do_sort = 0;
assert( ava );
}
ava->la_private = ( void * )ad;
+ do_sort = 1;
}
/*
* Replace attr oid/name with the canonical name
*/
- free( ava->la_attr.bv_val );
- ber_dupbv( &ava->la_attr, &ad->ad_cname );
+ ava->la_attr = ad->ad_cname;
if( flags & SLAP_LDAPDN_PRETTY ) {
transf = ad->ad_type->sat_syntax->ssyn_pretty;
}
if( mr && ( mr->smr_usage & SLAP_MR_DN_FOLD ) ) {
- struct berval *s = bv;
+ char *s = bv.bv_val;
- bv = ber_bvstr( UTF8normalize( bv ? bv : &ava->la_value,
- UTF8_CASEFOLD ) );
-
- ber_bvfree( s );
+ ber_str2bv( UTF8normalize( bv.bv_val ? &bv
+ : &ava->la_value, LDAP_UTF8_CASEFOLD ),
+ 0, 0, &bv );
+ free( s );
}
- if( bv ) {
+ if( bv.bv_val ) {
free( ava->la_value.bv_val );
- ava->la_value = *bv;
- free( bv );
+ ava->la_value = bv;
}
- AVA_Sort( rdn, iAVA );
+ if( do_sort ) AVA_Sort( rdn, iAVA );
}
}
const char *p;
int rc;
- rc = ldap_str2rdn( dn, NULL, &p, LDAP_DN_FORMAT_LDAP | LDAP_DN_SKIP );
+ rc = ldap_str2rdn( dn, NULL, (char **)&p,
+ LDAP_DN_FORMAT_LDAP | LDAP_DN_SKIP );
if ( rc != LDAP_SUCCESS ) {
return rc;
}
+ /* Parent is root */
+ if (*p == '\0') {
+ *pdn = "";
+ return LDAP_SUCCESS;
+ }
+
assert( DN_SEPARATOR( p[ 0 ] ) );
p++;
return LDAP_OTHER;
}
- rc = ldap_str2rdn( dn->bv_val, &tmpRDN, &p, LDAP_DN_FORMAT_LDAP );
+ rc = ldap_str2rdn( dn->bv_val, &tmpRDN, (char **)&p, LDAP_DN_FORMAT_LDAP );
if ( rc != LDAP_SUCCESS ) {
return rc;
}
return 0;
}
- rc = ldap_str2rdn( dn_in->bv_val, NULL, &p,
+ rc = ldap_str2rdn( dn_in->bv_val, NULL, (char **)&p,
LDAP_DN_FORMAT_LDAP | LDAP_DN_SKIP );
if ( rc != LDAP_SUCCESS ) {
return 0;
assert( *values == NULL );
assert( types == NULL || *types == NULL );
- rc = ldap_str2rdn( rdn, &tmpRDN, &p, LDAP_DN_FORMAT_LDAP );
+ rc = ldap_str2rdn( rdn, &tmpRDN, (char **)&p, LDAP_DN_FORMAT_LDAP );
if ( rc != LDAP_SUCCESS ) {
return rc;
}
}
#endif
- for ( iAVA = 0; tmpRDN[ iAVA ]; iAVA++ ) {
- LDAPAVA *ava = tmpRDN[ iAVA ][ 0 ];
+ for ( iAVA = 0; tmpRDN[ 0 ][ iAVA ]; iAVA++ ) {
+ LDAPAVA *ava = tmpRDN[ 0 ][ iAVA ];
assert( ava );
assert( ava->la_attr.bv_val );
/*
* must be parsable
*/
- rc = ldap_str2rdn( rdn, &RDN, &p, LDAP_DN_FORMAT_LDAP );
+ rc = ldap_str2rdn( rdn, &RDN, (char **)&p, LDAP_DN_FORMAT_LDAP );
if ( rc != LDAP_SUCCESS ) {
return 0;
}