From f422504dd466e258ff79521e280e08ae33631d37 Mon Sep 17 00:00:00 2001 From: Stephen Gallagher Date: Thu, 15 Mar 2012 15:43:34 -0400 Subject: SYSDB: Save only lowercased aliases in case-insensitive domains https://fedorahosted.org/sssd/ticket/1253 --- src/db/sysdb.c | 47 ++++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/db/sysdb.c b/src/db/sysdb.c index a7f65a33..c29382fe 100644 --- a/src/db/sysdb.c +++ b/src/db/sysdb.c @@ -1680,7 +1680,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; @@ -1701,47 +1701,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); -- cgit