Skip to content

Commit 1ba12e6

Browse files
committed
react to ISniNativeMethods
1 parent 669cc6a commit 1ba12e6

File tree

8 files changed

+39
-37
lines changed

8 files changed

+39
-37
lines changed

src/Microsoft.Data.SqlClient/src/Interop/Windows/Sni/ISniNativeMethods.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ unsafe uint SniSecGenClientContextWrapper(
7272
SNIHandle pConn,
7373
byte* pIn,
7474
uint cbIn,
75-
byte[] pOut,
75+
byte* pOut,
7676
ref uint pcbOut,
7777
out bool pfDone,
7878
byte* szServerInfo,

src/Microsoft.Data.SqlClient/src/Interop/Windows/Sni/SniNativeMethods.netcore.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public unsafe uint SniSecGenClientContextWrapper(
111111
SNIHandle pConn,
112112
byte* pIn,
113113
uint cbIn,
114-
byte[] pOut,
114+
byte* pOut,
115115
ref uint pcbOut,
116116
out bool pfDone,
117117
byte* szServerInfo,
@@ -265,7 +265,7 @@ private static extern unsafe uint SNISecGenClientContextWrapper(
265265
[In] SNIHandle pConn,
266266
[In, Out] byte* pIn,
267267
uint cbIn,
268-
[In, Out] byte[] pOut,
268+
[In, Out] byte* pOut,
269269
[In] ref uint pcbOut,
270270
[MarshalAs(UnmanagedType.Bool)] out bool pfDone,
271271
byte* szServerInfo,

src/Microsoft.Data.SqlClient/src/Interop/Windows/Sni/SniNativeMethodsArm64.netfx.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public unsafe uint SniSecGenClientContextWrapper(
111111
SNIHandle pConn,
112112
byte* pIn,
113113
uint cbIn,
114-
byte[] pOut,
114+
byte* pOut,
115115
ref uint pcbOut,
116116
out bool pfDone,
117117
byte* szServerInfo,
@@ -265,7 +265,7 @@ private static extern unsafe uint SNISecGenClientContextWrapper(
265265
[In] SNIHandle pConn,
266266
[In, Out] byte* pIn,
267267
uint cbIn,
268-
[In, Out] byte[] pOut,
268+
[In, Out] byte* pOut,
269269
[In] ref uint pcbOut,
270270
[MarshalAs(UnmanagedType.Bool)] out bool pfDone,
271271
byte* szServerInfo,

src/Microsoft.Data.SqlClient/src/Interop/Windows/Sni/SniNativeMethodsNotSupported.netfx.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public unsafe uint SniSecGenClientContextWrapper(
115115
SNIHandle pConn,
116116
byte* pIn,
117117
uint cbIn,
118-
byte[] pOut,
118+
byte* pOut,
119119
ref uint pcbOut,
120120
out bool pfDone,
121121
byte* szServerInfo,

src/Microsoft.Data.SqlClient/src/Interop/Windows/Sni/SniNativeMethodsX64.netfx.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public unsafe uint SniSecGenClientContextWrapper(
111111
SNIHandle pConn,
112112
byte* pIn,
113113
uint cbIn,
114-
byte[] pOut,
114+
byte* pOut,
115115
ref uint pcbOut,
116116
out bool pfDone,
117117
byte* szServerInfo,
@@ -265,7 +265,7 @@ private static extern unsafe uint SNISecGenClientContextWrapper(
265265
[In] SNIHandle pConn,
266266
[In, Out] byte* pIn,
267267
uint cbIn,
268-
[In, Out] byte[] pOut,
268+
[In, Out] byte* pOut,
269269
[In] ref uint pcbOut,
270270
[MarshalAs(UnmanagedType.Bool)] out bool pfDone,
271271
byte* szServerInfo,

src/Microsoft.Data.SqlClient/src/Interop/Windows/Sni/SniNativeMethodsX86.netfx.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public unsafe uint SniSecGenClientContextWrapper(
111111
SNIHandle pConn,
112112
byte* pIn,
113113
uint cbIn,
114-
byte[] pOut,
114+
byte* pOut,
115115
ref uint pcbOut,
116116
out bool pfDone,
117117
byte* szServerInfo,
@@ -265,7 +265,7 @@ private static extern unsafe uint SNISecGenClientContextWrapper(
265265
[In] SNIHandle pConn,
266266
[In, Out] byte* pIn,
267267
uint cbIn,
268-
[In, Out] byte[] pOut,
268+
[In, Out] byte* pOut,
269269
[In] ref uint pcbOut,
270270
[MarshalAs(UnmanagedType.Bool)] out bool pfDone,
271271
byte* szServerInfo,

src/Microsoft.Data.SqlClient/src/Interop/Windows/Sni/SniNativeWrapper.cs

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ namespace Microsoft.Data.SqlClient
1717
{
1818
internal static class SniNativeWrapper
1919
{
20-
#if NETFRAMEWORK
20+
#if NETFRAMEWORK
2121
private static readonly ISniNativeMethods NativeMethods = RuntimeInformation.ProcessArchitecture switch
2222
{
2323
Architecture.Arm64 => new SniNativeMethodsArm64(),
2424
Architecture.X64 => new SniNativeMethodsX64(),
2525
Architecture.X86 => new SniNativeMethodsX86(),
2626
_ => new SniNativeMethodsNotSupported(RuntimeInformation.ProcessArchitecture)
2727
};
28-
#else
28+
#else
2929
private static readonly ISniNativeMethods NativeMethods = new SniNativeMethods();
30-
#endif
30+
#endif
3131

3232
private static int s_sniMaxComposedSpnLength = -1;
3333

@@ -47,7 +47,7 @@ internal static int SniMaxComposedSpnLength
4747
}
4848
}
4949

50-
#if NETFRAMEWORK
50+
#if NETFRAMEWORK
5151
static AppDomain GetDefaultAppDomainInternal()
5252
{
5353
return AppDomain.CurrentDomain;
@@ -85,10 +85,10 @@ internal unsafe static void SetData(Byte[] data)
8585
SqlDependencyProcessDispatcherStorage.NativeSetData(pin_dispatcher, data.Length);
8686
}
8787
}
88-
#endif
88+
#endif
8989

9090
#region DLL Imports
91-
91+
9292
internal static uint SNIAddProvider(SNIHandle pConn, Provider ProvNum, [In] ref uint pInfo) =>
9393
NativeMethods.SniAddProvider(pConn, ProvNum, ref pInfo);
9494

@@ -146,10 +146,10 @@ private static uint GetSniMaxComposedSpnLength() =>
146146
private static uint SNIGetInfoWrapper([In] SNIHandle pConn, QueryType QType, out Guid pbQInfo) =>
147147
NativeMethods.SniGetInfoWrapper(pConn, QType, out pbQInfo);
148148

149-
#if NETFRAMEWORK
149+
#if NETFRAMEWORK
150150
private static uint SNIGetInfoWrapper([In] SNIHandle pConn, QueryType QType, [MarshalAs(UnmanagedType.Bool)] out bool pbQInfo) =>
151151
NativeMethods.SniGetInfoWrapper(pConn, QType, out pbQInfo);
152-
#endif
152+
#endif
153153

154154
private static uint SNIGetInfoWrapper([In] SNIHandle pConn, QueryType QType, out ushort portNum) =>
155155
NativeMethods.SniGetInfoWrapper(pConn, QType, out portNum);
@@ -191,11 +191,11 @@ private static uint SNIPacketGetDataWrapper([In] IntPtr packet, [In, Out] byte[]
191191

192192
private static unsafe void SNIPacketSetData(SNIPacket pPacket, [In] byte* pbBuf, uint cbBuf) =>
193193
NativeMethods.SniPacketSetData(pPacket, pbBuf, cbBuf);
194-
194+
195195
private static unsafe uint SNISecGenClientContextWrapper(
196196
[In] SNIHandle pConn,
197197
[In, Out] ReadOnlySpan<byte> pIn,
198-
[In, Out] byte[] pOut,
198+
[In, Out] Span<byte> pOut,
199199
[In] ref uint pcbOut,
200200
[MarshalAsAttribute(UnmanagedType.Bool)]
201201
out bool pfDone,
@@ -207,12 +207,13 @@ private static unsafe uint SNISecGenClientContextWrapper(
207207
string pwszPassword)
208208
{
209209
fixed (byte* pInPtr = pIn)
210+
fixed (byte* pOutPtr = pOut)
210211
{
211212
return NativeMethods.SniSecGenClientContextWrapper(
212213
pConn,
213214
pInPtr,
214215
(uint)pIn.Length,
215-
pOut,
216+
pOutPtr,
216217
ref pcbOut,
217218
out pfDone,
218219
szServerInfo,
@@ -227,7 +228,7 @@ private static uint SNIWriteAsyncWrapper(SNIHandle pConn, [In] SNIPacket pPacket
227228

228229
private static uint SNIWriteSyncOverAsync(SNIHandle pConn, [In] SNIPacket pPacket) =>
229230
NativeMethods.SniWriteSyncOverAsync(pConn, pPacket);
230-
231+
231232
internal static IntPtr SNIServerEnumOpen() =>
232233
NativeMethods.SniServerEnumOpen();
233234

@@ -236,11 +237,11 @@ internal static void SNIServerEnumClose([In] IntPtr packet) =>
236237

237238
internal static int SNIServerEnumRead(
238239
[In] IntPtr packet,
239-
[In] [MarshalAs(UnmanagedType.LPArray)] char[] readBuffer,
240+
[In][MarshalAs(UnmanagedType.LPArray)] char[] readBuffer,
240241
[In] int bufferLength,
241242
[MarshalAs(UnmanagedType.Bool)] out bool more) =>
242243
NativeMethods.SniServerEnumRead(packet, readBuffer, bufferLength, out more);
243-
244+
244245
#endregion
245246

246247
internal static uint SniGetConnectionId(SNIHandle pConn, ref Guid connId)
@@ -303,12 +304,12 @@ internal static unsafe uint SNIOpenSyncEx(
303304
bool fSync,
304305
int timeout,
305306
bool fParallel,
306-
307-
#if NETFRAMEWORK
307+
308+
#if NETFRAMEWORK
308309
Int32 transparentNetworkResolutionStateNo,
309310
Int32 totalTimeout,
310-
#endif
311-
311+
#endif
312+
312313
SqlConnectionIPAddressPreference ipPreference,
313314
SQLDNSInfo cachedDNSInfo,
314315
string hostNameInCertificate)
@@ -330,7 +331,7 @@ internal static unsafe uint SNIOpenSyncEx(
330331
clientConsumerInfo.timeout = timeout;
331332
clientConsumerInfo.fParallel = fParallel;
332333

333-
#if NETFRAMEWORK
334+
#if NETFRAMEWORK
334335
switch (transparentNetworkResolutionStateNo)
335336
{
336337
case (0):
@@ -344,10 +345,10 @@ internal static unsafe uint SNIOpenSyncEx(
344345
break;
345346
};
346347
clientConsumerInfo.totalTimeout = totalTimeout;
347-
#else
348+
#else
348349
clientConsumerInfo.transparentNetworkResolution = TransparentNetworkResolutionMode.DisabledMode;
349350
clientConsumerInfo.totalTimeout = SniOpenTimeOut;
350-
#endif
351+
#endif
351352

352353
clientConsumerInfo.isAzureSqlServerEndpoint = ADP.IsAzureSqlServerEndpoint(constring);
353354

@@ -374,7 +375,7 @@ internal static unsafe uint SNIOpenSyncEx(
374375
}
375376
}
376377

377-
#if NETFRAMEWORK
378+
#if NETFRAMEWORK
378379
[ResourceExposure(ResourceScope.None)]
379380
[ResourceConsumption(ResourceScope.Machine, ResourceScope.Machine)]
380381
internal static uint SNIAddProvider(SNIHandle pConn,
@@ -397,7 +398,7 @@ internal static uint SNIAddProvider(SNIHandle pConn,
397398

398399
return ret;
399400
}
400-
#endif
401+
#endif
401402

402403
internal static void SNIPacketAllocate(SafeHandle pConn, IoType IOType, ref IntPtr pPacket)
403404
{
@@ -417,7 +418,7 @@ internal static unsafe void SNIPacketSetData(SNIPacket packet, byte[] data, int
417418
}
418419
}
419420

420-
#if NETFRAMEWORK
421+
#if NETFRAMEWORK
421422
//[ResourceExposure(ResourceScope::None)]
422423
//
423424
// Notes on SecureString: Writing out security sensitive information to managed buffer should be avoid as these can be moved
@@ -541,10 +542,10 @@ Int32[] passwordOffsets // Offset into data buffer where the password to be w
541542
}
542543
}
543544
}
544-
#endif
545+
#endif
545546

546547

547-
internal static unsafe uint SNISecGenClientContext(SNIHandle pConnectionObject, ReadOnlySpan<byte> inBuff, byte[] OutBuff, ref uint sendLength, byte[] serverUserName)
548+
internal static unsafe uint SNISecGenClientContext(SNIHandle pConnectionObject, ReadOnlySpan<byte> inBuff, Span<byte> OutBuff, ref uint sendLength, byte[] serverUserName)
548549
{
549550
fixed (byte* pin_serverUserName = &serverUserName[0])
550551
//netcore fixed (byte* pInBuff = inBuff)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ protected override void GenerateSspiClientContext(ReadOnlySpan<byte> incomingBlo
5959
#endif
6060

6161
var outBuff = outgoingBlobWriter.GetSpan((int)s_maxSSPILength);
62+
uint sendLength = 0;
6263

63-
if (0 != SNINativeWrapper.SNISecGenClientContext(handle, incomingBlob, outBuff, out var sendLength, _sniSpnBuffer[0]))
64+
if (0 != SniNativeWrapper.SNISecGenClientContext(handle, incomingBlob, outBuff, ref sendLength, _sniSpnBuffer[0]))
6465
{
6566
throw new InvalidOperationException(SQLMessage.SSPIGenerateError());
6667
}

0 commit comments

Comments
 (0)