2001-07-15 01:34:24 +08:00
|
|
|
/* search.c - monitor backend search function */
|
2003-11-27 10:35:20 +08:00
|
|
|
/* $OpenLDAP$ */
|
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2019-01-15 02:46:16 +08:00
|
|
|
* Copyright 2001-2019 The OpenLDAP Foundation.
|
2003-12-09 01:41:40 +08:00
|
|
|
* Portions Copyright 2001-2003 Pierangelo Masarati.
|
2003-11-27 10:35: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 file LICENSE in the
|
|
|
|
* top-level directory of the distribution or, alternatively, at
|
|
|
|
* <http://www.OpenLDAP.org/license.html>.
|
|
|
|
*/
|
|
|
|
/* ACKNOWLEDGEMENTS:
|
|
|
|
* This work was initially developed by Pierangelo Masarati for inclusion
|
|
|
|
* in OpenLDAP Software.
|
2001-07-15 01:34:24 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/socket.h>
|
|
|
|
|
|
|
|
#include "slap.h"
|
|
|
|
#include "back-monitor.h"
|
|
|
|
#include "proto-back-monitor.h"
|
|
|
|
|
2011-01-13 09:11:08 +08:00
|
|
|
static void
|
|
|
|
monitor_find_children(
|
|
|
|
Operation *op,
|
|
|
|
SlapReply *rs,
|
|
|
|
Entry *e_parent,
|
|
|
|
Entry **nonv,
|
|
|
|
Entry **vol
|
|
|
|
)
|
|
|
|
{
|
|
|
|
monitor_entry_t *mp;
|
2011-02-09 01:20:44 +08:00
|
|
|
|
2011-01-13 09:11:08 +08:00
|
|
|
mp = ( monitor_entry_t * )e_parent->e_private;
|
|
|
|
*nonv = mp->mp_children;
|
|
|
|
|
|
|
|
if ( MONITOR_HAS_VOLATILE_CH( mp ) ) {
|
|
|
|
monitor_entry_create( op, rs, NULL, e_parent, vol );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-07-15 01:34:24 +08:00
|
|
|
static int
|
|
|
|
monitor_send_children(
|
2003-04-01 03:45:52 +08:00
|
|
|
Operation *op,
|
|
|
|
SlapReply *rs,
|
2011-01-13 09:11:08 +08:00
|
|
|
Entry *e_nonvolatile,
|
|
|
|
Entry *e_ch,
|
2006-09-09 08:00:44 +08:00
|
|
|
int sub )
|
2001-07-15 01:34:24 +08:00
|
|
|
{
|
2004-11-09 02:52:27 +08:00
|
|
|
monitor_info_t *mi = ( monitor_info_t * )op->o_bd->be_private;
|
2005-07-18 06:19:20 +08:00
|
|
|
Entry *e,
|
2011-01-13 09:11:08 +08:00
|
|
|
*e_tmp;
|
2004-11-09 02:52:27 +08:00
|
|
|
monitor_entry_t *mp;
|
2005-07-18 06:19:20 +08:00
|
|
|
int rc,
|
|
|
|
nonvolatile = 0;
|
2001-07-15 01:34:24 +08:00
|
|
|
|
2011-01-13 09:11:08 +08:00
|
|
|
e = e_nonvolatile;
|
2001-07-15 01:34:24 +08:00
|
|
|
|
2001-12-23 03:14:10 +08:00
|
|
|
/* no volatile entries? */
|
|
|
|
if ( e_ch == NULL ) {
|
|
|
|
/* no persistent entries? return */
|
|
|
|
if ( e == NULL ) {
|
2005-04-09 07:20:37 +08:00
|
|
|
return LDAP_SUCCESS;
|
2001-12-23 03:14:10 +08:00
|
|
|
}
|
2011-01-13 06:53:43 +08:00
|
|
|
|
2001-12-23 03:14:10 +08:00
|
|
|
/* volatile entries */
|
|
|
|
} else {
|
|
|
|
/* if no persistent, return only volatile */
|
|
|
|
if ( e == NULL ) {
|
|
|
|
e = e_ch;
|
|
|
|
|
|
|
|
/* else append persistent to volatile */
|
|
|
|
} else {
|
|
|
|
e_tmp = e_ch;
|
|
|
|
do {
|
2004-11-09 02:52:27 +08:00
|
|
|
mp = ( monitor_entry_t * )e_tmp->e_private;
|
2001-12-23 03:14:10 +08:00
|
|
|
e_tmp = mp->mp_next;
|
|
|
|
|
|
|
|
if ( e_tmp == NULL ) {
|
|
|
|
mp->mp_next = e;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while ( e_tmp );
|
|
|
|
e = e_ch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* return entries */
|
2011-01-13 10:23:04 +08:00
|
|
|
for ( ; e != NULL; e = e_tmp ) {
|
2011-01-13 09:11:08 +08:00
|
|
|
Entry *sub_nv = NULL, *sub_ch = NULL;
|
2011-01-13 10:23:04 +08:00
|
|
|
|
|
|
|
monitor_cache_lock( e );
|
2005-04-28 05:30:35 +08:00
|
|
|
monitor_entry_update( op, rs, e );
|
2005-04-09 07:20:37 +08:00
|
|
|
|
2011-01-13 06:53:43 +08:00
|
|
|
if ( e == e_nonvolatile )
|
|
|
|
nonvolatile = 1;
|
|
|
|
|
2011-01-13 06:28:46 +08:00
|
|
|
mp = ( monitor_entry_t * )e->e_private;
|
|
|
|
e_tmp = mp->mp_next;
|
2005-07-18 06:19:20 +08:00
|
|
|
|
2011-01-13 06:28:46 +08:00
|
|
|
if ( op->o_abandon ) {
|
|
|
|
monitor_cache_release( mi, e );
|
|
|
|
rc = SLAPD_ABANDON;
|
|
|
|
goto freeout;
|
2005-04-09 07:20:37 +08:00
|
|
|
}
|
2011-01-13 06:28:46 +08:00
|
|
|
|
2011-01-13 09:11:08 +08:00
|
|
|
if ( sub )
|
|
|
|
monitor_find_children( op, rs, e, &sub_nv, &sub_ch );
|
|
|
|
|
2003-04-01 03:45:52 +08:00
|
|
|
rc = test_filter( op, e, op->oq_search.rs_filter );
|
2001-07-15 01:34:24 +08:00
|
|
|
if ( rc == LDAP_COMPARE_TRUE ) {
|
2003-04-01 03:45:52 +08:00
|
|
|
rs->sr_entry = e;
|
2011-01-13 09:11:08 +08:00
|
|
|
rs->sr_flags = REP_ENTRY_MUSTRELEASE;
|
2005-11-25 08:28:33 +08:00
|
|
|
rc = send_search_entry( op, rs );
|
2011-01-13 06:48:30 +08:00
|
|
|
if ( rc ) {
|
2011-01-13 10:23:04 +08:00
|
|
|
for ( e = sub_ch; e != NULL; e = sub_nv ) {
|
|
|
|
mp = ( monitor_entry_t * )e->e_private;
|
|
|
|
sub_nv = mp->mp_next;
|
|
|
|
monitor_cache_lock( e );
|
|
|
|
monitor_cache_release( mi, e );
|
|
|
|
}
|
2011-01-13 06:28:46 +08:00
|
|
|
goto freeout;
|
2011-01-13 06:48:30 +08:00
|
|
|
}
|
2011-01-13 09:11:08 +08:00
|
|
|
} else {
|
|
|
|
monitor_cache_release( mi, e );
|
2001-07-15 01:34:24 +08:00
|
|
|
}
|
|
|
|
|
2005-07-18 06:19:20 +08:00
|
|
|
if ( sub ) {
|
2011-01-13 09:11:08 +08:00
|
|
|
rc = monitor_send_children( op, rs, sub_nv, sub_ch, sub );
|
2001-07-15 01:34:24 +08:00
|
|
|
if ( rc ) {
|
2011-01-13 06:28:46 +08:00
|
|
|
freeout:
|
2005-07-18 06:19:20 +08:00
|
|
|
if ( nonvolatile == 0 ) {
|
2005-07-20 08:50:35 +08:00
|
|
|
for ( ; e_tmp != NULL; ) {
|
2005-07-18 06:19:20 +08:00
|
|
|
mp = ( monitor_entry_t * )e_tmp->e_private;
|
|
|
|
e = e_tmp;
|
|
|
|
e_tmp = mp->mp_next;
|
2011-01-13 06:54:58 +08:00
|
|
|
monitor_cache_lock( e );
|
2005-07-18 06:19:20 +08:00
|
|
|
monitor_cache_release( mi, e );
|
|
|
|
|
|
|
|
if ( e_tmp == e_nonvolatile ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-07-15 01:34:24 +08:00
|
|
|
return( rc );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-09 07:20:37 +08:00
|
|
|
return LDAP_SUCCESS;
|
2001-07-15 01:34:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-04-01 03:21:19 +08:00
|
|
|
monitor_back_search( Operation *op, SlapReply *rs )
|
2001-07-15 01:34:24 +08:00
|
|
|
{
|
2004-11-09 02:52:27 +08:00
|
|
|
monitor_info_t *mi = ( monitor_info_t * )op->o_bd->be_private;
|
2002-10-23 22:11:02 +08:00
|
|
|
int rc = LDAP_SUCCESS;
|
2004-11-12 20:52:42 +08:00
|
|
|
Entry *e = NULL, *matched = NULL;
|
2011-01-13 09:11:08 +08:00
|
|
|
Entry *e_nv = NULL, *e_ch = NULL;
|
2005-04-09 07:20:37 +08:00
|
|
|
slap_mask_t mask;
|
2001-07-15 01:34:24 +08:00
|
|
|
|
2004-09-13 06:12:58 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "=> monitor_back_search\n", 0, 0, 0 );
|
2001-07-15 01:34:24 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* get entry with reader lock */
|
2005-04-28 05:30:35 +08:00
|
|
|
monitor_cache_dn2entry( op, rs, &op->o_req_ndn, &e, &matched );
|
2001-07-15 01:34:24 +08:00
|
|
|
if ( e == NULL ) {
|
2003-04-01 03:21:19 +08:00
|
|
|
rs->sr_err = LDAP_NO_SUCH_OBJECT;
|
2001-12-10 17:50:06 +08:00
|
|
|
if ( matched ) {
|
2005-04-09 07:20:37 +08:00
|
|
|
if ( !access_allowed_mask( op, matched,
|
|
|
|
slap_schema.si_ad_entry,
|
|
|
|
NULL, ACL_DISCLOSE, NULL, NULL ) )
|
|
|
|
{
|
|
|
|
/* do nothing */ ;
|
2006-04-12 13:53:26 +08:00
|
|
|
} else {
|
2005-04-09 07:20:37 +08:00
|
|
|
rs->sr_matched = matched->e_dn;
|
|
|
|
}
|
2001-12-10 17:50:06 +08:00
|
|
|
}
|
2001-07-15 01:34:24 +08:00
|
|
|
|
2003-04-01 03:21:19 +08:00
|
|
|
send_ldap_result( op, rs );
|
2003-04-08 07:22:27 +08:00
|
|
|
if ( matched ) {
|
|
|
|
monitor_cache_release( mi, matched );
|
|
|
|
rs->sr_matched = NULL;
|
|
|
|
}
|
2003-04-01 03:21:19 +08:00
|
|
|
|
2005-04-09 07:20:37 +08:00
|
|
|
return rs->sr_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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 ) )
|
|
|
|
{
|
|
|
|
monitor_cache_release( mi, e );
|
|
|
|
|
|
|
|
if ( !ACL_GRANT( mask, ACL_DISCLOSE ) ) {
|
|
|
|
rs->sr_err = LDAP_NO_SUCH_OBJECT;
|
2006-04-12 13:53:26 +08:00
|
|
|
} else {
|
2005-04-09 07:20:37 +08:00
|
|
|
rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
send_ldap_result( op, rs );
|
|
|
|
|
|
|
|
return rs->sr_err;
|
2001-07-15 01:34:24 +08:00
|
|
|
}
|
|
|
|
|
2003-04-07 16:53:03 +08:00
|
|
|
rs->sr_attrs = op->oq_search.rs_attrs;
|
2003-04-01 03:45:52 +08:00
|
|
|
switch ( op->oq_search.rs_scope ) {
|
2001-07-15 01:34:24 +08:00
|
|
|
case LDAP_SCOPE_BASE:
|
2005-04-28 05:30:35 +08:00
|
|
|
monitor_entry_update( op, rs, e );
|
2003-04-01 03:45:52 +08:00
|
|
|
rc = test_filter( op, e, op->oq_search.rs_filter );
|
|
|
|
if ( rc == LDAP_COMPARE_TRUE ) {
|
|
|
|
rs->sr_entry = e;
|
2011-01-13 09:11:08 +08:00
|
|
|
rs->sr_flags = REP_ENTRY_MUSTRELEASE;
|
2003-04-01 03:45:52 +08:00
|
|
|
send_search_entry( op, rs );
|
2003-04-04 05:24:53 +08:00
|
|
|
rs->sr_entry = NULL;
|
2011-01-13 09:11:08 +08:00
|
|
|
} else {
|
|
|
|
monitor_cache_release( mi, e );
|
2001-07-15 01:34:24 +08:00
|
|
|
}
|
2002-09-16 06:42:07 +08:00
|
|
|
rc = LDAP_SUCCESS;
|
2001-07-15 01:34:24 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LDAP_SCOPE_ONELEVEL:
|
2006-09-09 08:00:44 +08:00
|
|
|
case LDAP_SCOPE_SUBORDINATE:
|
2011-01-13 09:11:08 +08:00
|
|
|
monitor_find_children( op, rs, e, &e_nv, &e_ch );
|
|
|
|
monitor_cache_release( mi, e );
|
|
|
|
rc = monitor_send_children( op, rs, e_nv, e_ch,
|
2006-09-09 08:00:44 +08:00
|
|
|
op->oq_search.rs_scope == LDAP_SCOPE_SUBORDINATE );
|
2001-07-15 01:34:24 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LDAP_SCOPE_SUBTREE:
|
2005-04-28 05:30:35 +08:00
|
|
|
monitor_entry_update( op, rs, e );
|
2011-01-13 09:11:08 +08:00
|
|
|
monitor_find_children( op, rs, e, &e_nv, &e_ch );
|
2003-04-01 03:45:52 +08:00
|
|
|
rc = test_filter( op, e, op->oq_search.rs_filter );
|
2001-07-15 01:34:24 +08:00
|
|
|
if ( rc == LDAP_COMPARE_TRUE ) {
|
2003-04-04 05:24:53 +08:00
|
|
|
rs->sr_entry = e;
|
2011-01-13 09:11:08 +08:00
|
|
|
rs->sr_flags = REP_ENTRY_MUSTRELEASE;
|
2003-04-01 03:45:52 +08:00
|
|
|
send_search_entry( op, rs );
|
2003-04-04 05:24:53 +08:00
|
|
|
rs->sr_entry = NULL;
|
2011-01-13 09:11:08 +08:00
|
|
|
} else {
|
|
|
|
monitor_cache_release( mi, e );
|
2001-07-15 01:34:24 +08:00
|
|
|
}
|
|
|
|
|
2011-01-13 09:11:08 +08:00
|
|
|
rc = monitor_send_children( op, rs, e_nv, e_ch, 1 );
|
2001-07-15 01:34:24 +08:00
|
|
|
break;
|
2006-09-09 08:10:43 +08:00
|
|
|
|
|
|
|
default:
|
|
|
|
rc = LDAP_UNWILLING_TO_PERFORM;
|
|
|
|
monitor_cache_release( mi, e );
|
2001-07-15 01:34:24 +08:00
|
|
|
}
|
2005-04-09 07:20:37 +08:00
|
|
|
|
2003-04-07 16:53:03 +08:00
|
|
|
rs->sr_attrs = NULL;
|
2003-04-01 03:45:52 +08:00
|
|
|
rs->sr_err = rc;
|
2005-04-09 07:20:37 +08:00
|
|
|
if ( rs->sr_err != SLAPD_ABANDON ) {
|
|
|
|
send_ldap_result( op, rs );
|
|
|
|
}
|
2001-07-15 01:34:24 +08:00
|
|
|
|
2005-04-09 07:20:37 +08:00
|
|
|
return rs->sr_err;
|
2001-07-15 01:34:24 +08:00
|
|
|
}
|
2003-04-01 03:45:52 +08:00
|
|
|
|