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

🐛 use short windows computer info command as fallback always #4760

Merged
merged 1 commit into from
Oct 16, 2024
Merged
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
20 changes: 5 additions & 15 deletions providers/os/resources/windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package resources
import (
"errors"
"io"
"strings"

"go.mondoo.com/cnquery/v11/llx"
"go.mondoo.com/cnquery/v11/providers-sdk/v1/plugin"
Expand All @@ -30,27 +29,18 @@ func (s *mqlWindows) computerInfo() (map[string]interface{}, error) {

// If the exit code is not 0, then we got an error and we should read stderr for details
if executedCmd.ExitStatus != 0 {
stderr, err := io.ReadAll(executedCmd.Stderr)
// First attempt to use the short computer info command
encodedCmd := powershell.Encode(windows.PSGetComputerInfoShort)
executedCmd, err = conn.RunCommand(encodedCmd)
if err != nil {
return nil, err
}

// If the command is too long, then we fallback to the short command
if strings.HasPrefix(string(stderr), "The command line is too long.") {
encodedCmd := powershell.Encode(windows.PSGetComputerInfoShort)
executedCmd, err = conn.RunCommand(encodedCmd)
if executedCmd.ExitStatus != 0 {
stderr, err := io.ReadAll(executedCmd.Stderr)
if err != nil {
return nil, err
}

if executedCmd.ExitStatus != 0 {
stderr, err := io.ReadAll(executedCmd.Stderr)
if err != nil {
return nil, err
}
return nil, errors.New("failed to retrieve computer info: " + string(stderr))
}
} else {
return nil, errors.New("failed to retrieve computer info: " + string(stderr))
}
}
Expand Down
Loading