From: Pierangelo Masarati Date: Sat, 25 Sep 2004 18:11:06 +0000 (+0000) Subject: consistently check return value of BindParam*; rework macros to ease parameter bindin... X-Git-Tag: OPENLDAP_REL_ENG_2_3_0ALPHA~502 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=b09663d784b74fc304a578ba9fbe425dcd1da73d;p=openldap consistently check return value of BindParam*; rework macros to ease parameter binding; always add data length to string values (may need to specialize for integers) --- diff --git a/servers/slapd/back-sql/add.c b/servers/slapd/back-sql/add.c index 96bd88c191..c0918b8ccf 100644 --- a/servers/slapd/back-sql/add.c +++ b/servers/slapd/back-sql/add.c @@ -73,13 +73,7 @@ backsql_modify_delete_all_values( return LDAP_SUCCESS; } -#ifdef BACKSQL_ARBITRARY_KEY - rc = backsql_BindParamStr( asth, 1, - e_id->eid_keyval.bv_val, - BACKSQL_MAX_KEY_LEN ); -#else /* ! BACKSQL_ARBITRARY_KEY */ - rc = backsql_BindParamID( asth, 1, &e_id->eid_keyval ); -#endif /* ! BACKSQL_ARBITRARY_KEY */ + rc = backsql_BindParamID( asth, 1, SQL_PARAM_INPUT, &e_id->eid_keyval ); if ( rc != SQL_SUCCESS ) { Debug( LDAP_DEBUG_TRACE, " backsql_modify_delete_all_values(): " @@ -143,35 +137,59 @@ backsql_modify_delete_all_values( rs->sr_text = "SQL-backend error"; return rs->sr_err = LDAP_OTHER; } - return LDAP_SUCCESS; + + continue; } if ( BACKSQL_IS_DEL( at->bam_expect_return ) ) { pno = 1; - SQLBindParameter( sth, 1, - SQL_PARAM_OUTPUT, - SQL_C_ULONG, - SQL_INTEGER, - 0, 0, &prc, 0, 0 ); + rc = backsql_BindParamInt( sth, 1, + SQL_PARAM_OUTPUT, &prc ); + if ( rc != SQL_SUCCESS ) { + Debug( LDAP_DEBUG_TRACE, + " backsql_modify_delete_all_values(): " + "error binding output parameter for %s[%d]\n", + at->bam_ad->ad_cname.bv_val, i, 0 ); + backsql_PrintErrors( bi->db_env, dbh, + sth, rc ); + SQLFreeStmt( sth, SQL_DROP ); + + if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) { + rs->sr_text = "SQL-backend error"; + return rs->sr_err = LDAP_OTHER; + } + + continue; + } + } else { pno = 0; } po = ( BACKSQL_IS_DEL( at->bam_param_order ) ) > 0; + rc = backsql_BindParamID( sth, pno + 1 + po, + SQL_PARAM_INPUT, &e_id->eid_keyval ); + if ( rc != SQL_SUCCESS ) { + Debug( LDAP_DEBUG_TRACE, + " backsql_modify_delete_all_values(): " + "error binding keyval parameter for %s[%d]\n", + at->bam_ad->ad_cname.bv_val, i, 0 ); + backsql_PrintErrors( bi->db_env, dbh, + sth, rc ); + SQLFreeStmt( sth, SQL_DROP ); + + if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) { + rs->sr_text = "SQL-backend error"; + return rs->sr_err = LDAP_OTHER; + } + + continue; + } #ifdef BACKSQL_ARBITRARY_KEY - SQLBindParameter( sth, pno + 1 + po, - SQL_PARAM_INPUT, - SQL_C_CHAR, SQL_VARCHAR, - 0, 0, e_id->eid_keyval.bv_val, - 0, 0 ); Debug( LDAP_DEBUG_TRACE, " backsql_modify_delete_all_values() " "arg%d=%s\n", pno + 1 + po, e_id->eid_keyval.bv_val, 0 ); #else /* ! BACKSQL_ARBITRARY_KEY */ - SQLBindParameter( sth, pno + 1 + po, - SQL_PARAM_INPUT, - SQL_C_ULONG, SQL_INTEGER, - 0, 0, &e_id->eid_keyval, 0, 0 ); Debug( LDAP_DEBUG_TRACE, " backsql_modify_delete_all_values() " "arg%d=%lu\n", @@ -183,11 +201,24 @@ backsql_modify_delete_all_values( * maybe need binary bind? */ col_len = strlen( row.cols[ i ] ); - SQLBindParameter( sth, pno + 2 - po, - SQL_PARAM_INPUT, - SQL_C_CHAR, SQL_CHAR, - col_len, 0, row.cols[ i ], - col_len, 0 ); + rc = backsql_BindParamStr( sth, pno + 2 - po, + SQL_PARAM_INPUT, row.cols[ i ], col_len ); + if ( rc != SQL_SUCCESS ) { + Debug( LDAP_DEBUG_TRACE, + " backsql_modify_delete_all_values(): " + "error binding value parameter for %s[%d]\n", + at->bam_ad->ad_cname.bv_val, i, 0 ); + backsql_PrintErrors( bi->db_env, dbh, + sth, rc ); + SQLFreeStmt( sth, SQL_DROP ); + + if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) { + rs->sr_text = "SQL-backend error"; + return rs->sr_err = LDAP_OTHER; + } + + continue; + } Debug( LDAP_DEBUG_TRACE, " backsql_modify_delete_all_values(): " @@ -393,28 +424,47 @@ add_only:; if ( BACKSQL_IS_ADD( at->bam_expect_return ) ) { pno = 1; - SQLBindParameter( sth, 1, - SQL_PARAM_OUTPUT, - SQL_C_ULONG, SQL_INTEGER, - 0, 0, &prc, 0, 0); + rc = backsql_BindParamInt( sth, 1, + SQL_PARAM_OUTPUT, &prc ); + if ( rc != SQL_SUCCESS ) { + Debug( LDAP_DEBUG_TRACE, + " backsql_modify_internal(): " + "error binding output parameter for %s[%d]\n", + at->bam_ad->ad_cname.bv_val, i, 0 ); + backsql_PrintErrors( bi->db_env, dbh, + sth, rc ); + SQLFreeStmt( sth, SQL_DROP ); + + rs->sr_text = "SQL-backend error"; + rs->sr_err = LDAP_OTHER; + goto done; + } + } else { pno = 0; } po = ( BACKSQL_IS_ADD( at->bam_param_order ) ) > 0; + rc = backsql_BindParamID( sth, pno + 1 + po, + SQL_PARAM_INPUT, &e_id->eid_keyval ); + if ( rc != SQL_SUCCESS ) { + Debug( LDAP_DEBUG_TRACE, + " backsql_modify_internal(): " + "error binding keyval parameter for %s[%d]\n", + at->bam_ad->ad_cname.bv_val, i, 0 ); + backsql_PrintErrors( bi->db_env, dbh, + sth, rc ); + SQLFreeStmt( sth, SQL_DROP ); + + rs->sr_text = "SQL-backend error"; + rs->sr_err = LDAP_OTHER; + goto done; + } #ifdef BACKSQL_ARBITRARY_KEY - SQLBindParameter( sth, pno + 1 + po, - SQL_PARAM_INPUT, - SQL_C_CHAR, SQL_VARCHAR, - 0, 0, e_id->eid_keyval.bv_val, 0, 0 ); Debug( LDAP_DEBUG_TRACE, " backsql_modify_internal(): " "arg%d=\"%s\"\n", pno + 1 + po, e_id->eid_keyval.bv_val, 0 ); #else /* ! BACKSQL_ARBITRARY_KEY */ - SQLBindParameter( sth, pno + 1 + po, - SQL_PARAM_INPUT, - SQL_C_ULONG, SQL_INTEGER, - 0, 0, &e_id->eid_keyval, 0, 0 ); Debug( LDAP_DEBUG_TRACE, " backsql_modify_internal(): " "arg%d=\"%lu\"\n", @@ -425,11 +475,21 @@ add_only:; * check for syntax needed here * maybe need binary bind? */ - SQLBindParameter( sth, pno + 2 - po, - SQL_PARAM_INPUT, - SQL_C_CHAR, SQL_CHAR, - at_val->bv_len, 0, at_val->bv_val, - at_val->bv_len, 0 ); + rc = backsql_BindParamBerVal( sth, pno + 2 - po, + SQL_PARAM_INPUT, at_val ); + if ( rc != SQL_SUCCESS ) { + Debug( LDAP_DEBUG_TRACE, + " backsql_modify_internal(): " + "error binding value parameter for %s[%d]\n", + at->bam_ad->ad_cname.bv_val, i, 0 ); + backsql_PrintErrors( bi->db_env, dbh, + sth, rc ); + SQLFreeStmt( sth, SQL_DROP ); + + rs->sr_text = "SQL-backend error"; + rs->sr_err = LDAP_OTHER; + goto done; + } Debug( LDAP_DEBUG_TRACE, " backsql_modify_internal(): " "arg%d=\"%s\"; executing \"%s\"\n", @@ -507,34 +567,74 @@ add_only:; if ( BACKSQL_IS_DEL( at->bam_expect_return ) ) { pno = 1; - SQLBindParameter( sth, 1, - SQL_PARAM_OUTPUT, - SQL_C_ULONG, SQL_INTEGER, - 0, 0, &prc, 0, 0 ); + rc = backsql_BindParamInt( sth, 1, + SQL_PARAM_OUTPUT, &prc ); + if ( rc != SQL_SUCCESS ) { + Debug( LDAP_DEBUG_TRACE, + " backsql_modify_internal(): " + "error binding output parameter for %s[%d]\n", + at->bam_ad->ad_cname.bv_val, i, 0 ); + backsql_PrintErrors( bi->db_env, dbh, + sth, rc ); + SQLFreeStmt( sth, SQL_DROP ); + + rs->sr_text = "SQL-backend error"; + rs->sr_err = LDAP_OTHER; + goto done; + } + } else { pno = 0; } po = ( BACKSQL_IS_DEL( at->bam_param_order ) ) > 0; + rc = backsql_BindParamID( sth, pno + 1 + po, + SQL_PARAM_INPUT, &e_id->eid_keyval ); + if ( rc != SQL_SUCCESS ) { + Debug( LDAP_DEBUG_TRACE, + " backsql_modify_internal(): " + "error binding keyval parameter for %s[%d]\n", + at->bam_ad->ad_cname.bv_val, i, 0 ); + backsql_PrintErrors( bi->db_env, dbh, + sth, rc ); + SQLFreeStmt( sth, SQL_DROP ); + + rs->sr_text = "SQL-backend error"; + rs->sr_err = LDAP_OTHER; + goto done; + } #ifdef BACKSQL_ARBITRARY_KEY - SQLBindParameter( sth, pno + 1 + po, - SQL_PARAM_INPUT, - SQL_C_CHAR, SQL_VARCHAR, - 0, 0, e_id->eid_keyval.bv_val, 0, 0 ); + Debug( LDAP_DEBUG_TRACE, + " backsql_modify_internal(): " + "arg%d=\"%s\"\n", + pno + 1 + po, e_id->eid_keyval.bv_val, 0 ); #else /* ! BACKSQL_ARBITRARY_KEY */ - SQLBindParameter( sth, pno + 1 + po, - SQL_PARAM_INPUT, - SQL_C_ULONG, SQL_INTEGER, - 0, 0, &e_id->eid_keyval, 0, 0 ); + Debug( LDAP_DEBUG_TRACE, + " backsql_modify_internal(): " + "arg%d=\"%lu\"\n", + pno + 1 + po, e_id->eid_keyval, 0 ); #endif /* ! BACKSQL_ARBITRARY_KEY */ /* * check for syntax needed here * maybe need binary bind? */ - SQLBindParameter( sth, pno + 2 - po, - SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, - at_val->bv_len, 0, at_val->bv_val, - at_val->bv_len, 0 ); + rc = backsql_BindParamBerVal( sth, pno + 2 - po, + SQL_PARAM_INPUT, at_val ); + if ( rc != SQL_SUCCESS ) { + Debug( LDAP_DEBUG_TRACE, + " backsql_modify_internal(): " + "error binding value parameter for %s[%d]\n", + at->bam_ad->ad_cname.bv_val, i, 0 ); + backsql_PrintErrors( bi->db_env, dbh, + sth, rc ); + SQLFreeStmt( sth, SQL_DROP ); + + if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) { + rs->sr_text = "SQL-backend error"; + rs->sr_err = LDAP_OTHER; + goto done; + } + } Debug( LDAP_DEBUG_TRACE, " backsql_modify_internal(): " @@ -672,18 +772,49 @@ backsql_add_attr( if ( BACKSQL_IS_ADD( at_rec->bam_expect_return ) ) { pno = 1; - SQLBindParameter( sth, 1, SQL_PARAM_OUTPUT, - SQL_C_ULONG, SQL_INTEGER, - 0, 0, &prc, 0, 0 ); + rc = backsql_BindParamInt( sth, 1, SQL_PARAM_OUTPUT, &prc ); + if ( rc != SQL_SUCCESS ) { + Debug( LDAP_DEBUG_TRACE, + " backsql_add_attr(): " + "error binding output parameter for %s[%d]\n", + at_rec->bam_ad->ad_cname.bv_val, i, 0 ); + backsql_PrintErrors( bi->db_env, dbh, + sth, rc ); + SQLFreeStmt( sth, SQL_DROP ); + + if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) { + rs->sr_text = "SQL-backend error"; + return rs->sr_err = LDAP_OTHER; + } + + return LDAP_SUCCESS; + } + } else { pno = 0; } po = ( BACKSQL_IS_ADD( at_rec->bam_param_order ) ) > 0; currpos = pno + 1 + po; - SQLBindParameter( sth, currpos, - SQL_PARAM_INPUT, SQL_C_ULONG, - SQL_INTEGER, 0, 0, &new_keyval, 0, 0 ); + rc = backsql_BindParamInt( sth, currpos, + SQL_PARAM_INPUT, &new_keyval ); + if ( rc != SQL_SUCCESS ) { + Debug( LDAP_DEBUG_TRACE, + " backsql_add_attr(): " + "error binding keyval parameter for %s[%d]\n", + at_rec->bam_ad->ad_cname.bv_val, i, 0 ); + backsql_PrintErrors( bi->db_env, dbh, + sth, rc ); + SQLFreeStmt( sth, SQL_DROP ); + + if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) { + rs->sr_text = "SQL-backend error"; + return rs->sr_err = LDAP_OTHER; + } + + return LDAP_SUCCESS; + } + currpos = pno + 2 - po; /* @@ -691,8 +822,23 @@ backsql_add_attr( * maybe need binary bind? */ - backsql_BindParamStr( sth, currpos, - at_val->bv_val, at_val->bv_len + 1 ); + rc = backsql_BindParamBerVal( sth, currpos, SQL_PARAM_INPUT, at_val ); + if ( rc != SQL_SUCCESS ) { + Debug( LDAP_DEBUG_TRACE, + " backsql_add_attr(): " + "error binding value parameter for %s[%d]\n", + at_rec->bam_ad->ad_cname.bv_val, i, 0 ); + backsql_PrintErrors( bi->db_env, dbh, + sth, rc ); + SQLFreeStmt( sth, SQL_DROP ); + + if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) { + rs->sr_text = "SQL-backend error"; + return rs->sr_err = LDAP_OTHER; + } + + return LDAP_SUCCESS; + } #ifdef LDAP_DEBUG snprintf( logbuf, sizeof( logbuf ), "val[%lu], id=%lu", @@ -958,8 +1104,20 @@ backsql_add( Operation *op, SlapReply *rs ) } if ( BACKSQL_IS_ADD( oc->bom_expect_return ) ) { - SQLBindParameter( sth, 1, SQL_PARAM_OUTPUT, SQL_C_ULONG, - SQL_INTEGER, 0, 0, &new_keyval, 0, 0 ); + rc = backsql_BindParamInt( sth, 1, SQL_PARAM_OUTPUT, &new_keyval ); + if ( rc != SQL_SUCCESS ) { + Debug( LDAP_DEBUG_TRACE, + " backsql_add_attr(): " + "error binding keyval parameter for objectClass %s\n", + oc->bom_oc->soc_cname.bv_val, 0, 0 ); + backsql_PrintErrors( bi->db_env, dbh, + sth, rc ); + SQLFreeStmt( sth, SQL_DROP ); + + rs->sr_text = "SQL-backend error"; + rs->sr_err = LDAP_OTHER; + goto done; + } } Debug( LDAP_DEBUG_TRACE, " backsql_add(\"%s\"): executing \"%s\"\n", @@ -1104,18 +1262,65 @@ backsql_add( Operation *op, SlapReply *rs ) goto done; } - backsql_BindParamStr( sth, 1, realdn.bv_val, BACKSQL_MAX_DN_LEN ); - SQLBindParameter( sth, 2, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, - 0, 0, &oc->bom_id, 0, 0 ); -#ifdef BACKSQL_ARBITRARY_KEY - SQLBindParameter( sth, 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, - 0, 0, parent_id.eid_id.bv_val, 0, 0 ); -#else /* ! BACKSQL_ARBITRARY_KEY */ - SQLBindParameter( sth, 3, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, - 0, 0, &parent_id.eid_id, 0, 0 ); -#endif /* ! BACKSQL_ARBITRARY_KEY */ - SQLBindParameter( sth, 4, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, - 0, 0, &new_keyval, 0, 0 ); + rc = backsql_BindParamBerVal( sth, 1, SQL_PARAM_INPUT, &realdn ); + if ( rc != SQL_SUCCESS ) { + Debug( LDAP_DEBUG_TRACE, + " backsql_add_attr(): " + "error binding DN parameter for objectClass %s\n", + oc->bom_oc->soc_cname.bv_val, 0, 0 ); + backsql_PrintErrors( bi->db_env, dbh, + sth, rc ); + SQLFreeStmt( sth, SQL_DROP ); + + rs->sr_text = "SQL-backend error"; + rs->sr_err = LDAP_OTHER; + goto done; + } + + rc = backsql_BindParamInt( sth, 2, SQL_PARAM_INPUT, &oc->bom_id ); + if ( rc != SQL_SUCCESS ) { + Debug( LDAP_DEBUG_TRACE, + " backsql_add_attr(): " + "error binding objectClass ID parameter for objectClass %s\n", + oc->bom_oc->soc_cname.bv_val, 0, 0 ); + backsql_PrintErrors( bi->db_env, dbh, + sth, rc ); + SQLFreeStmt( sth, SQL_DROP ); + + rs->sr_text = "SQL-backend error"; + rs->sr_err = LDAP_OTHER; + goto done; + } + + rc = backsql_BindParamID( sth, 3, SQL_PARAM_INPUT, &parent_id.eid_id ); + if ( rc != SQL_SUCCESS ) { + Debug( LDAP_DEBUG_TRACE, + " backsql_add_attr(): " + "error binding parent ID parameter for objectClass %s\n", + oc->bom_oc->soc_cname.bv_val, 0, 0 ); + backsql_PrintErrors( bi->db_env, dbh, + sth, rc ); + SQLFreeStmt( sth, SQL_DROP ); + + rs->sr_text = "SQL-backend error"; + rs->sr_err = LDAP_OTHER; + goto done; + } + + rc = backsql_BindParamInt( sth, 4, SQL_PARAM_INPUT, &new_keyval ); + if ( rc != SQL_SUCCESS ) { + Debug( LDAP_DEBUG_TRACE, + " backsql_add_attr(): " + "error binding entry ID parameter for objectClass %s\n", + oc->bom_oc->soc_cname.bv_val, 0, 0 ); + backsql_PrintErrors( bi->db_env, dbh, + sth, rc ); + SQLFreeStmt( sth, SQL_DROP ); + + rs->sr_text = "SQL-backend error"; + rs->sr_err = LDAP_OTHER; + goto done; + } Debug( LDAP_DEBUG_TRACE, " backsql_add(): executing \"%s\" for dn \"%s\"\n", bi->insentry_query, op->oq_add.rs_e->e_name.bv_val, 0 ); diff --git a/servers/slapd/back-sql/delete.c b/servers/slapd/back-sql/delete.c index 31d0ef8c10..29e58c0742 100644 --- a/servers/slapd/back-sql/delete.c +++ b/servers/slapd/back-sql/delete.c @@ -86,6 +86,7 @@ backsql_delete( Operation *op, SlapReply *rs ) SQLHDBC dbh; SQLHSTMT sth; RETCODE rc; + int retval; backsql_oc_map_rec *oc = NULL; backsql_entryID e_id = BACKSQL_ENTRYID_INIT; Entry e; @@ -184,21 +185,39 @@ backsql_delete( Operation *op, SlapReply *rs ) if ( BACKSQL_IS_DEL( oc->bom_expect_return ) ) { pno = 1; - SQLBindParameter( sth, 1, SQL_PARAM_OUTPUT, SQL_C_ULONG, - SQL_INTEGER, 0, 0, &rc, 0, 0 ); + rc = backsql_BindParamInt( sth, 1, SQL_PARAM_OUTPUT, &retval ); + if ( rc != SQL_SUCCESS ) { + Debug( LDAP_DEBUG_TRACE, + " backsql_delete(): " + "error binding output parameter for objectClass %s\n", + oc->bom_oc->soc_cname.bv_val, 0, 0 ); + backsql_PrintErrors( bi->db_env, dbh, + sth, rc ); + SQLFreeStmt( sth, SQL_DROP ); + + rs->sr_text = "SQL-backend error"; + rs->sr_err = LDAP_OTHER; + goto done; + } + } else { pno = 0; } -#ifdef BACKSQL_ARBITRARY_KEY - SQLBindParameter( sth, pno + 1, SQL_PARAM_INPUT, - SQL_C_CHAR, SQL_VARCHAR, 0, 0, e_id.eid_keyval.bv_val, - 0, 0 ); -#else /* ! BACKSQL_ARBITRARY_KEY */ - SQLBindParameter( sth, pno + 1, SQL_PARAM_INPUT, - SQL_C_ULONG, SQL_INTEGER, 0, 0, &e_id.eid_keyval, - 0, 0 ); -#endif /* ! BACKSQL_ARBITRARY_KEY */ + rc = backsql_BindParamID( sth, pno + 1, SQL_PARAM_INPUT, &e_id.eid_keyval ); + if ( rc != SQL_SUCCESS ) { + Debug( LDAP_DEBUG_TRACE, + " backsql_delete(): " + "error binding keyval parameter for objectClass %s\n", + oc->bom_oc->soc_cname.bv_val, 0, 0 ); + backsql_PrintErrors( bi->db_env, dbh, + sth, rc ); + SQLFreeStmt( sth, SQL_DROP ); + + rs->sr_text = "SQL-backend error"; + rs->sr_err = LDAP_OTHER; + goto done; + } rc = SQLExecute( sth ); if ( rc != SQL_SUCCESS ) { @@ -226,13 +245,22 @@ backsql_delete( Operation *op, SlapReply *rs ) goto done; } -#ifdef BACKSQL_ARBITRARY_KEY - SQLBindParameter( sth, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, - 0, 0, e_id.eid_id.bv_val, 0, 0 ); -#else /* ! BACKSQL_ARBITRARY_KEY */ - SQLBindParameter( sth, 1, SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER, - 0, 0, &e_id.eid_id, 0, 0 ); -#endif /* ! BACKSQL_ARBITRARY_KEY */ + rc = backsql_BindParamID( sth, 1, SQL_PARAM_INPUT, &e_id.eid_id ); + if ( rc != SQL_SUCCESS ) { + Debug( LDAP_DEBUG_TRACE, + " backsql_delete(): " + "error binding auxiliary objectClasses " + "entry ID parameter for objectClass %s\n", + oc->bom_oc->soc_cname.bv_val, 0, 0 ); + backsql_PrintErrors( bi->db_env, dbh, + sth, rc ); + SQLFreeStmt( sth, SQL_DROP ); + + rs->sr_text = "SQL-backend error"; + rs->sr_err = LDAP_OTHER; + goto done; + } + rc = SQLExecute( sth ); switch ( rc ) { case SQL_NO_DATA: @@ -267,13 +295,22 @@ backsql_delete( Operation *op, SlapReply *rs ) goto done; } -#ifdef BACKSQL_ARBITRARY_KEY - SQLBindParameter( sth, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, - 0, 0, e_id.eid_id.bv_val, 0, 0 ); -#else /* ! BACKSQL_ARBITRARY_KEY */ - SQLBindParameter( sth, 1, SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER, - 0, 0, &e_id.eid_id, 0, 0 ); -#endif /* ! BACKSQL_ARBITRARY_KEY */ + rc = backsql_BindParamID( sth, 1, SQL_PARAM_INPUT, &e_id.eid_id ); + if ( rc != SQL_SUCCESS ) { + Debug( LDAP_DEBUG_TRACE, + " backsql_delete(): " + "error binding referrals entry ID parameter " + "for objectClass %s\n", + oc->bom_oc->soc_cname.bv_val, 0, 0 ); + backsql_PrintErrors( bi->db_env, dbh, + sth, rc ); + SQLFreeStmt( sth, SQL_DROP ); + + rs->sr_text = "SQL-backend error"; + rs->sr_err = LDAP_OTHER; + goto done; + } + rc = SQLExecute( sth ); switch ( rc ) { case SQL_NO_DATA: @@ -308,13 +345,22 @@ backsql_delete( Operation *op, SlapReply *rs ) goto done; } -#ifdef BACKSQL_ARBITRARY_KEY - SQLBindParameter( sth, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, - 0, 0, e_id.eid_id.bv_val, 0, 0 ); -#else /* ! BACKSQL_ARBITRARY_KEY */ - SQLBindParameter( sth, 1, SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER, - 0, 0, &e_id.eid_id, 0, 0 ); -#endif /* ! BACKSQL_ARBITRARY_KEY */ + rc = backsql_BindParamID( sth, 1, SQL_PARAM_INPUT, &e_id.eid_id ); + if ( rc != SQL_SUCCESS ) { + Debug( LDAP_DEBUG_TRACE, + " backsql_delete(): " + "error binding entry ID parameter " + "for objectClass %s\n", + oc->bom_oc->soc_cname.bv_val, 0, 0 ); + backsql_PrintErrors( bi->db_env, dbh, + sth, rc ); + SQLFreeStmt( sth, SQL_DROP ); + + rs->sr_text = "SQL-backend error"; + rs->sr_err = LDAP_OTHER; + goto done; + } + rc = SQLExecute( sth ); if ( rc != SQL_SUCCESS ) { Debug( LDAP_DEBUG_TRACE, " backsql_delete(): " diff --git a/servers/slapd/back-sql/entry-id.c b/servers/slapd/back-sql/entry-id.c index 26c2165379..0b422d223a 100644 --- a/servers/slapd/back-sql/entry-id.c +++ b/servers/slapd/back-sql/entry-id.c @@ -139,7 +139,7 @@ backsql_dn2id( } } - rc = backsql_BindParamStr( sth, 1, toBind.bv_val, BACKSQL_MAX_DN_LEN ); + rc = backsql_BindParamBerVal( sth, 1, SQL_PARAM_INPUT, &toBind ); if ( rc != SQL_SUCCESS) { /* end TimesTen */ Debug( LDAP_DEBUG_TRACE, "backsql_dn2id(): " @@ -229,7 +229,7 @@ backsql_count_children( return LDAP_OTHER; } - rc = backsql_BindParamStr( sth, 1, dn->bv_val, BACKSQL_MAX_DN_LEN ); + rc = backsql_BindParamBerVal( sth, 1, SQL_PARAM_INPUT, dn ); if ( rc != SQL_SUCCESS) { /* end TimesTen */ Debug( LDAP_DEBUG_TRACE, "backsql_count_children(): " @@ -329,12 +329,8 @@ backsql_get_attr_vals( void *v_at, void *v_bsi ) return 1; } -#ifdef BACKSQL_ARBITRARY_KEY - rc = backsql_BindParamStr( sth, 1, bsi->bsi_c_eid->eid_keyval.bv_val, - BACKSQL_MAX_KEY_LEN ); -#else /* ! BACKSQL_ARBITRARY_KEY */ - rc = backsql_BindParamID( sth, 1, &bsi->bsi_c_eid->eid_keyval ); -#endif /* ! BACKSQL_ARBITRARY_KEY */ + rc = backsql_BindParamID( sth, 1, SQL_PARAM_INPUT, + &bsi->bsi_c_eid->eid_keyval ); if ( rc != SQL_SUCCESS ) { Debug( LDAP_DEBUG_TRACE, "backsql_get_attr_values(): " "error binding key value parameter\n", 0, 0, 0 ); diff --git a/servers/slapd/back-sql/modrdn.c b/servers/slapd/back-sql/modrdn.c index 419065ccf6..83fd4ee0c4 100644 --- a/servers/slapd/back-sql/modrdn.c +++ b/servers/slapd/back-sql/modrdn.c @@ -247,13 +247,22 @@ backsql_modrdn( Operation *op, SlapReply *rs ) goto done; } -#ifdef BACKSQL_ARBITRARY_KEY - SQLBindParameter( sth, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, - 0, 0, e_id.eid_id.bv_val, 0, 0 ); -#else /* ! BACKSQL_ARBITRARY_KEY */ - SQLBindParameter( sth, 1, SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER, - 0, 0, &e_id.eid_id, 0, 0 ); -#endif /* ! BACKSQL_ARBITRARY_KEY */ + rc = backsql_BindParamID( sth, 1, SQL_PARAM_INPUT, &e_id.eid_id ); + if ( rc != SQL_SUCCESS ) { + Debug( LDAP_DEBUG_TRACE, + " backsql_delete(): " + "error binding entry ID parameter " + "for objectClass %s\n", + oc->bom_oc->soc_cname.bv_val, 0, 0 ); + backsql_PrintErrors( bi->db_env, dbh, + sth, rc ); + SQLFreeStmt( sth, SQL_DROP ); + + rs->sr_text = "SQL-backend error"; + rs->sr_err = LDAP_OTHER; + goto done; + } + rc = SQLExecute( sth ); if ( rc != SQL_SUCCESS ) { Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): " @@ -285,20 +294,66 @@ backsql_modrdn( Operation *op, SlapReply *rs ) goto done; } - backsql_BindParamStr( sth, 1, new_dn.bv_val, BACKSQL_MAX_DN_LEN ); - SQLBindParameter( sth, 2, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, - 0, 0, &e_id.eid_oc_id, 0, 0 ); -#ifdef BACKSQL_ARBITRARY_KEY - SQLBindParameter( sth, 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, - 0, 0, new_pe_id.eid_id.bv_val, 0, 0 ); - SQLBindParameter( sth, 4, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, - 0, 0, e_id.eid_keyval.bv_val, 0, 0 ); -#else /* ! BACKSQL_ARBITRARY_KEY */ - SQLBindParameter( sth, 3, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, - 0, 0, &new_pe_id.eid_id, 0, 0 ); - SQLBindParameter( sth, 4, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, - 0, 0, &e_id.eid_keyval, 0, 0 ); -#endif /* ! BACKSQL_ARBITRARY_KEY */ + rc = backsql_BindParamBerVal( sth, 1, SQL_PARAM_INPUT, &new_dn ); + if ( rc != SQL_SUCCESS ) { + Debug( LDAP_DEBUG_TRACE, + " backsql_add_attr(): " + "error binding DN parameter for objectClass %s\n", + oc->bom_oc->soc_cname.bv_val, 0, 0 ); + backsql_PrintErrors( bi->db_env, dbh, + sth, rc ); + SQLFreeStmt( sth, SQL_DROP ); + + rs->sr_text = "SQL-backend error"; + rs->sr_err = LDAP_OTHER; + goto done; + } + + rc = backsql_BindParamInt( sth, 2, SQL_PARAM_INPUT, &e_id.eid_oc_id ); + if ( rc != SQL_SUCCESS ) { + Debug( LDAP_DEBUG_TRACE, + " backsql_add_attr(): " + "error binding objectClass ID parameter for objectClass %s\n", + oc->bom_oc->soc_cname.bv_val, 0, 0 ); + backsql_PrintErrors( bi->db_env, dbh, + sth, rc ); + SQLFreeStmt( sth, SQL_DROP ); + + rs->sr_text = "SQL-backend error"; + rs->sr_err = LDAP_OTHER; + goto done; + } + + rc = backsql_BindParamID( sth, 3, SQL_PARAM_INPUT, &new_pe_id.eid_id ); + if ( rc != SQL_SUCCESS ) { + Debug( LDAP_DEBUG_TRACE, + " backsql_add_attr(): " + "error binding parent ID parameter for objectClass %s\n", + oc->bom_oc->soc_cname.bv_val, 0, 0 ); + backsql_PrintErrors( bi->db_env, dbh, + sth, rc ); + SQLFreeStmt( sth, SQL_DROP ); + + rs->sr_text = "SQL-backend error"; + rs->sr_err = LDAP_OTHER; + goto done; + } + + rc = backsql_BindParamID( sth, 4, SQL_PARAM_INPUT, &e_id.eid_keyval ); + if ( rc != SQL_SUCCESS ) { + Debug( LDAP_DEBUG_TRACE, + " backsql_add_attr(): " + "error binding entry ID parameter for objectClass %s\n", + oc->bom_oc->soc_cname.bv_val, 0, 0 ); + backsql_PrintErrors( bi->db_env, dbh, + sth, rc ); + SQLFreeStmt( sth, SQL_DROP ); + + rs->sr_text = "SQL-backend error"; + rs->sr_err = LDAP_OTHER; + goto done; + } + rc = SQLExecute( sth ); if ( rc != SQL_SUCCESS ) { Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): " diff --git a/servers/slapd/back-sql/proto-sql.h b/servers/slapd/back-sql/proto-sql.h index 8e3fbc3e99..c24e206075 100644 --- a/servers/slapd/back-sql/proto-sql.h +++ b/servers/slapd/back-sql/proto-sql.h @@ -160,17 +160,31 @@ void backsql_init_search( backsql_srch_info *bsi, RETCODE backsql_Prepare( SQLHDBC dbh, SQLHSTMT *sth, char* query, int timeout ); -#define backsql_BindParamStr( sth, par_ind, str, maxlen ) \ +#define backsql_BindParamStr( sth, par_ind, io, str, maxlen ) \ SQLBindParameter( (sth), (SQLUSMALLINT)(par_ind), \ - SQL_PARAM_INPUT, \ - SQL_C_CHAR, SQL_VARCHAR, \ + (io), SQL_C_CHAR, SQL_VARCHAR, \ (SQLUINTEGER)(maxlen), 0, (SQLPOINTER)(str), \ (SQLUINTEGER)(maxlen), NULL ) -#define backsql_BindParamID( sth, par_ind, id ) \ +#define backsql_BindParamBerVal( sth, par_ind, io, bv ) \ + SQLBindParameter( (sth), (SQLUSMALLINT)(par_ind), \ + (io), SQL_C_CHAR, SQL_VARCHAR, \ + (SQLUINTEGER)(bv)->bv_len, 0, \ + (SQLPOINTER)(bv)->bv_val, \ + (SQLUINTEGER)(bv)->bv_len, NULL ) + +#define backsql_BindParamInt( sth, par_ind, io, val ) \ SQLBindParameter( (sth), (SQLUSMALLINT)(par_ind), \ - SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER, \ - 0, 0, (SQLPOINTER)(id), 0, (SQLINTEGER*)NULL ) + (io), SQL_C_ULONG, SQL_INTEGER, \ + 0, 0, (SQLPOINTER)(val), 0, (SQLINTEGER*)NULL ) + +#ifdef BACKSQL_ARBITRARY_KEY +#define backsql_BindParamID( sth, par_ind, io, id ) \ + backsql_BindParamBerVal( (sth), (par_ind), (io), (id) ) +#else /* ! BACKSQL_ARBITRARY_KEY */ +#define backsql_BindParamID( sth, par_ind, io, id ) \ + backsql_BindParamInt( (sth), (par_ind), (io), (id) ) +#endif /* ! BACKSQL_ARBITRARY_KEY */ RETCODE backsql_BindRowAsStrings( SQLHSTMT sth, BACKSQL_ROW_NTS *row ); diff --git a/servers/slapd/back-sql/schema-map.c b/servers/slapd/back-sql/schema-map.c index cd539e8316..8b2d8f678f 100644 --- a/servers/slapd/back-sql/schema-map.c +++ b/servers/slapd/back-sql/schema-map.c @@ -633,11 +633,12 @@ backsql_load_schema_map( backsql_info *si, SQLHDBC dbh ) return LDAP_OTHER; } - rc = backsql_BindParamID( sth, 1, &oc_id ); + rc = backsql_BindParamInt( sth, 1, SQL_PARAM_INPUT, &oc_id ); if ( rc != SQL_SUCCESS ) { Debug( LDAP_DEBUG_TRACE, "backsql_load_schema_map(): " "error binding param \"oc_id\" for at_query\n", 0, 0, 0 ); backsql_PrintErrors( si->db_env, dbh, sth, rc ); + SQLFreeStmt( sth, SQL_DROP ); return LDAP_OTHER; } diff --git a/servers/slapd/back-sql/search.c b/servers/slapd/back-sql/search.c index 52d930b0a9..7b1f960e03 100644 --- a/servers/slapd/back-sql/search.c +++ b/servers/slapd/back-sql/search.c @@ -1241,7 +1241,9 @@ backsql_oc_get_candidates( void *v_oc, void *v_bsi ) Debug( LDAP_DEBUG_TRACE, "id: '%ld'\n", bsi->bsi_oc->bom_id, 0, 0 ); - if ( backsql_BindParamID( sth, 1, &bsi->bsi_oc->bom_id ) != SQL_SUCCESS ) { + rc = backsql_BindParamInt( sth, 1, SQL_PARAM_INPUT, + &bsi->bsi_oc->bom_id ); + if ( rc != SQL_SUCCESS ) { Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): " "error binding objectclass id parameter\n", 0, 0, 0 ); bsi->bsi_status = LDAP_OTHER; @@ -1272,8 +1274,8 @@ backsql_oc_get_candidates( void *v_oc, void *v_bsi ) Debug( LDAP_DEBUG_TRACE, "(base)dn: \"%s\"\n", temp_base_dn, 0, 0 ); - rc = backsql_BindParamStr( sth, 2, temp_base_dn, - BACKSQL_MAX_DN_LEN ); + rc = backsql_BindParamStr( sth, 2, SQL_PARAM_INPUT, + temp_base_dn, 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 ); @@ -1331,8 +1333,8 @@ backsql_oc_get_candidates( void *v_oc, void *v_bsi ) 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 ); + rc = backsql_BindParamStr( sth, 2, SQL_PARAM_INPUT, + temp_base_dn, BACKSQL_MAX_DN_LEN ); if ( rc != SQL_SUCCESS ) { Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): " "error binding base_dn parameter (2)\n", @@ -1360,15 +1362,12 @@ backsql_oc_get_candidates( void *v_oc, void *v_bsi ) #ifdef BACKSQL_ARBITRARY_KEY Debug( LDAP_DEBUG_TRACE, "(one)id: \"%s\"\n", base_id.eid_id.bv_val, 0, 0 ); - - rc = backsql_BindParamStr( sth, 2, base_id.eid_id.bv_val, - BACKSQL_MAX_KEY_LEN ); #else /* ! BACKSQL_ARBITRARY_KEY */ Debug( LDAP_DEBUG_TRACE, "(one)id: '%lu'\n", base_id.eid_id, 0, 0 ); - - rc = backsql_BindParamID( sth, 2, &base_id.eid_id ); #endif /* ! BACKSQL_ARBITRARY_KEY */ + rc = backsql_BindParamID( sth, 2, SQL_PARAM_INPUT, + &base_id.eid_id ); backsql_free_entryID( &base_id, 0 ); if ( rc != SQL_SUCCESS ) { Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): "