2 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
6 #pragma ident "%Z%%M% %I% %E% SMI"
9 * This module will parse the update logs on the master or slave servers.
14 #include <sys/types.h>
19 #include <kdb/kdb_log.h>
20 #include <kadm5/admin.h>
22 static char *progname
;
27 (void) fprintf(stderr
, gettext("\nUsage: %s [-h] [-v] [-e num]\n\n"),
33 * Print the individual types if verbose mode was specified.
36 print_attr(kdbe_attr_type_t type
)
40 (void) printf(gettext("\t\tAttribute flags\n"));
43 (void) printf(gettext("\t\tMaximum ticket life\n"));
45 case AT_MAX_RENEW_LIFE
:
46 (void) printf(gettext("\t\tMaximum renewable life\n"));
49 (void) printf(gettext("\t\tPrincipal expiration\n"));
52 (void) printf(gettext("\t\tPassword expiration\n"));
55 (void) printf(gettext("\t\tLast successful auth\n"));
58 (void) printf(gettext("\t\tLast failed auth\n"));
60 case AT_FAIL_AUTH_COUNT
:
61 (void) printf(gettext("\t\tFailed passwd attempt\n"));
64 (void) printf(gettext("\t\tPrincipal\n"));
67 (void) printf(gettext("\t\tKey data\n"));
70 (void) printf(gettext("\t\tTL data\n"));
73 (void) printf(gettext("\t\tLength\n"));
76 (void) printf(gettext("\t\tModifying principal\n"));
79 (void) printf(gettext("\t\tModification time\n"));
82 (void) printf(gettext("\t\tModified where\n"));
84 case AT_PW_LAST_CHANGE
:
85 (void) printf(gettext("\t\tPassword last changed\n"));
88 (void) printf(gettext("\t\tPassword policy\n"));
90 case AT_PW_POLICY_SWITCH
:
91 (void) printf(gettext("\t\tPassword policy switch\n"));
94 (void) printf(gettext("\t\tPassword history KVNO\n"));
97 (void) printf(gettext("\t\tPassword history\n"));
103 * Print the update entry information
106 print_update(kdb_hlog_t
*ulog
, uint32_t entry
, bool_t verbose
)
109 uint32_t start_sno
, i
, j
, indx
;
111 kdb_ent_header_t
*indx_log
;
112 kdb_incr_update_t upd
;
114 if (entry
&& (entry
< ulog
->kdb_num
))
115 start_sno
= ulog
->kdb_last_sno
- entry
;
117 start_sno
= ulog
->kdb_first_sno
- 1;
119 for (i
= start_sno
; i
< ulog
->kdb_last_sno
; i
++) {
120 indx
= i
% ulog
->kdb_num
;
122 indx_log
= (kdb_ent_header_t
*)INDEX(ulog
, indx
);
125 * Check for corrupt update entry
127 if (indx_log
->kdb_umagic
!= KDB_UMAGIC
) {
128 (void) fprintf(stderr
,
129 gettext("Corrupt update entry\n\n"));
133 (void) memset((char *)&upd
, 0, sizeof (kdb_incr_update_t
));
134 xdrmem_create(&xdrs
, (char *)indx_log
->entry_data
,
135 indx_log
->kdb_entry_size
, XDR_DECODE
);
136 if (!xdr_kdb_incr_update_t(&xdrs
, &upd
)) {
137 (void) printf(gettext("Entry data decode failure\n\n"));
141 (void) printf("---\n");
142 (void) printf(gettext("Update Entry\n"));
144 (void) printf(gettext("\tUpdate serial # : %u\n"),
145 indx_log
->kdb_entry_sno
);
147 (void) printf(gettext("\tUpdate operation : "));
149 (void) printf(gettext("Delete\n"));
151 (void) printf(gettext("Add\n"));
153 dbprinc
= malloc(upd
.kdb_princ_name
.utf8str_t_len
+ 1);
154 if (dbprinc
== NULL
) {
155 (void) printf(gettext("Could not allocate "
156 "principal name\n\n"));
159 (void) strlcpy(dbprinc
, upd
.kdb_princ_name
.utf8str_t_val
,
160 (upd
.kdb_princ_name
.utf8str_t_len
+ 1));
161 (void) printf(gettext("\tUpdate principal : %s\n"), dbprinc
);
163 (void) printf(gettext("\tUpdate size : %u\n"),
164 indx_log
->kdb_entry_size
);
166 (void) printf(gettext("\tUpdate committed : %s\n"),
167 indx_log
->kdb_commit
? "True" : "False");
169 if (indx_log
->kdb_time
.seconds
== 0L)
170 (void) printf(gettext("\tUpdate time stamp : None\n"));
172 (void) printf(gettext("\tUpdate time stamp : %s"),
173 ctime((time_t *)&(indx_log
->kdb_time
.seconds
)));
175 (void) printf(gettext("\tAttributes changed : %d\n"),
176 upd
.kdb_update
.kdbe_t_len
);
179 for (j
= 0; j
< upd
.kdb_update
.kdbe_t_len
; j
++)
181 upd
.kdb_update
.kdbe_t_val
[j
].av_type
);
183 xdr_free(xdr_kdb_incr_update_t
, (char *)&upd
);
190 main(int argc
, char **argv
)
193 bool_t verbose
= FALSE
;
194 bool_t headeronly
= FALSE
;
196 krb5_context context
;
197 kadm5_config_params params
;
198 kdb_log_context
*log_ctx
;
199 kdb_hlog_t
*ulog
= NULL
;
201 (void) setlocale(LC_ALL
, "");
203 #if !defined(TEXT_DOMAIN)
204 #define TEXT_DOMAIN "SYS_TEST"
205 #endif /* TEXT_DOMAIN */
207 (void) textdomain(TEXT_DOMAIN
);
209 if (geteuid() != (uid_t
)0) {
210 (void) fprintf(stderr
,
211 gettext("kproplog must be run as root\n\n"));
217 while ((c
= getopt(argc
, argv
, "vhe:")) != -1) {
223 entry
= atoi(optarg
);
233 if (krb5_init_context(&context
)) {
234 (void) fprintf(stderr
,
235 gettext("Unable to initialize Kerberos\n\n"));
239 (void) memset((char *)¶ms
, 0, sizeof (params
));
241 if (kadm5_get_config_params(context
, NULL
, NULL
, ¶ms
, ¶ms
)) {
242 (void) fprintf(stderr
,
243 gettext("Couldn't read database_name\n\n"));
247 (void) printf(gettext("\nKerberos update log (%s.ulog)\n"),
250 if (ulog_map(context
, ¶ms
, FKPROPLOG
)) {
251 (void) fprintf(stderr
, gettext("Unable to map log file "
252 "%s.ulog\n\n"), params
.dbname
);
256 log_ctx
= context
->kdblog_context
;
258 ulog
= log_ctx
->ulog
;
260 (void) fprintf(stderr
, gettext("Unable to map log file "
261 "%s.ulog\n\n"), params
.dbname
);
265 if (ulog
->kdb_hmagic
!= KDB_HMAGIC
) {
266 (void) fprintf(stderr
,
267 gettext("Corrupt header log, exiting\n\n"));
271 (void) printf(gettext("Update log dump :\n"));
272 (void) printf(gettext("\tLog version # : %u\n"), ulog
->db_version_num
);
273 (void) printf(gettext("\tLog state : "));
274 switch (ulog
->kdb_state
) {
276 (void) printf(gettext("Stable\n"));
279 (void) printf(gettext("Unstable\n"));
282 (void) printf(gettext("Corrupt\n"));
285 (void) printf(gettext("Unknown state: %d\n"),
289 (void) printf(gettext("\tEntry block size : %u\n"), ulog
->kdb_block
);
290 (void) printf(gettext("\tNumber of entries : %u\n"), ulog
->kdb_num
);
292 if (ulog
->kdb_last_sno
== 0)
293 (void) printf(gettext("\tLast serial # : None\n"));
295 if (ulog
->kdb_first_sno
== 0)
296 (void) printf(gettext("\tFirst serial # : None\n"));
298 (void) printf(gettext("\tFirst serial # : "));
299 (void) printf("%u\n", ulog
->kdb_first_sno
);
302 (void) printf(gettext("\tLast serial # : "));
303 (void) printf("%u\n", ulog
->kdb_last_sno
);
306 if (ulog
->kdb_last_time
.seconds
== 0L) {
307 (void) printf(gettext("\tLast time stamp : None\n"));
309 if (ulog
->kdb_first_time
.seconds
== 0L)
310 (void) printf(gettext("\tFirst time stamp : None\n"));
312 (void) printf(gettext("\tFirst time stamp : %s"),
314 &(ulog
->kdb_first_time
.seconds
)));
317 (void) printf(gettext("\tLast time stamp : %s\n"),
318 ctime((time_t *)&(ulog
->kdb_last_time
.seconds
)));
321 if ((!headeronly
) && ulog
->kdb_num
) {
322 print_update(ulog
, entry
, verbose
);