github.com/noqcks/syft@v0.0.0-20230920222752-a9e2c4e288e5/syft/pkg/rpm_metadata.go (about) 1 package pkg 2 3 import ( 4 "sort" 5 6 "github.com/scylladb/go-set/strset" 7 8 "github.com/anchore/syft/syft/file" 9 ) 10 11 // /var/lib/rpm/... is the typical path for most distributions 12 // /usr/share/rpm/... is common for rpm-ostree distributions (coreos-like) 13 // Packages is the legacy Berkely db based format 14 // Packages.db is the "ndb" format used in SUSE 15 // rpmdb.sqlite is the sqlite format used in fedora + derivates 16 const RpmDBGlob = "**/{var/lib,usr/share,usr/lib/sysimage}/rpm/{Packages,Packages.db,rpmdb.sqlite}" 17 18 // Used in CBL-Mariner distroless images 19 const RpmManifestGlob = "**/var/lib/rpmmanifest/container-manifest-2" 20 21 var _ FileOwner = (*RpmMetadata)(nil) 22 23 // RpmMetadata represents all captured data for a RPM DB package entry. 24 type RpmMetadata struct { 25 Name string `json:"name"` 26 Version string `json:"version"` 27 Epoch *int `json:"epoch" cyclonedx:"epoch" jsonschema:"nullable"` 28 Arch string `json:"architecture"` 29 Release string `json:"release" cyclonedx:"release"` 30 SourceRpm string `json:"sourceRpm" cyclonedx:"sourceRpm"` 31 Size int `json:"size" cyclonedx:"size"` 32 Vendor string `json:"vendor"` 33 ModularityLabel string `json:"modularityLabel"` 34 Files []RpmdbFileRecord `json:"files"` 35 } 36 37 // RpmdbFileRecord represents the file metadata for a single file attributed to a RPM package. 38 type RpmdbFileRecord struct { 39 Path string `json:"path"` 40 Mode RpmdbFileMode `json:"mode"` 41 Size int `json:"size"` 42 Digest file.Digest `json:"digest"` 43 UserName string `json:"userName"` 44 GroupName string `json:"groupName"` 45 Flags string `json:"flags"` 46 } 47 48 // RpmdbFileMode is the raw file mode for a single file. This can be interpreted as the linux stat.h mode (see https://pubs.opengroup.org/onlinepubs/007908799/xsh/sysstat.h.html) 49 type RpmdbFileMode uint16 50 51 func (m RpmMetadata) OwnedFiles() (result []string) { 52 s := strset.New() 53 for _, f := range m.Files { 54 if f.Path != "" { 55 s.Add(f.Path) 56 } 57 } 58 result = s.List() 59 sort.Strings(result) 60 return result 61 }