summaryrefslogtreecommitdiff
path: root/usr/src/uts/common/os/policy.c
blob: d2bdb4ce377fed7cf60854b897e9f79ca8fc5b72 (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
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
 * Copyright 2015 Joyent, Inc.
 */

#include <sys/types.h>
#include <sys/sysmacros.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/cred_impl.h>
#include <sys/vnode.h>
#include <sys/vfs.h>
#include <sys/stat.h>
#include <sys/errno.h>
#include <sys/kmem.h>
#include <sys/user.h>
#include <sys/proc.h>
#include <sys/acct.h>
#include <sys/ipc_impl.h>
#include <sys/cmn_err.h>
#include <sys/debug.h>
#include <sys/policy.h>
#include <sys/kobj.h>
#include <sys/msg.h>
#include <sys/devpolicy.h>
#include <c2/audit.h>
#include <sys/varargs.h>
#include <sys/klpd.h>
#include <sys/modctl.h>
#include <sys/disp.h>
#include <sys/zone.h>
#include <inet/optcom.h>
#include <sys/sdt.h>
#include <sys/vfs.h>
#include <sys/mntent.h>
#include <sys/contract_impl.h>
#include <sys/dld_ioc.h>
#include <sys/brand.h>

/*
 * There are two possible layers of privilege routines and two possible
 * levels of secpolicy.  Plus one other we may not be interested in, so
 * we may need as many as 6 but no more.
 */
#define	MAXPRIVSTACK		6

int priv_debug = 0;
int priv_basic_test = -1;

/*
 * This file contains the majority of the policy routines.
 * Since the policy routines are defined by function and not
 * by privilege, there is quite a bit of duplication of
 * functions.
 *
 * The secpolicy functions must not make assumptions about
 * locks held or not held as any lock can be held while they're
 * being called.
 *
 * Credentials are read-only so no special precautions need to
 * be taken while locking them.
 *
 * When a new policy check needs to be added to the system the
 * following procedure should be followed:
 *
 *		Pick an appropriate secpolicy_*() function
 *			-> done if one exists.
 *		Create a new secpolicy function, preferably with
 *		a descriptive name using the standard template.
 *		Pick an appropriate privilege for the policy.
 *		If no appropraite privilege exists, define new one
 *		(this should be done with extreme care; in most cases
 *		little is gained by adding another privilege)
 *
 * WHY ROOT IS STILL SPECIAL.
 *
 * In a number of the policy functions, there are still explicit
 * checks for uid 0.  The rationale behind these is that many root
 * owned files/objects hold configuration information which can give full
 * privileges to the user once written to.  To prevent escalation
 * of privilege by allowing just a single privilege to modify root owned
 * objects, we've added these root specific checks where we considered
 * them necessary: modifying root owned files, changing uids to 0, etc.
 *
 * PRIVILEGE ESCALATION AND ZONES.
 *
 * A number of operations potentially allow the caller to achieve
 * privileges beyond the ones normally required to perform the operation.
 * For example, if allowed to create a setuid 0 executable, a process can
 * gain privileges beyond PRIV_FILE_SETID.  Zones, however, place
 * restrictions on the ability to gain privileges beyond those available
 * within the zone through file and process manipulation.  Hence, such
 * operations require that the caller have an effective set that includes
 * all privileges available within the current zone, or all privileges
 * if executing in the global zone.
 *
 * This is indicated in the priv_policy* policy checking functions
 * through a combination of parameters.  The "priv" parameter indicates
 * the privilege that is required, and the "allzone" parameter indicates
 * whether or not all privileges in the zone are required.  In addition,
 * priv can be set to PRIV_ALL to indicate that all privileges are
 * required (regardless of zone).  There are three scenarios of interest:
 * (1) operation requires a specific privilege
 * (2) operation requires a specific privilege, and requires all
 *     privileges available within the zone (or all privileges if in
 *     the global zone)
 * (3) operation requires all privileges, regardless of zone
 *
 * For (1), priv should be set to the specific privilege, and allzone
 * should be set to B_FALSE.
 * For (2), priv should be set to the specific privilege, and allzone
 * should be set to B_TRUE.
 * For (3), priv should be set to PRIV_ALL, and allzone should be set
 * to B_FALSE.
 *
 */

/*
 * The privileges are checked against the Effective set for
 * ordinary processes and checked against the Limit set
 * for euid 0 processes that haven't manipulated their privilege
 * sets.
 */
#define	HAS_ALLPRIVS(cr)	priv_isfullset(&CR_OEPRIV(cr))
#define	ZONEPRIVS(cr)		((cr)->cr_zone->zone_privset)
#define	HAS_ALLZONEPRIVS(cr)	priv_issubset(ZONEPRIVS(cr), &CR_OEPRIV(cr))
#define	HAS_PRIVILEGE(cr, pr)	((pr) == PRIV_ALL ? \
					HAS_ALLPRIVS(cr) : \
					PRIV_ISASSERT(&CR_OEPRIV(cr), pr))

#define	FAST_BASIC_CHECK(cr, priv)	\
	if (PRIV_ISASSERT(&CR_OEPRIV(cr), priv)) { \
		DTRACE_PROBE2(priv__ok, int, priv, boolean_t, B_FALSE); \
		return (0); \
	}

/*
 * Policy checking functions.
 *
 * All of the system's policy should be implemented here.
 */

/*
 * Private functions which take an additional va_list argument to
 * implement an object specific policy override.
 */
static int priv_policy_ap(const cred_t *, int, boolean_t, int,
    const char *, va_list);
static int priv_policy_va(const cred_t *, int, boolean_t, int,
    const char *, ...);

/*
 * Generic policy calls
 *
 * The "bottom" functions of policy control
 */
static char *
mprintf(const char *fmt, ...)
{
	va_list args;
	char *buf;
	size_t len;

	va_start(args, fmt);
	len = vsnprintf(NULL, 0, fmt, args) + 1;
	va_end(args);

	buf = kmem_alloc(len, KM_NOSLEEP);

	if (buf == NULL)
		return (NULL);

	va_start(args, fmt);
	(void) vsnprintf(buf, len, fmt, args);
	va_end(args);

	return (buf);
}

/*
 * priv_policy_errmsg()
 *
 * Generate an error message if privilege debugging is enabled system wide
 * or for this particular process.
 */

#define	FMTHDR	"%s[%d]: missing privilege \"%s\" (euid = %d, syscall = %d)"
#define	FMTMSG	" for \"%s\""
#define	FMTFUN	" needed at %s+0x%lx"

/* The maximum size privilege format: the concatenation of the above */
#define	FMTMAX	FMTHDR FMTMSG FMTFUN "\n"

static void
priv_policy_errmsg(const cred_t *cr, int priv, const char *msg)
{
	struct proc *me;
	pc_t stack[MAXPRIVSTACK];
	int depth;
	int i;
	char *sym;
	ulong_t off;
	const char *pname;

	char *cmd;
	char fmt[sizeof (FMTMAX)];

	if ((me = curproc) == &p0)
		return;

	/* Privileges must be defined  */
	ASSERT(priv == PRIV_ALL || priv == PRIV_MULTIPLE ||
	    priv == PRIV_ALLZONE || priv == PRIV_GLOBAL ||
	    priv_getbynum(priv) != NULL);

	if (priv == PRIV_ALLZONE && INGLOBALZONE(me))
		priv = PRIV_ALL;

	if (curthread->t_pre_sys)
		ttolwp(curthread)->lwp_badpriv = (short)priv;

	if (priv_debug == 0 && (CR_FLAGS(cr) & PRIV_DEBUG) == 0)
		return;

	(void) strcpy(fmt, FMTHDR);

	if (me->p_user.u_comm[0])
		cmd = &me->p_user.u_comm[0];
	else
		cmd = "priv_policy";

	if (msg != NULL && *msg != '\0') {
		(void) strcat(fmt, FMTMSG);
	} else {
		(void) strcat(fmt, "%s");
		msg = "";
	}

	sym = NULL;

	depth = getpcstack(stack, MAXPRIVSTACK);

	/*
	 * Try to find the first interesting function on the stack.
	 * priv_policy* that's us, so completely uninteresting.
	 * suser(), drv_priv(), secpolicy_* are also called from
	 * too many locations to convey useful information.
	 */
	for (i = 0; i < depth; i++) {
		sym = kobj_getsymname((uintptr_t)stack[i], &off);
		if (sym != NULL &&
		    strstr(sym, "hasprocperm") == 0 &&
		    strcmp("suser", sym) != 0 &&
		    strcmp("ipcaccess", sym) != 0 &&
		    strcmp("drv_priv", sym) != 0 &&
		    strncmp("secpolicy_", sym, 10) != 0 &&
		    strncmp("priv_policy", sym, 11) != 0)
			break;
	}

	if (sym != NULL)
		(void) strcat(fmt, FMTFUN);

	(void) strcat(fmt, "\n");

	switch (priv) {
	case PRIV_ALL:
		pname = "ALL";
		break;
	case PRIV_MULTIPLE:
		pname = "MULTIPLE";
		break;
	case PRIV_ALLZONE:
		pname = "ZONE";
		break;
	case PRIV_GLOBAL:
		pname = "GLOBAL";
		break;
	default:
		pname = priv_getbynum(priv);
		break;
	}

	if (CR_FLAGS(cr) & PRIV_DEBUG) {
		/* Remember last message, just like lwp_badpriv. */
		if (curthread->t_pdmsg != NULL) {
			kmem_free(curthread->t_pdmsg,
			    strlen(curthread->t_pdmsg) + 1);
		}

		curthread->t_pdmsg = mprintf(fmt, cmd, me->p_pid, pname,
		    cr->cr_uid, curthread->t_sysnum, msg, sym, off);

		curthread->t_post_sys = 1;
	}
	if (priv_debug) {
		cmn_err(CE_NOTE, fmt, cmd, me->p_pid, pname, cr->cr_uid,
		    curthread->t_sysnum, msg, sym, off);
	}
}

/*
 * Override the policy, if appropriate.  Return 0 if the external
 * policy engine approves.
 */
static int
priv_policy_override(const cred_t *cr, int priv, boolean_t allzone, va_list ap)
{
	priv_set_t set;
	int ret;

	if (!(CR_FLAGS(cr) & PRIV_XPOLICY))
		return (-1);

	if (priv == PRIV_ALL) {
		priv_fillset(&set);
	} else if (allzone) {
		set = *ZONEPRIVS(cr);
	} else {
		priv_emptyset(&set);
		priv_addset(&set, priv);
	}
	ret = klpd_call(cr, &set, ap);
	return (ret);
}

