;;; Copyright (c) 2023 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)

;;; TODO: Change these to deny before finalizing this profile.
(allow (with report) default)
(allow (with report) file-map-executable process-info* nvram*)
(allow (with report) dynamic-code-generation)

(deny mach-priv-host-port)

(import "system.sb")
(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 process-info* (target self))

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

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

(allow mach-lookup
    (global-name "com.apple.SecurityServer")
    (global-name "com.apple.SystemConfiguration.configd")
    (global-name "com.apple.nesessionmanager.content-filter")
    (global-name "com.apple.usymptomsd"))

(allow file-read*
	(literal "/usr/local/bin"
			 "/usr/local/libexec"
			 "/usr/local/libexec/networkQualityd"))

(allow file-read*
	(home-literal "/Library/Preferences/com.apple.security.plist")
	(literal "/Library/Preferences/com.apple.security.plist")
	(literal "/Library/Preferences/com.apple.networkd.plist"))

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


;;;;
;;;; Security.framework section
;;;;

;; Security.framework read-write access
(allow file-read* file-write*
    (subpath "/private/var/db/mds/system"))

;; Security.framework read-only access
(allow file-read*
    (literal (param "SECURITY_MESSAGES_DIR"))
    (home-subpath "/Library/Preferences/com.apple.security.plist")
)

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