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;
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 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 = e; e_tmp != NULL; ) {
129 mp = ( monitor_entry_t * )e_tmp->e_private;
132 monitor_cache_release( mi, e );
134 if ( e_tmp == e_nonvolatile ) {
140 monitor_cache_release( mi, e );
147 if ( e_tmp != NULL ) {
148 monitor_cache_lock( e_tmp );
152 /* otherwise the recursive call already released */
153 monitor_cache_release( mi, e );
157 if ( e == e_nonvolatile ) {
166 monitor_back_search( Operation *op, SlapReply *rs )
168 monitor_info_t *mi = ( monitor_info_t * )op->o_bd->be_private;
169 int rc = LDAP_SUCCESS;
170 Entry *e = NULL, *matched = NULL;
173 Debug( LDAP_DEBUG_TRACE, "=> monitor_back_search\n", 0, 0, 0 );
176 /* get entry with reader lock */
177 monitor_cache_dn2entry( op, rs, &op->o_req_ndn, &e, &matched );
179 rs->sr_err = LDAP_NO_SUCH_OBJECT;
181 #ifdef SLAP_ACL_HONOR_DISCLOSE
182 if ( !access_allowed_mask( op, matched,
183 slap_schema.si_ad_entry,
184 NULL, ACL_DISCLOSE, NULL, NULL ) )
188 #endif /* SLAP_ACL_HONOR_DISCLOSE */
190 rs->sr_matched = matched->e_dn;
194 send_ldap_result( op, rs );
196 monitor_cache_release( mi, matched );
197 rs->sr_matched = NULL;
203 /* NOTE: __NEW__ "search" access is required
204 * on searchBase object */
205 if ( !access_allowed_mask( op, e, slap_schema.si_ad_entry,
206 NULL, ACL_SEARCH, NULL, &mask ) )
208 monitor_cache_release( mi, e );
210 #ifdef SLAP_ACL_HONOR_DISCLOSE
211 if ( !ACL_GRANT( mask, ACL_DISCLOSE ) ) {
212 rs->sr_err = LDAP_NO_SUCH_OBJECT;
214 #endif /* SLAP_ACL_HONOR_DISCLOSE */
216 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
219 send_ldap_result( op, rs );
224 rs->sr_attrs = op->oq_search.rs_attrs;
225 switch ( op->oq_search.rs_scope ) {
226 case LDAP_SCOPE_BASE:
227 monitor_entry_update( op, rs, e );
228 rc = test_filter( op, e, op->oq_search.rs_filter );
229 if ( rc == LDAP_COMPARE_TRUE ) {
232 send_search_entry( op, rs );
236 monitor_cache_release( mi, e );
239 case LDAP_SCOPE_ONELEVEL:
240 rc = monitor_send_children( op, rs, e, 0 );
243 case LDAP_SCOPE_SUBTREE:
244 monitor_entry_update( op, rs, e );
245 rc = test_filter( op, e, op->oq_search.rs_filter );
246 if ( rc == LDAP_COMPARE_TRUE ) {
249 send_search_entry( op, rs );
253 rc = monitor_send_children( op, rs, e, 1 );
259 if ( rs->sr_err != SLAPD_ABANDON ) {
260 send_ldap_result( op, rs );