From bb55b1f4e530efc5af24d79ca9705e8d7549676f Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Thu, 2 Sep 2004 00:42:50 +0000 Subject: [PATCH] * ms2mit.c: add -c ccache command line option * mit2ms.c: new command. Copies contents of the mit ccache to the MSLSA: ccache ticket: new git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16713 dc483132-0cff-0310-8789-dd5450dbe970 --- src/windows/ms2mit/ChangeLog | 9 +- src/windows/ms2mit/Makefile.in | 8 +- src/windows/ms2mit/mit2ms.c | 149 +++++++++++++++++++++++++++++++++ src/windows/ms2mit/ms2mit.c | 36 +++++++- 4 files changed, 198 insertions(+), 4 deletions(-) create mode 100644 src/windows/ms2mit/mit2ms.c diff --git a/src/windows/ms2mit/ChangeLog b/src/windows/ms2mit/ChangeLog index 992ba4f4f..0448e0498 100644 --- a/src/windows/ms2mit/ChangeLog +++ b/src/windows/ms2mit/ChangeLog @@ -1,6 +1,13 @@ +2004-08-20 Jeffrey Altman + + * ms2mit.c: add -c ccache command line option + + * mit2ms.c: new command. Copies contents of the mit ccache + to the MSLSA: ccache + 2004-03-08 Ken Raeburn - * Makefile.in (MY_SUBDIRS): Deleted. + * Makefile.in (MY_SUBDIRS): Deleted. 2004-01-31 Jeffrey Altman diff --git a/src/windows/ms2mit/Makefile.in b/src/windows/ms2mit/Makefile.in index 7314b987b..b1275bbb4 100644 --- a/src/windows/ms2mit/Makefile.in +++ b/src/windows/ms2mit/Makefile.in @@ -9,13 +9,17 @@ BUILDTOP=$(REL)..$(S).. DEFINES = PROG_LIBPATH=-L$(TOPLIBD) -L$(KRB5_LIBDIR) -all-windows:: $(OUTPRE)ms2mit.exe +all-windows:: $(OUTPRE)ms2mit.exe $(OUTPRE)mit2ms.exe $(OUTPRE)ms2mit.exe: $(OUTPRE)ms2mit.obj - link $(EXE_LINKOPTS) -out:$@ $(OUTPRE)ms2mit.obj user32.lib advapi32.lib $(KLIB) $(CLIB) + link $(EXE_LINKOPTS) -out:$@ $(OUTPRE)ms2mit.obj $(BUILDTOP)\util\windows\$(OUTPRE)getopt.obj user32.lib advapi32.lib $(KLIB) $(CLIB) + +$(OUTPRE)mit2ms.exe: $(OUTPRE)mit2ms.obj + link $(EXE_LINKOPTS) -out:$@ $(OUTPRE)mit2ms.obj $(BUILDTOP)\util\windows\$(OUTPRE)getopt.obj user32.lib advapi32.lib $(KLIB) $(CLIB) install:: copy $(OUTPRE)ms2mit.exe $(DESTDIR) + copy $(OUTPRE)mit2ms.exe $(DESTDIR) clean:: $(RM) $(OUTPRE)*.exe diff --git a/src/windows/ms2mit/mit2ms.c b/src/windows/ms2mit/mit2ms.c new file mode 100644 index 000000000..6f30d9f6d --- /dev/null +++ b/src/windows/ms2mit/mit2ms.c @@ -0,0 +1,149 @@ +/* + * mit2ms.c + * + */ +/* + * Copyright (C) 2003,2004 by the Massachusetts Institute of Technology. + * All rights reserved. + * + * Export of this software from the United States of America may + * require a specific license from the United States Government. + * It is the responsibility of any person or organization contemplating + * export to obtain such a license before exporting. + * + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of M.I.T. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + * + */ + +#include "krb5.h" +#include +#include + +extern int optind; +extern char *optarg; + +static char *prog; + +static void +xusage(void) +{ + fprintf(stderr, "xusage: %s [-c ccache]\n", prog); + exit(1); +} + +void +main( + int argc, + char *argv[] + ) +{ + krb5_context kcontext; + krb5_error_code code; + krb5_ccache ccache=NULL; + krb5_ccache mslsa_ccache=NULL; + krb5_cc_cursor cursor; + krb5_creds creds; + krb5_principal princ; + int initial_ticket = 0; + int option; + char * ccachestr = 0; + + prog = strrchr(argv[0], '/'); + prog = prog ? (prog + 1) : argv[0]; + + while ((option = getopt(argc, argv, "c:h")) != -1) { + switch (option) { + case 'c': + ccachestr = optarg; + break; + case 'h': + default: + xusage(); + break; + } + } + + if (code = krb5_init_context(&kcontext)) { + com_err(argv[0], code, "while initializing kerberos library"); + exit(1); + } + + if (ccachestr) + code = krb5_cc_resolve(kcontext, ccachestr, &ccache); + else + code = krb5_cc_default(kcontext, &ccache); + if (code) { + com_err(argv[0], code, "while getting default ccache"); + krb5_free_principal(kcontext, princ); + krb5_free_context(kcontext); + exit(1); + } + + /* Enumerate tickets from cache looking for an initial ticket */ + if ((code = krb5_cc_start_seq_get(kcontext, ccache, &cursor))) { + com_err(argv[0], code, "while initiating the cred sequence of MS LSA ccache"); + krb5_cc_close(kcontext, ccache); + krb5_free_context(kcontext); + exit(1); + } + + while (!(code = krb5_cc_next_cred(kcontext, ccache, &cursor, &creds))) + { + if ( creds.ticket_flags & TKT_FLG_INITIAL ) { + krb5_free_cred_contents(kcontext, &creds); + initial_ticket = 1; + break; + } + krb5_free_cred_contents(kcontext, &creds); + } + krb5_cc_end_seq_get(kcontext, ccache, &cursor); + + if ( !initial_ticket ) { + fprintf(stderr, "%s: Initial Ticket Getting Tickets are not available from the MIT default cache\n", + argv[0]); + krb5_cc_close(kcontext, ccache); + krb5_free_context(kcontext); + exit(1); + } + + if (code = krb5_cc_get_principal(kcontext, ccache, &princ)) { + com_err(argv[0], code, "while obtaining default MIT principal"); + krb5_cc_close(kcontext, ccache); + krb5_free_context(kcontext); + exit(1); + } + + if (code = krb5_cc_resolve(kcontext, "MSLSA:", &mslsa_ccache)) { + com_err(argv[0], code, "while opening MS LSA ccache"); + krb5_cc_close(kcontext, ccache); + krb5_free_context(kcontext); + exit(1); + } + + if (code = krb5_cc_copy_creds(kcontext, ccache, mslsa_ccache)) { + com_err (argv[0], code, "while copying default MIT ccache to MSLSA ccache"); + krb5_free_principal(kcontext, princ); + krb5_cc_close(kcontext, ccache); + krb5_cc_close(kcontext, mslsa_ccache); + krb5_free_context(kcontext); + exit(1); + } + + krb5_free_principal(kcontext, princ); + krb5_cc_close(kcontext, ccache); + krb5_cc_close(kcontext, mslsa_ccache); + krb5_free_context(kcontext); + return(0); +} diff --git a/src/windows/ms2mit/ms2mit.c b/src/windows/ms2mit/ms2mit.c index eba52e793..3a7f7d5a2 100644 --- a/src/windows/ms2mit/ms2mit.c +++ b/src/windows/ms2mit/ms2mit.c @@ -29,6 +29,19 @@ #include "krb5.h" #include +#include + +extern int optind; +extern char *optarg; + +static char *prog; + +static void +xusage(void) +{ + fprintf(stderr, "xusage: %s [-c ccache]\n", prog); + exit(1); +} void main( @@ -44,7 +57,24 @@ main( krb5_creds creds; krb5_principal princ; int initial_ticket = 0; + int option; + char * ccachestr = 0; + prog = strrchr(argv[0], '/'); + prog = prog ? (prog + 1) : argv[0]; + + while ((option = getopt(argc, argv, "c:h")) != -1) { + switch (option) { + case 'c': + ccachestr = optarg; + break; + case 'h': + default: + xusage(); + break; + } + } + if (code = krb5_init_context(&kcontext)) { com_err(argv[0], code, "while initializing kerberos library"); exit(1); @@ -90,7 +120,11 @@ main( exit(1); } - if (code = krb5_cc_default(kcontext, &ccache)) { + if (ccachestr) + code = krb5_cc_resolve(kcontext, ccachestr, &ccache); + else + 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); -- 2.26.2