]> git.sur5r.net Git - openldap/commitdiff
import small fixes from HEAD
authorPierangelo Masarati <ando@openldap.org>
Thu, 17 Aug 2006 19:53:16 +0000 (19:53 +0000)
committerPierangelo Masarati <ando@openldap.org>
Thu, 17 Aug 2006 19:53:16 +0000 (19:53 +0000)
13 files changed:
CHANGES
servers/slapd/back-sql/add.c
servers/slapd/back-sql/delete.c
servers/slapd/back-sql/entry-id.c
servers/slapd/back-sql/init.c
servers/slapd/back-sql/modify.c
servers/slapd/back-sql/modrdn.c
servers/slapd/back-sql/rdbms_depend/README
servers/slapd/back-sql/schema-map.c
servers/slapd/back-sql/search.c
servers/slapd/back-sql/sql-wrap.c
tests/data/sql-read.out
tests/scripts/sql-test000-read

diff --git a/CHANGES b/CHANGES
index 6153314802eeecabe1ce3bea142d18462276abbf..8329ef223163b52ecedbf618cafad11e81ca33fd 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -6,6 +6,7 @@ OpenLDAP 2.3.26 Release
        Fixed slapd incorrect rebuilding of replica URI (ITS#4633)
        Fixed slapd DN X.509 normalization crash (ITS#4644)
        Fixed slapd-monitor operations order via callbacks (ITS#4631)
+       Fixed slapd-sql undefined filter handling (ITS#4604)
        Fixed slapo-accesslog purge task during shutdown
        Fixed slapo-ppolicy handling of default policy (ITS#4634)
        Fixed slapo-ppolicy logging verbosity when using default policy
index e9f011a9946ec91abc1ac2bab57a82d2bc001f78..e5ee14dc5e19022bdce13735371776c5495e508c 100644 (file)
@@ -1141,15 +1141,6 @@ backsql_add( Operation *op, SlapReply *rs )
                }
        }
 
-       if ( get_assert( op ) &&
-               ( test_filter( op, op->oq_add.rs_e, get_assertion( op ) )
-                       != LDAP_COMPARE_TRUE ) )
-       {
-               rs->sr_err = LDAP_ASSERTION_FAILED;
-               e = op->ora_e;
-               goto done;
-       }
-
        /*
         * create_proc is executed; if expect_return is set, then
         * an output parameter is bound, which should contain 
@@ -1470,6 +1461,7 @@ done:;
                SQLUSMALLINT    CompletionType = SQL_ROLLBACK;
 
                if ( rs->sr_err == LDAP_SUCCESS && !op->o_noop ) {
+                       assert( e == NULL );
                        CompletionType = SQL_COMMIT;
                }
 
@@ -1514,6 +1506,10 @@ done:;
        }
 #endif /* SLAP_ACL_HONOR_DISCLOSE */
 
+       if ( op->o_noop && rs->sr_err == LDAP_SUCCESS ) {
+               rs->sr_err = LDAP_X_NO_OPERATION;
+       }
+
        send_ldap_result( op, rs );
        slap_graduate_commit_csn( op );
 
index bd2ee37c7d81c929bec9217718c56aa9a04db782..0e82c3f97d283a3273de940cb938df93196100d9 100644 (file)
@@ -441,6 +441,7 @@ backsql_delete( Operation *op, SlapReply *rs )
                SQLUSMALLINT    CompletionType = SQL_ROLLBACK;
        
                if ( rs->sr_err == LDAP_SUCCESS && !op->o_noop ) {
+                       assert( e == NULL );
                        CompletionType = SQL_COMMIT;
                }
 
@@ -464,6 +465,10 @@ done:;
        }
 #endif /* SLAP_ACL_HONOR_DISCLOSE */
 
+       if ( op->o_noop && rs->sr_err == LDAP_SUCCESS ) {
+               rs->sr_err = LDAP_X_NO_OPERATION;
+       }
+
        send_ldap_result( op, rs );
 
        Debug( LDAP_DEBUG_TRACE, "<==backsql_delete()\n", 0, 0, 0 );
index c2afde67276c4ef23a8eb1b36eefaac8d6c7cc2e..801729e73363a8e2d7a8ccd7aa5666949dc0655b 100644 (file)
@@ -90,7 +90,7 @@ backsql_dn2id(
 {
        backsql_info            *bi = op->o_bd->be_private;
        SQLHSTMT                sth = SQL_NULL_HSTMT; 
-       BACKSQL_ROW_NTS         row;
+       BACKSQL_ROW_NTS         row = { 0 };
        RETCODE                 rc;
        int                     res;
        struct berval           realndn = BER_BVNULL;
@@ -648,6 +648,11 @@ backsql_get_attr_vals( void *v_at, void *v_bsi )
                Debug( LDAP_DEBUG_TRACE, "backsql_get_attr_vals(): "
                        "error preparing query: %s\n", at->bam_query, 0, 0 );
                backsql_PrintErrors( bi->sql_db_env, bsi->bsi_dbh, sth, rc );
+#ifdef BACKSQL_COUNTQUERY
+               if ( append ) {
+                       attr_free( attr );
+               }
+#endif /* BACKSQL_COUNTQUERY */
                return 1;
        }
 
@@ -656,6 +661,11 @@ backsql_get_attr_vals( void *v_at, void *v_bsi )
        if ( rc != SQL_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE, "backsql_get_attr_vals(): "
                        "error binding key value parameter\n", 0, 0, 0 );
+#ifdef BACKSQL_COUNTQUERY
+               if ( append ) {
+                       attr_free( attr );
+               }
+#endif /* BACKSQL_COUNTQUERY */
                return 1;
        }
 
@@ -678,6 +688,11 @@ backsql_get_attr_vals( void *v_at, void *v_bsi )
                        at->bam_query, 0, 0 );
                backsql_PrintErrors( bi->sql_db_env, bsi->bsi_dbh, sth, rc );
                SQLFreeStmt( sth, SQL_DROP );
+#ifdef BACKSQL_COUNTQUERY
+               if ( append ) {
+                       attr_free( attr );
+               }
+#endif /* BACKSQL_COUNTQUERY */
                return 1;
        }
 
