From 7225deb7e1727a464bafb5b5f67d22cf70f2e4a9 Mon Sep 17 00:00:00 2001 From: Yannik Korzikowski Date: Fri, 17 Apr 2020 17:40:50 +0200 Subject: [PATCH] added support for non tls ldap --- gitea-group-sync.go | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/gitea-group-sync.go b/gitea-group-sync.go index 24540e3..f2683e7 100644 --- a/gitea-group-sync.go +++ b/gitea-group-sync.go @@ -98,16 +98,26 @@ func mainJob() { } var ldapPort int + var ldapTls bool if len(os.Getenv("LDAP_TLS_PORT")) > 0 { port, err := strconv.Atoi(os.Getenv("LDAP_TLS_PORT")) ldapPort = port + ldapTls = true log.Printf("DialTLS:=%v:%d", ldapUrl, ldapPort) if err != nil { log.Println("LDAP_TLS_PORT is invalid.") } } else { - log.Println("LDAP_TLS_PORT is empty") - } + if len(os.Getenv("LDAP_PORT")) > 0 { + port, err := strconv.Atoi(os.Getenv("LDAP_PORT")) + ldapPort = port + ldapTls = false + log.Printf("Dial:=%v:%d", ldapUrl, ldapPort) + if err != nil { + log.Println("LDAP_PORT is invalid.") + } + } +} var ldapbindDN string if len(os.Getenv("BIND_DN")) == 0 { @@ -137,7 +147,14 @@ func mainJob() { ldapUserSearchBase = os.Getenv("LDAP_USER_SEARCH_BASE") } - l, err := ldap.DialTLS("tcp", fmt.Sprintf("%s:%d", ldapUrl, ldapPort), &tls.Config{InsecureSkipVerify: true}) + var l *ldap.Conn + var err error + if ldapTls { + l, err = ldap.DialTLS("tcp", fmt.Sprintf("%s:%d", ldapUrl, ldapPort), &tls.Config{InsecureSkipVerify: true}) + } else { + l, err = ldap.Dial("tcp", fmt.Sprintf("%s:%d", ldapUrl, ldapPort)) + } + if err != nil { fmt.Println(err) fmt.Println("Please set the correct values for all specifics.")