summaryrefslogtreecommitdiff
path: root/source4/heimdal/lib
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2011-11-15 14:32:35 +0100
committerStefan Metzmacher <metze@samba.org>2011-11-16 02:00:12 +0100
commitdd504b1899f437a4b877475bba3b5b2b04f400e1 (patch)
tree045ee9e393d2b0984e5f202d1f47e2cbf54054e3 /source4/heimdal/lib
parentd158a5cb915f1d04952cf943d043f452d1f3184b (diff)
downloadsamba-dd504b1899f437a4b877475bba3b5b2b04f400e1.tar.gz
samba-dd504b1899f437a4b877475bba3b5b2b04f400e1.tar.bz2
samba-dd504b1899f437a4b877475bba3b5b2b04f400e1.zip
HEIMDAL:lib/krb5: add utf8 support to build_logon_name() for the PAC
Pair-Programmed-With: Arvid Requate <requate@univention.de> metze Autobuild-User: Stefan Metzmacher <metze@samba.org> Autobuild-Date: Wed Nov 16 02:00:12 CET 2011 on sn-devel-104
Diffstat (limited to 'source4/heimdal/lib')
-rw-r--r--source4/heimdal/lib/krb5/pac.c67
1 files changed, 49 insertions, 18 deletions
diff --git a/source4/heimdal/lib/krb5/pac.c b/source4/heimdal/lib/krb5/pac.c
index f4caaddc26..91f68d5e00 100644
--- a/source4/heimdal/lib/krb5/pac.c
+++ b/source4/heimdal/lib/krb5/pac.c
@@ -706,7 +706,7 @@ build_logon_name(krb5_context context,
krb5_storage *sp;
uint64_t t;
char *s, *s2;
- size_t i, len;
+ size_t s2_len;
t = unix2nttime(authtime);
@@ -726,29 +726,60 @@ build_logon_name(krb5_context context,
if (ret)
goto out;
- len = strlen(s);
+ {
+ size_t ucs2_len;
+ uint16_t *ucs2;
+ unsigned int flags;
- CHECK(ret, krb5_store_uint16(sp, len * 2), out);
+ ret = wind_utf8ucs2_length(s, &ucs2_len);
+ if (ret) {
+ free(s);
+ krb5_set_error_message(context, ret, "Failed to count length of UTF-8 string");
+ return ret;
+ }
-#if 1 /* cheat for now */
- s2 = malloc(len * 2);
- if (s2 == NULL) {
- ret = krb5_enomem(context);
+ ucs2 = malloc(sizeof(ucs2[0]) * ucs2_len);
+ if (ucs2 == NULL) {
+ free(s);
+ return krb5_enomem(context);
+ }
+
+ ret = wind_utf8ucs2(s, ucs2, &ucs2_len);
free(s);
- goto out;
- }
- for (i = 0; i < len; i++) {
- s2[i * 2] = s[i];
- s2[i * 2 + 1] = 0;
+ if (ret) {
+ free(ucs2);
+ krb5_set_error_message(context, ret, "Failed to convert string to UCS-2");
+ return ret;
+ }
+
+ s2_len = (ucs2_len + 1) * 2;
+ s2 = malloc(s2_len);
+ if (ucs2 == NULL) {
+ free(ucs2);
+ return krb5_enomem(context);
+ }
+
+ flags = WIND_RW_LE;
+ ret = wind_ucs2write(ucs2, ucs2_len,
+ &flags, s2, &s2_len);
+ free(ucs2);
+ if (ret) {
+ free(s2);
+ krb5_set_error_message(context, ret, "Failed to write to UCS-2 buffer");
+ return ret;
+ }
+
+ /*
+ * we do not want zero termination
+ */
+ s2_len = ucs2_len * 2;
}
- free(s);
-#else
- /* write libwind code here */
-#endif
- ret = krb5_storage_write(sp, s2, len * 2);
+ CHECK(ret, krb5_store_uint16(sp, s2_len), out);
+
+ ret = krb5_storage_write(sp, s2, s2_len);
free(s2);
- if (ret != (int)(len * 2)) {
+ if (ret != (int)s2_len) {
ret = krb5_enomem(context);
goto out;
}