From: Pierangelo Masarati Date: Tue, 18 Jan 2005 01:10:01 +0000 (+0000) Subject: fix different issues with referrals in searches; remove unused tests; cleanup referra... X-Git-Tag: OPENLDAP_REL_ENG_2_3_BP~356 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=8b26737c272461f971eb712452040c05d303bed5;p=openldap fix different issues with referrals in searches; remove unused tests; cleanup referrals in tests so that they don't get chased; improve schema checking in modrdn and updates in general; minor cleanup --- diff --git a/servers/slapd/back-sql/add.c b/servers/slapd/back-sql/add.c index f752b1320b..1e46866dd8 100644 --- a/servers/slapd/back-sql/add.c +++ b/servers/slapd/back-sql/add.c @@ -408,7 +408,7 @@ backsql_modify_internal( goto add_only; } - + del_all: rs->sr_err = backsql_modify_delete_all_values( op, rs, dbh, e_id, at ); if ( rs->sr_err != LDAP_SUCCESS ) { diff --git a/servers/slapd/back-sql/back-sql.h b/servers/slapd/back-sql/back-sql.h index 6c79a7b0c4..6943160b09 100644 --- a/servers/slapd/back-sql/back-sql.h +++ b/servers/slapd/back-sql/back-sql.h @@ -198,6 +198,11 @@ typedef struct { */ #undef BACKSQL_TRACE +/* + * define if using MS SQL and workaround needed (see sql-wrap.c) + */ +#undef BACKSQL_MSSQL_WORKAROUND + /* * define to enable values counting for attributes */ diff --git a/servers/slapd/back-sql/modify.c b/servers/slapd/back-sql/modify.c index b4de864199..07d1135a2c 100644 --- a/servers/slapd/back-sql/modify.c +++ b/servers/slapd/back-sql/modify.c @@ -150,8 +150,7 @@ backsql_modify( Operation *op, SlapReply *rs ) } rs->sr_err = backsql_modify_internal( op, rs, dbh, oc, - &bsi.bsi_base_id, - op->oq_modify.rs_modlist ); + &bsi.bsi_base_id, op->oq_modify.rs_modlist ); if ( rs->sr_err != LDAP_SUCCESS ) { e = &m; goto do_transact; diff --git a/servers/slapd/back-sql/modrdn.c b/servers/slapd/back-sql/modrdn.c index d5aa697f8c..d9b2d4d922 100644 --- a/servers/slapd/back-sql/modrdn.c +++ b/servers/slapd/back-sql/modrdn.c @@ -450,14 +450,52 @@ backsql_modrdn( Operation *op, SlapReply *rs ) char textbuf[ SLAP_TEXT_BUFLEN ] = { '\0' }; entry_clean( &r ); + (void)backsql_free_entryID( op, &e_id, 0 ); bsi.bsi_e = &r; - rs->sr_err = backsql_id2entry( &bsi, &e_id ); - if ( rs->sr_err != LDAP_SUCCESS ) { + rs->sr_err = backsql_init_search( &bsi, &new_ndn, + LDAP_SCOPE_BASE, + SLAP_NO_LIMIT, SLAP_NO_LIMIT, + (time_t)(-1), NULL, dbh, op, rs, + slap_anlist_all_attributes, + ( BACKSQL_ISF_MATCHED | BACKSQL_ISF_GET_ENTRY ) ); + switch ( rs->sr_err ) { + case LDAP_SUCCESS: + break; + + case LDAP_REFERRAL: + if ( !BER_BVISNULL( &bsi.bsi_e->e_nname ) && + dn_match( &new_ndn, &bsi.bsi_e->e_nname ) + && manageDSAit ) + { + rs->sr_err = LDAP_SUCCESS; + rs->sr_text = NULL; + rs->sr_matched = NULL; + if ( rs->sr_ref ) { + ber_bvarray_free( rs->sr_ref ); + rs->sr_ref = NULL; + } + break; + } e = &r; + /* fallthru */ + + default: + Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): " + "could not retrieve modrdnDN ID - no such entry\n", + 0, 0, 0 ); + if ( !BER_BVISNULL( &r.e_nname ) ) { + /* FIXME: should always be true! */ + e = &r; + + } else { + e = NULL; + } goto done; } + e_id = bsi.bsi_base_id; + rs->sr_err = entry_schema_check( op->o_bd, &r, NULL, &rs->sr_text, textbuf, sizeof( textbuf ) ); diff --git a/servers/slapd/back-sql/rdbms_depend/ibmdb2/testdb_metadata.sql b/servers/slapd/back-sql/rdbms_depend/ibmdb2/testdb_metadata.sql index 33c509a13b..0158c894c2 100644 --- a/servers/slapd/back-sql/rdbms_depend/ibmdb2/testdb_metadata.sql +++ b/servers/slapd/back-sql/rdbms_depend/ibmdb2/testdb_metadata.sql @@ -112,5 +112,5 @@ insert into ldap_entry_objclasses (entry_id,oc_name) values (4,'referral'); -- referrals mapping: entries that should be treated as referrals are stored here -- entry_id the "ldap_entries.id" of the entry that should be treated as a referral -- url the URI of the referral -insert into ldap_referrals (entry_id,url) values (4,'ldap://localhost/'); +insert into ldap_referrals (entry_id,url) values (4,'ldap://localhost:9010/'); diff --git a/servers/slapd/back-sql/rdbms_depend/mssql/testdb_metadata.sql b/servers/slapd/back-sql/rdbms_depend/mssql/testdb_metadata.sql index 91d808d2dc..9a9582d177 100644 --- a/servers/slapd/back-sql/rdbms_depend/mssql/testdb_metadata.sql +++ b/servers/slapd/back-sql/rdbms_depend/mssql/testdb_metadata.sql @@ -99,7 +99,7 @@ insert into ldap_entry_objclasses (entry_id,oc_name) values (4,'referral'); insert into ldap_referrals (entry_id,url) -values (4,'http://localhost/'); +values (4,'ldap://localhost:9010/'); -- support procedures diff --git a/servers/slapd/back-sql/rdbms_depend/mysql/testdb_metadata.sql b/servers/slapd/back-sql/rdbms_depend/mysql/testdb_metadata.sql index 8933a4c878..6f81c99bee 100644 --- a/servers/slapd/back-sql/rdbms_depend/mysql/testdb_metadata.sql +++ b/servers/slapd/back-sql/rdbms_depend/mysql/testdb_metadata.sql @@ -109,5 +109,5 @@ values (4,'referral'); -- entry_id the "ldap_entries.id" of the entry that should be treated as a referral -- url the URI of the referral insert into ldap_referrals (entry_id,url) -values (4,'ldap://localhost/'); +values (4,'ldap://localhost:9010/'); diff --git a/servers/slapd/back-sql/rdbms_depend/oracle/testdb_metadata.sql b/servers/slapd/back-sql/rdbms_depend/oracle/testdb_metadata.sql index d0c3186f49..f6c8d14acc 100644 --- a/servers/slapd/back-sql/rdbms_depend/oracle/testdb_metadata.sql +++ b/servers/slapd/back-sql/rdbms_depend/oracle/testdb_metadata.sql @@ -115,7 +115,7 @@ values (4,'referral'); -- entry_id the "ldap_entries.id" of the entry that should be treated as a referral -- url the URI of the referral insert into ldap_referrals (entry_id,url) -values (4,'http://localhost/'); +values (4,'ldap://localhost:9010/'); -- procedures diff --git a/servers/slapd/back-sql/rdbms_depend/pgsql/testdb_metadata.sql b/servers/slapd/back-sql/rdbms_depend/pgsql/testdb_metadata.sql index 75ade75e50..e841eb9d09 100644 --- a/servers/slapd/back-sql/rdbms_depend/pgsql/testdb_metadata.sql +++ b/servers/slapd/back-sql/rdbms_depend/pgsql/testdb_metadata.sql @@ -79,7 +79,7 @@ insert into ldap_entry_objclasses (entry_id,oc_name) values (4,'referral'); -- referrals mapping: entries that should be treated as referrals are stored here -- entry_id the "ldap_entries.id" of the entry that should be treated as a referral -- url the URI of the referral -insert into ldap_referrals (entry_id,url) values (4,'ldap://localhost/'); +insert into ldap_referrals (entry_id,url) values (4,'ldap://localhost:9010/'); -- procedures -- these procedures are specific for this RDBMS and are used in mapping objectClass and attributeType creation/modify/deletion diff --git a/servers/slapd/back-sql/rdbms_depend/timesten/testdb_metadata.sql b/servers/slapd/back-sql/rdbms_depend/timesten/testdb_metadata.sql index 098eea23b0..40e8001a8c 100644 --- a/servers/slapd/back-sql/rdbms_depend/timesten/testdb_metadata.sql +++ b/servers/slapd/back-sql/rdbms_depend/timesten/testdb_metadata.sql @@ -105,4 +105,4 @@ insert into ldap_entry_objclasses (entry_id,oc_name) values (4,'referral'); insert into ldap_referrals (entry_id,url) -values (4,'http://localhost'); +values (4,'ldap://localhost:9010'); diff --git a/servers/slapd/back-sql/search.c b/servers/slapd/back-sql/search.c index 9440a920c4..9ec5ab3176 100644 --- a/servers/slapd/back-sql/search.c +++ b/servers/slapd/back-sql/search.c @@ -740,11 +740,11 @@ backsql_process_filter( backsql_srch_info *bsi, Filter *f ) backsql_merge_from_tbls( bsi, &ldap_entry_objclasses ); backsql_strfcat( &bsi->bsi_flt_where, "lbl", - (ber_len_t)STRLENOF( "2=2 OR (ldap_entries.id=ldap_entry_objclasses.entry_id AND ldap_entry_objclasses.oc_name='" /* ') */ ), - "2=2 OR (ldap_entries.id=ldap_entry_objclasses.entry_id AND ldap_entry_objclasses.oc_name='" /* ') */, + (ber_len_t)STRLENOF( "(2=2 OR (ldap_entries.id=ldap_entry_objclasses.entry_id AND ldap_entry_objclasses.oc_name='" /* ')) */ ), + "(2=2 OR (ldap_entries.id=ldap_entry_objclasses.entry_id AND ldap_entry_objclasses.oc_name='" /* ')) */, &bsi->bsi_oc->bom_oc->soc_cname, - (ber_len_t)STRLENOF( /* (' */ "')" ), - /* (' */ "')" ); + (ber_len_t)STRLENOF( /* ((' */ "'))" ), + /* ((' */ "'))" ); bsi->bsi_status = LDAP_SUCCESS; rc = 1; goto done; @@ -1787,14 +1787,11 @@ backsql_search( Operation *op, SlapReply *rs ) int sres; Entry user_entry = { 0 }, base_entry = { 0 }; - int manageDSAit; + int manageDSAit = get_manageDSAit( op ); time_t stoptime = 0; backsql_srch_info bsi = { 0 }; backsql_entryID *eid = NULL; - struct berval nbase = BER_BVNULL, - realndn = BER_BVNULL; - - manageDSAit = get_manageDSAit( op ); + struct berval nbase = BER_BVNULL; Debug( LDAP_DEBUG_TRACE, "==>backsql_search(): " "base=\"%s\", filter=\"%s\", scope=%d,", @@ -1835,26 +1832,35 @@ backsql_search( Operation *op, SlapReply *rs ) /* compute it anyway; root does not use it */ stoptime = op->o_time + op->ors_tlimit; - realndn = op->o_req_ndn; - if ( backsql_api_dn2odbc( op, rs, &realndn ) ) { - Debug( LDAP_DEBUG_TRACE, " backsql_search(\"%s\"): " - "backsql_api_dn2odbc(\"%s\") failed\n", - op->o_req_ndn.bv_val, realndn.bv_val, 0 ); - rs->sr_err = LDAP_OTHER; - rs->sr_text = "SQL-backend error"; - send_ldap_result( op, rs ); - goto done; - } - /* init search */ bsi.bsi_e = &base_entry; - rs->sr_err = backsql_init_search( &bsi, &realndn, + rs->sr_err = backsql_init_search( &bsi, &op->o_req_ndn, op->ors_scope, op->ors_slimit, op->ors_tlimit, stoptime, op->ors_filter, dbh, op, rs, op->ors_attrs, ( BACKSQL_ISF_MATCHED | BACKSQL_ISF_GET_ENTRY ) ); - if ( rs->sr_err != LDAP_SUCCESS ) { + switch ( rs->sr_err ) { + case LDAP_SUCCESS: + break; + + case LDAP_REFERRAL: + if ( !BER_BVISNULL( &bsi.bsi_e->e_nname ) && + dn_match( &op->o_req_ndn, &bsi.bsi_e->e_nname ) + && manageDSAit ) + { + rs->sr_err = LDAP_SUCCESS; + rs->sr_text = NULL; + rs->sr_matched = NULL; + if ( rs->sr_ref ) { + ber_bvarray_free( rs->sr_ref ); + rs->sr_ref = NULL; + } + break; + } + /* fall thru */ + + default: #ifdef SLAP_ACL_HONOR_DISCLOSE if ( !BER_BVISNULL( &base_entry.e_nname ) && ! access_allowed( op, &base_entry, @@ -1864,11 +1870,13 @@ backsql_search( Operation *op, SlapReply *rs ) rs->sr_err = LDAP_NO_SUCH_OBJECT; if ( rs->sr_ref ) { ber_bvarray_free( rs->sr_ref ); + rs->sr_ref = NULL; } rs->sr_matched = NULL; rs->sr_text = NULL; } #endif /* SLAP_ACL_HONOR_DISCLOSE */ + send_ldap_result( op, rs ); goto done; @@ -1876,7 +1884,7 @@ backsql_search( Operation *op, SlapReply *rs ) #ifdef SLAP_ACL_HONOR_DISCLOSE /* NOTE: __NEW__ "search" access is required * on searchBase object */ - else { + { slap_mask_t mask; if ( get_assert( op ) && @@ -2266,10 +2274,6 @@ end_of_search:; #endif /* BACKSQL_SYNCPROV */ done:; - if ( !BER_BVISNULL( &realndn ) && realndn.bv_val != op->o_req_ndn.bv_val ) { - ch_free( realndn.bv_val ); - } - (void)backsql_free_entryID( op, &bsi.bsi_base_id, 0 ); if ( bsi.bsi_attrs != NULL ) { diff --git a/servers/slapd/back-sql/sql-wrap.c b/servers/slapd/back-sql/sql-wrap.c index c691952c21..13d715395f 100644 --- a/servers/slapd/back-sql/sql-wrap.c +++ b/servers/slapd/back-sql/sql-wrap.c @@ -61,8 +61,6 @@ RETCODE backsql_Prepare( SQLHDBC dbh, SQLHSTMT *sth, char *query, int timeout ) { RETCODE rc; - char drv_name[ 30 ]; - SWORD len; rc = SQLAllocStmt( dbh, sth ); if ( rc != SQL_SUCCESS ) { @@ -73,36 +71,43 @@ backsql_Prepare( SQLHDBC dbh, SQLHSTMT *sth, char *query, int timeout ) Debug( LDAP_DEBUG_TRACE, "==>backsql_Prepare()\n", 0, 0, 0 ); #endif /* BACKSQL_TRACE */ - SQLGetInfo( dbh, SQL_DRIVER_NAME, drv_name, sizeof( drv_name ), &len ); +#ifdef BACKSQL_MSSQL_WORKAROUND + { + char drv_name[ 30 ]; + SWORD len; + + SQLGetInfo( dbh, SQL_DRIVER_NAME, drv_name, sizeof( drv_name ), &len ); #ifdef BACKSQL_TRACE - Debug( LDAP_DEBUG_TRACE, "backsql_Prepare(): driver name=\"%s\"\n", - drv_name, 0, 0 ); + Debug( LDAP_DEBUG_TRACE, "backsql_Prepare(): driver name=\"%s\"\n", + drv_name, 0, 0 ); #endif /* BACKSQL_TRACE */ - ldap_pvt_str2upper( drv_name ); - if ( !strncmp( drv_name, "SQLSRV32.DLL", sizeof( drv_name ) ) ) { - /* - * stupid default result set in MS SQL Server - * does not support multiple active statements - * on the same connection -- so we are trying - * to make it not to use default result set... - */ - Debug( LDAP_DEBUG_TRACE, "_SQLprepare(): " - "enabling MS SQL Server default result " - "set workaround\n", 0, 0, 0 ); - rc = SQLSetStmtOption( *sth, SQL_CONCURRENCY, - SQL_CONCUR_ROWVER ); - if ( rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO ) { - Debug( LDAP_DEBUG_TRACE, "backsql_Prepare(): " - "SQLSetStmtOption(SQL_CONCURRENCY," - "SQL_CONCUR_ROWVER) failed:\n", - 0, 0, 0 ); - backsql_PrintErrors( SQL_NULL_HENV, dbh, *sth, rc ); - SQLFreeStmt( *sth, SQL_DROP ); - return rc; + ldap_pvt_str2upper( drv_name ); + if ( !strncmp( drv_name, "SQLSRV32.DLL", STRLENOF( "SQLSRV32.DLL" ) ) ) { + /* + * stupid default result set in MS SQL Server + * does not support multiple active statements + * on the same connection -- so we are trying + * to make it not to use default result set... + */ + Debug( LDAP_DEBUG_TRACE, "_SQLprepare(): " + "enabling MS SQL Server default result " + "set workaround\n", 0, 0, 0 ); + rc = SQLSetStmtOption( *sth, SQL_CONCURRENCY, + SQL_CONCUR_ROWVER ); + if ( rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO ) { + Debug( LDAP_DEBUG_TRACE, "backsql_Prepare(): " + "SQLSetStmtOption(SQL_CONCURRENCY," + "SQL_CONCUR_ROWVER) failed:\n", + 0, 0, 0 ); + backsql_PrintErrors( SQL_NULL_HENV, dbh, *sth, rc ); + SQLFreeStmt( *sth, SQL_DROP ); + return rc; + } } } +#endif /* BACKSQL_MSSQL_WORKAROUND */ if ( timeout > 0 ) { Debug( LDAP_DEBUG_TRACE, "_SQLprepare(): "