fix(portscan): to keep backward compatibility before v0.13.0 (#1076)

This commit is contained in:
Kota Kanbe
2020-11-19 16:54:36 +09:00
committed by GitHub
parent d02535d053
commit 3f8de02683
9 changed files with 168 additions and 131 deletions

View File

@@ -491,15 +491,20 @@ func (o *redhatBase) yumPs() error {
pidLoadedFiles[pid] = append(pidLoadedFiles[pid], ss...)
}
pidListenPorts := map[string][]models.ListenPort{}
pidListenPorts := map[string][]models.PortStat{}
stdout, err = o.lsOfListen()
if err != nil {
return xerrors.Errorf("Failed to ls of: %w", err)
}
portPids := o.parseLsOf(stdout)
for port, pids := range portPids {
for ipPort, pids := range portPids {
for _, pid := range pids {
pidListenPorts[pid] = append(pidListenPorts[pid], o.parseListenPorts(port))
portStat, err := models.NewPortStat(ipPort)
if err != nil {
o.log.Warnf("Failed to parse ip:port: %s, err: %+v", ipPort, err)
continue
}
pidListenPorts[pid] = append(pidListenPorts[pid], *portStat)
}
}
@@ -521,9 +526,9 @@ func (o *redhatBase) yumPs() error {
procName = pidNames[pid]
}
proc := models.AffectedProcess{
PID: pid,
Name: procName,
ListenPorts: pidListenPorts[pid],
PID: pid,
Name: procName,
ListenPortStats: pidListenPorts[pid],
}
for fqpn := range uniq {