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 | |
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')
-rw-r--r-- | source3/lib/ldb/modules/asq.c | 3 | ||||
-rw-r--r-- | source3/lib/ldb/modules/ldb_map.c | 120 | ||||
-rw-r--r-- | source3/lib/ldb/modules/ldb_map_inbound.c | 2 | ||||
-rw-r--r-- | source3/lib/ldb/modules/ldb_map_outbound.c | 11 | ||||
-rw-r--r-- | source3/lib/ldb/modules/ldb_map_private.h | 4 | ||||
-rw-r--r-- | source3/lib/ldb/modules/paged_results.c | 4 | ||||
-rw-r--r-- | source3/lib/ldb/modules/rdn_name.c | 46 | ||||
-rw-r--r-- | source3/lib/ldb/modules/sort.c | 4 |
8 files changed, 84 insertions, 110 deletions
diff --git a/source3/lib/ldb/modules/asq.c b/source3/lib/ldb/modules/asq.c index 354bbf2bc8..2fed6aac50 100644 --- a/source3/lib/ldb/modules/asq.c +++ b/source3/lib/ldb/modules/asq.c @@ -454,8 +454,7 @@ static int asq_init(struct ldb_module *module) ret = ldb_request(module->ldb, req); if (ret != LDB_SUCCESS) { - ldb_debug(module->ldb, LDB_DEBUG_ERROR, "asq: Unable to register control with rootdse!\n"); - return LDB_ERR_OTHER; + ldb_debug(module->ldb, LDB_DEBUG_WARNING, "asq: Unable to register control with rootdse!\n"); } return ldb_next_init(module); 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) diff --git a/source3/lib/ldb/modules/ldb_map_inbound.c b/source3/lib/ldb/modules/ldb_map_inbound.c index b83a17e502..38454b2b11 100644 --- a/source3/lib/ldb/modules/ldb_map_inbound.c +++ b/source3/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/source3/lib/ldb/modules/ldb_map_outbound.c b/source3/lib/ldb/modules/ldb_map_outbound.c index ff3b5c3aa2..dc213f36d1 100644 --- a/source3/lib/ldb/modules/ldb_map_outbound.c +++ b/source3/lib/ldb/modules/ldb_map_outbound.c @@ -195,6 +195,7 @@ static int ldb_msg_replace(struct ldb_message *msg, const struct ldb_message_ele if (ldb_msg_add_empty(msg, el->name, 0, &old) != 0) { return -1; } + talloc_free(old->name); } /* copy new element */ @@ -234,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; @@ -728,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/source3/lib/ldb/modules/ldb_map_private.h b/source3/lib/ldb/modules/ldb_map_private.h index 7fb2745179..ae53ebbdd4 100644 --- a/source3/lib/ldb/modules/ldb_map_private.h +++ b/source3/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/source3/lib/ldb/modules/paged_results.c b/source3/lib/ldb/modules/paged_results.c index 3ab575ef6b..c4b1ecf26b 100644 --- a/source3/lib/ldb/modules/paged_results.c +++ b/source3/lib/ldb/modules/paged_results.c @@ -544,9 +544,7 @@ static int paged_request_init(struct ldb_module *module) ret = ldb_request(module->ldb, req); if (ret != LDB_SUCCESS) { - ldb_debug(module->ldb, LDB_DEBUG_ERROR, "paged_request: Unable to register control with rootdse!\n"); - talloc_free(req); - return LDB_ERR_OTHER; + ldb_debug(module->ldb, LDB_DEBUG_WARNING, "paged_request: Unable to register control with rootdse!\n"); } talloc_free(req); diff --git a/source3/lib/ldb/modules/rdn_name.c b/source3/lib/ldb/modules/rdn_name.c index 510a43dbc9..bab5f6a014 100644 --- a/source3/lib/ldb/modules/rdn_name.c +++ b/source3/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; } diff --git a/source3/lib/ldb/modules/sort.c b/source3/lib/ldb/modules/sort.c index 3a0598c528..4fa03f8bfa 100644 --- a/source3/lib/ldb/modules/sort.c +++ b/source3/lib/ldb/modules/sort.c @@ -423,9 +423,7 @@ static int server_sort_init(struct ldb_module *module) ret = ldb_request(module->ldb, req); if (ret != LDB_SUCCESS) { - ldb_debug(module->ldb, LDB_DEBUG_ERROR, "server_sort: Unable to register control with rootdse!\n"); - talloc_free(req); - return LDB_ERR_OTHER; + ldb_debug(module->ldb, LDB_DEBUG_WARNING, "server_sort: Unable to register control with rootdse!\n"); } talloc_free(req); |