2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 2003-2008 The OpenLDAP Foundation.
5 * Portions Copyright 2003 IBM Corporation.
6 * Portions Copyright 2003 Symas Corporation.
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 the 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 Apurva Kumar for inclusion
19 * in OpenLDAP Software and subsequently rewritten by Howard Chu.
24 #ifdef SLAPD_OVER_PROXYCACHE
28 #include <ac/string.h>
40 * Control that allows to access the private DB
41 * instead of the public one
43 #define PCACHE_CONTROL_PRIVDB "1.3.6.1.4.1.4203.666.11.9.5.1"
46 * Extended Operation that allows to remove a query from the cache
48 #define PCACHE_EXOP_QUERY_DELETE "1.3.6.1.4.1.4203.666.11.9.6.1"
51 /* query cache structs */
54 typedef struct Query_s {
55 Filter* filter; /* Search Filter */
56 struct berval base; /* Search Base */
57 int scope; /* Search scope */
60 struct query_template_s;
62 typedef struct Qbase_s {
63 Avlnode *scopes[4]; /* threaded AVL trees of cached queries */
68 /* struct representing a cached query */
69 typedef struct cached_query_s {
74 struct berval q_uuid; /* query identifier */
76 struct query_template_s *qtemp; /* template of the query */
77 time_t expiry_time; /* time till the query is considered valid */
78 struct cached_query_s *next; /* next query in the template */
79 struct cached_query_s *prev; /* previous query in the template */
80 struct cached_query_s *lru_up; /* previous query in the LRU list */
81 struct cached_query_s *lru_down; /* next query in the LRU list */
82 ldap_pvt_thread_rdwr_t rwlock;
88 * ldap:///<base>??<scope>?<filter>?x-uuid=<uid>,x-template=<template>,x-attrset=<attrset>,x-expiry=<expiry>
90 * <base> ::= CachedQuery.qbase->base
91 * <scope> ::= CachedQuery.scope
92 * <filter> ::= filter2bv(CachedQuery.filter)
93 * <uuid> ::= CachedQuery.q_uuid
94 * <attrset> ::= CachedQuery.qtemp->attr_set_index
95 * <expiry> ::= CachedQuery.expiry_time
97 * quick hack: parse URI, call add_query() and then fix
98 * CachedQuery.expiry_time and CachedQuery.q_uuid
102 * Represents a set of projected attributes.
106 struct query_template_s *templates;
107 AttributeName* attrs; /* specifies the set */
109 #define PC_CONFIGURED (0x1)
110 #define PC_REFERENCED (0x2)
111 #define PC_GOT_OC (0x4)
112 int count; /* number of attributes */
115 /* struct representing a query template
116 * e.g. template string = &(cn=)(mail=)
118 typedef struct query_template_s {
119 struct query_template_s *qtnext;
120 struct query_template_s *qmnext;
123 CachedQuery* query; /* most recent query cached for the template */
124 CachedQuery* query_last; /* oldest query cached for the template */
125 ldap_pvt_thread_rdwr_t t_rwlock; /* Rd/wr lock for accessing queries in the template */
126 struct berval querystr; /* Filter string corresponding to the QT */
128 int attr_set_index; /* determines the projected attributes */
129 int no_of_queries; /* Total number of queries in the template */
130 time_t ttl; /* TTL for the queries of this template */
131 time_t negttl; /* TTL for negative results */
132 time_t limitttl; /* TTL for sizelimit exceeding results */
133 struct attr_set t_attrs; /* filter attrs + attr_set */
141 } pc_caching_reason_t;
143 static const char *pc_caching_reason_str[] = {
152 struct query_manager_s;
154 /* prototypes for functions for 1) query containment
155 * 2) query addition, 3) cache replacement
157 typedef CachedQuery *(QCfunc)(Operation *op, struct query_manager_s*,
158 Query*, QueryTemplate*);
159 typedef CachedQuery *(AddQueryfunc)(Operation *op, struct query_manager_s*,
160 Query*, QueryTemplate*, pc_caching_reason_t, int wlock);
161 typedef void (CRfunc)(struct query_manager_s*, struct berval*);
163 /* LDAP query cache */
164 typedef struct query_manager_s {
165 struct attr_set* attr_sets; /* possible sets of projected attributes */
166 QueryTemplate* templates; /* cacheable templates */
168 CachedQuery* lru_top; /* top and bottom of LRU list */
169 CachedQuery* lru_bottom;
171 ldap_pvt_thread_mutex_t lru_mutex; /* mutex for accessing LRU list */
173 /* Query cache methods */
174 QCfunc *qcfunc; /* Query containment*/
175 CRfunc *crfunc; /* cache replacement */
176 AddQueryfunc *addfunc; /* add query */
179 /* LDAP query cache manager */
180 typedef struct cache_manager_s {
181 BackendDB db; /* underlying database */
182 unsigned long num_cached_queries; /* total number of cached queries */
183 unsigned long max_queries; /* upper bound on # of cached queries */
184 int save_queries; /* save cached queries across restarts */
185 int check_cacheability; /* check whether a query is cacheable */
186 int numattrsets; /* number of attribute sets */
187 int cur_entries; /* current number of entries cached */
188 int max_entries; /* max number of entries cached */
189 int num_entries_limit; /* max # of entries in a cacheable query */
191 char response_cb; /* install the response callback
192 * at the tail of the callback list */
193 #define PCACHE_RESPONSE_CB_HEAD 0
194 #define PCACHE_RESPONSE_CB_TAIL 1
195 char defer_db_open; /* defer open for online add */
197 time_t cc_period; /* interval between successive consistency checks (sec) */
201 ldap_pvt_thread_mutex_t cache_mutex;
203 query_manager* qm; /* query cache managed by the cache manager */
206 static int pcache_debug;
208 #ifdef PCACHE_CONTROL_PRIVDB
209 static int privDB_cid;
210 #endif /* PCACHE_CONTROL_PRIVDB */
212 static AttributeDescription *ad_queryId, *ad_cachedQueryURL;
215 AttributeDescription **adp;
217 { "( 1.3.6.1.4.1.4203.666.11.9.1.1 "
219 "DESC 'ID of query the entry belongs to, formatted as a UUID' "
220 "EQUALITY octetStringMatch "
221 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40{64} "
222 "NO-USER-MODIFICATION "
223 "USAGE directoryOperation )",
225 { "( 1.3.6.1.4.1.4203.666.11.9.1.2 "
226 "NAME 'cachedQueryURL' "
227 "DESC 'URI describing a cached query' "
228 "EQUALITY caseExactMatch "
229 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 "
230 "NO-USER-MODIFICATION "
231 "USAGE directoryOperation )",
232 &ad_cachedQueryURL },
241 AttributeName** filter_attrs,
243 int* filter_got_oc );
250 QueryTemplate *templ,
251 pc_caching_reason_t why,
258 struct berval *query_uuid );
261 * Turn a cached query into its URL representation
264 query2url( Operation *op, CachedQuery *q, struct berval *urlbv )
266 struct berval bv_scope,
268 char attrset_buf[ LDAP_PVT_INTTYPE_CHARS( unsigned long ) ],
269 expiry_buf[ LDAP_PVT_INTTYPE_CHARS( unsigned long ) ],
271 ber_len_t attrset_len,
274 ldap_pvt_scope2bv( q->scope, &bv_scope );
275 filter2bv_x( op, q->filter, &bv_filter );
276 attrset_len = sprintf( attrset_buf,
277 "%lu", (unsigned long)q->qtemp->attr_set_index );
278 expiry_len = sprintf( expiry_buf,
279 "%lu", (unsigned long)q->expiry_time );
281 urlbv->bv_len = STRLENOF( "ldap:///" )
282 + q->qbase->base.bv_len
287 + STRLENOF( "?x-uuid=" )
289 + STRLENOF( ",x-attrset=" )
291 + STRLENOF( ",x-expiry=" )
293 ptr = urlbv->bv_val = ber_memalloc_x( urlbv->bv_len + 1, op->o_tmpmemctx );
294 ptr = lutil_strcopy( ptr, "ldap:///" );
295 ptr = lutil_strcopy( ptr, q->qbase->base.bv_val );
296 ptr = lutil_strcopy( ptr, "??" );
297 ptr = lutil_strcopy( ptr, bv_scope.bv_val );
298 ptr = lutil_strcopy( ptr, "?" );
299 ptr = lutil_strcopy( ptr, bv_filter.bv_val );
300 ptr = lutil_strcopy( ptr, "?x-uuid=" );
301 ptr = lutil_strcopy( ptr, q->q_uuid.bv_val );
302 ptr = lutil_strcopy( ptr, ",x-attrset=" );
303 ptr = lutil_strcopy( ptr, attrset_buf );
304 ptr = lutil_strcopy( ptr, ",x-expiry=" );
305 ptr = lutil_strcopy( ptr, expiry_buf );
307 ber_memfree_x( bv_filter.bv_val, op->o_tmpmemctx );
313 * Turn an URL representing a formerly cached query into a cached query,
314 * and try to cache it
325 LDAPURLDesc *lud = NULL;
327 tempstr = BER_BVNULL,
337 rc = ldap_url_parse( url, &lud );
338 if ( rc != LDAP_URL_SUCCESS ) {
342 /* non-allowed fields */
343 if ( lud->lud_host != NULL ) {
348 if ( lud->lud_attrs != NULL ) {
354 if ( strcmp( lud->lud_scheme, "ldap" ) != 0 ) {
359 /* required fields */
360 if ( lud->lud_dn == NULL || lud->lud_dn[ 0 ] == '\0' ) {
365 switch ( lud->lud_scope ) {
366 case LDAP_SCOPE_BASE:
367 case LDAP_SCOPE_ONELEVEL:
368 case LDAP_SCOPE_SUBTREE:
369 case LDAP_SCOPE_SUBORDINATE:
377 if ( lud->lud_filter == NULL || lud->lud_filter[ 0 ] == '\0' ) {
382 if ( lud->lud_exts == NULL ) {
387 for ( i = 0; lud->lud_exts[ i ] != NULL; i++ ) {
388 if ( strncmp( lud->lud_exts[ i ], "x-uuid=", STRLENOF( "x-uuid=" ) ) == 0 ) {
389 struct berval tmpUUID;
390 Syntax *syn_UUID = slap_schema.si_ad_entryUUID->ad_type->sat_syntax;
392 ber_str2bv( &lud->lud_exts[ i ][ STRLENOF( "x-uuid=" ) ], 0, 0, &tmpUUID );
393 rc = syn_UUID->ssyn_pretty( syn_UUID, &tmpUUID, &uuid, NULL );
394 if ( rc != LDAP_SUCCESS ) {
399 } else if ( strncmp( lud->lud_exts[ i ], "x-attrset=", STRLENOF( "x-attrset=" ) ) == 0 ) {
400 rc = lutil_atoi( &attrset, &lud->lud_exts[ i ][ STRLENOF( "x-attrset=" ) ] );
406 } else if ( strncmp( lud->lud_exts[ i ], "x-expiry=", STRLENOF( "x-expiry=" ) ) == 0 ) {
409 rc = lutil_atoul( &l, &lud->lud_exts[ i ][ STRLENOF( "x-expiry=" ) ] );
413 expiry_time = (time_t)l;
427 if ( !got_attrset ) {
437 /* ignore expired queries */
438 if ( expiry_time <= slap_get_time()) {
440 SlapReply rs2 = { 0 };
442 memset( &op2.oq_search, 0, sizeof( op2.oq_search ) );
444 (void)remove_query_data( &op2, &rs2, &uuid );
449 ber_str2bv( lud->lud_dn, 0, 0, &base );
450 rc = dnNormalize( 0, NULL, NULL, &base, &query.base, NULL );
451 if ( rc != LDAP_SUCCESS ) {
454 query.scope = lud->lud_scope;
455 query.filter = str2filter( lud->lud_filter );
457 tempstr.bv_val = ch_malloc( strlen( lud->lud_filter ) + 1 );
459 if ( filter2template( op, query.filter, &tempstr, NULL, NULL, NULL ) ) {
460 ch_free( tempstr.bv_val );
465 /* check for query containment */
466 qt = qm->attr_sets[attrset].templates;
467 for ( ; qt; qt = qt->qtnext ) {
468 /* find if template i can potentially answer tempstr */
469 if ( bvmatch( &qt->querystr, &tempstr ) ) {
479 cq = add_query( op, qm, &query, qt, PC_POSITIVE, 0 );
481 cq->expiry_time = expiry_time;
484 /* it's now into cq->filter */
494 if ( query.filter != NULL ) filter_free( query.filter );
495 if ( !BER_BVISNULL( &tempstr ) ) ch_free( tempstr.bv_val );
496 if ( !BER_BVISNULL( &query.base ) ) ch_free( query.base.bv_val );
497 if ( !BER_BVISNULL( &uuid ) ) ch_free( uuid.bv_val );
498 if ( lud != NULL ) ldap_free_urldesc( lud );
503 /* Return 1 for an added entry, else 0 */
508 struct berval* query_uuid )
511 Modifications* modlist = NULL;
512 const char* text = NULL;
514 char textbuf[SLAP_TEXT_BUFLEN];
515 size_t textlen = sizeof(textbuf);
517 SlapReply sreply = {REP_RESULT};
519 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
524 /* add queryId attribute */
525 attr_merge_one( e, ad_queryId, query_uuid, NULL );
527 /* append the attribute list from the fetched entry */
528 e->e_attrs->a_next = attr;
530 op->o_tag = LDAP_REQ_ADD;
531 op->o_protocol = LDAP_VERSION3;
532 op->o_callback = &cb;
533 op->o_time = slap_get_time();
534 op->o_do_not_cache = 1;
537 op->o_req_dn = e->e_name;
538 op->o_req_ndn = e->e_nname;
539 rc = op->o_bd->be_add( op, &sreply );
541 if ( rc != LDAP_SUCCESS ) {
542 if ( rc == LDAP_ALREADY_EXISTS ) {
543 slap_entry2mods( e, &modlist, &text, textbuf, textlen );
544 modlist->sml_op = LDAP_MOD_ADD;
545 op->o_tag = LDAP_REQ_MODIFY;
546 op->orm_modlist = modlist;
547 op->o_bd->be_modify( op, &sreply );
548 slap_mods_free( modlist, 1 );
549 } else if ( rc == LDAP_REFERRAL ||
550 rc == LDAP_NO_SUCH_OBJECT ) {
551 syncrepl_add_glue( op, e );
560 if ( op->ora_e == e )
561 be_entry_release_w( op, e );
568 /* Length-ordered sort on normalized DNs */
569 static int pcache_dn_cmp( const void *v1, const void *v2 )
571 const Qbase *q1 = v1, *q2 = v2;
573 int rc = q1->base.bv_len - q2->base.bv_len;
575 rc = strncmp( q1->base.bv_val, q2->base.bv_val, q1->base.bv_len );
579 static int lex_bvcmp( struct berval *bv1, struct berval *bv2 )
582 dif = bv1->bv_len - bv2->bv_len;
584 if ( dif > 0 ) len -= dif;
585 len = memcmp( bv1->bv_val, bv2->bv_val, len );
591 /* compare the first value in each filter */
592 static int pcache_filter_cmp( const void *v1, const void *v2 )
594 const CachedQuery *q1 = v1, *q2 =v2;
595 int rc, weight1, weight2;
597 switch( q1->first->f_choice ) {
598 case LDAP_FILTER_PRESENT:
601 case LDAP_FILTER_EQUALITY:
609 switch( q2->first->f_choice ) {
610 case LDAP_FILTER_PRESENT:
613 case LDAP_FILTER_EQUALITY:
621 rc = weight1 - weight2;
626 rc = lex_bvcmp( &q1->first->f_av_value, &q2->first->f_av_value );
629 if ( q1->first->f_choice == LDAP_FILTER_SUBSTRINGS ) {
631 if ( !BER_BVISNULL( &q1->first->f_sub_initial )) {
632 if ( !BER_BVISNULL( &q2->first->f_sub_initial )) {
633 rc = lex_bvcmp( &q1->first->f_sub_initial,
634 &q2->first->f_sub_initial );
638 } else if ( !BER_BVISNULL( &q2->first->f_sub_initial )) {
642 if ( q1->first->f_sub_any ) {
643 if ( q2->first->f_sub_any ) {
644 rc = lex_bvcmp( q1->first->f_sub_any,
645 q2->first->f_sub_any );
649 } else if ( q2->first->f_sub_any ) {
653 if ( !BER_BVISNULL( &q1->first->f_sub_final )) {
654 if ( !BER_BVISNULL( &q2->first->f_sub_final )) {
655 rc = lex_bvcmp( &q1->first->f_sub_final,
656 &q2->first->f_sub_final );
660 } else if ( !BER_BVISNULL( &q2->first->f_sub_final )) {
664 rc = lex_bvcmp( &q1->first->f_mr_value,
665 &q2->first->f_mr_value );
674 /* add query on top of LRU list */
676 add_query_on_top (query_manager* qm, CachedQuery* qc)
678 CachedQuery* top = qm->lru_top;
689 Debug( pcache_debug, "Base of added query = %s\n",
690 qc->qbase->base.bv_val, 0, 0 );
693 /* remove_query from LRU list */
696 remove_query (query_manager* qm, CachedQuery* qc)
719 qc->lru_up = qc->lru_down = NULL;
722 /* find and remove string2 from string1
723 * from start if position = 1,
724 * from end if position = 3,
725 * from anywhere if position = 2
726 * string1 is overwritten if position = 2.
730 find_and_remove(struct berval* ber1, struct berval* ber2, int position)
741 if ( ber1->bv_len >= ber2->bv_len && !memcmp( ber1->bv_val,
742 ber2->bv_val, ber2->bv_len )) {
744 ber1->bv_val += ber2->bv_len;
745 ber1->bv_len -= ber2->bv_len;
750 ber1->bv_val[ber1->bv_len] = '\0';
751 temp = strstr( ber1->bv_val, ber2->bv_val );
753 strcpy( temp, temp+ber2->bv_len );
754 ber1->bv_len -= ber2->bv_len;
760 if ( ber1->bv_len >= ber2->bv_len &&
761 !memcmp( ber1->bv_val+ber1->bv_len-ber2->bv_len, ber2->bv_val,
764 ber1->bv_len -= ber2->bv_len;
772 static struct berval*
773 merge_init_final(Operation *op, struct berval* init, struct berval* any,
774 struct berval* final)
776 struct berval* merged, *temp;
777 int i, any_count, count;
779 for (any_count=0; any && any[any_count].bv_val; any_count++)
789 merged = (struct berval*)op->o_tmpalloc( (count+1)*sizeof(struct berval),
794 ber_dupbv_x( temp, init, op->o_tmpmemctx );
798 for (i=0; i<any_count; i++) {
799 ber_dupbv_x( temp, any, op->o_tmpmemctx );
804 ber_dupbv_x( temp, final, op->o_tmpmemctx );
811 /* Each element in stored must be found in incoming. Incoming is overwritten.
814 strings_containment(struct berval* stored, struct berval* incoming)
816 struct berval* element;
820 for ( element=stored; element->bv_val != NULL; element++ ) {
821 for (j = k; incoming[j].bv_val != NULL; j++) {
822 if (find_and_remove(&(incoming[j]), element, 2)) {
839 substr_containment_substr(Operation *op, Filter* stored, Filter* incoming)
843 struct berval init_incoming;
844 struct berval final_incoming;
845 struct berval *remaining_incoming = NULL;
847 if ((!(incoming->f_sub_initial.bv_val) && (stored->f_sub_initial.bv_val))
848 || (!(incoming->f_sub_final.bv_val) && (stored->f_sub_final.bv_val)))
851 init_incoming = incoming->f_sub_initial;
852 final_incoming = incoming->f_sub_final;
854 if (find_and_remove(&init_incoming,
855 &(stored->f_sub_initial), 1) && find_and_remove(&final_incoming,
856 &(stored->f_sub_final), 3))
858 if (stored->f_sub_any == NULL) {
862 remaining_incoming = merge_init_final(op, &init_incoming,
863 incoming->f_sub_any, &final_incoming);
864 rc = strings_containment(stored->f_sub_any, remaining_incoming);
865 ber_bvarray_free_x( remaining_incoming, op->o_tmpmemctx );
872 substr_containment_equality(Operation *op, Filter* stored, Filter* incoming)
874 struct berval incoming_val[2];
877 incoming_val[1] = incoming->f_av_value;
879 if (find_and_remove(incoming_val+1,
880 &(stored->f_sub_initial), 1) && find_and_remove(incoming_val+1,
881 &(stored->f_sub_final), 3)) {
882 if (stored->f_sub_any == NULL){
886 ber_dupbv_x( incoming_val, incoming_val+1, op->o_tmpmemctx );
887 BER_BVZERO( incoming_val+1 );
888 rc = strings_containment(stored->f_sub_any, incoming_val);
889 op->o_tmpfree( incoming_val[0].bv_val, op->o_tmpmemctx );
896 filter_first( Filter *f )
898 while ( f->f_choice == LDAP_FILTER_OR || f->f_choice == LDAP_FILTER_AND )
905 find_filter( Operation *op, Avlnode *root, Filter *inputf, Filter *first )
909 MatchingRule* mrule = NULL;
910 int res=0, eqpass= 0;
918 /* substring matches sort to the end, and we just have to
919 * walk the entire list.
921 if ( first->f_choice == LDAP_FILTER_SUBSTRINGS ) {
922 ptr = tavl_end( root, 1 );
925 ptr = tavl_find3( root, &cq, pcache_filter_cmp, &ret );
926 dir = (first->f_choice == LDAP_FILTER_GE) ? TAVL_DIR_LEFT :
935 /* an incoming substr query can only be satisfied by a cached
938 if ( first->f_choice == LDAP_FILTER_SUBSTRINGS &&
939 qc->first->f_choice != LDAP_FILTER_SUBSTRINGS )
942 /* an incoming eq query can be satisfied by a cached eq or substr
945 if ( first->f_choice == LDAP_FILTER_EQUALITY ) {
947 if ( qc->first->f_choice != LDAP_FILTER_EQUALITY ) {
948 nextpass: eqpass = 1;
949 ptr = tavl_end( root, 1 );
954 if ( qc->first->f_choice != LDAP_FILTER_SUBSTRINGS )
960 switch (fs->f_choice) {
961 case LDAP_FILTER_EQUALITY:
962 if (fi->f_choice == LDAP_FILTER_EQUALITY)
963 mrule = fs->f_ava->aa_desc->ad_type->sat_equality;
969 mrule = fs->f_ava->aa_desc->ad_type->sat_ordering;
976 rc = value_match(&ret, fs->f_ava->aa_desc, mrule,
977 SLAP_MR_VALUE_OF_ASSERTION_SYNTAX,
978 &(fi->f_ava->aa_value),
979 &(fs->f_ava->aa_value), &text);
980 if (rc != LDAP_SUCCESS) {
983 if ( fi==first && fi->f_choice==LDAP_FILTER_EQUALITY && ret )
986 switch (fs->f_choice) {
988 case LDAP_FILTER_AND:
993 case LDAP_FILTER_SUBSTRINGS:
994 /* check if the equality query can be
995 * answered with cached substring query */
996 if ((fi->f_choice == LDAP_FILTER_EQUALITY)
997 && substr_containment_equality( op,
1000 /* check if the substring query can be
1001 * answered with cached substring query */
1002 if ((fi->f_choice ==LDAP_FILTER_SUBSTRINGS
1003 ) && substr_containment_substr( op,
1009 case LDAP_FILTER_PRESENT:
1014 case LDAP_FILTER_EQUALITY:
1020 case LDAP_FILTER_GE:
1021 if (mrule && ret >= 0)
1026 case LDAP_FILTER_LE:
1027 if (mrule && ret <= 0)
1032 case LDAP_FILTER_NOT:
1038 } while((res) && (fi != NULL) && (fs != NULL));
1042 ptr = tavl_next( ptr, dir );
1047 /* check whether query is contained in any of
1048 * the cached queries in template
1050 static CachedQuery *
1051 query_containment(Operation *op, query_manager *qm,
1053 QueryTemplate *templa)
1056 int depth = 0, tscope;
1057 Qbase qbase, *qbptr = NULL;
1060 if (query->filter != NULL) {
1063 Debug( pcache_debug, "Lock QC index = %p\n",
1064 (void *) templa, 0, 0 );
1065 qbase.base = query->base;
1067 first = filter_first( query->filter );
1069 ldap_pvt_thread_rdwr_rlock(&templa->t_rwlock);
1072 qbptr = avl_find( templa->qbase, &qbase, pcache_dn_cmp );
1074 tscope = query->scope;
1075 /* Find a matching scope:
1076 * match at depth 0 OK
1079 * subord at depth > 0 OK
1080 * subtree at any depth OK
1082 * subtree or subord at any depth OK
1084 * subtree or subord at any depth OK
1086 * subord at depth > 0 OK
1087 * subtree at any depth OK
1089 for ( tscope = 0 ; tscope <= LDAP_SCOPE_CHILDREN; tscope++ ) {
1090 switch ( query->scope ) {
1091 case LDAP_SCOPE_BASE:
1092 if ( tscope == LDAP_SCOPE_BASE && depth ) continue;
1093 if ( tscope == LDAP_SCOPE_ONE && depth != 1) continue;
1094 if ( tscope == LDAP_SCOPE_CHILDREN && !depth ) continue;
1096 case LDAP_SCOPE_ONE:
1097 if ( tscope == LDAP_SCOPE_BASE )
1098 tscope = LDAP_SCOPE_ONE;
1099 if ( tscope == LDAP_SCOPE_ONE && depth ) continue;
1100 if ( !depth ) break;
1101 if ( tscope < LDAP_SCOPE_SUBTREE )
1102 tscope = LDAP_SCOPE_SUBTREE;
1104 case LDAP_SCOPE_SUBTREE:
1105 if ( tscope < LDAP_SCOPE_SUBTREE )
1106 tscope = LDAP_SCOPE_SUBTREE;
1107 if ( tscope == LDAP_SCOPE_CHILDREN && !depth ) continue;
1109 case LDAP_SCOPE_CHILDREN:
1110 if ( tscope < LDAP_SCOPE_SUBTREE )
1111 tscope = LDAP_SCOPE_SUBTREE;
1114 if ( !qbptr->scopes[tscope] ) continue;
1117 qc = find_filter( op, qbptr->scopes[tscope],
1118 query->filter, first );
1120 if ( qc->q_sizelimit ) {
1121 ldap_pvt_thread_rdwr_runlock(&templa->t_rwlock);
1124 ldap_pvt_thread_mutex_lock(&qm->lru_mutex);
1125 if (qm->lru_top != qc) {
1126 remove_query(qm, qc);
1127 add_query_on_top(qm, qc);
1129 ldap_pvt_thread_mutex_unlock(&qm->lru_mutex);
1134 if ( be_issuffix( op->o_bd, &qbase.base ))
1137 dnParent( &qbase.base, &pdn );
1142 Debug( pcache_debug,
1143 "Not answerable: Unlock QC index=%p\n",
1144 (void *) templa, 0, 0 );
1145 ldap_pvt_thread_rdwr_runlock(&templa->t_rwlock);
1151 free_query (CachedQuery* qc)
1153 free(qc->q_uuid.bv_val);
1154 filter_free(qc->filter);
1159 /* Add query to query cache, the returned Query is locked for writing */
1160 static CachedQuery *
1165 QueryTemplate *templ,
1166 pc_caching_reason_t why,
1169 CachedQuery* new_cached_query = (CachedQuery*) ch_malloc(sizeof(CachedQuery));
1175 new_cached_query->qtemp = templ;
1176 BER_BVZERO( &new_cached_query->q_uuid );
1177 new_cached_query->q_sizelimit = 0;
1185 ttl = templ->negttl;
1189 ttl = templ->limitttl;
1196 new_cached_query->expiry_time = slap_get_time() + ttl;
1197 new_cached_query->lru_up = NULL;
1198 new_cached_query->lru_down = NULL;
1199 Debug( pcache_debug, "Added query expires at %ld (%s)\n",
1200 (long) new_cached_query->expiry_time,
1201 pc_caching_reason_str[ why ], 0 );
1203 new_cached_query->scope = query->scope;
1204 new_cached_query->filter = query->filter;
1205 new_cached_query->first = first = filter_first( query->filter );
1207 ldap_pvt_thread_rdwr_init(&new_cached_query->rwlock);
1209 ldap_pvt_thread_rdwr_wlock(&new_cached_query->rwlock);
1211 qb.base = query->base;
1213 /* Adding a query */
1214 Debug( pcache_debug, "Lock AQ index = %p\n",
1215 (void *) templ, 0, 0 );
1216 ldap_pvt_thread_rdwr_wlock(&templ->t_rwlock);
1217 qbase = avl_find( templ->qbase, &qb, pcache_dn_cmp );
1219 qbase = ch_calloc( 1, sizeof(Qbase) + qb.base.bv_len + 1 );
1220 qbase->base.bv_len = qb.base.bv_len;
1221 qbase->base.bv_val = (char *)(qbase+1);
1222 memcpy( qbase->base.bv_val, qb.base.bv_val, qb.base.bv_len );
1223 qbase->base.bv_val[qbase->base.bv_len] = '\0';
1224 avl_insert( &templ->qbase, qbase, pcache_dn_cmp, avl_dup_error );
1226 new_cached_query->next = templ->query;
1227 new_cached_query->prev = NULL;
1228 new_cached_query->qbase = qbase;
1229 rc = tavl_insert( &qbase->scopes[query->scope], new_cached_query,
1230 pcache_filter_cmp, avl_dup_error );
1233 if (templ->query == NULL)
1234 templ->query_last = new_cached_query;
1236 templ->query->prev = new_cached_query;
1237 templ->query = new_cached_query;
1238 templ->no_of_queries++;
1240 ch_free( new_cached_query );
1241 new_cached_query = find_filter( op, qbase->scopes[query->scope],
1242 query->filter, first );
1243 filter_free( query->filter );
1245 Debug( pcache_debug, "TEMPLATE %p QUERIES++ %d\n",
1246 (void *) templ, templ->no_of_queries, 0 );
1248 Debug( pcache_debug, "Unlock AQ index = %p \n",
1249 (void *) templ, 0, 0 );
1250 ldap_pvt_thread_rdwr_wunlock(&templ->t_rwlock);
1252 /* Adding on top of LRU list */
1254 ldap_pvt_thread_mutex_lock(&qm->lru_mutex);
1255 add_query_on_top(qm, new_cached_query);
1256 ldap_pvt_thread_mutex_unlock(&qm->lru_mutex);
1258 return rc == 0 ? new_cached_query : NULL;
1262 remove_from_template (CachedQuery* qc, QueryTemplate* template)
1264 if (!qc->prev && !qc->next) {
1265 template->query_last = template->query = NULL;
1266 } else if (qc->prev == NULL) {
1267 qc->next->prev = NULL;
1268 template->query = qc->next;
1269 } else if (qc->next == NULL) {
1270 qc->prev->next = NULL;
1271 template->query_last = qc->prev;
1273 qc->next->prev = qc->prev;
1274 qc->prev->next = qc->next;
1276 tavl_delete( &qc->qbase->scopes[qc->scope], qc, pcache_filter_cmp );
1277 qc->qbase->queries--;
1278 if ( qc->qbase->queries == 0 ) {
1279 avl_delete( &template->qbase, qc->qbase, pcache_dn_cmp );
1280 ch_free( qc->qbase );
1284 template->no_of_queries--;
1287 /* remove bottom query of LRU list from the query cache */
1289 * NOTE: slight change in functionality.
1291 * - if result->bv_val is NULL, the query at the bottom of the LRU
1293 * - otherwise, the query whose UUID is *result is removed
1294 * - if not found, result->bv_val is zeroed
1297 cache_replacement(query_manager* qm, struct berval *result)
1299 CachedQuery* bottom;
1300 QueryTemplate *temp;
1302 ldap_pvt_thread_mutex_lock(&qm->lru_mutex);
1303 if ( BER_BVISNULL( result ) ) {
1304 bottom = qm->lru_bottom;
1307 Debug ( pcache_debug,
1308 "Cache replacement invoked without "
1309 "any query in LRU list\n", 0, 0, 0 );
1310 ldap_pvt_thread_mutex_unlock(&qm->lru_mutex);
1315 for ( bottom = qm->lru_bottom;
1317 bottom = bottom->lru_up )
1319 if ( bvmatch( result, &bottom->q_uuid ) ) {
1325 Debug ( pcache_debug,
1326 "Could not find query with uuid=\"%s\""
1327 "in LRU list\n", result->bv_val, 0, 0 );
1328 ldap_pvt_thread_mutex_unlock(&qm->lru_mutex);
1329 BER_BVZERO( result );
1334 temp = bottom->qtemp;
1335 remove_query(qm, bottom);
1336 ldap_pvt_thread_mutex_unlock(&qm->lru_mutex);
1338 *result = bottom->q_uuid;
1339 BER_BVZERO( &bottom->q_uuid );
1341 Debug( pcache_debug, "Lock CR index = %p\n", (void *) temp, 0, 0 );
1342 ldap_pvt_thread_rdwr_wlock(&temp->t_rwlock);
1343 remove_from_template(bottom, temp);
1344 Debug( pcache_debug, "TEMPLATE %p QUERIES-- %d\n",
1345 (void *) temp, temp->no_of_queries, 0 );
1346 Debug( pcache_debug, "Unlock CR index = %p\n", (void *) temp, 0, 0 );
1347 ldap_pvt_thread_rdwr_wunlock(&temp->t_rwlock);
1352 struct query_info *next;
1364 struct query_info *qi;
1367 if ( rs->sr_type != REP_SEARCH ) return 0;
1369 attr = attr_find( rs->sr_entry->e_attrs, ad_queryId );
1370 if ( attr == NULL ) return 0;
1372 count = attr->a_numvals;
1373 assert( count > 0 );
1374 qi = op->o_tmpalloc( sizeof( struct query_info ), op->o_tmpmemctx );
1375 qi->next = op->o_callback->sc_private;
1376 op->o_callback->sc_private = qi;
1377 ber_dupbv_x( &qi->xdn, &rs->sr_entry->e_nname, op->o_tmpmemctx );
1378 qi->del = ( count == 1 );
1387 struct berval *query_uuid )
1389 struct query_info *qi, *qnext;
1390 char filter_str[ LDAP_LUTIL_UUIDSTR_BUFSIZE + STRLENOF( "(queryId=)" ) ];
1391 AttributeAssertion ava = ATTRIBUTEASSERTION_INIT;
1392 Filter filter = {LDAP_FILTER_EQUALITY};
1393 SlapReply sreply = {REP_RESULT};
1394 slap_callback cb = { NULL, remove_func, NULL, NULL };
1397 sreply.sr_entry = NULL;
1398 sreply.sr_nentries = 0;
1399 op->ors_filterstr.bv_len = snprintf(filter_str, sizeof(filter_str),
1400 "(%s=%s)", ad_queryId->ad_cname.bv_val, query_uuid->bv_val);
1401 filter.f_ava = &ava;
1402 filter.f_av_desc = ad_queryId;
1403 filter.f_av_value = *query_uuid;
1405 op->o_tag = LDAP_REQ_SEARCH;
1406 op->o_protocol = LDAP_VERSION3;
1407 op->o_callback = &cb;
1408 op->o_time = slap_get_time();
1409 op->o_do_not_cache = 1;
1411 op->o_req_dn = op->o_bd->be_suffix[0];
1412 op->o_req_ndn = op->o_bd->be_nsuffix[0];
1413 op->ors_scope = LDAP_SCOPE_SUBTREE;
1414 op->ors_deref = LDAP_DEREF_NEVER;
1415 op->ors_slimit = SLAP_NO_LIMIT;
1416 op->ors_tlimit = SLAP_NO_LIMIT;
1417 op->ors_filter = &filter;
1418 op->ors_filterstr.bv_val = filter_str;
1419 op->ors_filterstr.bv_len = strlen(filter_str);
1420 op->ors_attrs = NULL;
1421 op->ors_attrsonly = 0;
1423 op->o_bd->be_search( op, &sreply );
1425 for ( qi=cb.sc_private; qi; qi=qnext ) {
1428 op->o_req_dn = qi->xdn;
1429 op->o_req_ndn = qi->xdn;
1432 Debug( pcache_debug, "DELETING ENTRY TEMPLATE=%s\n",
1433 query_uuid->bv_val, 0, 0 );
1435 op->o_tag = LDAP_REQ_DELETE;
1437 if (op->o_bd->be_delete(op, &sreply) == LDAP_SUCCESS) {
1443 struct berval vals[2];
1445 vals[0] = *query_uuid;
1446 vals[1].bv_val = NULL;
1448 mod.sml_op = LDAP_MOD_DELETE;
1450 mod.sml_desc = ad_queryId;
1451 mod.sml_type = ad_queryId->ad_cname;
1452 mod.sml_values = vals;
1453 mod.sml_nvalues = NULL;
1454 mod.sml_numvals = 1;
1455 mod.sml_next = NULL;
1456 Debug( pcache_debug,
1457 "REMOVING TEMP ATTR : TEMPLATE=%s\n",
1458 query_uuid->bv_val, 0, 0 );
1460 op->orm_modlist = &mod;
1462 op->o_bd->be_modify( op, &sreply );
1464 op->o_tmpfree( qi->xdn.bv_val, op->o_tmpmemctx );
1465 op->o_tmpfree( qi, op->o_tmpmemctx );
1472 AttributeName* attrs,
1481 struct berval *fstr,
1482 AttributeName** filter_attrs,
1484 int* filter_got_oc )
1486 AttributeDescription *ad;
1489 switch ( f->f_choice ) {
1490 case LDAP_FILTER_EQUALITY:
1492 len = STRLENOF( "(=)" ) + ad->ad_cname.bv_len;
1493 ret = snprintf( fstr->bv_val+fstr->bv_len, len + 1, "(%s=)", ad->ad_cname.bv_val );
1494 assert( ret == len );
1495 fstr->bv_len += len;
1498 case LDAP_FILTER_GE:
1500 len = STRLENOF( "(>=)" ) + ad->ad_cname.bv_len;
1501 ret = snprintf( fstr->bv_val+fstr->bv_len, len + 1, "(%s>=)", ad->ad_cname.bv_val);
1502 assert( ret == len );
1503 fstr->bv_len += len;
1506 case LDAP_FILTER_LE:
1508 len = STRLENOF( "(<=)" ) + ad->ad_cname.bv_len;
1509 ret = snprintf( fstr->bv_val+fstr->bv_len, len + 1, "(%s<=)", ad->ad_cname.bv_val);
1510 assert( ret == len );
1511 fstr->bv_len += len;
1514 case LDAP_FILTER_APPROX:
1516 len = STRLENOF( "(~=)" ) + ad->ad_cname.bv_len;
1517 ret = snprintf( fstr->bv_val+fstr->bv_len, len + 1, "(%s~=)", ad->ad_cname.bv_val);
1518 assert( ret == len );
1519 fstr->bv_len += len;
1522 case LDAP_FILTER_SUBSTRINGS:
1524 len = STRLENOF( "(=)" ) + ad->ad_cname.bv_len;
1525 ret = snprintf( fstr->bv_val+fstr->bv_len, len + 1, "(%s=)", ad->ad_cname.bv_val );
1526 assert( ret == len );
1527 fstr->bv_len += len;
1530 case LDAP_FILTER_PRESENT:
1532 len = STRLENOF( "(=*)" ) + ad->ad_cname.bv_len;
1533 ret = snprintf( fstr->bv_val+fstr->bv_len, len + 1, "(%s=*)", ad->ad_cname.bv_val );
1534 assert( ret == len );
1535 fstr->bv_len += len;
1538 case LDAP_FILTER_AND:
1539 case LDAP_FILTER_OR:
1540 case LDAP_FILTER_NOT: {
1542 fstr->bv_val[fstr->bv_len++] = '(';
1543 switch ( f->f_choice ) {
1544 case LDAP_FILTER_AND:
1545 fstr->bv_val[fstr->bv_len] = '&';
1547 case LDAP_FILTER_OR:
1548 fstr->bv_val[fstr->bv_len] = '|';
1550 case LDAP_FILTER_NOT:
1551 fstr->bv_val[fstr->bv_len] = '!';
1556 for ( f = f->f_list; f != NULL; f = f->f_next ) {
1557 rc = filter2template( op, f, fstr, filter_attrs, filter_cnt,
1561 fstr->bv_val[fstr->bv_len++] = ')';
1562 fstr->bv_val[fstr->bv_len] = '\0';
1568 /* a filter should at least have room for "()",
1569 * an "=" and for a 1-char attr */
1570 strcpy( fstr->bv_val, "(?=)" );
1571 fstr->bv_len += STRLENOF("(?=)");
1575 if ( filter_attrs != NULL ) {
1576 *filter_attrs = (AttributeName *)op->o_tmprealloc(*filter_attrs,
1577 (*filter_cnt + 2)*sizeof(AttributeName), op->o_tmpmemctx);
1579 (*filter_attrs)[*filter_cnt].an_desc = ad;
1580 (*filter_attrs)[*filter_cnt].an_name = ad->ad_cname;
1581 (*filter_attrs)[*filter_cnt].an_oc = NULL;
1582 (*filter_attrs)[*filter_cnt].an_oc_exclude = 0;
1583 BER_BVZERO( &(*filter_attrs)[*filter_cnt+1].an_name );
1585 if ( ad == slap_schema.si_ad_objectClass )
1592 struct search_info {
1595 QueryTemplate *qtemp;
1596 AttributeName* save_attrs; /* original attributes, saved for response */
1597 int swap_saved_attrs;
1602 int slimit_exceeded;
1603 pc_caching_reason_t caching_reason;
1608 remove_query_and_data(
1612 struct berval *uuid )
1614 query_manager* qm = cm->qm;
1616 qm->crfunc( qm, uuid );
1617 if ( !BER_BVISNULL( uuid ) ) {
1620 Debug( pcache_debug,
1621 "Removing query UUID %s\n",
1622 uuid->bv_val, 0, 0 );
1623 return_val = remove_query_data( op, rs, uuid );
1624 Debug( pcache_debug,
1625 "QUERY REMOVED, SIZE=%d\n",
1627 ldap_pvt_thread_mutex_lock( &cm->cache_mutex );
1628 cm->cur_entries -= return_val;
1629 cm->num_cached_queries--;
1630 Debug( pcache_debug,
1631 "STORED QUERIES = %lu\n",
1632 cm->num_cached_queries, 0, 0 );
1633 ldap_pvt_thread_mutex_unlock( &cm->cache_mutex );
1634 Debug( pcache_debug,
1635 "QUERY REMOVED, CACHE ="
1637 cm->cur_entries, 0, 0 );
1642 * Callback used to fetch queryId values based on entryUUID;
1643 * used by pcache_remove_entries_from_cache()
1646 fetch_queryId_cb( Operation *op, SlapReply *rs )
1650 /* only care about searchEntry responses */
1651 if ( rs->sr_type != REP_SEARCH ) {
1655 /* allow only one response per entryUUID */
1656 if ( op->o_callback->sc_private != NULL ) {
1662 /* copy all queryId values into callback's private data */
1663 a = attr_find( rs->sr_entry->e_attrs, ad_queryId );
1665 BerVarray vals = NULL;
1667 ber_bvarray_dup_x( &vals, a->a_nvals, op->o_tmpmemctx );
1668 op->o_callback->sc_private = (void *)vals;
1672 /* clear entry if required */
1673 if ( rs->sr_flags & REP_ENTRY_MUSTBEFREED ) {
1674 entry_free( rs->sr_entry );
1675 rs->sr_entry = NULL;
1676 rs->sr_flags ^= REP_ENTRY_MUSTBEFREED;
1683 * Call that allows to remove a set of entries from the cache,
1684 * by forcing the removal of all the related queries.
1687 pcache_remove_entries_from_cache(
1690 BerVarray entryUUIDs )
1692 Connection conn = { 0 };
1693 OperationBuffer opbuf;
1695 slap_callback sc = { 0 };
1696 SlapReply rs = { REP_RESULT };
1698 char filtbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE + STRLENOF( "(entryUUID=)" ) ];
1699 AttributeAssertion ava = ATTRIBUTEASSERTION_INIT;
1700 AttributeName attrs[ 2 ] = {{{ 0 }}};
1704 void *thrctx = ldap_pvt_thread_pool_context();
1706 connection_fake_init( &conn, &opbuf, thrctx );
1714 memset( &op->oq_search, 0, sizeof( op->oq_search ) );
1715 op->ors_scope = LDAP_SCOPE_SUBTREE;
1716 op->ors_deref = LDAP_DEREF_NEVER;
1717 f.f_choice = LDAP_FILTER_EQUALITY;
1719 ava.aa_desc = slap_schema.si_ad_entryUUID;
1720 op->ors_filter = &f;
1722 op->ors_tlimit = SLAP_NO_LIMIT;
1723 attrs[ 0 ].an_desc = ad_queryId;
1724 attrs[ 0 ].an_name = ad_queryId->ad_cname;
1725 op->ors_attrs = attrs;
1726 op->ors_attrsonly = 0;
1728 op->o_req_dn = cm->db.be_suffix[ 0 ];
1729 op->o_req_ndn = cm->db.be_nsuffix[ 0 ];
1731 op->o_tag = LDAP_REQ_SEARCH;
1732 op->o_protocol = LDAP_VERSION3;
1733 op->o_managedsait = SLAP_CONTROL_CRITICAL;
1735 op->o_dn = op->o_bd->be_rootdn;
1736 op->o_ndn = op->o_bd->be_rootndn;
1737 sc.sc_response = fetch_queryId_cb;
1738 op->o_callback = ≻
1740 for ( s = 0; !BER_BVISNULL( &entryUUIDs[ s ] ); s++ ) {
1741 BerVarray vals = NULL;
1743 op->ors_filterstr.bv_len = snprintf( filtbuf, sizeof( filtbuf ),
1744 "(entryUUID=%s)", entryUUIDs[ s ].bv_val );
1745 op->ors_filterstr.bv_val = filtbuf;
1746 ava.aa_value = entryUUIDs[ s ];
1748 rc = op->o_bd->be_search( op, &rs );
1749 if ( rc != LDAP_SUCCESS ) {
1753 vals = (BerVarray)op->o_callback->sc_private;
1754 if ( vals != NULL ) {
1757 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1758 struct berval val = vals[ i ];
1760 remove_query_and_data( op, &rs, cm, &val );
1762 if ( !BER_BVISNULL( &val ) && val.bv_val != vals[ i ].bv_val ) {
1763 ch_free( val.bv_val );
1767 ber_bvarray_free_x( vals, op->o_tmpmemctx );
1768 op->o_callback->sc_private = NULL;
1776 * Call that allows to remove a query from the cache.
1779 pcache_remove_query_from_cache(
1782 struct berval *queryid )
1784 Operation op2 = *op;
1785 SlapReply rs2 = { 0 };
1789 /* remove the selected query */
1790 remove_query_and_data( &op2, &rs2, cm, queryid );
1792 return LDAP_SUCCESS;
1796 * Call that allows to remove a set of queries related to an entry
1797 * from the cache; if queryid is not null, the entry must belong to
1798 * the query indicated by queryid.
1801 pcache_remove_entry_queries_from_cache(
1805 struct berval *queryid )
1807 Connection conn = { 0 };
1808 OperationBuffer opbuf;
1810 slap_callback sc = { 0 };
1811 SlapReply rs = { REP_RESULT };
1813 char filter_str[ LDAP_LUTIL_UUIDSTR_BUFSIZE + STRLENOF( "(queryId=)" ) ];
1814 AttributeAssertion ava = ATTRIBUTEASSERTION_INIT;
1815 AttributeName attrs[ 2 ] = {{{ 0 }}};
1818 BerVarray vals = NULL;
1821 void *thrctx = ldap_pvt_thread_pool_context();
1823 connection_fake_init( &conn, &opbuf, thrctx );
1831 memset( &op->oq_search, 0, sizeof( op->oq_search ) );
1832 op->ors_scope = LDAP_SCOPE_BASE;
1833 op->ors_deref = LDAP_DEREF_NEVER;
1834 if ( queryid == NULL || BER_BVISNULL( queryid ) ) {
1835 BER_BVSTR( &op->ors_filterstr, "(objectClass=*)" );
1836 f.f_choice = LDAP_FILTER_PRESENT;
1837 f.f_desc = slap_schema.si_ad_objectClass;
1840 op->ors_filterstr.bv_len = snprintf( filter_str,
1841 sizeof( filter_str ), "(%s=%s)",
1842 ad_queryId->ad_cname.bv_val, queryid->bv_val );
1843 f.f_choice = LDAP_FILTER_EQUALITY;
1845 f.f_av_desc = ad_queryId;
1846 f.f_av_value = *queryid;
1848 op->ors_filter = &f;
1850 op->ors_tlimit = SLAP_NO_LIMIT;
1851 attrs[ 0 ].an_desc = ad_queryId;
1852 attrs[ 0 ].an_name = ad_queryId->ad_cname;
1853 op->ors_attrs = attrs;
1854 op->ors_attrsonly = 0;
1856 op->o_req_dn = *ndn;
1857 op->o_req_ndn = *ndn;
1859 op->o_tag = LDAP_REQ_SEARCH;
1860 op->o_protocol = LDAP_VERSION3;
1861 op->o_managedsait = SLAP_CONTROL_CRITICAL;
1863 op->o_dn = op->o_bd->be_rootdn;
1864 op->o_ndn = op->o_bd->be_rootndn;
1865 sc.sc_response = fetch_queryId_cb;
1866 op->o_callback = ≻
1868 rc = op->o_bd->be_search( op, &rs );
1869 if ( rc != LDAP_SUCCESS ) {
1873 vals = (BerVarray)op->o_callback->sc_private;
1874 if ( vals != NULL ) {
1877 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1878 struct berval val = vals[ i ];
1880 remove_query_and_data( op, &rs, cm, &val );
1882 if ( !BER_BVISNULL( &val ) && val.bv_val != vals[ i ].bv_val ) {
1883 ch_free( val.bv_val );
1887 ber_bvarray_free_x( vals, op->o_tmpmemctx );
1890 return LDAP_SUCCESS;
1897 struct berval *query_uuid )
1899 struct search_info *si = op->o_callback->sc_private;
1900 slap_overinst *on = si->on;
1901 cache_manager *cm = on->on_bi.bi_private;
1904 struct berval crp_uuid;
1905 char uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ];
1907 Connection conn = {0};
1908 OperationBuffer opbuf;
1909 void *thrctx = ldap_pvt_thread_pool_context();
1911 query_uuid->bv_len = lutil_uuidstr(uuidbuf, sizeof(uuidbuf));
1912 ber_str2bv(uuidbuf, query_uuid->bv_len, 1, query_uuid);
1914 connection_fake_init2( &conn, &opbuf, thrctx, 0 );
1915 op_tmp = &opbuf.ob_op;
1916 op_tmp->o_bd = &cm->db;
1917 op_tmp->o_dn = cm->db.be_rootdn;
1918 op_tmp->o_ndn = cm->db.be_rootndn;
1920 Debug( pcache_debug, "UUID for query being added = %s\n",
1923 for ( e=si->head; e; e=si->head ) {
1924 si->head = e->e_private;
1925 e->e_private = NULL;
1926 while ( cm->cur_entries > (cm->max_entries) ) {
1927 BER_BVZERO( &crp_uuid );
1928 remove_query_and_data( op_tmp, rs, cm, &crp_uuid );
1931 return_val = merge_entry(op_tmp, e, query_uuid);
1932 ldap_pvt_thread_mutex_lock(&cm->cache_mutex);
1933 cm->cur_entries += return_val;
1934 Debug( pcache_debug,
1935 "ENTRY ADDED/MERGED, CACHED ENTRIES=%d\n",
1936 cm->cur_entries, 0, 0 );
1938 ldap_pvt_thread_mutex_unlock(&cm->cache_mutex);
1945 pcache_op_cleanup( Operation *op, SlapReply *rs ) {
1946 slap_callback *cb = op->o_callback;
1947 struct search_info *si = cb->sc_private;
1948 slap_overinst *on = si->on;
1949 cache_manager *cm = on->on_bi.bi_private;
1950 query_manager* qm = cm->qm;
1952 if ( rs->sr_type == REP_SEARCH ) {
1955 /* don't return more entries than requested by the client */
1956 if ( si->slimit && rs->sr_nentries >= si->slimit ) {
1957 si->slimit_exceeded = 1;
1960 /* If we haven't exceeded the limit for this query,
1961 * build a chain of answers to store. If we hit the
1962 * limit, empty the chain and ignore the rest.
1965 /* check if the entry contains undefined
1966 * attributes/objectClasses (ITS#5680) */
1967 if ( cm->check_cacheability && test_filter( op, rs->sr_entry, si->query.filter ) != LDAP_COMPARE_TRUE ) {
1968 Debug( pcache_debug, "%s: query not cacheable because of schema issues in DN \"%s\"\n",
1969 op->o_log_prefix, rs->sr_entry->e_name.bv_val, 0 );
1973 if ( si->count < si->max ) {
1975 e = entry_dup( rs->sr_entry );
1976 if ( !si->head ) si->head = e;
1977 if ( si->tail ) si->tail->e_private = e;
1984 for (;si->head; si->head=e) {
1985 e = si->head->e_private;
1986 si->head->e_private = NULL;
1987 entry_free(si->head);
1995 if ( rs->sr_type == REP_RESULT ||
1996 op->o_abandon || rs->sr_err == SLAPD_ABANDON )
1998 if ( si->swap_saved_attrs ) {
1999 rs->sr_attrs = si->save_attrs;
2000 op->ors_attrs = si->save_attrs;
2002 if ( (op->o_abandon || rs->sr_err == SLAPD_ABANDON) &&
2003 si->caching_reason == PC_IGNORE ) {
2004 filter_free( si->query.filter );
2006 /* duplicate query, free it */
2008 for (;si->head; si->head=e) {
2009 e = si->head->e_private;
2010 si->head->e_private = NULL;
2011 entry_free(si->head);
2014 op->o_callback = op->o_callback->sc_next;
2015 op->o_tmpfree( cb, op->o_tmpmemctx );
2016 } else if ( si->caching_reason != PC_IGNORE ) {
2017 CachedQuery *qc = qm->addfunc(op, qm, &si->query,
2018 si->qtemp, si->caching_reason, 1 );
2021 switch ( si->caching_reason ) {
2023 cache_entries( op, rs, &qc->q_uuid );
2027 qc->q_sizelimit = rs->sr_nentries;
2037 ldap_pvt_thread_rdwr_wunlock(&qc->rwlock);
2038 ldap_pvt_thread_mutex_lock(&cm->cache_mutex);
2039 cm->num_cached_queries++;
2040 Debug( pcache_debug, "STORED QUERIES = %lu\n",
2041 cm->num_cached_queries, 0, 0 );
2042 ldap_pvt_thread_mutex_unlock(&cm->cache_mutex);
2044 /* If the consistency checker suspended itself,
2047 if ( cm->cc_paused ) {
2048 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
2049 if ( cm->cc_paused ) {
2051 ldap_pvt_runqueue_resched( &slapd_rq, cm->cc_arg, 0 );
2053 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
2056 } else if ( si->count ) {
2057 /* duplicate query, free it */
2059 for (;si->head; si->head=e) {
2060 e = si->head->e_private;
2061 si->head->e_private = NULL;
2062 entry_free(si->head);
2067 filter_free( si->query.filter );
2071 return SLAP_CB_CONTINUE;
2079 struct search_info *si = op->o_callback->sc_private;
2081 if ( si->swap_saved_attrs ) {
2082 rs->sr_attrs = si->save_attrs;
2083 op->ors_attrs = si->save_attrs;
2086 if ( rs->sr_type == REP_SEARCH ) {
2087 /* don't return more entries than requested by the client */
2088 if ( si->slimit_exceeded ) {
2092 } else if ( rs->sr_type == REP_RESULT ) {
2095 if ( rs->sr_err == LDAP_SUCCESS ) {
2096 si->caching_reason = PC_POSITIVE;
2098 } else if ( rs->sr_err == LDAP_SIZELIMIT_EXCEEDED
2099 && si->qtemp->limitttl )
2101 si->caching_reason = PC_SIZELIMIT;
2104 } else if ( si->qtemp->negttl && !si->count && !si->over &&
2105 rs->sr_err == LDAP_SUCCESS )
2107 si->caching_reason = PC_NEGATIVE;
2111 if ( si->slimit_exceeded ) {
2112 rs->sr_err = LDAP_SIZELIMIT_EXCEEDED;
2116 return SLAP_CB_CONTINUE;
2122 AttributeName** new_attrs,
2123 struct attr_set *attrs,
2124 AttributeName* filter_attrs,
2134 /* duplicate attrs */
2135 count = attrs->count + fattr_cnt;
2136 if ( !fattr_got_oc && !(attrs->flags & PC_GOT_OC)) {
2141 *new_attrs = (AttributeName*)ch_calloc( count + 1,
2142 sizeof(AttributeName) );
2143 for (i=0; i<attrs->count; i++) {
2144 (*new_attrs)[i].an_name = attrs->attrs[i].an_name;
2145 (*new_attrs)[i].an_desc = attrs->attrs[i].an_desc;
2147 BER_BVZERO( &(*new_attrs)[i].an_name );
2148 alluser = an_find(*new_attrs, &AllUser);
2149 allop = an_find(*new_attrs, &AllOper);
2152 for ( i=0; i<fattr_cnt; i++ ) {
2153 if ( an_find(*new_attrs, &filter_attrs[i].an_name ) ) {
2156 if ( is_at_operational(filter_attrs[i].an_desc->ad_type) ) {
2160 } else if ( alluser ) {
2163 (*new_attrs)[j].an_name = filter_attrs[i].an_name;
2164 (*new_attrs)[j].an_desc = filter_attrs[i].an_desc;
2165 (*new_attrs)[j].an_oc = NULL;
2166 (*new_attrs)[j].an_oc_exclude = 0;
2170 (*new_attrs)[j].an_name = slap_schema.si_ad_objectClass->ad_cname;
2171 (*new_attrs)[j].an_desc = slap_schema.si_ad_objectClass;
2172 (*new_attrs)[j].an_oc = NULL;
2173 (*new_attrs)[j].an_oc_exclude = 0;
2176 BER_BVZERO( &(*new_attrs)[j].an_name );
2181 /* NOTE: this is a quick workaround to let pcache minimally interact
2182 * with pagedResults. A more articulated solutions would be to
2183 * perform the remote query without control and cache all results,
2184 * performing the pagedResults search only within the client
2185 * and the proxy. This requires pcache to understand pagedResults. */
2187 pcache_chk_controls(
2191 const char *non = "";
2192 const char *stripped = "";
2194 switch( op->o_pagedresults ) {
2195 case SLAP_CONTROL_NONCRITICAL:
2197 stripped = "; stripped";
2200 case SLAP_CONTROL_CRITICAL:
2201 Debug( pcache_debug, "%s: "
2202 "%scritical pagedResults control "
2203 "disabled with proxy cache%s.\n",
2204 op->o_log_prefix, non, stripped );
2206 slap_remove_control( op, rs, slap_cids.sc_pagedResults, NULL );
2210 rs->sr_err = SLAP_CB_CONTINUE;
2217 #ifdef PCACHE_CONTROL_PRIVDB
2223 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
2224 cache_manager *cm = on->on_bi.bi_private;
2225 slap_callback *save_cb;
2228 /* skip if control is unset */
2229 if ( op->o_ctrlflag[ privDB_cid ] != SLAP_CONTROL_CRITICAL ) {
2230 return SLAP_CB_CONTINUE;
2233 /* The cache DB isn't open yet */
2234 if ( cm->defer_db_open ) {
2235 send_ldap_error( op, rs, LDAP_UNAVAILABLE,
2236 "pcachePrivDB: cacheDB not available" );
2240 /* FIXME: might be a little bit exaggerated... */
2241 if ( !be_isroot( op ) ) {
2242 save_cb = op->o_callback;
2243 op->o_callback = NULL;
2244 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
2245 "pcachePrivDB: operation not allowed" );
2246 op->o_callback = save_cb;
2251 /* map tag to operation */
2252 type = slap_req2op( op->o_tag );
2253 if ( type != SLAP_OP_LAST ) {
2257 /* execute, if possible */
2258 func = &cm->db.be_bind;
2259 if ( func[ type ] != NULL ) {
2260 Operation op2 = *op;
2264 rc = func[ type ]( &op2, rs );
2265 if ( type == SLAP_OP_BIND && rc == LDAP_SUCCESS ) {
2266 op->o_conn->c_authz_cookie = cm->db.be_private;
2271 /* otherwise fall back to error */
2272 save_cb = op->o_callback;
2273 op->o_callback = NULL;
2274 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
2275 "operation not supported with pcachePrivDB control" );
2276 op->o_callback = save_cb;
2280 #endif /* PCACHE_CONTROL_PRIVDB */
2287 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
2288 cache_manager *cm = on->on_bi.bi_private;
2289 query_manager* qm = cm->qm;
2293 AttributeName *filter_attrs = NULL;
2296 QueryTemplate *qtemp = NULL;
2299 CachedQuery *answerable = NULL;
2302 int fattr_got_oc = 0;
2304 struct berval tempstr;
2306 #ifdef PCACHE_CONTROL_PRIVDB
2307 if ( op->o_ctrlflag[ privDB_cid ] == SLAP_CONTROL_CRITICAL ) {
2308 return pcache_op_privdb( op, rs );
2310 #endif /* PCACHE_CONTROL_PRIVDB */
2312 /* The cache DB isn't open yet */
2313 if ( cm->defer_db_open ) {
2314 send_ldap_error( op, rs, LDAP_UNAVAILABLE,
2315 "pcachePrivDB: cacheDB not available" );
2319 tempstr.bv_val = op->o_tmpalloc( op->ors_filterstr.bv_len+1, op->o_tmpmemctx );
2321 if ( filter2template( op, op->ors_filter, &tempstr, &filter_attrs,
2322 &fattr_cnt, &fattr_got_oc )) {
2323 op->o_tmpfree( tempstr.bv_val, op->o_tmpmemctx );
2324 return SLAP_CB_CONTINUE;
2327 Debug( pcache_debug, "query template of incoming query = %s\n",
2328 tempstr.bv_val, 0, 0 );
2330 /* FIXME: cannot cache/answer requests with pagedResults control */
2333 attr_set = get_attr_set(op->ors_attrs, qm, cm->numattrsets);
2335 query.filter = op->ors_filter;
2336 query.base = op->o_req_ndn;
2337 query.scope = op->ors_scope;
2339 /* check for query containment */
2340 if (attr_set > -1) {
2341 QueryTemplate *qt = qm->attr_sets[attr_set].templates;
2342 for (; qt; qt = qt->qtnext ) {
2343 /* find if template i can potentially answer tempstr */
2344 if (qt->querystr.bv_len != tempstr.bv_len ||
2345 strcasecmp( qt->querystr.bv_val, tempstr.bv_val ))
2349 Debug( pcache_debug, "Entering QC, querystr = %s\n",
2350 op->ors_filterstr.bv_val, 0, 0 );
2351 answerable = (*(qm->qcfunc))(op, qm, &query, qt);
2357 op->o_tmpfree( tempstr.bv_val, op->o_tmpmemctx );
2360 /* Need to clear the callbacks of the original operation,
2361 * in case there are other overlays */
2362 BackendDB *save_bd = op->o_bd;
2363 slap_callback *save_cb = op->o_callback;
2365 Debug( pcache_debug, "QUERY ANSWERABLE\n", 0, 0, 0 );
2366 op->o_tmpfree( filter_attrs, op->o_tmpmemctx );
2367 ldap_pvt_thread_rdwr_rlock(&answerable->rwlock);
2368 if ( BER_BVISNULL( &answerable->q_uuid )) {
2369 /* No entries cached, just an empty result set */
2371 send_ldap_result( op, rs );
2374 op->o_callback = NULL;
2375 i = cm->db.bd_info->bi_op_search( op, rs );
2377 ldap_pvt_thread_rdwr_runlock(&answerable->rwlock);
2378 ldap_pvt_thread_rdwr_runlock(&qtemp->t_rwlock);
2380 op->o_callback = save_cb;
2384 Debug( pcache_debug, "QUERY NOT ANSWERABLE\n", 0, 0, 0 );
2386 ldap_pvt_thread_mutex_lock(&cm->cache_mutex);
2387 if (cm->num_cached_queries >= cm->max_queries) {
2390 ldap_pvt_thread_mutex_unlock(&cm->cache_mutex);
2392 if (op->ors_attrsonly)
2397 struct search_info *si;
2399 Debug( pcache_debug, "QUERY CACHEABLE\n", 0, 0, 0 );
2400 query.filter = filter_dup(op->ors_filter, NULL);
2401 ldap_pvt_thread_rdwr_wlock(&qtemp->t_rwlock);
2402 if ( !qtemp->t_attrs.count ) {
2403 qtemp->t_attrs.count = add_filter_attrs(op,
2404 &qtemp->t_attrs.attrs,
2405 &qm->attr_sets[attr_set],
2406 filter_attrs, fattr_cnt, fattr_got_oc);
2408 ldap_pvt_thread_rdwr_wunlock(&qtemp->t_rwlock);
2410 cb = op->o_tmpalloc( sizeof(*cb) + sizeof(*si), op->o_tmpmemctx );
2411 cb->sc_response = pcache_response;
2412 cb->sc_cleanup = pcache_op_cleanup;
2413 cb->sc_private = (cb+1);
2414 si = cb->sc_private;
2418 si->max = cm->num_entries_limit ;
2422 si->slimit_exceeded = 0;
2423 si->caching_reason = PC_IGNORE;
2424 if ( op->ors_slimit && op->ors_slimit < cm->num_entries_limit ) {
2425 si->slimit = op->ors_slimit;
2426 op->ors_slimit = cm->num_entries_limit;
2430 si->swap_saved_attrs = 1;
2431 si->save_attrs = op->ors_attrs;
2433 op->ors_attrs = qtemp->t_attrs.attrs;
2435 if ( cm->response_cb == PCACHE_RESPONSE_CB_HEAD ) {
2436 cb->sc_next = op->o_callback;
2437 op->o_callback = cb;
2440 slap_callback **pcb;
2442 /* need to move the callback at the end, in case other
2443 * overlays are present, so that the final entry is
2444 * actually cached */
2446 for ( pcb = &op->o_callback; *pcb; pcb = &(*pcb)->sc_next );
2451 Debug( pcache_debug, "QUERY NOT CACHEABLE\n",
2455 op->o_tmpfree( filter_attrs, op->o_tmpmemctx );
2457 return SLAP_CB_CONTINUE;
2462 AttributeName* attrs,
2470 for ( ; attrs[count].an_name.bv_val; count++ );
2473 /* recognize a single "*" or a "1.1" */
2476 attrs = slap_anlist_all_user_attributes;
2478 } else if ( count == 1 && strcmp( attrs[0].an_name.bv_val, LDAP_NO_ATTRS ) == 0 ) {
2483 for ( i = 0; i < num; i++ ) {
2487 if ( count > qm->attr_sets[i].count ) {
2492 if ( !qm->attr_sets[i].count ) {
2498 for ( a2 = attrs; a2->an_name.bv_val; a2++ ) {
2499 if ( !an_find( qm->attr_sets[i].attrs, &a2->an_name ) ) {
2522 struct re_s *rtask = arg;
2523 slap_overinst *on = rtask->arg;
2524 cache_manager *cm = on->on_bi.bi_private;
2525 query_manager *qm = cm->qm;
2526 Connection conn = {0};
2527 OperationBuffer opbuf;
2530 SlapReply rs = {REP_RESULT};
2532 int return_val, pause = 1;
2533 QueryTemplate* templ;
2535 connection_fake_init( &conn, &opbuf, ctx );
2539 op->o_dn = cm->db.be_rootdn;
2540 op->o_ndn = cm->db.be_rootndn;
2544 for (templ = qm->templates; templ; templ=templ->qmnext) {
2545 query = templ->query_last;
2546 if ( query ) pause = 0;
2547 op->o_time = slap_get_time();
2548 while (query && (query->expiry_time < op->o_time)) {
2550 Debug( pcache_debug, "Lock CR index = %p\n",
2551 (void *) templ, 0, 0 );
2552 ldap_pvt_thread_rdwr_wlock(&templ->t_rwlock);
2553 if ( query == templ->query_last ) {
2555 remove_from_template(query, templ);
2556 Debug( pcache_debug, "TEMPLATE %p QUERIES-- %d\n",
2557 (void *) templ, templ->no_of_queries, 0 );
2558 Debug( pcache_debug, "Unlock CR index = %p\n",
2559 (void *) templ, 0, 0 );
2561 ldap_pvt_thread_rdwr_wunlock(&templ->t_rwlock);
2563 query = templ->query_last;
2566 ldap_pvt_thread_mutex_lock(&qm->lru_mutex);
2567 remove_query(qm, query);
2568 ldap_pvt_thread_mutex_unlock(&qm->lru_mutex);
2569 if ( BER_BVISNULL( &query->q_uuid ))
2572 return_val = remove_query_data(op, &rs, &query->q_uuid);
2573 Debug( pcache_debug, "STALE QUERY REMOVED, SIZE=%d\n",
2575 ldap_pvt_thread_mutex_lock(&cm->cache_mutex);
2576 cm->cur_entries -= return_val;
2577 cm->num_cached_queries--;
2578 Debug( pcache_debug, "STORED QUERIES = %lu\n",
2579 cm->num_cached_queries, 0, 0 );
2580 ldap_pvt_thread_mutex_unlock(&cm->cache_mutex);
2581 Debug( pcache_debug,
2582 "STALE QUERY REMOVED, CACHE ="
2584 cm->cur_entries, 0, 0 );
2586 query = templ->query_last;
2589 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
2590 if ( ldap_pvt_runqueue_isrunning( &slapd_rq, rtask )) {
2591 ldap_pvt_runqueue_stoptask( &slapd_rq, rtask );
2593 /* If there were no queries, defer processing for a while */
2594 cm->cc_paused = pause;
2595 ldap_pvt_runqueue_resched( &slapd_rq, rtask, pause );
2597 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
2602 #define MAX_ATTR_SETS 500
2612 static ConfigDriver pc_cf_gen;
2613 static ConfigLDAPadd pc_ldadd;
2614 static ConfigCfAdd pc_cfadd;
2616 static ConfigTable pccfg[] = {
2617 { "proxycache", "backend> <max_entries> <numattrsets> <entry limit> "
2619 6, 6, 0, ARG_MAGIC|ARG_NO_DELETE|PC_MAIN, pc_cf_gen,
2620 "( OLcfgOvAt:2.1 NAME 'olcProxyCache' "
2621 "DESC 'ProxyCache basic parameters' "
2622 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
2623 { "proxyattrset", "index> <attributes...",
2624 2, 0, 0, ARG_MAGIC|PC_ATTR, pc_cf_gen,
2625 "( OLcfgOvAt:2.2 NAME 'olcProxyAttrset' "
2626 "DESC 'A set of attributes to cache' "
2627 "SYNTAX OMsDirectoryString )", NULL, NULL },
2628 { "proxytemplate", "filter> <attrset-index> <TTL> <negTTL",
2629 4, 6, 0, ARG_MAGIC|PC_TEMP, pc_cf_gen,
2630 "( OLcfgOvAt:2.3 NAME 'olcProxyTemplate' "
2631 "DESC 'Filter template, attrset, cache TTL, "
2632 "optional negative TTL, optional sizelimit TTL' "
2633 "SYNTAX OMsDirectoryString )", NULL, NULL },
2634 { "response-callback", "head|tail(default)",
2635 2, 2, 0, ARG_MAGIC|PC_RESP, pc_cf_gen,
2636 "( OLcfgOvAt:2.4 NAME 'olcProxyResponseCB' "
2637 "DESC 'Response callback position in overlay stack' "
2638 "SYNTAX OMsDirectoryString )", NULL, NULL },
2639 { "proxyCacheQueries", "queries",
2640 2, 2, 0, ARG_INT|ARG_MAGIC|PC_QUERIES, pc_cf_gen,
2641 "( OLcfgOvAt:2.5 NAME 'olcProxyCacheQueries' "
2642 "DESC 'Maximum number of queries to cache' "
2643 "SYNTAX OMsInteger )", NULL, NULL },
2644 { "proxySaveQueries", "TRUE|FALSE",
2645 2, 2, 0, ARG_ON_OFF|ARG_OFFSET, (void *)offsetof(cache_manager, save_queries),
2646 "( OLcfgOvAt:2.6 NAME 'olcProxySaveQueries' "
2647 "DESC 'Save cached queries for hot restart' "
2648 "SYNTAX OMsBoolean )", NULL, NULL },
2649 { "proxyCheckCacheability", "TRUE|FALSE",
2650 2, 2, 0, ARG_ON_OFF|ARG_OFFSET, (void *)offsetof(cache_manager, check_cacheability),
2651 "( OLcfgOvAt:2.7 NAME 'olcProxyCheckCacheability' "
2652 "DESC 'Check whether the results of a query are cacheable, e.g. for schema issues' "
2653 "SYNTAX OMsBoolean )", NULL, NULL },
2655 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
2658 static ConfigOCs pcocs[] = {
2659 { "( OLcfgOvOc:2.1 "
2660 "NAME 'olcPcacheConfig' "
2661 "DESC 'ProxyCache configuration' "
2662 "SUP olcOverlayConfig "
2663 "MUST ( olcProxyCache $ olcProxyAttrset $ olcProxyTemplate ) "
2664 "MAY ( olcProxyResponseCB $ olcProxyCacheQueries $ olcProxySaveQueries $ olcProxyCheckCacheability ) )",
2665 Cft_Overlay, pccfg, NULL, pc_cfadd },
2666 { "( OLcfgOvOc:2.2 "
2667 "NAME 'olcPcacheDatabase' "
2668 "DESC 'Cache database configuration' "
2669 "AUXILIARY )", Cft_Misc, olcDatabaseDummy, pc_ldadd },
2673 static int pcache_db_open2( slap_overinst *on, ConfigReply *cr );
2676 pc_ldadd_cleanup( ConfigArgs *c )
2678 slap_overinst *on = c->ca_private;
2679 return pcache_db_open2( on, &c->reply );
2683 pc_ldadd( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
2688 if ( p->ce_type != Cft_Overlay || !p->ce_bi ||
2689 p->ce_bi->bi_cf_ocs != pcocs )
2690 return LDAP_CONSTRAINT_VIOLATION;
2692 on = (slap_overinst *)p->ce_bi;
2693 cm = on->on_bi.bi_private;
2695 /* Defer open if this is an LDAPadd */
2696 if ( CONFIG_ONLINE_ADD( ca ))
2697 ca->cleanup = pc_ldadd_cleanup;
2699 cm->defer_db_open = 0;
2700 ca->ca_private = on;
2701 return LDAP_SUCCESS;
2705 pc_cfadd( Operation *op, SlapReply *rs, Entry *p, ConfigArgs *ca )
2707 CfEntryInfo *pe = p->e_private;
2708 slap_overinst *on = (slap_overinst *)pe->ce_bi;
2709 cache_manager *cm = on->on_bi.bi_private;
2712 /* FIXME: should not hardcode "olcDatabase" here */
2713 bv.bv_len = snprintf( ca->cr_msg, sizeof( ca->cr_msg ),
2714 "olcDatabase=%s", cm->db.bd_info->bi_type );
2715 if ( bv.bv_len >= sizeof( ca->cr_msg ) ) {
2718 bv.bv_val = ca->cr_msg;
2720 cm->defer_db_open = 0;
2722 /* We can only create this entry if the database is table-driven
2724 if ( cm->db.bd_info->bi_cf_ocs )
2725 config_build_entry( op, rs, pe, ca, &bv, cm->db.bd_info->bi_cf_ocs,
2732 pc_cf_gen( ConfigArgs *c )
2734 slap_overinst *on = (slap_overinst *)c->bi;
2735 cache_manager* cm = on->on_bi.bi_private;
2736 query_manager* qm = cm->qm;
2737 QueryTemplate* temp;
2738 AttributeName* attr_name;
2739 AttributeName* attrarray;
2740 const char* text=NULL;
2745 if ( c->op == SLAP_CONFIG_EMIT ) {
2749 bv.bv_len = snprintf( c->cr_msg, sizeof( c->cr_msg ), "%s %d %d %d %ld",
2750 cm->db.bd_info->bi_type, cm->max_entries, cm->numattrsets,
2751 cm->num_entries_limit, cm->cc_period );
2752 bv.bv_val = c->cr_msg;
2753 value_add_one( &c->rvalue_vals, &bv );
2756 for (i=0; i<cm->numattrsets; i++) {
2757 if ( !qm->attr_sets[i].count ) continue;
2759 bv.bv_len = snprintf( c->cr_msg, sizeof( c->cr_msg ), "%d", i );
2761 /* count the attr length */
2762 for ( attr_name = qm->attr_sets[i].attrs;
2763 attr_name->an_name.bv_val; attr_name++ )
2764 bv.bv_len += attr_name->an_name.bv_len + 1;
2766 bv.bv_val = ch_malloc( bv.bv_len+1 );
2767 ptr = lutil_strcopy( bv.bv_val, c->cr_msg );
2768 for ( attr_name = qm->attr_sets[i].attrs;
2769 attr_name->an_name.bv_val; attr_name++ ) {
2771 ptr = lutil_strcopy( ptr, attr_name->an_name.bv_val );
2773 ber_bvarray_add( &c->rvalue_vals, &bv );
2775 if ( !c->rvalue_vals )
2779 for (temp=qm->templates; temp; temp=temp->qmnext) {
2780 /* HEADS-UP: always print all;
2781 * if optional == 0, ignore */
2782 bv.bv_len = snprintf( c->cr_msg, sizeof( c->cr_msg ),
2784 temp->attr_set_index,
2788 bv.bv_len += temp->querystr.bv_len + 2;
2789 bv.bv_val = ch_malloc( bv.bv_len+1 );
2792 ptr = lutil_strcopy( ptr, temp->querystr.bv_val );
2794 strcpy( ptr, c->cr_msg );
2795 ber_bvarray_add( &c->rvalue_vals, &bv );
2797 if ( !c->rvalue_vals )
2801 if ( cm->response_cb == PCACHE_RESPONSE_CB_HEAD ) {
2802 BER_BVSTR( &bv, "head" );
2804 BER_BVSTR( &bv, "tail" );
2806 value_add_one( &c->rvalue_vals, &bv );
2809 c->value_int = cm->max_queries;
2813 } else if ( c->op == LDAP_MOD_DELETE ) {
2814 return 1; /* FIXME */
2826 if ( cm->numattrsets > 0 ) {
2827 snprintf( c->cr_msg, sizeof( c->cr_msg ), "\"proxycache\" directive already provided" );
2828 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
2832 if ( lutil_atoi( &cm->numattrsets, c->argv[3] ) != 0 ) {
2833 snprintf( c->cr_msg, sizeof( c->cr_msg ), "unable to parse num attrsets=\"%s\" (arg #3)",
2835 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
2838 if ( cm->numattrsets <= 0 ) {
2839 snprintf( c->cr_msg, sizeof( c->cr_msg ), "numattrsets (arg #3) must be positive" );
2840 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
2843 if ( cm->numattrsets > MAX_ATTR_SETS ) {
2844 snprintf( c->cr_msg, sizeof( c->cr_msg ), "numattrsets (arg #3) must be <= %d", MAX_ATTR_SETS );
2845 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
2849 if ( !backend_db_init( c->argv[1], &cm->db, -1, NULL )) {
2850 snprintf( c->cr_msg, sizeof( c->cr_msg ), "unknown backend type (arg #1)" );
2851 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
2855 if ( lutil_atoi( &cm->max_entries, c->argv[2] ) != 0 ) {
2856 snprintf( c->cr_msg, sizeof( c->cr_msg ), "unable to parse max entries=\"%s\" (arg #2)",
2858 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
2861 if ( cm->max_entries <= 0 ) {
2862 snprintf( c->cr_msg, sizeof( c->cr_msg ), "max entries (arg #2) must be positive.\n" );
2863 Debug( LDAP_DEBUG_CONFIG, "%s: %s\n", c->log, c->cr_msg, 0 );
2867 if ( lutil_atoi( &cm->num_entries_limit, c->argv[4] ) != 0 ) {
2868 snprintf( c->cr_msg, sizeof( c->cr_msg ), "unable to parse entry limit=\"%s\" (arg #4)",
2870 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
2873 if ( cm->num_entries_limit <= 0 ) {
2874 snprintf( c->cr_msg, sizeof( c->cr_msg ), "entry limit (arg #4) must be positive" );
2875 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
2878 if ( cm->num_entries_limit > cm->max_entries ) {
2879 snprintf( c->cr_msg, sizeof( c->cr_msg ), "entry limit (arg #4) must be less than max entries %d (arg #2)", cm->max_entries );
2880 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
2884 if ( lutil_parse_time( c->argv[5], &t ) != 0 ) {
2885 snprintf( c->cr_msg, sizeof( c->cr_msg ), "unable to parse period=\"%s\" (arg #5)",
2887 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
2891 cm->cc_period = (time_t)t;
2892 Debug( pcache_debug,
2893 "Total # of attribute sets to be cached = %d.\n",
2894 cm->numattrsets, 0, 0 );
2895 qm->attr_sets = ( struct attr_set * )ch_calloc( cm->numattrsets,
2896 sizeof( struct attr_set ) );
2899 if ( cm->numattrsets == 0 ) {
2900 snprintf( c->cr_msg, sizeof( c->cr_msg ), "\"proxycache\" directive not provided yet" );
2901 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
2904 if ( lutil_atoi( &num, c->argv[1] ) != 0 ) {
2905 snprintf( c->cr_msg, sizeof( c->cr_msg ), "unable to parse attrset #=\"%s\"",
2907 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
2911 if ( num < 0 || num >= cm->numattrsets ) {
2912 snprintf( c->cr_msg, sizeof( c->cr_msg ), "attrset index %d out of bounds (must be %s%d)",
2913 num, cm->numattrsets > 1 ? "0->" : "", cm->numattrsets - 1 );
2914 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
2917 qm->attr_sets[num].flags |= PC_CONFIGURED;
2918 if ( c->argc == 2 ) {
2920 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2921 "need an explicit attr in attrlist; use \"*\" to indicate all attrs" );
2922 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
2925 } else if ( c->argc == 3 ) {
2926 if ( strcmp( c->argv[2], LDAP_ALL_USER_ATTRIBUTES ) == 0 ) {
2927 qm->attr_sets[num].count = 1;
2928 qm->attr_sets[num].attrs = (AttributeName*)ch_calloc( 2,
2929 sizeof( AttributeName ) );
2930 BER_BVSTR( &qm->attr_sets[num].attrs[0].an_name, LDAP_ALL_USER_ATTRIBUTES );
2933 } else if ( strcmp( c->argv[2], LDAP_ALL_OPERATIONAL_ATTRIBUTES ) == 0 ) {
2934 qm->attr_sets[num].count = 1;
2935 qm->attr_sets[num].attrs = (AttributeName*)ch_calloc( 2,
2936 sizeof( AttributeName ) );
2937 BER_BVSTR( &qm->attr_sets[num].attrs[0].an_name, LDAP_ALL_OPERATIONAL_ATTRIBUTES );
2940 } else if ( strcmp( c->argv[2], LDAP_NO_ATTRS ) == 0 ) {
2943 /* else: fallthru */
2945 } else if ( c->argc == 4 ) {
2946 if ( ( strcmp( c->argv[2], LDAP_ALL_USER_ATTRIBUTES ) == 0 && strcmp( c->argv[3], LDAP_ALL_OPERATIONAL_ATTRIBUTES ) == 0 )
2947 || ( strcmp( c->argv[2], LDAP_ALL_OPERATIONAL_ATTRIBUTES ) == 0 && strcmp( c->argv[3], LDAP_ALL_USER_ATTRIBUTES ) == 0 ) )
2949 qm->attr_sets[num].count = 2;
2950 qm->attr_sets[num].attrs = (AttributeName*)ch_calloc( 3,
2951 sizeof( AttributeName ) );
2952 BER_BVSTR( &qm->attr_sets[num].attrs[0].an_name, LDAP_ALL_USER_ATTRIBUTES );
2953 BER_BVSTR( &qm->attr_sets[num].attrs[1].an_name, LDAP_ALL_OPERATIONAL_ATTRIBUTES );
2956 /* else: fallthru */
2959 if ( c->argc > 2 ) {
2960 int all_user = 0, all_op = 0;
2962 qm->attr_sets[num].count = c->argc - 2;
2963 qm->attr_sets[num].attrs = (AttributeName*)ch_calloc( c->argc - 1,
2964 sizeof( AttributeName ) );
2965 attr_name = qm->attr_sets[num].attrs;
2966 for ( i = 2; i < c->argc; i++ ) {
2967 attr_name->an_desc = NULL;
2968 if ( strcmp( c->argv[i], LDAP_NO_ATTRS ) == 0 ) {
2969 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2970 "invalid attr #%d \"%s\" in attrlist",
2971 i - 2, c->argv[i] );
2972 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
2973 ch_free( qm->attr_sets[num].attrs );
2974 qm->attr_sets[num].attrs = NULL;
2975 qm->attr_sets[num].count = 0;
2978 if ( strcmp( c->argv[i], LDAP_ALL_USER_ATTRIBUTES ) == 0 ) {
2980 BER_BVSTR( &attr_name->an_name, LDAP_ALL_USER_ATTRIBUTES );
2981 } else if ( strcmp( c->argv[i], LDAP_ALL_OPERATIONAL_ATTRIBUTES ) == 0 ) {
2983 BER_BVSTR( &attr_name->an_name, LDAP_ALL_OPERATIONAL_ATTRIBUTES );
2985 if ( slap_str2ad( c->argv[i], &attr_name->an_desc, &text ) ) {
2986 strcpy( c->cr_msg, text );
2987 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
2988 ch_free( qm->attr_sets[num].attrs );
2989 qm->attr_sets[num].attrs = NULL;
2990 qm->attr_sets[num].count = 0;
2993 attr_name->an_name = attr_name->an_desc->ad_cname;
2995 attr_name->an_oc = NULL;
2996 attr_name->an_oc_exclude = 0;
2997 if ( attr_name->an_desc == slap_schema.si_ad_objectClass )
2998 qm->attr_sets[num].flags |= PC_GOT_OC;
3000 BER_BVZERO( &attr_name->an_name );
3003 /* warn if list contains both "*" and "+" */
3004 if ( i > 4 && all_user && all_op ) {
3005 snprintf( c->cr_msg, sizeof( c->cr_msg ),
3006 "warning: attribute list contains \"*\" and \"+\"" );
3007 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
3012 if ( cm->numattrsets == 0 ) {
3013 snprintf( c->cr_msg, sizeof( c->cr_msg ), "\"proxycache\" directive not provided yet" );
3014 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
3017 if ( lutil_atoi( &i, c->argv[2] ) != 0 ) {
3018 snprintf( c->cr_msg, sizeof( c->cr_msg ), "unable to parse template #=\"%s\"",
3020 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
3024 if ( i < 0 || i >= cm->numattrsets ||
3025 !(qm->attr_sets[i].flags & PC_CONFIGURED )) {
3026 snprintf( c->cr_msg, sizeof( c->cr_msg ), "template index %d invalid (%s%d)",
3027 i, cm->numattrsets > 1 ? "0->" : "", cm->numattrsets - 1 );
3028 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
3031 temp = ch_calloc( 1, sizeof( QueryTemplate ));
3032 temp->qmnext = qm->templates;
3033 qm->templates = temp;
3034 ldap_pvt_thread_rdwr_init( &temp->t_rwlock );
3035 temp->query = temp->query_last = NULL;
3036 if ( lutil_parse_time( c->argv[3], &t ) != 0 ) {
3037 snprintf( c->cr_msg, sizeof( c->cr_msg ),
3038 "unable to parse template ttl=\"%s\"",
3040 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
3043 temp->ttl = (time_t)t;
3044 temp->negttl = (time_t)0;
3045 temp->limitttl = (time_t)0;
3046 switch ( c->argc ) {
3048 if ( lutil_parse_time( c->argv[5], &t ) != 0 ) {
3049 snprintf( c->cr_msg, sizeof( c->cr_msg ),
3050 "unable to parse template sizelimit ttl=\"%s\"",
3052 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
3055 temp->limitttl = (time_t)t;
3059 if ( lutil_parse_time( c->argv[4], &t ) != 0 ) {
3060 snprintf( c->cr_msg, sizeof( c->cr_msg ),
3061 "unable to parse template negative ttl=\"%s\"",
3063 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
3066 temp->negttl = (time_t)t;
3070 temp->no_of_queries = 0;
3072 ber_str2bv( c->argv[1], 0, 1, &temp->querystr );
3073 Debug( pcache_debug, "Template:\n", 0, 0, 0 );
3074 Debug( pcache_debug, " query template: %s\n",
3075 temp->querystr.bv_val, 0, 0 );
3076 temp->attr_set_index = i;
3077 qm->attr_sets[i].flags |= PC_REFERENCED;
3078 temp->qtnext = qm->attr_sets[i].templates;
3079 qm->attr_sets[i].templates = temp;
3080 Debug( pcache_debug, " attributes: \n", 0, 0, 0 );
3081 if ( ( attrarray = qm->attr_sets[i].attrs ) != NULL ) {
3082 for ( i=0; attrarray[i].an_name.bv_val; i++ )
3083 Debug( pcache_debug, "\t%s\n",
3084 attrarray[i].an_name.bv_val, 0, 0 );
3088 if ( strcasecmp( c->argv[1], "head" ) == 0 ) {
3089 cm->response_cb = PCACHE_RESPONSE_CB_HEAD;
3091 } else if ( strcasecmp( c->argv[1], "tail" ) == 0 ) {
3092 cm->response_cb = PCACHE_RESPONSE_CB_TAIL;
3095 snprintf( c->cr_msg, sizeof( c->cr_msg ), "unknown specifier" );
3096 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
3101 if ( c->value_int <= 0 ) {
3102 snprintf( c->cr_msg, sizeof( c->cr_msg ), "max queries must be positive" );
3103 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
3106 cm->max_queries = c->value_int;
3121 slap_overinst *on = (slap_overinst *)be->bd_info;
3122 cache_manager* cm = on->on_bi.bi_private;
3124 /* Something for the cache database? */
3125 if ( cm->db.bd_info && cm->db.bd_info->bi_db_config )
3126 return cm->db.bd_info->bi_db_config( &cm->db, fname, lineno,
3128 return SLAP_CONF_UNKNOWN;
3136 slap_overinst *on = (slap_overinst *)be->bd_info;
3140 cm = (cache_manager *)ch_malloc(sizeof(cache_manager));
3141 on->on_bi.bi_private = cm;
3143 qm = (query_manager*)ch_malloc(sizeof(query_manager));
3146 SLAP_DBFLAGS(&cm->db) |= SLAP_DBFLAG_NO_SCHEMA_CHECK;
3147 cm->db.be_private = NULL;
3148 cm->db.be_pcl_mutexp = &cm->db.be_pcl_mutex;
3150 cm->numattrsets = 0;
3151 cm->num_entries_limit = 5;
3152 cm->num_cached_queries = 0;
3153 cm->max_entries = 0;
3154 cm->cur_entries = 0;
3155 cm->max_queries = 10000;
3156 cm->save_queries = 0;
3157 cm->check_cacheability = 0;
3158 cm->response_cb = PCACHE_RESPONSE_CB_TAIL;
3159 cm->defer_db_open = 1;
3160 cm->cc_period = 1000;
3164 qm->attr_sets = NULL;
3165 qm->templates = NULL;
3167 qm->lru_bottom = NULL;
3169 qm->qcfunc = query_containment;
3170 qm->crfunc = cache_replacement;
3171 qm->addfunc = add_query;
3172 ldap_pvt_thread_mutex_init(&qm->lru_mutex);
3174 ldap_pvt_thread_mutex_init(&cm->cache_mutex);
3179 pcache_cachedquery_open_cb( Operation *op, SlapReply *rs )
3181 assert( op->o_tag == LDAP_REQ_SEARCH );
3183 if ( rs->sr_type == REP_SEARCH ) {
3186 a = attr_find( rs->sr_entry->e_attrs, ad_cachedQueryURL );
3190 assert( a->a_nvals != NULL );
3192 valsp = op->o_callback->sc_private;
3193 assert( *valsp == NULL );
3195 ber_bvarray_dup_x( valsp, a->a_nvals, op->o_tmpmemctx );
3203 pcache_cachedquery_count_cb( Operation *op, SlapReply *rs )
3205 assert( op->o_tag == LDAP_REQ_SEARCH );
3207 if ( rs->sr_type == REP_SEARCH ) {
3208 int *countp = (int *)op->o_callback->sc_private;
3221 cache_manager *cm = on->on_bi.bi_private;
3222 query_manager* qm = cm->qm;
3225 rc = backend_startup_one( &cm->db, cr );
3227 cm->defer_db_open = 0;
3230 /* There is no runqueue in TOOL mode */
3231 if (( slapMode & SLAP_SERVER_MODE ) && rc == 0 ) {
3232 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
3233 ldap_pvt_runqueue_insert( &slapd_rq, cm->cc_period,
3234 consistency_check, on,
3235 "pcache_consistency", cm->db.be_suffix[0].bv_val );
3236 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
3238 /* Cached database must have the rootdn */
3239 if ( BER_BVISNULL( &cm->db.be_rootndn )
3240 || BER_BVISEMPTY( &cm->db.be_rootndn ) )
3242 Debug( LDAP_DEBUG_ANY, "pcache_db_open(): "
3243 "underlying database of type \"%s\"\n"
3244 " serving naming context \"%s\"\n"
3245 " has no \"rootdn\", required by \"proxycache\".\n",
3246 on->on_info->oi_orig->bi_type,
3247 cm->db.be_suffix[0].bv_val, 0 );
3251 if ( cm->save_queries ) {
3252 void *thrctx = ldap_pvt_thread_pool_context();
3253 Connection conn = { 0 };
3254 OperationBuffer opbuf;
3256 slap_callback cb = { 0 };
3257 SlapReply rs = { 0 };
3258 BerVarray vals = NULL;
3259 Filter f = { 0 }, f2 = { 0 };
3260 AttributeAssertion ava = ATTRIBUTEASSERTION_INIT;
3261 AttributeName attrs[ 2 ] = {{{ 0 }}};
3263 connection_fake_init( &conn, &opbuf, thrctx );
3268 op->o_tag = LDAP_REQ_SEARCH;
3269 op->o_protocol = LDAP_VERSION3;
3270 cb.sc_response = pcache_cachedquery_open_cb;
3271 cb.sc_private = &vals;
3272 op->o_callback = &cb;
3273 op->o_time = slap_get_time();
3274 op->o_do_not_cache = 1;
3275 op->o_managedsait = SLAP_CONTROL_CRITICAL;
3277 op->o_dn = cm->db.be_rootdn;
3278 op->o_ndn = cm->db.be_rootndn;
3279 op->o_req_dn = cm->db.be_suffix[ 0 ];
3280 op->o_req_ndn = cm->db.be_nsuffix[ 0 ];
3282 op->ors_scope = LDAP_SCOPE_BASE;
3283 op->ors_deref = LDAP_DEREF_NEVER;
3285 op->ors_tlimit = SLAP_NO_LIMIT;
3286 ber_str2bv( "(cachedQueryURL=*)", 0, 0, &op->ors_filterstr );
3287 f.f_choice = LDAP_FILTER_PRESENT;
3288 f.f_desc = ad_cachedQueryURL;
3289 op->ors_filter = &f;
3290 attrs[ 0 ].an_desc = ad_cachedQueryURL;
3291 attrs[ 0 ].an_name = ad_cachedQueryURL->ad_cname;
3292 op->ors_attrs = attrs;
3293 op->ors_attrsonly = 0;
3295 rc = op->o_bd->be_search( op, &rs );
3296 if ( rc == LDAP_SUCCESS && vals != NULL ) {
3299 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
3300 if ( url2query( vals[ i ].bv_val, op, qm ) == 0 ) {
3301 cm->num_cached_queries++;
3305 ber_bvarray_free_x( vals, op->o_tmpmemctx );
3308 /* count cached entries */
3309 f.f_choice = LDAP_FILTER_NOT;
3311 f2.f_choice = LDAP_FILTER_EQUALITY;
3313 f2.f_av_desc = slap_schema.si_ad_objectClass;
3314 BER_BVSTR( &f2.f_av_value, "glue" );
3315 ber_str2bv( "(!(objectClass=glue))", 0, 0, &op->ors_filterstr );
3317 op->ors_slimit = SLAP_NO_LIMIT;
3318 op->ors_scope = LDAP_SCOPE_SUBTREE;
3319 op->ors_attrs = slap_anlist_no_attrs;
3321 op->o_callback->sc_response = pcache_cachedquery_count_cb;
3323 op->o_callback->sc_private = &rs.sr_nentries;
3325 rc = op->o_bd->be_search( op, &rs );
3327 cm->cur_entries = rs.sr_nentries;
3341 slap_overinst *on = (slap_overinst *)be->bd_info;
3342 cache_manager *cm = on->on_bi.bi_private;
3343 query_manager* qm = cm->qm;
3344 int i, ncf = 0, rf = 0, nrf = 0, rc = 0;
3346 /* check attr sets */
3347 for ( i = 0; i < cm->numattrsets; i++) {
3348 if ( !( qm->attr_sets[i].flags & PC_CONFIGURED ) ) {
3349 if ( qm->attr_sets[i].flags & PC_REFERENCED ) {
3350 Debug( LDAP_DEBUG_CONFIG, "pcache: attr set #%d not configured but referenced.\n", i, 0, 0 );
3354 Debug( LDAP_DEBUG_CONFIG, "pcache: warning, attr set #%d not configured.\n", i, 0, 0 );
3358 } else if ( !( qm->attr_sets[i].flags & PC_REFERENCED ) ) {
3359 Debug( LDAP_DEBUG_CONFIG, "pcache: attr set #%d configured but not referenced.\n", i, 0, 0 );
3364 if ( ncf || rf || nrf ) {
3365 Debug( LDAP_DEBUG_CONFIG, "pcache: warning, %d attr sets configured but not referenced.\n", nrf, 0, 0 );
3366 Debug( LDAP_DEBUG_CONFIG, "pcache: warning, %d attr sets not configured.\n", ncf, 0, 0 );
3367 Debug( LDAP_DEBUG_CONFIG, "pcache: %d attr sets not configured but referenced.\n", rf, 0, 0 );
3374 /* need to inherit something from the original database... */
3375 cm->db.be_def_limit = be->be_def_limit;
3376 cm->db.be_limits = be->be_limits;
3377 cm->db.be_acl = be->be_acl;
3378 cm->db.be_dfltaccess = be->be_dfltaccess;
3380 if ( SLAP_DBMONITORING( be ) ) {
3381 SLAP_DBFLAGS( &cm->db ) |= SLAP_DBFLAG_MONITORING;
3384 SLAP_DBFLAGS( &cm->db ) &= ~SLAP_DBFLAG_MONITORING;
3387 if ( !cm->defer_db_open )
3388 rc = pcache_db_open2( on, cr );
3394 pcache_free_qbase( void *v )
3400 tavl_free( qb->scopes[i], NULL );
3410 slap_overinst *on = (slap_overinst *)be->bd_info;
3411 cache_manager *cm = on->on_bi.bi_private;
3412 query_manager *qm = cm->qm;
3416 if ( cm->save_queries ) {
3418 BerVarray vals = NULL;
3421 Connection conn = { 0 };
3422 OperationBuffer opbuf;
3424 slap_callback cb = { 0 };
3426 SlapReply rs = { REP_RESULT };
3427 Modifications mod = {{ 0 }};
3429 thrctx = ldap_pvt_thread_pool_context();
3431 connection_fake_init( &conn, &opbuf, thrctx );
3434 if ( qm->templates != NULL ) {
3435 for ( tm = qm->templates; tm != NULL; tm = tm->qmnext ) {
3436 for ( qc = tm->query; qc; qc = qc->next ) {
3439 if ( query2url( op, qc, &bv ) == 0 ) {
3440 ber_bvarray_add_x( &vals, &bv, op->o_tmpmemctx );
3447 op->o_dn = cm->db.be_rootdn;
3448 op->o_ndn = cm->db.be_rootndn;
3450 op->o_tag = LDAP_REQ_MODIFY;
3451 op->o_protocol = LDAP_VERSION3;
3452 cb.sc_response = slap_null_cb;
3453 op->o_callback = &cb;
3454 op->o_time = slap_get_time();
3455 op->o_do_not_cache = 1;
3456 op->o_managedsait = SLAP_CONTROL_CRITICAL;
3458 op->o_req_dn = op->o_bd->be_suffix[0];
3459 op->o_req_ndn = op->o_bd->be_nsuffix[0];
3461 mod.sml_op = LDAP_MOD_REPLACE;
3463 mod.sml_desc = ad_cachedQueryURL;
3464 mod.sml_type = ad_cachedQueryURL->ad_cname;
3465 mod.sml_values = vals;
3466 mod.sml_nvalues = NULL;
3467 mod.sml_numvals = 1;
3468 mod.sml_next = NULL;
3469 Debug( pcache_debug,
3470 "%sSETTING CACHED QUERY URLS\n",
3471 vals == NULL ? "RE" : "", 0, 0 );
3473 op->orm_modlist = &mod;
3475 op->o_bd->be_modify( op, &rs );
3477 ber_bvarray_free_x( vals, op->o_tmpmemctx );
3480 /* cleanup stuff inherited from the original database... */
3481 cm->db.be_limits = NULL;
3482 cm->db.be_acl = NULL;
3484 /* stop the thread ... */
3486 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
3487 if ( ldap_pvt_runqueue_isrunning( &slapd_rq, cm->cc_arg ) ) {
3488 ldap_pvt_runqueue_stoptask( &slapd_rq, cm->cc_arg );
3490 ldap_pvt_runqueue_remove( &slapd_rq, cm->cc_arg );
3491 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
3494 if ( cm->db.bd_info->bi_db_close ) {
3495 rc = cm->db.bd_info->bi_db_close( &cm->db, NULL );
3497 while ( (tm = qm->templates) != NULL ) {
3498 CachedQuery *qc, *qn;
3499 qm->templates = tm->qmnext;
3500 for ( qc = tm->query; qc; qc = qn ) {
3504 avl_free( tm->qbase, pcache_free_qbase );
3505 free( tm->querystr.bv_val );
3506 ldap_pvt_thread_rdwr_destroy( &tm->t_rwlock );
3507 free( tm->t_attrs.attrs );
3511 for ( i=0; i<cm->numattrsets; i++ ) {
3512 free( qm->attr_sets[i].attrs );
3514 free( qm->attr_sets );
3515 qm->attr_sets = NULL;
3526 slap_overinst *on = (slap_overinst *)be->bd_info;
3527 cache_manager *cm = on->on_bi.bi_private;
3528 query_manager *qm = cm->qm;
3530 if ( cm->db.be_private != NULL ) {
3531 backend_stopdown_one( &cm->db );
3534 ldap_pvt_thread_mutex_destroy( &qm->lru_mutex );
3535 ldap_pvt_thread_mutex_destroy( &cm->cache_mutex );
3542 #ifdef PCACHE_CONTROL_PRIVDB
3544 Control ::= SEQUENCE {
3545 controlType LDAPOID,
3546 criticality BOOLEAN DEFAULT FALSE,
3547 controlValue OCTET STRING OPTIONAL }
3549 controlType ::= 1.3.6.1.4.1.4203.666.11.9.5.1
3551 * criticality must be TRUE; controlValue must be absent.
3559 if ( op->o_ctrlflag[ privDB_cid ] != SLAP_CONTROL_NONE ) {
3560 rs->sr_text = "privateDB control specified multiple times";
3561 return LDAP_PROTOCOL_ERROR;
3564 if ( !BER_BVISNULL( &ctrl->ldctl_value ) ) {
3565 rs->sr_text = "privateDB control value not absent";
3566 return LDAP_PROTOCOL_ERROR;
3569 if ( !ctrl->ldctl_iscritical ) {
3570 rs->sr_text = "privateDB control criticality required";
3571 return LDAP_PROTOCOL_ERROR;
3574 op->o_ctrlflag[ privDB_cid ] = SLAP_CONTROL_CRITICAL;
3576 return LDAP_SUCCESS;
3579 static char *extops[] = {
3580 LDAP_EXOP_MODIFY_PASSWD,
3583 #endif /* PCACHE_CONTROL_PRIVDB */
3585 #ifdef PCACHE_EXOP_QUERY_DELETE
3586 static struct berval pcache_exop_QUERY_DELETE = BER_BVC( PCACHE_EXOP_QUERY_DELETE );
3588 #define LDAP_TAG_EXOP_QUERY_DELETE_BASE ((LBER_CLASS_CONTEXT|LBER_CONSTRUCTED) + 0)
3589 #define LDAP_TAG_EXOP_QUERY_DELETE_DN ((LBER_CLASS_CONTEXT|LBER_CONSTRUCTED) + 1)
3590 #define LDAP_TAG_EXOP_QUERY_DELETE_UUID ((LBER_CLASS_CONTEXT|LBER_CONSTRUCTED) + 2)
3593 ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
3594 requestName [0] LDAPOID,
3595 requestValue [1] OCTET STRING OPTIONAL }
3597 requestName ::= 1.3.6.1.4.1.4203.666.11.9.6.1
3599 requestValue ::= SEQUENCE { CHOICE {
3601 entryDN [1] LDAPDN },
3602 queryID [2] OCTET STRING (SIZE(16))
3603 -- constrained to UUID }
3605 * Either baseDN or entryDN must be present, to allow database selection.
3607 * 1. if baseDN and queryID are present, then the query corresponding
3608 * to queryID is deleted;
3609 * 2. if baseDN is present and queryID is absent, then all queries
3611 * 3. if entryDN is present and queryID is absent, then all queries
3612 * corresponding to the queryID values present in entryDN are deleted;
3613 * 4. if entryDN and queryID are present, then all queries
3614 * corresponding to the queryID values present in entryDN are deleted,
3615 * but only if the value of queryID is contained in the entry;
3617 * Currently, only 1, 3 and 4 are implemented. 2 can be obtained by either
3618 * recursively deleting the database (ldapdelete -r) with PRIVDB control,
3619 * or by removing the database files.
3621 ExtendedResponse ::= [APPLICATION 24] SEQUENCE {
3622 COMPONENTS OF LDAPResult,
3623 responseName [10] LDAPOID OPTIONAL,
3624 responseValue [11] OCTET STRING OPTIONAL }
3626 * responseName and responseValue must be absent.
3630 * - on success, *tagp is either LDAP_TAG_EXOP_QUERY_DELETE_BASE
3631 * or LDAP_TAG_EXOP_QUERY_DELETE_DN.
3632 * - if ndn != NULL, it is set to the normalized DN in the request
3633 * corresponding to either the baseDN or the entryDN, according
3634 * to *tagp; memory is malloc'ed on the Operation's slab, and must
3635 * be freed by the caller.
3636 * - if uuid != NULL, it is set to point to the normalized UUID;
3637 * memory is malloc'ed on the Operation's slab, and must
3638 * be freed by the caller.
3641 pcache_parse_query_delete(
3645 struct berval *uuid,
3649 int rc = LDAP_SUCCESS;
3652 BerElementBuffer berbuf;
3653 BerElement *ber = (BerElement *)&berbuf;
3654 struct berval reqdata = BER_BVNULL;
3666 if ( in == NULL || in->bv_len == 0 ) {
3667 *text = "empty request data field in queryDelete exop";
3668 return LDAP_PROTOCOL_ERROR;
3671 ber_dupbv_x( &reqdata, in, ctx );
3673 /* ber_init2 uses reqdata directly, doesn't allocate new buffers */
3674 ber_init2( ber, &reqdata, 0 );
3676 tag = ber_scanf( ber, "{" /*}*/ );
3678 if ( tag == LBER_ERROR ) {
3679 Debug( LDAP_DEBUG_TRACE,
3680 "pcache_parse_query_delete: decoding error.\n",
3682 goto decoding_error;
3685 tag = ber_peek_tag( ber, &len );
3686 if ( tag == LDAP_TAG_EXOP_QUERY_DELETE_BASE
3687 || tag == LDAP_TAG_EXOP_QUERY_DELETE_DN )
3691 if ( ndn != NULL ) {
3694 tag = ber_scanf( ber, "m", &dn );
3695 if ( tag == LBER_ERROR ) {
3696 Debug( LDAP_DEBUG_TRACE,
3697 "pcache_parse_query_delete: DN parse failed.\n",
3699 goto decoding_error;
3702 rc = dnNormalize( 0, NULL, NULL, &dn, ndn, ctx );
3703 if ( rc != LDAP_SUCCESS ) {
3704 *text = "invalid DN in queryDelete exop request data";
3709 tag = ber_scanf( ber, "x" /* "m" */ );
3710 if ( tag == LBER_DEFAULT ) {
3711 goto decoding_error;
3715 tag = ber_peek_tag( ber, &len );
3718 if ( tag == LDAP_TAG_EXOP_QUERY_DELETE_UUID ) {
3719 if ( uuid != NULL ) {
3721 char uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ];
3723 tag = ber_scanf( ber, "m", &bv );
3724 if ( tag == LBER_ERROR ) {
3725 Debug( LDAP_DEBUG_TRACE,
3726 "pcache_parse_query_delete: UUID parse failed.\n",
3728 goto decoding_error;
3731 if ( bv.bv_len != 16 ) {
3732 Debug( LDAP_DEBUG_TRACE,
3733 "pcache_parse_query_delete: invalid UUID length %lu.\n",
3734 (unsigned long)bv.bv_len, 0, 0 );
3735 goto decoding_error;
3738 rc = lutil_uuidstr_from_normalized(
3739 bv.bv_val, bv.bv_len,
3740 uuidbuf, sizeof( uuidbuf ) );
3742 goto decoding_error;
3744 ber_str2bv( uuidbuf, rc, 1, uuid );
3748 tag = ber_skip_tag( ber, &len );
3749 if ( tag == LBER_DEFAULT ) {
3750 goto decoding_error;
3754 Debug( LDAP_DEBUG_TRACE,
3755 "pcache_parse_query_delete: invalid UUID length %lu.\n",
3756 (unsigned long)len, 0, 0 );
3757 goto decoding_error;
3761 tag = ber_peek_tag( ber, &len );
3764 if ( tag != LBER_DEFAULT || len != 0 ) {
3766 Debug( LDAP_DEBUG_TRACE,
3767 "pcache_parse_query_delete: decoding error\n",
3769 rc = LDAP_PROTOCOL_ERROR;
3770 *text = "queryDelete data decoding error";
3773 if ( ndn && !BER_BVISNULL( ndn ) ) {
3774 slap_sl_free( ndn->bv_val, ctx );
3778 if ( uuid && !BER_BVISNULL( uuid ) ) {
3779 slap_sl_free( uuid->bv_val, ctx );
3784 if ( !BER_BVISNULL( &reqdata ) ) {
3785 ber_memfree_x( reqdata.bv_val, ctx );
3792 pcache_exop_query_delete(
3796 BackendDB *bd = op->o_bd;
3798 struct berval uuid = BER_BVNULL,
3800 char buf[ SLAP_TEXT_BUFLEN ];
3802 ber_tag_t tag = LBER_DEFAULT;
3804 if ( LogTest( LDAP_DEBUG_STATS ) ) {
3808 rs->sr_err = pcache_parse_query_delete( op->ore_reqdata,
3809 &tag, &op->o_req_ndn, uuidp,
3810 &rs->sr_text, op->o_tmpmemctx );
3811 if ( rs->sr_err != LDAP_SUCCESS ) {
3815 if ( LogTest( LDAP_DEBUG_STATS ) ) {
3816 assert( !BER_BVISNULL( &op->o_req_ndn ) );
3817 len = snprintf( buf, sizeof( buf ), " dn=\"%s\"", op->o_req_ndn.bv_val );
3819 if ( !BER_BVISNULL( &uuid ) && len < sizeof( buf ) ) {
3820 snprintf( &buf[ len ], sizeof( buf ) - len, " queryId=\"%s\"", uuid.bv_val );
3823 Debug( LDAP_DEBUG_STATS, "%s QUERY DELETE%s\n",
3824 op->o_log_prefix, buf, 0 );
3826 op->o_req_dn = op->o_req_ndn;
3828 op->o_bd = select_backend( &op->o_req_ndn, 0 );
3829 rs->sr_err = backend_check_restrictions( op, rs,
3830 (struct berval *)&pcache_exop_QUERY_DELETE );
3831 if ( rs->sr_err != LDAP_SUCCESS ) {
3835 if ( op->o_bd->be_extended == NULL ) {
3836 send_ldap_error( op, rs, LDAP_UNAVAILABLE_CRITICAL_EXTENSION,
3837 "backend does not support extended operations" );
3841 op->o_bd->be_extended( op, rs );
3844 if ( !BER_BVISNULL( &op->o_req_ndn ) ) {
3845 op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
3846 BER_BVZERO( &op->o_req_ndn );
3847 BER_BVZERO( &op->o_req_dn );
3850 if ( !BER_BVISNULL( &uuid ) ) {
3851 op->o_tmpfree( uuid.bv_val, op->o_tmpmemctx );
3860 pcache_op_extended( Operation *op, SlapReply *rs )
3862 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
3863 cache_manager *cm = on->on_bi.bi_private;
3865 #ifdef PCACHE_CONTROL_PRIVDB
3866 if ( op->o_ctrlflag[ privDB_cid ] == SLAP_CONTROL_CRITICAL ) {
3867 return pcache_op_privdb( op, rs );
3869 #endif /* PCACHE_CONTROL_PRIVDB */
3871 if ( bvmatch( &op->ore_reqoid, &pcache_exop_QUERY_DELETE ) ) {
3872 struct berval uuid = BER_BVNULL;
3873 ber_tag_t tag = LBER_DEFAULT;
3875 rs->sr_err = pcache_parse_query_delete( op->ore_reqdata,
3876 &tag, NULL, &uuid, &rs->sr_text, op->o_tmpmemctx );
3877 assert( rs->sr_err == LDAP_SUCCESS );
3879 if ( tag == LDAP_TAG_EXOP_QUERY_DELETE_DN ) {
3880 /* remove all queries related to the selected entry */
3881 rs->sr_err = pcache_remove_entry_queries_from_cache( op,
3882 cm, &op->o_req_ndn, &uuid );
3884 } else if ( tag == LDAP_TAG_EXOP_QUERY_DELETE_BASE ) {
3885 if ( !BER_BVISNULL( &uuid ) ) {
3886 /* remove the selected query */
3887 rs->sr_err = pcache_remove_query_from_cache( op,
3891 /* TODO: remove all queries */
3892 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
3893 rs->sr_text = "deletion of all queries not implemented";
3897 op->o_tmpfree( uuid.bv_val, op->o_tmpmemctx );
3902 #endif /* PCACHE_EXOP_QUERY_DELETE */
3904 static slap_overinst pcache;
3906 static char *obsolete_names[] = {
3911 #if SLAPD_OVER_PROXYCACHE == SLAPD_MOD_DYNAMIC
3913 #endif /* SLAPD_OVER_PROXYCACHE == SLAPD_MOD_DYNAMIC */
3918 struct berval debugbv = BER_BVC("pcache");
3920 code = slap_loglevel_get( &debugbv, &pcache_debug );
3925 #ifdef PCACHE_CONTROL_PRIVDB
3926 code = register_supported_control( PCACHE_CONTROL_PRIVDB,
3927 SLAP_CTRL_BIND|SLAP_CTRL_ACCESS|SLAP_CTRL_HIDE, extops,
3928 parse_privdb_ctrl, &privDB_cid );
3929 if ( code != LDAP_SUCCESS ) {
3930 Debug( LDAP_DEBUG_ANY,
3931 "pcache_initialize: failed to register control %s (%d)\n",
3932 PCACHE_CONTROL_PRIVDB, code, 0 );
3935 #endif /* PCACHE_CONTROL_PRIVDB */
3937 #ifdef PCACHE_EXOP_QUERY_DELETE
3938 code = load_extop2( (struct berval *)&pcache_exop_QUERY_DELETE,
3939 SLAP_EXOP_WRITES|SLAP_EXOP_HIDE, pcache_exop_query_delete,
3941 if ( code != LDAP_SUCCESS ) {
3942 Debug( LDAP_DEBUG_ANY,
3943 "pcache_initialize: unable to register queryDelete exop: %d.\n",
3947 #endif /* PCACHE_EXOP_QUERY_DELETE */
3949 for ( i = 0; as[i].desc != NULL; i++ ) {
3950 code = register_at( as[i].desc, as[i].adp, 0 );
3952 Debug( LDAP_DEBUG_ANY,
3953 "pcache_initialize: register_at #%d failed\n", i, 0, 0 );
3956 (*as[i].adp)->ad_type->sat_flags |= SLAP_AT_HIDE;
3959 pcache.on_bi.bi_type = "pcache";
3960 pcache.on_bi.bi_obsolete_names = obsolete_names;
3961 pcache.on_bi.bi_db_init = pcache_db_init;
3962 pcache.on_bi.bi_db_config = pcache_db_config;
3963 pcache.on_bi.bi_db_open = pcache_db_open;
3964 pcache.on_bi.bi_db_close = pcache_db_close;
3965 pcache.on_bi.bi_db_destroy = pcache_db_destroy;
3967 pcache.on_bi.bi_op_search = pcache_op_search;
3968 #ifdef PCACHE_CONTROL_PRIVDB
3969 pcache.on_bi.bi_op_bind = pcache_op_privdb;
3970 pcache.on_bi.bi_op_compare = pcache_op_privdb;
3971 pcache.on_bi.bi_op_modrdn = pcache_op_privdb;
3972 pcache.on_bi.bi_op_modify = pcache_op_privdb;
3973 pcache.on_bi.bi_op_add = pcache_op_privdb;
3974 pcache.on_bi.bi_op_delete = pcache_op_privdb;
3975 #endif /* PCACHE_CONTROL_PRIVDB */
3976 #ifdef PCACHE_EXOP_QUERY_DELETE
3977 pcache.on_bi.bi_extended = pcache_op_extended;
3978 #elif defined( PCACHE_CONTROL_PRIVDB )
3979 pcache.on_bi.bi_extended = pcache_op_privdb;
3982 pcache.on_bi.bi_chk_controls = pcache_chk_controls;
3984 pcache.on_bi.bi_cf_ocs = pcocs;
3986 code = config_register_schema( pccfg, pcocs );
3987 if ( code ) return code;
3989 return overlay_register( &pcache );
3992 #if SLAPD_OVER_PROXYCACHE == SLAPD_MOD_DYNAMIC
3993 int init_module(int argc, char *argv[]) {
3994 return pcache_initialize();
3998 #endif /* defined(SLAPD_OVER_PROXYCACHE) */