From 3215d25965d9b27c267d201ad95450c2bc570283 Mon Sep 17 00:00:00 2001 From: Sergey Date: Wed, 31 Mar 2021 19:28:28 -0700 Subject: [PATCH 1/5] Reenable the tests. --- .../tests/AsqRequestControlTests.cs | 1 - .../tests/BerConversionExceptionTests.cs | 1 - .../tests/BerConverterTests.cs | 1 - .../tests/DirSyncRequestControlTests.cs | 1 - .../tests/DirectoryControlTests.cs | 1 - .../tests/DirectoryServicesProtocolsTests.cs | 1 - .../tests/ExtendedDNControlTests.cs | 1 - .../tests/PageResultRequestControlTests.cs | 1 - .../tests/QuotaControlTests.cs | 1 - .../tests/SearchOptionsControlTests.cs | 1 - .../tests/SecurityDescriptorFlagControlTests.cs | 1 - .../tests/VerifyNameControlTests.cs | 1 - .../tests/VlvRequestControlTests.cs | 1 - 13 files changed, 13 deletions(-) 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 Encode_TestData() diff --git a/src/libraries/System.DirectoryServices.Protocols/tests/DirSyncRequestControlTests.cs b/src/libraries/System.DirectoryServices.Protocols/tests/DirSyncRequestControlTests.cs index 847f482176d7d..da6bcfbdf5b69 100644 --- a/src/libraries/System.DirectoryServices.Protocols/tests/DirSyncRequestControlTests.cs +++ b/src/libraries/System.DirectoryServices.Protocols/tests/DirSyncRequestControlTests.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 DirSyncRequestControlTests { [Fact] diff --git a/src/libraries/System.DirectoryServices.Protocols/tests/DirectoryControlTests.cs b/src/libraries/System.DirectoryServices.Protocols/tests/DirectoryControlTests.cs index 4f79e81c83ec1..32d2b36f06249 100644 --- a/src/libraries/System.DirectoryServices.Protocols/tests/DirectoryControlTests.cs +++ b/src/libraries/System.DirectoryServices.Protocols/tests/DirectoryControlTests.cs @@ -5,7 +5,6 @@ namespace System.DirectoryServices.Protocols.Tests { - [ActiveIssue("https://github.com/dotnet/runtime/issues/49105", typeof(PlatformDetection), nameof(PlatformDetection.IsMacOsAppleSilicon))] public class DirectoryControlTests { [Theory] diff --git a/src/libraries/System.DirectoryServices.Protocols/tests/DirectoryServicesProtocolsTests.cs b/src/libraries/System.DirectoryServices.Protocols/tests/DirectoryServicesProtocolsTests.cs index 1329fa83a6cff..00d56e12bc8d1 100644 --- a/src/libraries/System.DirectoryServices.Protocols/tests/DirectoryServicesProtocolsTests.cs +++ b/src/libraries/System.DirectoryServices.Protocols/tests/DirectoryServicesProtocolsTests.cs @@ -10,7 +10,6 @@ namespace System.DirectoryServices.Protocols.Tests { - [ActiveIssue("https://github.com/dotnet/runtime/issues/49105", typeof(PlatformDetection), nameof(PlatformDetection.IsMacOsAppleSilicon))] public partial class DirectoryServicesProtocolsTests { internal static bool IsLdapConfigurationExist => LdapConfiguration.Configuration != null; diff --git a/src/libraries/System.DirectoryServices.Protocols/tests/ExtendedDNControlTests.cs b/src/libraries/System.DirectoryServices.Protocols/tests/ExtendedDNControlTests.cs index a7c571598d7c2..284d916613b23 100644 --- a/src/libraries/System.DirectoryServices.Protocols/tests/ExtendedDNControlTests.cs +++ b/src/libraries/System.DirectoryServices.Protocols/tests/ExtendedDNControlTests.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 ExtendedDNControlTests { [Fact] diff --git a/src/libraries/System.DirectoryServices.Protocols/tests/PageResultRequestControlTests.cs b/src/libraries/System.DirectoryServices.Protocols/tests/PageResultRequestControlTests.cs index e6f10e4bddc7e..537874c7f4fbd 100644 --- a/src/libraries/System.DirectoryServices.Protocols/tests/PageResultRequestControlTests.cs +++ b/src/libraries/System.DirectoryServices.Protocols/tests/PageResultRequestControlTests.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 PageResultRequestControlTests { [Fact] diff --git a/src/libraries/System.DirectoryServices.Protocols/tests/QuotaControlTests.cs b/src/libraries/System.DirectoryServices.Protocols/tests/QuotaControlTests.cs index 033865e1353d9..b1ddaa9efa8e8 100644 --- a/src/libraries/System.DirectoryServices.Protocols/tests/QuotaControlTests.cs +++ b/src/libraries/System.DirectoryServices.Protocols/tests/QuotaControlTests.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 QuotaControlTests { [Fact] diff --git a/src/libraries/System.DirectoryServices.Protocols/tests/SearchOptionsControlTests.cs b/src/libraries/System.DirectoryServices.Protocols/tests/SearchOptionsControlTests.cs index c173904caaaef..2a30d7dc3a522 100644 --- a/src/libraries/System.DirectoryServices.Protocols/tests/SearchOptionsControlTests.cs +++ b/src/libraries/System.DirectoryServices.Protocols/tests/SearchOptionsControlTests.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 SearchOptionsControlTests { [Fact] diff --git a/src/libraries/System.DirectoryServices.Protocols/tests/SecurityDescriptorFlagControlTests.cs b/src/libraries/System.DirectoryServices.Protocols/tests/SecurityDescriptorFlagControlTests.cs index 47ceca06e70a5..6ec7955faa782 100644 --- a/src/libraries/System.DirectoryServices.Protocols/tests/SecurityDescriptorFlagControlTests.cs +++ b/src/libraries/System.DirectoryServices.Protocols/tests/SecurityDescriptorFlagControlTests.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 SecurityDescriptorFlagControlTests { [Fact] diff --git a/src/libraries/System.DirectoryServices.Protocols/tests/VerifyNameControlTests.cs b/src/libraries/System.DirectoryServices.Protocols/tests/VerifyNameControlTests.cs index c6edf3487253d..5e7469d27ed01 100644 --- a/src/libraries/System.DirectoryServices.Protocols/tests/VerifyNameControlTests.cs +++ b/src/libraries/System.DirectoryServices.Protocols/tests/VerifyNameControlTests.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 VerifyNameControlTests { [Fact] diff --git a/src/libraries/System.DirectoryServices.Protocols/tests/VlvRequestControlTests.cs b/src/libraries/System.DirectoryServices.Protocols/tests/VlvRequestControlTests.cs index 4ea87e1a5f6ec..a259bd11c7e8a 100644 --- a/src/libraries/System.DirectoryServices.Protocols/tests/VlvRequestControlTests.cs +++ b/src/libraries/System.DirectoryServices.Protocols/tests/VlvRequestControlTests.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 VlvRequestControlTests { [Fact] From 552d9dd8e868b0af3613b7f7b0e88298570df83b Mon Sep 17 00:00:00 2001 From: Sergey Date: Tue, 13 Apr 2021 16:13:22 -0700 Subject: [PATCH 2/5] Use __arglist for windows. --- .../Interop/Windows/Wldap32/Interop.Ber.cs | 22 ++----------------- .../Protocols/Interop/BerPal.Windows.cs | 16 +++++++------- 2 files changed, 10 insertions(+), 28 deletions(-) diff --git a/src/libraries/Common/src/Interop/Windows/Wldap32/Interop.Ber.cs b/src/libraries/Common/src/Interop/Windows/Wldap32/Interop.Ber.cs index 99fec68cbcc73..0ba2c96ecf757 100644 --- a/src/libraries/Common/src/Interop/Windows/Wldap32/Interop.Ber.cs +++ b/src/libraries/Common/src/Interop/Windows/Wldap32/Interop.Ber.cs @@ -16,16 +16,7 @@ internal static partial class Ldap public static extern IntPtr ber_alloc(int option); [DllImport(Libraries.Wldap32, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ber_printf", CharSet = CharSet.Unicode)] - public static extern int ber_printf_emptyarg(SafeBerHandle berElement, string format); - - [DllImport(Libraries.Wldap32, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ber_printf", CharSet = CharSet.Unicode)] - public static extern int ber_printf_int(SafeBerHandle berElement, string format, int value); - - [DllImport(Libraries.Wldap32, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ber_printf", CharSet = CharSet.Unicode)] - public static extern int ber_printf_bytearray(SafeBerHandle berElement, string format, HGlobalMemHandle value, int length); - - [DllImport(Libraries.Wldap32, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ber_printf", CharSet = CharSet.Unicode)] - public static extern int ber_printf_berarray(SafeBerHandle berElement, string format, IntPtr value); + public static extern int ber_printf(SafeBerHandle berElement, string format, __arglist); [DllImport(Libraries.Wldap32, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ber_flatten", CharSet = CharSet.Unicode)] public static extern int ber_flatten(SafeBerHandle berElement, ref IntPtr value); @@ -34,16 +25,7 @@ internal static partial class Ldap public static extern IntPtr ber_init(berval value); [DllImport(Libraries.Wldap32, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ber_scanf", CharSet = CharSet.Unicode)] - public static extern int ber_scanf(SafeBerHandle berElement, string format); - - [DllImport(Libraries.Wldap32, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ber_scanf", CharSet = CharSet.Unicode)] - public static extern int ber_scanf_int(SafeBerHandle berElement, string format, ref int value); - - [DllImport(Libraries.Wldap32, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ber_scanf", CharSet = CharSet.Unicode)] - public static extern int ber_scanf_ptr(SafeBerHandle berElement, string format, ref IntPtr value); - - [DllImport(Libraries.Wldap32, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ber_scanf", CharSet = CharSet.Unicode)] - public static extern int ber_scanf_bitstring(SafeBerHandle berElement, string format, ref IntPtr value, ref int bitLength); + public static extern int ber_scanf(SafeBerHandle berElement, string format, __arglist); [DllImport(Libraries.Wldap32, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ber_bvfree", CharSet = CharSet.Unicode)] public static extern int ber_bvfree(IntPtr value); 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..d1c70f9d69060 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(berElement, format, __arglist(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(berElement, format, __arglist(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(berElement, format, __arglist()); - 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(berElement, format, __arglist(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(berElement, format, __arglist()); - 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(berElement, format, __arglist(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(berElement, format, __arglist(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(berElement, format, __arglist(ref value)); internal static bool IsBerDecodeError(int errorCode) => errorCode != 0; } From 46908e676af7f6e9b8b1b32c3833320adb858bb8 Mon Sep 17 00:00:00 2001 From: Sergey Date: Tue, 13 Apr 2021 18:03:38 -0700 Subject: [PATCH 3/5] Use ber_put_*/ber_get_* for Unix --- .../src/Interop/Linux/OpenLdap/Interop.Ber.cs | 194 ++++++++++++++++-- .../Protocols/Interop/BerPal.Linux.cs | 14 +- .../Protocols/Interop/BerPal.Windows.cs | 12 +- .../Protocols/common/BerConverter.cs | 69 +++++-- .../tests/BerConverterTests.cs | 13 +- 5 files changed, 261 insertions(+), 41 deletions(-) diff --git a/src/libraries/Common/src/Interop/Linux/OpenLdap/Interop.Ber.cs b/src/libraries/Common/src/Interop/Linux/OpenLdap/Interop.Ber.cs index 9dc20b7f4eb06..ce9eacee1ebd6 100644 --- a/src/libraries/Common/src/Interop/Linux/OpenLdap/Interop.Ber.cs +++ b/src/libraries/Common/src/Interop/Linux/OpenLdap/Interop.Ber.cs @@ -4,11 +4,14 @@ using System; using System.Runtime.InteropServices; using System.DirectoryServices.Protocols; +using System.Diagnostics; internal static partial class Interop { internal static partial class Ldap { + private const int ber_default_successful_return_code = 0; + [DllImport(Libraries.OpenLdap, EntryPoint = "ber_alloc_t", CharSet = CharSet.Ansi)] public static extern IntPtr ber_alloc(int option); @@ -18,17 +21,105 @@ internal static partial class Ldap [DllImport(Libraries.OpenLdap, EntryPoint = "ber_free", CharSet = CharSet.Ansi)] public static extern IntPtr ber_free([In] IntPtr berelement, int option); - [DllImport(Libraries.OpenLdap, EntryPoint = "ber_printf", CharSet = CharSet.Ansi)] - public static extern int ber_printf_emptyarg(SafeBerHandle berElement, string format); + public static int ber_printf_emptyarg(SafeBerHandle berElement, string format, int tag) + { + if (format == "{") + { + return ber_start_seq(berElement, tag); + } + else if (format == "}") + { + return ber_put_seq(berElement, tag); + } + else if (format == "[") + { + return ber_start_set(berElement, tag); + } + else if (format == "]") + { + return ber_put_set(berElement, tag); + } + else + { + // We allow "t" here to check that a tag value at the end of stream does not produce an error. + // The actual tag value that affects the next element is passed with the next element using the tag argument. + Debug.Assert(format == "n" || format == "t"); + return ber_put_null(berElement, tag); + } + } + + [DllImport(Libraries.OpenLdap, EntryPoint = "ber_start_seq", CharSet = CharSet.Ansi)] + public static extern int ber_start_seq(SafeBerHandle berElement, int tag); + + [DllImport(Libraries.OpenLdap, EntryPoint = "ber_start_set", CharSet = CharSet.Ansi)] + public static extern int ber_start_set(SafeBerHandle berElement, int tag); + + [DllImport(Libraries.OpenLdap, EntryPoint = "ber_put_seq", CharSet = CharSet.Ansi)] + public static extern int ber_put_seq(SafeBerHandle berElement, int tag); + + [DllImport(Libraries.OpenLdap, EntryPoint = "ber_put_set", CharSet = CharSet.Ansi)] + public static extern int ber_put_set(SafeBerHandle berElement, int tag); + + [DllImport(Libraries.OpenLdap, EntryPoint = "ber_put_null", CharSet = CharSet.Ansi)] + public static extern int ber_put_null(SafeBerHandle berElement, int tag); + + + public static int ber_printf_tag(SafeBerHandle berElement, string format, int tag) + { + return ber_default_successful_return_code; + } + + public static int ber_printf_int(SafeBerHandle berElement, string format, int value, int tag) + { + if (format == "i") + { + return ber_put_int(berElement, value, tag); + } + else if (format == "e") + { + return ber_put_enum(berElement, value, tag); + } + else + { + Debug.Assert(format == "b"); + return ber_put_boolean(berElement, value, tag); + } + } + + [DllImport(Libraries.OpenLdap, EntryPoint = "ber_put_int", CharSet = CharSet.Ansi)] + public static extern int ber_put_int(SafeBerHandle berElement, int value, int tag); + + [DllImport(Libraries.OpenLdap, EntryPoint = "ber_put_enum", CharSet = CharSet.Ansi)] + public static extern int ber_put_enum(SafeBerHandle berElement, int value, int tag); - [DllImport(Libraries.OpenLdap, EntryPoint = "ber_printf", CharSet = CharSet.Ansi)] - public static extern int ber_printf_int(SafeBerHandle berElement, string format, int value); + [DllImport(Libraries.OpenLdap, EntryPoint = "ber_put_boolean", CharSet = CharSet.Ansi)] + public static extern int ber_put_boolean(SafeBerHandle berElement, int value, int tag); - [DllImport(Libraries.OpenLdap, EntryPoint = "ber_printf", CharSet = CharSet.Ansi)] - public static extern int ber_printf_bytearray(SafeBerHandle berElement, string format, HGlobalMemHandle value, int length); + public static int ber_printf_bytearray(SafeBerHandle berElement, string format, HGlobalMemHandle value, int length, int tag) + { + if (format == "o") + { + return ber_put_ostring(berElement, value, length, tag); + } + else if (format == "s") + { + return ber_put_string(berElement, value, tag); + } + else + { + Debug.Assert(format == "X"); + return ber_put_bitstring(berElement, value, length, tag); + } + } - [DllImport(Libraries.OpenLdap, EntryPoint = "ber_printf", CharSet = CharSet.Ansi)] - public static extern int ber_printf_berarray(SafeBerHandle berElement, string format, IntPtr value); + [DllImport(Libraries.OpenLdap, EntryPoint = "ber_put_ostring", CharSet = CharSet.Ansi)] + private static extern int ber_put_ostring(SafeBerHandle berElement, HGlobalMemHandle value, int length, int tag); + + [DllImport(Libraries.OpenLdap, EntryPoint = "ber_put_string", CharSet = CharSet.Ansi)] + private static extern int ber_put_string(SafeBerHandle berElement, HGlobalMemHandle value, int tag); + + [DllImport(Libraries.OpenLdap, EntryPoint = "ber_put_bitstring", CharSet = CharSet.Ansi)] + private static extern int ber_put_bitstring(SafeBerHandle berElement, HGlobalMemHandle value, int length, int tag); [DllImport(Libraries.OpenLdap, EntryPoint = "ber_flatten", CharSet = CharSet.Ansi)] public static extern int ber_flatten(SafeBerHandle berElement, ref IntPtr value); @@ -39,16 +130,87 @@ internal static partial class Ldap [DllImport(Libraries.OpenLdap, EntryPoint = "ber_bvecfree", CharSet = CharSet.Ansi)] public static extern int ber_bvecfree(IntPtr value); - [DllImport(Libraries.OpenLdap, EntryPoint = "ber_scanf", CharSet = CharSet.Ansi)] - public static extern int ber_scanf(SafeBerHandle berElement, string format); + public static int ber_scanf_emptyarg(SafeBerHandle berElement, string format) + { + Debug.Assert(format == "{" || format == "}" || format == "[" || format == "]" || format == "n" || format == "x"); + if (format == "{" || format == "[") + { + int len = 0; + return ber_skip_tag(berElement, ref len); + } + else if (format == "]" || format == "}") + { + return ber_default_successful_return_code; + } + else + { + Debug.Assert(format == "n" || format == "x"); + return ber_get_null(berElement); + } + } + + [DllImport(Libraries.OpenLdap, EntryPoint = "ber_skip_tag", CharSet = CharSet.Ansi)] + private static extern int ber_skip_tag(SafeBerHandle berElement, ref int len); + + [DllImport(Libraries.OpenLdap, EntryPoint = "ber_get_null", CharSet = CharSet.Ansi)] + private static extern int ber_get_null(SafeBerHandle berElement); + + public static int ber_scanf_int(SafeBerHandle berElement, string format, ref int value) + { + if (format == "i") + { + return ber_get_int(berElement, ref value); + } + else if (format == "e") + { + return ber_get_enum(berElement, ref value); + } + else + { + Debug.Assert(format == "b"); + return ber_get_boolean(berElement, ref value); + } + } + + [DllImport(Libraries.OpenLdap, EntryPoint = "ber_get_int", CharSet = CharSet.Ansi)] + private static extern int ber_get_int(SafeBerHandle berElement, ref int value); + + [DllImport(Libraries.OpenLdap, EntryPoint = "ber_get_enum", CharSet = CharSet.Ansi)] + private static extern int ber_get_enum(SafeBerHandle berElement, ref int value); + + [DllImport(Libraries.OpenLdap, EntryPoint = "ber_get_boolean", CharSet = CharSet.Ansi)] + private static extern int ber_get_boolean(SafeBerHandle berElement, ref int value); + + public static int ber_scanf_bitstring(SafeBerHandle berElement, string format, ref IntPtr value, ref int bitLength) + { + Debug.Assert(format == "B"); + return ber_get_stringb(berElement, ref value, ref bitLength); + } + + [DllImport(Libraries.OpenLdap, EntryPoint = "ber_get_stringb", CharSet = CharSet.Ansi)] + private static extern int ber_get_stringb(SafeBerHandle berElement, ref IntPtr value, ref int bitLength); + + public static int ber_scanf_ptr(SafeBerHandle berElement, string format, ref IntPtr value) + { + Debug.Assert(format == "O"); + return ber_get_stringal(berElement, ref value); + } - [DllImport(Libraries.OpenLdap, EntryPoint = "ber_scanf", CharSet = CharSet.Ansi)] - public static extern int ber_scanf_int(SafeBerHandle berElement, string format, ref int value); + [DllImport(Libraries.OpenLdap, EntryPoint = "ber_get_stringal", CharSet = CharSet.Ansi)] + private static extern int ber_get_stringal(SafeBerHandle berElement, ref IntPtr value); - [DllImport(Libraries.OpenLdap, EntryPoint = "ber_scanf", CharSet = CharSet.Ansi)] - public static extern int ber_scanf_bitstring(SafeBerHandle berElement, string format, ref IntPtr value, ref int bitLength); + public static int ber_printf_berarray(SafeBerHandle berElement, string format, IntPtr value, int tag) + { + Debug.Assert(format == "v" || format == "V"); + // V and v are not supported on Unix yet. + return -1; + } - [DllImport(Libraries.OpenLdap, EntryPoint = "ber_scanf", CharSet = CharSet.Ansi)] - public static extern int ber_scanf_ptr(SafeBerHandle berElement, string format, ref IntPtr value); + public static int ber_scanf_multibytearray(SafeBerHandle berElement, string format, ref IntPtr value) + { + Debug.Assert(format == "v" || format == "V"); + // V and v are not supported on Unix yet. + return -1; + } } } 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..359a973463d5f 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,15 +13,17 @@ 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, int tag) => Interop.Ldap.ber_printf_berarray(berElement, format, value, tag); - 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, int tag) => Interop.Ldap.ber_printf_bytearray(berElement, format, value, length, tag); - internal static int PrintEmptyArgument(SafeBerHandle berElement, string format) => Interop.Ldap.ber_printf_emptyarg(berElement, format); + internal static int PrintEmptyArgument(SafeBerHandle berElement, string format, int tag) => Interop.Ldap.ber_printf_emptyarg(berElement, format, tag); - 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, int tag) => Interop.Ldap.ber_printf_int(berElement, format, value, tag); - internal static int ScanNext(SafeBerHandle berElement, string format) => Interop.Ldap.ber_scanf(berElement, format); + internal static int PrintTag(SafeBerHandle berElement, string format, int tag) => Interop.Ldap.ber_printf_tag(berElement, format, tag); + + internal static int ScanNext(SafeBerHandle berElement, string format) => Interop.Ldap.ber_scanf_emptyarg(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); @@ -29,6 +31,8 @@ internal static class BerPal internal static int ScanNextPtr(SafeBerHandle berElement, string format, ref IntPtr value) => Interop.Ldap.ber_scanf_ptr(berElement, format, ref value); + internal static int ScanNextMultiByteArray(SafeBerHandle berElement, string format, ref IntPtr value) => Interop.Ldap.ber_scanf_multibytearray(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 d1c70f9d69060..99532610f6767 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,13 +15,15 @@ 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(berElement, format, __arglist(value)); + internal static int PrintBerArray(SafeBerHandle berElement, string format, IntPtr value, int tag) => Interop.Ldap.ber_printf(berElement, format, __arglist(value)); - internal static int PrintByteArray(SafeBerHandle berElement, string format, HGlobalMemHandle value, int length) => Interop.Ldap.ber_printf(berElement, format, __arglist(value, length)); + internal static int PrintByteArray(SafeBerHandle berElement, string format, HGlobalMemHandle value, int length, int tag) => Interop.Ldap.ber_printf(berElement, format, __arglist(value, length)); - internal static int PrintEmptyArgument(SafeBerHandle berElement, string format) => Interop.Ldap.ber_printf(berElement, format, __arglist()); + internal static int PrintEmptyArgument(SafeBerHandle berElement, string format, int tag) => Interop.Ldap.ber_printf(berElement, format, __arglist()); - internal static int PrintInt(SafeBerHandle berElement, string format, int value) => Interop.Ldap.ber_printf(berElement, format, __arglist(value)); + internal static int PrintInt(SafeBerHandle berElement, string format, int value, int tag) => Interop.Ldap.ber_printf(berElement, format, __arglist(value)); + + internal static int PrintTag(SafeBerHandle berElement, string format, int tag) => Interop.Ldap.ber_printf(berElement, format, __arglist(tag)); internal static int ScanNext(SafeBerHandle berElement, string format) => Interop.Ldap.ber_scanf(berElement, format, __arglist()); @@ -31,6 +33,8 @@ internal static class BerPal internal static int ScanNextPtr(SafeBerHandle berElement, string format, ref IntPtr value) => Interop.Ldap.ber_scanf(berElement, format, __arglist(ref value)); + internal static int ScanNextMultiByteArray(SafeBerHandle berElement, string format, ref IntPtr value) => Interop.Ldap.ber_scanf(berElement, format, __arglist(ref value)); + internal static bool IsBerDecodeError(int errorCode) => errorCode != 0; } } diff --git a/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/common/BerConverter.cs b/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/common/BerConverter.cs index 058024fad909b..db2b2c1ee8292 100644 --- a/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/common/BerConverter.cs +++ b/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/common/BerConverter.cs @@ -29,15 +29,29 @@ public static byte[] Encode(string format, params object[] value) int valueCount = 0; int error = 0; + + // We can't use vararg on Unix and can't do bet_printf(tag), so we use ber_put_int(val, tag) + // and this local keeps tag value for the next element. + int tag = 0; + bool tagIsSet = false; for (int formatCount = 0; formatCount < format.Length; formatCount++) { + if (tagIsSet) + { + tagIsSet = false; + } + else + { + const int lberTagDefault = -1; + tag = lberTagDefault; + } char fmt = format[formatCount]; if (fmt == '{' || fmt == '}' || fmt == '[' || fmt == ']' || fmt == 'n') { // no argument needed - error = BerPal.PrintEmptyArgument(berElement, new string(fmt, 1)); + error = BerPal.PrintEmptyArgument(berElement, new string(fmt, 1), tag); } - else if (fmt == 't' || fmt == 'i' || fmt == 'e') + else if (fmt == 'i' || fmt == 'e') { if (valueCount >= value.Length) { @@ -54,7 +68,7 @@ public static byte[] Encode(string format, params object[] value) } // one int argument - error = BerPal.PrintInt(berElement, new string(fmt, 1), (int)value[valueCount]); + error = BerPal.PrintInt(berElement, new string(fmt, 1), (int)value[valueCount], tag); // increase the value count valueCount++; @@ -76,7 +90,7 @@ public static byte[] Encode(string format, params object[] value) } // one int argument - error = BerPal.PrintInt(berElement, new string(fmt, 1), (bool)value[valueCount] ? 1 : 0); + error = BerPal.PrintInt(berElement, new string(fmt, 1), (bool)value[valueCount] ? 1 : 0, tag); // increase the value count valueCount++; @@ -104,7 +118,7 @@ public static byte[] Encode(string format, params object[] value) { tempValue = utf8Encoder.GetBytes((string)value[valueCount]); } - error = EncodingByteArrayHelper(berElement, tempValue, 'o'); + error = EncodingByteArrayHelper(berElement, tempValue, 'o', tag); // increase the value count valueCount++; @@ -128,7 +142,7 @@ public static byte[] Encode(string format, params object[] value) } byte[] tempValue = (byte[])value[valueCount]; - error = EncodingByteArrayHelper(berElement, tempValue, fmt); + error = EncodingByteArrayHelper(berElement, tempValue, fmt, tag); valueCount++; } @@ -164,11 +178,13 @@ public static byte[] Encode(string format, params object[] value) { tempValues[i] = utf8Encoder.GetBytes(s); } + error = EncodingByteArrayHelper(berElement, tempValues[i], 'o', tag); + if (error == -1) + { + break; + } } } - - error = EncodingMultiByteArrayHelper(berElement, tempValues, 'V'); - valueCount++; } else if (fmt == 'V') @@ -191,8 +207,31 @@ public static byte[] Encode(string format, params object[] value) byte[][] tempValue = (byte[][])value[valueCount]; - error = EncodingMultiByteArrayHelper(berElement, tempValue, fmt); + error = EncodingMultiByteArrayHelper(berElement, tempValue, fmt, tag); + + valueCount++; + } + else if (fmt == 't') + { + if (valueCount >= value.Length) + { + // we don't have enough argument for the format string + Debug.WriteLine("value argument is not valid, valueCount >= value.Length\n"); + throw new ArgumentException(SR.BerConverterNotMatch); + } + + if (!(value[valueCount] is int)) + { + // argument is wrong + Debug.WriteLine("type should be int\n"); + throw new ArgumentException(SR.BerConverterNotMatch); + } + tag = (int)value[valueCount]; + tagIsSet = true; + // It will set the tag on Windows and only check the tag on Unix. + error = BerPal.PrintTag(berElement, new string(fmt, 1), tag); + // increase the value count valueCount++; } else @@ -423,7 +462,7 @@ internal static object[] TryDecode(string format, byte[] value, out bool decodeS return decodeResult; } - private static int EncodingByteArrayHelper(SafeBerHandle berElement, byte[] tempValue, char fmt) + private static int EncodingByteArrayHelper(SafeBerHandle berElement, byte[] tempValue, char fmt, int tag) { int error = 0; @@ -433,12 +472,12 @@ private static int EncodingByteArrayHelper(SafeBerHandle berElement, byte[] temp IntPtr tmp = Marshal.AllocHGlobal(tempValue.Length); Marshal.Copy(tempValue, 0, tmp, tempValue.Length); HGlobalMemHandle memHandle = new HGlobalMemHandle(tmp); - error = BerPal.PrintByteArray(berElement, new string(fmt, 1), memHandle, tempValue.Length); + error = BerPal.PrintByteArray(berElement, new string(fmt, 1), memHandle, tempValue.Length, tag); } else { HGlobalMemHandle memHandle = new HGlobalMemHandle(HGlobalMemHandle._dummyPointer); - error = BerPal.PrintByteArray(berElement, new string(fmt, 1), memHandle, 0); + error = BerPal.PrintByteArray(berElement, new string(fmt, 1), memHandle, 0, tag); } return error; @@ -479,7 +518,7 @@ private static byte[] DecodingByteArrayHelper(SafeBerHandle berElement, char fmt return byteArray; } - private static int EncodingMultiByteArrayHelper(SafeBerHandle berElement, byte[][] tempValue, char fmt) + private static int EncodingMultiByteArrayHelper(SafeBerHandle berElement, byte[][] tempValue, char fmt, int tag) { IntPtr berValArray = IntPtr.Zero; IntPtr tempPtr = IntPtr.Zero; @@ -521,7 +560,7 @@ private static int EncodingMultiByteArrayHelper(SafeBerHandle berElement, byte[] Marshal.WriteIntPtr(tempPtr, IntPtr.Zero); } - error = BerPal.PrintBerArray(berElement, new string(fmt, 1), berValArray); + error = BerPal.PrintBerArray(berElement, new string(fmt, 1), berValArray, tag); } finally { diff --git a/src/libraries/System.DirectoryServices.Protocols/tests/BerConverterTests.cs b/src/libraries/System.DirectoryServices.Protocols/tests/BerConverterTests.cs index d47ecba69a09c..ba92d33c2a7b6 100644 --- a/src/libraries/System.DirectoryServices.Protocols/tests/BerConverterTests.cs +++ b/src/libraries/System.DirectoryServices.Protocols/tests/BerConverterTests.cs @@ -29,6 +29,10 @@ public static IEnumerable Encode_TestData() yield return new object[] { "[]", new object[] { "a" }, (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) ? new byte[] { 49, 132, 0, 0, 0, 0 } : new byte[] { 49, 0 } }; yield return new object[] { "n", new object[] { "a" }, new byte[] { 5, 0 } }; + yield return new object[] { "e", new object[] { 128 }, new byte[] { 10, 2, 0, 128 } }; + yield return new object[] { "te", new object[] { 128, 0 }, new byte[] { 128, 1, 0 } }; + yield return new object[] { "tet", new object[] { 128, 0, 133 }, new byte[] { 128, 1, 0 } }; + yield return new object[] { "tetie", new object[] { 128, 0, 133, 2, 3 }, new byte[] { 128, 1, 0, 133, 1, 2, 10, 1, 3 } }; yield return new object[] { "{tetie}", new object[] { 128, 0, 133, 2, 3 }, (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) ? new byte[] { 48, 132, 0, 0, 0, 9, 128, 1, 0, 133, 1, 2, 10, 1, 3 } : new byte[] { 48, 9, 128, 1, 0, 133, 1, 2, 10, 1, 3 } }; @@ -36,10 +40,16 @@ public static IEnumerable Encode_TestData() yield return new object[] { "{bb}", new object[] { true, false }, (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) ? new byte[] { 48, 132, 0, 0, 0, 6, 1, 1, 255, 1, 1, 0 } : new byte[] { 48, 6, 1, 1, 255, 1, 1, 0 } }; yield return new object[] { "ssss", new object[] { null, "", "abc", "\0" }, new byte[] { 4, 0, 4, 0, 4, 3, 97, 98, 99, 4, 1, 0 } }; + + yield return new object[] { "o", new object[] { null }, new byte[] { 4, 0} }; + yield return new object[] { "X", new object[] { new byte[] { 0, 1, 2, 255 } }, (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) ? new byte[] { 3, 4, 0, 1, 2, 255 } : new byte[] { 3, 2, 4, 0 } }; yield return new object[] { "oXo", new object[] { null, new byte[] { 0, 1, 2, 255 }, new byte[0] }, (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) ? new byte[] { 4, 0, 3, 4, 0, 1, 2, 255, 4, 0 } : new byte[] { 4, 0, 3, 2, 4, 0, 4, 0 } }; yield return new object[] { "vv", new object[] { null, new string[] { "abc", "", null } }, new byte[] { 4, 3, 97, 98, 99, 4, 0, 4, 0 } }; yield return new object[] { "{vv}", new object[] { null, new string[] { "abc", "", null } }, (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) ? new byte[] { 48, 132, 0, 0, 0, 9, 4, 3, 97, 98, 99, 4, 0, 4, 0 } : new byte[] { 48, 9, 4, 3, 97, 98, 99, 4, 0, 4, 0 } }; - yield return new object[] { "VVVV", new object[] { null, new byte[][] { new byte[] { 0, 1, 2, 3 }, null }, new byte[][] { new byte[0] }, new byte[0][] }, new byte[] { 4, 4, 0, 1, 2, 3, 4, 0, 4, 0 } }; + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + yield return new object[] { "VVVV", new object[] { null, new byte[][] { new byte[] { 0, 1, 2, 3 }, null }, new byte[][] { new byte[0] }, new byte[0][] }, new byte[] { 4, 4, 0, 1, 2, 3, 4, 0, 4, 0 } }; + } } [Theory] @@ -116,6 +126,7 @@ public static IEnumerable Decode_TestData() { yield return new object[] { "{}", new byte[] { 48, 0, 0, 0, 0, 0 }, new object[0] }; yield return new object[] { "{a}", new byte[] { 48, 132, 0, 0, 0, 5, 4, 3, 97, 98, 99 }, new object[] { "abc" } }; + yield return new object[] { "{i}", new byte[] { 48, 132, 0, 0, 0, 3, 2, 1, 10 }, new object[] { 10 } }; yield return new object[] { "{ie}", new byte[] { 48, 132, 0, 0, 0, 6, 1, 1, 255, 1, 1, 0 }, new object[] { -1, 0 } }; yield return new object[] { "{bb}", new byte[] { 48, 132, 0, 0, 0, 6, 1, 1, 255, 1, 1, 0 }, new object[] { true, false } }; yield return new object[] { "{OO}", new byte[] { 48, 132, 0, 0, 0, 6, 1, 1, 255, 1, 1, 0 }, new object[] { new byte[] { 255 }, new byte[] { 0 } } }; From 0711327d8b7a0fd06bdc9f8731a62644dc884a9b Mon Sep 17 00:00:00 2001 From: Sergey Date: Thu, 15 Apr 2021 17:01:29 -0700 Subject: [PATCH 4/5] fix tag --- .../Common/src/Interop/Linux/OpenLdap/Interop.Ber.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/libraries/Common/src/Interop/Linux/OpenLdap/Interop.Ber.cs b/src/libraries/Common/src/Interop/Linux/OpenLdap/Interop.Ber.cs index ce9eacee1ebd6..9278d7ab4a102 100644 --- a/src/libraries/Common/src/Interop/Linux/OpenLdap/Interop.Ber.cs +++ b/src/libraries/Common/src/Interop/Linux/OpenLdap/Interop.Ber.cs @@ -41,9 +41,7 @@ public static int ber_printf_emptyarg(SafeBerHandle berElement, string format, i } else { - // We allow "t" here to check that a tag value at the end of stream does not produce an error. - // The actual tag value that affects the next element is passed with the next element using the tag argument. - Debug.Assert(format == "n" || format == "t"); + Debug.Assert(format == "n"); return ber_put_null(berElement, tag); } } From f3fd828125fd9bf82fe40820442a47d98e4c62a9 Mon Sep 17 00:00:00 2001 From: Sergey Date: Mon, 19 Apr 2021 13:38:50 -0700 Subject: [PATCH 5/5] fix review. --- src/libraries/Common/src/Interop/Linux/OpenLdap/Interop.Ber.cs | 2 ++ .../System/DirectoryServices/Protocols/common/BerConverter.cs | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libraries/Common/src/Interop/Linux/OpenLdap/Interop.Ber.cs b/src/libraries/Common/src/Interop/Linux/OpenLdap/Interop.Ber.cs index 9278d7ab4a102..830e56c056248 100644 --- a/src/libraries/Common/src/Interop/Linux/OpenLdap/Interop.Ber.cs +++ b/src/libraries/Common/src/Interop/Linux/OpenLdap/Interop.Ber.cs @@ -64,6 +64,8 @@ public static int ber_printf_emptyarg(SafeBerHandle berElement, string format, i public static int ber_printf_tag(SafeBerHandle berElement, string format, int tag) { + // Ber Linux tags are passed with the values that they affect, like `ber_printf_int(.., tag)`. + // So this function does nothing on Linux. return ber_default_successful_return_code; } diff --git a/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/common/BerConverter.cs b/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/common/BerConverter.cs index db2b2c1ee8292..36c94f297c6be 100644 --- a/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/common/BerConverter.cs +++ b/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/common/BerConverter.cs @@ -30,7 +30,7 @@ public static byte[] Encode(string format, params object[] value) int valueCount = 0; int error = 0; - // We can't use vararg on Unix and can't do bet_printf(tag), so we use ber_put_int(val, tag) + // We can't use vararg on Unix and can't do ber_printf(tag), so we use ber_put_int(val, tag) // and this local keeps tag value for the next element. int tag = 0; bool tagIsSet = false;