r17698: The original code assumed that &data->context was a valid talloc
authorAndrew Bartlett <abartlet@samba.org>
Tue, 22 Aug 2006 06:01:47 +0000 (06:01 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 19:16:27 +0000 (14:16 -0500)
pointer.

This only works when this is the only structure member, but when I
added a new context pointer, it failed.

Andrew Bartlett
(This used to be commit 5bcfa12cef0d9eba5d5d1f65f676e7852297667f)

source4/lib/ldb/modules/ldb_map.c
source4/lib/ldb/modules/ldb_map.h

index 5f14e96dd867f5cc42f278babeaa902c56b9a1b0..2bc3416a934e310c616b1e079df36c71459db77d 100644 (file)
@@ -99,7 +99,7 @@
 const struct ldb_map_context *map_get_context(struct ldb_module *module)
 {
        const struct map_private *data = talloc_get_type(module->private_data, struct map_private);
-       return &data->context;
+       return data->context;
 }
 
 /* Create a generic request context. */
@@ -338,35 +338,37 @@ const struct ldb_map_attribute *map_attr_find_local(const struct ldb_map_context
 /* Find an attribute mapping by the remote name. */
 const struct ldb_map_attribute *map_attr_find_remote(const struct ldb_map_context *data, const char *name)
 {
+       const struct ldb_map_attribute *map;
        const struct ldb_map_attribute *wildcard = NULL;
        int i, j;
 
        for (i = 0; data->attribute_maps[i].local_name; i++) {
-               if (ldb_attr_cmp(data->attribute_maps[i].local_name, "*") == 0) {
+               map = &data->attribute_maps[i];
+               if (ldb_attr_cmp(map->local_name, "*") == 0) {
                        wildcard = &data->attribute_maps[i];
                }
 
-               switch (data->attribute_maps[i].type) {
+               switch (map->type) {
                case MAP_IGNORE:
                        break;
 
                case MAP_KEEP:
-                       if (ldb_attr_cmp(data->attribute_maps[i].local_name, name) == 0) {
-                               return &data->attribute_maps[i];
+                       if (ldb_attr_cmp(map->local_name, name) == 0) {
+                               return map;
                        }
                        break;
 
                case MAP_RENAME:
                case MAP_CONVERT:
-                       if (ldb_attr_cmp(data->attribute_maps[i].u.rename.remote_name, name) == 0) {
-                               return &data->attribute_maps[i];
+                       if (ldb_attr_cmp(map->u.rename.remote_name, name) == 0) {
+                               return map;
                        }
                        break;
 
                case MAP_GENERATE:
-                       for (j = 0; data->attribute_maps[i].u.generate.remote_names[j]; j++) {
-                               if (ldb_attr_cmp(data->attribute_maps[i].u.generate.remote_names[j], name) == 0) {
-                                       return &data->attribute_maps[i];
+                       for (j = 0; map->u.generate.remote_names && map->u.generate.remote_names[j]; j++) {
+                               if (ldb_attr_cmp(map->u.generate.remote_names[j], name) == 0) {
+                                       return map;
                                }
                        }
                        break;
@@ -1283,15 +1285,21 @@ int ldb_map_init(struct ldb_module *module, const struct ldb_map_attribute *attr
 
        module->private_data = data;
 
+       data->context = talloc_zero(data, struct ldb_map_context);
+       if (!data->context) {
+               map_oom(module);
+               return LDB_ERR_OPERATIONS_ERROR;                
+       }
+
        /* Store local and remote baseDNs */
-       ret = map_init_dns(module, &(data->context), name);
+       ret = map_init_dns(module, data->context, name);
        if (ret != LDB_SUCCESS) {
                talloc_free(data);
                return ret;
        }
 
        /* Store list of attribute and objectClass maps */
-       ret = map_init_maps(module, &(data->context), attrs, ocls);
+       ret = map_init_maps(module, data->context, attrs, ocls);
        if (ret != LDB_SUCCESS) {
                talloc_free(data);
                return ret;
index edd3eca87100b19099ae6a41acf703d4187f1151..e743970564348f71362f176f5f0969507361c64a 100644 (file)
@@ -138,7 +138,7 @@ struct ldb_map_context {
 /* Global private data */
 struct map_private {
        void *caller_private;
-       struct ldb_map_context context;
+       struct ldb_map_context *context;
 };
 
 /* initialization function */