Qbase *qbase;
int scope;
struct berval q_uuid; /* query identifier */
- struct query_template_s *qtemp; /* template of the query */
+ struct query_template_s *qtemp; /* template of the query */
time_t expiry_time; /* time till the query is considered valid */
struct cached_query_s *next; /* next query in the template */
struct cached_query_s *prev; /* previous query in the template */
struct cached_query_s *lru_down; /* next query in the LRU list */
} CachedQuery;
+/*
+ * URL representation:
+ *
+ * ldap:///<base>??<scope>?<filter>?x-uuid=<uid>,x-template=<template>,x-attrset=<attrset>,x-expiry=<expiry>
+ *
+ * <base> ::= CachedQuery.qbase->base
+ * <scope> ::= CachedQuery.scope
+ * <filter> ::= filter2bv(CachedQuery.filter)
+ * <uuid> ::= CachedQuery.q_uuid
+ * <template> ::= CachedQuery.qtemp->querystr [FIXME: better give it an ID?]
+ * <attrset> ::= CachedQuery.qtemp->attr_set_index [FIXME: better give it an ID?]
+ * <expiry> ::= CachedQuery.expiry_time
+ *
+ * quick hack: parse URI, call add_query() and then fix
+ * CachedQuery.expiry_time and CachedQuery.q_uuid
+ */
+
/*
* Represents a set of projected attributes.
*/
BackendDB db; /* underlying database */
unsigned long num_cached_queries; /* total number of cached queries */
unsigned long max_queries; /* upper bound on # of cached queries */
+ int save_queries; /* save cached queries across restarts */
int numattrsets; /* number of attribute sets */
int cur_entries; /* current number of entries cached */
int max_entries; /* max number of entries cached */
static int pcache_debug;
-static AttributeDescription *ad_queryid;
-static char *queryid_schema = "( 1.3.6.1.4.1.4203.666.1.12 NAME 'queryid' "
- "DESC 'list of queries the entry belongs to' "
- "EQUALITY octetStringMatch "
- "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40{64} "
- "NO-USER-MODIFICATION USAGE directoryOperation )";
+static AttributeDescription *ad_queryid, *ad_cachedQueryURL;
+static struct {
+ char *desc;
+ AttributeDescription **adp;
+} as[] = {
+ { "( 1.3.6.1.4.1.4203.666.1.12 NAME 'queryid' "
+ "DESC 'list of queries the entry belongs to' "
+ "EQUALITY octetStringMatch "
+ "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40{64} "
+ "NO-USER-MODIFICATION USAGE directoryOperation )",
+ &ad_queryid },
+ { "(1.3.6.1.4.1.4203.666.1.999999 NAME 'cachedQueryURL' "
+ "DESC 'URI describing a cached query' "
+ "EQUALITY caseExactMatch "
+ "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 "
+ "NO-USER-MODIFICATION USAGE directoryOperation )",
+ &ad_cachedQueryURL },
+ { NULL }
+};
+
+static int
+filter2template(
+ Operation *op,
+ Filter *f,
+ struct berval *fstr,
+ AttributeName** filter_attrs,
+ int* filter_cnt,
+ int* filter_got_oc );
+
+static CachedQuery *
+add_query(
+ Operation *op,
+ query_manager* qm,
+ Query* query,
+ QueryTemplate *templ,
+ int positive);
+
+/*
+ * Turn a cached query into its URL representation
+ */
+static int
+query2url( CachedQuery *q, struct berval *urlbv )
+{
+ struct berval bv_scope,
+ bv_filter;
+ char attrset_buf[ 32 ],
+ expiry_buf[ 32 ],
+ *ptr;
+ ber_len_t attrset_len,
+ expiry_len;
+
+ ldap_pvt_scope2bv( q->scope, &bv_scope );
+ filter2bv( q->filter, &bv_filter );
+ attrset_len = snprintf( attrset_buf, sizeof( attrset_buf ),
+ "%lu", (unsigned long)q->qtemp->attr_set_index );
+ expiry_len = snprintf( expiry_buf, sizeof( expiry_buf ),
+ "%lu", (unsigned long)q->expiry_time );
+
+ urlbv->bv_len = STRLENOF( "ldap:///" )
+ + q->qbase->base.bv_len
+ + STRLENOF( "??" )
+ + bv_scope.bv_len
+ + STRLENOF( "?" )
+ + bv_filter.bv_len
+ + STRLENOF( "?x-uuid=" )
+ + q->q_uuid.bv_len
+ + STRLENOF( ",x-attrset=" )
+ + attrset_len
+ + STRLENOF( ",x-expiry=" )
+ + expiry_len;
+ ptr = urlbv->bv_val = ch_malloc( urlbv->bv_len + 1 );
+ ptr = lutil_strcopy( ptr, "ldap:///" );
+ ptr = lutil_strcopy( ptr, q->qbase->base.bv_val );
+ ptr = lutil_strcopy( ptr, "??" );
+ ptr = lutil_strcopy( ptr, bv_scope.bv_val );
+ ptr = lutil_strcopy( ptr, "?" );
+ ptr = lutil_strcopy( ptr, bv_filter.bv_val );
+ ptr = lutil_strcopy( ptr, "?x-uuid=" );
+ ptr = lutil_strcopy( ptr, q->q_uuid.bv_val );
+ ptr = lutil_strcopy( ptr, ",x-attrset=" );
+ ptr = lutil_strcopy( ptr, attrset_buf );
+ ptr = lutil_strcopy( ptr, ",x-expiry=" );
+ ptr = lutil_strcopy( ptr, expiry_buf );
+
+ ber_memfree( bv_filter.bv_val );
+
+ return 0;
+}
+
+/*
+ * Turn an URL representing a formerly cached query into a cached query,
+ * and try to cache it
+ */
+static int
+url2query(
+ char *url,
+ Operation *op,
+ query_manager *qm )
+{
+ Query query = { 0 };
+ QueryTemplate *qt;
+ CachedQuery *cq;
+ LDAPURLDesc *lud = NULL;
+ struct berval base,
+ tempstr = BER_BVNULL,
+ uuid;
+ int attrset;
+ time_t expiry_time;
+ int i,
+ got_uuid = 0,
+ got_attrset = 0,
+ got_expiry = 0,
+ rc = 0;
+
+ rc = ldap_url_parse( url, &lud );
+ if ( rc != LDAP_URL_SUCCESS ) {
+ return -1;
+ }
+
+ /* non-allowed fields */
+ if ( lud->lud_host != NULL ) {
+ rc = 1;
+ goto error;
+ }
+
+ if ( lud->lud_attrs != NULL ) {
+ rc = 1;
+ goto error;
+ }
+
+ /* be pedantic */
+ if ( strcmp( lud->lud_scheme, "ldap" ) != 0 ) {
+ rc = 1;
+ goto error;
+ }
+
+ /* required fields */
+ if ( lud->lud_dn == NULL || lud->lud_dn[ 0 ] == '\0' ) {
+ rc = 1;
+ goto error;
+ }
+
+ switch ( lud->lud_scope ) {
+ case LDAP_SCOPE_BASE:
+ case LDAP_SCOPE_ONELEVEL:
+ case LDAP_SCOPE_SUBTREE:
+ case LDAP_SCOPE_SUBORDINATE:
+ break;
+
+ default:
+ rc = 1;
+ goto error;
+ }
+
+ if ( lud->lud_filter == NULL || lud->lud_filter[ 0 ] == '\0' ) {
+ rc = 1;
+ goto error;
+ }
+
+ if ( lud->lud_exts == NULL ) {
+ rc = 1;
+ goto error;
+ }
+
+ for ( i = 0; lud->lud_exts[ i ] != NULL; i++ ) {
+ if ( strncmp( lud->lud_exts[ i ], "x-uuid=", STRLENOF( "x-uuid=" ) ) == 0 ) {
+ ber_str2bv( &lud->lud_exts[ i ][ STRLENOF( "x-uuid=" ) ], 0, 0, &uuid );
+ if ( rc ) {
+ goto error;
+ }
+ got_uuid = 1;
+
+ } else if ( strncmp( lud->lud_exts[ i ], "x-attrset=", STRLENOF( "x-attrset=" ) ) == 0 ) {
+ rc = lutil_atoi( &attrset, &lud->lud_exts[ i ][ STRLENOF( "x-attrset=" ) ] );
+ if ( rc ) {
+ goto error;
+ }
+ got_attrset = 1;
+
+ } else if ( strncmp( lud->lud_exts[ i ], "x-expiry=", STRLENOF( "x-expiry=" ) ) == 0 ) {
+ unsigned long l;
+
+ rc = lutil_atoul( &l, &lud->lud_exts[ i ][ STRLENOF( "x-expiry=" ) ] );
+ if ( rc ) {
+ goto error;
+ }
+ expiry_time = (time_t)l;
+ got_expiry = 1;
+
+ /* ignore expired queries */
+ if ( expiry_time <= slap_get_time()) {
+ rc = 0;
+ goto error;
+ }
+
+ } else {
+ rc = -1;
+ goto error;
+ }
+ }
+
+ if ( !got_uuid ) {
+ rc = 1;
+ goto error;
+ }
+
+ if ( !got_attrset ) {
+ rc = 1;
+ goto error;
+ }
+
+ if ( !got_expiry ) {
+ rc = 1;
+ goto error;
+ }
+
+ ber_str2bv( lud->lud_dn, 0, 0, &base );
+ rc = dnNormalize( 0, NULL, NULL, &base, &query.base, NULL );
+ if ( rc != LDAP_SUCCESS ) {
+ goto error;
+ }
+ query.scope = lud->lud_scope;
+ query.filter = str2filter( lud->lud_filter );
+
+ tempstr.bv_val = ch_malloc( strlen( lud->lud_filter ) + 1 );
+ tempstr.bv_len = 0;
+ if ( filter2template( op, query.filter, &tempstr, NULL, NULL, NULL ) ) {
+ ch_free( tempstr.bv_val );
+ rc = -1;
+ goto error;
+ }
+
+ /* check for query containment */
+ qt = qm->attr_sets[attrset].templates;
+ for ( ; qt; qt = qt->qtnext ) {
+ /* find if template i can potentially answer tempstr */
+ if ( bvmatch( &qt->querystr, &tempstr ) ) {
+ break;
+ }
+ }
+
+ if ( qt == NULL ) {
+ rc = 1;
+ goto error;
+ }
+
+
+ cq = add_query( op, qm, &query, qt, 1 );
+ if ( cq != NULL ) {
+ cq->expiry_time = expiry_time;
+ ber_dupbv( &cq->q_uuid, &uuid );
+ /* it's now into cq->filter */
+ query.filter = NULL;
+
+ } else {
+ rc = 1;
+ }
+
+error:;
+ if ( query.filter != NULL ) filter_free( query.filter );
+ if ( !BER_BVISNULL( &tempstr ) ) ch_free( tempstr.bv_val );
+ if ( !BER_BVISNULL( &query.base ) ) ch_free( query.base.bv_val );
+ if ( lud != NULL ) ldap_free_urldesc( lud );
+
+ return rc;
+}
/* Return 1 for an added entry, else 0 */
static int
/* Add query to query cache */
-static CachedQuery * add_query(
+static CachedQuery *
+add_query(
Operation *op,
query_manager* qm,
Query* query,
qbase = avl_find( templ->qbase, &qb, pcache_dn_cmp );
if ( !qbase ) {
qbase = ch_calloc( 1, sizeof(Qbase) + qb.base.bv_len + 1 );
- qbase->base.bv_len =qb.base.bv_len;
+ qbase->base.bv_len = qb.base.bv_len;
qbase->base.bv_val = (char *)(qbase+1);
memcpy( qbase->base.bv_val, qb.base.bv_val, qb.base.bv_len );
qbase->base.bv_val[qbase->base.bv_len] = '\0';
return -1;
}
- *filter_attrs = (AttributeName *)op->o_tmprealloc(*filter_attrs,
+ if ( filter_attrs != NULL ) {
+ *filter_attrs = (AttributeName *)op->o_tmprealloc(*filter_attrs,
(*filter_cnt + 2)*sizeof(AttributeName), op->o_tmpmemctx);
- (*filter_attrs)[*filter_cnt].an_desc = ad;
- (*filter_attrs)[*filter_cnt].an_name = ad->ad_cname;
- (*filter_attrs)[*filter_cnt].an_oc = NULL;
- (*filter_attrs)[*filter_cnt].an_oc_exclude = 0;
- BER_BVZERO( &(*filter_attrs)[*filter_cnt+1].an_name );
- (*filter_cnt)++;
- if ( ad == slap_schema.si_ad_objectClass )
- *filter_got_oc = 1;
+ (*filter_attrs)[*filter_cnt].an_desc = ad;
+ (*filter_attrs)[*filter_cnt].an_name = ad->ad_cname;
+ (*filter_attrs)[*filter_cnt].an_oc = NULL;
+ (*filter_attrs)[*filter_cnt].an_oc_exclude = 0;
+ BER_BVZERO( &(*filter_attrs)[*filter_cnt+1].an_name );
+ (*filter_cnt)++;
+ if ( ad == slap_schema.si_ad_objectClass )
+ *filter_got_oc = 1;
+ }
+
return 0;
}
count++;
}
- *new_attrs = (AttributeName*)ch_malloc((count+1)*
- sizeof(AttributeName));
+ *new_attrs = (AttributeName*)ch_calloc( count + 1,
+ sizeof(AttributeName) );
for (i=0; i<attrs->count; i++) {
(*new_attrs)[i].an_name = attrs->attrs[i].an_name;
(*new_attrs)[i].an_desc = attrs->attrs[i].an_desc;
j = i;
for ( i=0; i<fattr_cnt; i++ ) {
- if ( an_find(*new_attrs, &filter_attrs[i].an_name ))
+ if ( an_find(*new_attrs, &filter_attrs[i].an_name ) ) {
continue;
+ }
if ( is_at_operational(filter_attrs[i].an_desc->ad_type) ) {
- if (allop)
+ if ( allop ) {
continue;
- } else if (alluser)
+ }
+ } else if ( alluser ) {
continue;
+ }
(*new_attrs)[j].an_name = filter_attrs[i].an_name;
(*new_attrs)[j].an_desc = filter_attrs[i].an_desc;
(*new_attrs)[j].an_oc = NULL;
AttributeName *filter_attrs = NULL;
Query query;
- QueryTemplate *qtemp = NULL;
+ QueryTemplate *qtemp = NULL;
int attr_set = -1;
CachedQuery *answerable = NULL;
}
ldap_pvt_thread_rdwr_wunlock(&qtemp->t_rwlock);
- cb = op->o_tmpalloc( sizeof(*cb) + sizeof(*si), op->o_tmpmemctx);
+ cb = op->o_tmpalloc( sizeof(*cb) + sizeof(*si), op->o_tmpmemctx );
cb->sc_response = pcache_response;
cb->sc_cleanup = NULL;
cb->sc_private = (cb+1);
for ( ; attrs[count].an_name.bv_val; count++ );
}
- for (i=0; i<num; i++) {
+ /* recognize a single "*" or a "1.1" */
+ if ( count == 0 ) {
+ count = 1;
+ attrs = slap_anlist_all_user_attributes;
+
+ } else if ( count == 1 && strcmp( attrs[0].an_name.bv_val, LDAP_NO_ATTRS ) == 0 ) {
+ count = 0;
+ attrs = NULL;
+ }
+
+ for ( i = 0; i < num; i++ ) {
AttributeName *a2;
int found = 1;
- if ( count > qm->attr_sets[i].count )
+ if ( count > qm->attr_sets[i].count ) {
continue;
+ }
+
if ( !count ) {
- if ( !qm->attr_sets[i].count )
+ if ( !qm->attr_sets[i].count ) {
break;
+ }
continue;
}
+
for ( a2 = attrs; a2->an_name.bv_val; a2++ ) {
- if ( !an_find( qm->attr_sets[i].attrs, &a2->an_name )) {
+ if ( !an_find( qm->attr_sets[i].attrs, &a2->an_name ) ) {
found = 0;
break;
}
}
- if ( found )
+
+ if ( found ) {
break;
+ }
}
- if ( i == num )
+
+ if ( i == num ) {
i = -1;
+ }
+
return i;
}
"( OLcfgOvAt:2.5 NAME 'olcProxyCacheQueries' "
"DESC 'Maximum number of queries to cache' "
"SYNTAX OMsInteger )", NULL, NULL },
+ { "proxySaveQueries", "TRUE|FALSE",
+ 2, 2, 0, ARG_ON_OFF|ARG_OFFSET, (void *)offsetof(cache_manager, save_queries),
+ "( OLcfgOvAt:2.6 NAME 'olcProxySaveQueries' "
+ "DESC 'Save cached queries for hot restart' "
+ "SYNTAX OMsBoolean )", NULL, NULL },
{ NULL, NULL, 0, 0, 0, ARG_IGNORED }
};
"DESC 'ProxyCache configuration' "
"SUP olcOverlayConfig "
"MUST ( olcProxyCache $ olcProxyAttrset $ olcProxyTemplate ) "
- "MAY ( olcProxyResponseCB $ olcProxyCacheQueries ) )", Cft_Overlay, pccfg, NULL, pc_cfadd },
+ "MAY ( olcProxyResponseCB $ olcProxyCacheQueries $ olcProxySaveQueries ) )",
+ Cft_Overlay, pccfg, NULL, pc_cfadd },
{ "( OLcfgOvOc:2.2 "
"NAME 'olcPcacheDatabase' "
"DESC 'Cache database configuration' "
struct berval bv;
/* FIXME: should not hardcode "olcDatabase" here */
- bv.bv_len = sprintf( ca->msg, "olcDatabase=%s", cm->db.bd_info->bi_type );
- bv.bv_val = ca->msg;
+ bv.bv_len = sprintf( ca->cr_msg, "olcDatabase=%s", cm->db.bd_info->bi_type );
+ bv.bv_val = ca->cr_msg;
ca->be = &cm->db;
/* We can only create this entry if the database is table-driven
struct berval bv;
switch( c->type ) {
case PC_MAIN:
- bv.bv_len = snprintf( c->msg, sizeof( c->msg ), "%s %d %d %d %ld",
+ bv.bv_len = snprintf( c->cr_msg, sizeof( c->cr_msg ), "%s %d %d %d %ld",
cm->db.bd_info->bi_type, cm->max_entries, cm->numattrsets,
cm->num_entries_limit, cm->cc_period );
- bv.bv_val = c->msg;
+ bv.bv_val = c->cr_msg;
value_add_one( &c->rvalue_vals, &bv );
break;
case PC_ATTR:
for (i=0; i<cm->numattrsets; i++) {
if ( !qm->attr_sets[i].count ) continue;
- bv.bv_len = snprintf( c->msg, sizeof( c->msg ), "%d", i );
+ bv.bv_len = snprintf( c->cr_msg, sizeof( c->cr_msg ), "%d", i );
/* count the attr length */
for ( attr_name = qm->attr_sets[i].attrs;
bv.bv_len += attr_name->an_name.bv_len + 1;
bv.bv_val = ch_malloc( bv.bv_len+1 );
- ptr = lutil_strcopy( bv.bv_val, c->msg );
+ ptr = lutil_strcopy( bv.bv_val, c->cr_msg );
for ( attr_name = qm->attr_sets[i].attrs;
attr_name->an_name.bv_val; attr_name++ ) {
*ptr++ = ' ';
case PC_TEMP:
for (temp=qm->templates; temp; temp=temp->qmnext) {
if ( temp->negttl ) {
- bv.bv_len = snprintf( c->msg, sizeof( c->msg ),
+ bv.bv_len = snprintf( c->cr_msg, sizeof( c->cr_msg ),
" %d %ld %ld",
temp->attr_set_index,
temp->ttl,
temp->negttl );
} else {
- bv.bv_len = snprintf( c->msg, sizeof( c->msg ), " %d %ld",
+ bv.bv_len = snprintf( c->cr_msg, sizeof( c->cr_msg ), " %d %ld",
temp->attr_set_index,
temp->ttl );
}
*ptr++ = '"';
ptr = lutil_strcopy( ptr, temp->querystr.bv_val );
*ptr++ = '"';
- strcpy( ptr, c->msg );
+ strcpy( ptr, c->cr_msg );
ber_bvarray_add( &c->rvalue_vals, &bv );
}
if ( !c->rvalue_vals )
switch( c->type ) {
case PC_MAIN:
if ( cm->numattrsets > 0 ) {
- snprintf( c->msg, sizeof( c->msg ), "\"proxycache\" directive already provided" );
- Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->msg, 0 );
+ snprintf( c->cr_msg, sizeof( c->cr_msg ), "\"proxycache\" directive already provided" );
+ Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
return( 1 );
}
if ( lutil_atoi( &cm->numattrsets, c->argv[3] ) != 0 ) {
- snprintf( c->msg, sizeof( c->msg ), "unable to parse num attrsets=\"%s\" (arg #3)",
+ snprintf( c->cr_msg, sizeof( c->cr_msg ), "unable to parse num attrsets=\"%s\" (arg #3)",
c->argv[3] );
- Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->msg, 0 );
+ Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
return( 1 );
}
if ( cm->numattrsets <= 0 ) {
- snprintf( c->msg, sizeof( c->msg ), "numattrsets (arg #3) must be positive" );
- Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->msg, 0 );
+ snprintf( c->cr_msg, sizeof( c->cr_msg ), "numattrsets (arg #3) must be positive" );
+ Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
return( 1 );
}
if ( cm->numattrsets > MAX_ATTR_SETS ) {
- snprintf( c->msg, sizeof( c->msg ), "numattrsets (arg #3) must be <= %d", MAX_ATTR_SETS );
- Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->msg, 0 );
+ snprintf( c->cr_msg, sizeof( c->cr_msg ), "numattrsets (arg #3) must be <= %d", MAX_ATTR_SETS );
+ Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
return( 1 );
}
- if ( !backend_db_init( c->argv[1], &cm->db, -1 )) {
- snprintf( c->msg, sizeof( c->msg ), "unknown backend type (arg #1)" );
- Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->msg, 0 );
+ if ( !backend_db_init( c->argv[1], &cm->db, -1, NULL )) {
+ snprintf( c->cr_msg, sizeof( c->cr_msg ), "unknown backend type (arg #1)" );
+ Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
return( 1 );
}
if ( lutil_atoi( &cm->max_entries, c->argv[2] ) != 0 ) {
- snprintf( c->msg, sizeof( c->msg ), "unable to parse max entries=\"%s\" (arg #2)",
+ snprintf( c->cr_msg, sizeof( c->cr_msg ), "unable to parse max entries=\"%s\" (arg #2)",
c->argv[2] );
- Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->msg, 0 );
+ Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
return( 1 );
}
if ( cm->max_entries <= 0 ) {
- snprintf( c->msg, sizeof( c->msg ), "max entries (arg #2) must be positive.\n" );
- Debug( LDAP_DEBUG_CONFIG, "%s: %s\n", c->log, c->msg, 0 );
+ snprintf( c->cr_msg, sizeof( c->cr_msg ), "max entries (arg #2) must be positive.\n" );
+ Debug( LDAP_DEBUG_CONFIG, "%s: %s\n", c->log, c->cr_msg, 0 );
return( 1 );
}
if ( lutil_atoi( &cm->num_entries_limit, c->argv[4] ) != 0 ) {
- snprintf( c->msg, sizeof( c->msg ), "unable to parse entry limit=\"%s\" (arg #4)",
+ snprintf( c->cr_msg, sizeof( c->cr_msg ), "unable to parse entry limit=\"%s\" (arg #4)",
c->argv[4] );
- Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->msg, 0 );
+ Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
return( 1 );
}
if ( cm->num_entries_limit <= 0 ) {
- snprintf( c->msg, sizeof( c->msg ), "entry limit (arg #4) must be positive" );
- Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->msg, 0 );
+ snprintf( c->cr_msg, sizeof( c->cr_msg ), "entry limit (arg #4) must be positive" );
+ Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
return( 1 );
}
if ( cm->num_entries_limit > cm->max_entries ) {
- snprintf( c->msg, sizeof( c->msg ), "entry limit (arg #4) must be less than max entries %d (arg #2)", cm->max_entries );
- Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->msg, 0 );
+ snprintf( c->cr_msg, sizeof( c->cr_msg ), "entry limit (arg #4) must be less than max entries %d (arg #2)", cm->max_entries );
+ Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
return( 1 );
}
if ( lutil_parse_time( c->argv[5], &t ) != 0 ) {
- snprintf( c->msg, sizeof( c->msg ), "unable to parse period=\"%s\" (arg #5)",
+ snprintf( c->cr_msg, sizeof( c->cr_msg ), "unable to parse period=\"%s\" (arg #5)",
c->argv[5] );
- Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->msg, 0 );
+ Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
return( 1 );
}
cm->cc_period = (time_t)t;
break;
case PC_ATTR:
if ( cm->numattrsets == 0 ) {
- snprintf( c->msg, sizeof( c->msg ), "\"proxycache\" directive not provided yet" );
- Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->msg, 0 );
+ snprintf( c->cr_msg, sizeof( c->cr_msg ), "\"proxycache\" directive not provided yet" );
+ Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
return( 1 );
}
if ( lutil_atoi( &num, c->argv[1] ) != 0 ) {
- snprintf( c->msg, sizeof( c->msg ), "unable to parse attrset #=\"%s\"",
+ snprintf( c->cr_msg, sizeof( c->cr_msg ), "unable to parse attrset #=\"%s\"",
c->argv[1] );
- Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->msg, 0 );
+ Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
return( 1 );
}
if ( num < 0 || num >= cm->numattrsets ) {
- snprintf( c->msg, sizeof( c->msg ), "attrset index %d out of bounds (must be %s%d)",
+ snprintf( c->cr_msg, sizeof( c->cr_msg ), "attrset index %d out of bounds (must be %s%d)",
num, cm->numattrsets > 1 ? "0->" : "", cm->numattrsets - 1 );
- Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->msg, 0 );
+ Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
return 1;
}
qm->attr_sets[num].flags |= PC_CONFIGURED;
- if ( c->argc > 2 && strcmp( c->argv[2], "*" ) ) {
+ if ( c->argc == 2 ) {
+ /* assume "1.1" */
+ snprintf( c->cr_msg, sizeof( c->cr_msg ),
+ "need an explicit attr in attrlist; use \"*\" to indicate all attrs" );
+ Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
+ return 1;
+
+ } else if ( c->argc == 3 ) {
+ if ( strcmp( c->argv[2], LDAP_ALL_USER_ATTRIBUTES ) == 0 ) {
+ qm->attr_sets[num].count = 1;
+ qm->attr_sets[num].attrs = (AttributeName*)ch_calloc( 2,
+ sizeof( AttributeName ) );
+ BER_BVSTR( &qm->attr_sets[num].attrs[0].an_name, LDAP_ALL_USER_ATTRIBUTES );
+ break;
+
+ } else if ( strcmp( c->argv[2], LDAP_ALL_OPERATIONAL_ATTRIBUTES ) == 0 ) {
+ qm->attr_sets[num].count = 1;
+ qm->attr_sets[num].attrs = (AttributeName*)ch_calloc( 2,
+ sizeof( AttributeName ) );
+ BER_BVSTR( &qm->attr_sets[num].attrs[0].an_name, LDAP_ALL_OPERATIONAL_ATTRIBUTES );
+ break;
+
+ } else if ( strcmp( c->argv[2], LDAP_NO_ATTRS ) == 0 ) {
+ break;
+ }
+ /* else: fallthru */
+
+ } else if ( c->argc == 4 ) {
+ if ( ( strcmp( c->argv[2], LDAP_ALL_USER_ATTRIBUTES ) == 0 && strcmp( c->argv[3], LDAP_ALL_OPERATIONAL_ATTRIBUTES ) == 0 )
+ || ( strcmp( c->argv[2], LDAP_ALL_OPERATIONAL_ATTRIBUTES ) == 0 && strcmp( c->argv[3], LDAP_ALL_USER_ATTRIBUTES ) == 0 ) )
+ {
+ qm->attr_sets[num].count = 2;
+ qm->attr_sets[num].attrs = (AttributeName*)ch_calloc( 3,
+ sizeof( AttributeName ) );
+ BER_BVSTR( &qm->attr_sets[num].attrs[0].an_name, LDAP_ALL_USER_ATTRIBUTES );
+ BER_BVSTR( &qm->attr_sets[num].attrs[1].an_name, LDAP_ALL_OPERATIONAL_ATTRIBUTES );
+ break;
+ }
+ /* else: fallthru */
+ }
+
+ if ( c->argc > 2 ) {
+ int all_user = 0, all_op = 0;
+
qm->attr_sets[num].count = c->argc - 2;
- qm->attr_sets[num].attrs = (AttributeName*)ch_malloc(
- (c->argc-1) * sizeof( AttributeName ));
+ qm->attr_sets[num].attrs = (AttributeName*)ch_calloc( c->argc - 1,
+ sizeof( AttributeName ) );
attr_name = qm->attr_sets[num].attrs;
for ( i = 2; i < c->argc; i++ ) {
attr_name->an_desc = NULL;
- if ( slap_str2ad( c->argv[i],
- &attr_name->an_desc, &text ) )
- {
- strcpy( c->msg, text );
- Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->msg, 0 );
+ if ( strcmp( c->argv[i], LDAP_NO_ATTRS ) == 0 ) {
+ snprintf( c->cr_msg, sizeof( c->cr_msg ),
+ "invalid attr #%d \"%s\" in attrlist",
+ i - 2, c->argv[i] );
+ Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
ch_free( qm->attr_sets[num].attrs );
qm->attr_sets[num].attrs = NULL;
qm->attr_sets[num].count = 0;
return 1;
}
- attr_name->an_name = attr_name->an_desc->ad_cname;
+ if ( strcmp( c->argv[i], LDAP_ALL_USER_ATTRIBUTES ) == 0 ) {
+ all_user = 1;
+ BER_BVSTR( &attr_name->an_name, LDAP_ALL_USER_ATTRIBUTES );
+ } else if ( strcmp( c->argv[i], LDAP_ALL_OPERATIONAL_ATTRIBUTES ) == 0 ) {
+ all_op = 1;
+ BER_BVSTR( &attr_name->an_name, LDAP_ALL_OPERATIONAL_ATTRIBUTES );
+ } else {
+ if ( slap_str2ad( c->argv[i], &attr_name->an_desc, &text ) ) {
+ strcpy( c->cr_msg, text );
+ Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
+ ch_free( qm->attr_sets[num].attrs );
+ qm->attr_sets[num].attrs = NULL;
+ qm->attr_sets[num].count = 0;
+ return 1;
+ }
+ attr_name->an_name = attr_name->an_desc->ad_cname;
+ }
attr_name->an_oc = NULL;
attr_name->an_oc_exclude = 0;
if ( attr_name->an_desc == slap_schema.si_ad_objectClass )
attr_name++;
BER_BVZERO( &attr_name->an_name );
}
+
+ /* warn if list contains both "*" and "+" */
+ if ( i > 4 && all_user && all_op ) {
+ snprintf( c->cr_msg, sizeof( c->cr_msg ),
+ "warning: attribute list contains \"*\" and \"+\"" );
+ Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
+ }
}
break;
case PC_TEMP:
if ( cm->numattrsets == 0 ) {
- snprintf( c->msg, sizeof( c->msg ), "\"proxycache\" directive not provided yet" );
- Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->msg, 0 );
+ snprintf( c->cr_msg, sizeof( c->cr_msg ), "\"proxycache\" directive not provided yet" );
+ Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
return( 1 );
}
if ( lutil_atoi( &i, c->argv[2] ) != 0 ) {
- snprintf( c->msg, sizeof( c->msg ), "unable to parse template #=\"%s\"",
+ snprintf( c->cr_msg, sizeof( c->cr_msg ), "unable to parse template #=\"%s\"",
c->argv[2] );
- Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->msg, 0 );
+ Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
return( 1 );
}
if ( i < 0 || i >= cm->numattrsets ||
!(qm->attr_sets[i].flags & PC_CONFIGURED )) {
- snprintf( c->msg, sizeof( c->msg ), "template index %d invalid (%s%d)",
+ snprintf( c->cr_msg, sizeof( c->cr_msg ), "template index %d invalid (%s%d)",
i, cm->numattrsets > 1 ? "0->" : "", cm->numattrsets - 1 );
- Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->msg, 0 );
+ Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
return 1;
}
temp = ch_calloc( 1, sizeof( QueryTemplate ));
ldap_pvt_thread_rdwr_init( &temp->t_rwlock );
temp->query = temp->query_last = NULL;
if ( lutil_parse_time( c->argv[3], &t ) != 0 ) {
- snprintf( c->msg, sizeof( c->msg ), "unable to parse template ttl=\"%s\"",
+ snprintf( c->cr_msg, sizeof( c->cr_msg ), "unable to parse template ttl=\"%s\"",
c->argv[3] );
- Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->msg, 0 );
+ Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
return( 1 );
}
temp->ttl = (time_t)t;
if ( c->argc == 5 ) {
if ( lutil_parse_time( c->argv[4], &t ) != 0 ) {
- snprintf( c->msg, sizeof( c->msg ),
+ snprintf( c->cr_msg, sizeof( c->cr_msg ),
"unable to parse template negttl=\"%s\"",
c->argv[4] );
- Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->msg, 0 );
+ Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
return( 1 );
}
temp->negttl = (time_t)t;
cm->response_cb = PCACHE_RESPONSE_CB_TAIL;
} else {
- snprintf( c->msg, sizeof( c->msg ), "unknown specifier" );
- Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->msg, 0 );
+ snprintf( c->cr_msg, sizeof( c->cr_msg ), "unknown specifier" );
+ Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
return 1;
}
break;
case PC_QUERIES:
if ( c->value_int <= 0 ) {
- snprintf( c->msg, sizeof( c->msg ), "max queries must be positive" );
- Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->msg, 0 );
+ snprintf( c->cr_msg, sizeof( c->cr_msg ), "max queries must be positive" );
+ Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->cr_msg, 0 );
return( 1 );
}
cm->max_queries = c->value_int;
static int
pcache_db_init(
- BackendDB *be )
+ BackendDB *be,
+ ConfigReply *cr)
{
slap_overinst *on = (slap_overinst *)be->bd_info;
cache_manager *cm;
return 0;
}
+static int
+pcache_cachedquery_open_cb( Operation *op, SlapReply *rs )
+{
+ assert( op->o_tag == LDAP_REQ_SEARCH );
+
+ if ( rs->sr_type == REP_SEARCH ) {
+ Attribute *a;
+
+ a = attr_find( rs->sr_entry->e_attrs, ad_cachedQueryURL );
+ if ( a != NULL ) {
+ BerVarray *valsp;
+
+ assert( a->a_nvals != NULL );
+
+ valsp = op->o_callback->sc_private;
+ assert( *valsp == NULL );
+
+ ber_bvarray_dup_x( valsp, a->a_nvals, op->o_tmpmemctx );
+ }
+ }
+
+ return 0;
+}
+
static int
pcache_db_open(
- BackendDB *be )
+ BackendDB *be,
+ ConfigReply *cr )
{
slap_overinst *on = (slap_overinst *)be->bd_info;
cache_manager *cm = on->on_bi.bi_private;
SLAP_DBFLAGS( &cm->db ) &= ~SLAP_DBFLAG_MONITORING;
}
- rc = backend_startup_one( &cm->db );
+ rc = backend_startup_one( &cm->db, NULL );
/* There is no runqueue in TOOL mode */
if ( slapMode & SLAP_SERVER_MODE ) {
cm->db.be_suffix[0].bv_val, 0 );
return 1;
}
+
+ if ( cm->save_queries ) {
+ void *thrctx = ldap_pvt_thread_pool_context();
+ Connection conn = { 0 };
+ OperationBuffer opbuf;
+ Operation *op;
+ slap_callback cb = { 0 };
+ SlapReply rs = { 0 };
+ BerVarray vals = NULL;
+ AttributeName attrs[ 2 ] = { 0 };
+
+ connection_fake_init( &conn, &opbuf, thrctx );
+ op = &opbuf.ob_op;
+
+ op->o_bd = &cm->db;
+
+ op->o_tag = LDAP_REQ_SEARCH;
+ op->o_protocol = LDAP_VERSION3;
+ cb.sc_response = pcache_cachedquery_open_cb;
+ cb.sc_private = &vals;
+ op->o_callback = &cb;
+ op->o_time = slap_get_time();
+ op->o_do_not_cache = 1;
+ op->o_managedsait = SLAP_CONTROL_CRITICAL;
+
+ op->o_dn = cm->db.be_rootdn;
+ op->o_ndn = cm->db.be_rootndn;
+ op->o_req_dn = cm->db.be_suffix[ 0 ];
+ op->o_req_ndn = cm->db.be_nsuffix[ 0 ];
+
+ op->ors_scope = LDAP_SCOPE_BASE;
+ op->ors_deref = LDAP_DEREF_NEVER;
+ op->ors_slimit = 1;
+ op->ors_tlimit = SLAP_NO_LIMIT;
+ ber_str2bv( "(cachedQueryURL=*)", 0, 0, &op->ors_filterstr );
+ op->ors_filter = str2filter_x( op, op->ors_filterstr.bv_val );
+ if ( op->ors_filter != NULL ) {
+ attrs[ 0 ].an_desc = ad_cachedQueryURL;
+ attrs[ 0 ].an_name = ad_cachedQueryURL->ad_cname;
+ op->ors_attrs = attrs;
+ op->ors_attrsonly = 0;
+
+ rc = op->o_bd->be_search( op, &rs );
+ if ( rc == LDAP_SUCCESS && vals != NULL ) {
+ int i;
+
+ for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
+ if ( url2query( vals[ i ].bv_val, op, qm ) == 0 ) {
+ cm->num_cached_queries++;
+ }
+ }
+
+ ber_bvarray_free_x( vals, op->o_tmpmemctx );
+ }
+
+ filter_free_x( op, op->ors_filter );
+ }
+
+ /* ignore errors */
+ rc = 0;
+ }
}
return rc;
static int
pcache_db_close(
- BackendDB *be
+ BackendDB *be,
+ ConfigReply *cr
)
{
slap_overinst *on = (slap_overinst *)be->bd_info;
QueryTemplate *tm;
int i, rc = 0;
+ if ( cm->save_queries && qm->templates != NULL ) {
+ CachedQuery *qc;
+ BerVarray vals = NULL;
+
+ for ( tm = qm->templates; tm != NULL; tm = tm->qmnext ) {
+ for ( qc = tm->query; qc; qc = qc->next ) {
+ struct berval bv;
+
+ if ( query2url( qc, &bv ) == 0 ) {
+ ber_bvarray_add( &vals, &bv );
+ }
+ }
+ }
+
+ if ( vals != NULL ) {
+ void *thrctx = ldap_pvt_thread_pool_context();
+ Connection conn = { 0 };
+ OperationBuffer opbuf;
+ Operation *op;
+ slap_callback cb = { 0 };
+
+ SlapReply rs = { REP_RESULT };
+ Modifications mod = { 0 };
+
+ connection_fake_init( &conn, &opbuf, thrctx );
+ op = &opbuf.ob_op;
+
+ op->o_bd = &cm->db;
+ op->o_dn = cm->db.be_rootdn;
+ op->o_ndn = cm->db.be_rootndn;
+
+ op->o_tag = LDAP_REQ_MODIFY;
+ op->o_protocol = LDAP_VERSION3;
+ cb.sc_response = slap_null_cb;
+ op->o_callback = &cb;
+ op->o_time = slap_get_time();
+ op->o_do_not_cache = 1;
+ op->o_managedsait = SLAP_CONTROL_CRITICAL;
+
+ op->o_req_dn = op->o_bd->be_suffix[0];
+ op->o_req_ndn = op->o_bd->be_nsuffix[0];
+
+ mod.sml_op = LDAP_MOD_REPLACE;
+ mod.sml_flags = 0;
+ mod.sml_desc = ad_cachedQueryURL;
+ mod.sml_type = ad_cachedQueryURL->ad_cname;
+ mod.sml_values = vals;
+ mod.sml_nvalues = NULL;
+ mod.sml_next = NULL;
+ Debug( pcache_debug,
+ "SETTING CACHED QUERY URLS\n",
+ 0, 0, 0 );
+
+ op->orm_modlist = &mod;
+
+ op->o_bd->be_modify( op, &rs );
+
+ ber_bvarray_free( vals );
+ }
+ }
+
/* cleanup stuff inherited from the original database... */
cm->db.be_limits = NULL;
cm->db.be_acl = NULL;
if ( cm->db.bd_info->bi_db_close ) {
- rc = cm->db.bd_info->bi_db_close( &cm->db );
+ rc = cm->db.bd_info->bi_db_close( &cm->db, NULL );
}
while ( (tm = qm->templates) != NULL ) {
CachedQuery *qc, *qn;
static int
pcache_db_destroy(
- BackendDB *be
+ BackendDB *be,
+ ConfigReply *cr
)
{
slap_overinst *on = (slap_overinst *)be->bd_info;
int pcache_initialize()
{
- int code;
+ int i, code;
struct berval debugbv = BER_BVC("pcache");
- if (( code = slap_loglevel_get( &debugbv, &pcache_debug )))
- return code;
-
- code = register_at( queryid_schema, &ad_queryid, 0 );
+ code = slap_loglevel_get( &debugbv, &pcache_debug );
if ( code ) {
- Debug( LDAP_DEBUG_ANY,
- "pcache_initialize: register_at failed\n", 0, 0, 0 );
return code;
}
+ for ( i = 0; as[i].desc != NULL; i++ ) {
+ code = register_at( as[i].desc, as[i].adp, 0 );
+ if ( code ) {
+ Debug( LDAP_DEBUG_ANY,
+ "pcache_initialize: register_at #%d failed\n", i, 0, 0 );
+ return code;
+ }
+ }
+
pcache.on_bi.bi_type = "pcache";
pcache.on_bi.bi_obsolete_names = obsolete_names;
pcache.on_bi.bi_db_init = pcache_db_init;