From ce453e8dc921038ab195359bb31f3a5c7cfe5251 Mon Sep 17 00:00:00 2001 From: Tom Yu Date: Thu, 13 Jan 2005 00:42:30 +0000 Subject: [PATCH] pullup from trunk ticket: 2870 target_version: 1.4 version_fixed: 1.4 git-svn-id: svn://anonsvn.mit.edu/krb5/branches/krb5-1-4@17022 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/ccache/ChangeLog | 7 +++++++ src/lib/krb5/ccache/cc_mslsa.c | 35 +++++++++++++++++++++------------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/lib/krb5/ccache/ChangeLog b/src/lib/krb5/ccache/ChangeLog index 651e4a017..d7bf408cd 100644 --- a/src/lib/krb5/ccache/ChangeLog +++ b/src/lib/krb5/ccache/ChangeLog @@ -1,3 +1,10 @@ +2005-01-11 Jeffrey Altman + + * cc_mslsa.c: + - do not free krb5_creds if krb5_copy_creds fails + - cause MSTicketToMITTicket to return failure if + krb5_copy_data fails + 2004-12-25 Ezra Peisach * cc_file.c (krb5_fcc_close): Free the cache id. diff --git a/src/lib/krb5/ccache/cc_mslsa.c b/src/lib/krb5/ccache/cc_mslsa.c index b777bb01c..fdd3f108b 100644 --- a/src/lib/krb5/ccache/cc_mslsa.c +++ b/src/lib/krb5/ccache/cc_mslsa.c @@ -333,19 +333,25 @@ MSFlagsToMITFlags(ULONG msflags, ULONG *mitflags) *mitflags=msflags; } -static void +static BOOL MSTicketToMITTicket(KERB_EXTERNAL_TICKET *msticket, krb5_context context, krb5_data *ticket) { - krb5_data tmpdata, *newdata; + krb5_data tmpdata, *newdata = 0; + krb5_error_code rc; + tmpdata.magic=KV5M_DATA; tmpdata.length=msticket->EncodedTicketSize; tmpdata.data=msticket->EncodedTicket; // this is ugly and will break krb5_free_data() // now that this is being done within the library it won't break krb5_free_data() - krb5_copy_data(context, &tmpdata, &newdata); + rc = krb5_copy_data(context, &tmpdata, &newdata); + if (rc) + return FALSE; + memcpy(ticket, newdata, sizeof(krb5_data)); krb5_xfree(newdata); + return TRUE; } /* @@ -418,8 +424,7 @@ MSCredToMITCred(KERB_EXTERNAL_TICKET *msticket, UNICODE_STRING ClientRealm, creds->times.renew_till=FileTimeToUnixTime(&msticket->RenewUntil); creds->addresses = NULL; - MSTicketToMITTicket(msticket, context, &creds->ticket); - return TRUE; + return MSTicketToMITTicket(msticket, context, &creds->ticket); } static BOOL @@ -1988,7 +1993,7 @@ krb5_lcc_retrieve(krb5_context context, krb5_ccache id, krb5_flags whichfields, krb5_error_code kret = KRB5_OK; krb5_lcc_data *data = (krb5_lcc_data *)id->data; KERB_EXTERNAL_TICKET *msticket = 0, *mstgt = 0, *mstmp = 0; - krb5_creds * mcreds_noflags; + krb5_creds * mcreds_noflags = 0; krb5_creds fetchcreds; if (!is_windows_2000()) @@ -2002,7 +2007,9 @@ krb5_lcc_retrieve(krb5_context context, krb5_ccache id, krb5_flags whichfields, return KRB5_OK; /* if not, we must try to get a ticket without specifying any flags or etypes */ - krb5_copy_creds(context, mcreds, &mcreds_noflags); + kret = krb5_copy_creds(context, mcreds, &mcreds_noflags); + if (kret) + goto cleanup; mcreds_noflags->ticket_flags = 0; mcreds_noflags->keyblock.enctype = 0; @@ -2111,7 +2118,7 @@ krb5_lcc_store(krb5_context context, krb5_ccache id, krb5_creds *creds) krb5_error_code kret = KRB5_OK; krb5_lcc_data *data = (krb5_lcc_data *)id->data; KERB_EXTERNAL_TICKET *msticket = 0, *msticket2 = 0; - krb5_creds * creds_noflags; + krb5_creds * creds_noflags = 0; if (!is_windows_2000()) return KRB5_FCC_NOFILE; @@ -2119,12 +2126,14 @@ krb5_lcc_store(krb5_context context, krb5_ccache id, krb5_creds *creds) /* If not, lets try to obtain a matching ticket from the KDC */ if ( creds->ticket_flags != 0 && creds->keyblock.enctype != 0 ) { /* if not, we must try to get a ticket without specifying any flags or etypes */ - krb5_copy_creds(context, creds, &creds_noflags); - creds_noflags->ticket_flags = 0; - creds_noflags->keyblock.enctype = 0; + kret = krb5_copy_creds(context, creds, &creds_noflags); + if (kret == 0) { + creds_noflags->ticket_flags = 0; + creds_noflags->keyblock.enctype = 0; - GetMSCacheTicketFromMITCred(data->LogonHandle, data->PackageId, context, creds_noflags, &msticket2); - krb5_free_creds(context, creds_noflags); + GetMSCacheTicketFromMITCred(data->LogonHandle, data->PackageId, context, creds_noflags, &msticket2); + krb5_free_creds(context, creds_noflags); + } } GetMSCacheTicketFromMITCred(data->LogonHandle, data->PackageId, context, creds, &msticket); -- 2.26.2