1 /* $NetBSD: rd_req.c,v 1.1.1.2 2014/04/24 12:45:51 pettai Exp $ */
5 * Copyright (c) 1997 - 2007 Kungliga Tekniska Högskolan
6 * (Royal Institute of Technology, Stockholm, Sweden).
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the Institute nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 #include "krb5_locl.h"
39 static krb5_error_code
40 decrypt_tkt_enc_part (krb5_context context
,
42 EncryptedData
*enc_part
,
43 EncTicketPart
*decr_part
)
50 ret
= krb5_crypto_init(context
, key
, 0, &crypto
);
53 ret
= krb5_decrypt_EncryptedData (context
,
58 krb5_crypto_destroy(context
, crypto
);
62 ret
= decode_EncTicketPart(plain
.data
, plain
.length
, decr_part
, &len
);
64 krb5_set_error_message(context
, ret
,
65 N_("Failed to decode encrypted "
67 krb5_data_free (&plain
);
71 static krb5_error_code
72 decrypt_authenticator (krb5_context context
,
74 EncryptedData
*enc_part
,
75 Authenticator
*authenticator
,
83 ret
= krb5_crypto_init(context
, key
, 0, &crypto
);
86 ret
= krb5_decrypt_EncryptedData (context
,
88 usage
/* KRB5_KU_AP_REQ_AUTH */,
91 /* for backwards compatibility, also try the old usage */
92 if (ret
&& usage
== KRB5_KU_TGS_REQ_AUTH
)
93 ret
= krb5_decrypt_EncryptedData (context
,
98 krb5_crypto_destroy(context
, crypto
);
102 ret
= decode_Authenticator(plain
.data
, plain
.length
,
103 authenticator
, &len
);
104 krb5_data_free (&plain
);
108 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
109 krb5_decode_ap_req(krb5_context context
,
110 const krb5_data
*inbuf
,
115 ret
= decode_AP_REQ(inbuf
->data
, inbuf
->length
, ap_req
, &len
);
118 if (ap_req
->pvno
!= 5){
120 krb5_clear_error_message (context
);
121 return KRB5KRB_AP_ERR_BADVERSION
;
123 if (ap_req
->msg_type
!= krb_ap_req
){
125 krb5_clear_error_message (context
);
126 return KRB5KRB_AP_ERR_MSG_TYPE
;
128 if (ap_req
->ticket
.tkt_vno
!= 5){
130 krb5_clear_error_message (context
);
131 return KRB5KRB_AP_ERR_BADVERSION
;
136 static krb5_error_code
137 check_transited(krb5_context context
, Ticket
*ticket
, EncTicketPart
*enc
)
140 unsigned int num_realms
, n
;
144 * Windows 2000 and 2003 uses this inside their TGT so it's normaly
145 * not seen by others, however, samba4 joined with a Windows AD as
146 * a Domain Controller gets exposed to this.
148 if(enc
->transited
.tr_type
== 0 && enc
->transited
.contents
.length
== 0)
151 if(enc
->transited
.tr_type
!= DOMAIN_X500_COMPRESS
)
152 return KRB5KDC_ERR_TRTYPE_NOSUPP
;
154 if(enc
->transited
.contents
.length
== 0)
157 ret
= krb5_domain_x500_decode(context
, enc
->transited
.contents
,
158 &realms
, &num_realms
,
163 ret
= krb5_check_transited(context
, enc
->crealm
,
165 realms
, num_realms
, NULL
);
166 for (n
= 0; n
< num_realms
; n
++)
172 static krb5_error_code
173 find_etypelist(krb5_context context
,
174 krb5_auth_context auth_context
,
179 krb5_authdata adIfRelevant
;
182 memset(&adIfRelevant
, 0, sizeof(adIfRelevant
));
187 ad
= auth_context
->authenticator
->authorization_data
;
191 for (i
= 0; i
< ad
->len
; i
++) {
192 if (ad
->val
[i
].ad_type
== KRB5_AUTHDATA_IF_RELEVANT
) {
193 ret
= decode_AD_IF_RELEVANT(ad
->val
[i
].ad_data
.data
,
194 ad
->val
[i
].ad_data
.length
,
200 if (adIfRelevant
.len
== 1 &&
201 adIfRelevant
.val
[0].ad_type
==
202 KRB5_AUTHDATA_GSS_API_ETYPE_NEGOTIATION
) {
205 free_AD_IF_RELEVANT(&adIfRelevant
);
206 adIfRelevant
.len
= 0;
210 if (adIfRelevant
.len
== 0)
213 ret
= decode_EtypeList(adIfRelevant
.val
[0].ad_data
.data
,
214 adIfRelevant
.val
[0].ad_data
.length
,
218 krb5_clear_error_message(context
);
220 free_AD_IF_RELEVANT(&adIfRelevant
);
225 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
226 krb5_decrypt_ticket(krb5_context context
,
234 ret
= decrypt_tkt_enc_part (context
, key
, &ticket
->enc_part
, &t
);
240 time_t start
= t
.authtime
;
242 krb5_timeofday (context
, &now
);
244 start
= *t
.starttime
;
245 if(start
- now
> context
->max_skew
247 && !(flags
& KRB5_VERIFY_AP_REQ_IGNORE_INVALID
))) {
248 free_EncTicketPart(&t
);
249 krb5_clear_error_message (context
);
250 return KRB5KRB_AP_ERR_TKT_NYV
;
252 if(now
- t
.endtime
> context
->max_skew
) {
253 free_EncTicketPart(&t
);
254 krb5_clear_error_message (context
);
255 return KRB5KRB_AP_ERR_TKT_EXPIRED
;
258 if(!t
.flags
.transited_policy_checked
) {
259 ret
= check_transited(context
, ticket
, &t
);
261 free_EncTicketPart(&t
);
270 free_EncTicketPart(&t
);
274 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
275 krb5_verify_authenticator_checksum(krb5_context context
,
276 krb5_auth_context ac
,
282 krb5_authenticator authenticator
;
285 ret
= krb5_auth_con_getauthenticator (context
,
290 if(authenticator
->cksum
== NULL
) {
291 krb5_free_authenticator(context
, &authenticator
);
294 ret
= krb5_auth_con_getkey(context
, ac
, &key
);
296 krb5_free_authenticator(context
, &authenticator
);
299 ret
= krb5_crypto_init(context
, key
, 0, &crypto
);
302 ret
= krb5_verify_checksum (context
,
304 KRB5_KU_AP_REQ_AUTH_CKSUM
,
307 authenticator
->cksum
);
308 krb5_crypto_destroy(context
, crypto
);
310 krb5_free_authenticator(context
, &authenticator
);
311 krb5_free_keyblock(context
, key
);
316 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
317 krb5_verify_ap_req(krb5_context context
,
318 krb5_auth_context
*auth_context
,
320 krb5_const_principal server
,
321 krb5_keyblock
*keyblock
,
323 krb5_flags
*ap_req_options
,
324 krb5_ticket
**ticket
)
326 return krb5_verify_ap_req2 (context
,
334 KRB5_KU_AP_REQ_AUTH
);
337 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
338 krb5_verify_ap_req2(krb5_context context
,
339 krb5_auth_context
*auth_context
,
341 krb5_const_principal server
,
342 krb5_keyblock
*keyblock
,
344 krb5_flags
*ap_req_options
,
345 krb5_ticket
**ticket
,
346 krb5_key_usage usage
)
349 krb5_auth_context ac
;
356 if (auth_context
&& *auth_context
) {
359 ret
= krb5_auth_con_init (context
, &ac
);
364 t
= calloc(1, sizeof(*t
));
367 krb5_clear_error_message (context
);
371 if (ap_req
->ap_options
.use_session_key
&& ac
->keyblock
){
372 ret
= krb5_decrypt_ticket(context
, &ap_req
->ticket
,
376 krb5_free_keyblock(context
, ac
->keyblock
);
379 ret
= krb5_decrypt_ticket(context
, &ap_req
->ticket
,
387 ret
= _krb5_principalname2krb5_principal(context
,
389 ap_req
->ticket
.sname
,
390 ap_req
->ticket
.realm
);
392 ret
= _krb5_principalname2krb5_principal(context
,
398 ret
= decrypt_authenticator (context
,
400 &ap_req
->authenticator
,
407 krb5_principal p1
, p2
;
410 _krb5_principalname2krb5_principal(context
,
412 ac
->authenticator
->cname
,
413 ac
->authenticator
->crealm
);
414 _krb5_principalname2krb5_principal(context
,
418 res
= krb5_principal_compare (context
, p1
, p2
);
419 krb5_free_principal (context
, p1
);
420 krb5_free_principal (context
, p2
);
422 ret
= KRB5KRB_AP_ERR_BADMATCH
;
423 krb5_clear_error_message (context
);
428 /* check addresses */
431 && ac
->remote_address
432 && !krb5_address_search (context
,
435 ret
= KRB5KRB_AP_ERR_BADADDR
;
436 krb5_clear_error_message (context
);
440 /* check timestamp in authenticator */
444 krb5_timeofday (context
, &now
);
446 if (abs(ac
->authenticator
->ctime
- now
) > context
->max_skew
) {
447 ret
= KRB5KRB_AP_ERR_SKEW
;
448 krb5_clear_error_message (context
);
453 if (ac
->authenticator
->seq_number
)
454 krb5_auth_con_setremoteseqnumber(context
, ac
,
455 *ac
->authenticator
->seq_number
);
457 /* XXX - Xor sequence numbers */
459 if (ac
->authenticator
->subkey
) {
460 ret
= krb5_auth_con_setremotesubkey(context
, ac
,
461 ac
->authenticator
->subkey
);
466 ret
= find_etypelist(context
, ac
, &etypes
);
470 ac
->keytype
= ETYPE_NULL
;
475 for (i
= 0; i
< etypes
.len
; i
++) {
476 if (krb5_enctype_valid(context
, etypes
.val
[i
]) == 0) {
477 ac
->keytype
= etypes
.val
[i
];
484 ret
= krb5_copy_keyblock(context
, &t
->ticket
.key
, &ac
->keyblock
);
487 if (ap_req_options
) {
489 if (ac
->keytype
!= ETYPE_NULL
)
490 *ap_req_options
|= AP_OPTS_USE_SUBKEY
;
491 if (ap_req
->ap_options
.use_session_key
)
492 *ap_req_options
|= AP_OPTS_USE_SESSION_KEY
;
493 if (ap_req
->ap_options
.mutual_required
)
494 *ap_req_options
|= AP_OPTS_MUTUAL_REQUIRED
;
500 krb5_free_ticket (context
, t
);
502 if (*auth_context
== NULL
)
505 krb5_auth_con_free (context
, ac
);
506 free_EtypeList(&etypes
);
510 krb5_free_ticket (context
, t
);
511 if (auth_context
== NULL
|| *auth_context
== NULL
)
512 krb5_auth_con_free (context
, ac
);
520 struct krb5_rd_req_in_ctx_data
{
522 krb5_keyblock
*keyblock
;
523 krb5_boolean check_pac
;
526 struct krb5_rd_req_out_ctx_data
{
527 krb5_keyblock
*keyblock
;
528 krb5_flags ap_req_options
;
530 krb5_principal server
;
534 * Allocate a krb5_rd_req_in_ctx as an input parameter to
535 * krb5_rd_req_ctx(). The caller should free the context with
536 * krb5_rd_req_in_ctx_free() when done with the context.
538 * @param context Keberos 5 context.
539 * @param ctx in ctx to krb5_rd_req_ctx().
541 * @return Kerberos 5 error code, see krb5_get_error_message().
546 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
547 krb5_rd_req_in_ctx_alloc(krb5_context context
, krb5_rd_req_in_ctx
*ctx
)
549 *ctx
= calloc(1, sizeof(**ctx
));
551 krb5_set_error_message(context
, ENOMEM
,
552 N_("malloc: out of memory", ""));
555 (*ctx
)->check_pac
= (context
->flags
& KRB5_CTX_F_CHECK_PAC
) ? 1 : 0;
560 * Set the keytab that krb5_rd_req_ctx() will use.
562 * @param context Keberos 5 context.
563 * @param in in ctx to krb5_rd_req_ctx().
564 * @param keytab keytab that krb5_rd_req_ctx() will use, only copy the
565 * pointer, so the caller must free they keytab after
566 * krb5_rd_req_in_ctx_free() is called.
568 * @return Kerberos 5 error code, see krb5_get_error_message().
573 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
574 krb5_rd_req_in_set_keytab(krb5_context context
,
575 krb5_rd_req_in_ctx in
,
583 * Set if krb5_rq_red() is going to check the Windows PAC or not
585 * @param context Keberos 5 context.
586 * @param in krb5_rd_req_in_ctx to check the option on.
587 * @param flag flag to select if to check the pac (TRUE) or not (FALSE).
589 * @return Kerberos 5 error code, see krb5_get_error_message().
594 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
595 krb5_rd_req_in_set_pac_check(krb5_context context
,
596 krb5_rd_req_in_ctx in
,
599 in
->check_pac
= flag
;
604 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
605 krb5_rd_req_in_set_keyblock(krb5_context context
,
606 krb5_rd_req_in_ctx in
,
607 krb5_keyblock
*keyblock
)
609 in
->keyblock
= keyblock
; /* XXX should make copy */
613 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
614 krb5_rd_req_out_get_ap_req_options(krb5_context context
,
615 krb5_rd_req_out_ctx out
,
616 krb5_flags
*ap_req_options
)
618 *ap_req_options
= out
->ap_req_options
;
622 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
623 krb5_rd_req_out_get_ticket(krb5_context context
,
624 krb5_rd_req_out_ctx out
,
625 krb5_ticket
**ticket
)
627 return krb5_copy_ticket(context
, out
->ticket
, ticket
);
630 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
631 krb5_rd_req_out_get_keyblock(krb5_context context
,
632 krb5_rd_req_out_ctx out
,
633 krb5_keyblock
**keyblock
)
635 return krb5_copy_keyblock(context
, out
->keyblock
, keyblock
);
639 * Get the principal that was used in the request from the
640 * client. Might not match whats in the ticket if krb5_rd_req_ctx()
641 * searched in the keytab for a matching key.
643 * @param context a Kerberos 5 context.
644 * @param out a krb5_rd_req_out_ctx from krb5_rd_req_ctx().
645 * @param principal return principal, free with krb5_free_principal().
650 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
651 krb5_rd_req_out_get_server(krb5_context context
,
652 krb5_rd_req_out_ctx out
,
653 krb5_principal
*principal
)
655 return krb5_copy_principal(context
, out
->server
, principal
);
658 KRB5_LIB_FUNCTION
void KRB5_LIB_CALL
659 krb5_rd_req_in_ctx_free(krb5_context context
, krb5_rd_req_in_ctx ctx
)
665 * Free the krb5_rd_req_out_ctx.
667 * @param context Keberos 5 context.
668 * @param ctx krb5_rd_req_out_ctx context to free.
673 KRB5_LIB_FUNCTION
void KRB5_LIB_CALL
674 krb5_rd_req_out_ctx_free(krb5_context context
, krb5_rd_req_out_ctx ctx
)
677 krb5_free_ticket(context
, ctx
->ticket
);
679 krb5_free_keyblock(context
, ctx
->keyblock
);
681 krb5_free_principal(context
, ctx
->server
);
689 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
690 krb5_rd_req(krb5_context context
,
691 krb5_auth_context
*auth_context
,
692 const krb5_data
*inbuf
,
693 krb5_const_principal server
,
695 krb5_flags
*ap_req_options
,
696 krb5_ticket
**ticket
)
699 krb5_rd_req_in_ctx in
;
700 krb5_rd_req_out_ctx out
;
702 ret
= krb5_rd_req_in_ctx_alloc(context
, &in
);
706 ret
= krb5_rd_req_in_set_keytab(context
, in
, keytab
);
708 krb5_rd_req_in_ctx_free(context
, in
);
712 ret
= krb5_rd_req_ctx(context
, auth_context
, inbuf
, server
, in
, &out
);
713 krb5_rd_req_in_ctx_free(context
, in
);
718 *ap_req_options
= out
->ap_req_options
;
720 ret
= krb5_copy_ticket(context
, out
->ticket
, ticket
);
726 krb5_rd_req_out_ctx_free(context
, out
);
734 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
735 krb5_rd_req_with_keyblock(krb5_context context
,
736 krb5_auth_context
*auth_context
,
737 const krb5_data
*inbuf
,
738 krb5_const_principal server
,
739 krb5_keyblock
*keyblock
,
740 krb5_flags
*ap_req_options
,
741 krb5_ticket
**ticket
)
744 krb5_rd_req_in_ctx in
;
745 krb5_rd_req_out_ctx out
;
747 ret
= krb5_rd_req_in_ctx_alloc(context
, &in
);
751 ret
= krb5_rd_req_in_set_keyblock(context
, in
, keyblock
);
753 krb5_rd_req_in_ctx_free(context
, in
);
757 ret
= krb5_rd_req_ctx(context
, auth_context
, inbuf
, server
, in
, &out
);
758 krb5_rd_req_in_ctx_free(context
, in
);
763 *ap_req_options
= out
->ap_req_options
;
765 ret
= krb5_copy_ticket(context
, out
->ticket
, ticket
);
771 krb5_rd_req_out_ctx_free(context
, out
);
779 static krb5_error_code
780 get_key_from_keytab(krb5_context context
,
782 krb5_const_principal server
,
784 krb5_keyblock
**out_key
)
786 krb5_keytab_entry entry
;
789 krb5_keytab real_keytab
;
792 krb5_kt_default(context
, &real_keytab
);
794 real_keytab
= keytab
;
796 if (ap_req
->ticket
.enc_part
.kvno
)
797 kvno
= *ap_req
->ticket
.enc_part
.kvno
;
801 ret
= krb5_kt_get_entry (context
,
805 ap_req
->ticket
.enc_part
.etype
,
809 ret
= krb5_copy_keyblock(context
, &entry
.keyblock
, out_key
);
810 krb5_kt_free_entry (context
, &entry
);
813 krb5_kt_close(context
, real_keytab
);
819 * The core server function that verify application authentication
820 * requests from clients.
822 * @param context Keberos 5 context.
823 * @param auth_context the authentication context, can be NULL, then
824 * default values for the authentication context will used.
825 * @param inbuf the (AP-REQ) authentication buffer
827 * @param server the server with authenticate as, if NULL the function
828 * will try to find any available credential in the keytab
829 * that will verify the reply. The function will prefer the
830 * server the server client specified in the AP-REQ, but if
831 * there is no mach, it will try all keytab entries for a
832 * match. This have serious performance issues for larger keytabs.
834 * @param inctx control the behavior of the function, if NULL, the
835 * default behavior is used.
836 * @param outctx the return outctx, free with krb5_rd_req_out_ctx_free().
837 * @return Kerberos 5 error code, see krb5_get_error_message().
842 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
843 krb5_rd_req_ctx(krb5_context context
,
844 krb5_auth_context
*auth_context
,
845 const krb5_data
*inbuf
,
846 krb5_const_principal server
,
847 krb5_rd_req_in_ctx inctx
,
848 krb5_rd_req_out_ctx
*outctx
)
852 krb5_rd_req_out_ctx o
= NULL
;
853 krb5_keytab id
= NULL
, keytab
= NULL
;
854 krb5_principal service
= NULL
;
858 o
= calloc(1, sizeof(*o
));
860 krb5_set_error_message(context
, ENOMEM
,
861 N_("malloc: out of memory", ""));
865 if (*auth_context
== NULL
) {
866 ret
= krb5_auth_con_init(context
, auth_context
);
871 ret
= krb5_decode_ap_req(context
, inbuf
, &ap_req
);
875 /* Save that principal that was in the request */
876 ret
= _krb5_principalname2krb5_principal(context
,
879 ap_req
.ticket
.realm
);
883 if (ap_req
.ap_options
.use_session_key
&&
884 (*auth_context
)->keyblock
== NULL
) {
885 ret
= KRB5KRB_AP_ERR_NOKEY
;
886 krb5_set_error_message(context
, ret
,
887 N_("krb5_rd_req: user to user auth "
888 "without session key given", ""));
892 if (inctx
&& inctx
->keytab
)
895 if((*auth_context
)->keyblock
){
896 ret
= krb5_copy_keyblock(context
,
897 (*auth_context
)->keyblock
,
901 } else if(inctx
&& inctx
->keyblock
){
902 ret
= krb5_copy_keyblock(context
,
910 krb5_kt_default(context
, &keytab
);
916 if (server
== NULL
) {
917 ret
= _krb5_principalname2krb5_principal(context
,
920 ap_req
.ticket
.realm
);
926 ret
= get_key_from_keytab(context
,
932 /* If caller specified a server, fail. */
933 if (service
== NULL
&& (context
->flags
& KRB5_CTX_F_RD_REQ_IGNORE
) == 0)
935 /* Otherwise, fall back to iterating over the keytab. This
936 * have serious performace issues for larger keytab.
944 * We got an exact keymatch, use that.
947 ret
= krb5_verify_ap_req2(context
,
955 KRB5_KU_AP_REQ_AUTH
);
962 * Interate over keytab to find a key that can decrypt the request.
965 krb5_keytab_entry entry
;
966 krb5_kt_cursor cursor
;
967 int done
= 0, kvno
= 0;
969 memset(&cursor
, 0, sizeof(cursor
));
971 if (ap_req
.ticket
.enc_part
.kvno
)
972 kvno
= *ap_req
.ticket
.enc_part
.kvno
;
974 ret
= krb5_kt_start_seq_get(context
, id
, &cursor
);
982 ret
= krb5_kt_next_entry(context
, id
, &entry
, &cursor
);
984 _krb5_kt_principal_not_found(context
, ret
, id
, o
->server
,
985 ap_req
.ticket
.enc_part
.etype
,
990 if (entry
.keyblock
.keytype
!= ap_req
.ticket
.enc_part
.etype
) {
991 krb5_kt_free_entry (context
, &entry
);
995 ret
= krb5_verify_ap_req2(context
,
1003 KRB5_KU_AP_REQ_AUTH
);
1005 krb5_kt_free_entry (context
, &entry
);
1010 * Found a match, save the keyblock for PAC processing,
1011 * and update the service principal in the ticket to match
1012 * whatever is in the keytab.
1015 ret
= krb5_copy_keyblock(context
,
1019 krb5_kt_free_entry (context
, &entry
);
1023 ret
= krb5_copy_principal(context
, entry
.principal
, &p
);
1025 krb5_kt_free_entry (context
, &entry
);
1028 krb5_free_principal(context
, o
->ticket
->server
);
1029 o
->ticket
->server
= p
;
1031 krb5_kt_free_entry (context
, &entry
);
1035 krb5_kt_end_seq_get (context
, id
, &cursor
);
1038 /* If there is a PAC, verify its server signature */
1039 if (inctx
== NULL
|| inctx
->check_pac
) {
1043 ret
= krb5_ticket_get_authorization_data_type(context
,
1045 KRB5_AUTHDATA_WIN2K_PAC
,
1048 ret
= krb5_pac_parse(context
, data
.data
, data
.length
, &pac
);
1049 krb5_data_free(&data
);
1053 ret
= krb5_pac_verify(context
,
1055 o
->ticket
->ticket
.authtime
,
1059 krb5_pac_free(context
, pac
);
1067 if (ret
|| outctx
== NULL
) {
1068 krb5_rd_req_out_ctx_free(context
, o
);
1072 free_AP_REQ(&ap_req
);
1075 krb5_free_principal(context
, service
);
1078 krb5_kt_close(context
, keytab
);