From a599edf04cbdeef9014923ba0d3713b8ff84f266 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 12 Oct 2005 06:10:23 +0000 Subject: r10913: This patch isn't as big as it looks ... most of the changes are fixes to make all the ldb code compile without warnings on gcc4. Unfortunately That required a lot of casts :-( I have also added the start of an 'operational' module, which will replace the timestamp module, plus add support for some other operational attributes In ldb_msg_*() I added some new utility functions to make the operational module sane, and remove the 'ldb' argument from the ldb_msg_add_*() functions. That argument was only needed back in the early days of ldb when we didn't use the hierarchical talloc and thus needed a place to get the allocation function from. Now its just a pain to pass around everywhere. Also added a ldb_debug_set() function that calls ldb_debug() plus sets the result using ldb_set_errstring(). That saves on some awkward coding in a few places. (This used to be commit f6818daecca95760c12f79fd307770cbe3346f57) --- source4/lib/ldb/modules/schema.c | 81 ++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 54 deletions(-) (limited to 'source4/lib/ldb/modules/schema.c') diff --git a/source4/lib/ldb/modules/schema.c b/source4/lib/ldb/modules/schema.c index 0cae110487..27177116c2 100644 --- a/source4/lib/ldb/modules/schema.c +++ b/source4/lib/ldb/modules/schema.c @@ -106,7 +106,7 @@ static int get_msg_attributes(struct schema_structures *ss, const struct ldb_mes } for (j = 0, cnum = ss->objectclasses.num; j < msg->elements[i].num_values; j++) { - ss->objectclasses.attr[cnum+j].name = msg->elements[i].values[j].data; + ss->objectclasses.attr[cnum+j].name = (char *)msg->elements[i].values[j].data; ss->objectclasses.attr[cnum+j].flags = msg->elements[i].flags & flag_mask; } ss->objectclasses.num += msg->elements[i].num_values; @@ -164,14 +164,15 @@ static int add_attribute_uniq(void *mem_ctx, struct schema_attribute_list *list, for (c = 0; c < list->num; c++) { len = strlen(list->attr[c].name); if (len == el->values[i].length) { - if (ldb_attr_cmp(list->attr[c].name, el->values[i].data) == 0) { + if (ldb_attr_cmp(list->attr[c].name, + (char *)el->values[i].data) == 0) { found = 1; break; } } } if (!found) { - list->attr[j + list->num].name = el->values[i].data; + list->attr[j + list->num].name = (char *)el->values[i].data; list->attr[j + list->num].flags = flags; j++; } @@ -187,7 +188,6 @@ static int add_attribute_uniq(void *mem_ctx, struct schema_attribute_list *list, static int get_attr_list_recursive(struct ldb_module *module, struct schema_structures *schema_struct) { struct ldb_message **srch; - char *error_string; int i, j; int ret; @@ -209,21 +209,18 @@ static int get_attr_list_recursive(struct ldb_module *module, struct schema_stru talloc_steal(schema_struct, srch); if (ret <= 0) { - /* Schema DB Error: Error occurred retrieving Object Class Description */ - error_string = talloc_asprintf(module, "Error retrieving Objectclass %s.\n", schema_struct->objectclasses.attr[i].name); - if (error_string) { - ldb_set_errstring(module, error_string); - ldb_debug(module->ldb, LDB_DEBUG_ERROR, error_string); - } + /* Schema DB Error: Error occurred retrieving + Object Class Description */ + ldb_debug_set(module->ldb, LDB_DEBUG_ERROR, + "Error retrieving Objectclass %s.\n", + schema_struct->objectclasses.attr[i].name); return -1; } if (ret > 1) { /* Schema DB Error: Too Many Records */ - error_string = talloc_asprintf(module, "Too many records found retrieving Objectclass %s.\n", schema_struct->objectclasses.attr[i].name); - if (error_string) { - ldb_set_errstring(module, error_string); - ldb_debug(module->ldb, LDB_DEBUG_ERROR, error_string); - } + ldb_debug_set(module->ldb, LDB_DEBUG_ERROR, + "Too many records found retrieving Objectclass %s.\n", + schema_struct->objectclasses.attr[i].name); return -1; } @@ -294,7 +291,6 @@ static int schema_search_bytree(struct ldb_module *module, const struct ldb_dn * static int schema_add_record(struct ldb_module *module, const struct ldb_message *msg) { struct schema_structures *entry_structs; - char *error_string; unsigned int i; int ret; @@ -338,13 +334,9 @@ static int schema_add_record(struct ldb_module *module, const struct ldb_message entry_structs->required_attrs.attr[i].name); if (attr == NULL) { /* not found */ - error_string = talloc_asprintf(module, - "The required_attrs attribute %s is missing.\n", - entry_structs->required_attrs.attr[i].name); - if (error_string) { - ldb_set_errstring(module, error_string); - ldb_debug(module->ldb, LDB_DEBUG_ERROR, error_string); - } + ldb_debug_set(module->ldb, LDB_DEBUG_ERROR, + "The required_attrs attribute %s is missing.\n", + entry_structs->required_attrs.attr[i].name); talloc_free(entry_structs); return LDB_ERR_OBJECT_CLASS_VIOLATION; } @@ -363,13 +355,9 @@ static int schema_add_record(struct ldb_module *module, const struct ldb_message entry_structs->entry_attrs.attr[i].name); if (attr == NULL) { /* not found */ - error_string = talloc_asprintf(module, - "The attribute %s is not referenced by any objectclass.\n", - entry_structs->entry_attrs.attr[i].name); - if (error_string) { - ldb_set_errstring(module, error_string); - ldb_debug(module->ldb, LDB_DEBUG_ERROR, error_string); - } + ldb_debug_set(module->ldb, LDB_DEBUG_ERROR, + "The attribute %s is not referenced by any objectclass.\n", + entry_structs->entry_attrs.attr[i].name); talloc_free(entry_structs); return LDB_ERR_OBJECT_CLASS_VIOLATION; } @@ -385,7 +373,6 @@ static int schema_add_record(struct ldb_module *module, const struct ldb_message static int schema_modify_record(struct ldb_module *module, const struct ldb_message *msg) { struct schema_structures *entry_structs; - char *error_string; unsigned int i; int ret; @@ -437,13 +424,9 @@ static int schema_modify_record(struct ldb_module *module, const struct ldb_mess entry_structs->required_attrs.attr[i].name); if (attr == NULL) { /* not found */ - error_string = talloc_asprintf(module, - "The required_attrs attribute %s is missing.\n", - entry_structs->required_attrs.attr[i].name); - if (error_string) { - ldb_set_errstring(module, error_string); - ldb_debug(module->ldb, LDB_DEBUG_ERROR, error_string); - } + ldb_debug_set(module->ldb, LDB_DEBUG_ERROR, + "The required_attrs attribute %s is missing.\n", + entry_structs->required_attrs.attr[i].name); talloc_free(entry_structs); return LDB_ERR_OBJECT_CLASS_VIOLATION; } @@ -451,14 +434,9 @@ static int schema_modify_record(struct ldb_module *module, const struct ldb_mess /* check we are not trying to delete a required attribute */ /* TODO: consider multivalued attrs */ if ((attr->flags & SCHEMA_FLAG_MOD_DELETE) != 0) { - error_string = talloc_asprintf(module, - "Trying to delete the required attribute %s.\n", - attr->name); - if (error_string) { - ldb_set_errstring(module, error_string); - ldb_debug(module->ldb, LDB_DEBUG_ERROR, error_string); - } - + ldb_debug_set(module->ldb, LDB_DEBUG_ERROR, + "Trying to delete the required attribute %s.\n", + attr->name); talloc_free(entry_structs); return LDB_ERR_OBJECT_CLASS_VIOLATION; } @@ -477,14 +455,9 @@ static int schema_modify_record(struct ldb_module *module, const struct ldb_mess entry_structs->entry_attrs.attr[i].name); if (attr == NULL) { /* not found */ - error_string = talloc_asprintf(module, - "The attribute %s is not referenced by any objectclass.\n", - entry_structs->entry_attrs.attr[i].name); - if (error_string) { - ldb_set_errstring(module, error_string); - ldb_debug(module->ldb, LDB_DEBUG_ERROR, error_string); - } - + ldb_debug_set(module->ldb, LDB_DEBUG_ERROR, + "The attribute %s is not referenced by any objectclass.\n", + entry_structs->entry_attrs.attr[i].name); talloc_free(entry_structs); return LDB_ERR_OBJECT_CLASS_VIOLATION; } -- cgit