r10477: expose transactions outside ldb and change the API once more
authorSimo Sorce <idra@samba.org>
Sat, 24 Sep 2005 15:42:15 +0000 (15:42 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:38:52 +0000 (13:38 -0500)
do not autostart transactions on ldb operations if a transaction is already in place
test transactions on winsdb

all my tests passes so far
tridge please confirm this is ok for you
(This used to be commit c2bb2a36bdbe0ec7519697a9a9ba7526a0defac2)

19 files changed:
source4/dsdb/samdb/ldb_modules/objectguid.c
source4/dsdb/samdb/ldb_modules/samldb.c
source4/lib/ldb/common/ldb.c
source4/lib/ldb/common/ldb_modules.c
source4/lib/ldb/common/ldb_msg.c
source4/lib/ldb/include/ldb.h
source4/lib/ldb/include/ldb_errors.h
source4/lib/ldb/include/ldb_private.h
source4/lib/ldb/ldb_ildap/ldb_ildap.c
source4/lib/ldb/ldb_ldap/ldb_ldap.c
source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c
source4/lib/ldb/ldb_tdb/ldb_tdb.c
source4/lib/ldb/modules/ldb_map.c
source4/lib/ldb/modules/rdn_name.c
source4/lib/ldb/modules/schema.c
source4/lib/ldb/modules/skel.c
source4/lib/ldb/modules/timestamps.c
source4/lib/ldb/tools/ldbadd.c
source4/nbt_server/wins/winsdb.c

index 2a27398fbc04e5424ba139438462e22b541dd23a..bdef4d51478167f46cff8e6de2df72f09265075d 100644 (file)
@@ -145,10 +145,16 @@ static int objectguid_start_trans(struct ldb_module *module)
        return ldb_next_start_trans(module);
 }
 
-static int objectguid_end_trans(struct ldb_module *module, int status)
+static int objectguid_end_trans(struct ldb_module *module)
 {
        ldb_debug(module->ldb, LDB_DEBUG_TRACE, "objectguid_end_trans\n");
-       return ldb_next_end_trans(module, status);
+       return ldb_next_end_trans(module);
+}
+
+static int objectguid_del_trans(struct ldb_module *module)
+{
+       ldb_debug(module->ldb, LDB_DEBUG_TRACE, "objectguid_del_trans\n");
+       return ldb_next_del_trans(module);
 }
 
 static int objectguid_destructor(void *module_ctx)
@@ -167,7 +173,8 @@ static const struct ldb_module_ops objectguid_ops = {
        .delete_record = objectguid_delete_record,
        .rename_record = objectguid_rename_record,
        .start_transaction = objectguid_start_trans,
-       .end_transaction = objectguid_end_trans
+       .end_transaction = objectguid_end_trans,
+       .del_transaction = objectguid_del_trans
 };
 
 
index 18c7b27be3e68ee7c74a35f35c43024b6b9ce00e..28e56fe0cace48f6b65a0ea9c86b8e302f95b3b1 100644 (file)
@@ -581,10 +581,16 @@ static int samldb_start_trans(struct ldb_module *module)
        return ldb_next_start_trans(module);
 }
 
-static int samldb_end_trans(struct ldb_module *module, int status)
+static int samldb_end_trans(struct ldb_module *module)
 {
        ldb_debug(module->ldb, LDB_DEBUG_TRACE, "samldb_end_trans\n");
-       return ldb_next_end_trans(module, status);
+       return ldb_next_end_trans(module);
+}
+
+static int samldb_del_trans(struct ldb_module *module)
+{
+       ldb_debug(module->ldb, LDB_DEBUG_TRACE, "samldb_del_trans\n");
+       return ldb_next_del_trans(module);
 }
 
 static int samldb_destructor(void *module_ctx)
@@ -603,7 +609,8 @@ static const struct ldb_module_ops samldb_ops = {
        .delete_record = samldb_delete_record,
        .rename_record = samldb_rename_record,
        .start_transaction = samldb_start_trans,
-       .end_transaction = samldb_end_trans
+       .end_transaction = samldb_end_trans,
+       .del_transaction = samldb_del_trans
 };
 
 
index a00c2481d8a7edea487d7f3ad22455dcf53dbce1..a743b2f5844ba7f63f263a03f1e97a921931d247 100644 (file)
@@ -93,17 +93,17 @@ int ldb_connect(struct ldb_context *ldb, const char *url, unsigned int flags, co
                return LDB_ERR_OTHER;
        }
 
