summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorStephen Gallagher <sgallagh@redhat.com>2010-09-27 13:54:12 -0400
committerStephen Gallagher <sgallagh@redhat.com>2010-10-08 19:26:55 -0400
commit068bfb887e637522f99d0e5fd0a8313e2361d754 (patch)
treedb42312556bc775f3b23057e6dcb259a4a1cd676 /src
parent215951647b655b0aec12c1e1361071b03c57d09f (diff)
downloadsssd-068bfb887e637522f99d0e5fd0a8313e2361d754.tar.gz
sssd-068bfb887e637522f99d0e5fd0a8313e2361d754.tar.xz
sssd-068bfb887e637522f99d0e5fd0a8313e2361d754.zip
Add common hash table setup
sss_hash_create() produces a dhash table living in the talloc hierarchy.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am3
-rw-r--r--src/util/util.c53
-rw-r--r--src/util/util.h4
3 files changed, 59 insertions, 1 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 847e97ad3..1554ebb37 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -125,7 +125,8 @@ endif
libsss_crypt_la_SOURCES = \
$(SSS_CRYPT_SOURCES)
libsss_crypt_la_CPPFLAGS = \
- $(SSS_CRYPT_CFLAGS)
+ $(SSS_CRYPT_CFLAGS) \
+ $(DHASH_CFLAGS)
libsss_crypt_la_LIBADD = \
$(SSS_CRYPT_LIBS)
diff --git a/src/util/util.c b/src/util/util.c
index 10bfb647b..06eea2837 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -462,3 +462,56 @@ done:
talloc_free(tmp_ctx);
return ret;
}
+
+static void *hash_talloc(const size_t size, void *pvt)
+{
+ return talloc_size(pvt, size);
+}
+
+static void hash_talloc_free(void *ptr, void *pvt)
+{
+ talloc_free(ptr);
+}
+
+errno_t sss_hash_create(TALLOC_CTX *mem_ctx,
+ unsigned long count,
+ hash_table_t **tbl)
+{
+ errno_t ret;
+ hash_table_t *table;
+ int hret;
+
+ TALLOC_CTX *internal_ctx;
+ internal_ctx = talloc_new(NULL);
+ if (!internal_ctx) {
+ return ENOMEM;
+ }
+
+ hret = hash_create_ex(count, &table, 0, 0, 0, 0,
+ hash_talloc, hash_talloc_free,
+ internal_ctx, NULL, NULL);
+ switch (hret) {
+ case HASH_SUCCESS:
+ /* Steal the table pointer onto the mem_ctx,
+ * then make the internal_ctx a child of
+ * table.
+ *
+ * This way, we can clean up the values when
+ * we talloc_free() the table
+ */
+ *tbl = talloc_steal(mem_ctx, table);
+ talloc_steal(table, internal_ctx);
+ return EOK;
+
+ case HASH_ERROR_NO_MEMORY:
+ ret = ENOMEM;
+ default:
+ ret = EIO;
+ }
+
+ DEBUG(0, ("Could not create hash table: [%d][%s]\n",
+ hret, hash_error_string(hret)));
+
+ talloc_free(internal_ctx);
+ return ret;
+}
diff --git a/src/util/util.h b/src/util/util.h
index 6bcc9984d..7fcca3a6d 100644
--- a/src/util/util.h
+++ b/src/util/util.h
@@ -40,6 +40,7 @@
#include <talloc.h>
#include <tevent.h>
#include <ldb.h>
+#include <dhash.h>
#ifndef HAVE_ERRNO_T
#define HAVE_ERRNO_T
@@ -332,6 +333,9 @@ int split_on_separator(TALLOC_CTX *mem_ctx, const char *str,
char **parse_args(const char *str);
+errno_t sss_hash_create(TALLOC_CTX *mem_ctx,
+ unsigned long count,
+ hash_table_t **tbl);
/* Copy a NULL-terminated string list
* Returns NULL on out of memory error or invalid input