@@ -11,28 +11,22 @@ namespace Microsoft.Data.SqlClient
1111{
1212 internal sealed class NegotiateSSPIContextProvider : SSPIContextProvider
1313 {
14- private NegotiateAuthentication ? _negotiateAuth = null ;
15-
1614 protected override void GenerateSspiClientContext ( ReadOnlySpan < byte > incomingBlob , IBufferWriter < byte > outgoingBlobWriter , byte [ ] [ ] _sniSpnBuffer )
1715 {
1816 NegotiateAuthenticationStatusCode statusCode = NegotiateAuthenticationStatusCode . UnknownCredentials ;
1917
2018 for ( int i = 0 ; i < _sniSpnBuffer . Length ; i ++ )
2119 {
22- _negotiateAuth ?? = new ( new NegotiateAuthenticationClientOptions { Package = "Negotiate" , TargetName = Encoding . Unicode . GetString ( _sniSpnBuffer [ i ] ) } ) ;
23- var sendBuff = _negotiateAuth . GetOutgoingBlob ( incomingBlob , out statusCode ) ! ;
20+ var negotiateAuth = new NegotiateAuthentication ( new NegotiateAuthenticationClientOptions { Package = "Negotiate" , TargetName = Encoding . Unicode . GetString ( _sniSpnBuffer [ i ] ) } ) ;
21+ var sendBuff = negotiateAuth . GetOutgoingBlob ( incomingBlob , out statusCode ) ! ;
2422
2523 // Log session id, status code and the actual SPN used in the negotiation
2624 SqlClientEventSource . Log . TryTraceEvent ( "{0}.{1} | Info | Session Id {2}, StatusCode={3}, SPN={4}" , nameof ( NegotiateSSPIContextProvider ) ,
27- nameof ( GenerateSspiClientContext ) , _physicalStateObj . SessionId , statusCode , _negotiateAuth . TargetName ) ;
25+ nameof ( GenerateSspiClientContext ) , _physicalStateObj . SessionId , statusCode , negotiateAuth . TargetName ) ;
2826 if ( statusCode == NegotiateAuthenticationStatusCode . Completed || statusCode == NegotiateAuthenticationStatusCode . ContinueNeeded )
2927 {
3028 outgoingBlobWriter . Write ( sendBuff ) ;
31- break ; // Successful case, exit the loop with current SPN.
32- }
33- else
34- {
35- _negotiateAuth = null ; // Reset _negotiateAuth to be generated again for next SPN.
29+ return ; // Successful case, exit the loop with current SPN.
3630 }
3731 }
3832
0 commit comments