Skip to content

Commit 9ea6061

Browse files
committed
init
1 parent 1ec730d commit 9ea6061

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

ldap/ldap.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,32 @@ func (l *Config) Clone() (cloned Config) {
9191
}
9292

9393
func (l *Config) connect(ldapAddr string) (ldapConn *ldap.Conn, err error) {
94+
tls := l.TLS
95+
if tls.ServerName == "" {
96+
// Set the server name to the LDAP server address.
97+
colonPos := strings.LastIndex(ldapAddr, ":")
98+
if colonPos == -1 {
99+
colonPos = len(ldapAddr)
100+
}
101+
host := ldapAddr[:colonPos]
102+
tls = l.TLS.Clone()
103+
tls.ServerName = host
104+
}
105+
94106
if l.ServerInsecure {
95107
ldapConn, err = ldap.Dial("tcp", ldapAddr)
96108
} else {
97109
if l.ServerStartTLS {
98110
ldapConn, err = ldap.Dial("tcp", ldapAddr)
99111
} else {
100-
ldapConn, err = ldap.DialTLS("tcp", ldapAddr, l.TLS)
112+
ldapConn, err = ldap.DialTLS("tcp", ldapAddr, tls)
101113
}
102114
}
103115

104116
if ldapConn != nil {
105117
ldapConn.SetTimeout(30 * time.Second) // Change default timeout to 30 seconds.
106118
if l.ServerStartTLS {
107-
err = ldapConn.StartTLS(l.TLS)
119+
err = ldapConn.StartTLS(tls)
108120
}
109121
}
110122

0 commit comments

Comments
 (0)