summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/common/ldb.c
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2006-06-07 21:03:38 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:08:57 -0500
commit247af0d569594512a24e83156e257b8d4d356883 (patch)
tree01cc382ba950b92059d8dd3686016333caf043b1 /source4/lib/ldb/common/ldb.c
parent2ab5bafd7296e4c2a415a4fcbe8a2ba7b4373699 (diff)
downloadsamba-247af0d569594512a24e83156e257b8d4d356883.tar.gz
samba-247af0d569594512a24e83156e257b8d4d356883.tar.bz2
samba-247af0d569594512a24e83156e257b8d4d356883.zip
r16083: Make it possible to initialise a backend module, without it setting up
the whole ldb structure. Because the sequence number was a fn pointer on the main ldb context, turn it into a full request (currently sync). Andrew Bartlett (This used to be commit fbe7d0ca9031e292b2d2fae263233c973982980a)
Diffstat (limited to 'source4/lib/ldb/common/ldb.c')
-rw-r--r--source4/lib/ldb/common/ldb.c70
1 files changed, 66 insertions, 4 deletions
diff --git a/source4/lib/ldb/common/ldb.c b/source4/lib/ldb/common/ldb.c
index 1fdbeb55d2..ff5d2a2e8b 100644
--- a/source4/lib/ldb/common/ldb.c
+++ b/source4/lib/ldb/common/ldb.c
@@ -91,16 +91,20 @@ static ldb_connect_fn ldb_find_backend(const char *url)
}
/*
- connect to a database. The URL can either be one of the following forms
+ Return the ldb module form of a database. The URL can either be one of the following forms
ldb://path
ldapi://path
flags is made up of LDB_FLG_*
the options are passed uninterpreted to the backend, and are
- backend specific
+ backend specific.
+
+ This allows modules to get at only the backend module, for example where a module
+ may wish to direct certain requests at a particular backend.
*/
-int ldb_connect(struct ldb_context *ldb, const char *url, unsigned int flags, const char *options[])
+int ldb_connect_backend(struct ldb_context *ldb, const char *url, unsigned int flags, const char *options[],
+ struct ldb_module **backend_module)
{
int ret;
char *backend;
@@ -128,12 +132,34 @@ int ldb_connect(struct ldb_context *ldb, const char *url, unsigned int flags, co
return LDB_ERR_OTHER;
}
- ret = fn(ldb, url, flags, options);
+ ret = fn(ldb, url, flags, options, backend_module);
if (ret != LDB_SUCCESS) {
ldb_debug(ldb, LDB_DEBUG_ERROR, "Failed to connect to '%s'\n", url);
return ret;
}
+ return ret;
+}
+
+
+/*
+ connect to a database. The URL can either be one of the following forms
+ ldb://path
+ ldapi://path
+
+ flags is made up of LDB_FLG_*
+
+ the options are passed uninterpreted to the backend, and are
+ backend specific
+*/
+int ldb_connect(struct ldb_context *ldb, const char *url, unsigned int flags, const char *options[])
+{
+ int ret;
+
+ ret = ldb_connect_backend(ldb, url, flags, options, &ldb->modules);
+ if (ret != LDB_SUCCESS) {
+ return ret;
+ }
if (ldb_load_modules(ldb, options) != LDB_SUCCESS) {
ldb_debug(ldb, LDB_DEBUG_FATAL, "Unable to load modules for '%s'\n", url);
@@ -395,6 +421,10 @@ int ldb_request(struct ldb_context *ldb, struct ldb_request *req)
FIRST_OP(ldb, rename);
ret = module->ops->rename(module, req);
break;
+ case LDB_SEQUENCE_NUMBER:
+ FIRST_OP(ldb, sequence_number);
+ ret = module->ops->sequence_number(module, req);
+ break;
default:
FIRST_OP(ldb, request);
ret = module->ops->request(module, req);
@@ -655,6 +685,38 @@ int ldb_rename(struct ldb_context *ldb, const struct ldb_dn *olddn, const struct
}
+/*
+ rename a record in the database
+*/
+int ldb_sequence_number(struct ldb_context *ldb, uint64_t *seq_num)
+{
+ struct ldb_request *req;
+ int ret;
+
+ req = talloc(ldb, struct ldb_request);
+ if (req == NULL) {
+ ldb_set_errstring(ldb, talloc_strdup(ldb, "Out of memory!"));
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+
+ req->operation = LDB_SEQUENCE_NUMBER;
+ req->controls = NULL;
+ req->async.context = NULL;
+ req->async.callback = NULL;
+ ldb_set_timeout(ldb, req, 0); /* use default timeout */
+
+ /* do request and autostart a transaction */
+ ret = ldb_request(ldb, req);
+
+ if (ret == LDB_SUCCESS) {
+ *seq_num = req->op.seq_num.seq_num;
+ }
+
+ talloc_free(req);
+ return ret;
+}
+
+
/*
return extended error information