Commit 396743f6 authored by Pierangelo Masarati's avatar Pierangelo Masarati
Browse files

fix DN munging; also fix potential error when logging incomplete deletes

parent 98485f52
......@@ -60,11 +60,28 @@ backsql_modify_delete_all_values(
SQLHSTMT asth;
BACKSQL_ROW_NTS row;
assert( at );
if ( at->bam_delete_proc == NULL ) {
Debug( LDAP_DEBUG_TRACE,
" backsql_modify_delete_all_values(): "
"missing attribute value delete procedure "
"for attr \"%s\"\n",
at->bam_ad->ad_cname.bv_val, 0, 0 );
if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
rs->sr_text = "SQL-backend error";
return rs->sr_err = LDAP_OTHER;
}
return LDAP_SUCCESS;
}
rc = backsql_Prepare( dbh, &asth, at->bam_query, 0 );
if ( rc != SQL_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE,
" backsql_modify_delete_all_values(): "
"error preparing query\n", 0, 0, 0 );
"error preparing attribute value select query "
"\"%s\"\n",
at->bam_query, 0, 0 );
backsql_PrintErrors( bi->sql_db_env, dbh,
asth, rc );
......@@ -79,7 +96,8 @@ backsql_modify_delete_all_values(
if ( rc != SQL_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE,
" backsql_modify_delete_all_values(): "
"error binding key value parameter\n",
"error binding key value parameter "
"to attribute value select query\n",
0, 0, 0 );
backsql_PrintErrors( bi->sql_db_env, dbh,
asth, rc );
......@@ -97,7 +115,7 @@ backsql_modify_delete_all_values(
if ( !BACKSQL_SUCCESS( rc ) ) {
Debug( LDAP_DEBUG_TRACE,
" backsql_modify_delete_all_values(): "
"error executing attribute query\n",
"error executing attribute value select query\n",
0, 0, 0 );
backsql_PrintErrors( bi->sql_db_env, dbh,
asth, rc );
......@@ -130,7 +148,9 @@ backsql_modify_delete_all_values(
if ( rc != SQL_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE,
" backsql_modify_delete_all_values(): "
"error preparing query %s\n",
"error preparing attribute value "
"delete procedure "
"\"%s\"\n",
at->bam_delete_proc, 0, 0 );
backsql_PrintErrors( bi->sql_db_env, dbh,
sth, rc );
......@@ -1008,7 +1028,7 @@ backsql_add( Operation *op, SlapReply *rs )
goto done;
}
rs->sr_err = backsql_dn2id( bi, NULL, dbh, &realndn );
rs->sr_err = backsql_dn2id( op, rs, NULL, dbh, &realndn );
if ( rs->sr_err == LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, " backsql_add(\"%s\"): "
"entry exists\n",
......@@ -1037,7 +1057,7 @@ backsql_add( Operation *op, SlapReply *rs )
goto done;
}
rs->sr_err = backsql_dn2id( bi, &parent_id, dbh, &realpdn );
rs->sr_err = backsql_dn2id( op, rs, &parent_id, dbh, &realpdn );
if ( rs->sr_err != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, " backsql_add(\"%s\"): "
"could not lookup parent entry for new record \"%s\"\n",
......@@ -1086,7 +1106,7 @@ backsql_add( Operation *op, SlapReply *rs )
goto done;
}
rs->sr_err = backsql_dn2id( bi, NULL, dbh, &realpdn );
rs->sr_err = backsql_dn2id( op, rs, NULL, dbh, &realpdn );
switch ( rs->sr_err ) {
case LDAP_NO_SUCH_OBJECT:
if ( !BER_BVISEMPTY( &pdn ) ) {
......
......@@ -66,7 +66,7 @@ backsql_api_register( backsql_api *ba )
for ( ba2 = backsqlapi; ba2; ba2 = ba2->ba_next ) {
if ( strcasecmp( ba->ba_name, ba2->ba_name ) == 0 ) {
fprintf( stderr, "API module \"%s\" already defined\n", ba->ba_name );
exit(EXIT_FAILURE);
exit( EXIT_FAILURE );
}
}
......
......@@ -119,7 +119,7 @@ backsql_delete( Operation *op, SlapReply *rs )
}
/* FIXME: API... */
rs->sr_err = backsql_dn2id( bi, &e_id, dbh, &op->o_req_ndn );
rs->sr_err = backsql_dn2id( op, rs, &e_id, dbh, &op->o_req_ndn );
if ( rs->sr_err != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, " backsql_delete(): "
"could not lookup entry id\n", 0, 0, 0 );
......
......@@ -76,11 +76,13 @@ backsql_free_entryID( backsql_entryID *id, int freeit )
*/
int
backsql_dn2id(
backsql_info *bi,
Operation *op,
SlapReply *rs,
backsql_entryID *id,
SQLHDBC dbh,
struct berval *ndn )
{
backsql_info *bi = op->o_bd->be_private;
SQLHSTMT sth;
BACKSQL_ROW_NTS row;
RETCODE rc;
......@@ -223,16 +225,25 @@ backsql_dn2id(
ber_str2bv( row.cols[ 3 ], 0, 0, &dn );
res = dnPrettyNormal( NULL, &dn, &id->eid_dn, &id->eid_ndn, NULL );
if ( res != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE,
"<==backsql_dn2id(\"%s\"): "
"dnPrettyNormal failed (%d: %s)\n",
ndn->bv_val, res,
ldap_err2string( res ) );
if ( backsql_api_odbc2dn( op, rs, &dn ) ) {
res = LDAP_OTHER;
/* cleanup... */
(void)backsql_free_entryID( id, 0 );
} else {
res = dnPrettyNormal( NULL, &dn, &id->eid_dn, &id->eid_ndn, NULL );
if ( res != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE,
"<==backsql_dn2id(\"%s\"): "
"dnPrettyNormal failed (%d: %s)\n",
ndn->bv_val, res,
ldap_err2string( res ) );
/* cleanup... */
(void)backsql_free_entryID( id, 0 );
}
if ( dn.bv_val != row.cols[ 3 ] ) {
free( dn.bv_val );
}
}
id->eid_next = NULL;
......
......@@ -60,7 +60,7 @@ backsql_modify( Operation *op, SlapReply *rs )
}
/* FIXME: API... */
rs->sr_err = backsql_dn2id( bi, &e_id, dbh, &op->o_req_ndn );
rs->sr_err = backsql_dn2id( op, rs, &e_id, dbh, &op->o_req_ndn );
if ( rs->sr_err != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, " backsql_modify(): "
"could not lookup entry id\n", 0, 0, 0 );
......
......@@ -64,7 +64,7 @@ backsql_modrdn( Operation *op, SlapReply *rs )
}
/* FIXME: API... */
rs->sr_err = backsql_dn2id( bi, &e_id, dbh, &op->o_req_ndn );
rs->sr_err = backsql_dn2id( op, rs, &e_id, dbh, &op->o_req_ndn );
if ( rs->sr_err != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): "
"could not lookup entry id (%d)\n",
......@@ -191,7 +191,7 @@ backsql_modrdn( Operation *op, SlapReply *rs )
new_dn.bv_val, 0, 0 );
/* FIXME: API... */
rs->sr_err = backsql_dn2id( bi, &pe_id, dbh, &p_ndn );
rs->sr_err = backsql_dn2id( op, rs, &pe_id, dbh, &p_ndn );
if ( rs->sr_err != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): "
"could not lookup old parent entry id\n", 0, 0, 0 );
......@@ -212,7 +212,7 @@ backsql_modrdn( Operation *op, SlapReply *rs )
(void)backsql_free_entryID( &pe_id, 0 );
/* FIXME: API... */
rs->sr_err = backsql_dn2id( bi, &new_pe_id, dbh, new_npdn );
rs->sr_err = backsql_dn2id( op, rs, &new_pe_id, dbh, new_npdn );
if ( rs->sr_err != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): "
"could not lookup new parent entry id\n", 0, 0, 0 );
......
......@@ -110,7 +110,7 @@ extern struct berval backsql_baseObject_bv;
#endif /* BACKSQL_ARBITRARY_KEY */
/* stores in *id the ID in table ldap_entries corresponding to DN, if any */
int backsql_dn2id( backsql_info *bi, backsql_entryID *id,
int backsql_dn2id( Operation *op, SlapReply *rs, backsql_entryID *id,
SQLHDBC dbh, struct berval *dn );
/* stores in *nchildren the count of children for an entry */
......
......@@ -874,7 +874,7 @@ backsql_free_attr( void *v_at )
if ( at->bam_delete_proc != NULL ) {
ch_free( at->bam_delete_proc );
}
if ( at->bam_query ) {
if ( at->bam_query != NULL ) {
ch_free( at->bam_query );
}
......
......@@ -54,6 +54,7 @@ backsql_attrlist_add( backsql_srch_info *bsi, AttributeDescription *ad )
if ( ad == NULL ) {
ch_free( bsi->bsi_attrs );
bsi->bsi_attrs = NULL;
bsi->bsi_flags |= BSQL_SF_ALL_ATTRS;
return 1;
}
......@@ -193,8 +194,7 @@ backsql_init_search(
if ( get_base_id ) {
assert( op->o_bd->be_private );
rc = backsql_dn2id( (backsql_info *)op->o_bd->be_private,
&bsi->bsi_base_id, dbh, nbase );
rc = backsql_dn2id( op, rs, &bsi->bsi_base_id, dbh, nbase );
}
return ( bsi->bsi_status = rc );
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment