Skip to content

Commit

Permalink
Add CLDAP (RFC1798 UDP/Connectionless) support to DialURL (go-ldap#397)
Browse files Browse the repository at this point in the history
* 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 <cp@lumen.sh>
  • Loading branch information
2 people authored and inv2004 committed Jan 17, 2023
1 parent fbfd50c commit 724fb6f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion v3/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 724fb6f

Please sign in to comment.