/* $OpenLDAP$ */
-/*
- * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
- * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
+ *
+ * Copyright 1998-2004 The OpenLDAP Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
+ *
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
*/
#include "portable.h"
#include "proto-back-ldbm.h"
-static char* get_alias_dn(
- Entry *e,
- int *err,
- char **errmsg );
-
-static char* new_superior(
- char *dn,
- char *oldSup,
- char *newSup );
+static void new_superior(
+ struct berval *dn,
+ struct berval *oldSup,
+ struct berval *newSup,
+ struct berval *res );
static int dnlist_subordinate(
- char** dnlist,
- char *dn );
+ BerVarray dnlist,
+ struct berval *dn );
Entry *deref_internal_r(
Backend* be,
Entry* alias,
- char* dn,
+ struct berval* dn_in,
int* err,
Entry** matched,
- char** text )
+ const char** text )
{
+ struct berval dn;
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
Entry *entry;
Entry *sup;
unsigned depth;
- char **dnlist;
+ BerVarray dnlist;
- assert( ( alias != NULL && dn == NULL ) || ( alias == NULL && dn != NULL ) );
+ assert( ( alias != NULL && dn_in == NULL )
+ || ( alias == NULL && dn_in != NULL ) );
*matched = NULL;
- *err = LDAP_SUCCESS;
+ *err = LDAP_NO_SUCH_OBJECT;
*text = NULL;
if( alias == NULL ) {
- dn = ch_strdup( dn );
- entry = dn2entry_r( be, dn, &sup );
+ ber_dupbv( &dn, dn_in );
+ entry = dn2entry_r( be, &dn, &sup );
} else {
- dn = ch_strdup( alias->e_ndn );
+ ber_dupbv( &dn, &alias->e_nname );
entry = alias;
sup = NULL;
}
dnlist = NULL;
- charray_add( &dnlist, dn );
+ ber_bvarray_add( &dnlist, &dn );
for( depth=0 ; ; depth++ ) {
if( entry != NULL ) {
Entry *newe;
- char *aliasDN;
+ struct berval aliasDN;
/* have entry, may be an alias */
}
/* deref entry */
- aliasDN = get_alias_dn( entry, err, text );
-
- if( aliasDN == NULL ) {
+ if( get_alias_dn( entry, &aliasDN, err, text )) {
*matched = entry;
entry = NULL;
break;
}
/* check if aliasDN is a subordinate of any DN in our list */
- if( dnlist_subordinate( dnlist, aliasDN ) ) {
+ if( dnlist_subordinate( dnlist, &aliasDN ) ) {
+ ch_free( aliasDN.bv_val );
*matched = entry;
entry = NULL;
*err = LDAP_ALIAS_PROBLEM;
/* attempt to dereference alias */
- newe = dn2entry_r( be, aliasDN, &sup );
+ newe = dn2entry_r( be, &aliasDN, &sup );
+ ch_free( aliasDN.bv_val );
if( newe != NULL ) {
- free( dn );
cache_return_entry_r(&li->li_cache, entry );
entry = newe;
- dn = ch_strdup( entry->e_ndn );
- charray_add( &dnlist, dn );
+ ber_dupbv( &dn, &entry->e_nname );
+ ber_bvarray_add( &dnlist, &dn );
continue;
-
}
if ( sup != NULL ) {
/* have superior, may be an alias */
Entry *newe;
Entry *newSup;
- char *supDN;
- char *aliasDN;
+ struct berval supDN;
+ struct berval aliasDN;
if( !is_entry_alias( sup ) ) {
/* entry is not an alias */
}
/* deref entry */
- supDN = get_alias_dn( sup, err, text );
-
- if( supDN == NULL ) {
+ if( get_alias_dn( sup, &supDN, err, text )) {
*matched = sup;
break;
}
- aliasDN = new_superior( dn, sup->e_ndn, supDN );
-
- if( aliasDN == NULL ) {
- free(aliasDN);
- *matched = sup;
- *err = LDAP_ALIAS_PROBLEM;
- *text = "superior alias problem";
- break;
- }
+ new_superior( &dn, &sup->e_nname, &supDN, &aliasDN );
+ free(supDN.bv_val);
/* check if aliasDN is a subordinate of any DN in our list */
- if( dnlist_subordinate( dnlist, aliasDN ) ) {
- free(aliasDN);
+ if( dnlist_subordinate( dnlist, &aliasDN ) ) {
+ free(aliasDN.bv_val);
*matched = entry;
entry = NULL;
*err = LDAP_ALIAS_PROBLEM;
}
/* attempt to dereference alias */
- newe = dn2entry_r( be, aliasDN, &newSup );
+ newe = dn2entry_r( be, &aliasDN, &newSup );
if( newe != NULL ) {
- free(aliasDN);
- free( dn );
+ free(aliasDN.bv_val);
cache_return_entry_r(&li->li_cache, sup );
entry = newe;
- dn = ch_strdup( entry->e_ndn );
- charray_add( &dnlist, dn );
+ ber_dupbv( &dn, &entry->e_nname );
+ ber_bvarray_add( &dnlist, &dn );
continue;
-
}
if ( newSup != NULL ) {
- free( dn );
cache_return_entry_r(&li->li_cache, sup );
sup = newSup;
- dn = aliasDN;
+ ber_dupbv( &dn, &aliasDN );
continue;
}
}
}
- free( dn );
- charray_free( dnlist );
+ ber_bvarray_free( dnlist );
return entry;
}
-static char* get_alias_dn(
- Entry *e,
- int *err,
- char **errmsg )
-{
- Attribute *a = attr_find( e->e_attrs, "aliasedobjectname" );
-
- if( a == NULL ) {
- /*
- * there was an aliasedobjectname defined but no data.
- */
- *err = LDAP_ALIAS_PROBLEM;
- *errmsg = "alias missing aliasedObjectName attribute";
- return NULL;
- }
-
- /*
- * aliasedObjectName should be SINGLE-VALUED with a single value.
- */
- if ( a->a_vals[0] == NULL || a->a_vals[0]->bv_val == NULL ) {
- /*
- * there was an aliasedobjectname defined but no data.
- */
- *err = LDAP_ALIAS_PROBLEM;
- *errmsg = "alias missing aliasedObjectName value";
- return NULL;
- }
-
- if( a->a_vals[1] != NULL ) {
- *err = LDAP_ALIAS_PROBLEM;
- *errmsg = "alias has multivalued aliasedObjectName";
- return NULL;
- }
-
- return a->a_vals[0]->bv_val;
-}
-
-char* new_superior(
- char *dn,
- char *oldSup,
- char *newSup )
+static void new_superior(
+ struct berval *dn,
+ struct berval *oldSup,
+ struct berval *newSup,
+ struct berval *newDN )
{
- char *newDN;
size_t dnlen, olen, nlen;
- assert( dn && oldSup && newSup );
+ assert( dn && oldSup && newSup && newDN );
- dnlen = strlen( dn );
- olen = strlen( oldSup );
- nlen = strlen( newSup );
+ dnlen = dn->bv_len;
+ olen = oldSup->bv_len;
+ nlen = newSup->bv_len;
- newDN = ch_malloc( dnlen - olen + nlen + 1 );
+ newDN->bv_val = ch_malloc( dnlen - olen + nlen + 1 );
- memcpy( newDN, dn, dnlen - olen );
- memcpy( &newDN[dnlen - olen], newSup, nlen );
- newDN[dnlen - olen + nlen] = '\0';
+ AC_MEMCPY( newDN->bv_val, dn->bv_val, dnlen - olen );
+ AC_MEMCPY( &newDN->bv_val[dnlen - olen], newSup->bv_val, nlen );
+ newDN->bv_val[dnlen - olen + nlen] = '\0';
- return newDN;
+ return;
}
static int dnlist_subordinate(
- char** dnlist,
- char *dn )
+ BerVarray dnlist,
+ struct berval *dn )
{
- int i;
assert( dnlist );
- for( i = 0; dnlist[i] != NULL; i++ ) {
- if( dn_issuffix( dnlist[i], dn ) ) {
+ for( ; dnlist->bv_val != NULL; dnlist++ ) {
+ if( dnIsSuffix( dnlist, dn ) ) {
return 1;
}
}
return 0;
}
-