static int
priv_policy_override_set(const cred_t *cr, const priv_set_t *req, va_list ap)
{
	if (CR_FLAGS(cr) & PRIV_PFEXEC)
		return (check_user_privs(cr, req));
	if (CR_FLAGS(cr) & PRIV_XPOLICY) {
		return (klpd_call(cr, req, ap));
	}
	return (-1);
}

static int
priv_policy_override_set_va(const cred_t *cr, const priv_set_t *req, ...)
{
	va_list ap;
	int ret;

	va_start(ap, req);
	ret = priv_policy_override_set(cr, req, ap);
	va_end(ap);
	return (ret);
}

/*
 * Audit failure, log error message.
 */
static void
priv_policy_err(const cred_t *cr, int priv, boolean_t allzone, const char *msg)
{

	if (AU_AUDITING())
		audit_priv(priv, allzone ? ZONEPRIVS(cr) : NULL, 0);
	DTRACE_PROBE2(priv__err, int, priv, boolean_t, allzone);

	if (priv_debug || (CR_FLAGS(cr) & PRIV_DEBUG) ||
	    curthread->t_pre_sys) {
		if (allzone && !HAS_ALLZONEPRIVS(cr)) {
			priv_policy_errmsg(cr, PRIV_ALLZONE, msg);
		} else {
			ASSERT(!HAS_PRIVILEGE(cr, priv));
			priv_policy_errmsg(cr, priv, msg);
		}
	}
}

/*
 * priv_policy_ap()
 * return 0 or error.
 * See block comment above for a description of "priv" and "allzone" usage.
 */
static int
priv_policy_ap(const cred_t *cr, int priv, boolean_t allzone, int err,
    const char *msg, va_list ap)
{
	if ((HAS_PRIVILEGE(cr, priv) && (!allzone || HAS_ALLZONEPRIVS(cr))) ||
	    (!servicing_interrupt() &&
	    priv_policy_override(cr, priv, allzone, ap) == 0)) {
		if ((allzone || priv == PRIV_ALL ||
		    !PRIV_ISASSERT(priv_basic, priv)) &&
		    !servicing_interrupt()) {
			PTOU(curproc)->u_acflag |= ASU; /* Needed for SVVS */
			if (AU_AUDITING())
				audit_priv(priv,
				    allzone ? ZONEPRIVS(cr) : NULL, 1);
		}
		err = 0;
		DTRACE_PROBE2(priv__ok, int, priv, boolean_t, allzone);
	} else if (!servicing_interrupt()) {
		/* Failure audited in this procedure */
		priv_policy_err(cr, priv, allzone, msg);
	}
	return (err);
}

int
priv_policy_va(const cred_t *cr, int priv, boolean_t allzone, int err,
    const char *msg, ...)
{
	int ret;
	va_list ap;

	va_start(ap, msg);
	ret = priv_policy_ap(cr, priv, allzone, err, msg, ap);
	va_end(ap);

	return (ret);
}

int
priv_policy(const cred_t *cr, int priv, boolean_t allzone, int err,
    const char *msg)
{
	return (priv_policy_va(cr, priv, allzone, err, msg, KLPDARG_NONE));
}

/*
 * Return B_TRUE for sufficient privileges, B_FALSE for insufficient privileges.
 */
boolean_t
priv_policy_choice(const cred_t *cr, int priv, boolean_t allzone)
{
	boolean_t res = HAS_PRIVILEGE(cr, priv) &&
	    (!allzone || HAS_ALLZONEPRIVS(cr));

	/* Audit success only */
	if (res && AU_AUDITING() &&
	    (allzone || priv == PRIV_ALL || !PRIV_ISASSERT(priv_basic, priv)) &&
	    !servicing_interrupt()) {
		audit_priv(priv, allzone ? ZONEPRIVS(cr) : NULL, 1);
	}
	if (res) {
		DTRACE_PROBE2(priv__ok, int, priv, boolean_t, allzone);
	} else {
		DTRACE_PROBE2(priv__err, int, priv, boolean_t, allzone);
	}
	return (res);
}

/*
 * Non-auditing variant of priv_policy_choice().
 */
boolean_t
priv_policy_only(const cred_t *cr, int priv, boolean_t allzone)
{
	boolean_t res = HAS_PRIVILEGE(cr, priv) &&
	    (!allzone || HAS_ALLZONEPRIVS(cr));

	if (res) {
		DTRACE_PROBE2(priv__ok, int, priv, boolean_t, allzone);
	} else {
		DTRACE_PROBE2(priv__err, int, priv, boolean_t, allzone);
	}
	return (res);
}

/*
 * Check whether all privileges in the required set are present.
 */
static int
secpolicy_require_set(const cred_t *cr, const priv_set_t *req,
    const char *msg, ...)
{
	int priv;
	int pfound = -1;
	priv_set_t pset;
	va_list ap;
	int ret;

	if (req == PRIV_FULLSET ? HAS_ALLPRIVS(cr) : priv_issubset(req,
	    &CR_OEPRIV(cr))) {
		return (0);
	}

	va_start(ap, msg);
	ret = priv_policy_override_set(cr, req, ap);
	va_end(ap);
	if (ret == 0)
		return (0);

	if (req == PRIV_FULLSET || priv_isfullset(req)) {
		priv_policy_err(cr, PRIV_ALL, B_FALSE, msg);
		return (EACCES);
	}

	pset = CR_OEPRIV(cr);		/* present privileges */
	priv_inverse(&pset);		/* all non present privileges */
	priv_intersect(req, &pset);	/* the actual missing privs */

	if (AU_AUDITING())
		audit_priv(PRIV_NONE, &pset, 0);
	/*
	 * Privilege debugging; special case "one privilege in set".
	 */
	if (priv_debug || (CR_FLAGS(cr) & PRIV_DEBUG) || curthread->t_pre_sys) {
		for (priv = 0; priv < nprivs; priv++) {
			if (priv_ismember(&pset, priv)) {
				if (pfound != -1) {
					/* Multiple missing privs */
					priv_policy_errmsg(cr, PRIV_MULTIPLE,
					    msg);
					return (EACCES);
				}
				pfound = priv;
			}
		}
		ASSERT(pfound != -1);
		/* Just the one missing privilege */
		priv_policy_errmsg(cr, pfound, msg);
	}

	return (EACCES);
}

/*
 * Called when an operation requires that the caller be in the
 * global zone, regardless of privilege.
 */
static int
priv_policy_global(const cred_t *cr)
{
	if (crgetzoneid(cr) == GLOBAL_ZONEID)
		return (0);	/* success */

	if (priv_debug || (CR_FLAGS(cr) & PRIV_DEBUG) ||
	    curthread->t_pre_sys) {
		priv_policy_errmsg(cr, PRIV_GLOBAL, NULL);
	}
	return (EPERM);
}

/*
 * Raising process priority
 */
int
secpolicy_raisepriority(const cred_t *cr)
{
	if (PRIV_POLICY(cr, PRIV_PROC_PRIOUP, B_FALSE, EPERM, NULL) == 0)
		return (0);
	return (secpolicy_setpriority(cr));
}

/*
 * Changing process priority or scheduling class
 */
int
secpolicy_setpriority(const cred_t *cr)
{
	return (PRIV_POLICY(cr, PRIV_PROC_PRIOCNTL, B_FALSE, EPERM, NULL));
}

/*
 * Binding to a privileged port, port must be specified in host byte
 * order.
 * When adding a new privilege which allows binding to currently privileged
 * ports, then you MUST also allow processes with PRIV_NET_PRIVADDR bind
 * to these ports because of backward compatibility.
 */
int
secpolicy_net_privaddr(const cred_t *cr, in_port_t port, int proto)
{
	char *reason;
	int priv;

	switch (port) {
	case 137:
	case 138:
	case 139:
	case 445:
		/*
		 * NBT and SMB ports, these are normal privileged ports,
		 * allow bind only if the SYS_SMB or NET_PRIVADDR privilege
		 * is present.
		 * Try both, if neither is present return an error for
		 * priv SYS_SMB.
		 */
		if (PRIV_POLICY_ONLY(cr, PRIV_NET_PRIVADDR, B_FALSE))
			priv = PRIV_NET_PRIVADDR;
		else
			priv = PRIV_SYS_SMB;
		reason = "NBT or SMB port";
		break;

	case 2049:
	case 4045:
		/*
		 * NFS ports, these are extra privileged ports, allow bind
		 * only if the SYS_NFS privilege is present.
		 */
		priv = PRIV_SYS_NFS;
		reason = "NFS port";
		break;

	default:
		priv = PRIV_NET_PRIVADDR;
		reason = NULL;
		break;

	}

	return (priv_policy_va(cr, priv, B_FALSE, EACCES, reason,
	    KLPDARG_PORT, (int)proto, (int)port, KLPDARG_NOMORE));
}

/*
 * Binding to a multilevel port on a trusted (labeled) system.
 */
int
secpolicy_net_bindmlp(const cred_t *cr)
{
	return (PRIV_POLICY(cr, PRIV_NET_BINDMLP, B_FALSE, EACCES, NULL));
}

/*
 * Allow a communication between a zone and an unlabeled host when their
 * labels don't match.
 */
int
secpolicy_net_mac_aware(const cred_t *cr)
{
	return (PRIV_POLICY(cr, PRIV_NET_MAC_AWARE, B_FALSE, EACCES, NULL));
}

/*
 * Allow a privileged process to transmit traffic without explicit labels
 */
int
secpolicy_net_mac_implicit(const cred_t *cr)
{
	return (PRIV_POLICY(cr, PRIV_NET_MAC_IMPLICIT, B_FALSE, EACCES, NULL));
}

/*
 * Common routine which determines whether a given credential can
 * act on a given mount.
 * When called through mount, the parameter needoptcheck is a pointer
 * to a boolean variable which will be set to either true or false,
 * depending on whether the mount policy should change the mount options.
 * In all other cases, needoptcheck should be a NULL pointer.
 */
