summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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;
}