summaryrefslogtreecommitdiff
path: root/src/db
diff options
context:
space:
mode:
authorStephen Gallagher <sgallagh@redhat.com>2012-03-15 15:43:34 -0400
committerStephen Gallagher <sgallagh@redhat.com>2012-03-16 14:06:54 -0400
commita9b96ea0efe6174a70834efe253fb5eae99e71fa (patch)
tree4975d3a3e455d90dd1669c940f56fe5411c7c4b0 /src/db
parentf9edb7898c70adb2deccb03134184661a26ca0cc (diff)
downloadsssd-a9b96ea0efe6174a70834efe253fb5eae99e71fa.tar.gz
sssd-a9b96ea0efe6174a70834efe253fb5eae99e71fa.tar.bz2
sssd-a9b96ea0efe6174a70834efe253fb5eae99e71fa.zip
SYSDB: Save only lowercased aliases in case-insensitive domains
https://fedorahosted.org/sssd/ticket/1253
Diffstat (limited to 'src/db')
-rw-r--r--src/db/sysdb.c47
1 files changed, 28 insertions, 19 deletions
diff --git a/src/db/sysdb.c b/src/db/sysdb.c
index bec25057..1bf18923 100644
--- a/src/db/sysdb.c
+++ b/src/db/sysdb.c
@@ -1731,7 +1731,7 @@ errno_t sysdb_attrs_get_aliases(TALLOC_CTX *mem_ctx,
{
TALLOC_CTX *tmp_ctx = NULL;
struct ldb_message_element *sysdb_name_el;
- size_t i, ai, num;
+ size_t i, ai;
errno_t ret;
const char **aliases = NULL;
const char *name;
@@ -1752,47 +1752,56 @@ errno_t sysdb_attrs_get_aliases(TALLOC_CTX *mem_ctx,
goto done;
}
- num = lowercase ? 2 * sysdb_name_el->num_values : sysdb_name_el->num_values;
- aliases = talloc_array(tmp_ctx, const char *, num+1);
+ aliases = talloc_array(tmp_ctx, const char *,
+ sysdb_name_el->num_values + 1);
if (!aliases) {
ret = ENOMEM;
goto done;
}
+ if (lowercase) {
+ DEBUG(SSSDBG_TRACE_INTERNAL,
+ ("Domain is case-insensitive; will add lowercased aliases\n"));
+ }
+
ai = 0;
for (i=0; i < sysdb_name_el->num_values; i++) {
name = (const char *)sysdb_name_el->values[i].data;
- if (strcmp(primary, name) != 0) {
- aliases[ai] = talloc_strdup(aliases, name);
- if (!aliases[ai]) {
- ret = ENOMEM;
- goto done;
- }
- ai++;
- }
- }
- if (lowercase) {
- DEBUG(SSSDBG_TRACE_INTERNAL,
- ("Domain is case-insensitive; will add lowercased aliases\n"));
- for (i=0; i < sysdb_name_el->num_values; i++) {
- name = (const char *)sysdb_name_el->values[i].data;
+ if (lowercase) {
+ /* Domain is case-insensitive. Save the lower-cased version */
lower = sss_tc_utf8_str_tolower(tmp_ctx, name);
if (!lower) {
ret = ENOMEM;
goto done;
}
- if (strcmp(name, lower) != 0) {
+ if (sss_utf8_case_eq((const uint8_t *) primary,
+ (const uint8_t *) lower) == ENOMATCH) {
aliases[ai] = talloc_strdup(aliases, lower);
+ if (!aliases[ai]) {
+ ret = ENOMEM;
+ goto done;
+ }
+ ai++;
+ }
+ } else {
+ /* Domain is case-sensitive. Save it as-is */
+ if (strcmp(primary, name) != 0) {
+ aliases[ai] = talloc_strdup(aliases, name);
+ if (!aliases[ai]) {
+ ret = ENOMEM;
+ goto done;
+ }
ai++;
}
- talloc_free(lower);
}
}
aliases[ai] = NULL;
+
ret = EOK;
+
done:
*_aliases = talloc_steal(mem_ctx, aliases);
talloc_free(tmp_ctx);