svn commit: samba r16511 - in branches/SOC/mkhl/ldb-map/modules: .
mkhl at samba.org
mkhl at samba.org
Sun Jun 25 16:08:20 GMT 2006
Author: mkhl
Date: 2006-06-25 16:08:19 +0000 (Sun, 25 Jun 2006)
New Revision: 16511
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=16511
Log:
Add remote search callback, not yet merging results.
Martin
Modified:
branches/SOC/mkhl/ldb-map/modules/ldb_map.c
Changeset:
Modified: branches/SOC/mkhl/ldb-map/modules/ldb_map.c
===================================================================
--- branches/SOC/mkhl/ldb-map/modules/ldb_map.c 2006-06-25 12:22:12 UTC (rev 16510)
+++ branches/SOC/mkhl/ldb-map/modules/ldb_map.c 2006-06-25 16:08:19 UTC (rev 16511)
@@ -1395,7 +1395,14 @@
return 0;
}
+static
+int
+merge_mapped_results(struct map_async_search_context *context)
+{
+ return LDB_SUCCESS; /* TODO */
+}
+
/* store single search result in async context */
static
int
@@ -1404,6 +1411,7 @@
struct ldb_async_result *ares)
{
struct map_async_context *ac;
+ const char *dn;
if (context == NULL || ares == NULL) {
ldb_set_errstring(ldb, talloc_asprintf(ldb, "NULL Context or Result in callback"));
@@ -1418,19 +1426,17 @@
return LDB_SUCCESS;
}
- /* we already have a remote DN */
+ /* we have already found a remote DN */
if (ac->remote_dn) {
- ldb_set_errstring(ldb,
- talloc_asprintf(ldb, "Too many results"));
+ ldb_set_errstring(ldb, talloc_asprintf(ldb, "Too many results to base search"));
talloc_free(ares);
return LDB_ERR_OPERATIONS_ERROR;
}
/* extract remote DN */
- ac->search_res = talloc_steal(ac, ares);
- ac->remote_dn = ldb_dn_explode(ac,
- ldb_msg_find_string(ares->message,
- IS_MAPPED, NULL));
+ ac->search_res = ares;
+ dn = ldb_msg_find_string(ares->message, IS_MAPPED, NULL);
+ ac->remote_dn = ldb_dn_explode(ac, dn);
return LDB_SUCCESS;
}
@@ -1492,6 +1498,47 @@
void *context,
struct ldb_async_result *ares)
{
+ struct map_async_search_context *sc;
+ int ret;
+
+ if (context == NULL || ares == NULL) {
+ ldb_set_errstring(ldb, talloc_asprintf(ldb, "NULL Context or Result in callback"));
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+
+ sc = talloc_get_type(context, struct map_async_search_context);
+
+ switch (ares->type) {
+ case LDB_REPLY_ENTRY:
+ /* we have already found a remote record */
+ if (sc->remote_res) {
+ ldb_set_errstring(ldb, talloc_asprintf(ldb, "Too many results to base search"));
+ talloc_free(ares);
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+
+ /* store remote result */
+ sc->remote_res = ares;
+
+ /* merge remote into local record */
+ ret = merge_mapped_results(sc);
+ if (ret != LDB_SUCCESS)
+ talloc_free(ares);
+
+ return ret;
+
+ case LDB_REPLY_DONE:
+ /* no mapped record found, continue with local record */
+ if (sc->remote_res == NULL)
+ return sc->ac->orig_req->async.callback(ldb, sc->ac->orig_req->async.context, sc->local_res);
+ break;
+
+ default:
+ talloc_free(ares);
+ ldb_set_errstring(ldb, talloc_asprintf(ldb, "Unexpected result type in base search for mapped entry"));
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+
return LDB_SUCCESS;
}
@@ -1516,13 +1563,11 @@
/* stop searching if it's not a record */
if (ares->type != LDB_REPLY_ENTRY)
- return ac->orig_req->
- async.callback(ldb, ac->orig_req->async.context, ares);
+ goto callback;
/* stop searching if it's not mapped */
if (!ldb_msg_find_element(ares->message, IS_MAPPED))
- return ac->orig_req->
- async.callback(ldb, ac->orig_req->async.context, ares);
+ goto callback;
/* extract remote DN */
dn = ldb_dn_explode(ac, ldb_msg_find_string(ares->message,
@@ -1541,8 +1586,9 @@
if (sc == NULL)
goto error;
+ /* store local result */
sc->ac = ac;
- sc->local_res = ares; /* TODO: steal? */
+ sc->local_res = ares;
sc->remote_res = NULL;
/* TODO: replace NULL with remote attrs! */
@@ -1552,6 +1598,9 @@
return ldb_next_remote_request(ac->module, req);
+callback:
+ return ac->orig_req->async.callback(ldb, ac->orig_req->async.context, ares);
+
error:
talloc_free(ares);
return LDB_ERR_OPERATIONS_ERROR;
@@ -1561,7 +1610,6 @@
/* Handling LDB requests */
/* /\* Search fallback database *\/ */
-/* /\* TODO: async *\/ */
/* static int map_search_fb(struct ldb_module *module, struct ldb_request *req) */
/* { */
/* struct ldb_parse_tree *tree = req->op.search.tree; */
@@ -1592,7 +1640,6 @@
/* } */
/* /\* Search in the database against which we are mapping *\/ */
-/* /\* TODO: async *\/ */
/* static int map_search_mp(struct ldb_module *module, struct ldb_request *req) */
/* { */
/* const struct ldb_dn *base = req->op.search.base; */
@@ -1714,7 +1761,6 @@
/* } */
/* /\* Search for matching records using a ldb_parse_tree *\/ */
-/* /\* TODO: async *\/ */
/* static int map_search_bytree(struct ldb_module *module, struct ldb_request *req) */
/* { */
/* const struct ldb_dn *base = req->op.search.base; */
@@ -1905,7 +1951,7 @@
map_oom(module);
goto failed;
}
- local->dn = msg->dn; /* TODO: reference? */
+ local->dn = msg->dn;
/* prepare the remote message */
remote = ldb_msg_new(ac->remote_req);
@@ -2062,7 +2108,7 @@
map_oom(module);
goto failed;
}
- local->dn = msg->dn; /* TODO: reference? */
+ local->dn = msg->dn;
/* prepare the remote message */
remote = ldb_msg_new(ac->remote_req);
@@ -2329,7 +2375,7 @@
return ldb_next_request(module, req);
/* no mapping requested, skip to next module */
- /* TODO: both? either? neither? what to doin each case? */
+ /* TODO: both? either? neither? what to do in each case? */
if (!check_dn_local(module, req->op.rename.olddn) ||
!check_dn_local(module, req->op.rename.newdn))
return ldb_next_request(module, req);
More information about the samba-cvs
mailing list