From 724fb6f99af1807423850feff9f09d57a9e360d6 Mon Sep 17 00:00:00 2001 From: Danny Smith Date: Sat, 15 Oct 2022 09:17:04 +0100 Subject: [PATCH] Add CLDAP (RFC1798 UDP/Connectionless) support to DialURL (#397) * Add CLDAP (RFC1798 UDP/Connectionless) support to DialURL This is actually a deprecated RFC, however Active Directory relies on it for server discovery. Without this patch CLDAP is possible via directt use of the the deprecated `Dial` function with a UDP network connection. This patch adds the same support to the DialURL function. * Mirror code changes to root folder Co-authored-by: Christopher Puschmann --- conn.go | 8 +++++++- v3/conn.go | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/conn.go b/conn.go index 25a691cb..170f4af8 100644 --- a/conn.go +++ b/conn.go @@ -161,6 +161,11 @@ func (dc *DialContext) dial(u *url.URL) (net.Conn, error) { } switch u.Scheme { + case "cldap": + if port == "" { + port = DefaultLdapPort + } + return dc.d.Dial("udp", net.JoinHostPort(host, port)) case "ldap": if port == "" { port = DefaultLdapPort @@ -203,7 +208,8 @@ func DialTLS(network, addr string, config *tls.Config) (*Conn, error) { } // DialURL connects to the given ldap URL. -// The following schemas are supported: ldap://, ldaps://, ldapi://. +// The following schemas are supported: ldap://, ldaps://, ldapi://, +// and cldap:// (RFC1798, deprecated but used by Active Directory). // On success a new Conn for the connection is returned. func DialURL(addr string, opts ...DialOpt) (*Conn, error) { u, err := url.Parse(addr) diff --git a/v3/conn.go b/v3/conn.go index 25a691cb..170f4af8 100644 --- a/v3/conn.go +++ b/v3/conn.go @@ -161,6 +161,11 @@ func (dc *DialContext) dial(u *url.URL) (net.Conn, error) { } switch u.Scheme { + case "cldap": + if port == "" { + port = DefaultLdapPort + } + return dc.d.Dial("udp", net.JoinHostPort(host, port)) case "ldap": if port == "" { port = DefaultLdapPort @@ -203,7 +208,8 @@ func DialTLS(network, addr string, config *tls.Config) (*Conn, error) { } // DialURL connects to the given ldap URL. -// The following schemas are supported: ldap://, ldaps://, ldapi://. +// The following schemas are supported: ldap://, ldaps://, ldapi://, +// and cldap:// (RFC1798, deprecated but used by Active Directory). // On success a new Conn for the connection is returned. func DialURL(addr string, opts ...DialOpt) (*Conn, error) { u, err := url.Parse(addr)