index a8fc074795cff9ec07f85f39addc72dbc797227a..42bbb9c2a36469f43b9845a6565a967a3b48739e 100644 (file)
@@ -36,10 +36,8 @@ sql_back_initialize(
        static char *controls[] = {
                LDAP_CONTROL_ASSERT,
                LDAP_CONTROL_MANAGEDSAIT,
-#if 0 /* needs improvements */
                LDAP_CONTROL_NOOP,
-#endif
-#ifdef SLAP_CONTROL_X_TREE_DELETE
+#if 0 /* SLAP_CONTROL_X_TREE_DELETE */
                SLAP_CONTROL_X_TREE_DELETE,
 #endif /* SLAP_CONTROL_X_TREE_DELETE */
                NULL
index 45d21bda26b511f7f5ad2609edc8e83d4380f253..d371483e9dbaca67129d74d27bf1be3764b4a76d 100644 (file)
@@ -168,6 +168,7 @@ do_transact:;
         * Commit only if all operations succeed
         */
        if ( rs->sr_err == LDAP_SUCCESS && !op->o_noop ) {
+               assert( e == NULL );
                CompletionType = SQL_COMMIT;
        }
 
@@ -190,6 +191,10 @@ done:;
        }
 #endif /* SLAP_ACL_HONOR_DISCLOSE */
 
+       if ( op->o_noop && rs->sr_err == LDAP_SUCCESS ) {
+               rs->sr_err = LDAP_X_NO_OPERATION;
+       }
+
        send_ldap_result( op, rs );
        slap_graduate_commit_csn( op );
 
@@ -205,6 +210,11 @@ done:;
                op->o_tmpfree( bsi.bsi_attrs, op->o_tmpmemctx );
        }
 
+       if ( rs->sr_ref ) {
+               ber_bvarray_free( rs->sr_ref );
+               rs->sr_ref = NULL;
+       }
+
        Debug( LDAP_DEBUG_TRACE, "<==backsql_modify()\n", 0, 0, 0 );
 
        return rs->sr_err;
index 49cd073373b97669345a3f96209b7f53d8300ca0..28bae1fbdf5baaf78d7173471050432d9f536c08 100644 (file)
@@ -533,6 +533,10 @@ done:;
                SQLTransact( SQL_NULL_HENV, dbh, CompletionType );
        }
 
+       if ( op->o_noop && rs->sr_err == LDAP_SUCCESS ) {
+               rs->sr_err = LDAP_X_NO_OPERATION;
+       }
+
        send_ldap_result( op, rs );
        slap_graduate_commit_csn( op );
 