-       if (ret != LDB_ERR_SUCCESS) {
+       if (ret != LDB_SUCCESS) {
                ldb_debug(ldb, LDB_DEBUG_ERROR, "Failed to connect to '%s'\n", url);
                return ret;
        }
 
-       if (ldb_load_modules(ldb, options) != LDB_ERR_SUCCESS) {
+       if (ldb_load_modules(ldb, options) != LDB_SUCCESS) {
                ldb_debug(ldb, LDB_DEBUG_FATAL, "Unable to load modules for '%s'\n", url);
                return LDB_ERR_OTHER;
        }
 
-       return LDB_ERR_SUCCESS;
+       return LDB_SUCCESS;
 }
 
 static void ldb_reset_err_string(struct ldb_context *ldb)
@@ -117,17 +117,45 @@ static void ldb_reset_err_string(struct ldb_context *ldb)
 /*
   start a transaction
 */
-static int ldb_start_trans(struct ldb_context *ldb)
+int ldb_transaction_start(struct ldb_context *ldb)
 {
-        return ldb->modules->ops->start_transaction(ldb->modules);
+       ldb->transaction_active++;
+
+       ldb_reset_err_string(ldb);
+
+       return ldb->modules->ops->start_transaction(ldb->modules);
 }
 
 /*
-  end a transaction
+  commit a transaction
 */
-static int ldb_end_trans(struct ldb_context *ldb, int status)
+int ldb_transaction_commit(struct ldb_context *ldb)
 {
-        return ldb->modules->ops->end_transaction(ldb->modules, status);
+       if (ldb->transaction_active > 0) {
+               ldb->transaction_active--;
+       } else {
+               return LDB_ERR_OPERATIONS_ERROR;
+       }
+
+       ldb_reset_err_string(ldb);
+
+       return ldb->modules->ops->end_transaction(ldb->modules);
+}
+
+/*
+  cancel a transaction
+*/
+int ldb_transaction_cancel(struct ldb_context *ldb)
+{
+       if (ldb->transaction_active > 0) {
+               ldb->transaction_active--;
+       } else {
+               return LDB_ERR_OPERATIONS_ERROR;
+       }
+
+       ldb_reset_err_string(ldb);
+
+       return ldb->modules->ops->del_transaction(ldb->modules);
 }
 
 /*
@@ -180,13 +208,18 @@ int ldb_add(struct ldb_context *ldb,
        ldb_reset_err_string(ldb);
 
        status = ldb_msg_sanity_check(message);
-       if (status != LDB_ERR_SUCCESS) return status;
+       if (status != LDB_SUCCESS) return status;
 
-       status = ldb_start_trans(ldb);
-       if (status != LDB_ERR_SUCCESS) return status;
+       if (! ldb->transaction_active) {
+               status = ldb_transaction_start(ldb);
+               if (status != LDB_SUCCESS) return status;
 
-       status = ldb->modules->ops->add_record(ldb->modules, message);
-       return ldb_end_trans(ldb, status);
+               status = ldb->modules->ops->add_record(ldb->modules, message);
+               if (status != LDB_SUCCESS) return ldb_transaction_cancel(ldb);
+               return ldb_transaction_commit(ldb);
+       }
+
+       return ldb->modules->ops->add_record(ldb->modules, message);
 }
 
 /*
@@ -200,13 +233,18 @@ int ldb_modify(struct ldb_context *ldb,
        ldb_reset_err_string(ldb);
 
        status = ldb_msg_sanity_check(message);
-       if (status != LDB_ERR_SUCCESS) return status;
+       if (status != LDB_SUCCESS) return status;
+
+       if (! ldb->transaction_active) {
+               status = ldb_transaction_start(ldb);
+               if (status != LDB_SUCCESS) return status;
 
-       status = ldb_start_trans(ldb);
-       if (status != LDB_ERR_SUCCESS) return status;
+               status = ldb->modules->ops->modify_record(ldb->modules, message);
+               if (status != LDB_SUCCESS) return ldb_transaction_cancel(ldb);
+               return ldb_transaction_commit(ldb);
+       }
 
-       status = ldb->modules->ops->modify_record(ldb->modules, message);
-       return ldb_end_trans(ldb, status);
+       return ldb->modules->ops->modify_record(ldb->modules, message);
 }
 
 
@@ -219,11 +257,16 @@ int ldb_delete(struct ldb_context *ldb, const struct ldb_dn *dn)
 
        ldb_reset_err_string(ldb);
 
-       status = ldb_start_trans(ldb);
-       if (status != LDB_ERR_SUCCESS) return status;
+       if (! ldb->transaction_active) {
+               status = ldb_transaction_start(ldb);
+               if (status != LDB_SUCCESS) return status;
 
-       status = ldb->modules->ops->delete_record(ldb->modules, dn);
-       return ldb_end_trans(ldb, status);
+               status = ldb->modules->ops->delete_record(ldb->modules, dn);
+               if (status != LDB_SUCCESS) return ldb_transaction_cancel(ldb);
+               return ldb_transaction_commit(ldb);
+       }
+
+       return ldb->modules->ops->delete_record(ldb->modules, dn);
 }
 
 /*
@@ -235,13 +278,20 @@ int ldb_rename(struct ldb_context *ldb, const struct ldb_dn *olddn, const struct
 
        ldb_reset_err_string(ldb);
 
-       status = ldb_start_trans(ldb);
-       if (status != LDB_ERR_SUCCESS) return status;
+       if (! ldb->transaction_active) {
+               status = ldb_transaction_start(ldb);
+               if (status != LDB_SUCCESS) return status;
+
+               status = ldb->modules->ops->rename_record(ldb->modules, olddn, newdn);
+               if (status != LDB_SUCCESS) return ldb_transaction_cancel(ldb);
+               return ldb_transaction_commit(ldb);
+       }
 
-       status = ldb->modules->ops->rename_record(ldb->modules, olddn, newdn);
-       return ldb_end_trans(ldb, status);
+       return ldb->modules->ops->rename_record(ldb->modules, olddn, newdn);
 }
 
+
+
 /*
   return extended error information 
 */
@@ -269,7 +319,7 @@ int ldb_set_opaque(struct ldb_context *ldb, const char *name, void *value)
        o->name = name;
        o->value = value;
        ldb->opaque = o;
-       return LDB_ERR_SUCCESS;
+       return LDB_SUCCESS;
 }
 
 /*
index e1f5b8308334ca7158e7ee53e8c08b9b87148157..6802cc895512ef195779819d90a6dab382e9849c 100644 (file)
@@ -314,12 +314,20 @@ int ldb_next_start_trans(struct ldb_module *module)
        return module->next->ops->start_transaction(module->next);
 }
 
-int ldb_next_end_trans(struct ldb_module *module, int status)
+int ldb_next_end_trans(struct ldb_module *module)
 {
        if (!module->next) {
                return -1;
        }
-       return module->next->ops->end_transaction(module->next, status);
+       return module->next->ops->end_transaction(module->next);
+}
+
+int ldb_next_del_trans(struct ldb_module *module)
+{
+       if (!module->next) {
+               return -1;
+       }
+       return module->next->ops->del_transaction(module->next);
 }
 
 void ldb_set_errstring(struct ldb_module *module, char *err_string)
index 1b26d7833b648bc1b9f441114ffb2c2deda5a06a..c2f40f308a67f0ee54d0a0b52e937b980516f707 100644 (file)
@@ -527,5 +527,5 @@ int ldb_msg_sanity_check(const struct ldb_message *msg)
                }
        }
 
-       return LDB_ERR_SUCCESS;
+       return LDB_SUCCESS;
 }
index 0e794c6209ee1194a29948ab0b0f715b792cfed5..f371c340cc737f73ab5173d53388c0f36f43c2d1 100644 (file)
@@ -308,6 +308,21 @@ int ldb_rename(struct ldb_context *ldb, const struct ldb_dn *olddn, const struct
 */
 int ldb_delete(struct ldb_context *ldb, const struct ldb_dn *dn);
 
