Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion src/libraries/Common/src/Interop/Interop.Ldap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ internal enum LdapOption
LDAP_OPT_X_TLS_NEWCTX = 0x600F, // Not Supported in Windows
LDAP_OPT_X_SASL_REALM = 0x6101,
LDAP_OPT_X_SASL_AUTHCID = 0x6102,
LDAP_OPT_X_SASL_AUTHZID = 0x6103
LDAP_OPT_X_SASL_AUTHZID = 0x6103,
LDAP_OPT_X_SASL_NOCANON = 0x610b,
}

internal enum ResultAll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public static partial int ldap_search(
ref int messageNumber);

[LibraryImport(Libraries.OpenLdap, EntryPoint = "ldap_set_option", SetLastError = true)]
public static partial int ldap_set_option_bool(ConnectionHandle ld, LdapOption option, [MarshalAs(UnmanagedType.Bool)] bool value);
public static partial int ldap_set_option_bool(ConnectionHandle ld, LdapOption option, IntPtr value);

[LibraryImport(Libraries.OpenLdap, EntryPoint = "ldap_set_option")]
public static partial int ldap_set_option_clientcert(ConnectionHandle ldapHandle, LdapOption option, QUERYCLIENTCERT outValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,9 @@ public partial class LdapSessionOptions
{
internal LdapSessionOptions() { }
public bool AutoReconnect { get { throw null; } set { } }
#if NET
public bool CanonicalizeHostName { get { throw null; } [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("windows")] set { } }
#endif
public string DomainName { get { throw null; } set { } }
#if NET
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("windows")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ internal static int SearchDirectory(ConnectionHandle ldapHandle, string dn, int

return Interop.Ldap.ldap_search(ldapHandle, dn, scope, filter, attributes, attributeOnly, servercontrol, clientcontrol, searchTimeout, sizelimit, ref messageNumber);
}
internal static int SetBoolOption(ConnectionHandle ld, LdapOption option, bool value) => Interop.Ldap.ldap_set_option_bool(ld, option, value);
internal static int SetBoolOption(ConnectionHandle ld, LdapOption option, bool value) => Interop.Ldap.ldap_set_option_bool(ld, option, value ? (IntPtr)1 : IntPtr.Zero);

// This option is not supported in Linux, so it would most likely throw.
internal static int SetClientCertOption(ConnectionHandle ldapHandle, LdapOption option, QUERYCLIENTCERT outValue) => Interop.Ldap.ldap_set_option_clientcert(ldapHandle, option, outValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ public partial class LdapSessionOptions

private bool _secureSocketLayer;

public bool CanonicalizeHostName
{
get => !GetBoolValueHelper(LdapOption.LDAP_OPT_X_SASL_NOCANON);
[UnsupportedOSPlatform("windows")]
set => SetBoolValueHelper(LdapOption.LDAP_OPT_X_SASL_NOCANON, !value);
}

/// <summary>
/// Specifies the path of the directory containing CA certificates in the PEM format.
/// Multiple directories may be specified by separating with a semi-colon.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ public partial class LdapSessionOptions
{
private static void PALCertFreeCRLContext(IntPtr certPtr) => Interop.Ldap.CertFreeCRLContext(certPtr);

public bool CanonicalizeHostName
{
get => true;
[UnsupportedOSPlatform("windows")]
set => throw new PlatformNotSupportedException();
}

[UnsupportedOSPlatform("windows")]
public string TrustedCertificatesDirectory
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,33 @@ public void CertificateDirectoryProperty_ThrowsPlatformNotSupportedException()
Assert.Throws<PlatformNotSupportedException>(() => options.TrustedCertificatesDirectory = "CertificateDirectory");
}
}

[Fact]
[PlatformSpecific(TestPlatforms.Windows)]
public void CanonicalizeHostName_GetReturnsTrue_SetThrowsPlatformNotSupportedException()
{
using (var connection = new LdapConnection("server"))
{
LdapSessionOptions options = connection.SessionOptions;
Assert.True(options.CanonicalizeHostName);
Assert.Throws<PlatformNotSupportedException>(() => options.CanonicalizeHostName = false);
}
}

[Fact]
[PlatformSpecific(TestPlatforms.Linux)]
public void CanonicalizeHostName_GetSet_ReturnsExpected()
{
using (var connection = new LdapConnection("server"))
{
LdapSessionOptions options = connection.SessionOptions;
Assert.True(options.CanonicalizeHostName);
options.CanonicalizeHostName = false;
Assert.False(options.CanonicalizeHostName);
options.CanonicalizeHostName = true;
Assert.True(options.CanonicalizeHostName);
}
}
#endif
}
}
Loading