Skip to content

Commit 43dff4d

Browse files
committed
make sure to raise error if sspi not created
1 parent b448eb0 commit 43dff4d

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Microsoft.Data.SqlClient
1111
{
1212
internal sealed class NegotiateSspiContextProvider : SspiContextProvider
1313
{
14-
private NegotiateAuthentication? _negotiateAuth = null;
14+
private NegotiateAuthentication? _negotiateAuth;
1515

1616
protected override bool GenerateSspiClientContext(ReadOnlySpan<byte> incomingBlob, IBufferWriter<byte> outgoingBlobWriter, SspiAuthenticationParameters authParams)
1717
{

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ internal abstract class SspiContextProvider
1515
// This is used to store either a single or multiple SspiAuthenticationParameters. Since we initially have potential
1616
// multiple SPNs, we'll start with that. However, once we've succeeded creating an SSPI context, we'll consider that
1717
// to be the correct SPN going forward
18-
private object? _authParams;
18+
private object? _authParamValue;
1919

2020
private protected TdsParserStateObject _physicalStateObj = null!;
2121

@@ -35,9 +35,9 @@ string[] serverSpns
3535
_serverInfo = serverInfo;
3636

3737
#if NETFRAMEWORK
38-
_authParams = CreateAuthParams(serverSpn);
38+
_authParamValue = CreateAuthParams(serverSpn);
3939
#else
40-
_authParams = serverSpns.Select(CreateAuthParams).ToArray();
40+
_authParamValue = serverSpns.Select(CreateAuthParams).ToArray();
4141
#endif
4242
Initialize();
4343
}
@@ -48,23 +48,22 @@ private protected virtual void Initialize()
4848

4949
protected abstract bool GenerateSspiClientContext(ReadOnlySpan<byte> incomingBlob, IBufferWriter<byte> outgoingBlobWriter, SspiAuthenticationParameters authParams);
5050

51-
internal void SSPIData(ReadOnlySpan<byte> receivedBuff, IBufferWriter<byte> outgoingBlobWriter)
51+
internal void WriteSSPIContext(ReadOnlySpan<byte> receivedBuff, IBufferWriter<byte> outgoingBlobWriter)
5252
{
5353
using var _ = TrySNIEventScope.Create(nameof(SspiContextProvider));
5454

55-
if (_authParams is SspiAuthenticationParameters authParam)
55+
if (_authParamValue is SspiAuthenticationParameters authParam && RunGenerateSspiClientContext(receivedBuff, outgoingBlobWriter, authParam))
5656
{
57-
RunGenerateSspiClientContext(receivedBuff, outgoingBlobWriter, authParam);
5857
return;
5958
}
60-
else if (_authParams is SspiAuthenticationParameters[] authParams)
59+
else if (_authParamValue is SspiAuthenticationParameters[] authParams)
6160
{
6261
foreach (var p in authParams)
6362
{
6463
if (RunGenerateSspiClientContext(receivedBuff, outgoingBlobWriter, p))
6564
{
6665
// Reset the _authParams to only have a single one going forward to always call the context with that one
67-
_authParams = p;
66+
_authParamValue = p;
6867
return;
6968
}
7069
}

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParser.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ internal void ProcessSSPI(int receivedLength)
3535
try
3636
{
3737
// make call for SSPI data
38-
_authenticationProvider!.SSPIData(receivedBuff.AsSpan(0, receivedLength), writer);
38+
_authenticationProvider!.WriteSSPIContext(receivedBuff.AsSpan(0, receivedLength), writer);
3939

4040
// DO NOT SEND LENGTH - TDS DOC INCORRECT! JUST SEND SSPI DATA!
4141
_physicalStateObj.WriteByteSpan(writer.WrittenSpan);
@@ -175,7 +175,7 @@ internal void TdsLogin(
175175
// byte[] buffer and 0 for the int length.
176176
Debug.Assert(SniContext.Snix_Login == _physicalStateObj.SniContext, $"Unexpected SniContext. Expecting Snix_Login, actual value is '{_physicalStateObj.SniContext}'");
177177
_physicalStateObj.SniContext = SniContext.Snix_LoginSspi;
178-
_authenticationProvider.SSPIData(ReadOnlySpan<byte>.Empty, sspiWriter);
178+
_authenticationProvider.WriteSSPIContext(ReadOnlySpan<byte>.Empty, sspiWriter);
179179

180180
_physicalStateObj.SniContext = SniContext.Snix_Login;
181181

0 commit comments

Comments
 (0)