1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* kdc/kdc_log.c - Logging functions for KDC requests */
4 * Copyright 2008,2009 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.
30 #include "adm_proto.h"
33 * A note on KDC-status string format.
35 * - All letters in the status string should be capitalized;
36 * - the words in the status phrase are separated by underscores;
37 * - abbreviations should be avoided. Some acceptable "standard" acronyms
38 * are AS_REQ, TGS_REP etc.
39 * - since in almost all cases KDC status string is set on error, no need
40 * to state this fact as part of the status string;
41 * - KDC status string should be an imperative phrase.
43 * Example: "MAKE_RANDOM_KEY"
46 /* Main logging routines for ticket requests.
48 There are a few simple cases -- unparseable requests mainly --
49 where messages are logged otherwise, but once a ticket request can
50 be decoded in some basic way, these routines are used for logging
53 /* "status" is null to indicate success. */
54 /* Someday, pass local address/port as well. */
55 /* Currently no info about name canonicalization is logged. */
57 log_as_req(krb5_context context,
58 const krb5_fulladdr *local_addr,
59 const krb5_fulladdr *remote_addr,
60 krb5_kdc_req *request, krb5_kdc_rep *reply,
61 krb5_db_entry *client, const char *cname,
62 krb5_db_entry *server, const char *sname,
63 krb5_timestamp authtime,
64 const char *status, krb5_error_code errcode, const char *emsg)
66 const char *fromstring = 0;
67 char fromstringbuf[70];
68 char *ktypestr = NULL;
69 const char *cname2 = cname ? cname : "<unknown client>";
70 const char *sname2 = sname ? sname : "<unknown server>";
72 fromstring = inet_ntop(ADDRTYPE2FAMILY(remote_addr->address->addrtype),
73 remote_addr->address->contents,
74 fromstringbuf, sizeof(fromstringbuf));
76 fromstring = "<unknown>";
78 ktypestr = ktypes2str(request->ktype, request->nktypes);
82 char *rep_etypestr = rep_etypes2str(reply);
83 krb5_klog_syslog(LOG_INFO, _("AS_REQ (%s) %s: ISSUE: authtime %u, %s, "
85 ktypestr ? ktypestr : "", fromstring,
86 (unsigned int)authtime,
87 rep_etypestr ? rep_etypestr : "", cname2, sname2);
91 krb5_klog_syslog(LOG_INFO, _("AS_REQ (%s) %s: %s: %s for %s%s%s"),
92 ktypestr ? ktypestr : "", fromstring, status, cname2,
93 sname2, emsg ? ", " : "", emsg ? emsg : "");
95 krb5_db_audit_as_req(context, request,
96 local_addr->address, remote_addr->address,
97 client, server, authtime, errcode);
103 * Unparse a principal for logging purposes and limit the string length.
104 * Ignore errors because the most likely errors are memory exhaustion, and many
105 * other things will fail in the logging functions in that case.
108 unparse_and_limit(krb5_context ctx, krb5_principal princ, char **str)
111 krb5_unparse_name(ctx, princ, str);
115 /* Here "status" must be non-null. Error code
116 KRB5KDC_ERR_SERVER_NOMATCH is handled specially.
118 Currently no info about name canonicalization is logged. */
120 log_tgs_req(krb5_context ctx, const krb5_fulladdr *from,
121 krb5_kdc_req *request, krb5_kdc_rep *reply,
122 krb5_principal cprinc, krb5_principal sprinc,
123 krb5_principal altcprinc,
124 krb5_timestamp authtime,
125 unsigned int c_flags,
126 const char *status, krb5_error_code errcode, const char *emsg)
128 char *ktypestr = NULL, *rep_etypestr = NULL;
129 const char *fromstring = 0;
130 char fromstringbuf[70];
131 char *cname = NULL, *sname = NULL, *altcname = NULL;
132 char *logcname = NULL, *logsname = NULL, *logaltcname = NULL;
134 fromstring = inet_ntop(ADDRTYPE2FAMILY(from->address->addrtype),
135 from->address->contents,
136 fromstringbuf, sizeof(fromstringbuf));
138 fromstring = "<unknown>";
140 unparse_and_limit(ctx, cprinc, &cname);
141 logcname = (cname != NULL) ? cname : "<unknown client>";
142 unparse_and_limit(ctx, sprinc, &sname);
143 logsname = (sname != NULL) ? sname : "<unknown server>";
144 unparse_and_limit(ctx, altcprinc, &altcname);
145 logaltcname = (altcname != NULL) ? altcname : "<unknown>";
147 /* Differences: server-nomatch message logs 2nd ticket's client
148 name (useful), and doesn't log ktypestr (probably not
150 if (errcode != KRB5KDC_ERR_SERVER_NOMATCH) {
151 ktypestr = ktypes2str(request->ktype, request->nktypes);
152 rep_etypestr = rep_etypes2str(reply);
153 krb5_klog_syslog(LOG_INFO, _("TGS_REQ (%s) %s: %s: authtime %u, %s%s "
155 ktypestr ? ktypestr : "", fromstring, status,
156 (unsigned int)authtime,
157 rep_etypestr ? rep_etypestr : "",
158 !errcode ? "," : "", logcname, logsname,
159 errcode ? ", " : "", errcode ? emsg : "");
160 if (isflagset(c_flags, KRB5_KDB_FLAG_PROTOCOL_TRANSITION))
161 krb5_klog_syslog(LOG_INFO,
162 _("... PROTOCOL-TRANSITION s4u-client=%s"),
164 else if (isflagset(c_flags, KRB5_KDB_FLAG_CONSTRAINED_DELEGATION))
165 krb5_klog_syslog(LOG_INFO,
166 _("... CONSTRAINED-DELEGATION s4u-client=%s"),
170 krb5_klog_syslog(LOG_INFO, _("TGS_REQ %s: %s: authtime %u, %s for %s, "
171 "2nd tkt client %s"),
172 fromstring, status, (unsigned int)authtime,
173 logcname, logsname, logaltcname);
177 krb5_free_unparsed_name(ctx, cname);
178 krb5_free_unparsed_name(ctx, sname);
179 krb5_free_unparsed_name(ctx, altcname);
183 log_tgs_badtrans(krb5_context ctx, krb5_principal cprinc,
184 krb5_principal sprinc, krb5_data *trcont,
185 krb5_error_code errcode)
189 const char *emsg = NULL;
190 char *cname = NULL, *sname = NULL;
191 char *logcname = NULL, *logsname = NULL;
193 unparse_and_limit(ctx, cprinc, &cname);
194 logcname = (cname != NULL) ? cname : "<unknown client>";
195 unparse_and_limit(ctx, sprinc, &sname);
196 logsname = (sname != NULL) ? sname : "<unknown server>";
198 tlen = trcont->length;
199 tdots = tlen > 125 ? "..." : "";
200 tlen = tlen > 125 ? 125 : tlen;
202 if (errcode == KRB5KRB_AP_ERR_ILL_CR_TKT)
203 krb5_klog_syslog(LOG_INFO, _("bad realm transit path from '%s' "
204 "to '%s' via '%.*s%s'"),
205 logcname, logsname, tlen,
206 trcont->data, tdots);
208 emsg = krb5_get_error_message(ctx, errcode);
209 krb5_klog_syslog(LOG_ERR, _("unexpected error checking transit "
210 "from '%s' to '%s' via '%.*s%s': %s"),
211 logcname, logsname, tlen,
214 krb5_free_error_message(ctx, emsg);
217 krb5_free_unparsed_name(ctx, cname);
218 krb5_free_unparsed_name(ctx, sname);
222 log_tgs_alt_tgt(krb5_context context, krb5_principal p)
225 if (krb5_unparse_name(context, p, &sname)) {
226 krb5_klog_syslog(LOG_INFO,
227 _("TGS_REQ: issuing alternate <un-unparsable> TGT"));
230 krb5_klog_syslog(LOG_INFO, _("TGS_REQ: issuing TGT %s"), sname);
233 /* OpenSolaris: audit_krb5kdc_tgs_req_alt_tgt(...) */