summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source4/dsdb/samdb/ldb_modules/objectguid.c13
-rw-r--r--source4/dsdb/samdb/ldb_modules/samldb.c13
-rw-r--r--source4/lib/ldb/common/ldb.c104
-rw-r--r--source4/lib/ldb/common/ldb_modules.c12
-rw-r--r--source4/lib/ldb/common/ldb_msg.c2
-rw-r--r--source4/lib/ldb/include/ldb.h15
-rw-r--r--source4/lib/ldb/include/ldb_errors.h2
-rw-r--r--source4/lib/ldb/include/ldb_private.h8
-rw-r--r--source4/lib/ldb/ldb_ildap/ldb_ildap.c14
-rw-r--r--source4/lib/ldb/ldb_ldap/ldb_ldap.c14
-rw-r--r--source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c56
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_tdb.c44
-rw-r--r--source4/lib/ldb/modules/ldb_map.c12
-rw-r--r--source4/lib/ldb/modules/rdn_name.c13
-rw-r--r--source4/lib/ldb/modules/schema.c11
-rw-r--r--source4/lib/ldb/modules/skel.c11
-rw-r--r--source4/lib/ldb/modules/timestamps.c13
-rw-r--r--source4/lib/ldb/tools/ldbadd.c2
-rw-r--r--source4/nbt_server/wins/winsdb.c39
19 files changed, 293 insertions, 105 deletions
diff --git a/source4/dsdb/samdb/ldb_modules/objectguid.c b/source4/dsdb/samdb/ldb_modules/objectguid.c
index 2a27398fbc..bdef4d5147 100644
--- a/source4/dsdb/samdb/ldb_modules/objectguid.c
+++ b/source4/dsdb/samdb/ldb_modules/objectguid.c
@@ -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
};
diff --git a/source4/dsdb/samdb/ldb_modules/samldb.c b/source4/dsdb/samdb/ldb_modules/samldb.c
index 18c7b27be3..28e56fe0ca 100644
--- a/source4/dsdb/samdb/ldb_modules/samldb.c
+++ b/source4/dsdb/samdb/ldb_modules/samldb.c
@@ -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
};
diff --git a/source4/lib/ldb/common/ldb.c b/source4/lib/ldb/common/ldb.c
index a00c2481d8..a743b2f584 100644
--- a/source4/lib/ldb/common/ldb.c
+++ b/source4/lib/ldb/common/ldb.c
@@ -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;
}
/*
diff --git a/source4/lib/ldb/common/ldb_modules.c b/source4/lib/ldb/common/ldb_modules.c
index e1f5b83083..6802cc8955 100644
--- a/source4/lib/ldb/common/ldb_modules.c
+++ b/source4/lib/ldb/common/ldb_modules.c
@@ -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)
diff --git a/source4/lib/ldb/common/ldb_msg.c b/source4/lib/ldb/common/ldb_msg.c
index 1b26d7833b..c2f40f308a 100644
--- a/source4/lib/ldb/common/ldb_msg.c
+++ b/source4/lib/ldb/common/ldb_msg.c
@@ -527,5 +527,5 @@ int ldb_msg_sanity_check(const struct ldb_message *msg)
}
}
- return LDB_ERR_SUCCESS;
+ return LDB_SUCCESS;
}
diff --git a/source4/lib/ldb/include/ldb.h b/source4/lib/ldb/include/ldb.h
index 0e794c6209..f371c340cc 100644
--- a/source4/lib/ldb/include/ldb.h
+++ b/source4/lib/ldb/include/ldb.h
@@ -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
diff --git a/source4/lib/ldb/include/ldb_errors.h b/source4/lib/ldb/include/ldb_errors.h
index 38c42280d0..f59b39f92a 100644
--- a/source4/lib/ldb/include/ldb_errors.h
+++ b/source4/lib/ldb/include/ldb_errors.h
@@ -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
diff --git a/source4/lib/ldb/include/ldb_private.h b/source4/lib/ldb/include/ldb_private.h
index 7eb2bca679..2a9139df40 100644
--- a/source4/lib/ldb/include/ldb_private.h
+++ b/source4/lib/ldb/include/ldb_private.h
@@ -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);
diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c
index be51a65c58..ffb812acd0 100644
--- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c
+++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c
@@ -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
};
diff --git a/source4/lib/ldb/ldb_ldap/ldb_ldap.c b/source4/lib/ldb/ldb_ldap/ldb_ldap.c
index 2035913f2a..1d1dd66e84 100644
--- a/source4/lib/ldb/ldb_ldap/ldb_ldap.c
+++ b/source4/lib/ldb/ldb_ldap/ldb_ldap.c
@@ -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
};
diff --git a/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c b/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c
index ac706291ef..052b10f245 100644
--- a/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c
+++ b/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c
@@ -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
};
/*
diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c
index d8a03c3f55..701ed602ce 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c
@@ -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
};
diff --git a/source4/lib/ldb/modules/ldb_map.c b/source4/lib/ldb/modules/ldb_map.c
index 69e021b4ee..1133991ac4 100644
--- a/source4/lib/ldb/modules/ldb_map.c
+++ b/source4/lib/ldb/modules/ldb_map.c
@@ -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)
diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c
index c1a0c0852a..3e3fbd544f 100644
--- a/source4/lib/ldb/modules/rdn_name.c
+++ b/source4/lib/ldb/modules/rdn_name.c
@@ -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
};
diff --git a/source4/lib/ldb/modules/schema.c b/source4/lib/ldb/modules/schema.c
index 1a2c2b8f97..e882f72bd4 100644
--- a/source4/lib/ldb/modules/schema.c
+++ b/source4/lib/ldb/modules/schema.c
@@ -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
diff --git a/source4/lib/ldb/modules/skel.c b/source4/lib/ldb/modules/skel.c
index 701128cd27..5d14a27a7b 100644
--- a/source4/lib/ldb/modules/skel.c
+++ b/source4/lib/ldb/modules/skel.c
@@ -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
diff --git a/source4/lib/ldb/modules/timestamps.c b/source4/lib/ldb/modules/timestamps.c
index dc91937f85..01e5c2c37c 100644
--- a/source4/lib/ldb/modules/timestamps.c
+++ b/source4/lib/ldb/modules/timestamps.c
@@ -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
};
diff --git a/source4/lib/ldb/tools/ldbadd.c b/source4/lib/ldb/tools/ldbadd.c
index ba58f782f0..058f4dc751 100644
--- a/source4/lib/ldb/tools/ldbadd.c
+++ b/source4/lib/ldb/tools/ldbadd.c
@@ -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++;
diff --git a/source4/nbt_server/wins/winsdb.c b/source4/nbt_server/wins/winsdb.c
index 75d08227d9..88433795ea 100644
--- a/source4/nbt_server/wins/winsdb.c
+++ b/source4/nbt_server/wins/winsdb.c
@@ -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;
}