From: Ben Kaduk Date: Thu, 14 Aug 2014 17:51:22 +0000 (-0400) Subject: Move realm conversion into helper in cc_mslsa.c X-Git-Tag: kfw-4.1-beta1~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c6dfeb57c8002db2c41bdc66e8e50570e83cd7f1;p=thirdparty%2Fkrb5.git Move realm conversion into helper in cc_mslsa.c All the callers of UnicodeStringToMITPrinc() were already converting a UnicodeString into a wchar* just to pass it in as the realm. Simplify everyone's life by making the helper do the conversion. (cherry picked from commit e2d1a3aea7789b6acc5fa963da75ea666614764c) ticket: 7989 version_fixed: 1.13.3 --- diff --git a/src/lib/krb5/ccache/cc_mslsa.c b/src/lib/krb5/ccache/cc_mslsa.c index 229fa96a83..801d055815 100644 --- a/src/lib/krb5/ccache/cc_mslsa.c +++ b/src/lib/krb5/ccache/cc_mslsa.c @@ -199,17 +199,23 @@ MITPrincToMSPrinc(krb5_context context, krb5_principal principal, UNICODE_STRING } static BOOL -UnicodeStringToMITPrinc(UNICODE_STRING *service, WCHAR *realm, krb5_context context, - krb5_principal *principal) +UnicodeStringToMITPrinc(UNICODE_STRING *service, UNICODE_STRING *realm, + krb5_context context, krb5_principal *principal) { WCHAR princbuf[512]; + WCHAR realmbuf[512]; char aname[512]; + /* Convert the realm to a wchar string. */ + realmbuf[0] = '\0'; + wcsncpy(realmbuf, realm->Buffer, realm->Length / sizeof(WCHAR)); + realmbuf[realm->Length / sizeof(WCHAR)] = 0; + /* Convert the principal components to a wchar string. */ princbuf[0]=0; wcsncpy(princbuf, service->Buffer, service->Length/sizeof(WCHAR)); princbuf[service->Length/sizeof(WCHAR)]=0; wcscat(princbuf, L"@"); - wcscat(princbuf, realm); + wcscat(princbuf, realmbuf); if (UnicodeToANSI(princbuf, aname, sizeof(aname))) { if (krb5_parse_name(context, aname, principal) == 0) return TRUE; @@ -354,21 +360,17 @@ static BOOL CacheInfoEx2ToMITCred(KERB_TICKET_CACHE_INFO_EX2 *info, krb5_context context, krb5_creds *creds) { - WCHAR wrealm[128]; ZeroMemory(creds, sizeof(krb5_creds)); creds->magic=KV5M_CREDS; // construct Client Principal - wcsncpy(wrealm, info->ClientRealm.Buffer, info->ClientRealm.Length/sizeof(WCHAR)); - wrealm[info->ClientRealm.Length/sizeof(WCHAR)]=0; - if (!UnicodeStringToMITPrinc(&info->ClientName, wrealm, context, &creds->client)) + if (!UnicodeStringToMITPrinc(&info->ClientName, &info->ClientRealm, + context, &creds->client)) return FALSE; // construct Service Principal - wcsncpy(wrealm, info->ServerRealm.Buffer, - info->ServerRealm.Length/sizeof(WCHAR)); - wrealm[info->ServerRealm.Length/sizeof(WCHAR)]=0; - if (!UnicodeStringToMITPrinc(&info->ServerName, wrealm, context, &creds->server)) + if (!UnicodeStringToMITPrinc(&info->ServerName, &info->ServerRealm, + context, &creds->server)) return FALSE; creds->keyblock.magic = KV5M_KEYBLOCK;