]> git.sur5r.net Git - openldap/commitdiff
fix DN munging; also fix potential error when logging incomplete deletes
authorPierangelo Masarati <ando@openldap.org>
Wed, 1 Dec 2004 23:16:21 +0000 (23:16 +0000)
committerPierangelo Masarati <ando@openldap.org>
Wed, 1 Dec 2004 23:16:21 +0000 (23:16 +0000)
servers/slapd/back-sql/add.c
servers/slapd/back-sql/api.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/proto-sql.h
servers/slapd/back-sql/schema-map.c
servers/slapd/back-sql/search.c

index 02da98356281a6759cae9c176fc48bed4ddd9ce3..8c6bfa7d14c467610d15f394f8bc1865c16ca53d 100644 (file)
@@ -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 ) ) {
index 5eb71b8d67cf8e14eba6929cd9758cae0c12c8d9..1a1c32ab9368de151b744e13f24807e70771e550 100644 (file)
@@ -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 );
                }
        }
 
index fbe4f1a869bf8011dccd5a2c4faa685133a8f3e4..9de1d0af0548775b18bdaa30d534f17d0962f772 100644 (file)
@@ -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 );
index d75bfe0ddae0d5d50e8737f4624cc654dda22c31..8a0052027d485d3696bcb021ef21e3a6859fdbba 100644 (file)
@@ -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;
index c73ba2431c38596e2d29082d55aea45787245568..5ac398664169b8eff4441ff2ebb3be69fab6cb37 100644 (file)
@@ -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 );
index 6e01e5aa2ea75d0f631b77c138c03515644415e9..8df88271d83762f0d4f70d8d48ec021d188536ce 100644 (file)
@@ -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 );
index d438c7dda423fc8baf24b925ffa37ce35660a597..eb54d0af3c41375224c7eece846d44bc6b47743f 100644 (file)
@@ -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 */
index 7c115bd224826eb9a7872c324e38f5ae0ba339ff..9022c451dc08942e2efd09097a2a410bb20d054f 100644 (file)
@@ -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 );
        }
 
index 3fbe8cd13d7fbf267ed0ed5566372ceb43da8270..393068f189942c6ca3b4148e5c1310b6778ffb16 100644 (file)
@@ -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 );