Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!(scanner/redhatbase): change cmd in scanUpdatablePackages #2084

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions scanner/alma.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,11 @@ func (o *alma) checkDeps() error {
}

func (o *alma) depsFast() []string {
if o.getServerInfo().Mode.IsOffline() {
return []string{}
}

// repoquery
// `rpm -qa` shows dnf-utils as yum-utils on RHEL8, CentOS8, Alma8, Rocky8
return []string{"yum-utils"}
return []string{}
}

func (o *alma) depsFastRoot() []string {
if o.getServerInfo().Mode.IsOffline() {
return []string{}
}

// repoquery
// `rpm -qa` shows dnf-utils as yum-utils on RHEL8, CentOS8, Alma8, Rocky8
return []string{"yum-utils"}
return []string{}
}

func (o *alma) depsDeep() []string {
Expand Down
22 changes: 6 additions & 16 deletions scanner/amazon.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package scanner

import (
"strings"
"time"

"golang.org/x/xerrors"

"github.com/future-architect/vuls/config"
Expand Down Expand Up @@ -55,27 +52,20 @@ func (o *amazon) depsFast() []string {
if o.getServerInfo().Mode.IsOffline() {
return []string{}
}
// repoquery
switch s := strings.Fields(o.getDistro().Release)[0]; s {
case "1", "2":
switch v, _ := o.Distro.MajorVersion(); v {
case 1, 2:
return []string{"yum-utils"}
default:
if _, err := time.Parse("2006.01", s); err == nil {
return []string{"yum-utils"}
}
return []string{"dnf-utils"}
return []string{}
}
}

func (o *amazon) depsFastRoot() []string {
switch s := strings.Fields(o.getDistro().Release)[0]; s {
case "1", "2":
switch v, _ := o.Distro.MajorVersion(); v {
case 1, 2:
return []string{"yum-utils"}
default:
if _, err := time.Parse("2006.01", s); err == nil {
return []string{"yum-utils"}
}
return []string{"dnf-utils"}
return []string{}
}
}

Expand Down
22 changes: 16 additions & 6 deletions scanner/centos.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package scanner

import (
"strings"

"github.com/future-architect/vuls/config"
"github.com/future-architect/vuls/logging"
"github.com/future-architect/vuls/models"
Expand Down Expand Up @@ -48,19 +50,27 @@ func (o *centos) depsFast() []string {
return []string{}
}

// repoquery
// `rpm -qa` shows dnf-utils as yum-utils on RHEL8, CentOS8, Alma8, Rocky8
return []string{"yum-utils"}
if strings.HasPrefix(o.Distro.Release, "stream") {
return []string{}
}
if v, _ := o.Distro.MajorVersion(); v < 6 {
return []string{"yum-utils"}
}
return []string{}
}

func (o *centos) depsFastRoot() []string {
if o.getServerInfo().Mode.IsOffline() {
return []string{}
}

// repoquery
// `rpm -qa` shows dnf-utils as yum-utils on RHEL8, CentOS8, Alma8, Rocky8
return []string{"yum-utils"}
if strings.HasPrefix(o.Distro.Release, "stream") {
return []string{}
}
if v, _ := o.Distro.MajorVersion(); v < 6 {
return []string{"yum-utils"}
}
return []string{}
}

func (o *centos) depsDeep() []string {
Expand Down
11 changes: 8 additions & 3 deletions scanner/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,17 @@ func (o *oracle) depsFast() []string {
if o.getServerInfo().Mode.IsOffline() {
return []string{}
}
// repoquery
return []string{"yum-utils"}
if v, _ := o.Distro.MajorVersion(); v < 6 {
return []string{"yum-utils"}
}
return []string{}
}

func (o *oracle) depsFastRoot() []string {
return []string{"yum-utils"}
if v, _ := o.Distro.MajorVersion(); v < 6 {
return []string{"yum-utils"}
}
return []string{}
}

func (o *oracle) depsDeep() []string {
Expand Down
62 changes: 57 additions & 5 deletions scanner/redhatbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -735,11 +735,63 @@ func (o *redhatBase) yumMakeCache() error {
}

func (o *redhatBase) scanUpdatablePackages() (models.Packages, error) {
isDnf := o.exec(util.PrependProxyEnv(`repoquery --version | grep dnf`), o.sudo.repoquery()).isSuccess()
cmd := `repoquery --all --pkgnarrow=updates --qf='%{NAME} %{EPOCH} %{VERSION} %{RELEASE} %{REPO}'`
if isDnf {
cmd = `repoquery --upgrades --qf='%{NAME} %{EPOCH} %{VERSION} %{RELEASE} %{REPONAME}' -q`
}
cmd := func() string {
const (
yum = `repoquery --all --pkgnarrow=updates --qf="%{NAME} %{EPOCH} %{VERSION} %{RELEASE} %{REPO}"`
dnf = `dnf repoquery --upgrades --qf="%{NAME} %{EPOCH} %{VERSION} %{RELEASE} %{REPONAME}" -q`
dnf5 = `dnf5 repoquery --upgrades --qf="%{NAME} %{EPOCH} %{VERSION} %{RELEASE} %{REPONAME}\n" -q`
)

switch o.Distro.Family {
case constant.OpenSUSE:
switch o.Distro.Release {
case "tumbleweed":
isDnf5 := o.exec(util.PrependProxyEnv(`rpm -q dnf5`), noSudo).isSuccess()
if isDnf5 {
return dnf5
}
return dnf
default:
return yum
}
case constant.OpenSUSELeap:
return dnf
case constant.SUSEEnterpriseServer, constant.SUSEEnterpriseDesktop:
if v, _ := o.Distro.MajorVersion(); v < 12 {
return yum
}
return dnf
case constant.Fedora:
v, _ := o.Distro.MajorVersion()
if v < 22 {
return yum
}
if v < 41 {
return dnf
}
return dnf5
case constant.Amazon:
switch v, _ := o.Distro.MajorVersion(); v {
case 1, 2:
return yum
default:
return dnf
}
case constant.CentOS:
if strings.HasPrefix(o.Distro.Release, "stream") {
return dnf
}
if v, _ := o.Distro.MajorVersion(); v < 6 {
return yum
}
return dnf
default:
if v, _ := o.Distro.MajorVersion(); v < 6 {
return yum
}
return dnf
}
}()
for _, repo := range o.getServerInfo().Enablerepo {
cmd += " --enablerepo=" + repo
}
Expand Down
7 changes: 4 additions & 3 deletions scanner/rhel.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ func (o *rhel) depsFastRoot() []string {
return []string{}
}

// repoquery
// `rpm -qa` shows dnf-utils as yum-utils on RHEL8, CentOS8, Alma8, Rocky8
return []string{"yum-utils"}
if v, _ := o.Distro.MajorVersion(); v < 6 {
return []string{"yum-utils"}
}
return []string{}
}

func (o *rhel) depsDeep() []string {
Expand Down
16 changes: 2 additions & 14 deletions scanner/rocky.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,11 @@ func (o *rocky) checkDeps() error {
}

func (o *rocky) depsFast() []string {
if o.getServerInfo().Mode.IsOffline() {
return []string{}
}

// repoquery
// `rpm -qa` shows dnf-utils as yum-utils on RHEL8, CentOS8, Alma8, Rocky8
return []string{"yum-utils"}
return []string{}
}

func (o *rocky) depsFastRoot() []string {
if o.getServerInfo().Mode.IsOffline() {
return []string{}
}

// repoquery
// `rpm -qa` shows dnf-utils as yum-utils on RHEL8, CentOS8, Alma8, Rocky8
return []string{"yum-utils"}
return []string{}
}

func (o *rocky) depsDeep() []string {
Expand Down
Loading