From: Pierangelo Masarati Date: Tue, 15 Apr 2003 21:55:25 +0000 (+0000) Subject: fix backsql new API; use berbuf instead of berval X-Git-Tag: OPENLDAP_REL_ENG_2_2_0ALPHA~359 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=adf3744dd697b0897e974e3e69c6634897e71231;p=openldap fix backsql new API; use berbuf instead of berval --- diff --git a/servers/slapd/add.c b/servers/slapd/add.c index 3deabac3d6..0274426839 100644 --- a/servers/slapd/add.c +++ b/servers/slapd/add.c @@ -299,7 +299,6 @@ do_add( Operation *op, SlapReply *rs ) #ifndef SLAPD_MULTIMASTER } else { BerVarray defref; - BerVarray ref; #ifdef LDAP_SLAPI /* * SLAPI_ADD_ENTRY will be empty, but this may be acceptable @@ -457,7 +456,7 @@ slap_mods2entry( } } else { - int rc; + int rc = LDAP_SUCCESS; int match; for ( i = 0; mods->sml_nvalues[i].bv_val != NULL; i++ ) { diff --git a/servers/slapd/back-sql/entry-id.c b/servers/slapd/back-sql/entry-id.c index 2d449312c1..725367a9c9 100644 --- a/servers/slapd/back-sql/entry-id.c +++ b/servers/slapd/back-sql/entry-id.c @@ -266,12 +266,13 @@ backsql_has_children( static int backsql_get_attr_vals( void *v_at, void *v_bsi ) { - backsql_at_map_rec *at = v_at; - backsql_srch_info *bsi = v_bsi; - RETCODE rc; - SQLHSTMT sth; - BACKSQL_ROW_NTS row; - int i; + backsql_at_map_rec *at = v_at; + backsql_srch_info *bsi = v_bsi; + backsql_info *bi = (backsql_info *)bsi->op->o_bd->be_private; + RETCODE rc; + SQLHSTMT sth; + BACKSQL_ROW_NTS row; + int i; assert( at ); assert( bsi ); @@ -285,7 +286,7 @@ backsql_get_attr_vals( void *v_at, void *v_bsi ) if ( rc != SQL_SUCCESS ) { Debug( LDAP_DEBUG_TRACE, "backsql_get_attr_values(): " "error preparing query: %s\n", at->query, 0, 0 ); - backsql_PrintErrors( bsi->bi->db_env, bsi->dbh, sth, rc ); + backsql_PrintErrors( bi->db_env, bsi->dbh, sth, rc ); return 1; } @@ -301,7 +302,7 @@ backsql_get_attr_vals( void *v_at, void *v_bsi ) Debug( LDAP_DEBUG_TRACE, "backsql_get_attr_values(): " "error executing attribute query '%s'\n", at->query, 0, 0 ); - backsql_PrintErrors( bsi->bi->db_env, bsi->dbh, sth, rc ); + backsql_PrintErrors( bi->db_env, bsi->dbh, sth, rc ); SQLFreeStmt( sth, SQL_DROP ); return 1; } @@ -363,7 +364,7 @@ backsql_id2entry( backsql_srch_info *bsi, Entry *e, backsql_entryID *eid ) return NULL; } - bsi->oc = backsql_id2oc( bsi->bi, eid->oc_id ); + bsi->oc = backsql_id2oc( bsi->op->o_bd->be_private, eid->oc_id ); bsi->e = e; bsi->c_eid = eid; e->e_attrs = NULL; diff --git a/servers/slapd/back-sql/init.c b/servers/slapd/back-sql/init.c index b946f24c10..dd0e8320d9 100644 --- a/servers/slapd/back-sql/init.c +++ b/servers/slapd/back-sql/init.c @@ -163,7 +163,7 @@ backsql_db_open( backsql_info *si = (backsql_info*)bd->be_private; SQLHDBC dbh; ber_len_t idq_len; - struct berval bv; + struct berbuf bb = BB_NULL; Operation otmp; @@ -228,12 +228,12 @@ backsql_db_open( * Prepare concat function for subtree search condition */ struct berval concat; - ber_len_t len = 0; struct berval values[] = { { sizeof( "'%'" ) - 1, "'%'" }, { sizeof( "?" ) - 1, "?" }, { 0, NULL } }; + struct berbuf bb = BB_NULL; if ( backsql_prepare_pattern( si->concat_func, values, &concat ) ) { @@ -247,16 +247,13 @@ backsql_db_open( "(use \"subtree_cond\" directive in slapd.conf)\n", 0, 0, 0); - si->subtree_cond.bv_val = NULL; - si->subtree_cond.bv_len = 0; - if ( si->upper_func.bv_val ) { /* * UPPER(ldap_entries.dn) LIKE UPPER(CONCAT('%',?)) */ - backsql_strfcat( &si->subtree_cond, &len, "blbbb", + backsql_strfcat( &bb, "blbbb", &si->upper_func, (ber_len_t)sizeof( "(ldap_entries.dn) LIKE " ) - 1, "(ldap_entries.dn) LIKE ", @@ -270,11 +267,13 @@ backsql_db_open( * ldap_entries.dn LIKE CONCAT('%',?) */ - backsql_strfcat( &si->subtree_cond, &len, "lb", + backsql_strfcat( &bb, "lb", (ber_len_t)sizeof( "ldap_entries.dn LIKE " ) - 1, "ldap_entries.dn LIKE ", &concat ); } + + si->subtree_cond = bb.bb_val; Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): " "setting '%s' as default\n", @@ -282,7 +281,7 @@ backsql_db_open( } if ( si->children_cond.bv_val == NULL ) { - ber_len_t len = 0; + struct berbuf bb = BB_NULL; if ( si->upper_func.bv_val ) { @@ -290,7 +289,7 @@ backsql_db_open( * UPPER(ldap_entries.dn) LIKE UPPER(CONCAT('%,',?)) */ - backsql_strfcat( &si->children_cond, &len, "blbl", + backsql_strfcat( &bb, "blbl", &si->upper_func, (ber_len_t)sizeof( "(ldap_entries.dn)=" ) - 1, "(ldap_entries.dn)=", @@ -303,10 +302,12 @@ backsql_db_open( * ldap_entries.dn LIKE CONCAT('%,',?) */ - backsql_strfcat( &si->children_cond, &len, "l", + backsql_strfcat( &bb, "l", (ber_len_t)sizeof( "ldap_entries.dn=?" ) - 1, "ldap_entries.dn=?"); } + + si->children_cond = bb.bb_val; Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): " "setting '%s' as default\n", @@ -377,23 +378,20 @@ backsql_db_open( si->id_query = NULL; idq_len = 0; - bv.bv_val = NULL; - bv.bv_len = 0; if ( si->upper_func.bv_val == NULL ) { - backsql_strcat( &bv, &idq_len, backsql_id_query, - "dn=?", NULL ); + backsql_strcat( &bb, backsql_id_query, "dn=?", NULL ); } else { if ( BACKSQL_HAS_LDAPINFO_DN_RU( si ) ) { - backsql_strcat( &bv, &idq_len, backsql_id_query, + backsql_strcat( &bb, backsql_id_query, "dn_ru=?", NULL ); } else { if ( BACKSQL_USE_REVERSE_DN( si ) ) { - backsql_strfcat( &bv, &idq_len, "sbl", + backsql_strfcat( &bb, "sbl", backsql_id_query, &si->upper_func, (ber_len_t)sizeof( "(dn)=?" ) - 1, "(dn)=?" ); } else { - backsql_strfcat( &bv, &idq_len, "sblbcb", + backsql_strfcat( &bb, "sblbcb", backsql_id_query, &si->upper_func, (ber_len_t)sizeof( "(dn)=" ) - 1, "(dn)=", @@ -403,21 +401,21 @@ backsql_db_open( } } } - si->id_query = bv.bv_val; + si->id_query = bb.bb_val.bv_val; /* * Prepare children ID selection query */ si->has_children_query = NULL; - idq_len = 0; - bv.bv_val = NULL; - bv.bv_len = 0; - backsql_strfcat( &bv, &idq_len, "sb", + bb.bb_val.bv_val = NULL; + bb.bb_val.bv_len = 0; + bb.bb_len = 0; + backsql_strfcat( &bb, "sb", "SELECT COUNT(distinct subordinates.id) FROM ldap_entries,ldap_entries AS subordinates WHERE subordinates.parent=ldap_entries.id AND ", &si->children_cond ); - si->has_children_query = bv.bv_val; + si->has_children_query = bb.bb_val.bv_val; backsql_free_db_conn( &otmp ); if ( !BACKSQL_SCHEMA_LOADED( si ) ) { diff --git a/servers/slapd/back-sql/schema-map.c b/servers/slapd/back-sql/schema-map.c index 6244955033..a4404c5b48 100644 --- a/servers/slapd/back-sql/schema-map.c +++ b/servers/slapd/back-sql/schema-map.c @@ -54,10 +54,9 @@ backsql_make_attr_query( backsql_oc_map_rec *oc_map, backsql_at_map_rec *at_map ) { - struct berval tmps = BER_BVNULL; - ber_len_t tmpslen = 0; + struct berbuf bb = BB_NULL; - backsql_strfcat( &tmps, &tmpslen, "lblblblbcbl", + backsql_strfcat( &bb, "lblblblbcbl", (ber_len_t)sizeof( "SELECT " ) - 1, "SELECT ", &at_map->sel_expr, (ber_len_t)sizeof( " AS " ) - 1, " AS ", @@ -71,12 +70,12 @@ backsql_make_attr_query( (ber_len_t)sizeof( "=?" ) - 1, "=?" ); if ( at_map->join_where.bv_val != NULL ) { - backsql_strfcat( &tmps, &tmpslen, "lb", + backsql_strfcat( &bb, "lb", (ber_len_t)sizeof( " AND ") - 1, " AND ", &at_map->join_where ); } - at_map->query = tmps.bv_val; + at_map->query = bb.bb_val.bv_val; return 0; } @@ -85,8 +84,9 @@ static int backsql_add_sysmaps( backsql_oc_map_rec *oc_map ) { backsql_at_map_rec *at_map; - char s[ 30 ]; - ber_len_t len, slen; + char s[] = "+9223372036854775807L"; + ber_len_t slen; + struct berbuf bb; snprintf( s, sizeof( s ), "%ld", oc_map->id ); @@ -98,13 +98,16 @@ backsql_add_sysmaps( backsql_oc_map_rec *oc_map ) ber_str2bv( "ldap_entry_objclasses.oc_name", 0, 1, &at_map->sel_expr ); ber_str2bv( "ldap_entry_objclasses,ldap_entries", 0, 1, &at_map->from_tbls ); - len = at_map->from_tbls.bv_len + 1; - backsql_merge_from_clause( &at_map->from_tbls, &len, &oc_map->keytbl ); - - len = 0; - at_map->join_where.bv_val = NULL; - at_map->join_where.bv_len = 0; - backsql_strfcat( &at_map->join_where, &len, "lbcbll", + + bb.bb_len = at_map->from_tbls.bv_len + 1; + bb.bb_val = at_map->from_tbls; + backsql_merge_from_clause( &bb, &oc_map->keytbl ); + at_map->from_tbls = bb.bb_val; + + bb.bb_val.bv_val = NULL; + bb.bb_val.bv_len = 0; + bb.bb_len = 0; + backsql_strfcat( &bb, "lbcbll", (ber_len_t)sizeof( "ldap_entries.id=ldap_entry_objclasses.entry_id and ldap_entries.keyval=" ) - 1, "ldap_entries.id=ldap_entry_objclasses.entry_id and ldap_entries.keyval=", &oc_map->keytbl, @@ -114,10 +117,12 @@ backsql_add_sysmaps( backsql_oc_map_rec *oc_map ) " and ldap_entries.oc_map_id=", slen, s ); + at_map->join_where = bb.bb_val; at_map->add_proc = NULL; at_map->delete_proc = NULL; at_map->param_order = 0; at_map->expect_return = 0; + backsql_make_attr_query( oc_map, at_map ); avl_insert( &oc_map->attrs, at_map, backsql_cmp_attr, NULL ); @@ -126,13 +131,17 @@ backsql_add_sysmaps( backsql_oc_map_rec *oc_map ) at_map->ad = slap_schema.si_ad_ref; ber_str2bv( "ldap_referrals.url", 0, 1, &at_map->sel_expr ); ber_str2bv( "ldap_referrals,ldap_entries", 0, 1, &at_map->from_tbls ); - len = at_map->from_tbls.bv_len + 1; - backsql_merge_from_clause( &at_map->from_tbls, &len, &oc_map->keytbl ); - - len = 0; - at_map->join_where.bv_val = NULL; - at_map->join_where.bv_len = 0; - backsql_strfcat( &at_map->join_where, &len, "lbcbll", + + bb.bb_val.bv_val = NULL; + bb.bb_val.bv_len = 0; + bb.bb_len = at_map->from_tbls.bv_len + 1; + backsql_merge_from_clause( &bb, &oc_map->keytbl ); + at_map->from_tbls = bb.bb_val; + + bb.bb_val.bv_val = NULL; + bb.bb_val.bv_len = 0; + bb.bb_len = 0; + backsql_strfcat( &bb, "lbcbll", (ber_len_t)sizeof( "ldap_entries.id=ldap_referrals.entry_id and ldap_entries.keyval=" ) - 1, "ldap_entries.id=ldap_referrals.entry_id and ldap_entries.keyval=", &oc_map->keytbl, @@ -142,10 +151,12 @@ backsql_add_sysmaps( backsql_oc_map_rec *oc_map ) " and ldap_entries.oc_map_id=", slen, s ); + at_map->join_where = bb.bb_val; at_map->add_proc = NULL; at_map->delete_proc = NULL; at_map->param_order = 0; at_map->expect_return = 0; + backsql_make_attr_query( oc_map, at_map ); avl_insert( &oc_map->attrs, at_map, backsql_cmp_attr, NULL ); @@ -301,7 +312,7 @@ backsql_load_schema_map( backsql_info *si, SQLHDBC dbh ) for ( ; BACKSQL_SUCCESS(rc); rc = SQLFetch( at_sth ) ) { const char *text = NULL; struct berval bv; - ber_len_t tmpslen; + struct berbuf bb = BB_NULL; Debug( LDAP_DEBUG_TRACE, "********'%s'\n", at_row.cols[ 0 ], 0, 0 ); @@ -338,10 +349,10 @@ backsql_load_schema_map( backsql_info *si, SQLHDBC dbh ) ber_str2bv( at_row.cols[ 8 ], 0, 1, &at_map->sel_expr_u ); } - tmpslen = 0; + ber_str2bv( at_row.cols[ 2 ], 0, 0, &bv ); - backsql_merge_from_clause( &at_map->from_tbls, - &tmpslen, &bv ); + backsql_merge_from_clause( &bb, &bv ); + at_map->from_tbls = bb.bb_val; if ( at_row.value_len[ 3 ] < 0 ) { at_map->join_where.bv_val = NULL; at_map->join_where.bv_len = 0; diff --git a/servers/slapd/back-sql/search.c b/servers/slapd/back-sql/search.c index 6a14ba7b0a..1ee14746b8 100644 --- a/servers/slapd/back-sql/search.c +++ b/servers/slapd/back-sql/search.c @@ -137,18 +137,18 @@ backsql_init_search( bsi->id_list = NULL; bsi->n_candidates = 0; bsi->stoptime = stoptime; - bsi->sel.bv_val = NULL; - bsi->sel.bv_len = 0; - bsi->sel_len = 0; - bsi->from.bv_val = NULL; - bsi->from.bv_len = 0; - bsi->from_len = 0; - bsi->join_where.bv_val = NULL; - bsi->join_where.bv_len = 0; - bsi->jwhere_len = 0; - bsi->flt_where.bv_val = NULL; - bsi->flt_where.bv_len = 0; - bsi->fwhere_len = 0; + bsi->sel.bb_val.bv_val = NULL; + bsi->sel.bb_val.bv_len = 0; + bsi->sel.bb_len = 0; + bsi->from.bb_val.bv_val = NULL; + bsi->from.bb_val.bv_len = 0; + bsi->from.bb_len = 0; + bsi->join_where.bb_val.bv_val = NULL; + bsi->join_where.bb_val.bv_len = 0; + bsi->join_where.bb_len = 0; + bsi->flt_where.bb_val.bv_val = NULL; + bsi->flt_where.bb_val.bv_len = 0; + bsi->flt_where.bb_len = 0; bsi->status = LDAP_SUCCESS; } @@ -162,7 +162,7 @@ backsql_process_filter_list( backsql_srch_info *bsi, Filter *f, int op ) return 0; } - backsql_strfcat( &bsi->flt_where, &bsi->fwhere_len, "c", '(' /* ) */ ); + backsql_strfcat( &bsi->flt_where, "c", '(' /* ) */ ); while ( 1 ) { res = backsql_process_filter( bsi, f ); @@ -181,20 +181,20 @@ backsql_process_filter_list( backsql_srch_info *bsi, Filter *f, int op ) switch ( op ) { case LDAP_FILTER_AND: - backsql_strfcat( &bsi->flt_where, &bsi->fwhere_len, "l", + backsql_strfcat( &bsi->flt_where, "l", (ber_len_t)sizeof( " AND " ) - 1, " AND " ); break; case LDAP_FILTER_OR: - backsql_strfcat( &bsi->flt_where, &bsi->fwhere_len, "l", + backsql_strfcat( &bsi->flt_where, "l", (ber_len_t)sizeof( " OR " ) - 1, " OR " ); break; } } - backsql_strfcat( &bsi->flt_where, &bsi->fwhere_len, "c", /* ( */ ')' ); + backsql_strfcat( &bsi->flt_where, "c", /* ( */ ')' ); return 1; } @@ -204,6 +204,7 @@ backsql_process_sub_filter( backsql_srch_info *bsi, Filter *f ) { int i; backsql_at_map_rec *at; + backsql_info *bi = (backsql_info *)bsi->op->o_bd->be_private; if ( !f ) { return 0; @@ -219,25 +220,25 @@ backsql_process_sub_filter( backsql_srch_info *bsi, Filter *f ) * SQL filters are more liberal. */ - backsql_strfcat( &bsi->flt_where, &bsi->fwhere_len, "c", '(' /* ) */ ); + backsql_strfcat( &bsi->flt_where, "c", '(' /* ) */ ); /* TimesTen */ Debug( LDAP_DEBUG_TRACE, "expr: '%s' '%s'\n", at->sel_expr.bv_val, at->sel_expr_u.bv_val ? at->sel_expr_u.bv_val : "", 0 ); - if ( bsi->bi->upper_func.bv_val ) { + if ( bi->upper_func.bv_val ) { /* * If a pre-upper-cased version of the column exists, use it */ if ( at->sel_expr_u.bv_val ) { - backsql_strfcat( &bsi->flt_where, &bsi->fwhere_len, + backsql_strfcat( &bsi->flt_where, "bl", &at->sel_expr_u, (ber_len_t)sizeof( " LIKE '" ) - 1, " LIKE '" ); } else { - backsql_strfcat( &bsi->flt_where, &bsi->fwhere_len, + backsql_strfcat( &bsi->flt_where, "bcbcl", - &bsi->bi->upper_func, + &bi->upper_func, '(', &at->sel_expr, ')', @@ -245,7 +246,7 @@ backsql_process_sub_filter( backsql_srch_info *bsi, Filter *f ) " LIKE '" ); } } else { - backsql_strfcat( &bsi->flt_where, &bsi->fwhere_len, "bl", + backsql_strfcat( &bsi->flt_where, "bl", &at->sel_expr, (ber_len_t)sizeof( " LIKE '" ) - 1, " LIKE '" ); } @@ -253,15 +254,15 @@ backsql_process_sub_filter( backsql_srch_info *bsi, Filter *f ) if ( f->f_sub_initial.bv_val != NULL ) { size_t start; - start = bsi->flt_where.bv_len; - backsql_strfcat( &bsi->flt_where, &bsi->fwhere_len, "b", + start = bsi->flt_where.bb_val.bv_len; + backsql_strfcat( &bsi->flt_where, "b", &f->f_sub_initial ); - if ( bsi->bi->upper_func.bv_val ) { - ldap_pvt_str2upper( &bsi->flt_where.bv_val[ start ] ); + if ( bi->upper_func.bv_val ) { + ldap_pvt_str2upper( &bsi->flt_where.bb_val.bv_val[ start ] ); } } - backsql_strfcat( &bsi->flt_where, &bsi->fwhere_len, "c", '%' ); + backsql_strfcat( &bsi->flt_where, "c", '%' ); if ( f->f_sub_any != NULL ) { for ( i = 0; f->f_sub_any[ i ].bv_val != NULL; i++ ) { @@ -274,32 +275,32 @@ backsql_process_sub_filter( backsql_srch_info *bsi, Filter *f ) 0, 0 ); #endif /* BACKSQL_TRACE */ - start = bsi->flt_where.bv_len; - backsql_strfcat( &bsi->flt_where, &bsi->fwhere_len, + start = bsi->flt_where.bb_val.bv_len; + backsql_strfcat( &bsi->flt_where, "bc", &f->f_sub_any[ i ], '%' ); - if ( bsi->bi->upper_func.bv_val ) { + if ( bi->upper_func.bv_val ) { /* * Note: toupper('%') = '%' */ - ldap_pvt_str2upper( &bsi->flt_where.bv_val[ start ] ); + ldap_pvt_str2upper( &bsi->flt_where.bb_val.bv_val[ start ] ); } } if ( f->f_sub_final.bv_val != NULL ) { size_t start; - start = bsi->flt_where.bv_len; - backsql_strfcat( &bsi->flt_where, &bsi->fwhere_len, "b", + start = bsi->flt_where.bb_val.bv_len; + backsql_strfcat( &bsi->flt_where, "b", &f->f_sub_final ); - if ( bsi->bi->upper_func.bv_val ) { - ldap_pvt_str2upper( &bsi->flt_where.bv_val[ start ] ); + if ( bi->upper_func.bv_val ) { + ldap_pvt_str2upper( &bsi->flt_where.bb_val.bv_val[ start ] ); } } } - backsql_strfcat( &bsi->flt_where, &bsi->fwhere_len, "l", + backsql_strfcat( &bsi->flt_where, "l", (ber_len_t)sizeof( /* (' */ "')" ) - 1, /* ( */ "')" ); return 1; @@ -308,13 +309,13 @@ backsql_process_sub_filter( backsql_srch_info *bsi, Filter *f ) static int backsql_process_filter( backsql_srch_info *bsi, Filter *f ) { + backsql_info *bi = (backsql_info *)bsi->op->o_bd->be_private; backsql_at_map_rec *at; backsql_at_map_rec oc_attr = { slap_schema.si_ad_objectClass, BER_BVC(""), BER_BVC(""), BER_BVNULL, NULL, NULL, NULL }; AttributeDescription *ad = NULL; int done = 0; - ber_len_t len = 0; /* TimesTen */ int rc = 0; struct berval *filter_value = NULL; @@ -338,12 +339,11 @@ backsql_process_filter( backsql_srch_info *bsi, Filter *f ) break; case LDAP_FILTER_NOT: - backsql_strfcat( &bsi->flt_where, &bsi->fwhere_len, "l", + backsql_strfcat( &bsi->flt_where, "l", (ber_len_t)sizeof( "NOT (" /* ) */ ) - 1, "NOT (" /* ) */ ); rc = backsql_process_filter( bsi, f->f_not ); - backsql_strfcat( &bsi->flt_where, &bsi->fwhere_len, "c", - /* ( */ ')' ); + backsql_strfcat( &bsi->flt_where, "c", /* ( */ ')' ); done = 1; break; @@ -374,11 +374,14 @@ backsql_process_filter( backsql_srch_info *bsi, Filter *f ) */ if ( ad == slap_schema.si_ad_objectClass || ad == slap_schema.si_ad_structuralObjectClass ) { + struct berbuf bb = BB_NULL; + at = &oc_attr; - backsql_strfcat( &at->sel_expr, &len, "cbc", + backsql_strfcat( &bb, "cbc", '\'', &bsi->oc->oc->soc_cname, '\'' ); + at->sel_expr = bb.bb_val; } else if ( ad == slap_schema.si_ad_hasSubordinates || ad == NULL ) { /* @@ -390,7 +393,7 @@ backsql_process_filter( backsql_srch_info *bsi, Filter *f ) * so a more appropriate filter would be * '(hasSubordinates=FALSE)' */ - backsql_strfcat( &bsi->flt_where, &bsi->fwhere_len, "l", + backsql_strfcat( &bsi->flt_where, "l", (ber_len_t)sizeof( "1=1" ) - 1, "1=1" ); if ( ad == slap_schema.si_ad_hasSubordinates ) { /* @@ -418,13 +421,12 @@ backsql_process_filter( backsql_srch_info *bsi, Filter *f ) Debug( LDAP_DEBUG_TRACE, "backsql_process_filter(): " "attribute '%s' is not defined for objectclass '%s'\n", ad->ad_cname.bv_val, BACKSQL_OC_NAME( bsi->oc ), 0 ); - backsql_strfcat( &bsi->flt_where, &bsi->fwhere_len, "l", + backsql_strfcat( &bsi->flt_where, "l", (ber_len_t)sizeof( "1=0" ) - 1, "1=0" ); goto impossible; } - backsql_merge_from_clause( &bsi->from, &bsi->from_len, - &at->from_tbls ); + backsql_merge_from_clause( &bsi->from, &at->from_tbls ); /* * need to add this attribute to list of attrs to load, * so that we could do test_filter() later @@ -432,8 +434,8 @@ backsql_process_filter( backsql_srch_info *bsi, Filter *f ) backsql_attrlist_add( bsi, ad ); if ( at->join_where.bv_val != NULL - && strstr( bsi->join_where.bv_val, at->join_where.bv_val ) == NULL ) { - backsql_strfcat( &bsi->join_where, &bsi->jwhere_len, "lb", + && strstr( bsi->join_where.bb_val.bv_val, at->join_where.bv_val ) == NULL ) { + backsql_strfcat( &bsi->join_where, "lb", (ber_len_t)sizeof( " AND " ) - 1, " AND ", &at->join_where ); } @@ -444,7 +446,7 @@ backsql_process_filter( backsql_srch_info *bsi, Filter *f ) * attribute name syntax might collide with SQL legal aliases */ if ( at != &oc_attr ) { - backsql_strfcat( &bsi->sel, &bsi->sel_len, "cblb", + backsql_strfcat( &bsi->sel, "cblb", ',', &at->sel_expr, (ber_len_t)sizeof( " AS " ) - 1, " AS ", @@ -469,40 +471,36 @@ equality_match:; * upper_func stuff is made for Oracle, where UPPER is * safely applicable to NUMBER etc. */ - if ( bsi->bi->upper_func.bv_val ) { + if ( bi->upper_func.bv_val ) { size_t start; if ( at->sel_expr_u.bv_val ) { - backsql_strfcat( &bsi->flt_where, - &bsi->fwhere_len, "cbl", + backsql_strfcat( &bsi->flt_where, "cbl", '(', &at->sel_expr_u, (ber_len_t)sizeof( "='" ) - 1, "='" ); } else { - backsql_strfcat( &bsi->flt_where, - &bsi->fwhere_len, "cbcbl", + backsql_strfcat( &bsi->flt_where, "cbcbl", '(' /* ) */ , - &bsi->bi->upper_func, + &bi->upper_func, '(' /* ) */ , &at->sel_expr, (ber_len_t)sizeof( /* ( */ ")='" ) - 1, /* ( */ ")='" ); } - start = bsi->flt_where.bv_len; + start = bsi->flt_where.bb_val.bv_len; - backsql_strfcat( &bsi->flt_where, &bsi->fwhere_len, - "bl", + backsql_strfcat( &bsi->flt_where, "bl", filter_value, (ber_len_t)sizeof( /* (' */ "')" ) - 1, /* (' */ "')" ); - ldap_pvt_str2upper( &bsi->flt_where.bv_val[ start ] ); + ldap_pvt_str2upper( &bsi->flt_where.bb_val.bv_val[ start ] ); } else { - backsql_strfcat( &bsi->flt_where, &bsi->fwhere_len, - "cblbl", + backsql_strfcat( &bsi->flt_where, "cblbl", '(', &at->sel_expr, (ber_len_t)sizeof( "='" ) - 1, "='", @@ -516,7 +514,7 @@ equality_match:; /* * FIXME: should we uppercase the operands? */ - backsql_strfcat( &bsi->flt_where, &bsi->fwhere_len, "cblbc", + backsql_strfcat( &bsi->flt_where, "cblbc", '(' /* ) */ , &at->sel_expr, (ber_len_t)sizeof( ">=" ) - 1, ">=", @@ -528,7 +526,7 @@ equality_match:; /* * FIXME: should we uppercase the operands? */ - backsql_strfcat( &bsi->flt_where, &bsi->fwhere_len, "cblbc", + backsql_strfcat( &bsi->flt_where, "cblbc", '(' /* ) */ , &at->sel_expr, (ber_len_t)sizeof( "<=" ) - 1, "<=", @@ -537,7 +535,7 @@ equality_match:; break; case LDAP_FILTER_PRESENT: - backsql_strfcat( &bsi->flt_where, &bsi->fwhere_len, "lbl", + backsql_strfcat( &bsi->flt_where, "lbl", (ber_len_t)sizeof( "NOT (" ) - 1, "NOT (", &at->sel_expr, (ber_len_t)sizeof( " IS NULL)" ) - 1, " IS NULL)" ); @@ -556,40 +554,36 @@ equality_match:; * upper_func stuff is made for Oracle, where UPPER is * safely applicable to NUMBER etc. */ - if ( bsi->bi->upper_func.bv_val ) { + if ( bi->upper_func.bv_val ) { size_t start; if ( at->sel_expr_u.bv_val ) { - backsql_strfcat( &bsi->flt_where, - &bsi->fwhere_len, "cbl", + backsql_strfcat( &bsi->flt_where, "cbl", '(', &at->sel_expr_u, (ber_len_t)sizeof( " LIKE '%" ) - 1, " LIKE '%" ); } else { - backsql_strfcat( &bsi->flt_where, - &bsi->fwhere_len, "cbcbl", + backsql_strfcat( &bsi->flt_where, "cbcbl", '(' /* ) */ , - &bsi->bi->upper_func, + &bi->upper_func, '(' /* ) */ , &at->sel_expr, (ber_len_t)sizeof( /* ( */ ") LIKE '%" ) - 1, /* ( */ ") LIKE '%" ); } - start = bsi->flt_where.bv_len; + start = bsi->flt_where.bb_val.bv_len; - backsql_strfcat( &bsi->flt_where, &bsi->fwhere_len, - "bl", + backsql_strfcat( &bsi->flt_where, "bl", &f->f_av_value, (ber_len_t)sizeof( /* (' */ "%')" ) - 1, /* (' */ "%')" ); - ldap_pvt_str2upper( &bsi->flt_where.bv_val[ start ] ); + ldap_pvt_str2upper( &bsi->flt_where.bb_val.bv_val[ start ] ); } else { - backsql_strfcat( &bsi->flt_where, &bsi->fwhere_len, - "cblbl", + backsql_strfcat( &bsi->flt_where, "cblbl", '(', &at->sel_expr, (ber_len_t)sizeof( " LIKE '%" ) - 1, @@ -603,7 +597,7 @@ equality_match:; default: /* unhandled filter type; should not happen */ assert( 0 ); - backsql_strfcat( &bsi->flt_where, &bsi->fwhere_len, "l", + backsql_strfcat( &bsi->flt_where, "l", (ber_len_t)sizeof( "1=1" ) - 1, "1=1" ); break; @@ -630,7 +624,6 @@ static int backsql_srch_query( backsql_srch_info *bsi, struct berval *query ) { backsql_info *bi = (backsql_info *)bsi->op->o_bd->be_private; - ber_len_t q_len = 0; int rc; assert( query ); @@ -638,18 +631,18 @@ backsql_srch_query( backsql_srch_info *bsi, struct berval *query ) query->bv_len = 0; Debug( LDAP_DEBUG_TRACE, "==>backsql_srch_query()\n", 0, 0, 0 ); - bsi->sel.bv_val = NULL; - bsi->sel.bv_len = 0; - bsi->sel_len = 0; - bsi->from.bv_val = NULL; - bsi->from.bv_len = 0; - bsi->from_len = 0; - bsi->join_where.bv_val = NULL; - bsi->join_where.bv_len = 0; - bsi->jwhere_len = 0; - bsi->flt_where.bv_val = NULL; - bsi->flt_where.bv_len = 0; - bsi->fwhere_len = 0; + bsi->sel.bb_val.bv_val = NULL; + bsi->sel.bb_val.bv_len = 0; + bsi->sel.bb_len = 0; + bsi->from.bb_val.bv_val = NULL; + bsi->from.bb_val.bv_len = 0; + bsi->from.bb_len = 0; + bsi->join_where.bb_val.bv_val = NULL; + bsi->join_where.bb_val.bv_len = 0; + bsi->join_where.bb_len = 0; + bsi->flt_where.bb_val.bv_val = NULL; + bsi->flt_where.bb_val.bv_len = 0; + bsi->flt_where.bb_len = 0; #if 0 /* @@ -657,14 +650,14 @@ backsql_srch_query( backsql_srch_info *bsi, struct berval *query ) * is defined; more sophisticated (pattern based) function should * be used */ - backsql_strcat( &bsi->sel, &bsi->sel_len, + backsql_strcat( &bsi->sel, "SELECT DISTINCT ldap_entries.id,", bsi->oc->keytbl.bv_val, ".", bsi->oc->keycol.bv_val, ",'", bsi->oc->name.bv_val, "' AS objectClass", ",ldap_entries.dn AS dn", NULL ); #endif - backsql_strfcat( &bsi->sel, &bsi->sel_len, "lbcbc", + backsql_strfcat( &bsi->sel, "lbcbc", (ber_len_t)sizeof( "SELECT DISTINCT ldap_entries.id," ) - 1, "SELECT DISTINCT ldap_entries.id,", &bsi->oc->keytbl, @@ -673,7 +666,7 @@ backsql_srch_query( backsql_srch_info *bsi, struct berval *query ) ',' ); if ( bi->strcast_func.bv_val ) { - backsql_strfcat( &bsi->sel, &bsi->sel_len, "blbl", + backsql_strfcat( &bsi->sel, "blbl", &bi->strcast_func, (ber_len_t)sizeof( "('" /* ') */ ) - 1, "('" /* ') */ , @@ -681,21 +674,21 @@ backsql_srch_query( backsql_srch_info *bsi, struct berval *query ) (ber_len_t)sizeof( /* (' */ "')" ) - 1, /* (' */ "')" ); } else { - backsql_strfcat( &bsi->sel, &bsi->sel_len, "cbc", + backsql_strfcat( &bsi->sel, "cbc", '\'', &bsi->oc->oc->soc_cname, '\'' ); } - backsql_strfcat( &bsi->sel, &bsi->sel_len, "l", + backsql_strfcat( &bsi->sel, "l", (ber_len_t)sizeof( " AS objectClass,ldap_entries.dn AS dn" ) - 1, " AS objectClass,ldap_entries.dn AS dn" ); - backsql_strfcat( &bsi->from, &bsi->from_len, "lb", + backsql_strfcat( &bsi->from, "lb", (ber_len_t)sizeof( " FROM ldap_entries," ) - 1, " FROM ldap_entries,", &bsi->oc->keytbl ); - backsql_strfcat( &bsi->join_where, &bsi->jwhere_len, "lbcbl", + backsql_strfcat( &bsi->join_where, "lbcbl", (ber_len_t)sizeof( " WHERE " ) - 1, " WHERE ", &bsi->oc->keytbl, '.', @@ -705,49 +698,45 @@ backsql_srch_query( backsql_srch_info *bsi, struct berval *query ) switch ( bsi->scope ) { case LDAP_SCOPE_BASE: - if ( bsi->bi->upper_func.bv_val ) { - backsql_strfcat( &bsi->join_where, &bsi->jwhere_len, - "blbcb", - &bsi->bi->upper_func, + if ( bi->upper_func.bv_val ) { + backsql_strfcat( &bsi->join_where, "blbcb", + &bi->upper_func, (ber_len_t)sizeof( "(ldap_entries.dn)=" ) - 1, "(ldap_entries.dn)=", - &bsi->bi->upper_func_open, + &bi->upper_func_open, '?', - &bsi->bi->upper_func_close ); + &bi->upper_func_close ); } else { - backsql_strfcat( &bsi->join_where, &bsi->jwhere_len, - "l", + backsql_strfcat( &bsi->join_where, "l", (ber_len_t)sizeof( "ldap_entries.dn=?" ) - 1, "ldap_entries.dn=?" ); } break; case LDAP_SCOPE_ONELEVEL: - backsql_strfcat( &bsi->join_where, &bsi->jwhere_len, "l", + backsql_strfcat( &bsi->join_where, "l", (ber_len_t)sizeof( "ldap_entries.parent=?" ) - 1, "ldap_entries.parent=?" ); break; case LDAP_SCOPE_SUBTREE: - if ( bsi->bi->upper_func.bv_val ) { - backsql_strfcat( &bsi->join_where, &bsi->jwhere_len, - "blbcb", - &bsi->bi->upper_func, + if ( bi->upper_func.bv_val ) { + backsql_strfcat( &bsi->join_where, "blbcb", + &bi->upper_func, (ber_len_t)sizeof( "(ldap_entries.dn) LIKE " ) - 1, "(ldap_entries.dn) LIKE ", - &bsi->bi->upper_func_open, + &bi->upper_func_open, '?', - &bsi->bi->upper_func_close ); + &bi->upper_func_close ); } else { - backsql_strfcat( &bsi->join_where, &bsi->jwhere_len, - "l", + backsql_strfcat( &bsi->join_where, "l", (ber_len_t)sizeof( "ldap_entries.dn LIKE ?" ) - 1, "ldap_entries.dn LIKE ?" ); } #if 0 - backsql_strfcat( &bsi->join_where, &bsi->jwhere_len, "b", - &bsi->bi->subtree_cond ); + backsql_strfcat( &bsi->join_where, "b", + &bi->subtree_cond ); #endif break; @@ -757,12 +746,16 @@ backsql_srch_query( backsql_srch_info *bsi, struct berval *query ) rc = backsql_process_filter( bsi, bsi->filter ); if ( rc > 0 ) { - backsql_strfcat( query, &q_len, "bbblb", - &bsi->sel, - &bsi->from, - &bsi->join_where, + struct berbuf bb = BB_NULL; + + backsql_strfcat( &bb, "bbblb", + &bsi->sel.bb_val, + &bsi->from.bb_val, + &bsi->join_where.bb_val, (ber_len_t)sizeof( " AND " ) - 1, " AND ", - &bsi->flt_where ); + &bsi->flt_where.bb_val ); + + *query = bb.bb_val; } else if ( rc < 0 ) { /* @@ -775,18 +768,18 @@ backsql_srch_query( backsql_srch_info *bsi, struct berval *query ) query->bv_val = NULL; } - free( bsi->sel.bv_val ); - bsi->sel.bv_len = 0; - bsi->sel_len = 0; - free( bsi->from.bv_val ); - bsi->from.bv_len = 0; - bsi->from_len = 0; - free( bsi->join_where.bv_val ); - bsi->join_where.bv_len = 0; - bsi->jwhere_len = 0; - free( bsi->flt_where.bv_val ); - bsi->flt_where.bv_len = 0; - bsi->fwhere_len = 0; + free( bsi->sel.bb_val.bv_val ); + bsi->sel.bb_val.bv_len = 0; + bsi->sel.bb_len = 0; + free( bsi->from.bb_val.bv_val ); + bsi->from.bb_val.bv_len = 0; + bsi->from.bb_len = 0; + free( bsi->join_where.bb_val.bv_val ); + bsi->join_where.bb_val.bv_len = 0; + bsi->join_where.bb_len = 0; + free( bsi->flt_where.bb_val.bv_val ); + bsi->flt_where.bb_val.bv_len = 0; + bsi->flt_where.bb_len = 0; Debug( LDAP_DEBUG_TRACE, "<==backsql_srch_query()\n", 0, 0, 0 ); @@ -796,8 +789,9 @@ backsql_srch_query( backsql_srch_info *bsi, struct berval *query ) static int backsql_oc_get_candidates( void *v_oc, void *v_bsi ) { - backsql_oc_map_rec *oc = v_oc; - backsql_srch_info *bsi = v_bsi; + backsql_oc_map_rec *oc = v_oc; + backsql_srch_info *bsi = v_bsi; + backsql_info *bi = (backsql_info *)bsi->op->o_bd->be_private; struct berval query; SQLHSTMT sth; RETCODE rc; @@ -815,6 +809,7 @@ backsql_oc_get_candidates( void *v_oc, void *v_bsi ) "unchecked limit has been overcome\n", 0, 0, 0 ); /* should never get here */ assert( 0 ); + bsi->status = LDAP_OTHER; return BACKSQL_STOP; } @@ -823,6 +818,7 @@ backsql_oc_get_candidates( void *v_oc, void *v_bsi ) Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): " "could not construct query for objectclass\n", 0, 0, 0 ); + bsi->status = LDAP_OTHER; return BACKSQL_CONTINUE; } @@ -834,25 +830,33 @@ backsql_oc_get_candidates( void *v_oc, void *v_bsi ) if ( rc != SQL_SUCCESS ) { Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): " "error preparing query\n", 0, 0, 0 ); - backsql_PrintErrors( bsi->bi->db_env, bsi->dbh, sth, rc ); + backsql_PrintErrors( bi->db_env, bsi->dbh, sth, rc ); + bsi->status = LDAP_OTHER; return BACKSQL_CONTINUE; } + + Debug( LDAP_DEBUG_TRACE, "id: '%ld'\n", bsi->oc->id, 0, 0 ); if ( backsql_BindParamID( sth, 1, &bsi->oc->id ) != SQL_SUCCESS ) { Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): " "error binding objectclass id parameter\n", 0, 0, 0 ); + bsi->status = LDAP_OTHER; return BACKSQL_CONTINUE; } switch ( bsi->scope ) { case LDAP_SCOPE_BASE: + Debug( LDAP_DEBUG_TRACE, "(base)dn: '%s'\n", + bsi->base_dn->bv_val, 0, 0 ); + rc = backsql_BindParamStr( sth, 2, bsi->base_dn->bv_val, BACKSQL_MAX_DN_LEN ); if ( rc != SQL_SUCCESS ) { Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): " "error binding base_dn parameter\n", 0, 0, 0 ); - backsql_PrintErrors( bsi->bi->db_env, bsi->dbh, + backsql_PrintErrors( bi->db_env, bsi->dbh, sth, rc ); + bsi->status = LDAP_OTHER; return BACKSQL_CONTINUE; } break; @@ -885,7 +889,7 @@ backsql_oc_get_candidates( void *v_oc, void *v_bsi ) * If "dn" is being used, do a suffix search. * If "dn_ru" is being used, do a prefix search. */ - if ( BACKSQL_HAS_LDAPINFO_DN_RU( bsi->bi ) ) { + if ( BACKSQL_HAS_LDAPINFO_DN_RU( bi ) ) { temp_base_dn[ 0 ] = '\0'; for ( i = 0, j = bsi->base_dn->bv_len - 1; j >= 0; i++, j--) { @@ -893,16 +897,16 @@ backsql_oc_get_candidates( void *v_oc, void *v_bsi ) } temp_base_dn[ i ] = '%'; temp_base_dn[ i + 1 ] = '\0'; - ldap_pvt_str2upper( temp_base_dn ); } else { temp_base_dn[ 0 ] = '%'; AC_MEMCPY( &temp_base_dn[ 1 ], bsi->base_dn->bv_val, bsi->base_dn->bv_len + 1 ); - ldap_pvt_str2upper( &temp_base_dn[ 1 ] ); } + ldap_pvt_str2upper( temp_base_dn ); - Debug( LDAP_DEBUG_TRACE, "dn '%s'\n", temp_base_dn, 0, 0 ); + Debug( LDAP_DEBUG_TRACE, "(sub)dn: '%s'\n", temp_base_dn, + 0, 0 ); rc = backsql_BindParamStr( sth, 2, temp_base_dn, BACKSQL_MAX_DN_LEN ); @@ -910,15 +914,16 @@ backsql_oc_get_candidates( void *v_oc, void *v_bsi ) Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): " "error binding base_dn parameter (2)\n", 0, 0, 0 ); - backsql_PrintErrors( bsi->bi->db_env, bsi->dbh, + backsql_PrintErrors( bi->db_env, bsi->dbh, sth, rc ); + bsi->status = LDAP_OTHER; return BACKSQL_CONTINUE; } break; } case LDAP_SCOPE_ONELEVEL: - res = backsql_dn2id( bsi->bi, &base_id, + res = backsql_dn2id( bi, &base_id, bsi->dbh, bsi->base_dn ); if ( res != LDAP_SUCCESS ) { Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): " @@ -929,11 +934,15 @@ backsql_oc_get_candidates( void *v_oc, void *v_bsi ) return BACKSQL_CONTINUE; } + Debug( LDAP_DEBUG_TRACE, "(one)id: '%s'\n", base_id.id, + 0, 0 ); + rc = backsql_BindParamID( sth, 2, &base_id.id ); backsql_free_entryID( &base_id, 0 ); if ( rc != SQL_SUCCESS ) { Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): " "error binding base id parameter\n", 0, 0, 0 ); + bsi->status = LDAP_OTHER; return BACKSQL_CONTINUE; } break; @@ -943,8 +952,9 @@ backsql_oc_get_candidates( void *v_oc, void *v_bsi ) if ( !BACKSQL_SUCCESS( rc ) ) { Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): " "error executing query\n", 0, 0, 0 ); - backsql_PrintErrors( bsi->bi->db_env, bsi->dbh, sth, rc ); + backsql_PrintErrors( bi->db_env, bsi->dbh, sth, rc ); SQLFreeStmt( sth, SQL_DROP ); + bsi->status = LDAP_OTHER; return BACKSQL_CONTINUE; } @@ -1043,9 +1053,6 @@ backsql_search( Operation *op, SlapReply *rs ) return 1; } - /* TimesTen : Pass it along to the lower level routines */ - srch_info.use_reverse_dn = BACKSQL_USE_REVERSE_DN( bi ); - /* if not root, get appropriate limits */ if ( be_isroot( op->o_bd, &op->o_ndn ) ) { isroot = 1; diff --git a/servers/slapd/back-sql/util.c b/servers/slapd/back-sql/util.c index 126ca93b68..3e5f5275b2 100644 --- a/servers/slapd/back-sql/util.c +++ b/servers/slapd/back-sql/util.c @@ -51,59 +51,59 @@ char backsql_def_concat_func[] = "CONCAT(?,?)"; /* TimesTen */ char backsql_check_dn_ru_query[] = "SELECT dn_ru from ldap_entries"; -struct berval * -backsql_strcat( struct berval *dest, ber_len_t *buflen, ... ) +struct berbuf * +backsql_strcat( struct berbuf *dest, ... ) { va_list strs; ber_len_t cdlen, cslen, grow; char *cstr; assert( dest ); - assert( dest->bv_val == NULL - || dest->bv_len == strlen( dest->bv_val ) ); + assert( dest->bb_val.bv_val == NULL + || dest->bb_val.bv_len == strlen( dest->bb_val.bv_val ) ); #ifdef BACKSQL_TRACE Debug( LDAP_DEBUG_TRACE, "==>backsql_strcat()\n" ); #endif /* BACKSQL_TRACE */ - va_start( strs, buflen ); - if ( dest->bv_val == NULL || *buflen == 0 ) { - dest->bv_val = (char *)ch_calloc( BACKSQL_STR_GROW, + va_start( strs, dest ); + 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->bv_len = 0; - *buflen = BACKSQL_STR_GROW; + dest->bb_val.bv_len = 0; + dest->bb_len = BACKSQL_STR_GROW; } - cdlen = dest->bv_len; + cdlen = dest->bb_val.bv_len; while ( ( cstr = va_arg( strs, char * ) ) != NULL ) { cslen = strlen( cstr ); grow = BACKSQL_MAX( BACKSQL_STR_GROW, cslen ); - if ( *buflen - cdlen <= cslen ) { + if ( dest->bb_len - cdlen <= cslen ) { char *tmp_dest; #ifdef BACKSQL_TRACE Debug( LDAP_DEBUG_TRACE, "backsql_strcat(): " "buflen=%d, cdlen=%d, cslen=%d " "-- reallocating dest\n", - *buflen, cdlen + 1, cslen ); + dest->bb_len, cdlen + 1, cslen ); #endif /* BACKSQL_TRACE */ - tmp_dest = (char *)ch_realloc( dest->bv_val, - ( *buflen ) + grow * sizeof( char ) ); + tmp_dest = (char *)ch_realloc( dest->bb_val.bv_val, + ( dest->bb_len ) + grow * sizeof( char ) ); if ( tmp_dest == NULL ) { Debug( LDAP_DEBUG_ANY, "backsql_strcat(): " "could not reallocate string buffer.\n", 0, 0, 0 ); return NULL; } - dest->bv_val = tmp_dest; - *buflen += grow; + dest->bb_val.bv_val = tmp_dest; + dest->bb_len += grow; #ifdef BACKSQL_TRACE Debug( LDAP_DEBUG_TRACE, "backsql_strcat(): " - "new buflen=%d, dest=%p\n", *buflen, dest, 0 ); + "new buflen=%d, dest=%p\n", dest->bb_len, dest, 0 ); #endif /* BACKSQL_TRACE */ } - AC_MEMCPY( dest->bv_val + cdlen, cstr, cslen + 1 ); + AC_MEMCPY( dest->bb_val.bv_val + cdlen, cstr, cslen + 1 ); cdlen += cslen; } va_end( strs ); @@ -113,37 +113,36 @@ backsql_strcat( struct berval *dest, ber_len_t *buflen, ... ) dest, 0, 0 ); #endif /* BACKSQL_TRACE */ - dest->bv_len = cdlen; + dest->bb_val.bv_len = cdlen; return dest; } -struct berval * -backsql_strfcat( struct berval *dest, ber_len_t *buflen, const char *fmt, ... ) +struct berbuf * +backsql_strfcat( struct berbuf *dest, const char *fmt, ... ) { va_list strs; ber_len_t cdlen; assert( dest ); - assert( buflen ); assert( fmt ); - assert( *buflen == 0 || *buflen > dest->bv_len ); - assert( dest->bv_val == NULL - || dest->bv_len == strlen( dest->bv_val ) ); + assert( dest->bb_len == 0 || dest->bb_len > dest->bb_val.bv_len ); + assert( dest->bb_val.bv_val == NULL + || dest->bb_val.bv_len == strlen( dest->bb_val.bv_val ) ); #ifdef BACKSQL_TRACE Debug( LDAP_DEBUG_TRACE, "==>backsql_strfcat()\n" ); #endif /* BACKSQL_TRACE */ va_start( strs, fmt ); - if ( dest->bv_val == NULL || *buflen == 0 ) { - dest->bv_val = (char *)ch_calloc( BACKSQL_STR_GROW, + 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->bv_len = 0; - *buflen = BACKSQL_STR_GROW; + dest->bb_val.bv_len = 0; + dest->bb_len = BACKSQL_STR_GROW; } - cdlen = dest->bv_len; + cdlen = dest->bb_val.bv_len; for ( ; fmt[0]; fmt++ ) { ber_len_t cslen, grow; char *cstr, cc[ 2 ] = { '\0', '\0' }; @@ -185,36 +184,36 @@ backsql_strfcat( struct berval *dest, ber_len_t *buflen, const char *fmt, ... ) } grow = BACKSQL_MAX( BACKSQL_STR_GROW, cslen ); - if ( *buflen - cdlen <= cslen ) { + if ( dest->bb_len - cdlen <= cslen ) { char *tmp_dest; #ifdef BACKSQL_TRACE Debug( LDAP_DEBUG_TRACE, "backsql_strfcat(): " "buflen=%d, cdlen=%d, cslen=%d " "-- reallocating dest\n", - *buflen, cdlen + 1, cslen ); + dest->bb_len, cdlen + 1, cslen ); #endif /* BACKSQL_TRACE */ - tmp_dest = (char *)ch_realloc( dest->bv_val, - ( *buflen ) + grow * sizeof( char ) ); + tmp_dest = (char *)ch_realloc( dest->bb_val.bv_val, + ( dest->bb_len ) + grow * sizeof( char ) ); if ( tmp_dest == NULL ) { Debug( LDAP_DEBUG_ANY, "backsql_strfcat(): " "could not reallocate string buffer.\n", 0, 0, 0 ); return NULL; } - dest->bv_val = tmp_dest; - *buflen += grow * sizeof( char ); + dest->bb_val.bv_val = tmp_dest; + dest->bb_len += grow * sizeof( char ); #ifdef BACKSQL_TRACE Debug( LDAP_DEBUG_TRACE, "backsql_strfcat(): " - "new buflen=%d, dest=%p\n", *buflen, dest, 0 ); + "new buflen=%d, dest=%p\n", dest->bb_len, dest, 0 ); #endif /* BACKSQL_TRACE */ } assert( cstr ); - AC_MEMCPY( dest->bv_val + cdlen, cstr, cslen + 1 ); + AC_MEMCPY( dest->bb_val.bv_val + cdlen, cstr, cslen + 1 ); cdlen += cslen; } @@ -225,7 +224,7 @@ backsql_strfcat( struct berval *dest, ber_len_t *buflen, const char *fmt, ... ) dest, 0, 0 ); #endif /* BACKSQL_TRACE */ - dest->bv_len = cdlen; + dest->bb_val.bv_len = cdlen; return dest; } @@ -276,8 +275,7 @@ char * backsql_get_table_spec( char **p ) { char *s, *q; - struct berval res = BER_BVNULL; - ber_len_t res_len = 0; + struct berbuf res = BB_NULL; assert( p ); assert( *p ); @@ -293,7 +291,7 @@ backsql_get_table_spec( char **p ) #define BACKSQL_NEXT_WORD { \ while ( *s && isspace( (unsigned char)*s ) ) s++; \ - if ( !*s ) return res.bv_val; \ + if ( !*s ) return res.bb_val.bv_val; \ q = s; \ while ( *q && !isspace( (unsigned char)*q ) ) q++; \ if ( *q ) *q++='\0'; \ @@ -301,7 +299,7 @@ backsql_get_table_spec( char **p ) BACKSQL_NEXT_WORD; /* table name */ - backsql_strcat( &res, &res_len, s, NULL ); + backsql_strcat( &res, s, NULL ); s = q; BACKSQL_NEXT_WORD; @@ -311,29 +309,28 @@ backsql_get_table_spec( char **p ) } #if 0 - backsql_strcat( &res, &res_len, " AS ", s, NULL ); + backsql_strcat( &res, " AS ", s, NULL ); /* oracle doesn't understand AS :( */ #endif /* table alias */ - backsql_strfcat( &res, &res_len, "cs", ' ', s ); + backsql_strfcat( &res, "cs", ' ', s ); - return res.bv_val; + return res.bb_val.bv_val; } int backsql_merge_from_clause( - struct berval *dest_from, - ber_len_t *dest_len, + struct berbuf *dest_from, struct berval *src_from ) { char *s, *p, *srcc, *pos, e; - struct berval res = { 0 , NULL }; + struct berbuf res = BB_NULL; #ifdef BACKSQL_TRACE Debug( LDAP_DEBUG_TRACE, "==>backsql_merge_from_clause(): " "dest_from='%s',src_from='%s'\n", - dest_from ? dest_from->bv_val : "", src_from, 0 ); + dest_from ? dest_from->bb_val.bv_val : "", src_from, 0 ); #endif /* BACKSQL_TRACE */ srcc = ch_strdup( src_from->bv_val ); @@ -351,15 +348,13 @@ backsql_merge_from_clause( "p='%s' s='%s'\n", p, s, 0 ); #endif /* BACKSQL_TRACE */ - if ( res.bv_val == NULL ) { - backsql_strcat( &res, dest_len, s, NULL ); + if ( res.bb_val.bv_val == NULL ) { + backsql_strcat( &res, s, NULL ); } else { - pos = strstr( res.bv_val, s ); - if ( pos == NULL ) { - backsql_strfcat( &res, dest_len, "cs", ',', s ); - } else if ( ( e = pos[ strlen( s ) ] ) != '\0' && e != ',' ) { - backsql_strfcat( &res, dest_len, "cs", ',', s ); + pos = strstr( res.bb_val.bv_val, s ); + if ( pos == NULL || ( ( e = pos[ strlen( s ) ] ) != '\0' && e != ',' ) ) { + backsql_strfcat( &res, "cs", ',', s ); } } @@ -454,25 +449,28 @@ backsql_prepare_pattern( BerVarray values, struct berval *res ) { - ber_len_t len = 0; int i; + struct berbuf bb = BB_NULL; - res->bv_val = NULL; - res->bv_len = 0; + assert( res ); for ( i = 0; values[i].bv_val; i++ ) { if ( split_pattern[i].bv_val == NULL ) { + ch_free( bb.bb_val.bv_val ); return -1; } - backsql_strfcat( res, &len, "b", &split_pattern[ i ] ); - backsql_strfcat( res, &len, "b", &values[ i ] ); + backsql_strfcat( &bb, "b", &split_pattern[ i ] ); + backsql_strfcat( &bb, "b", &values[ i ] ); } if ( split_pattern[ i ].bv_val == NULL ) { + ch_free( bb.bb_val.bv_val ); return -1; } - backsql_strfcat( res, &len, "b", &split_pattern[ i ] ); + backsql_strfcat( &bb, "b", &split_pattern[ i ] ); + + *res = bb.bb_val; return 0; } diff --git a/servers/slapd/back-sql/util.h b/servers/slapd/back-sql/util.h index 37e94aa6f7..a510a604aa 100644 --- a/servers/slapd/back-sql/util.h +++ b/servers/slapd/back-sql/util.h @@ -16,36 +16,42 @@ #define BACKSQL_CONCAT -struct berval * backsql_strcat( struct berval *dest, ber_len_t *buflen, ... ); -struct berval * backsql_strfcat( struct berval *dest, ber_len_t *buflen, - const char *fmt, ... ); +typedef struct berbuf { + struct berval bb_val; + ber_len_t bb_len; +} BerBuffer; +#define BB_NULL { { 0, NULL }, 0 } + +struct berbuf * backsql_strcat( struct berbuf *dest, ... ); +struct berbuf * backsql_strfcat( struct berbuf *dest, const char *fmt, ... ); int backsql_entry_addattr( Entry *e, struct berval *at_name, struct berval *at_val, void *memctx ); typedef struct backsql_srch_info { + Operation *op; + + int bsi_flags; +#define BSQL_SF_ALL_OPER 0x0001 +#define BSQL_SF_FILTER_HASSUBORDINATE 0x0002 + struct berval *base_dn; int scope; Filter *filter; int slimit, tlimit; time_t stoptime; + backsql_entryID *id_list, *c_eid; int n_candidates; int abandon; - backsql_info *bi; + int status; + backsql_oc_map_rec *oc; - struct berval sel, from, join_where, flt_where; - ber_len_t sel_len, from_len, jwhere_len, fwhere_len; + struct berbuf sel, from, join_where, flt_where; SQLHDBC dbh; - int status; - Operation *op; AttributeName *attrs; - int bsi_flags; -#define BSQL_SF_ALL_OPER 0x0001 -#define BSQL_SF_FILTER_HASSUBORDINATE 0x0002 + Entry *e; - /* 1 if the db is TimesTen; 0 if it's not */ - int use_reverse_dn; } backsql_srch_info; void backsql_init_search( backsql_srch_info *bsi, @@ -68,7 +74,7 @@ extern char extern char backsql_check_dn_ru_query[]; -int backsql_merge_from_clause( struct berval *dest_from, ber_len_t *dest_len, +int backsql_merge_from_clause( struct berbuf *dest_from, struct berval *src_from ); int backsql_split_pattern( const char *pattern, BerVarray *split_pattern, diff --git a/servers/slapd/bind.c b/servers/slapd/bind.c index 112f099e05..93aedd3099 100644 --- a/servers/slapd/bind.c +++ b/servers/slapd/bind.c @@ -43,7 +43,7 @@ do_bind( struct berval mech = { 0, NULL }; struct berval dn = { 0, NULL }; ber_tag_t tag; - Backend *be; + Backend *be = NULL; #ifdef LDAP_SLAPI Slapi_PBlock *pb = op->o_pb; diff --git a/servers/slapd/config.c b/servers/slapd/config.c index 5adaada4c4..78b0a420e1 100644 --- a/servers/slapd/config.c +++ b/servers/slapd/config.c @@ -572,6 +572,12 @@ read_config( const char *fname, int depth ) slapd_args_file = ch_strdup( cargv[1] ); + } else if ( strcasecmp( cargv[0], "replica-pidfile" ) == 0 ) { + /* ignore */ ; + + } else if ( strcasecmp( cargv[0], "replica-argsfile" ) == 0 ) { + /* ignore */ ; + /* default password hash */ } else if ( strcasecmp( cargv[0], "password-hash" ) == 0 ) { if ( cargc < 2 ) { diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index 19f67952a5..8f8198fc91 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -37,7 +37,7 @@ #ifdef LDAP_DEVEL #define SLAP_EXTENDED_SCHEMA 1 -#define LDAP_CACHING +//#define LDAP_CACHING #endif LDAP_BEGIN_DECL