This commit is contained in:
Claire Wang 2023-09-13 14:35:42 -04:00
parent e582d148bd
commit b2e849170f
3 changed files with 64 additions and 58 deletions

View File

@ -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
}

49
mdm/mdm_apple.go Normal file
View File

@ -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
}

15
mdm/mdm_windows.go Normal file
View File

@ -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
}