static int
secpolicy_fs_common(cred_t *cr, vnode_t *mvp, const vfs_t *vfsp,
    boolean_t *needoptcheck)
{
	boolean_t allzone = B_FALSE;
	boolean_t mounting = needoptcheck != NULL;

	/*
	 * Short circuit the following cases:
	 *	vfsp == NULL or mvp == NULL (pure privilege check)
	 *	have all privileges - no further checks required
	 *	and no mount options need to be set.
	 */
	if (vfsp == NULL || mvp == NULL || HAS_ALLPRIVS(cr)) {
		if (mounting)
			*needoptcheck = B_FALSE;

		return (priv_policy_va(cr, PRIV_SYS_MOUNT, allzone, EPERM,
		    NULL, KLPDARG_VNODE, mvp, (char *)NULL, KLPDARG_NOMORE));
	}

	/*
	 * When operating on an existing mount (either we're not mounting
	 * or we're doing a remount and VFS_REMOUNT will be set), zones
	 * can operate only on mounts established by the zone itself.
	 */
	if (!mounting || (vfsp->vfs_flag & VFS_REMOUNT) != 0) {
		zoneid_t zoneid = crgetzoneid(cr);

		if (zoneid != GLOBAL_ZONEID &&
		    vfsp->vfs_zone->zone_id != zoneid) {
			return (EPERM);
		}
	}

	if (mounting)
		*needoptcheck = B_TRUE;

	/*
	 * Overlay mounts may hide important stuff; if you can't write to a
	 * mount point but would be able to mount on top of it, you can
	 * escalate your privileges.
	 * So we go about asking the same questions namefs does when it
	 * decides whether you can mount over a file or not but with the
	 * added restriction that you can only mount on top of a regular
	 * file or directory.
	 * If we have all the zone's privileges, we skip all other checks,
	 * or else we may actually get in trouble inside the automounter.
	 */
	if ((mvp->v_flag & VROOT) != 0 ||
	    (mvp->v_type != VDIR && mvp->v_type != VREG) ||
	    HAS_ALLZONEPRIVS(cr)) {
		allzone = B_TRUE;
	} else {
		vattr_t va;
		int err;

		va.va_mask = AT_UID|AT_MODE;
		err = VOP_GETATTR(mvp, &va, 0, cr, NULL);
		if (err != 0)
			return (err);

		if ((err = secpolicy_vnode_owner(cr, va.va_uid)) != 0)
			return (err);

		if (secpolicy_vnode_access2(cr, mvp, va.va_uid, va.va_mode,
		    VWRITE) != 0) {
			return (EACCES);
		}
	}
	return (priv_policy_va(cr, PRIV_SYS_MOUNT, allzone, EPERM,
	    NULL, KLPDARG_VNODE, mvp, (char *)NULL, KLPDARG_NOMORE));
}

void
secpolicy_fs_mount_clearopts(cred_t *cr, struct vfs *vfsp)
{
	boolean_t amsuper = HAS_ALLZONEPRIVS(cr);

	/*
	 * check; if we don't have either "nosuid" or
	 * both "nosetuid" and "nodevices", then we add
	 * "nosuid"; this depends on how the current
	 * implementation works (it first checks nosuid).  In a
	 * zone, a user with all zone privileges can mount with
	 * "setuid" but never with "devices".
	 */
	if (!vfs_optionisset(vfsp, MNTOPT_NOSUID, NULL) &&
	    (!vfs_optionisset(vfsp, MNTOPT_NODEVICES, NULL) ||
	    !vfs_optionisset(vfsp, MNTOPT_NOSETUID, NULL))) {
		if (crgetzoneid(cr) == GLOBAL_ZONEID || !amsuper)
			vfs_setmntopt(vfsp, MNTOPT_NOSUID, NULL, 0);
		else
			vfs_setmntopt(vfsp, MNTOPT_NODEVICES, NULL, 0);
	}
	/*
	 * If we're not the local super user, we set the "restrict"
	 * option to indicate to automountd that this mount should
	 * be handled with care.
	 */
	if (!amsuper)
		vfs_setmntopt(vfsp, MNTOPT_RESTRICT, NULL, 0);

}

int
secpolicy_fs_allowed_mount(const char *fsname)
{
	struct vfssw *vswp;
	const char *p;
	size_t len;

	ASSERT(fsname != NULL);
	ASSERT(fsname[0] != '\0');

	if (INGLOBALZONE(curproc))
		return (0);

	vswp = vfs_getvfssw(fsname);
	if (vswp == NULL)
		return (ENOENT);

	if ((vswp->vsw_flag & VSW_ZMOUNT) != 0) {
		vfs_unrefvfssw(vswp);
		return (0);
	}

	vfs_unrefvfssw(vswp);

	p = curzone->zone_fs_allowed;
	len = strlen(fsname);

	while (p != NULL && *p != '\0') {
		if (strncmp(p, fsname, len) == 0) {
			char c = *(p + len);
			if (c == '\0' || c == ',')
				return (0);
		}

		/* skip to beyond the next comma */
		if ((p = strchr(p, ',')) != NULL)
			p++;
	}

	return (EPERM);
}

extern vnode_t *rootvp;
extern vfs_t *rootvfs;

int
secpolicy_fs_mount(cred_t *cr, vnode_t *mvp, struct vfs *vfsp)
{
	boolean_t needoptchk;
	int error;

	/*
	 * If it's a remount, get the underlying mount point,
	 * except for the root where we use the rootvp.
	 */
	if ((vfsp->vfs_flag & VFS_REMOUNT) != 0) {
		if (vfsp == rootvfs)
			mvp = rootvp;
		else
			mvp = vfsp->vfs_vnodecovered;
	}

	error = secpolicy_fs_common(cr, mvp, vfsp, &needoptchk);

	if (error == 0 && needoptchk) {
		secpolicy_fs_mount_clearopts(cr, vfsp);
	}

	return (error);
}

/*
 * Does the policy computations for "ownership" of a mount;
 * here ownership is defined as the ability to "mount"
 * the filesystem originally.  The rootvfs doesn't cover any
 * vnodes; we attribute its ownership to the rootvp.
 */
static int
secpolicy_fs_owner(cred_t *cr, const struct vfs *vfsp)
{
	vnode_t *mvp;

	if (vfsp == NULL)
		mvp = NULL;
	else if (vfsp == rootvfs)
		mvp = rootvp;
	else
		mvp = vfsp->vfs_vnodecovered;

	return (secpolicy_fs_common(cr, mvp, vfsp, NULL));
}

int
secpolicy_fs_unmount(cred_t *cr, struct vfs *vfsp)
{
	return (secpolicy_fs_owner(cr, vfsp));
}

/*
 * Quotas are a resource, but if one has the ability to mount a filesystem, he
 * should be able to modify quotas on it.
 */
int
secpolicy_fs_quota(const cred_t *cr, const vfs_t *vfsp)
{
	return (secpolicy_fs_owner((cred_t *)cr, vfsp));
}

/*
 * Exceeding minfree: also a per-mount resource constraint.
 */
int
secpolicy_fs_minfree(const cred_t *cr, const vfs_t *vfsp)
{
	return (secpolicy_fs_owner((cred_t *)cr, vfsp));
}

int
secpolicy_fs_config(const cred_t *cr, const vfs_t *vfsp)
{
	return (secpolicy_fs_owner((cred_t *)cr, vfsp));
}

/* ARGSUSED */
int
secpolicy_fs_linkdir(const cred_t *cr, const vfs_t *vfsp)
{
	return (PRIV_POLICY(cr, PRIV_SYS_LINKDIR, B_FALSE, EPERM, NULL));
}

/*
 * Name:        secpolicy_vnode_access()
 *
 * Parameters:  Process credential
 *		vnode
 *		uid of owner of vnode
 *		permission bits not granted to the caller when examining
 *		file mode bits (i.e., when a process wants to open a
 *		mode 444 file for VREAD|VWRITE, this function should be
 *		called only with a VWRITE argument).
 *
 * Normal:      Verifies that cred has the appropriate privileges to
 *              override the mode bits that were denied.
 *
 * Override:    file_dac_execute - if VEXEC bit was denied and vnode is
 *                      not a directory.
 *              file_dac_read - if VREAD bit was denied.
 *              file_dac_search - if VEXEC bit was denied and vnode is
 *                      a directory.
 *              file_dac_write - if VWRITE bit was denied.
 *
 *		Root owned files are special cased to protect system
 *		configuration files and such.
 *
 * Output:      EACCES - if privilege check fails.
 */

int
secpolicy_vnode_access(const cred_t *cr, vnode_t *vp, uid_t owner, mode_t mode)
{
	if ((mode & VREAD) && priv_policy_va(cr, PRIV_FILE_DAC_READ, B_FALSE,
	    EACCES, NULL, KLPDARG_VNODE, vp, (char *)NULL,
	    KLPDARG_NOMORE) != 0) {
		return (EACCES);
	}

	if (mode & VWRITE) {
		boolean_t allzone;

		if (owner == 0 && cr->cr_uid != 0)
			allzone = B_TRUE;
		else
			allzone = B_FALSE;
		if (priv_policy_va(cr, PRIV_FILE_DAC_WRITE, allzone, EACCES,
		    NULL, KLPDARG_VNODE, vp, (char *)NULL,
		    KLPDARG_NOMORE) != 0) {
			return (EACCES);
		}
	}

	if (mode & VEXEC) {
		/*
		 * Directories use file_dac_search to override the execute bit.
		 */
		int p = vp->v_type == VDIR ? PRIV_FILE_DAC_SEARCH :
		    PRIV_FILE_DAC_EXECUTE;

		return (priv_policy_va(cr, p, B_FALSE, EACCES, NULL,
		    KLPDARG_VNODE, vp, (char *)NULL, KLPDARG_NOMORE));
	}
	return (0);
}

/*
 * Like secpolicy_vnode_access() but we get the actual wanted mode and the
 * current mode of the file, not the missing bits.
 */
int
secpolicy_vnode_access2(const cred_t *cr, vnode_t *vp, uid_t owner,
    mode_t curmode, mode_t wantmode)
{
	mode_t mode;

	/* Inline the basic privileges tests. */
	if ((wantmode & VREAD) &&
	    !PRIV_ISASSERT(&CR_OEPRIV(cr), PRIV_FILE_READ) &&
	    priv_policy_va(cr, PRIV_FILE_READ, B_FALSE, EACCES, NULL,
	    KLPDARG_VNODE, vp, (char *)NULL, KLPDARG_NOMORE) != 0) {
		return (EACCES);
	}

	if ((wantmode & VWRITE) &&
	    !PRIV_ISASSERT(&CR_OEPRIV(cr), PRIV_FILE_WRITE) &&
	    priv_policy_va(cr, PRIV_FILE_WRITE, B_FALSE, EACCES, NULL,
	    KLPDARG_VNODE, vp, (char *)NULL, KLPDARG_NOMORE) != 0) {
		return (EACCES);
	}

	mode = ~curmode & wantmode;

	if (mode == 0)
		return (0);

	if ((mode & VREAD) && priv_policy_va(cr, PRIV_FILE_DAC_READ, B_FALSE,
	    EACCES, NULL, KLPDARG_VNODE, vp, (char *)NULL,
	    KLPDARG_NOMORE) != 0) {
		return (EACCES);
	}

	if (mode & VWRITE) {
		boolean_t allzone;

		if (owner == 0 && cr->cr_uid != 0)
			allzone = B_TRUE;
		else
			allzone = B_FALSE;
		if (priv_policy_va(cr, PRIV_FILE_DAC_WRITE, allzone, EACCES,
		    NULL, KLPDARG_VNODE, vp, (char *)NULL,
		    KLPDARG_NOMORE) != 0) {
			return (EACCES);
		}
	}

	if (mode & VEXEC) {
		/*
		 * Directories use file_dac_search to override the execute bit.
		 */
		int p = vp->v_type == VDIR ? PRIV_FILE_DAC_SEARCH :
		    PRIV_FILE_DAC_EXECUTE;

		return (priv_policy_va(cr, p, B_FALSE, EACCES, NULL,
		    KLPDARG_VNODE, vp, (char *)NULL, KLPDARG_NOMORE));
	}
	return (0);
}

