Files
privatae-bastion/client-go/anchorpolicy_darwin.go
T
Privatae 48899b41a9
ci / personal-data (push) Successful in 4s
ci / test (push) Successful in 4m58s
ci / fuzz (push) Successful in 3m33s
bastion 0.63.1
2026-11-03 22:56:18 +00:00

36 lines
1022 B
Go

//go:build darwin
package main
import (
"os"
"os/exec"
"strings"
"syscall"
)
// anchorPolicyPlist is the machine-wide managed preference domain a
// configuration profile (MDM) installs for the bastion. The folder is root's
// and the system writes it; a file there not owned by root is not a policy.
const anchorPolicyPlist = "/Library/Managed Preferences/ai.privatae.bastion.plist"
func readAnchorPolicyOS() *anchorPolicy {
fi, err := os.Lstat(anchorPolicyPlist)
if err != nil || !fi.Mode().IsRegular() || fi.Mode().Perm()&0o022 != 0 {
return nil
}
if st, ok := fi.Sys().(*syscall.Stat_t); !ok || st.Uid != 0 {
return nil
}
// defaults reads the binary and the XML form alike.
out, err := exec.Command("/usr/bin/defaults", "read", strings.TrimSuffix(anchorPolicyPlist, ".plist"), "AnchorHost").Output()
if err != nil {
return nil
}
v := strings.TrimSpace(string(out))
if v == "" {
return nil
}
return &anchorPolicy{Host: v, Source: "the managed preference ai.privatae.bastion AnchorHost"}
}