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
|
.\" Automatically generated from an mdoc input file. Do not edit.
.\"
.\" Copyright (c) 2009-2018 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.
.\"
.TH "SUDO_PLUGIN" "5" "October 24, 2018" "Sudo @PACKAGE_VERSION@" "File Formats Manual"
.nh
.if n .ad l
.SH "NAME"
\fBsudo_plugin\fR
\- Sudo Plugin API
.SH "DESCRIPTION"
Starting with version 1.8,
\fBsudo\fR
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
\fBsudo\fR
binary itself.
By default, the
\fBsudoers\fR
policy plugin and an associated I/O logging plugin are used.
Via the plugin API,
\fBsudo\fR
can be configured to use alternate policy and/or I/O logging plugins
provided by third parties.
The plugins to be used are specified in the
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
\fRsudo_plugin.h\fR
header file.
.SS "Policy plugin API"
A policy plugin must declare and populate a
\fRpolicy_plugin\fR
struct in the global scope.
This structure contains pointers to the functions that implement the
\fBsudo\fR
policy checks.
The name of the symbol should be specified in
sudo.conf(@mansectform@)
along with a path to the plugin so that
\fBsudo\fR
can load it.
.nf
.sp
.RS 0n
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 plugin_printf, char * const settings[],
char * const user_info[], char * const user_env[],
char * const plugin_options[]);
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[]);
int (*list)(int argc, char * const argv[], int verbose,
const char *list_user);
int (*validate)(void);
void (*invalidate)(int remove);
int (*init_session)(struct passwd *pwd, char **user_env[]);
void (*register_hooks)(int version,
int (*register_hook)(struct sudo_hook *hook));
void (*deregister_hooks)(int version,
int (*deregister_hook)(struct sudo_hook *hook));
};
.RE
.fi
.PP
The policy_plugin struct has the following fields:
.TP 6n
type
The
\fRtype\fR
field should always be set to SUDO_POLICY_PLUGIN.
.TP 6n
version
The
\fRversion\fR
field should be set to
\fRSUDO_API_VERSION\fR.
.sp
This allows
\fBsudo\fR
to determine the API version the plugin was
built against.
.TP 6n
open
.nf
.RS 6n
int (*open)(unsigned int version, sudo_conv_t conversation,
sudo_printf_t plugin_printf, char * const settings[],
char * const user_info[], char * const user_env[],
char * const plugin_options[]);
.RE
.fi
.RS 6n
.sp
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,
\fBsudo\fR
will print a usage message before it exits.
If an error occurs, the plugin may optionally call the
\fBconversation\fR()
or
\fBplugin_printf\fR()
function with
\fRSUDO_CONF_ERROR_MSG\fR
to present additional error information to the user.
.sp
The function arguments are as follows:
.TP 6n
version
The version passed in by
\fBsudo\fR
allows the plugin to determine the
major and minor version number of the plugin API supported by
\fBsudo\fR.
.TP 6n
conversation
A pointer to the
\fBconversation\fR()
function that can be used by the plugin to interact with the user (see below).
Returns 0 on success and \-1 on failure.
.TP 6n
plugin_printf
A pointer to a
\fBprintf\fR()-style
function that may be used to display informational or error messages
(see below).
Returns the number of characters printed on success and \-1 on failure.
.TP 6n
settings
A vector of user-supplied
\fBsudo\fR
settings in the form of
\(lqname=value\(rq
strings.
The vector is terminated by a
\fRNULL\fR
pointer.
These settings correspond to flags the user specified when running
\fBsudo\fR.
As such, they will only be present when the corresponding flag has
been specified on the command line.
.sp
When parsing
\fIsettings\fR,
the plugin should split on the
\fBfirst\fR
equal sign
(\(oq=\(cq)
since the
\fIname\fR
field will never include one
itself but the
\fIvalue\fR
might.
.PP
.RS 6n
.PD 0
.TP 6n
bsdauth_type=string
Authentication type, if specified by the
\fB\-a\fR
flag, to use on
systems where
BSD
authentication is supported.
.PD
.TP 6n
closefrom=number
If specified, the user has requested via the
\fB\-C\fR
flag that
\fBsudo\fR
close all files descriptors with a value of
\fInumber\fR
or higher.
The plugin may optionally pass this, or another value, back in the
\fIcommand_info\fR
list.
.TP 6n
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
\fRDebug\fR
entry in
sudo.conf(@mansectform@),
if there is one.
The flags are passed to the plugin exactly as they appear in
sudo.conf(@mansectform@).
The syntax used by
\fBsudo\fR
and the
\fBsudoers\fR
plugin is
\fIsubsystem\fR@\fIpriority\fR
but a plugin is free to use a different
format so long as it does not include a comma
(\(oq,\&\(cq).
Prior to
\fBsudo\fR
1.8.12, there was no way to specify plugin-specific
\fIdebug_flags\fR
so the value was always the same as that used by the
\fBsudo\fR
front end and did not include a path name, only the flags themselves.
As of version 1.7 of the plugin interface,
\fBsudo\fR
will only pass
\fIdebug_flags\fR
if
sudo.conf(@mansectform@)
contains a plugin-specific
\fRDebug\fR
entry.
.TP 6n
debug_level=number
This setting has been deprecated in favor of
\fIdebug_flags\fR.
.TP 6n
ignore_ticket=bool
Set to true if the user specified the
\fB\-k\fR
flag along with a
command, indicating that the user wishes to ignore any cached
authentication credentials.
\fIimplied_shell\fR
to true.
This allows
\fBsudo\fR
with no arguments
to be used similarly to
su(1).
If the plugin does not to support this usage, it may return a value of \-2
from the
\fBcheck_policy\fR()
function, which will cause
\fBsudo\fR
to print a usage message and
exit.
.TP 6n
implied_shell=bool
If the user does not specify a program on the command line,
\fBsudo\fR
will pass the plugin the path to the user's shell and set
.TP 6n
login_class=string
BSD
login class to use when setting resource limits and nice value,
if specified by the
\fB\-c\fR
flag.
.TP 6n
login_shell=bool
Set to true if the user specified the
\fB\-i\fR
flag, indicating that
the user wishes to run a login shell.
.TP 6n
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
sudo.conf(@mansectform@).
.TP 6n
network_addrs=list
A space-separated list of IP network addresses and netmasks in the
form
\(lqaddr/netmask\(rq,
e.g.,
\(lq192.168.1.2/255.255.255.0\(rq.
The address and netmask pairs may be either IPv4 or IPv6, depending on
what the operating system supports.
If the address contains a colon
(\(oq:\&\(cq),
it is an IPv6 address, else it is IPv4.
.TP 6n
noninteractive=bool
Set to true if the user specified the
\fB\-n\fR
flag, indicating that
\fBsudo\fR
should operate in non-interactive mode.
The plugin may reject a command run in non-interactive mode if user
interaction is required.
.TP 6n
plugin_dir=string
The default plugin directory used by the
\fBsudo\fR
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.
.TP 6n
plugin_path=string
The path name of plugin loaded by the
\fBsudo\fR
front end.
The path name will be a fully-qualified unless the plugin was
statically compiled into
\fBsudo\fR.
.TP 6n
preserve_environment=bool
Set to true if the user specified the
\fB\-E\fR
flag, indicating that
the user wishes to preserve the environment.
.TP 6n
preserve_groups=bool
Set to true if the user specified the
\fB\-P\fR
flag, indicating that
the user wishes to preserve the group vector instead of setting it
based on the runas user.
.TP 6n
progname=string
The command name that sudo was run as, typically
\(lqsudo\(rq
or
\(lqsudoedit\(rq.
.TP 6n
prompt=string
The prompt to use when requesting a password, if specified via
the
\fB\-p\fR
flag.
.TP 6n
remote_host=string
The name of the remote host to run the command on, if specified via
the
\fB\-h\fR
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
\fBsudo\fR
front end is only capable of executing commands on the local host.
Only available starting with API version 1.4.
.TP 6n
run_shell=bool
Set to true if the user specified the
\fB\-s\fR
flag, indicating that the user wishes to run a shell.
.TP 6n
runas_group=string
The group name or gid to run the command as, if specified via
the
\fB\-g\fR
flag.
.TP 6n
runas_user=string
The user name or uid to run the command as, if specified via the
\fB\-u\fR
flag.
.TP 6n
selinux_role=string
SELinux role to use when executing the command, if specified by
the
\fB\-r\fR
flag.
.TP 6n
selinux_type=string
SELinux type to use when executing the command, if specified by
the
\fB\-t\fR
flag.
.TP 6n
set_home=bool
Set to true if the user specified the
\fB\-H\fR
flag.
If true, set the
\fRHOME\fR
environment variable to the target user's home directory.
.TP 6n
sudoedit=bool
Set to true when the
\fB\-e\fR
flag is specified or if invoked as
\fBsudoedit\fR.
The plugin shall substitute an editor into
\fIargv\fR
in the
\fBcheck_policy\fR()
function or return \-2 with a usage error
if the plugin does not support
\fIsudoedit\fR.
For more information, see the
\fIcheck_policy\fR
section.
.TP 6n
timeout=string
User-specified command timeout.
Not all plugins support command timeouts and the ability for the
user to set a timeout may be restricted by policy.
The format of the timeout string is plugin-specific.
.PP
Additional settings may be added in the future so the plugin should
silently ignore settings that it does not recognize.
.RE
.TP 6n
user_info
A vector of information about the user running the command in the form of
\(lqname=value\(rq
strings.
The vector is terminated by a
\fRNULL\fR
pointer.
.sp
When parsing
\fIuser_info\fR,
the plugin should split on the
\fBfirst\fR
equal sign
(\(oq=\(cq)
since the
\fIname\fR
field will never include one
itself but the
\fIvalue\fR
might.
.PP
.RS 6n
.PD 0
.TP 6n
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.
.PD
.TP 6n
cwd=string
The user's current working directory.
.TP 6n
egid=gid_t
The effective group ID of the user invoking
\fBsudo\fR.
.TP 6n
euid=uid_t
The effective user ID of the user invoking
\fBsudo\fR.
.TP 6n
gid=gid_t
The real group ID of the user invoking
\fBsudo\fR.
.TP 6n
groups=list
The user's supplementary group list formatted as a string of
comma-separated group IDs.
.TP 6n
host=string
The local machine's hostname as returned by the
gethostname(2)
system call.
.TP 6n
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.
.TP 6n
pgid=int
The ID of the process group that the running
\fBsudo\fR
process is a member of.
Only available starting with API version 1.2.
.TP 6n
pid=int
The process ID of the running
\fBsudo\fR
process.
Only available starting with API version 1.2.
.TP 6n
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
\fRNULL\fR-terminated
array of strings.
If no arguments were
specified,
\fIplugin_options\fR
will be the
\fRNULL\fR
pointer.
.sp
NOTE: the
\fIplugin_options\fR
parameter is only available starting with
API version 1.2.
A plugin
\fBmust\fR
check the API version specified
by the
\fBsudo\fR
front end before using
\fIplugin_options\fR.
Failure to do so may result in a crash.
.TP 6n
ppid=int
The parent process ID of the running
\fBsudo\fR
process.
Only available starting with API version 1.2.
.TP 6n
sid=int
The session ID of the running
\fBsudo\fR
process or 0 if
\fBsudo\fR
is not part of a POSIX job control session.
Only available starting with API version 1.2.
.TP 6n
tcpgid=int
The ID of the foreground process group associated with the terminal
device associated with the
\fBsudo\fR
process or \-1 if there is no
terminal present.
Only available starting with API version 1.2.
.TP 6n
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
\(lq\fRtty=\fR\(rq.
.TP 6n
uid=uid_t
The real user ID of the user invoking
\fBsudo\fR.
.TP 6n
umask=octal
The invoking user's file creation mask.
Only available starting with API version 1.10.
.TP 6n
user=string
The name of the user invoking
\fBsudo\fR.
.PD 0
.PP
.RE
.PD
.TP 6n
user_env
The user's environment in the form of a
\fRNULL\fR-terminated vector of
\(lqname=value\(rq
strings.
.sp
When parsing
\fIuser_env\fR,
the plugin should split on the
\fBfirst\fR
equal sign
(\(oq=\(cq)
since the
\fIname\fR
field will never include one
itself but the
\fIvalue\fR
might.
.PD 0
.PP
.RE
.PD
.TP 6n
close
.br
.nf
.RS 6n
void (*close)(int exit_status, int error);
.RE
.fi
.RS 6n
.sp
The
\fBclose\fR()
function is called when the command being run by
\fBsudo\fR
finishes.
.sp
The function arguments are as follows:
.TP 6n
exit_status
The command's exit status, as returned by the
wait(2)
system call.
The value of
\fRexit_status\fR
is undefined if
\fRerror\fR
is non-zero.
.TP 6n
error
.br
If the command could not be executed, this is set to the value of
\fRerrno\fR
set by the
execve(2)
system call.
The plugin is responsible for displaying error information via the
\fBconversation\fR()
or
\fBplugin_printf\fR()
function.
If the command was successfully executed, the value of
\fRerror\fR
is 0.
.PP
If no
\fBclose\fR()
function is defined, no I/O logging plugins are loaded,
and neither the
\fItimeout\fR
not
\fIuse_pty\fR
options are set in the
\fRcommand_info\fR
list, the
\fBsudo\fR
front end may execute the command directly instead of running
it as a child process.
.RE
.TP 6n
show_version
.nf
.RS 6n
int (*show_version)(int verbose);
.RE
.fi
.RS 6n
.sp
The
\fBshow_version\fR()
function is called by
\fBsudo\fR
when the user specifies
the
\fB\-V\fR
option.
The plugin may display its version information to the user via the
\fBconversation\fR()
or
\fBplugin_printf\fR()
function using
\fRSUDO_CONV_INFO_MSG\fR.
If the user requests detailed version information, the verbose flag will be set.
.sp
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.
.RE
.TP 6n
check_policy
.nf
.RS 6n
int (*check_policy)(int argc, char * const argv[],
char *env_add[], char **command_info[],
char **argv_out[], char **user_env_out[]);
.RE
.fi
.RS 6n
.sp
The
\fBcheck_policy\fR()
function is called by
\fBsudo\fR
to determine
whether the user is allowed to run the specified commands.
.sp
If the
\fIsudoedit\fR
option was enabled in the
\fIsettings\fR
array
passed to the
\fBopen\fR()
function, the user has requested
\fIsudoedit\fR
mode.
\fIsudoedit\fR
is a mechanism for editing one or more files
where an editor is run with the user's credentials instead of with
elevated privileges.
\fBsudo\fR
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
\fIsudoedit\fR,
it should choose the editor to be used, potentially from a variable
in the user's environment, such as
\fREDITOR\fR,
and include it in
\fIargv_out\fR
(note that environment
variables may include command line flags).
The files to be edited should be copied from
\fIargv\fR
into
\fIargv_out\fR,
separated from the
editor and its arguments by a
\(lq\fR--\fR\(rq
element.
The
\(lq\fR--\fR\(rq
will
be removed by
\fBsudo\fR
before the editor is executed.
The plugin should also set
\fIsudoedit=true\fR
in the
\fIcommand_info\fR
list.
.sp
The
\fBcheck_policy\fR()
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
\fIsudoedit\fR
was specified but is unsupported by the plugin.
In the latter case,
\fBsudo\fR
will print a usage message before it
exits.
If an error occurs, the plugin may optionally call the
\fBconversation\fR()
or
\fBplugin_printf\fR()
function with
\fRSUDO_CONF_ERROR_MSG\fR
to present additional error information to the user.
.sp
The function arguments are as follows:
.TP 6n
argc
The number of elements in
\fIargv\fR,
not counting the final
\fRNULL\fR
pointer.
.TP 6n
argv
The argument vector describing the command the user wishes to run,
in the same form as what would be passed to the
execve(2)
system call.
The vector is terminated by a
\fRNULL\fR
pointer.
.TP 6n
env_add
Additional environment variables specified by the user on the command
line in the form of a
\fRNULL\fR-terminated
vector of
\(lqname=value\(rq
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.
.sp
When parsing
\fIenv_add\fR,
the plugin should split on the
\fBfirst\fR
equal sign
(\(oq=\(cq)
since the
\fIname\fR
field will never include one
itself but the
\fIvalue\fR
might.
.TP 6n
command_info
Information about the command being run in the form of
\(lqname=value\(rq
strings.
These values are used by
\fBsudo\fR
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
\fRNULL\fR
pointer.
The following values are recognized by
\fBsudo\fR:
.PP
.RS 6n
.PD 0
.TP 6n
chroot=string
The root directory to use when running the command.
.PD
.TP 6n
closefrom=number
If specified,
\fBsudo\fR
will close all files descriptors with a value
of
\fInumber\fR
or higher.
.TP 6n
command=string
Fully qualified path to the command to be executed.
.TP 6n
cwd=string
The current working directory to change to when executing the command.
.TP 6n
exec_background=bool
By default,
\fBsudo\fR
runs a command as the foreground process as long as
\fBsudo\fR
itself is running in the foreground.
When
\fIexec_background\fR
is enabled and the command is being run in a pty (due to I/O logging
or the
\fIuse_pty\fR
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
\fRSIGTTIN\fR
signal (or
\fRSIGTTOU\fR
in the case of terminal settings).
If this happens when
\fBsudo\fR
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
\fBsudo\fR
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
\fIsudo\fR
behavior or when the command is not being run in a pty.
.sp
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
\fBtcgetattr\fR()
and
\fBtcsetattr\fR()
system calls (this is a bug in macOS).
Furthermore, because this behavior depends on the command stopping with the
\fRSIGTTIN\fR
or
\fRSIGTTOU\fR
signals, programs that catch these signals and suspend themselves
with a different signal (usually
\fRSIGTOP\fR)
will not be automatically foregrounded.
Some versions of the linux
su(1)
command behave this way.
Because of this, a plugin should not set
\fIexec_background\fR
unless it is explicitly enabled by the administrator and there should
be a way to enabled or disable it on a per-command basis.
.sp
This setting has no effect unless I/O logging is enabled or
\fIuse_pty\fR
is enabled.
.TP 6n
execfd=number
If specified,
\fBsudo\fR
will use the
fexecve(2)
system call to execute the command instead of
execve(2).
The specified
\fInumber\fR
must refer to an open file descriptor.
.TP 6n
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.
.TP 6n
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.
.TP 6n
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.
.TP 6n
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.
.TP 6n
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.
.TP 6n
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.
.TP 6n
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.
.TP 6n
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.
.TP 6n
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.
.TP 6n
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.
.TP 6n
login_class=string
BSD
login class to use when setting resource limits and nice value (optional).
This option is only set on systems that support login classes.
.TP 6n
nice=int
Nice value (priority) to use when executing the command.
The nice value, if specified, overrides the priority associated with the
\fIlogin_class\fR
on
BSD
systems.
.TP 6n
noexec=bool
If set, prevent the command from executing other programs.
.TP 6n
preserve_fds=list
A comma-separated list of file descriptors that should be
preserved, regardless of the value of the
\fIclosefrom\fR
setting.
Only available starting with API version 1.5.
.TP 6n
preserve_groups=bool
If set,
\fBsudo\fR
will preserve the user's group vector instead of
initializing the group vector based on
\fRrunas_user\fR.
.TP 6n
runas_egid=gid
Effective group ID to run the command as.
If not specified, the value of
\fIrunas_gid\fR
is used.
.TP 6n
runas_euid=uid
Effective user ID to run the command as.
If not specified, the value of
\fIrunas_uid\fR
is used.
.TP 6n
runas_gid=gid
Group ID to run the command as.
.TP 6n
runas_groups=list
The supplementary group vector to use for the command in the form
of a comma-separated list of group IDs.
If
\fIpreserve_groups\fR
is set, this option is ignored.
.TP 6n
runas_uid=uid
User ID to run the command as.
.TP 6n
selinux_role=string
SELinux role to use when executing the command.
.TP 6n
selinux_type=string
SELinux type to use when executing the command.
.TP 6n
set_utmp=bool
Create a utmp (or utmpx) entry when a pseudo-tty 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.
.TP 6n
sudoedit=bool
Set to true when in
\fIsudoedit\fR
mode.
The plugin may enable
\fIsudoedit\fR
mode even if
\fBsudo\fR
was not invoked as
\fBsudoedit\fR.
This allows the plugin to perform command substitution and transparently
enable
\fIsudoedit\fR
when the user attempts to run an editor.
.TP 6n
sudoedit_checkdir=bool
Set to false to disable directory writability checks in
\fBsudoedit\fR.
By default,
\fBsudoedit\fR
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
\fBsudoedit\fR
will refuse to edit a file located in a writable directory.
These restrictions are not enforced when
\fBsudoedit\fR
is run by root.
The
\fIsudoedit_follow\fR
option can be set to false to disable this check.
Only available starting with API version 1.8.
.TP 6n
sudoedit_follow=bool
Set to true to allow
\fBsudoedit\fR
to edit files that are symbolic links.
By default,
\fBsudoedit\fR
1.8.15 and higher will refuse to open a symbolic link.
The
\fIsudoedit_follow\fR
option can be used to restore the older behavior and allow
\fBsudoedit\fR
to open symbolic links.
Only available starting with API version 1.8.
.TP 6n
timeout=int
Command timeout.
If non-zero then when the timeout expires the command will be killed.
.TP 6n
umask=octal
The file creation mask to use when executing the command.
.TP 6n
use_pty=bool
Allocate a pseudo-tty to run the command in, regardless of whether
or not I/O logging is in use.
By default,
\fBsudo\fR
will only run
the command in a pty when an I/O log plugin is loaded.
.TP 6n
utmp_user=string
User name to use when constructing a new utmp (or utmpx) entry when
\fIset_utmp\fR
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,
\fBsudo\fR
will base the new entry on
the invoking user's existing entry.
.PP
Unsupported values will be ignored.
.RE
.TP 6n
argv_out
The
\fRNULL\fR-terminated
argument vector to pass to the
execve(2)
system call when executing the command.
The plugin is responsible for allocating and populating the vector.
.TP 6n
user_env_out
The
\fRNULL\fR-terminated
environment vector to use when executing the command.
The plugin is responsible for allocating and populating the vector.
.PD 0
.PP
.RE
.PD
.TP 6n
list
.nf
.RS 6n
int (*list)(int argc, char * const argv[],
int verbose, const char *list_user);
.RE
.fi
.RS 6n
.sp
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
\fBconversation\fR()
or
\fBplugin_printf\fR()
function with
\fRSUDO_CONF_ERROR_MSG\fR
to present additional error information to
the user.
.sp
Privileges should be output via the
\fBconversation\fR()
or
\fBplugin_printf\fR()
function using
\fRSUDO_CONV_INFO_MSG\fR,
.TP 6n
verbose
Flag indicating whether to list in verbose mode or not.
.TP 6n
list_user
The name of a different user to list privileges for if the policy
allows it.
If
\fRNULL\fR,
the plugin should list the privileges of the invoking user.
.TP 6n
argc
The number of elements in
\fIargv\fR,
not counting the final
\fRNULL\fR
pointer.
.TP 6n
argv
If
non-\fRNULL\fR,
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
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.
.PD 0
.PP
.RE
.PD
.TP 6n
validate
.nf
.RS 6n
int (*validate)(void);
.RE
.fi
.RS 6n
.sp
The
\fBvalidate\fR()
function is called when
\fBsudo\fR
is run with the
\fB\-v\fR
flag.
For policy plugins such as
\fBsudoers\fR
that cache
authentication credentials, this function will validate and cache
the credentials.
.sp
The
\fBvalidate\fR()
function should be
\fRNULL\fR
if the plugin does not support credential caching.
.sp
Returns 1 on success, 0 on failure and \-1 on error.
On error, the plugin may optionally call the
\fBconversation\fR()
or
\fBplugin_printf\fR()
function with
\fRSUDO_CONF_ERROR_MSG\fR
to present additional
error information to the user.
.RE
.TP 6n
invalidate
.nf
.RS 6n
void (*invalidate)(int remove);
.RE
.fi
.RS 6n
.sp
The
\fBinvalidate\fR()
function is called when
\fBsudo\fR
is called with
the
\fB\-k\fR
or
\fB\-K\fR
flag.
For policy plugins such as
\fBsudoers\fR
that
cache authentication credentials, this function will invalidate the
credentials.
If the
\fIremove\fR
flag is set, the plugin may remove
the credentials instead of simply invalidating them.
.sp
The
\fBinvalidate\fR()
function should be
\fRNULL\fR
if the plugin does not support credential caching.
.RE
.TP 6n
init_session
.nf
.RS 6n
int (*init_session)(struct passwd *pwd, char **user_envp[);
.RE
.fi
.RS 6n
.sp
The
\fBinit_session\fR()
function is called before
\fBsudo\fR
sets up the
execution environment for the command.
It is run in the parent
\fBsudo\fR
process and before any uid or gid changes.
This can be used to perform session setup that is not supported by
\fIcommand_info\fR,
such as opening the PAM session.
The
\fBclose\fR()
function can be
used to tear down the session that was opened by
\fRinit_session\fR.
.sp
The
\fIpwd\fR
argument points to a passwd struct for the user the
command will be run as if the uid the command will run as was found
in the password database, otherwise it will be
\fRNULL\fR.
.sp
The
\fIuser_env\fR
argument points to the environment the command will
run in, in the form of a
\fRNULL\fR-terminated
vector of
\(lqname=value\(rq
strings.
This is the same string passed back to the front end via
the Policy Plugin's
\fIuser_env_out\fR
parameter.
If the
\fBinit_session\fR()
function needs to modify the user environment, it should update the
pointer stored in
\fIuser_env\fR.
The expected use case is to merge the contents of the PAM environment
(if any) with the contents of
\fIuser_env\fR.
NOTE: the
\fIuser_env\fR
parameter is only available
starting with API version 1.2.
A plugin
\fBmust\fR
check the API
version specified by the
\fBsudo\fR
front end before using
\fIuser_env\fR.
Failure to do so may result in a crash.
.sp
Returns 1 on success, 0 on failure and \-1 on error.
On error, the plugin may optionally call the
\fBconversation\fR()
or
\fBplugin_printf\fR()
function with
\fRSUDO_CONF_ERROR_MSG\fR
to present additional
error information to the user.
.RE
.TP 6n
register_hooks
.nf
.RS 6n
void (*register_hooks)(int version,
int (*register_hook)(struct sudo_hook *hook));
.RE
.fi
.RS 6n
.sp
The
\fBregister_hooks\fR()
function is called by the sudo front end to
register any hooks the plugin needs.
If the plugin does not support hooks,
\fRregister_hooks\fR
should be set to the
\fRNULL\fR
pointer.
.sp
The
\fIversion\fR
argument describes the version of the hooks API
supported by the
\fBsudo\fR
front end.
.sp
The
\fBregister_hook\fR()
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
\fRstruct hook\fR
does not match the front end's major hook API version.
.sp
See the
\fIHook function API\fR
section below for more information
about hooks.
.sp
NOTE: the
\fBregister_hooks\fR()
function is only available starting
with API version 1.2.
If the
\fBsudo\fR
front end doesn't support API
version 1.2 or higher,
\fRregister_hooks\fR
will not be called.
.RE
.TP 6n
deregister_hooks
.nf
.RS 6n
void (*deregister_hooks)(int version,
int (*deregister_hook)(struct sudo_hook *hook));
.RE
.fi
.RS 6n
.sp
The
\fBderegister_hooks\fR()
function is called by the sudo front end
to deregister any hooks the plugin has registered.
If the plugin does not support hooks,
\fRderegister_hooks\fR
should be set to the
\fRNULL\fR
pointer.
.sp
The
\fIversion\fR
argument describes the version of the hooks API
supported by the
\fBsudo\fR
front end.
.sp
The
\fBderegister_hook\fR()
function should be used to deregister any
hooks that were put in place by the
\fBregister_hook\fR()
function.
If the plugin tries to deregister a hook that the front end does not support,
\fRderegister_hook\fR
will return an error.
.sp
See the
\fIHook function API\fR
section below for more information
about hooks.
.sp
NOTE: the
\fBderegister_hooks\fR()
function is only available starting
with API version 1.2.
If the
\fBsudo\fR
front end doesn't support API
version 1.2 or higher,
\fRderegister_hooks\fR
will not be called.
.RE
.PP
\fIPolicy Plugin Version Macros\fR
.nf
.sp
.RS 0n
/* 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)
.RE
.fi
.SS "I/O plugin API"
.nf
.RS 0n
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 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[]);
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);
int (*log_ttyout)(const char *buf, unsigned int len);
int (*log_stdin)(const char *buf, unsigned int len);
int (*log_stdout)(const char *buf, unsigned int len);
int (*log_stderr)(const char *buf, unsigned int len);
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);
int (*log_suspend)(int signo);
};
.RE
.fi
.PP
When an I/O plugin is loaded,
\fBsudo\fR
runs the command in a pseudo-tty.
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,
\fBsudo\fR
will open a pipe to capture
the I/O for logging before passing it on.
.PP
The log_ttyin function receives the raw user input from the terminal
device (note that this will include input even when echo is disabled,
such as when a password is read).
The log_ttyout function receives output from the pseudo-tty that is
suitable for replaying the user's session at a later time.
The
\fBlog_stdin\fR(),
\fBlog_stdout\fR()
and
\fBlog_stderr\fR()
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
\fRNULL\fR
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
(\-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
The io_plugin struct has the following fields:
.TP 6n
type
The
\fRtype\fR
field should always be set to
\fRSUDO_IO_PLUGIN\fR.
.TP 6n
version
The
\fRversion\fR
field should be set to
\fRSUDO_API_VERSION\fR.
.sp
This allows
\fBsudo\fR
to determine the API version the plugin was
built against.
.TP 6n
open
.nf
.RS 6n
int (*open)(unsigned int version, sudo_conv_t conversation,
sudo_printf_t 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[]);
.RE
.fi
.RS 6n
.sp
The
\fBopen\fR()
function is run before the
\fBlog_ttyin\fR(),
\fBlog_ttyout\fR(),
\fBlog_stdin\fR(),
\fBlog_stdout\fR(),
\fBlog_stderr\fR(),
\fBlog_suspend\fR(),
\fBchange_winsize\fR(),
or
\fBshow_version\fR()
functions are called.
It is only called if the version is being requested or if the
policy plugin's
\fBcheck_policy\fR()
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,
\fBsudo\fR
will print a usage message before it exits.
If an error occurs, the plugin may optionally call the
\fBconversation\fR()
or
\fBplugin_printf\fR()
function with
\fRSUDO_CONF_ERROR_MSG\fR
to present
additional error information to the user.
.sp
The function arguments are as follows:
.TP 6n
version
The version passed in by
\fBsudo\fR
allows the plugin to determine the
major and minor version number of the plugin API supported by
\fBsudo\fR.
.TP 6n
conversation
A pointer to the
\fBconversation\fR()
function that may be used by the
\fBshow_version\fR()
function to display version information (see
\fBshow_version\fR()
below).
The
\fBconversation\fR()
function may also be used to display additional error message to the user.
The
\fBconversation\fR()
function returns 0 on success and \-1 on failure.
.TP 6n
plugin_printf
A pointer to a
\fBprintf\fR()-style
function that may be used by the
\fBshow_version\fR()
function to display version information (see
show_version below).
The
\fBplugin_printf\fR()
function may also be used to display additional error message to the user.
The
\fBplugin_printf\fR()
function returns number of characters printed on success and \-1 on failure.
.TP 6n
settings
A vector of user-supplied
\fBsudo\fR
settings in the form of
\(lqname=value\(rq
strings.
The vector is terminated by a
\fRNULL\fR
pointer.
These settings correspond to flags the user specified when running
\fBsudo\fR.
As such, they will only be present when the corresponding flag has
been specified on the command line.
.sp
When parsing
\fIsettings\fR,
the plugin should split on the
\fBfirst\fR
equal sign
(\(oq=\(cq)
since the
\fIname\fR
field will never include one
itself but the
\fIvalue\fR
might.
.sp
See the
\fIPolicy plugin API\fR
section for a list of all possible settings.
.TP 6n
user_info
A vector of information about the user running the command in the form of
\(lqname=value\(rq
strings.
The vector is terminated by a
\fRNULL\fR
pointer.
.sp
When parsing
\fIuser_info\fR,
the plugin should split on the
\fBfirst\fR
equal sign
(\(oq=\(cq)
since the
\fIname\fR
field will never include one
itself but the
\fIvalue\fR
might.
.sp
See the
\fIPolicy plugin API\fR
section for a list of all possible strings.
.TP 6n
argc
The number of elements in
\fIargv\fR,
not counting the final
\fRNULL\fR
pointer.
It can be zero, when
\fBsudo\fR
is called with
\fB\-V\fR.
.TP 6n
argv
If
non-\fRNULL\fR,
an argument vector describing a command the user
wishes to run in the same form as what would be passed to the
execve(2)
system call.
.TP 6n
user_env
The user's environment in the form of a
\fRNULL\fR-terminated
vector of
\(lqname=value\(rq
strings.
.sp
When parsing
\fIuser_env\fR,
the plugin should split on the
\fBfirst\fR
equal sign
(\(oq=\(cq)
since the
\fIname\fR
field will never include one
itself but the
\fIvalue\fR
might.
.TP 6n
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
\fRNULL\fR-terminated
array of strings.
If no arguments were specified,
\fIplugin_options\fR
will be the
\fRNULL\fR
pointer.
.sp
NOTE: the
\fIplugin_options\fR
parameter is only available starting with
API version 1.2.
A plugin
\fBmust\fR
check the API version specified
by the
\fBsudo\fR
front end before using
\fIplugin_options\fR.
Failure to do so may result in a crash.
.PD 0
.PP
.RE
.PD
.TP 6n
close
.br
.nf
.RS 6n
void (*close)(int exit_status, int error);
.RE
.fi
.RS 6n
.sp
The
\fBclose\fR()
function is called when the command being run by
\fBsudo\fR
finishes.
.sp
The function arguments are as follows:
.TP 6n
exit_status
The command's exit status, as returned by the
wait(2)
system call.
The value of
\fRexit_status\fR
is undefined if
\fRerror\fR
is non-zero.
.TP 6n
error
.br
If the command could not be executed, this is set to the value of
\fRerrno\fR
set by the
execve(2)
system call.
If the command was successfully executed, the value of
\fRerror\fR
is 0.
.PD 0
.PP
.RE
.PD
.TP 6n
show_version
.nf
.RS 6n
int (*show_version)(int verbose);
.RE
.fi
.RS 6n
.sp
The
\fBshow_version\fR()
function is called by
\fBsudo\fR
when the user specifies
the
\fB\-V\fR
option.
The plugin may display its version information to the user via the
\fBconversation\fR()
or
\fBplugin_printf\fR()
function using
\fRSUDO_CONV_INFO_MSG\fR.
If the user requests detailed version information, the verbose flag will be set.
.sp
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.
.RE
.TP 6n
log_ttyin
.nf
.RS 6n
int (*log_ttyin)(const char *buf, unsigned int len);
.RE
.fi
.RS 6n
.sp
The
\fBlog_ttyin\fR()
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.
.sp
The function arguments are as follows:
.TP 6n
buf
The buffer containing user input.
.TP 6n
len
The length of
\fIbuf\fR
in bytes.
.PD 0
.PP
.RE
.PD
.TP 6n
log_ttyout
.nf
.RS 6n
int (*log_ttyout)(const char *buf, unsigned int len);
.RE
.fi
.RS 6n
.sp
The
\fBlog_ttyout\fR()
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.
.sp
The function arguments are as follows:
.TP 6n
buf
The buffer containing command output.
.TP 6n
len
The length of
\fIbuf\fR
in bytes.
.PD 0
.PP
.RE
.PD
.TP 6n
log_stdin
.nf
.RS 6n
int (*log_stdin)(const char *buf, unsigned int len);
.RE
.fi
.RS 6n
.sp
The
\fBlog_stdin\fR()
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.
.sp
The function arguments are as follows:
.TP 6n
buf
The buffer containing user input.
.TP 6n
len
The length of
\fIbuf\fR
in bytes.
.PD 0
.PP
.RE
.PD
.TP 6n
log_stdout
.nf
.RS 6n
int (*log_stdout)(const char *buf, unsigned int len);
.RE
.fi
.RS 6n
.sp
The
\fBlog_stdout\fR()
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.
.sp
The function arguments are as follows:
.TP 6n
buf
The buffer containing command output.
.TP 6n
len
The length of
\fIbuf\fR
in bytes.
.PD 0
.PP
.RE
.PD
.TP 6n
log_stderr
.nf
.RS 6n
int (*log_stderr)(const char *buf, unsigned int len);
.RE
.fi
.RS 6n
.sp
The
\fBlog_stderr\fR()
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.
.sp
The function arguments are as follows:
.TP 6n
buf
The buffer containing command output.
.TP 6n
len
The length of
\fIbuf\fR
in bytes.
.PD 0
.PP
.RE
.PD
.TP 6n
register_hooks
See the
\fIPolicy plugin API\fR
section for a description of
\fRregister_hooks\fR.
.TP 6n
deregister_hooks
See the
\fIPolicy plugin API\fR
section for a description of
\fRderegister_hooks\fR.
.TP 6n
change_winsize
.nf
.RS 6n
int (*change_winsize)(unsigned int lines, unsigned int cols);
.RE
.fi
.RS 6n
.sp
The
\fBchange_winsize\fR()
function is called whenever the window size of the terminal changes from
the initial values specified in the
\fRuser_info\fR
list.
Returns \-1 if an error occurred, in which case no further calls to
\fBchange_winsize\fR()
will be made,
.RE
.TP 6n
log_suspend
.nf
.RS 6n
int (*log_suspend)(int signo);
.RE
.fi
.RS 6n
.sp
The
\fBlog_suspend\fR()
function is called whenever a command is suspended or resumed.
The
\fIsigno\fR
argument is either the signal that caused the command to be suspended or
\fRSIGCONT\fR
if the command was 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
\fBlog_suspend\fR()
will be made,
.RE
.PP
\fII/O Plugin Version Macros\fR
.PP
Same as for the
\fIPolicy plugin API\fR.
.SS "Signal handlers"
The
\fBsudo\fR
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:
.TP 3n
\fB\(bu\fR
\fRSIGALRM\fR
.PD 0
.TP 3n
\fB\(bu\fR
\fRSIGHUP\fR
.TP 3n
\fB\(bu\fR
\fRSIGINT\fR
.TP 3n
\fB\(bu\fR
\fRSIGPIPE\fR
.TP 3n
\fB\(bu\fR
\fRSIGQUIT\fR
.TP 3n
\fB\(bu\fR
\fRSIGTERM\fR
.TP 3n
\fB\(bu\fR
\fRSIGTSTP\fR
.TP 3n
\fB\(bu\fR
\fRSIGUSR1\fR
.TP 3n
\fB\(bu\fR
\fRSIGUSR2\fR
.PD
.PP
If a fatal signal is received before the command is executed,
\fBsudo\fR
will call the plugin's
\fBclose\fR()
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
\fBclose\fR()
function.
An exception to this is
\fRSIGPIPE\fR,
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
\fBsudo\fR
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
\fBsudo\fR
front end functions as well.
.PP
\fIHook structure\fR
.PP
Hooks in
\fBsudo\fR
are described by the following structure:
.nf
.sp
.RS 0n
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;
};
.RE
.fi
.PP
The
\fRsudo_hook\fR
structure has the following fields:
.TP 6n
hook_version
The
\fRhook_version\fR
field should be set to
\fRSUDO_HOOK_VERSION\fR.
.TP 6n
hook_type
The
\fRhook_type\fR
field may be one of the following supported hook types:
.PP
.RS 6n
.PD 0
.TP 6n
\fRSUDO_HOOK_SETENV\fR
The C library
setenv(3)
function.
Any registered hooks will run before the C library implementation.
The
\fRhook_fn\fR
field should
be a function that matches the following typedef:
.nf
.sp
.RS 6n
typedef int (*sudo_hook_fn_setenv_t)(const char *name,
const char *value, int overwrite, void *closure);
.RE
.fi
.RS 6n
.sp
If the registered hook does not match the typedef the results are
unspecified.
.RE
.PD
.TP 6n
\fRSUDO_HOOK_UNSETENV\fR
The C library
unsetenv(3)
function.
Any registered hooks will run before the C library implementation.
The
\fRhook_fn\fR
field should
be a function that matches the following typedef:
.nf
.sp
.RS 6n
typedef int (*sudo_hook_fn_unsetenv_t)(const char *name,
void *closure);
.RE
.fi
.TP 6n
\fRSUDO_HOOK_GETENV\fR
The C library
getenv(3)
function.
Any registered hooks will run before the C library implementation.
The
\fRhook_fn\fR
field should
be a function that matches the following typedef:
.nf
.sp
.RS 6n
typedef int (*sudo_hook_fn_getenv_t)(const char *name,
char **value, void *closure);
.RE
.fi
.RS 6n
.sp
If the registered hook does not match the typedef the results are
unspecified.
.RE
.TP 6n
\fRSUDO_HOOK_PUTENV\fR
The C library
putenv(3)
function.
Any registered hooks will run before the C library implementation.
The
\fRhook_fn\fR
field should
be a function that matches the following typedef:
.nf
.sp
.RS 6n
typedef int (*sudo_hook_fn_putenv_t)(char *string,
void *closure);
.RE
.fi
.RS 6n
.sp
If the registered hook does not match the typedef the results are
unspecified.
.RE
.PD 0
.PP
.RE
.PD
.TP 6n
hook_fn
sudo_hook_fn_t hook_fn;
.sp
The
\fRhook_fn\fR
field should be set to the plugin's hook implementation.
The actual function arguments will vary depending on the
\fRhook_type\fR
(see
\fRhook_type\fR
above).
In all cases, the
\fRclosure\fR
field of
\fRstruct sudo_hook\fR
is passed as the last function parameter.
This can be used to pass arbitrary data to the plugin's hook implementation.
.sp
The function return value may be one of the following:
.PP
.RS 6n
.PD 0
.TP 6n
\fRSUDO_HOOK_RET_ERROR\fR
The hook function encountered an error.
.PD
.TP 6n
\fRSUDO_HOOK_RET_NEXT\fR
The hook completed without error, go on to the next hook (including
the native implementation if applicable).
For example, a
getenv(3)
hook might return
\fRSUDO_HOOK_RET_NEXT\fR
if the specified variable was not found in the private copy of the environment.
.TP 6n
\fRSUDO_HOOK_RET_STOP\fR
The hook completed without error, stop processing hooks for this invocation.
This can be used to replace the native implementation.
For example, a
\fRsetenv\fR
hook that operates on a private copy of
the environment but leaves
\fRenviron\fR
unchanged.
.PD 0
.PP
.RE
.PD
.PP
Note that it is very easy to create an infinite loop when hooking
C library functions.
For example, a
getenv(3)
hook that calls the
snprintf(3)
function may create a loop if the
snprintf(3)
implementation calls
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:
.nf
.sp
.RS 0n
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;
.RE
.fi
.PP
\fIHook API Version Macros\fR
.nf
.sp
.RS 0n
/* 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)
.RE
.fi
.PP
For getters and setters see the
\fIPolicy plugin API\fR.
.SS "Remote command execution"
The
\fBsudo\fR
front end does not have native support for running remote commands.
However, starting with
\fBsudo\fR
1.8.8, the
\fB\-h\fR
option may be used to specify a remote host that is passed
to the policy plugin.
A plugin may also accept a
\fIrunas_user\fR
in the form of
\(lquser@hostname\(rq
which will work with older versions of
\fBsudo\fR.
It is anticipated that remote commands will be supported by executing a
\(lqhelper\(rq
program.
The policy plugin should setup the execution environment such that the
\fBsudo\fR
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
\fBssh\fR
to perform remote command execution.
The helper program would be responsible for running
\fBssh\fR
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
Note that remote
\fBsudoedit\fR
functionality must be handled by the policy plugin, not
\fBsudo\fR
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
\fBconversation\fR()
function.
A plugin should not attempt to read directly from the standard input
or the user's tty (neither of which are guaranteed to exist).
The caller must include a trailing newline in
\fRmsg\fR
if one is to be printed.
.PP
A
\fBprintf\fR()-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
\fIConversation function structures\fR
.PP
The conversation function takes as arguments pointers to the following
structures:
.nf
.sp
.RS 0n
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 255
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;
};
.RE
.fi
.PP
Pointers to the
\fBconversation\fR()
and
\fBprintf\fR()-style
functions are passed
in to the plugin's
\fBopen\fR()
function when the plugin is initialized.
The following type definitions can be used in the declaration of the
\fBopen\fR()
function:
.nf
.sp
.RS 0n
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 *fmt, ...);
.RE
.fi
.PP
To use the
\fBconversation\fR()
function, the plugin must pass an array of
\fRsudo_conv_message\fR
and
\fRsudo_conv_reply\fR
structures.
There must be a
\fRstruct sudo_conv_message\fR
and
\fRstruct sudo_conv_reply\fR
for
each message in the conversation, that is, both arrays must have the same
number of elements.
Each
\fRstruct sudo_conv_reply\fR
must have its
\fIreply\fR
member initialized to
\fRNULL\fR.
The
\fRstruct sudo_conv_callback\fR
pointer, if not
\fRNULL\fR,
should contain function pointers to be called when the
\fBsudo\fR
process is suspended and/or resumed during conversation input.
The
\fIon_suspend\fR
and
\fIon_resume\fR
functions are called with the signal that caused
\fBsudo\fR
to be suspended and the
\fIclosure\fR
pointer from the
\fRstruct sudo_conv_callback\fR.
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.
Note that the functions are not actually invoked from within a signal handler.
.PP
The
\fImsg_type\fR
must be set to one of the following values:
.TP 6n
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
\fIreplies\fR
array, and it will never be
\fRNULL\fR.
.TP 6n
SUDO_CONV_PROMPT_ECHO_ON
Prompt the user for input with echo enabled.
The reply will be stored in the
\fIreplies\fR
array, and it will never be
\fRNULL\fR.
.TP 6n
SUDO_CONV_ERROR_MSG
Display an error message.
The message is written to the standard error unless the
\fRSUDO_CONV_PREFER_TTY\fR
flag is set, in which case it is written to the user's terminal if possible.
.TP 6n
SUDO_CONV_INFO_MSG
Display a message.
The message is written to the standard output unless the
\fRSUDO_CONV_PREFER_TTY\fR
flag is set, in which case it is written to the user's terminal if possible.
.TP 6n
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
\fIreplies\fR
array, and it will never be
\fRNULL\fR.
This can be used to provide visual feedback to the user while reading
sensitive information that should not be displayed.
.PP
In addition to the above values, the following flag bits may also be set:
.TP 6n
SUDO_CONV_PROMPT_ECHO_OK
Allow input to be read when echo cannot be disabled
when the message type is
\fRSUDO_CONV_PROMPT_ECHO_OFF\fR
or
\fRSUDO_CONV_PROMPT_MASK\fR.
By default,
\fBsudo\fR
will refuse to read input if the echo cannot be disabled for those
message types.
.TP 6n
SUDO_CONV_PREFER_TTY
When displaying a message via
\fRSUDO_CONV_ERROR_MSG\fR
or
\fRSUDO_CONV_INFO_MSG\fR,
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
The user's terminal is always used when possible for input,
this flag is only used for output.
\fRSUDO_CONV_ERROR_MSG\fR
or
\fRSUDO_CONV_INFO_MSG\fR
was used.
.PP
The
\fItimeout\fR
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
\fRstruct sudo_conv_reply\fR,
if it is not
\fRNULL\fR.
\fRSUDO_CONV_REPL_MAX\fR
represents the maximum length of the reply buffer (not including
the trailing NUL character).
In practical terms, this is the longest password
\fBsudo\fR
will support.
It is also useful as a maximum value for the
\fBmemset_s\fR()
function when clearing passwords filled in by the conversation function.
.PP
The
\fBprintf\fR()-style
function uses the same underlying mechanism as the
\fBconversation\fR()
function but only supports
\fRSUDO_CONV_INFO_MSG\fR
and
\fRSUDO_CONV_ERROR_MSG\fR
for the
\fImsg_type\fR
parameter.
It can be more convenient than using the
\fBconversation\fR()
function if no user reply is needed and supports standard
\fBprintf\fR()
escape sequences.
.PP
See the sample plugin for an example of the
\fBconversation\fR()
function usage.
.SS "Sudoers group plugin API"
The
\fBsudoers\fR
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
\fBsudo\fR,
\fIgroup_file\fR
and
\fIsystem_group\fR,
are detailed in
sudoers(@mansectform@).
Third party group plugins include a QAS AD plugin available from Quest Software.
.PP
A group plugin must declare and populate a
\fRsudoers_group_plugin\fR
struct in the global scope.
This structure contains pointers to the functions that implement plugin
initialization, cleanup and group lookup.
.nf
.sp
.RS 0n
struct sudoers_group_plugin {
unsigned int version;
int (*init)(int version, sudo_printf_t sudo_printf,
char *const argv[]);
void (*cleanup)(void);
int (*query)(const char *user, const char *group,
const struct passwd *pwd);
};
.RE
.fi
.PP
The
\fRsudoers_group_plugin\fR
struct has the following fields:
.TP 6n
version
The
\fRversion\fR
field should be set to GROUP_API_VERSION.
.sp
This allows
\fBsudoers\fR
to determine the API version the group plugin
was built against.
.TP 6n
init
.nf
.RS 6n
int (*init)(int version, sudo_printf_t plugin_printf,
char *const argv[]);
.RE
.fi
.RS 6n
.sp
The
\fBinit\fR()
function is called after
\fIsudoers\fR
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
\fBplugin_printf\fR()
function with
\fRSUDO_CONF_ERROR_MSG\fR
to present additional error information
to the user.
.sp
The function arguments are as follows:
.TP 6n
version
The version passed in by
\fBsudoers\fR
allows the plugin to determine the
major and minor version number of the group plugin API supported by
\fBsudoers\fR.
.TP 6n
plugin_printf
A pointer to a
\fBprintf\fR()-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.
.TP 6n
argv
A
\fRNULL\fR-terminated
array of arguments generated from the
\fIgroup_plugin\fR
option in
\fIsudoers\fR.
If no arguments were given,
\fIargv\fR
will be
\fRNULL\fR.
.PD 0
.PP
.RE
.PD
.TP 6n
cleanup
.nf
.RS 6n
void (*cleanup)();
.RE
.fi
.RS 6n
.sp
The
\fBcleanup\fR()
function is called when
\fBsudoers\fR
has finished its
group checks.
The plugin should free any memory it has allocated and close open file handles.
.RE
.TP 6n
query
.br
.nf
.RS 6n
int (*query)(const char *user, const char *group,
const struct passwd *pwd);
.RE
.fi
.RS 6n
.sp
The
\fBquery\fR()
function is used to ask the group plugin whether
\fIuser\fR
is a member of
\fIgroup\fR.
.sp
The function arguments are as follows:
.TP 6n
user
The name of the user being looked up in the external group database.
.TP 6n
group
.br
The name of the group being queried.
.TP 6n
pwd
The password database entry for
\fIuser\fR,
if any.
If
\fIuser\fR
is not
present in the password database,
\fIpwd\fR
will be
\fRNULL\fR.
.PD 0
.PP
.RE
.PD
.PP
\fIGroup API Version Macros\fR
.nf
.sp
.RS 0n
/* 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)
.RE
.fi
For getters and setters see the
\fIPolicy plugin API\fR.
.SH "PLUGIN API CHANGELOG"
The following revisions have been made to the Sudo Plugin API.
.TP 6n
Version 1.0
Initial API version.
.TP 6n
Version 1.1 (sudo 1.8.0)
The I/O logging plugin's
\fBopen\fR()
function was modified to take the
\fRcommand_info\fR
list as an argument.
.TP 6n
Version 1.2 (sudo 1.8.5)
The Policy and I/O logging plugins'
\fBopen\fR()
functions are now passed
a list of plugin parameters if any are specified in
sudo.conf(@mansectform@).
.sp
A simple hooks API has been introduced to allow plugins to hook in to the
system's environment handling functions.
.sp
The
\fRinit_session\fR
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.
.TP 6n
Version 1.3 (sudo 1.8.7)
Support for the
\fIexec_background\fR
entry has been added to the
\fRcommand_info\fR
list.
.sp
The
\fImax_groups\fR
and
\fIplugin_dir\fR
entries were added to the
\fRsettings\fR
list.
.sp
The
\fBversion\fR()
and
\fBclose\fR()
functions are now optional.
Previously, a missing
\fBversion\fR()
or
\fBclose\fR()
function would result in a crash.
If no policy plugin
\fBclose\fR()
function is defined, a default
\fBclose\fR()
function will be provided by the
\fBsudo\fR
front end that displays a warning if the command could not be
executed.
.sp
The
\fBsudo\fR
front end now installs default signal handlers to trap common signals
while the plugin functions are run.
.TP 6n
Version 1.4 (sudo 1.8.8)
The
\fIremote_host\fR
entry was added to the
\fRsettings\fR
list.
.TP 6n
Version 1.5 (sudo 1.8.9)
The
\fIpreserve_fds\fR
entry was added to the
\fRcommand_info\fR
list.
.TP 6n
Version 1.6 (sudo 1.8.11)
The behavior when an I/O logging plugin returns an error
(\-1)
has changed.
Previously, the
\fBsudo\fR
front end took no action when the
\fBlog_ttyin\fR(),
\fBlog_ttyout\fR(),
\fBlog_stdin\fR(),
\fBlog_stdout\fR(),
or
\fBlog_stderr\fR()
function returned an error.
.sp
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.
.TP 6n
Version 1.7 (sudo 1.8.12)
The
\fIplugin_path\fR
entry was added to the
\fRsettings\fR
list.
.sp
The
\fIdebug_flags\fR
entry now starts with a debug file path name and may occur multiple
times if there are multiple plugin-specific Debug lines in the
sudo.conf(@mansectform@) file.
.TP 6n
Version 1.8 (sudo 1.8.15)
The
\fIsudoedit_checkdir\fR
and
\fIsudoedit_follow\fR
entries were added to the
\fRcommand_info\fR
list.
The default value of
\fIsudoedit_checkdir\fR
was changed to true in sudo 1.8.16.
.sp
The sudo
\fIconversation\fR
function now takes a pointer to a
\fRstruct sudo_conv_callback\fR
as its fourth argument.
The
\fRsudo_conv_t\fR
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.
.TP 6n
Version 1.9 (sudo 1.8.16)
The
\fIexecfd\fR
entry was added to the
\fRcommand_info\fR
list.
.TP 6n
Version 1.10 (sudo 1.8.19)
The
\fIumask\fR
entry was added to the
\fRuser_info\fR
list.
The
\fIiolog_group\fR,
\fIiolog_mode\fR,
and
\fIiolog_user\fR
entries were added to the
\fRcommand_info\fR
list.
.TP 6n
Version 1.11 (sudo 1.8.20)
The
\fItimeout\fR
entry was added to the
\fRsettings\fR
list.
.TP 6n
Version 1.12 (sudo 1.8.21)
The
\fRchange_winsize\fR
field was added to the io_plugin struct.
.TP 6n
Version 1.13 (sudo 1.8.26)
The
\fRlog_suspend\fR
field was added to the io_plugin struct.
.SH "SEE ALSO"
sudo.conf(@mansectform@),
sudoers(@mansectform@),
sudo(@mansectsu@)
.SH "AUTHORS"
Many people have worked on
\fBsudo\fR
over the years; this version consists of code written primarily by:
.sp
.RS 6n
Todd C. Miller
.RE
.PP
See the CONTRIBUTORS file in the
\fBsudo\fR
distribution (https://www.sudo.ws/contributors.html) for an
exhaustive list of people who have contributed to
\fBsudo\fR.
.SH "BUGS"
If you feel you have found a bug in
\fBsudo\fR,
please 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"
\fBsudo\fR
is provided
\(lqAS IS\(rq
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 file distributed with
\fBsudo\fR
or https://www.sudo.ws/license.html for complete details.
|