3 * Copyright 1998-1999 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(
22 static char* new_superior(
27 static int dnlist_subordinate(
31 Entry *deref_internal_r(
39 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
45 assert( ( alias != NULL && dn == NULL ) || ( alias == NULL && dn != NULL ) );
53 entry = dn2entry_r( be, dn, &sup );
56 dn = ch_strdup( alias->e_ndn );
62 charray_add( &dnlist, dn );
64 for( depth=0 ; ; depth++ ) {
69 /* have entry, may be an alias */
71 if( !is_entry_alias( entry ) ) {
72 /* entry is not an alias */
77 if( depth > be->be_max_deref_depth ) {
80 *err = LDAP_ALIAS_DEREF_PROBLEM;
81 *text = "maximum deref depth exceeded";
86 aliasDN = get_alias_dn( entry, err, text );
88 if( aliasDN == NULL ) {
94 /* check if aliasDN is a subordinate of any DN in our list */
95 if( dnlist_subordinate( dnlist, aliasDN ) ) {
98 *err = LDAP_ALIAS_PROBLEM;
99 *text = "circular alias";
103 /* attempt to dereference alias */
105 newe = dn2entry_r( be, aliasDN, &sup );
109 cache_return_entry_r(&li->li_cache, entry );
111 dn = ch_strdup( entry->e_ndn );
112 charray_add( &dnlist, dn );
118 cache_return_entry_r(&li->li_cache, entry );
123 /* no newe and no superior, we're done */
126 } else if( sup != NULL ) {
127 /* have superior, may be an alias */
133 if( !is_entry_alias( sup ) ) {
134 /* entry is not an alias */
141 if( depth > be->be_max_deref_depth ) {
144 *err = LDAP_ALIAS_DEREF_PROBLEM;
145 *text = "maximum deref depth exceeded";
150 supDN = get_alias_dn( sup, err, text );
152 if( supDN == NULL ) {
157 aliasDN = new_superior( dn, sup->e_ndn, supDN );
159 if( aliasDN == NULL ) {
162 *err = LDAP_ALIAS_PROBLEM;
163 *text = "superior alias problem";
167 /* check if aliasDN is a subordinate of any DN in our list */
168 if( dnlist_subordinate( dnlist, aliasDN ) ) {
172 *err = LDAP_ALIAS_PROBLEM;
173 *text = "subordinate circular alias";
177 /* attempt to dereference alias */
178 newe = dn2entry_r( be, aliasDN, &newSup );
183 cache_return_entry_r(&li->li_cache, sup );
185 dn = ch_strdup( entry->e_ndn );
186 charray_add( &dnlist, dn );
191 if ( newSup != NULL ) {
193 cache_return_entry_r(&li->li_cache, sup );
202 /* no newe and no superior, we're done */
212 static char* get_alias_dn(
217 Attribute *a = attr_find( e->e_attrs, "aliasedobjectname" );
221 * there was an aliasedobjectname defined but no data.
223 *err = LDAP_ALIAS_PROBLEM;
224 *errmsg = "alias missing aliasedObjectName attribute";
229 * aliasedObjectName should be SINGLE-VALUED with a single value.
231 if ( a->a_vals[0] == NULL || a->a_vals[0]->bv_val == NULL ) {
233 * there was an aliasedobjectname defined but no data.
235 *err = LDAP_ALIAS_PROBLEM;
236 *errmsg = "alias missing aliasedObjectName value";
240 if( a->a_vals[1] != NULL ) {
241 *err = LDAP_ALIAS_PROBLEM;
242 *errmsg = "alias has multivalued aliasedObjectName";
246 return a->a_vals[0]->bv_val;
255 size_t dnlen, olen, nlen;
256 assert( dn && oldSup && newSup );
258 dnlen = strlen( dn );
259 olen = strlen( oldSup );
260 nlen = strlen( newSup );
262 newDN = ch_malloc( dnlen - olen + nlen + 1 );
264 memcpy( newDN, dn, dnlen - olen );
265 memcpy( &newDN[dnlen - olen], newSup, nlen );
266 newDN[dnlen - olen + nlen] = '\0';
271 static int dnlist_subordinate(
278 for( i = 0; dnlist[i] != NULL; i++ ) {
279 if( dn_issuffix( dnlist[i], dn ) ) {