/*
 * This is a special routine for ZFS; it is used to determine whether
 * any of the privileges in effect allow any form of access to the
 * file.  There's no reason to audit this or any reason to record
 * this.  More work is needed to do the "KPLD" stuff.
 */
int
secpolicy_vnode_any_access(const cred_t *cr, vnode_t *vp, uid_t owner)
{
	static int privs[] = {
	    PRIV_FILE_OWNER,
	    PRIV_FILE_CHOWN,
	    PRIV_FILE_DAC_READ,
	    PRIV_FILE_DAC_WRITE,
	    PRIV_FILE_DAC_EXECUTE,
	    PRIV_FILE_DAC_SEARCH,
	};
	int i;

	/* Same as secpolicy_vnode_setdac */
	if (owner == cr->cr_uid)
		return (0);

	for (i = 0; i < sizeof (privs)/sizeof (int); i++) {
		boolean_t allzone = B_FALSE;
		int priv;

		switch (priv = privs[i]) {
		case PRIV_FILE_DAC_EXECUTE:
			if (vp->v_type == VDIR)
				continue;
			break;
		case PRIV_FILE_DAC_SEARCH:
			if (vp->v_type != VDIR)
				continue;
			break;
		case PRIV_FILE_DAC_WRITE:
		case PRIV_FILE_OWNER:
		case PRIV_FILE_CHOWN:
			/* We know here that if owner == 0, that cr_uid != 0 */
			allzone = owner == 0;
			break;
		}
		if (PRIV_POLICY_CHOICE(cr, priv, allzone))
			return (0);
	}
	return (EPERM);
}

/*
 * Name:	secpolicy_vnode_setid_modify()
 *
 * Normal:	verify that subject can set the file setid flags.
 *
 * Output:	EPERM - if not privileged.
 */

static int
secpolicy_vnode_setid_modify(const cred_t *cr, uid_t owner)
{
	/* If changing to suid root, must have all zone privs */
	boolean_t allzone = B_TRUE;

	if (owner != 0) {
		if (owner == cr->cr_uid)
			return (0);
		allzone = B_FALSE;
	}
	return (PRIV_POLICY(cr, PRIV_FILE_SETID, allzone, EPERM, NULL));
}

/*
 * Are we allowed to retain the set-uid/set-gid bits when
 * changing ownership or when writing to a file?
 * "issuid" should be true when set-uid; only in that case
 * root ownership is checked (setgid is assumed).
 */
int
secpolicy_vnode_setid_retain(const cred_t *cred, boolean_t issuidroot)
{
	if (issuidroot && !HAS_ALLZONEPRIVS(cred))
		return (EPERM);

	return (!PRIV_POLICY_CHOICE(cred, PRIV_FILE_SETID, B_FALSE));
}

/*
 * Name:	secpolicy_vnode_setids_setgids()
 *
 * Normal:	verify that subject can set the file setgid flag.
 *
 * Output:	EPERM - if not privileged
 */

int
secpolicy_vnode_setids_setgids(const cred_t *cred, gid_t gid)
{
	if (!groupmember(gid, cred))
		return (PRIV_POLICY(cred, PRIV_FILE_SETID, B_FALSE, EPERM,
		    NULL));
	return (0);
}

/*
 * Name:	secpolicy_vnode_chown
 *
 * Normal:	Determine if subject can chown owner of a file.
 *
 * Output:	EPERM - if access denied
 */

int
secpolicy_vnode_chown(const cred_t *cred, uid_t owner)
{
	boolean_t is_owner = (owner == crgetuid(cred));
	boolean_t allzone = B_FALSE;
	int priv;

	if (!is_owner) {
		allzone = (owner == 0);
		priv = PRIV_FILE_CHOWN;
	} else {
		priv = HAS_PRIVILEGE(cred, PRIV_FILE_CHOWN) ?
		    PRIV_FILE_CHOWN : PRIV_FILE_CHOWN_SELF;
	}

	return (PRIV_POLICY(cred, priv, allzone, EPERM, NULL));
}

/*
 * Name:	secpolicy_vnode_create_gid
 *
 * Normal:	Determine if subject can change group ownership of a file.
 *
 * Output:	EPERM - if access denied
 */
int
secpolicy_vnode_create_gid(const cred_t *cred)
{
	if (HAS_PRIVILEGE(cred, PRIV_FILE_CHOWN))
		return (PRIV_POLICY(cred, PRIV_FILE_CHOWN, B_FALSE, EPERM,
		    NULL));
	else
		return (PRIV_POLICY(cred, PRIV_FILE_CHOWN_SELF, B_FALSE, EPERM,
		    NULL));
}

/*
 * Name:	secpolicy_vnode_utime_modify()
 *
 * Normal:	verify that subject can modify the utime on a file.
 *
 * Output:	EPERM - if access denied.
 */

static int
secpolicy_vnode_utime_modify(const cred_t *cred)
{
	return (PRIV_POLICY(cred, PRIV_FILE_OWNER, B_FALSE, EPERM,
	    "modify file times"));
}


/*
 * Name:	secpolicy_vnode_setdac()
 *
 * Normal:	verify that subject can modify the mode of a file.
 *		allzone privilege needed when modifying root owned object.
 *
 * Output:	EPERM - if access denied.
 */

int
secpolicy_vnode_setdac(const cred_t *cred, uid_t owner)
{
	if (owner == cred->cr_uid)
		return (0);

	return (PRIV_POLICY(cred, PRIV_FILE_OWNER, owner == 0, EPERM, NULL));
}
/*
 * Name:	secpolicy_vnode_stky_modify()
 *
 * Normal:	verify that subject can make a file a "sticky".
 *
 * Output:	EPERM - if access denied.
 */

int
secpolicy_vnode_stky_modify(const cred_t *cred)
{
	return (PRIV_POLICY(cred, PRIV_SYS_CONFIG, B_FALSE, EPERM,
	    "set file sticky"));
}

/*
 * Policy determines whether we can remove an entry from a directory,
 * regardless of permission bits.
 */
int
secpolicy_vnode_remove(const cred_t *cr)
{
	return (PRIV_POLICY(cr, PRIV_FILE_OWNER, B_FALSE, EACCES,
	    "sticky directory"));
}

int
secpolicy_vnode_owner(const cred_t *cr, uid_t owner)
{
	boolean_t allzone = (owner == 0);

	if (owner == cr->cr_uid)
		return (0);

	return (PRIV_POLICY(cr, PRIV_FILE_OWNER, allzone, EPERM, NULL));
}

void
secpolicy_setid_clear(vattr_t *vap, cred_t *cr)
{
	proc_t *p = curproc;

	/*
	 * Allow the brand to override this behaviour.
	 */
	if (PROC_IS_BRANDED(p) && BROP(p)->b_setid_clear != NULL) {
		/*
		 * This brand hook will return 0 if handling is complete, or
		 * some other value if the brand would like us to fall back to
		 * the usual behaviour.
		 */
		if (BROP(p)->b_setid_clear(vap, cr) == 0) {
			return;
		}
	}

	if ((vap->va_mode & (S_ISUID | S_ISGID)) != 0 &&
	    secpolicy_vnode_setid_retain(cr,
	    (vap->va_mode & S_ISUID) != 0 &&
	    (vap->va_mask & AT_UID) != 0 && vap->va_uid == 0) != 0) {
		vap->va_mask |= AT_MODE;
		vap->va_mode &= ~(S_ISUID|S_ISGID);
	}
}

int
secpolicy_setid_setsticky_clear(vnode_t *vp, vattr_t *vap, const vattr_t *ovap,
    cred_t *cr)
{
	int error;

	if ((vap->va_mode & S_ISUID) != 0 &&
	    (error = secpolicy_vnode_setid_modify(cr,
	    ovap->va_uid)) != 0) {
		return (error);
	}

	/*
	 * Check privilege if attempting to set the
	 * sticky bit on a non-directory.
	 */
	if (vp->v_type != VDIR && (vap->va_mode & S_ISVTX) != 0 &&
	    secpolicy_vnode_stky_modify(cr) != 0) {
		vap->va_mode &= ~S_ISVTX;
	}

	/*
	 * Check for privilege if attempting to set the
	 * group-id bit.
	 */
	if ((vap->va_mode & S_ISGID) != 0 &&
	    secpolicy_vnode_setids_setgids(cr, ovap->va_gid) != 0) {
		vap->va_mode &= ~S_ISGID;
	}

	return (0);
}

#define	ATTR_FLAG_PRIV(attr, value, cr)	\
	PRIV_POLICY(cr, value ? PRIV_FILE_FLAG_SET : PRIV_ALL, \
	B_FALSE, EPERM, NULL)

/*
 * Check privileges for setting xvattr attributes
 */
