Skip to content

Commit ca7841a

Browse files
committed
Apply suggestions from PR review.
1 parent a9c52ed commit ca7841a

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ internal override void GenerateSspiClientContext(ReadOnlyMemory<byte> received,
1616
{
1717
NegotiateAuthenticationStatusCode statusCode = NegotiateAuthenticationStatusCode.UnknownCredentials;
1818

19-
foreach (byte[] spn in _sniSpnBuffer)
19+
for (int i = 0; i < _sniSpnBuffer.Length; i++)
2020
{
21-
_negotiateAuth ??= new(new NegotiateAuthenticationClientOptions { Package = "Negotiate", TargetName = Encoding.Unicode.GetString(spn) });
21+
string spnName = Encoding.Unicode.GetString(_sniSpnBuffer[i]);
22+
_negotiateAuth ??= new(new NegotiateAuthenticationClientOptions { Package = "Negotiate", TargetName = spnName });
2223
sendBuff = _negotiateAuth.GetOutgoingBlob(received.Span, out statusCode)!;
23-
SqlClientEventSource.Log.TryTraceEvent("TdsParserStateObjectManaged.GenerateSspiClientContext | Info | Session Id {0}, StatusCode={1}", _physicalStateObj.SessionId, statusCode);
24+
// Log session id, status code and the actual SPN used in the negotiation
25+
SqlClientEventSource.Log.TryTraceEvent($"TdsParserStateObjectManaged.GenerateSspiClientContext | Info | Session Id {_physicalStateObj.SessionId}, StatusCode={statusCode}, SPN={_negotiateAuth.TargetName}");
2426

2527
if (statusCode == NegotiateAuthenticationStatusCode.Completed || statusCode == NegotiateAuthenticationStatusCode.ContinueNeeded)
26-
break;
28+
break; // Successful case, exit the loop with current SPN.
2729
else
2830
_negotiateAuth = null; // Reset _negotiateAuth to be generated again for next SPN.
2931
}

0 commit comments

Comments
 (0)