1 /* search.c - monitor backend search function */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2001-2006 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;
45 *e_nonvolatile = NULL;
50 mp = ( monitor_entry_t * )e_parent->e_private;
51 e_nonvolatile = e = mp->mp_children;
53 if ( MONITOR_HAS_VOLATILE_CH( mp ) ) {
54 monitor_entry_create( op, rs, NULL, e_parent, &e_ch );
56 monitor_cache_release( mi, e_parent );
58 /* no volatile entries? */
60 /* 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 if ( op->o_abandon ) {
92 /* FIXME: may leak generated children */
93 if ( nonvolatile == 0 ) {
94 for ( e_tmp = e; e_tmp != NULL; ) {
95 mp = ( monitor_entry_t * )e_tmp->e_private;
98 monitor_cache_release( mi, e );
100 if ( e_tmp == e_nonvolatile ) {
106 monitor_cache_release( mi, e );
109 return SLAPD_ABANDON;
112 rc = test_filter( op, e, op->oq_search.rs_filter );
113 if ( rc == LDAP_COMPARE_TRUE ) {
116 rc = send_search_entry( op, rs );
120 mp = ( monitor_entry_t * )e->e_private;
124 rc = monitor_send_children( op, rs, e, sub );
126 /* FIXME: may leak generated children */
127 if ( nonvolatile == 0 ) {
128 for ( ; e_tmp != NULL; ) {
129 mp = ( monitor_entry_t * )e_tmp->e_private;
132 monitor_cache_release( mi, e );
134 if ( e_tmp == e_nonvolatile ) {
144 if ( e_tmp != NULL ) {
145 monitor_cache_lock( e_tmp );
149 /* otherwise the recursive call already released */
150 monitor_cache_release( mi, e );
154 if ( e == e_nonvolatile ) {
163 monitor_back_search( Operation *op, SlapReply *rs )
165 monitor_info_t *mi = ( monitor_info_t * )op->o_bd->be_private;
166 int rc = LDAP_SUCCESS;
167 Entry *e = NULL, *matched = NULL;
170 Debug( LDAP_DEBUG_TRACE, "=> monitor_back_search\n", 0, 0, 0 );
173 /* get entry with reader lock */
174 monitor_cache_dn2entry( op, rs, &op->o_req_ndn, &e, &matched );
176 rs->sr_err = LDAP_NO_SUCH_OBJECT;
178 if ( !access_allowed_mask( op, matched,
179 slap_schema.si_ad_entry,
180 NULL, ACL_DISCLOSE, NULL, NULL ) )
184 rs->sr_matched = matched->e_dn;
188 send_ldap_result( op, rs );
190 monitor_cache_release( mi, matched );
191 rs->sr_matched = NULL;
197 /* NOTE: __NEW__ "search" access is required
198 * on searchBase object */
199 if ( !access_allowed_mask( op, e, slap_schema.si_ad_entry,
200 NULL, ACL_SEARCH, NULL, &mask ) )
202 monitor_cache_release( mi, e );
204 if ( !ACL_GRANT( mask, ACL_DISCLOSE ) ) {
205 rs->sr_err = LDAP_NO_SUCH_OBJECT;
207 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
210 send_ldap_result( op, rs );
215 rs->sr_attrs = op->oq_search.rs_attrs;
216 switch ( op->oq_search.rs_scope ) {
217 case LDAP_SCOPE_BASE:
218 monitor_entry_update( op, rs, e );
219 rc = test_filter( op, e, op->oq_search.rs_filter );
220 if ( rc == LDAP_COMPARE_TRUE ) {
223 send_search_entry( op, rs );
227 monitor_cache_release( mi, e );
230 case LDAP_SCOPE_ONELEVEL:
231 rc = monitor_send_children( op, rs, e, 0 );
234 case LDAP_SCOPE_SUBTREE:
235 monitor_entry_update( op, rs, e );
236 rc = test_filter( op, e, op->oq_search.rs_filter );
237 if ( rc == LDAP_COMPARE_TRUE ) {
240 send_search_entry( op, rs );
244 rc = monitor_send_children( op, rs, e, 1 );
250 if ( rs->sr_err != SLAPD_ABANDON ) {
251 send_ldap_result( op, rs );