1 /* search.c - monitor backend search function */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2001-2011 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(
40 monitor_info_t *mi = ( monitor_info_t * )op->o_bd->be_private;
44 *e_nonvolatile = NULL;
49 mp = ( monitor_entry_t * )e_parent->e_private;
50 e_nonvolatile = e = mp->mp_children;
52 if ( MONITOR_HAS_VOLATILE_CH( mp ) ) {
53 monitor_entry_create( op, rs, NULL, e_parent, &e_ch );
55 monitor_cache_release( mi, e_parent );
57 /* no volatile entries? */
59 /* no persistent entries? return */
65 /* volatile entries */
67 /* if no persistent, return only volatile */
71 /* else append persistent to volatile */
75 mp = ( monitor_entry_t * )e_tmp->e_private;
78 if ( e_tmp == NULL ) {
88 for ( monitor_cache_lock( e ); e != NULL; ) {
89 monitor_entry_update( op, rs, e );
91 mp = ( monitor_entry_t * )e->e_private;
94 if ( op->o_abandon ) {
95 monitor_cache_release( mi, e );
100 rc = test_filter( op, e, op->oq_search.rs_filter );
101 if ( rc == LDAP_COMPARE_TRUE ) {
104 rc = send_search_entry( op, rs );
107 monitor_cache_release( mi, e );
113 rc = monitor_send_children( op, rs, e, sub );
116 /* FIXME: may leak generated children */
117 if ( nonvolatile == 0 ) {
118 for ( ; e_tmp != NULL; ) {
119 mp = ( monitor_entry_t * )e_tmp->e_private;
122 monitor_cache_lock( mi, e );
123 monitor_cache_release( mi, e );
125 if ( e_tmp == e_nonvolatile ) {
135 if ( e_tmp != NULL ) {
136 monitor_cache_lock( e_tmp );
140 /* otherwise the recursive call already released */
141 monitor_cache_release( mi, e );
145 if ( e == e_nonvolatile ) {
154 monitor_back_search( Operation *op, SlapReply *rs )
156 monitor_info_t *mi = ( monitor_info_t * )op->o_bd->be_private;
157 int rc = LDAP_SUCCESS;
158 Entry *e = NULL, *matched = NULL;
161 Debug( LDAP_DEBUG_TRACE, "=> monitor_back_search\n", 0, 0, 0 );
164 /* get entry with reader lock */
165 monitor_cache_dn2entry( op, rs, &op->o_req_ndn, &e, &matched );
167 rs->sr_err = LDAP_NO_SUCH_OBJECT;
169 if ( !access_allowed_mask( op, matched,
170 slap_schema.si_ad_entry,
171 NULL, ACL_DISCLOSE, NULL, NULL ) )
175 rs->sr_matched = matched->e_dn;
179 send_ldap_result( op, rs );
181 monitor_cache_release( mi, matched );
182 rs->sr_matched = NULL;
188 /* NOTE: __NEW__ "search" access is required
189 * on searchBase object */
190 if ( !access_allowed_mask( op, e, slap_schema.si_ad_entry,
191 NULL, ACL_SEARCH, NULL, &mask ) )
193 monitor_cache_release( mi, e );
195 if ( !ACL_GRANT( mask, ACL_DISCLOSE ) ) {
196 rs->sr_err = LDAP_NO_SUCH_OBJECT;
198 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
201 send_ldap_result( op, rs );
206 rs->sr_attrs = op->oq_search.rs_attrs;
207 switch ( op->oq_search.rs_scope ) {
208 case LDAP_SCOPE_BASE:
209 monitor_entry_update( op, rs, e );
210 rc = test_filter( op, e, op->oq_search.rs_filter );
211 if ( rc == LDAP_COMPARE_TRUE ) {
214 send_search_entry( op, rs );
218 monitor_cache_release( mi, e );
221 case LDAP_SCOPE_ONELEVEL:
222 case LDAP_SCOPE_SUBORDINATE:
223 rc = monitor_send_children( op, rs, e,
224 op->oq_search.rs_scope == LDAP_SCOPE_SUBORDINATE );
227 case LDAP_SCOPE_SUBTREE:
228 monitor_entry_update( op, rs, e );
229 rc = test_filter( op, e, op->oq_search.rs_filter );
230 if ( rc == LDAP_COMPARE_TRUE ) {
233 send_search_entry( op, rs );
237 rc = monitor_send_children( op, rs, e, 1 );
241 rc = LDAP_UNWILLING_TO_PERFORM;
242 monitor_cache_release( mi, e );
247 if ( rs->sr_err != SLAPD_ABANDON ) {
248 send_ldap_result( op, rs );