Skip to content

Commit 2b59f38

Browse files
authored
Merge pull request #60318 from vseanreesermsft/internal-merge-5.0-2021-10-12-1521
Merging internal commits for release/5.0
2 parents b924deb + d4a0857 commit 2b59f38

File tree

8 files changed

+91
-10
lines changed

8 files changed

+91
-10
lines changed

src/libraries/Common/src/Interop/Linux/OpenLdap/Interop.Ldap.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,9 @@ static Ldap()
128128
[DllImport(Libraries.OpenLdap, EntryPoint = "ldap_set_option", CharSet = CharSet.Ansi)]
129129
public static extern int ldap_set_option_referral([In] ConnectionHandle ldapHandle, [In] LdapOption option, ref LdapReferralCallback outValue);
130130

131+
// Note that ldap_start_tls_s has a different signature across Windows LDAP and OpenLDAP
131132
[DllImport(Libraries.OpenLdap, EntryPoint = "ldap_start_tls_s", CharSet = CharSet.Ansi)]
132-
public static extern int ldap_start_tls(ConnectionHandle ldapHandle, ref int ServerReturnValue, ref IntPtr Message, IntPtr ServerControls, IntPtr ClientControls);
133+
public static extern int ldap_start_tls(ConnectionHandle ldapHandle, IntPtr serverControls, IntPtr clientControls);
133134

134135
[DllImport(Libraries.OpenLdap, EntryPoint = "ldap_parse_result", CharSet = CharSet.Ansi)]
135136
public static extern int ldap_parse_result([In] ConnectionHandle ldapHandle, [In] IntPtr result, ref int serverError, ref IntPtr dn, ref IntPtr message, ref IntPtr referral, ref IntPtr control, byte freeIt);

src/libraries/System.DirectoryServices.Protocols/Directory.Build.props

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
<StrongNameKeyId>Microsoft</StrongNameKeyId>
99
<IncludePlatformAttributes>true</IncludePlatformAttributes>
1010
<UnsupportedOSPlatforms>browser</UnsupportedOSPlatforms>
11+
<ServicingVersion>1</ServicingVersion>
1112
</PropertyGroup>
12-
</Project>
13+
</Project>

src/libraries/System.DirectoryServices.Protocols/src/System.DirectoryServices.Protocols.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@
6262
<Compile Include="System\DirectoryServices\Protocols\Interop\BerPal.Linux.cs" />
6363
<Compile Include="System\DirectoryServices\Protocols\ldap\LdapConnection.Linux.cs" />
6464
<Compile Include="System\DirectoryServices\Protocols\ldap\LdapSessionOptions.Linux.cs" />
65+
<Compile Include="System\DirectoryServices\Protocols\ldap\LocalAppContextSwitches.cs" />
6566
<Compile Include="System\DirectoryServices\Protocols\Interop\SafeHandles.Linux.cs" />
67+
<Compile Include="$(CommonPath)System\LocalAppContextSwitches.Common.cs">
68+
<Link>Common\System\LocalAppContextSwitches.Common.cs</Link>
69+
</Compile>
6670
<Compile Include="$(CommonPath)Interop\Linux\OpenLdap\Interop.Ldap.cs">
6771
<Link>Common\Interop\Linux\OpenLdap\Interop.Ldap.cs</Link>
6872
</Compile>

