Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When loading libldap try libldap.so.2 first #111553

Merged
merged 1 commit into from
Jan 22, 2025
Merged
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
4 changes: 3 additions & 1 deletion src/libraries/Common/src/Interop/Linux/Interop.Libraries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ internal static partial class Libraries
// Duplicated from Android for Linux Bionic
internal const string Liblog = "liblog";

internal const string OpenLdap = "libldap-2.5.so.0";
// As a convention, some ldap installs use this to reference the latest version.
internal const string OpenLdap = "libldap.so.2";

internal const string MsQuic = "libmsquic.so";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,18 @@ static Ldap()
{
Assembly currentAssembly = typeof(Ldap).Assembly;

// Register callback that tries to load other libraries when the default library "libldap-2.5.so.0" not found
// Register callback that tries to load other libraries when the default library "libldap.so.2" is not found.
// It is a convention to create the symbolic link "libldap.so.2" to point to a versioned library but not all distros do that.
AssemblyLoadContext.GetLoadContext(currentAssembly).ResolvingUnmanagedDll += (assembly, ldapName) =>
{
if (assembly != currentAssembly || ldapName != Libraries.OpenLdap)
{
return IntPtr.Zero;
}

// Try load next (libldap-2.6.so.0) or previous (libldap-2.4.so.2) versions
// Try versioned libraries.
if (NativeLibrary.TryLoad("libldap-2.6.so.0", out IntPtr handle) ||
NativeLibrary.TryLoad("libldap-2.5.so.0", out handle) ||
NativeLibrary.TryLoad("libldap-2.4.so.2", out handle))
{
return handle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ To enable the tests marked with [ConditionalFact(nameof(IsLdapConfigurationExist

To ship, we should test on both an Active Directory LDAP server, and at least one other server, as behaviors are a little different. However for local testing, it is easiest to connect to an OpenDJ LDAP server in a docker container (eg., in WSL2).

When testing with later of versions of LDAP, the ldapsearch commands below may need to use

-H ldap://localhost:<PORT>

instead of

-h localhost -p <PORT>

OPENDJ SERVER
=============

Expand Down
Loading