Skip to content

Commit 99335ca

Browse files
committed
only use second
1 parent a2713c9 commit 99335ca

File tree

2 files changed

+6
-43
lines changed

2 files changed

+6
-43
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,10 @@ internal void Connect(ServerInfo serverInfo,
593593
}
594594
SqlClientEventSource.Log.TryTraceEvent("<sc.TdsParser.Connect|SEC> Prelogin handshake successful");
595595

596-
_authenticationProvider?.Initialize(serverInfo, _physicalStateObj, this, serverSpns);
596+
// We need to initialize the authentication provider with the server SPN
597+
// This array will either be a single entry with the SPN or two entries with the second
598+
// one being including a default port.
599+
_authenticationProvider?.Initialize(serverInfo, _physicalStateObj, this, serverSpns[^1]);
597600

598601
if (_fMARS && marsCapable)
599602
{

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

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
using System;
22
using System.Buffers;
3-
using System.Collections.Generic;
43
using System.Diagnostics;
5-
using System.Linq;
64

75
#nullable enable
86

@@ -13,7 +11,6 @@ internal abstract class SspiContextProvider
1311
private TdsParser _parser = null!;
1412
private ServerInfo _serverInfo = null!;
1513

16-
private List<SspiAuthenticationParameters>? _authParams;
1714
private SspiAuthenticationParameters? _authParam;
1815

1916
private protected TdsParserStateObject _physicalStateObj = null!;
@@ -22,22 +19,15 @@ internal void Initialize(
2219
ServerInfo serverInfo,
2320
TdsParserStateObject physicalStateObj,
2421
TdsParser parser,
25-
#if NETFRAMEWORK
2622
string serverSpn
27-
#else
28-
string[] serverSpns
29-
#endif
3023
)
3124
{
3225
_parser = parser;
3326
_physicalStateObj = physicalStateObj;
3427
_serverInfo = serverInfo;
3528

36-
#if NETFRAMEWORK
3729
_authParam = CreateAuthParams(serverSpn);
38-
#else
39-
_authParams = [.. serverSpns.Select(CreateAuthParams)];
40-
#endif
30+
4131
Initialize();
4232
}
4333

@@ -51,43 +41,13 @@ internal void WriteSSPIContext(ReadOnlySpan<byte> receivedBuff, IBufferWriter<by
5141
{
5242
using var _ = TrySNIEventScope.Create(nameof(SspiContextProvider));
5343

54-
if (!TryRunSingle(receivedBuff, outgoingBlobWriter) && !TryRunMultiple(receivedBuff, outgoingBlobWriter))
44+
if (!(_authParam is { } && RunGenerateSspiClientContext(receivedBuff, outgoingBlobWriter, _authParam)))
5545
{
5646
// If we've hit here, the SSPI context provider implementation failed to generate the SSPI context.
5747
SSPIError(SQLMessage.SSPIGenerateError(), TdsEnums.GEN_CLIENT_CONTEXT);
5848
}
5949
}
6050

61-
/// <summary>
62-
/// If we only have a single auth param, we know it's the correct one to use.
63-
/// </summary>
64-
private bool TryRunSingle(ReadOnlySpan<byte> receivedBuff, IBufferWriter<byte> outgoingBlobWriter)
65-
{
66-
return _authParam is { } && RunGenerateSspiClientContext(receivedBuff, outgoingBlobWriter, _authParam);
67-
}
68-
69-
/// <summary>
70-
/// If we have multiple, we need to loop through them, and then identify the correct one for future use.
71-
/// </summary>
72-
private bool TryRunMultiple(ReadOnlySpan<byte> receivedBuff, IBufferWriter<byte> outgoingBlobWriter)
73-
{
74-
if (_authParams is { })
75-
{
76-
foreach (var authParam in _authParams)
77-
{
78-
if (RunGenerateSspiClientContext(receivedBuff, outgoingBlobWriter, authParam))
79-
{
80-
// Reset the _authParams to only have a single one going forward to always call the context with that one
81-
_authParam = authParam;
82-
_authParams = null;
83-
return true;
84-
}
85-
}
86-
}
87-
88-
return false;
89-
}
90-
9151
private SspiAuthenticationParameters CreateAuthParams(string serverSpn)
9252
{
9353
var options = _parser.Connection.ConnectionOptions;

0 commit comments

Comments
 (0)