int
secpolicy_xvattr(xvattr_t *xvap, uid_t owner, cred_t *cr, vtype_t vtype)
{
	xoptattr_t *xoap;
	int error = 0;

	if ((xoap = xva_getxoptattr(xvap)) == NULL)
		return (EINVAL);

	/*
	 * First process the DOS bits
	 */
	if (XVA_ISSET_REQ(xvap, XAT_ARCHIVE) ||
	    XVA_ISSET_REQ(xvap, XAT_HIDDEN) ||
	    XVA_ISSET_REQ(xvap, XAT_READONLY) ||
	    XVA_ISSET_REQ(xvap, XAT_SYSTEM) ||
	    XVA_ISSET_REQ(xvap, XAT_CREATETIME) ||
	    XVA_ISSET_REQ(xvap, XAT_OFFLINE) ||
	    XVA_ISSET_REQ(xvap, XAT_SPARSE)) {
		if ((error = secpolicy_vnode_owner(cr, owner)) != 0)
			return (error);
	}

	/*
	 * Now handle special attributes
	 */

	if (XVA_ISSET_REQ(xvap, XAT_IMMUTABLE))
		error = ATTR_FLAG_PRIV(XAT_IMMUTABLE,
		    xoap->xoa_immutable, cr);
	if (error == 0 && XVA_ISSET_REQ(xvap, XAT_NOUNLINK))
		error = ATTR_FLAG_PRIV(XAT_NOUNLINK,
		    xoap->xoa_nounlink, cr);
	if (error == 0 && XVA_ISSET_REQ(xvap, XAT_APPENDONLY))
		error = ATTR_FLAG_PRIV(XAT_APPENDONLY,
		    xoap->xoa_appendonly, cr);
	if (error == 0 && XVA_ISSET_REQ(xvap, XAT_NODUMP))
		error = ATTR_FLAG_PRIV(XAT_NODUMP,
		    xoap->xoa_nodump, cr);
	if (error == 0 && XVA_ISSET_REQ(xvap, XAT_OPAQUE))
		error = EPERM;
	if (error == 0 && XVA_ISSET_REQ(xvap, XAT_AV_QUARANTINED)) {
		error = ATTR_FLAG_PRIV(XAT_AV_QUARANTINED,
		    xoap->xoa_av_quarantined, cr);
		if (error == 0 && vtype != VREG && xoap->xoa_av_quarantined)
			error = EINVAL;
	}
	if (error == 0 && XVA_ISSET_REQ(xvap, XAT_AV_MODIFIED))
		error = ATTR_FLAG_PRIV(XAT_AV_MODIFIED,
		    xoap->xoa_av_modified, cr);
	if (error == 0 && XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP)) {
		error = ATTR_FLAG_PRIV(XAT_AV_SCANSTAMP,
		    xoap->xoa_av_scanstamp, cr);
		if (error == 0 && vtype != VREG)
			error = EINVAL;
	}
	return (error);
}

/*
 * This function checks the policy decisions surrounding the
 * vop setattr call.
 *
 * It should be called after sufficient locks have been established
 * on the underlying data structures.  No concurrent modifications
 * should be allowed.
 *
 * The caller must pass in unlocked version of its vaccess function
 * this is required because vop_access function should lock the
 * node for reading.  A three argument function should be defined
 * which accepts the following argument:
 * 	A pointer to the internal "node" type (inode *)
 *	vnode access bits (VREAD|VWRITE|VEXEC)
 *	a pointer to the credential
 *
 * This function makes the following policy decisions:
 *
 *		- change permissions
 *			- permission to change file mode if not owner
 *			- permission to add sticky bit to non-directory
 *			- permission to add set-gid bit
 *
 * The ovap argument should include AT_MODE|AT_UID|AT_GID.
 *
 * If the vap argument does not include AT_MODE, the mode will be copied from
 * ovap.  In certain situations set-uid/set-gid bits need to be removed;
 * this is done by marking vap->va_mask to include AT_MODE and va_mode
 * is updated to the newly computed mode.
 */

int
secpolicy_vnode_setattr(cred_t *cr, struct vnode *vp, struct vattr *vap,
	const struct vattr *ovap, int flags,
	int unlocked_access(void *, int, cred_t *),
	void *node)
{
	int mask = vap->va_mask;
	int error = 0;
	boolean_t skipaclchk = (flags & ATTR_NOACLCHECK) ? B_TRUE : B_FALSE;

	if (mask & AT_SIZE) {
		if (vp->v_type == VDIR) {
			error = EISDIR;
			goto out;
		}

		/*
		 * If ATTR_NOACLCHECK is set in the flags, then we don't
		 * perform the secondary unlocked_access() call since the
		 * ACL (if any) is being checked there.
		 */
		if (skipaclchk == B_FALSE) {
			error = unlocked_access(node, VWRITE, cr);
			if (error)
				goto out;
		}
	}
	if (mask & AT_MODE) {
		/*
		 * If not the owner of the file then check privilege
		 * for two things: the privilege to set the mode at all
		 * and, if we're setting setuid, we also need permissions
		 * to add the set-uid bit, if we're not the owner.
		 * In the specific case of creating a set-uid root
		 * file, we need even more permissions.
		 */
		if ((error = secpolicy_vnode_setdac(cr, ovap->va_uid)) != 0)
			goto out;

		if ((error = secpolicy_setid_setsticky_clear(vp, vap,
		    ovap, cr)) != 0)
			goto out;
	} else
		vap->va_mode = ovap->va_mode;

	if (mask & (AT_UID|AT_GID)) {
		boolean_t checkpriv = B_FALSE;

		/*
		 * Chowning files.
		 *
		 * If you are the file owner:
		 *	chown to other uid		FILE_CHOWN_SELF
		 *	chown to gid (non-member) 	FILE_CHOWN_SELF
		 *	chown to gid (member) 		<none>
		 *
		 * Instead of PRIV_FILE_CHOWN_SELF, FILE_CHOWN is also
		 * acceptable but the first one is reported when debugging.
		 *
		 * If you are not the file owner:
		 *	chown from root			PRIV_FILE_CHOWN + zone
		 *	chown from other to any		PRIV_FILE_CHOWN
		 *
		 */
		if (cr->cr_uid != ovap->va_uid) {
			checkpriv = B_TRUE;
		} else {
			if (((mask & AT_UID) && vap->va_uid != ovap->va_uid) ||
			    ((mask & AT_GID) && vap->va_gid != ovap->va_gid &&
			    !groupmember(vap->va_gid, cr))) {
				checkpriv = B_TRUE;
			}
		}
		/*
		 * If necessary, check privilege to see if update can be done.
		 */
		if (checkpriv &&
		    (error = secpolicy_vnode_chown(cr, ovap->va_uid)) != 0) {
			goto out;
		}

		/*
		 * If the file has either the set UID or set GID bits
		 * set and the caller can set the bits, then leave them.
		 */
		secpolicy_setid_clear(vap, cr);
	}
	if (mask & (AT_ATIME|AT_MTIME)) {
		/*
		 * If not the file owner and not otherwise privileged,
		 * always return an error when setting the
		 * time other than the current (ATTR_UTIME flag set).
		 * If setting the current time (ATTR_UTIME not set) then
		 * unlocked_access will check permissions according to policy.
		 */
		if (cr->cr_uid != ovap->va_uid) {
			if (flags & ATTR_UTIME)
				error = secpolicy_vnode_utime_modify(cr);
			else if (skipaclchk == B_FALSE) {
				error = unlocked_access(node, VWRITE, cr);
				if (error == EACCES &&
				    secpolicy_vnode_utime_modify(cr) == 0)
					error = 0;
			}
			if (error)
				goto out;
		}
	}

	/*
	 * Check for optional attributes here by checking the following:
	 */
	if (mask & AT_XVATTR)
		error = secpolicy_xvattr((xvattr_t *)vap, ovap->va_uid, cr,
		    vp->v_type);
out:
	return (error);
}

/*
 * Name:	secpolicy_pcfs_modify_bootpartition()
 *
 * Normal:	verify that subject can modify a pcfs boot partition.
 *
 * Output:	EACCES - if privilege check failed.
 */
/*ARGSUSED*/
int
secpolicy_pcfs_modify_bootpartition(const cred_t *cred)
{
	return (PRIV_POLICY(cred, PRIV_ALL, B_FALSE, EACCES,
	    "modify pcfs boot partition"));
}

/*
 * System V IPC routines
 */
int
secpolicy_ipc_owner(const cred_t *cr, const struct kipc_perm *ip)
{
	if (crgetzoneid(cr) != ip->ipc_zoneid ||
	    (cr->cr_uid != ip->ipc_uid && cr->cr_uid != ip->ipc_cuid)) {
		boolean_t allzone = B_FALSE;
		if (ip->ipc_uid == 0 || ip->ipc_cuid == 0)
			allzone = B_TRUE;
		return (PRIV_POLICY(cr, PRIV_IPC_OWNER, allzone, EPERM, NULL));
	}
	return (0);
}

int
secpolicy_ipc_config(const cred_t *cr)
{
	return (PRIV_POLICY(cr, PRIV_SYS_IPC_CONFIG, B_FALSE, EPERM, NULL));
}

int
secpolicy_ipc_access(const cred_t *cr, const struct kipc_perm *ip, mode_t mode)
{

	boolean_t allzone = B_FALSE;

	ASSERT((mode & (MSG_R|MSG_W)) != 0);

	if ((mode & MSG_R) &&
	    PRIV_POLICY(cr, PRIV_IPC_DAC_READ, allzone, EACCES, NULL) != 0)
		return (EACCES);

	if (mode & MSG_W) {
		if (cr->cr_uid != 0 && (ip->ipc_uid == 0 || ip->ipc_cuid == 0))
			allzone = B_TRUE;

		return (PRIV_POLICY(cr, PRIV_IPC_DAC_WRITE, allzone, EACCES,
		    NULL));
	}
	return (0);
}

int
secpolicy_rsm_access(const cred_t *cr, uid_t owner, mode_t mode)
{
	boolean_t allzone = B_FALSE;

	ASSERT((mode & (MSG_R|MSG_W)) != 0);

	if ((mode & MSG_R) &&
	    PRIV_POLICY(cr, PRIV_IPC_DAC_READ, allzone, EACCES, NULL) != 0)
		return (EACCES);

	if (mode & MSG_W) {
		if (cr->cr_uid != 0 && owner == 0)
			allzone = B_TRUE;

		return (PRIV_POLICY(cr, PRIV_IPC_DAC_WRITE, allzone, EACCES,
		    NULL));
	}
	return (0);
}

/*
 * Audit configuration.
 */
int
secpolicy_audit_config(const cred_t *cr)
{
	return (PRIV_POLICY(cr, PRIV_SYS_AUDIT, B_FALSE, EPERM, NULL));
}

/*
 * Audit record generation.
 */
int
secpolicy_audit_modify(const cred_t *cr)
{
	return (PRIV_POLICY(cr, PRIV_PROC_AUDIT, B_FALSE, EPERM, NULL));
}

/*
 * Get audit attributes.
 * Either PRIV_SYS_AUDIT or PRIV_PROC_AUDIT required; report the
 * "Least" of the two privileges on error.
 */
