@@ -6,11 +6,14 @@ package packages
66import (
77 "fmt"
88 "io"
9+ "path/filepath"
910 "strings"
1011
1112 "github.com/cockroachdb/errors"
13+ "github.com/rs/zerolog/log"
1214 "go.mondoo.com/cnquery/v12/providers-sdk/v1/inventory"
1315 "go.mondoo.com/cnquery/v12/providers/os/connection/shared"
16+ "go.mondoo.com/cnquery/v12/providers/os/resources/parsers"
1417 "go.mondoo.com/cnquery/v12/providers/os/resources/purl"
1518 plist "howett.net/plist"
1619)
@@ -19,8 +22,18 @@ const (
1922 MacosPkgFormat = "macos"
2023)
2124
25+ type sysProfilerItem struct {
26+ Name string `plist:"_name"`
27+ Version string `plist:"version"`
28+ Path string `plist:"path"`
29+ }
30+
31+ type sysProfiler struct {
32+ Items []sysProfilerItem `plist:"_items"`
33+ }
34+
2235// parse macos system version property list
23- func ParseMacOSPackages (platform * inventory.Platform , input io.Reader ) ([]Package , error ) {
36+ func ParseMacOSPackages (conn shared. Connection , platform * inventory.Platform , input io.Reader ) ([]Package , error ) {
2437 var r io.ReadSeeker
2538 r , ok := input .(io.ReadSeeker )
2639
@@ -33,16 +46,6 @@ func ParseMacOSPackages(platform *inventory.Platform, input io.Reader) ([]Packag
3346 r = strings .NewReader (string (packageList ))
3447 }
3548
36- type sysProfilerItems struct {
37- Name string `plist:"_name"`
38- Version string `plist:"version"`
39- Path string `plist:"path"`
40- }
41-
42- type sysProfiler struct {
43- Items []sysProfilerItems `plist:"_items"`
44- }
45-
4649 var data []sysProfiler
4750 decoder := plist .NewDecoder (r )
4851 err := decoder .Decode (& data )
@@ -56,13 +59,15 @@ func ParseMacOSPackages(platform *inventory.Platform, input io.Reader) ([]Packag
5659
5760 pkgs := make ([]Package , len (data [0 ].Items ))
5861 for i , entry := range data [0 ].Items {
62+ // We need a special handling for Firefox to determine ESR installations
63+ purlQualifiers := getPurlQualifiers (conn , entry )
5964 pkgs [i ].Name = entry .Name
6065 pkgs [i ].Version = entry .Version
6166 pkgs [i ].Format = MacosPkgFormat
6267 pkgs [i ].FilesAvailable = PkgFilesIncluded
6368 pkgs [i ].Arch = platform .Arch
6469 pkgs [i ].PUrl = purl .NewPackageURL (
65- platform , purl .TypeMacos , entry .Name , entry .Version ,
70+ platform , purl .TypeMacos , entry .Name , entry .Version , purl . WithQualifiers ( purlQualifiers ),
6671 ).String ()
6772 if entry .Path != "" {
6873 pkgs [i ].Files = []FileRecord {
@@ -96,7 +101,7 @@ func (mpm *MacOSPkgManager) List() ([]Package, error) {
96101 return nil , fmt .Errorf ("could not read package list" )
97102 }
98103
99- return ParseMacOSPackages (mpm .platform , cmd .Stdout )
104+ return ParseMacOSPackages (mpm .conn , mpm . platform , cmd .Stdout )
100105}
101106
102107func (mpm * MacOSPkgManager ) Available () (map [string ]PackageUpdate , error ) {
@@ -107,3 +112,38 @@ func (mpm *MacOSPkgManager) Files(name string, version string, arch string) ([]F
107112 // nothing extra to be done here since the list is already included in the package list
108113 return nil , nil
109114}
115+
116+ func getPurlQualifiers (conn shared.Connection , entry sysProfilerItem ) map [string ]string {
117+ qualifiers := make (map [string ]string )
118+ if entry .Name == "Firefox" {
119+ appIni := ""
120+ if entry .Path != "" {
121+ appIni = filepath .Join (entry .Path , "Contents" , "Resources" , "application.ini" )
122+ }
123+ if appIni != "" {
124+ f , err := conn .FileSystem ().Open (appIni )
125+ if err != nil {
126+ log .Debug ().Err (err ).Msg ("could not open application.ini" )
127+ return nil
128+ }
129+ defer f .Close ()
130+ content , err := io .ReadAll (f )
131+ if err != nil {
132+ log .Debug ().Err (err ).Msg ("could not read application.ini" )
133+ return nil
134+ }
135+ ini := parsers .ParseIni (string (content ), "=" )
136+ if ini != nil {
137+ if data , ok := ini .Fields ["App" ]; ok {
138+ fields , ok := data .(map [string ]any )
139+ if ok {
140+ if name , ok := fields ["RemotingName" ]; ok {
141+ qualifiers ["remoting-name" ] = name .(string )
142+ }
143+ }
144+ }
145+ }
146+ }
147+ }
148+ return qualifiers
149+ }
0 commit comments