static int backsql_process_filter( backsql_srch_info *bsi, Filter *f );
+static int backsql_process_filter_attr( backsql_srch_info *bsi, Filter *f,
+ backsql_at_map_rec *at );
+
static int
backsql_attrlist_add( backsql_srch_info *bsi, AttributeDescription *ad )
{
return 0;
}
+#if 0 /* always uppercase strings by now */
if ( SLAP_MR_ASSOCIATED( f->f_sub_desc->ad_type->sat_substr,
- bi->bi_caseIgnoreMatch ) ) {
+ bi->bi_caseIgnoreMatch ) )
+#endif
+ {
casefold = 1;
}
backsql_strfcat( &bsi->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 : "<NULL>", 0 );
+ Debug( LDAP_DEBUG_TRACE, "expr: '%s' '%s'\n", at->bam_sel_expr.bv_val,
+ at->bam_sel_expr_u.bv_val ? at->bam_sel_expr_u.bv_val : "<NULL>", 0 );
if ( casefold && bi->upper_func.bv_val ) {
/*
* If a pre-upper-cased version of the column exists, use it
*/
- if ( at->sel_expr_u.bv_val ) {
+ if ( at->bam_sel_expr_u.bv_val ) {
backsql_strfcat( &bsi->bsi_flt_where,
"bl",
- &at->sel_expr_u,
+ &at->bam_sel_expr_u,
(ber_len_t)sizeof( " LIKE '" ) - 1,
" LIKE '" );
} else {
"bcbcl",
&bi->upper_func,
'(',
- &at->sel_expr,
+ &at->bam_sel_expr,
')',
(ber_len_t)sizeof( " LIKE '" ) - 1,
" LIKE '" );
}
} else {
backsql_strfcat( &bsi->bsi_flt_where, "bl",
- &at->sel_expr,
+ &at->bam_sel_expr,
(ber_len_t)sizeof( " LIKE '" ) - 1, " LIKE '" );
}
static int
backsql_process_filter( backsql_srch_info *bsi, Filter *f )
{
- backsql_info *bi = (backsql_info *)bsi->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;
- int casefold = 0;
int rc = 0;
- struct berval *filter_value = NULL;
- MatchingRule *matching_rule = NULL;
- struct berval ordering = BER_BVC("<=");
Debug( LDAP_DEBUG_TRACE, "==>backsql_process_filter()\n", 0, 0, 0 );
- if ( f == NULL || f->f_choice == SLAPD_FILTER_COMPUTED ) {
- return 0;
+ if ( f->f_choice == SLAPD_FILTER_COMPUTED ) {
+ Debug( LDAP_DEBUG_TRACE, "backsql_process_filter(): "
+ "invalid filter\n", 0, 0, 0 );
+ goto impossible;
}
switch( f->f_choice ) {
*/
if ( ad == slap_schema.si_ad_objectClass
|| ad == slap_schema.si_ad_structuralObjectClass ) {
- struct berbuf bb = BB_NULL;
+ /*
+ * If the filter is LDAP_FILTER_PRESENT, then it's done;
+ * otherwise, let's see if we are lucky: filtering
+ * for "structural" objectclass or ancestor...
+ */
+ switch ( f->f_choice ) {
+ case LDAP_FILTER_EQUALITY:
+ {
+ ObjectClass *oc = oc_bvfind( &f->f_av_value );
+
+ if ( oc == NULL ) {
+ Debug( LDAP_DEBUG_TRACE,
+ "backsql_process_filter(): "
+ "unknown objectClass \"%s\" "
+ "in filter\n",
+ f->f_av_value.bv_val, 0, 0 );
+ bsi->bsi_status = LDAP_OTHER;
+ goto impossible;
+ }
- at = &oc_attr;
- backsql_strfcat( &bb, "cbc",
- '\'',
- &bsi->bsi_oc->oc->soc_cname,
- '\'' );
- at->sel_expr = bb.bb_val;
+ /*
+ * objectClass inheritance:
+ * - a search for "person" will also return "inetOrgPerson"
+ * - a search for "top" will return everything
+ */
+ if ( is_object_subclass( oc, bsi->bsi_oc->bom_oc ) ) {
+ goto filter_oc_success;
+ }
+
+ break;
+ }
+
+ case LDAP_FILTER_PRESENT:
+filter_oc_success:;
+ backsql_strfcat( &bsi->bsi_flt_where, "l",
+ (ber_len_t)sizeof( "1=1" ) - 1, "1=1" );
+ bsi->bsi_status = LDAP_SUCCESS;
+ goto done;
+
+ default:
+ Debug( LDAP_DEBUG_TRACE,
+ "backsql_process_filter(): "
+ "illegal/unhandled filter "
+ "on objectClass attribute",
+ 0, 0, 0 );
+ bsi->bsi_status = LDAP_OTHER;
+ goto impossible;
+ }
} else if ( ad == slap_schema.si_ad_hasSubordinates || ad == NULL ) {
/*
backsql_attrlist_add( bsi, NULL );
}
goto done;
-
- } else {
- at = backsql_ad2at( bsi->bsi_oc, ad );
}
+ /* look for attribute (also if objectClass but not structural one) */
+ at = backsql_ad2at( bsi->bsi_oc, ad );
+
if ( at == NULL ) {
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->bsi_oc ), 0 );
+
+#if 0
backsql_strfcat( &bsi->bsi_flt_where, "l",
(ber_len_t)sizeof( "1=0" ) - 1, "1=0" );
bsi->bsi_status = LDAP_UNDEFINED_TYPE;
goto impossible;
+#else
+ /* search anyway; other parts of the filter may succeeed */
+ backsql_strfcat( &bsi->bsi_flt_where, "l",
+ (ber_len_t)sizeof( "1=1" ) - 1, "1=1" );
+ bsi->bsi_status = LDAP_SUCCESS;
+ goto done;
+#endif
}
- backsql_merge_from_clause( &bsi->bsi_from, &at->from_tbls );
+ /* apply extra level of parens only if required */
+ done = 0;
+ if ( at->bam_next ) {
+ backsql_strfcat( &bsi->bsi_flt_where, "c", '(' );
+ done = 1;
+ }
+next:;
+ if ( backsql_process_filter_attr( bsi, f, at ) == -1 ) {
+ return -1;
+ }
+
+ if ( at->bam_next ) {
+ backsql_strfcat( &bsi->bsi_flt_where, "l",
+ sizeof( " OR " ) - 1, " OR " );
+ at = at->bam_next;
+ goto next;
+ }
+ if ( done ) {
+ backsql_strfcat( &bsi->bsi_flt_where, "c", ')' );
+ }
+
+done:;
+ Debug( LDAP_DEBUG_TRACE, "<==backsql_process_filter()\n", 0, 0, 0 );
+ return 1;
+
+impossible:;
+ Debug( LDAP_DEBUG_TRACE, "<==backsql_process_filter() returns -1\n",
+ 0, 0, 0 );
+ return -1;
+}
+
+static int
+backsql_process_filter_attr( backsql_srch_info *bsi, Filter *f, backsql_at_map_rec *at )
+{
+ backsql_info *bi = (backsql_info *)bsi->bsi_op->o_bd->be_private;
+ int casefold = 0;
+ struct berval *filter_value = NULL;
+ MatchingRule *matching_rule = NULL;
+ struct berval ordering = BER_BVC("<=");
+
+ Debug( LDAP_DEBUG_TRACE, "==>backsql_process_filter_attr(%s)\n",
+ at->bam_ad->ad_cname.bv_val, 0, 0 );
+
+ backsql_merge_from_clause( &bsi->bsi_from, &at->bam_from_tbls );
+
/*
* need to add this attribute to list of attrs to load,
* so that we can do test_filter() later
*/
- backsql_attrlist_add( bsi, ad );
+ backsql_attrlist_add( bsi, at->bam_ad );
- if ( at->join_where.bv_val != NULL
- && strstr( bsi->bsi_join_where.bb_val.bv_val, at->join_where.bv_val ) == NULL ) {
+ if ( at->bam_join_where.bv_val != NULL
+ && strstr( bsi->bsi_join_where.bb_val.bv_val, at->bam_join_where.bv_val ) == NULL ) {
backsql_strfcat( &bsi->bsi_join_where, "lb",
(ber_len_t)sizeof( " AND " ) - 1, " AND ",
- &at->join_where );
+ &at->bam_join_where );
}
switch ( f->f_choice ) {
case LDAP_FILTER_EQUALITY:
filter_value = &f->f_av_value;
- matching_rule = ad->ad_type->sat_equality;
+ matching_rule = at->bam_ad->ad_type->sat_equality;
goto equality_match;
casefold = 1;
}
- /*
- * objectClass inheritance:
- * - a search for "person" will also return "inetOrgPerson"
- * - a search for "top" will return everything
- */
- if ( at == &oc_attr ) {
- ObjectClass *oc = oc_bvfind( filter_value );
-
- rc = is_object_subclass( oc, bsi->bsi_oc->oc );
- if ( rc ) {
- backsql_strfcat( &bsi->bsi_flt_where, "l",
- sizeof( "(1=1)" ) - 1, "(1=1)" );
- break;
-
- } else {
- rc = -1;
- goto impossible;
- }
- }
-
/*
* maybe we should check type of at->sel_expr here somehow,
* to know whether upper_func is applicable, but for now
if ( casefold && bi->upper_func.bv_val ) {
size_t start;
- if ( at->sel_expr_u.bv_val ) {
+ if ( at->bam_sel_expr_u.bv_val ) {
backsql_strfcat( &bsi->bsi_flt_where, "cbl",
'(', /* ) */
- &at->sel_expr_u,
+ &at->bam_sel_expr_u,
(ber_len_t)sizeof( "='" ) - 1,
"='" );
} else {
'(' /* ) */ ,
&bi->upper_func,
'(' /* ) */ ,
- &at->sel_expr,
+ &at->bam_sel_expr,
(ber_len_t)sizeof( /* ( */ ")='" ) - 1,
/* ( */ ")='" );
}
} else {
backsql_strfcat( &bsi->bsi_flt_where, "cblbl",
'(',
- &at->sel_expr,
+ &at->bam_sel_expr,
(ber_len_t)sizeof( "='" ) - 1, "='",
filter_value,
(ber_len_t)sizeof( /* (' */ "')" ) - 1,
/* fall thru to next case */
case LDAP_FILTER_LE:
- if ( SLAP_MR_ASSOCIATED( ad->ad_type->sat_ordering,
- bi->bi_caseIgnoreMatch ) ) {
+#if 0 /* always uppercase strings by now */
+ if ( SLAP_MR_ASSOCIATED( at->bam_ad->ad_type->sat_ordering,
+ bi->bi_caseIgnoreMatch ) )
+#endif
+ {
casefold = 1;
}
if ( casefold && bi->upper_func.bv_val ) {
size_t start;
- if ( at->sel_expr_u.bv_val ) {
+ if ( at->bam_sel_expr_u.bv_val ) {
backsql_strfcat( &bsi->bsi_flt_where, "cbbc",
'(',
- &at->sel_expr_u,
+ &at->bam_sel_expr_u,
&ordering,
'\'' );
} else {
'(' /* ) */ ,
&bi->upper_func,
'(' /* ) */ ,
- &at->sel_expr,
+ &at->bam_sel_expr,
/* ( */ ')',
&ordering,
'\'' );
} else {
backsql_strfcat( &bsi->bsi_flt_where, "cbbcbl",
'(' /* ) */ ,
- &at->sel_expr,
+ &at->bam_sel_expr,
&ordering,
'\'',
&f->f_av_value,
backsql_strfcat( &bsi->bsi_flt_where, "lbl",
(ber_len_t)sizeof( "NOT (" /* ) */) - 1,
"NOT (", /* ) */
- &at->sel_expr,
+ &at->bam_sel_expr,
(ber_len_t)sizeof( /* ( */ " IS NULL)" ) - 1,
/* ( */ " IS NULL)" );
break;
if ( bi->upper_func.bv_val ) {
size_t start;
- if ( at->sel_expr_u.bv_val ) {
+ if ( at->bam_sel_expr_u.bv_val ) {
backsql_strfcat( &bsi->bsi_flt_where, "cbl",
'(', /* ) */
- &at->sel_expr_u,
+ &at->bam_sel_expr_u,
(ber_len_t)sizeof( " LIKE '%" ) - 1,
" LIKE '%" );
} else {
'(' /* ) */ ,
&bi->upper_func,
'(' /* ) */ ,
- &at->sel_expr,
+ &at->bam_sel_expr,
(ber_len_t)sizeof( /* ( */ ") LIKE '%" ) - 1,
/* ( */ ") LIKE '%" );
}
} else {
backsql_strfcat( &bsi->bsi_flt_where, "cblbl",
'(', /* ) */
- &at->sel_expr,
+ &at->bam_sel_expr,
(ber_len_t)sizeof( " LIKE '%" ) - 1,
" LIKE '%",
&f->f_av_value,
}
-done:
- if ( oc_attr.sel_expr.bv_val != NULL ) {
- free( oc_attr.sel_expr.bv_val );
- }
-
- Debug( LDAP_DEBUG_TRACE, "<==backsql_process_filter()\n", 0, 0, 0 );
- return 1;
+ Debug( LDAP_DEBUG_TRACE, "<==backsql_process_filter_attr(%s)\n",
+ at->bam_ad->ad_cname.bv_val, 0, 0 );
-impossible:
- if ( oc_attr.sel_expr.bv_val != NULL ) {
- free( oc_attr.sel_expr.bv_val );
- }
- Debug( LDAP_DEBUG_TRACE, "<==backsql_process_filter() returns -1\n",
- 0, 0, 0 );
- return -1;
+ return 1;
}
static int
backsql_strfcat( &bsi->bsi_sel, "lbcbc",
(ber_len_t)sizeof( "SELECT DISTINCT ldap_entries.id," ) - 1,
"SELECT DISTINCT ldap_entries.id,",
- &bsi->bsi_oc->keytbl,
+ &bsi->bsi_oc->bom_keytbl,
'.',
- &bsi->bsi_oc->keycol,
+ &bsi->bsi_oc->bom_keycol,
',' );
if ( bi->strcast_func.bv_val ) {
&bi->strcast_func,
(ber_len_t)sizeof( "('" /* ') */ ) - 1,
"('" /* ') */ ,
- &bsi->bsi_oc->oc->soc_cname,
+ &bsi->bsi_oc->bom_oc->soc_cname,
(ber_len_t)sizeof( /* (' */ "')" ) - 1,
/* (' */ "')" );
} else {
backsql_strfcat( &bsi->bsi_sel, "cbc",
'\'',
- &bsi->bsi_oc->oc->soc_cname,
+ &bsi->bsi_oc->bom_oc->soc_cname,
'\'' );
}
backsql_strfcat( &bsi->bsi_sel, "l",
backsql_strfcat( &bsi->bsi_from, "lb",
(ber_len_t)sizeof( " FROM ldap_entries," ) - 1,
" FROM ldap_entries,",
- &bsi->bsi_oc->keytbl );
+ &bsi->bsi_oc->bom_keytbl );
backsql_strfcat( &bsi->bsi_join_where, "lbcbl",
(ber_len_t)sizeof( " WHERE " ) - 1, " WHERE ",
- &bsi->bsi_oc->keytbl,
+ &bsi->bsi_oc->bom_keytbl,
'.',
- &bsi->bsi_oc->keycol,
+ &bsi->bsi_oc->bom_keycol,
(ber_len_t)sizeof( "=ldap_entries.keyval AND ldap_entries.oc_map_id=? AND " ) - 1,
"=ldap_entries.keyval AND ldap_entries.oc_map_id=? AND " );
if ( res ) {
Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): "
"error while constructing query for objectclass '%s'\n",
- oc->oc->soc_cname.bv_val, 0, 0 );
+ oc->bom_oc->soc_cname.bv_val, 0, 0 );
/*
* FIXME: need to separate errors from legally
* impossible filters
if ( query.bv_val == NULL ) {
Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): "
"could not construct query for objectclass '%s'\n",
- oc->oc->soc_cname.bv_val, 0, 0 );
+ oc->bom_oc->soc_cname.bv_val, 0, 0 );
bsi->bsi_status = LDAP_SUCCESS;
return BACKSQL_CONTINUE;
}
return BACKSQL_CONTINUE;
}
- Debug( LDAP_DEBUG_TRACE, "id: '%ld'\n", bsi->bsi_oc->id, 0, 0 );
+ Debug( LDAP_DEBUG_TRACE, "id: '%ld'\n", bsi->bsi_oc->bom_id, 0, 0 );
- if ( backsql_BindParamID( sth, 1, &bsi->bsi_oc->id ) != SQL_SUCCESS ) {
+ if ( backsql_BindParamID( sth, 1, &bsi->bsi_oc->bom_id ) != SQL_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): "
"error binding objectclass id parameter\n", 0, 0, 0 );
bsi->bsi_status = LDAP_OTHER;
sizeof( backsql_entryID ) );
c_id->id = strtol( row.cols[ 0 ], NULL, 0 );
c_id->keyval = strtol( row.cols[ 1 ], NULL, 0 );
- c_id->oc_id = bsi->bsi_oc->id;
+ c_id->oc_id = bsi->bsi_oc->bom_id;
ber_str2bv( row.cols[ 3 ], 0, 1, &c_id->dn );
c_id->next = bsi->bsi_id_list;
bsi->bsi_id_list = c_id;
ber_bvarray_free( refs );
}
- if (!rs->sr_ref) {
+ if ( !rs->sr_ref ) {
rs->sr_text = "bad_referral object";
}