int
secpolicy_audit_getattr(const cred_t *cr, boolean_t checkonly)
{
	int priv;

	if (PRIV_POLICY_ONLY(cr, PRIV_SYS_AUDIT, B_FALSE))
		priv = PRIV_SYS_AUDIT;
	else
		priv = PRIV_PROC_AUDIT;

	if (checkonly)
		return (!PRIV_POLICY_ONLY(cr, priv, B_FALSE));
	else
		return (PRIV_POLICY(cr, priv, B_FALSE, EPERM, NULL));
}


/*
 * Locking physical memory
 */
int
secpolicy_lock_memory(const cred_t *cr)
{
	return (PRIV_POLICY(cr, PRIV_PROC_LOCK_MEMORY, B_FALSE, EPERM, NULL));
}

/*
 * Accounting (both acct(2) and exacct).
 */
int
secpolicy_acct(const cred_t *cr)
{
	return (PRIV_POLICY(cr, PRIV_SYS_ACCT, B_FALSE, EPERM, NULL));
}

/*
 * Is this process privileged to change its uids at will?
 * Uid 0 is still considered "special" and having the SETID
 * privilege is not sufficient to get uid 0.
 * Files are owned by root, so the privilege would give
 * full access and euid 0 is still effective.
 *
 * If you have the privilege and euid 0 only then do you
 * get the powers of root wrt uid 0.
 *
 * For gid manipulations, this is should be called with an
 * uid of -1.
 *
 */
int
secpolicy_allow_setid(const cred_t *cr, uid_t newuid, boolean_t checkonly)
{
	boolean_t allzone = B_FALSE;

	if (newuid == 0 && cr->cr_uid != 0 && cr->cr_suid != 0 &&
	    cr->cr_ruid != 0) {
		allzone = B_TRUE;
	}

	return (checkonly ? !PRIV_POLICY_ONLY(cr, PRIV_PROC_SETID, allzone) :
	    PRIV_POLICY(cr, PRIV_PROC_SETID, allzone, EPERM, NULL));
}


/*
 * Acting on a different process: if the mode is for writing,
 * the restrictions are more severe.  This is called after
 * we've verified that the uids do not match.
 */
int
secpolicy_proc_owner(const cred_t *scr, const cred_t *tcr, int mode)
{
	boolean_t allzone = B_FALSE;

	if ((mode & VWRITE) && scr->cr_uid != 0 &&
	    (tcr->cr_uid == 0 || tcr->cr_ruid == 0 || tcr->cr_suid == 0))
		allzone = B_TRUE;

	return (PRIV_POLICY(scr, PRIV_PROC_OWNER, allzone, EPERM, NULL));
}

int
secpolicy_proc_access(const cred_t *scr)
{
	return (PRIV_POLICY(scr, PRIV_PROC_OWNER, B_FALSE, EACCES, NULL));
}

int
secpolicy_proc_excl_open(const cred_t *scr)
{
	return (PRIV_POLICY(scr, PRIV_PROC_OWNER, B_FALSE, EBUSY, NULL));
}

int
secpolicy_proc_zone(const cred_t *scr)
{
	return (PRIV_POLICY(scr, PRIV_PROC_ZONE, B_FALSE, EPERM, NULL));
}

/*
 * Destroying the system
 */

int
secpolicy_kmdb(const cred_t *scr)
{
	return (PRIV_POLICY(scr, PRIV_ALL, B_FALSE, EPERM, NULL));
}

int
secpolicy_error_inject(const cred_t *scr)
{
	return (PRIV_POLICY(scr, PRIV_ALL, B_FALSE, EPERM, NULL));
}

/*
 * Processor sets, cpu configuration, resource pools.
 */
int
secpolicy_pset(const cred_t *cr)
{
	return (PRIV_POLICY(cr, PRIV_SYS_RES_CONFIG, B_FALSE, EPERM, NULL));
}

/*
 * Processor set binding.
 */
int
secpolicy_pbind(const cred_t *cr)
{
	if (PRIV_POLICY_ONLY(cr, PRIV_SYS_RES_CONFIG, B_FALSE))
		return (secpolicy_pset(cr));
	return (PRIV_POLICY(cr, PRIV_SYS_RES_BIND, B_FALSE, EPERM, NULL));
}

int
secpolicy_ponline(const cred_t *cr)
{
	return (PRIV_POLICY(cr, PRIV_SYS_RES_CONFIG, B_FALSE, EPERM, NULL));
}

int
secpolicy_pool(const cred_t *cr)
{
	return (PRIV_POLICY(cr, PRIV_SYS_RES_CONFIG, B_FALSE, EPERM, NULL));
}

int
secpolicy_blacklist(const cred_t *cr)
{
	return (PRIV_POLICY(cr, PRIV_SYS_RES_CONFIG, B_FALSE, EPERM, NULL));
}

/*
 * Catch all system configuration.
 */
int
secpolicy_sys_config(const cred_t *cr, boolean_t checkonly)
{
	if (checkonly) {
		return (PRIV_POLICY_ONLY(cr, PRIV_SYS_CONFIG, B_FALSE) ? 0 :
		    EPERM);
	} else {
		return (PRIV_POLICY(cr, PRIV_SYS_CONFIG, B_FALSE, EPERM, NULL));
	}
}

/*
 * Zone administration (halt, reboot, etc.) from within zone.
 */
int
secpolicy_zone_admin(const cred_t *cr, boolean_t checkonly)
{
	if (checkonly) {
		return (PRIV_POLICY_ONLY(cr, PRIV_SYS_ADMIN, B_FALSE) ? 0 :
		    EPERM);
	} else {
		return (PRIV_POLICY(cr, PRIV_SYS_ADMIN, B_FALSE, EPERM,
		    NULL));
	}
}

/*
 * Zone configuration (create, halt, enter).
 */
int
secpolicy_zone_config(const cred_t *cr)
{
	/*
	 * Require all privileges to avoid possibility of privilege
	 * escalation.
	 */
	return (secpolicy_require_set(cr, PRIV_FULLSET, NULL, KLPDARG_NONE));
}

/*
 * Various other system configuration calls
 */
int
secpolicy_coreadm(const cred_t *cr)
{
	return (PRIV_POLICY(cr, PRIV_SYS_ADMIN, B_FALSE, EPERM, NULL));
}

int
secpolicy_systeminfo(const cred_t *cr)
{
	return (PRIV_POLICY(cr, PRIV_SYS_ADMIN, B_FALSE, EPERM, NULL));
}

int
secpolicy_dispadm(const cred_t *cr)
{
	return (PRIV_POLICY(cr, PRIV_SYS_CONFIG, B_FALSE, EPERM, NULL));
}

int
secpolicy_settime(const cred_t *cr)
{
	return (PRIV_POLICY(cr, PRIV_SYS_TIME, B_FALSE, EPERM, NULL));
}

/*
 * For realtime users: high resolution clock.
 */
int
secpolicy_clock_highres(const cred_t *cr)
{
	return (PRIV_POLICY(cr, PRIV_PROC_CLOCK_HIGHRES, B_FALSE, EPERM,
	    NULL));
}

/*
 * drv_priv() is documented as callable from interrupt context, not that
 * anyone ever does, but still.  No debugging or auditing can be done when
 * it is called from interrupt context.
 * returns 0 on succes, EPERM on failure.
 */
int
drv_priv(cred_t *cr)
{
	return (PRIV_POLICY(cr, PRIV_SYS_DEVICES, B_FALSE, EPERM, NULL));
}

int
secpolicy_sys_devices(const cred_t *cr)
{
	return (PRIV_POLICY(cr, PRIV_SYS_DEVICES, B_FALSE, EPERM, NULL));
}

int
secpolicy_excl_open(const cred_t *cr)
{
	return (PRIV_POLICY(cr, PRIV_SYS_DEVICES, B_FALSE, EBUSY, NULL));
}

int
secpolicy_rctlsys(const cred_t *cr, boolean_t is_zone_rctl)
{
	/* zone.* rctls can only be set from the global zone */
	if (is_zone_rctl && priv_policy_global(cr) != 0)
		return (EPERM);
	return (PRIV_POLICY(cr, PRIV_SYS_RESOURCE, B_FALSE, EPERM, NULL));
}

int
secpolicy_resource(const cred_t *cr)
{
	return (PRIV_POLICY(cr, PRIV_SYS_RESOURCE, B_FALSE, EPERM, NULL));
}

int
secpolicy_resource_anon_mem(const cred_t *cr)
{
	return (PRIV_POLICY_ONLY(cr, PRIV_SYS_RESOURCE, B_FALSE));
}

/*
 * Processes with a real uid of 0 escape any form of accounting, much
 * like before.
 */
int
secpolicy_newproc(const cred_t *cr)
{
	if (cr->cr_ruid == 0)
		return (0);

	return (PRIV_POLICY(cr, PRIV_SYS_RESOURCE, B_FALSE, EPERM, NULL));
}

/*
 * Networking
 */
int
secpolicy_net_rawaccess(const cred_t *cr)
{
	return (PRIV_POLICY(cr, PRIV_NET_RAWACCESS, B_FALSE, EACCES, NULL));
}

int
secpolicy_net_observability(const cred_t *cr)
{
	return (PRIV_POLICY(cr, PRIV_NET_OBSERVABILITY, B_FALSE, EACCES, NULL));
}

/*
 * Need this privilege for accessing the ICMP device
 */
int
secpolicy_net_icmpaccess(const cred_t *cr)
{
	return (PRIV_POLICY(cr, PRIV_NET_ICMPACCESS, B_FALSE, EACCES, NULL));
}

/*
 * There are a few rare cases where the kernel generates ioctls() from
 * interrupt context with a credential of kcred rather than NULL.
 * In those cases, we take the safe and cheap test.
 */
int
secpolicy_net_config(const cred_t *cr, boolean_t checkonly)
{
	if (checkonly) {
		return (PRIV_POLICY_ONLY(cr, PRIV_SYS_NET_CONFIG, B_FALSE) ?
		    0 : EPERM);
	} else {
		return (PRIV_POLICY(cr, PRIV_SYS_NET_CONFIG, B_FALSE, EPERM,
		    NULL));
	}
}


/*
 * PRIV_SYS_NET_CONFIG is a superset of PRIV_SYS_IP_CONFIG.
 *
 * There are a few rare cases where the kernel generates ioctls() from
 * interrupt context with a credential of kcred rather than NULL.
 * In those cases, we take the safe and cheap test.
 */
int
secpolicy_ip_config(const cred_t *cr, boolean_t checkonly)
{
	if (PRIV_POLICY_ONLY(cr, PRIV_SYS_NET_CONFIG, B_FALSE))
		return (secpolicy_net_config(cr, checkonly));

	if (checkonly) {
		return (PRIV_POLICY_ONLY(cr, PRIV_SYS_IP_CONFIG, B_FALSE) ?
		    0 : EPERM);
	} else {
		return (PRIV_POLICY(cr, PRIV_SYS_IP_CONFIG, B_FALSE, EPERM,
		    NULL));
	}
}

