2 * Copyright (c) 1997 - 2002 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include "parse_time.h"
37 RCSID("$Id: dump_log.c,v 1.12 2002/05/24 15:19:18 joda Exp $");
39 static char *op_names[] = {
54 print_entry(kadm5_server_context *server_context,
64 krb5_principal source;
67 krb5_context context = server_context->context;
69 off_t end = krb5_storage_seek(sp, 0, SEEK_CUR) + len;
73 strftime(t, sizeof(t), "%Y-%m-%d %H:%M:%S", localtime(×tamp));
75 if(op < kadm_get || op > kadm_nop) {
76 printf("unknown op: %d\n", op);
77 krb5_storage_seek(sp, end, SEEK_SET);
81 printf ("%s: ver = %u, timestamp = %s, len = %u\n",
82 op_names[op], ver, t, len);
85 krb5_ret_principal(sp, &source);
86 krb5_unparse_name(context, source, &name1);
87 printf(" %s\n", name1);
89 krb5_free_principal(context, source);
92 krb5_data_alloc(&data, len);
93 krb5_ret_principal(sp, &source);
94 krb5_storage_read(sp, data.data, data.length);
95 hdb_value2entry(context, &data, &ent);
96 krb5_unparse_name(context, source, &name1);
97 krb5_unparse_name(context, ent.principal, &name2);
98 printf(" %s -> %s\n", name1, name2);
101 krb5_free_principal(context, source);
102 hdb_free_entry(context, &ent);
105 krb5_data_alloc(&data, len);
106 krb5_storage_read(sp, data.data, data.length);
107 ret = hdb_value2entry(context, &data, &ent);
113 krb5_data_alloc(&data, len);
114 krb5_ret_int32(sp, &mask);
115 krb5_storage_read(sp, data.data, data.length);
116 ret = hdb_value2entry(context, &data, &ent);
120 if(ent.principal /* mask & KADM5_PRINCIPAL */) {
121 krb5_unparse_name(context, ent.principal, &name1);
122 printf(" principal = %s\n", name1);
125 if(mask & KADM5_PRINC_EXPIRE_TIME) {
126 if(ent.valid_end == NULL) {
129 strftime(t, sizeof(t), "%Y-%m-%d %H:%M:%S",
130 localtime(ent.valid_end));
132 printf(" expires = %s\n", t);
134 if(mask & KADM5_PW_EXPIRATION) {
135 if(ent.pw_end == NULL) {
138 strftime(t, sizeof(t), "%Y-%m-%d %H:%M:%S",
139 localtime(ent.pw_end));
141 printf(" password exp = %s\n", t);
143 if(mask & KADM5_LAST_PWD_CHANGE) {
145 if(mask & KADM5_ATTRIBUTES) {
146 unparse_flags(HDBFlags2int(ent.flags),
147 HDBFlags_units, t, sizeof(t));
148 printf(" attributes = %s\n", t);
150 if(mask & KADM5_MAX_LIFE) {
151 if(ent.max_life == NULL)
152 strcpy(t, "for ever");
154 unparse_time(*ent.max_life, t, sizeof(t));
155 printf(" max life = %s\n", t);
157 if(mask & KADM5_MAX_RLIFE) {
158 if(ent.max_renew == NULL)
159 strcpy(t, "for ever");
161 unparse_time(*ent.max_renew, t, sizeof(t));
162 printf(" max rlife = %s\n", t);
164 if(mask & KADM5_MOD_TIME) {
165 printf(" mod time\n");
167 if(mask & KADM5_MOD_NAME) {
168 printf(" mod name\n");
170 if(mask & KADM5_KVNO) {
171 printf(" kvno = %d\n", ent.kvno);
173 if(mask & KADM5_MKVNO) {
176 if(mask & KADM5_AUX_ATTRIBUTES) {
177 printf(" aux attributes\n");
179 if(mask & KADM5_POLICY) {
182 if(mask & KADM5_POLICY_CLR) {
183 printf(" mod time\n");
185 if(mask & KADM5_LAST_SUCCESS) {
186 printf(" last success\n");
188 if(mask & KADM5_LAST_FAILED) {
189 printf(" last failed\n");
191 if(mask & KADM5_FAIL_AUTH_COUNT) {
192 printf(" fail auth count\n");
194 if(mask & KADM5_KEY_DATA) {
195 printf(" key data\n");
197 if(mask & KADM5_TL_DATA) {
198 printf(" tl data\n");
200 hdb_free_entry(context, &ent);
207 krb5_storage_seek(sp, end, SEEK_SET);
211 static int version_flag;
212 static int help_flag;
214 static struct getargs args[] = {
215 { "realm", 'r', arg_string, &realm },
216 { "version", 0, arg_flag, &version_flag },
217 { "help", 0, arg_flag, &help_flag }
219 int num_args = sizeof(args) / sizeof(args[0]);
222 main(int argc, char **argv)
224 krb5_context context;
227 kadm5_server_context *server_context;
228 kadm5_config_params conf;
230 krb5_program_setup(&context, argc, argv, args, num_args, NULL);
233 krb5_std_usage(0, args, num_args);
239 memset(&conf, 0, sizeof(conf));
241 conf.mask |= KADM5_CONFIG_REALM;
244 ret = kadm5_init_with_password_ctx (context,
251 krb5_err (context, 1, ret, "kadm5_init_with_password_ctx");
253 server_context = (kadm5_server_context *)kadm_handle;
255 ret = kadm5_log_init (server_context);
257 krb5_err (context, 1, ret, "kadm5_log_init");
259 ret = kadm5_log_foreach (server_context, print_entry);
261 krb5_warn(context, ret, "kadm5_log_foreach");
263 ret = kadm5_log_end (server_context);
265 krb5_warn(context, ret, "kadm5_log_end");