@@ -583,6 +587,11 @@ done:;
                backsql_entry_clean( op, &n );
        }
 
+       if ( rs->sr_ref ) {
+               ber_bvarray_free( rs->sr_ref );
+               rs->sr_ref = NULL;
+       }
+
        Debug( LDAP_DEBUG_TRACE, "<==backsql_modrdn()\n", 0, 0, 0 );
 
        return rs->sr_err;
index 65af67a196732b5a03238411a647df98a9929c71..8c9ffe14f26217f6a15caa3f6611b7983ddddfdb 100644 (file)
@@ -120,7 +120,7 @@ example=> <control-D>
 
 3.1.5) Run the test:
 [root@localhost]# cd $SOURCES/tests
-[root@localhost]# SLAPD_USE_SQL=pgsql ./run test031
+[root@localhost]# SLAPD_USE_SQL=pgsql ./run sql-test000
 
 3.2) MySQL
 
@@ -149,7 +149,7 @@ mysql> exit;
 
 3.2.5) Run the test:
 [root@localhost]# cd $SOURCES/tests
-[root@localhost]# SLAPD_USE_SQL=mysql ./run test031
+[root@localhost]# SLAPD_USE_SQL=mysql ./run sql-test000
 
 3.3) IBM db2
 [n.a.]
@@ -173,7 +173,7 @@ in auto-commit mode (-c)
 
 3.3.5) Run the test:
 [root@localhost]# cd $SOURCES/tests
-[root@localhost]# SLAPD_USE_SQL=ibmdb2 ./run test031
+[root@localhost]# SLAPD_USE_SQL=ibmdb2 ./run sql-test000
 
 4) Cleanup:
 The test is basically readonly; this can be performed by all RDBMSes 
index 3ecdcdfaa21748997520e4fc9a595d4034f779fe..6f47ce96aaec579b56bfaafa222a7ef9aea59923 100644 (file)
@@ -319,6 +319,7 @@ backsql_oc_get_attr_mapping( void *v_oc, void *v_bas )
                const char      *text = NULL;
                struct berval   bv;
                struct berbuf   bb = BB_NULL;
+               AttributeDescription *ad = NULL;
 
                Debug( LDAP_DEBUG_TRACE, 
                        "attributeType:\n"
@@ -336,10 +337,7 @@ backsql_oc_get_attr_mapping( void *v_oc, void *v_bas )
                /* TimesTen */
                Debug( LDAP_DEBUG_TRACE, "\tsel_expr_u=\"%s\"\n",
                                at_row.cols[ 8 ], 0, 0 );
-               at_map = (backsql_at_map_rec *)ch_calloc( 1,
-                               sizeof( backsql_at_map_rec ) );
-               rc = slap_str2ad( at_row.cols[ 0 ], 
-                               &at_map->bam_ad, &text );
+               rc = slap_str2ad( at_row.cols[ 0 ], &ad, &text );
                if ( rc != LDAP_SUCCESS ) {
                        Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_attr_mapping(): "
                                "attribute \"%s\" for objectClass \"%s\" "
@@ -349,6 +347,9 @@ backsql_oc_get_attr_mapping( void *v_oc, void *v_bas )
                        bas->bas_rc = LDAP_CONSTRAINT_VIOLATION;
                        return BACKSQL_AVL_STOP;
                }
+               at_map = (backsql_at_map_rec *)ch_calloc( 1,
+                               sizeof( backsql_at_map_rec ) );
+               at_map->bam_ad = ad;
 
                ber_str2bv( at_row.cols[ 1 ], 0, 1, &at_map->bam_sel_expr );
                if ( at_row.value_len[ 8 ] < 0 ) {
index 045dff25dfe81cd41e93027c60f8756419fe28be..faddc121651daee9c3a8cedb5df2dc163bc33876 100644 (file)
@@ -314,9 +314,7 @@ backsql_init_search(
                                }
 
                        } else {
-                               rs->sr_ref = referral_rewrite( default_referral,
-                                               NULL, &op->o_req_dn, scope );
-                               rc = rs->sr_err = LDAP_REFERRAL;
+                               rs->sr_err = rc;
                        }
                }
        }
