Commit 8b26737c authored by Pierangelo Masarati's avatar Pierangelo Masarati
Browse files

fix different issues with referrals in searches; remove unused tests; cleanup...

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
parent 73bf4506
......@@ -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 ) {
......
......@@ -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
*/
......
......@@ -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;
......
......@@ -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 ) );
......
......@@ -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/');
......@@ -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
......
......@@ -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/');
......@@ -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
......
......@@ -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
......
......@@ -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');
......@@ -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 ) {
......
......@@ -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(): "
......
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