@@ -11,28 +11,22 @@ namespace Microsoft.Data.SqlClient
11
11
{
12
12
internal sealed class NegotiateSSPIContextProvider : SSPIContextProvider
13
13
{
14
- private NegotiateAuthentication ? _negotiateAuth = null ;
15
-
16
14
protected override void GenerateSspiClientContext ( ReadOnlySpan < byte > incomingBlob , IBufferWriter < byte > outgoingBlobWriter , byte [ ] [ ] _sniSpnBuffer )
17
15
{
18
16
NegotiateAuthenticationStatusCode statusCode = NegotiateAuthenticationStatusCode . UnknownCredentials ;
19
17
20
18
for ( int i = 0 ; i < _sniSpnBuffer . Length ; i ++ )
21
19
{
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 ) ! ;
24
22
25
23
// Log session id, status code and the actual SPN used in the negotiation
26
24
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 ) ;
28
26
if ( statusCode == NegotiateAuthenticationStatusCode . Completed || statusCode == NegotiateAuthenticationStatusCode . ContinueNeeded )
29
27
{
30
28
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.
36
30
}
37
31
}
38
32
0 commit comments