svn commit: samba r17372 - in branches/SOC/mkhl/ldb-map/modules: .
abartlet at samba.org
abartlet at samba.org
Wed Aug 2 02:24:01 GMT 2006
Author: abartlet
Date: 2006-08-02 02:24:00 +0000 (Wed, 02 Aug 2006)
New Revision: 17372
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=17372
Log:
Changes to ldb_map to handle wildcard mappings, and not rebasing the DN.
Andrew Bartlett
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-08-02 01:25:05 UTC (rev 17371)
+++ branches/SOC/mkhl/ldb-map/modules/ldb_map.c 2006-08-02 02:24:00 UTC (rev 17372)
@@ -218,6 +218,11 @@
struct ldb_dn *new;
int i, offset;
+ /* Perhaps we don't need to rebase at all? */
+ if (!old_base || !new_base) {
+ return ldb_dn_copy(mem_ctx, old);
+ }
+
offset = old->comp_num - old_base->comp_num;
new = ldb_dn_copy_partial(mem_ctx, new_base,
offset + new_base->comp_num);
@@ -319,7 +324,7 @@
{
int i;
- for (i = 0; data->objectclass_maps[i].local_name; i++)
+ for (i = 0; data->objectclass_maps && data->objectclass_maps[i].local_name; i++)
if (ldb_attr_cmp(data->objectclass_maps[i]
.local_name, name) == 0)
return &data->objectclass_maps[i];
@@ -334,7 +339,7 @@
{
int i;
- for (i = 0; data->objectclass_maps[i].remote_name; i++)
+ for (i = 0; data->objectclass_maps && data->objectclass_maps[i].remote_name; i++)
if (ldb_attr_cmp(data->objectclass_maps[i]
.remote_name, name) == 0)
return &data->objectclass_maps[i];
@@ -350,11 +355,16 @@
{
int i;
- for (i = 0; data->attribute_maps[i].local_name; i++)
+ for (i = 0; data->attribute_maps[i].local_name; i++) {
if (ldb_attr_cmp(data->attribute_maps[i]
.local_name, name) == 0)
return &data->attribute_maps[i];
-
+ }
+ for (i = 0; data->attribute_maps[i].local_name; i++) {
+ if (ldb_attr_cmp(data->attribute_maps[i]
+ .local_name, "*") == 0)
+ return &data->attribute_maps[i];
+ }
return NULL;
}
@@ -365,8 +375,14 @@
const char *name)
{
int i, j;
+ const struct ldb_map_attribute *wildcard = NULL;
for (i = 0; data->attribute_maps[i].local_name; i++) {
+ if (ldb_attr_cmp(data->attribute_maps[i]
+ .local_name, "*") == 0) {
+ wildcard = &data->attribute_maps[i];
+ }
+
switch (data->attribute_maps[i].type) {
case MAP_KEEP:
if (ldb_attr_cmp(data->attribute_maps[i] .local_name, name) == 0)
@@ -390,7 +406,8 @@
}
}
- return NULL;
+ /* We didn't find it, so return the wildcard record if one was configured */
+ return wildcard;
}
@@ -404,6 +421,10 @@
{
const struct ldb_map_context *data = map_get_context(module);
+ if (!data->local_base_dn) {
+ return True;
+ }
+
return ldb_dn_compare_base(module->ldb, data->local_base_dn, dn) == 0;
}
@@ -572,7 +593,7 @@
continue;
case MAP_KEEP:
- name = map->local_name;
+ name = attrs[i];
goto named;
case MAP_RENAME:
@@ -1601,13 +1622,16 @@
partition_msg_el(struct ldb_module *module,
struct ldb_message *local,
struct ldb_message *remote,
- const struct ldb_map_attribute *map,
+ const char *attr_name,
const struct ldb_message *msg,
/* const char * const names[], */
const struct ldb_message_element *old)
{
struct ldb_message_element *el;
+ const struct ldb_map_context *data = map_get_context(module);
+ const struct ldb_map_attribute *map = find_local_attr(data, attr_name);
+
/* no mapping: ignore */
if (map == NULL) {
ldb_debug(module->ldb, LDB_DEBUG_WARNING, "ldb_map: "
@@ -1698,10 +1722,8 @@
struct ldb_message *remote,
const struct ldb_message *msg)
{
- const struct ldb_map_context *data = map_get_context(module);
/* names of remote attributes the original message can map */
/* const char * const names[]; */
- const struct ldb_map_attribute *map;
int i, ret;
/* try to map each attribute;
@@ -1716,9 +1738,7 @@
continue;
}
- map = find_local_attr(data, msg->elements[i].name);
-
- ret = partition_msg_el(module, local, remote, map,
+ ret = partition_msg_el(module, local, remote, msg->elements[i].name,
msg, &msg->elements[i]);
if (ret != 0)
return ret;
@@ -1783,6 +1803,10 @@
goto failed;
case MAP_KEEP:
+ el = copy_conv_msg_el(module, local, old,
+ old->name, NULL);
+ break;
+
case MAP_RENAME:
el = copy_conv_msg_el(module, local, old,
map->local_name, NULL);
@@ -1844,7 +1868,8 @@
for (i = 0; i < remote->num_elements; i++) {
map = find_remote_attr(data, remote->elements[i].name);
- ret = merge_msg_el(module, local, remote, map,
+ ret = merge_msg_el(module, local, remote,
+ map,
&remote->elements[i]);
if (ret != 0)
return ret;
@@ -2035,7 +2060,8 @@
}
/* XXX: ugly kludge: pass only requested attrs */
- if (req->op.search.attrs) {
+ if (req->op.search.attrs
+ && (!ldb_attr_in_list(req->op.search.attrs, "*"))) {
struct ldb_message *msg = ldb_msg_new(ares);
if (msg == NULL)
goto error;
@@ -2046,6 +2072,7 @@
ldb_msg_add(msg, el, 0);
}
+ msg->dn = talloc_steal(msg, ares->message->dn);
talloc_free(ares->message);
ares->message = msg;
}
@@ -2242,9 +2269,8 @@
/* XXX: ugly kludge
ac->local_attrs = local_attrs;
+ */
ac->remote_req->op.search.attrs = remote_attrs;
- */
- ac->remote_req->op.search.attrs = NULL;
/* split local from remote tree */
ret = partition_tree(module, ac->remote_req, ac,
@@ -2642,7 +2668,7 @@
if (ldb_dn_is_special(req->op.del.dn))
return ldb_next_request(module, req);
- /* no mapping requested, skip to next module */
+ /* no mapping requested (perhaps no DN mapping specified), skip to next module */
if (!check_dn_local(module, req->op.del.dn))
return ldb_next_request(module, req);
@@ -2672,6 +2698,13 @@
ac->remote_req->op.del.dn = map_local_dn(module, ac->remote_req,
req->op.del.dn);
+ /* The DN didn't change, so just pretend we were never here */
+ if (ldb_dn_compare(module->ldb, ac->remote_req->op.del.dn,
+ req->op.del.dn) == 0) {
+ talloc_free(h);
+ return ldb_next_request(module, req);
+ }
+
ac->remote_req->context = NULL;
ac->remote_req->callback = NULL;
@@ -2774,10 +2807,11 @@
if (ldb_dn_is_special(req->op.rename.olddn))
return ldb_next_request(module, req);
- /* no mapping requested, skip to next module */
- if (!check_dn_local(module, req->op.rename.olddn) &&
- !check_dn_local(module, req->op.rename.newdn))
+ /* no mapping requested, (perhaps no DN mapping specified), skip to next module */
+ if ((!check_dn_local(module, req->op.rename.olddn) &&
+ !check_dn_local(module, req->op.rename.newdn))) {
return ldb_next_request(module, req);
+ }
/* rename into/out of the mapped partition requested, bail out */
if (!check_dn_local(module, req->op.rename.olddn) ||
@@ -3078,6 +3112,12 @@
struct ldb_result *res;
int ret;
+ if (!name) {
+ data->local_base_dn = NULL;
+ data->remote_base_dn = NULL;
+ return LDB_SUCCESS;
+ }
+
dn = ldb_dn_string_compose(data, NULL, "%s=%s", MAP_DN_NAME, name);
if (dn == NULL) {
ldb_debug(module->ldb, LDB_DEBUG_ERROR, "ldb_map: "
More information about the samba-cvs
mailing list