Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
117 commits
Select commit Hold shift + click to select a range
94482bb
Merged PR 17575: [Release 6.0] Fix StartTLS in DirectoryService.Proto…
joperezr Sep 14, 2021
5cddcbb
Merge in 'release/6.0' changes
dotnet-bot Sep 14, 2021
182149f
Merge in 'release/6.0' changes
dotnet-bot Sep 14, 2021
fc87781
Merge in 'release/6.0' changes
dotnet-bot Sep 15, 2021
14ae29a
Merge in 'release/6.0' changes
dotnet-bot Sep 15, 2021
58ccb06
Merge in 'release/6.0' changes
dotnet-bot Sep 15, 2021
1673fcb
Merge in 'release/6.0' changes
dotnet-bot Sep 15, 2021
ce7a8e1
Merge in 'release/6.0' changes
dotnet-bot Sep 15, 2021
814a49c
Merge in 'release/6.0' changes
dotnet-bot Sep 15, 2021
67f1401
Merge in 'release/6.0' changes
dotnet-bot Sep 15, 2021
d68cf3c
Merge in 'release/6.0' changes
dotnet-bot Sep 15, 2021
840d402
Merge in 'release/6.0' changes
dotnet-bot Sep 15, 2021
377e68d
Merge in 'release/6.0' changes
dotnet-bot Sep 15, 2021
971882e
Merge in 'release/6.0' changes
dotnet-bot Sep 15, 2021
2c84e1f
Merge in 'release/6.0' changes
dotnet-bot Sep 15, 2021
9ed76c6
Merge in 'release/6.0' changes
dotnet-bot Sep 15, 2021
449d48c
Merge in 'release/6.0' changes
dotnet-bot Sep 15, 2021
3d66b17
Merge in 'release/6.0' changes
dotnet-bot Sep 15, 2021
8803c01
Merge in 'release/6.0' changes
dotnet-bot Sep 15, 2021
3d5df7d
Merge in 'release/6.0' changes
dotnet-bot Sep 21, 2021
33480ff
Merge in 'release/6.0' changes
dotnet-bot Sep 21, 2021
fc6d117
Merge in 'release/6.0' changes
dotnet-bot Sep 21, 2021
523ebf1
Merge in 'release/6.0' changes
dotnet-bot Sep 22, 2021
5b24a6d
Merge in 'release/6.0' changes
dotnet-bot Sep 24, 2021
7f81cef
Merge in 'release/6.0' changes
dotnet-bot Sep 27, 2021
7e27b6d
Merge in 'release/6.0' changes
dotnet-bot Sep 27, 2021
b9a8282
Merge in 'release/6.0' changes
dotnet-bot Sep 28, 2021
5fa879c
Merge in 'release/6.0' changes
dotnet-bot Sep 29, 2021
0926dad
Merge in 'release/6.0' changes
dotnet-bot Sep 29, 2021
5632281
Merge in 'release/6.0' changes
dotnet-bot Sep 30, 2021
dde631d
Merge in 'release/6.0' changes
dotnet-bot Sep 30, 2021
819f532
Merge in 'release/6.0' changes
dotnet-bot Oct 1, 2021
6c7850e
Merge in 'release/6.0' changes
dotnet-bot Oct 1, 2021
c81d3a4
Merge in 'release/6.0' changes
dotnet-bot Oct 1, 2021
652d4d2
Merge in 'release/6.0' changes
dotnet-bot Oct 1, 2021
bfb058d
Merge in 'release/6.0' changes
dotnet-bot Oct 4, 2021
9a3981f
Merge in 'release/6.0' changes
dotnet-bot Oct 4, 2021
47580cd
Merge in 'release/6.0' changes
dotnet-bot Oct 4, 2021
8c9441d
Merge in 'release/6.0' changes
dotnet-bot Oct 4, 2021
2690b52
Merge in 'release/6.0' changes
dotnet-bot Oct 5, 2021
005e20d
Merge in 'release/6.0' changes
dotnet-bot Oct 6, 2021
86379d4
Merge in 'release/6.0' changes
dotnet-bot Oct 6, 2021
57c5d89
Merge in 'release/6.0' changes
dotnet-bot Oct 6, 2021
b743be2
Merge in 'release/6.0' changes
dotnet-bot Oct 6, 2021
a757af8
Merge in 'release/6.0' changes
dotnet-bot Oct 7, 2021
c474a56
Merge in 'release/6.0' changes
dotnet-bot Oct 7, 2021
18166f7
Merge in 'release/6.0' changes
dotnet-bot Oct 7, 2021
f8b5936
Merge in 'release/6.0' changes
dotnet-bot Oct 8, 2021
138ccd8
Merge in 'release/6.0' changes
dotnet-bot Oct 8, 2021
e1eb7b0
Merge in 'release/6.0' changes
dotnet-bot Oct 8, 2021
832f978
Merge in 'release/6.0' changes
dotnet-bot Oct 8, 2021
2e54d19
Merge in 'release/6.0' changes
dotnet-bot Oct 8, 2021
a2ab6bb
Merge in 'release/6.0' changes
dotnet-bot Oct 8, 2021
a75df8e
Merge in 'release/6.0' changes
dotnet-bot Oct 9, 2021
3fcd14f
Merge in 'release/6.0' changes
dotnet-bot Oct 11, 2021
23f2d29
Merge in 'release/6.0' changes
dotnet-bot Oct 11, 2021
806b5e5
Merge in 'release/6.0' changes
dotnet-bot Oct 12, 2021
0808485
Merge in 'release/6.0' changes
dotnet-bot Oct 12, 2021
040652e
Merge in 'release/6.0' changes
dotnet-bot Oct 13, 2021
63fb5f3
Merge in 'release/6.0' changes
dotnet-bot Oct 13, 2021
cbc5576
Merge in 'release/6.0' changes
dotnet-bot Oct 13, 2021
96e1118
Merge in 'release/6.0' changes
dotnet-bot Oct 13, 2021
4b4b25a
Merge in 'release/6.0' changes
dotnet-bot Oct 13, 2021
941138f
Merge in 'release/6.0' changes
dotnet-bot Oct 13, 2021
8b108cc
Merge in 'release/6.0' changes
dotnet-bot Oct 13, 2021
444a2f9
Merge in 'release/6.0' changes
dotnet-bot Oct 13, 2021
b90e90e
Merge in 'release/6.0' changes
dotnet-bot Oct 13, 2021
f18e25a
Merge in 'release/6.0' changes
dotnet-bot Oct 14, 2021
3d0240a
Merge in 'release/6.0' changes
dotnet-bot Oct 14, 2021
d2a3799
Merge in 'release/6.0' changes
dotnet-bot Oct 15, 2021
9742658
Merge in 'release/6.0' changes
dotnet-bot Oct 15, 2021
4e21fe7
Merge in 'release/6.0' changes
dotnet-bot Oct 15, 2021
3e360c6
Merge in 'release/6.0' changes
dotnet-bot Oct 15, 2021
977d779
Merge in 'release/6.0' changes
dotnet-bot Oct 16, 2021
101b60e
Merge in 'release/6.0' changes
dotnet-bot Oct 18, 2021
7470597
Merge in 'release/6.0' changes
dotnet-bot Oct 18, 2021
7666b54
Merge in 'release/6.0' changes
dotnet-bot Oct 18, 2021
883e484
Merge in 'release/6.0' changes
dotnet-bot Oct 18, 2021
7d0568b
Merge in 'release/6.0' changes
dotnet-bot Oct 18, 2021
947486c
Merge in 'release/6.0' changes
dotnet-bot Oct 18, 2021
c1b23d4
Merge in 'release/6.0' changes
dotnet-bot Oct 19, 2021
4d229bf
Merge in 'release/6.0' changes
dotnet-bot Oct 19, 2021
8daced2
Merge in 'release/6.0' changes
dotnet-bot Oct 19, 2021
016b381
Merge in 'release/6.0' changes
dotnet-bot Oct 19, 2021
1acd487
Merge in 'release/6.0' changes
dotnet-bot Oct 19, 2021
18cec8b
Merge in 'release/6.0' changes
dotnet-bot Oct 19, 2021
467c326
Merge in 'release/6.0' changes
dotnet-bot Oct 20, 2021
e638db9
Merge in 'release/6.0' changes
dotnet-bot Oct 20, 2021
8470979
Merge in 'release/6.0' changes
dotnet-bot Oct 23, 2021
8a8769c
Merge in 'release/6.0' changes
dotnet-bot Nov 9, 2021
f3b00d8
Merge in 'release/6.0' changes
dotnet-bot Nov 9, 2021
a023d00
Merge in 'release/6.0' changes
dotnet-bot Nov 9, 2021
3eaa3b5
Merge in 'release/6.0' changes
dotnet-bot Nov 9, 2021
0fc8e74
Merge in 'release/6.0' changes
dotnet-bot Nov 10, 2021
f851930
Merge in 'release/6.0' changes
dotnet-bot Nov 10, 2021
279e896
Merge in 'release/6.0' changes
dotnet-bot Nov 10, 2021
d774aef
Merge in 'release/6.0' changes
dotnet-bot Nov 11, 2021
66ccfaf
Merge in 'release/6.0' changes
dotnet-bot Nov 11, 2021
a0175b4
Merge in 'release/6.0' changes
dotnet-bot Nov 11, 2021
2d92b8b
Merge in 'release/6.0' changes
dotnet-bot Nov 11, 2021
76890f9
Merge in 'release/6.0' changes
dotnet-bot Nov 11, 2021
165bb6b
Merge in 'release/6.0' changes
dotnet-bot Nov 12, 2021
2022b39
Merge in 'release/6.0' changes
dotnet-bot Nov 12, 2021
a6124ae
Merge in 'release/6.0' changes
dotnet-bot Nov 12, 2021
6de4589
Merge in 'release/6.0' changes
dotnet-bot Nov 12, 2021
357c80a
Merge in 'release/6.0' changes
dotnet-bot Nov 15, 2021
f130d26
Merge in 'release/6.0' changes
dotnet-bot Nov 15, 2021
f9d02c2
Merge in 'release/6.0' changes
dotnet-bot Nov 15, 2021
7280473
Merge in 'release/6.0' changes
dotnet-bot Nov 16, 2021
5b7875a
Merge in 'release/6.0' changes
dotnet-bot Nov 16, 2021
32a62c9
Merge in 'release/6.0' changes
dotnet-bot Nov 16, 2021
f35d5b0
Merge in 'release/6.0' changes
dotnet-bot Nov 17, 2021
479322e
Merge in 'release/6.0' changes
dotnet-bot Nov 17, 2021
756a3c0
Merge remote-tracking branch 'upstream/release/6.0' into internal/rel…
mmitche Nov 17, 2021
bfdc5e9
Merge branch 'internal/release/6.0' of https://dev.azure.com/dnceng/i…
mmitche Nov 17, 2021
3a25a7f
Merge in 'release/6.0' changes
dotnet-bot Nov 17, 2021
17fcde6
Merge commit '3a25a7f1cc446b60678ed25c9d829420d6321eba' into internal…
vseanreesermsft Dec 14, 2021
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
Next Next commit
Merged PR 17575: [Release 6.0] Fix StartTLS in DirectoryService.Proto…
…cols in 6.0 and backport changes from 5.0 release.

