2 * Copyright (c) 2003 by International Business Machines, Inc.
4 * International Business Machines, Inc. (hereinafter called IBM) grants
5 * permission under its copyrights to use, copy, modify, and distribute this
6 * Software with or without fee, provided that the above copyright notice and
7 * all paragraphs of this notice appear in all copies, and that the name of IBM
8 * not be used in connection with the marketing of any product incorporating
9 * the Software or modifications thereof, without specific, written prior
12 * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
13 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
14 * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
15 * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
16 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
17 * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
20 * This software is based on the backends back-ldap and back-meta, implemented
21 * by Howard Chu <hyc@highlandsun.com>, Mark Valence
22 * <kurash@sassafras.com>, Pierangelo Masarati <ando@sys-net.it> and other
25 * The original copyright statements follow.
26 * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
27 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
29 * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
31 * This work has been developed to fulfill the requirements
32 * of SysNet s.n.c. <http:www.sys-net.it> and it has been donated
33 * to the OpenLDAP Foundation in the hope that it may be useful
34 * to the Open Source community, but WITHOUT ANY WARRANTY.
36 * Permission is granted to anyone to use this software for any purpose
37 * on any computer system, and to alter it and redistribute it, subject
38 * to the following restrictions:
40 * 1. The author and SysNet s.n.c. are not responsible for the consequences
41 * of use of this software, no matter how awful, even if they arise from
44 * 2. The origin of this software must not be misrepresented, either by
45 * explicit claim or by omission. Since few users ever read sources,
46 * credits should appear in the documentation.
48 * 3. Altered versions must be plainly marked as such, and must not be
49 * misrepresented as being the original software. Since few users
50 * ever read sources, credits should appear in the documentation.
51 * SysNet s.n.c. cannot be responsible for the consequences of the
54 * 4. This notice may not be removed or altered.
57 * This software is based on the backend back-ldap, implemented
58 * by Howard Chu <hyc@highlandsun.com>, and modified by Mark Valence
59 * <kurash@sassafras.com>, Pierangelo Masarati <ando@sys-net.it> and other
60 * contributors. The contribution of the original software to the present
61 * implementation is acknowledged in this copyright statement.
63 * A special acknowledgement goes to Howard for the overall architecture
64 * (and for borrowing large pieces of code), and to Mark, who implemented
65 * from scratch the attribute/objectclass mapping.
67 * The original copyright statement follows.
69 * Copyright 1999, Howard Chu, All rights reserved. <hyc@highlandsun.com>
71 * Permission is granted to anyone to use this software for any purpose
72 * on any computer system, and to alter it and redistribute it, subject
73 * to the following restrictions:
75 * 1. The author is not responsible for the consequences of use of this
76 * software, no matter how awful, even if they arise from flaws in it.
78 * 2. The origin of this software must not be misrepresented, either by
79 * explicit claim or by omission. Since few users ever read sources,
80 * credits should appear in the documentation.
82 * 3. Altered versions must be plainly marked as such, and must not be
83 * misrepresented as being the original software. Since few users
84 * ever read sources, credits should appear in the
87 * 4. This notice may not be removed or altered.
94 #include <ac/socket.h>
95 #include <ac/string.h>
101 #include "../back-ldap/back-ldap.h"
102 #include "back-meta.h"
103 #undef ldap_debug /* silence a warning in ldap-int.h */
104 #include "ldap_log.h"
105 #include "../../../libraries/libldap/ldap-int.h"
114 struct exception* result
123 static struct metaconn*
128 struct berval *nbase,
129 struct exception *result
134 AttributeName** newattrs,
135 AttributeName* attrs,
136 AttributeName* filter_attrs
144 int* msgid, Backend* be,
145 AttributeName* attrs,
149 Entry*** entry_array,
152 struct exception* result
159 struct metasingleconn* lsc,
163 struct exception* result
168 struct rewrite_info* info,
169 const char* rewriteContext,
173 struct exception* result
178 AttributeName* attrs,
185 AttributeName* attrs_in,
195 struct exception* result
201 struct berval* tempstr,
219 meta_back_cache_search(
227 struct berval *nbase,
233 struct berval *filterstr,
234 AttributeName *attributes,
238 struct metainfo *li = ( struct metainfo * )op->o_bd->be_private;
240 struct metasingleconn *lsc;
241 cache_manager* cm = li->cm;
242 query_manager* qm = cm->qm;
248 int count, rc = 0, *msgid = NULL;
253 int i = -1, last = 0, candidates = 0, op_type;
255 struct berval mfilter;
256 struct berval cachebase = { 0L, NULL };
257 struct berval ncachebase = { 0L, NULL };
258 struct berval cache_suffix;
259 struct berval tempstr = { 0L, NULL };
261 AttributeName *filter_attrs = NULL;
262 AttributeName *new_attrs = NULL;
263 AttributeName *attrs = NULL;
266 Entry **entry_array = NULL;
271 int template_id = -1;
277 int oc_attr_absent = 1;
279 struct exception result[1];
281 Filter* filter = str2filter(op->ors_filterstr.bv_val);
282 slap_callback cb = {cache_back_sentry, NULL};
284 cb.sc_private = op->o_bd;
287 for ( count=0; op->ors_attrs[ count ].an_name.bv_val; count++ ) {
288 if ( op->ors_attrs[count].an_desc == slap_schema.si_ad_objectClass )
291 attrs = (AttributeName*)malloc( ( count + 1 + oc_attr_absent )
292 *sizeof(AttributeName));
293 for ( count=0; op->ors_attrs[ count ].an_name.bv_val; count++ ) {
294 ber_dupbv(&attrs[ count ].an_name,
295 &op->ors_attrs[ count ].an_name);
296 attrs[count].an_desc = op->ors_attrs[count].an_desc;
298 attrs[ count ].an_name.bv_val = NULL;
299 attrs[ count ].an_name.bv_len = 0;
302 result->type = SUCCESS;
304 ldap_pvt_thread_mutex_lock(&cm->cache_mutex);
307 LDAP_LOG( BACK_META, DETAIL1, "Threads++ = %d\n", cm->threads, 0, 0 );
308 #else /* !NEW_LOGGING */
309 Debug( LDAP_DEBUG_ANY, "Threads++ = %d\n", cm->threads, 0, 0 );
310 #endif /* !NEW_LOGGING */
311 ldap_pvt_thread_mutex_unlock(&cm->cache_mutex);
313 ldap_pvt_thread_mutex_lock(&cm->cc_mutex);
314 if (!cm->cc_thread_started) {
315 oper = (Operation*)malloc(sizeof(Operation));
317 cm->cc_thread_started = 1;
318 ldap_pvt_thread_create(&(cm->cc_thread), 1, consistency_check, (void*)oper);
320 ldap_pvt_thread_mutex_unlock(&cm->cc_mutex);
322 filter2template(filter, &tempstr, &filter_attrs, &fattr_cnt, result);
323 if (result->type != SUCCESS)
327 LDAP_LOG( BACK_META, DETAIL1, "query template of incoming query = %s\n",
328 tempstr.bv_val, 0, 0 );
329 #else /* !NEW_LOGGING */
330 Debug( LDAP_DEBUG_ANY, "query template of incoming query = %s\n",
331 tempstr.bv_val, 0, 0 );
332 #endif /* !NEW_LOGGING */
333 curr_limit = cm->num_entries_limit ;
336 attr_set = get_attr_set(attrs, qm, cm->numattrsets);
338 query.filter = filter;
340 query.base = op->o_req_dn;
341 query.scope = op->ors_scope;
343 /* check for query containment */
345 for (i=0; i<cm->numtemplates; i++) {
346 /* find if template i can potentially answer tempstr */
347 if (!is_temp_answerable(attr_set, &tempstr, qm, i))
349 if (attr_set == qm->templates[i].attr_set_index) {
354 LDAP_LOG( BACK_META, DETAIL2,
355 "Entering QC, querystr = %s\n",
356 op->ors_filterstr.bv_val, 0, 0 );
357 #else /* !NEW_LOGGING */
358 Debug( LDAP_DEBUG_NONE, "Entering QC, querystr = %s\n",
359 op->ors_filterstr.bv_val, 0, 0 );
360 #endif /* !NEW_LOGGING */
361 answerable = (*(qm->qcfunc))(qm, &query, i);
368 if ( attrs && oc_attr_absent ) {
369 for ( count = 0; attrs[count].an_name.bv_val; count++) ;
370 attrs[ count ].an_name.bv_val = "objectClass";
371 attrs[ count ].an_name.bv_len = strlen( "objectClass" );
372 attrs[ count ].an_desc = slap_schema.si_ad_objectClass;
373 attrs[ count + 1 ].an_name.bv_val = NULL;
374 attrs[ count + 1 ].an_name.bv_len = 0;
381 LDAP_LOG( BACK_META, DETAIL1, "QUERY ANSWERABLE\n", 0, 0, 0 );
382 #else /* !NEW_LOGGING */
383 Debug( LDAP_DEBUG_ANY, "QUERY ANSWERABLE\n", 0, 0, 0 );
384 #endif /* !NEW_LOGGING */
385 rewriteSession(li->rwinfo, "cacheBase", op->o_req_dn.bv_val,
386 op->o_conn, &cbase, result);
387 if (result->type != SUCCESS) {
388 ldap_pvt_thread_rdwr_runlock(&qm->templates[i].t_rwlock);
391 if ( cbase == NULL ) {
392 cachebase = op->o_req_dn;
394 cachebase.bv_val = cbase;
395 cachebase.bv_len = strlen(cbase);
397 dnNormalize(0, NULL, NULL, &cachebase, &ncachebase,
400 /* FIXME: safe default? */
403 op_tmp.o_bd = li->glue_be;
404 op_tmp.o_req_dn = cachebase;
405 op_tmp.o_req_ndn = ncachebase;
407 op_tmp.o_callback = &cb;
409 li->glue_be->be_search(&op_tmp, rs);
410 free( ncachebase.bv_val );
411 if ( cachebase.bv_val != op->o_req_dn.bv_val ) {
412 /* free only if rewritten */
413 free( cachebase.bv_val );
416 ldap_pvt_thread_rdwr_runlock(&qm->templates[i].t_rwlock);
421 LDAP_LOG( BACK_META, DETAIL1, "QUERY NOT ANSWERABLE\n",
423 #else /* !NEW_LOGGING */
424 Debug( LDAP_DEBUG_ANY, "QUERY NOT ANSWERABLE\n", 0, 0, 0 );
425 #endif /* !NEW_LOGGING */
427 if ( op->ors_scope == LDAP_SCOPE_BASE ) {
428 op_type = META_OP_REQUIRE_SINGLE;
430 op_type = META_OP_ALLOW_MULTIPLE;
433 lc = metaConnect(&op_tmp, rs, op_type,
434 &op->o_req_ndn, result);
436 if (result->type != SUCCESS)
439 ldap_pvt_thread_mutex_lock(&cm->cache_mutex);
440 if (cm->num_cached_queries >= cm->max_queries) {
443 ldap_pvt_thread_mutex_unlock(&cm->cache_mutex);
446 add_filter_attrs(&new_attrs, attrs, filter_attrs);
454 * Array of message id of each target
456 msgid = ch_calloc( sizeof( int ), li->ntargets );
457 if ( msgid == NULL ) {
458 result->type = CONN_ERR;
463 if (slimit > 0 && (slimit <= cm->num_entries_limit))
464 slimit = cm->num_entries_limit;
471 for ( i = 0, lsc = lc->conns; !META_LAST(lsc); ++i, ++lsc ) {
472 char *realbase = ( char * )op->o_req_dn.bv_val;
473 int realscope = op->ors_scope;
475 char *mapped_filter, **mapped_attrs;
477 /* FIXME: Check for more than one targets */
478 if ( meta_back_is_candidate(
479 &li->targets[i]->suffix,
481 lsc->candidate = META_CANDIDATE;
483 if ( lsc->candidate != META_CANDIDATE )
486 if ( op->ors_deref != -1 ) {
487 ldap_set_option( lsc->ld, LDAP_OPT_DEREF,
488 ( void * )&op->ors_deref);
490 if ( op->ors_tlimit != -1 ) {
491 ldap_set_option( lsc->ld, LDAP_OPT_TIMELIMIT,
492 ( void * )&op->ors_tlimit);
494 if ( op->ors_slimit != -1 ) {
495 ldap_set_option( lsc->ld, LDAP_OPT_SIZELIMIT,
496 ( void * )&op->ors_slimit);
500 * modifies the base according to the scope, if required
502 suffixlen = li->targets[ i ]->suffix.bv_len;
503 if ( suffixlen > op->o_req_ndn.bv_len ) {
504 switch ( op->ors_scope ) {
505 case LDAP_SCOPE_SUBTREE:
507 * make the target suffix the new base
508 * FIXME: this is very forgiving,
509 * because illegal bases may be turned
510 * into the suffix of the target.
513 &li->targets[ i ]->suffix,
516 li->targets[i]->suffix.bv_val;
519 * this target is no longer
528 case LDAP_SCOPE_ONELEVEL:
529 if ( is_one_level_rdn(
530 li->targets[ i ]->suffix.bv_val,
531 suffixlen - op->o_req_ndn.bv_len - 1 )
533 &li->targets[ i ]->suffix,
536 * if there is exactly one
537 * level, make the target suffix
538 * the new base, and make scope
542 li->targets[i]->suffix.bv_val;
543 realscope = LDAP_SCOPE_BASE;
545 } /* else continue with the next case */
547 case LDAP_SCOPE_BASE:
549 * this target is no longer candidate
551 lsc->candidate = META_NOT_CANDIDATE;
557 * Rewrite the search base, if required
560 rewriteSession(li->targets[i]->rwmap.rwm_rw,
562 realbase, op->o_conn, &mbase, result);
564 if (result->type != SUCCESS)
567 if ( mbase == NULL ) {
572 * Rewrite the search filter, if required
574 rewriteSession( li->targets[i]->rwmap.rwm_rw,
576 op->ors_filterstr.bv_val, op->o_conn,
577 &mfilter.bv_val, result);
578 if (result->type != SUCCESS)
581 if ( mfilter.bv_val != NULL && mfilter.bv_val[ 0 ]
583 mfilter.bv_len = strlen( mfilter.bv_val );
585 if ( mfilter.bv_val != NULL ) {
586 free( mfilter.bv_val );
588 mfilter = op->ors_filterstr;
593 * Maps attributes in filter
595 mapped_filter = ldap_back_map_filter(
596 &li->targets[i]->rwmap.rwm_at,
597 &li->targets[i]->rwmap.rwm_oc,
599 if ( mapped_filter == NULL ) {
600 mapped_filter = ( char * )mfilter.bv_val;
602 if ( mfilter.bv_val != op->ors_filterstr.bv_val ) {
603 free( mfilter.bv_val );
606 mfilter.bv_val = NULL;
609 mapped_filter = (char *) mfilter.bv_val;
613 * Maps required attributes
615 if ( ldap_back_map_attrs(
616 &li->targets[ i ]->rwmap.rwm_at,
617 new_attrs, 0, &mapped_attrs ) ) {
624 msgid[ i ] = ldap_search( lsc->ld, mbase, realscope,
625 mapped_filter, mapped_attrs,
628 if ( msgid[ i ] == -1 ) {
629 result->type = CONN_ERR;
632 lsc->candidate = META_NOT_CANDIDATE;
637 if ( mapped_attrs ) {
638 free( mapped_attrs );
642 if ( mapped_filter != op->ors_filterstr.bv_val ) {
643 free( mapped_filter );
644 mapped_filter = NULL;
647 if ( mbase != realbase ) {
655 num_entries = handleLdapResult(lc, &op_tmp, rs, msgid,
657 op->ors_attrsonly, candidates,
658 cacheable, &entry_array,
659 curr_limit, op->ors_slimit, result);
661 if (result->type != SUCCESS)
663 if (cacheable && (num_entries <= curr_limit)) {
666 LDAP_LOG( BACK_META, DETAIL1,
667 "QUERY CACHEABLE\n", 0, 0, 0 );
668 #else /* !NEW_LOGGING */
669 Debug( LDAP_DEBUG_ANY, "QUERY CACHEABLE\n", 0, 0, 0 );
670 #endif /* !NEW_LOGGING */
671 op_tmp.o_bd = li->glue_be;
672 uuid = cache_entries(&op_tmp, rs, entry_array, cm, result);
674 LDAP_LOG( BACK_META, DETAIL1,
675 "Added query %s UUID %s ENTRIES %d\n",
676 op->ors_filterstr.bv_val,
678 #else /* !NEW_LOGGING */
679 Debug( LDAP_DEBUG_ANY,
680 "Added query %s UUID %s ENTRIES %d\n",
681 op->ors_filterstr.bv_val,
683 #endif /* !NEW_LOGGING */
685 if (result->type != SUCCESS)
687 (*(qm->addfunc))(qm, &query, template_id, uuid, result);
688 if (result->type != SUCCESS)
693 /* FIXME : launch do_syncrepl() threads around here
695 * entryUUID and entryCSN need also to be requested by :
698 msgid[ i ] = ldap_search( lsc->ld, mbase, realscope,
699 mapped_filter, mapped_attrs, op->ors_attrsonly );
701 /* Also, mbase, realscope, mapped_filter, mapped_attrs need
702 * be managed as arrays. Each element needs to be retained by this point.
707 LDAP_LOG( BACK_META, DETAIL1,
708 "QUERY NOT CACHEABLE no\n",
710 #else /* !NEW_LOGGING */
711 Debug( LDAP_DEBUG_ANY, "QUERY NOT CACHEABLE no\n",
713 #endif /* !NEW_LOGGING */
718 switch (result->type) {
725 LDAP_LOG( BACK_META, DETAIL1,
726 "Invalid template error\n", 0, 0, 0 );
727 #else /* !NEW_LOGGING */
728 Debug( LDAP_DEBUG_ANY, "Invalid template error\n",
730 #endif /* !NEW_LOGGING */
736 LDAP_LOG( BACK_META, DETAIL1,
737 "Could not connect to a remote server\n",
739 #else /* !NEW_LOGGING */
740 Debug( LDAP_DEBUG_ANY,
741 "Could not connect to a remote server\n",
743 #endif /* !NEW_LOGGING */
744 send_ldap_error(op, rs, LDAP_OTHER,
745 "Connection error" );
751 LDAP_LOG( BACK_META, DETAIL1,
752 "Error in handling ldap_result\n", 0, 0, 0 );
753 #else /* !NEW_LOGGING */
754 Debug( LDAP_DEBUG_ANY,
755 "Error in handling ldap_result\n", 0, 0, 0 );
756 #endif /* !NEW_LOGGING */
761 if (result->rc == REWRITE_REGEXEC_UNWILLING) {
762 send_ldap_error( op, rs,
763 LDAP_UNWILLING_TO_PERFORM,
764 "Unwilling to perform" );
766 send_ldap_error( op, rs, LDAP_OTHER,
774 LDAP_LOG( BACK_META, DETAIL1,
775 "Error in merging entry \n", 0, 0, 0 );
776 #else /* !NEW_LOGGING */
777 Debug( LDAP_DEBUG_ANY,
778 "Error in merging entry \n", 0, 0, 0 );
779 #endif /* !NEW_LOGGING */
785 LDAP_LOG( BACK_META, DETAIL1,
786 "Error in removing query \n",
788 #else /* !NEW_LOGGING */
789 Debug( LDAP_DEBUG_ANY, "Error in removing query \n",
791 #endif /* !NEW_LOGGING */
804 for (i=0; (e = entry_array[i]); i++) {
813 if (new_attrs != attrs)
820 if (tempstr.bv_val ) {
821 free(tempstr.bv_val);
823 ldap_pvt_thread_mutex_lock(&cm->cache_mutex);
826 LDAP_LOG( BACK_META, DETAIL1, "Threads-- = %d\n", cm->threads, 0, 0 );
827 #else /* !NEW_LOGGING */
828 Debug( LDAP_DEBUG_ANY, "Threads-- = %d\n", cm->threads, 0, 0 );
829 #endif /* !NEW_LOGGING */
830 ldap_pvt_thread_mutex_unlock(&cm->cache_mutex);
841 struct exception* result
844 struct metainfo *li = ( struct metainfo * )be->be_private;
845 struct berval a, mapped;
847 BerElement ber = *e->lm_ber;
848 Attribute *attr, *soc_attr, **attrp;
849 struct berval dummy = { 0, NULL };
850 struct berval *bv, bdn;
857 if ( ber_scanf( &ber, "{m{", &bdn ) == LBER_ERROR ) {
858 result->type = CREATE_ENTRY_ERR;
861 ent = (Entry*)malloc(sizeof(Entry));
864 * Rewrite the dn of the result, if needed
866 rewriteSession( li->targets[ target ]->rwmap.rwm_rw, "searchResult",
867 bdn.bv_val, lc->conn, &ent->e_name.bv_val, result );
869 if (result->type != SUCCESS) {
872 if ( ent->e_name.bv_val == NULL ) {
873 ber_dupbv(&(ent->e_name), &bdn);
876 LDAP_LOG( BACK_META, DETAIL1,
877 "[rw] searchResult[%d]: \"%s\" -> \"%s\"\n",
878 target, bdn.bv_val, ent->e_name.bv_val );
879 #else /* !NEW_LOGGING */
880 Debug( LDAP_DEBUG_ARGS, "rw> searchResult[%d]: \"%s\""
882 target, bdn.bv_val, ent->e_name.bv_val );
883 #endif /* !NEW_LOGGING */
884 ent->e_name.bv_len = strlen( ent->e_name.bv_val );
888 * Note: this may fail if the target host(s) schema differs
889 * from the one known to the meta, and a DN with unknown
890 * attributes is returned.
892 * FIXME: should we log anything, or delegate to dnNormalize?
894 dnNormalize( 0, NULL, NULL, &ent->e_name, &ent->e_nname, NULL );
897 if ( dnNormalize( 0, NULL, NULL, &ent->e_name, &ent->e_nname )
900 return LDAP_INVALID_DN_SYNTAX;
907 if ( li->cache.ttl != META_DNCACHE_DISABLED ) {
908 meta_dncache_update_entry( &li->cache, &ent->e_nname, target );
914 ent->e_bv.bv_val = 0;
916 attrp = &ent->e_attrs;
918 while ( ber_scanf( &ber, "{m", &a ) != LBER_ERROR ) {
919 ldap_back_map( &li->targets[ target ]->rwmap.rwm_at,
921 if ( mapped.bv_val == NULL ) {
924 attr = ( Attribute * )ch_malloc( sizeof( Attribute ) );
925 if ( attr == NULL ) {
931 attr->a_nvals = NULL;
932 if ( slap_bv2ad( &mapped, &attr->a_desc, &text ) != LDAP_SUCCESS) {
933 if ( slap_bv2undef_ad( &mapped, &attr->a_desc, &text )
936 LDAP_LOG( BACK_META, DETAIL1,
937 "slap_bv2undef_ad(%s): %s\n",
938 mapped.bv_val, text, 0 );
939 #else /* !NEW_LOGGING */
940 Debug( LDAP_DEBUG_ANY,
941 "slap_bv2undef_ad(%s): "
942 "%s\n%s", mapped.bv_val, text, "" );
943 #endif /* !NEW_LOGGING */
949 /* no subschemaSubentry */
950 if ( attr->a_desc == slap_schema.si_ad_subschemaSubentry ) {
955 if ( ber_scanf( &ber, "[W]", &attr->a_vals ) == LBER_ERROR
956 || attr->a_vals == NULL ) {
957 attr->a_vals = &dummy;
959 } else if ( attr->a_desc == slap_schema.si_ad_objectClass ||
961 slap_schema.si_ad_structuralObjectClass) {
963 } else if ( attr->a_desc == slap_schema.si_ad_objectClass ) {
966 for ( last = 0; attr->a_vals[ last ].bv_val; ++last )
968 for ( i = 0, bv = attr->a_vals; bv->bv_val; bv++,i++ ) {
969 ldap_back_map( &li->targets[ target]->rwmap.rwm_oc,
971 if ( mapped.bv_val == NULL ) {
977 *bv = attr->a_vals[ last ];
978 attr->a_vals[ last ].bv_val = NULL;
980 } else if ( mapped.bv_val != bv->bv_val ) {
982 ber_dupbv( bv, &mapped );
986 structural_class( attr->a_vals, &sc, NULL, &text, textbuf, textlen );
987 soc_attr = (Attribute*) ch_malloc( sizeof( Attribute ));
988 soc_attr->a_desc = slap_schema.si_ad_structuralObjectClass;
989 soc_attr->a_vals = (BerVarray) ch_malloc( 2* sizeof( BerValue ));
990 ber_dupbv( &soc_attr->a_vals[0], &sc );
991 soc_attr->a_vals[1].bv_len = 0;
992 soc_attr->a_vals[1].bv_val = NULL;
993 soc_attr->a_nvals = (BerVarray) ch_malloc( 2* sizeof( BerValue ));
994 ber_dupbv( &soc_attr->a_nvals[0], &sc );
995 soc_attr->a_nvals[1].bv_len = 0;
996 soc_attr->a_nvals[1].bv_val = NULL;
999 attrp = &soc_attr->a_next;
1002 * It is necessary to try to rewrite attributes with
1003 * dn syntax because they might be used in ACLs as
1004 * members of groups; since ACLs are applied to the
1005 * rewritten stuff, no dn-based subecj clause could
1006 * be used at the ldap backend side (see
1007 * http://www.OpenLDAP.org/faq/data/cache/452.html)
1008 * The problem can be overcome by moving the dn-based
1009 * ACLs to the target directory server, and letting
1010 * everything pass thru the ldap backend.
1012 } else if ( strcmp( attr->a_desc->ad_type->sat_syntax->ssyn_oid,
1013 SLAPD_DN_SYNTAX ) == 0 ) {
1015 for ( i = 0, bv = attr->a_vals; bv->bv_val; bv++,i++ ) {
1017 rewriteSession(li->targets[ target ]->rwmap.rwm_rw,
1018 "searchResult", bv->bv_val,
1019 lc->conn, &newval, result);
1020 if (result->type != SUCCESS) {
1021 /* FIXME : Handle error */
1022 result->type = SUCCESS;
1025 if ( newval == NULL ) {
1029 LDAP_LOG( BACK_META, DETAIL1,
1030 "[rw] searchResult on "
1031 "attr=%s: \"%s\" -> \"%s\"\n",
1032 attr->a_desc->ad_type->
1034 bv->bv_val, newval );
1035 #else /* !NEW_LOGGING */
1036 Debug( LDAP_DEBUG_ARGS,
1037 "rw> searchResult on attr=%s:"
1038 " \"%s\" -> \"%s\"\n",
1039 attr->a_desc->ad_type->
1041 bv->bv_val, newval );
1042 #endif /* !NEW_LOGGING */
1044 bv->bv_val = newval;
1045 bv->bv_len = strlen( newval );
1050 attrp = &attr->a_next;
1063 if ( DN_SEPARATOR( rdn[ from ] ) ) {
1070 static struct metaconn*
1075 struct berval *nbase,
1076 struct exception *result)
1078 struct metaconn *lc;
1080 result->type = SUCCESS;
1081 lc = meta_back_getconn( op, rs, op_type, nbase, NULL );
1083 result->type = CONN_ERR;
1091 AttributeName** new_attrs,
1092 AttributeName* attrs,
1093 AttributeName* filter_attrs )
1095 struct berval all_user = { sizeof(LDAP_ALL_USER_ATTRIBUTES) -1,
1096 LDAP_ALL_USER_ATTRIBUTES };
1098 struct berval all_op = { sizeof(LDAP_ALL_OPERATIONAL_ATTRIBUTES) -1,
1099 LDAP_ALL_OPERATIONAL_ATTRIBUTES};
1106 /* duplicate attrs */
1107 if (attrs == NULL) {
1110 for (count=0; attrs[count].an_name.bv_val; count++)
1113 *new_attrs = (AttributeName*)(malloc((count+1)*sizeof(AttributeName)));
1114 if (attrs == NULL) {
1115 (*new_attrs)[0].an_name.bv_val = "*";
1116 (*new_attrs)[0].an_name.bv_len = 1;
1117 (*new_attrs)[1].an_name.bv_val = NULL;
1118 (*new_attrs)[1].an_name.bv_len = 0;
1122 for (i=0; i<count; i++) {
1123 (*new_attrs)[i].an_name = attrs[i].an_name;
1124 (*new_attrs)[i].an_desc = attrs[i].an_desc;
1126 (*new_attrs)[count].an_name.bv_val = NULL;
1127 (*new_attrs)[count].an_name.bv_len = 0;
1128 alluser = an_find(*new_attrs, &all_user);
1129 allop = an_find(*new_attrs, &all_op);
1132 for ( i=0; filter_attrs[i].an_name.bv_val; i++ ) {
1133 if ( an_find(*new_attrs, &filter_attrs[i].an_name ))
1135 if ( is_at_operational(filter_attrs[i].an_desc->ad_type) ) {
1140 *new_attrs = (AttributeName*)(realloc(*new_attrs,
1141 (count+2)*sizeof(AttributeName)));
1142 (*new_attrs)[count].an_name.bv_val =
1143 filter_attrs[i].an_name.bv_val;
1144 (*new_attrs)[count].an_name.bv_len =
1145 filter_attrs[i].an_name.bv_len;
1146 (*new_attrs)[count].an_desc = filter_attrs[i].an_desc;
1147 (*new_attrs)[count+1].an_name.bv_val = NULL;
1148 (*new_attrs)[count+1].an_name.bv_len = 0;
1155 struct metaconn* lc,
1158 int* msgid, Backend* be,
1159 AttributeName* attrs,
1163 Entry*** entry_array,
1166 struct exception* result)
1169 char *match = NULL, *err = NULL, *cache_ename = NULL;
1171 int mres = LDAP_SUCCESS;
1172 int num_entries = 0, count, i, rc;
1173 struct timeval tv = {0, 0};
1174 struct metasingleconn* lsc;
1175 struct metainfo *li = ( struct metainfo * )be->be_private;
1177 result->type = SUCCESS;
1179 for ( count = 0, rc = 0; candidates > 0; ) {
1182 /* check for abandon */
1185 for ( i = 0, lsc = lc->conns; !META_LAST(lsc); lsc++, i++ ) {
1186 if ( lsc->candidate != META_CANDIDATE ) {
1191 ldap_abandon( lsc->ld, msgid[ i ] );
1192 result->type = ABANDON_ERR;
1196 if ( slimit > 0 && num_entries == slimit ) {
1197 result->type = SLIMIT_ERR;
1201 if ((entry = get_result_entry(be, lc, lsc,
1202 msgid, i, &tv, result))) {
1203 rs->sr_entry = entry;
1204 rs->sr_attrs = op->ors_attrs;
1205 send_search_entry( op, rs );
1206 rs->sr_entry = NULL;
1207 rs->sr_attrs = NULL;
1209 (num_entries < curr_limit)) {
1210 rewriteSession( li->rwinfo,
1212 entry->e_name.bv_val,
1214 &cache_ename, result );
1215 free(entry->e_name.bv_val);
1216 if (result->type != SUCCESS) {
1219 ber_str2bv(cache_ename,
1220 strlen(cache_ename),
1222 ber_dupbv(&entry->e_nname,
1224 *entry_array = (Entry**)realloc(
1226 (( num_entries+2 ) *
1228 (*entry_array)[num_entries] = entry;
1229 (*entry_array)[num_entries+1] = NULL;
1233 } else if (result->type == REWRITING_ERR) {
1235 } else if (result->type == TIMEOUT_ERR) {
1236 result->type = SUCCESS;
1238 } else if (result->type == CREATE_ENTRY_ERR) {
1240 } else if (result->rc == -1) {
1243 rs->sr_err = result->rc;
1244 sres = ldap_back_map_result(rs);
1245 if (mres == LDAP_SUCCESS &&
1246 sres != LDAP_SUCCESS) {
1248 ldap_get_option(lsc->ld,
1249 LDAP_OPT_ERROR_STRING, &err);
1250 ldap_get_option(lsc->ld,
1251 LDAP_OPT_MATCHED_DN, &match);
1253 lsc->candidate = META_NOT_CANDIDATE;
1255 result->type = SUCCESS;
1258 switch (result->type) {
1261 LDAP_LOG( BACK_META, DETAIL1,
1262 "ldap_result error, rc = -1\n",
1264 #else /* !NEW_LOGGING */
1265 Debug( LDAP_DEBUG_ANY, "ldap_result error, rc = -1\n",
1267 #endif /* !NEW_LOGGING */
1268 rs->sr_err = LDAP_OTHER;
1269 send_ldap_result( op, rs );
1272 case CREATE_ENTRY_ERR:
1274 LDAP_LOG( BACK_META, DETAIL1,
1275 "Error in parsing result \n",
1277 #else /* !NEW_LOGGING */
1278 Debug( LDAP_DEBUG_ANY, "Error in parsing result \n",
1280 #endif /* !NEW_LOGGING */
1281 rs->sr_err = LDAP_OTHER;
1282 send_ldap_result( op, rs );
1283 result->type = RESULT_ERR;
1288 LDAP_LOG( BACK_META, DETAIL1, "Size limit exceeded \n",
1290 #else /* !NEW_LOGGING */
1291 Debug( LDAP_DEBUG_ANY, "Size limit exceeded \n",
1293 #endif /* !NEW_LOGGING */
1294 rs->sr_err = LDAP_SIZELIMIT_EXCEEDED;
1295 send_ldap_result( op, rs );
1296 result->type = RESULT_ERR;
1301 LDAP_LOG( BACK_META, DETAIL1,
1302 "search operation abandoned \n",
1304 #else /* !NEW_LOGGING */
1305 Debug( LDAP_DEBUG_ANY, "search operation abandoned \n",
1307 #endif /* !NEW_LOGGING */
1308 result->type = RESULT_ERR;
1317 tv.tv_usec = 100000;
1318 ldap_pvt_thread_yield();
1327 rs->sr_matched = match;
1329 send_ldap_result( op, rs );
1332 rs->sr_matched = NULL;
1340 result->type = (mres == LDAP_SUCCESS) ? SUCCESS : RESULT_ERR;
1347 struct metaconn* lc,
1348 struct metasingleconn* lsc,
1352 struct exception* result)
1355 LDAPMessage *res, *e;
1357 int sres = LDAP_SUCCESS;
1359 rc = ldap_result( lsc->ld, msgid[ i ],
1363 result->type = TIMEOUT_ERR;
1365 } else if ( rc == -1 ) {
1367 result->type = RESULT_ERR;
1369 } else if ( rc == LDAP_RES_SEARCH_ENTRY ) {
1370 e = ldap_first_entry( lsc->ld, res );
1371 entry = meta_create_entry(be, lc, i, e, result);
1375 ldap_msgfree( res );
1376 result->type = SUCCESS;
1379 sres = ldap_result2error( lsc->ld,
1382 result->type = RESULT_ERR;
1389 struct rewrite_info* info,
1390 const char* rewriteContext,
1394 struct exception* result)
1396 int rc = rewrite_session(info, rewriteContext, string, cookie, base);
1397 if (rc != REWRITE_REGEXEC_OK) {
1399 result->type = REWRITING_ERR;
1401 if (strcmp(rewriteContext, "searchBase") == 0)
1403 LDAP_LOG( BACK_META, DETAIL1,
1404 "Problem in rewriting search base\n", 0, 0, 0 );
1405 #else /* !NEW_LOGGING */
1406 Debug( LDAP_DEBUG_ANY,
1407 "Problem in rewriting search base\n", 0, 0, 0 );
1408 #endif /* !NEW_LOGGING */
1409 if (strcmp(rewriteContext, "searchFilter") == 0)
1411 LDAP_LOG( BACK_META, DETAIL1,
1412 "Problem in rewriting search filter\n",
1414 #else /* !NEW_LOGGING */
1415 Debug( LDAP_DEBUG_ANY,
1416 "Problem in rewriting search filter\n",
1418 #endif /* !NEW_LOGGING */
1419 if (strcmp(rewriteContext, "searchResult") == 0)
1421 LDAP_LOG( BACK_META, DETAIL1,
1422 "Problem in rewriting DN, or DN syntax "
1423 "attributes of search result\n", 0, 0, 0 );
1424 #else /* !NEW_LOGGING */
1425 Debug( LDAP_DEBUG_ANY,
1426 "Problem in rewriting DN, or DN syntax "
1427 "attributes of search result\n", 0, 0, 0 );
1428 #endif /* !NEW_LOGGING */
1429 if (strcmp(rewriteContext, "cacheBase") == 0)
1431 LDAP_LOG( BACK_META, DETAIL1,
1432 "Problem in rewriting search base with "
1433 "cache base\n", 0, 0, 0 );
1434 #else /* !NEW_LOGGING */
1435 Debug( LDAP_DEBUG_ANY,
1436 "Problem in rewriting search base with "
1437 "cache base\n", 0, 0, 0 );
1438 #endif /* !NEW_LOGGING */
1439 if (strcmp(rewriteContext, "cacheResult") == 0)
1441 LDAP_LOG( BACK_META, DETAIL1,
1442 "Problem in rewriting DN for cached entries\n",
1444 #else /* !NEW_LOGGING */
1445 Debug( LDAP_DEBUG_ANY,
1446 "Problem in rewriting DN for cached entries\n",
1448 #endif /* !NEW_LOGGING */
1449 if (strcmp(rewriteContext, "cacheReturn") == 0)
1451 LDAP_LOG( BACK_META, DETAIL1,
1452 "Problem in rewriting DN for answerable "
1453 "entries\n", 0, 0, 0 );
1454 #else /* !NEW_LOGGING */
1455 Debug( LDAP_DEBUG_ANY,
1456 "Problem in rewriting DN for answerable "
1457 "entries\n", 0, 0, 0 );
1458 #endif /* !NEW_LOGGING */
1460 result->type = SUCCESS;
1466 AttributeName* attrs,
1471 for (i=0; i<num; i++) {
1472 if (attrscmp(attrs, qm->attr_sets[i].attrs))
1480 AttributeName* attrs_in,
1481 AttributeName* attrs)
1483 int i, count1, count2;
1484 if ( attrs_in == NULL ) {
1485 return (attrs ? 0 : 1);
1487 if ( attrs == NULL )
1491 attrs_in && attrs_in[count1].an_name.bv_val != NULL;
1495 attrs && attrs[count2].an_name.bv_val != NULL;
1498 if ( count1 != count2 )
1501 for ( i=0; i<count1; i++ ) {
1502 if ( !an_find(attrs, &attrs_in[i].an_name ))
1512 Entry** entry_array,
1514 struct exception* result)
1520 struct berval query_uuid;
1521 struct berval crp_uuid;
1522 char uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ], *crpid;
1524 query_manager *qm = cm->qm;
1526 result->type = SUCCESS;
1527 query_uuid.bv_len = lutil_uuidstr(uuidbuf, sizeof(uuidbuf));
1528 query_uuid.bv_val = ch_strdup(uuidbuf);
1531 LDAP_LOG( BACK_META, DETAIL1, "UUID for query being added = %s\n",
1533 #else /* !NEW_LOGGING */
1534 Debug( LDAP_DEBUG_ANY, "UUID for query being added = %s\n",
1536 #endif /* !NEW_LOGGING */
1538 for ( i=0; ( entry_array && (e=entry_array[i]) ); i++ ) {
1540 LDAP_LOG( BACK_META, DETAIL2, "LOCKING REMOVE MUTEX\n",
1542 #else /* !NEW_LOGGING */
1543 Debug( LDAP_DEBUG_NONE, "LOCKING REMOVE MUTEX\n", 0, 0, 0 );
1544 #endif /* !NEW_LOGGING */
1545 ldap_pvt_thread_mutex_lock(&cm->remove_mutex);
1547 LDAP_LOG( BACK_META, DETAIL2, "LOCKED REMOVE MUTEX\n", 0, 0, 0);
1548 #else /* !NEW_LOGGING */
1549 Debug( LDAP_DEBUG_NONE, "LOCKED REMOVE MUTEX\n", 0, 0, 0);
1550 #endif /* !NEW_LOGGING */
1551 if ( cm->cache_size > (cm->thresh_hi) ) {
1552 while(cm->cache_size > (cm->thresh_lo)) {
1553 crpid = cache_replacement(qm);
1554 if (crpid == NULL) {
1555 result->type = REMOVE_ERR;
1557 strcpy(crpuuid, crpid);
1558 crp_uuid.bv_val = crpuuid;
1559 crp_uuid.bv_len = strlen(crpuuid);
1561 LDAP_LOG( BACK_META, DETAIL1,
1562 "Removing query UUID %s\n",
1564 #else /* !NEW_LOGGING */
1565 Debug( LDAP_DEBUG_ANY,
1566 "Removing query UUID %s\n",
1568 #endif /* !NEW_LOGGING */
1569 return_val = remove_query_data(op, rs,
1572 LDAP_LOG( BACK_META, DETAIL1,
1573 "QUERY REMOVED, SIZE=%d\n",
1575 #else /* !NEW_LOGGING */
1576 Debug( LDAP_DEBUG_ANY,
1577 "QUERY REMOVED, SIZE=%d\n",
1579 #endif /* !NEW_LOGGING */
1580 ldap_pvt_thread_mutex_lock(
1582 cm->total_entries -= result->rc;
1583 cm->num_cached_queries--;
1585 LDAP_LOG( BACK_META, DETAIL1,
1586 "STORED QUERIES = %lu\n",
1587 cm->num_cached_queries, 0, 0 );
1588 #else /* !NEW_LOGGING */
1589 Debug( LDAP_DEBUG_ANY,
1590 "STORED QUERIES = %lu\n",
1591 cm->num_cached_queries, 0, 0 );
1592 #endif /* !NEW_LOGGING */
1593 ldap_pvt_thread_mutex_unlock(
1595 cm->cache_size = (return_val >
1597 0 : (cm->cache_size-return_val);
1599 LDAP_LOG( BACK_META, DETAIL1,
1600 "QUERY REMOVED, CACHE SIZE="
1601 "%lu bytes %d entries\n",
1603 cm->total_entries, 0 );
1604 #else /* !NEW_LOGGING */
1605 Debug( LDAP_DEBUG_ANY,
1606 "QUERY REMOVED, CACHE SIZE="
1607 "%lu bytes %d entries\n",
1609 cm->total_entries, 0 );
1610 #endif /* !NEW_LOGGING */
1616 return_val = merge_entry(op, rs, &query_uuid, result);
1617 rs->sr_entry = NULL;
1618 cm->cache_size += return_val;
1620 LDAP_LOG( BACK_META, DETAIL1,
1621 "ENTRY ADDED/MERGED, CACHE SIZE=%lu bytes\n",
1622 cm->cache_size, 0, 0 );
1623 #else /* !NEW_LOGGING */
1624 Debug( LDAP_DEBUG_ANY,
1625 "ENTRY ADDED/MERGED, CACHE SIZE=%lu bytes\n",
1626 cm->cache_size, 0, 0 );
1627 #endif /* !NEW_LOGGING */
1629 LDAP_LOG( BACK_META, DETAIL2, "UNLOCKING REMOVE MUTEX\n",
1631 #else /* !NEW_LOGGING */
1632 Debug( LDAP_DEBUG_NONE, "UNLOCKING REMOVE MUTEX\n", 0, 0, 0 );
1633 #endif /* !NEW_LOGGING */
1634 ldap_pvt_thread_mutex_unlock(&cm->remove_mutex);
1636 LDAP_LOG( BACK_META, DETAIL2, "UNLOCKED REMOVE MUTEX\n",
1638 #else /* !NEW_LOGGING */
1639 Debug( LDAP_DEBUG_NONE, "UNLOCKED REMOVE MUTEX\n", 0, 0, 0 );
1640 #endif /* !NEW_LOGGING */
1641 if (result->type != SUCCESS)
1643 ldap_pvt_thread_mutex_lock(&cm->cache_mutex);
1644 cm->total_entries += result->rc;
1646 LDAP_LOG( BACK_META, DETAIL1,
1647 "ENTRY ADDED/MERGED, SIZE=%d, CACHED ENTRIES=%d\n",
1648 return_val, cm->total_entries, 0 );
1649 #else /* !NEW_LOGGING */
1650 Debug( LDAP_DEBUG_ANY,
1651 "ENTRY ADDED/MERGED, SIZE=%d, CACHED ENTRIES=%d\n",
1652 return_val, cm->total_entries, 0 );
1653 #endif /* !NEW_LOGGING */
1654 ldap_pvt_thread_mutex_unlock(&cm->cache_mutex);
1656 ldap_pvt_thread_mutex_lock(&cm->cache_mutex);
1657 cm->num_cached_queries++;
1659 LDAP_LOG( BACK_META, DETAIL1, "STORED QUERIES = %lu\n",
1660 cm->num_cached_queries, 0, 0 );
1661 #else /* !NEW_LOGGING */
1662 Debug( LDAP_DEBUG_ANY, "STORED QUERIES = %lu\n",
1663 cm->num_cached_queries, 0, 0 );
1664 #endif /* !NEW_LOGGING */
1665 ldap_pvt_thread_mutex_unlock(&cm->cache_mutex);
1667 return query_uuid.bv_val;
1673 struct berval* tempstr,
1681 i = qm->templates[template_id].attr_set_index;
1682 str = qm->templates[template_id].querystr;
1684 if (attr_set == i) {
1687 id_array = qm->attr_sets[attr_set].ID_array;
1689 while (*id_array != -1) {
1697 if (strcasecmp(str, tempstr->bv_val) == 0)
1703 consistency_check(void* operation)
1705 Operation* op = (Operation*)operation;
1707 SlapReply rs = {REP_RESULT};
1709 struct metainfo *li = ( struct metainfo * )op->o_bd->be_private;
1710 cache_manager* cm = li->cm;
1711 query_manager* qm = cm->qm;
1712 CachedQuery* query, *query_prev;
1715 struct exception result;
1717 QueryTemplate* templ;
1720 op->o_bd = li->glue_be;
1723 ldap_pvt_thread_sleep(cm->cc_period);
1724 for (i=0; qm->templates[i].querystr; i++) {
1725 templ = qm->templates + i;
1726 query = templ->query_last;
1727 curr_time = slap_get_time();
1728 ldap_pvt_thread_mutex_lock(&cm->remove_mutex);
1729 while (query && (query->expiry_time < curr_time)) {
1730 ldap_pvt_thread_mutex_lock(&qm->lru_mutex);
1731 remove_query(qm, query);
1732 ldap_pvt_thread_mutex_unlock(&qm->lru_mutex);
1734 LDAP_LOG( BACK_META, DETAIL1, "Lock CR index = %d\n",
1736 #else /* !NEW_LOGGING */
1737 Debug( LDAP_DEBUG_ANY, "Lock CR index = %d\n",
1739 #endif /* !NEW_LOGGING */
1740 ldap_pvt_thread_rdwr_wlock(&templ->t_rwlock);
1741 remove_from_template(query, templ);
1743 LDAP_LOG( BACK_META, DETAIL1,
1744 "TEMPLATE %d QUERIES-- %d\n",
1745 i, templ->no_of_queries, 0 );
1746 #else /* !NEW_LOGGING */
1747 Debug( LDAP_DEBUG_ANY, "TEMPLATE %d QUERIES-- %d\n",
1748 i, templ->no_of_queries, 0 );
1749 #endif /* !NEW_LOGGING */
1751 LDAP_LOG( BACK_META, DETAIL1, "Unlock CR index = %d\n",
1753 #else /* !NEW_LOGGING */
1754 Debug( LDAP_DEBUG_ANY, "Unlock CR index = %d\n",
1756 #endif /* !NEW_LOGGING */
1757 ldap_pvt_thread_rdwr_wunlock(&templ->t_rwlock);
1758 uuid.bv_val = query->q_uuid;
1759 uuid.bv_len = strlen(query->q_uuid);
1760 return_val = remove_query_data(op, &rs, &uuid, &result);
1762 LDAP_LOG( BACK_META, DETAIL1,
1763 "STALE QUERY REMOVED, SIZE=%d\n",
1765 #else /* !NEW_LOGGING */
1766 Debug( LDAP_DEBUG_ANY, "STALE QUERY REMOVED, SIZE=%d\n",
1768 #endif /* !NEW_LOGGING */
1769 ldap_pvt_thread_mutex_lock(&cm->cache_mutex);
1770 cm->total_entries -= result.rc;
1771 cm->num_cached_queries--;
1773 LDAP_LOG( BACK_META, DETAIL1, "STORED QUERIES = %lu\n",
1774 cm->num_cached_queries, 0, 0 );
1775 #else /* !NEW_LOGGING */
1776 Debug( LDAP_DEBUG_ANY, "STORED QUERIES = %lu\n",
1777 cm->num_cached_queries, 0, 0 );
1778 #endif /* !NEW_LOGGING */
1779 ldap_pvt_thread_mutex_unlock(&cm->cache_mutex);
1780 cm->cache_size = (return_val > cm->cache_size) ?
1781 0: (cm->cache_size-return_val);
1783 LDAP_LOG( BACK_META, DETAIL1,
1784 "STALE QUERY REMOVED, CACHE SIZE=%lu bytes %d "
1785 "entries\n", cm->cache_size,
1786 cm->total_entries, 0 );
1787 #else /* !NEW_LOGGING */
1788 Debug( LDAP_DEBUG_ANY,
1789 "STALE QUERY REMOVED, CACHE SIZE=%lu bytes %d "
1790 "entries\n", cm->cache_size,
1791 cm->total_entries, 0 );
1792 #endif /* !NEW_LOGGING */
1794 query = query->prev;
1795 free_query(query_prev);
1797 ldap_pvt_thread_mutex_unlock(&cm->remove_mutex);
1807 slap_callback *cb = op->o_callback;
1808 /*struct metainfo *li = ( struct metainfo * )op->o_bd->be_private;*/
1809 Backend* be = (Backend*)(cb->sc_private);
1810 struct metainfo *li = ( struct metainfo * )be->be_private;
1813 struct exception result;
1817 if (rs->sr_type == REP_SEARCH) {
1818 dn = rs->sr_entry->e_name;
1819 ndn = rs->sr_entry->e_nname;
1821 rewriteSession( li->rwinfo, "cacheReturn",
1822 rs->sr_entry->e_name.bv_val, op->o_conn,
1824 ber_str2bv(ename, strlen(ename), 0, &rs->sr_entry->e_name);
1825 /* FIXME: should we normalize this? */
1826 ber_dupbv(&rs->sr_entry->e_nname, &rs->sr_entry->e_name);
1828 op->o_callback = NULL;
1830 send_search_entry( op, rs );
1832 rs->sr_entry->e_name = dn;
1833 rs->sr_entry->e_nname = ndn;
1835 op->o_callback = cb;
1837 } else if (rs->sr_type == REP_RESULT) {
1838 op->o_callback = NULL;
1839 send_ldap_result( op, rs );