]> git.sur5r.net Git - openldap/commitdiff
more on DN munging; now works for all operations
authorPierangelo Masarati <ando@openldap.org>
Thu, 2 Dec 2004 00:33:36 +0000 (00:33 +0000)
committerPierangelo Masarati <ando@openldap.org>
Thu, 2 Dec 2004 00:33:36 +0000 (00:33 +0000)
servers/slapd/back-sql/add.c
servers/slapd/back-sql/bind.c
servers/slapd/back-sql/compare.c
servers/slapd/back-sql/delete.c
servers/slapd/back-sql/entry-id.c
servers/slapd/back-sql/modify.c
servers/slapd/back-sql/modrdn.c
servers/slapd/back-sql/operational.c
servers/slapd/back-sql/proto-sql.h
servers/slapd/back-sql/search.c

index 8c6bfa7d14c467610d15f394f8bc1865c16ca53d..75b3e0ecd01a6094425770e3bb0a0b5cf2e0e192 100644 (file)
@@ -908,9 +908,7 @@ backsql_add( Operation *op, SlapReply *rs )
        Attribute               *at,
                                *at_objectClass = NULL;
        struct berval           pdn;
-       struct berval           realdn = BER_BVNULL,
-                               realndn = BER_BVNULL,
-                               realpdn = BER_BVNULL;
+       struct berval           realdn = BER_BVNULL;
 
 #ifdef BACKSQL_SYNCPROV
        /*
@@ -1018,17 +1016,7 @@ backsql_add( Operation *op, SlapReply *rs )
                goto done;
        }
 
-       realndn = op->oq_add.rs_e->e_nname;
-       if ( backsql_api_dn2odbc( op, rs, &realndn ) ) {
-               Debug( LDAP_DEBUG_TRACE, "   backsql_add(\"%s\"): "
-                       "backsql_api_dn2odbc(\"%s\") failed\n", 
-                       op->oq_add.rs_e->e_name.bv_val, realndn.bv_val, 0 );
-               rs->sr_err = LDAP_OTHER;
-               rs->sr_text = "SQL-backend error";
-               goto done;
-       }
-
-       rs->sr_err = backsql_dn2id( op, rs, NULL, dbh, &realndn );
+       rs->sr_err = backsql_dn2id( op, rs, NULL, dbh, &realdn, 0 );
        if ( rs->sr_err == LDAP_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE, "   backsql_add(\"%s\"): "
                        "entry exists\n",
@@ -1047,17 +1035,7 @@ backsql_add( Operation *op, SlapReply *rs )
                dnParent( &op->oq_add.rs_e->e_nname, &pdn );
        }
 
-       realpdn = pdn;
-       if ( backsql_api_dn2odbc( op, rs, &realpdn ) ) {
-               Debug( LDAP_DEBUG_TRACE, "   backsql_add(\"%s\"): "
-                       "backsql_api_dn2odbc(\"%s\") failed\n", 
-                       op->oq_add.rs_e->e_name.bv_val, pdn.bv_val, 0 );
-               rs->sr_err = LDAP_OTHER;
-               rs->sr_text = "SQL-backend error";
-               goto done;
-       }
-
-       rs->sr_err = backsql_dn2id( op, rs, &parent_id, dbh, &realpdn );
+       rs->sr_err = backsql_dn2id( op, rs, &parent_id, dbh, &pdn, 1 );
        if ( rs->sr_err != LDAP_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE, "   backsql_add(\"%s\"): "
                        "could not lookup parent entry for new record \"%s\"\n",
@@ -1085,28 +1063,13 @@ backsql_add( Operation *op, SlapReply *rs )
                                struct berval   dn;
                                char            *matched = NULL;
        
-                               if ( realpdn.bv_val != pdn.bv_val ) {
-                                       ch_free( realpdn.bv_val );
-                               }
-       
                                dn = pdn;
                                dnParent( &dn, &pdn );
        
                                /*
                                 * Empty DN ("") defaults to LDAP_SUCCESS
                                 */
