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);
// 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;
}
// allocate memory for SSPI variables
+ byte[] rentedSSPIBuff = null;
byte[] outSSPIBuff = null;
uint outSSPILength = 0;
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.
throw;
}
+ if (rentedSSPIBuff != null)
+ {
+ ArrayPool<byte>.Shared.Return(rentedSSPIBuff, clearArray: true);
+ }
+
_physicalStateObj.WritePacket(TdsEnums.HARDFLUSH);
_physicalStateObj.ResetSecurePasswordsInformation();
_physicalStateObj._pendingData = true;
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
// 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;