remove gcc34
[dragonfly.git] / crypto / heimdal-0.6.3 / lib / kadm5 / dump_log.c
blobf8309fb5acfee082931e9ca1670181da30fef6c7
1 /*
2 * Copyright (c) 1997 - 2003 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
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
31 * SUCH DAMAGE.
34 #include "iprop.h"
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[] = {
40 "get",
41 "delete",
42 "create",
43 "rename",
44 "chpass",
45 "modify",
46 "randkey",
47 "get_privs",
48 "get_princs",
49 "chpass_with_key",
50 "nop"
53 static void
54 print_entry(kadm5_server_context *server_context,
55 u_int32_t ver,
56 time_t timestamp,
57 enum kadm_ops op,
58 u_int32_t len,
59 krb5_storage *sp)
61 char t[256];
62 int32_t mask;
63 hdb_entry ent;
64 krb5_principal source;
65 char *name1, *name2;
66 krb5_data data;
67 krb5_context context = server_context->context;
69 off_t end = krb5_storage_seek(sp, 0, SEEK_CUR) + len;
71 krb5_error_code ret;
73 strftime(t, sizeof(t), "%Y-%m-%d %H:%M:%S", localtime(&timestamp));
75 if(op < kadm_get || op > kadm_nop) {
76 printf("unknown op: %d\n", op);
77 krb5_storage_seek(sp, end, SEEK_SET);
78 return;
81 printf ("%s: ver = %u, timestamp = %s, len = %u\n",
82 op_names[op], ver, t, len);
83 switch(op) {
84 case kadm_delete:
85 krb5_ret_principal(sp, &source);
86 krb5_unparse_name(context, source, &name1);
87 printf(" %s\n", name1);
88 free(name1);
89 krb5_free_principal(context, source);
90 break;
91 case kadm_rename:
92 ret = krb5_data_alloc(&data, len);
93 if (ret)
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);
101 free(name1);
102 free(name2);
103 krb5_free_principal(context, source);
104 hdb_free_entry(context, &ent);
105 break;
106 case kadm_create:
107 ret = krb5_data_alloc(&data, len);
108 if (ret)
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);
112 if(ret)
113 abort();
114 mask = ~0;
115 goto foo;
116 case kadm_modify:
117 ret = krb5_data_alloc(&data, len);
118 if (ret)
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);
123 if(ret)
124 abort();
125 foo:
126 if(ent.principal /* mask & KADM5_PRINCIPAL */) {
127 krb5_unparse_name(context, ent.principal, &name1);
128 printf(" principal = %s\n", name1);
129 free(name1);
131 if(mask & KADM5_PRINC_EXPIRE_TIME) {
132 if(ent.valid_end == NULL) {
133 strcpy(t, "never");
134 } else {
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) {
142 strcpy(t, "never");
143 } else {
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");
159 else
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");
166 else
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) {
180 printf(" mkvno\n");
182 if(mask & KADM5_AUX_ATTRIBUTES) {
183 printf(" aux attributes\n");
185 if(mask & KADM5_POLICY) {
186 printf(" policy\n");
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);
207 break;
208 case kadm_nop :
209 break;
210 default:
211 abort();
213 krb5_storage_seek(sp, end, SEEK_SET);
216 static char *realm;
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;
231 krb5_error_code ret;
232 void *kadm_handle;
233 kadm5_server_context *server_context;
234 kadm5_config_params conf;
236 krb5_program_setup(&context, argc, argv, args, num_args, NULL);
238 if(help_flag)
239 krb5_std_usage(0, args, num_args);
240 if(version_flag) {
241 print_version(NULL);
242 exit(0);
245 memset(&conf, 0, sizeof(conf));
246 if(realm) {
247 conf.mask |= KADM5_CONFIG_REALM;
248 conf.realm = realm;
250 ret = kadm5_init_with_password_ctx (context,
251 KADM5_ADMIN_SERVICE,
252 NULL,
253 KADM5_ADMIN_SERVICE,
254 &conf, 0, 0,
255 &kadm_handle);
256 if (ret)
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);
262 if (ret)
263 krb5_err (context, 1, ret, "kadm5_log_init");
265 ret = kadm5_log_foreach (server_context, print_entry);
266 if(ret)
267 krb5_warn(context, ret, "kadm5_log_foreach");
269 ret = kadm5_log_end (server_context);
270 if (ret)
271 krb5_warn(context, ret, "kadm5_log_end");
272 return 0;