/
application.sb
1225 lines (1225 loc) · 52.2 KB
/
application.sb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;;;;; Base profile for Application Sandboxing
;;;;;;
;;;;;; Copyright (c) 2011-2013 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. The contents of this file are also auto-generated and
;;;;;; not user editable; it may be overwritten at any time.
(version 1)
(deny default)
(define entitlement-legacy-names
'(("com.apple.security.device.microphone" "com.apple.security.microphone")
("com.apple.security.device.camera" "com.apple.security.camera")
("com.apple.security.personal-information.addressbook"
"com.apple.security.addressbook")
("com.apple.security.personal-information.calendars"
"com.apple.security.calendars")
("com.apple.security.personal-information.location"
"com.apple.security.location")
("com.apple.security.files.user-selected.read-only"
"com.apple.security.documents.user-selected.read"
"com.apple.security.files.user-selected.read")
("com.apple.security.files.user-selected.read-write"
"com.apple.security.documents.user-selected.read-write")))
(if (not (defined? 'sbpl-filter?))
(define (sbpl-filter? x) (and (list? x) (eq? (car x) 'filter))))
(macro (with-filter form)
(let* ((ps (cdr form)) (extra-filter (car ps)) (rules (cdr ps)))
`(letrec ((collect
(lambda (l filters non-filters)
(if (null? l)
(list filters non-filters)
(let* ((x (car l)) (rest (cdr l)))
(if (sbpl-filter? x)
(collect rest (cons x filters) non-filters)
(collect rest filters (cons x non-filters)))))))
(inject-filter
(lambda args
(let* ((collected (collect args '() '()))
(filters (car collected))
(non-filters (cadr collected)))
(if (null? filters)
(cons ,extra-filter non-filters)
(cons (require-all
(apply require-any filters)
,extra-filter)
non-filters)))))
(orig-allow allow)
(orig-deny deny)
(wrapper
(lambda (action)
(lambda args
(apply action (apply inject-filter args))))))
(set! allow (wrapper orig-allow))
(set! deny (wrapper orig-deny))
,@rules
(set! deny orig-deny)
(set! allow orig-allow))))
(define (legacy-entitlement ls)
(let loop ((ls ls))
(if (null? ls)
#f
(let ((entry (assoc (car ls) *entitlements*)))
(if entry (cdr entry) (loop (cdr ls)))))))
(define (entitlement key)
(let ((entry (assoc key *entitlements*)))
(if entry
(cdr entry)
(let ((legacy (assoc key entitlement-legacy-names)))
(and legacy (legacy-entitlement legacy))))))
(define (%string-prefix? pattern str)
(let loop ((i 0))
(cond ((>= i (string-length pattern)) #t)
((>= i (string-length str)) #f)
((char=? (string-ref pattern i) (string-ref str i)) (loop (+ i 1)))
(else #f))))
(define (sandbox-array-entitlement name fun)
(let ((ls (entitlement name)))
(cond ((list? ls) (for-each (lambda (x) (if (string? x) (fun x))) ls))
((string? ls) (fun ls)))))
(define (apply-read-and-issue-extension op path-filter)
(op file-read* path-filter)
(op file-issue-extension
(require-all
(extension-class "com.apple.app-sandbox.read")
path-filter)))
(define (apply-write-and-issue-extension op path-filter)
(op file-write* path-filter)
(op file-issue-extension
(require-all
(extension-class "com.apple.app-sandbox.read-write")
path-filter)))
(define (read-only-and-issue-extensions path-filter)
(apply-read-and-issue-extension allow path-filter))
(define (read-write-and-issue-extensions path-filter)
(apply-read-and-issue-extension allow path-filter)
(apply-write-and-issue-extension allow path-filter))
(define (allow-read-directory-contents path)
(if path (apply-read-and-issue-extension allow (subpath path))))
(define (allow-read-write-directory-contents path)
(if path
(begin
(apply-read-and-issue-extension allow (subpath path))
(apply-write-and-issue-extension
allow
(regex (string-append "^" (regex-quote path) "/")))
(allow file-write-create
file-write-data
(require-all (vnode-type DIRECTORY) (literal path))))))
(define resolving-literal literal)
(define resolving-subpath subpath)
(define resolving-regex regex)
(define (protect-redirected-paths))
(define (protect-redirectable-paths))
(letrec ((*path-aliases*
(or (entitlement "com.apple.private.app-sandbox.redirected-paths")
'()))
(*redirectable-paths*
(or (entitlement "com.apple.private.app-sandbox.redirectable-paths")
'()))
(path-ancestor?
(lambda (short long)
(cond ((< (string-length long) (string-length short)) #f)
((string=? short long) #t)
((%string-prefix? short long)
(char=? #\/ (string-ref long (string-length short))))
(else #f))))
(path-alias-resolve
(lambda (path)
(let loop ((mapping *path-aliases*))
(if (null? mapping)
path
(let ((key (caar mapping)) (realpath (cadar mapping)))
(if (path-ancestor? key path)
(string-append
realpath
(substring path (string-length key)))
(loop (cdr mapping))))))))
(path-ancestor-regex?
(lambda (short long)
(cond ((< (string-length long) (string-length short)) #f)
((string=? short long) #f)
((%string-prefix? short long)
(let ((c (string-ref long (string-length short))))
(or (char=? c #\/) (char=? c #\$))))
(else #f))))
(path-alias-resolve-regex
(lambda (path-regex)
(let loop ((mapping *path-aliases*))
(if (null? mapping)
path-regex
(let ((key (string-append "^" (regex-quote (caar mapping))))
(realpath
(string-append "^" (regex-quote (cadar mapping)))))
(if (path-ancestor-regex? key path-regex)
(string-append
realpath
(substring path-regex (string-length key)))
(loop (cdr mapping))))))))
(subpath-aliases
(lambda (path)
(let ((x (list path)))
(for-each
(lambda (mapping)
(if (and (not (string=? path (car mapping)))
(path-ancestor? path (car mapping)))
(set! x (append x (car mapping)))))
*path-aliases*)
x)))
(flatten
(lambda (l accum)
(cond ((null? l) accum)
((atom? l) (cons l accum))
(else (flatten (car l) (flatten (cdr l) accum))))))
(orig-regex regex)
(orig-literal literal)
(orig-subpath subpath)
(%resolving-literal
(lambda paths (apply orig-literal (map path-alias-resolve paths))))
(%resolving-subpath
(lambda paths
(apply orig-subpath
(map path-alias-resolve
(flatten (map subpath-aliases paths) '())))))
(%resolving-regex
(lambda patterns
(apply orig-regex (map path-alias-resolve-regex patterns))))
(%protect-redirected-paths
(lambda ()
(for-each
(lambda (mapping)
(let ((symlink-path (car mapping))
(target-path (cadr mapping)))
(allow file-read-metadata (orig-literal symlink-path))
(deny file-write-unlink (orig-literal symlink-path))
(deny file-write-create
(require-all
(orig-literal target-path)
(vnode-type SYMLINK)))))
*path-aliases*)))
(%protect-redirectable-paths
(lambda ()
(for-each
(lambda (path)
(deny file-write-create
(require-all (orig-literal path) (vnode-type SYMLINK))))
*redirectable-paths*))))
(if *path-aliases*
(begin
(set! resolving-literal %resolving-literal)
(set! resolving-subpath %resolving-subpath)
(set! resolving-regex %resolving-regex)
(set! protect-redirected-paths %protect-redirected-paths)))
(if *redirectable-paths*
(set! protect-redirectable-paths %protect-redirectable-paths)))
(macro (with-transparent-redirection rules)
`(let ((literal resolving-literal)
(subpath resolving-subpath)
(regex resolving-regex))
,@rules))
(define (home-regex home-relative-regex)
(resolving-regex
(string-append "^" (regex-quote (param "_HOME")) home-relative-regex)))
(define regex-home home-regex)
(define (home-subpath home-relative-subpath)
(resolving-subpath (string-append (param "_HOME") home-relative-subpath)))
(define (home-literal home-relative-literal)
(resolving-literal (string-append (param "_HOME") home-relative-literal)))
(define (container-regex container-relative-regex)
(resolving-regex
(string-append
"^"
(regex-quote (param "application_container"))
container-relative-regex)))
(define (container-subpath container-relative-subpath)
(resolving-subpath
(string-append
(param "application_container")
container-relative-subpath)))
(define (container-literal container-relative-literal)
(resolving-literal
(string-append
(param "application_container")
container-relative-literal)))
(import "system.sb")
(allow system-audit
system-sched
mach-register
mach-task-name
process-fork
lsopen)
(if (and (param "application_bundle_id")
(%string-prefix? "com.apple." (param "application_bundle_id"))
(allow mach-register (with report))))
(define (restrict-service-name-to-bundle-id service-name bundle-id)
(unless
(or (not (param "application_bundle_id"))
(equal? (param "application_bundle_id") bundle-id))
(deny mach-register (global-name service-name))))
(restrict-service-name-to-bundle-id
"com.evernote.ipc.note"
"com.evernote.Evernote")
(restrict-service-name-to-bundle-id
"com.pushbullet.macapp-notifications"
"com.pushbullet.macapp-notifications")
(deny mach-register (global-name "KeychainUtilityServer"))
(deny process-info*)
(allow process-info-pidinfo)
(allow process-info-pidfdinfo (target self))
(allow process-info-pidfileportinfo (target self))
(allow process-info-setcontrol (target self))
(allow process-info-dirtycontrol (target self))
(allow process-info-rusage (target self))
(deny file-link (home-subpath "/Library"))
(if (entitlement "com.apple.security.temporary-exception.yasb")
(begin
(read-write-and-issue-extensions (subpath "/"))
(apply-read-and-issue-extension deny (home-subpath "/Library"))
(apply-write-and-issue-extension deny (home-subpath "/Library"))))
(allow file-read* process-exec (subpath "/Library"))
(deny file-read*
process-exec
(subpath "/Library/Preferences")
(subpath "/Library/Caches")
(subpath "/Library/Logs")
(subpath "/Library/Application Support/AppStoreContent")
(subpath "/Library/Application Support/AppStore"))
(when (param "application_bundle")
(allow-read-directory-contents (param "application_bundle"))
(allow process-exec (subpath (param "application_bundle"))))
(allow-read-write-directory-contents (param "application_darwin_user_dir"))
(allow-read-write-directory-contents (param "application_darwin_temp_dir"))
(allow file-mount
file-unmount
(subpath (param "application_darwin_user_dir"))
(subpath (param "application_darwin_temp_dir")))
(allow-read-write-directory-contents (param "application_darwin_cache_dir"))
(allow file-mount
file-unmount
(subpath (param "application_darwin_cache_dir")))
(allow file-issue-extension
(require-all
(extension-class "com.apple.nsurlstorage.extension-cache")
(subpath (param "application_darwin_cache_dir"))))
(when (param "application_dyld_paths")
(allow file-read*
process-exec
(apply subpath
(split-string (param "application_dyld_paths") ":"))))
(let ((container-root (param "application_container")))
(allow-read-write-directory-contents container-root)
(allow file-chroot
file-ioctl
file-link
file-mknod
file-revoke
file-search
file-mount
file-unmount
(subpath container-root)))
(deny file-write-create
(require-all
(vnode-type SYMLINK)
(require-any
(container-literal "/Library")
(container-subpath "/Library/Preferences")
(container-subpath "/Library/SyncedPreferences"))))
(define (%protect-preference-symlink domain)
(deny file-unlink
(container-literal
(string-append "/Library/Preferences/" domain ".plist"))
(container-regex
(string-append
"/Library/Preferences/ByHost/"
(regex-quote domain)
"\\..*\\.plist$"))))
(define (shared-preferences-read . domains)
(for-each
(lambda (domain)
(begin
(if (defined? `user-preference-read)
(allow user-preference-read (preference-domain domain)))
(allow file-read*
(home-literal
(string-append "/Library/Preferences/" domain ".plist"))
(home-regex
(string-append
"/Library/Preferences/ByHost/"
(regex-quote domain)
"\\..*\\.plist$")))
(%protect-preference-symlink domain)))
domains))
(define (shared-preferences-read-write . domains)
(for-each
(lambda (domain)
(begin
(if (defined? `user-preference-write)
(allow user-preference-read
user-preference-write
(preference-domain domain)))
(allow file-read*
file-write*
(home-regex
(string-append
"/Library/Preferences/"
(regex-quote domain)
"\\.plist(\\..+)?$"))
(home-regex
(string-append
"/Library/Preferences/ByHost/"
(regex-quote domain)
"\\..*\\.plist(\\..+)?$")))
(%protect-preference-symlink domain)))
domains))
(allow file-read*
file-ioctl
(require-all
(regex "^/dev/r?disk[0-9]+")
(require-any
(device-conforms-to "IOBDMedia")
(device-conforms-to "IODVDMedia")
(device-conforms-to "IOCDMedia"))))
(if (entitlement "com.apple.security.network.client")
(begin
(allow network-outbound (remote ip))
(allow mach-lookup
(global-name "com.apple.cfnetwork.AuthBrokerAgent")
(global-name "com.apple.cfnetwork.cfnetworkagent")
(global-name "com.apple.nesessionmanager")
(global-name "com.apple.nsurlsessiond")
(global-name "com.apple.NetworkDiagnostic.agent"))))
(if (entitlement "com.apple.security.network.server")
(allow network-inbound (local ip)))
(if (or (entitlement "com.apple.security.network.client")
(entitlement "com.apple.security.network.server"))
(system-network))
(if (entitlement "com.apple.security.network.client")
(allow mach-lookup (global-name "com.apple.WebKit.PluginAgent")))
(if (entitlement "com.apple.security.device.camera")
(begin
(allow iokit-open
(iokit-user-client-class "IOUSBDeviceUserClientV2")
(iokit-user-client-class "IOUSBInterfaceUserClientV2"))
(allow device-camera)))
(if (or (entitlement "com.apple.security.device.microphone")
(entitlement "com.apple.security.device.audio-input"))
(allow device-microphone))
(if (or (entitlement "com.apple.security.device.hid")
(entitlement "com.apple.security.device.usb"))
(allow iokit-open (iokit-user-client-class "IOHIDLibUserClient")))
(if (entitlement "com.apple.security.device.usb")
(begin
(allow iokit-open
(iokit-user-client-class "IOUSBDeviceUserClientV2")
(iokit-user-client-class "IOUSBInterfaceUserClientV3"))))
(if (entitlement "com.apple.security.device.firewire")
(begin
(allow iokit-open (iokit-user-client-class "IOFireWireUserClient"))
(allow iokit-open (iokit-user-client-class "IOFireWireAVCUserClient"))
(allow iokit-open
(iokit-user-client-class "IOFireWireAVCProtocolUserClient"))
(allow iokit-set-properties (iokit-property "SummonNub"))))
(if (entitlement "com.apple.security.device.bluetooth")
(begin
(shared-preferences-read "com.apple.Bluetooth")
(allow file-read*
(literal "/Library/Preferences/com.apple.Bluetooth.plist"))
(allow mach-lookup
(global-name "com.apple.BluetoothDOServer")
(global-name "com.apple.blued"))
(allow iokit-open
(iokit-user-client-class "IOBluetoothRFCOMMConnectionUserClient")
(iokit-user-client-class "IOBluetoothRFCOMMChannelUserClient")
(iokit-user-client-class "IOBluetoothL2CAPChannelUserClient")
(iokit-user-client-class "IOBluetoothDeviceUserClient")
(iokit-user-client-class "IOBluetoothHCIUserClient"))
(allow iokit-set-properties
(iokit-property "AuthenticationAttempted")
(iokit-property "ClassOfDevice")
(iokit-property "OpenConnectionAuthenticationRequired"))))
(if (entitlement "com.apple.security.device.serial")
(allow file*
(require-all
(vnode-type TTY)
(require-not
(require-any
(literal "/dev/fsevents")
(literal "/dev/lockstat")
(literal "/dev/machtrace")
(literal "/dev/profile")
(literal "/dev/ptmx")
(literal "/dev/sdt")
(literal "/dev/systrace")
(regex "^/dev/tty[^\\.]")
(regex "^/dev/pty")
(regex "^/dev/fbt")
(regex "^/dev/io8log"))))))
(if (entitlement "com.apple.security.personal-information.location")
(begin
(allow mach-lookup
(global-name "com.apple.CoreLocation.agent")
(global-name "com.apple.locationd.desktop.spi")
(global-name "com.apple.locationd.desktop.synchronous")
(global-name "com.apple.locationd.desktop.registration"))))
(if (entitlement "com.apple.security.personal-information.addressbook")
(begin
(allow distributed-notification-post)
(with-filter
(extension "com.apple.tcc.kTCCServiceAddressBook")
(allow mach-lookup
(global-name
"com.apple.AddressBook.AddressBookApplicationFrameworkIPC")
(global-name "com.apple.AddressBook.SourceSync")
(global-name "com.apple.AddressBook.AssistantService")
(global-name "com.apple.AddressBook.abd"))
(shared-preferences-read-write "com.apple.AddressBook")
(allow file-read*
file-write*
(home-subpath "/Library/Application Support/AddressBook"))
(allow-read-write-directory-contents
(param "application_addressbook_lock_dir"))
(read-write-and-issue-extensions (home-subpath "/Library/Images/People"))
(read-only-and-issue-extensions
(require-any
(subpath "/Library/Images/People")
(subpath "/System/Library/Images/People")
(subpath "/Network/Library/Images/People"))))
(deny file-link
(subpath "/Library/Images/People")
(subpath "/System/Library/Images/People")
(subpath "/Network/Library/Images/People"))))
(if (entitlement "com.apple.security.personal-information.calendars")
(begin
(allow file-read* file-write* (home-subpath "/Library/Calendars"))
(deny file-read*
file-write*
(home-literal "/Library/Calendars/Calendar Cache")
(home-literal "/Library/Calendars/Calendar Cache-journal")
(home-literal "/Library/Calendars/Calendar Cache-shm")
(home-literal "/Library/Calendars/Calendar Cache-wal")
(home-literal "/Library/Calendars/.Calendar Cache-conch"))
(read-write-and-issue-extensions
(require-any
(home-subpath "/Library/Calendars/Attachments")
(home-regex "/Library/Calendars/[0-9A-Z-]+\\.[^/]+/Attachments(/|$)")
(home-subpath "/Library/Calendars/Temporary Files")))
(allow-read-write-directory-contents
(param "application_calendars_lock_dir"))
(allow mach-lookup
(global-name-regex "^com\\.apple\\.CalendarStore\\.lock\\.")
(global-name "com.apple.accountsd.accountmanager")
(global-name "com.apple.CalendarAgent")
(global-name "com.apple.CalendarAgent.database")
(global-name "com.apple.CalendarAgent.proxy")
(global-name "com.apple.CalendarAgent.store"))))
(letrec ((itunes-subpaths
(lambda args
(let* ((itunes-roots
'("/Music/iTunes/iTunes Media"
"/Music/iTunes/iTunes Music"
"/Documents/iTunes/iTunes Music"))
(_subpath
(if (null? args) "" (string-append "/" (car args))))
(subfilters
(map (lambda (root)
(home-subpath (string-append root _subpath)))
itunes-roots)))
(apply require-any subfilters))))
(allow-subdirs
(lambda (subdirs func)
(for-each
(lambda (subdir)
(func allow (home-subpath (string-append "/" subdir))))
subdirs)
(func allow
(require-any
(home-literal "/Music")
(home-subpath "/Music/iTunes")
(home-subpath "/Documents/iTunes")))
(func deny (itunes-subpaths))
(for-each
(lambda (subdir) (func allow (itunes-subpaths subdir)))
subdirs)))
(read '())
(write '())
(assets
(lambda (ent subdir)
(let ((ro (string-append ent ".read-only"))
(rw (string-append ent ".read-write")))
(cond ((entitlement rw)
(let ()
(set! read (cons subdir read))
(set! write (cons subdir write))))
((entitlement ro) (set! read (cons subdir read)))))))
(finish
(lambda ()
(if (positive? (length write))
(allow-subdirs write apply-write-and-issue-extension))
(if (positive? (length read))
(allow-subdirs read apply-read-and-issue-extension)))))
(assets "com.apple.security.assets.music" "Music")
(assets "com.apple.security.assets.movies" "Movies")
(assets "com.apple.security.assets.pictures" "Pictures")
(finish))
(define (set-access-to-itunes-music-subdirectory
base-entitlement
subdir-path-filter
access-to-containing-dir-is-read-only)
(let ((ent-ro (string-append base-entitlement ".read-only"))
(ent-rw (string-append base-entitlement ".read-write")))
(if (entitlement ent-ro)
(apply-read-and-issue-extension allow subdir-path-filter)
(if access-to-containing-dir-is-read-only
(apply-read-and-issue-extension deny subdir-path-filter)))
(if (entitlement ent-rw)
(begin
(apply-read-and-issue-extension allow subdir-path-filter)
(apply-write-and-issue-extension allow subdir-path-filter))
(if (not access-to-containing-dir-is-read-only)
(begin
(apply-read-and-issue-extension deny subdir-path-filter)
(apply-write-and-issue-extension deny subdir-path-filter))))))
(if (entitlement "com.apple.security.assets.music.read-only")
(begin
(apply-read-and-issue-extension
allow
(home-subpath "/Music/iTunes/iTunes Music"))
(set-access-to-itunes-music-subdirectory
"com.apple.security.assets.movies"
(home-subpath "/Music/iTunes/iTunes Music/Movies")
#t)
(set-access-to-itunes-music-subdirectory
"com.apple.security.assets.pictures"
(home-subpath "/Music/iTunes/iTunes Music/Pictures")
#t)))
(if (entitlement "com.apple.security.assets.music.read-write")
(begin
(apply-read-and-issue-extension
allow
(home-subpath "/Music/iTunes/iTunes Music"))
(apply-write-and-issue-extension
allow
(home-subpath "/Music/iTunes/iTunes Music"))
(set-access-to-itunes-music-subdirectory
"com.apple.security.assets.movies"
(home-subpath "/Music/iTunes/iTunes Music/Movies")
#f)
(set-access-to-itunes-music-subdirectory
"com.apple.security.assets.pictures"
(home-subpath "/Music/iTunes/iTunes Music/Pictures")
#f)))
(define (ubiquity-filter s)
(let ((s (list->string
(let loop ((orig (string->list s)) (ls '()))
(if (null? orig)
(reverse ls)
(loop (cdr orig)
(let ((ch (car orig)))
(cons (if (char=? #\. ch) #\~ ch) ls))))))))
(let ((path (string-append "/Library/Mobile Documents/" s)))
(let ((n (string-length path)))
(if (and (char=? #\* (string-ref path (- n 1)))
(char=? #\~ (string-ref path (- n 2))))
(let ((sub (substring path 0 (- n 2))))
(home-regex (string-append (regex-quote sub) ".*")))
(home-subpath path))))))
(sandbox-array-entitlement
"com.apple.developer.ubiquity-container-identifiers"
(lambda (id) (read-write-and-issue-extensions (ubiquity-filter id))))
(read-only-and-issue-extensions
(require-all
(extension "com.apple.librarian.ubiquity-revision")
(mount-relative-regex "^/\\.DocumentRevisions-V100(/|$)")))
(read-write-and-issue-extensions
(require-all
(home-subpath "/Library/Mobile Documents")
(extension "com.apple.librarian.ubiquity-container")))
(if (entitlement "com.apple.developer.game-center")
(begin
(allow mach-lookup
(global-name "com.apple.gamed")
(global-name "com.apple.gamed.osx")
(global-name "com.apple.gamed.xpc"))
(shared-preferences-read "com.apple.gamekit")))
(if (entitlement "com.apple.security.print")
(begin
(allow authorization-right-obtain
(right-name "system.print.operator")
(right-name "system.printingmanager"))
(allow mach-lookup
(global-name "com.apple.printuitool.agent")
(global-name "com.apple.printtool.agent")
(global-name "com.apple.printtool.daemon"))
(allow file-read*
(home-literal "/.cups/lpoptions")
(home-literal "/.cups/client.conf")
(literal "/private/etc/cups/client.conf")
(literal "/private/etc/cups/lpoptions")
(subpath "/private/etc/cups/ppd")
(literal "/private/var/run/cupsd"))
(shared-preferences-read "org.cups.PrintingPrefs")))
(if (entitlement "com.apple.security.files.downloads.read-only")
(read-only-and-issue-extensions (home-subpath "/Downloads")))
(if (entitlement "com.apple.security.files.downloads.read-write")
(read-write-and-issue-extensions (home-subpath "/Downloads")))
(if (or (entitlement "com.apple.security.files.downloads.read-only")
(entitlement "com.apple.security.files.downloads.read-write"))
(allow process-exec (home-subpath "/Downloads")))
(if (or (entitlement "com.apple.security.files.bookmarks.app-scope")
(entitlement "com.apple.security.files.bookmarks.document-scope")
(entitlement "com.apple.security.files.bookmarks.collection-scope")
(entitlement "com.apple.security.files.user-selected.read-only")
(entitlement "com.apple.security.files.user-selected.read-write"))
(allow mach-lookup (global-name "com.apple.scopedbookmarksagent.xpc")))
(allow qtn-user (extension "com.apple.app-sandbox.read-write"))
(allow file-write-create
(require-all
(vnode-type DIRECTORY)
(home-literal "/Library/Group Containers")))
(sandbox-array-entitlement
"com.apple.security.application-groups"
(lambda (suite)
(let* ((group-container-root
(string-append "/Library/Group Containers/" suite))
(group-container-literal
(lambda (container-relative-literal)
(home-literal
(string-append
group-container-root
container-relative-literal))))
(group-container-subpath
(lambda (container-relative-subpath)
(home-subpath
(string-append
group-container-root
container-relative-subpath))))
(group-container-regex
(lambda (container-relative-regex)
(home-regex
(string-append
(regex-quote group-container-root)
container-relative-regex)))))
(allow file-write-create
file-write-data
file-read-data
(require-all
(vnode-type DIRECTORY)
(home-literal group-container-root)))
(allow file-chroot
file-ioctl
file-link
file-mknod
file-revoke
file-search
file-mount
file-unmount
network-bind
network-outbound
(group-container-regex "/"))
(read-write-and-issue-extensions (group-container-regex "/"))
(deny file-read*
file-write*
(group-container-subpath "/Library/Preferences"))
(allow file-read*
process-exec
(subpath
(string-append
"/Library/Application Support/AppStore/GroupContent/"
suite)))
(deny file-write-create
(require-all
(require-not (vnode-type DIRECTORY))
(group-container-literal "/Library")))
(allow mach-lookup
mach-register
(global-name-regex
(string-append "^" (regex-quote (string-append suite ".")))))
(allow ipc-posix*
(ipc-posix-name-regex
(string-append "^" (regex-quote (string-append suite "/"))))))))
(read-only-and-issue-extensions (extension "com.apple.app-sandbox.read"))
(read-write-and-issue-extensions
(extension "com.apple.app-sandbox.read-write"))
(allow mach-lookup (extension "com.apple.app-sandbox.mach"))
(allow iokit-open (extension "com.apple.app-sandbox.iokit-client"))
(allow authorization-right-obtain
(right-name "system.burn")
(right-name-regex
"^system\\.volume\\.(external|optical|removable)\\.unmount$")
(right-name "system.volume.optical.mount"))
(allow iokit-open (iokit-user-client-class "SCSITaskUserClient"))
(allow mach-lookup
(global-name "com.apple.DiscRecording:registrar")
(global-name "com.apple.SUISMessaging"))
(allow file-read*
file-write*
(require-all
(require-not (vnode-type SYMLINK))
(require-any
(home-subpath "/Library/Colors")
(home-subpath "/Library/FontCollections")
(home-subpath "/Library/Spelling"))))
(if (entitlement "com.apple.security.assets.music.read-write")
(allow file-read* file-write* (home-subpath "/Library/Audio/Presets")))
(allow mach-lookup
(global-name "com.apple.cfprefsd.daemon")
(global-name "com.apple.cfprefsd.agent")
(local-name "com.apple.cfprefsd.agent"))
(read-only-and-issue-extensions
(require-all (file-mode 4) (require-any (subpath "/System"))))
(allow process-exec
(require-all (file-mode 4) (require-any (subpath "/System"))))
(allow file-read*
process-exec
(home-subpath "/Library/Audio")
(home-subpath "/Library/ColorPickers")
(home-subpath "/Library/Compositions")
(home-subpath "/Library/Input Methods")
(home-subpath "/Library/PDF Services")
(home-subpath "/Library/QuickLook"))
(allow file-read*
(home-literal "/.CFUserTextEncoding")
(home-subpath "/Library/Fonts")
(home-subpath "/Library/KeyBindings")
(home-subpath "/Library/Keyboard Layouts")
(home-literal "/Library/Preferences/com.apple.DownloadAssessment.plist")
(home-subpath "/Library/Sounds"))
(shared-preferences-read
".GlobalPreferences"
"com.apple.AppleMultitouchTrackpad"
"com.apple.avfoundation"
"com.apple.cmio"
"com.apple.coreanimation"
"com.apple.coremedia"
"com.apple.coremediaio.support"
"com.apple.corevideo"
"com.apple.driver.AppleBluetoothMultitouch.mouse"
"com.apple.driver.AppleBluetoothMultitouch.trackpad"
"com.apple.driver.AppleHIDMouse"
"com.apple.HIToolbox"
"com.apple.inputmethodkit"
"com.apple.LaunchServices"
"com.apple.MultitouchSupport"
"com.apple.security"
"com.apple.security_common"
"com.apple.ServicesMenu.Services"
"com.apple.speech.synthesis.general.prefs"
"com.apple.speech.voice.prefs"
"com.apple.systemsound"
"com.apple.TelephonyUtilities"
"com.apple.universalaccess"
"pbs")
(shared-preferences-read-write "com.apple.AppKit.TextFavorites")
(allow user-preference-read (preference-domain "kCFPreferencesAnyApplication"))
(shared-preferences-read "com.apple.mediaaccessibility")
(shared-preferences-read-write "com.apple.mediaaccessibility.public")
(shared-preferences-read-write "com.apple.sharekit.recents")
(shared-preferences-read-write
"com.apple.preferences.extensions.ServicesWithUI"
"com.apple.preferences.extensions.ShareMenu")
(read-only-and-issue-extensions
(require-any
(home-subpath "/Library/Sounds")
(home-subpath "/Library/Audio/Sounds")
(home-subpath "/Library/Components")
(home-subpath "/Library/QuickTime")))
(allow process-exec
(home-subpath "/Library/Components")
(home-subpath "/Library/QuickTime"))
(read-only-and-issue-extensions
(home-subpath
(string-append
"/Library/Application Scripts/"
(param "application_container_id"))))
(allow process-exec
(home-subpath
(string-append
"/Library/Application Scripts/"
(param "application_container_id"))))
(allow file-write-create
(require-all
(vnode-type DIRECTORY)
(require-any
(home-literal "/Library/Application Scripts")
(home-literal
(string-append
"/Library/Application Scripts/"
(param "application_container_id"))))))
(when (param "application_bundle_id")
(allow file-read*
(literal
(string-append
"/Library/Preferences/"
(param "application_bundle_id")
".plist"))
(subpath
(string-append
"/Library/Application Support/AppStore/Content/"
(param "application_bundle_id")))
(home-regex
(string-append
"/Library/Preferences/"
(regex-quote (param "application_bundle_id"))
"\\.([^\\.]+\\.)?LSSharedFileList\\.plist$")))
(allow mach-register
(global-name (param "application_bundle_id"))
(global-name
(string-append
(param "application_bundle_id")
".ServiceProvider"))))
(allow file-read-metadata)
(allow file-read*
(literal "/Volumes")
(literal "/private/etc/group")
(literal "/private/etc/hosts")
(literal "/private/etc/passwd")
(literal "/private/etc/protocols")
(literal "/private/etc/resolv.conf")
(literal "/private/etc/services")
(literal "/private/etc/openldap/ldap.conf")
(literal "/private/var/run/resolv.conf")
(literal "/Library/Caches/com.apple.DiagnosticReporting.Networks.plist")
(literal "/Library/Preferences/.GlobalPreferences.plist")
(literal
"/Library/Preferences/SystemConfiguration/com.apple.PowerManagement.plist")
(literal "/Library/Preferences/SystemConfiguration/preferences.plist")
(literal "/Library/Preferences/com.apple.AppleShareClient.plist")
(regex "^/Library/Preferences/com\\.apple\\.security")
(literal "/Library/Preferences/com.apple.loginwindow.plist")
(literal "/Library/Preferences/SystemConfiguration/preferences.plist")
(literal "/Library/Preferences/com.apple.HIToolbox.plist")
(subpath "/Users/Shared/SC Info"))
(allow file-read*
process-exec
(subpath
(string-append
"/Library/Application Support/AppStoreContent/"
(param "application_container_id")))
(subpath "/Library/PDF Services")
(subpath "/Developer")
(require-all (file-mode 4) (subpath "/Applications")))
(allow mach-lookup (global-name "com.apple.ocspd"))
(allow file-read* file-write* (home-subpath "/Library/Keychains"))
(allow file-read*
(subpath "/private/var/db/mds")
(literal "/private/var/db/DetachedSignatures"))
(allow ipc-posix-shm-read*
ipc-posix-shm-write-data
(ipc-posix-name "com.apple.AppleDatabaseChanged"))
(allow file-read*
process-exec
(subpath "/bin")
(subpath "/sbin")
(subpath "/usr/bin")
(subpath "/usr/sbin"))
(allow mach-lookup
(local-name "com.apple.CFPasteboardClient")
(local-name "com.apple.coredrag")
(global-name "com.apple.apsd")
(global-name "com.apple.audio.audiohald")
(global-name "com.apple.audio.coreaudiod")
(global-name "com.apple.backupd.sandbox.xpc")
(global-name "com.apple.bird")
(global-name "com.apple.bird.token")
(global-name "com.apple.colorsyncd")
(global-name "com.apple.controlcenter.toggle")
(global-name "com.apple.coremedia.endpoint.xpc")
(global-name "com.apple.coremedia.endpointpicker.xpc")
(global-name "com.apple.coremedia.endpointplaybacksession.xpc")
(global-name "com.apple.coremedia.endpointstream.xpc")
(global-name "com.apple.coreservices.appleevents")
(global-name "com.apple.CoreServices.coreservicesd")
(global-name "com.apple.coreservices.launcherror-handler")
(global-name "com.apple.coreservices.quarantine-resolver")
(global-name "com.apple.coreservices.sharedfilelistd.async-mig")
(global-name "com.apple.coreservices.sharedfilelistd.mig")
(global-name "com.apple.coreservices.sharedfilelistd.xpc")
(global-name "com.apple.cvmsServ")
(global-name "com.apple.decalog4.incoming")
(global-name "com.apple.DiskArbitration.diskarbitrationd")
(global-name "com.apple.distributed_notifications@1v3")
(global-name "com.apple.distributed_notifications@Uv3")
(global-name "com.apple.dock.fullscreen")
(global-name "com.apple.dock.server")
(global-name "com.apple.FileCoordination")
(global-name "com.apple.FontObjectsServer")
(global-name "com.apple.FontServer")
(global-name "com.apple.FSEvents")
(global-name "com.apple.helpd")
(global-name "com.apple.iconservices")
(global-name "com.apple.iconservices.store")
(global-name "com.apple.ImageCaptureExtension2.presence")
(global-name "com.apple.ink.private")
(global-name "com.apple.inputmethodkit.getxpcendpoint")
(global-name "com.apple.inputmethodkit.launchagent")
(global-name "com.apple.inputmethodkit.launcher")
(global-name "com.apple.inputmethodkit.setxpcendpoint")
(global-name "com.apple.InputMethodKit.TextReplacementService")
(global-name "com.apple.KerberosHelper.LKDCHelper")
(global-name "com.apple.librariand")
(global-name "com.apple.lookupd")
(global-name "com.apple.ls.boxd")
(global-name "com.apple.lsd.mapdb")
(global-name "com.apple.lsd.modifydb")
(global-name "com.apple.lsd.open")
(global-name "com.apple.lsd.openurl")
(global-name "com.apple.metadata.mds")
(global-name "com.apple.midiserver")
(global-name "com.apple.midiserver.io")
(global-name "com.apple.netauth.user.auth")
(global-name "com.apple.pasteboard.1")
(global-name "com.apple.pbs.fetch_services")
(global-name "com.apple.pluginkit.pkd")
(global-name "com.apple.ProgressReporting")
(global-name "com.apple.quicklook")
(global-name "com.apple.quicklook.config")
(global-name "com.apple.quicklook.ui.helper")
(global-name "com.apple.quicklook.ui.helper.active")
(global-name "com.apple.revisiond")
(global-name "com.apple.rtcreportingd")
(global-name "com.apple.security.pboxd")
(global-name "com.apple.securityd.xpc")
(global-name "com.apple.SecurityServer")
(global-name "com.apple.sharingd.nsxpc")
(global-name "com.apple.SleepServices")
(global-name "com.apple.speech.recognitionserver")
(global-name "com.apple.speech.synthesis.console")
(global-name "com.apple.speechArbitrationServer")
(global-name "com.apple.spindump")
(global-name "com.apple.storeagent.storekit")
(global-name "com.apple.storeagent.storekit.receiptrenewal")
(global-name "com.apple.syncdefaultsd")
(global-name "com.apple.system.DirectoryService.membership_v1")
(global-name "com.apple.system.opendirectoryd.api")
(global-name "com.apple.SystemConfiguration.configd")
(global-name "com.apple.SystemConfiguration.DNSConfiguration")
(global-name "com.apple.SystemConfiguration.NetworkInformation")
(global-name "com.apple.tccd")
(global-name "com.apple.tccd.system")
(global-name