;;; Copyright (c) 2017 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 nvram*)
(deny dynamic-code-generation)

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

(define (home-regex home-relative-regex)
    (regex (string-append "^" (regex-quote (param "HOME")) home-relative-regex)))

(define (home-subpath home-relative-subpath)
    (subpath (string-append (param "HOME") home-relative-subpath)))

(define (home-prefix home-relative-prefix)
    (prefix (string-append (param "HOME") home-relative-prefix)))

(define (home-literal home-relative-literal)
    (literal (string-append (param "HOME") home-relative-literal)))


(allow process-info* (target self))

(allow file-read-metadata)

(allow process-info-codesignature)

(allow user-preference-read user-preference-write
    (preference-domain "com.apple.airplay")
    (preference-domain "com.apple.audiomxd")
    (preference-domain "com.apple.celestial"))

(allow file-read*
    (literal "/Library/Preferences/com.apple.Bluetooth.plist")
    (literal "/Library/Preferences/SystemConfiguration/preferences.plist")
    (literal "/usr/libexec")
    (literal "/usr/libexec/audiomxd")
    (subpath "/Library/Audio/Plug-Ins/Components")
    (subpath "/Library/Audio/Plug-Ins/HAL")
    (literal "/Library/Apple")
    (literal "/usr/sbin")
    (literal "/usr/sbin/systemsoundserverd")
    (literal "/usr/sbin/systemsoundserverd/..namedfork/rsrc")
    (literal "/private/etc/master.passwd")
    (literal "/private/var/root/Library/Preferences/.GlobalPreferences.plist")
    (subpath "/usr/share"))

(with-filter (system-attribute apple-internal)
    (allow file-read*
        (subpath "/AppleInternal/Library/MediaExperience")))

(allow file-read* file-write*
    (subpath (param "TMPDIR"))
    (subpath (param "DARWIN_CACHE_DIR"))
    (subpath "/private/var/db/audiomxd"))

(allow iokit-open-user-client
    (iokit-user-client-class "IOAudioControlUserClient")
    (iokit-user-client-class "IOAudioEngineUserClient")
    (iokit-user-client-class "RootDomainUserClient"))

(allow file-issue-extension
    (require-all
        (extension-class "com.apple.cfprefsd.read" "com.apple.cfprefsd.read-write")
        (subpath "/private/var/db/audiomxd/Library/Preferences")))

(allow mach-lookup
    (global-name "com.apple.airplay.endpoint.xpc")
    (global-name "com.apple.AirPlayXPCHelper")
    (global-name "com.apple.audio.AudioComponentRegistrar")
    (global-name "com.apple.audio.AudioConverterService")
    (global-name "com.apple.audio.audiohald")
    (global-name "com.apple.audio.AudioSession")
    (global-name "com.apple.audio.coreaudiod")
    (global-name "com.apple.audio.hapticd")
    (global-name "com.apple.audio.isolated.historicalaudiod")
    (global-name "com.apple.audio.SandboxHelper")
    (global-name "com.apple.audio.toolbox.reporting.service")
    (global-name "com.apple.AudioAccessoryServices")
    (global-name "com.apple.audioanalyticsd")
    (global-name "com.apple.bluetooth.xpc")
    (global-name "com.apple.BluetoothServices")
    (global-name "com.apple.cfprefsd.agent")
    (global-name "com.apple.cfprefsd.daemon")
    (global-name "com.apple.coremedia.endpoint.xpc")
    (global-name "com.apple.coremedia.endpointmanager.xpc")
    (global-name "com.apple.coremedia.endpointstream.xpc")
    (global-name "com.apple.CoreServices.coreservicesd")
    (global-name "com.apple.diagnosticd")
    (global-name "com.apple.distributed_notifications@1v3")
    (global-name "com.apple.distributed_notifications@Uv3")
    (global-name "com.apple.logd")
    (global-name "com.apple.mediaexperience.endpoint.xpc")
    (global-name "com.apple.mediaremoted.xpc")
    (global-name "com.apple.mobileassetd")
    (global-name "com.apple.mobileassetd.v2")
    (global-name "com.apple.runningboard")
    (global-name "com.apple.system.logger")
    (global-name "com.apple.system.notification_center")
    (global-name "com.apple.system.opendirectoryd.libinfo")
    (global-name "com.apple.SystemConfiguration.configd"))

(allow user-preference-read
    (preference-domain "kCFPreferencesAnyApplication"))

(allow file-map-executable
    (subpath "/System/Library/Components/CoreAudio.component")
    (subpath "/System/Library/Components/AudioCodecs.component"))
