5 Commits

Author SHA1 Message Date
yo 90e0af59c3 Fix ldapAttr typo 2026-07-14 16:19:39 +02:00
yo b7a6689b9b v0.9.9 : Handle nil connection when LDAP server is down 2026-07-14 16:18:42 +02:00
yo ab597c221b Merge branch 'master' of ssh://git.nosd.in:2222/yo/mxrouter 2021-02-11 15:03:35 +01:00
yo add02d2554 BUGFIX 2021-02-11 15:02:50 +01:00
gitadm 558519f048 Move "Closing connection" message to Debug mode 2021-02-10 22:01:53 +01:00
2 changed files with 30 additions and 15 deletions
+1 -1
View File
@@ -6,5 +6,5 @@ ldapPass here_lies_the_password
# "domain" sera ajoute a relayName pour former le FQDN
domain example.org
# Le nom de l'attribut LDAP contenant le relais a retourner
lapAttr relayName
ldapAttr relayName
+29 -14
View File
@@ -33,7 +33,7 @@ import (
)
const (
version = "0.9.8"
version = "0.9.9"
// Match le nom de domaine, soit les 2 dernieres chaines separees par un point.
// Peut aussi terminer par un point (Ex: srv.domaine.com. => domaine.com)
DomainRegexpFormat = `([0-9A-Za-z\-]*)\.([0-9A-Za-z\-]*)(?:\.)?$`
@@ -55,22 +55,38 @@ var (
timeout *int
)
// attempt is useless now. It was introduced to break after N attempts, but this is not implemented. Should it be?
func ldapSearch(searchReq *ldap.SearchRequest, attempt int) (*ldap.SearchResult, error) {
mutex.Lock()
result, err := conLdap.Search(searchReq)
mutex.Unlock()
// Let's just manage connection errors here
if err != nil && strings.HasSuffix(err.Error(), "ldap: connection closed") {
logstream.Err("LDAP connection closed, retrying")
mutex.Lock()
conLdap.Close()
conLdap, err = connectLdap()
mutex.Unlock()
if err != nil {
return result, err
} else {
attempt = attempt + 1
return ldapSearch(searchReq, attempt)
if err != nil {
if strings.HasSuffix(err.Error(), "ldap: connection closed") {
logstream.Err("LDAP connection closed, retrying")
mutex.Lock()
conLdap.Close()
conLdap, err = connectLdap()
mutex.Unlock()
if err != nil {
return result, err
} else {
attempt = attempt + 1
return ldapSearch(searchReq, attempt)
}
} else if err == ldap.ErrNilConnection {
logstream.Err("LDAP connection is nil, reconnecting")
mutex.Lock()
// conLdap is nil so this would be a sigsegv/panic
//conLdap.Close()
conLdap, err = connectLdap()
mutex.Unlock()
if err != nil {
return result, err
} else {
attempt = attempt + 1
return ldapSearch(searchReq, attempt)
}
}
}
@@ -142,8 +158,7 @@ func handleConnection(connClt net.Conn, conLdap *ldap.Conn) {
group := re.FindSubmatch([]byte(mxs[0].Host))
if len(group) < 3 || len(group[2]) == 0 {
logstream.Err(fmt.Sprintln("MX format incorrect: ", mxs[0].Host))
w
s := fmt.Sprintf("MX format incorrect: %s", err.Error())
s := fmt.Sprintf("MX format incorrect: %s", mxs[0].Host)
sendResponse(connClt, s, 500)
continue
}