From 622f91859702f115afee529e4d8a3bd59a41234f Mon Sep 17 00:00:00 2001 From: Christoph Hartmann Date: Mon, 8 Jan 2024 10:32:54 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20only=20use=20native=20registry?= =?UTF-8?q?=20key=20implementation=20if=20we=20are=20scanning=20local=20ma?= =?UTF-8?q?chine=20from=20windows=20(#2979)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- providers/os/resources/python.go | 2 ++ providers/os/resources/registrykey.go | 11 +++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/providers/os/resources/python.go b/providers/os/resources/python.go index 1d4aa43113..f48f16c25f 100644 --- a/providers/os/resources/python.go +++ b/providers/os/resources/python.go @@ -368,6 +368,8 @@ func genericSearch(afs *afero.Afero) ([]python.PackageDetails, error) { func darwinSearch(afs *afero.Afero) ([]python.PackageDetails, error) { allResults := []python.PackageDetails{} + // TODO: this does not work properly, we need to use the connection here to determine if we are running on a + // local connection if runtime.GOOS != "darwin" { return allResults, nil } diff --git a/providers/os/resources/registrykey.go b/providers/os/resources/registrykey.go index f7d4b46573..ca78d93039 100644 --- a/providers/os/resources/registrykey.go +++ b/providers/os/resources/registrykey.go @@ -11,6 +11,7 @@ import ( "go.mondoo.com/cnquery/v9/llx" "go.mondoo.com/cnquery/v9/providers-sdk/v1/plugin" "go.mondoo.com/cnquery/v9/providers/os/connection/mock" + "go.mondoo.com/cnquery/v9/providers/os/connection/shared" "go.mondoo.com/cnquery/v9/providers/os/resources/powershell" "go.mondoo.com/cnquery/v9/providers/os/resources/windows" "go.mondoo.com/ranger-rpc/codes" @@ -22,8 +23,9 @@ func (k *mqlRegistrykey) id() (string, error) { } func (k *mqlRegistrykey) exists() (bool, error) { + conn := k.MqlRuntime.Connection.(shared.Connection) // if we are running locally on windows, we can use native api - if runtime.GOOS == "windows" { + if conn.Type() == shared.Type_Local && runtime.GOOS == "windows" { items, err := windows.GetNativeRegistryKeyItems(k.Path.Data) if err == nil && len(items) > 0 { return true, nil @@ -69,7 +71,8 @@ func (k *mqlRegistrykey) exists() (bool, error) { // GetEntries returns a list of registry key property resources func (k *mqlRegistrykey) getEntries() ([]windows.RegistryKeyItem, error) { // if we are running locally on windows, we can use native api - if runtime.GOOS == "windows" { + conn := k.MqlRuntime.Connection.(shared.Connection) + if conn.Type() == shared.Type_Local && runtime.GOOS == "windows" { return windows.GetNativeRegistryKeyItems(k.Path.Data) } @@ -162,10 +165,10 @@ func (k *mqlRegistrykey) items() ([]interface{}, error) { } func (k *mqlRegistrykey) children() ([]interface{}, error) { + conn := k.MqlRuntime.Connection.(shared.Connection) res := []interface{}{} - var children []windows.RegistryKeyChild - if runtime.GOOS == "windows" { + if conn.Type() == shared.Type_Local && runtime.GOOS == "windows" { var err error children, err = windows.GetNativeRegistryKeyChildren(k.Path.Data) if err != nil {