From b2e849170f905e1bade1b174ccbc9d93c43f1182 Mon Sep 17 00:00:00 2001 From: Claire Wang Date: Wed, 13 Sep 2023 14:35:42 -0400 Subject: [PATCH] wip --- mdm/mdm.go | 58 ---------------------------------------------- mdm/mdm_apple.go | 49 +++++++++++++++++++++++++++++++++++++++ mdm/mdm_windows.go | 15 ++++++++++++ 3 files changed, 64 insertions(+), 58 deletions(-) create mode 100644 mdm/mdm_apple.go create mode 100644 mdm/mdm_windows.go diff --git a/mdm/mdm.go b/mdm/mdm.go index 7da37e5c1..5172efc90 100644 --- a/mdm/mdm.go +++ b/mdm/mdm.go @@ -7,10 +7,7 @@ package mdm import ( "fmt" - "os/exec" "runtime" - - "tailscale.com/version" ) // MDMSettings gets MDM settings from device. @@ -41,58 +38,3 @@ func ReadString(key string) (string, error) { return "", fmt.Errorf("unsupported platform") } } - -/// Darwin - -// readUserDefaultsBool reads a boolean value with the given key from the macOS/iOS UserDefaults. -func readUserDefaultsBool(key string) (bool, error) { - cmd := exec.Command("defaults", "read", userDefaultsDomain(), key) - output, err := cmd.Output() - if err != nil { - return false, err - } - asString := string(output) - if asString == "0" { - return false, nil - } else if asString == "1" { - return true, nil - } else { - return false, fmt.Errorf("unexpected user defaults value for %v: %v", key, err) - } -} - -// readRegistryString reads a string value with the given key from the macOS/iOS UserDefaults. -func readUserDefaultsString(key string) (string, error) { - cmd := exec.Command("defaults", "read", userDefaultsDomain(), key) - output, err := cmd.Output() - if err != nil { - return "", err - } - asString := string(output) - return asString, nil -} - -// userDefaultsDomain returns the domain iOS or macOS store the Tailscale settings in. -func userDefaultsDomain() string { - var bundleIdentifierSuffix string - if version.IsMacSysExt() { - bundleIdentifierSuffix = "macsys" - } else { - bundleIdentifierSuffix = "macos" - } - return "io.tailscale.ipn." + bundleIdentifierSuffix -} - -/// Windows - -// readRegistryBool reads a boolean value with the given key from the Windows registry. -func readRegistryBool(key string) (bool, error) { - // TODO(angott): Windows support - return false, nil -} - -// readRegistryBool reads a string value with the given key from the Windows registry. -func readRegistryString(key string) (string, error) { - // TODO(angott): Windows support - return "", nil -} diff --git a/mdm/mdm_apple.go b/mdm/mdm_apple.go new file mode 100644 index 000000000..4a6c39fdf --- /dev/null +++ b/mdm/mdm_apple.go @@ -0,0 +1,49 @@ +//go:build darwin + +package mdm + +import ( + "fmt" + "os/exec" + + "tailscale.com/version" +) + +// readUserDefaultsBool reads a boolean value with the given key from the macOS/iOS UserDefaults. +func readUserDefaultsBool(key string) (bool, error) { + cmd := exec.Command("defaults", "read", userDefaultsDomain(), key) + output, err := cmd.Output() + if err != nil { + return false, err + } + asString := string(output) + if asString == "0" { + return false, nil + } else if asString == "1" { + return true, nil + } else { + return false, fmt.Errorf("unexpected user defaults value for %v: %v", key, err) + } +} + +// readRegistryString reads a string value with the given key from the macOS/iOS UserDefaults. +func readUserDefaultsString(key string) (string, error) { + cmd := exec.Command("defaults", "read", userDefaultsDomain(), key) + output, err := cmd.Output() + if err != nil { + return "", err + } + asString := string(output) + return asString, nil +} + +// userDefaultsDomain returns the domain iOS or macOS store the Tailscale settings in. +func userDefaultsDomain() string { + var bundleIdentifierSuffix string + if version.IsMacSysExt() { + bundleIdentifierSuffix = "macsys" + } else { + bundleIdentifierSuffix = "macos" + } + return "io.tailscale.ipn." + bundleIdentifierSuffix +} diff --git a/mdm/mdm_windows.go b/mdm/mdm_windows.go new file mode 100644 index 000000000..b514d75b1 --- /dev/null +++ b/mdm/mdm_windows.go @@ -0,0 +1,15 @@ +//go:build windows + +package mdm + +// readRegistryBool reads a boolean value with the given key from the Windows registry. +func readRegistryBool(key string) (bool, error) { + // TODO(angott): Windows support + return false, nil +} + +// readRegistryBool reads a string value with the given key from the Windows registry. +func readRegistryString(key string) (string, error) { + // TODO(angott): Windows support + return "", nil +}