@@ -654,9 +652,35 @@ backsql_process_filter( backsql_srch_info *bsi, Filter *f )
 
        Debug( LDAP_DEBUG_TRACE, "==>backsql_process_filter()\n", 0, 0, 0 );
        if ( f->f_choice == SLAPD_FILTER_COMPUTED ) {
+               struct berval   flt;
+               char            *msg = NULL;
+
+               switch ( f->f_result ) {
+               case LDAP_COMPARE_TRUE:
+                       BER_BVSTR( &flt, "10=10" );
+                       msg = "TRUE";
+                       break;
+
+               case LDAP_COMPARE_FALSE:
+                       BER_BVSTR( &flt, "11=0" );
+                       msg = "FALSE";
+                       break;
+
+               case SLAPD_COMPARE_UNDEFINED:
+                       BER_BVSTR( &flt, "12=0" );
+                       msg = "UNDEFINED";
+                       break;
+
+               default:
+                       rc = -1;
+                       goto done;
+               }
+
                Debug( LDAP_DEBUG_TRACE, "backsql_process_filter(): "
-                       "invalid filter\n", 0, 0, 0 );
-               rc = -1;
+                       "filter computed (%s)\n", msg, 0, 0 );
+               backsql_strfcat_x( &bsi->bsi_flt_where,
+                               bsi->bsi_op->o_tmpmemctx, "b", &flt );
+               rc = 1;
                goto done;
        }
 
@@ -1517,16 +1541,16 @@ backsql_srch_query( backsql_srch_info *bsi, struct berval *query )
                BER_BVZERO( query );
        }
  
-       free( bsi->bsi_sel.bb_val.bv_val );
+       bsi->bsi_op->o_tmpfree( bsi->bsi_sel.bb_val.bv_val, bsi->bsi_op->o_tmpmemctx );
        BER_BVZERO( &bsi->bsi_sel.bb_val );
        bsi->bsi_sel.bb_len = 0;
-       free( bsi->bsi_from.bb_val.bv_val );
+       bsi->bsi_op->o_tmpfree( bsi->bsi_from.bb_val.bv_val, bsi->bsi_op->o_tmpmemctx );
        BER_BVZERO( &bsi->bsi_from.bb_val );
        bsi->bsi_from.bb_len = 0;
-       free( bsi->bsi_join_where.bb_val.bv_val );
+       bsi->bsi_op->o_tmpfree( bsi->bsi_join_where.bb_val.bv_val, bsi->bsi_op->o_tmpmemctx );
        BER_BVZERO( &bsi->bsi_join_where.bb_val );
        bsi->bsi_join_where.bb_len = 0;
-       free( bsi->bsi_flt_where.bb_val.bv_val );
+       bsi->bsi_op->o_tmpfree( bsi->bsi_flt_where.bb_val.bv_val, bsi->bsi_op->o_tmpmemctx );
        BER_BVZERO( &bsi->bsi_flt_where.bb_val );
        bsi->bsi_flt_where.bb_len = 0;
        
@@ -1620,7 +1644,7 @@ backsql_oc_get_candidates( void *v_oc, void *v_bsi )
                        query.bv_val, 0, 0 );
 
        rc = backsql_Prepare( bsi->bsi_dbh, &sth, query.bv_val, 0 );
-       free( query.bv_val );
+       bsi->bsi_op->o_tmpfree( query.bv_val, bsi->bsi_op->o_tmpmemctx );
        BER_BVZERO( &query );
        if ( rc != SQL_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): "
@@ -1970,7 +1994,7 @@ backsql_search( Operation *op, SlapReply *rs )
        default:
 #ifdef SLAP_ACL_HONOR_DISCLOSE
                if ( !BER_BVISNULL( &base_entry.e_nname )
-                               && ! access_allowed( op, &base_entry,
+                               && !access_allowed( op, &base_entry,
                                        slap_schema.si_ad_entry, NULL,
                                        ACL_DISCLOSE, NULL ) )
                {
@@ -1991,6 +2015,10 @@ backsql_search( Operation *op, SlapReply *rs )
                        rs->sr_ref = NULL;
                }
 
+               if ( !BER_BVISNULL( &base_entry.e_nname ) ) {
+                       entry_clean( &base_entry );
+               }
+
                goto done;
        }
 #ifdef SLAP_ACL_HONOR_DISCLOSE