src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/Interop/LdapPal.Linux.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,31 @@ internal static int SearchDirectory(ConnectionHandle ldapHandle, string dn, int
9999

100100
internal static int BindToDirectory(ConnectionHandle ld, string who, string passwd) => Interop.Ldap.ldap_simple_bind(ld, who, passwd);
101101

102-
internal static int StartTls(ConnectionHandle ldapHandle, ref int ServerReturnValue, ref IntPtr Message, IntPtr ServerControls, IntPtr ClientControls) => Interop.Ldap.ldap_start_tls(ldapHandle, ref ServerReturnValue, ref Message, ServerControls, ClientControls);
102+
internal static int StartTls(ConnectionHandle ldapHandle, ref int serverReturnValue, ref IntPtr message, IntPtr serverControls, IntPtr clientControls)
103+
{
104+
// Windows and Linux have different signatures for ldap_start_tls_s.
105+
// On Linux, we don't have a serverReturnValue or the message/result parameter.
106+
//
107+
// So in the PAL here, just emulate.
108+
109+
int error = Interop.Ldap.ldap_start_tls(ldapHandle, serverControls, clientControls);
110+
111+
// On Windows, serverReturnValue only has meaning if the result code is LDAP_OTHER.
112+
// If OpenLDAP returns that, we don't have a better code, so assign that through.
113+
// If we get any other error, assign serverReturnValue to 0 since it shouldn't be read.
114+
if (error == (int)ResultCode.Other)
115+
{
116+
serverReturnValue = error;
117+
}
118+
else
119+
{
120+
serverReturnValue = 0;
121+
}
122+
123+
// We don't have a referrer/message/result value, so just set it to NULL.
124+
message = IntPtr.Zero;
125+
return error;
126+
}
103127

104128
// openldap doesn't have a ldap_stop_tls function. Returning true as no-op for Linux.
105129
internal static byte StopTls(ConnectionHandle ldapHandle) => 1;

src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/ldap/LdapConnection.Linux.cs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,39 @@ private int InternalConnectToServer()
2424
private int InternalBind(NetworkCredential tempCredential, SEC_WINNT_AUTH_IDENTITY_EX cred, BindMethod method)
2525
{
2626
int error;
27-
if (tempCredential == null && (AuthType == AuthType.External || AuthType == AuthType.Kerberos))
27+
28+
if (LocalAppContextSwitches.UseBasicAuthFallback)
2829
{
29-
error = BindSasl();
30+
if (tempCredential == null && (AuthType == AuthType.External || AuthType == AuthType.Kerberos))
31+
{
32+
error = BindSasl();
33+
}
34+
else
35+
{
36+
error = Interop.Ldap.ldap_simple_bind(_ldapHandle, cred.user, cred.password);
37+
}
3038
}
3139
else
3240
{
33-
error = Interop.Ldap.ldap_simple_bind(_ldapHandle, cred.user, cred.password);
41+
if (method == BindMethod.LDAP_AUTH_NEGOTIATE)
42+
{
43+
if (tempCredential == null)
44+
{
45+
error = BindSasl();
46+
}
47+
else
48+
{
49+
// Explicit credentials were provided. If we call ldap_bind_s it will
50+
// return LDAP_NOT_SUPPORTED, so just skip the P/Invoke.
51+
error = (int)LdapError.NotSupported;
52+
}
53+
}
54+
else
55+
{
56+
// Basic and Anonymous are handled elsewhere.
57+
Debug.Assert(AuthType != AuthType.Anonymous && AuthType != AuthType.Basic);
58+
error = (int)LdapError.AuthUnknown;
59+
}
3460
}
3561

3662
return error;

src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/ldap/LdapSessionOptions.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -664,11 +664,17 @@ public unsafe void StartTransportLayerSecurity(DirectoryControlCollection contro
664664
response.ResponseName = "1.3.6.1.4.1.1466.20037";
665665
throw new TlsOperationException(response);
666666
}
667-
else if (Utility.IsLdapError((LdapError)error))
667+
668+
// Turn OpenLDAP error values into Windows error values. e.g. LDAP_NOT_SUPPORTED (-12) => 92
669+
int normalizedError = error < 0 && error >= -17 ? 80 - error : error;
670+
671+
if (Utility.IsLdapError((LdapError)normalizedError))
668672
{
669-
string errorMessage = LdapErrorMappings.MapResultCode(error);
670-
throw new LdapException(error, errorMessage);
673+
string errorMessage = LdapErrorMappings.MapResultCode(normalizedError);
674+
throw new LdapException(normalizedError, errorMessage);
671675
}
676+
677+
throw new LdapException(error);
672678
}
673679
}
674680
finally
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Runtime.CompilerServices;
5+
6+
namespace System
7+
{
8+
internal static partial class LocalAppContextSwitches
9+
{
10+
private static int s_useBasicAuthFallback;
11+
12+
public static bool UseBasicAuthFallback
13+
{
14+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
15+
get => GetCachedSwitchValue("System.DirectoryServices.Protocols.UseBasicAuthFallback", ref s_useBasicAuthFallback);
16+
}
17+
}
18+
}

src/libraries/pkg/baseline/packageIndex.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2885,7 +2885,8 @@
28852885
"StableVersions": [
28862886
"4.5.0",
28872887
"4.6.0",
2888-
"5.0.0"
2888+
"5.0.0",
2889+
"5.0.1"
28892890
],
28902891
"BaselineVersion": "5.0.0",
28912892
"InboxOn": {

0 commit comments

Comments
 (0)