<!-- Add the related story/sub-task/bug number, like Resolves #123, or remove if NA --> **Related issue:** Resolves #48760 # Checklist for submitter If some of the following don't apply, delete the relevant line. - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files) for more information. ## Testing - [x] Added/updated automated tests - [x] QA'd all new/changed functionality manually ## fleetd/orbit/Fleet Desktop Note: changes are Windows only; only verified/tested these items for Linux and Windows - [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** * Fixed an issue where some Windows MDM enrollment sessions could stay queued or fail to start on certain devices. * Improved detection of active Windows MDM enrollment, helping commands run more reliably when enrollment is already present. * **Tests** * Added coverage for Windows enrollment detection to prevent regressions. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
32 lines
1.2 KiB
Go
32 lines
1.2 KiB
Go
package update
|
|
|
|
import (
|
|
"regexp"
|
|
|
|
"github.com/fleetdm/fleet/v4/server/mdm/microsoft/syncml"
|
|
)
|
|
|
|
// Exported so that it can be used in tools/ (so that it can be built for
|
|
// Windows and tested on a Windows machine). Otherwise not meant to be used
|
|
// from outside this package.
|
|
type WindowsMDMEnrollmentArgs struct {
|
|
DiscoveryURL string
|
|
HostUUID string
|
|
OrbitNodeKey string
|
|
}
|
|
|
|
// windowsEnrollmentStateUnknown is the EnrollmentState value that means "unknown / not enrolled".
|
|
const windowsEnrollmentStateUnknown = 0
|
|
|
|
// windowsEnrollmentGUIDRe matches a standard enrollment GUID (8-4-4-4-12 hex).
|
|
var windowsEnrollmentGUIDRe = regexp.MustCompile(`^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$`)
|
|
|
|
// isActiveFleetEnrollment reports whether an HKLM\SOFTWARE\Microsoft\Enrollments\<subkeyName> entry is Fleet's active Windows MDM
|
|
// enrollment. It matches when the ProviderID is Fleet's, the EnrollmentState is a non-zero (enrolled) value, and the subkey name is a
|
|
// well-formed enrollment GUID.
|
|
func isActiveFleetEnrollment(providerID string, state uint64, subkeyName string) bool {
|
|
return providerID == syncml.DocProvisioningAppProviderID &&
|
|
state != windowsEnrollmentStateUnknown &&
|
|
windowsEnrollmentGUIDRe.MatchString(subkeyName)
|
|
}
|