mirror of
https://github.com/tailscale/tailscale.git
synced 2026-05-08 05:36:38 +02:00
wip
This commit is contained in:
parent
b2e849170f
commit
b62a0b7978
28
mdm/mdm.go
28
mdm/mdm.go
@ -5,10 +5,9 @@
|
||||
// in a platform-independent manner.
|
||||
package mdm
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
)
|
||||
type MDMHandler struct {
|
||||
Settings *MDMSettings
|
||||
}
|
||||
|
||||
// MDMSettings gets MDM settings from device.
|
||||
type MDMSettings interface {
|
||||
@ -18,23 +17,10 @@ type MDMSettings interface {
|
||||
ReadString(key string) (string, error)
|
||||
}
|
||||
|
||||
func ReadBool(key string) (bool, error) {
|
||||
if runtime.GOOS == "darwin" || runtime.GOOS == "ios" {
|
||||
return readUserDefaultsBool(key)
|
||||
} else if runtime.GOOS == "windows" {
|
||||
return readRegistryBool(key)
|
||||
} else {
|
||||
return false, fmt.Errorf("unsupported platform")
|
||||
}
|
||||
func (handler *MDMHandler) ReadBool(key string) (bool, error) {
|
||||
return handler.ReadBool(key)
|
||||
}
|
||||
|
||||
func ReadString(key string) (string, error) {
|
||||
if runtime.GOOS == "darwin" || runtime.GOOS == "ios" {
|
||||
return readUserDefaultsString(key)
|
||||
} else if runtime.GOOS == "windows" {
|
||||
// TODO(angott): Windows
|
||||
return readRegistryString(key)
|
||||
} else {
|
||||
return "", fmt.Errorf("unsupported platform")
|
||||
}
|
||||
func (handler *MDMHandler) ReadString(key string) (string, error) {
|
||||
return handler.ReadString(key)
|
||||
}
|
||||
|
||||
@ -1,49 +1,5 @@
|
||||
//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
|
||||
func NewAppleMDMHandler(settings *MDMSettings) *MDMHandler {
|
||||
return &MDMHandler{Settings: settings}
|
||||
}
|
||||
|
||||
@ -2,6 +2,10 @@
|
||||
|
||||
package mdm
|
||||
|
||||
func NewWindowsMDMHandler(settings *MDMSettings) *MDMHandler {
|
||||
return &MDMHandler{Settings: settings}
|
||||
}
|
||||
|
||||
// readRegistryBool reads a boolean value with the given key from the Windows registry.
|
||||
func readRegistryBool(key string) (bool, error) {
|
||||
// TODO(angott): Windows support
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user