Skip to content

Commit 7225deb

Browse files
committed
added support for non tls ldap
1 parent 1117269 commit 7225deb

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

gitea-group-sync.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,26 @@ func mainJob() {
9898
}
9999

100100
var ldapPort int
101+
var ldapTls bool
101102
if len(os.Getenv("LDAP_TLS_PORT")) > 0 {
102103
port, err := strconv.Atoi(os.Getenv("LDAP_TLS_PORT"))
103104
ldapPort = port
105+
ldapTls = true
104106
log.Printf("DialTLS:=%v:%d", ldapUrl, ldapPort)
105107
if err != nil {
106108
log.Println("LDAP_TLS_PORT is invalid.")
107109
}
108110
} else {
109-
log.Println("LDAP_TLS_PORT is empty")
110-
}
111+
if len(os.Getenv("LDAP_PORT")) > 0 {
112+
port, err := strconv.Atoi(os.Getenv("LDAP_PORT"))
113+
ldapPort = port
114+
ldapTls = false
115+
log.Printf("Dial:=%v:%d", ldapUrl, ldapPort)
116+
if err != nil {
117+
log.Println("LDAP_PORT is invalid.")
118+
}
119+
}
120+
}
111121

112122
var ldapbindDN string
113123
if len(os.Getenv("BIND_DN")) == 0 {
@@ -137,7 +147,14 @@ func mainJob() {
137147
ldapUserSearchBase = os.Getenv("LDAP_USER_SEARCH_BASE")
138148
}
139149

140-
l, err := ldap.DialTLS("tcp", fmt.Sprintf("%s:%d", ldapUrl, ldapPort), &tls.Config{InsecureSkipVerify: true})
150+
var l *ldap.Conn
151+
var err error
152+
if ldapTls {
153+
l, err = ldap.DialTLS("tcp", fmt.Sprintf("%s:%d", ldapUrl, ldapPort), &tls.Config{InsecureSkipVerify: true})
154+
} else {
155+
l, err = ldap.Dial("tcp", fmt.Sprintf("%s:%d", ldapUrl, ldapPort))
156+
}
157+
141158
if err != nil {
142159
fmt.Println(err)
143160
fmt.Println("Please set the correct values for all specifics.")

0 commit comments

Comments
 (0)