1 /* krb5dissect.c --- Dissect Kerberos ccache/keytab files.
2 * Copyright (C) 2007 Simon Josefsson.
4 * This file is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2, or (at your option)
9 * This file is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this file; see the file COPYING. If not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 /* Autoconf definitions. */
23 /* Standard headers. */
31 #include "version-etc.h"
32 #include "read-file.h"
34 #include "xvasprintf.h"
39 #include "krb5dissect_cmd.h"
41 const char version_etc_copyright
[] = "Copyright %s %d Simon Josefsson.";
44 parse_ccache (const char *data
, size_t len
)
47 struct ccache_credential cred
;
51 rc
= ccache_parse (data
, len
, &ccache
);
53 error (EXIT_FAILURE
, 0, "Cannot parse ccache");
55 ccache_print (&ccache
);
57 while (ccache
.credentialslen
)
61 rc
= ccache_parse_credential (ccache
.credentials
,
62 ccache
.credentialslen
, &cred
, &n
);
64 error (EXIT_FAILURE
, 0, "Cannot parse ccache entry %d", i
);
66 printf ("\nCcache entry %d:\n", i
++);
68 ccache_print_credential (&cred
);
70 ccache
.credentials
+= n
;
71 ccache
.credentialslen
-= n
;
76 parse_keytab (const char *data
, size_t len
)
79 struct keytab_entry entry
;
83 rc
= keytab_parse (data
, len
, &keytab
);
85 error (EXIT_FAILURE
, 0, "Cannot parse keytab");
87 keytab_print (&keytab
);
89 while (keytab
.keytabslen
)
93 rc
= keytab_parse_entry (keytab
.keytabs
,
94 keytab
.keytabslen
, &entry
, &n
);
96 error (EXIT_FAILURE
, 0, "Cannot parse keytab entry %d", i
);
98 printf ("\nKeytab entry %d:\n", i
++);
100 keytab_print_entry (&entry
);
103 keytab
.keytabslen
-= n
;
108 main (int argc
, char *argv
[])
110 struct gengetopt_args_info args_info
;
111 int free_filename
= 0;
116 set_program_name (argv
[0]);
118 if (cmdline_parser (argc
, argv
, &args_info
) != 0)
121 if (!args_info
.quiet_given
)
123 version_etc (stdout
, program_name
, PACKAGE
, VERSION
,
124 "Simon Josefsson", (char*) NULL
);
128 if (args_info
.keytab_given
)
129 filename
= "/etc/krb5.keytab";
130 else if (args_info
.ccache_given
)
132 filename
= xasprintf("/tmp/krb5cc_%u", (unsigned long) getuid ());
135 else if (args_info
.inputs_num
== 1)
136 filename
= args_info
.inputs
[0];
139 cmdline_parser_print_help ();
143 cmdline_parser_free (&args_info
);
145 if (strcmp (filename
, "-") == 0)
146 data
= fread_file (stdin
, &len
);
148 data
= read_binary_file (filename
, &len
);
150 error (EXIT_FAILURE
, errno
, "%s", filename
);
155 if (len
> 2 && data
[0] == '\x05' && data
[1] == '\x04')
156 parse_ccache (data
, len
);
158 parse_keytab (data
, len
);