-                               realpdn = pdn;
-                               if ( backsql_api_dn2odbc( op, rs, &realpdn ) ) {
-                                       Debug( LDAP_DEBUG_TRACE,
-                                               "   backsql_add(\"%s\"): "
-                                               "backsql_api_dn2odbc failed\n", 
-                                               op->oq_add.rs_e->e_name.bv_val, 0, 0 );
-                                       rs->sr_err = LDAP_OTHER;
-                                       rs->sr_text = "SQL-backend error";
-                                       goto done;
-                               }
-       
-                               rs->sr_err = backsql_dn2id( op, rs, NULL, dbh, &realpdn );
+                               rs->sr_err = backsql_dn2id( op, rs, NULL, dbh, &pdn, 1 );
                                switch ( rs->sr_err ) {
                                case LDAP_NO_SUCH_OBJECT:
                                        if ( !BER_BVISEMPTY( &pdn ) ) {
@@ -1444,14 +1407,6 @@ done:;
        {
                ch_free( realdn.bv_val );
        }
-       if ( !BER_BVISNULL( &realndn )
-                       && realndn.bv_val != op->oq_add.rs_e->e_nname.bv_val )
-       {
-               ch_free( realndn.bv_val );
-       }
-       if ( !BER_BVISNULL( &realpdn ) && realpdn.bv_val != pdn.bv_val ) {
-               ch_free( realpdn.bv_val );
-       }
        if ( !BER_BVISNULL( &parent_id.eid_ndn ) ) {
                (void)backsql_free_entryID( &parent_id, 0 );
        }
index 4e5bccb73bb40ccae5514553dfd2ba8d3ca8acef..c775280a9bf1a3ecb6983f35c686565e231d69b0 100644 (file)
@@ -36,7 +36,6 @@ backsql_bind( Operation *op, SlapReply *rs )
        backsql_srch_info       bsi;
        AttributeName           anlist[2];
        int                     rc;
-       struct berval           ndn;
  
        Debug( LDAP_DEBUG_TRACE, "==>backsql_bind()\n", 0, 0, 0 );
 
@@ -71,22 +70,13 @@ backsql_bind( Operation *op, SlapReply *rs )
                return 1;
        }
 
-       ndn = op->o_req_ndn;
-       if ( backsql_api_dn2odbc( op, rs, &ndn ) ) {
-               Debug( LDAP_DEBUG_TRACE, "backsql_search(): "
-                       "backsql_api_dn2odbc failed\n", 
-                       0, 0, 0 );
-               rs->sr_err = LDAP_OTHER;
-               rs->sr_text = "SQL-backend error";
-               goto error_return;
-       }
-
        anlist[0].an_name = password->ad_cname;
        anlist[0].an_desc = password;
        anlist[1].an_name.bv_val = NULL;
 
-       rc = backsql_init_search( &bsi, &ndn, LDAP_SCOPE_BASE, 
-                       -1, -1, -1, NULL, dbh, op, rs, anlist, 1 );
+       rc = backsql_init_search( &bsi, &op->o_req_ndn, LDAP_SCOPE_BASE, 
+                       -1, -1, -1, NULL, dbh, op, rs, anlist,
+                       ( BACKSQL_ISF_GET_ID | BACKSQL_ISF_MUCK ) );
        if ( rc != LDAP_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE, "backsql_bind(): "
                        "could not retrieve bindDN ID - no such entry\n", 
@@ -141,10 +131,6 @@ error_return:;
                return 1;
        }
        
-       if ( ndn.bv_val != op->o_req_ndn.bv_val ) {
-               ch_free( ndn.bv_val );
-       }
-
        Debug(LDAP_DEBUG_TRACE,"<==backsql_bind()\n",0,0,0);
        return 0;
 }
index 5178e67928d91788e1fc796d609803d7d4a2b39d..d091def078deaa790054c9dee7ec04b73e93f80d 100644 (file)
@@ -35,7 +35,6 @@ backsql_compare( Operation *op, SlapReply *rs )
        backsql_srch_info       bsi;
        int                     rc;
        AttributeName           anlist[2];
-       struct berval           ndn;
 
        user_entry.e_name.bv_val = NULL;
        user_entry.e_name.bv_len = 0;
@@ -56,16 +55,6 @@ backsql_compare( Operation *op, SlapReply *rs )
                goto return_results;
        }
 
