2 * Copyright (c) 1997 - 2008 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #include "gsskrb5_locl.h"
37 * copy the addresses from `input_chan_bindings' (if any) to
38 * the auth context `ac'
42 set_addresses (krb5_context context
,
44 const gss_channel_bindings_t input_chan_bindings
)
46 /* Port numbers are expected to be in application_data.value,
47 * initator's port first */
49 krb5_address initiator_addr
, acceptor_addr
;
52 if (input_chan_bindings
== GSS_C_NO_CHANNEL_BINDINGS
53 || input_chan_bindings
->application_data
.length
!=
54 2 * sizeof(ac
->local_port
))
57 memset(&initiator_addr
, 0, sizeof(initiator_addr
));
58 memset(&acceptor_addr
, 0, sizeof(acceptor_addr
));
61 *(int16_t *) input_chan_bindings
->application_data
.value
;
64 *((int16_t *) input_chan_bindings
->application_data
.value
+ 1);
66 kret
= _gsskrb5i_address_to_krb5addr(context
,
67 input_chan_bindings
->acceptor_addrtype
,
68 &input_chan_bindings
->acceptor_address
,
74 kret
= _gsskrb5i_address_to_krb5addr(context
,
75 input_chan_bindings
->initiator_addrtype
,
76 &input_chan_bindings
->initiator_address
,
80 krb5_free_address (context
, &acceptor_addr
);
84 kret
= krb5_auth_con_setaddrs(context
,
86 &initiator_addr
, /* local address */
87 &acceptor_addr
); /* remote address */
89 krb5_free_address (context
, &initiator_addr
);
90 krb5_free_address (context
, &acceptor_addr
);
93 free(input_chan_bindings
->application_data
.value
);
94 input_chan_bindings
->application_data
.value
= NULL
;
95 input_chan_bindings
->application_data
.length
= 0;
103 OM_uint32
* minor_status
,
104 gss_ctx_id_t
* context_handle
,
105 krb5_context context
,
106 const gss_channel_bindings_t input_chan_bindings
,
107 enum gss_ctx_id_t_state state
)
109 krb5_error_code kret
;
112 *context_handle
= NULL
;
114 ctx
= malloc(sizeof(*ctx
));
116 *minor_status
= ENOMEM
;
117 return GSS_S_FAILURE
;
119 ctx
->auth_context
= NULL
;
120 ctx
->deleg_auth_context
= NULL
;
128 ctx
->service_keyblock
= NULL
;
130 krb5_data_zero(&ctx
->fwd_data
);
134 HEIMDAL_MUTEX_init(&ctx
->ctx_id_mutex
);
136 kret
= krb5_auth_con_init (context
, &ctx
->auth_context
);
138 *minor_status
= kret
;
139 HEIMDAL_MUTEX_destroy(&ctx
->ctx_id_mutex
);
141 return GSS_S_FAILURE
;
144 kret
= krb5_auth_con_init (context
, &ctx
->deleg_auth_context
);
146 *minor_status
= kret
;
147 krb5_auth_con_free(context
, ctx
->auth_context
);
148 HEIMDAL_MUTEX_destroy(&ctx
->ctx_id_mutex
);
150 return GSS_S_FAILURE
;
153 kret
= set_addresses(context
, ctx
->auth_context
, input_chan_bindings
);
155 *minor_status
= kret
;
157 krb5_auth_con_free(context
, ctx
->auth_context
);
158 krb5_auth_con_free(context
, ctx
->deleg_auth_context
);
160 HEIMDAL_MUTEX_destroy(&ctx
->ctx_id_mutex
);
162 return GSS_S_BAD_BINDINGS
;
165 kret
= set_addresses(context
, ctx
->deleg_auth_context
, input_chan_bindings
);
167 *minor_status
= kret
;
169 krb5_auth_con_free(context
, ctx
->auth_context
);
170 krb5_auth_con_free(context
, ctx
->deleg_auth_context
);
172 HEIMDAL_MUTEX_destroy(&ctx
->ctx_id_mutex
);
174 return GSS_S_BAD_BINDINGS
;
178 * We need a sequence number
181 krb5_auth_con_addflags(context
,
183 KRB5_AUTH_CONTEXT_DO_SEQUENCE
|
184 KRB5_AUTH_CONTEXT_CLEAR_FORWARDED_CRED
,
188 * We need a sequence number
191 krb5_auth_con_addflags(context
,
192 ctx
->deleg_auth_context
,
193 KRB5_AUTH_CONTEXT_DO_SEQUENCE
|
194 KRB5_AUTH_CONTEXT_CLEAR_FORWARDED_CRED
,
197 *context_handle
= (gss_ctx_id_t
)ctx
;
199 return GSS_S_COMPLETE
;
205 OM_uint32
* minor_status
,
206 krb5_context context
,
209 gss_const_name_t target_name
,
211 OM_uint32
* time_rec
)
214 krb5_error_code kret
;
215 krb5_creds this_cred
;
216 OM_uint32 lifetime_rec
;
219 krb5_free_principal(context
, ctx
->target
);
223 krb5_free_creds(context
, ctx
->kcred
);
227 ret
= _gsskrb5_canon_name(minor_status
, context
, target_name
,
232 memset(&this_cred
, 0, sizeof(this_cred
));
233 this_cred
.client
= ctx
->source
;
234 this_cred
.server
= ctx
->target
;
236 if (time_req
&& time_req
!= GSS_C_INDEFINITE
) {
239 krb5_timeofday (context
, &ts
);
240 this_cred
.times
.endtime
= ts
+ time_req
;
242 this_cred
.times
.endtime
= 0;
245 this_cred
.session
.keytype
= KEYTYPE_NULL
;
247 kret
= krb5_get_credentials(context
,
253 *minor_status
= kret
;
254 return GSS_S_FAILURE
;
257 ctx
->endtime
= ctx
->kcred
->times
.endtime
;
259 ret
= _gsskrb5_lifetime_left(minor_status
, context
,
260 ctx
->endtime
, &lifetime_rec
);
263 if (lifetime_rec
== 0) {
265 return GSS_S_CONTEXT_EXPIRED
;
268 if (time_rec
) *time_rec
= lifetime_rec
;
270 return GSS_S_COMPLETE
;
274 gsskrb5_initiator_ready(
275 OM_uint32
* minor_status
,
277 krb5_context context
)
282 OM_uint32 flags
= ctx
->flags
;
284 krb5_free_creds(context
, ctx
->kcred
);
287 if (ctx
->more_flags
& CLOSE_CCACHE
)
288 krb5_cc_close(context
, ctx
->ccache
);
291 krb5_auth_con_getremoteseqnumber (context
, ctx
->auth_context
, &seq_number
);
293 _gsskrb5i_is_cfx(context
, ctx
, 0);
294 is_cfx
= (ctx
->more_flags
& IS_CFX
);
296 ret
= _gssapi_msg_order_create(minor_status
,
298 _gssapi_msg_order_f(flags
),
299 seq_number
, 0, is_cfx
);
302 ctx
->state
= INITIATOR_READY
;
303 ctx
->more_flags
|= OPEN
;
305 return GSS_S_COMPLETE
;
309 * handle delegated creds in init-sec-context
313 do_delegation (krb5_context context
,
314 krb5_auth_context ac
,
317 krb5_const_principal name
,
323 KDCOptions fwd_flags
;
324 krb5_error_code kret
;
326 memset (&creds
, 0, sizeof(creds
));
327 krb5_data_zero (fwd_data
);
329 kret
= krb5_cc_get_principal(context
, ccache
, &creds
.client
);
333 kret
= krb5_make_principal(context
,
342 creds
.times
.endtime
= 0;
344 memset(&fwd_flags
, 0, sizeof(fwd_flags
));
345 fwd_flags
.forwarded
= 1;
346 fwd_flags
.forwardable
= 1;
348 if ( /*target_name->name.name_type != KRB5_NT_SRV_HST ||*/
349 name
->name
.name_string
.len
< 2)
352 kret
= krb5_get_forwarded_creds(context
,
355 KDCOptions2int(fwd_flags
),
356 name
->name
.name_string
.val
[1],
367 krb5_free_principal(context
, creds
.client
);
369 krb5_free_principal(context
, creds
.server
);
373 * first stage of init-sec-context
378 (OM_uint32
* minor_status
,
381 krb5_context context
,
382 gss_const_name_t name
,
383 const gss_OID mech_type
,
386 const gss_buffer_t input_token
,
387 gss_OID
* actual_mech_type
,
388 gss_buffer_t output_token
,
389 OM_uint32
* ret_flags
,
393 OM_uint32 ret
= GSS_S_FAILURE
;
394 krb5_error_code kret
;
396 OM_uint32 lifetime_rec
;
398 krb5_data_zero(&fwd_data
);
402 if (actual_mech_type
)
403 *actual_mech_type
= GSS_KRB5_MECHANISM
;
406 kret
= krb5_cc_default (context
, &ctx
->ccache
);
408 *minor_status
= kret
;
412 ctx
->more_flags
|= CLOSE_CCACHE
;
414 ctx
->ccache
= cred
->ccache
;
416 kret
= krb5_cc_get_principal (context
, ctx
->ccache
, &ctx
->source
);
418 *minor_status
= kret
;
424 * This is hideous glue for (NFS) clients that wants to limit the
425 * available enctypes to what it can support (encryption in
428 if (cred
&& cred
->enctypes
)
429 krb5_set_default_in_tkt_etypes(context
, cred
->enctypes
);
431 ret
= gsskrb5_get_creds(minor_status
, context
, ctx
->ccache
,
432 ctx
, name
, time_req
, time_rec
);
436 ctx
->endtime
= ctx
->kcred
->times
.endtime
;
438 ret
= _gss_DES3_get_mic_compat(minor_status
, ctx
, context
);
442 ret
= _gsskrb5_lifetime_left(minor_status
,
449 if (lifetime_rec
== 0) {
451 ret
= GSS_S_CONTEXT_EXPIRED
;
455 krb5_auth_con_setkey(context
,
457 &ctx
->kcred
->session
);
459 kret
= krb5_auth_con_generatelocalsubkey(context
,
461 &ctx
->kcred
->session
);
463 *minor_status
= kret
;
468 return GSS_S_COMPLETE
;
471 if (ctx
->ccache
&& (ctx
->more_flags
& CLOSE_CCACHE
))
472 krb5_cc_close(context
, ctx
->ccache
);
481 (OM_uint32
* minor_status
,
484 krb5_context context
,
486 const gss_channel_bindings_t input_chan_bindings
,
487 const gss_buffer_t input_token
,
488 gss_OID
* actual_mech_type
,
489 gss_buffer_t output_token
,
490 OM_uint32
* ret_flags
,
494 OM_uint32 ret
= GSS_S_FAILURE
;
495 krb5_error_code kret
;
496 krb5_flags ap_options
;
499 krb5_data authenticator
;
501 krb5_enctype enctype
;
502 krb5_data fwd_data
, timedata
;
503 int32_t offset
= 0, oldoffset
= 0;
506 krb5_data_zero(&outbuf
);
507 krb5_data_zero(&fwd_data
);
512 * If the credential doesn't have ok-as-delegate, check if there
513 * is a realm setting and use that.
515 if (!ctx
->kcred
->flags
.b
.ok_as_delegate
) {
518 ret
= krb5_cc_get_config(context
, ctx
->ccache
, NULL
,
519 "realm-config", &data
);
521 /* XXX 1 is use ok-as-delegate */
522 if (data
.length
< 1 || ((((unsigned char *)data
.data
)[0]) & 1) == 0)
523 req_flags
&= ~(GSS_C_DELEG_FLAG
|GSS_C_DELEG_POLICY_FLAG
);
524 krb5_data_free(&data
);
530 /* if we used GSS_C_DELEG_POLICY_FLAG, trust KDC */
531 if ((req_flags
& GSS_C_DELEG_POLICY_FLAG
)
532 && ctx
->kcred
->flags
.b
.ok_as_delegate
)
533 flagmask
|= GSS_C_DELEG_FLAG
| GSS_C_DELEG_POLICY_FLAG
;
534 /* if there still is a GSS_C_DELEG_FLAG, use that */
535 if (req_flags
& GSS_C_DELEG_FLAG
)
536 flagmask
|= GSS_C_DELEG_FLAG
;
541 if (flagmask
& GSS_C_DELEG_FLAG
) {
542 do_delegation (context
,
543 ctx
->deleg_auth_context
,
544 ctx
->ccache
, ctx
->kcred
, ctx
->target
,
545 &fwd_data
, flagmask
, &flags
);
548 if (req_flags
& GSS_C_MUTUAL_FLAG
) {
549 flags
|= GSS_C_MUTUAL_FLAG
;
550 ap_options
|= AP_OPTS_MUTUAL_REQUIRED
;
553 if (req_flags
& GSS_C_REPLAY_FLAG
)
554 flags
|= GSS_C_REPLAY_FLAG
;
555 if (req_flags
& GSS_C_SEQUENCE_FLAG
)
556 flags
|= GSS_C_SEQUENCE_FLAG
;
558 if (req_flags
& GSS_C_ANON_FLAG
)
561 if (req_flags
& GSS_C_DCE_STYLE
) {
562 /* GSS_C_DCE_STYLE implies GSS_C_MUTUAL_FLAG */
563 flags
|= GSS_C_DCE_STYLE
| GSS_C_MUTUAL_FLAG
;
564 ap_options
|= AP_OPTS_MUTUAL_REQUIRED
;
566 if (req_flags
& GSS_C_IDENTIFY_FLAG
)
567 flags
|= GSS_C_IDENTIFY_FLAG
;
568 if (req_flags
& GSS_C_EXTENDED_ERROR_FLAG
)
569 flags
|= GSS_C_EXTENDED_ERROR_FLAG
;
571 if (req_flags
& GSS_C_CONF_FLAG
) {
572 flags
|= GSS_C_CONF_FLAG
;
574 if (req_flags
& GSS_C_INTEG_FLAG
) {
575 flags
|= GSS_C_INTEG_FLAG
;
577 if (cred
== NULL
|| !(cred
->cred_flags
& GSS_CF_NO_CI_FLAGS
)) {
578 flags
|= GSS_C_CONF_FLAG
;
579 flags
|= GSS_C_INTEG_FLAG
;
581 flags
|= GSS_C_TRANS_FLAG
;
586 ctx
->more_flags
|= LOCAL
;
588 ret
= _gsskrb5_create_8003_checksum (minor_status
,
593 krb5_data_free (&fwd_data
);
597 enctype
= ctx
->auth_context
->keyblock
->keytype
;
599 ret
= krb5_cc_get_config(context
, ctx
->ccache
, ctx
->target
,
600 "time-offset", &timedata
);
602 if (timedata
.length
== 4) {
603 const u_char
*p
= timedata
.data
;
604 offset
= (p
[0] <<24) | (p
[1] << 16) | (p
[2] << 8) | (p
[3] << 0);
606 krb5_data_free(&timedata
);
610 krb5_get_kdc_sec_offset (context
, &oldoffset
, NULL
);
611 krb5_set_kdc_sec_offset (context
, offset
, -1);
614 kret
= _krb5_build_authenticator(context
,
620 KRB5_KU_AP_REQ_AUTH
);
624 krb5_set_kdc_sec_offset (context
, oldoffset
, -1);
625 *minor_status
= kret
;
630 kret
= krb5_build_ap_req (context
,
637 krb5_set_kdc_sec_offset (context
, oldoffset
, -1);
639 *minor_status
= kret
;
644 if (flags
& GSS_C_DCE_STYLE
) {
645 output_token
->value
= outbuf
.data
;
646 output_token
->length
= outbuf
.length
;
648 ret
= _gsskrb5_encapsulate (minor_status
, &outbuf
, output_token
,
649 (u_char
*)(intptr_t)"\x01\x00",
651 krb5_data_free (&outbuf
);
656 free_Checksum(&cksum
);
658 if (flags
& GSS_C_MUTUAL_FLAG
) {
659 ctx
->state
= INITIATOR_WAIT_FOR_MUTAL
;
660 return GSS_S_CONTINUE_NEEDED
;
663 return gsskrb5_initiator_ready(minor_status
, ctx
, context
);
665 if (ctx
->ccache
&& (ctx
->more_flags
& CLOSE_CCACHE
))
666 krb5_cc_close(context
, ctx
->ccache
);
672 static krb5_error_code
673 handle_error_packet(krb5_context context
,
677 krb5_error_code kret
;
680 kret
= krb5_rd_error(context
, &indata
, &error
);
682 kret
= krb5_error_from_rd_error(context
, &error
, NULL
);
684 /* save the time skrew for this host */
685 if (kret
== KRB5KRB_AP_ERR_SKEW
) {
688 int32_t t
= error
.stime
- time(NULL
);
690 p
[0] = (t
>> 24) & 0xFF;
691 p
[1] = (t
>> 16) & 0xFF;
692 p
[2] = (t
>> 8) & 0xFF;
693 p
[3] = (t
>> 0) & 0xFF;
696 timedata
.length
= sizeof(p
);
698 krb5_cc_set_config(context
, ctx
->ccache
, ctx
->target
,
699 "time-offset", &timedata
);
701 if ((ctx
->more_flags
& RETRIED
) == 0)
702 ctx
->state
= INITIATOR_RESTART
;
703 ctx
->more_flags
|= RETRIED
;
705 free_KRB_ERROR (&error
);
713 (OM_uint32
* minor_status
,
715 krb5_context context
,
716 const gss_OID mech_type
,
719 const gss_channel_bindings_t input_chan_bindings
,
720 const gss_buffer_t input_token
,
721 gss_OID
* actual_mech_type
,
722 gss_buffer_t output_token
,
723 OM_uint32
* ret_flags
,
728 krb5_error_code kret
;
730 krb5_ap_rep_enc_part
*repl
;
732 output_token
->length
= 0;
733 output_token
->value
= NULL
;
735 if (actual_mech_type
)
736 *actual_mech_type
= GSS_KRB5_MECHANISM
;
738 if (IS_DCE_STYLE(ctx
)) {
739 /* There is no OID wrapping. */
740 indata
.length
= input_token
->length
;
741 indata
.data
= input_token
->value
;
742 kret
= krb5_rd_rep(context
,
747 ret
= _gsskrb5_decapsulate(minor_status
,
752 if (ret
== GSS_S_COMPLETE
) {
753 *minor_status
= handle_error_packet(context
, ctx
, indata
);
755 *minor_status
= kret
;
757 return GSS_S_FAILURE
;
760 ret
= _gsskrb5_decapsulate (minor_status
,
765 if (ret
== GSS_S_DEFECTIVE_TOKEN
) {
766 /* check if there is an error token sent instead */
767 ret
= _gsskrb5_decapsulate (minor_status
,
772 if (ret
== GSS_S_COMPLETE
) {
773 *minor_status
= handle_error_packet(context
, ctx
, indata
);
774 return GSS_S_FAILURE
;
777 kret
= krb5_rd_rep (context
,
782 *minor_status
= kret
;
783 return GSS_S_FAILURE
;
787 krb5_free_ap_rep_enc_part (context
,
792 ret
= _gsskrb5_lifetime_left(minor_status
,
797 ret
= GSS_S_COMPLETE
;
800 *ret_flags
= ctx
->flags
;
802 if (req_flags
& GSS_C_DCE_STYLE
) {
803 int32_t local_seq
, remote_seq
;
807 * So DCE_STYLE is strange. The client echos the seq number
808 * that the server used in the server's mk_rep in its own
809 * mk_rep(). After when done, it resets to it's own seq number
810 * for the gss_wrap calls.
813 krb5_auth_con_getremoteseqnumber(context
, ctx
->auth_context
, &remote_seq
);
814 krb5_auth_con_getlocalseqnumber(context
, ctx
->auth_context
, &local_seq
);
815 krb5_auth_con_setlocalseqnumber(context
, ctx
->auth_context
, remote_seq
);
817 kret
= krb5_mk_rep(context
, ctx
->auth_context
, &outbuf
);
819 *minor_status
= kret
;
820 return GSS_S_FAILURE
;
823 /* reset local seq number */
824 krb5_auth_con_setlocalseqnumber(context
, ctx
->auth_context
, local_seq
);
826 output_token
->length
= outbuf
.length
;
827 output_token
->value
= outbuf
.data
;
830 return gsskrb5_initiator_ready(minor_status
, ctx
, context
);
834 * gss_init_sec_context
837 OM_uint32 GSSAPI_CALLCONV _gsskrb5_init_sec_context
838 (OM_uint32
* minor_status
,
839 gss_const_cred_id_t cred_handle
,
840 gss_ctx_id_t
* context_handle
,
841 gss_const_name_t target_name
,
842 const gss_OID mech_type
,
845 const gss_channel_bindings_t input_chan_bindings
,
846 const gss_buffer_t input_token
,
847 gss_OID
* actual_mech_type
,
848 gss_buffer_t output_token
,
849 OM_uint32
* ret_flags
,
853 krb5_context context
;
854 gsskrb5_cred cred
= (gsskrb5_cred
)cred_handle
;
858 GSSAPI_KRB5_INIT (&context
);
860 output_token
->length
= 0;
861 output_token
->value
= NULL
;
863 if (context_handle
== NULL
) {
865 return GSS_S_FAILURE
| GSS_S_CALL_BAD_STRUCTURE
;
873 if (target_name
== GSS_C_NO_NAME
) {
874 if (actual_mech_type
)
875 *actual_mech_type
= GSS_C_NO_OID
;
877 return GSS_S_BAD_NAME
;
880 if (mech_type
!= GSS_C_NO_OID
&&
881 !gss_oid_equal(mech_type
, GSS_KRB5_MECHANISM
))
882 return GSS_S_BAD_MECH
;
884 if (input_token
== GSS_C_NO_BUFFER
|| input_token
->length
== 0) {
887 if (*context_handle
!= GSS_C_NO_CONTEXT
) {
889 return GSS_S_FAILURE
| GSS_S_CALL_BAD_STRUCTURE
;
892 ret1
= _gsskrb5_create_ctx(minor_status
,
901 if (*context_handle
== GSS_C_NO_CONTEXT
) {
903 return GSS_S_FAILURE
| GSS_S_CALL_BAD_STRUCTURE
;
906 ctx
= (gsskrb5_ctx
) *context_handle
;
908 HEIMDAL_MUTEX_lock(&ctx
->ctx_id_mutex
);
911 switch (ctx
->state
) {
912 case INITIATOR_START
:
913 ret
= init_auth(minor_status
,
926 if (ret
!= GSS_S_COMPLETE
)
929 case INITIATOR_RESTART
:
930 ret
= init_auth_restart(minor_status
,
942 case INITIATOR_WAIT_FOR_MUTAL
:
943 ret
= repl_mutual(minor_status
,
955 if (ctx
->state
== INITIATOR_RESTART
)
958 case INITIATOR_READY
:
960 * If we get there, the caller have called
961 * gss_init_sec_context() one time too many.
963 _gsskrb5_set_status(EINVAL
, "init_sec_context "
964 "called one time too many");
965 *minor_status
= EINVAL
;
966 ret
= GSS_S_BAD_STATUS
;
969 _gsskrb5_set_status(EINVAL
, "init_sec_context "
970 "invalid state %d for client",
972 *minor_status
= EINVAL
;
973 ret
= GSS_S_BAD_STATUS
;
976 HEIMDAL_MUTEX_unlock(&ctx
->ctx_id_mutex
);
978 /* destroy context in case of error */
979 if (GSS_ERROR(ret
)) {
981 _gsskrb5_delete_sec_context(&min2
, context_handle
, GSS_C_NO_BUFFER
);