;;; 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 process-info* nvram*)
(deny dynamic-code-generation)

(deny mach-priv-host-port)

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

;;; Homedir-relative path filters
(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 mach-lookup
    (global-name "com.apple.duetactivityscheduler")
    (global-name "com.apple.windowserver.active")
    (global-name "com.apple.apsd")
    (global-name "com.apple.logind")
)

(allow process-info* (target self))

(allow file-read-data (home-subpath "/Library/SecureMessaging"))
(allow file-write-create (home-subpath "/Library/SecureMessaging"))
(allow file-write-unlink (home-subpath "/Library/SecureMessaging"))
(allow file-write-data (home-subpath "/Library/SecureMessaging"))
(allow file-read-metadata (subpath "/Users"))

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

(allow network-outbound)

(allow user-preference-read
       (preference-domain "kCFPreferencesAnyApplication")
       (preference-domain "com.apple.ids")
       (preference-domain "com.apple.facetime.bag")
       (preference-domain "com.apple.imessage.bag")
)
