From 64f55a0b50229fb6f8854712de257be7cc27431a Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Thu, 22 Mar 2012 16:49:12 +0100 Subject: [PATCH 1/3] Add sss_get_cased_name_list utility function --- src/util/usertools.c | 37 +++++++++++++++++++++++++++++++++++++ src/util/util.h | 4 ++++ 2 files changed, 41 insertions(+), 0 deletions(-) diff --git a/src/util/usertools.c b/src/util/usertools.c index 64e8b1037fca322492e2d7c55152a7b07592df85..ff189e32fa5235bbc9d9828dd7b7269bc4403cb1 100644 --- a/src/util/usertools.c +++ b/src/util/usertools.c @@ -182,3 +182,40 @@ sss_get_cased_name(TALLOC_CTX *mem_ctx, return case_sensitive ? talloc_strdup(mem_ctx, orig_name) : sss_tc_utf8_str_tolower(mem_ctx, orig_name); } + +errno_t +sss_get_cased_name_list(TALLOC_CTX *mem_ctx, const char * const *orig, + bool case_sensitive, const char ***_cased) +{ + const char **out; + size_t num, i; + + if (orig == NULL) { + *_cased = NULL; + return EOK; + } + + for (num=0; orig[num]; num++); /* count the num of strings */ + + if (num == 0) { + *_cased = NULL; + return EOK; + } + + out = talloc_array(mem_ctx, const char *, num + 1); + if (out == NULL) { + return ENOMEM; + } + + for (i = 0; i < num; i++) { + out[i] = sss_get_cased_name(out, orig[i], case_sensitive); + if (out[i] == NULL) { + talloc_free(out); + return ENOMEM; + } + } + + out[num] = NULL; + *_cased = out; + return EOK; +} diff --git a/src/util/util.h b/src/util/util.h index 985c7898182c5e58ca79e049f99f37d724009cf1..da6db1cffe36035f27c447b9971b4a8ba7b7f740 100644 --- a/src/util/util.h +++ b/src/util/util.h @@ -405,6 +405,10 @@ char * sss_get_cased_name(TALLOC_CTX *mem_ctx, const char *orig_name, bool case_sensitive); +errno_t +sss_get_cased_name_list(TALLOC_CTX *mem_ctx, const char * const *orig, + bool case_sensitive, const char ***_cased); + /* from backup-file.c */ int backup_file(const char *src, int dbglvl); -- 1.7.7.6