4 Commits

Author SHA1 Message Date
yo
8ac556ad8b Fix sigsev when conLdap.Close() after connection was droped remotely 2023-01-16 10:39:35 +01:00
yo
6e9947809c Change "Invalid IP" msgs to info loglevel 2022-05-17 15:54:12 +02:00
yo
874b1c541a Duh! 2022-05-17 11:51:23 +02:00
yo
28dd17ccee Dont create pidfile if not defined 2022-05-17 11:43:36 +02:00

View File

@ -26,7 +26,7 @@ import (
)
const (
version = "1.0.0-rc2"
version = "1.0.1"
)
var (
@ -227,7 +227,12 @@ func handleConnection(connClt net.Conn, conLdap *ldap.Conn) {
// First query netCache built with ipNetworkNumber
res, err := isIPContainedInNetCache(ip)
if err != nil {
if strings.EqualFold(err.Error(), fmt.Sprintf("Invalid IP: %s", ip)) {
// We don't want those msg to pollute logs
logstream.Info(err.Error())
} else {
logstream.Error(err.Error())
}
sendResponse(connClt, err.Error(), 500)
continue
}
@ -279,7 +284,11 @@ func searchLdap(searchReq *ldap.SearchRequest, attempt int) (*ldap.SearchResult,
if err != nil && strings.HasSuffix(err.Error(), "ldap: connection closed") {
logstream.Error("LDAP connection closed, retrying")
mutex.Lock()
// 16/01/2023: panic: runtime error: invalid memory address or nil pointer dereference
// probably bc connection is already closed
if conLdap != nil {
conLdap.Close()
}
conLdap, err = connectLdap()
mutex.Unlock()
if err != nil {
@ -297,12 +306,12 @@ func connectLdap() (*ldap.Conn, error) {
conLdap, err = ldap.DialURL(*ldapURL)
if err != nil {
logstream.Errorf("Error dialing LDAP on %s: %v\n", *ldapURL, err)
return conLdap, err
return nil, err
}
err = conLdap.Bind(*ldapUser, *ldapPass)
if err != nil {
logstream.Errorf("Error binding LDAP: ", err)
return conLdap, err
logstream.Errorf("Error binding LDAP: %s", err)
return nil, err
}
return conLdap, err
}
@ -349,7 +358,7 @@ func main() {
ldapBaseDN = fs.String("ldapDN", "", "LDAP base DN (also via LDAPDN env var)")
ldapUser = fs.String("ldapUser", "", "LDAP user DN (also via LDAPUSER env var)")
ldapPass = fs.String("ldapPass", "", "LDAP user password (also via LDAPPASS env var)")
pidFilePath = fs.String("pidfile", "/var/run/mynettcptable/mynettcptable.pid", "PID File (also via PIDFILE env var)")
pidFilePath = fs.String("pidfile", "", "PID File (also via PIDFILE env var). Creates pidfile only if defined")
refreshInterval = fs.Int("refresh", 300, "Net cache update interval in seconds")
timeout = fs.Int("timeout", 5, "timeout in seconds")
_ = fs.String("config", "", "config file (optional)")
@ -403,11 +412,13 @@ func main() {
logstream.Hooks.Add(hook)
}
if len(*pidFilePath) > 0 {
if pid, err := pidfile.Create(*pidFilePath); err != nil {
logstream.Fatal(err)
} else {
defer pid.Clear()
}
}
logstream.Infof("Start listening for incoming connections on %s\n", *listen)
run()