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
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
|
.\"
.\" SPDX-License-Identifier: ISC
.\"
.\" Copyright (c) 2009-2023 Todd C. Miller <Todd.Miller@sudo.ws>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.Dd July 10, 2023
.Dt SUDO_PLUGIN @mansectform@
.Os Sudo @PACKAGE_VERSION@
.Sh NAME
.Nm sudo_plugin
.Nd Sudo Plugin API
.Sh DESCRIPTION
Starting with version 1.8,
.Nm sudo
supports a plugin API
for policy and session logging.
Plugins may be compiled as dynamic shared objects (the default on
systems that support them) or compiled statically into the
.Nm sudo
binary itself.
By default, the
.Nm sudoers
plugin provides audit, security policy and I/O logging capabilities.
Via the plugin API,
.Nm sudo
can be configured to use alternate plugins provided by third parties.
The plugins to be used are specified in the
.Xr sudo.conf @mansectform@
file.
.Pp
The API is versioned with a major and minor number.
The minor version number is incremented when additions are made.
The major number is incremented when incompatible changes are made.
A plugin should be check the version passed to it and make sure that the
major version matches.
.Pp
The plugin API is defined by the
.In sudo_plugin.h
header file.
.Ss Policy plugin API
A policy plugin must declare and populate a
.Vt struct policy_plugin
in the global scope.
This structure contains pointers to the functions that implement the
.Nm sudo
policy checks.
The name of the symbol should be specified in
.Xr sudo.conf @mansectform@
along with a path to the plugin so that
.Nm sudo
can load it.
.Bd -literal
struct policy_plugin {
#define SUDO_POLICY_PLUGIN 1
unsigned int type; /* always SUDO_POLICY_PLUGIN */
unsigned int version; /* always SUDO_API_VERSION */
int (*open)(unsigned int version, sudo_conv_t conversation,
sudo_printf_t sudo_plugin_printf, char * const settings[],
char * const user_info[], char * const user_env[],
char * const plugin_options[], const char **errstr);
void (*close)(int exit_status, int error);
int (*show_version)(int verbose);
int (*check_policy)(int argc, char * const argv[],
char *env_add[], char **command_info[],
char **argv_out[], char **user_env_out[], const char **errstr);
int (*list)(int argc, char * const argv[], int verbose,
const char *user, const char **errstr);
int (*validate)(const char **errstr);
void (*invalidate)(int rmcred);
int (*init_session)(struct passwd *pwd, char **user_env[],
const char **errstr);
void (*register_hooks)(int version,
int (*register_hook)(struct sudo_hook *hook));
void (*deregister_hooks)(int version,
int (*deregister_hook)(struct sudo_hook *hook));
struct sudo_plugin_event * (*event_alloc)(void);
};
.Ed
.Pp
A
.Vt struct policy_plugin
has the following fields:
.Bl -tag -width 4n
.It Fa type
The
.Fa type
field should always be set to SUDO_POLICY_PLUGIN.
.It Fa version
The
.Fa version
field should be set to
.Dv SUDO_API_VERSION .
.Pp
This allows
.Nm sudo
to determine the API version the plugin was
built against.
.It Fa open
.Bd -literal -compact
int (*open)(unsigned int version, sudo_conv_t conversation,
sudo_printf_t sudo_plugin_printf, char * const settings[],
char * const user_info[], char * const user_env[],
char * const plugin_options[], const char **errstr);
.Ed
.Pp
Returns 1 on success, 0 on failure, \-1 if a general error occurred,
or \-2 if there was a usage error.
In the latter case,
.Nm sudo
will print a usage message before it exits.
If an error occurs, the plugin may optionally call the
.Fn conversation
or
.Fn sudo_plugin_printf
function with
.Dv SUDO_CONF_ERROR_MSG
to present additional error information to the user.
.Pp
The function arguments are as follows:
.Bl -tag -width 4n
.It Fa version
The version passed in by
.Nm sudo
allows the plugin to determine the
major and minor version number of the plugin API supported by
.Nm sudo .
.It Fa conversation
A pointer to the
.Fn conversation
function that can be used by the plugin to interact with the user (see
.Sx Conversation API
for details).
Returns 0 on success and \-1 on failure.
.It Fa sudo_plugin_printf
A pointer to a
.Fn printf Ns -style
function that may be used to display informational or error messages (see
.Sx Conversation API
for details).
Returns the number of characters printed on success and \-1 on failure.
.It Fa settings
A vector of user-supplied
.Nm sudo
settings in the form of
.Dq name=value
strings.
The vector is terminated by a
.Dv NULL
pointer.
These settings correspond to options the user specified when running
.Nm sudo .
As such, they will only be present when the corresponding option has
been specified on the command line.
.Pp
When parsing
.Fa settings ,
the plugin should split on the
.Sy first
equal sign
.Pq Ql =
since the
.Em name
field will never include one itself but the
.Em value
might.
.Pp
The following values may be set by
.Nm sudo :
.Bl -tag -width 4n
.It bsdauth_type=string
Authentication type, if specified by the
.Fl a
option, to use on
systems where
.Bx
authentication is supported.
.It closefrom=number
If specified, the user has requested via the
.Fl C
option that
.Nm sudo
close all files descriptors with a value of
.Em number
or higher.
The plugin may optionally pass this, or another value, back in the
.Fa command_info
list.
.It cmnd_chroot=string
The root directory (see
.Xr chroot 2 )
to run the command in, as specified by the user via the
.Fl R
option.
The plugin may ignore or restrict the user's ability to specify a new
root directory.
Only available starting with API version 1.16.
.It cmnd_cwd=string
The working directory to run the command in, as specified by the user via the
.Fl D
option.
The plugin may ignore or restrict the user's ability to specify a new
working directory.
Only available starting with API version 1.16.
.It debug_flags=string
A debug file path name followed by a space and a comma-separated
list of debug flags that correspond to the plugin's
.Em Debug
entry in
.Xr sudo.conf @mansectform@ ,
if there is one.
The flags are passed to the plugin exactly as they appear in
.Xr sudo.conf @mansectform@ .
The syntax used by
.Nm sudo
and the
.Nm sudoers
plugin is
.Em subsystem Ns @ Ns Em priority
but a plugin is free to use a different
format so long as it does not include a comma
.Pq Ql ,\& .
Prior to
.Nm sudo
1.8.12, there was no way to specify plugin-specific
.Em debug_flags
so the value was always the same as that used by the
.Nm sudo
front-end and did not include a path name, only the flags themselves.
As of version 1.7 of the plugin interface,
.Nm sudo
will only pass
.Em debug_flags
if
.Xr sudo.conf @mansectform@
contains a plugin-specific
.Em Debug
entry.
.It ignore_ticket=bool
Set to true if the user specified the
.Fl k
option along with a
command, indicating that the user wishes to ignore any cached
authentication credentials.
.Em implied_shell
to true.
This allows
.Nm sudo
with no arguments
to be used similarly to
.Xr su 1 .
If the plugin does not to support this usage, it may return a value of \-2
from the
.Fn check_policy
function, which will cause
.Nm sudo
to print a usage message and exit.
.It implied_shell=bool
If the user does not specify a program on the command line,
.Nm sudo
will pass the plugin the path to the user's shell and set
.Em implied_shell .
.It intercept_ptrace=bool
Indicates whether or not the system supports intercept
mode using
.Xr ptrace 2 .
This is currently only true for Linux systems that support
.Xr seccomp 2
filtering and the
.Dq trap
action.
Other systems will use a dynamic shared object to implement
intercept.
Only available starting with API version 1.19.
.It intercept_setid=bool
Indicates whether or not the system supports running set-user-ID
and set-group-ID binaries in intercept mode.
This is currently only true for Linux systems that support
.Xr seccomp 2
filtering and the
.Dq trap
action.
On systems that use a dynamic shared object to implement
intercept, the dynamic linker (ld.so or the equivalent)
will disable preloading of shared objects when executing a
set-user-ID or set-group-ID binary.
This will disable intercept mode for that program and any other
programs that it executes.
The policy plugin may refuse to execute a set-user-ID or set-group-ID
binary in intercept mode to avoid this.
Only available starting with API version 1.19.
.It login_class=string
.Bx
login class to use when setting resource limits and nice value,
if specified by the
.Fl c
option.
.It login_shell=bool
Set to true if the user specified the
.Fl i
option, indicating that
the user wishes to run a login shell.
.It max_groups=int
The maximum number of groups a user may belong to.
This will only be present if there is a corresponding setting in
.Xr sudo.conf @mansectform@ .
.It network_addrs=list
A space-separated list of IP network addresses and netmasks in the
form
.Dq addr/netmask ,
e.g.,
.Dq 192.168.1.2/255.255.255.0 .
The address and netmask pairs may be either IPv4 or IPv6, depending on
what the operating system supports.
If the address contains a colon
.Pq Ql :\& ,
it is an IPv6 address, else it is IPv4.
.It noninteractive=bool
Set to true if the user specified the
.Fl n
option, indicating that
.Nm sudo
should operate in non-interactive mode.
The plugin may reject a command run in non-interactive mode if user
interaction is required.
.It plugin_dir=string
The default plugin directory used by the
.Nm sudo
front-end.
This is the default directory set at compile time and may not
correspond to the directory the running plugin was loaded from.
It may be used by a plugin to locate support files.
.It plugin_path=string
The path name of plugin loaded by the
.Nm sudo
front-end.
The path name will be a fully-qualified unless the plugin was
statically compiled into
.Nm sudo .
.It preserve_environment=bool
Set to true if the user specified the
.Fl E
option, indicating that
the user wishes to preserve the environment.
.It preserve_groups=bool
Set to true if the user specified the
.Fl P
option, indicating that
the user wishes to preserve the group vector instead of setting it
based on the runas user.
.It progname=string
The command name that sudo was run as, typically
.Dq sudo
or
.Dq sudoedit .
.It prompt=string
The prompt to use when requesting a password, if specified via
the
.Fl p
option.
.It remote_host=string
The name of the remote host to run the command on, if specified via
the
.Fl h
option.
Support for running the command on a remote host is meant to be implemented
via a helper program that is executed in place of the user-specified command.
The
.Nm sudo
front-end is only capable of executing commands on the local host.
Only available starting with API version 1.4.
.It run_shell=bool
Set to true if the user specified the
.Fl s
option, indicating that the user wishes to run a shell.
.It runas_group=string
The group name or group-ID to run the command as, if specified via
the
.Fl g
option.
.It runas_user=string
The user name or user-ID to run the command as, if specified via the
.Fl u
option.
.It selinux_role=string
SELinux role to use when executing the command, if specified by
the
.Fl r
option.
.It selinux_type=string
SELinux type to use when executing the command, if specified by
the
.Fl t
option.
.It set_home=bool
Set to true if the user specified the
.Fl H
option.
If true, set the
.Ev HOME
environment variable to the target user's home directory.
.It sudoedit=bool
Set to true when the
.Fl e
option is specified or if invoked as
.Nm sudoedit .
The plugin shall substitute an editor into
.Fa argv
in the
.Fn check_policy
function or return \-2 with a usage error
if the plugin does not support
.Em sudoedit .
For more information, see the
.Fn check_policy
section.
.It timeout=string
Command timeout specified by the user via the
.Fl T
option.
Not all plugins support command timeouts and the ability of the
user to set a timeout may be restricted by policy.
The format of the timeout string is plugin-specific.
.It update_ticket=bool
Set to false if the user specified the
.Fl N
option, indicating that the user wishes to avoid updating any cached
authentication credentials.
Only available starting with API version 1.20.
.El
.Pp
Additional settings may be added in the future so the plugin should
silently ignore settings that it does not recognize.
.It Fa user_info
A vector of information about the user running the command in the form of
.Dq name=value
strings.
The vector is terminated by a
.Dv NULL
pointer.
.Pp
When parsing
.Fa user_info ,
the plugin should split on the
.Sy first
equal sign
.Pq Ql =
since the
.Em name
field will never include one
itself but the
.Em value
might.
.Pp
The following values may be set by
.Nm sudo :
.Bl -tag -width 4n
.It cols=int
The number of columns the user's terminal supports.
If there is no terminal device available, a default value of 80 is used.
.It cwd=string
The user's current working directory.
.It egid=gid_t
The effective group-ID of the user invoking
.Nm sudo .
.It euid=uid_t
The effective user-ID of the user invoking
.Nm sudo .
.It gid=gid_t
The real group-ID of the user invoking
.Nm sudo .
.It groups=list
The user's supplementary group list formatted as a string of
comma-separated group-IDs.
.It host=string
The local machine's hostname as returned by the
.Xr gethostname 2
system call.
.It lines=int
The number of lines the user's terminal supports.
If there is
no terminal device available, a default value of 24 is used.
.It pgid=int
The ID of the process group that the running
.Nm sudo
process is a member of.
Only available starting with API version 1.2.
.It pid=int
The process ID of the running
.Nm sudo
process.
Only available starting with API version 1.2.
.It ppid=int
The parent process ID of the running
.Nm sudo
process.
Only available starting with API version 1.2.
.It rlimit_as=soft,hard
The maximum size to which the process's address space may grow (in bytes),
if supported by the operating system.
The soft and hard limits are separated by a comma.
A value of
.Dq infinity
indicates that there is no limit.
Only available starting with API version 1.16.
.It rlimit_core=soft,hard
The largest size core dump file that may be created (in bytes).
The soft and hard limits are separated by a comma.
A value of
.Dq infinity
indicates that there is no limit.
Only available starting with API version 1.16.
.It rlimit_cpu=soft,hard
The maximum amount of CPU time that the process may use (in seconds).
The soft and hard limits are separated by a comma.
A value of
.Dq infinity
indicates that there is no limit.
Only available starting with API version 1.16.
.It rlimit_data=soft,hard
The maximum size of the data segment for the process (in bytes).
The soft and hard limits are separated by a comma.
A value of
.Dq infinity
indicates that there is no limit.
Only available starting with API version 1.16.
.It rlimit_fsize=soft,hard
The largest size file that the process may create (in bytes).
The soft and hard limits are separated by a comma.
A value of
.Dq infinity
indicates that there is no limit.
Only available starting with API version 1.16.
.It rlimit_locks=soft,hard
The maximum number of locks that the process may establish,
if supported by the operating system.
The soft and hard limits are separated by a comma.
A value of
.Dq infinity
indicates that there is no limit.
Only available starting with API version 1.16.
.It rlimit_memlock=soft,hard
The maximum size that the process may lock in memory (in bytes),
if supported by the operating system.
The soft and hard limits are separated by a comma.
A value of
.Dq infinity
indicates that there is no limit.
Only available starting with API version 1.16.
.It rlimit_nofile=soft,hard
The maximum number of files that the process may have open.
The soft and hard limits are separated by a comma.
A value of
.Dq infinity
indicates that there is no limit.
Only available starting with API version 1.16.
.It rlimit_nproc=soft,hard
The maximum number of processes that the user may run simultaneously.
The soft and hard limits are separated by a comma.
A value of
.Dq infinity
indicates that there is no limit.
Only available starting with API version 1.16.
.It rlimit_rss=soft,hard
The maximum size to which the process's resident set size may grow (in bytes).
The soft and hard limits are separated by a comma.
A value of
.Dq infinity
indicates that there is no limit.
Only available starting with API version 1.16.
.It rlimit_stack=soft,hard
The maximum size to which the process's stack may grow (in bytes).
The soft and hard limits are separated by a comma.
A value of
.Dq infinity
indicates that there is no limit.
Only available starting with API version 1.16.
.It sid=int
The session ID of the running
.Nm sudo
process or 0 if
.Nm sudo
is not part of a POSIX job control session.
Only available starting with API version 1.2.
.It tcpgid=int
The ID of the foreground process group associated with the terminal
device associated with the
.Nm sudo
process or 0 if there is no terminal present.
Only available starting with API version 1.2.
.It tty=string
The path to the user's terminal device.
If the user has no terminal device associated with the session,
the value will be empty, as in
.Ql tty= .
.It uid=uid_t
The real user-ID of the user invoking
.Nm sudo .
.It umask=octal
The invoking user's file creation mask.
Only available starting with API version 1.10.
.It user=string
The name of the user invoking
.Nm sudo .
.El
.It Fa user_env
The user's environment in the form of a
.Dv NULL Ns -terminated vector of
.Dq name=value
strings.
.Pp
When parsing
.Fa user_env ,
the plugin should split on the
.Sy first
equal sign
.Pq Ql =
since the
.Em name
field will never include one
itself but the
.Em value
might.
.It Fa plugin_options
Any (non-comment) strings immediately after the plugin path are
passed as arguments to the plugin.
These arguments are split on a white space boundary and are passed to
the plugin in the form of a
.Dv NULL Ns -terminated
array of strings.
If no arguments were
specified,
.Fa plugin_options
will be the
.Dv NULL
pointer.
.Pp
The
.Fa plugin_options
parameter is only available starting with
API version 1.2.
A plugin
.Sy must
check the API version specified
by the
.Nm sudo
front-end before using
.Fa plugin_options .
Failure to do so may result in a crash.
.It Fa errstr
If the
.Fn open
function returns a value other than 1, the plugin may
store a message describing the failure or error in
.Fa errstr .
The
.Nm sudo
front-end will then pass this value to any registered audit plugins.
The string stored in
.Fa errstr
must remain valid until the plugin's
.Fn close
function is called.
.Pp
The
.Fa errstr
parameter is only available starting with
API version 1.15.
A plugin
.Sy must
check the API version specified by the
.Nm sudo
front-end before using
.Fa errstr .
Failure to do so may result in a crash.
.El
.It Fa close
.Bd -literal -compact
void (*close)(int exit_status, int error);
.Ed
.Pp
The
.Fn close
function is called when
.Nm sudo
is finished, shortly before it exits.
Starting with API version 1.15,
.Fn close
is called regardless of whether or not a command was actually executed.
This makes it possible for plugins to perform cleanup even when a
command was not run.
It is not possible to tell whether a command was run based solely
on the arguments passed to the
.Fn close
function.
To determine if a command was actually run,
the plugin must keep track of whether or not the
.Fn check_policy
function returned successfully.
.Pp
The function arguments are as follows:
.Bl -tag -width 4n
.It Fa exit_status
The command's exit status, as returned by the
.Xr wait 2
system call, or zero if no command was run.
The value of
.Fa exit_status
is undefined if
.Fa error
is non-zero.
.It Fa error
If the command could not be executed, this is set to the value of
.Va errno
set by the
.Xr execve 2
system call.
The plugin is responsible for displaying error information via the
.Fn conversation
or
.Fn sudo_plugin_printf
function.
If the command was successfully executed, the value of
.Fa error
is zero.
.El
.Pp
If no
.Fn close
function is defined, no I/O logging plugins are loaded,
and neither the
.Em timeout
nor
.Em use_pty
options are set in the
.Fa command_info
list, the
.Nm sudo
front-end may execute the command directly instead of running
it as a child process.
.It Fa show_version
.Bd -literal -compact
int (*show_version)(int verbose);
.Ed
.Pp
The
.Fn show_version
function is called by
.Nm sudo
when the user specifies the
.Fl V
option.
The plugin may display its version information to the user via the
.Fn conversation
or
.Fn sudo_plugin_printf
function using
.Dv SUDO_CONV_INFO_MSG .
If the user requests detailed version information, the
.Fa verbose
flag will be non-zero.
.Pp
Returns 1 on success, 0 on failure, \-1 if a general error occurred,
or \-2 if there was a usage error, although the return value is currently
ignored.
.It Fa check_policy
.Bd -literal -compact
int (*check_policy)(int argc, char * const argv[], char *env_add[],
char **command_info[], char **argv_out[], char **user_env_out[],
const char **errstr);
.Ed
.Pp
The
.Fn check_policy
function is called by
.Nm sudo
to determine
whether the user is allowed to run the specified commands.
.Pp
If the
.Em sudoedit
option was enabled in the
.Fa settings
array passed to the
.Fn open
function, the user has requested
.Em sudoedit
mode.
.Em sudoedit
is a mechanism for editing one or more files
where an editor is run with the user's credentials instead of with
elevated privileges.
.Nm sudo
achieves this by creating user-writable
temporary copies of the files to be edited and then overwriting the
originals with the temporary copies after editing is complete.
If the plugin supports
.Em sudoedit ,
it must set
.Em sudoedit=true
in the
.Fa command_info
list.
The plugin is responsible for choosing the editor to be used,
potentially from a variable in the user's environment, such as
.Ev EDITOR ,
and should be stored in
.Fa argv_out
(environment variables may include command line options).
The files to be edited should be copied from
.Fa argv
to
.Fa argv_out ,
separated from the
editor and its arguments by a
.Ql --
element.
The
.Ql --
will be removed by
.Nm sudo
before the editor is executed.
The plugin may also set
.Em sudoedit_nfiles
to the number of files to be edited in the
.Fa command_info
list; this will only be used by the
.Nm sudo
front-end starting with API version 1.21.
.Pp
The
.Fn check_policy
function returns 1 if the command is allowed,
0 if not allowed, \-1 for a general error, or \-2 for a usage error
or if
.Em sudoedit
was specified but is unsupported by the plugin.
In the latter case,
.Nm sudo
will print a usage message before it
exits.
If an error occurs, the plugin may optionally call the
.Fn conversation
or
.Fn sudo_plugin_printf
function with
.Dv SUDO_CONF_ERROR_MSG
to present additional error information to the user.
.Pp
The function arguments are as follows:
.Bl -tag -width 4n
.It Fa argc
The number of elements in
.Fa argv ,
not counting the final
.Dv NULL
pointer.
.It Fa argv
The argument vector describing the command the user wishes to run,
in the same form as what would be passed to the
.Xr execve 2
system call.
The vector is terminated by a
.Dv NULL
pointer.
.It Fa env_add
Additional environment variables specified by the user on the command
line in the form of a
.Dv NULL Ns -terminated
vector of
.Dq name=value
strings.
The plugin may reject the command if one or more variables
are not allowed to be set, or it may silently ignore such variables.
.Pp
When parsing
.Fa env_add ,
the plugin should split on the
.Sy first
equal sign
.Pq Ql =
since the
.Em name
field will never include one itself but the
.Em value
might.
.It Fa command_info
Information about the command being run in the form of
.Dq name=value
strings.
These values are used by
.Nm sudo
to set the execution environment when running a command.
The plugin is responsible for creating and populating the vector,
which must be terminated with a
.Dv NULL
pointer.
The following values are recognized by
.Nm sudo :
.Bl -tag -width 4n
.It apparmor_profile=string
AppArmor profile to transition to when executing the command.
Only available starting with API version 1.19.
.It chroot=string
The root directory to use when running the command.
.It closefrom=number
If specified,
.Nm sudo
will close all files descriptors with a value
of
.Em number
or higher.
.It command=string
Fully qualified path to the command to be executed.
.It cwd=string
The current working directory to change to when executing the command.
If
.Nm sudo
is unable to change to the new working directory, the command will
not be run unless
.Em cwd_optional
is also set (see below).
.It cwd_optional=bool
If set,
.Nm sudo
will treat an inability to change to the new working directory as a
non-fatal error.
This setting has no effect unless
.Em cwd
is also set.
.It exec_background=bool
By default,
.Nm sudo
runs a command as the foreground process as long as
.Nm sudo
itself is running in the foreground.
When
.Em exec_background
is enabled and the command is being run in a pseudo-terminal
(due to I/O logging or the
.Em use_pty
setting), the command will be run as a background process.
Attempts to read from the controlling terminal (or to change terminal
settings) will result in the command being suspended with the
.Dv SIGTTIN
signal (or
.Dv SIGTTOU
in the case of terminal settings).
If this happens when
.Nm sudo
is a foreground process, the command will be granted the controlling terminal
and resumed in the foreground with no user intervention required.
The advantage of initially running the command in the background is that
.Nm sudo
need not read from the terminal unless the command explicitly requests it.
Otherwise, any terminal input must be passed to the command, whether it
has required it or not (the kernel buffers terminals so it is not possible
to tell whether the command really wants the input).
This is different from historic
.Nm sudo
behavior or when the command is not being run in a pseudo-terminal.
.Pp
For this to work seamlessly, the operating system must support the
automatic restarting of system calls.
Unfortunately, not all operating systems do this by default,
and even those that do may have bugs.
For example, macOS fails to restart the
.Fn tcgetattr
and
.Fn tcsetattr
system calls (this is a bug in macOS).
Furthermore, because this behavior depends on the command stopping with the
.Dv SIGTTIN
or
.Dv SIGTTOU
signals, programs that catch these signals and suspend themselves
with a different signal (usually
.Dv SIGTOP )
will not be automatically foregrounded.
Some versions of the linux
.Xr su 1
command behave this way.
Because of this, a plugin should not set
.Em exec_background
unless it is explicitly enabled by the administrator and there should
be a way to enabled or disable it on a per-command basis.
.Pp
This setting has no effect unless I/O logging is enabled or
.Em use_pty
is enabled.
.It execfd=number
If specified,
.Nm sudo
will use the
.Xr fexecve 2
system call to execute the command instead of
.Xr execve 2 .
The specified
.Em number
must refer to an open file descriptor.
.It intercept=bool
If set,
.Nm sudo
will intercept attempts to execute a subsequent command and perform
a policy check via the policy plugin's
.Fn check_policy
function to determine whether or not the command is permitted.
This can be used to prevent shell escapes on supported platforms
but it has a number of limitations.
See
.Sy Preventing shell escapes
in
.Xr sudoers @mansectform@
for details.
Only available starting with API version 1.18.
.It intercept_verify=bool
If set,
.Nm sudo
will attempt to verify that a command run in intercept mode has the
expected path name, command line arguments and environment.
This setting has no effect unless
.Em use_ptrace
is also enabled.
Only available starting with API version 1.20.
.It iolog_compress=bool
Set to true if the I/O logging plugins, if any, should compress the
log data.
This is a hint to the I/O logging plugin which may choose to ignore it.
.It iolog_group=string
The group that will own newly created I/O log files and directories.
This is a hint to the I/O logging plugin which may choose to ignore it.
.It iolog_mode=octal
The file permission mode to use when creating I/O log files and directories.
This is a hint to the I/O logging plugin which may choose to ignore it.
.It iolog_user=string
The user that will own newly created I/O log files and directories.
This is a hint to the I/O logging plugin which may choose to ignore it.
.It iolog_path=string
Fully qualified path to the file or directory in which I/O log is
to be stored.
This is a hint to the I/O logging plugin which may choose to ignore it.
If no I/O logging plugin is loaded, this setting has no effect.
.It iolog_stdin=bool
Set to true if the I/O logging plugins, if any, should log the
standard input if it is not connected to a terminal device.
This is a hint to the I/O logging plugin which may choose to ignore it.
.It iolog_stdout=bool
Set to true if the I/O logging plugins, if any, should log the
standard output if it is not connected to a terminal device.
This is a hint to the I/O logging plugin which may choose to ignore it.
.It iolog_stderr=bool
Set to true if the I/O logging plugins, if any, should log the
standard error if it is not connected to a terminal device.
This is a hint to the I/O logging plugin which may choose to ignore it.
.It iolog_ttyin=bool
Set to true if the I/O logging plugins, if any, should log all
terminal input.
This only includes input typed by the user and not from a pipe or
redirected from a file.
This is a hint to the I/O logging plugin which may choose to ignore it.
.It iolog_ttyout=bool
Set to true if the I/O logging plugins, if any, should log all
terminal output.
This only includes output to the screen, not output to a pipe or file.
This is a hint to the I/O logging plugin which may choose to ignore it.
.It login_class=string
.Bx
login class to use when setting resource limits and nice value (optional).
This option is only set on systems that support login classes.
.It nice=int
Nice value (priority) to use when executing the command.
The nice value, if specified, overrides the priority associated with the
.Em login_class
on
.Bx
systems.
.It log_subcmds=bool
If set,
.Nm sudo
will call the audit plugin's
.Fn accept
function to log when the command runs a subsequent command, if supported
by the system.
If
.Em intercept
is also specified,
.Em log_subcmds
will be ignored.
See
.Sy Preventing shell escapes
in
.Xr sudoers @mansectform@
for more information.
Only available starting with API version 1.18.
.It noexec=bool
If set, prevent the command from executing other programs.
.It preserve_fds=list
A comma-separated list of file descriptors that should be
preserved, regardless of the value of the
.Em closefrom
setting.
Only available starting with API version 1.5.
.It preserve_groups=bool
If set,
.Nm sudo
will preserve the user's group vector instead of
initializing the group vector based on
.Em runas_user .
.It rlimit_as=soft,hard
The maximum size to which the process's address space may grow (in bytes),
if supported by the operating system.
The soft and hard limits are separated by a comma.
If only a single value is specified, both the hard and soft limits are set.
A value of
.Dq infinity
indicates that there is no limit.
A value of
.Dq user
will cause the invoking user's resource limit to be preserved.
A value of
.Dq default
will cause the target user's default resource limit to be used
on systems that allow per-user resource limits to be configured.
Only available starting with API version 1.18.
.It rlimit_core=soft,hard
The largest size core dump file that may be created (in bytes).
The soft and hard limits are separated by a comma.
If only a single value is specified, both the hard and soft limits are set.
A value of
.Dq infinity
indicates that there is no limit.
A value of
.Dq user
will cause the invoking user's resource limit to be preserved.
A value of
.Dq default
will cause the target user's default resource limit to be used
on systems that allow per-user resource limits to be configured.
Only available starting with API version 1.18.
.It rlimit_cpu=soft,hard
The maximum amount of CPU time that the process may use (in seconds).
The soft and hard limits are separated by a comma.
If only a single value is specified, both the hard and soft limits are set.
A value of
.Dq infinity
indicates that there is no limit.
A value of
.Dq user
will cause the invoking user's resource limit to be preserved.
A value of
.Dq default
will cause the target user's default resource limit to be used
on systems that allow per-user resource limits to be configured.
Only available starting with API version 1.18.
.It rlimit_data=soft,hard
The maximum size of the data segment for the process (in bytes).
The soft and hard limits are separated by a comma.
If only a single value is specified, both the hard and soft limits are set.
A value of
.Dq infinity
indicates that there is no limit.
A value of
.Dq user
will cause the invoking user's resource limit to be preserved.
A value of
.Dq default
will cause the target user's default resource limit to be used
on systems that allow per-user resource limits to be configured.
Only available starting with API version 1.18.
.It rlimit_fsize=soft,hard
The largest size file that the process may create (in bytes).
The soft and hard limits are separated by a comma.
If only a single value is specified, both the hard and soft limits are set.
A value of
.Dq infinity
indicates that there is no limit.
A value of
.Dq user
will cause the invoking user's resource limit to be preserved.
A value of
.Dq default
will cause the target user's default resource limit to be used
on systems that allow per-user resource limits to be configured.
Only available starting with API version 1.18.
.It rlimit_locks=soft,hard
The maximum number of locks that the process may establish,
if supported by the operating system.
The soft and hard limits are separated by a comma.
If only a single value is specified, both the hard and soft limits are set.
A value of
.Dq infinity
indicates that there is no limit.
A value of
.Dq user
will cause the invoking user's resource limit to be preserved.
A value of
.Dq default
will cause the target user's default resource limit to be used
on systems that allow per-user resource limits to be configured.
Only available starting with API version 1.18.
.It rlimit_memlock=soft,hard
The maximum size that the process may lock in memory (in bytes),
if supported by the operating system.
The soft and hard limits are separated by a comma.
If only a single value is specified, both the hard and soft limits are set.
A value of
.Dq infinity
indicates that there is no limit.
A value of
.Dq user
will cause the invoking user's resource limit to be preserved.
A value of
.Dq default
will cause the target user's default resource limit to be used
on systems that allow per-user resource limits to be configured.
Only available starting with API version 1.18.
.It rlimit_nofile=soft,hard
The maximum number of files that the process may have open.
The soft and hard limits are separated by a comma.
If only a single value is specified, both the hard and soft limits are set.
A value of
.Dq infinity
indicates that there is no limit.
A value of
.Dq user
will cause the invoking user's resource limit to be preserved.
A value of
.Dq default
will cause the target user's default resource limit to be used
on systems that allow per-user resource limits to be configured.
Only available starting with API version 1.18.
.It rlimit_nproc=soft,hard
The maximum number of processes that the user may run simultaneously.
The soft and hard limits are separated by a comma.
If only a single value is specified, both the hard and soft limits are set.
A value of
.Dq infinity
indicates that there is no limit.
A value of
.Dq user
will cause the invoking user's resource limit to be preserved.
A value of
.Dq default
will cause the target user's default resource limit to be used
on systems that allow per-user resource limits to be configured.
Only available starting with API version 1.18.
.It rlimit_rss=soft,hard
The maximum size to which the process's resident set size may grow (in bytes).
The soft and hard limits are separated by a comma.
If only a single value is specified, both the hard and soft limits are set.
A value of
.Dq infinity
indicates that there is no limit.
A value of
.Dq user
will cause the invoking user's resource limit to be preserved.
A value of
.Dq default
will cause the target user's default resource limit to be used
on systems that allow per-user resource limits to be configured.
Only available starting with API version 1.18.
.It rlimit_stack=soft,hard
The maximum size to which the process's stack may grow (in bytes).
The soft and hard limits are separated by a comma.
If only a single value is specified, both the hard and soft limits are set.
A value of
.Dq infinity
indicates that there is no limit.
A value of
.Dq user
will cause the invoking user's resource limit to be preserved.
A value of
.Dq default
will cause the target user's default resource limit to be used
on systems that allow per-user resource limits to be configured.
Only available starting with API version 1.18.
.It runas_egid=gid
Effective group-ID to run the command as.
If not specified, the value of
.Em runas_gid
is used.
.It runas_euid=uid
Effective user-ID to run the command as.
If not specified, the value of
.Em runas_uid
is used.
.It runas_gid=gid
Group-ID to run the command as.
.It runas_group=string
The name of the group the command will run as, if it is different
from the
.Em runas_user Ns 's
default group.
This value is provided for auditing purposes only, the
.Nm sudo
front-end uses
.Em runas_egid
and
.Em runas_gid
when executing the command.
.It runas_groups=list
The supplementary group vector to use for the command in the form
of a comma-separated list of group-IDs.
If
.Em preserve_groups
is set, this option is ignored.
.It runas_uid=uid
User-ID to run the command as.
.It runas_user=string
The name of the user the command will run as, which should correspond to
.Em runas_euid
(or
.Em runas_uid
if
.Em runas_euid
is not set).
This value is provided for auditing purposes only, the
.Nm sudo
front-end uses
.Em runas_euid
and
.Em runas_uid
when executing the command.
.It selinux_role=string
SELinux role to use when executing the command.
.It selinux_type=string
SELinux type to use when executing the command.
.It set_utmp=bool
Create a utmp (or utmpx) entry when a pseudo-terminal is allocated.
By default, the new entry will be a copy of the user's existing utmp
entry (if any), with the tty, time, type, and pid fields updated.
.It sudoedit=bool
Set to true when in
.Em sudoedit
mode.
The plugin may enable
.Em sudoedit
mode even if
.Nm sudo
was not invoked as
.Nm sudoedit .
This allows the plugin to perform command substitution and transparently
enable
.Em sudoedit
when the user attempts to run an editor.
.It sudoedit_checkdir=bool
Set to false to disable directory writability checks in
.Nm sudoedit .
By default,
.Nm sudoedit
1.8.16 and higher will check all directory components of the path to be
edited for writability by the invoking user.
Symbolic links will not be followed in writable directories and
.Nm sudoedit
will refuse to edit a file located in a writable directory.
These restrictions are not enforced when
.Nm sudoedit
is run by root.
The
.Em sudoedit_checkdir
option can be set to false to disable this check.
Only available starting with API version 1.8.
.It sudoedit_follow=bool
Set to true to allow
.Nm sudoedit
to edit files that are symbolic links.
By default,
.Nm sudoedit
1.8.15 and higher will refuse to open a symbolic link.
The
.Em sudoedit_follow
option can be used to restore the older behavior and allow
.Nm sudoedit
to open symbolic links.
Only available starting with API version 1.8.
.It sudoedit_nfiles=number
The number of files to be edited by the user.
If present, this is will be used by the
.Nm sudo
front-end to determine which elements of the
.Fa argv_out
vector are files to be edited.
The
.Ql --
element must immediately precede the first file to be editied.
If
.Em sudoedit_nfiles
is not specified, the
.Nm sudo
front-end will use the position of the
.Ql --
element to determine where the file list begins.
Only available starting with API version 1.21.
.It timeout=int
Command timeout.
If non-zero then when the timeout expires the command will be killed.
.It umask=octal
The file creation mask to use when executing the command.
This value may be overridden by PAM or login.conf on some systems
unless the
.Em umask_override
option is also set.
.It umask_override=bool
Force the value specified by the
.Em umask
option to override any umask set by PAM or login.conf.
.It use_ptrace=bool
If set,
.Nm sudo
will use
.Xr ptrace 2
to implement intercept mode if supported by the system.
This setting has no effect unless
.Em intercept
is also set.
Only available starting with API version 1.19.
.It use_pty=bool
Allocate a pseudo-terminal to run the command in, regardless of whether
or not I/O logging is in use.
By default,
.Nm sudo
will only run
the command in a pseudo-terminal when an I/O log plugin is loaded.
.It utmp_user=string
User name to use when constructing a new utmp (or utmpx) entry when
.Em set_utmp
is enabled.
This option can be used to set the user field in the utmp entry to
the user the command runs as rather than the invoking user.
If not set,
.Nm sudo
will base the new entry on
the invoking user's existing entry.
.El
.Pp
Unsupported values will be ignored.
.It Fa argv_out
The
.Dv NULL Ns -terminated
argument vector to pass to the
.Xr execve 2
system call when executing the command.
The plugin is responsible for allocating and populating the vector.
.It Fa user_env_out
The
.Dv NULL Ns -terminated
environment vector to use when executing the command.
The plugin is responsible for allocating and populating the vector.
.It Fa errstr
If the
.Fn check_policy
function returns a value other than 1, the plugin may
store a message describing the failure or error in
.Fa errstr .
The
.Nm sudo
front-end will then pass this value to any registered audit plugins.
The string stored in
.Fa errstr
must remain valid until the plugin's
.Fn close
function is called.
.Pp
The
.Fa errstr
parameter is only available starting with
API version 1.15.
A plugin
.Sy must
check the API version specified by the
.Nm sudo
front-end before using
.Fa errstr .
Failure to do so may result in a crash.
.El
.It Fa list
.Bd -literal -compact
int (*list)(int argc, char * const argv[], int verbose,
const char *user, const char **errstr);
.Ed
.Pp
List available privileges for the invoking user.
Returns 1 on success, 0 on failure, and \-1 on error.
On error, the plugin may optionally call the
.Fn conversation
or
.Fn sudo_plugin_printf
function with
.Dv SUDO_CONF_ERROR_MSG
to present additional error information to
the user.
.Pp
Privileges should be output via the
.Fn conversation
or
.Fn sudo_plugin_printf
function using
.Dv SUDO_CONV_INFO_MSG .
.Pp
The function arguments are as follows:
.Bl -tag -width 4n
.It Fa argc
The number of elements in
.Fa argv ,
not counting the final
.Dv NULL
pointer.
.It Fa argv
If
.No non- Ns Dv NULL ,
an argument vector describing a command the user
wishes to check against the policy in the same form as what would
be passed to the
.Xr execve 2
system call.
If the command is permitted by the policy, the fully-qualified path
to the command should be displayed along with any command line arguments.
.It Fa verbose
Flag indicating whether to list in verbose mode or not.
.It Fa user
The name of a different user to list privileges for if the policy
allows it.
If
.Dv NULL ,
the plugin should list the privileges of the invoking user.
.It Fa errstr
If the
.Fn list
function returns a value other than 1, the plugin may
store a message describing the failure or error in
.Fa errstr .
The
.Nm sudo
front-end will then pass this value to any registered audit plugins.
The string stored in
.Fa errstr
must remain valid until the plugin's
.Fn close
function is called.
.Pp
The
.Fa errstr
parameter is only available starting with
API version 1.15.
A plugin
.Sy must
check the API version specified by the
.Nm sudo
front-end before using
.Fa errstr .
Failure to do so may result in a crash.
.El
.It Fa validate
.Bd -literal -compact
int (*validate)(const char **errstr);
.Ed
.Pp
The
.Fn validate
function is called when
.Nm sudo
is run with the
.Fl v
option.
For policy plugins such as
.Nm sudoers
that cache
authentication credentials, this function will validate and cache
the credentials.
.Pp
The
.Fn validate
function should be
.Dv NULL
if the plugin does not support credential caching.
.Pp
Returns 1 on success, 0 on failure, and \-1 on error.
On error, the plugin may optionally call the
.Fn conversation
or
.Fn sudo_plugin_printf
function with
.Dv SUDO_CONF_ERROR_MSG
to present additional
error information to the user.
.Pp
The function arguments are as follows:
.Bl -tag -width 4n
.It Va errstr
If the
.Fn validate
function returns a value other than 1, the plugin may
store a message describing the failure or error in
.Fa errstr .
The
.Nm sudo
front-end will then pass this value to any registered audit plugins.
The string stored in
.Fa errstr
must remain valid until the plugin's
.Fn close
function is called.
.Pp
The
.Fa errstr
parameter is only available starting with
API version 1.15.
A plugin
.Sy must
check the API version specified by the
.Nm sudo
front-end before using
.Fa errstr .
Failure to do so may result in a crash.
.El
.It Fa invalidate
.Bd -literal -compact
void (*invalidate)(int rmcred);
.Ed
.Pp
The
.Fn invalidate
function is called when
.Nm sudo
is run with the
.Fl k
or
.Fl K
option.
For policy plugins such as
.Nm sudoers
that
cache authentication credentials, this function will invalidate the
credentials.
If the
.Fa rmcred
flag is non-zero, the plugin may remove
the credentials instead of simply invalidating them.
.Pp
The
.Fn invalidate
function should be
.Dv NULL
if the plugin does not support credential caching.
.It Fa init_session
.Bd -literal -compact
int (*init_session)(struct passwd *pwd, char **user_env[],
const char **errstr);
.Ed
.Pp
The
.Fn init_session
function is called before
.Nm sudo
sets up the
execution environment for the command.
It is run in the parent
.Nm sudo
process before any user-ID or group-ID changes.
This can be used to perform session setup that is not supported by
.Fa command_info ,
such as opening the PAM session.
The
.Fn close
function can be
used to tear down the session that was opened by
.Fn init_session .
.Pp
Returns 1 on success, 0 on failure, and \-1 on error.
On error, the plugin may optionally call the
.Fn conversation
or
.Fn sudo_plugin_printf
function with
.Dv SUDO_CONF_ERROR_MSG
to present additional
error information to the user.
.Pp
The function arguments are as follows:
.Bl -tag -width 4n
.It Fa pwd
If the user-ID the command will run as was found in the password database,
.Fa pwd
will describe that user, otherwise it will be
.Dv NULL .
.It Fa user_env_out
The
.Dv NULL Ns -terminated
environment vector to use when executing the command.
This is the same string passed back to the front-end via the Policy Plugin's
.Fa user_env_out
parameter.
If the
.Fn init_session
function needs to modify the user environment, it should update the
pointer stored in
.Fa user_env_out .
The expected use case is to merge the contents of the PAM environment
(if any) with the contents of
.Fa user_env_out .
The
.Fa user_env_out
parameter is only available
starting with API version 1.2.
A plugin
.Sy must
check the API
version specified by the
.Nm sudo
front-end before using
.Fa user_env_out .
Failure to do so may result in a crash.
.It Fa errstr
If the
.Fn init_session
function returns a value other than 1, the plugin may
store a message describing the failure or error in
.Fa errstr .
The
.Nm sudo
front-end will then pass this value to any registered audit plugins.
The string stored in
.Fa errstr
must remain valid until the plugin's
.Fn close
function is called.
.Pp
The
.Fa errstr
parameter is only available starting with
API version 1.15.
A plugin
.Sy must
check the API version specified by the
.Nm sudo
front-end before using
.Fa errstr .
Failure to do so may result in a crash.
.El
.It Fa register_hooks
.Bd -literal -compact
void (*register_hooks)(int version,
int (*register_hook)(struct sudo_hook *hook));
.Ed
.Pp
The
.Fn register_hooks
function is called by the sudo front-end to
register any hooks the plugin needs.
If the plugin does not support hooks,
.Fa register_hooks
should be set to the
.Dv NULL
pointer.
.Pp
The
.Fa version
argument describes the version of the hooks API
supported by the
.Nm sudo
front-end.
.Pp
The
.Fn register_hook
function should be used to register any supported
hooks the plugin needs.
It returns 0 on success, 1 if the hook type is not supported, and \-1
if the major version in
.Vt struct sudo_hook
does not match the front-end's major hook API version.
.Pp
See the
.Sx Hook function API
section below for more information about hooks.
.Pp
The
.Fn register_hooks
function is only available starting
with API version 1.2.
If the
.Nm sudo
front-end doesn't support API
version 1.2 or higher,
.Fn register_hooks
will not be called.
.It Fa deregister_hooks
.Bd -literal -compact
void (*deregister_hooks)(int version,
int (*deregister_hook)(struct sudo_hook *hook));
.Ed
.Pp
The
.Fn deregister_hooks
function is called by the sudo front-end
to deregister any hooks the plugin has registered.
If the plugin does not support hooks,
.Fa deregister_hooks
should be set to the
.Dv NULL
pointer.
.Pp
The
.Fa version
argument describes the version of the hooks API
supported by the
.Nm sudo
front-end.
.Pp
The
.Fn deregister_hook
function should be used to deregister any
hooks that were put in place by the
.Fn register_hook
function.
If the plugin tries to deregister a hook that the front-end does not support,
.Fn deregister_hook
will return an error.
.Pp
See the
.Sx Hook function API
section below for more information about hooks.
.Pp
The
.Fn deregister_hooks
function is only available starting
with API version 1.2.
If the
.Nm sudo
front-end doesn't support API
version 1.2 or higher,
.Fn deregister_hooks
will not be called.
.It Fa event_alloc
.Bd -literal -compact
struct sudo_plugin_event * (*event_alloc)(void);
.Ed
.Pp
The
.Fn event_alloc
function is used to allocate a
.Vt struct sudo_plugin_event
which provides access to the main
.Nm sudo
event loop.
Unlike the other fields, the
.Fa event_alloc
pointer is filled in by the
.Nm sudo
front-end, not by the plugin.
.Pp
See the
.Sx Event API
section below for more information
about events.
.Pp
The
.Fn event_alloc
function is only available starting
with API version 1.15.
If the
.Nm sudo
front-end doesn't support API
version 1.15 or higher,
.Fa event_alloc
will not be set.
.El
.Pp
.Em Policy Plugin Version Macros
.Bd -literal
/* Plugin API version major/minor. */
#define SUDO_API_VERSION_MAJOR 1
#define SUDO_API_VERSION_MINOR 13
#define SUDO_API_MKVERSION(x, y) ((x << 16) | y)
#define SUDO_API_VERSION SUDO_API_MKVERSION(SUDO_API_VERSION_MAJOR,\e
SUDO_API_VERSION_MINOR)
/* Getters and setters for API version */
#define SUDO_API_VERSION_GET_MAJOR(v) ((v) >> 16)
#define SUDO_API_VERSION_GET_MINOR(v) ((v) & 0xffff)
#define SUDO_API_VERSION_SET_MAJOR(vp, n) do { \e
*(vp) = (*(vp) & 0x0000ffff) | ((n) << 16); \e
} while(0)
#define SUDO_API_VERSION_SET_MINOR(vp, n) do { \e
*(vp) = (*(vp) & 0xffff0000) | (n); \e
} while(0)
.Ed
.Ss I/O plugin API
.Bd -literal
struct io_plugin {
#define SUDO_IO_PLUGIN 2
unsigned int type; /* always SUDO_IO_PLUGIN */
unsigned int version; /* always SUDO_API_VERSION */
int (*open)(unsigned int version, sudo_conv_t conversation,
sudo_printf_t sudo_plugin_printf, char * const settings[],
char * const user_info[], char * const command_info[],
int argc, char * const argv[], char * const user_env[],
char * const plugin_options[], const char **errstr);
void (*close)(int exit_status, int error); /* wait status or error */
int (*show_version)(int verbose);
int (*log_ttyin)(const char *buf, unsigned int len,
const char **errstr);
int (*log_ttyout)(const char *buf, unsigned int len,
const char **errstr);
int (*log_stdin)(const char *buf, unsigned int len,
const char **errstr);
int (*log_stdout)(const char *buf, unsigned int len,
const char **errstr);
int (*log_stderr)(const char *buf, unsigned int len,
const char **errstr);
void (*register_hooks)(int version,
int (*register_hook)(struct sudo_hook *hook));
void (*deregister_hooks)(int version,
int (*deregister_hook)(struct sudo_hook *hook));
int (*change_winsize)(unsigned int lines, unsigned int cols,
const char **errstr);
int (*log_suspend)(int signo, const char **errstr);
struct sudo_plugin_event * (*event_alloc)(void);
};
.Ed
.Pp
When an I/O plugin is loaded,
.Nm sudo
runs the command in a pseudo-terminal.
This makes it possible to log the input and output from the user's
session.
If any of the standard input, standard output, or standard error do not
correspond to a tty,
.Nm sudo
will open a pipe to capture the I/O for logging before passing it on.
.Pp
The
.Fn log_ttyin
function receives the raw user input from the terminal
device (this will include input even when echo is disabled,
such as when a password is read).
The
.Fn log_ttyout
function receives output from the pseudo-terminal that is
suitable for replaying the user's session at a later time.
The
.Fn log_stdin ,
.Fn log_stdout ,
and
.Fn log_stderr
functions are only called if the standard input, standard output,
or standard error respectively correspond to something other than
a tty.
.Pp
Any of the logging functions may be set to the
.Dv NULL
pointer if no logging is to be performed.
If the open function returns 0, no I/O will be sent to the plugin.
.Pp
If a logging function returns an error
.Pq \-1 ,
the running command will be terminated and all of the plugin's logging
functions will be disabled.
Other I/O logging plugins will still receive any remaining
input or output that has not yet been processed.
.Pp
If an input logging function rejects the data by returning 0, the
command will be terminated and the data will not be passed to the
command, though it will still be sent to any other I/O logging plugins.
If an output logging function rejects the data by returning 0, the
command will be terminated and the data will not be written to the
terminal, though it will still be sent to any other I/O logging plugins.
.Pp
A
.Vt struct audit_plugin
has the following fields:
.Bl -tag -width 4n
.It Fa type
The
.Fa type
field should always be set to
.Dv SUDO_IO_PLUGIN .
.It Fa version
The
.Fa version
field should be set to
.Dv SUDO_API_VERSION .
.Pp
This allows
.Nm sudo
to determine the API version the plugin was
built against.
.It Fa open
.Bd -literal -compact
int (*open)(unsigned int version, sudo_conv_t conversation,
sudo_printf_t sudo_plugin_printf, char * const settings[],
char * const user_info[], char * const command_info[],
int argc, char * const argv[], char * const user_env[],
char * const plugin_options[]);
.Ed
.Pp
The
.Fn open
function is run before the
.Fn log_ttyin ,
.Fn log_ttyout ,
.Fn log_stdin ,
.Fn log_stdout ,
.Fn log_stderr ,
.Fn log_suspend ,
.Fn change_winsize ,
or
.Fn show_version
functions are called.
It is only called if the version is being requested or if the
policy plugin's
.Fn check_policy
function has returned successfully.
It returns 1 on success, 0 on failure, \-1 if a general error occurred,
or \-2 if there was a usage error.
In the latter case,
.Nm sudo
will print a usage message before it exits.
If an error occurs, the plugin may optionally call the
.Fn conversation
or
.Fn sudo_plugin_printf
function with
.Dv SUDO_CONF_ERROR_MSG
to present additional error information to the user.
.Pp
The function arguments are as follows:
.Bl -tag -width 4n
.It Fa version
The version passed in by
.Nm sudo
allows the plugin to determine the
major and minor version number of the plugin API supported by
.Nm sudo .
.It Fa conversation
A pointer to the
.Fn conversation
function that may be used by the
.Fn Fa show_version
function to display version information (see
.Fn show_version
below).
The
.Fn conversation
function may also be used to display additional error message to the user.
The
.Fn conversation
function returns 0 on success and \-1 on failure.
.It Fa sudo_plugin_printf
A pointer to a
.Fn printf Ns -style
function that may be used by the
.Fn show_version
function to display version information (see
show_version below).
The
.Fn sudo_plugin_printf
function may also be used to display additional error message to the user.
The
.Fn sudo_plugin_printf
function returns number of characters printed on success and \-1 on failure.
.It Fa settings
A vector of user-supplied
.Nm sudo
settings in the form of
.Dq name=value
strings.
The vector is terminated by a
.Dv NULL
pointer.
These settings correspond to options the user specified when running
.Nm sudo .
As such, they will only be present when the corresponding option has
been specified on the command line.
.Pp
When parsing
.Fa settings ,
the plugin should split on the
.Sy first
equal sign
.Pq Ql =
since the
.Em name
field will never include one
itself but the
.Em value
might.
.Pp
See the
.Sx Policy plugin API
section for a list of all possible settings.
.It Fa user_info
A vector of information about the user running the command in the form of
.Dq name=value
strings.
The vector is terminated by a
.Dv NULL
pointer.
.Pp
When parsing
.Fa user_info ,
the plugin should split on the
.Sy first
equal sign
.Pq Ql =
since the
.Em name
field will never include one
itself but the
.Em value
might.
.Pp
See the
.Sx Policy plugin API
section for a list of all possible strings.
.It Fa command_info
A vector of information describing the command being run in the form of
.Dq name=value
strings.
The vector is terminated by a
.Dv NULL
pointer.
.Pp
When parsing
.Fa command_info ,
the plugin should split on the
.Sy first
equal sign
.Pq Ql =
since the
.Em name
field will never include one
itself but the
.Em value
might.
.Pp
See the
.Sx Policy plugin API
section for a list of all possible strings.
.It Fa argc
The number of elements in
.Fa argv ,
not counting the final
.Dv NULL
pointer.
It can be zero, such as when
.Nm sudo
is called with the
.Fl V
option.
.It Fa argv
If
.No non- Ns Dv NULL ,
an argument vector describing a command the user
wishes to run in the same form as what would be passed to the
.Xr execve 2
system call.
.It Fa user_env
The user's environment in the form of a
.Dv NULL Ns -terminated
vector of
.Dq name=value
strings.
.Pp
When parsing
.Fa user_env ,
the plugin should split on the
.Sy first
equal sign
.Pq Ql =
since the
.Em name
field will never include one
itself but the
.Em value
might.
.It Fa plugin_options
Any (non-comment) strings immediately after the plugin path are
treated as arguments to the plugin.
These arguments are split on a white space boundary and are passed to
the plugin in the form of a
.Dv NULL Ns -terminated
array of strings.
If no arguments were specified,
.Fa plugin_options
will be the
.Dv NULL
pointer.
.Pp
The
.Fa plugin_options
parameter is only available starting with
API version 1.2.
A plugin
.Sy must
check the API version specified
by the
.Nm sudo
front-end before using
.Fa plugin_options .
Failure to do so may result in a crash.
.It Fa errstr
If the
.Fn open
function returns a value other than 1, the plugin may
store a message describing the failure or error in
.Fa errstr .
The
.Nm sudo
front-end will then pass this value to any registered audit plugins.
The string stored in
.Fa errstr
must remain valid until the plugin's
.Fn close
function is called.
.Pp
The
.Fa errstr
parameter is only available starting with
API version 1.15.
A plugin
.Sy must
check the API version specified by the
.Nm sudo
front-end before using
.Fa errstr .
Failure to do so may result in a crash.
.El
.It Fa close
.Bd -literal -compact
void (*close)(int exit_status, int error);
.Ed
.Pp
The
.Fn close
function is called when
.Nm sudo
is finished, shortly before it exits.
.Pp
The function arguments are as follows:
.Bl -tag -width 4n
.It Fa exit_status
The command's exit status, as returned by the
.Xr wait 2
system call, or zero if no command was run.
The value of
.Fa exit_status
is undefined if
.Fa error
is non-zero.
.It Fa error
If the command could not be executed, this is set to the value of
.Va errno
set by the
.Xr execve 2
system call.
If the command was successfully executed, the value of
.Fa error
is zero.
.El
.It Fa show_version
.Bd -literal -compact
int (*show_version)(int verbose);
.Ed
.Pp
The
.Fn show_version
function is called by
.Nm sudo
when the user specifies the
.Fl V
option.
The plugin may display its version information to the user via the
.Fn conversation
or
.Fn sudo_plugin_printf
function using
.Dv SUDO_CONV_INFO_MSG .
If the user requests detailed version information, the
.Fa verbose
flag will be non-zero.
.Pp
Returns 1 on success, 0 on failure, \-1 if a general error occurred,
or \-2 if there was a usage error, although the return value is currently
ignored.
.It Fa log_ttyin
.Bd -literal -compact
int (*log_ttyin)(const char *buf, unsigned int len,
const char **errstr);
.Ed
.Pp
The
.Fn log_ttyin
function is called whenever data can be read from
the user but before it is passed to the running command.
This allows the plugin to reject data if it chooses to (for instance
if the input contains banned content).
Returns 1 if the data should be passed to the command, 0 if the data
is rejected (which will terminate the running command), or \-1 if an
error occurred.
.Pp
The function arguments are as follows:
.Bl -tag -width 4n
.It Fa buf
The buffer containing user input.
.It Fa len
The length of
.Fa buf
in bytes.
.It Fa errstr
If the
.Fn log_ttyin
function returns a value other than 1, the plugin may
store a message describing the failure or error in
.Fa errstr .
The
.Nm sudo
front-end will then pass this value to any registered audit plugins.
The string stored in
.Fa errstr
must remain valid until the plugin's
.Fn close
function is called.
.Pp
The
.Fa errstr
parameter is only available starting with
API version 1.15.
A plugin
.Sy must
check the API version specified by the
.Nm sudo
front-end before using
.Fa errstr .
Failure to do so may result in a crash.
.El
.It Fa log_ttyout
.Bd -literal -compact
int (*log_ttyout)(const char *buf, unsigned int len,
const char **errstr);
.Ed
.Pp
The
.Fn log_ttyout
function is called whenever data can be read from
the command but before it is written to the user's terminal.
This allows the plugin to reject data if it chooses to (for instance
if the output contains banned content).
Returns 1 if the data should be passed to the user, 0 if the data is rejected
(which will terminate the running command), or \-1 if an error occurred.
.Pp
The function arguments are as follows:
.Bl -tag -width 4n
.It Fa buf
The buffer containing command output.
.It Fa len
The length of
.Fa buf
in bytes.
.It Fa errstr
If the
.Fn log_ttyout
function returns a value other than 1, the plugin may
store a message describing the failure or error in
.Fa errstr .
The
.Nm sudo
front-end will then pass this value to any registered audit plugins.
The string stored in
.Fa errstr
must remain valid until the plugin's
.Fn close
function is called.
.Pp
The
.Fa errstr
parameter is only available starting with
API version 1.15.
A plugin
.Sy must
check the API version specified by the
.Nm sudo
front-end before using
.Fa errstr .
Failure to do so may result in a crash.
.El
.It Fa log_stdin
.Bd -literal -compact
int (*log_stdin)(const char *buf, unsigned int len,
const char **errstr);
.Ed
.Pp
The
.Fn log_stdin
function is only used if the standard input does
not correspond to a tty device.
It is called whenever data can be read from the standard input but
before it is passed to the running command.
This allows the plugin to reject data if it chooses to
(for instance if the input contains banned content).
Returns 1 if the data should be passed to the command, 0 if the
data is rejected (which will terminate the running command), or \-1
if an error occurred.
.Pp
The function arguments are as follows:
.Bl -tag -width 4n
.It Fa buf
The buffer containing user input.
.It Fa len
The length of
.Fa buf
in bytes.
.It Fa errstr
If the
.Fn log_stdin
function returns a value other than 1, the plugin may
store a message describing the failure or error in
.Fa errstr .
The
.Nm sudo
front-end will then pass this value to any registered audit plugins.
The string stored in
.Fa errstr
must remain valid until the plugin's
.Fn close
function is called.
.Pp
The
.Fa errstr
parameter is only available starting with
API version 1.15.
A plugin
.Sy must
check the API version specified by the
.Nm sudo
front-end before using
.Fa errstr .
Failure to do so may result in a crash.
.El
.It Fa log_stdout
.Bd -literal -compact
int (*log_stdout)(const char *buf, unsigned int len,
const char **errstr);
.Ed
.Pp
The
.Fn log_stdout
function is only used if the standard output does not correspond
to a tty device.
It is called whenever data can be read from the command but before
it is written to the standard output.
This allows the plugin to reject data if it chooses to
(for instance if the output contains banned content).
Returns 1 if the data should be passed to the user, 0 if the data
is rejected (which will terminate the running command), or \-1 if
an error occurred.
.Pp
The function arguments are as follows:
.Bl -tag -width 4n
.It Fa buf
The buffer containing command output.
.It Fa len
The length of
.Fa buf
in bytes.
.It Fa errstr
If the
.Fn log_stdout
function returns a value other than 1, the plugin may
store a message describing the failure or error in
.Fa errstr .
The
.Nm sudo
front-end will then pass this value to any registered audit plugins.
The string stored in
.Fa errstr
must remain valid until the plugin's
.Fn close
function is called.
.Pp
The
.Fa errstr
parameter is only available starting with
API version 1.15.
A plugin
.Sy must
check the API version specified by the
.Nm sudo
front-end before using
.Fa errstr .
Failure to do so may result in a crash.
.El
.It Fa log_stderr
.Bd -literal -compact
int (*log_stderr)(const char *buf, unsigned int len,
const char **errstr);
.Ed
.Pp
The
.Fn log_stderr
function is only used if the standard error does
not correspond to a tty device.
It is called whenever data can be read from the command but before it
is written to the standard error.
This allows the plugin to reject data if it chooses to
(for instance if the output contains banned content).
Returns 1 if the data should be passed to the user, 0 if the data
is rejected (which will terminate the running command), or \-1 if
an error occurred.
.Pp
The function arguments are as follows:
.Bl -tag -width 4n
.It Fa buf
The buffer containing command output.
.It Fa len
The length of
.Fa buf
in bytes.
.It Fa errstr
If the
.Fn log_stderr
function returns a value other than 1, the plugin may
store a message describing the failure or error in
.Fa errstr .
The
.Nm sudo
front-end will then pass this value to any registered audit plugins.
The string stored in
.Fa errstr
must remain valid until the plugin's
.Fn close
function is called.
.Pp
The
.Fa errstr
parameter is only available starting with
API version 1.15.
A plugin
.Sy must
check the API version specified by the
.Nm sudo
front-end before using
.Fa errstr .
Failure to do so may result in a crash.
.El
.It Fa register_hooks
See the
.Sx Policy plugin API
section for a description of
.Fn register_hooks .
.It Fa deregister_hooks
See the
.Sx Policy plugin API
section for a description of
.Fn deregister_hooks .
.It Fa change_winsize
.Bd -literal -compact
int (*change_winsize)(unsigned int lines, unsigned int cols,
const char **errstr);
.Ed
.Pp
The
.Fn change_winsize
function is called whenever the window size of the terminal changes from
the initial values specified in the
.Fa user_info
list.
Returns \-1 if an error occurred, in which case no further calls to
.Fn change_winsize
will be made,
.Pp
The function arguments are as follows:
.Bl -tag -width 4n
.It Fa lines
The number of lines (rows) in the re-sized terminal.
.It Fa cols
The number of columns in the re-sized terminal.
.It Fa errstr
If the
.Fn change_winsize
function returns a value other than 1, the plugin may
store a message describing the failure or error in
.Fa errstr .
The
.Nm sudo
front-end will then pass this value to any registered audit plugins.
The string stored in
.Fa errstr
must remain valid until the plugin's
.Fn close
function is called.
.Pp
The
.Fa errstr
parameter is only available starting with
API version 1.15.
A plugin
.Sy must
check the API version specified by the
.Nm sudo
front-end before using
.Fa errstr .
Failure to do so may result in a crash.
.El
.It Fa log_suspend
.Bd -literal -compact
int (*log_suspend)(int signo, const char **errstr);
.Ed
.Pp
The
.Fn log_suspend
function is called whenever a command is suspended or resumed.
Logging this information makes it possible to skip the period of time when
the command was suspended during playback of a session.
Returns \-1 if an error occurred, in which case no further calls to
.Fn log_suspend
will be made,
.Pp
The function arguments are as follows:
.Bl -tag -width 4n
.It Fa signo
The signal that caused the command to be suspended, or
.Dv SIGCONT
if the command was resumed.
.It Fa errstr
If the
.Fn log_suspend
function returns a value other than 1, the plugin may
store a message describing the failure or error in
.Fa errstr .
The
.Nm sudo
front-end will then pass this value to any registered audit plugins.
The string stored in
.Fa errstr
must remain valid until the plugin's
.Fn close
function is called.
.Pp
The
.Fa errstr
parameter is only available starting with
API version 1.15.
A plugin
.Sy must
check the API version specified by the
.Nm sudo
front-end before using
.Fa errstr .
Failure to do so may result in a crash.
.It Fa event_alloc
.Bd -literal -compact
struct sudo_plugin_event * (*event_alloc)(void);
.Ed
.Pp
The
.Fn event_alloc
function is used to allocate a
.Vt struct sudo_plugin_event
which provides access to the main
.Nm sudo
event loop.
Unlike the other fields, the
.Fn event_alloc
pointer is filled in by the
.Nm sudo
front-end, not by the plugin.
.Pp
See the
.Sx Event API
section below for more information
about events.
.Pp
The
.Fn event_alloc
function is only available starting
with API version 1.15.
If the
.Nm sudo
front-end doesn't support API
version 1.15 or higher,
.Fn event_alloc
will not be set.
.El
.Pp
.Em I/O Plugin Version Macros
.Pp
Same as for the
.Sx Policy plugin API .
.El
.Ss Audit plugin API
.Bd -literal
/* Audit plugin close function status types. */
#define SUDO_PLUGIN_NO_STATUS 0
#define SUDO_PLUGIN_WAIT_STATUS 1
#define SUDO_PLUGIN_EXEC_ERROR 2
#define SUDO_PLUGIN_SUDO_ERROR 3
#define SUDO_AUDIT_PLUGIN 3
struct audit_plugin {
unsigned int type; /* always SUDO_AUDIT_PLUGIN */
unsigned int version; /* always SUDO_API_VERSION */
int (*open)(unsigned int version, sudo_conv_t conversation,
sudo_printf_t sudo_plugin_printf, char * const settings[],
char * const user_info[], int submit_optind,
char * const submit_argv[], char * const submit_envp[],
char * const plugin_options[], const char **errstr);
void (*close)(int status_type, int status);
int (*accept)(const char *plugin_name,
unsigned int plugin_type, char * const command_info[],
char * const run_argv[], char * const run_envp[],
const char **errstr);
int (*reject)(const char *plugin_name, unsigned int plugin_type,
const char *audit_msg, char * const command_info[],
const char **errstr);
int (*error)(const char *plugin_name, unsigned int plugin_type,
const char *audit_msg, char * const command_info[],
const char **errstr);
int (*show_version)(int verbose);
void (*register_hooks)(int version,
int (*register_hook)(struct sudo_hook *hook));
void (*deregister_hooks)(int version,
int (*deregister_hook)(struct sudo_hook *hook));
struct sudo_plugin_event * (*event_alloc)(void);
}
.Ed
.Pp
An audit plugin can be used to log successful and unsuccessful attempts
to run
.Nm sudo
independent of the policy or any I/O plugins.
Multiple audit plugins may be specified in
.Xr sudo.conf @mansectform@ .
.Pp
A
.Vt struct audit_plugin
has the following fields:
.Bl -tag -width 4n
.It Fa type
The
.Fa type
field should always be set to
.Dv SUDO_AUDIT_PLUGIN .
.It Fa version
The
.Fa version
field should be set to
.Dv SUDO_API_VERSION .
.Pp
This allows
.Nm sudo
to determine the API version the plugin was
built against.
.It Fa open
.Bd -literal -compact
int (*open)(unsigned int version, sudo_conv_t conversation,
sudo_printf_t sudo_plugin_printf, char * const settings[],
char * const user_info[], int submit_optind,
char * const submit_argv[], char * const submit_envp[],
char * const plugin_options[], const char **errstr);
.Ed
.Pp
The audit
.Fn open
function is run before any other
.Nm sudo
plugin API functions.
This makes it possible to audit failures in the other plugins.
It returns 1 on success, 0 on failure, \-1 if a general error occurred,
or \-2 if there was a usage error.
In the latter case,
.Nm sudo
will print a usage message before it exits.
If an error occurs, the plugin may optionally call the
.Fn conversation
or
.Fn plugin_printf
function with
.Dv SUDO_CONF_ERROR_MSG
to present additional error information to the user.
.Pp
The function arguments are as follows:
.Bl -tag -width 4n
.It Fa version
The version passed in by
.Nm sudo
allows the plugin to determine the
major and minor version number of the plugin API supported by
.Nm sudo .
.It Fa conversation
A pointer to the
.Fn conversation
function that may be used by the
.Fn show_version
function to display version information (see
.Fn show_version
below).
The
.Fn conversation
function may also be used to display additional error message to the user.
The
.Fn conversation
function returns 0 on success, and \-1 on failure.
.It Fa plugin_printf
A pointer to a
.Fn printf Ns -style
function that may be used by the
.Fn show_version
function to display version information (see
show_version below).
The
.Fn plugin_printf
function may also be used to display additional error message to the user.
The
.Fn plugin_printf
function returns number of characters printed on success and \-1 on failure.
.It Fa settings
A vector of user-supplied
.Nm sudo
settings in the form of
.Dq name=value
strings.
The vector is terminated by a
.Dv NULL
pointer.
These settings correspond to options the user specified when running
.Nm sudo .
As such, they will only be present when the corresponding option has
been specified on the command line.
.Pp
When parsing
.Fa settings ,
the plugin should split on the
.Sy first
equal sign
.Pq Ql =
since the
.Em name
field will never include one
itself but the
.Em value
might.
.Pp
See the
.Sx Policy plugin API
section for a list of all possible settings.
.It Fa user_info
A vector of information about the user running the command in the form of
.Dq name=value
strings.
The vector is terminated by a
.Dv NULL
pointer.
.Pp
When parsing
.Fa user_info ,
the plugin should split on the
.Sy first
equal sign
.Pq Ql =
since the
.Em name
field will never include one
itself but the
.Em value
might.
.Pp
See the
.Sx Policy plugin API
section for a list of all possible strings.
.It Fa submit_optind
The index into
.Fa submit_argv
that corresponds to the first entry that is not a command line option.
If
.Fa submit_argv
only consists of options, which may be the case with the
.Fl l
or
.Fl v
options,
.Fa submit_argv Ns [ Fa submit_optind ]
will evaluate to the NULL pointer.
.It Fa submit_argv
The argument vector
.Nm sudo
was invoked with, including all command line options.
The
.Fa submit_optind
argument can be used to determine the end of the command line options.
.It Fa submit_envp
The invoking user's environment in the form of a
.Dv NULL Ns -terminated
vector of
.Dq name=value
strings.
.Pp
When parsing
.Fa submit_envp ,
the plugin should split on the
.Sy first
equal sign
.Pq Ql =
since the
.Em name
field will never include one
itself but the
.Em value
might.
.It Fa plugin_options
Any (non-comment) strings immediately after the plugin path are
treated as arguments to the plugin.
These arguments are split on a white space boundary and are passed to
the plugin in the form of a
.Dv NULL Ns -terminated
array of strings.
If no arguments were specified,
.Fa plugin_options
will be the
.Dv NULL
pointer.
.It Fa errstr
If the
.Fn open
function returns a value other than 1, the plugin may
store a message describing the failure or error in
.Fa errstr .
The
.Nm sudo
front-end will then pass this value to any registered audit plugins.
The string stored in
.Fa errstr
must remain valid until the plugin's
.Fn close
function is called.
.El
.It Fa close
.Bd -literal -compact
void (*close)(int status_type, int status);
.Ed
.Pp
The
.Fn close
function is called when
.Nm sudo
is finished, shortly before it exits.
.Pp
The function arguments are as follows:
.Bl -tag -width 4n
.It Fa status_type
The type of status being passed.
One of
.Dv SUDO_PLUGIN_NO_STATUS ,
.Dv SUDO_PLUGIN_WAIT_STATUS ,
.Dv SUDO_PLUGIN_EXEC_ERROR
or
.Dv SUDO_PLUGIN_SUDO_ERROR .
.It Fa status
Depending on the value of
.Fa status_type ,
this value is either
ignored, the command's exit status as returned by the
.Xr wait 2
system call, the value of
.Va errno
set by the
.Xr execve 2
system call, or the value of
.Va errno
resulting from an error in the
.Nm sudo
front-end.
.El
.It Fa accept
.Bd -literal -compact
int (*accept)(const char *plugin_name, unsigned int plugin_type,
char * const command_info[], char * const run_argv[],
char * const run_envp[], const char **errstr);
.Ed
.Pp
The
.Fn accept
function is called when a command or action is accepted by a policy
or approval plugin.
The function arguments are as follows:
.Bl -tag -width 4n
.It Fa plugin_name
The name of the plugin that accepted the command or
.Dq sudo
for the
.Nm sudo
front-end.
.It Fa plugin_type
The type of plugin that accepted the command, currently either
.Dv SUDO_POLICY_PLUGIN ,
.Dv SUDO_POLICY_APPROVAL ,
or
.Dv SUDO_FRONT_END .
The
.Fn accept
function is called multiple times--once for each policy or approval
plugin that succeeds and once for the sudo front-end.
When called on behalf of the sudo front-end,
.Fa command_info
may include information from an I/O logging plugin as well.
.Pp
Typically, an audit plugin is interested in either the accept status from
the
.Nm sudo
front-end or from the various policy and approval plugins, but not both.
It is possible for the policy plugin to accept a command that is
later rejected by an approval plugin, in which case the audit
plugin's
.Fn accept
and
.Fn reject
functions will
.Em both
be called.
.It Fa command_info
An optional
vector of information describing the command being run in the form of
.Dq name=value
strings.
The vector is terminated by a
.Dv NULL
pointer.
.Pp
When parsing
.Fa command_info ,
the plugin should split on the
.Sy first
equal sign
.Pq Ql =
since the
.Em name
field will never include one
itself but the
.Em value
might.
.Pp
See the
.Sx Policy plugin API
section for a list of all possible strings.
.It Fa run_argv
A
.Dv NULL Ns -terminated
argument vector describing a command that will be run in the
same form as what would be passed to the
.Xr execve 2
system call.
.It Fa run_envp
The environment the command will be run with in the form of a
.Dv NULL Ns -terminated
vector of
.Dq name=value
strings.
.Pp
When parsing
.Fa run_envp ,
the plugin should split on the
.Sy first
equal sign
.Pq Ql =
since the
.Em name
field will never include one
itself but the
.Em value
might.
.It Fa errstr
If the
.Fn accept
function returns a value other than 1, the plugin may
store a message describing the failure or error in
.Fa errstr .
The
.Nm sudo
front-end will then pass this value to any registered audit plugins.
The string stored in
.Fa errstr
must remain valid until the plugin's
.Fn close
function is called.
.El
.It Fa reject
.Bd -literal -compact
int (*reject)(const char *plugin_name, unsigned int plugin_type,
const char *audit_msg, char * const command_info[],
const char **errstr);
.Ed
.Pp
The
.Fn reject
function is called when a command or action is rejected by a plugin.
The function arguments are as follows:
.Bl -tag -width 4n
.It Fa plugin_name
The name of the plugin that rejected the command.
.It Fa plugin_type
The type of plugin that rejected the command, currently either
.Dv SUDO_POLICY_PLUGIN ,
.Dv SUDO_APPROVAL_PLUGIN ,
or
.Dv SUDO_IO_PLUGIN .
.Pp
Unlike the
.Fn accept
function, the
.Fn reject
function is not called on behalf of the
.Nm sudo
front-end.
.It Fa audit_msg
An optional string describing the reason the command was rejected
by the plugin.
If the plugin did not provide a reason,
.Fa audit_msg
will be the
.Dv NULL
pointer.
.It Fa command_info
An optional
vector of information describing the command being run in the form of
.Dq name=value
strings.
The vector is terminated by a
.Dv NULL
pointer.
.Pp
When parsing
.Fa command_info ,
the plugin should split on the
.Sy first
equal sign
.Pq Ql =
since the
.Em name
field will never include one
itself but the
.Em value
might.
.Pp
See the
.Sx Policy plugin API
section for a list of all possible strings.
.It Fa errstr
If the
.Fn reject
function returns a value other than 1, the plugin may
store a message describing the failure or error in
.Fa errstr .
The
.Nm sudo
front-end will then pass this value to any registered audit plugins.
The string stored in
.Fa errstr
must remain valid until the plugin's
.Fn close
function is called.
.El
.It Fa error
.Bd -literal -compact
int (*error)(const char *plugin_name, unsigned int plugin_type,
const char *audit_msg, char * const command_info[],
const char **errstr);
.Ed
.Pp
The
.Fn error
function is called when a plugin or the
.Nm sudo
front-end returns an error.
The function arguments are as follows:
.Bl -tag -width 4n
.It Fa plugin_name
The name of the plugin that generated the error or
.Dq sudo
for the
.Nm sudo
front-end.
.It Fa plugin_type
The type of plugin that generated the error, or
.Dv SUDO_FRONT_END
for the
.Nm sudo
front-end.
.It Fa audit_msg
An optional string describing the plugin error.
If the plugin did not provide a description,
.Fa audit_msg
will be the
.Dv NULL
pointer.
.It Fa command_info
An optional
vector of information describing the command being run in the form of
.Dq name=value
strings.
The vector is terminated by a
.Dv NULL
pointer.
.Pp
When parsing
.Fa command_info ,
the plugin should split on the
.Sy first
equal sign
.Pq Ql =
since the
.Em name
field will never include one
itself but the
.Em value
might.
.Pp
See the
.Sx Policy plugin API
section for a list of all possible strings.
.It Fa errstr
If the
.Fn error
function returns a value other than 1, the plugin may
store a message describing the failure or error in
.Fa errstr .
The
.Nm sudo
front-end will then pass this value to any registered audit plugins.
The string stored in
.Fa errstr
must remain valid until the plugin's
.Fn close
function is called.
.El
.It Fa show_version
.Bd -literal -compact
int (*show_version)(int verbose);
.Ed
.Pp
The
.Fn show_version
function is called by
.Nm sudo
when the user specifies the
.Fl V
option.
The plugin may display its version information to the user via the
.Fn conversation
or
.Fn plugin_printf
function using
.Dv SUDO_CONV_INFO_MSG .
If the user requests detailed version information, the verbose flag will be set.
.Pp
Returns 1 on success, 0 on failure, \-1 if a general error occurred,
or \-2 if there was a usage error, although the return value is currently
ignored.
.It Fa register_hooks
See the
.Sx Policy plugin API
section for a description of
.Fn register_hooks .
.It Fa deregister_hooks
See the
.Sx Policy plugin API
section for a description of
.Fn deregister_hooks .
.It Fa event_alloc
.Bd -literal -compact
struct sudo_plugin_event * (*event_alloc)(void);
.Ed
.Pp
The
.Fn event_alloc
function is used to allocate a
.Vt struct sudo_plugin_event
which provides access to the main
.Nm sudo
event loop.
Unlike the other fields, the
.Fa event_alloc
pointer is filled in by the
.Nm sudo
front-end, not by the plugin.
.Pp
See the
.Sx Event API
section below for more information
about events.
.Pp
The
.Fn event_alloc
function is only available starting
with API version 1.17.
If the
.Nm sudo
front-end doesn't support API
version 1.17 or higher,
.Fn event_alloc
will not be set.
.El
.Ss Approval plugin API
.Bd -literal
struct approval_plugin {
#define SUDO_APPROVAL_PLUGIN 4
unsigned int type; /* always SUDO_APPROVAL_PLUGIN */
unsigned int version; /* always SUDO_API_VERSION */
int (*open)(unsigned int version, sudo_conv_t conversation,
sudo_printf_t sudo_plugin_printf, char * const settings[],
char * const user_info[], int submit_optind,
char * const submit_argv[], char * const submit_envp[],
char * const plugin_options[], const char **errstr);
void (*close)(void);
int (*check)(char * const command_info[], char * const run_argv[],
char * const run_envp[], const char **errstr);
int (*show_version)(int verbose);
};
.Ed
.Pp
An approval plugin can be used to apply extra constraints after a
command has been accepted by the policy plugin.
Unlike the other plugin types, it does not remain open until the command
completes.
The plugin is opened before a call to
.Fn check
or
.Fn show_version
and closed shortly thereafter (audit plugin functions must be called
before the plugin is closed).
Multiple approval plugins may be specified in
.Xr sudo.conf @mansectform@ .
.Pp
A
.Vt struct approval_plugin
has the following fields:
.Bl -tag -width 4n
.It Fa type
The
.Fa type
field should always be set to
.Dv SUDO_APPROVAL_PLUGIN .
.It Fa version
The
.Fa version
field should be set to
.Dv SUDO_API_VERSION .
.Pp
This allows
.Nm sudo
to determine the API version the plugin was
built against.
.It Fa open
.Bd -literal -compact
int (*open)(unsigned int version, sudo_conv_t conversation,
sudo_printf_t sudo_plugin_printf, char * const settings[],
char * const user_info[], int submit_optind,
char * const submit_argv[], char * const submit_envp[],
char * const plugin_options[], const char **errstr);
.Ed
.Pp
The approval
.Fn open
function is run immediately before a call to the plugin's
.Fn check
or
.Fn show_version
functions.
It is only called if the version is being requested or if the
policy plugin's
.Fn check_policy
function has returned successfully.
It returns 1 on success, 0 on failure, \-1 if a general error occurred,
or \-2 if there was a usage error.
In the latter case,
.Nm sudo
will print a usage message before it exits.
If an error occurs, the plugin may optionally call the
.Fn conversation
or
.Fn plugin_printf
function with
.Dv SUDO_CONF_ERROR_MSG
to present additional error information to the user.
.Pp
The function arguments are as follows:
.Bl -tag -width 4n
.It Fa version
The version passed in by
.Nm sudo
allows the plugin to determine the
major and minor version number of the plugin API supported by
.Nm sudo .
.It Fa conversation
A pointer to the
.Fn conversation
function that can be used by the plugin to interact with the user (see
.Sx Conversation API
for details).
Returns 0 on success and \-1 on failure.
.It Fa plugin_printf
A pointer to a
.Fn printf Ns -style
function that may be used to display informational or error messages (see
.Sx Conversation API
for details).
Returns the number of characters printed on success and \-1 on failure.
.It Fa settings
A vector of user-supplied
.Nm sudo
settings in the form of
.Dq name=value
strings.
The vector is terminated by a
.Dv NULL
pointer.
These settings correspond to options the user specified when running
.Nm sudo .
As such, they will only be present when the corresponding option has
been specified on the command line.
.Pp
When parsing
.Fa settings ,
the plugin should split on the
.Sy first
equal sign
.Pq Ql =
since the
.Em name
field will never include one
itself but the
.Em value
might.
.Pp
See the
.Sx Policy plugin API
section for a list of all possible settings.
.It Fa user_info
A vector of information about the user running the command in the form of
.Dq name=value
strings.
The vector is terminated by a
.Dv NULL
pointer.
.Pp
When parsing
.Fa user_info ,
the plugin should split on the
.Sy first
equal sign
.Pq Ql =
since the
.Em name
field will never include one
itself but the
.Em value
might.
.Pp
See the
.Sx Policy plugin API
section for a list of all possible strings.
.It Fa submit_optind
The index into
.Fa submit_argv
that corresponds to the first entry that is not a command line option.
If
.Fa submit_argv
only consists of options, which may be the case with the
.Fl l
or
.Fl v
options,
.Fa submit_argv Ns [ Fa submit_optind ]
will evaluate to the NULL pointer.
.It Fa submit_argv
The argument vector
.Nm sudo
was invoked with, including all command line options.
The
.Fa submit_optind
argument can be used to determine the end of the command line options.
.It Fa submit_envp
The invoking user's environment in the form of a
.Dv NULL Ns -terminated
vector of
.Dq name=value
strings.
.Pp
When parsing
.Fa submit_envp ,
the plugin should split on the
.Sy first
equal sign
.Pq Ql =
since the
.Em name
field will never include one
itself but the
.Em value
might.
.It Fa plugin_options
Any (non-comment) strings immediately after the plugin path are
treated as arguments to the plugin.
These arguments are split on a white space boundary and are passed to
the plugin in the form of a
.Dv NULL Ns -terminated
array of strings.
If no arguments were specified,
.Fa plugin_options
will be the
.Dv NULL
pointer.
.It Fa errstr
If the
.Fn open
function returns a value other than 1, the plugin may
store a message describing the failure or error in
.Fa errstr .
The
.Nm sudo
front-end will then pass this value to any registered audit plugins.
The string stored in
.Fa errstr
must remain valid until the plugin's
.Fn close
function is called.
.El
.It Fa close
.Bd -literal -compact
void (*close)(void);
.Ed
.Pp
The
.Fn close
function is called after the approval plugin's
.Fn check
or
.Fn show_version
functions have been called.
It takes no arguments.
The
.Fn close
function is typically used to perform plugin-specific cleanup,
such as the freeing of memory objects allocated by the plugin.
If the plugin does not need to perform any cleanup,
.Fn close
may be set to the
.Dv NULL
pointer.
.It Fa check
.Bd -literal -compact
int (*check)(char * const command_info[], char * const run_argv[],
char * const run_envp[], const char **errstr);
.Ed
.Pp
The approval
.Fn check
function is run after the policy plugin
.Fn check_policy
function and before any I/O logging plugins.
If multiple approval plugins are loaded, they must all succeed for
the command to be allowed.
It returns 1 on success, 0 on failure, \-1 if a general error occurred,
or \-2 if there was a usage error.
In the latter case,
.Nm sudo
will print a usage message before it exits.
If an error occurs, the plugin may optionally call the
.Fn conversation
or
.Fn plugin_printf
function with
.Dv SUDO_CONF_ERROR_MSG
to present additional error information to the user.
.Pp
The function arguments are as follows:
.Bl -tag -width 4n
.It Fa command_info
A vector of information describing the command being run in the form of
.Dq name=value
strings.
The vector is terminated by a
.Dv NULL
pointer.
.Pp
When parsing
.Fa command_info ,
the plugin should split on the
.Sy first
equal sign
.Pq Ql =
since the
.Em name
field will never include one
itself but the
.Em value
might.
.Pp
See the
.Sx Policy plugin API
section for a list of all possible strings.
.It Fa run_argv
A
.Dv NULL Ns -terminated
argument vector describing a command that will be run in the
same form as what would be passed to the
.Xr execve 2
system call.
.It Fa run_envp
The environment the command will be run with in the form of a
.Dv NULL Ns -terminated
vector of
.Dq name=value
strings.
.Pp
When parsing
.Fa run_envp ,
the plugin should split on the
.Sy first
equal sign
.Pq Ql =
since the
.Em name
field will never include one
itself but the
.Em value
might.
.It Fa errstr
If the
.Fn open
function returns a value other than 1, the plugin may
store a message describing the failure or error in
.Fa errstr .
The
.Nm sudo
front-end will then pass this value to any registered audit plugins.
The string stored in
.Fa errstr
must remain valid until the plugin's
.Fn close
function is called.
.El
.It Fa show_version
.Bd -literal -compact
int (*show_version)(int verbose);
.Ed
.Pp
The
.Fn show_version
function is called by
.Nm sudo
when the user specifies the
.Fl V
option.
The plugin may display its version information to the user via the
.Fn conversation
or
.Fn plugin_printf
function using
.Dv SUDO_CONV_INFO_MSG .
If the user requests detailed version information, the verbose flag will be set.
.Pp
Returns 1 on success, 0 on failure, \-1 if a general error occurred,
or \-2 if there was a usage error, although the return value is currently
ignored.
.El
.Ss Signal handlers
The
.Nm sudo
front-end installs default signal handlers to trap common signals
while the plugin functions are run.
The following signals are trapped by default before the command is
executed:
.Pp
.Bl -bullet -compact -width 1n
.It
.Dv SIGALRM
.It
.Dv SIGHUP
.It
.Dv SIGINT
.It
.Dv SIGPIPE
.It
.Dv SIGQUIT
.It
.Dv SIGTERM
.It
.Dv SIGTSTP
.It
.Dv SIGUSR1
.It
.Dv SIGUSR2
.El
.Pp
If a fatal signal is received before the command is executed,
.Nm sudo
will call the plugin's
.Fn close
function with an exit status of 128 plus the value of the signal
that was received.
This allows for consistent logging of commands killed by a signal
for plugins that log such information in their
.Fn close
function.
An exception to this is
.Dv SIGPIPE ,
which is ignored until the command is executed.
.Pp
A plugin may temporarily install its own signal handlers but must
restore the original handler before the plugin function returns.
.Ss Hook function API
Beginning with plugin API version 1.2, it is possible to install
hooks for certain functions called by the
.Nm sudo
front-end.
.Pp
Currently, the only supported hooks relate to the handling of
environment variables.
Hooks can be used to intercept attempts to get, set, or remove
environment variables so that these changes can be reflected in
the version of the environment that is used to execute a command.
A future version of the API will support hooking internal
.Nm sudo
front-end functions as well.
.Pp
.Em Hook structure
.Pp
Hooks in
.Nm sudo
are described by the following structure:
.Bd -literal
typedef int (*sudo_hook_fn_t)();
struct sudo_hook {
unsigned int hook_version;
unsigned int hook_type;
sudo_hook_fn_t hook_fn;
void *closure;
};
.Ed
.Pp
A
.Vt struct sudo_hook
has the following fields:
.Bl -tag -width 4n
.It Fa hook_version
The
.Fa hook_version
field should be set to
.Dv SUDO_HOOK_VERSION .
.It Fa hook_type
The
.Fa hook_type
field may be one of the following supported hook types:
.Bl -tag -width 4n
.It Dv SUDO_HOOK_SETENV
The C library
.Xr setenv 3
function.
Any registered hooks will run before the C library implementation.
The
.Fa hook_fn
field should
be a function that matches the following typedef:
.Bd -literal
typedef int (*sudo_hook_fn_setenv_t)(const char *name,
const char *value, int overwrite, void *closure);
.Ed
.Pp
If the registered hook does not match the typedef the results are
unspecified.
.It Dv SUDO_HOOK_UNSETENV
The C library
.Xr unsetenv 3
function.
Any registered hooks will run before the C library implementation.
The
.Fa hook_fn
field should
be a function that matches the following typedef:
.Bd -literal
typedef int (*sudo_hook_fn_unsetenv_t)(const char *name,
void *closure);
.Ed
.It Dv SUDO_HOOK_GETENV
The C library
.Xr getenv 3
function.
Any registered hooks will run before the C library implementation.
The
.Fa hook_fn
field should
be a function that matches the following typedef:
.Bd -literal
typedef int (*sudo_hook_fn_getenv_t)(const char *name,
char **value, void *closure);
.Ed
.Pp
If the registered hook does not match the typedef the results are
unspecified.
.It Dv SUDO_HOOK_PUTENV
The C library
.Xr putenv 3
function.
Any registered hooks will run before the C library implementation.
The
.Fa hook_fn
field should
be a function that matches the following typedef:
.Bd -literal
typedef int (*sudo_hook_fn_putenv_t)(char *string,
void *closure);
.Ed
.Pp
If the registered hook does not match the typedef the results are
unspecified.
.El
.It Fa hook_fn
.Bd -literal -compact
sudo_hook_fn_t hook_fn;
.Ed
.Pp
The
.Fa hook_fn
field should be set to the plugin's hook implementation.
The actual function arguments will vary depending on the
.Fa hook_type
(see
.Fa hook_type
above).
In all cases, the
.Fa closure
field of
.Vt struct sudo_hook
is passed as the last function parameter.
This can be used to pass arbitrary data to the plugin's hook implementation.
.Pp
The function return value may be one of the following:
.Bl -tag -width 4n
.It Dv SUDO_HOOK_RET_ERROR
The hook function encountered an error.
.It Dv SUDO_HOOK_RET_NEXT
The hook completed without error, go on to the next hook (including
the system implementation if applicable).
For example, a
.Xr getenv 3
hook might return
.Dv SUDO_HOOK_RET_NEXT
if the specified variable was not found in the private copy of the environment.
.It Dv SUDO_HOOK_RET_STOP
The hook completed without error, stop processing hooks for this invocation.
This can be used to replace the system implementation.
For example, a
.Fa setenv
hook that operates on a private copy of
the environment but leaves
.Va environ
unchanged.
.El
.El
.Pp
Care must be taken when hooking C library functions,
it is very easy to create an infinite loop.
For example, a
.Xr getenv 3
hook that calls the
.Xr snprintf 3
function may create a loop if the
.Xr snprintf 3
implementation calls
.Xr getenv 3
to check the locale.
To prevent this, you may wish to use a static variable in the hook
function to guard against nested calls.
For example:
.Bd -literal -offset indent
static int in_progress = 0; /* avoid recursion */
if (in_progress)
return SUDO_HOOK_RET_NEXT;
in_progress = 1;
\&...
in_progress = 0;
return SUDO_HOOK_RET_STOP;
.Ed
.Pp
.Em Hook API Version Macros
.Bd -literal
/* Hook API version major/minor */
#define SUDO_HOOK_VERSION_MAJOR 1
#define SUDO_HOOK_VERSION_MINOR 0
#define SUDO_HOOK_VERSION SUDO_API_MKVERSION(SUDO_HOOK_VERSION_MAJOR,\e
SUDO_HOOK_VERSION_MINOR)
.Ed
.Pp
For getters and setters see the
.Sx Policy plugin API .
.Ss Event API
When
.Nm sudo
runs a command, it uses an event loop to service signals and I/O.
Events may be triggered based on time, a file or socket descriptor
becoming ready, or due to receipt of a signal.
Starting with API version 1.15, it is possible for a plugin to
participate in this event loop by calling the
.Fn event_alloc
function.
.Pp
.Em Event structure
.Pp
Events are described by the following structure:
.Pp
.Bd -literal -compact
typedef void (*sudo_plugin_ev_callback_t)(int fd, int what, void *closure);
struct sudo_plugin_event {
int (*set)(struct sudo_plugin_event *pev, int fd, int events,
sudo_plugin_ev_callback_t callback, void *closure);
int (*add)(struct sudo_plugin_event *pev, struct timespec *timeout);
int (*del)(struct sudo_plugin_event *pev);
int (*pending)(struct sudo_plugin_event *pev, int events,
struct timespec *ts);
int (*fd)(struct sudo_plugin_event *pev);
void (*setbase)(struct sudo_plugin_event *pev, void *base);
void (*loopbreak)(struct sudo_plugin_event *pev);
void (*free)(struct sudo_plugin_event *pev);
};
.Ed
.Pp
A
.Vt struct sudo_plugin_event
contains the following function pointers:
.Bl -tag -width 4n
.It Fa set
.Bd -literal -compact
int (*set)(struct sudo_plugin_event *pev, int fd, int events,
sudo_plugin_ev_callback_t callback, void *closure);
.Ed
.Pp
The
.Fn set
function takes the following arguments:
.Bl -tag -width 4n
.It Vt struct sudo_plugin_event * Ns Fa pev
A pointer to the
.Vt struct sudo_plugin_event
itself.
.It Fa fd
The file or socket descriptor for I/O-based events or the signal
number for signal events.
For time-based events,
.Fa fd
must be \-1.
.It Fa events
The following values determine what will trigger the event callback:
.Bl -tag -width 4n
.It Dv SUDO_PLUGIN_EV_TIMEOUT
callback is run after the specified timeout expires
.It Dv SUDO_PLUGIN_EV_READ
callback is run when the file descriptor is readable
.It Dv SUDO_PLUGIN_EV_WRITE
callback is run when the file descriptor is writable
.It Dv SUDO_PLUGIN_EV_PERSIST
event is persistent and remains enabled until explicitly deleted
.It Dv SUDO_PLUGIN_EV_SIGNAL
callback is run when the specified signal is received
.El
.Pp
The
.Dv SUDO_PLUGIN_EV_PERSIST
flag may be ORed with any of the event types.
It is also possible to OR
.Dv SUDO_PLUGIN_EV_READ
and
.Dv SUDO_PLUGIN_EV_WRITE
together to run the callback when a descriptor is ready to be
either read from or written to.
All other event values are mutually exclusive.
.It Vt sudo_plugin_ev_callback_t Fa callback
.Bd -literal -compact
typedef void (*sudo_plugin_ev_callback_t)(int fd, int what,
void *closure);
.Ed
.Pp
The function to call when an event is triggered.
The
.Fn callback
function is run with the following arguments:
.Bl -tag -width 4n
.It Fa fd
The file or socket descriptor for I/O-based events or the signal
number for signal events.
.It Fa what
The event type that triggered that callback.
For events that have multiple event types (for example
.Dv SUDO_PLUGIN_EV_READ
and
.Dv SUDO_PLUGIN_EV_WRITE )
or have an associated timeout,
.Fa what
can be used to determine why the callback was run.
.It Fa closure
The generic pointer that was specified in the
.Fn set
function.
.El
.It Fa closure
A generic pointer that will be passed to the callback function.
.El
.Pp
The
.Fn set
function returns 1 on success, and \-1 if a error occurred.
.It Fa add
.Bd -literal -compact
int (*add)(struct sudo_plugin_event *pev, struct timespec *timeout);
.Ed
.Pp
The
.Fn add
function adds the event
.Fa pev
to
.Nm sudo Ns No 's
event loop.
The event must have previously been initialized via the
.Fn set
function.
If the
.Fa timeout
argument is not NULL, it should specify a (relative) timeout after
which the event will be triggered if the main event criteria has
not been met.
This is often used to implement an I/O timeout where the event
will fire if a descriptor is not ready within a certain time
period.
If the event is already present in the event loop, its
.Fa timeout
will be adjusted to match the new value, if any.
.Pp
The
.Fn add
function returns 1 on success, and \-1 if a error occurred.
.It Fa del
.Bd -literal -compact
int (*del)(struct sudo_plugin_event *pev);
.Ed
.Pp
The
.Fn del
function deletes the event
.Fa pev
from
.Nm sudo Ns No 's
event loop.
Deleted events can be added back via the
.Fn add
function.
.Pp
The
.Fn del
function returns 1 on success, and \-1 if a error occurred.
.It Fa pending
.Bd -literal -compact
int (*pending)(struct sudo_plugin_event *pev, int events,
struct timespec *ts);
.Ed
.Pp
The
.Fn pending
function can be used to determine whether one or more events is pending.
The
.Fa events
argument specifies which events to check for.
See the
.Fn set
function for a list of valid event types.
If
.Dv SUDO_PLUGIN_EV_TIMEOUT
is specified in
.Fa events ,
the event has an associated timeout and the
.Fa ts
pointer is non-NULL, it will be filled in with the remaining time.
.It Fa fd
.Bd -literal -compact
int (*fd)(struct sudo_plugin_event *pev);
.Ed
.Pp
The
.Fn fd
function returns the descriptor or signal number associated with
the event
.Fa pev .
.It Fa setbase
.Bd -literal -compact
void (*setbase)(struct sudo_plugin_event *pev, void *base);
.Ed
.Pp
The
.Fn setbase
function sets the underlying event
.Fa base
for
.Fa pev
to the specified value.
This can be used to move an event created via
.Fn event_alloc
to a new event loop allocated by sudo's event subsystem.
If
.Fa base
is
.Dv NULL ,
.Fa pev Ns 's
event base is reset to the default value, which corresponds to
.Nm sudo Ns 's
main event loop.
Using this function requires linking the plugin with the sudo_util
library.
It is unlikely to be used outside of the
.Nm sudoers
plugin.
.It Fa loopbreak
.Bd -literal -compact
void (*loopbreak)(struct sudo_plugin_event *pev);
.Ed
.Pp
The
.Fn loopbreak
function causes
.Nm sudo Ns No 's
event loop to exit immediately and the running command to be terminated.
.It Fa free
.Bd -literal -compact
void (*free)(struct sudo_plugin_event *pev);
.Ed
.Pp
The
.Fn free
function deletes the event
.Fa pev
from the event loop and frees the memory associated with it.
.El
.Ss Remote command execution
The
.Nm sudo
front-end does not support running remote commands.
However, starting with
.Nm sudo
1.8.8, the
.Fl h
option may be used to specify a remote host that is passed
to the policy plugin.
A plugin may also accept a
.Em runas_user
in the form of
.Dq user@hostname
which will work with older versions of
.Nm sudo .
It is anticipated that remote commands will be supported by executing a
.Dq helper
program.
The policy plugin should setup the execution environment such that the
.Nm sudo
front-end will run the helper which, in turn, will connect to the
remote host and run the command.
.Pp
For example, the policy plugin could utilize
.Nm ssh
to perform remote command execution.
The helper program would be responsible for running
.Nm ssh
with the proper options to use a private key or certificate
that the remote host will accept and run a program
on the remote host that would setup the execution environment
accordingly.
.Pp
Remote
.Nm sudoedit
functionality must be handled by the policy plugin, not
.Nm sudo
itself as the front-end has no knowledge that a remote command is
being executed.
This may be addressed in a future revision of the plugin API.
.Ss Conversation API
If the plugin needs to interact with the user, it may do so via the
.Fn conversation
function.
A plugin should not attempt to read directly from the standard input
or the user's terminal (neither of which are guaranteed to exist).
The caller must include a trailing newline in
.Fa msg
if one is to be printed.
.Pp
A
.Fn printf Ns -style
function is also available that can be used to display informational
or error messages to the user, which is usually more convenient for
simple messages where no use input is required.
.Pp
.Em Conversation function structures
.Pp
The conversation function takes as arguments pointers to the following
structures:
.Bd -literal
struct sudo_conv_message {
#define SUDO_CONV_PROMPT_ECHO_OFF 0x0001 /* do not echo user input */
#define SUDO_CONV_PROMPT_ECHO_ON 0x0002 /* echo user input */
#define SUDO_CONV_ERROR_MSG 0x0003 /* error message */
#define SUDO_CONV_INFO_MSG 0x0004 /* informational message */
#define SUDO_CONV_PROMPT_MASK 0x0005 /* mask user input */
#define SUDO_CONV_PROMPT_ECHO_OK 0x1000 /* flag: allow echo if no tty */
#define SUDO_CONV_PREFER_TTY 0x2000 /* flag: use tty if possible */
int msg_type;
int timeout;
const char *msg;
};
#define SUDO_CONV_REPL_MAX 1023
struct sudo_conv_reply {
char *reply;
};
typedef int (*sudo_conv_callback_fn_t)(int signo, void *closure);
struct sudo_conv_callback {
unsigned int version;
void *closure;
sudo_conv_callback_fn_t on_suspend;
sudo_conv_callback_fn_t on_resume;
};
.Ed
.Pp
Pointers to the
.Fn conversation
and
.Fn printf Ns -style
functions are passed
in to the plugin's
.Fn open
function when the plugin is initialized.
The following type definitions can be used in the declaration of the
.Fn open
function:
.Bd -literal
typedef int (*sudo_conv_t)(int num_msgs,
const struct sudo_conv_message msgs[],
struct sudo_conv_reply replies[], struct sudo_conv_callback *callback);
typedef int (*sudo_printf_t)(int msg_type, const char * restrict fmt, ...);
.Ed
.Pp
To use the
.Fn conversation
function, the plugin must pass an array of
.Vt struct sudo_conv_message
and
.Vt struct sudo_conv_reply .
There must be a
.Vt struct sudo_conv_message
and
.Vt struct sudo_conv_reply
for each message in the conversation, that is, both arrays must
have the same number of elements.
Each
.Vt struct sudo_conv_reply
must have its
.Fa reply
member initialized to
.Dv NULL .
The
.Vt struct sudo_conv_callback
pointer, if not
.Dv NULL ,
should contain function pointers to be called when the
.Nm sudo
process is suspended and/or resumed during conversation input.
The
.Fa on_suspend
and
.Fa on_resume
functions are called with the signal that caused
.Nm sudo
to be suspended and the
.Fa closure
pointer from the
.Vt struct sudo_conv_callback .
These functions should return 0 on success and \-1 on error.
On error, the conversation will end and the conversation function
will return a value of \-1.
The intended use is to allow the plugin to release resources, such as locks,
that should not be held indefinitely while suspended and then reacquire them
when the process is resumed.
The functions are not actually invoked from within a signal handler.
.Pp
The
.Fa msg_type
must be set to one of the following values:
.Bl -tag -width 4n
.It Dv SUDO_CONV_PROMPT_ECHO_OFF
Prompt the user for input with echo disabled;
this is generally used for passwords.
The reply will be stored in the
.Fa replies
array, and it will never be
.Dv NULL .
.It Dv SUDO_CONV_PROMPT_ECHO_ON
Prompt the user for input with echo enabled.
The reply will be stored in the
.Fa replies
array, and it will never be
.Dv NULL .
.It Dv SUDO_CONV_ERROR_MSG
Display an error message.
The message is written to the standard error unless the
.Dv SUDO_CONV_PREFER_TTY
flag is set, in which case it is written to the user's terminal if possible.
.It Dv SUDO_CONV_INFO_MSG
Display a message.
The message is written to the standard output unless the
.Dv SUDO_CONV_PREFER_TTY
flag is set, in which case it is written to the user's terminal if possible.
.It Dv SUDO_CONV_PROMPT_MASK
Prompt the user for input but echo an asterisk character for each
character read.
The reply will be stored in the
.Fa replies
array, and it will never be
.Dv NULL .
This can be used to provide visual feedback to the user while reading
sensitive information that should not be displayed.
.El
.Pp
In addition to the above values, the following flag bits may also be set:
.Bl -tag -width 4n
.It Dv SUDO_CONV_PROMPT_ECHO_OK
Allow input to be read when echo cannot be disabled
when the message type is
.Dv SUDO_CONV_PROMPT_ECHO_OFF
or
.Dv SUDO_CONV_PROMPT_MASK .
By default,
.Nm sudo
will refuse to read input if the echo cannot be disabled for those
message types.
.It Dv SUDO_CONV_PREFER_TTY
When displaying a message via
.Dv SUDO_CONV_ERROR_MSG
or
.Dv SUDO_CONV_INFO_MSG ,
try to write the message to the user's terminal.
If the terminal is unavailable, the standard error or standard output
will be used, depending upon whether
.Dv SUDO_CONV_ERROR_MSG
or
.Dv SUDO_CONV_INFO_MSG
was used.
The user's terminal is always used when possible for input,
this flag is only used for output.
.El
.Pp
The
.Fa timeout
in seconds until the prompt will wait for no more input.
A zero value implies an infinite timeout.
.Pp
The plugin is responsible for freeing the reply buffer located in each
.Vt struct sudo_conv_reply ,
if it is not
.Dv NULL .
.Dv SUDO_CONV_REPL_MAX
represents the maximum length of the reply buffer (not including
the trailing NUL character).
In practical terms, this is the longest password
.Nm sudo
will support.
.Pp
The
.Fn printf Ns -style
function uses the same underlying mechanism as the
.Fn conversation
function but only supports
.Dv SUDO_CONV_INFO_MSG
and
.Dv SUDO_CONV_ERROR_MSG
for the
.Fa msg_type
parameter.
It can be more convenient than using the
.Fn conversation
function if no user reply is needed and supports standard
.Fn printf
escape sequences.
.Pp
See the sample plugin for an example of the
.Fn conversation
function usage.
.Ss Plugin invocation order
As of
.Nm sudo
1.9.0, the plugin
.Fn open
and
.Fn close
functions are called in the
following order:
.Bl -enum
.It
audit open
.It
policy open
.It
approval open
.It
approval close
.It
I/O log open
.It
command runs
.It
command exits
.It
I/O log close
.It
policy close
.It
audit close
.It
sudo exits
.El
.Pp
Prior to
.Nm sudo
1.9.0, the I/O log
.Fn close
function was called
.Em after
the policy
.Fn close
function.
.Ss Sudoers group plugin API
The
.Nm sudoers
plugin supports its own plugin interface to allow non-Unix
group lookups.
This can be used to query a group source other than the standard Unix
group database.
Two sample group plugins are bundled with
.Nm sudo ,
.Em group_file ,
and
.Em system_group ,
are detailed in
.Xr sudoers @mansectform@ .
Third party group plugins include a QAS AD plugin available from Quest Software.
.Pp
A group plugin must declare and populate a
.Vt struct sudoers_group_plugin
in the global scope.
This structure contains pointers to the functions that implement plugin
initialization, cleanup, and group lookup.
.Bd -literal
struct sudoers_group_plugin {
unsigned int version;
int (*init)(int version, sudo_printf_t sudo_plugin_printf,
char *const argv[]);
void (*cleanup)(void);
int (*query)(const char *user, const char *group,
const struct passwd *pwd);
};
.Ed
.Pp
A
.Vt struct sudoers_group_plugin
has the following fields:
.Bl -tag -width 4n
.It Fa version
The
.Fa version
field should be set to GROUP_API_VERSION.
.Pp
This allows
.Nm sudoers
to determine the API version the group plugin
was built against.
.It Fa init
.Bd -literal -compact
int (*init)(int version, sudo_printf_t sudo_plugin_printf,
char *const argv[]);
.Ed
.Pp
The
.Fn init
function is called after
.Em sudoers
has been parsed but
before any policy checks.
It returns 1 on success, 0 on failure (or if the plugin is not configured),
and \-1 if a error occurred.
If an error occurs, the plugin may call the
.Fn plugin_printf
function with
.Dv SUDO_CONF_ERROR_MSG
to present additional error information to the user.
.Pp
The function arguments are as follows:
.Bl -tag -width 4n
.It Fa version
The version passed in by
.Nm sudoers
allows the plugin to determine the
major and minor version number of the group plugin API supported by
.Nm sudoers .
.It Fa plugin_printf
A pointer to a
.Fn printf Ns -style
function that may be used to display informational or error message to the user.
Returns the number of characters printed on success and \-1 on failure.
.It Fa argv
A
.Dv NULL Ns -terminated
array of arguments generated from the
.Em group_plugin
option in
.Em sudoers .
If no arguments were given,
.Fa argv
will be
.Dv NULL .
.El
.It Fa cleanup
.Bd -literal -compact
void (*cleanup)();
.Ed
.Pp
The
.Fn cleanup
function is called when
.Nm sudoers
has finished its
group checks.
The plugin should free any memory it has allocated and close open file handles.
.It Fa query
.Bd -literal -compact
int (*query)(const char *user, const char *group,
const struct passwd *pwd);
.Ed
.Pp
The
.Fn query
function is used to ask the group plugin whether
.Fa user
is a member of
.Fa group .
.Pp
The function arguments are as follows:
.Bl -tag -width 4n
.It Fa user
The name of the user being looked up in the external group database.
.It Fa group
The name of the group being queried.
.It Fa pwd
The password database entry for
.Fa user ,
if any.
If
.Fa user
is not
present in the password database,
.Fa pwd
will be
.Dv NULL .
.El
.El
.Pp
.Em Group API Version Macros
.Bd -literal
/* Sudoers group plugin version major/minor */
#define GROUP_API_VERSION_MAJOR 1
#define GROUP_API_VERSION_MINOR 0
#define GROUP_API_VERSION ((GROUP_API_VERSION_MAJOR << 16) | \e
GROUP_API_VERSION_MINOR)
.Ed
For getters and setters see the
.Sx Policy plugin API .
.Sh PLUGIN API CHANGELOG
The following revisions have been made to the Sudo Plugin API.
.Bl -tag -width 4n
.It Version 1.0
Initial API version.
.It Version 1.1 (sudo 1.8.0)
The I/O logging plugin's
.Fn open
function was modified to take the
.Fa command_info
list as an argument.
.It Version 1.2 (sudo 1.8.5)
The Policy and I/O logging plugins'
.Fn open
functions are now passed
a list of plugin parameters if any are specified in
.Xr sudo.conf @mansectform@ .
.Pp
A simple hooks API has been introduced to allow plugins to hook in to the
system's environment handling functions.
.Pp
The
.Fn init_session
Policy plugin function is now passed a pointer
to the user environment which can be updated as needed.
This can be used to merge in environment variables stored in the PAM
handle before a command is run.
.It Version 1.3 (sudo 1.8.7)
Support for the
.Em exec_background
entry has been added to the
.Fa command_info
list.
.Pp
The
.Em max_groups
and
.Em plugin_dir
entries were added to the
.Fa settings
list.
.Pp
The
.Fn version
and
.Fn close
functions are now optional.
Previously, a missing
.Fn version
or
.Fn close
function would result in a crash.
If no policy plugin
.Fn close
function is defined, a default
.Fn close
function will be provided by the
.Nm sudo
front-end that displays a warning if the command could not be
executed.
.Pp
The
.Nm sudo
front-end now installs default signal handlers to trap common signals
while the plugin functions are run.
.It Version 1.4 (sudo 1.8.8)
The
.Em remote_host
entry was added to the
.Fa settings
list.
.It Version 1.5 (sudo 1.8.9)
The
.Em preserve_fds
entry was added to the
.Fa command_info
list.
.It Version 1.6 (sudo 1.8.11)
The behavior when an I/O logging plugin returns an error
.Pq \-1
has changed.
Previously, the
.Nm sudo
front-end took no action when the
.Fn log_ttyin ,
.Fn log_ttyout ,
.Fn log_stdin ,
.Fn log_stdout ,
or
.Fn log_stderr
function returned an error.
.Pp
The behavior when an I/O logging plugin returns 0 has changed.
Previously, output from the command would be displayed to the
terminal even if an output logging function returned 0.
.It Version 1.7 (sudo 1.8.12)
The
.Em plugin_path
entry was added to the
.Fa settings
list.
.Pp
The
.Em debug_flags
entry now starts with a debug file path name and may occur multiple
times if there are multiple plugin-specific Debug lines in the
.Xr sudo.conf @mansectform@ file.
.It Version 1.8 (sudo 1.8.15)
The
.Em sudoedit_checkdir
and
.Em sudoedit_follow
entries were added to the
.Fa command_info
list.
The default value of
.Em sudoedit_checkdir
was changed to true in sudo 1.8.16.
.Pp
The sudo
.Fn conversation
function now takes a pointer to a
.Vt struct sudo_conv_callback
as its fourth argument.
The
.Vt sudo_conv_t
definition has been updated to match.
The plugin must specify that it supports plugin API version 1.8 or higher
to receive a conversation function pointer that supports this argument.
.It Version 1.9 (sudo 1.8.16)
The
.Em execfd
entry was added to the
.Fa command_info
list.
.It Version 1.10 (sudo 1.8.19)
The
.Em umask
entry was added to the
.Fa user_info
list.
The
.Em iolog_group ,
.Em iolog_mode ,
and
.Em iolog_user
entries were added to the
.Fa command_info
list.
.It Version 1.11 (sudo 1.8.20)
The
.Em timeout
entry was added to the
.Fa settings
list.
.It Version 1.12 (sudo 1.8.21)
The
.Fn change_winsize
function was added to
.Vt struct io_plugin .
.It Version 1.13 (sudo 1.8.26)
The
.Fn log_suspend
function was added to
.Vt struct io_plugin .
.It Version 1.14 (sudo 1.8.29)
The
.Em umask_override
entry was added to the
.Fa command_info
list.
.It Version 1.15 (sudo 1.9.0)
The
.Em cwd_optional
entry was added to the
.Fa command_info
list.
.Pp
The
.Fn event_alloc
function was added to
.Vt struct policy_plugin
and
.Vt struct io_plugin .
.Pp
The
.Fa errstr
argument was added to the policy and I/O plugin functions
which the plugin function can use to return an error string.
This string may be used by the audit plugin to report failure or
error conditions set by the other plugins.
.Pp
The
.Fn close
function is now is called regardless of whether or not a command
was actually executed.
This makes it possible for plugins to perform cleanup even when a
command was not run.
.Pp
.Dv SUDO_CONV_REPL_MAX
has increased from 255 to 1023 bytes.
.Pp
Support for audit and approval plugins was added.
.It Version 1.16 (sudo 1.9.3)
Initial resource limit values were added to the
.Fa user_info
list.
.Pp
The
.Em cmnd_chroot
and
.Em cmnd_cwd
entries were added to the
.Fa settings
list.
.It Version 1.17 (sudo 1.9.4)
The
.Fn event_alloc
function was added to
.Vt struct audit_plugin
and
.Vt struct approval_plugin .
.It Version 1.18 (sudo 1.9.9)
The policy may now set resource limit values in the
.Fa command_info
list.
The
.Em intercept
and
.Em log_subcmds
entries were added to the
.Fa command_info
list.
.It Version 1.19 (sudo 1.9.11)
The
.Em intercept_ptrace
and
.Em intercept_setid
entries were added to the
.Fa settings
list.
The
.Em apparmor_profile
and
.Em use_ptrace
entries were added to the
.Fa command_info
list.
.It Version 1.20 (sudo 1.9.12)
The
.Em update_ticket
entry was added to the
.Fa settings
list.
The
.Em intercept_verify
entry was added to the
.Fa command_info
list.
.It Version 1.21 (sudo 1.9.13)
The
.Em sudoedit_nfiles
entry was added to the
.Fa command_info
list.
.El
.Sh SEE ALSO
.Xr sudo.conf @mansectform@ ,
.Xr sudoers @mansectform@ ,
.Xr sudo @mansectsu@
.Sh AUTHORS
Many people have worked on
.Nm sudo
over the years; this version consists of code written primarily by:
.Bd -ragged -offset indent
.An Todd C. Miller
.Ed
.Pp
See the CONTRIBUTORS.md file in the
.Nm sudo
distribution (https://www.sudo.ws/about/contributors/) for an
exhaustive list of people who have contributed to
.Nm sudo .
.Sh BUGS
If you believe you have found a bug in
.Nm sudo ,
you can submit a bug report at https://bugzilla.sudo.ws/
.Sh SUPPORT
Limited free support is available via the sudo-users mailing list,
see https://www.sudo.ws/mailman/listinfo/sudo-users to subscribe or
search the archives.
.Sh DISCLAIMER
.Nm sudo
is provided
.Dq AS IS
and any express or implied warranties, including, but not limited
to, the implied warranties of merchantability and fitness for a
particular purpose are disclaimed.
See the LICENSE.md file distributed with
.Nm sudo
or https://www.sudo.ws/about/license/ for complete details.
|