summaryrefslogtreecommitdiffstats
path: root/server/util
diff options
context:
space:
mode:
authorStephen Gallagher <sgallagh@redhat.com>2009-02-27 13:35:33 -0500
committerSimo Sorce <ssorce@redhat.com>2009-02-27 17:11:23 -0500
commit24480f7fa3bf3f40bd9fb7c865f9e3b329bf3ed8 (patch)
tree735441471a4e8c5fcc2dd9b9311b000f44584e29 /server/util
parent60bbc5034e546b7df7a6f782e3353b863f49618b (diff)
downloadsssd-24480f7fa3bf3f40bd9fb7c865f9e3b329bf3ed8.tar.gz
sssd-24480f7fa3bf3f40bd9fb7c865f9e3b329bf3ed8.tar.xz
sssd-24480f7fa3bf3f40bd9fb7c865f9e3b329bf3ed8.zip
Refactor creation of domain_map into confdb
The NSS provider, the Data Provider backends and the InfoPipe all need access to the domain map provided by the confdb. Instead of reimplimenting it in multiple places, it is now provided in a pair of helper functions from the confdb. confdb_get_domains() returns a domain map by reference. Always returns the most up-to-date set of domains from the confdb. confdb_get_domains_list() returns an array of strings of all the domain names. Always returns the most up-to-date set of domains from the confdb. This patch also modifies the btreemap_get_keys() function to better handle memory and report allocation failures.
Diffstat (limited to 'server/util')
-rw-r--r--server/util/btreemap.c46
-rw-r--r--server/util/btreemap.h2
2 files changed, 39 insertions, 9 deletions
diff --git a/server/util/btreemap.c b/server/util/btreemap.c
index c9289f521..7bda0570a 100644
--- a/server/util/btreemap.c
+++ b/server/util/btreemap.c
@@ -166,21 +166,51 @@ int btreemap_set_value(TALLOC_CTX *mem_ctx,
return EOK;
}
-/* Return an array of keys in sort order
- * count should be initialized to zero before calling this function.
- */
-void btreemap_get_keys(TALLOC_CTX *mem_ctx, struct btreemap *map, const void ***array, int *count)
+static int _btreemap_get_keys(TALLOC_CTX *mem_ctx, struct btreemap *map, const void ***array, int *count, int depth)
{
- if (map == NULL) return;
+ int ret;
+ const void **tmp_array;
+
+ if (map == NULL) {
+ if (depth == 0) {
+ /* This is the top-level */
+ count = 0;
+ *array = NULL;
+ }
+ return EOK;
+ }
/* Left Node */
- btreemap_get_keys(mem_ctx, map->left, array, count);
+ ret = _btreemap_get_keys(mem_ctx, map->left, array, count, depth+1);
+ if (ret != EOK) {
+ return ret;
+ }
/* Current Node */
(*count)++;
- *array = talloc_realloc(mem_ctx, *array, const void *, *count);
+ tmp_array = talloc_realloc(mem_ctx, *array, const void *, *count);
+ if (tmp_array == NULL) {
+ /* Out of memory */
+ *count = 0;
+ talloc_free(*array);
+ *array = NULL;
+ return ENOMEM;
+ }
+ *array = tmp_array;
(*array)[(*count)-1] = map->key;
/* Right Node */
- btreemap_get_keys(mem_ctx, map->right, array, count);
+ ret = _btreemap_get_keys(mem_ctx, map->right, array, count, depth+1);
+ if (ret != EOK) {
+ return ret;
+ }
+
+ return EOK;
+}
+/* Return an array of keys in sort order
+ */
+int btreemap_get_keys(TALLOC_CTX *mem_ctx, struct btreemap *map, const void ***array, int *count)
+{
+ *array = NULL;
+ return _btreemap_get_keys(mem_ctx, map, array, count, 0);
}
diff --git a/server/util/btreemap.h b/server/util/btreemap.h
index c5c415075..8d7fb1595 100644
--- a/server/util/btreemap.h
+++ b/server/util/btreemap.h
@@ -35,7 +35,7 @@ void *btreemap_get_value(struct btreemap *map, const void *key);
int btreemap_set_value(TALLOC_CTX *mem_ctx,
struct btreemap **map, const void *key, void *value,
btreemap_comparison_fn comparator);
-void btreemap_get_keys(TALLOC_CTX *mem_ctx, struct btreemap *map, const void ***array, int *count);
+int btreemap_get_keys(TALLOC_CTX *mem_ctx, struct btreemap *map, const void ***array, int *count);
#endif /*BTREEMAP_H_*/