-       ndn = op->o_req_ndn;
-       if ( backsql_api_dn2odbc( op, rs, &ndn ) ) {
-               Debug( LDAP_DEBUG_TRACE, "backsql_search(): "
-                       "backsql_api_dn2odbc failed\n", 
-                       0, 0, 0 );
-               rs->sr_err = LDAP_OTHER;
-               rs->sr_text = "SQL-backend error";
-               goto return_results;
-       }
-
        memset( &anlist[0], 0, 2 * sizeof( AttributeName ) );
        anlist[0].an_name = op->oq_compare.rs_ava->aa_desc->ad_cname;
        anlist[0].an_desc = op->oq_compare.rs_ava->aa_desc;
@@ -93,8 +82,9 @@ backsql_compare( Operation *op, SlapReply *rs )
                user_entry.e_attrs = nrs.sr_operational_attrs;
 
        } else {
-               rc = backsql_init_search( &bsi, &ndn, LDAP_SCOPE_BASE, 
-                               -1, -1, -1, NULL, dbh, op, rs, anlist, 1 );
+               rc = backsql_init_search( &bsi, &op->o_req_ndn, LDAP_SCOPE_BASE, 
+                               -1, -1, -1, NULL, dbh, op, rs, anlist,
+                               ( BACKSQL_ISF_GET_ID | BACKSQL_ISF_MUCK ) );
                if ( rc != LDAP_SUCCESS ) {
                        Debug( LDAP_DEBUG_TRACE, "backsql_compare(): "
                                "could not retrieve compareDN ID - no such entry\n", 
@@ -147,10 +137,6 @@ return_results:;
                (void)backsql_free_entryID( &bsi.bsi_base_id, 0 );
        }
 
-       if ( ndn.bv_val != op->o_req_ndn.bv_val ) {
-               ch_free( ndn.bv_val );
-       }
-
        if ( e != NULL ) {
                entry_clean( e );
        }
index 9de1d0af0548775b18bdaa30d534f17d0962f772..c769783ca05584f3a8b5c9de9a37d0993b49c36e 100644 (file)
@@ -118,8 +118,7 @@ backsql_delete( Operation *op, SlapReply *rs )
                goto done;
        }
        
-       /* FIXME: API... */
-       rs->sr_err = backsql_dn2id( op, rs, &e_id, dbh, &op->o_req_ndn );
+       rs->sr_err = backsql_dn2id( op, rs, &e_id, dbh, &op->o_req_ndn, 1 );
        if ( rs->sr_err != LDAP_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE, "   backsql_delete(): "
                        "could not lookup entry id\n", 0, 0, 0 );
index 8a0052027d485d3696bcb021ef21e3a6859fdbba..819da825d4571c537c6cd298a0bb9e95e9bd1791 100644 (file)
@@ -80,13 +80,15 @@ backsql_dn2id(
        SlapReply               *rs,
        backsql_entryID         *id,
        SQLHDBC                 dbh,
-       struct berval           *ndn )
+       struct berval           *ndn,
+       int                     muck )
 {
        backsql_info            *bi = op->o_bd->be_private;
-       SQLHSTMT                sth; 
+       SQLHSTMT                sth = SQL_NULL_HSTMT
        BACKSQL_ROW_NTS         row;
        RETCODE                 rc;
        int                     res;
+       struct berval           realndn = BER_BVNULL;
 
        /* TimesTen */
        char                    upperdn[ BACKSQL_MAX_DN_LEN + 1 ];
@@ -141,8 +143,19 @@ backsql_dn2id(
                        "backsql_dn2id(): error preparing SQL:\n%s", 
                        bi->sql_id_query, 0, 0);
                backsql_PrintErrors( bi->sql_db_env, dbh, sth, rc );
-               SQLFreeStmt( sth, SQL_DROP );
-               return LDAP_OTHER;
+               res = LDAP_OTHER;
+               goto done;
+       }
+
+       realndn = *ndn;
+       if ( muck ) {
+               if ( backsql_api_dn2odbc( op, rs, &realndn ) ) {
+                       Debug( LDAP_DEBUG_TRACE, "   backsql_dn2id(\"%s\"): "
+                               "backsql_api_dn2odbc(\"%s\") failed\n", 
+                               ndn->bv_val, realndn.bv_val, 0 );
+                       res = LDAP_OTHER;
+                       goto done;
+               }
        }
 
        if ( BACKSQL_HAS_LDAPINFO_DN_RU( bi ) ) {
@@ -151,8 +164,8 @@ backsql_dn2id(
                 * that can be searched using indexes
                 */
 
-               for ( i = 0, j = ndn->bv_len - 1; ndn->bv_val[ i ]; i++, j--) {
-                       upperdn[ i ] = ndn->bv_val[ j ];
+               for ( i = 0, j = realndn.bv_len - 1; realndn.bv_val[ i ]; i++, j--) {
+                       upperdn[ i ] = realndn.bv_val[ j ];
                }
                upperdn[ i ] = '\0';
                ldap_pvt_str2upper( upperdn );
@@ -163,7 +176,7 @@ backsql_dn2id(
 
        } else {
                if ( BACKSQL_USE_REVERSE_DN( bi ) ) {
-                       AC_MEMCPY( upperdn, ndn->bv_val, ndn->bv_len + 1 );
+                       AC_MEMCPY( upperdn, realndn.bv_val, realndn.bv_len + 1 );
                        ldap_pvt_str2upper( upperdn );
                        Debug( LDAP_DEBUG_TRACE,
                                "==>backsql_dn2id(): upperdn=\"%s\"\n",
@@ -171,7 +184,7 @@ backsql_dn2id(
                        ber_str2bv( upperdn, 0, 0, &tbbDN );
 
                } else {
-                       tbbDN = *ndn;
+                       tbbDN = realndn;
                }
        }
 
@@ -182,8 +195,8 @@ backsql_dn2id(
                        "error binding dn=\"%s\" parameter:\n", 
                        tbbDN.bv_val, 0, 0 );
                backsql_PrintErrors( bi->sql_db_env, dbh, sth, rc );
-               SQLFreeStmt( sth, SQL_DROP );
-               return LDAP_OTHER;
+               res = LDAP_OTHER;
+               goto done;
        }
 
        rc = SQLExecute( sth );
@@ -192,8 +205,8 @@ backsql_dn2id(
                        "error executing query (\"%s\", \"%s\"):\n", 
                        bi->sql_id_query, tbbDN.bv_val, 0 );
                backsql_PrintErrors( bi->sql_db_env, dbh, sth, rc );
-               SQLFreeStmt( sth, SQL_DROP );
-               return LDAP_OTHER;
+               res = LDAP_OTHER;
+               goto done;
        }
 
        backsql_BindRowAsStrings( sth, &row );
@@ -234,7 +247,7 @@ backsql_dn2id(
                                        Debug( LDAP_DEBUG_TRACE,
                                                "<==backsql_dn2id(\"%s\"): "
                                                "dnPrettyNormal failed (%d: %s)\n",
-                                               ndn->bv_val, res,
+                                               realndn.bv_val, res,
                                                ldap_err2string( res ) );
 
                                        /* cleanup... */
@@ -256,7 +269,15 @@ backsql_dn2id(
        }
        backsql_FreeRow( &row );
 
-       SQLFreeStmt( sth, SQL_DROP );
+done:;
+       if ( sth != SQL_NULL_HSTMT ) {
+               SQLFreeStmt( sth, SQL_DROP );
+       }
+
+       if ( !BER_BVISNULL( &realndn ) && realndn.bv_val != ndn->bv_val ) {
+               ch_free( realndn.bv_val );
+       }
+
        return res;
 }
 
index 5ac398664169b8eff4441ff2ebb3be69fab6cb37..e1434cdf65426823252112faba5208437dc59105 100644 (file)
@@ -55,19 +55,16 @@ backsql_modify( Operation *op, SlapReply *rs )
                 */
                rs->sr_text = ( rs->sr_err == LDAP_OTHER )
                        ? "SQL-backend error" : NULL;
-               send_ldap_result( op, rs );
-               return 1;
+               goto done;
        }
 
-       /* FIXME: API... */
-       rs->sr_err = backsql_dn2id( op, rs, &e_id, dbh, &op->o_req_ndn );
+       rs->sr_err = backsql_dn2id( op, rs, &e_id, dbh, &op->o_req_ndn, 1 );
        if ( rs->sr_err != LDAP_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE, "   backsql_modify(): "
                        "could not lookup entry id\n", 0, 0, 0 );
                rs->sr_text = ( rs->sr_err == LDAP_OTHER )
                        ? "SQL-backend error" : NULL;
-               send_ldap_result( op, rs );
-               return 1;
+               goto done;
        }
 
 #ifdef BACKSQL_ARBITRARY_KEY
@@ -95,8 +92,7 @@ backsql_modify( Operation *op, SlapReply *rs )
                 */
                rs->sr_err = LDAP_OTHER;
                rs->sr_text = "SQL-backend error";
-               send_ldap_result( op, rs );
-               return 1;
+               goto done;
        }
 
        e.e_attrs = NULL;
