-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Add support for TLS and connectionless LDAP connections on Linux #52904
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
|
|
||
| using System.Diagnostics; | ||
| using System.Net; | ||
| using System.Text; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| namespace System.DirectoryServices.Protocols | ||
|
|
@@ -12,13 +13,67 @@ public partial class LdapConnection | |
| // Linux doesn't support setting FQDN so we mark the flag as if it is already set so we don't make a call to set it again. | ||
| private bool _setFQDNDone = true; | ||
|
|
||
| private void InternalInitConnectionHandle(string hostname) => _ldapHandle = new ConnectionHandle(Interop.Ldap.ldap_init(hostname, ((LdapDirectoryIdentifier)_directoryIdentifier).PortNumber), _needDispose); | ||
| private void InternalInitConnectionHandle(string hostname) | ||
| { | ||
| if ((LdapDirectoryIdentifier)_directoryIdentifier == null) | ||
| { | ||
| throw new NullReferenceException(); | ||
| } | ||
|
|
||
| _ldapHandle = new ConnectionHandle(); | ||
| } | ||
|
|
||
| private int InternalConnectToServer() | ||
| { | ||
| // In Linux you don't have to call Connect after calling init. You | ||
| // directly call bind. However, we set the URI for the connection | ||
| // here instead of during initialization because we need access to | ||
| // the SessionOptions property to properly define it, which is not | ||
| // available during init. | ||
| Debug.Assert(!_ldapHandle.IsInvalid); | ||
| // In Linux you don't have to call Connect after calling init. You directly call bind. | ||
| return 0; | ||
|
|
||
| string scheme = null; | ||
| LdapDirectoryIdentifier directoryIdentifier = (LdapDirectoryIdentifier)_directoryIdentifier; | ||
| if (directoryIdentifier.Connectionless) | ||
| { | ||
| scheme = "cldap://"; | ||
|
||
| } | ||
| else if (SessionOptions.SecureSocketLayer) | ||
| { | ||
| scheme = "ldaps://"; | ||
| } | ||
| else | ||
| { | ||
| scheme = "ldap://"; | ||
| } | ||
|
|
||
| string uris = null; | ||
| string[] servers = directoryIdentifier.Servers; | ||
| if (servers != null && servers.Length != 0) | ||
| { | ||
| StringBuilder temp = new StringBuilder(200); | ||
| for (int i = 0; i < servers.Length; i++) | ||
| { | ||
| if (i != 0) | ||
| { | ||
| temp.Append(' '); | ||
| } | ||
| temp.Append(scheme); | ||
| temp.Append(servers[i]); | ||
| temp.Append(':'); | ||
| temp.Append(directoryIdentifier.PortNumber); | ||
| } | ||
| if (temp.Length != 0) | ||
| { | ||
| uris = temp.ToString(); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| uris = $"{scheme}:{directoryIdentifier.PortNumber}"; | ||
| } | ||
|
|
||
| return LdapPal.SetStringOption(_ldapHandle, LdapOption.LDAP_OPT_URI, uris); | ||
|
||
| } | ||
|
|
||
| private int InternalBind(NetworkCredential tempCredential, SEC_WINNT_AUTH_IDENTITY_EX cred, BindMethod method) | ||
|
|
@@ -30,7 +85,7 @@ private int InternalBind(NetworkCredential tempCredential, SEC_WINNT_AUTH_IDENTI | |
| } | ||
| else | ||
| { | ||
| error = Interop.Ldap.ldap_simple_bind(_ldapHandle, cred.user, cred.password); | ||
| error = LdapPal.BindToDirectory(_ldapHandle, cred.user, cred.password); | ||
| } | ||
|
|
||
| return error; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,11 +9,12 @@ public partial class LdapSessionOptions | |
| { | ||
| private static void PALCertFreeCRLContext(IntPtr certPtr) { /* No op */ } | ||
|
|
||
| [SupportedOSPlatform("windows")] | ||
danmoseley marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public bool SecureSocketLayer | ||
| public bool SecureSocketLayer { get; set; } | ||
|
|
||
| public int ProtocolVersion | ||
| { | ||
| get => throw new PlatformNotSupportedException(); | ||
| set => throw new PlatformNotSupportedException(); | ||
| get => GetPtrValueHelper(LdapOption.LDAP_OPT_VERSION).ToInt32(); | ||
|
||
| set => SetPtrValueHelper(LdapOption.LDAP_OPT_VERSION, new IntPtr(value)); | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.