dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / krb5 / kproplog / kproplog.c
blob31ef5cc582f219bb22581af3f1105dc5e91287b6
1 /*
2 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
4 */
6 /*
7 * This module will parse the update logs on the master or slave servers.
8 */
10 #include <stdio.h>
11 #include <libintl.h>
12 #include <sys/types.h>
13 #include <time.h>
14 #include <limits.h>
15 #include <locale.h>
16 #include <syslog.h>
17 #include <kdb/kdb_log.h>
18 #include <kadm5/admin.h>
20 static char *progname;
22 static void
23 usage()
25 (void) fprintf(stderr, gettext("\nUsage: %s [-h] [-v] [-e num]\n\n"),
26 progname);
27 exit(1);
31 * Print the individual types if verbose mode was specified.
33 static void
34 print_attr(kdbe_attr_type_t type)
36 switch (type) {
37 case AT_ATTRFLAGS:
38 (void) printf(gettext("\t\tAttribute flags\n"));
39 break;
40 case AT_MAX_LIFE:
41 (void) printf(gettext("\t\tMaximum ticket life\n"));
42 break;
43 case AT_MAX_RENEW_LIFE:
44 (void) printf(gettext("\t\tMaximum renewable life\n"));
45 break;
46 case AT_EXP:
47 (void) printf(gettext("\t\tPrincipal expiration\n"));
48 break;
49 case AT_PW_EXP:
50 (void) printf(gettext("\t\tPassword expiration\n"));
51 break;
52 case AT_LAST_SUCCESS:
53 (void) printf(gettext("\t\tLast successful auth\n"));
54 break;
55 case AT_LAST_FAILED:
56 (void) printf(gettext("\t\tLast failed auth\n"));
57 break;
58 case AT_FAIL_AUTH_COUNT:
59 (void) printf(gettext("\t\tFailed passwd attempt\n"));
60 break;
61 case AT_PRINC:
62 (void) printf(gettext("\t\tPrincipal\n"));
63 break;
64 case AT_KEYDATA:
65 (void) printf(gettext("\t\tKey data\n"));
66 break;
67 case AT_TL_DATA:
68 (void) printf(gettext("\t\tTL data\n"));
69 break;
70 case AT_LEN:
71 (void) printf(gettext("\t\tLength\n"));
72 break;
73 case AT_MOD_PRINC:
74 (void) printf(gettext("\t\tModifying principal\n"));
75 break;
76 case AT_MOD_TIME:
77 (void) printf(gettext("\t\tModification time\n"));
78 break;
79 case AT_MOD_WHERE:
80 (void) printf(gettext("\t\tModified where\n"));
81 break;
82 case AT_PW_LAST_CHANGE:
83 (void) printf(gettext("\t\tPassword last changed\n"));
84 break;
85 case AT_PW_POLICY:
86 (void) printf(gettext("\t\tPassword policy\n"));
87 break;
88 case AT_PW_POLICY_SWITCH:
89 (void) printf(gettext("\t\tPassword policy switch\n"));
90 break;
91 case AT_PW_HIST_KVNO:
92 (void) printf(gettext("\t\tPassword history KVNO\n"));
93 break;
94 case AT_PW_HIST:
95 (void) printf(gettext("\t\tPassword history\n"));
96 break;
97 } /* switch */
101 * Print the update entry information
103 static void
104 print_update(kdb_hlog_t *ulog, uint32_t entry, bool_t verbose)
106 XDR xdrs;
107 uint32_t start_sno, i, j, indx;
108 char *dbprinc;
109 kdb_ent_header_t *indx_log;
110 kdb_incr_update_t upd;
112 if (entry && (entry < ulog->kdb_num))
113 start_sno = ulog->kdb_last_sno - entry;
114 else
115 start_sno = ulog->kdb_first_sno - 1;
117 for (i = start_sno; i < ulog->kdb_last_sno; i++) {
118 indx = i % ulog->kdb_num;
120 indx_log = (kdb_ent_header_t *)INDEX(ulog, indx);
123 * Check for corrupt update entry
125 if (indx_log->kdb_umagic != KDB_UMAGIC) {
126 (void) fprintf(stderr,
127 gettext("Corrupt update entry\n\n"));
128 exit(1);
131 (void) memset((char *)&upd, 0, sizeof (kdb_incr_update_t));
132 xdrmem_create(&xdrs, (char *)indx_log->entry_data,
133 indx_log->kdb_entry_size, XDR_DECODE);
134 if (!xdr_kdb_incr_update_t(&xdrs, &upd)) {
135 (void) printf(gettext("Entry data decode failure\n\n"));
136 exit(1);
139 (void) printf("---\n");
140 (void) printf(gettext("Update Entry\n"));
142 (void) printf(gettext("\tUpdate serial # : %u\n"),
143 indx_log->kdb_entry_sno);
145 (void) printf(gettext("\tUpdate operation : "));
146 if (upd.kdb_deleted)
147 (void) printf(gettext("Delete\n"));
148 else
149 (void) printf(gettext("Add\n"));
151 dbprinc = malloc(upd.kdb_princ_name.utf8str_t_len + 1);
152 if (dbprinc == NULL) {
153 (void) printf(gettext("Could not allocate "
154 "principal name\n\n"));
155 exit(1);
157 (void) strlcpy(dbprinc, upd.kdb_princ_name.utf8str_t_val,
158 (upd.kdb_princ_name.utf8str_t_len + 1));
159 (void) printf(gettext("\tUpdate principal : %s\n"), dbprinc);
161 (void) printf(gettext("\tUpdate size : %u\n"),
162 indx_log->kdb_entry_size);
164 (void) printf(gettext("\tUpdate committed : %s\n"),
165 indx_log->kdb_commit ? "True" : "False");
167 if (indx_log->kdb_time.seconds == 0L)
168 (void) printf(gettext("\tUpdate time stamp : None\n"));
169 else
170 (void) printf(gettext("\tUpdate time stamp : %s"),
171 ctime((time_t *)&(indx_log->kdb_time.seconds)));
173 (void) printf(gettext("\tAttributes changed : %d\n"),
174 upd.kdb_update.kdbe_t_len);
176 if (verbose)
177 for (j = 0; j < upd.kdb_update.kdbe_t_len; j++)
178 print_attr(
179 upd.kdb_update.kdbe_t_val[j].av_type);
181 xdr_free(xdr_kdb_incr_update_t, (char *)&upd);
182 free(dbprinc);
183 } /* for */
187 main(int argc, char **argv)
189 int c;
190 bool_t verbose = FALSE;
191 bool_t headeronly = FALSE;
192 uint32_t entry = 0;
193 krb5_context context;
194 kadm5_config_params params;
195 kdb_log_context *log_ctx;
196 kdb_hlog_t *ulog = NULL;
198 (void) setlocale(LC_ALL, "");
200 #if !defined(TEXT_DOMAIN)
201 #define TEXT_DOMAIN "SYS_TEST"
202 #endif /* TEXT_DOMAIN */
204 (void) textdomain(TEXT_DOMAIN);
206 if (geteuid() != (uid_t)0) {
207 (void) fprintf(stderr,
208 gettext("kproplog must be run as root\n\n"));
209 exit(1);
212 progname = argv[0];
214 while ((c = getopt(argc, argv, "vhe:")) != -1) {
215 switch (c) {
216 case 'h':
217 headeronly = TRUE;
218 break;
219 case 'e':
220 entry = atoi(optarg);
221 break;
222 case 'v':
223 verbose = TRUE;
224 break;
225 default:
226 usage();
230 if (krb5_init_context(&context)) {
231 (void) fprintf(stderr,
232 gettext("Unable to initialize Kerberos\n\n"));
233 exit(1);
236 (void) memset((char *)&params, 0, sizeof (params));
238 if (kadm5_get_config_params(context, NULL, NULL, &params, &params)) {
239 (void) fprintf(stderr,
240 gettext("Couldn't read database_name\n\n"));
241 exit(1);
244 (void) printf(gettext("\nKerberos update log (%s.ulog)\n"),
245 params.dbname);
247 if (ulog_map(context, &params, FKPROPLOG)) {
248 (void) fprintf(stderr, gettext("Unable to map log file "
249 "%s.ulog\n\n"), params.dbname);
250 exit(1);
253 log_ctx = context->kdblog_context;
254 if (log_ctx)
255 ulog = log_ctx->ulog;
256 else {
257 (void) fprintf(stderr, gettext("Unable to map log file "
258 "%s.ulog\n\n"), params.dbname);
259 exit(1);
262 if (ulog->kdb_hmagic != KDB_HMAGIC) {
263 (void) fprintf(stderr,
264 gettext("Corrupt header log, exiting\n\n"));
265 exit(1);
268 (void) printf(gettext("Update log dump :\n"));
269 (void) printf(gettext("\tLog version # : %u\n"), ulog->db_version_num);
270 (void) printf(gettext("\tLog state : "));
271 switch (ulog->kdb_state) {
272 case KDB_STABLE:
273 (void) printf(gettext("Stable\n"));
274 break;
275 case KDB_UNSTABLE:
276 (void) printf(gettext("Unstable\n"));
277 break;
278 case KDB_CORRUPT:
279 (void) printf(gettext("Corrupt\n"));
280 break;
281 default:
282 (void) printf(gettext("Unknown state: %d\n"),
283 ulog->kdb_state);
284 break;
286 (void) printf(gettext("\tEntry block size : %u\n"), ulog->kdb_block);
287 (void) printf(gettext("\tNumber of entries : %u\n"), ulog->kdb_num);
289 if (ulog->kdb_last_sno == 0)
290 (void) printf(gettext("\tLast serial # : None\n"));
291 else {
292 if (ulog->kdb_first_sno == 0)
293 (void) printf(gettext("\tFirst serial # : None\n"));
294 else {
295 (void) printf(gettext("\tFirst serial # : "));
296 (void) printf("%u\n", ulog->kdb_first_sno);
299 (void) printf(gettext("\tLast serial # : "));
300 (void) printf("%u\n", ulog->kdb_last_sno);
303 if (ulog->kdb_last_time.seconds == 0L) {
304 (void) printf(gettext("\tLast time stamp : None\n"));
305 } else {
306 if (ulog->kdb_first_time.seconds == 0L)
307 (void) printf(gettext("\tFirst time stamp : None\n"));
308 else {
309 (void) printf(gettext("\tFirst time stamp : %s"),
310 ctime((time_t *)
311 &(ulog->kdb_first_time.seconds)));
314 (void) printf(gettext("\tLast time stamp : %s\n"),
315 ctime((time_t *)&(ulog->kdb_last_time.seconds)));
318 if ((!headeronly) && ulog->kdb_num) {
319 print_update(ulog, entry, verbose);
322 (void) printf("\n");
324 return (0);