@@ -117,9 +113,11 @@ backsql_modify( Operation *op, SlapReply *rs )
                SQLTransact( SQL_NULL_HENV, dbh, 
                                op->o_noop ? SQL_ROLLBACK : SQL_COMMIT );
        }
+
+done:;
        send_ldap_result( op, rs );
        Debug( LDAP_DEBUG_TRACE, "<==backsql_modify()\n", 0, 0, 0 );
 
-       return op->o_noop;
+       return rs->sr_err != LDAP_SUCCESS ? rs->sr_err : op->o_noop;
 }
 
index 8df88271d83762f0d4f70d8d48ec021d188536ce..4a9703c7ce4371dc9f64bcc51906a62c69d6ba16 100644 (file)
@@ -40,7 +40,8 @@ backsql_modrdn( Operation *op, SlapReply *rs )
        backsql_oc_map_rec      *oc = NULL;
        struct berval           p_dn = BER_BVNULL, p_ndn = BER_BVNULL,
                                *new_pdn = NULL, *new_npdn = NULL,
-                               new_dn = BER_BVNULL, new_ndn = BER_BVNULL;
+                               new_dn = BER_BVNULL, new_ndn = BER_BVNULL,
+                               realnew_dn = BER_BVNULL;
        LDAPRDN                 new_rdn = NULL;
        LDAPRDN                 old_rdn = NULL;
        Entry                   e;
