Path: blob/main/crypto/krb5/src/windows/ms2mit/mit2ms.c
34907 views
/* windows/ms2mit/mit2ms.c */1/*2* Copyright (C) 2003,2004 by the Massachusetts Institute of Technology.3* All rights reserved.4*5* Export of this software from the United States of America may6* require a specific license from the United States Government.7* It is the responsibility of any person or organization contemplating8* export to obtain such a license before exporting.9*10* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and11* distribute this software and its documentation for any purpose and12* without fee is hereby granted, provided that the above copyright13* notice appear in all copies and that both that copyright notice and14* this permission notice appear in supporting documentation, and that15* the name of M.I.T. not be used in advertising or publicity pertaining16* to distribution of the software without specific, written prior17* permission. Furthermore if you modify this software you must label18* your software as modified software and not distribute it in such a19* fashion that it might be confused with the original M.I.T. software.20* M.I.T. makes no representations about the suitability of21* this software for any purpose. It is provided "as is" without express22* or implied warranty.23*/2425#include "krb5.h"26#include <stdio.h>27#include <string.h>28#include "k5-platform.h"2930static char *prog;3132static void33xusage(void)34{35fprintf(stderr, "xusage: %s [-c ccache]\n", prog);36exit(1);37}3839void40main(41int argc,42char *argv[]43)44{45krb5_context kcontext;46krb5_error_code code;47krb5_ccache ccache=NULL;48krb5_ccache mslsa_ccache=NULL;49krb5_cc_cursor cursor;50krb5_creds creds;51krb5_principal princ;52int initial_ticket = 0;53int option;54char * ccachestr = 0;5556prog = strrchr(argv[0], '/');57prog = prog ? (prog + 1) : argv[0];5859while ((option = getopt(argc, argv, "c:h")) != -1) {60switch (option) {61case 'c':62ccachestr = optarg;63break;64case 'h':65default:66xusage();67break;68}69}7071if (code = krb5_init_context(&kcontext)) {72com_err(argv[0], code, "while initializing kerberos library");73exit(1);74}7576if (ccachestr)77code = krb5_cc_resolve(kcontext, ccachestr, &ccache);78else79code = krb5_cc_default(kcontext, &ccache);80if (code) {81com_err(argv[0], code, "while getting default ccache");82krb5_free_principal(kcontext, princ);83krb5_free_context(kcontext);84exit(1);85}8687/* Enumerate tickets from cache looking for an initial ticket */88if ((code = krb5_cc_start_seq_get(kcontext, ccache, &cursor))) {89com_err(argv[0], code, "while initiating the cred sequence of MS LSA ccache");90krb5_cc_close(kcontext, ccache);91krb5_free_context(kcontext);92exit(1);93}9495while (!(code = krb5_cc_next_cred(kcontext, ccache, &cursor, &creds)))96{97if ( creds.ticket_flags & TKT_FLG_INITIAL ) {98krb5_free_cred_contents(kcontext, &creds);99initial_ticket = 1;100break;101}102krb5_free_cred_contents(kcontext, &creds);103}104krb5_cc_end_seq_get(kcontext, ccache, &cursor);105106if ( !initial_ticket ) {107fprintf(stderr, "%s: Initial Ticket Getting Tickets are not available from the MIT default cache\n",108argv[0]);109krb5_cc_close(kcontext, ccache);110krb5_free_context(kcontext);111exit(1);112}113114if (code = krb5_cc_get_principal(kcontext, ccache, &princ)) {115com_err(argv[0], code, "while obtaining default MIT principal");116krb5_cc_close(kcontext, ccache);117krb5_free_context(kcontext);118exit(1);119}120121if (code = krb5_cc_resolve(kcontext, "MSLSA:", &mslsa_ccache)) {122com_err(argv[0], code, "while opening MS LSA ccache");123krb5_cc_close(kcontext, ccache);124krb5_free_context(kcontext);125exit(1);126}127128if (code = krb5_cc_copy_creds(kcontext, ccache, mslsa_ccache)) {129com_err (argv[0], code, "while copying default MIT ccache to MSLSA ccache");130krb5_free_principal(kcontext, princ);131krb5_cc_close(kcontext, ccache);132krb5_cc_close(kcontext, mslsa_ccache);133krb5_free_context(kcontext);134exit(1);135}136137krb5_free_principal(kcontext, princ);138krb5_cc_close(kcontext, ccache);139krb5_cc_close(kcontext, mslsa_ccache);140krb5_free_context(kcontext);141return(0);142}143144145