2 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
7 * This module will parse the update logs on the master or slave servers.
12 #include <sys/types.h>
17 #include <kdb/kdb_log.h>
18 #include <kadm5/admin.h>
20 static char *progname
;
25 (void) fprintf(stderr
, gettext("\nUsage: %s [-h] [-v] [-e num]\n\n"),
31 * Print the individual types if verbose mode was specified.
34 print_attr(kdbe_attr_type_t type
)
38 (void) printf(gettext("\t\tAttribute flags\n"));
41 (void) printf(gettext("\t\tMaximum ticket life\n"));
43 case AT_MAX_RENEW_LIFE
:
44 (void) printf(gettext("\t\tMaximum renewable life\n"));
47 (void) printf(gettext("\t\tPrincipal expiration\n"));
50 (void) printf(gettext("\t\tPassword expiration\n"));
53 (void) printf(gettext("\t\tLast successful auth\n"));
56 (void) printf(gettext("\t\tLast failed auth\n"));
58 case AT_FAIL_AUTH_COUNT
:
59 (void) printf(gettext("\t\tFailed passwd attempt\n"));
62 (void) printf(gettext("\t\tPrincipal\n"));
65 (void) printf(gettext("\t\tKey data\n"));
68 (void) printf(gettext("\t\tTL data\n"));
71 (void) printf(gettext("\t\tLength\n"));
74 (void) printf(gettext("\t\tModifying principal\n"));
77 (void) printf(gettext("\t\tModification time\n"));
80 (void) printf(gettext("\t\tModified where\n"));
82 case AT_PW_LAST_CHANGE
:
83 (void) printf(gettext("\t\tPassword last changed\n"));
86 (void) printf(gettext("\t\tPassword policy\n"));
88 case AT_PW_POLICY_SWITCH
:
89 (void) printf(gettext("\t\tPassword policy switch\n"));
92 (void) printf(gettext("\t\tPassword history KVNO\n"));
95 (void) printf(gettext("\t\tPassword history\n"));
101 * Print the update entry information
104 print_update(kdb_hlog_t
*ulog
, uint32_t entry
, bool_t verbose
)
107 uint32_t start_sno
, i
, j
, indx
;
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
;
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"));
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"));
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 : "));
147 (void) printf(gettext("Delete\n"));
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"));
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"));
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
);
177 for (j
= 0; j
< upd
.kdb_update
.kdbe_t_len
; j
++)
179 upd
.kdb_update
.kdbe_t_val
[j
].av_type
);
181 xdr_free(xdr_kdb_incr_update_t
, (char *)&upd
);
187 main(int argc
, char **argv
)
190 bool_t verbose
= FALSE
;
191 bool_t headeronly
= FALSE
;
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"));
214 while ((c
= getopt(argc
, argv
, "vhe:")) != -1) {
220 entry
= atoi(optarg
);
230 if (krb5_init_context(&context
)) {
231 (void) fprintf(stderr
,
232 gettext("Unable to initialize Kerberos\n\n"));
236 (void) memset((char *)¶ms
, 0, sizeof (params
));
238 if (kadm5_get_config_params(context
, NULL
, NULL
, ¶ms
, ¶ms
)) {
239 (void) fprintf(stderr
,
240 gettext("Couldn't read database_name\n\n"));
244 (void) printf(gettext("\nKerberos update log (%s.ulog)\n"),
247 if (ulog_map(context
, ¶ms
, FKPROPLOG
)) {
248 (void) fprintf(stderr
, gettext("Unable to map log file "
249 "%s.ulog\n\n"), params
.dbname
);
253 log_ctx
= context
->kdblog_context
;
255 ulog
= log_ctx
->ulog
;
257 (void) fprintf(stderr
, gettext("Unable to map log file "
258 "%s.ulog\n\n"), params
.dbname
);
262 if (ulog
->kdb_hmagic
!= KDB_HMAGIC
) {
263 (void) fprintf(stderr
,
264 gettext("Corrupt header log, exiting\n\n"));
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
) {
273 (void) printf(gettext("Stable\n"));
276 (void) printf(gettext("Unstable\n"));
279 (void) printf(gettext("Corrupt\n"));
282 (void) printf(gettext("Unknown state: %d\n"),
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"));
292 if (ulog
->kdb_first_sno
== 0)
293 (void) printf(gettext("\tFirst serial # : None\n"));
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"));
306 if (ulog
->kdb_first_time
.seconds
== 0L)
307 (void) printf(gettext("\tFirst time stamp : None\n"));
309 (void) printf(gettext("\tFirst time stamp : %s"),
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
);