;;; Copyright (c) 2020 Apple Inc.  All Rights reserved.
;;;
;;; WARNING: The sandbox rules in this file currently constitute
;;; Apple System Private Interface and are subject to change at any time and
;;; without notice.
;;;
(version 1)

(deny default)
(deny file-map-executable iokit-get-properties process-info* nvram*)
(deny dynamic-code-generation)

(deny mach-priv-host-port)

(import "system.sb")
(import "com.apple.corefoundation.sb")
(corefoundation)

(allow process-info* (target self))

(allow network-outbound network-inbound)

(allow network*)

(allow system-socket)

;; For resolving symlinks, realpath(3), and equivalents.
(allow file-read-metadata)

(allow file-read-data (regex #"/usr/libexec"))

(allow file*
    (subpath "/Library/Keychains/")
    (literal "/private/var/db/mds/system/mdsObject.db")
    (literal "/private/var/db/mds/system/mds.lock")
    (literal "/private/var/db/mds/system/mdsDirectory.db")
    (literal "/private/var/db/mds/messages/se_SecurityMessages")
)

(allow ipc-posix-shm-read-data ipc-posix-shm-write-create ipc-posix-shm-write-data
    (ipc-posix-name "com.apple.AppleDatabaseChanged")
)

;; For validating the entitlements of clients.
(allow process-info-codesignature)

;; Your preference domain
(allow user-preference-read user-preference-write
    (preference-domain "com.apple.lightsoutmanagementd")
    (preference-domain "kCFPreferencesAnyApplication")
)

(allow user-preference-read (preference-domain "com.apple.security"))

(allow mach-lookup
    (global-name "com.apple.SecurityServer")
    (global-name "com.apple.securityd.xpc")
    (global-name "com.apple.ocspd")
    (global-name "com.apple.security.agent")
    (global-name "com.apple.mdmclient.agent")
    (global-name "com.apple.mdmclient.daemon")
    (global-name "com.apple.mdmclient.agent.unrestricted")
    (global-name "com.apple.mdmclient.daemon.unrestricted")
)

(allow iokit-open
    (iokit-user-client-class "AppleSMCClient")
    (iokit-user-client-class "RootDomainUserClient")
)

(allow iokit-get-properties
    (iokit-property "kAppleI2CEthernetLomEnable")
    (iokit-property "lom-supported")
    (iokit-property "kAppleExtLomMacAddress")
)

(allow iokit-set-properties
    (iokit-property "kAppleI2CEthernetLomEnable")
    (iokit-property "kAppleI2CEthernetExtLomEnable")
    (iokit-property "lom-supported")
)

(allow file-map-executable
    (literal "/System/Library/CoreServices/ManagedClient.app/Contents/PlugIns/MCXToolsInterface.bundle/Contents/MacOS/MCXToolsInterface"))
    
(allow ipc-posix-shm-read* ipc-posix-shm-write-create ipc-posix-shm-write-data
    (ipc-posix-name "com.apple.AppleLOM.Watchdog"))
