]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/overlays/pcache.c
fix length
[openldap] / servers / slapd / overlays / pcache.c
index 22b8355865071a9f1ba995656a1cb6415b219054..81d195aa243bba624337494570865a4de03bb0c5 100644 (file)
@@ -182,6 +182,7 @@ typedef struct cache_manager_s {
        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     check_cacheability;             /* check whether a query is cacheable */
        int     numattrsets;                    /* number of attribute sets */
        int     cur_entries;                    /* current number of entries cached */
        int     max_entries;                    /* max number of entries cached */
@@ -264,17 +265,17 @@ query2url( Operation *op, CachedQuery *q, struct berval *urlbv )
 {
        struct berval   bv_scope,
                        bv_filter;
-       char            attrset_buf[ 32 ],
-                       expiry_buf[ 32 ],
+       char            attrset_buf[ LDAP_PVT_INTTYPE_CHARS( unsigned long ) ],
+                       expiry_buf[ LDAP_PVT_INTTYPE_CHARS( unsigned long ) ],
                        *ptr;
        ber_len_t       attrset_len,
                        expiry_len;
 
        ldap_pvt_scope2bv( q->scope, &bv_scope );
        filter2bv_x( op, q->filter, &bv_filter );
-       attrset_len = snprintf( attrset_buf, sizeof( attrset_buf ),
+       attrset_len = sprintf( attrset_buf,
                "%lu", (unsigned long)q->qtemp->attr_set_index );
-       expiry_len = snprintf( expiry_buf, sizeof( expiry_buf ),
+       expiry_len = sprintf( expiry_buf,
                "%lu", (unsigned long)q->expiry_time );
 
        urlbv->bv_len = STRLENOF( "ldap:///" )
@@ -1696,7 +1697,7 @@ pcache_remove_entries_from_cache(
        Filter          f = { 0 };
        char            filtbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE + STRLENOF( "(entryUUID=)" ) ];
        AttributeAssertion ava = ATTRIBUTEASSERTION_INIT;
-       AttributeName   attrs[ 2 ] = { 0 };
+       AttributeName   attrs[ 2 ] = {{{ 0 }}};
        int             s, rc;
 
        if ( op == NULL ) {
@@ -1811,7 +1812,7 @@ pcache_remove_entry_queries_from_cache(
        Filter                  f = { 0 };
        char                    filter_str[ LDAP_LUTIL_UUIDSTR_BUFSIZE + STRLENOF( "(queryId=)" ) ];
        AttributeAssertion      ava = ATTRIBUTEASSERTION_INIT;
-       AttributeName           attrs[ 2 ] = { 0 };
+       AttributeName           attrs[ 2 ] = {{{ 0 }}};
        int                     rc;
 
        BerVarray               vals = NULL;
@@ -1963,7 +1964,7 @@ pcache_op_cleanup( Operation *op, SlapReply *rs ) {
                if ( !si->over ) {
                        /* check if the entry contains undefined
                         * attributes/objectClasses (ITS#5680) */
-                       if ( test_filter( op, rs->sr_entry, si->query.filter ) != LDAP_COMPARE_TRUE ) {
+                       if ( cm->check_cacheability && test_filter( op, rs->sr_entry, si->query.filter ) != LDAP_COMPARE_TRUE ) {
                                Debug( pcache_debug, "%s: query not cacheable because of schema issues in DN \"%s\"\n",
                                        op->o_log_prefix, rs->sr_entry->e_name.bv_val, 0 );
                                goto over;
@@ -2315,6 +2316,9 @@ pcache_op_search(
                return rs->sr_err;
        }
 
+       /* pickup runtime ACL changes */
+       cm->db.be_acl = op->o_bd->be_acl;
+
        tempstr.bv_val = op->o_tmpalloc( op->ors_filterstr.bv_len+1, op->o_tmpmemctx );
        tempstr.bv_len = 0;
        if ( filter2template( op, op->ors_filter, &tempstr, &filter_attrs,
@@ -2645,31 +2649,27 @@ static ConfigTable pccfg[] = {
                "( OLcfgOvAt:2.6 NAME 'olcProxySaveQueries' "
                        "DESC 'Save cached queries for hot restart' "
                        "SYNTAX OMsBoolean )", NULL, NULL },
+       { "proxyCheckCacheability", "TRUE|FALSE",
+               2, 2, 0, ARG_ON_OFF|ARG_OFFSET, (void *)offsetof(cache_manager, check_cacheability),
+               "( OLcfgOvAt:2.7 NAME 'olcProxyCheckCacheability' "
+                       "DESC 'Check whether the results of a query are cacheable, e.g. for schema issues' "
+                       "SYNTAX OMsBoolean )", NULL, NULL },
 
        { NULL, NULL, 0, 0, 0, ARG_IGNORED }
 };
 
-/* Need to no-op this keyword for dynamic config */
-static ConfigTable pcdummy[] = {
-       { "", "", 0, 0, 0, ARG_IGNORED,
-               NULL, "( OLcfgGlAt:13 NAME 'olcDatabase' "
-                       "DESC 'The backend type for a database instance' "
-                       "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
-       { NULL, NULL, 0, 0, 0, ARG_IGNORED }
-};
-
 static ConfigOCs pcocs[] = {
        { "( OLcfgOvOc:2.1 "
                "NAME 'olcPcacheConfig' "
                "DESC 'ProxyCache configuration' "
                "SUP olcOverlayConfig "
                "MUST ( olcProxyCache $ olcProxyAttrset $ olcProxyTemplate ) "
-               "MAY ( olcProxyResponseCB $ olcProxyCacheQueries $ olcProxySaveQueries ) )",
+               "MAY ( olcProxyResponseCB $ olcProxyCacheQueries $ olcProxySaveQueries $ olcProxyCheckCacheability ) )",
                Cft_Overlay, pccfg, NULL, pc_cfadd },
        { "( OLcfgOvOc:2.2 "
                "NAME 'olcPcacheDatabase' "
                "DESC 'Cache database configuration' "
-               "AUXILIARY )", Cft_Misc, pcdummy, pc_ldadd },
+               "AUXILIARY )", Cft_Misc, olcDatabaseDummy, pc_ldadd },
        { NULL, 0, NULL }
 };
 
@@ -2715,7 +2715,7 @@ pc_cfadd( Operation *op, SlapReply *rs, Entry *p, ConfigArgs *ca )
        /* FIXME: should not hardcode "olcDatabase" here */
        bv.bv_len = snprintf( ca->cr_msg, sizeof( ca->cr_msg ),
                "olcDatabase=%s", cm->db.bd_info->bi_type );
-       if ( bv.bv_len < 0 || bv.bv_len >= sizeof( ca->cr_msg ) ) {
+       if ( bv.bv_len >= sizeof( ca->cr_msg ) ) {
                return -1;
        }
        bv.bv_val = ca->cr_msg;
@@ -3148,7 +3148,7 @@ pcache_db_init(
        cm->db = *be;
        SLAP_DBFLAGS(&cm->db) |= SLAP_DBFLAG_NO_SCHEMA_CHECK;
        cm->db.be_private = NULL;
-       cm->db.be_pcl_mutexp = &cm->db.be_pcl_mutex;
+       cm->db.bd_self = &cm->db;
        cm->qm = qm;
        cm->numattrsets = 0;
        cm->num_entries_limit = 5;
@@ -3157,6 +3157,7 @@ pcache_db_init(
        cm->cur_entries = 0;
        cm->max_queries = 10000;
        cm->save_queries = 0;
+       cm->check_cacheability = 0;
        cm->response_cb = PCACHE_RESPONSE_CB_TAIL;
        cm->defer_db_open = 1;
        cm->cc_period = 1000;
@@ -3260,7 +3261,7 @@ pcache_db_open2(
                        BerVarray       vals = NULL;
                        Filter          f = { 0 }, f2 = { 0 };
                        AttributeAssertion      ava = ATTRIBUTEASSERTION_INIT;
-                       AttributeName   attrs[ 2 ] = { 0 };
+                       AttributeName   attrs[ 2 ] = {{{ 0 }}};
 
                        connection_fake_init( &conn, &opbuf, thrctx );
                        op = &opbuf.ob_op;
@@ -3426,7 +3427,7 @@ pcache_db_close(
                slap_callback   cb = { 0 };
 
                SlapReply       rs = { REP_RESULT };
-               Modifications   mod = { 0 };
+               Modifications   mod = {{ 0 }};
 
                thrctx = ldap_pvt_thread_pool_context();
 
@@ -3799,8 +3800,8 @@ pcache_exop_query_delete(
 
        struct berval   uuid = BER_BVNULL,
                        *uuidp = NULL;
-       char            buf[ SLAP_TEXT_BUFLEN ] = { '\0' };
-       int             len = 0;
+       char            buf[ SLAP_TEXT_BUFLEN ];
+       unsigned        len;
        ber_tag_t       tag = LBER_DEFAULT;
 
        if ( LogTest( LDAP_DEBUG_STATS ) ) {
@@ -3818,7 +3819,7 @@ pcache_exop_query_delete(
                assert( !BER_BVISNULL( &op->o_req_ndn ) );
                len = snprintf( buf, sizeof( buf ), " dn=\"%s\"", op->o_req_ndn.bv_val );
 
-               if ( !BER_BVISNULL( &uuid ) ) {
+               if ( !BER_BVISNULL( &uuid ) && len < sizeof( buf ) ) {
                        snprintf( &buf[ len ], sizeof( buf ) - len, " queryId=\"%s\"", uuid.bv_val );
                }
 
@@ -3988,11 +3989,6 @@ pcache_initialize()
        code = config_register_schema( pccfg, pcocs );
        if ( code ) return code;
 
-       {
-               const char *text;
-               code = slap_str2ad( "olcDatabase", &pcdummy[0].ad, &text );
-               if ( code ) return code;
-       }
        return overlay_register( &pcache );
 }