From b1f74ee745aa84f53fe330d55fafb9810012f875 Mon Sep 17 00:00:00 2001
From: Sumit Bose <sbose@redhat.com>
Date: Thu, 28 Nov 2013 11:28:39 +0100
Subject: [PATCH 37/41] Add sysdb_attrs_add_lc_name_alias
---
src/db/sysdb.c | 22 ++++++++++++++++++++++
src/db/sysdb.h | 2 ++
src/tests/sysdb-tests.c | 29 +++++++++++++++++++++++++++++
3 files changed, 53 insertions(+)
diff --git a/src/db/sysdb.c b/src/db/sysdb.c
index da5dbe84c2415025a188544f4b4c944888f07888..2a4be58008fc1164765db26aaba3886071448d30 100644
--- a/src/db/sysdb.c
+++ b/src/db/sysdb.c
@@ -618,6 +618,28 @@ int sysdb_attrs_add_time_t(struct sysdb_attrs *attrs,
return ret;
}
+int sysdb_attrs_add_lc_name_alias(struct sysdb_attrs *attrs,
+ const char *value)
+{
+ char *lc_str;
+ int ret;
+
+ if (attrs == NULL || value == NULL) {
+ return EINVAL;
+ }
+
+ lc_str = sss_tc_utf8_str_tolower(attrs, value);
+ if (lc_str == NULL) {
+ DEBUG(SSSDBG_OP_FAILURE, ("Cannot convert name to lowercase\n"));
+ return ENOMEM;
+ }
+
+ ret = sysdb_attrs_add_string(attrs, SYSDB_NAME_ALIAS, lc_str);
+ talloc_free(lc_str);
+
+ return ret;
+}
+
int sysdb_attrs_copy_values(struct sysdb_attrs *src,
struct sysdb_attrs *dst,
const char *name)
diff --git a/src/db/sysdb.h b/src/db/sysdb.h
index 4d5ef0b4794a85aa7fbc8f261d42eddd1043284e..f3358d642efd1c13203061c43e455a5c26c72740 100644
--- a/src/db/sysdb.h
+++ b/src/db/sysdb.h
@@ -274,6 +274,8 @@ int sysdb_attrs_add_uint32(struct sysdb_attrs *attrs,
const char *name, uint32_t value);
int sysdb_attrs_add_time_t(struct sysdb_attrs *attrs,
const char *name, time_t value);
+int sysdb_attrs_add_lc_name_alias(struct sysdb_attrs *attrs,
+ const char *value);
int sysdb_attrs_copy_values(struct sysdb_attrs *src,
struct sysdb_attrs *dst,
const char *name);
diff --git a/src/tests/sysdb-tests.c b/src/tests/sysdb-tests.c
index ddbf6f28fd5024945fedcb3c6e2122948c4f1459..63ffac82e15849e5f6534462ce7c58b183412acc 100644
--- a/src/tests/sysdb-tests.c
+++ b/src/tests/sysdb-tests.c
@@ -4422,6 +4422,33 @@ START_TEST(test_sysdb_svc_remove_alias)
}
END_TEST
+#define LC_NAME_ALIAS_TEST_VAL "TeSt VaLuE"
+#define LC_NAME_ALIAS_CHECK_VAL "test value"
+START_TEST(test_sysdb_attrs_add_lc_name_alias)
+{
+ int ret;
+ struct sysdb_attrs *attrs;
+ const char *str;
+
+ ret = sysdb_attrs_add_lc_name_alias(NULL, NULL);
+ fail_unless(ret == EINVAL, "EINVAL not returned for NULL input");
+
+ attrs = sysdb_new_attrs(NULL);
+ fail_unless(attrs != NULL, "sysdb_new_attrs failed");
+
+ ret = sysdb_attrs_add_lc_name_alias(attrs, LC_NAME_ALIAS_TEST_VAL);
+ fail_unless(ret == EOK, "sysdb_attrs_add_lc_name_alias failed");
+
+ ret = sysdb_attrs_get_string(attrs, SYSDB_NAME_ALIAS, &str);
+ fail_unless(ret == EOK, "sysdb_attrs_get_string failed");
+ fail_unless(strcmp(str, LC_NAME_ALIAS_CHECK_VAL) == 0,
+ "Unexpected value, expected [%s], got [%s]",
+ LC_NAME_ALIAS_CHECK_VAL, str);
+
+ talloc_free(attrs);
+}
+END_TEST
+
START_TEST(test_sysdb_has_enumerated)
{
errno_t ret;
@@ -5188,6 +5215,8 @@ Suite *create_sysdb_suite(void)
tcase_add_test(tc_sysdb, test_sysdb_store_services);
tcase_add_test(tc_sysdb, test_sysdb_svc_remove_alias);
+ tcase_add_test(tc_sysdb, test_sysdb_attrs_add_lc_name_alias);
+
/* Add all test cases to the test suite */
suite_add_tcase(s, tc_sysdb);
--
1.8.4.2