summaryrefslogtreecommitdiff
path: root/policy/modules/system/userdomain.if
blob: f209ccff8b7148abe18993d56d9fff1e24f7168b (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
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
## <summary>Policy for user domains</summary>

#######################################
## <summary>
##	The template containing the most basic rules common to all users.
## </summary>
## <desc>
##	<p>
##	The template containing the most basic rules common to all users.
##	</p>
##	<p>
##	This template creates a user domain, types, and
##	rules for the user's tty and pty.
##	</p>
## </desc>
## <param name="userdomain_prefix">
##	<summary>
##	The prefix of the user domain (e.g., user
##	is the prefix for user_t).
##	</summary>
## </param>
## <rolebase/>
#
template(`userdom_base_user_template',`

	gen_require(`
		attribute userdomain;
		type user_devpts_t, user_tty_device_t;
		class context contains;
	')

	attribute $1_file_type;

	type $1_t, userdomain;
	domain_type($1_t)
	corecmd_shell_entry_type($1_t)
	corecmd_bin_entry_type($1_t)
	domain_user_exemption_target($1_t)
	ubac_constrained($1_t)
	role $1_r types $1_t;
	allow system_r $1_r;

	term_user_pty($1_t, user_devpts_t)

	term_user_tty($1_t, user_tty_device_t)

	allow $1_t self:process { signal_perms getsched setsched share getpgid setpgid setcap getsession getattr };
	allow $1_t self:fd use;
	allow $1_t self:fifo_file rw_fifo_file_perms;
	allow $1_t self:unix_dgram_socket { create_socket_perms sendto };
	allow $1_t self:unix_stream_socket { create_stream_socket_perms connectto };
	allow $1_t self:shm create_shm_perms;
	allow $1_t self:sem create_sem_perms;
	allow $1_t self:msgq create_msgq_perms;
	allow $1_t self:msg { send receive };
	allow $1_t self:context contains;
	dontaudit $1_t self:socket create;

	allow $1_t user_devpts_t:chr_file { setattr rw_chr_file_perms };
	term_create_pty($1_t, user_devpts_t)
	# avoid annoying messages on terminal hangup on role change
	dontaudit $1_t user_devpts_t:chr_file ioctl;

	allow $1_t user_tty_device_t:chr_file { setattr rw_chr_file_perms };
	# avoid annoying messages on terminal hangup on role change
	dontaudit $1_t user_tty_device_t:chr_file ioctl;

	kernel_read_kernel_sysctls($1_t)
	kernel_dontaudit_list_unlabeled($1_t)
	kernel_dontaudit_getattr_unlabeled_files($1_t)
	kernel_dontaudit_getattr_unlabeled_symlinks($1_t)
	kernel_dontaudit_getattr_unlabeled_pipes($1_t)
	kernel_dontaudit_getattr_unlabeled_sockets($1_t)
	kernel_dontaudit_getattr_unlabeled_blk_files($1_t)
	kernel_dontaudit_getattr_unlabeled_chr_files($1_t)

	dev_dontaudit_getattr_all_blk_files($1_t)
	dev_dontaudit_getattr_all_chr_files($1_t)

	# When the user domain runs ps, there will be a number of access
	# denials when ps tries to search /proc. Do not audit these denials.
	domain_dontaudit_read_all_domains_state($1_t)
	domain_dontaudit_getattr_all_domains($1_t)
	domain_dontaudit_getsession_all_domains($1_t)

	files_read_etc_files($1_t)
	files_read_etc_runtime_files($1_t)
	files_read_usr_files($1_t)
	# Read directories and files with the readable_t type.
	# This type is a general type for "world"-readable files.
	files_list_world_readable($1_t)
	files_read_world_readable_files($1_t)
	files_read_world_readable_symlinks($1_t)
	files_read_world_readable_pipes($1_t)
	files_read_world_readable_sockets($1_t)
	# old broswer_domain():
	files_dontaudit_list_non_security($1_t)
	files_dontaudit_getattr_non_security_files($1_t)
	files_dontaudit_getattr_non_security_symlinks($1_t)
	files_dontaudit_getattr_non_security_pipes($1_t)
	files_dontaudit_getattr_non_security_sockets($1_t)

	libs_exec_ld_so($1_t)

	miscfiles_read_localization($1_t)
	miscfiles_read_certs($1_t)

	sysnet_read_config($1_t)

	tunable_policy(`allow_execmem',`
		# Allow loading DSOs that require executable stack.
		allow $1_t self:process execmem;
	')

	tunable_policy(`allow_execmem && allow_execstack',`
		# Allow making the stack executable via mprotect.
		allow $1_t self:process execstack;
	')
')

#######################################
## <summary>
##	Allow a home directory for which the
##	role has read-only access.
## </summary>
## <desc>
##	<p>
##	Allow a home directory for which the
##	role has read-only access.
##	</p>
##	<p>
##	This does not allow execute access.
##	</p>
## </desc>
## <param name="role">
##	<summary>
##	The user role
##	</summary>
## </param>
## <param name="userdomain">
##	<summary>
##	The user domain
##	</summary>
## </param>
## <rolebase/>
#
interface(`userdom_ro_home_role',`
	gen_require(`
		type user_home_t, user_home_dir_t;
	')

	role $1 types { user_home_t user_home_dir_t };

	##############################
	#
	# Domain access to home dir
	#

	type_member $2 user_home_dir_t:dir user_home_dir_t;

	# read-only home directory
	allow $2 user_home_dir_t:dir list_dir_perms;
	allow $2 user_home_t:dir list_dir_perms;
	allow $2 user_home_t:file entrypoint;
	read_files_pattern($2, { user_home_t user_home_dir_t }, user_home_t)
	read_lnk_files_pattern($2, { user_home_t user_home_dir_t }, user_home_t)
	read_fifo_files_pattern($2, { user_home_t user_home_dir_t }, user_home_t)
	read_sock_files_pattern($2, { user_home_t user_home_dir_t }, user_home_t)
	files_list_home($2)

	tunable_policy(`use_nfs_home_dirs',`
		fs_list_nfs($2)
		fs_read_nfs_files($2)
		fs_read_nfs_symlinks($2)
		fs_read_nfs_named_sockets($2)
		fs_read_nfs_named_pipes($2)
	',`
		fs_dontaudit_list_nfs($2)
		fs_dontaudit_read_nfs_files($2)
	')

	tunable_policy(`use_samba_home_dirs',`
		fs_list_cifs($2)
		fs_read_cifs_files($2)
		fs_read_cifs_symlinks($2)
		fs_read_cifs_named_sockets($2)
		fs_read_cifs_named_pipes($2)
	',`
		fs_dontaudit_list_cifs($2)
		fs_dontaudit_read_cifs_files($2)
	')
')

#######################################
## <summary>
##	Allow a home directory for which the
##	role has full access.
## </summary>
## <desc>
##	<p>
##	Allow a home directory for which the
##	role has full access.
##	</p>
##	<p>
##	This does not allow execute access.
##	</p>
## </desc>
## <param name="role">
##	<summary>
##	The user role
##	</summary>
## </param>
## <param name="userdomain">
##	<summary>
##	The user domain
##	</summary>
## </param>
## <rolebase/>
#
interface(`userdom_manage_home_role',`
	gen_require(`
		type user_home_t, user_home_dir_t;
	')

	role $1 types { user_home_t user_home_dir_t };

	##############################
	#
	# Domain access to home dir
	#

	type_member $2 user_home_dir_t:dir user_home_dir_t;

	# full control of the home directory
	allow $2 user_home_t:file entrypoint;
	manage_dirs_pattern($2, { user_home_dir_t user_home_t }, user_home_t)
	manage_files_pattern($2, { user_home_dir_t user_home_t }, user_home_t)
	manage_lnk_files_pattern($2, { user_home_dir_t user_home_t }, user_home_t)
	manage_sock_files_pattern($2, { user_home_dir_t user_home_t }, user_home_t)
	manage_fifo_files_pattern($2, { user_home_dir_t user_home_t }, user_home_t)
	relabel_dirs_pattern($2, { user_home_dir_t user_home_t }, user_home_t)
	relabel_files_pattern($2, { user_home_dir_t user_home_t }, user_home_t)
	relabel_lnk_files_pattern($2, { user_home_dir_t user_home_t }, user_home_t)
	relabel_sock_files_pattern($2, { user_home_dir_t user_home_t }, user_home_t)
	relabel_fifo_files_pattern($2, { user_home_dir_t user_home_t }, user_home_t)
	filetrans_pattern($2, user_home_dir_t, user_home_t, { dir file lnk_file sock_file fifo_file })
	files_list_home($2)

	# cjp: this should probably be removed:
	allow $2 user_home_dir_t:dir { manage_dir_perms relabel_dir_perms };

	tunable_policy(`use_nfs_home_dirs',`
		fs_manage_nfs_dirs($2)
		fs_manage_nfs_files($2)
		fs_manage_nfs_symlinks($2)
		fs_manage_nfs_named_sockets($2)
		fs_manage_nfs_named_pipes($2)
	',`
		fs_dontaudit_manage_nfs_dirs($2)
		fs_dontaudit_manage_nfs_files($2)
	')

	tunable_policy(`use_samba_home_dirs',`
		fs_manage_cifs_dirs($2)
		fs_manage_cifs_files($2)
		fs_manage_cifs_symlinks($2)
		fs_manage_cifs_named_sockets($2)
		fs_manage_cifs_named_pipes($2)
	',`
		fs_dontaudit_manage_cifs_dirs($2)
		fs_dontaudit_manage_cifs_files($2)
	')
')

#######################################
## <summary>
##	Manage user temporary files
## </summary>
## <param name="role">
##	<summary>
##	Role allowed access.
##	</summary>
## </param>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
## <rolebase/>
#
interface(`userdom_manage_tmp_role',`
	gen_require(`
		type user_tmp_t;
	')

	role $1 types user_tmp_t;

	files_poly_member_tmp($2, user_tmp_t)

	manage_dirs_pattern($2, user_tmp_t, user_tmp_t)
	manage_files_pattern($2, user_tmp_t, user_tmp_t)
	manage_lnk_files_pattern($2, user_tmp_t, user_tmp_t)
	manage_sock_files_pattern($2, user_tmp_t, user_tmp_t)
	manage_fifo_files_pattern($2, user_tmp_t, user_tmp_t)
	files_tmp_filetrans($2, user_tmp_t, { dir file lnk_file sock_file fifo_file })
')

#######################################
## <summary>
##	The execute access user temporary files.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
## <rolebase/>
#
interface(`userdom_exec_user_tmp_files',`
	gen_require(`
		type user_tmp_t;
	')

	exec_files_pattern($1, user_tmp_t, user_tmp_t)
	files_search_tmp($1)
')

#######################################
## <summary>
##	Role access for the user tmpfs type
##	that the user has full access.
## </summary>
## <desc>
##	<p>
##	Role access for the user tmpfs type
##	that the user has full access.
##	</p>
##	<p>
##	This does not allow execute access.
##	</p>
## </desc>
## <param name="role">
##	<summary>
##	Role allowed access.
##	</summary>
## </param>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
## <rolecap/>
#
interface(`userdom_manage_tmpfs_role',`
	gen_require(`
		type user_tmpfs_t;
	')

	role $1 types user_tmpfs_t;

	manage_dirs_pattern($2, user_tmpfs_t, user_tmpfs_t)
	manage_files_pattern($2, user_tmpfs_t, user_tmpfs_t)
	manage_lnk_files_pattern($2, user_tmpfs_t, user_tmpfs_t)
	manage_sock_files_pattern($2, user_tmpfs_t, user_tmpfs_t)
	manage_fifo_files_pattern($2, user_tmpfs_t, user_tmpfs_t)
	fs_tmpfs_filetrans($2, user_tmpfs_t, { dir file lnk_file sock_file fifo_file })
')

#######################################
## <summary>
##	The template allowing the user basic
##	network permissions
## </summary>
## <param name="userdomain_prefix">
##	<summary>
##	The prefix of the user domain (e.g., user
##	is the prefix for user_t).
##	</summary>
## </param>
## <rolebase/>
#
template(`userdom_basic_networking_template',`
	gen_require(`
		type $1_t;
	')

	allow $1_t self:tcp_socket create_stream_socket_perms;
	allow $1_t self:udp_socket create_socket_perms;

	corenet_all_recvfrom_unlabeled($1_t)
	corenet_all_recvfrom_netlabel($1_t)
	corenet_tcp_sendrecv_generic_if($1_t)
	corenet_udp_sendrecv_generic_if($1_t)
	corenet_tcp_sendrecv_generic_node($1_t)
	corenet_udp_sendrecv_generic_node($1_t)
	corenet_tcp_sendrecv_all_ports($1_t)
	corenet_udp_sendrecv_all_ports($1_t)
	corenet_tcp_connect_all_ports($1_t)
	corenet_sendrecv_all_client_packets($1_t)

	corenet_all_recvfrom_labeled($1_t, $1_t)

	optional_policy(`
		init_tcp_recvfrom_all_daemons($1_t)
		init_udp_recvfrom_all_daemons($1_t)
	')

	optional_policy(`
		ipsec_match_default_spd($1_t)
	')
')

#######################################
## <summary>
##	The template for creating a user xwindows client.  (Deprecated)
## </summary>
## <param name="userdomain_prefix">
##	<summary>
##	The prefix of the user domain (e.g., user
##	is the prefix for user_t).
##	</summary>
## </param>
## <rolebase/>
#
template(`userdom_xwindows_client_template',`
	refpolicywarn(`$0() has been deprecated, please use xserver_role() instead.')
	gen_require(`
		type $1_t, user_tmpfs_t;
	')

	dev_rw_xserver_misc($1_t)
	dev_rw_power_management($1_t)
	dev_read_input($1_t)
	dev_read_misc($1_t)
	dev_write_misc($1_t)
	# open office is looking for the following
	dev_getattr_agp_dev($1_t)
	dev_dontaudit_rw_dri($1_t)
	# GNOME checks for usb and other devices:
	dev_rw_usbfs($1_t)

	xserver_user_x_domain_template($1, $1_t, user_tmpfs_t)
	xserver_xsession_entry_type($1_t)
	xserver_dontaudit_write_log($1_t)
	xserver_stream_connect_xdm($1_t)
	# certain apps want to read xdm.pid file
	xserver_read_xdm_pid($1_t)
	# gnome-session creates socket under /tmp/.ICE-unix/
	xserver_create_xdm_tmp_sockets($1_t)
	# Needed for escd, remove if we get escd policy
	xserver_manage_xdm_tmp_files($1_t)
')

#######################################
## <summary>
##	The template for allowing the user to change passwords.
## </summary>
## <param name="userdomain_prefix">
##	<summary>
##	The prefix of the user domain (e.g., user
##	is the prefix for user_t).
##	</summary>
## </param>
## <rolebase/>
#
template(`userdom_change_password_template',`
	gen_require(`
		type $1_t;
		role $1_r;
	')

	optional_policy(`
		usermanage_run_chfn($1_t,$1_r)
		usermanage_run_passwd($1_t,$1_r)
	')
')

#######################################
## <summary>
##	The template containing rules common to unprivileged
##	users and administrative users.
## </summary>
## <desc>
##	<p>
##	This template creates a user domain, types, and
##	rules for the user's tty, pty, tmp, and tmpfs files.
##	</p>
## </desc>
## <param name="userdomain_prefix">
##	<summary>
##	The prefix of the user domain (e.g., user
##	is the prefix for user_t).
##	</summary>
## </param>
#
template(`userdom_common_user_template',`
	gen_require(`
		attribute unpriv_userdomain;
	')

	userdom_basic_networking_template($1)

	##############################
	#
	# User domain Local policy
	#

	# evolution and gnome-session try to create a netlink socket
	dontaudit $1_t self:netlink_socket { create ioctl read getattr write setattr append bind connect getopt setopt shutdown };
	dontaudit $1_t self:netlink_route_socket { create ioctl read getattr write setattr append bind connect getopt setopt shutdown nlmsg_read nlmsg_write };

	allow $1_t unpriv_userdomain:fd use;

	kernel_read_system_state($1_t)
	kernel_read_network_state($1_t)
	kernel_read_net_sysctls($1_t)
	# Very permissive allowing every domain to see every type:
	kernel_get_sysvipc_info($1_t)
	# Find CDROM devices:
	kernel_read_device_sysctls($1_t)

	corecmd_exec_bin($1_t)

	corenet_udp_bind_generic_node($1_t)
	corenet_udp_bind_generic_port($1_t)

	dev_read_rand($1_t)
	dev_write_sound($1_t)
	dev_read_sound($1_t)
	dev_read_sound_mixer($1_t)
	dev_write_sound_mixer($1_t)

	files_exec_etc_files($1_t)
	files_search_locks($1_t)
	# Check to see if cdrom is mounted
	files_search_mnt($1_t)
	# cjp: perhaps should cut back on file reads:
	files_read_var_files($1_t)
	files_read_var_symlinks($1_t)
	files_read_generic_spool($1_t)
	files_read_var_lib_files($1_t)
	# Stat lost+found.
	files_getattr_lost_found_dirs($1_t)

	# cjp: some of this probably can be removed
	selinux_get_fs_mount($1_t)
	selinux_validate_context($1_t)
	selinux_compute_access_vector($1_t)
	selinux_compute_create_context($1_t)
	selinux_compute_relabel_context($1_t)
	selinux_compute_user_contexts($1_t)

	# for eject
	storage_getattr_fixed_disk_dev($1_t)

	auth_use_nsswitch($1_t)
	auth_read_login_records($1_t)
	auth_search_pam_console_data($1_t)
	auth_run_pam($1_t,$1_r)
	auth_run_utempter($1_t,$1_r)

	init_read_utmp($1_t)

	seutil_read_file_contexts($1_t)
	seutil_read_default_contexts($1_t)
	seutil_run_newrole($1_t,$1_r)
	seutil_exec_checkpolicy($1_t)
	seutil_exec_setfiles($1_t)
	# for when the network connection is killed
	# this is needed when a login role can change
	# to this one.
	seutil_dontaudit_signal_newrole($1_t)

	tunable_policy(`user_direct_mouse',`
		dev_read_mouse($1_t)
	')

	tunable_policy(`user_ttyfile_stat',`
		term_getattr_all_user_ttys($1_t)
	')

	optional_policy(`
		alsa_read_rw_config($1_t)
	')

	optional_policy(`
		# Allow graphical boot to check battery lifespan
		apm_stream_connect($1_t)
	')

	optional_policy(`
		canna_stream_connect($1_t)
	')

	optional_policy(`
		dbus_system_bus_client($1_t)

		optional_policy(`
			bluetooth_dbus_chat($1_t)
		')

		optional_policy(`
			evolution_dbus_chat($1_t)
			evolution_alarm_dbus_chat($1_t)
		')

		optional_policy(`
			cups_dbus_chat_config($1_t)
		')

		optional_policy(`
			hal_dbus_chat($1_t)
		')

		optional_policy(`
			networkmanager_dbus_chat($1_t)
		')
	')

	optional_policy(`
		inetd_use_fds($1_t)
		inetd_rw_tcp_sockets($1_t)
	')

	optional_policy(`
		inn_read_config($1_t)
		inn_read_news_lib($1_t)
		inn_read_news_spool($1_t)
	')

	optional_policy(`
		locate_read_lib_files($1_t)
	')

	# for running depmod as part of the kernel packaging process
	optional_policy(`
		modutils_read_module_config($1_t)
	')

	optional_policy(`
		mta_rw_spool($1_t)
	')

	optional_policy(`
		tunable_policy(`allow_user_mysql_connect',`
			mysql_stream_connect($1_t)
		')
	')

	optional_policy(`
		# to allow monitoring of pcmcia status
		pcmcia_read_pid($1_t)
	')

	optional_policy(`
		pcscd_read_pub_files($1_t)
		pcscd_stream_connect($1_t)
	')

	optional_policy(`
		tunable_policy(`allow_user_postgresql_connect',`
			postgresql_stream_connect($1_t)
			postgresql_tcp_connect($1_t)
		')
	')

	optional_policy(`
		resmgr_stream_connect($1_t)
	')

	optional_policy(`
		rpc_dontaudit_getattr_exports($1_t)
		rpc_manage_nfs_rw_content($1_t)
	')

	optional_policy(`
		samba_stream_connect_winbind($1_t)
	')

	optional_policy(`
		slrnpull_search_spool($1_t)
	')

	optional_policy(`
		usernetctl_run($1_t,$1_r)
	')
')

#######################################
## <summary>
##	The template for creating a login user.
## </summary>
## <desc>
##	<p>
##	This template creates a user domain, types, and
##	rules for the user's tty, pty, home directories,
##	tmp, and tmpfs files.
##	</p>
## </desc>
## <param name="userdomain_prefix">
##	<summary>
##	The prefix of the user domain (e.g., user
##	is the prefix for user_t).
##	</summary>
## </param>
#
template(`userdom_login_user_template', `
	gen_require(`
		class context contains;
	')

	userdom_base_user_template($1)

	userdom_manage_home_role($1_r, $1_t)

	userdom_manage_tmp_role($1_r, $1_t)
	userdom_manage_tmpfs_role($1_r, $1_t)

	userdom_exec_user_tmp_files($1_t)
	userdom_exec_user_home_content_files($1_t)

	userdom_change_password_template($1)

	##############################
	#
	# User domain Local policy
	#

	allow $1_t self:capability { setgid chown fowner };
	dontaudit $1_t self:capability { sys_nice fsetid };

	allow $1_t self:process ~{ setcurrent setexec setrlimit execmem execstack execheap };
	dontaudit $1_t self:process setrlimit;
	dontaudit $1_t self:netlink_route_socket { create ioctl read getattr write setattr append bind connect getopt setopt shutdown nlmsg_read nlmsg_write };

	allow $1_t self:context contains;

	kernel_dontaudit_read_system_state($1_t)

	dev_read_sysfs($1_t)
	dev_read_urand($1_t)

	domain_use_interactive_fds($1_t)
	# Command completion can fire hundreds of denials
	domain_dontaudit_exec_all_entry_files($1_t)

	files_dontaudit_list_default($1_t)
	files_dontaudit_read_default_files($1_t)
	# Stat lost+found.
	files_getattr_lost_found_dirs($1_t)

	fs_get_all_fs_quotas($1_t)
	fs_getattr_all_fs($1_t)
	fs_getattr_all_dirs($1_t)
	fs_search_auto_mountpoints($1_t)
	fs_list_inotifyfs($1_t)
	fs_rw_anon_inodefs_files($1_t)

	auth_dontaudit_write_login_records($1_t)

	application_exec_all($1_t)

	# The library functions always try to open read-write first,
	# then fall back to read-only if it fails. 
	init_dontaudit_rw_utmp($1_t)
	# Stop warnings about access to /dev/console
	init_dontaudit_use_fds($1_t)
	init_dontaudit_use_script_fds($1_t)

	libs_exec_lib_files($1_t)

	logging_dontaudit_getattr_all_logs($1_t)

	miscfiles_read_man_pages($1_t)
	# for running TeX programs
	miscfiles_read_tetex_data($1_t)
	miscfiles_exec_tetex_data($1_t)

	seutil_read_config($1_t)

	optional_policy(`
		cups_read_config($1_t)
		cups_stream_connect($1_t)
		cups_stream_connect_ptal($1_t)
	')

	optional_policy(`
		kerberos_use($1_t)
	')

	optional_policy(`
		mta_dontaudit_read_spool_symlinks($1_t)
	')

	optional_policy(`
		quota_dontaudit_getattr_db($1_t)
	')

	optional_policy(`
		rpm_read_db($1_t)
		rpm_dontaudit_manage_db($1_t)
	')
')

#######################################
## <summary>
##	The template for creating a unprivileged login user.
## </summary>
## <desc>
##	<p>
##	This template creates a user domain, types, and
##	rules for the user's tty, pty, home directories,
##	tmp, and tmpfs files.
##	</p>
## </desc>
## <param name="userdomain_prefix">
##	<summary>
##	The prefix of the user domain (e.g., user
##	is the prefix for user_t).
##	</summary>
## </param>
#
template(`userdom_restricted_user_template',`
	gen_require(`
		attribute unpriv_userdomain;
	')

	userdom_login_user_template($1)

	typeattribute $1_t unpriv_userdomain;
	domain_interactive_fd($1_t)

	##############################
	#
	# Local policy
	#

	optional_policy(`
		loadkeys_run($1_t,$1_r)
	')
')

#######################################
## <summary>
##	The template for creating a unprivileged xwindows login user.
## </summary>
## <desc>
##	<p>
##	The template for creating a unprivileged xwindows login user.
##	</p>
##	<p>
##	This template creates a user domain, types, and
##	rules for the user's tty, pty, home directories,
##	tmp, and tmpfs files.
##	</p>
## </desc>
## <param name="userdomain_prefix">
##	<summary>
##	The prefix of the user domain (e.g., user
##	is the prefix for user_t).
##	</summary>
## </param>
#
template(`userdom_restricted_xwindows_user_template',`

	userdom_restricted_user_template($1)

	##############################
	#
	# Local policy
	#

	auth_role($1_r, $1_t)
	auth_search_pam_console_data($1_t)

	dev_read_sound($1_t)
	dev_write_sound($1_t)
	# gnome keyring wants to read this.
	dev_dontaudit_read_rand($1_t)

	logging_send_syslog_msg($1_t)
	logging_dontaudit_send_audit_msgs($1_t)

	# Need to to this just so screensaver will work. Should be moved to screensaver domain
	logging_send_audit_msgs($1_t)
	selinux_get_enforce_mode($1_t)

	xserver_restricted_role($1_r, $1_t)

	optional_policy(`
		alsa_read_rw_config($1_t)
	')

	optional_policy(`
		dbus_role_template($1, $1_r, $1_t)
		dbus_system_bus_client($1_t)

		optional_policy(`
			consolekit_dbus_chat($1_t)
		')

		optional_policy(`
			cups_dbus_chat($1_t)
		')
	')

	optional_policy(`
		java_role($1_r, $1_t)
	')

	optional_policy(`
		setroubleshoot_dontaudit_stream_connect($1_t)
	')
')

#######################################
## <summary>
##	The template for creating a unprivileged user roughly
##	equivalent to a regular linux user.
## </summary>
## <desc>
##	<p>
##	The template for creating a unprivileged user roughly
##	equivalent to a regular linux user.
##	</p>
##	<p>
##	This template creates a user domain, types, and
##	rules for the user's tty, pty, home directories,
##	tmp, and tmpfs files.
##	</p>
## </desc>
## <param name="userdomain_prefix">
##	<summary>
##	The prefix of the user domain (e.g., user
##	is the prefix for user_t).
##	</summary>
## </param>
#
template(`userdom_unpriv_user_template', `

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

	# Inherit rules for ordinary users.
	userdom_restricted_user_template($1)
	userdom_common_user_template($1)

	##############################
	#
	# Local policy
	#

	# port access is audited even if dac would not have allowed it, so dontaudit it here
	corenet_dontaudit_tcp_bind_all_reserved_ports($1_t)
	# Need the following rule to allow users to run vpnc
	corenet_tcp_bind_xserver_port($1_t)

	files_exec_usr_files($1_t)
	# cjp: why?
	files_read_kernel_symbol_table($1_t)

	ifndef(`enable_mls',`
		fs_exec_noxattr($1_t)

		tunable_policy(`user_rw_noexattrfile',`
			fs_manage_noxattr_fs_files($1_t)
			fs_manage_noxattr_fs_dirs($1_t)
			# Write floppies 
			storage_raw_read_removable_device($1_t)
			storage_raw_write_removable_device($1_t)
		',`
			storage_raw_read_removable_device($1_t)
		')
	')

	tunable_policy(`user_dmesg',`
		kernel_read_ring_buffer($1_t)
	',`
		kernel_dontaudit_read_ring_buffer($1_t)
	')

	# Allow users to run TCP servers (bind to ports and accept connection from
	# the same domain and outside users) disabling this forces FTP passive mode
	# and may change other protocols
	tunable_policy(`user_tcp_server',`
		corenet_tcp_bind_generic_node($1_t)
		corenet_tcp_bind_generic_port($1_t)
	')

	optional_policy(`
		netutils_run_ping_cond($1_t,$1_r)
		netutils_run_traceroute_cond($1_t,$1_r)
	')

	optional_policy(`
		postgresql_role($1_r,$1_t)
	')

	# Run pppd in pppd_t by default for user
	optional_policy(`
		ppp_run_cond($1_t,$1_r)
	')

	optional_policy(`
		setroubleshoot_stream_connect($1_t)
	')
')

#######################################
## <summary>
##	The template for creating an administrative user.
## </summary>
## <desc>
##	<p>
##	This template creates a user domain, types, and
##	rules for the user's tty, pty, home directories,
##	tmp, and tmpfs files.
##	</p>
##	<p>
##	The privileges given to administrative users are:
##	<ul>
##		<li>Raw disk access</li>
##		<li>Set all sysctls</li>
##		<li>All kernel ring buffer controls</li>
##		<li>Create, read, write, and delete all files but shadow</li>
##		<li>Manage source and binary format SELinux policy</li>
##		<li>Run insmod</li>
##	</ul>
##	</p>
## </desc>
## <param name="userdomain_prefix">
##	<summary>
##	The prefix of the user domain (e.g., sysadm
##	is the prefix for sysadm_t).
##	</summary>
## </param>
#
template(`userdom_admin_user_template',`
	gen_require(`
		attribute admindomain;
		class passwd { passwd chfn chsh rootok };
	')

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

	# Inherit rules for ordinary users.
	userdom_login_user_template($1)
	userdom_common_user_template($1)

	domain_obj_id_change_exemption($1_t)
	role system_r types $1_t;

	typeattribute $1_t admindomain;

	ifdef(`direct_sysadm_daemon',`
		domain_system_change_exemption($1_t)
	')

	##############################
	#
	# $1_t local policy
	#

	allow $1_t self:capability ~{ sys_module audit_control audit_write };
	allow $1_t self:process { setexec setfscreate };
	allow $1_t self:netlink_audit_socket nlmsg_readpriv;
	allow $1_t self:tun_socket create;
	# Set password information for other users.
	allow $1_t self:passwd { passwd chfn chsh };
	# Skip authentication when pam_rootok is specified.
	allow $1_t self:passwd rootok;

	kernel_read_software_raid_state($1_t)
	kernel_getattr_core_if($1_t)
	kernel_getattr_message_if($1_t)
	kernel_change_ring_buffer_level($1_t)
	kernel_clear_ring_buffer($1_t)
	kernel_read_ring_buffer($1_t)
	kernel_get_sysvipc_info($1_t)
	kernel_rw_all_sysctls($1_t)
	# signal unlabeled processes:
	kernel_kill_unlabeled($1_t)
	kernel_signal_unlabeled($1_t)
	kernel_sigstop_unlabeled($1_t)
	kernel_signull_unlabeled($1_t)
	kernel_sigchld_unlabeled($1_t)

	corenet_tcp_bind_generic_port($1_t)
	# allow setting up tunnels
	corenet_rw_tun_tap_dev($1_t)

	dev_getattr_generic_blk_files($1_t)
	dev_getattr_generic_chr_files($1_t)
	# for lsof
	dev_getattr_mtrr_dev($1_t)
	# Allow MAKEDEV to work
	dev_create_all_blk_files($1_t)
	dev_create_all_chr_files($1_t)
	dev_delete_all_blk_files($1_t)
	dev_delete_all_chr_files($1_t)
	dev_rename_all_blk_files($1_t)
	dev_rename_all_chr_files($1_t)
	dev_create_generic_symlinks($1_t)

	domain_setpriority_all_domains($1_t)
	domain_read_all_domains_state($1_t)
	domain_getattr_all_domains($1_t)
	domain_dontaudit_ptrace_all_domains($1_t)
	# signal all domains:
	domain_kill_all_domains($1_t)
	domain_signal_all_domains($1_t)
	domain_signull_all_domains($1_t)
	domain_sigstop_all_domains($1_t)
	domain_sigstop_all_domains($1_t)
	domain_sigchld_all_domains($1_t)
	# for lsof
	domain_getattr_all_sockets($1_t)

	files_exec_usr_src_files($1_t)

	fs_getattr_all_fs($1_t)
	fs_set_all_quotas($1_t)
	fs_exec_noxattr($1_t)

	storage_raw_read_removable_device($1_t)
	storage_raw_write_removable_device($1_t)

	term_use_all_terms($1_t)

	auth_getattr_shadow($1_t)
	# Manage almost all files
	auth_manage_all_files_except_shadow($1_t)
	# Relabel almost all files
	auth_relabel_all_files_except_shadow($1_t)

	init_telinit($1_t)

	logging_send_syslog_msg($1_t)

	modutils_domtrans_insmod($1_t)

	# The following rule is temporary until such time that a complete
	# policy management infrastructure is in place so that an administrator
	# cannot directly manipulate policy files with arbitrary programs.
	seutil_manage_src_policy($1_t)
	# Violates the goal of limiting write access to checkpolicy.
	# But presently necessary for installing the file_contexts file.
	seutil_manage_bin_policy($1_t)

	userdom_manage_user_home_content_dirs($1_t)
	userdom_manage_user_home_content_files($1_t)
	userdom_manage_user_home_content_symlinks($1_t)
	userdom_manage_user_home_content_pipes($1_t)
	userdom_manage_user_home_content_sockets($1_t)
	userdom_user_home_dir_filetrans_user_home_content($1_t, { dir file lnk_file fifo_file sock_file })

	tunable_policy(`user_rw_noexattrfile',`
		fs_manage_noxattr_fs_files($1_t)
		fs_manage_noxattr_fs_dirs($1_t)
	',`
		fs_read_noxattr_fs_files($1_t)
	')

	optional_policy(`
		postgresql_unconfined($1_t)
	')

	optional_policy(`
		userhelper_exec($1_t)
	')
')

########################################
## <summary>
##	Allow user to run as a secadm
## </summary>
## <desc>
##	<p>
##	Create objects in a user home directory
##	with an automatic type transition to
##	a specified private type.
##	</p>
##	<p>
##	This is a templated interface, and should only
##	be called from a per-userdomain template.
##	</p>
## </desc>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
## <param name="role">
##	<summary>
##	The role  of the object to create.
##	</summary>
## </param>
#
template(`userdom_security_admin_template',`
	allow $1 self:capability { dac_read_search dac_override };

	corecmd_exec_shell($1)

	domain_obj_id_change_exemption($1)

	dev_relabel_all_dev_nodes($1)

	files_create_boot_flag($1)

	# Necessary for managing /boot/efi
	fs_manage_dos_files($1)

	mls_process_read_up($1)
	mls_file_read_all_levels($1)
	mls_file_upgrade($1)
	mls_file_downgrade($1)

	selinux_set_enforce_mode($1)
	selinux_set_all_booleans($1)
	selinux_set_parameters($1)

	auth_relabel_all_files_except_shadow($1)
	auth_relabel_shadow($1)

	init_exec($1)

	logging_send_syslog_msg($1)
	logging_read_audit_log($1)
	logging_read_generic_logs($1)
	logging_read_audit_config($1)

	seutil_manage_bin_policy($1)
	seutil_run_checkpolicy($1,$2)
	seutil_run_loadpolicy($1,$2)
	seutil_run_semanage($1,$2)
	seutil_run_setfiles($1, $2)

	optional_policy(`
		aide_run($1,$2)
	')

	optional_policy(`
		consoletype_exec($1)
	')

	optional_policy(`
		dmesg_exec($1)
	')

	optional_policy(`	
		ipsec_run_setkey($1,$2)
	')

	optional_policy(`
		netlabel_run_mgmt($1,$2)
	')
')

########################################
## <summary>
##	Make the specified type usable in a
##	user home directory.
## </summary>
## <param name="type">
##	<summary>
##	Type to be used as a file in the
##	user home directory.
##	</summary>
## </param>
#
interface(`userdom_user_home_content',`
	gen_require(`
		type user_home_t;
	')

	allow $1 user_home_t:filesystem associate;
	files_type($1)
	ubac_constrained($1)
')

########################################
## <summary>
##	Allow domain to attach to TUN devices created by administrative users.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_attach_admin_tun_iface',`
	gen_require(`
		attribute admindomain;
	')

	allow $1 admindomain:tun_socket relabelfrom;
	allow $1 self:tun_socket relabelto;
')

########################################
## <summary>
##	Set the attributes of a user pty.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_setattr_user_ptys',`
	gen_require(`
		type user_devpts_t;
	')

	allow $1 user_devpts_t:chr_file setattr;
')

########################################
## <summary>
##	Create a user pty.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_create_user_pty',`
	gen_require(`
		type user_devpts_t;
	')

	term_create_pty($1, user_devpts_t)
')

########################################
## <summary>
##	Get the attributes of user home directories.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_getattr_user_home_dirs',`
	gen_require(`
		type user_home_dir_t;
	')

	allow $1 user_home_dir_t:dir getattr_dir_perms;
	files_search_home($1)
')

########################################
## <summary>
##	Do not audit attempts to get the attributes of user home directories.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_dontaudit_getattr_user_home_dirs',`
	gen_require(`
		type user_home_dir_t;
	')

	dontaudit $1 user_home_dir_t:dir getattr_dir_perms;
')

########################################
## <summary>
##	Search user home directories.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_search_user_home_dirs',`
	gen_require(`
		type user_home_dir_t;
	')

	allow $1 user_home_dir_t:dir search_dir_perms;
	files_search_home($1)
')

########################################
## <summary>
##	Search user home directories.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_dontaudit_search_user_home_dirs',`
	gen_require(`
		type user_home_dir_t;
	')

	dontaudit $1 user_home_dir_t:dir search_dir_perms;
')

########################################
## <summary>
##	List user home directories.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_list_user_home_dirs',`
	gen_require(`
		type user_home_dir_t;
	')

	allow $1 user_home_dir_t:dir list_dir_perms;
	files_search_home($1)
')

########################################
## <summary>
##	Do not audit attempts to list user home subdirectories.
## </summary>
## <param name="domain">
##	<summary>
##	Domain to not audit
##	</summary>
## </param>
#
interface(`userdom_dontaudit_list_user_home_dirs',`
	gen_require(`
		type user_home_dir_t;
	')

	dontaudit $1 user_home_dir_t:dir list_dir_perms;
')

########################################
## <summary>
##	Create user home directories.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_create_user_home_dirs',`
	gen_require(`
		type user_home_dir_t;
	')

	allow $1 user_home_dir_t:dir create_dir_perms;
')

########################################
## <summary>
##	Create user home directories.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_manage_user_home_dirs',`
	gen_require(`
		type user_home_dir_t;
	')

	allow $1 user_home_dir_t:dir manage_dir_perms;
')

########################################
## <summary>
##	Relabel to user home directories.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_relabelto_user_home_dirs',`
	gen_require(`
		type user_home_dir_t;
	')

	allow $1 user_home_dir_t:dir relabelto;
')

########################################
## <summary>
##	Create directories in the home dir root with
##	the user home directory type.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_home_filetrans_user_home_dir',`
	gen_require(`
		type user_home_dir_t;
	')

	files_home_filetrans($1, user_home_dir_t, dir)
')

########################################
## <summary>
##	Do a domain transition to the specified
##	domain when executing a program in the
##	user home directory.
## </summary>
## <desc>
##	<p>
##	Do a domain transition to the specified
##	domain when executing a program in the
##	user home directory.
##	</p>
##	<p>
##	No interprocess communication (signals, pipes,
##	etc.) is provided by this interface since
##	the domains are not owned by this module.
##	</p>
## </desc>
## <param name="source_domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
## <param name="target_domain">
##	<summary>
##	Domain to transition to.
##	</summary>
## </param>
#
interface(`userdom_user_home_domtrans',`
	gen_require(`
		type user_home_dir_t, user_home_t;
	')

	domain_auto_trans($1, user_home_t, $2)
	allow $1 user_home_dir_t:dir search_dir_perms;
	files_search_home($1)
')

########################################
## <summary>
##	Do not audit attempts to search user home content directories.
## </summary>
## <param name="domain">
##	<summary>
##	Domain to not audit
##	</summary>
## </param>
#
interface(`userdom_dontaudit_search_user_home_content',`
	gen_require(`
		type user_home_t;
	')

	dontaudit $1 user_home_t:dir search_dir_perms;
')

########################################
## <summary>
##	Create, read, write, and delete directories
##	in a user home subdirectory.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_manage_user_home_content_dirs',`
	gen_require(`
		type user_home_dir_t, user_home_t;
	')

	manage_dirs_pattern($1, { user_home_dir_t user_home_t }, user_home_t)
	files_search_home($1)
')

########################################
## <summary>
##	Delete directories in a user home subdirectory.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_delete_user_home_content_dirs',`
	gen_require(`
		type user_home_t;
	')

	allow $1 user_home_t:dir delete_dir_perms;
')

########################################
## <summary>
##	Do not audit attempts to set the
##	attributes of user home files.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_dontaudit_setattr_user_home_content_files',`
	gen_require(`
		type user_home_t;
	')

	dontaudit $1 user_home_t:file setattr;
')

########################################
## <summary>
##	Mmap user home files.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_mmap_user_home_content_files',`
	gen_require(`
		type user_home_dir_t, user_home_t;
	')

	mmap_files_pattern($1, { user_home_dir_t user_home_t }, user_home_t)
	files_search_home($1)
')

########################################
## <summary>
##	Read user home files.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_read_user_home_content_files',`
	gen_require(`
		type user_home_dir_t, user_home_t;
	')

	read_files_pattern($1, { user_home_dir_t user_home_t }, user_home_t)
	files_search_home($1)
')

########################################
## <summary>
##	Do not audit attempts to read user home files.
## </summary>
## <param name="domain">
##	<summary>
##	Domain to not audit.
##	</summary>
## </param>
#
interface(`userdom_dontaudit_read_user_home_content_files',`
	gen_require(`
		type user_home_t;
	')

	dontaudit $1 user_home_t:dir list_dir_perms;
	dontaudit $1 user_home_t:file read_file_perms;
')

########################################
## <summary>
##	Do not audit attempts to append user home files.
## </summary>
## <param name="domain">
##	<summary>
##	Domain to not audit.
##	</summary>
## </param>
#
interface(`userdom_dontaudit_append_user_home_content_files',`
	gen_require(`
		type user_home_t;
	')

	dontaudit $1 user_home_t:file append;
')

########################################
## <summary>
##	Do not audit attempts to write user home files.
## </summary>
## <param name="domain">
##	<summary>
##	Domain to not audit.
##	</summary>
## </param>
#
interface(`userdom_dontaudit_write_user_home_content_files',`
	gen_require(`
		type user_home_t;
	')

	dontaudit $1 user_home_t:file write;
')

########################################
## <summary>
##	Delete files in a user home subdirectory.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_delete_user_home_content_files',`
	gen_require(`
		type user_home_t;
	')

	allow $1 user_home_t:file delete_file_perms;
')

########################################
## <summary>
##	Do not audit attempts to write user home files.
## </summary>
## <param name="domain">
##	<summary>
##	Domain to not audit.
##	</summary>
## </param>
#
interface(`userdom_dontaudit_relabel_user_home_content_files',`
	gen_require(`
		type user_home_t;
	')

	dontaudit $1 user_home_t:file relabel_file_perms;
')

########################################
## <summary>
##	Read user home subdirectory symbolic links.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_read_user_home_content_symlinks',`
	gen_require(`
		type user_home_dir_t, user_home_t;
	')

	read_lnk_files_pattern($1, { user_home_dir_t user_home_t }, user_home_t)
	files_search_home($1)
')

########################################
## <summary>
##	Execute user home files.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
## <rolecap/>
#
interface(`userdom_exec_user_home_content_files',`
	gen_require(`
		type user_home_dir_t, user_home_t;
	')

	files_search_home($1)
	exec_files_pattern($1, { user_home_dir_t user_home_t }, user_home_t)

	tunable_policy(`use_nfs_home_dirs',`
		fs_exec_nfs_files($1)
	')

	tunable_policy(`use_samba_home_dirs',`
		fs_exec_cifs_files($1)
	')
')

########################################
## <summary>
##	Do not audit attempts to execute user home files.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_dontaudit_exec_user_home_content_files',`
	gen_require(`
		type user_home_t;
	')

	dontaudit $1 user_home_t:file execute;
')

########################################
## <summary>
##	Create, read, write, and delete files
##	in a user home subdirectory.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_manage_user_home_content_files',`
	gen_require(`
		type user_home_dir_t, user_home_t;
	')

	manage_files_pattern($1, user_home_t, user_home_t)
	allow $1 user_home_dir_t:dir search_dir_perms;
	files_search_home($1)
')

########################################
## <summary>
##	Do not audit attempts to create, read, write, and delete directories
##	in a user home subdirectory.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_dontaudit_manage_user_home_content_dirs',`
	gen_require(`
		type user_home_dir_t, user_home_t;
	')

	dontaudit $1 user_home_t:dir manage_dir_perms;
')

########################################
## <summary>
##	Create, read, write, and delete symbolic links
##	in a user home subdirectory.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_manage_user_home_content_symlinks',`
	gen_require(`
		type user_home_dir_t, user_home_t;
	')

	manage_lnk_files_pattern($1, user_home_t, user_home_t)
	allow $1 user_home_dir_t:dir search_dir_perms;
	files_search_home($1)
')

########################################
## <summary>
##	Delete symbolic links in a user home directory.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_delete_user_home_content_symlinks',`
	gen_require(`
		type user_home_t;
	')

	allow $1 user_home_t:lnk_file delete_lnk_file_perms;
')

########################################
## <summary>
##	Create, read, write, and delete named pipes
##	in a user home subdirectory.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_manage_user_home_content_pipes',`
	gen_require(`
		type user_home_dir_t, user_home_t;
	')

	manage_fifo_files_pattern($1, user_home_t, user_home_t)
	allow $1 user_home_dir_t:dir search_dir_perms;
	files_search_home($1)
')

########################################
## <summary>
##	Create, read, write, and delete named sockets
##	in a user home subdirectory.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_manage_user_home_content_sockets',`
	gen_require(`
		type user_home_dir_t, user_home_t;
	')

	allow $1 user_home_dir_t:dir search_dir_perms;
	manage_sock_files_pattern($1, user_home_t, user_home_t)
	files_search_home($1)
')

########################################
## <summary>
##	Create objects in a user home directory
##	with an automatic type transition to
##	a specified private type.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
## <param name="private_type">
##	<summary>
##	The type of the object to create.
##	</summary>
## </param>
## <param name="object_class">
##	<summary>
##	The class of the object to be created.
##	</summary>
## </param>
#
interface(`userdom_user_home_dir_filetrans',`
	gen_require(`
		type user_home_dir_t;
	')

	filetrans_pattern($1, user_home_dir_t, $2, $3)
	files_search_home($1)
')

########################################
## <summary>
##	Create objects in a user home directory
##	with an automatic type transition to
##	a specified private type.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
## <param name="private_type">
##	<summary>
##	The type of the object to create.
##	</summary>
## </param>
## <param name="object_class">
##	<summary>
##	The class of the object to be created.
##	</summary>
## </param>
#
interface(`userdom_user_home_content_filetrans',`
	gen_require(`
		type user_home_dir_t, user_home_t;
	')

	filetrans_pattern($1, user_home_t, $2, $3)
	allow $1 user_home_dir_t:dir search_dir_perms;
	files_search_home($1)
')

########################################
## <summary>
##	Create objects in a user home directory
##	with an automatic type transition to
##	the user home file type.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
## <param name="object_class">
##	<summary>
##	The class of the object to be created.
##	</summary>
## </param>
#
interface(`userdom_user_home_dir_filetrans_user_home_content',`
	gen_require(`
		type user_home_dir_t, user_home_t;
	')

	filetrans_pattern($1, user_home_dir_t, user_home_t, $2)
	files_search_home($1)
')

########################################
## <summary>
##	Write to user temporary named sockets.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_write_user_tmp_sockets',`
	gen_require(`
		type user_tmp_t;
	')

	allow $1 user_tmp_t:sock_file write;
	files_search_tmp($1)
')

########################################
## <summary>
##	List user temporary directories.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_list_user_tmp',`
	gen_require(`
		type user_tmp_t;
	')

	allow $1 user_tmp_t:dir list_dir_perms;
	files_search_tmp($1)
')

########################################
## <summary>
##	Do not audit attempts to list user
##	temporary directories.
## </summary>
## <param name="domain">
##	<summary>
##	Domain to not audit.
##	</summary>
## </param>
#
interface(`userdom_dontaudit_list_user_tmp',`
	gen_require(`
		type user_tmp_t;
	')

	dontaudit $1 user_tmp_t:dir list_dir_perms;
')

########################################
## <summary>
##	Do not audit attempts to manage users
##	temporary directories.
## </summary>
## <param name="domain">
##	<summary>
##	Domain to not audit.
##	</summary>
## </param>
#
interface(`userdom_dontaudit_manage_user_tmp_dirs',`
	gen_require(`
		type user_tmp_t;
	')

	dontaudit $1 user_tmp_t:dir manage_dir_perms;
')

########################################
## <summary>
##	Read user temporary files.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_read_user_tmp_files',`
	gen_require(`
		type user_tmp_t;
	')

	read_files_pattern($1, user_tmp_t, user_tmp_t)
	allow $1 user_tmp_t:dir list_dir_perms;
	files_search_tmp($1)
')

########################################
## <summary>
##	Do not audit attempts to read users
##	temporary files.
## </summary>
## <param name="domain">
##	<summary>
##	Domain to not audit.
##	</summary>
## </param>
#
interface(`userdom_dontaudit_read_user_tmp_files',`
	gen_require(`
		type user_tmp_t;
	')

	dontaudit $1 user_tmp_t:file read_file_perms;
')

########################################
## <summary>
##	Do not audit attempts to append users
##	temporary files.
## </summary>
## <param name="domain">
##	<summary>
##	Domain to not audit.
##	</summary>
## </param>
#
interface(`userdom_dontaudit_append_user_tmp_files',`
	gen_require(`
		type user_tmp_t;
	')

	dontaudit $1 user_tmp_t:file append;
')

########################################
## <summary>
##	Read and write user temporary files.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_rw_user_tmp_files',`
	gen_require(`
		type user_tmp_t;
	')

	allow $1 user_tmp_t:dir list_dir_perms;
	rw_files_pattern($1, user_tmp_t, user_tmp_t)
	files_search_tmp($1)
')

########################################
## <summary>
##	Do not audit attempts to manage users
##	temporary files.
## </summary>
## <param name="domain">
##	<summary>
##	Domain to not audit.
##	</summary>
## </param>
#
interface(`userdom_dontaudit_manage_user_tmp_files',`
	gen_require(`
		type user_tmp_t;
	')

	dontaudit $1 user_tmp_t:file manage_file_perms;
')

########################################
## <summary>
##	Read user temporary symbolic links.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_read_user_tmp_symlinks',`
	gen_require(`
		type user_tmp_t;
	')

	read_lnk_files_pattern($1, user_tmp_t, user_tmp_t)
	allow $1 user_tmp_t:dir list_dir_perms;
	files_search_tmp($1)
')

########################################
## <summary>
##	Create, read, write, and delete user
##	temporary directories.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_manage_user_tmp_dirs',`
	gen_require(`
		type user_tmp_t;
	')

	manage_dirs_pattern($1, user_tmp_t, user_tmp_t)
	files_search_tmp($1)
')

########################################
## <summary>
##	Create, read, write, and delete user
##	temporary files.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_manage_user_tmp_files',`
	gen_require(`
		type user_tmp_t;
	')

	manage_files_pattern($1, user_tmp_t, user_tmp_t)
	files_search_tmp($1)
')

########################################
## <summary>
##	Create, read, write, and delete user
##	temporary symbolic links.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_manage_user_tmp_symlinks',`
	gen_require(`
		type user_tmp_t;
	')

	manage_lnk_files_pattern($1, user_tmp_t, user_tmp_t)
	files_search_tmp($1)
')

########################################
## <summary>
##	Create, read, write, and delete user
##	temporary named pipes.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_manage_user_tmp_pipes',`
	gen_require(`
		type user_tmp_t;
	')

	manage_fifo_files_pattern($1, user_tmp_t, user_tmp_t)
	files_search_tmp($1)
')

########################################
## <summary>
##	Create, read, write, and delete user
##	temporary named sockets.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_manage_user_tmp_sockets',`
	gen_require(`
		type user_tmp_t;
	')

	manage_sock_files_pattern($1, user_tmp_t, user_tmp_t)
	files_search_tmp($1)
')

########################################
## <summary>
##	Create objects in a user temporary directory
##	with an automatic type transition to
##	a specified private type.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
## <param name="private_type">
##	<summary>
##	The type of the object to create.
##	</summary>
## </param>
## <param name="object_class">
##	<summary>
##	The class of the object to be created.
##	</summary>
## </param>
#
interface(`userdom_user_tmp_filetrans',`
	gen_require(`
		type user_tmp_t;
	')

	filetrans_pattern($1, user_tmp_t, $2, $3)
	files_search_tmp($1)
')

########################################
## <summary>
##	Create objects in the temporary directory
##	with an automatic type transition to
##	the user temporary type.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
## <param name="object_class">
##	<summary>
##	The class of the object to be created.
##	</summary>
## </param>
#
interface(`userdom_tmp_filetrans_user_tmp',`
	gen_require(`
		type user_tmp_t;
	')

	files_tmp_filetrans($1, user_tmp_t, $2)
')

########################################
## <summary>
##	Read user tmpfs files.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_read_user_tmpfs_files',`
	gen_require(`
		type user_tmpfs_t;
	')

	read_files_pattern($1, user_tmpfs_t, user_tmpfs_t)
	allow $1 user_tmpfs_t:dir list_dir_perms;
	fs_search_tmpfs($1)
')

########################################
## <summary>
##	Read user tmpfs files.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_rw_user_tmpfs_files',`
	gen_require(`
		type user_tmpfs_t;
	')

	rw_files_pattern($1, user_tmpfs_t, user_tmpfs_t)
	read_lnk_files_pattern($1, user_tmpfs_t, user_tmpfs_t)
	allow $1 user_tmpfs_t:dir list_dir_perms;
	fs_search_tmpfs($1)
')

########################################
## <summary>
##	Get the attributes of a user domain tty.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_getattr_user_ttys',`
	gen_require(`
		type user_tty_device_t;
	')

	allow $1 user_tty_device_t:chr_file getattr;
')

########################################
## <summary>
##	Do not audit attempts to get the attributes of a user domain tty.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_dontaudit_getattr_user_ttys',`
	gen_require(`
		type user_tty_device_t;
	')

	dontaudit $1 user_tty_device_t:chr_file getattr;
')

########################################
## <summary>
##	Set the attributes of a user domain tty.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_setattr_user_ttys',`
	gen_require(`
		type user_tty_device_t;
	')

	allow $1 user_tty_device_t:chr_file setattr;
')

########################################
## <summary>
##	Do not audit attempts to set the attributes of a user domain tty.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_dontaudit_setattr_user_ttys',`
	gen_require(`
		type user_tty_device_t;
	')

	dontaudit $1 user_tty_device_t:chr_file setattr;
')

########################################
## <summary>
##	Read and write a user domain tty.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_use_user_ttys',`
	gen_require(`
		type user_tty_device_t;
	')

	allow $1 user_tty_device_t:chr_file rw_term_perms;
')

########################################
## <summary>
##	Read and write a user domain pty.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_use_user_ptys',`
	gen_require(`
		type user_devpts_t;
	')

	allow $1 user_devpts_t:chr_file rw_term_perms;
')

########################################
## <summary>
##	Read and write a user domain tty and pty.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_use_user_terminals',`
	gen_require(`
		type user_tty_device_t, user_devpts_t;
	')

	allow $1 user_tty_device_t:chr_file rw_term_perms;
	allow $1 user_devpts_t:chr_file rw_term_perms;
	term_list_ptys($1)
')

########################################
## <summary>
##	Do not audit attempts to read and write
##	a user domain tty and pty.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_dontaudit_use_user_terminals',`
	gen_require(`
		type user_tty_device_t, user_devpts_t;
	')

	dontaudit $1 user_tty_device_t:chr_file rw_term_perms;
	dontaudit $1 user_devpts_t:chr_file rw_term_perms;
')

########################################
## <summary>
##	Execute a shell in all user domains.  This
##	is an explicit transition, requiring the
##	caller to use setexeccon().
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_spec_domtrans_all_users',`
	gen_require(`
		attribute userdomain;
	')

	corecmd_shell_spec_domtrans($1, userdomain)
	allow userdomain $1:fd use;
	allow userdomain $1:fifo_file rw_file_perms;
	allow userdomain $1:process sigchld;
')

########################################
## <summary>
##	Execute an Xserver session in all unprivileged user domains.  This
##	is an explicit transition, requiring the
##	caller to use setexeccon().
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_xsession_spec_domtrans_all_users',`
	gen_require(`
		attribute userdomain;
	')

	xserver_xsession_spec_domtrans($1, userdomain)
	allow userdomain $1:fd use;
	allow userdomain $1:fifo_file rw_file_perms;
	allow userdomain $1:process sigchld;
')

########################################
## <summary>
##	Execute a shell in all unprivileged user domains.  This
##	is an explicit transition, requiring the
##	caller to use setexeccon().
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_spec_domtrans_unpriv_users',`
	gen_require(`
		attribute unpriv_userdomain;
	')

	corecmd_shell_spec_domtrans($1, unpriv_userdomain)
	allow unpriv_userdomain $1:fd use;
	allow unpriv_userdomain $1:fifo_file rw_file_perms;
	allow unpriv_userdomain $1:process sigchld;
')

########################################
## <summary>
##	Execute an Xserver session in all unprivileged user domains.  This
##	is an explicit transition, requiring the
##	caller to use setexeccon().
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_xsession_spec_domtrans_unpriv_users',`
	gen_require(`
		attribute unpriv_userdomain;
	')

	xserver_xsession_spec_domtrans($1, unpriv_userdomain)
	allow unpriv_userdomain $1:fd use;
	allow unpriv_userdomain $1:fifo_file rw_file_perms;
	allow unpriv_userdomain $1:process sigchld;
')

########################################
## <summary>
##	Manage unpriviledged user SysV sempaphores.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_manage_unpriv_user_semaphores',`
	gen_require(`
		attribute unpriv_userdomain;
	')

	allow $1 unpriv_userdomain:sem create_sem_perms;
')

########################################
## <summary>
##	Manage unpriviledged user SysV shared
##	memory segments.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_manage_unpriv_user_shared_mem',`
	gen_require(`
		attribute unpriv_userdomain;
	')

	allow $1 unpriv_userdomain:shm create_shm_perms;
')

########################################
## <summary>
##	Execute bin_t in the unprivileged user domains. This
##	is an explicit transition, requiring the
##	caller to use setexeccon().
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_bin_spec_domtrans_unpriv_users',`
	gen_require(`
		attribute unpriv_userdomain;
	')

	corecmd_bin_spec_domtrans($1, unpriv_userdomain)
	allow unpriv_userdomain $1:fd use;
	allow unpriv_userdomain $1:fifo_file rw_file_perms;
	allow unpriv_userdomain $1:process sigchld;
')

########################################
## <summary>
##	Execute all entrypoint files in unprivileged user
##	domains. This is an explicit transition, requiring the
##	caller to use setexeccon().
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_entry_spec_domtrans_unpriv_users',`
	gen_require(`
		attribute unpriv_userdomain;
	')

	domain_entry_file_spec_domtrans($1, unpriv_userdomain)
	allow unpriv_userdomain $1:fd use;
	allow unpriv_userdomain $1:fifo_file rw_file_perms;
	allow unpriv_userdomain $1:process sigchld;
')

########################################
## <summary>
##	Search users home directories.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_search_user_home_content',`
	gen_require(`
		type user_home_dir_t, user_home_t;
	')

	files_list_home($1)
	allow $1 { user_home_dir_t user_home_t }:dir search_dir_perms;
')

########################################
## <summary>
##	Send general signals to unprivileged user domains.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_signal_unpriv_users',`
	gen_require(`
		attribute unpriv_userdomain;
	')

	allow $1 unpriv_userdomain:process signal;
')

########################################
## <summary>
##	Inherit the file descriptors from unprivileged user domains.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_use_unpriv_users_fds',`
	gen_require(`
		attribute unpriv_userdomain;
	')

	allow $1 unpriv_userdomain:fd use;
')

########################################
## <summary>
##	Do not audit attempts to inherit the
##	file descriptors from all user domains.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_dontaudit_use_unpriv_user_fds',`
	gen_require(`
		attribute unpriv_userdomain;
	')

	dontaudit $1 unpriv_userdomain:fd use;
')

########################################
## <summary>
##	Do not audit attempts to use user ptys.
## </summary>
## <param name="domain">
##	<summary>
##	Domain to not audit.
##	</summary>
## </param>
#
interface(`userdom_dontaudit_use_user_ptys',`
	gen_require(`
		type user_devpts_t;
	')

	dontaudit $1 user_devpts_t:chr_file rw_file_perms;
')

########################################
## <summary>
##	Relabel files to unprivileged user pty types.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_relabelto_user_ptys',`
	gen_require(`
		type user_devpts_t;
	')

	allow $1 user_devpts_t:chr_file relabelto;
')

########################################
## <summary>
##	Do not audit attempts to relabel files from
##	user pty types.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_dontaudit_relabelfrom_user_ptys',`
	gen_require(`
		type user_devpts_t;
	')

	dontaudit $1 user_devpts_t:chr_file relabelfrom;
')

########################################
## <summary>
##	Write all users files in /tmp
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_write_user_tmp_files',`
	gen_require(`
		type user_tmp_t;
	')

	allow $1 user_tmp_t:file write_file_perms;
')

########################################
## <summary>
##	Do not audit attempts to use user ttys.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_dontaudit_use_user_ttys',`
	gen_require(`
		type user_tty_device_t;
	')

	dontaudit $1 user_tty_device_t:chr_file rw_file_perms;
')

########################################
## <summary>
##	Read the process state of all user domains.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_read_all_users_state',`
	gen_require(`
		attribute userdomain;
	')

	read_files_pattern($1, userdomain, userdomain)
	kernel_search_proc($1)
')

########################################
## <summary>
##	Get the attributes of all user domains.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_getattr_all_users',`
	gen_require(`
		attribute userdomain;
	')

	allow $1 userdomain:process getattr;
')

########################################
## <summary>
##	Inherit the file descriptors from all user domains
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_use_all_users_fds',`
	gen_require(`
		attribute userdomain;
	')

	allow $1 userdomain:fd use;
')

########################################
## <summary>
##	Do not audit attempts to inherit the file
##	descriptors from any user domains.
## </summary>
## <param name="domain">
##	<summary>
##	Domain to not audit.
##	</summary>
## </param>
#
interface(`userdom_dontaudit_use_all_users_fds',`
	gen_require(`
		attribute userdomain;
	')

	dontaudit $1 userdomain:fd use;
')

########################################
## <summary>
##	Send general signals to all user domains.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_signal_all_users',`
	gen_require(`
		attribute userdomain;
	')

	allow $1 userdomain:process signal;
')

########################################
## <summary>
##	Send a SIGCHLD signal to all user domains.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_sigchld_all_users',`
	gen_require(`
		attribute userdomain;
	')

	allow $1 userdomain:process sigchld;
')

########################################
## <summary>
##	Create keys for all user domains.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_create_all_users_keys',`
	gen_require(`
		attribute userdomain;
	')

	allow $1 userdomain:key create;
')

########################################
## <summary>
##	Send a dbus message to all user domains.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`userdom_dbus_send_all_users',`
	gen_require(`
		attribute userdomain;
		class dbus send_msg;
	')

	allow $1 userdomain:dbus send_msg;
')