]> git.sur5r.net Git - openldap/commitdiff
fix different issues with referrals in searches; remove unused tests; cleanup referra...
authorPierangelo Masarati <ando@openldap.org>
Tue, 18 Jan 2005 01:10:01 +0000 (01:10 +0000)
committerPierangelo Masarati <ando@openldap.org>
Tue, 18 Jan 2005 01:10:01 +0000 (01:10 +0000)
12 files changed:
servers/slapd/back-sql/add.c
servers/slapd/back-sql/back-sql.h
servers/slapd/back-sql/modify.c
servers/slapd/back-sql/modrdn.c
servers/slapd/back-sql/rdbms_depend/ibmdb2/testdb_metadata.sql
servers/slapd/back-sql/rdbms_depend/mssql/testdb_metadata.sql
servers/slapd/back-sql/rdbms_depend/mysql/testdb_metadata.sql
servers/slapd/back-sql/rdbms_depend/oracle/testdb_metadata.sql
servers/slapd/back-sql/rdbms_depend/pgsql/testdb_metadata.sql
servers/slapd/back-sql/rdbms_depend/timesten/testdb_metadata.sql
servers/slapd/back-sql/search.c
servers/slapd/back-sql/sql-wrap.c

index f752b1320b78da967164a6d3cad0f8e8fca71b38..1e46866dd826daaa56582f299cb6f33e0e7ba12d 100644 (file)
@@ -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 ) {
index 6c79a7b0c4d2406bf38ff9163fe31641dee55794..6943160b09c840d5e1207709420a79ba3ee89024 100644 (file)
@@ -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
  */
index b4de8641990fdde3e3eaf4d1e460e7b2cc959c54..07d1135a2cd2030abf819617af325692dddc6e54 100644 (file)
@@ -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;
index d5aa697f8ce4ebef38d806b4132f9b052cebde57..d9b2d4d922184cf719f118ad9c1a559e194b2da0 100644 (file)
@@ -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 ) );
index 33c509a13b1bbbbd35c9370071532560f9231b6a..0158c894c2e8d6dc469c6cb87da2af08a92b3bb5 100644 (file)
@@ -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/');
 
index 91d808d2dcb3d2ec6dabe190ed361bd7e4ef4caf..9a9582d1777c20a59df680dca2facf0068b4e209 100644 (file)
@@ -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
 
index 8933a4c87803f4f47f28cab8908ee6c5f30ae986..6f81c99bee18a5261510bc3647d32a5a0b22b82f 100644 (file)
@@ -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/');
 
index d0c3186f49dd31a96d4a58af972f98864295c0dd..f6c8d14acc92747e9b388053fbb9a8c64786cd0d 100644 (file)
@@ -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
index 75ade75e504f4d265e6cb117eb079b0785e82f9f..e841eb9d0959dbffd213a917feb27b990e32be2b 100644 (file)
@@ -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
index 098eea23b043e8c7fd4e21c8500e73b8562523f0..40e8001a8c611cea962805a75c42c4ac9d5fb555 100644 (file)
@@ -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');
index 9440a920c45c307c826e65961a57effaa10ee107..9ec5ab3176ae79beef7d9277bf62612475d09288 100644 (file)
@@ -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 ) {
index c691952c2143eb41a6db889a5a334824b5ee9f43..13d715395ffc1b2f510270b1d3d9eef695fb1cee 100644 (file)
@@ -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(): "