index 9a9b4f350016d0a44e1858d9f902fe7874faab03..bda1982bcdbb47de64a5eddd6716730a45eca556 100644 (file)
@@ -48,12 +48,11 @@ backsql_PrintErrors( SQLHENV henv, SQLHDBC hdbc, SQLHSTMT sth, int rc )
        Debug( LDAP_DEBUG_TRACE, "Return code: %d\n", rc, 0, 0 );
 
        for ( ; rc = SQLError( henv, hdbc, sth, state, &iSqlCode, msg,
-                       SQL_MAX_MESSAGE_LENGTH - 1, &len ), BACKSQL_SUCCESS( rc ); ) {
+               SQL_MAX_MESSAGE_LENGTH - 1, &len ), BACKSQL_SUCCESS( rc ); )
+       {
                Debug( LDAP_DEBUG_TRACE,
-                               "   Native error code: %d\n"
-                               "   SQL engine state:  %s\n"
-                               "   Message:           %s\n", 
-                               (int)iSqlCode, state, msg );
+                       "   nativeErrCode=%d SQLengineState=%s msg=\"%s\"\n",
+                       (int)iSqlCode, state, msg );
        }
 }
 
@@ -163,12 +162,26 @@ backsql_BindRowAsStrings_x( SQLHSTMT sth, BACKSQL_ROW_NTS *row, void *ctx )
 
                row->col_names = (BerVarray)ber_memcalloc_x( row->ncols + 1, 
                                sizeof( struct berval ), ctx );
+               if ( !row->col_names ) goto nomem3;
                row->cols = (char **)ber_memcalloc_x( row->ncols + 1, 
                                sizeof( char * ), ctx );
+               if ( !row->cols ) goto nomem2;
                row->col_prec = (UDWORD *)ber_memcalloc_x( row->ncols,
                                sizeof( UDWORD ), ctx );
+               if ( !row->col_prec ) goto nomem1;
                row->value_len = (SQLINTEGER *)ber_memcalloc_x( row->ncols,
                                sizeof( SQLINTEGER ), ctx );
+               if ( !row->value_len ) {
+                       ber_memfree_x( row->col_prec, ctx );
+                       row->col_prec = NULL;
+nomem1:                ber_memfree_x( row->cols, ctx );
+                       row->cols = NULL;
+nomem2:                ber_memfree_x( row->col_names, ctx );
+                       row->col_names = NULL;
+nomem3:                Debug( LDAP_DEBUG_ANY, "backsql_BindRowAsStrings: "
+                               "out of memory\n", 0, 0, 0 );
+                       return LDAP_NO_MEMORY;
+               }
                for ( i = 1; i <= row->ncols; i++ ) {
                        rc = SQLDescribeCol( sth, (SQLSMALLINT)i, &colname[ 0 ],
                                        (SQLUINTEGER)( sizeof( colname ) - 1 ),
index 53fe8c059ce135012a6976752d07e27491eb8df3..a88f3192b0a78b5d5fa009fbc92ea93ae10010cc 100644 (file)
@@ -382,6 +382,15 @@ objectClass: dcObject
 o: Example
 dc: example
 
+# Testing undefined attribute in filter...
+# refldap://localhost:9012/dc=example,dc=com??sub
+
+dn: dc=example,dc=com
+objectClass: organization
+objectClass: dcObject
+o: Example
+dc: example
+
 # Testing objectClass inheritance in filter...
 dn: cn=Mitya Kovalev,dc=example,dc=com
 objectClass: inetOrgPerson
index d55d56ae3e1da761787dee80374b487507588253..1d206cc9f34fe7edf214a0580db8c38e6dc2dc6d 100755 (executable)
@@ -326,6 +326,19 @@ if test $RC != 0 ; then
        exit $RC
 fi
 
+# ITS#4604
+echo "Testing undefined attribute in filter..."
+echo "# Testing undefined attribute in filter..." >> $SEARCHOUT
+$LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
+        "(|(o=example)(foobar=x))" >> $SEARCHOUT 2>&1
+
+RC=$?
+if test $RC != 0 ; then
+       echo "ldapsearch failed ($RC)!"
+       test $KILLSERVERS != no && kill -HUP $KILLPIDS
+       exit $RC
+fi
+
 echo "Testing objectClass inheritance in filter..."
 echo "# Testing objectClass inheritance in filter..." >> $SEARCHOUT
 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \