private void ListTickets(string cache) { TicketCacheBase.TryParseCacheType(cache, out _, out string path); var ticketCache = new Krb5TicketCache(path); var tickets = ticketCache.Krb5Cache.Credentials.ToArray(); this.IO.Writer.WriteLine("{0}: {1}", SR.Resource("CommandLine_KList_Count"), tickets.Length); this.IO.Writer.WriteLine(); for (var i = 0; i < tickets.Length; i++) { var ticket = tickets[i]; KrbTicket decodedTicket = TryParseTicket(ticket.Ticket); var properties = new List <(string, string)> { ("CommandLine_KList_Client", $"{ticket.Client.FullyQualifiedName} @ {ticket.Client.Realm}"), ("CommandLine_KList_Server", $"{ticket.Server.FullyQualifiedName} @ {ticket.Server.Realm}"), ("CommandLine_KList_TicketEType", $"{decodedTicket?.EncryptedPart?.EType.ToString()}"), ("CommandLine_KList_Flags", ticket.Flags.ToString()), ("CommandLine_KList_Start", ticket.AuthTime.ToLocalTime().ToString(CultureInfo.CurrentCulture)), ("CommandLine_KList_End", ticket.EndTime.ToLocalTime().ToString(CultureInfo.CurrentCulture)), ("CommandLine_KList_RenewTime", ticket.RenewTill.ToLocalTime().ToString(CultureInfo.CurrentCulture)) }; var ticketEntryNumber = string.Format("#{0}>", i); var max = properties.Max(p => p.Item1.Length); bool first = true; foreach (var prop in properties) { var key = string.Format("{0}: ", SR.Resource(prop.Item1)).PadLeft(max - 1).PadRight(max); if (first) { key = ticketEntryNumber + key.Substring(ticketEntryNumber.Length); first = false; } this.IO.Writer.Write(key); this.IO.Writer.WriteLine(prop.Item2); } this.IO.Writer.WriteLine(); } }
private void PurgeTickets(string cache) { TicketCacheBase.TryParseCacheType(cache, out _, out string path); try { File.Delete(Environment.ExpandEnvironmentVariables(path)); this.IO.Writer.WriteLine(SR.Resource("CommandLine_KerberosDestroy_Deleted")); } catch (Exception ex) { this.IO.Writer.Write("{0}: ", SR.Resource("CommandLine_KerberosDestroy_Error")); this.IO.Writer.WriteLine(ex.Message); } }