@@ -63,8 +64,7 @@ backsql_modrdn( Operation *op, SlapReply *rs )
                return 1;
        }
 
-       /* FIXME: API... */
-       rs->sr_err = backsql_dn2id( op, rs, &e_id, dbh, &op->o_req_ndn );
+       rs->sr_err = backsql_dn2id( op, rs, &e_id, dbh, &op->o_req_ndn, 1 );
        if ( rs->sr_err != LDAP_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE, "   backsql_modrdn(): "
                        "could not lookup entry id (%d)\n",
@@ -190,8 +190,7 @@ backsql_modrdn( Operation *op, SlapReply *rs )
        Debug( LDAP_DEBUG_TRACE, "   backsql_modrdn(): new entry dn is \"%s\"\n",
                        new_dn.bv_val, 0, 0 );
 
-       /* FIXME: API... */
-       rs->sr_err = backsql_dn2id( op, rs, &pe_id, dbh, &p_ndn );
+       rs->sr_err = backsql_dn2id( op, rs, &pe_id, dbh, &p_ndn, 1 );
        if ( rs->sr_err != LDAP_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE, "   backsql_modrdn(): "
                        "could not lookup old parent entry id\n", 0, 0, 0 );
@@ -211,8 +210,7 @@ backsql_modrdn( Operation *op, SlapReply *rs )
 
        (void)backsql_free_entryID( &pe_id, 0 );
 
-       /* FIXME: API... */
-       rs->sr_err = backsql_dn2id( op, rs, &new_pe_id, dbh, new_npdn );
+       rs->sr_err = backsql_dn2id( op, rs, &new_pe_id, dbh, new_npdn, 1 );
        if ( rs->sr_err != LDAP_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE, "   backsql_modrdn(): "
                        "could not lookup new parent entry id\n", 0, 0, 0 );
@@ -294,7 +292,19 @@ backsql_modrdn( Operation *op, SlapReply *rs )
                goto done;
        }
 
