This commit is contained in:
Chris Mann 2023-07-23 13:02:09 +02:00
parent 82acecbfe8
commit f66f51019b
3 changed files with 30 additions and 13 deletions

View file

@ -84,8 +84,11 @@ func passwordLost(user User, config *ConfigFile, ldapConn *ldap.Conn) error {
} }
func passwordFound(user User, config *ConfigFile, ldapConn *ldap.Conn) (bool, error) { func passwordFound(user User, config *ConfigFile, ldapConn *ldap.Conn) (bool, error) {
l := openLdap(config) l, err := openLdap(config)
err := l.Bind(user.DN, user.Password) if err != nil {
return false, err
}
err = l.Bind(user.DN, user.Password)
if err != nil { if err != nil {
return false, err return false, err
} }

View file

@ -55,8 +55,12 @@ type PasswordLostData struct {
} }
func openNewUserLdap(config *ConfigFile) (*ldap.Conn, error) { func openNewUserLdap(config *ConfigFile) (*ldap.Conn, error) {
l := openLdap(config) l, err := openLdap(config)
err := l.Bind(config.NewUserDN, config.NewUserPassword) if err != nil {
log.Printf(fmt.Sprintf("openNewUserLdap : %v %v", err, l))
// data.ErrorMessage = err.Error()
}
err = l.Bind(config.NewUserDN, config.NewUserPassword)
if err != nil { if err != nil {
log.Printf(fmt.Sprintf("openNewUserLdap : %v %v", err, l)) log.Printf(fmt.Sprintf("openNewUserLdap : %v %v", err, l))
// data.ErrorMessage = err.Error() // data.ErrorMessage = err.Error()

View file

@ -1,8 +1,8 @@
package main package main
import ( import (
"fmt" "crypto/tls"
"log" "net"
"math/rand" "math/rand"
@ -10,15 +10,25 @@ import (
// "golang.org/x/text/encoding/unicode" // "golang.org/x/text/encoding/unicode"
) )
func openLdap(config *ConfigFile) *ldap.Conn { func openLdap(config *ConfigFile) (*ldap.Conn, error) {
l, err := ldap.DialURL(config.LdapServerAddr) if config.LdapTLS {
if err != nil { tlsConf := &tls.Config{
log.Printf(fmt.Sprint("Erreur connect LDAP %v", err)) ServerName: config.LdapServerAddr,
log.Printf(fmt.Sprint("Erreur connect LDAP %v", config.LdapServerAddr)) InsecureSkipVerify: true,
return nil }
return ldap.DialTLS("tcp", net.JoinHostPort(config.LdapServerAddr, "636"), tlsConf)
} else { } else {
return l return ldap.DialURL("ldap://" + config.LdapServerAddr)
} }
// l, err := ldap.DialURL(config.LdapServerAddr)
// if err != nil {
// log.Printf(fmt.Sprint("Erreur connect LDAP %v", err))
// log.Printf(fmt.Sprint("Erreur connect LDAP %v", config.LdapServerAddr))
// return nil
// } else {
// return l
// }
} }
func suggestPassword() string { func suggestPassword() string {