From da3d471d10a822713fea937b3e1951bdbdc7dc83 Mon Sep 17 00:00:00 2001 From: Matthias Dieter Wallnöfer Date: Sat, 14 Nov 2009 20:12:42 +0100 Subject: s4:samdb util - add a call for generating a correct "lDAPDisplayName" This is needed for the SAMLDB module enhancement regarding schema objects. The algorithm in pseudo code is located in MS-ADTS 3.1.1.2.3.4. --- source4/dsdb/common/util.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/source4/dsdb/common/util.c b/source4/dsdb/common/util.c index dcbb462e71..4175928c50 100644 --- a/source4/dsdb/common/util.c +++ b/source4/dsdb/common/util.c @@ -37,6 +37,7 @@ #include "param/param.h" #include "libcli/auth/libcli_auth.h" #include "librpc/gen_ndr/ndr_drsblobs.h" +#include "system/locale.h" /* search the sam for the specified attributes in a specific domain, filter on @@ -2617,3 +2618,30 @@ failed: talloc_free(tmp_ctx); return LDB_ERR_NO_SUCH_OBJECT; } + +/* + * Function which generates a "lDAPDisplayName" attribute from a "CN" one. + * Algorithm implemented according to MS-ADTS 3.1.1.2.3.4 + */ +const char *samdb_cn_to_lDAPDisplayName(TALLOC_CTX *mem_ctx, const char *cn) +{ + char **tokens, *ret; + size_t i; + + tokens = str_list_make(mem_ctx, cn, " -_"); + if (tokens == NULL) + return NULL; + + /* "tolower()" and "toupper()" should also work properly on 0x00 */ + tokens[0][0] = tolower(tokens[0][0]); + for (i = 1; i < str_list_length((const char **)tokens); i++) + tokens[i][0] = toupper(tokens[i][0]); + + ret = talloc_strdup(mem_ctx, tokens[0]); + for (i = 1; i < str_list_length((const char **)tokens); i++) + ret = talloc_asprintf_append_buffer(ret, "%s", tokens[i]); + + talloc_free(tokens); + + return ret; +} -- cgit