-       rc = backsql_BindParamBerVal( sth, 1, SQL_PARAM_INPUT, &new_dn );
+       realnew_dn = new_dn;
+       if ( backsql_api_dn2odbc( op, rs, &realnew_dn ) ) {
+               Debug( LDAP_DEBUG_TRACE, "   backsql_modrdn(\"%s\"): "
+                       "backsql_api_dn2odbc(\"%s\") failed\n", 
+                       op->o_req_dn.bv_val, realnew_dn.bv_val, 0 );
+               SQLFreeStmt( sth, SQL_DROP );
+
+               rs->sr_text = "SQL-backend error";
+               rs->sr_err = LDAP_OTHER;
+               goto done;
+       }
+
+       rc = backsql_BindParamBerVal( sth, 1, SQL_PARAM_INPUT, &realnew_dn );
        if ( rc != SQL_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE,
                        "   backsql_add_attr(): "
@@ -428,6 +438,10 @@ done:;
        }
 
 modrdn_return:;
+       if ( !BER_BVISNULL( &realnew_dn ) && realnew_dn.bv_val != new_dn.bv_val ) {
+               ch_free( realnew_dn.bv_val );
+       }
+
        if ( !BER_BVISNULL( &new_dn ) ) {
                slap_sl_free( new_dn.bv_val, op->o_tmpmemctx );
        }
