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
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
|
/*
* Copyright (c) 1998-2009 Sendmail, Inc. and its suppliers.
* All rights reserved.
* Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved.
* Copyright (c) 1988, 1993
* The Regents of the University of California. All rights reserved.
*
* By using this file, you agree to the terms and conditions set
* forth in the LICENSE file which can be found at the top level of
* the sendmail distribution.
*
*/
#include <sendmail.h>
SM_RCSID("@(#)$Id: conf.c,v 8.1153 2009/12/18 17:25:12 ca Exp $")
#include <sm/sendmail.h>
#include <sendmail/pathnames.h>
#if NEWDB
# include "sm/bdb.h"
#endif /* NEWDB */
#include <daemon.h>
#include "map.h"
#ifdef DEC
# if NETINET6
/* for the IPv6 device lookup */
# define _SOCKADDR_LEN
# include <macros.h>
# endif /* NETINET6 */
#endif /* DEC */
# include <sys/ioctl.h>
# include <sys/param.h>
#include <limits.h>
#if NETINET || NETINET6
# include <arpa/inet.h>
#endif /* NETINET || NETINET6 */
#if HASULIMIT && defined(HPUX11)
# include <ulimit.h>
#endif /* HASULIMIT && defined(HPUX11) */
static void setupmaps __P((void));
static void setupmailers __P((void));
static void setupqueues __P((void));
static int get_num_procs_online __P((void));
static int add_hostnames __P((SOCKADDR *));
#if NETINET6 && NEEDSGETIPNODE
static struct hostent *getipnodebyname __P((char *, int, int, int *));
static struct hostent *getipnodebyaddr __P((char *, int, int, int *));
#endif /* NETINET6 && NEEDSGETIPNODE */
/*
** CONF.C -- Sendmail Configuration Tables.
**
** Defines the configuration of this installation.
**
** Configuration Variables:
** HdrInfo -- a table describing well-known header fields.
** Each entry has the field name and some flags,
** which are described in sendmail.h.
**
** Notes:
** I have tried to put almost all the reasonable
** configuration information into the configuration
** file read at runtime. My intent is that anything
** here is a function of the version of UNIX you
** are running, or is really static -- for example
** the headers are a superset of widely used
** protocols. If you find yourself playing with
** this file too much, you may be making a mistake!
*/
/*
** Header info table
** Final (null) entry contains the flags used for any other field.
**
** Not all of these are actually handled specially by sendmail
** at this time. They are included as placeholders, to let
** you know that "someday" I intend to have sendmail do
** something with them.
*/
struct hdrinfo HdrInfo[] =
{
/* originator fields, most to least significant */
{ "resent-sender", H_FROM|H_RESENT, NULL },
{ "resent-from", H_FROM|H_RESENT, NULL },
{ "resent-reply-to", H_FROM|H_RESENT, NULL },
{ "sender", H_FROM, NULL },
{ "from", H_FROM, NULL },
{ "reply-to", H_FROM, NULL },
{ "errors-to", H_FROM|H_ERRORSTO, NULL },
{ "full-name", H_ACHECK, NULL },
{ "return-receipt-to", H_RECEIPTTO, NULL },
{ "delivery-receipt-to", H_RECEIPTTO, NULL },
{ "disposition-notification-to", H_FROM, NULL },
/* destination fields */
{ "to", H_RCPT, NULL },
{ "resent-to", H_RCPT|H_RESENT, NULL },
{ "cc", H_RCPT, NULL },
{ "resent-cc", H_RCPT|H_RESENT, NULL },
{ "bcc", H_RCPT|H_BCC, NULL },
{ "resent-bcc", H_RCPT|H_BCC|H_RESENT, NULL },
{ "apparently-to", H_RCPT, NULL },
/* message identification and control */
{ "message-id", 0, NULL },
{ "resent-message-id", H_RESENT, NULL },
{ "message", H_EOH, NULL },
{ "text", H_EOH, NULL },
/* date fields */
{ "date", 0, NULL },
{ "resent-date", H_RESENT, NULL },
/* trace fields */
{ "received", H_TRACE|H_FORCE, NULL },
{ "x400-received", H_TRACE|H_FORCE, NULL },
{ "via", H_TRACE|H_FORCE, NULL },
{ "mail-from", H_TRACE|H_FORCE, NULL },
/* miscellaneous fields */
{ "comments", H_FORCE|H_ENCODABLE, NULL },
{ "return-path", H_FORCE|H_ACHECK|H_BINDLATE, NULL },
{ "content-transfer-encoding", H_CTE, NULL },
{ "content-type", H_CTYPE, NULL },
{ "content-length", H_ACHECK, NULL },
{ "subject", H_ENCODABLE, NULL },
{ "x-authentication-warning", H_FORCE, NULL },
{ NULL, 0, NULL }
};
/*
** Privacy values
*/
struct prival PrivacyValues[] =
{
{ "public", PRIV_PUBLIC },
{ "needmailhelo", PRIV_NEEDMAILHELO },
{ "needexpnhelo", PRIV_NEEDEXPNHELO },
{ "needvrfyhelo", PRIV_NEEDVRFYHELO },
{ "noexpn", PRIV_NOEXPN },
{ "novrfy", PRIV_NOVRFY },
{ "restrictexpand", PRIV_RESTRICTEXPAND },
{ "restrictmailq", PRIV_RESTRICTMAILQ },
{ "restrictqrun", PRIV_RESTRICTQRUN },
{ "noetrn", PRIV_NOETRN },
{ "noverb", PRIV_NOVERB },
{ "authwarnings", PRIV_AUTHWARNINGS },
{ "noreceipts", PRIV_NORECEIPTS },
{ "nobodyreturn", PRIV_NOBODYRETN },
{ "goaway", PRIV_GOAWAY },
{ "noactualrecipient", PRIV_NOACTUALRECIPIENT },
{ NULL, 0 }
};
/*
** DontBlameSendmail values
*/
struct dbsval DontBlameSendmailValues[] =
{
{ "safe", DBS_SAFE },
{ "assumesafechown", DBS_ASSUMESAFECHOWN },
{ "groupwritabledirpathsafe", DBS_GROUPWRITABLEDIRPATHSAFE },
{ "groupwritableforwardfilesafe",
DBS_GROUPWRITABLEFORWARDFILESAFE },
{ "groupwritableincludefilesafe",
DBS_GROUPWRITABLEINCLUDEFILESAFE },
{ "groupwritablealiasfile", DBS_GROUPWRITABLEALIASFILE },
{ "worldwritablealiasfile", DBS_WORLDWRITABLEALIASFILE },
{ "forwardfileinunsafedirpath", DBS_FORWARDFILEINUNSAFEDIRPATH },
{ "includefileinunsafedirpath", DBS_INCLUDEFILEINUNSAFEDIRPATH },
{ "mapinunsafedirpath", DBS_MAPINUNSAFEDIRPATH },
{ "linkedaliasfileinwritabledir",
DBS_LINKEDALIASFILEINWRITABLEDIR },
{ "linkedclassfileinwritabledir",
DBS_LINKEDCLASSFILEINWRITABLEDIR },
{ "linkedforwardfileinwritabledir",
DBS_LINKEDFORWARDFILEINWRITABLEDIR },
{ "linkedincludefileinwritabledir",
DBS_LINKEDINCLUDEFILEINWRITABLEDIR },
{ "linkedmapinwritabledir", DBS_LINKEDMAPINWRITABLEDIR },
{ "linkedserviceswitchfileinwritabledir",
DBS_LINKEDSERVICESWITCHFILEINWRITABLEDIR },
{ "filedeliverytohardlink", DBS_FILEDELIVERYTOHARDLINK },
{ "filedeliverytosymlink", DBS_FILEDELIVERYTOSYMLINK },
{ "writemaptohardlink", DBS_WRITEMAPTOHARDLINK },
{ "writemaptosymlink", DBS_WRITEMAPTOSYMLINK },
{ "writestatstohardlink", DBS_WRITESTATSTOHARDLINK },
{ "writestatstosymlink", DBS_WRITESTATSTOSYMLINK },
{ "forwardfileingroupwritabledirpath",
DBS_FORWARDFILEINGROUPWRITABLEDIRPATH },
{ "includefileingroupwritabledirpath",
DBS_INCLUDEFILEINGROUPWRITABLEDIRPATH },
{ "classfileinunsafedirpath", DBS_CLASSFILEINUNSAFEDIRPATH },
{ "errorheaderinunsafedirpath", DBS_ERRORHEADERINUNSAFEDIRPATH },
{ "helpfileinunsafedirpath", DBS_HELPFILEINUNSAFEDIRPATH },
{ "forwardfileinunsafedirpathsafe",
DBS_FORWARDFILEINUNSAFEDIRPATHSAFE },
{ "includefileinunsafedirpathsafe",
DBS_INCLUDEFILEINUNSAFEDIRPATHSAFE },
{ "runprograminunsafedirpath", DBS_RUNPROGRAMINUNSAFEDIRPATH },
{ "runwritableprogram", DBS_RUNWRITABLEPROGRAM },
{ "nonrootsafeaddr", DBS_NONROOTSAFEADDR },
{ "truststickybit", DBS_TRUSTSTICKYBIT },
{ "dontwarnforwardfileinunsafedirpath",
DBS_DONTWARNFORWARDFILEINUNSAFEDIRPATH },
{ "insufficiententropy", DBS_INSUFFICIENTENTROPY },
{ "groupreadablesasldbfile", DBS_GROUPREADABLESASLDBFILE },
{ "groupwritablesasldbfile", DBS_GROUPWRITABLESASLDBFILE },
{ "groupwritableforwardfile", DBS_GROUPWRITABLEFORWARDFILE },
{ "groupwritableincludefile", DBS_GROUPWRITABLEINCLUDEFILE },
{ "worldwritableforwardfile", DBS_WORLDWRITABLEFORWARDFILE },
{ "worldwritableincludefile", DBS_WORLDWRITABLEINCLUDEFILE },
{ "groupreadablekeyfile", DBS_GROUPREADABLEKEYFILE },
#if _FFR_GROUPREADABLEAUTHINFOFILE
{ "groupreadableadefaultauthinfofile",
DBS_GROUPREADABLEAUTHINFOFILE },
#endif /* _FFR_GROUPREADABLEAUTHINFOFILE */
{ NULL, 0 }
};
/*
** Miscellaneous stuff.
*/
int DtableSize = 50; /* max open files; reset in 4.2bsd */
/*
** SETDEFAULTS -- set default values
**
** Some of these must be initialized using direct code since they
** depend on run-time values. So let's do all of them this way.
**
** Parameters:
** e -- the default envelope.
**
** Returns:
** none.
**
** Side Effects:
** Initializes a bunch of global variables to their
** default values.
*/
#define MINUTES * 60
#define HOURS * 60 MINUTES
#define DAYS * 24 HOURS
#ifndef MAXRULERECURSION
# define MAXRULERECURSION 50 /* max ruleset recursion depth */
#endif /* ! MAXRULERECURSION */
void
setdefaults(e)
register ENVELOPE *e;
{
int i;
int numprocs;
struct passwd *pw;
numprocs = get_num_procs_online();
SpaceSub = ' '; /* option B */
QueueLA = 8 * numprocs; /* option x */
RefuseLA = 12 * numprocs; /* option X */
WkRecipFact = 30000L; /* option y */
WkClassFact = 1800L; /* option z */
WkTimeFact = 90000L; /* option Z */
QueueFactor = WkRecipFact * 20; /* option q */
QueueMode = QM_NORMAL; /* what queue items to act upon */
FileMode = (RealUid != geteuid()) ? 0644 : 0600;
/* option F */
QueueFileMode = (RealUid != geteuid()) ? 0644 : 0600;
/* option QueueFileMode */
if (((pw = sm_getpwnam("mailnull")) != NULL && pw->pw_uid != 0) ||
((pw = sm_getpwnam("sendmail")) != NULL && pw->pw_uid != 0) ||
((pw = sm_getpwnam("daemon")) != NULL && pw->pw_uid != 0))
{
DefUid = pw->pw_uid; /* option u */
DefGid = pw->pw_gid; /* option g */
DefUser = newstr(pw->pw_name);
}
else
{
DefUid = 1; /* option u */
DefGid = 1; /* option g */
setdefuser();
}
TrustedUid = 0;
if (tTd(37, 4))
sm_dprintf("setdefaults: DefUser=%s, DefUid=%d, DefGid=%d\n",
DefUser != NULL ? DefUser : "<1:1>",
(int) DefUid, (int) DefGid);
CheckpointInterval = 10; /* option C */
MaxHopCount = 25; /* option h */
set_delivery_mode(SM_FORK, e); /* option d */
e->e_errormode = EM_PRINT; /* option e */
e->e_qgrp = NOQGRP;
e->e_qdir = NOQDIR;
e->e_xfqgrp = NOQGRP;
e->e_xfqdir = NOQDIR;
e->e_ctime = curtime();
SevenBitInput = false; /* option 7 */
MaxMciCache = 1; /* option k */
MciCacheTimeout = 5 MINUTES; /* option K */
LogLevel = 9; /* option L */
#if MILTER
MilterLogLevel = -1;
#endif /* MILTER */
inittimeouts(NULL, false); /* option r */
PrivacyFlags = PRIV_PUBLIC; /* option p */
MeToo = true; /* option m */
SendMIMEErrors = true; /* option f */
SuperSafe = SAFE_REALLY; /* option s */
clrbitmap(DontBlameSendmail); /* DontBlameSendmail option */
#if MIME8TO7
MimeMode = MM_CVTMIME|MM_PASS8BIT; /* option 8 */
#else /* MIME8TO7 */
MimeMode = MM_PASS8BIT;
#endif /* MIME8TO7 */
for (i = 0; i < MAXTOCLASS; i++)
{
TimeOuts.to_q_return[i] = 5 DAYS; /* option T */
TimeOuts.to_q_warning[i] = 0; /* option T */
}
ServiceSwitchFile = "/etc/mail/service.switch";
ServiceCacheMaxAge = (time_t) 10;
HostsFile = _PATH_HOSTS;
PidFile = newstr(_PATH_SENDMAILPID);
MustQuoteChars = "@,;:\\()[].'";
MciInfoTimeout = 30 MINUTES;
MaxRuleRecursion = MAXRULERECURSION;
MaxAliasRecursion = 10;
MaxMacroRecursion = 10;
ColonOkInAddr = true;
DontLockReadFiles = true;
DontProbeInterfaces = DPI_PROBEALL;
DoubleBounceAddr = "postmaster";
MaxHeadersLength = MAXHDRSLEN;
MaxMimeHeaderLength = MAXLINE;
MaxMimeFieldLength = MaxMimeHeaderLength / 2;
MaxForwardEntries = 0;
FastSplit = 1;
MaxNOOPCommands = MAXNOOPCOMMANDS;
#if SASL
AuthMechanisms = newstr(AUTH_MECHANISMS);
AuthRealm = NULL;
MaxSLBits = INT_MAX;
#endif /* SASL */
#if STARTTLS
TLS_Srv_Opts = TLS_I_SRV;
#endif /* STARTTLS */
#ifdef HESIOD_INIT
HesiodContext = NULL;
#endif /* HESIOD_INIT */
#if NETINET6
/* Detect if IPv6 is available at run time */
i = socket(AF_INET6, SOCK_STREAM, 0);
if (i >= 0)
{
InetMode = AF_INET6;
(void) close(i);
}
else
InetMode = AF_INET;
#else /* NETINET6 */
InetMode = AF_INET;
#endif /* NETINET6 */
ControlSocketName = NULL;
memset(&ConnectOnlyTo, '\0', sizeof(ConnectOnlyTo));
DataFileBufferSize = 4096;
XscriptFileBufferSize = 4096;
for (i = 0; i < MAXRWSETS; i++)
RuleSetNames[i] = NULL;
#if MILTER
InputFilters[0] = NULL;
#endif /* MILTER */
RejectLogInterval = 3 HOURS;
#if REQUIRES_DIR_FSYNC
RequiresDirfsync = true;
#endif /* REQUIRES_DIR_FSYNC */
#if _FFR_RCPTTHROTDELAY
BadRcptThrottleDelay = 1;
#endif /* _FFR_RCPTTHROTDELAY */
ConnectionRateWindowSize = 60;
setupmaps();
setupqueues();
setupmailers();
setupheaders();
}
/*
** SETDEFUSER -- set/reset DefUser using DefUid (for initgroups())
*/
void
setdefuser()
{
struct passwd *defpwent;
static char defuserbuf[40];
DefUser = defuserbuf;
defpwent = sm_getpwuid(DefUid);
(void) sm_strlcpy(defuserbuf,
(defpwent == NULL || defpwent->pw_name == NULL)
? "nobody" : defpwent->pw_name,
sizeof(defuserbuf));
if (tTd(37, 4))
sm_dprintf("setdefuser: DefUid=%d, DefUser=%s\n",
(int) DefUid, DefUser);
}
/*
** SETUPQUEUES -- initialize default queues
**
** The mqueue QUEUE structure gets filled in after readcf() but
** we need something to point to now for the mailer setup,
** which use "mqueue" as default queue.
*/
static void
setupqueues()
{
char buf[100];
MaxRunnersPerQueue = 1;
(void) sm_strlcpy(buf, "mqueue, P=/var/spool/mqueue", sizeof(buf));
makequeue(buf, false);
}
/*
** SETUPMAILERS -- initialize default mailers
*/
static void
setupmailers()
{
char buf[100];
(void) sm_strlcpy(buf, "prog, P=/bin/sh, F=lsouDq9, T=X-Unix/X-Unix/X-Unix, A=sh -c \201u",
sizeof(buf));
makemailer(buf);
(void) sm_strlcpy(buf, "*file*, P=[FILE], F=lsDFMPEouq9, T=X-Unix/X-Unix/X-Unix, A=FILE \201u",
sizeof(buf));
makemailer(buf);
(void) sm_strlcpy(buf, "*include*, P=/dev/null, F=su, A=INCLUDE \201u",
sizeof(buf));
makemailer(buf);
initerrmailers();
}
/*
** SETUPMAPS -- set up map classes
*/
#define MAPDEF(name, ext, flags, parse, open, close, lookup, store) \
{ \
extern bool parse __P((MAP *, char *)); \
extern bool open __P((MAP *, int)); \
extern void close __P((MAP *)); \
extern char *lookup __P((MAP *, char *, char **, int *)); \
extern void store __P((MAP *, char *, char *)); \
s = stab(name, ST_MAPCLASS, ST_ENTER); \
s->s_mapclass.map_cname = name; \
s->s_mapclass.map_ext = ext; \
s->s_mapclass.map_cflags = flags; \
s->s_mapclass.map_parse = parse; \
s->s_mapclass.map_open = open; \
s->s_mapclass.map_close = close; \
s->s_mapclass.map_lookup = lookup; \
s->s_mapclass.map_store = store; \
}
static void
setupmaps()
{
register STAB *s;
#if NEWDB
# if DB_VERSION_MAJOR > 1
int major_v, minor_v, patch_v;
(void) db_version(&major_v, &minor_v, &patch_v);
if (major_v != DB_VERSION_MAJOR || minor_v != DB_VERSION_MINOR)
{
errno = 0;
syserr("Berkeley DB version mismatch: compiled against %d.%d.%d, run-time linked against %d.%d.%d",
DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH,
major_v, minor_v, patch_v);
}
# endif /* DB_VERSION_MAJOR > 1 */
MAPDEF("hash", ".db", MCF_ALIASOK|MCF_REBUILDABLE,
map_parseargs, hash_map_open, db_map_close,
db_map_lookup, db_map_store);
MAPDEF("btree", ".db", MCF_ALIASOK|MCF_REBUILDABLE,
map_parseargs, bt_map_open, db_map_close,
db_map_lookup, db_map_store);
#endif /* NEWDB */
#if NDBM
MAPDEF("dbm", ".dir", MCF_ALIASOK|MCF_REBUILDABLE,
map_parseargs, ndbm_map_open, ndbm_map_close,
ndbm_map_lookup, ndbm_map_store);
#endif /* NDBM */
#if NIS
MAPDEF("nis", NULL, MCF_ALIASOK,
map_parseargs, nis_map_open, null_map_close,
nis_map_lookup, null_map_store);
#endif /* NIS */
#if NISPLUS
MAPDEF("nisplus", NULL, MCF_ALIASOK,
map_parseargs, nisplus_map_open, null_map_close,
nisplus_map_lookup, null_map_store);
#endif /* NISPLUS */
#if LDAPMAP
MAPDEF("ldap", NULL, MCF_ALIASOK|MCF_NOTPERSIST,
ldapmap_parseargs, ldapmap_open, ldapmap_close,
ldapmap_lookup, null_map_store);
#endif /* LDAPMAP */
#if PH_MAP
MAPDEF("ph", NULL, MCF_NOTPERSIST,
ph_map_parseargs, ph_map_open, ph_map_close,
ph_map_lookup, null_map_store);
#endif /* PH_MAP */
#if MAP_NSD
/* IRIX 6.5 nsd support */
MAPDEF("nsd", NULL, MCF_ALIASOK,
map_parseargs, null_map_open, null_map_close,
nsd_map_lookup, null_map_store);
#endif /* MAP_NSD */
#if HESIOD
MAPDEF("hesiod", NULL, MCF_ALIASOK|MCF_ALIASONLY,
map_parseargs, hes_map_open, hes_map_close,
hes_map_lookup, null_map_store);
#endif /* HESIOD */
#if NETINFO
MAPDEF("netinfo", NULL, MCF_ALIASOK,
map_parseargs, ni_map_open, null_map_close,
ni_map_lookup, null_map_store);
#endif /* NETINFO */
#if 0
MAPDEF("dns", NULL, 0,
dns_map_init, null_map_open, null_map_close,
dns_map_lookup, null_map_store);
#endif /* 0 */
#if NAMED_BIND
# if DNSMAP
# if _FFR_DNSMAP_ALIASABLE
MAPDEF("dns", NULL, MCF_ALIASOK,
dns_map_parseargs, dns_map_open, null_map_close,
dns_map_lookup, null_map_store);
# else /* _FFR_DNSMAP_ALIASABLE */
MAPDEF("dns", NULL, 0,
dns_map_parseargs, dns_map_open, null_map_close,
dns_map_lookup, null_map_store);
# endif /* _FFR_DNSMAP_ALIASABLE */
# endif /* DNSMAP */
#endif /* NAMED_BIND */
#if NAMED_BIND
/* best MX DNS lookup */
MAPDEF("bestmx", NULL, MCF_OPTFILE,
map_parseargs, null_map_open, null_map_close,
bestmx_map_lookup, null_map_store);
#endif /* NAMED_BIND */
MAPDEF("host", NULL, 0,
host_map_init, null_map_open, null_map_close,
host_map_lookup, null_map_store);
MAPDEF("text", NULL, MCF_ALIASOK,
map_parseargs, text_map_open, null_map_close,
text_map_lookup, null_map_store);
MAPDEF("stab", NULL, MCF_ALIASOK|MCF_ALIASONLY,
map_parseargs, stab_map_open, null_map_close,
stab_map_lookup, stab_map_store);
MAPDEF("implicit", NULL, MCF_ALIASOK|MCF_ALIASONLY|MCF_REBUILDABLE,
map_parseargs, impl_map_open, impl_map_close,
impl_map_lookup, impl_map_store);
/* access to system passwd file */
MAPDEF("user", NULL, MCF_OPTFILE,
map_parseargs, user_map_open, null_map_close,
user_map_lookup, null_map_store);
/* dequote map */
MAPDEF("dequote", NULL, 0,
dequote_init, null_map_open, null_map_close,
dequote_map, null_map_store);
#if MAP_REGEX
MAPDEF("regex", NULL, 0,
regex_map_init, null_map_open, null_map_close,
regex_map_lookup, null_map_store);
#endif /* MAP_REGEX */
#if USERDB
/* user database */
MAPDEF("userdb", ".db", 0,
map_parseargs, null_map_open, null_map_close,
udb_map_lookup, null_map_store);
#endif /* USERDB */
/* arbitrary programs */
MAPDEF("program", NULL, MCF_ALIASOK,
map_parseargs, null_map_open, null_map_close,
prog_map_lookup, null_map_store);
/* sequenced maps */
MAPDEF("sequence", NULL, MCF_ALIASOK,
seq_map_parse, null_map_open, null_map_close,
seq_map_lookup, seq_map_store);
/* switched interface to sequenced maps */
MAPDEF("switch", NULL, MCF_ALIASOK,
map_parseargs, switch_map_open, null_map_close,
seq_map_lookup, seq_map_store);
/* null map lookup -- really for internal use only */
MAPDEF("null", NULL, MCF_ALIASOK|MCF_OPTFILE,
map_parseargs, null_map_open, null_map_close,
null_map_lookup, null_map_store);
/* syslog map -- logs information to syslog */
MAPDEF("syslog", NULL, 0,
syslog_map_parseargs, null_map_open, null_map_close,
syslog_map_lookup, null_map_store);
/* macro storage map -- rulesets can set macros */
MAPDEF("macro", NULL, 0,
dequote_init, null_map_open, null_map_close,
macro_map_lookup, null_map_store);
/* arithmetic map -- add/subtract/compare */
MAPDEF("arith", NULL, 0,
dequote_init, null_map_open, null_map_close,
arith_map_lookup, null_map_store);
#if SOCKETMAP
/* arbitrary daemons */
MAPDEF("socket", NULL, MCF_ALIASOK,
map_parseargs, socket_map_open, socket_map_close,
socket_map_lookup, null_map_store);
#endif /* SOCKETMAP */
#if _FFR_DPRINTF_MAP
/* dprintf map -- logs information to syslog */
MAPDEF("dprintf", NULL, 0,
dprintf_map_parseargs, null_map_open, null_map_close,
dprintf_map_lookup, null_map_store);
#endif /* _FFR_DPRINTF_MAP */
if (tTd(38, 2))
{
/* bogus map -- always return tempfail */
MAPDEF("bogus", NULL, MCF_ALIASOK|MCF_OPTFILE,
map_parseargs, null_map_open, null_map_close,
bogus_map_lookup, null_map_store);
}
}
#undef MAPDEF
/*
** INITHOSTMAPS -- initial host-dependent maps
**
** This should act as an interface to any local service switch
** provided by the host operating system.
**
** Parameters:
** none
**
** Returns:
** none
**
** Side Effects:
** Should define maps "host" and "users" as necessary
** for this OS. If they are not defined, they will get
** a default value later. It should check to make sure
** they are not defined first, since it's possible that
** the config file has provided an override.
*/
void
inithostmaps()
{
register int i;
int nmaps;
char *maptype[MAXMAPSTACK];
short mapreturn[MAXMAPACTIONS];
char buf[MAXLINE];
/*
** Make sure we have a host map.
*/
if (stab("host", ST_MAP, ST_FIND) == NULL)
{
/* user didn't initialize: set up host map */
(void) sm_strlcpy(buf, "host host", sizeof(buf));
#if NAMED_BIND
if (ConfigLevel >= 2)
(void) sm_strlcat(buf, " -a. -D", sizeof(buf));
#endif /* NAMED_BIND */
(void) makemapentry(buf);
}
/*
** Set up default aliases maps
*/
nmaps = switch_map_find("aliases", maptype, mapreturn);
for (i = 0; i < nmaps; i++)
{
if (strcmp(maptype[i], "files") == 0 &&
stab("aliases.files", ST_MAP, ST_FIND) == NULL)
{
(void) sm_strlcpy(buf, "aliases.files null",
sizeof(buf));
(void) makemapentry(buf);
}
#if NISPLUS
else if (strcmp(maptype[i], "nisplus") == 0 &&
stab("aliases.nisplus", ST_MAP, ST_FIND) == NULL)
{
(void) sm_strlcpy(buf, "aliases.nisplus nisplus -kalias -vexpansion mail_aliases.org_dir",
sizeof(buf));
(void) makemapentry(buf);
}
#endif /* NISPLUS */
#if NIS
else if (strcmp(maptype[i], "nis") == 0 &&
stab("aliases.nis", ST_MAP, ST_FIND) == NULL)
{
(void) sm_strlcpy(buf, "aliases.nis nis mail.aliases",
sizeof(buf));
(void) makemapentry(buf);
}
#endif /* NIS */
#if NETINFO
else if (strcmp(maptype[i], "netinfo") == 0 &&
stab("aliases.netinfo", ST_MAP, ST_FIND) == NULL)
{
(void) sm_strlcpy(buf, "aliases.netinfo netinfo -z, /aliases",
sizeof(buf));
(void) makemapentry(buf);
}
#endif /* NETINFO */
#if HESIOD
else if (strcmp(maptype[i], "hesiod") == 0 &&
stab("aliases.hesiod", ST_MAP, ST_FIND) == NULL)
{
(void) sm_strlcpy(buf, "aliases.hesiod hesiod aliases",
sizeof(buf));
(void) makemapentry(buf);
}
#endif /* HESIOD */
#if LDAPMAP && defined(SUN_EXTENSIONS) && \
defined(SUN_SIMPLIFIED_LDAP) && HASLDAPGETALIASBYNAME
else if (strcmp(maptype[i], "ldap") == 0 &&
stab("aliases.ldap", ST_MAP, ST_FIND) == NULL)
{
(void) sm_strlcpy(buf, "aliases.ldap ldap -b . -h localhost -k mail=%0 -v mailgroup",
sizeof buf);
(void) makemapentry(buf);
}
#endif /* LDAPMAP && defined(SUN_EXTENSIONS) && ... */
}
if (stab("aliases", ST_MAP, ST_FIND) == NULL)
{
(void) sm_strlcpy(buf, "aliases switch aliases", sizeof(buf));
(void) makemapentry(buf);
}
}
/*
** SWITCH_MAP_FIND -- find the list of types associated with a map
**
** This is the system-dependent interface to the service switch.
**
** Parameters:
** service -- the name of the service of interest.
** maptype -- an out-array of strings containing the types
** of access to use for this service. There can
** be at most MAXMAPSTACK types for a single service.
** mapreturn -- an out-array of return information bitmaps
** for the map.
**
** Returns:
** The number of map types filled in, or -1 for failure.
**
** Side effects:
** Preserves errno so nothing in the routine clobbers it.
*/
#if defined(SOLARIS) || (defined(sony_news) && defined(__svr4))
# define _USE_SUN_NSSWITCH_
#endif /* defined(SOLARIS) || (defined(sony_news) && defined(__svr4)) */
#if _FFR_HPUX_NSSWITCH
# ifdef __hpux
# define _USE_SUN_NSSWITCH_
# endif /* __hpux */
#endif /* _FFR_HPUX_NSSWITCH */
#ifdef _USE_SUN_NSSWITCH_
# include <nsswitch.h>
#endif /* _USE_SUN_NSSWITCH_ */
#if defined(ultrix) || (defined(__osf__) && defined(__alpha))
# define _USE_DEC_SVC_CONF_
#endif /* defined(ultrix) || (defined(__osf__) && defined(__alpha)) */
#ifdef _USE_DEC_SVC_CONF_
# include <sys/svcinfo.h>
#endif /* _USE_DEC_SVC_CONF_ */
int
switch_map_find(service, maptype, mapreturn)
char *service;
char *maptype[MAXMAPSTACK];
short mapreturn[MAXMAPACTIONS];
{
int svcno = 0;
int save_errno = errno;
#ifdef _USE_SUN_NSSWITCH_
struct __nsw_switchconfig *nsw_conf;
enum __nsw_parse_err pserr;
struct __nsw_lookup *lk;
static struct __nsw_lookup lkp0 =
{ "files", {1, 0, 0, 0}, NULL, NULL };
static struct __nsw_switchconfig lkp_default =
{ 0, "sendmail", 3, &lkp0 };
for (svcno = 0; svcno < MAXMAPACTIONS; svcno++)
mapreturn[svcno] = 0;
if ((nsw_conf = __nsw_getconfig(service, &pserr)) == NULL)
lk = lkp_default.lookups;
else
lk = nsw_conf->lookups;
svcno = 0;
while (lk != NULL && svcno < MAXMAPSTACK)
{
maptype[svcno] = lk->service_name;
if (lk->actions[__NSW_NOTFOUND] == __NSW_RETURN)
mapreturn[MA_NOTFOUND] |= 1 << svcno;
if (lk->actions[__NSW_TRYAGAIN] == __NSW_RETURN)
mapreturn[MA_TRYAGAIN] |= 1 << svcno;
if (lk->actions[__NSW_UNAVAIL] == __NSW_RETURN)
mapreturn[MA_TRYAGAIN] |= 1 << svcno;
svcno++;
lk = lk->next;
}
errno = save_errno;
return svcno;
#endif /* _USE_SUN_NSSWITCH_ */
#ifdef _USE_DEC_SVC_CONF_
struct svcinfo *svcinfo;
int svc;
for (svcno = 0; svcno < MAXMAPACTIONS; svcno++)
mapreturn[svcno] = 0;
svcinfo = getsvc();
if (svcinfo == NULL)
goto punt;
if (strcmp(service, "hosts") == 0)
svc = SVC_HOSTS;
else if (strcmp(service, "aliases") == 0)
svc = SVC_ALIASES;
else if (strcmp(service, "passwd") == 0)
svc = SVC_PASSWD;
else
{
errno = save_errno;
return -1;
}
for (svcno = 0; svcno < SVC_PATHSIZE && svcno < MAXMAPSTACK; svcno++)
{
switch (svcinfo->svcpath[svc][svcno])
{
case SVC_LOCAL:
maptype[svcno] = "files";
break;
case SVC_YP:
maptype[svcno] = "nis";
break;
case SVC_BIND:
maptype[svcno] = "dns";
break;
# ifdef SVC_HESIOD
case SVC_HESIOD:
maptype[svcno] = "hesiod";
break;
# endif /* SVC_HESIOD */
case SVC_LAST:
errno = save_errno;
return svcno;
}
}
errno = save_errno;
return svcno;
#endif /* _USE_DEC_SVC_CONF_ */
#if !defined(_USE_SUN_NSSWITCH_) && !defined(_USE_DEC_SVC_CONF_)
/*
** Fall-back mechanism.
*/
STAB *st;
static time_t servicecachetime; /* time service switch was cached */
time_t now = curtime();
for (svcno = 0; svcno < MAXMAPACTIONS; svcno++)
mapreturn[svcno] = 0;
if ((now - servicecachetime) > (time_t) ServiceCacheMaxAge)
{
/* (re)read service switch */
register SM_FILE_T *fp;
long sff = SFF_REGONLY|SFF_OPENASROOT|SFF_NOLOCK;
if (!bitnset(DBS_LINKEDSERVICESWITCHFILEINWRITABLEDIR,
DontBlameSendmail))
sff |= SFF_NOWLINK;
if (ConfigFileRead)
servicecachetime = now;
fp = safefopen(ServiceSwitchFile, O_RDONLY, 0, sff);
if (fp != NULL)
{
char buf[MAXLINE];
while (sm_io_fgets(fp, SM_TIME_DEFAULT, buf,
sizeof(buf)) != NULL)
{
register char *p;
p = strpbrk(buf, "#\n");
if (p != NULL)
*p = '\0';
#ifndef SM_NSSWITCH_DELIMS
# define SM_NSSWITCH_DELIMS " \t"
#endif /* SM_NSSWITCH_DELIMS */
p = strpbrk(buf, SM_NSSWITCH_DELIMS);
if (p != NULL)
*p++ = '\0';
if (buf[0] == '\0')
continue;
if (p == NULL)
{
sm_syslog(LOG_ERR, NOQID,
"Bad line on %.100s: %.100s",
ServiceSwitchFile,
buf);
continue;
}
while (isascii(*p) && isspace(*p))
p++;
if (*p == '\0')
continue;
/*
** Find/allocate space for this service entry.
** Space for all of the service strings
** are allocated at once. This means
** that we only have to free the first
** one to free all of them.
*/
st = stab(buf, ST_SERVICE, ST_ENTER);
if (st->s_service[0] != NULL)
sm_free((void *) st->s_service[0]); /* XXX */
p = newstr(p);
for (svcno = 0; svcno < MAXMAPSTACK; )
{
if (*p == '\0')
break;
st->s_service[svcno++] = p;
p = strpbrk(p, " \t");
if (p == NULL)
break;
*p++ = '\0';
while (isascii(*p) && isspace(*p))
p++;
}
if (svcno < MAXMAPSTACK)
st->s_service[svcno] = NULL;
}
(void) sm_io_close(fp, SM_TIME_DEFAULT);
}
}
/* look up entry in cache */
st = stab(service, ST_SERVICE, ST_FIND);
if (st != NULL && st->s_service[0] != NULL)
{
/* extract data */
svcno = 0;
while (svcno < MAXMAPSTACK)
{
maptype[svcno] = st->s_service[svcno];
if (maptype[svcno++] == NULL)
break;
}
errno = save_errno;
return --svcno;
}
#endif /* !defined(_USE_SUN_NSSWITCH_) && !defined(_USE_DEC_SVC_CONF_) */
#if !defined(_USE_SUN_NSSWITCH_)
/* if the service file doesn't work, use an absolute fallback */
# ifdef _USE_DEC_SVC_CONF_
punt:
# endif /* _USE_DEC_SVC_CONF_ */
for (svcno = 0; svcno < MAXMAPACTIONS; svcno++)
mapreturn[svcno] = 0;
svcno = 0;
if (strcmp(service, "aliases") == 0)
{
maptype[svcno++] = "files";
# if defined(AUTO_NETINFO_ALIASES) && defined (NETINFO)
maptype[svcno++] = "netinfo";
# endif /* defined(AUTO_NETINFO_ALIASES) && defined (NETINFO) */
# ifdef AUTO_NIS_ALIASES
# if NISPLUS
maptype[svcno++] = "nisplus";
# endif /* NISPLUS */
# if NIS
maptype[svcno++] = "nis";
# endif /* NIS */
# endif /* AUTO_NIS_ALIASES */
errno = save_errno;
return svcno;
}
if (strcmp(service, "hosts") == 0)
{
# if NAMED_BIND
maptype[svcno++] = "dns";
# else /* NAMED_BIND */
# if defined(sun) && !defined(BSD)
/* SunOS */
maptype[svcno++] = "nis";
# endif /* defined(sun) && !defined(BSD) */
# endif /* NAMED_BIND */
# if defined(AUTO_NETINFO_HOSTS) && defined (NETINFO)
maptype[svcno++] = "netinfo";
# endif /* defined(AUTO_NETINFO_HOSTS) && defined (NETINFO) */
maptype[svcno++] = "files";
errno = save_errno;
return svcno;
}
errno = save_errno;
return -1;
#endif /* !defined(_USE_SUN_NSSWITCH_) */
}
/*
** USERNAME -- return the user id of the logged in user.
**
** Parameters:
** none.
**
** Returns:
** The login name of the logged in user.
**
** Side Effects:
** none.
**
** Notes:
** The return value is statically allocated.
*/
char *
username()
{
static char *myname = NULL;
extern char *getlogin();
register struct passwd *pw;
/* cache the result */
if (myname == NULL)
{
myname = getlogin();
if (myname == NULL || myname[0] == '\0')
{
pw = sm_getpwuid(RealUid);
if (pw != NULL)
myname = pw->pw_name;
}
else
{
uid_t uid = RealUid;
if ((pw = sm_getpwnam(myname)) == NULL ||
(uid != 0 && uid != pw->pw_uid))
{
pw = sm_getpwuid(uid);
if (pw != NULL)
myname = pw->pw_name;
}
}
if (myname == NULL || myname[0] == '\0')
{
syserr("554 5.3.0 Who are you?");
myname = "postmaster";
}
else if (strpbrk(myname, ",;:/|\"\\") != NULL)
myname = addquotes(myname, NULL);
else
myname = sm_pstrdup_x(myname);
}
return myname;
}
/*
** TTYPATH -- Get the path of the user's tty
**
** Returns the pathname of the user's tty. Returns NULL if
** the user is not logged in or if s/he has write permission
** denied.
**
** Parameters:
** none
**
** Returns:
** pathname of the user's tty.
** NULL if not logged in or write permission denied.
**
** Side Effects:
** none.
**
** WARNING:
** Return value is in a local buffer.
**
** Called By:
** savemail
*/
char *
ttypath()
{
struct stat stbuf;
register char *pathn;
extern char *ttyname();
extern char *getlogin();
/* compute the pathname of the controlling tty */
if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL &&
(pathn = ttyname(0)) == NULL)
{
errno = 0;
return NULL;
}
/* see if we have write permission */
if (stat(pathn, &stbuf) < 0 || !bitset(S_IWOTH, stbuf.st_mode))
{
errno = 0;
return NULL;
}
/* see if the user is logged in */
if (getlogin() == NULL)
return NULL;
/* looks good */
return pathn;
}
/*
** CHECKCOMPAT -- check for From and To person compatible.
**
** This routine can be supplied on a per-installation basis
** to determine whether a person is allowed to send a message.
** This allows restriction of certain types of internet
** forwarding or registration of users.
**
** If the hosts are found to be incompatible, an error
** message should be given using "usrerr" and an EX_ code
** should be returned. You can also set to->q_status to
** a DSN-style status code.
**
** EF_NO_BODY_RETN can be set in e->e_flags to suppress the
** body during the return-to-sender function; this should be done
** on huge messages. This bit may already be set by the ESMTP
** protocol.
**
** Parameters:
** to -- the person being sent to.
**
** Returns:
** an exit status
**
** Side Effects:
** none (unless you include the usrerr stuff)
*/
int
checkcompat(to, e)
register ADDRESS *to;
register ENVELOPE *e;
{
if (tTd(49, 1))
sm_dprintf("checkcompat(to=%s, from=%s)\n",
to->q_paddr, e->e_from.q_paddr);
#ifdef EXAMPLE_CODE
/* this code is intended as an example only */
register STAB *s;
s = stab("arpa", ST_MAILER, ST_FIND);
if (s != NULL && strcmp(e->e_from.q_mailer->m_name, "local") != 0 &&
to->q_mailer == s->s_mailer)
{
usrerr("553 No ARPA mail through this machine: see your system administration");
/* e->e_flags |= EF_NO_BODY_RETN; to suppress body on return */
to->q_status = "5.7.1";
return EX_UNAVAILABLE;
}
#endif /* EXAMPLE_CODE */
return EX_OK;
}
#ifdef SUN_EXTENSIONS
static void
init_md_sun()
{
struct stat sbuf;
/* Check for large file descriptor */
if (fstat(fileno(stdin), &sbuf) < 0)
{
if (errno == EOVERFLOW)
{
perror("stdin");
exit(EX_NOINPUT);
}
}
}
#endif /* SUN_EXTENSIONS */
/*
** INIT_MD -- do machine dependent initializations
**
** Systems that have global modes that should be set should do
** them here rather than in main.
*/
#ifdef _AUX_SOURCE
# include <compat.h>
#endif /* _AUX_SOURCE */
#if SHARE_V1
# include <shares.h>
#endif /* SHARE_V1 */
void
init_md(argc, argv)
int argc;
char **argv;
{
#ifdef _AUX_SOURCE
setcompat(getcompat() | COMPAT_BSDPROT);
#endif /* _AUX_SOURCE */
#ifdef SUN_EXTENSIONS
init_md_sun();
#endif /* SUN_EXTENSIONS */
#if _CONVEX_SOURCE
/* keep gethostby*() from stripping the local domain name */
set_domain_trim_off();
#endif /* _CONVEX_SOURCE */
#if defined(__QNX__) && !defined(__QNXNTO__)
/*
** Due to QNX's network distributed nature, you can target a tcpip
** stack on a different node in the qnx network; this patch lets
** this feature work. The __sock_locate() must be done before the
** environment is clear.
*/
__sock_locate();
#endif /* __QNX__ */
#if SECUREWARE || defined(_SCO_unix_)
set_auth_parameters(argc, argv);
# ifdef _SCO_unix_
/*
** This is required for highest security levels (the kernel
** won't let it call set*uid() or run setuid binaries without
** it). It may be necessary on other SECUREWARE systems.
*/
if (getluid() == -1)
setluid(0);
# endif /* _SCO_unix_ */
#endif /* SECUREWARE || defined(_SCO_unix_) */
#ifdef VENDOR_DEFAULT
VendorCode = VENDOR_DEFAULT;
#else /* VENDOR_DEFAULT */
VendorCode = VENDOR_BERKELEY;
#endif /* VENDOR_DEFAULT */
}
/*
** INIT_VENDOR_MACROS -- vendor-dependent macro initializations
**
** Called once, on startup.
**
** Parameters:
** e -- the global envelope.
**
** Returns:
** none.
**
** Side Effects:
** vendor-dependent.
*/
void
init_vendor_macros(e)
register ENVELOPE *e;
{
}
/*
** GETLA -- get the current load average
**
** This code stolen from la.c.
**
** Parameters:
** none.
**
** Returns:
** The current load average as an integer.
**
** Side Effects:
** none.
*/
/* try to guess what style of load average we have */
#define LA_ZERO 1 /* always return load average as zero */
#define LA_INT 2 /* read kmem for avenrun; interpret as long */
#define LA_FLOAT 3 /* read kmem for avenrun; interpret as float */
#define LA_SUBR 4 /* call getloadavg */
#define LA_MACH 5 /* MACH load averages (as on NeXT boxes) */
#define LA_SHORT 6 /* read kmem for avenrun; interpret as short */
#define LA_PROCSTR 7 /* read string ("1.17") from /proc/loadavg */
#define LA_READKSYM 8 /* SVR4: use MIOC_READKSYM ioctl call */
#define LA_DGUX 9 /* special DGUX implementation */
#define LA_HPUX 10 /* special HPUX implementation */
#define LA_IRIX6 11 /* special IRIX 6.2 implementation */
#define LA_KSTAT 12 /* special Solaris kstat(3k) implementation */
#define LA_DEVSHORT 13 /* read short from a device */
#define LA_ALPHAOSF 14 /* Digital UNIX (OSF/1 on Alpha) table() call */
#define LA_PSET 15 /* Solaris per-processor-set load average */
#define LA_LONGLONG 17 /* read kmem for avenrun; interpret as long long */
/* do guesses based on general OS type */
#ifndef LA_TYPE
# define LA_TYPE LA_ZERO
#endif /* ! LA_TYPE */
#ifndef FSHIFT
# if defined(unixpc)
# define FSHIFT 5
# endif /* defined(unixpc) */
# if defined(__alpha) || defined(IRIX)
# define FSHIFT 10
# endif /* defined(__alpha) || defined(IRIX) */
#endif /* ! FSHIFT */
#ifndef FSHIFT
# define FSHIFT 8
#endif /* ! FSHIFT */
#ifndef FSCALE
# define FSCALE (1 << FSHIFT)
#endif /* ! FSCALE */
#ifndef LA_AVENRUN
# ifdef SYSTEM5
# define LA_AVENRUN "avenrun"
# else /* SYSTEM5 */
# define LA_AVENRUN "_avenrun"
# endif /* SYSTEM5 */
#endif /* ! LA_AVENRUN */
/* _PATH_KMEM should be defined in <paths.h> */
#ifndef _PATH_KMEM
# define _PATH_KMEM "/dev/kmem"
#endif /* ! _PATH_KMEM */
#if (LA_TYPE == LA_INT) || (LA_TYPE == LA_FLOAT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG)
# include <nlist.h>
/* _PATH_UNIX should be defined in <paths.h> */
# ifndef _PATH_UNIX
# if defined(SYSTEM5)
# define _PATH_UNIX "/unix"
# else /* defined(SYSTEM5) */
# define _PATH_UNIX "/vmunix"
# endif /* defined(SYSTEM5) */
# endif /* ! _PATH_UNIX */
# ifdef _AUX_SOURCE
struct nlist Nl[2];
# else /* _AUX_SOURCE */
struct nlist Nl[] =
{
{ LA_AVENRUN },
{ 0 },
};
# endif /* _AUX_SOURCE */
# define X_AVENRUN 0
int
getla()
{
int j;
static int kmem = -1;
# if LA_TYPE == LA_INT
long avenrun[3];
# else /* LA_TYPE == LA_INT */
# if LA_TYPE == LA_SHORT
short avenrun[3];
# else
# if LA_TYPE == LA_LONGLONG
long long avenrun[3];
# else /* LA_TYPE == LA_LONGLONG */
double avenrun[3];
# endif /* LA_TYPE == LA_LONGLONG */
# endif /* LA_TYPE == LA_SHORT */
# endif /* LA_TYPE == LA_INT */
extern off_t lseek();
if (kmem < 0)
{
# ifdef _AUX_SOURCE
(void) sm_strlcpy(Nl[X_AVENRUN].n_name, LA_AVENRUN,
sizeof(Nl[X_AVENRUN].n_name));
Nl[1].n_name[0] = '\0';
# endif /* _AUX_SOURCE */
# if defined(_AIX3) || defined(_AIX4)
if (knlist(Nl, 1, sizeof(Nl[0])) < 0)
# else /* defined(_AIX3) || defined(_AIX4) */
if (nlist(_PATH_UNIX, Nl) < 0)
# endif /* defined(_AIX3) || defined(_AIX4) */
{
if (tTd(3, 1))
sm_dprintf("getla: nlist(%s): %s\n", _PATH_UNIX,
sm_errstring(errno));
return -1;
}
if (Nl[X_AVENRUN].n_value == 0)
{
if (tTd(3, 1))
sm_dprintf("getla: nlist(%s, %s) ==> 0\n",
_PATH_UNIX, LA_AVENRUN);
return -1;
}
# ifdef NAMELISTMASK
Nl[X_AVENRUN].n_value &= NAMELISTMASK;
# endif /* NAMELISTMASK */
kmem = open(_PATH_KMEM, 0, 0);
if (kmem < 0)
{
if (tTd(3, 1))
sm_dprintf("getla: open(/dev/kmem): %s\n",
sm_errstring(errno));
return -1;
}
if ((j = fcntl(kmem, F_GETFD, 0)) < 0 ||
fcntl(kmem, F_SETFD, j | FD_CLOEXEC) < 0)
{
if (tTd(3, 1))
sm_dprintf("getla: fcntl(/dev/kmem, FD_CLOEXEC): %s\n",
sm_errstring(errno));
(void) close(kmem);
kmem = -1;
return -1;
}
}
if (tTd(3, 20))
sm_dprintf("getla: symbol address = %#lx\n",
(unsigned long) Nl[X_AVENRUN].n_value);
if (lseek(kmem, (off_t) Nl[X_AVENRUN].n_value, SEEK_SET) == -1 ||
read(kmem, (char *) avenrun, sizeof(avenrun)) != sizeof(avenrun))
{
/* thank you Ian */
if (tTd(3, 1))
sm_dprintf("getla: lseek or read: %s\n",
sm_errstring(errno));
return -1;
}
# if (LA_TYPE == LA_INT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG)
if (tTd(3, 5))
{
# if LA_TYPE == LA_SHORT
sm_dprintf("getla: avenrun = %d", avenrun[0]);
if (tTd(3, 15))
sm_dprintf(", %d, %d", avenrun[1], avenrun[2]);
# else /* LA_TYPE == LA_SHORT */
# if LA_TYPE == LA_LONGLONG
sm_dprintf("getla: avenrun = %lld", avenrun[0]);
if (tTd(3, 15))
sm_dprintf(", %lld, %lld", avenrun[1], avenrun[2]);
# else /* LA_TYPE == LA_LONGLONG */
sm_dprintf("getla: avenrun = %ld", avenrun[0]);
if (tTd(3, 15))
sm_dprintf(", %ld, %ld", avenrun[1], avenrun[2]);
# endif /* LA_TYPE == LA_LONGLONG */
# endif /* LA_TYPE == LA_SHORT */
sm_dprintf("\n");
}
if (tTd(3, 1))
sm_dprintf("getla: %d\n",
(int) (avenrun[0] + FSCALE/2) >> FSHIFT);
return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT);
# else /* (LA_TYPE == LA_INT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG) */
if (tTd(3, 5))
{
sm_dprintf("getla: avenrun = %g", avenrun[0]);
if (tTd(3, 15))
sm_dprintf(", %g, %g", avenrun[1], avenrun[2]);
sm_dprintf("\n");
}
if (tTd(3, 1))
sm_dprintf("getla: %d\n", (int) (avenrun[0] +0.5));
return ((int) (avenrun[0] + 0.5));
# endif /* (LA_TYPE == LA_INT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG) */
}
#endif /* (LA_TYPE == LA_INT) || (LA_TYPE == LA_FLOAT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG) */
#if LA_TYPE == LA_READKSYM
# include <sys/ksym.h>
int
getla()
{
int j;
static int kmem = -1;
long avenrun[3];
struct mioc_rksym mirk;
if (kmem < 0)
{
kmem = open("/dev/kmem", 0, 0);
if (kmem < 0)
{
if (tTd(3, 1))
sm_dprintf("getla: open(/dev/kmem): %s\n",
sm_errstring(errno));
return -1;
}
if ((j = fcntl(kmem, F_GETFD, 0)) < 0 ||
fcntl(kmem, F_SETFD, j | FD_CLOEXEC) < 0)
{
if (tTd(3, 1))
sm_dprintf("getla: fcntl(/dev/kmem, FD_CLOEXEC): %s\n",
sm_errstring(errno));
(void) close(kmem);
kmem = -1;
return -1;
}
}
mirk.mirk_symname = LA_AVENRUN;
mirk.mirk_buf = avenrun;
mirk.mirk_buflen = sizeof(avenrun);
if (ioctl(kmem, MIOC_READKSYM, &mirk) < 0)
{
if (tTd(3, 1))
sm_dprintf("getla: ioctl(MIOC_READKSYM) failed: %s\n",
sm_errstring(errno));
return -1;
}
if (tTd(3, 5))
{
sm_dprintf("getla: avenrun = %d", avenrun[0]);
if (tTd(3, 15))
sm_dprintf(", %d, %d", avenrun[1], avenrun[2]);
sm_dprintf("\n");
}
if (tTd(3, 1))
sm_dprintf("getla: %d\n",
(int) (avenrun[0] + FSCALE/2) >> FSHIFT);
return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT);
}
#endif /* LA_TYPE == LA_READKSYM */
#if LA_TYPE == LA_DGUX
# include <sys/dg_sys_info.h>
int
getla()
{
struct dg_sys_info_load_info load_info;
dg_sys_info((long *)&load_info,
DG_SYS_INFO_LOAD_INFO_TYPE, DG_SYS_INFO_LOAD_VERSION_0);
if (tTd(3, 1))
sm_dprintf("getla: %d\n", (int) (load_info.one_minute + 0.5));
return ((int) (load_info.one_minute + 0.5));
}
#endif /* LA_TYPE == LA_DGUX */
#if LA_TYPE == LA_HPUX
/* forward declarations to keep gcc from complaining */
struct pst_dynamic;
struct pst_status;
struct pst_static;
struct pst_vminfo;
struct pst_diskinfo;
struct pst_processor;
struct pst_lv;
struct pst_swapinfo;
# include <sys/param.h>
# include <sys/pstat.h>
int
getla()
{
struct pst_dynamic pstd;
if (pstat_getdynamic(&pstd, sizeof(struct pst_dynamic),
(size_t) 1, 0) == -1)
return 0;
if (tTd(3, 1))
sm_dprintf("getla: %d\n", (int) (pstd.psd_avg_1_min + 0.5));
return (int) (pstd.psd_avg_1_min + 0.5);
}
#endif /* LA_TYPE == LA_HPUX */
#if LA_TYPE == LA_SUBR
int
getla()
{
double avenrun[3];
if (getloadavg(avenrun, sizeof(avenrun) / sizeof(avenrun[0])) < 0)
{
if (tTd(3, 1))
sm_dprintf("getla: getloadavg failed: %s",
sm_errstring(errno));
return -1;
}
if (tTd(3, 1))
sm_dprintf("getla: %d\n", (int) (avenrun[0] +0.5));
return ((int) (avenrun[0] + 0.5));
}
#endif /* LA_TYPE == LA_SUBR */
#if LA_TYPE == LA_MACH
/*
** This has been tested on NEXTSTEP release 2.1/3.X.
*/
# if defined(NX_CURRENT_COMPILER_RELEASE) && NX_CURRENT_COMPILER_RELEASE > NX_COMPILER_RELEASE_3_0
# include <mach/mach.h>
# else /* defined(NX_CURRENT_COMPILER_RELEASE) && NX_CURRENT_COMPILER_RELEASE > NX_COMPILER_RELEASE_3_0 */
# include <mach.h>
# endif /* defined(NX_CURRENT_COMPILER_RELEASE) && NX_CURRENT_COMPILER_RELEASE > NX_COMPILER_RELEASE_3_0 */
int
getla()
{
processor_set_t default_set;
kern_return_t error;
unsigned int info_count;
struct processor_set_basic_info info;
host_t host;
error = processor_set_default(host_self(), &default_set);
if (error != KERN_SUCCESS)
{
if (tTd(3, 1))
sm_dprintf("getla: processor_set_default failed: %s",
sm_errstring(errno));
return -1;
}
info_count = PROCESSOR_SET_BASIC_INFO_COUNT;
if (processor_set_info(default_set, PROCESSOR_SET_BASIC_INFO,
&host, (processor_set_info_t)&info,
&info_count) != KERN_SUCCESS)
{
if (tTd(3, 1))
sm_dprintf("getla: processor_set_info failed: %s",
sm_errstring(errno));
return -1;
}
if (tTd(3, 1))
sm_dprintf("getla: %d\n",
(int) ((info.load_average + (LOAD_SCALE / 2)) /
LOAD_SCALE));
return (int) (info.load_average + (LOAD_SCALE / 2)) / LOAD_SCALE;
}
#endif /* LA_TYPE == LA_MACH */
#if LA_TYPE == LA_PROCSTR
# if SM_CONF_BROKEN_STRTOD
ERROR: This OS has most likely a broken strtod() implemenentation.
ERROR: The function is required for getla().
ERROR: Check the compilation options _LA_PROCSTR and
ERROR: _SM_CONF_BROKEN_STRTOD (without the leading _).
# endif /* SM_CONF_BROKEN_STRTOD */
/*
** Read /proc/loadavg for the load average. This is assumed to be
** in a format like "0.15 0.12 0.06".
**
** Initially intended for Linux. This has been in the kernel
** since at least 0.99.15.
*/
# ifndef _PATH_LOADAVG
# define _PATH_LOADAVG "/proc/loadavg"
# endif /* ! _PATH_LOADAVG */
int
getla()
{
double avenrun;
register int result;
SM_FILE_T *fp;
fp = sm_io_open(SmFtStdio, SM_TIME_DEFAULT, _PATH_LOADAVG, SM_IO_RDONLY,
NULL);
if (fp == NULL)
{
if (tTd(3, 1))
sm_dprintf("getla: sm_io_open(%s): %s\n",
_PATH_LOADAVG, sm_errstring(errno));
return -1;
}
result = sm_io_fscanf(fp, SM_TIME_DEFAULT, "%lf", &avenrun);
(void) sm_io_close(fp, SM_TIME_DEFAULT);
if (result != 1)
{
if (tTd(3, 1))
sm_dprintf("getla: sm_io_fscanf() = %d: %s\n",
result, sm_errstring(errno));
return -1;
}
if (tTd(3, 1))
sm_dprintf("getla(): %.2f\n", avenrun);
return ((int) (avenrun + 0.5));
}
#endif /* LA_TYPE == LA_PROCSTR */
#if LA_TYPE == LA_IRIX6
# include <sys/sysmp.h>
# ifdef _UNICOSMP
# define CAST_SYSMP(x) (x)
# else /* _UNICOSMP */
# define CAST_SYSMP(x) ((x) & 0x7fffffff)
# endif /* _UNICOSMP */
int
getla(void)
{
int j;
static int kmem = -1;
int avenrun[3];
if (kmem < 0)
{
kmem = open(_PATH_KMEM, 0, 0);
if (kmem < 0)
{
if (tTd(3, 1))
sm_dprintf("getla: open(%s): %s\n", _PATH_KMEM,
sm_errstring(errno));
return -1;
}
if ((j = fcntl(kmem, F_GETFD, 0)) < 0 ||
fcntl(kmem, F_SETFD, j | FD_CLOEXEC) < 0)
{
if (tTd(3, 1))
sm_dprintf("getla: fcntl(/dev/kmem, FD_CLOEXEC): %s\n",
sm_errstring(errno));
(void) close(kmem);
kmem = -1;
return -1;
}
}
if (lseek(kmem, CAST_SYSMP(sysmp(MP_KERNADDR, MPKA_AVENRUN)), SEEK_SET)
== -1 ||
read(kmem, (char *) avenrun, sizeof(avenrun)) != sizeof(avenrun))
{
if (tTd(3, 1))
sm_dprintf("getla: lseek or read: %s\n",
sm_errstring(errno));
return -1;
}
if (tTd(3, 5))
{
sm_dprintf("getla: avenrun = %ld", (long int) avenrun[0]);
if (tTd(3, 15))
sm_dprintf(", %ld, %ld",
(long int) avenrun[1], (long int) avenrun[2]);
sm_dprintf("\n");
}
if (tTd(3, 1))
sm_dprintf("getla: %d\n",
(int) (avenrun[0] + FSCALE/2) >> FSHIFT);
return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT);
}
#endif /* LA_TYPE == LA_IRIX6 */
#if LA_TYPE == LA_KSTAT
# include <kstat.h>
int
getla()
{
static kstat_ctl_t *kc = NULL;
static kstat_t *ksp = NULL;
kstat_named_t *ksn;
int la;
if (kc == NULL) /* if not initialized before */
kc = kstat_open();
if (kc == NULL)
{
if (tTd(3, 1))
sm_dprintf("getla: kstat_open(): %s\n",
sm_errstring(errno));
return -1;
}
if (ksp == NULL)
ksp = kstat_lookup(kc, "unix", 0, "system_misc");
if (ksp == NULL)
{
if (tTd(3, 1))
sm_dprintf("getla: kstat_lookup(): %s\n",
sm_errstring(errno));
return -1;
}
if (kstat_read(kc, ksp, NULL) < 0)
{
if (tTd(3, 1))
sm_dprintf("getla: kstat_read(): %s\n",
sm_errstring(errno));
return -1;
}
ksn = (kstat_named_t *) kstat_data_lookup(ksp, "avenrun_1min");
la = ((double) ksn->value.ul + FSCALE/2) / FSCALE;
/* kstat_close(kc); /o do not close for fast access */
return la;
}
#endif /* LA_TYPE == LA_KSTAT */
#if LA_TYPE == LA_DEVSHORT
/*
** Read /dev/table/avenrun for the load average. This should contain
** three shorts for the 1, 5, and 15 minute loads. We only read the
** first, since that's all we care about.
**
** Intended for SCO OpenServer 5.
*/
# ifndef _PATH_AVENRUN
# define _PATH_AVENRUN "/dev/table/avenrun"
# endif /* ! _PATH_AVENRUN */
int
getla()
{
static int afd = -1;
short avenrun;
int loadav;
int r;
errno = EBADF;
if (afd == -1 || lseek(afd, 0L, SEEK_SET) == -1)
{
if (errno != EBADF)
return -1;
afd = open(_PATH_AVENRUN, O_RDONLY|O_SYNC);
if (afd < 0)
{
sm_syslog(LOG_ERR, NOQID,
"can't open %s: %s",
_PATH_AVENRUN, sm_errstring(errno));
return -1;
}
}
r = read(afd, &avenrun, sizeof(avenrun));
if (r != sizeof(avenrun))
{
sm_syslog(LOG_ERR, NOQID,
"can't read %s: %s", _PATH_AVENRUN,
r == -1 ? sm_errstring(errno) : "short read");
return -1;
}
if (tTd(3, 5))
sm_dprintf("getla: avenrun = %d\n", avenrun);
loadav = (int) (avenrun + FSCALE/2) >> FSHIFT;
if (tTd(3, 1))
sm_dprintf("getla: %d\n", loadav);
return loadav;
}
#endif /* LA_TYPE == LA_DEVSHORT */
#if LA_TYPE == LA_ALPHAOSF
struct rtentry;
struct mbuf;
# include <sys/table.h>
int
getla()
{
int ave = 0;
struct tbl_loadavg tab;
if (table(TBL_LOADAVG, 0, &tab, 1, sizeof(tab)) == -1)
{
if (tTd(3, 1))
sm_dprintf("getla: table %s\n", sm_errstring(errno));
return -1;
}
if (tTd(3, 1))
sm_dprintf("getla: scale = %d\n", tab.tl_lscale);
if (tab.tl_lscale)
ave = ((tab.tl_avenrun.l[2] + (tab.tl_lscale/2)) /
tab.tl_lscale);
else
ave = (int) (tab.tl_avenrun.d[2] + 0.5);
if (tTd(3, 1))
sm_dprintf("getla: %d\n", ave);
return ave;
}
#endif /* LA_TYPE == LA_ALPHAOSF */
#if LA_TYPE == LA_PSET
int
getla()
{
double avenrun[3];
if (pset_getloadavg(PS_MYID, avenrun,
sizeof(avenrun) / sizeof(avenrun[0])) < 0)
{
if (tTd(3, 1))
sm_dprintf("getla: pset_getloadavg failed: %s",
sm_errstring(errno));
return -1;
}
if (tTd(3, 1))
sm_dprintf("getla: %d\n", (int) (avenrun[0] +0.5));
return ((int) (avenrun[0] + 0.5));
}
#endif /* LA_TYPE == LA_PSET */
#if LA_TYPE == LA_ZERO
int
getla()
{
if (tTd(3, 1))
sm_dprintf("getla: ZERO\n");
return 0;
}
#endif /* LA_TYPE == LA_ZERO */
/*
* Copyright 1989 Massachusetts Institute of Technology
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation, and that the name of M.I.T. not be used in advertising or
* publicity pertaining to distribution of the software without specific,
* written prior permission. M.I.T. makes no representations about the
* suitability of this software for any purpose. It is provided "as is"
* without express or implied warranty.
*
* M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
* BE LIABLE FOR ANY SPECIAL, 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.
*
* Authors: Many and varied...
*/
/* Non Apollo stuff removed by Don Lewis 11/15/93 */
#ifndef lint
SM_UNUSED(static char rcsid[]) = "@(#)$OrigId: getloadavg.c,v 1.16 1991/06/21 12:51:15 paul Exp $";
#endif /* ! lint */
#ifdef apollo
# undef volatile
# include <apollo/base.h>
/* ARGSUSED */
int getloadavg( call_data )
caddr_t call_data; /* pointer to (double) return value */
{
double *avenrun = (double *) call_data;
int i;
status_$t st;
long loadav[3];
proc1_$get_loadav(loadav, &st);
*avenrun = loadav[0] / (double) (1 << 16);
return 0;
}
#endif /* apollo */
/*
** SM_GETLA -- get the current load average
**
** Parameters:
** none
**
** Returns:
** none
**
** Side Effects:
** Set CurrentLA to the current load average.
** Set {load_avg} in GlobalMacros to the current load average.
*/
void
sm_getla()
{
char labuf[8];
CurrentLA = getla();
(void) sm_snprintf(labuf, sizeof(labuf), "%d", CurrentLA);
macdefine(&GlobalMacros, A_TEMP, macid("{load_avg}"), labuf);
}
/*
** SHOULDQUEUE -- should this message be queued or sent?
**
** Compares the message cost to the load average to decide.
**
** Note: Do NOT change this API! It is documented in op.me
** and theoretically the user can change this function...
**
** Parameters:
** pri -- the priority of the message in question.
** ct -- the message creation time (unused, but see above).
**
** Returns:
** true -- if this message should be queued up for the
** time being.
** false -- if the load is low enough to send this message.
**
** Side Effects:
** none.
*/
/* ARGSUSED1 */
bool
shouldqueue(pri, ct)
long pri;
time_t ct;
{
bool rval;
#if _FFR_MEMSTAT
long memfree;
#endif /* _FFR_MEMSTAT */
if (tTd(3, 30))
sm_dprintf("shouldqueue: CurrentLA=%d, pri=%ld: ",
CurrentLA, pri);
#if _FFR_MEMSTAT
if (QueueLowMem > 0 &&
sm_memstat_get(MemoryResource, &memfree) >= 0 &&
memfree < QueueLowMem)
{
if (tTd(3, 30))
sm_dprintf("true (memfree=%ld < QueueLowMem=%ld)\n",
memfree, QueueLowMem);
return true;
}
#endif /* _FFR_MEMSTAT */
if (CurrentLA < QueueLA)
{
if (tTd(3, 30))
sm_dprintf("false (CurrentLA < QueueLA)\n");
return false;
}
rval = pri > (QueueFactor / (CurrentLA - QueueLA + 1));
if (tTd(3, 30))
sm_dprintf("%s (by calculation)\n", rval ? "true" : "false");
return rval;
}
/*
** REFUSECONNECTIONS -- decide if connections should be refused
**
** Parameters:
** e -- the current envelope.
** dn -- number of daemon.
** active -- was this daemon actually active?
**
** Returns:
** true if incoming SMTP connections should be refused
** (for now).
** false if we should accept new work.
**
** Side Effects:
** Sets process title when it is rejecting connections.
*/
bool
refuseconnections(e, dn, active)
ENVELOPE *e;
int dn;
bool active;
{
static time_t lastconn[MAXDAEMONS];
static int conncnt[MAXDAEMONS];
static time_t firstrejtime[MAXDAEMONS];
static time_t nextlogtime[MAXDAEMONS];
int limit;
#if _FFR_MEMSTAT
long memfree;
#endif /* _FFR_MEMSTAT */
#if XLA
if (!xla_smtp_ok())
return true;
#endif /* XLA */
SM_ASSERT(dn >= 0);
SM_ASSERT(dn < MAXDAEMONS);
if (ConnRateThrottle > 0)
{
time_t now;
now = curtime();
if (active)
{
if (now != lastconn[dn])
{
lastconn[dn] = now;
conncnt[dn] = 1;
}
else if (conncnt[dn]++ > ConnRateThrottle)
{
#define D_MSG_CRT "deferring connections on daemon %s: %d per second"
/* sleep to flatten out connection load */
sm_setproctitle(true, e, D_MSG_CRT,
Daemons[dn].d_name,
ConnRateThrottle);
if (LogLevel > 8)
sm_syslog(LOG_INFO, NOQID, D_MSG_CRT,
Daemons[dn].d_name,
ConnRateThrottle);
(void) sleep(1);
}
}
else if (now != lastconn[dn])
conncnt[dn] = 0;
}
#if _FFR_MEMSTAT
if (RefuseLowMem > 0 &&
sm_memstat_get(MemoryResource, &memfree) >= 0 &&
memfree < RefuseLowMem)
{
# define R_MSG_LM "rejecting connections on daemon %s: free memory: %ld"
sm_setproctitle(true, e, R_MSG_LM, Daemons[dn].d_name, memfree);
if (LogLevel > 8)
sm_syslog(LOG_NOTICE, NOQID, R_MSG_LM,
Daemons[dn].d_name, memfree);
return true;
}
#endif /* _FFR_MEMSTAT */
sm_getla();
limit = (Daemons[dn].d_refuseLA != DPO_NOTSET) ?
Daemons[dn].d_refuseLA : RefuseLA;
if (limit > 0 && CurrentLA >= limit)
{
time_t now;
# define R_MSG_LA "rejecting connections on daemon %s: load average: %d"
# define R2_MSG_LA "have been rejecting connections on daemon %s for %s"
sm_setproctitle(true, e, R_MSG_LA, Daemons[dn].d_name,
CurrentLA);
if (LogLevel > 8)
sm_syslog(LOG_NOTICE, NOQID, R_MSG_LA,
Daemons[dn].d_name, CurrentLA);
now = curtime();
if (firstrejtime[dn] == 0)
{
firstrejtime[dn] = now;
nextlogtime[dn] = now + RejectLogInterval;
}
else if (nextlogtime[dn] < now)
{
sm_syslog(LOG_ERR, NOQID, R2_MSG_LA, Daemons[dn].d_name,
pintvl(now - firstrejtime[dn], true));
nextlogtime[dn] = now + RejectLogInterval;
}
return true;
}
else
firstrejtime[dn] = 0;
limit = (Daemons[dn].d_delayLA != DPO_NOTSET) ?
Daemons[dn].d_delayLA : DelayLA;
if (limit > 0 && CurrentLA >= limit)
{
time_t now;
static time_t log_delay = (time_t) 0;
# define MIN_DELAY_LOG 90 /* wait before logging this again */
# define D_MSG_LA "delaying connections on daemon %s: load average=%d >= %d"
/* sleep to flatten out connection load */
sm_setproctitle(true, e, D_MSG_LA, Daemons[dn].d_name,
CurrentLA, limit);
if (LogLevel > 8 && (now = curtime()) > log_delay)
{
sm_syslog(LOG_INFO, NOQID, D_MSG_LA,
Daemons[dn].d_name, CurrentLA, limit);
log_delay = now + MIN_DELAY_LOG;
}
(void) sleep(1);
}
limit = (Daemons[dn].d_maxchildren != DPO_NOTSET) ?
Daemons[dn].d_maxchildren : MaxChildren;
if (limit > 0 && CurChildren >= limit)
{
proc_list_probe();
if (CurChildren >= limit)
{
#define R_MSG_CHILD "rejecting connections on daemon %s: %d children, max %d"
sm_setproctitle(true, e, R_MSG_CHILD,
Daemons[dn].d_name, CurChildren,
limit);
if (LogLevel > 8)
sm_syslog(LOG_INFO, NOQID, R_MSG_CHILD,
Daemons[dn].d_name, CurChildren,
limit);
return true;
}
}
return false;
}
/*
** SETPROCTITLE -- set process title for ps
**
** Parameters:
** fmt -- a printf style format string.
** a, b, c -- possible parameters to fmt.
**
** Returns:
** none.
**
** Side Effects:
** Clobbers argv of our main procedure so ps(1) will
** display the title.
*/
#define SPT_NONE 0 /* don't use it at all */
#define SPT_REUSEARGV 1 /* cover argv with title information */
#define SPT_BUILTIN 2 /* use libc builtin */
#define SPT_PSTAT 3 /* use pstat(PSTAT_SETCMD, ...) */
#define SPT_PSSTRINGS 4 /* use PS_STRINGS->... */
#define SPT_SYSMIPS 5 /* use sysmips() supported by NEWS-OS 6 */
#define SPT_SCO 6 /* write kernel u. area */
#define SPT_CHANGEARGV 7 /* write our own strings into argv[] */
#ifndef SPT_TYPE
# define SPT_TYPE SPT_REUSEARGV
#endif /* ! SPT_TYPE */
#if SPT_TYPE != SPT_NONE && SPT_TYPE != SPT_BUILTIN
# if SPT_TYPE == SPT_PSTAT
# include <sys/pstat.h>
# endif /* SPT_TYPE == SPT_PSTAT */
# if SPT_TYPE == SPT_PSSTRINGS
# include <machine/vmparam.h>
# include <sys/exec.h>
# ifndef PS_STRINGS /* hmmmm.... apparently not available after all */
# undef SPT_TYPE
# define SPT_TYPE SPT_REUSEARGV
# else /* ! PS_STRINGS */
# ifndef NKPDE /* FreeBSD 2.0 */
# define NKPDE 63
typedef unsigned int *pt_entry_t;
# endif /* ! NKPDE */
# endif /* ! PS_STRINGS */
# endif /* SPT_TYPE == SPT_PSSTRINGS */
# if SPT_TYPE == SPT_PSSTRINGS || SPT_TYPE == SPT_CHANGEARGV
# define SETPROC_STATIC static
# else /* SPT_TYPE == SPT_PSSTRINGS || SPT_TYPE == SPT_CHANGEARGV */
# define SETPROC_STATIC
# endif /* SPT_TYPE == SPT_PSSTRINGS || SPT_TYPE == SPT_CHANGEARGV */
# if SPT_TYPE == SPT_SYSMIPS
# include <sys/sysmips.h>
# include <sys/sysnews.h>
# endif /* SPT_TYPE == SPT_SYSMIPS */
# if SPT_TYPE == SPT_SCO
# include <sys/immu.h>
# include <sys/dir.h>
# include <sys/user.h>
# include <sys/fs/s5param.h>
# if PSARGSZ > MAXLINE
# define SPT_BUFSIZE PSARGSZ
# endif /* PSARGSZ > MAXLINE */
# endif /* SPT_TYPE == SPT_SCO */
# ifndef SPT_PADCHAR
# define SPT_PADCHAR ' '
# endif /* ! SPT_PADCHAR */
#endif /* SPT_TYPE != SPT_NONE && SPT_TYPE != SPT_BUILTIN */
#ifndef SPT_BUFSIZE
# define SPT_BUFSIZE MAXLINE
#endif /* ! SPT_BUFSIZE */
#if _FFR_SPT_ALIGN
/*
** It looks like the Compaq Tru64 5.1A now aligns argv and envp to
** 64 bit alignment, so unless each piece of argv and envp is a multiple
** of 8 bytes (including terminating NULL), initsetproctitle() won't use
** any of the space beyond argv[0]. Be sure to set SPT_ALIGN_SIZE if
** you use this FFR.
*/
# ifdef SPT_ALIGN_SIZE
# define SPT_ALIGN(x, align) (((((x) + SPT_ALIGN_SIZE) >> (align)) << (align)) - 1)
# else /* SPT_ALIGN_SIZE */
# define SPT_ALIGN(x, align) (x)
# endif /* SPT_ALIGN_SIZE */
#else /* _FFR_SPT_ALIGN */
# define SPT_ALIGN(x, align) (x)
#endif /* _FFR_SPT_ALIGN */
/*
** Pointers for setproctitle.
** This allows "ps" listings to give more useful information.
*/
static char **Argv = NULL; /* pointer to argument vector */
static char *LastArgv = NULL; /* end of argv */
#if SPT_TYPE != SPT_BUILTIN
static void setproctitle __P((const char *, ...));
#endif /* SPT_TYPE != SPT_BUILTIN */
void
initsetproctitle(argc, argv, envp)
int argc;
char **argv;
char **envp;
{
register int i;
int align;
extern char **environ;
/*
** Move the environment so setproctitle can use the space at
** the top of memory.
*/
if (envp != NULL)
{
for (i = 0; envp[i] != NULL; i++)
continue;
environ = (char **) xalloc(sizeof(char *) * (i + 1));
for (i = 0; envp[i] != NULL; i++)
environ[i] = newstr(envp[i]);
environ[i] = NULL;
}
/*
** Save start and extent of argv for setproctitle.
*/
Argv = argv;
/*
** Determine how much space we can use for setproctitle.
** Use all contiguous argv and envp pointers starting at argv[0]
*/
align = -1;
# if _FFR_SPT_ALIGN
# ifdef SPT_ALIGN_SIZE
for (i = SPT_ALIGN_SIZE; i > 0; i >>= 1)
align++;
# endif /* SPT_ALIGN_SIZE */
# endif /* _FFR_SPT_ALIGN */
for (i = 0; i < argc; i++)
{
if (i == 0 || LastArgv + 1 == argv[i])
LastArgv = argv[i] + SPT_ALIGN(strlen(argv[i]), align);
}
for (i = 0; LastArgv != NULL && envp != NULL && envp[i] != NULL; i++)
{
if (LastArgv + 1 == envp[i])
LastArgv = envp[i] + SPT_ALIGN(strlen(envp[i]), align);
}
}
#if SPT_TYPE != SPT_BUILTIN
/*VARARGS1*/
static void
# ifdef __STDC__
setproctitle(const char *fmt, ...)
# else /* __STDC__ */
setproctitle(fmt, va_alist)
const char *fmt;
va_dcl
# endif /* __STDC__ */
{
# if SPT_TYPE != SPT_NONE
register int i;
register char *p;
SETPROC_STATIC char buf[SPT_BUFSIZE];
SM_VA_LOCAL_DECL
# if SPT_TYPE == SPT_PSTAT
union pstun pst;
# endif /* SPT_TYPE == SPT_PSTAT */
# if SPT_TYPE == SPT_SCO
int j;
off_t seek_off;
static int kmem = -1;
static pid_t kmempid = -1;
struct user u;
# endif /* SPT_TYPE == SPT_SCO */
p = buf;
/* print sendmail: heading for grep */
(void) sm_strlcpy(p, "sendmail: ", SPACELEFT(buf, p));
p += strlen(p);
/* print the argument string */
SM_VA_START(ap, fmt);
(void) sm_vsnprintf(p, SPACELEFT(buf, p), fmt, ap);
SM_VA_END(ap);
i = (int) strlen(buf);
if (i < 0)
return;
# if SPT_TYPE == SPT_PSTAT
pst.pst_command = buf;
pstat(PSTAT_SETCMD, pst, i, 0, 0);
# endif /* SPT_TYPE == SPT_PSTAT */
# if SPT_TYPE == SPT_PSSTRINGS
PS_STRINGS->ps_nargvstr = 1;
PS_STRINGS->ps_argvstr = buf;
# endif /* SPT_TYPE == SPT_PSSTRINGS */
# if SPT_TYPE == SPT_SYSMIPS
sysmips(SONY_SYSNEWS, NEWS_SETPSARGS, buf);
# endif /* SPT_TYPE == SPT_SYSMIPS */
# if SPT_TYPE == SPT_SCO
if (kmem < 0 || kmempid != CurrentPid)
{
if (kmem >= 0)
(void) close(kmem);
kmem = open(_PATH_KMEM, O_RDWR, 0);
if (kmem < 0)
return;
if ((j = fcntl(kmem, F_GETFD, 0)) < 0 ||
fcntl(kmem, F_SETFD, j | FD_CLOEXEC) < 0)
{
(void) close(kmem);
kmem = -1;
return;
}
kmempid = CurrentPid;
}
buf[PSARGSZ - 1] = '\0';
seek_off = UVUBLK + (off_t) u.u_psargs - (off_t) &u;
if (lseek(kmem, (off_t) seek_off, SEEK_SET) == seek_off)
(void) write(kmem, buf, PSARGSZ);
# endif /* SPT_TYPE == SPT_SCO */
# if SPT_TYPE == SPT_REUSEARGV
if (LastArgv == NULL)
return;
if (i > LastArgv - Argv[0] - 2)
{
i = LastArgv - Argv[0] - 2;
buf[i] = '\0';
}
(void) sm_strlcpy(Argv[0], buf, i + 1);
p = &Argv[0][i];
while (p < LastArgv)
*p++ = SPT_PADCHAR;
Argv[1] = NULL;
# endif /* SPT_TYPE == SPT_REUSEARGV */
# if SPT_TYPE == SPT_CHANGEARGV
Argv[0] = buf;
Argv[1] = 0;
# endif /* SPT_TYPE == SPT_CHANGEARGV */
# endif /* SPT_TYPE != SPT_NONE */
}
#endif /* SPT_TYPE != SPT_BUILTIN */
/*
** SM_SETPROCTITLE -- set process task and set process title for ps
**
** Possibly set process status and call setproctitle() to
** change the ps display.
**
** Parameters:
** status -- whether or not to store as process status
** e -- the current envelope.
** fmt -- a printf style format string.
** a, b, c -- possible parameters to fmt.
**
** Returns:
** none.
*/
/*VARARGS2*/
void
#ifdef __STDC__
sm_setproctitle(bool status, ENVELOPE *e, const char *fmt, ...)
#else /* __STDC__ */
sm_setproctitle(status, e, fmt, va_alist)
bool status;
ENVELOPE *e;
const char *fmt;
va_dcl
#endif /* __STDC__ */
{
char buf[SPT_BUFSIZE];
SM_VA_LOCAL_DECL
/* print the argument string */
SM_VA_START(ap, fmt);
(void) sm_vsnprintf(buf, sizeof(buf), fmt, ap);
SM_VA_END(ap);
if (status)
proc_list_set(CurrentPid, buf);
if (ProcTitlePrefix != NULL)
{
char prefix[SPT_BUFSIZE];
expand(ProcTitlePrefix, prefix, sizeof(prefix), e);
setproctitle("%s: %s", prefix, buf);
}
else
setproctitle("%s", buf);
}
/*
** WAITFOR -- wait for a particular process id.
**
** Parameters:
** pid -- process id to wait for.
**
** Returns:
** status of pid.
** -1 if pid never shows up.
**
** Side Effects:
** none.
*/
int
waitfor(pid)
pid_t pid;
{
int st;
pid_t i;
do
{
errno = 0;
i = sm_wait(&st);
if (i > 0)
proc_list_drop(i, st, NULL);
} while ((i >= 0 || errno == EINTR) && i != pid);
if (i < 0)
return -1;
return st;
}
/*
** SM_WAIT -- wait
**
** Parameters:
** status -- pointer to status (return value)
**
** Returns:
** pid
*/
pid_t
sm_wait(status)
int *status;
{
# ifdef WAITUNION
union wait st;
# else /* WAITUNION */
auto int st;
# endif /* WAITUNION */
pid_t i;
# if defined(ISC_UNIX) || defined(_SCO_unix_)
int savesig;
# endif /* defined(ISC_UNIX) || defined(_SCO_unix_) */
# if defined(ISC_UNIX) || defined(_SCO_unix_)
savesig = sm_releasesignal(SIGCHLD);
# endif /* defined(ISC_UNIX) || defined(_SCO_unix_) */
i = wait(&st);
# if defined(ISC_UNIX) || defined(_SCO_unix_)
if (savesig > 0)
sm_blocksignal(SIGCHLD);
# endif /* defined(ISC_UNIX) || defined(_SCO_unix_) */
# ifdef WAITUNION
*status = st.w_status;
# else /* WAITUNION */
*status = st;
# endif /* WAITUNION */
return i;
}
/*
** REAPCHILD -- pick up the body of my child, lest it become a zombie
**
** Parameters:
** sig -- the signal that got us here (unused).
**
** Returns:
** none.
**
** Side Effects:
** Picks up extant zombies.
** Control socket exits may restart/shutdown daemon.
**
** NOTE: THIS CAN BE CALLED FROM A SIGNAL HANDLER. DO NOT ADD
** ANYTHING TO THIS ROUTINE UNLESS YOU KNOW WHAT YOU ARE
** DOING.
*/
/* ARGSUSED0 */
SIGFUNC_DECL
reapchild(sig)
int sig;
{
int save_errno = errno;
int st;
pid_t pid;
# if HASWAITPID
auto int status;
int count;
count = 0;
while ((pid = waitpid(-1, &status, WNOHANG)) > 0)
{
st = status;
if (count++ > 1000)
break;
# else /* HASWAITPID */
# ifdef WNOHANG
union wait status;
while ((pid = wait3(&status, WNOHANG, (struct rusage *) NULL)) > 0)
{
st = status.w_status;
# else /* WNOHANG */
auto int status;
/*
** Catch one zombie -- we will be re-invoked (we hope) if there
** are more. Unreliable signals probably break this, but this
** is the "old system" situation -- waitpid or wait3 are to be
** strongly preferred.
*/
if ((pid = wait(&status)) > 0)
{
st = status;
# endif /* WNOHANG */
# endif /* HASWAITPID */
/* Drop PID and check if it was a control socket child */
proc_list_drop(pid, st, NULL);
}
FIX_SYSV_SIGNAL(sig, reapchild);
errno = save_errno;
return SIGFUNC_RETURN;
}
/*
** GETDTABLESIZE -- return number of file descriptors
**
** Only on non-BSD systems
**
** Parameters:
** none
**
** Returns:
** size of file descriptor table
**
** Side Effects:
** none
*/
#ifdef SOLARIS
# include <sys/resource.h>
#endif /* SOLARIS */
int
getdtsize()
{
# ifdef RLIMIT_NOFILE
struct rlimit rl;
if (getrlimit(RLIMIT_NOFILE, &rl) >= 0)
return rl.rlim_cur;
# endif /* RLIMIT_NOFILE */
# if HASGETDTABLESIZE
return getdtablesize();
# else /* HASGETDTABLESIZE */
# ifdef _SC_OPEN_MAX
return sysconf(_SC_OPEN_MAX);
# else /* _SC_OPEN_MAX */
return NOFILE;
# endif /* _SC_OPEN_MAX */
# endif /* HASGETDTABLESIZE */
}
/*
** UNAME -- get the UUCP name of this system.
*/
#if !HASUNAME
int
uname(name)
struct utsname *name;
{
SM_FILE_T *file;
char *n;
name->nodename[0] = '\0';
/* try /etc/whoami -- one line with the node name */
if ((file = sm_io_open(SmFtStdio, SM_TIME_DEFAULT, "/etc/whoami",
SM_IO_RDONLY, NULL)) != NULL)
{
(void) sm_io_fgets(file, SM_TIME_DEFAULT, name->nodename,
NODE_LENGTH + 1);
(void) sm_io_close(file, SM_TIME_DEFAULT);
n = strchr(name->nodename, '\n');
if (n != NULL)
*n = '\0';
if (name->nodename[0] != '\0')
return 0;
}
/* try /usr/include/whoami.h -- has a #define somewhere */
if ((file = sm_io_open(SmFtStdio, SM_TIME_DEFAULT,
"/usr/include/whoami.h", SM_IO_RDONLY, NULL))
!= NULL)
{
char buf[MAXLINE];
while (sm_io_fgets(file, SM_TIME_DEFAULT,
buf, sizeof(buf)) != NULL)
{
if (sm_io_sscanf(buf, "#define sysname \"%*[^\"]\"",
NODE_LENGTH, name->nodename) > 0)
break;
}
(void) sm_io_close(file, SM_TIME_DEFAULT);
if (name->nodename[0] != '\0')
return 0;
}
return -1;
}
#endif /* !HASUNAME */
/*
** INITGROUPS -- initialize groups
**
** Stub implementation for System V style systems
*/
#if !HASINITGROUPS
initgroups(name, basegid)
char *name;
int basegid;
{
return 0;
}
#endif /* !HASINITGROUPS */
/*
** SETGROUPS -- set group list
**
** Stub implementation for systems that don't have group lists
*/
#ifndef NGROUPS_MAX
int
setgroups(ngroups, grouplist)
int ngroups;
GIDSET_T grouplist[];
{
return 0;
}
#endif /* ! NGROUPS_MAX */
/*
** SETSID -- set session id (for non-POSIX systems)
*/
#if !HASSETSID
pid_t
setsid __P ((void))
{
# ifdef TIOCNOTTY
int fd;
fd = open("/dev/tty", O_RDWR, 0);
if (fd >= 0)
{
(void) ioctl(fd, TIOCNOTTY, (char *) 0);
(void) close(fd);
}
# endif /* TIOCNOTTY */
# ifdef SYS5SETPGRP
return setpgrp();
# else /* SYS5SETPGRP */
return setpgid(0, CurrentPid);
# endif /* SYS5SETPGRP */
}
#endif /* !HASSETSID */
/*
** FSYNC -- dummy fsync
*/
#if NEEDFSYNC
fsync(fd)
int fd;
{
# ifdef O_SYNC
return fcntl(fd, F_SETFL, O_SYNC);
# else /* O_SYNC */
/* nothing we can do */
return 0;
# endif /* O_SYNC */
}
#endif /* NEEDFSYNC */
/*
** DGUX_INET_ADDR -- inet_addr for DG/UX
**
** Data General DG/UX version of inet_addr returns a struct in_addr
** instead of a long. This patches things. Only needed on versions
** prior to 5.4.3.
*/
#ifdef DGUX_5_4_2
# undef inet_addr
long
dgux_inet_addr(host)
char *host;
{
struct in_addr haddr;
haddr = inet_addr(host);
return haddr.s_addr;
}
#endif /* DGUX_5_4_2 */
/*
** GETOPT -- for old systems or systems with bogus implementations
*/
#if !SM_CONF_GETOPT
/*
* Copyright (c) 1985 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
*/
/*
** this version hacked to add `atend' flag to allow state machine
** to reset if invoked by the program to scan args for a 2nd time
*/
# if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)getopt.c 4.3 (Berkeley) 3/9/86";
# endif /* defined(LIBC_SCCS) && !defined(lint) */
/*
** get option letter from argument vector
*/
# ifdef _CONVEX_SOURCE
extern int optind, opterr, optopt;
extern char *optarg;
# else /* _CONVEX_SOURCE */
int opterr = 1; /* if error message should be printed */
int optind = 1; /* index into parent argv vector */
int optopt = 0; /* character checked for validity */
char *optarg = NULL; /* argument associated with option */
# endif /* _CONVEX_SOURCE */
# define BADCH (int)'?'
# define EMSG ""
# define tell(s) if (opterr) \
{sm_io_fputs(smioerr, SM_TIME_DEFAULT, *nargv); \
(void) sm_io_fputs(smioerr, SM_TIME_DEFAULT, s); \
(void) sm_io_putc(smioerr, SM_TIME_DEFAULT, optopt); \
(void) sm_io_putc(smioerr, SM_TIME_DEFAULT, '\n'); \
return BADCH;}
int
getopt(nargc,nargv,ostr)
int nargc;
char *const *nargv;
const char *ostr;
{
static char *place = EMSG; /* option letter processing */
static char atend = 0;
register char *oli = NULL; /* option letter list index */
if (atend) {
atend = 0;
place = EMSG;
}
if(!*place) { /* update scanning pointer */
if (optind >= nargc || *(place = nargv[optind]) != '-' || !*++place) {
atend++;
return -1;
}
if (*place == '-') { /* found "--" */
++optind;
atend++;
return -1;
}
} /* option letter okay? */
if ((optopt = (int)*place++) == (int)':' || !(oli = strchr(ostr,optopt))) {
if (!*place) ++optind;
tell(": illegal option -- ");
}
if (oli && *++oli != ':') { /* don't need argument */
optarg = NULL;
if (!*place) ++optind;
}
else { /* need an argument */
if (*place) optarg = place; /* no white space */
else if (nargc <= ++optind) { /* no arg */
place = EMSG;
tell(": option requires an argument -- ");
}
else optarg = nargv[optind]; /* white space */
place = EMSG;
++optind;
}
return optopt; /* dump back option letter */
}
#endif /* !SM_CONF_GETOPT */
/*
** USERSHELLOK -- tell if a user's shell is ok for unrestricted use
**
** Parameters:
** user -- the name of the user we are checking.
** shell -- the user's shell from /etc/passwd
**
** Returns:
** true -- if it is ok to use this for unrestricted access.
** false -- if the shell is restricted.
*/
#if !HASGETUSERSHELL
# ifndef _PATH_SHELLS
# define _PATH_SHELLS "/etc/shells"
# endif /* ! _PATH_SHELLS */
# if defined(_AIX3) || defined(_AIX4)
# include <userconf.h>
# if _AIX4 >= 40200
# include <userpw.h>
# endif /* _AIX4 >= 40200 */
# include <usersec.h>
# endif /* defined(_AIX3) || defined(_AIX4) */
static char *DefaultUserShells[] =
{
"/bin/sh", /* standard shell */
# ifdef MPE
"/SYS/PUB/CI",
# else /* MPE */
"/usr/bin/sh",
"/bin/csh", /* C shell */
"/usr/bin/csh",
# endif /* MPE */
# ifdef __hpux
# ifdef V4FS
"/usr/bin/rsh", /* restricted Bourne shell */
"/usr/bin/ksh", /* Korn shell */
"/usr/bin/rksh", /* restricted Korn shell */
"/usr/bin/pam",
"/usr/bin/keysh", /* key shell (extended Korn shell) */
"/usr/bin/posix/sh",
# else /* V4FS */
"/bin/rsh", /* restricted Bourne shell */
"/bin/ksh", /* Korn shell */
"/bin/rksh", /* restricted Korn shell */
"/bin/pam",
"/usr/bin/keysh", /* key shell (extended Korn shell) */
"/bin/posix/sh",
"/sbin/sh",
# endif /* V4FS */
# endif /* __hpux */
# if defined(_AIX3) || defined(_AIX4)
"/bin/ksh", /* Korn shell */
"/usr/bin/ksh",
"/bin/tsh", /* trusted shell */
"/usr/bin/tsh",
"/bin/bsh", /* Bourne shell */
"/usr/bin/bsh",
# endif /* defined(_AIX3) || defined(_AIX4) */
# if defined(__svr4__) || defined(__svr5__)
"/bin/ksh", /* Korn shell */
"/usr/bin/ksh",
# endif /* defined(__svr4__) || defined(__svr5__) */
# ifdef sgi
"/sbin/sh", /* SGI's shells really live in /sbin */
"/usr/bin/sh",
"/sbin/bsh", /* classic Bourne shell */
"/bin/bsh",
"/usr/bin/bsh",
"/sbin/csh", /* standard csh */
"/bin/csh",
"/usr/bin/csh",
"/sbin/jsh", /* classic Bourne shell w/ job control*/
"/bin/jsh",
"/usr/bin/jsh",
"/bin/ksh", /* Korn shell */
"/sbin/ksh",
"/usr/bin/ksh",
"/sbin/tcsh", /* Extended csh */
"/bin/tcsh",
"/usr/bin/tcsh",
# endif /* sgi */
NULL
};
#endif /* !HASGETUSERSHELL */
#define WILDCARD_SHELL "/SENDMAIL/ANY/SHELL/"
bool
usershellok(user, shell)
char *user;
char *shell;
{
# if HASGETUSERSHELL
register char *p;
extern char *getusershell();
if (shell == NULL || shell[0] == '\0' || wordinclass(user, 't') ||
ConfigLevel <= 1)
return true;
setusershell();
while ((p = getusershell()) != NULL)
if (strcmp(p, shell) == 0 || strcmp(p, WILDCARD_SHELL) == 0)
break;
endusershell();
return p != NULL;
# else /* HASGETUSERSHELL */
# if USEGETCONFATTR
auto char *v;
# endif /* USEGETCONFATTR */
register SM_FILE_T *shellf;
char buf[MAXLINE];
if (shell == NULL || shell[0] == '\0' || wordinclass(user, 't') ||
ConfigLevel <= 1)
return true;
# if USEGETCONFATTR
/*
** Naturally IBM has a "better" idea.....
**
** What a crock. This interface isn't documented, it is
** considered part of the security library (-ls), and it
** only works if you are running as root (since the list
** of valid shells is obviously a source of great concern).
** I recommend that you do NOT define USEGETCONFATTR,
** especially since you are going to have to set up an
** /etc/shells anyhow to handle the cases where getconfattr
** fails.
*/
if (getconfattr(SC_SYS_LOGIN, SC_SHELLS, &v, SEC_LIST) == 0 && v != NULL)
{
while (*v != '\0')
{
if (strcmp(v, shell) == 0 || strcmp(v, WILDCARD_SHELL) == 0)
return true;
v += strlen(v) + 1;
}
return false;
}
# endif /* USEGETCONFATTR */
shellf = sm_io_open(SmFtStdio, SM_TIME_DEFAULT, _PATH_SHELLS,
SM_IO_RDONLY, NULL);
if (shellf == NULL)
{
/* no /etc/shells; see if it is one of the std shells */
char **d;
if (errno != ENOENT && LogLevel > 3)
sm_syslog(LOG_ERR, NOQID,
"usershellok: cannot open %s: %s",
_PATH_SHELLS, sm_errstring(errno));
for (d = DefaultUserShells; *d != NULL; d++)
{
if (strcmp(shell, *d) == 0)
return true;
}
return false;
}
while (sm_io_fgets(shellf, SM_TIME_DEFAULT, buf, sizeof(buf)) != NULL)
{
register char *p, *q;
p = buf;
while (*p != '\0' && *p != '#' && *p != '/')
p++;
if (*p == '#' || *p == '\0')
continue;
q = p;
while (*p != '\0' && *p != '#' && !(isascii(*p) && isspace(*p)))
p++;
*p = '\0';
if (strcmp(shell, q) == 0 || strcmp(WILDCARD_SHELL, q) == 0)
{
(void) sm_io_close(shellf, SM_TIME_DEFAULT);
return true;
}
}
(void) sm_io_close(shellf, SM_TIME_DEFAULT);
return false;
# endif /* HASGETUSERSHELL */
}
/*
** FREEDISKSPACE -- see how much free space is on the queue filesystem
**
** Only implemented if you have statfs.
**
** Parameters:
** dir -- the directory in question.
** bsize -- a variable into which the filesystem
** block size is stored.
**
** Returns:
** The number of blocks free on the queue filesystem.
** -1 if the statfs call fails.
**
** Side effects:
** Puts the filesystem block size into bsize.
*/
/* statfs types */
# define SFS_NONE 0 /* no statfs implementation */
# define SFS_USTAT 1 /* use ustat */
# define SFS_4ARGS 2 /* use four-argument statfs call */
# define SFS_VFS 3 /* use <sys/vfs.h> implementation */
# define SFS_MOUNT 4 /* use <sys/mount.h> implementation */
# define SFS_STATFS 5 /* use <sys/statfs.h> implementation */
# define SFS_STATVFS 6 /* use <sys/statvfs.h> implementation */
# ifndef SFS_TYPE
# define SFS_TYPE SFS_NONE
# endif /* ! SFS_TYPE */
# if SFS_TYPE == SFS_USTAT
# include <ustat.h>
# endif /* SFS_TYPE == SFS_USTAT */
# if SFS_TYPE == SFS_4ARGS || SFS_TYPE == SFS_STATFS
# include <sys/statfs.h>
# endif /* SFS_TYPE == SFS_4ARGS || SFS_TYPE == SFS_STATFS */
# if SFS_TYPE == SFS_VFS
# include <sys/vfs.h>
# endif /* SFS_TYPE == SFS_VFS */
# if SFS_TYPE == SFS_MOUNT
# include <sys/mount.h>
# endif /* SFS_TYPE == SFS_MOUNT */
# if SFS_TYPE == SFS_STATVFS
# include <sys/statvfs.h>
# endif /* SFS_TYPE == SFS_STATVFS */
long
freediskspace(dir, bsize)
const char *dir;
long *bsize;
{
# if SFS_TYPE == SFS_NONE
if (bsize != NULL)
*bsize = 4096L;
/* assume free space is plentiful */
return (long) LONG_MAX;
# else /* SFS_TYPE == SFS_NONE */
# if SFS_TYPE == SFS_USTAT
struct ustat fs;
struct stat statbuf;
# define FSBLOCKSIZE DEV_BSIZE
# define SFS_BAVAIL f_tfree
# else /* SFS_TYPE == SFS_USTAT */
# if defined(ultrix)
struct fs_data fs;
# define SFS_BAVAIL fd_bfreen
# define FSBLOCKSIZE 1024L
# else /* defined(ultrix) */
# if SFS_TYPE == SFS_STATVFS
struct statvfs fs;
# define FSBLOCKSIZE fs.f_frsize
# else /* SFS_TYPE == SFS_STATVFS */
struct statfs fs;
# define FSBLOCKSIZE fs.f_bsize
# endif /* SFS_TYPE == SFS_STATVFS */
# endif /* defined(ultrix) */
# endif /* SFS_TYPE == SFS_USTAT */
# ifndef SFS_BAVAIL
# define SFS_BAVAIL f_bavail
# endif /* ! SFS_BAVAIL */
# if SFS_TYPE == SFS_USTAT
if (stat(dir, &statbuf) == 0 && ustat(statbuf.st_dev, &fs) == 0)
# else /* SFS_TYPE == SFS_USTAT */
# if SFS_TYPE == SFS_4ARGS
if (statfs(dir, &fs, sizeof(fs), 0) == 0)
# else /* SFS_TYPE == SFS_4ARGS */
# if SFS_TYPE == SFS_STATVFS
if (statvfs(dir, &fs) == 0)
# else /* SFS_TYPE == SFS_STATVFS */
# if defined(ultrix)
if (statfs(dir, &fs) > 0)
# else /* defined(ultrix) */
if (statfs(dir, &fs) == 0)
# endif /* defined(ultrix) */
# endif /* SFS_TYPE == SFS_STATVFS */
# endif /* SFS_TYPE == SFS_4ARGS */
# endif /* SFS_TYPE == SFS_USTAT */
{
if (bsize != NULL)
*bsize = FSBLOCKSIZE;
if (fs.SFS_BAVAIL <= 0)
return 0;
else if (fs.SFS_BAVAIL > LONG_MAX)
return (long) LONG_MAX;
else
return (long) fs.SFS_BAVAIL;
}
return -1;
# endif /* SFS_TYPE == SFS_NONE */
}
/*
** ENOUGHDISKSPACE -- is there enough free space on the queue file systems?
**
** Parameters:
** msize -- the size to check against. If zero, we don't yet
** know how big the message will be, so just check for
** a "reasonable" amount.
** e -- envelope, or NULL -- controls logging
**
** Returns:
** true if in every queue group there is at least one
** queue directory whose file system contains enough free space.
** false otherwise.
**
** Side Effects:
** If there is not enough disk space and e != NULL
** then sm_syslog is called.
*/
bool
enoughdiskspace(msize, e)
long msize;
ENVELOPE *e;
{
int i;
#if _FFR_TESTS
if (tTd(4, 101))
return false;
#endif /* _FFR_TESTS */
if (MinBlocksFree <= 0 && msize <= 0)
{
if (tTd(4, 80))
sm_dprintf("enoughdiskspace: no threshold\n");
return true;
}
filesys_update();
for (i = 0; i < NumQueue; ++i)
{
if (pickqdir(Queue[i], msize, e) < 0)
return false;
}
return true;
}
/*
** TRANSIENTERROR -- tell if an error code indicates a transient failure
**
** This looks at an errno value and tells if this is likely to
** go away if retried later.
**
** Parameters:
** err -- the errno code to classify.
**
** Returns:
** true if this is probably transient.
** false otherwise.
*/
bool
transienterror(err)
int err;
{
switch (err)
{
case EIO: /* I/O error */
case ENXIO: /* Device not configured */
case EAGAIN: /* Resource temporarily unavailable */
case ENOMEM: /* Cannot allocate memory */
case ENODEV: /* Operation not supported by device */
case ENFILE: /* Too many open files in system */
case EMFILE: /* Too many open files */
case ENOSPC: /* No space left on device */
case ETIMEDOUT: /* Connection timed out */
#ifdef ESTALE
case ESTALE: /* Stale NFS file handle */
#endif /* ESTALE */
#ifdef ENETDOWN
case ENETDOWN: /* Network is down */
#endif /* ENETDOWN */
#ifdef ENETUNREACH
case ENETUNREACH: /* Network is unreachable */
#endif /* ENETUNREACH */
#ifdef ENETRESET
case ENETRESET: /* Network dropped connection on reset */
#endif /* ENETRESET */
#ifdef ECONNABORTED
case ECONNABORTED: /* Software caused connection abort */
#endif /* ECONNABORTED */
#ifdef ECONNRESET
case ECONNRESET: /* Connection reset by peer */
#endif /* ECONNRESET */
#ifdef ENOBUFS
case ENOBUFS: /* No buffer space available */
#endif /* ENOBUFS */
#ifdef ESHUTDOWN
case ESHUTDOWN: /* Can't send after socket shutdown */
#endif /* ESHUTDOWN */
#ifdef ECONNREFUSED
case ECONNREFUSED: /* Connection refused */
#endif /* ECONNREFUSED */
#ifdef EHOSTDOWN
case EHOSTDOWN: /* Host is down */
#endif /* EHOSTDOWN */
#ifdef EHOSTUNREACH
case EHOSTUNREACH: /* No route to host */
#endif /* EHOSTUNREACH */
#ifdef EDQUOT
case EDQUOT: /* Disc quota exceeded */
#endif /* EDQUOT */
#ifdef EPROCLIM
case EPROCLIM: /* Too many processes */
#endif /* EPROCLIM */
#ifdef EUSERS
case EUSERS: /* Too many users */
#endif /* EUSERS */
#ifdef EDEADLK
case EDEADLK: /* Resource deadlock avoided */
#endif /* EDEADLK */
#ifdef EISCONN
case EISCONN: /* Socket already connected */
#endif /* EISCONN */
#ifdef EINPROGRESS
case EINPROGRESS: /* Operation now in progress */
#endif /* EINPROGRESS */
#ifdef EALREADY
case EALREADY: /* Operation already in progress */
#endif /* EALREADY */
#ifdef EADDRINUSE
case EADDRINUSE: /* Address already in use */
#endif /* EADDRINUSE */
#ifdef EADDRNOTAVAIL
case EADDRNOTAVAIL: /* Can't assign requested address */
#endif /* EADDRNOTAVAIL */
#ifdef ETXTBSY
case ETXTBSY: /* (Apollo) file locked */
#endif /* ETXTBSY */
#if defined(ENOSR) && (!defined(ENOBUFS) || (ENOBUFS != ENOSR))
case ENOSR: /* Out of streams resources */
#endif /* defined(ENOSR) && (!defined(ENOBUFS) || (ENOBUFS != ENOSR)) */
#ifdef ENOLCK
case ENOLCK: /* No locks available */
#endif /* ENOLCK */
case E_SM_OPENTIMEOUT: /* PSEUDO: open timed out */
return true;
}
/* nope, must be permanent */
return false;
}
/*
** LOCKFILE -- lock a file using flock or (shudder) fcntl locking
**
** Parameters:
** fd -- the file descriptor of the file.
** filename -- the file name (for error messages).
** ext -- the filename extension.
** type -- type of the lock. Bits can be:
** LOCK_EX -- exclusive lock.
** LOCK_NB -- non-blocking.
** LOCK_UN -- unlock.
**
** Returns:
** true if the lock was acquired.
** false otherwise.
*/
bool
lockfile(fd, filename, ext, type)
int fd;
char *filename;
char *ext;
int type;
{
int i;
int save_errno;
# if !HASFLOCK
int action;
struct flock lfd;
if (ext == NULL)
ext = "";
memset(&lfd, '\0', sizeof(lfd));
if (bitset(LOCK_UN, type))
lfd.l_type = F_UNLCK;
else if (bitset(LOCK_EX, type))
lfd.l_type = F_WRLCK;
else
lfd.l_type = F_RDLCK;
if (bitset(LOCK_NB, type))
action = F_SETLK;
else
action = F_SETLKW;
if (tTd(55, 60))
sm_dprintf("lockfile(%s%s, action=%d, type=%d): ",
filename, ext, action, lfd.l_type);
while ((i = fcntl(fd, action, &lfd)) < 0 && errno == EINTR)
continue;
if (i >= 0)
{
if (tTd(55, 60))
sm_dprintf("SUCCESS\n");
return true;
}
save_errno = errno;
if (tTd(55, 60))
sm_dprintf("(%s) ", sm_errstring(save_errno));
/*
** On SunOS, if you are testing using -oQ/tmp/mqueue or
** -oA/tmp/aliases or anything like that, and /tmp is mounted
** as type "tmp" (that is, served from swap space), the
** previous fcntl will fail with "Invalid argument" errors.
** Since this is fairly common during testing, we will assume
** that this indicates that the lock is successfully grabbed.
*/
if (save_errno == EINVAL)
{
if (tTd(55, 60))
sm_dprintf("SUCCESS\n");
return true;
}
if (!bitset(LOCK_NB, type) ||
(save_errno != EACCES && save_errno != EAGAIN))
{
int omode = fcntl(fd, F_GETFL, 0);
uid_t euid = geteuid();
errno = save_errno;
syserr("cannot lockf(%s%s, fd=%d, type=%o, omode=%o, euid=%d)",
filename, ext, fd, type, omode, euid);
dumpfd(fd, true, true);
}
# else /* !HASFLOCK */
if (ext == NULL)
ext = "";
if (tTd(55, 60))
sm_dprintf("lockfile(%s%s, type=%o): ", filename, ext, type);
while ((i = flock(fd, type)) < 0 && errno == EINTR)
continue;
if (i >= 0)
{
if (tTd(55, 60))
sm_dprintf("SUCCESS\n");
return true;
}
save_errno = errno;
if (tTd(55, 60))
sm_dprintf("(%s) ", sm_errstring(save_errno));
if (!bitset(LOCK_NB, type) || save_errno != EWOULDBLOCK)
{
int omode = fcntl(fd, F_GETFL, 0);
uid_t euid = geteuid();
errno = save_errno;
syserr("cannot flock(%s%s, fd=%d, type=%o, omode=%o, euid=%d)",
filename, ext, fd, type, omode, euid);
dumpfd(fd, true, true);
}
# endif /* !HASFLOCK */
if (tTd(55, 60))
sm_dprintf("FAIL\n");
errno = save_errno;
return false;
}
/*
** CHOWNSAFE -- tell if chown is "safe" (executable only by root)
**
** Unfortunately, given that we can't predict other systems on which
** a remote mounted (NFS) filesystem will be mounted, the answer is
** almost always that this is unsafe.
**
** Note also that many operating systems have non-compliant
** implementations of the _POSIX_CHOWN_RESTRICTED variable and the
** fpathconf() routine. According to IEEE 1003.1-1990, if
** _POSIX_CHOWN_RESTRICTED is defined and not equal to -1, then
** no non-root process can give away the file. However, vendors
** don't take NFS into account, so a comfortable value of
** _POSIX_CHOWN_RESTRICTED tells us nothing.
**
** Also, some systems (e.g., IRIX 6.2) return 1 from fpathconf()
** even on files where chown is not restricted. Many systems get
** this wrong on NFS-based filesystems (that is, they say that chown
** is restricted [safe] on NFS filesystems where it may not be, since
** other systems can access the same filesystem and do file giveaway;
** only the NFS server knows for sure!) Hence, it is important to
** get the value of SAFENFSPATHCONF correct -- it should be defined
** _only_ after testing (see test/t_pathconf.c) a system on an unsafe
** NFS-based filesystem to ensure that you can get meaningful results.
** If in doubt, assume unsafe!
**
** You may also need to tweak IS_SAFE_CHOWN -- it should be a
** condition indicating whether the return from pathconf indicates
** that chown is safe (typically either > 0 or >= 0 -- there isn't
** even any agreement about whether a zero return means that a file
** is or is not safe). It defaults to "> 0".
**
** If the parent directory is safe (writable only by owner back
** to the root) then we can relax slightly and trust fpathconf
** in more circumstances. This is really a crock -- if this is an
** NFS mounted filesystem then we really know nothing about the
** underlying implementation. However, most systems pessimize and
** return an error (EINVAL or EOPNOTSUPP) on NFS filesystems, which
** we interpret as unsafe, as we should. Thus, this heuristic gets
** us into a possible problem only on systems that have a broken
** pathconf implementation and which are also poorly configured
** (have :include: files in group- or world-writable directories).
**
** Parameters:
** fd -- the file descriptor to check.
** safedir -- set if the parent directory is safe.
**
** Returns:
** true -- if the chown(2) operation is "safe" -- that is,
** only root can chown the file to an arbitrary user.
** false -- if an arbitrary user can give away a file.
*/
#ifndef IS_SAFE_CHOWN
# define IS_SAFE_CHOWN > 0
#endif /* ! IS_SAFE_CHOWN */
bool
chownsafe(fd, safedir)
int fd;
bool safedir;
{
# if (!defined(_POSIX_CHOWN_RESTRICTED) || _POSIX_CHOWN_RESTRICTED != -1) && \
(defined(_PC_CHOWN_RESTRICTED) || defined(_GNU_TYPES_H))
int rval;
/* give the system administrator a chance to override */
if (bitnset(DBS_ASSUMESAFECHOWN, DontBlameSendmail))
return true;
/*
** Some systems (e.g., SunOS) seem to have the call and the
** #define _PC_CHOWN_RESTRICTED, but don't actually implement
** the call. This heuristic checks for that.
*/
errno = 0;
rval = fpathconf(fd, _PC_CHOWN_RESTRICTED);
# if SAFENFSPATHCONF
return errno == 0 && rval IS_SAFE_CHOWN;
# else /* SAFENFSPATHCONF */
return safedir && errno == 0 && rval IS_SAFE_CHOWN;
# endif /* SAFENFSPATHCONF */
# else /* (!defined(_POSIX_CHOWN_RESTRICTED) || _POSIX_CHOWN_RESTRICTED != -1) && ... */
return bitnset(DBS_ASSUMESAFECHOWN, DontBlameSendmail);
# endif /* (!defined(_POSIX_CHOWN_RESTRICTED) || _POSIX_CHOWN_RESTRICTED != -1) && ... */
}
/*
** RESETLIMITS -- reset system controlled resource limits
**
** This is to avoid denial-of-service attacks
**
** Parameters:
** none
**
** Returns:
** none
*/
#if HASSETRLIMIT
# ifdef RLIMIT_NEEDS_SYS_TIME_H
# include <sm/time.h>
# endif /* RLIMIT_NEEDS_SYS_TIME_H */
# include <sys/resource.h>
#endif /* HASSETRLIMIT */
void
resetlimits()
{
#if HASSETRLIMIT
struct rlimit lim;
lim.rlim_cur = lim.rlim_max = RLIM_INFINITY;
(void) setrlimit(RLIMIT_CPU, &lim);
(void) setrlimit(RLIMIT_FSIZE, &lim);
# ifdef RLIMIT_NOFILE
lim.rlim_cur = lim.rlim_max = FD_SETSIZE;
(void) setrlimit(RLIMIT_NOFILE, &lim);
# endif /* RLIMIT_NOFILE */
#else /* HASSETRLIMIT */
# if HASULIMIT
(void) ulimit(2, 0x3fffff);
(void) ulimit(4, FD_SETSIZE);
# endif /* HASULIMIT */
#endif /* HASSETRLIMIT */
errno = 0;
}
/*
** SETVENDOR -- process vendor code from V configuration line
**
** Parameters:
** vendor -- string representation of vendor.
**
** Returns:
** true -- if ok.
** false -- if vendor code could not be processed.
**
** Side Effects:
** It is reasonable to set mode flags here to tweak
** processing in other parts of the code if necessary.
** For example, if you are a vendor that uses $%y to
** indicate YP lookups, you could enable that here.
*/
bool
setvendor(vendor)
char *vendor;
{
if (sm_strcasecmp(vendor, "Berkeley") == 0)
{
VendorCode = VENDOR_BERKELEY;
return true;
}
/* add vendor extensions here */
#ifdef SUN_EXTENSIONS
if (sm_strcasecmp(vendor, "Sun") == 0)
{
VendorCode = VENDOR_SUN;
return true;
}
#endif /* SUN_EXTENSIONS */
#ifdef DEC
if (sm_strcasecmp(vendor, "Digital") == 0)
{
VendorCode = VENDOR_DEC;
return true;
}
#endif /* DEC */
#if defined(VENDOR_NAME) && defined(VENDOR_CODE)
if (sm_strcasecmp(vendor, VENDOR_NAME) == 0)
{
VendorCode = VENDOR_CODE;
return true;
}
#endif /* defined(VENDOR_NAME) && defined(VENDOR_CODE) */
return false;
}
/*
** GETVENDOR -- return vendor name based on vendor code
**
** Parameters:
** vendorcode -- numeric representation of vendor.
**
** Returns:
** string containing vendor name.
*/
char *
getvendor(vendorcode)
int vendorcode;
{
#if defined(VENDOR_NAME) && defined(VENDOR_CODE)
/*
** Can't have the same switch case twice so need to
** handle VENDOR_CODE outside of switch. It might
** match one of the existing VENDOR_* codes.
*/
if (vendorcode == VENDOR_CODE)
return VENDOR_NAME;
#endif /* defined(VENDOR_NAME) && defined(VENDOR_CODE) */
switch (vendorcode)
{
case VENDOR_BERKELEY:
return "Berkeley";
case VENDOR_SUN:
return "Sun";
case VENDOR_HP:
return "HP";
case VENDOR_IBM:
return "IBM";
case VENDOR_SENDMAIL:
return "Sendmail";
default:
return "Unknown";
}
}
/*
** VENDOR_PRE_DEFAULTS, VENDOR_POST_DEFAULTS -- set vendor-specific defaults
**
** Vendor_pre_defaults is called before reading the configuration
** file; vendor_post_defaults is called immediately after.
**
** Parameters:
** e -- the global environment to initialize.
**
** Returns:
** none.
*/
#if SHARE_V1
int DefShareUid; /* default share uid to run as -- unused??? */
#endif /* SHARE_V1 */
void
vendor_pre_defaults(e)
ENVELOPE *e;
{
#if SHARE_V1
/* OTHERUID is defined in shares.h, do not be alarmed */
DefShareUid = OTHERUID;
#endif /* SHARE_V1 */
#if defined(SUN_EXTENSIONS) && defined(SUN_DEFAULT_VALUES)
sun_pre_defaults(e);
#endif /* defined(SUN_EXTENSIONS) && defined(SUN_DEFAULT_VALUES) */
#ifdef apollo
/*
** stupid domain/os can't even open
** /etc/mail/sendmail.cf without this
*/
sm_setuserenv("ISP", NULL);
sm_setuserenv("SYSTYPE", NULL);
#endif /* apollo */
}
void
vendor_post_defaults(e)
ENVELOPE *e;
{
#ifdef __QNX__
/* Makes sure the SOCK environment variable remains */
sm_setuserenv("SOCK", NULL);
#endif /* __QNX__ */
#if defined(SUN_EXTENSIONS) && defined(SUN_DEFAULT_VALUES)
sun_post_defaults(e);
#endif /* defined(SUN_EXTENSIONS) && defined(SUN_DEFAULT_VALUES) */
}
/*
** VENDOR_DAEMON_SETUP -- special vendor setup needed for daemon mode
*/
void
vendor_daemon_setup(e)
ENVELOPE *e;
{
#if HASSETLOGIN
(void) setlogin(RunAsUserName);
#endif /* HASSETLOGIN */
#if SECUREWARE
if (getluid() != -1)
{
usrerr("Daemon cannot have LUID");
finis(false, true, EX_USAGE);
}
#endif /* SECUREWARE */
}
/*
** VENDOR_SET_UID -- do setup for setting a user id
**
** This is called when we are still root.
**
** Parameters:
** uid -- the uid we are about to become.
**
** Returns:
** none.
*/
void
vendor_set_uid(uid)
UID_T uid;
{
/*
** We need to setup the share groups (lnodes)
** and add auditing information (luid's)
** before we loose our ``root''ness.
*/
#if SHARE_V1
if (setupshares(uid, syserr) != 0)
syserr("Unable to set up shares");
#endif /* SHARE_V1 */
#if SECUREWARE
(void) setup_secure(uid);
#endif /* SECUREWARE */
}
/*
** VALIDATE_CONNECTION -- check connection for rationality
**
** If the connection is rejected, this routine should log an
** appropriate message -- but should never issue any SMTP protocol.
**
** Parameters:
** sap -- a pointer to a SOCKADDR naming the peer.
** hostname -- the name corresponding to sap.
** e -- the current envelope.
**
** Returns:
** error message from rejection.
** NULL if not rejected.
*/
#if TCPWRAPPERS
# include <tcpd.h>
/* tcpwrappers does no logging, but you still have to declare these -- ugh */
int allow_severity = LOG_INFO;
int deny_severity = LOG_NOTICE;
#endif /* TCPWRAPPERS */
char *
validate_connection(sap, hostname, e)
SOCKADDR *sap;
char *hostname;
ENVELOPE *e;
{
#if TCPWRAPPERS
char *host;
char *addr;
extern int hosts_ctl();
#endif /* TCPWRAPPERS */
if (tTd(48, 3))
sm_dprintf("validate_connection(%s, %s)\n",
hostname, anynet_ntoa(sap));
connection_rate_check(sap, e);
if (rscheck("check_relay", hostname, anynet_ntoa(sap),
e, RSF_RMCOMM|RSF_COUNT, 3, NULL, NOQID, NULL) != EX_OK)
{
static char reject[BUFSIZ*2];
extern char MsgBuf[];
if (tTd(48, 4))
sm_dprintf(" ... validate_connection: BAD (rscheck)\n");
if (strlen(MsgBuf) >= 3)
(void) sm_strlcpy(reject, MsgBuf, sizeof(reject));
else
(void) sm_strlcpy(reject, "Access denied", sizeof(reject));
return reject;
}
#if TCPWRAPPERS
if (hostname[0] == '[' && hostname[strlen(hostname) - 1] == ']')
host = "unknown";
else
host = hostname;
addr = anynet_ntoa(sap);
# if NETINET6
/* TCP/Wrappers don't want the IPv6: protocol label */
if (addr != NULL && sm_strncasecmp(addr, "IPv6:", 5) == 0)
addr += 5;
# endif /* NETINET6 */
if (!hosts_ctl("sendmail", host, addr, STRING_UNKNOWN))
{
if (tTd(48, 4))
sm_dprintf(" ... validate_connection: BAD (tcpwrappers)\n");
if (LogLevel > 3)
sm_syslog(LOG_NOTICE, e->e_id,
"tcpwrappers (%s, %s) rejection",
host, addr);
return "Access denied";
}
#endif /* TCPWRAPPERS */
if (tTd(48, 4))
sm_dprintf(" ... validate_connection: OK\n");
return NULL;
}
/*
** STRTOL -- convert string to long integer
**
** For systems that don't have it in the C library.
**
** This is taken verbatim from the 4.4-Lite C library.
*/
#if NEEDSTRTOL
# if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)strtol.c 8.1 (Berkeley) 6/4/93";
# endif /* defined(LIBC_SCCS) && !defined(lint) */
/*
** Convert a string to a long integer.
**
** Ignores `locale' stuff. Assumes that the upper and lower case
** alphabets and digits are each contiguous.
*/
long
strtol(nptr, endptr, base)
const char *nptr;
char **endptr;
register int base;
{
register const char *s = nptr;
register unsigned long acc;
register int c;
register unsigned long cutoff;
register int neg = 0, any, cutlim;
/*
** Skip white space and pick up leading +/- sign if any.
** If base is 0, allow 0x for hex and 0 for octal, else
** assume decimal; if base is already 16, allow 0x.
*/
do {
c = *s++;
} while (isascii(c) && isspace(c));
if (c == '-') {
neg = 1;
c = *s++;
} else if (c == '+')
c = *s++;
if ((base == 0 || base == 16) &&
c == '0' && (*s == 'x' || *s == 'X')) {
c = s[1];
s += 2;
base = 16;
}
if (base == 0)
base = c == '0' ? 8 : 10;
/*
** Compute the cutoff value between legal numbers and illegal
** numbers. That is the largest legal value, divided by the
** base. An input number that is greater than this value, if
** followed by a legal input character, is too big. One that
** is equal to this value may be valid or not; the limit
** between valid and invalid numbers is then based on the last
** digit. For instance, if the range for longs is
** [-2147483648..2147483647] and the input base is 10,
** cutoff will be set to 214748364 and cutlim to either
** 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated
** a value > 214748364, or equal but the next digit is > 7 (or 8),
** the number is too big, and we will return a range error.
**
** Set any if any `digits' consumed; make it negative to indicate
** overflow.
*/
cutoff = neg ? -(unsigned long) LONG_MIN : LONG_MAX;
cutlim = cutoff % (unsigned long) base;
cutoff /= (unsigned long) base;
for (acc = 0, any = 0;; c = *s++) {
if (isascii(c) && isdigit(c))
c -= '0';
else if (isascii(c) && isalpha(c))
c -= isupper(c) ? 'A' - 10 : 'a' - 10;
else
break;
if (c >= base)
break;
if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim)
any = -1;
else {
any = 1;
acc *= base;
acc += c;
}
}
if (any < 0) {
acc = neg ? LONG_MIN : LONG_MAX;
errno = ERANGE;
} else if (neg)
acc = -acc;
if (endptr != 0)
*endptr = (char *)(any ? s - 1 : nptr);
return acc;
}
#endif /* NEEDSTRTOL */
/*
** STRSTR -- find first substring in string
**
** Parameters:
** big -- the big (full) string.
** little -- the little (sub) string.
**
** Returns:
** A pointer to the first instance of little in big.
** big if little is the null string.
** NULL if little is not contained in big.
*/
#if NEEDSTRSTR
char *
strstr(big, little)
char *big;
char *little;
{
register char *p = big;
int l;
if (*little == '\0')
return big;
l = strlen(little);
while ((p = strchr(p, *little)) != NULL)
{
if (strncmp(p, little, l) == 0)
return p;
p++;
}
return NULL;
}
#endif /* NEEDSTRSTR */
/*
** SM_GETHOSTBY{NAME,ADDR} -- compatibility routines for gethostbyXXX
**
** Some operating systems have wierd problems with the gethostbyXXX
** routines. For example, Solaris versions at least through 2.3
** don't properly deliver a canonical h_name field. This tries to
** work around these problems.
**
** Support IPv6 as well as IPv4.
*/
#if NETINET6 && NEEDSGETIPNODE
# ifndef AI_DEFAULT
# define AI_DEFAULT 0 /* dummy */
# endif /* ! AI_DEFAULT */
# ifndef AI_ADDRCONFIG
# define AI_ADDRCONFIG 0 /* dummy */
# endif /* ! AI_ADDRCONFIG */
# ifndef AI_V4MAPPED
# define AI_V4MAPPED 0 /* dummy */
# endif /* ! AI_V4MAPPED */
# ifndef AI_ALL
# define AI_ALL 0 /* dummy */
# endif /* ! AI_ALL */
static struct hostent *
getipnodebyname(name, family, flags, err)
char *name;
int family;
int flags;
int *err;
{
bool resv6 = true;
struct hostent *h;
if (family == AF_INET6)
{
/* From RFC2133, section 6.1 */
resv6 = bitset(RES_USE_INET6, _res.options);
_res.options |= RES_USE_INET6;
}
SM_SET_H_ERRNO(0);
h = gethostbyname(name);
if (!resv6)
_res.options &= ~RES_USE_INET6;
*err = h_errno;
return h;
}
static struct hostent *
getipnodebyaddr(addr, len, family, err)
char *addr;
int len;
int family;
int *err;
{
struct hostent *h;
SM_SET_H_ERRNO(0);
h = gethostbyaddr(addr, len, family);
*err = h_errno;
return h;
}
void
freehostent(h)
struct hostent *h;
{
/*
** Stub routine -- if they don't have getipnodeby*(),
** they probably don't have the free routine either.
*/
return;
}
#endif /* NETINET6 && NEEDSGETIPNODE */
struct hostent *
sm_gethostbyname(name, family)
char *name;
int family;
{
int save_errno;
struct hostent *h = NULL;
#if (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) || (defined(sony_news) && defined(__svr4))
# if SOLARIS == 20300 || SOLARIS == 203
static struct hostent hp;
static char buf[1000];
extern struct hostent *_switch_gethostbyname_r();
if (tTd(61, 10))
sm_dprintf("_switch_gethostbyname_r(%s)... ", name);
h = _switch_gethostbyname_r(name, &hp, buf, sizeof(buf), &h_errno);
save_errno = errno;
# else /* SOLARIS == 20300 || SOLARIS == 203 */
extern struct hostent *__switch_gethostbyname();
if (tTd(61, 10))
sm_dprintf("__switch_gethostbyname(%s)... ", name);
h = __switch_gethostbyname(name);
save_errno = errno;
# endif /* SOLARIS == 20300 || SOLARIS == 203 */
#else /* (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) || (defined(sony_news) && defined(__svr4)) */
int nmaps;
# if NETINET6
int flags = AI_DEFAULT|AI_ALL;
int err;
# endif /* NETINET6 */
char *maptype[MAXMAPSTACK];
short mapreturn[MAXMAPACTIONS];
char hbuf[MAXNAME];
if (tTd(61, 10))
sm_dprintf("sm_gethostbyname(%s, %d)... ", name, family);
# if NETINET6
# if ADDRCONFIG_IS_BROKEN
flags &= ~AI_ADDRCONFIG;
# endif /* ADDRCONFIG_IS_BROKEN */
h = getipnodebyname(name, family, flags, &err);
SM_SET_H_ERRNO(err);
# else /* NETINET6 */
h = gethostbyname(name);
# endif /* NETINET6 */
save_errno = errno;
if (h == NULL)
{
if (tTd(61, 10))
sm_dprintf("failure\n");
nmaps = switch_map_find("hosts", maptype, mapreturn);
while (--nmaps >= 0)
{
if (strcmp(maptype[nmaps], "nis") == 0 ||
strcmp(maptype[nmaps], "files") == 0)
break;
}
if (nmaps >= 0)
{
/* try short name */
if (strlen(name) > sizeof(hbuf) - 1)
{
errno = save_errno;
return NULL;
}
(void) sm_strlcpy(hbuf, name, sizeof(hbuf));
(void) shorten_hostname(hbuf);
/* if it hasn't been shortened, there's no point */
if (strcmp(hbuf, name) != 0)
{
if (tTd(61, 10))
sm_dprintf("sm_gethostbyname(%s, %d)... ",
hbuf, family);
# if NETINET6
h = getipnodebyname(hbuf, family, flags, &err);
SM_SET_H_ERRNO(err);
save_errno = errno;
# else /* NETINET6 */
h = gethostbyname(hbuf);
save_errno = errno;
# endif /* NETINET6 */
}
}
}
#endif /* (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) || (defined(sony_news) && defined(__svr4)) */
if (tTd(61, 10))
{
if (h == NULL)
sm_dprintf("failure\n");
else
{
sm_dprintf("%s\n", h->h_name);
if (tTd(61, 11))
{
#if NETINET6
struct in6_addr ia6;
char buf6[INET6_ADDRSTRLEN];
#else /* NETINET6 */
struct in_addr ia;
#endif /* NETINET6 */
size_t i;
if (h->h_aliases != NULL)
for (i = 0; h->h_aliases[i] != NULL;
i++)
sm_dprintf("\talias: %s\n",
h->h_aliases[i]);
for (i = 0; h->h_addr_list[i] != NULL; i++)
{
char *addr;
#if NETINET6
memmove(&ia6, h->h_addr_list[i],
IN6ADDRSZ);
addr = anynet_ntop(&ia6,
buf6, sizeof(buf6));
#else /* NETINET6 */
memmove(&ia, h->h_addr_list[i],
INADDRSZ);
addr = (char *) inet_ntoa(ia);
#endif /* NETINET6 */
if (addr != NULL)
sm_dprintf("\taddr: %s\n", addr);
}
}
}
}
errno = save_errno;
return h;
}
struct hostent *
sm_gethostbyaddr(addr, len, type)
char *addr;
int len;
int type;
{
struct hostent *hp;
#if NETINET6
if (type == AF_INET6 &&
IN6_IS_ADDR_UNSPECIFIED((struct in6_addr *) addr))
{
/* Avoid reverse lookup for IPv6 unspecified address */
SM_SET_H_ERRNO(HOST_NOT_FOUND);
return NULL;
}
#endif /* NETINET6 */
#if (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204)
# if SOLARIS == 20300 || SOLARIS == 203
{
static struct hostent he;
static char buf[1000];
extern struct hostent *_switch_gethostbyaddr_r();
hp = _switch_gethostbyaddr_r(addr, len, type, &he,
buf, sizeof(buf), &h_errno);
}
# else /* SOLARIS == 20300 || SOLARIS == 203 */
{
extern struct hostent *__switch_gethostbyaddr();
hp = __switch_gethostbyaddr(addr, len, type);
}
# endif /* SOLARIS == 20300 || SOLARIS == 203 */
#else /* (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) */
# if NETINET6
{
int err;
hp = getipnodebyaddr(addr, len, type, &err);
SM_SET_H_ERRNO(err);
}
# else /* NETINET6 */
hp = gethostbyaddr(addr, len, type);
# endif /* NETINET6 */
#endif /* (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) */
return hp;
}
/*
** SM_GETPW{NAM,UID} -- wrapper for getpwnam and getpwuid
*/
struct passwd *
sm_getpwnam(user)
char *user;
{
#ifdef _AIX4
extern struct passwd *_getpwnam_shadow(const char *, const int);
return _getpwnam_shadow(user, 0);
#else /* _AIX4 */
return getpwnam(user);
#endif /* _AIX4 */
}
struct passwd *
sm_getpwuid(uid)
UID_T uid;
{
#if defined(_AIX4) && 0
extern struct passwd *_getpwuid_shadow(const int, const int);
return _getpwuid_shadow(uid,0);
#else /* defined(_AIX4) && 0 */
return getpwuid(uid);
#endif /* defined(_AIX4) && 0 */
}
/*
** SECUREWARE_SETUP_SECURE -- Convex SecureWare setup
**
** Set up the trusted computing environment for C2 level security
** under SecureWare.
**
** Parameters:
** uid -- uid of the user to initialize in the TCB
**
** Returns:
** none
**
** Side Effects:
** Initialized the user in the trusted computing base
*/
#if SECUREWARE
# include <sys/security.h>
# include <prot.h>
void
secureware_setup_secure(uid)
UID_T uid;
{
int rc;
if (getluid() != -1)
return;
if ((rc = set_secure_info(uid)) != SSI_GOOD_RETURN)
{
switch (rc)
{
case SSI_NO_PRPW_ENTRY:
syserr("No protected passwd entry, uid = %d",
(int) uid);
break;
case SSI_LOCKED:
syserr("Account has been disabled, uid = %d",
(int) uid);
break;
case SSI_RETIRED:
syserr("Account has been retired, uid = %d",
(int) uid);
break;
case SSI_BAD_SET_LUID:
syserr("Could not set LUID, uid = %d", (int) uid);
break;
case SSI_BAD_SET_PRIVS:
syserr("Could not set kernel privs, uid = %d",
(int) uid);
default:
syserr("Unknown return code (%d) from set_secure_info(%d)",
rc, (int) uid);
break;
}
finis(false, true, EX_NOPERM);
}
}
#endif /* SECUREWARE */
/*
** ADD_HOSTNAMES -- Add a hostname to class 'w' based on IP address
**
** Add hostnames to class 'w' based on the IP address read from
** the network interface.
**
** Parameters:
** sa -- a pointer to a SOCKADDR containing the address
**
** Returns:
** 0 if successful, -1 if host lookup fails.
*/
static int
add_hostnames(sa)
SOCKADDR *sa;
{
struct hostent *hp;
char **ha;
char hnb[MAXHOSTNAMELEN];
/* lookup name with IP address */
switch (sa->sa.sa_family)
{
#if NETINET
case AF_INET:
hp = sm_gethostbyaddr((char *) &sa->sin.sin_addr,
sizeof(sa->sin.sin_addr),
sa->sa.sa_family);
break;
#endif /* NETINET */
#if NETINET6
case AF_INET6:
hp = sm_gethostbyaddr((char *) &sa->sin6.sin6_addr,
sizeof(sa->sin6.sin6_addr),
sa->sa.sa_family);
break;
#endif /* NETINET6 */
default:
/* Give warning about unsupported family */
if (LogLevel > 3)
sm_syslog(LOG_WARNING, NOQID,
"Unsupported address family %d: %.100s",
sa->sa.sa_family, anynet_ntoa(sa));
return -1;
}
if (hp == NULL)
{
int save_errno = errno;
if (LogLevel > 3 &&
#if NETINET6
!(sa->sa.sa_family == AF_INET6 &&
IN6_IS_ADDR_LINKLOCAL(&sa->sin6.sin6_addr)) &&
#endif /* NETINET6 */
true)
sm_syslog(LOG_WARNING, NOQID,
"gethostbyaddr(%.100s) failed: %d",
anynet_ntoa(sa),
#if NAMED_BIND
h_errno
#else /* NAMED_BIND */
-1
#endif /* NAMED_BIND */
);
errno = save_errno;
return -1;
}
/* save its cname */
if (!wordinclass((char *) hp->h_name, 'w'))
{
setclass('w', (char *) hp->h_name);
if (tTd(0, 4))
sm_dprintf("\ta.k.a.: %s\n", hp->h_name);
if (sm_snprintf(hnb, sizeof(hnb), "[%s]", hp->h_name) <
sizeof(hnb)
&& !wordinclass((char *) hnb, 'w'))
setclass('w', hnb);
}
else
{
if (tTd(0, 43))
sm_dprintf("\ta.k.a.: %s (already in $=w)\n", hp->h_name);
}
/* save all it aliases name */
for (ha = hp->h_aliases; ha != NULL && *ha != NULL; ha++)
{
if (!wordinclass(*ha, 'w'))
{
setclass('w', *ha);
if (tTd(0, 4))
sm_dprintf("\ta.k.a.: %s\n", *ha);
if (sm_snprintf(hnb, sizeof(hnb),
"[%s]", *ha) < sizeof(hnb) &&
!wordinclass((char *) hnb, 'w'))
setclass('w', hnb);
}
else
{
if (tTd(0, 43))
sm_dprintf("\ta.k.a.: %s (already in $=w)\n",
*ha);
}
}
#if NETINET6
freehostent(hp);
#endif /* NETINET6 */
return 0;
}
/*
** LOAD_IF_NAMES -- load interface-specific names into $=w
**
** Parameters:
** none.
**
** Returns:
** none.
**
** Side Effects:
** Loads $=w with the names of all the interfaces.
*/
#if !NETINET
# define SIOCGIFCONF_IS_BROKEN 1 /* XXX */
#endif /* !NETINET */
#if defined(SIOCGIFCONF) && !SIOCGIFCONF_IS_BROKEN
struct rtentry;
struct mbuf;
# ifndef SUNOS403
# include <sm/time.h>
# endif /* ! SUNOS403 */
# if (_AIX4 >= 40300) && !defined(_NET_IF_H)
# undef __P
# endif /* (_AIX4 >= 40300) && !defined(_NET_IF_H) */
# include <net/if.h>
#endif /* defined(SIOCGIFCONF) && !SIOCGIFCONF_IS_BROKEN */
void
load_if_names()
{
# if NETINET6 && defined(SIOCGLIFCONF)
# ifdef __hpux
/*
** Unfortunately, HP has changed all of the structures,
** making life difficult for implementors.
*/
# define lifconf if_laddrconf
# define lifc_len iflc_len
# define lifc_buf iflc_buf
# define lifreq if_laddrreq
# define lifr_addr iflr_addr
# define lifr_name iflr_name
# define lifr_flags iflr_flags
# define ss_family sa_family
# undef SIOCGLIFNUM
# endif /* __hpux */
int s;
int i;
size_t len;
int numifs;
char *buf;
struct lifconf lifc;
# ifdef SIOCGLIFNUM
struct lifnum lifn;
# endif /* SIOCGLIFNUM */
s = socket(InetMode, SOCK_DGRAM, 0);
if (s == -1)
return;
/* get the list of known IP address from the kernel */
# ifdef __hpux
i = ioctl(s, SIOCGIFNUM, (char *) &numifs);
# endif /* __hpux */
# ifdef SIOCGLIFNUM
lifn.lifn_family = AF_UNSPEC;
lifn.lifn_flags = 0;
i = ioctl(s, SIOCGLIFNUM, (char *)&lifn);
numifs = lifn.lifn_count;
# endif /* SIOCGLIFNUM */
# if defined(__hpux) || defined(SIOCGLIFNUM)
if (i < 0)
{
/* can't get number of interfaces -- fall back */
if (tTd(0, 4))
sm_dprintf("SIOCGLIFNUM failed: %s\n",
sm_errstring(errno));
numifs = -1;
}
else if (tTd(0, 42))
sm_dprintf("system has %d interfaces\n", numifs);
if (numifs < 0)
# endif /* defined(__hpux) || defined(SIOCGLIFNUM) */
numifs = MAXINTERFACES;
if (numifs <= 0)
{
(void) close(s);
return;
}
len = lifc.lifc_len = numifs * sizeof(struct lifreq);
buf = lifc.lifc_buf = xalloc(lifc.lifc_len);
# ifndef __hpux
lifc.lifc_family = AF_UNSPEC;
lifc.lifc_flags = 0;
# endif /* ! __hpux */
if (ioctl(s, SIOCGLIFCONF, (char *)&lifc) < 0)
{
if (tTd(0, 4))
sm_dprintf("SIOCGLIFCONF failed: %s\n",
sm_errstring(errno));
(void) close(s);
sm_free(buf);
return;
}
/* scan the list of IP address */
if (tTd(0, 40))
sm_dprintf("scanning for interface specific names, lifc_len=%ld\n",
(long) len);
for (i = 0; i < len && i >= 0; )
{
int flags;
struct lifreq *ifr = (struct lifreq *)&buf[i];
SOCKADDR *sa = (SOCKADDR *) &ifr->lifr_addr;
int af = ifr->lifr_addr.ss_family;
char *addr;
char *name;
struct in6_addr ia6;
struct in_addr ia;
# ifdef SIOCGLIFFLAGS
struct lifreq ifrf;
# endif /* SIOCGLIFFLAGS */
char ip_addr[256];
char buf6[INET6_ADDRSTRLEN];
/*
** We must close and recreate the socket each time
** since we don't know what type of socket it is now
** (each status function may change it).
*/
(void) close(s);
s = socket(af, SOCK_DGRAM, 0);
if (s == -1)
{
sm_free(buf); /* XXX */
return;
}
/*
** If we don't have a complete ifr structure,
** don't try to use it.
*/
if ((len - i) < sizeof(*ifr))
break;
# ifdef BSD4_4_SOCKADDR
if (sa->sa.sa_len > sizeof(ifr->lifr_addr))
i += sizeof(ifr->lifr_name) + sa->sa.sa_len;
else
# endif /* BSD4_4_SOCKADDR */
# ifdef DEC
/* fix for IPv6 size differences */
i += sizeof(ifr->ifr_name) +
max(sizeof(ifr->ifr_addr), ifr->ifr_addr.sa_len);
# else /* DEC */
i += sizeof(*ifr);
# endif /* DEC */
if (tTd(0, 20))
sm_dprintf("%s\n", anynet_ntoa(sa));
if (af != AF_INET && af != AF_INET6)
continue;
# ifdef SIOCGLIFFLAGS
memset(&ifrf, '\0', sizeof(struct lifreq));
(void) sm_strlcpy(ifrf.lifr_name, ifr->lifr_name,
sizeof(ifrf.lifr_name));
if (ioctl(s, SIOCGLIFFLAGS, (char *) &ifrf) < 0)
{
if (tTd(0, 4))
sm_dprintf("SIOCGLIFFLAGS failed: %s\n",
sm_errstring(errno));
continue;
}
name = ifr->lifr_name;
flags = ifrf.lifr_flags;
if (tTd(0, 41))
sm_dprintf("\tflags: %lx\n", (unsigned long) flags);
if (!bitset(IFF_UP, flags))
continue;
# endif /* SIOCGLIFFLAGS */
ip_addr[0] = '\0';
/* extract IP address from the list*/
switch (af)
{
case AF_INET6:
# ifdef __KAME__
/* convert into proper scoped address */
if ((IN6_IS_ADDR_LINKLOCAL(&sa->sin6.sin6_addr) ||
IN6_IS_ADDR_SITELOCAL(&sa->sin6.sin6_addr)) &&
sa->sin6.sin6_scope_id == 0)
{
struct in6_addr *ia6p;
ia6p = &sa->sin6.sin6_addr;
sa->sin6.sin6_scope_id = ntohs(ia6p->s6_addr[3] |
((unsigned int)ia6p->s6_addr[2] << 8));
ia6p->s6_addr[2] = ia6p->s6_addr[3] = 0;
}
# endif /* __KAME__ */
ia6 = sa->sin6.sin6_addr;
if (IN6_IS_ADDR_UNSPECIFIED(&ia6))
{
addr = anynet_ntop(&ia6, buf6, sizeof(buf6));
message("WARNING: interface %s is UP with %s address",
name, addr == NULL ? "(NULL)" : addr);
continue;
}
/* save IP address in text from */
addr = anynet_ntop(&ia6, buf6, sizeof(buf6));
if (addr != NULL)
(void) sm_snprintf(ip_addr, sizeof(ip_addr),
"[%.*s]",
(int) sizeof(ip_addr) - 3,
addr);
break;
case AF_INET:
ia = sa->sin.sin_addr;
if (ia.s_addr == INADDR_ANY ||
ia.s_addr == INADDR_NONE)
{
message("WARNING: interface %s is UP with %s address",
name, inet_ntoa(ia));
continue;
}
/* save IP address in text from */
(void) sm_snprintf(ip_addr, sizeof(ip_addr), "[%.*s]",
(int) sizeof(ip_addr) - 3, inet_ntoa(ia));
break;
}
if (*ip_addr == '\0')
continue;
if (!wordinclass(ip_addr, 'w'))
{
setclass('w', ip_addr);
if (tTd(0, 4))
sm_dprintf("\ta.k.a.: %s\n", ip_addr);
}
# ifdef SIOCGLIFFLAGS
/* skip "loopback" interface "lo" */
if (DontProbeInterfaces == DPI_SKIPLOOPBACK &&
bitset(IFF_LOOPBACK, flags))
continue;
# endif /* SIOCGLIFFLAGS */
(void) add_hostnames(sa);
}
sm_free(buf); /* XXX */
(void) close(s);
# else /* NETINET6 && defined(SIOCGLIFCONF) */
# if defined(SIOCGIFCONF) && !SIOCGIFCONF_IS_BROKEN
int s;
int i;
struct ifconf ifc;
int numifs;
s = socket(AF_INET, SOCK_DGRAM, 0);
if (s == -1)
return;
/* get the list of known IP address from the kernel */
# if defined(SIOCGIFNUM) && !SIOCGIFNUM_IS_BROKEN
if (ioctl(s, SIOCGIFNUM, (char *) &numifs) < 0)
{
/* can't get number of interfaces -- fall back */
if (tTd(0, 4))
sm_dprintf("SIOCGIFNUM failed: %s\n",
sm_errstring(errno));
numifs = -1;
}
else if (tTd(0, 42))
sm_dprintf("system has %d interfaces\n", numifs);
if (numifs < 0)
# endif /* defined(SIOCGIFNUM) && !SIOCGIFNUM_IS_BROKEN */
numifs = MAXINTERFACES;
if (numifs <= 0)
{
(void) close(s);
return;
}
ifc.ifc_len = numifs * sizeof(struct ifreq);
ifc.ifc_buf = xalloc(ifc.ifc_len);
if (ioctl(s, SIOCGIFCONF, (char *)&ifc) < 0)
{
if (tTd(0, 4))
sm_dprintf("SIOCGIFCONF failed: %s\n",
sm_errstring(errno));
(void) close(s);
return;
}
/* scan the list of IP address */
if (tTd(0, 40))
sm_dprintf("scanning for interface specific names, ifc_len=%d\n",
ifc.ifc_len);
for (i = 0; i < ifc.ifc_len && i >= 0; )
{
int af;
struct ifreq *ifr = (struct ifreq *) &ifc.ifc_buf[i];
SOCKADDR *sa = (SOCKADDR *) &ifr->ifr_addr;
# if NETINET6
char *addr;
struct in6_addr ia6;
# endif /* NETINET6 */
struct in_addr ia;
# ifdef SIOCGIFFLAGS
struct ifreq ifrf;
# endif /* SIOCGIFFLAGS */
char ip_addr[256];
# if NETINET6
char buf6[INET6_ADDRSTRLEN];
# endif /* NETINET6 */
/*
** If we don't have a complete ifr structure,
** don't try to use it.
*/
if ((ifc.ifc_len - i) < sizeof(*ifr))
break;
# ifdef BSD4_4_SOCKADDR
if (sa->sa.sa_len > sizeof(ifr->ifr_addr))
i += sizeof(ifr->ifr_name) + sa->sa.sa_len;
else
# endif /* BSD4_4_SOCKADDR */
i += sizeof(*ifr);
if (tTd(0, 20))
sm_dprintf("%s\n", anynet_ntoa(sa));
af = ifr->ifr_addr.sa_family;
if (af != AF_INET
# if NETINET6
&& af != AF_INET6
# endif /* NETINET6 */
)
continue;
# ifdef SIOCGIFFLAGS
memset(&ifrf, '\0', sizeof(struct ifreq));
(void) sm_strlcpy(ifrf.ifr_name, ifr->ifr_name,
sizeof(ifrf.ifr_name));
(void) ioctl(s, SIOCGIFFLAGS, (char *) &ifrf);
if (tTd(0, 41))
sm_dprintf("\tflags: %lx\n",
(unsigned long) ifrf.ifr_flags);
# define IFRFREF ifrf
# else /* SIOCGIFFLAGS */
# define IFRFREF (*ifr)
# endif /* SIOCGIFFLAGS */
if (!bitset(IFF_UP, IFRFREF.ifr_flags))
continue;
ip_addr[0] = '\0';
/* extract IP address from the list*/
switch (af)
{
case AF_INET:
ia = sa->sin.sin_addr;
if (ia.s_addr == INADDR_ANY ||
ia.s_addr == INADDR_NONE)
{
message("WARNING: interface %s is UP with %s address",
ifr->ifr_name, inet_ntoa(ia));
continue;
}
/* save IP address in text from */
(void) sm_snprintf(ip_addr, sizeof(ip_addr), "[%.*s]",
(int) sizeof(ip_addr) - 3,
inet_ntoa(ia));
break;
# if NETINET6
case AF_INET6:
# ifdef __KAME__
/* convert into proper scoped address */
if ((IN6_IS_ADDR_LINKLOCAL(&sa->sin6.sin6_addr) ||
IN6_IS_ADDR_SITELOCAL(&sa->sin6.sin6_addr)) &&
sa->sin6.sin6_scope_id == 0)
{
struct in6_addr *ia6p;
ia6p = &sa->sin6.sin6_addr;
sa->sin6.sin6_scope_id = ntohs(ia6p->s6_addr[3] |
((unsigned int)ia6p->s6_addr[2] << 8));
ia6p->s6_addr[2] = ia6p->s6_addr[3] = 0;
}
# endif /* __KAME__ */
ia6 = sa->sin6.sin6_addr;
if (IN6_IS_ADDR_UNSPECIFIED(&ia6))
{
addr = anynet_ntop(&ia6, buf6, sizeof(buf6));
message("WARNING: interface %s is UP with %s address",
ifr->ifr_name,
addr == NULL ? "(NULL)" : addr);
continue;
}
/* save IP address in text from */
addr = anynet_ntop(&ia6, buf6, sizeof(buf6));
if (addr != NULL)
(void) sm_snprintf(ip_addr, sizeof(ip_addr),
"[%.*s]",
(int) sizeof(ip_addr) - 3,
addr);
break;
# endif /* NETINET6 */
}
if (ip_addr[0] == '\0')
continue;
if (!wordinclass(ip_addr, 'w'))
{
setclass('w', ip_addr);
if (tTd(0, 4))
sm_dprintf("\ta.k.a.: %s\n", ip_addr);
}
/* skip "loopback" interface "lo" */
if (DontProbeInterfaces == DPI_SKIPLOOPBACK &&
bitset(IFF_LOOPBACK, IFRFREF.ifr_flags))
continue;
(void) add_hostnames(sa);
}
sm_free(ifc.ifc_buf); /* XXX */
(void) close(s);
# undef IFRFREF
# endif /* defined(SIOCGIFCONF) && !SIOCGIFCONF_IS_BROKEN */
# endif /* NETINET6 && defined(SIOCGLIFCONF) */
}
/*
** ISLOOPBACK -- is socket address in the loopback net?
**
** Parameters:
** sa -- socket address.
**
** Returns:
** true -- is socket address in the loopback net?
** false -- otherwise
**
*/
bool
isloopback(sa)
SOCKADDR sa;
{
#if NETINET6
if (IN6_IS_ADDR_LOOPBACK(&sa.sin6.sin6_addr))
return true;
#else /* NETINET6 */
/* XXX how to correctly extract IN_LOOPBACKNET part? */
if (((ntohl(sa.sin.sin_addr.s_addr) & IN_CLASSA_NET)
>> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET)
return true;
#endif /* NETINET6 */
return false;
}
/*
** GET_NUM_PROCS_ONLINE -- return the number of processors currently online
**
** Parameters:
** none.
**
** Returns:
** The number of processors online.
*/
static int
get_num_procs_online()
{
int nproc = 0;
#ifdef USESYSCTL
# if defined(CTL_HW) && defined(HW_NCPU)
size_t sz;
int mib[2];
mib[0] = CTL_HW;
mib[1] = HW_NCPU;
sz = (size_t) sizeof(nproc);
(void) sysctl(mib, 2, &nproc, &sz, NULL, 0);
# endif /* defined(CTL_HW) && defined(HW_NCPU) */
#else /* USESYSCTL */
# ifdef _SC_NPROCESSORS_ONLN
nproc = (int) sysconf(_SC_NPROCESSORS_ONLN);
# else /* _SC_NPROCESSORS_ONLN */
# ifdef __hpux
# include <sys/pstat.h>
struct pst_dynamic psd;
if (pstat_getdynamic(&psd, sizeof(psd), (size_t)1, 0) != -1)
nproc = psd.psd_proc_cnt;
# endif /* __hpux */
# endif /* _SC_NPROCESSORS_ONLN */
#endif /* USESYSCTL */
if (nproc <= 0)
nproc = 1;
return nproc;
}
/*
** SM_CLOSEFROM -- close file descriptors
**
** Parameters:
** lowest -- first fd to close
** highest -- last fd + 1 to close
**
** Returns:
** none
*/
void
sm_closefrom(lowest, highest)
int lowest, highest;
{
#if HASCLOSEFROM
closefrom(lowest);
#else /* HASCLOSEFROM */
int i;
for (i = lowest; i < highest; i++)
(void) close(i);
#endif /* HASCLOSEFROM */
}
#if HASFDWALK
/*
** CLOSEFD_WALK -- walk fd's arranging to close them
** Callback for fdwalk()
**
** Parameters:
** lowest -- first fd to arrange to be closed
** fd -- fd to arrange to be closed
**
** Returns:
** zero
*/
static int
closefd_walk(lowest, fd)
void *lowest;
int fd;
{
if (fd >= *(int *)lowest)
(void) fcntl(fd, F_SETFD, FD_CLOEXEC);
return 0;
}
#endif /* HASFDWALK */
/*
** SM_CLOSE_ON_EXEC -- arrange for file descriptors to be closed
**
** Parameters:
** lowest -- first fd to arrange to be closed
** highest -- last fd + 1 to arrange to be closed
**
** Returns:
** none
*/
void
sm_close_on_exec(highest, lowest)
int highest, lowest;
{
#if HASFDWALK
(void) fdwalk(closefd_walk, &lowest);
#else /* HASFDWALK */
int i, j;
for (i = lowest; i < highest; i++)
{
if ((j = fcntl(i, F_GETFD, 0)) != -1)
(void) fcntl(i, F_SETFD, j | FD_CLOEXEC);
}
#endif /* HASFDWALK */
}
/*
** SEED_RANDOM -- seed the random number generator
**
** Parameters:
** none
**
** Returns:
** none
*/
void
seed_random()
{
#if HASSRANDOMDEV
srandomdev();
#else /* HASSRANDOMDEV */
long seed;
struct timeval t;
seed = (long) CurrentPid;
if (gettimeofday(&t, NULL) >= 0)
seed += t.tv_sec + t.tv_usec;
# if HASRANDOM
(void) srandom(seed);
# else /* HASRANDOM */
(void) srand((unsigned int) seed);
# endif /* HASRANDOM */
#endif /* HASSRANDOMDEV */
}
/*
** SM_SYSLOG -- syslog wrapper to keep messages under SYSLOG_BUFSIZE
**
** Parameters:
** level -- syslog level
** id -- envelope ID or NULL (NOQUEUE)
** fmt -- format string
** arg... -- arguments as implied by fmt.
**
** Returns:
** none
*/
/* VARARGS3 */
void
#ifdef __STDC__
sm_syslog(int level, const char *id, const char *fmt, ...)
#else /* __STDC__ */
sm_syslog(level, id, fmt, va_alist)
int level;
const char *id;
const char *fmt;
va_dcl
#endif /* __STDC__ */
{
char *buf;
size_t bufsize;
char *begin, *end;
int save_errno;
int seq = 1;
int idlen;
char buf0[MAXLINE];
char *newstring;
extern int SyslogPrefixLen;
SM_VA_LOCAL_DECL
save_errno = errno;
if (id == NULL)
id = "NOQUEUE";
idlen = strlen(id) + SyslogPrefixLen;
buf = buf0;
bufsize = sizeof(buf0);
for (;;)
{
int n;
/* print log message into buf */
SM_VA_START(ap, fmt);
n = sm_vsnprintf(buf, bufsize, fmt, ap);
SM_VA_END(ap);
SM_ASSERT(n > 0);
if (n < bufsize)
break;
/* String too small, redo with correct size */
bufsize = n + 1;
if (buf != buf0)
{
sm_free(buf);
buf = NULL;
}
buf = sm_malloc_x(bufsize);
}
/* clean up buf after it has been expanded with args */
newstring = str2prt(buf);
if ((strlen(newstring) + idlen + 1) < SYSLOG_BUFSIZE)
{
#if LOG
if (*id == '\0')
{
if (tTd(89, 8))
sm_dprintf("%s\n", newstring);
else
syslog(level, "%s", newstring);
}
else
{
if (tTd(89, 8))
sm_dprintf("%s: %s\n", id, newstring);
else
syslog(level, "%s: %s", id, newstring);
}
#else /* LOG */
/*XXX should do something more sensible */
if (*id == '\0')
(void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT, "%s\n",
newstring);
else
(void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
"%s: %s\n", id, newstring);
#endif /* LOG */
if (buf != buf0)
sm_free(buf);
errno = save_errno;
return;
}
/*
** additional length for splitting: " ..." + 3, where 3 is magic to
** have some data for the next entry.
*/
#define SL_SPLIT 7
begin = newstring;
idlen += 5; /* strlen("[999]"), see below */
while (*begin != '\0' &&
(strlen(begin) + idlen) > SYSLOG_BUFSIZE)
{
char save;
if (seq >= 999)
{
/* Too many messages */
break;
}
end = begin + SYSLOG_BUFSIZE - idlen - SL_SPLIT;
while (end > begin)
{
/* Break on comma or space */
if (*end == ',' || *end == ' ')
{
end++; /* Include separator */
break;
}
end--;
}
/* No separator, break midstring... */
if (end == begin)
end = begin + SYSLOG_BUFSIZE - idlen - SL_SPLIT;
save = *end;
*end = 0;
#if LOG
if (tTd(89, 8))
sm_dprintf("%s[%d]: %s ...\n", id, seq++, begin);
else
syslog(level, "%s[%d]: %s ...", id, seq++, begin);
#else /* LOG */
(void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
"%s[%d]: %s ...\n", id, seq++, begin);
#endif /* LOG */
*end = save;
begin = end;
}
if (seq >= 999)
{
#if LOG
if (tTd(89, 8))
sm_dprintf("%s[%d]: log terminated, too many parts\n",
id, seq);
else
syslog(level, "%s[%d]: log terminated, too many parts",
id, seq);
#else /* LOG */
(void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
"%s[%d]: log terminated, too many parts\n", id, seq);
#endif /* LOG */
}
else if (*begin != '\0')
{
#if LOG
if (tTd(89, 8))
sm_dprintf("%s[%d]: %s\n", id, seq, begin);
else
syslog(level, "%s[%d]: %s", id, seq, begin);
#else /* LOG */
(void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
"%s[%d]: %s\n", id, seq, begin);
#endif /* LOG */
}
if (buf != buf0)
sm_free(buf);
errno = save_errno;
}
/*
** HARD_SYSLOG -- call syslog repeatedly until it works
**
** Needed on HP-UX, which apparently doesn't guarantee that
** syslog succeeds during interrupt handlers.
*/
#if defined(__hpux) && !defined(HPUX11)
# define MAXSYSLOGTRIES 100
# undef syslog
# ifdef V4FS
# define XCNST const
# define CAST (const char *)
# else /* V4FS */
# define XCNST
# define CAST
# endif /* V4FS */
void
# ifdef __STDC__
hard_syslog(int pri, XCNST char *msg, ...)
# else /* __STDC__ */
hard_syslog(pri, msg, va_alist)
int pri;
XCNST char *msg;
va_dcl
# endif /* __STDC__ */
{
int i;
char buf[SYSLOG_BUFSIZE];
SM_VA_LOCAL_DECL
SM_VA_START(ap, msg);
(void) sm_vsnprintf(buf, sizeof(buf), msg, ap);
SM_VA_END(ap);
for (i = MAXSYSLOGTRIES; --i >= 0 && syslog(pri, CAST "%s", buf) < 0; )
continue;
}
# undef CAST
#endif /* defined(__hpux) && !defined(HPUX11) */
#if NEEDLOCAL_HOSTNAME_LENGTH
/*
** LOCAL_HOSTNAME_LENGTH
**
** This is required to get sendmail to compile against BIND 4.9.x
** on Ultrix.
**
** Unfortunately, a Compaq Y2K patch kit provides it without
** bumping __RES in /usr/include/resolv.h so we can't automatically
** figure out whether it is needed.
*/
int
local_hostname_length(hostname)
char *hostname;
{
size_t len_host, len_domain;
if (!*_res.defdname)
res_init();
len_host = strlen(hostname);
len_domain = strlen(_res.defdname);
if (len_host > len_domain &&
(sm_strcasecmp(hostname + len_host - len_domain,
_res.defdname) == 0) &&
hostname[len_host - len_domain - 1] == '.')
return len_host - len_domain - 1;
else
return 0;
}
#endif /* NEEDLOCAL_HOSTNAME_LENGTH */
#if NEEDLINK
/*
** LINK -- clone a file
**
** Some OS's lacks link() and hard links. Since sendmail is using
** link() as an efficient way to clone files, this implementation
** will simply do a file copy.
**
** NOTE: This link() replacement is not a generic replacement as it
** does not handle all of the semantics of the real link(2).
**
** Parameters:
** source -- pathname of existing file.
** target -- pathname of link (clone) to be created.
**
** Returns:
** 0 -- success.
** -1 -- failure, see errno for details.
*/
int
link(source, target)
const char *source;
const char *target;
{
int save_errno;
int sff;
int src = -1, dst = -1;
ssize_t readlen;
ssize_t writelen;
char buf[BUFSIZ];
struct stat st;
sff = SFF_REGONLY|SFF_OPENASROOT;
if (DontLockReadFiles)
sff |= SFF_NOLOCK;
/* Open the original file */
src = safeopen((char *)source, O_RDONLY, 0, sff);
if (src < 0)
goto fail;
/* Obtain the size and the mode */
if (fstat(src, &st) < 0)
goto fail;
/* Create the duplicate copy */
sff &= ~SFF_NOLOCK;
sff |= SFF_CREAT;
dst = safeopen((char *)target, O_CREAT|O_EXCL|O_WRONLY,
st.st_mode, sff);
if (dst < 0)
goto fail;
/* Copy all of the bytes one buffer at a time */
while ((readlen = read(src, &buf, sizeof(buf))) > 0)
{
ssize_t left = readlen;
char *p = buf;
while (left > 0 &&
(writelen = write(dst, p, (size_t) left)) >= 0)
{
left -= writelen;
p += writelen;
}
if (writelen < 0)
break;
}
/* Any trouble reading? */
if (readlen < 0 || writelen < 0)
goto fail;
/* Close the input file */
if (close(src) < 0)
{
src = -1;
goto fail;
}
src = -1;
/* Close the output file */
if (close(dst) < 0)
{
/* don't set dst = -1 here so we unlink the file */
goto fail;
}
/* Success */
return 0;
fail:
save_errno = errno;
if (src >= 0)
(void) close(src);
if (dst >= 0)
{
(void) unlink(target);
(void) close(dst);
}
errno = save_errno;
return -1;
}
#endif /* NEEDLINK */
/*
** Compile-Time options
*/
char *CompileOptions[] =
{
#if ALLOW_255
"ALLOW_255",
#endif /* ALLOW_255 */
#if NAMED_BIND
# if DNSMAP
"DNSMAP",
# endif /* DNSMAP */
#endif /* NAMED_BIND */
#if EGD
"EGD",
#endif /* EGD */
#if HESIOD
"HESIOD",
#endif /* HESIOD */
#if HES_GETMAILHOST
"HES_GETMAILHOST",
#endif /* HES_GETMAILHOST */
#if LDAPMAP
"LDAPMAP",
#endif /* LDAPMAP */
#if LDAP_REFERRALS
"LDAP_REFERRALS",
#endif /* LDAP_REFERRALS */
#if LOG
"LOG",
#endif /* LOG */
#if MAP_NSD
"MAP_NSD",
#endif /* MAP_NSD */
#if MAP_REGEX
"MAP_REGEX",
#endif /* MAP_REGEX */
#if MATCHGECOS
"MATCHGECOS",
#endif /* MATCHGECOS */
#if MILTER
"MILTER",
#endif /* MILTER */
#if MIME7TO8
"MIME7TO8",
#endif /* MIME7TO8 */
#if MIME7TO8_OLD
"MIME7TO8_OLD",
#endif /* MIME7TO8_OLD */
#if MIME8TO7
"MIME8TO7",
#endif /* MIME8TO7 */
#if NAMED_BIND
"NAMED_BIND",
#endif /* NAMED_BIND */
#if NDBM
"NDBM",
#endif /* NDBM */
#if NETINET
"NETINET",
#endif /* NETINET */
#if NETINET6
"NETINET6",
#endif /* NETINET6 */
#if NETINFO
"NETINFO",
#endif /* NETINFO */
#if NETISO
"NETISO",
#endif /* NETISO */
#if NETNS
"NETNS",
#endif /* NETNS */
#if NETUNIX
"NETUNIX",
#endif /* NETUNIX */
#if NETX25
"NETX25",
#endif /* NETX25 */
#if NEWDB
"NEWDB",
#endif /* NEWDB */
#if NIS
"NIS",
#endif /* NIS */
#if NISPLUS
"NISPLUS",
#endif /* NISPLUS */
#if NO_DH
"NO_DH",
#endif /* NO_DH */
#if PH_MAP
"PH_MAP",
#endif /* PH_MAP */
#ifdef PICKY_HELO_CHECK
"PICKY_HELO_CHECK",
#endif /* PICKY_HELO_CHECK */
#if PIPELINING
"PIPELINING",
#endif /* PIPELINING */
#if SASL
# if SASL >= 20000
"SASLv2",
# else /* SASL >= 20000 */
"SASL",
# endif /* SASL >= 20000 */
#endif /* SASL */
#if SCANF
"SCANF",
#endif /* SCANF */
#if SM_LDAP_ERROR_ON_MISSING_ARGS
"SM_LDAP_ERROR_ON_MISSING_ARGS",
#endif /* SM_LDAP_ERROR_ON_MISSING_ARGS */
#if SMTPDEBUG
"SMTPDEBUG",
#endif /* SMTPDEBUG */
#if SOCKETMAP
"SOCKETMAP",
#endif /* SOCKETMAP */
#if STARTTLS
"STARTTLS",
#endif /* STARTTLS */
#if SUID_ROOT_FILES_OK
"SUID_ROOT_FILES_OK",
#endif /* SUID_ROOT_FILES_OK */
#if TCPWRAPPERS
"TCPWRAPPERS",
#endif /* TCPWRAPPERS */
#if TLS_NO_RSA
"TLS_NO_RSA",
#endif /* TLS_NO_RSA */
#if TLS_VRFY_PER_CTX
"TLS_VRFY_PER_CTX",
#endif /* TLS_VRFY_PER_CTX */
#if USERDB
"USERDB",
#endif /* USERDB */
#if USE_LDAP_INIT
"USE_LDAP_INIT",
#endif /* USE_LDAP_INIT */
#if USE_TTYPATH
"USE_TTYPATH",
#endif /* USE_TTYPATH */
#if XDEBUG
"XDEBUG",
#endif /* XDEBUG */
#if XLA
"XLA",
#endif /* XLA */
NULL
};
/*
** OS compile options.
*/
char *OsCompileOptions[] =
{
#if ADDRCONFIG_IS_BROKEN
"ADDRCONFIG_IS_BROKEN",
#endif /* ADDRCONFIG_IS_BROKEN */
#ifdef AUTO_NETINFO_HOSTS
"AUTO_NETINFO_HOSTS",
#endif /* AUTO_NETINFO_HOSTS */
#ifdef AUTO_NIS_ALIASES
"AUTO_NIS_ALIASES",
#endif /* AUTO_NIS_ALIASES */
#if BROKEN_RES_SEARCH
"BROKEN_RES_SEARCH",
#endif /* BROKEN_RES_SEARCH */
#ifdef BSD4_4_SOCKADDR
"BSD4_4_SOCKADDR",
#endif /* BSD4_4_SOCKADDR */
#if BOGUS_O_EXCL
"BOGUS_O_EXCL",
#endif /* BOGUS_O_EXCL */
#if DEC_OSF_BROKEN_GETPWENT
"DEC_OSF_BROKEN_GETPWENT",
#endif /* DEC_OSF_BROKEN_GETPWENT */
#if FAST_PID_RECYCLE
"FAST_PID_RECYCLE",
#endif /* FAST_PID_RECYCLE */
#if HASCLOSEFROM
"HASCLOSEFROM",
#endif /* HASCLOSEFROM */
#if HASFCHOWN
"HASFCHOWN",
#endif /* HASFCHOWN */
#if HASFCHMOD
"HASFCHMOD",
#endif /* HASFCHMOD */
#if HASFDWALK
"HASFDWALK",
#endif /* HASFDWALK */
#if HASFLOCK
"HASFLOCK",
#endif /* HASFLOCK */
#if HASGETDTABLESIZE
"HASGETDTABLESIZE",
#endif /* HASGETDTABLESIZE */
#if HASGETUSERSHELL
"HASGETUSERSHELL",
#endif /* HASGETUSERSHELL */
#if HASINITGROUPS
"HASINITGROUPS",
#endif /* HASINITGROUPS */
#if HASLDAPGETALIASBYNAME
"HASLDAPGETALIASBYNAME",
#endif /* HASLDAPGETALIASBYNAME */
#if HASLSTAT
"HASLSTAT",
#endif /* HASLSTAT */
#if HASNICE
"HASNICE",
#endif /* HASNICE */
#if HASRANDOM
"HASRANDOM",
#endif /* HASRANDOM */
#if HASRRESVPORT
"HASRRESVPORT",
#endif /* HASRRESVPORT */
#if HASSETEGID
"HASSETEGID",
#endif /* HASSETEGID */
#if HASSETLOGIN
"HASSETLOGIN",
#endif /* HASSETLOGIN */
#if HASSETREGID
"HASSETREGID",
#endif /* HASSETREGID */
#if HASSETRESGID
"HASSETRESGID",
#endif /* HASSETRESGID */
#if HASSETREUID
"HASSETREUID",
#endif /* HASSETREUID */
#if HASSETRLIMIT
"HASSETRLIMIT",
#endif /* HASSETRLIMIT */
#if HASSETSID
"HASSETSID",
#endif /* HASSETSID */
#if HASSETUSERCONTEXT
"HASSETUSERCONTEXT",
#endif /* HASSETUSERCONTEXT */
#if HASSETVBUF
"HASSETVBUF",
#endif /* HASSETVBUF */
#if HAS_ST_GEN
"HAS_ST_GEN",
#endif /* HAS_ST_GEN */
#if HASSRANDOMDEV
"HASSRANDOMDEV",
#endif /* HASSRANDOMDEV */
#if HASURANDOMDEV
"HASURANDOMDEV",
#endif /* HASURANDOMDEV */
#if HASSTRERROR
"HASSTRERROR",
#endif /* HASSTRERROR */
#if HASULIMIT
"HASULIMIT",
#endif /* HASULIMIT */
#if HASUNAME
"HASUNAME",
#endif /* HASUNAME */
#if HASUNSETENV
"HASUNSETENV",
#endif /* HASUNSETENV */
#if HASWAITPID
"HASWAITPID",
#endif /* HASWAITPID */
#if IDENTPROTO
"IDENTPROTO",
#endif /* IDENTPROTO */
#if IP_SRCROUTE
"IP_SRCROUTE",
#endif /* IP_SRCROUTE */
#if O_EXLOCK && HASFLOCK && !BOGUS_O_EXCL
"LOCK_ON_OPEN",
#endif /* O_EXLOCK && HASFLOCK && !BOGUS_O_EXCL */
#if MILTER_NO_NAGLE
"MILTER_NO_NAGLE ",
#endif /* MILTER_NO_NAGLE */
#if NEEDFSYNC
"NEEDFSYNC",
#endif /* NEEDFSYNC */
#if NEEDLINK
"NEEDLINK",
#endif /* NEEDLINK */
#if NEEDLOCAL_HOSTNAME_LENGTH
"NEEDLOCAL_HOSTNAME_LENGTH",
#endif /* NEEDLOCAL_HOSTNAME_LENGTH */
#if NEEDSGETIPNODE
"NEEDSGETIPNODE",
#endif /* NEEDSGETIPNODE */
#if NEEDSTRSTR
"NEEDSTRSTR",
#endif /* NEEDSTRSTR */
#if NEEDSTRTOL
"NEEDSTRTOL",
#endif /* NEEDSTRTOL */
#ifdef NO_GETSERVBYNAME
"NO_GETSERVBYNAME",
#endif /* NO_GETSERVBYNAME */
#if NOFTRUNCATE
"NOFTRUNCATE",
#endif /* NOFTRUNCATE */
#if REQUIRES_DIR_FSYNC
"REQUIRES_DIR_FSYNC",
#endif /* REQUIRES_DIR_FSYNC */
#if RLIMIT_NEEDS_SYS_TIME_H
"RLIMIT_NEEDS_SYS_TIME_H",
#endif /* RLIMIT_NEEDS_SYS_TIME_H */
#if SAFENFSPATHCONF
"SAFENFSPATHCONF",
#endif /* SAFENFSPATHCONF */
#if SECUREWARE
"SECUREWARE",
#endif /* SECUREWARE */
#if SHARE_V1
"SHARE_V1",
#endif /* SHARE_V1 */
#if SIOCGIFCONF_IS_BROKEN
"SIOCGIFCONF_IS_BROKEN",
#endif /* SIOCGIFCONF_IS_BROKEN */
#if SIOCGIFNUM_IS_BROKEN
"SIOCGIFNUM_IS_BROKEN",
#endif /* SIOCGIFNUM_IS_BROKEN */
#if SNPRINTF_IS_BROKEN
"SNPRINTF_IS_BROKEN",
#endif /* SNPRINTF_IS_BROKEN */
#if SO_REUSEADDR_IS_BROKEN
"SO_REUSEADDR_IS_BROKEN",
#endif /* SO_REUSEADDR_IS_BROKEN */
#if SYS5SETPGRP
"SYS5SETPGRP",
#endif /* SYS5SETPGRP */
#if SYSTEM5
"SYSTEM5",
#endif /* SYSTEM5 */
#if USE_DOUBLE_FORK
"USE_DOUBLE_FORK",
#endif /* USE_DOUBLE_FORK */
#if USE_ENVIRON
"USE_ENVIRON",
#endif /* USE_ENVIRON */
#if USE_SA_SIGACTION
"USE_SA_SIGACTION",
#endif /* USE_SA_SIGACTION */
#if USE_SIGLONGJMP
"USE_SIGLONGJMP",
#endif /* USE_SIGLONGJMP */
#if USEGETCONFATTR
"USEGETCONFATTR",
#endif /* USEGETCONFATTR */
#if USESETEUID
"USESETEUID",
#endif /* USESETEUID */
#ifdef USESYSCTL
"USESYSCTL",
#endif /* USESYSCTL */
#if USING_NETSCAPE_LDAP
"USING_NETSCAPE_LDAP",
#endif /* USING_NETSCAPE_LDAP */
#ifdef WAITUNION
"WAITUNION",
#endif /* WAITUNION */
NULL
};
/*
** FFR compile options.
*/
char *FFRCompileOptions[] =
{
#if _FFR_ADDR_TYPE_MODES
/* more info in {addr_type}, requires m4 changes! */
"_FFR_ADDR_TYPE_MODES",
#endif /* _FFR_ADDR_TYPE_MODES */
#if _FFR_ALLOW_SASLINFO
/* DefaultAuthInfo can be specified by user. */
/* DefaultAuthInfo doesn't really work in 8.13 anymore. */
"_FFR_ALLOW_SASLINFO",
#endif /* _FFR_ALLOW_SASLINFO */
#if _FFR_BADRCPT_SHUTDOWN
/* shut down connection (421) if there are too many bad RCPTs */
"_FFR_BADRCPT_SHUTDOWN",
#endif /* _FFR_BADRCPT_SHUTDOWN */
#if _FFR_BESTMX_BETTER_TRUNCATION
/* Better truncation of list of MX records for dns map. */
"_FFR_BESTMX_BETTER_TRUNCATION",
#endif /* _FFR_BESTMX_BETTER_TRUNCATION */
#if _FFR_CATCH_BROKEN_MTAS
/* Deal with MTAs that send a reply during the DATA phase. */
"_FFR_CATCH_BROKEN_MTAS",
#endif /* _FFR_CATCH_BROKEN_MTAS */
#if _FFR_CHECKCONFIG
/* New OpMode to check the configuration file */
"_FFR_CHECKCONFIG",
#endif /* _FFR_CHECKCONFIG */
#if _FFR_CHK_QUEUE
/* Stricter checks about queue directory permissions. */
"_FFR_CHK_QUEUE",
#endif /* _FFR_CHK_QUEUE */
#if _FFR_CLIENT_SIZE
/* Don't try to send mail if its size exceeds SIZE= of server. */
"_FFR_CLIENT_SIZE",
#endif /* _FFR_CLIENT_SIZE */
#if _FFR_CRLPATH
/* CRLPath; needs documentation; Al Smith */
"_FFR_CRLPATH",
#endif /* _FFR_CRLPATH */
#if _FFR_DAEMON_NETUNIX
/* Allow local (not just TCP) socket connection to server. */
"_FFR_DAEMON_NETUNIX",
#endif /* _FFR_DAEMON_NETUNIX */
#if _FFR_DEPRECATE_MAILER_FLAG_I
/* What it says :-) */
"_FFR_DEPRECATE_MAILER_FLAG_I",
#endif /* _FFR_DEPRECATE_MAILER_FLAG_I */
#if _FFR_DM_ONE
/* deliver first TA in background, then queue */
"_FFR_DM_ONE",
#endif /* _FFR_DM_ONE */
#if _FFR_DIGUNIX_SAFECHOWN
/* Properly set SAFECHOWN (include/sm/conf.h) for Digital UNIX */
/* Problem noted by Anne Bennett of Concordia University */
"_FFR_DIGUNIX_SAFECHOWN",
#endif /* _FFR_DIGUNIX_SAFECHOWN */
#if _FFR_DNSMAP_ALIASABLE
/* Allow dns map type to be used for aliases. */
/* Don Lewis of TDK */
"_FFR_DNSMAP_ALIASABLE",
#endif /* _FFR_DNSMAP_ALIASABLE */
#if _FFR_DONTLOCKFILESFORREAD_OPTION
/* Enable DontLockFilesForRead option. */
"_FFR_DONTLOCKFILESFORREAD_OPTION",
#endif /* _FFR_DONTLOCKFILESFORREAD_OPTION */
#if _FFR_DOTTED_USERNAMES
/* Allow usernames with '.' */
"_FFR_DOTTED_USERNAMES",
#endif /* _FFR_DOTTED_USERNAMES */
#if _FFR_DPO_CS
/*
** Make DaemonPortOptions case sensitive.
** For some unknown reasons the code converted every option
** to uppercase (first letter only, as that's the only one that
** is actually checked). This prevented all new lower case options
** from working...
** The documentation doesn't say anything about case (in)sensitivity,
** which means it should be case sensitive by default,
** but it's not a good idea to change this within a patch release,
** so let's delay this to 8.15.
*/
"_FFR_DPO_CS",
#endif /* _FFR_DPO_CS */
#if _FFR_DPRINTF_MAP
/* dprintf map for logging */
"_FFR_DPRINTF_MAP",
#endif /* _FFR_DPRINTF_MAP */
#if _FFR_DROP_TRUSTUSER_WARNING
/*
** Don't issue this warning:
** "readcf: option TrustedUser may cause problems on systems
** which do not support fchown() if UseMSP is not set.
*/
"_FFR_DROP_TRUSTUSER_WARNING",
#endif /* _FFR_DROP_TRUSTUSER_WARNING */
#if _FFR_EIGHT_BIT_ADDR_OK
/* EightBitAddrOK: allow 8-bit e-mail addresses */
"_FFR_EIGHT_BIT_ADDR_OK",
#endif /* _FFR_EIGHT_BIT_ADDR_OK */
#if _FFR_EXPDELAY
/* exponential queue delay */
"_FFR_EXPDELAY",
#endif /* _FFR_EXPDELAY */
#if _FFR_EXTRA_MAP_CHECK
/* perform extra checks on $( $) in R lines */
"_FFR_EXTRA_MAP_CHECK",
#endif /* _FFR_EXTRA_MAP_CHECK */
#if _FFR_GETHBN_ExFILE
/*
** According to Motonori Nakamura some gethostbyname()
** implementations (TurboLinux?) may (temporarily) fail
** due to a lack of file discriptors. Enabling this FFR
** will check errno for EMFILE and ENFILE and in case of a match
** cause a temporary error instead of a permanent error.
** The right solution is of course to file a bug against those
** systems such that they actually set h_errno = TRY_AGAIN.
*/
"_FFR_GETHBN_ExFILE",
#endif /* _FFR_GETHBN_ExFILE */
#if _FFR_FIX_DASHT
/*
** If using -t, force not sending to argv recipients, even
** if they are mentioned in the headers.
*/
"_FFR_FIX_DASHT",
#endif /* _FFR_FIX_DASHT */
#if _FFR_FORWARD_SYSERR
/* Cause a "syserr" if forward file isn't "safe". */
"_FFR_FORWARD_SYSERR",
#endif /* _FFR_FORWARD_SYSERR */
#if _FFR_GEN_ORCPT
/* Generate a ORCPT DSN arg if not already provided */
"_FFR_GEN_ORCPT",
#endif /* _FFR_GEN_ORCPT */
#if _FFR_GROUPREADABLEAUTHINFOFILE
/* Allow group readable DefaultAuthInfo file. */
"_FFR_GROUPREADABLEAUTHINFOFILE",
#endif /* _FFR_GROUPREADABLEAUTHINFOFILE */
#if _FFR_HANDLE_ISO8859_GECOS
/*
** Allow ISO 8859 characters in GECOS field: replace them
** ith ASCII "equivalent".
*/
/* Peter Eriksson of Linkopings universitet */
"_FFR_HANDLE_ISO8859_GECOS",
#endif /* _FFR_HANDLE_ISO8859_GECOS */
#if _FFR_HPUX_NSSWITCH
/* Use nsswitch on HP-UX */
"_FFR_HPUX_NSSWITCH",
#endif /* _FFR_HPUX_NSSWITCH */
#if _FFR_IGNORE_BOGUS_ADDR
/* Ignore addresses for which prescan() failed */
"_FFR_IGNORE_BOGUS_ADDR",
#endif /* _FFR_IGNORE_BOGUS_ADDR */
#if _FFR_IGNORE_EXT_ON_HELO
/* Ignore extensions offered in response to HELO */
"_FFR_IGNORE_EXT_ON_HELO",
#endif /* _FFR_IGNORE_EXT_ON_HELO */
#if _FFR_LINUX_MHNL
/* Set MAXHOSTNAMELEN to 256 (Linux) */
"_FFR_LINUX_MHNL",
#endif /* _FFR_LINUX_MHNL */
#if _FFR_LOCAL_DAEMON
/* Local daemon mode (-bl) which only accepts loopback connections */
"_FFR_LOCAL_DAEMON",
#endif /* _FFR_LOCAL_DAEMON */
#if _FFR_MAIL_MACRO
"_FFR_MAIL_MACRO",
#endif /* _FFR_MAIL_MACRO */
#if _FFR_MAXDATASIZE
/*
** It is possible that a header is larger than MILTER_CHUNK_SIZE,
** hence this shouldn't be used as limit for milter communication.
** see also libmilter/comm.c
** Gurusamy Sarathy of ActiveState
*/
"_FFR_MAXDATASIZE",
#endif /* _FFR_MAXDATASIZE */
#if _FFR_MAX_FORWARD_ENTRIES
/* Try to limit number of .forward entries */
/* (doesn't work) */
/* Randall S. Winchester of the University of Maryland */
"_FFR_MAX_FORWARD_ENTRIES",
#endif /* _FFR_MAX_FORWARD_ENTRIES */
#if _FFR_MAX_SLEEP_TIME
/* Limit sleep(2) time in libsm/clock.c */
"_FFR_MAX_SLEEP_TIME",
#endif /* _FFR_MAX_SLEEP_TIME */
#if _FFR_MDS_NEGOTIATE
/* MaxDataSize negotation with libmilter */
"_FFR_MDS_NEGOTIATE",
#endif /* _FFR_MDS_NEGOTIATE */
#if _FFR_MEMSTAT
/* Check free memory */
"_FFR_MEMSTAT",
#endif /* _FFR_MEMSTAT */
#if _FFR_MILTER_CHECK
"_FFR_MILTER_CHECK",
#endif /* _FFR_MILTER_CHECK */
#if _FFR_MILTER_CONVERT_ALL_LF_TO_CRLF
/*
** milter_body() uses the same conversion algorithm as putbody()
** to translate the "local" df format (\n) to SMTP format (\r\n).
** However, putbody() and mime8to7() use different conversion
** algorithms.
** If the input date does not follow the SMTP standard
** (e.g., if it has "naked \r"s), then the output from putbody()
** and mime8to7() will most likely be different.
** By turning on this FFR milter_body() will try to "imitate"
** mime8to7().
** Note: there is no (simple) way to deal with both conversions
** in a consistent manner. Moreover, as the "GiGo" principle applies,
** it's not really worth to fix it.
*/
"_FFR_MILTER_CONVERT_ALL_LF_TO_CRLF",
#endif /* _FFR_MILTER_CONVERT_ALL_LF_TO_CRLF */
#if _FFR_MILTER_CHECK_REJECTIONS_TOO
/*
** Also send RCPTs that are rejected by check_rcpt to a milter
** (if requested during option negotiation).
*/
"_FFR_MILTER_CHECK_REJECTIONS_TOO",
#endif /* _FFR_MILTER_CHECK_REJECTIONS_TOO */
#if _FFR_MILTER_ENHSC
/* extract enhanced status code from milter replies for dsn= logging */
"_FFR_MILTER_ENHSC",
#endif /* _FFR_MILTER_ENHSC */
#if _FFR_MIME7TO8_OLD
/* Old mime7to8 code, the new is broken for at least one example. */
"_FFR_MIME7TO8_OLD",
#endif /* _FFR_MAX_SLEEP_TIME */
#if _FFR_MORE_MACROS
/* allow more long macro names ("unprintable" characters). */
"_FFR_MORE_MACROS",
#endif /* _FFR_MORE_MACROS */
#if _FFR_MSG_ACCEPT
/* allow to override "Message accepted for delivery" */
"_FFR_MSG_ACCEPT",
#endif /* _FFR_MSG_ACCEPT */
#if _FFR_NODELAYDSN_ON_HOLD
/* Do not issue a DELAY DSN for mailers that use the hold flag. */
/* Steven Pitzl */
"_FFR_NODELAYDSN_ON_HOLD",
#endif /* _FFR_NODELAYDSN_ON_HOLD */
#if _FFR_NO_PIPE
/* Disable PIPELINING, delay client if used. */
"_FFR_NO_PIPE",
#endif /* _FFR_NO_PIPE */
#if _FFR_LDAP_NETWORK_TIMEOUT
/* set LDAP_OPT_NETWORK_TIMEOUT if available (-c) */
"_FFR_LDAP_NETWORK_TIMEOUT",
#endif /* _FFR_LDAP_NETWORK_TIMEOUT */
#if _FFR_LOG_NTRIES
/* log ntries=, from Nik Clayton of FreeBSD */
"_FFR_LOG_NTRIES",
#endif /* _FFR_LOG_NTRIES */
#if _FFR_QF_PARANOIA
"_FFR_QF_PARANOIA",
#endif /* _FFR_QF_PARANOIA */
#if _FFR_QUEUEDELAY
/* Exponential queue delay; disabled in 8.13 since it isn't used. */
"_FFR_QUEUEDELAY",
#endif /* _FFR_QUEUEDELAY */
#if _FFR_QUEUE_GROUP_SORTORDER
/* Allow QueueSortOrder per queue group. */
/* XXX: Still need to actually use qgrp->qg_sortorder */
"_FFR_QUEUE_GROUP_SORTORDER",
#endif /* _FFR_QUEUE_GROUP_SORTORDER */
#if _FFR_QUEUE_MACRO
/* Define {queue} macro. */
"_FFR_QUEUE_MACRO",
#endif /* _FFR_QUEUE_MACRO */
#if _FFR_QUEUE_RUN_PARANOIA
/* Additional checks when doing queue runs; interval of checks */
"_FFR_QUEUE_RUN_PARANOIA",
#endif /* _FFR_QUEUE_RUN_PARANOIA */
#if _FFR_QUEUE_SCHED_DBG
/* Debug output for the queue scheduler. */
"_FFR_QUEUE_SCHED_DBG",
#endif /* _FFR_QUEUE_SCHED_DBG */
#if _FFR_RCPTTHROTDELAY
/* configurable delay for BadRcptThrottle */
"_FFR_RCPTTHROTDELAY"
#endif /* _FFR_RCPTTHROTDELAY */
#if _FFR_REDIRECTEMPTY
/*
** envelope <> can't be sent to mailing lists, only owner-
** send spam of this type to owner- of the list
** ---- to stop spam from going to mailing lists.
*/
"_FFR_REDIRECTEMPTY",
#endif /* _FFR_REDIRECTEMPTY */
#if _FFR_RESET_MACRO_GLOBALS
/* Allow macro 'j' to be set dynamically via rulesets. */
"_FFR_RESET_MACRO_GLOBALS",
#endif /* _FFR_RESET_MACRO_GLOBALS */
#if _FFR_RHS
/* Random shuffle for queue sorting. */
"_FFR_RHS",
#endif /* _FFR_RHS */
#if _FFR_RUNPQG
/*
** allow -qGqueue_group -qp to work, i.e.,
** restrict a persistent queue runner to a queue group.
*/
"_FFR_RUNPQG",
#endif /* _FFR_RUNPQG */
#if _FFR_SESSID
/* session id (for logging) */
"_FFR_SESSID",
#endif /* _FFR_SESSID */
#if _FFR_SHM_STATUS
/* Donated code (unused). */
"_FFR_SHM_STATUS",
#endif /* _FFR_SHM_STATUS */
#if _FFR_LDAP_SINGLEDN
/*
** The LDAP database map code in Sendmail 8.12.10, when
** given the -1 switch, would match only a single DN,
** but was able to return multiple attributes for that
** DN. In Sendmail 8.13 this "bug" was corrected to
** only return if exactly one attribute matched.
**
** Unfortunately, our configuration uses the former
** behaviour. Attached is a relatively simple patch
** to 8.13.4 which adds a -2 switch (for lack of a
** better option) which returns the single dn/multiple
** attributes.
**
** Jeffrey T. Eaton, Carnegie-Mellon University
*/
"_FFR_LDAP_SINGLEDN",
#endif /* _FFR_LDAP_SINGLEDN */
#if _FFR_SKIP_DOMAINS
/* process every N'th domain instead of every N'th message */
"_FFR_SKIP_DOMAINS",
#endif /* _FFR_SKIP_DOMAINS */
#if _FFR_SLEEP_USE_SELECT
/* Use select(2) in libsm/clock.c to emulate sleep(2) */
"_FFR_SLEEP_USE_SELECT ",
#endif /* _FFR_SLEEP_USE_SELECT */
#if _FFR_SPT_ALIGN
/*
** It looks like the Compaq Tru64 5.1A now aligns argv and envp to 64
** bit alignment, so unless each piece of argv and envp is a multiple
** of 8 bytes (including terminating NULL), initsetproctitle() won't
** use any of the space beyond argv[0]. Be sure to set SPT_ALIGN_SIZE
** if you use this FFR.
*/
/* Chris Adams of HiWAAY Informations Services */
"_FFR_SPT_ALIGN",
#endif /* _FFR_SPT_ALIGN */
#if _FFR_SS_PER_DAEMON
/* SuperSafe per DaemonPortOptions: 'T' (better letter?) */
"_FFR_SS_PER_DAEMON",
#endif /* _FFR_SS_PER_DAEMON */
#if _FFR_TESTS
/* enable some test code */
"_FFR_TESTS",
#endif /* _FFR_TESTS */
#if _FFR_TIMERS
/* Donated code (unused). */
"_FFR_TIMERS",
#endif /* _FFR_TIMERS */
#if _FFR_TLS_1
/* More STARTTLS options, e.g., secondary certs. */
"_FFR_TLS_1",
#endif /* _FFR_TLS_1 */
#if _FFR_TRUSTED_QF
/*
** If we don't own the file mark it as unsafe.
** However, allow TrustedUser to own it as well
** in case TrustedUser manipulates the queue.
*/
"_FFR_TRUSTED_QF",
#endif /* _FFR_TRUSTED_QF */
#if _FFR_USE_SEM_LOCKING
"_FFR_USE_SEM_LOCKING",
#endif /* _FFR_USE_SEM_LOCKING */
#if _FFR_USE_SETLOGIN
/* Use setlogin() */
/* Peter Philipp */
"_FFR_USE_SETLOGIN",
#endif /* _FFR_USE_SETLOGIN */
NULL
};
|