diff options
author | Ben Kaduk <kaduk@mit.edu> | 2014-08-14 13:51:22 -0400 |
---|---|---|
committer | Tom Yu <tlyu@mit.edu> | 2015-05-13 16:15:02 -0400 |
commit | c6dfeb57c8002db2c41bdc66e8e50570e83cd7f1 (patch) | |
tree | 707293ccd74a6cd529a0a74d6509d88ad6e7f51c /src | |
parent | db13963e400fddb35a1bddf52d6a69ad93945be3 (diff) | |
download | krb5-c6dfeb57c8002db2c41bdc66e8e50570e83cd7f1.zip krb5-c6dfeb57c8002db2c41bdc66e8e50570e83cd7f1.tar.gz krb5-c6dfeb57c8002db2c41bdc66e8e50570e83cd7f1.tar.bz2 |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/krb5/ccache/cc_mslsa.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/src/lib/krb5/ccache/cc_mslsa.c b/src/lib/krb5/ccache/cc_mslsa.c index 229fa96..801d055 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; |