krb5 commit: Move realm conversion into helper in cc_mslsa.c
Benjamin Kaduk
kaduk at mit.edu
Tue Sep 9 17:37:11 EDT 2014
https://github.com/krb5/krb5/commit/e2d1a3aea7789b6acc5fa963da75ea666614764c
commit e2d1a3aea7789b6acc5fa963da75ea666614764c
Author: Ben Kaduk <kaduk at mit.edu>
Date: Thu Aug 14 13:51:22 2014 -0400
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.
ticket: 7989
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;
More information about the cvs-krb5
mailing list