@@ -110,6 +110,31 @@ ssh_gss_sspi_init(_Out_ OM_uint32 * minor_status)
110110 return 1 ;
111111}
112112
113+ static CredHandle *
114+ default_cred_handle (ULONG cred_usage , const gss_cred_id_t * in )
115+ {
116+ static CredHandle default_inbound_cred_handle = { 0 , 0 };
117+ static CredHandle default_outbound_cred_handle = { 0 , 0 };
118+ TimeStamp cred_expiry ;
119+
120+ if (* in != GSS_C_NO_CREDENTIAL )
121+ return & (* in )-> credHandle ;
122+
123+ CredHandle * ret = & default_inbound_cred_handle ;
124+ if (cred_usage == SECPKG_CRED_OUTBOUND )
125+ ret = & default_outbound_cred_handle ;
126+
127+ if (ret -> dwLower || ret -> dwUpper )
128+ return ret ;
129+
130+ if (SecFunctions -> AcquireCredentialsHandleW (NULL ,
131+ MICROSOFT_KERBEROS_NAME_W , cred_usage , NULL , NULL , NULL ,
132+ NULL , ret , & cred_expiry ) != SEC_E_OK )
133+ return NULL ;
134+
135+ return ret ;
136+ }
137+
113138/*
114139 * Allows an application to determine which underlying security mechanisms are
115140 * available.
@@ -532,20 +557,10 @@ gss_init_sec_context(
532557 GetSystemTime (& current_time_system );
533558
534559 /* acquire default cred handler if none specified */
535- CredHandle * pCredHandle = NULL ;
536- if (claimant_cred_handle != NULL )
537- pCredHandle = & (claimant_cred_handle -> credHandle );
538-
539- if (pCredHandle == NULL ) {
540- static CredHandle cred_handle = { 0 , 0 };
541- pCredHandle = & cred_handle ;
542- if (cred_handle .dwLower == 0 && cred_handle .dwUpper == 0 ) {
543- TimeStamp expiry_cred ;
544- if (SecFunctions -> AcquireCredentialsHandleW (NULL , MICROSOFT_KERBEROS_NAME_W , SECPKG_CRED_OUTBOUND ,
545- NULL , NULL , NULL , NULL , & cred_handle , & expiry_cred ) != SEC_E_OK )
546- goto done ;
547- }
548- }
560+ CredHandle * pCredHandle = default_cred_handle (SECPKG_CRED_OUTBOUND ,
561+ & claimant_cred_handle );
562+ if (!pCredHandle )
563+ goto done ;
549564
550565 /* condition the string for windows */
551566 if ((target_name_utf16 = utf8_to_utf16 (target_name )) == NULL )
@@ -822,6 +837,11 @@ gss_accept_sec_context(_Out_ OM_uint32 * minor_status, _Inout_opt_ gss_ctx_id_t
822837 if (ssh_gss_sspi_init (minor_status ) == 0 )
823838 goto done ;
824839
840+ CredHandle * p_acceptor_cred_handle = default_cred_handle (
841+ SECPKG_CRED_INBOUND , & acceptor_cred_handle );
842+ if (!p_acceptor_cred_handle )
843+ goto done ;
844+
825845 /* setup input buffer */
826846 SecBuffer input_buffer_token = { (unsigned long ) input_token_buffer -> length ,
827847 SECBUFFER_TOKEN | SECBUFFER_READONLY , input_token_buffer -> value };
@@ -842,7 +862,7 @@ gss_accept_sec_context(_Out_ OM_uint32 * minor_status, _Inout_opt_ gss_ctx_id_t
842862 ASC_REQ_DELEGATE | ASC_REQ_SEQUENCE_DETECT | ASC_REQ_ALLOCATE_MEMORY ;
843863
844864 /* call sspi accept security context function */
845- const SECURITY_STATUS status = SecFunctions -> AcceptSecurityContext (& acceptor_cred_handle -> credHandle ,
865+ const SECURITY_STATUS status = SecFunctions -> AcceptSecurityContext (p_acceptor_cred_handle ,
846866 (* context_handle == GSS_C_NO_CONTEXT ) ? NULL : * context_handle , & input_buffer ,
847867 sspi_req_flags , SECURITY_NATIVE_DREP ,
848868 (* context_handle == GSS_C_NO_CONTEXT ) ? & sspi_context_handle : * context_handle ,
0 commit comments