+/*
+  start a transaction
+*/
+int ldb_transaction_start(struct ldb_context *ldb);
+
+/*
+  commit a transaction
+*/
+int ldb_transaction_commit(struct ldb_context *ldb);
+
+/*
+  cancel a transaction
+*/
+int ldb_transaction_cancel(struct ldb_context *ldb);
+
 
 /*
   return extended error information from the last call
index 38c42280d09c782bb8a4cabc285f521d5d9a1074..f59b39f92ad94232fcb1405c24710223b5f8decb 100644 (file)
@@ -40,7 +40,7 @@
  * but they are keept here for reference anyway
  */
 
-#define LDB_ERR_SUCCESS                                0
+#define LDB_SUCCESS                            0
 #define LDB_ERR_OPERATIONS_ERROR               1
 #define LDB_ERR_PROTOCOL_ERROR                 2
 #define LDB_ERR_TIME_LIMIT_EXCEEDED            3
index 7eb2bca679642bb677cc58ebffd1c14562ed1be4..2a9139df406898cf18202b2caca79fbc69f33816 100644 (file)
@@ -65,7 +65,8 @@ struct ldb_module_ops {
        int (*delete_record)(struct ldb_module *, const struct ldb_dn *);
        int (*rename_record)(struct ldb_module *, const struct ldb_dn *, const struct ldb_dn *);
        int (*start_transaction)(struct ldb_module *);
-       int (*end_transaction)(struct ldb_module *, int);
+       int (*end_transaction)(struct ldb_module *);
+       int (*del_transaction)(struct ldb_module *);
 };
 
 
