int tlimit,
Filter *filter,
const char *filterstr,
- char **attrs,
+ struct berval **attrs,
int attrsonly )
{
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
char *realbase = NULL;
int nentries = 0;
int manageDSAit = get_manageDSAit( op );
+ int cscope = LDAP_SCOPE_DEFAULT;
struct slap_limits_set *limit = NULL;
int isroot = 0;
if ( *nbase == '\0' ) {
/* DIT root special case */
- static const Entry root = { NOID, "", "", NULL, NULL };
- e = (Entry *) &root;
+ e = (Entry *) &slap_entry_root;
/* need normalized dn below */
realbase = ch_strdup( e->e_ndn );
struct berval **refs = NULL;
if ( matched != NULL ) {
+ struct berval **erefs;
matched_dn = ch_strdup( matched->e_dn );
- refs = is_entry_referral( matched )
- ? get_entry_referrals( be, conn, op, matched )
+ erefs = is_entry_referral( matched )
+ ? get_entry_referrals( be, conn, op, matched,
+ base, scope )
: NULL;
cache_return_entry_r( &li->li_cache, matched );
+ if( erefs ) {
+ refs = referral_rewrite( erefs, matched_dn,
+ base, scope );
+
+ ber_bvecfree( erefs );
+ }
+
} else {
- refs = default_referral;
+ refs = referral_rewrite( default_referral,
+ NULL, base, scope );
}
send_ldap_result( conn, op, err,
matched_dn, text, refs, NULL );
- if( matched != NULL ) {
- ber_bvecfree( refs );
- free( matched_dn );
- }
-
+ ber_bvecfree( refs );
+ free( matched_dn );
return 1;
}
if (!manageDSAit && is_entry_referral( e ) ) {
/* entry is a referral, don't allow add */
char *matched_dn = ch_strdup( e->e_dn );
- struct berval **refs = get_entry_referrals( be,
- conn, op, e );
+ struct berval **erefs = get_entry_referrals( be,
+ conn, op, e, base, scope );
+ struct berval **refs = NULL;
cache_return_entry_r( &li->li_cache, e );
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
- "ldbm_search: entry (%s) is a referral.\n",
- e->e_dn ));
+ "ldbm_search: entry (%s) is a referral.\n",
+ e->e_dn ));
#else
Debug( LDAP_DEBUG_TRACE,
"ldbm_search: entry is referral\n",
0, 0, 0 );
#endif
+ if( erefs ) {
+ refs = referral_rewrite( erefs, matched_dn,
+ base, scope );
- send_ldap_result( conn, op, LDAP_REFERRAL,
- matched_dn, NULL, refs, NULL );
+ ber_bvecfree( erefs );
+ }
- ber_bvecfree( refs );
- free( matched_dn );
+ if( refs ) {
+ send_ldap_result( conn, op, LDAP_REFERRAL,
+ matched_dn, NULL, refs, NULL );
+ ber_bvecfree( refs );
+
+ } else {
+ send_ldap_result( conn, op, LDAP_OTHER, matched_dn,
+ "bad referral object", NULL, NULL );
+ }
+ free( matched_dn );
return 1;
}
}
if ( scope == LDAP_SCOPE_BASE ) {
+ cscope = LDAP_SCOPE_BASE;
candidates = base_candidate( be, e );
} else {
+ cscope = ( scope != LDAP_SCOPE_SUBTREE )
+ ? LDAP_SCOPE_BASE : LDAP_SCOPE_SUBTREE;
candidates = search_candidates( be, e, filter,
scope, deref, manageDSAit );
}
/* no candidates */
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
- "ldbm_search: no candidates\n" ));
+ "ldbm_search: no candidates\n" ));
#else
Debug( LDAP_DEBUG_TRACE, "ldbm_search: no candidates\n",
0, 0, 0 );
#endif
-
send_search_result( conn, op,
LDAP_SUCCESS,
NULL, NULL, NULL, NULL, 0 );
}
/* if not root, get appropriate limits */
- if ( be_isroot( be, op->o_ndn ) ) {
+ if ( be_isroot( be, &op->o_ndn ) ) {
isroot = 1;
} else {
- ( void ) get_limits( be, op->o_ndn, &limit );
+ ( void ) get_limits( be, &op->o_ndn, &limit );
}
/* if candidates exceed to-be-checked entries, abort */
if ( !isroot && limit->lms_s_unchecked != -1 ) {
- if ( ID_BLOCK_NIDS( candidates ) > limit->lms_s_unchecked ) {
+ if ( ID_BLOCK_NIDS( candidates ) > (unsigned) limit->lms_s_unchecked ) {
send_search_result( conn, op, LDAP_UNWILLING_TO_PERFORM,
NULL, NULL, NULL, NULL, 0 );
rc = 0;
}
}
- /* if no time limit requested, use soft limit (unless root!) */
- if ( tlimit <= 0 ) {
- if ( isroot ) {
- tlimit = -1; /* allow root to set no limit */
- } else {
- tlimit = limit->lms_t_soft;
- }
-
- /* if requested limit higher than hard limit, abort */
- } else if ( tlimit > limit->lms_t_hard ) {
- /* no hard limit means use soft instead */
- if ( limit->lms_t_hard == 0 ) {
- tlimit = limit->lms_t_soft;
-
- /* positive hard limit means abort */
- } else if ( limit->lms_t_hard > 0 ) {
- send_search_result( conn, op, LDAP_UNWILLING_TO_PERFORM,
- NULL, NULL, NULL, NULL, 0 );
- rc = 0;
- goto done;
+ /* if root an no specific limit is required, allow unlimited search */
+ if ( isroot ) {
+ if ( tlimit == 0 ) {
+ tlimit = -1;
}
- /* negative hard limit means no limit */
- }
+ if ( slimit == 0 ) {
+ slimit = -1;
+ }
- /* compute it anyway; root does not use it */
- stoptime = op->o_time + tlimit;
+ } else {
+ /* if no limit is required, use soft limit */
+ if ( tlimit <= 0 ) {
+ tlimit = limit->lms_t_soft;
+
+ /* if requested limit higher than hard limit, abort */
+ } else if ( tlimit > limit->lms_t_hard ) {
+ /* no hard limit means use soft instead */
+ if ( limit->lms_t_hard == 0 ) {
+ tlimit = limit->lms_t_soft;
+
+ /* positive hard limit means abort */
+ } else if ( limit->lms_t_hard > 0 ) {
+ send_search_result( conn, op,
+ LDAP_UNWILLING_TO_PERFORM,
+ NULL, NULL, NULL, NULL, 0 );
+ rc = 0;
+ goto done;
+ }
- /* if no size limit requested, use soft limit (unless root!) */
- if ( slimit == 0 ) {
- if ( isroot ) {
- slimit = -1; /* allow root to set no limit */
- } else {
- slimit = limit->lms_s_soft;
+ /* negative hard limit means no limit */
}
-
- /* if requested limit higher than hard limit, abort */
- } else if ( slimit > limit->lms_s_hard ) {
- /* no hard limit means use soft instead */
- if ( limit->lms_s_hard == 0 ) {
+
+ /* if no limit is required, use soft limit */
+ if ( slimit <= 0 ) {
slimit = limit->lms_s_soft;
- /* positive hard limit means abort */
- } else if ( limit->lms_s_hard > 0 ) {
- send_search_result( conn, op, LDAP_UNWILLING_TO_PERFORM,
- NULL, NULL, NULL, NULL, 0 );
- rc = 0;
- goto done;
- }
+ /* if requested limit higher than hard limit, abort */
+ } else if ( slimit > limit->lms_s_hard ) {
+ /* no hard limit means use soft instead */
+ if ( limit->lms_s_hard == 0 ) {
+ slimit = limit->lms_s_soft;
+
+ /* positive hard limit means abort */
+ } else if ( limit->lms_s_hard > 0 ) {
+ send_search_result( conn, op,
+ LDAP_UNWILLING_TO_PERFORM,
+ NULL, NULL, NULL, NULL, 0 );
+ rc = 0;
+ goto done;
+ }
- /* negative hard limit means no limit */
+ /* negative hard limit means no limit */
+ }
}
+ /* compute it anyway; root does not use it */
+ stoptime = op->o_time + tlimit;
+
for ( id = idl_firstid( candidates, &cursor ); id != NOID;
id = idl_nextid( candidates, &cursor ) )
{
- int scopeok = 0;
+ int scopeok = 0;
/* check for abandon */
ldap_pvt_thread_mutex_lock( &op->o_abandonmutex );
if ( e == NULL ) {
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
- "ldbm_search: candidate %ld not found.\n", id ));
+ "ldbm_search: candidate %ld not found.\n", id ));
#else
Debug( LDAP_DEBUG_TRACE,
"ldbm_search: candidate %ld not found\n",
id, 0, 0 );
#endif
-
goto loop_continue;
}
free( pdn );
goto loop_continue;
}
- free(pdn);
}
} else if ( dn_issuffix( e->e_ndn, realbase ) ) {
/* alias is within scope */
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
- "ldbm_search: \"%s\" in subtree\n", e->e_dn ));
+ "ldbm_search: alias \"%s\" in subtree\n", e->e_dn ));
#else
Debug( LDAP_DEBUG_TRACE,
- "ldbm_search: \"%s\" in subtree\n",
+ "ldbm_search: alias \"%s\" in subtree\n",
e->e_dn, 0, 0 );
#endif
if ( !manageDSAit && scope != LDAP_SCOPE_BASE &&
is_entry_referral( e ) )
{
- struct berval **refs = get_entry_referrals(
- be, conn, op, e );
+ char *dn;
- send_search_reference( be, conn, op,
- e, refs, scope, NULL, &v2refs );
+ /* check scope */
+ if ( !scopeok && scope == LDAP_SCOPE_ONELEVEL ) {
+ if ( (dn = dn_parent( be, e->e_ndn )) != NULL ) {
+ scopeok = (dn == realbase)
+ ? 1
+ : (strcmp( dn, realbase ) ? 0 : 1 );
+ } else {
+ scopeok = (realbase == NULL || *realbase == '\0');
+ }
- ber_bvecfree( refs );
+ } else if ( !scopeok && scope == LDAP_SCOPE_SUBTREE ) {
+ dn = ch_strdup( e->e_ndn );
+ scopeok = dn_issuffix( dn, realbase );
+ free( dn );
+
+ } else {
+ scopeok = 1;
+ }
+
+ if( scopeok ) {
+ struct berval **erefs = get_entry_referrals(
+ be, conn, op, e, NULL, cscope );
+ struct berval **refs = referral_rewrite( erefs, e->e_dn, NULL,
+ scope == LDAP_SCOPE_SUBTREE
+ ? LDAP_SCOPE_SUBTREE
+ : LDAP_SCOPE_BASE );
+
+ send_search_reference( be, conn, op,
+ e, refs, NULL, &v2refs );
+
+ ber_bvecfree( refs );
+
+ } else {
+#ifdef NEW_LOGGING
+ LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL2,
+ "ldbm_search: candidate referral %ld scope not okay\n",
+ id ));
+#else
+ Debug( LDAP_DEBUG_TRACE,
+ "ldbm_search: candidate referral %ld scope not okay\n",
+ id, 0, 0 );
+#endif
+ }
goto loop_continue;
}
/* check scope */
if ( !scopeok && scope == LDAP_SCOPE_ONELEVEL ) {
if ( (dn = dn_parent( be, e->e_ndn )) != NULL ) {
- (void) dn_normalize( dn );
scopeok = (dn == realbase)
? 1
: (strcmp( dn, realbase ) ? 0 : 1 );
- free( dn );
-
} else {
scopeok = (realbase == NULL || *realbase == '\0');
}
} else {
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL2,
- "ldbm_search: candidate %ld scope not okay\n", id ));
+ "ldbm_search: candidate entry %ld scope not okay\n", id ));
#else
Debug( LDAP_DEBUG_TRACE,
- "ldbm_search: candidate %ld scope not okay\n",
+ "ldbm_search: candidate entry %ld scope not okay\n",
id, 0, 0 );
#endif
-
}
+
} else {
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL2,
- "ldbm_search: candidate %ld does not match filter\n", id ));
+ "ldbm_search: candidate entry %ld does not match filter\n", id ));
#else
Debug( LDAP_DEBUG_TRACE,
- "ldbm_search: candidate %ld does not match filter\n",
+ "ldbm_search: candidate entry %ld does not match filter\n",
id, 0, 0 );
#endif
-
}
loop_continue:
ldap_pvt_thread_yield();
}
+
send_search_result( conn, op,
v2refs == NULL ? LDAP_SUCCESS : LDAP_REFERRAL,
NULL, NULL, v2refs, NULL, nentries );