Skip to content

Commit

Permalink
Add cleanup label in ms2mit
Browse files Browse the repository at this point in the history
ticket: 8390 (new)
tags: pullup
target_version: 1.13-next
target_version: 1.14-next
  • Loading branch information
SaharahSarah authored and tlyu committed Mar 30, 2016
1 parent 0f1c3d7 commit e033a81
Showing 1 changed file with 20 additions and 42 deletions.
62 changes: 20 additions & 42 deletions src/windows/ms2mit/ms2mit.c
Expand Up @@ -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;
Expand All @@ -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)))
Expand All @@ -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)
Expand All @@ -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;
}

0 comments on commit e033a81

Please sign in to comment.