/*
 * PRIV_SYS_NET_CONFIG is a superset of PRIV_SYS_DL_CONFIG.
 */
int
secpolicy_dl_config(const cred_t *cr)
{
	if (PRIV_POLICY_ONLY(cr, PRIV_SYS_NET_CONFIG, B_FALSE))
		return (secpolicy_net_config(cr, B_FALSE));
	return (PRIV_POLICY(cr, PRIV_SYS_DL_CONFIG, B_FALSE, EPERM, NULL));
}

/*
 * PRIV_SYS_DL_CONFIG is a superset of PRIV_SYS_IPTUN_CONFIG.
 */
int
secpolicy_iptun_config(const cred_t *cr)
{
	if (PRIV_POLICY_ONLY(cr, PRIV_SYS_NET_CONFIG, B_FALSE))
		return (secpolicy_net_config(cr, B_FALSE));
	if (PRIV_POLICY_ONLY(cr, PRIV_SYS_DL_CONFIG, B_FALSE))
		return (secpolicy_dl_config(cr));
	return (PRIV_POLICY(cr, PRIV_SYS_IPTUN_CONFIG, B_FALSE, EPERM, NULL));
}

/*
 * Map IP pseudo privileges to actual privileges.
 * So we don't need to recompile IP when we change the privileges.
 */
int
secpolicy_ip(const cred_t *cr, int netpriv, boolean_t checkonly)
{
	int priv = PRIV_ALL;

	switch (netpriv) {
	case OP_CONFIG:
		priv = PRIV_SYS_IP_CONFIG;
		break;
	case OP_RAW:
		priv = PRIV_NET_RAWACCESS;
		break;
	case OP_PRIVPORT:
		priv = PRIV_NET_PRIVADDR;
		break;
	}
	ASSERT(priv != PRIV_ALL);
	if (checkonly)
		return (PRIV_POLICY_ONLY(cr, priv, B_FALSE) ? 0 : EPERM);
	else
		return (PRIV_POLICY(cr, priv, B_FALSE, EPERM, NULL));
}

/*
 * Map network pseudo privileges to actual privileges.
 * So we don't need to recompile IP when we change the privileges.
 */
int
secpolicy_net(const cred_t *cr, int netpriv, boolean_t checkonly)
{
	int priv = PRIV_ALL;

	switch (netpriv) {
	case OP_CONFIG:
		priv = PRIV_SYS_NET_CONFIG;
		break;
	case OP_RAW:
		priv = PRIV_NET_RAWACCESS;
		break;
	case OP_PRIVPORT:
		priv = PRIV_NET_PRIVADDR;
		break;
	}
	ASSERT(priv != PRIV_ALL);
	if (checkonly)
		return (PRIV_POLICY_ONLY(cr, priv, B_FALSE) ? 0 : EPERM);
	else
		return (PRIV_POLICY(cr, priv, B_FALSE, EPERM, NULL));
}

/*
 * Checks for operations that are either client-only or are used by
 * both clients and servers.
 */
int
secpolicy_nfs(const cred_t *cr)
{
	return (PRIV_POLICY(cr, PRIV_SYS_NFS, B_FALSE, EPERM, NULL));
}

/*
 * Special case for opening rpcmod: have NFS privileges or network
 * config privileges.
 */
int
secpolicy_rpcmod_open(const cred_t *cr)
{
	if (PRIV_POLICY_ONLY(cr, PRIV_SYS_NFS, B_FALSE))
		return (secpolicy_nfs(cr));
	else
		return (secpolicy_net_config(cr, NULL));
}

int
secpolicy_chroot(const cred_t *cr)
{
	return (PRIV_POLICY(cr, PRIV_PROC_CHROOT, B_FALSE, EPERM, NULL));
}

int
secpolicy_tasksys(const cred_t *cr)
{
	return (PRIV_POLICY(cr, PRIV_PROC_TASKID, B_FALSE, EPERM, NULL));
}

int
secpolicy_meminfo(const cred_t *cr)
{
	return (PRIV_POLICY(cr, PRIV_PROC_MEMINFO, B_FALSE, EPERM, NULL));
}

int
secpolicy_fs_import(const cred_t *cr)
{
	return (PRIV_POLICY(cr, PRIV_SYS_FS_IMPORT, B_FALSE, EPERM, NULL));
}


int
secpolicy_pfexec_register(const cred_t *cr)
{
	return (PRIV_POLICY(cr, PRIV_SYS_ADMIN, B_TRUE, EPERM, NULL));
}

/*
 * Basic privilege checks.
 */
int
secpolicy_basic_exec(const cred_t *cr, vnode_t *vp)
{
	FAST_BASIC_CHECK(cr, PRIV_PROC_EXEC);

	return (priv_policy_va(cr, PRIV_PROC_EXEC, B_FALSE, EPERM, NULL,
	    KLPDARG_VNODE, vp, (char *)NULL, KLPDARG_NOMORE));
}

int
secpolicy_basic_fork(const cred_t *cr)
{
	FAST_BASIC_CHECK(cr, PRIV_PROC_FORK);

	return (PRIV_POLICY(cr, PRIV_PROC_FORK, B_FALSE, EPERM, NULL));
}

int
secpolicy_basic_proc(const cred_t *cr)
{
	FAST_BASIC_CHECK(cr, PRIV_PROC_SESSION);

	return (PRIV_POLICY(cr, PRIV_PROC_SESSION, B_FALSE, EPERM, NULL));
}

/*
 * Slightly complicated because we don't want to trigger the policy too
 * often.  First we shortcircuit access to "self" (tp == sp) or if
 * we don't have the privilege but if we have permission
 * just return (0) and we don't flag the privilege as needed.
 * Else, we test for the privilege because we either have it or need it.
 */
int
secpolicy_basic_procinfo(const cred_t *cr, proc_t *tp, proc_t *sp)
{
	if (tp == sp ||
	    !HAS_PRIVILEGE(cr, PRIV_PROC_INFO) && prochasprocperm(tp, sp, cr)) {
		return (0);
	} else {
		return (PRIV_POLICY(cr, PRIV_PROC_INFO, B_FALSE, EPERM, NULL));
	}
}

int
secpolicy_basic_link(const cred_t *cr)
{
	FAST_BASIC_CHECK(cr, PRIV_FILE_LINK_ANY);

	return (PRIV_POLICY(cr, PRIV_FILE_LINK_ANY, B_FALSE, EPERM, NULL));
}

int
secpolicy_basic_net_access(const cred_t *cr)
{
	FAST_BASIC_CHECK(cr, PRIV_NET_ACCESS);

	return (PRIV_POLICY(cr, PRIV_NET_ACCESS, B_FALSE, EACCES, NULL));
}

/* ARGSUSED */
int
secpolicy_basic_file_read(const cred_t *cr, vnode_t *vp, const char *pn)
{
	FAST_BASIC_CHECK(cr, PRIV_FILE_READ);

	return (priv_policy_va(cr, PRIV_FILE_READ, B_FALSE, EACCES, NULL,
	    KLPDARG_VNODE, vp, (char *)pn, KLPDARG_NOMORE));
}

/* ARGSUSED */
int
secpolicy_basic_file_write(const cred_t *cr, vnode_t *vp, const char *pn)
{
	FAST_BASIC_CHECK(cr, PRIV_FILE_WRITE);

	return (priv_policy_va(cr, PRIV_FILE_WRITE, B_FALSE, EACCES, NULL,
	    KLPDARG_VNODE, vp, (char *)pn, KLPDARG_NOMORE));
}

/*
 * Additional device protection.
 *
 * Traditionally, a device has specific permissions on the node in
 * the filesystem which govern which devices can be opened by what
 * processes.  In certain cases, it is desirable to add extra
 * restrictions, as writing to certain devices is identical to
 * having a complete run of the system.
 *
 * This mechanism is called the device policy.
 *
 * When a device is opened, its policy entry is looked up in the
 * policy cache and checked.
 */
int
secpolicy_spec_open(const cred_t *cr, struct vnode *vp, int oflag)
{
	devplcy_t *plcy;
	int err;
	struct snode *csp = VTOS(common_specvp(vp));
	priv_set_t pset;

	mutex_enter(&csp->s_lock);

	if (csp->s_plcy == NULL || csp->s_plcy->dp_gen != devplcy_gen) {
		plcy = devpolicy_find(vp);
		if (csp->s_plcy)
			dpfree(csp->s_plcy);
		csp->s_plcy = plcy;
		ASSERT(plcy != NULL);
	} else
		plcy = csp->s_plcy;

	if (plcy == nullpolicy) {
		mutex_exit(&csp->s_lock);
		return (0);
	}

	dphold(plcy);

	mutex_exit(&csp->s_lock);

	if (oflag & FWRITE)
		pset = plcy->dp_wrp;
	else
		pset = plcy->dp_rdp;
	/*
	 * Special case:
	 * PRIV_SYS_NET_CONFIG is a superset of PRIV_SYS_IP_CONFIG.
	 * If PRIV_SYS_NET_CONFIG is present and PRIV_SYS_IP_CONFIG is
	 * required, replace PRIV_SYS_IP_CONFIG with PRIV_SYS_NET_CONFIG
	 * in the required privilege set before doing the check.
	 */
	if (priv_ismember(&pset, PRIV_SYS_IP_CONFIG) &&
	    priv_ismember(&CR_OEPRIV(cr), PRIV_SYS_NET_CONFIG) &&
	    !priv_ismember(&CR_OEPRIV(cr), PRIV_SYS_IP_CONFIG)) {
		priv_delset(&pset, PRIV_SYS_IP_CONFIG);
		priv_addset(&pset, PRIV_SYS_NET_CONFIG);
	}

	err = secpolicy_require_set(cr, &pset, "devpolicy", KLPDARG_NONE);
	dpfree(plcy);

	return (err);
}

