3 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
10 #include <ac/string.h>
11 #include <ac/socket.h>
13 #include "back-ldbm.h"
14 #include "proto-back-ldbm.h"
17 static char* get_alias_dn(
20 const char **errmsg );
22 static char* new_superior(
27 static int dnlist_subordinate(
31 Entry *deref_internal_r(
40 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
46 assert( ( alias != NULL && dn == NULL ) || ( alias == NULL && dn != NULL ) );
53 dn = ch_strdup( dn_in );
54 entry = dn2entry_r( be, dn, &sup );
57 dn = ch_strdup( alias->e_ndn );
63 charray_add( &dnlist, dn );
65 for( depth=0 ; ; depth++ ) {
70 /* have entry, may be an alias */
72 if( !is_entry_alias( entry ) ) {
73 /* entry is not an alias */
78 if( depth > be->be_max_deref_depth ) {
81 *err = LDAP_ALIAS_DEREF_PROBLEM;
82 *text = "maximum deref depth exceeded";
87 aliasDN = get_alias_dn( entry, err, text );
89 if( aliasDN == NULL ) {
95 /* check if aliasDN is a subordinate of any DN in our list */
96 if( dnlist_subordinate( dnlist, aliasDN ) ) {
99 *err = LDAP_ALIAS_PROBLEM;
100 *text = "circular alias";
104 /* attempt to dereference alias */
106 newe = dn2entry_r( be, aliasDN, &sup );
110 cache_return_entry_r(&li->li_cache, entry );
112 dn = ch_strdup( entry->e_ndn );
113 charray_add( &dnlist, dn );
119 cache_return_entry_r(&li->li_cache, entry );
124 /* no newe and no superior, we're done */
127 } else if( sup != NULL ) {
128 /* have superior, may be an alias */
134 if( !is_entry_alias( sup ) ) {
135 /* entry is not an alias */
142 if( depth > be->be_max_deref_depth ) {
145 *err = LDAP_ALIAS_DEREF_PROBLEM;
146 *text = "maximum deref depth exceeded";
151 supDN = get_alias_dn( sup, err, text );
153 if( supDN == NULL ) {
158 aliasDN = new_superior( dn, sup->e_ndn, supDN );
160 if( aliasDN == NULL ) {
163 *err = LDAP_ALIAS_PROBLEM;
164 *text = "superior alias problem";
168 /* check if aliasDN is a subordinate of any DN in our list */
169 if( dnlist_subordinate( dnlist, aliasDN ) ) {
173 *err = LDAP_ALIAS_PROBLEM;
174 *text = "subordinate circular alias";
178 /* attempt to dereference alias */
179 newe = dn2entry_r( be, aliasDN, &newSup );
184 cache_return_entry_r(&li->li_cache, sup );
186 dn = ch_strdup( entry->e_ndn );
187 charray_add( &dnlist, dn );
192 if ( newSup != NULL ) {
194 cache_return_entry_r(&li->li_cache, sup );
203 /* no newe and no superior, we're done */
209 charray_free( dnlist );
214 static char* get_alias_dn(
217 const char **errmsg )
220 #ifdef SLAPD_SCHEMA_NOT_COMPAT
221 AttributeDescription *aliasedObjectName = slap_schema.si_ad_aliasedObjectName;
223 static const char *aliasedObjectName = "aliasedObjectName";
226 a = attr_find( e->e_attrs, aliasedObjectName );
230 * there was an aliasedobjectname defined but no data.
232 *err = LDAP_ALIAS_PROBLEM;
233 *errmsg = "alias missing aliasedObjectName attribute";
238 * aliasedObjectName should be SINGLE-VALUED with a single value.
240 if ( a->a_vals[0] == NULL || a->a_vals[0]->bv_val == NULL ) {
242 * there was an aliasedobjectname defined but no data.
244 *err = LDAP_ALIAS_PROBLEM;
245 *errmsg = "alias missing aliasedObjectName value";
249 if( a->a_vals[1] != NULL ) {
250 *err = LDAP_ALIAS_PROBLEM;
251 *errmsg = "alias has multivalued aliasedObjectName";
255 return a->a_vals[0]->bv_val;
264 size_t dnlen, olen, nlen;
265 assert( dn && oldSup && newSup );
267 dnlen = strlen( dn );
268 olen = strlen( oldSup );
269 nlen = strlen( newSup );
271 newDN = ch_malloc( dnlen - olen + nlen + 1 );
273 memcpy( newDN, dn, dnlen - olen );
274 memcpy( &newDN[dnlen - olen], newSup, nlen );
275 newDN[dnlen - olen + nlen] = '\0';
280 static int dnlist_subordinate(
287 for( i = 0; dnlist[i] != NULL; i++ ) {
288 if( dn_issuffix( dnlist[i], dn ) ) {