Skip to content

Commit a49abc3

Browse files
committed
use return
1 parent 09db047 commit a49abc3

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SSPI/NegotiateSSPIContextProvider.cs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,27 @@ 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)!;
22+
2423
// Log session id, status code and the actual SPN used in the negotiation
2524
SqlClientEventSource.Log.TryTraceEvent("{0}.{1} | Info | Session Id {2}, StatusCode={3}, SPN={4}", nameof(NegotiateSSPIContextProvider),
26-
nameof(GenerateSspiClientContext), _physicalStateObj.SessionId, statusCode, _negotiateAuth.TargetName);
25+
nameof(GenerateSspiClientContext), _physicalStateObj.SessionId, statusCode, negotiateAuth.TargetName);
26+
2727
if (statusCode == NegotiateAuthenticationStatusCode.Completed || statusCode == NegotiateAuthenticationStatusCode.ContinueNeeded)
2828
{
2929
outgoingBlobWriter.Write(sendBuff);
30-
break; // Successful case, exit the loop with current SPN.
31-
}
32-
else
33-
{
34-
_negotiateAuth = null; // Reset _negotiateAuth to be generated again for next SPN.
30+
return; // Successful case, exit the loop with current SPN.
3531
}
3632
}
3733

38-
if (statusCode is not NegotiateAuthenticationStatusCode.Completed and not NegotiateAuthenticationStatusCode.ContinueNeeded)
39-
{
40-
throw new InvalidOperationException(SQLMessage.SSPIGenerateError() + Environment.NewLine + statusCode);
41-
}
34+
throw new InvalidOperationException(SQLMessage.SSPIGenerateError() + Environment.NewLine + statusCode);
4235
}
4336
}
4437
}

0 commit comments

Comments
 (0)