1 /* search.c - monitor backend search function */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2001-2017 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(
44 mp = ( monitor_entry_t * )e_parent->e_private;
45 *nonv = mp->mp_children;
47 if ( MONITOR_HAS_VOLATILE_CH( mp ) ) {
48 monitor_entry_create( op, rs, NULL, e_parent, vol );
53 monitor_send_children(
60 monitor_info_t *mi = ( monitor_info_t * )op->o_bd->be_private;
69 /* no volatile entries? */
71 /* no persistent entries? return */
76 /* volatile entries */
78 /* if no persistent, return only volatile */
82 /* else append persistent to volatile */
86 mp = ( monitor_entry_t * )e_tmp->e_private;
89 if ( e_tmp == NULL ) {
99 for ( ; e != NULL; e = e_tmp ) {
100 Entry *sub_nv = NULL, *sub_ch = NULL;
102 monitor_cache_lock( e );
103 monitor_entry_update( op, rs, e );
105 if ( e == e_nonvolatile )
108 mp = ( monitor_entry_t * )e->e_private;
111 if ( op->o_abandon ) {
112 monitor_cache_release( mi, e );
118 monitor_find_children( op, rs, e, &sub_nv, &sub_ch );
120 rc = test_filter( op, e, op->oq_search.rs_filter );
121 if ( rc == LDAP_COMPARE_TRUE ) {
123 rs->sr_flags = REP_ENTRY_MUSTRELEASE;
124 rc = send_search_entry( op, rs );
126 for ( e = sub_ch; e != NULL; e = sub_nv ) {
127 mp = ( monitor_entry_t * )e->e_private;
128 sub_nv = mp->mp_next;
129 monitor_cache_lock( e );
130 monitor_cache_release( mi, e );
135 monitor_cache_release( mi, e );
139 rc = monitor_send_children( op, rs, sub_nv, sub_ch, sub );
142 if ( nonvolatile == 0 ) {
143 for ( ; e_tmp != NULL; ) {
144 mp = ( monitor_entry_t * )e_tmp->e_private;
147 monitor_cache_lock( e );
148 monitor_cache_release( mi, e );
150 if ( e_tmp == e_nonvolatile ) {
165 monitor_back_search( Operation *op, SlapReply *rs )
167 monitor_info_t *mi = ( monitor_info_t * )op->o_bd->be_private;
168 int rc = LDAP_SUCCESS;
169 Entry *e = NULL, *matched = NULL;
170 Entry *e_nv = NULL, *e_ch = 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 if ( !access_allowed_mask( op, matched,
182 slap_schema.si_ad_entry,
183 NULL, ACL_DISCLOSE, NULL, NULL ) )
187 rs->sr_matched = matched->e_dn;
191 send_ldap_result( op, rs );
193 monitor_cache_release( mi, matched );
194 rs->sr_matched = NULL;
200 /* NOTE: __NEW__ "search" access is required
201 * on searchBase object */
202 if ( !access_allowed_mask( op, e, slap_schema.si_ad_entry,
203 NULL, ACL_SEARCH, NULL, &mask ) )
205 monitor_cache_release( mi, e );
207 if ( !ACL_GRANT( mask, ACL_DISCLOSE ) ) {
208 rs->sr_err = LDAP_NO_SUCH_OBJECT;
210 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
213 send_ldap_result( op, rs );
218 rs->sr_attrs = op->oq_search.rs_attrs;
219 switch ( op->oq_search.rs_scope ) {
220 case LDAP_SCOPE_BASE:
221 monitor_entry_update( op, rs, e );
222 rc = test_filter( op, e, op->oq_search.rs_filter );
223 if ( rc == LDAP_COMPARE_TRUE ) {
225 rs->sr_flags = REP_ENTRY_MUSTRELEASE;
226 send_search_entry( op, rs );
229 monitor_cache_release( mi, e );
234 case LDAP_SCOPE_ONELEVEL:
235 case LDAP_SCOPE_SUBORDINATE:
236 monitor_find_children( op, rs, e, &e_nv, &e_ch );
237 monitor_cache_release( mi, e );
238 rc = monitor_send_children( op, rs, e_nv, e_ch,
239 op->oq_search.rs_scope == LDAP_SCOPE_SUBORDINATE );
242 case LDAP_SCOPE_SUBTREE:
243 monitor_entry_update( op, rs, e );
244 monitor_find_children( op, rs, e, &e_nv, &e_ch );
245 rc = test_filter( op, e, op->oq_search.rs_filter );
246 if ( rc == LDAP_COMPARE_TRUE ) {
248 rs->sr_flags = REP_ENTRY_MUSTRELEASE;
249 send_search_entry( op, rs );
252 monitor_cache_release( mi, e );
255 rc = monitor_send_children( op, rs, e_nv, e_ch, 1 );
259 rc = LDAP_UNWILLING_TO_PERFORM;
260 monitor_cache_release( mi, e );
265 if ( rs->sr_err != SLAPD_ABANDON ) {
266 send_ldap_result( op, rs );