r12658: Couple of fixes related to shared module builds.
[abartlet/samba.git/.git] / source4 / lib / ldb / modules / schema.c
index 1a2c2b8f978d908deb15c754917caa6d2ad4d0a0..9fb2efee30c7d96f093f26beac56ebf1c598aa6e 100644 (file)
@@ -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;
@@ -128,7 +128,7 @@ static int get_msg_attributes(struct schema_structures *ss, const struct ldb_mes
 
 static int get_entry_attributes(struct ldb_context *ldb, const struct ldb_dn *dn, struct schema_structures *ss)
 {
-       struct ldb_message **srch;
+       struct ldb_result *srch;
        int ret;
 
        ret = ldb_search(ldb, dn, LDB_SCOPE_BASE, NULL, NULL, &srch);
@@ -138,7 +138,7 @@ static int get_entry_attributes(struct ldb_context *ldb, const struct ldb_dn *dn
        talloc_steal(ss, srch);
 
        /* set flags to 0 as flags on search have undefined values */
-       ret = get_msg_attributes(ss, *srch, 0);
+       ret = get_msg_attributes(ss, *(srch->msgs), 0);
        if (ret != 0) {
                talloc_free(srch);
                return ret;
@@ -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++;
                }
@@ -186,8 +187,7 @@ static int add_attribute_uniq(void *mem_ctx, struct schema_attribute_list *list,
    recursively get parent objectlasses attributes */
 static int get_attr_list_recursive(struct ldb_module *module, struct schema_structures *schema_struct)
 {
-       struct ldb_message **srch;
-       char *error_string;
+       struct ldb_result *srch;
        int i, j;
        int ret;
 
@@ -209,40 +209,37 @@ 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;
                }
 
                /* Add inherited classes eliminating duplicates */
                /* fill in required_attrs and optional_attrs attribute lists */
-               for (j = 0; j < (*srch)->num_elements; j++) {
+               for (j = 0; j < srch->msgs[0]->num_elements; j++) {
                        int is_aux, is_class;
 
                        is_aux = 0;
                        is_class = 0;
-                       if (ldb_attr_cmp((*srch)->elements[j].name, "systemAuxiliaryclass") == 0) {
+                       if (ldb_attr_cmp(srch->msgs[0]->elements[j].name, "systemAuxiliaryclass") == 0) {
                                is_aux = SCHEMA_FLAG_AUXILIARY;
                                is_class = 1;
                        }
-                       if (ldb_attr_cmp((*srch)->elements[j].name, "auxiliaryClass") == 0) {
+                       if (ldb_attr_cmp(srch->msgs[0]->elements[j].name, "auxiliaryClass") == 0) {
                                is_aux = SCHEMA_FLAG_AUXILIARY;
                                is_class = 1;
                        }
-                       if (ldb_attr_cmp((*srch)->elements[j].name, "subClassOf") == 0) {
+                       if (ldb_attr_cmp(srch->msgs[0]->elements[j].name, "subClassOf") == 0) {
                                is_class = 1;
                        }
 
@@ -250,28 +247,28 @@ static int get_attr_list_recursive(struct ldb_module *module, struct schema_stru
                                if (add_attribute_uniq(schema_struct,
                                                        &schema_struct->objectclasses,
                                                        is_aux,
-                                                       &(*srch)->elements[j]) != 0) {
+                                                       &srch->msgs[0]->elements[j]) != 0) {
                                        return -1;
                                }
                        } else {
 
-                               if (ldb_attr_cmp((*srch)->elements[j].name, "mustContain") == 0 ||
-                                       ldb_attr_cmp((*srch)->elements[j].name, "SystemMustContain") == 0) {
+                               if (ldb_attr_cmp(srch->msgs[0]->elements[j].name, "mustContain") == 0 ||
+                                       ldb_attr_cmp(srch->msgs[0]->elements[j].name, "SystemMustContain") == 0) {
                                        if (add_attribute_uniq(schema_struct,
                                                                &schema_struct->required_attrs,
                                                                SCHEMA_FLAG_RESET,
-                                                               &(*srch)->elements[j]) != 0) {
+                                                               &srch->msgs[0]->elements[j]) != 0) {
                                                return -1;
                                        }
                                }
 
-                               if (ldb_attr_cmp((*srch)->elements[j].name, "mayContain") == 0 ||
-                                   ldb_attr_cmp((*srch)->elements[j].name, "SystemMayContain") == 0) {
+                               if (ldb_attr_cmp(srch->msgs[0]->elements[j].name, "mayContain") == 0 ||
+                                   ldb_attr_cmp(srch->msgs[0]->elements[j].name, "SystemMayContain") == 0) {
 
                                        if (add_attribute_uniq(schema_struct,
                                                                &schema_struct->optional_attrs,
                                                                SCHEMA_FLAG_RESET,
-                                                               &(*srch)->elements[j]) != 0) {
+                                                               &srch->msgs[0]->elements[j]) != 0) {
                                                return -1;
                                        }
                                }
@@ -282,26 +279,11 @@ static int get_attr_list_recursive(struct ldb_module *module, struct schema_stru
        return 0;
 }
 
-/* search */
-static int schema_search(struct ldb_module *module, const struct ldb_dn *base,
-                      enum ldb_scope scope, const char *expression,
-                      const char * const *attrs, struct ldb_message ***res)
-{
-       return ldb_next_search(module, base, scope, expression, attrs, res); 
-}
-
-static int schema_search_bytree(struct ldb_module *module, const struct ldb_dn *base,
-                               enum ldb_scope scope, struct ldb_parse_tree *tree,
-                               const char * const *attrs, struct ldb_message ***res)
-{
-       return ldb_next_search_bytree(module, base, scope, tree, attrs, res); 
-}
-
 /* add_record */
-static int schema_add_record(struct ldb_module *module, const struct ldb_message *msg)
+static int schema_add(struct ldb_module *module, struct ldb_request *req)
 {
+       const struct ldb_message *msg = req->op.add.message;
        struct schema_structures *entry_structs;
-       char *error_string;
        unsigned int i;
        int ret;
 
@@ -315,7 +297,7 @@ static int schema_add_record(struct ldb_module *module, const struct ldb_message
 
        /* do not check on our control entries */
        if (ldb_dn_is_special(msg->dn)) {
-               return ldb_next_add_record(module, msg);
+               return ldb_next_request(module, req);
        }
 
        /* TODO: check parent exists */
@@ -345,13 +327,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;
                }
@@ -370,13 +348,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,14 +359,14 @@ static int schema_add_record(struct ldb_module *module, const struct ldb_message
 
        talloc_free(entry_structs);
 
-       return ldb_next_add_record(module, msg);
+       return ldb_next_request(module, req);
 }
 
 /* modify_record */
-static int schema_modify_record(struct ldb_module *module, const struct ldb_message *msg)
+static int schema_modify(struct ldb_module *module, struct ldb_request *req)
 {
+       const struct ldb_message *msg = req->op.mod.message;
        struct schema_structures *entry_structs;
-       char *error_string;
        unsigned int i;
        int ret;
 
@@ -407,7 +381,7 @@ static int schema_modify_record(struct ldb_module *module, const struct ldb_mess
 
        /* do not check on our control entries */
        if (ldb_dn_is_special(msg->dn)) {
-               return ldb_next_add_record(module, msg);
+               return ldb_next_request(module, req);
        }
 
        /* allocate object structs */
@@ -444,13 +418,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;
                }
@@ -458,14 +428,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;
                }
@@ -484,14 +449,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;
                        }
@@ -500,54 +460,31 @@ static int schema_modify_record(struct ldb_module *module, const struct ldb_mess
 
        talloc_free(entry_structs);
 
-       return ldb_next_modify_record(module, msg);
+       return ldb_next_request(module, req);
 }
 
-/* delete_record */
-static int schema_delete_record(struct ldb_module *module, const struct ldb_dn *dn)
+static int schema_request(struct ldb_module *module, struct ldb_request *req)
 {
-/*     struct private_data *data = (struct private_data *)module->private_data; */
-       return ldb_next_delete_record(module, dn);
-}
+       switch (req->operation) {
 
-/* rename_record */
-static int schema_rename_record(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn)
-{
-       return ldb_next_rename_record(module, olddn, newdn);
-}
+       case LDB_REQ_ADD:
+               return schema_add(module, req);
 
-static int schema_start_trans(struct ldb_module *module) {
-       return ldb_next_start_trans(module);
-}
+       case LDB_REQ_MODIFY:
+               return schema_modify(module, req);
 
-static int schema_end_trans(struct ldb_module *module, int status) {
-       return ldb_next_end_trans(module, status);
-}
+       default:
+               return ldb_next_request(module, req);
 
-static int schema_destructor(void *module_ctx)
-{
-/*     struct ldb_module *ctx = module_ctx; */
-       /* put your clean-up functions here */
-       return 0;
+       }
 }
 
 static const struct ldb_module_ops schema_ops = {
        .name              = "schema",
-       .search            = schema_search,
-       .search_bytree     = schema_search_bytree,
-       .add_record        = schema_add_record,
-       .modify_record     = schema_modify_record,
-       .delete_record     = schema_delete_record,
-       .rename_record     = schema_rename_record,
-       .start_transaction = schema_start_trans,
-       .end_transaction   = schema_end_trans
+       .request           = schema_request
 };
 
-#ifdef HAVE_DLOPEN_DISABLED
-struct ldb_module *init_module(struct ldb_context *ldb, const char *options[])
-#else
 struct ldb_module *schema_module_init(struct ldb_context *ldb, const char *options[])
-#endif
 {
        struct ldb_module *ctx;
 
@@ -561,7 +498,5 @@ struct ldb_module *schema_module_init(struct ldb_context *ldb, const char *optio
        ctx->prev = ctx->next = NULL;
        ctx->ops = &schema_ops;
 
-       talloc_set_destructor (ctx, schema_destructor);
-
        return ctx;
 }