krb5 commit [krb5-1.13]: Move realm conversion into helper in cc_mslsa.c

Tom Yu tlyu at mit.edu
Wed May 13 17:06:02 EDT 2015


https://github.com/krb5/krb5/commit/c6dfeb57c8002db2c41bdc66e8e50570e83cd7f1
commit c6dfeb57c8002db2c41bdc66e8e50570e83cd7f1
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.
    
    (cherry picked from commit e2d1a3aea7789b6acc5fa963da75ea666614764c)
    
    ticket: 7989
    version_fixed: 1.13.3

 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