int
secpolicy_modctl(const cred_t *cr, int cmd)
{
	switch (cmd) {
	case MODINFO:
	case MODGETMAJBIND:
	case MODGETPATH:
	case MODGETPATHLEN:
	case MODGETNAME:
	case MODGETFBNAME:
	case MODGETDEVPOLICY:
	case MODGETDEVPOLICYBYNAME:
	case MODDEVT2INSTANCE:
	case MODSIZEOF_DEVID:
	case MODGETDEVID:
	case MODSIZEOF_MINORNAME:
	case MODGETMINORNAME:
	case MODGETDEVFSPATH_LEN:
	case MODGETDEVFSPATH:
	case MODGETDEVFSPATH_MI_LEN:
	case MODGETDEVFSPATH_MI:
		/* Unprivileged */
		return (0);
	case MODLOAD:
	case MODSETDEVPOLICY:
		return (secpolicy_require_set(cr, PRIV_FULLSET, NULL,
		    KLPDARG_NONE));
	default:
		return (secpolicy_sys_config(cr, B_FALSE));
	}
}

int
secpolicy_console(const cred_t *cr)
{
	return (PRIV_POLICY(cr, PRIV_SYS_DEVICES, B_FALSE, EPERM, NULL));
}

int
secpolicy_power_mgmt(const cred_t *cr)
{
	return (PRIV_POLICY(cr, PRIV_SYS_DEVICES, B_FALSE, EPERM, NULL));
}

/*
 * Simulate terminal input; another escalation of privileges avenue.
 */

int
secpolicy_sti(const cred_t *cr)
{
	return (secpolicy_require_set(cr, PRIV_FULLSET, NULL, KLPDARG_NONE));
}

boolean_t
secpolicy_net_reply_equal(const cred_t *cr)
{
	return (PRIV_POLICY(cr, PRIV_SYS_CONFIG, B_FALSE, EPERM, NULL));
}

int
secpolicy_swapctl(const cred_t *cr)
{
	return (PRIV_POLICY(cr, PRIV_SYS_CONFIG, B_FALSE, EPERM, NULL));
}

int
secpolicy_cpc_cpu(const cred_t *cr)
{
	return (PRIV_POLICY(cr, PRIV_CPC_CPU, B_FALSE, EACCES, NULL));
}

/*
 * secpolicy_contract_identity
 *
 * Determine if the subject may set the process contract FMRI value
 */
int
secpolicy_contract_identity(const cred_t *cr)
{
	return (PRIV_POLICY(cr, PRIV_CONTRACT_IDENTITY, B_FALSE, EPERM, NULL));
}

/*
 * secpolicy_contract_observer
 *
 * Determine if the subject may observe a specific contract's events.
 */
int
secpolicy_contract_observer(const cred_t *cr, struct contract *ct)
{
	if (contract_owned(ct, cr, B_FALSE))
		return (0);
	return (PRIV_POLICY(cr, PRIV_CONTRACT_OBSERVER, B_FALSE, EPERM, NULL));
}

/*
 * secpolicy_contract_observer_choice
 *
 * Determine if the subject may observe any contract's events.  Just
 * tests privilege and audits on success.
 */
boolean_t
secpolicy_contract_observer_choice(const cred_t *cr)
{
	return (PRIV_POLICY_CHOICE(cr, PRIV_CONTRACT_OBSERVER, B_FALSE));
}

/*
 * secpolicy_contract_event
 *
 * Determine if the subject may request critical contract events or
 * reliable contract event delivery.
 */
int
secpolicy_contract_event(const cred_t *cr)
{
	return (PRIV_POLICY(cr, PRIV_CONTRACT_EVENT, B_FALSE, EPERM, NULL));
}

/*
 * secpolicy_contract_event_choice
 *
 * Determine if the subject may retain contract events in its critical
 * set when a change in other terms would normally require a change in
 * the critical set.  Just tests privilege and audits on success.
 */
boolean_t
secpolicy_contract_event_choice(const cred_t *cr)
{
	return (PRIV_POLICY_CHOICE(cr, PRIV_CONTRACT_EVENT, B_FALSE));
}

/*
 * secpolicy_gart_access
 *
 * Determine if the subject has sufficient priveleges to make ioctls to agpgart
 * device.
 */
int
secpolicy_gart_access(const cred_t *cr)
{
	return (PRIV_POLICY(cr, PRIV_GRAPHICS_ACCESS, B_FALSE, EPERM, NULL));
}

/*
 * secpolicy_gart_map
 *
 * Determine if the subject has sufficient priveleges to map aperture range
 * through agpgart driver.
 */
int
secpolicy_gart_map(const cred_t *cr)
{
	if (PRIV_POLICY_ONLY(cr, PRIV_GRAPHICS_ACCESS, B_FALSE)) {
		return (PRIV_POLICY(cr, PRIV_GRAPHICS_ACCESS, B_FALSE, EPERM,
		    NULL));
	} else {
		return (PRIV_POLICY(cr, PRIV_GRAPHICS_MAP, B_FALSE, EPERM,
		    NULL));
	}
}

/*
 * secpolicy_zinject
 *
 * Determine if the subject can inject faults in the ZFS fault injection
 * framework.  Requires all privileges.
 */
int
secpolicy_zinject(const cred_t *cr)
{
	return (secpolicy_require_set(cr, PRIV_FULLSET, NULL, KLPDARG_NONE));
}

/*
 * secpolicy_zfs
 *
 * Determine if the subject has permission to manipulate ZFS datasets
 * (not pools).  Equivalent to the SYS_MOUNT privilege.
 */
int
secpolicy_zfs(const cred_t *cr)
{
	return (PRIV_POLICY(cr, PRIV_SYS_MOUNT, B_FALSE, EPERM, NULL));
}

/*
 * secpolicy_idmap
 *
 * Determine if the calling process has permissions to register an SID
 * mapping daemon and allocate ephemeral IDs.
 */
int
secpolicy_idmap(const cred_t *cr)
{
	return (PRIV_POLICY(cr, PRIV_FILE_SETID, B_TRUE, EPERM, NULL));
}

/*
 * secpolicy_ucode_update
 *
 * Determine if the subject has sufficient privilege to update microcode.
 */
int
secpolicy_ucode_update(const cred_t *scr)
{
	return (PRIV_POLICY(scr, PRIV_ALL, B_FALSE, EPERM, NULL));
}

/*
 * secpolicy_sadopen
 *
 * Determine if the subject has sufficient privilege to access /dev/sad/admin.
 * /dev/sad/admin appear in global zone and exclusive-IP zones only.
 * In global zone, sys_config is required.
 * In exclusive-IP zones, sys_ip_config is required.
 * Note that sys_config is prohibited in non-global zones.
 */
int
secpolicy_sadopen(const cred_t *credp)
{
	priv_set_t pset;

	priv_emptyset(&pset);

	if (crgetzoneid(credp) == GLOBAL_ZONEID)
		priv_addset(&pset, PRIV_SYS_CONFIG);
	else
		priv_addset(&pset, PRIV_SYS_IP_CONFIG);

	return (secpolicy_require_set(credp, &pset, "devpolicy", KLPDARG_NONE));
}


/*
 * Add privileges to a particular privilege set; this is called when the
 * current sets of privileges are not sufficient.  I.e., we should always
 * call the policy override functions from here.
 * What we are allowed to have is in the Observed Permitted set; so
 * we compute the difference between that and the newset.
 */
int
secpolicy_require_privs(const cred_t *cr, const priv_set_t *nset)
{
	priv_set_t rqd;

	rqd = CR_OPPRIV(cr);

	priv_inverse(&rqd);
	priv_intersect(nset, &rqd);

	return (secpolicy_require_set(cr, &rqd, NULL, KLPDARG_NONE));
}

/*
 * secpolicy_smb
 *
 * Determine if the cred_t has PRIV_SYS_SMB privilege, indicating
 * that it has permission to access the smbsrv kernel driver.
 * PRIV_POLICY checks the privilege and audits the check.
 *
 * Returns:
 * 0       Driver access is allowed.
 * EPERM   Driver access is NOT permitted.
 */
int
secpolicy_smb(const cred_t *cr)
{
	return (PRIV_POLICY(cr, PRIV_SYS_SMB, B_FALSE, EPERM, NULL));
}

/*
 * secpolicy_vscan
 *
 * Determine if cred_t has the necessary privileges to access a file
 * for virus scanning and update its extended system attributes.
 * PRIV_FILE_DAC_SEARCH, PRIV_FILE_DAC_READ - file access
 * PRIV_FILE_FLAG_SET - set extended system attributes
 *
 * PRIV_POLICY checks the privilege and audits the check.
 *
 * Returns:
 * 0      file access for virus scanning allowed.
 * EPERM  file access for virus scanning is NOT permitted.
 */
int
secpolicy_vscan(const cred_t *cr)
{
	if ((PRIV_POLICY(cr, PRIV_FILE_DAC_SEARCH, B_FALSE, EPERM, NULL)) ||
	    (PRIV_POLICY(cr, PRIV_FILE_DAC_READ, B_FALSE, EPERM, NULL)) ||
	    (PRIV_POLICY(cr, PRIV_FILE_FLAG_SET, B_FALSE, EPERM, NULL))) {
		return (EPERM);
	}

	return (0);
}

/*
 * secpolicy_smbfs_login
 *
 * Determines if the caller can add and delete the smbfs login
 * password in the the nsmb kernel module for the CIFS client.
 *
 * Returns:
 * 0       access is allowed.
 * EPERM   access is NOT allowed.
 */
int
secpolicy_smbfs_login(const cred_t *cr, uid_t uid)
{
	uid_t cruid = crgetruid(cr);

	if (cruid == uid)
		return (0);
	return (PRIV_POLICY(cr, PRIV_PROC_OWNER, B_FALSE,
	    EPERM, NULL));
}

/*
 * secpolicy_xvm_control
 *
 * Determines if a caller can control the xVM hypervisor and/or running
 * domains (x86 specific).
 *
 * Returns:
 * 0       access is allowed.
 * EPERM   access is NOT allowed.
 */
int
secpolicy_xvm_control(const cred_t *cr)
{
	if (PRIV_POLICY(cr, PRIV_XVM_CONTROL, B_FALSE, EPERM, NULL))
		return (EPERM);
	return (0);
}

/*
 * secpolicy_ppp_config
 *
 * Determine if the subject has sufficient privileges to configure PPP and
 * PPP-related devices.
 */
int
secpolicy_ppp_config(const cred_t *cr)
{
	if (PRIV_POLICY_ONLY(cr, PRIV_SYS_NET_CONFIG, B_FALSE))
		return (secpolicy_net_config(cr, B_FALSE));
	return (PRIV_POLICY(cr, PRIV_SYS_PPP_CONFIG, B_FALSE, EPERM, NULL));
}

int
secpolicy_hyprlofs_control(const cred_t *cr)
{
	if (PRIV_POLICY(cr, PRIV_HYPRLOFS_CONTROL, B_FALSE, EPERM, NULL))
		return (EPERM);
	return (0);
}