Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ private static DbConnectionPoolIdentity GetCurrentNative()
using (WindowsIdentity identity = WindowsIdentity.GetCurrent())
{
IntPtr token = identity.AccessToken.DangerousGetHandle();
bool isNetwork = identity.User.IsWellKnown(WellKnownSidType.NetworkSid);
string sidString = identity.User.Value;
SecurityIdentifier user = identity.User;
bool isNetwork = user.IsWellKnown(WellKnownSidType.NetworkSid);
string sidString = user.Value;

// Win32NativeMethods.IsTokenRestricted will raise exception if the native call fails
bool isRestricted = Win32NativeMethods.IsTokenRestrictedWrapper(token);
Expand Down
15 changes: 13 additions & 2 deletions src/System.Data.SqlClient/src/System/Data/SqlClient/TdsParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;
using System.Buffers;
using System.Data.Common;
using System.Data.Sql;
using System.Data.SqlTypes;
Expand Down Expand Up @@ -6190,6 +6191,7 @@ internal void TdsLogin(SqlLogin rec, TdsEnums.FeatureExtension requestedFeatures
}

// allocate memory for SSPI variables
byte[] rentedSSPIBuff = null;
byte[] outSSPIBuff = null;
uint outSSPILength = 0;

Expand All @@ -6207,7 +6209,8 @@ internal void TdsLogin(SqlLogin rec, TdsEnums.FeatureExtension requestedFeatures
if (rec.useSSPI)
{
// now allocate proper length of buffer, and set length
outSSPIBuff = new byte[s_maxSSPILength];
rentedSSPIBuff = ArrayPool<byte>.Shared.Rent((int)s_maxSSPILength);
outSSPIBuff = rentedSSPIBuff;
outSSPILength = s_maxSSPILength;

// Call helper function for SSPI data and actual length.
Expand Down Expand Up @@ -6515,6 +6518,11 @@ internal void TdsLogin(SqlLogin rec, TdsEnums.FeatureExtension requestedFeatures
throw;
}

if (rentedSSPIBuff != null)
{
ArrayPool<byte>.Shared.Return(rentedSSPIBuff, clearArray: true);
}

_physicalStateObj.WritePacket(TdsEnums.HARDFLUSH);
_physicalStateObj.ResetSecurePasswordsInformation();
_physicalStateObj._pendingData = true;
Expand Down Expand Up @@ -6569,7 +6577,8 @@ private void ProcessSSPI(int receivedLength)
if (!result) { throw SQL.SynchronousCallMayNotPend(); }

// allocate send buffer and initialize length
byte[] sendBuff = new byte[s_maxSSPILength];
byte[] rentedSendBuff = ArrayPool<byte>.Shared.Rent((int)s_maxSSPILength);
byte[] sendBuff = rentedSendBuff;
uint sendLength = s_maxSSPILength;

// make call for SSPI data
Expand All @@ -6579,6 +6588,8 @@ private void ProcessSSPI(int receivedLength)
// DO NOT SEND LENGTH - TDS DOC INCORRECT! JUST SEND SSPI DATA!
_physicalStateObj.WriteByteArray(sendBuff, (int)sendLength, 0);

ArrayPool<byte>.Shared.Return(rentedSendBuff, clearArray: true);

// set message type so server knows its a SSPI response
_physicalStateObj._outputMessageType = TdsEnums.MT_SSPI;

Expand Down