diff --git a/cmd/vuls/main.go b/cmd/vuls/main.go index c11fbcfac5..6ba380f240 100644 --- a/cmd/vuls/main.go +++ b/cmd/vuls/main.go @@ -29,7 +29,7 @@ func main() { flag.Parse() if *v { - fmt.Printf("vuls %s %s\n", config.Version, config.Revision) + fmt.Printf("vuls-%s-%s\n", config.Version, config.Revision) os.Exit(int(subcommands.ExitSuccess)) } diff --git a/scan/alpine.go b/scan/alpine.go index 218d021c6b..f90a6fa391 100644 --- a/scan/alpine.go +++ b/scan/alpine.go @@ -32,19 +32,16 @@ func newAlpine(c config.ServerInfo) *alpine { // Alpine // https://github.com/mizzy/specinfra/blob/master/lib/specinfra/helper/detect_os/alpine.rb -func detectAlpine(c config.ServerInfo) (itsMe bool, os osTypeInterface) { - os = newAlpine(c) - +func detectAlpine(c config.ServerInfo) (bool, osTypeInterface) { if r := exec(c, "ls /etc/alpine-release", noSudo); !r.isSuccess() { - return false, os + return false, nil } - if r := exec(c, "cat /etc/alpine-release", noSudo); r.isSuccess() { + os := newAlpine(c) os.setDistro(config.Alpine, strings.TrimSpace(r.Stdout)) return true, os } - - return false, os + return false, nil } func (o *alpine) checkScanMode() error { diff --git a/scan/debian.go b/scan/debian.go index 81884c3961..ff11001ab3 100644 --- a/scan/debian.go +++ b/scan/debian.go @@ -40,18 +40,16 @@ func newDebian(c config.ServerInfo) *debian { // Ubuntu, Debian, Raspbian // https://github.com/serverspec/specinfra/blob/master/lib/specinfra/helper/detect_os/debian.rb -func detectDebian(c config.ServerInfo) (itsMe bool, deb osTypeInterface, err error) { - deb = newDebian(c) - +func detectDebian(c config.ServerInfo) (bool, osTypeInterface, error) { if r := exec(c, "ls /etc/debian_version", noSudo); !r.isSuccess() { if r.Error != nil { - return false, deb, nil + return false, nil, nil } if r.ExitStatus == 255 { - return false, deb, xerrors.Errorf("Unable to connect via SSH. Scan with -vvv option to print SSH debugging messages and check SSH settings. If you have never SSH to the host to be scanned, SSH to the host before scanning in order to add the HostKey. %s@%s port: %s\n%s", c.User, c.Host, c.Port, r) + return false, nil, xerrors.Errorf("Unable to connect via SSH. Scan with -vvv option to print SSH debugging messages and check SSH settings. If you have never SSH to the host to be scanned, SSH to the host before scanning in order to add the HostKey. %s@%s port: %s\n%s", c.User, c.Host, c.Port, r) } util.Log.Debugf("Not Debian like Linux. %s", r) - return false, deb, nil + return false, nil, nil } // Raspbian @@ -62,8 +60,8 @@ func detectDebian(c config.ServerInfo) (itsMe bool, deb osTypeInterface, err err // Raspbian GNU/Linux 7 \n \l result := strings.Fields(r.Stdout) if len(result) > 2 && result[0] == config.Raspbian { - distro := strings.ToLower(trim(result[0])) - deb.setDistro(distro, trim(result[2])) + deb := newDebian(c) + deb.setDistro(strings.ToLower(trim(result[0])), trim(result[2])) return true, deb, nil } } @@ -76,10 +74,10 @@ func detectDebian(c config.ServerInfo) (itsMe bool, deb osTypeInterface, err err re := regexp.MustCompile(`(?s)^Distributor ID:\s*(.+?)\n*Release:\s*(.+?)$`) result := re.FindStringSubmatch(trim(r.Stdout)) + deb := newDebian(c) if len(result) == 0 { deb.setDistro("debian/ubuntu", "unknown") - util.Log.Warnf( - "Unknown Debian/Ubuntu version. lsb_release -ir: %s", r) + util.Log.Warnf("Unknown Debian/Ubuntu version. lsb_release -ir: %s", r) } else { distro := strings.ToLower(trim(result[1])) deb.setDistro(distro, trim(result[2])) @@ -95,6 +93,7 @@ func detectDebian(c config.ServerInfo) (itsMe bool, deb osTypeInterface, err err // DISTRIB_DESCRIPTION="Ubuntu 14.04.2 LTS" re := regexp.MustCompile(`(?s)^DISTRIB_ID=(.+?)\n*DISTRIB_RELEASE=(.+?)\n.*$`) result := re.FindStringSubmatch(trim(r.Stdout)) + deb := newDebian(c) if len(result) == 0 { util.Log.Warnf( "Unknown Debian/Ubuntu. cat /etc/lsb-release: %s", r) @@ -109,12 +108,13 @@ func detectDebian(c config.ServerInfo) (itsMe bool, deb osTypeInterface, err err // Debian cmd := "cat /etc/debian_version" if r := exec(c, cmd, noSudo); r.isSuccess() { + deb := newDebian(c) deb.setDistro(config.Debian, trim(r.Stdout)) return true, deb, nil } util.Log.Debugf("Not Debian like Linux: %s", c.ServerName) - return false, deb, nil + return false, nil, nil } func trim(str string) string { diff --git a/scan/freebsd.go b/scan/freebsd.go index a80c86da08..3cd61336b0 100644 --- a/scan/freebsd.go +++ b/scan/freebsd.go @@ -31,15 +31,14 @@ func newBsd(c config.ServerInfo) *bsd { } //https://github.com/mizzy/specinfra/blob/master/lib/specinfra/helper/detect_os/freebsd.rb -func detectFreebsd(c config.ServerInfo) (itsMe bool, bsd osTypeInterface) { - bsd = newBsd(c) - +func detectFreebsd(c config.ServerInfo) (bool, osTypeInterface) { // Prevent from adding `set -o pipefail` option c.Distro = config.Distro{Family: config.FreeBSD} if r := exec(c, "uname", noSudo); r.isSuccess() { if strings.Contains(strings.ToLower(r.Stdout), config.FreeBSD) == true { if b := exec(c, "freebsd-version", noSudo); b.isSuccess() { + bsd := newBsd(c) rel := strings.TrimSpace(b.Stdout) bsd.setDistro(config.FreeBSD, rel) return true, bsd @@ -47,7 +46,7 @@ func detectFreebsd(c config.ServerInfo) (itsMe bool, bsd osTypeInterface) { } } util.Log.Debugf("Not FreeBSD. servernam: %s", c.ServerName) - return false, bsd + return false, nil } func (o *bsd) checkScanMode() error { diff --git a/scan/pseudo.go b/scan/pseudo.go index 7287e9bf49..526a56c9a6 100644 --- a/scan/pseudo.go +++ b/scan/pseudo.go @@ -12,9 +12,12 @@ type pseudo struct { } func detectPseudo(c config.ServerInfo) (itsMe bool, pseudo osTypeInterface, err error) { - p := newPseudo(c) - p.setDistro(config.ServerTypePseudo, "") - return c.Type == config.ServerTypePseudo, p, nil + if c.Type == config.ServerTypePseudo { + p := newPseudo(c) + p.setDistro(config.ServerTypePseudo, "") + return true, p, nil + } + return false, nil, nil } func newPseudo(c config.ServerInfo) *pseudo { diff --git a/scan/suse.go b/scan/suse.go index ed8b39fb53..5fee8103ee 100644 --- a/scan/suse.go +++ b/scan/suse.go @@ -36,10 +36,10 @@ func newSUSE(c config.ServerInfo) *suse { // https://github.com/mizzy/specinfra/blob/master/lib/specinfra/helper/detect_os/suse.rb func detectSUSE(c config.ServerInfo) (bool, osTypeInterface) { - s := newSUSE(c) if r := exec(c, "ls /etc/os-release", noSudo); r.isSuccess() { if r := exec(c, "zypper -V", noSudo); r.isSuccess() { if r := exec(c, "cat /etc/os-release", noSudo); r.isSuccess() { + s := newSUSE(c) name, ver := s.parseOSRelease(r.Stdout) s.setDistro(name, ver) return true, s @@ -52,6 +52,7 @@ func detectSUSE(c config.ServerInfo) (bool, osTypeInterface) { result := re.FindStringSubmatch(strings.TrimSpace(r.Stdout)) if len(result) == 2 { //TODO check opensuse or opensuse.leap + s := newSUSE(c) s.setDistro(config.OpenSUSE, result[1]) return true, s } @@ -63,18 +64,19 @@ func detectSUSE(c config.ServerInfo) (bool, osTypeInterface) { re = regexp.MustCompile(`PATCHLEVEL = (\d+)`) result = re.FindStringSubmatch(strings.TrimSpace(r.Stdout)) if len(result) == 2 { + s := newSUSE(c) s.setDistro(config.SUSEEnterpriseServer, fmt.Sprintf("%s.%s", version, result[1])) return true, s } } util.Log.Warnf("Failed to parse SUSE Linux version: %s", r) - return true, s + return true, newSUSE(c) } } } util.Log.Debugf("Not SUSE Linux. servername: %s", c.ServerName) - return false, s + return false, nil } func (o *suse) parseOSRelease(content string) (name string, ver string) { diff --git a/util/logutil.go b/util/logutil.go index a4d8c5601c..1fb0478915 100644 --- a/util/logutil.go +++ b/util/logutil.go @@ -86,8 +86,9 @@ func NewCustomLogger(server config.ServerInfo) *logrus.Entry { } } - fields := logrus.Fields{"prefix": whereami} - return log.WithFields(fields) + entry := log.WithFields(logrus.Fields{"prefix": whereami}) + entry.Infof("vuls-%s-%s", config.Version, config.Revision) + return entry } // GetDefaultLogDir returns default log directory