1999-09-09 03:06:24 +08:00
|
|
|
/* $OpenLDAP$ */
|
1998-10-24 11:49:07 +08:00
|
|
|
/*
|
2000-05-13 10:47:56 +08:00
|
|
|
* Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
|
1999-07-16 10:45:46 +08:00
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
1998-10-24 11:49:07 +08:00
|
|
|
*/
|
|
|
|
|
1998-11-05 13:05:05 +08:00
|
|
|
#include "portable.h"
|
|
|
|
|
1998-10-24 11:49:07 +08:00
|
|
|
#include <stdio.h>
|
1999-06-03 08:37:44 +08:00
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/socket.h>
|
1998-10-24 11:49:07 +08:00
|
|
|
#include "slap.h"
|
|
|
|
#include "back-ldbm.h"
|
1998-10-24 12:01:20 +08:00
|
|
|
#include "proto-back-ldbm.h"
|
1998-10-24 11:49:07 +08:00
|
|
|
|
1999-07-16 10:45:46 +08:00
|
|
|
|
|
|
|
static char* get_alias_dn(
|
|
|
|
Entry *e,
|
|
|
|
int *err,
|
2000-05-22 11:46:57 +08:00
|
|
|
const char **errmsg );
|
1999-07-16 10:45:46 +08:00
|
|
|
|
|
|
|
static char* new_superior(
|
2000-05-22 11:46:57 +08:00
|
|
|
const char *dn,
|
|
|
|
const char *oldSup,
|
|
|
|
const char *newSup );
|
1999-07-16 10:45:46 +08:00
|
|
|
|
|
|
|
static int dnlist_subordinate(
|
|
|
|
char** dnlist,
|
2000-05-22 11:46:57 +08:00
|
|
|
const char *dn );
|
1999-07-16 10:45:46 +08:00
|
|
|
|
|
|
|
Entry *deref_internal_r(
|
|
|
|
Backend* be,
|
|
|
|
Entry* alias,
|
2001-12-27 08:26:59 +08:00
|
|
|
struct berval* dn_in,
|
1999-07-16 10:45:46 +08:00
|
|
|
int* err,
|
|
|
|
Entry** matched,
|
2000-05-22 11:46:57 +08:00
|
|
|
const char** text )
|
1999-07-16 10:45:46 +08:00
|
|
|
{
|
2000-05-22 11:46:57 +08:00
|
|
|
char *dn;
|
1999-07-16 10:45:46 +08:00
|
|
|
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
|
|
|
|
Entry *entry;
|
|
|
|
Entry *sup;
|
|
|
|
unsigned depth;
|
|
|
|
char **dnlist;
|
|
|
|
|
2000-06-16 01:37:02 +08:00
|
|
|
assert( ( alias != NULL && dn_in == NULL )
|
|
|
|
|| ( alias == NULL && dn_in != NULL ) );
|
1999-07-16 10:45:46 +08:00
|
|
|
|
|
|
|
*matched = NULL;
|
2000-08-28 01:53:01 +08:00
|
|
|
*err = LDAP_NO_SUCH_OBJECT;
|
1999-07-16 10:45:46 +08:00
|
|
|
*text = NULL;
|
|
|
|
|
|
|
|
if( alias == NULL ) {
|
2001-12-27 08:26:59 +08:00
|
|
|
dn = ch_strdup( dn_in->bv_val );
|
1999-07-16 10:45:46 +08:00
|
|
|
entry = dn2entry_r( be, dn, &sup );
|
|
|
|
|
|
|
|
} else {
|
|
|
|
dn = ch_strdup( alias->e_ndn );
|
|
|
|
entry = alias;
|
|
|
|
sup = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
dnlist = NULL;
|
|
|
|
charray_add( &dnlist, dn );
|
|
|
|
|
|
|
|
for( depth=0 ; ; depth++ ) {
|
|
|
|
if( entry != NULL ) {
|
|
|
|
Entry *newe;
|
|
|
|
char *aliasDN;
|
|
|
|
|
|
|
|
/* have entry, may be an alias */
|
|
|
|
|
|
|
|
if( !is_entry_alias( entry ) ) {
|
|
|
|
/* entry is not an alias */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* entry is alias */
|
|
|
|
if( depth > be->be_max_deref_depth ) {
|
|
|
|
*matched = entry;
|
|
|
|
entry = NULL;
|
|
|
|
*err = LDAP_ALIAS_DEREF_PROBLEM;
|
|
|
|
*text = "maximum deref depth exceeded";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* deref entry */
|
|
|
|
aliasDN = get_alias_dn( entry, err, text );
|
|
|
|
|
|
|
|
if( aliasDN == NULL ) {
|
|
|
|
*matched = entry;
|
|
|
|
entry = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check if aliasDN is a subordinate of any DN in our list */
|
|
|
|
if( dnlist_subordinate( dnlist, aliasDN ) ) {
|
2000-06-17 10:00:30 +08:00
|
|
|
ch_free( aliasDN );
|
1999-07-16 10:45:46 +08:00
|
|
|
*matched = entry;
|
|
|
|
entry = NULL;
|
|
|
|
*err = LDAP_ALIAS_PROBLEM;
|
|
|
|
*text = "circular alias";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* attempt to dereference alias */
|
|
|
|
|
|
|
|
newe = dn2entry_r( be, aliasDN, &sup );
|
2000-06-17 10:00:30 +08:00
|
|
|
ch_free( aliasDN );
|
1999-07-16 10:45:46 +08:00
|
|
|
|
|
|
|
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 );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( sup != NULL ) {
|
|
|
|
cache_return_entry_r(&li->li_cache, entry );
|
|
|
|
entry = NULL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* no newe and no superior, we're done */
|
|
|
|
break;
|
|
|
|
|
|
|
|
} else if( sup != NULL ) {
|
|
|
|
/* have superior, may be an alias */
|
|
|
|
Entry *newe;
|
|
|
|
Entry *newSup;
|
|
|
|
char *supDN;
|
|
|
|
char *aliasDN;
|
|
|
|
|
|
|
|
if( !is_entry_alias( sup ) ) {
|
|
|
|
/* entry is not an alias */
|
|
|
|
*matched = sup;
|
|
|
|
sup = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* entry is alias */
|
|
|
|
if( depth > be->be_max_deref_depth ) {
|
|
|
|
*matched = sup;
|
|
|
|
entry = NULL;
|
|
|
|
*err = LDAP_ALIAS_DEREF_PROBLEM;
|
|
|
|
*text = "maximum deref depth exceeded";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* deref entry */
|
|
|
|
supDN = get_alias_dn( sup, err, text );
|
|
|
|
|
|
|
|
if( supDN == NULL ) {
|
|
|
|
*matched = sup;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
aliasDN = new_superior( dn, sup->e_ndn, supDN );
|
2000-06-17 10:00:30 +08:00
|
|
|
free(supDN);
|
1999-07-16 10:45:46 +08:00
|
|
|
|
|
|
|
if( aliasDN == NULL ) {
|
|
|
|
free(aliasDN);
|
|
|
|
*matched = sup;
|
|
|
|
*err = LDAP_ALIAS_PROBLEM;
|
|
|
|
*text = "superior alias problem";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check if aliasDN is a subordinate of any DN in our list */
|
|
|
|
if( dnlist_subordinate( dnlist, aliasDN ) ) {
|
|
|
|
free(aliasDN);
|
|
|
|
*matched = entry;
|
|
|
|
entry = NULL;
|
|
|
|
*err = LDAP_ALIAS_PROBLEM;
|
|
|
|
*text = "subordinate circular alias";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* attempt to dereference alias */
|
|
|
|
newe = dn2entry_r( be, aliasDN, &newSup );
|
|
|
|
|
|
|
|
if( newe != NULL ) {
|
|
|
|
free(aliasDN);
|
|
|
|
free( dn );
|
|
|
|
cache_return_entry_r(&li->li_cache, sup );
|
|
|
|
entry = newe;
|
|
|
|
dn = ch_strdup( entry->e_ndn );
|
|
|
|
charray_add( &dnlist, dn );
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( newSup != NULL ) {
|
|
|
|
free( dn );
|
|
|
|
cache_return_entry_r(&li->li_cache, sup );
|
|
|
|
sup = newSup;
|
|
|
|
dn = aliasDN;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
/* no newe and no superior, we're done */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free( dn );
|
1999-11-22 07:20:25 +08:00
|
|
|
charray_free( dnlist );
|
1999-07-16 10:45:46 +08:00
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static char* get_alias_dn(
|
|
|
|
Entry *e,
|
|
|
|
int *err,
|
2000-05-22 11:46:57 +08:00
|
|
|
const char **errmsg )
|
1999-07-16 10:45:46 +08:00
|
|
|
{
|
2000-06-17 10:00:30 +08:00
|
|
|
char *dn;
|
2000-02-15 04:57:34 +08:00
|
|
|
Attribute *a;
|
2000-05-28 03:33:08 +08:00
|
|
|
AttributeDescription *aliasedObjectName = slap_schema.si_ad_aliasedObjectName;
|
2000-02-15 04:57:34 +08:00
|
|
|
|
|
|
|
a = attr_find( e->e_attrs, aliasedObjectName );
|
1999-07-16 10:45:46 +08:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
1999-07-23 03:17:16 +08:00
|
|
|
if ( a->a_vals[0] == NULL || a->a_vals[0]->bv_val == NULL ) {
|
1999-07-16 10:45:46 +08:00
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
2000-06-17 10:00:30 +08:00
|
|
|
dn = ch_strdup( a->a_vals[0]->bv_val );
|
|
|
|
|
|
|
|
if( dn_normalize(dn) == NULL ) {
|
|
|
|
ch_free( dn );
|
|
|
|
*err = LDAP_ALIAS_PROBLEM;
|
|
|
|
*errmsg = "alias aliasedObjectName value is invalid";
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return dn;
|
1999-07-16 10:45:46 +08:00
|
|
|
}
|
|
|
|
|
2000-10-12 07:42:53 +08:00
|
|
|
static char* new_superior(
|
2000-05-22 11:46:57 +08:00
|
|
|
const char *dn,
|
|
|
|
const char *oldSup,
|
|
|
|
const char *newSup )
|
1998-10-24 11:49:07 +08:00
|
|
|
{
|
1999-07-16 10:45:46 +08:00
|
|
|
char *newDN;
|
|
|
|
size_t dnlen, olen, nlen;
|
|
|
|
assert( dn && oldSup && newSup );
|
|
|
|
|
|
|
|
dnlen = strlen( dn );
|
|
|
|
olen = strlen( oldSup );
|
|
|
|
nlen = strlen( newSup );
|
|
|
|
|
|
|
|
newDN = ch_malloc( dnlen - olen + nlen + 1 );
|
|
|
|
|
2000-07-28 09:07:07 +08:00
|
|
|
AC_MEMCPY( newDN, dn, dnlen - olen );
|
|
|
|
AC_MEMCPY( &newDN[dnlen - olen], newSup, nlen );
|
1999-07-16 10:45:46 +08:00
|
|
|
newDN[dnlen - olen + nlen] = '\0';
|
|
|
|
|
|
|
|
return newDN;
|
1998-10-24 11:49:07 +08:00
|
|
|
}
|
|
|
|
|
1999-07-16 10:45:46 +08:00
|
|
|
static int dnlist_subordinate(
|
|
|
|
char** dnlist,
|
2000-05-22 11:46:57 +08:00
|
|
|
const char *dn )
|
1998-10-24 11:49:07 +08:00
|
|
|
{
|
1999-07-16 10:45:46 +08:00
|
|
|
int i;
|
|
|
|
assert( dnlist );
|
|
|
|
|
|
|
|
for( i = 0; dnlist[i] != NULL; i++ ) {
|
|
|
|
if( dn_issuffix( dnlist[i], dn ) ) {
|
|
|
|
return 1;
|
|
|
|
}
|
1998-10-24 11:49:07 +08:00
|
|
|
}
|
1999-07-16 10:45:46 +08:00
|
|
|
|
|
|
|
return 0;
|
1998-10-24 11:49:07 +08:00
|
|
|
}
|
1999-07-16 10:45:46 +08:00
|
|
|
|