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

Switch DirectoryControl to use AsnWriter, AsnDecoder #101512

Merged
merged 24 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
9b87b4e
Removed BerConverter.Decode usage
edwardneal Apr 21, 2024
31600a4
Removed BerConverter.Encode usage
edwardneal Apr 23, 2024
a152c84
Regression in CrossDomainMoveControl
edwardneal Apr 23, 2024
9461057
Correcting test values
edwardneal Apr 23, 2024
cb07eb4
Removed SortKeyInterop from .csproj
edwardneal Apr 23, 2024
73dd1bc
Small optimisations
edwardneal Apr 23, 2024
c5c9598
AD compatibility test corrections
edwardneal Apr 24, 2024
33e4f25
Performance improvement, bugfix
edwardneal Apr 27, 2024
6b487c2
Following code review
edwardneal May 11, 2024
b4bbdc7
Implemented further code review comments
edwardneal May 24, 2024
e12d447
Remainder of code review feedback
edwardneal May 25, 2024
57fc5f6
First response to code review feedback
edwardneal Jul 24, 2024
f1aca42
Further code review changes
edwardneal Jul 26, 2024
2a6915b
Merge remote-tracking branch 'upstream/main' into issue-97540
edwardneal Sep 30, 2024
96790e0
Update tests from PR107201
edwardneal Oct 1, 2024
a215542
Tightened validation based on updated tests
edwardneal Oct 1, 2024
2d87369
Eliminated OS-specific test condition
edwardneal Oct 2, 2024
5ca1fad
Merge remote-tracking branch 'upstream/main' into issue-97540
edwardneal Nov 25, 2024
610b5b2
Code review: SortResponseControl
edwardneal Nov 25, 2024
c2df730
Code review: VlvRequestControl
edwardneal Nov 25, 2024
3056ec7
Code review: TransformControls
edwardneal Nov 25, 2024
98ef3e6
Disabled the new VlvRequestControl on .NET Framework
edwardneal Nov 28, 2024
80cb7af
Cleanup GetWriter
edwardneal Nov 28, 2024
0af321f
Renamed WriteLdapString to WriteStringAsOctetString
edwardneal Nov 28, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,6 @@ internal static partial int ldap_sasl_interactive_bind(
[LibraryImport(Libraries.OpenLdap, EntryPoint = "ldap_first_reference")]
public static partial IntPtr ldap_first_reference(ConnectionHandle ldapHandle, IntPtr result);

[LibraryImport(Libraries.OpenLdap, EntryPoint = "ldap_create_sort_control")]
public static partial int ldap_create_sort_control(ConnectionHandle handle, IntPtr keys, byte critical, ref IntPtr control);

[LibraryImport(Libraries.OpenLdap, EntryPoint = "ldap_control_free")]
public static partial int ldap_control_free(IntPtr control);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,6 @@ internal static partial class Ldap
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial int ldap_parse_reference(ConnectionHandle ldapHandle, IntPtr result, ref IntPtr referrals);

[LibraryImport(Libraries.Wldap32, EntryPoint = "ldap_create_sort_controlW")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial int ldap_create_sort_control(ConnectionHandle handle, IntPtr keys, byte critical, ref IntPtr control);

[LibraryImport(Libraries.Wldap32, EntryPoint = "ldap_control_freeW")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial int ldap_control_free(IntPtr control);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
</PropertyGroup>

<ItemGroup Condition="'$(TargetPlatformIdentifier)' != ''">
<Compile Include="System\DirectoryServices\Protocols\common\AsnWriterExtensions.cs" />
<Compile Include="System\DirectoryServices\Protocols\common\AuthTypes.cs" />
<Compile Include="System\DirectoryServices\Protocols\common\BerConverter.cs" />
<Compile Include="System\DirectoryServices\Protocols\common\DereferenceAlias.cs" />
Expand All @@ -51,7 +52,6 @@
<Compile Include="System\DirectoryServices\Protocols\ldap\LdapPartialResultsProcessor.cs" />
<Compile Include="System\DirectoryServices\Protocols\ldap\LdapSessionOptions.cs" />
<Compile Include="System\DirectoryServices\Protocols\Interop\SafeHandles.cs" />
<Compile Include="System\DirectoryServices\Protocols\Interop\SortKeyInterop.cs" />

<Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs" Link="Common\DisableRuntimeMarshalling.cs" />
<Compile Include="$(CommonPath)Interop\Interop.Ldap.cs" Link="Common\Interop\Interop.Ldap.cs" />
Expand All @@ -64,7 +64,6 @@
<Compile Include="System\DirectoryServices\Protocols\common\QuotaControl.Windows.cs" />
<Compile Include="System\DirectoryServices\Protocols\Interop\LdapPal.Windows.cs" />
<Compile Include="System\DirectoryServices\Protocols\Interop\BerPal.Windows.cs" />
<Compile Include="System\DirectoryServices\Protocols\Interop\SortKeyInterop.Windows.cs" />
<Compile Include="System\DirectoryServices\Protocols\ldap\LdapConnection.Windows.cs" />
<Compile Include="System\DirectoryServices\Protocols\ldap\LdapSessionOptions.Windows.cs" />
<Compile Include="System\DirectoryServices\Protocols\Interop\SafeHandles.Windows.cs" />
Expand All @@ -79,7 +78,6 @@
<Compile Include="System\DirectoryServices\Protocols\common\QuotaControl.Linux.cs" />
<Compile Include="System\DirectoryServices\Protocols\Interop\LdapPal.Linux.cs" />
<Compile Include="System\DirectoryServices\Protocols\Interop\BerPal.Linux.cs" />
<Compile Include="System\DirectoryServices\Protocols\Interop\SortKeyInterop.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" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ internal static int CompareDirectoryEntries(ConnectionHandle ldapHandle, string

internal static void FreeDirectoryControls(IntPtr value) => Interop.Ldap.ldap_controls_free(value);

internal static int CreateDirectorySortControl(ConnectionHandle handle, IntPtr keys, byte critical, ref IntPtr control) => Interop.Ldap.ldap_create_sort_control(handle, keys, critical, ref control);

internal static int DeleteDirectoryEntry(ConnectionHandle ldapHandle, string dn, IntPtr servercontrol, IntPtr clientcontrol, ref int messageNumber) => Interop.Ldap.ldap_delete_ext(ldapHandle, dn, servercontrol, clientcontrol, ref messageNumber);

internal static int ExtendedDirectoryOperation(ConnectionHandle ldapHandle, string oid, BerVal data, IntPtr servercontrol, IntPtr clientcontrol, ref int messageNumber) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ internal static int CompareDirectoryEntries(ConnectionHandle ldapHandle, string

internal static void FreeDirectoryControls(IntPtr value) => Interop.Ldap.ldap_controls_free(value);

internal static int CreateDirectorySortControl(ConnectionHandle handle, IntPtr keys, byte critical, ref IntPtr control) => Interop.Ldap.ldap_create_sort_control(handle, keys, critical, ref control);

internal static int DeleteDirectoryEntry(ConnectionHandle ldapHandle, string dn, IntPtr servercontrol, IntPtr clientcontrol, ref int messageNumber) => Interop.Ldap.ldap_delete_ext(ldapHandle, dn, servercontrol, clientcontrol, ref messageNumber);

internal static int ExtendedDirectoryOperation(ConnectionHandle ldapHandle, string oid, BerVal data, IntPtr servercontrol, IntPtr clientcontrol, ref int messageNumber) =>
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Formats.Asn1;
using System.Text;

namespace System.DirectoryServices.Protocols
{
internal static class AsnWriterExtensions
{
public static void WriteStringAsOctetString(this AsnWriter writer, string value, Encoding stringEncoding, Asn1Tag? tag = null)
{
// A typical stack allocation threshold would be 256 bytes. A higher threshold has been chosen because an LdapString can be
// used to serialize server names. A server name is defined by RF1035, which specifies that a label in a domain name should
// be < 64 characters. If a server name is specified as an FQDN, this will be at least three labels in an AD environment -
// up to 192 characters. Doubling this to allow for Unicode encoding, then rounding to the nearest power of two yields 512.
const int StackAllocationThreshold = 512;

if (!string.IsNullOrEmpty(value))
{
int octetStringLength = stringEncoding.GetByteCount(value);
// Allocate space on the stack. There's a modest codegen advantage to a constant-value stackalloc.
Span<byte> tmpValue = octetStringLength <= StackAllocationThreshold
? stackalloc byte[StackAllocationThreshold].Slice(0, octetStringLength)
: new byte[octetStringLength];

stringEncoding.GetBytes(value, tmpValue);
writer.WriteOctetString(tmpValue, tag);
}
else
{
writer.WriteOctetString([], tag);
}
}
}
}
Loading
Loading