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
|
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2006 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
include ../../Makefile.lib
# Hammerhead: amd64-only
SUBDIRS = $(MACH64)
all : TARGET= all
clean : TARGET= clean
clobber : TARGET= clobber
install : TARGET= install
LIBRARY= libkadm5clnt.a
POFILE= $(LIBRARY:%.a=%.po)
POFILES= generic.po
.KEEP_STATE:
all clean install: $(SUBDIRS)
clobber: $(SUBDIRS)
$(RM) $(CLOBBERFILES)
_msg: $(MSGDOMAIN) .WAIT $(POFILE)
$(RM) $(MSGDOMAIN)/$(POFILE)
$(CP) $(POFILE) $(MSGDOMAIN)
$(POFILE): $(DERIVED_FILES) .WAIT $(POFILES)
$(RM) $@
$(CAT) $(POFILES) > $@
generic.po: FRC
$(RM) messages.po
$(XGETTEXT) $(XGETFLAGS) `$(GREP) -l gettext ../*.[ch] *.[ch]`
$(SED) "/^domain/d" messages.po > $@
$(RM) messages.po
$(SUBDIRS): FRC
@cd $@; pwd; $(MAKE) $(TARGET)
FRC:
$(MSGDOMAIN):
$(INS.dir)
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
# Copyright (c) 2018, Joyent, Inc.
LIBRARY= libkadm5clnt.a
VERS= .1
CLNT_OBJS = clnt_policy.o \
client_rpc.o \
client_principal.o \
client_init.o \
clnt_privs.o \
clnt_chpass_util.o \
logger.o \
changepw.o \
chpw.o
SHARED_OBJS = \
alt_prof.o \
chpass_util.o \
kadm_rpc_xdr.o \
misc_free.o \
kadm_host_srv_names.o \
str_conv.o
OBJECTS= $(CLNT_OBJS) $(SHARED_OBJS)
ISRCHDR= ../iprop.h
KRB5IPROPDIR= $(SRC)/cmd/krb5/iprop
# include library definitions
include ../../../Makefile.lib
SRCS= $(CLNT_OBJS:%.o=../%.c) \
$(SHARED_OBJS:%.o=../../%.c)
LIBS= $(DYNLIB)
include $(SRC)/lib/gss_mechs/mech_krb5/Makefile.mech_krb5
POFILE = $(LIBRARY:%.a=%.po)
POFILES = generic.po
#override liblink
INS.liblink= -$(RM) $@; $(SYMLINK) $(LIBLINKS)$(VERS) $@
CPPFLAGS += -I.. -I../.. -I../../.. -I$(SRC)/lib/gss_mechs/mech_krb5/include \
-I$(SRC)/lib/krb5 \
-I$(SRC)/lib/gss_mechs/mech_krb5/include/krb5 \
-I$(SRC)/uts/common/gssapi/ \
-I$(SRC)/uts/common/gssapi/include/ \
-I$(SRC)/uts/common/gssapi/mechs/krb5/include \
-I$(SRC)/lib/gss_mechs/mech_krb5/krb5/os \
-I$(KRB5IPROPDIR) \
-DHAVE_STDLIB_H -DUSE_SOLARIS_SHARED_LIBRARIES \
-DHAVE_LIBSOCKET=1 -DHAVE_LIBNSL=1 -DSETRPCENT_TYPE=void \
-DENDRPCENT_TYPE=void -DHAVE_SYS_ERRLIST=1 -DNEED_SYS_ERRLIST=1 \
-DHAVE_SYSLOG_H=1 -DHAVE_OPENLOG=1 -DHAVE_SYSLOG=1 -DHAVE_CLOSELOG=1 \
-DHAVE_STRFTIME=1 -DHAVE_VSPRINTF=1 -DUSE_KADM5_API_VERSION=2
# Hammerhead: -I.. already in CPPFLAGS above; removed from CFLAGS (lost in Makefile.master.64 reset)
CFLAGS += $(CCVERBOSE)
CERRWARN += -Wno-unused-function
CERRWARN += -Wno-unused-variable
CERRWARN += -Wno-parentheses
CERRWARN += $(CNOWARN_UNINIT)
SMOFF += all_func_returns,indenting,no_if_block
LDLIBS += -lc
.KEEP_STATE:
all: $(LIBS)
# Hammerhead: pre-generated (rpcgen + GNU cpp truncation bug)
# iprop.h is now a committed source file.
# Hammerhead: GNU Make parallel builds need PICS to depend on generated files.
# $(LIBS): $(ISRCHDR) only ensures iprop.h before link, not before .o compilation.
$(PICS): $(ISRCHDR)
# Hammerhead: pre-generated files are permanent source, do not delete
# CLEANFILES += $(ISRCHDR)
# include library targets
include ../../../Makefile.targ
pics/%.o: ../../%.c
$(COMPILE.c) -o $@ $<
$(POST_PROCESS_O)
FRC:
generic.po: FRC
$(RM) messages.po
$(XGETTEXT) $(XGETFLAGS) `$(GREP) -l gettext ../*.[ch] ../../*.[ch]`
$(SED) "/^domain/d" messages.po > $@
$(RM) messages.po
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2006 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
# ident "%Z%%M% %I% %E% SMI"
#
include ../Makefile.com
include ../../../../Makefile.lib.64
DYNFLAGS += $(KRUNPATH64) $(KMECHLIB64)
LDLIBS += -L $(ROOTLIBDIR) -lgss -lnsl -lsocket -lc
install: all $(ROOTLIBS64) $(ROOTLINKS64)
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* lib/krb5/os/changepw.c
*
* Copyright 1990,1999 by the Massachusetts Institute of Technology.
* All Rights Reserved.
*
* Export of this software from the United States of America may
* require a specific license from the United States Government.
* It is the responsibility of any person or organization contemplating
* export to obtain such a license before exporting.
*
* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
* distribute this software and its documentation for any purpose and
* without fee is hereby granted, 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. Furthermore if you modify this software you must label
* your software as modified software and not distribute it in such a
* fashion that it might be confused with the original M.I.T. software.
* 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.
*
*/
#define NEED_SOCKETS
#include <k5-int.h>
#include <kadm5/admin.h>
#include <client_internal.h>
#include <gssapi/gssapi.h>
#include <gssapi_krb5.h>
#include <gssapiP_krb5.h>
#include <krb5.h>
/* #include "adm_err.h" */
#include <stdio.h>
#include <errno.h>
extern krb5_error_code krb5int_mk_chpw_req(krb5_context context,
krb5_auth_context auth_context,
krb5_data *ap_req, char *passwd,
krb5_data *packet);
extern krb5_error_code krb5int_rd_chpw_rep(krb5_context context,
krb5_auth_context auth_context,
krb5_data *packet, int *result_code,
krb5_data *result_data);
/*
* _kadm5_get_kpasswd_protocol
*
* returns the password change protocol value to the caller.
* Since the 'handle' is an opaque value to higher up callers,
* this method is needed to provide a way for them to get a peek
* at the protocol being used without having to expose the entire
* handle structure.
*/
krb5_chgpwd_prot
_kadm5_get_kpasswd_protocol(void *handle)
{
kadm5_server_handle_t srvrhdl = (kadm5_server_handle_t)handle;
return (srvrhdl->params.kpasswd_protocol);
}
/*
* krb5_change_password
*
* Prepare and send a CHANGEPW request to a password server
* using UDP datagrams. This is only used for sending to
* non-SEAM servers which support the Marc Horowitz defined
* protocol (1998) for password changing.
*
* SUNW14resync - added _local as it conflicts with one in krb5.h
*/
static krb5_error_code
krb5_change_password_local(context, params, creds, newpw, srvr_rsp_code,
srvr_msg)
krb5_context context;
kadm5_config_params *params;
krb5_creds *creds;
char *newpw;
kadm5_ret_t *srvr_rsp_code;
krb5_data *srvr_msg;
{
krb5_auth_context auth_context;
krb5_data ap_req, chpw_req, chpw_rep;
krb5_address local_kaddr, remote_kaddr;
krb5_error_code code = 0;
int i, addrlen;
struct sockaddr *addr_p, local_addr, remote_addr, tmp_addr;
struct sockaddr_in *sin_p;
struct hostent *hp;
int naddr_p;
int cc, local_result_code, tmp_len;
SOCKET s1 = INVALID_SOCKET;
SOCKET s2 = INVALID_SOCKET;
/* Initialize values so that cleanup call can safely check for NULL */
auth_context = NULL;
addr_p = NULL;
memset(&chpw_req, 0, sizeof (krb5_data));
memset(&chpw_rep, 0, sizeof (krb5_data));
memset(&ap_req, 0, sizeof (krb5_data));
/* initialize auth_context so that we know we have to free it */
if ((code = krb5_auth_con_init(context, &auth_context)))
goto cleanup;
if (code = krb5_mk_req_extended(context, &auth_context,
AP_OPTS_USE_SUBKEY,
NULL, creds, &ap_req))
goto cleanup;
/*
* find the address of the kpasswd_server.
*/
addr_p = (struct sockaddr *)malloc(sizeof (struct sockaddr));
if (!addr_p)
goto cleanup;
memset(addr_p, 0, sizeof (struct sockaddr));
if ((hp = gethostbyname(params->kpasswd_server)) == NULL) {
code = KRB5_REALM_CANT_RESOLVE;
goto cleanup;
}
sin_p = (struct sockaddr_in *)addr_p;
memset((char *)sin_p, 0, sizeof (struct sockaddr));
sin_p->sin_family = hp->h_addrtype;
sin_p->sin_port = htons(params->kpasswd_port);
memcpy((char *)&sin_p->sin_addr, (char *)hp->h_addr, hp->h_length);
naddr_p = 1;
/*
* this is really obscure. s1 is used for all communications. it
* is left unconnected in case the server is multihomed and routes
* are asymmetric. s2 is connected to resolve routes and get
* addresses. this is the *only* way to get proper addresses for
* multihomed hosts if routing is asymmetric.
*
* A related problem in the server, but not the client, is that
* many os's have no way to disconnect a connected udp socket, so
* the s2 socket needs to be closed and recreated for each
* request. The s1 socket must not be closed, or else queued
* requests will be lost.
*
* A "naive" client implementation (one socket, no connect,
* hostname resolution to get the local ip addr) will work and
* interoperate if the client is single-homed.
*/
if ((s1 = socket(AF_INET, SOCK_DGRAM, 0)) == INVALID_SOCKET)
{
code = errno;
goto cleanup;
}
if ((s2 = socket(AF_INET, SOCK_DGRAM, 0)) == INVALID_SOCKET)
{
code = errno;
goto cleanup;
}
for (i = 0; i < naddr_p; i++)
{
fd_set fdset;
struct timeval timeout;
if (connect(s2, &addr_p[i], sizeof (addr_p[i])) ==
SOCKET_ERROR)
{
if ((errno == ECONNREFUSED) ||
(errno == EHOSTUNREACH))
continue; /* try the next addr */
code = errno;
goto cleanup;
}
addrlen = sizeof (local_addr);
if (getsockname(s2, &local_addr, &addrlen) < 0)
{
if ((errno == ECONNREFUSED) ||
(errno == EHOSTUNREACH))
continue; /* try the next addr */
code = errno;
goto cleanup;
}
/*
* some brain-dead OS's don't return useful information from
* the getsockname call. Namely, windows and solaris.
*/
if (((struct sockaddr_in *)&local_addr)->sin_addr.s_addr != 0)
{
local_kaddr.addrtype = ADDRTYPE_INET;
local_kaddr.length = sizeof (((struct sockaddr_in *)
&local_addr)->sin_addr);
local_kaddr.contents = (krb5_octet *)
&(((struct sockaddr_in *)
&local_addr)->sin_addr);
}
else
{
krb5_address **addrs;
krb5_os_localaddr(context, &addrs);
local_kaddr.magic = addrs[0]->magic;
local_kaddr.addrtype = addrs[0]->addrtype;
local_kaddr.length = addrs[0]->length;
local_kaddr.contents = malloc(addrs[0]->length);
memcpy(local_kaddr.contents, addrs[0]->contents,
addrs[0]->length);
krb5_free_addresses(context, addrs);
}
addrlen = sizeof (remote_addr);
if (getpeername(s2, &remote_addr, &addrlen) < 0)
{
if ((errno == ECONNREFUSED) ||
(errno == EHOSTUNREACH))
continue; /* try the next addr */
code = errno;
goto cleanup;
}
remote_kaddr.addrtype = ADDRTYPE_INET;
remote_kaddr.length = sizeof (((struct sockaddr_in *)
&remote_addr)->sin_addr);
remote_kaddr.contents = (krb5_octet *)
&(((struct sockaddr_in *)&remote_addr)->sin_addr);
/*
* mk_priv requires that the local address be set.
* getsockname is used for this. rd_priv requires that the
* remote address be set. recvfrom is used for this. If
* rd_priv is given a local address, and the message has the
* recipient addr in it, this will be checked. However, there
* is simply no way to know ahead of time what address the
* message will be delivered *to*. Therefore, it is important
* that either no recipient address is in the messages when
* mk_priv is called, or that no local address is passed to
* rd_priv. Both is a better idea, and I have done that. In
* summary, when mk_priv is called, *only* a local address is
* specified. when rd_priv is called, *only* a remote address
* is specified. Are we having fun yet?
*/
if (code = krb5_auth_con_setaddrs(context, auth_context,
&local_kaddr, NULL))
{
code = errno;
goto cleanup;
}
if (code = krb5int_mk_chpw_req(context, auth_context,
&ap_req, newpw, &chpw_req))
{
code = errno;
goto cleanup;
}
if ((cc = sendto(s1, chpw_req.data, chpw_req.length, 0,
(struct sockaddr *)&addr_p[i],
sizeof (addr_p[i]))) != chpw_req.length)
{
if ((cc < 0) && ((errno == ECONNREFUSED) ||
(errno == EHOSTUNREACH)))
continue; /* try the next addr */
code = (cc < 0) ? errno : ECONNABORTED;
goto cleanup;
}
chpw_rep.length = 1500;
chpw_rep.data = (char *)malloc(chpw_rep.length);
/* XXX need a timeout/retry loop here */
FD_ZERO(&fdset);
FD_SET(s1, &fdset);
timeout.tv_sec = 120;
timeout.tv_usec = 0;
switch (select(s1 + 1, &fdset, 0, 0, &timeout)) {
case -1:
code = errno;
goto cleanup;
case 0:
code = ETIMEDOUT;
goto cleanup;
default:
/* fall through */
;
}
tmp_len = sizeof (tmp_addr);
if ((cc = recvfrom(s1, chpw_rep.data, chpw_rep.length,
0, &tmp_addr, &tmp_len)) < 0)
{
code = errno;
goto cleanup;
}
closesocket(s1);
s1 = INVALID_SOCKET;
closesocket(s2);
s2 = INVALID_SOCKET;
chpw_rep.length = cc;
if (code = krb5_auth_con_setaddrs(context, auth_context,
NULL, &remote_kaddr))
goto cleanup;
if (code = krb5int_rd_chpw_rep(context, auth_context, &chpw_rep,
&local_result_code, srvr_msg))
goto cleanup;
if (srvr_rsp_code)
*srvr_rsp_code = local_result_code;
code = 0;
goto cleanup;
}
code = errno;
cleanup:
if (auth_context != NULL)
krb5_auth_con_free(context, auth_context);
if (addr_p != NULL)
krb5_xfree(addr_p);
if (s1 != INVALID_SOCKET)
closesocket(s1);
if (s2 != INVALID_SOCKET)
closesocket(s2);
krb5_xfree(chpw_req.data);
krb5_xfree(chpw_rep.data);
krb5_xfree(ap_req.data);
return (code);
}
/*
* kadm5_chpass_principal_v2
*
* New function used to prepare to make the change password request to a
* non-SEAM admin server. The protocol used in this case is not based on
* RPCSEC_GSS, it simply makes the request to port 464 (udp and tcp).
* This is the same way that MIT KRB5 1.2.1 changes passwords.
*/
kadm5_ret_t
kadm5_chpass_principal_v2(void *server_handle,
krb5_principal princ,
char *newpw,
kadm5_ret_t *srvr_rsp_code,
krb5_data *srvr_msg)
{
kadm5_ret_t code;
kadm5_server_handle_t handle = (kadm5_server_handle_t)server_handle;
krb5_error_code result;
krb5_creds mcreds;
krb5_creds ncreds;
krb5_ccache ccache;
int cpwlen;
char *cpw_service = NULL;
/*
* The credentials have already been stored in the cache in the
* initialization step earlier, but we dont have direct access to it
* at this level. Derive the cache and fetch the credentials to use for
* sending the request.
*/
memset(&mcreds, 0, sizeof (krb5_creds));
if ((code = krb5_cc_resolve(handle->context, handle->cache_name,
&ccache)))
return (code);
/* set the client principal in the credential match structure */
mcreds.client = princ;
/*
* set the server principal (kadmin/changepw@REALM) in the credential
* match struct
*/
cpwlen = strlen(KADM5_CHANGEPW_SERVICE) +
strlen(handle->params.realm) + 2;
cpw_service = malloc(cpwlen);
if (cpw_service == NULL) {
return (ENOMEM);
}
snprintf(cpw_service, cpwlen, "%s@%s",
KADM5_CHANGEPW_SERVICE, handle->params.realm);
/* generate the server principal from the name string we generated */
if ((code = krb5_parse_name(handle->context, cpw_service,
&mcreds.server))) {
free(cpw_service);
return (code);
}
/* Find the credentials in the cache */
if ((code = krb5_cc_retrieve_cred(handle->context, ccache, 0, &mcreds,
&ncreds))) {
free(cpw_service);
return (code);
}
/* Now we have all we need to make the change request. */
result = krb5_change_password_local(handle->context, &handle->params,
&ncreds, newpw,
srvr_rsp_code,
srvr_msg);
free(cpw_service);
return (result);
}
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <string.h>
#include "k5-int.h"
#include <kadm5/admin.h>
#include <client_internal.h>
#include "auth_con.h"
#include <locale.h>
krb5_error_code
krb5int_mk_chpw_req(
krb5_context context,
krb5_auth_context auth_context,
krb5_data *ap_req,
char *passwd,
krb5_data *packet)
{
krb5_error_code ret = 0;
krb5_data clearpw;
krb5_data cipherpw;
krb5_replay_data replay;
char *ptr;
cipherpw.data = NULL;
if ((ret = krb5_auth_con_setflags(context, auth_context,
KRB5_AUTH_CONTEXT_DO_SEQUENCE)))
goto cleanup;
clearpw.length = strlen(passwd);
clearpw.data = passwd;
if ((ret = krb5_mk_priv(context, auth_context,
&clearpw, &cipherpw, &replay)))
goto cleanup;
packet->length = 6 + ap_req->length + cipherpw.length;
packet->data = (char *) malloc(packet->length);
if (packet->data == NULL)
{
ret = ENOMEM;
goto cleanup;
}
ptr = packet->data;
/* length */
*ptr++ = (packet->length>> 8) & 0xff;
*ptr++ = packet->length & 0xff;
/* version == 0x0001 big-endian
* NOTE: when MS and MIT start supporting the latest
* version of the passwd change protocol (v2),
* this value will change to 2.
*/
*ptr++ = 0;
*ptr++ = 1;
/* ap_req length, big-endian */
*ptr++ = (ap_req->length>>8) & 0xff;
*ptr++ = ap_req->length & 0xff;
/* ap-req data */
memcpy(ptr, ap_req->data, ap_req->length);
ptr += ap_req->length;
/* krb-priv of password */
memcpy(ptr, cipherpw.data, cipherpw.length);
cleanup:
if(cipherpw.data != NULL) /* allocated by krb5_mk_priv */
free(cipherpw.data);
return(ret);
}
krb5_error_code
krb5int_rd_chpw_rep(krb5_context context, krb5_auth_context auth_context, krb5_data *packet, int *result_code, krb5_data *result_data)
{
char *ptr;
int plen, vno;
krb5_data ap_rep;
krb5_ap_rep_enc_part *ap_rep_enc;
krb5_error_code ret;
krb5_data cipherresult;
krb5_data clearresult;
krb5_error *krberror;
krb5_replay_data replay;
krb5_keyblock *tmp;
int local_result_code;
if (packet->length < 4)
/* either this, or the server is printing bad messages,
or the caller passed in garbage */
return(KRB5KRB_AP_ERR_MODIFIED);
ptr = packet->data;
/* verify length */
plen = (*ptr++ & 0xff);
plen = (plen<<8) | (*ptr++ & 0xff);
if (plen != packet->length)
{
/*
* MS KDCs *may* send back a KRB_ERROR. Although
* not 100% correct via RFC3244, it's something
* we can workaround here.
*/
if (krb5_is_krb_error(packet)) {
if ((ret = krb5_rd_error(context, packet, &krberror)))
return(ret);
if (krberror->e_data.data == NULL) {
ret = ERROR_TABLE_BASE_krb5 + (krb5_error_code) krberror->error;
krb5_free_error(context, krberror);
return (ret);
}
}
else
{
return(KRB5KRB_AP_ERR_MODIFIED);
}
}
/* verify version number */
vno = (*ptr++ & 0xff);
vno = (vno<<8) | (*ptr++ & 0xff);
/*
* when the servers update to v2 of the protocol,
* "2" will be a valid version number here
*/
if (vno != 1 && vno != 2)
return (KRB5KDC_ERR_BAD_PVNO);
/* read, check ap-rep length */
ap_rep.length = (*ptr++ & 0xff);
ap_rep.length = (ap_rep.length<<8) | (*ptr++ & 0xff);
if (ptr + ap_rep.length >= packet->data + packet->length)
return(KRB5KRB_AP_ERR_MODIFIED);
if (ap_rep.length) {
/* verify ap_rep */
ap_rep.data = ptr;
ptr += ap_rep.length;
/*
* Save send_subkey to later smash recv_subkey.
*/
ret = krb5_auth_con_getsendsubkey(context, auth_context, &tmp);
if (ret)
return ret;
ret = krb5_rd_rep(context, auth_context, &ap_rep, &ap_rep_enc);
if (ret) {
krb5_free_keyblock(context, tmp);
return(ret);
}
krb5_free_ap_rep_enc_part(context, ap_rep_enc);
/* extract and decrypt the result */
cipherresult.data = ptr;
cipherresult.length = (packet->data + packet->length) - ptr;
/*
* Smash recv_subkey to be send_subkey, per spec.
*/
ret = krb5_auth_con_setrecvsubkey(context, auth_context, tmp);
krb5_free_keyblock(context, tmp);
if (ret)
return ret;
ret = krb5_rd_priv(context, auth_context, &cipherresult, &clearresult,
&replay);
if (ret)
return(ret);
} else {
cipherresult.data = ptr;
cipherresult.length = (packet->data + packet->length) - ptr;
if ((ret = krb5_rd_error(context, &cipherresult, &krberror)))
return(ret);
clearresult = krberror->e_data;
}
if (clearresult.length < 2) {
ret = KRB5KRB_AP_ERR_MODIFIED;
goto cleanup;
}
ptr = clearresult.data;
local_result_code = (*ptr++ & 0xff);
local_result_code = (local_result_code<<8) | (*ptr++ & 0xff);
if (result_code)
*result_code = local_result_code;
/*
* Make sure the result code is in range for this
* protocol.
*/
if ((local_result_code < KRB5_KPASSWD_SUCCESS) ||
(local_result_code > KRB5_KPASSWD_ETYPE_NOSUPP)) {
ret = KRB5KRB_AP_ERR_MODIFIED;
goto cleanup;
}
/* all success replies should be authenticated/encrypted */
if ((ap_rep.length == 0) && (local_result_code == KRB5_KPASSWD_SUCCESS)) {
ret = KRB5KRB_AP_ERR_MODIFIED;
goto cleanup;
}
result_data->length = (clearresult.data + clearresult.length) - ptr;
if (result_data->length) {
result_data->data = (char *) malloc(result_data->length);
if (result_data->data == NULL) {
ret = ENOMEM;
goto cleanup;
}
memcpy(result_data->data, ptr, result_data->length);
} else {
result_data->data = NULL;
}
ret = 0;
cleanup:
if (ap_rep.length) {
krb5_xfree(clearresult.data);
} else {
krb5_free_error(context, krberror);
}
return(ret);
}
/*
* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
*
* Openvision retains the copyright to derivative works of
* this source code. Do *NOT* create a derivative of this
* source code before consulting with your legal department.
* Do *NOT* integrate *ANY* of this source code into another
* product before consulting with your legal department.
*
* For further information, read the top-level Openvision
* copyright which is contained in the top-level MIT Kerberos
* copyright.
*
* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
*
*/
#include <krb5.h>
#include <kadm5/admin.h>
#include "client_internal.h"
int _kadm5_check_handle(void *handle)
{
CHECK_HANDLE(handle);
return 0;
}
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright 1993 OpenVision Technologies, Inc., All Rights Reserved
*/
/*
* Copyright (C) 1998 by the FundsXpress, INC.
*
* All rights reserved.
*
* Export of this software from the United States of America may require
* a specific license from the United States Government. It is the
* responsibility of any person or organization contemplating export to
* obtain such a license before exporting.
*
* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
* distribute this software and its documentation for any purpose and
* without fee is hereby granted, 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 FundsXpress. not be used in advertising or publicity pertaining
* to distribution of the software without specific, written prior
* permission. FundsXpress makes no representations about the suitability of
* this software for any purpose. It is provided "as is" without express
* or implied warranty.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#include <stdio.h>
#include <netdb.h>
#include "autoconf.h"
#ifdef HAVE_MEMORY_H
#include <memory.h>
#endif
#include <string.h>
#include <com_err.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <k5-int.h> /* for KRB5_ADM_DEFAULT_PORT */
#include <krb5.h>
#ifdef __STDC__
#include <stdlib.h>
#endif
#include <libintl.h>
#include <kadm5/admin.h>
#include <kadm5/kadm_rpc.h>
#include "client_internal.h"
#include <syslog.h>
#include <gssapi/gssapi.h>
#include <gssapi_krb5.h>
#include <gssapiP_krb5.h>
#include <rpc/clnt.h>
#include <iprop_hdr.h>
#include "iprop.h"
#define ADM_CCACHE "/tmp/ovsec_adm.XXXXXX"
static int old_auth_gssapi = 0;
/* connection timeout to kadmind in seconds */
#define KADMIND_CONNECT_TIMEOUT 25
int _kadm5_check_handle();
enum init_type { INIT_PASS, INIT_SKEY, INIT_CREDS };
static kadm5_ret_t _kadm5_init_any(char *client_name,
enum init_type init_type,
char *pass,
krb5_ccache ccache_in,
char *service_name,
kadm5_config_params *params,
krb5_ui_4 struct_version,
krb5_ui_4 api_version,
char **db_args,
void **server_handle);
kadm5_ret_t kadm5_init_with_creds(char *client_name,
krb5_ccache ccache,
char *service_name,
kadm5_config_params *params,
krb5_ui_4 struct_version,
krb5_ui_4 api_version,
char **db_args,
void **server_handle)
{
return _kadm5_init_any(client_name, INIT_CREDS, NULL, ccache,
service_name, params,
struct_version, api_version, db_args,
server_handle);
}
kadm5_ret_t kadm5_init_with_password(char *client_name, char *pass,
char *service_name,
kadm5_config_params *params,
krb5_ui_4 struct_version,
krb5_ui_4 api_version,
char **db_args,
void **server_handle)
{
return _kadm5_init_any(client_name, INIT_PASS, pass, NULL,
service_name, params, struct_version,
api_version, db_args, server_handle);
}
kadm5_ret_t kadm5_init(char *client_name, char *pass,
char *service_name,
kadm5_config_params *params,
krb5_ui_4 struct_version,
krb5_ui_4 api_version,
char **db_args,
void **server_handle)
{
return _kadm5_init_any(client_name, INIT_PASS, pass, NULL,
service_name, params, struct_version,
api_version, db_args, server_handle);
}
kadm5_ret_t kadm5_init_with_skey(char *client_name, char *keytab,
char *service_name,
kadm5_config_params *params,
krb5_ui_4 struct_version,
krb5_ui_4 api_version,
char **db_args,
void **server_handle)
{
return _kadm5_init_any(client_name, INIT_SKEY, keytab, NULL,
service_name, params, struct_version,
api_version, db_args, server_handle);
}
krb5_error_code kadm5_free_config_params();
static void
display_status_1(m, code, type, mech)
char *m;
OM_uint32 code;
int type;
const gss_OID mech;
{
OM_uint32 maj_stat, min_stat;
gss_buffer_desc msg = GSS_C_EMPTY_BUFFER;
OM_uint32 msg_ctx;
msg_ctx = 0;
ADMIN_LOG(LOG_ERR, "%s\n", m);
/* LINTED */
while (1) {
maj_stat = gss_display_status(&min_stat, code,
type, mech,
&msg_ctx, &msg);
if (maj_stat != GSS_S_COMPLETE) {
syslog(LOG_ERR,
dgettext(TEXT_DOMAIN,
"error in gss_display_status"
" called from <%s>\n"), m);
break;
} else
syslog(LOG_ERR, dgettext(TEXT_DOMAIN,
"GSS-API error : %s\n"),
m);
syslog(LOG_ERR, dgettext(TEXT_DOMAIN,
"GSS-API error : %s\n"),
(char *)msg.value);
if (msg.length != 0)
(void) gss_release_buffer(&min_stat, &msg);
if (!msg_ctx)
break;
}
}
/*
* Function: display_status
*
* Purpose: displays GSS-API messages
*
* Arguments:
*
* msg a string to be displayed with the message
* maj_stat the GSS-API major status code
* min_stat the GSS-API minor status code
* mech kerberos mech
* Effects:
*
* The GSS-API messages associated with maj_stat and min_stat are
* displayed on stderr, each preceeded by "GSS-API error <msg>: " and
* followed by a newline.
*/
void
display_status(msg, maj_stat, min_stat, mech)
char *msg;
OM_uint32 maj_stat;
OM_uint32 min_stat;
char *mech;
{
gss_OID mech_oid;
if (!rpc_gss_mech_to_oid(mech, (rpc_gss_OID *)&mech_oid)) {
ADMIN_LOG(LOG_ERR,
dgettext(TEXT_DOMAIN,
"Invalid mechanism oid <%s>"), mech);
return;
}
display_status_1(msg, maj_stat, GSS_C_GSS_CODE, mech_oid);
display_status_1(msg, min_stat, GSS_C_MECH_CODE, mech_oid);
}
/*
* Open an fd for the given address and connect asynchronously. Wait
* KADMIND_CONNECT_TIMEOUT seconds or till it succeeds. If it succeeds
* change fd to blocking and return it, else return -1.
*/
static int
get_connection(struct netconfig *nconf, struct netbuf netaddr)
{
struct t_info tinfo;
struct t_call sndcall;
struct t_call *rcvcall = NULL;
int connect_time;
int flags;
int fd;
(void) memset(&tinfo, 0, sizeof (tinfo));
/* we'l open with O_NONBLOCK and avoid an fcntl */
fd = t_open(nconf->nc_device, O_RDWR | O_NONBLOCK, &tinfo);
if (fd == -1) {
return (-1);
}
if (t_bind(fd, (struct t_bind *)NULL, (struct t_bind *)NULL) == -1) {
(void) close(fd);
return (-1);
}
/* we can't connect unless fd is in IDLE state */
if (t_getstate(fd) != T_IDLE) {
(void) close(fd);
return (-1);
}
/* setup connect parameters */
netaddr.len = netaddr.maxlen = __rpc_get_a_size(tinfo.addr);
sndcall.addr = netaddr;
sndcall.opt.len = sndcall.udata.len = 0;
/* we wait for KADMIND_CONNECT_TIMEOUT seconds from now */
connect_time = time(NULL) + KADMIND_CONNECT_TIMEOUT;
if (t_connect(fd, &sndcall, rcvcall) != 0) {
if (t_errno != TNODATA) {
(void) close(fd);
return (-1);
}
}
/* loop till success or timeout */
for (;;) {
if (t_rcvconnect(fd, rcvcall) == 0)
break;
if (t_errno != TNODATA || time(NULL) > connect_time) {
/* we have either timed out or caught an error */
(void) close(fd);
if (rcvcall != NULL)
t_free((char *)rcvcall, T_CALL);
return (-1);
}
sleep(1);
}
/* make the fd blocking (synchronous) */
flags = fcntl(fd, F_GETFL, 0);
(void) fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
if (rcvcall != NULL)
t_free((char *)rcvcall, T_CALL);
return (fd);
}
/*
* Open an RPCSEC_GSS connection and
* get a client handle to use for future RPCSEC calls.
*
* This function is only used when changing passwords and
* the kpasswd_protocol is RPCSEC_GSS
*/
static int
_kadm5_initialize_rpcsec_gss_handle(kadm5_server_handle_t handle,
char *client_name,
char *service_name)
{
struct netbuf netaddr;
struct hostent *hp;
int fd;
struct sockaddr_in addr;
struct sockaddr_in *sin;
struct netconfig *nconf;
int code = 0;
generic_ret *r;
char *ccname_orig;
char *iprop_svc;
boolean_t iprop_enable = B_FALSE;
char mech[] = "kerberos_v5";
gss_OID mech_oid;
gss_OID_set_desc oid_set;
gss_name_t gss_client;
gss_buffer_desc input_name;
gss_cred_id_t gss_client_creds = GSS_C_NO_CREDENTIAL;
rpc_gss_options_req_t options_req;
rpc_gss_options_ret_t options_ret;
rpc_gss_service_t service = rpc_gss_svc_privacy;
OM_uint32 gssstat, minor_stat;
void *handlep;
enum clnt_stat rpc_err_code;
char *server = handle->params.admin_server;
/*
* Try to find the kpasswd_server first if this is for the changepw
* service. If defined then it should be resolvable else return error.
*/
if (strncmp(service_name, KADM5_CHANGEPW_HOST_SERVICE,
strlen(KADM5_CHANGEPW_HOST_SERVICE)) == 0) {
if (handle->params.kpasswd_server != NULL)
server = handle->params.kpasswd_server;
}
hp = gethostbyname(server);
if (hp == (struct hostent *)NULL) {
code = KADM5_BAD_SERVER_NAME;
ADMIN_LOGO(LOG_ERR, dgettext(TEXT_DOMAIN,
"bad server name\n"));
goto cleanup;
}
memset(&addr, 0, sizeof (addr));
addr.sin_family = hp->h_addrtype;
(void) memcpy((char *)&addr.sin_addr, (char *)hp->h_addr,
sizeof (addr.sin_addr));
addr.sin_port = htons((ushort_t)handle->params.kadmind_port);
sin = &addr;
#ifdef DEBUG
printf("kadmin_port %d\n", handle->params.kadmind_port);
printf("addr: sin_port: %d, sin_family: %d, sin_zero %s\n",
addr.sin_port, addr.sin_family, addr.sin_zero);
printf("sin_addr %d:%d\n", addr.sin_addr.S_un.S_un_w.s_w1,
addr.sin_addr.S_un.S_un_w.s_w2);
#endif
if ((handlep = setnetconfig()) == (void *) NULL) {
(void) syslog(LOG_ERR,
dgettext(TEXT_DOMAIN,
"cannot get any transport information"));
goto error;
}
while (nconf = getnetconfig(handlep)) {
if ((nconf->nc_semantics == NC_TPI_COTS_ORD) &&
(strcmp(nconf->nc_protofmly, NC_INET) == 0) &&
(strcmp(nconf->nc_proto, NC_TCP) == 0))
break;
}
if (nconf == (struct netconfig *)NULL)
goto error;
/* Transform addr to netbuf */
(void) memset(&netaddr, 0, sizeof (netaddr));
netaddr.buf = (char *)sin;
/* get an fd connected to the given address */
fd = get_connection(nconf, netaddr);
if (fd == -1) {
syslog(LOG_ERR, dgettext(TEXT_DOMAIN,
"unable to open connection to ADMIN server "
"(t_error %i)"), t_errno);
code = KADM5_RPC_ERROR;
goto error;
}
#ifdef DEBUG
printf("fd: %d, KADM: %d, KADMVERS %d\n", fd, KADM, KADMVERS);
printf("nconf: nc_netid: %s, nc_semantics: %d, nc_flag: %d, "
"nc_protofmly: %s\n",
nconf->nc_netid, nconf->nc_semantics, nconf->nc_flag,
nconf->nc_protofmly);
printf("nc_proto: %s, nc_device: %s, nc_nlookups: %d, nc_used: %d\n",
nconf->nc_proto, nconf->nc_device, nconf->nc_nlookups,
nconf->nc_unused);
printf("netaddr: maxlen %d, buf: %s, len: %d\n", netaddr.maxlen,
netaddr.buf, netaddr.len);
#endif
/*
* Tell clnt_tli_create that given fd is already connected
*
* If the service_name and client_name are iprop-centric,
* we need to clnt_tli_create to the appropriate RPC prog
*/
iprop_svc = strdup(KIPROP_SVC_NAME);
if (iprop_svc == NULL)
return (ENOMEM);
if ((strstr(service_name, iprop_svc) != NULL) &&
(strstr(client_name, iprop_svc) != NULL)) {
iprop_enable = B_TRUE;
handle->clnt = clnt_tli_create(fd, nconf, NULL,
KRB5_IPROP_PROG, KRB5_IPROP_VERS, 0, 0);
}
else
handle->clnt = clnt_tli_create(fd, nconf, NULL,
KADM, KADMVERS, 0, 0);
if (iprop_svc)
free(iprop_svc);
if (handle->clnt == NULL) {
syslog(LOG_ERR, dgettext(TEXT_DOMAIN,
"clnt_tli_create failed\n"));
code = KADM5_RPC_ERROR;
(void) close(fd);
goto error;
}
/*
* The rpc-handle was created on an fd opened and connected
* by us, so we have to explicitly tell rpc to close it.
*/
if (clnt_control(handle->clnt, CLSET_FD_CLOSE, NULL) != TRUE) {
clnt_pcreateerror("ERROR:");
syslog(LOG_ERR, dgettext(TEXT_DOMAIN,
"clnt_control failed to set CLSET_FD_CLOSE"));
code = KADM5_RPC_ERROR;
(void) close(fd);
goto error;
}
handle->lhandle->clnt = handle->clnt;
/* now that handle->clnt is set, we can check the handle */
if (code = _kadm5_check_handle((void *) handle))
goto error;
/*
* The RPC connection is open; establish the GSS-API
* authentication context.
*/
ADMIN_LOGO(LOG_ERR, dgettext(TEXT_DOMAIN,
"have an rpc connection open\n"));
/* use the kadm5 cache */
ccname_orig = getenv("KRB5CCNAME");
if (ccname_orig)
ccname_orig = strdup(ccname_orig);
(void) krb5_setenv("KRB5CCNAME", handle->cache_name, 1);
ADMIN_LOG(LOG_ERR,
dgettext(TEXT_DOMAIN,
"current credential cache: %s"), handle->cache_name);
input_name.value = client_name;
input_name.length = strlen((char *)input_name.value) + 1;
gssstat = gss_import_name(&minor_stat, &input_name,
(gss_OID)gss_nt_krb5_name, &gss_client);
if (gssstat != GSS_S_COMPLETE) {
code = KADM5_GSS_ERROR;
ADMIN_LOGO(LOG_ERR,
dgettext(TEXT_DOMAIN,
"gss_import_name failed for client name\n"));
goto error;
}
if (!rpc_gss_mech_to_oid(mech, (rpc_gss_OID *)&mech_oid)) {
ADMIN_LOG(LOG_ERR,
dgettext(TEXT_DOMAIN,
"Invalid mechanism oid <%s>"), mech);
goto error;
}
oid_set.count = 1;
oid_set.elements = mech_oid;
gssstat = gss_acquire_cred(&minor_stat, gss_client, 0,
&oid_set, GSS_C_INITIATE,
&gss_client_creds, NULL, NULL);
(void) gss_release_name(&minor_stat, &gss_client);
if (gssstat != GSS_S_COMPLETE) {
code = KADM5_GSS_ERROR;
ADMIN_LOG(LOG_ERR,
dgettext(TEXT_DOMAIN,
"could not acquire credentials, "
"major error code: %d\n"), gssstat);
goto error;
}
handle->my_cred = gss_client_creds;
options_req.my_cred = gss_client_creds;
options_req.req_flags = GSS_C_MUTUAL_FLAG | GSS_C_REPLAY_FLAG;
options_req.time_req = 0;
options_req.input_channel_bindings = NULL;
#ifndef INIT_TEST
handle->clnt->cl_auth = rpc_gss_seccreate(handle->clnt,
service_name,
mech,
service,
NULL,
&options_req,
&options_ret);
#endif /* ! INIT_TEST */
if (ccname_orig) {
(void) krb5_setenv("KRB5CCNAME", ccname_orig, 1);
free(ccname_orig);
} else
(void) krb5_unsetenv("KRB5CCNAME");
if (handle->clnt->cl_auth == NULL) {
code = KADM5_GSS_ERROR;
display_status(dgettext(TEXT_DOMAIN,
"rpc_gss_seccreate failed\n"),
options_ret.major_status,
options_ret.minor_status,
mech);
goto error;
}
/*
* Bypass the remainder of the code and return straightaway
* if the gss service requested is kiprop
*/
if (iprop_enable == B_TRUE) {
code = 0;
goto cleanup;
}
r = init_2(&handle->api_version, handle->clnt);
/* Solaris Kerberos: 163 resync */
if (r == NULL) {
ADMIN_LOGO(LOG_ERR, dgettext(TEXT_DOMAIN,
"error during admin api initialization\n"));
code = KADM5_RPC_ERROR;
goto error;
}
if (r->code) {
code = r->code;
ADMIN_LOG(LOG_ERR,
dgettext(TEXT_DOMAIN,
"error during admin api initialization: %d\n"),
r->code);
goto error;
}
error:
cleanup:
if (handlep != (void *) NULL)
(void) endnetconfig(handlep);
/*
* gss_client_creds is freed only when there is an error condition,
* given that rpc_gss_seccreate() will assign the cred pointer to the
* my_cred member in the auth handle's private data structure.
*/
if (code && (gss_client_creds != GSS_C_NO_CREDENTIAL))
(void) gss_release_cred(&minor_stat, &gss_client_creds);
return (code);
}
static kadm5_ret_t _kadm5_init_any(char *client_name,
enum init_type init_type,
char *pass,
krb5_ccache ccache_in,
char *service_name,
kadm5_config_params *params_in,
krb5_ui_4 struct_version,
krb5_ui_4 api_version,
char **db_args,
void **server_handle)
{
int i;
krb5_creds creds;
krb5_ccache ccache = NULL;
krb5_timestamp now;
OM_uint32 gssstat, minor_stat;
kadm5_server_handle_t handle;
kadm5_config_params params_local;
int code = 0;
krb5_get_init_creds_opt opt;
gss_buffer_desc input_name;
krb5_error_code kret;
krb5_int32 starttime;
char *server = NULL;
krb5_principal serverp = NULL, clientp = NULL;
krb5_principal saved_server = NULL;
bool_t cpw = FALSE;
ADMIN_LOGO(LOG_ERR, dgettext(TEXT_DOMAIN,
"entering kadm5_init_any\n"));
if (! server_handle) {
return EINVAL;
}
if (! (handle = malloc(sizeof(*handle)))) {
return ENOMEM;
}
if (! (handle->lhandle = malloc(sizeof(*handle)))) {
free(handle);
return ENOMEM;
}
handle->magic_number = KADM5_SERVER_HANDLE_MAGIC;
handle->struct_version = struct_version;
handle->api_version = api_version;
handle->clnt = 0;
handle->cache_name = 0;
handle->destroy_cache = 0;
*handle->lhandle = *handle;
handle->lhandle->api_version = KADM5_API_VERSION_2;
handle->lhandle->struct_version = KADM5_STRUCT_VERSION;
handle->lhandle->lhandle = handle->lhandle;
kret = krb5_init_context(&handle->context);
if (kret) {
free(handle->lhandle);
free(handle);
return (kret);
}
if(service_name == NULL || client_name == NULL) {
krb5_free_context(handle->context);
free(handle->lhandle);
free(handle);
return EINVAL;
}
memset((char *) &creds, 0, sizeof(creds));
/*
* Verify the version numbers before proceeding; we can't use
* CHECK_HANDLE because not all fields are set yet.
*/
GENERIC_CHECK_HANDLE(handle, KADM5_OLD_LIB_API_VERSION,
KADM5_NEW_LIB_API_VERSION);
/*
* Acquire relevant profile entries. In version 2, merge values
* in params_in with values from profile, based on
* params_in->mask.
*
* In version 1, we've given a realm (which may be NULL) instead
* of params_in. So use that realm, make params_in contain an
* empty mask, and behave like version 2.
*/
memset((char *) ¶ms_local, 0, sizeof(params_local));
if (api_version == KADM5_API_VERSION_1) {
if (params_in)
params_local.mask = KADM5_CONFIG_REALM;
params_in = ¶ms_local;
}
#define ILLEGAL_PARAMS ( \
KADM5_CONFIG_ACL_FILE | KADM5_CONFIG_ADB_LOCKFILE | \
KADM5_CONFIG_DBNAME | KADM5_CONFIG_ADBNAME | \
KADM5_CONFIG_DICT_FILE | KADM5_CONFIG_ADMIN_KEYTAB | \
KADM5_CONFIG_STASH_FILE | KADM5_CONFIG_MKEY_NAME | \
KADM5_CONFIG_ENCTYPE | KADM5_CONFIG_MAX_LIFE | \
KADM5_CONFIG_MAX_RLIFE | KADM5_CONFIG_EXPIRATION | \
KADM5_CONFIG_FLAGS | KADM5_CONFIG_ENCTYPES | \
KADM5_CONFIG_MKEY_FROM_KBD)
if (params_in && params_in->mask & ILLEGAL_PARAMS) {
krb5_free_context(handle->context);
free(handle->lhandle);
free(handle);
ADMIN_LOG(LOG_ERR, dgettext(TEXT_DOMAIN,
"bad client parameters, returning %d"),
KADM5_BAD_CLIENT_PARAMS);
return KADM5_BAD_CLIENT_PARAMS;
}
if ((code = kadm5_get_config_params(handle->context, 0,
params_in, &handle->params))) {
krb5_free_context(handle->context);
free(handle->lhandle);
free(handle);
ADMIN_LOG(LOG_ERR, dgettext(TEXT_DOMAIN,
"failed to get config_params, return: %d\n"), code);
return(code);
}
#define REQUIRED_PARAMS (KADM5_CONFIG_REALM | \
KADM5_CONFIG_ADMIN_SERVER | \
KADM5_CONFIG_KADMIND_PORT)
#define KPW_REQUIRED_PARAMS (KADM5_CONFIG_REALM | \
KADM5_CONFIG_KPASSWD_SERVER | \
KADM5_CONFIG_KPASSWD_PORT)
if (((handle->params.mask & REQUIRED_PARAMS) != REQUIRED_PARAMS) &&
((handle->params.mask & KPW_REQUIRED_PARAMS) != KPW_REQUIRED_PARAMS)) {
(void) kadm5_free_config_params(handle->context,
&handle->params);
krb5_free_context(handle->context);
free(handle->lhandle);
free(handle);
ADMIN_LOGO(LOG_ERR, dgettext(TEXT_DOMAIN,
"missing config parameters\n"));
return KADM5_MISSING_KRB5_CONF_PARAMS;
}
/*
* Acquire a service ticket for service_name@realm in the name of
* client_name, using password pass (which could be NULL), and
* create a ccache to store them in. If INIT_CREDS, use the
* ccache we were provided instead.
*/
if ((code = krb5_parse_name(handle->context, client_name,
&creds.client))) {
ADMIN_LOGO(LOG_ERR, dgettext(TEXT_DOMAIN,
"could not parse client name\n"));
goto error;
}
clientp = creds.client;
if (strncmp(service_name, KADM5_CHANGEPW_HOST_SERVICE,
strlen(KADM5_CHANGEPW_HOST_SERVICE)) == 0)
cpw = TRUE;
if (init_type == INIT_PASS &&
handle->params.kpasswd_protocol == KRB5_CHGPWD_CHANGEPW_V2 &&
cpw == TRUE) {
/*
* The 'service_name' is constructed by the caller
* but its done before the parameter which determines
* the kpasswd_protocol is found. The servers that
* support the SET/CHANGE password protocol expect
* a slightly different service principal than
* the normal SEAM kadmind so construct the correct
* name here and then forget it.
*/
char *newsvcname = NULL;
newsvcname = malloc(strlen(KADM5_CHANGEPW_SERVICE) +
strlen(handle->params.realm) + 2);
if (newsvcname == NULL) {
ADMIN_LOGO(LOG_ERR, dgettext(TEXT_DOMAIN,
"could not malloc\n"));
code = ENOMEM;
goto error;
}
sprintf(newsvcname, "%s@%s", KADM5_CHANGEPW_SERVICE,
handle->params.realm);
if ((code = krb5_parse_name(handle->context, newsvcname,
&creds.server))) {
ADMIN_LOGO(LOG_ERR, dgettext(TEXT_DOMAIN,
"could not parse server "
"name\n"));
free(newsvcname);
goto error;
}
free(newsvcname);
} else {
input_name.value = service_name;
input_name.length = strlen((char *)input_name.value) + 1;
gssstat = krb5_gss_import_name(&minor_stat,
&input_name,
(gss_OID)GSS_C_NT_HOSTBASED_SERVICE,
(gss_name_t *)&creds.server);
if (gssstat != GSS_S_COMPLETE) {
code = KADM5_GSS_ERROR;
ADMIN_LOGO(LOG_ERR, dgettext(TEXT_DOMAIN,
"gss_import_name failed for client name\n"));
goto error;
}
}
serverp = creds.server;
/* XXX temporarily fix a bug in krb5_cc_get_type */
#undef krb5_cc_get_type
#define krb5_cc_get_type(context, cache) ((cache)->ops->prefix)
if (init_type == INIT_CREDS) {
ccache = ccache_in;
handle->cache_name = (char *)
malloc(strlen(krb5_cc_get_type(handle->context, ccache)) +
strlen(krb5_cc_get_name(handle->context, ccache)) + 2);
if (handle->cache_name == NULL) {
code = ENOMEM;
goto error;
}
sprintf(handle->cache_name, "%s:%s",
krb5_cc_get_type(handle->context, ccache),
krb5_cc_get_name(handle->context, ccache));
} else {
#if 0
handle->cache_name =
(char *) malloc(strlen(ADM_CCACHE)+strlen("FILE:")+1);
if (handle->cache_name == NULL) {
code = ENOMEM;
goto error;
}
sprintf(handle->cache_name, "FILE:%s", ADM_CCACHE);
mktemp(handle->cache_name + strlen("FILE:"));
#endif
{
static int counter = 0;
handle->cache_name = malloc(sizeof("MEMORY:kadm5_")
+ 3*sizeof(counter));
sprintf(handle->cache_name, "MEMORY:kadm5_%u", counter++);
}
if ((code = krb5_cc_resolve(handle->context, handle->cache_name,
&ccache)))
goto error;
if ((code = krb5_cc_initialize (handle->context, ccache,
creds.client)))
goto error;
handle->destroy_cache = 1;
}
handle->lhandle->cache_name = handle->cache_name;
ADMIN_LOG(LOG_ERR, dgettext(TEXT_DOMAIN,
"cache created: %s\n"), handle->cache_name);
if ((code = krb5_timeofday(handle->context, &now)))
goto error;
/*
* Get a ticket, use the method specified in init_type.
*/
creds.times.starttime = 0; /* start timer at KDC */
creds.times.endtime = 0; /* endtime will be limited by service */
memset(&opt, 0, sizeof (opt));
krb5_get_init_creds_opt_init(&opt);
if (creds.times.endtime) {
if (creds.times.starttime)
starttime = creds.times.starttime;
else
starttime = now;
krb5_get_init_creds_opt_set_tkt_life(&opt,
creds.times.endtime - starttime);
}
code = krb5_unparse_name(handle->context, creds.server, &server);
if (code)
goto error;
/*
* Solaris Kerberos:
* Save the original creds.server as krb5_get_init_creds*() always
* sets the realm of the server to the client realm.
*/
code = krb5_copy_principal(handle->context, creds.server, &saved_server);
if (code)
goto error;
if (init_type == INIT_PASS) {
code = krb5_get_init_creds_password(handle->context,
&creds, creds.client, pass, NULL,
NULL, creds.times.starttime,
server, &opt);
} else if (init_type == INIT_SKEY) {
krb5_keytab kt = NULL;
if (!(pass && (code = krb5_kt_resolve(handle->context,
pass, &kt)))) {
code = krb5_get_init_creds_keytab(
handle->context,
&creds, creds.client, kt,
creds.times.starttime,
server, &opt);
if (pass) krb5_kt_close(handle->context, kt);
}
}
/* Improved error messages */
if (code == KRB5KRB_AP_ERR_BAD_INTEGRITY) code = KADM5_BAD_PASSWORD;
if (code == KRB5KDC_ERR_S_PRINCIPAL_UNKNOWN)
code = KADM5_SECURE_PRINC_MISSING;
if (code != 0) {
ADMIN_LOGO(LOG_ERR, dgettext(TEXT_DOMAIN,
"failed to obtain credentials cache\n"));
krb5_free_principal(handle->context, saved_server);
goto error;
}
/*
* Solaris Kerberos:
* If the server principal had an empty realm then store that in
* the cred cache and not the server realm as returned by
* krb5_get_init_creds_{keytab|password}(). This ensures that rpcsec_gss
* will find the credential in the cred cache even if a "fallback"
* method is being used to determine the realm.
*/
if (init_type != INIT_CREDS) {
krb5_free_principal(handle->context, creds.server);
}
creds.server = saved_server;
/*
* If we got this far, save the creds in the cache.
*/
if (ccache) {
code = krb5_cc_store_cred(handle->context, ccache, &creds);
}
ADMIN_LOGO(LOG_ERR, dgettext(TEXT_DOMAIN, "obtained credentials cache\n"));
#ifdef ZEROPASSWD
if (pass != NULL)
memset(pass, 0, strlen(pass));
#endif
if (init_type != INIT_PASS ||
handle->params.kpasswd_protocol == KRB5_CHGPWD_RPCSEC ||
cpw == FALSE) {
code = _kadm5_initialize_rpcsec_gss_handle(handle,
client_name, service_name);
/*
* Solaris Kerberos:
* If _kadm5_initialize_rpcsec_gss_handle() fails it will have
* called krb5_gss_release_cred(). If the credential cache is a
* MEMORY cred cache krb5_gss_release_cred() destroys the
* cred cache data. Make sure that the cred-cache is closed
* to prevent a double free in the "error" code.
*/
if (code != 0) {
if (init_type != INIT_CREDS) {
krb5_cc_close(handle->context, ccache);
ccache = NULL;
}
goto error;
}
}
*server_handle = (void *) handle;
if (init_type != INIT_CREDS)
krb5_cc_close(handle->context, ccache);
goto cleanup;
error:
/*
* Note that it is illegal for this code to execute if "handle"
* has not been allocated and initialized. I.e., don't use "goto
* error" before the block of code at the top of the function
* that allocates and initializes "handle".
*/
if (handle->cache_name)
free(handle->cache_name);
if (handle->destroy_cache && ccache)
krb5_cc_destroy(handle->context, ccache);
if(handle->clnt && handle->clnt->cl_auth)
AUTH_DESTROY(handle->clnt->cl_auth);
if(handle->clnt)
clnt_destroy(handle->clnt);
(void) kadm5_free_config_params(handle->context, &handle->params);
cleanup:
if (server)
free(server);
/*
* cred's server and client pointers could have been overwritten
* by the krb5_get_init_* functions. If the addresses are different
* before and after the calls then we must free the memory that
* was allocated before the call.
*/
if (clientp && clientp != creds.client)
krb5_free_principal(handle->context, clientp);
if (serverp && serverp != creds.server)
krb5_free_principal(handle->context, serverp);
krb5_free_cred_contents(handle->context, &creds);
/*
* Dont clean up the handle if the code is OK (code==0)
* because it is returned to the caller in the 'server_handle'
* ptr.
*/
if (code) {
krb5_free_context(handle->context);
free(handle->lhandle);
free(handle);
}
return code;
}
kadm5_ret_t
kadm5_destroy(void *server_handle)
{
krb5_ccache ccache = NULL;
int code = KADM5_OK;
kadm5_server_handle_t handle =
(kadm5_server_handle_t) server_handle;
OM_uint32 min_stat;
CHECK_HANDLE(server_handle);
/* SUNW14resync:
* krb5_cc_resolve() will resolve a ccache with the same data that
* handle->my_cred points to. If the ccache is a MEMORY ccache then
* gss_release_cred() will free that data (it doesn't do this when ccache
* is a FILE ccache).
* if'ed out to avoid the double free.
*/
#if 0
if (handle->destroy_cache && handle->cache_name) {
if ((code = krb5_cc_resolve(handle->context,
handle->cache_name, &ccache)) == 0)
code = krb5_cc_destroy (handle->context, ccache);
}
#endif
if (handle->cache_name)
free(handle->cache_name);
if (handle->clnt && handle->clnt->cl_auth) {
/*
* Since kadm5 doesn't use the default credentials we
* must clean this up manually.
*/
if (handle->my_cred != GSS_C_NO_CREDENTIAL)
(void) gss_release_cred(&min_stat, &handle->my_cred);
AUTH_DESTROY(handle->clnt->cl_auth);
}
if (handle->clnt)
clnt_destroy(handle->clnt);
if (handle->lhandle)
free (handle->lhandle);
kadm5_free_config_params(handle->context, &handle->params);
krb5_free_context(handle->context);
handle->magic_number = 0;
free(handle);
return code;
}
/* not supported on client */
kadm5_ret_t kadm5_lock(void *server_handle)
{
return EINVAL;
}
/* not supported on client */
kadm5_ret_t kadm5_unlock(void *server_handle)
{
return EINVAL;
}
kadm5_ret_t kadm5_flush(void *server_handle)
{
return KADM5_OK;
}
int _kadm5_check_handle(void *handle)
{
CHECK_HANDLE(handle);
return 0;
}
krb5_error_code kadm5_init_krb5_context (krb5_context *ctx)
{
return krb5_init_context(ctx);
}
/*
* Stub function for kadmin. It was created to eliminate the dependency on
* libkdb's ulog functions. The srv equivalent makes the actual calls.
*/
krb5_error_code
kadm5_init_iprop(void *handle)
{
return (0);
}
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef __KADM5_CLIENT_INTERNAL_H__
#define __KADM5_CLIENT_INTERNAL_H__
/*
* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
*
* Openvision retains the copyright to derivative works of
* this source code. Do *NOT* create a derivative of this
* source code before consulting with your legal department.
* Do *NOT* integrate *ANY* of this source code into another
* product before consulting with your legal department.
*
* For further information, read the top-level Openvision
* copyright which is contained in the top-level MIT Kerberos
* copyright.
*
* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
*
*/
/*
* Copyright 1993 OpenVision Technologies, Inc., All Rights Reserved
*
* $Header$
*
* $Log$
* Revision 1.1 1996/07/24 22:22:43 tlyu
* * Makefile.in, configure.in: break out client lib into a
* subdirectory
*
* Revision 1.11 1996/07/22 20:35:46 marc
* this commit includes all the changes on the OV_9510_INTEGRATION and
* OV_MERGE branches. This includes, but is not limited to, the new openvision
* admin system, and major changes to gssapi to add functionality, and bring
* the implementation in line with rfc1964. before committing, the
* code was built and tested for netbsd and solaris.
*
* Revision 1.10.4.1 1996/07/18 03:08:37 marc
* merged in changes from OV_9510_BP to OV_9510_FINAL1
*
* Revision 1.10.2.1 1996/06/20 02:16:46 marc
* File added to the repository on a branch
*
* Revision 1.10 1996/06/06 20:09:16 bjaspan
* add destroy_cache, for kadm5_init_with_creds
*
* Revision 1.9 1996/05/30 21:04:42 bjaspan
* add lhandle to handle
*
* Revision 1.8 1996/05/28 20:33:49 bjaspan
* rework kadm5_config
*
* Revision 1.7 1996/05/17 21:36:59 bjaspan
* rename to kadm5, begin implementing version 2
*
* Revision 1.6 1996/05/16 21:45:07 bjaspan
* add context
*
* Revision 1.5 1996/05/08 21:10:23 bjaspan
* marc's changes
*
* Revision 1.4 1996/01/16 20:54:30 grier
* secure/3570 use krb5_ui_4 not unsigned int
*
* Revision 1.3 1995/11/14 17:48:57 grier
* long to int
*
* Revision 1.2 1994/08/16 18:53:47 jik
* Versioning stuff.
*
* Revision 1.1 1994/08/09 21:14:38 jik
* Initial revision
*
*/
/*
* This header file is used internally by the Admin API client
* libraries. IF YOU THINK YOU NEED TO USE THIS FILE FOR ANYTHING,
* YOU'RE ALMOST CERTAINLY WRONG.
*/
#ifdef __cplusplus
extern "C" {
#endif
#include "admin_internal.h"
typedef struct _kadm5_server_handle_t {
krb5_ui_4 magic_number;
krb5_ui_4 struct_version;
krb5_ui_4 api_version;
char * cache_name;
int destroy_cache;
CLIENT * clnt;
krb5_context context;
/* Solaris Kerberos */
gss_cred_id_t my_cred;
kadm5_config_params params;
struct _kadm5_server_handle_t *lhandle;
} kadm5_server_handle_rec, *kadm5_server_handle_t;
#define CLIENT_CHECK_HANDLE(handle) \
{ \
kadm5_server_handle_t srvr = \
(kadm5_server_handle_t) handle; \
\
if (srvr->params.kpasswd_protocol == KRB5_CHGPWD_RPCSEC && ! srvr->clnt) \
return KADM5_BAD_SERVER_HANDLE; \
if (! srvr->cache_name) \
return KADM5_BAD_SERVER_HANDLE; \
if (! srvr->lhandle) \
return KADM5_BAD_SERVER_HANDLE; \
}
#define CHECK_HANDLE(handle) \
GENERIC_CHECK_HANDLE(handle, KADM5_OLD_LIB_API_VERSION, \
KADM5_NEW_LIB_API_VERSION) \
CLIENT_CHECK_HANDLE(handle)
#ifdef __cplusplus
}
#endif
#endif /* __KADM5_CLIENT_INTERNAL_H__ */
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
*
* Openvision retains the copyright to derivative works of
* this source code. Do *NOT* create a derivative of this
* source code before consulting with your legal department.
* Do *NOT* integrate *ANY* of this source code into another
* product before consulting with your legal department.
*
* For further information, read the top-level Openvision
* copyright which is contained in the top-level MIT Kerberos
* copyright.
*
* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
*
*/
/*
* Copyright 1993 OpenVision Technologies, Inc., All Rights Reserved
*
* $Header$
*/
#if !defined(lint) && !defined(__CODECENTER__)
static char *rcsid = "$Header$";
#endif
#include <rpc/rpc.h> /* SUNWresync121 XXX */
#include <kadm5/admin.h>
#include <kadm5/kadm_rpc.h>
#ifdef HAVE_MEMORY_H
#include <memory.h>
#endif
#include <errno.h>
#include "client_internal.h"
#ifdef DEBUG /* SUNWresync14 XXX */
#define eret() {clnt_perror(handle->clnt, "null ret"); return KADM5_RPC_ERROR;}
#else
#define eret() return KADM5_RPC_ERROR
#endif
kadm5_ret_t
kadm5_create_principal(void *server_handle,
kadm5_principal_ent_t princ, long mask,
char *pw)
{
generic_ret *r;
cprinc_arg arg;
kadm5_server_handle_t handle = server_handle;
CHECK_HANDLE(server_handle);
memset(&arg, 0, sizeof(arg));
arg.mask = mask;
arg.passwd = pw;
arg.api_version = handle->api_version;
if(princ == NULL)
return EINVAL;
if (handle->api_version == KADM5_API_VERSION_1) {
memcpy(&arg.rec, princ, sizeof(kadm5_principal_ent_rec_v1));
} else {
memcpy(&arg.rec, princ, sizeof(kadm5_principal_ent_rec));
}
if (handle->api_version == KADM5_API_VERSION_1) {
/*
* hack hack cough cough.
* krb5_unparse name dumps core if we pass it in garbage
* or null. So, since the client is not allowed to set mod_name
* anyway, we just fill it in with a dummy principal. The server of
* course ignores this.
*/
/* krb5_parse_name(handle->context, "bogus/bogus", &arg.rec.mod_name); */
arg.rec.mod_name = NULL;
} else
arg.rec.mod_name = NULL;
if(!(mask & KADM5_POLICY))
arg.rec.policy = NULL;
if (! (mask & KADM5_KEY_DATA)) {
arg.rec.n_key_data = 0;
arg.rec.key_data = NULL;
}
if (! (mask & KADM5_TL_DATA)) {
arg.rec.n_tl_data = 0;
arg.rec.tl_data = NULL;
}
r = create_principal_2(&arg, handle->clnt);
if (handle->api_version == KADM5_API_VERSION_1)
krb5_free_principal(handle->context, arg.rec.mod_name);
if(r == NULL)
eret();
return r->code;
}
kadm5_ret_t
kadm5_create_principal_3(void *server_handle,
kadm5_principal_ent_t princ, long mask,
int n_ks_tuple,
krb5_key_salt_tuple *ks_tuple,
char *pw)
{
generic_ret *r;
cprinc3_arg arg;
kadm5_server_handle_t handle = server_handle;
CHECK_HANDLE(server_handle);
memset(&arg, 0, sizeof(arg));
arg.mask = mask;
arg.passwd = pw;
arg.api_version = handle->api_version;
arg.n_ks_tuple = n_ks_tuple;
arg.ks_tuple = ks_tuple;
if(princ == NULL)
return EINVAL;
if (handle->api_version == KADM5_API_VERSION_1) {
memcpy(&arg.rec, princ, sizeof(kadm5_principal_ent_rec_v1));
} else {
memcpy(&arg.rec, princ, sizeof(kadm5_principal_ent_rec));
}
if (handle->api_version == KADM5_API_VERSION_1) {
/*
* hack hack cough cough.
* krb5_unparse name dumps core if we pass it in garbage
* or null. So, since the client is not allowed to set mod_name
* anyway, we just fill it in with a dummy principal. The server of
* course ignores this.
*/
krb5_parse_name(handle->context, "bogus/bogus", &arg.rec.mod_name);
} else
arg.rec.mod_name = NULL;
if(!(mask & KADM5_POLICY))
arg.rec.policy = NULL;
if (! (mask & KADM5_KEY_DATA)) {
arg.rec.n_key_data = 0;
arg.rec.key_data = NULL;
}
if (! (mask & KADM5_TL_DATA)) {
arg.rec.n_tl_data = 0;
arg.rec.tl_data = NULL;
}
r = create_principal3_2(&arg, handle->clnt);
if (handle->api_version == KADM5_API_VERSION_1)
krb5_free_principal(handle->context, arg.rec.mod_name);
if(r == NULL)
eret();
return r->code;
}
kadm5_ret_t
kadm5_delete_principal(void *server_handle, krb5_principal principal)
{
dprinc_arg arg;
generic_ret *r;
kadm5_server_handle_t handle = server_handle;
CHECK_HANDLE(server_handle);
if(principal == NULL)
return EINVAL;
arg.princ = principal;
arg.api_version = handle->api_version;
r = delete_principal_2(&arg, handle->clnt);
if(r == NULL)
eret();
return r->code;
}
kadm5_ret_t
kadm5_modify_principal(void *server_handle,
kadm5_principal_ent_t princ, long mask)
{
mprinc_arg arg;
generic_ret *r;
kadm5_server_handle_t handle = server_handle;
CHECK_HANDLE(server_handle);
memset(&arg, 0, sizeof(arg));
arg.mask = mask;
arg.api_version = handle->api_version;
/*
* cough cough gag gag
* see comment in create_principal.
*/
if(princ == NULL)
return EINVAL;
if (handle->api_version == KADM5_API_VERSION_1) {
memcpy(&arg.rec, princ, sizeof(kadm5_principal_ent_rec_v1));
} else {
memcpy(&arg.rec, princ, sizeof(kadm5_principal_ent_rec));
}
if(!(mask & KADM5_POLICY))
arg.rec.policy = NULL;
if (! (mask & KADM5_KEY_DATA)) {
arg.rec.n_key_data = 0;
arg.rec.key_data = NULL;
}
if (! (mask & KADM5_TL_DATA)) {
arg.rec.n_tl_data = 0;
arg.rec.tl_data = NULL;
}
if (handle->api_version == KADM5_API_VERSION_1) {
/*
* See comment in create_principal
*/
krb5_parse_name(handle->context, "bogus/bogus", &arg.rec.mod_name);
} else
arg.rec.mod_name = NULL;
r = modify_principal_2(&arg, handle->clnt);
if (handle->api_version == KADM5_API_VERSION_1)
krb5_free_principal(handle->context, arg.rec.mod_name);
if(r == NULL)
eret();
return r->code;
}
kadm5_ret_t
kadm5_get_principal(void *server_handle,
krb5_principal princ, kadm5_principal_ent_t ent,
long mask)
{
gprinc_arg arg;
gprinc_ret *r;
kadm5_server_handle_t handle = server_handle;
CHECK_HANDLE(server_handle);
if(princ == NULL)
return EINVAL;
arg.princ = princ;
if (handle->api_version == KADM5_API_VERSION_1)
arg.mask = KADM5_PRINCIPAL_NORMAL_MASK;
else
arg.mask = mask;
arg.api_version = handle->api_version;
r = get_principal_2(&arg, handle->clnt);
if(r == NULL)
eret();
if (handle->api_version == KADM5_API_VERSION_1) {
kadm5_principal_ent_t_v1 *entp;
entp = (kadm5_principal_ent_t_v1 *) ent;
if (r->code == 0) {
if (!(*entp = (kadm5_principal_ent_t_v1)
malloc(sizeof(kadm5_principal_ent_rec_v1))))
return ENOMEM;
/* this memcpy works because the v1 structure is an initial
subset of the v2 struct. C guarantees that this will
result in the same layout in memory */
memcpy(*entp, &r->rec, sizeof(**entp));
} else {
*entp = NULL;
}
} else {
if (r->code == 0)
memcpy(ent, &r->rec, sizeof(r->rec));
}
return r->code;
}
kadm5_ret_t
kadm5_get_principals(void *server_handle,
char *exp, char ***princs, int *count)
{
gprincs_arg arg;
gprincs_ret *r;
kadm5_server_handle_t handle = server_handle;
CHECK_HANDLE(server_handle);
if(princs == NULL || count == NULL)
return EINVAL;
arg.exp = exp;
arg.api_version = handle->api_version;
r = get_princs_2(&arg, handle->clnt);
if(r == NULL)
eret();
if(r->code == 0) {
*count = r->count;
*princs = r->princs;
} else {
*count = 0;
*princs = NULL;
}
return r->code;
}
kadm5_ret_t
kadm5_rename_principal(void *server_handle,
krb5_principal source, krb5_principal dest)
{
rprinc_arg arg;
generic_ret *r;
kadm5_server_handle_t handle = server_handle;
CHECK_HANDLE(server_handle);
arg.src = source;
arg.dest = dest;
arg.api_version = handle->api_version;
if (source == NULL || dest == NULL)
return EINVAL;
r = rename_principal_2(&arg, handle->clnt);
if(r == NULL)
eret();
return r->code;
}
kadm5_ret_t
kadm5_chpass_principal(void *server_handle,
krb5_principal princ, char *password)
{
chpass_arg arg;
generic_ret *r;
kadm5_server_handle_t handle = server_handle;
CHECK_HANDLE(server_handle);
arg.princ = princ;
arg.pass = password;
arg.api_version = handle->api_version;
if(princ == NULL)
return EINVAL;
r = chpass_principal_2(&arg, handle->clnt);
if(r == NULL)
eret();
return r->code;
}
kadm5_ret_t
kadm5_chpass_principal_3(void *server_handle,
krb5_principal princ, krb5_boolean keepold,
int n_ks_tuple, krb5_key_salt_tuple *ks_tuple,
char *password)
{
chpass3_arg arg;
generic_ret *r;
kadm5_server_handle_t handle = server_handle;
CHECK_HANDLE(server_handle);
arg.princ = princ;
arg.pass = password;
arg.api_version = handle->api_version;
arg.keepold = keepold;
arg.n_ks_tuple = n_ks_tuple;
arg.ks_tuple = ks_tuple;
if(princ == NULL)
return EINVAL;
r = chpass_principal3_2(&arg, handle->clnt);
if(r == NULL)
eret();
return r->code;
}
kadm5_ret_t
kadm5_setv4key_principal(void *server_handle,
krb5_principal princ,
krb5_keyblock *keyblock)
{
setv4key_arg arg;
generic_ret *r;
kadm5_server_handle_t handle = server_handle;
CHECK_HANDLE(server_handle);
arg.princ = princ;
arg.keyblock = keyblock;
arg.api_version = handle->api_version;
if(princ == NULL || keyblock == NULL)
return EINVAL;
r = setv4key_principal_2(&arg, handle->clnt);
if(r == NULL)
eret();
return r->code;
}
kadm5_ret_t
kadm5_setkey_principal(void *server_handle,
krb5_principal princ,
krb5_keyblock *keyblocks,
int n_keys)
{
setkey_arg arg;
generic_ret *r;
kadm5_server_handle_t handle = server_handle;
CHECK_HANDLE(server_handle);
arg.princ = princ;
arg.keyblocks = keyblocks;
arg.n_keys = n_keys;
arg.api_version = handle->api_version;
if(princ == NULL || keyblocks == NULL)
return EINVAL;
r = setkey_principal_2(&arg, handle->clnt);
if(r == NULL)
eret();
return r->code;
}
kadm5_ret_t
kadm5_setkey_principal_3(void *server_handle,
krb5_principal princ,
krb5_boolean keepold, int n_ks_tuple,
krb5_key_salt_tuple *ks_tuple,
krb5_keyblock *keyblocks,
int n_keys)
{
setkey3_arg arg;
generic_ret *r;
kadm5_server_handle_t handle = server_handle;
CHECK_HANDLE(server_handle);
arg.princ = princ;
arg.keyblocks = keyblocks;
arg.n_keys = n_keys;
arg.api_version = handle->api_version;
arg.keepold = keepold;
arg.n_ks_tuple = n_ks_tuple;
arg.ks_tuple = ks_tuple;
if(princ == NULL || keyblocks == NULL)
return EINVAL;
r = setkey_principal3_2(&arg, handle->clnt);
if(r == NULL)
eret();
return r->code;
}
/*
* Solaris Kerberos:
* This routine implements just the "old" randkey_principal code.
* The code in the kadmin client sometimes needs to call this
* directly when the kadm5_randkey_principal_3 call fails.
*
* The kadmin client utility uses a specific set of key/salt tuples,
* so the standard fallback in kadm5_randkey_principal (see below)
* will not work because it would result in kadm5_randkey_principal_3
* being called twice - once with the specific key/salts specified by
* kadmin and once with the NULL set (used to indicate that the server
* should use the full set of supported enctypes). Making this
* routine separate makes the code simpler and avoids making the
* kadm5_randkey_principal_3 twice from kadmin.
*/
kadm5_ret_t
kadm5_randkey_principal_old(void *server_handle,
krb5_principal princ,
krb5_keyblock **key,
int *n_keys)
{
chrand_arg arg;
chrand_ret *r;
kadm5_server_handle_t handle = server_handle;
int i, ret;
/* For safety */
if (n_keys)
*n_keys = 0;
if (key)
*key = NULL;
CHECK_HANDLE(server_handle);
arg.princ = princ;
arg.api_version = handle->api_version;
if(princ == NULL)
return EINVAL;
r = chrand_principal_2(&arg, handle->clnt);
if (r == NULL)
return KADM5_RPC_ERROR;
if (handle->api_version == KADM5_API_VERSION_1) {
if (key)
krb5_copy_keyblock(handle->context, &r->key, key);
} else if (key && (r->n_keys > 0)) {
*key = (krb5_keyblock *) malloc(
r->n_keys*sizeof(krb5_keyblock));
if (*key == NULL)
return ENOMEM;
for (i = 0; i < r->n_keys; i++) {
ret = krb5_copy_keyblock_contents(
handle->context,
&r->keys[i],
&(*key)[i]);
if (ret) {
free(*key);
*key = NULL;
return ENOMEM;
}
}
if (n_keys)
*n_keys = r->n_keys;
}
return (r->code);
}
kadm5_ret_t
kadm5_randkey_principal_3(void *server_handle,
krb5_principal princ,
krb5_boolean keepold, int n_ks_tuple,
krb5_key_salt_tuple *ks_tuple,
krb5_keyblock **key, int *n_keys)
{
chrand3_arg arg;
chrand_ret *r;
kadm5_server_handle_t handle = server_handle;
int i, ret;
/* Solaris Kerberos - For safety */
if (n_keys)
*n_keys = 0;
if (key)
*key = NULL;
CHECK_HANDLE(server_handle);
arg.princ = princ;
arg.api_version = handle->api_version;
arg.keepold = keepold;
arg.n_ks_tuple = n_ks_tuple;
arg.ks_tuple = ks_tuple;
if(princ == NULL)
return EINVAL;
r = chrand_principal3_2(&arg, handle->clnt);
if(r == NULL)
eret();
if (handle->api_version == KADM5_API_VERSION_1) {
if (key)
krb5_copy_keyblock(handle->context, &r->key, key);
} else {
if (n_keys)
*n_keys = r->n_keys;
if (key) {
if(r->n_keys) {
*key = (krb5_keyblock *)
malloc(r->n_keys*sizeof(krb5_keyblock));
if (*key == NULL)
return ENOMEM;
for (i = 0; i < r->n_keys; i++) {
ret = krb5_copy_keyblock_contents(handle->context,
&r->keys[i],
&(*key)[i]);
if (ret) {
free(*key);
return ENOMEM;
}
}
} else *key = NULL;
}
}
return r->code;
}
kadm5_ret_t
kadm5_randkey_principal(void *server_handle,
krb5_principal princ,
krb5_keyblock **key, int *n_keys)
{
/* Solaris Kerberos */
kadm5_ret_t kret;
/*
* Default to trying the newest API to insure that the full
* set of enctypes is created.
*/
kret = kadm5_randkey_principal_3(server_handle, princ, FALSE,
0, NULL, key, n_keys);
/*
* We will get an RPC error if the RPC call failed which
* will normally indicate that the remote procedure did not
* exist on the server, so try the older API.
*/
if (kret == KADM5_RPC_ERROR) {
kret = kadm5_randkey_principal_old(server_handle, princ,
key, n_keys);
}
return (kret);
}
/* not supported on client side */
kadm5_ret_t kadm5_decrypt_key(void *server_handle,
kadm5_principal_ent_t entry, krb5_int32
ktype, krb5_int32 stype, krb5_int32
kvno, krb5_keyblock *keyblock,
krb5_keysalt *keysalt, int *kvnop)
{
return EINVAL;
}
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
*
* Openvision retains the copyright to derivative works of
* this source code. Do *NOT* create a derivative of this
* source code before consulting with your legal department.
* Do *NOT* integrate *ANY* of this source code into another
* product before consulting with your legal department.
*
* For further information, read the top-level Openvision
* copyright which is contained in the top-level MIT Kerberos
* copyright.
*
* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
*
*/
#include <rpc/rpc.h> /* SUNWresync121 XXX */
#include <kadm5/kadm_rpc.h>
#include <krb5.h>
#include <kadm5/admin.h>
#ifdef HAVE_MEMORY_H
#include <memory.h>
#endif
/* Default timeout can be changed using clnt_control() */
static struct timeval TIMEOUT = { 25, 0 };
generic_ret *
create_principal_2(cprinc_arg *argp, CLIENT *clnt)
{
static generic_ret clnt_res;
/* Solaris Kerberos */
if (clnt == NULL)
return (NULL);
memset((char *)&clnt_res, 0, sizeof(clnt_res));
if (clnt_call(clnt, CREATE_PRINCIPAL,
(xdrproc_t) xdr_cprinc_arg, (caddr_t) argp,
(xdrproc_t) xdr_generic_ret, (caddr_t) &clnt_res,
TIMEOUT) != RPC_SUCCESS) {
return (NULL);
}
return (&clnt_res);
}
generic_ret *
create_principal3_2(cprinc3_arg *argp, CLIENT *clnt)
{
static generic_ret clnt_res;
/* Solaris Kerberos */
if (clnt == NULL)
return (NULL);
memset((char *)&clnt_res, 0, sizeof(clnt_res));
if (clnt_call(clnt, CREATE_PRINCIPAL3,
(xdrproc_t) xdr_cprinc3_arg, (caddr_t) argp,
(xdrproc_t) xdr_generic_ret, (caddr_t) &clnt_res,
TIMEOUT) != RPC_SUCCESS) {
return (NULL);
}
return (&clnt_res);
}
generic_ret *
delete_principal_2(dprinc_arg *argp, CLIENT *clnt)
{
static generic_ret clnt_res;
/* Solaris Kerberos */
if (clnt == NULL)
return (NULL);
memset((char *)&clnt_res, 0, sizeof(clnt_res));
if (clnt_call(clnt, DELETE_PRINCIPAL,
(xdrproc_t) xdr_dprinc_arg, (caddr_t) argp,
(xdrproc_t) xdr_generic_ret, (caddr_t) &clnt_res,
TIMEOUT) != RPC_SUCCESS) {
return (NULL);
}
return (&clnt_res);
}
generic_ret *
modify_principal_2(mprinc_arg *argp, CLIENT *clnt)
{
static generic_ret clnt_res;
/* Solaris Kerberos */
if (clnt == NULL)
return (NULL);
memset((char *)&clnt_res, 0, sizeof(clnt_res));
if (clnt_call(clnt, MODIFY_PRINCIPAL,
(xdrproc_t) xdr_mprinc_arg, (caddr_t) argp,
(xdrproc_t) xdr_generic_ret, (caddr_t) &clnt_res,
TIMEOUT) != RPC_SUCCESS) {
return (NULL);
}
return (&clnt_res);
}
generic_ret *
rename_principal_2(rprinc_arg *argp, CLIENT *clnt)
{
static generic_ret clnt_res;
/* Solaris Kerberos */
if (clnt == NULL)
return (NULL);
memset((char *)&clnt_res, 0, sizeof(clnt_res));
if (clnt_call(clnt, RENAME_PRINCIPAL,
(xdrproc_t) xdr_rprinc_arg, (caddr_t) argp,
(xdrproc_t) xdr_generic_ret, (caddr_t) &clnt_res,
TIMEOUT) != RPC_SUCCESS) {
return (NULL);
}
return (&clnt_res);
}
gprinc_ret *
get_principal_2(gprinc_arg *argp, CLIENT *clnt)
{
static gprinc_ret clnt_res;
/* Solaris Kerberos */
if (clnt == NULL)
return (NULL);
memset((char *)&clnt_res, 0, sizeof(clnt_res));
if (clnt_call(clnt, GET_PRINCIPAL,
(xdrproc_t) xdr_gprinc_arg, (caddr_t) argp,
(xdrproc_t) xdr_gprinc_ret, (caddr_t) &clnt_res,
TIMEOUT) != RPC_SUCCESS) {
return (NULL);
}
return (&clnt_res);
}
gprincs_ret *
get_princs_2(gprincs_arg *argp, CLIENT *clnt)
{
static gprincs_ret clnt_res;
/* Solaris Kerberos */
if (clnt == NULL)
return (NULL);
memset((char *)&clnt_res, 0, sizeof(clnt_res));
if (clnt_call(clnt, GET_PRINCS,
(xdrproc_t) xdr_gprincs_arg, (caddr_t) argp,
(xdrproc_t) xdr_gprincs_ret, (caddr_t) &clnt_res,
TIMEOUT) != RPC_SUCCESS) {
return (NULL);
}
return (&clnt_res);
}
generic_ret *
chpass_principal_2(chpass_arg *argp, CLIENT *clnt)
{
static generic_ret clnt_res;
/* Solaris Kerberos */
if (clnt == NULL)
return (NULL);
memset((char *)&clnt_res, 0, sizeof(clnt_res));
if (clnt_call(clnt, CHPASS_PRINCIPAL,
(xdrproc_t) xdr_chpass_arg, (caddr_t) argp,
(xdrproc_t) xdr_generic_ret, (caddr_t) &clnt_res,
TIMEOUT) != RPC_SUCCESS) {
return (NULL);
}
return (&clnt_res);
}
generic_ret *
chpass_principal3_2(chpass3_arg *argp, CLIENT *clnt)
{
static generic_ret clnt_res;
/* Solaris Kerberos */
if (clnt == NULL)
return (NULL);
memset((char *)&clnt_res, 0, sizeof(clnt_res));
if (clnt_call(clnt, CHPASS_PRINCIPAL3,
(xdrproc_t) xdr_chpass3_arg, (caddr_t) argp,
(xdrproc_t) xdr_generic_ret, (caddr_t) &clnt_res,
TIMEOUT) != RPC_SUCCESS) {
return (NULL);
}
return (&clnt_res);
}
generic_ret *
setv4key_principal_2(setv4key_arg *argp, CLIENT *clnt)
{
static generic_ret clnt_res;
/* Solaris Kerberos */
if (clnt == NULL)
return (NULL);
memset((char *)&clnt_res, 0, sizeof(clnt_res));
if (clnt_call(clnt, SETV4KEY_PRINCIPAL,
(xdrproc_t) xdr_setv4key_arg, (caddr_t) argp,
(xdrproc_t) xdr_generic_ret, (caddr_t) &clnt_res,
TIMEOUT) != RPC_SUCCESS) {
return (NULL);
}
return (&clnt_res);
}
generic_ret *
setkey_principal_2(setkey_arg *argp, CLIENT *clnt)
{
static generic_ret clnt_res;
/* Solaris Kerberos */
if (clnt == NULL)
return (NULL);
memset((char *)&clnt_res, 0, sizeof(clnt_res));
if (clnt_call(clnt, SETKEY_PRINCIPAL,
(xdrproc_t) xdr_setkey_arg, (caddr_t) argp,
(xdrproc_t) xdr_generic_ret, (caddr_t) &clnt_res,
TIMEOUT) != RPC_SUCCESS) {
return (NULL);
}
return (&clnt_res);
}
generic_ret *
setkey_principal3_2(setkey3_arg *argp, CLIENT *clnt)
{
static generic_ret clnt_res;
/* Solaris Kerberos */
if (clnt == NULL)
return (NULL);
memset((char *)&clnt_res, 0, sizeof(clnt_res));
if (clnt_call(clnt, SETKEY_PRINCIPAL3,
(xdrproc_t) xdr_setkey3_arg, (caddr_t) argp,
(xdrproc_t) xdr_generic_ret, (caddr_t) &clnt_res,
TIMEOUT) != RPC_SUCCESS) {
return (NULL);
}
return (&clnt_res);
}
chrand_ret *
chrand_principal_2(chrand_arg *argp, CLIENT *clnt)
{
static chrand_ret clnt_res;
/* Solaris Kerberos */
if (clnt == NULL)
return (NULL);
memset((char *)&clnt_res, 0, sizeof(clnt_res));
if (clnt_call(clnt, CHRAND_PRINCIPAL,
(xdrproc_t) xdr_chrand_arg, (caddr_t) argp,
(xdrproc_t) xdr_chrand_ret, (caddr_t) &clnt_res,
TIMEOUT) != RPC_SUCCESS) {
return (NULL);
}
return (&clnt_res);
}
chrand_ret *
chrand_principal3_2(chrand3_arg *argp, CLIENT *clnt)
{
static chrand_ret clnt_res;
/* Solaris Kerberos */
if (clnt == NULL)
return (NULL);
memset((char *)&clnt_res, 0, sizeof(clnt_res));
if (clnt_call(clnt, CHRAND_PRINCIPAL3,
(xdrproc_t) xdr_chrand3_arg, (caddr_t) argp,
(xdrproc_t) xdr_chrand_ret, (caddr_t) &clnt_res,
TIMEOUT) != RPC_SUCCESS) {
return (NULL);
}
return (&clnt_res);
}
generic_ret *
create_policy_2(cpol_arg *argp, CLIENT *clnt)
{
static generic_ret clnt_res;
/* Solaris Kerberos */
if (clnt == NULL)
return (NULL);
memset((char *)&clnt_res, 0, sizeof(clnt_res));
if (clnt_call(clnt, CREATE_POLICY,
(xdrproc_t) xdr_cpol_arg, (caddr_t) argp,
(xdrproc_t) xdr_generic_ret, (caddr_t) &clnt_res,
TIMEOUT) != RPC_SUCCESS) {
return (NULL);
}
return (&clnt_res);
}
generic_ret *
delete_policy_2(dpol_arg *argp, CLIENT *clnt)
{
static generic_ret clnt_res;
/* Solaris Kerberos */
if (clnt == NULL)
return (NULL);
memset((char *)&clnt_res, 0, sizeof(clnt_res));
if (clnt_call(clnt, DELETE_POLICY,
(xdrproc_t) xdr_dpol_arg, (caddr_t) argp,
(xdrproc_t) xdr_generic_ret, (caddr_t) &clnt_res,
TIMEOUT) != RPC_SUCCESS) {
return (NULL);
}
return (&clnt_res);
}
generic_ret *
modify_policy_2(mpol_arg *argp, CLIENT *clnt)
{
static generic_ret clnt_res;
/* Solaris Kerberos */
if (clnt == NULL)
return (NULL);
memset((char *)&clnt_res, 0, sizeof(clnt_res));
if (clnt_call(clnt, MODIFY_POLICY,
(xdrproc_t) xdr_mpol_arg, (caddr_t) argp,
(xdrproc_t) xdr_generic_ret, (caddr_t) &clnt_res,
TIMEOUT) != RPC_SUCCESS) {
return (NULL);
}
return (&clnt_res);
}
gpol_ret *
get_policy_2(gpol_arg *argp, CLIENT *clnt)
{
static gpol_ret clnt_res;
/* Solaris Kerberos */
if (clnt == NULL)
return (NULL);
memset((char *)&clnt_res, 0, sizeof(clnt_res));
if (clnt_call(clnt, GET_POLICY,
(xdrproc_t) xdr_gpol_arg, (caddr_t) argp,
(xdrproc_t) xdr_gpol_ret, (caddr_t) &clnt_res,
TIMEOUT) != RPC_SUCCESS) {
return (NULL);
}
return (&clnt_res);
}
gpols_ret *
get_pols_2(gpols_arg *argp, CLIENT *clnt)
{
static gpols_ret clnt_res;
/* Solaris Kerberos */
if (clnt == NULL)
return (NULL);
memset((char *)&clnt_res, 0, sizeof(clnt_res));
if (clnt_call(clnt, GET_POLS,
(xdrproc_t) xdr_gpols_arg, (caddr_t) argp,
(xdrproc_t) xdr_gpols_ret, (caddr_t) &clnt_res,
TIMEOUT) != RPC_SUCCESS) {
return (NULL);
}
return (&clnt_res);
}
getprivs_ret *
get_privs_2(void *argp, CLIENT *clnt)
{
static getprivs_ret clnt_res;
/* Solaris Kerberos */
if (clnt == NULL)
return (NULL);
memset((char *)&clnt_res, 0, sizeof(clnt_res));
if (clnt_call(clnt, GET_PRIVS,
(xdrproc_t) xdr_u_int, (caddr_t) argp,
(xdrproc_t) xdr_getprivs_ret, (caddr_t) &clnt_res,
TIMEOUT) != RPC_SUCCESS) {
return (NULL);
}
return (&clnt_res);
}
generic_ret *
init_2(void *argp, CLIENT *clnt)
{
static generic_ret clnt_res;
/* Solaris Kerberos */
if (clnt == NULL)
return (NULL);
memset((char *)&clnt_res, 0, sizeof(clnt_res));
if (clnt_call(clnt, INIT,
(xdrproc_t) xdr_u_int, (caddr_t) argp,
(xdrproc_t) xdr_generic_ret, (caddr_t) &clnt_res,
TIMEOUT) != RPC_SUCCESS) {
return (NULL);
}
return (&clnt_res);
}
/*
* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
*
* Openvision retains the copyright to derivative works of
* this source code. Do *NOT* create a derivative of this
* source code before consulting with your legal department.
* Do *NOT* integrate *ANY* of this source code into another
* product before consulting with your legal department.
*
* For further information, read the top-level Openvision
* copyright which is contained in the top-level MIT Kerberos
* copyright.
*
* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
*
*/
#include <kadm5/admin.h>
#include "client_internal.h"
kadm5_ret_t kadm5_chpass_principal_util(void *server_handle,
krb5_principal princ,
char *new_pw,
char **ret_pw,
char *msg_ret,
unsigned int msg_len)
{
kadm5_server_handle_t handle = server_handle;
CHECK_HANDLE(server_handle);
return _kadm5_chpass_principal_util(handle, handle->lhandle, princ,
new_pw, ret_pw, msg_ret, msg_len);
}
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
*
* Openvision retains the copyright to derivative works of
* this source code. Do *NOT* create a derivative of this
* source code before consulting with your legal department.
* Do *NOT* integrate *ANY* of this source code into another
* product before consulting with your legal department.
*
* For further information, read the top-level Openvision
* copyright which is contained in the top-level MIT Kerberos
* copyright.
*
* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
*
*/
/*
* Copyright 1993 OpenVision Technologies, Inc., All Rights Reserved
*
* $Header$
*/
#if !defined(lint) && !defined(__CODECENTER__)
static char *rcsid = "$Header$";
#endif
#include <rpc/rpc.h> /* SUNWresync121 XXX */
#include <kadm5/admin.h>
#include <kadm5/kadm_rpc.h>
#include "client_internal.h"
#include <stdlib.h>
#include <string.h>
#include <errno.h>
kadm5_ret_t
kadm5_create_policy(void *server_handle,
kadm5_policy_ent_t policy, long mask)
{
cpol_arg arg;
generic_ret *r;
kadm5_server_handle_t handle = server_handle;
CHECK_HANDLE(server_handle);
if(policy == (kadm5_policy_ent_t) NULL)
return EINVAL;
arg.mask = mask;
arg.api_version = handle->api_version;
memcpy(&arg.rec, policy, sizeof(kadm5_policy_ent_rec));
r = create_policy_2(&arg, handle->clnt);
if(r == NULL)
return KADM5_RPC_ERROR;
return r->code;
}
kadm5_ret_t
kadm5_delete_policy(void *server_handle, char *name)
{
dpol_arg arg;
generic_ret *r;
kadm5_server_handle_t handle = server_handle;
CHECK_HANDLE(server_handle);
if(name == NULL)
return EINVAL;
arg.name = name;
arg.api_version = handle->api_version;
r = delete_policy_2(&arg, handle->clnt);
if(r == NULL)
return KADM5_RPC_ERROR;
return r->code;
}
kadm5_ret_t
kadm5_modify_policy(void *server_handle,
kadm5_policy_ent_t policy, long mask)
{
mpol_arg arg;
generic_ret *r;
kadm5_server_handle_t handle = server_handle;
CHECK_HANDLE(server_handle);
if(policy == (kadm5_policy_ent_t) NULL)
return EINVAL;
arg.mask = mask;
arg.api_version = handle->api_version;
memcpy(&arg.rec, policy, sizeof(kadm5_policy_ent_rec));
r = modify_policy_2(&arg, handle->clnt);
if(r == NULL)
return KADM5_RPC_ERROR;
return r->code;
}
kadm5_ret_t
kadm5_get_policy(void *server_handle, char *name, kadm5_policy_ent_t ent)
{
gpol_arg arg;
gpol_ret *r;
kadm5_server_handle_t handle = server_handle;
CHECK_HANDLE(server_handle);
arg.name = name;
arg.api_version = handle->api_version;
if(name == NULL)
return EINVAL;
r = get_policy_2(&arg, handle->clnt);
if(r == NULL)
return KADM5_RPC_ERROR;
if (handle->api_version == KADM5_API_VERSION_1) {
kadm5_policy_ent_t *entp;
entp = (kadm5_policy_ent_t *) ent;
if(r->code == 0) {
if (!(*entp = (kadm5_policy_ent_t)
malloc(sizeof(kadm5_policy_ent_rec))))
return ENOMEM;
memcpy(*entp, &r->rec, sizeof(**entp));
} else {
*entp = NULL;
}
} else {
if (r->code == 0)
memcpy(ent, &r->rec, sizeof(r->rec));
}
return r->code;
}
kadm5_ret_t
kadm5_get_policies(void *server_handle,
char *exp, char ***pols, int *count)
{
gpols_arg arg;
gpols_ret *r;
kadm5_server_handle_t handle = server_handle;
CHECK_HANDLE(server_handle);
if(pols == NULL || count == NULL)
return EINVAL;
arg.exp = exp;
arg.api_version = handle->api_version;
r = get_pols_2(&arg, handle->clnt);
if(r == NULL)
return KADM5_RPC_ERROR;
if(r->code == 0) {
*count = r->count;
*pols = r->pols;
} else {
*count = 0;
*pols = NULL;
}
return r->code;
}
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
*
* Openvision retains the copyright to derivative works of
* this source code. Do *NOT* create a derivative of this
* source code before consulting with your legal department.
* Do *NOT* integrate *ANY* of this source code into another
* product before consulting with your legal department.
*
* For further information, read the top-level Openvision
* copyright which is contained in the top-level MIT Kerberos
* copyright.
*
* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
*
*/
/*
* Copyright 1993 OpenVision Technologies, Inc., All Rights Reserved.
*
* $Id: clnt_privs.c 18130 2006-06-14 21:42:02Z raeburn $
* $Source$
*
*/
#if !defined(lint) && !defined(__CODECENTER__)
static char *rcsid = "$Header$";
#endif
#include <rpc/rpc.h> /* SUNWresync121 XXX */
#include <kadm5/admin.h>
#include <kadm5/kadm_rpc.h>
#include "client_internal.h"
kadm5_ret_t kadm5_get_privs(void *server_handle, long *privs)
{
getprivs_ret *r;
kadm5_server_handle_t handle = server_handle;
r = get_privs_2(&handle->api_version, handle->clnt);
if (r == NULL)
return KADM5_RPC_ERROR;
else if (r->code == KADM5_OK)
*privs = r->privs;
return r->code;
}
/*
* Please do not edit this file.
* It was generated using rpcgen.
*/
#ifndef _IPROP_H_RPCGEN
#define _IPROP_H_RPCGEN
#include <rpc/rpc.h>
typedef struct {
u_int utf8str_t_len;
char *utf8str_t_val;
} utf8str_t;
typedef uint32_t kdb_sno_t;
struct kdbe_time_t {
uint32_t seconds;
uint32_t useconds;
};
typedef struct kdbe_time_t kdbe_time_t;
struct kdbe_key_t {
int32_t k_ver;
int32_t k_kvno;
struct {
u_int k_enctype_len;
int32_t *k_enctype_val;
} k_enctype;
struct {
u_int k_contents_len;
utf8str_t *k_contents_val;
} k_contents;
};
typedef struct kdbe_key_t kdbe_key_t;
struct kdbe_data_t {
int32_t k_magic;
utf8str_t k_data;
};
typedef struct kdbe_data_t kdbe_data_t;
struct kdbe_princ_t {
utf8str_t k_realm;
struct {
u_int k_components_len;
kdbe_data_t *k_components_val;
} k_components;
int32_t k_nametype;
};
typedef struct kdbe_princ_t kdbe_princ_t;
struct kdbe_tl_t {
int16_t tl_type;
struct {
u_int tl_data_len;
char *tl_data_val;
} tl_data;
};
typedef struct kdbe_tl_t kdbe_tl_t;
typedef struct {
u_int kdbe_pw_hist_t_len;
kdbe_key_t *kdbe_pw_hist_t_val;
} kdbe_pw_hist_t;
enum kdbe_attr_type_t {
AT_ATTRFLAGS = 0,
AT_MAX_LIFE = 1,
AT_MAX_RENEW_LIFE = 2,
AT_EXP = 3,
AT_PW_EXP = 4,
AT_LAST_SUCCESS = 5,
AT_LAST_FAILED = 6,
AT_FAIL_AUTH_COUNT = 7,
AT_PRINC = 8,
AT_KEYDATA = 9,
AT_TL_DATA = 10,
AT_LEN = 11,
AT_MOD_PRINC = 12,
AT_MOD_TIME = 13,
AT_MOD_WHERE = 14,
AT_PW_LAST_CHANGE = 15,
AT_PW_POLICY = 16,
AT_PW_POLICY_SWITCH = 17,
AT_PW_HIST_KVNO = 18,
AT_PW_HIST = 19
};
typedef enum kdbe_attr_type_t kdbe_attr_type_t;
struct kdbe_val_t {
kdbe_attr_type_t av_type;
union {
uint32_t av_attrflags;
uint32_t av_max_life;
uint32_t av_max_renew_life;
uint32_t av_exp;
uint32_t av_pw_exp;
uint32_t av_last_success;
uint32_t av_last_failed;
uint32_t av_fail_auth_count;
kdbe_princ_t av_princ;
struct {
u_int av_keydata_len;
kdbe_key_t *av_keydata_val;
} av_keydata;
struct {
u_int av_tldata_len;
kdbe_tl_t *av_tldata_val;
} av_tldata;
int16_t av_len;
uint32_t av_pw_last_change;
kdbe_princ_t av_mod_princ;
uint32_t av_mod_time;
utf8str_t av_mod_where;
utf8str_t av_pw_policy;
bool_t av_pw_policy_switch;
uint32_t av_pw_hist_kvno;
struct {
u_int av_pw_hist_len;
kdbe_pw_hist_t *av_pw_hist_val;
} av_pw_hist;
struct {
u_int av_extension_len;
char *av_extension_val;
} av_extension;
} kdbe_val_t_u;
};
typedef struct kdbe_val_t kdbe_val_t;
typedef struct {
u_int kdbe_t_len;
kdbe_val_t *kdbe_t_val;
} kdbe_t;
struct kdb_incr_update_t {
utf8str_t kdb_princ_name;
kdb_sno_t kdb_entry_sno;
kdbe_time_t kdb_time;
kdbe_t kdb_update;
bool_t kdb_deleted;
bool_t kdb_commit;
struct {
u_int kdb_kdcs_seen_by_len;
utf8str_t *kdb_kdcs_seen_by_val;
} kdb_kdcs_seen_by;
struct {
u_int kdb_futures_len;
char *kdb_futures_val;
} kdb_futures;
};
typedef struct kdb_incr_update_t kdb_incr_update_t;
typedef struct {
u_int kdb_ulog_t_len;
kdb_incr_update_t *kdb_ulog_t_val;
} kdb_ulog_t;
enum update_status_t {
UPDATE_OK = 0,
UPDATE_ERROR = 1,
UPDATE_FULL_RESYNC_NEEDED = 2,
UPDATE_BUSY = 3,
UPDATE_NIL = 4,
UPDATE_PERM_DENIED = 5
};
typedef enum update_status_t update_status_t;
struct kdb_last_t {
kdb_sno_t last_sno;
kdbe_time_t last_time;
};
typedef struct kdb_last_t kdb_last_t;
struct kdb_incr_result_t {
kdb_last_t lastentry;
kdb_ulog_t updates;
update_status_t ret;
};
typedef struct kdb_incr_result_t kdb_incr_result_t;
struct kdb_fullresync_result_t {
kdb_last_t lastentry;
update_status_t ret;
};
typedef struct kdb_fullresync_result_t kdb_fullresync_result_t;
#define KRB5_IPROP_PROG 100423
#define KRB5_IPROP_VERS 1
#define IPROP_NULL 0
extern void * iprop_null_1();
#define IPROP_GET_UPDATES 1
extern kdb_incr_result_t * iprop_get_updates_1();
#define IPROP_FULL_RESYNC 2
extern kdb_fullresync_result_t * iprop_full_resync_1();
extern int krb5_iprop_prog_1_freeresult();
/* the xdr functions */
extern bool_t xdr_utf8str_t();
extern bool_t xdr_kdb_sno_t();
extern bool_t xdr_kdbe_time_t();
extern bool_t xdr_kdbe_key_t();
extern bool_t xdr_kdbe_data_t();
extern bool_t xdr_kdbe_princ_t();
extern bool_t xdr_kdbe_tl_t();
extern bool_t xdr_kdbe_pw_hist_t();
extern bool_t xdr_kdbe_attr_type_t();
extern bool_t xdr_kdbe_val_t();
extern bool_t xdr_kdbe_t();
extern bool_t xdr_kdb_incr_update_t();
extern bool_t xdr_kdb_ulog_t();
extern bool_t xdr_update_status_t();
extern bool_t xdr_kdb_last_t();
extern bool_t xdr_kdb_incr_result_t();
extern bool_t xdr_kdb_fullresync_result_t();
#endif /* !_IPROP_H_RPCGEN */
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* lib/kadm/logger.c
*
* Copyright 1995 by the Massachusetts Institute of Technology.
* All Rights Reserved.
*
* Export of this software from the United States of America may
* require a specific license from the United States Government.
* It is the responsibility of any person or organization contemplating
* export to obtain such a license before exporting.
*
* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
* distribute this software and its documentation for any purpose and
* without fee is hereby granted, 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. Furthermore if you modify this software you must label
* your software as modified software and not distribute it in such a
* fashion that it might be confused with the original M.I.T. software.
* 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.
*
*/
/* KADM5 wants non-syslog log files to contain syslog-like entries */
#define VERBOSE_LOGS
/*
* logger.c - Handle logging functions for those who want it.
*/
#include "k5-int.h"
#include "adm_proto.h"
#include "com_err.h"
#include <stdio.h>
#include <ctype.h>
#include <ctype.h>
#ifdef HAVE_SYSLOG_H
#include <syslog.h>
#endif /* HAVE_SYSLOG_H */
#ifdef HAVE_STDARG_H
#include <stdarg.h>
#else /* HAVE_STDARG_H */
#include <varargs.h>
#endif /* HAVE_STDARG_H */
#include <libintl.h>
#include <sys/types.h>
#include <sys/stat.h>
#define KRB5_KLOG_MAX_ERRMSG_SIZE 2048
#ifndef MAXHOSTNAMELEN
#define MAXHOSTNAMELEN 256
#endif /* MAXHOSTNAMELEN */
#define LSPEC_PARSE_ERR_1 1
#define LSPEC_PARSE_ERR_2 2
#define LOG_FILE_ERR 3
#define LOG_DEVICE_ERR 4
#define LOG_UFO_STRING 5
#define LOG_EMERG_STRING 6
#define LOG_ALERT_STRING 7
#define LOG_CRIT_STRING 8
#define LOG_ERR_STRING 9
#define LOG_WARNING_STRING 10
#define LOG_NOTICE_STRING 11
#define LOG_INFO_STRING 12
#define LOG_DEBUG_STRING 13
/* This is to assure that we have at least one match in the syslog stuff */
/*
static const char LSPEC_PARSE_ERR_1[] = "%s: cannot parse <%s>\n";
static const char LSPEC_PARSE_ERR_2[] = "%s: warning - logging entry syntax error\n";
static const char LOG_FILE_ERR[] = "%s: error writing to %s\n";
static const char LOG_DEVICE_ERR[] = "%s: error writing to %s device\n";
static const char LOG_UFO_STRING[] = "???";
static const char LOG_EMERG_STRING[] = "EMERGENCY";
static const char LOG_ALERT_STRING[] = "ALERT";
static const char LOG_CRIT_STRING[] = "CRITICAL";
static const char LOG_ERR_STRING[] = "Error";
static const char LOG_WARNING_STRING[] = "Warning";
static const char LOG_NOTICE_STRING[] = "Notice";
static const char LOG_INFO_STRING[] = "info";
static const char LOG_DEBUG_STRING[] = "debug";
*/
const char *
krb5_log_error_table(long errorno) {
switch (errorno) {
case LSPEC_PARSE_ERR_1:
return(gettext("%s: cannot parse <%s>\n"));
case LSPEC_PARSE_ERR_2:
return(gettext("%s: warning - logging entry syntax error\n"));
case LOG_FILE_ERR:
return(gettext("%s: error writing to %s\n"));
case LOG_DEVICE_ERR:
return(gettext("%s: error writing to %s device\n"));
case LOG_UFO_STRING:
return(gettext("???"));
case LOG_EMERG_STRING:
return(gettext("EMERGENCY"));
case LOG_ALERT_STRING:
return(gettext("ALERT"));
case LOG_CRIT_STRING:
return(gettext("CRITICAL"));
case LOG_ERR_STRING:
return(gettext("Error"));
case LOG_WARNING_STRING:
return(gettext("Warning"));
case LOG_NOTICE_STRING:
return(gettext("Notice"));
case LOG_INFO_STRING:
case LOG_DEBUG_STRING:
default:
return(gettext("info"));
}
}
/*
* Output logging.
*
* Output logging is now controlled by the configuration file. We can specify
* the following syntaxes under the [logging]->entity specification.
* FILE<opentype><pathname>
* SYSLOG[=<severity>[:<facility>]]
* STDERR
* CONSOLE
* DEVICE=<device-spec>
*
* Where:
* <opentype> is ":" for open/append, "=" for open/create.
* <pathname> is a valid path name.
* <severity> is one of: (default = ERR)
* EMERG
* ALERT
* CRIT
* ERR
* WARNING
* NOTICE
* INFO
* DEBUG
* <facility> is one of: (default = AUTH)
* KERN
* USER
* MAIL
* DAEMON
* AUTH
* LPR
* NEWS
* UUCP
* AUDIT
* CRON
* LOCAL0..LOCAL7
* <device-spec> is a valid device specification.
*/
struct log_entry {
enum log_type { K_LOG_FILE,
K_LOG_SYSLOG,
K_LOG_STDERR,
K_LOG_CONSOLE,
K_LOG_DEVICE,
K_LOG_NONE } log_type;
krb5_pointer log_2free;
union log_union {
struct log_file {
FILE *lf_filep;
char *lf_fname;
char *lf_fopen_mode; /* "a+" or "w" */
#define K_LOG_DEF_FILE_ROTATE_PERIOD -1 /* never */
#define K_LOG_DEF_FILE_ROTATE_VERSIONS 0 /* no versions */
time_t lf_rotate_period;
time_t lf_last_rotated;
int lf_rotate_versions;
} log_file;
struct log_syslog {
int ls_facility;
int ls_severity;
} log_syslog;
struct log_device {
FILE *ld_filep;
char *ld_devname;
} log_device;
} log_union;
};
#define lfu_filep log_union.log_file.lf_filep
#define lfu_fname log_union.log_file.lf_fname
#define lfu_fopen_mode log_union.log_file.lf_fopen_mode
#define lfu_rotate_period log_union.log_file.lf_rotate_period
#define lfu_last_rotated log_union.log_file.lf_last_rotated
#define lfu_rotate_versions log_union.log_file.lf_rotate_versions
#define lsu_facility log_union.log_syslog.ls_facility
#define lsu_severity log_union.log_syslog.ls_severity
#define ldu_filep log_union.log_device.ld_filep
#define ldu_devname log_union.log_device.ld_devname
struct log_control {
struct log_entry *log_entries;
int log_nentries;
char *log_whoami;
char *log_hostname;
krb5_boolean log_opened;
};
static struct log_control log_control = {
(struct log_entry *) NULL,
0,
(char *) NULL,
(char *) NULL,
0
};
static struct log_entry def_log_entry;
/*
* These macros define any special processing that needs to happen for
* devices. For unix, of course, this is hardly anything.
*/
#define DEVICE_OPEN(d, m) fopen(d, m)
#define CONSOLE_OPEN(m) fopen("/dev/console", m)
#define DEVICE_PRINT(f, m) ((fprintf(f, "%s\r\n", m) >= 0) ? \
(fflush(f), 0) : \
-1)
#define DEVICE_CLOSE(d) fclose(d)
/*
* klog_rotate() - roate a log file if we have specified rotation
* parameters in krb5.conf.
*/
static void
klog_rotate(struct log_entry *le)
{
time_t t;
int i;
char *name_buf1;
char *name_buf2;
char *old_name;
char *new_name;
char *tmp;
FILE *fp;
int num_vers;
mode_t old_umask;
/*
* By default we don't rotate.
*/
if (le->lfu_rotate_period == K_LOG_DEF_FILE_ROTATE_PERIOD)
return;
t = time(0);
if (t >= le->lfu_last_rotated + le->lfu_rotate_period) {
/*
* The N log file versions will be renamed X.N-1 X.N-2, ... X.0.
* So the allocate file name buffers that can the version
* number extensions.
* 32 extra bytes is plenty.
*/
name_buf1 = malloc(strlen(le->lfu_fname) + 32);
if (name_buf1 == NULL)
return;
name_buf2 = malloc(strlen(le->lfu_fname) + 32);
if (name_buf2 == NULL) {
free(name_buf1);
return;
}
old_name = name_buf1;
new_name = name_buf2;
/*
* If there N versions, then the first one has file extension
* of N-1.
*/
(void) sprintf(new_name, "%s.%d", le->lfu_fname,
le->lfu_rotate_versions - 1);
/*
* Rename file.N-2 to file.N-1, file.N-3 to file.N-2, ...
* file.0 to file.1
*/
for (i = le->lfu_rotate_versions - 1; i > 0; i--) {
(void) sprintf(old_name, "%s.%d", le->lfu_fname, i - 1);
(void) rename(old_name, new_name);
/*
* swap old name and new name. This way,
* on the next iteration, new_name.X
* becomes new_name.X-1.
*/
tmp = old_name;
old_name = new_name;
new_name = tmp;
}
old_name = le->lfu_fname;
(void) rename(old_name, new_name);
/*
* Even though we don't know yet if the fopen()
* of the log file will succeed, we mark the log
* as rotated. This is so we don't repeatably
* rotate file.N-2 to file.N-1 ... etc without
* waiting for the rotate period to elapse.
*/
le->lfu_last_rotated = t;
/*
* Default log file creation mode should be read-only
* by owner(root), but the admin can override with
* chmod(1) if desired.
*/
old_umask = umask(077);
fp = fopen(old_name, le->lfu_fopen_mode);
umask(old_umask);
if (fp != NULL) {
(void) fclose(le->lfu_filep);
le->lfu_filep = fp;
/*
* If the version parameter in krb5.conf was
* 0, then we take this to mean that rotating the
* log file will cause us to dispose of the
* old one, and created a new one. We have just
* renamed the old one to file.-1, so remove it.
*/
if (le->lfu_rotate_versions <= 0)
(void) unlink(new_name);
} else {
fprintf(stderr,
gettext("During rotate, couldn't open log file %s: %s\n"),
old_name, error_message(errno));
/*
* Put it back.
*/
(void) rename(new_name, old_name);
}
free(name_buf1);
free(name_buf2);
}
}
/*
* klog_com_err_proc() - Handle com_err(3) messages as specified by the
* profile.
*/
static krb5_context err_context;
static void
klog_com_err_proc(const char *whoami, long code, const char *format, va_list ap)
{
char outbuf[KRB5_KLOG_MAX_ERRMSG_SIZE];
int lindex;
const char *actual_format;
#ifdef HAVE_SYSLOG
int log_pri = -1;
#endif /* HAVE_SYSLOG */
char *cp;
char *syslogp;
/* Make the header */
sprintf(outbuf, "%s: ", whoami);
/*
* Squirrel away address after header for syslog since syslog makes
* a header
*/
syslogp = &outbuf[strlen(outbuf)];
/* If reporting an error message, separate it. */
if (code) {
const char *emsg;
outbuf[sizeof(outbuf) - 1] = '\0';
emsg = krb5_get_error_message (err_context, code);
strncat(outbuf, emsg, sizeof(outbuf) - 1 - strlen(outbuf));
strncat(outbuf, " - ", sizeof(outbuf) - 1 - strlen(outbuf));
krb5_free_error_message(err_context, emsg);
}
cp = &outbuf[strlen(outbuf)];
actual_format = format;
#ifdef HAVE_SYSLOG
/*
* This is an unpleasant hack. If the first character is less than
* 8, then we assume that it is a priority.
*
* Since it is not guaranteed that there is a direct mapping between
* syslog priorities (e.g. Ultrix and old BSD), we resort to this
* intermediate representation.
*/
if ((((unsigned char) *format) > 0) && (((unsigned char) *format) <= 8)) {
actual_format = (format + 1);
switch ((unsigned char) *format) {
#ifdef LOG_EMERG
case 1:
log_pri = LOG_EMERG;
break;
#endif /* LOG_EMERG */
#ifdef LOG_ALERT
case 2:
log_pri = LOG_ALERT;
break;
#endif /* LOG_ALERT */
#ifdef LOG_CRIT
case 3:
log_pri = LOG_CRIT;
break;
#endif /* LOG_CRIT */
default:
case 4:
log_pri = LOG_ERR;
break;
#ifdef LOG_WARNING
case 5:
log_pri = LOG_WARNING;
break;
#endif /* LOG_WARNING */
#ifdef LOG_NOTICE
case 6:
log_pri = LOG_NOTICE;
break;
#endif /* LOG_NOTICE */
#ifdef LOG_INFO
case 7:
log_pri = LOG_INFO;
break;
#endif /* LOG_INFO */
#ifdef LOG_DEBUG
case 8:
log_pri = LOG_DEBUG;
break;
#endif /* LOG_DEBUG */
}
}
#endif /* HAVE_SYSLOG */
/* Now format the actual message */
#if HAVE_VSNPRINTF
vsnprintf(cp, sizeof(outbuf) - (cp - outbuf), actual_format, ap);
#elif HAVE_VSPRINTF
vsprintf(cp, actual_format, ap);
#else /* HAVE_VSPRINTF */
sprintf(cp, actual_format, ((int *) ap)[0], ((int *) ap)[1],
((int *) ap)[2], ((int *) ap)[3],
((int *) ap)[4], ((int *) ap)[5]);
#endif /* HAVE_VSPRINTF */
/*
* Now that we have the message formatted, perform the output to each
* logging specification.
*/
for (lindex = 0; lindex < log_control.log_nentries; lindex++) {
switch (log_control.log_entries[lindex].log_type) {
case K_LOG_FILE:
klog_rotate(&log_control.log_entries[lindex]);
/*FALLTHRU*/
case K_LOG_STDERR:
/*
* Files/standard error.
*/
if (fprintf(log_control.log_entries[lindex].lfu_filep, "%s\n",
outbuf) < 0) {
/* Attempt to report error */
fprintf(stderr, krb5_log_error_table(LOG_FILE_ERR), whoami,
log_control.log_entries[lindex].lfu_fname);
}
else {
fflush(log_control.log_entries[lindex].lfu_filep);
}
break;
case K_LOG_CONSOLE:
case K_LOG_DEVICE:
/*
* Devices (may need special handling)
*/
if (DEVICE_PRINT(log_control.log_entries[lindex].ldu_filep,
outbuf) < 0) {
/* Attempt to report error */
fprintf(stderr, krb5_log_error_table(LOG_DEVICE_ERR), whoami,
log_control.log_entries[lindex].ldu_devname);
}
break;
#ifdef HAVE_SYSLOG
case K_LOG_SYSLOG:
/*
* System log.
*/
/*
* If we have specified a priority through our hackery, then
* use it, otherwise use the default.
*/
if (log_pri >= 0)
log_pri |= log_control.log_entries[lindex].lsu_facility;
else
log_pri = log_control.log_entries[lindex].lsu_facility |
log_control.log_entries[lindex].lsu_severity;
/* Log the message with our header trimmed off */
syslog(log_pri, syslogp);
break;
#endif /* HAVE_SYSLOG */
default:
break;
}
}
}
/*
* krb5_klog_init() - Initialize logging.
*
* This routine parses the syntax described above to specify destinations for
* com_err(3) or krb5_klog_syslog() messages generated by the caller.
*
* Parameters:
* kcontext - Kerberos context.
* ename - Entity name as it is to appear in the profile.
* whoami - Entity name as it is to appear in error output.
* do_com_err - Take over com_err(3) processing.
*
* Implicit inputs:
* stderr - This is where STDERR output goes.
*
* Implicit outputs:
* log_nentries - Number of log entries, both valid and invalid.
* log_control - List of entries (log_nentries long) which contains
* data for klog_com_err_proc() to use to determine
* where/how to send output.
*/
krb5_error_code
krb5_klog_init(krb5_context kcontext, char *ename, char *whoami, krb5_boolean do_com_err)
{
const char *logging_profent[3];
const char *logging_defent[3];
char **logging_specs;
int i, ngood;
char *cp, *cp2;
char savec = '\0';
int error;
int do_openlog, log_facility;
FILE *f;
mode_t old_umask;
/* Initialize */
do_openlog = 0;
log_facility = 0;
err_context = kcontext;
/*
* Look up [logging]-><ename> in the profile. If that doesn't
* succeed, then look for [logging]->default.
*/
logging_profent[0] = "logging";
logging_profent[1] = ename;
logging_profent[2] = (char *) NULL;
logging_defent[0] = "logging";
logging_defent[1] = "default";
logging_defent[2] = (char *) NULL;
logging_specs = (char **) NULL;
ngood = 0;
log_control.log_nentries = 0;
if (!profile_get_values(kcontext->profile,
logging_profent,
&logging_specs) ||
!profile_get_values(kcontext->profile,
logging_defent,
&logging_specs)) {
/*
* We have a match, so we first count the number of elements
*/
for (log_control.log_nentries = 0;
logging_specs[log_control.log_nentries];
log_control.log_nentries++);
/*
* Now allocate our structure.
*/
log_control.log_entries = (struct log_entry *)
malloc(log_control.log_nentries * sizeof(struct log_entry));
if (log_control.log_entries) {
/*
* Scan through the list.
*/
for (i=0; i<log_control.log_nentries; i++) {
log_control.log_entries[i].log_type = K_LOG_NONE;
log_control.log_entries[i].log_2free = logging_specs[i];
/*
* The format is:
* <whitespace><data><whitespace>
* so, trim off the leading and trailing whitespace here.
*/
for (cp = logging_specs[i]; isspace((int) *cp); cp++);
for (cp2 = &logging_specs[i][strlen(logging_specs[i])-1];
isspace((int) *cp2); cp2--);
cp2++;
*cp2 = '\0';
/*
* Is this a file?
*/
if (!strncasecmp(cp, "FILE", 4)) {
/*
* Check for append/overwrite, then open the file.
*/
if (cp[4] == ':' || cp[4] == '=') {
log_control.log_entries[i].lfu_fopen_mode =
(cp[4] == ':') ? "a+F" : "wF";
old_umask = umask(077);
f = fopen(&cp[5],
log_control.log_entries[i].lfu_fopen_mode);
umask(old_umask);
if (f) {
char rotate_kw[128];
log_control.log_entries[i].lfu_filep = f;
log_control.log_entries[i].log_type = K_LOG_FILE;
log_control.log_entries[i].lfu_fname = &cp[5];
log_control.log_entries[i].lfu_rotate_period =
K_LOG_DEF_FILE_ROTATE_PERIOD;
log_control.log_entries[i].lfu_rotate_versions =
K_LOG_DEF_FILE_ROTATE_VERSIONS;
log_control.log_entries[i].lfu_last_rotated =
time(0);
/*
* Now parse for ename_"rotate" = {
* period = XXX
* versions = 10
* }
*/
if (strlen(ename) + strlen("_rotate") <
sizeof (rotate_kw)) {
char *time;
krb5_deltat dt;
int vers;
strcpy(rotate_kw, ename);
strcat(rotate_kw, "_rotate");
if (!profile_get_string(kcontext->profile,
"logging", rotate_kw, "period",
NULL, &time)) {
if (time != NULL) {
if (!krb5_string_to_deltat(time,
&dt)) {
log_control.log_entries[i].lfu_rotate_period =
(time_t) dt;
}
free(time);
}
}
if (!profile_get_integer(
kcontext->profile, "logging",
rotate_kw, "versions",
K_LOG_DEF_FILE_ROTATE_VERSIONS,
&vers)) {
log_control.log_entries[i].lfu_rotate_versions = vers;
}
}
} else {
fprintf(stderr, gettext("Couldn't open log file %s: %s\n"),
&cp[5], error_message(errno));
continue;
}
}
}
#ifdef HAVE_SYSLOG
/*
* Is this a syslog?
*/
else if (!strncasecmp(cp, "SYSLOG", 6)) {
error = 0;
log_control.log_entries[i].lsu_facility = LOG_AUTH;
log_control.log_entries[i].lsu_severity = LOG_ERR;
/*
* Is there a severify specified?
*/
if (cp[6] == ':') {
/*
* Find the end of the severity.
*/
cp2 = strchr(&cp[7], ':');
if (cp2) {
savec = *cp2;
*cp2 = '\0';
cp2++;
}
/*
* Match a severity.
*/
if (!strcasecmp(&cp[7], "ERR")) {
log_control.log_entries[i].lsu_severity = LOG_ERR;
}
#ifdef LOG_EMERG
else if (!strcasecmp(&cp[7], "EMERG")) {
log_control.log_entries[i].lsu_severity =
LOG_EMERG;
}
#endif /* LOG_EMERG */
#ifdef LOG_ALERT
else if (!strcasecmp(&cp[7], "ALERT")) {
log_control.log_entries[i].lsu_severity =
LOG_ALERT;
}
#endif /* LOG_ALERT */
#ifdef LOG_CRIT
else if (!strcasecmp(&cp[7], "CRIT")) {
log_control.log_entries[i].lsu_severity = LOG_CRIT;
}
#endif /* LOG_CRIT */
#ifdef LOG_WARNING
else if (!strcasecmp(&cp[7], "WARNING")) {
log_control.log_entries[i].lsu_severity =
LOG_WARNING;
}
#endif /* LOG_WARNING */
#ifdef LOG_NOTICE
else if (!strcasecmp(&cp[7], "NOTICE")) {
log_control.log_entries[i].lsu_severity =
LOG_NOTICE;
}
#endif /* LOG_NOTICE */
#ifdef LOG_INFO
else if (!strcasecmp(&cp[7], "INFO")) {
log_control.log_entries[i].lsu_severity = LOG_INFO;
}
#endif /* LOG_INFO */
#ifdef LOG_DEBUG
else if (!strcasecmp(&cp[7], "DEBUG")) {
log_control.log_entries[i].lsu_severity =
LOG_DEBUG;
}
#endif /* LOG_DEBUG */
else
error = 1;
/*
* If there is a facility present, then parse that.
*/
if (cp2) {
if (!strcasecmp(cp2, "AUTH")) {
log_control.log_entries[i].lsu_facility = LOG_AUTH;
}
else if (!strcasecmp(cp2, "KERN")) {
log_control.log_entries[i].lsu_facility = LOG_KERN;
}
else if (!strcasecmp(cp2, "USER")) {
log_control.log_entries[i].lsu_facility = LOG_USER;
}
else if (!strcasecmp(cp2, "MAIL")) {
log_control.log_entries[i].lsu_facility = LOG_MAIL;
}
else if (!strcasecmp(cp2, "DAEMON")) {
log_control.log_entries[i].lsu_facility = LOG_DAEMON;
}
else if (!strcasecmp(cp2, "LPR")) {
log_control.log_entries[i].lsu_facility = LOG_LPR;
}
else if (!strcasecmp(cp2, "NEWS")) {
log_control.log_entries[i].lsu_facility = LOG_NEWS;
}
else if (!strcasecmp(cp2, "UUCP")) {
log_control.log_entries[i].lsu_facility = LOG_UUCP;
}
else if (!strcasecmp(cp2, "CRON")) {
log_control.log_entries[i].lsu_facility = LOG_CRON;
}
else if (!strcasecmp(cp2, "AUDIT")) {
log_control.log_entries[i].lsu_facility = LOG_AUDIT;
}
else if (!strcasecmp(cp2, "LOCAL0")) {
log_control.log_entries[i].lsu_facility = LOG_LOCAL0;
}
else if (!strcasecmp(cp2, "LOCAL1")) {
log_control.log_entries[i].lsu_facility = LOG_LOCAL1;
}
else if (!strcasecmp(cp2, "LOCAL2")) {
log_control.log_entries[i].lsu_facility = LOG_LOCAL2;
}
else if (!strcasecmp(cp2, "LOCAL3")) {
log_control.log_entries[i].lsu_facility = LOG_LOCAL3;
}
else if (!strcasecmp(cp2, "LOCAL4")) {
log_control.log_entries[i].lsu_facility = LOG_LOCAL4;
}
else if (!strcasecmp(cp2, "LOCAL5")) {
log_control.log_entries[i].lsu_facility = LOG_LOCAL5;
}
else if (!strcasecmp(cp2, "LOCAL6")) {
log_control.log_entries[i].lsu_facility = LOG_LOCAL6;
}
else if (!strcasecmp(cp2, "LOCAL7")) {
log_control.log_entries[i].lsu_facility = LOG_LOCAL7;
}
cp2--;
*cp2 = savec;
}
}
if (!error) {
log_control.log_entries[i].log_type = K_LOG_SYSLOG;
do_openlog = 1;
log_facility = log_control.log_entries[i].lsu_facility;
}
}
#endif /* HAVE_SYSLOG */
/*
* Is this a standard error specification?
*/
else if (!strcasecmp(cp, "STDERR")) {
log_control.log_entries[i].lfu_filep =
fdopen(fileno(stderr), "a+F");
if (log_control.log_entries[i].lfu_filep) {
log_control.log_entries[i].log_type = K_LOG_STDERR;
log_control.log_entries[i].lfu_fname =
"standard error";
}
}
/*
* Is this a specification of the console?
*/
else if (!strcasecmp(cp, "CONSOLE")) {
log_control.log_entries[i].ldu_filep =
CONSOLE_OPEN("a+F");
if (log_control.log_entries[i].ldu_filep) {
log_control.log_entries[i].log_type = K_LOG_CONSOLE;
log_control.log_entries[i].ldu_devname = "console";
}
}
/*
* Is this a specification of a device?
*/
else if (!strncasecmp(cp, "DEVICE", 6)) {
/*
* We handle devices very similarly to files.
*/
if (cp[6] == '=') {
log_control.log_entries[i].ldu_filep =
DEVICE_OPEN(&cp[7], "wF");
if (log_control.log_entries[i].ldu_filep) {
log_control.log_entries[i].log_type = K_LOG_DEVICE;
log_control.log_entries[i].ldu_devname = &cp[7];
}
}
}
/*
* See if we successfully parsed this specification.
*/
if (log_control.log_entries[i].log_type == K_LOG_NONE) {
fprintf(stderr, krb5_log_error_table(LSPEC_PARSE_ERR_1), whoami, cp);
fprintf(stderr, krb5_log_error_table(LSPEC_PARSE_ERR_2), whoami);
}
else
ngood++;
}
}
/*
* If we didn't find anything, then free our lists.
*/
if (ngood == 0) {
for (i=0; i<log_control.log_nentries; i++)
free(logging_specs[i]);
}
free(logging_specs);
}
/*
* If we didn't find anything, go for the default which is to log to
* the system log.
*/
if (ngood == 0) {
if (log_control.log_entries)
free(log_control.log_entries);
log_control.log_entries = &def_log_entry;
log_control.log_entries->log_type = K_LOG_SYSLOG;
log_control.log_entries->log_2free = (krb5_pointer) NULL;
log_facility = log_control.log_entries->lsu_facility = LOG_AUTH;
log_control.log_entries->lsu_severity = LOG_ERR;
do_openlog = 1;
log_control.log_nentries = 1;
}
if (log_control.log_nentries) {
log_control.log_whoami = (char *) malloc(strlen(whoami)+1);
if (log_control.log_whoami)
strcpy(log_control.log_whoami, whoami);
log_control.log_hostname = (char *) malloc(MAXHOSTNAMELEN + 1);
if (log_control.log_hostname) {
gethostname(log_control.log_hostname, MAXHOSTNAMELEN);
log_control.log_hostname[MAXHOSTNAMELEN] = '\0';
}
#ifdef HAVE_OPENLOG
if (do_openlog) {
openlog(whoami, LOG_NDELAY|LOG_PID, log_facility);
log_control.log_opened = 1;
}
#endif /* HAVE_OPENLOG */
if (do_com_err)
(void) set_com_err_hook(klog_com_err_proc);
}
return((log_control.log_nentries) ? 0 : ENOENT);
}
/*
* krb5_klog_close() - Close the logging context and free all data.
*/
void
krb5_klog_close(krb5_context kcontext)
{
int lindex;
(void) reset_com_err_hook();
for (lindex = 0; lindex < log_control.log_nentries; lindex++) {
switch (log_control.log_entries[lindex].log_type) {
case K_LOG_FILE:
case K_LOG_STDERR:
/*
* Files/standard error.
*/
fclose(log_control.log_entries[lindex].lfu_filep);
break;
case K_LOG_CONSOLE:
case K_LOG_DEVICE:
/*
* Devices (may need special handling)
*/
DEVICE_CLOSE(log_control.log_entries[lindex].ldu_filep);
break;
#ifdef HAVE_SYSLOG
case K_LOG_SYSLOG:
/*
* System log.
*/
break;
#endif /* HAVE_SYSLOG */
default:
break;
}
if (log_control.log_entries[lindex].log_2free)
free(log_control.log_entries[lindex].log_2free);
}
if (log_control.log_entries != &def_log_entry)
free(log_control.log_entries);
log_control.log_entries = (struct log_entry *) NULL;
log_control.log_nentries = 0;
if (log_control.log_whoami)
free(log_control.log_whoami);
log_control.log_whoami = (char *) NULL;
if (log_control.log_hostname)
free(log_control.log_hostname);
log_control.log_hostname = (char *) NULL;
#ifdef HAVE_CLOSELOG
if (log_control.log_opened)
closelog();
#endif /* HAVE_CLOSELOG */
}
/*
* severity2string() - Convert a severity to a string.
*/
static const char *
severity2string(int severity)
{
int s;
const char *ss;
s = severity & LOG_PRIMASK;
ss = krb5_log_error_table(LOG_UFO_STRING);
switch (s) {
#ifdef LOG_EMERG
case LOG_EMERG:
ss = krb5_log_error_table(LOG_EMERG_STRING);
break;
#endif /* LOG_EMERG */
#ifdef LOG_ALERT
case LOG_ALERT:
ss = krb5_log_error_table(LOG_ALERT_STRING);
break;
#endif /* LOG_ALERT */
#ifdef LOG_CRIT
case LOG_CRIT:
ss = krb5_log_error_table(LOG_CRIT_STRING);
break;
#endif /* LOG_CRIT */
case LOG_ERR:
ss = krb5_log_error_table(LOG_ERR_STRING);
break;
#ifdef LOG_WARNING
case LOG_WARNING:
ss = krb5_log_error_table(LOG_WARNING_STRING);
break;
#endif /* LOG_WARNING */
#ifdef LOG_NOTICE
case LOG_NOTICE:
ss = krb5_log_error_table(LOG_NOTICE_STRING);
break;
#endif /* LOG_NOTICE */
#ifdef LOG_INFO
case LOG_INFO:
ss = krb5_log_error_table(LOG_INFO_STRING);
break;
#endif /* LOG_INFO */
#ifdef LOG_DEBUG
case LOG_DEBUG:
ss = krb5_log_error_table(LOG_DEBUG_STRING);
break;
#endif /* LOG_DEBUG */
}
return((char *) ss);
}
/*
* krb5_klog_syslog() - Simulate the calling sequence of syslog(3), while
* also performing the logging redirection as specified
* by krb5_klog_init().
*/
static int
klog_vsyslog(int priority, const char *format, va_list arglist)
{
char outbuf[KRB5_KLOG_MAX_ERRMSG_SIZE];
int lindex;
char *syslogp;
char *cp;
time_t now;
#ifdef HAVE_STRFTIME
size_t soff;
#endif /* HAVE_STRFTIME */
/*
* Format a syslog-esque message of the format:
*
* (verbose form)
* <date> <hostname> <id>[<pid>](<priority>): <message>
*
* (short form)
* <date> <message>
*/
cp = outbuf;
(void) time(&now);
#ifdef HAVE_STRFTIME
/*
* Format the date: mon dd hh:mm:ss
*/
soff = strftime(outbuf, sizeof(outbuf), "%b %d %H:%M:%S", localtime(&now));
if (soff > 0)
cp += soff;
else
return(-1);
#else /* HAVE_STRFTIME */
/*
* Format the date:
* We ASSUME here that the output of ctime is of the format:
* dow mon dd hh:mm:ss tzs yyyy\n
* 012345678901234567890123456789
*/
strncpy(outbuf, ctime(&now) + 4, 15);
cp += 15;
#endif /* HAVE_STRFTIME */
#ifdef VERBOSE_LOGS
sprintf(cp, " %s %s[%ld](%s): ",
log_control.log_hostname, log_control.log_whoami, (long) getpid(),
severity2string(priority));
#else
sprintf(cp, " ");
#endif
syslogp = &outbuf[strlen(outbuf)];
/* Now format the actual message */
#ifdef HAVE_VSNPRINTF
vsnprintf(syslogp, sizeof(outbuf) - (syslogp - outbuf), format, arglist);
#elif HAVE_VSPRINTF
vsprintf(syslogp, format, arglist);
#else /* HAVE_VSPRINTF */
sprintf(syslogp, format, ((int *) arglist)[0], ((int *) arglist)[1],
((int *) arglist)[2], ((int *) arglist)[3],
((int *) arglist)[4], ((int *) arglist)[5]);
#endif /* HAVE_VSPRINTF */
/*
* If the user did not use krb5_klog_init() instead of dropping
* the request on the floor, syslog it - if it exists
*/
#ifdef HAVE_SYSLOG
if (log_control.log_nentries == 0) {
/* Log the message with our header trimmed off */
syslog(priority, "%s", syslogp);
}
#endif
/*
* Now that we have the message formatted, perform the output to each
* logging specification.
*/
for (lindex = 0; lindex < log_control.log_nentries; lindex++) {
switch (log_control.log_entries[lindex].log_type) {
case K_LOG_FILE:
klog_rotate(&log_control.log_entries[lindex]);
/*FALLTHRU*/
case K_LOG_STDERR:
/*
* Files/standard error.
*/
if (fprintf(log_control.log_entries[lindex].lfu_filep, "%s\n",
outbuf) < 0) {
/* Attempt to report error */
fprintf(stderr, krb5_log_error_table(LOG_FILE_ERR),
log_control.log_whoami,
log_control.log_entries[lindex].lfu_fname);
}
else {
fflush(log_control.log_entries[lindex].lfu_filep);
}
break;
case K_LOG_CONSOLE:
case K_LOG_DEVICE:
/*
* Devices (may need special handling)
*/
if (DEVICE_PRINT(log_control.log_entries[lindex].ldu_filep,
outbuf) < 0) {
/* Attempt to report error */
fprintf(stderr, krb5_log_error_table(LOG_DEVICE_ERR),
log_control.log_whoami,
log_control.log_entries[lindex].ldu_devname);
}
break;
#ifdef HAVE_SYSLOG
case K_LOG_SYSLOG:
/*
* System log.
*/
/* Log the message with our header trimmed off */
syslog(priority, "%s", syslogp);
break;
#endif /* HAVE_SYSLOG */
default:
break;
}
}
return(0);
}
int
krb5_klog_syslog(int priority, const char *format, ...)
{
int retval;
va_list pvar;
va_start(pvar, format);
retval = klog_vsyslog(priority, format, pvar);
va_end(pvar);
return(retval);
}
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
#
#
#
# MAPFILE HEADER START
#
# WARNING: STOP NOW. DO NOT MODIFY THIS FILE.
# Object versioning must comply with the rules detailed in
#
# usr/src/lib/README.mapfiles
#
# You should not be making modifications here until you've read the most current
# copy of that file. If you need help, contact a gatekeeper for guidance.
#
# MAPFILE HEADER END
#
$mapfile_version 2
SYMBOL_VERSION SUNWprivate_1.1 {
global:
_kadm5_get_kpasswd_protocol;
chpass_principal3_2;
chpass_principal_2;
chpw_error_message;
chrand_principal3_2;
chrand_principal_2;
create_policy_2;
create_principal3_2;
create_principal_2;
delete_policy_2;
delete_principal_2;
display_status;
get_policy_2;
get_pols_2;
get_principal_2;
get_princs_2;
get_privs_2;
init_2;
kadm5_chpass_principal;
kadm5_chpass_principal_3;
kadm5_chpass_principal_util;
kadm5_chpass_principal_v2;
kadm5_create_policy;
kadm5_create_principal;
kadm5_create_principal_3;
kadm5_decrypt_key;
kadm5_delete_policy;
kadm5_delete_principal;
kadm5_destroy;
kadm5_flush;
kadm5_free_config_params;
kadm5_free_name_list;
kadm5_free_policy_ent;
kadm5_free_principal_ent;
kadm5_get_adm_host_srv_name;
kadm5_get_admin_service_name;
kadm5_get_config_params;
kadm5_get_cpw_host_srv_name;
kadm5_get_kiprop_host_srv_name;
kadm5_get_master;
kadm5_get_policies;
kadm5_get_policy;
kadm5_get_principal;
kadm5_get_principals;
kadm5_get_privs;
kadm5_init;
kadm5_init_iprop;
kadm5_init_krb5_context;
kadm5_init_with_creds;
kadm5_init_with_password;
kadm5_init_with_skey;
kadm5_is_master;
kadm5_lock;
kadm5_modify_policy;
kadm5_modify_principal;
kadm5_randkey_principal;
kadm5_randkey_principal_3;
kadm5_randkey_principal_old;
kadm5_rename_principal;
kadm5_setkey_principal;
kadm5_setkey_principal_3;
kadm5_unlock;
krb5_aprof_finish;
krb5_aprof_get_boolean;
krb5_aprof_get_deltat;
krb5_aprof_get_int32;
krb5_aprof_get_string;
krb5_aprof_getvals;
krb5_aprof_init;
krb5_flags_to_string;
krb5_free_key_data_contents;
krb5_free_realm_params;
krb5_input_flag_to_string;
krb5_keysalt_is_present;
krb5_keysalt_iterate;
krb5_klog_close;
krb5_klog_init;
krb5_klog_syslog;
krb5_log_error_table;
krb5int_mk_chpw_req;
krb5int_rd_chpw_rep;
krb5_read_realm_params;
krb5_string_to_flags;
krb5_string_to_keysalts;
modify_policy_2;
modify_principal_2;
rename_principal_2;
setkey_principal3_2;
setkey_principal_2;
xdr_chpass3_arg;
xdr_chpass_arg;
xdr_chrand3_arg;
xdr_chrand_arg;
xdr_chrand_ret;
xdr_cpol_arg;
xdr_cprinc3_arg;
xdr_cprinc_arg;
xdr_dpol_arg;
xdr_dprinc_arg;
xdr_generic_ret;
xdr_getprivs_ret;
xdr_gpol_arg;
xdr_gpol_ret;
xdr_gpols_arg;
xdr_gpols_ret;
xdr_gprinc_arg;
xdr_gprinc_ret;
xdr_gprincs_arg;
xdr_gprincs_ret;
xdr_kadm5_policy_ent_rec;
xdr_kadm5_principal_ent_rec;
xdr_kadm5_principal_ent_rec_v1;
xdr_kadm5_ret_t;
xdr_krb5_deltat;
xdr_krb5_enctype;
xdr_krb5_flags;
xdr_krb5_int16;
xdr_krb5_key_data_nocontents;
xdr_krb5_key_salt_tuple;
xdr_krb5_keyblock;
xdr_krb5_kvno;
xdr_krb5_octet;
xdr_krb5_principal;
xdr_krb5_salttype;
xdr_krb5_timestamp;
xdr_krb5_tl_data;
xdr_krb5_ui_2;
xdr_krb5_ui_4;
xdr_mpol_arg;
xdr_mprinc_arg;
xdr_nullstring;
xdr_nulltype;
xdr_rprinc_arg;
xdr_setkey3_arg;
xdr_setkey_arg;
xdr_ui_4;
local:
*;
};
|