@@ -105,6 +106,8 @@ struct ldb_context {
        struct ldb_schema schema;
 
        char *err_string;
+
+       int transaction_active;
 };
 
 /* the modules init function */
@@ -137,7 +140,8 @@ int ldb_next_modify_record(struct ldb_module *module, const struct ldb_message *
 int ldb_next_delete_record(struct ldb_module *module, const struct ldb_dn *dn);
 int ldb_next_rename_record(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn);
 int ldb_next_start_trans(struct ldb_module *module);
-int ldb_next_end_trans(struct ldb_module *module, int status);
+int ldb_next_end_trans(struct ldb_module *module);
+int ldb_next_del_trans(struct ldb_module *module);
 
 void ldb_set_errstring(struct ldb_module *module, char *err_string);
 
index be51a65c58a8bb99c1d6aef7eb929d544bc7ea78..ffb812acd0b25c6c0507f0d6b9e3a5fcf17bb83e 100644 (file)
@@ -373,11 +373,18 @@ static int ildb_start_trans(struct ldb_module *module)
        return 0;
 }
 
-static int ildb_end_trans(struct ldb_module *module, int status)
+static int ildb_end_trans(struct ldb_module *module)
 {
        /* TODO implement a local transaction mechanism here */
 
-       return status;
+       return 0;
+}
+
+static int ildb_del_trans(struct ldb_module *module)
+{
+       /* TODO implement a local locking mechanism here */
+
+       return 0;
 }
 
 static const struct ldb_module_ops ildb_ops = {
@@ -389,7 +396,8 @@ static const struct ldb_module_ops ildb_ops = {
        .delete_record     = ildb_delete,
        .rename_record     = ildb_rename,
        .start_transaction = ildb_start_trans,
-       .end_transaction   = ildb_end_trans
+       .end_transaction   = ildb_end_trans,
+       .del_transaction   = ildb_del_trans
 };
 
 
index 2035913f2ab41f758d530cffb6617a69610dcc0c..1d1dd66e84f0254e6ee200f0d1500f7b697e7086 100644 (file)
@@ -462,11 +462,18 @@ static int lldb_start_trans(struct ldb_module *module)
        return 0;
 }
 
-static int lldb_end_trans(struct ldb_module *module, int status)
+static int lldb_end_trans(struct ldb_module *module)
 {
        /* TODO implement a local transaction mechanism here */
 
-       return status;
+       return 0;
+}
+
+static int lldb_del_trans(struct ldb_module *module)
+{
+       /* TODO implement a local transaction mechanism here */
+
+       return 0;
 }
 
 static const struct ldb_module_ops lldb_ops = {
@@ -478,7 +485,8 @@ static const struct ldb_module_ops lldb_ops = {
        .delete_record     = lldb_delete,
        .rename_record     = lldb_rename,
        .start_transaction = lldb_start_trans,
-       .end_transaction   = lldb_end_trans
+       .end_transaction   = lldb_end_trans,
+       .del_transaction   = lldb_del_trans
 };
 
 
index ac706291ef911b714fb95496505f54ba5e2fac52..052b10f2459facd80254f3a99075a83796e72dbc 100644 (file)
@@ -1065,7 +1065,7 @@ static int lsqlite3_add(struct ldb_module *module, const struct ldb_message *msg
                }
 */
                 /* Others are implicitly ignored */
-                return LDB_ERR_SUCCESS;
+                return LDB_SUCCESS;
        }
 
        /* create linearized and normalized dns */
@@ -1155,7 +1155,7 @@ static int lsqlite3_add(struct ldb_module *module, const struct ldb_message *msg
        }
 
        talloc_free(local_ctx);
-        return LDB_ERR_SUCCESS;
+        return LDB_SUCCESS;
 
 failed:
        talloc_free(local_ctx);
@@ -1191,7 +1191,7 @@ static int lsqlite3_modify(struct ldb_module *module, const struct ldb_message *
                }
 
                 /* Others are implicitly ignored */
-                return LDB_ERR_SUCCESS;
+                return LDB_SUCCESS;
        }
 
        eid = lsqlite3_get_eid(module, msg->dn);
@@ -1346,7 +1346,7 @@ static int lsqlite3_modify(struct ldb_module *module, const struct ldb_message *
        }
 
        talloc_free(local_ctx);
-        return LDB_ERR_SUCCESS;
+        return LDB_SUCCESS;
 
 failed:
        talloc_free(local_ctx);
@@ -1365,7 +1365,7 @@ static int lsqlite3_delete(struct ldb_module *module, const struct ldb_dn *dn)
 
        /* ignore ltdb specials */
        if (ldb_dn_is_special(dn)) {
-               return LDB_ERR_SUCCESS;
+               return LDB_SUCCESS;
        }
 
        /* create a local ctx */
