|
|
e543c9 |
From 62416ef0d547018872da915d0fe863780926d7be Mon Sep 17 00:00:00 2001
|
|
|
e543c9 |
From: Jakub Hrozek <jhrozek@redhat.com>
|
|
|
e543c9 |
Date: Fri, 22 May 2015 18:31:42 +0200
|
|
|
e543c9 |
Subject: [PATCH 205/207] SDAP: Add sdap_copy_map_entry
|
|
|
e543c9 |
|
|
|
e543c9 |
Reviewed-by: Pavel Reichl <preichl@redhat.com>
|
|
|
e543c9 |
(cherry picked from commit 12089241f6a6eabf4f0c95669e5fc2bb3b503c06)
|
|
|
e543c9 |
|
|
|
e543c9 |
Conflicts:
|
|
|
e543c9 |
src/tests/cmocka/test_sdap.c
|
|
|
e543c9 |
---
|
|
|
e543c9 |
src/providers/ldap/sdap.c | 17 +++++++++
|
|
|
e543c9 |
src/providers/ldap/sdap.h | 4 +++
|
|
|
e543c9 |
src/tests/cmocka/test_sdap.c | 82 ++++++++++++++++++++++++++++++++++++++++++++
|
|
|
e543c9 |
3 files changed, 103 insertions(+)
|
|
|
e543c9 |
|
|
|
e543c9 |
diff --git a/src/providers/ldap/sdap.c b/src/providers/ldap/sdap.c
|
|
|
e543c9 |
index e428d5f..bc9f8b3 100644
|
|
|
e543c9 |
--- a/src/providers/ldap/sdap.c
|
|
|
e543c9 |
+++ b/src/providers/ldap/sdap.c
|
|
|
e543c9 |
@@ -28,6 +28,23 @@
|
|
|
e543c9 |
|
|
|
e543c9 |
/* =Retrieve-Options====================================================== */
|
|
|
e543c9 |
|
|
|
e543c9 |
+errno_t sdap_copy_map_entry(const struct sdap_attr_map *src_map,
|
|
|
e543c9 |
+ struct sdap_attr_map *dst_map,
|
|
|
e543c9 |
+ int entry_index)
|
|
|
e543c9 |
+{
|
|
|
e543c9 |
+ if (src_map[entry_index].name != NULL) {
|
|
|
e543c9 |
+ dst_map[entry_index].name = talloc_strdup(dst_map,
|
|
|
e543c9 |
+ src_map[entry_index].name);
|
|
|
e543c9 |
+ if (dst_map[entry_index].name == NULL) {
|
|
|
e543c9 |
+ return ENOMEM;
|
|
|
e543c9 |
+ }
|
|
|
e543c9 |
+ } else {
|
|
|
e543c9 |
+ dst_map->name = NULL;
|
|
|
e543c9 |
+ }
|
|
|
e543c9 |
+
|
|
|
e543c9 |
+ return EOK;
|
|
|
e543c9 |
+}
|
|
|
e543c9 |
+
|
|
|
e543c9 |
int sdap_copy_map(TALLOC_CTX *memctx,
|
|
|
e543c9 |
struct sdap_attr_map *src_map,
|
|
|
e543c9 |
int num_entries,
|
|
|
e543c9 |
diff --git a/src/providers/ldap/sdap.h b/src/providers/ldap/sdap.h
|
|
|
e543c9 |
index 921051b..c0e9ff9 100644
|
|
|
e543c9 |
--- a/src/providers/ldap/sdap.h
|
|
|
e543c9 |
+++ b/src/providers/ldap/sdap.h
|
|
|
e543c9 |
@@ -467,6 +467,10 @@ struct sdap_deref_attrs {
|
|
|
e543c9 |
struct sysdb_attrs *attrs;
|
|
|
e543c9 |
};
|
|
|
e543c9 |
|
|
|
e543c9 |
+errno_t sdap_copy_map_entry(const struct sdap_attr_map *src_map,
|
|
|
e543c9 |
+ struct sdap_attr_map *dst_map,
|
|
|
e543c9 |
+ int entry_index);
|
|
|
e543c9 |
+
|
|
|
e543c9 |
int sdap_copy_map(TALLOC_CTX *memctx,
|
|
|
e543c9 |
struct sdap_attr_map *src_map,
|
|
|
e543c9 |
int num_entries,
|
|
|
e543c9 |
diff --git a/src/tests/cmocka/test_sdap.c b/src/tests/cmocka/test_sdap.c
|
|
|
e543c9 |
index 404e100..d1e6959 100644
|
|
|
e543c9 |
--- a/src/tests/cmocka/test_sdap.c
|
|
|
e543c9 |
+++ b/src/tests/cmocka/test_sdap.c
|
|
|
e543c9 |
@@ -718,6 +718,80 @@ void test_parse_no_dn(void **state)
|
|
|
e543c9 |
talloc_free(map);
|
|
|
e543c9 |
}
|
|
|
e543c9 |
|
|
|
e543c9 |
+struct copy_map_entry_test_ctx {
|
|
|
e543c9 |
+ struct sdap_attr_map *src_map;
|
|
|
e543c9 |
+ struct sdap_attr_map *dst_map;
|
|
|
e543c9 |
+};
|
|
|
e543c9 |
+
|
|
|
e543c9 |
+static void copy_map_entry_test_setup(void **state)
|
|
|
e543c9 |
+{
|
|
|
e543c9 |
+ int ret;
|
|
|
e543c9 |
+ struct copy_map_entry_test_ctx *test_ctx;
|
|
|
e543c9 |
+
|
|
|
e543c9 |
+ assert_true(leak_check_setup());
|
|
|
e543c9 |
+
|
|
|
e543c9 |
+ test_ctx = talloc_zero(global_talloc_context,
|
|
|
e543c9 |
+ struct copy_map_entry_test_ctx);
|
|
|
e543c9 |
+ assert_non_null(test_ctx);
|
|
|
e543c9 |
+
|
|
|
e543c9 |
+ ret = sdap_copy_map(test_ctx, rfc2307_user_map,
|
|
|
e543c9 |
+ SDAP_OPTS_USER, &test_ctx->src_map);
|
|
|
e543c9 |
+ assert_int_equal(ret, ERR_OK);
|
|
|
e543c9 |
+
|
|
|
e543c9 |
+ ret = sdap_copy_map(test_ctx, rfc2307_user_map,
|
|
|
e543c9 |
+ SDAP_OPTS_USER, &test_ctx->dst_map);
|
|
|
e543c9 |
+ assert_int_equal(ret, ERR_OK);
|
|
|
e543c9 |
+
|
|
|
e543c9 |
+ check_leaks_push(test_ctx);
|
|
|
e543c9 |
+ *state = test_ctx;
|
|
|
e543c9 |
+}
|
|
|
e543c9 |
+
|
|
|
e543c9 |
+static void copy_map_entry_test_teardown(void **state)
|
|
|
e543c9 |
+{
|
|
|
e543c9 |
+ struct copy_map_entry_test_ctx *test_ctx = talloc_get_type_abort(*state,
|
|
|
e543c9 |
+ struct copy_map_entry_test_ctx);
|
|
|
e543c9 |
+ assert_true(check_leaks_pop(test_ctx) == true);
|
|
|
e543c9 |
+ talloc_free(test_ctx);
|
|
|
e543c9 |
+ assert_true(leak_check_teardown());
|
|
|
e543c9 |
+ return 0;
|
|
|
e543c9 |
+}
|
|
|
e543c9 |
+
|
|
|
e543c9 |
+static const char *copy_uuid(struct copy_map_entry_test_ctx *test_ctx)
|
|
|
e543c9 |
+{
|
|
|
e543c9 |
+ errno_t ret;
|
|
|
e543c9 |
+
|
|
|
e543c9 |
+ assert_null(test_ctx->dst_map[SDAP_AT_USER_UUID].name);
|
|
|
e543c9 |
+ ret = sdap_copy_map_entry(test_ctx->src_map, test_ctx->dst_map,
|
|
|
e543c9 |
+ SDAP_AT_USER_UUID);
|
|
|
e543c9 |
+ assert_int_equal(ret, EOK);
|
|
|
e543c9 |
+ return test_ctx->dst_map[SDAP_AT_USER_UUID].name;
|
|
|
e543c9 |
+}
|
|
|
e543c9 |
+
|
|
|
e543c9 |
+static void test_sdap_copy_map_entry(void **state)
|
|
|
e543c9 |
+{
|
|
|
e543c9 |
+ struct copy_map_entry_test_ctx *test_ctx = talloc_get_type_abort(*state,
|
|
|
e543c9 |
+ struct copy_map_entry_test_ctx);
|
|
|
e543c9 |
+ const char *uuid_set_val = "test_uuid_val";
|
|
|
e543c9 |
+ const char *uuid_val = NULL;
|
|
|
e543c9 |
+
|
|
|
e543c9 |
+ test_ctx->src_map[SDAP_AT_USER_UUID].name = discard_const(uuid_set_val);
|
|
|
e543c9 |
+
|
|
|
e543c9 |
+ uuid_val = copy_uuid(test_ctx);
|
|
|
e543c9 |
+ assert_non_null(uuid_val);
|
|
|
e543c9 |
+ assert_string_equal(uuid_val, uuid_set_val);
|
|
|
e543c9 |
+ talloc_free(test_ctx->dst_map[SDAP_AT_USER_UUID].name);
|
|
|
e543c9 |
+}
|
|
|
e543c9 |
+
|
|
|
e543c9 |
+static void test_sdap_copy_map_entry_null_name(void **state)
|
|
|
e543c9 |
+{
|
|
|
e543c9 |
+ struct copy_map_entry_test_ctx *test_ctx = talloc_get_type_abort(*state,
|
|
|
e543c9 |
+ struct copy_map_entry_test_ctx);
|
|
|
e543c9 |
+ const char *uuid_val = NULL;
|
|
|
e543c9 |
+
|
|
|
e543c9 |
+ uuid_val = copy_uuid(test_ctx);
|
|
|
e543c9 |
+ assert_null(uuid_val);
|
|
|
e543c9 |
+}
|
|
|
e543c9 |
+
|
|
|
e543c9 |
int main(int argc, const char *argv[])
|
|
|
e543c9 |
{
|
|
|
e543c9 |
poptContext pc;
|
|
|
e543c9 |
@@ -763,6 +837,14 @@ int main(int argc, const char *argv[])
|
|
|
e543c9 |
unit_test_setup_teardown(test_parse_deref_map_mismatch,
|
|
|
e543c9 |
parse_entry_test_setup,
|
|
|
e543c9 |
parse_entry_test_teardown),
|
|
|
e543c9 |
+
|
|
|
e543c9 |
+ /* Map option tests */
|
|
|
e543c9 |
+ unit_test_setup_teardown(test_sdap_copy_map_entry,
|
|
|
e543c9 |
+ copy_map_entry_test_setup,
|
|
|
e543c9 |
+ copy_map_entry_test_teardown),
|
|
|
e543c9 |
+ unit_test_setup_teardown(test_sdap_copy_map_entry_null_name,
|
|
|
e543c9 |
+ copy_map_entry_test_setup,
|
|
|
e543c9 |
+ copy_map_entry_test_teardown),
|
|
|
e543c9 |
};
|
|
|
e543c9 |
|
|
|
e543c9 |
/* Set debug level to invalid value so we can deside if -d 0 was used. */
|
|
|
e543c9 |
--
|
|
|
e543c9 |
2.1.0
|
|
|
e543c9 |
|