Resolves #34311. It's not urgent because: - Orbit uses a fallback mechanism to fetch the device UUID (using SMBIOS): https://github.com/fleetdm/fleet/blob/d3092bbc640ebd8e92c13476f0ca8772b98d425e/orbit/pkg/platform/platform_windows.go#L354-L359 - Only used by the `mdm_bridge` table implementation. Which is only used by CIS policies (not for critical MDM functionality). - [X] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. ## Testing - [X] QA'd all new/changed functionality manually Tested on both a Windows 11 VM with 25H2 and real Windows 11 device with 23H2. The extracted UUID matches the UUID reported by osquery. ## fleetd/orbit/Fleet Desktop - [X] Verified compatibility with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)) - [X] If the change applies to only one platform, confirmed that `runtime.GOOS` is used as needed to isolate changes - [X] Verified that fleetd runs on macOS, Linux and Windows - [X] Verified auto-update works from the released version of component to the new version (see [tools/tuf/test](../tools/tuf/test/README.md)) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - Updated Windows device identification to obtain the system UUID using COM-based WMI querying instead of relying on the deprecated WMIC utility. - Removed the WMIC dependency from the MDM bridge table implementation. - Improved cross-platform UUID handling by removing unused non-Windows UUID placeholder logic and related constants. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
85 lines
2.1 KiB
Go
85 lines
2.1 KiB
Go
package platform
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"strings"
|
|
|
|
gopsutil_process "github.com/shirou/gopsutil/v4/process"
|
|
)
|
|
|
|
var (
|
|
ErrProcessNotFound = errors.New("process not found")
|
|
ErrComChannelNotFound = errors.New("comm channel not found")
|
|
)
|
|
|
|
type UUIDSource string
|
|
|
|
const (
|
|
UUIDSourceWMI = "UUID_Source_WMI"
|
|
UUIDSourceHardware = "UUID_Source_Hardware"
|
|
)
|
|
|
|
// getProcessesByName returns all the running processes with the given prefix in their name.
|
|
func getProcessesByName(namePrefix string) ([]*gopsutil_process.Process, error) {
|
|
if namePrefix == "" {
|
|
return nil, errors.New("process name prefix should not be empty")
|
|
}
|
|
|
|
processes, err := gopsutil_process.Processes()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var foundProcesses []*gopsutil_process.Process
|
|
for _, process := range processes {
|
|
processName, err := process.Name()
|
|
if err != nil {
|
|
// No need to print errors here as this method might file for system processes
|
|
continue
|
|
}
|
|
|
|
if strings.HasPrefix(processName, namePrefix) {
|
|
foundProcesses = append(foundProcesses, process)
|
|
}
|
|
}
|
|
|
|
return foundProcesses, nil
|
|
}
|
|
|
|
// Process holds basic information of a process.
|
|
type Process struct {
|
|
// Name is the name of the process.
|
|
Name string
|
|
// PID is the process identifier.
|
|
PID int32
|
|
}
|
|
|
|
// KillAllProcessByName kills all the running processes with the given prefix in their name.
|
|
// It returns the processes that were killed. It returns `nil, nil` if there were no processes
|
|
// running with such name prefix.
|
|
func KillAllProcessByName(namePrefix string) ([]Process, error) {
|
|
if namePrefix == "" {
|
|
return nil, errors.New("process name prefix should not be empty")
|
|
}
|
|
|
|
foundProcesses, err := getProcessesByName(namePrefix)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("get processes by name: %w", err)
|
|
}
|
|
|
|
var killedProcesses []Process
|
|
for _, foundProcess := range foundProcesses {
|
|
processName, _ := foundProcess.Name()
|
|
if err := foundProcess.Kill(); err != nil {
|
|
return nil, fmt.Errorf("kill process %d: %w", foundProcess.Pid, err)
|
|
}
|
|
killedProcesses = append(killedProcesses, Process{
|
|
Name: processName,
|
|
PID: foundProcess.Pid,
|
|
})
|
|
}
|
|
|
|
return killedProcesses, nil
|
|
}
|