]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/overlays/pcache.c
fix wrong response tags (ITS4182; consequence of fixing ITS#4173)
[openldap] / servers / slapd / overlays / pcache.c
index b6f433b5cc008a20d5a3edd712f03f2dbfb92292..b34ab149ad97213a2a029a498dc1e5e592530452 100644 (file)
@@ -186,7 +186,7 @@ merge_entry(
                        op->o_tag = LDAP_REQ_MODIFY;
                        op->orm_modlist = modlist;
                        op->o_bd->be_modify( op, &sreply );
-                       slap_mods_free( modlist );
+                       slap_mods_free( modlist, 1 );
                } else if ( rc == LDAP_REFERRAL ||
                                        rc == LDAP_NO_SUCH_OBJECT ) {
                        syncrepl_add_glue( op, e );
@@ -636,10 +636,12 @@ free_query (CachedQuery* qc)
        free(qc->q_uuid.bv_val);
        filter_free(q->filter);
        free (q->base.bv_val);
-       for (i=0; q->attrs[i].an_name.bv_val; i++) {
-               free(q->attrs[i].an_name.bv_val);
+       if ( q->attrs ) {
+               for (i=0; q->attrs[i].an_name.bv_val; i++) {
+                       free(q->attrs[i].an_name.bv_val);
+               }
+               free(q->attrs);
        }
-       free(q->attrs);
        free(qc);
 }
 
@@ -852,6 +854,7 @@ remove_query_data (
                        vals[1].bv_val = NULL;
                        vals[1].bv_len = 0;
                        mod.sml_op = LDAP_MOD_DELETE;
+                       mod.sml_flags = 0;
                        mod.sml_desc = ad_queryid;
                        mod.sml_type = ad_queryid->ad_cname;
                        mod.sml_values = vals;
@@ -984,8 +987,9 @@ filter2template(
 
        (*filter_attrs)[*filter_cnt].an_desc = ad;
        (*filter_attrs)[*filter_cnt].an_name = ad->ad_cname;
-       (*filter_attrs)[*filter_cnt+1].an_name.bv_val = NULL;
-       (*filter_attrs)[*filter_cnt+1].an_name.bv_len = 0;
+       (*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)++;
        return 0;
 }
@@ -1010,7 +1014,6 @@ cache_entries(
        slap_overinst *on = si->on;
        cache_manager *cm = on->on_bi.bi_private;
        query_manager*          qm = cm->qm;
-       int             i;
        int             return_val = 0;
        Entry           *e;
        struct berval   crp_uuid;
@@ -1166,10 +1169,11 @@ add_filter_attrs(
        *new_attrs = (AttributeName*)(op->o_tmpalloc((count+1)*
                sizeof(AttributeName), op->o_tmpmemctx));
        if (attrs == NULL) {
-               (*new_attrs)[0].an_name.bv_val = "*";
-               (*new_attrs)[0].an_name.bv_len = 1;
-               (*new_attrs)[1].an_name.bv_val = NULL;
-               (*new_attrs)[1].an_name.bv_len = 0;
+               BER_BVSTR( &(*new_attrs)[0].an_name, "*" );
+               (*new_attrs)[0].an_desc = NULL;
+               (*new_attrs)[0].an_oc = NULL;
+               (*new_attrs)[0].an_oc_exclude = 0;
+               BER_BVZERO( &(*new_attrs)[1].an_name );
                alluser = 1;
                allop = 0;
        } else {
@@ -1177,8 +1181,7 @@ add_filter_attrs(
                        (*new_attrs)[i].an_name = attrs[i].an_name;
                        (*new_attrs)[i].an_desc = attrs[i].an_desc;
                }
-               (*new_attrs)[count].an_name.bv_val = NULL;
-               (*new_attrs)[count].an_name.bv_len = 0;
+               BER_BVZERO( &(*new_attrs)[count].an_name );
                alluser = an_find(*new_attrs, &AllUser);
                allop = an_find(*new_attrs, &AllOper);
        }
@@ -1195,10 +1198,47 @@ add_filter_attrs(
                                        (count+2)*sizeof(AttributeName), op->o_tmpmemctx));
                (*new_attrs)[count].an_name = filter_attrs[i].an_name;
                (*new_attrs)[count].an_desc = filter_attrs[i].an_desc;
+               (*new_attrs)[count].an_oc = NULL;
+               (*new_attrs)[count].an_oc_exclude = 0;
                count++;
-               (*new_attrs)[count].an_name.bv_val = NULL;
-               (*new_attrs)[count].an_name.bv_len = 0;
+               BER_BVZERO( &(*new_attrs)[count].an_name );
+       }
+}
+
+/* NOTE: this is a quick workaround to let pcache minimally interact
+ * with pagedResults.  A more articulated solutions would be to
+ * perform the remote query without control and cache all results,
+ * performing the pagedResults search only within the client
+ * and the proxy.  This requires pcache to understand pagedResults. */
+static int
+proxy_cache_chk_controls(
+       Operation       *op,
+       SlapReply       *rs )
+{
+       const char      *non = "";
+       const char      *stripped = "";
+
+       switch( op->o_pagedresults ) {
+       case SLAP_CONTROL_NONCRITICAL:
+               non = "non-";
+               stripped = "; stripped";
+               /* fallthru */
+
+       case SLAP_CONTROL_CRITICAL:
+               Debug( LDAP_DEBUG_ANY, "%s: "
+                       "%scritical pagedResults control "
+                       "disabled with proxy cache%s.\n",
+                       op->o_log_prefix, non, stripped );
+               
+               slap_remove_control( op, rs, slap_cids.sc_pagedResults, NULL );
+               break;
+
+       default:
+               rs->sr_err = SLAP_CB_CONTINUE;
+               break;
        }
+
+       return rs->sr_err;
 }
 
 static int
@@ -1215,7 +1255,6 @@ proxy_cache_search(
        int i = -1;
 
        AttributeName   *filter_attrs = NULL;
-       AttributeName   *new_attrs = NULL;
 
        Query           query;
 
@@ -1238,6 +1277,9 @@ proxy_cache_search(
        Debug( LDAP_DEBUG_ANY, "query template of incoming query = %s\n",
                                        tempstr.bv_val, 0, 0 );
 
+       /* FIXME: cannot cache/answer requests with pagedResults control */
+       
+
        /* find attr set */
        attr_set = get_attr_set(op->ors_attrs, qm, cm->numattrsets);
 
@@ -1312,15 +1354,18 @@ proxy_cache_search(
                        for ( count = 0; !BER_BVISNULL( &op->ors_attrs[ count ].an_name ); count++ ) {
                                ber_dupbv( &query.attrs[count].an_name, &op->ors_attrs[count].an_name );
                                query.attrs[count].an_desc = op->ors_attrs[count].an_desc;
+                               query.attrs[count].an_oc = op->ors_attrs[count].an_oc;
+                               query.attrs[count].an_oc_exclude = op->ors_attrs[count].an_oc_exclude;
                        }
                        if ( oc_attr_absent ) {
                                query.attrs[ count ].an_desc = slap_schema.si_ad_objectClass;
                                ber_dupbv( &query.attrs[count].an_name,
                                        &slap_schema.si_ad_objectClass->ad_cname );
+                               query.attrs[ count ].an_oc = NULL;
+                               query.attrs[ count ].an_oc_exclude = 0;
                                count++;
                        }
-                       query.attrs[ count ].an_name.bv_val = NULL;
-                       query.attrs[ count ].an_name.bv_len = 0;
+                       BER_BVZERO( &query.attrs[ count ].an_name );
                }
                add_filter_attrs(op, &op->ors_attrs, query.attrs, filter_attrs);
 
@@ -1417,7 +1462,7 @@ consistency_check(
        cache_manager *cm = on->on_bi.bi_private;
        query_manager *qm = cm->qm;
        Connection conn = {0};
-       char opbuf[OPERATION_BUFFER_SIZE];
+       OperationBuffer opbuf;
        Operation *op;
 
        SlapReply rs = {REP_RESULT};
@@ -1425,7 +1470,7 @@ consistency_check(
        int i, return_val, pause = 1;
        QueryTemplate* templ;
 
-       op = (Operation *)opbuf;
+       op = (Operation *) &opbuf;
        connection_fake_init( &conn, op, ctx );
 
        op->o_bd = &cm->db;
@@ -1603,7 +1648,7 @@ static ConfigTable pccfg[] = {
                        "DESC 'Filter template, attrset, and cache TTL' "
                        "SYNTAX OMsDirectoryString )", NULL, NULL },
        { "response-callback", "head|tail(default)",
-               2, 2, 0, ARG_MAGIC|ARG_STRING|PC_RESP, pc_cf_gen,
+               2, 2, 0, ARG_MAGIC|PC_RESP, pc_cf_gen,
                "( OLcfgOvAt:2.4 NAME 'olcProxyResponseCB' "
                        "DESC 'Response callback position in overlay stack' "
                        "SYNTAX OMsDirectoryString )", NULL, NULL },
@@ -1652,8 +1697,12 @@ pc_cfadd( Operation *op, SlapReply *rs, Entry *p, ConfigArgs *ca )
        bv.bv_len = sprintf( ca->msg, "olcDatabase=%s", cm->db.bd_info->bi_type );
        bv.bv_val = ca->msg;
        ca->be = &cm->db;
-       config_build_entry( op, rs, pe, ca, &bv, cm->db.bd_info->bi_cf_ocs,
-               &pcocs[1] );
+
+       /* We can only create this entry if the database is table-driven
+        */
+       if ( cm->db.bd_info->bi_cf_ocs )
+               config_build_entry( op, rs, pe, ca, &bv, cm->db.bd_info->bi_cf_ocs,
+                       &pcocs[1] );
 
        return 0;
 }
@@ -1706,7 +1755,7 @@ pc_cf_gen( ConfigArgs *c )
                        break;
                case PC_TEMP:
                        for (i=0; i<cm->numtemplates; i++) {
-                               bv.bv_len = sprintf( c->msg, " %d %d",
+                               bv.bv_len = sprintf( c->msg, " %d %ld",
                                        qm->templates[i].attr_set_index,
                                        qm->templates[i].ttl );
                                bv.bv_len += qm->templates[i].querystr.bv_len + 2;
@@ -1723,11 +1772,9 @@ pc_cf_gen( ConfigArgs *c )
                        break;
                case PC_RESP:
                        if ( cm->response_cb == PCACHE_RESPONSE_CB_HEAD ) {
-                               bv.bv_val = "head";
-                               bv.bv_len = STRLENOF("head");
+                               BER_BVSTR( &bv, "head" );
                        } else {
-                               bv.bv_val = "tail";
-                               bv.bv_len = STRLENOF("tail");
+                               BER_BVSTR( &bv, "tail" );
                        }
                        value_add_one( &c->rvalue_vals, &bv );
                        break;
@@ -1752,21 +1799,11 @@ pc_cf_gen( ConfigArgs *c )
                        Debug( LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
                        return( 1 );
                }
-               cm->db.bd_info = backend_info( c->argv[1] );
-               if ( !cm->db.bd_info ) {
+               if ( !backend_db_init( c->argv[1], &cm->db )) {
                        sprintf( c->msg, "unknown backend type" );
                        Debug( LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
                        return( 1 );
                }
-               if ( cm->db.bd_info->bi_db_init( &cm->db ) ) {
-                       sprintf( c->msg, "backend %s init failed", c->argv[1] );
-                       Debug( LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
-                       return( 1 );
-               }
-
-               /* This type is in use, needs to be opened */
-               cm->db.bd_info->bi_nDB++;
-
                cm->max_entries = atoi( c->argv[2] );
 
                cm->num_entries_limit = atoi( c->argv[4] );
@@ -1804,9 +1841,10 @@ pc_cf_gen( ConfigArgs *c )
                                        qm->attr_sets[num].count = 0;
                                        return 1;
                                }
+                               attr_name->an_oc = NULL;
+                               attr_name->an_oc_exclude = 0;
                                attr_name++;
-                               attr_name->an_name.bv_val = NULL;
-                               attr_name->an_name.bv_len = 0;
+                               BER_BVZERO( &attr_name->an_name );
                        }
                }
                break;
@@ -1931,17 +1969,6 @@ proxy_cache_open(
        slap_overinst   *on = (slap_overinst *)be->bd_info;
        cache_manager   *cm = on->on_bi.bi_private;
        int             rc = 0;
-       int             i;
-
-       /* consistency check (add more...) */
-       for ( i = 0; i < cm->numattrsets; i++ ) {
-               if ( cm->qm->attr_sets[i].attrs == NULL ) {
-                       Debug( LDAP_DEBUG_ANY, "proxy_cache_open(): "
-                               "attr set %d (of %d) missing\n",
-                               i, cm->numattrsets, 0 );
-                       return 1;
-               }
-       }
 
        /* need to inherit something from the original database... */
        cm->db.be_def_limit = be->be_def_limit;
@@ -2026,17 +2053,24 @@ proxy_cache_destroy(
        slap_overinst *on = (slap_overinst *)be->bd_info;
        cache_manager *cm = on->on_bi.bi_private;
        query_manager *qm = cm->qm;
-       int rc = 0;
 
-       if ( cm->db.bd_info->bi_db_destroy ) {
-               rc = cm->db.bd_info->bi_db_destroy( &cm->db );
-       }
-       ldap_pvt_thread_mutex_destroy(&qm->lru_mutex);
-       ldap_pvt_thread_mutex_destroy(&cm->cache_mutex);
-       ldap_pvt_thread_mutex_destroy(&cm->remove_mutex);
+       /* cleanup stuff inherited from the original database... */
+       cm->db.be_suffix = NULL;
+       cm->db.be_nsuffix = NULL;
+       BER_BVZERO( &cm->db.be_rootdn );
+       BER_BVZERO( &cm->db.be_rootndn );
+       BER_BVZERO( &cm->db.be_rootpw );
+       /* FIXME: there might be more... */
+
+       backend_destroy_one( &cm->db, 0 );
+
+       ldap_pvt_thread_mutex_destroy( &qm->lru_mutex );
+       ldap_pvt_thread_mutex_destroy( &cm->cache_mutex );
+       ldap_pvt_thread_mutex_destroy( &cm->remove_mutex );
        free( qm );
        free( cm );
-       return rc;
+
+       return 0;
 }
 
 static slap_overinst proxy_cache;
@@ -2067,7 +2101,7 @@ int pcache_init()
                return code;
        }
 
-       proxy_cache.on_bi.bi_type = "proxycache";
+       proxy_cache.on_bi.bi_type = "pcache";
        proxy_cache.on_bi.bi_db_init = proxy_cache_init;
        proxy_cache.on_bi.bi_db_config = proxy_cache_config;
        proxy_cache.on_bi.bi_db_open = proxy_cache_open;
@@ -2075,6 +2109,8 @@ int pcache_init()
        proxy_cache.on_bi.bi_db_destroy = proxy_cache_destroy;
        proxy_cache.on_bi.bi_op_search = proxy_cache_search;
 
+       proxy_cache.on_bi.bi_chk_controls = proxy_cache_chk_controls;
+
        proxy_cache.on_bi.bi_cf_ocs = pcocs;
 
        code = config_register_schema( pccfg, pcocs );