]> git.sur5r.net Git - openldap/commitdiff
use pooled memory whenever appropriate
authorPierangelo Masarati <ando@openldap.org>
Sun, 13 Nov 2005 21:51:13 +0000 (21:51 +0000)
committerPierangelo Masarati <ando@openldap.org>
Sun, 13 Nov 2005 21:51:13 +0000 (21:51 +0000)
servers/slapd/back-sql/init.c
servers/slapd/back-sql/operational.c
servers/slapd/back-sql/proto-sql.h
servers/slapd/back-sql/schema-map.c
servers/slapd/back-sql/search.c
servers/slapd/back-sql/util.c

index 40a4478c1f2219f7280ab19b6643d4caecaac9d6..48396c9753c580b27f6849e068efb272da8b84b7 100644 (file)
@@ -335,7 +335,7 @@ backsql_db_open(
                         * UPPER(ldap_entries.dn) LIKE UPPER(CONCAT('%',?))
                         */
 
-                       backsql_strfcat( &bb, "blbbb",
+                       backsql_strfcat_x( &bb, NULL, "blbbb",
                                        &bi->sql_upper_func,
                                        (ber_len_t)STRLENOF( "(ldap_entries.dn) LIKE " ),
                                                "(ldap_entries.dn) LIKE ",
@@ -349,7 +349,7 @@ backsql_db_open(
                         * ldap_entries.dn LIKE CONCAT('%',?)
                         */
 
-                       backsql_strfcat( &bb, "lb",
+                       backsql_strfcat_x( &bb, NULL, "lb",
                                        (ber_len_t)STRLENOF( "ldap_entries.dn LIKE " ),
                                                "ldap_entries.dn LIKE ",
                                        &concat );
@@ -373,7 +373,7 @@ backsql_db_open(
                         * UPPER(ldap_entries.dn) LIKE UPPER(CONCAT('%,',?))
                         */
 
-                       backsql_strfcat( &bb, "blbl",
+                       backsql_strfcat_x( &bb, NULL, "blbl",
                                        &bi->sql_upper_func,
                                        (ber_len_t)STRLENOF( "(ldap_entries.dn)=" ),
                                                "(ldap_entries.dn)=",
@@ -386,7 +386,7 @@ backsql_db_open(
                         * ldap_entries.dn LIKE CONCAT('%,',?)
                         */
 
-                       backsql_strfcat( &bb, "l",
+                       backsql_strfcat_x( &bb, NULL, "l",
                                        (ber_len_t)STRLENOF( "ldap_entries.dn=?" ),
                                                "ldap_entries.dn=?");
                }
@@ -497,20 +497,20 @@ backsql_db_open(
        if ( bi->sql_id_query == NULL ) {
                /* no custom id_query provided */
                if ( bi->sql_upper_func.bv_val == NULL ) {
-                       backsql_strcat( &bb, backsql_id_query, "dn=?", NULL );
+                       backsql_strcat_x( &bb, NULL, backsql_id_query, "dn=?", NULL );
 
                } else {
                        if ( BACKSQL_HAS_LDAPINFO_DN_RU( bi ) ) {
-                               backsql_strcat( &bb, backsql_id_query,
+                               backsql_strcat_x( &bb, NULL, backsql_id_query,
                                                "dn_ru=?", NULL );
                        } else {
                                if ( BACKSQL_USE_REVERSE_DN( bi ) ) {
-                                       backsql_strfcat( &bb, "sbl",
+                                       backsql_strfcat_x( &bb, NULL, "sbl",
                                                        backsql_id_query,
                                                        &bi->sql_upper_func, 
                                                        (ber_len_t)STRLENOF( "(dn)=?" ), "(dn)=?" );
                                } else {
-                                       backsql_strfcat( &bb, "sblbcb",
+                                       backsql_strfcat_x( &bb, NULL, "sblbcb",
                                                        backsql_id_query,
                                                        &bi->sql_upper_func, 
                                                        (ber_len_t)STRLENOF( "(dn)=" ), "(dn)=",
@@ -528,7 +528,7 @@ backsql_db_open(
         */
        BER_BVZERO( &bb.bb_val );
        bb.bb_len = 0;
-       backsql_strfcat( &bb, "sbsb",
+       backsql_strfcat_x( &bb, NULL, "sbsb",
                        "SELECT COUNT(distinct subordinates.id) "
                        "FROM ldap_entries,ldap_entries ",
                        &bi->sql_aliasing, "subordinates "
@@ -541,7 +541,7 @@ backsql_db_open(
         */
        BER_BVZERO( &bb.bb_val );
        bb.bb_len = 0;
-       backsql_strfcat( &bb, "sbbsbsbbsb",
+       backsql_strfcat_x( &bb, NULL, "sbbsbsbbsb",
                        " ", &bi->sql_aliasing, &bi->sql_aliasing_quote,
                        "objectClass", &bi->sql_aliasing_quote,
                        ",ldap_entries.dn ", &bi->sql_aliasing,
index 1423e2156a88cf1d331527d98a621fd7996a9c9f..e99741a6d9b4ae530e504a5f971f32c889f661cf 100644 (file)
@@ -83,7 +83,7 @@ backsql_operational_entryCSN( Operation *op )
        BER_BVZERO( &a->a_vals[ 1 ] );
 
 #ifdef BACKSQL_SYNCPROV
-       if ( op->o_sync && op->o_tag == LDAP_REQ_SEARCH ) {
+       if ( op->o_sync && op->o_tag == LDAP_REQ_SEARCH && op->o_private != NULL ) {
                assert( op->o_private != NULL );
 
                entryCSN = *((struct berval *)op->o_private);
index 16a7ec66833b89b82deba75f0a6470fdd1e64ac4..a427f205e4c5fce98777d7ac68f0bc0f0cb9a1a4 100644 (file)
@@ -242,8 +242,8 @@ extern char
 extern char 
        backsql_check_dn_ru_query[];
 
-struct berbuf * backsql_strcat( struct berbuf *dest, ... );
-struct berbuf * backsql_strfcat( struct berbuf *dest, const char *fmt, ... );
+struct berbuf * backsql_strcat_x( struct berbuf *dest, void *memctx, ... );
+struct berbuf * backsql_strfcat_x( struct berbuf *dest, void *memctx, const char *fmt, ... );
 
 int backsql_entry_addattr( Entry *e, AttributeDescription *ad, 
                struct berval *at_val, void *memctx );
index ae97d27cf0e53ab9be99587cc9d8500e4c67fce5..11056f039e7dc044ddf6cee04e9246f40ac24feb 100644 (file)
@@ -106,7 +106,7 @@ backsql_make_attr_query(
 {
        struct berbuf   bb = BB_NULL;
 
-       backsql_strfcat( &bb, "lblbbbblblbcbl", 
+       backsql_strfcat_x( &bb, NULL, "lblbbbblblbcbl", 
                        (ber_len_t)STRLENOF( "SELECT " ), "SELECT ", 
                        &at_map->bam_sel_expr, 
                        (ber_len_t)STRLENOF( " " ), " ",
@@ -123,12 +123,12 @@ backsql_make_attr_query(
                        (ber_len_t)STRLENOF( "=?" ), "=?" );
 
        if ( !BER_BVISNULL( &at_map->bam_join_where ) ) {
-               backsql_strfcat( &bb, "lb",
+               backsql_strfcat_x( &bb, NULL, "lb",
                                (ber_len_t)STRLENOF( " AND " ), " AND ", 
                                &at_map->bam_join_where );
        }
 
-       backsql_strfcat( &bb, "lbbb", 
+       backsql_strfcat_x( &bb, NULL, "lbbb", 
                        (ber_len_t)STRLENOF( " ORDER BY " ), " ORDER BY ",
                        &bi->sql_aliasing_quote,
                        &at_map->bam_ad->ad_cname,
@@ -140,7 +140,7 @@ backsql_make_attr_query(
        /* Query to count how many rows will be returned. */
        BER_BVZERO( &bb.bb_val );
        bb.bb_len = 0;
-       backsql_strfcat( &bb, "lblbcbl", 
+       backsql_strfcat_x( &bb, NULL, "lblbcbl", 
                        (ber_len_t)STRLENOF( "SELECT COUNT(*) FROM " ),
                                "SELECT COUNT(*) FROM ", 
                        &at_map->bam_from_tbls, 
@@ -151,7 +151,7 @@ backsql_make_attr_query(
                        (ber_len_t)STRLENOF( "=?" ), "=?" );
 
        if ( !BER_BVISNULL( &at_map->bam_join_where ) ) {
-               backsql_strfcat( &bb, "lb",
+               backsql_strfcat_x( &bb, NULL, "lb",
                                (ber_len_t)STRLENOF( " AND " ), " AND ", 
                                &at_map->bam_join_where );
        }
@@ -189,7 +189,7 @@ backsql_add_sysmaps( backsql_info *bi, backsql_oc_map_rec *oc_map )
 
        BER_BVZERO( &bb.bb_val );
        bb.bb_len = 0;
-       backsql_strfcat( &bb, "lbcblb",
+       backsql_strfcat_x( &bb, NULL, "lbcblb",
                        (ber_len_t)STRLENOF( "ldap_entries.id=ldap_entry_objclasses.entry_id AND ldap_entries.keyval=" ),
                                "ldap_entries.id=ldap_entry_objclasses.entry_id AND ldap_entries.keyval=",
                        &oc_map->bom_keytbl, 
@@ -254,7 +254,7 @@ backsql_add_sysmaps( backsql_info *bi, backsql_oc_map_rec *oc_map )
        ch_free( at_map->bam_join_where.bv_val );
        BER_BVZERO( &bb.bb_val );
        bb.bb_len = 0;
-       backsql_strfcat( &bb, "lbcblb",
+       backsql_strfcat_x( &bb, NULL, "lbcblb",
                        (ber_len_t)STRLENOF( /* "ldap_entries.id=ldap_entry_objclasses.entry_id AND " */ "ldap_entries.keyval=" ),
                                /* "ldap_entries.id=ldap_entry_objclasses.entry_id AND " */ "ldap_entries.keyval=",
                        &oc_map->bom_keytbl, 
@@ -405,7 +405,7 @@ backsql_oc_get_attr_mapping( void *v_oc, void *v_bas )
                {
                        struct berbuf   bb = BB_NULL;
 
-                       backsql_strfcat( &bb, "bcbc",
+                       backsql_strfcat_x( &bb, NULL, "bcbc",
                                        &bas->bas_bi->sql_upper_func,
                                        '(' /* ) */ ,
                                        &at_map->bam_sel_expr,
index 44b061777238892f449427af4bef90033241171c..dcd349ffa71750c2b7ef62c2c4bd7711b1dc6470 100644 (file)
@@ -345,7 +345,8 @@ backsql_process_filter_list( backsql_srch_info *bsi, Filter *f, int op )
                return 0;
        }
 
-       backsql_strfcat( &bsi->bsi_flt_where, "c", '(' /* ) */  );
+       backsql_strfcat_x( &bsi->bsi_flt_where,
+                       bsi->bsi_op->o_tmpmemctx, "c", '(' /* ) */  );
 
        while ( 1 ) {
                res = backsql_process_filter( bsi, f );
@@ -364,20 +365,23 @@ backsql_process_filter_list( backsql_srch_info *bsi, Filter *f, int op )
 
                switch ( op ) {
                case LDAP_FILTER_AND:
-                       backsql_strfcat( &bsi->bsi_flt_where, "l",
+                       backsql_strfcat_x( &bsi->bsi_flt_where,
+                                       bsi->bsi_op->o_tmpmemctx, "l",
                                        (ber_len_t)STRLENOF( " AND " ), 
                                                " AND " );
                        break;
 
                case LDAP_FILTER_OR:
-                       backsql_strfcat( &bsi->bsi_flt_where, "l",
+                       backsql_strfcat_x( &bsi->bsi_flt_where,
+                                       bsi->bsi_op->o_tmpmemctx, "l",
                                        (ber_len_t)STRLENOF( " OR " ),
                                                " OR " );
                        break;
                }
        }
 
-       backsql_strfcat( &bsi->bsi_flt_where, "c", /* ( */ ')' );
+       backsql_strfcat_x( &bsi->bsi_flt_where,
+                       bsi->bsi_op->o_tmpmemctx, "c", /* ( */ ')' );
 
        return 1;
 }
@@ -482,7 +486,8 @@ backsql_process_sub_filter( backsql_srch_info *bsi, Filter *f,
         * SQL filters are more liberal.
         */
 
-       backsql_strfcat( &bsi->bsi_flt_where, "c", '(' /* ) */  );
+       backsql_strfcat_x( &bsi->bsi_flt_where,
+                       bsi->bsi_op->o_tmpmemctx, "c", '(' /* ) */  );
 
        /* TimesTen */
        Debug( LDAP_DEBUG_TRACE, "backsql_process_sub_filter(%s):\n",
@@ -495,14 +500,17 @@ backsql_process_sub_filter( backsql_srch_info *bsi, Filter *f,
                 * If a pre-upper-cased version of the column 
                 * or a precompiled upper function exists, use it
                 */
-               backsql_strfcat( &bsi->bsi_flt_where, 
+               backsql_strfcat_x( &bsi->bsi_flt_where, 
+                               bsi->bsi_op->o_tmpmemctx,
                                "bl",
                                &at->bam_sel_expr_u,
                                (ber_len_t)STRLENOF( " LIKE '" ),
                                        " LIKE '" );
 
        } else {
-               backsql_strfcat( &bsi->bsi_flt_where, "bl",
+               backsql_strfcat_x( &bsi->bsi_flt_where,
+                               bsi->bsi_op->o_tmpmemctx,
+                               "bl",
                                &at->bam_sel_expr,
                                (ber_len_t)STRLENOF( " LIKE '" ), " LIKE '" );
        }
@@ -518,14 +526,18 @@ backsql_process_sub_filter( backsql_srch_info *bsi, Filter *f,
 #endif /* BACKSQL_TRACE */
 
                start = bsi->bsi_flt_where.bb_val.bv_len;
-               backsql_strfcat( &bsi->bsi_flt_where, "b",
+               backsql_strfcat_x( &bsi->bsi_flt_where,
+                               bsi->bsi_op->o_tmpmemctx,
+                               "b",
                                &f->f_sub_initial );
                if ( casefold && BACKSQL_AT_CANUPPERCASE( at ) ) {
                        ldap_pvt_str2upper( &bsi->bsi_flt_where.bb_val.bv_val[ start ] );
                }
        }
 
-       backsql_strfcat( &bsi->bsi_flt_where, "c", '%' );
+       backsql_strfcat_x( &bsi->bsi_flt_where,
+                       bsi->bsi_op->o_tmpmemctx,
+                       "c", '%' );
 
        if ( f->f_sub_any != NULL ) {
                for ( i = 0; !BER_BVISNULL( &f->f_sub_any[ i ] ); i++ ) {
@@ -539,7 +551,8 @@ backsql_process_sub_filter( backsql_srch_info *bsi, Filter *f,
 #endif /* BACKSQL_TRACE */
 
                        start = bsi->bsi_flt_where.bb_val.bv_len;
-                       backsql_strfcat( &bsi->bsi_flt_where,
+                       backsql_strfcat_x( &bsi->bsi_flt_where,
+                                       bsi->bsi_op->o_tmpmemctx,
                                        "bc",
                                        &f->f_sub_any[ i ],
                                        '%' );
@@ -563,14 +576,18 @@ backsql_process_sub_filter( backsql_srch_info *bsi, Filter *f,
 #endif /* BACKSQL_TRACE */
 
                start = bsi->bsi_flt_where.bb_val.bv_len;
-               backsql_strfcat( &bsi->bsi_flt_where, "b",
+               backsql_strfcat_x( &bsi->bsi_flt_where,
+                               bsi->bsi_op->o_tmpmemctx,
+                               "b",
                                &f->f_sub_final );
                if ( casefold && BACKSQL_AT_CANUPPERCASE( at ) ) {
                        ldap_pvt_str2upper( &bsi->bsi_flt_where.bb_val.bv_val[ start ] );
                }
        }
 
-       backsql_strfcat( &bsi->bsi_flt_where, "l", 
+       backsql_strfcat_x( &bsi->bsi_flt_where,
+                       bsi->bsi_op->o_tmpmemctx,
+                       "l", 
                        (ber_len_t)STRLENOF( /* (' */ "')" ), /* (' */ "')" );
  
        return 1;
@@ -584,18 +601,21 @@ backsql_merge_from_tbls( backsql_srch_info *bsi, struct berval *from_tbls )
        }
 
        if ( !BER_BVISNULL( &bsi->bsi_from.bb_val ) ) {
-               char    *start, *end, *tmp;
+               char            *start, *end;
+               struct berval   tmp;
 
-               tmp = ch_strdup( from_tbls->bv_val );
+               ber_dupbv_x( &tmp, from_tbls, bsi->bsi_op->o_tmpmemctx );
 
-               for ( start = tmp, end = strchr( start, ',' ); start; ) {
+               for ( start = tmp.bv_val, end = strchr( start, ',' ); start; ) {
                        if ( end ) {
                                end[0] = '\0';
                        }
 
                        if ( strstr( bsi->bsi_from.bb_val.bv_val, start) == NULL )
                        {
-                               backsql_strfcat( &bsi->bsi_from, "cs", ',', start );
+                               backsql_strfcat_x( &bsi->bsi_from,
+                                               bsi->bsi_op->o_tmpmemctx,
+                                               "cs", ',', start );
                        }
 
                        if ( end ) {
@@ -611,10 +631,12 @@ backsql_merge_from_tbls( backsql_srch_info *bsi, struct berval *from_tbls )
                        }
                }
 
-               ch_free( tmp );
+               bsi->bsi_op->o_tmpfree( tmp.bv_val, bsi->bsi_op->o_tmpmemctx );
 
        } else {
-               backsql_strfcat( &bsi->bsi_from, "b", from_tbls );
+               backsql_strfcat_x( &bsi->bsi_from,
+                               bsi->bsi_op->o_tmpmemctx,
+                               "b", from_tbls );
        }
 
        return LDAP_SUCCESS;
@@ -651,11 +673,15 @@ backsql_process_filter( backsql_srch_info *bsi, Filter *f )
                break;
 
        case LDAP_FILTER_NOT:
-               backsql_strfcat( &bsi->bsi_flt_where, "l",
+               backsql_strfcat_x( &bsi->bsi_flt_where,
+                               bsi->bsi_op->o_tmpmemctx,
+                               "l",
                                (ber_len_t)STRLENOF( "NOT (" /* ) */ ),
                                        "NOT (" /* ) */ );
                rc = backsql_process_filter( bsi, f->f_not );
-               backsql_strfcat( &bsi->bsi_flt_where, "c", /* ( */ ')' );
+               backsql_strfcat_x( &bsi->bsi_flt_where,
+                               bsi->bsi_op->o_tmpmemctx,
+                               "c", /* ( */ ')' );
                done = 1;
                break;
 
@@ -674,7 +700,9 @@ backsql_process_filter( backsql_srch_info *bsi, Filter *f )
                         * ldap_entries AS attributeName WHERE attributeName.dn
                         * like '%attributeName=value%'"
                         */
-                       backsql_strfcat( &bsi->bsi_flt_where, "l",
+                       backsql_strfcat_x( &bsi->bsi_flt_where,
+                                       bsi->bsi_op->o_tmpmemctx,
+                                       "l",
                                        (ber_len_t)STRLENOF( "1=1" ), "1=1" );
                        bsi->bsi_status = LDAP_SUCCESS;
                        rc = 1;
@@ -734,7 +762,9 @@ backsql_process_filter( backsql_srch_info *bsi, Filter *f )
 
                                backsql_merge_from_tbls( bsi, &ldap_entry_objclasses );
 
-                               backsql_strfcat( &bsi->bsi_flt_where, "lbl",
+                               backsql_strfcat_x( &bsi->bsi_flt_where,
+                                               bsi->bsi_op->o_tmpmemctx,
+                                               "lbl",
                                                (ber_len_t)STRLENOF( "(2=2 OR (ldap_entries.id=ldap_entry_objclasses.entry_id AND ldap_entry_objclasses.oc_name='" /* ')) */ ),
                                                        "(2=2 OR (ldap_entries.id=ldap_entry_objclasses.entry_id AND ldap_entry_objclasses.oc_name='" /* ')) */,
                                                &bsi->bsi_oc->bom_oc->soc_cname,
@@ -749,7 +779,9 @@ backsql_process_filter( backsql_srch_info *bsi, Filter *f )
                }
 
                case LDAP_FILTER_PRESENT:
-                       backsql_strfcat( &bsi->bsi_flt_where, "l",
+                       backsql_strfcat_x( &bsi->bsi_flt_where,
+                                       bsi->bsi_op->o_tmpmemctx,
+                                       "l",
                                        (ber_len_t)STRLENOF( "3=3" ), "3=3" );
                        bsi->bsi_status = LDAP_SUCCESS;
                        rc = 1;
@@ -788,21 +820,27 @@ backsql_process_filter( backsql_srch_info *bsi, Filter *f )
                        }
 
 #ifdef BACKSQL_ARBITRARY_KEY
-                       backsql_strfcat( &bsi->bsi_flt_where, "bcblbc",
+                       backsql_strfcat_x( &bsi->bsi_flt_where,
+                                       bsi->bsi_op->o_tmpmemctx,
+                                       "bcblbc",
                                        &bsi->bsi_oc->bom_keytbl, '.',
                                        &bsi->bsi_oc->bom_keycol,
                                        STRLENOF( " LIKE '" ), " LIKE '",
                                        &keyval, '\'' );
 #else /* ! BACKSQL_ARBITRARY_KEY */
                        snprintf( keyvalbuf, sizeof( keyvalbuf ), "%lu", keyval );
-                       backsql_strfcat( &bsi->bsi_flt_where, "bcbcs",
+                       backsql_strfcat_x( &bsi->bsi_flt_where,
+                                       bsi->bsi_op->o_tmpmemctx,
+                                       "bcbcs",
                                        &bsi->bsi_oc->bom_keytbl, '.',
                                        &bsi->bsi_oc->bom_keycol, '=', keyvalbuf );
 #endif /* ! BACKSQL_ARBITRARY_KEY */
                        break;
 
                case LDAP_FILTER_PRESENT:
-                       backsql_strfcat( &bsi->bsi_flt_where, "l",
+                       backsql_strfcat_x( &bsi->bsi_flt_where,
+                                       bsi->bsi_op->o_tmpmemctx,
+                                       "l",
                                        (ber_len_t)STRLENOF( "4=4" ), "4=4" );
                        break;
 
@@ -820,18 +858,22 @@ backsql_process_filter( backsql_srch_info *bsi, Filter *f )
                /*
                 * support for syncrepl as producer...
                 */
+#if 0
                if ( !bsi->bsi_op->o_sync ) {
                        /* unsupported at present... */
                        bsi->bsi_status = LDAP_OTHER;
                        rc = -1;
                        goto done;
                }
+#endif
 
                bsi->bsi_flags |= ( BSQL_SF_FILTER_ENTRYCSN | BSQL_SF_RETURN_ENTRYUUID);
 
                /* if doing a syncrepl, try to return as much as possible,
                 * and always match the filter */
-               backsql_strfcat( &bsi->bsi_flt_where, "l",
+               backsql_strfcat_x( &bsi->bsi_flt_where,
+                               bsi->bsi_op->o_tmpmemctx,
+                               "l",
                                (ber_len_t)STRLENOF( "5=5" ), "5=5" );
 
                /* save for later use in operational attributes */
@@ -865,7 +907,9 @@ backsql_process_filter( backsql_srch_info *bsi, Filter *f )
                 * selecting if there are descendants of the
                 * candidate.
                 */
-               backsql_strfcat( &bsi->bsi_flt_where, "l",
+               backsql_strfcat_x( &bsi->bsi_flt_where,
+                               bsi->bsi_op->o_tmpmemctx,
+                               "l",
                                (ber_len_t)STRLENOF( "6=6" ), "6=6" );
                if ( ad == slap_schema.si_ad_hasSubordinates ) {
                        /*
@@ -898,7 +942,9 @@ backsql_process_filter( backsql_srch_info *bsi, Filter *f )
        if ( vat == NULL ) {
                /* search anyway; other parts of the filter
                 * may succeeed */
-               backsql_strfcat( &bsi->bsi_flt_where, "l",
+               backsql_strfcat_x( &bsi->bsi_flt_where,
+                               bsi->bsi_op->o_tmpmemctx,
+                               "l",
                                (ber_len_t)STRLENOF( "7=7" ), "7=7" );
                bsi->bsi_status = LDAP_SUCCESS;
                rc = 1;
@@ -908,7 +954,9 @@ backsql_process_filter( backsql_srch_info *bsi, Filter *f )
        /* if required, open extra level of parens */
        done = 0;
        if ( vat[0]->bam_next || vat[1] ) {
-               backsql_strfcat( &bsi->bsi_flt_where, "c", '(' );
+               backsql_strfcat_x( &bsi->bsi_flt_where,
+                               bsi->bsi_op->o_tmpmemctx,
+                               "c", '(' );
                done = 1;
        }
 
@@ -921,7 +969,9 @@ next:;
 
        /* if more definitions of the same attr, apply */
        if ( vat[i]->bam_next ) {
-               backsql_strfcat( &bsi->bsi_flt_where, "l",
+               backsql_strfcat_x( &bsi->bsi_flt_where,
+                               bsi->bsi_op->o_tmpmemctx,
+                               "l",
                        STRLENOF( " OR " ), " OR " );
                vat[i] = vat[i]->bam_next;
                goto next;
@@ -930,14 +980,18 @@ next:;
        /* if more descendants of the same attr, apply */
        i++;
        if ( vat[i] ) {
-               backsql_strfcat( &bsi->bsi_flt_where, "l",
+               backsql_strfcat_x( &bsi->bsi_flt_where,
+                               bsi->bsi_op->o_tmpmemctx,
+                               "l",
                        STRLENOF( " OR " ), " OR " );
                goto next;
        }
 
        /* if needed, close extra level of parens */
        if ( done ) {
-               backsql_strfcat( &bsi->bsi_flt_where, "c", ')' );
+               backsql_strfcat_x( &bsi->bsi_flt_where,
+                               bsi->bsi_op->o_tmpmemctx,
+                               "c", ')' );
        }
 
        rc = 1;
@@ -967,7 +1021,9 @@ backsql_process_filter_eq( backsql_srch_info *bsi, backsql_at_map_rec *at,
        if ( casefold && BACKSQL_AT_CANUPPERCASE( at ) ) {
                ber_len_t       start;
 
-               backsql_strfcat( &bsi->bsi_flt_where, "cbl",
+               backsql_strfcat_x( &bsi->bsi_flt_where,
+                               bsi->bsi_op->o_tmpmemctx,
+                               "cbl",
                                '(', /* ) */
                                &at->bam_sel_expr_u, 
                                (ber_len_t)STRLENOF( "='" ),
@@ -975,7 +1031,9 @@ backsql_process_filter_eq( backsql_srch_info *bsi, backsql_at_map_rec *at,
 
                start = bsi->bsi_flt_where.bb_val.bv_len;
 
-               backsql_strfcat( &bsi->bsi_flt_where, "bl",
+               backsql_strfcat_x( &bsi->bsi_flt_where,
+                               bsi->bsi_op->o_tmpmemctx,
+                               "bl",
                                filter_value, 
                                (ber_len_t)STRLENOF( /* (' */ "')" ),
                                        /* (' */ "')" );
@@ -983,7 +1041,9 @@ backsql_process_filter_eq( backsql_srch_info *bsi, backsql_at_map_rec *at,
                ldap_pvt_str2upper( &bsi->bsi_flt_where.bb_val.bv_val[ start ] );
 
        } else {
-               backsql_strfcat( &bsi->bsi_flt_where, "cblbl",
+               backsql_strfcat_x( &bsi->bsi_flt_where,
+                               bsi->bsi_op->o_tmpmemctx,
+                               "cblbl",
                                '(', /* ) */
                                &at->bam_sel_expr,
                                (ber_len_t)STRLENOF( "='" ), "='",
@@ -1008,7 +1068,9 @@ backsql_process_filter_like( backsql_srch_info *bsi, backsql_at_map_rec *at,
        if ( casefold && BACKSQL_AT_CANUPPERCASE( at ) ) {
                ber_len_t       start;
 
-               backsql_strfcat( &bsi->bsi_flt_where, "cbl",
+               backsql_strfcat_x( &bsi->bsi_flt_where,
+                               bsi->bsi_op->o_tmpmemctx,
+                               "cbl",
                                '(', /* ) */
                                &at->bam_sel_expr_u, 
                                (ber_len_t)STRLENOF( " LIKE '%" ),
@@ -1016,7 +1078,9 @@ backsql_process_filter_like( backsql_srch_info *bsi, backsql_at_map_rec *at,
 
                start = bsi->bsi_flt_where.bb_val.bv_len;
 
-               backsql_strfcat( &bsi->bsi_flt_where, "bl",
+               backsql_strfcat_x( &bsi->bsi_flt_where,
+                               bsi->bsi_op->o_tmpmemctx,
+                               "bl",
                                filter_value, 
                                (ber_len_t)STRLENOF( /* (' */ "%')" ),
                                        /* (' */ "%')" );
@@ -1024,7 +1088,9 @@ backsql_process_filter_like( backsql_srch_info *bsi, backsql_at_map_rec *at,
                ldap_pvt_str2upper( &bsi->bsi_flt_where.bb_val.bv_val[ start ] );
 
        } else {
-               backsql_strfcat( &bsi->bsi_flt_where, "cblbl",
+               backsql_strfcat_x( &bsi->bsi_flt_where,
+                               bsi->bsi_op->o_tmpmemctx,
+                               "cblbl",
                                '(', /* ) */
                                &at->bam_sel_expr,
                                (ber_len_t)STRLENOF( " LIKE '%" ),
@@ -1061,7 +1127,9 @@ backsql_process_filter_attr( backsql_srch_info *bsi, Filter *f, backsql_at_map_r
                        && strstr( bsi->bsi_join_where.bb_val.bv_val,
                                at->bam_join_where.bv_val ) == NULL )
        {
-               backsql_strfcat( &bsi->bsi_join_where, "lb",
+               backsql_strfcat_x( &bsi->bsi_join_where,
+                               bsi->bsi_op->o_tmpmemctx,
+                               "lb",
                                (ber_len_t)STRLENOF( " AND " ), " AND ",
                                &at->bam_join_where );
        }
@@ -1131,7 +1199,9 @@ equality_match:;
                if ( at->bam_ad == slap_schema.si_ad_objectClass
                                || at->bam_ad == slap_schema.si_ad_structuralObjectClass )
                {
-                       backsql_strfcat( &bsi->bsi_flt_where, "lbl",
+                       backsql_strfcat_x( &bsi->bsi_flt_where,
+                                       bsi->bsi_op->o_tmpmemctx,
+                                       "lbl",
                                        (ber_len_t)STRLENOF( "(ldap_entries.id=ldap_entry_objclasses.entry_id AND ldap_entry_objclasses.oc_name='" /* ') */ ),
                                                "(ldap_entries.id=ldap_entry_objclasses.entry_id AND ldap_entry_objclasses.oc_name='" /* ') */,
                                        filter_value,
@@ -1173,7 +1243,9 @@ equality_match:;
                if ( casefold && BACKSQL_AT_CANUPPERCASE( at ) ) {
                        ber_len_t       start;
 
-                       backsql_strfcat( &bsi->bsi_flt_where, "cbbc",
+                       backsql_strfcat_x( &bsi->bsi_flt_where,
+                                       bsi->bsi_op->o_tmpmemctx,
+                                       "cbbc",
                                        '(', /* ) */
                                        &at->bam_sel_expr_u, 
                                        &ordering,
@@ -1181,7 +1253,9 @@ equality_match:;
 
                        start = bsi->bsi_flt_where.bb_val.bv_len;
 
-                       backsql_strfcat( &bsi->bsi_flt_where, "bl",
+                       backsql_strfcat_x( &bsi->bsi_flt_where,
+                                       bsi->bsi_op->o_tmpmemctx,
+                                       "bl",
                                        filter_value, 
                                        (ber_len_t)STRLENOF( /* (' */ "')" ),
                                                /* (' */ "')" );
@@ -1189,7 +1263,9 @@ equality_match:;
                        ldap_pvt_str2upper( &bsi->bsi_flt_where.bb_val.bv_val[ start ] );
                
                } else {
-                       backsql_strfcat( &bsi->bsi_flt_where, "cbbcbl",
+                       backsql_strfcat_x( &bsi->bsi_flt_where,
+                                       bsi->bsi_op->o_tmpmemctx,
+                                       "cbbcbl",
                                        '(' /* ) */ ,
                                        &at->bam_sel_expr,
                                        &ordering,
@@ -1201,7 +1277,9 @@ equality_match:;
                break;
 
        case LDAP_FILTER_PRESENT:
-               backsql_strfcat( &bsi->bsi_flt_where, "lbl",
+               backsql_strfcat_x( &bsi->bsi_flt_where,
+                               bsi->bsi_op->o_tmpmemctx,
+                               "lbl",
                                (ber_len_t)STRLENOF( "NOT (" /* ) */),
                                        "NOT (", /* ) */
                                &at->bam_sel_expr, 
@@ -1228,7 +1306,9 @@ equality_match:;
        default:
                /* unhandled filter type; should not happen */
                assert( 0 );
-               backsql_strfcat( &bsi->bsi_flt_where, "l",
+               backsql_strfcat_x( &bsi->bsi_flt_where,
+                               bsi->bsi_op->o_tmpmemctx,
+                               "l",
                                (ber_len_t)STRLENOF( "8=8" ), "8=8" );
                break;
 
@@ -1262,7 +1342,9 @@ backsql_srch_query( backsql_srch_info *bsi, struct berval *query )
        BER_BVZERO( &bsi->bsi_flt_where.bb_val );
        bsi->bsi_flt_where.bb_len = 0;
 
-       backsql_strfcat( &bsi->bsi_sel, "lbcbc",
+       backsql_strfcat_x( &bsi->bsi_sel,
+                       bsi->bsi_op->o_tmpmemctx,
+                       "lbcbc",
                        (ber_len_t)STRLENOF( "SELECT DISTINCT ldap_entries.id," ),
                                "SELECT DISTINCT ldap_entries.id,", 
                        &bsi->bsi_oc->bom_keytbl, 
@@ -1271,7 +1353,9 @@ backsql_srch_query( backsql_srch_info *bsi, struct berval *query )
                        ',' );
 
        if ( !BER_BVISNULL( &bi->sql_strcast_func ) ) {
-               backsql_strfcat( &bsi->bsi_sel, "blbl",
+               backsql_strfcat_x( &bsi->bsi_sel,
+                               bsi->bsi_op->o_tmpmemctx,
+                               "blbl",
                                &bi->sql_strcast_func, 
                                (ber_len_t)STRLENOF( "('" /* ') */ ),
                                        "('" /* ') */ ,
@@ -1279,19 +1363,28 @@ backsql_srch_query( backsql_srch_info *bsi, struct berval *query )
                                (ber_len_t)STRLENOF( /* (' */ "')" ),
                                        /* (' */ "')" );
        } else {
-               backsql_strfcat( &bsi->bsi_sel, "cbc",
+               backsql_strfcat_x( &bsi->bsi_sel,
+                               bsi->bsi_op->o_tmpmemctx,
+                               "cbc",
                                '\'',
                                &bsi->bsi_oc->bom_oc->soc_cname,
                                '\'' );
        }
 
-       backsql_strfcat( &bsi->bsi_sel, "b", &bi->sql_dn_oc_aliasing );
-       backsql_strfcat( &bsi->bsi_from, "lb",
+       backsql_strfcat_x( &bsi->bsi_sel,
+                       bsi->bsi_op->o_tmpmemctx,
+                       "b",
+                       &bi->sql_dn_oc_aliasing );
+       backsql_strfcat_x( &bsi->bsi_from,
+                       bsi->bsi_op->o_tmpmemctx,
+                       "lb",
                        (ber_len_t)STRLENOF( " FROM ldap_entries," ),
                                " FROM ldap_entries,",
                        &bsi->bsi_oc->bom_keytbl );
 
-       backsql_strfcat( &bsi->bsi_join_where, "lbcbl",
+       backsql_strfcat_x( &bsi->bsi_join_where,
+                       bsi->bsi_op->o_tmpmemctx,
+                       "lbcbl",
                        (ber_len_t)STRLENOF( " WHERE " ), " WHERE ",
                        &bsi->bsi_oc->bom_keytbl,
                        '.',
@@ -1302,12 +1395,16 @@ backsql_srch_query( backsql_srch_info *bsi, struct berval *query )
        switch ( bsi->bsi_scope ) {
        case LDAP_SCOPE_BASE:
                if ( BACKSQL_CANUPPERCASE( bi ) ) {
-                       backsql_strfcat( &bsi->bsi_join_where, "bl",
+                       backsql_strfcat_x( &bsi->bsi_join_where,
+                                       bsi->bsi_op->o_tmpmemctx, 
+                                       "bl",
                                        &bi->sql_upper_func,
                                        (ber_len_t)STRLENOF( "(ldap_entries.dn)=?" ),
                                                "(ldap_entries.dn)=?" );
                } else {
-                       backsql_strfcat( &bsi->bsi_join_where, "l",
+                       backsql_strfcat_x( &bsi->bsi_join_where,
+                                       bsi->bsi_op->o_tmpmemctx,
+                                       "l",
                                        (ber_len_t)STRLENOF( "ldap_entries.dn=?" ),
                                                "ldap_entries.dn=?" );
                }
@@ -1315,19 +1412,25 @@ backsql_srch_query( backsql_srch_info *bsi, struct berval *query )
                
        case BACKSQL_SCOPE_BASE_LIKE:
                if ( BACKSQL_CANUPPERCASE( bi ) ) {
-                       backsql_strfcat( &bsi->bsi_join_where, "bl",
+                       backsql_strfcat_x( &bsi->bsi_join_where,
+                                       bsi->bsi_op->o_tmpmemctx,
+                                       "bl",
                                        &bi->sql_upper_func,
                                        (ber_len_t)STRLENOF( "(ldap_entries.dn) LIKE ?" ),
                                                "(ldap_entries.dn) LIKE ?" );
                } else {
-                       backsql_strfcat( &bsi->bsi_join_where, "l",
+                       backsql_strfcat_x( &bsi->bsi_join_where,
+                                       bsi->bsi_op->o_tmpmemctx,
+                                       "l",
                                        (ber_len_t)STRLENOF( "ldap_entries.dn LIKE ?" ),
                                                "ldap_entries.dn LIKE ?" );
                }
                break;
                
        case LDAP_SCOPE_ONELEVEL:
-               backsql_strfcat( &bsi->bsi_join_where, "l",
+               backsql_strfcat_x( &bsi->bsi_join_where,
+                               bsi->bsi_op->o_tmpmemctx,
+                               "l",
                                (ber_len_t)STRLENOF( "ldap_entries.parent=?" ),
                                        "ldap_entries.parent=?" );
                break;
@@ -1358,20 +1461,29 @@ backsql_srch_query( backsql_srch_info *bsi, struct berval *query )
 
                if ( bsi->bsi_use_subtree_shortcut ) {
                        /* Skip the base DN filter, as every entry will match it */
-                       backsql_strfcat( &bsi->bsi_join_where, "l",
+                       backsql_strfcat_x( &bsi->bsi_join_where,
+                                       bsi->bsi_op->o_tmpmemctx,
+                                       "l",
                                        (ber_len_t)STRLENOF( "9=9"), "9=9");
 
                } else if ( !BER_BVISNULL( &bi->sql_subtree_cond ) ) {
-                       backsql_strfcat( &bsi->bsi_join_where, "b", &bi->sql_subtree_cond );
+                       backsql_strfcat_x( &bsi->bsi_join_where,
+                                       bsi->bsi_op->o_tmpmemctx,
+                                       "b",
+                                       &bi->sql_subtree_cond );
 
                } else if ( BACKSQL_CANUPPERCASE( bi ) ) {
-                       backsql_strfcat( &bsi->bsi_join_where, "bl",
+                       backsql_strfcat_x( &bsi->bsi_join_where,
+                                       bsi->bsi_op->o_tmpmemctx,
+                                       "bl",
                                        &bi->sql_upper_func,
                                        (ber_len_t)STRLENOF( "(ldap_entries.dn) LIKE ?" ),
                                                "(ldap_entries.dn) LIKE ?"  );
 
                } else {
-                       backsql_strfcat( &bsi->bsi_join_where, "l",
+                       backsql_strfcat_x( &bsi->bsi_join_where,
+                                       bsi->bsi_op->o_tmpmemctx,
+                                       "l",
                                        (ber_len_t)STRLENOF( "ldap_entries.dn LIKE ?" ),
                                                "ldap_entries.dn LIKE ?" );
                }
@@ -1386,7 +1498,9 @@ backsql_srch_query( backsql_srch_info *bsi, struct berval *query )
        if ( rc > 0 ) {
                struct berbuf   bb = BB_NULL;
 
-               backsql_strfcat( &bb, "bbblb",
+               backsql_strfcat_x( &bb,
+                               bsi->bsi_op->o_tmpmemctx,
+                               "bbblb",
                                &bsi->bsi_sel.bb_val,
                                &bsi->bsi_from.bb_val, 
                                &bsi->bsi_join_where.bb_val,
index eee55942e54a265d3611c8ac3455db8715f61638..316f2bc5ee68148c77216bf584a1dafcdca6ba4f 100644 (file)
@@ -65,7 +65,7 @@ char backsql_def_concat_func[] = "CONCAT(?,?)";
 char backsql_check_dn_ru_query[] = "SELECT dn_ru FROM ldap_entries";
 
 struct berbuf *
-backsql_strcat( struct berbuf *dest, ... )
+backsql_strcat_x( struct berbuf *dest, void *memctx, ... )
 {
        va_list         strs;
        ber_len_t       cdlen, cslen, grow;
@@ -79,10 +79,9 @@ backsql_strcat( struct berbuf *dest, ... )
        Debug( LDAP_DEBUG_TRACE, "==>backsql_strcat()\n", 0, 0, 0 );
 #endif /* BACKSQL_TRACE */
 
-       va_start( strs, dest );
+       va_start( strs, memctx );
        if ( dest->bb_val.bv_val == NULL || dest->bb_len == 0 ) {
-               dest->bb_val.bv_val = (char *)ch_calloc( BACKSQL_STR_GROW, 
-                               sizeof( char ) );
+               dest->bb_val.bv_val = (char *)ber_memalloc_x( BACKSQL_STR_GROW * sizeof( char ), memctx );
                dest->bb_val.bv_len = 0;
                dest->bb_len = BACKSQL_STR_GROW;
        }
@@ -100,8 +99,8 @@ backsql_strcat( struct berbuf *dest, ... )
                                dest->bb_len, cdlen + 1, cslen );
 #endif /* BACKSQL_TRACE */
 
-                       tmp_dest = (char *)ch_realloc( dest->bb_val.bv_val,
-                                       ( dest->bb_len ) + grow * sizeof( char ) );
+                       tmp_dest = (char *)ber_memrealloc_x( dest->bb_val.bv_val,
+                                       dest->bb_len + grow * sizeof( char ), memctx );
                        if ( tmp_dest == NULL ) {
                                Debug( LDAP_DEBUG_ANY, "backsql_strcat(): "
                                        "could not reallocate string buffer.\n",
@@ -133,7 +132,7 @@ backsql_strcat( struct berbuf *dest, ... )
 } 
 
 struct berbuf *
-backsql_strfcat( struct berbuf *dest, const char *fmt, ... )
+backsql_strfcat_x( struct berbuf *dest, void *memctx, const char *fmt, ... )
 {
        va_list         strs;
        ber_len_t       cdlen;
@@ -150,8 +149,7 @@ backsql_strfcat( struct berbuf *dest, const char *fmt, ... )
 
        va_start( strs, fmt );
        if ( dest->bb_val.bv_val == NULL || dest->bb_len == 0 ) {
-               dest->bb_val.bv_val = (char *)ch_calloc( BACKSQL_STR_GROW, 
-                               sizeof( char ) );
+               dest->bb_val.bv_val = (char *)ber_memalloc_x( BACKSQL_STR_GROW * sizeof( char ), memctx );
                dest->bb_val.bv_len = 0;
                dest->bb_len = BACKSQL_STR_GROW;
        }
@@ -208,8 +206,8 @@ backsql_strfcat( struct berbuf *dest, const char *fmt, ... )
                                dest->bb_len, cdlen + 1, cslen );
 #endif /* BACKSQL_TRACE */
 
-                       tmp_dest = (char *)ch_realloc( dest->bb_val.bv_val,
-                                       ( dest->bb_len ) + grow * sizeof( char ) );
+                       tmp_dest = (char *)ber_memrealloc_x( dest->bb_val.bv_val,
+                                       ( dest->bb_len ) + grow * sizeof( char ), memctx );
                        if ( tmp_dest == NULL ) {
                                Debug( LDAP_DEBUG_ANY, "backsql_strfcat(): "
                                        "could not reallocate string buffer.\n",
@@ -302,7 +300,7 @@ backsql_get_table_spec( backsql_info *bi, char **p )
 
        BACKSQL_NEXT_WORD;
        /* table name */
-       backsql_strcat( &res, s, NULL );
+       backsql_strcat_x( &res, NULL, s, NULL );
        s = q;
 
        BACKSQL_NEXT_WORD;
@@ -312,7 +310,7 @@ backsql_get_table_spec( backsql_info *bi, char **p )
        }
 
        /* oracle doesn't understand "AS" :( and other RDBMSes don't need it */
-       backsql_strfcat( &res, "lbbsb",
+       backsql_strfcat_x( &res, NULL, "lbbsb",
                        STRLENOF( " " ), " ",
                        &bi->sql_aliasing,
                        &bi->sql_aliasing_quote,
@@ -353,13 +351,13 @@ backsql_merge_from_clause(
                        "p=\"%s\" s=\"%s\"\n", p, s, 0 );
 #endif /* BACKSQL_TRACE */
 
-               if ( res.bb_val.bv_val == NULL ) {
-                       backsql_strcat( &res, s, NULL );
+               if ( BER_BVISNULL( &res.bb_val ) ) {
+                       backsql_strcat_x( &res, NULL, s, NULL );
 
                } else {
                        pos = strstr( res.bb_val.bv_val, s );
                        if ( pos == NULL || ( ( e = pos[ strlen( s ) ] ) != '\0' && e != ',' ) ) {
-                               backsql_strfcat( &res, "cs", ',', s );
+                               backsql_strfcat_x( &res, NULL, "cs", ',', s );
                        }
                }
                
@@ -464,8 +462,8 @@ backsql_prepare_pattern(
                        ch_free( bb.bb_val.bv_val );
                        return -1;
                }
-               backsql_strfcat( &bb, "b", &split_pattern[ i ] );
-               backsql_strfcat( &bb, "b", &values[ i ] );
+               backsql_strfcat_x( &bb, NULL, "b", &split_pattern[ i ] );
+               backsql_strfcat_x( &bb, NULL, "b", &values[ i ] );
        }
 
        if ( split_pattern[ i ].bv_val == NULL ) {
@@ -473,7 +471,7 @@ backsql_prepare_pattern(
                return -1;
        }
 
-       backsql_strfcat( &bb, "b", &split_pattern[ i ] );
+       backsql_strfcat_x( &bb, NULL, "b", &split_pattern[ i ] );
 
        *res = bb.bb_val;