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