summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/modules
diff options
context:
space:
mode:
Diffstat (limited to 'source4/lib/ldb/modules')
-rw-r--r--source4/lib/ldb/modules/ldb_map.c116
-rw-r--r--source4/lib/ldb/modules/ldb_map_inbound.c2
-rw-r--r--source4/lib/ldb/modules/ldb_map_outbound.c10
-rw-r--r--source4/lib/ldb/modules/ldb_map_private.h4
-rw-r--r--source4/lib/ldb/modules/rdn_name.c46
5 files changed, 78 insertions, 100 deletions
diff --git a/source4/lib/ldb/modules/ldb_map.c b/source4/lib/ldb/modules/ldb_map.c
index 9146f2d863..32e64f3eb2 100644
--- a/source4/lib/ldb/modules/ldb_map.c
+++ b/source4/lib/ldb/modules/ldb_map.c
@@ -181,60 +181,16 @@ BOOL map_check_local_db(struct ldb_module *module)
return True;
}
-/* WARK: verbatim copy from ldb_dn.c */
-static struct ldb_dn_component ldb_dn_copy_component(void *mem_ctx, struct ldb_dn_component *src)
-{
- struct ldb_dn_component dst;
-
- memset(&dst, 0, sizeof(dst));
-
- if (src == NULL) {
- return dst;
- }
-
- dst.value = ldb_val_dup(mem_ctx, &(src->value));
- if (dst.value.data == NULL) {
- return dst;
- }
-
- dst.name = talloc_strdup(mem_ctx, src->name);
- if (dst.name == NULL) {
- talloc_free(dst.value.data);
- }
-
- return dst;
-}
-
-/* Copy a DN but replace the old with the new base DN. */
-static struct ldb_dn *ldb_dn_rebase(void *mem_ctx, const struct ldb_dn *old, const struct ldb_dn *old_base, const struct ldb_dn *new_base)
-{
- 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);
- for (i = 0; i < offset; i++) {
- new->components[i] = ldb_dn_copy_component(new->components, &(old->components[i]));
- }
-
- return new;
-}
-
/* Copy a DN with the base DN of the local partition. */
static struct ldb_dn *ldb_dn_rebase_local(void *mem_ctx, const struct ldb_map_context *data, const struct ldb_dn *dn)
{
- return ldb_dn_rebase(mem_ctx, dn, data->remote_base_dn, data->local_base_dn);
+ return ldb_dn_copy_rebase(mem_ctx, dn, data->remote_base_dn, data->local_base_dn);
}
/* Copy a DN with the base DN of the remote partition. */
static struct ldb_dn *ldb_dn_rebase_remote(void *mem_ctx, const struct ldb_map_context *data, const struct ldb_dn *dn)
{
- return ldb_dn_rebase(mem_ctx, dn, data->local_base_dn, data->remote_base_dn);
+ return ldb_dn_copy_rebase(mem_ctx, dn, data->local_base_dn, data->remote_base_dn);
}
/* Run a request and make sure it targets the remote partition. */
@@ -460,23 +416,23 @@ int map_attrs_merge(struct ldb_module *module, void *mem_ctx, const char ***attr
* ================== */
/* Map an ldb value into the remote partition. */
-struct ldb_val ldb_val_map_local(struct ldb_module *module, void *mem_ctx, const struct ldb_map_attribute *map, struct ldb_val val)
+struct ldb_val ldb_val_map_local(struct ldb_module *module, void *mem_ctx, const struct ldb_map_attribute *map, const struct ldb_val *val)
{
if (map && (map->type == MAP_CONVERT) && (map->u.convert.convert_local)) {
- return map->u.convert.convert_local(module, mem_ctx, &val);
+ return map->u.convert.convert_local(module, mem_ctx, val);
}
- return ldb_val_dup(mem_ctx, &val);
+ return ldb_val_dup(mem_ctx, val);
}
/* Map an ldb value back into the local partition. */
-struct ldb_val ldb_val_map_remote(struct ldb_module *module, void *mem_ctx, const struct ldb_map_attribute *map, struct ldb_val val)
+struct ldb_val ldb_val_map_remote(struct ldb_module *module, void *mem_ctx, const struct ldb_map_attribute *map, const struct ldb_val *val)
{
if (map && (map->type == MAP_CONVERT) && (map->u.convert.convert_remote)) {
- return map->u.convert.convert_remote(module, mem_ctx, &val);
+ return map->u.convert.convert_remote(module, mem_ctx, val);
}
- return ldb_val_dup(mem_ctx, &val);
+ return ldb_val_dup(mem_ctx, val);
}
@@ -500,10 +456,11 @@ struct ldb_dn *ldb_dn_map_local(struct ldb_module *module, void *mem_ctx, const
{
const struct ldb_map_context *data = map_get_context(module);
struct ldb_dn *newdn;
- struct ldb_dn_component *old, *new;
const struct ldb_map_attribute *map;
enum ldb_map_attr_type map_type;
- int i;
+ const char *name;
+ struct ldb_val value;
+ int i, ret;
if (dn == NULL) {
return NULL;
@@ -516,10 +473,8 @@ struct ldb_dn *ldb_dn_map_local(struct ldb_module *module, void *mem_ctx, const
}
/* For each RDN, map the component name and possibly the value */
- for (i = 0; i < newdn->comp_num; i++) {
- old = &dn->components[i];
- new = &newdn->components[i];
- map = map_attr_find_local(data, old->name);
+ for (i = 0; i < ldb_dn_get_comp_num(newdn); i++) {
+ map = map_attr_find_local(data, ldb_dn_get_component_name(dn, i));
/* Unknown attribute - leave this RDN as is and hope the best... */
if (map == NULL) {
@@ -533,21 +488,30 @@ struct ldb_dn *ldb_dn_map_local(struct ldb_module *module, void *mem_ctx, const
case MAP_GENERATE:
ldb_debug(module->ldb, LDB_DEBUG_ERROR, "ldb_map: "
"MAP_IGNORE/MAP_GENERATE attribute '%s' "
- "used in DN!\n", old->name);
+ "used in DN!\n", ldb_dn_get_component_name(dn, i));
goto failed;
case MAP_CONVERT:
if (map->u.convert.convert_local == NULL) {
ldb_debug(module->ldb, LDB_DEBUG_ERROR, "ldb_map: "
"'convert_local' not set for attribute '%s' "
- "used in DN!\n", old->name);
+ "used in DN!\n", ldb_dn_get_component_name(dn, i));
goto failed;
}
/* fall through */
case MAP_KEEP:
case MAP_RENAME:
- new->name = discard_const_p(char, map_attr_map_local(newdn->components, map, old->name));
- new->value = ldb_val_map_local(module, newdn->components, map, old->value);
+ name = map_attr_map_local(newdn, map, ldb_dn_get_component_name(dn, i));
+ if (name == NULL) goto failed;
+
+ value = ldb_val_map_local(module, newdn, map, ldb_dn_get_component_val(dn, i));
+ if (value.data == NULL) goto failed;
+
+ ret = ldb_dn_set_component(newdn, i, name, value);
+ if (ret != LDB_SUCCESS) {
+ goto failed;
+ }
+
break;
}
}
@@ -564,10 +528,11 @@ struct ldb_dn *ldb_dn_map_remote(struct ldb_module *module, void *mem_ctx, const
{
const struct ldb_map_context *data = map_get_context(module);
struct ldb_dn *newdn;
- struct ldb_dn_component *old, *new;
const struct ldb_map_attribute *map;
enum ldb_map_attr_type map_type;
- int i;
+ const char *name;
+ struct ldb_val value;
+ int i, ret;
if (dn == NULL) {
return NULL;
@@ -580,10 +545,8 @@ struct ldb_dn *ldb_dn_map_remote(struct ldb_module *module, void *mem_ctx, const
}
/* For each RDN, map the component name and possibly the value */
- for (i = 0; i < newdn->comp_num; i++) {
- old = &dn->components[i];
- new = &newdn->components[i];
- map = map_attr_find_remote(data, old->name);
+ for (i = 0; i < ldb_dn_get_comp_num(newdn); i++) {
+ map = map_attr_find_remote(data, ldb_dn_get_component_name(dn, i));
/* Unknown attribute - leave this RDN as is and hope the best... */
if (map == NULL) {
@@ -597,21 +560,30 @@ struct ldb_dn *ldb_dn_map_remote(struct ldb_module *module, void *mem_ctx, const
case MAP_GENERATE:
ldb_debug(module->ldb, LDB_DEBUG_ERROR, "ldb_map: "
"MAP_IGNORE/MAP_GENERATE attribute '%s' "
- "used in DN!\n", old->name);
+ "used in DN!\n", ldb_dn_get_component_name(dn, i));
goto failed;
case MAP_CONVERT:
if (map->u.convert.convert_remote == NULL) {
ldb_debug(module->ldb, LDB_DEBUG_ERROR, "ldb_map: "
"'convert_remote' not set for attribute '%s' "
- "used in DN!\n", old->name);
+ "used in DN!\n", ldb_dn_get_component_name(dn, i));
goto failed;
}
/* fall through */
case MAP_KEEP:
case MAP_RENAME:
- new->name = discard_const_p(char, map_attr_map_remote(newdn->components, map, old->name));
- new->value = ldb_val_map_remote(module, newdn->components, map, old->value);
+ name = map_attr_map_remote(newdn, map, ldb_dn_get_component_name(dn, i));
+ if (name == NULL) goto failed;
+
+ value = ldb_val_map_remote(module, newdn, map, ldb_dn_get_component_val(dn, i));
+ if (value.data == NULL) goto failed;
+
+ ret = ldb_dn_set_component(newdn, i, name, value);
+ if (ret != LDB_SUCCESS) {
+ goto failed;
+ }
+
break;
}
}
diff --git a/source4/lib/ldb/modules/ldb_map_inbound.c b/source4/lib/ldb/modules/ldb_map_inbound.c
index b83a17e502..38454b2b11 100644
--- a/source4/lib/ldb/modules/ldb_map_inbound.c
+++ b/source4/lib/ldb/modules/ldb_map_inbound.c
@@ -56,7 +56,7 @@ static struct ldb_message_element *ldb_msg_el_map_local(struct ldb_module *modul
el->name = map_attr_map_local(el, map, old->name);
for (i = 0; i < el->num_values; i++) {
- el->values[i] = ldb_val_map_local(module, el->values, map, old->values[i]);
+ el->values[i] = ldb_val_map_local(module, el->values, map, &old->values[i]);
}
return el;
diff --git a/source4/lib/ldb/modules/ldb_map_outbound.c b/source4/lib/ldb/modules/ldb_map_outbound.c
index aa8d4f9165..dc213f36d1 100644
--- a/source4/lib/ldb/modules/ldb_map_outbound.c
+++ b/source4/lib/ldb/modules/ldb_map_outbound.c
@@ -235,7 +235,7 @@ static struct ldb_message_element *ldb_msg_el_map_remote(struct ldb_module *modu
el->name = map_attr_map_remote(el, map, old->name);
for (i = 0; i < el->num_values; i++) {
- el->values[i] = ldb_val_map_remote(module, el->values, map, old->values[i]);
+ el->values[i] = ldb_val_map_remote(module, el->values, map, &old->values[i]);
}
return el;
@@ -729,21 +729,21 @@ int map_subtree_collect_remote_simple(struct ldb_module *module, void *mem_ctx,
*new = NULL;
return 0;
}
- *(*new)->u.substring.chunks[i] = ldb_val_map_local(module, *new, map, *tree->u.substring.chunks[i]);
+ *(*new)->u.substring.chunks[i] = ldb_val_map_local(module, *new, map, tree->u.substring.chunks[i]);
(*new)->u.substring.chunks[i+1] = NULL;
}
break;
}
case LDB_OP_EQUALITY:
- (*new)->u.equality.value = ldb_val_map_local(module, *new, map, tree->u.equality.value);
+ (*new)->u.equality.value = ldb_val_map_local(module, *new, map, &tree->u.equality.value);
break;
case LDB_OP_LESS:
case LDB_OP_GREATER:
case LDB_OP_APPROX:
- (*new)->u.comparison.value = ldb_val_map_local(module, *new, map, tree->u.comparison.value);
+ (*new)->u.comparison.value = ldb_val_map_local(module, *new, map, &tree->u.comparison.value);
break;
case LDB_OP_EXTENDED:
- (*new)->u.extended.value = ldb_val_map_local(module, *new, map, tree->u.extended.value);
+ (*new)->u.extended.value = ldb_val_map_local(module, *new, map, &tree->u.extended.value);
(*new)->u.extended.rule_id = talloc_strdup(*new, tree->u.extended.rule_id);
break;
default: /* unknown kind of simple subtree */
diff --git a/source4/lib/ldb/modules/ldb_map_private.h b/source4/lib/ldb/modules/ldb_map_private.h
index 7fb2745179..ae53ebbdd4 100644
--- a/source4/lib/ldb/modules/ldb_map_private.h
+++ b/source4/lib/ldb/modules/ldb_map_private.h
@@ -77,8 +77,8 @@ const char *map_attr_map_local(void *mem_ctx, const struct ldb_map_attribute *ma
const char *map_attr_map_remote(void *mem_ctx, const struct ldb_map_attribute *map, const char *attr);
int map_attrs_merge(struct ldb_module *module, void *mem_ctx, const char ***attrs, const char * const *more_attrs);
-struct ldb_val ldb_val_map_local(struct ldb_module *module, void *mem_ctx, const struct ldb_map_attribute *map, struct ldb_val val);
-struct ldb_val ldb_val_map_remote(struct ldb_module *module, void *mem_ctx, const struct ldb_map_attribute *map, struct ldb_val val);
+struct ldb_val ldb_val_map_local(struct ldb_module *module, void *mem_ctx, const struct ldb_map_attribute *map, const struct ldb_val *val);
+struct ldb_val ldb_val_map_remote(struct ldb_module *module, void *mem_ctx, const struct ldb_map_attribute *map, const struct ldb_val *val);
struct ldb_dn *ldb_dn_map_local(struct ldb_module *module, void *mem_ctx, const struct ldb_dn *dn);
struct ldb_dn *ldb_dn_map_remote(struct ldb_module *module, void *mem_ctx, const struct ldb_dn *dn);
diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c
index 510a43dbc9..bab5f6a014 100644
--- a/source4/lib/ldb/modules/rdn_name.c
+++ b/source4/lib/ldb/modules/rdn_name.c
@@ -58,7 +58,8 @@ static int rdn_name_add(struct ldb_module *module, struct ldb_request *req)
struct ldb_request *down_req;
struct ldb_message *msg;
struct ldb_message_element *attribute;
- struct ldb_dn_component *rdn;
+ const char *rdn_name;
+ struct ldb_val rdn_val;
int i, ret;
ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_add_record\n");
@@ -80,43 +81,45 @@ static int rdn_name_add(struct ldb_module *module, struct ldb_request *req)
return LDB_ERR_OPERATIONS_ERROR;
}
- rdn = ldb_dn_get_rdn(msg, msg->dn);
- if (rdn == NULL) {
+ rdn_name = ldb_dn_get_rdn_name(msg->dn);
+ if (rdn_name == NULL) {
talloc_free(down_req);
return LDB_ERR_OPERATIONS_ERROR;
}
+ rdn_val = ldb_val_dup(msg, ldb_dn_get_rdn_val(msg->dn));
+
/* Perhaps someone above us tried to set this? */
if ((attribute = rdn_name_find_attribute(msg, "name")) != NULL ) {
attribute->num_values = 0;
}
- if (ldb_msg_add_value(msg, "name", &rdn->value, NULL) != 0) {
+ if (ldb_msg_add_value(msg, "name", &rdn_val, NULL) != 0) {
talloc_free(down_req);
return LDB_ERR_OPERATIONS_ERROR;
}
- attribute = rdn_name_find_attribute(msg, rdn->name);
+ attribute = rdn_name_find_attribute(msg, rdn_name);
if (!attribute) {
- if (ldb_msg_add_value(msg, rdn->name, &rdn->value, NULL) != 0) {
+ if (ldb_msg_add_value(msg, rdn_name, &rdn_val, NULL) != 0) {
talloc_free(down_req);
return LDB_ERR_OPERATIONS_ERROR;
}
} else {
- const struct ldb_attrib_handler *handler = ldb_attrib_handler(module->ldb, rdn->name);
+ const struct ldb_attrib_handler *handler = ldb_attrib_handler(module->ldb, rdn_name);
for (i = 0; i < attribute->num_values; i++) {
- if (handler->comparison_fn(module->ldb, msg, &rdn->value, &attribute->values[i]) == 0) {
+ if (handler->comparison_fn(module->ldb, msg, &rdn_val, &attribute->values[i]) == 0) {
/* overwrite so it matches in case */
- attribute->values[i] = rdn->value;
+ attribute->values[i] = rdn_val;
break;
}
}
if (i == attribute->num_values) {
ldb_debug_set(module->ldb, LDB_DEBUG_FATAL,
- "RDN mismatch on %s: %s",
- ldb_dn_linearize(msg, msg->dn), rdn->name);
+ "RDN mismatch on %s: %s (%s)",
+ ldb_dn_linearize(msg, msg->dn), rdn_name, rdn_val.data);
talloc_free(down_req);
return LDB_ERR_OPERATIONS_ERROR;
}
@@ -190,16 +193,12 @@ static int rdn_name_rename(struct ldb_module *module, struct ldb_request *req)
static int rdn_name_rename_do_mod(struct ldb_handle *h) {
struct rename_context *ac;
- struct ldb_dn_component *rdn;
+ const char *rdn_name;
+ struct ldb_val rdn_val;
struct ldb_message *msg;
ac = talloc_get_type(h->private_data, struct rename_context);
- rdn = ldb_dn_get_rdn(ac, ac->orig_req->op.rename.newdn);
- if (rdn == NULL) {
- return LDB_ERR_OPERATIONS_ERROR;
- }
-
ac->mod_req = talloc_zero(ac, struct ldb_request);
ac->mod_req->operation = LDB_MODIFY;
@@ -213,16 +212,23 @@ static int rdn_name_rename_do_mod(struct ldb_handle *h) {
return LDB_ERR_OPERATIONS_ERROR;
}
- if (ldb_msg_add_empty(msg, rdn->name, LDB_FLAG_MOD_REPLACE, NULL) != 0) {
+ rdn_name = ldb_dn_get_rdn_name(ac->orig_req->op.rename.newdn);
+ if (rdn_name == NULL) {
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+
+ rdn_val = ldb_val_dup(msg, ldb_dn_get_rdn_val(ac->orig_req->op.rename.newdn));
+
+ if (ldb_msg_add_empty(msg, rdn_name, LDB_FLAG_MOD_REPLACE, NULL) != 0) {
return LDB_ERR_OPERATIONS_ERROR;
}
- if (ldb_msg_add_value(msg, rdn->name, &rdn->value, NULL) != 0) {
+ if (ldb_msg_add_value(msg, rdn_name, &rdn_val, NULL) != 0) {
return LDB_ERR_OPERATIONS_ERROR;
}
if (ldb_msg_add_empty(msg, "name", LDB_FLAG_MOD_REPLACE, NULL) != 0) {
return LDB_ERR_OPERATIONS_ERROR;
}
- if (ldb_msg_add_value(msg, "name", &rdn->value, NULL) != 0) {
+ if (ldb_msg_add_value(msg, "name", &rdn_val, NULL) != 0) {
return LDB_ERR_OPERATIONS_ERROR;
}