diff --git a/mxrouter.go b/mxrouter.go index 1944276..befcb00 100644 --- a/mxrouter.go +++ b/mxrouter.go @@ -43,7 +43,6 @@ var ( defDomain *string ) - func ldapSearch(conLdap *ldap.Conn, searchReq *ldap.SearchRequest, attempt int) (*ldap.SearchResult, error) { mutex.Lock() result, err := conLdap.Search(searchReq) @@ -64,7 +63,6 @@ func ldapSearch(conLdap *ldap.Conn, searchReq *ldap.SearchRequest, attempt int) return result, err } - func handleConnection(connClt net.Conn, conLdap *ldap.Conn) { var s string var mxdom string @@ -120,14 +118,6 @@ func handleConnection(connClt net.Conn, conLdap *ldap.Conn) { return } - // L'attribut n'existe pas - if len(result.Entries[0].Attributes) == 0 { - logstream.Err(fmt.Sprintf("Error searching into LDAP: Attribute %s not found for entry %s\n", *ldapAttr, result.Entries[0])) - s := strings.Replace(fmt.Sprintf("Attribute not found: %s", *ldapAttr), " ", "%20", -1) - response := fmt.Sprintf("500 %s\n", s) - connClt.Write([]byte(response)) - return - } if len(result.Entries) != 1 { if *debug { logstream.Debug("Got no result, returning 500") @@ -137,6 +127,16 @@ func handleConnection(connClt net.Conn, conLdap *ldap.Conn) { connClt.Write([]byte(response)) return } + + // L'attribut n'existe pas + if len(result.Entries[0].Attributes) == 0 { + logstream.Err(fmt.Sprintf("Error searching into LDAP: Attribute %s not found for entry %s\n", *ldapAttr, result.Entries[0])) + s := strings.Replace(fmt.Sprintf("Attribute not found: %s", *ldapAttr), " ", "%20", -1) + response := fmt.Sprintf("500 %s\n", s) + connClt.Write([]byte(response)) + return + } + if *debug { logstream.Debug("Got result, returning " + result.Entries[0].Attributes[0].Values[0]) }