2 * Copyright (c) 1997 - 2003 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.13 2003/04/16 17:56:02 lha 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 ret = krb5_data_alloc(&data, len);
94 krb5_err (context, 1, ret, "kadm_rename: data alloc: %d", len);
95 krb5_ret_principal(sp, &source);
96 krb5_storage_read(sp, data.data, data.length);
97 hdb_value2entry(context, &data, &ent);
98 krb5_unparse_name(context, source, &name1);
99 krb5_unparse_name(context, ent.principal, &name2);
100 printf(" %s -> %s\n", name1, name2);
103 krb5_free_principal(context, source);
104 hdb_free_entry(context, &ent);
107 ret = krb5_data_alloc(&data, len);
109 krb5_err (context, 1, ret, "kadm_create: data alloc: %d", len);
110 krb5_storage_read(sp, data.data, data.length);
111 ret = hdb_value2entry(context, &data, &ent);
117 ret = krb5_data_alloc(&data, len);
119 krb5_err (context, 1, ret, "kadm_modify: data alloc: %d", len);
120 krb5_ret_int32(sp, &mask);
121 krb5_storage_read(sp, data.data, data.length);
122 ret = hdb_value2entry(context, &data, &ent);
126 if(ent.principal /* mask & KADM5_PRINCIPAL */) {
127 krb5_unparse_name(context, ent.principal, &name1);
128 printf(" principal = %s\n", name1);
131 if(mask & KADM5_PRINC_EXPIRE_TIME) {
132 if(ent.valid_end == NULL) {
135 strftime(t, sizeof(t), "%Y-%m-%d %H:%M:%S",
136 localtime(ent.valid_end));
138 printf(" expires = %s\n", t);
140 if(mask & KADM5_PW_EXPIRATION) {
141 if(ent.pw_end == NULL) {
144 strftime(t, sizeof(t), "%Y-%m-%d %H:%M:%S",
145 localtime(ent.pw_end));
147 printf(" password exp = %s\n", t);
149 if(mask & KADM5_LAST_PWD_CHANGE) {
151 if(mask & KADM5_ATTRIBUTES) {
152 unparse_flags(HDBFlags2int(ent.flags),
153 HDBFlags_units, t, sizeof(t));
154 printf(" attributes = %s\n", t);
156 if(mask & KADM5_MAX_LIFE) {
157 if(ent.max_life == NULL)
158 strcpy(t, "for ever");
160 unparse_time(*ent.max_life, t, sizeof(t));
161 printf(" max life = %s\n", t);
163 if(mask & KADM5_MAX_RLIFE) {
164 if(ent.max_renew == NULL)
165 strcpy(t, "for ever");
167 unparse_time(*ent.max_renew, t, sizeof(t));
168 printf(" max rlife = %s\n", t);
170 if(mask & KADM5_MOD_TIME) {
171 printf(" mod time\n");
173 if(mask & KADM5_MOD_NAME) {
174 printf(" mod name\n");
176 if(mask & KADM5_KVNO) {
177 printf(" kvno = %d\n", ent.kvno);
179 if(mask & KADM5_MKVNO) {
182 if(mask & KADM5_AUX_ATTRIBUTES) {
183 printf(" aux attributes\n");
185 if(mask & KADM5_POLICY) {
188 if(mask & KADM5_POLICY_CLR) {
189 printf(" mod time\n");
191 if(mask & KADM5_LAST_SUCCESS) {
192 printf(" last success\n");
194 if(mask & KADM5_LAST_FAILED) {
195 printf(" last failed\n");
197 if(mask & KADM5_FAIL_AUTH_COUNT) {
198 printf(" fail auth count\n");
200 if(mask & KADM5_KEY_DATA) {
201 printf(" key data\n");
203 if(mask & KADM5_TL_DATA) {
204 printf(" tl data\n");
206 hdb_free_entry(context, &ent);
213 krb5_storage_seek(sp, end, SEEK_SET);
217 static int version_flag;
218 static int help_flag;
220 static struct getargs args[] = {
221 { "realm", 'r', arg_string, &realm },
222 { "version", 0, arg_flag, &version_flag },
223 { "help", 0, arg_flag, &help_flag }
225 int num_args = sizeof(args) / sizeof(args[0]);
228 main(int argc, char **argv)
230 krb5_context context;
233 kadm5_server_context *server_context;
234 kadm5_config_params conf;
236 krb5_program_setup(&context, argc, argv, args, num_args, NULL);
239 krb5_std_usage(0, args, num_args);
245 memset(&conf, 0, sizeof(conf));
247 conf.mask |= KADM5_CONFIG_REALM;
250 ret = kadm5_init_with_password_ctx (context,
257 krb5_err (context, 1, ret, "kadm5_init_with_password_ctx");
259 server_context = (kadm5_server_context *)kadm_handle;
261 ret = kadm5_log_init (server_context);
263 krb5_err (context, 1, ret, "kadm5_log_init");
265 ret = kadm5_log_foreach (server_context, print_entry);
267 krb5_warn(context, ret, "kadm5_log_foreach");
269 ret = kadm5_log_end (server_context);
271 krb5_warn(context, ret, "kadm5_log_end");