2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 2003-2007 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>
38 /* query cache structs */
41 typedef struct Query_s {
42 Filter* filter; /* Search Filter */
43 struct berval base; /* Search Base */
44 int scope; /* Search scope */
47 struct query_template_s;
49 typedef struct Qbase_s {
50 Avlnode *scopes[4]; /* threaded AVL trees of cached queries */
55 /* struct representing a cached query */
56 typedef struct cached_query_s {
61 struct berval q_uuid; /* query identifier */
62 struct query_template_s *qtemp; /* template of the query */
63 time_t expiry_time; /* time till the query is considered valid */
64 struct cached_query_s *next; /* next query in the template */
65 struct cached_query_s *prev; /* previous query in the template */
66 struct cached_query_s *lru_up; /* previous query in the LRU list */
67 struct cached_query_s *lru_down; /* next query in the LRU list */
73 * ldap:///<base>??<scope>?<filter>?x-uuid=<uid>,x-template=<template>,x-attrset=<attrset>,x-expiry=<expiry>
75 * <base> ::= CachedQuery.qbase->base
76 * <scope> ::= CachedQuery.scope
77 * <filter> ::= filter2bv(CachedQuery.filter)
78 * <uuid> ::= CachedQuery.q_uuid
79 * <template> ::= CachedQuery.qtemp->querystr [FIXME: better give it an ID?]
80 * <attrset> ::= CachedQuery.qtemp->attr_set_index [FIXME: better give it an ID?]
81 * <expiry> ::= CachedQuery.expiry_time
83 * quick hack: parse URI, call add_query() and then fix
84 * CachedQuery.expiry_time and CachedQuery.q_uuid
88 * Represents a set of projected attributes.
92 struct query_template_s *templates;
93 AttributeName* attrs; /* specifies the set */
95 #define PC_CONFIGURED (0x1)
96 #define PC_REFERENCED (0x2)
97 #define PC_GOT_OC (0x4)
98 int count; /* number of attributes */
101 /* struct representing a query template
102 * e.g. template string = &(cn=)(mail=)
104 typedef struct query_template_s {
105 struct query_template_s *qtnext;
106 struct query_template_s *qmnext;
109 CachedQuery* query; /* most recent query cached for the template */
110 CachedQuery* query_last; /* oldest query cached for the template */
111 ldap_pvt_thread_rdwr_t t_rwlock; /* Rd/wr lock for accessing queries in the template */
112 struct berval querystr; /* Filter string corresponding to the QT */
114 int attr_set_index; /* determines the projected attributes */
115 int no_of_queries; /* Total number of queries in the template */
116 time_t ttl; /* TTL for the queries of this template */
117 time_t negttl; /* TTL for negative results */
118 struct attr_set t_attrs; /* filter attrs + attr_set */
121 struct query_manager_s;
123 /* prototypes for functions for 1) query containment
124 * 2) query addition, 3) cache replacement
126 typedef CachedQuery * (QCfunc)(Operation *op, struct query_manager_s*, Query*, QueryTemplate*);
127 typedef CachedQuery * (AddQueryfunc)(Operation *op, struct query_manager_s*, Query*, QueryTemplate*, int positive);
128 typedef void (CRfunc)(struct query_manager_s*, struct berval * );
130 /* LDAP query cache */
131 typedef struct query_manager_s {
132 struct attr_set* attr_sets; /* possible sets of projected attributes */
133 QueryTemplate* templates; /* cacheable templates */
135 CachedQuery* lru_top; /* top and bottom of LRU list */
136 CachedQuery* lru_bottom;
138 ldap_pvt_thread_mutex_t lru_mutex; /* mutex for accessing LRU list */
140 /* Query cache methods */
141 QCfunc *qcfunc; /* Query containment*/
142 CRfunc *crfunc; /* cache replacement */
143 AddQueryfunc *addfunc; /* add query */
146 /* LDAP query cache manager */
147 typedef struct cache_manager_s {
148 BackendDB db; /* underlying database */
149 unsigned long num_cached_queries; /* total number of cached queries */
150 unsigned long max_queries; /* upper bound on # of cached queries */
151 int save_queries; /* save cached queries across restarts */
152 int numattrsets; /* number of attribute sets */
153 int cur_entries; /* current number of entries cached */
154 int max_entries; /* max number of entries cached */
155 int num_entries_limit; /* max # of entries in a cacheable query */
157 char response_cb; /* install the response callback
158 * at the tail of the callback list */
159 #define PCACHE_RESPONSE_CB_HEAD 0
160 #define PCACHE_RESPONSE_CB_TAIL 1
162 time_t cc_period; /* interval between successive consistency checks (sec) */
166 ldap_pvt_thread_mutex_t cache_mutex;
168 query_manager* qm; /* query cache managed by the cache manager */
171 static int pcache_debug;
173 static AttributeDescription *ad_queryid, *ad_cachedQueryURL;
176 AttributeDescription **adp;
178 { "( 1.3.6.1.4.1.4203.666.1.12 NAME 'queryid' "
179 "DESC 'list of queries the entry belongs to' "
180 "EQUALITY octetStringMatch "
181 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40{64} "
182 "NO-USER-MODIFICATION USAGE directoryOperation )",
184 { "(1.3.6.1.4.1.4203.666.1.999999 NAME 'cachedQueryURL' "
185 "DESC 'URI describing a cached query' "
186 "EQUALITY caseExactMatch "
187 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 "
188 "NO-USER-MODIFICATION USAGE directoryOperation )",
189 &ad_cachedQueryURL },
198 AttributeName** filter_attrs,
200 int* filter_got_oc );
207 QueryTemplate *templ,
214 struct berval *query_uuid );
217 * Turn a cached query into its URL representation
220 query2url( Operation *op, CachedQuery *q, struct berval *urlbv )
222 struct berval bv_scope,
224 char attrset_buf[ 32 ],
227 ber_len_t attrset_len,
230 ldap_pvt_scope2bv( q->scope, &bv_scope );
231 filter2bv_x( op, q->filter, &bv_filter );
232 attrset_len = snprintf( attrset_buf, sizeof( attrset_buf ),
233 "%lu", (unsigned long)q->qtemp->attr_set_index );
234 expiry_len = snprintf( expiry_buf, sizeof( expiry_buf ),
235 "%lu", (unsigned long)q->expiry_time );
237 urlbv->bv_len = STRLENOF( "ldap:///" )
238 + q->qbase->base.bv_len
243 + STRLENOF( "?x-uuid=" )
245 + STRLENOF( ",x-attrset=" )
247 + STRLENOF( ",x-expiry=" )
249 ptr = urlbv->bv_val = ber_memalloc_x( urlbv->bv_len + 1, op->o_tmpmemctx );
250 ptr = lutil_strcopy( ptr, "ldap:///" );
251 ptr = lutil_strcopy( ptr, q->qbase->base.bv_val );
252 ptr = lutil_strcopy( ptr, "??" );
253 ptr = lutil_strcopy( ptr, bv_scope.bv_val );
254 ptr = lutil_strcopy( ptr, "?" );
255 ptr = lutil_strcopy( ptr, bv_filter.bv_val );
256 ptr = lutil_strcopy( ptr, "?x-uuid=" );
257 ptr = lutil_strcopy( ptr, q->q_uuid.bv_val );
258 ptr = lutil_strcopy( ptr, ",x-attrset=" );
259 ptr = lutil_strcopy( ptr, attrset_buf );
260 ptr = lutil_strcopy( ptr, ",x-expiry=" );
261 ptr = lutil_strcopy( ptr, expiry_buf );
263 ber_memfree_x( bv_filter.bv_val, op->o_tmpmemctx );
269 * Turn an URL representing a formerly cached query into a cached query,
270 * and try to cache it
281 LDAPURLDesc *lud = NULL;
283 tempstr = BER_BVNULL,
293 rc = ldap_url_parse( url, &lud );
294 if ( rc != LDAP_URL_SUCCESS ) {
298 /* non-allowed fields */
299 if ( lud->lud_host != NULL ) {
304 if ( lud->lud_attrs != NULL ) {
310 if ( strcmp( lud->lud_scheme, "ldap" ) != 0 ) {
315 /* required fields */
316 if ( lud->lud_dn == NULL || lud->lud_dn[ 0 ] == '\0' ) {
321 switch ( lud->lud_scope ) {
322 case LDAP_SCOPE_BASE:
323 case LDAP_SCOPE_ONELEVEL:
324 case LDAP_SCOPE_SUBTREE:
325 case LDAP_SCOPE_SUBORDINATE:
333 if ( lud->lud_filter == NULL || lud->lud_filter[ 0 ] == '\0' ) {
338 if ( lud->lud_exts == NULL ) {
343 for ( i = 0; lud->lud_exts[ i ] != NULL; i++ ) {
344 if ( strncmp( lud->lud_exts[ i ], "x-uuid=", STRLENOF( "x-uuid=" ) ) == 0 ) {
345 struct berval tmpUUID;
346 Syntax *syn_UUID = slap_schema.si_ad_entryUUID->ad_type->sat_syntax;
348 ber_str2bv( &lud->lud_exts[ i ][ STRLENOF( "x-uuid=" ) ], 0, 0, &tmpUUID );
349 rc = syn_UUID->ssyn_pretty( syn_UUID, &tmpUUID, &uuid, NULL );
350 if ( rc != LDAP_SUCCESS ) {
355 } else if ( strncmp( lud->lud_exts[ i ], "x-attrset=", STRLENOF( "x-attrset=" ) ) == 0 ) {
356 rc = lutil_atoi( &attrset, &lud->lud_exts[ i ][ STRLENOF( "x-attrset=" ) ] );
362 } else if ( strncmp( lud->lud_exts[ i ], "x-expiry=", STRLENOF( "x-expiry=" ) ) == 0 ) {
365 rc = lutil_atoul( &l, &lud->lud_exts[ i ][ STRLENOF( "x-expiry=" ) ] );
369 expiry_time = (time_t)l;
383 if ( !got_attrset ) {
393 /* ignore expired queries */
394 if ( expiry_time <= slap_get_time()) {
396 SlapReply rs2 = { 0 };
398 memset( &op2.oq_search, 0, sizeof( op2.oq_search ) );
400 (void)remove_query_data( &op2, &rs2, &uuid );
405 ber_str2bv( lud->lud_dn, 0, 0, &base );
406 rc = dnNormalize( 0, NULL, NULL, &base, &query.base, NULL );
407 if ( rc != LDAP_SUCCESS ) {
410 query.scope = lud->lud_scope;
411 query.filter = str2filter( lud->lud_filter );
413 tempstr.bv_val = ch_malloc( strlen( lud->lud_filter ) + 1 );
415 if ( filter2template( op, query.filter, &tempstr, NULL, NULL, NULL ) ) {
416 ch_free( tempstr.bv_val );
421 /* check for query containment */
422 qt = qm->attr_sets[attrset].templates;
423 for ( ; qt; qt = qt->qtnext ) {
424 /* find if template i can potentially answer tempstr */
425 if ( bvmatch( &qt->querystr, &tempstr ) ) {
435 cq = add_query( op, qm, &query, qt, 1 );
437 cq->expiry_time = expiry_time;
440 /* it's now into cq->filter */
450 if ( query.filter != NULL ) filter_free( query.filter );
451 if ( !BER_BVISNULL( &tempstr ) ) ch_free( tempstr.bv_val );
452 if ( !BER_BVISNULL( &query.base ) ) ch_free( query.base.bv_val );
453 if ( !BER_BVISNULL( &uuid ) ) ch_free( uuid.bv_val );
454 if ( lud != NULL ) ldap_free_urldesc( lud );
459 /* Return 1 for an added entry, else 0 */
464 struct berval* query_uuid )
467 Modifications* modlist = NULL;
468 const char* text = NULL;
470 char textbuf[SLAP_TEXT_BUFLEN];
471 size_t textlen = sizeof(textbuf);
473 SlapReply sreply = {REP_RESULT};
475 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
480 /* add queryid attribute */
481 attr_merge_one( e, ad_queryid, query_uuid, NULL );
483 /* append the attribute list from the fetched entry */
484 e->e_attrs->a_next = attr;
486 op->o_tag = LDAP_REQ_ADD;
487 op->o_protocol = LDAP_VERSION3;
488 op->o_callback = &cb;
489 op->o_time = slap_get_time();
490 op->o_do_not_cache = 1;
493 op->o_req_dn = e->e_name;
494 op->o_req_ndn = e->e_nname;
495 rc = op->o_bd->be_add( op, &sreply );
497 if ( rc != LDAP_SUCCESS ) {
498 if ( rc == LDAP_ALREADY_EXISTS ) {
499 slap_entry2mods( e, &modlist, &text, textbuf, textlen );
500 modlist->sml_op = LDAP_MOD_ADD;
501 op->o_tag = LDAP_REQ_MODIFY;
502 op->orm_modlist = modlist;
503 op->o_bd->be_modify( op, &sreply );
504 slap_mods_free( modlist, 1 );
505 } else if ( rc == LDAP_REFERRAL ||
506 rc == LDAP_NO_SUCH_OBJECT ) {
507 syncrepl_add_glue( op, e );
516 if ( op->ora_e == e )
517 be_entry_release_w( op, e );
524 /* Length-ordered sort on normalized DNs */
525 static int pcache_dn_cmp( const void *v1, const void *v2 )
527 const Qbase *q1 = v1, *q2 = v2;
529 int rc = q1->base.bv_len - q2->base.bv_len;
531 rc = strncmp( q1->base.bv_val, q2->base.bv_val, q1->base.bv_len );
535 static int lex_bvcmp( struct berval *bv1, struct berval *bv2 )
538 dif = bv1->bv_len - bv2->bv_len;
540 if ( dif > 0 ) len -= dif;
541 len = memcmp( bv1->bv_val, bv2->bv_val, len );
547 /* compare the first value in each filter */
548 static int pcache_filter_cmp( const void *v1, const void *v2 )
550 const CachedQuery *q1 = v1, *q2 =v2;
551 int rc, weight1, weight2;
553 switch( q1->first->f_choice ) {
554 case LDAP_FILTER_PRESENT:
557 case LDAP_FILTER_EQUALITY:
565 switch( q2->first->f_choice ) {
566 case LDAP_FILTER_PRESENT:
569 case LDAP_FILTER_EQUALITY:
577 rc = weight1 - weight2;
582 rc = lex_bvcmp( &q1->first->f_av_value, &q2->first->f_av_value );
585 if ( q1->first->f_choice == LDAP_FILTER_SUBSTRINGS ) {
587 if ( !BER_BVISNULL( &q1->first->f_sub_initial )) {
588 if ( !BER_BVISNULL( &q2->first->f_sub_initial )) {
589 rc = lex_bvcmp( &q1->first->f_sub_initial,
590 &q2->first->f_sub_initial );
594 } else if ( !BER_BVISNULL( &q2->first->f_sub_initial )) {
598 if ( q1->first->f_sub_any ) {
599 if ( q2->first->f_sub_any ) {
600 rc = lex_bvcmp( q1->first->f_sub_any,
601 q2->first->f_sub_any );
605 } else if ( q2->first->f_sub_any ) {
609 if ( !BER_BVISNULL( &q1->first->f_sub_final )) {
610 if ( !BER_BVISNULL( &q2->first->f_sub_final )) {
611 rc = lex_bvcmp( &q1->first->f_sub_final,
612 &q2->first->f_sub_final );
616 } else if ( !BER_BVISNULL( &q2->first->f_sub_final )) {
620 rc = lex_bvcmp( &q1->first->f_mr_value,
621 &q2->first->f_mr_value );
630 /* add query on top of LRU list */
632 add_query_on_top (query_manager* qm, CachedQuery* qc)
634 CachedQuery* top = qm->lru_top;
645 Debug( pcache_debug, "Base of added query = %s\n",
646 qc->qbase->base.bv_val, 0, 0 );
649 /* remove_query from LRU list */
652 remove_query (query_manager* qm, CachedQuery* qc)
675 qc->lru_up = qc->lru_down = NULL;
678 /* find and remove string2 from string1
679 * from start if position = 1,
680 * from end if position = 3,
681 * from anywhere if position = 2
682 * string1 is overwritten if position = 2.
686 find_and_remove(struct berval* ber1, struct berval* ber2, int position)
697 if ( ber1->bv_len >= ber2->bv_len && !memcmp( ber1->bv_val,
698 ber2->bv_val, ber2->bv_len )) {
700 ber1->bv_val += ber2->bv_len;
701 ber1->bv_len -= ber2->bv_len;
706 ber1->bv_val[ber1->bv_len] = '\0';
707 temp = strstr( ber1->bv_val, ber2->bv_val );
709 strcpy( temp, temp+ber2->bv_len );
710 ber1->bv_len -= ber2->bv_len;
716 if ( ber1->bv_len >= ber2->bv_len &&
717 !memcmp( ber1->bv_val+ber1->bv_len-ber2->bv_len, ber2->bv_val,
720 ber1->bv_len -= ber2->bv_len;
728 static struct berval*
729 merge_init_final(Operation *op, struct berval* init, struct berval* any,
730 struct berval* final)
732 struct berval* merged, *temp;
733 int i, any_count, count;
735 for (any_count=0; any && any[any_count].bv_val; any_count++)
745 merged = (struct berval*)op->o_tmpalloc( (count+1)*sizeof(struct berval),
750 ber_dupbv_x( temp, init, op->o_tmpmemctx );
754 for (i=0; i<any_count; i++) {
755 ber_dupbv_x( temp, any, op->o_tmpmemctx );
760 ber_dupbv_x( temp, final, op->o_tmpmemctx );
767 /* Each element in stored must be found in incoming. Incoming is overwritten.
770 strings_containment(struct berval* stored, struct berval* incoming)
772 struct berval* element;
776 for ( element=stored; element->bv_val != NULL; element++ ) {
777 for (j = k; incoming[j].bv_val != NULL; j++) {
778 if (find_and_remove(&(incoming[j]), element, 2)) {
795 substr_containment_substr(Operation *op, Filter* stored, Filter* incoming)
799 struct berval init_incoming;
800 struct berval final_incoming;
801 struct berval *remaining_incoming = NULL;
803 if ((!(incoming->f_sub_initial.bv_val) && (stored->f_sub_initial.bv_val))
804 || (!(incoming->f_sub_final.bv_val) && (stored->f_sub_final.bv_val)))
807 init_incoming = incoming->f_sub_initial;
808 final_incoming = incoming->f_sub_final;
810 if (find_and_remove(&init_incoming,
811 &(stored->f_sub_initial), 1) && find_and_remove(&final_incoming,
812 &(stored->f_sub_final), 3))
814 if (stored->f_sub_any == NULL) {
818 remaining_incoming = merge_init_final(op, &init_incoming,
819 incoming->f_sub_any, &final_incoming);
820 rc = strings_containment(stored->f_sub_any, remaining_incoming);
821 ber_bvarray_free_x( remaining_incoming, op->o_tmpmemctx );
828 substr_containment_equality(Operation *op, Filter* stored, Filter* incoming)
830 struct berval incoming_val[2];
833 incoming_val[1] = incoming->f_av_value;
835 if (find_and_remove(incoming_val+1,
836 &(stored->f_sub_initial), 1) && find_and_remove(incoming_val+1,
837 &(stored->f_sub_final), 3)) {
838 if (stored->f_sub_any == NULL){
842 ber_dupbv_x( incoming_val, incoming_val+1, op->o_tmpmemctx );
843 BER_BVZERO( incoming_val+1 );
844 rc = strings_containment(stored->f_sub_any, incoming_val);
845 op->o_tmpfree( incoming_val[0].bv_val, op->o_tmpmemctx );
852 filter_first( Filter *f )
854 while ( f->f_choice == LDAP_FILTER_OR || f->f_choice == LDAP_FILTER_AND )
861 find_filter( Operation *op, Avlnode *root, Filter *inputf, Filter *first )
865 MatchingRule* mrule = NULL;
866 int res=0, eqpass= 0;
874 /* substring matches sort to the end, and we just have to
875 * walk the entire list.
877 if ( first->f_choice == LDAP_FILTER_SUBSTRINGS ) {
878 ptr = tavl_end( root, 1 );
881 ptr = tavl_find3( root, &cq, pcache_filter_cmp, &ret );
882 dir = (first->f_choice == LDAP_FILTER_GE) ? TAVL_DIR_LEFT :
891 /* an incoming substr query can only be satisfied by a cached
894 if ( first->f_choice == LDAP_FILTER_SUBSTRINGS &&
895 qc->first->f_choice != LDAP_FILTER_SUBSTRINGS )
898 /* an incoming eq query can be satisfied by a cached eq or substr
901 if ( first->f_choice == LDAP_FILTER_EQUALITY ) {
903 if ( qc->first->f_choice != LDAP_FILTER_EQUALITY ) {
904 nextpass: eqpass = 1;
905 ptr = tavl_end( root, 1 );
910 if ( qc->first->f_choice != LDAP_FILTER_SUBSTRINGS )
916 switch (fs->f_choice) {
917 case LDAP_FILTER_EQUALITY:
918 if (fi->f_choice == LDAP_FILTER_EQUALITY)
919 mrule = fs->f_ava->aa_desc->ad_type->sat_equality;
925 mrule = fs->f_ava->aa_desc->ad_type->sat_ordering;
932 rc = value_match(&ret, fs->f_ava->aa_desc, mrule,
933 SLAP_MR_VALUE_OF_ASSERTION_SYNTAX,
934 &(fi->f_ava->aa_value),
935 &(fs->f_ava->aa_value), &text);
936 if (rc != LDAP_SUCCESS) {
939 if ( fi==first && fi->f_choice==LDAP_FILTER_EQUALITY && ret )
942 switch (fs->f_choice) {
944 case LDAP_FILTER_AND:
949 case LDAP_FILTER_SUBSTRINGS:
950 /* check if the equality query can be
951 * answered with cached substring query */
952 if ((fi->f_choice == LDAP_FILTER_EQUALITY)
953 && substr_containment_equality( op,
956 /* check if the substring query can be
957 * answered with cached substring query */
958 if ((fi->f_choice ==LDAP_FILTER_SUBSTRINGS
959 ) && substr_containment_substr( op,
965 case LDAP_FILTER_PRESENT:
970 case LDAP_FILTER_EQUALITY:
977 if (mrule && ret >= 0)
983 if (mrule && ret <= 0)
988 case LDAP_FILTER_NOT:
994 } while((res) && (fi != NULL) && (fs != NULL));
998 ptr = tavl_next( ptr, dir );
1003 /* check whether query is contained in any of
1004 * the cached queries in template
1006 static CachedQuery *
1007 query_containment(Operation *op, query_manager *qm,
1009 QueryTemplate *templa)
1012 int depth = 0, tscope;
1013 Qbase qbase, *qbptr = NULL;
1016 if (query->filter != NULL) {
1019 Debug( pcache_debug, "Lock QC index = %p\n",
1020 (void *) templa, 0, 0 );
1021 qbase.base = query->base;
1023 first = filter_first( query->filter );
1025 ldap_pvt_thread_rdwr_rlock(&templa->t_rwlock);
1028 qbptr = avl_find( templa->qbase, &qbase, pcache_dn_cmp );
1030 tscope = query->scope;
1031 /* Find a matching scope:
1032 * match at depth 0 OK
1035 * subord at depth > 0 OK
1036 * subtree at any depth OK
1038 * subtree or subord at any depth OK
1040 * subtree or subord at any depth OK
1042 * subord at depth > 0 OK
1043 * subtree at any depth OK
1045 for ( tscope = 0 ; tscope <= LDAP_SCOPE_CHILDREN; tscope++ ) {
1046 switch ( query->scope ) {
1047 case LDAP_SCOPE_BASE:
1048 if ( tscope == LDAP_SCOPE_BASE && depth ) continue;
1049 if ( tscope == LDAP_SCOPE_ONE && depth != 1) continue;
1050 if ( tscope == LDAP_SCOPE_CHILDREN && !depth ) continue;
1052 case LDAP_SCOPE_ONE:
1053 if ( tscope == LDAP_SCOPE_BASE )
1054 tscope = LDAP_SCOPE_ONE;
1055 if ( tscope == LDAP_SCOPE_ONE && depth ) continue;
1056 if ( !depth ) break;
1057 if ( tscope < LDAP_SCOPE_SUBTREE )
1058 tscope = LDAP_SCOPE_SUBTREE;
1060 case LDAP_SCOPE_SUBTREE:
1061 if ( tscope < LDAP_SCOPE_SUBTREE )
1062 tscope = LDAP_SCOPE_SUBTREE;
1063 if ( tscope == LDAP_SCOPE_CHILDREN && !depth ) continue;
1065 case LDAP_SCOPE_CHILDREN:
1066 if ( tscope < LDAP_SCOPE_SUBTREE )
1067 tscope = LDAP_SCOPE_SUBTREE;
1070 if ( !qbptr->scopes[tscope] ) continue;
1073 qc = find_filter( op, qbptr->scopes[tscope],
1074 query->filter, first );
1076 ldap_pvt_thread_mutex_lock(&qm->lru_mutex);
1077 if (qm->lru_top != qc) {
1078 remove_query(qm, qc);
1079 add_query_on_top(qm, qc);
1081 ldap_pvt_thread_mutex_unlock(&qm->lru_mutex);
1086 if ( be_issuffix( op->o_bd, &qbase.base ))
1089 dnParent( &qbase.base, &pdn );
1094 Debug( pcache_debug,
1095 "Not answerable: Unlock QC index=%p\n",
1096 (void *) templa, 0, 0 );
1097 ldap_pvt_thread_rdwr_runlock(&templa->t_rwlock);
1103 free_query (CachedQuery* qc)
1105 free(qc->q_uuid.bv_val);
1106 filter_free(qc->filter);
1111 /* Add query to query cache */
1112 static CachedQuery *
1117 QueryTemplate *templ,
1120 CachedQuery* new_cached_query = (CachedQuery*) ch_malloc(sizeof(CachedQuery));
1125 new_cached_query->qtemp = templ;
1126 BER_BVZERO( &new_cached_query->q_uuid );
1128 new_cached_query->expiry_time = slap_get_time() + templ->ttl;
1130 new_cached_query->expiry_time = slap_get_time() + templ->negttl;
1132 new_cached_query->lru_up = NULL;
1133 new_cached_query->lru_down = NULL;
1134 Debug( pcache_debug, "Added query expires at %ld\n",
1135 (long) new_cached_query->expiry_time, 0, 0 );
1137 new_cached_query->scope = query->scope;
1138 new_cached_query->filter = query->filter;
1139 new_cached_query->first = first = filter_first( query->filter );
1141 qb.base = query->base;
1143 /* Adding a query */
1144 Debug( pcache_debug, "Lock AQ index = %p\n",
1145 (void *) templ, 0, 0 );
1146 ldap_pvt_thread_rdwr_wlock(&templ->t_rwlock);
1147 qbase = avl_find( templ->qbase, &qb, pcache_dn_cmp );
1149 qbase = ch_calloc( 1, sizeof(Qbase) + qb.base.bv_len + 1 );
1150 qbase->base.bv_len = qb.base.bv_len;
1151 qbase->base.bv_val = (char *)(qbase+1);
1152 memcpy( qbase->base.bv_val, qb.base.bv_val, qb.base.bv_len );
1153 qbase->base.bv_val[qbase->base.bv_len] = '\0';
1154 avl_insert( &templ->qbase, qbase, pcache_dn_cmp, avl_dup_error );
1156 new_cached_query->next = templ->query;
1157 new_cached_query->prev = NULL;
1158 new_cached_query->qbase = qbase;
1159 rc = tavl_insert( &qbase->scopes[query->scope], new_cached_query,
1160 pcache_filter_cmp, avl_dup_error );
1163 if (templ->query == NULL)
1164 templ->query_last = new_cached_query;
1166 templ->query->prev = new_cached_query;
1167 templ->query = new_cached_query;
1168 templ->no_of_queries++;
1170 ch_free( new_cached_query );
1171 new_cached_query = find_filter( op, qbase->scopes[query->scope],
1172 query->filter, first );
1173 filter_free( query->filter );
1175 Debug( pcache_debug, "TEMPLATE %p QUERIES++ %d\n",
1176 (void *) templ, templ->no_of_queries, 0 );
1178 Debug( pcache_debug, "Unlock AQ index = %p \n",
1179 (void *) templ, 0, 0 );
1180 ldap_pvt_thread_rdwr_wunlock(&templ->t_rwlock);
1182 /* Adding on top of LRU list */
1184 ldap_pvt_thread_mutex_lock(&qm->lru_mutex);
1185 add_query_on_top(qm, new_cached_query);
1186 ldap_pvt_thread_mutex_unlock(&qm->lru_mutex);
1188 return rc == 0 ? new_cached_query : NULL;
1192 remove_from_template (CachedQuery* qc, QueryTemplate* template)
1194 if (!qc->prev && !qc->next) {
1195 template->query_last = template->query = NULL;
1196 } else if (qc->prev == NULL) {
1197 qc->next->prev = NULL;
1198 template->query = qc->next;
1199 } else if (qc->next == NULL) {
1200 qc->prev->next = NULL;
1201 template->query_last = qc->prev;
1203 qc->next->prev = qc->prev;
1204 qc->prev->next = qc->next;
1206 tavl_delete( &qc->qbase->scopes[qc->scope], qc, pcache_filter_cmp );
1207 qc->qbase->queries--;
1208 if ( qc->qbase->queries == 0 ) {
1209 avl_delete( &template->qbase, qc->qbase, pcache_dn_cmp );
1210 ch_free( qc->qbase );
1214 template->no_of_queries--;
1217 /* remove bottom query of LRU list from the query cache */
1219 * NOTE: slight change in functionality.
1221 * - if result->bv_val is NULL, the query at the bottom of the LRU
1223 * - otherwise, the query whose UUID is *result is removed
1224 * - if not found, result->bv_val is zeroed
1227 cache_replacement(query_manager* qm, struct berval *result)
1229 CachedQuery* bottom;
1230 QueryTemplate *temp;
1232 ldap_pvt_thread_mutex_lock(&qm->lru_mutex);
1233 if ( BER_BVISNULL( result ) ) {
1234 bottom = qm->lru_bottom;
1237 Debug ( pcache_debug,
1238 "Cache replacement invoked without "
1239 "any query in LRU list\n", 0, 0, 0 );
1240 ldap_pvt_thread_mutex_unlock(&qm->lru_mutex);
1245 for ( bottom = qm->lru_bottom;
1247 bottom = bottom->lru_up )
1249 if ( bvmatch( result, &bottom->q_uuid ) ) {
1255 Debug ( pcache_debug,
1256 "Could not find query with uuid=\"%s\""
1257 "in LRU list\n", result->bv_val, 0, 0 );
1258 ldap_pvt_thread_mutex_unlock(&qm->lru_mutex);
1259 BER_BVZERO( result );
1264 temp = bottom->qtemp;
1265 remove_query(qm, bottom);
1266 ldap_pvt_thread_mutex_unlock(&qm->lru_mutex);
1268 *result = bottom->q_uuid;
1269 bottom->q_uuid.bv_val = NULL;
1271 Debug( pcache_debug, "Lock CR index = %p\n", (void *) temp, 0, 0 );
1272 ldap_pvt_thread_rdwr_wlock(&temp->t_rwlock);
1273 remove_from_template(bottom, temp);
1274 Debug( pcache_debug, "TEMPLATE %p QUERIES-- %d\n",
1275 (void *) temp, temp->no_of_queries, 0 );
1276 Debug( pcache_debug, "Unlock CR index = %p\n", (void *) temp, 0, 0 );
1277 ldap_pvt_thread_rdwr_wunlock(&temp->t_rwlock);
1282 struct query_info *next;
1294 struct query_info *qi;
1297 if ( rs->sr_type != REP_SEARCH ) return 0;
1299 attr = attr_find( rs->sr_entry->e_attrs, ad_queryid );
1300 if ( attr == NULL ) return 0;
1302 for ( count = 0; !BER_BVISNULL( &attr->a_vals[count] ); count++ )
1304 assert( count > 0 );
1305 qi = op->o_tmpalloc( sizeof( struct query_info ), op->o_tmpmemctx );
1306 qi->next = op->o_callback->sc_private;
1307 op->o_callback->sc_private = qi;
1308 ber_dupbv_x( &qi->xdn, &rs->sr_entry->e_nname, op->o_tmpmemctx );
1309 qi->del = ( count == 1 );
1318 struct berval *query_uuid )
1320 struct query_info *qi, *qnext;
1321 char filter_str[ LDAP_LUTIL_UUIDSTR_BUFSIZE + STRLENOF( "(queryid=)" ) ];
1322 #ifdef LDAP_COMP_MATCH
1323 AttributeAssertion ava = { NULL, BER_BVNULL, NULL };
1325 AttributeAssertion ava = { NULL, BER_BVNULL };
1327 Filter filter = {LDAP_FILTER_EQUALITY};
1328 SlapReply sreply = {REP_RESULT};
1329 slap_callback cb = { NULL, remove_func, NULL, NULL };
1332 sreply.sr_entry = NULL;
1333 sreply.sr_nentries = 0;
1334 op->ors_filterstr.bv_len = snprintf(filter_str, sizeof(filter_str),
1335 "(%s=%s)", ad_queryid->ad_cname.bv_val, query_uuid->bv_val);
1336 filter.f_ava = &ava;
1337 filter.f_av_desc = ad_queryid;
1338 filter.f_av_value = *query_uuid;
1340 op->o_tag = LDAP_REQ_SEARCH;
1341 op->o_protocol = LDAP_VERSION3;
1342 op->o_callback = &cb;
1343 op->o_time = slap_get_time();
1344 op->o_do_not_cache = 1;
1346 op->o_req_dn = op->o_bd->be_suffix[0];
1347 op->o_req_ndn = op->o_bd->be_nsuffix[0];
1348 op->ors_scope = LDAP_SCOPE_SUBTREE;
1349 op->ors_deref = LDAP_DEREF_NEVER;
1350 op->ors_slimit = SLAP_NO_LIMIT;
1351 op->ors_tlimit = SLAP_NO_LIMIT;
1352 op->ors_filter = &filter;
1353 op->ors_filterstr.bv_val = filter_str;
1354 op->ors_filterstr.bv_len = strlen(filter_str);
1355 op->ors_attrs = NULL;
1356 op->ors_attrsonly = 0;
1358 op->o_bd->be_search( op, &sreply );
1360 for ( qi=cb.sc_private; qi; qi=qnext ) {
1363 op->o_req_dn = qi->xdn;
1364 op->o_req_ndn = qi->xdn;
1367 Debug( pcache_debug, "DELETING ENTRY TEMPLATE=%s\n",
1368 query_uuid->bv_val, 0, 0 );
1370 op->o_tag = LDAP_REQ_DELETE;
1372 if (op->o_bd->be_delete(op, &sreply) == LDAP_SUCCESS) {
1378 struct berval vals[2];
1380 vals[0] = *query_uuid;
1381 vals[1].bv_val = NULL;
1383 mod.sml_op = LDAP_MOD_DELETE;
1385 mod.sml_desc = ad_queryid;
1386 mod.sml_type = ad_queryid->ad_cname;
1387 mod.sml_values = vals;
1388 mod.sml_nvalues = NULL;
1389 mod.sml_next = NULL;
1390 Debug( pcache_debug,
1391 "REMOVING TEMP ATTR : TEMPLATE=%s\n",
1392 query_uuid->bv_val, 0, 0 );
1394 op->orm_modlist = &mod;
1396 op->o_bd->be_modify( op, &sreply );
1398 op->o_tmpfree( qi->xdn.bv_val, op->o_tmpmemctx );
1399 op->o_tmpfree( qi, op->o_tmpmemctx );
1406 AttributeName* attrs,
1415 struct berval *fstr,
1416 AttributeName** filter_attrs,
1418 int* filter_got_oc )
1420 AttributeDescription *ad;
1422 switch ( f->f_choice ) {
1423 case LDAP_FILTER_EQUALITY:
1425 sprintf( fstr->bv_val+fstr->bv_len, "(%s=)", ad->ad_cname.bv_val );
1426 fstr->bv_len += ad->ad_cname.bv_len + ( sizeof("(=)") - 1 );
1429 case LDAP_FILTER_GE:
1431 sprintf( fstr->bv_val+fstr->bv_len, "(%s>=)", ad->ad_cname.bv_val);
1432 fstr->bv_len += ad->ad_cname.bv_len + ( sizeof("(>=)") - 1 );
1435 case LDAP_FILTER_LE:
1437 sprintf( fstr->bv_val+fstr->bv_len, "(%s<=)", ad->ad_cname.bv_val);
1438 fstr->bv_len += ad->ad_cname.bv_len + ( sizeof("(<=)") - 1 );
1441 case LDAP_FILTER_APPROX:
1443 sprintf( fstr->bv_val+fstr->bv_len, "(%s~=)", ad->ad_cname.bv_val);
1444 fstr->bv_len += ad->ad_cname.bv_len + ( sizeof("(~=)") - 1 );
1447 case LDAP_FILTER_SUBSTRINGS:
1449 sprintf( fstr->bv_val+fstr->bv_len, "(%s=)", ad->ad_cname.bv_val );
1450 fstr->bv_len += ad->ad_cname.bv_len + ( sizeof("(=)") - 1 );
1453 case LDAP_FILTER_PRESENT:
1455 sprintf( fstr->bv_val+fstr->bv_len, "(%s=*)", ad->ad_cname.bv_val );
1456 fstr->bv_len += ad->ad_cname.bv_len + ( sizeof("(=*)") - 1 );
1459 case LDAP_FILTER_AND:
1460 case LDAP_FILTER_OR:
1461 case LDAP_FILTER_NOT: {
1463 sprintf( fstr->bv_val+fstr->bv_len, "(%c",
1464 f->f_choice == LDAP_FILTER_AND ? '&' :
1465 f->f_choice == LDAP_FILTER_OR ? '|' : '!' );
1466 fstr->bv_len += sizeof("(%") - 1;
1468 for ( f = f->f_list; f != NULL; f = f->f_next ) {
1469 rc = filter2template( op, f, fstr, filter_attrs, filter_cnt,
1473 sprintf( fstr->bv_val+fstr->bv_len, ")" );
1474 fstr->bv_len += sizeof(")") - 1;
1480 strcpy( fstr->bv_val, "(?=?)" );
1481 fstr->bv_len += sizeof("(?=?)")-1;
1485 if ( filter_attrs != NULL ) {
1486 *filter_attrs = (AttributeName *)op->o_tmprealloc(*filter_attrs,
1487 (*filter_cnt + 2)*sizeof(AttributeName), op->o_tmpmemctx);
1489 (*filter_attrs)[*filter_cnt].an_desc = ad;
1490 (*filter_attrs)[*filter_cnt].an_name = ad->ad_cname;
1491 (*filter_attrs)[*filter_cnt].an_oc = NULL;
1492 (*filter_attrs)[*filter_cnt].an_oc_exclude = 0;
1493 BER_BVZERO( &(*filter_attrs)[*filter_cnt+1].an_name );
1495 if ( ad == slap_schema.si_ad_objectClass )
1502 struct search_info {
1505 QueryTemplate *qtemp;
1506 AttributeName* save_attrs; /* original attributes, saved for response */
1514 remove_query_and_data(
1518 struct berval *uuid )
1520 query_manager* qm = cm->qm;
1522 qm->crfunc( qm, uuid );
1523 if ( !BER_BVISNULL( uuid ) ) {
1526 Debug( pcache_debug,
1527 "Removing query UUID %s\n",
1528 uuid->bv_val, 0, 0 );
1529 return_val = remove_query_data( op, rs, uuid );
1530 Debug( pcache_debug,
1531 "QUERY REMOVED, SIZE=%d\n",
1533 ldap_pvt_thread_mutex_lock( &cm->cache_mutex );
1534 cm->cur_entries -= return_val;
1535 cm->num_cached_queries--;
1536 Debug( pcache_debug,
1537 "STORED QUERIES = %lu\n",
1538 cm->num_cached_queries, 0, 0 );
1539 ldap_pvt_thread_mutex_unlock( &cm->cache_mutex );
1540 Debug( pcache_debug,
1541 "QUERY REMOVED, CACHE ="
1543 cm->cur_entries, 0, 0 );
1548 * Callback used to fetch queryid values based on entryUUID;
1549 * used by pcache_remove_entries_from_cache()
1552 fetch_queryid_cb( Operation *op, SlapReply *rs )
1556 /* only care about searchEntry responses */
1557 if ( rs->sr_type != REP_SEARCH ) {
1561 /* allow only one response per entryUUID */
1562 if ( op->o_callback->sc_private != NULL ) {
1568 /* copy all queryid values into callback's private data */
1569 a = attr_find( rs->sr_entry->e_attrs, ad_queryid );
1571 BerVarray vals = NULL;
1573 ber_bvarray_dup_x( &vals, a->a_nvals, op->o_tmpmemctx );
1574 op->o_callback->sc_private = (void *)vals;
1578 /* clear entry if required */
1579 if ( rs->sr_flags & REP_ENTRY_MUSTBEFREED ) {
1580 entry_free( rs->sr_entry );
1581 rs->sr_entry = NULL;
1582 rs->sr_flags ^= REP_ENTRY_MUSTBEFREED;
1589 * Call that allows to remove a set of entries from the cache,
1590 * by forcing the removal of all the related queries.
1593 pcache_remove_entries_from_cache(
1598 Connection conn = { 0 };
1599 OperationBuffer opbuf;
1601 slap_callback sc = { 0 };
1602 SlapReply rs = { REP_RESULT };
1604 char filtbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE + STRLENOF( "(entryUUID=)" ) ];
1605 #ifdef LDAP_COMP_MATCH
1606 AttributeAssertion ava = { NULL, BER_BVNULL, NULL };
1608 AttributeAssertion ava = { NULL, BER_BVNULL };
1610 AttributeName attrs[ 2 ] = { 0 };
1614 void *thrctx = ldap_pvt_thread_pool_context();
1616 connection_fake_init( &conn, &opbuf, thrctx );
1624 memset( &op->oq_search, 0, sizeof( op->oq_search ) );
1625 op->ors_scope = LDAP_SCOPE_SUBTREE;
1626 op->ors_deref = LDAP_DEREF_NEVER;
1627 f.f_choice = LDAP_FILTER_EQUALITY;
1629 ava.aa_desc = slap_schema.si_ad_entryUUID;
1630 op->ors_filter = &f;
1632 op->ors_tlimit = SLAP_NO_LIMIT;
1633 attrs[ 0 ].an_desc = ad_queryid;
1634 attrs[ 0 ].an_name = ad_queryid->ad_cname;
1635 op->ors_attrs = attrs;
1636 op->ors_attrsonly = 0;
1638 op->o_req_dn = cm->db.be_suffix[ 0 ];
1639 op->o_req_ndn = cm->db.be_nsuffix[ 0 ];
1641 op->o_tag = LDAP_REQ_SEARCH;
1642 op->o_protocol = LDAP_VERSION3;
1643 op->o_managedsait = SLAP_CONTROL_CRITICAL;
1645 op->o_dn = op->o_bd->be_rootdn;
1646 op->o_ndn = op->o_bd->be_rootndn;
1647 sc.sc_response = fetch_queryid_cb;
1648 op->o_callback = ≻
1650 for ( s = 0; !BER_BVISNULL( &UUIDs[ s ] ); s++ ) {
1651 BerVarray vals = NULL;
1653 op->ors_filterstr.bv_len = snprintf( filtbuf, sizeof( filtbuf ),
1654 "(entryUUID=%s)", UUIDs[ s ].bv_val );
1655 op->ors_filterstr.bv_val = filtbuf;
1656 ava.aa_value = UUIDs[ s ];
1658 rc = op->o_bd->be_search( op, &rs );
1659 if ( rc != LDAP_SUCCESS ) {
1663 vals = (BerVarray)op->o_callback->sc_private;
1664 if ( vals != NULL ) {
1667 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1668 struct berval val = vals[ i ];
1670 remove_query_and_data( op, &rs, cm, &val );
1672 if ( !BER_BVISNULL( &val ) && val.bv_val != vals[ i ].bv_val ) {
1673 ch_free( val.bv_val );
1677 ber_bvarray_free_x( vals, op->o_tmpmemctx );
1678 op->o_callback->sc_private = NULL;
1686 * Call that allows to remove a set of queries from the cache
1689 pcache_remove_entry_queries_from_cache(
1693 struct berval *uuid )
1695 Connection conn = { 0 };
1696 OperationBuffer opbuf;
1698 slap_callback sc = { 0 };
1699 SlapReply rs = { REP_RESULT };
1701 char filter_str[ LDAP_LUTIL_UUIDSTR_BUFSIZE + STRLENOF( "(queryid=)" ) ];
1702 #ifdef LDAP_COMP_MATCH
1703 AttributeAssertion ava = { NULL, BER_BVNULL, NULL };
1705 AttributeAssertion ava = { NULL, BER_BVNULL };
1707 AttributeName attrs[ 2 ] = { 0 };
1710 BerVarray vals = NULL;
1713 void *thrctx = ldap_pvt_thread_pool_context();
1715 connection_fake_init( &conn, &opbuf, thrctx );
1723 memset( &op->oq_search, 0, sizeof( op->oq_search ) );
1724 op->ors_scope = LDAP_SCOPE_BASE;
1725 op->ors_deref = LDAP_DEREF_NEVER;
1726 if ( uuid == NULL || BER_BVISNULL( uuid ) ) {
1727 BER_BVSTR( &op->ors_filterstr, "(objectClass=*)" );
1728 f.f_choice = LDAP_FILTER_PRESENT;
1729 f.f_desc = slap_schema.si_ad_objectClass;
1732 op->ors_filterstr.bv_len = snprintf( filter_str,
1733 sizeof( filter_str ), "(%s=%s)",
1734 ad_queryid->ad_cname.bv_val, uuid->bv_val );
1735 f.f_choice = LDAP_FILTER_EQUALITY;
1737 f.f_av_desc = ad_queryid;
1738 f.f_av_value = *uuid;
1740 op->ors_filter = &f;
1742 op->ors_tlimit = SLAP_NO_LIMIT;
1743 attrs[ 0 ].an_desc = ad_queryid;
1744 attrs[ 0 ].an_name = ad_queryid->ad_cname;
1745 op->ors_attrs = attrs;
1746 op->ors_attrsonly = 0;
1748 op->o_req_dn = *ndn;
1749 op->o_req_ndn = *ndn;
1751 op->o_tag = LDAP_REQ_SEARCH;
1752 op->o_protocol = LDAP_VERSION3;
1753 op->o_managedsait = SLAP_CONTROL_CRITICAL;
1755 op->o_dn = op->o_bd->be_rootdn;
1756 op->o_ndn = op->o_bd->be_rootndn;
1757 sc.sc_response = fetch_queryid_cb;
1758 op->o_callback = ≻
1760 rc = op->o_bd->be_search( op, &rs );
1761 if ( rc != LDAP_SUCCESS ) {
1765 vals = (BerVarray)op->o_callback->sc_private;
1766 if ( vals != NULL ) {
1769 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
1770 struct berval val = vals[ i ];
1772 remove_query_and_data( op, &rs, cm, &val );
1774 if ( !BER_BVISNULL( &val ) && val.bv_val != vals[ i ].bv_val ) {
1775 ch_free( val.bv_val );
1779 ber_bvarray_free_x( vals, op->o_tmpmemctx );
1782 return LDAP_SUCCESS;
1789 struct berval *query_uuid )
1791 struct search_info *si = op->o_callback->sc_private;
1792 slap_overinst *on = si->on;
1793 cache_manager *cm = on->on_bi.bi_private;
1796 struct berval crp_uuid;
1797 char uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ];
1798 Operation op_tmp = *op;
1800 query_uuid->bv_len = lutil_uuidstr(uuidbuf, sizeof(uuidbuf));
1801 ber_str2bv(uuidbuf, query_uuid->bv_len, 1, query_uuid);
1803 op_tmp.o_bd = &cm->db;
1804 op_tmp.o_dn = cm->db.be_rootdn;
1805 op_tmp.o_ndn = cm->db.be_rootndn;
1807 Debug( pcache_debug, "UUID for query being added = %s\n",
1810 for ( e=si->head; e; e=si->head ) {
1811 si->head = e->e_private;
1812 e->e_private = NULL;
1813 while ( cm->cur_entries > (cm->max_entries) ) {
1814 BER_BVZERO( &crp_uuid );
1815 remove_query_and_data( &op_tmp, rs, cm, &crp_uuid );
1818 return_val = merge_entry(&op_tmp, e, query_uuid);
1819 ldap_pvt_thread_mutex_lock(&cm->cache_mutex);
1820 cm->cur_entries += return_val;
1821 Debug( pcache_debug,
1822 "ENTRY ADDED/MERGED, CACHED ENTRIES=%d\n",
1823 cm->cur_entries, 0, 0 );
1825 ldap_pvt_thread_mutex_unlock(&cm->cache_mutex);
1832 pcache_op_cleanup( Operation *op, SlapReply *rs ) {
1833 slap_callback *cb = op->o_callback;
1834 struct search_info *si = cb->sc_private;
1835 if ( si->save_attrs != NULL ) {
1836 rs->sr_attrs = si->save_attrs;
1837 op->ors_attrs = si->save_attrs;
1839 op->o_callback = op->o_callback->sc_next;
1840 op->o_tmpfree( cb, op->o_tmpmemctx );
1841 return SLAP_CB_CONTINUE;
1849 struct search_info *si = op->o_callback->sc_private;
1850 slap_overinst *on = si->on;
1851 cache_manager *cm = on->on_bi.bi_private;
1852 query_manager* qm = cm->qm;
1854 if ( si->save_attrs != NULL ) {
1855 rs->sr_attrs = si->save_attrs;
1856 op->ors_attrs = si->save_attrs;
1859 if ( rs->sr_type == REP_SEARCH ) {
1861 /* If we haven't exceeded the limit for this query,
1862 * build a chain of answers to store. If we hit the
1863 * limit, empty the chain and ignore the rest.
1866 if ( si->count < si->max ) {
1868 e = entry_dup( rs->sr_entry );
1869 if ( !si->head ) si->head = e;
1870 if ( si->tail ) si->tail->e_private = e;
1875 for (;si->head; si->head=e) {
1876 e = si->head->e_private;
1877 si->head->e_private = NULL;
1878 entry_free(si->head);
1884 } else if ( rs->sr_type == REP_RESULT ) {
1886 ( si->qtemp->negttl && !si->count && !si->over &&
1887 rs->sr_err == LDAP_SUCCESS )) {
1888 CachedQuery *qc = qm->addfunc(op, qm, &si->query, si->qtemp,
1893 cache_entries( op, rs, &qc->q_uuid );
1894 ldap_pvt_thread_mutex_lock(&cm->cache_mutex);
1895 cm->num_cached_queries++;
1896 Debug( pcache_debug, "STORED QUERIES = %lu\n",
1897 cm->num_cached_queries, 0, 0 );
1898 ldap_pvt_thread_mutex_unlock(&cm->cache_mutex);
1900 /* If the consistency checker suspended itself,
1903 if ( cm->cc_paused ) {
1904 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
1905 if ( cm->cc_paused ) {
1907 ldap_pvt_runqueue_resched( &slapd_rq, cm->cc_arg, 0 );
1909 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
1911 } else if ( si->count ) {
1912 /* duplicate query, free it */
1914 for (;si->head; si->head=e) {
1915 e = si->head->e_private;
1916 si->head->e_private = NULL;
1917 entry_free(si->head);
1921 filter_free( si->query.filter );
1924 op->o_callback->sc_cleanup = pcache_op_cleanup;
1926 return SLAP_CB_CONTINUE;
1932 AttributeName** new_attrs,
1933 struct attr_set *attrs,
1934 AttributeName* filter_attrs,
1944 /* duplicate attrs */
1945 count = attrs->count + fattr_cnt;
1946 if ( !fattr_got_oc && !(attrs->flags & PC_GOT_OC)) {
1951 *new_attrs = (AttributeName*)ch_calloc( count + 1,
1952 sizeof(AttributeName) );
1953 for (i=0; i<attrs->count; i++) {
1954 (*new_attrs)[i].an_name = attrs->attrs[i].an_name;
1955 (*new_attrs)[i].an_desc = attrs->attrs[i].an_desc;
1957 BER_BVZERO( &(*new_attrs)[i].an_name );
1958 alluser = an_find(*new_attrs, &AllUser);
1959 allop = an_find(*new_attrs, &AllOper);
1962 for ( i=0; i<fattr_cnt; i++ ) {
1963 if ( an_find(*new_attrs, &filter_attrs[i].an_name ) ) {
1966 if ( is_at_operational(filter_attrs[i].an_desc->ad_type) ) {
1970 } else if ( alluser ) {
1973 (*new_attrs)[j].an_name = filter_attrs[i].an_name;
1974 (*new_attrs)[j].an_desc = filter_attrs[i].an_desc;
1975 (*new_attrs)[j].an_oc = NULL;
1976 (*new_attrs)[j].an_oc_exclude = 0;
1980 (*new_attrs)[j].an_name = slap_schema.si_ad_objectClass->ad_cname;
1981 (*new_attrs)[j].an_desc = slap_schema.si_ad_objectClass;
1982 (*new_attrs)[j].an_oc = NULL;
1983 (*new_attrs)[j].an_oc_exclude = 0;
1986 BER_BVZERO( &(*new_attrs)[j].an_name );
1991 /* NOTE: this is a quick workaround to let pcache minimally interact
1992 * with pagedResults. A more articulated solutions would be to
1993 * perform the remote query without control and cache all results,
1994 * performing the pagedResults search only within the client
1995 * and the proxy. This requires pcache to understand pagedResults. */
1997 pcache_chk_controls(
2001 const char *non = "";
2002 const char *stripped = "";
2004 switch( op->o_pagedresults ) {
2005 case SLAP_CONTROL_NONCRITICAL:
2007 stripped = "; stripped";
2010 case SLAP_CONTROL_CRITICAL:
2011 Debug( pcache_debug, "%s: "
2012 "%scritical pagedResults control "
2013 "disabled with proxy cache%s.\n",
2014 op->o_log_prefix, non, stripped );
2016 slap_remove_control( op, rs, slap_cids.sc_pagedResults, NULL );
2020 rs->sr_err = SLAP_CB_CONTINUE;
2032 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
2033 cache_manager *cm = on->on_bi.bi_private;
2034 query_manager* qm = cm->qm;
2038 AttributeName *filter_attrs = NULL;
2041 QueryTemplate *qtemp = NULL;
2044 CachedQuery *answerable = NULL;
2047 int fattr_got_oc = 0;
2049 struct berval tempstr;
2051 tempstr.bv_val = op->o_tmpalloc( op->ors_filterstr.bv_len+1, op->o_tmpmemctx );
2053 if ( filter2template( op, op->ors_filter, &tempstr, &filter_attrs,
2054 &fattr_cnt, &fattr_got_oc )) {
2055 op->o_tmpfree( tempstr.bv_val, op->o_tmpmemctx );
2056 return SLAP_CB_CONTINUE;
2059 Debug( pcache_debug, "query template of incoming query = %s\n",
2060 tempstr.bv_val, 0, 0 );
2062 /* FIXME: cannot cache/answer requests with pagedResults control */
2065 attr_set = get_attr_set(op->ors_attrs, qm, cm->numattrsets);
2067 query.filter = op->ors_filter;
2068 query.base = op->o_req_ndn;
2069 query.scope = op->ors_scope;
2071 /* check for query containment */
2072 if (attr_set > -1) {
2073 QueryTemplate *qt = qm->attr_sets[attr_set].templates;
2074 for (; qt; qt = qt->qtnext ) {
2075 /* find if template i can potentially answer tempstr */
2076 if (qt->querystr.bv_len != tempstr.bv_len ||
2077 strcasecmp( qt->querystr.bv_val, tempstr.bv_val ))
2081 Debug( pcache_debug, "Entering QC, querystr = %s\n",
2082 op->ors_filterstr.bv_val, 0, 0 );
2083 answerable = (*(qm->qcfunc))(op, qm, &query, qt);
2089 op->o_tmpfree( tempstr.bv_val, op->o_tmpmemctx );
2092 /* Need to clear the callbacks of the original operation,
2093 * in case there are other overlays */
2094 BackendDB *save_bd = op->o_bd;
2095 slap_callback *save_cb = op->o_callback;
2097 Debug( pcache_debug, "QUERY ANSWERABLE\n", 0, 0, 0 );
2098 op->o_tmpfree( filter_attrs, op->o_tmpmemctx );
2099 if ( BER_BVISNULL( &answerable->q_uuid )) {
2100 /* No entries cached, just an empty result set */
2102 send_ldap_result( op, rs );
2105 op->o_callback = NULL;
2106 i = cm->db.bd_info->bi_op_search( op, rs );
2108 ldap_pvt_thread_rdwr_runlock(&qtemp->t_rwlock);
2110 op->o_callback = save_cb;
2114 Debug( pcache_debug, "QUERY NOT ANSWERABLE\n", 0, 0, 0 );
2116 ldap_pvt_thread_mutex_lock(&cm->cache_mutex);
2117 if (cm->num_cached_queries >= cm->max_queries) {
2120 ldap_pvt_thread_mutex_unlock(&cm->cache_mutex);
2122 if (op->ors_attrsonly)
2127 struct search_info *si;
2129 Debug( pcache_debug, "QUERY CACHEABLE\n", 0, 0, 0 );
2130 query.filter = filter_dup(op->ors_filter, NULL);
2131 ldap_pvt_thread_rdwr_wlock(&qtemp->t_rwlock);
2132 if ( !qtemp->t_attrs.count ) {
2133 qtemp->t_attrs.count = add_filter_attrs(op,
2134 &qtemp->t_attrs.attrs,
2135 &qm->attr_sets[attr_set],
2136 filter_attrs, fattr_cnt, fattr_got_oc);
2138 ldap_pvt_thread_rdwr_wunlock(&qtemp->t_rwlock);
2140 cb = op->o_tmpalloc( sizeof(*cb) + sizeof(*si), op->o_tmpmemctx );
2141 cb->sc_response = pcache_response;
2142 cb->sc_cleanup = NULL;
2143 cb->sc_private = (cb+1);
2144 si = cb->sc_private;
2148 si->max = cm->num_entries_limit ;
2153 si->save_attrs = op->ors_attrs;
2155 op->ors_attrs = qtemp->t_attrs.attrs;
2157 if ( cm->response_cb == PCACHE_RESPONSE_CB_HEAD ) {
2158 cb->sc_next = op->o_callback;
2159 op->o_callback = cb;
2162 slap_callback **pcb;
2164 /* need to move the callback at the end, in case other
2165 * overlays are present, so that the final entry is
2166 * actually cached */
2168 for ( pcb = &op->o_callback; *pcb; pcb = &(*pcb)->sc_next );
2173 Debug( pcache_debug, "QUERY NOT CACHEABLE\n",
2177 op->o_tmpfree( filter_attrs, op->o_tmpmemctx );
2179 return SLAP_CB_CONTINUE;
2184 AttributeName* attrs,
2192 for ( ; attrs[count].an_name.bv_val; count++ );
2195 /* recognize a single "*" or a "1.1" */
2198 attrs = slap_anlist_all_user_attributes;
2200 } else if ( count == 1 && strcmp( attrs[0].an_name.bv_val, LDAP_NO_ATTRS ) == 0 ) {
2205 for ( i = 0; i < num; i++ ) {
2209 if ( count > qm->attr_sets[i].count ) {
2214 if ( !qm->attr_sets[i].count ) {
2220 for ( a2 = attrs; a2->an_name.bv_val; a2++ ) {
2221 if ( !an_find( qm->attr_sets[i].attrs, &a2->an_name ) ) {
2244 struct re_s *rtask = arg;
2245 slap_overinst *on = rtask->arg;
2246 cache_manager *cm = on->on_bi.bi_private;
2247 query_manager *qm = cm->qm;
2248 Connection conn = {0};
2249 OperationBuffer opbuf;
2252 SlapReply rs = {REP_RESULT};
2254 int return_val, pause = 1;
2255 QueryTemplate* templ;
2257 connection_fake_init( &conn, &opbuf, ctx );
2261 op->o_dn = cm->db.be_rootdn;
2262 op->o_ndn = cm->db.be_rootndn;
2266 for (templ = qm->templates; templ; templ=templ->qmnext) {
2267 query = templ->query_last;
2268 if ( query ) pause = 0;
2269 op->o_time = slap_get_time();
2270 while (query && (query->expiry_time < op->o_time)) {
2272 Debug( pcache_debug, "Lock CR index = %p\n",
2273 (void *) templ, 0, 0 );
2274 ldap_pvt_thread_rdwr_wlock(&templ->t_rwlock);
2275 if ( query == templ->query_last ) {
2277 remove_from_template(query, templ);
2278 Debug( pcache_debug, "TEMPLATE %p QUERIES-- %d\n",
2279 (void *) templ, templ->no_of_queries, 0 );
2280 Debug( pcache_debug, "Unlock CR index = %p\n",
2281 (void *) templ, 0, 0 );
2283 ldap_pvt_thread_rdwr_wunlock(&templ->t_rwlock);
2285 query = templ->query_last;
2288 ldap_pvt_thread_mutex_lock(&qm->lru_mutex);
2289 remove_query(qm, query);
2290 ldap_pvt_thread_mutex_unlock(&qm->lru_mutex);
2291 if ( BER_BVISNULL( &query->q_uuid ))
2294 return_val = remove_query_data(op, &rs, &query->q_uuid);
2295 Debug( pcache_debug, "STALE QUERY REMOVED, SIZE=%d\n",
2297 ldap_pvt_thread_mutex_lock(&cm->cache_mutex);
2298 cm->cur_entries -= return_val;
2299 cm->num_cached_queries--;
2300 Debug( pcache_debug, "STORED QUERIES = %lu\n",
2301 cm->num_cached_queries, 0, 0 );
2302 ldap_pvt_thread_mutex_unlock(&cm->cache_mutex);
2303 Debug( pcache_debug,
2304 "STALE QUERY REMOVED, CACHE ="
2306 cm->cur_entries, 0, 0 );
2308 query = templ->query_last;
2311 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
2312 if ( ldap_pvt_runqueue_isrunning( &slapd_rq, rtask )) {
2313 ldap_pvt_runqueue_stoptask( &slapd_rq, rtask );
2315 /* If there were no queries, defer processing for a while */
2316 cm->cc_paused = pause;
2317 ldap_pvt_runqueue_resched( &slapd_rq, rtask, pause );
2319 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
2324 #define MAX_ATTR_SETS 500
2334 static ConfigDriver pc_cf_gen;
2335 static ConfigLDAPadd pc_ldadd;
2336 static ConfigCfAdd pc_cfadd;
2338 static ConfigTable pccfg[] = {
2339 { "proxycache", "backend> <max_entries> <numattrsets> <entry limit> "
2341 6, 6, 0, ARG_MAGIC|ARG_NO_DELETE|PC_MAIN, pc_cf_gen,
2342 "( OLcfgOvAt:2.1 NAME 'olcProxyCache' "
2343 "DESC 'ProxyCache basic parameters' "
2344 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
2345 { "proxyattrset", "index> <attributes...",
2346 2, 0, 0, ARG_MAGIC|PC_ATTR, pc_cf_gen,
2347 "( OLcfgOvAt:2.2 NAME 'olcProxyAttrset' "
2348 "DESC 'A set of attributes to cache' "
2349 "SYNTAX OMsDirectoryString )", NULL, NULL },
2350 { "proxytemplate", "filter> <attrset-index> <TTL> <negTTL",
2351 4, 5, 0, ARG_MAGIC|PC_TEMP, pc_cf_gen,
2352 "( OLcfgOvAt:2.3 NAME 'olcProxyTemplate' "
2353 "DESC 'Filter template, attrset, cache TTL, optional negative TTL' "
2354 "SYNTAX OMsDirectoryString )", NULL, NULL },
2355 { "response-callback", "head|tail(default)",
2356 2, 2, 0, ARG_MAGIC|PC_RESP, pc_cf_gen,
2357 "( OLcfgOvAt:2.4 NAME 'olcProxyResponseCB' "
2358 "DESC 'Response callback position in overlay stack' "
2359 "SYNTAX OMsDirectoryString )", NULL, NULL },
2360 { "proxyCacheQueries", "queries",
2361 2, 2, 0, ARG_INT|ARG_MAGIC|PC_QUERIES, pc_cf_gen,
2362 "( OLcfgOvAt:2.5 NAME 'olcProxyCacheQueries' "
2363 "DESC 'Maximum number of queries to cache' "
2364 "SYNTAX OMsInteger )", NULL, NULL },
2365 { "proxySaveQueries", "TRUE|FALSE",
2366 2, 2, 0, ARG_ON_OFF|ARG_OFFSET, (void *)offsetof(cache_manager, save_queries),
2367 "( OLcfgOvAt:2.6 NAME 'olcProxySaveQueries' "
2368 "DESC 'Save cached queries for hot restart' "
2369 "SYNTAX OMsBoolean )", NULL, NULL },
2371 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
2374 static ConfigOCs pcocs[] = {
2375 { "( OLcfgOvOc:2.1 "
2376 "NAME 'olcPcacheConfig' "
2377 "DESC 'ProxyCache configuration' "
2378 "SUP olcOverlayConfig "
2379 "MUST ( olcProxyCache $ olcProxyAttrset $ olcProxyTemplate ) "
2380 "MAY ( olcProxyResponseCB $ olcProxyCacheQueries $ olcProxySaveQueries ) )",
2381 Cft_Overlay, pccfg, NULL, pc_cfadd },
2382 { "( OLcfgOvOc:2.2 "
2383 "NAME 'olcPcacheDatabase' "
2384 "DESC 'Cache database configuration' "
2385 "AUXILIARY )", Cft_Misc, pccfg, pc_ldadd },
2390 pc_ldadd( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
2395 if ( p->ce_type != Cft_Overlay || !p->ce_bi ||
2396 p->ce_bi->bi_cf_ocs != pcocs )
2397 return LDAP_CONSTRAINT_VIOLATION;
2399 on = (slap_overinst *)p->ce_bi;
2400 cm = on->on_bi.bi_private;
2402 return LDAP_SUCCESS;
2406 pc_cfadd( Operation *op, SlapReply *rs, Entry *p, ConfigArgs *ca )
2408 CfEntryInfo *pe = p->e_private;
2409 slap_overinst *on = (slap_overinst *)pe->ce_bi;
2410 cache_manager *cm = on->on_bi.bi_private;
2413 /* FIXME: should not hardcode "olcDatabase" here */
2414 bv.bv_len = sprintf( ca->cr_msg, "olcDatabase=%s", cm->db.bd_info->bi_type );
2415 bv.bv_val = ca->cr_msg;
2418 /* We can only create this entry if the database is table-driven
2420 if ( cm->db.bd_info->bi_cf_ocs )
2421 config_build_entry( op, rs, pe, ca, &bv, cm->db.bd_info->bi_cf_ocs,
2428 pc_cf_gen( ConfigArgs *c )
2430 slap_overinst *on = (slap_overinst *)c->bi;
2431 cache_manager* cm = on->on_bi.bi_private;
2432 query_manager* qm = cm->qm;
2433 QueryTemplate* temp;
2434 AttributeName* attr_name;
2435 AttributeName* attrarray;
2436 const char* text=NULL;
2441 if ( c->op == SLAP_CONFIG_EMIT ) {
2445 bv.bv_len = snprintf( c->cr_msg, sizeof( c->cr_msg ), "%s %d %d %d %ld",
2446 cm->db.bd_info->bi_type, cm->max_entries, cm->numattrsets,
2447 cm->num_entries_limit, cm->cc_period );
2448 bv.bv_val = c->cr_msg;
2449 value_add_one( &c->rvalue_vals, &bv );
2452 for (i=0; i<cm->numattrsets; i++) {
2453 if ( !qm->attr_sets[i].count ) continue;
2455 bv.bv_len = snprintf( c->cr_msg, sizeof( c->cr_msg ), "%d", i );
2457 /* count the attr length */
2458 for ( attr_name = qm->attr_sets[i].attrs;
2459 attr_name->an_name.bv_val; attr_name++ )
2460 bv.bv_len += attr_name->an_name.bv_len + 1;
2462 bv.bv_val = ch_malloc( bv.bv_len+1 );
2463 ptr = lutil_strcopy( bv.bv_val, c->cr_msg );
2464 for ( attr_name = qm->attr_sets[i].attrs;
2465 attr_name->an_name.bv_val; attr_name++ ) {
2467 ptr = lutil_strcopy( ptr, attr_name->an_name.bv_val );
2469 ber_bvarray_add( &c->rvalue_vals, &bv );
2471 if ( !c->rvalue_vals )
2475 for (temp=qm->templates; temp; temp=temp->qmnext) {
2476 if ( temp->negttl ) {
2477 bv.bv_len = snprintf( c->cr_msg, sizeof( c->cr_msg ),
2479 temp->attr_set_index,
2483 bv.bv_len = snprintf( c->cr_msg, sizeof( c->cr_msg ), " %d %ld",
2484 temp->attr_set_index,
2487 bv.bv_len += temp->querystr.bv_len + 2;
2488 bv.bv_val = ch_malloc( bv.bv_len+1 );
2491 ptr = lutil_strcopy( ptr, temp->querystr.bv_val );
2493 strcpy( ptr, c->cr_msg );
2494 ber_bvarray_add( &c->rvalue_vals, &bv );
2496 if ( !c->rvalue_vals )
2500 if ( cm->response_cb == PCACHE_RESPONSE_CB_HEAD ) {
2501 BER_BVSTR( &bv, "head" );
2503 BER_BVSTR( &bv, "tail" );
2505 value_add_one( &c->rvalue_vals, &bv );
2508 c->value_int = cm->max_queries;
2512 } else if ( c->op == LDAP_MOD_DELETE ) {
2513 return 1; /* FIXME */
2525 if ( cm->numattrsets > 0 ) {
2526 snprintf( c->cr_msg, sizeof( c->cr_msg ), "\"proxycache\" directive already provided" );
2527 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
2531 if ( lutil_atoi( &cm->numattrsets, c->argv[3] ) != 0 ) {
2532 snprintf( c->cr_msg, sizeof( c->cr_msg ), "unable to parse num attrsets=\"%s\" (arg #3)",
2534 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
2537 if ( cm->numattrsets <= 0 ) {
2538 snprintf( c->cr_msg, sizeof( c->cr_msg ), "numattrsets (arg #3) must be positive" );
2539 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
2542 if ( cm->numattrsets > MAX_ATTR_SETS ) {
2543 snprintf( c->cr_msg, sizeof( c->cr_msg ), "numattrsets (arg #3) must be <= %d", MAX_ATTR_SETS );
2544 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
2548 if ( !backend_db_init( c->argv[1], &cm->db, -1, NULL )) {
2549 snprintf( c->cr_msg, sizeof( c->cr_msg ), "unknown backend type (arg #1)" );
2550 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
2554 if ( lutil_atoi( &cm->max_entries, c->argv[2] ) != 0 ) {
2555 snprintf( c->cr_msg, sizeof( c->cr_msg ), "unable to parse max entries=\"%s\" (arg #2)",
2557 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
2560 if ( cm->max_entries <= 0 ) {
2561 snprintf( c->cr_msg, sizeof( c->cr_msg ), "max entries (arg #2) must be positive.\n" );
2562 Debug( LDAP_DEBUG_CONFIG, "%s: %s\n", c->log, c->cr_msg, 0 );
2566 if ( lutil_atoi( &cm->num_entries_limit, c->argv[4] ) != 0 ) {
2567 snprintf( c->cr_msg, sizeof( c->cr_msg ), "unable to parse entry limit=\"%s\" (arg #4)",
2569 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
2572 if ( cm->num_entries_limit <= 0 ) {
2573 snprintf( c->cr_msg, sizeof( c->cr_msg ), "entry limit (arg #4) must be positive" );
2574 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
2577 if ( cm->num_entries_limit > cm->max_entries ) {
2578 snprintf( c->cr_msg, sizeof( c->cr_msg ), "entry limit (arg #4) must be less than max entries %d (arg #2)", cm->max_entries );
2579 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
2583 if ( lutil_parse_time( c->argv[5], &t ) != 0 ) {
2584 snprintf( c->cr_msg, sizeof( c->cr_msg ), "unable to parse period=\"%s\" (arg #5)",
2586 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
2589 cm->cc_period = (time_t)t;
2590 Debug( pcache_debug,
2591 "Total # of attribute sets to be cached = %d.\n",
2592 cm->numattrsets, 0, 0 );
2593 qm->attr_sets = ( struct attr_set * )ch_calloc( cm->numattrsets,
2594 sizeof( struct attr_set ) );
2597 if ( cm->numattrsets == 0 ) {
2598 snprintf( c->cr_msg, sizeof( c->cr_msg ), "\"proxycache\" directive not provided yet" );
2599 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
2602 if ( lutil_atoi( &num, c->argv[1] ) != 0 ) {
2603 snprintf( c->cr_msg, sizeof( c->cr_msg ), "unable to parse attrset #=\"%s\"",
2605 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
2609 if ( num < 0 || num >= cm->numattrsets ) {
2610 snprintf( c->cr_msg, sizeof( c->cr_msg ), "attrset index %d out of bounds (must be %s%d)",
2611 num, cm->numattrsets > 1 ? "0->" : "", cm->numattrsets - 1 );
2612 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
2615 qm->attr_sets[num].flags |= PC_CONFIGURED;
2616 if ( c->argc == 2 ) {
2618 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2619 "need an explicit attr in attrlist; use \"*\" to indicate all attrs" );
2620 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
2623 } else if ( c->argc == 3 ) {
2624 if ( strcmp( c->argv[2], LDAP_ALL_USER_ATTRIBUTES ) == 0 ) {
2625 qm->attr_sets[num].count = 1;
2626 qm->attr_sets[num].attrs = (AttributeName*)ch_calloc( 2,
2627 sizeof( AttributeName ) );
2628 BER_BVSTR( &qm->attr_sets[num].attrs[0].an_name, LDAP_ALL_USER_ATTRIBUTES );
2631 } else if ( strcmp( c->argv[2], LDAP_ALL_OPERATIONAL_ATTRIBUTES ) == 0 ) {
2632 qm->attr_sets[num].count = 1;
2633 qm->attr_sets[num].attrs = (AttributeName*)ch_calloc( 2,
2634 sizeof( AttributeName ) );
2635 BER_BVSTR( &qm->attr_sets[num].attrs[0].an_name, LDAP_ALL_OPERATIONAL_ATTRIBUTES );
2638 } else if ( strcmp( c->argv[2], LDAP_NO_ATTRS ) == 0 ) {
2641 /* else: fallthru */
2643 } else if ( c->argc == 4 ) {
2644 if ( ( strcmp( c->argv[2], LDAP_ALL_USER_ATTRIBUTES ) == 0 && strcmp( c->argv[3], LDAP_ALL_OPERATIONAL_ATTRIBUTES ) == 0 )
2645 || ( strcmp( c->argv[2], LDAP_ALL_OPERATIONAL_ATTRIBUTES ) == 0 && strcmp( c->argv[3], LDAP_ALL_USER_ATTRIBUTES ) == 0 ) )
2647 qm->attr_sets[num].count = 2;
2648 qm->attr_sets[num].attrs = (AttributeName*)ch_calloc( 3,
2649 sizeof( AttributeName ) );
2650 BER_BVSTR( &qm->attr_sets[num].attrs[0].an_name, LDAP_ALL_USER_ATTRIBUTES );
2651 BER_BVSTR( &qm->attr_sets[num].attrs[1].an_name, LDAP_ALL_OPERATIONAL_ATTRIBUTES );
2654 /* else: fallthru */
2657 if ( c->argc > 2 ) {
2658 int all_user = 0, all_op = 0;
2660 qm->attr_sets[num].count = c->argc - 2;
2661 qm->attr_sets[num].attrs = (AttributeName*)ch_calloc( c->argc - 1,
2662 sizeof( AttributeName ) );
2663 attr_name = qm->attr_sets[num].attrs;
2664 for ( i = 2; i < c->argc; i++ ) {
2665 attr_name->an_desc = NULL;
2666 if ( strcmp( c->argv[i], LDAP_NO_ATTRS ) == 0 ) {
2667 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2668 "invalid attr #%d \"%s\" in attrlist",
2669 i - 2, c->argv[i] );
2670 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
2671 ch_free( qm->attr_sets[num].attrs );
2672 qm->attr_sets[num].attrs = NULL;
2673 qm->attr_sets[num].count = 0;
2676 if ( strcmp( c->argv[i], LDAP_ALL_USER_ATTRIBUTES ) == 0 ) {
2678 BER_BVSTR( &attr_name->an_name, LDAP_ALL_USER_ATTRIBUTES );
2679 } else if ( strcmp( c->argv[i], LDAP_ALL_OPERATIONAL_ATTRIBUTES ) == 0 ) {
2681 BER_BVSTR( &attr_name->an_name, LDAP_ALL_OPERATIONAL_ATTRIBUTES );
2683 if ( slap_str2ad( c->argv[i], &attr_name->an_desc, &text ) ) {
2684 strcpy( c->cr_msg, text );
2685 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
2686 ch_free( qm->attr_sets[num].attrs );
2687 qm->attr_sets[num].attrs = NULL;
2688 qm->attr_sets[num].count = 0;
2691 attr_name->an_name = attr_name->an_desc->ad_cname;
2693 attr_name->an_oc = NULL;
2694 attr_name->an_oc_exclude = 0;
2695 if ( attr_name->an_desc == slap_schema.si_ad_objectClass )
2696 qm->attr_sets[num].flags |= PC_GOT_OC;
2698 BER_BVZERO( &attr_name->an_name );
2701 /* warn if list contains both "*" and "+" */
2702 if ( i > 4 && all_user && all_op ) {
2703 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2704 "warning: attribute list contains \"*\" and \"+\"" );
2705 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
2710 if ( cm->numattrsets == 0 ) {
2711 snprintf( c->cr_msg, sizeof( c->cr_msg ), "\"proxycache\" directive not provided yet" );
2712 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
2715 if ( lutil_atoi( &i, c->argv[2] ) != 0 ) {
2716 snprintf( c->cr_msg, sizeof( c->cr_msg ), "unable to parse template #=\"%s\"",
2718 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
2722 if ( i < 0 || i >= cm->numattrsets ||
2723 !(qm->attr_sets[i].flags & PC_CONFIGURED )) {
2724 snprintf( c->cr_msg, sizeof( c->cr_msg ), "template index %d invalid (%s%d)",
2725 i, cm->numattrsets > 1 ? "0->" : "", cm->numattrsets - 1 );
2726 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
2729 temp = ch_calloc( 1, sizeof( QueryTemplate ));
2730 temp->qmnext = qm->templates;
2731 qm->templates = temp;
2732 ldap_pvt_thread_rdwr_init( &temp->t_rwlock );
2733 temp->query = temp->query_last = NULL;
2734 if ( lutil_parse_time( c->argv[3], &t ) != 0 ) {
2735 snprintf( c->cr_msg, sizeof( c->cr_msg ), "unable to parse template ttl=\"%s\"",
2737 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
2740 temp->ttl = (time_t)t;
2741 if ( c->argc == 5 ) {
2742 if ( lutil_parse_time( c->argv[4], &t ) != 0 ) {
2743 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2744 "unable to parse template negttl=\"%s\"",
2746 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
2749 temp->negttl = (time_t)t;
2754 temp->no_of_queries = 0;
2756 ber_str2bv( c->argv[1], 0, 1, &temp->querystr );
2757 Debug( pcache_debug, "Template:\n", 0, 0, 0 );
2758 Debug( pcache_debug, " query template: %s\n",
2759 temp->querystr.bv_val, 0, 0 );
2760 temp->attr_set_index = i;
2761 qm->attr_sets[i].flags |= PC_REFERENCED;
2762 temp->qtnext = qm->attr_sets[i].templates;
2763 qm->attr_sets[i].templates = temp;
2764 Debug( pcache_debug, " attributes: \n", 0, 0, 0 );
2765 if ( ( attrarray = qm->attr_sets[i].attrs ) != NULL ) {
2766 for ( i=0; attrarray[i].an_name.bv_val; i++ )
2767 Debug( pcache_debug, "\t%s\n",
2768 attrarray[i].an_name.bv_val, 0, 0 );
2772 if ( strcasecmp( c->argv[1], "head" ) == 0 ) {
2773 cm->response_cb = PCACHE_RESPONSE_CB_HEAD;
2775 } else if ( strcasecmp( c->argv[1], "tail" ) == 0 ) {
2776 cm->response_cb = PCACHE_RESPONSE_CB_TAIL;
2779 snprintf( c->cr_msg, sizeof( c->cr_msg ), "unknown specifier" );
2780 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
2785 if ( c->value_int <= 0 ) {
2786 snprintf( c->cr_msg, sizeof( c->cr_msg ), "max queries must be positive" );
2787 Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
2790 cm->max_queries = c->value_int;
2805 slap_overinst *on = (slap_overinst *)be->bd_info;
2806 cache_manager* cm = on->on_bi.bi_private;
2808 /* Something for the cache database? */
2809 if ( cm->db.bd_info && cm->db.bd_info->bi_db_config )
2810 return cm->db.bd_info->bi_db_config( &cm->db, fname, lineno,
2812 return SLAP_CONF_UNKNOWN;
2820 slap_overinst *on = (slap_overinst *)be->bd_info;
2824 cm = (cache_manager *)ch_malloc(sizeof(cache_manager));
2825 on->on_bi.bi_private = cm;
2827 qm = (query_manager*)ch_malloc(sizeof(query_manager));
2830 SLAP_DBFLAGS(&cm->db) |= SLAP_DBFLAG_NO_SCHEMA_CHECK;
2831 cm->db.be_private = NULL;
2832 cm->db.be_pcl_mutexp = &cm->db.be_pcl_mutex;
2834 cm->numattrsets = 0;
2835 cm->num_entries_limit = 5;
2836 cm->num_cached_queries = 0;
2837 cm->max_entries = 0;
2838 cm->cur_entries = 0;
2839 cm->max_queries = 10000;
2840 cm->save_queries = 0;
2841 cm->response_cb = PCACHE_RESPONSE_CB_TAIL;
2842 cm->cc_period = 1000;
2845 qm->attr_sets = NULL;
2846 qm->templates = NULL;
2848 qm->lru_bottom = NULL;
2850 qm->qcfunc = query_containment;
2851 qm->crfunc = cache_replacement;
2852 qm->addfunc = add_query;
2853 ldap_pvt_thread_mutex_init(&qm->lru_mutex);
2855 ldap_pvt_thread_mutex_init(&cm->cache_mutex);
2860 pcache_cachedquery_open_cb( Operation *op, SlapReply *rs )
2862 assert( op->o_tag == LDAP_REQ_SEARCH );
2864 if ( rs->sr_type == REP_SEARCH ) {
2867 a = attr_find( rs->sr_entry->e_attrs, ad_cachedQueryURL );
2871 assert( a->a_nvals != NULL );
2873 valsp = op->o_callback->sc_private;
2874 assert( *valsp == NULL );
2876 ber_bvarray_dup_x( valsp, a->a_nvals, op->o_tmpmemctx );
2888 slap_overinst *on = (slap_overinst *)be->bd_info;
2889 cache_manager *cm = on->on_bi.bi_private;
2890 query_manager* qm = cm->qm;
2891 int i, ncf = 0, rf = 0, nrf = 0, rc = 0;
2893 /* check attr sets */
2894 for ( i = 0; i < cm->numattrsets; i++) {
2895 if ( !( qm->attr_sets[i].flags & PC_CONFIGURED ) ) {
2896 if ( qm->attr_sets[i].flags & PC_REFERENCED ) {
2897 Debug( LDAP_DEBUG_CONFIG, "pcache: attr set #%d not configured but referenced.\n", i, 0, 0 );
2901 Debug( LDAP_DEBUG_CONFIG, "pcache: warning, attr set #%d not configured.\n", i, 0, 0 );
2905 } else if ( !( qm->attr_sets[i].flags & PC_REFERENCED ) ) {
2906 Debug( LDAP_DEBUG_CONFIG, "pcache: attr set #%d configured but not referenced.\n", i, 0, 0 );
2911 if ( ncf || rf || nrf ) {
2912 Debug( LDAP_DEBUG_CONFIG, "pcache: warning, %d attr sets configured but not referenced.\n", nrf, 0, 0 );
2913 Debug( LDAP_DEBUG_CONFIG, "pcache: warning, %d attr sets not configured.\n", ncf, 0, 0 );
2914 Debug( LDAP_DEBUG_CONFIG, "pcache: %d attr sets not configured but referenced.\n", rf, 0, 0 );
2921 /* need to inherit something from the original database... */
2922 cm->db.be_def_limit = be->be_def_limit;
2923 cm->db.be_limits = be->be_limits;
2924 cm->db.be_acl = be->be_acl;
2925 cm->db.be_dfltaccess = be->be_dfltaccess;
2927 if ( SLAP_DBMONITORING( be ) ) {
2928 SLAP_DBFLAGS( &cm->db ) |= SLAP_DBFLAG_MONITORING;
2931 SLAP_DBFLAGS( &cm->db ) &= ~SLAP_DBFLAG_MONITORING;
2934 rc = backend_startup_one( &cm->db, NULL );
2936 /* There is no runqueue in TOOL mode */
2937 if ( slapMode & SLAP_SERVER_MODE ) {
2938 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
2939 ldap_pvt_runqueue_insert( &slapd_rq, cm->cc_period,
2940 consistency_check, on,
2941 "pcache_consistency", be->be_suffix[0].bv_val );
2942 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
2944 /* Cached database must have the rootdn */
2945 if ( BER_BVISNULL( &cm->db.be_rootndn )
2946 || BER_BVISEMPTY( &cm->db.be_rootndn ) )
2948 Debug( LDAP_DEBUG_ANY, "pcache_db_open(): "
2949 "underlying database of type \"%s\"\n"
2950 " serving naming context \"%s\"\n"
2951 " has no \"rootdn\", required by \"proxycache\".\n",
2952 on->on_info->oi_orig->bi_type,
2953 cm->db.be_suffix[0].bv_val, 0 );
2957 if ( cm->save_queries ) {
2958 void *thrctx = ldap_pvt_thread_pool_context();
2959 Connection conn = { 0 };
2960 OperationBuffer opbuf;
2962 slap_callback cb = { 0 };
2963 SlapReply rs = { 0 };
2964 BerVarray vals = NULL;
2966 AttributeName attrs[ 2 ] = { 0 };
2968 connection_fake_init( &conn, &opbuf, thrctx );
2973 op->o_tag = LDAP_REQ_SEARCH;
2974 op->o_protocol = LDAP_VERSION3;
2975 cb.sc_response = pcache_cachedquery_open_cb;
2976 cb.sc_private = &vals;
2977 op->o_callback = &cb;
2978 op->o_time = slap_get_time();
2979 op->o_do_not_cache = 1;
2980 op->o_managedsait = SLAP_CONTROL_CRITICAL;
2982 op->o_dn = cm->db.be_rootdn;
2983 op->o_ndn = cm->db.be_rootndn;
2984 op->o_req_dn = cm->db.be_suffix[ 0 ];
2985 op->o_req_ndn = cm->db.be_nsuffix[ 0 ];
2987 op->ors_scope = LDAP_SCOPE_BASE;
2988 op->ors_deref = LDAP_DEREF_NEVER;
2990 op->ors_tlimit = SLAP_NO_LIMIT;
2991 ber_str2bv( "(cachedQueryURL=*)", 0, 0, &op->ors_filterstr );
2992 f.f_choice = LDAP_FILTER_PRESENT;
2993 f.f_desc = ad_cachedQueryURL;
2994 op->ors_filter = &f;
2995 attrs[ 0 ].an_desc = ad_cachedQueryURL;
2996 attrs[ 0 ].an_name = ad_cachedQueryURL->ad_cname;
2997 op->ors_attrs = attrs;
2998 op->ors_attrsonly = 0;
3000 rc = op->o_bd->be_search( op, &rs );
3001 if ( rc == LDAP_SUCCESS && vals != NULL ) {
3004 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
3005 if ( url2query( vals[ i ].bv_val, op, qm ) == 0 ) {
3006 cm->num_cached_queries++;
3010 ber_bvarray_free_x( vals, op->o_tmpmemctx );
3022 pcache_free_qbase( void *v )
3028 tavl_free( qb->scopes[i], NULL );
3038 slap_overinst *on = (slap_overinst *)be->bd_info;
3039 cache_manager *cm = on->on_bi.bi_private;
3040 query_manager *qm = cm->qm;
3044 if ( cm->save_queries ) {
3046 BerVarray vals = NULL;
3049 Connection conn = { 0 };
3050 OperationBuffer opbuf;
3052 slap_callback cb = { 0 };
3054 SlapReply rs = { REP_RESULT };
3055 Modifications mod = { 0 };
3057 thrctx = ldap_pvt_thread_pool_context();
3059 connection_fake_init( &conn, &opbuf, thrctx );
3062 if ( qm->templates != NULL ) {
3063 for ( tm = qm->templates; tm != NULL; tm = tm->qmnext ) {
3064 for ( qc = tm->query; qc; qc = qc->next ) {
3067 if ( query2url( op, qc, &bv ) == 0 ) {
3068 ber_bvarray_add_x( &vals, &bv, op->o_tmpmemctx );
3075 op->o_dn = cm->db.be_rootdn;
3076 op->o_ndn = cm->db.be_rootndn;
3078 op->o_tag = LDAP_REQ_MODIFY;
3079 op->o_protocol = LDAP_VERSION3;
3080 cb.sc_response = slap_null_cb;
3081 op->o_callback = &cb;
3082 op->o_time = slap_get_time();
3083 op->o_do_not_cache = 1;
3084 op->o_managedsait = SLAP_CONTROL_CRITICAL;
3086 op->o_req_dn = op->o_bd->be_suffix[0];
3087 op->o_req_ndn = op->o_bd->be_nsuffix[0];
3089 mod.sml_op = LDAP_MOD_REPLACE;
3091 mod.sml_desc = ad_cachedQueryURL;
3092 mod.sml_type = ad_cachedQueryURL->ad_cname;
3093 mod.sml_values = vals;
3094 mod.sml_nvalues = NULL;
3095 mod.sml_next = NULL;
3096 Debug( pcache_debug,
3097 "%sSETTING CACHED QUERY URLS\n",
3098 vals == NULL ? "RE" : "", 0, 0 );
3100 op->orm_modlist = &mod;
3102 op->o_bd->be_modify( op, &rs );
3104 ber_bvarray_free_x( vals, op->o_tmpmemctx );
3107 /* cleanup stuff inherited from the original database... */
3108 cm->db.be_limits = NULL;
3109 cm->db.be_acl = NULL;
3111 /* stop the thread ... */
3113 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
3114 if ( ldap_pvt_runqueue_isrunning( &slapd_rq, cm->cc_arg ) ) {
3115 ldap_pvt_runqueue_stoptask( &slapd_rq, cm->cc_arg );
3117 ldap_pvt_runqueue_remove( &slapd_rq, cm->cc_arg );
3118 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
3121 if ( cm->db.bd_info->bi_db_close ) {
3122 rc = cm->db.bd_info->bi_db_close( &cm->db, NULL );
3124 while ( (tm = qm->templates) != NULL ) {
3125 CachedQuery *qc, *qn;
3126 qm->templates = tm->qmnext;
3127 for ( qc = tm->query; qc; qc = qn ) {
3131 avl_free( tm->qbase, pcache_free_qbase );
3132 free( tm->querystr.bv_val );
3133 ldap_pvt_thread_rdwr_destroy( &tm->t_rwlock );
3134 free( tm->t_attrs.attrs );
3138 for ( i=0; i<cm->numattrsets; i++ ) {
3139 free( qm->attr_sets[i].attrs );
3141 free( qm->attr_sets );
3142 qm->attr_sets = NULL;
3153 slap_overinst *on = (slap_overinst *)be->bd_info;
3154 cache_manager *cm = on->on_bi.bi_private;
3155 query_manager *qm = cm->qm;
3157 if ( cm->db.be_private != NULL ) {
3158 backend_stopdown_one( &cm->db );
3161 ldap_pvt_thread_mutex_destroy( &qm->lru_mutex );
3162 ldap_pvt_thread_mutex_destroy( &cm->cache_mutex );
3169 static slap_overinst pcache;
3171 static char *obsolete_names[] = {
3176 #if SLAPD_OVER_PROXYCACHE == SLAPD_MOD_DYNAMIC
3178 #endif /* SLAPD_OVER_PROXYCACHE == SLAPD_MOD_DYNAMIC */
3183 struct berval debugbv = BER_BVC("pcache");
3185 code = slap_loglevel_get( &debugbv, &pcache_debug );
3190 for ( i = 0; as[i].desc != NULL; i++ ) {
3191 code = register_at( as[i].desc, as[i].adp, 0 );
3193 Debug( LDAP_DEBUG_ANY,
3194 "pcache_initialize: register_at #%d failed\n", i, 0, 0 );
3199 pcache.on_bi.bi_type = "pcache";
3200 pcache.on_bi.bi_obsolete_names = obsolete_names;
3201 pcache.on_bi.bi_db_init = pcache_db_init;
3202 pcache.on_bi.bi_db_config = pcache_db_config;
3203 pcache.on_bi.bi_db_open = pcache_db_open;
3204 pcache.on_bi.bi_db_close = pcache_db_close;
3205 pcache.on_bi.bi_db_destroy = pcache_db_destroy;
3207 pcache.on_bi.bi_op_search = pcache_op_search;
3209 pcache.on_bi.bi_chk_controls = pcache_chk_controls;
3211 pcache.on_bi.bi_cf_ocs = pcocs;
3213 code = config_register_schema( pccfg, pcocs );
3214 if ( code ) return code;
3216 return overlay_register( &pcache );
3219 #if SLAPD_OVER_PROXYCACHE == SLAPD_MOD_DYNAMIC
3220 int init_module(int argc, char *argv[]) {
3221 return pcache_initialize();
3225 #endif /* defined(SLAPD_OVER_PROXYCACHE) */