1 /* search.c - monitor backend search function */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2001-2005 The OpenLDAP Foundation.
6 * Portions Copyright 2001-2003 Pierangelo Masarati.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
13 * A copy of this license is available in file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
18 * This work was initially developed by Pierangelo Masarati for inclusion
19 * in OpenLDAP Software.
26 #include <ac/string.h>
27 #include <ac/socket.h>
30 #include "back-monitor.h"
31 #include "proto-back-monitor.h"
34 monitor_send_children(
41 monitor_info_t *mi = ( monitor_info_t * )op->o_bd->be_private;
42 Entry *e, *e_tmp, *e_ch;
46 mp = ( monitor_entry_t * )e_parent->e_private;
50 if ( MONITOR_HAS_VOLATILE_CH( mp ) ) {
51 monitor_entry_create( op, rs, NULL, e_parent, &e_ch );
53 monitor_cache_release( mi, e_parent );
55 /* no volatile entries? */
57 /* no persistent entries? return */
62 /* volatile entries */
64 /* if no persistent, return only volatile */
67 monitor_cache_lock( e_ch );
69 /* else append persistent to volatile */
73 mp = ( monitor_entry_t * )e_tmp->e_private;
76 if ( e_tmp == NULL ) {
86 for ( ; e != NULL; ) {
87 mp = ( monitor_entry_t * )e->e_private;
89 monitor_entry_update( op, rs, e );
91 if ( op->o_abandon ) {
92 monitor_cache_release( mi, e );
96 rc = test_filter( op, e, op->oq_search.rs_filter );
97 if ( rc == LDAP_COMPARE_TRUE ) {
100 send_search_entry( op, rs );
104 if ( ( mp->mp_children || MONITOR_HAS_VOLATILE_CH( mp ) )
107 rc = monitor_send_children( op, rs, e, sub );
109 monitor_cache_release( mi, e );
115 if ( e_tmp != NULL ) {
116 monitor_cache_lock( e_tmp );
118 monitor_cache_release( mi, e );
126 monitor_back_search( Operation *op, SlapReply *rs )
128 monitor_info_t *mi = ( monitor_info_t * )op->o_bd->be_private;
129 int rc = LDAP_SUCCESS;
130 Entry *e = NULL, *matched = NULL;
133 Debug( LDAP_DEBUG_TRACE, "=> monitor_back_search\n", 0, 0, 0 );
136 /* get entry with reader lock */
137 monitor_cache_dn2entry( op, rs, &op->o_req_ndn, &e, &matched );
139 rs->sr_err = LDAP_NO_SUCH_OBJECT;
141 #ifdef SLAP_ACL_HONOR_DISCLOSE
142 if ( !access_allowed_mask( op, matched,
143 slap_schema.si_ad_entry,
144 NULL, ACL_DISCLOSE, NULL, NULL ) )
148 #endif /* SLAP_ACL_HONOR_DISCLOSE */
150 rs->sr_matched = matched->e_dn;
154 send_ldap_result( op, rs );
156 monitor_cache_release( mi, matched );
157 rs->sr_matched = NULL;
163 /* NOTE: __NEW__ "search" access is required
164 * on searchBase object */
165 if ( !access_allowed_mask( op, e, slap_schema.si_ad_entry,
166 NULL, ACL_SEARCH, NULL, &mask ) )
168 monitor_cache_release( mi, e );
170 #ifdef SLAP_ACL_HONOR_DISCLOSE
171 if ( !ACL_GRANT( mask, ACL_DISCLOSE ) ) {
172 rs->sr_err = LDAP_NO_SUCH_OBJECT;
174 #endif /* SLAP_ACL_HONOR_DISCLOSE */
176 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
179 send_ldap_result( op, rs );
184 rs->sr_attrs = op->oq_search.rs_attrs;
185 switch ( op->oq_search.rs_scope ) {
186 case LDAP_SCOPE_BASE:
187 monitor_entry_update( op, rs, e );
188 rc = test_filter( op, e, op->oq_search.rs_filter );
189 if ( rc == LDAP_COMPARE_TRUE ) {
192 send_search_entry( op, rs );
196 monitor_cache_release( mi, e );
199 case LDAP_SCOPE_ONELEVEL:
200 rc = monitor_send_children( op, rs, e, 0 );
203 case LDAP_SCOPE_SUBTREE:
204 monitor_entry_update( op, rs, e );
205 rc = test_filter( op, e, op->oq_search.rs_filter );
206 if ( rc == LDAP_COMPARE_TRUE ) {
209 send_search_entry( op, rs );
213 rc = monitor_send_children( op, rs, e, 1 );
219 if ( rs->sr_err != SLAPD_ABANDON ) {
220 send_ldap_result( op, rs );