From 396743f62f451f1d55df9d91ebbdaf21f075ec2c Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Wed, 1 Dec 2004 23:16:21 +0000 Subject: [PATCH] fix DN munging; also fix potential error when logging incomplete deletes --- servers/slapd/back-sql/add.c | 34 +++++++++++++++++++++++------ servers/slapd/back-sql/api.c | 2 +- servers/slapd/back-sql/delete.c | 2 +- servers/slapd/back-sql/entry-id.c | 31 +++++++++++++++++--------- servers/slapd/back-sql/modify.c | 2 +- servers/slapd/back-sql/modrdn.c | 6 ++--- servers/slapd/back-sql/proto-sql.h | 2 +- servers/slapd/back-sql/schema-map.c | 2 +- servers/slapd/back-sql/search.c | 4 ++-- 9 files changed, 58 insertions(+), 27 deletions(-) diff --git a/servers/slapd/back-sql/add.c b/servers/slapd/back-sql/add.c index 02da983562..8c6bfa7d14 100644 --- a/servers/slapd/back-sql/add.c +++ b/servers/slapd/back-sql/add.c @@ -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 ) ) { diff --git a/servers/slapd/back-sql/api.c b/servers/slapd/back-sql/api.c index 5eb71b8d67..1a1c32ab93 100644 --- a/servers/slapd/back-sql/api.c +++ b/servers/slapd/back-sql/api.c @@ -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 ); } } diff --git a/servers/slapd/back-sql/delete.c b/servers/slapd/back-sql/delete.c index fbe4f1a869..9de1d0af05 100644 --- a/servers/slapd/back-sql/delete.c +++ b/servers/slapd/back-sql/delete.c @@ -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 ); diff --git a/servers/slapd/back-sql/entry-id.c b/servers/slapd/back-sql/entry-id.c index d75bfe0dda..8a0052027d 100644 --- a/servers/slapd/back-sql/entry-id.c +++ b/servers/slapd/back-sql/entry-id.c @@ -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; diff --git a/servers/slapd/back-sql/modify.c b/servers/slapd/back-sql/modify.c index c73ba2431c..5ac3986641 100644 --- a/servers/slapd/back-sql/modify.c +++ b/servers/slapd/back-sql/modify.c @@ -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 ); diff --git a/servers/slapd/back-sql/modrdn.c b/servers/slapd/back-sql/modrdn.c index 6e01e5aa2e..8df88271d8 100644 --- a/servers/slapd/back-sql/modrdn.c +++ b/servers/slapd/back-sql/modrdn.c @@ -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 ); diff --git a/servers/slapd/back-sql/proto-sql.h b/servers/slapd/back-sql/proto-sql.h index d438c7dda4..eb54d0af3c 100644 --- a/servers/slapd/back-sql/proto-sql.h +++ b/servers/slapd/back-sql/proto-sql.h @@ -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 */ diff --git a/servers/slapd/back-sql/schema-map.c b/servers/slapd/back-sql/schema-map.c index 7c115bd224..9022c451dc 100644 --- a/servers/slapd/back-sql/schema-map.c +++ b/servers/slapd/back-sql/schema-map.c @@ -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 ); } diff --git a/servers/slapd/back-sql/search.c b/servers/slapd/back-sql/search.c index 3fbe8cd13d..393068f189 100644 --- a/servers/slapd/back-sql/search.c +++ b/servers/slapd/back-sql/search.c @@ -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 ); -- 2.39.5