@@ -1402,7 +1402,7 @@ static int lsqlite3_delete(struct ldb_module *module, const struct ldb_dn *dn)
        }
 
        talloc_free(local_ctx);
-        return LDB_ERR_SUCCESS;
+        return LDB_SUCCESS;
 
 failed:
        talloc_free(local_ctx);
@@ -1421,7 +1421,7 @@ static int lsqlite3_rename(struct ldb_module *module, const struct ldb_dn *olddn
 
        /* ignore ltdb specials */
        if (ldb_dn_is_special(olddn) || ldb_dn_is_special(newdn)) {
-               return LDB_ERR_SUCCESS;
+               return LDB_SUCCESS;
        }
 
        /* create a local ctx */
@@ -1462,7 +1462,7 @@ static int lsqlite3_rename(struct ldb_module *module, const struct ldb_dn *olddn
 
        /* clean up and exit */
        talloc_free(local_ctx);
-        return LDB_ERR_SUCCESS;
+        return LDB_SUCCESS;
 
 failed:
        talloc_free(local_ctx);
@@ -1491,32 +1491,45 @@ static int lsqlite3_start_trans(struct ldb_module * module)
        return 0;
 }
 
-static int lsqlite3_end_trans(struct ldb_module *module, int status)
+static int lsqlite3_end_trans(struct ldb_module *module)
 {
        int ret;
        char *errmsg;
        struct lsqlite3_private *lsqlite3 = module->private_data;
 
-       lsqlite3->trans_count--;
+       if (lsqlite3->trans_count > 0) {
+               lsqlite3->trans_count--;
+       } else return -1;
 
        if (lsqlite3->trans_count == 0) {
-               if (status == 0) {
-                       ret = sqlite3_exec(lsqlite3->sqlite, "COMMIT;", NULL, NULL, &errmsg);
-                       if (ret != SQLITE_OK) {
-                               if (errmsg) {
-                                       printf("lsqlite3_end_trans: error: %s\n", errmsg);
-                                       free(errmsg);
-                               }
-                               return -1;
+               ret = sqlite3_exec(lsqlite3->sqlite, "COMMIT;", NULL, NULL, &errmsg);
+               if (ret != SQLITE_OK) {
+                       if (errmsg) {
+                               printf("lsqlite3_end_trans: error: %s\n", errmsg);
+                               free(errmsg);
                        }
-               } else {
-                       return lsqlite3_safe_rollback(lsqlite3->sqlite);
+                       return -1;
                }
        }
 
         return 0;
 }
 
+static int lsqlite3_del_trans(struct ldb_module *module)
+{
+       struct lsqlite3_private *lsqlite3 = module->private_data;
+
+       if (lsqlite3->trans_count > 0) {
+               lsqlite3->trans_count--;
+       } else return -1;
+
+       if (lsqlite3->trans_count == 0) {
+               return lsqlite3_safe_rollback(lsqlite3->sqlite);
+       }
+
+       return -1;
+}
+
 /*
  * Static functions
  */
@@ -1814,7 +1827,8 @@ static const struct ldb_module_ops lsqlite3_ops = {
        .delete_record     = lsqlite3_delete,
        .rename_record     = lsqlite3_rename,
        .start_transaction = lsqlite3_start_trans,
-       .end_transaction   = lsqlite3_end_trans
+       .end_transaction   = lsqlite3_end_trans,
+       .del_transaction   = lsqlite3_del_trans
 };
 
 /*
index d8a03c3f559a32f4ede3be9953f94b4d535765cb..701ed602cec94694d5db277eb658843cc83c3924 100644 (file)
@@ -193,7 +193,7 @@ static int ltdb_add(struct ldb_module *module, const struct ldb_message *msg)
        int ret;
 
        ret = ltdb_check_special_dn(module, msg);
-       if (ret != LDB_ERR_SUCCESS) {
+       if (ret != LDB_SUCCESS) {
                return ret;
        }
        
@@ -203,7 +203,7 @@ static int ltdb_add(struct ldb_module *module, const struct ldb_message *msg)
 
        ret = ltdb_store(module, msg, TDB_INSERT);
 
-       if (ret == LDB_ERR_SUCCESS) {
+       if (ret == LDB_SUCCESS) {
                ltdb_modified(module, msg->dn);
        }
 
@@ -261,13 +261,13 @@ static int ltdb_delete(struct ldb_module *module, const struct ldb_dn *dn)
        }
 
        ret = ltdb_delete_noindex(module, dn);
-       if (ret != LDB_ERR_SUCCESS) {
+       if (ret != LDB_SUCCESS) {
                goto failed;
        }
 
        /* remove any indexed attributes */
        ret = ltdb_index_del(module, msg);
-       if (ret == LDB_ERR_SUCCESS) {
+       if (ret == LDB_SUCCESS) {
                ltdb_modified(module, dn);
        } else
                ret = LDB_ERR_OTHER;
@@ -605,7 +605,7 @@ static int ltdb_modify(struct ldb_module *module, const struct ldb_message *msg)
 
        ret = ltdb_modify_internal(module, msg);
 
-       if (ret == LDB_ERR_SUCCESS) {
+       if (ret == LDB_SUCCESS) {
                ltdb_modified(module, msg->dn);
        }
 
@@ -646,13 +646,13 @@ static int ltdb_rename(struct ldb_module *module, const struct ldb_dn *olddn, co
        }
 
        ret = ltdb_add(module, msg);
-       if (ret != LDB_ERR_SUCCESS) {
+       if (ret != LDB_SUCCESS) {
                goto failed;
        }
 
        ret = ltdb_delete(module, olddn);
        error_str = talloc_strdup(module, ldb_errstring(module->ldb));
-       if (ret != LDB_ERR_SUCCESS) {
+       if (ret != LDB_SUCCESS) {
                ltdb_delete(module, newdn);
        }
 
@@ -675,24 +675,29 @@ static int ltdb_start_trans(struct ldb_module *module)
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
-       return LDB_ERR_SUCCESS;
+       return LDB_SUCCESS;
 }
 
-static int ltdb_end_trans(struct ldb_module *module, int status)
+static int ltdb_end_trans(struct ldb_module *module)
 {
        struct ltdb_private *ltdb = module->private_data;
 
-       if (status != LDB_ERR_SUCCESS) {
-               if (tdb_transaction_cancel(ltdb->tdb) != 0) {
-                       return LDB_ERR_OPERATIONS_ERROR;
-               }
-       } else {
-               if (tdb_transaction_commit(ltdb->tdb) != 0) {
-                       return LDB_ERR_OPERATIONS_ERROR;
-               }
+       if (tdb_transaction_commit(ltdb->tdb) != 0) {
+               return LDB_ERR_OPERATIONS_ERROR;
+       }
+
+       return LDB_SUCCESS;
+}
+
+static int ltdb_del_trans(struct ldb_module *module)
+{
+       struct ltdb_private *ltdb = module->private_data;
+
+       if (tdb_transaction_cancel(ltdb->tdb) != 0) {
+               return LDB_ERR_OPERATIONS_ERROR;
        }
 
-       return status;
+       return LDB_SUCCESS;
 }
 
 static const struct ldb_module_ops ltdb_ops = {
@@ -704,7 +709,8 @@ static const struct ldb_module_ops ltdb_ops = {
        .delete_record     = ltdb_delete,
        .rename_record     = ltdb_rename,
        .start_transaction = ltdb_start_trans,
-       .end_transaction   = ltdb_end_trans
+       .end_transaction   = ltdb_end_trans,
+       .del_transaction   = ltdb_del_trans
 };
 
 
index 69e021b4ee21ec8d21e0bf43fe55f5a1ad805e75..1133991ac442cfe711dfcb67ea8a844792dfaf53 100644 (file)
@@ -1258,9 +1258,14 @@ static int map_start_trans(struct ldb_module *module)
        return ldb_next_start_trans(module);
 }
 
-static int map_end_trans(struct ldb_module *module, int status)
+static int map_end_trans(struct ldb_module *module)
 {
-       return ldb_next_end_trans(module, status);
+       return ldb_next_end_trans(module);
+}
+
+static int map_del_trans(struct ldb_module *module)
+{
+       return ldb_next_del_trans(module);
 }
 
 static const struct ldb_module_ops map_ops = {
@@ -1272,7 +1277,8 @@ static const struct ldb_module_ops map_ops = {
        .delete_record     = map_delete,
        .rename_record     = map_rename,
        .start_transaction = map_start_trans,
-       .end_transaction   = map_end_trans
+       .end_transaction   = map_end_trans,
+       .del_transaction   = map_del_trans
 };
 
 static char *map_find_url(struct ldb_context *ldb, const char *name)
index c1a0c0852a457759fec89ac91565970929254db6..3e3fbd544f29f6945869a8fc805a76c5060f107e 100644 (file)
@@ -220,10 +220,16 @@ static int rdn_start_trans(struct ldb_module *module)
        return ldb_next_start_trans(module);
 }
 
-static int rdn_end_trans(struct ldb_module *module, int status)
+static int rdn_end_trans(struct ldb_module *module)
 {
        ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_end_trans\n");
-       return ldb_next_end_trans(module, status);
+       return ldb_next_end_trans(module);
+}
+
+static int rdn_del_trans(struct ldb_module *module)
+{
+       ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_del_trans\n");
+       return ldb_next_del_trans(module);
 }
 
 static int rdn_name_destructor(void *module_ctx)
@@ -242,7 +248,8 @@ static const struct ldb_module_ops rdn_name_ops = {
        .delete_record     = rdn_name_delete_record,
        .rename_record     = rdn_name_rename_record,
        .start_transaction = rdn_start_trans,
-       .end_transaction   = rdn_end_trans
+       .end_transaction   = rdn_end_trans,
+       .del_transaction   = rdn_del_trans
 };
 
 
index 1a2c2b8f978d908deb15c754917caa6d2ad4d0a0..e882f72bd495e8b903fafe07444f4d20b897a033 100644 (file)
@@ -520,8 +520,12 @@ static int schema_start_trans(struct ldb_module *module) {
        return ldb_next_start_trans(module);
 }
 
-static int schema_end_trans(struct ldb_module *module, int status) {
-       return ldb_next_end_trans(module, status);
+static int schema_end_trans(struct ldb_module *module) {
+       return ldb_next_end_trans(module);
+}
+
+static int schema_del_trans(struct ldb_module *module) {
+       return ldb_next_del_trans(module);
 }
 
 static int schema_destructor(void *module_ctx)
@@ -540,7 +544,8 @@ static const struct ldb_module_ops schema_ops = {
        .delete_record     = schema_delete_record,
        .rename_record     = schema_rename_record,
        .start_transaction = schema_start_trans,
-       .end_transaction   = schema_end_trans
+       .end_transaction   = schema_end_trans,
+       .del_transaction   = schema_del_trans
 };
 
 #ifdef HAVE_DLOPEN_DISABLED
index 701128cd2712948517ce713dbcb676d8d95f1221..5d14a27a7b68fb4c620e6ec78169a9419386665f 100644 (file)
@@ -80,9 +80,15 @@ static int skel_start_trans(struct ldb_module *module)
 }
 
 /* end a transaction */
-static int skel_end_trans(struct ldb_module *module, int status)
+static int skel_end_trans(struct ldb_module *module)
 {
-       return ldb_next_end_trans(module, status);
+       return ldb_next_end_trans(module);
+}
+
+/* delete a transaction */
+static int skel_del_trans(struct ldb_module *module)
+{
+       return ldb_next_del_trans(module);
 }
 
 static int skel_destructor(void *module_ctx)
@@ -104,6 +110,7 @@ static const struct ldb_module_ops skel_ops = {
        .rename_record     = skel_rename_record,
        .start_transaction = skel_start_trans,
        .end_transaction   = skel_end_trans,
+       .del_transaction   = skel_del_trans,
 };
 
 #ifdef HAVE_DLOPEN_DISABLED
index dc91937f857bb644b4db5d7be364a15436f051fc..01e5c2c37cc6b6f8728c93fa83f164d928703b57 100644 (file)
@@ -217,10 +217,16 @@ static int timestamps_start_trans(struct ldb_module *module)
        return ldb_next_start_trans(module);
 }
 
-static int timestamps_end_trans(struct ldb_module *module, int status)
+static int timestamps_end_trans(struct ldb_module *module)
 {
        ldb_debug(module->ldb, LDB_DEBUG_TRACE, "timestamps_end_trans\n");
-       return ldb_next_end_trans(module, status);
+       return ldb_next_end_trans(module);
+}
+
+static int timestamps_del_trans(struct ldb_module *module)
+{
+       ldb_debug(module->ldb, LDB_DEBUG_TRACE, "timestamps_del_trans\n");
+       return ldb_next_del_trans(module);
 }
 
 static int timestamps_destructor(void *module_ctx)
@@ -239,7 +245,8 @@ static const struct ldb_module_ops timestamps_ops = {
        .delete_record     = timestamps_delete_record,
        .rename_record     = timestamps_rename_record,
        .start_transaction = timestamps_start_trans,
-       .end_transaction   = timestamps_end_trans
+       .end_transaction   = timestamps_end_trans,
+       .del_transaction   = timestamps_del_trans
 };
 
 
index ba58f782f09e72d9429563a8594408ac5c3ace01..058f4dc751b0770b7db7e65a1946a90639caf591 100644 (file)
@@ -75,7 +75,7 @@ static int process_file(struct ldb_context *ldb, FILE *f)
                ldif->msg = ldb_msg_canonicalize(ldb, ldif->msg);
 
                ret = ldb_add(ldb, ldif->msg);
-               if (ret != LDB_ERR_SUCCESS) {
+               if (ret != LDB_SUCCESS) {
                        fprintf(stderr, "ERR: \"%s\" on DN %s\n", 
                                ldb_errstring(ldb), ldb_dn_linearize(ldb, ldif->msg->dn));
                        failures++;
index 75d08227d96b046615e3f9b36a35e8b71cc28e6d..88433795eadfc7c2e59da9c302ca40d7d4e61f5c 100644 (file)
@@ -24,6 +24,7 @@
 #include "nbt_server/nbt_server.h"
 #include "nbt_server/wins/winsdb.h"
 #include "lib/ldb/include/ldb.h"
+#include "lib/ldb/include/ldb_errors.h"
 #include "db_wrap.h"
 #include "system/time.h"
 
@@ -75,12 +76,14 @@ static uint64_t winsdb_allocate_version(struct wins_server *winssrv)
 /*
   remove a version id
 */
-static void winsdb_remove_version(struct wins_server *winssrv, uint64_t version)
+static BOOL winsdb_remove_version(struct wins_server *winssrv, uint64_t version)
 {
        if (version == winssrv->min_version) {
                winssrv->min_version++;
-               winsdb_save_version(winssrv);
+               return winsdb_save_version(winssrv);
        }
+
+       return True;
 }
 
 
@@ -205,7 +208,12 @@ uint8_t winsdb_add(struct wins_server *winssrv, struct winsdb_record *rec)
        struct ldb_context *ldb = winssrv->wins_db;
        struct ldb_message *msg;
        TALLOC_CTX *tmp_ctx = talloc_new(winssrv);
-       int ret;
+       int trans = -1;
+       int ret = 0;
+
+
+       trans = ldb_transaction_start(ldb);
+       if (trans != LDB_SUCCESS) goto failed;
 
        rec->version = winsdb_allocate_version(winssrv);
        if (rec->version == 0) goto failed;
@@ -215,10 +223,14 @@ uint8_t winsdb_add(struct wins_server *winssrv, struct winsdb_record *rec)
        ret = ldb_add(ldb, msg);
        if (ret != 0) goto failed;
 
+       trans = ldb_transaction_commit(ldb);
+       if (trans != LDB_SUCCESS) goto failed;
+
        talloc_free(tmp_ctx);
        return NBT_RCODE_OK;
 
 failed:
+       if (trans == LDB_SUCCESS) ldb_transaction_cancel(ldb);
        talloc_free(tmp_ctx);
        return NBT_RCODE_SVR;
 }
@@ -232,9 +244,13 @@ uint8_t winsdb_modify(struct wins_server *winssrv, struct winsdb_record *rec)
        struct ldb_context *ldb = winssrv->wins_db;
        struct ldb_message *msg;
        TALLOC_CTX *tmp_ctx = talloc_new(winssrv);
+       int trans;
        int ret;
        int i;
 
+       trans = ldb_transaction_start(ldb);
+       if (trans != LDB_SUCCESS) goto failed;
+
        rec->version = winsdb_allocate_version(winssrv);
        if (rec->version == 0) goto failed;
 
@@ -248,10 +264,14 @@ uint8_t winsdb_modify(struct wins_server *winssrv, struct winsdb_record *rec)
        ret = ldb_modify(ldb, msg);
        if (ret != 0) goto failed;
 
+       trans = ldb_transaction_commit(ldb);
+       if (trans != LDB_SUCCESS) goto failed;
+
        talloc_free(tmp_ctx);
        return NBT_RCODE_OK;
 
 failed:
+       if (trans == LDB_SUCCESS) ldb_transaction_cancel(ldb);
        talloc_free(tmp_ctx);
        return NBT_RCODE_SVR;
 }
@@ -264,10 +284,15 @@ uint8_t winsdb_delete(struct wins_server *winssrv, struct winsdb_record *rec)
 {
        struct ldb_context *ldb = winssrv->wins_db;
        TALLOC_CTX *tmp_ctx = talloc_new(winssrv);
-       int ret;
        const struct ldb_dn *dn;
+       int trans;
+       int ret;
+
+       trans = ldb_transaction_start(ldb);
+       if (trans != LDB_SUCCESS) goto failed;
 
-       winsdb_remove_version(winssrv, rec->version);
+       if(!winsdb_remove_version(winssrv, rec->version))
+               goto failed;
 
        dn = winsdb_dn(tmp_ctx, rec->name);
        if (dn == NULL) goto failed;
@@ -275,10 +300,14 @@ uint8_t winsdb_delete(struct wins_server *winssrv, struct winsdb_record *rec)
        ret = ldb_delete(ldb, dn);
        if (ret != 0) goto failed;
 
+       trans = ldb_transaction_commit(ldb);
+       if (trans != LDB_SUCCESS) goto failed;
+
        talloc_free(tmp_ctx);
        return NBT_RCODE_OK;
 
 failed:
+       if (trans == LDB_SUCCESS) ldb_transaction_cancel(ldb);
        talloc_free(tmp_ctx);
        return NBT_RCODE_SVR;
 }