diff --git a/eng/liveBuilds.targets b/eng/liveBuilds.targets
index 5b72dedeb1a3b..5dd04a62316a6 100644
--- a/eng/liveBuilds.targets
+++ b/eng/liveBuilds.targets
@@ -155,7 +155,7 @@
$(LibrariesAllBinArtifactsPath)*.pdb"
IsNative="" />
+ Include="$(LibrariesNativeArtifactsPath)libSystem.IO.Ports.Native.*;$(LibrariesNativeArtifactsPath)*System.DirectoryServices.Native.*" />
+
+#ifdef _WIN32
+FUNCTIONEXPORT ULONG FUNCTIONCALLINGCONVENCTION ber_scanf(BerElement* ber, char* fmt, ...);
+FUNCTIONEXPORT INT FUNCTIONCALLINGCONVENCTION ber_printf(BerElement* ber, char* fmt, ...);
+#else
+FUNCTIONEXPORT long FUNCTIONCALLINGCONVENCTION ber_scanf(BerElement* ber, const char* fmt, ...);
+FUNCTIONEXPORT int FUNCTIONCALLINGCONVENCTION ber_printf(BerElement* ber, const char* fmt, ...);
+#endif
+
+FUNCTIONEXPORT int FUNCTIONCALLINGCONVENCTION ber_scanf_proxy(BerElement *ber, char *fmt)
+{
+ return (int)ber_scanf(ber, fmt);
+}
+
+FUNCTIONEXPORT int FUNCTIONCALLINGCONVENCTION ber_scanf_proxy_int(BerElement *ber, char *fmt, int* value)
+{
+ return (int)ber_scanf(ber, fmt, value);
+}
+
+FUNCTIONEXPORT int FUNCTIONCALLINGCONVENCTION ber_scanf_proxy_bitstring(BerElement *ber, char *fmt, int** value, int* bitLength)
+{
+ return (int)ber_scanf(ber, fmt, value, bitLength);
+}
+
+FUNCTIONEXPORT int FUNCTIONCALLINGCONVENCTION ber_scanf_proxy_ptr(BerElement *ber, char *fmt, int** value)
+{
+ return (int)ber_scanf(ber, fmt, value);
+}
+
+FUNCTIONEXPORT int FUNCTIONCALLINGCONVENCTION ber_printf_proxy_emptyarg(BerElement *ber, char *fmt)
+{
+ return ber_printf(ber, fmt);
+}
+
+FUNCTIONEXPORT int FUNCTIONCALLINGCONVENCTION ber_printf_proxy_int(BerElement *ber, char *fmt, int value)
+{
+ return ber_printf(ber, fmt, value);
+}
+
+FUNCTIONEXPORT int FUNCTIONCALLINGCONVENCTION ber_printf_proxy_bytearray(BerElement *ber, char *fmt, int* value, int length)
+{
+ return ber_printf(ber, fmt, value, length);
+}
+
+FUNCTIONEXPORT int FUNCTIONCALLINGCONVENCTION ber_printf_proxy_berarray(BerElement *ber, char *fmt, int* value)
+{
+ return ber_printf(ber, fmt, value);
+}
diff --git a/src/libraries/Native/AnyOS/System.DirectoryServices.Native/LdapProxyForVarArgs.h b/src/libraries/Native/AnyOS/System.DirectoryServices.Native/LdapProxyForVarArgs.h
new file mode 100644
index 0000000000000..ac0387fbcafe0
--- /dev/null
+++ b/src/libraries/Native/AnyOS/System.DirectoryServices.Native/LdapProxyForVarArgs.h
@@ -0,0 +1,34 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+#pragma once
+
+#ifdef _WIN32
+ #include
+ #include
+ #define FUNCTIONEXPORT extern
+ #define FUNCTIONCALLINGCONVENCTION __cdecl
+#else
+ #include "pal_types.h"
+ #include "pal_compiler.h"
+ #define FUNCTIONEXPORT PALEXPORT
+ #define FUNCTIONCALLINGCONVENCTION
+#endif
+
+typedef struct BerElementStruct BerElement;
+
+FUNCTIONEXPORT int FUNCTIONCALLINGCONVENCTION ber_scanf_proxy(BerElement* ber, char *fmt);
+
+FUNCTIONEXPORT int FUNCTIONCALLINGCONVENCTION ber_scanf_proxy_int(BerElement *ber, char *fmt, int* value);
+
+FUNCTIONEXPORT int FUNCTIONCALLINGCONVENCTION ber_scanf_proxy_bitstring(BerElement *ber, char *fmt, int** value, int* bitLength);
+
+FUNCTIONEXPORT int FUNCTIONCALLINGCONVENCTION ber_scanf_proxy_ptr(BerElement *ber, char *fmt, int** value);
+
+FUNCTIONEXPORT int FUNCTIONCALLINGCONVENCTION ber_printf_proxy_emptyarg(BerElement *ber, char *fmt);
+
+FUNCTIONEXPORT int FUNCTIONCALLINGCONVENCTION ber_printf_proxy_int(BerElement *ber, char *fmt, int value);
+
+FUNCTIONEXPORT int FUNCTIONCALLINGCONVENCTION ber_printf_proxy_bytearray(BerElement *ber, char *fmt, int* value, int length);
+
+FUNCTIONEXPORT int FUNCTIONCALLINGCONVENCTION ber_printf_proxy_berarray(BerElement *ber, char *fmt, int* value);
diff --git a/src/libraries/Native/Unix/CMakeLists.txt b/src/libraries/Native/Unix/CMakeLists.txt
index f47135fd8871c..0325c1f7c326d 100644
--- a/src/libraries/Native/Unix/CMakeLists.txt
+++ b/src/libraries/Native/Unix/CMakeLists.txt
@@ -260,6 +260,7 @@ else()
add_subdirectory(System.Globalization.Native)
add_subdirectory(System.Net.Security.Native)
add_subdirectory(System.Security.Cryptography.Native)
+ add_subdirectory(System.DirectoryServices.Native)
endif()
if(CLR_CMAKE_TARGET_OSX OR CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS)
diff --git a/src/libraries/Native/Unix/System.DirectoryServices.Native/CMakeLists.txt b/src/libraries/Native/Unix/System.DirectoryServices.Native/CMakeLists.txt
new file mode 100644
index 0000000000000..0cd353cb3db51
--- /dev/null
+++ b/src/libraries/Native/Unix/System.DirectoryServices.Native/CMakeLists.txt
@@ -0,0 +1,37 @@
+project(System.DirectoryServices.Native C)
+
+set (NATIVEPROTOCOLS_SOURCES
+ ../../AnyOS/System.DirectoryServices.Native/LdapProxyForVarArgs.c
+)
+
+if(CLR_CMAKE_TARGET_OSX)
+ # Workaround for "'ber_scanf' is deprecated: first deprecated in macOS 10.11 - use OpenDirectory Framework".
+ add_compile_options(-Wno-deprecated-declarations)
+endif()
+
+if (GEN_SHARED_LIB)
+
+ add_library(System.DirectoryServices.Native
+ SHARED
+ ${NATIVEPROTOCOLS_SOURCES}
+ ${VERSION_FILE_PATH}
+ )
+
+ find_library(LIBLDAP NAMES ldap libldap.dylib libldap-2.4.so.2)
+ if(LIBLDAP STREQUAL LIBLDAP-NOTFOUND)
+ message(FATAL_ERROR "Cannot find OpenLdap")
+ else()
+ message(STATUS "OpenLdap found as ${LIBLDAP}")
+ endif()
+
+ target_link_libraries(System.DirectoryServices.Native ${LIBLDAP})
+
+ install_with_stripped_symbols (System.DirectoryServices.Native PROGRAMS .)
+endif ()
+
+add_library(System.DirectoryServices.Native-Static
+ STATIC
+ ${NATIVEPROTOCOLS_SOURCES}
+)
+
+install (TARGETS System.IO.Ports.Native-Static DESTINATION ${STATIC_LIB_DESTINATION} COMPONENT libs)
diff --git a/src/libraries/Native/Windows/CMakeLists.txt b/src/libraries/Native/Windows/CMakeLists.txt
index b9b6c823d0b49..eb1b390ae31dc 100644
--- a/src/libraries/Native/Windows/CMakeLists.txt
+++ b/src/libraries/Native/Windows/CMakeLists.txt
@@ -124,3 +124,4 @@ if(STATIC_LIBS_ONLY)
endif()
add_subdirectory(System.IO.Compression.Native)
+add_subdirectory(System.DirectoryServices.Native)
diff --git a/src/libraries/Native/Windows/System.DirectoryServices.Native/CMakeLists.txt b/src/libraries/Native/Windows/System.DirectoryServices.Native/CMakeLists.txt
new file mode 100644
index 0000000000000..0bedd50f0d1e8
--- /dev/null
+++ b/src/libraries/Native/Windows/System.DirectoryServices.Native/CMakeLists.txt
@@ -0,0 +1,59 @@
+project(System.DirectoryServices.Native)
+
+if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
+ message(FATAL_ERROR "Binary directory isn't being correctly set before calling Cmake. Tree must be built in separate directory from source.")
+endif()
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+if (GEN_SHARED_LIB)
+ include (GenerateExportHeader)
+endif()
+
+set (NATIVEPROTOCOLS_SOURCES
+ ../../AnyOS/System.DirectoryServices.Native/LdapProxyForVarArgs.c
+)
+
+if (GEN_SHARED_LIB)
+ add_library(System.DirectoryServices.Native
+ SHARED
+ ${NATIVEPROTOCOLS_SOURCES}
+ System.DirectoryServices.Native.def
+ # This will add versioning to the library
+ ${CMAKE_REPO_ROOT}/artifacts/obj/NativeVersion.rc
+ )
+
+endif()
+
+list(APPEND __LinkLibraries Wldap32.dll)
+
+add_library(System.DirectoryServices.Native-Static
+ STATIC
+ ${NATIVEPROTOCOLS_SOURCES}
+)
+
+# Allow specification of arguments that should be passed to the linker
+if (GEN_SHARED_LIB)
+ SET_TARGET_PROPERTIES(System.DirectoryServices.Native PROPERTIES LINK_OPTIONS "${__LinkArgs};${__SharedLinkArgs}")
+endif()
+SET_TARGET_PROPERTIES(System.DirectoryServices.Native-Static PROPERTIES STATIC_LIBRARY_OPTIONS "${__LinkArgs}")
+
+# Allow specification of libraries that should be linked against
+if (GEN_SHARED_LIB)
+ target_link_libraries(System.DirectoryServices.Native ${__LinkLibraries})
+endif()
+target_link_libraries(System.DirectoryServices.Native-Static ${__LinkLibraries})
+
+if (GEN_SHARED_LIB)
+ GENERATE_EXPORT_HEADER( System.DirectoryServices.Native
+ BASE_NAME System.DirectoryServices.Native
+ EXPORT_MACRO_NAME System.DirectoryServices.Native_EXPORT
+ EXPORT_FILE_NAME System.DirectoryServices.Native_Export.h
+ STATIC_DEFINE System.DirectoryServices.Native_BUILT_AS_STATIC
+ )
+
+ install (TARGETS System.DirectoryServices.Native DESTINATION .)
+ install (FILES $ DESTINATION .)
+endif()
+
+install (TARGETS System.DirectoryServices.Native-Static DESTINATION ${STATIC_LIB_DESTINATION})
diff --git a/src/libraries/Native/Windows/System.DirectoryServices.Native/System.DirectoryServices.Native.def b/src/libraries/Native/Windows/System.DirectoryServices.Native/System.DirectoryServices.Native.def
new file mode 100644
index 0000000000000..477ab83099edc
--- /dev/null
+++ b/src/libraries/Native/Windows/System.DirectoryServices.Native/System.DirectoryServices.Native.def
@@ -0,0 +1,11 @@
+LIBRARY System.DirectoryServices.Native.dll
+
+EXPORTS
+ ber_scanf_proxy
+ ber_scanf_proxy_int
+ ber_scanf_proxy_bitstring
+ ber_scanf_proxy_ptr
+ ber_printf_proxy_emptyarg
+ ber_printf_proxy_int
+ ber_printf_proxy_bytearray
+ ber_printf_proxy_berarray
diff --git a/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/Interop/BerPal.Linux.cs b/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/Interop/BerPal.Linux.cs
index b8856cf2d2bda..17914d569b0ed 100644
--- a/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/Interop/BerPal.Linux.cs
+++ b/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/Interop/BerPal.Linux.cs
@@ -13,21 +13,21 @@ internal static class BerPal
internal static int FlattenBerElement(SafeBerHandle berElement, ref IntPtr flattenptr) => Interop.Ldap.ber_flatten(berElement, ref flattenptr);
- internal static int PrintBerArray(SafeBerHandle berElement, string format, IntPtr value) => Interop.Ldap.ber_printf_berarray(berElement, format, value);
+ internal static int PrintBerArray(SafeBerHandle berElement, string format, IntPtr value) => Interop.Ldap.ber_printf_proxy_berarray(berElement, format, value);
- internal static int PrintByteArray(SafeBerHandle berElement, string format, HGlobalMemHandle value, int length) => Interop.Ldap.ber_printf_bytearray(berElement, format, value, length);
+ internal static int PrintByteArray(SafeBerHandle berElement, string format, HGlobalMemHandle value, int length) => Interop.Ldap.ber_printf_proxy_bytearray(berElement, format, value, length);
- internal static int PrintEmptyArgument(SafeBerHandle berElement, string format) => Interop.Ldap.ber_printf_emptyarg(berElement, format);
+ internal static int PrintEmptyArgument(SafeBerHandle berElement, string format) => Interop.Ldap.ber_printf_proxy_emptyarg(berElement, format);
- internal static int PrintInt(SafeBerHandle berElement, string format, int value) => Interop.Ldap.ber_printf_int(berElement, format, value);
+ internal static int PrintInt(SafeBerHandle berElement, string format, int value) => Interop.Ldap.ber_printf_proxy_int(berElement, format, value);
- internal static int ScanNext(SafeBerHandle berElement, string format) => Interop.Ldap.ber_scanf(berElement, format);
+ internal static int ScanNext(SafeBerHandle berElement, string format) => Interop.Ldap.ber_scanf_proxy(berElement, format);
- internal static int ScanNextBitString(SafeBerHandle berElement, string format, ref IntPtr ptrResult, ref int bitLength) => Interop.Ldap.ber_scanf_bitstring(berElement, format, ref ptrResult, ref bitLength);
+ internal static int ScanNextBitString(SafeBerHandle berElement, string format, ref IntPtr ptrResult, ref int bitLength) => Interop.Ldap.ber_scanf_proxy_bitstring(berElement, format, ref ptrResult, ref bitLength);
- internal static int ScanNextInt(SafeBerHandle berElement, string format, ref int result) => Interop.Ldap.ber_scanf_int(berElement, format, ref result);
+ internal static int ScanNextInt(SafeBerHandle berElement, string format, ref int result) => Interop.Ldap.ber_scanf_proxy_int(berElement, format, ref result);
- internal static int ScanNextPtr(SafeBerHandle berElement, string format, ref IntPtr value) => Interop.Ldap.ber_scanf_ptr(berElement, format, ref value);
+ internal static int ScanNextPtr(SafeBerHandle berElement, string format, ref IntPtr value) => Interop.Ldap.ber_scanf_proxy_ptr(berElement, format, ref value);
internal static bool IsBerDecodeError(int errorCode) => errorCode == -1;
}
diff --git a/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/Interop/BerPal.Windows.cs b/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/Interop/BerPal.Windows.cs
index 202737f2cb281..7624db3cce5af 100644
--- a/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/Interop/BerPal.Windows.cs
+++ b/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/Interop/BerPal.Windows.cs
@@ -15,21 +15,21 @@ internal static class BerPal
internal static int FlattenBerElement(SafeBerHandle berElement, ref IntPtr flattenptr) => Interop.Ldap.ber_flatten(berElement, ref flattenptr);
- internal static int PrintBerArray(SafeBerHandle berElement, string format, IntPtr value) => Interop.Ldap.ber_printf_berarray(berElement, format, value);
+ internal static int PrintBerArray(SafeBerHandle berElement, string format, IntPtr value) => Interop.Ldap.ber_printf_proxy_berarray(berElement, format, value);
- internal static int PrintByteArray(SafeBerHandle berElement, string format, HGlobalMemHandle value, int length) => Interop.Ldap.ber_printf_bytearray(berElement, format, value, length);
+ internal static int PrintByteArray(SafeBerHandle berElement, string format, HGlobalMemHandle value, int length) => Interop.Ldap.ber_printf_proxy_bytearray(berElement, format, value, length);
- internal static int PrintEmptyArgument(SafeBerHandle berElement, string format) => Interop.Ldap.ber_printf_emptyarg(berElement, format);
+ internal static int PrintEmptyArgument(SafeBerHandle berElement, string format) => Interop.Ldap.ber_printf_proxy_emptyarg(berElement, format);
- internal static int PrintInt(SafeBerHandle berElement, string format, int value) => Interop.Ldap.ber_printf_int(berElement, format, value);
+ internal static int PrintInt(SafeBerHandle berElement, string format, int value) => Interop.Ldap.ber_printf_proxy_int(berElement, format, value);
- internal static int ScanNext(SafeBerHandle berElement, string format) => Interop.Ldap.ber_scanf(berElement, format);
+ internal static int ScanNext(SafeBerHandle berElement, string format) => Interop.Ldap.ber_scanf_proxy(berElement, format);
- internal static int ScanNextBitString(SafeBerHandle berElement, string format, ref IntPtr ptrResult, ref int bitLength) => Interop.Ldap.ber_scanf_bitstring(berElement, format, ref ptrResult, ref bitLength);
+ internal static int ScanNextBitString(SafeBerHandle berElement, string format, ref IntPtr ptrResult, ref int bitLength) => Interop.Ldap.ber_scanf_proxy_bitstring(berElement, format, ref ptrResult, ref bitLength);
- internal static int ScanNextInt(SafeBerHandle berElement, string format, ref int result) => Interop.Ldap.ber_scanf_int(berElement, format, ref result);
+ internal static int ScanNextInt(SafeBerHandle berElement, string format, ref int result) => Interop.Ldap.ber_scanf_proxy_int(berElement, format, ref result);
- internal static int ScanNextPtr(SafeBerHandle berElement, string format, ref IntPtr value) => Interop.Ldap.ber_scanf_ptr(berElement, format, ref value);
+ internal static int ScanNextPtr(SafeBerHandle berElement, string format, ref IntPtr value) => Interop.Ldap.ber_scanf_proxy_ptr(berElement, format, ref value);
internal static bool IsBerDecodeError(int errorCode) => errorCode != 0;
}
diff --git a/src/libraries/System.DirectoryServices.Protocols/tests/AsqRequestControlTests.cs b/src/libraries/System.DirectoryServices.Protocols/tests/AsqRequestControlTests.cs
index 6391870ef11aa..d2704307152d5 100644
--- a/src/libraries/System.DirectoryServices.Protocols/tests/AsqRequestControlTests.cs
+++ b/src/libraries/System.DirectoryServices.Protocols/tests/AsqRequestControlTests.cs
@@ -8,7 +8,6 @@
namespace System.DirectoryServices.Protocols.Tests
{
[ConditionalClass(typeof(DirectoryServicesTestHelpers), nameof(DirectoryServicesTestHelpers.IsWindowsOrLibLdapIsInstalled))]
- [ActiveIssue("https://github.com/dotnet/runtime/issues/49105", typeof(PlatformDetection), nameof(PlatformDetection.IsMacOsAppleSilicon))]
public class AsqRequestControlTests
{
[Fact]
diff --git a/src/libraries/System.DirectoryServices.Protocols/tests/BerConversionExceptionTests.cs b/src/libraries/System.DirectoryServices.Protocols/tests/BerConversionExceptionTests.cs
index 4a474ec57eae1..b0a47bad6fe64 100644
--- a/src/libraries/System.DirectoryServices.Protocols/tests/BerConversionExceptionTests.cs
+++ b/src/libraries/System.DirectoryServices.Protocols/tests/BerConversionExceptionTests.cs
@@ -9,7 +9,6 @@
namespace System.DirectoryServices.Protocols.Tests
{
- [ActiveIssue("https://github.com/dotnet/runtime/issues/49105", typeof(PlatformDetection), nameof(PlatformDetection.IsMacOsAppleSilicon))]
public class BerConversionExceptionTests
{
[Fact]
diff --git a/src/libraries/System.DirectoryServices.Protocols/tests/BerConverterTests.cs b/src/libraries/System.DirectoryServices.Protocols/tests/BerConverterTests.cs
index d636a88989881..d47ecba69a09c 100644
--- a/src/libraries/System.DirectoryServices.Protocols/tests/BerConverterTests.cs
+++ b/src/libraries/System.DirectoryServices.Protocols/tests/BerConverterTests.cs
@@ -9,7 +9,6 @@
namespace System.DirectoryServices.Protocols.Tests
{
[ConditionalClass(typeof(DirectoryServicesTestHelpers), nameof(DirectoryServicesTestHelpers.IsWindowsOrLibLdapIsInstalled))]
- [ActiveIssue("https://github.com/dotnet/runtime/issues/49105", typeof(PlatformDetection), nameof(PlatformDetection.IsMacOsAppleSilicon))]
public class BerConverterTests
{
public static IEnumerable