Skip to content

Commit aa22b0a

Browse files
committed
Revert all the fallback code paths, System.Net.Security.UseManagedNtlm has to be enabled explicitly; NativeAOT on Linux Bionic does that by default because it doesn't have GSSAPI and native shim
1 parent c58d44e commit aa22b0a

File tree

5 files changed

+26
-37
lines changed

5 files changed

+26
-37
lines changed

src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,9 @@ The .NET Foundation licenses this file to you under the MIT license.
279279
<IlcArg Include="--feature:System.Linq.Expressions.CanEmitObjectArrayDelegate=false" />
280280
<IlcArg Include="--feature:System.Linq.Expressions.CanCreateArbitraryDelegates=false" />
281281

282+
<!-- Linux Bionic doesn't ship GSSAPI, so enable managed implementation -->
283+
<IlcArg Condition="'$(_linuxLibcFlavor)' == 'bionic'" Include="--feature:System.Net.Security.UseManagedNtlm=true" />
284+
282285
<!-- The managed debugging support in libraries is unused - trim it -->
283286
<IlcArg Condition="'$(IlcKeepManagedDebuggerSupport)' != 'true'" Include="--feature:System.Diagnostics.Debugger.IsSupported=false" />
284287
<IlcArg Condition="'$(UseWindowsThreadPool)' != '' and '$(_targetOS)' == 'win'" Include="--feature:System.Threading.ThreadPool.UseWindowsThreadPool=$(UseWindowsThreadPool)" />

src/libraries/Common/tests/System/Net/Capability.Security.Unix.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ public static partial class Capability
77
{
88
public static bool IsNtlmInstalled()
99
{
10-
return true;
10+
// GSS on Linux does not work with OpenSSL 3.0. Fix was submitted to gss-ntlm but it will take a while to make to
11+
// all supported distributions. The second part of the check should be removed when it does.
12+
return Interop.NetSecurityNative.IsNtlmInstalled() && (!PlatformDetection.IsOpenSslSupported || PlatformDetection.OpenSslVersion.Major < 3);
1113
}
1214
}
1315
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<linker>
2+
<assembly fullname="System.Net.Security">
3+
<type fullname="System.Net.NegotiateAuthenticationPal">
4+
<method signature="System.Boolean get_UseManagedNtlm()" feature="System.Net.Security.UseManagedNtlm" featurevalue="false" body="stub" value="false" />
5+
</type>
6+
</assembly>
7+
</linker>

src/libraries/System.Net.Security/src/System.Net.Security.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@
284284
<Compile Include="System\Net\Security\Pal.Managed\SafeChannelBindingHandle.cs" />
285285
</ItemGroup>
286286
<ItemGroup Condition="'$(TargetPlatformIdentifier)' != '' and '$(TargetPlatformIdentifier)' != 'windows' and '$(UseManagedNtlm)' != 'true'">
287+
<ILLinkSubstitutionsXmls Include="$(ILLinkDirectory)ILLink.Substitutions.xml" />
287288
<Compile Include="System\Net\NegotiateAuthenticationPal.Unix.cs" />
288289
<Compile Include="$(CommonPath)Microsoft\Win32\SafeHandles\GssSafeHandles.cs"
289290
Link="Common\Microsoft\Win32\SafeHandles\GssSafeHandles.cs" />

src/libraries/System.Net.Security/src/System/Net/NegotiateAuthenticationPal.Unix.cs

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -19,35 +19,11 @@ namespace System.Net
1919
{
2020
internal partial class NegotiateAuthenticationPal
2121
{
22-
private static bool _useManagedNtlm;
23-
private static bool _isGssApiAvailable;
24-
25-
#pragma warning disable CA1810 // explicit static cctor
26-
static NegotiateAuthenticationPal()
27-
{
28-
try
29-
{
30-
if (!Interop.NetSecurityNative.IsNtlmInstalled())
31-
{
32-
_useManagedNtlm = !AppContext.TryGetSwitch("System.Net.Security.UseManagedNtlm", out bool useManagedNtlm) || useManagedNtlm;
33-
}
34-
else
35-
{
36-
_useManagedNtlm = AppContext.TryGetSwitch("System.Net.Security.UseManagedNtlm", out bool useManagedNtlm) && useManagedNtlm;
37-
}
38-
_isGssApiAvailable = true;
39-
}
40-
catch (EntryPointNotFoundException)
41-
{
42-
// GSSAPI shim may not be available on some platforms (Linux Bionic)
43-
_isGssApiAvailable = false;
44-
}
45-
}
46-
#pragma warning restore CA1810
22+
private static bool UseManagedNtlm { get; } = AppContext.TryGetSwitch("System.Net.Security.UseManagedNtlm", out bool useManagedNtlm) && useManagedNtlm;
4723

4824
public static NegotiateAuthenticationPal Create(NegotiateAuthenticationClientOptions clientOptions)
4925
{
50-
if (_useManagedNtlm)
26+
if (UseManagedNtlm)
5127
{
5228
switch (clientOptions.Package)
5329
{
@@ -57,11 +33,6 @@ public static NegotiateAuthenticationPal Create(NegotiateAuthenticationClientOpt
5733
case NegotiationInfoClass.Negotiate:
5834
return new ManagedSpnegoNegotiateAuthenticationPal(clientOptions, supportKerberos: true);
5935
}
60-
61-
if (!_isGssApiAvailable)
62-
{
63-
return new UnsupportedNegotiateAuthenticationPal(clientOptions);
64-
}
6536
}
6637

6738
try
@@ -76,15 +47,15 @@ public static NegotiateAuthenticationPal Create(NegotiateAuthenticationClientOpt
7647
{
7748
return new UnsupportedNegotiateAuthenticationPal(clientOptions);
7849
}
50+
catch (EntryPointNotFoundException)
51+
{
52+
// GSSAPI shim may not be available on some platforms (Linux Bionic)
53+
return new UnsupportedNegotiateAuthenticationPal(clientOptions);
54+
}
7955
}
8056

8157
public static NegotiateAuthenticationPal Create(NegotiateAuthenticationServerOptions serverOptions)
8258
{
83-
if (!_isGssApiAvailable)
84-
{
85-
return new UnsupportedNegotiateAuthenticationPal(serverOptions);
86-
}
87-
8859
try
8960
{
9061
return new UnixNegotiateAuthenticationPal(serverOptions);
@@ -97,6 +68,11 @@ public static NegotiateAuthenticationPal Create(NegotiateAuthenticationServerOpt
9768
{
9869
return new UnsupportedNegotiateAuthenticationPal(serverOptions);
9970
}
71+
catch (EntryPointNotFoundException)
72+
{
73+
// GSSAPI shim may not be available on some platforms (Linux Bionic)
74+
return new UnsupportedNegotiateAuthenticationPal(serverOptions);
75+
}
10076
}
10177

10278
internal sealed class UnixNegotiateAuthenticationPal : NegotiateAuthenticationPal

0 commit comments

Comments
 (0)