From 9261fa997ccda8f89556b644ddd45cd86919ec2e Mon Sep 17 00:00:00 2001 From: Matthias Dieter Wallnöfer Date: Tue, 9 Sep 2008 17:36:14 +0200 Subject: Cosmetic corrections for the LDB backend modules This commit applies some cosmetic corrections for the LDB backend modules. --- source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c') diff --git a/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c b/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c index a0e63c8da1..7e4fe1d08d 100644 --- a/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c +++ b/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c @@ -670,10 +670,10 @@ static int lsqlite3_safe_rollback(sqlite3 *sqlite) printf("lsqlite3_safe_rollback: Error: %s\n", errmsg); free(errmsg); } - return -1; + return SQLITE_ERROR; } - return 0; + return SQLITE_OK; } /* return an eid as result */ @@ -1440,13 +1440,13 @@ static int lsql_start_trans(struct ldb_module * module) printf("lsqlite3_start_trans: error: %s\n", errmsg); free(errmsg); } - return -1; + return SQLITE_ERROR; } }; lsqlite3->trans_count++; - return 0; + return SQLITE_OK; } static int lsql_end_trans(struct ldb_module *module) @@ -1457,7 +1457,7 @@ static int lsql_end_trans(struct ldb_module *module) if (lsqlite3->trans_count > 0) { lsqlite3->trans_count--; - } else return -1; + } else return SQLITE_ERROR; if (lsqlite3->trans_count == 0) { ret = sqlite3_exec(lsqlite3->sqlite, "COMMIT;", NULL, NULL, &errmsg); @@ -1466,11 +1466,11 @@ static int lsql_end_trans(struct ldb_module *module) printf("lsqlite3_end_trans: error: %s\n", errmsg); free(errmsg); } - return -1; + return SQLITE_ERROR; } } - return 0; + return SQLITE_OK; } static int lsql_del_trans(struct ldb_module *module) @@ -1479,13 +1479,13 @@ static int lsql_del_trans(struct ldb_module *module) if (lsqlite3->trans_count > 0) { lsqlite3->trans_count--; - } else return -1; + } else return SQLITE_ERROR; if (lsqlite3->trans_count == 0) { return lsqlite3_safe_rollback(lsqlite3->sqlite); } - return -1; + return SQLITE_ERROR; } static int destructor(struct lsqlite3_private *lsqlite3) @@ -1493,7 +1493,7 @@ static int destructor(struct lsqlite3_private *lsqlite3) if (lsqlite3->sqlite) { sqlite3_close(lsqlite3->sqlite); } - return 0; + return SQLITE_OK; } static int lsql_request(struct ldb_module *module, struct ldb_request *req) @@ -1540,7 +1540,7 @@ static int initialize(struct lsqlite3_private *lsqlite3, /* create a local ctx */ local_ctx = talloc_named(lsqlite3, 0, "lsqlite3_rename local context"); if (local_ctx == NULL) { - return -1; + return SQLITE_ERROR; } schema = lsqlite3_tprintf(local_ctx, @@ -1792,7 +1792,7 @@ static int initialize(struct lsqlite3_private *lsqlite3, failed: if (rollback) lsqlite3_safe_rollback(lsqlite3->sqlite); sqlite3_close(lsqlite3->sqlite); - return -1; + return SQLITE_ERROR; } /* @@ -1860,14 +1860,14 @@ static int lsqlite3_connect(struct ldb_context *ldb, } } - return 0; + return LDB_SUCCESS; failed: if (lsqlite3->sqlite != NULL) { (void) sqlite3_close(lsqlite3->sqlite); } talloc_free(lsqlite3); - return -1; + return LDB_ERR_OPERATIONS_ERROR; } const struct ldb_backend_ops ldb_sqlite3_backend_ops = { -- cgit From b0a95ad2f68cfc87822420c22216d83c0abf0690 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 24 Sep 2008 23:59:59 +0200 Subject: Revert LDB return code patches from Matthias. --- source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c') diff --git a/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c b/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c index 7e4fe1d08d..a0e63c8da1 100644 --- a/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c +++ b/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c @@ -670,10 +670,10 @@ static int lsqlite3_safe_rollback(sqlite3 *sqlite) printf("lsqlite3_safe_rollback: Error: %s\n", errmsg); free(errmsg); } - return SQLITE_ERROR; + return -1; } - return SQLITE_OK; + return 0; } /* return an eid as result */ @@ -1440,13 +1440,13 @@ static int lsql_start_trans(struct ldb_module * module) printf("lsqlite3_start_trans: error: %s\n", errmsg); free(errmsg); } - return SQLITE_ERROR; + return -1; } }; lsqlite3->trans_count++; - return SQLITE_OK; + return 0; } static int lsql_end_trans(struct ldb_module *module) @@ -1457,7 +1457,7 @@ static int lsql_end_trans(struct ldb_module *module) if (lsqlite3->trans_count > 0) { lsqlite3->trans_count--; - } else return SQLITE_ERROR; + } else return -1; if (lsqlite3->trans_count == 0) { ret = sqlite3_exec(lsqlite3->sqlite, "COMMIT;", NULL, NULL, &errmsg); @@ -1466,11 +1466,11 @@ static int lsql_end_trans(struct ldb_module *module) printf("lsqlite3_end_trans: error: %s\n", errmsg); free(errmsg); } - return SQLITE_ERROR; + return -1; } } - return SQLITE_OK; + return 0; } static int lsql_del_trans(struct ldb_module *module) @@ -1479,13 +1479,13 @@ static int lsql_del_trans(struct ldb_module *module) if (lsqlite3->trans_count > 0) { lsqlite3->trans_count--; - } else return SQLITE_ERROR; + } else return -1; if (lsqlite3->trans_count == 0) { return lsqlite3_safe_rollback(lsqlite3->sqlite); } - return SQLITE_ERROR; + return -1; } static int destructor(struct lsqlite3_private *lsqlite3) @@ -1493,7 +1493,7 @@ static int destructor(struct lsqlite3_private *lsqlite3) if (lsqlite3->sqlite) { sqlite3_close(lsqlite3->sqlite); } - return SQLITE_OK; + return 0; } static int lsql_request(struct ldb_module *module, struct ldb_request *req) @@ -1540,7 +1540,7 @@ static int initialize(struct lsqlite3_private *lsqlite3, /* create a local ctx */ local_ctx = talloc_named(lsqlite3, 0, "lsqlite3_rename local context"); if (local_ctx == NULL) { - return SQLITE_ERROR; + return -1; } schema = lsqlite3_tprintf(local_ctx, @@ -1792,7 +1792,7 @@ static int initialize(struct lsqlite3_private *lsqlite3, failed: if (rollback) lsqlite3_safe_rollback(lsqlite3->sqlite); sqlite3_close(lsqlite3->sqlite); - return SQLITE_ERROR; + return -1; } /* @@ -1860,14 +1860,14 @@ static int lsqlite3_connect(struct ldb_context *ldb, } } - return LDB_SUCCESS; + return 0; failed: if (lsqlite3->sqlite != NULL) { (void) sqlite3_close(lsqlite3->sqlite); } talloc_free(lsqlite3); - return LDB_ERR_OPERATIONS_ERROR; + return -1; } const struct ldb_backend_ops ldb_sqlite3_backend_ops = { -- cgit From 9f7c2548d9da848397b4730f02c7c47f23e259dc Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Thu, 11 Sep 2008 18:34:56 -0400 Subject: LDB ASYNC: other backends --- source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c | 130 ++++++++++++++---------------- 1 file changed, 62 insertions(+), 68 deletions(-) (limited to 'source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c') diff --git a/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c b/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c index a0e63c8da1..be99c29d1e 100644 --- a/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c +++ b/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c @@ -44,51 +44,14 @@ struct lsqlite3_private { struct lsql_context { struct ldb_module *module; + struct ldb_request *req; /* search stuff */ long long current_eid; const char * const * attrs; struct ldb_reply *ares; - - /* async stuff */ - void *context; - int (*callback)(struct ldb_context *, void *, struct ldb_reply *); }; -static struct ldb_handle *init_handle(struct lsqlite3_private *lsqlite3, - struct ldb_module *module, - struct ldb_request *req) -{ - struct lsql_context *ac; - struct ldb_handle *h; - - h = talloc_zero(lsqlite3, struct ldb_handle); - if (h == NULL) { - ldb_set_errstring(module->ldb, "Out of Memory"); - return NULL; - } - - h->module = module; - - ac = talloc(h, struct lsql_context); - if (ac == NULL) { - ldb_set_errstring(module->ldb, "Out of Memory"); - talloc_free(h); - return NULL; - } - - h->private_data = (void *)ac; - - h->state = LDB_ASYNC_INIT; - h->status = LDB_SUCCESS; - - ac->module = module; - ac->context = req->context; - ac->callback = req->callback; - - return h; -} - /* * Macros used throughout */ @@ -835,11 +798,6 @@ int lsql_search(struct ldb_module *module, struct ldb_request *req) char *query = NULL; int ret; - req->handle = init_handle(lsqlite3, module, req); - if (req->handle == NULL) { - return LDB_ERR_OPERATIONS_ERROR; - } - lsql_ac = talloc_get_type(req->handle->private_data, struct lsql_context); if ((( ! ldb_dn_is_valid(req->op.search.base)) || ldb_dn_is_null(req->op.search.base)) && @@ -1013,10 +971,6 @@ static int lsql_add(struct ldb_module *module, struct ldb_request *req) int i; int ret = LDB_SUCCESS; - req->handle = init_handle(lsqlite3, module, req); - if (req->handle == NULL) { - return LDB_ERR_OPERATIONS_ERROR; - } lsql_ac = talloc_get_type(req->handle->private_data, struct lsql_context); req->handle->state = LDB_ASYNC_DONE; req->handle->status = LDB_SUCCESS; @@ -1143,10 +1097,6 @@ static int lsql_modify(struct ldb_module *module, struct ldb_request *req) int i; int ret = LDB_SUCCESS; - req->handle = init_handle(lsqlite3, module, req); - if (req->handle == NULL) { - return LDB_ERR_OPERATIONS_ERROR; - } lsql_ac = talloc_get_type(req->handle->private_data, struct lsql_context); req->handle->state = LDB_ASYNC_DONE; req->handle->status = LDB_SUCCESS; @@ -1329,10 +1279,6 @@ static int lsql_delete(struct ldb_module *module, struct ldb_request *req) int ret = LDB_SUCCESS; - req->handle = init_handle(lsqlite3, module, req); - if (req->handle == NULL) { - return LDB_ERR_OPERATIONS_ERROR; - } lsql_ac = talloc_get_type(req->handle->private_data, struct lsql_context); req->handle->state = LDB_ASYNC_DONE; req->handle->status = LDB_SUCCESS; @@ -1382,10 +1328,6 @@ static int lsql_rename(struct ldb_module *module, struct ldb_request *req) char *query; int ret = LDB_SUCCESS; - req->handle = init_handle(lsqlite3, module, req); - if (req->handle == NULL) { - return LDB_ERR_OPERATIONS_ERROR; - } lsql_ac = talloc_get_type(req->handle->private_data, struct lsql_context); req->handle->state = LDB_ASYNC_DONE; req->handle->status = LDB_SUCCESS; @@ -1501,9 +1443,61 @@ static int lsql_request(struct ldb_module *module, struct ldb_request *req) return LDB_ERR_OPERATIONS_ERROR; } -static int lsql_wait(struct ldb_handle *handle, enum ldb_wait_type type) +static int lsql_run_request(struct ldb_module *module, struct ldb_request *req) +{ + switch (req->operation) { + case LDB_SEARCH: + return lsql_search(module, req); + break; + case LDB_ADD: + return lsql_add(module, req); + break; + case LDB_MODIFY: + return lsql_modify(module, req); + break; + case LDB_DELETE: + return lsql_delete(module, req); + break; + case LDB_RENAME: + return lsql_rename(module, req); + break; +/* TODO: + case LDB_SEQUENCE_NUMBER: + return lsql_sequence_number(module, req); + break; + */ + default: + return lsql_request(module, req); + break; + } + + return LDB_ERR_OPERATIONS_ERROR; +} + +static int lsql_handle_request(struct ldb_module *module, struct ldb_request *req) { - return handle->status; + struct lsql_context *ac; + + if (check_critical_controls(req->controls)) { + return LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION; + } + + ac = talloc_zero(req, struct lsql_context); + if (ac == NULL) { + ldb_set_errstring(module->ldb, "Out of Memory"); + return LDB_ERR_OPERATIONS_ERROR; + } + + ac->module = module; + ac->req = req; + + req->handle = ldb_handle_new(req, lsql_run_request, ac); + if (req->handle == NULL) { + talloc_free(ac); + return LDB_ERR_OPERATIONS_ERROR; + } + + return LDB_SUCCESS; } /* @@ -1511,16 +1505,16 @@ static int lsql_wait(struct ldb_handle *handle, enum ldb_wait_type type) */ static const struct ldb_module_ops lsqlite3_ops = { .name = "sqlite", - .search = lsql_search, - .add = lsql_add, - .modify = lsql_modify, - .del = lsql_delete, - .rename = lsql_rename, - .request = lsql_request, + .search = lsql_handle_request, + .add = lsql_handle_request, + .modify = lsql_handle_request, + .del = lsql_handle_request, + .rename = lsql_handle_request, + .request = lsql_handle_request, .start_transaction = lsql_start_trans, .end_transaction = lsql_end_trans, .del_transaction = lsql_del_trans, - .wait = lsql_wait, + /* TODO: .sequence_number = lsql_handle_request */ }; /* -- cgit