index 4cd880187bae9d97c443389205c01e4dde988398..c0c7ed2442f5012f84a023febd91ffc9a5841725 100644 (file)
@@ -178,19 +178,12 @@ backsql_operational(
                        && !got[ BACKSQL_OP_ENTRYUUID ]
                        && attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_entryUUID ) == NULL )
        {
-               struct berval           ndn;
                backsql_srch_info       bsi;
 
-               ndn = rs->sr_entry->e_nname;
-               if ( backsql_api_dn2odbc( op, rs, &ndn ) ) {
-                       Debug( LDAP_DEBUG_TRACE, "backsql_operational(): "
-                               "backsql_api_dn2odbc failed\n", 
-                               0, 0, 0 );
-                       return 1;
-               }
-
-               rc = backsql_init_search( &bsi, &ndn, LDAP_SCOPE_BASE, 
-                       -1, -1, -1, NULL, dbh, op, rs, NULL, 1 );
+               rc = backsql_init_search( &bsi, &rs->sr_entry->e_nname,
+                               LDAP_SCOPE_BASE, -1, -1, -1, NULL,
+                               dbh, op, rs, NULL,
+                               ( BACKSQL_ISF_GET_ID | BACKSQL_ISF_MUCK ) );
                if ( rc != LDAP_SUCCESS ) {
                        Debug( LDAP_DEBUG_TRACE, "backsql_operational(): "
                                "could not retrieve entry ID - no such entry\n", 
@@ -202,10 +195,6 @@ backsql_operational(
 
                (void)backsql_free_entryID( &bsi.bsi_base_id, 0 );
 
-               if ( ndn.bv_val != rs->sr_entry->e_nname.bv_val ) {
-                       free( ndn.bv_val );
-               }
-
                if ( *ap == NULL ) {
                        Debug( LDAP_DEBUG_TRACE, "backsql_operational(): "
                                "could not retrieve entryUUID\n", 
index eb54d0af3c41375224c7eece846d44bc6b47743f..42162b9535fdcf9f347324ac052ed6f3f16abacf 100644 (file)
@@ -111,7 +111,7 @@ extern struct berval        backsql_baseObject_bv;
 
 /* stores in *id the ID in table ldap_entries corresponding to DN, if any */
 int backsql_dn2id( Operation *op, SlapReply *rs, backsql_entryID *id,
-               SQLHDBC dbh, struct berval *dn );
+               SQLHDBC dbh, struct berval *dn, int muck );
 
 /* stores in *nchildren the count of children for an entry */
 int backsql_count_children( backsql_info *bi, SQLHDBC dbh,
@@ -160,11 +160,13 @@ int backsql_destroy_schema_map( backsql_info *si );
  * search.c
  */
 
+#define BACKSQL_ISF_GET_ID     0x1U
+#define BACKSQL_ISF_MUCK       0x2U
 int backsql_init_search( backsql_srch_info *bsi, 
                struct berval *nbase, int scope, int slimit, int tlimit,
                time_t stoptime, Filter *filter, SQLHDBC dbh,
                Operation *op, SlapReply *rs, AttributeName *attrs,
-               int get_base_id );
+               unsigned flags );
 
 /*
  * sql-wrap.h
index 393068f189942c6ca3b4148e5c1310b6778ffb16..c43abc2053a390c58c498f2505f052f9e9eab092 100644 (file)
@@ -113,7 +113,7 @@ backsql_init_search(
        Operation               *op,
        SlapReply               *rs,
        AttributeName           *attrs,
-       int                     get_base_id )
+       unsigned                flags )
 {
        AttributeName           *p;
        int                     rc = LDAP_SUCCESS;
@@ -191,10 +191,11 @@ backsql_init_search(
        bsi->bsi_flt_where.bb_len = 0;
        bsi->bsi_filter_oc = NULL;
 
-       if ( get_base_id ) {
+       if ( flags & BACKSQL_ISF_GET_ID ) {
                assert( op->o_bd->be_private );
 
-               rc = backsql_dn2id( op, rs, &bsi->bsi_base_id, dbh, nbase );
+               rc = backsql_dn2id( op, rs, &bsi->bsi_base_id, dbh, nbase,
+                               ( flags & BACKSQL_ISF_MUCK ) );
        }
 
        return ( bsi->bsi_status = rc );
@@ -1601,7 +1602,8 @@ backsql_search( Operation *op, SlapReply *rs )
        time_t                  stoptime = 0;
        backsql_srch_info       bsi;
        backsql_entryID         *eid = NULL;
-       struct berval           nbase = BER_BVNULL;
+       struct berval           nbase = BER_BVNULL,
+                               realndn = BER_BVNULL;
 
        manageDSAit = get_manageDSAit( op );
 
@@ -1644,11 +1646,11 @@ backsql_search( Operation *op, SlapReply *rs )
        /* compute it anyway; root does not use it */
        stoptime = op->o_time + op->ors_tlimit;
 
-       nbase = op->o_req_ndn;
-       if ( backsql_api_dn2odbc( op, rs, &nbase ) ) {
-               Debug( LDAP_DEBUG_TRACE, "backsql_search(): "
-                       "backsql_api_dn2odbc failed\n", 
-                       0, 0, 0 );
+       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 );
@@ -1656,11 +1658,12 @@ backsql_search( Operation *op, SlapReply *rs )
        }
 
        /* init search */
-       rs->sr_err = backsql_init_search( &bsi, &nbase,
+       rs->sr_err = backsql_init_search( &bsi, &realndn,
                        op->ors_scope,
                        op->ors_slimit, op->ors_tlimit,
                        stoptime, op->ors_filter,
-                       dbh, op, rs, op->ors_attrs, 1 );
+                       dbh, op, rs, op->ors_attrs,
+                       ( BACKSQL_ISF_GET_ID | BACKSQL_ISF_MUCK ) );
        if ( rs->sr_err != LDAP_SUCCESS ) {
                send_ldap_result( op, rs );
                goto done;
@@ -1829,7 +1832,8 @@ backsql_search( Operation *op, SlapReply *rs )
                                                &e->e_nname,
                                                LDAP_SCOPE_BASE, 
                                                -1, -1, -1, NULL,
-                                               dbh, op, rs, NULL, 0 );
+                                               dbh, op, rs, NULL,
+                                               BACKSQL_ISF_MUCK );
                                bsi2.bsi_e = &user_entry2;
                                rc = backsql_id2entry( &bsi2, eid );
                                if ( rc == LDAP_SUCCESS ) {
@@ -2010,6 +2014,10 @@ 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 );
+       }
+
        if ( !BER_BVISNULL( &bsi.bsi_base_id.eid_ndn ) ) {
                (void)backsql_free_entryID( &bsi.bsi_base_id, 0 );
        }
@@ -2066,7 +2074,8 @@ backsql_entry_get(
                        ndn,
                        LDAP_SCOPE_BASE, 
                        SLAP_NO_LIMIT, SLAP_NO_LIMIT, -1, NULL,
-                       dbh, op, &rs, at ? anlist : NULL, 1 );
+                       dbh, op, &rs, at ? anlist : NULL,
+                       ( BACKSQL_ISF_GET_ID | BACKSQL_ISF_MUCK ) );
        if ( rc != LDAP_SUCCESS ) {
                return rc;
        }