]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-sql/add.c
ITS#6001 SID of queued CSN must match the one in the op
[openldap] / servers / slapd / back-sql / add.c
index 15c3b9742a3c5115f01c9b390f0c51e3dcf2735c..ae88f76e4938b4fc0215c4f5db04a3153ce57439 100644 (file)
@@ -1,7 +1,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1999-2005 The OpenLDAP Foundation.
+ * Copyright 1999-2009 The OpenLDAP Foundation.
  * Portions Copyright 1999 Dmitry Kovalev.
  * Portions Copyright 2002 Pierangelo Masarati.
  * Portions Copyright 2004 Mark Adamson.
@@ -794,7 +794,7 @@ backsql_add_attr(
                int             prc = LDAP_SUCCESS;
                /* first parameter #, parameter order */
                SQLUSMALLINT    pno, po;
-               char            logbuf[] = "val[18446744073709551615UL], id=18446744073709551615UL";
+               char            logbuf[ STRLENOF("val[], id=") + 2*LDAP_PVT_INTTYPE_CHARS(unsigned long)];
                
                /*
                 * Do not deal with the objectClass that is used
@@ -924,6 +924,7 @@ backsql_add( Operation *op, SlapReply *rs )
        Entry                   p = { 0 }, *e = NULL;
        Attribute               *at,
                                *at_objectClass = NULL;
+       ObjectClass             *soc = NULL;
        struct berval           scname = BER_BVNULL;
        struct berval           pdn;
        struct berval           realdn = BER_BVNULL;
@@ -957,13 +958,11 @@ backsql_add( Operation *op, SlapReply *rs )
        Debug( LDAP_DEBUG_TRACE, "==>backsql_add(\"%s\")\n",
                        op->ora_e->e_name.bv_val, 0, 0 );
 
-       slap_add_opattrs( op, &rs->sr_text, textbuf, textlen, 1 );
-
        /* check schema */
        if ( BACKSQL_CHECK_SCHEMA( bi ) ) {
                char            textbuf[ SLAP_TEXT_BUFLEN ] = { '\0' };
 
-               rs->sr_err = entry_schema_check( op, op->ora_e, NULL, 0,
+               rs->sr_err = entry_schema_check( op, op->ora_e, NULL, 0, 1, NULL,
                        &rs->sr_text, textbuf, sizeof( textbuf ) );
                if ( rs->sr_err != LDAP_SUCCESS ) {
                        Debug( LDAP_DEBUG_TRACE, "   backsql_add(\"%s\"): "
@@ -974,6 +973,19 @@ backsql_add( Operation *op, SlapReply *rs )
                }
        }
 
+       slap_add_opattrs( op, &rs->sr_text, textbuf, textlen, 1 );
+
+       if ( get_assert( op ) &&
+               ( test_filter( op, op->ora_e, get_assertion( op )) != LDAP_COMPARE_TRUE ))
+       {
+               Debug( LDAP_DEBUG_TRACE, "   backsql_add(\"%s\"): "
+                       "assertion control failed -- aborting\n",
+                       op->ora_e->e_name.bv_val, 0, 0 );
+               e = NULL;
+               rs->sr_err = LDAP_ASSERTION_FAILED;
+               goto done;
+       }
+
        /* search structuralObjectClass */
        for ( at = op->ora_e->e_attrs; at != NULL; at = at->a_next ) {
                if ( at->a_desc == slap_schema.si_ad_structuralObjectClass ) {
@@ -1002,8 +1014,8 @@ backsql_add( Operation *op, SlapReply *rs )
                        goto done;
                }
 
-               rs->sr_err = structural_class( at->a_vals, &scname, NULL,
-                               &text, buf, sizeof( buf ) );
+               rs->sr_err = structural_class( at->a_vals, &soc, NULL,
+                               &text, buf, sizeof( buf ), op->o_tmpmemctx );
                if ( rs->sr_err != LDAP_SUCCESS ) {
                        Debug( LDAP_DEBUG_TRACE, "   backsql_add(\"%s\"): "
                                "%s (%d)\n",
@@ -1011,6 +1023,7 @@ backsql_add( Operation *op, SlapReply *rs )
                        e = NULL;
                        goto done;
                }
+               scname = soc->soc_cname;
 
        } else {
                scname = at->a_vals[0];
@@ -1141,15 +1154,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 +1474,7 @@ done:;
                SQLUSMALLINT    CompletionType = SQL_ROLLBACK;
 
                if ( rs->sr_err == LDAP_SUCCESS && !op->o_noop ) {
+                       assert( e == NULL );
                        CompletionType = SQL_COMMIT;
                }
 
@@ -1487,7 +1492,6 @@ done:;
         * in deleting that row.
         */
 
-#ifdef SLAP_ACL_HONOR_DISCLOSE
        if ( e != NULL ) {
                int     disclose = 1;
 
@@ -1512,9 +1516,13 @@ 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 );
 
        if ( !BER_BVISNULL( &realdn )
                        && realdn.bv_val != op->ora_e->e_name.bv_val )
@@ -1523,7 +1531,7 @@ done:;
        }
 
        if ( !BER_BVISNULL( &bsi.bsi_base_id.eid_ndn ) ) {
-               (void)backsql_free_entryID( op, &bsi.bsi_base_id, 0 );
+               (void)backsql_free_entryID( &bsi.bsi_base_id, 0, op->o_tmpmemctx );
        }
 
        if ( !BER_BVISNULL( &p.e_nname ) ) {