dotnet / dotnet/runtime

[API Proposal]: Add a new `CanonicalizeHostName` property on `LdapSessionOptions`

Open
#125,454 4 comments 0 reactions 0 assignees View on GitHub
api-ready-for-review area-System.DirectoryServices
Dominant language
C#
Stars
18.3k
Forks
5.6k
PR merge metrics
PR metrics pending

Description

### Background and motivation

OpenLDAP offers the possibility to configure whether to perform reverse DNS lookups to canonicalize SASL host names.

This can be configured with the [SASL_NOCANON](https://www.openldap.org/software/man.cgi?query=ldap.conf) option of the LDAP configuration or the `LDAP_OPT_X_SASL_NOCANON` option of the API.

Configuring this option can be useful, for example to workaround misconfigured DNS PTR records, as explained in [ldapsearch command suddenly stopped working on my Mac](https://superuser.com/questions/1842687/ldapsearch-command-suddenly-stopped-working-on-my-mac/1935578#1935578) on Super User.

This option is unfortunately not exposed on the [LdapSessionOptions](https://learn.microsoft.com/en-us/dotnet/api/system.directoryservices.protocols.ldapsessionoptions) class.

### API Proposal

```csharp
namespace System.DirectoryServices.Protocols;

public class LdapSessionOptions
{
public bool CanonicalizeHostName { get; set; }
}
```

### API Usage

```csharp
using var connection = new LdapConnection(ldapHost);
connection.SessionOptions.CanonicalizeHostName = false;
```

### Alternative Designs

I can't think of an alternative design for exposing this new property.

Also note that the implementation would be straightforward:
```csharp
public bool CanonicalizeHostName
{
get => !GetBoolValueHelper(LdapOption.LDAP_OPT_X_SASL_NOCANON);
set => SetBoolValueHelper(LdapOption.LDAP_OPT_X_SASL_NOCANON, !value);
}
```

It would require moving the `GetBoolValueHelper` and `SetBoolValueHelper` from LdapSessionOptions.Linux.cs into LdapSessionOptions.cs and define the new `LDAP_OPT_X_SASL_NOCANON` enum value (0x610b).

### Risks

No risks are associated by introducing this new property. It's purely additional and without getting it or setting it nothing would happen.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.