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_find_children(
42 monitor_info_t *mi = ( monitor_info_t * )op->o_bd->be_private;
45 mp = ( monitor_entry_t * )e_parent->e_private;
46 *nonv = mp->mp_children;
48 if ( MONITOR_HAS_VOLATILE_CH( mp ) ) {
49 monitor_entry_create( op, rs, NULL, e_parent, vol );
54 monitor_send_children(
61 monitor_info_t *mi = ( monitor_info_t * )op->o_bd->be_private;
70 /* no volatile entries? */
72 /* no persistent entries? return */
77 /* volatile entries */
79 /* if no persistent, return only volatile */
83 /* else append persistent to volatile */
87 mp = ( monitor_entry_t * )e_tmp->e_private;
90 if ( e_tmp == NULL ) {
100 for ( ; e != NULL; e = e_tmp ) {
101 Entry *sub_nv = NULL, *sub_ch = NULL;
103 monitor_cache_lock( e );
104 monitor_entry_update( op, rs, e );
106 if ( e == e_nonvolatile )
109 mp = ( monitor_entry_t * )e->e_private;
112 if ( op->o_abandon ) {
113 monitor_cache_release( mi, e );
119 monitor_find_children( op, rs, e, &sub_nv, &sub_ch );
121 rc = test_filter( op, e, op->oq_search.rs_filter );
122 if ( rc == LDAP_COMPARE_TRUE ) {
124 rs->sr_flags = REP_ENTRY_MUSTRELEASE;
125 rc = send_search_entry( op, rs );
127 for ( e = sub_ch; e != NULL; e = sub_nv ) {
128 mp = ( monitor_entry_t * )e->e_private;
129 sub_nv = mp->mp_next;
130 monitor_cache_lock( e );
131 monitor_cache_release( mi, e );
136 monitor_cache_release( mi, e );
140 rc = monitor_send_children( op, rs, sub_nv, sub_ch, sub );
143 if ( nonvolatile == 0 ) {
144 for ( ; e_tmp != NULL; ) {
145 mp = ( monitor_entry_t * )e_tmp->e_private;
148 monitor_cache_lock( e );
149 monitor_cache_release( mi, e );
151 if ( e_tmp == 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;
171 Entry *e_nv = NULL, *e_ch = NULL;
174 Debug( LDAP_DEBUG_TRACE, "=> monitor_back_search\n", 0, 0, 0 );
177 /* get entry with reader lock */
178 monitor_cache_dn2entry( op, rs, &op->o_req_ndn, &e, &matched );
180 rs->sr_err = LDAP_NO_SUCH_OBJECT;
182 if ( !access_allowed_mask( op, matched,
183 slap_schema.si_ad_entry,
184 NULL, ACL_DISCLOSE, NULL, NULL ) )
188 rs->sr_matched = matched->e_dn;
192 send_ldap_result( op, rs );
194 monitor_cache_release( mi, matched );
195 rs->sr_matched = NULL;
201 /* NOTE: __NEW__ "search" access is required
202 * on searchBase object */
203 if ( !access_allowed_mask( op, e, slap_schema.si_ad_entry,
204 NULL, ACL_SEARCH, NULL, &mask ) )
206 monitor_cache_release( mi, e );
208 if ( !ACL_GRANT( mask, ACL_DISCLOSE ) ) {
209 rs->sr_err = LDAP_NO_SUCH_OBJECT;
211 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
214 send_ldap_result( op, rs );
219 rs->sr_attrs = op->oq_search.rs_attrs;
220 switch ( op->oq_search.rs_scope ) {
221 case LDAP_SCOPE_BASE:
222 monitor_entry_update( op, rs, e );
223 rc = test_filter( op, e, op->oq_search.rs_filter );
224 if ( rc == LDAP_COMPARE_TRUE ) {
226 rs->sr_flags = REP_ENTRY_MUSTRELEASE;
227 send_search_entry( op, rs );
230 monitor_cache_release( mi, e );
235 case LDAP_SCOPE_ONELEVEL:
236 case LDAP_SCOPE_SUBORDINATE:
237 monitor_find_children( op, rs, e, &e_nv, &e_ch );
238 monitor_cache_release( mi, e );
239 rc = monitor_send_children( op, rs, e_nv, e_ch,
240 op->oq_search.rs_scope == LDAP_SCOPE_SUBORDINATE );
243 case LDAP_SCOPE_SUBTREE:
244 monitor_entry_update( op, rs, e );
245 monitor_find_children( op, rs, e, &e_nv, &e_ch );
246 rc = test_filter( op, e, op->oq_search.rs_filter );
247 if ( rc == LDAP_COMPARE_TRUE ) {
249 rs->sr_flags = REP_ENTRY_MUSTRELEASE;
250 send_search_entry( op, rs );
253 monitor_cache_release( mi, e );
256 rc = monitor_send_children( op, rs, e_nv, e_ch, 1 );
260 rc = LDAP_UNWILLING_TO_PERFORM;
261 monitor_cache_release( mi, e );
266 if ( rs->sr_err != SLAPD_ABANDON ) {
267 send_ldap_result( op, rs );