diff options
author | Stefan Metzmacher <metze@samba.org> | 2006-11-15 17:34:20 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 12:15:50 -0500 |
commit | 866a3b6e40952193d5bcd812ec7079cf7434e600 (patch) | |
tree | fe66f644d76f735fb642ec80df4c368d573b4745 /source3/lib/ldb/modules/ldb_map.c | |
parent | 06715191dd4347104efb3f8929290edc1f969752 (diff) | |
download | samba-866a3b6e40952193d5bcd812ec7079cf7434e600.tar.gz samba-866a3b6e40952193d5bcd812ec7079cf7434e600.tar.bz2 samba-866a3b6e40952193d5bcd812ec7079cf7434e600.zip |
r19725: sync samba3's ldb with samba4
metze
(This used to be commit 207643e9c9c75546f38a09f12ea0b574b08086c5)
Diffstat (limited to 'source3/lib/ldb/modules/ldb_map.c')
-rw-r--r-- | source3/lib/ldb/modules/ldb_map.c | 120 |
1 files changed, 46 insertions, 74 deletions
diff --git a/source3/lib/ldb/modules/ldb_map.c b/source3/lib/ldb/modules/ldb_map.c index 1cdeeeb293..32e64f3eb2 100644 --- a/source3/lib/ldb/modules/ldb_map.c +++ b/source3/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; } } @@ -1296,13 +1268,13 @@ static int map_init_maps(struct ldb_module *module, struct ldb_map_context *data } /* Copy the list of provided module operations. */ -struct ldb_module_ops ldb_map_get_ops(void) +_PUBLIC_ struct ldb_module_ops ldb_map_get_ops(void) { return map_ops; } /* Initialize global private data. */ -int ldb_map_init(struct ldb_module *module, const struct ldb_map_attribute *attrs, +_PUBLIC_ int ldb_map_init(struct ldb_module *module, const struct ldb_map_attribute *attrs, const struct ldb_map_objectclass *ocls, const char * const *wildcard_attributes, const char *name) |