From: Sarah Day Date: Thu, 3 Mar 2016 21:49:06 +0000 (-0500) Subject: Add cleanup label in ms2mit X-Git-Tag: kfw-4.1-beta3-mit~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e77af6d50e8a4bd66988cdb231551614791b873e;p=thirdparty%2Fkrb5.git Add cleanup label in ms2mit (cherry picked from commit e033a81c891030741952e4743a0b5503bdbcea17) ticket: 8390 --- diff --git a/src/windows/ms2mit/ms2mit.c b/src/windows/ms2mit/ms2mit.c index 31c269a8de..9018707f04 100644 --- a/src/windows/ms2mit/ms2mit.c +++ b/src/windows/ms2mit/ms2mit.c @@ -39,19 +39,16 @@ xusage(void) exit(1); } -void -main( - int argc, - char *argv[] - ) +int +main(int argc, char *argv[]) { - krb5_context kcontext; + krb5_context kcontext = NULL; krb5_error_code code; krb5_ccache ccache=NULL; krb5_ccache mslsa_ccache=NULL; krb5_cc_cursor cursor; krb5_creds creds; - krb5_principal princ; + krb5_principal princ = NULL; int initial_ticket = 0; int option; char * ccachestr = 0; @@ -73,28 +70,23 @@ main( if (code = krb5_init_context(&kcontext)) { com_err(argv[0], code, "while initializing kerberos library"); - exit(1); + goto cleanup; } if (code = krb5_cc_resolve(kcontext, "MSLSA:", &mslsa_ccache)) { com_err(argv[0], code, "while opening MS LSA ccache"); - krb5_free_context(kcontext); - exit(1); + goto cleanup; } if (code = krb5_cc_set_flags(kcontext, mslsa_ccache, KRB5_TC_NOTICKET)) { com_err(argv[0], code, "while setting KRB5_TC_NOTICKET flag"); - krb5_cc_close(kcontext, mslsa_ccache); - krb5_free_context(kcontext); - exit(1); + goto cleanup; } /* Enumerate tickets from cache looking for an initial ticket */ if ((code = krb5_cc_start_seq_get(kcontext, mslsa_ccache, &cursor))) { com_err(argv[0], code, "while initiating the cred sequence of MS LSA ccache"); - krb5_cc_close(kcontext, mslsa_ccache); - krb5_free_context(kcontext); - exit(1); + goto cleanup; } while (!(code = krb5_cc_next_cred(kcontext, mslsa_ccache, &cursor, &creds))) @@ -110,24 +102,18 @@ main( if (code = krb5_cc_set_flags(kcontext, mslsa_ccache, 0)) { com_err(argv[0], code, "while clearing flags"); - krb5_cc_close(kcontext, mslsa_ccache); - krb5_free_context(kcontext); - exit(1); + goto cleanup; } if ( !initial_ticket ) { fprintf(stderr, "%s: Initial Ticket Getting Tickets are not available from the MS LSA\n", argv[0]); - krb5_cc_close(kcontext, mslsa_ccache); - krb5_free_context(kcontext); - exit(1); + goto cleanup; } if (code = krb5_cc_get_principal(kcontext, mslsa_ccache, &princ)) { com_err(argv[0], code, "while obtaining MS LSA principal"); - krb5_cc_close(kcontext, mslsa_ccache); - krb5_free_context(kcontext); - exit(1); + goto cleanup; } if (ccachestr) @@ -136,32 +122,24 @@ main( code = krb5_cc_default(kcontext, &ccache); if (code) { com_err(argv[0], code, "while getting default ccache"); - krb5_free_principal(kcontext, princ); - krb5_cc_close(kcontext, mslsa_ccache); - krb5_free_context(kcontext); - exit(1); + goto cleanup; } if (code = krb5_cc_initialize(kcontext, ccache, princ)) { com_err (argv[0], code, "when initializing ccache"); - krb5_free_principal(kcontext, princ); - krb5_cc_close(kcontext, mslsa_ccache); - krb5_cc_close(kcontext, ccache); - krb5_free_context(kcontext); - exit(1); + goto cleanup; } if (code = krb5_cc_copy_creds(kcontext, mslsa_ccache, ccache)) { com_err (argv[0], code, "while copying MS LSA ccache to default ccache"); - krb5_free_principal(kcontext, princ); - krb5_cc_close(kcontext, ccache); - krb5_cc_close(kcontext, mslsa_ccache); - krb5_free_context(kcontext); - exit(1); + goto cleanup; } +cleanup: krb5_free_principal(kcontext, princ); - krb5_cc_close(kcontext, ccache); - krb5_cc_close(kcontext, mslsa_ccache); + if (ccache != NULL) + krb5_cc_close(kcontext, ccache); + if (mslsa_ccache != NULL) + krb5_cc_close(kcontext, mslsa_ccache); krb5_free_context(kcontext); - return(0); + return code ? 1 : 0; }