aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSarah Day <sarahday@mit.edu>2016-03-03 16:49:06 -0500
committerTom Yu <tlyu@mit.edu>2016-04-06 13:48:05 -0400
commite77af6d50e8a4bd66988cdb231551614791b873e (patch)
tree6ce0bb1eecbd2fe5ebe3ec2832c71fa172f712ab
parente4c219e8d0208fb6b3ee9037d3dc2ef1a3003c56 (diff)
downloadkrb5-e77af6d50e8a4bd66988cdb231551614791b873e.zip
krb5-e77af6d50e8a4bd66988cdb231551614791b873e.tar.gz
krb5-e77af6d50e8a4bd66988cdb231551614791b873e.tar.bz2
Add cleanup label in ms2mit
(cherry picked from commit e033a81c891030741952e4743a0b5503bdbcea17) ticket: 8390
-rw-r--r--src/windows/ms2mit/ms2mit.c62
1 files changed, 20 insertions, 42 deletions
diff --git a/src/windows/ms2mit/ms2mit.c b/src/windows/ms2mit/ms2mit.c
index 31c269a..9018707 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;
}