1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* include/k5-trace.h */
4 * Copyright (C) 2010 by the Massachusetts Institute of Technology.
7 * Export of this software from the United States of America may
8 * require a specific license from the United States Government.
9 * It is the responsibility of any person or organization contemplating
10 * export to obtain such a license before exporting.
12 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
13 * distribute this software and its documentation for any purpose and
14 * without fee is hereby granted, provided that the above copyright
15 * notice appear in all copies and that both that copyright notice and
16 * this permission notice appear in supporting documentation, and that
17 * the name of M.I.T. not be used in advertising or publicity pertaining
18 * to distribution of the software without specific, written prior
19 * permission. Furthermore if you modify this software you must label
20 * your software as modified software and not distribute it in such a
21 * fashion that it might be confused with the original M.I.T. software.
22 * M.I.T. makes no representations about the suitability of
23 * this software for any purpose. It is provided "as is" without express
24 * or implied warranty.
28 * This header contains trace macro definitions, which map trace points within
29 * the code to krb5int_trace() calls with descriptive text strings.
31 * Trace logging is intended to aid power users in diagnosing configuration
32 * problems by showing what's going on behind the scenes of complex operations.
33 * Although trace logging is sometimes useful to developers, it is not intended
34 * as a replacement for a debugger, and it is not desirable to drown the user
35 * in output. Observe the following guidelines when adding trace points:
37 * - Avoid mentioning function or variable names in messages.
39 * - Try to convey what decisions are being made and what external inputs
40 * they are based on, not the process of making decisions.
42 * - It is generally not necessary to trace before returning an unrecoverable
43 * error. If an error code is unclear by itself, make it clearer with
44 * krb5_set_error_message().
46 * - Keep macros simple. Add format specifiers to krb5int_trace's formatter
47 * as necessary (and document them here) instead of transforming macro
50 * - Like printf, the trace formatter interface is not type-safe. Check your
51 * formats carefully. Cast integral arguments to the appropriate type if
52 * they do not already patch.
54 * The following specifiers are supported by the formatter (see the
55 * implementation in lib/krb5/os/trace.c for details):
57 * {int} int, in decimal
58 * {long} long, in decimal
59 * {str} const char *, display as C string
60 * {lenstr} size_t and const char *, as a counted string
61 * {hexlenstr} size_t and const char *, as hex bytes
62 * {hashlenstr} size_t and const char *, as four-character hex hash
63 * {connstate} struct conn_state *, show socket type, address, port
64 * {data} krb5_data *, display as counted string
65 * {hexdata} krb5_data *, display as hex bytes
66 * {errno} int, display as number/errorstring
67 * {kerr} krb5_error_code, display as number/errorstring
68 * {keyblock} const krb5_keyblock *, display enctype and hash of key
69 * {key} krb5_key, display enctype and hash of key
70 * {cksum} const krb5_checksum *, display cksumtype and hex checksum
71 * {princ} krb5_principal, unparse and display
72 * {patypes} krb5_pa_data **, display list of padata type numbers
73 * {etype} krb5_enctype, display shortest name of enctype
74 * {etypes} krb5_enctype *, display list of enctypes
75 * {ccache} krb5_ccache, display type:name
76 * {keytab} krb5_keytab, display name
77 * {creds} krb5_creds *, display clientprinc -> serverprinc
83 #ifdef DISABLE_TRACING
84 #define TRACE(ctx, ...)
87 void krb5int_trace(krb5_context context, const char *fmt, ...);
89 /* Try to optimize away argument evaluation and function call when we're not
90 * tracing, if this source file knows the internals of the context. */
92 #define TRACE(ctx, ...) \
93 do { if (ctx->trace_callback != NULL) \
94 krb5int_trace(ctx, __VA_ARGS__); } while (0)
96 #define TRACE(ctx, ...) krb5int_trace(ctx, __VA_ARGS__)
99 #endif /* DISABLE_TRACING */
101 #define TRACE_CC_DESTROY(c, cache) \
102 TRACE(c, "Destroying ccache {ccache}", cache)
103 #define TRACE_CC_GEN_NEW(c, cache) \
104 TRACE(c, "Generating new unique ccache based on {ccache}", cache)
105 #define TRACE_CC_GET_CONFIG(c, cache, princ, key, data) \
106 TRACE(c, "Read config in {ccache} for {princ}: {str}: {data}", \
107 cache, princ, key, data)
108 #define TRACE_CC_INIT(c, cache, princ) \
109 TRACE(c, "Initializing {ccache} with default princ {princ}", \
111 #define TRACE_CC_MOVE(c, src, dst) \
112 TRACE(c, "Moving contents of ccache {src} to {dst}", src, dst)
113 #define TRACE_CC_NEW_UNIQUE(c, type) \
114 TRACE(c, "Resolving unique ccache of type {str}", type)
115 #define TRACE_CC_REMOVE(c, cache, creds) \
116 TRACE(c, "Removing {creds} from {ccache}", creds, cache)
117 #define TRACE_CC_RETRIEVE(c, cache, creds, ret) \
118 TRACE(c, "Retrieving {creds} from {ccache} with result: {kerr}", \
120 #define TRACE_CC_RETRIEVE_REF(c, cache, creds, ret) \
121 TRACE(c, "Retrying {creds} with result: {kerr}", creds, ret)
122 #define TRACE_CC_SET_CONFIG(c, cache, princ, key, data) \
123 TRACE(c, "Storing config in {ccache} for {princ}: {str}: {data}", \
124 cache, princ, key, data)
125 #define TRACE_CC_STORE(c, cache, creds) \
126 TRACE(c, "Storing {creds} in {ccache}", creds, cache)
127 #define TRACE_CC_STORE_TKT(c, cache, creds) \
128 TRACE(c, "Also storing {creds} based on ticket", creds)
130 #define TRACE_CCSELECT_VTINIT_FAIL(c, ret) \
131 TRACE(c, "ccselect module failed to init vtable: {kerr}", ret)
132 #define TRACE_CCSELECT_INIT_FAIL(c, name, ret) \
133 TRACE(c, "ccselect module {str} failed to init: {kerr}", name, ret)
134 #define TRACE_CCSELECT_MODCHOICE(c, name, server, cache, princ) \
135 TRACE(c, "ccselect module {str} chose cache {ccache} with client " \
136 "principal {princ} for server principal {princ}", name, cache, \
138 #define TRACE_CCSELECT_MODNOTFOUND(c, name, server, princ) \
139 TRACE(c, "ccselect module {str} chose client principal {princ} " \
140 "for server principal {princ} but found no cache", name, princ, \
142 #define TRACE_CCSELECT_MODFAIL(c, name, ret, server) \
143 TRACE(c, "ccselect module {str} yielded error {kerr} for server " \
144 "principal {princ}", name, ret, server)
145 #define TRACE_CCSELECT_NOTFOUND(c, server) \
146 TRACE(c, "ccselect can't find appropriate cache for server " \
147 "principal {princ}", server)
148 #define TRACE_CCSELECT_DEFAULT(c, cache, server) \
149 TRACE(c, "ccselect choosing default cache {ccache} for server " \
150 "principal {princ}", cache, server)
152 #define TRACE_FAST_ARMOR_CCACHE(c, ccache_name) \
153 TRACE(c, "FAST armor ccache: {str}", ccache_name)
154 #define TRACE_FAST_ARMOR_CCACHE_KEY(c, keyblock) \
155 TRACE(c, "Armor ccache sesion key: {keyblock}", keyblock)
156 #define TRACE_FAST_ARMOR_KEY(c, keyblock) \
157 TRACE(c, "FAST armor key: {keyblock}", keyblock)
158 #define TRACE_FAST_CCACHE_CONFIG(c) \
159 TRACE(c, "Using FAST due to armor ccache negotiation result")
160 #define TRACE_FAST_DECODE(c) \
161 TRACE(c, "Decoding FAST response")
162 #define TRACE_FAST_ENCODE(c) \
163 TRACE(c, "Encoding request body and padata into FAST request")
164 #define TRACE_FAST_NEGO(c, avail) \
165 TRACE(c, "FAST negotiation: {str}available", (avail) ? "" : "un")
166 #define TRACE_FAST_PADATA_UPGRADE(c) \
167 TRACE(c, "Upgrading to FAST due to presence of PA_FX_FAST in reply")
168 #define TRACE_FAST_REPLY_KEY(c, keyblock) \
169 TRACE(c, "FAST reply key: {keyblock}", keyblock)
170 #define TRACE_FAST_REQUIRED(c) \
171 TRACE(c, "Using FAST due to KRB5_FAST_REQUIRED flag")
173 #define TRACE_GIC_PWD_CHANGED(c) \
174 TRACE(c, "Getting initial TGT with changed password")
175 #define TRACE_GIC_PWD_CHANGEPW(c, tries) \
176 TRACE(c, "Attempting password change; {int} tries remaining", tries)
177 #define TRACE_GIC_PWD_EXPIRED(c) \
178 TRACE(c, "Principal expired; getting changepw ticket")
179 #define TRACE_GIC_PWD_MASTER(c) \
180 TRACE(c, "Retrying AS request with master KDC")
182 #define TRACE_ENCTYPE_LIST_UNKNOWN(c, profvar, name) \
183 TRACE(c, "Unrecognized enctype name in {str}: {str}", profvar, name)
185 #define TRACE_INIT_CREDS(c, princ) \
186 TRACE(c, "Getting initial credentials for {princ}", princ)
187 #define TRACE_INIT_CREDS_AS_KEY_GAK(c, keyblock) \
188 TRACE(c, "AS key obtained from gak_fct: {keyblock}", keyblock)
189 #define TRACE_INIT_CREDS_AS_KEY_PREAUTH(c, keyblock) \
190 TRACE(c, "AS key determined by preauth: {keyblock}", keyblock)
191 #define TRACE_INIT_CREDS_DECRYPTED_REPLY(c, keyblock) \
192 TRACE(c, "Decrypted AS reply; session key is: {keyblock}", keyblock)
193 #define TRACE_INIT_CREDS_ERROR_REPLY(c, code) \
194 TRACE(c, "Received error from KDC: {kerr}", code)
195 #define TRACE_INIT_CREDS_GAK(c, salt, s2kparams) \
196 TRACE(c, "Getting AS key, salt \"{data}\", params \"{data}\"", \
198 #define TRACE_INIT_CREDS_KEYTAB_LOOKUP(c, etypes) \
199 TRACE(c, "Looked up etypes in keytab: {etypes}", etypes)
200 #define TRACE_INIT_CREDS_KEYTAB_LOOKUP_FAILED(c, code) \
201 TRACE(c, "Couldn't lookup etypes in keytab: {kerr}", code)
202 #define TRACE_INIT_CREDS_PREAUTH_DECRYPT_FAIL(c, code) \
203 TRACE(c, "Decrypt with preauth AS key failed: {kerr}", code)
204 #define TRACE_INIT_CREDS_RESTART_FAST(c) \
205 TRACE(c, "Restarting to upgrade to FAST")
206 #define TRACE_INIT_CREDS_RESTART_PREAUTH_FAILED(c) \
207 TRACE(c, "Restarting due to PREAUTH_FAILED from FAST negotiation")
208 #define TRACE_INIT_CREDS_REFERRAL(c, realm) \
209 TRACE(c, "Following referral to realm {data}", realm)
210 #define TRACE_INIT_CREDS_RETRY_TCP(c) \
211 TRACE(c, "Request or response is too big for UDP; retrying with TCP")
212 #define TRACE_INIT_CREDS_SALT_PRINC(c, salt) \
213 TRACE(c, "Salt derived from principal: {data}", salt)
214 #define TRACE_INIT_CREDS_SERVICE(c, service) \
215 TRACE(c, "Setting initial creds service to {str}", service)
217 #define TRACE_KT_GET_ENTRY(c, keytab, princ, vno, enctype, err) \
218 TRACE(c, "Retrieving {princ} from {keytab} (vno {int}, enctype {etype}) " \
219 "with result: {kerr}", princ, keytab, (int) vno, enctype, err)
221 #define TRACE_MK_REP(c, ctime, cusec, subkey, seqnum) \
222 TRACE(c, "Creating AP-REP, time {long}.{int}, subkey {keyblock}, " \
223 "seqnum {int}", (long) ctime, (int) cusec, subkey, (int) seqnum)
225 #define TRACE_MK_REQ(c, creds, seqnum, subkey, sesskeyblock) \
226 TRACE(c, "Creating authenticator for {creds}, seqnum {int}, " \
227 "subkey {key}, session key {keyblock}", creds, (int) seqnum, \
228 subkey, sesskeyblock)
229 #define TRACE_MK_REQ_ETYPES(c, etypes) \
230 TRACE(c, "Negotiating for enctypes in authenticator: {etypes}", etypes)
232 #define TRACE_MSPAC_VERIFY_FAIL(c, err) \
233 TRACE(c, "PAC checksum verification failed: {kerr}", err)
234 #define TRACE_MSPAC_DISCARD_UNVERF(c) \
235 TRACE(c, "Filtering out unverified MS PAC")
237 #define TRACE_PREAUTH_COOKIE(c, len, data) \
238 TRACE(c, "Received cookie: {lenstr}", (size_t) len, data)
239 #define TRACE_PREAUTH_ENC_TS_KEY_GAK(c, keyblock) \
240 TRACE(c, "AS key obtained for encrypted timestamp: {keyblock}", keyblock)
241 #define TRACE_PREAUTH_ENC_TS(c, sec, usec, plain, enc) \
242 TRACE(c, "Encrypted timestamp (for {long}.{int}): plain {hexdata}, " \
243 "encrypted {hexdata}", (long) sec, (int) usec, plain, enc)
244 #define TRACE_PREAUTH_ETYPE_INFO(c, etype, salt, s2kparams) \
245 TRACE(c, "Selected etype info: etype {etype}, salt \"{data}\", " \
246 "params \"{data}\"", etype, salt, s2kparams)
247 #define TRACE_PREAUTH_INFO_FAIL(c, patype, code) \
248 TRACE(c, "Preauth builtin info function failure, type={int}: {kerr}", \
250 #define TRACE_PREAUTH_INPUT(c, padata) \
251 TRACE(c, "Processing preauth types: {patypes}", padata)
252 #define TRACE_PREAUTH_OUTPUT(c, padata) \
253 TRACE(c, "Produced preauth for next request: {patypes}", padata)
254 #define TRACE_PREAUTH_PROCESS(c, name, patype, flags, code) \
255 TRACE(c, "Preauth module {str} ({int}) (flags={int}) returned: " \
256 "{kerr}", name, (int) patype, flags, code)
257 #define TRACE_PREAUTH_SAM_KEY_GAK(c, keyblock) \
258 TRACE(c, "AS key obtained for SAM: {keyblock}", keyblock)
259 #define TRACE_PREAUTH_SALT(c, salt, patype) \
260 TRACE(c, "Received salt \"{data}\" via padata type {int}", salt, \
262 #define TRACE_PREAUTH_SKIP(c, name, patype) \
263 TRACE(c, "Skipping previously used preauth module {str} ({int})", \
265 #define TRACE_PREAUTH_TRYAGAIN_INPUT(c, padata) \
266 TRACE(c, "Preauth tryagain input types: {patypes}", padata)
267 #define TRACE_PREAUTH_TRYAGAIN_OUTPUT(c, padata) \
268 TRACE(c, "Followup preauth for next request: {patypes}", padata)
270 #define TRACE_PROFILE_ERR(c,subsection, section, retval) \
271 TRACE(c, "Bad value of {str} from [{str}] in conf file: {kerr}", \
272 subsection, section, retval)
274 #define TRACE_RD_REP(c, ctime, cusec, subkey, seqnum) \
275 TRACE(c, "Read AP-REP, time {long}.{int}, subkey {keyblock}, " \
276 "seqnum {int}", (long) ctime, (int) cusec, subkey, (int) seqnum)
277 #define TRACE_RD_REP_DCE(c, ctime, cusec, seqnum) \
278 TRACE(c, "Read DCE-style AP-REP, time {long}.{int}, seqnum {int}", \
279 (long) ctime, (int) cusec, (int) seqnum)
281 #define TRACE_RD_REQ_DECRYPT_ANY(c, princ, keyblock) \
282 TRACE(c, "Decrypted AP-REQ with server principal {princ}: " \
283 "{keyblock}", princ, keyblock)
284 #define TRACE_RD_REQ_DECRYPT_SPECIFIC(c, princ, keyblock) \
285 TRACE(c, "Decrypted AP-REQ with specified server principal {princ}: " \
286 "{keyblock}", princ, keyblock)
287 #define TRACE_RD_REQ_NEGOTIATED_ETYPE(c, etype) \
288 TRACE(c, "Negotiated enctype based on authenticator: {etype}", \
290 #define TRACE_RD_REQ_SUBKEY(c, keyblock) \
291 TRACE(c, "Authenticator contains subkey: {keyblock}", keyblock)
292 #define TRACE_RD_REQ_TICKET(c, client, server, keyblock) \
293 TRACE(c, "AP-REQ ticket: {princ} -> {princ}, session key {keyblock}", \
294 client, server, keyblock)
296 #define TRACE_SENDTO_KDC(c, len, rlm, master, tcp) \
297 TRACE(c, "Sending request ({int} bytes) to {data}{str}{str}", len, \
298 rlm, (master) ? " (master)" : "", (tcp) ? " (tcp only)" : "")
299 #define TRACE_SENDTO_KDC_MASTER(c, master) \
300 TRACE(c, "Response was{str} from master KDC", (master) ? "" : " not")
301 #define TRACE_SENDTO_KDC_RESOLVING(c, hostname) \
302 TRACE(c, "Resolving hostname {str}", hostname)
303 #define TRACE_SENDTO_KDC_RESPONSE(c, conn) \
304 TRACE(c, "Received answer from {connstate}", conn)
305 #define TRACE_SENDTO_KDC_TCP_CONNECT(c, conn) \
306 TRACE(c, "Initiating TCP connection to {connstate}", conn)
307 #define TRACE_SENDTO_KDC_TCP_DISCONNECT(c, conn) \
308 TRACE(c, "Terminating TCP connection to {connstate}", conn)
309 #define TRACE_SENDTO_KDC_TCP_ERROR_CONNECT(c, conn, err) \
310 TRACE(c, "TCP error connecting to {connstate}: {errno}", conn, err)
311 #define TRACE_SENDTO_KDC_TCP_ERROR_RECV(c, conn, err) \
312 TRACE(c, "TCP error receiving from {connstate}: {errno}", conn, err)
313 #define TRACE_SENDTO_KDC_TCP_ERROR_RECV_LEN(c, conn, err) \
314 TRACE(c, "TCP error receiving from {connstate}: {errno}", conn, err)
315 #define TRACE_SENDTO_KDC_TCP_ERROR_SEND(c, conn, err) \
316 TRACE(c, "TCP error sending to {connstate}: {errno}", conn, err)
317 #define TRACE_SENDTO_KDC_TCP_SEND(c, conn) \
318 TRACE(c, "Sending TCP request to {connstate}", conn)
319 #define TRACE_SENDTO_KDC_UDP_ERROR_RECV(c, conn, err) \
320 TRACE(c, "UDP error receiving from {connstate}: {errno}", conn, err)
321 #define TRACE_SENDTO_KDC_UDP_ERROR_SEND_INITIAL(c, conn, err) \
322 TRACE(c, "UDP error sending to {connstate}: {errno}", conn, err)
323 #define TRACE_SENDTO_KDC_UDP_ERROR_SEND_RETRY(c, conn, err) \
324 TRACE(c, "UDP error sending to {connstate}: {errno}", conn, err)
325 #define TRACE_SENDTO_KDC_UDP_SEND_INITIAL(c, conn) \
326 TRACE(c, "Sending initial UDP request to {connstate}", conn)
327 #define TRACE_SENDTO_KDC_UDP_SEND_RETRY(c, conn) \
328 TRACE(c, "Sending retry UDP request to {connstate}", conn)
330 #define TRACE_SEND_TGS_ETYPES(c, etypes) \
331 TRACE(c, "etypes requested in TGS request: {etypes}", etypes)
332 #define TRACE_SEND_TGS_SUBKEY(c, keyblock) \
333 TRACE(c, "Generated subkey for TGS request: {keyblock}", keyblock)
335 #define TRACE_TGS_REPLY(c, client, server, keyblock) \
336 TRACE(c, "TGS reply is for {princ} -> {princ} with session key " \
337 "{keyblock}", client, server, keyblock)
338 #define TRACE_TGS_REPLY_DECODE_SESSION(c, keyblock) \
339 TRACE(c, "TGS reply didn't decode with subkey; trying session key " \
340 "({keyblock)}", keyblock)
342 #define TRACE_TKT_CREDS(c, creds, cache) \
343 TRACE(c, "Getting credentials {creds} using ccache {ccache}", \
345 #define TRACE_TKT_CREDS_ADVANCE(c, realm) \
346 TRACE(c, "Received TGT for {data}; advancing current realm", realm)
347 #define TRACE_TKT_CREDS_CACHED_INTERMEDIATE_TGT(c, tgt) \
348 TRACE(c, "Found cached TGT for intermediate realm: {creds}", tgt)
349 #define TRACE_TKT_CREDS_CACHED_SERVICE_TGT(c, tgt) \
350 TRACE(c, "Found cached TGT for service realm: {creds}", tgt)
351 #define TRACE_TKT_CREDS_CLOSER_REALM(c, realm) \
352 TRACE(c, "Trying next closer realm in path: {data}", realm)
353 #define TRACE_TKT_CREDS_COMPLETE(c, princ) \
354 TRACE(c, "Received creds for desired service {princ}", princ)
355 #define TRACE_TKT_CREDS_FALLBACK(c, realm) \
356 TRACE(c, "Local realm referral failed; trying fallback realm {data}", \
358 #define TRACE_TKT_CREDS_LOCAL_TGT(c, tgt) \
359 TRACE(c, "Starting with TGT for client realm: {creds}", tgt)
360 #define TRACE_TKT_CREDS_NON_TGT(c, princ) \
361 TRACE(c, "Received non-TGT referral response ({princ}); trying " \
362 "again without referrals", princ)
363 #define TRACE_TKT_CREDS_OFFPATH(c, realm) \
364 TRACE(c, "Received TGT for offpath realm {data}", realm)
365 #define TRACE_TKT_CREDS_REFERRAL(c, princ) \
366 TRACE(c, "Following referral TGT {princ}", princ)
367 #define TRACE_TKT_CREDS_REFERRAL_REALM(c, princ) \
368 TRACE(c, "Server has referral realm; starting with {princ}", princ)
369 #define TRACE_TKT_CREDS_RESPONSE_CODE(c, code) \
370 TRACE(c, "TGS request result: {kerr}", code)
371 #define TRACE_TKT_CREDS_RETRY_TCP(c) \
372 TRACE(c, "Request or response is too big for UDP; retrying with TCP")
373 #define TRACE_TKT_CREDS_SAME_REALM_TGT(c, realm) \
374 TRACE(c, "Received TGT referral back to same realm ({data}); trying " \
375 "again without referrals", realm)
376 #define TRACE_TKT_CREDS_SERVICE_REQ(c, princ, referral) \
377 TRACE(c, "Requesting tickets for {princ}, referrals {str}", princ, \
378 (referral) ? "on" : "off")
379 #define TRACE_TKT_CREDS_TARGET_TGT(c, princ) \
380 TRACE(c, "Received TGT for service realm: {princ}", princ)
381 #define TRACE_TKT_CREDS_TARGET_TGT_OFFPATH(c, princ) \
382 TRACE(c, "Received TGT for service realm: {princ}", princ)
383 #define TRACE_TKT_CREDS_TGT_REQ(c, next, cur) \
384 TRACE(c, "Requesting TGT {princ} using TGT {princ}", next, cur)
385 #define TRACE_TKT_CREDS_WRONG_ENCTYPE(c) \
386 TRACE(c, "Retrying TGS request with desired service ticket enctypes")
388 #endif /* K5_TRACE_H */