/* referral.c - muck with referrals */
/* $OpenLDAP$ */
/*
- * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
*/
static char * referral_dn_muck(
const char * refDN,
- const char * baseDN,
- const char * targetDN )
+ struct berval * baseDN,
+ struct berval * targetDN )
{
int rc;
struct berval bvin;
if( !baseDN ) {
/* no base, return target */
- return targetDN ? ch_strdup( targetDN ) : NULL;
+ return targetDN ? ch_strdup( targetDN->bv_val ) : NULL;
}
if( refDN ) {
* if refDN present return refDN
* else return baseDN
*/
- return nrefDN.bv_len ? nrefDN.bv_val : ch_strdup( baseDN );
+ return nrefDN.bv_len ? nrefDN.bv_val : ch_strdup( baseDN->bv_val );
}
- bvin.bv_val = (char *)targetDN;
- bvin.bv_len = strlen( targetDN );
-
- rc = dnPretty2( NULL, &bvin, &ntargetDN );
+ rc = dnPretty2( NULL, targetDN, &ntargetDN );
if( rc != LDAP_SUCCESS ) {
/* Invalid targetDN */
ch_free( nrefDN.bv_val );
}
if( nrefDN.bv_len ) {
- bvin.bv_val = (char *)baseDN;
- bvin.bv_len = strlen( baseDN );
-
- rc = dnPretty2( NULL, &bvin, &nbaseDN );
+ rc = dnPretty2( NULL, baseDN, &nbaseDN );
if( rc != LDAP_SUCCESS ) {
/* Invalid baseDN */
ch_free( nrefDN.bv_val );
}
muck.bv_len = ntargetDN.bv_len + nrefDN.bv_len - nbaseDN.bv_len;
- muck.bv_val = ch_malloc( muck.bv_len + 1 );
+ muck.bv_val = SLAP_MALLOC( muck.bv_len + 1 );
+ if( muck.bv_val == NULL ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG( OPERATION, CRIT,
+ "referral_dn_muck: SLAP_MALLOC failed\n", 0, 0, 0 );
+#else
+ Debug( LDAP_DEBUG_ANY,
+ "referral_dn_muck: SLAP_MALLOC failed\n", 0, 0, 0 );
+#endif
+ return NULL;
+ }
strncpy( muck.bv_val, ntargetDN.bv_val,
ntargetDN.bv_len-nbaseDN.bv_len );
if( i < 1 ) return NULL;
- refs = ch_malloc( (i+1) * sizeof( struct berval ) );
+ refs = SLAP_MALLOC( (i+1) * sizeof( struct berval ) );
+ if( refs == NULL ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG( OPERATION, CRIT,
+ "referral_rewrite: SLAP_MALLOC failed\n", 0, 0, 0 );
+#else
+ Debug( LDAP_DEBUG_ANY,
+ "referral_rewrite: SLAP_MALLOC failed\n", 0, 0, 0 );
+#endif
+ return NULL;
+ }
for( iv=in,jv=refs; iv->bv_val != NULL ; iv++ ) {
LDAPURLDesc *url;
char *dn = url->lud_dn;
url->lud_dn = referral_dn_muck(
( dn && *dn ) ? dn : NULL,
- base ? base->bv_val : NULL,
- target ? target->bv_val : NULL );
+ base, target );
ldap_memfree( dn );
}
if( i < 1 ) return NULL;
- refs = ch_malloc( (i + 1) * sizeof(struct berval));
+ refs = SLAP_MALLOC( (i + 1) * sizeof(struct berval));
+ if( refs == NULL ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG( OPERATION, CRIT,
+ "get_entry_referrals: SLAP_MALLOC failed\n", 0, 0, 0 );
+#else
+ Debug( LDAP_DEBUG_ANY,
+ "get_entry_referrals: SLAP_MALLOC failed\n", 0, 0, 0 );
+#endif
+ return NULL;
+ }
for( iv=attr->a_vals, jv=refs; iv->bv_val != NULL; iv++ ) {
unsigned k;