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
);
131 ctx
->lifetime
= GSS_C_INDEFINITE
;
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 const gss_name_t target_name
,
212 OM_uint32
* time_rec
)
215 krb5_error_code kret
;
216 krb5_creds this_cred
;
217 OM_uint32 lifetime_rec
;
220 krb5_free_principal(context
, ctx
->target
);
224 krb5_free_creds(context
, ctx
->kcred
);
228 ret
= _gsskrb5_canon_name(minor_status
, context
, use_dns
,
229 ctx
->source
, target_name
, &ctx
->target
);
233 memset(&this_cred
, 0, sizeof(this_cred
));
234 this_cred
.client
= ctx
->source
;
235 this_cred
.server
= ctx
->target
;
237 if (time_req
&& time_req
!= GSS_C_INDEFINITE
) {
240 krb5_timeofday (context
, &ts
);
241 this_cred
.times
.endtime
= ts
+ time_req
;
243 this_cred
.times
.endtime
= 0;
246 this_cred
.session
.keytype
= KEYTYPE_NULL
;
248 kret
= krb5_get_credentials(context
,
254 *minor_status
= kret
;
255 return GSS_S_FAILURE
;
258 ctx
->lifetime
= ctx
->kcred
->times
.endtime
;
260 ret
= _gsskrb5_lifetime_left(minor_status
, context
,
261 ctx
->lifetime
, &lifetime_rec
);
264 if (lifetime_rec
== 0) {
266 return GSS_S_CONTEXT_EXPIRED
;
269 if (time_rec
) *time_rec
= lifetime_rec
;
271 return GSS_S_COMPLETE
;
275 gsskrb5_initiator_ready(
276 OM_uint32
* minor_status
,
278 krb5_context context
)
283 OM_uint32 flags
= ctx
->flags
;
285 krb5_free_creds(context
, ctx
->kcred
);
288 if (ctx
->more_flags
& CLOSE_CCACHE
)
289 krb5_cc_close(context
, ctx
->ccache
);
292 krb5_auth_con_getremoteseqnumber (context
, ctx
->auth_context
, &seq_number
);
294 _gsskrb5i_is_cfx(context
, ctx
, 0);
295 is_cfx
= (ctx
->more_flags
& IS_CFX
);
297 ret
= _gssapi_msg_order_create(minor_status
,
299 _gssapi_msg_order_f(flags
),
300 seq_number
, 0, is_cfx
);
303 ctx
->state
= INITIATOR_READY
;
304 ctx
->more_flags
|= OPEN
;
306 return GSS_S_COMPLETE
;
310 * handle delegated creds in init-sec-context
314 do_delegation (krb5_context context
,
315 krb5_auth_context ac
,
318 krb5_const_principal name
,
324 KDCOptions fwd_flags
;
325 krb5_error_code kret
;
327 memset (&creds
, 0, sizeof(creds
));
328 krb5_data_zero (fwd_data
);
330 kret
= krb5_cc_get_principal(context
, ccache
, &creds
.client
);
334 kret
= krb5_make_principal(context
,
343 creds
.times
.endtime
= 0;
345 memset(&fwd_flags
, 0, sizeof(fwd_flags
));
346 fwd_flags
.forwarded
= 1;
347 fwd_flags
.forwardable
= 1;
349 if ( /*target_name->name.name_type != KRB5_NT_SRV_HST ||*/
350 name
->name
.name_string
.len
< 2)
353 kret
= krb5_get_forwarded_creds(context
,
356 KDCOptions2int(fwd_flags
),
357 name
->name
.name_string
.val
[1],
368 krb5_free_principal(context
, creds
.client
);
370 krb5_free_principal(context
, creds
.server
);
374 * first stage of init-sec-context
379 (OM_uint32
* minor_status
,
382 krb5_context context
,
384 const gss_OID mech_type
,
387 const gss_buffer_t input_token
,
388 gss_OID
* actual_mech_type
,
389 gss_buffer_t output_token
,
390 OM_uint32
* ret_flags
,
394 OM_uint32 ret
= GSS_S_FAILURE
;
395 krb5_error_code kret
;
398 OM_uint32 lifetime_rec
;
401 krb5_data_zero(&outbuf
);
402 krb5_data_zero(&fwd_data
);
406 if (actual_mech_type
)
407 *actual_mech_type
= GSS_KRB5_MECHANISM
;
410 kret
= krb5_cc_default (context
, &ctx
->ccache
);
412 *minor_status
= kret
;
416 ctx
->more_flags
|= CLOSE_CCACHE
;
418 ctx
->ccache
= cred
->ccache
;
420 kret
= krb5_cc_get_principal (context
, ctx
->ccache
, &ctx
->source
);
422 *minor_status
= kret
;
428 * This is hideous glue for (NFS) clients that wants to limit the
429 * available enctypes to what it can support (encryption in
430 * kernel). If there is no enctypes selected for this credential,
431 * reset it to the default set of enctypes.
434 krb5_enctype
*enctypes
= NULL
;
436 if (cred
&& cred
->enctypes
)
437 enctypes
= cred
->enctypes
;
438 krb5_set_default_in_tkt_etypes(context
, enctypes
);
441 /* canon name if needed for client + target realm */
442 kret
= krb5_cc_get_config(context
, ctx
->ccache
, NULL
,
443 "realm-config", &outbuf
);
445 /* XXX 2 is no server canon */
446 if (outbuf
.length
< 1 || ((((unsigned char *)outbuf
.data
)[0]) & 2))
448 krb5_data_free(&outbuf
);
452 * First we try w/o dns, hope that the KDC have register alias
453 * (and referrals if cross realm) for this principal. If that
454 * fails and if we are allowed to using this realm try again with
455 * DNS canonicalizion.
457 ret
= gsskrb5_get_creds(minor_status
, context
, ctx
->ccache
,
458 ctx
, name
, 0, time_req
,
460 if (ret
&& allow_dns
)
461 ret
= gsskrb5_get_creds(minor_status
, context
, ctx
->ccache
,
462 ctx
, name
, 1, time_req
,
467 ctx
->lifetime
= ctx
->kcred
->times
.endtime
;
469 ret
= _gss_DES3_get_mic_compat(minor_status
, ctx
, context
);
473 ret
= _gsskrb5_lifetime_left(minor_status
,
480 if (lifetime_rec
== 0) {
482 ret
= GSS_S_CONTEXT_EXPIRED
;
486 krb5_auth_con_setkey(context
,
488 &ctx
->kcred
->session
);
490 kret
= krb5_auth_con_generatelocalsubkey(context
,
492 &ctx
->kcred
->session
);
494 *minor_status
= kret
;
499 return GSS_S_COMPLETE
;
502 if (ctx
->ccache
&& (ctx
->more_flags
& CLOSE_CCACHE
))
503 krb5_cc_close(context
, ctx
->ccache
);
512 (OM_uint32
* minor_status
,
515 krb5_context context
,
517 const gss_channel_bindings_t input_chan_bindings
,
518 const gss_buffer_t input_token
,
519 gss_OID
* actual_mech_type
,
520 gss_buffer_t output_token
,
521 OM_uint32
* ret_flags
,
525 OM_uint32 ret
= GSS_S_FAILURE
;
526 krb5_error_code kret
;
527 krb5_flags ap_options
;
530 krb5_data authenticator
;
532 krb5_enctype enctype
;
533 krb5_data fwd_data
, timedata
;
534 int32_t offset
= 0, oldoffset
= 0;
537 krb5_data_zero(&outbuf
);
538 krb5_data_zero(&fwd_data
);
543 * If the credential doesn't have ok-as-delegate, check if there
544 * is a realm setting and use that.
546 if (!ctx
->kcred
->flags
.b
.ok_as_delegate
) {
549 ret
= krb5_cc_get_config(context
, ctx
->ccache
, NULL
,
550 "realm-config", &data
);
552 /* XXX 1 is use ok-as-delegate */
553 if (data
.length
< 1 || ((((unsigned char *)data
.data
)[0]) & 1) == 0)
554 req_flags
&= ~(GSS_C_DELEG_FLAG
|GSS_C_DELEG_POLICY_FLAG
);
555 krb5_data_free(&data
);
561 /* if we used GSS_C_DELEG_POLICY_FLAG, trust KDC */
562 if ((req_flags
& GSS_C_DELEG_POLICY_FLAG
)
563 && ctx
->kcred
->flags
.b
.ok_as_delegate
)
564 flagmask
|= GSS_C_DELEG_FLAG
| GSS_C_DELEG_POLICY_FLAG
;
565 /* if there still is a GSS_C_DELEG_FLAG, use that */
566 if (req_flags
& GSS_C_DELEG_FLAG
)
567 flagmask
|= GSS_C_DELEG_FLAG
;
572 if (flagmask
& GSS_C_DELEG_FLAG
) {
573 do_delegation (context
,
574 ctx
->deleg_auth_context
,
575 ctx
->ccache
, ctx
->kcred
, ctx
->target
,
576 &fwd_data
, flagmask
, &flags
);
579 if (req_flags
& GSS_C_MUTUAL_FLAG
) {
580 flags
|= GSS_C_MUTUAL_FLAG
;
581 ap_options
|= AP_OPTS_MUTUAL_REQUIRED
;
584 if (req_flags
& GSS_C_REPLAY_FLAG
)
585 flags
|= GSS_C_REPLAY_FLAG
;
586 if (req_flags
& GSS_C_SEQUENCE_FLAG
)
587 flags
|= GSS_C_SEQUENCE_FLAG
;
589 if (req_flags
& GSS_C_ANON_FLAG
)
592 if (req_flags
& GSS_C_DCE_STYLE
) {
593 /* GSS_C_DCE_STYLE implies GSS_C_MUTUAL_FLAG */
594 flags
|= GSS_C_DCE_STYLE
| GSS_C_MUTUAL_FLAG
;
595 ap_options
|= AP_OPTS_MUTUAL_REQUIRED
;
597 if (req_flags
& GSS_C_IDENTIFY_FLAG
)
598 flags
|= GSS_C_IDENTIFY_FLAG
;
599 if (req_flags
& GSS_C_EXTENDED_ERROR_FLAG
)
600 flags
|= GSS_C_EXTENDED_ERROR_FLAG
;
602 if (req_flags
& GSS_C_CONF_FLAG
) {
603 flags
|= GSS_C_CONF_FLAG
;
605 if (req_flags
& GSS_C_INTEG_FLAG
) {
606 flags
|= GSS_C_INTEG_FLAG
;
608 if (cred
== NULL
|| !(cred
->cred_flags
& GSS_CF_NO_CI_FLAGS
)) {
609 flags
|= GSS_C_CONF_FLAG
;
610 flags
|= GSS_C_INTEG_FLAG
;
612 flags
|= GSS_C_TRANS_FLAG
;
617 ctx
->more_flags
|= LOCAL
;
619 ret
= _gsskrb5_create_8003_checksum (minor_status
,
624 krb5_data_free (&fwd_data
);
628 enctype
= ctx
->auth_context
->keyblock
->keytype
;
630 ret
= krb5_cc_get_config(context
, ctx
->ccache
, ctx
->target
,
631 "time-offset", &timedata
);
633 if (timedata
.length
== 4) {
634 const u_char
*p
= timedata
.data
;
635 offset
= (p
[0] <<24) | (p
[1] << 16) | (p
[2] << 8) | (p
[3] << 0);
637 krb5_data_free(&timedata
);
641 krb5_get_kdc_sec_offset (context
, &oldoffset
, NULL
);
642 krb5_set_kdc_sec_offset (context
, offset
, -1);
645 kret
= _krb5_build_authenticator(context
,
651 KRB5_KU_AP_REQ_AUTH
);
655 krb5_set_kdc_sec_offset (context
, oldoffset
, -1);
656 *minor_status
= kret
;
661 kret
= krb5_build_ap_req (context
,
668 krb5_set_kdc_sec_offset (context
, oldoffset
, -1);
670 *minor_status
= kret
;
675 if (flags
& GSS_C_DCE_STYLE
) {
676 output_token
->value
= outbuf
.data
;
677 output_token
->length
= outbuf
.length
;
679 ret
= _gsskrb5_encapsulate (minor_status
, &outbuf
, output_token
,
680 (u_char
*)(intptr_t)"\x01\x00",
682 krb5_data_free (&outbuf
);
687 free_Checksum(&cksum
);
689 if (flags
& GSS_C_MUTUAL_FLAG
) {
690 ctx
->state
= INITIATOR_WAIT_FOR_MUTAL
;
691 return GSS_S_CONTINUE_NEEDED
;
694 return gsskrb5_initiator_ready(minor_status
, ctx
, context
);
696 if (ctx
->ccache
&& (ctx
->more_flags
& CLOSE_CCACHE
))
697 krb5_cc_close(context
, ctx
->ccache
);
703 static krb5_error_code
704 handle_error_packet(krb5_context context
,
708 krb5_error_code kret
;
711 kret
= krb5_rd_error(context
, &indata
, &error
);
713 kret
= krb5_error_from_rd_error(context
, &error
, NULL
);
715 /* save the time skrew for this host */
716 if (kret
== KRB5KRB_AP_ERR_SKEW
) {
719 int32_t t
= error
.stime
- time(NULL
);
721 p
[0] = (t
>> 24) & 0xFF;
722 p
[1] = (t
>> 16) & 0xFF;
723 p
[2] = (t
>> 8) & 0xFF;
724 p
[3] = (t
>> 0) & 0xFF;
727 timedata
.length
= sizeof(p
);
729 krb5_cc_set_config(context
, ctx
->ccache
, ctx
->target
,
730 "time-offset", &timedata
);
732 if ((ctx
->more_flags
& RETRIED
) == 0)
733 ctx
->state
= INITIATOR_RESTART
;
734 ctx
->more_flags
|= RETRIED
;
736 free_KRB_ERROR (&error
);
744 (OM_uint32
* minor_status
,
746 krb5_context context
,
747 const gss_OID mech_type
,
750 const gss_channel_bindings_t input_chan_bindings
,
751 const gss_buffer_t input_token
,
752 gss_OID
* actual_mech_type
,
753 gss_buffer_t output_token
,
754 OM_uint32
* ret_flags
,
759 krb5_error_code kret
;
761 krb5_ap_rep_enc_part
*repl
;
763 output_token
->length
= 0;
764 output_token
->value
= NULL
;
766 if (actual_mech_type
)
767 *actual_mech_type
= GSS_KRB5_MECHANISM
;
769 if (IS_DCE_STYLE(ctx
)) {
770 /* There is no OID wrapping. */
771 indata
.length
= input_token
->length
;
772 indata
.data
= input_token
->value
;
773 kret
= krb5_rd_rep(context
,
778 ret
= _gsskrb5_decapsulate(minor_status
,
783 if (ret
== GSS_S_COMPLETE
) {
784 *minor_status
= handle_error_packet(context
, ctx
, indata
);
786 *minor_status
= kret
;
788 return GSS_S_FAILURE
;
791 ret
= _gsskrb5_decapsulate (minor_status
,
796 if (ret
== GSS_S_DEFECTIVE_TOKEN
) {
797 /* check if there is an error token sent instead */
798 ret
= _gsskrb5_decapsulate (minor_status
,
803 if (ret
== GSS_S_COMPLETE
) {
804 *minor_status
= handle_error_packet(context
, ctx
, indata
);
805 return GSS_S_FAILURE
;
808 kret
= krb5_rd_rep (context
,
813 *minor_status
= kret
;
814 return GSS_S_FAILURE
;
818 krb5_free_ap_rep_enc_part (context
,
823 ret
= _gsskrb5_lifetime_left(minor_status
,
828 ret
= GSS_S_COMPLETE
;
831 *ret_flags
= ctx
->flags
;
833 if (req_flags
& GSS_C_DCE_STYLE
) {
834 int32_t local_seq
, remote_seq
;
838 * So DCE_STYLE is strange. The client echos the seq number
839 * that the server used in the server's mk_rep in its own
840 * mk_rep(). After when done, it resets to it's own seq number
841 * for the gss_wrap calls.
844 krb5_auth_con_getremoteseqnumber(context
, ctx
->auth_context
, &remote_seq
);
845 krb5_auth_con_getlocalseqnumber(context
, ctx
->auth_context
, &local_seq
);
846 krb5_auth_con_setlocalseqnumber(context
, ctx
->auth_context
, remote_seq
);
848 kret
= krb5_mk_rep(context
, ctx
->auth_context
, &outbuf
);
850 *minor_status
= kret
;
851 return GSS_S_FAILURE
;
854 /* reset local seq number */
855 krb5_auth_con_setlocalseqnumber(context
, ctx
->auth_context
, local_seq
);
857 output_token
->length
= outbuf
.length
;
858 output_token
->value
= outbuf
.data
;
861 return gsskrb5_initiator_ready(minor_status
, ctx
, context
);
865 * gss_init_sec_context
868 OM_uint32 GSSAPI_CALLCONV _gsskrb5_init_sec_context
869 (OM_uint32
* minor_status
,
870 const gss_cred_id_t cred_handle
,
871 gss_ctx_id_t
* context_handle
,
872 const gss_name_t target_name
,
873 const gss_OID mech_type
,
876 const gss_channel_bindings_t input_chan_bindings
,
877 const gss_buffer_t input_token
,
878 gss_OID
* actual_mech_type
,
879 gss_buffer_t output_token
,
880 OM_uint32
* ret_flags
,
884 krb5_context context
;
885 gsskrb5_cred cred
= (gsskrb5_cred
)cred_handle
;
889 GSSAPI_KRB5_INIT (&context
);
891 output_token
->length
= 0;
892 output_token
->value
= NULL
;
894 if (context_handle
== NULL
) {
896 return GSS_S_FAILURE
| GSS_S_CALL_BAD_STRUCTURE
;
904 if (target_name
== GSS_C_NO_NAME
) {
905 if (actual_mech_type
)
906 *actual_mech_type
= GSS_C_NO_OID
;
908 return GSS_S_BAD_NAME
;
911 if (mech_type
!= GSS_C_NO_OID
&&
912 !gss_oid_equal(mech_type
, GSS_KRB5_MECHANISM
))
913 return GSS_S_BAD_MECH
;
915 if (input_token
== GSS_C_NO_BUFFER
|| input_token
->length
== 0) {
918 if (*context_handle
!= GSS_C_NO_CONTEXT
) {
920 return GSS_S_FAILURE
| GSS_S_CALL_BAD_STRUCTURE
;
923 ret1
= _gsskrb5_create_ctx(minor_status
,
932 if (*context_handle
== GSS_C_NO_CONTEXT
) {
934 return GSS_S_FAILURE
| GSS_S_CALL_BAD_STRUCTURE
;
937 ctx
= (gsskrb5_ctx
) *context_handle
;
939 HEIMDAL_MUTEX_lock(&ctx
->ctx_id_mutex
);
942 switch (ctx
->state
) {
943 case INITIATOR_START
:
944 ret
= init_auth(minor_status
,
957 if (ret
!= GSS_S_COMPLETE
)
960 case INITIATOR_RESTART
:
961 ret
= init_auth_restart(minor_status
,
973 case INITIATOR_WAIT_FOR_MUTAL
:
974 ret
= repl_mutual(minor_status
,
986 if (ctx
->state
== INITIATOR_RESTART
)
989 case INITIATOR_READY
:
991 * If we get there, the caller have called
992 * gss_init_sec_context() one time too many.
994 _gsskrb5_set_status(EINVAL
, "init_sec_context "
995 "called one time too many");
996 *minor_status
= EINVAL
;
997 ret
= GSS_S_BAD_STATUS
;
1000 _gsskrb5_set_status(EINVAL
, "init_sec_context "
1001 "invalid state %d for client",
1003 *minor_status
= EINVAL
;
1004 ret
= GSS_S_BAD_STATUS
;
1007 HEIMDAL_MUTEX_unlock(&ctx
->ctx_id_mutex
);
1009 /* destroy context in case of error */
1010 if (GSS_ERROR(ret
)) {
1012 _gsskrb5_delete_sec_context(&min2
, context_handle
, GSS_C_NO_BUFFER
);