2000-09-26 02:59:15 +08:00
|
|
|
/* search.c - search operation */
|
|
|
|
/* $OpenLDAP$ */
|
2003-11-29 05:08:20 +08:00
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2007-01-03 04:00:42 +08:00
|
|
|
* Copyright 2000-2007 The OpenLDAP Foundation.
|
2003-11-29 05:08:20 +08:00
|
|
|
* 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>.
|
2000-09-26 02:59:15 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
|
|
|
|
#include "back-bdb.h"
|
2001-06-15 15:08:37 +08:00
|
|
|
#include "idl.h"
|
2000-09-26 02:59:15 +08:00
|
|
|
|
|
|
|
static int base_candidate(
|
2000-09-28 06:28:59 +08:00
|
|
|
BackendDB *be,
|
2000-09-26 02:59:15 +08:00
|
|
|
Entry *e,
|
|
|
|
ID *ids );
|
2003-09-17 02:56:04 +08:00
|
|
|
|
2000-09-26 03:59:45 +08:00
|
|
|
static int search_candidates(
|
2005-01-14 13:57:58 +08:00
|
|
|
Operation *op,
|
2003-04-05 14:35:16 +08:00
|
|
|
SlapReply *rs,
|
2000-09-26 03:59:45 +08:00
|
|
|
Entry *e,
|
2003-04-05 14:35:16 +08:00
|
|
|
u_int32_t locker,
|
2003-04-17 17:23:53 +08:00
|
|
|
ID *ids,
|
|
|
|
ID *scopes );
|
2003-09-17 02:56:04 +08:00
|
|
|
|
2004-08-24 17:19:33 +08:00
|
|
|
static int parse_paged_cookie( Operation *op, SlapReply *rs );
|
|
|
|
|
2004-06-09 13:20:57 +08:00
|
|
|
static void send_paged_response(
|
2002-11-21 10:16:53 +08:00
|
|
|
Operation *op,
|
2003-03-30 17:03:54 +08:00
|
|
|
SlapReply *rs,
|
2004-06-13 02:22:53 +08:00
|
|
|
ID *lastid,
|
2003-04-05 17:46:54 +08:00
|
|
|
int tentries );
|
2000-09-26 02:59:15 +08:00
|
|
|
|
2003-04-05 17:46:54 +08:00
|
|
|
/* Dereference aliases for a single alias entry. Return the final
|
|
|
|
* dereferenced entry on success, NULL on any failure.
|
|
|
|
*/
|
2003-04-05 14:35:16 +08:00
|
|
|
static Entry * deref_base (
|
2003-04-17 00:23:36 +08:00
|
|
|
Operation *op,
|
2003-04-05 14:35:16 +08:00
|
|
|
SlapReply *rs,
|
|
|
|
Entry *e,
|
|
|
|
Entry **matched,
|
|
|
|
u_int32_t locker,
|
|
|
|
DB_LOCK *lock,
|
|
|
|
ID *tmp,
|
|
|
|
ID *visited )
|
|
|
|
{
|
2003-04-17 00:23:36 +08:00
|
|
|
struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
|
2003-04-05 14:35:16 +08:00
|
|
|
struct berval ndn;
|
2003-04-17 00:23:36 +08:00
|
|
|
EntryInfo *ei;
|
2003-04-05 15:50:01 +08:00
|
|
|
DB_LOCK lockr;
|
2003-04-05 14:35:16 +08:00
|
|
|
|
|
|
|
rs->sr_err = LDAP_ALIAS_DEREF_PROBLEM;
|
|
|
|
rs->sr_text = "maximum deref depth exceeded";
|
|
|
|
|
2005-09-23 05:12:04 +08:00
|
|
|
for (;;) {
|
2003-04-05 17:46:54 +08:00
|
|
|
/* Remember the last entry we looked at, so we can
|
|
|
|
* report broken links
|
|
|
|
*/
|
2003-04-05 14:35:16 +08:00
|
|
|
*matched = e;
|
2003-04-05 17:46:54 +08:00
|
|
|
|
2005-09-23 05:12:04 +08:00
|
|
|
if (BDB_IDL_N(tmp) >= op->o_bd->be_max_deref_depth) {
|
|
|
|
e = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-04-05 17:46:54 +08:00
|
|
|
/* If this is part of a subtree or onelevel search,
|
|
|
|
* have we seen this ID before? If so, quit.
|
|
|
|
*/
|
|
|
|
if ( visited && bdb_idl_insert( visited, e->e_id ) ) {
|
|
|
|
e = NULL;
|
|
|
|
break;
|
2003-04-05 14:35:16 +08:00
|
|
|
}
|
2003-04-05 17:46:54 +08:00
|
|
|
|
|
|
|
/* If we've seen this ID during this deref iteration,
|
|
|
|
* we've hit a loop.
|
|
|
|
*/
|
2003-04-05 14:35:16 +08:00
|
|
|
if ( bdb_idl_insert( tmp, e->e_id ) ) {
|
|
|
|
rs->sr_err = LDAP_ALIAS_PROBLEM;
|
|
|
|
rs->sr_text = "circular alias";
|
|
|
|
e = NULL;
|
|
|
|
break;
|
|
|
|
}
|
2003-04-05 17:46:54 +08:00
|
|
|
|
|
|
|
/* If there was a problem getting the aliasedObjectName,
|
|
|
|
* get_alias_dn will have set the error status.
|
|
|
|
*/
|
2003-04-05 14:35:16 +08:00
|
|
|
if ( get_alias_dn(e, &ndn, &rs->sr_err, &rs->sr_text) ) {
|
|
|
|
e = NULL;
|
|
|
|
break;
|
|
|
|
}
|
2003-04-05 17:46:54 +08:00
|
|
|
|
2003-05-25 08:53:08 +08:00
|
|
|
rs->sr_err = bdb_dn2entry( op, NULL, &ndn, &ei,
|
|
|
|
0, locker, &lockr );
|
2003-04-17 17:23:53 +08:00
|
|
|
|
2003-12-30 11:53:03 +08:00
|
|
|
if ( ei ) {
|
|
|
|
e = ei->bei_e;
|
|
|
|
} else {
|
|
|
|
e = NULL;
|
|
|
|
}
|
2003-04-17 17:23:53 +08:00
|
|
|
|
2003-04-05 14:35:16 +08:00
|
|
|
if (!e) {
|
|
|
|
rs->sr_err = LDAP_ALIAS_PROBLEM;
|
|
|
|
rs->sr_text = "aliasedObject not found";
|
|
|
|
break;
|
|
|
|
}
|
2003-04-05 17:46:54 +08:00
|
|
|
|
|
|
|
/* Free the previous entry, continue to work with the
|
|
|
|
* one we just retrieved.
|
|
|
|
*/
|
2007-01-01 07:37:06 +08:00
|
|
|
bdb_cache_return_entry_r( bdb, *matched, lock);
|
2003-04-05 15:50:01 +08:00
|
|
|
*lock = lockr;
|
2003-04-05 17:46:54 +08:00
|
|
|
|
|
|
|
/* We found a regular entry. Return this to the caller. The
|
|
|
|
* entry is still locked for Read.
|
|
|
|
*/
|
2003-04-05 14:35:16 +08:00
|
|
|
if (!is_entry_alias(e)) {
|
|
|
|
rs->sr_err = LDAP_SUCCESS;
|
|
|
|
rs->sr_text = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
2003-04-05 17:46:54 +08:00
|
|
|
/* Look for and dereference all aliases within the search scope. Adds
|
|
|
|
* the dereferenced entries to the "ids" list. Requires "stack" to be
|
2003-05-01 19:59:08 +08:00
|
|
|
* able to hold 8 levels of DB_SIZE IDLs. Of course we're hardcoded to
|
|
|
|
* require a minimum of 8 UM_SIZE IDLs so this is never a problem.
|
2003-04-05 17:46:54 +08:00
|
|
|
*/
|
2003-04-05 14:35:16 +08:00
|
|
|
static int search_aliases(
|
|
|
|
Operation *op,
|
|
|
|
SlapReply *rs,
|
|
|
|
Entry *e,
|
|
|
|
u_int32_t locker,
|
|
|
|
ID *ids,
|
2003-04-17 17:23:53 +08:00
|
|
|
ID *scopes,
|
2003-12-30 11:53:03 +08:00
|
|
|
ID *stack )
|
2003-04-05 14:35:16 +08:00
|
|
|
{
|
|
|
|
struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
|
|
|
|
ID *aliases, *curscop, *subscop, *visited, *newsubs, *oldsubs, *tmp;
|
2003-04-05 16:54:24 +08:00
|
|
|
ID cursora, ida, cursoro, ido, *subscop2;
|
2003-04-05 14:35:16 +08:00
|
|
|
Entry *matched, *a;
|
2003-04-17 00:23:36 +08:00
|
|
|
EntryInfo *ei;
|
2004-07-12 06:55:57 +08:00
|
|
|
struct berval bv_alias = BER_BVC( "alias" );
|
2005-03-29 08:12:05 +08:00
|
|
|
#ifdef LDAP_COMP_MATCH
|
2005-02-17 01:00:11 +08:00
|
|
|
AttributeAssertion aa_alias = { NULL, BER_BVNULL, NULL };
|
2005-03-29 08:12:05 +08:00
|
|
|
#else
|
|
|
|
AttributeAssertion aa_alias = { NULL, BER_BVNULL };
|
|
|
|
#endif
|
2003-04-05 14:35:16 +08:00
|
|
|
Filter af;
|
2003-04-05 15:50:01 +08:00
|
|
|
DB_LOCK locka, lockr;
|
|
|
|
int first = 1;
|
2003-04-05 14:35:16 +08:00
|
|
|
|
2003-04-05 17:46:54 +08:00
|
|
|
aliases = stack; /* IDL of all aliases in the database */
|
2003-04-17 17:23:53 +08:00
|
|
|
curscop = aliases + BDB_IDL_DB_SIZE; /* Aliases in the current scope */
|
|
|
|
subscop = curscop + BDB_IDL_DB_SIZE; /* The current scope */
|
|
|
|
visited = subscop + BDB_IDL_DB_SIZE; /* IDs we've seen in this search */
|
|
|
|
newsubs = visited + BDB_IDL_DB_SIZE; /* New subtrees we've added */
|
|
|
|
oldsubs = newsubs + BDB_IDL_DB_SIZE; /* Subtrees added previously */
|
|
|
|
tmp = oldsubs + BDB_IDL_DB_SIZE; /* Scratch space for deref_base() */
|
2003-04-05 17:46:54 +08:00
|
|
|
|
|
|
|
/* A copy of subscop, because subscop gets clobbered by
|
|
|
|
* the bdb_idl_union/intersection routines
|
|
|
|
*/
|
2003-04-17 17:23:53 +08:00
|
|
|
subscop2 = tmp + BDB_IDL_DB_SIZE;
|
2003-04-05 14:35:16 +08:00
|
|
|
|
|
|
|
af.f_choice = LDAP_FILTER_EQUALITY;
|
|
|
|
af.f_ava = &aa_alias;
|
|
|
|
af.f_av_desc = slap_schema.si_ad_objectClass;
|
|
|
|
af.f_av_value = bv_alias;
|
|
|
|
af.f_next = NULL;
|
|
|
|
|
|
|
|
/* Find all aliases in database */
|
2003-04-18 11:36:52 +08:00
|
|
|
BDB_IDL_ZERO( aliases );
|
2003-04-11 09:29:28 +08:00
|
|
|
rs->sr_err = bdb_filter_candidates( op, &af, aliases,
|
2003-04-05 16:40:07 +08:00
|
|
|
curscop, visited );
|
2003-04-05 14:35:16 +08:00
|
|
|
if (rs->sr_err != LDAP_SUCCESS) {
|
|
|
|
return rs->sr_err;
|
|
|
|
}
|
|
|
|
oldsubs[0] = 1;
|
|
|
|
oldsubs[1] = e->e_id;
|
|
|
|
|
2003-04-05 15:50:01 +08:00
|
|
|
BDB_IDL_ZERO( ids );
|
|
|
|
BDB_IDL_ZERO( visited );
|
2003-04-05 14:35:16 +08:00
|
|
|
BDB_IDL_ZERO( newsubs );
|
|
|
|
|
2003-04-05 16:54:24 +08:00
|
|
|
cursoro = 0;
|
2003-04-05 14:35:16 +08:00
|
|
|
ido = bdb_idl_first( oldsubs, &cursoro );
|
|
|
|
|
|
|
|
for (;;) {
|
2003-04-05 17:46:54 +08:00
|
|
|
/* Set curscop to only the aliases in the current scope. Start with
|
|
|
|
* all the aliases, obtain the IDL for the current scope, and then
|
2003-04-08 19:17:20 +08:00
|
|
|
* get the intersection of these two IDLs. Add the current scope
|
|
|
|
* to the cumulative list of candidates.
|
2003-04-05 17:46:54 +08:00
|
|
|
*/
|
2003-04-05 14:35:16 +08:00
|
|
|
BDB_IDL_CPY( curscop, aliases );
|
2003-05-01 19:59:08 +08:00
|
|
|
rs->sr_err = bdb_dn2idl( op, e, subscop,
|
2003-12-30 11:53:03 +08:00
|
|
|
subscop2+BDB_IDL_DB_SIZE );
|
2003-04-05 15:50:01 +08:00
|
|
|
if (first) {
|
|
|
|
first = 0;
|
|
|
|
} else {
|
2007-01-01 07:37:06 +08:00
|
|
|
bdb_cache_return_entry_r (bdb, e, &locka);
|
2003-04-05 15:50:01 +08:00
|
|
|
}
|
2003-04-05 16:54:24 +08:00
|
|
|
BDB_IDL_CPY(subscop2, subscop);
|
2003-04-05 14:35:16 +08:00
|
|
|
rs->sr_err = bdb_idl_intersection(curscop, subscop);
|
2003-04-08 19:17:20 +08:00
|
|
|
bdb_idl_union( ids, subscop2 );
|
2003-04-05 14:35:16 +08:00
|
|
|
|
2003-04-05 17:46:54 +08:00
|
|
|
/* Dereference all of the aliases in the current scope. */
|
2003-04-05 16:54:24 +08:00
|
|
|
cursora = 0;
|
2003-04-05 14:35:16 +08:00
|
|
|
for (ida = bdb_idl_first(curscop, &cursora); ida != NOID;
|
2003-04-05 16:40:07 +08:00
|
|
|
ida = bdb_idl_next(curscop, &cursora))
|
|
|
|
{
|
2003-04-17 00:23:36 +08:00
|
|
|
ei = NULL;
|
2004-07-11 03:06:20 +08:00
|
|
|
retry1:
|
2003-05-25 08:53:08 +08:00
|
|
|
rs->sr_err = bdb_cache_find_id(op, NULL,
|
|
|
|
ida, &ei, 0, locker, &lockr );
|
2003-04-05 14:35:16 +08:00
|
|
|
if (rs->sr_err != LDAP_SUCCESS) {
|
2004-07-11 03:06:20 +08:00
|
|
|
if ( rs->sr_err == DB_LOCK_DEADLOCK ||
|
|
|
|
rs->sr_err == DB_LOCK_NOTGRANTED ) goto retry1;
|
2003-04-05 14:35:16 +08:00
|
|
|
continue;
|
|
|
|
}
|
2003-04-17 00:23:36 +08:00
|
|
|
a = ei->bei_e;
|
2003-04-05 17:46:54 +08:00
|
|
|
|
|
|
|
/* This should only happen if the curscop IDL has maxed out and
|
|
|
|
* turned into a range that spans IDs indiscriminately
|
|
|
|
*/
|
2003-04-05 14:35:16 +08:00
|
|
|
if (!is_entry_alias(a)) {
|
2007-01-01 07:37:06 +08:00
|
|
|
bdb_cache_return_entry_r (bdb, a, &lockr);
|
2003-04-05 14:35:16 +08:00
|
|
|
continue;
|
|
|
|
}
|
2003-04-05 17:46:54 +08:00
|
|
|
|
|
|
|
/* Actually dereference the alias */
|
2003-04-05 14:35:16 +08:00
|
|
|
BDB_IDL_ZERO(tmp);
|
2003-04-17 00:23:36 +08:00
|
|
|
a = deref_base( op, rs, a, &matched, locker, &lockr,
|
2003-04-05 16:40:07 +08:00
|
|
|
tmp, visited );
|
2003-04-05 14:35:16 +08:00
|
|
|
if (a) {
|
2003-04-08 19:17:20 +08:00
|
|
|
/* If the target was not already in our current candidates,
|
2003-04-17 17:23:53 +08:00
|
|
|
* make note of it in the newsubs list. Also
|
|
|
|
* set it in the scopes list so that bdb_search
|
|
|
|
* can check it.
|
2003-04-05 17:46:54 +08:00
|
|
|
*/
|
2003-04-08 19:17:20 +08:00
|
|
|
if (bdb_idl_insert(ids, a->e_id) == 0) {
|
2003-04-05 14:35:16 +08:00
|
|
|
bdb_idl_insert(newsubs, a->e_id);
|
2003-04-17 17:23:53 +08:00
|
|
|
bdb_idl_insert(scopes, a->e_id);
|
2003-04-05 14:35:16 +08:00
|
|
|
}
|
2007-01-01 07:37:06 +08:00
|
|
|
bdb_cache_return_entry_r( bdb, a, &lockr);
|
2003-04-05 16:40:07 +08:00
|
|
|
|
2003-04-05 14:35:16 +08:00
|
|
|
} else if (matched) {
|
2003-04-05 17:46:54 +08:00
|
|
|
/* Alias could not be dereferenced, or it deref'd to
|
|
|
|
* an ID we've already seen. Ignore it.
|
|
|
|
*/
|
2007-01-01 07:37:06 +08:00
|
|
|
bdb_cache_return_entry_r( bdb, matched, &lockr );
|
2003-04-05 16:54:24 +08:00
|
|
|
rs->sr_text = NULL;
|
2003-04-05 14:35:16 +08:00
|
|
|
}
|
|
|
|
}
|
2003-04-05 17:46:54 +08:00
|
|
|
/* If this is a OneLevel search, we're done; oldsubs only had one
|
|
|
|
* ID in it. For a Subtree search, oldsubs may be a list of scope IDs.
|
|
|
|
*/
|
2003-12-30 11:53:03 +08:00
|
|
|
if ( op->ors_scope == LDAP_SCOPE_ONELEVEL ) break;
|
2003-04-05 14:35:16 +08:00
|
|
|
nextido:
|
|
|
|
ido = bdb_idl_next( oldsubs, &cursoro );
|
2003-04-05 17:46:54 +08:00
|
|
|
|
|
|
|
/* If we're done processing the old scopes, did we add any new
|
|
|
|
* scopes in this iteration? If so, go back and do those now.
|
|
|
|
*/
|
2003-04-05 14:35:16 +08:00
|
|
|
if (ido == NOID) {
|
|
|
|
if (BDB_IDL_IS_ZERO(newsubs)) break;
|
|
|
|
BDB_IDL_CPY(oldsubs, newsubs);
|
|
|
|
BDB_IDL_ZERO(newsubs);
|
2003-04-05 16:54:24 +08:00
|
|
|
cursoro = 0;
|
2003-04-05 14:35:16 +08:00
|
|
|
ido = bdb_idl_first( oldsubs, &cursoro );
|
|
|
|
}
|
2003-04-05 17:46:54 +08:00
|
|
|
|
|
|
|
/* Find the entry corresponding to the next scope. If it can't
|
|
|
|
* be found, ignore it and move on. This should never happen;
|
|
|
|
* we should never see the ID of an entry that doesn't exist.
|
|
|
|
* Set the name so that the scope's IDL can be retrieved.
|
|
|
|
*/
|
2003-04-17 00:23:36 +08:00
|
|
|
ei = NULL;
|
2004-07-11 03:06:20 +08:00
|
|
|
sameido:
|
2003-05-25 08:53:08 +08:00
|
|
|
rs->sr_err = bdb_cache_find_id(op, NULL, ido, &ei,
|
|
|
|
0, locker, &locka );
|
2004-07-11 03:06:20 +08:00
|
|
|
if ( rs->sr_err != LDAP_SUCCESS ) {
|
|
|
|
if ( rs->sr_err == DB_LOCK_DEADLOCK ||
|
|
|
|
rs->sr_err == DB_LOCK_NOTGRANTED )
|
|
|
|
goto sameido;
|
|
|
|
goto nextido;
|
|
|
|
}
|
2003-04-17 00:23:36 +08:00
|
|
|
e = ei->bei_e;
|
2003-04-05 14:35:16 +08:00
|
|
|
}
|
|
|
|
return rs->sr_err;
|
|
|
|
}
|
2003-04-30 10:04:23 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
int
|
2005-01-14 13:57:58 +08:00
|
|
|
bdb_search( Operation *op, SlapReply *rs )
|
2003-03-30 17:03:54 +08:00
|
|
|
{
|
|
|
|
struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
|
2000-09-26 02:59:15 +08:00
|
|
|
time_t stoptime;
|
|
|
|
ID id, cursor;
|
2001-10-14 00:55:54 +08:00
|
|
|
ID candidates[BDB_IDL_UM_SIZE];
|
2003-04-17 17:23:53 +08:00
|
|
|
ID scopes[BDB_IDL_DB_SIZE];
|
2004-04-08 20:15:26 +08:00
|
|
|
Entry *e = NULL, base, e_root = {0};
|
2004-04-09 19:44:28 +08:00
|
|
|
Entry *matched = NULL;
|
2004-04-08 20:15:26 +08:00
|
|
|
EntryInfo *ei, ei_root = {0};
|
2004-04-07 12:11:43 +08:00
|
|
|
struct berval realbase = BER_BVNULL;
|
2005-01-14 19:51:16 +08:00
|
|
|
slap_mask_t mask;
|
2000-09-26 13:33:37 +08:00
|
|
|
int manageDSAit;
|
2003-04-01 12:12:18 +08:00
|
|
|
int tentries = 0;
|
2002-11-21 10:16:53 +08:00
|
|
|
ID lastid = NOID;
|
2003-03-30 17:03:54 +08:00
|
|
|
AttributeName *attrs;
|
2000-09-26 13:33:37 +08:00
|
|
|
|
2004-11-26 05:16:54 +08:00
|
|
|
u_int32_t locker = 0;
|
|
|
|
DB_LOCK lock;
|
|
|
|
struct bdb_op_info *opinfo = NULL;
|
|
|
|
DB_TXN *ltid = NULL;
|
|
|
|
|
2004-11-17 22:53:03 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "=> " LDAP_XSTRING(bdb_search) "\n", 0, 0, 0);
|
2005-01-14 13:57:58 +08:00
|
|
|
attrs = op->oq_search.rs_attrs;
|
2000-09-26 02:59:15 +08:00
|
|
|
|
2004-06-23 10:00:00 +08:00
|
|
|
opinfo = (struct bdb_op_info *) op->o_private;
|
|
|
|
|
2005-01-14 13:57:58 +08:00
|
|
|
manageDSAit = get_manageDSAit( op );
|
2002-10-26 01:51:30 +08:00
|
|
|
|
2004-08-26 18:17:53 +08:00
|
|
|
if ( opinfo && opinfo->boi_txn ) {
|
2004-06-23 13:10:18 +08:00
|
|
|
ltid = opinfo->boi_txn;
|
|
|
|
locker = TXN_ID( ltid );
|
2004-06-23 10:00:00 +08:00
|
|
|
} else {
|
|
|
|
rs->sr_err = LOCK_ID( bdb->bi_dbenv, &locker );
|
2003-02-07 23:47:32 +08:00
|
|
|
|
2004-06-23 10:00:00 +08:00
|
|
|
switch(rs->sr_err) {
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
default:
|
2005-01-14 13:57:58 +08:00
|
|
|
send_ldap_error( op, rs, LDAP_OTHER, "internal error" );
|
2004-06-23 10:00:00 +08:00
|
|
|
return rs->sr_err;
|
|
|
|
}
|
2002-08-20 11:10:08 +08:00
|
|
|
}
|
2002-06-01 04:49:19 +08:00
|
|
|
|
2005-01-14 13:57:58 +08:00
|
|
|
if ( op->o_req_ndn.bv_len == 0 ) {
|
2001-11-15 01:27:24 +08:00
|
|
|
/* DIT root special case */
|
2004-04-08 20:15:26 +08:00
|
|
|
ei_root.bei_e = &e_root;
|
|
|
|
ei_root.bei_parent = &ei_root;
|
|
|
|
e_root.e_private = &ei_root;
|
2004-06-12 15:39:24 +08:00
|
|
|
e_root.e_id = 0;
|
2004-07-12 06:55:57 +08:00
|
|
|
BER_BVSTR( &e_root.e_nname, "" );
|
|
|
|
BER_BVSTR( &e_root.e_name, "" );
|
2004-04-08 20:15:26 +08:00
|
|
|
ei = &ei_root;
|
2003-08-30 01:02:53 +08:00
|
|
|
rs->sr_err = LDAP_SUCCESS;
|
2003-04-05 14:35:16 +08:00
|
|
|
} else {
|
2005-09-23 05:12:04 +08:00
|
|
|
if ( op->ors_deref & LDAP_DEREF_FINDING ) {
|
|
|
|
BDB_IDL_ZERO(candidates);
|
|
|
|
}
|
2002-06-01 04:49:19 +08:00
|
|
|
dn2entry_retry:
|
2003-04-05 16:40:07 +08:00
|
|
|
/* get entry with reader lock */
|
2005-01-14 13:57:58 +08:00
|
|
|
rs->sr_err = bdb_dn2entry( op, ltid, &op->o_req_ndn, &ei,
|
2003-05-25 08:53:08 +08:00
|
|
|
1, locker, &lock );
|
2003-04-05 14:35:16 +08:00
|
|
|
}
|
2003-04-05 16:40:07 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
switch(rs->sr_err) {
|
2000-09-26 02:59:15 +08:00
|
|
|
case DB_NOTFOUND:
|
2003-12-30 06:25:43 +08:00
|
|
|
matched = ei->bei_e;
|
|
|
|
break;
|
2000-09-26 02:59:15 +08:00
|
|
|
case 0:
|
2003-12-30 06:25:43 +08:00
|
|
|
e = ei->bei_e;
|
|
|
|
break;
|
2002-04-20 05:41:32 +08:00
|
|
|
case LDAP_BUSY:
|
2005-01-14 13:57:58 +08:00
|
|
|
send_ldap_error( op, rs, LDAP_BUSY, "ldap server busy" );
|
2004-06-23 10:00:00 +08:00
|
|
|
if ( !opinfo )
|
|
|
|
LOCK_ID_FREE (bdb->bi_dbenv, locker );
|
2002-04-20 05:41:32 +08:00
|
|
|
return LDAP_BUSY;
|
2002-06-01 04:49:19 +08:00
|
|
|
case DB_LOCK_DEADLOCK:
|
|
|
|
case DB_LOCK_NOTGRANTED:
|
|
|
|
goto dn2entry_retry;
|
2000-09-26 02:59:15 +08:00
|
|
|
default:
|
2005-01-14 13:57:58 +08:00
|
|
|
send_ldap_error( op, rs, LDAP_OTHER, "internal error" );
|
2004-06-23 10:00:00 +08:00
|
|
|
if ( !opinfo )
|
|
|
|
LOCK_ID_FREE (bdb->bi_dbenv, locker );
|
2003-03-30 17:03:54 +08:00
|
|
|
return rs->sr_err;
|
2000-09-26 02:59:15 +08:00
|
|
|
}
|
|
|
|
|
2005-09-23 05:12:04 +08:00
|
|
|
if ( op->ors_deref & LDAP_DEREF_FINDING ) {
|
|
|
|
if ( matched && is_entry_alias( matched )) {
|
|
|
|
struct berval stub;
|
|
|
|
|
|
|
|
stub.bv_val = op->o_req_ndn.bv_val;
|
|
|
|
stub.bv_len = op->o_req_ndn.bv_len - matched->e_nname.bv_len - 1;
|
|
|
|
e = deref_base( op, rs, matched, &matched, locker, &lock,
|
|
|
|
candidates, NULL );
|
|
|
|
if ( e ) {
|
|
|
|
build_new_dn( &op->o_req_ndn, &e->e_nname, &stub,
|
|
|
|
op->o_tmpmemctx );
|
2007-01-01 07:37:06 +08:00
|
|
|
bdb_cache_return_entry_r (bdb, e, &lock);
|
2005-09-23 05:12:04 +08:00
|
|
|
matched = NULL;
|
|
|
|
goto dn2entry_retry;
|
|
|
|
}
|
|
|
|
} else if ( e && is_entry_alias( e )) {
|
|
|
|
e = deref_base( op, rs, e, &matched, locker, &lock,
|
|
|
|
candidates, NULL );
|
|
|
|
}
|
2003-04-05 14:35:16 +08:00
|
|
|
}
|
|
|
|
|
2000-09-26 02:59:15 +08:00
|
|
|
if ( e == NULL ) {
|
2004-04-07 12:11:43 +08:00
|
|
|
struct berval matched_dn = BER_BVNULL;
|
2000-09-26 02:59:15 +08:00
|
|
|
|
|
|
|
if ( matched != NULL ) {
|
2005-01-12 23:11:17 +08:00
|
|
|
BerVarray erefs = NULL;
|
2000-09-26 02:59:15 +08:00
|
|
|
|
2005-01-14 19:51:16 +08:00
|
|
|
/* return referral only if "disclose"
|
|
|
|
* is granted on the object */
|
2005-01-11 23:59:13 +08:00
|
|
|
if ( ! access_allowed( op, matched,
|
|
|
|
slap_schema.si_ad_entry,
|
|
|
|
NULL, ACL_DISCLOSE, NULL ) )
|
|
|
|
{
|
|
|
|
rs->sr_err = LDAP_NO_SUCH_OBJECT;
|
|
|
|
|
2006-04-12 13:53:26 +08:00
|
|
|
} else {
|
2005-01-11 23:59:13 +08:00
|
|
|
ber_dupbv( &matched_dn, &matched->e_name );
|
|
|
|
|
|
|
|
erefs = is_entry_referral( matched )
|
|
|
|
? get_entry_referrals( op, matched )
|
|
|
|
: NULL;
|
2005-09-23 05:12:04 +08:00
|
|
|
if ( rs->sr_err == DB_NOTFOUND )
|
|
|
|
rs->sr_err = LDAP_REFERRAL;
|
2005-01-11 23:59:13 +08:00
|
|
|
rs->sr_matched = matched_dn.bv_val;
|
|
|
|
}
|
2000-09-26 02:59:15 +08:00
|
|
|
|
2004-12-15 01:22:22 +08:00
|
|
|
#ifdef SLAP_ZONE_ALLOC
|
|
|
|
slap_zn_runlock(bdb->bi_cache.c_zctx, matched);
|
|
|
|
#endif
|
2007-01-01 07:37:06 +08:00
|
|
|
bdb_cache_return_entry_r (bdb, matched, &lock);
|
2001-11-05 14:24:11 +08:00
|
|
|
matched = NULL;
|
|
|
|
|
2005-01-11 23:59:13 +08:00
|
|
|
if ( erefs ) {
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_ref = referral_rewrite( erefs, &matched_dn,
|
2005-01-14 13:57:58 +08:00
|
|
|
&op->o_req_dn, op->oq_search.rs_scope );
|
2002-01-14 09:43:17 +08:00
|
|
|
ber_bvarray_free( erefs );
|
2001-11-05 14:24:11 +08:00
|
|
|
}
|
|
|
|
|
2000-09-26 02:59:15 +08:00
|
|
|
} else {
|
2004-12-15 01:22:22 +08:00
|
|
|
#ifdef SLAP_ZONE_ALLOC
|
|
|
|
slap_zn_runlock(bdb->bi_cache.c_zctx, matched);
|
|
|
|
#endif
|
2004-10-06 13:51:38 +08:00
|
|
|
rs->sr_ref = referral_rewrite( default_referral,
|
2005-01-14 13:57:58 +08:00
|
|
|
NULL, &op->o_req_dn, op->oq_search.rs_scope );
|
2005-12-16 19:33:11 +08:00
|
|
|
rs->sr_err = rs->sr_ref != NULL ? LDAP_REFERRAL : LDAP_NO_SUCH_OBJECT;
|
2000-09-26 02:59:15 +08:00
|
|
|
}
|
|
|
|
|
2005-01-14 13:57:58 +08:00
|
|
|
send_ldap_result( op, rs );
|
2000-09-26 02:59:15 +08:00
|
|
|
|
2004-06-23 10:00:00 +08:00
|
|
|
if ( !opinfo )
|
|
|
|
LOCK_ID_FREE (bdb->bi_dbenv, locker );
|
2003-03-30 17:03:54 +08:00
|
|
|
if ( rs->sr_ref ) {
|
|
|
|
ber_bvarray_free( rs->sr_ref );
|
|
|
|
rs->sr_ref = NULL;
|
|
|
|
}
|
2005-01-11 23:59:13 +08:00
|
|
|
if ( !BER_BVISNULL( &matched_dn ) ) {
|
2003-03-30 17:03:54 +08:00
|
|
|
ber_memfree( matched_dn.bv_val );
|
|
|
|
rs->sr_matched = NULL;
|
|
|
|
}
|
|
|
|
return rs->sr_err;
|
2000-09-26 02:59:15 +08:00
|
|
|
}
|
|
|
|
|
2005-01-14 19:51:16 +08:00
|
|
|
/* NOTE: __NEW__ "search" access is required
|
|
|
|
* on searchBase object */
|
|
|
|
if ( ! access_allowed_mask( op, e, slap_schema.si_ad_entry,
|
|
|
|
NULL, ACL_SEARCH, NULL, &mask ) )
|
2005-01-11 23:59:13 +08:00
|
|
|
{
|
2005-01-14 19:51:16 +08:00
|
|
|
if ( !ACL_GRANT( mask, ACL_DISCLOSE ) ) {
|
|
|
|
rs->sr_err = LDAP_NO_SUCH_OBJECT;
|
|
|
|
} else {
|
|
|
|
rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
|
|
|
|
}
|
2005-01-11 23:59:13 +08:00
|
|
|
|
|
|
|
#ifdef SLAP_ZONE_ALLOC
|
|
|
|
slap_zn_runlock(bdb->bi_cache.c_zctx, e);
|
|
|
|
#endif
|
|
|
|
if ( e != &e_root ) {
|
2007-01-01 07:37:06 +08:00
|
|
|
bdb_cache_return_entry_r(bdb, e, &lock);
|
2005-01-11 23:59:13 +08:00
|
|
|
}
|
2005-01-14 13:57:58 +08:00
|
|
|
send_ldap_result( op, rs );
|
2005-08-24 01:38:50 +08:00
|
|
|
return rs->sr_err;
|
2005-01-11 23:59:13 +08:00
|
|
|
}
|
|
|
|
|
2004-04-08 20:15:26 +08:00
|
|
|
if ( !manageDSAit && e != &e_root && is_entry_referral( e ) ) {
|
2000-09-26 02:59:15 +08:00
|
|
|
/* entry is a referral, don't allow add */
|
2005-01-11 23:59:13 +08:00
|
|
|
struct berval matched_dn = BER_BVNULL;
|
|
|
|
BerVarray erefs = NULL;
|
2002-01-06 01:49:59 +08:00
|
|
|
|
|
|
|
ber_dupbv( &matched_dn, &e->e_name );
|
2003-03-30 17:03:54 +08:00
|
|
|
erefs = get_entry_referrals( op, e );
|
2000-09-26 02:59:15 +08:00
|
|
|
|
2005-01-11 23:59:13 +08:00
|
|
|
rs->sr_err = LDAP_REFERRAL;
|
|
|
|
|
2004-12-15 01:22:22 +08:00
|
|
|
#ifdef SLAP_ZONE_ALLOC
|
|
|
|
slap_zn_runlock(bdb->bi_cache.c_zctx, e);
|
|
|
|
#endif
|
2007-01-01 07:37:06 +08:00
|
|
|
bdb_cache_return_entry_r( bdb, e, &lock );
|
2000-09-28 10:27:49 +08:00
|
|
|
e = NULL;
|
2000-09-26 02:59:15 +08:00
|
|
|
|
2005-01-11 23:59:13 +08:00
|
|
|
if ( erefs ) {
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_ref = referral_rewrite( erefs, &matched_dn,
|
2005-01-14 13:57:58 +08:00
|
|
|
&op->o_req_dn, op->oq_search.rs_scope );
|
2002-01-14 09:43:17 +08:00
|
|
|
ber_bvarray_free( erefs );
|
2005-01-11 23:59:13 +08:00
|
|
|
|
|
|
|
if ( !rs->sr_ref ) {
|
|
|
|
rs->sr_text = "bad_referral object";
|
|
|
|
}
|
2001-11-05 14:24:11 +08:00
|
|
|
}
|
|
|
|
|
2004-11-17 22:53:03 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
LDAP_XSTRING(bdb_search) ": entry is referral\n",
|
2000-09-26 02:59:15 +08:00
|
|
|
0, 0, 0 );
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_matched = matched_dn.bv_val;
|
2005-01-14 13:57:58 +08:00
|
|
|
send_ldap_result( op, rs );
|
2000-09-26 02:59:15 +08:00
|
|
|
|
2005-01-11 23:59:13 +08:00
|
|
|
if ( !opinfo ) {
|
2004-06-23 10:00:00 +08:00
|
|
|
LOCK_ID_FREE (bdb->bi_dbenv, locker );
|
2005-01-11 23:59:13 +08:00
|
|
|
}
|
2003-03-30 17:03:54 +08:00
|
|
|
ber_bvarray_free( rs->sr_ref );
|
|
|
|
rs->sr_ref = NULL;
|
2002-01-06 01:49:59 +08:00
|
|
|
ber_memfree( matched_dn.bv_val );
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_matched = NULL;
|
2000-09-26 02:59:15 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2003-06-10 12:44:41 +08:00
|
|
|
if ( get_assert( op ) &&
|
|
|
|
( test_filter( op, e, get_assertion( op )) != LDAP_COMPARE_TRUE ))
|
|
|
|
{
|
|
|
|
rs->sr_err = LDAP_ASSERTION_FAILED;
|
2004-12-15 01:22:22 +08:00
|
|
|
#ifdef SLAP_ZONE_ALLOC
|
|
|
|
slap_zn_runlock(bdb->bi_cache.c_zctx, e);
|
|
|
|
#endif
|
2005-01-11 23:59:13 +08:00
|
|
|
if ( e != &e_root ) {
|
2007-01-01 07:37:06 +08:00
|
|
|
bdb_cache_return_entry_r(bdb, e, &lock);
|
2005-01-11 23:59:13 +08:00
|
|
|
}
|
2005-01-14 13:57:58 +08:00
|
|
|
send_ldap_result( op, rs );
|
2003-06-10 12:44:41 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2001-11-13 01:12:43 +08:00
|
|
|
/* compute it anyway; root does not use it */
|
2005-01-14 13:57:58 +08:00
|
|
|
stoptime = op->o_time + op->ors_tlimit;
|
2001-11-13 01:12:43 +08:00
|
|
|
|
2003-04-17 00:23:36 +08:00
|
|
|
/* need normalized dn below */
|
|
|
|
ber_dupbv( &realbase, &e->e_nname );
|
|
|
|
|
2003-04-17 19:03:21 +08:00
|
|
|
/* Copy info to base, must free entry before accessing the database
|
|
|
|
* in search_candidates, to avoid deadlocks.
|
|
|
|
*/
|
2003-04-23 02:22:51 +08:00
|
|
|
base.e_private = e->e_private;
|
2003-04-17 19:03:21 +08:00
|
|
|
base.e_nname = realbase;
|
|
|
|
base.e_id = e->e_id;
|
2003-04-17 00:23:36 +08:00
|
|
|
|
2004-12-15 01:22:22 +08:00
|
|
|
#ifdef SLAP_ZONE_ALLOC
|
|
|
|
slap_zn_runlock(bdb->bi_cache.c_zctx, e);
|
|
|
|
#endif
|
2004-04-08 20:15:26 +08:00
|
|
|
if ( e != &e_root ) {
|
2007-01-01 07:37:06 +08:00
|
|
|
bdb_cache_return_entry_r(bdb, e, &lock);
|
2003-04-17 00:23:36 +08:00
|
|
|
}
|
|
|
|
e = NULL;
|
|
|
|
|
2001-10-02 20:00:01 +08:00
|
|
|
/* select candidates */
|
2005-01-14 13:57:58 +08:00
|
|
|
if ( op->oq_search.rs_scope == LDAP_SCOPE_BASE ) {
|
2003-04-17 19:03:21 +08:00
|
|
|
rs->sr_err = base_candidate( op->o_bd, &base, candidates );
|
2000-09-26 02:59:15 +08:00
|
|
|
|
|
|
|
} else {
|
2003-04-18 11:36:52 +08:00
|
|
|
BDB_IDL_ZERO( candidates );
|
2003-04-17 17:23:53 +08:00
|
|
|
BDB_IDL_ZERO( scopes );
|
2005-01-14 13:57:58 +08:00
|
|
|
rs->sr_err = search_candidates( op, rs, &base,
|
2003-12-30 06:25:43 +08:00
|
|
|
locker, candidates, scopes );
|
2000-09-26 02:59:15 +08:00
|
|
|
}
|
|
|
|
|
2002-09-09 12:24:38 +08:00
|
|
|
/* start cursor at beginning of candidates.
|
2002-03-05 06:32:33 +08:00
|
|
|
*/
|
2002-09-09 12:24:38 +08:00
|
|
|
cursor = 0;
|
2000-09-26 02:59:15 +08:00
|
|
|
|
|
|
|
if ( candidates[0] == 0 ) {
|
2004-11-17 22:53:03 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
LDAP_XSTRING(bdb_search) ": no candidates\n",
|
2000-09-26 02:59:15 +08:00
|
|
|
0, 0, 0 );
|
|
|
|
|
2004-01-28 02:16:40 +08:00
|
|
|
goto nochange;
|
2000-09-26 02:59:15 +08:00
|
|
|
}
|
|
|
|
|
2001-10-02 20:00:01 +08:00
|
|
|
/* if not root and candidates exceed to-be-checked entries, abort */
|
2005-01-14 13:57:58 +08:00
|
|
|
if ( op->ors_limit /* isroot == FALSE */ &&
|
|
|
|
op->ors_limit->lms_s_unchecked != -1 &&
|
|
|
|
BDB_IDL_N(candidates) > (unsigned) op->ors_limit->lms_s_unchecked )
|
2004-03-09 02:12:45 +08:00
|
|
|
{
|
|
|
|
rs->sr_err = LDAP_ADMINLIMIT_EXCEEDED;
|
2005-01-14 13:57:58 +08:00
|
|
|
send_ldap_result( op, rs );
|
2004-03-09 02:12:45 +08:00
|
|
|
rs->sr_err = LDAP_SUCCESS;
|
|
|
|
goto done;
|
2001-10-02 20:00:01 +08:00
|
|
|
}
|
|
|
|
|
2005-01-14 13:57:58 +08:00
|
|
|
if ( op->ors_limit == NULL /* isroot == TRUE */ ||
|
|
|
|
!op->ors_limit->lms_s_pr_hide )
|
2004-06-09 13:20:57 +08:00
|
|
|
{
|
2002-11-22 04:49:02 +08:00
|
|
|
tentries = BDB_IDL_N(candidates);
|
|
|
|
}
|
|
|
|
|
2005-01-14 13:57:58 +08:00
|
|
|
if ( get_pagedresults( op ) > SLAP_CONTROL_IGNORED ) {
|
|
|
|
PagedResultsState *ps = op->o_pagedresults_state;
|
2004-08-24 17:19:33 +08:00
|
|
|
/* deferred cookie parsing */
|
2005-01-14 13:57:58 +08:00
|
|
|
rs->sr_err = parse_paged_cookie( op, rs );
|
2004-08-24 17:19:33 +08:00
|
|
|
if ( rs->sr_err != LDAP_SUCCESS ) {
|
2005-01-14 13:57:58 +08:00
|
|
|
send_ldap_result( op, rs );
|
2004-08-24 17:19:33 +08:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2004-11-23 21:08:45 +08:00
|
|
|
if ( (ID)( ps->ps_cookie ) == 0 ) {
|
2004-04-13 01:59:27 +08:00
|
|
|
id = bdb_idl_first( candidates, &cursor );
|
2004-04-09 19:44:28 +08:00
|
|
|
|
2002-11-21 10:16:53 +08:00
|
|
|
} else {
|
2004-11-23 21:08:45 +08:00
|
|
|
if ( ps->ps_size == 0 ) {
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LDAP_SUCCESS;
|
|
|
|
rs->sr_text = "search abandoned by pagedResult size=0";
|
2005-01-14 13:57:58 +08:00
|
|
|
send_ldap_result( op, rs );
|
2002-11-21 11:36:37 +08:00
|
|
|
goto done;
|
|
|
|
}
|
2002-11-21 10:16:53 +08:00
|
|
|
for ( id = bdb_idl_first( candidates, &cursor );
|
2004-06-09 13:20:57 +08:00
|
|
|
id != NOID &&
|
2004-11-23 21:08:45 +08:00
|
|
|
id <= (ID)( ps->ps_cookie );
|
2004-06-09 13:20:57 +08:00
|
|
|
id = bdb_idl_next( candidates, &cursor ) )
|
|
|
|
{
|
|
|
|
/* empty */;
|
|
|
|
}
|
2002-11-21 10:16:53 +08:00
|
|
|
}
|
2004-06-09 13:20:57 +08:00
|
|
|
|
2002-11-21 10:16:53 +08:00
|
|
|
if ( cursor == NOID ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
2004-11-17 22:53:03 +08:00
|
|
|
LDAP_XSTRING(bdb_search)
|
|
|
|
": no paged results candidates\n",
|
2002-11-21 10:16:53 +08:00
|
|
|
0, 0, 0 );
|
2005-01-14 13:57:58 +08:00
|
|
|
send_paged_response( op, rs, &lastid, 0 );
|
2002-11-21 10:16:53 +08:00
|
|
|
|
2003-08-30 01:02:53 +08:00
|
|
|
rs->sr_err = LDAP_OTHER;
|
2002-11-21 10:16:53 +08:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
goto loop_begin;
|
|
|
|
}
|
|
|
|
|
2001-06-15 15:08:37 +08:00
|
|
|
for ( id = bdb_idl_first( candidates, &cursor );
|
2005-01-14 13:49:45 +08:00
|
|
|
id != NOID ; id = bdb_idl_next( candidates, &cursor ) )
|
2000-09-26 02:59:15 +08:00
|
|
|
{
|
2005-07-11 00:14:28 +08:00
|
|
|
int scopeok;
|
2000-09-26 02:59:15 +08:00
|
|
|
|
2002-11-21 10:16:53 +08:00
|
|
|
loop_begin:
|
2004-10-09 17:26:16 +08:00
|
|
|
|
2004-11-26 05:16:54 +08:00
|
|
|
/* check for abandon */
|
2005-01-14 13:57:58 +08:00
|
|
|
if ( op->o_abandon ) {
|
2005-02-18 08:37:40 +08:00
|
|
|
rs->sr_err = SLAPD_ABANDON;
|
2004-11-26 05:16:54 +08:00
|
|
|
goto done;
|
|
|
|
}
|
2003-01-25 08:36:50 +08:00
|
|
|
|
2000-09-26 02:59:15 +08:00
|
|
|
/* check time limit */
|
2005-01-14 13:57:58 +08:00
|
|
|
if ( op->ors_tlimit != SLAP_NO_LIMIT
|
2004-06-12 19:33:21 +08:00
|
|
|
&& slap_get_time() > stoptime )
|
|
|
|
{
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LDAP_TIMELIMIT_EXCEEDED;
|
|
|
|
rs->sr_ref = rs->sr_v2ref;
|
2005-01-14 13:57:58 +08:00
|
|
|
send_ldap_result( op, rs );
|
2003-08-30 01:02:53 +08:00
|
|
|
rs->sr_err = LDAP_SUCCESS;
|
2000-09-26 02:59:15 +08:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2004-12-15 01:22:22 +08:00
|
|
|
fetch_entry_retry:
|
2003-03-30 17:03:54 +08:00
|
|
|
/* get the entry with reader lock */
|
2003-04-17 00:23:36 +08:00
|
|
|
ei = NULL;
|
2004-06-23 13:10:18 +08:00
|
|
|
rs->sr_err = bdb_cache_find_id( op, ltid,
|
2003-05-25 08:53:08 +08:00
|
|
|
id, &ei, 0, locker, &lock );
|
2000-09-26 02:59:15 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
if (rs->sr_err == LDAP_BUSY) {
|
|
|
|
rs->sr_text = "ldap server busy";
|
2005-01-14 13:57:58 +08:00
|
|
|
send_ldap_result( op, rs );
|
2003-03-30 17:03:54 +08:00
|
|
|
goto done;
|
2002-06-02 04:21:59 +08:00
|
|
|
|
2003-04-05 16:40:07 +08:00
|
|
|
} else if ( rs->sr_err == DB_LOCK_DEADLOCK
|
|
|
|
|| rs->sr_err == DB_LOCK_NOTGRANTED )
|
|
|
|
{
|
2004-12-15 01:22:22 +08:00
|
|
|
goto fetch_entry_retry;
|
2003-03-30 17:03:54 +08:00
|
|
|
}
|
2002-04-20 05:41:32 +08:00
|
|
|
|
2003-08-30 01:02:53 +08:00
|
|
|
if ( ei && rs->sr_err == LDAP_SUCCESS ) {
|
2003-04-17 00:23:36 +08:00
|
|
|
e = ei->bei_e;
|
|
|
|
} else {
|
|
|
|
e = NULL;
|
|
|
|
}
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
if ( e == NULL ) {
|
2004-11-26 05:16:54 +08:00
|
|
|
if( !BDB_IDL_IS_RANGE(candidates) ) {
|
2003-03-30 17:03:54 +08:00
|
|
|
/* only complain for non-range IDLs */
|
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
2004-11-17 22:53:03 +08:00
|
|
|
LDAP_XSTRING(bdb_search)
|
|
|
|
": candidate %ld not found\n",
|
2003-03-30 17:03:54 +08:00
|
|
|
(long) id, 0, 0 );
|
|
|
|
}
|
2000-09-26 02:59:15 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
goto loop_continue;
|
|
|
|
}
|
2000-09-26 02:59:15 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_entry = e;
|
2003-12-31 12:26:07 +08:00
|
|
|
|
2005-11-27 09:03:03 +08:00
|
|
|
if ( is_entry_subentry( e ) ) {
|
|
|
|
if( op->oq_search.rs_scope != LDAP_SCOPE_BASE ) {
|
|
|
|
if(!get_subentries_visibility( op )) {
|
2002-01-10 03:43:15 +08:00
|
|
|
/* only subentries are visible */
|
|
|
|
goto loop_continue;
|
|
|
|
}
|
2002-01-29 12:53:47 +08:00
|
|
|
|
2005-11-27 09:03:03 +08:00
|
|
|
} else if ( get_subentries( op ) &&
|
|
|
|
!get_subentries_visibility( op ))
|
|
|
|
{
|
2002-01-10 03:43:15 +08:00
|
|
|
/* only subentries are visible */
|
|
|
|
goto loop_continue;
|
|
|
|
}
|
2005-11-27 09:03:03 +08:00
|
|
|
|
|
|
|
} else if ( get_subentries_visibility( op )) {
|
|
|
|
/* only subentries are visible */
|
|
|
|
goto loop_continue;
|
2002-01-10 03:43:15 +08:00
|
|
|
}
|
|
|
|
|
2003-04-17 19:03:21 +08:00
|
|
|
/* Does this candidate actually satisfy the search scope?
|
|
|
|
*
|
|
|
|
* Note that we don't lock access to the bei_parent pointer.
|
|
|
|
* Since only leaf nodes can be deleted, the parent of any
|
|
|
|
* node will always be a valid node. Also since we have
|
|
|
|
* a Read lock on the data, it cannot be renamed out of the
|
|
|
|
* scope while we are looking at it, and unless we're using
|
|
|
|
* BDB_HIER, its parents cannot be moved either.
|
|
|
|
*/
|
2005-07-11 00:14:28 +08:00
|
|
|
scopeok = 0;
|
2005-01-14 13:57:58 +08:00
|
|
|
switch( op->ors_scope ) {
|
2003-04-17 19:03:21 +08:00
|
|
|
case LDAP_SCOPE_BASE:
|
|
|
|
/* This is always true, yes? */
|
2003-12-30 06:25:43 +08:00
|
|
|
if ( id == base.e_id ) scopeok = 1;
|
2003-04-17 19:03:21 +08:00
|
|
|
break;
|
2003-12-30 06:25:43 +08:00
|
|
|
|
2003-04-17 19:03:21 +08:00
|
|
|
case LDAP_SCOPE_ONELEVEL:
|
2003-12-30 06:25:43 +08:00
|
|
|
if ( ei->bei_parent->bei_id == base.e_id ) scopeok = 1;
|
2003-04-17 19:03:21 +08:00
|
|
|
break;
|
2003-12-30 06:25:43 +08:00
|
|
|
|
2004-03-18 09:06:39 +08:00
|
|
|
#ifdef LDAP_SCOPE_CHILDREN
|
2003-12-30 11:53:03 +08:00
|
|
|
case LDAP_SCOPE_CHILDREN:
|
|
|
|
if ( id == base.e_id ) break;
|
|
|
|
/* Fall-thru */
|
2004-03-18 09:06:39 +08:00
|
|
|
#endif
|
2003-12-30 06:25:43 +08:00
|
|
|
case LDAP_SCOPE_SUBTREE: {
|
2004-01-01 06:11:38 +08:00
|
|
|
EntryInfo *tmp;
|
2004-10-05 04:55:09 +08:00
|
|
|
for ( tmp = BEI(e); tmp; tmp = tmp->bei_parent ) {
|
2003-04-17 19:03:21 +08:00
|
|
|
if ( tmp->bei_id == base.e_id ) {
|
|
|
|
scopeok = 1;
|
|
|
|
break;
|
|
|
|
}
|
2003-12-30 06:25:43 +08:00
|
|
|
}
|
|
|
|
} break;
|
2003-04-17 19:03:21 +08:00
|
|
|
}
|
|
|
|
|
2003-04-05 14:35:16 +08:00
|
|
|
/* aliases were already dereferenced in candidate list */
|
2005-01-14 13:57:58 +08:00
|
|
|
if ( op->ors_deref & LDAP_DEREF_SEARCHING ) {
|
2003-04-05 15:50:01 +08:00
|
|
|
/* but if the search base is an alias, and we didn't
|
|
|
|
* deref it when finding, return it.
|
|
|
|
*/
|
2003-04-17 17:23:53 +08:00
|
|
|
if ( is_entry_alias(e) &&
|
2005-01-14 13:57:58 +08:00
|
|
|
((op->ors_deref & LDAP_DEREF_FINDING) ||
|
2003-12-30 06:25:43 +08:00
|
|
|
!bvmatch(&e->e_nname, &op->o_req_ndn)))
|
2003-04-05 16:40:07 +08:00
|
|
|
{
|
2003-04-05 15:50:01 +08:00
|
|
|
goto loop_continue;
|
2003-04-05 16:40:07 +08:00
|
|
|
}
|
2003-04-17 17:23:53 +08:00
|
|
|
|
|
|
|
/* scopes is only non-empty for onelevel or subtree */
|
2003-04-17 19:03:21 +08:00
|
|
|
if ( !scopeok && BDB_IDL_N(scopes) ) {
|
2003-04-17 17:23:53 +08:00
|
|
|
unsigned x;
|
2005-01-14 13:57:58 +08:00
|
|
|
if ( op->ors_scope == LDAP_SCOPE_ONELEVEL ) {
|
2003-12-30 11:53:03 +08:00
|
|
|
x = bdb_idl_search( scopes, e->e_id );
|
|
|
|
if ( scopes[x] == e->e_id ) scopeok = 1;
|
2003-04-17 17:23:53 +08:00
|
|
|
} else {
|
2003-12-30 11:53:03 +08:00
|
|
|
/* subtree, walk up the tree */
|
2003-04-17 17:23:53 +08:00
|
|
|
EntryInfo *tmp = BEI(e);
|
2003-12-30 06:25:43 +08:00
|
|
|
for (;tmp->bei_parent; tmp=tmp->bei_parent) {
|
|
|
|
x = bdb_idl_search( scopes, tmp->bei_id );
|
2003-04-17 17:23:53 +08:00
|
|
|
if ( scopes[x] == tmp->bei_id ) {
|
|
|
|
scopeok = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-09-26 02:59:15 +08:00
|
|
|
}
|
2003-04-17 19:03:21 +08:00
|
|
|
|
|
|
|
/* Not in scope, ignore it */
|
2004-11-26 05:16:54 +08:00
|
|
|
if ( !scopeok )
|
|
|
|
{
|
2003-04-17 19:03:21 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
2004-11-17 22:53:03 +08:00
|
|
|
LDAP_XSTRING(bdb_search)
|
|
|
|
": %ld scope not okay\n",
|
2003-04-17 19:03:21 +08:00
|
|
|
(long) id, 0, 0 );
|
|
|
|
goto loop_continue;
|
|
|
|
}
|
|
|
|
|
2000-09-26 02:59:15 +08:00
|
|
|
/*
|
|
|
|
* if it's a referral, add it to the list of referrals. only do
|
|
|
|
* this for non-base searches, and don't check the filter
|
|
|
|
* explicitly here since it's only a candidate anyway.
|
|
|
|
*/
|
2005-01-14 13:57:58 +08:00
|
|
|
if ( !manageDSAit && op->oq_search.rs_scope != LDAP_SCOPE_BASE
|
2003-04-17 19:03:21 +08:00
|
|
|
&& is_entry_referral( e ) )
|
2000-09-26 02:59:15 +08:00
|
|
|
{
|
2005-01-14 13:57:58 +08:00
|
|
|
BerVarray erefs = get_entry_referrals( op, e );
|
2003-12-30 11:53:03 +08:00
|
|
|
rs->sr_ref = referral_rewrite( erefs, &e->e_name, NULL,
|
2005-01-14 13:57:58 +08:00
|
|
|
op->oq_search.rs_scope == LDAP_SCOPE_ONELEVEL
|
2003-12-30 11:53:03 +08:00
|
|
|
? LDAP_SCOPE_BASE : LDAP_SCOPE_SUBTREE );
|
2002-06-02 04:01:32 +08:00
|
|
|
|
2005-01-14 13:57:58 +08:00
|
|
|
send_search_reference( op, rs );
|
2002-06-02 04:01:32 +08:00
|
|
|
|
2003-04-17 19:03:21 +08:00
|
|
|
ber_bvarray_free( rs->sr_ref );
|
|
|
|
ber_bvarray_free( erefs );
|
|
|
|
rs->sr_ref = NULL;
|
2000-09-26 02:59:15 +08:00
|
|
|
|
|
|
|
goto loop_continue;
|
|
|
|
}
|
|
|
|
|
2003-07-15 08:43:39 +08:00
|
|
|
if ( !manageDSAit && is_entry_glue( e )) {
|
2003-06-26 00:22:08 +08:00
|
|
|
goto loop_continue;
|
|
|
|
}
|
|
|
|
|
2000-09-26 02:59:15 +08:00
|
|
|
/* if it matches the filter and scope, send it */
|
2005-01-14 13:57:58 +08:00
|
|
|
rs->sr_err = test_filter( op, rs->sr_entry, op->oq_search.rs_filter );
|
2002-08-29 18:55:48 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
if ( rs->sr_err == LDAP_COMPARE_TRUE ) {
|
2003-04-17 19:03:21 +08:00
|
|
|
/* check size limit */
|
2005-01-14 13:57:58 +08:00
|
|
|
if ( get_pagedresults(op) > SLAP_CONTROL_IGNORED ) {
|
|
|
|
if ( rs->sr_nentries >= ((PagedResultsState *)op->o_pagedresults_state)->ps_size ) {
|
2005-08-15 19:27:42 +08:00
|
|
|
#ifdef SLAP_ZONE_ALLOC
|
|
|
|
slap_zn_runlock(bdb->bi_cache.c_zctx, e);
|
|
|
|
#endif
|
2007-01-01 07:37:06 +08:00
|
|
|
bdb_cache_return_entry_r( bdb, e, &lock );
|
2005-08-15 19:27:42 +08:00
|
|
|
e = NULL;
|
2005-01-14 13:57:58 +08:00
|
|
|
send_paged_response( op, rs, &lastid, tentries );
|
2003-04-17 19:03:21 +08:00
|
|
|
goto done;
|
2002-11-21 10:16:53 +08:00
|
|
|
}
|
2003-04-17 19:03:21 +08:00
|
|
|
lastid = id;
|
|
|
|
}
|
2000-09-26 02:59:15 +08:00
|
|
|
|
2003-04-17 19:03:21 +08:00
|
|
|
if (e) {
|
|
|
|
/* safe default */
|
2005-01-14 13:57:58 +08:00
|
|
|
rs->sr_attrs = op->oq_search.rs_attrs;
|
2005-01-14 13:49:45 +08:00
|
|
|
rs->sr_operational_attrs = NULL;
|
|
|
|
rs->sr_ctrls = NULL;
|
|
|
|
rs->sr_flags = 0;
|
|
|
|
rs->sr_err = LDAP_SUCCESS;
|
2005-11-26 06:17:24 +08:00
|
|
|
rs->sr_err = send_search_entry( op, rs );
|
2000-09-26 02:59:15 +08:00
|
|
|
|
2005-11-26 06:17:24 +08:00
|
|
|
switch ( rs->sr_err ) {
|
|
|
|
case LDAP_SUCCESS: /* entry sent ok */
|
2003-04-17 19:03:21 +08:00
|
|
|
break;
|
2005-11-26 06:17:24 +08:00
|
|
|
default: /* entry not sent */
|
2003-04-17 19:03:21 +08:00
|
|
|
break;
|
2005-11-26 06:17:24 +08:00
|
|
|
case LDAP_UNAVAILABLE:
|
|
|
|
case LDAP_SIZELIMIT_EXCEEDED:
|
2004-12-15 01:22:22 +08:00
|
|
|
#ifdef SLAP_ZONE_ALLOC
|
2005-01-14 13:49:45 +08:00
|
|
|
slap_zn_runlock(bdb->bi_cache.c_zctx, e);
|
2004-11-26 05:16:54 +08:00
|
|
|
#endif
|
2007-01-01 07:37:06 +08:00
|
|
|
bdb_cache_return_entry_r(bdb, e, &lock);
|
2003-04-17 19:03:21 +08:00
|
|
|
e = NULL;
|
|
|
|
rs->sr_entry = NULL;
|
2005-11-26 06:17:24 +08:00
|
|
|
if ( rs->sr_err == LDAP_SIZELIMIT_EXCEEDED ) {
|
2005-11-25 08:28:33 +08:00
|
|
|
rs->sr_ref = rs->sr_v2ref;
|
|
|
|
send_ldap_result( op, rs );
|
|
|
|
rs->sr_err = LDAP_SUCCESS;
|
2005-11-26 06:17:24 +08:00
|
|
|
|
|
|
|
} else {
|
2005-11-25 08:28:33 +08:00
|
|
|
rs->sr_err = LDAP_OTHER;
|
|
|
|
}
|
2003-04-17 19:03:21 +08:00
|
|
|
goto done;
|
2000-09-26 02:59:15 +08:00
|
|
|
}
|
|
|
|
}
|
2004-06-09 13:20:57 +08:00
|
|
|
|
2000-09-26 02:59:15 +08:00
|
|
|
} else {
|
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
2004-11-17 22:53:03 +08:00
|
|
|
LDAP_XSTRING(bdb_search)
|
|
|
|
": %ld does not match filter\n",
|
2001-10-14 00:55:54 +08:00
|
|
|
(long) id, 0, 0 );
|
2000-09-26 02:59:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
loop_continue:
|
|
|
|
if( e != NULL ) {
|
|
|
|
/* free reader lock */
|
2004-12-15 01:22:22 +08:00
|
|
|
#ifdef SLAP_ZONE_ALLOC
|
|
|
|
slap_zn_runlock(bdb->bi_cache.c_zctx, e);
|
|
|
|
#endif
|
2007-01-01 07:37:06 +08:00
|
|
|
bdb_cache_return_entry_r( bdb, e , &lock );
|
2002-09-06 08:29:20 +08:00
|
|
|
e = NULL;
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_entry = NULL;
|
2000-09-26 02:59:15 +08:00
|
|
|
}
|
|
|
|
}
|
2002-09-16 06:42:50 +08:00
|
|
|
|
2003-10-22 15:53:28 +08:00
|
|
|
nochange:
|
2005-01-14 13:49:45 +08:00
|
|
|
rs->sr_ctrls = NULL;
|
|
|
|
rs->sr_ref = rs->sr_v2ref;
|
|
|
|
rs->sr_err = (rs->sr_v2ref == NULL) ? LDAP_SUCCESS : LDAP_REFERRAL;
|
|
|
|
rs->sr_rspoid = NULL;
|
2005-01-14 13:57:58 +08:00
|
|
|
if ( get_pagedresults(op) > SLAP_CONTROL_IGNORED ) {
|
|
|
|
send_paged_response( op, rs, NULL, 0 );
|
2005-01-14 13:49:45 +08:00
|
|
|
} else {
|
2005-01-14 13:57:58 +08:00
|
|
|
send_ldap_result( op, rs );
|
2004-10-09 17:26:16 +08:00
|
|
|
}
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LDAP_SUCCESS;
|
2000-09-26 02:59:15 +08:00
|
|
|
|
|
|
|
done:
|
2004-06-23 10:00:00 +08:00
|
|
|
if ( !opinfo )
|
|
|
|
LOCK_ID_FREE( bdb->bi_dbenv, locker );
|
2002-06-01 04:49:19 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
if( rs->sr_v2ref ) {
|
|
|
|
ber_bvarray_free( rs->sr_v2ref );
|
|
|
|
rs->sr_v2ref = NULL;
|
|
|
|
}
|
2001-12-30 18:47:28 +08:00
|
|
|
if( realbase.bv_val ) ch_free( realbase.bv_val );
|
2000-09-26 02:59:15 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
return rs->sr_err;
|
2000-09-26 02:59:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int base_candidate(
|
2000-09-28 06:28:59 +08:00
|
|
|
BackendDB *be,
|
2000-09-26 02:59:15 +08:00
|
|
|
Entry *e,
|
|
|
|
ID *ids )
|
|
|
|
{
|
2000-09-27 03:26:08 +08:00
|
|
|
Debug(LDAP_DEBUG_ARGS, "base_candidates: base: \"%s\" (0x%08lx)\n",
|
2003-04-17 19:03:21 +08:00
|
|
|
e->e_nname.bv_val, (long) e->e_id, 0);
|
2000-09-26 02:59:15 +08:00
|
|
|
|
|
|
|
ids[0] = 1;
|
|
|
|
ids[1] = e->e_id;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-08-26 20:04:53 +08:00
|
|
|
/* Look for "objectClass Present" in this filter.
|
|
|
|
* Also count depth of filter tree while we're at it.
|
2001-11-27 03:32:39 +08:00
|
|
|
*/
|
|
|
|
static int oc_filter(
|
2002-03-18 19:40:58 +08:00
|
|
|
Filter *f,
|
|
|
|
int cur,
|
2003-12-30 11:53:03 +08:00
|
|
|
int *max )
|
2001-11-27 03:32:39 +08:00
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
|
2005-07-18 14:22:33 +08:00
|
|
|
assert( f != NULL );
|
2003-12-01 15:59:30 +08:00
|
|
|
|
2002-03-18 19:40:58 +08:00
|
|
|
if( cur > *max ) *max = cur;
|
|
|
|
|
2003-12-30 11:53:03 +08:00
|
|
|
switch( f->f_choice ) {
|
2002-08-26 20:04:53 +08:00
|
|
|
case LDAP_FILTER_PRESENT:
|
2002-09-10 07:25:22 +08:00
|
|
|
if (f->f_desc == slap_schema.si_ad_objectClass) {
|
2001-11-27 03:32:39 +08:00
|
|
|
rc = 1;
|
2002-09-10 07:25:22 +08:00
|
|
|
}
|
2001-11-27 03:32:39 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LDAP_FILTER_AND:
|
|
|
|
case LDAP_FILTER_OR:
|
2002-03-18 19:40:58 +08:00
|
|
|
cur++;
|
2003-12-30 11:53:03 +08:00
|
|
|
for ( f=f->f_and; f; f=f->f_next ) {
|
2002-09-10 07:25:22 +08:00
|
|
|
(void) oc_filter(f, cur, max);
|
|
|
|
}
|
2001-11-27 03:32:39 +08:00
|
|
|
break;
|
2002-09-10 07:25:22 +08:00
|
|
|
|
2001-11-27 03:32:39 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2003-04-18 15:43:07 +08:00
|
|
|
static void search_stack_free( void *key, void *data )
|
2002-12-11 01:59:21 +08:00
|
|
|
{
|
2003-04-18 15:43:07 +08:00
|
|
|
ber_memfree_x(data, NULL);
|
2002-12-11 01:59:21 +08:00
|
|
|
}
|
|
|
|
|
2003-12-30 06:25:43 +08:00
|
|
|
static void *search_stack( Operation *op )
|
2002-12-11 01:59:21 +08:00
|
|
|
{
|
2003-03-30 17:03:54 +08:00
|
|
|
struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
|
2002-12-11 01:59:21 +08:00
|
|
|
void *ret = NULL;
|
|
|
|
|
|
|
|
if ( op->o_threadctx ) {
|
|
|
|
ldap_pvt_thread_pool_getkey( op->o_threadctx, search_stack,
|
|
|
|
&ret, NULL );
|
|
|
|
} else {
|
|
|
|
ret = bdb->bi_search_stack;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !ret ) {
|
2003-04-05 16:40:07 +08:00
|
|
|
ret = ch_malloc( bdb->bi_search_stack_depth * BDB_IDL_UM_SIZE
|
2003-04-05 17:57:21 +08:00
|
|
|
* sizeof( ID ) );
|
2002-12-11 01:59:21 +08:00
|
|
|
if ( op->o_threadctx ) {
|
|
|
|
ldap_pvt_thread_pool_setkey( op->o_threadctx, search_stack,
|
|
|
|
ret, search_stack_free );
|
|
|
|
} else {
|
|
|
|
bdb->bi_search_stack = ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2000-09-26 03:59:45 +08:00
|
|
|
static int search_candidates(
|
2003-03-31 02:49:25 +08:00
|
|
|
Operation *op,
|
2003-04-05 14:35:16 +08:00
|
|
|
SlapReply *rs,
|
2000-09-26 03:59:45 +08:00
|
|
|
Entry *e,
|
2003-04-05 14:35:16 +08:00
|
|
|
u_int32_t locker,
|
2003-04-17 17:23:53 +08:00
|
|
|
ID *ids,
|
|
|
|
ID *scopes )
|
2000-09-26 03:59:45 +08:00
|
|
|
{
|
2003-03-30 17:03:54 +08:00
|
|
|
struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
|
2002-03-18 19:40:58 +08:00
|
|
|
int rc, depth = 1;
|
2003-05-01 19:59:08 +08:00
|
|
|
Filter f, rf, xf, nf;
|
2002-03-18 19:40:58 +08:00
|
|
|
ID *stack;
|
2005-03-29 08:12:05 +08:00
|
|
|
#ifdef LDAP_COMP_MATCH
|
2005-02-17 01:00:11 +08:00
|
|
|
AttributeAssertion aa_ref = { NULL, BER_BVNULL, NULL };
|
2005-03-29 08:12:05 +08:00
|
|
|
#else
|
|
|
|
AttributeAssertion aa_ref = { NULL, BER_BVNULL };
|
|
|
|
#endif
|
2002-01-29 12:53:47 +08:00
|
|
|
Filter sf;
|
2005-03-29 08:12:05 +08:00
|
|
|
#ifdef LDAP_COMP_MATCH
|
2005-02-17 01:00:11 +08:00
|
|
|
AttributeAssertion aa_subentry = { NULL, BER_BVNULL, NULL };
|
2005-03-29 08:12:05 +08:00
|
|
|
#else
|
|
|
|
AttributeAssertion aa_subentry = { NULL, BER_BVNULL };
|
2002-01-29 12:53:47 +08:00
|
|
|
#endif
|
2000-09-28 06:28:59 +08:00
|
|
|
|
2002-01-10 03:21:07 +08:00
|
|
|
/*
|
|
|
|
* This routine takes as input a filter (user-filter)
|
|
|
|
* and rewrites it as follows:
|
|
|
|
* (&(scope=DN)[(objectClass=subentry)]
|
|
|
|
* (|[(objectClass=referral)(objectClass=alias)](user-filter))
|
|
|
|
*/
|
|
|
|
|
2000-09-28 06:28:59 +08:00
|
|
|
Debug(LDAP_DEBUG_TRACE,
|
|
|
|
"search_candidates: base=\"%s\" (0x%08lx) scope=%d\n",
|
2003-04-17 19:03:21 +08:00
|
|
|
e->e_nname.bv_val, (long) e->e_id, op->oq_search.rs_scope );
|
2000-09-28 06:28:59 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
xf.f_or = op->oq_search.rs_filter;
|
2000-09-28 06:28:59 +08:00
|
|
|
xf.f_choice = LDAP_FILTER_OR;
|
|
|
|
xf.f_next = NULL;
|
|
|
|
|
2002-08-26 20:04:53 +08:00
|
|
|
/* If the user's filter uses objectClass=*,
|
|
|
|
* these clauses are redundant.
|
2001-11-27 03:32:39 +08:00
|
|
|
*/
|
2003-04-05 16:40:07 +08:00
|
|
|
if (!oc_filter(op->oq_search.rs_filter, 1, &depth)
|
2005-01-14 13:49:45 +08:00
|
|
|
&& !get_subentries_visibility(op)) {
|
2003-02-09 13:39:21 +08:00
|
|
|
if( !get_manageDSAit(op) && !get_domainScope(op) ) {
|
|
|
|
/* match referral objects */
|
2004-07-12 06:55:57 +08:00
|
|
|
struct berval bv_ref = BER_BVC( "referral" );
|
2001-11-27 11:41:03 +08:00
|
|
|
rf.f_choice = LDAP_FILTER_EQUALITY;
|
|
|
|
rf.f_ava = &aa_ref;
|
|
|
|
rf.f_av_desc = slap_schema.si_ad_objectClass;
|
2001-12-29 23:01:10 +08:00
|
|
|
rf.f_av_value = bv_ref;
|
2001-11-27 11:41:03 +08:00
|
|
|
rf.f_next = xf.f_or;
|
|
|
|
xf.f_or = &rf;
|
2003-04-05 14:35:16 +08:00
|
|
|
depth++;
|
2001-11-27 11:41:03 +08:00
|
|
|
}
|
2001-11-27 03:32:39 +08:00
|
|
|
}
|
2000-09-26 03:59:45 +08:00
|
|
|
|
2003-04-05 14:35:16 +08:00
|
|
|
f.f_next = NULL;
|
|
|
|
f.f_choice = LDAP_FILTER_AND;
|
|
|
|
f.f_and = &nf;
|
|
|
|
/* Dummy; we compute scope separately now */
|
2003-04-18 11:36:52 +08:00
|
|
|
nf.f_choice = SLAPD_FILTER_COMPUTED;
|
2003-05-13 09:16:26 +08:00
|
|
|
nf.f_result = LDAP_SUCCESS;
|
2003-12-30 11:53:03 +08:00
|
|
|
nf.f_next = ( xf.f_or == op->oq_search.rs_filter )
|
2003-04-05 16:40:07 +08:00
|
|
|
? op->oq_search.rs_filter : &xf ;
|
2003-04-05 14:35:16 +08:00
|
|
|
/* Filter depth increased again, adding dummy clause */
|
2002-03-18 19:40:58 +08:00
|
|
|
depth++;
|
2002-01-10 03:21:07 +08:00
|
|
|
|
|
|
|
if( get_subentries_visibility( op ) ) {
|
2004-11-10 11:52:42 +08:00
|
|
|
struct berval bv_subentry = BER_BVC( "subentry" );
|
2002-01-10 03:21:07 +08:00
|
|
|
sf.f_choice = LDAP_FILTER_EQUALITY;
|
|
|
|
sf.f_ava = &aa_subentry;
|
|
|
|
sf.f_av_desc = slap_schema.si_ad_objectClass;
|
|
|
|
sf.f_av_value = bv_subentry;
|
2003-04-18 11:36:52 +08:00
|
|
|
sf.f_next = nf.f_next;
|
2003-04-05 14:35:16 +08:00
|
|
|
nf.f_next = &sf;
|
2002-01-10 03:21:07 +08:00
|
|
|
}
|
2001-06-15 15:08:37 +08:00
|
|
|
|
2002-03-18 19:40:58 +08:00
|
|
|
/* Allocate IDL stack, plus 1 more for former tmp */
|
2002-12-11 04:33:49 +08:00
|
|
|
if ( depth+1 > bdb->bi_search_stack_depth ) {
|
2002-12-11 01:59:21 +08:00
|
|
|
stack = ch_malloc( (depth + 1) * BDB_IDL_UM_SIZE * sizeof( ID ) );
|
|
|
|
} else {
|
2005-01-14 13:57:58 +08:00
|
|
|
stack = search_stack( op );
|
2002-12-11 01:59:21 +08:00
|
|
|
}
|
2002-03-18 19:40:58 +08:00
|
|
|
|
2003-04-05 14:35:16 +08:00
|
|
|
if( op->ors_deref & LDAP_DEREF_SEARCHING ) {
|
2003-05-01 19:59:08 +08:00
|
|
|
rc = search_aliases( op, rs, e, locker, ids, scopes, stack );
|
2003-04-05 14:35:16 +08:00
|
|
|
} else {
|
2003-05-01 19:59:08 +08:00
|
|
|
rc = bdb_dn2idl( op, e, ids, stack );
|
2003-04-05 14:35:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( rc == LDAP_SUCCESS ) {
|
2003-04-11 09:29:28 +08:00
|
|
|
rc = bdb_filter_candidates( op, &f, ids,
|
2003-04-05 16:40:07 +08:00
|
|
|
stack, stack+BDB_IDL_UM_SIZE );
|
2003-04-05 14:35:16 +08:00
|
|
|
}
|
2002-03-18 19:40:58 +08:00
|
|
|
|
2002-12-11 04:33:49 +08:00
|
|
|
if ( depth+1 > bdb->bi_search_stack_depth ) {
|
2002-12-11 01:59:21 +08:00
|
|
|
ch_free( stack );
|
|
|
|
}
|
2000-09-27 06:22:42 +08:00
|
|
|
|
2002-03-05 06:32:33 +08:00
|
|
|
if( rc ) {
|
|
|
|
Debug(LDAP_DEBUG_TRACE,
|
|
|
|
"bdb_search_candidates: failed (rc=%d)\n",
|
|
|
|
rc, NULL, NULL );
|
|
|
|
|
|
|
|
} else {
|
|
|
|
Debug(LDAP_DEBUG_TRACE,
|
|
|
|
"bdb_search_candidates: id=%ld first=%ld last=%ld\n",
|
|
|
|
(long) ids[0],
|
|
|
|
(long) BDB_IDL_FIRST(ids),
|
|
|
|
(long) BDB_IDL_LAST(ids) );
|
|
|
|
}
|
2000-09-28 06:28:59 +08:00
|
|
|
|
|
|
|
return rc;
|
2000-09-26 03:59:45 +08:00
|
|
|
}
|
2002-08-29 18:55:48 +08:00
|
|
|
|
2004-08-24 17:19:33 +08:00
|
|
|
static int
|
|
|
|
parse_paged_cookie( Operation *op, SlapReply *rs )
|
|
|
|
{
|
|
|
|
LDAPControl **c;
|
|
|
|
int rc = LDAP_SUCCESS;
|
|
|
|
ber_tag_t tag;
|
|
|
|
ber_int_t size;
|
|
|
|
BerElement *ber;
|
|
|
|
struct berval cookie = BER_BVNULL;
|
2004-11-23 21:08:45 +08:00
|
|
|
PagedResultsState *ps = op->o_pagedresults_state;
|
2004-08-24 17:19:33 +08:00
|
|
|
|
|
|
|
/* this function must be invoked only if the pagedResults
|
|
|
|
* control has been detected, parsed and partially checked
|
|
|
|
* by the frontend */
|
2004-11-23 21:08:45 +08:00
|
|
|
assert( get_pagedresults( op ) > SLAP_CONTROL_IGNORED );
|
2004-08-24 17:19:33 +08:00
|
|
|
|
|
|
|
/* look for the appropriate ctrl structure */
|
|
|
|
for ( c = op->o_ctrls; c[0] != NULL; c++ ) {
|
|
|
|
if ( strcmp( c[0]->ldctl_oid, LDAP_CONTROL_PAGEDRESULTS ) == 0 )
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( c[0] == NULL ) {
|
|
|
|
rs->sr_text = "missing pagedResults control";
|
|
|
|
return LDAP_PROTOCOL_ERROR;
|
|
|
|
}
|
|
|
|
|
2004-11-05 15:48:15 +08:00
|
|
|
/* Tested by frontend */
|
2004-08-24 17:19:33 +08:00
|
|
|
assert( c[0]->ldctl_value.bv_len > 0 );
|
|
|
|
|
|
|
|
/* Parse the control value
|
|
|
|
* realSearchControlValue ::= SEQUENCE {
|
|
|
|
* size INTEGER (0..maxInt),
|
|
|
|
* -- requested page size from client
|
|
|
|
* -- result set size estimate from server
|
|
|
|
* cookie OCTET STRING
|
|
|
|
* }
|
|
|
|
*/
|
|
|
|
ber = ber_init( &c[0]->ldctl_value );
|
|
|
|
if ( ber == NULL ) {
|
|
|
|
rs->sr_text = "internal error";
|
|
|
|
return LDAP_OTHER;
|
|
|
|
}
|
|
|
|
|
|
|
|
tag = ber_scanf( ber, "{im}", &size, &cookie );
|
|
|
|
|
2004-11-05 15:48:15 +08:00
|
|
|
/* Tested by frontend */
|
2004-08-24 17:19:33 +08:00
|
|
|
assert( tag != LBER_ERROR );
|
|
|
|
assert( size >= 0 );
|
|
|
|
|
|
|
|
/* cookie decoding/checks deferred to backend... */
|
|
|
|
if ( cookie.bv_len ) {
|
|
|
|
PagedResultsCookie reqcookie;
|
|
|
|
if( cookie.bv_len != sizeof( reqcookie ) ) {
|
|
|
|
/* bad cookie */
|
|
|
|
rs->sr_text = "paged results cookie is invalid";
|
|
|
|
rc = LDAP_PROTOCOL_ERROR;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
AC_MEMCPY( &reqcookie, cookie.bv_val, sizeof( reqcookie ));
|
|
|
|
|
2004-11-23 21:08:45 +08:00
|
|
|
if ( reqcookie > ps->ps_cookie ) {
|
2004-08-24 17:19:33 +08:00
|
|
|
/* bad cookie */
|
|
|
|
rs->sr_text = "paged results cookie is invalid";
|
|
|
|
rc = LDAP_PROTOCOL_ERROR;
|
|
|
|
goto done;
|
|
|
|
|
2004-11-23 21:08:45 +08:00
|
|
|
} else if ( reqcookie < ps->ps_cookie ) {
|
2004-08-24 17:19:33 +08:00
|
|
|
rs->sr_text = "paged results cookie is invalid or old";
|
|
|
|
rc = LDAP_UNWILLING_TO_PERFORM;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
/* Initial request. Initialize state. */
|
|
|
|
#if 0
|
|
|
|
if ( op->o_conn->c_pagedresults_state.ps_cookie != 0 ) {
|
|
|
|
/* There's another pagedResults control on the
|
|
|
|
* same connection; reject new pagedResults controls
|
|
|
|
* (allowed by RFC2696) */
|
|
|
|
rs->sr_text = "paged results cookie unavailable; try later";
|
|
|
|
rc = LDAP_UNWILLING_TO_PERFORM;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
#endif
|
2004-11-23 21:08:45 +08:00
|
|
|
ps->ps_cookie = 0;
|
|
|
|
ps->ps_count = 0;
|
2004-08-24 17:19:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
done:;
|
|
|
|
(void)ber_free( ber, 1 );
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2002-11-21 10:16:53 +08:00
|
|
|
static void
|
2004-06-09 13:20:57 +08:00
|
|
|
send_paged_response(
|
2002-11-21 10:16:53 +08:00
|
|
|
Operation *op,
|
2003-03-30 17:03:54 +08:00
|
|
|
SlapReply *rs,
|
2004-06-13 02:22:53 +08:00
|
|
|
ID *lastid,
|
2002-11-22 04:49:02 +08:00
|
|
|
int tentries )
|
2002-11-21 10:16:53 +08:00
|
|
|
{
|
|
|
|
LDAPControl ctrl, *ctrls[2];
|
2003-10-12 14:07:02 +08:00
|
|
|
BerElementBuffer berbuf;
|
|
|
|
BerElement *ber = (BerElement *)&berbuf;
|
2002-11-21 10:16:53 +08:00
|
|
|
PagedResultsCookie respcookie;
|
2004-06-19 07:07:56 +08:00
|
|
|
struct berval cookie;
|
2002-11-21 10:16:53 +08:00
|
|
|
|
2004-06-19 07:12:03 +08:00
|
|
|
Debug(LDAP_DEBUG_ARGS,
|
|
|
|
"send_paged_response: lastid=0x%08lx nentries=%d\n",
|
|
|
|
lastid ? *lastid : 0, rs->sr_nentries, NULL );
|
2002-11-21 10:16:53 +08:00
|
|
|
|
2004-07-12 06:55:57 +08:00
|
|
|
BER_BVZERO( &ctrl.ldctl_value );
|
2002-11-21 10:16:53 +08:00
|
|
|
ctrls[0] = &ctrl;
|
|
|
|
ctrls[1] = NULL;
|
|
|
|
|
2002-12-19 03:17:15 +08:00
|
|
|
ber_init2( ber, NULL, LBER_USE_DER );
|
2002-11-21 10:16:53 +08:00
|
|
|
|
2004-06-13 02:22:53 +08:00
|
|
|
if ( lastid ) {
|
|
|
|
respcookie = ( PagedResultsCookie )(*lastid);
|
|
|
|
cookie.bv_len = sizeof( respcookie );
|
|
|
|
cookie.bv_val = (char *)&respcookie;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
respcookie = ( PagedResultsCookie )0;
|
2004-07-12 06:55:57 +08:00
|
|
|
BER_BVSTR( &cookie, "" );
|
2004-06-13 02:22:53 +08:00
|
|
|
}
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
op->o_conn->c_pagedresults_state.ps_cookie = respcookie;
|
2004-06-09 13:20:57 +08:00
|
|
|
op->o_conn->c_pagedresults_state.ps_count =
|
2005-04-01 10:39:01 +08:00
|
|
|
((PagedResultsState *)op->o_pagedresults_state)->ps_count +
|
|
|
|
rs->sr_nentries;
|
2002-11-21 10:16:53 +08:00
|
|
|
|
2004-06-19 07:07:56 +08:00
|
|
|
/* return size of 0 -- no estimate */
|
|
|
|
ber_printf( ber, "{iO}", 0, &cookie );
|
2002-11-21 10:16:53 +08:00
|
|
|
|
2003-01-19 21:10:17 +08:00
|
|
|
if ( ber_flatten2( ber, &ctrls[0]->ldctl_value, 0 ) == -1 ) {
|
2002-11-21 10:16:53 +08:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctrls[0]->ldctl_oid = LDAP_CONTROL_PAGEDRESULTS;
|
|
|
|
ctrls[0]->ldctl_iscritical = 0;
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_ctrls = ctrls;
|
|
|
|
rs->sr_err = LDAP_SUCCESS;
|
2003-04-01 12:12:18 +08:00
|
|
|
send_ldap_result( op, rs );
|
2004-06-12 20:29:18 +08:00
|
|
|
rs->sr_ctrls = NULL;
|
2002-11-21 10:16:53 +08:00
|
|
|
|
|
|
|
done:
|
2002-12-19 03:17:15 +08:00
|
|
|
(void) ber_free_buf( ber );
|
2004-04-09 19:44:28 +08:00
|
|
|
}
|
|
|
|
|