aboutsummaryrefslogtreecommitdiff
blob: 010f0ec1330611b11ad8ffeacaa121046a7aa222 (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
policy_module(init, 2.6.0)

gen_require(`
	class passwd rootok;
')

########################################
#
# Declarations
#

## <desc>
## <p>
## Enable support for upstart as the init program.
## </p>
## </desc>
gen_tunable(init_upstart, false)

## <desc>
## <p>
## Allow all daemons the ability to read/write terminals
## </p>
## </desc>
gen_tunable(init_daemons_use_tty, false)

attribute init_script_domain_type;
attribute init_script_file_type;
attribute init_run_all_scripts_domain;
attribute systemdunit;
attribute initrc_transition_domain;

# Mark process types as daemons
attribute daemon;
attribute systemprocess;

# Mark file type as a daemon pid file
attribute daemonpidfile;

#
# init_t is the domain of the init process.
#
type init_t, initrc_transition_domain;
type init_exec_t;
domain_type(init_t)
domain_entry_file(init_t, init_exec_t)
kernel_domtrans_to(init_t, init_exec_t)
role system_r types init_t;

#
# init_var_run_t is the type for /var/run/shutdown.pid and /var/run/systemd.
#
type init_var_run_t;
files_pid_file(init_var_run_t)

#
# init_var_lib_t is the type for /var/lib/systemd.
#
type init_var_lib_t;
files_type(init_var_lib_t)

#
# initctl_t is the type of the named pipe created
# by init during initialization.  This pipe is used
# to communicate with init.
#
type initctl_t;
files_type(initctl_t)
mls_trusted_object(initctl_t)

type initrc_t, init_script_domain_type, init_run_all_scripts_domain;
type initrc_exec_t, init_script_file_type;
domain_type(initrc_t)
domain_entry_file(initrc_t, initrc_exec_t)
init_named_socket_activation(initrc_t, init_var_run_t)
role system_r types initrc_t;
# should be part of the true block
# of the below init_upstart tunable
# but this has a typeattribute in it
corecmd_shell_entry_type(initrc_t)

type initrc_devpts_t;
term_pty(initrc_devpts_t)
files_type(initrc_devpts_t)

type initrc_lock_t;
files_lock_file(initrc_lock_t)

type initrc_state_t;
files_type(initrc_state_t)

type initrc_tmp_t;
files_tmp_file(initrc_tmp_t)

type initrc_var_log_t;
logging_log_file(initrc_var_log_t)

type initrc_var_run_t;
files_pid_file(initrc_var_run_t)

type systemd_unit_t;
init_unit_file(systemd_unit_t)

ifdef(`distro_gentoo',`
	type rc_exec_t;
	domain_entry_file(initrc_t, rc_exec_t)
')

ifdef(`enable_mls',`
	kernel_ranged_domtrans_to(init_t, init_exec_t, s0 - mls_systemhigh)
')

########################################
#
# Init local policy
#

# Use capabilities. old rule:
allow init_t self:capability { chown dac_override dac_read_search fowner fsetid kill setgid setuid setpcap linux_immutable net_bind_service net_broadcast net_admin net_raw ipc_lock ipc_owner sys_rawio sys_chroot sys_ptrace sys_pacct sys_admin sys_boot sys_nice sys_resource sys_time sys_tty_config mknod lease audit_write audit_control setfcap };
allow init_t self:capability2 { wake_alarm block_suspend };
# is ~sys_module really needed? observed:
# sys_boot
# sys_tty_config
# kill: now provided by domain_kill_all_domains()
# setuid (from /sbin/shutdown)
# sys_chroot (from /usr/bin/chroot): now provided by corecmd_chroot_exec_chroot()

allow init_t self:fifo_file rw_fifo_file_perms;

# Re-exec itself
can_exec(init_t, init_exec_t)

allow init_t initrc_t:unix_stream_socket connectto;

# For /var/run/shutdown.pid.
allow init_t init_var_run_t:file manage_file_perms;
files_pid_filetrans(init_t, init_var_run_t, file)

# for /run/initctl
allow init_t init_var_run_t:fifo_file manage_fifo_file_perms;

allow init_t init_var_run_t:lnk_file manage_lnk_file_perms;

# for systemd to manage service file symlinks
allow init_t init_var_run_t:file manage_lnk_file_perms;

allow init_t initctl_t:fifo_file manage_fifo_file_perms;
dev_filetrans(init_t, initctl_t, fifo_file)
files_pid_filetrans(init_t, initctl_t, fifo_file)

# Modify utmp.
allow init_t initrc_var_run_t:file { rw_file_perms setattr };

kernel_read_system_state(init_t)
kernel_share_state(init_t)
kernel_dontaudit_search_unlabeled(init_t)

corecmd_exec_chroot(init_t)
corecmd_exec_bin(init_t)

dev_read_sysfs(init_t)
# Early devtmpfs
dev_rw_generic_chr_files(init_t)

domain_getpgid_all_domains(init_t)
domain_kill_all_domains(init_t)
domain_getattr_all_domains(init_t)
domain_signal_all_domains(init_t)
domain_signull_all_domains(init_t)
domain_sigstop_all_domains(init_t)
domain_sigchld_all_domains(init_t)

files_read_etc_files(init_t)
files_rw_generic_pids(init_t)
files_manage_etc_runtime_files(init_t)
files_etc_filetrans_etc_runtime(init_t, file)
# Run /etc/X11/prefdm:
files_exec_etc_files(init_t)
# file descriptors inherited from the rootfs:
files_dontaudit_rw_root_files(init_t)
files_dontaudit_rw_root_chr_files(init_t)

fs_getattr_xattr_fs(init_t)
fs_list_inotifyfs(init_t)
# cjp: this may be related to /dev/log
fs_write_ramfs_sockets(init_t)

mcs_process_set_categories(init_t)
mcs_killall(init_t)

mls_file_read_all_levels(init_t)
mls_file_write_all_levels(init_t)
mls_process_write_all_levels(init_t)
mls_fd_use_all_levels(init_t)
mls_process_set_level(init_t)

# the following one is needed for libselinux:is_selinux_enabled()
# otherwise the call fails and sysvinit tries to load the policy
# again when using the initramfs
selinux_get_fs_mount(init_t)
selinux_set_all_booleans(init_t)

term_use_all_terms(init_t)

# Run init scripts.
init_domtrans_script(init_t)

libs_rw_ld_so_cache(init_t)

logging_send_syslog_msg(init_t)
logging_rw_generic_logs(init_t)
logging_create_devlog(init_t)

seutil_read_config(init_t)

miscfiles_read_localization(init_t)

ifdef(`init_systemd',`
	# handle instances where an old labeled init script is encountered.
	typeattribute init_t init_run_all_scripts_domain;

	allow init_t self:unix_dgram_socket { create_socket_perms sendto };
	allow init_t self:process { setsockcreate setfscreate setrlimit };
	allow init_t self:process { getcap setcap getsched setsched };
	allow init_t self:unix_stream_socket { create_stream_socket_perms connectto };
	allow init_t self:netlink_audit_socket { nlmsg_relay create_socket_perms };
	allow init_t self:netlink_selinux_socket create_socket_perms;
	allow init_t self:system { status reboot halt reload };
	# Until systemd is fixed
	allow init_t self:udp_socket create_socket_perms;
	allow init_t self:netlink_route_socket create_netlink_socket_perms;
	allow init_t initrc_t:unix_dgram_socket create_socket_perms;
	allow init_t self:capability2 audit_read;
	allow init_t self:bpf { map_create map_read map_write prog_load prog_run };

	# for /run/systemd/inaccessible/{chr,blk}
	allow init_t init_var_run_t:blk_file { create getattr };
	allow init_t init_var_run_t:chr_file { create getattr };

	allow init_t systemprocess:process { dyntransition siginh };
	allow init_t systemprocess:unix_stream_socket create_stream_socket_perms;
	allow init_t systemprocess:unix_dgram_socket create_socket_perms;

	allow init_t self:process { getcap getsched setsched setpgid setfscreate setsockcreate setcap setrlimit };
	allow init_t self:capability2 { audit_read block_suspend };
	allow init_t self:netlink_kobject_uevent_socket create_socket_perms;
	allow init_t self:unix_dgram_socket lock;

	allow init_t init_var_run_t:sock_file manage_sock_file_perms;

	allow init_t daemon:unix_stream_socket create_stream_socket_perms;
	allow init_t daemon:unix_dgram_socket create_socket_perms;
	allow init_t daemon:tcp_socket create_stream_socket_perms;
	allow init_t daemon:udp_socket create_socket_perms;
	allow daemon init_t:unix_dgram_socket sendto;

	allow init_run_all_scripts_domain systemdunit:service { status start stop };

	allow systemprocess init_t:unix_dgram_socket sendto;
	allow systemprocess init_t:unix_stream_socket { append write read getattr ioctl };

	allow daemon init_t:unix_stream_socket { append write read getattr ioctl };
	manage_files_pattern(init_t, init_var_run_t, init_var_run_t)
	manage_lnk_files_pattern(init_t, init_var_run_t, init_var_run_t)
	manage_sock_files_pattern(init_t, init_var_run_t, init_var_run_t)
	manage_dirs_pattern(init_t, init_var_run_t, init_var_run_t)

	manage_files_pattern(init_t, systemd_unit_t, systemdunit)

	manage_dirs_pattern(init_t, systemd_unit_t, systemd_unit_t)
	manage_lnk_files_pattern(init_t, systemd_unit_t, systemd_unit_t)
	allow init_t systemd_unit_t:dir relabel_dir_perms;

	kernel_dyntrans_to(init_t)
	kernel_read_network_state(init_t)
	kernel_dgram_send(init_t)
	kernel_stream_connect(init_t)
	kernel_getattr_proc(init_t)
	kernel_read_fs_sysctls(init_t)
	kernel_list_unlabeled(init_t)
	kernel_load_module(init_t)
	kernel_rw_kernel_sysctl(init_t)
	kernel_rw_net_sysctls(init_t)
	kernel_read_all_sysctls(init_t)
	kernel_read_software_raid_state(init_t)
	kernel_unmount_debugfs(init_t)
	kernel_search_key(init_t)
	kernel_setsched(init_t)
	kernel_rw_unix_sysctls(init_t)

	# run systemd misc initializations
	# in the initrc_t domain, as would be
	# done in traditional sysvinit/upstart.
	corecmd_bin_domtrans(init_t, initrc_t)
	corecmd_shell_domtrans(init_t, initrc_t)

	dev_manage_input_dev(init_t)
	dev_relabel_all_sysfs(init_t)
	dev_relabel_generic_symlinks(init_t)
	dev_read_urand(init_t)
	dev_write_kmsg(init_t)
	dev_write_urand(init_t)
	dev_rw_lvm_control(init_t)
	dev_rw_autofs(init_t)
	dev_manage_generic_symlinks(init_t)
	dev_manage_generic_dirs(init_t)
	dev_manage_generic_files(init_t)
	dev_manage_null_service(initrc_t)
	dev_read_generic_chr_files(init_t)
	dev_relabel_generic_dev_dirs(init_t)
	dev_relabel_all_dev_nodes(init_t)
	dev_relabel_all_dev_files(init_t)
	dev_manage_sysfs_dirs(init_t)
	dev_relabel_sysfs_dirs(init_t)
	dev_read_usbfs(initrc_t)
	# systemd writes to /dev/watchdog on shutdown
	dev_write_watchdog(init_t)

	domain_read_all_domains_state(init_t)

	files_read_all_pids(init_t)
	files_list_usr(init_t)
	files_list_var(init_t)
	files_list_var_lib(init_t)
	files_mounton_root(init_t)
	files_search_pids(init_t)
	files_relabel_all_pids(init_t)
	files_relabel_all_pid_sock_files(init_t)
	files_relabelto_etc_runtime_dirs(init_t)
	files_relabelto_etc_runtime_files(init_t)
	files_read_all_locks(init_t)
	files_search_kernel_modules(init_t)
	files_create_all_pid_pipes(init_t)
	files_create_all_pid_sockets(init_t)
	files_create_all_spool_sockets(init_t)
	files_create_lock_dirs(init_t)
	systemd_rw_networkd_netlink_route_sockets(init_t)
	files_delete_all_pids(init_t)
	files_delete_all_spool_sockets(init_t)
	files_exec_generic_pid_files(init_t)
	files_list_locks(init_t)
	files_list_spool(init_t)
	files_manage_all_pid_dirs(init_t)
	files_manage_generic_tmp_dirs(init_t)
	files_manage_urandom_seed(init_t)
	files_mounton_all_mountpoints(init_t)
	files_read_boot_files(initrc_t)
	files_relabel_all_lock_dirs(init_t)
	files_relabel_all_pid_dirs(init_t)
	files_relabel_all_pid_files(init_t)
	files_search_all(init_t)
	files_unmount_all_file_type_fs(init_t)
	# for privatetmp functions
	files_mounton_tmp(init_t)
	# for ProtectSystem
	files_mounton_etc_dirs(init_t)

	fs_relabel_cgroup_dirs(init_t)
	fs_list_auto_mountpoints(init_t)
	fs_mount_autofs(init_t)
	fs_manage_hugetlbfs_dirs(init_t)
	fs_getattr_tmpfs(init_t)
	fs_read_tmpfs_files(init_t)
	fs_relabel_cgroup_symlinks(init_t)
	fs_relabel_pstore_dirs(init_t)
	fs_dontaudit_getattr_xattr_fs(init_t)
	fs_create_cgroup_links(init_t)
	fs_getattr_all_fs(init_t)
	fs_manage_cgroup_dirs(init_t)
	fs_manage_cgroup_files(init_t)
	fs_manage_tmpfs_dirs(init_t)
	fs_mount_all_fs(init_t)
	fs_remount_all_fs(init_t)
	fs_relabelfrom_tmpfs_symlinks(init_t)
	fs_unmount_all_fs(init_t)
	# for privatetmp functions
	fs_relabel_tmpfs_dirs(init_t)
	fs_relabel_tmpfs_files(init_t)
	fs_relabelfrom_tmpfs_sockets(init_t)
	# mount-setup
	fs_unmount_autofs(init_t)
	fs_getattr_pstore_dirs(init_t)
	# for network namespaces
	fs_read_nsfs_files(init_t)

	init_read_script_state(init_t)

	# systemd_socket_activated policy
	mls_socket_write_all_levels(init_t)
	# read from systemd-journal and similar
	mls_socket_read_to_clearance(init_t)

	selinux_unmount_fs(init_t)
	selinux_validate_context(init_t)
	selinux_compute_create_context(init_t)
	selinux_compute_access_vector(init_t)

	storage_getattr_removable_dev(init_t)

	term_relabel_pty_dirs(init_t)

	auth_manage_var_auth(init_t)
	auth_relabel_login_records(init_t)
	auth_relabel_pam_console_data_dirs(init_t)

	logging_manage_pid_sockets(init_t)
	logging_send_audit_msgs(init_t)
	logging_relabelto_devlog_sock_files(init_t)
	logging_relabel_generic_log_dirs(init_t)

	# lvm2-activation-generator checks file labels
	seutil_read_file_contexts(init_t)

	systemd_getattr_updated_runtime(init_t)
	systemd_manage_passwd_runtime_symlinks(init_t)
	systemd_use_passwd_agent(init_t)
	systemd_list_tmpfiles_conf(init_t)
	systemd_relabelto_tmpfiles_conf_dirs(init_t)
	systemd_relabelto_tmpfiles_conf_files(init_t)
	systemd_relabelto_journal_dirs(init_t)
	systemd_relabelto_journal_files(init_t)
	systemd_manage_all_units(init_t)

	term_create_devpts_dirs(init_t)

	# udevd is a "systemd kobject uevent socket activated daemon"
	udev_create_kobject_uevent_sockets(init_t)

	# for systemd to read udev status
	udev_read_pid_files(init_t)

	udev_relabelto_db_sockets(init_t)

	optional_policy(`
		clock_read_adjtime(init_t)
	')

	optional_policy(`
		systemd_dbus_chat_logind(init_t)
	')

	optional_policy(`
		dbus_connect_system_bus(init_t)
	')

	optional_policy(`
		modutils_domtrans(init_t)
	')
',`
	tunable_policy(`init_upstart',`
		corecmd_shell_domtrans(init_t, initrc_t)
	',`
		# Run the shell in the sysadm role for single-user mode.
		# causes problems with upstart
		ifndef(`distro_debian',`
			sysadm_shell_domtrans(init_t)
		')
	')
')

ifdef(`distro_debian',`
	fs_tmpfs_filetrans(init_t, initctl_t, fifo_file, "initctl")

	allow init_t initrc_var_run_t:file manage_file_perms;
	fs_tmpfs_filetrans(init_t, initrc_var_run_t, file, "utmp")
	fs_manage_tmpfs_files(initrc_t)

	sysnet_manage_config(initrc_t)

	optional_policy(`
		postfix_read_config(initrc_t)
	')
')

ifdef(`distro_gentoo',`
	allow init_t self:process { getcap setcap };

	init_exec_rc(initrc_t)
')

ifdef(`distro_redhat',`
	fs_read_tmpfs_symlinks(init_t)
	fs_rw_tmpfs_chr_files(init_t)
	fs_tmpfs_filetrans(init_t, initctl_t, fifo_file)
')

optional_policy(`
	modutils_read_module_config(init_t)
	modutils_read_module_deps(init_t)
	modutils_read_module_objects(init_t)
')

optional_policy(`
	auth_rw_login_records(init_t)
')

optional_policy(`
	dbus_system_bus_client(init_t)

	optional_policy(`
		unconfined_dbus_send(init_t)
	')
')

optional_policy(`
	nscd_use(init_t)
')

optional_policy(`
	shutdown_domtrans(init_t)
')

optional_policy(`
	sssd_stream_connect(init_t)
')

optional_policy(`
	udev_read_db(init_t)
	udev_relabelto_db(init_t)
')

optional_policy(`
	unconfined_domain(init_t)
')

########################################
#
# Init script local policy
#

allow initrc_t self:process { getpgid setsched setpgid setrlimit getsched };
allow initrc_t self:capability { chown dac_override dac_read_search fowner fsetid kill setgid setuid setpcap linux_immutable net_bind_service net_broadcast net_admin net_raw ipc_lock ipc_owner sys_rawio sys_chroot sys_ptrace sys_pacct sys_boot sys_nice sys_resource sys_time sys_tty_config mknod lease audit_write audit_control setfcap };
allow initrc_t self:capability2 { wake_alarm block_suspend };
dontaudit initrc_t self:capability sys_module; # sysctl is triggering this
allow initrc_t self:passwd rootok;
allow initrc_t self:key manage_key_perms;

# Allow IPC with self
allow initrc_t self:unix_dgram_socket create_socket_perms;
allow initrc_t self:unix_stream_socket { create listen accept ioctl read getattr write setattr append bind connect getopt setopt shutdown connectto };
allow initrc_t self:tcp_socket create_stream_socket_perms;
allow initrc_t self:udp_socket create_socket_perms;
allow initrc_t self:fifo_file rw_file_perms;

allow initrc_t initrc_devpts_t:chr_file rw_term_perms;
term_create_pty(initrc_t, initrc_devpts_t)

# Going to single user mode
init_telinit(initrc_t)

can_exec(initrc_t, init_script_file_type)

create_dirs_pattern(initrc_t, daemonpidfile, daemonpidfile)
manage_files_pattern(initrc_t, daemonpidfile, daemonpidfile)
setattr_dirs_pattern(initrc_t, daemonpidfile, daemonpidfile)

domtrans_pattern(init_run_all_scripts_domain, initrc_exec_t, initrc_t)

manage_dirs_pattern(initrc_t, initrc_state_t, initrc_state_t)
manage_files_pattern(initrc_t, initrc_state_t, initrc_state_t)
manage_lnk_files_pattern(initrc_t, initrc_state_t, initrc_state_t)
manage_fifo_files_pattern(initrc_t, initrc_state_t, initrc_state_t)

allow initrc_t initrc_var_run_t:file manage_file_perms;
files_pid_filetrans(initrc_t, initrc_var_run_t, file)

allow initrc_t daemon:process siginh;

can_exec(initrc_t, initrc_tmp_t)
manage_files_pattern(initrc_t, initrc_tmp_t, initrc_tmp_t)
manage_dirs_pattern(initrc_t, initrc_tmp_t, initrc_tmp_t)
manage_lnk_files_pattern(initrc_t, initrc_tmp_t, initrc_tmp_t)
files_tmp_filetrans(initrc_t, initrc_tmp_t, { file dir })
allow initrc_t initrc_tmp_t:dir relabelfrom;

manage_dirs_pattern(initrc_t, initrc_var_log_t, initrc_var_log_t)
manage_files_pattern(initrc_t, initrc_var_log_t, initrc_var_log_t)
logging_log_filetrans(initrc_t, initrc_var_log_t, dir)

init_write_initctl(initrc_t)

kernel_read_system_state(initrc_t)
kernel_read_software_raid_state(initrc_t)
kernel_read_network_state(initrc_t)
kernel_read_ring_buffer(initrc_t)
kernel_change_ring_buffer_level(initrc_t)
kernel_clear_ring_buffer(initrc_t)
kernel_get_sysvipc_info(initrc_t)
kernel_read_all_sysctls(initrc_t)
kernel_rw_all_sysctls(initrc_t)
kernel_use_fds(initrc_t)
# for lsof which is used by alsa shutdown:
kernel_dontaudit_getattr_message_if(initrc_t)
# cjp: not sure why these are here; should use mount policy
kernel_list_unlabeled(initrc_t)
kernel_mounton_unlabeled_dirs(initrc_t)

files_create_lock_dirs(initrc_t)
files_manage_all_locks(initrc_t)
files_pid_filetrans_lock_dir(initrc_t, "lock")
files_read_kernel_symbol_table(initrc_t)
files_setattr_lock_dirs(initrc_t)

corecmd_exec_all_executables(initrc_t)

corenet_all_recvfrom_unlabeled(initrc_t)
corenet_all_recvfrom_netlabel(initrc_t)
corenet_tcp_sendrecv_all_if(initrc_t)
corenet_udp_sendrecv_all_if(initrc_t)
corenet_tcp_sendrecv_all_nodes(initrc_t)
corenet_udp_sendrecv_all_nodes(initrc_t)
corenet_tcp_sendrecv_all_ports(initrc_t)
corenet_udp_sendrecv_all_ports(initrc_t)
corenet_tcp_connect_all_ports(initrc_t)
corenet_sendrecv_all_client_packets(initrc_t)

dev_read_rand(initrc_t)
dev_read_urand(initrc_t)
dev_dontaudit_read_kmsg(initrc_t)
dev_write_kmsg(initrc_t)
dev_write_rand(initrc_t)
dev_write_urand(initrc_t)
dev_rw_sysfs(initrc_t)
dev_list_usbfs(initrc_t)
dev_read_framebuffer(initrc_t)
dev_write_framebuffer(initrc_t)
dev_read_realtime_clock(initrc_t)
dev_read_sound_mixer(initrc_t)
dev_write_sound_mixer(initrc_t)
dev_setattr_generic_dirs(initrc_t)
dev_setattr_all_chr_files(initrc_t)
dev_rw_lvm_control(initrc_t)
dev_rw_generic_chr_files(initrc_t)
dev_delete_lvm_control_dev(initrc_t)
dev_manage_generic_symlinks(initrc_t)
dev_manage_generic_files(initrc_t)
# Wants to remove udev.tbl:
dev_delete_generic_symlinks(initrc_t)
dev_getattr_all_blk_files(initrc_t)
dev_getattr_all_chr_files(initrc_t)
dev_rw_xserver_misc(initrc_t)
dev_map_xserver_misc(initrc_t)

domain_kill_all_domains(initrc_t)
domain_signal_all_domains(initrc_t)
domain_signull_all_domains(initrc_t)
domain_sigstop_all_domains(initrc_t)
domain_sigchld_all_domains(initrc_t)
domain_read_all_domains_state(initrc_t)
domain_getattr_all_domains(initrc_t)
domain_getsession_all_domains(initrc_t)
domain_use_interactive_fds(initrc_t)
# for lsof which is used by alsa shutdown:
domain_dontaudit_getattr_all_udp_sockets(initrc_t)
domain_dontaudit_getattr_all_tcp_sockets(initrc_t)
domain_dontaudit_getattr_all_dgram_sockets(initrc_t)
domain_dontaudit_getattr_all_pipes(initrc_t)
domain_obj_id_change_exemption(initrc_t)

files_getattr_all_dirs(initrc_t)
files_getattr_all_files(initrc_t)
files_getattr_all_symlinks(initrc_t)
files_getattr_all_pipes(initrc_t)
files_getattr_all_sockets(initrc_t)
files_purge_tmp(initrc_t)
files_manage_all_locks(initrc_t)
files_manage_boot_files(initrc_t)
files_read_all_pids(initrc_t)
files_delete_root_files(initrc_t)
files_delete_all_pids(initrc_t)
files_delete_all_pid_dirs(initrc_t)
files_read_etc_files(initrc_t)
files_manage_etc_runtime_files(initrc_t)
files_etc_filetrans_etc_runtime(initrc_t, file)
files_exec_etc_files(initrc_t)
files_read_usr_files(initrc_t)
files_manage_urandom_seed(initrc_t)
files_manage_generic_spool(initrc_t)
# Mount and unmount file systems.
# cjp: not sure why these are here; should use mount policy
files_list_default(initrc_t)
files_mounton_default(initrc_t)
files_manage_mnt_dirs(initrc_t)
files_manage_mnt_files(initrc_t)

fs_delete_cgroup_dirs(initrc_t)
fs_list_cgroup_dirs(initrc_t)
fs_rw_cgroup_files(initrc_t)
fs_list_inotifyfs(initrc_t)
fs_register_binary_executable_type(initrc_t)
# rhgb-console writes to ramfs
fs_write_ramfs_pipes(initrc_t)
# cjp: not sure why these are here; should use mount policy
fs_mount_all_fs(initrc_t)
fs_unmount_all_fs(initrc_t)
fs_remount_all_fs(initrc_t)
fs_getattr_all_fs(initrc_t)
fs_search_all(initrc_t)
fs_getattr_nfsd_files(initrc_t)

# initrc_t needs to do a pidof which requires ptrace
mcs_ptrace_all(initrc_t)
mcs_file_read_all(initrc_t)
mcs_file_write_all(initrc_t)
mcs_killall(initrc_t)
mcs_process_set_categories(initrc_t)

mls_file_read_all_levels(initrc_t)
mls_file_write_all_levels(initrc_t)
mls_process_read_all_levels(initrc_t)
mls_process_write_all_levels(initrc_t)
mls_rangetrans_source(initrc_t)
mls_fd_share_all_levels(initrc_t)
mls_socket_write_to_clearance(initrc_t)

selinux_get_enforce_mode(initrc_t)

storage_getattr_fixed_disk_dev(initrc_t)
storage_setattr_fixed_disk_dev(initrc_t)
storage_setattr_removable_dev(initrc_t)

term_use_all_terms(initrc_t)
term_reset_tty_labels(initrc_t)

auth_rw_login_records(initrc_t)
auth_setattr_login_records(initrc_t)
auth_rw_lastlog(initrc_t)
auth_read_pam_pid(initrc_t)
auth_delete_pam_pid(initrc_t)
auth_delete_pam_console_data(initrc_t)
auth_use_nsswitch(initrc_t)

init_get_system_status(initrc_t)
init_stream_connect(initrc_t)
init_start_all_units(initrc_t)
init_stop_all_units(initrc_t)

libs_rw_ld_so_cache(initrc_t)
libs_exec_lib_files(initrc_t)
libs_exec_ld_so(initrc_t)

logging_send_audit_msgs(initrc_t)
logging_send_syslog_msg(initrc_t)
logging_manage_generic_logs(initrc_t)
logging_read_all_logs(initrc_t)
logging_append_all_logs(initrc_t)
logging_read_audit_config(initrc_t)

miscfiles_read_localization(initrc_t)
# slapd needs to read cert files from its initscript
miscfiles_manage_generic_cert_files(initrc_t)

seutil_read_config(initrc_t)

userdom_read_user_home_content_files(initrc_t)
# Allow access to the sysadm TTYs. Note that this will give access to the
# TTYs to any process in the initrc_t domain. Therefore, daemons and such
# started from init should be placed in their own domain.
userdom_use_inherited_user_terminals(initrc_t)

ifdef(`distro_debian',`
	kernel_getattr_core_if(initrc_t)

	dev_getattr_generic_blk_files(initrc_t)

	fs_tmpfs_filetrans(initrc_t, initrc_var_run_t, dir)

	# for storing state under /dev/shm
	fs_setattr_tmpfs_dirs(initrc_t)
	storage_manage_fixed_disk(initrc_t)
	storage_tmpfs_filetrans_fixed_disk(initrc_t)

	files_setattr_etc_dirs(initrc_t)

	optional_policy(`
		exim_manage_var_lib_files(initrc_t)
	')

	optional_policy(`
		gdomap_read_config(initrc_t)
	')

	optional_policy(`
		minissdpd_read_config(initrc_t)
	')
')

ifdef(`distro_gentoo',`
	kernel_dontaudit_getattr_core_if(initrc_t)

	# seed udev /dev
	allow initrc_t self:process setfscreate;
	dev_create_null_dev(initrc_t)
	dev_create_zero_dev(initrc_t)
	term_create_console_dev(initrc_t)

	# unfortunately /sbin/rc does stupid tricks
	# with /dev/.rcboot to decide if we are in
	# early init
	dev_create_generic_dirs(initrc_t)
	dev_delete_generic_dirs(initrc_t)
	dev_setattr_generic_dirs(initrc_t)

	files_manage_all_pids(initrc_t)
	# allow bootmisc to create /var/lock/.keep.
	files_manage_generic_locks(initrc_t)
	files_manage_var_symlinks(initrc_t)
	files_pid_filetrans(initrc_t, initrc_state_t, dir, "openrc")

	# openrc uses tmpfs for its state data
	fs_tmpfs_filetrans(initrc_t, initrc_state_t, { dir file fifo_file lnk_file })
	files_mountpoint(initrc_state_t)

	# init scripts touch this
	clock_dontaudit_write_adjtime(initrc_t)

	# for integrated run_init to read run_init_type.
	# happens during boot (/sbin/rc execs init scripts)
	seutil_read_default_contexts(initrc_t)

	# /lib/rcscripts/net/system.sh rewrites resolv.conf :(
	sysnet_manage_config(initrc_t)

	optional_policy(`
		abrt_manage_pid_files(initrc_t)
	')

	optional_policy(`
		alsa_read_lib(initrc_t)
	')

	optional_policy(`
		arpwatch_manage_data_files(initrc_t)
	')

	optional_policy(`
		dhcpd_setattr_state_files(initrc_t)
	')
')

ifdef(`distro_redhat',`
	# this is from kmodule, which should get its own policy:
	allow initrc_t self:capability sys_admin;

	allow initrc_t self:process setfscreate;

	# Red Hat systems seem to have a stray
	# fd open from the initrd
	kernel_use_fds(initrc_t)
	files_dontaudit_read_root_files(initrc_t)

	# These seem to be from the initrd
	# during device initialization:
	dev_create_generic_dirs(initrc_t)
	dev_rwx_zero(initrc_t)
	dev_rx_raw_memory(initrc_t)
	dev_wx_raw_memory(initrc_t)
	storage_raw_read_fixed_disk(initrc_t)
	storage_raw_write_fixed_disk(initrc_t)

	files_create_boot_dirs(initrc_t)
	files_create_boot_flag(initrc_t)
	files_rw_boot_symlinks(initrc_t)
	# wants to read /.fonts directory
	files_read_default_files(initrc_t)
	files_mountpoint(initrc_tmp_t)
	# Needs to cp localtime to /var dirs
	files_write_var_dirs(initrc_t)

	fs_read_tmpfs_symlinks(initrc_t)
	fs_rw_tmpfs_chr_files(initrc_t)

	storage_manage_fixed_disk(initrc_t)
	storage_dev_filetrans_fixed_disk(initrc_t)
	storage_getattr_removable_dev(initrc_t)

	# readahead asks for these
	auth_dontaudit_read_shadow(initrc_t)

	# init scripts cp /etc/localtime over other directories localtime
	miscfiles_rw_localization(initrc_t)
	miscfiles_setattr_localization(initrc_t)
	miscfiles_relabel_localization(initrc_t)

	miscfiles_read_fonts(initrc_t)
	miscfiles_read_hwdata(initrc_t)

	optional_policy(`
		alsa_manage_config(initrc_t)
	')

	optional_policy(`
		abrt_manage_pid_files(initrc_t)
	')

	optional_policy(`
		bind_manage_config_dirs(initrc_t)
		bind_write_config(initrc_t)
		bind_setattr_zone_dirs(initrc_t)
	')

	optional_policy(`
		devicekit_append_inherited_log_files(initrc_t)
	')

	optional_policy(`
		gnome_manage_gconf_config(initrc_t)
	')

	optional_policy(`
		pulseaudio_stream_connect(initrc_t)
	')

	optional_policy(`
		#for /etc/rc.d/init.d/nfs to create /etc/exports
		rpc_write_exports(initrc_t)
		rpc_manage_nfs_state_data(initrc_t)
	')
	optional_policy(`
		rpcbind_stream_connect(initrc_t)
	')

	optional_policy(`
		sysnet_rw_dhcp_config(initrc_t)
		sysnet_manage_config(initrc_t)
	')

	optional_policy(`
		xserver_delete_log(initrc_t)
	')
')

ifdef(`distro_suse',`
	optional_policy(`
		# set permissions on /tmp/.X11-unix
		xserver_setattr_xdm_tmp_dirs(initrc_t)
	')
')

ifdef(`enabled_mls',`
	optional_policy(`
		# allow init scripts to su
		su_restricted_domain_template(initrc, initrc_t, system_r)
		# Allow initrc_su_t, now defined, to transition to postgresql_t
		postgresql_domtrans(initrc_su_t)
		# Allow initrc_su_t to use the initrc_devpts_t (needed for init script failure output)
		allow initrc_su_t initrc_devpts_t:chr_file { read write };
	')
')

ifdef(`init_systemd',`
	allow initrc_t init_t:system { start status reboot halt reload };

	manage_files_pattern(initrc_t, initrc_lock_t, initrc_lock_t)
	files_lock_filetrans(initrc_t, initrc_lock_t, file)

	manage_dirs_pattern(initrc_t, init_var_run_t, init_var_run_t)
	allow initrc_t init_var_run_t:file create_file_perms;
	allow initrc_t init_var_run_t:lnk_file create_lnk_file_perms;
	allow initrc_t init_var_run_t:service { start status };

	manage_dirs_pattern(initrc_t, initrc_var_run_t, initrc_var_run_t)
	manage_chr_files_pattern(initrc_t, initrc_var_run_t, initrc_var_run_t)
	manage_lnk_files_pattern(initrc_t, initrc_var_run_t, initrc_var_run_t)
	files_pid_filetrans(initrc_t, initrc_var_run_t, dir_file_class_set)

	create_dirs_pattern(initrc_t, systemd_unit_t, systemd_unit_t)
	allow initrc_t systemd_unit_t:service reload;

	manage_files_pattern(initrc_t, systemdunit, systemdunit)
	manage_lnk_files_pattern(initrc_t, systemdunit, systemdunit)
	allow initrc_t systemdunit:service reload;
	allow initrc_t init_script_file_type:service { stop start status reload };

	kernel_dgram_send(initrc_t)

	# run systemd misc initializations
	# in the initrc_t domain, as would be
	# done in traditional sysvinit/upstart.
	corecmd_bin_entry_type(initrc_t)

	dev_create_generic_dirs(initrc_t)

	# Allow initrc_t to check /etc/fstab "service." It appears that
	# systemd is conflating files and services.
	files_get_etc_unit_status(initrc_t)
	files_create_pid_dirs(initrc_t)
	files_setattr_pid_dirs(initrc_t)

	# for logsave in strict configuration
	fstools_write_log(initrc_t)

	selinux_set_enforce_mode(initrc_t)

	init_get_all_units_status(initrc_t)
	init_manage_var_lib_files(initrc_t)
	init_rw_stream_sockets(initrc_t)

	# Create /etc/audit.rules.prev after firstboot remediation
	logging_manage_audit_config(initrc_t)

	# lvm2-activation-generator checks file labels
	seutil_read_file_contexts(initrc_t)

	systemd_start_power_units(initrc_t)

	optional_policy(`
		# create /var/lock/lvm/
		lvm_create_lock_dirs(initrc_t)
	')
')

optional_policy(`
	amavis_search_lib(initrc_t)
	amavis_setattr_pid_files(initrc_t)
')

optional_policy(`
	dev_rw_acpi_bios(initrc_t)
')

optional_policy(`
	apache_read_config(initrc_t)
	apache_list_modules(initrc_t)
	# webmin seems to cause this.
	apache_search_sys_content(daemon)
')

optional_policy(`
	asterisk_setattr_logs(initrc_t)
	asterisk_setattr_pid_files(initrc_t)
')

optional_policy(`
	bind_read_config(initrc_t)

	# for chmod in start script
	bind_setattr_pid_dirs(initrc_t)
')

optional_policy(`
	bluetooth_read_config(initrc_t)
')

optional_policy(`
	cgroup_stream_connect_cgred(initrc_t)
	domain_setpriority_all_domains(initrc_t)
')

optional_policy(`
	clamav_read_config(initrc_t)
')

optional_policy(`
	courier_read_config(initrc_t)
')

optional_policy(`
	cpucontrol_stub(initrc_t)
	dev_getattr_cpu_dev(initrc_t)
')

optional_policy(`
	cron_read_pipes(initrc_t)
	# managing /etc/cron.d/mailman content
	cron_manage_system_spool(initrc_t)
')

optional_policy(`
	dev_getattr_printer_dev(initrc_t)

	cups_read_log(initrc_t)
	cups_read_rw_config(initrc_t)
#cups init script clears error log
	cups_write_log(initrc_t)
')

optional_policy(`
	daemontools_manage_svc(initrc_t)
')

optional_policy(`
	dbus_connect_system_bus(initrc_t)
	dbus_system_bus_client(initrc_t)
	dbus_read_config(initrc_t)
	dbus_manage_lib_files(initrc_t)

	init_dbus_chat(initrc_t)

	optional_policy(`
		consolekit_dbus_chat(initrc_t)
		consolekit_manage_log(initrc_t)
	')

	optional_policy(`
		networkmanager_dbus_chat(initrc_t)
	')

	optional_policy(`
		policykit_dbus_chat(initrc_t)
	')
')

optional_policy(`
	# /var/run/dovecot/login/ssl-parameters.dat is a hard link to
	# /var/lib/dovecot/ssl-parameters.dat and init tries to clean up
	# the directory. But we do not want to allow this.
	# The master process of dovecot will manage this file.
	dovecot_dontaudit_unlink_lib_files(initrc_t)
')

optional_policy(`
	ftp_read_config(initrc_t)
')

optional_policy(`
	gpm_setattr_gpmctl(initrc_t)
')

optional_policy(`
	hal_write_log(initrc_t)
')

optional_policy(`
	# init scripts run /etc/hotplug/usb.rc
	hotplug_read_config(initrc_t)

	modutils_read_module_deps(initrc_t)
')

optional_policy(`
	inn_exec_config(initrc_t)
')

optional_policy(`
	ipsec_read_config(initrc_t)
	ipsec_manage_pid(initrc_t)
')

optional_policy(`
	iptables_read_config(initrc_t)
')

optional_policy(`
	iscsi_stream_connect(initrc_t)
	iscsi_read_lib_files(initrc_t)
')

optional_policy(`
	kerberos_use(initrc_t)
')

optional_policy(`
	ldap_read_config(initrc_t)
	ldap_list_db(initrc_t)
')

optional_policy(`
	loadkeys_exec(initrc_t)
')

optional_policy(`
	# in emergency/recovery situations use sulogin
	locallogin_domtrans_sulogin(initrc_t)
')

optional_policy(`
	# This is needed to permit chown to read /var/spool/lpd/lp.
	# This is opens up security more than necessary; this means that ANYTHING
	# running in the initrc_t domain can read the printer spool directory.
	# Perhaps executing /etc/rc.d/init.d/lpd should transition
	# to domain lpd_t, instead of waiting for executing lpd.
	lpd_list_spool(initrc_t)

	lpd_read_config(initrc_t)
	lpd_manage_spool(init_t)
')

optional_policy(`
	#allow initrc_t lvm_control_t:chr_file unlink;

	dev_read_lvm_control(initrc_t)
	dev_create_generic_chr_files(initrc_t)

	lvm_read_config(initrc_t)
')

optional_policy(`
	mailman_list_data(initrc_t)
	mailman_read_data_symlinks(initrc_t)
')

optional_policy(`
	modutils_read_module_config(initrc_t)
	modutils_domtrans(initrc_t)
')

optional_policy(`
	mta_read_config(initrc_t)
	mta_write_config(initrc_t)
	mta_dontaudit_read_spool_symlinks(initrc_t)
')

optional_policy(`
	ifdef(`distro_redhat',`
		mysql_manage_db_dirs(initrc_t)
	')

	mysql_stream_connect(initrc_t)
	mysql_write_log(initrc_t)
	mysql_read_config(initrc_t)
')

optional_policy(`
	nis_list_var_yp(initrc_t)
')

optional_policy(`
	openvpn_read_config(initrc_t)
')

optional_policy(`
	plymouthd_stream_connect(initrc_t)
')

optional_policy(`
	postgresql_manage_db(initrc_t)
	postgresql_read_config(initrc_t)
')

optional_policy(`
	postfix_list_spool(initrc_t)
')

optional_policy(`
	puppet_rw_tmp(initrc_t)
')

optional_policy(`
	quota_manage_flags(initrc_t)
')

optional_policy(`
	raid_manage_mdadm_pid(initrc_t)
')

optional_policy(`
	fs_write_ramfs_sockets(initrc_t)
	fs_search_ramfs(initrc_t)

	rhgb_rw_stream_sockets(initrc_t)
	rhgb_stream_connect(initrc_t)
')

optional_policy(`
	rpc_read_exports(initrc_t)
')

optional_policy(`
	# bash tries to access a block device in the initrd
	kernel_dontaudit_getattr_unlabeled_blk_files(initrc_t)

	# for a bug in rm
	files_dontaudit_write_all_pids(initrc_t)

	# bash tries ioctl for some reason
	files_dontaudit_ioctl_all_pids(initrc_t)

')

optional_policy(`
	samba_rw_config(initrc_t)
	samba_read_winbind_pid(initrc_t)
')

optional_policy(`
	# shorewall-init script run /var/lib/shorewall/firewall
	shorewall_lib_domtrans(initrc_t)
')

optional_policy(`
	squid_read_config(initrc_t)
	squid_manage_logs(initrc_t)
')

optional_policy(`
	ssh_dontaudit_read_server_keys(initrc_t)
	ssh_setattr_key_files(initrc_t)
')

optional_policy(`
	stunnel_read_config(initrc_t)
')

optional_policy(`
	sysnet_read_dhcpc_state(initrc_t)
')

optional_policy(`
	udev_manage_pid_files(initrc_t)
	udev_manage_pid_dirs(initrc_t)
	udev_manage_rules_files(initrc_t)
')

optional_policy(`
	uml_setattr_util_sockets(initrc_t)
')

optional_policy(`
	virt_stream_connect(initrc_t)
	virt_manage_virt_cache(initrc_t)
')

optional_policy(`
	domain_role_change_exemption(initrc_t)

	unconfined_domain(initrc_t)

	optional_policy(`
		mono_domtrans(initrc_t)
	')

	optional_policy(`
		rtkit_scheduled(initrc_t)
	')
')

optional_policy(`
	rpm_read_db(initrc_t)
	rpm_delete_db(initrc_t)
')

optional_policy(`
	vmware_read_system_config(initrc_t)
	vmware_append_system_config(initrc_t)
')

optional_policy(`
	miscfiles_manage_fonts(initrc_t)

	# cjp: is this really needed?
	xfs_read_sockets(initrc_t)
')

optional_policy(`
	# Set device ownerships/modes.
	xserver_setattr_console_pipes(initrc_t)

	# init script wants to check if it needs to update windowmanagerlist
	xserver_read_xdm_rw_config(initrc_t)
')

optional_policy(`
	zebra_read_config(initrc_t)
')

ifdef(`distro_gentoo',`
	# Attribute to assign to types that the initrc_t domain needs read access to
	attribute init_script_readable;

	#####################################
	#
	# Local initrc_t policy
	#
	allow initrc_t self:capability sys_admin;

	read_files_pattern(initrc_t, init_script_readable, init_script_readable)
	read_lnk_files_pattern(initrc_t, init_script_readable, init_script_readable)

	manage_dirs_pattern(initrc_t, initrc_var_run_t, initrc_var_run_t)
	files_pid_filetrans(initrc_t, initrc_var_run_t, dir)

	kernel_write_proc_files(initrc_t)

	dev_manage_sysfs_dirs(initrc_t)
	# needs to chmod some devices in early boot
	dev_setattr_generic_chr_files(initrc_t)

	files_dontaudit_write_usr_dirs(initrc_t)
	files_manage_generic_tmp_dirs(initrc_t)
	files_manage_generic_tmp_files(initrc_t)

	fs_manage_cgroup_dirs(initrc_t)
	fs_manage_cgroup_files(initrc_t)

	logging_delete_devlog_socket(initrc_t)

	selinux_set_enforce_mode(initrc_t)

	optional_policy(`
		alsa_write_lib(initrc_t)
	')

	optional_policy(`
		mysql_setattr_run_dirs(initrc_t)
	')

	optional_policy(`
		networkmanager_rw_rawip_sockets(initrc_t)
		networkmanager_stream_connect(initrc_t)
	')

	optional_policy(`
		fail2ban_stream_connect(initrc_t)
	')

	optional_policy(`
		rpc_manage_nfs_state_data(initrc_t)
	')

	optional_policy(`
		udev_create_rules_dirs(initrc_t)
		udev_pid_filetrans_rules(initrc_t, dir, "rules.d")
	')
')

########################################
#
# Rules applied to all daemons
#

domain_dontaudit_use_interactive_fds(daemon)

# daemons started from init will
# inherit fds from init for the console
term_dontaudit_use_console(daemon)

init_dontaudit_use_fds(daemon)
# init script ptys are the stdin/out/err
# when using run_init
init_use_script_ptys(daemon)

ifdef(`init_systemd',`
	# Until systemd is fixed
	allow daemon init_t:socket_class_set { getopt read getattr ioctl setopt write };

	fs_search_cgroup_dirs(daemon)

	# need write to /var/run/systemd/notify
	init_write_runtime_socket(daemon)
')

tunable_policy(`init_daemons_use_tty',`
	term_use_unallocated_ttys(daemon)
	term_use_generic_ptys(daemon)
	term_use_all_ttys(daemon)
	term_use_all_ptys(daemon)
',`
	term_dontaudit_use_unallocated_ttys(daemon)
	term_dontaudit_use_generic_ptys(daemon)
	term_dontaudit_use_all_ttys(daemon)
	term_dontaudit_use_all_ptys(daemon)
 ')

tunable_policy(`use_nfs_home_dirs',`
	fs_dontaudit_rw_nfs_files(daemon)
')

tunable_policy(`use_samba_home_dirs',`
	fs_dontaudit_rw_cifs_files(daemon)
')

optional_policy(`
	unconfined_dontaudit_rw_pipes(daemon)
	unconfined_dontaudit_rw_stream_sockets(daemon)
')

optional_policy(`
	userdom_dontaudit_rw_all_users_stream_sockets(daemon)
	userdom_dontaudit_read_user_tmp_files(daemon)
	userdom_dontaudit_write_user_tmp_files(daemon)
')

########################################
#
# Rules applied to all system processes
#

dontaudit systemprocess init_t:unix_stream_socket getattr;

optional_policy(`
	userdom_dontaudit_search_user_home_dirs(systemprocess)
	userdom_dontaudit_rw_all_users_stream_sockets(systemprocess)
	userdom_dontaudit_write_user_tmp_files(systemprocess)
')