Supersedes https://dev.azure.com/dnceng/internal/_git/dotnet-runtime/pullrequest/17428 for release/6.0 branch.
  • Loading branch information
joperezr authored and mmitche committed Sep 14, 2021
commit 94482bbb689f0625488acaf45d506637b7a27834
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,9 @@ static Ldap()
[DllImport(Libraries.OpenLdap, EntryPoint = "ldap_set_option", CharSet = CharSet.Ansi)]
public static extern int ldap_set_option_referral([In] ConnectionHandle ldapHandle, [In] LdapOption option, ref LdapReferralCallback outValue);

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

[DllImport(Libraries.OpenLdap, EntryPoint = "ldap_parse_result", CharSet = CharSet.Ansi)]
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@
<Compile Include="System\DirectoryServices\Protocols\Interop\BerPal.Linux.cs" />
<Compile Include="System\DirectoryServices\Protocols\ldap\LdapConnection.Linux.cs" />
<Compile Include="System\DirectoryServices\Protocols\ldap\LdapSessionOptions.Linux.cs" />
<Compile Include="System\DirectoryServices\Protocols\ldap\LocalAppContextSwitches.cs" />
<Compile Include="System\DirectoryServices\Protocols\Interop\SafeHandles.Linux.cs" />
<Compile Include="$(CommonPath)System\LocalAppContextSwitches.Common.cs">
<Link>Common\System\LocalAppContextSwitches.Common.cs</Link>
</Compile>
<Compile Include="$(CommonPath)Interop\Linux\OpenLdap\Interop.Ldap.cs">
<Link>Common\Interop\Linux\OpenLdap\Interop.Ldap.cs</Link>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,31 @@ internal static int BindToDirectory(ConnectionHandle ld, string who, string pass
}
}

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);
internal static int StartTls(ConnectionHandle ldapHandle, ref int serverReturnValue, ref IntPtr message, IntPtr serverControls, IntPtr clientControls)
{
// Windows and Linux have different signatures for ldap_start_tls_s.
// On Linux, we don't have a serverReturnValue or the message/result parameter.
//
// So in the PAL here, just emulate.

int error = Interop.Ldap.ldap_start_tls(ldapHandle, serverControls, clientControls);

// On Windows, serverReturnValue only has meaning if the result code is LDAP_OTHER.
// If OpenLDAP returns that, we don't have a better code, so assign that through.
// If we get any other error, assign serverReturnValue to 0 since it shouldn't be read.
if (error == (int)ResultCode.Other)
{
serverReturnValue = error;
}
else
{
serverReturnValue = 0;
}

// We don't have a referrer/message/result value, so just set it to NULL.
message = IntPtr.Zero;
return error;
}

