s4:samdb util - add a call for generating a correct "lDAPDisplayName"
authorMatthias Dieter Wallnöfer <mwallnoefer@yahoo.de>
Sat, 14 Nov 2009 19:12:42 +0000 (20:12 +0100)
committerMatthias Dieter Wallnöfer <mwallnoefer@yahoo.de>
Sun, 15 Nov 2009 13:26:40 +0000 (14:26 +0100)
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

index dcbb462e710a657a91cd0809af3c3b1c2fb80b4b..4175928c506ef5388f61470c86e9ff7c3708b87c 100644 (file)
@@ -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;
+}