return 0;
}
+/*
+ start a transaction
+*/
+static int ldb_start_trans(struct ldb_context *ldb)
+{
+ return ldb->modules->ops->start_transaction(ldb->modules);
+}
+
+/*
+ end a transaction
+*/
+static int ldb_end_trans(struct ldb_context *ldb, int status)
+{
+ return ldb->modules->ops->end_transaction(ldb->modules, status);
+}
+
/*
search the database given a LDAP-like search expression
int ldb_add(struct ldb_context *ldb,
const struct ldb_message *message)
{
- return ldb->modules->ops->add_record(ldb->modules, message);
+ int status = ldb_start_trans(ldb);
+ if (status != 0) return status;
+
+ status = ldb->modules->ops->add_record(ldb->modules, message);
+ return ldb_end_trans(ldb, status);
}
/*
int ldb_modify(struct ldb_context *ldb,
const struct ldb_message *message)
{
- return ldb->modules->ops->modify_record(ldb->modules, message);
+ int status = ldb_start_trans(ldb);
+ if (status != 0) return status;
+
+ status = ldb->modules->ops->modify_record(ldb->modules, message);
+ return ldb_end_trans(ldb, status);
}
*/
int ldb_delete(struct ldb_context *ldb, const struct ldb_dn *dn)
{
- return ldb->modules->ops->delete_record(ldb->modules, dn);
+ int status = ldb_start_trans(ldb);
+ if (status != 0) return status;
+
+ status = ldb->modules->ops->delete_record(ldb->modules, dn);
+ return ldb_end_trans(ldb, status);
}
/*
*/
int ldb_rename(struct ldb_context *ldb, const struct ldb_dn *olddn, const struct ldb_dn *newdn)
{
- return ldb->modules->ops->rename_record(ldb->modules, olddn, newdn);
-}
+ int status = ldb_start_trans(ldb);
+ if (status != 0) return status;
-/*
- create a named lock
-*/
-int ldb_lock(struct ldb_context *ldb, const char *lockname)
-{
- return ldb->modules->ops->named_lock(ldb->modules, lockname);
-}
-
-/*
- release a named lock
-*/
-int ldb_unlock(struct ldb_context *ldb, const char *lockname)
-{
- return ldb->modules->ops->named_unlock(ldb->modules, lockname);
+ status = ldb->modules->ops->rename_record(ldb->modules, olddn, newdn);
+ return ldb_end_trans(ldb, status);
}
/*
return module->next->ops->rename_record(module->next, olddn, newdn);
}
-int ldb_next_named_lock(struct ldb_module *module, const char *lockname)
+int ldb_next_start_trans(struct ldb_module *module)
{
if (!module->next) {
return -1;
}
- return module->next->ops->named_lock(module->next, lockname);
+ return module->next->ops->start_transaction(module->next);
}
-int ldb_next_named_unlock(struct ldb_module *module, const char *lockname)
+int ldb_next_end_trans(struct ldb_module *module, int status)
{
if (!module->next) {
return -1;
}
- return module->next->ops->named_unlock(module->next, lockname);
+ return module->next->ops->end_transaction(module->next, status);
}
const char *ldb_next_errstring(struct ldb_module *module)
int (*modify_record)(struct ldb_module *, const struct ldb_message *);
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 (*named_lock)(struct ldb_module *, const char *);
- int (*named_unlock)(struct ldb_module *, const char *);
+ int (*start_transaction)(struct ldb_module *);
+ int (*end_transaction)(struct ldb_module *, int);
const char * (*errstring)(struct ldb_module *);
};
int ldb_next_modify_record(struct ldb_module *module, const struct ldb_message *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_named_lock(struct ldb_module *module, const char *lockname);
-int ldb_next_named_unlock(struct ldb_module *module, const char *lockname);
+int ldb_next_start_trans(struct ldb_module *module);
+int ldb_next_end_trans(struct ldb_module *module, int status);
const char *ldb_next_errstring(struct ldb_module *module);
/* The following definitions come from lib/ldb/common/ldb_debug.c */
return ret;
}
-static int ildb_lock(struct ldb_module *module, const char *lockname)
+static int ildb_start_trans(struct ldb_module *module)
{
- int ret = 0;
-
- if (lockname == NULL) {
- return -1;
- }
-
/* TODO implement a local locking mechanism here */
- return ret;
+ return 0;
}
-static int ildb_unlock(struct ldb_module *module, const char *lockname)
+static int ildb_end_trans(struct ldb_module *module, int status)
{
- int ret = 0;
-
- if (lockname == NULL) {
- return -1;
- }
-
- /* TODO implement a local unlocking mechanism here */
+ /* TODO implement a local transaction mechanism here */
- return ret;
+ return status;
}
/*
static const struct ldb_module_ops ildb_ops = {
- .name = "ldap",
- .search = ildb_search,
- .search_bytree = ildb_search_bytree,
- .add_record = ildb_add,
- .modify_record = ildb_modify,
- .delete_record = ildb_delete,
- .rename_record = ildb_rename,
- .named_lock = ildb_lock,
- .named_unlock = ildb_unlock,
- .errstring = ildb_errstring
+ .name = "ldap",
+ .search = ildb_search,
+ .search_bytree = ildb_search_bytree,
+ .add_record = ildb_add,
+ .modify_record = ildb_modify,
+ .delete_record = ildb_delete,
+ .rename_record = ildb_rename,
+ .start_transaction = ildb_start_trans,
+ .end_transaction = ildb_end_trans,
+ .errstring = ildb_errstring
};
return ret;
}
-static int lldb_lock(struct ldb_module *module, const char *lockname)
+static int lldb_start_trans(struct ldb_module *module)
{
- int ret = 0;
-
- if (lockname == NULL) {
- return -1;
- }
+ /* TODO implement a local transaction mechanism here */
- /* TODO implement a local locking mechanism here */
-
- return ret;
+ return 0;
}
-static int lldb_unlock(struct ldb_module *module, const char *lockname)
+static int lldb_end_trans(struct ldb_module *module, int status)
{
- int ret = 0;
-
- if (lockname == NULL) {
- return -1;
- }
-
- /* TODO implement a local unlocking mechanism here */
+ /* TODO implement a local transaction mechanism here */
- return ret;
+ return status;
}
/*
static const struct ldb_module_ops lldb_ops = {
- .name = "ldap",
- .search = lldb_search,
- .search_bytree = lldb_search_bytree,
- .add_record = lldb_add,
- .modify_record = lldb_modify,
- .delete_record = lldb_delete,
- .rename_record = lldb_rename,
- .named_lock = lldb_lock,
- .named_unlock = lldb_unlock,
- .errstring = lldb_errstring
+ .name = "ldap",
+ .search = lldb_search,
+ .search_bytree = lldb_search_bytree,
+ .add_record = lldb_add,
+ .modify_record = lldb_modify,
+ .delete_record = lldb_delete,
+ .rename_record = lldb_rename,
+ .start_transaction = lldb_start_trans,
+ .end_transaction = lldb_end_trans,
+ .errstring = lldb_errstring
};
return NULL;
}
-/* obtain a named lock */
-static int
-lsqlite3_lock(struct ldb_module * module,
- const char * lockname)
-{
- struct lsqlite3_private * lsqlite3 = module->private_data;
-
-/* FIXME
- if (lockname == NULL) {
- return -1;
- }
-
- if (strcmp(lockname, "transaction") == 0) {
- if (lsqlite3->lock_count == 0) {
- if (query_norows(lsqlite3, "BEGIN EXCLUSIVE;") != 0) {
- return -1;
- }
- }
- ++lsqlite3->lock_count;
- }
-*/
- return 0;
-}
-
-/* release a named lock */
-static int
-lsqlite3_unlock(struct ldb_module *module,
- const char *lockname)
-{
- struct lsqlite3_private * lsqlite3 = module->private_data;
-
-/* FIXME
- if (lockname == NULL) {
- return -1;
- }
-
- if (strcmp(lockname, "transaction") == 0) {
- if (lsqlite3->lock_count == 1) {
- if (query_norows(lsqlite3, "COMMIT;") != 0) {
- query_norows(lsqlite3, "ROLLBACK;");
- }
- } else if (lsqlite3->lock_count > 0) {
- --lsqlite3->lock_count;
- }
- } else if (strcmp(lockname, "rollback") == 0) {
- query_norows(lsqlite3, "ROLLBACK;");
- }
-*/
- return 0;
-}
-
/*
* query_int()
*
ret = sqlite3_exec(sqlite, "ROLLBACK;", NULL, NULL, &errmsg);
if (ret != SQLITE_OK) {
if (errmsg) {
- printf("lsqlite3_safe_rollback: Serious Error: %s\n", errmsg);
+ printf("lsqlite3_safe_rollback: Error: %s\n", errmsg);
free(errmsg);
}
return -1;
char *dn, *ndn;
char *errmsg;
char *query;
- int rollback = 0;
int ret;
int i;
if (dn == NULL || ndn == NULL) goto failed;
query = lsqlite3_tprintf(local_ctx,
- /* Begin the transaction */
- "BEGIN EXCLUSIVE; "
/* Add new entry */
"INSERT OR ABORT INTO ldb_entry "
"('dn', 'norm_dn') "
printf("lsqlite3_add: exec error: %s\n", errmsg);
free(errmsg);
}
- lsqlite3_safe_rollback(lsqlite3->sqlite);
goto failed;
}
- rollback = 1;
eid = lsqlite3_get_eid_ndn(lsqlite3->sqlite, local_ctx, ndn);
if (eid == -1) goto failed;
}
}
- ret = sqlite3_exec(lsqlite3->sqlite, "COMMIT;", NULL, NULL, &errmsg);
- if (ret != SQLITE_OK) {
- if (errmsg) {
- printf("lsqlite3_add: commit error: %s\n", errmsg);
- free(errmsg);
- }
- goto failed;
- }
-
talloc_free(local_ctx);
return 0;
failed:
- if (rollback) lsqlite3_safe_rollback(lsqlite3->sqlite);
talloc_free(local_ctx);
return -1;
}
struct lsqlite3_private *lsqlite3 = module->private_data;
long long eid;
char *errmsg;
- int rollback = 0;
int ret;
int i;
return 0;
}
- ret = sqlite3_exec(lsqlite3->sqlite, "BEGIN EXCLUSIVE;", NULL, NULL, &errmsg);
- if (ret != SQLITE_OK) {
- if (errmsg) {
- printf("lsqlite3_modify: error: %s\n", errmsg);
- free(errmsg);
- }
- goto failed;
- }
- rollback = 1;
-
eid = lsqlite3_get_eid(module, msg->dn);
if (eid == -1) {
goto failed;
}
}
- ret = sqlite3_exec(lsqlite3->sqlite, "COMMIT;", NULL, NULL, &errmsg);
- if (ret != SQLITE_OK) {
- if (errmsg) {
- printf("lsqlite3_modify: error: %s\n", errmsg);
- free(errmsg);
- }
- goto failed;
- }
-
talloc_free(local_ctx);
return 0;
failed:
- if (rollback) lsqlite3_safe_rollback(lsqlite3->sqlite);
talloc_free(local_ctx);
return -1;
}
if (eid == -1) goto failed;
query = lsqlite3_tprintf(local_ctx,
- /* Begin the transaction */
- "BEGIN EXCLUSIVE; "
/* Delete entry */
"DELETE FROM ldb_entry WHERE eid = %lld; "
/* Delete attributes */
- "DELETE FROM ldb_attribute_values WHERE eid = %lld; "
- /* Commit */
- "COMMIT;",
+ "DELETE FROM ldb_attribute_values WHERE eid = %lld; ",
eid, eid);
if (query == NULL) goto failed;
printf("lsqlite3_delete: error getting eid: %s\n", errmsg);
free(errmsg);
}
- lsqlite3_safe_rollback(lsqlite3->sqlite);
goto failed;
}
talloc_free(local_ctx);
return -1;
}
+
+static int lsqlite3_start_trans(struct ldb_module * module)
+{
+ int ret;
+ char *errmsg;
+ struct lsqlite3_private * lsqlite3 = module->private_data;
+
+ ret = sqlite3_exec(lsqlite3->sqlite, "BEGIN IMMEDIATE;", NULL, NULL, &errmsg);
+ if (ret != SQLITE_OK) {
+ if (errmsg) {
+ printf("lsqlite3_start_trans: error: %s\n", errmsg);
+ free(errmsg);
+ }
+ return -1;
+ }
+
+ return 0;
+}
+
+static int lsqlite3_end_trans(struct ldb_module *module, int status)
+{
+ int ret;
+ char *errmsg;
+ struct lsqlite3_private *lsqlite3 = module->private_data;
+
+ 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;
+ }
+ } else {
+ return lsqlite3_safe_rollback(lsqlite3->sqlite);
+ }
+
+ return 0;
+}
+
+
+
/* return extended error information */
static const char *
lsqlite3_errstring(struct ldb_module *module)
* Table of operations for the sqlite3 backend
*/
static const struct ldb_module_ops lsqlite3_ops = {
- .name = "sqlite",
- .search = lsqlite3_search,
- .search_bytree = lsqlite3_search_bytree,
- .add_record = lsqlite3_add,
- .modify_record = lsqlite3_modify,
- .delete_record = lsqlite3_delete,
- .rename_record = lsqlite3_rename,
- .named_lock = lsqlite3_lock,
- .named_unlock = lsqlite3_unlock,
- .errstring = lsqlite3_errstring
+ .name = "sqlite",
+ .search = lsqlite3_search,
+ .search_bytree = lsqlite3_search_bytree,
+ .add_record = lsqlite3_add,
+ .modify_record = lsqlite3_modify,
+ .delete_record = lsqlite3_delete,
+ .rename_record = lsqlite3_rename,
+ .start_transaction = lsqlite3_start_trans,
+ .end_transaction = lsqlite3_end_trans,
+ .errstring = lsqlite3_errstring
};
/*
return -1;
}
+static int ltdb_start_trans(struct ldb_module *module)
+{
+ /* TODO: implement transactions */
+
+ return 0;
+}
+
+static int ltdb_end_trans(struct ldb_module *module, int status)
+{
+ /* TODO: implement transactions */
+
+ return status;
+}
/*
return extended error information
static const struct ldb_module_ops ltdb_ops = {
- .name = "tdb",
- .search = ltdb_search,
- .search_bytree = ltdb_search_bytree,
- .add_record = ltdb_add,
- .modify_record = ltdb_modify,
- .delete_record = ltdb_delete,
- .rename_record = ltdb_rename,
- .named_lock = ltdb_lock,
- .named_unlock = ltdb_unlock,
- .errstring = ltdb_errstring
+ .name = "tdb",
+ .search = ltdb_search,
+ .search_bytree = ltdb_search_bytree,
+ .add_record = ltdb_add,
+ .modify_record = ltdb_modify,
+ .delete_record = ltdb_delete,
+ .rename_record = ltdb_rename,
+ .start_transaction = ltdb_start_trans,
+ .end_transaction = ltdb_end_trans,
+ .errstring = ltdb_errstring
};
return (mp_ret == -1 || fb_ret == -1)?-1:0;
}
-static int map_lock(struct ldb_module *module, const char *lockname)
+static int map_start_trans(struct ldb_module *module)
{
- return ldb_next_named_lock(module, lockname);
+ return ldb_next_start_trans(module);
}
-static int map_unlock(struct ldb_module *module, const char *lockname)
+static int map_end_trans(struct ldb_module *module, int status)
{
- return ldb_next_named_unlock(module, lockname);
+ return ldb_next_end_trans(module, status);
}
/*
}
static const struct ldb_module_ops map_ops = {
- .name = "map",
- .search = map_search,
- .search_bytree = map_search_bytree,
- .add_record = map_add,
- .modify_record = map_modify,
- .delete_record = map_delete,
- .rename_record = map_rename,
- .named_lock = map_lock,
- .named_unlock = map_unlock,
- .errstring = map_errstring
+ .name = "map",
+ .search = map_search,
+ .search_bytree = map_search_bytree,
+ .add_record = map_add,
+ .modify_record = map_modify,
+ .delete_record = map_delete,
+ .rename_record = map_rename,
+ .start_transaction = map_start_trans,
+ .end_transaction = map_end_trans,
+ .errstring = map_errstring
};
static char *map_find_url(struct ldb_context *ldb, const char *name)
return ldb_next_rename_record(module, olddn, newdn);
}
-static int rdn_name_lock(struct ldb_module *module, const char *lockname)
+static int rdn_start_trans(struct ldb_module *module)
{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_lock\n");
- return ldb_next_named_lock(module, lockname);
+ ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_start_trans\n");
+ return ldb_next_start_trans(module);
}
-static int rdn_name_unlock(struct ldb_module *module, const char *lockname)
+static int rdn_end_trans(struct ldb_module *module, int status)
{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_unlock\n");
- return ldb_next_named_unlock(module, lockname);
+ ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_end_trans\n");
+ return ldb_next_end_trans(module, status);
}
/* return extended error information */
}
static const struct ldb_module_ops rdn_name_ops = {
- .name = "rdn_name",
- .search = rdn_name_search,
- .search_bytree = rdn_name_search_bytree,
- .add_record = rdn_name_add_record,
- .modify_record = rdn_name_modify_record,
- .delete_record = rdn_name_delete_record,
- .rename_record = rdn_name_rename_record,
- .named_lock = rdn_name_lock,
- .named_unlock = rdn_name_unlock,
- .errstring = rdn_name_errstring
+ .name = "rdn_name",
+ .search = rdn_name_search,
+ .search_bytree = rdn_name_search_bytree,
+ .add_record = rdn_name_add_record,
+ .modify_record = rdn_name_modify_record,
+ .delete_record = rdn_name_delete_record,
+ .rename_record = rdn_name_rename_record,
+ .start_transaction = rdn_start_trans,
+ .end_transaction = rdn_end_trans,
+ .errstring = rdn_name_errstring
};
return ldb_next_rename_record(module, olddn, newdn);
}
-static int schema_named_lock(struct ldb_module *module, const char *name) {
- return ldb_next_named_lock(module, name);
+static int schema_start_trans(struct ldb_module *module) {
+ return ldb_next_start_trans(module);
}
-static int schema_named_unlock(struct ldb_module *module, const char *name) {
- return ldb_next_named_unlock(module, name);
+static int schema_end_trans(struct ldb_module *module, int status) {
+ return ldb_next_end_trans(module, status);
}
/* return extended error information */
}
static const struct ldb_module_ops schema_ops = {
- .name = "schema",
- .search = schema_search,
- .search_bytree = schema_search_bytree,
- .add_record = schema_add_record,
- .modify_record = schema_modify_record,
- .delete_record = schema_delete_record,
- .rename_record = schema_rename_record,
- .named_lock = schema_named_lock,
- .named_unlock = schema_named_unlock,
- .errstring = schema_errstring,
+ .name = "schema",
+ .search = schema_search,
+ .search_bytree = schema_search_bytree,
+ .add_record = schema_add_record,
+ .modify_record = schema_modify_record,
+ .delete_record = schema_delete_record,
+ .rename_record = schema_rename_record,
+ .start_transaction = schema_start_trans,
+ .end_transaction = schema_end_trans,
+ .errstring = schema_errstring,
};
#ifdef HAVE_DLOPEN_DISABLED
return ldb_next_rename_record(module, olddn, newdn);
}
-/* named_lock */
-static int skel_named_lock(struct ldb_module *module, const char *lockname)
+/* start a transaction */
+static int skel_start_trans(struct ldb_module *module)
{
- return ldb_next_named_lock(module, lockname);
+ return ldb_next_start_trans(module);
}
-/* named_unlock */
-static int skel_named_unlock(struct ldb_module *module, const char *lockname)
+/* end a transaction */
+static int skel_end_trans(struct ldb_module *module, int status)
{
- return ldb_next_named_unlock(module, lockname);
+ return ldb_next_end_trans(module, status);
}
/* return extended error information */
}
static const struct ldb_module_ops skel_ops = {
- .name = "skel",
- .search = skel_search,
- .search_bytree = skel_search_bytree,
- .add_record = skel_add_record,
- .modify_record = skel_modify_record,
- .delete_record = skel_delete_record,
- .rename_record = skel_rename_record,
- .named_lock = skel_named_lock,
- .named_unlock = skel_named_unlock,
- .errstring = skel_errstring
+ .name = "skel",
+ .search = skel_search,
+ .search_bytree = skel_search_bytree,
+ .add_record = skel_add_record,
+ .modify_record = skel_modify_record,
+ .delete_record = skel_delete_record,
+ .rename_record = skel_rename_record,
+ .start_transaction = skel_start_trans,
+ .end_transaction = skel_end_trans,
+ .errstring = skel_errstring
};
#ifdef HAVE_DLOPEN_DISABLED
return ldb_next_rename_record(module, olddn, newdn);
}
-static int timestamps_lock(struct ldb_module *module, const char *lockname)
+static int timestamps_start_trans(struct ldb_module *module)
{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "timestamps_lock\n");
- return ldb_next_named_lock(module, lockname);
+ ldb_debug(module->ldb, LDB_DEBUG_TRACE, "timestamps_start_trans\n");
+ return ldb_next_start_trans(module);
}
-static int timestamps_unlock(struct ldb_module *module, const char *lockname)
+static int timestamps_end_trans(struct ldb_module *module, int status)
{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "timestamps_unlock\n");
- return ldb_next_named_unlock(module, lockname);
+ ldb_debug(module->ldb, LDB_DEBUG_TRACE, "timestamps_end_trans\n");
+ return ldb_next_end_trans(module, status);
}
/* return extended error information */
}
static const struct ldb_module_ops timestamps_ops = {
- .name = "timestamps",
- .search = timestamps_search,
- .search_bytree = timestamps_search_bytree,
- .add_record = timestamps_add_record,
- .modify_record = timestamps_modify_record,
- .delete_record = timestamps_delete_record,
- .rename_record = timestamps_rename_record,
- .named_lock = timestamps_lock,
- .named_unlock = timestamps_unlock,
- .errstring = timestamps_errstring
+ .name = "timestamps",
+ .search = timestamps_search,
+ .search_bytree = timestamps_search_bytree,
+ .add_record = timestamps_add_record,
+ .modify_record = timestamps_modify_record,
+ .delete_record = timestamps_delete_record,
+ .rename_record = timestamps_rename_record,
+ .start_transaction = timestamps_start_trans,
+ .end_transaction = timestamps_end_trans,
+ .errstring = timestamps_errstring
};
struct ldb_message msg;
int i;
+#if 0
if (ldb_lock(ldb, "transaction") != 0) {
printf("transaction lock failed\n");
exit(1);
}
-
+#endif
for (i=0;i<count;i++) {
struct ldb_message_element el[6];
struct ldb_val vals[6][1];
talloc_free(tmp_ctx);
}
-
+#if 0
if (ldb_unlock(ldb, "transaction") != 0) {
printf("transaction unlock failed\n");
exit(1);
}
-
+#endif
printf("\n");
}