// openldap doesn't have a ldap_stop_tls function. Returning true as no-op for Linux.
internal static byte StopTls(ConnectionHandle ldapHandle) => 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ public ConnectionHandle()
_needDispose = true;
}

internal ConnectionHandle(string uri)
:base(true)
{
Interop.Ldap.ldap_initialize(out handle, uri);
_needDispose = true;
}

internal ConnectionHandle(IntPtr value, bool disposeHandle) : base(true)
{
_needDispose = disposeHandle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private void InternalInitConnectionHandle(string hostname)
throw new NullReferenceException();
}

_ldapHandle = new ConnectionHandle();
_ldapHandle = new ConnectionHandle($"ldap://{hostname}:{((LdapDirectoryIdentifier)_directoryIdentifier).PortNumber}");
}

private int InternalConnectToServer()
Expand Down Expand Up @@ -79,13 +79,39 @@ private int InternalConnectToServer()
private int InternalBind(NetworkCredential tempCredential, SEC_WINNT_AUTH_IDENTITY_EX cred, BindMethod method)
{
int error;
if (tempCredential == null && (AuthType == AuthType.External || AuthType == AuthType.Kerberos))

if (LocalAppContextSwitches.UseBasicAuthFallback)
{
error = BindSasl();
if (tempCredential == null && (AuthType == AuthType.External || AuthType == AuthType.Kerberos))
{
error = BindSasl();
}
else
{
error = LdapPal.BindToDirectory(_ldapHandle, cred.user, cred.password);
}
}
else
{
error = LdapPal.BindToDirectory(_ldapHandle, cred.user, cred.password);
if (method == BindMethod.LDAP_AUTH_NEGOTIATE)
{
if (tempCredential == null)
{
error = BindSasl();
}
else
{
// Explicit credentials were provided. If we call ldap_bind_s it will
// return LDAP_NOT_SUPPORTED, so just skip the P/Invoke.
error = (int)LdapError.NotSupported;
}
}
else
{
// Basic and Anonymous are handled elsewhere.
Debug.Assert(AuthType != AuthType.Anonymous && AuthType != AuthType.Basic);
error = (int)LdapError.AuthUnknown;
}
}

return error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -641,11 +641,14 @@ public unsafe void StartTransportLayerSecurity(DirectoryControlCollection contro
response.ResponseName = "1.3.6.1.4.1.1466.20037";
throw new TlsOperationException(response);
}
else if (LdapErrorMappings.IsLdapError(error))

if (LdapErrorMappings.IsLdapError(error))
{
string errorMessage = LdapErrorMappings.MapResultCode(error);
throw new LdapException(error, errorMessage);
}

throw new LdapException(error);
}
}
finally
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.CompilerServices;

namespace System
{
internal static partial class LocalAppContextSwitches
{
private static int s_useBasicAuthFallback;

public static bool UseBasicAuthFallback
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => GetCachedSwitchValue("System.DirectoryServices.Protocols.UseBasicAuthFallback", ref s_useBasicAuthFallback);
}
}
}