File tree 1 file changed +14
-2
lines changed 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -91,20 +91,32 @@ func (l *Config) Clone() (cloned Config) {
91
91
}
92
92
93
93
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
+
94
106
if l .ServerInsecure {
95
107
ldapConn , err = ldap .Dial ("tcp" , ldapAddr )
96
108
} else {
97
109
if l .ServerStartTLS {
98
110
ldapConn , err = ldap .Dial ("tcp" , ldapAddr )
99
111
} else {
100
- ldapConn , err = ldap .DialTLS ("tcp" , ldapAddr , l . TLS )
112
+ ldapConn , err = ldap .DialTLS ("tcp" , ldapAddr , tls )
101
113
}
102
114
}
103
115
104
116
if ldapConn != nil {
105
117
ldapConn .SetTimeout (30 * time .Second ) // Change default timeout to 30 seconds.
106
118
if l .ServerStartTLS {
107
- err = ldapConn .StartTLS (l . TLS )
119
+ err = ldapConn .StartTLS (tls )
108
120
}
109
121
}
110
122
You can’t perform that action at this time.
0 commit comments