Browse Source

added support for non tls ldap

pull/2/head
Yannik Korzikowski 5 years ago
parent
commit
7225deb7e1
No known key found for this signature in database
GPG Key ID: C7BE4B99FF3F9A08
  1. 23
      gitea-group-sync.go

23
gitea-group-sync.go

@ -98,16 +98,26 @@ func mainJob() {
} }


var ldapPort int var ldapPort int
var ldapTls bool
if len(os.Getenv("LDAP_TLS_PORT")) > 0 { if len(os.Getenv("LDAP_TLS_PORT")) > 0 {
port, err := strconv.Atoi(os.Getenv("LDAP_TLS_PORT")) port, err := strconv.Atoi(os.Getenv("LDAP_TLS_PORT"))
ldapPort = port ldapPort = port
ldapTls = true
log.Printf("DialTLS:=%v:%d", ldapUrl, ldapPort) log.Printf("DialTLS:=%v:%d", ldapUrl, ldapPort)
if err != nil { if err != nil {
log.Println("LDAP_TLS_PORT is invalid.") log.Println("LDAP_TLS_PORT is invalid.")
} }
} else { } 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 var ldapbindDN string
if len(os.Getenv("BIND_DN")) == 0 { if len(os.Getenv("BIND_DN")) == 0 {
@ -137,7 +147,14 @@ func mainJob() {
ldapUserSearchBase = os.Getenv("LDAP_USER_SEARCH_BASE") 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 { if err != nil {
fmt.Println(err) fmt.Println(err)
fmt.Println("Please set the correct values for all specifics.") fmt.Println("Please set the correct values for all specifics.")

Loading…
Cancel
Save