]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
In KDC, log client principal in bad header ticket
authorrbasch <probe@tardis.internal.bright-prospects.com>
Tue, 3 Jun 2014 22:44:17 +0000 (18:44 -0400)
committerGreg Hudson <ghudson@mit.edu>
Wed, 11 Jun 2014 03:54:41 +0000 (23:54 -0400)
Fix KDC logging to include client principal in TGS_REQ logging even
during error conditions such as "Ticket expired".  As long as the
TGS_REQ can be decrypted and the client principal is available, it
should be included in the log, regardless of other errors which might
be detected.

krb5_rd_req_decoded and krb5_rd_req_decoded_anyflag (not public
interfaces) now leave the decrypted ticket in req->ticket->enc_part2
on success or failure, if the ticket was successfully decrypted.  This
does not affect the behavior of krb5_rd_req.

[ghudson@mit.edu: removed extraneous change, added commit message
summary and description of internal API change, fixed possible memory
leak, removed comment and #if 0 code block of purely historical
interest]

ticket: 7910

src/kdc/kdc_util.c
src/lib/krb5/krb/rd_req_dec.c

index 98e19375a53a8daddd1c7f0f4359dbbc92d6a296..cd276e4a9b9daf673323c6db01f8fff37dd14e5f 100644 (file)
@@ -363,6 +363,10 @@ cleanup:
  *
  * This function also implements key rollover support for kvno 0 cross-realm
  * TGTs issued by AD.
+ *
+ * If the ticket was successfully decrypted, it will be returned in *ticket
+ * even if we return an error because the ticket was invalid (e.g. if it was
+ * expired).
  */
 static
 krb5_error_code
@@ -371,12 +375,14 @@ kdc_rd_ap_req(kdc_realm_t *kdc_active_realm,
               krb5_db_entry **server, krb5_keyblock **tgskey,
               krb5_ticket **ticket)
 {
-    krb5_error_code     retval;
+    krb5_error_code     retval, ret2;
     krb5_enctype        search_enctype = apreq->ticket->enc_part.enctype;
     krb5_boolean        match_enctype = 1;
     krb5_kvno           kvno;
     size_t              tries = 3;
 
+    *ticket = NULL;
+
     /*
      * When we issue tickets we use the first key in the principals' highest
      * kvno keyset.  For non-cross-realm krbtgt principals we want to only
@@ -413,7 +419,17 @@ kdc_rd_ap_req(kdc_realm_t *kdc_active_realm,
         retval = krb5_rd_req_decoded_anyflag(kdc_context, &auth_context, apreq,
                                              apreq->ticket->server,
                                              kdc_active_realm->realm_keytab,
-                                             NULL, ticket);
+                                             NULL, NULL);
+
+        /* If the ticket was decrypted, save it even if it didn't validate, and
+         * don't try any more keys. */
+        if (apreq->ticket->enc_part2 != NULL) {
+            ret2 = krb5_copy_ticket(kdc_context, apreq->ticket, ticket);
+            if (!retval)
+                retval = ret2;
+            break;
+        }
+
     } while (retval && apreq->ticket->enc_part.kvno == 0 && kvno-- > 1 &&
              --tries > 0);
 
index fbfe36eb01e2d4e9576de343fb3193edbc9a28d1..df5ba7a35abc6a70d2208e2bd5a2dbc2e1dc19db 100644 (file)
@@ -791,13 +791,6 @@ cleanup:
     if (permitted_etypes != NULL &&
         permitted_etypes != (*auth_context)->permitted_etypes)
         free(permitted_etypes);
-    if (retval) {
-        /* only free if we're erroring out...otherwise some
-           applications will need the output. */
-        if (req->ticket->enc_part2)
-            krb5_free_enc_tkt_part(context, req->ticket->enc_part2);
-        req->ticket->enc_part2 = NULL;
-    }
     if (check_valid_flag)
         krb5_free_keyblock_contents(context, &decrypt_key);