1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9466
9467
9468
9469
9470
9471
9472
9473
9474
9475
9476
9477
9478
9479
9480
9481
9482
9483
9484
9485
9486
9487
9488
9489
9490
9491
9492
9493
9494
9495
9496
9497
9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
9526
9527
9528
9529
9530
9531
9532
9533
9534
9535
9536
9537
9538
9539
9540
9541
9542
9543
9544
9545
9546
9547
9548
9549
9550
9551
9552
9553
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570
9571
9572
9573
9574
9575
9576
9577
9578
9579
9580
9581
9582
9583
9584
9585
9586
9587
9588
9589
9590
9591
9592
9593
9594
9595
9596
9597
9598
9599
9600
9601
9602
9603
9604
9605
9606
9607
9608
9609
9610
9611
9612
9613
9614
9615
9616
9617
9618
9619
9620
9621
9622
9623
9624
9625
9626
9627
9628
9629
9630
9631
9632
9633
9634
9635
9636
9637
9638
9639
9640
9641
9642
9643
9644
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655
9656
9657
9658
9659
9660
9661
9662
9663
9664
9665
9666
9667
9668
9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9701
9702
9703
9704
9705
9706
9707
9708
9709
9710
9711
9712
9713
9714
9715
9716
9717
9718
9719
9720
9721
9722
9723
9724
9725
9726
9727
9728
9729
9730
9731
9732
9733
9734
9735
9736
9737
9738
9739
9740
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768
9769
9770
9771
9772
9773
9774
9775
9776
9777
9778
9779
9780
9781
9782
9783
9784
9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9799
9800
9801
9802
9803
9804
9805
9806
9807
9808
9809
9810
9811
9812
9813
9814
9815
9816
9817
9818
9819
9820
9821
9822
9823
9824
9825
9826
9827
9828
9829
9830
9831
9832
9833
9834
9835
9836
9837
9838
9839
9840
9841
9842
9843
9844
9845
9846
9847
9848
9849
9850
9851
9852
9853
9854
9855
9856
9857
9858
9859
9860
9861
9862
9863
9864
9865
9866
9867
9868
9869
9870
9871
9872
9873
9874
9875
9876
9877
9878
9879
9880
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
9894
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905
9906
9907
9908
9909
9910
9911
9912
9913
9914
9915
9916
9917
9918
9919
9920
9921
9922
9923
9924
9925
9926
9927
9928
9929
9930
9931
9932
9933
9934
9935
9936
9937
9938
9939
9940
9941
9942
9943
9944
9945
9946
9947
9948
9949
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9972
9973
9974
9975
9976
9977
9978
9979
9980
9981
9982
9983
9984
9985
9986
9987
9988
9989
9990
9991
9992
9993
9994
9995
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10046
10047
10048
10049
10050
10051
10052
10053
10054
10055
10056
10057
10058
10059
10060
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10076
10077
10078
10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
10102
10103
10104
10105
10106
10107
10108
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128
10129
10130
10131
10132
10133
10134
10135
10136
10137
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
10159
10160
10161
10162
10163
10164
10165
10166
10167
10168
10169
10170
10171
10172
10173
10174
10175
10176
10177
10178
10179
10180
10181
10182
10183
10184
10185
10186
10187
10188
10189
10190
10191
10192
10193
10194
10195
10196
10197
10198
10199
10200
10201
10202
10203
10204
10205
10206
10207
10208
10209
10210
10211
10212
10213
10214
10215
10216
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
10228
10229
10230
10231
10232
10233
10234
10235
10236
10237
10238
10239
10240
10241
10242
10243
10244
10245
10246
10247
10248
10249
10250
10251
10252
10253
10254
10255
10256
10257
10258
10259
10260
10261
10262
10263
10264
10265
10266
10267
10268
10269
10270
10271
10272
10273
10274
10275
10276
10277
10278
10279
10280
10281
10282
10283
10284
10285
10286
10287
10288
10289
10290
10291
10292
10293
10294
10295
10296
10297
10298
10299
10300
10301
10302
10303
10304
10305
10306
10307
10308
10309
10310
10311
10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
10323
10324
10325
10326
10327
10328
10329
10330
10331
10332
10333
10334
10335
10336
10337
10338
10339
10340
10341
10342
10343
10344
10345
10346
10347
10348
10349
10350
10351
10352
10353
10354
10355
10356
10357
10358
10359
10360
10361
10362
10363
10364
10365
10366
10367
10368
10369
10370
10371
10372
10373
10374
10375
10376
10377
10378
10379
10380
10381
10382
10383
10384
10385
10386
10387
10388
10389
10390
10391
10392
10393
10394
10395
10396
10397
10398
10399
10400
10401
10402
10403
10404
10405
10406
10407
10408
10409
10410
10411
10412
10413
10414
10415
10416
10417
10418
10419
10420
10421
10422
10423
10424
10425
10426
10427
10428
10429
10430
10431
10432
10433
10434
10435
10436
10437
10438
10439
10440
10441
10442
10443
10444
10445
10446
10447
10448
10449
10450
10451
10452
10453
10454
10455
10456
10457
10458
10459
10460
10461
10462
10463
10464
10465
10466
10467
10468
10469
10470
10471
10472
10473
10474
10475
10476
10477
10478
10479
10480
10481
10482
10483
10484
10485
10486
10487
10488
10489
10490
10491
10492
10493
10494
10495
10496
10497
10498
10499
10500
10501
10502
10503
10504
10505
10506
10507
10508
10509
10510
10511
10512
10513
10514
10515
10516
10517
10518
10519
10520
10521
10522
10523
10524
10525
10526
10527
10528
10529
10530
10531
10532
10533
10534
10535
10536
10537
10538
10539
10540
10541
10542
10543
10544
10545
10546
10547
10548
10549
10550
10551
10552
10553
10554
10555
10556
10557
10558
10559
10560
10561
10562
10563
10564
10565
10566
10567
10568
10569
10570
10571
10572
10573
10574
10575
10576
10577
10578
10579
10580
10581
10582
10583
10584
10585
10586
10587
10588
10589
10590
10591
10592
10593
10594
10595
10596
10597
10598
10599
10600
10601
10602
10603
10604
10605
10606
10607
10608
10609
10610
10611
10612
10613
10614
10615
10616
10617
10618
10619
10620
10621
10622
10623
10624
10625
10626
10627
10628
10629
10630
10631
10632
10633
10634
10635
10636
10637
10638
10639
10640
10641
10642
10643
10644
10645
10646
10647
10648
10649
10650
10651
10652
10653
10654
10655
10656
10657
10658
10659
10660
10661
10662
10663
10664
10665
10666
10667
10668
10669
10670
10671
10672
10673
10674
10675
10676
10677
10678
10679
10680
10681
10682
10683
10684
10685
10686
10687
10688
10689
10690
10691
10692
10693
10694
10695
10696
10697
10698
10699
10700
10701
10702
10703
10704
10705
10706
10707
10708
10709
10710
10711
10712
10713
10714
10715
10716
10717
10718
10719
10720
10721
10722
10723
10724
10725
10726
10727
10728
10729
10730
10731
10732
10733
10734
10735
10736
10737
10738
10739
10740
10741
10742
10743
10744
10745
10746
10747
10748
10749
10750
10751
10752
10753
10754
10755
10756
10757
10758
10759
10760
10761
10762
10763
10764
10765
10766
10767
10768
10769
10770
10771
10772
10773
10774
10775
10776
10777
10778
10779
10780
10781
10782
10783
10784
10785
10786
10787
10788
10789
10790
10791
10792
10793
10794
10795
10796
10797
10798
10799
10800
10801
10802
10803
10804
10805
10806
10807
10808
10809
10810
10811
10812
10813
10814
10815
10816
10817
10818
10819
10820
10821
10822
10823
10824
10825
10826
10827
10828
10829
10830
10831
10832
10833
10834
10835
10836
10837
10838
10839
10840
10841
10842
10843
10844
10845
10846
10847
10848
10849
10850
10851
10852
10853
10854
10855
10856
10857
10858
10859
10860
10861
10862
10863
10864
10865
10866
10867
10868
10869
10870
10871
10872
10873
10874
10875
10876
10877
10878
10879
10880
10881
10882
10883
10884
10885
10886
10887
10888
10889
10890
10891
10892
10893
10894
10895
10896
10897
10898
10899
10900
10901
10902
10903
10904
10905
10906
10907
10908
10909
10910
10911
10912
10913
10914
10915
10916
10917
10918
10919
10920
10921
10922
10923
10924
10925
10926
10927
10928
10929
10930
10931
10932
10933
10934
10935
10936
10937
10938
10939
10940
10941
10942
10943
10944
10945
10946
10947
10948
10949
10950
10951
10952
10953
10954
10955
10956
10957
10958
10959
10960
10961
10962
10963
10964
10965
10966
10967
10968
10969
10970
10971
10972
10973
10974
10975
10976
10977
10978
10979
10980
10981
10982
10983
10984
10985
10986
10987
10988
10989
10990
10991
10992
10993
10994
10995
10996
10997
10998
10999
11000
11001
11002
11003
11004
11005
11006
11007
11008
11009
11010
11011
11012
11013
11014
11015
11016
11017
11018
11019
11020
11021
11022
11023
11024
11025
11026
11027
11028
11029
11030
11031
11032
11033
11034
11035
11036
11037
11038
11039
11040
11041
11042
11043
11044
11045
11046
11047
11048
11049
11050
11051
11052
11053
11054
11055
11056
11057
11058
11059
11060
11061
11062
11063
11064
11065
11066
11067
11068
11069
11070
11071
11072
11073
11074
11075
11076
11077
11078
11079
11080
11081
11082
11083
11084
11085
11086
11087
11088
11089
11090
11091
11092
11093
11094
11095
11096
11097
11098
11099
11100
11101
11102
11103
11104
11105
11106
11107
11108
11109
11110
11111
11112
11113
11114
11115
11116
11117
11118
11119
11120
11121
11122
11123
11124
11125
11126
11127
11128
11129
11130
11131
11132
11133
11134
11135
11136
11137
11138
11139
11140
11141
11142
11143
11144
11145
11146
11147
11148
11149
11150
11151
11152
11153
11154
11155
11156
11157
11158
11159
11160
11161
11162
11163
11164
11165
11166
11167
11168
11169
11170
11171
11172
11173
11174
11175
11176
11177
11178
11179
11180
11181
11182
11183
11184
11185
11186
11187
11188
11189
11190
11191
11192
11193
11194
11195
11196
11197
11198
11199
11200
11201
11202
11203
11204
11205
11206
11207
11208
11209
11210
11211
11212
11213
11214
11215
11216
11217
11218
11219
11220
11221
11222
11223
11224
11225
11226
11227
11228
11229
11230
11231
11232
11233
11234
11235
11236
11237
11238
11239
11240
11241
11242
11243
11244
11245
11246
11247
11248
11249
11250
11251
11252
11253
11254
11255
11256
11257
11258
11259
11260
11261
11262
11263
11264
11265
11266
11267
11268
11269
11270
11271
11272
11273
11274
11275
11276
11277
11278
11279
11280
11281
11282
11283
11284
11285
11286
11287
11288
11289
11290
11291
11292
11293
11294
11295
11296
11297
11298
11299
11300
11301
11302
11303
11304
11305
11306
11307
11308
11309
11310
11311
11312
11313
11314
11315
11316
11317
11318
11319
11320
11321
11322
11323
11324
11325
11326
11327
11328
11329
11330
11331
11332
11333
11334
11335
11336
11337
11338
11339
11340
11341
11342
11343
11344
11345
11346
11347
11348
11349
11350
11351
11352
11353
11354
11355
11356
11357
11358
11359
11360
11361
11362
11363
11364
11365
11366
11367
11368
11369
11370
11371
11372
11373
11374
11375
11376
11377
11378
11379
11380
11381
11382
11383
11384
11385
11386
11387
11388
11389
11390
11391
11392
11393
11394
11395
11396
11397
11398
11399
11400
11401
11402
11403
11404
11405
11406
11407
11408
11409
11410
11411
11412
11413
11414
11415
11416
11417
11418
11419
11420
11421
11422
11423
11424
11425
11426
11427
11428
11429
11430
11431
11432
11433
11434
11435
11436
11437
11438
11439
11440
11441
11442
11443
11444
11445
11446
11447
11448
11449
11450
11451
11452
11453
11454
11455
11456
11457
11458
11459
11460
11461
11462
11463
11464
11465
11466
11467
11468
11469
11470
11471
11472
11473
11474
11475
11476
11477
11478
11479
11480
11481
11482
11483
11484
11485
11486
11487
11488
11489
11490
11491
11492
11493
11494
11495
11496
11497
11498
11499
11500
11501
11502
11503
11504
11505
11506
11507
11508
11509
11510
11511
11512
11513
11514
11515
11516
11517
11518
11519
11520
11521
11522
11523
11524
11525
11526
11527
11528
11529
11530
11531
11532
11533
11534
11535
11536
11537
11538
11539
11540
11541
11542
11543
11544
11545
11546
11547
11548
11549
11550
11551
11552
11553
11554
11555
11556
11557
11558
11559
11560
11561
11562
11563
11564
11565
11566
11567
11568
11569
11570
11571
11572
11573
11574
11575
11576
11577
11578
11579
11580
11581
11582
11583
11584
11585
11586
11587
11588
11589
11590
11591
11592
11593
11594
11595
11596
11597
11598
11599
11600
11601
11602
11603
11604
11605
11606
11607
11608
11609
11610
11611
11612
11613
11614
11615
11616
11617
11618
11619
11620
11621
11622
11623
11624
11625
11626
11627
11628
11629
11630
11631
11632
11633
11634
11635
11636
11637
11638
11639
11640
11641
11642
11643
11644
11645
11646
11647
11648
11649
11650
11651
11652
11653
11654
11655
11656
11657
11658
11659
11660
11661
11662
11663
11664
11665
11666
11667
11668
11669
11670
11671
11672
11673
11674
11675
11676
11677
11678
11679
11680
11681
11682
11683
11684
11685
11686
11687
11688
11689
11690
11691
11692
11693
11694
11695
11696
11697
11698
11699
11700
11701
11702
11703
11704
11705
11706
11707
11708
11709
11710
11711
11712
11713
11714
11715
11716
11717
11718
11719
11720
11721
11722
11723
11724
11725
11726
11727
11728
11729
11730
11731
11732
11733
11734
11735
11736
11737
11738
11739
11740
11741
11742
11743
11744
11745
11746
11747
11748
11749
11750
11751
11752
11753
11754
11755
11756
11757
11758
11759
11760
11761
11762
11763
11764
11765
11766
11767
11768
11769
11770
11771
11772
11773
11774
11775
11776
11777
11778
11779
11780
11781
11782
11783
11784
11785
11786
11787
11788
11789
11790
11791
11792
11793
11794
11795
11796
11797
11798
11799
11800
11801
11802
11803
11804
11805
11806
11807
11808
11809
11810
11811
11812
11813
11814
11815
11816
11817
11818
11819
11820
11821
11822
11823
11824
11825
11826
11827
11828
11829
11830
11831
11832
11833
11834
11835
11836
11837
11838
11839
11840
11841
11842
11843
11844
11845
11846
11847
11848
11849
11850
11851
11852
11853
11854
11855
11856
11857
11858
11859
11860
11861
11862
11863
11864
11865
11866
11867
11868
11869
11870
11871
11872
11873
11874
11875
11876
11877
11878
11879
11880
11881
11882
11883
11884
11885
11886
11887
11888
11889
11890
11891
11892
11893
11894
11895
11896
11897
11898
11899
11900
11901
11902
11903
11904
11905
11906
11907
11908
11909
11910
11911
11912
11913
11914
11915
11916
11917
11918
11919
11920
11921
11922
11923
11924
11925
11926
11927
11928
11929
11930
11931
11932
11933
11934
11935
11936
11937
11938
11939
11940
11941
11942
11943
11944
11945
11946
11947
11948
11949
11950
11951
11952
11953
11954
11955
11956
11957
11958
11959
11960
11961
11962
11963
11964
11965
11966
11967
11968
11969
11970
11971
11972
11973
11974
11975
11976
11977
11978
11979
11980
11981
11982
11983
11984
11985
11986
11987
11988
11989
11990
11991
11992
11993
11994
11995
11996
11997
11998
11999
12000
12001
12002
12003
12004
12005
12006
12007
12008
12009
12010
12011
12012
12013
12014
12015
12016
12017
12018
12019
12020
12021
12022
12023
12024
12025
12026
12027
12028
12029
12030
12031
12032
12033
12034
12035
12036
12037
12038
12039
12040
12041
12042
12043
12044
12045
12046
12047
12048
12049
12050
12051
12052
12053
12054
12055
12056
12057
12058
12059
12060
12061
12062
12063
12064
12065
12066
12067
12068
12069
12070
12071
12072
12073
12074
12075
12076
12077
12078
12079
12080
12081
12082
12083
12084
12085
12086
12087
12088
12089
12090
12091
12092
12093
12094
12095
12096
12097
12098
12099
12100
12101
12102
12103
12104
12105
12106
12107
12108
12109
12110
12111
12112
12113
12114
12115
12116
12117
12118
12119
12120
12121
12122
12123
12124
12125
12126
12127
12128
12129
12130
12131
12132
12133
12134
12135
12136
12137
12138
12139
12140
12141
12142
12143
12144
12145
12146
12147
12148
12149
12150
12151
12152
12153
12154
12155
12156
12157
12158
12159
12160
12161
12162
12163
12164
12165
12166
12167
12168
12169
12170
12171
12172
12173
12174
12175
12176
12177
12178
12179
12180
12181
12182
12183
12184
12185
12186
12187
12188
12189
12190
12191
12192
12193
12194
12195
12196
12197
12198
12199
12200
12201
12202
12203
12204
12205
12206
12207
12208
12209
12210
12211
12212
12213
12214
12215
12216
12217
12218
12219
12220
12221
12222
12223
12224
12225
12226
12227
12228
12229
12230
12231
12232
12233
12234
12235
12236
12237
12238
12239
12240
12241
12242
12243
12244
12245
12246
12247
12248
12249
12250
12251
12252
12253
12254
12255
12256
12257
12258
12259
12260
12261
12262
12263
12264
12265
12266
12267
12268
12269
12270
12271
12272
12273
12274
12275
12276
12277
12278
12279
12280
12281
12282
12283
12284
12285
12286
12287
12288
12289
12290
12291
12292
12293
12294
12295
12296
12297
12298
12299
12300
12301
12302
12303
12304
12305
12306
12307
12308
12309
12310
12311
12312
12313
12314
12315
12316
12317
12318
12319
12320
12321
12322
12323
12324
12325
12326
12327
12328
12329
12330
12331
12332
12333
12334
12335
12336
12337
12338
12339
12340
12341
12342
12343
12344
12345
12346
12347
12348
12349
12350
12351
12352
12353
12354
12355
12356
12357
12358
12359
12360
12361
12362
12363
12364
12365
12366
12367
12368
12369
12370
12371
12372
12373
12374
12375
12376
12377
12378
12379
12380
12381
12382
12383
12384
12385
12386
12387
12388
12389
12390
12391
12392
12393
12394
12395
12396
12397
12398
12399
12400
12401
12402
12403
12404
12405
12406
12407
12408
12409
12410
12411
12412
12413
12414
12415
12416
12417
12418
12419
12420
12421
12422
12423
12424
12425
12426
12427
12428
12429
12430
12431
12432
12433
12434
12435
12436
12437
12438
12439
12440
12441
12442
12443
12444
12445
12446
12447
12448
12449
12450
12451
12452
12453
12454
12455
12456
12457
12458
12459
12460
12461
12462
12463
12464
12465
12466
12467
12468
12469
12470
12471
12472
12473
12474
12475
12476
12477
12478
12479
12480
12481
12482
12483
12484
12485
12486
12487
12488
12489
12490
12491
12492
12493
12494
12495
12496
12497
12498
12499
12500
12501
12502
12503
12504
12505
12506
12507
12508
12509
12510
12511
12512
12513
12514
12515
12516
12517
12518
12519
12520
12521
12522
12523
12524
12525
12526
12527
12528
12529
12530
12531
12532
12533
12534
12535
12536
12537
12538
12539
12540
12541
12542
12543
12544
12545
12546
12547
12548
12549
12550
12551
12552
12553
12554
12555
12556
12557
12558
12559
12560
12561
12562
12563
12564
12565
12566
12567
12568
12569
12570
12571
12572
12573
12574
12575
12576
12577
12578
12579
12580
12581
12582
12583
12584
12585
12586
12587
12588
12589
12590
12591
12592
12593
12594
12595
12596
12597
12598
12599
12600
12601
12602
12603
12604
12605
12606
12607
12608
12609
12610
12611
12612
12613
12614
12615
12616
12617
12618
12619
12620
12621
12622
12623
12624
12625
12626
12627
12628
12629
12630
12631
12632
12633
12634
12635
12636
12637
12638
12639
12640
12641
12642
12643
12644
12645
12646
12647
12648
12649
12650
12651
12652
12653
12654
12655
12656
12657
12658
12659
12660
12661
12662
12663
12664
12665
12666
12667
12668
12669
12670
12671
12672
12673
12674
12675
12676
12677
12678
12679
12680
12681
12682
12683
12684
12685
12686
12687
12688
12689
12690
12691
12692
12693
12694
12695
12696
12697
12698
12699
12700
12701
12702
12703
12704
12705
12706
12707
12708
12709
12710
12711
12712
12713
12714
12715
12716
12717
12718
12719
12720
12721
12722
12723
12724
12725
12726
12727
12728
12729
12730
12731
12732
12733
12734
12735
12736
12737
12738
12739
12740
12741
12742
12743
12744
12745
12746
12747
12748
12749
12750
12751
12752
12753
12754
12755
12756
12757
12758
12759
12760
12761
12762
12763
12764
12765
12766
12767
12768
12769
12770
12771
12772
12773
12774
12775
12776
12777
12778
12779
12780
12781
12782
12783
12784
12785
12786
12787
12788
12789
12790
12791
12792
12793
12794
12795
12796
12797
12798
12799
12800
12801
12802
12803
12804
12805
12806
12807
12808
12809
12810
12811
12812
12813
12814
12815
12816
12817
12818
12819
12820
12821
12822
12823
12824
12825
12826
12827
12828
12829
12830
12831
12832
12833
12834
12835
12836
12837
12838
12839
12840
12841
12842
12843
12844
12845
12846
12847
12848
12849
12850
12851
12852
12853
12854
12855
12856
12857
12858
12859
12860
12861
12862
12863
12864
12865
12866
12867
12868
12869
12870
12871
12872
12873
12874
12875
12876
12877
12878
12879
12880
12881
12882
12883
12884
12885
12886
12887
12888
12889
12890
12891
12892
12893
12894
12895
12896
12897
12898
12899
12900
12901
12902
12903
12904
12905
12906
12907
12908
12909
12910
12911
12912
12913
12914
12915
12916
12917
12918
12919
12920
12921
12922
12923
12924
12925
12926
12927
12928
12929
12930
12931
12932
12933
12934
12935
12936
12937
12938
12939
12940
12941
12942
12943
12944
12945
12946
12947
12948
12949
12950
12951
12952
12953
12954
12955
12956
12957
12958
12959
12960
12961
12962
12963
12964
12965
12966
12967
12968
12969
12970
12971
12972
12973
12974
12975
12976
12977
12978
12979
12980
12981
12982
12983
12984
12985
12986
12987
12988
12989
12990
12991
12992
12993
12994
12995
12996
12997
12998
12999
13000
13001
13002
13003
13004
13005
13006
13007
13008
13009
13010
13011
13012
13013
13014
13015
13016
13017
13018
13019
13020
13021
13022
13023
13024
13025
13026
13027
13028
13029
13030
13031
13032
13033
13034
13035
13036
13037
13038
13039
13040
13041
13042
13043
13044
13045
13046
13047
13048
13049
13050
13051
13052
13053
13054
13055
13056
13057
13058
13059
13060
13061
13062
13063
13064
13065
13066
13067
13068
13069
13070
13071
13072
13073
13074
13075
13076
13077
13078
13079
13080
13081
13082
13083
13084
13085
13086
13087
13088
13089
13090
13091
13092
13093
13094
13095
13096
13097
13098
13099
13100
13101
13102
13103
13104
13105
13106
13107
13108
13109
13110
13111
13112
13113
13114
13115
13116
13117
13118
13119
13120
13121
13122
13123
13124
13125
13126
13127
13128
13129
13130
13131
13132
13133
13134
13135
13136
13137
13138
13139
13140
13141
13142
13143
13144
13145
13146
13147
13148
13149
13150
13151
13152
13153
13154
13155
13156
13157
13158
13159
13160
13161
13162
13163
13164
13165
13166
13167
13168
13169
13170
13171
13172
13173
13174
13175
13176
13177
13178
13179
13180
13181
13182
13183
13184
13185
13186
13187
13188
13189
13190
13191
13192
13193
13194
13195
13196
13197
13198
13199
13200
13201
13202
13203
13204
13205
13206
13207
13208
13209
13210
13211
13212
13213
13214
13215
13216
13217
13218
13219
13220
13221
13222
13223
13224
13225
13226
13227
13228
13229
13230
13231
13232
13233
13234
13235
13236
13237
13238
13239
13240
13241
13242
13243
13244
13245
13246
13247
13248
13249
13250
13251
13252
13253
13254
13255
13256
13257
13258
13259
13260
13261
13262
13263
13264
13265
13266
13267
13268
13269
13270
13271
13272
13273
13274
13275
13276
13277
13278
13279
13280
13281
13282
13283
13284
13285
13286
13287
13288
13289
13290
13291
13292
13293
13294
13295
13296
13297
13298
13299
13300
13301
13302
13303
13304
13305
13306
13307
13308
13309
13310
13311
13312
13313
13314
13315
13316
13317
13318
13319
13320
13321
13322
13323
13324
13325
13326
13327
13328
13329
13330
13331
13332
13333
13334
13335
13336
13337
13338
13339
13340
13341
13342
13343
13344
13345
13346
13347
13348
13349
13350
13351
13352
13353
13354
13355
13356
13357
13358
13359
13360
13361
13362
13363
13364
13365
13366
13367
13368
13369
13370
13371
13372
13373
13374
13375
13376
13377
13378
13379
13380
13381
13382
13383
13384
13385
13386
13387
13388
13389
13390
13391
13392
13393
13394
13395
13396
13397
13398
13399
13400
13401
13402
13403
13404
13405
13406
13407
13408
13409
13410
13411
13412
13413
13414
13415
13416
13417
13418
13419
13420
13421
13422
13423
13424
13425
13426
13427
13428
13429
13430
13431
13432
13433
13434
13435
13436
13437
13438
13439
13440
13441
13442
13443
13444
13445
13446
13447
13448
13449
13450
13451
13452
13453
13454
13455
13456
13457
13458
13459
13460
13461
13462
13463
13464
13465
13466
13467
13468
13469
13470
13471
13472
13473
13474
13475
13476
13477
13478
13479
13480
13481
13482
13483
13484
13485
13486
13487
13488
13489
13490
13491
13492
13493
13494
13495
13496
13497
13498
13499
13500
13501
13502
13503
13504
13505
13506
13507
13508
13509
13510
13511
13512
13513
13514
13515
13516
13517
13518
13519
13520
13521
13522
13523
13524
13525
13526
13527
13528
13529
13530
13531
13532
13533
13534
13535
13536
13537
13538
13539
13540
13541
13542
13543
13544
13545
13546
13547
13548
13549
13550
13551
13552
13553
13554
13555
13556
13557
13558
13559
13560
13561
13562
13563
13564
13565
13566
13567
13568
13569
13570
13571
13572
13573
13574
13575
13576
13577
13578
13579
13580
13581
13582
13583
13584
13585
13586
13587
13588
13589
13590
13591
13592
13593
13594
13595
13596
13597
13598
13599
13600
13601
13602
13603
13604
13605
13606
13607
13608
13609
13610
13611
13612
13613
13614
13615
13616
13617
13618
13619
13620
13621
13622
13623
13624
13625
13626
13627
13628
13629
13630
13631
13632
13633
13634
13635
13636
13637
13638
13639
13640
13641
13642
13643
13644
13645
13646
13647
13648
13649
13650
13651
13652
13653
13654
13655
13656
13657
13658
13659
13660
13661
13662
13663
13664
13665
13666
13667
13668
13669
13670
13671
13672
13673
13674
13675
13676
13677
13678
13679
13680
13681
13682
13683
13684
13685
13686
13687
13688
13689
13690
13691
13692
13693
13694
13695
13696
13697
13698
13699
13700
13701
13702
13703
13704
13705
13706
13707
13708
13709
13710
13711
13712
13713
13714
13715
13716
13717
13718
13719
13720
13721
13722
13723
13724
13725
13726
13727
13728
13729
13730
13731
13732
13733
13734
13735
13736
13737
13738
13739
13740
13741
13742
13743
13744
13745
13746
13747
13748
13749
13750
13751
13752
13753
13754
13755
13756
13757
13758
13759
13760
13761
13762
13763
13764
13765
13766
13767
13768
13769
13770
13771
13772
13773
13774
13775
13776
13777
13778
13779
13780
13781
13782
13783
13784
13785
13786
13787
13788
13789
13790
13791
13792
13793
13794
13795
13796
13797
13798
13799
13800
13801
13802
13803
13804
13805
13806
13807
13808
13809
13810
13811
13812
13813
13814
13815
13816
13817
13818
13819
13820
13821
13822
13823
13824
13825
13826
13827
13828
13829
13830
13831
13832
13833
13834
13835
13836
13837
13838
13839
13840
13841
13842
13843
13844
13845
13846
13847
13848
13849
13850
13851
13852
13853
13854
13855
13856
13857
13858
13859
13860
13861
13862
13863
13864
13865
13866
13867
13868
13869
13870
13871
13872
13873
13874
13875
13876
13877
13878
13879
13880
13881
13882
13883
13884
13885
13886
13887
13888
13889
13890
13891
13892
13893
13894
13895
13896
13897
13898
13899
13900
13901
13902
13903
13904
13905
13906
13907
13908
13909
13910
13911
13912
13913
13914
13915
13916
13917
13918
13919
13920
13921
13922
13923
13924
13925
13926
13927
13928
13929
13930
13931
13932
13933
13934
13935
13936
13937
13938
13939
13940
13941
13942
13943
13944
13945
13946
13947
13948
13949
13950
13951
13952
13953
13954
13955
13956
13957
13958
13959
13960
13961
13962
13963
13964
13965
13966
13967
13968
13969
13970
13971
13972
13973
13974
13975
13976
13977
13978
13979
13980
13981
13982
13983
13984
13985
13986
13987
13988
13989
13990
13991
13992
13993
13994
13995
13996
13997
13998
13999
14000
14001
14002
14003
14004
14005
14006
14007
14008
14009
14010
14011
14012
14013
14014
14015
14016
14017
14018
14019
14020
14021
14022
14023
14024
14025
14026
14027
14028
14029
14030
14031
14032
14033
14034
14035
14036
14037
14038
14039
14040
14041
14042
14043
14044
14045
14046
14047
14048
14049
14050
14051
14052
14053
14054
14055
14056
14057
14058
14059
14060
14061
14062
14063
14064
14065
14066
14067
14068
14069
14070
14071
14072
14073
14074
14075
14076
14077
14078
14079
14080
14081
14082
14083
14084
14085
14086
14087
14088
14089
14090
14091
14092
14093
14094
14095
14096
14097
14098
14099
14100
14101
14102
14103
14104
14105
14106
14107
14108
14109
14110
14111
14112
14113
14114
14115
14116
14117
14118
14119
14120
14121
14122
14123
14124
14125
14126
14127
14128
14129
14130
14131
14132
14133
14134
14135
14136
14137
14138
14139
14140
14141
14142
14143
14144
14145
14146
14147
14148
14149
14150
14151
14152
14153
14154
14155
14156
14157
14158
14159
14160
14161
14162
14163
14164
14165
14166
14167
14168
14169
14170
14171
14172
14173
14174
14175
14176
14177
14178
14179
14180
14181
14182
14183
14184
14185
14186
14187
14188
14189
14190
14191
14192
14193
14194
14195
14196
14197
14198
14199
14200
14201
14202
14203
14204
14205
14206
14207
14208
14209
14210
14211
14212
14213
14214
14215
14216
14217
14218
14219
14220
14221
14222
14223
14224
14225
14226
14227
14228
14229
14230
14231
14232
14233
14234
14235
14236
14237
14238
14239
14240
14241
14242
14243
14244
14245
14246
14247
14248
14249
14250
14251
14252
14253
14254
14255
14256
14257
14258
14259
14260
14261
14262
14263
14264
14265
14266
14267
14268
14269
14270
14271
14272
14273
14274
14275
14276
14277
14278
14279
14280
14281
14282
14283
14284
14285
14286
14287
14288
14289
14290
14291
14292
14293
14294
14295
14296
14297
14298
14299
14300
14301
14302
14303
14304
14305
14306
14307
14308
14309
14310
14311
14312
14313
14314
14315
14316
14317
14318
14319
14320
14321
14322
14323
14324
14325
14326
14327
14328
14329
14330
14331
14332
14333
14334
14335
14336
14337
14338
14339
14340
14341
14342
14343
14344
14345
14346
14347
14348
14349
14350
14351
14352
14353
14354
14355
14356
14357
14358
14359
14360
14361
14362
14363
14364
14365
14366
14367
14368
14369
14370
14371
14372
14373
14374
14375
14376
14377
14378
14379
14380
14381
14382
14383
14384
14385
14386
14387
14388
14389
14390
14391
14392
14393
14394
14395
14396
14397
14398
14399
14400
14401
14402
14403
14404
14405
14406
14407
14408
14409
14410
14411
14412
14413
14414
14415
14416
14417
14418
14419
14420
14421
14422
14423
14424
14425
14426
14427
14428
14429
14430
14431
14432
14433
14434
14435
14436
14437
14438
14439
14440
14441
14442
14443
14444
14445
14446
14447
14448
14449
14450
14451
14452
14453
14454
14455
14456
14457
14458
14459
14460
14461
14462
14463
14464
14465
14466
14467
14468
14469
14470
14471
14472
14473
14474
14475
14476
14477
14478
14479
14480
14481
14482
14483
14484
14485
14486
14487
14488
14489
14490
14491
14492
14493
14494
14495
14496
14497
14498
14499
14500
14501
14502
14503
14504
14505
14506
14507
14508
14509
14510
14511
14512
14513
14514
14515
14516
14517
14518
14519
14520
14521
14522
14523
14524
14525
14526
14527
14528
14529
14530
14531
14532
14533
14534
14535
14536
14537
14538
14539
14540
14541
14542
14543
14544
14545
14546
14547
14548
14549
14550
14551
14552
14553
14554
14555
14556
14557
14558
14559
14560
14561
14562
14563
14564
14565
14566
14567
14568
14569
14570
14571
14572
14573
14574
14575
14576
14577
14578
14579
14580
14581
14582
14583
14584
14585
14586
14587
14588
14589
14590
14591
14592
14593
14594
14595
14596
14597
14598
14599
14600
14601
14602
14603
14604
14605
14606
14607
14608
14609
14610
14611
14612
14613
14614
14615
14616
14617
14618
14619
14620
14621
14622
14623
14624
14625
14626
14627
14628
14629
14630
14631
14632
14633
14634
14635
14636
14637
14638
14639
14640
14641
14642
14643
14644
14645
14646
14647
14648
14649
14650
14651
14652
14653
14654
14655
14656
14657
14658
14659
14660
14661
14662
14663
14664
14665
14666
14667
14668
14669
14670
14671
14672
14673
14674
14675
14676
14677
14678
14679
14680
14681
14682
14683
14684
14685
14686
14687
14688
14689
14690
14691
14692
14693
14694
14695
14696
14697
14698
14699
14700
14701
14702
14703
14704
14705
14706
14707
14708
14709
14710
14711
14712
14713
14714
14715
14716
14717
14718
14719
14720
14721
14722
14723
14724
14725
14726
14727
14728
14729
14730
14731
14732
14733
14734
14735
14736
14737
14738
14739
14740
14741
14742
14743
14744
14745
14746
14747
14748
14749
14750
14751
14752
14753
14754
14755
14756
14757
14758
14759
14760
14761
14762
14763
14764
14765
14766
14767
14768
14769
14770
14771
14772
14773
14774
14775
14776
14777
14778
14779
14780
14781
14782
14783
14784
14785
14786
14787
14788
14789
14790
14791
14792
14793
14794
14795
14796
14797
14798
14799
14800
14801
14802
14803
14804
14805
14806
14807
14808
14809
14810
14811
14812
14813
14814
14815
14816
14817
14818
14819
14820
14821
14822
14823
14824
14825
14826
14827
14828
14829
14830
14831
14832
14833
14834
14835
14836
14837
14838
14839
14840
14841
14842
14843
14844
14845
14846
14847
14848
14849
14850
14851
14852
14853
14854
14855
14856
14857
14858
14859
14860
14861
14862
14863
14864
14865
14866
14867
14868
14869
14870
14871
14872
14873
14874
14875
14876
14877
14878
14879
14880
14881
14882
14883
14884
14885
14886
14887
14888
14889
14890
14891
14892
14893
14894
14895
14896
14897
14898
14899
14900
14901
14902
14903
14904
14905
14906
14907
14908
14909
14910
14911
14912
14913
14914
14915
14916
14917
14918
14919
14920
14921
14922
14923
14924
14925
14926
14927
14928
14929
14930
14931
14932
14933
14934
14935
14936
14937
14938
14939
14940
14941
14942
14943
14944
14945
14946
14947
14948
14949
14950
14951
14952
14953
14954
14955
14956
14957
14958
14959
14960
14961
14962
14963
14964
14965
14966
14967
14968
14969
14970
14971
14972
14973
14974
14975
14976
14977
14978
14979
14980
14981
14982
14983
14984
14985
14986
14987
14988
14989
14990
14991
14992
14993
14994
14995
14996
14997
14998
14999
15000
15001
15002
15003
15004
15005
15006
15007
15008
15009
15010
15011
15012
15013
15014
15015
15016
15017
15018
15019
15020
15021
15022
15023
15024
15025
15026
15027
15028
15029
15030
15031
15032
15033
15034
15035
15036
15037
15038
15039
15040
15041
15042
15043
15044
15045
15046
15047
15048
15049
15050
15051
15052
15053
15054
15055
15056
15057
15058
15059
15060
15061
15062
15063
15064
15065
15066
15067
15068
15069
15070
15071
15072
15073
15074
15075
15076
15077
15078
15079
15080
15081
15082
15083
15084
15085
15086
15087
15088
15089
15090
15091
15092
15093
15094
15095
15096
15097
15098
15099
15100
15101
15102
15103
15104
15105
15106
15107
15108
15109
15110
15111
15112
15113
15114
15115
15116
15117
15118
15119
15120
15121
15122
15123
15124
15125
15126
15127
15128
15129
15130
15131
15132
15133
15134
15135
15136
15137
15138
15139
15140
15141
15142
15143
15144
15145
15146
15147
15148
15149
15150
15151
15152
15153
15154
15155
15156
15157
15158
15159
15160
15161
15162
15163
15164
15165
15166
15167
15168
15169
15170
15171
15172
15173
15174
15175
15176
15177
15178
15179
15180
15181
15182
15183
15184
15185
15186
15187
15188
15189
15190
15191
15192
15193
15194
15195
15196
15197
15198
15199
15200
15201
15202
15203
15204
15205
15206
15207
15208
15209
15210
15211
15212
15213
15214
15215
15216
15217
15218
15219
15220
15221
15222
15223
15224
15225
15226
15227
15228
15229
15230
15231
15232
15233
15234
15235
15236
15237
15238
15239
15240
15241
15242
15243
15244
15245
15246
15247
15248
15249
15250
15251
15252
15253
15254
15255
15256
15257
15258
15259
15260
15261
15262
15263
15264
15265
15266
15267
15268
15269
15270
15271
15272
15273
15274
15275
15276
15277
15278
15279
15280
15281
15282
15283
15284
15285
15286
15287
15288
15289
15290
15291
15292
15293
15294
15295
15296
15297
15298
15299
15300
15301
15302
15303
15304
15305
15306
15307
15308
15309
15310
15311
15312
15313
15314
15315
15316
15317
15318
15319
15320
15321
15322
15323
15324
15325
15326
15327
15328
15329
15330
15331
15332
15333
15334
15335
15336
15337
15338
15339
15340
15341
15342
15343
15344
15345
15346
15347
15348
15349
15350
15351
15352
15353
15354
15355
15356
15357
15358
15359
15360
15361
15362
15363
15364
15365
15366
15367
15368
15369
15370
15371
15372
15373
15374
15375
15376
15377
15378
15379
15380
15381
15382
15383
15384
15385
15386
15387
15388
15389
15390
15391
15392
15393
15394
15395
15396
15397
15398
15399
15400
15401
15402
15403
15404
15405
15406
15407
15408
15409
15410
15411
15412
15413
15414
15415
15416
15417
15418
15419
15420
15421
15422
15423
15424
15425
15426
15427
15428
15429
15430
15431
15432
15433
15434
15435
15436
15437
15438
15439
15440
15441
15442
15443
15444
15445
15446
15447
15448
15449
15450
15451
15452
15453
15454
15455
15456
15457
15458
15459
15460
15461
15462
15463
15464
15465
15466
15467
15468
15469
15470
15471
15472
15473
15474
15475
15476
15477
15478
15479
15480
15481
15482
15483
15484
15485
15486
15487
15488
15489
15490
15491
15492
15493
15494
15495
15496
15497
15498
15499
15500
15501
15502
15503
15504
15505
15506
15507
15508
15509
15510
15511
15512
15513
15514
15515
15516
15517
15518
15519
15520
15521
15522
15523
15524
15525
15526
15527
15528
15529
15530
15531
15532
15533
15534
15535
15536
15537
15538
15539
15540
15541
15542
15543
15544
15545
15546
15547
15548
15549
15550
15551
15552
15553
15554
15555
15556
15557
15558
15559
15560
15561
15562
15563
15564
15565
15566
15567
15568
15569
15570
15571
15572
15573
15574
15575
15576
15577
15578
15579
15580
15581
15582
15583
15584
15585
15586
15587
15588
15589
15590
15591
15592
15593
15594
15595
15596
15597
15598
15599
15600
15601
15602
15603
15604
15605
15606
15607
15608
15609
15610
15611
15612
15613
15614
15615
15616
15617
15618
15619
15620
15621
15622
15623
15624
15625
15626
15627
15628
15629
15630
15631
15632
15633
15634
15635
15636
15637
15638
15639
15640
15641
15642
15643
15644
15645
15646
15647
15648
15649
15650
15651
15652
15653
15654
15655
15656
15657
15658
15659
15660
15661
15662
15663
15664
15665
15666
15667
15668
15669
15670
15671
15672
15673
15674
15675
15676
15677
15678
15679
15680
15681
15682
15683
15684
15685
15686
15687
15688
15689
15690
15691
15692
15693
15694
15695
15696
15697
15698
15699
15700
15701
15702
15703
15704
15705
15706
15707
15708
15709
15710
15711
15712
15713
15714
15715
15716
15717
15718
15719
15720
15721
15722
15723
15724
15725
15726
15727
15728
15729
15730
15731
15732
15733
15734
15735
15736
15737
15738
15739
15740
15741
15742
15743
15744
15745
15746
15747
15748
15749
15750
15751
15752
15753
15754
15755
15756
15757
15758
15759
15760
15761
15762
15763
15764
15765
15766
15767
15768
15769
15770
15771
15772
15773
15774
15775
15776
15777
15778
15779
15780
15781
15782
15783
15784
15785
15786
15787
15788
15789
15790
15791
15792
15793
15794
15795
15796
15797
15798
15799
15800
15801
15802
15803
15804
15805
15806
15807
15808
15809
15810
15811
15812
15813
15814
15815
15816
15817
15818
15819
15820
15821
15822
15823
15824
15825
15826
15827
15828
15829
15830
15831
15832
15833
15834
15835
15836
15837
15838
15839
15840
15841
15842
15843
15844
15845
15846
15847
15848
15849
15850
15851
15852
15853
15854
15855
15856
15857
15858
15859
15860
15861
15862
15863
15864
15865
15866
15867
15868
15869
15870
15871
15872
15873
15874
15875
15876
15877
15878
15879
15880
15881
15882
15883
15884
15885
15886
15887
15888
15889
15890
15891
15892
15893
15894
15895
15896
15897
15898
15899
15900
15901
15902
15903
15904
15905
15906
15907
15908
15909
15910
15911
15912
15913
15914
15915
15916
15917
15918
15919
15920
15921
15922
15923
15924
15925
15926
15927
15928
15929
15930
15931
15932
15933
15934
15935
15936
15937
15938
15939
15940
15941
15942
15943
15944
15945
15946
15947
15948
15949
15950
15951
15952
15953
15954
15955
15956
15957
15958
15959
15960
15961
15962
15963
15964
15965
15966
15967
15968
15969
15970
15971
15972
15973
15974
15975
15976
15977
15978
15979
15980
15981
15982
15983
15984
15985
15986
15987
15988
15989
15990
15991
15992
15993
15994
15995
15996
15997
15998
15999
16000
16001
16002
16003
16004
16005
16006
16007
16008
16009
16010
16011
16012
16013
16014
16015
16016
16017
16018
16019
16020
16021
16022
16023
16024
16025
16026
16027
16028
16029
16030
16031
16032
16033
16034
16035
16036
16037
16038
16039
16040
16041
16042
16043
16044
16045
16046
16047
16048
16049
16050
16051
16052
16053
16054
16055
16056
16057
16058
16059
16060
16061
16062
16063
16064
16065
16066
16067
16068
16069
16070
16071
16072
16073
16074
16075
16076
16077
16078
16079
16080
16081
16082
16083
16084
16085
16086
16087
16088
16089
16090
16091
16092
16093
16094
16095
16096
16097
16098
16099
16100
16101
16102
16103
16104
16105
16106
16107
16108
16109
16110
16111
16112
16113
16114
16115
16116
16117
16118
16119
16120
16121
16122
16123
16124
16125
16126
16127
16128
16129
16130
16131
16132
16133
16134
16135
16136
16137
16138
16139
16140
16141
16142
16143
16144
16145
16146
16147
16148
16149
16150
16151
16152
16153
16154
16155
16156
16157
16158
16159
16160
16161
16162
16163
16164
16165
16166
16167
16168
16169
16170
16171
16172
16173
16174
16175
16176
16177
16178
16179
16180
16181
16182
16183
16184
16185
16186
16187
16188
16189
16190
16191
16192
16193
16194
16195
16196
16197
16198
16199
16200
16201
16202
16203
16204
16205
16206
16207
16208
16209
16210
16211
16212
16213
16214
16215
16216
16217
16218
16219
16220
16221
16222
16223
16224
16225
16226
16227
16228
16229
16230
16231
16232
16233
16234
16235
16236
16237
16238
16239
16240
16241
16242
16243
16244
16245
16246
16247
16248
16249
16250
16251
16252
16253
16254
16255
16256
16257
16258
16259
16260
16261
16262
16263
16264
16265
16266
16267
16268
16269
16270
16271
16272
16273
16274
16275
16276
16277
16278
16279
16280
16281
16282
16283
16284
16285
16286
16287
16288
16289
16290
16291
16292
16293
16294
16295
16296
16297
16298
16299
16300
16301
16302
16303
16304
16305
16306
16307
16308
16309
16310
16311
16312
16313
16314
16315
16316
16317
16318
16319
16320
16321
16322
16323
16324
16325
16326
16327
16328
16329
16330
16331
16332
16333
16334
16335
16336
16337
16338
16339
16340
16341
16342
16343
16344
16345
16346
16347
16348
16349
16350
16351
16352
16353
16354
16355
16356
16357
16358
16359
16360
16361
16362
16363
16364
16365
16366
16367
16368
16369
16370
16371
16372
16373
16374
16375
16376
16377
16378
16379
16380
16381
16382
16383
16384
16385
16386
16387
16388
16389
16390
16391
16392
16393
16394
16395
16396
16397
16398
16399
16400
16401
16402
16403
16404
16405
16406
16407
16408
16409
16410
16411
16412
16413
16414
16415
16416
16417
16418
16419
16420
16421
16422
16423
16424
16425
16426
16427
16428
16429
16430
16431
16432
16433
16434
16435
16436
16437
16438
16439
16440
16441
16442
16443
16444
16445
16446
16447
16448
16449
16450
16451
16452
16453
16454
16455
16456
16457
16458
16459
16460
16461
16462
16463
16464
16465
16466
16467
16468
16469
16470
16471
16472
16473
16474
16475
16476
16477
16478
16479
16480
16481
16482
16483
16484
16485
16486
16487
16488
16489
16490
16491
16492
16493
16494
16495
16496
16497
16498
16499
16500
16501
16502
16503
16504
16505
16506
16507
16508
16509
16510
16511
16512
16513
16514
16515
16516
16517
16518
16519
16520
16521
16522
16523
16524
16525
16526
16527
16528
16529
16530
16531
16532
16533
16534
16535
16536
16537
16538
16539
16540
16541
16542
16543
16544
16545
16546
16547
16548
16549
16550
16551
16552
16553
16554
16555
16556
16557
16558
16559
16560
16561
16562
16563
16564
16565
16566
16567
16568
16569
16570
16571
16572
16573
16574
16575
16576
16577
16578
16579
16580
16581
16582
16583
16584
16585
16586
16587
16588
16589
16590
16591
16592
16593
16594
16595
16596
16597
16598
16599
16600
16601
16602
16603
16604
16605
16606
16607
16608
16609
16610
16611
16612
16613
16614
16615
16616
16617
16618
16619
16620
16621
16622
16623
16624
16625
16626
16627
16628
16629
16630
16631
16632
16633
16634
16635
16636
16637
16638
16639
16640
16641
16642
16643
16644
16645
16646
16647
16648
16649
16650
16651
16652
16653
16654
16655
16656
16657
16658
16659
16660
16661
16662
16663
16664
16665
16666
16667
16668
16669
16670
16671
16672
16673
16674
16675
16676
16677
16678
16679
16680
16681
16682
16683
16684
16685
16686
16687
16688
16689
16690
16691
16692
16693
16694
16695
16696
16697
16698
16699
16700
16701
16702
16703
16704
16705
16706
16707
16708
16709
16710
16711
16712
16713
16714
16715
16716
16717
16718
16719
16720
16721
16722
16723
16724
16725
16726
16727
16728
16729
16730
16731
16732
16733
16734
16735
16736
16737
16738
16739
16740
16741
16742
16743
16744
16745
16746
16747
16748
16749
16750
16751
16752
16753
16754
16755
16756
16757
16758
16759
16760
16761
16762
16763
16764
16765
16766
16767
16768
16769
16770
16771
16772
16773
16774
16775
16776
16777
16778
16779
16780
16781
16782
16783
16784
16785
16786
16787
16788
16789
16790
16791
16792
16793
16794
16795
16796
16797
16798
16799
16800
16801
16802
16803
16804
16805
16806
16807
16808
16809
16810
16811
16812
16813
16814
16815
16816
16817
16818
16819
16820
16821
16822
16823
16824
16825
16826
16827
16828
16829
16830
16831
16832
16833
16834
16835
16836
16837
16838
16839
16840
16841
16842
16843
16844
16845
16846
16847
16848
16849
16850
16851
16852
16853
16854
16855
16856
16857
16858
16859
16860
16861
16862
16863
16864
16865
16866
16867
16868
16869
16870
16871
16872
16873
16874
16875
16876
16877
16878
16879
16880
16881
16882
16883
16884
16885
16886
16887
16888
16889
16890
16891
16892
16893
16894
16895
16896
16897
16898
16899
16900
16901
16902
16903
16904
16905
16906
16907
16908
16909
16910
16911
16912
16913
16914
16915
16916
16917
16918
16919
16920
16921
16922
16923
16924
16925
16926
16927
16928
16929
16930
16931
16932
16933
16934
16935
16936
16937
16938
16939
16940
16941
16942
16943
16944
16945
16946
16947
16948
16949
16950
16951
16952
16953
16954
16955
16956
16957
16958
16959
16960
16961
16962
16963
16964
16965
16966
16967
16968
16969
16970
16971
16972
16973
16974
16975
16976
16977
16978
16979
16980
16981
16982
16983
16984
16985
16986
16987
16988
16989
16990
16991
16992
16993
16994
16995
16996
16997
16998
16999
17000
17001
17002
17003
17004
17005
17006
17007
17008
17009
17010
17011
17012
17013
17014
17015
17016
17017
17018
17019
17020
17021
17022
17023
17024
17025
17026
17027
17028
17029
17030
17031
17032
17033
17034
17035
17036
17037
17038
17039
17040
17041
17042
17043
17044
17045
17046
17047
17048
17049
17050
17051
17052
17053
17054
17055
17056
17057
17058
17059
17060
17061
17062
17063
17064
17065
17066
17067
17068
17069
17070
17071
17072
17073
17074
17075
17076
17077
17078
17079
17080
17081
17082
17083
17084
17085
17086
17087
17088
17089
17090
17091
17092
17093
17094
17095
17096
17097
17098
17099
17100
17101
17102
17103
17104
17105
17106
17107
17108
17109
17110
17111
17112
17113
17114
17115
17116
17117
17118
17119
17120
17121
17122
17123
17124
17125
17126
17127
17128
17129
17130
17131
17132
17133
17134
17135
17136
17137
17138
17139
17140
17141
17142
17143
17144
17145
17146
17147
17148
17149
17150
17151
17152
17153
17154
17155
17156
17157
17158
17159
17160
17161
17162
17163
17164
17165
17166
17167
17168
17169
17170
17171
17172
17173
17174
17175
17176
17177
17178
17179
17180
17181
17182
17183
17184
17185
17186
17187
17188
17189
17190
17191
17192
17193
17194
17195
17196
17197
17198
17199
17200
17201
17202
17203
17204
17205
17206
17207
17208
17209
17210
17211
17212
17213
17214
17215
17216
17217
17218
17219
17220
17221
17222
17223
17224
17225
17226
17227
17228
17229
17230
17231
17232
17233
17234
17235
17236
17237
17238
17239
17240
17241
17242
17243
17244
17245
17246
17247
17248
17249
17250
17251
17252
17253
17254
17255
17256
17257
17258
17259
17260
17261
17262
17263
17264
17265
17266
17267
17268
17269
17270
17271
17272
17273
17274
17275
17276
17277
17278
17279
17280
17281
17282
17283
17284
17285
17286
17287
17288
17289
17290
17291
17292
17293
17294
17295
17296
17297
17298
17299
17300
17301
17302
17303
17304
17305
17306
17307
17308
17309
17310
17311
17312
17313
17314
17315
17316
17317
17318
17319
17320
17321
17322
17323
17324
17325
17326
17327
17328
17329
17330
17331
17332
17333
17334
17335
17336
17337
17338
17339
17340
17341
17342
17343
17344
17345
17346
17347
17348
17349
17350
17351
17352
17353
17354
17355
17356
17357
17358
17359
17360
17361
17362
17363
17364
17365
17366
17367
17368
17369
17370
17371
17372
17373
17374
17375
17376
17377
17378
17379
17380
17381
17382
17383
17384
17385
17386
17387
17388
17389
17390
17391
17392
17393
17394
17395
17396
17397
17398
17399
17400
17401
17402
17403
17404
17405
17406
17407
17408
17409
17410
17411
17412
17413
17414
17415
17416
17417
17418
17419
17420
17421
17422
17423
17424
17425
17426
17427
17428
17429
17430
17431
17432
17433
17434
17435
17436
17437
17438
17439
17440
17441
17442
17443
17444
17445
17446
17447
17448
17449
17450
17451
17452
17453
17454
17455
17456
17457
17458
17459
17460
17461
17462
17463
17464
17465
17466
17467
17468
17469
17470
17471
17472
17473
17474
17475
17476
17477
17478
17479
17480
17481
17482
17483
17484
17485
17486
17487
17488
17489
17490
17491
17492
17493
17494
17495
17496
17497
17498
17499
17500
17501
17502
17503
17504
17505
17506
17507
17508
17509
17510
17511
17512
17513
17514
17515
17516
17517
17518
17519
17520
17521
17522
17523
17524
17525
17526
17527
17528
17529
17530
17531
17532
17533
17534
17535
17536
17537
17538
17539
17540
17541
17542
17543
17544
17545
17546
17547
17548
17549
17550
17551
17552
17553
17554
17555
17556
17557
17558
17559
17560
17561
17562
17563
17564
17565
17566
17567
17568
17569
17570
17571
17572
17573
17574
17575
17576
17577
17578
17579
17580
17581
17582
17583
17584
17585
17586
17587
17588
17589
17590
17591
17592
17593
17594
17595
17596
17597
17598
17599
17600
17601
17602
17603
17604
17605
17606
17607
17608
17609
17610
17611
17612
17613
17614
17615
17616
17617
17618
17619
17620
17621
17622
17623
17624
17625
17626
17627
17628
17629
17630
17631
17632
17633
17634
17635
17636
17637
17638
17639
17640
17641
17642
17643
17644
17645
17646
17647
17648
17649
17650
17651
17652
17653
17654
17655
17656
17657
17658
17659
17660
17661
17662
17663
17664
17665
17666
17667
17668
17669
17670
17671
17672
17673
17674
17675
17676
17677
17678
17679
17680
17681
17682
17683
17684
17685
17686
17687
17688
17689
17690
17691
17692
17693
17694
17695
17696
17697
17698
17699
17700
17701
17702
17703
17704
17705
17706
17707
17708
17709
17710
17711
17712
17713
17714
17715
17716
17717
17718
17719
17720
17721
17722
17723
17724
17725
17726
17727
17728
17729
17730
17731
17732
17733
17734
17735
17736
17737
17738
17739
17740
17741
17742
17743
17744
17745
17746
17747
17748
17749
17750
17751
17752
17753
17754
17755
17756
17757
17758
17759
17760
17761
17762
17763
17764
17765
17766
17767
17768
17769
17770
17771
17772
17773
17774
17775
17776
17777
17778
17779
17780
17781
17782
17783
17784
17785
17786
17787
17788
17789
17790
17791
17792
17793
17794
17795
17796
17797
17798
17799
17800
17801
17802
17803
17804
17805
17806
17807
17808
17809
17810
17811
17812
17813
17814
17815
17816
17817
17818
17819
17820
17821
17822
17823
17824
17825
17826
17827
17828
17829
17830
17831
17832
17833
17834
17835
17836
17837
17838
17839
17840
17841
17842
17843
17844
17845
17846
17847
17848
17849
17850
17851
17852
17853
17854
17855
17856
17857
17858
17859
17860
17861
17862
17863
17864
17865
17866
17867
17868
17869
17870
17871
17872
17873
17874
17875
17876
17877
17878
17879
17880
17881
17882
17883
17884
17885
17886
17887
17888
17889
17890
17891
17892
17893
17894
17895
17896
17897
17898
17899
17900
17901
17902
17903
17904
17905
17906
17907
17908
17909
17910
17911
17912
17913
17914
17915
17916
17917
17918
17919
17920
17921
17922
17923
17924
17925
17926
17927
17928
17929
17930
17931
17932
17933
17934
17935
17936
17937
17938
17939
17940
17941
17942
17943
17944
17945
17946
17947
17948
17949
17950
17951
17952
17953
17954
17955
17956
17957
17958
17959
17960
17961
17962
17963
17964
17965
17966
17967
17968
17969
17970
17971
17972
17973
17974
17975
17976
17977
17978
17979
17980
17981
17982
17983
17984
17985
17986
17987
17988
17989
17990
17991
17992
17993
17994
17995
17996
17997
17998
17999
18000
18001
18002
18003
18004
18005
18006
18007
18008
18009
18010
18011
18012
18013
18014
18015
18016
18017
18018
18019
18020
18021
18022
18023
18024
18025
18026
18027
18028
18029
18030
18031
18032
18033
18034
18035
18036
18037
18038
18039
18040
18041
18042
18043
18044
18045
18046
18047
18048
18049
18050
18051
18052
18053
18054
18055
18056
18057
18058
18059
18060
18061
18062
18063
18064
18065
18066
18067
18068
18069
18070
18071
18072
18073
18074
18075
18076
18077
18078
18079
18080
18081
18082
18083
18084
18085
18086
18087
18088
18089
18090
18091
18092
18093
18094
18095
18096
18097
18098
18099
18100
18101
18102
18103
18104
18105
18106
18107
18108
18109
18110
18111
18112
18113
18114
18115
18116
18117
18118
18119
18120
18121
18122
18123
18124
18125
18126
18127
18128
18129
18130
18131
18132
18133
18134
18135
18136
18137
18138
18139
18140
18141
18142
18143
18144
18145
18146
18147
18148
18149
18150
18151
18152
18153
18154
18155
18156
18157
18158
18159
18160
18161
18162
18163
18164
18165
18166
18167
18168
18169
18170
18171
18172
18173
18174
18175
18176
18177
18178
18179
18180
18181
18182
18183
18184
18185
18186
18187
18188
18189
18190
18191
18192
18193
18194
18195
18196
18197
18198
18199
18200
18201
18202
18203
18204
18205
18206
18207
18208
18209
18210
18211
18212
18213
18214
18215
18216
18217
18218
18219
18220
18221
18222
18223
18224
18225
18226
18227
18228
18229
18230
18231
18232
18233
18234
18235
18236
18237
18238
18239
18240
18241
18242
18243
18244
18245
18246
18247
18248
18249
18250
18251
18252
18253
18254
18255
18256
18257
18258
18259
18260
18261
18262
18263
18264
18265
18266
18267
18268
18269
18270
18271
18272
18273
18274
18275
18276
18277
18278
18279
18280
18281
18282
18283
18284
18285
18286
18287
18288
18289
18290
18291
18292
18293
18294
18295
18296
18297
18298
18299
18300
18301
18302
18303
18304
18305
18306
18307
18308
18309
18310
18311
18312
18313
18314
18315
18316
18317
18318
18319
18320
18321
18322
18323
18324
18325
18326
18327
18328
18329
18330
18331
18332
18333
18334
18335
18336
18337
18338
18339
18340
18341
18342
18343
18344
18345
18346
18347
18348
18349
18350
18351
18352
18353
18354
18355
18356
18357
18358
18359
18360
18361
18362
18363
18364
18365
18366
18367
18368
18369
18370
18371
18372
18373
18374
18375
18376
18377
18378
18379
18380
18381
18382
18383
18384
18385
18386
18387
18388
18389
18390
18391
18392
18393
18394
18395
18396
18397
18398
18399
18400
18401
18402
18403
18404
18405
18406
18407
18408
18409
18410
18411
18412
18413
18414
18415
18416
18417
18418
18419
18420
18421
18422
18423
18424
18425
18426
18427
18428
18429
18430
18431
18432
18433
18434
18435
18436
18437
18438
18439
18440
18441
18442
18443
18444
18445
18446
18447
18448
18449
18450
18451
18452
18453
18454
18455
18456
18457
18458
18459
18460
18461
18462
18463
18464
18465
18466
18467
18468
18469
18470
18471
18472
18473
18474
18475
18476
18477
18478
18479
18480
18481
18482
18483
18484
18485
18486
18487
18488
18489
18490
18491
18492
18493
18494
18495
18496
18497
18498
18499
18500
18501
18502
18503
18504
18505
18506
18507
18508
18509
18510
18511
18512
18513
18514
18515
18516
18517
18518
18519
18520
18521
18522
18523
18524
18525
18526
18527
18528
18529
18530
18531
18532
18533
18534
18535
18536
18537
18538
18539
18540
18541
18542
18543
18544
18545
18546
18547
18548
18549
18550
18551
18552
18553
18554
18555
18556
18557
18558
18559
18560
18561
18562
18563
18564
18565
18566
18567
18568
18569
18570
18571
18572
18573
18574
18575
18576
18577
18578
18579
18580
18581
18582
18583
18584
18585
18586
18587
18588
18589
18590
18591
18592
18593
18594
18595
18596
18597
18598
18599
18600
18601
18602
18603
18604
18605
18606
18607
18608
18609
18610
18611
18612
18613
18614
18615
18616
18617
18618
18619
18620
18621
18622
18623
18624
18625
18626
18627
18628
18629
18630
18631
18632
18633
18634
18635
18636
18637
18638
18639
18640
18641
18642
18643
18644
18645
18646
18647
18648
18649
18650
18651
18652
18653
18654
18655
18656
18657
18658
18659
18660
18661
18662
18663
18664
18665
18666
18667
18668
18669
18670
18671
18672
18673
18674
18675
18676
18677
18678
18679
18680
18681
18682
18683
18684
18685
18686
18687
18688
18689
18690
18691
18692
18693
18694
18695
18696
18697
18698
18699
18700
18701
18702
18703
18704
18705
18706
18707
18708
18709
18710
18711
18712
18713
18714
18715
18716
18717
18718
18719
18720
18721
18722
18723
18724
18725
18726
18727
18728
18729
18730
18731
18732
18733
18734
18735
18736
18737
18738
18739
18740
18741
18742
18743
18744
18745
18746
18747
18748
18749
18750
18751
18752
18753
18754
18755
18756
18757
18758
18759
18760
18761
18762
18763
18764
18765
18766
18767
18768
18769
18770
18771
18772
18773
18774
18775
18776
18777
18778
18779
18780
18781
18782
18783
18784
18785
18786
18787
18788
18789
18790
18791
18792
18793
18794
18795
18796
18797
18798
18799
18800
18801
18802
18803
18804
18805
18806
18807
18808
18809
18810
18811
18812
18813
18814
18815
18816
18817
18818
18819
18820
18821
18822
18823
18824
18825
18826
18827
18828
18829
18830
18831
18832
18833
18834
18835
18836
18837
18838
18839
18840
18841
18842
18843
18844
18845
18846
18847
18848
18849
18850
18851
18852
18853
18854
18855
18856
18857
18858
18859
18860
18861
18862
18863
18864
18865
18866
18867
18868
18869
18870
18871
18872
18873
18874
18875
18876
18877
18878
18879
18880
18881
18882
18883
18884
18885
18886
18887
18888
18889
18890
18891
18892
18893
18894
18895
18896
18897
18898
18899
18900
18901
18902
18903
18904
18905
18906
18907
18908
18909
18910
18911
18912
18913
18914
18915
18916
18917
18918
18919
18920
18921
18922
18923
18924
18925
18926
18927
18928
18929
18930
18931
18932
18933
18934
18935
18936
18937
18938
18939
18940
18941
18942
18943
18944
18945
18946
18947
18948
18949
18950
18951
18952
18953
18954
18955
18956
18957
18958
18959
18960
18961
18962
18963
18964
18965
18966
18967
18968
18969
18970
18971
18972
18973
18974
18975
18976
18977
18978
18979
18980
18981
18982
18983
18984
18985
18986
18987
18988
18989
18990
18991
18992
18993
18994
18995
18996
18997
18998
18999
19000
19001
19002
19003
19004
19005
19006
19007
19008
19009
19010
19011
19012
19013
19014
19015
19016
19017
19018
19019
19020
19021
19022
19023
19024
19025
19026
19027
19028
19029
19030
19031
19032
19033
19034
19035
19036
19037
19038
19039
19040
19041
19042
19043
19044
19045
19046
19047
19048
19049
19050
19051
19052
19053
19054
19055
19056
19057
19058
19059
19060
19061
19062
19063
19064
19065
19066
19067
19068
19069
19070
19071
19072
19073
19074
19075
19076
19077
19078
19079
19080
19081
19082
19083
19084
19085
19086
19087
19088
19089
19090
19091
19092
19093
19094
19095
19096
19097
19098
19099
19100
19101
19102
19103
19104
19105
19106
19107
19108
19109
19110
19111
19112
19113
19114
19115
19116
19117
19118
19119
19120
19121
19122
19123
19124
19125
19126
19127
19128
19129
19130
19131
19132
19133
19134
19135
19136
19137
19138
19139
19140
19141
19142
19143
19144
19145
19146
19147
19148
19149
19150
19151
19152
19153
19154
19155
19156
19157
19158
19159
19160
19161
19162
19163
19164
19165
19166
19167
19168
19169
19170
19171
19172
19173
19174
19175
19176
19177
19178
19179
19180
19181
19182
19183
19184
19185
19186
19187
19188
19189
19190
19191
19192
19193
19194
19195
19196
19197
19198
19199
19200
19201
19202
19203
19204
19205
19206
19207
19208
19209
19210
19211
19212
19213
19214
19215
19216
19217
19218
19219
19220
19221
19222
19223
19224
19225
19226
19227
19228
19229
19230
19231
19232
19233
19234
19235
19236
19237
19238
19239
19240
19241
19242
19243
19244
19245
19246
19247
19248
19249
19250
19251
19252
19253
19254
19255
19256
19257
19258
19259
19260
19261
19262
19263
19264
19265
19266
19267
19268
19269
19270
19271
19272
19273
19274
19275
19276
19277
19278
19279
19280
19281
19282
19283
19284
19285
19286
19287
19288
19289
19290
19291
19292
19293
19294
19295
19296
19297
19298
19299
19300
19301
19302
19303
19304
19305
19306
19307
19308
19309
19310
19311
19312
19313
19314
19315
19316
19317
19318
19319
19320
19321
19322
19323
19324
19325
19326
19327
19328
19329
19330
19331
19332
19333
19334
19335
19336
19337
19338
19339
19340
19341
19342
19343
19344
19345
19346
19347
19348
19349
19350
19351
19352
19353
19354
19355
19356
19357
19358
19359
19360
19361
19362
19363
19364
19365
19366
19367
19368
19369
19370
19371
19372
19373
19374
19375
19376
19377
19378
19379
19380
19381
19382
19383
19384
19385
19386
19387
19388
19389
19390
19391
19392
19393
19394
19395
19396
19397
19398
19399
19400
19401
19402
19403
19404
19405
19406
19407
19408
19409
19410
19411
19412
19413
19414
19415
19416
19417
19418
19419
19420
19421
19422
19423
19424
19425
19426
19427
19428
19429
19430
19431
19432
19433
19434
19435
19436
19437
19438
19439
19440
19441
19442
19443
19444
19445
19446
19447
19448
19449
19450
19451
19452
19453
19454
19455
19456
19457
19458
19459
19460
19461
19462
19463
19464
19465
19466
19467
19468
19469
19470
19471
19472
19473
19474
19475
19476
19477
19478
19479
19480
19481
19482
19483
19484
19485
19486
19487
19488
19489
19490
19491
19492
19493
19494
19495
19496
19497
19498
19499
19500
19501
19502
19503
19504
19505
19506
19507
19508
19509
19510
19511
19512
19513
19514
19515
19516
19517
19518
19519
19520
19521
19522
19523
19524
19525
19526
19527
19528
19529
19530
19531
19532
19533
19534
19535
19536
19537
19538
19539
19540
19541
19542
19543
19544
19545
19546
19547
19548
19549
19550
19551
19552
19553
19554
19555
19556
19557
19558
19559
19560
19561
19562
19563
19564
19565
19566
19567
19568
19569
19570
19571
19572
19573
19574
19575
19576
19577
19578
19579
19580
19581
19582
19583
19584
19585
19586
19587
19588
19589
19590
19591
19592
19593
19594
19595
19596
19597
19598
19599
19600
19601
19602
19603
19604
19605
19606
19607
19608
19609
19610
19611
19612
19613
19614
19615
19616
19617
19618
19619
19620
19621
19622
19623
19624
19625
19626
19627
19628
19629
19630
19631
19632
19633
19634
19635
19636
19637
19638
19639
19640
19641
19642
19643
19644
19645
19646
19647
19648
19649
19650
19651
19652
19653
19654
19655
19656
19657
19658
19659
19660
19661
19662
19663
19664
19665
19666
19667
19668
19669
19670
19671
19672
19673
19674
19675
19676
19677
19678
19679
19680
19681
19682
19683
19684
19685
19686
19687
19688
19689
19690
19691
19692
19693
19694
19695
19696
19697
19698
19699
19700
19701
19702
19703
19704
19705
19706
19707
19708
19709
19710
19711
19712
19713
19714
19715
19716
19717
19718
19719
19720
19721
19722
19723
19724
19725
19726
19727
19728
19729
19730
19731
19732
19733
19734
19735
19736
19737
19738
19739
19740
19741
19742
19743
19744
19745
19746
19747
19748
19749
19750
19751
19752
19753
19754
19755
19756
19757
19758
19759
19760
19761
19762
19763
19764
19765
19766
19767
19768
19769
19770
19771
19772
19773
19774
19775
19776
19777
19778
19779
19780
19781
19782
19783
19784
19785
19786
19787
19788
19789
19790
19791
19792
19793
19794
19795
19796
19797
19798
19799
19800
19801
19802
19803
19804
19805
19806
19807
19808
19809
19810
19811
19812
19813
19814
19815
19816
19817
19818
19819
19820
19821
19822
19823
19824
19825
19826
19827
19828
19829
19830
19831
19832
19833
19834
19835
19836
19837
19838
19839
19840
19841
19842
19843
19844
19845
19846
19847
19848
19849
19850
19851
19852
19853
19854
19855
19856
19857
19858
19859
19860
19861
19862
19863
19864
19865
19866
19867
19868
19869
19870
19871
19872
19873
19874
19875
19876
19877
19878
19879
19880
19881
19882
19883
19884
19885
19886
19887
19888
19889
19890
19891
19892
19893
19894
19895
19896
19897
19898
19899
19900
19901
19902
19903
19904
19905
19906
19907
19908
19909
19910
19911
19912
19913
19914
19915
19916
19917
19918
19919
19920
19921
19922
19923
19924
19925
19926
19927
19928
19929
19930
19931
19932
19933
19934
19935
19936
19937
19938
19939
19940
19941
19942
19943
19944
19945
19946
19947
19948
19949
19950
19951
19952
19953
19954
19955
19956
19957
19958
19959
19960
19961
19962
19963
19964
19965
19966
19967
19968
19969
19970
19971
19972
19973
19974
19975
19976
19977
19978
19979
19980
19981
19982
19983
19984
19985
19986
19987
19988
19989
19990
19991
19992
19993
19994
19995
19996
19997
19998
19999
20000
20001
20002
20003
20004
20005
20006
20007
20008
20009
20010
20011
20012
20013
20014
20015
20016
20017
20018
20019
20020
20021
20022
20023
20024
20025
20026
20027
20028
20029
20030
20031
20032
20033
20034
20035
20036
20037
20038
20039
20040
20041
20042
20043
20044
20045
20046
20047
20048
20049
20050
20051
20052
20053
20054
20055
20056
20057
20058
20059
20060
20061
20062
20063
20064
20065
20066
20067
20068
20069
20070
20071
20072
20073
20074
20075
20076
20077
20078
20079
20080
20081
20082
20083
20084
20085
20086
20087
20088
20089
20090
20091
20092
20093
20094
20095
20096
20097
20098
20099
20100
20101
20102
20103
20104
20105
20106
20107
20108
20109
20110
20111
20112
20113
20114
20115
20116
20117
20118
20119
20120
20121
20122
20123
20124
20125
20126
20127
20128
20129
20130
20131
20132
20133
20134
20135
20136
20137
20138
20139
20140
20141
20142
20143
20144
20145
20146
20147
20148
20149
20150
20151
20152
20153
20154
20155
20156
20157
20158
20159
20160
20161
20162
20163
20164
20165
20166
20167
20168
20169
20170
20171
20172
20173
20174
20175
20176
20177
20178
20179
20180
20181
20182
20183
20184
20185
20186
20187
20188
20189
20190
20191
20192
20193
20194
20195
20196
20197
20198
20199
20200
20201
20202
20203
20204
20205
20206
20207
20208
20209
20210
20211
20212
20213
20214
20215
20216
20217
20218
20219
20220
20221
20222
20223
20224
20225
20226
20227
20228
20229
20230
20231
20232
20233
20234
20235
20236
20237
20238
20239
20240
20241
20242
20243
20244
20245
20246
20247
20248
20249
20250
20251
20252
20253
20254
20255
20256
20257
20258
20259
20260
20261
20262
20263
20264
20265
20266
20267
20268
20269
20270
20271
20272
20273
20274
20275
20276
20277
20278
20279
20280
20281
20282
20283
20284
20285
20286
20287
20288
20289
20290
20291
20292
20293
20294
20295
20296
20297
20298
20299
20300
20301
20302
20303
20304
20305
20306
20307
20308
20309
20310
20311
20312
20313
20314
20315
20316
20317
20318
20319
20320
20321
20322
20323
20324
20325
20326
20327
20328
20329
20330
20331
20332
20333
20334
20335
20336
20337
20338
20339
20340
20341
20342
20343
20344
20345
20346
20347
20348
20349
20350
20351
20352
20353
20354
20355
20356
20357
20358
20359
20360
20361
20362
20363
20364
20365
20366
20367
20368
20369
20370
20371
20372
20373
20374
20375
20376
20377
20378
20379
20380
20381
20382
20383
20384
20385
20386
20387
20388
20389
20390
20391
20392
20393
20394
20395
20396
20397
20398
20399
20400
20401
20402
20403
20404
20405
20406
20407
20408
20409
20410
20411
20412
20413
20414
20415
20416
20417
20418
20419
20420
20421
20422
20423
20424
20425
20426
20427
20428
20429
20430
20431
20432
20433
20434
20435
20436
20437
20438
20439
20440
20441
20442
20443
20444
20445
20446
20447
20448
20449
20450
20451
20452
20453
20454
20455
20456
20457
20458
20459
20460
20461
20462
20463
20464
20465
20466
20467
20468
20469
20470
20471
20472
20473
20474
20475
20476
20477
20478
20479
20480
20481
20482
20483
20484
20485
20486
20487
20488
20489
20490
20491
20492
20493
20494
20495
20496
20497
20498
20499
20500
20501
20502
20503
20504
20505
20506
20507
20508
20509
20510
20511
20512
20513
20514
20515
20516
20517
20518
20519
20520
20521
20522
20523
20524
20525
20526
20527
20528
20529
20530
20531
20532
20533
20534
20535
20536
20537
20538
20539
20540
20541
20542
20543
20544
20545
20546
20547
20548
20549
20550
20551
20552
20553
20554
20555
20556
20557
20558
20559
20560
20561
20562
20563
20564
20565
20566
20567
20568
20569
20570
20571
20572
20573
20574
20575
20576
20577
20578
20579
20580
20581
20582
20583
20584
20585
20586
20587
20588
20589
20590
20591
20592
20593
20594
20595
20596
20597
20598
20599
20600
20601
20602
20603
20604
20605
20606
20607
20608
20609
20610
20611
20612
20613
20614
20615
20616
20617
20618
20619
20620
20621
20622
20623
20624
20625
20626
20627
20628
20629
20630
20631
20632
20633
20634
20635
20636
20637
20638
20639
20640
20641
20642
20643
20644
20645
20646
20647
20648
20649
20650
20651
20652
20653
20654
20655
20656
20657
20658
20659
20660
20661
20662
20663
20664
20665
20666
20667
20668
20669
20670
20671
20672
20673
20674
20675
20676
20677
20678
20679
20680
20681
20682
20683
20684
20685
20686
20687
20688
20689
20690
20691
20692
20693
20694
20695
20696
20697
20698
20699
20700
20701
20702
20703
20704
20705
20706
20707
20708
20709
20710
20711
20712
20713
20714
20715
20716
20717
20718
20719
20720
20721
20722
20723
20724
20725
20726
20727
20728
20729
20730
20731
20732
20733
20734
20735
20736
20737
20738
20739
20740
20741
20742
20743
20744
20745
20746
20747
20748
20749
20750
20751
20752
20753
20754
20755
20756
20757
20758
20759
20760
20761
20762
20763
20764
20765
20766
20767
20768
20769
20770
20771
20772
20773
20774
20775
20776
20777
20778
20779
20780
20781
20782
20783
20784
20785
20786
20787
20788
20789
20790
20791
20792
20793
20794
20795
20796
20797
20798
20799
20800
20801
20802
20803
20804
20805
20806
20807
20808
20809
20810
20811
20812
20813
20814
20815
20816
20817
20818
20819
20820
20821
20822
20823
20824
20825
20826
20827
20828
20829
20830
20831
20832
20833
20834
20835
20836
20837
20838
20839
20840
20841
20842
20843
20844
20845
20846
20847
20848
20849
20850
20851
20852
20853
20854
20855
20856
20857
20858
20859
20860
20861
20862
20863
20864
20865
20866
20867
20868
20869
20870
20871
20872
20873
20874
20875
20876
20877
20878
20879
20880
20881
20882
20883
20884
20885
20886
20887
20888
20889
20890
20891
20892
20893
20894
20895
20896
20897
20898
20899
20900
20901
20902
20903
20904
20905
20906
20907
20908
20909
20910
20911
20912
20913
20914
20915
20916
20917
20918
20919
20920
20921
20922
20923
20924
20925
20926
20927
20928
20929
20930
20931
20932
20933
20934
20935
20936
20937
20938
20939
20940
20941
20942
20943
20944
20945
20946
20947
20948
20949
20950
20951
20952
20953
20954
20955
20956
20957
20958
20959
20960
20961
20962
20963
20964
20965
20966
20967
20968
20969
20970
20971
20972
20973
20974
20975
20976
20977
20978
20979
20980
20981
20982
20983
20984
20985
20986
20987
20988
20989
20990
20991
20992
20993
20994
20995
20996
20997
20998
20999
21000
21001
21002
21003
21004
21005
21006
21007
21008
21009
21010
21011
21012
21013
21014
21015
21016
21017
21018
21019
21020
21021
21022
21023
21024
21025
21026
21027
21028
21029
21030
21031
21032
21033
21034
21035
21036
21037
21038
21039
21040
21041
21042
21043
21044
21045
21046
21047
21048
21049
21050
21051
21052
21053
21054
21055
21056
21057
21058
21059
21060
21061
21062
21063
21064
21065
21066
21067
21068
21069
21070
21071
21072
21073
21074
21075
21076
21077
21078
21079
21080
21081
21082
21083
21084
21085
21086
21087
21088
21089
21090
21091
21092
21093
21094
21095
21096
21097
21098
21099
21100
21101
21102
21103
21104
21105
21106
21107
21108
21109
21110
21111
21112
21113
21114
21115
21116
21117
21118
21119
21120
21121
21122
21123
21124
21125
21126
21127
21128
21129
21130
21131
21132
21133
21134
21135
21136
21137
21138
21139
21140
21141
21142
21143
21144
21145
21146
21147
21148
21149
21150
21151
21152
21153
21154
21155
21156
21157
21158
21159
21160
21161
21162
21163
21164
21165
21166
21167
21168
21169
21170
21171
21172
21173
21174
21175
21176
21177
21178
21179
21180
21181
21182
21183
21184
21185
21186
21187
21188
21189
21190
21191
21192
21193
21194
21195
21196
21197
21198
21199
21200
21201
21202
21203
21204
21205
21206
21207
21208
21209
21210
21211
21212
21213
21214
21215
21216
21217
21218
21219
21220
21221
21222
21223
21224
21225
21226
21227
21228
21229
21230
21231
21232
21233
21234
21235
21236
21237
21238
21239
21240
21241
21242
21243
21244
21245
21246
21247
21248
21249
21250
21251
21252
21253
21254
21255
21256
21257
21258
21259
21260
21261
21262
21263
21264
21265
21266
21267
21268
21269
21270
21271
21272
21273
21274
21275
21276
21277
21278
21279
21280
21281
21282
21283
21284
21285
21286
21287
21288
21289
21290
21291
21292
21293
21294
21295
21296
21297
21298
21299
21300
21301
21302
21303
21304
21305
21306
21307
21308
21309
21310
21311
21312
21313
21314
21315
21316
21317
21318
21319
21320
21321
21322
21323
21324
21325
21326
21327
21328
21329
21330
21331
21332
21333
21334
21335
21336
21337
21338
21339
21340
21341
21342
21343
21344
21345
21346
21347
21348
21349
21350
21351
21352
21353
21354
21355
21356
21357
21358
21359
21360
21361
21362
21363
21364
21365
21366
21367
21368
21369
21370
21371
21372
21373
21374
21375
21376
21377
21378
21379
21380
21381
21382
21383
21384
21385
21386
21387
21388
21389
21390
21391
21392
21393
21394
21395
21396
21397
21398
21399
21400
21401
21402
21403
21404
21405
21406
21407
21408
21409
21410
21411
21412
21413
21414
21415
21416
21417
21418
21419
21420
21421
21422
21423
21424
21425
21426
21427
21428
21429
21430
21431
21432
21433
21434
21435
21436
21437
21438
21439
21440
21441
21442
21443
21444
21445
21446
21447
21448
21449
21450
21451
21452
21453
21454
21455
21456
21457
21458
21459
21460
21461
21462
21463
21464
21465
21466
21467
21468
21469
21470
21471
21472
21473
21474
21475
21476
21477
21478
21479
21480
21481
21482
21483
21484
21485
21486
21487
21488
21489
21490
21491
21492
21493
21494
21495
21496
21497
21498
21499
21500
21501
21502
21503
21504
21505
21506
21507
21508
21509
21510
21511
21512
21513
21514
21515
21516
21517
21518
21519
21520
21521
21522
21523
21524
21525
21526
21527
21528
21529
21530
21531
21532
21533
21534
21535
21536
21537
21538
21539
21540
21541
21542
21543
21544
21545
21546
21547
21548
21549
21550
21551
21552
21553
21554
21555
21556
21557
21558
21559
21560
21561
21562
21563
21564
21565
21566
21567
21568
21569
21570
21571
21572
21573
21574
21575
21576
21577
21578
21579
21580
21581
21582
21583
21584
21585
21586
21587
21588
21589
21590
21591
21592
21593
21594
21595
21596
21597
21598
21599
21600
21601
21602
21603
21604
21605
21606
21607
21608
21609
21610
21611
21612
21613
21614
21615
21616
21617
21618
21619
21620
21621
21622
21623
21624
21625
21626
21627
21628
21629
21630
21631
21632
21633
21634
21635
21636
21637
21638
21639
21640
21641
21642
21643
21644
21645
21646
21647
21648
21649
21650
21651
21652
21653
21654
21655
21656
21657
21658
21659
21660
21661
21662
21663
21664
21665
21666
21667
21668
21669
21670
21671
21672
21673
21674
21675
21676
21677
21678
21679
21680
21681
21682
21683
21684
21685
21686
21687
21688
21689
21690
21691
21692
21693
21694
21695
21696
21697
21698
21699
21700
21701
21702
21703
21704
21705
21706
21707
21708
21709
21710
21711
21712
21713
21714
21715
21716
21717
21718
21719
21720
21721
21722
21723
21724
21725
21726
21727
21728
21729
21730
21731
21732
21733
21734
21735
21736
21737
21738
21739
21740
21741
21742
21743
21744
21745
21746
21747
21748
21749
21750
21751
21752
21753
21754
21755
21756
21757
21758
21759
21760
21761
21762
21763
21764
21765
21766
21767
21768
21769
21770
21771
21772
21773
21774
21775
21776
21777
21778
21779
21780
21781
21782
21783
21784
21785
21786
21787
21788
21789
21790
21791
21792
21793
21794
21795
21796
21797
21798
21799
21800
21801
21802
21803
21804
21805
21806
21807
21808
21809
21810
21811
21812
21813
21814
21815
21816
21817
21818
21819
21820
21821
21822
21823
21824
21825
21826
21827
21828
21829
21830
21831
21832
21833
21834
21835
21836
21837
21838
21839
21840
21841
21842
21843
21844
21845
21846
21847
21848
21849
21850
21851
21852
21853
21854
21855
21856
21857
21858
21859
21860
21861
21862
21863
21864
21865
21866
21867
21868
21869
21870
21871
21872
21873
21874
21875
21876
21877
21878
21879
21880
21881
21882
21883
21884
21885
21886
21887
21888
21889
21890
21891
21892
21893
21894
21895
21896
21897
21898
21899
21900
21901
21902
21903
21904
21905
21906
21907
21908
21909
21910
21911
21912
21913
21914
21915
21916
21917
21918
21919
21920
21921
21922
21923
21924
21925
21926
21927
21928
21929
21930
21931
21932
21933
21934
21935
21936
21937
21938
21939
21940
21941
21942
21943
21944
21945
21946
21947
21948
21949
21950
21951
21952
21953
21954
21955
21956
21957
21958
21959
21960
21961
21962
21963
21964
21965
21966
21967
21968
21969
21970
21971
21972
21973
21974
21975
21976
21977
21978
21979
21980
21981
21982
21983
21984
21985
21986
21987
21988
21989
21990
21991
21992
21993
21994
21995
21996
21997
21998
21999
22000
22001
22002
22003
22004
22005
22006
22007
22008
22009
22010
22011
22012
22013
22014
22015
22016
22017
22018
22019
22020
22021
22022
22023
22024
22025
22026
22027
22028
22029
22030
22031
22032
22033
22034
22035
22036
22037
22038
22039
22040
22041
22042
22043
22044
22045
22046
22047
22048
22049
22050
22051
22052
22053
22054
22055
22056
22057
22058
22059
22060
22061
22062
22063
22064
22065
22066
22067
22068
22069
22070
22071
22072
22073
22074
22075
22076
22077
22078
22079
22080
22081
22082
22083
22084
22085
22086
22087
22088
22089
22090
22091
22092
22093
22094
22095
22096
22097
22098
22099
22100
22101
22102
22103
22104
22105
22106
22107
22108
22109
22110
22111
22112
22113
22114
22115
22116
22117
22118
22119
22120
22121
22122
22123
22124
22125
22126
22127
22128
22129
22130
22131
22132
22133
22134
22135
22136
22137
22138
22139
22140
22141
22142
22143
22144
22145
22146
22147
22148
22149
22150
22151
22152
22153
22154
22155
22156
22157
22158
22159
22160
22161
22162
22163
22164
22165
22166
22167
22168
22169
22170
22171
22172
22173
22174
22175
22176
22177
22178
22179
22180
22181
22182
22183
22184
22185
22186
22187
22188
22189
22190
22191
22192
22193
22194
22195
22196
22197
22198
22199
22200
22201
22202
22203
22204
22205
22206
22207
22208
22209
22210
22211
22212
22213
22214
22215
22216
22217
22218
22219
22220
22221
22222
22223
22224
22225
22226
22227
22228
22229
22230
22231
22232
22233
22234
22235
22236
22237
22238
22239
22240
22241
22242
22243
22244
22245
22246
22247
22248
22249
22250
22251
22252
22253
22254
22255
22256
22257
22258
22259
22260
22261
22262
22263
22264
22265
22266
22267
22268
22269
22270
22271
22272
22273
22274
22275
22276
22277
22278
22279
22280
22281
22282
22283
22284
22285
22286
22287
22288
22289
22290
22291
22292
22293
22294
22295
22296
22297
22298
22299
22300
22301
22302
22303
22304
22305
22306
22307
22308
22309
22310
22311
22312
22313
22314
22315
22316
22317
22318
22319
22320
22321
22322
22323
22324
22325
22326
22327
22328
22329
22330
22331
22332
22333
22334
22335
22336
22337
22338
22339
22340
22341
22342
22343
22344
22345
22346
22347
22348
22349
22350
22351
22352
22353
22354
22355
22356
22357
22358
22359
22360
22361
22362
22363
22364
22365
22366
22367
22368
22369
22370
22371
22372
22373
22374
22375
22376
22377
22378
22379
22380
22381
22382
22383
22384
22385
22386
22387
22388
22389
22390
22391
22392
22393
22394
22395
22396
22397
22398
22399
22400
22401
22402
22403
22404
22405
22406
22407
22408
22409
22410
22411
22412
22413
22414
22415
22416
22417
22418
22419
22420
22421
22422
22423
22424
22425
22426
22427
22428
22429
22430
22431
22432
22433
22434
22435
22436
22437
22438
22439
22440
22441
22442
22443
22444
22445
22446
22447
22448
22449
22450
22451
22452
22453
22454
22455
22456
22457
22458
22459
22460
22461
22462
22463
22464
22465
22466
22467
22468
22469
22470
22471
22472
22473
22474
22475
22476
22477
22478
22479
22480
22481
22482
22483
22484
22485
22486
22487
22488
22489
22490
22491
22492
22493
22494
22495
22496
22497
22498
22499
22500
22501
22502
22503
22504
22505
22506
22507
22508
22509
22510
22511
22512
22513
22514
22515
22516
22517
22518
22519
22520
22521
22522
22523
22524
22525
22526
22527
22528
22529
22530
22531
22532
22533
22534
22535
22536
22537
22538
22539
22540
22541
22542
22543
22544
22545
22546
22547
22548
22549
22550
22551
22552
22553
22554
22555
22556
22557
22558
22559
22560
22561
22562
22563
22564
22565
22566
22567
22568
22569
22570
22571
22572
22573
22574
22575
22576
22577
22578
22579
22580
22581
22582
22583
22584
22585
22586
22587
22588
22589
22590
22591
22592
22593
22594
22595
22596
22597
22598
22599
22600
22601
22602
22603
22604
22605
22606
22607
22608
22609
22610
22611
22612
22613
22614
22615
22616
22617
22618
22619
22620
22621
22622
22623
22624
22625
22626
22627
22628
22629
22630
22631
22632
22633
22634
22635
22636
22637
22638
22639
22640
22641
22642
22643
22644
22645
22646
22647
22648
22649
22650
22651
22652
22653
22654
22655
22656
22657
22658
22659
22660
22661
22662
22663
22664
22665
22666
22667
22668
22669
22670
22671
22672
22673
22674
22675
22676
22677
22678
22679
22680
22681
22682
22683
22684
22685
22686
22687
22688
22689
22690
22691
22692
22693
22694
22695
22696
22697
22698
22699
22700
22701
22702
22703
22704
22705
22706
22707
22708
22709
22710
22711
22712
22713
22714
22715
22716
22717
22718
22719
22720
22721
22722
22723
22724
22725
22726
22727
22728
22729
22730
22731
22732
22733
22734
22735
22736
22737
22738
22739
22740
22741
22742
22743
22744
22745
22746
22747
22748
22749
22750
22751
22752
22753
22754
22755
22756
22757
22758
22759
22760
22761
22762
22763
22764
22765
22766
22767
22768
22769
22770
22771
22772
22773
22774
22775
22776
22777
22778
22779
22780
22781
22782
22783
22784
22785
22786
22787
22788
22789
22790
22791
22792
22793
22794
22795
22796
22797
22798
22799
22800
22801
22802
22803
22804
22805
22806
22807
22808
22809
22810
22811
22812
22813
22814
22815
22816
22817
22818
22819
22820
22821
22822
22823
22824
22825
22826
22827
22828
22829
22830
22831
22832
22833
22834
22835
22836
22837
22838
22839
22840
22841
22842
22843
22844
22845
22846
22847
22848
22849
22850
22851
22852
22853
22854
22855
22856
22857
22858
22859
22860
22861
22862
22863
22864
22865
22866
22867
22868
22869
22870
22871
22872
22873
22874
22875
22876
22877
22878
22879
22880
22881
22882
22883
22884
22885
22886
22887
22888
22889
22890
22891
22892
22893
22894
22895
22896
22897
22898
22899
22900
22901
22902
22903
22904
22905
22906
22907
22908
22909
22910
22911
22912
22913
22914
22915
22916
22917
22918
22919
22920
22921
22922
22923
22924
22925
22926
22927
22928
22929
22930
22931
22932
22933
22934
22935
22936
22937
22938
22939
22940
22941
22942
22943
22944
22945
22946
22947
22948
22949
22950
22951
22952
22953
22954
22955
22956
22957
22958
22959
22960
22961
22962
22963
22964
22965
22966
22967
22968
22969
22970
22971
22972
22973
22974
22975
22976
22977
22978
22979
22980
22981
22982
22983
22984
22985
22986
22987
22988
22989
22990
22991
22992
22993
22994
22995
22996
22997
22998
22999
23000
23001
23002
23003
23004
23005
23006
23007
23008
23009
23010
23011
23012
23013
23014
23015
23016
23017
23018
23019
23020
23021
23022
23023
23024
23025
23026
23027
23028
23029
23030
23031
23032
23033
23034
23035
23036
23037
23038
23039
23040
23041
23042
23043
23044
23045
23046
23047
23048
23049
23050
23051
23052
23053
23054
23055
23056
23057
23058
23059
23060
23061
23062
23063
23064
23065
23066
23067
23068
23069
23070
23071
23072
23073
23074
23075
23076
23077
23078
23079
23080
23081
23082
23083
23084
23085
23086
23087
23088
23089
23090
23091
23092
23093
23094
23095
23096
23097
23098
23099
23100
23101
23102
23103
23104
23105
23106
23107
23108
23109
23110
23111
23112
23113
23114
23115
23116
23117
23118
23119
23120
23121
23122
23123
23124
23125
23126
23127
23128
23129
23130
23131
23132
23133
23134
23135
23136
23137
23138
23139
23140
23141
23142
23143
23144
23145
23146
23147
23148
23149
23150
23151
23152
23153
23154
23155
23156
23157
23158
23159
23160
23161
23162
23163
23164
23165
23166
23167
23168
23169
23170
23171
23172
23173
23174
23175
23176
23177
23178
23179
23180
23181
23182
23183
23184
23185
23186
23187
23188
23189
23190
23191
23192
23193
23194
23195
23196
23197
23198
23199
23200
23201
23202
23203
23204
23205
23206
23207
23208
23209
23210
23211
23212
23213
23214
23215
23216
23217
23218
23219
23220
23221
23222
23223
23224
23225
23226
23227
23228
23229
23230
23231
23232
23233
23234
23235
23236
23237
23238
23239
23240
23241
23242
23243
23244
23245
23246
23247
23248
23249
23250
23251
23252
23253
23254
23255
23256
23257
23258
23259
23260
23261
23262
23263
23264
23265
23266
23267
23268
23269
23270
23271
23272
23273
23274
23275
23276
23277
23278
23279
23280
23281
23282
23283
23284
23285
23286
23287
23288
23289
23290
23291
23292
23293
23294
23295
23296
23297
23298
23299
23300
23301
23302
23303
23304
23305
23306
23307
23308
23309
23310
23311
23312
23313
23314
23315
23316
23317
23318
23319
23320
23321
23322
23323
23324
23325
23326
23327
23328
23329
23330
23331
23332
23333
23334
23335
23336
23337
23338
23339
23340
23341
23342
23343
23344
23345
23346
23347
23348
23349
23350
23351
23352
23353
23354
23355
23356
23357
23358
23359
23360
23361
23362
23363
23364
23365
23366
23367
23368
23369
23370
23371
23372
23373
23374
23375
23376
23377
23378
23379
23380
23381
23382
23383
23384
23385
23386
23387
23388
23389
23390
23391
23392
23393
23394
23395
23396
23397
23398
23399
23400
23401
23402
23403
23404
23405
23406
23407
23408
23409
23410
23411
23412
23413
23414
23415
23416
23417
23418
23419
23420
23421
23422
23423
23424
23425
23426
23427
23428
23429
23430
23431
23432
23433
23434
23435
23436
23437
23438
23439
23440
23441
23442
23443
23444
23445
23446
23447
23448
23449
23450
23451
23452
23453
23454
23455
23456
23457
23458
23459
23460
23461
23462
23463
23464
23465
23466
23467
23468
23469
23470
23471
23472
23473
23474
23475
23476
23477
23478
23479
23480
23481
23482
23483
23484
23485
23486
23487
23488
23489
23490
23491
23492
23493
23494
23495
23496
23497
23498
23499
23500
23501
23502
23503
23504
23505
23506
23507
23508
23509
23510
23511
23512
23513
23514
23515
23516
23517
23518
23519
23520
23521
23522
23523
23524
23525
23526
23527
23528
23529
23530
23531
23532
23533
23534
23535
23536
23537
23538
23539
23540
23541
23542
23543
23544
23545
23546
23547
23548
23549
23550
23551
23552
23553
23554
23555
23556
23557
23558
23559
23560
23561
23562
23563
23564
23565
23566
23567
23568
23569
23570
23571
23572
23573
23574
23575
23576
23577
23578
23579
23580
23581
23582
23583
23584
23585
23586
23587
23588
23589
23590
23591
23592
23593
23594
23595
23596
23597
23598
23599
23600
23601
23602
23603
23604
23605
23606
23607
23608
23609
23610
23611
23612
23613
23614
23615
23616
23617
23618
23619
23620
23621
23622
23623
23624
23625
23626
23627
23628
23629
23630
23631
23632
23633
23634
23635
23636
23637
23638
23639
23640
23641
23642
23643
23644
23645
23646
23647
23648
23649
23650
23651
23652
23653
23654
23655
23656
23657
23658
23659
23660
23661
23662
23663
23664
23665
23666
23667
23668
23669
23670
23671
23672
23673
23674
23675
23676
23677
23678
23679
23680
23681
23682
23683
23684
23685
23686
23687
23688
23689
23690
23691
23692
23693
23694
23695
23696
23697
23698
23699
23700
23701
23702
23703
23704
23705
23706
23707
23708
23709
23710
23711
23712
23713
23714
23715
23716
23717
23718
23719
23720
23721
23722
23723
23724
23725
23726
23727
23728
23729
23730
23731
23732
23733
23734
23735
23736
23737
23738
23739
23740
23741
23742
23743
23744
23745
23746
23747
23748
23749
23750
23751
23752
23753
23754
23755
23756
23757
23758
23759
23760
23761
23762
23763
23764
23765
23766
23767
23768
23769
23770
23771
23772
23773
23774
23775
23776
23777
23778
23779
23780
23781
23782
23783
23784
23785
23786
23787
23788
23789
23790
23791
23792
23793
23794
23795
23796
23797
23798
23799
23800
23801
23802
23803
23804
23805
23806
23807
23808
23809
23810
23811
23812
23813
23814
23815
23816
23817
23818
23819
23820
23821
23822
23823
23824
23825
23826
23827
23828
23829
23830
23831
23832
23833
23834
23835
23836
23837
23838
23839
23840
23841
23842
23843
23844
23845
23846
23847
23848
23849
23850
23851
23852
23853
23854
23855
23856
23857
23858
23859
23860
23861
23862
23863
23864
23865
23866
23867
23868
23869
23870
23871
23872
23873
23874
23875
23876
23877
23878
23879
23880
23881
23882
23883
23884
23885
23886
23887
23888
23889
23890
23891
23892
23893
23894
23895
23896
23897
23898
23899
23900
23901
23902
23903
23904
23905
23906
23907
23908
23909
23910
23911
23912
23913
23914
23915
23916
23917
23918
23919
23920
23921
23922
23923
23924
23925
23926
23927
23928
23929
23930
23931
23932
23933
23934
23935
23936
23937
23938
23939
23940
23941
23942
23943
23944
23945
23946
23947
23948
23949
23950
23951
23952
23953
23954
23955
23956
23957
23958
23959
23960
23961
23962
23963
23964
23965
23966
23967
23968
23969
23970
23971
23972
23973
23974
23975
23976
23977
23978
23979
23980
23981
23982
23983
23984
23985
23986
23987
23988
23989
23990
23991
23992
23993
23994
23995
23996
23997
23998
23999
24000
24001
24002
24003
24004
24005
24006
24007
24008
24009
24010
24011
24012
24013
24014
24015
24016
24017
24018
24019
24020
24021
24022
24023
24024
24025
24026
24027
24028
24029
24030
24031
24032
24033
24034
24035
24036
24037
24038
24039
24040
24041
24042
24043
24044
24045
24046
24047
24048
24049
24050
24051
24052
24053
24054
24055
24056
24057
24058
24059
24060
24061
24062
24063
24064
24065
24066
24067
24068
24069
24070
24071
24072
24073
24074
24075
24076
24077
24078
24079
24080
24081
24082
24083
24084
24085
24086
24087
24088
24089
24090
24091
24092
24093
24094
24095
24096
24097
24098
24099
24100
24101
24102
24103
24104
24105
24106
24107
24108
24109
24110
24111
24112
24113
24114
24115
24116
24117
24118
24119
24120
24121
24122
24123
24124
24125
24126
24127
24128
24129
24130
24131
24132
24133
24134
24135
24136
24137
24138
24139
24140
24141
24142
24143
24144
24145
24146
24147
24148
24149
24150
24151
24152
24153
24154
24155
24156
24157
24158
24159
24160
24161
24162
24163
24164
24165
24166
24167
24168
24169
24170
24171
24172
24173
24174
24175
24176
24177
24178
24179
24180
24181
24182
24183
24184
24185
24186
24187
24188
24189
24190
24191
24192
24193
24194
24195
24196
24197
24198
24199
24200
24201
24202
24203
24204
24205
24206
24207
24208
24209
24210
24211
24212
24213
24214
24215
24216
24217
24218
24219
24220
24221
24222
24223
24224
24225
24226
24227
24228
24229
24230
24231
24232
24233
24234
24235
24236
24237
24238
24239
24240
24241
24242
24243
24244
24245
24246
24247
24248
24249
24250
24251
24252
24253
24254
24255
24256
24257
24258
24259
24260
24261
24262
24263
24264
24265
24266
24267
24268
24269
24270
24271
24272
24273
24274
24275
24276
24277
24278
24279
24280
24281
24282
24283
24284
24285
24286
24287
24288
24289
24290
24291
24292
24293
24294
24295
24296
24297
24298
24299
24300
24301
24302
24303
24304
24305
24306
24307
24308
24309
24310
24311
24312
24313
24314
24315
24316
24317
24318
24319
24320
24321
24322
24323
24324
24325
24326
24327
24328
24329
24330
24331
24332
24333
24334
24335
24336
24337
24338
24339
24340
24341
24342
24343
24344
24345
24346
24347
24348
24349
24350
24351
24352
24353
24354
24355
24356
24357
24358
24359
24360
24361
24362
24363
24364
24365
24366
24367
24368
24369
24370
24371
24372
24373
24374
24375
24376
24377
24378
24379
24380
24381
24382
24383
24384
24385
24386
24387
24388
24389
24390
24391
24392
24393
24394
24395
24396
24397
24398
24399
24400
24401
24402
24403
24404
24405
24406
24407
24408
24409
24410
24411
24412
24413
24414
24415
24416
24417
24418
24419
24420
24421
24422
24423
24424
24425
24426
24427
24428
24429
24430
24431
24432
24433
24434
24435
24436
24437
24438
24439
24440
24441
24442
24443
24444
24445
24446
24447
24448
24449
24450
24451
24452
24453
24454
24455
24456
24457
24458
24459
24460
24461
24462
24463
24464
24465
24466
24467
24468
24469
24470
24471
24472
24473
24474
24475
24476
24477
24478
24479
24480
24481
24482
24483
24484
24485
24486
24487
24488
24489
24490
24491
24492
24493
24494
24495
24496
24497
24498
24499
24500
24501
24502
24503
24504
24505
24506
24507
24508
24509
24510
24511
24512
24513
24514
24515
24516
24517
24518
24519
24520
24521
24522
24523
24524
24525
24526
24527
24528
24529
24530
24531
24532
24533
24534
24535
24536
24537
24538
24539
24540
24541
24542
24543
24544
24545
24546
24547
24548
24549
24550
24551
24552
24553
24554
24555
24556
24557
24558
24559
24560
24561
24562
24563
24564
24565
24566
24567
24568
24569
24570
24571
24572
24573
24574
24575
24576
24577
24578
24579
24580
24581
24582
24583
24584
24585
24586
24587
24588
24589
24590
24591
24592
24593
24594
24595
24596
24597
24598
24599
24600
24601
24602
24603
24604
24605
24606
24607
24608
24609
24610
24611
24612
24613
24614
24615
24616
24617
24618
24619
24620
24621
24622
24623
24624
24625
24626
24627
24628
24629
24630
24631
24632
24633
24634
24635
24636
24637
24638
24639
24640
24641
24642
24643
24644
24645
24646
24647
24648
24649
24650
24651
24652
24653
24654
24655
24656
24657
24658
24659
24660
24661
24662
24663
24664
24665
24666
24667
24668
24669
24670
24671
24672
24673
24674
24675
24676
24677
24678
24679
24680
24681
24682
24683
24684
24685
24686
24687
24688
24689
24690
24691
24692
24693
24694
24695
24696
24697
24698
24699
24700
24701
24702
24703
24704
24705
24706
24707
24708
24709
24710
24711
24712
24713
24714
24715
24716
24717
24718
24719
24720
24721
24722
24723
24724
24725
24726
24727
24728
24729
24730
24731
24732
24733
24734
24735
24736
24737
24738
24739
24740
24741
24742
24743
24744
24745
24746
24747
24748
24749
24750
24751
24752
24753
24754
24755
24756
24757
24758
24759
24760
24761
24762
24763
24764
24765
24766
24767
24768
24769
24770
24771
24772
24773
24774
24775
24776
24777
24778
24779
24780
24781
24782
24783
24784
24785
24786
24787
24788
24789
24790
24791
24792
24793
24794
24795
24796
24797
24798
24799
24800
24801
24802
24803
24804
24805
24806
24807
24808
24809
24810
24811
24812
24813
24814
24815
24816
24817
24818
24819
24820
24821
24822
24823
24824
24825
24826
24827
24828
24829
24830
24831
24832
24833
24834
24835
24836
24837
24838
24839
24840
24841
24842
24843
24844
24845
24846
24847
24848
24849
24850
24851
24852
24853
24854
24855
24856
24857
24858
24859
24860
24861
24862
24863
24864
24865
24866
24867
24868
24869
24870
24871
24872
24873
24874
24875
24876
24877
24878
24879
24880
24881
24882
24883
24884
24885
24886
24887
24888
24889
24890
24891
24892
24893
24894
24895
24896
24897
24898
24899
24900
24901
24902
24903
24904
24905
24906
24907
24908
24909
24910
24911
24912
24913
24914
24915
24916
24917
24918
24919
24920
24921
24922
24923
24924
24925
24926
24927
24928
24929
24930
24931
24932
24933
24934
24935
24936
24937
24938
24939
24940
24941
24942
24943
24944
24945
24946
24947
24948
24949
24950
24951
24952
24953
24954
24955
24956
24957
24958
24959
24960
24961
24962
24963
24964
24965
24966
24967
24968
24969
24970
24971
24972
24973
24974
24975
24976
24977
24978
24979
24980
24981
24982
24983
24984
24985
24986
24987
24988
24989
24990
24991
24992
24993
24994
24995
24996
24997
24998
24999
25000
25001
25002
25003
25004
25005
25006
25007
25008
25009
25010
25011
25012
25013
25014
25015
25016
25017
25018
25019
25020
25021
25022
25023
25024
25025
25026
25027
25028
25029
25030
25031
25032
25033
25034
25035
25036
25037
25038
25039
25040
25041
25042
25043
25044
25045
25046
25047
25048
25049
25050
25051
25052
25053
25054
25055
25056
25057
25058
25059
25060
25061
25062
25063
25064
25065
25066
25067
25068
25069
25070
25071
25072
25073
25074
25075
25076
25077
25078
25079
25080
25081
25082
25083
25084
25085
25086
25087
25088
25089
25090
25091
25092
25093
25094
25095
25096
25097
25098
25099
25100
25101
25102
25103
25104
25105
25106
25107
25108
25109
25110
25111
25112
25113
25114
25115
25116
25117
25118
25119
25120
25121
25122
25123
25124
25125
25126
25127
25128
25129
25130
25131
25132
25133
25134
25135
25136
25137
25138
25139
25140
25141
25142
25143
25144
25145
25146
25147
25148
25149
25150
25151
25152
25153
25154
25155
25156
25157
25158
25159
25160
25161
25162
25163
25164
25165
25166
25167
25168
25169
25170
25171
25172
25173
25174
25175
25176
25177
25178
25179
25180
25181
25182
25183
25184
25185
25186
25187
25188
25189
25190
25191
25192
25193
25194
25195
25196
25197
25198
25199
25200
25201
25202
25203
25204
25205
25206
25207
25208
25209
25210
25211
25212
25213
25214
25215
25216
25217
25218
25219
25220
25221
25222
25223
25224
25225
25226
25227
25228
25229
25230
25231
25232
25233
25234
25235
25236
25237
25238
25239
25240
25241
25242
25243
25244
25245
25246
25247
25248
25249
25250
25251
25252
25253
25254
25255
25256
25257
25258
25259
25260
25261
25262
25263
25264
25265
25266
25267
25268
25269
25270
25271
25272
25273
25274
25275
25276
25277
25278
25279
25280
25281
25282
25283
25284
25285
25286
25287
25288
25289
25290
25291
25292
25293
25294
25295
25296
25297
25298
25299
25300
25301
25302
25303
25304
25305
25306
25307
25308
25309
25310
25311
25312
25313
25314
25315
25316
25317
25318
25319
25320
25321
25322
25323
25324
25325
25326
25327
25328
25329
25330
25331
25332
25333
25334
25335
25336
25337
25338
25339
25340
25341
25342
25343
25344
25345
25346
25347
25348
25349
25350
25351
25352
25353
25354
25355
25356
25357
25358
25359
25360
25361
25362
25363
25364
25365
25366
25367
25368
25369
25370
25371
25372
25373
25374
25375
25376
25377
25378
25379
25380
25381
25382
25383
25384
25385
25386
25387
25388
25389
25390
25391
25392
25393
25394
25395
25396
25397
25398
25399
25400
25401
25402
25403
25404
25405
25406
25407
25408
25409
25410
25411
25412
25413
25414
25415
25416
25417
25418
25419
25420
25421
25422
25423
25424
25425
25426
25427
25428
25429
25430
25431
25432
25433
25434
25435
25436
25437
25438
25439
25440
25441
25442
25443
25444
25445
25446
25447
25448
25449
25450
25451
25452
25453
25454
25455
25456
25457
25458
25459
25460
25461
25462
25463
25464
25465
25466
25467
25468
25469
25470
25471
25472
25473
25474
25475
25476
25477
25478
25479
25480
25481
25482
25483
25484
25485
25486
25487
25488
25489
25490
25491
25492
25493
25494
25495
25496
25497
25498
25499
25500
25501
25502
25503
25504
25505
25506
25507
25508
25509
25510
25511
25512
25513
25514
25515
25516
25517
25518
25519
25520
25521
25522
25523
25524
25525
25526
25527
25528
25529
25530
25531
25532
25533
25534
25535
25536
25537
25538
25539
25540
25541
25542
25543
25544
25545
25546
25547
25548
25549
25550
25551
25552
25553
25554
25555
25556
25557
25558
25559
25560
25561
25562
25563
25564
25565
25566
25567
25568
25569
25570
25571
25572
25573
25574
25575
25576
25577
25578
25579
25580
25581
25582
25583
25584
25585
25586
25587
25588
25589
25590
25591
25592
25593
25594
25595
25596
25597
25598
25599
25600
25601
25602
25603
25604
25605
25606
25607
25608
25609
25610
25611
25612
25613
25614
25615
25616
25617
25618
25619
25620
25621
25622
25623
25624
25625
25626
25627
25628
25629
25630
25631
25632
25633
25634
25635
25636
25637
25638
25639
25640
25641
25642
25643
25644
25645
25646
25647
25648
25649
25650
25651
25652
25653
25654
25655
25656
25657
25658
25659
25660
25661
25662
25663
25664
25665
25666
25667
25668
25669
25670
25671
25672
25673
25674
25675
25676
25677
25678
25679
25680
25681
25682
25683
25684
25685
25686
25687
25688
25689
25690
25691
25692
25693
25694
25695
25696
25697
25698
25699
25700
25701
25702
25703
25704
25705
25706
25707
25708
25709
25710
25711
25712
25713
25714
25715
25716
25717
25718
25719
25720
25721
25722
25723
25724
25725
25726
25727
25728
25729
25730
25731
25732
25733
25734
25735
25736
25737
25738
25739
25740
25741
25742
25743
25744
25745
25746
25747
25748
25749
25750
25751
25752
25753
25754
25755
25756
25757
25758
25759
25760
25761
25762
25763
25764
25765
25766
25767
25768
25769
25770
25771
25772
25773
25774
25775
25776
25777
25778
25779
25780
25781
25782
25783
25784
25785
25786
25787
25788
25789
25790
25791
25792
25793
25794
25795
25796
25797
25798
25799
25800
25801
25802
25803
25804
25805
25806
25807
25808
25809
25810
25811
25812
25813
25814
25815
25816
25817
25818
25819
25820
25821
25822
25823
25824
25825
25826
25827
25828
25829
25830
25831
25832
25833
25834
25835
25836
25837
25838
25839
25840
25841
25842
25843
25844
25845
25846
25847
25848
25849
25850
25851
25852
25853
25854
25855
25856
25857
25858
25859
25860
25861
25862
25863
25864
25865
25866
25867
25868
25869
25870
25871
25872
25873
25874
25875
25876
25877
25878
25879
25880
25881
25882
25883
25884
25885
25886
25887
25888
25889
25890
25891
25892
25893
25894
25895
25896
25897
25898
25899
25900
25901
25902
25903
25904
25905
25906
25907
25908
25909
25910
25911
25912
25913
25914
25915
25916
25917
25918
25919
25920
25921
25922
25923
25924
25925
25926
25927
25928
25929
25930
25931
25932
25933
25934
25935
25936
25937
25938
25939
25940
25941
25942
25943
25944
25945
25946
25947
25948
25949
25950
25951
25952
25953
25954
25955
25956
25957
25958
25959
25960
25961
25962
25963
25964
25965
25966
25967
25968
25969
25970
25971
25972
25973
25974
25975
25976
25977
25978
25979
25980
25981
25982
25983
25984
25985
25986
25987
25988
25989
25990
25991
25992
25993
25994
25995
25996
25997
25998
25999
26000
26001
26002
26003
26004
26005
26006
26007
26008
26009
26010
26011
26012
26013
26014
26015
26016
26017
26018
26019
26020
26021
26022
26023
26024
26025
26026
26027
26028
26029
26030
26031
26032
26033
26034
26035
26036
26037
26038
26039
26040
26041
26042
26043
26044
26045
26046
26047
26048
26049
26050
26051
26052
26053
26054
26055
26056
26057
26058
26059
26060
26061
26062
26063
26064
26065
26066
26067
26068
26069
26070
26071
26072
26073
26074
26075
26076
26077
26078
26079
26080
26081
26082
26083
26084
26085
26086
26087
26088
26089
26090
26091
26092
26093
26094
26095
26096
26097
26098
26099
26100
26101
26102
26103
26104
26105
26106
26107
26108
26109
26110
26111
26112
26113
26114
26115
26116
26117
26118
26119
26120
26121
26122
26123
26124
26125
26126
26127
26128
26129
26130
26131
26132
26133
26134
26135
26136
26137
26138
26139
26140
26141
26142
26143
26144
26145
26146
26147
26148
26149
26150
26151
26152
26153
26154
26155
26156
26157
26158
26159
26160
26161
26162
26163
26164
26165
26166
26167
26168
26169
26170
26171
26172
26173
26174
26175
26176
26177
26178
26179
26180
26181
26182
26183
26184
26185
26186
26187
26188
26189
26190
26191
26192
26193
26194
26195
26196
26197
26198
26199
26200
26201
26202
26203
26204
26205
26206
26207
26208
26209
26210
26211
26212
26213
26214
26215
26216
26217
26218
26219
26220
26221
26222
26223
26224
26225
26226
26227
26228
26229
26230
26231
26232
26233
26234
26235
26236
26237
26238
26239
26240
26241
26242
26243
26244
26245
26246
26247
26248
26249
26250
26251
26252
26253
26254
26255
26256
26257
26258
26259
26260
26261
26262
26263
26264
26265
26266
26267
26268
26269
26270
26271
26272
26273
26274
26275
26276
26277
26278
26279
26280
26281
26282
26283
26284
26285
26286
26287
26288
26289
26290
26291
26292
26293
26294
26295
26296
26297
26298
26299
26300
26301
26302
26303
26304
26305
26306
26307
26308
26309
26310
26311
26312
26313
26314
26315
26316
26317
26318
26319
26320
26321
26322
26323
26324
26325
26326
26327
26328
26329
26330
26331
26332
26333
26334
26335
26336
26337
26338
26339
26340
26341
26342
26343
26344
26345
26346
26347
26348
26349
26350
26351
26352
26353
26354
26355
26356
26357
26358
26359
26360
26361
26362
26363
26364
26365
26366
26367
26368
26369
26370
26371
26372
26373
26374
26375
26376
26377
26378
26379
26380
26381
26382
26383
26384
26385
26386
26387
26388
26389
26390
26391
26392
26393
26394
26395
26396
26397
26398
26399
26400
26401
26402
26403
26404
26405
26406
26407
26408
26409
26410
26411
26412
26413
26414
26415
26416
26417
26418
26419
26420
26421
26422
26423
26424
26425
26426
26427
26428
26429
26430
26431
26432
26433
26434
26435
26436
26437
26438
26439
26440
26441
26442
26443
26444
26445
26446
26447
26448
26449
26450
26451
26452
26453
26454
26455
26456
26457
26458
26459
26460
26461
26462
26463
26464
26465
26466
26467
26468
26469
26470
26471
26472
26473
26474
26475
26476
26477
26478
26479
26480
26481
26482
26483
26484
26485
26486
26487
26488
26489
26490
26491
26492
26493
26494
26495
26496
26497
26498
26499
26500
26501
26502
26503
26504
26505
26506
26507
26508
26509
26510
26511
26512
26513
26514
26515
26516
26517
26518
26519
26520
26521
26522
26523
26524
26525
26526
26527
26528
26529
26530
26531
26532
26533
26534
26535
26536
26537
26538
26539
26540
26541
26542
26543
26544
26545
26546
26547
26548
26549
26550
26551
26552
26553
26554
26555
26556
26557
26558
26559
26560
26561
26562
26563
26564
26565
26566
26567
26568
26569
26570
26571
26572
26573
26574
26575
26576
26577
26578
26579
26580
26581
26582
26583
26584
26585
26586
26587
26588
26589
26590
26591
26592
26593
26594
26595
26596
26597
26598
26599
26600
26601
26602
26603
26604
26605
26606
26607
26608
26609
26610
26611
26612
26613
26614
26615
26616
26617
26618
26619
26620
26621
26622
26623
26624
26625
26626
26627
26628
26629
26630
26631
26632
26633
26634
26635
26636
26637
26638
26639
26640
26641
26642
26643
26644
26645
26646
26647
26648
26649
26650
26651
26652
26653
26654
26655
26656
26657
26658
26659
26660
26661
26662
26663
26664
26665
26666
26667
26668
26669
26670
26671
26672
26673
26674
26675
26676
26677
26678
26679
26680
26681
26682
26683
26684
26685
26686
26687
26688
26689
26690
26691
26692
26693
26694
26695
26696
26697
26698
26699
26700
26701
26702
26703
26704
26705
26706
26707
26708
26709
26710
26711
26712
26713
26714
26715
26716
26717
26718
26719
26720
26721
26722
26723
26724
26725
26726
26727
26728
26729
26730
26731
26732
26733
26734
26735
26736
26737
26738
26739
26740
26741
26742
26743
26744
26745
26746
26747
26748
26749
26750
26751
26752
26753
26754
26755
26756
26757
26758
26759
26760
26761
26762
26763
26764
26765
26766
26767
26768
26769
26770
26771
26772
26773
26774
26775
26776
26777
26778
26779
26780
26781
26782
26783
26784
26785
26786
26787
26788
26789
26790
26791
26792
26793
26794
26795
26796
26797
26798
26799
26800
26801
26802
26803
26804
26805
26806
26807
26808
26809
26810
26811
26812
26813
26814
26815
26816
26817
26818
26819
26820
26821
26822
26823
26824
26825
26826
26827
26828
26829
26830
26831
26832
26833
26834
26835
26836
26837
26838
26839
26840
26841
26842
26843
26844
26845
26846
26847
26848
26849
26850
26851
26852
26853
26854
26855
26856
26857
26858
26859
26860
26861
26862
26863
26864
26865
26866
26867
26868
26869
26870
26871
26872
26873
26874
26875
26876
26877
26878
26879
26880
26881
26882
26883
26884
26885
26886
26887
26888
26889
26890
26891
26892
26893
26894
26895
26896
26897
26898
26899
26900
26901
26902
26903
26904
26905
26906
26907
26908
26909
26910
26911
26912
26913
26914
26915
26916
26917
26918
26919
26920
26921
26922
26923
26924
26925
26926
26927
26928
26929
26930
26931
26932
26933
26934
26935
26936
26937
26938
26939
26940
26941
26942
26943
26944
26945
26946
26947
26948
26949
26950
26951
26952
26953
26954
26955
26956
26957
26958
26959
26960
26961
26962
26963
26964
26965
26966
26967
26968
26969
26970
26971
26972
26973
26974
26975
26976
26977
26978
26979
26980
26981
26982
26983
26984
26985
26986
26987
26988
26989
26990
26991
26992
26993
26994
26995
26996
26997
26998
26999
27000
27001
27002
27003
27004
27005
27006
27007
27008
27009
27010
27011
27012
27013
27014
27015
27016
27017
27018
27019
27020
27021
27022
27023
27024
27025
27026
27027
27028
27029
27030
27031
27032
27033
27034
27035
27036
27037
27038
27039
27040
27041
27042
27043
27044
27045
27046
27047
27048
27049
27050
27051
27052
27053
27054
27055
27056
27057
27058
27059
27060
27061
27062
27063
27064
27065
27066
27067
27068
27069
27070
27071
27072
27073
27074
27075
27076
27077
27078
27079
27080
27081
27082
27083
27084
27085
27086
27087
27088
27089
27090
27091
27092
27093
27094
27095
27096
27097
27098
27099
27100
27101
27102
27103
27104
27105
27106
27107
27108
27109
27110
27111
27112
27113
27114
27115
27116
27117
27118
27119
27120
27121
27122
27123
27124
27125
27126
27127
27128
27129
27130
27131
27132
27133
27134
27135
27136
27137
27138
27139
27140
27141
27142
27143
27144
27145
27146
27147
27148
27149
27150
27151
27152
27153
27154
27155
27156
27157
27158
27159
27160
27161
27162
27163
27164
27165
27166
27167
27168
27169
27170
27171
27172
27173
27174
27175
27176
27177
27178
27179
27180
27181
27182
27183
27184
27185
27186
27187
27188
27189
27190
27191
27192
27193
27194
27195
27196
27197
27198
27199
27200
27201
27202
27203
27204
27205
27206
27207
27208
27209
27210
27211
27212
27213
27214
27215
27216
27217
27218
27219
27220
27221
27222
27223
27224
27225
27226
27227
27228
27229
27230
27231
27232
27233
27234
27235
27236
27237
27238
27239
27240
27241
27242
27243
27244
27245
27246
27247
27248
27249
27250
27251
27252
27253
27254
27255
27256
27257
27258
27259
27260
27261
27262
27263
27264
27265
27266
27267
27268
27269
27270
27271
27272
27273
27274
27275
27276
27277
27278
27279
27280
27281
27282
27283
27284
27285
27286
27287
27288
27289
27290
27291
27292
27293
27294
27295
27296
27297
27298
27299
27300
27301
27302
27303
27304
27305
27306
27307
27308
27309
27310
27311
27312
27313
27314
27315
27316
27317
27318
27319
27320
27321
27322
27323
27324
27325
27326
27327
27328
27329
27330
27331
27332
27333
27334
27335
27336
27337
27338
27339
27340
27341
27342
27343
27344
27345
27346
27347
27348
27349
27350
27351
27352
27353
27354
27355
27356
27357
27358
27359
27360
27361
27362
27363
27364
27365
27366
27367
27368
27369
27370
27371
27372
27373
27374
27375
27376
27377
27378
27379
27380
27381
27382
27383
27384
27385
27386
27387
27388
27389
27390
27391
27392
27393
27394
27395
27396
27397
27398
27399
27400
27401
27402
27403
27404
27405
27406
27407
27408
27409
27410
27411
27412
27413
27414
27415
27416
27417
27418
27419
27420
27421
27422
27423
27424
27425
27426
27427
27428
27429
27430
27431
27432
27433
27434
27435
27436
27437
27438
27439
27440
27441
27442
27443
27444
27445
27446
27447
27448
27449
27450
27451
27452
27453
27454
27455
27456
27457
27458
27459
27460
27461
27462
27463
27464
27465
27466
27467
27468
27469
27470
27471
27472
27473
27474
27475
27476
27477
27478
27479
27480
27481
27482
27483
27484
27485
27486
27487
27488
27489
27490
27491
27492
27493
27494
27495
27496
27497
27498
27499
27500
27501
27502
27503
27504
27505
27506
27507
27508
27509
27510
27511
27512
27513
27514
27515
27516
27517
27518
27519
27520
27521
27522
27523
27524
27525
27526
27527
27528
27529
27530
27531
27532
27533
27534
27535
27536
27537
27538
27539
27540
27541
27542
27543
27544
27545
27546
27547
27548
27549
27550
27551
27552
27553
27554
27555
27556
27557
27558
27559
27560
27561
27562
27563
27564
27565
27566
27567
27568
27569
27570
27571
27572
27573
27574
27575
27576
27577
27578
27579
27580
27581
27582
27583
27584
27585
27586
27587
27588
27589
27590
27591
27592
27593
27594
27595
27596
27597
27598
27599
27600
27601
27602
27603
27604
27605
27606
27607
27608
27609
27610
27611
27612
27613
27614
27615
27616
27617
27618
27619
27620
27621
27622
27623
27624
27625
27626
27627
27628
27629
27630
27631
27632
27633
27634
27635
27636
27637
27638
27639
27640
27641
27642
27643
27644
27645
27646
27647
27648
27649
27650
27651
27652
27653
27654
27655
27656
27657
27658
27659
27660
27661
27662
27663
27664
27665
27666
27667
27668
27669
27670
27671
27672
27673
27674
27675
27676
27677
27678
27679
27680
27681
27682
27683
27684
27685
27686
27687
27688
27689
27690
27691
27692
27693
27694
27695
27696
27697
27698
27699
27700
27701
27702
27703
27704
27705
27706
27707
27708
27709
27710
27711
27712
27713
27714
27715
27716
27717
27718
27719
27720
27721
27722
27723
27724
27725
27726
27727
27728
27729
27730
27731
27732
27733
27734
27735
27736
27737
27738
27739
27740
27741
27742
27743
27744
27745
27746
27747
27748
27749
27750
27751
27752
27753
27754
27755
27756
27757
27758
27759
27760
27761
27762
27763
27764
27765
27766
27767
27768
27769
27770
27771
27772
27773
27774
27775
27776
27777
27778
27779
27780
27781
27782
27783
27784
27785
27786
27787
27788
27789
27790
27791
27792
27793
27794
27795
27796
27797
27798
27799
27800
27801
27802
27803
27804
27805
27806
27807
27808
27809
27810
27811
27812
27813
27814
27815
27816
27817
27818
27819
27820
27821
27822
27823
27824
27825
27826
27827
27828
27829
27830
27831
27832
27833
27834
27835
27836
27837
27838
27839
27840
27841
27842
27843
27844
27845
27846
27847
27848
27849
27850
27851
27852
27853
27854
27855
27856
27857
27858
27859
27860
27861
27862
27863
27864
27865
27866
27867
27868
27869
27870
27871
27872
27873
27874
27875
27876
27877
27878
27879
27880
27881
27882
27883
27884
27885
27886
27887
27888
27889
27890
27891
27892
27893
27894
27895
27896
27897
27898
27899
27900
27901
27902
27903
27904
27905
27906
27907
27908
27909
27910
27911
27912
27913
27914
27915
27916
27917
27918
27919
27920
27921
27922
27923
27924
27925
27926
27927
27928
27929
27930
27931
27932
27933
27934
27935
27936
27937
27938
27939
27940
27941
27942
27943
27944
27945
27946
27947
27948
27949
27950
27951
27952
27953
27954
27955
27956
27957
27958
27959
27960
27961
27962
27963
27964
27965
27966
27967
27968
27969
27970
27971
27972
27973
27974
27975
27976
27977
27978
27979
27980
27981
27982
27983
27984
27985
27986
27987
27988
27989
27990
27991
27992
27993
27994
27995
27996
27997
27998
27999
28000
28001
28002
28003
28004
28005
28006
28007
28008
28009
28010
28011
28012
28013
28014
28015
28016
28017
28018
28019
28020
28021
28022
28023
28024
28025
28026
28027
28028
28029
28030
28031
28032
28033
28034
28035
28036
28037
28038
28039
28040
28041
28042
28043
28044
28045
28046
28047
28048
28049
28050
28051
28052
28053
28054
28055
28056
28057
28058
28059
28060
28061
28062
28063
28064
28065
28066
28067
28068
28069
28070
28071
28072
28073
28074
28075
28076
28077
28078
28079
28080
28081
28082
28083
28084
28085
28086
28087
28088
28089
28090
28091
28092
28093
28094
28095
28096
28097
28098
28099
28100
28101
28102
28103
28104
28105
28106
28107
28108
28109
28110
28111
28112
28113
28114
28115
28116
28117
28118
28119
28120
28121
28122
28123
28124
28125
28126
28127
28128
28129
28130
28131
28132
28133
28134
28135
28136
28137
28138
28139
28140
28141
28142
28143
28144
28145
28146
28147
28148
28149
28150
28151
28152
28153
28154
28155
28156
28157
28158
28159
28160
28161
28162
28163
28164
28165
28166
28167
28168
28169
28170
28171
28172
28173
28174
28175
28176
28177
28178
28179
28180
28181
28182
28183
28184
28185
28186
28187
28188
28189
28190
28191
28192
28193
28194
28195
28196
28197
28198
28199
28200
28201
28202
28203
28204
28205
28206
28207
28208
28209
28210
28211
28212
28213
28214
28215
28216
28217
28218
28219
28220
28221
28222
28223
28224
28225
28226
28227
28228
28229
28230
28231
28232
28233
28234
28235
28236
28237
28238
28239
28240
28241
28242
28243
28244
28245
28246
28247
28248
28249
28250
28251
28252
28253
28254
28255
28256
28257
28258
28259
28260
28261
28262
28263
28264
28265
28266
28267
28268
28269
28270
28271
28272
28273
28274
28275
28276
28277
28278
28279
28280
28281
28282
28283
28284
28285
28286
28287
28288
28289
28290
28291
28292
28293
28294
28295
28296
28297
28298
28299
28300
28301
28302
28303
28304
28305
28306
28307
28308
28309
28310
28311
28312
28313
28314
28315
28316
28317
28318
28319
28320
28321
28322
28323
28324
28325
28326
28327
28328
28329
28330
28331
28332
28333
28334
28335
28336
28337
28338
28339
28340
28341
28342
28343
28344
28345
28346
28347
28348
28349
28350
28351
28352
28353
28354
28355
28356
28357
28358
28359
28360
28361
28362
28363
28364
28365
28366
28367
28368
28369
28370
28371
28372
28373
28374
28375
28376
28377
28378
28379
28380
28381
28382
28383
28384
28385
28386
28387
28388
28389
28390
28391
28392
28393
28394
28395
28396
28397
28398
28399
28400
28401
28402
28403
28404
28405
28406
28407
28408
28409
28410
28411
28412
28413
28414
28415
28416
28417
28418
28419
28420
28421
28422
28423
28424
28425
28426
28427
28428
28429
28430
28431
28432
28433
28434
28435
28436
28437
28438
28439
28440
28441
28442
28443
28444
28445
28446
28447
28448
28449
28450
28451
28452
28453
28454
28455
28456
28457
28458
28459
28460
28461
28462
28463
28464
28465
28466
28467
28468
28469
28470
28471
28472
28473
28474
28475
28476
28477
28478
28479
28480
28481
28482
28483
28484
28485
28486
28487
28488
28489
28490
28491
28492
28493
28494
28495
28496
28497
28498
28499
28500
28501
28502
28503
28504
28505
28506
28507
28508
28509
28510
28511
28512
28513
28514
28515
28516
28517
28518
28519
28520
28521
28522
28523
28524
28525
28526
28527
28528
28529
28530
28531
28532
28533
28534
28535
28536
28537
28538
28539
28540
28541
28542
28543
28544
28545
28546
28547
28548
28549
28550
28551
28552
28553
28554
28555
28556
28557
28558
28559
28560
28561
28562
28563
28564
28565
28566
28567
28568
28569
28570
28571
28572
28573
28574
28575
28576
28577
28578
28579
28580
28581
28582
28583
28584
28585
28586
28587
28588
28589
28590
28591
28592
28593
28594
28595
28596
28597
28598
28599
28600
28601
28602
28603
28604
28605
28606
28607
28608
28609
28610
28611
28612
28613
28614
28615
28616
28617
28618
28619
28620
28621
28622
28623
28624
28625
28626
28627
28628
28629
28630
28631
28632
28633
28634
28635
28636
28637
28638
28639
28640
28641
28642
28643
28644
28645
28646
28647
28648
28649
28650
28651
28652
28653
28654
28655
28656
28657
28658
28659
28660
28661
28662
28663
28664
28665
28666
28667
28668
28669
28670
28671
28672
28673
28674
28675
28676
28677
28678
28679
28680
28681
28682
28683
28684
28685
28686
28687
28688
28689
28690
28691
28692
28693
28694
28695
28696
28697
28698
28699
28700
28701
28702
28703
28704
28705
28706
28707
28708
28709
28710
28711
28712
28713
28714
28715
28716
28717
28718
28719
28720
28721
28722
28723
28724
28725
28726
28727
28728
28729
28730
28731
28732
28733
28734
28735
28736
28737
28738
28739
28740
28741
28742
28743
28744
28745
28746
28747
28748
28749
28750
28751
28752
28753
28754
28755
28756
28757
28758
28759
28760
28761
28762
28763
28764
28765
28766
28767
28768
28769
28770
28771
28772
28773
28774
28775
28776
28777
28778
28779
28780
28781
28782
28783
28784
28785
28786
28787
28788
28789
28790
28791
28792
28793
28794
28795
28796
28797
28798
28799
28800
28801
28802
28803
28804
28805
28806
28807
28808
28809
28810
28811
28812
28813
28814
28815
28816
28817
28818
28819
28820
28821
28822
28823
28824
28825
28826
28827
28828
28829
28830
28831
28832
28833
28834
28835
28836
28837
28838
28839
28840
28841
28842
28843
28844
28845
28846
28847
28848
28849
28850
28851
28852
28853
28854
28855
28856
28857
28858
28859
28860
28861
28862
28863
28864
28865
28866
28867
28868
28869
28870
28871
28872
28873
28874
28875
28876
28877
28878
28879
28880
28881
28882
28883
28884
28885
28886
28887
28888
28889
28890
28891
28892
28893
28894
28895
28896
28897
28898
28899
28900
28901
28902
28903
28904
28905
28906
28907
28908
28909
28910
28911
28912
28913
28914
28915
28916
28917
28918
28919
28920
28921
28922
28923
28924
28925
28926
28927
28928
28929
28930
28931
28932
28933
28934
28935
28936
28937
28938
28939
28940
28941
28942
28943
28944
28945
28946
28947
28948
28949
28950
28951
28952
28953
28954
28955
28956
28957
28958
28959
28960
28961
28962
28963
28964
28965
28966
28967
28968
28969
28970
28971
28972
28973
28974
28975
28976
28977
28978
28979
28980
28981
28982
28983
28984
28985
28986
28987
28988
28989
28990
28991
28992
28993
28994
28995
28996
28997
28998
28999
29000
29001
29002
29003
29004
29005
29006
29007
29008
29009
29010
29011
29012
29013
29014
29015
29016
29017
29018
29019
29020
29021
29022
29023
29024
29025
29026
29027
29028
29029
29030
29031
29032
29033
29034
29035
29036
29037
29038
29039
29040
29041
29042
29043
29044
29045
29046
29047
29048
29049
29050
29051
29052
29053
29054
29055
29056
29057
29058
29059
29060
29061
29062
29063
29064
29065
29066
29067
29068
29069
29070
29071
29072
29073
29074
29075
29076
29077
29078
29079
29080
29081
29082
29083
29084
29085
29086
29087
29088
29089
29090
29091
29092
29093
29094
29095
29096
29097
29098
29099
29100
29101
29102
29103
29104
29105
29106
29107
29108
29109
29110
29111
29112
29113
29114
29115
29116
29117
29118
29119
29120
29121
29122
29123
29124
29125
29126
29127
29128
29129
29130
29131
29132
29133
29134
29135
29136
29137
29138
29139
29140
29141
29142
29143
29144
29145
29146
29147
29148
29149
29150
29151
29152
29153
29154
29155
29156
29157
29158
29159
29160
29161
29162
29163
29164
29165
29166
29167
29168
29169
29170
29171
29172
29173
29174
29175
29176
29177
29178
29179
29180
29181
29182
29183
29184
29185
29186
29187
29188
29189
29190
29191
29192
29193
29194
29195
29196
29197
29198
29199
29200
29201
29202
29203
29204
29205
29206
29207
29208
29209
29210
29211
29212
29213
29214
29215
29216
29217
29218
29219
29220
29221
29222
29223
29224
29225
29226
29227
29228
29229
29230
29231
29232
29233
29234
29235
29236
29237
29238
29239
29240
29241
29242
29243
29244
29245
29246
29247
29248
29249
29250
29251
29252
29253
29254
29255
29256
29257
29258
29259
29260
29261
29262
29263
29264
29265
29266
29267
29268
29269
29270
29271
29272
29273
29274
29275
29276
29277
29278
29279
29280
29281
29282
29283
29284
29285
29286
29287
29288
29289
29290
29291
29292
29293
29294
29295
29296
29297
29298
29299
29300
29301
29302
29303
29304
29305
29306
29307
29308
29309
29310
29311
29312
29313
29314
29315
29316
29317
29318
29319
29320
29321
29322
29323
29324
29325
29326
29327
29328
29329
29330
29331
29332
29333
29334
29335
29336
29337
29338
29339
29340
29341
29342
29343
29344
29345
29346
29347
29348
29349
29350
29351
29352
29353
29354
29355
29356
29357
29358
29359
29360
29361
29362
29363
29364
29365
29366
29367
29368
29369
29370
29371
29372
29373
29374
29375
29376
29377
29378
29379
29380
29381
29382
29383
29384
29385
29386
29387
29388
29389
29390
29391
29392
29393
29394
29395
29396
29397
29398
29399
29400
29401
29402
29403
29404
29405
29406
29407
29408
29409
29410
29411
29412
29413
29414
29415
29416
29417
29418
29419
29420
29421
29422
29423
29424
29425
29426
29427
29428
29429
29430
29431
29432
29433
29434
29435
29436
29437
29438
29439
29440
29441
29442
29443
29444
29445
29446
29447
29448
29449
29450
29451
29452
29453
29454
29455
29456
29457
29458
29459
29460
29461
29462
29463
29464
29465
29466
29467
29468
29469
29470
29471
29472
29473
29474
29475
29476
29477
29478
29479
29480
29481
29482
29483
29484
29485
29486
29487
29488
29489
29490
29491
29492
29493
29494
29495
29496
29497
29498
29499
29500
29501
29502
29503
29504
29505
29506
29507
29508
29509
29510
29511
29512
29513
29514
29515
29516
29517
29518
29519
29520
29521
29522
29523
29524
29525
29526
29527
29528
29529
29530
29531
29532
29533
29534
29535
29536
29537
29538
29539
29540
29541
29542
29543
29544
29545
29546
29547
29548
29549
29550
29551
29552
29553
29554
29555
29556
29557
29558
29559
29560
29561
29562
29563
29564
29565
29566
29567
29568
29569
29570
29571
29572
29573
29574
29575
29576
29577
29578
29579
29580
29581
29582
29583
29584
29585
29586
29587
29588
29589
29590
29591
29592
29593
29594
29595
29596
29597
29598
29599
29600
29601
29602
29603
29604
29605
29606
29607
29608
29609
29610
29611
29612
29613
29614
29615
29616
29617
29618
29619
29620
29621
29622
29623
29624
29625
29626
29627
29628
29629
29630
29631
29632
29633
29634
29635
29636
29637
29638
29639
29640
29641
29642
29643
29644
29645
29646
29647
29648
29649
29650
29651
29652
29653
29654
29655
29656
29657
29658
29659
29660
29661
29662
29663
29664
29665
29666
29667
29668
29669
29670
29671
29672
29673
29674
29675
29676
29677
29678
29679
29680
29681
29682
29683
29684
29685
29686
29687
29688
29689
29690
29691
29692
29693
29694
29695
29696
29697
29698
29699
29700
29701
29702
29703
29704
29705
29706
29707
29708
29709
29710
29711
29712
29713
29714
29715
29716
29717
29718
29719
29720
29721
29722
29723
29724
29725
29726
29727
29728
29729
29730
29731
29732
29733
29734
29735
29736
29737
29738
29739
29740
29741
29742
29743
29744
29745
29746
29747
29748
29749
29750
29751
29752
29753
29754
29755
29756
29757
29758
29759
29760
29761
29762
29763
29764
29765
29766
29767
29768
29769
29770
29771
29772
29773
29774
29775
29776
29777
29778
29779
29780
29781
29782
29783
29784
29785
29786
29787
29788
29789
29790
29791
29792
29793
29794
29795
29796
29797
29798
29799
29800
29801
29802
29803
29804
29805
29806
29807
29808
29809
29810
29811
29812
29813
29814
29815
29816
29817
29818
29819
29820
29821
29822
29823
29824
29825
29826
29827
29828
29829
29830
29831
29832
29833
29834
29835
29836
29837
29838
29839
29840
29841
29842
29843
29844
29845
29846
29847
29848
29849
29850
29851
29852
29853
29854
29855
29856
29857
29858
29859
29860
29861
29862
29863
29864
29865
29866
29867
29868
29869
29870
29871
29872
29873
29874
29875
29876
29877
29878
29879
29880
29881
29882
29883
29884
29885
29886
29887
29888
29889
29890
29891
29892
29893
29894
29895
29896
29897
29898
29899
29900
29901
29902
29903
29904
29905
29906
29907
29908
29909
29910
29911
29912
29913
29914
29915
29916
29917
29918
29919
29920
29921
29922
29923
29924
29925
29926
29927
29928
29929
29930
29931
29932
29933
29934
29935
29936
29937
29938
29939
29940
29941
29942
29943
29944
29945
29946
29947
29948
29949
29950
29951
29952
29953
29954
29955
29956
29957
29958
29959
29960
29961
29962
29963
29964
29965
29966
29967
29968
29969
29970
29971
29972
29973
29974
29975
29976
29977
29978
29979
29980
29981
29982
29983
29984
29985
29986
29987
29988
29989
29990
29991
29992
29993
29994
29995
29996
29997
29998
29999
30000
30001
30002
30003
30004
30005
30006
30007
30008
30009
30010
30011
30012
30013
30014
30015
30016
30017
30018
30019
30020
30021
30022
30023
30024
30025
30026
30027
30028
30029
30030
30031
30032
30033
30034
30035
30036
30037
30038
30039
30040
30041
30042
30043
30044
30045
30046
30047
30048
30049
30050
30051
30052
30053
30054
30055
30056
30057
30058
30059
30060
30061
30062
30063
30064
30065
30066
30067
30068
30069
30070
30071
30072
30073
30074
30075
30076
30077
30078
30079
30080
30081
30082
30083
30084
30085
30086
30087
30088
30089
30090
30091
30092
30093
30094
30095
30096
30097
30098
30099
30100
30101
30102
30103
30104
30105
30106
30107
30108
30109
30110
30111
30112
30113
30114
30115
30116
30117
30118
30119
30120
30121
30122
30123
30124
30125
30126
30127
30128
30129
30130
30131
30132
30133
30134
30135
30136
30137
30138
30139
30140
30141
30142
30143
30144
30145
30146
30147
30148
30149
30150
30151
30152
30153
30154
30155
30156
30157
30158
30159
30160
30161
30162
30163
30164
30165
30166
30167
30168
30169
30170
30171
30172
30173
30174
30175
30176
30177
30178
30179
30180
30181
30182
30183
30184
30185
30186
30187
30188
30189
30190
30191
30192
30193
30194
30195
30196
30197
30198
30199
30200
30201
30202
30203
30204
30205
30206
30207
30208
30209
30210
30211
30212
30213
30214
30215
30216
30217
30218
30219
30220
30221
30222
30223
30224
30225
30226
30227
30228
30229
30230
30231
30232
30233
30234
30235
30236
30237
30238
30239
30240
30241
30242
30243
30244
30245
30246
30247
30248
30249
30250
30251
30252
30253
30254
30255
30256
30257
30258
30259
30260
30261
30262
30263
30264
30265
30266
30267
30268
30269
30270
30271
30272
30273
30274
30275
30276
30277
30278
30279
30280
30281
30282
30283
30284
30285
30286
30287
30288
30289
30290
30291
30292
30293
30294
30295
30296
30297
30298
30299
30300
30301
30302
30303
30304
30305
30306
30307
30308
30309
30310
30311
30312
30313
30314
30315
30316
30317
30318
30319
30320
30321
30322
30323
30324
30325
30326
30327
30328
30329
30330
30331
30332
30333
30334
30335
30336
30337
30338
30339
30340
30341
30342
30343
30344
30345
30346
30347
30348
30349
30350
30351
30352
30353
30354
30355
30356
30357
30358
30359
30360
30361
30362
30363
30364
30365
30366
30367
30368
30369
30370
30371
30372
30373
30374
30375
30376
30377
30378
30379
30380
30381
30382
30383
30384
30385
30386
30387
30388
30389
30390
30391
30392
30393
30394
30395
30396
30397
30398
30399
30400
30401
30402
30403
30404
30405
30406
30407
30408
30409
30410
30411
30412
30413
30414
30415
30416
30417
30418
30419
30420
30421
30422
30423
30424
30425
30426
30427
30428
30429
30430
30431
30432
30433
30434
30435
30436
30437
30438
30439
30440
30441
30442
30443
30444
30445
30446
30447
30448
30449
30450
30451
30452
30453
30454
30455
30456
30457
30458
30459
30460
30461
30462
30463
30464
30465
30466
30467
30468
30469
30470
30471
30472
30473
30474
30475
30476
30477
30478
30479
30480
30481
30482
30483
30484
30485
30486
30487
30488
30489
30490
30491
30492
30493
30494
30495
30496
30497
30498
30499
30500
30501
30502
30503
30504
30505
30506
30507
30508
30509
30510
30511
30512
30513
30514
30515
30516
30517
30518
30519
30520
30521
30522
30523
30524
30525
30526
30527
30528
30529
30530
30531
30532
30533
30534
30535
30536
30537
30538
30539
30540
30541
30542
30543
30544
30545
30546
30547
30548
30549
30550
30551
30552
30553
30554
30555
30556
30557
30558
30559
30560
30561
30562
30563
30564
30565
30566
30567
30568
30569
30570
30571
30572
30573
30574
30575
30576
30577
30578
30579
30580
30581
30582
30583
30584
30585
30586
30587
30588
30589
30590
30591
30592
30593
30594
30595
30596
30597
30598
30599
30600
30601
30602
30603
30604
30605
30606
30607
30608
30609
30610
30611
30612
30613
30614
30615
30616
30617
30618
30619
30620
30621
30622
30623
30624
30625
30626
30627
30628
30629
30630
30631
30632
30633
30634
30635
30636
30637
30638
30639
30640
30641
30642
30643
30644
30645
30646
30647
30648
30649
30650
30651
30652
30653
30654
30655
30656
30657
30658
30659
30660
30661
30662
30663
30664
30665
30666
30667
30668
30669
30670
30671
30672
30673
30674
30675
30676
30677
30678
30679
30680
30681
30682
30683
30684
30685
30686
30687
30688
30689
30690
30691
30692
30693
30694
30695
30696
30697
30698
30699
30700
30701
30702
30703
30704
30705
30706
30707
30708
30709
30710
30711
30712
30713
30714
30715
30716
30717
30718
30719
30720
30721
30722
30723
30724
30725
30726
30727
30728
30729
30730
30731
30732
30733
30734
30735
30736
30737
30738
30739
30740
30741
30742
30743
30744
30745
30746
30747
30748
30749
30750
30751
30752
30753
30754
30755
30756
30757
30758
30759
30760
30761
30762
30763
30764
30765
30766
30767
30768
30769
30770
30771
30772
30773
30774
30775
30776
30777
30778
30779
30780
30781
30782
30783
30784
30785
30786
30787
30788
30789
30790
30791
30792
30793
30794
30795
30796
30797
30798
30799
30800
30801
30802
30803
30804
30805
30806
30807
30808
30809
30810
30811
30812
30813
30814
30815
30816
30817
30818
30819
30820
30821
30822
30823
30824
30825
30826
30827
30828
30829
30830
30831
30832
30833
30834
30835
30836
30837
30838
30839
30840
30841
30842
30843
30844
30845
30846
30847
30848
30849
30850
30851
30852
30853
30854
30855
30856
30857
30858
30859
30860
30861
30862
30863
30864
30865
30866
30867
30868
30869
30870
30871
30872
30873
30874
30875
30876
30877
30878
30879
30880
30881
30882
30883
30884
30885
30886
30887
30888
30889
30890
30891
30892
30893
30894
30895
30896
30897
30898
30899
30900
30901
30902
30903
30904
30905
30906
30907
30908
30909
30910
30911
30912
30913
30914
30915
30916
30917
30918
30919
30920
30921
30922
30923
30924
30925
30926
30927
30928
30929
30930
30931
30932
30933
30934
30935
30936
30937
30938
30939
30940
30941
30942
30943
30944
30945
30946
30947
30948
30949
30950
30951
30952
30953
30954
30955
30956
30957
30958
30959
30960
30961
30962
30963
30964
30965
30966
30967
30968
30969
30970
30971
30972
30973
30974
30975
30976
30977
30978
30979
30980
30981
30982
30983
30984
30985
30986
30987
30988
30989
30990
30991
30992
30993
30994
30995
30996
30997
30998
30999
31000
31001
31002
31003
31004
31005
31006
31007
31008
31009
31010
31011
31012
31013
31014
31015
31016
31017
31018
31019
31020
31021
31022
31023
31024
31025
31026
31027
31028
31029
31030
31031
31032
31033
31034
31035
31036
31037
31038
31039
31040
31041
31042
31043
31044
31045
31046
31047
31048
31049
31050
31051
31052
31053
31054
31055
31056
31057
31058
31059
31060
31061
31062
31063
31064
31065
31066
31067
31068
31069
31070
31071
31072
31073
31074
31075
31076
31077
31078
31079
31080
31081
31082
31083
31084
31085
31086
31087
31088
31089
31090
31091
31092
31093
31094
31095
31096
31097
31098
31099
31100
31101
31102
31103
31104
31105
31106
31107
31108
31109
31110
31111
31112
31113
31114
31115
31116
31117
31118
31119
31120
31121
31122
31123
31124
31125
31126
31127
31128
31129
31130
31131
31132
31133
31134
31135
31136
31137
31138
31139
31140
31141
31142
31143
31144
31145
31146
31147
31148
31149
31150
31151
31152
31153
31154
31155
31156
31157
31158
31159
31160
31161
31162
31163
31164
31165
31166
31167
31168
31169
31170
31171
31172
31173
31174
31175
31176
31177
31178
31179
31180
31181
31182
31183
31184
31185
31186
31187
31188
31189
31190
31191
31192
31193
31194
31195
31196
31197
31198
31199
31200
31201
31202
31203
31204
31205
31206
31207
31208
31209
31210
31211
31212
31213
31214
31215
31216
31217
31218
31219
31220
31221
31222
31223
31224
31225
31226
31227
31228
31229
31230
31231
31232
31233
31234
31235
31236
31237
31238
31239
31240
31241
31242
31243
31244
31245
31246
31247
31248
31249
31250
31251
31252
31253
31254
31255
31256
31257
31258
31259
31260
31261
31262
31263
31264
31265
31266
31267
31268
31269
31270
31271
31272
31273
31274
31275
31276
31277
31278
31279
31280
31281
31282
31283
31284
31285
31286
31287
31288
31289
31290
31291
31292
31293
31294
31295
31296
31297
31298
31299
31300
31301
31302
31303
31304
31305
31306
31307
31308
31309
31310
31311
31312
31313
31314
31315
31316
31317
31318
31319
31320
31321
31322
31323
31324
31325
31326
31327
31328
31329
31330
31331
31332
31333
31334
31335
31336
31337
31338
31339
31340
31341
31342
31343
31344
31345
31346
31347
31348
31349
31350
31351
31352
31353
31354
31355
31356
31357
31358
31359
31360
31361
31362
31363
31364
31365
31366
31367
31368
31369
31370
31371
31372
31373
31374
31375
31376
31377
31378
31379
31380
31381
31382
31383
31384
31385
31386
31387
31388
31389
31390
31391
31392
31393
31394
31395
31396
31397
31398
31399
31400
31401
31402
31403
31404
31405
31406
31407
31408
31409
31410
31411
31412
31413
31414
31415
31416
31417
31418
31419
31420
31421
31422
31423
31424
31425
31426
31427
31428
31429
31430
31431
31432
31433
31434
31435
31436
31437
31438
31439
31440
31441
31442
31443
31444
31445
31446
31447
31448
31449
31450
31451
31452
31453
31454
31455
31456
31457
31458
31459
31460
31461
31462
31463
31464
31465
31466
31467
31468
31469
31470
31471
31472
31473
31474
31475
31476
31477
31478
31479
31480
31481
31482
31483
31484
31485
31486
31487
31488
31489
31490
31491
31492
31493
31494
31495
31496
31497
31498
31499
31500
31501
31502
31503
31504
31505
31506
31507
31508
31509
31510
31511
31512
31513
31514
31515
31516
31517
31518
31519
31520
31521
31522
31523
31524
31525
31526
31527
31528
31529
31530
31531
31532
31533
31534
31535
31536
31537
31538
31539
31540
31541
31542
31543
31544
31545
31546
31547
31548
31549
31550
31551
31552
31553
31554
31555
31556
31557
31558
31559
31560
31561
31562
31563
31564
31565
31566
31567
31568
31569
31570
31571
31572
31573
31574
31575
31576
31577
31578
31579
31580
31581
31582
31583
31584
31585
31586
31587
31588
31589
31590
31591
31592
31593
31594
31595
31596
31597
31598
31599
31600
31601
31602
31603
31604
31605
31606
31607
31608
31609
31610
31611
31612
31613
31614
31615
31616
31617
31618
31619
31620
31621
31622
31623
31624
31625
31626
31627
31628
31629
31630
31631
31632
31633
31634
31635
31636
31637
31638
31639
31640
31641
31642
31643
31644
31645
31646
31647
31648
31649
31650
31651
31652
31653
31654
31655
31656
31657
31658
31659
31660
31661
31662
31663
31664
31665
31666
31667
31668
31669
31670
31671
31672
31673
31674
31675
31676
31677
31678
31679
31680
31681
31682
31683
31684
31685
31686
31687
31688
31689
31690
31691
31692
31693
31694
31695
31696
31697
31698
31699
31700
31701
31702
31703
31704
31705
31706
31707
31708
31709
31710
31711
31712
31713
31714
31715
31716
31717
31718
31719
31720
31721
31722
31723
31724
31725
31726
31727
31728
31729
31730
31731
31732
31733
31734
31735
31736
31737
31738
31739
31740
31741
31742
31743
31744
31745
31746
31747
31748
31749
31750
31751
31752
31753
31754
31755
31756
31757
31758
31759
31760
31761
31762
31763
31764
31765
31766
31767
31768
31769
31770
31771
31772
31773
31774
31775
31776
31777
31778
31779
31780
31781
31782
31783
31784
31785
31786
31787
31788
31789
31790
31791
31792
31793
31794
31795
31796
31797
31798
31799
31800
31801
31802
31803
31804
31805
31806
31807
31808
31809
31810
31811
31812
31813
31814
31815
31816
31817
31818
31819
31820
31821
31822
31823
31824
31825
31826
31827
31828
31829
31830
31831
31832
31833
31834
31835
31836
31837
31838
31839
31840
31841
31842
31843
31844
31845
31846
31847
31848
31849
31850
31851
31852
31853
31854
31855
31856
31857
31858
31859
31860
31861
31862
31863
31864
31865
31866
31867
31868
31869
31870
31871
31872
31873
31874
31875
31876
31877
31878
31879
31880
31881
31882
31883
31884
31885
31886
31887
31888
31889
31890
31891
31892
31893
31894
31895
31896
31897
31898
31899
31900
31901
31902
31903
31904
31905
31906
31907
31908
31909
31910
31911
31912
31913
31914
31915
31916
31917
31918
31919
31920
31921
31922
31923
31924
31925
31926
31927
31928
31929
31930
31931
31932
31933
31934
31935
31936
31937
31938
31939
31940
31941
31942
31943
31944
31945
31946
31947
31948
31949
31950
31951
31952
31953
31954
31955
31956
31957
31958
31959
31960
31961
31962
31963
31964
31965
31966
31967
31968
31969
31970
31971
31972
31973
31974
31975
31976
31977
31978
31979
31980
31981
31982
31983
31984
31985
31986
31987
31988
31989
31990
31991
31992
31993
31994
31995
31996
31997
31998
31999
32000
32001
32002
32003
32004
32005
32006
32007
32008
32009
32010
32011
32012
32013
32014
32015
32016
32017
32018
32019
32020
32021
32022
32023
32024
32025
32026
32027
32028
32029
32030
32031
32032
32033
32034
32035
32036
32037
32038
32039
32040
32041
32042
32043
32044
32045
32046
32047
32048
32049
32050
32051
32052
32053
32054
32055
32056
32057
32058
32059
32060
32061
32062
32063
32064
32065
32066
32067
32068
32069
32070
32071
32072
32073
32074
32075
32076
32077
32078
32079
32080
32081
32082
32083
32084
32085
32086
32087
32088
32089
32090
32091
32092
32093
32094
32095
32096
32097
32098
32099
32100
32101
32102
32103
32104
32105
32106
32107
32108
32109
32110
32111
32112
32113
32114
32115
32116
32117
32118
32119
32120
32121
32122
32123
32124
32125
32126
32127
32128
32129
32130
32131
32132
32133
32134
32135
32136
32137
32138
32139
32140
32141
32142
32143
32144
32145
32146
32147
32148
32149
32150
32151
32152
32153
32154
32155
32156
32157
32158
32159
32160
32161
32162
32163
32164
32165
32166
32167
32168
32169
32170
32171
32172
32173
32174
32175
32176
32177
32178
32179
32180
32181
32182
32183
32184
32185
32186
32187
32188
32189
32190
32191
32192
32193
32194
32195
32196
32197
32198
32199
32200
32201
32202
32203
32204
32205
32206
32207
32208
32209
32210
32211
32212
32213
32214
32215
32216
32217
32218
32219
32220
32221
32222
32223
32224
32225
32226
32227
32228
32229
32230
32231
32232
32233
32234
32235
32236
32237
32238
32239
32240
32241
32242
32243
32244
32245
32246
32247
32248
32249
32250
32251
32252
32253
32254
32255
32256
32257
32258
32259
32260
32261
32262
32263
32264
32265
32266
32267
32268
32269
32270
32271
32272
32273
32274
32275
32276
32277
32278
32279
32280
32281
32282
32283
32284
32285
32286
32287
32288
32289
32290
32291
32292
32293
32294
32295
32296
32297
32298
32299
32300
32301
32302
32303
32304
32305
32306
32307
32308
32309
32310
32311
32312
32313
32314
32315
32316
32317
32318
32319
32320
32321
32322
32323
32324
32325
32326
32327
32328
32329
32330
32331
32332
32333
32334
32335
32336
32337
32338
32339
32340
32341
32342
32343
32344
32345
32346
32347
32348
32349
32350
32351
32352
32353
32354
32355
32356
32357
32358
32359
32360
32361
32362
32363
32364
32365
32366
32367
32368
32369
32370
32371
32372
32373
32374
32375
32376
32377
32378
32379
32380
32381
32382
32383
32384
32385
32386
32387
32388
32389
32390
32391
32392
32393
32394
32395
32396
32397
32398
32399
32400
32401
32402
32403
32404
32405
32406
32407
32408
32409
32410
32411
32412
32413
32414
32415
32416
32417
32418
32419
32420
32421
32422
32423
32424
32425
32426
32427
32428
32429
32430
32431
32432
32433
32434
32435
32436
32437
32438
32439
32440
32441
32442
32443
32444
32445
32446
32447
32448
32449
32450
32451
32452
32453
32454
32455
32456
32457
32458
32459
32460
32461
32462
32463
32464
32465
32466
32467
32468
32469
32470
32471
32472
32473
32474
32475
32476
32477
32478
32479
32480
32481
32482
32483
32484
32485
32486
32487
32488
32489
32490
32491
32492
32493
32494
32495
32496
32497
32498
32499
32500
32501
32502
32503
32504
32505
32506
32507
32508
32509
32510
32511
32512
32513
32514
32515
32516
32517
32518
32519
32520
32521
32522
32523
32524
32525
32526
32527
32528
32529
32530
32531
32532
32533
32534
32535
32536
32537
32538
32539
32540
32541
32542
32543
32544
32545
32546
32547
32548
32549
32550
32551
32552
32553
32554
32555
32556
32557
32558
32559
32560
32561
32562
32563
32564
32565
32566
32567
32568
32569
32570
32571
32572
32573
32574
32575
32576
32577
32578
32579
32580
32581
32582
32583
32584
32585
32586
32587
32588
32589
32590
32591
32592
32593
32594
32595
32596
32597
32598
32599
32600
32601
32602
32603
32604
32605
32606
32607
32608
32609
32610
32611
32612
32613
32614
32615
32616
32617
32618
32619
32620
32621
32622
32623
32624
32625
32626
32627
32628
32629
32630
32631
32632
32633
32634
32635
32636
32637
32638
32639
32640
32641
32642
32643
32644
32645
32646
32647
32648
32649
32650
32651
32652
32653
32654
32655
32656
32657
32658
32659
32660
32661
32662
32663
32664
32665
32666
32667
32668
32669
32670
32671
32672
32673
32674
32675
32676
32677
32678
32679
32680
32681
32682
32683
32684
32685
32686
32687
32688
32689
32690
32691
32692
32693
32694
32695
32696
32697
32698
32699
32700
32701
32702
32703
32704
32705
32706
32707
32708
32709
32710
32711
32712
32713
32714
32715
32716
32717
32718
32719
32720
32721
32722
32723
32724
32725
32726
32727
32728
32729
32730
32731
32732
32733
32734
32735
32736
32737
32738
32739
32740
32741
32742
32743
32744
32745
32746
32747
32748
32749
32750
32751
32752
32753
32754
32755
32756
32757
32758
32759
32760
32761
32762
32763
32764
32765
32766
32767
32768
32769
32770
32771
32772
32773
32774
32775
32776
32777
32778
32779
32780
32781
32782
32783
32784
32785
32786
32787
32788
32789
32790
32791
32792
32793
32794
32795
32796
32797
32798
32799
32800
32801
32802
32803
32804
32805
32806
32807
32808
32809
32810
32811
32812
32813
32814
32815
32816
32817
32818
32819
32820
32821
32822
32823
32824
32825
32826
32827
32828
32829
32830
32831
32832
32833
32834
32835
32836
32837
32838
32839
32840
32841
32842
32843
32844
32845
32846
32847
32848
32849
32850
32851
32852
32853
32854
32855
32856
32857
32858
32859
32860
32861
32862
32863
32864
32865
32866
32867
32868
32869
32870
32871
32872
32873
32874
32875
32876
32877
32878
32879
32880
32881
32882
32883
32884
32885
32886
32887
32888
32889
32890
32891
32892
32893
32894
32895
32896
32897
32898
32899
32900
32901
32902
32903
32904
32905
32906
32907
32908
32909
32910
32911
32912
32913
32914
32915
32916
32917
32918
32919
32920
32921
32922
32923
32924
32925
32926
32927
32928
32929
32930
32931
32932
32933
32934
32935
32936
32937
32938
32939
32940
32941
32942
32943
32944
32945
32946
32947
32948
32949
32950
32951
32952
32953
32954
32955
32956
32957
32958
32959
32960
32961
32962
32963
32964
32965
32966
32967
32968
32969
32970
32971
32972
32973
32974
32975
32976
32977
32978
32979
32980
32981
32982
32983
32984
32985
32986
32987
32988
32989
32990
32991
32992
32993
32994
32995
32996
32997
32998
32999
33000
33001
33002
33003
33004
33005
33006
33007
33008
33009
33010
33011
33012
33013
33014
33015
33016
33017
33018
33019
33020
33021
33022
33023
33024
33025
33026
33027
33028
33029
33030
33031
33032
33033
33034
33035
33036
33037
33038
33039
33040
33041
33042
33043
33044
33045
33046
33047
33048
33049
33050
33051
33052
33053
33054
33055
33056
33057
33058
33059
33060
33061
33062
33063
33064
33065
33066
33067
33068
33069
33070
33071
33072
33073
33074
33075
33076
33077
33078
33079
33080
33081
33082
33083
33084
33085
33086
33087
33088
33089
33090
33091
33092
33093
33094
33095
33096
33097
33098
33099
33100
33101
33102
33103
33104
33105
33106
33107
33108
33109
33110
33111
33112
33113
33114
33115
33116
33117
33118
33119
33120
33121
33122
33123
33124
33125
33126
33127
33128
33129
33130
33131
33132
33133
33134
33135
33136
33137
33138
33139
33140
33141
33142
33143
33144
33145
33146
33147
33148
33149
33150
33151
33152
33153
33154
33155
33156
33157
33158
33159
33160
33161
33162
33163
33164
33165
33166
33167
33168
33169
33170
33171
33172
33173
33174
33175
33176
33177
33178
33179
33180
33181
33182
33183
33184
33185
33186
33187
33188
33189
33190
33191
33192
33193
33194
33195
33196
33197
33198
33199
33200
33201
33202
33203
33204
33205
33206
33207
33208
33209
33210
33211
33212
33213
33214
33215
33216
33217
33218
33219
33220
33221
33222
33223
33224
33225
33226
33227
33228
33229
33230
33231
33232
33233
33234
33235
33236
33237
33238
33239
33240
33241
33242
33243
33244
33245
33246
33247
33248
33249
33250
33251
33252
33253
33254
33255
33256
33257
33258
33259
33260
33261
33262
33263
33264
33265
33266
33267
33268
33269
33270
33271
33272
33273
33274
33275
33276
33277
33278
33279
33280
33281
33282
33283
33284
33285
33286
33287
33288
33289
33290
33291
33292
33293
33294
33295
33296
33297
33298
33299
33300
33301
33302
33303
33304
33305
33306
33307
33308
33309
33310
33311
33312
33313
33314
33315
33316
33317
33318
33319
33320
33321
33322
33323
33324
33325
33326
33327
33328
33329
33330
33331
33332
33333
33334
33335
33336
33337
33338
33339
33340
33341
33342
33343
33344
33345
33346
33347
33348
33349
33350
33351
33352
33353
33354
33355
33356
33357
33358
33359
33360
33361
33362
33363
33364
33365
33366
33367
33368
33369
33370
33371
33372
33373
33374
33375
33376
33377
33378
33379
33380
33381
33382
33383
33384
33385
33386
33387
33388
33389
33390
33391
33392
33393
33394
33395
33396
33397
33398
33399
33400
33401
33402
33403
33404
33405
33406
33407
33408
33409
33410
33411
33412
33413
33414
33415
33416
33417
33418
33419
33420
33421
33422
33423
33424
33425
33426
33427
33428
33429
33430
33431
33432
33433
33434
33435
33436
33437
33438
33439
33440
33441
33442
33443
33444
33445
33446
33447
33448
33449
33450
33451
33452
33453
33454
33455
33456
33457
33458
33459
33460
33461
33462
33463
33464
33465
33466
33467
33468
33469
33470
33471
33472
33473
33474
33475
33476
33477
33478
33479
33480
33481
33482
33483
33484
33485
33486
33487
33488
33489
33490
33491
33492
33493
33494
33495
33496
33497
33498
33499
33500
33501
33502
33503
33504
33505
33506
33507
33508
33509
33510
33511
33512
33513
33514
33515
33516
33517
33518
33519
33520
33521
33522
33523
33524
33525
33526
33527
33528
33529
33530
33531
33532
33533
33534
33535
33536
33537
33538
33539
33540
33541
33542
33543
33544
33545
33546
33547
33548
33549
33550
33551
33552
33553
33554
33555
33556
33557
33558
33559
33560
33561
33562
33563
33564
33565
33566
33567
33568
33569
33570
33571
33572
33573
33574
33575
33576
33577
33578
33579
33580
33581
33582
33583
33584
33585
33586
33587
33588
33589
33590
33591
33592
33593
33594
33595
33596
33597
33598
33599
33600
33601
33602
33603
33604
33605
33606
33607
33608
33609
33610
33611
33612
33613
33614
33615
33616
33617
33618
33619
33620
33621
33622
33623
33624
33625
33626
33627
33628
33629
33630
33631
33632
33633
33634
33635
33636
33637
33638
33639
33640
33641
33642
33643
33644
33645
33646
33647
33648
33649
33650
33651
33652
33653
33654
33655
33656
33657
33658
33659
33660
33661
33662
33663
33664
33665
33666
33667
33668
33669
33670
33671
33672
33673
33674
33675
33676
33677
33678
33679
33680
33681
33682
33683
33684
33685
33686
33687
33688
33689
33690
33691
33692
33693
33694
33695
33696
33697
33698
33699
33700
33701
33702
33703
33704
33705
33706
33707
33708
33709
33710
33711
33712
33713
33714
33715
33716
33717
33718
33719
33720
33721
33722
33723
33724
33725
33726
33727
33728
33729
33730
33731
33732
33733
33734
33735
33736
33737
33738
33739
33740
33741
33742
33743
33744
33745
33746
33747
33748
33749
33750
33751
33752
33753
33754
33755
33756
33757
33758
33759
33760
33761
33762
33763
33764
33765
33766
33767
33768
33769
33770
33771
33772
33773
33774
33775
33776
33777
33778
33779
33780
33781
33782
33783
33784
33785
33786
33787
33788
33789
33790
33791
33792
33793
33794
33795
33796
33797
33798
33799
33800
33801
33802
33803
33804
33805
33806
33807
33808
33809
33810
33811
33812
33813
33814
33815
33816
33817
33818
33819
33820
33821
33822
33823
33824
33825
33826
33827
33828
33829
33830
33831
33832
33833
33834
33835
33836
33837
33838
33839
33840
33841
33842
33843
33844
33845
33846
33847
33848
33849
33850
33851
33852
33853
33854
33855
33856
33857
33858
33859
33860
33861
33862
33863
33864
33865
33866
33867
33868
33869
33870
33871
33872
33873
33874
33875
33876
33877
33878
33879
33880
33881
33882
33883
33884
33885
33886
33887
33888
33889
33890
33891
33892
33893
33894
33895
33896
33897
33898
33899
33900
33901
33902
33903
33904
33905
33906
33907
33908
33909
33910
33911
33912
33913
33914
33915
33916
33917
33918
33919
33920
33921
33922
33923
33924
33925
33926
33927
33928
33929
33930
33931
33932
33933
33934
33935
33936
33937
33938
33939
33940
33941
33942
33943
33944
33945
33946
33947
33948
33949
33950
33951
33952
33953
33954
33955
33956
33957
33958
33959
33960
33961
33962
33963
33964
33965
33966
33967
33968
33969
33970
33971
33972
33973
33974
33975
33976
33977
33978
33979
33980
33981
33982
33983
33984
33985
33986
33987
33988
33989
33990
33991
33992
33993
33994
33995
33996
33997
33998
33999
34000
34001
34002
34003
34004
34005
34006
34007
34008
34009
34010
34011
34012
34013
34014
34015
34016
34017
34018
34019
34020
34021
34022
34023
34024
34025
34026
34027
34028
34029
34030
34031
34032
34033
34034
34035
34036
34037
34038
34039
34040
34041
34042
34043
34044
34045
34046
34047
34048
34049
34050
34051
34052
34053
34054
34055
34056
34057
34058
34059
34060
34061
34062
34063
34064
34065
34066
34067
34068
34069
34070
34071
34072
34073
34074
34075
34076
34077
34078
34079
34080
34081
34082
34083
34084
34085
34086
34087
34088
34089
34090
34091
34092
34093
34094
34095
34096
34097
34098
34099
34100
34101
34102
34103
34104
34105
34106
34107
34108
34109
34110
34111
34112
34113
34114
34115
34116
34117
34118
34119
34120
34121
34122
34123
34124
34125
34126
34127
34128
34129
34130
34131
34132
34133
34134
34135
34136
34137
34138
34139
34140
34141
34142
34143
34144
34145
34146
34147
34148
34149
34150
34151
34152
34153
34154
34155
34156
34157
34158
34159
34160
34161
34162
34163
34164
34165
34166
34167
34168
34169
34170
34171
34172
34173
34174
34175
34176
34177
34178
34179
34180
34181
34182
34183
34184
34185
34186
34187
34188
34189
34190
34191
34192
34193
34194
34195
34196
34197
34198
34199
34200
34201
34202
34203
34204
34205
34206
34207
34208
34209
34210
34211
34212
34213
34214
34215
34216
34217
34218
34219
34220
34221
34222
34223
34224
34225
34226
34227
34228
34229
34230
34231
34232
34233
34234
34235
34236
34237
34238
34239
34240
34241
34242
34243
34244
34245
34246
34247
34248
34249
34250
34251
34252
34253
34254
34255
34256
34257
34258
34259
34260
34261
34262
34263
34264
34265
34266
34267
34268
34269
34270
34271
34272
34273
34274
34275
34276
34277
34278
34279
34280
34281
34282
34283
34284
34285
34286
34287
34288
34289
34290
34291
34292
34293
34294
34295
34296
34297
34298
34299
34300
34301
34302
34303
34304
34305
34306
34307
34308
34309
34310
34311
34312
34313
34314
34315
34316
34317
34318
34319
34320
34321
34322
34323
34324
34325
34326
34327
34328
34329
34330
34331
34332
34333
34334
34335
34336
34337
34338
34339
34340
34341
34342
34343
34344
34345
34346
34347
34348
34349
34350
34351
34352
34353
34354
34355
34356
34357
34358
34359
34360
34361
34362
34363
34364
34365
34366
34367
34368
34369
34370
34371
34372
34373
34374
34375
34376
34377
34378
34379
34380
34381
34382
34383
34384
34385
34386
34387
34388
34389
34390
34391
34392
34393
34394
34395
34396
34397
34398
34399
34400
34401
34402
34403
34404
34405
34406
34407
34408
34409
34410
34411
34412
34413
34414
34415
34416
34417
34418
34419
34420
34421
34422
34423
34424
34425
34426
34427
34428
34429
34430
34431
34432
34433
34434
34435
34436
34437
34438
34439
34440
34441
34442
34443
34444
34445
34446
34447
34448
34449
34450
34451
34452
34453
34454
34455
34456
34457
34458
34459
34460
34461
34462
34463
34464
34465
34466
34467
34468
34469
34470
34471
34472
34473
34474
34475
34476
34477
34478
34479
34480
34481
34482
34483
34484
34485
34486
34487
34488
34489
34490
34491
34492
34493
34494
34495
34496
34497
34498
34499
34500
34501
34502
34503
34504
34505
34506
34507
34508
34509
34510
34511
34512
34513
34514
34515
34516
34517
34518
34519
34520
34521
34522
34523
34524
34525
34526
34527
34528
34529
34530
34531
34532
34533
34534
34535
34536
34537
34538
34539
34540
34541
34542
34543
34544
34545
34546
34547
34548
34549
34550
34551
34552
34553
34554
34555
34556
34557
34558
34559
34560
34561
34562
34563
34564
34565
34566
34567
34568
34569
34570
34571
34572
34573
34574
34575
34576
34577
34578
34579
34580
34581
34582
34583
34584
34585
34586
34587
34588
34589
34590
34591
34592
34593
34594
34595
34596
34597
34598
34599
34600
34601
34602
34603
34604
34605
34606
34607
34608
34609
34610
34611
34612
34613
34614
34615
34616
34617
34618
34619
34620
34621
34622
34623
34624
34625
34626
34627
34628
34629
34630
34631
34632
34633
34634
34635
34636
34637
34638
34639
34640
34641
34642
34643
34644
34645
34646
34647
34648
34649
34650
34651
34652
34653
34654
34655
34656
34657
34658
34659
34660
34661
34662
34663
34664
34665
34666
34667
34668
34669
34670
34671
34672
34673
34674
34675
34676
34677
34678
34679
34680
34681
34682
34683
34684
34685
34686
34687
34688
34689
34690
34691
34692
34693
34694
34695
34696
34697
34698
34699
34700
34701
34702
34703
34704
34705
34706
34707
34708
34709
34710
34711
34712
34713
34714
34715
34716
34717
34718
34719
34720
34721
34722
34723
34724
34725
34726
34727
34728
34729
34730
34731
34732
34733
34734
34735
34736
34737
34738
34739
34740
34741
34742
34743
34744
34745
34746
34747
34748
34749
34750
34751
34752
34753
34754
34755
34756
34757
34758
34759
34760
34761
34762
34763
34764
34765
34766
34767
34768
34769
34770
34771
34772
34773
34774
34775
34776
34777
34778
34779
34780
34781
34782
34783
34784
34785
34786
34787
34788
34789
34790
34791
34792
34793
34794
34795
34796
34797
34798
34799
34800
34801
34802
34803
34804
34805
34806
34807
34808
34809
34810
34811
34812
34813
34814
34815
34816
34817
34818
34819
34820
34821
34822
34823
34824
34825
34826
34827
34828
34829
34830
34831
34832
34833
34834
34835
34836
34837
34838
34839
34840
34841
34842
34843
34844
34845
34846
34847
34848
34849
34850
34851
34852
34853
34854
34855
34856
34857
34858
34859
34860
34861
34862
34863
34864
34865
34866
34867
34868
34869
34870
34871
34872
34873
34874
34875
34876
34877
34878
34879
34880
34881
34882
34883
34884
34885
34886
34887
34888
34889
34890
34891
34892
34893
34894
34895
34896
34897
34898
34899
34900
34901
34902
34903
34904
34905
34906
34907
34908
34909
34910
34911
34912
34913
34914
34915
34916
34917
34918
34919
34920
34921
34922
34923
34924
34925
34926
34927
34928
34929
34930
34931
34932
34933
34934
34935
34936
34937
34938
34939
34940
34941
34942
34943
34944
34945
34946
34947
34948
34949
34950
34951
34952
34953
34954
34955
34956
34957
34958
34959
34960
34961
34962
34963
34964
34965
34966
34967
34968
34969
34970
34971
34972
34973
34974
34975
34976
34977
34978
34979
34980
34981
34982
34983
34984
34985
34986
34987
34988
34989
34990
34991
34992
34993
34994
34995
34996
34997
34998
34999
35000
35001
35002
35003
35004
35005
35006
35007
35008
35009
35010
35011
35012
35013
35014
35015
35016
35017
35018
35019
35020
35021
35022
35023
35024
35025
35026
35027
35028
35029
35030
35031
35032
35033
35034
35035
35036
35037
35038
35039
35040
35041
35042
35043
35044
35045
35046
35047
35048
35049
35050
35051
35052
35053
35054
35055
35056
35057
35058
35059
35060
35061
35062
35063
35064
35065
35066
35067
35068
35069
35070
35071
35072
35073
35074
35075
35076
35077
35078
35079
35080
35081
35082
35083
35084
35085
35086
35087
35088
35089
35090
35091
35092
35093
35094
35095
35096
35097
35098
35099
35100
35101
35102
35103
35104
35105
35106
35107
35108
35109
35110
35111
35112
35113
35114
35115
35116
35117
35118
35119
35120
35121
35122
35123
35124
35125
35126
35127
35128
35129
35130
35131
35132
35133
35134
35135
35136
35137
35138
35139
35140
35141
35142
35143
35144
35145
35146
35147
35148
35149
35150
35151
35152
35153
35154
35155
35156
35157
35158
35159
35160
35161
35162
35163
35164
35165
35166
35167
35168
35169
35170
35171
35172
35173
35174
35175
35176
35177
35178
35179
35180
35181
35182
35183
35184
35185
35186
35187
35188
35189
35190
35191
35192
35193
35194
35195
35196
35197
35198
35199
35200
35201
35202
35203
35204
35205
35206
35207
35208
35209
35210
35211
35212
35213
35214
35215
35216
35217
35218
35219
35220
35221
35222
35223
35224
35225
35226
35227
35228
35229
35230
35231
35232
35233
35234
35235
35236
35237
35238
35239
35240
35241
35242
35243
35244
35245
35246
35247
35248
35249
35250
35251
35252
35253
35254
35255
35256
35257
35258
35259
35260
35261
35262
35263
35264
35265
35266
35267
35268
35269
35270
35271
35272
35273
35274
35275
35276
35277
35278
35279
35280
35281
35282
35283
35284
35285
35286
35287
35288
35289
35290
35291
35292
35293
35294
35295
35296
35297
35298
35299
35300
35301
35302
35303
35304
35305
35306
35307
35308
35309
35310
35311
35312
35313
35314
35315
35316
35317
35318
35319
35320
35321
35322
35323
35324
35325
35326
35327
35328
35329
35330
35331
35332
35333
35334
35335
35336
35337
35338
35339
35340
35341
35342
35343
35344
35345
35346
35347
35348
35349
35350
35351
35352
35353
35354
35355
35356
35357
35358
35359
35360
35361
35362
35363
35364
35365
35366
35367
35368
35369
35370
35371
35372
35373
35374
35375
35376
35377
35378
35379
35380
35381
35382
35383
35384
35385
35386
35387
35388
35389
35390
35391
35392
35393
35394
35395
35396
35397
35398
35399
35400
35401
35402
35403
35404
35405
35406
35407
35408
35409
35410
35411
35412
35413
35414
35415
35416
35417
35418
35419
35420
35421
35422
35423
35424
35425
35426
35427
35428
35429
35430
35431
35432
35433
35434
35435
35436
35437
35438
35439
35440
35441
35442
35443
35444
35445
35446
35447
35448
35449
35450
35451
35452
35453
35454
35455
35456
35457
35458
35459
35460
35461
35462
35463
35464
35465
35466
35467
35468
35469
35470
35471
35472
35473
35474
35475
35476
35477
35478
35479
35480
35481
35482
35483
35484
35485
35486
35487
35488
35489
35490
35491
35492
35493
35494
35495
35496
35497
35498
35499
35500
35501
35502
35503
35504
35505
35506
35507
35508
35509
35510
35511
35512
35513
35514
35515
35516
35517
35518
35519
35520
35521
35522
35523
35524
35525
35526
35527
35528
35529
35530
35531
35532
35533
35534
35535
35536
35537
35538
35539
35540
35541
35542
35543
35544
35545
35546
35547
35548
35549
35550
35551
35552
35553
35554
35555
35556
35557
35558
35559
35560
35561
35562
35563
35564
35565
35566
35567
35568
35569
35570
35571
35572
35573
35574
35575
35576
35577
35578
35579
35580
35581
35582
35583
35584
35585
35586
35587
35588
35589
35590
35591
35592
35593
35594
35595
35596
35597
35598
35599
35600
35601
35602
35603
35604
35605
35606
35607
35608
35609
35610
35611
35612
35613
35614
35615
35616
35617
35618
35619
35620
35621
35622
35623
35624
35625
35626
35627
35628
35629
35630
35631
35632
35633
35634
35635
35636
35637
35638
35639
35640
35641
35642
35643
35644
35645
35646
35647
35648
35649
35650
35651
35652
35653
35654
35655
35656
35657
35658
35659
35660
35661
35662
35663
35664
35665
35666
35667
35668
35669
35670
35671
35672
35673
35674
35675
35676
35677
35678
35679
35680
35681
35682
35683
35684
35685
35686
35687
35688
35689
35690
35691
35692
35693
35694
35695
35696
35697
35698
35699
35700
35701
35702
35703
35704
35705
35706
35707
35708
35709
35710
35711
35712
35713
35714
35715
35716
35717
35718
35719
35720
35721
35722
35723
35724
35725
35726
35727
35728
35729
35730
35731
35732
35733
35734
35735
35736
35737
35738
35739
35740
35741
35742
35743
35744
35745
35746
35747
35748
35749
35750
35751
35752
35753
35754
35755
35756
35757
35758
35759
35760
35761
35762
35763
35764
35765
35766
35767
35768
35769
35770
35771
35772
35773
35774
35775
35776
35777
35778
35779
35780
35781
35782
35783
35784
35785
35786
35787
35788
35789
35790
35791
35792
35793
35794
35795
35796
35797
35798
35799
35800
35801
35802
35803
35804
35805
35806
35807
35808
35809
35810
35811
35812
35813
35814
35815
35816
35817
35818
35819
35820
35821
35822
35823
35824
35825
35826
35827
35828
35829
35830
35831
35832
35833
35834
35835
35836
35837
35838
35839
35840
35841
35842
35843
35844
35845
35846
35847
35848
35849
35850
35851
35852
35853
35854
35855
35856
35857
35858
35859
35860
35861
35862
35863
35864
35865
35866
35867
35868
35869
35870
35871
35872
35873
35874
35875
35876
35877
35878
35879
35880
35881
35882
35883
35884
35885
35886
35887
35888
35889
35890
35891
35892
35893
35894
35895
35896
35897
35898
35899
35900
35901
35902
35903
35904
35905
35906
35907
35908
35909
35910
35911
35912
35913
35914
35915
35916
35917
35918
35919
35920
35921
35922
35923
35924
35925
35926
35927
35928
35929
35930
35931
35932
35933
35934
35935
35936
35937
35938
35939
35940
35941
35942
35943
35944
35945
35946
35947
35948
35949
35950
35951
35952
35953
35954
35955
35956
35957
35958
35959
35960
35961
35962
35963
35964
35965
35966
35967
35968
35969
35970
35971
35972
35973
35974
35975
35976
35977
35978
35979
35980
35981
35982
35983
35984
35985
35986
35987
35988
35989
35990
35991
35992
35993
35994
35995
35996
35997
35998
35999
36000
36001
36002
36003
36004
36005
36006
36007
36008
36009
36010
36011
36012
36013
36014
36015
36016
36017
36018
36019
36020
36021
36022
36023
36024
36025
36026
36027
36028
36029
36030
36031
36032
36033
36034
36035
36036
36037
36038
36039
36040
36041
36042
36043
36044
36045
36046
36047
36048
36049
36050
36051
36052
36053
36054
36055
36056
36057
36058
36059
36060
36061
36062
36063
36064
36065
36066
36067
36068
36069
36070
36071
36072
36073
36074
36075
36076
36077
36078
36079
36080
36081
36082
36083
36084
36085
36086
36087
36088
36089
36090
36091
36092
36093
36094
36095
36096
36097
36098
36099
36100
36101
36102
36103
36104
36105
36106
36107
36108
36109
36110
36111
36112
36113
36114
36115
36116
36117
36118
36119
36120
36121
36122
36123
36124
36125
36126
36127
36128
36129
36130
36131
36132
36133
36134
36135
36136
36137
36138
36139
36140
36141
36142
36143
36144
36145
36146
36147
36148
36149
36150
36151
36152
36153
36154
36155
36156
36157
36158
36159
36160
36161
36162
36163
36164
36165
36166
36167
36168
36169
36170
36171
36172
36173
36174
36175
36176
36177
36178
36179
36180
36181
36182
36183
36184
36185
36186
36187
36188
36189
36190
36191
36192
36193
36194
36195
36196
36197
36198
36199
36200
36201
36202
36203
36204
36205
36206
36207
36208
36209
36210
36211
36212
36213
36214
36215
36216
36217
36218
36219
36220
36221
36222
36223
36224
36225
36226
36227
36228
36229
36230
36231
36232
36233
36234
36235
36236
36237
36238
36239
36240
36241
36242
36243
36244
36245
36246
36247
36248
36249
36250
36251
36252
36253
36254
36255
36256
36257
36258
36259
36260
36261
36262
36263
36264
36265
36266
36267
36268
36269
36270
36271
36272
36273
36274
36275
36276
36277
36278
36279
36280
36281
36282
36283
36284
36285
36286
36287
36288
36289
36290
36291
36292
36293
36294
36295
36296
36297
36298
36299
36300
36301
36302
36303
36304
36305
36306
36307
36308
36309
36310
36311
36312
36313
36314
36315
36316
36317
36318
36319
36320
36321
36322
36323
36324
36325
36326
36327
36328
36329
36330
36331
36332
36333
36334
36335
36336
36337
36338
36339
36340
36341
36342
36343
36344
36345
36346
36347
36348
36349
36350
36351
36352
36353
36354
36355
36356
36357
36358
36359
36360
36361
36362
36363
36364
36365
36366
36367
36368
36369
36370
36371
36372
36373
36374
36375
36376
36377
36378
36379
36380
36381
36382
36383
36384
36385
36386
36387
36388
36389
36390
36391
36392
36393
36394
36395
36396
36397
36398
36399
36400
36401
36402
36403
36404
36405
36406
36407
36408
36409
36410
36411
36412
36413
36414
36415
36416
36417
36418
36419
36420
36421
36422
36423
36424
36425
36426
36427
36428
36429
36430
36431
36432
36433
36434
36435
36436
36437
36438
36439
36440
36441
36442
36443
36444
36445
36446
36447
36448
36449
36450
36451
36452
36453
36454
36455
36456
36457
36458
36459
36460
36461
36462
36463
36464
36465
36466
36467
36468
36469
36470
36471
36472
36473
36474
36475
36476
36477
36478
36479
36480
36481
36482
36483
36484
36485
36486
36487
36488
36489
36490
36491
36492
36493
36494
36495
36496
36497
36498
36499
36500
36501
36502
36503
36504
36505
36506
36507
36508
36509
36510
36511
36512
36513
36514
36515
36516
36517
36518
36519
36520
36521
36522
36523
36524
36525
36526
36527
36528
36529
36530
36531
36532
36533
36534
36535
36536
36537
36538
36539
36540
36541
36542
36543
36544
36545
36546
36547
36548
36549
36550
36551
36552
36553
36554
36555
36556
36557
36558
36559
36560
36561
36562
36563
36564
36565
36566
36567
36568
36569
36570
36571
36572
36573
36574
36575
36576
36577
36578
36579
36580
36581
36582
36583
36584
36585
36586
36587
36588
36589
36590
36591
36592
36593
36594
36595
36596
36597
36598
36599
36600
36601
36602
36603
36604
36605
36606
36607
36608
36609
36610
36611
36612
36613
36614
36615
36616
36617
36618
36619
36620
36621
36622
36623
36624
36625
36626
36627
36628
36629
36630
36631
36632
36633
36634
36635
36636
36637
36638
36639
36640
36641
36642
36643
36644
36645
36646
36647
36648
36649
36650
36651
36652
36653
36654
36655
36656
36657
36658
36659
36660
36661
36662
36663
36664
36665
36666
36667
36668
36669
36670
36671
36672
36673
36674
36675
36676
36677
36678
36679
36680
36681
36682
36683
36684
36685
36686
36687
36688
36689
36690
36691
36692
36693
36694
36695
36696
36697
36698
36699
36700
36701
36702
36703
36704
36705
36706
36707
36708
36709
36710
36711
36712
36713
36714
36715
36716
36717
36718
36719
36720
36721
36722
36723
36724
36725
36726
36727
36728
36729
36730
36731
36732
36733
36734
36735
36736
36737
36738
36739
36740
36741
36742
36743
36744
36745
36746
36747
36748
36749
36750
36751
36752
36753
36754
36755
36756
36757
36758
36759
36760
36761
36762
36763
36764
36765
36766
36767
36768
36769
36770
36771
36772
36773
36774
36775
36776
36777
36778
36779
36780
36781
36782
36783
36784
36785
36786
36787
36788
36789
36790
36791
36792
36793
36794
36795
36796
36797
36798
36799
36800
36801
36802
36803
36804
36805
36806
36807
36808
36809
36810
36811
36812
36813
36814
36815
36816
36817
36818
36819
36820
36821
36822
36823
36824
36825
36826
36827
36828
36829
36830
36831
36832
36833
36834
36835
36836
36837
36838
36839
36840
36841
36842
36843
36844
36845
36846
36847
36848
36849
36850
36851
36852
36853
36854
36855
36856
36857
36858
36859
36860
36861
36862
36863
36864
36865
36866
36867
36868
36869
36870
36871
36872
36873
36874
36875
36876
36877
36878
36879
36880
36881
36882
36883
36884
36885
36886
36887
36888
36889
36890
36891
36892
36893
36894
36895
36896
36897
36898
36899
36900
36901
36902
36903
36904
36905
36906
36907
36908
36909
36910
36911
36912
36913
36914
36915
36916
36917
36918
36919
36920
36921
36922
36923
36924
36925
36926
36927
36928
36929
36930
36931
36932
36933
36934
36935
36936
36937
36938
36939
36940
36941
36942
36943
36944
36945
36946
36947
36948
36949
36950
36951
36952
36953
36954
36955
36956
36957
36958
36959
36960
36961
36962
36963
36964
36965
36966
36967
36968
36969
36970
36971
36972
36973
36974
36975
36976
36977
36978
36979
36980
36981
36982
36983
36984
36985
36986
36987
36988
36989
36990
36991
36992
36993
36994
36995
36996
36997
36998
36999
37000
37001
37002
37003
37004
37005
37006
37007
37008
37009
37010
37011
37012
37013
37014
37015
37016
37017
37018
37019
37020
37021
37022
37023
37024
37025
37026
37027
37028
37029
37030
37031
37032
37033
37034
37035
37036
37037
37038
37039
37040
37041
37042
37043
37044
37045
37046
37047
37048
37049
37050
37051
37052
37053
37054
37055
37056
37057
37058
37059
37060
37061
37062
37063
37064
37065
37066
37067
37068
37069
37070
37071
37072
37073
37074
37075
37076
37077
37078
37079
37080
37081
37082
37083
37084
37085
37086
37087
37088
37089
37090
37091
37092
37093
37094
37095
37096
37097
37098
37099
37100
37101
37102
37103
37104
37105
37106
37107
37108
37109
37110
37111
37112
37113
37114
37115
37116
37117
37118
37119
37120
37121
37122
37123
37124
37125
37126
37127
37128
37129
37130
37131
37132
37133
37134
37135
37136
37137
37138
37139
37140
37141
37142
37143
37144
37145
37146
37147
37148
37149
37150
37151
37152
37153
37154
37155
37156
37157
37158
37159
37160
37161
37162
37163
37164
37165
37166
37167
37168
37169
37170
37171
37172
37173
37174
37175
37176
37177
37178
37179
37180
37181
37182
37183
37184
37185
37186
37187
37188
37189
37190
37191
37192
37193
37194
37195
37196
37197
37198
37199
37200
37201
37202
37203
37204
37205
37206
37207
37208
37209
37210
37211
37212
37213
37214
37215
37216
37217
37218
37219
37220
37221
37222
37223
37224
37225
37226
37227
37228
37229
37230
37231
37232
37233
37234
37235
37236
37237
37238
37239
37240
37241
37242
37243
37244
37245
37246
37247
37248
37249
37250
37251
37252
37253
37254
37255
37256
37257
37258
37259
37260
37261
37262
37263
37264
37265
37266
37267
37268
37269
37270
37271
37272
37273
37274
37275
37276
37277
37278
37279
37280
37281
37282
37283
37284
37285
37286
37287
37288
37289
37290
37291
37292
37293
37294
37295
37296
37297
37298
37299
37300
37301
37302
37303
37304
37305
37306
37307
37308
37309
37310
37311
37312
37313
37314
37315
37316
37317
37318
37319
37320
37321
37322
37323
37324
37325
37326
37327
37328
37329
37330
37331
37332
37333
37334
37335
37336
37337
37338
37339
37340
37341
37342
37343
37344
37345
37346
37347
37348
37349
37350
37351
37352
37353
37354
37355
37356
37357
37358
37359
37360
37361
37362
37363
37364
37365
37366
37367
37368
37369
37370
37371
37372
37373
37374
37375
37376
37377
37378
37379
37380
37381
37382
37383
37384
37385
37386
37387
37388
37389
37390
37391
37392
37393
37394
37395
37396
37397
37398
37399
37400
37401
37402
37403
37404
37405
37406
37407
37408
37409
37410
37411
37412
37413
37414
37415
37416
37417
37418
37419
37420
37421
37422
37423
37424
37425
37426
37427
37428
37429
37430
37431
37432
37433
37434
37435
37436
37437
37438
37439
37440
37441
37442
37443
37444
37445
37446
37447
37448
37449
37450
37451
37452
37453
37454
37455
37456
37457
37458
37459
37460
37461
37462
37463
37464
37465
37466
37467
37468
37469
37470
37471
37472
37473
37474
37475
37476
37477
37478
37479
37480
37481
37482
37483
37484
37485
37486
37487
37488
37489
37490
37491
37492
37493
37494
37495
37496
37497
37498
37499
37500
37501
37502
37503
37504
37505
37506
37507
37508
37509
37510
37511
37512
37513
37514
37515
37516
37517
37518
37519
37520
37521
37522
37523
37524
37525
37526
37527
37528
37529
37530
37531
37532
37533
37534
37535
37536
37537
37538
37539
37540
37541
37542
37543
37544
37545
37546
37547
37548
37549
37550
37551
37552
37553
37554
37555
37556
37557
37558
37559
37560
37561
37562
37563
37564
37565
37566
37567
37568
37569
37570
37571
37572
37573
37574
37575
37576
37577
37578
37579
37580
37581
37582
37583
37584
37585
37586
37587
37588
37589
37590
37591
37592
37593
37594
37595
37596
37597
37598
37599
37600
37601
37602
37603
37604
37605
37606
37607
37608
37609
37610
37611
37612
37613
37614
37615
37616
37617
37618
37619
37620
37621
37622
37623
37624
37625
37626
37627
37628
37629
37630
37631
37632
37633
37634
37635
37636
37637
37638
37639
37640
37641
37642
37643
37644
37645
37646
37647
37648
37649
37650
37651
37652
37653
37654
37655
37656
37657
37658
37659
37660
37661
37662
37663
37664
37665
37666
37667
37668
37669
37670
37671
37672
37673
37674
37675
37676
37677
37678
37679
37680
37681
37682
37683
37684
37685
37686
37687
37688
37689
37690
37691
37692
37693
37694
37695
37696
37697
37698
37699
37700
37701
37702
37703
37704
37705
37706
37707
37708
37709
37710
37711
37712
37713
37714
37715
37716
37717
37718
37719
37720
37721
37722
37723
37724
37725
37726
37727
37728
37729
37730
37731
37732
37733
37734
37735
37736
37737
37738
37739
37740
37741
37742
37743
37744
37745
37746
37747
37748
37749
37750
37751
37752
37753
37754
37755
37756
37757
37758
37759
37760
37761
37762
37763
37764
37765
37766
37767
37768
37769
37770
37771
37772
37773
37774
37775
37776
37777
37778
37779
37780
37781
37782
37783
37784
37785
37786
37787
37788
37789
37790
37791
37792
37793
37794
37795
37796
37797
37798
37799
37800
37801
37802
37803
37804
37805
37806
37807
37808
37809
37810
37811
37812
37813
37814
37815
37816
37817
37818
37819
37820
37821
37822
37823
37824
37825
37826
37827
37828
37829
37830
37831
37832
37833
37834
37835
37836
37837
37838
37839
37840
37841
37842
37843
37844
37845
37846
37847
37848
37849
37850
37851
37852
37853
37854
37855
37856
37857
37858
37859
37860
37861
37862
37863
37864
37865
37866
37867
37868
37869
37870
37871
37872
37873
37874
37875
37876
37877
37878
37879
37880
37881
37882
37883
37884
37885
37886
37887
37888
37889
37890
37891
37892
37893
37894
37895
37896
37897
37898
37899
37900
37901
37902
37903
37904
37905
37906
37907
37908
37909
37910
37911
37912
37913
37914
37915
37916
37917
37918
37919
37920
37921
37922
37923
37924
37925
37926
37927
37928
37929
37930
37931
37932
37933
37934
37935
37936
37937
37938
37939
37940
37941
37942
37943
37944
37945
37946
37947
37948
37949
37950
37951
37952
37953
37954
37955
37956
37957
37958
37959
37960
37961
37962
37963
37964
37965
37966
37967
37968
37969
37970
37971
37972
37973
37974
37975
37976
37977
37978
37979
37980
37981
37982
37983
37984
37985
37986
37987
37988
37989
37990
37991
37992
37993
37994
37995
37996
37997
37998
37999
38000
38001
38002
38003
38004
38005
38006
38007
38008
38009
38010
38011
38012
38013
38014
38015
38016
38017
38018
38019
38020
38021
38022
38023
38024
38025
38026
38027
38028
38029
38030
38031
38032
38033
38034
38035
38036
38037
38038
38039
38040
38041
38042
38043
38044
38045
38046
38047
38048
38049
38050
38051
38052
38053
38054
38055
38056
38057
38058
38059
38060
38061
38062
38063
38064
38065
38066
38067
38068
38069
38070
38071
38072
38073
38074
38075
38076
38077
38078
38079
38080
38081
38082
38083
38084
38085
38086
38087
38088
38089
38090
38091
38092
38093
38094
38095
38096
38097
38098
38099
38100
38101
38102
38103
38104
38105
38106
38107
38108
38109
38110
38111
38112
38113
38114
38115
38116
38117
38118
38119
38120
38121
38122
38123
38124
38125
38126
38127
38128
38129
38130
38131
38132
38133
38134
38135
38136
38137
38138
38139
38140
38141
38142
38143
38144
38145
38146
38147
38148
38149
38150
38151
38152
38153
38154
38155
38156
38157
38158
38159
38160
38161
38162
38163
38164
38165
38166
38167
38168
38169
38170
38171
38172
38173
38174
38175
38176
38177
38178
38179
38180
38181
38182
38183
38184
38185
38186
38187
38188
38189
38190
38191
38192
38193
38194
38195
38196
38197
38198
38199
38200
38201
38202
38203
38204
38205
38206
38207
38208
38209
38210
38211
38212
38213
38214
38215
38216
38217
38218
38219
38220
38221
38222
38223
38224
38225
38226
38227
38228
38229
38230
38231
38232
38233
38234
38235
38236
38237
38238
38239
38240
38241
38242
38243
38244
38245
38246
38247
38248
38249
38250
38251
38252
38253
38254
38255
38256
38257
38258
38259
38260
38261
38262
38263
38264
38265
38266
38267
38268
38269
38270
38271
38272
38273
38274
38275
38276
38277
38278
38279
38280
38281
38282
38283
38284
38285
38286
38287
38288
38289
38290
38291
38292
38293
38294
38295
38296
38297
38298
38299
38300
38301
38302
38303
38304
38305
38306
38307
38308
38309
38310
38311
38312
38313
38314
38315
38316
38317
38318
38319
38320
38321
38322
38323
38324
38325
38326
38327
38328
38329
38330
38331
38332
38333
38334
38335
38336
38337
38338
38339
38340
38341
38342
38343
38344
38345
38346
38347
38348
38349
38350
38351
38352
38353
38354
38355
38356
38357
38358
38359
38360
38361
38362
38363
38364
38365
38366
38367
38368
38369
38370
38371
38372
38373
38374
38375
38376
38377
38378
38379
38380
38381
38382
38383
38384
38385
38386
38387
38388
38389
38390
38391
38392
38393
38394
38395
38396
38397
38398
38399
38400
38401
38402
38403
38404
38405
38406
38407
38408
38409
38410
38411
38412
38413
38414
38415
38416
38417
38418
38419
38420
38421
38422
38423
38424
38425
38426
38427
38428
38429
38430
38431
38432
38433
38434
38435
38436
38437
38438
38439
38440
38441
38442
38443
38444
38445
38446
38447
38448
38449
38450
38451
38452
38453
38454
38455
38456
38457
38458
38459
38460
38461
38462
38463
38464
38465
38466
38467
38468
38469
38470
38471
38472
38473
38474
38475
38476
38477
38478
38479
38480
38481
38482
38483
38484
38485
38486
38487
38488
38489
38490
38491
38492
38493
38494
38495
38496
38497
38498
38499
38500
38501
38502
38503
38504
38505
38506
38507
38508
38509
38510
38511
38512
38513
38514
38515
38516
38517
38518
38519
38520
38521
38522
38523
38524
38525
38526
38527
38528
38529
38530
38531
38532
38533
38534
38535
38536
38537
38538
38539
38540
38541
38542
38543
38544
38545
38546
38547
38548
38549
38550
38551
38552
38553
38554
38555
38556
38557
38558
38559
38560
38561
38562
38563
38564
38565
38566
38567
38568
38569
38570
38571
38572
38573
38574
38575
38576
38577
38578
38579
38580
38581
38582
38583
38584
38585
38586
38587
38588
38589
38590
38591
38592
38593
38594
38595
38596
38597
38598
38599
38600
38601
38602
38603
38604
38605
38606
38607
38608
38609
38610
38611
38612
38613
38614
38615
38616
38617
38618
38619
38620
38621
38622
38623
38624
38625
38626
38627
38628
38629
38630
38631
38632
38633
38634
38635
38636
38637
38638
38639
38640
38641
38642
38643
38644
38645
38646
38647
38648
38649
38650
38651
38652
38653
38654
38655
38656
38657
38658
38659
38660
38661
38662
38663
38664
38665
38666
38667
38668
38669
38670
38671
38672
38673
38674
38675
38676
38677
38678
38679
38680
38681
38682
38683
38684
38685
38686
38687
38688
38689
38690
38691
38692
38693
38694
38695
38696
38697
38698
38699
38700
38701
38702
38703
38704
38705
38706
38707
38708
38709
38710
38711
38712
38713
38714
38715
38716
38717
38718
38719
38720
38721
38722
38723
38724
38725
38726
38727
38728
38729
38730
38731
38732
38733
38734
38735
38736
38737
38738
38739
38740
38741
38742
38743
38744
38745
38746
38747
38748
38749
38750
38751
38752
38753
38754
38755
38756
38757
38758
38759
38760
38761
38762
38763
38764
38765
38766
38767
38768
38769
38770
38771
38772
38773
38774
38775
38776
38777
38778
38779
38780
38781
38782
38783
38784
38785
38786
38787
38788
38789
38790
38791
38792
38793
38794
38795
38796
38797
38798
38799
38800
38801
38802
38803
38804
38805
38806
38807
38808
38809
38810
38811
38812
38813
38814
38815
38816
38817
38818
38819
38820
38821
38822
38823
38824
38825
38826
38827
38828
38829
38830
38831
38832
38833
38834
38835
38836
38837
38838
38839
38840
38841
38842
38843
38844
38845
38846
38847
38848
38849
38850
38851
38852
38853
38854
38855
38856
38857
38858
38859
38860
38861
38862
38863
38864
38865
38866
38867
38868
38869
38870
38871
38872
38873
38874
38875
38876
38877
38878
38879
38880
38881
38882
38883
38884
38885
38886
38887
38888
38889
38890
38891
38892
38893
38894
38895
38896
38897
38898
38899
38900
38901
38902
38903
38904
38905
38906
38907
38908
38909
38910
38911
38912
38913
38914
38915
38916
38917
38918
38919
38920
38921
38922
38923
38924
38925
38926
38927
38928
38929
38930
38931
38932
38933
38934
38935
38936
38937
38938
38939
38940
38941
38942
38943
38944
38945
38946
38947
38948
38949
38950
38951
38952
38953
38954
38955
38956
38957
38958
38959
38960
38961
38962
38963
38964
38965
38966
38967
38968
38969
38970
38971
38972
38973
38974
38975
38976
38977
38978
38979
38980
38981
38982
38983
38984
38985
38986
38987
38988
38989
38990
38991
38992
38993
38994
38995
38996
38997
38998
38999
39000
39001
39002
39003
39004
39005
39006
39007
39008
39009
39010
39011
39012
39013
39014
39015
39016
39017
39018
39019
39020
39021
39022
39023
39024
39025
39026
39027
39028
39029
39030
39031
39032
39033
39034
39035
39036
39037
39038
39039
39040
39041
39042
39043
39044
39045
39046
39047
39048
39049
39050
39051
39052
39053
39054
39055
39056
39057
39058
39059
39060
39061
39062
39063
39064
39065
39066
39067
39068
39069
39070
39071
39072
39073
39074
39075
39076
39077
39078
39079
39080
39081
39082
39083
39084
39085
39086
39087
39088
39089
39090
39091
39092
39093
39094
39095
39096
39097
39098
39099
39100
39101
39102
39103
39104
39105
39106
39107
39108
39109
39110
39111
39112
39113
39114
39115
39116
39117
39118
39119
39120
39121
39122
39123
39124
39125
39126
39127
39128
39129
39130
39131
39132
39133
39134
39135
39136
39137
39138
39139
39140
39141
39142
39143
39144
39145
39146
39147
39148
39149
39150
39151
39152
39153
39154
39155
39156
39157
39158
39159
39160
39161
39162
39163
39164
39165
39166
39167
39168
39169
39170
39171
39172
39173
39174
39175
39176
39177
39178
39179
39180
39181
39182
39183
39184
39185
39186
39187
39188
39189
39190
39191
39192
39193
39194
39195
39196
39197
39198
39199
39200
39201
39202
39203
39204
39205
39206
39207
39208
39209
39210
39211
39212
39213
39214
39215
39216
39217
39218
39219
39220
39221
39222
39223
39224
39225
39226
39227
39228
39229
39230
39231
39232
39233
39234
39235
39236
39237
39238
39239
39240
39241
39242
39243
39244
39245
39246
39247
39248
39249
39250
39251
39252
39253
39254
39255
39256
39257
39258
39259
39260
39261
39262
39263
39264
39265
39266
39267
39268
39269
39270
39271
39272
39273
39274
39275
39276
39277
39278
39279
39280
39281
39282
39283
39284
39285
39286
39287
39288
39289
39290
39291
39292
39293
39294
39295
39296
39297
39298
39299
39300
39301
39302
39303
39304
39305
39306
39307
39308
39309
39310
39311
39312
39313
39314
39315
39316
39317
39318
39319
39320
39321
39322
39323
39324
39325
39326
39327
39328
39329
39330
39331
39332
39333
39334
39335
39336
39337
39338
39339
39340
39341
39342
39343
39344
39345
39346
39347
39348
39349
39350
39351
39352
39353
39354
39355
39356
39357
39358
39359
39360
39361
39362
39363
39364
39365
39366
39367
39368
39369
39370
39371
39372
39373
39374
39375
39376
39377
39378
39379
39380
39381
39382
39383
39384
39385
39386
39387
39388
39389
39390
39391
39392
39393
39394
39395
39396
39397
39398
39399
39400
39401
39402
39403
39404
39405
39406
39407
39408
39409
39410
39411
39412
39413
39414
39415
39416
39417
39418
39419
39420
39421
39422
39423
39424
39425
39426
39427
39428
39429
39430
39431
39432
39433
39434
39435
39436
39437
39438
39439
39440
39441
39442
39443
39444
39445
39446
39447
39448
39449
39450
39451
39452
39453
39454
39455
39456
39457
39458
39459
39460
39461
39462
39463
39464
39465
39466
39467
39468
39469
39470
39471
39472
39473
39474
39475
39476
39477
39478
39479
39480
39481
39482
39483
39484
39485
39486
39487
39488
39489
39490
39491
39492
39493
39494
39495
39496
39497
39498
39499
39500
39501
39502
39503
39504
39505
39506
39507
39508
39509
39510
39511
39512
39513
39514
39515
39516
39517
39518
39519
39520
39521
39522
39523
39524
39525
39526
39527
39528
39529
39530
39531
39532
39533
39534
39535
39536
39537
39538
39539
39540
39541
39542
39543
39544
39545
39546
39547
39548
39549
39550
39551
39552
39553
39554
39555
39556
39557
39558
39559
39560
39561
39562
39563
39564
39565
39566
39567
39568
39569
39570
39571
39572
39573
39574
39575
39576
39577
39578
39579
39580
39581
39582
39583
39584
39585
39586
39587
39588
39589
39590
39591
39592
39593
39594
39595
39596
39597
39598
39599
39600
39601
39602
39603
39604
39605
39606
39607
39608
39609
39610
39611
39612
39613
39614
39615
39616
39617
39618
39619
39620
39621
39622
39623
39624
39625
39626
39627
39628
39629
39630
39631
39632
39633
39634
39635
39636
39637
39638
39639
39640
39641
39642
39643
39644
39645
39646
39647
39648
39649
39650
39651
39652
39653
39654
39655
39656
39657
39658
39659
39660
39661
39662
39663
39664
39665
39666
39667
39668
39669
39670
39671
39672
39673
39674
39675
39676
39677
39678
39679
39680
39681
39682
39683
39684
39685
39686
39687
39688
39689
39690
39691
39692
39693
39694
39695
39696
39697
39698
39699
39700
39701
39702
39703
39704
39705
39706
39707
39708
39709
39710
39711
39712
39713
39714
39715
39716
39717
39718
39719
39720
39721
39722
39723
39724
39725
39726
39727
39728
39729
39730
39731
39732
39733
39734
39735
39736
39737
39738
39739
39740
39741
39742
39743
39744
39745
39746
39747
39748
39749
39750
39751
39752
39753
39754
39755
39756
39757
39758
39759
39760
39761
39762
39763
39764
39765
39766
39767
39768
39769
39770
39771
39772
39773
39774
39775
39776
39777
39778
39779
39780
39781
39782
39783
39784
39785
39786
39787
39788
39789
39790
39791
39792
39793
39794
39795
39796
39797
39798
39799
39800
39801
39802
39803
39804
39805
39806
39807
39808
39809
39810
39811
39812
39813
39814
39815
39816
39817
39818
39819
39820
39821
39822
39823
39824
39825
39826
39827
39828
39829
39830
39831
39832
39833
39834
39835
39836
39837
39838
39839
39840
39841
39842
39843
39844
39845
39846
39847
39848
39849
39850
39851
39852
39853
39854
39855
39856
39857
39858
39859
39860
39861
39862
39863
|
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License, Version 1.0 only
# (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) 1989,1997,1999 by Sun Microsystems, Inc.
# All rights reserved.
#
# Copyright 2012 Milan Jurik. All rights reserved.
# Copyright 2014 Nexenta Systems, Inc. All rights reserved.
#
# uts/common/gssd/Makefile
#
# include global definitions
include ../../../Makefile.master
INSTALLED_HDRS= gssapi.h gssapi_ext.h gssapi_krb5.h
PRIVATE_HDRS= gssd.x gssd_prot.h
HDRS= $(INSTALLED_HDRS) $(PRIVATE_HDRS)
# Hammerhead: These are pre-generated and checked into the repo.
# rpcgen + GNU cpp truncates %#define output from gssd.x.
# If you need to regenerate, use illumos native rpcgen on OI.
DERIVED_FILES= gssd_prot.h gssd_prot.c gssd_xdr.c
GSSDDIRS= $(ROOT)/usr/include/gssapi
GSSDHDRS= $(INSTALLED_HDRS:%=$(GSSDDIRS)/%)
CHECKHDRS= $(INSTALLED_HDRS:%.h=%.check)
# gssd_prot.h is rpcgen'ed and can never be made to pass
# cstyle so it is unchecked
UNCHECKED_HDRS= gss_prot.h
# install rules
$(GSSDDIRS)/%: %
$(INS.file)
$(GSSDDIRS)/%: mechs/krb5/include/%
$(INS.file)
# This is 3rd party code, so just skip hdrchk.
gssapi_krb5.check:
.KEEP_STATE:
.PARALLEL: $(CHECKHDRS)
install_h: all_h $(GSSDDIRS) $(GSSDHDRS)
all_h: $(DERIVED_FILES)
$(GSSDDIRS):
$(INS.dir)
# Hammerhead: Pre-generated files — do NOT regenerate with rpcgen.
# Original rules preserved as comments for reference:
# gssd_prot.h: $(RPCGEN) -CM -h gssd.x > $@
# gssd_prot.c: $(RPCGEN) -M -l gssd.x | sed ... > $@
# gssd_xdr.c: $(RPCGEN) -M -c gssd.x | sed ... > $@
check: $(CHECKHDRS)
clean:
@# Hammerhead: do NOT delete pre-generated DERIVED_FILES
clobber: clean
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright 1993 by OpenVision Technologies, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appears in all copies and
* that both that copyright notice and this permission notice appear in
* supporting documentation, and that the name of OpenVision not be used
* in advertising or publicity pertaining to distribution of the software
* without specific, written prior permission. OpenVision makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
* OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
#include <mechglueP.h>
/*
* See krb5/gssapi_krb5.c for a description of the algorithm for
* encoding an object identifier.
*/
/*
* The OID of user_name is(gss_nt_user_name, GSS_C_NT_USER_NAME):
* iso(1) member-body(2) US(840) mit(113554) infosys(1) gssapi(2)
* generic(1) user_name(1) = 1.2.840.113554.1.2.1.1
* machine_uid_name(gss_nt_machine_uid_name, GSS_C_NT_MACHINE_UID_NAME):
* iso(1) member-body(2) US(840) mit(113554) infosys(1) gssapi(2)
* generic(1) machine_uid_name(2) = 1.2.840.113554.1.2.1.2
* string_uid_name(gss_nt_string_uid_name,GSS_C_NT_STRING_UID_NAME):
* iso(1) member-body(2) US(840) mit(113554) infosys(1) gssapi(2)
* generic(1) string_uid_name(3) = 1.2.840.113554.1.2.1.3
* service_name(gss_nt_service_name):
* iso(1) member-body(2) US(840) mit(113554) infosys(1) gssapi(2)
* generic(1) service_name(4) = 1.2.840.113554.1.2.1.4
* hostbased_service_name(GSS_C_NT_HOSTBASED_SERVICE)
* iso(1) org(3) dod(6) 1(internet) 5(security) 6(nametypes)
* 2(gss-host-based-services) == 1.3.6.1.5.6.2
* anonymous_name(GSS_C_NT_ANONYMOUS)
* iso(1) org(3) dod(6) 1(internet) 5(security) 6(nametypes)
* 3(anonymous) = 1.3.6.1.5.6.3
* export_name(GSS_C_NT_EXPORT)
* iso(1) org(3) dod(6) 1(internet) 5(security) 6(nametypes)
* 4(export) = 1.3.6.1.5.6.4
*/
static const gss_OID_desc oids[] = {
/* GSS_C_NT_USER_NAME */
{10, "\052\206\110\206\367\022\001\002\001\001"},
/* GSS_C_NT_MACHINE_UID_NAME */
{10, "\052\206\110\206\367\022\001\002\001\002"},
/* GSS_C_NT_STRING_UID_NAME */
{10, "\052\206\110\206\367\022\001\002\001\003"},
/* gss_nt_service_name */
{10, "\052\206\110\206\367\022\001\002\001\004"},
/* GSS_C_NT_HOSTBASED_SERVICE */
{6, "\053\006\001\005\006\002"},
/* GSS_C_NT_ANONYMOUS */
{6, "\053\006\001\005\006\003"},
/* GSS_C_NT_EXPORT_NAME */
{6, "\053\006\001\005\006\004"},
/* GSS_C_INQ_SSPI_SESSION_KEY */
{11, "\x2a\x86\x48\x86\xf7\x12\x01\x02\x02\x05\x05"},
};
const gss_OID_desc * const gss_nt_user_name = oids+0;
const gss_OID_desc * const gss_nt_machine_uid_name = oids+1;
const gss_OID_desc * const gss_nt_string_uid_name = oids+2;
const gss_OID_desc * const gss_nt_service_name = oids+3;
/* XXXXX These are needed for Kerberos */
const gss_OID_desc * const gss_nt_service_name_v2 = oids+4;
const gss_OID_desc * const gss_nt_exported_name = oids+6;
/*
* These are added to reflect definitions in the
* gss c-bindings spec.
*/
/*
* The use of the following defines are preferred over the above defines.
* This is because the following are the only ones defined
* in GSS-API Specs.
*/
const gss_OID GSS_C_NT_USER_NAME = (gss_OID)oids+0;
const gss_OID GSS_C_NT_MACHINE_UID_NAME = (gss_OID)oids+1;
const gss_OID GSS_C_NT_STRING_UID_NAME = (gss_OID)oids+2;
const gss_OID GSS_C_NT_HOSTBASED_SERVICE = (gss_OID)oids+4;
const gss_OID GSS_C_NT_ANONYMOUS = (gss_OID)oids+5;
const gss_OID GSS_C_NT_EXPORT_NAME = (gss_OID)oids+6;
const gss_OID GSS_C_INQ_SSPI_SESSION_KEY = (gss_OID)oids+7;
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* glue routine for gss_display_name()
*/
#include <mechglueP.h>
#include <gssapi/kgssapi_defs.h>
OM_uint32
gss_display_name(OM_uint32 *minor_status,
const gss_name_t input_name,
gss_buffer_t output_name_buffer,
gss_OID *output_name_type)
{
gss_union_name_t union_name;
if (input_name == 0)
return (GSS_S_BAD_NAME);
union_name = (gss_union_name_t) input_name;
GSSLOG(8, "union_name value %s\n",
(char *)union_name->external_name->value);
/*
* copy the value of the external_name component of the union
* name into the output_name_buffer and point the output_name_type
* to the name_type component of union_name
*/
if (output_name_type != NULL)
*output_name_type = union_name->name_type;
if (output_name_buffer != NULL) {
output_name_buffer->length = union_name->external_name->length;
output_name_buffer->value =
(void *) MALLOC(output_name_buffer->length);
(void) memcpy(output_name_buffer->value,
union_name->external_name->value,
output_name_buffer->length);
}
if (minor_status)
*minor_status = 0;
return (GSS_S_COMPLETE);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* glue routine gss_import_name
*
*/
#include "mechglueP.h"
#include <sys/errno.h>
OM_uint32
gss_import_name(
OM_uint32 *minor_status,
const gss_buffer_t input_name_buffer,
const gss_OID input_name_type,
gss_name_t *output_name)
{
gss_union_name_t union_name;
OM_uint32 major_status = GSS_S_FAILURE;
if (minor_status)
*minor_status = 0;
/* if output_name is NULL, simply return */
if (output_name == NULL)
return (GSS_S_COMPLETE);
*output_name = 0;
if (input_name_buffer == GSS_C_NO_BUFFER || input_name_type == NULL)
return (GSS_S_BAD_NAME);
/*
* First create the union name struct that will hold the external
* name and the name type.
*/
union_name = (gss_union_name_t) MALLOC(sizeof (gss_union_name_desc));
if (!union_name) {
*minor_status = ENOMEM;
goto allocation_failure;
}
union_name->mech_type = 0;
union_name->mech_name = 0;
union_name->name_type = 0;
union_name->external_name = 0;
/*
* All we do here is record the external name and name_type.
* When the name is actually used, the underlying gss_import_name()
* is called for the appropriate mechanism.
* Since the name type may be a constant or comming from the
* rpc resoults, we must make a copy.
*/
union_name->external_name =
(gss_buffer_t) MALLOC(sizeof (gss_buffer_desc));
if (!union_name->external_name) {
*minor_status = ENOMEM;
goto allocation_failure;
}
union_name->external_name->length = input_name_buffer->length;
union_name->external_name->value =
(void *) MALLOC(input_name_buffer->length);
if (!union_name->external_name->value) {
*minor_status = ENOMEM;
goto allocation_failure;
}
(void) memcpy(union_name->external_name->value,
input_name_buffer->value, input_name_buffer->length);
/*
* making a copy of the name_type structure and elements
* we now delete it when calling gss_release_name
*/
union_name->name_type = (gss_OID) MALLOC(sizeof (gss_OID_desc));
if (!union_name->name_type) {
*minor_status = ENOMEM;
goto allocation_failure;
}
union_name->name_type->elements = (void *)
MALLOC(input_name_type->length);
if (!union_name->name_type->elements) {
*minor_status = ENOMEM;
goto allocation_failure;
}
(void) memcpy(union_name->name_type->elements,
input_name_type->elements, input_name_type->length);
union_name->name_type->length = input_name_type->length;
*output_name = (gss_name_t) union_name;
return (GSS_S_COMPLETE);
allocation_failure:
if (union_name) {
if (union_name->external_name) {
if (union_name->external_name->value)
FREE(union_name->external_name->value,
union_name->external_name->length);
FREE(union_name->external_name,
sizeof (gss_buffer_desc));
}
if (union_name->name_type) {
FREE(union_name->name_type, sizeof (gss_OID_desc));
}
FREE(union_name, sizeof (gss_union_name_desc));
}
return (major_status);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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) 1996,1997, by Sun Microsystems, Inc.
* All rights reserved.
*/
/*
* glue routine for gss_release_buffer
*/
#include "mechglueP.h"
OM_uint32
gss_release_buffer(OM_uint32 *minor_status, gss_buffer_t buffer)
{
if (minor_status)
*minor_status = 0;
/* if buffer is NULL, return */
if (buffer == GSS_C_NO_BUFFER)
return (GSS_S_COMPLETE);
if ((buffer->length) && (buffer->value)) {
FREE(buffer->value, buffer->length);
buffer->length = 0;
buffer->value = NULL;
}
return (GSS_S_COMPLETE);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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) 1996,1997, by Sun Microsystems, Inc.
* All rights reserved.
*/
/*
* glue routine for gss_release_name
*/
#include "mechglueP.h"
OM_uint32
gss_release_name(OM_uint32 *minor_status, gss_name_t *input_name)
{
gss_union_name_t union_name;
/* if input_name is NULL, return error */
if (input_name == 0)
return (GSS_S_BAD_NAME);
/*
* free up the space for the external_name, name_type
* and then free the union_name descriptor
*/
union_name = (gss_union_name_t) *input_name;
*input_name = 0;
*minor_status = 0;
if (union_name == NULL)
return (GSS_S_BAD_NAME);
FREE(union_name->external_name->value,
union_name->external_name->length);
FREE(union_name->external_name, sizeof (gss_buffer_desc));
/* free the name_type */
FREE(union_name->name_type->elements, union_name->name_type->length);
FREE(union_name->name_type, sizeof (gss_OID_desc));
FREE(union_name, sizeof (gss_union_name_desc));
return (GSS_S_COMPLETE);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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) 1996,1997, by Sun Microsystems, Inc.
* All rights reserved.
*/
/*
* glue routine for gss_release_oid_set
*/
#include "mechglueP.h"
OM_uint32
gss_release_oid_set(OM_uint32 *minor_status, gss_OID_set *set)
{
if (minor_status)
*minor_status = 0;
if (set == NULL)
return (GSS_S_COMPLETE);
if (*set == GSS_C_NULL_OID_SET)
return (GSS_S_COMPLETE);
FREE((*set)->elements, (*set)->count * sizeof (gss_OID_desc));
FREE(*set, sizeof (gss_OID_set_desc));
*set = GSS_C_NULL_OID_SET;
return (GSS_S_COMPLETE);
}
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright 1993 by OpenVision Technologies, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appears in all copies and
* that both that copyright notice and this permission notice appear in
* supporting documentation, and that the name of OpenVision not be used
* in advertising or publicity pertaining to distribution of the software
* without specific, written prior permission. OpenVision makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
* OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef _GSSAPI_H_
#define _GSSAPI_H_
#ifdef __cplusplus
extern "C" {
#endif
/*
* First, include sys/types.h to get size_t defined.
*/
#include <sys/types.h>
/*
* If the platform supports the xom.h header file, it should be
* included here.
*/
#ifdef HAVE_XOM_H
#include <xom.h>
#endif
/*
* Now define the three implementation-dependent types.
*/
struct gss_ctx_id;
struct gss_cred_id;
struct gss_name;
typedef struct gss_ctx_id *gss_ctx_id_t;
typedef struct gss_cred_id *gss_cred_id_t;
typedef struct gss_name *gss_name_t;
/*
* The following type must be defined as the smallest natural
* unsigned integer supported by the platform that has at least
* 32 bits of precision.
*/
typedef unsigned int gss_uint32;
typedef int gss_int32;
#ifdef OM_STRING
/*
* We have included the xom.h header file. Verify that OM_uint32
* is defined correctly.
*/
#if sizeof (gss_uint32) != sizeof (OM_uint32)
#error Incompatible definition of OM_uint32 from xom.h
#endif
typedef OM_object_identifier gss_OID_desc, *gss_OID;
#else
/*
* We can't use X/Open definitions, so roll our own.
*/
typedef gss_uint32 OM_uint32;
typedef struct gss_OID_desc_struct {
OM_uint32 length;
void*elements;
} gss_OID_desc, *gss_OID;
#endif
typedef struct gss_OID_set_desc_struct {
size_t count;
gss_OID elements;
} gss_OID_set_desc, *gss_OID_set;
#ifdef _SYSCALL32
typedef struct gss_OID_desc_struct32 {
OM_uint32 length;
caddr32_t elements;
} gss_OID_desc32, *gss_OID32;
#endif /* _SYSCALL32 */
typedef struct gss_buffer_desc_struct {
size_t length;
void *value;
} gss_buffer_desc, *gss_buffer_t;
typedef struct gss_channel_bindings_struct {
OM_uint32 initiator_addrtype;
gss_buffer_desc initiator_address;
OM_uint32 acceptor_addrtype;
gss_buffer_desc acceptor_address;
gss_buffer_desc application_data;
} *gss_channel_bindings_t;
/*
* For now, define a QOP-type as an OM_uint32
*/
typedef OM_uint32 gss_qop_t;
typedef int gss_cred_usage_t;
/*
* Flag bits for context-level services.
*/
#define GSS_C_DELEG_FLAG 1
#define GSS_C_MUTUAL_FLAG 2
#define GSS_C_REPLAY_FLAG 4
#define GSS_C_SEQUENCE_FLAG 8
#define GSS_C_CONF_FLAG 16
#define GSS_C_INTEG_FLAG 32
#define GSS_C_ANON_FLAG 64
#define GSS_C_PROT_READY_FLAG 128
#define GSS_C_TRANS_FLAG 256
/*
* Credential usage options
*/
#define GSS_C_BOTH 0
#define GSS_C_INITIATE 1
#define GSS_C_ACCEPT 2
/*
* Status code types for gss_display_status
*/
#define GSS_C_GSS_CODE 1
#define GSS_C_MECH_CODE 2
/*
* The constant definitions for channel-bindings address families
*/
#define GSS_C_AF_UNSPEC 0
#define GSS_C_AF_LOCAL 1
#define GSS_C_AF_INET 2
#define GSS_C_AF_IMPLINK 3
#define GSS_C_AF_PUP 4
#define GSS_C_AF_CHAOS 5
#define GSS_C_AF_NS 6
#define GSS_C_AF_NBS 7
#define GSS_C_AF_ECMA 8
#define GSS_C_AF_DATAKIT 9
#define GSS_C_AF_CCITT 10
#define GSS_C_AF_SNA 11
#define GSS_C_AF_DECnet 12
#define GSS_C_AF_DLI 13
#define GSS_C_AF_LAT 14
#define GSS_C_AF_HYLINK 15
#define GSS_C_AF_APPLETALK 16
#define GSS_C_AF_BSC 17
#define GSS_C_AF_DSS 18
#define GSS_C_AF_OSI 19
#define GSS_C_AF_X25 21
#define GSS_C_AF_NULLADDR 255
/*
* Various Null values
*/
#define GSS_C_NO_NAME ((gss_name_t) 0)
#define GSS_C_NO_BUFFER ((gss_buffer_t) 0)
#define GSS_C_NO_OID ((gss_OID) 0)
#define GSS_C_NO_OID_SET ((gss_OID_set) 0)
#define GSS_C_NO_CONTEXT ((gss_ctx_id_t) 0)
#define GSS_C_NO_CREDENTIAL ((gss_cred_id_t) 0)
#define GSS_C_NO_CHANNEL_BINDINGS ((gss_channel_bindings_t) 0)
#define GSS_C_EMPTY_BUFFER {0, NULL}
/*
* Some alternate names for a couple of the above
* values. These are defined for V1 compatibility.
*/
#define GSS_C_NULL_OID GSS_C_NO_OID
#define GSS_C_NULL_OID_SET GSS_C_NO_OID_SET
/*
* Define the default Quality of Protection for per-message
* services. Note that an implementation that offers multiple
* levels of QOP may define GSS_C_QOP_DEFAULT to be either zero
* (as done here) to mean "default protection", or to a specific
* explicit QOP value. However, a value of 0 should always be
* interpreted by a GSSAPI implementation as a request for the
* default protection level.
*/
#define GSS_C_QOP_DEFAULT 0
/*
* Expiration time of 2^32-1 seconds means infinite lifetime for a
* credential or security context
*/
#define GSS_C_INDEFINITE ((OM_uint32) 0xfffffffful)
/*
* The implementation must reserve static storage for a
* gss_OID_desc object containing the value
* {10, (void *)"\x2a\x86\x48\x86\xf7\x12"
* "\x01\x02\x01\x01"},
* corresponding to an object-identifier value of
* {iso(1) member-body(2) United States(840) mit(113554)
* infosys(1) gssapi(2) generic(1) user_name(1)}. The constant
* GSS_C_NT_USER_NAME should be initialized to point
* to that gss_OID_desc.
*/
extern const gss_OID GSS_C_NT_USER_NAME;
/*
* The implementation must reserve static storage for a
* gss_OID_desc object containing the value
* {10, (void *)"\x2a\x86\x48\x86\xf7\x12"
* "\x01\x02\x01\x02"},
* corresponding to an object-identifier value of
* {iso(1) member-body(2) United States(840) mit(113554)
* infosys(1) gssapi(2) generic(1) machine_uid_name(2)}.
* The constant GSS_C_NT_MACHINE_UID_NAME should be
* initialized to point to that gss_OID_desc.
*/
extern const gss_OID GSS_C_NT_MACHINE_UID_NAME;
/*
* The implementation must reserve static storage for a
* gss_OID_desc object containing the value
* {10, (void *)"\x2a\x86\x48\x86\xf7\x12"
* "\x01\x02\x01\x03"},
* corresponding to an object-identifier value of
* {iso(1) member-body(2) United States(840) mit(113554)
* infosys(1) gssapi(2) generic(1) string_uid_name(3)}.
* The constant GSS_C_NT_STRING_UID_NAME should be
* initialized to point to that gss_OID_desc.
*/
extern const gss_OID GSS_C_NT_STRING_UID_NAME;
/*
* The implementation must reserve static storage for a
* gss_OID_desc object containing the value
* {6, (void *)"\x2b\x06\x01\x05\x06\x02"},
* corresponding to an object-identifier value of
* {1(iso), 3(org), 6(dod), 1(internet), 5(security),
* 6(nametypes), 2(gss-host-based-services)}. The constant
* GSS_C_NT_HOSTBASED_SERVICE should be initialized to point
* to that gss_OID_desc.
*/
extern const gss_OID GSS_C_NT_HOSTBASED_SERVICE;
/*
* The implementation must reserve static storage for a
* gss_OID_desc object containing the value
* {6, (void *)"\x2b\x06\01\x05\x06\x03"},
* corresponding to an object identifier value of
* {1(iso), 3(org), 6(dod), 1(internet), 5(security),
* 6(nametypes), 3(gss-anonymous-name)}. The constant
* and GSS_C_NT_ANONYMOUS should be initialized to point
* to that gss_OID_desc.
*/
extern const gss_OID GSS_C_NT_ANONYMOUS;
/*
* The implementation must reserve static storage for a
* gss_OID_desc object containing the value
* {6, (void *)"\x2b\x06\x01\x05\x06\x04"},
* corresponding to an object-identifier value of
* {1(iso), 3(org), 6(dod), 1(internet), 5(security),
* 6(nametypes), 4(gss-api-exported-name)}. The constant
* GSS_C_NT_EXPORT_NAME should be initialized to point
* to that gss_OID_desc.
*/
extern const gss_OID GSS_C_NT_EXPORT_NAME;
/* Major status codes */
#define GSS_S_COMPLETE 0
/*
* Some "helper" definitions to make the status code macros obvious.
*/
#define GSS_C_CALLING_ERROR_OFFSET 24
#define GSS_C_ROUTINE_ERROR_OFFSET 16
#define GSS_C_SUPPLEMENTARY_OFFSET 0
#define GSS_C_CALLING_ERROR_MASK ((OM_uint32) 0377ul)
#define GSS_C_ROUTINE_ERROR_MASK ((OM_uint32) 0377ul)
#define GSS_C_SUPPLEMENTARY_MASK ((OM_uint32) 0177777ul)
/*
* The macros that test status codes for error conditions.
* Note that the GSS_ERROR() macro has changed slightly from
* the V1 GSSAPI so that it now evaluates its argument
* only once.
*/
#define GSS_CALLING_ERROR(x) \
((x) & (GSS_C_CALLING_ERROR_MASK << GSS_C_CALLING_ERROR_OFFSET))
#define GSS_ROUTINE_ERROR(x) \
((x) & (GSS_C_ROUTINE_ERROR_MASK << GSS_C_ROUTINE_ERROR_OFFSET))
#define GSS_SUPPLEMENTARY_INFO(x) \
((x) & (GSS_C_SUPPLEMENTARY_MASK << GSS_C_SUPPLEMENTARY_OFFSET))
#define GSS_ERROR(x) \
((x) & ((GSS_C_CALLING_ERROR_MASK << GSS_C_CALLING_ERROR_OFFSET) | \
(GSS_C_ROUTINE_ERROR_MASK << GSS_C_ROUTINE_ERROR_OFFSET)))
/*
* Now the actual status code definitions
*/
/*
* Calling errors:
*/
#define GSS_S_CALL_INACCESSIBLE_READ \
(((OM_uint32) 1ul) << GSS_C_CALLING_ERROR_OFFSET)
#define GSS_S_CALL_INACCESSIBLE_WRITE \
(((OM_uint32) 2ul) << GSS_C_CALLING_ERROR_OFFSET)
#define GSS_S_CALL_BAD_STRUCTURE \
(((OM_uint32) 3ul) << GSS_C_CALLING_ERROR_OFFSET)
/*
* Routine errors:
*/
#define GSS_S_BAD_MECH (((OM_uint32) 1ul) << GSS_C_ROUTINE_ERROR_OFFSET)
#define GSS_S_BAD_NAME (((OM_uint32) 2ul) << GSS_C_ROUTINE_ERROR_OFFSET)
#define GSS_S_BAD_NAMETYPE (((OM_uint32) 3ul) << GSS_C_ROUTINE_ERROR_OFFSET)
#define GSS_S_BAD_BINDINGS (((OM_uint32) 4ul) << GSS_C_ROUTINE_ERROR_OFFSET)
#define GSS_S_BAD_STATUS (((OM_uint32) 5ul) << GSS_C_ROUTINE_ERROR_OFFSET)
#define GSS_S_BAD_SIG (((OM_uint32) 6ul) << GSS_C_ROUTINE_ERROR_OFFSET)
#define GSS_S_BAD_MIC GSS_S_BAD_SIG
#define GSS_S_NO_CRED (((OM_uint32) 7ul) << GSS_C_ROUTINE_ERROR_OFFSET)
#define GSS_S_NO_CONTEXT (((OM_uint32) 8ul) << GSS_C_ROUTINE_ERROR_OFFSET)
#define GSS_S_DEFECTIVE_TOKEN (((OM_uint32) 9ul) << GSS_C_ROUTINE_ERROR_OFFSET)
#define GSS_S_DEFECTIVE_CREDENTIAL \
(((OM_uint32) 10ul) << GSS_C_ROUTINE_ERROR_OFFSET)
#define GSS_S_CREDENTIALS_EXPIRED \
(((OM_uint32) 11ul) << GSS_C_ROUTINE_ERROR_OFFSET)
#define GSS_S_CONTEXT_EXPIRED \
(((OM_uint32) 12ul) << GSS_C_ROUTINE_ERROR_OFFSET)
#define GSS_S_FAILURE (((OM_uint32) 13ul) << GSS_C_ROUTINE_ERROR_OFFSET)
#define GSS_S_BAD_QOP (((OM_uint32) 14ul) << GSS_C_ROUTINE_ERROR_OFFSET)
#define GSS_S_UNAUTHORIZED (((OM_uint32) 15ul) << GSS_C_ROUTINE_ERROR_OFFSET)
#define GSS_S_UNAVAILABLE (((OM_uint32) 16ul) << GSS_C_ROUTINE_ERROR_OFFSET)
#define GSS_S_DUPLICATE_ELEMENT \
(((OM_uint32) 17ul) << GSS_C_ROUTINE_ERROR_OFFSET)
#define GSS_S_NAME_NOT_MN (((OM_uint32) 18ul) << GSS_C_ROUTINE_ERROR_OFFSET)
/*
* Supplementary info bits:
*/
#define GSS_S_CONTINUE_NEEDED (1 << (GSS_C_SUPPLEMENTARY_OFFSET + 0))
#define GSS_S_DUPLICATE_TOKEN (1 << (GSS_C_SUPPLEMENTARY_OFFSET + 1))
#define GSS_S_OLD_TOKEN (1 << (GSS_C_SUPPLEMENTARY_OFFSET + 2))
#define GSS_S_UNSEQ_TOKEN (1 << (GSS_C_SUPPLEMENTARY_OFFSET + 3))
#define GSS_S_GAP_TOKEN (1 << (GSS_C_SUPPLEMENTARY_OFFSET + 4))
/*
* Finally, function prototypes for the GSS-API routines.
*/
OM_uint32 gss_acquire_cred(
OM_uint32 *, /* minor_status */
const gss_name_t, /* desired_name */
OM_uint32, /* time_req */
const gss_OID_set, /* desired_mechs */
gss_cred_usage_t, /* cred_usage */
gss_cred_id_t *, /* output_cred_handle */
gss_OID_set *, /* actual_mechs */
OM_uint32 * /* time_rec */
);
OM_uint32 gss_release_cred(
OM_uint32 *, /* minor_status */
gss_cred_id_t * /* cred_handle */
);
OM_uint32 gss_init_sec_context(
OM_uint32 *, /* minor_status */
const gss_cred_id_t, /* initiator_cred_handle */
gss_ctx_id_t *, /* context_handle */
const gss_name_t, /* target_name */
const gss_OID, /* mech_type */
OM_uint32, /* req_flags */
OM_uint32, /* time_req */
gss_channel_bindings_t, /* input_chan_bindings */
const gss_buffer_t, /* input_token */
gss_OID *, /* actual_mech_type */
gss_buffer_t, /* output_token */
OM_uint32 *, /* ret_flags */
OM_uint32 * /* time_rec */
);
OM_uint32 gss_accept_sec_context(
OM_uint32 *, /* minor_status */
gss_ctx_id_t *, /* context_handle */
const gss_cred_id_t, /* acceptor_cred_handle */
const gss_buffer_t, /* input_token_buffer */
const gss_channel_bindings_t, /* input_chan_bindings */
gss_name_t *, /* src_name */
gss_OID *, /* mech_type */
gss_buffer_t, /* output_token */
OM_uint32 *, /* ret_flags */
OM_uint32 *, /* time_rec */
gss_cred_id_t * /* delegated_cred_handle */
);
OM_uint32 gss_process_context_token(
OM_uint32 *, /* minor_status */
const gss_ctx_id_t, /* context_handle */
const gss_buffer_t /* token_buffer */
);
OM_uint32 gss_delete_sec_context(
OM_uint32 *, /* minor_status */
gss_ctx_id_t *, /* context_handle */
gss_buffer_t /* output_token */
);
OM_uint32 gss_context_time(
OM_uint32 *, /* minor_status */
const gss_ctx_id_t, /* context_handle */
OM_uint32 * /* time_rec */
);
OM_uint32 gss_get_mic(
OM_uint32 *, /* minor_status */
const gss_ctx_id_t, /* context_handle */
gss_qop_t, /* qop_req */
const gss_buffer_t, /* message_buffer */
gss_buffer_t /* message_token */
);
OM_uint32 gss_verify_mic(
OM_uint32 *, /* minor_status */
const gss_ctx_id_t, /* context_handle */
const gss_buffer_t, /* message_buffer */
const gss_buffer_t, /* token_buffer */
gss_qop_t * /* qop_state */
);
OM_uint32 gss_wrap(
OM_uint32 *, /* minor_status */
const gss_ctx_id_t, /* context_handle */
int, /* conf_req_flag */
gss_qop_t, /* qop_req */
const gss_buffer_t, /* input_message_buffer */
int *, /* conf_state */
gss_buffer_t /* output_message_buffer */
);
OM_uint32 gss_unwrap(
OM_uint32 *, /* minor_status */
const gss_ctx_id_t, /* context_handle */
const gss_buffer_t, /* input_message_buffer */
gss_buffer_t, /* output_message_buffer */
int *, /* conf_state */
gss_qop_t * /* qop_state */
);
OM_uint32 gss_display_status(
OM_uint32 *, /* minor_status */
OM_uint32, /* status_value */
int, /* status_type */
const gss_OID, /* mech_type */
OM_uint32 *, /* message_context */
gss_buffer_t /* status_string */
);
OM_uint32 gss_indicate_mechs(
OM_uint32 *, /* minor_status */
gss_OID_set * /* mech_set */
);
OM_uint32 gss_compare_name(
OM_uint32 *, /* minor_status */
const gss_name_t, /* name1 */
const gss_name_t, /* name2 */
int * /* name_equal */
);
OM_uint32 gss_display_name(
OM_uint32 *, /* minor_status */
const gss_name_t, /* input_name */
gss_buffer_t, /* output_name_buffer */
gss_OID * /* output_name_type */
);
OM_uint32 gss_import_name(
OM_uint32 *, /* minor_status */
const gss_buffer_t, /* input_name_buffer */
const gss_OID, /* input_name_type */
gss_name_t * /* output_name */
);
OM_uint32 gss_export_name(
OM_uint32 *, /* minor_status */
const gss_name_t, /* input_name */
gss_buffer_t /* exported_name */
);
OM_uint32 gss_release_name(
OM_uint32 *, /* minor_status */
gss_name_t * /* input_name */
);
OM_uint32 gss_release_buffer(
OM_uint32 *, /* minor_status */
gss_buffer_t /* buffer */
);
OM_uint32 gss_release_oid_set(
OM_uint32 *, /* minor_status */
gss_OID_set * /* set */
);
OM_uint32 gss_inquire_cred(
OM_uint32 *, /* minor_status */
const gss_cred_id_t, /* cred_handle */
gss_name_t *, /* name */
OM_uint32 *, /* lifetime */
gss_cred_usage_t *, /* cred_usage */
gss_OID_set * /* mechanisms */
);
OM_uint32 gss_inquire_context(
OM_uint32 *, /* minor_status */
const gss_ctx_id_t, /* context_handle */
gss_name_t *, /* src_name */
gss_name_t *, /* targ_name */
OM_uint32 *, /* lifetime_rec */
gss_OID *, /* mech_type */
OM_uint32 *, /* ctx_flags */
int *, /* locally_initiated */
int * /* open */
);
OM_uint32 gss_wrap_size_limit(
OM_uint32 *, /* minor_status */
const gss_ctx_id_t, /* context_handle */
int, /* conf_req_flag */
gss_qop_t, /* qop_req */
OM_uint32, /* req_output_size */
OM_uint32 * /* max_input_size */
);
OM_uint32 gss_add_cred(
OM_uint32 *, /* minor_status */
const gss_cred_id_t, /* input_cred_handle */
const gss_name_t, /* desired_name */
const gss_OID, /* desired_mech */
gss_cred_usage_t, /* cred_usage */
OM_uint32, /* initiator_time_req */
OM_uint32, /* acceptor_time_req */
gss_cred_id_t *, /* output_cred_handle */
gss_OID_set *, /* actual_mechs */
OM_uint32 *, /* initiator_time_rec */
OM_uint32 * /* acceptor_time_rec */
);
OM_uint32 gss_store_cred(
OM_uint32 *, /* minor_status */
const gss_cred_id_t, /* input_cred */
gss_cred_usage_t, /* cred_usage */
const gss_OID, /* desired_mech */
OM_uint32, /* overwrite_cred */
OM_uint32, /* default_cred */
gss_OID_set *, /* elements_stored */
gss_cred_usage_t * /* cred_usage_stored */
);
OM_uint32 gss_inquire_cred_by_mech(
OM_uint32 *, /* minor_status */
const gss_cred_id_t, /* cred_handle */
const gss_OID, /* mech_type */
gss_name_t *, /* name */
OM_uint32 *, /* initiator_lifetime */
OM_uint32 *, /* acceptor_lifetime */
gss_cred_usage_t * /* cred_usage */
);
OM_uint32 gss_export_sec_context(
OM_uint32 *, /* minor_status */
gss_ctx_id_t *, /* context_handle */
gss_buffer_t /* interprocess_token */
);
OM_uint32 gss_import_sec_context(
OM_uint32 *, /* minor_status */
const gss_buffer_t, /* interprocess_token */
gss_ctx_id_t * /* context_handle */
);
OM_uint32 gss_create_empty_oid_set(
OM_uint32 *, /* minor_status */
gss_OID_set * /* oid_set */
);
OM_uint32 gss_add_oid_set_member(
OM_uint32 *, /* minor_status */
const gss_OID, /* member_oid */
gss_OID_set * /* oid_set */
);
OM_uint32 gss_test_oid_set_member(
OM_uint32 *, /* minor_status */
const gss_OID, /* member */
const gss_OID_set, /* set */
int * /* present */
);
OM_uint32 gss_inquire_names_for_mech(
OM_uint32 *, /* minor_status */
const gss_OID, /* mechanism */
gss_OID_set * /* name_types */
);
OM_uint32 gss_inquire_mechs_for_name(
OM_uint32 *, /* minor_status */
const gss_name_t, /* input_name */
gss_OID_set * /* mech_types */
);
OM_uint32 gss_canonicalize_name(
OM_uint32 *, /* minor_status */
const gss_name_t, /* input_name */
const gss_OID, /* mech_type */
gss_name_t * /* output_name */
);
OM_uint32 gss_duplicate_name(
OM_uint32 *, /* minor_status */
const gss_name_t, /* src_name */
gss_name_t * /* dest_name */
);
OM_uint32 gss_release_oid(
OM_uint32 *, /* minor_status */
gss_OID * /* oid */
);
OM_uint32 gss_str_to_oid(
OM_uint32 *, /* minor_status */
const gss_buffer_t, /* oid_str */
gss_OID * /* oid */
);
OM_uint32 gss_oid_to_str(
OM_uint32 *, /* minor_status */
const gss_OID, /* oid */
gss_buffer_t /* oid_str */
);
/*
* The following routines are obsolete variants of gss_get_mic,
* gss_verify_mic, gss_wrap and gss_unwrap. They should be
* provided by GSSAPI V2 implementations for backwards
* compatibility with V1 applications. Distinct entrypoints
* (as opposed to #defines) should be provided, both to allow
* GSSAPI V1 applications to link against GSSAPI V2 implementations,
* and to retain the slight parameter type differences between the
* obsolete versions of these routines and their current forms.
*/
OM_uint32 gss_sign(
OM_uint32 *, /* minor_status */
gss_ctx_id_t, /* context_handle */
int, /* qop_req */
gss_buffer_t, /* message_buffer */
gss_buffer_t /* message_token */
);
OM_uint32 gss_verify(
OM_uint32 *, /* minor_status */
gss_ctx_id_t, /* context_handle */
gss_buffer_t, /* message_buffer */
gss_buffer_t, /* token_buffer */
int * /* qop_state */
);
OM_uint32 gss_seal(
OM_uint32 *, /* minor_status */
gss_ctx_id_t, /* context_handle */
int, /* conf_req_flag */
int, /* qop_req */
gss_buffer_t, /* input_message_buffer */
int *, /* conf_state */
gss_buffer_t /* output_message_buffer */
);
OM_uint32 gss_unseal(
OM_uint32 *, /* minor_status */
gss_ctx_id_t, /* context_handle */
gss_buffer_t, /* input_message_buffer */
gss_buffer_t, /* output_message_buffer */
int *, /* conf_state */
int * /* qop_state */
);
#ifdef _KERNEL /* For kernel */
#include <rpc/types.h>
void kgss_free_oid(gss_OID oid);
OM_uint32 kgss_acquire_cred(
OM_uint32 *,
const gss_name_t,
OM_uint32,
const gss_OID_set,
int,
gss_cred_id_t *,
gss_OID_set *,
OM_uint32 *,
uid_t);
OM_uint32 kgss_add_cred(
OM_uint32 *,
gss_cred_id_t,
gss_name_t,
gss_OID,
int,
int,
int,
gss_OID_set *,
OM_uint32 *,
OM_uint32 *,
uid_t);
OM_uint32 kgss_release_cred(
OM_uint32 *,
gss_cred_id_t *,
uid_t);
OM_uint32 kgss_init_sec_context(
OM_uint32 *,
const gss_cred_id_t,
gss_ctx_id_t *,
const gss_name_t,
const gss_OID,
int,
OM_uint32,
const gss_channel_bindings_t,
const gss_buffer_t,
gss_OID *,
gss_buffer_t,
int *,
OM_uint32 *,
uid_t);
OM_uint32 kgss_accept_sec_context(
OM_uint32 *,
gss_ctx_id_t *,
const gss_cred_id_t,
const gss_buffer_t,
const gss_channel_bindings_t,
const gss_buffer_t,
gss_OID *,
gss_buffer_t,
int *,
OM_uint32 *,
gss_cred_id_t *,
uid_t);
OM_uint32 kgss_process_context_token(
OM_uint32 *,
const gss_ctx_id_t,
const gss_buffer_t,
uid_t);
OM_uint32 kgss_delete_sec_context(
OM_uint32 *,
gss_ctx_id_t *,
gss_buffer_t);
OM_uint32 kgss_export_sec_context(
OM_uint32 *,
const gss_ctx_id_t,
gss_buffer_t);
OM_uint32 kgss_import_sec_context(
OM_uint32 *,
const gss_buffer_t,
gss_ctx_id_t);
OM_uint32 kgss_context_time(
OM_uint32 *,
const gss_ctx_id_t,
OM_uint32 *,
uid_t);
OM_uint32 kgss_sign(
OM_uint32 *,
const gss_ctx_id_t,
int,
const gss_buffer_t,
gss_buffer_t);
OM_uint32 kgss_verify(
OM_uint32 *,
const gss_ctx_id_t,
const gss_buffer_t,
const gss_buffer_t,
int *);
OM_uint32 kgss_seal(
OM_uint32 *,
const gss_ctx_id_t,
int,
int,
const gss_buffer_t,
int *,
gss_buffer_t);
OM_uint32 kgss_unseal(
OM_uint32 *,
const gss_ctx_id_t,
const gss_buffer_t,
gss_buffer_t,
int *,
int *);
OM_uint32 kgss_display_status(
OM_uint32 *,
OM_uint32,
int,
const gss_OID,
int *,
gss_buffer_t,
uid_t);
OM_uint32 kgss_indicate_mechs(
OM_uint32 *,
gss_OID_set *,
uid_t);
OM_uint32 kgss_inquire_cred(
OM_uint32 *,
const gss_cred_id_t,
gss_name_t *,
OM_uint32 *,
int *,
gss_OID_set *,
uid_t);
OM_uint32 kgss_inquire_cred_by_mech(
OM_uint32 *,
gss_cred_id_t,
gss_OID,
uid_t);
#endif /* if _KERNEL */
#ifdef __cplusplus
}
#endif
#endif /* _GSSAPI_H_ */
/*
* 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 2011 Nexenta Systems, Inc. All rights reserved.
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* Private extensions and utilities to the GSS-API.
* These are not part of the GSS-API specification
* but may be useful to GSS-API users.
*/
#ifndef _GSSAPI_EXT_H
#define _GSSAPI_EXT_H
#include <gssapi/gssapi.h>
#ifdef _KERNEL
#include <sys/systm.h>
#else
#include <strings.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
/* MACRO for comparison of gss_OID's */
#define g_OID_equal(o1, o2) \
(((o1)->length == (o2)->length) && \
(memcmp((o1)->elements, (o2)->elements, (int)(o1)->length) == 0))
/*
* MACRO for copying of OIDs - memory must already be allocated
* o2 is copied to o1
*/
#define g_OID_copy(o1, o2) \
bcopy((o2)->elements, (o1)->elements, (o2)->length);\
(o1)->length = (o2)->length;
/* MACRO to check if input buffer is valid */
#define GSS_EMPTY_BUFFER(buf) ((buf) == NULL ||\
(buf)->value == NULL || (buf)->length == 0)
/*
* GSSAPI Extension functions -- these functions aren't
* in the GSSAPI specification, but are provided in our
* GSS library.
*/
#ifndef _KERNEL
/*
* qop configuration file handling.
*/
#define MAX_QOP_NUM_PAIRS 128
#define MAX_QOPS_PER_MECH 128
typedef struct _qop_num {
char *qop;
OM_uint32 num;
char *mech;
} qop_num;
OM_uint32
__gss_qop_to_num(
char *qop, /* input qop string */
char *mech, /* input mech string */
OM_uint32 *num /* output qop num */
);
OM_uint32
__gss_num_to_qop(
char *mech, /* input mech string */
OM_uint32 num, /* input qop num */
char **qop /* output qop name */
);
OM_uint32
__gss_get_mech_info(
char *mech, /* input mech string */
char **qops /* buffer for return qops */
);
OM_uint32
__gss_mech_qops(
char *mech, /* input mech */
qop_num *mech_qops, /* mech qops buffer */
int *numqops /* buffer to return numqops */
);
OM_uint32
__gss_mech_to_oid(
const char *mech, /* mechanism string name */
gss_OID *oid /* mechanism oid */
);
const char *
__gss_oid_to_mech(
const gss_OID oid /* mechanism oid */
);
OM_uint32
__gss_get_mechanisms(
char *mechArray[], /* array to populate with mechs */
int arrayLen /* length of passed in array */
);
OM_uint32
__gss_get_mech_type(
gss_OID oid, /* mechanism oid */
const gss_buffer_t token /* token */
);
OM_uint32
__gss_userok(
OM_uint32 *, /* minor status */
const gss_name_t, /* remote user principal name */
const char *, /* local unix user name */
int *); /* remote principal ok to login w/out pw? */
OM_uint32
gsscred_expname_to_unix_cred(
const gss_buffer_t, /* export name */
uid_t *, /* uid out */
gid_t *, /* gid out */
gid_t *[], /* gid array out */
int *); /* gid array length */
OM_uint32
gsscred_name_to_unix_cred(
const gss_name_t, /* gss name */
const gss_OID, /* mechanim type */
uid_t *, /* uid out */
gid_t *, /* gid out */
gid_t *[], /* gid array out */
int *); /* gid array length */
/*
* The following function will be used to resolve group
* ids from a UNIX uid.
*/
OM_uint32
gss_get_group_info(
const uid_t, /* entity UNIX uid */
gid_t *, /* gid out */
gid_t *[], /* gid array */
int *); /* length of the gid array */
OM_uint32
gss_acquire_cred_with_password(
OM_uint32 * minor_status,
const gss_name_t desired_name,
const gss_buffer_t password,
OM_uint32 time_req,
const gss_OID_set desired_mechs,
int cred_usage,
gss_cred_id_t *output_cred_handle,
gss_OID_set * actual_mechs,
OM_uint32 * time_rec);
OM_uint32
gss_add_cred_with_password(
OM_uint32 *minor_status,
const gss_cred_id_t input_cred_handle,
const gss_name_t desired_name,
const gss_OID desired_mech,
const gss_buffer_t password,
gss_cred_usage_t cred_usage,
OM_uint32 initiator_time_req,
OM_uint32 acceptor_time_req,
gss_cred_id_t *output_cred_handle,
gss_OID_set *actual_mechs,
OM_uint32 *initiator_time_rec,
OM_uint32 *acceptor_time_rec);
/*
* Returns a buffer set with the first member containing the
* session key for SSPI compatibility. The optional second
* member contains an OID identifying the session key type.
*/
extern const gss_OID GSS_C_INQ_SSPI_SESSION_KEY;
/*
* For compatability with other GSSAPI implementations.
* This is needed by Samba.
*/
extern const gss_OID_desc * const gss_mech_krb5;
#else /* _KERNEL */
OM_uint32
kgsscred_expname_to_unix_cred(
const gss_buffer_t expName,
uid_t *uidOut,
gid_t *gidOut,
gid_t *gids[],
int *gidsLen,
uid_t uid);
OM_uint32
kgsscred_name_to_unix_cred(
const gss_name_t intName,
const gss_OID mechType,
uid_t *uidOut,
gid_t *gidOut,
gid_t *gids[],
int *gidsLen,
uid_t uid);
OM_uint32
kgss_get_group_info(
const uid_t puid,
gid_t *gidOut,
gid_t *gids[],
int *gidsLen,
uid_t uid);
#endif
/*
* GGF extensions
*/
typedef struct gss_buffer_set_desc_struct {
size_t count;
gss_buffer_desc *elements;
} gss_buffer_set_desc, *gss_buffer_set_t;
#define GSS_C_NO_BUFFER_SET ((gss_buffer_set_t)0)
OM_uint32 gss_create_empty_buffer_set
(OM_uint32 *, /* minor_status */
gss_buffer_set_t *); /* buffer_set */
OM_uint32 gss_add_buffer_set_member
(OM_uint32 *, /* minor_status */
const gss_buffer_t, /* member_buffer */
gss_buffer_set_t *); /* buffer_set */
OM_uint32 gss_release_buffer_set
(OM_uint32 *, /* minor_status */
gss_buffer_set_t *); /* buffer_set */
OM_uint32 gss_inquire_sec_context_by_oid
(OM_uint32 *, /* minor_status */
const gss_ctx_id_t, /* context_handle */
const gss_OID, /* desired_object */
gss_buffer_set_t *); /* data_set */
#ifdef __cplusplus
}
#endif
#endif /* _GSSAPI_EXT_H */
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 2004 Sun Microsystems, Inc. All rights reserved.
% * Use is subject to license terms.
% */
%
%/*
% * RPC protocol information for gssd, the usermode daemon that
% * assists the kernel with gssapi. It is gssd that executes all
% * gssapi calls except for some such as gss_sign(), and
% * gss_verify(), which are executed in the kernel itself.
% *
% * File generated from gssd.x
% */
%
%#define NO 0
%#define YES 1
%#define FOREVER 1
%
%#include <sys/types.h>
%#include <sys/time.h>
%#include <rpc/auth_sys.h>
%#ifndef _KERNEL
%#include <locale.h>
%#endif /* not _KERNEL */
%
%#ifdef _KERNEL
%extern void killgssd_handle(CLIENT *);
%extern CLIENT *getgssd_handle(void);
%#endif /* _KERNEL */
%
/*
* These are the definitions for the interface to GSSD.
*/
typedef unsigned int OM_UINT32;
typedef opaque GSS_CTX_ID_T<>;
typedef opaque GSS_CRED_ID_T<>;
typedef opaque GSS_OID<>;
typedef opaque GSS_BUFFER_T<>;
typedef gid_t GSSCRED_GIDS<>;
typedef GSS_OID GSS_OID_SET<>;
struct GSS_CHANNEL_BINDINGS_STRUCT {
int present;
OM_UINT32 initiator_addrtype;
GSS_BUFFER_T initiator_address;
OM_UINT32 acceptor_addrtype;
GSS_BUFFER_T acceptor_address;
GSS_BUFFER_T application_data;
};
typedef struct GSS_CHANNEL_BINDINGS_STRUCT GSS_CHANNEL_BINDINGS;
struct gss_acquire_cred_arg {
uid_t uid; /* client uid */
GSS_BUFFER_T desired_name; /* name of cred */
GSS_OID name_type; /* type of desired name */
OM_UINT32 time_req; /* context validity interval */
GSS_OID_SET desired_mechs; /* cred mechanisms */
int cred_usage; /* init/accept/both */
};
struct gss_acquire_cred_res {
OM_UINT32 minor_status; /* status from the mechanism */
GSS_CRED_ID_T output_cred_handle; /* returned credential handle */
OM_UINT32 gssd_cred_verifier; /* verifier for cred handle */
GSS_OID_SET actual_mechs; /* found cred mechanisms */
OM_UINT32 time_rec; /* actual context validity */
OM_UINT32 status; /* status of GSSAPI call */
};
struct gss_add_cred_arg {
uid_t uid; /* client uid */
GSS_CRED_ID_T input_cred_handle; /* input credential handle */
OM_UINT32 gssd_cred_verifier; /* verifier for cred handle */
GSS_BUFFER_T desired_name; /* name of cred */
GSS_OID name_type; /* type of desired name */
GSS_OID desired_mech_type; /* cred mechanisms */
int cred_usage; /* init/accept/both */
OM_UINT32 initiator_time_req; /* context validity interval */
OM_UINT32 acceptor_time_req; /* context validity interval */
};
/* Note: For gss_add_cred we always update the underlying credentials of
* input_cred_handle. We always pass NULL as output_cred_handle when the call
* to gss_add_cred is made
*/
struct gss_add_cred_res {
OM_UINT32 minor_status; /* status from the mechanism */
GSS_OID_SET actual_mechs; /* found cred mechanisms */
OM_UINT32 initiator_time_rec; /* cred validity interval */
OM_UINT32 acceptor_time_rec; /* cred validity interval */
OM_UINT32 status; /* status of GSSAPI call */
};
struct gss_release_cred_arg {
uid_t uid; /* client uid */
OM_UINT32 gssd_cred_verifier; /* verifier for cred handles */
GSS_CRED_ID_T cred_handle; /* credential handle */
};
struct gss_release_cred_res {
OM_UINT32 minor_status; /* status from the mechanism */
OM_UINT32 status; /* status of GSSAPI call */
};
struct gss_init_sec_context_arg {
uid_t uid; /* client uid */
GSS_CTX_ID_T context_handle; /* handle to existing context */
OM_UINT32 gssd_context_verifier; /* verifier for context handles */
GSS_CRED_ID_T claimant_cred_handle; /* must = GSS_C_NO_CREDENTIAL */
OM_UINT32 gssd_cred_verifier; /* verifier for cred handle */
GSS_BUFFER_T target_name; /* name of server */
GSS_OID name_type; /* type of principal name */
GSS_OID mech_type; /* requested mechanism */
int req_flags; /* requested context options */
OM_UINT32 time_req; /* context validity interval */
GSS_CHANNEL_BINDINGS
input_chan_bindings; /* requested channel bindings */
GSS_BUFFER_T input_token; /* token to send to peer */
};
struct gss_init_sec_context_res {
GSS_CTX_ID_T context_handle; /* handle to created context */
OM_UINT32 gssd_context_verifier; /* verifier for context handles */
OM_UINT32 minor_status; /* status from the mechanism */
GSS_OID actual_mech_type; /* actual mechanism used */
GSS_BUFFER_T output_token; /* where peer token is put */
OM_UINT32 ret_flags; /* options of context */
OM_UINT32 time_rec; /* actual context validity */
OM_UINT32 status; /* status of GSSAPI call */
};
struct gss_accept_sec_context_arg {
uid_t uid; /* client uid */
GSS_CTX_ID_T context_handle; /* handle to existing context */
OM_UINT32 gssd_context_verifier; /* verifier for context handles */
GSS_CRED_ID_T verifier_cred_handle; /* must = GSS_C_NO_CREDENTIAL */
OM_UINT32 gssd_cred_verifier; /* verifier for cred handle */
GSS_BUFFER_T input_token_buffer; /* token to send to peer */
GSS_CHANNEL_BINDINGS
input_chan_bindings; /* requested channel bindings */
};
struct gss_accept_sec_context_res {
GSS_CTX_ID_T context_handle; /* handle to created context */
OM_UINT32 gssd_context_verifier; /* verifier for context handles */
OM_UINT32 minor_status; /* status from the mechanism */
GSS_BUFFER_T src_name; /* authenticated name of peer */
GSS_OID mech_type; /* mechanism used */
GSS_BUFFER_T output_token; /* where peer token is put */
OM_UINT32 ret_flags; /* options of context */
OM_UINT32 time_rec; /* actual context validity */
GSS_CRED_ID_T delegated_cred_handle; /* always GSS_C_NO_CREDENTIAL */
OM_UINT32 status; /* status of GSSAPI call */
};
struct gss_process_context_token_arg {
uid_t uid; /* client uid */
OM_UINT32 gssd_context_verifier; /* verifier for context handles */
GSS_CTX_ID_T context_handle; /* handle to existing context */
GSS_BUFFER_T token_buffer; /* token to process */
};
struct gss_process_context_token_res {
OM_UINT32 minor_status; /* status from the mechanism */
OM_UINT32 status; /* status of GSSAPI call */
};
struct gss_delete_sec_context_arg {
OM_UINT32 gssd_context_verifier; /* verifier for context handles */
GSS_CTX_ID_T context_handle; /* handle to existing context */
};
struct gss_delete_sec_context_res {
OM_UINT32 minor_status; /* status from the mechanism */
GSS_CTX_ID_T context_handle; /* handle to deleted context */
GSS_BUFFER_T output_token; /* output token for peer */
OM_UINT32 status; /* status of GSSAPI call */
};
struct gss_export_sec_context_arg {
GSS_CTX_ID_T context_handle; /* handle to existing context */
OM_UINT32 gssd_context_verifier; /* verifier for context handles */
};
struct gss_export_sec_context_res {
OM_UINT32 minor_status; /* status from the mechanism */
GSS_CTX_ID_T context_handle; /* handle to existing context */
GSS_BUFFER_T output_token; /* input token for import_sec_context */
OM_UINT32 status; /* status of GSSAPI call */
};
struct gss_import_sec_context_arg {
GSS_BUFFER_T input_token; /* input token for import_sec_context */
OM_UINT32 gssd_context_verifier; /* verifier for context handles */
};
struct gss_import_sec_context_res {
OM_UINT32 minor_status; /* status from the mechanism */
GSS_CTX_ID_T context_handle; /* handle to created context */
OM_UINT32 status; /* status of GSSAPI call */
};
struct gss_context_time_arg {
uid_t uid; /* client uid */
OM_UINT32 gssd_context_verifier; /* verifier for context handles */
GSS_CTX_ID_T context_handle; /* handle to existing context */
};
struct gss_context_time_res {
OM_UINT32 minor_status; /* status from the mechanism */
OM_UINT32 time_rec; /* actual context validity */
OM_UINT32 status; /* status of GSSAPI call */
};
struct gss_sign_arg {
OM_UINT32 gssd_context_verifier; /* verifier for context handles */
GSS_CTX_ID_T context_handle; /* handle to existing context */
int qop_req; /* quality of protection */
GSS_BUFFER_T message_buffer; /* message to sign */
};
struct gss_sign_res {
OM_UINT32 minor_status; /* status from the mechanism */
GSS_BUFFER_T msg_token; /* msg_token */
OM_UINT32 status; /* status of GSSAPI call */
};
struct gss_verify_arg {
OM_UINT32 gssd_context_verifier; /* verifier for context handles */
GSS_CTX_ID_T context_handle; /* handle to existing context */
GSS_BUFFER_T message_buffer; /* message to verify */
GSS_BUFFER_T token_buffer; /* buffer containg token */
};
struct gss_verify_res {
OM_UINT32 minor_status; /* status from the mechanism */
int qop_state; /* quality of protection */
OM_UINT32 status; /* status of GSSAPI call */
};
struct gss_seal_arg {
OM_UINT32 gssd_context_verifier; /* verifier for context handles */
GSS_CTX_ID_T context_handle; /* handle to existing context */
int conf_req_flag; /* type of conf requested */
int qop_req; /* quality of prot. requested */
GSS_BUFFER_T input_message_buffer; /* message to protect */
};
struct gss_seal_res {
OM_UINT32 minor_status; /* status from the mechanism */
int conf_state; /* type of conf. applied */
GSS_BUFFER_T output_message_buffer; /* protected message */
OM_UINT32 status; /* status of GSSAPI call */
};
struct gss_unseal_arg {
OM_UINT32 gssd_context_verifier; /* verifier for context handles */
GSS_CTX_ID_T context_handle; /* handle to existing context */
GSS_BUFFER_T input_message_buffer; /* message to protect */
};
struct gss_unseal_res {
OM_UINT32 minor_status; /* status from the mechanism */
GSS_BUFFER_T output_message_buffer; /* protected message */
int conf_state; /* type of conf. provided */
int qop_state; /* quality of prot. provided */
OM_UINT32 status; /* status of GSSAPI call */
};
struct gss_display_status_arg {
uid_t uid; /* client uid */
int status_value; /* status to be converted */
int status_type; /* GSS or mech status */
GSS_OID mech_type; /* mechanism */
OM_UINT32 message_context; /* recursion flag */
};
struct gss_display_status_res {
OM_UINT32 minor_status; /* status from the mechanism */
int message_context; /* recursion flag */
GSS_BUFFER_T status_string; /* text equiv of status */
OM_UINT32 status; /* status of GSSAPI call */
};
%/* gss_indicate_mechs_arg is void. This appears in the rpc call def */
struct gss_indicate_mechs_res {
OM_UINT32 minor_status; /* status from the mechanism */
GSS_OID_SET mech_set; /* mechanism set supported */
OM_UINT32 status; /* status of GSSAPI call */
};
struct gss_inquire_cred_arg {
uid_t uid; /* client uid */
OM_UINT32 gssd_cred_verifier; /* verifier for cred handle */
GSS_CRED_ID_T cred_handle; /* credential handle */
};
struct gss_inquire_cred_res {
OM_UINT32 minor_status; /* status from the mechanism */
GSS_BUFFER_T name; /* name associated with cred */
GSS_OID name_type; /* type of name */
OM_UINT32 lifetime; /* remaining validiy period */
int cred_usage; /* how creds may be used */
GSS_OID_SET mechanisms; /* mechs associated with cred */
OM_UINT32 status; /* status of GSSAPI call */
};
struct gss_inquire_cred_by_mech_arg {
uid_t uid; /* client uid */
OM_UINT32 gssd_cred_verifier; /* verifier for cred handle */
GSS_CRED_ID_T cred_handle; /* credential handle */
GSS_OID mech_type; /* cred mechanism */
};
struct gss_inquire_cred_by_mech_res {
OM_UINT32 minor_status; /* status from the mechanism */
OM_UINT32 status; /* status of GSSAPI call */
};
struct gsscred_name_to_unix_cred_arg {
uid_t uid; /* client uid */
GSS_BUFFER_T pname; /* principal name */
GSS_OID name_type; /* oid of principal name */
GSS_OID mech_type; /* for which mechanism to use */
};
struct gsscred_name_to_unix_cred_res {
uid_t uid; /* principal's uid */
gid_t gid; /* principal's gid */
GSSCRED_GIDS gids; /* array of principal's gids */
OM_UINT32 major; /* status of the GSSAPI call */
};
struct
gsscred_expname_to_unix_cred_arg {
uid_t uid; /* client uid */
GSS_BUFFER_T expname; /* principal in export format */
};
struct
gsscred_expname_to_unix_cred_res {
uid_t uid; /* principal's uid */
gid_t gid; /* principal's gid */
GSSCRED_GIDS gids; /* array of principal's gids */
OM_UINT32 major; /* major status code */
};
struct gss_get_group_info_arg {
uid_t uid; /* client uid */
uid_t puid; /* principal's uid */
};
struct gss_get_group_info_res {
gid_t gid; /* principal's gid */
GSSCRED_GIDS gids; /* array of principal's gids */
OM_UINT32 major; /* major status code */
};
struct gss_get_kmod_arg {
GSS_OID mech_oid;
};
union gss_get_kmod_res switch (bool module_follow) {
case TRUE:
string modname<>;
case FALSE:
void;
};
/*
* The server accepts requests only from the loopback address.
* Unix authentication is used, and the port must be in the reserved range.
*/
program GSSPROG {
version GSSVERS {
/*
* Called by the client to acquire a credential.
*/
gss_acquire_cred_res
GSS_ACQUIRE_CRED(gss_acquire_cred_arg) = 1;
/*
* Called by the client to release a credential.
*/
gss_release_cred_res
GSS_RELEASE_CRED(gss_release_cred_arg) = 2;
/*
* Called by the client to initialize a security context.
*/
gss_init_sec_context_res
GSS_INIT_SEC_CONTEXT(gss_init_sec_context_arg) = 3;
/*
* Called by the server to initialize a security context.
*/
gss_accept_sec_context_res
GSS_ACCEPT_SEC_CONTEXT(gss_accept_sec_context_arg) = 4;
/*
* Called to pass token to underlying mechanism.
*/
gss_process_context_token_res
GSS_PROCESS_CONTEXT_TOKEN(gss_process_context_token_arg) = 5;
/*
* Called to delete a security context.
*/
gss_delete_sec_context_res
GSS_DELETE_SEC_CONTEXT(gss_delete_sec_context_arg) = 6;
/*
* Called to get remaining time security context has to live.
*/
gss_context_time_res
GSS_CONTEXT_TIME(gss_context_time_arg) = 7;
/*
* Called to sign a message.
*/
gss_sign_res GSS_SIGN(gss_sign_arg) = 8;
/*
* Called to verify a signed message.
*/
gss_verify_res GSS_VERIFY(gss_verify_arg) = 9;
/*
* Called to translate minor status into a string.
*/
gss_display_status_res
GSS_DISPLAY_STATUS(gss_display_status_arg) = 10;
/*
* Called to indicate which underlying mechanisms are supported
*/
gss_indicate_mechs_res
GSS_INDICATE_MECHS(void) = 11;
/*
* Called by the client to inquire about a credential.
*/
gss_inquire_cred_res
GSS_INQUIRE_CRED(gss_inquire_cred_arg) = 12;
/*
* Called to seal a message.
*/
gss_seal_res GSS_SEAL(gss_seal_arg) = 13;
/*
* Called to unseal a message.
*/
gss_unseal_res GSS_UNSEAL(gss_unseal_arg) = 14;
/*
* gsscred interface functions to obtain principal uid and gids
*/
gsscred_expname_to_unix_cred_res
GSSCRED_EXPNAME_TO_UNIX_CRED(
gsscred_expname_to_unix_cred_arg) = 15;
gsscred_name_to_unix_cred_res
GSSCRED_NAME_TO_UNIX_CRED(
gsscred_name_to_unix_cred_arg) = 16;
gss_get_group_info_res
GSS_GET_GROUP_INFO(gss_get_group_info_arg) = 17;
gss_get_kmod_res
GSS_GET_KMOD(gss_get_kmod_arg) = 18;
gss_export_sec_context_res
GSS_EXPORT_SEC_CONTEXT(gss_export_sec_context_arg) = 19;
gss_import_sec_context_res
GSS_IMPORT_SEC_CONTEXT(gss_import_sec_context_arg) = 20;
/*
* Called by the client to add to a credential.
*/
gss_add_cred_res
GSS_ADD_CRED(gss_add_cred_arg) = 21;
gss_inquire_cred_by_mech_res
GSS_INQUIRE_CRED_BY_MECH(gss_inquire_cred_by_mech_arg)
= 22;
} = 1;
} = 100234;
/*
* 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 2012 Milan Jurik. All rights reserved.
*/
/*
* GSSAPI library stub module for gssd.
*/
#include <mechglueP.h>
#include "gssd_prot.h"
#include <rpc/rpc.h>
#include <sys/systm.h>
#include <sys/types.h>
#include <sys/cmn_err.h>
#include <sys/kmem.h>
#include <gssapi/kgssapi_defs.h>
#include <sys/debug.h>
#ifdef GSSDEBUG
/*
* Kernel kgssd module debugging aid. The global variable "gss_log"
* is a bit mask which allows various types of debugging messages
* to be printed out.
*
* gss_log & 1 will cause actual failures to be printed.
* gss_log & 2 will cause informational messages to be
* printed on the client side of kgssd.
* gss_log & 4 will cause informational messages to be
* printed on the server side of kgssd.
* gss_log & 8 will cause informational messages to be
* printed on both client and server side of kgssd.
*/
uint_t gss_log = 1;
#endif /* GSSDEBUG */
#ifdef DEBUG
extern void prom_printf(const char *, ...);
#endif
char *server = "localhost";
static OM_uint32 kgss_sign_wrapped(void *, OM_uint32 *, gss_ctx_id_t, int,
gss_buffer_t, gss_buffer_t, OM_uint32);
static OM_uint32 kgss_verify_wrapped(void *, OM_uint32 *, gss_ctx_id_t,
gss_buffer_t, gss_buffer_t, int *qop_state, OM_uint32);
static OM_uint32 kgss_seal_wrapped(void *, OM_uint32 *, gss_ctx_id_t,
int, int, gss_buffer_t, int *, gss_buffer_t, OM_uint32);
static OM_uint32 kgss_unseal_wrapped(void *, OM_uint32 *, gss_ctx_id_t,
gss_buffer_t, gss_buffer_t, int *conf_state, int *qop_state,
OM_uint32);
static OM_uint32 kgss_delete_sec_context_wrapped(void *, OM_uint32 *,
gssd_ctx_id_t *, gss_buffer_t, OM_uint32);
static void __kgss_reset_mech(gss_mechanism *, gss_OID);
#define DEFAULT_MINOR_STAT ((OM_uint32) ~0)
OM_uint32
kgss_acquire_cred_wrapped(minor_status,
desired_name,
time_req,
desired_mechs,
cred_usage,
output_cred_handle,
actual_mechs,
time_rec,
uid,
gssd_cred_verifier)
OM_uint32 *minor_status;
const gss_name_t desired_name;
OM_uint32 time_req;
const gss_OID_set desired_mechs;
int cred_usage;
gssd_cred_id_t *output_cred_handle;
gss_OID_set *actual_mechs;
OM_uint32 *time_rec;
uid_t uid;
OM_uint32 *gssd_cred_verifier;
{
CLIENT *clnt;
OM_uint32 minor_status_temp;
gss_buffer_desc external_name;
gss_OID name_type;
enum clnt_stat client_stat;
int i;
gss_acquire_cred_arg arg;
gss_acquire_cred_res res;
/* get the client handle to GSSD */
if ((clnt = getgssd_handle()) == NULL) {
GSSLOG(1, "kgss_acquire_cred: can't connect to server on %s\n",
server);
return (GSS_S_FAILURE);
}
/* convert the desired name from internal to external format */
if (gss_display_name(&minor_status_temp, desired_name, &external_name,
&name_type) != GSS_S_COMPLETE) {
*minor_status = (OM_uint32) minor_status_temp;
killgssd_handle(clnt);
GSSLOG0(1, "kgss_acquire_cred: display name failed\n");
return ((OM_uint32) GSS_S_FAILURE);
}
/* copy the procedure arguments into the rpc arg parameter */
arg.uid = (OM_uint32) uid;
arg.desired_name.GSS_BUFFER_T_len = (uint_t)external_name.length;
arg.desired_name.GSS_BUFFER_T_val = (char *)external_name.value;
arg.name_type.GSS_OID_len =
name_type == GSS_C_NULL_OID ?
0 : (uint_t)name_type->length;
arg.name_type.GSS_OID_val =
name_type == GSS_C_NULL_OID ?
(char *)NULL : (char *)name_type->elements;
arg.time_req = time_req;
if (desired_mechs != GSS_C_NULL_OID_SET) {
arg.desired_mechs.GSS_OID_SET_len =
(uint_t)desired_mechs->count;
arg.desired_mechs.GSS_OID_SET_val = (GSS_OID *)
MALLOC(sizeof (GSS_OID) * desired_mechs->count);
for (i = 0; i < desired_mechs->count; i++) {
arg.desired_mechs.GSS_OID_SET_val[i].GSS_OID_len =
(uint_t)desired_mechs->elements[i].length;
arg.desired_mechs.GSS_OID_SET_val[i].GSS_OID_val =
(char *)MALLOC(desired_mechs->elements[i].length);
(void) memcpy(
arg.desired_mechs.GSS_OID_SET_val[i].GSS_OID_val,
desired_mechs->elements[i].elements,
desired_mechs->elements[i].length);
}
} else
arg.desired_mechs.GSS_OID_SET_len = 0;
arg.cred_usage = cred_usage;
/* call the remote procedure */
bzero((caddr_t)&res, sizeof (res));
client_stat = gss_acquire_cred_1(&arg, &res, clnt);
(void) gss_release_buffer(&minor_status_temp, &external_name);
if (desired_mechs != GSS_C_NULL_OID_SET) {
for (i = 0; i < desired_mechs->count; i++)
FREE(arg.desired_mechs.GSS_OID_SET_val[i].GSS_OID_val,
arg.desired_mechs.GSS_OID_SET_val[i].GSS_OID_len);
FREE(arg.desired_mechs.GSS_OID_SET_val,
arg.desired_mechs.GSS_OID_SET_len * sizeof (GSS_OID));
}
if (client_stat != RPC_SUCCESS) {
/*
* if the RPC call times out, null out all return arguments,
* set minor_status to its maximum value, and return
* GSS_S_FAILURE
*/
if (minor_status != NULL)
*minor_status = DEFAULT_MINOR_STAT;
if (output_cred_handle != NULL)
*output_cred_handle = 0;
if (actual_mechs != NULL)
*actual_mechs = NULL;
if (time_rec != NULL)
*time_rec = 0;
killgssd_handle(clnt);
GSSLOG0(1, "kgss_acquire_cred: RPC call times out\n");
return (GSS_S_FAILURE);
}
/* copy the rpc results into the return arguments */
if (minor_status != NULL)
*minor_status = res.minor_status;
if (output_cred_handle != NULL &&
(res.status == GSS_S_COMPLETE)) {
*output_cred_handle =
*((gssd_cred_id_t *)res.output_cred_handle.GSS_CRED_ID_T_val);
*gssd_cred_verifier = res.gssd_cred_verifier;
}
if (res.status == GSS_S_COMPLETE &&
res.actual_mechs.GSS_OID_SET_len != 0 &&
actual_mechs != NULL) {
*actual_mechs = (gss_OID_set) MALLOC(sizeof (gss_OID_set_desc));
(*actual_mechs)->count =
(int)res.actual_mechs.GSS_OID_SET_len;
(*actual_mechs)->elements = (gss_OID)
MALLOC(sizeof (gss_OID_desc) * (*actual_mechs)->count);
for (i = 0; i < (*actual_mechs)->count; i++) {
(*actual_mechs)->elements[i].length = (OM_uint32)
res.actual_mechs.GSS_OID_SET_val[i].GSS_OID_len;
(*actual_mechs)->elements[i].elements =
(void *) MALLOC((*actual_mechs)->elements[i].length);
(void) memcpy((*actual_mechs)->elements[i].elements,
res.actual_mechs.GSS_OID_SET_val[i].GSS_OID_val,
(*actual_mechs)->elements[i].length);
}
} else {
if (res.status == GSS_S_COMPLETE &&
actual_mechs != NULL)
(*actual_mechs) = NULL;
}
if (time_rec != NULL)
*time_rec = res.time_rec;
/*
* free the memory allocated for the results and return with the status
* received in the rpc call
*/
clnt_freeres(clnt, xdr_gss_acquire_cred_res, (caddr_t)&res);
killgssd_handle(clnt);
return (res.status);
}
OM_uint32
kgss_acquire_cred(minor_status,
desired_name,
time_req,
desired_mechs,
cred_usage,
output_cred_handle,
actual_mechs,
time_rec,
uid)
OM_uint32 *minor_status;
const gss_name_t desired_name;
OM_uint32 time_req;
const gss_OID_set desired_mechs;
int cred_usage;
gss_cred_id_t *output_cred_handle;
gss_OID_set *actual_mechs;
OM_uint32 *time_rec;
uid_t uid;
{
OM_uint32 err;
struct kgss_cred *kcred;
kcred = KGSS_CRED_ALLOC();
*output_cred_handle = (gss_cred_id_t)kcred;
err = kgss_acquire_cred_wrapped(minor_status, desired_name, time_req,
desired_mechs, cred_usage, &kcred->gssd_cred, actual_mechs,
time_rec, uid, &kcred->gssd_cred_verifier);
if (GSS_ERROR(err)) {
KGSS_CRED_FREE(kcred);
*output_cred_handle = GSS_C_NO_CREDENTIAL;
}
return (err);
}
OM_uint32
kgss_add_cred_wrapped(minor_status,
input_cred_handle,
gssd_cred_verifier,
desired_name,
desired_mech_type,
cred_usage,
initiator_time_req,
acceptor_time_req,
actual_mechs,
initiator_time_rec,
acceptor_time_rec,
uid)
OM_uint32 *minor_status;
gssd_cred_id_t input_cred_handle;
OM_uint32 gssd_cred_verifier;
gss_name_t desired_name;
gss_OID desired_mech_type;
int cred_usage;
int initiator_time_req;
int acceptor_time_req;
gss_OID_set *actual_mechs;
OM_uint32 *initiator_time_rec;
OM_uint32 *acceptor_time_rec;
uid_t uid;
{
CLIENT *clnt;
OM_uint32 minor_status_temp;
gss_buffer_desc external_name;
gss_OID name_type;
int i;
gss_add_cred_arg arg;
gss_add_cred_res res;
/*
* NULL the params here once
* If there are errors then we won't
* have to do it for every error
* case
*/
if (minor_status != NULL)
*minor_status = DEFAULT_MINOR_STAT;
if (actual_mechs != NULL)
*actual_mechs = NULL;
if (initiator_time_rec != NULL)
*initiator_time_rec = 0;
if (acceptor_time_rec != NULL)
*acceptor_time_rec = 0;
/* get the client handle to GSSD */
if ((clnt = getgssd_handle()) == NULL) {
GSSLOG(1, "kgss_add_cred: can't connect to server on %s\n",
server);
return (GSS_S_FAILURE);
}
/* convert the desired name from internal to external format */
if (gss_display_name(&minor_status_temp, desired_name, &external_name,
&name_type) != GSS_S_COMPLETE) {
*minor_status = (OM_uint32) minor_status_temp;
killgssd_handle(clnt);
GSSLOG0(1, "kgss_acquire_cred: display name failed\n");
return ((OM_uint32) GSS_S_FAILURE);
}
/* copy the procedure arguments into the rpc arg parameter */
arg.uid = (OM_uint32)uid;
arg.input_cred_handle.GSS_CRED_ID_T_len =
input_cred_handle == GSSD_NO_CREDENTIAL ?
0 : (uint_t)sizeof (gssd_cred_id_t);
arg.input_cred_handle.GSS_CRED_ID_T_val = (char *)&input_cred_handle;
arg.gssd_cred_verifier = gssd_cred_verifier;
arg.desired_name.GSS_BUFFER_T_len = (uint_t)external_name.length;
arg.desired_name.GSS_BUFFER_T_val = (char *)external_name.value;
arg.name_type.GSS_OID_len =
name_type == GSS_C_NULL_OID ?
0 : (uint_t)name_type->length;
arg.name_type.GSS_OID_val =
name_type == GSS_C_NULL_OID ?
(char *)NULL : (char *)name_type->elements;
arg.desired_mech_type.GSS_OID_len =
(uint_t)(desired_mech_type != GSS_C_NULL_OID ?
desired_mech_type->length : 0);
arg.desired_mech_type.GSS_OID_val =
(char *)(desired_mech_type != GSS_C_NULL_OID ?
desired_mech_type->elements : 0);
arg.cred_usage = cred_usage;
arg.initiator_time_req = initiator_time_req;
arg.acceptor_time_req = acceptor_time_req;
/* call the remote procedure */
bzero((caddr_t)&res, sizeof (res));
if (gss_add_cred_1(&arg, &res, clnt) != RPC_SUCCESS) {
/*
* if the RPC call times out, null out all return arguments,
* set minor_status to its maximum value, and return
* GSS_S_FAILURE
*/
killgssd_handle(clnt);
(void) gss_release_buffer(&minor_status_temp, &external_name);
GSSLOG0(1, "kgss_add_cred: RPC call times out\n");
return (GSS_S_FAILURE);
}
/* free the allocated memory for the flattened name */
(void) gss_release_buffer(&minor_status_temp, &external_name);
/* copy the rpc results into the return arguments */
if (minor_status != NULL)
*minor_status = res.minor_status;
if (res.status == GSS_S_COMPLETE &&
res.actual_mechs.GSS_OID_SET_len != 0 &&
actual_mechs != NULL) {
*actual_mechs = (gss_OID_set) MALLOC(sizeof (gss_OID_set_desc));
(*actual_mechs)->count =
(int)res.actual_mechs.GSS_OID_SET_len;
(*actual_mechs)->elements = (gss_OID)
MALLOC(sizeof (gss_OID_desc) * (*actual_mechs)->count);
for (i = 0; i < (*actual_mechs)->count; i++) {
(*actual_mechs)->elements[i].length = (OM_uint32)
res.actual_mechs.GSS_OID_SET_val[i].GSS_OID_len;
(*actual_mechs)->elements[i].elements =
(void *) MALLOC((*actual_mechs)->elements[i].length);
(void) memcpy((*actual_mechs)->elements[i].elements,
res.actual_mechs.GSS_OID_SET_val[i].GSS_OID_val,
(*actual_mechs)->elements[i].length);
}
} else {
if (res.status == GSS_S_COMPLETE && actual_mechs != NULL)
(*actual_mechs) = NULL;
}
if (initiator_time_rec != NULL)
*initiator_time_rec = res.acceptor_time_rec;
if (acceptor_time_rec != NULL)
*acceptor_time_rec = res.acceptor_time_rec;
/*
* free the memory allocated for the results and return with the status
* received in the rpc call
*/
clnt_freeres(clnt, xdr_gss_add_cred_res, (caddr_t)&res);
killgssd_handle(clnt);
return (res.status);
}
OM_uint32
kgss_add_cred(minor_status,
input_cred_handle,
desired_name,
desired_mech_type,
cred_usage,
initiator_time_req,
acceptor_time_req,
actual_mechs,
initiator_time_rec,
acceptor_time_rec,
uid)
OM_uint32 *minor_status;
gss_cred_id_t input_cred_handle;
gss_name_t desired_name;
gss_OID desired_mech_type;
int cred_usage;
int initiator_time_req;
int acceptor_time_req;
gss_OID_set *actual_mechs;
OM_uint32 *initiator_time_rec;
OM_uint32 *acceptor_time_rec;
uid_t uid;
{
OM_uint32 err;
OM_uint32 gssd_cred_verifier;
gssd_cred_id_t gssd_input_cred_handle;
if (input_cred_handle != GSS_C_NO_CREDENTIAL) {
gssd_cred_verifier = KCRED_TO_CREDV(input_cred_handle);
gssd_input_cred_handle = KCRED_TO_CRED(input_cred_handle);
} else {
gssd_input_cred_handle = GSSD_NO_CREDENTIAL;
}
err = kgss_add_cred_wrapped(minor_status, gssd_input_cred_handle,
gssd_cred_verifier, desired_name, desired_mech_type,
cred_usage, initiator_time_req, acceptor_time_req,
actual_mechs, initiator_time_rec,
acceptor_time_rec, uid);
return (err);
}
OM_uint32
kgss_release_cred_wrapped(minor_status,
cred_handle,
uid,
gssd_cred_verifier)
OM_uint32 *minor_status;
gssd_cred_id_t *cred_handle;
uid_t uid;
OM_uint32 gssd_cred_verifier;
{
CLIENT *clnt;
gss_release_cred_arg arg;
gss_release_cred_res res;
/* get the client handle to GSSD */
if ((clnt = getgssd_handle()) == NULL) {
GSSLOG(1, "kgss_release_cred: can't connect to server on %s\n",
server);
return (GSS_S_FAILURE);
}
/* copy the procedure arguments into the rpc arg parameter */
arg.uid = (OM_uint32)uid;
arg.gssd_cred_verifier = gssd_cred_verifier;
if (cred_handle != NULL) {
arg.cred_handle.GSS_CRED_ID_T_len =
(uint_t)sizeof (gssd_cred_id_t);
arg.cred_handle.GSS_CRED_ID_T_val = (char *)cred_handle;
} else
arg.cred_handle.GSS_CRED_ID_T_len = 0;
/* call the remote procedure */
bzero((caddr_t)&res, sizeof (res));
if (gss_release_cred_1(&arg, &res, clnt) != RPC_SUCCESS) {
/*
* if the RPC call times out, null out all return arguments, set
* minor_status to its maximum value, and return GSS_S_FAILURE
*/
if (minor_status != NULL)
*minor_status = DEFAULT_MINOR_STAT;
if (cred_handle != NULL)
*cred_handle = 0;
killgssd_handle(clnt);
GSSLOG0(1, "kgss_release_cred: RPC call times out\n");
return (GSS_S_FAILURE);
}
/* if the release succeeded, null out the cred_handle */
if (res.status == GSS_S_COMPLETE && cred_handle != NULL)
*cred_handle = 0;
/* copy the rpc results into the return arguments */
if (minor_status != NULL)
*minor_status = res.minor_status;
/* return with status returned in rpc call */
killgssd_handle(clnt);
return (res.status);
}
OM_uint32
kgss_release_cred(minor_status,
cred_handle,
uid)
OM_uint32 *minor_status;
gss_cred_id_t *cred_handle;
uid_t uid;
{
OM_uint32 err;
struct kgss_cred *kcred;
if (*cred_handle == GSS_C_NO_CREDENTIAL)
return (GSS_S_COMPLETE);
else
kcred = KCRED_TO_KGSS_CRED(*cred_handle);
err = kgss_release_cred_wrapped(minor_status, &kcred->gssd_cred,
uid, kcred->gssd_cred_verifier);
KGSS_CRED_FREE(kcred);
*cred_handle = GSS_C_NO_CREDENTIAL;
return (err);
}
static OM_uint32
kgss_init_sec_context_wrapped(
OM_uint32 *minor_status,
const gssd_cred_id_t claimant_cred_handle,
OM_uint32 gssd_cred_verifier,
gssd_ctx_id_t *context_handle,
OM_uint32 *gssd_context_verifier,
const gss_name_t target_name,
const gss_OID mech_type,
int req_flags,
OM_uint32 time_req,
const gss_channel_bindings_t input_chan_bindings,
const gss_buffer_t input_token,
gss_OID *actual_mech_type,
gss_buffer_t output_token,
int *ret_flags,
OM_uint32 *time_rec,
uid_t uid)
{
CLIENT *clnt;
OM_uint32 minor_status_temp;
gss_buffer_desc external_name;
gss_OID name_type;
gss_init_sec_context_arg arg;
gss_init_sec_context_res res;
/* get the client handle to GSSD */
if ((clnt = getgssd_handle()) == NULL) {
GSSLOG(1,
"kgss_init_sec_context: can't connect to server on %s\n",
server);
return (GSS_S_FAILURE);
}
/* convert the target name from internal to external format */
if (gss_display_name(&minor_status_temp, target_name,
&external_name, &name_type) != GSS_S_COMPLETE) {
*minor_status = (OM_uint32) minor_status_temp;
killgssd_handle(clnt);
GSSLOG0(1, "kgss_init_sec_context: can't display name\n");
return ((OM_uint32) GSS_S_FAILURE);
}
/* copy the procedure arguments into the rpc arg parameter */
arg.uid = (OM_uint32)uid;
arg.context_handle.GSS_CTX_ID_T_len =
*context_handle == GSSD_NO_CONTEXT ?
0 : (uint_t)sizeof (gssd_ctx_id_t);
arg.context_handle.GSS_CTX_ID_T_val = (char *)context_handle;
arg.gssd_context_verifier = *gssd_context_verifier;
arg.claimant_cred_handle.GSS_CRED_ID_T_len =
claimant_cred_handle == GSSD_NO_CREDENTIAL ?
0 : (uint_t)sizeof (gssd_cred_id_t);
arg.claimant_cred_handle.GSS_CRED_ID_T_val =
(char *)&claimant_cred_handle;
arg.gssd_cred_verifier = gssd_cred_verifier;
arg.target_name.GSS_BUFFER_T_len = (uint_t)external_name.length;
arg.target_name.GSS_BUFFER_T_val = (char *)external_name.value;
arg.name_type.GSS_OID_len =
name_type == GSS_C_NULL_OID ? 0 : (uint_t)name_type->length;
arg.name_type.GSS_OID_val =
name_type == GSS_C_NULL_OID ?
(char *)NULL : (char *)name_type->elements;
arg.mech_type.GSS_OID_len = (uint_t)(mech_type != GSS_C_NULL_OID ?
mech_type->length : 0);
arg.mech_type.GSS_OID_val = (char *)(mech_type != GSS_C_NULL_OID ?
mech_type->elements : 0);
arg.req_flags = req_flags;
arg.time_req = time_req;
if (input_chan_bindings != GSS_C_NO_CHANNEL_BINDINGS) {
arg.input_chan_bindings.present = YES;
arg.input_chan_bindings.initiator_addrtype =
input_chan_bindings->initiator_addrtype;
arg.input_chan_bindings.initiator_address.GSS_BUFFER_T_len =
(uint_t)input_chan_bindings->initiator_address.length;
arg.input_chan_bindings.initiator_address.GSS_BUFFER_T_val =
(void *)input_chan_bindings->initiator_address.value;
arg.input_chan_bindings.acceptor_addrtype =
input_chan_bindings->acceptor_addrtype;
arg.input_chan_bindings.acceptor_address.GSS_BUFFER_T_len =
(uint_t)input_chan_bindings->acceptor_address.length;
arg.input_chan_bindings.acceptor_address.GSS_BUFFER_T_val =
(void *)input_chan_bindings->acceptor_address.value;
arg.input_chan_bindings.application_data.GSS_BUFFER_T_len =
(uint_t)input_chan_bindings->application_data.length;
arg.input_chan_bindings.application_data.GSS_BUFFER_T_val =
(void *)input_chan_bindings->application_data.value;
} else {
arg.input_chan_bindings.present = NO;
arg.input_chan_bindings.initiator_addrtype = 0;
arg.input_chan_bindings.initiator_address.GSS_BUFFER_T_len = 0;
arg.input_chan_bindings.initiator_address.GSS_BUFFER_T_val = 0;
arg.input_chan_bindings.acceptor_addrtype = 0;
arg.input_chan_bindings.acceptor_address.GSS_BUFFER_T_len = 0;
arg.input_chan_bindings.acceptor_address.GSS_BUFFER_T_val = 0;
arg.input_chan_bindings.application_data.GSS_BUFFER_T_len = 0;
arg.input_chan_bindings.application_data.GSS_BUFFER_T_val = 0;
}
arg.input_token.GSS_BUFFER_T_len =
(uint_t)(input_token != GSS_C_NO_BUFFER ? input_token->length : 0);
arg.input_token.GSS_BUFFER_T_val =
(char *)(input_token != GSS_C_NO_BUFFER ? input_token->value : 0);
/* call the remote procedure */
bzero((caddr_t)&res, sizeof (res));
if (gss_init_sec_context_1(&arg, &res, clnt) != RPC_SUCCESS) {
/*
* if the RPC call times out, null out all return arguments, set
* minor_status to its maximum value, and return GSS_S_FAILURE
*/
if (minor_status != NULL)
*minor_status = DEFAULT_MINOR_STAT;
if (actual_mech_type != NULL)
*actual_mech_type = NULL;
if (output_token != NULL)
output_token->length = 0;
if (ret_flags != NULL)
*ret_flags = 0;
if (time_rec != NULL)
*time_rec = 0;
killgssd_handle(clnt);
(void) gss_release_buffer(&minor_status_temp, &external_name);
GSSLOG0(1, "kgss_init_sec_context: RPC call times out\n");
return (GSS_S_FAILURE);
}
/* free the allocated memory for the flattened name */
(void) gss_release_buffer(&minor_status_temp, &external_name);
if (minor_status != NULL)
*minor_status = res.minor_status;
if (output_token != NULL && res.output_token.GSS_BUFFER_T_val != NULL) {
output_token->length =
(size_t)res.output_token.GSS_BUFFER_T_len;
output_token->value =
(void *)MALLOC(output_token->length);
(void) memcpy(output_token->value,
res.output_token.GSS_BUFFER_T_val, output_token->length);
}
/* if the call was successful, copy out the results */
if (res.status == (OM_uint32) GSS_S_COMPLETE ||
res.status == (OM_uint32) GSS_S_CONTINUE_NEEDED) {
/*
* if the return code is GSS_S_CONTINUE_NEEDED
* ignore all return parameters except for
* status codes, output token and context handle.
*/
*context_handle =
*((gssd_ctx_id_t *)res.context_handle.GSS_CTX_ID_T_val);
*gssd_context_verifier = res.gssd_context_verifier;
if (res.status == GSS_S_COMPLETE) {
if (actual_mech_type != NULL) {
*actual_mech_type =
(gss_OID) MALLOC(sizeof (gss_OID_desc));
(*actual_mech_type)->length =
(OM_UINT32)res.actual_mech_type.GSS_OID_len;
(*actual_mech_type)->elements =
(void *)MALLOC((*actual_mech_type)->length);
(void) memcpy((*actual_mech_type)->elements,
(void *)res.actual_mech_type.GSS_OID_val,
(*actual_mech_type)->length);
}
if (ret_flags != NULL)
*ret_flags = res.ret_flags;
if (time_rec != NULL)
*time_rec = res.time_rec;
}
}
/*
* free the memory allocated for the results and return with the status
* received in the rpc call
*/
clnt_freeres(clnt, xdr_gss_init_sec_context_res, (caddr_t)&res);
killgssd_handle(clnt);
return (res.status);
}
static struct gss_config default_gc = {
{ 0, NULL},
NULL,
NULL,
0,
kgss_unseal_wrapped,
NULL, /* kgss_delete_sec_context_wrapped */
kgss_seal_wrapped,
NULL, /* kgss_import_sec_context */
kgss_sign_wrapped,
kgss_verify_wrapped
};
void
kgss_free_oid(gss_OID oid)
{
FREE(oid->elements, oid->length);
FREE(oid, sizeof (gss_OID_desc));
}
OM_uint32
kgss_init_sec_context(
OM_uint32 *minor_status,
const gss_cred_id_t claimant_cred_handle,
gss_ctx_id_t *context_handle,
const gss_name_t target_name,
const gss_OID mech_type,
int req_flags,
OM_uint32 time_req,
const gss_channel_bindings_t input_chan_bindings,
const gss_buffer_t input_token,
gss_OID *actual_mech_type,
gss_buffer_t output_token,
int *ret_flags,
OM_uint32 *time_rec,
uid_t uid)
{
OM_uint32 err;
struct kgss_ctx *kctx;
gss_OID amt;
gssd_cred_id_t gssd_cl_cred_handle;
OM_uint32 gssd_cred_verifier;
/*
* If this is an initial call, we'll need to create the
* wrapper struct that contains kernel state information, and
* a reference to the handle from gssd.
*/
if (*context_handle == GSS_C_NO_CONTEXT) {
kctx = KGSS_ALLOC();
/*
* The default gss-mechanism struct as pointers to
* the sign/seal/verify/unseal routines that make
* upcalls to gssd.
*/
kctx->mech = &default_gc;
kctx->gssd_ctx = GSSD_NO_CONTEXT;
*context_handle = (gss_ctx_id_t)kctx;
} else
kctx = (struct kgss_ctx *)*context_handle;
if (claimant_cred_handle != GSS_C_NO_CREDENTIAL) {
gssd_cred_verifier = KCRED_TO_CREDV(claimant_cred_handle);
gssd_cl_cred_handle = KCRED_TO_CRED(claimant_cred_handle);
} else {
gssd_cl_cred_handle = GSSD_NO_CREDENTIAL;
}
/*
* We need to know the resulting mechanism oid, so allocate
* it if the caller won't.
*/
if (actual_mech_type == NULL)
actual_mech_type = &amt;
err = kgss_init_sec_context_wrapped(minor_status, gssd_cl_cred_handle,
gssd_cred_verifier, &kctx->gssd_ctx, &kctx->gssd_ctx_verifier,
target_name, mech_type, req_flags, time_req,
input_chan_bindings, input_token, actual_mech_type,
output_token, ret_flags, time_rec, uid);
if (GSS_ERROR(err)) {
KGSS_FREE(kctx);
*context_handle = GSS_C_NO_CONTEXT;
} else if (err == GSS_S_COMPLETE) {
/*
* Now check if there is a kernel module for this
* mechanism OID. If so, set the gss_mechanism structure
* in the wrapper context to point to the kernel mech.
*/
__kgss_reset_mech(&kctx->mech, *actual_mech_type);
/*
* If the mech oid was allocated for us, free it.
*/
if (&amt == actual_mech_type) {
kgss_free_oid(amt);
}
}
return (err);
}
static OM_uint32
kgss_accept_sec_context_wrapped(
OM_uint32 *minor_status,
gssd_ctx_id_t *context_handle,
OM_uint32 *gssd_context_verifier,
const gssd_cred_id_t verifier_cred_handle,
OM_uint32 gssd_cred_verifier,
const gss_buffer_t input_token,
const gss_channel_bindings_t input_chan_bindings,
gss_buffer_t src_name,
gss_OID *mech_type,
gss_buffer_t output_token,
int *ret_flags,
OM_uint32 *time_rec,
gss_cred_id_t *delegated_cred_handle,
uid_t uid)
{
CLIENT *clnt;
gss_accept_sec_context_arg arg;
gss_accept_sec_context_res res;
struct kgss_cred *kcred;
/* get the client handle to GSSD */
if ((clnt = getgssd_handle()) == NULL) {
GSSLOG(1,
"kgss_accept_sec_context: can't connect to server on %s\n",
server);
return (GSS_S_FAILURE);
}
/* copy the procedure arguments into the rpc arg parameter */
arg.uid = (OM_uint32)uid;
arg.context_handle.GSS_CTX_ID_T_len =
*context_handle == GSSD_NO_CONTEXT ?
0 : (uint_t)sizeof (gssd_ctx_id_t);
arg.context_handle.GSS_CTX_ID_T_val = (char *)context_handle;
arg.gssd_context_verifier = *gssd_context_verifier;
arg.verifier_cred_handle.GSS_CRED_ID_T_len =
verifier_cred_handle == GSSD_NO_CREDENTIAL ?
0 : (uint_t)sizeof (gssd_cred_id_t);
arg.verifier_cred_handle.GSS_CRED_ID_T_val =
(char *)&verifier_cred_handle;
arg.gssd_cred_verifier = gssd_cred_verifier;
arg.input_token_buffer.GSS_BUFFER_T_len =
(uint_t)(input_token != GSS_C_NO_BUFFER ? input_token->length : 0);
arg.input_token_buffer.GSS_BUFFER_T_val =
(char *)(input_token != GSS_C_NO_BUFFER ? input_token->value : 0);
if (input_chan_bindings != GSS_C_NO_CHANNEL_BINDINGS) {
arg.input_chan_bindings.present = YES;
arg.input_chan_bindings.initiator_addrtype =
input_chan_bindings->initiator_addrtype;
arg.input_chan_bindings.initiator_address.GSS_BUFFER_T_len =
(uint_t)input_chan_bindings->initiator_address.length;
arg.input_chan_bindings.initiator_address.GSS_BUFFER_T_val =
(void *)input_chan_bindings->initiator_address.value;
arg.input_chan_bindings.acceptor_addrtype =
input_chan_bindings->acceptor_addrtype;
arg.input_chan_bindings.acceptor_address.GSS_BUFFER_T_len =
(uint_t)input_chan_bindings->acceptor_address.length;
arg.input_chan_bindings.acceptor_address.GSS_BUFFER_T_val =
(void *)input_chan_bindings->acceptor_address.value;
arg.input_chan_bindings.application_data.GSS_BUFFER_T_len =
(uint_t)input_chan_bindings->application_data.length;
arg.input_chan_bindings.application_data.GSS_BUFFER_T_val =
(void *)input_chan_bindings->application_data.value;
} else {
arg.input_chan_bindings.present = NO;
arg.input_chan_bindings.initiator_addrtype = 0;
arg.input_chan_bindings.initiator_address.GSS_BUFFER_T_len = 0;
arg.input_chan_bindings.initiator_address.GSS_BUFFER_T_val = 0;
arg.input_chan_bindings.acceptor_addrtype = 0;
arg.input_chan_bindings.acceptor_address.GSS_BUFFER_T_len = 0;
arg.input_chan_bindings.acceptor_address.GSS_BUFFER_T_val = 0;
arg.input_chan_bindings.application_data.GSS_BUFFER_T_len = 0;
arg.input_chan_bindings.application_data.GSS_BUFFER_T_val = 0;
}
/* set the return parameters in case of errors.... */
if (minor_status != NULL)
*minor_status = DEFAULT_MINOR_STAT;
if (src_name != NULL) {
src_name->length = 0;
src_name->value = NULL;
}
if (mech_type != NULL)
*mech_type = NULL;
if (output_token != NULL)
output_token->length = 0;
if (ret_flags != NULL)
*ret_flags = 0;
if (time_rec != NULL)
*time_rec = 0;
if (delegated_cred_handle != NULL)
*delegated_cred_handle = NULL;
/* call the remote procedure */
bzero((caddr_t)&res, sizeof (res));
if (gss_accept_sec_context_1(&arg, &res, clnt) != RPC_SUCCESS) {
killgssd_handle(clnt);
GSSLOG0(1, "kgss_accept_sec_context: RPC call times out\n");
return (GSS_S_FAILURE);
}
if (minor_status != NULL)
*minor_status = res.minor_status;
if (output_token != NULL && res.output_token.GSS_BUFFER_T_val != NULL) {
output_token->length = res.output_token.GSS_BUFFER_T_len;
output_token->value = (void *)MALLOC(output_token->length);
(void) memcpy(output_token->value,
res.output_token.GSS_BUFFER_T_val, output_token->length);
}
/* if the call was successful, copy out the results */
if (res.status == (OM_uint32)GSS_S_COMPLETE ||
res.status == (OM_uint32)GSS_S_CONTINUE_NEEDED) {
/*
* the only parameters that are ready when we
* get GSS_S_CONTINUE_NEEDED are: minor, ctxt_handle,
* and the output token to send to the peer.
*/
*context_handle = *((gssd_ctx_id_t *)
res.context_handle.GSS_CTX_ID_T_val);
*gssd_context_verifier = res.gssd_context_verifier;
/* these other parameters are only ready upon GSS_S_COMPLETE */
if (res.status == (OM_uint32)GSS_S_COMPLETE) {
if (src_name != NULL) {
src_name->length =
res.src_name.GSS_BUFFER_T_len;
src_name->value = res.src_name.GSS_BUFFER_T_val;
res.src_name.GSS_BUFFER_T_val = NULL;
res.src_name.GSS_BUFFER_T_len = 0;
}
/*
* move mech type returned to mech_type
* for gss_import_name_for_mech()
*/
if (mech_type != NULL) {
*mech_type =
(gss_OID)MALLOC(sizeof (gss_OID_desc));
(*mech_type)->length =
(OM_UINT32)res.mech_type.GSS_OID_len;
(*mech_type)->elements =
(void *)MALLOC((*mech_type)->length);
(void) memcpy((*mech_type)->elements,
res.mech_type.GSS_OID_val,
(*mech_type)->length);
}
if (ret_flags != NULL)
*ret_flags = res.ret_flags;
if (time_rec != NULL)
*time_rec = res.time_rec;
if ((delegated_cred_handle != NULL) &&
(res.delegated_cred_handle.GSS_CRED_ID_T_len
!= 0)) {
kcred = KGSS_CRED_ALLOC();
kcred->gssd_cred =
*((gssd_cred_id_t *)
res.delegated_cred_handle.GSS_CRED_ID_T_val);
kcred->gssd_cred_verifier =
res.gssd_context_verifier;
*delegated_cred_handle = (gss_cred_id_t)kcred;
}
}
}
/*
* free the memory allocated for the results and return with the status
* received in the rpc call
*/
clnt_freeres(clnt, xdr_gss_accept_sec_context_res, (caddr_t)&res);
killgssd_handle(clnt);
return (res.status);
}
OM_uint32
kgss_accept_sec_context(
OM_uint32 *minor_status,
gss_ctx_id_t *context_handle,
const gss_cred_id_t verifier_cred_handle,
const gss_buffer_t input_token,
const gss_channel_bindings_t input_chan_bindings,
gss_buffer_t src_name,
gss_OID *mech_type,
gss_buffer_t output_token,
int *ret_flags,
OM_uint32 *time_rec,
gss_cred_id_t *delegated_cred_handle,
uid_t uid)
{
OM_uint32 err;
struct kgss_ctx *kctx;
gss_OID mt;
OM_uint32 gssd_cred_verifier;
gssd_cred_id_t gssd_ver_cred_handle;
/*
* See kgss_init_sec_context() to get an idea of what is going
* on here.
*/
if (mech_type == NULL)
mech_type = &mt;
if (*context_handle == GSS_C_NO_CONTEXT) {
kctx = KGSS_ALLOC();
kctx->mech = &default_gc;
kctx->gssd_ctx = GSSD_NO_CONTEXT;
*context_handle = (gss_ctx_id_t)kctx;
} else
kctx = (struct kgss_ctx *)*context_handle;
if (verifier_cred_handle != GSS_C_NO_CREDENTIAL) {
gssd_cred_verifier = KCRED_TO_CREDV(verifier_cred_handle);
gssd_ver_cred_handle = KCRED_TO_CRED(verifier_cred_handle);
} else {
gssd_ver_cred_handle = GSSD_NO_CREDENTIAL;
}
err = kgss_accept_sec_context_wrapped(minor_status,
&kctx->gssd_ctx, &kctx->gssd_ctx_verifier,
gssd_ver_cred_handle, gssd_cred_verifier,
input_token, input_chan_bindings, src_name,
mech_type, output_token, ret_flags,
time_rec, delegated_cred_handle, uid);
if (GSS_ERROR(err)) {
KGSS_FREE(kctx);
*context_handle = GSS_C_NO_CONTEXT;
} else if (err == GSS_S_COMPLETE) {
__kgss_reset_mech(&kctx->mech, *mech_type);
/*
* If the mech oid was allocated for us, free it.
*/
if (&mt == mech_type) {
kgss_free_oid(mt);
}
}
return (err);
}
OM_uint32
kgss_process_context_token(minor_status,
context_handle,
token_buffer,
uid)
OM_uint32 *minor_status;
const gss_ctx_id_t context_handle;
gss_buffer_t token_buffer;
uid_t uid;
{
CLIENT *clnt;
OM_uint32 gssd_context_verifier;
gssd_ctx_id_t gssd_ctx_handle;
gss_process_context_token_arg arg;
gss_process_context_token_res res;
gssd_context_verifier = KGSS_CTX_TO_GSSD_CTXV(context_handle);
gssd_ctx_handle = (gssd_ctx_id_t)KGSS_CTX_TO_GSSD_CTX(context_handle);
/* get the client handle to GSSD */
if ((clnt = getgssd_handle()) == NULL) {
GSSLOG(1,
"kgss_process_context_token: can't connect to server on %s\n",
server);
return (GSS_S_FAILURE);
}
/* copy the procedure arguments into the rpc arg parameter */
arg.uid = (OM_uint32) uid;
arg.context_handle.GSS_CTX_ID_T_len = (uint_t)sizeof (gssd_ctx_id_t);
arg.context_handle.GSS_CTX_ID_T_val = (char *)&gssd_ctx_handle;
arg.gssd_context_verifier = gssd_context_verifier;
arg.token_buffer.GSS_BUFFER_T_len = (uint_t)token_buffer->length;
arg.token_buffer.GSS_BUFFER_T_val = (char *)token_buffer->value;
/* call the remote procedure */
bzero(&res, sizeof (res));
if (gss_process_context_token_1(&arg, &res, clnt) != RPC_SUCCESS) {
/*
* if the RPC call times out, null out all return arguments, set
* minor_status to its maximum value, and return GSS_S_FAILURE
*/
if (minor_status != NULL)
*minor_status = DEFAULT_MINOR_STAT;
GSSLOG0(1, "kgss_process_context_token: RPC call times out\n");
killgssd_handle(clnt);
return (GSS_S_FAILURE);
}
/* copy the rpc results into the return arguments */
if (minor_status != NULL)
*minor_status = res.minor_status;
/* return with status returned in rpc call */
killgssd_handle(clnt);
return (res.status);
}
/*ARGSUSED*/
static OM_uint32
kgss_delete_sec_context_wrapped(void *private,
OM_uint32 *minor_status,
gssd_ctx_id_t *context_handle,
gss_buffer_t output_token,
OM_uint32 gssd_context_verifier)
{
CLIENT *clnt;
gss_delete_sec_context_arg arg;
gss_delete_sec_context_res res;
/* get the client handle to GSSD */
if ((clnt = getgssd_handle()) == NULL) {
GSSLOG(1,
"kgss_delete_sec_context: can't connect to server on %s\n",
server);
return (GSS_S_FAILURE);
}
/* copy the procedure arguments into the rpc arg parameter */
arg.context_handle.GSS_CTX_ID_T_len =
*context_handle == GSSD_NO_CONTEXT ?
0 : (uint_t)sizeof (gssd_ctx_id_t);
arg.context_handle.GSS_CTX_ID_T_val = (char *)context_handle;
arg.gssd_context_verifier = gssd_context_verifier;
/* call the remote procedure */
bzero((caddr_t)&res, sizeof (res));
if (gss_delete_sec_context_1(&arg, &res, clnt) != RPC_SUCCESS) {
/*
* if the RPC call times out, null out all return arguments, set
* minor_status to its maximum value, and return GSS_S_FAILURE
*/
if (minor_status != NULL)
*minor_status = DEFAULT_MINOR_STAT;
if (context_handle != NULL)
*context_handle = 0;
if (output_token != NULL)
output_token->length = 0;
killgssd_handle(clnt);
GSSLOG0(1, "kgssd_delete_sec_context: RPC call times out\n");
return (GSS_S_FAILURE);
}
/* copy the rpc results into the return arguments */
if (minor_status != NULL)
*minor_status = res.minor_status;
if (res.context_handle.GSS_CTX_ID_T_len == 0)
*context_handle = 0;
else
*context_handle =
*((gssd_ctx_id_t *)res.context_handle.GSS_CTX_ID_T_val);
if (output_token != NULL) {
output_token->length = res.output_token.GSS_BUFFER_T_len;
output_token->value = res.output_token.GSS_BUFFER_T_val;
res.output_token.GSS_BUFFER_T_len = 0;
res.output_token.GSS_BUFFER_T_val = NULL;
}
/*
* free the memory allocated for the results and return with the status
* received in the rpc call
*/
clnt_freeres(clnt, xdr_gss_delete_sec_context_res, (caddr_t)&res);
killgssd_handle(clnt);
return (res.status);
}
OM_uint32
kgss_delete_sec_context(
OM_uint32 *minor_status,
gss_ctx_id_t *context_handle,
gss_buffer_t output_token)
{
OM_uint32 err;
struct kgss_ctx *kctx;
if (*context_handle == GSS_C_NO_CONTEXT) {
GSSLOG0(8, "kgss_delete_sec_context: Null context handle \n");
return (GSS_S_COMPLETE);
} else
kctx = (struct kgss_ctx *)*context_handle;
if (kctx->ctx_imported == FALSE) {
if (kctx->gssd_ctx == GSSD_NO_CONTEXT) {
KGSS_FREE(kctx);
*context_handle = GSS_C_NO_CONTEXT;
return (GSS_S_COMPLETE);
}
err = kgss_delete_sec_context_wrapped(
KCTX_TO_PRIVATE(*context_handle),
minor_status,
&kctx->gssd_ctx,
output_token,
kctx->gssd_ctx_verifier);
} else {
if (kctx->gssd_i_ctx == (gss_ctx_id_t)GSS_C_NO_CONTEXT) {
KGSS_FREE(kctx);
*context_handle = GSS_C_NO_CONTEXT;
return (GSS_S_COMPLETE);
}
err = KGSS_DELETE_SEC_CONTEXT(minor_status, kctx,
&kctx->gssd_i_ctx, output_token);
}
KGSS_FREE(kctx);
*context_handle = GSS_C_NO_CONTEXT;
return (err);
}
OM_uint32
kgss_export_sec_context_wrapped(minor_status,
context_handle,
output_token,
gssd_context_verifier)
OM_uint32 *minor_status;
gssd_ctx_id_t *context_handle;
gss_buffer_t output_token;
OM_uint32 gssd_context_verifier;
{
CLIENT *clnt;
gss_export_sec_context_arg arg;
gss_export_sec_context_res res;
/* get the client handle to GSSD */
if ((clnt = getgssd_handle()) == NULL) {
GSSLOG(1, "kgss_export_sec_context_wrapped :"
" can't connect to server on %s\n", server);
return (GSS_S_FAILURE);
}
/* copy the procedure arguments into the rpc arg parameter */
arg.context_handle.GSS_CTX_ID_T_len = (uint_t)sizeof (gssd_ctx_id_t);
arg.context_handle.GSS_CTX_ID_T_val = (char *)context_handle;
arg.gssd_context_verifier = gssd_context_verifier;
/* call the remote procedure */
(void) memset(&res, 0, sizeof (res));
if (gss_export_sec_context_1(&arg, &res, clnt) != RPC_SUCCESS) {
/*
* if the RPC call times out, null out all return arguments,
* set minor_status to its maximum value, and return
* GSS_S_FAILURE
*/
if (minor_status != NULL)
*minor_status = DEFAULT_MINOR_STAT;
if (context_handle != NULL)
*context_handle = 0;
if (output_token != NULL)
output_token->length = 0;
killgssd_handle(clnt);
GSSLOG0(1,
"kgss_export_sec_context_wrapped: RPC call times out\n");
return (GSS_S_FAILURE);
}
/* copy the rpc results into the return arguments */
if (minor_status != NULL)
*minor_status = res.minor_status;
if (res.context_handle.GSS_CTX_ID_T_len == 0)
*context_handle = 0;
else
*context_handle =
*((gssd_ctx_id_t *)res.context_handle.GSS_CTX_ID_T_val);
if (output_token != NULL) {
output_token->length = res.output_token.GSS_BUFFER_T_len;
output_token->value =
(void *) MALLOC(output_token->length);
(void) memcpy(output_token->value,
res.output_token.GSS_BUFFER_T_val,
output_token->length);
}
/*
* free the memory allocated for the results and return with the status
* received in the rpc call
*/
clnt_freeres(clnt, xdr_gss_export_sec_context_res, (caddr_t)&res);
killgssd_handle(clnt);
return (res.status);
}
OM_uint32
kgss_export_sec_context(minor_status,
context_handle,
output_token)
OM_uint32 *minor_status;
gss_ctx_id_t context_handle;
gss_buffer_t output_token;
{
struct kgss_ctx *kctx;
if (context_handle == GSS_C_NO_CONTEXT)
return (GSS_S_FAILURE);
else
kctx = (struct kgss_ctx *)context_handle;
/*
* If there is a kernel module then import_sec context must be
* supported and we make an upcall to export_sec_context.
* If there is no kernel module then we return an error
*/
*minor_status = 0;
if (kctx->mech->gss_import_sec_context) {
GSSLOG0(8, "kgss_export_sec_context: Kernel mod available \n");
return (kgss_export_sec_context_wrapped(minor_status,
&kctx->gssd_ctx,
output_token,
kctx->gssd_ctx_verifier));
} else {
/*
* This is not the right error value; instead of
* inventing new error we return GSS_S_NAME_NOT_MN
* This error is not returned by the export routine
*/
GSSLOG0(8, "kgss_export_sec_context: Kernel mod "
"unavailable \n");
return (GSS_S_NAME_NOT_MN);
}
}
OM_uint32
kgss_import_sec_context(minor_status,
interprocess_token,
context_handle)
OM_uint32 * minor_status;
const gss_buffer_t interprocess_token;
gss_ctx_id_t context_handle;
{
OM_uint32 status;
struct kgss_ctx *kctx;
size_t length;
char *p;
gss_buffer_desc token;
gss_ctx_id_t internal_ctx_id;
kctx = (struct kgss_ctx *)context_handle;
if (kctx->gssd_ctx != GSSD_NO_CONTEXT) {
return (GSS_S_FAILURE);
}
if (!(KCTX_TO_MECH(context_handle)->gss_import_sec_context)) {
/*
* This should never happen
* If Kernel import sec context does not exist the export
* sec context should have caught this and returned an error
* and the caller should not have called this routine
*/
GSSLOG0(1, "import_sec_context called improperly\n");
return (GSS_S_FAILURE);
}
*minor_status = 0;
if (interprocess_token->length == 0 || interprocess_token->value == 0)
return (GSS_S_DEFECTIVE_TOKEN);
status = GSS_S_FAILURE;
p = interprocess_token->value;
length = *p++;
length = (length << 8) + *p++;
length = (length << 8) + *p++;
length = (length << 8) + *p++;
p += length;
token.length = interprocess_token->length - 4 - length;
token.value = p;
/*
* select the approprate underlying mechanism routine and
* call it.
*/
status = KGSS_IMPORT_SEC_CONTEXT(minor_status, &token, kctx,
&internal_ctx_id);
if (status == GSS_S_COMPLETE) {
KCTX_TO_I_CTX(kctx) = internal_ctx_id;
kctx->ctx_imported = TRUE;
return (GSS_S_COMPLETE);
} else
return (status);
}
/*ARGSUSED*/
OM_uint32
kgss_context_time(minor_status,
context_handle,
time_rec,
uid)
OM_uint32 *minor_status;
const gss_ctx_id_t context_handle;
OM_uint32 *time_rec;
uid_t uid;
{
return (GSS_S_FAILURE);
}
/*ARGSUSED*/
static OM_uint32
kgss_sign_wrapped(void *private,
OM_uint32 *minor_status,
const gss_ctx_id_t ctx_handle,
int qop_req,
const gss_buffer_t message_buffer,
gss_buffer_t msg_token,
OM_uint32 gssd_context_verifier)
{
CLIENT *clnt;
gssd_ctx_id_t context_handle;
gss_sign_arg arg;
gss_sign_res res;
context_handle = (gssd_ctx_id_t)KCTX_TO_GSSD_CTX(ctx_handle);
/* get the client handle to GSSD */
if ((clnt = getgssd_handle()) == NULL) {
GSSLOG(1, "kgss_sign: can't connect to server on %s\n", server);
return (GSS_S_FAILURE);
}
/* copy the procedure arguments into the rpc arg parameter */
arg.context_handle.GSS_CTX_ID_T_len = (uint_t)sizeof (gssd_ctx_id_t);
arg.context_handle.GSS_CTX_ID_T_val = (char *)&context_handle;
arg.context_handle.GSS_CTX_ID_T_len = (uint_t)sizeof (gssd_ctx_id_t);
arg.context_handle.GSS_CTX_ID_T_val = (char *)&context_handle;
arg.gssd_context_verifier = gssd_context_verifier;
arg.qop_req = qop_req;
arg.message_buffer.GSS_BUFFER_T_len = (uint_t)message_buffer->length;
arg.message_buffer.GSS_BUFFER_T_val = (char *)message_buffer->value;
/* call the remote procedure */
bzero((caddr_t)&res, sizeof (res));
if (gss_sign_1(&arg, &res, clnt) != RPC_SUCCESS) {
/*
* if the RPC call times out, null out all return arguments, set
* minor_status to its maximum value, and return GSS_S_FAILURE
*/
if (minor_status != NULL)
*minor_status = DEFAULT_MINOR_STAT;
if (msg_token != NULL)
msg_token->length = 0;
killgssd_handle(clnt);
GSSLOG0(1, "kgss_sign: RPC call times out\n");
return (GSS_S_FAILURE);
}
/* copy the rpc results into the return arguments */
if (minor_status != NULL)
*minor_status = res.minor_status;
if (msg_token != NULL) {
msg_token->length = res.msg_token.GSS_BUFFER_T_len;
msg_token->value = (void *) MALLOC(msg_token->length);
(void) memcpy(msg_token->value, res.msg_token.GSS_BUFFER_T_val,
msg_token->length);
}
/*
* free the memory allocated for the results and return with the status
* received in the rpc call
*/
clnt_freeres(clnt, xdr_gss_sign_res, (caddr_t)&res);
killgssd_handle(clnt);
return (res.status);
}
OM_uint32
kgss_sign(
OM_uint32 *minor_status,
const gss_ctx_id_t context_handle,
int qop_req,
const gss_buffer_t message_buffer,
gss_buffer_t msg_token)
{
if (context_handle == GSS_C_NO_CONTEXT)
return (GSS_S_FAILURE);
return (KGSS_SIGN(minor_status, context_handle, qop_req,
message_buffer, msg_token));
}
/*ARGSUSED*/
static OM_uint32
kgss_verify_wrapped(void *private,
OM_uint32 *minor_status,
const gss_ctx_id_t ctx_handle,
const gss_buffer_t message_buffer,
const gss_buffer_t token_buffer,
int *qop_state,
OM_uint32 gssd_context_verifier)
{
CLIENT *clnt;
gssd_ctx_id_t context_handle;
gss_verify_arg arg;
gss_verify_res res;
context_handle = (gssd_ctx_id_t)KCTX_TO_GSSD_CTX(ctx_handle);
/* get the client handle to GSSD */
if ((clnt = getgssd_handle()) == NULL) {
GSSLOG(1, "kgss_verify: can't connect to server on %s\n",
server);
return (GSS_S_FAILURE);
}
/* copy the procedure arguments into the rpc arg parameter */
arg.context_handle.GSS_CTX_ID_T_len = (uint_t)sizeof (gss_ctx_id_t);
arg.context_handle.GSS_CTX_ID_T_val = (char *)&context_handle;
arg.context_handle.GSS_CTX_ID_T_len = (uint_t)sizeof (gssd_ctx_id_t);
arg.context_handle.GSS_CTX_ID_T_val = (char *)&context_handle;
arg.gssd_context_verifier = gssd_context_verifier;
arg.message_buffer.GSS_BUFFER_T_len = (uint_t)message_buffer->length;
arg.message_buffer.GSS_BUFFER_T_val = (char *)message_buffer->value;
arg.token_buffer.GSS_BUFFER_T_len = (uint_t)token_buffer->length;
arg.token_buffer.GSS_BUFFER_T_val = (char *)token_buffer->value;
/* call the remote procedure */
bzero((caddr_t)&res, sizeof (res));
if (gss_verify_1(&arg, &res, clnt) != RPC_SUCCESS) {
/*
* if the RPC call times out, null out all return arguments, set
* minor_status to its maximum value, and return GSS_S_FAILURE
*/
if (minor_status != NULL)
*minor_status = DEFAULT_MINOR_STAT;
if (qop_state != NULL)
*qop_state = 0;
killgssd_handle(clnt);
GSSLOG0(1, "kgss_verify: RPC call times out\n");
return (GSS_S_FAILURE);
}
/* copy the rpc results into the return arguments */
if (minor_status != NULL)
*minor_status = res.minor_status;
if (qop_state != NULL)
*qop_state = res.qop_state;
/* return with status returned in rpc call */
killgssd_handle(clnt);
return (res.status);
}
OM_uint32
kgss_verify(OM_uint32 *minor_status,
const gss_ctx_id_t context_handle,
const gss_buffer_t message_buffer,
const gss_buffer_t token_buffer,
int *qop_state)
{
if (context_handle == GSS_C_NO_CONTEXT)
return (GSS_S_FAILURE);
return (KGSS_VERIFY(minor_status, context_handle,
message_buffer, token_buffer, qop_state));
}
/*ARGSUSED*/
static OM_uint32
kgss_seal_wrapped(void *private,
OM_uint32 *minor_status,
const gss_ctx_id_t ctx_handle,
int conf_req_flag,
int qop_req,
const gss_buffer_t input_message_buffer,
int *conf_state,
gss_buffer_t output_message_buffer,
OM_uint32 gssd_context_verifier)
{
CLIENT *clnt;
gssd_ctx_id_t context_handle;
gss_seal_arg arg;
gss_seal_res res;
context_handle = (gssd_ctx_id_t)KCTX_TO_GSSD_CTX(ctx_handle);
/* get the client handle to GSSD */
if ((clnt = getgssd_handle()) == NULL) {
GSSLOG(1, "kgss_seal: can't connect to server on %s\n", server);
return (GSS_S_FAILURE);
}
/* copy the procedure arguments into the rpc arg parameter */
arg.context_handle.GSS_CTX_ID_T_len = (uint_t)sizeof (gss_ctx_id_t);
arg.context_handle.GSS_CTX_ID_T_val = (char *)&context_handle;
arg.context_handle.GSS_CTX_ID_T_len = (uint_t)sizeof (OM_uint32);
arg.context_handle.GSS_CTX_ID_T_val = (char *)&context_handle;
arg.gssd_context_verifier = gssd_context_verifier;
arg.conf_req_flag = conf_req_flag;
arg.qop_req = qop_req;
arg.input_message_buffer.GSS_BUFFER_T_len =
(uint_t)input_message_buffer->length;
arg.input_message_buffer.GSS_BUFFER_T_val =
(char *)input_message_buffer->value;
/* call the remote procedure */
bzero((caddr_t)&res, sizeof (res));
if (gss_seal_1(&arg, &res, clnt) != RPC_SUCCESS) {
/*
* if the RPC call times out, null out all return arguments, set
* minor_status to its maximum value, and return GSS_S_FAILURE
*/
if (minor_status != NULL)
*minor_status = DEFAULT_MINOR_STAT;
if (conf_state != NULL)
*conf_state = 0;
if (output_message_buffer != NULL)
output_message_buffer->length = 0;
killgssd_handle(clnt);
GSSLOG0(1, "kgss_seal: RPC call times out\n");
return (GSS_S_FAILURE);
}
/* copy the rpc results into the return arguments */
if (minor_status != NULL)
*minor_status = res.minor_status;
if (conf_state != NULL)
*conf_state = res.conf_state;
if (output_message_buffer != NULL) {
output_message_buffer->length =
res.output_message_buffer.GSS_BUFFER_T_len;
output_message_buffer->value =
(void *) MALLOC(output_message_buffer->length);
(void) memcpy(output_message_buffer->value,
res.output_message_buffer.GSS_BUFFER_T_val,
output_message_buffer->length);
}
/*
* free the memory allocated for the results and return with the status
* received in the rpc call
*/
clnt_freeres(clnt, xdr_gss_seal_res, (caddr_t)&res);
killgssd_handle(clnt);
return (res.status);
}
/*ARGSUSED*/
OM_uint32
kgss_seal(OM_uint32 *minor_status,
const gss_ctx_id_t context_handle,
int conf_req_flag,
int qop_req,
const gss_buffer_t input_message_buffer,
int *conf_state,
gss_buffer_t output_message_buffer)
{
if (context_handle == GSS_C_NO_CONTEXT)
return (GSS_S_FAILURE);
return (KGSS_SEAL(minor_status, context_handle,
conf_req_flag, qop_req,
input_message_buffer, conf_state,
output_message_buffer));
}
/*ARGSUSED*/
static OM_uint32
kgss_unseal_wrapped(void *private,
OM_uint32 *minor_status,
const gss_ctx_id_t ctx_handle,
const gss_buffer_t input_message_buffer,
gss_buffer_t output_message_buffer,
int *conf_state,
int *qop_state,
OM_uint32 gssd_context_verifier)
{
CLIENT *clnt;
gss_unseal_arg arg;
gss_unseal_res res;
gssd_ctx_id_t context_handle;
context_handle = (gssd_ctx_id_t)KCTX_TO_GSSD_CTX(ctx_handle);
/* get the client handle to GSSD */
if ((clnt = getgssd_handle()) == NULL) {
GSSLOG(1, "kgss_unseal: can't connect to server on %s\n",
server);
return (GSS_S_FAILURE);
}
/* copy the procedure arguments into the rpc arg parameter */
arg.context_handle.GSS_CTX_ID_T_len = (uint_t)sizeof (gss_ctx_id_t);
arg.context_handle.GSS_CTX_ID_T_val = (char *)&context_handle;
arg.context_handle.GSS_CTX_ID_T_len = (uint_t)sizeof (gssd_ctx_id_t);
arg.context_handle.GSS_CTX_ID_T_val = (char *)&context_handle;
arg.gssd_context_verifier = gssd_context_verifier;
arg.input_message_buffer.GSS_BUFFER_T_len =
(uint_t)input_message_buffer->length;
arg.input_message_buffer.GSS_BUFFER_T_val =
(char *)input_message_buffer->value;
/* call the remote procedure */
bzero((caddr_t)&res, sizeof (res));
if (gss_unseal_1(&arg, &res, clnt) != RPC_SUCCESS) {
/*
* if the RPC call times out, null out all return arguments, set
* minor_status to its maximum value, and return GSS_S_FAILURE
*/
if (minor_status != NULL)
*minor_status = DEFAULT_MINOR_STAT;
if (output_message_buffer != NULL)
output_message_buffer->length = 0;
if (conf_state != NULL)
*conf_state = 0;
if (qop_state != NULL)
*qop_state = 0;
killgssd_handle(clnt);
GSSLOG0(1, "kgss_unseal: RPC call times out\n");
return (GSS_S_FAILURE);
}
/* copy the rpc results into the return arguments */
if (minor_status != NULL)
*minor_status = res.minor_status;
if (output_message_buffer != NULL) {
output_message_buffer->length =
res.output_message_buffer.GSS_BUFFER_T_len;
output_message_buffer->value =
(void *) MALLOC(output_message_buffer->length);
(void) memcpy(output_message_buffer->value,
res.output_message_buffer.GSS_BUFFER_T_val,
output_message_buffer->length);
}
if (conf_state != NULL)
*conf_state = res.conf_state;
if (qop_state != NULL)
*qop_state = res.qop_state;
/*
* free the memory allocated for the results and return with the
* status received in the rpc call
*/
clnt_freeres(clnt, xdr_gss_unseal_res, (caddr_t)&res);
killgssd_handle(clnt);
return (res.status);
}
OM_uint32
kgss_unseal(OM_uint32 *minor_status,
const gss_ctx_id_t context_handle,
const gss_buffer_t input_message_buffer,
const gss_buffer_t output_message_buffer,
int *conf_state,
int *qop_state)
{
if (context_handle == GSS_C_NO_CONTEXT)
return (GSS_S_FAILURE);
return (KGSS_UNSEAL(minor_status, context_handle, input_message_buffer,
output_message_buffer, conf_state, qop_state));
}
OM_uint32
kgss_display_status(minor_status,
status_value,
status_type,
mech_type,
message_context,
status_string,
uid)
OM_uint32 *minor_status;
OM_uint32 status_value;
int status_type;
const gss_OID mech_type;
int *message_context;
gss_buffer_t status_string;
uid_t uid;
{
CLIENT *clnt;
gss_display_status_arg arg;
gss_display_status_res res;
/* get the client handle to GSSD */
if ((clnt = getgssd_handle()) == NULL) {
GSSLOG(1, "kgss_display_status: can't connect to server on %s\n",
server);
return (GSS_S_FAILURE);
}
/* copy the procedure arguments into the rpc arg parameter */
arg.uid = (OM_uint32) uid;
arg.status_value = status_value;
arg.status_type = status_type;
arg.mech_type.GSS_OID_len = (uint_t)(mech_type != GSS_C_NULL_OID ?
mech_type->length : 0);
arg.mech_type.GSS_OID_val = (char *)(mech_type != GSS_C_NULL_OID ?
mech_type->elements : 0);
arg.message_context = *message_context;
/* call the remote procedure */
if (message_context != NULL)
*message_context = 0;
if (status_string != NULL) {
status_string->length = 0;
status_string->value = NULL;
}
bzero((caddr_t)&res, sizeof (res));
if (gss_display_status_1(&arg, &res, clnt) != RPC_SUCCESS) {
/*
* if the RPC call times out, null out all return arguments, set
* minor_status to its maximum value, and return GSS_S_FAILURE
*/
if (minor_status != NULL)
*minor_status = DEFAULT_MINOR_STAT;
killgssd_handle(clnt);
GSSLOG0(1, "kgss_display_status: RPC call time out\n");
return (GSS_S_FAILURE);
}
/* now process the results and pass them back to the caller */
if (res.status == GSS_S_COMPLETE) {
if (minor_status != NULL)
*minor_status = res.minor_status;
if (message_context != NULL)
*message_context = res.message_context;
if (status_string != NULL) {
status_string->length =
(size_t)res.status_string.GSS_BUFFER_T_len;
status_string->value =
(void *) MALLOC(status_string->length);
(void) memcpy(status_string->value,
res.status_string.GSS_BUFFER_T_val,
status_string->length);
}
}
clnt_freeres(clnt, xdr_gss_display_status_res, (caddr_t)&res);
killgssd_handle(clnt);
return (res.status);
}
/*ARGSUSED*/
OM_uint32
kgss_indicate_mechs(minor_status,
mech_set,
uid)
OM_uint32 *minor_status;
gss_OID_set *mech_set;
uid_t uid;
{
CLIENT *clnt;
void *arg;
gss_indicate_mechs_res res;
int i;
/* get the client handle to GSSD */
if ((clnt = getgssd_handle()) == NULL) {
GSSLOG(1, "kgss_indicate_mechs: can't connect to server on %s\n",
server);
return (GSS_S_FAILURE);
}
bzero((caddr_t)&res, sizeof (res));
if (gss_indicate_mechs_1(&arg, &res, clnt) != RPC_SUCCESS) {
/*
* if the RPC call times out, null out all return arguments, set
* minor_status to its maximum value, and return GSS_S_FAILURE
*/
if (minor_status != NULL)
*minor_status = DEFAULT_MINOR_STAT;
if (mech_set != NULL)
*mech_set = NULL;
killgssd_handle(clnt);
GSSLOG0(1, "kgss_indicate_mechs: RPC call times out\n");
return (GSS_S_FAILURE);
}
/* copy the rpc results into the return arguments */
if (minor_status != NULL)
*minor_status = res.minor_status;
if (mech_set != NULL) {
*mech_set = (gss_OID_set) MALLOC(sizeof (gss_OID_set_desc));
(*mech_set)->count = res.mech_set.GSS_OID_SET_len;
(*mech_set)->elements = (void *)
MALLOC ((*mech_set)->count * sizeof (gss_OID_desc));
for (i = 0; i < (*mech_set)->count; i++) {
(*mech_set)->elements[i].length =
res.mech_set.GSS_OID_SET_val[i].GSS_OID_len;
(*mech_set)->elements[i].elements = (void *)
MALLOC ((*mech_set)->elements[i].length);
(void) memcpy((*mech_set)->elements[i].elements,
res.mech_set.GSS_OID_SET_val[i].GSS_OID_val,
(*mech_set)->elements[i].length);
}
}
/*
* free the memory allocated for the results and return with the status
* received in the rpc call
*/
clnt_freeres(clnt, xdr_gss_indicate_mechs_res, (caddr_t)&res);
killgssd_handle(clnt);
return (res.status);
}
OM_uint32
kgss_inquire_cred_wrapped(minor_status,
cred_handle,
gssd_cred_verifier,
name,
lifetime,
cred_usage,
mechanisms,
uid)
OM_uint32 *minor_status;
const gssd_cred_id_t cred_handle;
OM_uint32 gssd_cred_verifier;
gss_name_t *name;
OM_uint32 *lifetime;
int *cred_usage;
gss_OID_set *mechanisms;
uid_t uid;
{
CLIENT *clnt;
OM_uint32 minor_status_temp;
gss_buffer_desc external_name;
gss_OID_desc name_type;
int i;
gss_inquire_cred_arg arg;
gss_inquire_cred_res res;
/*
* NULL the params here once
* If there are errors then we won't
* have to do it for every error
* case
*/
if (minor_status != NULL)
*minor_status = DEFAULT_MINOR_STAT;
if (name != NULL)
*name = NULL;
if (lifetime != NULL)
*lifetime = 0;
if (cred_usage != NULL)
*cred_usage = 0;
if (mechanisms != NULL)
*mechanisms = NULL;
/* get the client handle to GSSD */
if ((clnt = getgssd_handle()) == NULL) {
GSSLOG(1, "kgss_inquire_cred: can't connect to server on %s\n",
server);
return (GSS_S_FAILURE);
}
/* copy the procedure arguments into the rpc arg parameter */
arg.uid = (OM_uint32) uid;
arg.cred_handle.GSS_CRED_ID_T_len =
cred_handle == GSSD_NO_CREDENTIAL ?
0 : (uint_t)sizeof (gssd_cred_id_t);
arg.cred_handle.GSS_CRED_ID_T_val = (char *)&cred_handle;
arg.gssd_cred_verifier = gssd_cred_verifier;
/* call the remote procedure */
bzero((caddr_t)&res, sizeof (res));
if (gss_inquire_cred_1(&arg, &res, clnt) != RPC_SUCCESS) {
/*
* if the RPC call times out
* kill the handle and return GSS_S_FAILURE
* the parameters have been set to NULL already
*/
killgssd_handle(clnt);
GSSLOG0(1, "kgss_inquire_cred: RPC call times out\n");
return (GSS_S_FAILURE);
}
/* copy the rpc results into the return arguments */
if (minor_status != NULL)
*minor_status = res.minor_status;
/* convert name from external to internal format */
if (name != NULL) {
external_name.length = res.name.GSS_BUFFER_T_len;
external_name.value = res.name.GSS_BUFFER_T_val;
/*
* we can pass a pointer to res structure
* since gss_import_name treats the name_type
* parameter as read only and performs a copy
*/
name_type.length = res.name_type.GSS_OID_len;
name_type.elements = (void *)res.name_type.GSS_OID_val;
if (gss_import_name(&minor_status_temp, &external_name,
&name_type, name) != GSS_S_COMPLETE) {
*minor_status = (OM_uint32) minor_status_temp;
clnt_freeres(clnt, xdr_gss_inquire_cred_res,
(caddr_t)&res);
killgssd_handle(clnt);
GSSLOG0(1, "kgss_inquire_cred: import name fails\n");
return ((OM_uint32) GSS_S_FAILURE);
}
}
if (lifetime != NULL)
*lifetime = res.lifetime;
if (cred_usage != NULL)
*cred_usage = res.cred_usage;
if (res.status == GSS_S_COMPLETE &&
res.mechanisms.GSS_OID_SET_len != 0 &&
mechanisms != NULL) {
*mechanisms = (gss_OID_set) MALLOC(sizeof (gss_OID_set_desc));
(*mechanisms)->count =
(int)res.mechanisms.GSS_OID_SET_len;
(*mechanisms)->elements = (gss_OID)
MALLOC(sizeof (gss_OID_desc) * (*mechanisms)->count);
for (i = 0; i < (*mechanisms)->count; i++) {
(*mechanisms)->elements[i].length = (OM_uint32)
res.mechanisms.GSS_OID_SET_val[i].GSS_OID_len;
(*mechanisms)->elements[i].elements =
(void *) MALLOC((*mechanisms)->elements[i].length);
(void) memcpy((*mechanisms)->elements[i].elements,
res.mechanisms.GSS_OID_SET_val[i].GSS_OID_val,
(*mechanisms)->elements[i].length);
}
} else {
if (res.status == GSS_S_COMPLETE &&
mechanisms != NULL)
(*mechanisms) = NULL;
}
/*
* free the memory allocated for the results and return with the status
* received in the rpc call
*/
clnt_freeres(clnt, xdr_gss_inquire_cred_res, (caddr_t)&res);
killgssd_handle(clnt);
return (res.status);
}
OM_uint32
kgss_inquire_cred(minor_status,
cred_handle,
name,
lifetime,
cred_usage,
mechanisms,
uid)
OM_uint32 *minor_status;
const gss_cred_id_t cred_handle;
gss_name_t *name;
OM_uint32 *lifetime;
int *cred_usage;
gss_OID_set * mechanisms;
uid_t uid;
{
OM_uint32 gssd_cred_verifier;
OM_uint32 gssd_cred_handle;
gssd_cred_verifier = KCRED_TO_CREDV(cred_handle);
gssd_cred_handle = KCRED_TO_CRED(cred_handle);
return (kgss_inquire_cred_wrapped(minor_status,
gssd_cred_handle, gssd_cred_verifier,
name, lifetime, cred_usage, mechanisms, uid));
}
OM_uint32
kgss_inquire_cred_by_mech_wrapped(minor_status,
cred_handle,
gssd_cred_verifier,
mech_type,
uid)
OM_uint32 *minor_status;
gssd_cred_id_t cred_handle;
OM_uint32 gssd_cred_verifier;
gss_OID mech_type;
uid_t uid;
{
CLIENT *clnt;
gss_inquire_cred_by_mech_arg arg;
gss_inquire_cred_by_mech_res res;
/* get the client handle to GSSD */
if ((clnt = getgssd_handle()) == NULL) {
GSSLOG(1, "kgss_inquire_cred: can't connect to server on %s\n",
server);
return (GSS_S_FAILURE);
}
/* copy the procedure arguments into the rpc arg parameter */
arg.uid = (OM_uint32) uid;
arg.cred_handle.GSS_CRED_ID_T_len =
cred_handle == GSSD_NO_CREDENTIAL ?
0 : (uint_t)sizeof (gssd_cred_id_t);
arg.cred_handle.GSS_CRED_ID_T_val = (char *)&cred_handle;
arg.gssd_cred_verifier = gssd_cred_verifier;
arg.mech_type.GSS_OID_len =
(uint_t)(mech_type != GSS_C_NULL_OID ?
mech_type->length : 0);
arg.mech_type.GSS_OID_val =
(char *)(mech_type != GSS_C_NULL_OID ?
mech_type->elements : 0);
/* call the remote procedure */
bzero((caddr_t)&res, sizeof (res));
if (gss_inquire_cred_by_mech_1(&arg, &res, clnt) != RPC_SUCCESS) {
/*
* if the RPC call times out, null out all return arguments, set
* minor_status to its maximum value, and return GSS_S_FAILURE
*/
if (minor_status != NULL)
*minor_status = DEFAULT_MINOR_STAT;
killgssd_handle(clnt);
GSSLOG0(1, "kgss_inquire_cred: RPC call times out\n");
return (GSS_S_FAILURE);
}
/* copy the rpc results into the return arguments */
if (minor_status != NULL)
*minor_status = res.minor_status;
clnt_freeres(clnt, xdr_gss_inquire_cred_by_mech_res, (caddr_t)&res);
killgssd_handle(clnt);
return (res.status);
}
OM_uint32
kgss_inquire_cred_by_mech(minor_status,
cred_handle,
mech_type,
uid)
OM_uint32 *minor_status;
gss_cred_id_t cred_handle;
gss_OID mech_type;
uid_t uid;
{
OM_uint32 gssd_cred_verifier;
OM_uint32 gssd_cred_handle;
gssd_cred_verifier = KCRED_TO_CREDV(cred_handle);
gssd_cred_handle = KCRED_TO_CRED(cred_handle);
return (kgss_inquire_cred_by_mech_wrapped(minor_status,
gssd_cred_handle, gssd_cred_verifier,
mech_type, uid));
}
OM_uint32
kgsscred_expname_to_unix_cred(expName, uidOut, gidOut, gids, gidsLen, uid)
const gss_buffer_t expName;
uid_t *uidOut;
gid_t *gidOut;
gid_t *gids[];
int *gidsLen;
uid_t uid;
{
CLIENT *clnt;
gsscred_expname_to_unix_cred_arg args;
gsscred_expname_to_unix_cred_res res;
/* check input/output parameters */
if (expName == NULL || expName->value == NULL)
return (GSS_S_CALL_INACCESSIBLE_READ);
if (uidOut == NULL)
return (GSS_S_CALL_INACCESSIBLE_WRITE);
/* NULL out output parameters */
*uidOut = UID_NOBODY;
if (gidsLen)
*gidsLen = 0;
if (gids)
*gids = NULL;
/* get the client handle to gssd */
if ((clnt = getgssd_handle()) == NULL)
{
GSSLOG(1, "kgsscred_expname_to_unix_cred:"
" can't connect to server on %s\n", server);
return (GSS_S_FAILURE);
}
/* copy the procedure arguments */
args.uid = uid;
args.expname.GSS_BUFFER_T_val = expName->value;
args.expname.GSS_BUFFER_T_len = expName->length;
/* null out the return buffer and call the remote proc */
bzero(&res, sizeof (res));
if (gsscred_expname_to_unix_cred_1(&args, &res, clnt) != RPC_SUCCESS)
{
killgssd_handle(clnt);
GSSLOG0(1,
"kgsscred_expname_to_unix_cred: RPC call times out\n");
return (GSS_S_FAILURE);
}
/* copy the results into the result parameters */
if (res.major == GSS_S_COMPLETE)
{
*uidOut = res.uid;
if (gidOut)
*gidOut = res.gid;
if (gids && gidsLen)
{
*gids = res.gids.GSSCRED_GIDS_val;
*gidsLen = res.gids.GSSCRED_GIDS_len;
res.gids.GSSCRED_GIDS_val = NULL;
res.gids.GSSCRED_GIDS_len = 0;
}
}
/* free RPC results */
clnt_freeres(clnt, xdr_gsscred_expname_to_unix_cred_res, (caddr_t)&res);
killgssd_handle(clnt);
return (res.major);
} /* kgsscred_expname_to_unix_cred */
OM_uint32
kgsscred_name_to_unix_cred(intName, mechType, uidOut, gidOut, gids,
gidsLen, uid)
const gss_name_t intName;
const gss_OID mechType;
uid_t *uidOut;
gid_t *gidOut;
gid_t *gids[];
int *gidsLen;
uid_t uid;
{
CLIENT *clnt;
gsscred_name_to_unix_cred_arg args;
gsscred_name_to_unix_cred_res res;
OM_uint32 major, minor;
gss_OID nameOid;
gss_buffer_desc flatName = GSS_C_EMPTY_BUFFER;
/* check the input/output parameters */
if (intName == NULL || mechType == NULL)
return (GSS_S_CALL_INACCESSIBLE_READ);
if (uidOut == NULL)
return (GSS_S_CALL_INACCESSIBLE_WRITE);
/* NULL out the output parameters */
*uidOut = UID_NOBODY;
if (gids)
*gids = NULL;
if (gidsLen)
*gidsLen = 0;
/* get the client handle to gssd */
if ((clnt = getgssd_handle()) == NULL)
{
GSSLOG(1,
"kgsscred_name_to_unix_cred: can't connect to server %s\n",
server);
return (GSS_S_FAILURE);
}
/* convert the name to flat representation */
if ((major = gss_display_name(&minor, intName, &flatName, &nameOid))
!= GSS_S_COMPLETE)
{
killgssd_handle(clnt);
GSSLOG0(1, "kgsscred_name_to_unix_cred: display name failed\n");
return (major);
}
/* set the rpc parameters */
args.uid = uid;
args.pname.GSS_BUFFER_T_len = flatName.length;
args.pname.GSS_BUFFER_T_val = flatName.value;
args.name_type.GSS_OID_len = nameOid->length;
args.name_type.GSS_OID_val = nameOid->elements;
args.mech_type.GSS_OID_len = mechType->length;
args.mech_type.GSS_OID_val = mechType->elements;
/* call the remote procedure */
bzero(&res, sizeof (res));
if (gsscred_name_to_unix_cred_1(&args, &res, clnt) != RPC_SUCCESS) {
killgssd_handle(clnt);
(void) gss_release_buffer(&minor, &flatName);
GSSLOG0(1, "kgsscred_name_to_unix_cred: RPC call times out\n");
return (GSS_S_FAILURE);
}
/* delete the flat name buffer */
(void) gss_release_buffer(&minor, &flatName);
/* copy the output parameters on output */
if (res.major == GSS_S_COMPLETE) {
*uidOut = res.uid;
if (gidOut)
*gidOut = res.gid;
if (gids && gidsLen) {
*gids = res.gids.GSSCRED_GIDS_val;
*gidsLen = res.gids.GSSCRED_GIDS_len;
res.gids.GSSCRED_GIDS_val = NULL;
res.gids.GSSCRED_GIDS_len = 0;
}
}
/* delete RPC allocated memory */
clnt_freeres(clnt, xdr_gsscred_name_to_unix_cred_res, (caddr_t)&res);
killgssd_handle(clnt);
return (res.major);
} /* kgsscred_name_to_unix_cred */
OM_uint32
kgss_get_group_info(puid, gidOut, gids, gidsLen, uid)
const uid_t puid;
gid_t *gidOut;
gid_t *gids[];
int *gidsLen;
uid_t uid;
{
CLIENT *clnt;
gss_get_group_info_arg args;
gss_get_group_info_res res;
/* check the output parameters */
if (gidOut == NULL || gids == NULL || gidsLen == NULL)
return (GSS_S_CALL_INACCESSIBLE_WRITE);
/* get the client GSSD handle */
if ((clnt = getgssd_handle()) == NULL) {
GSSLOG(1,
"kgss_get_group_info: can't connect to server on %s\n",
server);
return (GSS_S_FAILURE);
}
/* set the input parameters */
args.uid = uid;
args.puid = puid;
/* call the remote procedure */
bzero(&res, sizeof (res));
if (gss_get_group_info_1(&args, &res, clnt) != RPC_SUCCESS) {
killgssd_handle(clnt);
GSSLOG0(1, "kgss_get_group_info: RPC call times out\n");
return (GSS_S_FAILURE);
}
/* copy the results */
if (res.major == GSS_S_COMPLETE) {
*gidOut = res.gid;
*gids = res.gids.GSSCRED_GIDS_val;
*gidsLen = res.gids.GSSCRED_GIDS_len;
res.gids.GSSCRED_GIDS_val = NULL;
res.gids.GSSCRED_GIDS_len = 0;
}
/* no results to free */
killgssd_handle(clnt);
return (res.major);
} /* kgss_get_group_info */
static char *
kgss_get_kmod(gss_OID mech_oid)
{
CLIENT *clnt;
gss_get_kmod_arg args;
gss_get_kmod_res res;
/* get the client GSSD handle */
if ((clnt = getgssd_handle()) == NULL) {
GSSLOG(1, "kgss_get_kmod: can't connect to server on %s\n",
server);
return (NULL);
}
/* set the input parameters */
args.mech_oid.GSS_OID_len = mech_oid->length;
args.mech_oid.GSS_OID_val = mech_oid->elements;
/* call the remote procedure */
bzero(&res, sizeof (res));
if (gss_get_kmod_1(&args, &res, clnt) != RPC_SUCCESS) {
killgssd_handle(clnt);
GSSLOG0(1, "gss_get_kmod_1: RPC call times out\n");
return (NULL);
}
/* no results to free */
killgssd_handle(clnt);
if (res.module_follow == TRUE) {
return (res.gss_get_kmod_res_u.modname);
} else
return (NULL);
} /* kgss_get_kmod */
static gss_mechanism kgss_mech_head;
static gss_mechanism kgss_mech_tail;
kmutex_t __kgss_mech_lock;
/*
* See if there is kernel mechanism module, and if so, attempt to
* load it and reset the pointer (gss_mechanism) to the sign/seal/etc.
* entry points to that of the kernel module.
*/
static void
__kgss_reset_mech(gss_mechanism *mechp, gss_OID mech_oid)
{
gss_mechanism mech;
char *kmod;
/*
* We can search the list without a mutex, becuase the list never
* shrinks and we always add to the end.
*/
mech = __kgss_get_mechanism(mech_oid);
if (mech) {
*mechp = mech;
return;
}
/*
* Get the module name from the kernel.
*/
kmod = kgss_get_kmod(mech_oid);
if (kmod) {
extern int modload(const char *, const char *);
if (modload("misc/kgss", kmod) < 0) {
/*
* Modload of 'kmod' failed, so log an
* appropriate comment
*/
cmn_err(CE_NOTE, "kgss_reset_mech: Algorithm modload "
"(%s) failed. Userland gssd will now handle "
"all GSSAPI calls, which may result in "
"reduced performance.\n", kmod);
};
/*
* Allocated in the XDR routine called by gss_get_kmod_1().
*/
FREE(kmod, strlen(kmod)+1);
mech = __kgss_get_mechanism(mech_oid);
if (mech) {
*mechp = mech;
}
/*
* If for some reason the module load didn't take,
* we return anyway and hope that the next context
* creation succeeds.
*/
return;
}
/*
* No kernel module, so enter this mech oid into the list
* using the default sign/seal/etc. operations that upcall to
* gssd.
*/
mutex_enter(&__kgss_mech_lock);
mech = __kgss_get_mechanism(mech_oid);
if (mech) {
mutex_exit(&__kgss_mech_lock);
*mechp = mech;
return;
}
/*
* Allocate space for the mechanism entry.
*/
mech = kmem_zalloc(sizeof (struct gss_config), KM_SLEEP);
/*
* Copy basic information from default mechanism struct.
*/
*mech = default_gc;
/*
* Record the real mech OID.
*/
mech->mech_type.length = mech_oid->length;
mech->mech_type.elements = MALLOC(mech_oid->length);
bcopy(mech_oid->elements, mech->mech_type.elements, mech_oid->length);
/*
* Add it to the table.
*/
__kgss_add_mechanism(mech);
mutex_exit(&__kgss_mech_lock);
*mechp = mech;
}
/*
* Called with __kgss_mech_lock held.
*/
void
__kgss_add_mechanism(gss_mechanism mech)
{
gss_mechanism tmp;
tmp = kgss_mech_tail;
kgss_mech_tail = mech;
if (tmp != NULL)
tmp->next = mech;
if (kgss_mech_head == NULL)
kgss_mech_head = mech;
}
/*
* given the mechs_array and a mechanism OID, return the
* pointer to the mechanism, or NULL if that mechanism is
* not supported.
*/
gss_mechanism
__kgss_get_mechanism(gss_OID type)
{
gss_mechanism mech;
mech = kgss_mech_head;
/*
* Note that a reader can scan this list without the mutex held.
* This is safe because we always append, and never shrink the list.
* Moreover, the entry is fully initialized before it is ever
* added to the list.
*/
while (mech != NULL) {
if ((mech->mech_type.length == type->length) &&
(bcmp(mech->mech_type.elements, type->elements,
type->length) == 0))
return (mech);
mech = mech->next;
}
return (NULL);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 2015 Nexenta Systems, Inc. All rights reserved.
*/
/*
* Copyright 2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Kernel code to obtain client handle to gssd server
*/
#include <sys/types.h>
#include <gssapi/gssapi.h>
#include <gssapi/gssd_prot.h>
#include <gssapi/kgssapi_defs.h>
#include <sys/systm.h>
#include <sys/vnode.h>
#include <sys/uio.h>
#include <sys/pathname.h>
#define GSSD_RETRY 5
kmutex_t gssrpcb_lock;
zone_key_t gss_zone_key;
struct gss_globals {
enum clnt_stat gss_last_stat;
struct netbuf gss_netaddr;
struct knetconfig gss_config;
};
/* ARGSUSED */
void *
gss_zone_init(zoneid_t zoneid)
{
struct gss_globals *gssg;
gssg = kmem_zalloc(sizeof (*gssg), KM_SLEEP);
return (gssg);
}
/* ARGSUSED */
void
gss_zone_fini(zoneid_t zoneid, void *data)
{
struct gss_globals *gssg = data;
struct netbuf *netaddrp = &gssg->gss_netaddr;
if (netaddrp->len != 0)
kmem_free(netaddrp->buf, netaddrp->maxlen);
kmem_free(gssg, sizeof (*gssg));
}
void
killgssd_handle(CLIENT *client)
{
struct rpc_err rpcerr;
struct gss_globals *gssg;
gssg = zone_getspecific(gss_zone_key, curproc->p_zone);
CLNT_GETERR(client, &rpcerr);
gssg->gss_last_stat = rpcerr.re_status;
AUTH_DESTROY(client->cl_auth);
CLNT_DESTROY(client);
}
CLIENT *
getgssd_handle(void)
{
struct vnode *vp;
int error;
CLIENT *clnt;
enum clnt_stat stat;
struct netbuf tmpaddr;
struct gss_globals *gssg;
struct netbuf *netaddrp;
gssg = zone_getspecific(gss_zone_key, curproc->p_zone);
/*
* Cribbed from kerb_krpc.c. Really should do the config set up
* in the _init routine.
*/
if (gssg->gss_config.knc_rdev == 0) {
if ((error = lookupname("/dev/ticotsord", UIO_SYSSPACE,
FOLLOW, NULLVPP, &vp)) != 0) {
GSSLOG(1, "getgssd_handle: lookupname: %d\n", error);
return (NULL);
}
gssg->gss_config.knc_rdev = vp->v_rdev;
gssg->gss_config.knc_protofmly = loopback_name;
VN_RELE(vp);
gssg->gss_config.knc_semantics = NC_TPI_COTS_ORD;
}
/*
* Contact rpcbind to get gssd's address only
* once and re-use the address.
*/
mutex_enter(&gssrpcb_lock);
netaddrp = &gssg->gss_netaddr;
if (netaddrp->len == 0 || gssg->gss_last_stat != RPC_SUCCESS) {
if (netaddrp->buf != NULL)
kmem_free(netaddrp->buf, netaddrp->maxlen);
/* Set up netaddr to be "localhost." (strlen is 10) */
netaddrp->len = netaddrp->maxlen = 10;
netaddrp->buf = kmem_alloc(netaddrp->len, KM_SLEEP);
(void) strncpy(netaddrp->buf, "localhost.", netaddrp->len);
/* Get address of gssd from rpcbind */
stat = rpcbind_getaddr(&gssg->gss_config, GSSPROG, GSSVERS,
netaddrp);
if (stat != RPC_SUCCESS) {
kmem_free(netaddrp->buf, netaddrp->maxlen);
netaddrp->buf = NULL;
netaddrp->len = netaddrp->maxlen = 0;
mutex_exit(&gssrpcb_lock);
return (NULL);
}
}
/*
* Copy the netaddr information into a tmp location to
* be used by clnt_tli_kcreate. The purpose of this
* is for MT race condition (ie. netaddr being modified
* while it is being used.)
*/
tmpaddr.buf = kmem_zalloc(netaddrp->maxlen, KM_SLEEP);
bcopy(netaddrp->buf, tmpaddr.buf, netaddrp->maxlen);
tmpaddr.maxlen = netaddrp->maxlen;
tmpaddr.len = netaddrp->len;
mutex_exit(&gssrpcb_lock);
error = clnt_tli_kcreate(&gssg->gss_config, &tmpaddr, GSSPROG,
GSSVERS, 0, GSSD_RETRY, kcred, &clnt);
kmem_free(tmpaddr.buf, tmpaddr.maxlen);
if (error != 0) {
GSSLOG(1,
"getgssd_handle: clnt_tli_kcreate: error %d\n", error);
return (NULL);
}
return (clnt);
}
/*
* Please do not edit this file.
* It was generated using rpcgen.
*/
#include "gssd_prot.h"
#ifndef _KERNEL
#endif /* !_KERNEL */
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* RPC protocol information for gssd, the usermode daemon that
* assists the kernel with gssapi. It is gssd that executes all
* gssapi calls except for some such as gss_sign(), and
* gss_verify(), which are executed in the kernel itself.
*
* File generated from gssd.x
*/
#define NO 0
#define YES 1
#define FOREVER 1
#include <sys/types.h>
#include <sys/time.h>
#include <rpc/auth_sys.h>
#ifndef _KERNEL
#include <locale.h>
#endif /* not _KERNEL */
#ifdef _KERNEL
extern void killgssd_handle(CLIENT *);
extern CLIENT *getgssd_handle(void);
#endif /* _KERNEL */
/* gss_indicate_mechs_arg is void. This appears in the rpc call def */
/* Default timeout can be changed using clnt_control() */
static struct timeval gssd_timeout = { 125, 0 };
enum clnt_stat
gss_acquire_cred_1(argp, clnt_res, clnt)
gss_acquire_cred_arg *argp;
gss_acquire_cred_res *clnt_res;
CLIENT *clnt;
{
return (clnt_call(clnt, GSS_ACQUIRE_CRED,
(xdrproc_t)xdr_gss_acquire_cred_arg, (caddr_t)argp,
(xdrproc_t)xdr_gss_acquire_cred_res, (caddr_t)clnt_res,
gssd_timeout));
}
enum clnt_stat
gss_release_cred_1(argp, clnt_res, clnt)
gss_release_cred_arg *argp;
gss_release_cred_res *clnt_res;
CLIENT *clnt;
{
return (clnt_call(clnt, GSS_RELEASE_CRED,
(xdrproc_t)xdr_gss_release_cred_arg, (caddr_t)argp,
(xdrproc_t)xdr_gss_release_cred_res, (caddr_t)clnt_res,
gssd_timeout));
}
enum clnt_stat
gss_init_sec_context_1(argp, clnt_res, clnt)
gss_init_sec_context_arg *argp;
gss_init_sec_context_res *clnt_res;
CLIENT *clnt;
{
return (clnt_call(clnt, GSS_INIT_SEC_CONTEXT,
(xdrproc_t)xdr_gss_init_sec_context_arg, (caddr_t)argp,
(xdrproc_t)xdr_gss_init_sec_context_res, (caddr_t)clnt_res,
gssd_timeout));
}
enum clnt_stat
gss_accept_sec_context_1(argp, clnt_res, clnt)
gss_accept_sec_context_arg *argp;
gss_accept_sec_context_res *clnt_res;
CLIENT *clnt;
{
return (clnt_call(clnt, GSS_ACCEPT_SEC_CONTEXT,
(xdrproc_t)xdr_gss_accept_sec_context_arg, (caddr_t)argp,
(xdrproc_t)xdr_gss_accept_sec_context_res, (caddr_t)clnt_res,
gssd_timeout));
}
enum clnt_stat
gss_process_context_token_1(argp, clnt_res, clnt)
gss_process_context_token_arg *argp;
gss_process_context_token_res *clnt_res;
CLIENT *clnt;
{
return (clnt_call(clnt, GSS_PROCESS_CONTEXT_TOKEN,
(xdrproc_t)xdr_gss_process_context_token_arg, (caddr_t)argp,
(xdrproc_t)xdr_gss_process_context_token_res, (caddr_t)clnt_res,
gssd_timeout));
}
enum clnt_stat
gss_delete_sec_context_1(argp, clnt_res, clnt)
gss_delete_sec_context_arg *argp;
gss_delete_sec_context_res *clnt_res;
CLIENT *clnt;
{
return (clnt_call(clnt, GSS_DELETE_SEC_CONTEXT,
(xdrproc_t)xdr_gss_delete_sec_context_arg, (caddr_t)argp,
(xdrproc_t)xdr_gss_delete_sec_context_res, (caddr_t)clnt_res,
gssd_timeout));
}
enum clnt_stat
gss_context_time_1(argp, clnt_res, clnt)
gss_context_time_arg *argp;
gss_context_time_res *clnt_res;
CLIENT *clnt;
{
return (clnt_call(clnt, GSS_CONTEXT_TIME,
(xdrproc_t)xdr_gss_context_time_arg, (caddr_t)argp,
(xdrproc_t)xdr_gss_context_time_res, (caddr_t)clnt_res,
gssd_timeout));
}
enum clnt_stat
gss_sign_1(argp, clnt_res, clnt)
gss_sign_arg *argp;
gss_sign_res *clnt_res;
CLIENT *clnt;
{
return (clnt_call(clnt, GSS_SIGN,
(xdrproc_t)xdr_gss_sign_arg, (caddr_t)argp,
(xdrproc_t)xdr_gss_sign_res, (caddr_t)clnt_res,
gssd_timeout));
}
enum clnt_stat
gss_verify_1(argp, clnt_res, clnt)
gss_verify_arg *argp;
gss_verify_res *clnt_res;
CLIENT *clnt;
{
return (clnt_call(clnt, GSS_VERIFY,
(xdrproc_t)xdr_gss_verify_arg, (caddr_t)argp,
(xdrproc_t)xdr_gss_verify_res, (caddr_t)clnt_res,
gssd_timeout));
}
enum clnt_stat
gss_display_status_1(argp, clnt_res, clnt)
gss_display_status_arg *argp;
gss_display_status_res *clnt_res;
CLIENT *clnt;
{
return (clnt_call(clnt, GSS_DISPLAY_STATUS,
(xdrproc_t)xdr_gss_display_status_arg, (caddr_t)argp,
(xdrproc_t)xdr_gss_display_status_res, (caddr_t)clnt_res,
gssd_timeout));
}
enum clnt_stat
gss_indicate_mechs_1(argp, clnt_res, clnt)
void *argp;
gss_indicate_mechs_res *clnt_res;
CLIENT *clnt;
{
return (clnt_call(clnt, GSS_INDICATE_MECHS,
(xdrproc_t)xdr_void, (caddr_t)argp,
(xdrproc_t)xdr_gss_indicate_mechs_res, (caddr_t)clnt_res,
gssd_timeout));
}
enum clnt_stat
gss_inquire_cred_1(argp, clnt_res, clnt)
gss_inquire_cred_arg *argp;
gss_inquire_cred_res *clnt_res;
CLIENT *clnt;
{
return (clnt_call(clnt, GSS_INQUIRE_CRED,
(xdrproc_t)xdr_gss_inquire_cred_arg, (caddr_t)argp,
(xdrproc_t)xdr_gss_inquire_cred_res, (caddr_t)clnt_res,
gssd_timeout));
}
enum clnt_stat
gss_seal_1(argp, clnt_res, clnt)
gss_seal_arg *argp;
gss_seal_res *clnt_res;
CLIENT *clnt;
{
return (clnt_call(clnt, GSS_SEAL,
(xdrproc_t)xdr_gss_seal_arg, (caddr_t)argp,
(xdrproc_t)xdr_gss_seal_res, (caddr_t)clnt_res,
gssd_timeout));
}
enum clnt_stat
gss_unseal_1(argp, clnt_res, clnt)
gss_unseal_arg *argp;
gss_unseal_res *clnt_res;
CLIENT *clnt;
{
return (clnt_call(clnt, GSS_UNSEAL,
(xdrproc_t)xdr_gss_unseal_arg, (caddr_t)argp,
(xdrproc_t)xdr_gss_unseal_res, (caddr_t)clnt_res,
gssd_timeout));
}
enum clnt_stat
gsscred_expname_to_unix_cred_1(argp, clnt_res, clnt)
gsscred_expname_to_unix_cred_arg *argp;
gsscred_expname_to_unix_cred_res *clnt_res;
CLIENT *clnt;
{
return (clnt_call(clnt, GSSCRED_EXPNAME_TO_UNIX_CRED,
(xdrproc_t)xdr_gsscred_expname_to_unix_cred_arg, (caddr_t)argp,
(xdrproc_t)xdr_gsscred_expname_to_unix_cred_res, (caddr_t)clnt_res,
gssd_timeout));
}
enum clnt_stat
gsscred_name_to_unix_cred_1(argp, clnt_res, clnt)
gsscred_name_to_unix_cred_arg *argp;
gsscred_name_to_unix_cred_res *clnt_res;
CLIENT *clnt;
{
return (clnt_call(clnt, GSSCRED_NAME_TO_UNIX_CRED,
(xdrproc_t)xdr_gsscred_name_to_unix_cred_arg, (caddr_t)argp,
(xdrproc_t)xdr_gsscred_name_to_unix_cred_res, (caddr_t)clnt_res,
gssd_timeout));
}
enum clnt_stat
gss_get_group_info_1(argp, clnt_res, clnt)
gss_get_group_info_arg *argp;
gss_get_group_info_res *clnt_res;
CLIENT *clnt;
{
return (clnt_call(clnt, GSS_GET_GROUP_INFO,
(xdrproc_t)xdr_gss_get_group_info_arg, (caddr_t)argp,
(xdrproc_t)xdr_gss_get_group_info_res, (caddr_t)clnt_res,
gssd_timeout));
}
enum clnt_stat
gss_get_kmod_1(argp, clnt_res, clnt)
gss_get_kmod_arg *argp;
gss_get_kmod_res *clnt_res;
CLIENT *clnt;
{
return (clnt_call(clnt, GSS_GET_KMOD,
(xdrproc_t)xdr_gss_get_kmod_arg, (caddr_t)argp,
(xdrproc_t)xdr_gss_get_kmod_res, (caddr_t)clnt_res,
gssd_timeout));
}
enum clnt_stat
gss_export_sec_context_1(argp, clnt_res, clnt)
gss_export_sec_context_arg *argp;
gss_export_sec_context_res *clnt_res;
CLIENT *clnt;
{
return (clnt_call(clnt, GSS_EXPORT_SEC_CONTEXT,
(xdrproc_t)xdr_gss_export_sec_context_arg, (caddr_t)argp,
(xdrproc_t)xdr_gss_export_sec_context_res, (caddr_t)clnt_res,
gssd_timeout));
}
enum clnt_stat
gss_import_sec_context_1(argp, clnt_res, clnt)
gss_import_sec_context_arg *argp;
gss_import_sec_context_res *clnt_res;
CLIENT *clnt;
{
return (clnt_call(clnt, GSS_IMPORT_SEC_CONTEXT,
(xdrproc_t)xdr_gss_import_sec_context_arg, (caddr_t)argp,
(xdrproc_t)xdr_gss_import_sec_context_res, (caddr_t)clnt_res,
gssd_timeout));
}
enum clnt_stat
gss_add_cred_1(argp, clnt_res, clnt)
gss_add_cred_arg *argp;
gss_add_cred_res *clnt_res;
CLIENT *clnt;
{
return (clnt_call(clnt, GSS_ADD_CRED,
(xdrproc_t)xdr_gss_add_cred_arg, (caddr_t)argp,
(xdrproc_t)xdr_gss_add_cred_res, (caddr_t)clnt_res,
gssd_timeout));
}
enum clnt_stat
gss_inquire_cred_by_mech_1(argp, clnt_res, clnt)
gss_inquire_cred_by_mech_arg *argp;
gss_inquire_cred_by_mech_res *clnt_res;
CLIENT *clnt;
{
return (clnt_call(clnt, GSS_INQUIRE_CRED_BY_MECH,
(xdrproc_t)xdr_gss_inquire_cred_by_mech_arg, (caddr_t)argp,
(xdrproc_t)xdr_gss_inquire_cred_by_mech_res, (caddr_t)clnt_res,
gssd_timeout));
}
/*
* Please do not edit this file.
* It was generated using rpcgen.
*/
#ifndef _GSSD_H_RPCGEN
#define _GSSD_H_RPCGEN
#include <rpc/rpc.h>
#ifndef _KERNEL
#include <synch.h>
#include <thread.h>
#endif /* !_KERNEL */
#ifdef __cplusplus
extern "C" {
#endif
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* RPC protocol information for gssd, the usermode daemon that
* assists the kernel with gssapi. It is gssd that executes all
* gssapi calls except for some such as gss_sign(), and
* gss_verify(), which are executed in the kernel itself.
*
* File generated from gssd.x
*/
#define NO 0
#define YES 1
#define FOREVER 1
#include <sys/types.h>
#include <sys/time.h>
#include <rpc/auth_sys.h>
#ifndef _KERNEL
#include <locale.h>
#endif /* not _KERNEL */
#ifdef _KERNEL
extern void killgssd_handle(CLIENT *);
extern CLIENT *getgssd_handle(void);
#endif /* _KERNEL */
typedef u_int OM_UINT32;
typedef struct {
u_int GSS_CTX_ID_T_len;
char *GSS_CTX_ID_T_val;
} GSS_CTX_ID_T;
typedef struct {
u_int GSS_CRED_ID_T_len;
char *GSS_CRED_ID_T_val;
} GSS_CRED_ID_T;
typedef struct {
u_int GSS_OID_len;
char *GSS_OID_val;
} GSS_OID;
typedef struct {
u_int GSS_BUFFER_T_len;
char *GSS_BUFFER_T_val;
} GSS_BUFFER_T;
typedef struct {
u_int GSSCRED_GIDS_len;
gid_t *GSSCRED_GIDS_val;
} GSSCRED_GIDS;
typedef struct {
u_int GSS_OID_SET_len;
GSS_OID *GSS_OID_SET_val;
} GSS_OID_SET;
struct GSS_CHANNEL_BINDINGS_STRUCT {
int present;
OM_UINT32 initiator_addrtype;
GSS_BUFFER_T initiator_address;
OM_UINT32 acceptor_addrtype;
GSS_BUFFER_T acceptor_address;
GSS_BUFFER_T application_data;
};
typedef struct GSS_CHANNEL_BINDINGS_STRUCT GSS_CHANNEL_BINDINGS_STRUCT;
typedef GSS_CHANNEL_BINDINGS_STRUCT GSS_CHANNEL_BINDINGS;
struct gss_acquire_cred_arg {
uid_t uid;
GSS_BUFFER_T desired_name;
GSS_OID name_type;
OM_UINT32 time_req;
GSS_OID_SET desired_mechs;
int cred_usage;
};
typedef struct gss_acquire_cred_arg gss_acquire_cred_arg;
struct gss_acquire_cred_res {
OM_UINT32 minor_status;
GSS_CRED_ID_T output_cred_handle;
OM_UINT32 gssd_cred_verifier;
GSS_OID_SET actual_mechs;
OM_UINT32 time_rec;
OM_UINT32 status;
};
typedef struct gss_acquire_cred_res gss_acquire_cred_res;
struct gss_add_cred_arg {
uid_t uid;
GSS_CRED_ID_T input_cred_handle;
OM_UINT32 gssd_cred_verifier;
GSS_BUFFER_T desired_name;
GSS_OID name_type;
GSS_OID desired_mech_type;
int cred_usage;
OM_UINT32 initiator_time_req;
OM_UINT32 acceptor_time_req;
};
typedef struct gss_add_cred_arg gss_add_cred_arg;
struct gss_add_cred_res {
OM_UINT32 minor_status;
GSS_OID_SET actual_mechs;
OM_UINT32 initiator_time_rec;
OM_UINT32 acceptor_time_rec;
OM_UINT32 status;
};
typedef struct gss_add_cred_res gss_add_cred_res;
struct gss_release_cred_arg {
uid_t uid;
OM_UINT32 gssd_cred_verifier;
GSS_CRED_ID_T cred_handle;
};
typedef struct gss_release_cred_arg gss_release_cred_arg;
struct gss_release_cred_res {
OM_UINT32 minor_status;
OM_UINT32 status;
};
typedef struct gss_release_cred_res gss_release_cred_res;
struct gss_init_sec_context_arg {
uid_t uid;
GSS_CTX_ID_T context_handle;
OM_UINT32 gssd_context_verifier;
GSS_CRED_ID_T claimant_cred_handle;
OM_UINT32 gssd_cred_verifier;
GSS_BUFFER_T target_name;
GSS_OID name_type;
GSS_OID mech_type;
int req_flags;
OM_UINT32 time_req;
GSS_CHANNEL_BINDINGS input_chan_bindings;
GSS_BUFFER_T input_token;
};
typedef struct gss_init_sec_context_arg gss_init_sec_context_arg;
struct gss_init_sec_context_res {
GSS_CTX_ID_T context_handle;
OM_UINT32 gssd_context_verifier;
OM_UINT32 minor_status;
GSS_OID actual_mech_type;
GSS_BUFFER_T output_token;
OM_UINT32 ret_flags;
OM_UINT32 time_rec;
OM_UINT32 status;
};
typedef struct gss_init_sec_context_res gss_init_sec_context_res;
struct gss_accept_sec_context_arg {
uid_t uid;
GSS_CTX_ID_T context_handle;
OM_UINT32 gssd_context_verifier;
GSS_CRED_ID_T verifier_cred_handle;
OM_UINT32 gssd_cred_verifier;
GSS_BUFFER_T input_token_buffer;
GSS_CHANNEL_BINDINGS input_chan_bindings;
};
typedef struct gss_accept_sec_context_arg gss_accept_sec_context_arg;
struct gss_accept_sec_context_res {
GSS_CTX_ID_T context_handle;
OM_UINT32 gssd_context_verifier;
OM_UINT32 minor_status;
GSS_BUFFER_T src_name;
GSS_OID mech_type;
GSS_BUFFER_T output_token;
OM_UINT32 ret_flags;
OM_UINT32 time_rec;
GSS_CRED_ID_T delegated_cred_handle;
OM_UINT32 status;
};
typedef struct gss_accept_sec_context_res gss_accept_sec_context_res;
struct gss_process_context_token_arg {
uid_t uid;
OM_UINT32 gssd_context_verifier;
GSS_CTX_ID_T context_handle;
GSS_BUFFER_T token_buffer;
};
typedef struct gss_process_context_token_arg gss_process_context_token_arg;
struct gss_process_context_token_res {
OM_UINT32 minor_status;
OM_UINT32 status;
};
typedef struct gss_process_context_token_res gss_process_context_token_res;
struct gss_delete_sec_context_arg {
OM_UINT32 gssd_context_verifier;
GSS_CTX_ID_T context_handle;
};
typedef struct gss_delete_sec_context_arg gss_delete_sec_context_arg;
struct gss_delete_sec_context_res {
OM_UINT32 minor_status;
GSS_CTX_ID_T context_handle;
GSS_BUFFER_T output_token;
OM_UINT32 status;
};
typedef struct gss_delete_sec_context_res gss_delete_sec_context_res;
struct gss_export_sec_context_arg {
GSS_CTX_ID_T context_handle;
OM_UINT32 gssd_context_verifier;
};
typedef struct gss_export_sec_context_arg gss_export_sec_context_arg;
struct gss_export_sec_context_res {
OM_UINT32 minor_status;
GSS_CTX_ID_T context_handle;
GSS_BUFFER_T output_token;
OM_UINT32 status;
};
typedef struct gss_export_sec_context_res gss_export_sec_context_res;
struct gss_import_sec_context_arg {
GSS_BUFFER_T input_token;
OM_UINT32 gssd_context_verifier;
};
typedef struct gss_import_sec_context_arg gss_import_sec_context_arg;
struct gss_import_sec_context_res {
OM_UINT32 minor_status;
GSS_CTX_ID_T context_handle;
OM_UINT32 status;
};
typedef struct gss_import_sec_context_res gss_import_sec_context_res;
struct gss_context_time_arg {
uid_t uid;
OM_UINT32 gssd_context_verifier;
GSS_CTX_ID_T context_handle;
};
typedef struct gss_context_time_arg gss_context_time_arg;
struct gss_context_time_res {
OM_UINT32 minor_status;
OM_UINT32 time_rec;
OM_UINT32 status;
};
typedef struct gss_context_time_res gss_context_time_res;
struct gss_sign_arg {
OM_UINT32 gssd_context_verifier;
GSS_CTX_ID_T context_handle;
int qop_req;
GSS_BUFFER_T message_buffer;
};
typedef struct gss_sign_arg gss_sign_arg;
struct gss_sign_res {
OM_UINT32 minor_status;
GSS_BUFFER_T msg_token;
OM_UINT32 status;
};
typedef struct gss_sign_res gss_sign_res;
struct gss_verify_arg {
OM_UINT32 gssd_context_verifier;
GSS_CTX_ID_T context_handle;
GSS_BUFFER_T message_buffer;
GSS_BUFFER_T token_buffer;
};
typedef struct gss_verify_arg gss_verify_arg;
struct gss_verify_res {
OM_UINT32 minor_status;
int qop_state;
OM_UINT32 status;
};
typedef struct gss_verify_res gss_verify_res;
struct gss_seal_arg {
OM_UINT32 gssd_context_verifier;
GSS_CTX_ID_T context_handle;
int conf_req_flag;
int qop_req;
GSS_BUFFER_T input_message_buffer;
};
typedef struct gss_seal_arg gss_seal_arg;
struct gss_seal_res {
OM_UINT32 minor_status;
int conf_state;
GSS_BUFFER_T output_message_buffer;
OM_UINT32 status;
};
typedef struct gss_seal_res gss_seal_res;
struct gss_unseal_arg {
OM_UINT32 gssd_context_verifier;
GSS_CTX_ID_T context_handle;
GSS_BUFFER_T input_message_buffer;
};
typedef struct gss_unseal_arg gss_unseal_arg;
struct gss_unseal_res {
OM_UINT32 minor_status;
GSS_BUFFER_T output_message_buffer;
int conf_state;
int qop_state;
OM_UINT32 status;
};
typedef struct gss_unseal_res gss_unseal_res;
struct gss_display_status_arg {
uid_t uid;
int status_value;
int status_type;
GSS_OID mech_type;
OM_UINT32 message_context;
};
typedef struct gss_display_status_arg gss_display_status_arg;
struct gss_display_status_res {
OM_UINT32 minor_status;
int message_context;
GSS_BUFFER_T status_string;
OM_UINT32 status;
};
typedef struct gss_display_status_res gss_display_status_res;
/* gss_indicate_mechs_arg is void. This appears in the rpc call def */
struct gss_indicate_mechs_res {
OM_UINT32 minor_status;
GSS_OID_SET mech_set;
OM_UINT32 status;
};
typedef struct gss_indicate_mechs_res gss_indicate_mechs_res;
struct gss_inquire_cred_arg {
uid_t uid;
OM_UINT32 gssd_cred_verifier;
GSS_CRED_ID_T cred_handle;
};
typedef struct gss_inquire_cred_arg gss_inquire_cred_arg;
struct gss_inquire_cred_res {
OM_UINT32 minor_status;
GSS_BUFFER_T name;
GSS_OID name_type;
OM_UINT32 lifetime;
int cred_usage;
GSS_OID_SET mechanisms;
OM_UINT32 status;
};
typedef struct gss_inquire_cred_res gss_inquire_cred_res;
struct gss_inquire_cred_by_mech_arg {
uid_t uid;
OM_UINT32 gssd_cred_verifier;
GSS_CRED_ID_T cred_handle;
GSS_OID mech_type;
};
typedef struct gss_inquire_cred_by_mech_arg gss_inquire_cred_by_mech_arg;
struct gss_inquire_cred_by_mech_res {
OM_UINT32 minor_status;
OM_UINT32 status;
};
typedef struct gss_inquire_cred_by_mech_res gss_inquire_cred_by_mech_res;
struct gsscred_name_to_unix_cred_arg {
uid_t uid;
GSS_BUFFER_T pname;
GSS_OID name_type;
GSS_OID mech_type;
};
typedef struct gsscred_name_to_unix_cred_arg gsscred_name_to_unix_cred_arg;
struct gsscred_name_to_unix_cred_res {
uid_t uid;
gid_t gid;
GSSCRED_GIDS gids;
OM_UINT32 major;
};
typedef struct gsscred_name_to_unix_cred_res gsscred_name_to_unix_cred_res;
struct gsscred_expname_to_unix_cred_arg {
uid_t uid;
GSS_BUFFER_T expname;
};
typedef struct gsscred_expname_to_unix_cred_arg gsscred_expname_to_unix_cred_arg;
struct gsscred_expname_to_unix_cred_res {
uid_t uid;
gid_t gid;
GSSCRED_GIDS gids;
OM_UINT32 major;
};
typedef struct gsscred_expname_to_unix_cred_res gsscred_expname_to_unix_cred_res;
struct gss_get_group_info_arg {
uid_t uid;
uid_t puid;
};
typedef struct gss_get_group_info_arg gss_get_group_info_arg;
struct gss_get_group_info_res {
gid_t gid;
GSSCRED_GIDS gids;
OM_UINT32 major;
};
typedef struct gss_get_group_info_res gss_get_group_info_res;
struct gss_get_kmod_arg {
GSS_OID mech_oid;
};
typedef struct gss_get_kmod_arg gss_get_kmod_arg;
struct gss_get_kmod_res {
bool_t module_follow;
union {
char *modname;
} gss_get_kmod_res_u;
};
typedef struct gss_get_kmod_res gss_get_kmod_res;
#define GSSPROG 100234
#define GSSVERS 1
#if defined(__STDC__) || defined(__cplusplus)
#define GSS_ACQUIRE_CRED 1
extern enum clnt_stat gss_acquire_cred_1(gss_acquire_cred_arg *, gss_acquire_cred_res *, CLIENT *);
extern bool_t gss_acquire_cred_1_svc(gss_acquire_cred_arg *, gss_acquire_cred_res *, struct svc_req *);
#define GSS_RELEASE_CRED 2
extern enum clnt_stat gss_release_cred_1(gss_release_cred_arg *, gss_release_cred_res *, CLIENT *);
extern bool_t gss_release_cred_1_svc(gss_release_cred_arg *, gss_release_cred_res *, struct svc_req *);
#define GSS_INIT_SEC_CONTEXT 3
extern enum clnt_stat gss_init_sec_context_1(gss_init_sec_context_arg *, gss_init_sec_context_res *, CLIENT *);
extern bool_t gss_init_sec_context_1_svc(gss_init_sec_context_arg *, gss_init_sec_context_res *, struct svc_req *);
#define GSS_ACCEPT_SEC_CONTEXT 4
extern enum clnt_stat gss_accept_sec_context_1(gss_accept_sec_context_arg *, gss_accept_sec_context_res *, CLIENT *);
extern bool_t gss_accept_sec_context_1_svc(gss_accept_sec_context_arg *, gss_accept_sec_context_res *, struct svc_req *);
#define GSS_PROCESS_CONTEXT_TOKEN 5
extern enum clnt_stat gss_process_context_token_1(gss_process_context_token_arg *, gss_process_context_token_res *, CLIENT *);
extern bool_t gss_process_context_token_1_svc(gss_process_context_token_arg *, gss_process_context_token_res *, struct svc_req *);
#define GSS_DELETE_SEC_CONTEXT 6
extern enum clnt_stat gss_delete_sec_context_1(gss_delete_sec_context_arg *, gss_delete_sec_context_res *, CLIENT *);
extern bool_t gss_delete_sec_context_1_svc(gss_delete_sec_context_arg *, gss_delete_sec_context_res *, struct svc_req *);
#define GSS_CONTEXT_TIME 7
extern enum clnt_stat gss_context_time_1(gss_context_time_arg *, gss_context_time_res *, CLIENT *);
extern bool_t gss_context_time_1_svc(gss_context_time_arg *, gss_context_time_res *, struct svc_req *);
#define GSS_SIGN 8
extern enum clnt_stat gss_sign_1(gss_sign_arg *, gss_sign_res *, CLIENT *);
extern bool_t gss_sign_1_svc(gss_sign_arg *, gss_sign_res *, struct svc_req *);
#define GSS_VERIFY 9
extern enum clnt_stat gss_verify_1(gss_verify_arg *, gss_verify_res *, CLIENT *);
extern bool_t gss_verify_1_svc(gss_verify_arg *, gss_verify_res *, struct svc_req *);
#define GSS_DISPLAY_STATUS 10
extern enum clnt_stat gss_display_status_1(gss_display_status_arg *, gss_display_status_res *, CLIENT *);
extern bool_t gss_display_status_1_svc(gss_display_status_arg *, gss_display_status_res *, struct svc_req *);
#define GSS_INDICATE_MECHS 11
extern enum clnt_stat gss_indicate_mechs_1(void *, gss_indicate_mechs_res *, CLIENT *);
extern bool_t gss_indicate_mechs_1_svc(void *, gss_indicate_mechs_res *, struct svc_req *);
#define GSS_INQUIRE_CRED 12
extern enum clnt_stat gss_inquire_cred_1(gss_inquire_cred_arg *, gss_inquire_cred_res *, CLIENT *);
extern bool_t gss_inquire_cred_1_svc(gss_inquire_cred_arg *, gss_inquire_cred_res *, struct svc_req *);
#define GSS_SEAL 13
extern enum clnt_stat gss_seal_1(gss_seal_arg *, gss_seal_res *, CLIENT *);
extern bool_t gss_seal_1_svc(gss_seal_arg *, gss_seal_res *, struct svc_req *);
#define GSS_UNSEAL 14
extern enum clnt_stat gss_unseal_1(gss_unseal_arg *, gss_unseal_res *, CLIENT *);
extern bool_t gss_unseal_1_svc(gss_unseal_arg *, gss_unseal_res *, struct svc_req *);
#define GSSCRED_EXPNAME_TO_UNIX_CRED 15
extern enum clnt_stat gsscred_expname_to_unix_cred_1(gsscred_expname_to_unix_cred_arg *, gsscred_expname_to_unix_cred_res *, CLIENT *);
extern bool_t gsscred_expname_to_unix_cred_1_svc(gsscred_expname_to_unix_cred_arg *, gsscred_expname_to_unix_cred_res *, struct svc_req *);
#define GSSCRED_NAME_TO_UNIX_CRED 16
extern enum clnt_stat gsscred_name_to_unix_cred_1(gsscred_name_to_unix_cred_arg *, gsscred_name_to_unix_cred_res *, CLIENT *);
extern bool_t gsscred_name_to_unix_cred_1_svc(gsscred_name_to_unix_cred_arg *, gsscred_name_to_unix_cred_res *, struct svc_req *);
#define GSS_GET_GROUP_INFO 17
extern enum clnt_stat gss_get_group_info_1(gss_get_group_info_arg *, gss_get_group_info_res *, CLIENT *);
extern bool_t gss_get_group_info_1_svc(gss_get_group_info_arg *, gss_get_group_info_res *, struct svc_req *);
#define GSS_GET_KMOD 18
extern enum clnt_stat gss_get_kmod_1(gss_get_kmod_arg *, gss_get_kmod_res *, CLIENT *);
extern bool_t gss_get_kmod_1_svc(gss_get_kmod_arg *, gss_get_kmod_res *, struct svc_req *);
#define GSS_EXPORT_SEC_CONTEXT 19
extern enum clnt_stat gss_export_sec_context_1(gss_export_sec_context_arg *, gss_export_sec_context_res *, CLIENT *);
extern bool_t gss_export_sec_context_1_svc(gss_export_sec_context_arg *, gss_export_sec_context_res *, struct svc_req *);
#define GSS_IMPORT_SEC_CONTEXT 20
extern enum clnt_stat gss_import_sec_context_1(gss_import_sec_context_arg *, gss_import_sec_context_res *, CLIENT *);
extern bool_t gss_import_sec_context_1_svc(gss_import_sec_context_arg *, gss_import_sec_context_res *, struct svc_req *);
#define GSS_ADD_CRED 21
extern enum clnt_stat gss_add_cred_1(gss_add_cred_arg *, gss_add_cred_res *, CLIENT *);
extern bool_t gss_add_cred_1_svc(gss_add_cred_arg *, gss_add_cred_res *, struct svc_req *);
#define GSS_INQUIRE_CRED_BY_MECH 22
extern enum clnt_stat gss_inquire_cred_by_mech_1(gss_inquire_cred_by_mech_arg *, gss_inquire_cred_by_mech_res *, CLIENT *);
extern bool_t gss_inquire_cred_by_mech_1_svc(gss_inquire_cred_by_mech_arg *, gss_inquire_cred_by_mech_res *, struct svc_req *);
extern int gssprog_1_freeresult(SVCXPRT *, xdrproc_t, caddr_t);
#else /* K&R C */
#define GSS_ACQUIRE_CRED 1
extern enum clnt_stat gss_acquire_cred_1();
extern bool_t gss_acquire_cred_1_svc();
#define GSS_RELEASE_CRED 2
extern enum clnt_stat gss_release_cred_1();
extern bool_t gss_release_cred_1_svc();
#define GSS_INIT_SEC_CONTEXT 3
extern enum clnt_stat gss_init_sec_context_1();
extern bool_t gss_init_sec_context_1_svc();
#define GSS_ACCEPT_SEC_CONTEXT 4
extern enum clnt_stat gss_accept_sec_context_1();
extern bool_t gss_accept_sec_context_1_svc();
#define GSS_PROCESS_CONTEXT_TOKEN 5
extern enum clnt_stat gss_process_context_token_1();
extern bool_t gss_process_context_token_1_svc();
#define GSS_DELETE_SEC_CONTEXT 6
extern enum clnt_stat gss_delete_sec_context_1();
extern bool_t gss_delete_sec_context_1_svc();
#define GSS_CONTEXT_TIME 7
extern enum clnt_stat gss_context_time_1();
extern bool_t gss_context_time_1_svc();
#define GSS_SIGN 8
extern enum clnt_stat gss_sign_1();
extern bool_t gss_sign_1_svc();
#define GSS_VERIFY 9
extern enum clnt_stat gss_verify_1();
extern bool_t gss_verify_1_svc();
#define GSS_DISPLAY_STATUS 10
extern enum clnt_stat gss_display_status_1();
extern bool_t gss_display_status_1_svc();
#define GSS_INDICATE_MECHS 11
extern enum clnt_stat gss_indicate_mechs_1();
extern bool_t gss_indicate_mechs_1_svc();
#define GSS_INQUIRE_CRED 12
extern enum clnt_stat gss_inquire_cred_1();
extern bool_t gss_inquire_cred_1_svc();
#define GSS_SEAL 13
extern enum clnt_stat gss_seal_1();
extern bool_t gss_seal_1_svc();
#define GSS_UNSEAL 14
extern enum clnt_stat gss_unseal_1();
extern bool_t gss_unseal_1_svc();
#define GSSCRED_EXPNAME_TO_UNIX_CRED 15
extern enum clnt_stat gsscred_expname_to_unix_cred_1();
extern bool_t gsscred_expname_to_unix_cred_1_svc();
#define GSSCRED_NAME_TO_UNIX_CRED 16
extern enum clnt_stat gsscred_name_to_unix_cred_1();
extern bool_t gsscred_name_to_unix_cred_1_svc();
#define GSS_GET_GROUP_INFO 17
extern enum clnt_stat gss_get_group_info_1();
extern bool_t gss_get_group_info_1_svc();
#define GSS_GET_KMOD 18
extern enum clnt_stat gss_get_kmod_1();
extern bool_t gss_get_kmod_1_svc();
#define GSS_EXPORT_SEC_CONTEXT 19
extern enum clnt_stat gss_export_sec_context_1();
extern bool_t gss_export_sec_context_1_svc();
#define GSS_IMPORT_SEC_CONTEXT 20
extern enum clnt_stat gss_import_sec_context_1();
extern bool_t gss_import_sec_context_1_svc();
#define GSS_ADD_CRED 21
extern enum clnt_stat gss_add_cred_1();
extern bool_t gss_add_cred_1_svc();
#define GSS_INQUIRE_CRED_BY_MECH 22
extern enum clnt_stat gss_inquire_cred_by_mech_1();
extern bool_t gss_inquire_cred_by_mech_1_svc();
extern int gssprog_1_freeresult();
#endif /* K&R C */
/* the xdr functions */
#if defined(__STDC__) || defined(__cplusplus)
extern bool_t xdr_OM_UINT32(XDR *, OM_UINT32*);
extern bool_t xdr_GSS_CTX_ID_T(XDR *, GSS_CTX_ID_T*);
extern bool_t xdr_GSS_CRED_ID_T(XDR *, GSS_CRED_ID_T*);
extern bool_t xdr_GSS_OID(XDR *, GSS_OID*);
extern bool_t xdr_GSS_BUFFER_T(XDR *, GSS_BUFFER_T*);
extern bool_t xdr_GSSCRED_GIDS(XDR *, GSSCRED_GIDS*);
extern bool_t xdr_GSS_OID_SET(XDR *, GSS_OID_SET*);
extern bool_t xdr_GSS_CHANNEL_BINDINGS_STRUCT(XDR *, GSS_CHANNEL_BINDINGS_STRUCT*);
extern bool_t xdr_GSS_CHANNEL_BINDINGS(XDR *, GSS_CHANNEL_BINDINGS*);
extern bool_t xdr_gss_acquire_cred_arg(XDR *, gss_acquire_cred_arg*);
extern bool_t xdr_gss_acquire_cred_res(XDR *, gss_acquire_cred_res*);
extern bool_t xdr_gss_add_cred_arg(XDR *, gss_add_cred_arg*);
extern bool_t xdr_gss_add_cred_res(XDR *, gss_add_cred_res*);
extern bool_t xdr_gss_release_cred_arg(XDR *, gss_release_cred_arg*);
extern bool_t xdr_gss_release_cred_res(XDR *, gss_release_cred_res*);
extern bool_t xdr_gss_init_sec_context_arg(XDR *, gss_init_sec_context_arg*);
extern bool_t xdr_gss_init_sec_context_res(XDR *, gss_init_sec_context_res*);
extern bool_t xdr_gss_accept_sec_context_arg(XDR *, gss_accept_sec_context_arg*);
extern bool_t xdr_gss_accept_sec_context_res(XDR *, gss_accept_sec_context_res*);
extern bool_t xdr_gss_process_context_token_arg(XDR *, gss_process_context_token_arg*);
extern bool_t xdr_gss_process_context_token_res(XDR *, gss_process_context_token_res*);
extern bool_t xdr_gss_delete_sec_context_arg(XDR *, gss_delete_sec_context_arg*);
extern bool_t xdr_gss_delete_sec_context_res(XDR *, gss_delete_sec_context_res*);
extern bool_t xdr_gss_export_sec_context_arg(XDR *, gss_export_sec_context_arg*);
extern bool_t xdr_gss_export_sec_context_res(XDR *, gss_export_sec_context_res*);
extern bool_t xdr_gss_import_sec_context_arg(XDR *, gss_import_sec_context_arg*);
extern bool_t xdr_gss_import_sec_context_res(XDR *, gss_import_sec_context_res*);
extern bool_t xdr_gss_context_time_arg(XDR *, gss_context_time_arg*);
extern bool_t xdr_gss_context_time_res(XDR *, gss_context_time_res*);
extern bool_t xdr_gss_sign_arg(XDR *, gss_sign_arg*);
extern bool_t xdr_gss_sign_res(XDR *, gss_sign_res*);
extern bool_t xdr_gss_verify_arg(XDR *, gss_verify_arg*);
extern bool_t xdr_gss_verify_res(XDR *, gss_verify_res*);
extern bool_t xdr_gss_seal_arg(XDR *, gss_seal_arg*);
extern bool_t xdr_gss_seal_res(XDR *, gss_seal_res*);
extern bool_t xdr_gss_unseal_arg(XDR *, gss_unseal_arg*);
extern bool_t xdr_gss_unseal_res(XDR *, gss_unseal_res*);
extern bool_t xdr_gss_display_status_arg(XDR *, gss_display_status_arg*);
extern bool_t xdr_gss_display_status_res(XDR *, gss_display_status_res*);
extern bool_t xdr_gss_indicate_mechs_res(XDR *, gss_indicate_mechs_res*);
extern bool_t xdr_gss_inquire_cred_arg(XDR *, gss_inquire_cred_arg*);
extern bool_t xdr_gss_inquire_cred_res(XDR *, gss_inquire_cred_res*);
extern bool_t xdr_gss_inquire_cred_by_mech_arg(XDR *, gss_inquire_cred_by_mech_arg*);
extern bool_t xdr_gss_inquire_cred_by_mech_res(XDR *, gss_inquire_cred_by_mech_res*);
extern bool_t xdr_gsscred_name_to_unix_cred_arg(XDR *, gsscred_name_to_unix_cred_arg*);
extern bool_t xdr_gsscred_name_to_unix_cred_res(XDR *, gsscred_name_to_unix_cred_res*);
extern bool_t xdr_gsscred_expname_to_unix_cred_arg(XDR *, gsscred_expname_to_unix_cred_arg*);
extern bool_t xdr_gsscred_expname_to_unix_cred_res(XDR *, gsscred_expname_to_unix_cred_res*);
extern bool_t xdr_gss_get_group_info_arg(XDR *, gss_get_group_info_arg*);
extern bool_t xdr_gss_get_group_info_res(XDR *, gss_get_group_info_res*);
extern bool_t xdr_gss_get_kmod_arg(XDR *, gss_get_kmod_arg*);
extern bool_t xdr_gss_get_kmod_res(XDR *, gss_get_kmod_res*);
#else /* K&R C */
extern bool_t xdr_OM_UINT32();
extern bool_t xdr_GSS_CTX_ID_T();
extern bool_t xdr_GSS_CRED_ID_T();
extern bool_t xdr_GSS_OID();
extern bool_t xdr_GSS_BUFFER_T();
extern bool_t xdr_GSSCRED_GIDS();
extern bool_t xdr_GSS_OID_SET();
extern bool_t xdr_GSS_CHANNEL_BINDINGS_STRUCT();
extern bool_t xdr_GSS_CHANNEL_BINDINGS();
extern bool_t xdr_gss_acquire_cred_arg();
extern bool_t xdr_gss_acquire_cred_res();
extern bool_t xdr_gss_add_cred_arg();
extern bool_t xdr_gss_add_cred_res();
extern bool_t xdr_gss_release_cred_arg();
extern bool_t xdr_gss_release_cred_res();
extern bool_t xdr_gss_init_sec_context_arg();
extern bool_t xdr_gss_init_sec_context_res();
extern bool_t xdr_gss_accept_sec_context_arg();
extern bool_t xdr_gss_accept_sec_context_res();
extern bool_t xdr_gss_process_context_token_arg();
extern bool_t xdr_gss_process_context_token_res();
extern bool_t xdr_gss_delete_sec_context_arg();
extern bool_t xdr_gss_delete_sec_context_res();
extern bool_t xdr_gss_export_sec_context_arg();
extern bool_t xdr_gss_export_sec_context_res();
extern bool_t xdr_gss_import_sec_context_arg();
extern bool_t xdr_gss_import_sec_context_res();
extern bool_t xdr_gss_context_time_arg();
extern bool_t xdr_gss_context_time_res();
extern bool_t xdr_gss_sign_arg();
extern bool_t xdr_gss_sign_res();
extern bool_t xdr_gss_verify_arg();
extern bool_t xdr_gss_verify_res();
extern bool_t xdr_gss_seal_arg();
extern bool_t xdr_gss_seal_res();
extern bool_t xdr_gss_unseal_arg();
extern bool_t xdr_gss_unseal_res();
extern bool_t xdr_gss_display_status_arg();
extern bool_t xdr_gss_display_status_res();
extern bool_t xdr_gss_indicate_mechs_res();
extern bool_t xdr_gss_inquire_cred_arg();
extern bool_t xdr_gss_inquire_cred_res();
extern bool_t xdr_gss_inquire_cred_by_mech_arg();
extern bool_t xdr_gss_inquire_cred_by_mech_res();
extern bool_t xdr_gsscred_name_to_unix_cred_arg();
extern bool_t xdr_gsscred_name_to_unix_cred_res();
extern bool_t xdr_gsscred_expname_to_unix_cred_arg();
extern bool_t xdr_gsscred_expname_to_unix_cred_res();
extern bool_t xdr_gss_get_group_info_arg();
extern bool_t xdr_gss_get_group_info_res();
extern bool_t xdr_gss_get_kmod_arg();
extern bool_t xdr_gss_get_kmod_res();
#endif /* K&R C */
#ifdef __cplusplus
}
#endif
#endif /* !_GSSD_H_RPCGEN */
/*
* Please do not edit this file.
* It was generated using rpcgen.
*/
#include "gssd_prot.h"
#ifndef _KERNEL
#include <stdlib.h>
#endif /* !_KERNEL */
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* RPC protocol information for gssd, the usermode daemon that
* assists the kernel with gssapi. It is gssd that executes all
* gssapi calls except for some such as gss_sign(), and
* gss_verify(), which are executed in the kernel itself.
*
* File generated from gssd.x
*/
#define NO 0
#define YES 1
#define FOREVER 1
#include <sys/types.h>
#include <sys/time.h>
#include <rpc/auth_sys.h>
#ifndef _KERNEL
#include <locale.h>
#endif /* not _KERNEL */
#ifdef _KERNEL
extern void killgssd_handle(CLIENT *);
extern CLIENT *getgssd_handle(void);
#endif /* _KERNEL */
bool_t
xdr_OM_UINT32(xdrs, objp)
XDR *xdrs;
OM_UINT32 *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_u_int(xdrs, objp))
return (FALSE);
return (TRUE);
}
bool_t
xdr_GSS_CTX_ID_T(xdrs, objp)
XDR *xdrs;
GSS_CTX_ID_T *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_bytes(xdrs, (char **)&objp->GSS_CTX_ID_T_val, (u_int *) &objp->GSS_CTX_ID_T_len, ~0))
return (FALSE);
return (TRUE);
}
bool_t
xdr_GSS_CRED_ID_T(xdrs, objp)
XDR *xdrs;
GSS_CRED_ID_T *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_bytes(xdrs, (char **)&objp->GSS_CRED_ID_T_val, (u_int *) &objp->GSS_CRED_ID_T_len, ~0))
return (FALSE);
return (TRUE);
}
bool_t
xdr_GSS_OID(xdrs, objp)
XDR *xdrs;
GSS_OID *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_bytes(xdrs, (char **)&objp->GSS_OID_val, (u_int *) &objp->GSS_OID_len, ~0))
return (FALSE);
return (TRUE);
}
bool_t
xdr_GSS_BUFFER_T(xdrs, objp)
XDR *xdrs;
GSS_BUFFER_T *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_bytes(xdrs, (char **)&objp->GSS_BUFFER_T_val, (u_int *) &objp->GSS_BUFFER_T_len, ~0))
return (FALSE);
return (TRUE);
}
bool_t
xdr_GSSCRED_GIDS(xdrs, objp)
XDR *xdrs;
GSSCRED_GIDS *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_array(xdrs, (char **)&objp->GSSCRED_GIDS_val, (u_int *) &objp->GSSCRED_GIDS_len, ~0,
sizeof (gid_t), (xdrproc_t)xdr_gid_t))
return (FALSE);
return (TRUE);
}
bool_t
xdr_GSS_OID_SET(xdrs, objp)
XDR *xdrs;
GSS_OID_SET *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_array(xdrs, (char **)&objp->GSS_OID_SET_val, (u_int *) &objp->GSS_OID_SET_len, ~0,
sizeof (GSS_OID), (xdrproc_t)xdr_GSS_OID))
return (FALSE);
return (TRUE);
}
bool_t
xdr_GSS_CHANNEL_BINDINGS_STRUCT(xdrs, objp)
XDR *xdrs;
GSS_CHANNEL_BINDINGS_STRUCT *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_int(xdrs, &objp->present))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->initiator_addrtype))
return (FALSE);
if (!xdr_GSS_BUFFER_T(xdrs, &objp->initiator_address))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->acceptor_addrtype))
return (FALSE);
if (!xdr_GSS_BUFFER_T(xdrs, &objp->acceptor_address))
return (FALSE);
if (!xdr_GSS_BUFFER_T(xdrs, &objp->application_data))
return (FALSE);
return (TRUE);
}
bool_t
xdr_GSS_CHANNEL_BINDINGS(xdrs, objp)
XDR *xdrs;
GSS_CHANNEL_BINDINGS *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_GSS_CHANNEL_BINDINGS_STRUCT(xdrs, objp))
return (FALSE);
return (TRUE);
}
bool_t
xdr_gss_acquire_cred_arg(xdrs, objp)
XDR *xdrs;
gss_acquire_cred_arg *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_uid_t(xdrs, &objp->uid))
return (FALSE);
if (!xdr_GSS_BUFFER_T(xdrs, &objp->desired_name))
return (FALSE);
if (!xdr_GSS_OID(xdrs, &objp->name_type))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->time_req))
return (FALSE);
if (!xdr_GSS_OID_SET(xdrs, &objp->desired_mechs))
return (FALSE);
if (!xdr_int(xdrs, &objp->cred_usage))
return (FALSE);
return (TRUE);
}
bool_t
xdr_gss_acquire_cred_res(xdrs, objp)
XDR *xdrs;
gss_acquire_cred_res *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_OM_UINT32(xdrs, &objp->minor_status))
return (FALSE);
if (!xdr_GSS_CRED_ID_T(xdrs, &objp->output_cred_handle))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->gssd_cred_verifier))
return (FALSE);
if (!xdr_GSS_OID_SET(xdrs, &objp->actual_mechs))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->time_rec))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->status))
return (FALSE);
return (TRUE);
}
bool_t
xdr_gss_add_cred_arg(xdrs, objp)
XDR *xdrs;
gss_add_cred_arg *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_uid_t(xdrs, &objp->uid))
return (FALSE);
if (!xdr_GSS_CRED_ID_T(xdrs, &objp->input_cred_handle))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->gssd_cred_verifier))
return (FALSE);
if (!xdr_GSS_BUFFER_T(xdrs, &objp->desired_name))
return (FALSE);
if (!xdr_GSS_OID(xdrs, &objp->name_type))
return (FALSE);
if (!xdr_GSS_OID(xdrs, &objp->desired_mech_type))
return (FALSE);
if (!xdr_int(xdrs, &objp->cred_usage))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->initiator_time_req))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->acceptor_time_req))
return (FALSE);
return (TRUE);
}
bool_t
xdr_gss_add_cred_res(xdrs, objp)
XDR *xdrs;
gss_add_cred_res *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_OM_UINT32(xdrs, &objp->minor_status))
return (FALSE);
if (!xdr_GSS_OID_SET(xdrs, &objp->actual_mechs))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->initiator_time_rec))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->acceptor_time_rec))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->status))
return (FALSE);
return (TRUE);
}
bool_t
xdr_gss_release_cred_arg(xdrs, objp)
XDR *xdrs;
gss_release_cred_arg *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_uid_t(xdrs, &objp->uid))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->gssd_cred_verifier))
return (FALSE);
if (!xdr_GSS_CRED_ID_T(xdrs, &objp->cred_handle))
return (FALSE);
return (TRUE);
}
bool_t
xdr_gss_release_cred_res(xdrs, objp)
XDR *xdrs;
gss_release_cred_res *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_OM_UINT32(xdrs, &objp->minor_status))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->status))
return (FALSE);
return (TRUE);
}
bool_t
xdr_gss_init_sec_context_arg(xdrs, objp)
XDR *xdrs;
gss_init_sec_context_arg *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_uid_t(xdrs, &objp->uid))
return (FALSE);
if (!xdr_GSS_CTX_ID_T(xdrs, &objp->context_handle))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->gssd_context_verifier))
return (FALSE);
if (!xdr_GSS_CRED_ID_T(xdrs, &objp->claimant_cred_handle))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->gssd_cred_verifier))
return (FALSE);
if (!xdr_GSS_BUFFER_T(xdrs, &objp->target_name))
return (FALSE);
if (!xdr_GSS_OID(xdrs, &objp->name_type))
return (FALSE);
if (!xdr_GSS_OID(xdrs, &objp->mech_type))
return (FALSE);
if (!xdr_int(xdrs, &objp->req_flags))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->time_req))
return (FALSE);
if (!xdr_GSS_CHANNEL_BINDINGS(xdrs, &objp->input_chan_bindings))
return (FALSE);
if (!xdr_GSS_BUFFER_T(xdrs, &objp->input_token))
return (FALSE);
return (TRUE);
}
bool_t
xdr_gss_init_sec_context_res(xdrs, objp)
XDR *xdrs;
gss_init_sec_context_res *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_GSS_CTX_ID_T(xdrs, &objp->context_handle))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->gssd_context_verifier))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->minor_status))
return (FALSE);
if (!xdr_GSS_OID(xdrs, &objp->actual_mech_type))
return (FALSE);
if (!xdr_GSS_BUFFER_T(xdrs, &objp->output_token))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->ret_flags))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->time_rec))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->status))
return (FALSE);
return (TRUE);
}
bool_t
xdr_gss_accept_sec_context_arg(xdrs, objp)
XDR *xdrs;
gss_accept_sec_context_arg *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_uid_t(xdrs, &objp->uid))
return (FALSE);
if (!xdr_GSS_CTX_ID_T(xdrs, &objp->context_handle))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->gssd_context_verifier))
return (FALSE);
if (!xdr_GSS_CRED_ID_T(xdrs, &objp->verifier_cred_handle))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->gssd_cred_verifier))
return (FALSE);
if (!xdr_GSS_BUFFER_T(xdrs, &objp->input_token_buffer))
return (FALSE);
if (!xdr_GSS_CHANNEL_BINDINGS(xdrs, &objp->input_chan_bindings))
return (FALSE);
return (TRUE);
}
bool_t
xdr_gss_accept_sec_context_res(xdrs, objp)
XDR *xdrs;
gss_accept_sec_context_res *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_GSS_CTX_ID_T(xdrs, &objp->context_handle))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->gssd_context_verifier))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->minor_status))
return (FALSE);
if (!xdr_GSS_BUFFER_T(xdrs, &objp->src_name))
return (FALSE);
if (!xdr_GSS_OID(xdrs, &objp->mech_type))
return (FALSE);
if (!xdr_GSS_BUFFER_T(xdrs, &objp->output_token))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->ret_flags))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->time_rec))
return (FALSE);
if (!xdr_GSS_CRED_ID_T(xdrs, &objp->delegated_cred_handle))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->status))
return (FALSE);
return (TRUE);
}
bool_t
xdr_gss_process_context_token_arg(xdrs, objp)
XDR *xdrs;
gss_process_context_token_arg *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_uid_t(xdrs, &objp->uid))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->gssd_context_verifier))
return (FALSE);
if (!xdr_GSS_CTX_ID_T(xdrs, &objp->context_handle))
return (FALSE);
if (!xdr_GSS_BUFFER_T(xdrs, &objp->token_buffer))
return (FALSE);
return (TRUE);
}
bool_t
xdr_gss_process_context_token_res(xdrs, objp)
XDR *xdrs;
gss_process_context_token_res *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_OM_UINT32(xdrs, &objp->minor_status))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->status))
return (FALSE);
return (TRUE);
}
bool_t
xdr_gss_delete_sec_context_arg(xdrs, objp)
XDR *xdrs;
gss_delete_sec_context_arg *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_OM_UINT32(xdrs, &objp->gssd_context_verifier))
return (FALSE);
if (!xdr_GSS_CTX_ID_T(xdrs, &objp->context_handle))
return (FALSE);
return (TRUE);
}
bool_t
xdr_gss_delete_sec_context_res(xdrs, objp)
XDR *xdrs;
gss_delete_sec_context_res *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_OM_UINT32(xdrs, &objp->minor_status))
return (FALSE);
if (!xdr_GSS_CTX_ID_T(xdrs, &objp->context_handle))
return (FALSE);
if (!xdr_GSS_BUFFER_T(xdrs, &objp->output_token))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->status))
return (FALSE);
return (TRUE);
}
bool_t
xdr_gss_export_sec_context_arg(xdrs, objp)
XDR *xdrs;
gss_export_sec_context_arg *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_GSS_CTX_ID_T(xdrs, &objp->context_handle))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->gssd_context_verifier))
return (FALSE);
return (TRUE);
}
bool_t
xdr_gss_export_sec_context_res(xdrs, objp)
XDR *xdrs;
gss_export_sec_context_res *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_OM_UINT32(xdrs, &objp->minor_status))
return (FALSE);
if (!xdr_GSS_CTX_ID_T(xdrs, &objp->context_handle))
return (FALSE);
if (!xdr_GSS_BUFFER_T(xdrs, &objp->output_token))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->status))
return (FALSE);
return (TRUE);
}
bool_t
xdr_gss_import_sec_context_arg(xdrs, objp)
XDR *xdrs;
gss_import_sec_context_arg *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_GSS_BUFFER_T(xdrs, &objp->input_token))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->gssd_context_verifier))
return (FALSE);
return (TRUE);
}
bool_t
xdr_gss_import_sec_context_res(xdrs, objp)
XDR *xdrs;
gss_import_sec_context_res *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_OM_UINT32(xdrs, &objp->minor_status))
return (FALSE);
if (!xdr_GSS_CTX_ID_T(xdrs, &objp->context_handle))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->status))
return (FALSE);
return (TRUE);
}
bool_t
xdr_gss_context_time_arg(xdrs, objp)
XDR *xdrs;
gss_context_time_arg *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_uid_t(xdrs, &objp->uid))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->gssd_context_verifier))
return (FALSE);
if (!xdr_GSS_CTX_ID_T(xdrs, &objp->context_handle))
return (FALSE);
return (TRUE);
}
bool_t
xdr_gss_context_time_res(xdrs, objp)
XDR *xdrs;
gss_context_time_res *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_OM_UINT32(xdrs, &objp->minor_status))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->time_rec))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->status))
return (FALSE);
return (TRUE);
}
bool_t
xdr_gss_sign_arg(xdrs, objp)
XDR *xdrs;
gss_sign_arg *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_OM_UINT32(xdrs, &objp->gssd_context_verifier))
return (FALSE);
if (!xdr_GSS_CTX_ID_T(xdrs, &objp->context_handle))
return (FALSE);
if (!xdr_int(xdrs, &objp->qop_req))
return (FALSE);
if (!xdr_GSS_BUFFER_T(xdrs, &objp->message_buffer))
return (FALSE);
return (TRUE);
}
bool_t
xdr_gss_sign_res(xdrs, objp)
XDR *xdrs;
gss_sign_res *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_OM_UINT32(xdrs, &objp->minor_status))
return (FALSE);
if (!xdr_GSS_BUFFER_T(xdrs, &objp->msg_token))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->status))
return (FALSE);
return (TRUE);
}
bool_t
xdr_gss_verify_arg(xdrs, objp)
XDR *xdrs;
gss_verify_arg *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_OM_UINT32(xdrs, &objp->gssd_context_verifier))
return (FALSE);
if (!xdr_GSS_CTX_ID_T(xdrs, &objp->context_handle))
return (FALSE);
if (!xdr_GSS_BUFFER_T(xdrs, &objp->message_buffer))
return (FALSE);
if (!xdr_GSS_BUFFER_T(xdrs, &objp->token_buffer))
return (FALSE);
return (TRUE);
}
bool_t
xdr_gss_verify_res(xdrs, objp)
XDR *xdrs;
gss_verify_res *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_OM_UINT32(xdrs, &objp->minor_status))
return (FALSE);
if (!xdr_int(xdrs, &objp->qop_state))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->status))
return (FALSE);
return (TRUE);
}
bool_t
xdr_gss_seal_arg(xdrs, objp)
XDR *xdrs;
gss_seal_arg *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_OM_UINT32(xdrs, &objp->gssd_context_verifier))
return (FALSE);
if (!xdr_GSS_CTX_ID_T(xdrs, &objp->context_handle))
return (FALSE);
if (!xdr_int(xdrs, &objp->conf_req_flag))
return (FALSE);
if (!xdr_int(xdrs, &objp->qop_req))
return (FALSE);
if (!xdr_GSS_BUFFER_T(xdrs, &objp->input_message_buffer))
return (FALSE);
return (TRUE);
}
bool_t
xdr_gss_seal_res(xdrs, objp)
XDR *xdrs;
gss_seal_res *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_OM_UINT32(xdrs, &objp->minor_status))
return (FALSE);
if (!xdr_int(xdrs, &objp->conf_state))
return (FALSE);
if (!xdr_GSS_BUFFER_T(xdrs, &objp->output_message_buffer))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->status))
return (FALSE);
return (TRUE);
}
bool_t
xdr_gss_unseal_arg(xdrs, objp)
XDR *xdrs;
gss_unseal_arg *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_OM_UINT32(xdrs, &objp->gssd_context_verifier))
return (FALSE);
if (!xdr_GSS_CTX_ID_T(xdrs, &objp->context_handle))
return (FALSE);
if (!xdr_GSS_BUFFER_T(xdrs, &objp->input_message_buffer))
return (FALSE);
return (TRUE);
}
bool_t
xdr_gss_unseal_res(xdrs, objp)
XDR *xdrs;
gss_unseal_res *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_OM_UINT32(xdrs, &objp->minor_status))
return (FALSE);
if (!xdr_GSS_BUFFER_T(xdrs, &objp->output_message_buffer))
return (FALSE);
if (!xdr_int(xdrs, &objp->conf_state))
return (FALSE);
if (!xdr_int(xdrs, &objp->qop_state))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->status))
return (FALSE);
return (TRUE);
}
bool_t
xdr_gss_display_status_arg(xdrs, objp)
XDR *xdrs;
gss_display_status_arg *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_uid_t(xdrs, &objp->uid))
return (FALSE);
if (!xdr_int(xdrs, &objp->status_value))
return (FALSE);
if (!xdr_int(xdrs, &objp->status_type))
return (FALSE);
if (!xdr_GSS_OID(xdrs, &objp->mech_type))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->message_context))
return (FALSE);
return (TRUE);
}
bool_t
xdr_gss_display_status_res(xdrs, objp)
XDR *xdrs;
gss_display_status_res *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_OM_UINT32(xdrs, &objp->minor_status))
return (FALSE);
if (!xdr_int(xdrs, &objp->message_context))
return (FALSE);
if (!xdr_GSS_BUFFER_T(xdrs, &objp->status_string))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->status))
return (FALSE);
return (TRUE);
}
/* gss_indicate_mechs_arg is void. This appears in the rpc call def */
bool_t
xdr_gss_indicate_mechs_res(xdrs, objp)
XDR *xdrs;
gss_indicate_mechs_res *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_OM_UINT32(xdrs, &objp->minor_status))
return (FALSE);
if (!xdr_GSS_OID_SET(xdrs, &objp->mech_set))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->status))
return (FALSE);
return (TRUE);
}
bool_t
xdr_gss_inquire_cred_arg(xdrs, objp)
XDR *xdrs;
gss_inquire_cred_arg *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_uid_t(xdrs, &objp->uid))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->gssd_cred_verifier))
return (FALSE);
if (!xdr_GSS_CRED_ID_T(xdrs, &objp->cred_handle))
return (FALSE);
return (TRUE);
}
bool_t
xdr_gss_inquire_cred_res(xdrs, objp)
XDR *xdrs;
gss_inquire_cred_res *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_OM_UINT32(xdrs, &objp->minor_status))
return (FALSE);
if (!xdr_GSS_BUFFER_T(xdrs, &objp->name))
return (FALSE);
if (!xdr_GSS_OID(xdrs, &objp->name_type))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->lifetime))
return (FALSE);
if (!xdr_int(xdrs, &objp->cred_usage))
return (FALSE);
if (!xdr_GSS_OID_SET(xdrs, &objp->mechanisms))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->status))
return (FALSE);
return (TRUE);
}
bool_t
xdr_gss_inquire_cred_by_mech_arg(xdrs, objp)
XDR *xdrs;
gss_inquire_cred_by_mech_arg *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_uid_t(xdrs, &objp->uid))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->gssd_cred_verifier))
return (FALSE);
if (!xdr_GSS_CRED_ID_T(xdrs, &objp->cred_handle))
return (FALSE);
if (!xdr_GSS_OID(xdrs, &objp->mech_type))
return (FALSE);
return (TRUE);
}
bool_t
xdr_gss_inquire_cred_by_mech_res(xdrs, objp)
XDR *xdrs;
gss_inquire_cred_by_mech_res *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_OM_UINT32(xdrs, &objp->minor_status))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->status))
return (FALSE);
return (TRUE);
}
bool_t
xdr_gsscred_name_to_unix_cred_arg(xdrs, objp)
XDR *xdrs;
gsscred_name_to_unix_cred_arg *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_uid_t(xdrs, &objp->uid))
return (FALSE);
if (!xdr_GSS_BUFFER_T(xdrs, &objp->pname))
return (FALSE);
if (!xdr_GSS_OID(xdrs, &objp->name_type))
return (FALSE);
if (!xdr_GSS_OID(xdrs, &objp->mech_type))
return (FALSE);
return (TRUE);
}
bool_t
xdr_gsscred_name_to_unix_cred_res(xdrs, objp)
XDR *xdrs;
gsscred_name_to_unix_cred_res *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_uid_t(xdrs, &objp->uid))
return (FALSE);
if (!xdr_gid_t(xdrs, &objp->gid))
return (FALSE);
if (!xdr_GSSCRED_GIDS(xdrs, &objp->gids))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->major))
return (FALSE);
return (TRUE);
}
bool_t
xdr_gsscred_expname_to_unix_cred_arg(xdrs, objp)
XDR *xdrs;
gsscred_expname_to_unix_cred_arg *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_uid_t(xdrs, &objp->uid))
return (FALSE);
if (!xdr_GSS_BUFFER_T(xdrs, &objp->expname))
return (FALSE);
return (TRUE);
}
bool_t
xdr_gsscred_expname_to_unix_cred_res(xdrs, objp)
XDR *xdrs;
gsscred_expname_to_unix_cred_res *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_uid_t(xdrs, &objp->uid))
return (FALSE);
if (!xdr_gid_t(xdrs, &objp->gid))
return (FALSE);
if (!xdr_GSSCRED_GIDS(xdrs, &objp->gids))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->major))
return (FALSE);
return (TRUE);
}
bool_t
xdr_gss_get_group_info_arg(xdrs, objp)
XDR *xdrs;
gss_get_group_info_arg *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_uid_t(xdrs, &objp->uid))
return (FALSE);
if (!xdr_uid_t(xdrs, &objp->puid))
return (FALSE);
return (TRUE);
}
bool_t
xdr_gss_get_group_info_res(xdrs, objp)
XDR *xdrs;
gss_get_group_info_res *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_gid_t(xdrs, &objp->gid))
return (FALSE);
if (!xdr_GSSCRED_GIDS(xdrs, &objp->gids))
return (FALSE);
if (!xdr_OM_UINT32(xdrs, &objp->major))
return (FALSE);
return (TRUE);
}
bool_t
xdr_gss_get_kmod_arg(xdrs, objp)
XDR *xdrs;
gss_get_kmod_arg *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_GSS_OID(xdrs, &objp->mech_oid))
return (FALSE);
return (TRUE);
}
bool_t
xdr_gss_get_kmod_res(xdrs, objp)
XDR *xdrs;
gss_get_kmod_res *objp;
{
rpc_inline_t *buf __unused;
if (!xdr_bool(xdrs, &objp->module_follow))
return (FALSE);
switch (objp->module_follow) {
case TRUE:
if (!xdr_string(xdrs, &objp->gss_get_kmod_res_u.modname, ~0))
return (FALSE);
break;
case FALSE:
break;
default:
return (FALSE);
}
return (TRUE);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
* Copyright (c) 2011 Bayard G. Bell. All rights reserved.
*/
#include <sys/types.h>
#include <sys/modctl.h>
#include <sys/errno.h>
#include <gssapi/kgssapi_defs.h>
static struct modlmisc modlmisc = {
&mod_miscops, "in-kernel GSSAPI"
};
static struct modlinkage modlinkage = {
MODREV_1,
(void *)&modlmisc,
NULL
};
int
_init()
{
int retval;
mutex_init(&gssrpcb_lock, NULL, MUTEX_DEFAULT, NULL);
mutex_init(&__kgss_mech_lock, NULL, MUTEX_DEFAULT, NULL);
zone_key_create(&gss_zone_key, gss_zone_init, NULL, gss_zone_fini);
if ((retval = mod_install(&modlinkage)) != 0) {
mutex_destroy(&__kgss_mech_lock);
mutex_destroy(&gssrpcb_lock);
}
return (retval);
}
int
_fini()
{
return (EBUSY);
}
int
_info(struct modinfo *modinfop)
{
return (mod_info(&modlinkage, modinfop));
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _GSSAPIP_DUMMY_H
#define _GSSAPIP_DUMMY_H
#ifdef __cplusplus
extern "C" {
#endif
#include <gssapi/gssapi.h>
#define SEC_CONTEXT_TOKEN 1
#define DUMMY_SIZE_OF_INT 4
typedef void * dummy_token_t;
/* dummy name structure for internal representation. */
typedef struct {
gss_OID type;
gss_buffer_t buffer;
} dummy_name_desc, *dummy_name_t;
/* Structure for context handle */
typedef struct {
OM_uint32 last_stat;
int token_number;
int established;
} dummy_gss_ctx_id_rec, *dummy_gss_ctx_id_t;
/* Dummy oid structure */
static const gss_OID_desc dummy_oids[] = {
{10, "\053\006\001\004\001\052\002\032\001\002"},
};
const gss_OID_desc * const gss_mech_dummy = dummy_oids+0;
static const gss_OID_set_desc dummy_oidsets[] = {
{1, (gss_OID) dummy_oids+0},
};
const gss_OID_set_desc * const gss_mech_set_dummy = dummy_oidsets+0;
#define TWRITE_STR(ptr, str, len) \
(void) memcpy((ptr), (char *) (str), (len)); \
(ptr) += (len);
#ifndef _KERNEL
#ifdef DEBUG_ON
#define dprintf(a) printf(a)
#define dprintf1(a, b) printf(a, b)
#else
#define dprintf(a)
#define dprintf1(a, b)
#define DUMMY_STATIC
#endif /* DEBUG_ON */
#else /* _KERNEL */
#if defined(DEBUG) && !defined(DUMMY_MECH_DEBUG)
#define DUMMY_MECH_DEBUG
#endif
#ifdef DUMMY_MECH_DEBUG
#define DUMMY_MECH_LOG(A, B, C) \
((void)((dummy_mech_log & (A)) && (printf((B), (C)), TRUE)))
#define DUMMY_MECH_LOG0(A, B) \
((void)((dummy_mech_log & (A)) && (printf(B), TRUE)))
#else
#define DUMMY_MECH_LOG(A, B, C)
#define DUMMY_MECH_LOG0(A, B)
#endif
#define dprintf(a) DUMMY_MECH_LOG0(8, a)
#define dprintf1(a, b) DUMMY_MECH_LOG(8, a, b)
#define DUMMY_STATIC static
#endif /* _KERNEL */
/*
* declarations of internal name mechanism functions
*/
OM_uint32 dummy_gss_acquire_cred
(
void *, /* dummy context */
OM_uint32 *, /* minor_status */
gss_name_t, /* desired_name */
OM_uint32, /* time_req */
gss_OID_set, /* desired_mechs */
gss_cred_usage_t, /* cred_usage */
gss_cred_id_t *, /* output_cred_handle */
gss_OID_set *, /* actual_mechs */
OM_uint32 * /* time_rec */
/* */);
OM_uint32 dummy_gss_release_cred
(
void *, /* dummy context */
OM_uint32 *, /* minor_status */
gss_cred_id_t * /* cred_handle */
/* */);
OM_uint32 dummy_gss_init_sec_context
(
void *, /* dummy context */
OM_uint32 *, /* minor_status */
gss_cred_id_t, /* claimant_cred_handle */
gss_ctx_id_t *, /* context_handle */
gss_name_t, /* target_name */
gss_OID, /* mech_type */
OM_uint32, /* req_flags */
OM_uint32, /* time_req */
gss_channel_bindings_t, /* input_chan_bindings */
gss_buffer_t, /* input_token */
gss_OID *, /* actual_mech_type */
gss_buffer_t, /* output_token */
OM_uint32 *, /* ret_flags */
OM_uint32 * /* time_rec */
/* */);
OM_uint32 dummy_gss_accept_sec_context
(
void *, /* dummy context */
OM_uint32 *, /* minor_status */
gss_ctx_id_t *, /* context_handle */
gss_cred_id_t, /* verifier_cred_handle */
gss_buffer_t, /* input_token_buffer */
gss_channel_bindings_t, /* input_chan_bindings */
gss_name_t *, /* src_name */
gss_OID *, /* mech_type */
gss_buffer_t, /* output_token */
OM_uint32 *, /* ret_flags */
OM_uint32 *, /* time_rec */
gss_cred_id_t * /* delegated_cred_handle */
/* */);
OM_uint32 dummy_gss_process_context_token
(
void *, /* dummy context */
OM_uint32 *, /* minor_status */
gss_ctx_id_t, /* context_handle */
gss_buffer_t /* token_buffer */
/* */);
DUMMY_STATIC OM_uint32 dummy_gss_delete_sec_context
(
void *, /* dummy context */
OM_uint32 *, /* minor_status */
gss_ctx_id_t *, /* context_handle */
gss_buffer_t /* output_token */
#ifdef _KERNEL
/* */, OM_uint32
#endif
/* */);
OM_uint32 dummy_gss_context_time
(
void *, /* dummy context */
OM_uint32 *, /* minor_status */
gss_ctx_id_t, /* context_handle */
OM_uint32 * /* time_rec */
/* */);
DUMMY_STATIC OM_uint32 dummy_gss_sign
(
void *, /* dummy context */
OM_uint32 *, /* minor_status */
gss_ctx_id_t, /* context_handle */
int, /* qop_req */
gss_buffer_t, /* message_buffer */
gss_buffer_t /* message_token */
#ifdef _KERNEL
/* */, OM_uint32
#endif
/* */);
DUMMY_STATIC OM_uint32 dummy_gss_verify
(
void *, /* dummy context */
OM_uint32 *, /* minor_status */
gss_ctx_id_t, /* context_handle */
gss_buffer_t, /* message_buffer */
gss_buffer_t, /* token_buffer */
int * /* qop_state */
#ifdef _KERNEL
/* */, OM_uint32
#endif
/* */);
DUMMY_STATIC OM_uint32 dummy_gss_seal
(
void *, /* dummy context */
OM_uint32 *, /* minor_status */
gss_ctx_id_t, /* context_handle */
int, /* conf_req_flag */
int, /* qop_req */
gss_buffer_t, /* input_message_buffer */
int *, /* conf_state */
gss_buffer_t /* output_message_buffer */
#ifdef _KERNEL
/* */, OM_uint32
#endif
/* */);
DUMMY_STATIC OM_uint32 dummy_gss_unseal
(
void *, /* dummy context */
OM_uint32 *, /* minor_status */
gss_ctx_id_t, /* context_handle */
gss_buffer_t, /* input_message_buffer */
gss_buffer_t, /* output_message_buffer */
int *, /* conf_state */
int * /* qop_state */
#ifdef _KERNEL
/* */, OM_uint32
#endif
/* */);
OM_uint32 dummy_gss_display_status
(
void *, /* dummy context */
OM_uint32 *, /* minor_status */
OM_uint32, /* status_value */
int, /* status_type */
gss_OID, /* mech_type */
OM_uint32 *, /* message_context */
gss_buffer_t /* status_string */
/* */);
OM_uint32 dummy_gss_indicate_mechs
(
void *, /* dummy context */
OM_uint32 *, /* minor_status */
gss_OID_set * /* mech_set */
/* */);
OM_uint32 dummy_gss_compare_name
(
void *, /* dummy context */
OM_uint32 *, /* minor_status */
gss_name_t, /* name1 */
gss_name_t, /* name2 */
int * /* name_equal */
/* */);
OM_uint32 dummy_gss_display_name
(
void *, /* dummy context */
OM_uint32 *, /* minor_status */
gss_name_t, /* input_name */
gss_buffer_t, /* output_name_buffer */
gss_OID * /* output_name_type */
/* */);
OM_uint32 dummy_gss_import_name
(
void *, /* dummy context */
OM_uint32 *, /* minor_status */
gss_buffer_t, /* input_name_buffer */
gss_OID, /* input_name_type */
gss_name_t * /* output_name */
/* */);
OM_uint32 dummy_gss_release_name
(
void *, /* dummy context */
OM_uint32 *, /* minor_status */
gss_name_t * /* input_name */
/* */);
OM_uint32 dummy_gss_inquire_cred
(
void *, /* dummy context */
OM_uint32 *, /* minor_status */
gss_cred_id_t, /* cred_handle */
gss_name_t *, /* name */
OM_uint32 *, /* lifetime */
gss_cred_usage_t *, /* cred_usage */
gss_OID_set * /* mechanisms */
/* */);
OM_uint32 dummy_gss_inquire_context
(
void *, /* dummy context */
OM_uint32 *, /* minor_status */
gss_ctx_id_t, /* context_handle */
gss_name_t *, /* initiator_name */
gss_name_t *, /* acceptor_name */
OM_uint32 *, /* lifetime_rec */
gss_OID *, /* mech_type */
OM_uint32 *, /* ret_flags */
int *, /* locally_initiated */
int * /* open */
/* */);
/* New V2 entry points */
OM_uint32 dummy_gss_get_mic
(
void *, /* dummy context */
OM_uint32 *, /* minor_status */
gss_ctx_id_t, /* context_handle */
gss_qop_t, /* qop_req */
gss_buffer_t, /* message_buffer */
gss_buffer_t /* message_token */
/* */);
OM_uint32 dummy_gss_verify_mic
(
void *, /* dummy context */
OM_uint32 *, /* minor_status */
gss_ctx_id_t, /* context_handle */
gss_buffer_t, /* message_buffer */
gss_buffer_t, /* message_token */
gss_qop_t * /* qop_state */
/* */);
OM_uint32 dummy_gss_wrap
(
void *, /* dummy context */
OM_uint32 *, /* minor_status */
gss_ctx_id_t, /* context_handle */
int, /* conf_req_flag */
gss_qop_t, /* qop_req */
gss_buffer_t, /* input_message_buffer */
int *, /* conf_state */
gss_buffer_t /* output_message_buffer */
/* */);
OM_uint32 dummy_gss_unwrap
(
void *, /* dummy context */
OM_uint32 *, /* minor_status */
gss_ctx_id_t, /* context_handle */
gss_buffer_t, /* input_message_buffer */
gss_buffer_t, /* output_message_buffer */
int *, /* conf_state */
gss_qop_t * /* qop_state */
/* */);
OM_uint32 dummy_gss_wrap_size_limit
(
void *, /* dummy context */
OM_uint32 *, /* minor_status */
gss_ctx_id_t, /* context_handle */
int, /* conf_req_flag */
gss_qop_t, /* qop_req */
OM_uint32, /* req_output_size */
OM_uint32 * /* max_input_size */
/* */);
OM_uint32 dummy_gss_add_cred
(
void *, /* dummy context */
OM_uint32 *, /* minor_status */
gss_cred_id_t, /* input_cred_handle */
gss_name_t, /* desired_name */
gss_OID, /* desired_mech */
gss_cred_usage_t, /* cred_usage */
OM_uint32, /* initiator_time_req */
OM_uint32, /* acceptor_time_req */
gss_cred_id_t *, /* output_cred_handle */
gss_OID_set *, /* actual_mechs */
OM_uint32 *, /* initiator_time_rec */
OM_uint32 * /* acceptor_time_rec */
/* */);
OM_uint32 dummy_gss_inquire_cred_by_mech
(
void *, /* dummy context */
OM_uint32 *, /* minor_status */
gss_cred_id_t, /* cred_handle */
gss_OID, /* mech_type */
gss_name_t *, /* name */
OM_uint32 *, /* initiator_lifetime */
OM_uint32 *, /* acceptor_lifetime */
gss_cred_usage_t * /* cred_usage */
/* */);
OM_uint32 dummy_gss_export_sec_context
(
void *, /* dummy context */
OM_uint32 *, /* minor_status */
gss_ctx_id_t *, /* context_handle */
gss_buffer_t /* interprocess_token */
/* */);
OM_uint32 dummy_gss_import_sec_context
(
void *, /* dummy context */
OM_uint32 *, /* minor_status */
gss_buffer_t, /* interprocess_token */
gss_ctx_id_t * /* context_handle */
/* */);
#if 0
OM_uint32 dummy_gss_release_oid
(
OM_uint32 *, /* minor_status */
gss_OID * /* oid */
/* */);
#endif
OM_uint32 dummy_gss_internal_release_oid
(
void *, /* dummy context */
OM_uint32 *, /* minor_status */
gss_OID * /* oid */
/* */);
OM_uint32 dummy_gss_inquire_names_for_mech
(
void *, /* dummy context */
OM_uint32 *, /* minor_status */
gss_OID, /* mechanism */
gss_OID_set * /* name_types */
/* */);
OM_uint32 dummy_pname_to_uid
(
void *, /* dummy context */
OM_uint32 *, /* minor status */
const gss_name_t, /* pname */
uid_t * /* uidOut */
/* */);
#ifdef __cplusplus
}
#endif
#endif /* _GSSAPIP_DUMMY_H */
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* This file was derived from the MIT 1.0 source release.
*/
#ifndef _GSSAPI_ERR_GENERIC_H
#define _GSSAPI_ERR_GENERIC_H
#ifdef __cplusplus
extern "C" {
#endif
/*
* gssapi_err_generic.h:
* This file is automatically generated; please do not edit it.
*/
#define G_BAD_SERVICE_NAME (-2045022976L)
#define G_BAD_STRING_UID (-2045022975L)
#define G_NOUSER (-2045022974L)
#define G_VALIDATE_FAILED (-2045022973L)
#define G_BUFFER_ALLOC (-2045022972L)
#define G_BAD_MSG_CTX (-2045022971L)
#define G_WRONG_SIZE (-2045022970L)
#define G_BAD_USAGE (-2045022969L)
#define G_UNKNOWN_QOP (-2045022968L)
#define G_NO_HOSTNAME (-2045022967L)
#define G_BAD_HOSTNAME (-2045022966L)
#define G_WRONG_MECH (-2045022965L)
#define G_BAD_TOK_HEADER (-2045022964L)
#define G_BAD_DIRECTION (-2045022963L)
#define G_TOK_TRUNC (-2045022962L)
#define G_REFLECT (-2045022961L)
#define G_WRONG_TOKID (-2045022960L)
#define G_CRED_USAGE_MISMATCH (-2045022959L)
#define G_STORE_ACCEPTOR_CRED_NOSUPP (-2045022958L)
#define G_STORE_NON_DEFAULT_CRED_NOSUPP (-2045022957L)
#define ERROR_TABLE_BASE_ggss (-2045022976L)
/* for compatibility with older versions... */
#define ggss_err_base ERROR_TABLE_BASE_ggss
#ifdef __cplusplus
}
#endif
#endif /* _GSSAPI_ERR_GENERIC_H */
/*
* 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) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
*/
/*
* This header contains the private mechglue definitions.
*
*/
#ifndef _GSS_MECHGLUEP_H
#define _GSS_MECHGLUEP_H
#if 0 /* SUNW15resync - disable for sake of non-krb5 mechs */
#include "autoconf.h"
#endif
/* SUNW15resync */
#ifndef GSS_DLLIMP
#define GSS_DLLIMP
#endif
#include <gssapi/gssapi_ext.h> /* SUNW15resync - mechglue.h in mit 1.5 */
#if 0 /* Solaris Kerberos */
#include "gssapiP_generic.h"
#endif
#ifdef _KERNEL
#include <rpc/rpc.h>
#endif
#ifndef g_OID_copy /* SUNW15resync */
#define g_OID_copy(o1, o2) \
do { \
memcpy((o1)->elements, (o2)->elements, (o2)->length); \
(o1)->length = (o2)->length; \
} while (0)
#endif
#define GSS_EMPTY_BUFFER(buf) ((buf) == NULL ||\
(buf)->value == NULL || (buf)->length == 0)
/*
* Array of context IDs typed by mechanism OID
*/
typedef struct gss_union_ctx_id_t {
gss_OID mech_type;
gss_ctx_id_t internal_ctx_id;
} gss_union_ctx_id_desc, *gss_union_ctx_id_t;
/*
* Generic GSSAPI names. A name can either be a generic name, or a
* mechanism specific name....
*/
typedef struct gss_name_struct {
struct gss_name_struct *loopback;
gss_OID name_type;
gss_buffer_t external_name;
/*
* These last two fields are only filled in for mechanism
* names.
*/
gss_OID mech_type;
gss_name_t mech_name;
} gss_union_name_desc, *gss_union_name_t;
/*
* Structure for holding list of mechanism-specific name types
*/
typedef struct gss_mech_spec_name_t {
gss_OID name_type;
gss_OID mech;
struct gss_mech_spec_name_t *next, *prev;
} gss_mech_spec_name_desc, *gss_mech_spec_name;
/*
* Credential auxiliary info, used in the credential structure
*/
typedef struct gss_union_cred_auxinfo {
gss_buffer_desc name;
gss_OID name_type;
OM_uint32 creation_time;
OM_uint32 time_rec;
int cred_usage;
} gss_union_cred_auxinfo;
/*
* Set of Credentials typed on mechanism OID
*/
typedef struct gss_union_cred_t {
int count;
gss_OID mechs_array;
gss_cred_id_t *cred_array;
gss_union_cred_auxinfo auxinfo;
} gss_union_cred_desc, *gss_union_cred_t;
/* Solaris Kerberos */
typedef OM_uint32 (*gss_acquire_cred_with_password_sfct)(
void *, /* context */
OM_uint32 *, /* minor_status */
const gss_name_t, /* desired_name */
const gss_buffer_t, /* password */
OM_uint32, /* time_req */
const gss_OID_set, /* desired_mechs */
int, /* cred_usage */
gss_cred_id_t *, /* output_cred_handle */
gss_OID_set *, /* actual_mechs */
OM_uint32 * /* time_rec */
/* */);
/*
* Rudimentary pointer validation macro to check whether the
* "loopback" field of an opaque struct points back to itself. This
* field also catches some programming errors where an opaque pointer
* is passed to a function expecting the address of the opaque
* pointer.
*/
#if 0 /* Solaris Kerberos - revisit for full 1.7/next resync */
#define GSSINT_CHK_LOOP(p) (!((p) != NULL && (p)->loopback == (p)))
#else
#define GSSINT_CHK_LOOP(p) ((p) == NULL)
#endif
/********************************************************/
/* The Mechanism Dispatch Table -- a mechanism needs to */
/* define one of these and provide a function to return */
/* it to initialize the GSSAPI library */
/*
* This is the definition of the mechs_array struct, which is used to
* define the mechs array table. This table is used to indirectly
* access mechanism specific versions of the gssapi routines through
* the routines in the glue module (gssd_mech_glue.c)
*
* This contants all of the functions defined in gssapi.h except for
* gss_release_buffer() and gss_release_oid_set(), which I am
* assuming, for now, to be equal across mechanisms.
*/
typedef struct gss_config {
#if 0 /* Solaris Kerberos */
OM_uint32 priority;
char * mechNameStr;
#endif
gss_OID_desc mech_type;
void * context;
#ifdef _KERNEL
struct gss_config *next;
bool_t uses_kmod;
#endif
#ifndef _KERNEL
OM_uint32 (*gss_acquire_cred)
(
void *, /* context */
OM_uint32 *, /* minor_status */
const gss_name_t, /* desired_name */
OM_uint32, /* time_req */
const gss_OID_set, /* desired_mechs */
int, /* cred_usage */
gss_cred_id_t *, /* output_cred_handle */
gss_OID_set *, /* actual_mechs */
OM_uint32 * /* time_rec */
/* */);
OM_uint32 (*gss_release_cred)
(
void *, /* context */
OM_uint32 *, /* minor_status */
gss_cred_id_t * /* cred_handle */
/* */);
OM_uint32 (*gss_init_sec_context)
(
void *, /* context */
OM_uint32 *, /* minor_status */
const gss_cred_id_t, /* claimant_cred_handle */
gss_ctx_id_t *, /* context_handle */
const gss_name_t, /* target_name */
const gss_OID, /* mech_type */
OM_uint32, /* req_flags */
OM_uint32, /* time_req */
const gss_channel_bindings_t, /* input_chan_bindings */
const gss_buffer_t, /* input_token */
gss_OID*, /* actual_mech_type */
gss_buffer_t, /* output_token */
OM_uint32 *, /* ret_flags */
OM_uint32 * /* time_rec */
/* */);
OM_uint32 (*gss_accept_sec_context)
(
void *, /* context */
OM_uint32 *, /* minor_status */
gss_ctx_id_t *, /* context_handle */
const gss_cred_id_t, /* verifier_cred_handle */
const gss_buffer_t, /* input_token_buffer */
const gss_channel_bindings_t, /* input_chan_bindings */
gss_name_t *, /* src_name */
gss_OID*, /* mech_type */
gss_buffer_t, /* output_token */
OM_uint32 *, /* ret_flags */
OM_uint32 *, /* time_rec */
gss_cred_id_t * /* delegated_cred_handle */
/* */);
#endif /* ! _KERNEL */
/*
* Note: there are two gss_unseal's in here. Make any changes to both.
*/
OM_uint32 (*gss_unseal)
(
void *, /* context */
OM_uint32 *, /* minor_status */
const gss_ctx_id_t, /* context_handle */
const gss_buffer_t, /* input_message_buffer */
gss_buffer_t, /* output_message_buffer */
int *, /* conf_state */
int * /* qop_state */
#ifdef _KERNEL
/* */, OM_uint32
#endif
/* */);
#ifndef _KERNEL
OM_uint32 (*gss_process_context_token)
(
void *, /* context */
OM_uint32 *, /* minor_status */
const gss_ctx_id_t, /* context_handle */
const gss_buffer_t /* token_buffer */
/* */);
#endif /* ! _KERNEL */
OM_uint32 (*gss_delete_sec_context)
(
void *, /* context */
OM_uint32 *, /* minor_status */
gss_ctx_id_t *, /* context_handle */
gss_buffer_t /* output_token */
#ifdef _KERNEL
/* */, OM_uint32
#endif
/* */);
#ifndef _KERNEL
OM_uint32 (*gss_context_time)
(
void *, /* context */
OM_uint32 *, /* minor_status */
const gss_ctx_id_t, /* context_handle */
OM_uint32 * /* time_rec */
/* */);
OM_uint32 (*gss_display_status)
(
void *, /* context */
OM_uint32 *, /* minor_status */
OM_uint32, /* status_value */
int, /* status_type */
const gss_OID, /* mech_type */
OM_uint32 *, /* message_context */
gss_buffer_t /* status_string */
/* */);
OM_uint32 (*gss_indicate_mechs)
(
void *, /* context */
OM_uint32 *, /* minor_status */
gss_OID_set * /* mech_set */
/* */);
OM_uint32 (*gss_compare_name)
(
void *, /* context */
OM_uint32 *, /* minor_status */
const gss_name_t, /* name1 */
const gss_name_t, /* name2 */
int * /* name_equal */
/* */);
OM_uint32 (*gss_display_name)
(
void *, /* context */
OM_uint32 *, /* minor_status */
const gss_name_t, /* input_name */
gss_buffer_t, /* output_name_buffer */
gss_OID* /* output_name_type */
/* */);
OM_uint32 (*gss_import_name)
(
void *, /* context */
OM_uint32 *, /* minor_status */
const gss_buffer_t, /* input_name_buffer */
const gss_OID, /* input_name_type */
gss_name_t * /* output_name */
/* */);
OM_uint32 (*gss_release_name)
(
void *, /* context */
OM_uint32 *, /* minor_status */
gss_name_t * /* input_name */
/* */);
OM_uint32 (*gss_inquire_cred)
(
void *, /* context */
OM_uint32 *, /* minor_status */
const gss_cred_id_t, /* cred_handle */
gss_name_t *, /* name */
OM_uint32 *, /* lifetime */
int *, /* cred_usage */
gss_OID_set * /* mechanisms */
/* */);
OM_uint32 (*gss_add_cred)
(
void *, /* context */
OM_uint32 *, /* minor_status */
const gss_cred_id_t, /* input_cred_handle */
const gss_name_t, /* desired_name */
const gss_OID, /* desired_mech */
gss_cred_usage_t, /* cred_usage */
OM_uint32, /* initiator_time_req */
OM_uint32, /* acceptor_time_req */
gss_cred_id_t *, /* output_cred_handle */
gss_OID_set *, /* actual_mechs */
OM_uint32 *, /* initiator_time_rec */
OM_uint32 * /* acceptor_time_rec */
/* */);
#endif /* ! _KERNEL */
/*
* Note: there are two gss_seal's in here. Make any changes to both.
*/
OM_uint32 (*gss_seal)
(
void *, /* context */
OM_uint32 *, /* minor_status */
const gss_ctx_id_t, /* context_handle */
int, /* conf_req_flag */
int, /* qop_req */
const gss_buffer_t, /* input_message_buffer */
int *, /* conf_state */
gss_buffer_t /* output_message_buffer */
#ifdef _KERNEL
/* */, OM_uint32
#endif
/* */);
#ifndef _KERNEL
OM_uint32 (*gss_export_sec_context)
(
void *, /* context */
OM_uint32 *, /* minor_status */
gss_ctx_id_t *, /* context_handle */
gss_buffer_t /* interprocess_token */
/* */);
#endif /* ! _KERNEL */
OM_uint32 (*gss_import_sec_context)
(
void *, /* context */
OM_uint32 *, /* minor_status */
const gss_buffer_t, /* interprocess_token */
gss_ctx_id_t * /* context_handle */
/* */);
#ifndef _KERNEL
OM_uint32 (*gss_inquire_cred_by_mech)
(
void *, /* context */
OM_uint32 *, /* minor_status */
const gss_cred_id_t, /* cred_handle */
const gss_OID, /* mech_type */
gss_name_t *, /* name */
OM_uint32 *, /* initiator_lifetime */
OM_uint32 *, /* acceptor_lifetime */
gss_cred_usage_t * /* cred_usage */
/* */);
OM_uint32 (*gss_inquire_names_for_mech)
(
void *, /* context */
OM_uint32 *, /* minor_status */
const gss_OID, /* mechanism */
gss_OID_set * /* name_types */
/* */);
OM_uint32 (*gss_inquire_context)
(
void *, /* context */
OM_uint32 *, /* minor_status */
const gss_ctx_id_t, /* context_handle */
gss_name_t *, /* src_name */
gss_name_t *, /* targ_name */
OM_uint32 *, /* lifetime_rec */
gss_OID *, /* mech_type */
OM_uint32 *, /* ctx_flags */
int *, /* locally_initiated */
int * /* open */
/* */);
OM_uint32 (*gss_internal_release_oid)
(
void *, /* context */
OM_uint32 *, /* minor_status */
gss_OID * /* OID */
/* */);
OM_uint32 (*gss_wrap_size_limit)
(
void *, /* context */
OM_uint32 *, /* minor_status */
const gss_ctx_id_t, /* context_handle */
int, /* conf_req_flag */
gss_qop_t, /* qop_req */
OM_uint32, /* req_output_size */
OM_uint32 * /* max_input_size */
/* */);
OM_uint32 (*pname_to_uid)
(
void *, /* context */
OM_uint32 *, /* minor_status */
const gss_name_t, /* pname */
uid_t * /* uid */
/* */);
OM_uint32 (*__gss_userok)
(
void *, /* context */
OM_uint32 *, /* minor_status */
const gss_name_t, /* pname */
const char *, /* local user */
int * /* user ok? */
/* */);
OM_uint32 (*gss_export_name)
(
void *, /* context */
OM_uint32 *, /* minor_status */
const gss_name_t, /* input_name */
gss_buffer_t /* exported_name */
/* */);
#endif /* ! _KERNEL */
OM_uint32 (*gss_sign)
(
void *, /* context */
OM_uint32 *, /* minor_status */
const gss_ctx_id_t, /* context_handle */
int, /* qop_req */
const gss_buffer_t, /* message_buffer */
gss_buffer_t /* message_token */
#ifdef _KERNEL
/* */, OM_uint32
#endif
/* */);
OM_uint32 (*gss_verify)
(
void *, /* context */
OM_uint32 *, /* minor_status */
const gss_ctx_id_t, /* context_handle */
const gss_buffer_t, /* message_buffer */
const gss_buffer_t, /* token_buffer */
int * /* qop_state */
#ifdef _KERNEL
/* */, OM_uint32
#endif
/* */);
#ifndef _KERNEL
OM_uint32 (*gss_store_cred)
(
void *, /* context */
OM_uint32 *, /* minor_status */
const gss_cred_id_t, /* input_cred */
gss_cred_usage_t, /* cred_usage */
const gss_OID, /* desired_mech */
OM_uint32, /* overwrite_cred */
OM_uint32, /* default_cred */
gss_OID_set *, /* elements_stored */
gss_cred_usage_t * /* cred_usage_stored */
/* */);
/* GGF extensions */
OM_uint32 (*gss_inquire_sec_context_by_oid)
(
OM_uint32 *, /* minor_status */
const gss_ctx_id_t, /* context_handle */
const gss_OID, /* OID */
gss_buffer_set_t * /* data_set */
/* */);
#endif
} *gss_mechanism;
#ifndef _KERNEL
/* This structure MUST NOT be used by any code outside libgss */
typedef struct gss_config_ext {
gss_acquire_cred_with_password_sfct gss_acquire_cred_with_password;
} *gss_mechanism_ext;
#endif /* _KERNEL */
/*
* In the user space we use a wrapper structure to encompass the
* mechanism entry points. The wrapper contain the mechanism
* entry points and other data which is only relevant to the gss-api
* layer. In the kernel we use only the gss_config strucutre because
* the kernal does not cantain any of the extra gss-api specific data.
*/
typedef struct gss_mech_config {
char *kmodName; /* kernel module name */
char *uLibName; /* user library name */
char *mechNameStr; /* mechanism string name */
char *optionStr; /* optional mech parameters */
void *dl_handle; /* RTLD object handle for the mech */
gss_OID mech_type; /* mechanism oid */
gss_mechanism mech; /* mechanism initialization struct */
#ifndef _KERNEL
gss_mechanism_ext mech_ext; /* Solaris extensions */
#endif /* _KERNEL */
struct gss_mech_config *next; /* next element in the list */
} *gss_mech_info;
/********************************************************/
/* Internal mechglue routines */
/* SUNW15resync - Solaris versions - replace w/mit ones? */
gss_mechanism __gss_get_mechanism(const gss_OID);
#ifndef _KERNEL
gss_mechanism_ext __gss_get_mechanism_ext(const gss_OID);
#endif /* _KERNEL */
char *__gss_get_kmodName(const gss_OID);
char *__gss_get_modOptions(const gss_OID);
OM_uint32 __gss_import_internal_name(OM_uint32 *, const gss_OID,
gss_union_name_t, gss_name_t *);
OM_uint32 __gss_export_internal_name(OM_uint32 *, const gss_OID,
const gss_name_t, gss_buffer_t);
OM_uint32 __gss_display_internal_name(OM_uint32 *, const gss_OID,
const gss_name_t, gss_buffer_t, gss_OID *);
OM_uint32 __gss_release_internal_name(OM_uint32 *, const gss_OID,
gss_name_t *);
OM_uint32 gssint_delete_internal_sec_context (OM_uint32 *, gss_OID,
gss_ctx_id_t *, gss_buffer_t);
OM_uint32 __gss_convert_name_to_union_name(
OM_uint32 *, /* minor_status */
gss_mechanism, /* mech */
gss_name_t, /* internal_name */
gss_name_t * /* external_name */
);
gss_cred_id_t __gss_get_mechanism_cred(
const gss_union_cred_t, /* union_cred */
const gss_OID /* mech_type */
);
int gssint_mechglue_init(void);
void gssint_mechglue_fini(void);
gss_mechanism gssint_get_mechanism (gss_OID);
OM_uint32 gssint_get_mech_type (gss_OID, gss_buffer_t);
char *gssint_get_kmodName(const gss_OID);
char *gssint_get_modOptions(const gss_OID);
OM_uint32 gssint_import_internal_name (OM_uint32 *, gss_OID, gss_union_name_t,
gss_name_t *);
OM_uint32 gssint_export_internal_name(OM_uint32 *, const gss_OID,
const gss_name_t, gss_buffer_t);
OM_uint32 gssint_display_internal_name (OM_uint32 *, gss_OID, gss_name_t,
gss_buffer_t, gss_OID *);
OM_uint32 gssint_release_internal_name (OM_uint32 *, gss_OID, gss_name_t *);
OM_uint32 gssint_convert_name_to_union_name
(OM_uint32 *, /* minor_status */
gss_mechanism, /* mech */
gss_name_t, /* internal_name */
gss_name_t * /* external_name */
);
gss_cred_id_t gssint_get_mechanism_cred
(gss_union_cred_t, /* union_cred */
gss_OID /* mech_type */
);
OM_uint32 gssint_create_copy_buffer(
const gss_buffer_t, /* src buffer */
gss_buffer_t *, /* destination buffer */
int /* NULL terminate buffer ? */
);
OM_uint32 gssint_copy_oid_set(
OM_uint32 *, /* minor_status */
const gss_OID_set_desc *, /* oid set */
gss_OID_set * /* new oid set */
);
/* SUNW15resync - for old Solaris version in libgss */
OM_uint32 gss_copy_oid_set(
OM_uint32 *, /* minor_status */
const gss_OID_set_desc *, /* oid set */
gss_OID_set * /* new oid set */
);
gss_OID gss_find_mechanism_from_name_type (gss_OID); /* name_type */
OM_uint32 gss_add_mech_name_type
(OM_uint32 *, /* minor_status */
gss_OID, /* name_type */
gss_OID /* mech */
);
/*
* Sun extensions to GSS-API v2
*/
OM_uint32
gssint_mech_to_oid(
const char *mech, /* mechanism string name */
gss_OID *oid /* mechanism oid */
);
const char *
gssint_oid_to_mech(
const gss_OID oid /* mechanism oid */
);
OM_uint32
gssint_get_mechanisms(
char *mechArray[], /* array to populate with mechs */
int arrayLen /* length of passed in array */
);
OM_uint32
gss_store_cred(
OM_uint32 *, /* minor_status */
const gss_cred_id_t, /* input_cred_handle */
gss_cred_usage_t, /* cred_usage */
const gss_OID, /* desired_mech */
OM_uint32, /* overwrite_cred */
OM_uint32, /* default_cred */
gss_OID_set *, /* elements_stored */
gss_cred_usage_t * /* cred_usage_stored */
);
int
gssint_get_der_length(
unsigned char **, /* buf */
unsigned int, /* buf_len */
unsigned int * /* bytes */
);
unsigned int
gssint_der_length_size(unsigned int /* len */);
int
gssint_put_der_length(
unsigned int, /* length */
unsigned char **, /* buf */
unsigned int /* max_len */
);
/* Solaris kernel and gssd support */
/*
* derived types for passing context and credential handles
* between gssd and kernel
*/
typedef unsigned int gssd_ctx_id_t;
typedef unsigned int gssd_cred_id_t;
#define GSSD_NO_CONTEXT ((gssd_ctx_id_t)0)
#define GSSD_NO_CREDENTIAL ((gssd_cred_id_t)0)
#ifdef _KERNEL
#ifndef _KRB5_H
/* These macros are defined for Kerberos in krb5.h, and have priority */
#define MALLOC(n) kmem_alloc((n), KM_SLEEP)
#define FREE(x, n) kmem_free((x), (n))
#endif /* _KRB5_H */
gss_mechanism __kgss_get_mechanism(gss_OID);
void __kgss_add_mechanism(gss_mechanism);
#endif /* _KERNEL */
struct kgss_cred {
gssd_cred_id_t gssd_cred;
OM_uint32 gssd_cred_verifier;
};
#define KCRED_TO_KGSS_CRED(cred) ((struct kgss_cred *)(cred))
#define KCRED_TO_CRED(cred) (KCRED_TO_KGSS_CRED(cred)->gssd_cred)
#define KCRED_TO_CREDV(cred) (KCRED_TO_KGSS_CRED(cred)->gssd_cred_verifier)
struct kgss_ctx {
gssd_ctx_id_t gssd_ctx;
#ifdef _KERNEL
gss_ctx_id_t gssd_i_ctx;
bool_t ctx_imported;
gss_mechanism mech;
#endif /* _KERNEL */
OM_uint32 gssd_ctx_verifier;
};
#define KCTX_TO_KGSS_CTX(ctx) ((struct kgss_ctx *)(ctx))
#define KCTX_TO_CTX_IMPORTED(ctx) (KCTX_TO_KGSS_CTX(ctx)->ctx_imported)
#define KCTX_TO_GSSD_CTX(ctx) (KCTX_TO_KGSS_CTX(ctx)->gssd_ctx)
#define KCTX_TO_CTXV(ctx) (KCTX_TO_KGSS_CTX(ctx)->gssd_ctx_verifier)
#define KCTX_TO_MECH(ctx) (KCTX_TO_KGSS_CTX(ctx)->mech)
#define KCTX_TO_PRIVATE(ctx) (KCTX_TO_MECH(ctx)->context)
#define KGSS_CTX_TO_GSSD_CTX(ctx) \
(((ctx) == GSS_C_NO_CONTEXT) ? (gssd_ctx_id_t)(uintptr_t)(ctx) : \
KCTX_TO_GSSD_CTX(ctx))
#define KGSS_CTX_TO_GSSD_CTXV(ctx) \
(((ctx) == GSS_C_NO_CONTEXT) ? (0) : KCTX_TO_CTXV(ctx))
#ifdef _KERNEL
#define KCTX_TO_I_CTX(ctx) (KCTX_TO_KGSS_CTX(ctx)->gssd_i_ctx)
#define KCTX_TO_CTX(ctx) \
((KCTX_TO_CTX_IMPORTED(ctx) == FALSE) ? (ctx) : \
KCTX_TO_I_CTX(ctx))
#define KGSS_CRED_ALLOC() kmem_zalloc(sizeof (struct kgss_cred), \
KM_SLEEP)
#define KGSS_CRED_FREE(cred) kmem_free(cred, sizeof (struct kgss_cred))
#define KGSS_ALLOC() kmem_zalloc(sizeof (struct kgss_ctx), KM_SLEEP)
#define KGSS_FREE(ctx) kmem_free(ctx, sizeof (struct kgss_ctx))
#define KGSS_SIGN(minor_st, ctx, qop, msg, tkn) \
(*(KCTX_TO_MECH(ctx)->gss_sign))(KCTX_TO_PRIVATE(ctx), minor_st, \
KCTX_TO_CTX(ctx), qop, msg, tkn, KCTX_TO_CTXV(ctx))
#define KGSS_VERIFY(minor_st, ctx, msg, tkn, qop) \
(*(KCTX_TO_MECH(ctx)->gss_verify))(KCTX_TO_PRIVATE(ctx), minor_st,\
KCTX_TO_CTX(ctx), msg, tkn, qop, KCTX_TO_CTXV(ctx))
#define KGSS_DELETE_SEC_CONTEXT(minor_st, ctx, int_ctx_id, tkn) \
(*(KCTX_TO_MECH(ctx)->gss_delete_sec_context))(KCTX_TO_PRIVATE(ctx),\
minor_st, int_ctx_id, tkn, KCTX_TO_CTXV(ctx))
#define KGSS_IMPORT_SEC_CONTEXT(minor_st, tkn, ctx, int_ctx_id) \
(*(KCTX_TO_MECH(ctx)->gss_import_sec_context))(KCTX_TO_PRIVATE(ctx),\
minor_st, tkn, int_ctx_id)
#define KGSS_SEAL(minor_st, ctx, conf_req, qop, msg, conf_state, tkn) \
(*(KCTX_TO_MECH(ctx)->gss_seal))(KCTX_TO_PRIVATE(ctx), minor_st, \
KCTX_TO_CTX(ctx), conf_req, qop, msg, conf_state, tkn,\
KCTX_TO_CTXV(ctx))
#define KGSS_UNSEAL(minor_st, ctx, msg, tkn, conf, qop) \
(*(KCTX_TO_MECH(ctx)->gss_unseal))(KCTX_TO_PRIVATE(ctx), minor_st,\
KCTX_TO_CTX(ctx), msg, tkn, conf, qop, \
KCTX_TO_CTXV(ctx))
#define KGSS_INIT_CONTEXT(ctx) krb5_init_context(ctx)
#define KGSS_RELEASE_OID(minor_st, oid) krb5_gss_release_oid(minor_st, oid)
extern OM_uint32 kgss_release_oid(OM_uint32 *, gss_OID *);
#else /* !_KERNEL */
#define KGSS_INIT_CONTEXT(ctx) krb5_gss_init_context(ctx)
#define KGSS_RELEASE_OID(minor_st, oid) gss_release_oid(minor_st, oid)
#define KCTX_TO_CTX(ctx) (KCTX_TO_KGSS_CTX(ctx)->gssd_ctx)
#define MALLOC(n) malloc(n)
#define FREE(x, n) free(x)
#define KGSS_CRED_ALLOC() (struct kgss_cred *) \
MALLOC(sizeof (struct kgss_cred))
#define KGSS_CRED_FREE(cred) free(cred)
#define KGSS_ALLOC() (struct kgss_ctx *)MALLOC(sizeof (struct kgss_ctx))
#define KGSS_FREE(ctx) free(ctx)
#define KGSS_SIGN(minor_st, ctx, qop, msg, tkn) \
kgss_sign_wrapped(minor_st, \
KCTX_TO_CTX(ctx), qop, msg, tkn, KCTX_TO_CTXV(ctx))
#define KGSS_VERIFY(minor_st, ctx, msg, tkn, qop) \
kgss_verify_wrapped(minor_st,\
KCTX_TO_CTX(ctx), msg, tkn, qop, KCTX_TO_CTXV(ctx))
#define KGSS_SEAL(minor_st, ctx, conf_req, qop, msg, conf_state, tkn) \
kgss_seal_wrapped(minor_st, \
KCTX_TO_CTX(ctx), conf_req, qop, msg, conf_state, tkn, \
KCTX_TO_CTXV(ctx))
#define KGSS_UNSEAL(minor_st, ctx, msg, tkn, conf, qop) \
kgss_unseal_wrapped(minor_st,\
KCTX_TO_CTX(ctx), msg, tkn, conf, qop, \
KCTX_TO_CTXV(ctx))
#endif /* _KERNEL */
/* SUNW15resync - moved from gssapiP_generic.h for sake of non-krb5 mechs */
OM_uint32 generic_gss_release_buffer
(OM_uint32*, /* minor_status */
gss_buffer_t /* buffer */
);
OM_uint32 generic_gss_release_oid_set
(OM_uint32*, /* minor_status */
gss_OID_set* /* set */
);
OM_uint32 generic_gss_release_oid
(OM_uint32*, /* minor_status */
gss_OID* /* set */
);
OM_uint32 generic_gss_copy_oid
(OM_uint32 *, /* minor_status */
gss_OID_desc * const, /* oid */ /* SUNW15resync */
gss_OID * /* new_oid */
);
OM_uint32 generic_gss_create_empty_oid_set
(OM_uint32 *, /* minor_status */
gss_OID_set * /* oid_set */
);
OM_uint32 generic_gss_add_oid_set_member
(OM_uint32 *, /* minor_status */
gss_OID_desc * const, /* member_oid */
gss_OID_set * /* oid_set */
);
OM_uint32 generic_gss_test_oid_set_member
(OM_uint32 *, /* minor_status */
gss_OID_desc * const, /* member */
gss_OID_set, /* set */
int * /* present */
);
OM_uint32 generic_gss_oid_to_str
(OM_uint32 *, /* minor_status */
gss_OID_desc * const, /* oid */
gss_buffer_t /* oid_str */
);
OM_uint32 generic_gss_str_to_oid
(OM_uint32 *, /* minor_status */
gss_buffer_t, /* oid_str */
gss_OID * /* oid */
);
OM_uint32
generic_gss_oid_compose(
OM_uint32 *, /* minor_status */
const char *, /* prefix */
size_t, /* prefix_len */
int, /* suffix */
gss_OID_desc *); /* oid */
OM_uint32
generic_gss_oid_decompose(
OM_uint32 *, /* minor_status */
const char *, /*prefix */
size_t, /* prefix_len */
gss_OID_desc *, /* oid */
int *); /* suffix */
OM_uint32 generic_gss_create_empty_buffer_set
(OM_uint32 * /*minor_status*/,
gss_buffer_set_t * /*buffer_set*/);
OM_uint32 generic_gss_add_buffer_set_member
(OM_uint32 * /*minor_status*/,
const gss_buffer_t /*member_buffer*/,
gss_buffer_set_t * /*buffer_set*/);
OM_uint32 generic_gss_release_buffer_set
(OM_uint32 * /*minor_status*/,
gss_buffer_set_t * /*buffer_set*/);
/*
* SUNW17PACresync
* New map error API in MIT 1.7, at build time generates code for errors.
* Solaris does not gen the errors at build time so we just stub these
* for now, need to revisit.
* See mglueP.h and util_errmap.c in MIT 1.7.
*/
#ifdef _KERNEL
#define map_error(MINORP, MECH)
#define map_errcode(MINORP)
#else /* _KERNEL */
/* Use this to map an error code that was returned from a mech
operation; the mech will be asked to produce the associated error
messages.
Remember that if the minor status code cannot be returned to the
caller (e.g., if it's stuffed in an automatic variable and then
ignored), then we don't care about producing a mapping. */
#define map_error(MINORP, MECH) \
(*(MINORP) = gssint_mecherrmap_map(*(MINORP), &(MECH)->mech_type))
#define map_error_oid(MINORP, MECHOID) \
(*(MINORP) = gssint_mecherrmap_map(*(MINORP), (MECHOID)))
/* Use this to map an errno value or com_err error code being
generated within the mechglue code (e.g., by calling generic oid
ops). Any errno or com_err values produced by mech operations
should be processed with map_error. This means they'll be stored
separately even if the mech uses com_err, because we can't assume
that it will use com_err. */
#define map_errcode(MINORP) \
(*(MINORP) = gssint_mecherrmap_map_errcode(*(MINORP)))
#endif /* _KERNEL */
#endif /* _GSS_MECHGLUEP_H */
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* SUNW15resync
* This file (mglueP.h) is the MIT name for the mech glue
* header file, but the Solaris one is mechglueP.h. We keep this file
* so MIT files don't need to be changed to include the Solaris one.
*/
#include "mechglueP.h"
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _KGSSAPI_DEFS_H
#define _KGSSAPI_DEFS_H
#ifdef __cplusplus
extern "C" {
#endif
#include <sys/zone.h>
extern kmutex_t gssrpcb_lock;
extern kmutex_t __kgss_mech_lock;
extern zone_key_t gss_zone_key;
extern void *gss_zone_init(zoneid_t);
extern void gss_zone_fini(zoneid_t, void *);
/*
* GSSLOG debugging for kgss module.
*/
#if defined(DEBUG) && !defined(GSSDEBUG)
#define GSSDEBUG
#endif
#ifdef GSSDEBUG
extern uint_t gss_log;
#include <sys/cmn_err.h>
#define GSSLOG(A, B, C) \
((void)((gss_log & (A)) && (printf((B), (C)), TRUE)))
#define GSSLOG0(A, B) \
((void)((gss_log & (A)) && (printf(B), TRUE)))
#else
#define GSSLOG(A, B, C)
#define GSSLOG0(A, B)
#endif
#ifdef __cplusplus
}
#endif
#endif /* _KGSSAPI_DEFS_H */
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
* Copyright (c) 2011 Bayard G. Bell. All rights reserved.
*/
/*
* A module that implements a dummy security mechanism.
* It's mainly used to test GSS-API application. Multiple tokens
* exchanged during security context establishment can be
* specified through dummy_mech.conf located in /etc.
*/
#include <sys/types.h>
#include <sys/modctl.h>
#include <sys/errno.h>
#include <gssapiP_dummy.h>
#include <gssapi_err_generic.h>
#include <mechglueP.h>
#include <gssapi/kgssapi_defs.h>
#include <sys/debug.h>
#ifdef DUMMY_MECH_DEBUG
/*
* Kernel kgssd module debugging aid. The global variable "dummy_mech_log"
* is a bit mask which allows various types of debugging messages
* to be printed out.
*
* dummy_mech_log & 1 will cause actual failures to be printed.
* dummy_mech_log & 2 will cause informational messages to be
* printed on the client side of kgssd.
* dummy_mech_log & 4 will cause informational messages to be
* printed on the server side of kgssd.
* dummy_mech_log & 8 will cause informational messages to be
* printed on both client and server side of kgssd.
*/
uint_t dummy_mech_log = 1;
#endif
/* Local defines */
#define MAGIC_TOKEN_NUMBER 12345
/* private routines for dummy_mechanism */
static gss_buffer_desc make_dummy_token_msg(void *data, int datalen);
static int der_length_size(int);
static void der_write_length(unsigned char **, int);
static int der_read_length(unsigned char **, int *);
static int g_token_size(gss_OID mech, unsigned int body_size);
static void g_make_token_header(gss_OID mech, int body_size,
unsigned char **buf, int tok_type);
static int g_verify_token_header(gss_OID mech, int *body_size,
unsigned char **buf_in, int tok_type,
int toksize);
/* private global variables */
static int dummy_token_nums;
/*
* This OID:
* { iso(1) org(3) internet(6) dod(1) private(4) enterprises(1) sun(42)
* products(2) gssapi(26) mechtypes(1) dummy(2) }
*/
static struct gss_config dummy_mechanism =
{{10, "\053\006\001\004\001\052\002\032\001\002"},
NULL, /* context */
NULL, /* next */
TRUE, /* uses_kmod */
dummy_gss_unseal,
dummy_gss_delete_sec_context,
dummy_gss_seal,
dummy_gss_import_sec_context,
dummy_gss_sign,
dummy_gss_verify
};
static gss_mechanism
gss_mech_initialize()
{
dprintf("Entering gss_mech_initialize\n");
if (dummy_token_nums == 0)
dummy_token_nums = 1;
dprintf("Leaving gss_mech_initialize\n");
return (&dummy_mechanism);
}
/*
* Clean up after a failed mod_install()
*/
static void
gss_mech_fini()
{
/* Nothing to do */
}
/*
* Module linkage information for the kernel.
*/
extern struct mod_ops mod_miscops;
static struct modlmisc modlmisc = {
&mod_miscops, "in-kernel dummy GSS mechanism"
};
static struct modlinkage modlinkage = {
MODREV_1,
(void *)&modlmisc,
NULL
};
static int dummy_fini_code = EBUSY;
int
_init()
{
int retval;
gss_mechanism mech, tmp;
mech = gss_mech_initialize();
mutex_enter(&__kgss_mech_lock);
tmp = __kgss_get_mechanism(&mech->mech_type);
if (tmp != NULL) {
DUMMY_MECH_LOG0(8,
"dummy GSS mechanism: mechanism already in table.\n");
if (tmp->uses_kmod == TRUE) {
DUMMY_MECH_LOG0(8, "dummy GSS mechanism: mechanism "
"table supports kernel operations!\n");
}
/*
* keep us loaded, but let us be unloadable. This
* will give the developer time to trouble shoot
*/
dummy_fini_code = 0;
} else {
__kgss_add_mechanism(mech);
ASSERT(__kgss_get_mechanism(&mech->mech_type) == mech);
}
mutex_exit(&__kgss_mech_lock);
if ((retval = mod_install(&modlinkage)) != 0)
gss_mech_fini(); /* clean up */
return (retval);
}
int
_fini()
{
int ret = dummy_fini_code;
if (ret == 0) {
ret = (mod_remove(&modlinkage));
}
return (ret);
}
int
_info(struct modinfo *modinfop)
{
return (mod_info(&modlinkage, modinfop));
}
/*ARGSUSED*/
static OM_uint32
dummy_gss_sign(context, minor_status, context_handle,
qop_req, message_buffer, message_token,
gssd_ctx_verifier)
void *context;
OM_uint32 *minor_status;
gss_ctx_id_t context_handle;
int qop_req;
gss_buffer_t message_buffer;
gss_buffer_t message_token;
OM_uint32 gssd_ctx_verifier;
{
dummy_gss_ctx_id_rec *ctx;
char token_string[] = "dummy_gss_sign";
dprintf("Entering gss_sign\n");
if (context_handle == GSS_C_NO_CONTEXT)
return (GSS_S_NO_CONTEXT);
ctx = (dummy_gss_ctx_id_rec *) context_handle;
ASSERT(ctx->established == 1);
ASSERT(ctx->token_number == MAGIC_TOKEN_NUMBER);
*message_token = make_dummy_token_msg(
token_string, strlen(token_string));
dprintf("Leaving gss_sign\n");
return (GSS_S_COMPLETE);
}
/*ARGSUSED*/
static OM_uint32
dummy_gss_verify(context, minor_status, context_handle,
message_buffer, token_buffer, qop_state,
gssd_ctx_verifier)
void *context;
OM_uint32 *minor_status;
gss_ctx_id_t context_handle;
gss_buffer_t message_buffer;
gss_buffer_t token_buffer;
int *qop_state;
OM_uint32 gssd_ctx_verifier;
{
unsigned char *ptr;
int bodysize;
int err;
dummy_gss_ctx_id_rec *ctx;
dprintf("Entering gss_verify\n");
if (context_handle == GSS_C_NO_CONTEXT)
return (GSS_S_NO_CONTEXT);
ctx = (dummy_gss_ctx_id_rec *) context_handle;
ASSERT(ctx->established == 1);
ASSERT(ctx->token_number == MAGIC_TOKEN_NUMBER);
/* Check for defective input token. */
ptr = (unsigned char *) token_buffer->value;
if (err = g_verify_token_header((gss_OID)gss_mech_dummy, &bodysize,
&ptr, 0,
token_buffer->length)) {
*minor_status = err;
return (GSS_S_DEFECTIVE_TOKEN);
}
*qop_state = GSS_C_QOP_DEFAULT;
dprintf("Leaving gss_verify\n");
return (GSS_S_COMPLETE);
}
/*ARGSUSED*/
static OM_uint32
dummy_gss_seal(context, minor_status, context_handle, conf_req_flag,
qop_req, input_message_buffer, conf_state,
output_message_buffer, gssd_ctx_verifier)
void *context;
OM_uint32 *minor_status;
gss_ctx_id_t context_handle;
int conf_req_flag;
int qop_req;
gss_buffer_t input_message_buffer;
int *conf_state;
gss_buffer_t output_message_buffer;
OM_uint32 gssd_ctx_verifier;
{
gss_buffer_desc output;
dummy_gss_ctx_id_rec *ctx;
dprintf("Entering gss_seal\n");
if (context_handle == GSS_C_NO_CONTEXT)
return (GSS_S_NO_CONTEXT);
ctx = (dummy_gss_ctx_id_rec *) context_handle;
ASSERT(ctx->established == 1);
ASSERT(ctx->token_number == MAGIC_TOKEN_NUMBER);
/* Copy the input message to output message */
output = make_dummy_token_msg(
input_message_buffer->value, input_message_buffer->length);
if (conf_state)
*conf_state = 1;
*output_message_buffer = output;
dprintf("Leaving gss_seal\n");
return (GSS_S_COMPLETE);
}
/*ARGSUSED*/
static OM_uint32
dummy_gss_unseal(context, minor_status, context_handle,
input_message_buffer, output_message_buffer,
conf_state, qop_state, gssd_ctx_verifier)
void *context;
OM_uint32 *minor_status;
gss_ctx_id_t context_handle;
gss_buffer_t input_message_buffer;
gss_buffer_t output_message_buffer;
int *conf_state;
int *qop_state;
OM_uint32 gssd_ctx_verifier;
{
gss_buffer_desc output;
dummy_gss_ctx_id_rec *ctx;
unsigned char *ptr;
int bodysize;
int err;
dprintf("Entering gss_unseal\n");
if (context_handle == GSS_C_NO_CONTEXT)
return (GSS_S_NO_CONTEXT);
ctx = (dummy_gss_ctx_id_rec *) context_handle;
ASSERT(ctx->established == 1);
ASSERT(ctx->token_number == MAGIC_TOKEN_NUMBER);
ptr = (unsigned char *) input_message_buffer->value;
if (err = g_verify_token_header((gss_OID)gss_mech_dummy, &bodysize,
&ptr, 0,
input_message_buffer->length)) {
*minor_status = err;
return (GSS_S_DEFECTIVE_TOKEN);
}
output.length = bodysize;
output.value = (void *)MALLOC(output.length);
(void) memcpy(output.value, ptr, output.length);
*output_message_buffer = output;
*qop_state = GSS_C_QOP_DEFAULT;
if (conf_state)
*conf_state = 1;
dprintf("Leaving gss_unseal\n");
return (GSS_S_COMPLETE);
}
/*ARGSUSED*/
OM_uint32
dummy_gss_import_sec_context(ct, minor_status, interprocess_token,
context_handle)
void *ct;
OM_uint32 *minor_status;
gss_buffer_t interprocess_token;
gss_ctx_id_t *context_handle;
{
unsigned char *ptr;
int bodysize;
int err;
/* Assume that we got ctx from the interprocess token. */
dummy_gss_ctx_id_t ctx;
dprintf("Entering import_sec_context\n");
ptr = (unsigned char *) interprocess_token->value;
if (err = g_verify_token_header((gss_OID)gss_mech_dummy, &bodysize,
&ptr, 0,
interprocess_token->length)) {
*minor_status = err;
return (GSS_S_DEFECTIVE_TOKEN);
}
ctx = (dummy_gss_ctx_id_t)MALLOC(sizeof (dummy_gss_ctx_id_rec));
ctx->token_number = MAGIC_TOKEN_NUMBER;
ctx->established = 1;
*context_handle = (gss_ctx_id_t)ctx;
dprintf("Leaving import_sec_context\n");
return (GSS_S_COMPLETE);
}
/*ARGSUSED*/
static OM_uint32
dummy_gss_delete_sec_context(ct, minor_status,
context_handle, output_token,
gssd_ctx_verifier)
void *ct;
OM_uint32 *minor_status;
gss_ctx_id_t *context_handle;
gss_buffer_t output_token;
OM_uint32 gssd_ctx_verifier;
{
dummy_gss_ctx_id_t ctx;
dprintf("Entering delete_sec_context\n");
/* Make the length to 0, so the output token is not sent to peer */
if (output_token) {
output_token->length = 0;
output_token->value = NULL;
}
if (*context_handle == GSS_C_NO_CONTEXT) {
*minor_status = 0;
return (GSS_S_COMPLETE);
}
ctx = (dummy_gss_ctx_id_rec *) *context_handle;
ASSERT(ctx->established == 1);
ASSERT(ctx->token_number == MAGIC_TOKEN_NUMBER);
FREE(ctx, sizeof (dummy_gss_ctx_id_rec));
*context_handle = GSS_C_NO_CONTEXT;
dprintf("Leaving delete_sec_context\n");
return (GSS_S_COMPLETE);
}
static int
der_length_size(int length)
{
if (length < (1<<7))
return (1);
else if (length < (1<<8))
return (2);
else if (length < (1<<16))
return (3);
else if (length < (1<<24))
return (4);
else
return (5);
}
static void
der_write_length(unsigned char ** buf, int length)
{
if (length < (1<<7)) {
*(*buf)++ = (unsigned char) length;
} else {
*(*buf)++ = (unsigned char) (der_length_size(length)+127);
if (length >= (1<<24))
*(*buf)++ = (unsigned char) (length>>24);
if (length >= (1<<16))
*(*buf)++ = (unsigned char) ((length>>16)&0xff);
if (length >= (1<<8))
*(*buf)++ = (unsigned char) ((length>>8)&0xff);
*(*buf)++ = (unsigned char) (length&0xff);
}
}
static int
der_read_length(buf, bufsize)
unsigned char **buf;
int *bufsize;
{
unsigned char sf;
int ret;
if (*bufsize < 1)
return (-1);
sf = *(*buf)++;
(*bufsize)--;
if (sf & 0x80) {
if ((sf &= 0x7f) > ((*bufsize)-1))
return (-1);
if (sf > DUMMY_SIZE_OF_INT)
return (-1);
ret = 0;
for (; sf; sf--) {
ret = (ret<<8) + (*(*buf)++);
(*bufsize)--;
}
} else {
ret = sf;
}
return (ret);
}
static int
g_token_size(mech, body_size)
gss_OID mech;
unsigned int body_size;
{
/* set body_size to sequence contents size */
body_size += 4 + (int)mech->length; /* NEED overflow check */
return (1 + der_length_size(body_size) + body_size);
}
static void
g_make_token_header(mech, body_size, buf, tok_type)
gss_OID mech;
int body_size;
unsigned char **buf;
int tok_type;
{
*(*buf)++ = 0x60;
der_write_length(buf, 4 + mech->length + body_size);
*(*buf)++ = 0x06;
*(*buf)++ = (unsigned char) mech->length;
TWRITE_STR(*buf, mech->elements, ((int)mech->length));
*(*buf)++ = (unsigned char) ((tok_type>>8)&0xff);
*(*buf)++ = (unsigned char) (tok_type&0xff);
}
static int
g_verify_token_header(mech, body_size, buf_in, tok_type, toksize)
gss_OID mech;
int *body_size;
unsigned char **buf_in;
int tok_type;
int toksize;
{
unsigned char *buf = *buf_in;
int seqsize;
gss_OID_desc toid;
int ret = 0;
if ((toksize -= 1) < 0)
return (G_BAD_TOK_HEADER);
if (*buf++ != 0x60)
return (G_BAD_TOK_HEADER);
if ((seqsize = der_read_length(&buf, &toksize)) < 0)
return (G_BAD_TOK_HEADER);
if (seqsize != toksize)
return (G_BAD_TOK_HEADER);
if ((toksize -= 1) < 0)
return (G_BAD_TOK_HEADER);
if (*buf++ != 0x06)
return (G_BAD_TOK_HEADER);
if ((toksize -= 1) < 0)
return (G_BAD_TOK_HEADER);
toid.length = *buf++;
if ((toksize -= toid.length) < 0)
return (G_BAD_TOK_HEADER);
toid.elements = buf;
buf += toid.length;
if (! g_OID_equal(&toid, mech))
ret = G_WRONG_MECH;
/*
* G_WRONG_MECH is not returned immediately because it's more important
* to return G_BAD_TOK_HEADER if the token header is in fact bad
*/
if ((toksize -= 2) < 0)
return (G_BAD_TOK_HEADER);
if ((*buf++ != ((tok_type>>8)&0xff)) ||
(*buf++ != (tok_type&0xff)))
return (G_BAD_TOK_HEADER);
if (!ret) {
*buf_in = buf;
*body_size = toksize;
}
return (ret);
}
static gss_buffer_desc
make_dummy_token_msg(void *data, int dataLen)
{
gss_buffer_desc buffer;
int tlen;
unsigned char *t;
unsigned char *ptr;
if (data == NULL) {
buffer.length = 0;
buffer.value = NULL;
return (buffer);
}
tlen = g_token_size((gss_OID)gss_mech_dummy, dataLen);
t = (unsigned char *) MALLOC(tlen);
ptr = t;
g_make_token_header((gss_OID)gss_mech_dummy, dataLen, &ptr, 0);
(void) memcpy(ptr, data, dataLen);
buffer.length = tlen;
buffer.value = (void *) t;
return (buffer);
}
* Copyright 1989,1990,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. 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.
* Copyright 1987-2004 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.
* Copyright (C) 1989-1995 by the Massachusetts Institute of Technology,
* Cambridge, MA, USA. All Rights Reserved.
*
* This software is being provided to you, the LICENSEE, by the
* Massachusetts Institute of Technology (M.I.T.) under the following
* license. By obtaining, using and/or copying this software, you agree
* that you have read, understood, and will comply with these terms and
* conditions:
*
* 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 or
* royalty is hereby granted, provided that you agree to comply with the
* following copyright notice and statements, including the disclaimer, and
* that the same appear on ALL copies of the software and documentation,
* including modifications that you make for internal use or for
* distribution:
*
* THIS SOFTWARE IS PROVIDED "AS IS", AND M.I.T. MAKES NO REPRESENTATIONS
* OR WARRANTIES, EXPRESS OR IMPLIED. By way of example, but not
* limitation, M.I.T. MAKES NO REPRESENTATIONS OR WARRANTIES OF
* MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF
* THE LICENSED SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY
* PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
*
* The name of the Massachusetts Institute of Technology or M.I.T. may NOT
* be used in advertising or publicity pertaining to distribution of the
* software. Title to copyright in this software and any associated
* documentation shall at all times remain with M.I.T., and USER agrees to
* preserve same.
** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved. **
** **
** License to copy and use this software is granted provided that **
** it is identified as the "RSA Data Security, Inc. MD4 Message **
** Digest Algorithm" in all material mentioning or referencing this **
** software or this function. **
** **
** License is also granted to make and use derivative works **
** provided that such works are identified as "derived from the RSA **
** Data Security, Inc. MD4 Message Digest Algorithm" in all **
** material mentioning or referencing the derived work. **
** **
** RSA Data Security, Inc. makes no representations concerning **
** either the merchantability of this software or the suitability **
** of this software for any particular purpose. It is provided "as **
** is" without express or implied warranty of any kind. **
** **
** These notices must be retained in any copies of any part of this **
** documentation and/or software. **
* Copyright 1993,1995 by OpenVision Technologies, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appears in all copies and
* that both that copyright notice and this permission notice appear in
* supporting documentation, and that the name of OpenVision not be used
* in advertising or publicity pertaining to distribution of the software
* without specific, written prior permission. OpenVision makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
* OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
* 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.
* Copyright (c) 2002 Naval Research Laboratory (NRL/CCS)
*
* Permission to use, copy, modify and distribute this software and its
* documentation is hereby granted, provided that both the copyright
* notice and this permission notice appear in all copies of the software,
* derivative works or modified versions, and any portions thereof.
*
* NRL ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION AND
* DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
* RESULTING FROM THE USE OF THIS SOFTWARE.
* Copyright 1995 by Richard P. Basch. All Rights Reserved.
* Copyright 1995 by Lehman Brothers, 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 Richard P. Basch, Lehman Brothers and M.I.T. not be used
* in advertising or publicity pertaining to distribution of the software
* without specific, written prior permission. Richard P. Basch,
* Lehman Brothers and M.I.T. make no representations about the suitability
* of this software for any purpose. It is provided "as is" without
* express or implied warranty.
PORTIONS OF KERBEROS MECHANISM FOR GENERIC SECURITY SERVICES (KERNEL)
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
ARCFOUR cipher (based on a cipher posted on the Usenet in Spring-95).
This cipher is widely believed and has been tested to be equivalent
with the RC4 cipher from RSA Data Security, Inc. (RC4 is a trademark
of RSA Data Security)
*/
#include <k5-int.h>
#include <arcfour.h>
/* salt string used for exportable ARCFOUR */
static const char *l40 = "fortybits";
void
krb5_arcfour_encrypt_length(enc, hash, inputlen, length)
const struct krb5_enc_provider *enc;
const struct krb5_hash_provider *hash;
size_t inputlen;
size_t *length;
{
size_t blocksize, hashsize;
blocksize = enc->block_size;
hashsize = hash->hashsize;
/* checksum + (confounder + inputlen, in even blocksize) */
*length = hashsize + krb5_roundup(8 + inputlen, blocksize);
}
krb5_keyusage
krb5int_arcfour_translate_usage(krb5_keyusage usage)
{
switch (usage) {
case 1: /* AS-REQ PA-ENC-TIMESTAMP padata timestamp, */
return 1;
case 2: /* ticket from kdc */
return 2;
case 3: /* as-rep encrypted part */
return 8;
case 4: /* tgs-req authz data */
return 4;
case 5: /* tgs-req authz data in subkey */
return 5;
case 6: /* tgs-req authenticator cksum */
return 6;
case 7: /* tgs-req authenticator */
return 7;
case 8:
return 8;
case 9: /* tgs-rep encrypted with subkey */
return 8;
case 10: /* ap-rep authentication cksum */
return 10; /* xxx Microsoft never uses this*/
case 11: /* app-req authenticator */
return 11;
case 12: /* app-rep encrypted part */
return 12;
case 23: /* sign wrap token*/
return 13;
default:
return usage;
}
}
krb5_error_code
krb5_arcfour_encrypt(context, enc, hash, key, usage, ivec, input, output)
krb5_context context;
const struct krb5_enc_provider *enc;
const struct krb5_hash_provider *hash;
const krb5_keyblock *key;
krb5_keyusage usage;
const krb5_data *ivec;
const krb5_data *input;
krb5_data *output;
{
krb5_keyblock k1, k2, k3;
krb5_keyblock *kptr;
krb5_data d1, d2, d3, salt, plaintext, checksum, ciphertext, confounder;
krb5_keyusage ms_usage;
size_t keybytes, blocksize, hashsize;
krb5_error_code ret = 0;
blocksize = enc->block_size;
keybytes = enc->keybytes;
hashsize = hash->hashsize;
bzero(&d2, sizeof(krb5_data));
bzero(&k2, sizeof(krb5_keyblock));
/*
* d1 is the contents buffer for key k1.
* k1 = HMAC(input_key, salt)
*/
d1.length=keybytes;
d1.data=MALLOC(d1.length);
if (d1.data == NULL)
return (ENOMEM);
bcopy(key, &k1, sizeof (krb5_keyblock));
k1.length=d1.length;
k1.contents= (void *) d1.data;
/*
* d2 is the contents of key 'k2', which is used to generate the
* checksum field. 'd2' == 'd1' when not using the exportable
* enctype. This is only needed when using the exportable
* enctype.
*/
if (key->enctype==ENCTYPE_ARCFOUR_HMAC_EXP) {
d2.length=keybytes;
d2.data=MALLOC(d2.length);
if (d2.data == NULL) {
FREE(d1.data, d1.length);
return (ENOMEM);
}
bcopy(key, &k2, sizeof (krb5_keyblock));
k2.length=d2.length;
k2.contents=(void *) d2.data;
}
/*
* d3 will hold the contents of the final key used for the
* encryption step. 'k3' is the key structure that has 'd3'
* as its 'contents' field.
* k3 = HMAC(k1, checksum)
*/
d3.length=keybytes;
d3.data=MALLOC(d3.length);
if (d3.data == NULL) {
FREE(d1.data, d1.length);
if (d2.data)
FREE(d2.data, d2.length);
return (ENOMEM);
}
bcopy(key, &k3, sizeof (krb5_keyblock));
k3.length=d3.length;
k3.contents= (void *) d3.data;
salt.length=14;
salt.data=MALLOC(salt.length);
if (salt.data == NULL) {
FREE(d1.data, d1.length);
if (d2.data)
FREE(d2.data, d2.length);
FREE(d3.data, d3.length);
return (ENOMEM);
}
/* is "input" already blocksize aligned? if it is, then we need this
step, otherwise we do not */
plaintext.length=krb5_roundup(input->length+CONFOUNDERLENGTH,blocksize);
plaintext.data=MALLOC(plaintext.length);
if (plaintext.data == NULL) {
FREE(d1.data, d1.length);
if (d2.data)
FREE(d2.data, d2.length);
FREE(d3.data, d3.length);
FREE(salt.data, salt.length);
return(ENOMEM);
}
bzero(plaintext.data, plaintext.length);
/* setup convienient pointers into the allocated data */
checksum.length=hashsize;
checksum.data=output->data;
ciphertext.length=krb5_roundup(input->length+CONFOUNDERLENGTH,blocksize);
ciphertext.data=output->data+hashsize;
confounder.length=CONFOUNDERLENGTH;
confounder.data=plaintext.data;
output->length = plaintext.length+hashsize;
/* begin the encryption, computer K1 */
ms_usage=krb5int_arcfour_translate_usage(usage);
if (key->enctype == ENCTYPE_ARCFOUR_HMAC_EXP) {
(void) strncpy(salt.data, l40, salt.length);
salt.data[10]=ms_usage & 0xff;
salt.data[11]=(ms_usage >> 8) & 0xff;
salt.data[12]=(ms_usage >> 16) & 0xff;
salt.data[13]=(ms_usage >> 24) & 0xff;
} else {
salt.length=4;
salt.data[0]=ms_usage & 0xff;
salt.data[1]=(ms_usage >> 8) & 0xff;
salt.data[2]=(ms_usage >> 16) & 0xff;
salt.data[3]=(ms_usage >> 24) & 0xff;
}
#ifdef _KERNEL
ret = krb5_hmac(context, key, &salt, &d1);
#else
ret = krb5_hmac(context, hash, key, 1, &salt, &d1);
#endif /* _KERNEL */
if (ret != 0)
goto cleanup;
if (key->enctype==ENCTYPE_ARCFOUR_HMAC_EXP) {
bcopy(k1.contents, k2.contents, k2.length);
(void) memset(k1.contents+7, 0xab, 9);
kptr = &k2;
} else {
kptr = &k1;
}
/* create a confounder block */
ret=krb5_c_random_make_octets(context, &confounder);
bcopy(input->data, plaintext.data+confounder.length, input->length);
if (ret)
goto cleanup;
/*
* Compute the HMAC checksum field.
* checksum = HMAC(k1/k2, plaintext);
* k2 used when key->enctype==ENCTYPE_ARCFOUR_HMAC_EXP
*/
#ifdef _KERNEL
ret = krb5_hmac(context, kptr, &plaintext, &checksum);
#else
ret = krb5_hmac(context, hash, kptr, 1, &plaintext, &checksum);
#endif /* _KERNEL */
if (ret)
goto cleanup;
/*
* The final encryption key is the HMAC of the checksum
* using k1
*
* k3 = HMAC(k1, checksum);
* == or (in other terms) ==
* k3 = HMAC((HMAC(input_key,salt), HMAC(k1, plaintext));
*/
#ifdef _KERNEL
ret = krb5_hmac(context, &k1, &checksum, &d3);
#else
ret = krb5_hmac(context, hash, &k1, 1, &checksum, &d3);
#endif /* _KERNEL */
if (ret)
goto cleanup;
ret = (*(enc->encrypt))(context, &k3, ivec, &plaintext, &ciphertext);
cleanup:
bzero(d1.data, d1.length);
if (d2.data) {
bzero(d2.data, d2.length);
FREE(d2.data, d2.length);
}
bzero(d3.data, d3.length);
bzero(salt.data, salt.length);
bzero(plaintext.data, plaintext.length);
FREE(d1.data, d1.length);
FREE(d3.data, d3.length);
FREE(salt.data, salt.length);
FREE(plaintext.data, plaintext.length);
return (ret);
}
/* This is the arcfour-hmac decryption routine */
krb5_error_code
krb5_arcfour_decrypt(context, enc, hash, key, usage, ivec, input, output)
krb5_context context;
const struct krb5_enc_provider *enc;
const struct krb5_hash_provider *hash;
const krb5_keyblock *key;
krb5_keyusage usage;
const krb5_data *ivec;
const krb5_data *input;
krb5_data *output;
{
krb5_keyblock k1,k2,k3, *kptr;
krb5_data d1,d2,d3,salt,ciphertext,plaintext,checksum;
krb5_keyusage ms_usage;
size_t keybytes, hashsize;
krb5_error_code ret;
keybytes = enc->keybytes;
hashsize = hash->hashsize;
/* Verify input and output lengths. */
if (input->length < hashsize + CONFOUNDERLENGTH)
return KRB5_BAD_MSIZE;
if (output->length < input->length - hashsize - CONFOUNDERLENGTH)
return KRB5_BAD_MSIZE;
bzero(&d2, sizeof(krb5_data));
bzero(&k2, sizeof(krb5_keyblock));
/*
* d1 is the contents buffer for key k1.
* k1 = HMAC(input_key, salt)
*/
d1.length=keybytes;
d1.data=MALLOC(d1.length);
if (d1.data == NULL)
return (ENOMEM);
(void) bcopy(key, &k1, sizeof (krb5_keyblock));
k1.length=d1.length;
k1.contents= (void *) d1.data;
/*
* d2 is the contents of key 'k2', which is used to generate the
* checksum field. 'd2' == 'd1' when not using the exportable
* enctype. This is only needed when using the exportable
* enctype.
*/
if (key->enctype==ENCTYPE_ARCFOUR_HMAC_EXP) {
d2.length=keybytes;
d2.data=MALLOC(d2.length);
if (d2.data == NULL) {
FREE(d1.data, d1.length);
return (ENOMEM);
}
(void) bcopy(key, &k2, sizeof(krb5_keyblock));
k2.length=d2.length;
k2.contents= (void *) d2.data;
}
/*
* d3 will hold the contents of the final key used for the
* encryption step. 'k3' is the key structure that has 'd3'
* as its 'contents' field.
* k3 = HMAC(k1, checksum)
*/
d3.length=keybytes;
d3.data=MALLOC(d3.length);
if (d3.data == NULL) {
FREE(d1.data, d1.length);
if (d2.data)
FREE(d2.data, d2.length);
return (ENOMEM);
}
bcopy(key, &k3, sizeof(krb5_keyblock));
k3.length=d3.length;
k3.contents= (void *) d3.data;
salt.length=14;
salt.data=MALLOC(salt.length);
if(salt.data==NULL) {
FREE(d1.data, d1.length);
if (d2.data)
FREE(d2.data, d2.length);
FREE(d3.data, d3.length);
return (ENOMEM);
}
ciphertext.length=input->length-hashsize;
ciphertext.data=input->data+hashsize;
plaintext.length=ciphertext.length;
plaintext.data=MALLOC(plaintext.length);
if (plaintext.data == NULL) {
FREE(d1.data, d1.length);
if (d2.data)
FREE(d2.data, d2.length);
FREE(d3.data, d3.length);
FREE(salt.data, salt.length);
return (ENOMEM);
}
checksum.length=hashsize;
checksum.data=input->data;
/* compute the salt */
ms_usage=krb5int_arcfour_translate_usage(usage);
if (key->enctype == ENCTYPE_ARCFOUR_HMAC_EXP) {
(void) strncpy(salt.data, l40, salt.length);
salt.data[10]=ms_usage & 0xff;
salt.data[11]=(ms_usage>>8) & 0xff;
salt.data[12]=(ms_usage>>16) & 0xff;
salt.data[13]=(ms_usage>>24) & 0xff;
} else {
salt.length=4;
salt.data[0]=ms_usage & 0xff;
salt.data[1]=(ms_usage>>8) & 0xff;
salt.data[2]=(ms_usage>>16) & 0xff;
salt.data[3]=(ms_usage>>24) & 0xff;
}
#ifdef _KERNEL
ret=krb5_hmac(context, key, &salt, &d1);
#else
ret=krb5_hmac(context, hash, key, 1, &salt, &d1);
#endif /* _KERNEL */
if (ret)
goto cleanup;
if (key->enctype == ENCTYPE_ARCFOUR_HMAC_EXP) {
bcopy(k1.contents, k2.contents, d1.length);
(void) memset(k1.contents+7, 0xab, 9);
kptr = &k2;
} else {
kptr = &k1;
}
#ifdef _KERNEL
ret = krb5_hmac(context, &k1, &checksum, &d3);
#else
ret = krb5_hmac(context, hash, &k1, 1, &checksum, &d3);
#endif /* _KERNEL */
if (ret)
goto cleanup;
ret=(*(enc->decrypt))(context, &k3, ivec, &ciphertext, &plaintext);
if (ret)
goto cleanup;
#ifdef _KERNEL
ret = krb5_hmac(context, kptr, &plaintext, &d1);
#else
ret = krb5_hmac(context, hash, kptr, 1, &plaintext, &d1);
#endif /* _KERNEL */
if (ret)
goto cleanup;
if (bcmp(checksum.data, d1.data, hashsize) != 0) {
ret=KRB5KRB_AP_ERR_BAD_INTEGRITY;
goto cleanup;
}
bcopy(plaintext.data+CONFOUNDERLENGTH, output->data,
(plaintext.length-CONFOUNDERLENGTH));
output->length=plaintext.length-CONFOUNDERLENGTH;
cleanup:
bzero(d1.data, d1.length);
if (d2.data) {
bzero(d2.data, d2.length);
FREE(d2.data, d2.length);
}
bzero(d3.data, d2.length);
bzero(salt.data, salt.length);
bzero(plaintext.data, plaintext.length);
FREE(d1.data, d1.length);
FREE(d3.data, d3.length);
FREE(salt.data, salt.length);
FREE(plaintext.data, plaintext.length);
return (ret);
}
/*
* 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 "k5-int.h"
#include "etypes.h"
/*ARGSUSED*/
krb5_error_code KRB5_CALLCONV
krb5_c_block_size(krb5_context context, krb5_enctype enctype,
size_t *blocksize)
{
int i;
for (i=0; i<krb5_enctypes_length; i++) {
if (krb5_enctypes_list[i].etype == enctype)
break;
}
if (i == krb5_enctypes_length)
return(KRB5_BAD_ENCTYPE);
*blocksize = krb5_enctypes_list[i].enc->block_size;
return(0);
}
/*
* 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 "k5-int.h"
#include "cksumtypes.h"
/*ARGSUSED*/
krb5_error_code KRB5_CALLCONV
krb5_c_checksum_length(krb5_context context, krb5_cksumtype cksumtype,
size_t *length)
{
int i;
for (i=0; i<krb5_cksumtypes_length; i++) {
if (krb5_cksumtypes_list[i].ctype == cksumtype)
break;
}
if (i == krb5_cksumtypes_length)
return(KRB5_BAD_ENCTYPE);
if (krb5_cksumtypes_list[i].keyhash)
*length = krb5_cksumtypes_list[i].keyhash->hashsize;
else if (krb5_cksumtypes_list[i].trunc_size)
*length = krb5_cksumtypes_list[i].trunc_size;
else
*length = krb5_cksumtypes_list[i].hash->hashsize;
return(0);
}
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* 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 "k5-int.h"
#include "hash_provider.h"
#include "keyhash_provider.h"
#include "cksumtypes.h"
const struct krb5_cksumtypes krb5_cksumtypes_list[] = {
{ CKSUMTYPE_CRC32, KRB5_CKSUMFLAG_NOT_COLL_PROOF,
"crc32", "CRC-32",
0, NULL, &krb5int_hash_crc32, 0,
#ifdef _KERNEL
NULL,
CRYPTO_MECH_INVALID
#endif /* _KERNEL */
},
{ CKSUMTYPE_DESCBC, 0,
"des-cbc", "DES cbc mode",
ENCTYPE_DES_CBC_CRC, &krb5int_keyhash_descbc,
0, 0,
#ifdef _KERNEL
NULL,
CRYPTO_MECH_INVALID
#endif /* _KERNEL */
},
{ CKSUMTYPE_RSA_MD5, 0,
"md5", "RSA-MD5",
0, NULL, &krb5int_hash_md5, 0,
#ifdef _KERNEL
SUN_CKM_MD5,
CRYPTO_MECH_INVALID
#endif /* _KERNEL */
},
{ CKSUMTYPE_RSA_MD5_DES, 0,
"md5-des", "RSA-MD5 with DES cbc mode",
ENCTYPE_DES_CBC_CRC, &krb5int_keyhash_md5des,
0, 0,
#ifdef _KERNEL
SUN_CKM_MD5,
CRYPTO_MECH_INVALID
#endif /* _KERNEL */
},
{ CKSUMTYPE_NIST_SHA, 0,
"sha", "NIST-SHA",
0, NULL, &krb5int_hash_sha1, 0,
#ifdef _KERNEL
SUN_CKM_SHA1,
CRYPTO_MECH_INVALID
#endif /* _KERNEL */
},
{ CKSUMTYPE_HMAC_SHA1_DES3, KRB5_CKSUMFLAG_DERIVE,
"hmac-sha1-des3", "HMAC-SHA1 DES3 key",
0, NULL, &krb5int_hash_sha1, 0,
#ifdef _KERNEL
SUN_CKM_SHA1_HMAC,
CRYPTO_MECH_INVALID
#endif /* _KERNEL */
},
{ CKSUMTYPE_HMAC_SHA1_DES3, KRB5_CKSUMFLAG_DERIVE,
"hmac-sha1-des3-kd", "HMAC-SHA1 DES3 key", /* alias */
0, NULL, &krb5int_hash_sha1, 0,
#ifdef _KERNEL
SUN_CKM_SHA1_HMAC,
CRYPTO_MECH_INVALID
#endif /* _KERNEL */
},
{ CKSUMTYPE_HMAC_MD5_ARCFOUR, 0,
"hmac-md5-rc4", "Microsoft HMAC MD5 (RC4 key)",
ENCTYPE_ARCFOUR_HMAC, &krb5int_keyhash_hmac_md5,
NULL, 0,
#ifdef _KERNEL
SUN_CKM_MD5,
CRYPTO_MECH_INVALID
#endif /* _KERNEL */
},
{ CKSUMTYPE_HMAC_MD5_ARCFOUR, 0,
"hmac-md5-enc", "Microsoft HMAC MD5 (RC4 key)", /*Heimdal alias*/
ENCTYPE_ARCFOUR_HMAC, &krb5int_keyhash_hmac_md5,
NULL, 0,
#ifdef _KERNEL
SUN_CKM_MD5,
CRYPTO_MECH_INVALID
#endif /* _KERNEL */
},
{ CKSUMTYPE_HMAC_MD5_ARCFOUR, 0,
"hmac-md5-earcfour", "Microsoft HMAC MD5 (RC4 key)", /* alias*/
ENCTYPE_ARCFOUR_HMAC, &krb5int_keyhash_hmac_md5,
NULL, 0,
#ifdef _KERNEL
SUN_CKM_MD5,
CRYPTO_MECH_INVALID
#endif /* _KERNEL */
},
{ CKSUMTYPE_HMAC_SHA1_96_AES128, KRB5_CKSUMFLAG_DERIVE,
"hmac-sha1-96-aes128", "HMAC-SHA1 AES128 key",
0, NULL, &krb5int_hash_sha1, 12,
#ifdef _KERNEL
SUN_CKM_SHA1_HMAC,
CRYPTO_MECH_INVALID
#endif /* _KERNEL */
},
{ CKSUMTYPE_HMAC_SHA1_96_AES256, KRB5_CKSUMFLAG_DERIVE,
"hmac-sha1-96-aes256", "HMAC-SHA1 AES256 key",
0, NULL, &krb5int_hash_sha1, 12,
#ifdef _KERNEL
SUN_CKM_SHA1_HMAC,
CRYPTO_MECH_INVALID
#endif /* _KERNEL */
}
};
const int krb5_cksumtypes_length =
sizeof(krb5_cksumtypes_list)/sizeof(struct krb5_cksumtypes);
/* Solaris Kerberos */
#ifdef _KERNEL
void
setup_kef_cksumtypes()
{
int i;
struct krb5_cksumtypes *ck;
for (i=0; i<krb5_cksumtypes_length; i++) {
ck = (struct krb5_cksumtypes *)&krb5_cksumtypes_list[i];
if (ck != NULL &&
ck->mt_c_name != NULL &&
ck->kef_cksum_mt == CRYPTO_MECH_INVALID) {
ck->kef_cksum_mt = crypto_mech2id(ck->mt_c_name);
KRB5_LOG1(KRB5_INFO, "setup_kef_cksumtypes() - "
"%s ==> %ld",
ck->mt_c_name, (ulong_t)ck->kef_cksum_mt);
}
}
}
#endif /* _KERNEL */
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright (c) 2002 Naval Research Laboratory (NRL/CCS)
*
* Permission to use, copy, modify and distribute this software and its
* documentation is hereby granted, provided that both the copyright
* notice and this permission notice appear in all copies of the software,
* derivative works or modified versions, and any portions thereof.
*
* NRL ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION AND
* DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
* RESULTING FROM THE USE OF THIS SOFTWARE.
*
* Key combination function.
*
* If Key1 and Key2 are two keys to be combined, the algorithm to combine
* them is as follows.
*
* Definitions:
*
* k-truncate is defined as truncating to the key size the input.
*
* DR is defined as the generate "random" data from a key
* (defined in crypto draft)
*
* DK is defined as the key derivation function (krb5_derive_key())
*
* (note: | means "concatenate")
*
* Combine key algorithm:
*
* R1 = DR(Key1, n-fold(Key2)) [ Output is length of Key1 ]
* R2 = DR(Key2, n-fold(Key1)) [ Output is length of Key2 ]
*
* rnd = n-fold(R1 | R2) [ Note: output size of nfold must be appropriately
* sized for random-to-key function ]
* tkey = random-to-key(rnd)
* Combine-Key(Key1, Key2) = DK(tkey, CombineConstant)
*
* CombineConstant is defined as the byte string:
*
* { 0x63 0x6f 0x6d 0x62 0x69 0x6e 0x65 }, which corresponds to the
* ASCII encoding of the string "combine"
*/
#include "k5-int.h"
#include "etypes.h"
#include "dk.h"
/* Solaris Kerberos */
static krb5_error_code dr
(krb5_context context,
const struct krb5_enc_provider *enc, const krb5_keyblock *inkey,
unsigned char *outdata, const krb5_data *in_constant);
/*
* We only support this combine_keys algorithm for des and 3des keys.
* Everything else should use the PRF defined in the crypto framework.
* We don't implement that yet.
*/
static krb5_boolean enctype_ok (krb5_enctype e)
{
switch (e) {
case ENCTYPE_DES_CBC_CRC:
case ENCTYPE_DES_CBC_MD4:
case ENCTYPE_DES_CBC_MD5:
case ENCTYPE_DES3_CBC_SHA1:
return 1;
default:
return 0;
}
}
krb5_error_code krb5int_c_combine_keys
(krb5_context context, krb5_keyblock *key1, krb5_keyblock *key2, krb5_keyblock *outkey)
{
unsigned char *r1, *r2, *combined, *rnd, *output;
size_t keybytes, keylength;
const struct krb5_enc_provider *enc;
krb5_data input, randbits;
krb5_keyblock tkey;
krb5_error_code ret;
int i, myalloc = 0;
if (!(enctype_ok(key1->enctype)&&enctype_ok(key2->enctype)))
return (KRB5_CRYPTO_INTERNAL);
if (key1->length != key2->length || key1->enctype != key2->enctype)
return (KRB5_CRYPTO_INTERNAL);
/*
* Find our encryption algorithm
*/
for (i = 0; i < krb5_enctypes_length; i++) {
if (krb5_enctypes_list[i].etype == key1->enctype)
break;
}
if (i == krb5_enctypes_length)
return (KRB5_BAD_ENCTYPE);
enc = krb5_enctypes_list[i].enc;
keybytes = enc->keybytes;
keylength = enc->keylength;
/*
* Allocate and set up buffers
*/
if ((r1 = (unsigned char *) malloc(keybytes)) == NULL)
return (ENOMEM);
if ((r2 = (unsigned char *) malloc(keybytes)) == NULL) {
free(r1);
return (ENOMEM);
}
if ((rnd = (unsigned char *) malloc(keybytes)) == NULL) {
free(r1);
free(r2);
return (ENOMEM);
}
if ((combined = (unsigned char *) malloc(keybytes * 2)) == NULL) {
free(r1);
free(r2);
free(rnd);
return (ENOMEM);
}
if ((output = (unsigned char *) malloc(keylength)) == NULL) {
free(r1);
free(r2);
free(rnd);
free(combined);
return (ENOMEM);
}
/*
* Get R1 and R2 (by running the input keys through the DR algorithm.
* Note this is most of derive-key, but not all.
*/
input.length = key2->length;
input.data = (char *) key2->contents;
/* Solaris Kerberos */
if ((ret = dr(context, enc, key1, r1, &input)))
goto cleanup;
#if 0
{
int i;
printf("R1 =");
for (i = 0; i < keybytes; i++)
printf(" %02x", (unsigned char) r1[i]);
printf("\n");
}
#endif
input.length = key1->length;
input.data = (char *) key1->contents;
/* Solaris Kerberos */
if ((ret = dr(context, enc, key2, r2, &input)))
goto cleanup;
#if 0
{
int i;
printf("R2 =");
for (i = 0; i < keybytes; i++)
printf(" %02x", (unsigned char) r2[i]);
printf("\n");
}
#endif
/*
* Concatenate the two keys together, and then run them through
* n-fold to reduce them to a length appropriate for the random-to-key
* operation. Note here that krb5_nfold() takes sizes in bits, hence
* the multiply by 8.
*/
memcpy(combined, r1, keybytes);
memcpy(combined + keybytes, r2, keybytes);
krb5_nfold((keybytes * 2) * 8, combined, keybytes * 8, rnd);
#if 0
{
int i;
printf("rnd =");
for (i = 0; i < keybytes; i++)
printf(" %02x", (unsigned char) rnd[i]);
printf("\n");
}
#endif
/*
* Run the "random" bits through random-to-key to produce a encryption
* key.
*/
randbits.length = keybytes;
randbits.data = (char *) rnd;
tkey.length = keylength;
tkey.contents = output;
/* Solaris Kerberos */
if ((ret = (*(enc->make_key))(context, &randbits, &tkey)))
goto cleanup;
#if 0
{
int i;
printf("tkey =");
for (i = 0; i < tkey.length; i++)
printf(" %02x", (unsigned char) tkey.contents[i]);
printf("\n");
}
#endif
/*
* Run through derive-key one more time to produce the final key.
* Note that the input to derive-key is the ASCII string "combine".
*/
input.length = 7; /* Note; change this if string length changes */
input.data = "combine";
/*
* Just FYI: _if_ we have space here in the key, then simply use it
* without modification. But if the key is blank (no allocated storage)
* then allocate some memory for it. This allows programs to use one of
* the existing keys as the output key, _or_ pass in a blank keyblock
* for us to allocate. It's easier for us to allocate it since we already
* know the crypto library internals
*/
if (outkey->length == 0 || outkey->contents == NULL) {
outkey->contents = (krb5_octet *) malloc(keylength);
if (!outkey->contents) {
ret = ENOMEM;
goto cleanup;
}
outkey->length = keylength;
outkey->enctype = key1->enctype;
myalloc = 1;
}
/* Solaris Kerberos */
if ((ret = krb5_derive_key(context, enc, &tkey, outkey, &input))) {
if (myalloc) {
free(outkey->contents);
outkey->contents = NULL;
}
goto cleanup;
}
#if 0
{
int i;
printf("output =");
for (i = 0; i < outkey->length; i++)
printf(" %02x", (unsigned char) outkey->contents[i]);
printf("\n");
}
#endif
ret = 0;
cleanup:
memset(r1, 0, keybytes);
memset(r2, 0, keybytes);
memset(rnd, 0, keybytes);
memset(combined, 0, keybytes * 2);
memset(output, 0, keylength);
free(r1);
free(r2);
free(rnd);
free(combined);
free(output);
return (ret);
}
/*
* Our DR function; mostly taken from derive.c
*/
/* Solaris Kerberos */
static krb5_error_code dr
( krb5_context context,
const struct krb5_enc_provider *enc,
const krb5_keyblock *inkey,
unsigned char *out,
const krb5_data *in_constant)
{
size_t blocksize, keybytes, keylength, n;
unsigned char *inblockdata, *outblockdata;
krb5_data inblock, outblock;
blocksize = enc->block_size;
keybytes = enc->keybytes;
keylength = enc->keylength;
/* allocate and set up buffers */
if ((inblockdata = (unsigned char *) malloc(blocksize)) == NULL)
return(ENOMEM);
if ((outblockdata = (unsigned char *) malloc(blocksize)) == NULL) {
free(inblockdata);
return(ENOMEM);
}
inblock.data = (char *) inblockdata;
inblock.length = blocksize;
outblock.data = (char *) outblockdata;
outblock.length = blocksize;
/* initialize the input block */
if (in_constant->length == inblock.length) {
memcpy(inblock.data, in_constant->data, inblock.length);
} else {
krb5_nfold(in_constant->length*8, (unsigned char *) in_constant->data,
inblock.length*8, (unsigned char *) inblock.data);
}
/* loop encrypting the blocks until enough key bytes are generated */
n = 0;
while (n < keybytes) {
/* Solaris Kerberos */
(*(enc->encrypt))(context, inkey, 0, &inblock, &outblock);
if ((keybytes - n) <= outblock.length) {
memcpy(out+n, outblock.data, (keybytes - n));
break;
}
memcpy(out+n, outblock.data, outblock.length);
memcpy(inblock.data, outblock.data, outblock.length);
n += outblock.length;
}
/* clean memory, free resources and exit */
memset(inblockdata, 0, blocksize);
memset(outblockdata, 0, blocksize);
free(outblockdata);
free(inblockdata);
return(0);
}
/*
* Copyright 2001-2002 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* lib/crypto/crc32/crc.c
*
* Copyright 1990 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. 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.
*
*
* CRC-32/AUTODIN-II routines
*/
#include <k5-int.h>
#include <gssapiP_generic.h>
#include <crc-32.h>
#include <sys/crc32.h>
static uint32_t const crc_table[256] = { CRC32_TABLE };
void
mit_crc32(in, in_length, cksum)
krb5_const krb5_pointer in;
krb5_const size_t in_length;
unsigned long *cksum;
{
unsigned int crc;
CRC32(crc, in, in_length, 0, crc_table);
*cksum = crc;
}
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* 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 "k5-int.h"
#include "etypes.h"
/*ARGSUSED*/
krb5_error_code KRB5_CALLCONV
krb5_c_decrypt(krb5_context context, const krb5_keyblock *key,
krb5_keyusage usage, const krb5_data *ivec,
const krb5_enc_data *input, krb5_data *output)
{
int i;
krb5_error_code ret = 0;
for (i=0; i<krb5_enctypes_length; i++) {
if (krb5_enctypes_list[i].etype == key->enctype)
break;
}
if (i == krb5_enctypes_length)
return(KRB5_BAD_ENCTYPE);
if ((input->enctype != ENCTYPE_UNKNOWN) &&
(krb5_enctypes_list[i].etype != input->enctype))
return(KRB5_BAD_ENCTYPE);
/* Solaris Kerberos */
#ifdef _KERNEL
context->kef_cipher_mt = krb5_enctypes_list[i].kef_cipher_mt;
context->kef_hash_mt = krb5_enctypes_list[i].kef_hash_mt;
if (key->kef_key.ck_data == NULL)
ret = init_key_kef(context->kef_cipher_mt, (krb5_keyblock *)key);
if (ret)
return(ret);
#else
if ((ret = init_key_uef(krb_ctx_hSession(context), (krb5_keyblock *)key)))
return (ret);
#endif /* _KERNEL */
/* Solaris Kerberos */
return((*(krb5_enctypes_list[i].decrypt))
(context, krb5_enctypes_list[i].enc, krb5_enctypes_list[i].hash,
key, usage, ivec, &input->ciphertext, output));
}
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright (C) 2001 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.
*
* Section 6 (Encryption) of the Kerberos revisions document defines
* cipher states to be used to chain encryptions and decryptions
* together. Examples of cipher states include initialization vectors
* for CBC encription. Most Kerberos encryption systems can share
* code for initializing and freeing cipher states. This file
* contains that default code.
*/
#include "k5-int.h"
/* ARGSUSED */
krb5_error_code krb5int_des_init_state
(krb5_context context, const krb5_keyblock *key,
krb5_keyusage usage, krb5_data *new_state )
{
new_state->length = 8;
new_state->data = (void *) MALLOC(8);
if (new_state->data) {
/* Solaris Kerberos */
(void) memset (new_state->data, 0, new_state->length);
/* We need to copy in the key for des-cbc-cr--ick, but that's how it works*/
if (key->enctype == ENCTYPE_DES_CBC_CRC) {
/* Solaris Kerberos */
(void) memcpy (new_state->data, key->contents, new_state->length);
}
} else {
return ENOMEM;
}
return 0;
}
/* ARGSUSED */
krb5_error_code krb5int_default_free_state
(krb5_context context, krb5_data *state)
{
if (state->data) {
FREE (state->data, state->length);
state-> data = NULL;
state->length = 0;
}
return 0;
}
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright 1995 by Richard P. Basch. All Rights Reserved.
* Copyright 1995 by Lehman Brothers, 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 Richard P. Basch, Lehman Brothers and M.I.T. not be used
* in advertising or publicity pertaining to distribution of the software
* without specific, written prior permission. Richard P. Basch,
* Lehman Brothers and M.I.T. make no representations about the suitability
* of this software for any purpose. It is provided "as is" without
* express or implied warranty.
*/
#include "des_int.h"
/*
* Triple-DES CBC encryption mode.
*/
#ifndef _KERNEL
int
mit_des3_cbc_encrypt(krb5_context context, const mit_des_cblock *in, mit_des_cblock *out,
unsigned long length, krb5_keyblock *key,
const mit_des_cblock ivec, int encrypt)
{
int ret = KRB5_PROG_ETYPE_NOSUPP;
KRB5_MECH_TO_PKCS algos;
CK_MECHANISM mechanism;
CK_RV rv;
/* For the Key Object */
ret = 0;
if ((rv = get_algo(key->enctype, &algos)) != CKR_OK) {
KRB5_LOG0(KRB5_ERR, "failure to get algo id in function "
"mit_des3_cbc_encrypt.");
ret = PKCS_ERR;
goto cleanup;
}
rv = init_key_uef(krb_ctx_hSession(context), key);
if (rv != CKR_OK) {
KRB5_LOG(KRB5_ERR, "init_key_uef failed in "
"mit_des3_cbc_encrypt: rv = 0x%0x", rv);
ret = PKCS_ERR;
goto cleanup;
}
mechanism.mechanism = algos.enc_algo;
mechanism.pParameter = (void*)ivec;
if (ivec != NULL)
mechanism.ulParameterLen = sizeof(mit_des_cblock);
else
mechanism.ulParameterLen = 0;
if (encrypt)
rv = C_EncryptInit(krb_ctx_hSession(context), &mechanism, key->hKey);
else
rv = C_DecryptInit(krb_ctx_hSession(context), &mechanism, key->hKey);
if (rv != CKR_OK) {
KRB5_LOG(KRB5_ERR, "C_EncryptInit/C_DecryptInit failed in "
"mit_des3_cbc_encrypt: rv = 0x%x", rv);
ret = PKCS_ERR;
goto cleanup;
}
if (encrypt)
rv = C_Encrypt(krb_ctx_hSession(context), (CK_BYTE_PTR)in,
(CK_ULONG)length, (CK_BYTE_PTR)out,
(CK_ULONG_PTR)&length);
else
rv = C_Decrypt(krb_ctx_hSession(context), (CK_BYTE_PTR)in,
(CK_ULONG)length, (CK_BYTE_PTR)out,
(CK_ULONG_PTR)&length);
if (rv != CKR_OK) {
KRB5_LOG(KRB5_ERR,
"C_Encrypt/C_Decrypt failed in mit_des3_cbc_encrypt: "
"rv = 0x%x", rv);
ret = PKCS_ERR;
}
cleanup:
if (ret)
(void) memset(out, 0, length);
KRB5_LOG(KRB5_INFO, "mit_des3_cbc_encrypt() end ret=%d\n", ret);
return(ret);
}
#else
#include <sys/crypto/api.h>
/* ARGSUSED */
int
mit_des3_cbc_encrypt(krb5_context context,
const mit_des_cblock *in,
mit_des_cblock *out,
unsigned long length, krb5_keyblock *key,
const mit_des_cblock ivec, int encrypt)
{
int ret = KRB5_PROG_ETYPE_NOSUPP;
krb5_data ivdata;
KRB5_LOG(KRB5_INFO, "mit_des3_cbc_encrypt() start encrypt=%d", encrypt);
ivdata.data = (char *)ivec;
ivdata.length = sizeof(mit_des_cblock);
ret = k5_ef_crypto((const char *)in, (char *)out,
length, key, &ivdata, encrypt);
KRB5_LOG(KRB5_INFO, "mit_des3_cbc_encrypt() end retval=%d", ret);
return(ret);
}
#endif /* !_KERNEL */
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <des_int.h>
#include <sys/crypto/api.h>
#include <sys/callb.h>
#include <sys/uio.h>
#include <sys/cmn_err.h>
int
k5_ef_crypto(const char *in, char *out,
long length, krb5_keyblock *key,
const krb5_data *ivec, int encrypt_flag)
{
int rv = CRYPTO_FAILED;
crypto_mechanism_t mech;
crypto_data_t d1, d2;
ASSERT(in != NULL);
ASSERT(out != NULL);
ASSERT(key != NULL);
ASSERT(key->contents != NULL);
bzero(&d1, sizeof (d1));
bzero(&d2, sizeof (d2));
d1.cd_format = CRYPTO_DATA_RAW;
d1.cd_offset = 0;
d1.cd_length = length;
d1.cd_raw.iov_base = (char *)in;
d1.cd_raw.iov_len = length;
d2.cd_format = CRYPTO_DATA_RAW;
d2.cd_offset = 0;
d2.cd_length = length;
d2.cd_raw.iov_base = (char *)out;
d2.cd_raw.iov_len = length;
mech.cm_type = key->kef_mt;
if (mech.cm_type == CRYPTO_MECH_INVALID) {
KRB5_LOG(KRB5_ERR,
"k5_ef_crypto - invalid crypto mech type: 0x%llx",
(long long)key->kef_mt);
return (CRYPTO_FAILED);
}
if (ivec != NULL) {
mech.cm_param_len = ivec->length;
mech.cm_param = (char *)ivec->data;
} else {
mech.cm_param_len = 0;
mech.cm_param = NULL;
}
if (encrypt_flag)
rv = crypto_encrypt(&mech, &d1,
&key->kef_key,
key->key_tmpl,
(in != out ? &d2 : NULL),
NULL);
else
rv = crypto_decrypt(&mech, &d1,
&key->kef_key,
key->key_tmpl,
(in != out ? &d2 : NULL),
NULL);
if (rv != CRYPTO_SUCCESS) {
KRB5_LOG1(KRB5_ERR,
"k5_ef_crypto: %s error: rv = 0x%08x",
(encrypt_flag ? "encrypt" : "decrypt"),
rv);
return (CRYPTO_FAILED);
}
return (0);
}
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright (c) 1990 Dennis Ferguson. All rights reserved.
*
* Commercial use is permitted only if products which are derived from
* or include this software are made available for purchase and/or use
* in Canada. Otherwise, redistribution and use in source and binary
* forms are permitted.
*/
/*
* des_cbc_encrypt.c - an implementation of the DES cipher function in cbc mode
*/
#include "des_int.h"
/*
* des_cbc_encrypt - {en,de}crypt a stream in CBC mode
*/
/* SUNW14resync - sparcv9 cc complained about lack of object init */
/* = all zero */
const mit_des_cblock mit_des_zeroblock = {0, 0, 0, 0, 0, 0, 0, 0};
#undef mit_des_cbc_encrypt
#ifndef _KERNEL
int
mit_des_cbc_encrypt(context, in, out, length, key, ivec, encrypt)
krb5_context context;
const mit_des_cblock *in;
mit_des_cblock *out;
long length;
krb5_keyblock *key;
mit_des_cblock ivec;
int encrypt;
{
krb5_error_code ret = KRB5_PROG_ETYPE_NOSUPP;
KRB5_MECH_TO_PKCS algos;
CK_MECHANISM mechanism;
CK_RV rv;
/* For the Key Object */
ret = 0;
if ((rv = get_algo(key->enctype, &algos)) != CKR_OK) {
KRB5_LOG0(KRB5_ERR, "failure to get algo id in function "
"mit_des_cbc_encrypt.");
ret = PKCS_ERR;
goto cleanup;
}
rv = init_key_uef(krb_ctx_hSession(context), key);
if (rv != CKR_OK) {
KRB5_LOG(KRB5_ERR, "init_key_uef failed in "
"mit_des_cbc_encrypt: rv = 0x%x", rv);
ret = PKCS_ERR;
goto cleanup;
}
mechanism.mechanism = algos.enc_algo;
mechanism.pParameter = ivec;
if (ivec != NULL)
mechanism.ulParameterLen = MIT_DES_BLOCK_LENGTH;
else
mechanism.ulParameterLen = 0;
if (encrypt)
rv = C_EncryptInit(krb_ctx_hSession(context), &mechanism, key->hKey);
else
rv = C_DecryptInit(krb_ctx_hSession(context), &mechanism, key->hKey);
if (rv != CKR_OK) {
KRB5_LOG(KRB5_ERR, "C_EncryptInit/C_DecryptInit failed in "
"mit_des_cbc_encrypt: rv = 0x%x", rv);
ret = PKCS_ERR;
goto cleanup;
}
if (encrypt)
rv = C_Encrypt(krb_ctx_hSession(context), (CK_BYTE_PTR)in,
(CK_ULONG)length, (CK_BYTE_PTR)out,
(CK_ULONG_PTR)&length);
else
rv = C_Decrypt(krb_ctx_hSession(context), (CK_BYTE_PTR)in,
(CK_ULONG)length, (CK_BYTE_PTR)out,
(CK_ULONG_PTR)&length);
if (rv != CKR_OK) {
KRB5_LOG(KRB5_ERR,
"C_Encrypt/C_Decrypt failed in mit_des_cbc_encrypt: "
"rv = 0x%x", rv);
ret = PKCS_ERR;
}
cleanup:
if (ret)
(void) memset(out, 0, length);
KRB5_LOG(KRB5_INFO, "mit_des_cbc_encrypt() end retval=%d", ret);
return(ret);
}
#else
/*
* This routine performs DES cipher-block-chaining operation, either
* encrypting from cleartext to ciphertext, if encrypt != 0 or
* decrypting from ciphertext to cleartext, if encrypt == 0.
*
* The key schedule is passed as an arg, as well as the cleartext or
* ciphertext. The cleartext and ciphertext should be in host order.
*
* NOTE-- the output is ALWAYS an multiple of 8 bytes long. If not
* enough space was provided, your program will get trashed.
*
* For encryption, the cleartext string is null padded, at the end, to
* an integral multiple of eight bytes.
*
* For decryption, the ciphertext will be used in integral multiples
* of 8 bytes, but only the first "length" bytes returned into the
* cleartext.
*/
/* ARGSUSED */
int
mit_des_cbc_encrypt(krb5_context context,
const mit_des_cblock *in,
mit_des_cblock *out,
long length, krb5_keyblock *key,
mit_des_cblock ivec, int encrypt)
{
int ret = KRB5_PROG_ETYPE_NOSUPP;
krb5_data ivdata;
ret = 0;
KRB5_LOG(KRB5_INFO, "mit_des_cbc_encrypt() start encrypt=%d", encrypt);
ivdata.data = (char *)ivec;
ivdata.length = sizeof(mit_des_cblock);
ret = k5_ef_crypto((const char *)in,
(char *)out, length, key, &ivdata, encrypt);
KRB5_LOG(KRB5_INFO, "mit_des_cbc_encrypt() end retval=%d", ret);
return(ret);
}
#endif /* !_KERNEL */
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* des_cbc_cksum.c - compute an 8 byte checksum using DES in CBC mode
*/
#include "des_int.h"
/*
* This routine performs DES cipher-block-chaining checksum operation,
* a.k.a. Message Authentication Code. It ALWAYS encrypts from input
* to a single 64 bit output MAC checksum.
*
* The key schedule is passed as an arg, as well as the cleartext or
* ciphertext. The cleartext and ciphertext should be in host order.
*
* NOTE-- the output is ALWAYS 8 bytes long. If not enough space was
* provided, your program will get trashed.
*
* The input is null padded, at the end (highest addr), to an integral
* multiple of eight bytes.
*/
unsigned long
mit_des_cbc_cksum(krb5_context context,
const krb5_octet *in, krb5_octet *out,
unsigned long length, krb5_keyblock *key,
const krb5_octet *ivec)
{
krb5_error_code ret = 0;
krb5_data input;
krb5_data output;
krb5_data ivecdata;
input.data = (char *)in;
input.length = length;
output.data = (char *)out;
output.length = MIT_DES_BLOCK_LENGTH;
ivecdata.data = (char *)ivec;
ivecdata.length = MIT_DES_BLOCK_LENGTH;
ret = k5_ef_mac(context, key, &ivecdata,
(const krb5_data *)&input, &output);
return (ret);
}
/*
* These routines check and fix parity of encryption keys for the DES
* algorithm.
*
* They are a replacement for routines in key_parity.c, that don't require
* the table building that they do.
*
* Mark Eichin -- Cygnus Support
*/
#include "des_int.h"
/*
* des_fixup_key_parity: Forces odd parity per byte; parity is bits
* 8,16,...64 in des order, implies 0, 8, 16, ...
* vax order.
*/
#define smask(step) ((1<<step)-1)
#define pstep(x,step) (((x)&smask(step))^(((x)>>step)&smask(step)))
#define parity_char(x) pstep(pstep(pstep((x),4),2),1)
void
mit_des_fixup_key_parity(mit_des_cblock key)
{
int i;
for (i=0; i<sizeof(mit_des_cblock); i++)
{
key[i] &= 0xfe;
key[i] |= 1^parity_char(key[i]);
}
return;
}
/*
* des_check_key_parity: returns true iff key has the correct des parity.
* See des_fix_key_parity for the definition of
* correct des parity.
*/
int
mit_des_check_key_parity(mit_des_cblock key)
{
int i;
for (i=0; i<sizeof(mit_des_cblock); i++)
{
if((key[i] & 1) == parity_char(0xfe&key[i]))
{
return 0;
}
}
return(1);
}
/*
* lib/crypto/des/weak_key.c
*
* Copyright 1989,1990 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.
*
*
* Under U.S. law, this software may not be exported outside the US
* without license from the U.S. Commerce department.
*
* These routines form the library interface to the DES facilities.
*
* Originally written 8/85 by Steve Miller, MIT Project Athena.
*/
#include "k5-int.h"
#include "des_int.h"
/*
* The following are the weak DES keys:
*/
static const mit_des_cblock weak[16] = {
/* weak keys */
{0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01},
{0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe},
{0x1f,0x1f,0x1f,0x1f,0x0e,0x0e,0x0e,0x0e},
{0xe0,0xe0,0xe0,0xe0,0xf1,0xf1,0xf1,0xf1},
/* semi-weak */
{0x01,0xfe,0x01,0xfe,0x01,0xfe,0x01,0xfe},
{0xfe,0x01,0xfe,0x01,0xfe,0x01,0xfe,0x01},
{0x1f,0xe0,0x1f,0xe0,0x0e,0xf1,0x0e,0xf1},
{0xe0,0x1f,0xe0,0x1f,0xf1,0x0e,0xf1,0x0e},
{0x01,0xe0,0x01,0xe0,0x01,0xf1,0x01,0xf1},
{0xe0,0x01,0xe0,0x01,0xf1,0x01,0xf1,0x01},
{0x1f,0xfe,0x1f,0xfe,0x0e,0xfe,0x0e,0xfe},
{0xfe,0x1f,0xfe,0x1f,0xfe,0x0e,0xfe,0x0e},
{0x01,0x1f,0x01,0x1f,0x01,0x0e,0x01,0x0e},
{0x1f,0x01,0x1f,0x01,0x0e,0x01,0x0e,0x01},
{0xe0,0xfe,0xe0,0xfe,0xf1,0xfe,0xf1,0xfe},
{0xfe,0xe0,0xfe,0xe0,0xfe,0xf1,0xfe,0xf1}
};
/*
* mit_des_is_weak_key: returns true iff key is a [semi-]weak des key.
*
* Requires: key has correct odd parity.
*/
int
mit_des_is_weak_key(mit_des_cblock key)
{
int i;
const mit_des_cblock *weak_p = weak;
for (i = 0; i < (sizeof(weak)/sizeof(mit_des_cblock)); i++) {
if (!memcmp(weak_p++,key,sizeof(mit_des_cblock)))
return 1;
}
return 0;
}
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* 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 "k5-int.h"
#include "etypes.h"
#include "dk.h"
#define K5CLENGTH 5 /* 32 bit net byte order integer + one byte seed */
/*
* Derive the key for checksum calculation.
* This is only called (currently) for SHA1-DES3
* checksum types.
*
* The primary benefit here is that a KEF template
* is created for use when doing the HMAC operation which
* saves ALOT of computation cycles and improves performance.
*/
static krb5_error_code
derive_cksum_key(krb5_context context,
struct krb5_enc_provider *enc,
const krb5_keyblock *key,
krb5_keyusage usage,
krb5_keyblock **outkey)
{
krb5_error_code ret = 0;
krb5_keyblock *cached_key = NULL;
krb5_data d1;
unsigned char constantdata[K5CLENGTH];
cached_key = find_derived_key(usage, DK_CKSUM_KEY_BYTE,
(krb5_keyblock *)key);
if (cached_key)
*outkey = cached_key;
else {
*outkey = krb5_create_derived_keyblock(key->length);
if (*outkey == NULL)
return (ENOMEM);
constantdata[0] = (usage>>24)&0xff;
constantdata[1] = (usage>>16)&0xff;
constantdata[2] = (usage>>8)&0xff;
constantdata[3] = usage&0xff;
constantdata[4] = DK_CKSUM_KEY_BYTE;
d1.data = (char *)constantdata;
d1.length = sizeof(constantdata);
ret = krb5_derive_key(context, enc, key,
*outkey, &d1);
if (ret) {
krb5_free_keyblock(context, *outkey);
*outkey = NULL;
return (ret);
}
#ifdef _KERNEL
/*
* By default, derived keys get the "mech_type"
* that was associated with their parent.
* we need to switch the mech_type to correspond
* to the checksum mech type.
*/
if (ret == 0 &&
(*outkey)->kef_mt != context->kef_cksum_mt) {
(*outkey)->kef_mt = context->kef_cksum_mt;
if ((*outkey)->key_tmpl != NULL) {
crypto_destroy_ctx_template((*outkey)->key_tmpl);
(*outkey)->key_tmpl = NULL;
}
ret = update_key_template(*outkey);
}
#endif /* _KERNEL */
if (ret == 0)
ret = add_derived_key((krb5_keyblock *)key, usage,
DK_CKSUM_KEY_BYTE,
*outkey);
}
KRB5_LOG0(KRB5_INFO, "derive_cksum_key() end.");
return (ret);
}
/* ARGSUSED */
krb5_error_code
krb5_dk_make_checksum(context, hash, key, usage, input, output)
krb5_context context;
krb5_const struct krb5_hash_provider *hash;
krb5_const krb5_keyblock *key;
krb5_keyusage usage;
krb5_const krb5_data *input;
krb5_data *output;
{
int i;
krb5_error_code ret;
krb5_keyblock *cksum_key = NULL;
struct krb5_enc_provider *enc = NULL;
KRB5_LOG0(KRB5_INFO, "krb5_dk_make_checksum() start");
for (i=0; i<krb5_enctypes_length; i++) {
if (krb5_enctypes_list[i].etype == key->enctype)
break;
}
if (i == krb5_enctypes_length) {
KRB5_LOG(KRB5_ERR, "krb5_ck_make_checksum bad enctype: %d",
key->enctype);
return(KRB5_BAD_ENCTYPE);
}
enc = (struct krb5_enc_provider *)krb5_enctypes_list[i].enc;
#ifdef _KERNEL
if (key->kef_key.ck_data == NULL &&
(ret = init_key_kef(krb5_enctypes_list[i].kef_cipher_mt,
(krb5_keyblock *)key)))
goto cleanup;
#endif
ret = derive_cksum_key(context, enc, key, usage, &cksum_key);
if (ret != 0)
goto cleanup;
#ifdef _KERNEL
if ((ret = krb5_hmac(context, (krb5_keyblock *)cksum_key,
input, output))) {
KRB5_LOG(KRB5_ERR, "krb5_hmac error: %0x", ret);
(void) memset(output->data, 0, output->length);
}
#else
if ((ret = krb5_hmac(context, hash, cksum_key, 1, input, output)) != 0) {
KRB5_LOG(KRB5_ERR, "krb5_hmac error: %0x", ret);
(void) memset(output->data, 0, output->length);
}
#endif /* _KERNEL */
cleanup:
KRB5_LOG0(KRB5_INFO, "krb5_dk_make_checksum() end");
return(ret);
}
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* 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 "k5-int.h"
#include "dk.h"
#define K5CLENGTH 5 /* 32 bit net byte order integer + one byte seed */
/*
* Search for a derived key based on the input key,
* the usage constant and the dkid byte.
*
* Return *derived key on success, NULL on failure.
*/
krb5_keyblock *
find_derived_key(krb5_keyusage usage, uchar_t dkid,
krb5_keyblock *key)
{
krb5_dk_node *dknode = key->dk_list;
while (dknode != NULL) {
if (usage == dknode->usage &&
dkid == dknode->dkid) {
KRB5_LOG1(KRB5_INFO,
"find_derived_key - MATCH FOUND %d 0x%0x",
usage, dkid);
return(dknode->derived_key);
}
dknode = dknode->next;
}
KRB5_LOG0(KRB5_INFO, "find_derived_key - no match");
return(NULL);
}
/*
* Add a derived key to the dk_list for the indicated key.
*/
krb5_error_code
add_derived_key(krb5_keyblock *key,
krb5_keyusage usage, uchar_t dkid,
krb5_keyblock *derived_key)
{
krb5_dk_node *dknode;
KRB5_LOG1(KRB5_INFO, "add_derived_key: %d 0x%0x",
usage, dkid);
if (key->dk_list == NULL) {
key->dk_list = MALLOC(sizeof(krb5_dk_node));
if (key->dk_list == NULL)
return (ENOMEM);
dknode = key->dk_list;
} else {
dknode = key->dk_list;
/*
* Find last derived key in list
*/
while (dknode->next != NULL)
dknode = dknode->next;
dknode->next = MALLOC(sizeof(krb5_dk_node));
if (dknode->next == NULL)
return (ENOMEM);
dknode = dknode->next;
}
dknode->usage = usage;
dknode->dkid = dkid;
dknode->derived_key = derived_key;
dknode->next = NULL;
return (0);
}
/*
* Utility function to create a new keyblock
* Return NULL on failure.
*/
krb5_keyblock *
krb5_create_derived_keyblock(int keysize)
{
krb5_keyblock *key = MALLOC(sizeof(krb5_keyblock));
KRB5_LOG0(KRB5_INFO, "krb5_create_derived_keyblock()");
if (key == NULL)
return (NULL);
bzero(key, sizeof(krb5_keyblock));
key->length = keysize;
key->contents = (uchar_t *)MALLOC(key->length);
if (key->contents == NULL) {
FREE(key, sizeof(krb5_keyblock));
return (NULL);
}
bzero(key->contents, key->length);
#ifdef _KERNEL
key->kef_mt = CRYPTO_MECH_INVALID;
key->key_tmpl = NULL;
#else
key->hKey = CK_INVALID_HANDLE;
#endif /* _KERNEL */
return(key);
}
/*
* initialize the derived key values in the context.
*/
krb5_error_code
init_derived_keydata(krb5_context context,
const struct krb5_enc_provider *enc,
krb5_keyblock *key,
krb5_keyusage usage,
krb5_keyblock **d_encr_key,
krb5_keyblock **d_hmac_key)
{
krb5_error_code rv = 0;
unsigned char constantdata[K5CLENGTH];
krb5_keyblock *cached_key;
krb5_data d1;
KRB5_LOG0(KRB5_INFO,"init_ef_derived_keydata().");
/*
* Get a derived encryption key, either from the cache
* or by calculation.
*/
cached_key = find_derived_key(usage, DK_ENCR_KEY_BYTE, key);
if (cached_key != NULL)
*d_encr_key = cached_key;
else {
*d_encr_key = krb5_create_derived_keyblock(key->length);
if (*d_encr_key == NULL) {
return (ENOMEM);
}
(*d_encr_key)->enctype = key->enctype;
constantdata[0] = (usage>>24)&0xff;
constantdata[1] = (usage>>16)&0xff;
constantdata[2] = (usage>>8)&0xff;
constantdata[3] = usage&0xff;
constantdata[4] = DK_ENCR_KEY_BYTE;
d1.data = (char *)constantdata;
d1.length = sizeof(constantdata);
rv = krb5_derive_key(context, enc, key,
*d_encr_key, &d1);
if (rv != 0) {
krb5_free_keyblock(context, *d_encr_key);
*d_encr_key = NULL;
return (rv);
}
rv = add_derived_key(key, usage, DK_ENCR_KEY_BYTE,
*d_encr_key);
if (rv != 0) {
krb5_free_keyblock(context, *d_encr_key);
*d_encr_key = NULL;
return (rv);
}
}
/*
* Get a derived HMAC key, either from the cache
* or by calculation.
*/
cached_key = find_derived_key(usage, DK_HASH_KEY_BYTE, key);
if (cached_key != NULL)
*d_hmac_key = cached_key;
else {
*d_hmac_key = krb5_create_derived_keyblock(key->length);
if (*d_hmac_key == NULL) {
return (ENOMEM);
}
(*d_hmac_key)->enctype = key->enctype;
constantdata[0] = (usage>>24)&0xff;
constantdata[1] = (usage>>16)&0xff;
constantdata[2] = (usage>>8)&0xff;
constantdata[3] = usage&0xff;
constantdata[4] = DK_HASH_KEY_BYTE;
d1.data = (char *)constantdata;
d1.length = sizeof(constantdata);
rv = krb5_derive_key(context, enc, key, *d_hmac_key, &d1);
if (rv != 0) {
krb5_free_keyblock(context, *d_hmac_key);
*d_hmac_key = NULL;
return (rv);
}
#ifdef _KERNEL
/*
* By default, derived keys get the "mech_type"
* that was associated with their parent.
* we need to switch the mech type of the derived HMAC key
* to correspond to the mech type for the hmac key.
*/
if ((*d_hmac_key)->kef_mt != context->kef_hash_mt) {
(*d_hmac_key)->kef_mt = context->kef_hash_mt;
if ((*d_hmac_key)->key_tmpl != NULL) {
crypto_destroy_ctx_template((*d_hmac_key)->key_tmpl);
(*d_hmac_key)->key_tmpl = NULL;
}
rv = update_key_template(*d_hmac_key);
if (rv != 0) {
krb5_free_keyblock(context, *d_hmac_key);
*d_hmac_key = NULL;
return (rv);
}
}
#endif /* _KERNEL */
if (rv == 0) {
rv = add_derived_key(key, usage, DK_HASH_KEY_BYTE,
*d_hmac_key);
if (rv != 0) {
krb5_free_keyblock(context, *d_hmac_key);
*d_hmac_key = NULL;
return (rv);
}
}
}
KRB5_LOG0(KRB5_INFO,"init_ef_derived_keydata() end.");
return (rv);
}
krb5_error_code
krb5_derive_key(context, enc, inkey, outkey, in_constant)
krb5_context context;
krb5_const struct krb5_enc_provider *enc;
krb5_const krb5_keyblock *inkey;
krb5_keyblock *outkey;
krb5_const krb5_data *in_constant;
{
size_t blocksize, keybytes, keylength, n;
unsigned char *inblockdata, *outblockdata, *rawkey;
krb5_data inblock, outblock;
krb5_error_code ret = 0;
KRB5_LOG0(KRB5_INFO, "krb5_derive_key() start");
blocksize = enc->block_size;
keybytes = enc->keybytes;
keylength = enc->keylength;
if ((inkey->length != keylength) ||
(outkey->length != keylength))
return(KRB5_CRYPTO_INTERNAL);
/* allocate and set up buffers */
if ((inblockdata = (unsigned char *) MALLOC(blocksize)) == NULL)
return(ENOMEM);
if ((outblockdata = (unsigned char *) MALLOC(blocksize)) == NULL) {
FREE(inblockdata, blocksize);
return(ENOMEM);
}
if ((rawkey = (unsigned char *) MALLOC(keybytes)) == NULL) {
FREE(outblockdata, blocksize);
FREE(inblockdata, blocksize);
return(ENOMEM);
}
inblock.data = (char *) inblockdata;
inblock.length = blocksize;
outblock.data = (char *) outblockdata;
outblock.length = blocksize;
/* initialize the input block */
if (in_constant->length == inblock.length) {
(void) memcpy(inblock.data, in_constant->data, inblock.length);
} else {
krb5_nfold(in_constant->length*8,
(krb5_const unsigned char *) in_constant->data,
inblock.length*8, (unsigned char *) inblock.data);
}
/* loop encrypting the blocks until enough key bytes are generated */
n = 0;
while (n < keybytes) {
ret = (*(enc->encrypt))(context, inkey, 0, &inblock, &outblock);
if (ret) {
KRB5_LOG(KRB5_INFO, "krb5_derive_key() encrypt error: %d", ret);
goto cleanup;
}
if ((keybytes - n) <= outblock.length) {
(void) memcpy(rawkey+n, outblock.data, (keybytes - n));
break;
}
(void) memcpy(rawkey+n, outblock.data, outblock.length);
(void) memcpy(inblock.data, outblock.data, outblock.length);
n += outblock.length;
}
/* postprocess the key */
inblock.data = (char *) rawkey;
inblock.length = keybytes;
outkey->enctype = inkey->enctype;
ret = (*(enc->make_key))(context, &inblock, outkey);
/* clean memory, free resources and exit */
cleanup:
(void) memset(inblockdata, 0, blocksize);
(void) memset(outblockdata, 0, blocksize);
(void) memset(rawkey, 0, keybytes);
FREE(rawkey, keybytes);
FREE(outblockdata, blocksize);
FREE(inblockdata, blocksize);
KRB5_LOG0(KRB5_INFO, "krb5_derive_key() end");
return(ret);
}
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* 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 "k5-int.h"
#include "dk.h"
#define K5CLENGTH 5 /* 32 bit net byte order integer + one byte seed */
static krb5_error_code
krb5_dk_decrypt_maybe_trunc_hmac(krb5_context context,
const struct krb5_enc_provider *enc,
const struct krb5_hash_provider *hash,
const krb5_keyblock *key,
krb5_keyusage usage,
const krb5_data *ivec,
const krb5_data *input,
krb5_data *output,
size_t hmacsize);
krb5_error_code
krb5_dk_decrypt(
krb5_context context,
const struct krb5_enc_provider *enc,
const struct krb5_hash_provider *hash,
const krb5_keyblock *key, krb5_keyusage usage,
const krb5_data *ivec, const krb5_data *input,
krb5_data *output)
{
return krb5_dk_decrypt_maybe_trunc_hmac(context, enc, hash, key, usage,
ivec, input, output, 0);
}
krb5_error_code
krb5int_aes_dk_decrypt(
krb5_context context,
const struct krb5_enc_provider *enc,
const struct krb5_hash_provider *hash,
const krb5_keyblock *key, krb5_keyusage usage,
const krb5_data *ivec, const krb5_data *input,
krb5_data *output)
{
return krb5_dk_decrypt_maybe_trunc_hmac(context, enc, hash, key, usage,
ivec, input, output, 96 / 8);
}
static krb5_error_code
krb5_dk_decrypt_maybe_trunc_hmac(
krb5_context context,
const struct krb5_enc_provider *enc,
const struct krb5_hash_provider *hash,
const krb5_keyblock *key, krb5_keyusage usage,
const krb5_data *ivec, const krb5_data *input,
krb5_data *output, size_t hmacsize)
{
krb5_error_code ret;
size_t hashsize, blocksize, enclen, plainlen;
unsigned char *plaindata = NULL, *cksum = NULL, *cn;
krb5_data d1, d2;
krb5_keyblock *derived_encr_key = NULL;
krb5_keyblock *derived_hmac_key = NULL;
KRB5_LOG0(KRB5_INFO, "krb5_dk_decrypt() start\n");
/*
* Derive the encryption and hmac keys.
* This routine is optimized to fetch the DK
* from the original key's DK list.
*/
ret = init_derived_keydata(context, enc,
(krb5_keyblock *)key,
usage,
&derived_encr_key,
&derived_hmac_key);
if (ret)
return (ret);
hashsize = hash->hashsize;
blocksize = enc->block_size;
if (hmacsize == 0)
hmacsize = hashsize;
else if (hmacsize > hashsize)
return (KRB5KRB_AP_ERR_BAD_INTEGRITY);
/* Verify input and output lengths. */
if (input->length < blocksize + hmacsize)
return KRB5_BAD_MSIZE;
if (output->length < input->length - blocksize - hmacsize)
return KRB5_BAD_MSIZE;
enclen = input->length - hmacsize;
if ((plaindata = (unsigned char *) MALLOC(enclen)) == NULL) {
ret = ENOMEM;
goto cleanup;
}
/* decrypt the ciphertext */
d1.length = enclen;
d1.data = input->data;
d2.length = enclen;
d2.data = (char *) plaindata;
if ((ret = ((*(enc->decrypt))(context, derived_encr_key,
ivec, &d1, &d2))) != 0)
goto cleanup;
if (ivec != NULL && ivec->length == blocksize) {
cn = (unsigned char *) d1.data + d1.length - blocksize;
} else {
cn = NULL;
}
/* verify the hash */
if ((cksum = (unsigned char *) MALLOC(hashsize)) == NULL) {
ret = ENOMEM;
goto cleanup;
}
d1.length = hashsize;
d1.data = (char *) cksum;
#ifdef _KERNEL
if ((ret = krb5_hmac(context, derived_hmac_key, &d2, &d1)) != 0)
goto cleanup;
#else
if ((ret = krb5_hmac(context, hash, derived_hmac_key,
1, &d2, &d1)) != 0)
goto cleanup;
#endif /* _KERNEL */
if (memcmp(cksum, input->data+enclen, hmacsize) != 0) {
ret = KRB5KRB_AP_ERR_BAD_INTEGRITY;
goto cleanup;
}
/* because this encoding isn't self-describing wrt length, the
best we can do here is to compute the length minus the
confounder. */
plainlen = enclen - blocksize;
if (output->length < plainlen) {
ret = KRB5_BAD_MSIZE;
goto cleanup;
}
output->length = plainlen;
(void) memcpy(output->data, d2.data+blocksize, output->length);
/*
* AES crypto updates the ivec differently, it is handled
* in the AES crypto routines directly.
*/
if (cn != NULL &&
key->enctype != ENCTYPE_AES128_CTS_HMAC_SHA1_96 &&
key->enctype != ENCTYPE_AES256_CTS_HMAC_SHA1_96) {
(void) memcpy(ivec->data, cn, blocksize);
}
ret = 0;
cleanup:
if (plaindata) {
(void) memset(plaindata, 0, enclen);
FREE(plaindata, enclen);
}
if (cksum) {
(void) memset(cksum, 0, hashsize);
FREE(cksum, hashsize);
}
KRB5_LOG(KRB5_INFO, "krb5_dk_decrypt() end, ret=%d\n", ret);
return(ret);
}
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* 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 "k5-int.h"
#include "dk.h"
#define K5CLENGTH 5 /* 32 bit net byte order integer + one byte seed */
/* the spec says that the confounder size and padding are specific to
the encryption algorithm. This code (dk_encrypt_length and
dk_encrypt) assume the confounder is always the blocksize, and the
padding is always zero bytes up to the blocksize. If these
assumptions ever fails, the keytype table should be extended to
include these bits of info. */
void
krb5_dk_encrypt_length(const struct krb5_enc_provider *enc,
const struct krb5_hash_provider *hash,
size_t inputlen, size_t *length)
{
size_t blocksize, hashsize;
blocksize = enc->block_size;
hashsize = hash->hashsize;
*length = krb5_roundup(blocksize+inputlen, blocksize) + hashsize;
}
krb5_error_code
krb5_dk_encrypt(krb5_context context,
const struct krb5_enc_provider *enc,
const struct krb5_hash_provider *hash,
const krb5_keyblock *key, krb5_keyusage usage,
const krb5_data *ivec, const krb5_data *input,
krb5_data *output)
{
size_t blocksize, plainlen, enclen;
krb5_error_code ret;
krb5_data d1, d2;
unsigned char *plaintext = NULL, *cn;
krb5_keyblock *derived_encr_key = NULL;
krb5_keyblock *derived_hmac_key = NULL;
KRB5_LOG0(KRB5_INFO, "krb5_dk_encrypt() start");
/*
* Derive the encryption and hmac keys.
* This routine is optimized to fetch the DK
* from the original key's DK list.
*/
ret = init_derived_keydata(context, enc,
(krb5_keyblock *)key,
usage,
&derived_encr_key,
&derived_hmac_key);
if (ret)
return (ret);
blocksize = enc->block_size;
plainlen = krb5_roundup(blocksize+input->length, blocksize);
krb5_dk_encrypt_length(enc, hash, input->length, &enclen);
if (output->length < enclen)
return(KRB5_BAD_MSIZE);
if ((plaintext = (unsigned char *) MALLOC(plainlen)) == NULL) {
return(ENOMEM);
}
/* put together the plaintext */
d1.length = blocksize;
d1.data = (char *) plaintext;
if ((ret = krb5_c_random_make_octets(context, &d1)))
goto cleanup;
(void) memcpy(plaintext+blocksize, input->data, input->length);
(void) memset(plaintext+blocksize+input->length, 0,
plainlen - (blocksize+input->length));
/* encrypt the plaintext */
d1.length = plainlen;
d1.data = (char *) plaintext;
d2.length = plainlen;
d2.data = output->data;
/*
* Always use the derived encryption key here.
*/
if ((ret = ((*(enc->encrypt))(context, derived_encr_key,
ivec, &d1, &d2))))
goto cleanup;
if (ivec != NULL && ivec->length == blocksize)
cn = (unsigned char *) d2.data + d2.length - blocksize;
else
cn = NULL;
/* hash the plaintext */
d2.length = enclen - plainlen;
d2.data = output->data+plainlen;
output->length = enclen;
#ifdef _KERNEL
if ((ret = krb5_hmac(context, derived_hmac_key, &d1, &d2))) {
(void) memset(d2.data, 0, d2.length);
goto cleanup;
}
#else
if ((ret = krb5_hmac(context, hash, derived_hmac_key,
1, &d1, &d2))) {
(void) memset(d2.data, 0, d2.length);
goto cleanup;
}
#endif /* _KERNEL */
/* update ivec */
if (cn != NULL)
(void) memcpy(ivec->data, cn, blocksize);
/* ret is set correctly by the prior call */
cleanup:
FREE(plaintext, plainlen);
KRB5_LOG(KRB5_INFO, "krb5_dk_encrypt() end, ret=%d\n", ret);
return(ret);
}
/* Not necessarily "AES", per se, but "a CBC+CTS mode block cipher
with a 96-bit truncated HMAC". */
/*ARGSUSED*/
void
krb5int_aes_encrypt_length(enc, hash, inputlen, length)
const struct krb5_enc_provider *enc;
const struct krb5_hash_provider *hash;
size_t inputlen;
size_t *length;
{
size_t blocksize, hashsize;
blocksize = enc->block_size;
hashsize = 96 / 8;
/* No roundup, since CTS requires no padding once we've hit the
block size. */
*length = blocksize+inputlen + hashsize;
}
/*ARGSUSED*/
static krb5_error_code
trunc_hmac (krb5_context context,
const struct krb5_hash_provider *hash,
const krb5_keyblock *ki, int num,
const krb5_data *input, krb5_data *output)
{
size_t hashsize;
krb5_error_code ret;
char buff[256]; /* sufficiently large enough to hold current hmacs */
krb5_data tmphash;
hashsize = hash->hashsize;
if (hashsize < output->length)
return (KRB5_CRYPTO_INTERNAL);
tmphash.length = hashsize;
tmphash.data = buff;
#ifdef _KERNEL
ret = krb5_hmac(context, ki, input, &tmphash);
#else
ret = krb5_hmac(context, hash, ki, num, input, &tmphash);
#endif /* _KERNEL */
if (ret)
(void) memset(output->data, 0, output->length);
else
/* truncate the HMAC output accordingly */
(void) memcpy(output->data, tmphash.data, output->length);
(void) memset(buff, 0, sizeof(buff));
return (ret);
}
krb5_error_code
krb5int_aes_dk_encrypt(krb5_context context,
const struct krb5_enc_provider *enc,
const struct krb5_hash_provider *hash,
const krb5_keyblock *key,
krb5_keyusage usage,
const krb5_data *ivec,
const krb5_data *input,
krb5_data *output)
{
size_t blocksize, plainlen, enclen;
krb5_error_code ret;
krb5_data d1, d2;
unsigned char *plaintext, *cn;
krb5_keyblock *derived_encr_key = NULL;
krb5_keyblock *derived_hmac_key = NULL;
/*
* Derive the encryption and hmac keys.
* This routine is optimized to fetch the DK
* from the original key's DK list.
*/
ret = init_derived_keydata(context, enc,
(krb5_keyblock *)key,
usage,
&derived_encr_key,
&derived_hmac_key);
if (ret)
return (ret);
blocksize = enc->block_size;
plainlen = blocksize+input->length;
krb5int_aes_encrypt_length(enc, hash, input->length, &enclen);
/* key->length, ivec will be tested in enc->encrypt */
if (output->length < enclen)
return(KRB5_BAD_MSIZE);
if ((plaintext = (unsigned char *) MALLOC(plainlen)) == NULL) {
return(ENOMEM);
}
d1.length = blocksize;
d1.data = (char *)plaintext;
if ((ret = krb5_c_random_make_octets(context, &d1)))
goto cleanup;
(void) memcpy(plaintext+blocksize, input->data, input->length);
/* Ciphertext stealing; there should be no more. */
if (plainlen != blocksize + input->length) {
ret = KRB5_BAD_KEYSIZE;
goto cleanup;
}
/* encrypt the plaintext */
d1.length = plainlen;
d1.data = (char *)plaintext;
d2.length = plainlen;
d2.data = output->data;
if ((ret = ((*(enc->encrypt))(context, derived_encr_key, ivec, &d1, &d2))))
goto cleanup;
if (ivec != NULL && ivec->length == blocksize) {
int nblocks = (d2.length + blocksize - 1) / blocksize;
cn = (uchar_t *) d2.data + blocksize * (nblocks - 2);
} else {
cn = NULL;
}
/* hash the plaintext */
d2.length = enclen - plainlen;
d2.data = output->data+plainlen;
if (d2.length != 96 / 8)
goto cleanup;
if ((ret = trunc_hmac(context, hash, derived_hmac_key, 1, &d1, &d2))) {
(void) memset(d2.data, 0, d2.length);
goto cleanup;
}
output->length = enclen;
/* update ivec */
if (cn != NULL) {
(void) memcpy(ivec->data, cn, blocksize);
}
/* ret is set correctly by the prior call */
cleanup:
(void) memset(plaintext, 0, plainlen);
FREE(plaintext, plainlen);
return(ret);
}
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
* Note, this file is cstyle and lint clean and should stay that way.
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*/
#include <k5-int.h>
#include <enc_provider.h>
#define BLOCK_SIZE 16
/*
* AES encrypt using CipherText Stealing mode built on top of CBC mode. CBC is
* being used because the Solaris Cryptographic Framework/PKCS11 does not
* currently support CTS while CBC is supported. CBC as compared to ECB that
* was previously used allows crypto providers to do the crypto more
* efficiently. In addition there is a crypto card (SCA6000) that did not
* provide ECB mode so krb was unable to take advantage. If CTS mode is ever
* supported by the Solaris Cryptographic Framework then this code should be
* changed to use that.
*
* CTS is based on what is described in Schneier's Applied Cryptography and RFC
* 3962.
*/
#ifdef _KERNEL
/*ARGSUSED*/
krb5_error_code
krb5int_aes_encrypt(krb5_context context,
const krb5_keyblock *key, const krb5_data *ivec,
const krb5_data *input, krb5_data *output)
{
int ret = 0;
int nblocks, partialamount;
crypto_mechanism_t mech;
/*
* nlobp = next to last output block pointer, lobp = last output block
* pointer
*/
char *nlobp, *lobp;
char local_iv_data[BLOCK_SIZE];
krb5_data local_iv;
KRB5_LOG0(KRB5_INFO, "In krb5int_aes_encrypt(kernel): start");
ASSERT(input != NULL);
if (input->length < BLOCK_SIZE)
return (KRB5_BAD_MSIZE);
ASSERT(output != NULL);
ASSERT(input->length == output->length);
ASSERT(key != NULL);
ASSERT(key->key_tmpl != NULL);
ASSERT(key->kef_mt == crypto_mech2id(SUN_CKM_AES_CBC));
if (ivec != NULL) {
/*
* This function updates ivec->data if the ivec is passed in so
* it better have a data pointer and a proper length.
*/
if (ivec->data == NULL || ivec->length != BLOCK_SIZE) {
ASSERT(ivec->data != NULL);
ASSERT(ivec->length == BLOCK_SIZE);
KRB5_LOG1(KRB5_ERR, "In krb5int_aes_encrypt: error "
"ivec->data = %p ivec->length = %d",
(void *)ivec->data, ivec->length);
ret = KRB5_CRYPTO_INTERNAL;
goto cleanup;
}
}
/* number of input blocks including partial block */
nblocks = (input->length + BLOCK_SIZE - 1) / BLOCK_SIZE;
KRB5_LOG(KRB5_INFO, "nblocks = %d", nblocks);
/* get # of bytes in partially filled block */
partialamount = input->length % BLOCK_SIZE;
KRB5_LOG(KRB5_INFO, "partialamount = %d", partialamount);
if (nblocks == 1 || (partialamount == 0)) {
/*
* Simple case:
*
* Use CBC for all plaintext blocks, all must be full, then swap
* last 2 ciphertext blocks to implement CTS. Note, CBC needs a
* non-NULL IV.
*/
if (ivec != NULL) {
local_iv.data = ivec->data;
local_iv.length = ivec->length;
} else {
bzero(local_iv_data, sizeof (local_iv_data));
local_iv.data = local_iv_data;
local_iv.length = sizeof (local_iv_data);
}
/* Note using TRUE here because encryption is desired */
ret = k5_ef_crypto((const char *)input->data,
(char *)output->data,
input->length, (krb5_keyblock *)key,
&local_iv, TRUE);
if (ret != 0) {
KRB5_LOG(KRB5_ERR,
"k5_ef_crypto: error: ret = 0x%08x", ret);
goto cleanup;
}
if (nblocks > 1) {
/*
* swap last 2 ciphertext blocks to implement CTS
*/
char tmp[BLOCK_SIZE];
nlobp = (char *)(output->data +
((nblocks - 2) * BLOCK_SIZE));
lobp = (char *)(output->data +
((nblocks - 1) * BLOCK_SIZE));
bcopy(nlobp, tmp, BLOCK_SIZE);
bcopy(lobp, nlobp, BLOCK_SIZE);
bcopy(tmp, lobp, BLOCK_SIZE);
}
} else {
/*
* Complex case:
*
* This implements CTS mode where there is > 1 block and the
* last block is partially filled Uses CBC mode in the kCF, then
* does some swapping.
*
* pt = plain text, ct = cipher text
*/
char tmp_pt[BLOCK_SIZE], tmp_ct[BLOCK_SIZE];
/* Note the iovec below is NOT the ivec in the crypto sense */
struct iovec iovarray_pt[2], iovarray_ct[2];
struct uio uio_pt, uio_ct;
/* ct = ciphertext, pt = plaintext */
crypto_data_t ct, pt;
/* tmp_pt will provide 0 padding for last parital pt block */
bzero(tmp_pt, sizeof (tmp_pt));
/*
* Setup the uio/iovecs so only one call to crypto_encrypt() is
* made. Plaintext first.
*/
pt.cd_format = CRYPTO_DATA_UIO;
pt.cd_offset = 0;
pt.cd_length = nblocks * BLOCK_SIZE;
pt.cd_miscdata = NULL;
bzero(&uio_pt, sizeof (uio_pt));
pt.cd_uio = &uio_pt;
pt.cd_uio->uio_iov = iovarray_pt;
pt.cd_uio->uio_iovcnt = 2;
pt.cd_uio->uio_segflg = UIO_SYSSPACE;
/*
* first iovec has all full blocks of pt.
*/
pt.cd_uio->uio_iov[0].iov_base = (char *)input->data;
/* use full block input */
pt.cd_uio->uio_iov[0].iov_len = input->length - partialamount;
KRB5_LOG(KRB5_INFO, "pt0 iov_len = %d",
(int)pt.cd_uio->uio_iov[0].iov_len);
/*
* second iovec has the parital pt and 0 padding
*/
pt.cd_uio->uio_iov[1].iov_base = tmp_pt;
/*
* since the first iovec includes the last partial pt,
* set length to enough bytes to pad out to a full block
*/
bcopy(input->data + (input->length - partialamount), tmp_pt,
partialamount);
pt.cd_uio->uio_iov[1].iov_len = BLOCK_SIZE;
/* setup ciphertext iovecs */
ct.cd_format = CRYPTO_DATA_UIO;
ct.cd_offset = 0;
ct.cd_length = nblocks * BLOCK_SIZE;
ct.cd_miscdata = NULL;
bzero(&uio_ct, sizeof (uio_ct));
ct.cd_uio = &uio_ct;
ct.cd_uio->uio_iov = iovarray_ct;
ct.cd_uio->uio_iovcnt = 2;
ct.cd_uio->uio_segflg = UIO_SYSSPACE;
/*
* First iovec has almost all the ct but not the ct for the last
* partial pt with the padding. That will be stored in the
* secont ct iovec.
*/
ct.cd_uio->uio_iov[0].iov_base = (char *)output->data;
ct.cd_uio->uio_iov[0].iov_len = output->length - partialamount;
KRB5_LOG(KRB5_INFO, "ct0 iov_len = %d",
(int)ct.cd_uio->uio_iov[0].iov_len);
/*
* Second iovec has the last ciphertext block
*/
ct.cd_uio->uio_iov[1].iov_base = tmp_ct;
ct.cd_uio->uio_iov[1].iov_len = BLOCK_SIZE;
/* This had better be AES CBC mode! */
mech.cm_type = key->kef_mt;
if (ivec == NULL) {
bzero(local_iv_data, sizeof (local_iv_data));
mech.cm_param = local_iv_data;
mech.cm_param_len = sizeof (local_iv_data);
} else {
mech.cm_param = ivec->data;
mech.cm_param_len = ivec->length;
}
/* encrypt using AES CBC */
ret = crypto_encrypt(&mech, &pt, (crypto_key_t *)&key->kef_key,
key->key_tmpl, &ct, NULL);
if (ret != CRYPTO_SUCCESS) {
KRB5_LOG(KRB5_ERR,
"crypto_encrypt: error: ret = 0x%08x",
ret);
goto cleanup;
}
/*
* Swap:
* copy the next to last ct to last partial output block (only
* the partial amount is copied).
*/
nlobp = (char *)(output->data + ((nblocks - 2) * BLOCK_SIZE));
lobp = (char *)(output->data + ((nblocks - 1) * BLOCK_SIZE));
bcopy(nlobp, lobp, partialamount);
/*
* copy the last ct output block to next to last output block
*/
bcopy(tmp_ct, nlobp, BLOCK_SIZE);
} /* end partial block processing */
/*
* The ivec is updated to allow the caller to chain ivecs. At this
* point I don't think any kernel callers are using this however the
* userland version of this function does it so this should be done in
* kernel for consistency's sake. This is not done for 1 block, got
* this from MIT. Note, the next to last output block is copied because
* it contains the last full block of cipher text.
*/
if (nblocks > 1 && ivec)
(void) memcpy(ivec->data, nlobp, BLOCK_SIZE);
cleanup:
if (ret)
bzero(output->data, output->length);
return (ret);
}
#else /* User Space */
/*ARGSUSED*/
krb5_error_code
krb5int_aes_encrypt(krb5_context context,
const krb5_keyblock *key, const krb5_data *ivec,
const krb5_data *input, krb5_data *output)
{
krb5_error_code ret = 0;
int nblocks, partialamount;
CK_RV rv;
KRB5_MECH_TO_PKCS algos;
CK_MECHANISM mechanism;
CK_ULONG outlen;
/*
* nlobp = next to last output block pointer, lobp = last output block
* pointer
*/
char *nlobp, *lobp;
char tmp_ivec[BLOCK_SIZE];
assert(input != NULL);
if (input->length < BLOCK_SIZE)
return (KRB5_BAD_MSIZE);
assert(output != NULL);
assert(input->length == output->length);
assert(key != NULL);
if (ivec != NULL) {
/*
* This function updates ivec->data if the ivec is passed in so
* it better have a data pointer and a proper length.
*/
if (ivec->data == NULL || ivec->length != BLOCK_SIZE) {
assert(ivec->data != NULL);
assert(ivec->length == BLOCK_SIZE);
KRB5_LOG1(KRB5_ERR, "In krb5int_aes_encrypt: error "
"ivec->data = %p ivec->length = %d", ivec->data,
ivec->length);
ret = KRB5_CRYPTO_INTERNAL;
goto cleanup;
}
}
/* number of input blocks including partial block */
nblocks = (input->length + BLOCK_SIZE - 1) / BLOCK_SIZE;
KRB5_LOG(KRB5_INFO, "nblocks = %d", nblocks);
/* get # of bytes in partially filled block */
partialamount = input->length % BLOCK_SIZE;
KRB5_LOG(KRB5_INFO, "partialamount = %d", partialamount);
rv = get_algo(key->enctype, &algos);
if (rv != CKR_OK)
goto cleanup;
assert(algos.enc_algo == CKM_AES_CBC);
rv = init_key_uef(krb_ctx_hSession(context), (krb5_keyblock *)key);
if (rv != CKR_OK)
goto cleanup;
mechanism.mechanism = algos.enc_algo;
if (ivec == NULL) {
bzero(tmp_ivec, sizeof (tmp_ivec));
mechanism.pParameter = tmp_ivec;
mechanism.ulParameterLen = sizeof (tmp_ivec);
} else {
mechanism.pParameter = ivec->data;
mechanism.ulParameterLen = ivec->length;
}
/*
* Note, since CBC is assumed to be the underlying mode, this
* call to C_EncryptInit is setting the IV. The IV in use here
* is either the ivec passed in or a block of 0's.
*/
rv = C_EncryptInit(krb_ctx_hSession(context), &mechanism, key->hKey);
if (rv != CKR_OK) {
KRB5_LOG(KRB5_ERR, "C_EncryptInit failed in "
"krb5int_aes_encrypt: rv = 0x%x", rv);
goto cleanup;
}
if (nblocks == 1 || (partialamount == 0)) {
/*
* Simple case:
*
* Use CBC for all plaintext blocks, all must be full, then swap
* last 2 ciphertext blocks to implement CTS.
*/
/*
* C_Encrypt/Decrypt requires a pointer to long, not a pointer
* to int cast to pointer to long!!!
*/
outlen = output->length;
rv = C_Encrypt(krb_ctx_hSession(context),
(CK_BYTE_PTR)input->data,
input->length,
(CK_BYTE_PTR)output->data,
&outlen);
if (rv != CKR_OK) {
KRB5_LOG(KRB5_ERR, "C_Encrypt failed in "
"krb5int_aes_encrypt: rv = 0x%x", rv);
goto cleanup;
}
assert(output->length == (unsigned int)outlen);
if (nblocks > 1) {
/*
* swap last 2 ciphertext blocks to implement CTS
*/
char tmp[BLOCK_SIZE];
nlobp = (char *)(output->data +
((nblocks - 2) * BLOCK_SIZE));
lobp = (char *)(output->data +
((nblocks - 1) * BLOCK_SIZE));
bcopy(nlobp, tmp, BLOCK_SIZE);
bcopy(lobp, nlobp, BLOCK_SIZE);
bcopy(tmp, lobp, BLOCK_SIZE);
}
} else {
/*
* Complex case:
*
* This implements CTS mode where there is > 1 block and the
* last block is partially filled. Uses CBC mode in uCF/PKCS11,
* then does some swapping.
*
* pt = plain text, ct = cipher text
*/
char tmp_pt[BLOCK_SIZE], tmp_ct[BLOCK_SIZE];
/*
* encrypt from P0...Pn-1 using CBC, last block of output is Cn
* & C'
*/
outlen = input->length - partialamount;
rv = C_EncryptUpdate(krb_ctx_hSession(context),
(CK_BYTE_PTR)input->data,
input->length - partialamount,
(CK_BYTE_PTR)output->data,
&outlen);
if (rv != CKR_OK) {
KRB5_LOG(KRB5_ERR, "C_EncryptUpdate failed in "
"krb5int_aes_encrypt: rv = 0x%x", rv);
goto cleanup;
}
/* tmp_pt will provide 0 padding for last parital pt block */
bzero(tmp_pt, sizeof (tmp_pt));
/* copy Pn to tmp_pt which has 0 padding */
bcopy(input->data + (input->length - partialamount), tmp_pt,
partialamount);
/* encrypt Pn with 0 padding, Cn & C' ivec, output is Cn-1 */
outlen = sizeof (tmp_ct);
rv = C_EncryptUpdate(krb_ctx_hSession(context),
(CK_BYTE_PTR)tmp_pt,
BLOCK_SIZE,
(CK_BYTE_PTR)tmp_ct,
&outlen);
if (rv != CKR_OK) {
KRB5_LOG(KRB5_ERR, "C_Encrypt failed in "
"krb5int_aes_encrypt: rv = 0x%x", rv);
goto cleanup;
}
nlobp = (char *)(output->data + ((nblocks - 2) * BLOCK_SIZE));
lobp = (char *)(output->data + ((nblocks - 1) * BLOCK_SIZE));
/* copy Cn from next to last output block to last block */
bcopy(nlobp, lobp, partialamount);
/* copy Cn-1 from tmp_ct to next to last output block */
bcopy(tmp_ct, nlobp, BLOCK_SIZE);
/* Close the crypto session, ignore the output */
rv = C_EncryptFinal(krb_ctx_hSession(context),
(CK_BYTE_PTR)tmp_ct, &outlen);
if (rv != CKR_OK)
goto cleanup;
}
/*
* The ivec is updated to allow the caller to chain ivecs, done for the
* kcmd (rsh/rcp/etc...). Note this is not done for 1 block although I
* am not sure why but I'm continuing the tradition from the MIT code.
* Note, the next to last output block is copied because it contains the
* last full block of cipher text.
*/
if (nblocks > 1 && ivec)
(void) memcpy(ivec->data, nlobp, BLOCK_SIZE);
cleanup:
if (rv != CKR_OK)
ret = PKCS_ERR;
if (ret)
bzero(output->data, input->length);
return (ret);
}
#endif /* _KERNEL */
/*
* AES Decrypt using CipherText Stealing mode built on top of CBC mode. See the
* krb5int_aes_encrypt() comments for the reason CBC is being used.
*/
#ifdef _KERNEL
/*ARGSUSED*/
krb5_error_code
krb5int_aes_decrypt(krb5_context context,
const krb5_keyblock *key, const krb5_data *ivec,
const krb5_data *input, krb5_data *output)
{
krb5_error_code ret = 0;
int nblocks, partialamount;
char local_iv_data[BLOCK_SIZE];
krb5_data local_iv;
KRB5_LOG0(KRB5_INFO, "In krb5int_aes_decrypt: start");
ASSERT(input != NULL);
if (input->length < BLOCK_SIZE)
return (KRB5_BAD_MSIZE);
ASSERT(output != NULL);
ASSERT(input->length == output->length);
ASSERT(key != NULL);
ASSERT(key->kef_mt == crypto_mech2id(SUN_CKM_AES_CBC));
if (ivec != NULL) {
/*
* This function updates ivec->data if the ivec is passed in so
* it better have a data pointer and a proper length.
*/
if (ivec->data == NULL || ivec->length != BLOCK_SIZE) {
ASSERT(ivec->data != NULL);
ASSERT(ivec->length == BLOCK_SIZE);
KRB5_LOG1(KRB5_ERR, "In krb5int_aes_decrypt: error "
"ivec->data = %p ivec->length = %d",
(void *)ivec->data, ivec->length);
ret = KRB5_CRYPTO_INTERNAL;
goto cleanup;
}
}
/* number of input blocks including partial block */
nblocks = (input->length + BLOCK_SIZE - 1) / BLOCK_SIZE;
KRB5_LOG(KRB5_INFO, "nblocks = %d", nblocks);
/* get # of bytes in partially filled block */
partialamount = input->length % BLOCK_SIZE;
KRB5_LOG(KRB5_INFO, "partialamount = %d", partialamount);
if (ivec != NULL) {
local_iv.data = ivec->data;
local_iv.length = ivec->length;
} else {
bzero(local_iv_data, sizeof (local_iv_data));
local_iv.data = local_iv_data;
local_iv.length = sizeof (local_iv_data);
}
if (nblocks == 1 || (partialamount == 0)) {
char orig_input[BLOCK_SIZE * 2];
/*
* nlibp = next to last input block pointer
* libp = last input block pointer
*/
char *nlibp, *libp;
/*
* Simple case:
*
* Swap last 2 ciphertext blocks (all must be full), then use
* CBC to implement CTS.
*/
if (nblocks > 1) {
/*
* swap last 2 ciphertext blocks to implement CTS
*/
char tmp[BLOCK_SIZE];
nlibp = input->data + ((nblocks - 2) * BLOCK_SIZE);
libp = input->data + ((nblocks - 1) * BLOCK_SIZE);
/* first save orig input data for later restore */
/* we know that partial amount is 0, because */
/* nblocks is > 1, so we copy the last two blocks */
bcopy(nlibp, orig_input, sizeof (orig_input));
/* swap */
bcopy(nlibp, tmp, BLOCK_SIZE);
bcopy(libp, nlibp, BLOCK_SIZE);
bcopy(tmp, libp, BLOCK_SIZE);
}
ret = k5_ef_crypto((const char *)input->data,
(char *)output->data,
input->length, (krb5_keyblock *)key,
&local_iv, FALSE);
if (nblocks > 1) {
/* restore orig input data */
bcopy(orig_input, nlibp, sizeof (orig_input));
}
if (ret != 0) {
KRB5_LOG(KRB5_ERR,
"k5_ef_crypto returned error: ret = 0x%08x",
ret);
goto cleanup;
}
} else {
krb5_data tmp_ivec;
char tmp_ivec_data[BLOCK_SIZE], tmp_input_data[BLOCK_SIZE],
tmp_output_data[BLOCK_SIZE];
/* pointers to Cn, Cn-1, Cn-2 CipherText */
char *Cn, *Cn_1, *Cn_2;
long length;
/*
* Complex case:
*
* Decrypting in CTS where there is a partial block of
* ciphertext.
*/
/* setting pointers to CipherText for later use */
Cn = input->data + (input->length - partialamount);
/* Cn - 1 */
Cn_1 = Cn - BLOCK_SIZE;
/* Cn - 2 */
Cn_2 = Cn_1 - BLOCK_SIZE;
if (nblocks > 2) {
/* set length to include blocks C0 thru Cn-2 */
length = input->length - (BLOCK_SIZE + partialamount);
/*
* First decrypt C0 thru Cn-2 using CBC with the input
* ivec.
*/
ret = k5_ef_crypto((const char *)input->data,
output->data, length, (krb5_keyblock *)key,
&local_iv, FALSE);
if (ret != 0) {
KRB5_LOG(KRB5_ERR,
"k5_ef_crypto: error: ret = 0x%08x",
ret);
goto cleanup;
}
}
/*
* Prepare to decrypt Cn-1 using a ivec of Cn with 0 padding.
*/
bzero(tmp_ivec_data, sizeof (tmp_ivec_data));
/* the tmp ivec data holds Cn with 0 padding */
bcopy(Cn, tmp_ivec_data, partialamount);
tmp_ivec.data = tmp_ivec_data;
tmp_ivec.length = sizeof (tmp_ivec_data);
/* decrypt 1 block */
length = BLOCK_SIZE;
/*
* Now decrypt using Cn-1 input, Cn + 0 padding for ivec, Pn &
* C' output
*/
ret = k5_ef_crypto((const char *)Cn_1,
tmp_output_data, length,
(krb5_keyblock *)key, &tmp_ivec, FALSE);
if (ret != 0) {
KRB5_LOG(KRB5_ERR,
"k5_ef_crypto: error: ret = 0x%08x",
ret);
goto cleanup;
}
/*
* tmp input data should hold Cn with C'
* Note, tmp_output_data contains Pn + C',
*/
/* copy Cn */
bcopy(Cn, tmp_input_data, partialamount);
/* copy C' */
bcopy(tmp_output_data + partialamount,
tmp_input_data + partialamount,
(BLOCK_SIZE - partialamount));
/* copy Pn in tmp output to output->data */
bcopy(tmp_output_data,
output->data + (input->length - partialamount),
partialamount);
if (nblocks > 2) {
/* use Cn-2 as ivec */
tmp_ivec.data = Cn_2;
} else {
/* use 0 as ivec because Cn-2 does not exist */
bzero(tmp_ivec_data, sizeof (tmp_ivec_data));
}
/*
* Now decrypt Cn + C' input, using either Cn-2 or 0 for ivec
* (set above), Pn-1 output.
*/
ret = k5_ef_crypto((const char *)tmp_input_data,
(char *)output->data +
(input->length - (BLOCK_SIZE + partialamount)),
length, (krb5_keyblock *)key,
&tmp_ivec, FALSE);
if (ret != 0) {
KRB5_LOG(KRB5_ERR,
"k5_ef_crypto: error: ret = 0x%08x", ret);
goto cleanup;
}
} /* end partial block processing */
/*
* The ivec is updated to allow the caller to chain ivecs. At this
* point I don't think any kernel callers are using this however the
* userland version of this function does it so this should be done in
* kernel for consistency's sake. This is not done for 1 block, got
* this from MIT.
*/
if (nblocks > 1 && ivec) {
(void) memcpy(ivec->data,
input->data + ((nblocks - 2) * BLOCK_SIZE),
BLOCK_SIZE);
}
cleanup:
if (ret)
bzero(output->data, output->length);
return (ret);
}
#else /* User Space */
/*ARGSUSED*/
krb5_error_code
krb5int_aes_decrypt(krb5_context context,
const krb5_keyblock *key, const krb5_data *ivec,
const krb5_data *input, krb5_data *output)
{
krb5_error_code ret = 0;
int nblocks, partialamount;
CK_RV rv;
KRB5_MECH_TO_PKCS algos;
CK_MECHANISM mechanism;
CK_ULONG outlen;
char tmp_ivec[BLOCK_SIZE];
assert(input != NULL);
if (input->length < BLOCK_SIZE)
return (KRB5_BAD_MSIZE);
assert(output != NULL);
assert(input->length == output->length);
assert(key != NULL);
if (ivec != NULL) {
/*
* This function updates ivec->data if the ivec is passed in so
* it better have a data pointer and a proper length.
*/
if (ivec->data == NULL || ivec->length != BLOCK_SIZE) {
assert(ivec->data != NULL);
assert(ivec->length == BLOCK_SIZE);
KRB5_LOG1(KRB5_ERR, "In krb5int_aes_decrypt: error "
"ivec->data = %p ivec->length = %d", ivec->data,
ivec->length);
ret = KRB5_CRYPTO_INTERNAL;
goto cleanup;
}
}
/* number of input blocks including partial block */
nblocks = (input->length + BLOCK_SIZE - 1) / BLOCK_SIZE;
KRB5_LOG(KRB5_INFO, "nblocks = %d", nblocks);
/* get # of bytes in partially filled block */
partialamount = input->length % BLOCK_SIZE;
KRB5_LOG(KRB5_INFO, "partialamount = %d", partialamount);
rv = get_algo(key->enctype, &algos);
if (rv != CKR_OK)
goto cleanup;
assert(algos.enc_algo == CKM_AES_CBC);
rv = init_key_uef(krb_ctx_hSession(context), (krb5_keyblock *)key);
if (rv != CKR_OK) {
goto cleanup;
}
mechanism.mechanism = algos.enc_algo;
if (ivec == NULL) {
bzero(tmp_ivec, sizeof (tmp_ivec));
mechanism.pParameter = tmp_ivec;
mechanism.ulParameterLen = sizeof (tmp_ivec);
} else {
mechanism.pParameter = ivec->data;
mechanism.ulParameterLen = ivec->length;
}
if (nblocks == 1 || (partialamount == 0)) {
char orig_input[BLOCK_SIZE * 2];
/*
* nlibp = next to last input block pointer
* libp = last input block pointer
*/
char *nlibp, *libp;
/*
* Simple case:
*
* Swap last 2 ciphertext blocks (all must be full), then use
* CBC to implement CTS.
*/
if (nblocks > 1) {
/*
* swap last 2 ciphertext blocks to implement CTS
*/
char tmp[BLOCK_SIZE];
/*
* Note, the side effect with this is that we are
* modifying the input->data!
*/
nlibp = input->data + ((nblocks - 2) * BLOCK_SIZE);
libp = input->data + ((nblocks - 1) * BLOCK_SIZE);
/* first save orig input data for later restore */
/* we know that partial amount is 0, because */
/* nblocks is > 1, so we copy the last two blocks */
bcopy(nlibp, orig_input, sizeof (orig_input));
bcopy(nlibp, tmp, BLOCK_SIZE);
bcopy(libp, nlibp, BLOCK_SIZE);
bcopy(tmp, libp, BLOCK_SIZE);
}
/*
* Note, since CBC is assumed to be the underlying mode, this
* call to C_DecryptInit is setting the IV. The IV in use here
* is either the ivec passed in or a block of 0's. All calls to
* C_DecryptInit set the IV in this function.
*/
rv = C_DecryptInit(krb_ctx_hSession(context), &mechanism,
key->hKey);
if (rv != CKR_OK) {
KRB5_LOG(KRB5_ERR, "C_DecryptInit failed in "
"krb5int_aes_decrypt: rv = 0x%x", rv);
goto cleanup;
}
/*
* C_Encrypt/Decrypt requires a pointer to long, not a pointer
* to int cast to pointer to long!!!
*/
outlen = output->length;
rv = C_Decrypt(krb_ctx_hSession(context),
(CK_BYTE_PTR)input->data,
input->length,
(CK_BYTE_PTR)output->data,
&outlen);
if (nblocks > 1) {
/* restore orig input data */
bcopy(orig_input, nlibp, sizeof (orig_input));
}
} else {
char tmp_ivec_data[BLOCK_SIZE], tmp_input_data[BLOCK_SIZE],
tmp_output_data[BLOCK_SIZE];
/* pointers to Cn, Cn-1, Cn-2 CipherText */
char *Cn, *Cn_1, *Cn_2;
CK_ULONG length;
/*
* Complex case:
*
* Decrypting in CTS where there is a partial block of
* ciphertext.
*/
/* setting pointers to CipherText for later use */
Cn = input->data + (input->length - partialamount);
/* Cn - 1 */
Cn_1 = Cn - BLOCK_SIZE;
/* Cn - 2 */
Cn_2 = Cn_1 - BLOCK_SIZE;
if (nblocks > 2) {
rv = C_DecryptInit(krb_ctx_hSession(context),
&mechanism, key->hKey);
if (rv != CKR_OK) {
KRB5_LOG(KRB5_ERR, "C_DecryptInit failed in "
"krb5int_aes_decrypt: rv = 0x%x", rv);
goto cleanup;
}
/* set length to include blocks C0 thru Cn-2 */
length = input->length - (BLOCK_SIZE + partialamount);
outlen = length;
/*
* First decrypt C0 thru Cn-2 using CBC with the input
* ivec.
*/
rv = C_Decrypt(krb_ctx_hSession(context),
(CK_BYTE_PTR)input->data,
length,
(CK_BYTE_PTR)output->data,
&outlen);
if (rv != CKR_OK)
goto cleanup;
}
/*
* Prepare to decrypt Cn-1 using a ivec of Cn with 0 padding.
*/
bzero(tmp_ivec_data, sizeof (tmp_ivec_data));
/* the tmp ivec data holds Cn with 0 padding */
bcopy(Cn, tmp_ivec_data, partialamount);
/* decrypt 1 block */
length = BLOCK_SIZE;
outlen = length;
/* set ivec to Cn with 0 padding */
mechanism.pParameter = tmp_ivec_data;
mechanism.ulParameterLen = sizeof (tmp_ivec_data);
rv = C_DecryptInit(krb_ctx_hSession(context), &mechanism,
key->hKey);
if (rv != CKR_OK) {
KRB5_LOG(KRB5_ERR, "C_DecryptInit failed in "
"krb5int_aes_decrypt: rv = 0x%x", rv);
goto cleanup;
}
/*
* Now decrypt using Cn-1 input, Cn + 0 padding for ivec, Pn &
* C' output
*/
rv = C_Decrypt(krb_ctx_hSession(context),
(CK_BYTE_PTR)Cn_1,
length,
(CK_BYTE_PTR)tmp_output_data,
&outlen);
if (rv != CKR_OK)
goto cleanup;
/*
* tmp input data should hold Cn with C'
* Note, tmp_output_data contains Pn + C',
*/
/* copy Cn */
bcopy(Cn, tmp_input_data, partialamount);
/* copy C' */
bcopy(tmp_output_data + partialamount,
tmp_input_data + partialamount,
(BLOCK_SIZE - partialamount));
/* copy Pn in tmp output to output->data last block */
bcopy(tmp_output_data,
output->data + (input->length - partialamount),
partialamount);
if (nblocks > 2) {
/* use Cn-2 as ivec */
mechanism.pParameter = Cn_2;
} else {
/*
* nblocks == 2
*
* Cn-2 does not exist so either use 0 if input ivec
* does not exist or use the input ivec.
*/
if (ivec == NULL) {
bzero(tmp_ivec_data, sizeof (tmp_ivec_data));
} else {
/* use original input ivec */
mechanism.pParameter = ivec->data;
mechanism.ulParameterLen = ivec->length;
}
}
rv = C_DecryptInit(krb_ctx_hSession(context), &mechanism,
key->hKey);
if (rv != CKR_OK) {
KRB5_LOG(KRB5_ERR, "C_DecryptInit failed in "
"krb5int_aes_decrypt: rv = 0x%x", rv);
goto cleanup;
}
/*
* Now decrypt Cn + C' input, using either Cn-2, original input
* ivec or 0 for ivec (set above), Pn-1 output.
*/
rv = C_Decrypt(krb_ctx_hSession(context),
(CK_BYTE_PTR)tmp_input_data,
length,
(CK_BYTE_PTR)output->data + (input->length -
(BLOCK_SIZE + partialamount)),
&outlen);
if (rv != CKR_OK)
goto cleanup;
} /* end partial block processing */
/*
* The ivec is updated to allow the caller to chain ivecs, done for the
* kcmd (rsh/rcp/etc...). Note this is not done for 1 block although I
* am not sure why but I'm continuing the tradition from the MIT code.
*/
if (nblocks > 1 && ivec) {
(void) memcpy(ivec->data,
input->data + ((nblocks - 2) * BLOCK_SIZE),
BLOCK_SIZE);
}
cleanup:
if (rv != CKR_OK)
ret = PKCS_ERR;
if (ret)
bzero(output->data, input->length);
return (ret);
}
#endif /* _KERNEL */
static krb5_error_code
k5_aes_make_key(krb5_context context,
const krb5_data *randombits, krb5_keyblock *key)
{
krb5_error_code ret = 0;
if (key->length != 16 && key->length != 32)
return (KRB5_BAD_KEYSIZE);
if (randombits->length != key->length)
return (KRB5_CRYPTO_INTERNAL);
key->magic = KV5M_KEYBLOCK;
key->dk_list = NULL;
#ifdef _KERNEL
key->kef_key.ck_data = NULL;
key->key_tmpl = NULL;
(void) memcpy(key->contents, randombits->data, randombits->length);
ret = init_key_kef(context->kef_cipher_mt, key);
#else
key->hKey = CK_INVALID_HANDLE;
(void) memcpy(key->contents, randombits->data, randombits->length);
ret = init_key_uef(krb_ctx_hSession(context), key);
#endif /* _KERNEL */
KRB5_LOG0(KRB5_INFO, "k5_aes_make_key() end\n");
return (ret);
}
/*ARGSUSED*/
static krb5_error_code
krb5int_aes_init_state(krb5_context context, const krb5_keyblock *key,
krb5_keyusage usage, krb5_data *state)
{
if (!state)
return (0);
if (state && state->data)
FREE(state->data, state->length);
state->length = BLOCK_SIZE;
state->data = (void *) MALLOC(BLOCK_SIZE);
if (state->data == NULL)
return (ENOMEM);
(void) memset(state->data, 0, state->length);
return (0);
}
const struct krb5_enc_provider krb5int_enc_aes128 = {
BLOCK_SIZE,
16, 16,
krb5int_aes_encrypt,
krb5int_aes_decrypt,
k5_aes_make_key,
krb5int_aes_init_state,
krb5int_default_free_state
};
const struct krb5_enc_provider krb5int_enc_aes256 = {
BLOCK_SIZE,
32, 32,
krb5int_aes_encrypt,
krb5int_aes_decrypt,
k5_aes_make_key,
krb5int_aes_init_state,
krb5int_default_free_state
};
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright (c) 2000 by Computer Science Laboratory,
* Rensselaer Polytechnic Institute
* #include STD_DISCLAIMER
*/
#include <k5-int.h>
#include <arcfour.h>
/* from a random bitstrem, construct a key */
static krb5_error_code
k5_arcfour_make_key(krb5_context, const krb5_data *, krb5_keyblock *);
#ifndef _KERNEL
static krb5_error_code
setup_arcfour_crypto(CK_SESSION_HANDLE session,
const krb5_keyblock *key,
KRB5_MECH_TO_PKCS *algos,
CK_OBJECT_HANDLE *hKey)
{
krb5_error_code ret = 0;
CK_RV rv;
CK_OBJECT_CLASS class = CKO_SECRET_KEY;
CK_KEY_TYPE keyType = CKK_RC4;
CK_BBOOL true = TRUE, false = FALSE;
CK_ATTRIBUTE template[5];
if ((rv = get_algo(key->enctype, algos)) != CKR_OK) {
KRB5_LOG0(KRB5_ERR, "failure to get algo id in function "
"k5_arcfour_decrypt.");
return (PKCS_ERR);
}
template[0].type = CKA_CLASS;
template[0].pValue = &class;
template[0].ulValueLen = sizeof (class);
template[1].type = CKA_KEY_TYPE;
template[1].pValue = &keyType;
template[1].ulValueLen = sizeof (keyType);
template[2].type = CKA_TOKEN;
template[2].pValue = &false;
template[2].ulValueLen = sizeof (false);
template[3].type = CKA_ENCRYPT;
template[3].pValue = &true;
template[3].ulValueLen = sizeof (true);
template[4].type = CKA_VALUE;
template[4].pValue = key->contents;
template[4].ulValueLen = key->length;
/* Create an object handle for the key */
if ((rv = C_CreateObject(session, template,
sizeof(template)/sizeof(CK_ATTRIBUTE),
hKey)) != CKR_OK) {
KRB5_LOG(KRB5_ERR, "C_CreateObject failed in "
"k5_arcfour_decrypt: rv = 0x%x.", rv);
ret = PKCS_ERR;
}
return (ret);
}
#endif /* !_KERNEL */
/* The workhorse of the arcfour system, this impliments the cipher */
/* ARGSUSED */
static krb5_error_code
k5_arcfour_decrypt(krb5_context context,
const krb5_keyblock *key, const krb5_data *state,
const krb5_data *input, krb5_data *output)
{
krb5_error_code ret = 0;
#ifndef _KERNEL
CK_RV rv;
KRB5_MECH_TO_PKCS algos;
CK_OBJECT_HANDLE *kptr = NULL, hKey = CK_INVALID_HANDLE;
CK_MECHANISM mechanism;
CK_SESSION_HANDLE session = 0;
CK_ULONG outlen;
int need_init = 0;
#endif
KRB5_LOG0(KRB5_INFO, "k5_arcfour_decrypt start");
if (key->length != 16)
return(KRB5_BAD_KEYSIZE);
if (input->length != output->length)
return(KRB5_BAD_MSIZE);
#ifndef _KERNEL
/*
* If RC4 is being used to encrypt a stream of data blocks,
* the keys for encrypt and decrypt must be kept separate
* so that their associated state data doesn't get mixed up
* between operations. The r-cmds (rlogin, rsh, rcp) use
* the "init_state" function (see bottom of this module)
* to set up and prepare for stream encryption.
*
* Normally, the RC4 key is used as a single operation
* (i.e. call C_Encrypt) instead of a constantly updating
* stream cipher (C_EncryptUpdate). In those cases, we just
* use a short-term key object defined locally. We don't
* have to save state between operations.
*
* This logic here is to make sure that the keys are tracked
* correctly depending on how they are used and that the RC4
* context record is properly initialized.
*/
if (!context->arcfour_ctx.initialized) {
session = krb_ctx_hSession(context);
/* Just use a local, 1-time only key object */
kptr = (CK_OBJECT_HANDLE *)&hKey;
need_init = 1;
} else {
session = context->arcfour_ctx.dSession;
/* If the dKey handle was not defined, we need to initialize one */
if (context->arcfour_ctx.dKey == CK_INVALID_HANDLE) {
need_init = 1;
/* Use the long-term key object in the RC4 context area */
kptr = &context->arcfour_ctx.dKey;
}
}
if (need_init) {
ret = setup_arcfour_crypto(session, key, &algos, kptr);
if (ret)
goto cleanup;
mechanism.mechanism = algos.enc_algo;
mechanism.pParameter = NULL;
mechanism.ulParameterLen = 0;
rv = C_DecryptInit(session, &mechanism, *kptr);
if (rv != CKR_OK) {
KRB5_LOG(KRB5_ERR, "C_DecryptInit failed in "
"k5_arcfour_decrypt: rv = 0x%x", rv);
ret = PKCS_ERR;
goto cleanup;
}
}
outlen = (CK_ULONG)output->length;
if (context->arcfour_ctx.initialized)
rv = C_DecryptUpdate(session,
(CK_BYTE_PTR)input->data,
(CK_ULONG)input->length,
(CK_BYTE_PTR)output->data,
(CK_ULONG_PTR)&outlen);
else {
rv = C_Decrypt(session,
(CK_BYTE_PTR)input->data,
(CK_ULONG)input->length,
(CK_BYTE_PTR)output->data,
(CK_ULONG_PTR)&outlen);
}
output->length = (uint32_t)outlen;
if (rv != CKR_OK) {
KRB5_LOG(KRB5_ERR,
"C_DecryptUpdate failed in k5_arcfour_decrypt: "
"rv = 0x%x", rv);
ret = PKCS_ERR;
}
cleanup:
if (ret)
bzero(output->data, input->length);
/* If we used a 1-time only key object, destroy it now */
if (hKey != CK_INVALID_HANDLE)
(void)C_DestroyObject(session, hKey);
#else /* !_KERNEL */
KRB5_LOG(KRB5_INFO, "key->kef_mt = %ld", (ulong_t) key->kef_mt);
ret = k5_ef_crypto((const char *)input->data, (char *)output->data,
input->length, (krb5_keyblock *)key, NULL, 0);
#endif /* !_KERNEL */
KRB5_LOG0(KRB5_INFO, "k5_arcfour_docrypt end");
return (ret);
}
/* ARGSUSED */
static krb5_error_code
k5_arcfour_encrypt(krb5_context context,
const krb5_keyblock *key, const krb5_data *state,
const krb5_data *input, krb5_data *output)
{
krb5_error_code ret = 0;
#ifndef _KERNEL
CK_RV rv;
KRB5_MECH_TO_PKCS algos;
CK_MECHANISM mechanism;
CK_OBJECT_HANDLE *kptr = NULL, hKey = CK_INVALID_HANDLE;
CK_SESSION_HANDLE session;
int need_init = 0;
CK_ULONG outlen;
#endif
KRB5_LOG0(KRB5_INFO, "k5_arcfour_encrypt start");
if (key->length != 16)
return(KRB5_BAD_KEYSIZE);
if (input->length != output->length)
return(KRB5_BAD_MSIZE);
#ifndef _KERNEL
/*
* See the comments in the k5_arcfour_decrypt routine (above)
* for an explanation of why the key handles are initialized
* and used as they are here.
*/
if (!context->arcfour_ctx.initialized) {
session = krb_ctx_hSession(context);
kptr = (CK_OBJECT_HANDLE *)&hKey;
need_init = 1;
} else {
session = context->arcfour_ctx.eSession;
if (context->arcfour_ctx.eKey == 0) {
kptr = &context->arcfour_ctx.eKey;
need_init = 1;
}
}
if (need_init) {
ret = setup_arcfour_crypto(session, key, &algos, kptr);
if (ret)
goto cleanup;
mechanism.mechanism = algos.enc_algo;
mechanism.pParameter = NULL;
mechanism.ulParameterLen = 0;
rv = C_EncryptInit(session, &mechanism, *kptr);
if (rv != CKR_OK) {
KRB5_LOG(KRB5_ERR, "C_EncryptInit failed in "
"k5_arcfour_encrypt: rv = 0x%x", rv);
ret = PKCS_ERR;
goto cleanup;
}
}
/*
* If we've initialize the stream for use with r-commands,
* use the open-ended session handle and call.
*/
outlen = (CK_ULONG)output->length;
if (context->arcfour_ctx.initialized)
rv = C_EncryptUpdate(session,
(CK_BYTE_PTR)input->data,
(CK_ULONG)input->length,
(CK_BYTE_PTR)output->data,
(CK_ULONG_PTR)&outlen);
else {
rv = C_Encrypt(session,
(CK_BYTE_PTR)input->data,
(CK_ULONG)input->length,
(CK_BYTE_PTR)output->data,
(CK_ULONG_PTR)&outlen);
}
output->length = (uint32_t)outlen;
if (rv != CKR_OK) {
KRB5_LOG(KRB5_ERR,
"C_EncryptUpdate failed in k5_arcfour_encrypt: "
"rv = 0x%x", rv);
ret = PKCS_ERR;
}
cleanup:
if (ret)
bzero(output->data, input->length);
if (hKey != CK_INVALID_HANDLE)
(void)C_DestroyObject(session, hKey);
#else /* !_KERNEL */
KRB5_LOG1(KRB5_INFO, "key->kef_mt = %ld key->key_tmpl = %ld",
(ulong_t) key->kef_mt, (ulong_t) key->key_tmpl);
ret = k5_ef_crypto((const char *)input->data, (char *)output->data,
input->length, (krb5_keyblock *)key, NULL, 1);
#endif /* !_KERNEL */
KRB5_LOG0(KRB5_INFO, "k5_arcfour_docrypt end");
return (ret);
}
/* ARGSUSED */
static krb5_error_code
k5_arcfour_make_key(krb5_context context,
const krb5_data *randombits, krb5_keyblock *key)
{
krb5_error_code ret = 0;
KRB5_LOG0(KRB5_INFO, "k5_arcfour_make_key() start\n");
if (key->length != 16)
return(KRB5_BAD_KEYSIZE);
if (randombits->length != 16)
return(KRB5_CRYPTO_INTERNAL);
key->magic = KV5M_KEYBLOCK;
key->length = 16;
key->dk_list = NULL;
#ifdef _KERNEL
key->kef_key.ck_data = NULL;
key->key_tmpl = NULL;
ret = init_key_kef(context->kef_cipher_mt, key);
#else
key->hKey = CK_INVALID_HANDLE;
ret = init_key_uef(krb_ctx_hSession(context), key);
#endif /* _KERNEL */
bcopy(randombits->data, key->contents, randombits->length);
KRB5_LOG0(KRB5_INFO, "k5_arcfour_make_key() end\n");
return (ret);
}
/*ARGSUSED*/
static krb5_error_code
k5_arcfour_init_state (krb5_context context,
const krb5_keyblock *key,
krb5_keyusage keyusage, krb5_data *new_state)
{
krb5_error_code retval = 0;
#ifndef _KERNEL
if (!context->arcfour_ctx.initialized) {
retval = krb5_open_pkcs11_session(&context->arcfour_ctx.eSession);
if (retval)
return (retval);
retval = krb5_open_pkcs11_session(&context->arcfour_ctx.dSession);
if (retval)
return (retval);
context->arcfour_ctx.initialized = 1;
context->arcfour_ctx.eKey = CK_INVALID_HANDLE;
context->arcfour_ctx.dKey = CK_INVALID_HANDLE;
}
#endif
return (retval);
}
/* Since the arcfour cipher is identical going forwards and backwards,
we just call "docrypt" directly
*/
const struct krb5_enc_provider krb5int_enc_arcfour = {
1,
16, 16,
k5_arcfour_encrypt,
k5_arcfour_decrypt,
k5_arcfour_make_key,
k5_arcfour_init_state,
krb5int_default_free_state
};
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* 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 "k5-int.h"
#include "des_int.h"
#include "enc_provider.h"
static krb5_error_code
k5_des_docrypt(krb5_context context, krb5_const krb5_keyblock *key,
krb5_const krb5_data *ivec, krb5_const krb5_data *input,
krb5_data *output, int encrypt)
{
krb5_error_code ret;
KRB5_LOG(KRB5_INFO, "k5_des_docrypt() start encrypt=%d\n", encrypt);
/* key->enctype was checked by the caller */
if (key->length != 8)
return(KRB5_BAD_KEYSIZE);
if ((input->length%8) != 0)
return(KRB5_BAD_MSIZE);
if (ivec && (ivec->length != 8))
return(KRB5_BAD_MSIZE);
if (input->length != output->length)
return(KRB5_BAD_MSIZE);
ret = mit_des_cbc_encrypt(context, (krb5_pointer) input->data,
(krb5_pointer) output->data, input->length,
(krb5_keyblock *)key,
ivec?(unsigned char *)ivec->data:
(unsigned char *)mit_des_zeroblock, encrypt);
KRB5_LOG0(KRB5_INFO, "k5_des_docrypt() end\n");
return(ret);
}
static krb5_error_code
k5_des_encrypt(krb5_context context, krb5_const krb5_keyblock *key,
krb5_const krb5_data *ivec, krb5_const krb5_data *input,
krb5_data *output)
{
return(k5_des_docrypt(context, key, ivec, input, output, 1));
}
static krb5_error_code
k5_des_decrypt(krb5_context context, krb5_const krb5_keyblock *key,
krb5_const krb5_data *ivec, krb5_const krb5_data *input,
krb5_data *output)
{
return(k5_des_docrypt(context, key, ivec, input, output, 0));
}
static krb5_error_code
k5_des_make_key(krb5_context context, krb5_const krb5_data *randombits,
krb5_keyblock *key)
{
krb5_error_code ret = 0;
if (key->length != 8)
return(KRB5_BAD_KEYSIZE);
if (randombits->length != 7)
return(KRB5_CRYPTO_INTERNAL);
key->magic = KV5M_KEYBLOCK;
key->length = 8;
key->dk_list = NULL;
/* take the seven bytes, move them around into the top 7 bits of the
8 key bytes, then compute the parity bits */
(void) memcpy(key->contents, randombits->data, randombits->length);
key->contents[7] = (((key->contents[0]&1)<<1) | ((key->contents[1]&1)<<2) |
((key->contents[2]&1)<<3) | ((key->contents[3]&1)<<4) |
((key->contents[4]&1)<<5) | ((key->contents[5]&1)<<6) |
((key->contents[6]&1)<<7));
mit_des_fixup_key_parity(key->contents);
#ifdef _KERNEL
key->kef_key.ck_data = NULL;
key->key_tmpl = NULL;
ret = init_key_kef(context->kef_cipher_mt, key);
#else
key->hKey = CK_INVALID_HANDLE;
ret = init_key_uef(krb_ctx_hSession(context), key);
#endif /* _KERNEL */
return (ret);
}
const struct krb5_enc_provider krb5int_enc_des = {
8,
7, 8,
k5_des_encrypt,
k5_des_decrypt,
k5_des_make_key,
krb5int_des_init_state,
krb5int_default_free_state
};
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* 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 "k5-int.h"
#include "des_int.h"
static krb5_error_code
k5_des3_docrypt(krb5_context context,
krb5_const krb5_keyblock *key, krb5_const krb5_data *ivec,
krb5_const krb5_data *input, krb5_data *output, int encrypt)
{
/* LINTED */
krb5_error_code ret;
KRB5_LOG0(KRB5_INFO, "k5_des3_docrypt() start");
/* key->enctype was checked by the caller */
if (key->length != 24)
return(KRB5_BAD_KEYSIZE);
if ((input->length%8) != 0)
return(KRB5_BAD_MSIZE);
if (ivec && (ivec->length != 8))
return(KRB5_BAD_MSIZE);
if (input->length != output->length)
return(KRB5_BAD_MSIZE);
ret = mit_des3_cbc_encrypt(context, (krb5_pointer) input->data,
(krb5_pointer) output->data, input->length,
(krb5_keyblock *)key,
ivec?(unsigned char *)ivec->data:(unsigned char *)mit_des_zeroblock,
encrypt);
KRB5_LOG0(KRB5_INFO, "k5_des3_docrypt() end\n");
return(ret);
}
static krb5_error_code
k5_des3_encrypt(krb5_context context,
krb5_const krb5_keyblock *key, krb5_const krb5_data *ivec,
krb5_const krb5_data *input, krb5_data *output)
{
return(k5_des3_docrypt(context, key, ivec, input, output, 1));
}
static krb5_error_code
k5_des3_decrypt(krb5_context context,
krb5_const krb5_keyblock *key, krb5_const krb5_data *ivec,
krb5_const krb5_data *input, krb5_data *output)
{
return(k5_des3_docrypt(context, key, ivec, input, output, 0));
}
static krb5_error_code
k5_des3_make_key(krb5_context context, krb5_const krb5_data *randombits,
krb5_keyblock *key)
{
int i;
krb5_error_code ret = 0;
KRB5_LOG0(KRB5_INFO, "k5_des3_make_key() start\n");
if (key->length != 24)
return(KRB5_BAD_KEYSIZE);
if (randombits->length != 21)
return(KRB5_CRYPTO_INTERNAL);
key->magic = KV5M_KEYBLOCK;
key->length = 24;
key->dk_list = NULL;
/* take the seven bytes, move them around into the top 7 bits of the
8 key bytes, then compute the parity bits. Do this three times. */
for (i=0; i<3; i++) {
(void) memcpy(key->contents+i*8, randombits->data+i*7, 7);
key->contents[i*8+7] = (((key->contents[i*8]&1)<<1) |
((key->contents[i*8+1]&1)<<2) |
((key->contents[i*8+2]&1)<<3) |
((key->contents[i*8+3]&1)<<4) |
((key->contents[i*8+4]&1)<<5) |
((key->contents[i*8+5]&1)<<6) |
((key->contents[i*8+6]&1)<<7));
mit_des_fixup_key_parity(key->contents+i*8);
}
#ifdef _KERNEL
key->kef_key.ck_data = NULL;
key->key_tmpl = NULL;
ret = init_key_kef(context->kef_cipher_mt, key);
#else
key->hKey = CK_INVALID_HANDLE;
ret = init_key_uef(krb_ctx_hSession(context), key);
#endif /* _KERNEL */
KRB5_LOG0(KRB5_INFO, "k5_des3_make_key() end\n");
return(ret);
}
const struct krb5_enc_provider krb5int_enc_des3 = {
8,
21, 24,
k5_des3_encrypt,
k5_des3_decrypt,
k5_des3_make_key,
krb5int_des_init_state,
krb5int_default_free_state
};
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* 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 "k5-int.h"
#include "etypes.h"
#ifdef _KERNEL
krb5_error_code
update_key_template(krb5_keyblock *key)
{
crypto_mechanism_t kef_mech;
int rv = 0;
krb5_error_code ret = 0;
KRB5_LOG0(KRB5_INFO, "update_key_template()");
if (key == NULL)
return (ret);
/*
* Preallocate the crypto_key_t records
* needed by the kernel crypto calls later.
*/
kef_mech.cm_type = key->kef_mt;
kef_mech.cm_param = NULL;
kef_mech.cm_param_len = 0;
/*
* Create an template to improve HMAC performance later.
*/
rv = crypto_create_ctx_template(&kef_mech,
&key->kef_key,
&key->key_tmpl,
KM_SLEEP);
if (rv != CRYPTO_SUCCESS) {
/*
* Some mechs don't support context templates
*/
if (rv == CRYPTO_NOT_SUPPORTED) {
ret = 0;
key->key_tmpl = NULL;
} else {
KRB5_LOG(KRB5_ERR,"crypto_create_ctx_template "
"error: %0x", rv);
ret = KRB5_KEF_ERROR;
}
}
return (ret);
}
/*
* initialize the KEF components of the krb5_keyblock record.
*/
krb5_error_code
init_key_kef(crypto_mech_type_t mech_type, krb5_keyblock *key)
{
krb5_error_code rv = 0;
KRB5_LOG0(KRB5_INFO, "init_key_kef()");
if (key == NULL)
return (rv);
if (key->kef_key.ck_data == NULL) {
key->kef_key.ck_data = key->contents;
}
/* kef keys are measured in bits */
key->kef_key.ck_length = key->length * 8;
key->kef_key.ck_format = CRYPTO_KEY_RAW;
key->kef_mt = mech_type;
if (key->key_tmpl == NULL && mech_type != CRYPTO_MECH_INVALID) {
rv = update_key_template(key);
}
return(rv);
}
#else
/*
* init_key_uef
* Initialize the Userland Encryption Framework fields of the
* key block.
*/
krb5_error_code
init_key_uef(CK_SESSION_HANDLE hSession, krb5_keyblock *key)
{
CK_RV rv = CKR_OK;
CK_MECHANISM mechanism;
CK_OBJECT_CLASS class = CKO_SECRET_KEY;
CK_KEY_TYPE keyType;
CK_BBOOL true = TRUE, false = FALSE;
CK_ATTRIBUTE template[6];
/* If its already initialized, return OK */
/*
* fork safety: if the key->pid != __krb5_current_pid then a fork has
* taken place and the pkcs11 key handle must be re-acquired.
*/
if ((key->hKey != CK_INVALID_HANDLE) &&
(key->pid == __krb5_current_pid))
return (rv);
/* fork safety */
key->pid = __krb5_current_pid;
if ((rv = get_key_type(key->enctype, &keyType)) != CKR_OK) {
KRB5_LOG0(KRB5_ERR, "failure to get key type in function "
"init_key_uef.");
return (PKCS_ERR);
}
template[0].type = CKA_CLASS;
template[0].pValue = &class;
template[0].ulValueLen = sizeof (class);
template[1].type = CKA_KEY_TYPE;
template[1].pValue = &keyType;
template[1].ulValueLen = sizeof (keyType);
template[2].type = CKA_TOKEN;
template[2].pValue = &false;
template[2].ulValueLen = sizeof (false);
template[3].type = CKA_ENCRYPT;
template[3].pValue = &true;
template[3].ulValueLen = sizeof (true);
template[4].type = CKA_DECRYPT;
template[4].pValue = &true;
template[4].ulValueLen = sizeof (true);
template[5].type = CKA_VALUE;
template[5].pValue = key->contents;
template[5].ulValueLen = key->length;
/* Create an object handle for the key */
if ((rv = C_CreateObject(hSession, template,
sizeof(template)/sizeof(CK_ATTRIBUTE),
&key->hKey)) != CKR_OK) {
KRB5_LOG(KRB5_ERR, "C_CreateObject failed in "
"init_key_uef: rv = 0x%x.", rv);
rv = PKCS_ERR;
}
return (rv);
}
#endif /* _KERNEL */
/*ARGSUSED*/
krb5_error_code KRB5_CALLCONV
krb5_c_encrypt(krb5_context context, const krb5_keyblock *key,
krb5_keyusage usage, const krb5_data *ivec,
const krb5_data *input, krb5_enc_data *output)
{
krb5_error_code ret;
int i;
KRB5_LOG(KRB5_INFO, "krb5_c_encrypt start etype = %d", key->enctype);
for (i=0; i<krb5_enctypes_length; i++) {
if (krb5_enctypes_list[i].etype == key->enctype)
break;
}
if (i == krb5_enctypes_length)
return(KRB5_BAD_ENCTYPE);
output->magic = KV5M_ENC_DATA;
output->kvno = 0;
output->enctype = key->enctype;
#ifdef _KERNEL
context->kef_cipher_mt = krb5_enctypes_list[i].kef_cipher_mt;
context->kef_hash_mt = krb5_enctypes_list[i].kef_hash_mt;
if (key->kef_key.ck_data == NULL) {
if ((ret = init_key_kef(context->kef_cipher_mt,
(krb5_keyblock *)key)))
return(ret);
}
#else
if ((ret = init_key_uef(krb_ctx_hSession(context), (krb5_keyblock *)key)))
return (ret);
#endif /* _KERNEL */
KRB5_LOG0(KRB5_INFO, "krb5_c_encrypt calling encrypt.");
return((*(krb5_enctypes_list[i].encrypt))
(context, krb5_enctypes_list[i].enc, krb5_enctypes_list[i].hash,
key, usage, ivec, input, &output->ciphertext));
}
/*
* 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 "k5-int.h"
#include "etypes.h"
/*ARGSUSED*/
krb5_error_code KRB5_CALLCONV
krb5_c_encrypt_length(krb5_context context, krb5_enctype enctype,
size_t inputlen, size_t *length)
{
int i;
for (i=0; i<krb5_enctypes_length; i++) {
if (krb5_enctypes_list[i].etype == enctype)
break;
}
if (i == krb5_enctypes_length)
return(KRB5_BAD_ENCTYPE);
(*(krb5_enctypes_list[i].encrypt_len))
(krb5_enctypes_list[i].enc, krb5_enctypes_list[i].hash,
inputlen, length);
return(0);
}
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* 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.
*/
#ifdef _KERNEL
/* Solaris Kerberos:
* we don't provide these functions to the kernel
*/
#define krb5int_des_string_to_key NULL
#define krb5_dk_string_to_key NULL
#define krb5int_arcfour_string_to_key NULL
#endif /* _KERNEL */
#include <k5-int.h>
#include <enc_provider.h>
#include <hash_provider.h>
#include <etypes.h>
#include <old.h>
#include <raw.h>
#include <dk.h>
#include <arcfour.h>
/* these will be linear searched. if they ever get big, a binary
search or hash table would be better, which means these would need
to be sorted. An array would be more efficient, but that assumes
that the keytypes are all near each other. I'd rather not make
that assumption. */
struct krb5_keytypes krb5_enctypes_list[] = {
{ ENCTYPE_DES_CBC_CRC,
"des-cbc-crc", "DES cbc mode with CRC-32",
&krb5int_enc_des, &krb5int_hash_crc32,
krb5_old_encrypt_length, krb5_old_encrypt, krb5_old_decrypt,
CKSUMTYPE_RSA_MD5,
#ifndef _KERNEL
krb5int_des_string_to_key,
#else
SUN_CKM_DES_CBC,
NULL,
CRYPTO_MECH_INVALID,
CRYPTO_MECH_INVALID
#endif /* !_KERNEL */
},
{ ENCTYPE_DES_CBC_MD5,
"des-cbc-md5", "DES cbc mode with RSA-MD5",
&krb5int_enc_des, &krb5int_hash_md5,
krb5_old_encrypt_length, krb5_old_encrypt, krb5_old_decrypt,
CKSUMTYPE_RSA_MD5,
#ifndef _KERNEL
krb5int_des_string_to_key,
#else
SUN_CKM_DES_CBC,
SUN_CKM_MD5,
CRYPTO_MECH_INVALID,
CRYPTO_MECH_INVALID
#endif /* !_KERNEL */
},
{ ENCTYPE_DES_CBC_MD5,
"des", "DES cbc mode with RSA-MD5", /* alias */
&krb5int_enc_des, &krb5int_hash_md5,
krb5_old_encrypt_length, krb5_old_encrypt, krb5_old_decrypt,
CKSUMTYPE_RSA_MD5,
#ifndef _KERNEL
krb5int_des_string_to_key,
#else
SUN_CKM_DES_CBC,
SUN_CKM_MD5,
CRYPTO_MECH_INVALID,
CRYPTO_MECH_INVALID
#endif /* _KERNEL */
},
{ ENCTYPE_DES_CBC_RAW,
"des-cbc-raw", "DES cbc mode raw",
&krb5int_enc_des, NULL,
krb5_raw_encrypt_length, krb5_raw_encrypt, krb5_raw_decrypt,
0,
#ifndef _KERNEL
krb5int_des_string_to_key,
#else
SUN_CKM_DES_CBC,
NULL,
CRYPTO_MECH_INVALID,
CRYPTO_MECH_INVALID
#endif /* !_KERNEL */
},
{ ENCTYPE_DES3_CBC_RAW,
"des3-cbc-raw", "Triple DES cbc mode raw",
&krb5int_enc_des3, NULL,
krb5_raw_encrypt_length, krb5_raw_encrypt, krb5_raw_decrypt,
0,
#ifndef _KERNEL
krb5int_dk_string_to_key,
#else
SUN_CKM_DES3_CBC,
NULL,
CRYPTO_MECH_INVALID,
CRYPTO_MECH_INVALID
#endif /* !_KERNEL */
},
{ ENCTYPE_DES3_CBC_SHA1,
"des3-cbc-sha1", "Triple DES cbc mode with HMAC/sha1",
&krb5int_enc_des3, &krb5int_hash_sha1,
krb5_dk_encrypt_length, krb5_dk_encrypt, krb5_dk_decrypt,
CKSUMTYPE_HMAC_SHA1_DES3,
#ifndef _KERNEL
krb5int_dk_string_to_key,
#else
SUN_CKM_DES3_CBC,
SUN_CKM_SHA1_HMAC,
CRYPTO_MECH_INVALID,
CRYPTO_MECH_INVALID
#endif
},
{ ENCTYPE_DES3_CBC_SHA1, /* alias */
"des3-hmac-sha1", "Triple DES cbc mode with HMAC/sha1",
&krb5int_enc_des3, &krb5int_hash_sha1,
krb5_dk_encrypt_length, krb5_dk_encrypt, krb5_dk_decrypt,
CKSUMTYPE_HMAC_SHA1_DES3,
#ifndef _KERNEL
krb5int_dk_string_to_key,
#else
SUN_CKM_DES3_CBC,
SUN_CKM_SHA1_HMAC,
CRYPTO_MECH_INVALID,
CRYPTO_MECH_INVALID
#endif /* !_KERNEL */
},
{ ENCTYPE_DES3_CBC_SHA1, /* alias */
"des3-cbc-sha1-kd", "Triple DES cbc mode with HMAC/sha1",
&krb5int_enc_des3, &krb5int_hash_sha1,
krb5_dk_encrypt_length, krb5_dk_encrypt, krb5_dk_decrypt,
CKSUMTYPE_HMAC_SHA1_DES3,
#ifndef _KERNEL
krb5int_dk_string_to_key,
#else
SUN_CKM_DES3_CBC,
SUN_CKM_SHA1_HMAC,
CRYPTO_MECH_INVALID,
CRYPTO_MECH_INVALID
#endif /* !_KERNEL */
},
/* The des3-cbc-hmac-sha1-kd is the official enctype associated with
* 3DES/SHA1 in draft-ietf-krb-wg-crypto-00.txt
*/
{ ENCTYPE_DES3_CBC_SHA1, /* alias */
"des3-cbc-hmac-sha1-kd", "Triple DES cbc mode with HMAC/sha1",
&krb5int_enc_des3, &krb5int_hash_sha1,
krb5_dk_encrypt_length, krb5_dk_encrypt, krb5_dk_decrypt,
CKSUMTYPE_HMAC_SHA1_DES3,
#ifndef _KERNEL
krb5int_dk_string_to_key,
#else
SUN_CKM_DES3_CBC,
SUN_CKM_SHA1_HMAC,
CRYPTO_MECH_INVALID,
CRYPTO_MECH_INVALID
#endif /* !_KERNEL */
},
{ ENCTYPE_DES_HMAC_SHA1,
"des-hmac-sha1", "DES with HMAC/sha1",
&krb5int_enc_des, &krb5int_hash_sha1,
krb5_dk_encrypt_length, krb5_dk_encrypt, krb5_dk_decrypt,
0,
#ifndef _KERNEL
krb5int_dk_string_to_key,
#else
SUN_CKM_DES_CBC,
SUN_CKM_SHA1_HMAC,
CRYPTO_MECH_INVALID,
CRYPTO_MECH_INVALID
#endif /* !_KERNEL */
},
{ ENCTYPE_ARCFOUR_HMAC,
"arcfour-hmac","ArcFour with HMAC/md5", &krb5int_enc_arcfour,
&krb5int_hash_md5,
krb5_arcfour_encrypt_length, krb5_arcfour_encrypt,
krb5_arcfour_decrypt,
CKSUMTYPE_HMAC_MD5_ARCFOUR,
#ifndef _KERNEL
krb5int_arcfour_string_to_key,
#else
SUN_CKM_RC4,
SUN_CKM_MD5_HMAC,
CRYPTO_MECH_INVALID,
CRYPTO_MECH_INVALID
#endif /* !_KERNEL */
},
{ ENCTYPE_ARCFOUR_HMAC, /* alias */
"rc4-hmac", "ArcFour with HMAC/md5", &krb5int_enc_arcfour,
&krb5int_hash_md5,
krb5_arcfour_encrypt_length, krb5_arcfour_encrypt,
krb5_arcfour_decrypt,
CKSUMTYPE_HMAC_MD5_ARCFOUR,
#ifndef _KERNEL
krb5int_arcfour_string_to_key,
#else
SUN_CKM_RC4,
SUN_CKM_MD5_HMAC,
CRYPTO_MECH_INVALID,
CRYPTO_MECH_INVALID
#endif /* !_KERNEL */
},
{ ENCTYPE_ARCFOUR_HMAC, /* alias */
"arcfour-hmac-md5", "ArcFour with HMAC/md5", &krb5int_enc_arcfour,
&krb5int_hash_md5,
krb5_arcfour_encrypt_length, krb5_arcfour_encrypt,
krb5_arcfour_decrypt,
CKSUMTYPE_HMAC_MD5_ARCFOUR,
#ifndef _KERNEL
krb5int_arcfour_string_to_key,
#else
SUN_CKM_RC4,
SUN_CKM_MD5_HMAC,
CRYPTO_MECH_INVALID,
CRYPTO_MECH_INVALID
#endif /* !_KERNEL */
},
{ ENCTYPE_ARCFOUR_HMAC_EXP,
"arcfour-hmac-exp", "Exportable ArcFour with HMAC/md5",
&krb5int_enc_arcfour,
&krb5int_hash_md5, krb5_arcfour_encrypt_length, krb5_arcfour_encrypt,
krb5_arcfour_decrypt,
CKSUMTYPE_HMAC_MD5_ARCFOUR,
#ifndef _KERNEL
krb5int_arcfour_string_to_key,
#else
SUN_CKM_RC4,
SUN_CKM_MD5_HMAC,
CRYPTO_MECH_INVALID,
CRYPTO_MECH_INVALID
#endif /* !_KERNEL */
},
{ ENCTYPE_ARCFOUR_HMAC_EXP, /* alias */
"rc4-hmac-exp", "Exportable ArcFour with HMAC/md5",
&krb5int_enc_arcfour,
&krb5int_hash_md5,
krb5_arcfour_encrypt_length, krb5_arcfour_encrypt,
krb5_arcfour_decrypt,
CKSUMTYPE_HMAC_MD5_ARCFOUR,
#ifndef _KERNEL
krb5int_arcfour_string_to_key,
#else
SUN_CKM_RC4,
SUN_CKM_MD5_HMAC,
CRYPTO_MECH_INVALID,
CRYPTO_MECH_INVALID
#endif /* !_KERNEL */
},
{ ENCTYPE_ARCFOUR_HMAC_EXP, /* alias */
"arcfour-hmac-md5-exp", "Exportable ArcFour with HMAC/md5",
&krb5int_enc_arcfour,
&krb5int_hash_md5,
krb5_arcfour_encrypt_length, krb5_arcfour_encrypt,
krb5_arcfour_decrypt,
CKSUMTYPE_HMAC_MD5_ARCFOUR,
#ifndef _KERNEL
krb5int_arcfour_string_to_key,
#else
SUN_CKM_RC4,
SUN_CKM_MD5_HMAC,
CRYPTO_MECH_INVALID,
CRYPTO_MECH_INVALID
#endif /* !_KERNEL */
},
/*
* Note, all AES enctypes must use SUN_CKM_AES_CBC. See aes_provider.c for
* more info.
*/
{ ENCTYPE_AES128_CTS_HMAC_SHA1_96,
"aes128-cts-hmac-sha1-96", "AES-128 CTS mode with 96-bit SHA-1 HMAC",
&krb5int_enc_aes128, &krb5int_hash_sha1,
krb5int_aes_encrypt_length, krb5int_aes_dk_encrypt, krb5int_aes_dk_decrypt,
CKSUMTYPE_HMAC_SHA1_96_AES128,
#ifndef _KERNEL
krb5int_aes_string_to_key,
#else
SUN_CKM_AES_CBC,
SUN_CKM_SHA1_HMAC,
CRYPTO_MECH_INVALID,
CRYPTO_MECH_INVALID
#endif /* !_KERNEL */
},
{ ENCTYPE_AES128_CTS_HMAC_SHA1_96,
"aes128-cts", "AES-128 CTS mode with 96-bit SHA-1 HMAC",
&krb5int_enc_aes128, &krb5int_hash_sha1,
krb5int_aes_encrypt_length, krb5int_aes_dk_encrypt, krb5int_aes_dk_decrypt,
CKSUMTYPE_HMAC_SHA1_96_AES128,
#ifndef _KERNEL
krb5int_aes_string_to_key,
#else
SUN_CKM_AES_CBC,
SUN_CKM_SHA1_HMAC,
CRYPTO_MECH_INVALID,
CRYPTO_MECH_INVALID
#endif /* !_KERNEL */
},
{ ENCTYPE_AES256_CTS_HMAC_SHA1_96,
"aes256-cts-hmac-sha1-96", "AES-256 CTS mode with 96-bit SHA-1 HMAC",
&krb5int_enc_aes256, &krb5int_hash_sha1,
krb5int_aes_encrypt_length, krb5int_aes_dk_encrypt, krb5int_aes_dk_decrypt,
CKSUMTYPE_HMAC_SHA1_96_AES256,
#ifndef _KERNEL
krb5int_aes_string_to_key,
#else
SUN_CKM_AES_CBC,
SUN_CKM_SHA1_HMAC,
CRYPTO_MECH_INVALID,
CRYPTO_MECH_INVALID
#endif /* !_KERNEL */
},
{ ENCTYPE_AES256_CTS_HMAC_SHA1_96,
"aes256-cts", "AES-256 CTS mode with 96-bit SHA-1 HMAC",
&krb5int_enc_aes256, &krb5int_hash_sha1,
krb5int_aes_encrypt_length, krb5int_aes_dk_encrypt, krb5int_aes_dk_decrypt,
CKSUMTYPE_HMAC_SHA1_96_AES256,
#ifndef _KERNEL
krb5int_aes_string_to_key,
#else
SUN_CKM_AES_CBC,
SUN_CKM_SHA1_HMAC,
CRYPTO_MECH_INVALID,
CRYPTO_MECH_INVALID
#endif /* !_KERNEL */
},
};
const int krb5_enctypes_length =
sizeof(krb5_enctypes_list)/sizeof(struct krb5_keytypes);
#ifdef _KERNEL
/*
* Routine to pre-fetch the mechanism types from KEF so
* we dont keep doing this step later.
*/
void
setup_kef_keytypes()
{
int i;
struct krb5_keytypes *kt;
for (i=0; i<krb5_enctypes_length; i++) {
kt = (struct krb5_keytypes *)&krb5_enctypes_list[i];
if (kt->kef_cipher_mt == CRYPTO_MECH_INVALID &&
kt->mt_e_name != NULL) {
krb5_enctypes_list[i].kef_cipher_mt =
crypto_mech2id(kt->mt_e_name);
}
if (kt->kef_hash_mt == CRYPTO_MECH_INVALID &&
kt->mt_h_name != NULL) {
krb5_enctypes_list[i].kef_hash_mt =
crypto_mech2id(kt->mt_h_name);
}
KRB5_LOG1(KRB5_INFO, "setup_kef_keytypes(): %s ==> %ld",
kt->mt_e_name,
(ulong_t) krb5_enctypes_list[i].kef_cipher_mt);
}
}
/*ARGSUSED*/
crypto_mech_type_t
get_cipher_mech_type(krb5_context context, krb5_keyblock *key)
{
int i;
struct krb5_keytypes *kt;
if (key == NULL)
return (CRYPTO_MECH_INVALID);
for (i=0; i<krb5_enctypes_length; i++) {
kt = (struct krb5_keytypes *)&krb5_enctypes_list[i];
if (kt->etype == key->enctype) {
KRB5_LOG1(KRB5_INFO, "get_cipher_mech_type() "
"found %s %ld",
kt->mt_e_name,
(ulong_t) kt->kef_cipher_mt);
return (kt->kef_cipher_mt);
}
}
return (CRYPTO_MECH_INVALID);
}
/*ARGSUSED*/
crypto_mech_type_t
get_hash_mech_type(krb5_context context, krb5_keyblock *key)
{
int i;
struct krb5_keytypes *kt;
if (key == NULL)
return (CRYPTO_MECH_INVALID);
for (i=0; i<krb5_enctypes_length; i++) {
kt = (struct krb5_keytypes *)&krb5_enctypes_list[i];
if (kt->etype == key->enctype) {
KRB5_LOG1(KRB5_INFO, "get_hash_mech_type() "
"found %s %ld",
kt->mt_h_name,
(ulong_t) kt->kef_hash_mt);
return (kt->kef_hash_mt);
}
}
return (CRYPTO_MECH_INVALID);
}
#endif /* _KERNEL */
/*
* 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 "k5-int.h"
#include "crc-32.h"
#include "hash_provider.h"
/* ARGSUSED */
static krb5_error_code
k5_crc32_hash(krb5_context context,
unsigned int icount, krb5_const krb5_data *input,
krb5_data *output)
{
unsigned long c, cn;
int i;
if (output->length != CRC32_CKSUM_LENGTH)
return(KRB5_CRYPTO_INTERNAL);
c = 0;
for (i=0; i<icount; i++) {
mit_crc32(input[i].data, input[i].length, &cn);
c ^= cn;
}
output->data[0] = c&0xff;
output->data[1] = (c>>8)&0xff;
output->data[2] = (c>>16)&0xff;
output->data[3] = (c>>24)&0xff;
return(0);
}
const struct krb5_hash_provider krb5int_hash_crc32 = {
CRC32_CKSUM_LENGTH,
1,
k5_crc32_hash
};
/*
* Copyright 2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <k5-int.h>
#include <sys/crypto/api.h>
#include <sys/callb.h>
#include <sys/uio.h>
int
k5_ef_hash(krb5_context context, int icount,
const krb5_data *input,
krb5_data *output)
{
int i;
int rv = CRYPTO_FAILED;
iovec_t v1, v2;
crypto_data_t d1, d2;
crypto_mechanism_t mech;
crypto_context_t ctxp;
KRB5_LOG0(KRB5_INFO, "k5_ef_hash() start");
bzero(&d1, sizeof (d1));
bzero(&d2, sizeof (d2));
v2.iov_base = (void *)output->data;
v2.iov_len = output->length;
d2.cd_format = CRYPTO_DATA_RAW;
d2.cd_offset = 0;
d2.cd_length = output->length;
d2.cd_raw = v2;
mech.cm_type = context->kef_cksum_mt;
if (mech.cm_type == CRYPTO_MECH_INVALID) {
KRB5_LOG(KRB5_ERR,
"k5_ef_hash() invalid mech specified: 0x%llx",
(long long)context->kef_hash_mt);
return (CRYPTO_FAILED);
}
mech.cm_param = 0;
mech.cm_param_len = 0;
rv = crypto_digest_init(&mech, &ctxp, NULL);
if (rv != CRYPTO_SUCCESS) {
KRB5_LOG(KRB5_ERR, "crypto_digest_init error: %0x", rv);
return (rv);
}
for (i = 0; i < icount; i++) {
v1.iov_base = (void *)input[i].data;
v1.iov_len = input[i].length;
d1.cd_length = input[i].length;
d1.cd_format = CRYPTO_DATA_RAW;
d1.cd_offset = 0;
d1.cd_raw = v1;
rv = crypto_digest_update(ctxp, &d1, NULL);
if (rv != CRYPTO_SUCCESS) {
KRB5_LOG(KRB5_ERR,
"crypto_digest_update error: %0x", rv);
crypto_cancel_ctx(ctxp);
return (rv);
}
}
rv = crypto_digest_final(ctxp, &d2, NULL);
/*
* crypto_digest_final() internally destroys the context. So, we
* do not use the context any more. This means we do not call
* crypto_cancel_ctx() for the failure case here unlike the failure
* case of crypto_digest_update() where we do.
*/
if (rv != CRYPTO_SUCCESS) {
KRB5_LOG(KRB5_ERR, "crypto_digest_final error: %0x", rv);
}
return (rv);
}
int
k5_ef_mac(krb5_context context,
krb5_keyblock *key,
krb5_data *ivec,
const krb5_data *input,
krb5_data *output)
{
int rv;
iovec_t v1, v2;
crypto_data_t d1, d2;
crypto_mechanism_t mech;
KRB5_LOG0(KRB5_INFO, "k5_ef_mac() start");
ASSERT(input != NULL);
ASSERT(ivec != NULL);
ASSERT(output != NULL);
v2.iov_base = (void *)output->data;
v2.iov_len = output->length;
bzero(&d1, sizeof (d1));
bzero(&d2, sizeof (d2));
d2.cd_format = CRYPTO_DATA_RAW;
d2.cd_offset = 0;
d2.cd_length = output->length;
d2.cd_raw = v2;
mech.cm_type = context->kef_hash_mt;
if (mech.cm_type == CRYPTO_MECH_INVALID) {
KRB5_LOG(KRB5_ERR,
"k5_ef_mac() invalid mech specified: 0x%llx",
(long long)context->kef_hash_mt);
return (CRYPTO_FAILED);
}
mech.cm_param = ivec->data;
mech.cm_param_len = ivec->length;
v1.iov_base = (void *)input->data;
v1.iov_len = input->length;
d1.cd_format = CRYPTO_DATA_RAW;
d1.cd_offset = 0;
d1.cd_length = input->length;
d1.cd_raw = v1;
rv = crypto_mac(&mech, &d1, &key->kef_key, key->key_tmpl, &d2, NULL);
if (rv != CRYPTO_SUCCESS) {
KRB5_LOG(KRB5_ERR,
"k5_ef_mac(): crypto_mac error: %0x", rv);
}
return (rv);
}
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* 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.
*/
/* Solaris Kerberos:
* this code is based on the
* usr/src/lib/gss_mechs/mech_krb5/crypto/hash_provider/hash_md5.c
* file, but has been modified to use the Solaris resident md5.o kernel
* module and associated header /usr/include/sys/md5.o.
* This means that the MD5* functions are called instead of krb5_MD5*.
*/
#include <k5-int.h>
#include <hash_provider.h>
#include <sys/crypto/api.h>
static krb5_error_code
k5_md5_hash(krb5_context context,
unsigned int icount, krb5_const krb5_data *input,
krb5_data *output)
{
if (output->length != MD5_CKSUM_LENGTH)
return(KRB5_CRYPTO_INTERNAL);
if (k5_ef_hash(context, icount, input, output))
return(KRB5_KEF_ERROR);
return(0);
}
const struct krb5_hash_provider krb5int_hash_md5 = {
MD5_CKSUM_LENGTH,
64,
k5_md5_hash
};
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* 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.
*/
/* Solaris Kerberos:
* this code is based on the
* usr/src/lib/gss_mechs/mech_krb5/crypto/hash_provider/hash_sha1.c
* file, but has been modified to use the Solaris resident sha1.o kernel
* module and associated header /usr/include/sys/sha1.h.
* This means that the SHA1* functions are called instead of shs*.
*/
#include <k5-int.h>
#include <hash_provider.h>
#include <sys/crypto/api.h>
static krb5_error_code
k5_sha1_hash(krb5_context context,
unsigned int icount, krb5_const krb5_data *input,
krb5_data *output)
{
krb5_error_code ret = 0;
KRB5_LOG0(KRB5_INFO, "k5_sha1_hash() start");
if (output->length != SHS_DIGESTSIZE) {
KRB5_LOG1(KRB5_ERR, "k5_sha1_hash() end error "
"output->length(%d) != SHS_DIGESTSIZE(%d)",
output->length, SHS_DIGESTSIZE);
return(KRB5_CRYPTO_INTERNAL);
}
if (k5_ef_hash(context, icount, input, output))
ret = KRB5_KEF_ERROR;
KRB5_LOG0(KRB5_INFO, "k5_sha1_hash() end");
return(ret);
}
const struct krb5_hash_provider krb5int_hash_sha1 = {
SHS_DIGESTSIZE,
SHS_DATASIZE,
k5_sha1_hash
};
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* 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 "k5-int.h"
/* Solaris Kerberos */
#ifdef _KERNEL
/*
* In kernel, use the Kernel encryption framework HMAC
* operation, its far more efficient than the MIT method.
* Also, a template is used to further improve performance.
*/
/* ARGSUSED */
krb5_error_code
krb5_hmac(krb5_context context, const krb5_keyblock *key,
krb5_const krb5_data *input, krb5_data *output)
{
int rv = CRYPTO_FAILED;
crypto_mechanism_t mac_mech;
crypto_data_t dd;
crypto_data_t mac;
KRB5_LOG0(KRB5_INFO, "krb5_hmac() start");
if (output == NULL || output->data == NULL) {
KRB5_LOG0(KRB5_INFO, "krb5_hmac() NULL output");
return (rv);
}
if (input == NULL || input->data == NULL) {
KRB5_LOG0(KRB5_INFO, "krb5_hmac() NULL input");
return (rv);
}
dd.cd_format = CRYPTO_DATA_RAW;
dd.cd_offset = 0;
dd.cd_length = input->length;
dd.cd_raw.iov_base = (char *)input->data;
dd.cd_raw.iov_len = input->length;
mac.cd_format = CRYPTO_DATA_RAW;
mac.cd_offset = 0;
mac.cd_length = output->length;
mac.cd_raw.iov_base = (char *)output->data;
mac.cd_raw.iov_len = output->length;
mac_mech.cm_type = context->kef_hash_mt;
mac_mech.cm_param = NULL;
mac_mech.cm_param_len = 0;
rv = crypto_mac(&mac_mech, &dd,
(crypto_key_t *)&key->kef_key,
key->key_tmpl, &mac, NULL);
if (rv != CRYPTO_SUCCESS) {
KRB5_LOG(KRB5_ERR,"crypto_mac error: %0x", rv);
}
KRB5_LOG(KRB5_INFO, "krb5_hmac() end ret=%d\n", rv);
return(rv);
}
#else
/* Userland implementation of HMAC algorithm */
/*
* the HMAC transform looks like:
*
* H(K XOR opad, H(K XOR ipad, text))
*
* where H is a cryptographic hash
* K is an n byte key
* ipad is the byte 0x36 repeated blocksize times
* opad is the byte 0x5c repeated blocksize times
* and text is the data being protected
*/
krb5_error_code
krb5_hmac(krb5_context context,
krb5_const struct krb5_hash_provider *hash,
krb5_const krb5_keyblock *key,
krb5_const unsigned int icount,
krb5_const krb5_data *input,
krb5_data *output)
{
size_t hashsize, blocksize;
unsigned char *xorkey, *ihash;
int i;
krb5_data *hashin, hashout;
krb5_error_code ret;
/* Solaris Kerberos */
KRB5_LOG0(KRB5_INFO, "krb5_hmac() start\n");
if (hash == NULL) {
KRB5_LOG0(KRB5_ERR, "krb5_hmac() error hash == NULL\n");
return(EINVAL);
}
if (key == NULL) {
KRB5_LOG0(KRB5_ERR, "krb5_hmac() error key == NULL\n");
return(EINVAL);
}
if (input == NULL) {
KRB5_LOG0(KRB5_ERR, "krb5_hmac() error input == NULL\n");
return(EINVAL);
}
if (output == NULL) {
KRB5_LOG0(KRB5_ERR, "krb5_hmac() error output == NULL\n");
return(EINVAL);
}
hashsize = hash->hashsize;
blocksize = hash->blocksize;
if (key->length > blocksize)
return(KRB5_CRYPTO_INTERNAL);
if (output->length < hashsize)
return(KRB5_BAD_MSIZE);
/* if this isn't > 0, then there won't be enough space in this
array to compute the outer hash */
if (icount == 0)
return(KRB5_CRYPTO_INTERNAL);
/* allocate space for the xor key, hash input vector, and inner hash */
if ((xorkey = (unsigned char *) MALLOC(blocksize)) == NULL)
return(ENOMEM);
if ((ihash = (unsigned char *) MALLOC(hashsize)) == NULL) {
FREE(xorkey, blocksize);
return(ENOMEM);
}
if ((hashin = (krb5_data *)MALLOC(sizeof(krb5_data)*(icount+1))) == NULL) {
FREE(ihash, hashsize);
FREE(xorkey, blocksize);
return(ENOMEM);
}
/* create the inner padded key */
/* Solaris Kerberos */
(void) memset(xorkey, 0x36, blocksize);
for (i=0; i<key->length; i++)
xorkey[i] ^= key->contents[i];
/* compute the inner hash */
for (i=0; i<icount; i++) {
hashin[0].length = blocksize;
hashin[0].data = (char *) xorkey;
hashin[i+1] = input[i];
}
hashout.length = hashsize;
hashout.data = (char *) ihash;
/* Solaris Kerberos */
if ((ret = ((*(hash->hash))(context, icount+1, hashin, &hashout))))
goto cleanup;
/* create the outer padded key */
/* Solaris Kerberos */
(void) memset(xorkey, 0x5c, blocksize);
for (i=0; i<key->length; i++)
xorkey[i] ^= key->contents[i];
/* compute the outer hash */
hashin[0].length = blocksize;
hashin[0].data = (char *) xorkey;
hashin[1] = hashout;
output->length = hashsize;
/* Solaris Kerberos */
if ((ret = ((*(hash->hash))(context, 2, hashin, output))))
(void) memset(output->data, 0, output->length);
/* ret is set correctly by the prior call */
cleanup:
/* Solaris Kerberos */
(void) memset(xorkey, 0, blocksize);
(void) memset(ihash, 0, hashsize);
FREE(hashin, sizeof(krb5_data)*(icount+1));
FREE(ihash, hashsize);
FREE(xorkey, blocksize);
/* Solaris Kerberos */
KRB5_LOG(KRB5_INFO, "krb5_hmac() end ret=%d\n", ret);
return(ret);
}
#endif /* _KERNEL */
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* 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 "k5-int.h"
#include "des_int.h"
#include "keyhash_provider.h"
#ifdef _KERNEL
#include <sys/kmem.h>
#include <sys/crypto/api.h>
#endif
/*ARGSUSED*/
static krb5_error_code
k5_descbc_hash(krb5_context context,
krb5_const krb5_keyblock *key,
krb5_keyusage usage,
krb5_const krb5_data *ivec,
krb5_const krb5_data *input, krb5_data *output)
{
int ret;
krb5_data zero_ivec;
if (key->length != MIT_DES_KEYSIZE)
return(KRB5_BAD_KEYSIZE);
if ((input->length%8) != 0)
return(KRB5_BAD_MSIZE);
if (ivec && (ivec->length != MIT_DES_BLOCK_LENGTH))
return(KRB5_CRYPTO_INTERNAL);
if (output->length != MIT_DES_BLOCK_LENGTH)
return(KRB5_CRYPTO_INTERNAL);
zero_ivec.data = (char *)mit_des_zeroblock;
zero_ivec.length = sizeof(mit_des_zeroblock);
ret = k5_ef_mac(context, (krb5_keyblock *)key,
ivec ? (krb5_data *)ivec : &zero_ivec, input, output);
return(ret);
}
const struct krb5_keyhash_provider krb5int_keyhash_descbc = {
MIT_DES_BLOCK_LENGTH,
k5_descbc_hash,
NULL
};
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* 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.
*/
/* Solaris Kerberos:
* this code is based on the
* usr/src/lib/gss_mechs/mech_krb5/crypto/keyhash_provider/k5_md5des.c
* file, but has been modified to use the Solaris resident md5.o kernel
* module and associated header /usr/include/sys/md5.o.
* This means that the MD5* functions are called instead of krb5_MD5*.
*/
#include <des_int.h>
#include <krb5.h>
#include <keyhash_provider.h>
#include <sys/kmem.h>
#include <sys/crypto/api.h>
#define CONFLENGTH 8
/* Force acceptance of krb5-beta5 md5des checksum for now. */
#define KRB5_MD5DES_BETA5_COMPAT
/* des-cbc(xorkey, conf | rsa-md5(conf | data)) */
/* this could be done in terms of the md5 and des providers, but
that's less efficient, and there's no need for this to be generic */
/*ARGSUSED*/
static krb5_error_code
k5_md5des_hash(krb5_context context,
krb5_const krb5_keyblock *key,
krb5_keyusage usage,
krb5_const krb5_data *ivec,
krb5_const krb5_data *input, krb5_data *output)
{
krb5_error_code ret = 0;
krb5_data data;
unsigned char conf[CONFLENGTH];
unsigned char xorkey[MIT_DES_KEYSIZE];
int i;
krb5_data *hash_input;
char *outptr;
krb5_keyblock newkey;
if (key->length != MIT_DES_KEYSIZE)
return(KRB5_BAD_KEYSIZE);
if (ivec)
return(KRB5_CRYPTO_INTERNAL);
if (output->length != (CONFLENGTH + MD5_CKSUM_LENGTH))
return(KRB5_CRYPTO_INTERNAL);
/* create the confounder */
data.length = CONFLENGTH;
data.data = (char *) conf;
if ((ret = krb5_c_random_make_octets(context, &data)))
return(ret);
/* hash the confounder, then the input data */
hash_input = (krb5_data *)MALLOC(sizeof(krb5_data) * 2);
if (hash_input == NULL)
return(KRB5_RC_MALLOC);
hash_input[0].data = (char *)conf;
hash_input[0].length = CONFLENGTH;
hash_input[1].data = input->data;
hash_input[1].length = input->length;
/* Save the pointer to the beginning of the output buffer */
outptr = (char *)output->data;
/*
* Move the output ptr ahead so we can write the hash
* digest directly into the buffer.
*/
output->data = output->data + CONFLENGTH;
/* Use generic hash function that calls to kEF */
if (k5_ef_hash(context, 2, hash_input, output)) {
FREE(hash_input, sizeof(krb5_data) * 2);
return(KRB5_KEF_ERROR);
}
/* restore the original ptr to the output data */
output->data = outptr;
/*
* Put the confounder in the beginning of the buffer to be
* encrypted.
*/
bcopy(conf, output->data, CONFLENGTH);
bcopy(key->contents, xorkey, sizeof(xorkey));
for (i=0; i<sizeof(xorkey); i++)
xorkey[i] ^= 0xf0;
/*
* Solaris Kerberos:
* Encryption Framework checks for parity and weak keys.
*/
bzero(&newkey, sizeof(krb5_keyblock));
newkey.enctype = key->enctype;
newkey.contents = xorkey;
newkey.length = sizeof(xorkey);
newkey.dk_list = NULL;
newkey.kef_key.ck_data = NULL;
ret = init_key_kef(context->kef_cipher_mt, &newkey);
if (ret) {
FREE(hash_input, sizeof(krb5_data) * 2);
return (ret);
}
/* encrypt it, in place. this has a return value, but it's
always zero. */
ret = mit_des_cbc_encrypt(context, (krb5_pointer) output->data,
(krb5_pointer) output->data, output->length,
&newkey, (unsigned char*) mit_des_zeroblock, 1);
FREE(hash_input, sizeof(krb5_data) * 2);
(void)crypto_destroy_ctx_template(newkey.key_tmpl);
return(ret);
}
/*ARGSUSED*/
static krb5_error_code
k5_md5des_verify(krb5_context context,
krb5_const krb5_keyblock *key,
krb5_keyusage usage,
krb5_const krb5_data *ivec,
krb5_const krb5_data *input,
krb5_const krb5_data *hash,
krb5_boolean *valid)
{
krb5_error_code ret = 0;
unsigned char plaintext[CONFLENGTH + MD5_CKSUM_LENGTH];
unsigned char xorkey[8];
int i;
int compathash = 0;
krb5_octet outtmp[MD5_CKSUM_LENGTH];
size_t hisize;
krb5_data *hash_input;
krb5_data hash_output;
krb5_keyblock newkey;
if (key->length != MIT_DES_KEYSIZE)
return(KRB5_BAD_KEYSIZE);
if (ivec)
return(KRB5_CRYPTO_INTERNAL);
if (hash->length != (CONFLENGTH + MD5_CKSUM_LENGTH)) {
#ifdef KRB5_MD5DES_BETA5_COMPAT
if (hash->length != MD5_CKSUM_LENGTH)
return(KRB5_CRYPTO_INTERNAL);
else
compathash = 1;
#else
return(KRB5_CRYPTO_INTERNAL);
#endif
}
/* create and schedule the encryption key */
(void) bcopy(key->contents, xorkey, sizeof(xorkey));
if (!compathash) {
for (i=0; i<sizeof(xorkey); i++)
xorkey[i] ^= 0xf0;
}
/*
* Solaris Kerberos:
* Encryption Framework checks for parity and weak keys
*/
bzero(&newkey, sizeof(krb5_keyblock));
newkey.enctype = key->enctype;
newkey.contents = xorkey;
newkey.length = sizeof(xorkey);
newkey.dk_list = NULL;
newkey.kef_key.ck_data = NULL;
ret = init_key_kef(context->kef_cipher_mt, &newkey);
/* decrypt it. this has a return value, but it's always zero. */
if (!compathash) {
ret = mit_des_cbc_encrypt(context, (krb5_pointer) hash->data,
(krb5_pointer) plaintext, hash->length,
&newkey, (unsigned char*) mit_des_zeroblock, 0);
} else {
ret = mit_des_cbc_encrypt(context, (krb5_pointer) hash->data,
(krb5_pointer) plaintext, hash->length,
&newkey, xorkey, 0);
}
if (ret) goto cleanup;
/* hash the confounder, then the input data */
i = 1;
if (!compathash)
i++;
hisize = sizeof(krb5_data) * i;
hash_input = (krb5_data *)MALLOC(hisize);
if (hash_input == NULL)
return(KRB5_RC_MALLOC);
i=0;
if (!compathash) {
hash_input[i].data = (char *)plaintext;
hash_input[i].length = CONFLENGTH;
i++;
}
hash_input[i].data = input->data;
hash_input[i].length = input->length;
hash_output.data = (char *)outtmp;
hash_output.length = sizeof(outtmp);
if (k5_ef_hash(context, 1, hash_input, &hash_output)) {
ret = KRB5_KEF_ERROR;
goto cleanup;
}
/* compare the decrypted hash to the computed one */
if (!compathash) {
*valid = !bcmp((const void *)(plaintext+CONFLENGTH),
(void *)outtmp, MD5_CKSUM_LENGTH);
} else {
*valid = !bcmp((const void *)plaintext,
(void *)outtmp, MD5_CKSUM_LENGTH);
}
bzero((void *)plaintext, sizeof(plaintext));
cleanup:
if (hash_input != NULL && hisize > 0)
FREE(hash_input, hisize);
(void)crypto_destroy_ctx_template(newkey.key_tmpl);
return(ret);
}
const struct krb5_keyhash_provider krb5int_keyhash_md5des = {
CONFLENGTH+MD5_CKSUM_LENGTH,
k5_md5des_hash,
k5_md5des_verify
};
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* lib/crypto/keyhash_provider/hmac_md5.c
*
(I don't know)
.
* Copyright2001 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.
*
*
* Implementation of the Microsoft hmac-md5 checksum type.
* Implemented based on draft-brezak-win2k-krb-rc4-hmac-03
*/
#include <k5-int.h>
#include <etypes.h>
#include <keyhash_provider.h>
#include <arcfour.h>
#include <hash_provider.h>
/*ARGSUSED*/
static krb5_error_code
k5_hmac_md5_hash (krb5_context context,
const krb5_keyblock *key, krb5_keyusage usage,
const krb5_data *iv,
const krb5_data *input, krb5_data *output)
{
krb5_keyusage ms_usage;
krb5_error_code ret;
krb5_keyblock ks;
krb5_data ds, ks_constant, md5tmp;
krb5_data hash_input[2];
int i;
char t[4], outbuf[MD5_CKSUM_LENGTH];
#ifdef _KERNEL
KRB5_LOG1(KRB5_INFO, "k5_hmac_md5_hash() hash_mt = %ld cipher_mt = %ld",
(ulong_t) context->kef_hash_mt,
(ulong_t) context->kef_cipher_mt);
#endif
for (i=0; i<krb5_enctypes_length; i++) {
if (krb5_enctypes_list[i].etype == key->enctype)
break;
}
if (i == krb5_enctypes_length) {
KRB5_LOG(KRB5_ERR, "krb5_ck_make_checksum bad enctype: %d",
key->enctype);
return(KRB5_BAD_ENCTYPE);
}
bzero(&ks, sizeof(krb5_keyblock));
/*
* Solaris Kerberos: The digest length is that of MD5_CKSUM_LENGTH not the key
* length, as keys can be of varying lengths but should not affect the digest
* length. The signing key is the digest and therefore is also the same
* length, MD5_CKSUM_LENGTH.
*/
ds.length = MD5_CKSUM_LENGTH;
ds.data = MALLOC(ds.length);
if (ds.data == NULL)
return (ENOMEM);
ks.contents = (void *) ds.data;
ks.length = MD5_CKSUM_LENGTH;
#ifdef _KERNEL
if (key->kef_key.ck_data == NULL) {
ret = init_key_kef(krb5_enctypes_list[i].kef_cipher_mt,
(krb5_keyblock *)key);
if (ret)
goto cleanup;
}
ret = init_key_kef(krb5_enctypes_list[i].kef_cipher_mt, &ks);
if (ret)
goto cleanup;
#endif /* _KERNEL */
ks_constant.data = "signaturekey";
ks_constant.length = strlen(ks_constant.data)+1; /* Including null*/
#ifdef _KERNEL
ret = krb5_hmac(context, (krb5_keyblock *)key, &ks_constant, &ds);
#else
ret = krb5_hmac(context, &krb5int_hash_md5, key, 1, &ks_constant, &ds);
#endif /* _KERNEL */
if (ret)
goto cleanup;
ms_usage = krb5int_arcfour_translate_usage (usage);
t[0] = (ms_usage) & 0xff;
t[1] = (ms_usage>>8) & 0xff;
t[2] = (ms_usage >>16) & 0xff;
t[3] = (ms_usage>>24) & 0XFF;
hash_input[0].data = (char *)&t;
hash_input[0].length = 4;
hash_input[1].data = input->data;
hash_input[1].length = input->length;
md5tmp.data = (void *)outbuf;
md5tmp.length = sizeof(outbuf);
/* Use generic hash function that calls to kEF */
if (k5_ef_hash(context, 2, hash_input, &md5tmp)) {
return (KRB5_KEF_ERROR);
}
#ifdef _KERNEL
ret = krb5_hmac (context, &ks, &md5tmp, output);
#else
ret = krb5_hmac (context, &krb5int_hash_md5, &ks, 1, &md5tmp, output);
#endif /* _KERNEL */
cleanup:
bzero(md5tmp.data, md5tmp.length);
bzero(ks.contents, ks.length);
FREE (ks.contents, ks.length);
return (ret);
}
const struct krb5_keyhash_provider
krb5int_keyhash_hmac_md5 = {
MD5_CKSUM_LENGTH,
k5_hmac_md5_hash,
NULL /*checksum again*/
};
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* Copyright 2025 RackTop Systems, Inc.
*/
/*
* 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 "k5-int.h"
#include "cksumtypes.h"
#include "etypes.h"
#include "dk.h"
krb5_error_code KRB5_CALLCONV
krb5_c_make_checksum(krb5_context context, krb5_cksumtype cksumtype,
const krb5_keyblock *key, krb5_keyusage usage,
const krb5_data *input, krb5_checksum *cksum)
{
int i, e1, e2;
krb5_data data;
krb5_error_code ret = 0;
size_t cksumlen;
KRB5_LOG0(KRB5_INFO, "krb5_c_make_checksum() start.");
for (i=0; i<krb5_cksumtypes_length; i++) {
if (krb5_cksumtypes_list[i].ctype == cksumtype)
break;
}
if (i == krb5_cksumtypes_length)
return(KRB5_BAD_ENCTYPE);
if (krb5_cksumtypes_list[i].keyhash)
cksumlen = krb5_cksumtypes_list[i].keyhash->hashsize;
else
cksumlen = krb5_cksumtypes_list[i].hash->hashsize;
#ifdef _KERNEL
context->kef_cksum_mt = krb5_cksumtypes_list[i].kef_cksum_mt;
#endif
cksum->length = cksumlen;
if ((cksum->contents = (krb5_octet *) MALLOC(cksum->length)) == NULL) {
cksum->length = 0;
return(ENOMEM);
}
data.length = cksum->length;
data.data = (char *) cksum->contents;
if (krb5_cksumtypes_list[i].keyhash) {
/* check if key is compatible */
if (krb5_cksumtypes_list[i].keyed_etype) {
for (e1=0; e1<krb5_enctypes_length; e1++)
if (krb5_enctypes_list[e1].etype ==
krb5_cksumtypes_list[i].keyed_etype)
break;
for (e2=0; e2<krb5_enctypes_length; e2++)
if (krb5_enctypes_list[e2].etype == key->enctype)
break;
/*
* Solaris Kerberos: The actual key encryption type could be
* arbitrary, so the checksum enc type doesn't need to be the same.
*/
if ((e1 == krb5_enctypes_length) || (e2 == krb5_enctypes_length)) {
ret = KRB5_BAD_ENCTYPE;
goto cleanup;
}
}
#ifdef _KERNEL
context->kef_cipher_mt = krb5_enctypes_list[e1].kef_cipher_mt;
context->kef_hash_mt = krb5_enctypes_list[e1].kef_hash_mt;
if (key->kef_key.ck_data == NULL) {
if ((ret = init_key_kef(context->kef_cipher_mt,
(krb5_keyblock *)key)))
goto cleanup;
}
#else
if ((ret = init_key_uef(krb_ctx_hSession(context), (krb5_keyblock *)key)))
goto cleanup;
#endif /* _KERNEL */
ret = (*(krb5_cksumtypes_list[i].keyhash->hash))(context, key,
usage, 0, input, &data);
} else if (krb5_cksumtypes_list[i].flags & KRB5_CKSUMFLAG_DERIVE) {
#ifdef _KERNEL
context->kef_cipher_mt = get_cipher_mech_type(context,
(krb5_keyblock *)key);
context->kef_hash_mt = get_hash_mech_type(context,
(krb5_keyblock *)key);
/*
* If the hash_mt is invalid, try using the cksum_mt
* because "hash" and "checksum" are overloaded terms
* in some places.
*/
if (context->kef_hash_mt == CRYPTO_MECH_INVALID)
context->kef_hash_mt = context->kef_cksum_mt;
#else
ret = init_key_uef(krb_ctx_hSession(context), (krb5_keyblock *)key);
if (ret)
goto cleanup;
#endif /* _KERNEL */
ret = krb5_dk_make_checksum(context,
krb5_cksumtypes_list[i].hash,
key, usage, input, &data);
} else {
/*
* No key is used, hash and cksum are synonymous
* in this case
*/
#ifdef _KERNEL
context->kef_hash_mt = context->kef_cksum_mt;
#endif /* _KERNEL */
ret = (*(krb5_cksumtypes_list[i].hash->hash))(context, 1,
input, &data);
}
if (!ret) {
cksum->magic = KV5M_CHECKSUM;
cksum->checksum_type = cksumtype;
if (krb5_cksumtypes_list[i].trunc_size) {
krb5_octet *trunc;
size_t old_len = cksum->length;
/*
* Solaris Kerberos:
* The Kernel does not like 'realloc' (which is what
* MIT code does here), so we do our own "realloc".
*/
cksum->length = krb5_cksumtypes_list[i].trunc_size;
trunc = (krb5_octet *) MALLOC(cksum->length);
if (trunc) {
(void) memcpy(trunc, cksum->contents, cksum->length);
FREE(cksum->contents, old_len);
cksum->contents = trunc;
} else {
ret = ENOMEM;
}
}
}
cleanup:
if (ret) {
(void) memset(cksum->contents, 0, cksum->length);
FREE(cksum->contents, cksum->length);
cksum->length = 0;
cksum->contents = NULL;
}
KRB5_LOG(KRB5_INFO, "krb5_c_make_checksum() end ret = %d\n", ret);
return(ret);
}
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright (C) 2003 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.
*/
#include "k5-int.h"
#include "etypes.h"
/*ARGSUSED*/
krb5_error_code
krb5int_c_mandatory_cksumtype (krb5_context ctx, krb5_enctype etype,
krb5_cksumtype *cksumtype)
{
int i;
for (i = 0; i < krb5_enctypes_length; i++)
if (krb5_enctypes_list[i].etype == etype) {
*cksumtype = krb5_enctypes_list[i].required_ctype;
return 0;
}
return KRB5_BAD_ENCTYPE;
}
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* 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 "k5-int.h"
/*
* Solaris Kerberos defines memory management macros in <krb5.h>,
* which is included by <k5-int.h>, so we need not include <memory.h>
*/
/* #include <memory.h> */
/*
n-fold(k-bits):
l = lcm(n,k)
r = l/k
s = k-bits | k-bits rot 13 | k-bits rot 13*2 | ... | k-bits rot 13*(r-1)
compute the 1's complement sum:
n-fold = s[0..n-1]+s[n..2n-1]+s[2n..3n-1]+..+s[(k-1)*n..k*n-1]
*/
/* representation: msb first, assume n and k are multiples of 8, and
that k>=16. this is the case of all the cryptosystems which are
likely to be used. this function can be replaced if that
assumption ever fails. */
/* input length is in bits */
void
krb5_nfold(unsigned int inbits, const unsigned char *in, unsigned int outbits,
unsigned char *out)
{
int a,b,c,lcm;
int byte, i, msbit;
/* the code below is more readable if I make these bytes
instead of bits */
inbits >>= 3;
outbits >>= 3;
/* first compute lcm(n,k) */
a = outbits;
b = inbits;
while(b != 0) {
c = b;
b = a%b;
a = c;
}
lcm = outbits*inbits/a;
/* now do the real work */
(void) memset(out, 0, outbits);
byte = 0;
/* this will end up cycling through k lcm(k,n)/k times, which
is correct */
for (i=lcm-1; i>=0; i--) {
/* compute the msbit in k which gets added into this byte */
msbit = (/* first, start with the msbit in the first, unrotated
byte */
((inbits<<3)-1)
/* then, for each byte, shift to the right for each
repetition */
+(((inbits<<3)+13)*(i/inbits))
/* last, pick out the correct byte within that
shifted repetition */
+((inbits-(i%inbits))<<3)
)%(inbits<<3);
/* pull out the byte value itself */
byte += (((in[((inbits-1)-(msbit>>3))%inbits]<<8)|
(in[((inbits)-(msbit>>3))%inbits]))
>>((msbit&7)+1))&0xff;
/* do the addition */
byte += out[i%outbits];
out[i%outbits] = byte&0xff;
#if 0
printf("msbit[%d] = %d\tbyte = %02x\tsum = %03x\n", i, msbit,
(((in[((inbits-1)-(msbit>>3))%inbits]<<8)|
(in[((inbits)-(msbit>>3))%inbits]))
>>((msbit&7)+1))&0xff, byte);
#endif
/* keep around the carry bit, if any */
byte >>= 8;
#if 0
printf("carry=%d\n", byte);
#endif
}
/* if there's a carry bit left over, add it back in */
if (byte) {
for (i=outbits-1; i>=0; i--) {
/* do the addition */
byte += out[i];
out[i] = byte&0xff;
/* keep around the carry bit, if any */
byte >>= 8;
}
}
}
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* 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 "k5-int.h"
#include "old.h"
/*ARGSUSED*/
krb5_error_code
krb5_old_decrypt(krb5_context context,
const struct krb5_enc_provider *enc,
const struct krb5_hash_provider *hash,
const krb5_keyblock *key,
krb5_keyusage usage,
const krb5_data *ivec,
const krb5_data *input,
krb5_data *arg_output)
{
krb5_error_code ret;
size_t blocksize, hashsize, plainsize;
unsigned char *cn;
krb5_data output, cksum, crcivec;
int alloced;
unsigned char orig_cksum[128], new_cksum[128];
blocksize = enc->block_size;
hashsize = hash->hashsize;
/* Verify input and output lengths. */
if (input->length < blocksize + hashsize || input->length % blocksize != 0)
return(KRB5_BAD_MSIZE);
plainsize = input->length - blocksize - hashsize;
if (arg_output->length < plainsize)
return(KRB5_BAD_MSIZE);
if (arg_output->length < input->length) {
output.length = input->length;
if ((output.data = (char *) MALLOC(output.length)) == NULL) {
return(ENOMEM);
}
alloced = 1;
} else {
output.length = input->length;
output.data = arg_output->data;
alloced = 0;
}
/* decrypt it */
/* save last ciphertext block in case we decrypt in place */
if (ivec != NULL && ivec->length == blocksize) {
cn = MALLOC(blocksize);
if (cn == NULL) {
ret = ENOMEM;
goto cleanup;
}
(void) memcpy(cn, input->data + input->length - blocksize, blocksize);
} else
cn = NULL;
/* XXX this is gross, but I don't have much choice */
if ((key->enctype == ENCTYPE_DES_CBC_CRC) && (ivec == 0)) {
crcivec.length = key->length;
crcivec.data = (char *) key->contents;
ivec = &crcivec;
}
if ((ret = ((*(enc->decrypt))(context, key, ivec, input, &output))))
goto cleanup;
/* verify the checksum */
(void) memcpy(orig_cksum, output.data+blocksize, hashsize);
(void) memset(output.data+blocksize, 0, hashsize);
cksum.length = hashsize;
cksum.data = (char *)new_cksum;
if ((ret = ((*(hash->hash))(context, 1, &output, &cksum))))
goto cleanup;
if (memcmp(cksum.data, orig_cksum, cksum.length) != 0) {
ret = KRB5KRB_AP_ERR_BAD_INTEGRITY;
goto cleanup;
}
/* copy the plaintext around */
if (alloced) {
(void) memcpy(arg_output->data, output.data+blocksize+hashsize,
plainsize);
} else {
(void) memmove(arg_output->data, arg_output->data+blocksize+hashsize,
plainsize);
}
arg_output->length = plainsize;
/* update ivec */
if (cn != NULL)
(void) memcpy(ivec->data, cn, blocksize);
ret = 0;
cleanup:
if (alloced) {
(void) memset(output.data, 0, output.length);
FREE(output.data, output.length);
}
if (cn != NULL)
FREE(cn, blocksize);
(void) memset(new_cksum, 0, hashsize);
return(ret);
}
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* 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 "k5-int.h"
#include "old.h"
void
krb5_old_encrypt_length(const struct krb5_enc_provider *enc,
const struct krb5_hash_provider *hash,
size_t inputlen,
size_t *length)
{
size_t blocksize, hashsize;
blocksize = enc->block_size;
hashsize = hash->hashsize;
*length = krb5_roundup(blocksize+hashsize+inputlen, blocksize);
}
/*ARGSUSED*/
krb5_error_code
krb5_old_encrypt(krb5_context context,
const struct krb5_enc_provider *enc,
const struct krb5_hash_provider *hash,
const krb5_keyblock *key,
krb5_keyusage usage,
const krb5_data *ivec,
const krb5_data *input,
krb5_data *output)
{
krb5_error_code ret;
size_t blocksize, hashsize, enclen;
krb5_data datain, crcivec;
int real_ivec;
blocksize = enc->block_size;
hashsize = hash->hashsize;
krb5_old_encrypt_length(enc, hash, input->length, &enclen);
if (output->length < enclen)
return(KRB5_BAD_MSIZE);
output->length = enclen;
/* fill in confounded, padded, plaintext buffer with zero checksum */
(void) memset(output->data, 0, output->length);
datain.length = blocksize;
datain.data = (char *) output->data;
if ((ret = krb5_c_random_make_octets(context, &datain)))
return(ret);
(void) memcpy(output->data+blocksize+hashsize, input->data, input->length);
/* compute the checksum */
datain.length = hashsize;
datain.data = output->data+blocksize;
if ((ret = ((*(hash->hash))(context, 1, output, &datain))))
goto cleanup;
/* encrypt it */
/* XXX this is gross, but I don't have much choice */
if ((key->enctype == ENCTYPE_DES_CBC_CRC) && (ivec == 0)) {
crcivec.length = key->length;
crcivec.data = (char *) key->contents;
ivec = &crcivec;
real_ivec = 0;
} else
real_ivec = 1;
if ((ret = ((*(enc->encrypt))(context, key, ivec, output, output))))
goto cleanup;
/* update ivec */
if (real_ivec && ivec != NULL && ivec->length == blocksize)
(void) memcpy(ivec->data, output->data + output->length - blocksize,
blocksize);
cleanup:
if (ret)
(void) memset(output->data, 0, output->length);
return(ret);
}
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* 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.
*/
#include <k5-int.h>
#ifdef _KERNEL
#include <sys/random.h>
#endif
#ifndef _KERNEL
/*
* Solaris kerberos: we don't need a random number generator
* for the /dev/[u]random, as it uses entropy in the kernel.
* Keep this function as some apps might call it directly.
*/
/*ARGSUSED*/
krb5_error_code KRB5_CALLCONV
krb5_c_random_seed(krb5_context context, krb5_data *data)
{
/*
* We can't do much if this fails, so ignore the
* return code. /dev/urandom has its own entropy
* source, so seeding it from here is of questionable
* value in the first place.
*/
(void) C_SeedRandom(krb_ctx_hSession(context),
(CK_BYTE_PTR)data->data,
(CK_ULONG)data->length);
return(0);
}
#endif /* !_KERNEL */
/*
* krb5_get_random_octets
* New for Solaris 9. This routine takes advantage of the new
* /dev/[u]random interface provided in Solaris 9 for getting random
* bytes generated from the kernel. The entropy produced there is generally
* considered better than the current MIT PRNG code that we are replacing.
*
* This func is visible so that it can be used to generate a
* random confounder.
*/
#ifndef _KERNEL
#endif /* ! _KERNEL */
/*
* We can assume that the memory for data is already malloc'd.
* Return an error if there is an error, but don't clear the data->length
* or free data->data. This will be done by the calling function.
*/
/*ARGSUSED*/
krb5_error_code KRB5_CALLCONV
krb5_c_random_make_octets(krb5_context context, krb5_data *data)
{
/*
* Solaris kerberos uses /dev/[u]random
*/
#ifndef _KERNEL /* User space code */
krb5_error_code err = 0;
CK_RV rv;
KRB5_LOG0(KRB5_INFO, "krb5_c_random_make_octets() start, user space using "
"krb5_get_random_octets()\n");
rv = C_GenerateRandom(krb_ctx_hSession(context), (CK_BYTE_PTR)data->data,
(CK_ULONG)data->length);
if (rv != CKR_OK) {
KRB5_LOG(KRB5_ERR, "C_GenerateRandom failed in "
"krb5_c_random_make_octets: rv = 0x%x.", rv);
err = PKCS_ERR;
}
if (err != 0) {
KRB5_LOG0(KRB5_ERR, "krb5_c_random_make_octets() end, error");
return (err);
}
#else /* Kernel code section */
/*
* Solaris Kerberos: for kernel code we use the randomness generator native
* to Solaris 9. We avoid global variables and other nastiness this way.
*
* Using random_get_pseudo_bytes() instead of random_get_bytes() because it
* will not return an error code if there isn't enough entropy but will use
* a pseudo random algorithm to produce randomness. Most of the time it
* should be as good as random_get_bytes() and we don't have to worry about
* dealing with a non-fatal error.
*/
KRB5_LOG0(KRB5_INFO, "krb5_c_random_make_octets() start, kernel using "
"random_get_pseudo_bytes()\n ");
if(random_get_pseudo_bytes((uint8_t *)data->data, data->length) != 0) {
KRB5_LOG0(KRB5_ERR, "krb5_c_random_make_octets() end, "
"random_get_pseudo_bytes() error.\n");
return(KRB5_CRYPTO_INTERNAL);
}
#endif /* !_KERNEL */
KRB5_LOG0(KRB5_INFO, "krb5_c_random_make_octets() end\n");
return(0);
}
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* 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 "k5-int.h"
#include "raw.h"
/*ARGSUSED*/
krb5_error_code
krb5_raw_decrypt(krb5_context context,
const struct krb5_enc_provider *enc,
const struct krb5_hash_provider *hash,
const krb5_keyblock *key, krb5_keyusage usage,
const krb5_data *ivec, const krb5_data *input,
krb5_data *output)
{
if (output->length < input->length)
return KRB5_BAD_MSIZE;
return((*(enc->decrypt))(context, key, ivec, input, output));
}
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* 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 "k5-int.h"
#include "raw.h"
/*ARGSUSED*/
void
krb5_raw_encrypt_length(const struct krb5_enc_provider *enc,
const struct krb5_hash_provider *hash,
size_t inputlen, size_t *length)
{
size_t blocksize;
blocksize = enc->block_size;
*length = krb5_roundup(inputlen, blocksize);
}
/*ARGSUSED*/
krb5_error_code
krb5_raw_encrypt(krb5_context context,
const struct krb5_enc_provider *enc,
const struct krb5_hash_provider *hash,
const krb5_keyblock *key, krb5_keyusage usage,
const krb5_data *ivec, const krb5_data *input,
krb5_data *output)
{
return((*(enc->encrypt))(context, key, ivec, input, output));
}
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* 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 "k5-int.h"
#include "cksumtypes.h"
krb5_error_code KRB5_CALLCONV
krb5_c_verify_checksum(krb5_context context, const krb5_keyblock *key,
krb5_keyusage usage, const krb5_data *data,
const krb5_checksum *cksum, krb5_boolean *valid)
{
int i;
size_t hashsize;
krb5_error_code ret;
krb5_data indata;
krb5_checksum computed;
for (i=0; i<krb5_cksumtypes_length; i++) {
if (krb5_cksumtypes_list[i].ctype == cksum->checksum_type)
break;
}
if (i == krb5_cksumtypes_length)
return(KRB5_BAD_ENCTYPE);
/* if there's actually a verify function, call it */
indata.length = cksum->length;
indata.data = (char *) cksum->contents;
*valid = 0;
if (krb5_cksumtypes_list[i].keyhash &&
krb5_cksumtypes_list[i].keyhash->verify)
return((*(krb5_cksumtypes_list[i].keyhash->verify))(
context, key, usage, 0, data, &indata, valid));
/* otherwise, make the checksum again, and compare */
if ((ret = krb5_c_checksum_length(context, cksum->checksum_type, &hashsize)))
return(ret);
if (cksum->length != hashsize)
return(KRB5_BAD_MSIZE);
computed.length = hashsize;
if ((ret = krb5_c_make_checksum(context, cksum->checksum_type, key, usage,
data, &computed))) {
FREE(computed.contents, computed.length);
return(ret);
}
*valid = (memcmp(computed.contents, cksum->contents, hashsize) == 0);
FREE(computed.contents, computed.length);
return(0);
}
extern krb5_error_code
krb5int_aes_string_to_key (krb5_context context, const struct krb5_enc_provider *,
const krb5_data *, const krb5_data *,
const krb5_data *, krb5_keyblock *key);
/*
* Copyright 2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef ARCFOUR_H
#define ARCFOUR_H
#define CONFOUNDERLENGTH 8
extern void
krb5_arcfour_encrypt_length(const struct krb5_enc_provider *,
const struct krb5_hash_provider *,
size_t,
size_t *);
extern
krb5_error_code krb5_arcfour_encrypt(krb5_context,
const struct krb5_enc_provider *,
const struct krb5_hash_provider *,
const krb5_keyblock *,
krb5_keyusage,
const krb5_data *,
const krb5_data *,
krb5_data *);
extern
krb5_error_code krb5_arcfour_decrypt(krb5_context,
const struct krb5_enc_provider *,
const struct krb5_hash_provider *,
const krb5_keyblock *,
krb5_keyusage,
const krb5_data *,
const krb5_data *,
krb5_data *);
#ifndef _KERNEL
extern krb5_error_code krb5int_arcfour_string_to_key(
krb5_context,
const struct krb5_enc_provider *,
const krb5_data *,
const krb5_data *,
const krb5_data *,
krb5_keyblock *);
#endif /* _KERNEL */
extern const struct krb5_enc_provider krb5int_enc_arcfour;
krb5_keyusage krb5int_arcfour_translate_usage(krb5_keyusage usage);
#endif /* ARCFOUR_H */
#ifndef KRB5_AUTH_CONTEXT
#define KRB5_AUTH_CONTEXT
struct _krb5_auth_context {
krb5_magic magic;
krb5_address * remote_addr;
krb5_address * remote_port;
krb5_address * local_addr;
krb5_address * local_port;
krb5_keyblock * keyblock;
krb5_keyblock * send_subkey;
krb5_keyblock * recv_subkey;
krb5_int32 auth_context_flags;
krb5_ui_4 remote_seq_number;
krb5_ui_4 local_seq_number;
krb5_authenticator *authentp; /* mk_req, rd_req, mk_rep, ...*/
krb5_cksumtype req_cksumtype; /* mk_safe, ... */
krb5_cksumtype safe_cksumtype; /* mk_safe, ... */
krb5_pointer i_vector; /* mk_priv, rd_priv only */
krb5_rcache rcache;
krb5_enctype * permitted_etypes; /* rd_req */
krb5_mk_req_checksum_func checksum_func;
void *checksum_func_data;
};
/* Internal auth_context_flags */
#define KRB5_AUTH_CONN_INITIALIZED 0x00010000
#define KRB5_AUTH_CONN_USED_W_MK_REQ 0x00020000
#define KRB5_AUTH_CONN_USED_W_RD_REQ 0x00040000
#define KRB5_AUTH_CONN_SANE_SEQ 0x00080000
#define KRB5_AUTH_CONN_HEIMDAL_SEQ 0x00100000
#endif
/*
* 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 "k5-int.h"
extern const struct krb5_cksumtypes krb5_cksumtypes_list[];
extern const int krb5_cksumtypes_length;
/*
* include/krb5/crc-32.h
*
* Copyright 1989,1990 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.
*
*
* Definitions for the CRC-32 checksum
*/
/*
* 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.
*/
#ifndef KRB5_CRC32__
#define KRB5_CRC32__
#define CRC32_CKSUM_LENGTH 4
void
mit_crc32 (const krb5_pointer in, size_t in_length, unsigned long *c);
#ifdef CRC32_SHIFT4
void mit_crc32_shift4(const krb5_pointer /* in */,
const size_t /* in_length */,
unsigned long * /* cksum */);
#endif
#endif /* KRB5_CRC32__ */
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* lib/crypto/des/des_int.h
*
* Copyright 1987, 1988, 1990, 2002 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.
*
*
* Private include file for the Data Encryption Standard library.
*/
/*
* 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.
*/
/* only do the whole thing once */
#ifndef DES_INTERNAL_DEFS
#define DES_INTERNAL_DEFS
#include "k5-int.h"
/*
* Begin "mit-des.h"
*/
#ifndef KRB5_MIT_DES__
#define KRB5_MIT_DES__
#if 0 /* SUNW14resync */
#define KRB5INT_CRYPTO_DES_INT /* skip krb4-specific DES stuff */
#include "kerberosIV/des.h" /* for des_key_schedule, etc. */
#undef KRB5INT_CRYPTO_DES_INT /* don't screw other inclusions of des.h */
#endif
/*
* SUNW14resync
* Solaris Kerberos does not do krb4 so we don't have its des.h file
* but we need a few symbols from it so we include them here.
*/
/* begin: from mit kerberosIV/des.h */
#if UINT_MAX >= 0xFFFFFFFFUL
#define DES_INT32 int
#define DES_UINT32 unsigned int
#else
#define DES_INT32 long
#define DES_UINT32 unsigned long
#endif
/* end: from mit kerberosIV/des.h */
typedef unsigned char des_cblock[8]; /* crypto-block size */
typedef struct des_ks_struct { DES_INT32 _[2]; } des_key_schedule[16];
typedef des_cblock mit_des_cblock;
typedef des_key_schedule mit_des_key_schedule;
/* Triple-DES structures */
typedef mit_des_cblock mit_des3_cblock[3];
typedef mit_des_key_schedule mit_des3_key_schedule[3];
#define MIT_DES_ENCRYPT 1
#define MIT_DES_DECRYPT 0
#define K5ROUNDUP(x, align) (-(-(x) & -(align)))
/* the first byte of the key is already in the keyblock */
#define MIT_DES_BLOCK_LENGTH (8*sizeof(krb5_octet))
#define MIT_DES_CBC_CRC_PAD_MINIMUM CRC32_CKSUM_LENGTH
/* This used to be 8*sizeof(krb5_octet) */
#define MIT_DES_KEYSIZE 8
#define MIT_DES_CBC_CKSUM_LENGTH (4*sizeof(krb5_octet))
/*
* Check if k5-int.h has been included before us. If so, then check to see
* that our view of the DES key size is the same as k5-int.h's.
*/
#ifdef KRB5_MIT_DES_KEYSIZE
#if MIT_DES_KEYSIZE != KRB5_MIT_DES_KEYSIZE
error(MIT_DES_KEYSIZE does not equal KRB5_MIT_DES_KEYSIZE)
#endif /* MIT_DES_KEYSIZE != KRB5_MIT_DES_KEYSIZE */
#endif /* KRB5_MIT_DES_KEYSIZE */
#endif /* KRB5_MIT_DES__ */
/*
* End "mit-des.h"
*/
#ifndef _KERNEL
/* afsstring2key.c */
extern krb5_error_code mit_afs_string_to_key
(krb5_context context,
krb5_keyblock *keyblock,
const krb5_data *data,
const krb5_data *salt);
#endif
/* f_cksum.c */
extern unsigned long mit_des_cbc_cksum
( krb5_context context,
const krb5_octet *, krb5_octet *, unsigned long ,
krb5_keyblock *, const krb5_octet *);
/* f_cbc.c */
extern int mit_des_cbc_encrypt
(krb5_context context,
const mit_des_cblock *in,
mit_des_cblock *out, long length,
krb5_keyblock *key,
mit_des_cblock ivec,
int encrypt);
#define mit_des_zeroblock krb5int_c_mit_des_zeroblock
extern const mit_des_cblock mit_des_zeroblock;
/* fin_rndkey.c */
extern krb5_error_code mit_des_finish_random_key
( const krb5_encrypt_block *,
krb5_pointer *);
/* finish_key.c */
extern krb5_error_code mit_des_finish_key
( krb5_encrypt_block *);
/* key_parity.c */
extern void mit_des_fixup_key_parity (mit_des_cblock );
extern int mit_des_check_key_parity (mit_des_cblock );
/* process_ky.c */
extern krb5_error_code mit_des_process_key
( krb5_encrypt_block *, const krb5_keyblock *);
/* string2key.c */
extern krb5_error_code mit_des_string_to_key
( const krb5_encrypt_block *,
krb5_keyblock *, const krb5_data *, const krb5_data *);
/* weak_key.c */
extern int mit_des_is_weak_key (mit_des_cblock );
/* cmb_keys.c */
krb5_error_code mit_des_combine_subkeys
(const krb5_keyblock *, const krb5_keyblock *,
krb5_keyblock **);
/* f_pcbc.c */
int mit_des_pcbc_encrypt ();
/* f_sched.c */
int mit_des_make_key_sched(mit_des_cblock, mit_des_key_schedule);
/* misc.c */
extern void swap_bits (char *);
extern unsigned long long_swap_bits (unsigned long );
extern unsigned long swap_six_bits_to_ansi (unsigned long );
extern unsigned long swap_four_bits_to_ansi (unsigned long );
extern unsigned long swap_bit_pos_1 (unsigned long );
extern unsigned long swap_bit_pos_0 (unsigned long );
extern unsigned long swap_bit_pos_0_to_ansi (unsigned long );
extern unsigned long rev_swap_bit_pos_0 (unsigned long );
extern unsigned long swap_byte_bits (unsigned long );
extern unsigned long swap_long_bytes_bit_number (unsigned long );
#ifdef FILE
/* XXX depends on FILE being a #define! */
extern void test_set (FILE *, const char *, int, const char *, int);
#endif
/* d3_cbc.c */
extern int mit_des3_cbc_encrypt
(krb5_context context,
const mit_des_cblock *in,
mit_des_cblock *out,
unsigned long length,
krb5_keyblock *key,
const mit_des_cblock ivec,
int enc);
/* d3_procky.c */
extern krb5_error_code mit_des3_process_key
(krb5_encrypt_block * eblock,
const krb5_keyblock * keyblock);
/* d3_str2ky.c */
extern krb5_error_code mit_des3_string_to_key
(const krb5_encrypt_block * eblock,
krb5_keyblock * keyblock,
const krb5_data * data,
const krb5_data * salt);
/* u_nfold.c */
extern krb5_error_code mit_des_n_fold
(const krb5_octet * input,
const size_t in_len,
krb5_octet * output,
const size_t out_len);
extern krb5_error_code mit_des_set_random_sequence_number
(const krb5_data * sequence,
krb5_pointer random_state);
#endif /*DES_INTERNAL_DEFS*/
/*
* 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 "k5-int.h"
void krb5_dk_encrypt_length
(const struct krb5_enc_provider *enc,
const struct krb5_hash_provider *hash,
size_t input, size_t *length);
krb5_error_code krb5_dk_encrypt
(
krb5_context context,
const struct krb5_enc_provider *enc,
const struct krb5_hash_provider *hash,
const krb5_keyblock *key, krb5_keyusage usage,
const krb5_data *ivec,
const krb5_data *input, krb5_data *output);
extern krb5_error_code krb5_dk_decrypt
(krb5_context context,
krb5_const struct krb5_enc_provider *enc,
krb5_const struct krb5_hash_provider *hash,
krb5_const krb5_keyblock *key, krb5_keyusage usage,
krb5_const krb5_data *ivec, krb5_const krb5_data *input,
krb5_data *arg_output);
extern krb5_error_code krb5_derive_key
(krb5_context context,
krb5_const struct krb5_enc_provider *enc,
krb5_const krb5_keyblock *inkey,
krb5_keyblock *outkey, krb5_const krb5_data *in_constant);
extern krb5_error_code krb5_dk_make_checksum
(krb5_context context,
krb5_const struct krb5_hash_provider *hash,
krb5_const krb5_keyblock *key, krb5_keyusage usage,
krb5_const krb5_data *input, krb5_data *output);
#ifndef _KERNEL
extern krb5_error_code krb5int_dk_string_to_key
(krb5_context context,
krb5_const struct krb5_enc_provider *enc,
krb5_const krb5_data *string,
krb5_const krb5_data *salt,
krb5_const krb5_data *params,
krb5_keyblock *key);
#endif
void krb5int_aes_encrypt_length
(const struct krb5_enc_provider *enc,
const struct krb5_hash_provider *hash,
size_t input, size_t *length);
krb5_error_code krb5int_aes_dk_encrypt
( krb5_context context,
const struct krb5_enc_provider *enc,
const struct krb5_hash_provider *hash,
const krb5_keyblock *key, krb5_keyusage usage,
const krb5_data *ivec,
const krb5_data *input, krb5_data *output);
krb5_error_code krb5int_aes_dk_decrypt
( krb5_context context,
const struct krb5_enc_provider *enc,
const struct krb5_hash_provider *hash,
const krb5_keyblock *key, krb5_keyusage usage,
const krb5_data *ivec, const krb5_data *input,
krb5_data *arg_output);
extern krb5_error_code
krb5int_aes_string_to_key (krb5_context context,
const struct krb5_enc_provider *,
const krb5_data *, const krb5_data *,
const krb5_data *, krb5_keyblock *key);
/*
* 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 "k5-int.h"
extern const struct krb5_enc_provider krb5int_enc_des;
extern const struct krb5_enc_provider krb5int_enc_des3;
extern const struct krb5_enc_provider krb5int_enc_arcfour;
extern const struct krb5_enc_provider krb5int_enc_aes128;
extern const struct krb5_enc_provider krb5int_enc_aes256;
/*
* 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 "k5-int.h"
extern struct krb5_keytypes krb5_enctypes_list[];
extern const int krb5_enctypes_length;
/*
* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Copyright 1993 by OpenVision Technologies, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appears in all copies and
* that both that copyright notice and this permission notice appear in
* supporting documentation, and that the name of OpenVision not be used
* in advertising or publicity pertaining to distribution of the software
* without specific, written prior permission. OpenVision makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
* OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef _GSSAPIP_GENERIC_H_
#define _GSSAPIP_GENERIC_H_
/*
* $Id: gssapiP_generic.h 18396 2006-07-25 20:29:43Z lxs $
*/
#if defined(_WIN32)
#include "k5-int.h"
#else
#include "autoconf.h"
#ifndef _KERNEL
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif /* !_KERNEL */
#endif
#endif
#include "k5-thread.h"
#include "gssapi_generic.h"
#include "gssapi_err_generic.h"
#ifndef _KERNEL
#include <errno.h>
#else
#include <sys/errno.h>
#endif /* !_KERNEL */
#include "k5-platform.h"
typedef UINT64_TYPE gssint_uint64;
#include "gssapi/gssapi_ext.h"
/** helper macros **/
#if 0 /* SUNW15resync - on Solaris g_OID_equal is in gssapi_ext.h */
#define g_OID_equal(o1, o2) \
(((o1)->length == (o2)->length) && \
(memcmp((o1)->elements,(o2)->elements,(unsigned int) (o1)->length) == 0))
#endif
/* this code knows that an int on the wire is 32 bits. The type of
num should be at least this big, or the extra shifts may do weird
things */
#define TWRITE_INT(ptr, num, bigend) \
(ptr)[0] = (char) ((bigend)?((num)>>24):((num)&0xff)); \
(ptr)[1] = (char) ((bigend)?(((num)>>16)&0xff):(((num)>>8)&0xff)); \
(ptr)[2] = (char) ((bigend)?(((num)>>8)&0xff):(((num)>>16)&0xff)); \
(ptr)[3] = (char) ((bigend)?((num)&0xff):((num)>>24)); \
(ptr) += 4;
#define TWRITE_INT16(ptr, num, bigend) \
(ptr)[0] = (char) ((bigend)?((num)>>24):((num)&0xff)); \
(ptr)[1] = (char) ((bigend)?(((num)>>16)&0xff):(((num)>>8)&0xff)); \
(ptr) += 2;
#define TREAD_INT(ptr, num, bigend) \
(num) = (((ptr)[0]<<((bigend)?24: 0)) | \
((ptr)[1]<<((bigend)?16: 8)) | \
((ptr)[2]<<((bigend)? 8:16)) | \
((ptr)[3]<<((bigend)? 0:24))); \
(ptr) += 4;
#define TREAD_INT16(ptr, num, bigend) \
(num) = (((ptr)[0]<<((bigend)?24: 0)) | \
((ptr)[1]<<((bigend)?16: 8))); \
(ptr) += 2;
#define TWRITE_STR(ptr, str, len) \
(void) memcpy((ptr), (char *) (str), (len)); \
(ptr) += (len);
#define TREAD_STR(ptr, str, len) \
(str) = (ptr); \
(ptr) += (len);
#define TWRITE_BUF(ptr, buf, bigend) \
TWRITE_INT((ptr), (buf).length, (bigend)); \
TWRITE_STR((ptr), (buf).value, (buf).length);
/** malloc wrappers; these may actually do something later */
#ifdef _KERNEL
#define xmalloc(n) MALLOC(n)
#else
#define xmalloc(n) malloc(n)
#endif
#define xrealloc(p,n) realloc(p,n)
#ifdef xfree
#undef xfree
#endif
#ifdef _KERNEL
#define xfree_wrap(p,sze) kmem_free(p,sze)
#else
#define xfree_wrap(p,sze) free(p)
#define xfree(p) free(p)
#endif
/** helper functions **/
/* hide names from applications, especially glib applications */
#define g_set_init gssint_g_set_init
#define g_set_destroy gssint_g_set_destroy
#define g_set_entry_add gssint_g_set_entry_add
#define g_set_entry_delete gssint_g_set_entry_delete
#define g_set_entry_get gssint_g_set_entry_get
#define g_save_name gssint_g_save_name
#define g_save_cred_id gssint_g_save_cred_id
#define g_save_ctx_id gssint_g_save_ctx_id
#define g_save_lucidctx_id gssint_g_save_lucidctx_id
#define g_validate_name gssint_g_validate_name
#define g_validate_cred_id gssint_g_validate_cred_id
#define g_validate_ctx_id gssint_g_validate_ctx_id
#define g_validate_lucidctx_id gssint_g_validate_lucidctx_id
#define g_delete_name gssint_g_delete_name
#define g_delete_cred_id gssint_g_delete_cred_id
#define g_delete_ctx_id gssint_g_delete_ctx_id
#define g_delete_lucidctx_id gssint_g_delete_lucidctx_id
#define g_make_string_buffer gssint_g_make_string_buffer
#define g_token_size gssint_g_token_size
#define g_make_token_header gssint_g_make_token_header
#define g_verify_token_header gssint_g_verify_token_header
#define g_display_major_status gssint_g_display_major_status
#define g_display_com_err_status gssint_g_display_com_err_status
#define g_order_init gssint_g_order_init
#define g_order_check gssint_g_order_check
#define g_order_free gssint_g_order_free
#define g_queue_size gssint_g_queue_size
#define g_queue_externalize gssint_g_queue_externalize
#define g_queue_internalize gssint_g_queue_internalize
#define g_canonicalize_host gssint_g_canonicalize_host
#define g_local_host_name gssint_g_local_host_name
#define g_strdup gssint_g_strdup
typedef struct _g_set_elt *g_set_elt;
typedef struct {
k5_mutex_t mutex;
void *data;
} g_set;
#define G_SET_INIT { K5_MUTEX_PARTIAL_INITIALIZER, 0 }
int g_set_init (g_set_elt *s);
int g_set_destroy (g_set_elt *s);
int g_set_entry_add (g_set_elt *s, void *key, void *value);
int g_set_entry_delete (g_set_elt *s, void *key);
int g_set_entry_get (g_set_elt *s, void *key, void **value);
int g_save_name (g_set *vdb, gss_name_t name);
int g_save_cred_id (g_set *vdb, gss_cred_id_t cred);
int g_save_ctx_id (g_set *vdb, gss_ctx_id_t ctx);
int g_save_lucidctx_id (g_set *vdb, void *lctx);
int g_validate_name (g_set *vdb, gss_name_t name);
int g_validate_cred_id (g_set *vdb, gss_cred_id_t cred);
int g_validate_ctx_id (g_set *vdb, gss_ctx_id_t ctx);
int g_validate_lucidctx_id (g_set *vdb, void *lctx);
int g_delete_name (g_set *vdb, gss_name_t name);
int g_delete_cred_id (g_set *vdb, gss_cred_id_t cred);
int g_delete_ctx_id (g_set *vdb, gss_ctx_id_t ctx);
int g_delete_lucidctx_id (g_set *vdb, void *lctx);
int g_make_string_buffer (const char *str, gss_buffer_t buffer);
unsigned int g_token_size (const gss_OID_desc * mech, unsigned int body_size);
void g_make_token_header (const gss_OID_desc * mech, unsigned int body_size,
unsigned char **buf, int tok_type);
gss_int32 g_verify_token_header (const gss_OID_desc * mech,
unsigned int *body_size,
unsigned char **buf, int tok_type,
unsigned int toksize_in,
int wrapper_required);
OM_uint32 g_display_major_status (OM_uint32 *minor_status,
OM_uint32 status_value,
OM_uint32 *message_context,
gss_buffer_t status_string);
OM_uint32 g_display_com_err_status (OM_uint32 *minor_status,
OM_uint32 status_value,
gss_buffer_t status_string);
gss_int32 g_order_init (void **queue, gssint_uint64 seqnum,
int do_replay, int do_sequence, int wide);
gss_int32 g_order_check (void **queue, gssint_uint64 seqnum);
void g_order_free (void **queue);
gss_uint32 g_queue_size(void *vqueue, size_t *sizep);
gss_uint32 g_queue_externalize(void *vqueue, unsigned char **buf,
size_t *lenremain);
gss_uint32 g_queue_internalize(void **vqueue, unsigned char **buf,
size_t *lenremain);
char *g_strdup (char *str);
/** declarations of internal name mechanism functions **/
#if 0 /* SUNW15resync - mved to mglueP.h for sake of non-krb5 mechs */
OM_uint32 generic_gss_release_buffer
(OM_uint32*, /* minor_status */
gss_buffer_t /* buffer */
);
OM_uint32 generic_gss_release_oid_set
(OM_uint32*, /* minor_status */
gss_OID_set* /* set */
);
OM_uint32 generic_gss_release_oid
(OM_uint32*, /* minor_status */
gss_OID* /* set */
);
OM_uint32 generic_gss_copy_oid
(OM_uint32 *, /* minor_status */
gss_OID_desc * const, /* oid */ /* SUNW15resync */
gss_OID * /* new_oid */
);
OM_uint32 generic_gss_create_empty_oid_set
(OM_uint32 *, /* minor_status */
gss_OID_set * /* oid_set */
);
OM_uint32 generic_gss_add_oid_set_member
(OM_uint32 *, /* minor_status */
const gss_OID_desc * const, /* member_oid */
gss_OID_set * /* oid_set */
);
OM_uint32 generic_gss_test_oid_set_member
(OM_uint32 *, /* minor_status */
const gss_OID_desc * const, /* member */
gss_OID_set, /* set */
int * /* present */
);
OM_uint32 generic_gss_oid_to_str
(OM_uint32 *, /* minor_status */
const gss_OID_desc * const, /* oid */
gss_buffer_t /* oid_str */
);
OM_uint32 generic_gss_str_to_oid
(OM_uint32 *, /* minor_status */
gss_buffer_t, /* oid_str */
gss_OID * /* oid */
);
OM_uint32
generic_gss_oid_compose(
OM_uint32 *, /* minor_status */
const char *, /* prefix */
size_t, /* prefix_len */
int, /* suffix */
gss_OID_desc *); /* oid */
OM_uint32
generic_gss_oid_decompose(
OM_uint32 *, /* minor_status */
const char *, /*prefix */
size_t, /* prefix_len */
gss_OID_desc *, /* oid */
int *); /* suffix */
#endif /* 0 */
#ifndef _KERNEL
int gssint_mecherrmap_init(void);
void gssint_mecherrmap_destroy(void);
OM_uint32 gssint_mecherrmap_map(OM_uint32 minor, const gss_OID_desc *oid);
int gssint_mecherrmap_get(OM_uint32 minor, gss_OID mech_oid,
OM_uint32 *mech_minor);
OM_uint32 gssint_mecherrmap_map_errcode(OM_uint32 errcode);
#endif
#endif /* _GSSAPIP_GENERIC_H_ */
/*
* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Copyright 2000 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.
*
*/
/*
* Copyright 1993 by OpenVision Technologies, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appears in all copies and
* that both that copyright notice and this permission notice appear in
* supporting documentation, and that the name of OpenVision not be used
* in advertising or publicity pertaining to distribution of the software
* without specific, written prior permission. OpenVision makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
* OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef _GSSAPIP_KRB5_H_
#define _GSSAPIP_KRB5_H_
#include <k5-int.h>
#ifdef HAVE_MEMORY_H
#include <memory.h>
#endif
/* work around sunos braindamage */
#ifdef major
#undef major
#endif
#ifdef minor
#undef minor
#endif
#include "gssapiP_generic.h"
/* The include of gssapi_krb5.h will dtrt with the above #defines in
* effect.
*/
#include "gssapi_krb5.h"
#include "gssapi_err_krb5.h"
#include "gssapi_ext.h"
/* for debugging */
#undef CFX_EXERCISE
/** constants **/
#define GSS_MECH_KRB5_OID_LENGTH 9
#define GSS_MECH_KRB5_OID "\052\206\110\206\367\022\001\002\002"
#define GSS_MECH_KRB5_OLD_OID_LENGTH 5
#define GSS_MECH_KRB5_OLD_OID "\053\005\001\005\002"
/* Incorrect krb5 mech OID emitted by MS. */
#define GSS_MECH_KRB5_WRONG_OID_LENGTH 9
#define GSS_MECH_KRB5_WRONG_OID "\052\206\110\202\367\022\001\002\002"
#define CKSUMTYPE_KG_CB 0x8003
#define KG_TOK_CTX_AP_REQ 0x0100
#define KG_TOK_CTX_AP_REP 0x0200
#define KG_TOK_CTX_ERROR 0x0300
#define KG_TOK_SIGN_MSG 0x0101
#define KG_TOK_SEAL_MSG 0x0201
#define KG_TOK_MIC_MSG 0x0101
#define KG_TOK_WRAP_MSG 0x0201
#define KG_TOK_DEL_CTX 0x0102
#define KG2_TOK_INITIAL 0x0101
#define KG2_TOK_RESPONSE 0x0202
#define KG2_TOK_MIC 0x0303
#define KG2_TOK_WRAP_INTEG 0x0404
#define KG2_TOK_WRAP_PRIV 0x0505
#define KRB5_GSS_FOR_CREDS_OPTION 1
#define KG2_RESP_FLAG_ERROR 0x0001
#define KG2_RESP_FLAG_DELEG_OK 0x0002
/* These are to be stored in little-endian order, i.e., des-mac is
stored as 02 00. */
enum sgn_alg {
SGN_ALG_DES_MAC_MD5 = 0x0000,
SGN_ALG_MD2_5 = 0x0001,
SGN_ALG_DES_MAC = 0x0002,
SGN_ALG_3 = 0x0003, /* not published */
SGN_ALG_HMAC_MD5 = 0x0011, /* microsoft w2k; */
SGN_ALG_HMAC_SHA1_DES3_KD = 0x0004
};
enum seal_alg {
SEAL_ALG_NONE = 0xffff,
SEAL_ALG_DES = 0x0000,
SEAL_ALG_1 = 0x0001, /* not published */
SEAL_ALG_MICROSOFT_RC4 = 0x0010, /* microsoft w2k; */
SEAL_ALG_DES3KD = 0x0002
};
/* for 3DES */
#define KG_USAGE_SEAL 22
#define KG_USAGE_SIGN 23
#define KG_USAGE_SEQ 24
/* for draft-ietf-krb-wg-gssapi-cfx-01 */
#define KG_USAGE_ACCEPTOR_SEAL 22
#define KG_USAGE_ACCEPTOR_SIGN 23
#define KG_USAGE_INITIATOR_SEAL 24
#define KG_USAGE_INITIATOR_SIGN 25
enum qop {
GSS_KRB5_INTEG_C_QOP_MD5 = 0x0001, /* *partial* MD5 = "MD2.5" */
GSS_KRB5_INTEG_C_QOP_DES_MD5 = 0x0002,
GSS_KRB5_INTEG_C_QOP_DES_MAC = 0x0003,
GSS_KRB5_INTEG_C_QOP_HMAC_SHA1 = 0x0004,
GSS_KRB5_INTEG_C_QOP_MASK = 0x00ff,
GSS_KRB5_CONF_C_QOP_DES = 0x0100,
GSS_KRB5_CONF_C_QOP_DES3_KD = 0x0200,
GSS_KRB5_CONF_C_QOP_MASK = 0xff00
};
/** internal types **/
typedef krb5_principal krb5_gss_name_t;
typedef struct _krb5_gss_cred_id_rec {
/* protect against simultaneous accesses */
k5_mutex_t lock;
/* name/type of credential */
gss_cred_usage_t usage;
krb5_principal princ; /* this is not interned as a gss_name_t */
int prerfc_mech;
int rfc_mech;
/* keytab (accept) data */
krb5_keytab keytab;
krb5_rcache rcache;
/* ccache (init) data */
krb5_ccache ccache;
krb5_timestamp tgt_expire;
krb5_enctype *req_enctypes; /* limit negotiated enctypes to this list */
} krb5_gss_cred_id_rec, *krb5_gss_cred_id_t;
typedef struct _krb5_gss_ctx_id_rec {
unsigned int initiate : 1; /* nonzero if initiating, zero if accepting */
unsigned int established : 1;
unsigned int big_endian : 1;
unsigned int have_acceptor_subkey : 1;
unsigned int seed_init : 1; /* XXX tested but never actually set */
OM_uint32 gss_flags;
unsigned char seed[16];
krb5_principal here;
krb5_principal there;
krb5_keyblock *subkey;
int signalg;
size_t cksum_size;
int sealalg;
krb5_keyblock *enc;
krb5_keyblock *seq;
krb5_timestamp endtime;
krb5_ticket_times krb_times;
krb5_flags krb_flags;
/* XXX these used to be signed. the old spec is inspecific, and
the new spec specifies unsigned. I don't believe that the change
affects the wire encoding. */
gssint_uint64 seq_send;
gssint_uint64 seq_recv;
void *seqstate;
krb5_context k5_context;
krb5_auth_context auth_context;
gss_OID_desc *mech_used;
/* Protocol spec revision
0 => RFC 1964 with 3DES and RC4 enhancements
1 => draft-ietf-krb-wg-gssapi-cfx-01
No others defined so far. */
int proto;
krb5_cksumtype cksumtype; /* for "main" subkey */
krb5_keyblock *acceptor_subkey; /* CFX only */
krb5_cksumtype acceptor_subkey_cksumtype;
int cred_rcache; /* did we get rcache from creds? */
krb5_authdata **authdata;
} krb5_gss_ctx_id_rec, *krb5_gss_ctx_id_t;
extern g_set kg_vdb;
extern k5_mutex_t gssint_krb5_keytab_lock;
/* helper macros */
#define kg_save_name(name) g_save_name(&kg_vdb,name)
#define kg_save_cred_id(cred) g_save_cred_id(&kg_vdb,cred)
#define kg_save_ctx_id(ctx) g_save_ctx_id(&kg_vdb,ctx)
#define kg_save_lucidctx_id(lctx) g_save_lucidctx_id(&kg_vdb,lctx)
#define kg_validate_name(name) g_validate_name(&kg_vdb,name)
#define kg_validate_cred_id(cred) g_validate_cred_id(&kg_vdb,cred)
#define kg_validate_ctx_id(ctx) g_validate_ctx_id(&kg_vdb,ctx)
#define kg_validate_lucidctx_id(lctx) g_validate_lucidctx_id(&kg_vdb,lctx)
#define kg_delete_name(name) g_delete_name(&kg_vdb,name)
#define kg_delete_cred_id(cred) g_delete_cred_id(&kg_vdb,cred)
#define kg_delete_ctx_id(ctx) g_delete_ctx_id(&kg_vdb,ctx)
#define kg_delete_lucidctx_id(lctx) g_delete_lucidctx_id(&kg_vdb,lctx)
/** helper functions **/
OM_uint32 kg_get_defcred
(OM_uint32 *minor_status,
gss_cred_id_t *cred);
krb5_error_code kg_checksum_channel_bindings
(krb5_context context, gss_channel_bindings_t cb,
krb5_checksum *cksum,
int bigend);
krb5_error_code kg_make_seq_num (krb5_context context,
krb5_keyblock *key,
int direction, krb5_ui_4 seqnum, unsigned char *cksum,
unsigned char *buf);
krb5_error_code kg_get_seq_num (krb5_context context,
krb5_keyblock *key,
unsigned char *cksum, unsigned char *buf, int *direction,
krb5_ui_4 *seqnum);
krb5_error_code kg_make_seed (krb5_context context,
krb5_keyblock *key,
unsigned char *seed);
int kg_confounder_size (krb5_context context, krb5_keyblock *key);
krb5_error_code kg_make_confounder (krb5_context context,
krb5_keyblock *key, unsigned char *buf);
krb5_error_code kg_encrypt (krb5_context context,
krb5_keyblock *key, int usage,
krb5_pointer iv,
krb5_const_pointer in,
krb5_pointer out,
unsigned int length);
krb5_error_code
kg_arcfour_docrypt (krb5_context,
const krb5_keyblock *longterm_key , int ms_usage,
const unsigned char *kd_data, size_t kd_data_len,
const unsigned char *input_buf, size_t input_len,
unsigned char *output_buf);
krb5_error_code kg_decrypt (krb5_context context,
krb5_keyblock *key, int usage,
krb5_pointer iv,
krb5_const_pointer in,
krb5_pointer out,
unsigned int length);
OM_uint32 kg_seal (OM_uint32 *minor_status,
gss_ctx_id_t context_handle,
int conf_req_flag,
int qop_req,
gss_buffer_t input_message_buffer,
int *conf_state,
gss_buffer_t output_message_buffer,
int toktype);
OM_uint32 kg_unseal (OM_uint32 *minor_status,
gss_ctx_id_t context_handle,
gss_buffer_t input_token_buffer,
gss_buffer_t message_buffer,
int *conf_state,
int *qop_state,
int toktype);
OM_uint32 kg_seal_size (OM_uint32 *minor_status,
gss_ctx_id_t context_handle,
int conf_req_flag,
gss_qop_t qop_req,
OM_uint32 output_size,
OM_uint32 *input_size);
krb5_error_code kg_ctx_size (krb5_context kcontext,
krb5_pointer arg,
size_t *sizep);
krb5_error_code kg_ctx_externalize (krb5_context kcontext,
krb5_pointer arg,
krb5_octet **buffer,
size_t *lenremain);
krb5_error_code kg_ctx_internalize (krb5_context kcontext,
krb5_pointer *argp,
krb5_octet **buffer,
size_t *lenremain);
OM_uint32 kg_sync_ccache_name (krb5_context context, OM_uint32 *minor_status);
OM_uint32 kg_caller_provided_ccache_name (OM_uint32 *minor_status,
int *out_caller_provided_name);
OM_uint32 kg_get_ccache_name (OM_uint32 *minor_status,
const char **out_name);
OM_uint32 kg_set_ccache_name (OM_uint32 *minor_status,
const char *name);
/** declarations of internal name mechanism functions **/
OM_uint32 krb5_gss_acquire_cred
(OM_uint32*, /* minor_status */
gss_name_t, /* desired_name */
OM_uint32, /* time_req */
gss_OID_set, /* desired_mechs */
gss_cred_usage_t, /* cred_usage */
gss_cred_id_t*, /* output_cred_handle */
gss_OID_set*, /* actual_mechs */
OM_uint32* /* time_rec */
);
OM_uint32 krb5_gss_release_cred
(OM_uint32*, /* minor_status */
gss_cred_id_t* /* cred_handle */
);
OM_uint32 krb5_gss_init_sec_context
(OM_uint32*, /* minor_status */
gss_cred_id_t, /* claimant_cred_handle */
gss_ctx_id_t*, /* context_handle */
gss_name_t, /* target_name */
gss_OID, /* mech_type */
OM_uint32, /* req_flags */
OM_uint32, /* time_req */
gss_channel_bindings_t,
/* input_chan_bindings */
gss_buffer_t, /* input_token */
gss_OID*, /* actual_mech_type */
gss_buffer_t, /* output_token */
OM_uint32*, /* ret_flags */
OM_uint32* /* time_rec */
);
OM_uint32 krb5_gss_accept_sec_context
(OM_uint32*, /* minor_status */
gss_ctx_id_t*, /* context_handle */
gss_cred_id_t, /* verifier_cred_handle */
gss_buffer_t, /* input_token_buffer */
gss_channel_bindings_t,
/* input_chan_bindings */
gss_name_t*, /* src_name */
gss_OID*, /* mech_type */
gss_buffer_t, /* output_token */
OM_uint32*, /* ret_flags */
OM_uint32*, /* time_rec */
gss_cred_id_t* /* delegated_cred_handle */
);
OM_uint32 krb5_gss_process_context_token
(OM_uint32*, /* minor_status */
gss_ctx_id_t, /* context_handle */
gss_buffer_t /* token_buffer */
);
OM_uint32 krb5_gss_delete_sec_context
(OM_uint32*, /* minor_status */
gss_ctx_id_t*, /* context_handle */
gss_buffer_t /* output_token */
#ifdef _KERNEL
/* */, OM_uint32 /* context verifier */
#endif
);
OM_uint32 krb5_gss_context_time
(OM_uint32*, /* minor_status */
gss_ctx_id_t, /* context_handle */
OM_uint32* /* time_rec */
);
OM_uint32 krb5_gss_sign
(OM_uint32*, /* minor_status */
gss_ctx_id_t, /* context_handle */
int, /* qop_req */
gss_buffer_t, /* message_buffer */
gss_buffer_t /* message_token */
#ifdef _KERNEL
/* */, OM_uint32 /* context verifier */
#endif
);
OM_uint32 krb5_gss_verify
(OM_uint32*, /* minor_status */
gss_ctx_id_t, /* context_handle */
gss_buffer_t, /* message_buffer */
gss_buffer_t, /* token_buffer */
int* /* qop_state */
#ifdef _KERNEL
/* */, OM_uint32 /* context verifier */
#endif
);
OM_uint32 krb5_gss_seal
(OM_uint32*, /* minor_status */
gss_ctx_id_t, /* context_handle */
int, /* conf_req_flag */
int, /* qop_req */
gss_buffer_t, /* input_message_buffer */
int*, /* conf_state */
gss_buffer_t /* output_message_buffer */
#ifdef _KERNEL
/* */, OM_uint32 /* context verifier */
#endif
);
OM_uint32 krb5_gss_unseal
(OM_uint32*, /* minor_status */
gss_ctx_id_t, /* context_handle */
gss_buffer_t, /* input_message_buffer */
gss_buffer_t, /* output_message_buffer */
int*, /* conf_state */
int* /* qop_state */
#ifdef _KERNEL
/* */, OM_uint32 /* context verifier */
#endif
);
OM_uint32 krb5_gss_display_status
(OM_uint32*, /* minor_status */
OM_uint32, /* status_value */
int, /* status_type */
gss_OID, /* mech_type */
OM_uint32*, /* message_context */
gss_buffer_t /* status_string */
);
OM_uint32 krb5_gss_indicate_mechs
(OM_uint32*, /* minor_status */
gss_OID_set* /* mech_set */
);
OM_uint32 krb5_gss_compare_name
(OM_uint32*, /* minor_status */
gss_name_t, /* name1 */
gss_name_t, /* name2 */
int* /* name_equal */
);
OM_uint32 krb5_gss_display_name
(OM_uint32*, /* minor_status */
gss_name_t, /* input_name */
gss_buffer_t, /* output_name_buffer */
gss_OID* /* output_name_type */
);
OM_uint32 krb5_gss_import_name
(OM_uint32*, /* minor_status */
gss_buffer_t, /* input_name_buffer */
gss_OID, /* input_name_type */
gss_name_t* /* output_name */
);
OM_uint32 krb5_gss_release_name
(OM_uint32*, /* minor_status */
gss_name_t* /* input_name */
);
OM_uint32 krb5_gss_inquire_cred
(OM_uint32 *, /* minor_status */
gss_cred_id_t, /* cred_handle */
gss_name_t *, /* name */
OM_uint32 *, /* lifetime */
gss_cred_usage_t*,/* cred_usage */
gss_OID_set * /* mechanisms */
);
OM_uint32 krb5_gss_inquire_context
(OM_uint32*, /* minor_status */
gss_ctx_id_t, /* context_handle */
gss_name_t*, /* initiator_name */
gss_name_t*, /* acceptor_name */
OM_uint32*, /* lifetime_rec */
gss_OID*, /* mech_type */
OM_uint32*, /* ret_flags */
int*, /* locally_initiated */
int* /* open */
);
/* New V2 entry points */
OM_uint32 krb5_gss_get_mic
(OM_uint32 *, /* minor_status */
gss_ctx_id_t, /* context_handle */
gss_qop_t, /* qop_req */
gss_buffer_t, /* message_buffer */
gss_buffer_t /* message_token */
);
OM_uint32 krb5_gss_verify_mic
(OM_uint32 *, /* minor_status */
gss_ctx_id_t, /* context_handle */
gss_buffer_t, /* message_buffer */
gss_buffer_t, /* message_token */
gss_qop_t * /* qop_state */
);
OM_uint32 krb5_gss_wrap
(OM_uint32 *, /* minor_status */
gss_ctx_id_t, /* context_handle */
int, /* conf_req_flag */
gss_qop_t, /* qop_req */
gss_buffer_t, /* input_message_buffer */
int *, /* conf_state */
gss_buffer_t /* output_message_buffer */
);
OM_uint32 krb5_gss_unwrap
(OM_uint32 *, /* minor_status */
gss_ctx_id_t, /* context_handle */
gss_buffer_t, /* input_message_buffer */
gss_buffer_t, /* output_message_buffer */
int *, /* conf_state */
gss_qop_t * /* qop_state */
);
OM_uint32 krb5_gss_wrap_size_limit
(OM_uint32 *, /* minor_status */
gss_ctx_id_t, /* context_handle */
int, /* conf_req_flag */
gss_qop_t, /* qop_req */
OM_uint32, /* req_output_size */
OM_uint32 * /* max_input_size */
);
OM_uint32 krb5_gss_import_name_object
(OM_uint32 *, /* minor_status */
void *, /* input_name */
gss_OID, /* input_name_type */
gss_name_t * /* output_name */
);
OM_uint32 krb5_gss_export_name_object
(OM_uint32 *, /* minor_status */
gss_name_t, /* input_name */
gss_OID, /* desired_name_type */
void * * /* output_name */
);
OM_uint32 krb5_gss_add_cred
(OM_uint32 *, /* minor_status */
gss_cred_id_t, /* input_cred_handle */
gss_name_t, /* desired_name */
gss_OID, /* desired_mech */
gss_cred_usage_t, /* cred_usage */
OM_uint32, /* initiator_time_req */
OM_uint32, /* acceptor_time_req */
gss_cred_id_t *, /* output_cred_handle */
gss_OID_set *, /* actual_mechs */
OM_uint32 *, /* initiator_time_rec */
OM_uint32 * /* acceptor_time_rec */
);
OM_uint32 krb5_gss_inquire_cred_by_mech
(OM_uint32 *, /* minor_status */
gss_cred_id_t, /* cred_handle */
gss_OID, /* mech_type */
gss_name_t *, /* name */
OM_uint32 *, /* initiator_lifetime */
OM_uint32 *, /* acceptor_lifetime */
gss_cred_usage_t * /* cred_usage */
);
OM_uint32 krb5_gss_export_sec_context
(OM_uint32 *, /* minor_status */
gss_ctx_id_t *, /* context_handle */
gss_buffer_t /* interprocess_token */
);
OM_uint32 krb5_gss_import_sec_context
(OM_uint32 *, /* minor_status */
gss_buffer_t, /* interprocess_token */
gss_ctx_id_t * /* context_handle */
/* Note no _KERNEL context verifier */
);
krb5_error_code krb5_gss_ser_init(krb5_context);
OM_uint32 krb5_gss_release_oid
(OM_uint32 *, /* minor_status */
gss_OID * /* oid */
);
OM_uint32 krb5_gss_internal_release_oid
(OM_uint32 *, /* minor_status */
gss_OID * /* oid */
);
OM_uint32 krb5_gss_inquire_names_for_mech
(OM_uint32 *, /* minor_status */
gss_OID, /* mechanism */
gss_OID_set * /* name_types */
);
/* SUNW15resync - XXX nullify? */
OM_uint32 krb5_gss_canonicalize_name
(OM_uint32 *, /* minor_status */
const gss_name_t, /* input_name */
const gss_OID, /* mech_type */
gss_name_t * /* output_name */
);
OM_uint32 krb5_gss_export_name
(OM_uint32 *, /* minor_status */
const gss_name_t, /* input_name */
gss_buffer_t /* exported_name */
);
OM_uint32 krb5_gss_duplicate_name
(OM_uint32 *, /* minor_status */
const gss_name_t, /* input_name */
gss_name_t * /* dest_name */
);
OM_uint32 krb5_gss_validate_cred
(OM_uint32 *, /* minor_status */
gss_cred_id_t /* cred */
);
OM_uint32
krb5_gss_validate_cred_1(OM_uint32 * /* minor_status */,
gss_cred_id_t /* cred_handle */,
krb5_context /* context */);
gss_OID krb5_gss_convert_static_mech_oid(gss_OID oid);
krb5_error_code gss_krb5int_make_seal_token_v3(krb5_context,
krb5_gss_ctx_id_rec *,
const gss_buffer_desc *,
gss_buffer_t,
int, int);
OM_uint32 gss_krb5int_unseal_token_v3(krb5_context *contextptr,
OM_uint32 *minor_status,
krb5_gss_ctx_id_rec *ctx,
unsigned char *ptr, int bodysize,
gss_buffer_t message_buffer,
int *conf_state, int *qop_state,
int toktype);
/*
* SUNW15resync
* Solaris specific interfaces start
*/
OM_uint32 krb5_gss_store_cred (
OM_uint32 *, /* minor_status */
const gss_cred_id_t, /* input_cred */
gss_cred_usage_t, /* cred_usage */
const gss_OID, /* desired_mech */
OM_uint32, /* overwrite_cred */
OM_uint32, /* default_cred */
gss_OID_set *, /* elements_stored */
gss_cred_usage_t * /* cred_usage_stored */
);
OM_uint32 krb5_pname_to_uid(
OM_uint32 *, /* minor status */
const gss_name_t, /* pname */
uid_t * /* uidOUt */
);
OM_uint32 krb5_gss_userok(
OM_uint32 *, /* minor status */
const gss_name_t, /* remote user principal name */
const char *, /* local unix user name */
int * /* remote user ok to login w/out pw? */
);
/*
* SUNW15resync
* Solaris specific interfaces end
*/
/*
* These take unglued krb5-mech-specific contexts.
*/
#define GSS_KRB5_GET_TKT_FLAGS_OID_LENGTH 11
#define GSS_KRB5_GET_TKT_FLAGS_OID "\x2a\x86\x48\x86\xf7\x12\x01\x02\x02\x05\x01"
#ifndef _KERNEL
OM_uint32 gss_krb5int_get_tkt_flags
(OM_uint32 *minor_status,
const gss_ctx_id_t context_handle,
const gss_OID desired_object,
gss_buffer_set_t *data_set);
OM_uint32 KRB5_CALLCONV gss_krb5int_copy_ccache
(OM_uint32 *minor_status,
gss_cred_id_t cred_handle,
krb5_ccache out_ccache);
#define GSS_KRB5_SET_ALLOWABLE_ENCTYPES_OID_LENGTH 11
#define GSS_KRB5_SET_ALLOWABLE_ENCTYPES_OID "\x2a\x86\x48\x86\xf7\x12\x01\x02\x02\x05\x04"
struct krb5_gss_set_allowable_enctypes_req {
OM_uint32 num_ktypes;
krb5_enctype *ktypes;
};
#define GSS_KRB5_INQ_SSPI_SESSION_KEY_OID_LENGTH 11
#define GSS_KRB5_INQ_SSPI_SESSION_KEY_OID "\x2a\x86\x48\x86\xf7\x12\x01\x02\x02\x05\x05"
OM_uint32
gss_krb5int_inq_session_key(OM_uint32 *, const gss_ctx_id_t, const gss_OID, gss_buffer_set_t *);
OM_uint32 KRB5_CALLCONV
gss_krb5int_set_allowable_enctypes(OM_uint32 *minor_status,
gss_cred_id_t cred,
OM_uint32 num_ktypes,
krb5_enctype *ktypes);
#endif /* _KERNEL */
#if 0
/*
* SUNW17PACresync
* These two functions not needed yet, revisit for full 1.7 resync.
*/
OM_uint32 KRB5_CALLCONV
gss_krb5int_set_allowable_enctypes(OM_uint32 *minor_status,
gss_cred_id_t cred,
const gss_OID desired_oid,
const gss_buffer_t value);
OM_uint32 KRB5_CALLCONV
gss_krb5int_export_lucid_sec_context(OM_uint32 *minor_status,
gss_ctx_id_t *context_handle,
OM_uint32 version,
void **kctx);
#endif
#ifndef _KERNEL
#define GSS_KRB5_EXPORT_LUCID_SEC_CONTEXT_OID_LENGTH 11
#define GSS_KRB5_EXPORT_LUCID_SEC_CONTEXT_OID "\x2a\x86\x48\x86\xf7\x12\x01\x02\x02\x05\x06"
OM_uint32
gss_krb5int_export_lucid_sec_context(OM_uint32 *minor_status,
const gss_ctx_id_t context_handle,
const gss_OID desired_object,
gss_buffer_set_t *data_set);
#define GSS_KRB5_FREE_LUCID_SEC_CONTEXT_OID_LENGTH 11
#define GSS_KRB5_FREE_LUCID_SEC_CONTEXT_OID "\x2a\x86\x48\x86\xf7\x12\x01\x02\x02\x05\x07"
OM_uint32
gss_krb5int_free_lucid_sec_context(OM_uint32 *, const gss_OID,
const gss_OID, gss_buffer_t);
extern k5_mutex_t kg_kdc_flag_mutex;
krb5_error_code krb5_gss_init_context (krb5_context *ctxp);
#define GSS_KRB5_INQ_SSPI_SESSION_KEY_OID_LENGTH 11
#define GSS_KRB5_INQ_SSPI_SESSION_KEY_OID "\x2a\x86\x48\x86\xf7\x12\x01\x02\x02\x05\x05"
OM_uint32
gss_krb5int_inq_session_key(OM_uint32 *, const gss_ctx_id_t, const gss_OID, gss_buffer_set_t *);
#define GSS_KRB5_USE_KDC_CONTEXT_OID_LENGTH 11
#define GSS_KRB5_USE_KDC_CONTEXT_OID "\x2a\x86\x48\x86\xf7\x12\x01\x02\x02\x05\x08"
OM_uint32 krb5int_gss_use_kdc_context(OM_uint32 *, const gss_OID,
const gss_OID, gss_buffer_t);
krb5_error_code krb5_gss_use_kdc_context(void);
#define GSS_KRB5_REGISTER_ACCEPTOR_IDENTITY_OID_LENGTH 11
#define GSS_KRB5_REGISTER_ACCEPTOR_IDENTITY_OID "\x2a\x86\x48\x86\xf7\x12\x01\x02\x02\x05\x09"
OM_uint32
gss_krb5int_register_acceptor_identity(OM_uint32 *, const gss_OID, const gss_OID, gss_buffer_t);
#define GSS_KRB5_EXTRACT_AUTHZ_DATA_FROM_SEC_CONTEXT_OID_LENGTH 11
#define GSS_KRB5_EXTRACT_AUTHZ_DATA_FROM_SEC_CONTEXT_OID "\x2a\x86\x48\x86\xf7\x12\x01\x02\x02\x05\x0a"
OM_uint32
gss_krb5int_extract_authz_data_from_sec_context(OM_uint32 *minor_status,
const gss_ctx_id_t context_handle,
const gss_OID desired_object,
gss_buffer_set_t *ad_data);
#define GSS_KRB5_SET_CRED_RCACHE_OID_LENGTH 11
#define GSS_KRB5_SET_CRED_RCACHE_OID "\x2a\x86\x48\x86\xf7\x12\x01\x02\x02\x05\x0b"
OM_uint32
gss_krb5int_set_cred_rcache(OM_uint32 *, gss_cred_id_t, const gss_OID, const gss_buffer_t);
#define GSS_KRB5_EXTRACT_AUTHTIME_FROM_SEC_CONTEXT_OID_LENGTH 11
#define GSS_KRB5_EXTRACT_AUTHTIME_FROM_SEC_CONTEXT_OID "\x2a\x86\x48\x86\xf7\x12\x01\x02\x02\x05\x0c"
OM_uint32
gss_krb5int_extract_authtime_from_sec_context(OM_uint32 *,
const gss_ctx_id_t,
const gss_OID,
gss_buffer_set_t *);
#endif /* _KERNEL */
OM_uint32 gss_krb5int_initialize_library(void);
void gss_krb5int_cleanup_library(void);
/* For error message handling. */
/* Returns a shared string, not a private copy! */
extern char *
krb5_gss_get_error_message(OM_uint32 minor_code);
extern void
krb5_gss_save_error_string(OM_uint32 minor_code, char *msg);
extern void
krb5_gss_save_error_message(OM_uint32 minor_code, const char *format, ...)
#if !defined(__cplusplus) && (__GNUC__ > 2)
__attribute__((__format__(__printf__, 2, 3)))
#endif
;
extern void
krb5_gss_save_error_info(OM_uint32 minor_code, krb5_context ctx);
#define get_error_message krb5_gss_get_error_message
#define save_error_string krb5_gss_save_error_string
#define save_error_message krb5_gss_save_error_message
/* Solaris Kerberos */
#ifdef _KERNEL
#define save_error_info(m, ctx)
#else
#define save_error_info krb5_gss_save_error_info
#endif
extern void krb5_gss_delete_error_info(void *p);
/* Prefix concatenated with Kerberos encryption type */
#define GSS_KRB5_SESSION_KEY_ENCTYPE_OID_LENGTH 10
#define GSS_KRB5_SESSION_KEY_ENCTYPE_OID "\x2a\x86\x48\x86\xf7\x12\x01\x02\x02\x04"
#endif /* _GSSAPIP_KRB5_H_ */
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef __GSSAPI_ERR_KRB5_H
#define __GSSAPI_ERR_KRB5_H
/*
* gssapi_err_krb5.h:
* This file is automatically generated; please do not edit it.
*/
#define KG_CCACHE_NOMATCH (39756032L)
#define KG_KEYTAB_NOMATCH (39756033L)
#define KG_TGT_MISSING (39756034L)
#define KG_NO_SUBKEY (39756035L)
#define KG_CONTEXT_ESTABLISHED (39756036L)
#define KG_BAD_SIGN_TYPE (39756037L)
#define KG_BAD_LENGTH (39756038L)
#define KG_CTX_INCOMPLETE (39756039L)
#define KG_CONTEXT (39756040L)
#define KG_CRED (39756041L)
#define KG_ENC_DESC (39756042L)
#define KG_BAD_SEQ (39756043L)
#define KG_EMPTY_CCACHE (39756044L)
#define KG_NO_CTYPES (39756045L)
#define KG_LUCID_VERSION (39756046L)
#define ERROR_TABLE_BASE_k5g (39756032L)
/* for compatibility with older versions... */
#define k5g_err_base ERROR_TABLE_BASE_k5g
#endif /* ! __GSSAPI_ERR_KRB5_H */
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright 1993 by OpenVision Technologies, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appears in all copies and
* that both that copyright notice and this permission notice appear in
* supporting documentation, and that the name of OpenVision not be used
* in advertising or publicity pertaining to distribution of the software
* without specific, written prior permission. OpenVision makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
* OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef _GSSAPI_GENERIC_H_
#define _GSSAPI_GENERIC_H_
/*
* $Id: gssapi_generic.h 15252 2003-03-06 20:26:39Z lxs $
*/
#include <gssapi/gssapi.h>
#if defined(__cplusplus) && !defined(GSSAPIGENERIC_BEGIN_DECLS)
#define GSSAPIGENERIC_BEGIN_DECLS extern "C" {
#define GSSAPIGENERIC_END_DECLS }
#else
#define GSSAPIGENERIC_BEGIN_DECLS
#define GSSAPIGENERIC_END_DECLS
#endif
GSSAPIGENERIC_BEGIN_DECLS
/* SUNW14resync */
#ifndef GSS_DLLIMP
#define GSS_DLLIMP
#endif
/* Deprecated MIT krb5 oid names provided for compatibility.
* The correct oids (GSS_C_NT_USER_NAME, etc) from rfc 2744
* are defined in gssapi.h. */
GSS_DLLIMP extern gss_OID gss_nt_user_name;
GSS_DLLIMP extern gss_OID gss_nt_machine_uid_name;
GSS_DLLIMP extern gss_OID gss_nt_string_uid_name;
extern gss_OID gss_nt_service_name_v2;
GSS_DLLIMP extern gss_OID gss_nt_service_name;
extern gss_OID gss_nt_exported_name;
GSSAPIGENERIC_END_DECLS
#endif /* _GSSAPI_GENERIC_H_ */
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright 1993 by OpenVision Technologies, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appears in all copies and
* that both that copyright notice and this permission notice appear in
* supporting documentation, and that the name of OpenVision not be used
* in advertising or publicity pertaining to distribution of the software
* without specific, written prior permission. OpenVision makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
* OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef _GSSAPI_KRB5_H_
#define _GSSAPI_KRB5_H_
#include <gssapi/gssapi.h>
#include <gssapi/gssapi_ext.h>
#include <krb5.h>
/* SUNW15resync */
#ifndef GSS_DLLIMP
#define GSS_DLLIMP
#endif
/* C++ friendlyness */
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* Reserved static storage for GSS_oids. See rfc 1964 for more details. */
/* 2.1.1. Kerberos Principal Name Form: */
GSS_DLLIMP extern const gss_OID_desc * const GSS_KRB5_NT_PRINCIPAL_NAME;
/* This name form shall be represented by the Object Identifier {iso(1)
* member-body(2) United States(840) mit(113554) infosys(1) gssapi(2)
* krb5(2) krb5_name(1)}. The recommended symbolic name for this type
* is "GSS_KRB5_NT_PRINCIPAL_NAME". */
/* 2.1.2. Host-Based Service Name Form */
#define GSS_KRB5_NT_HOSTBASED_SERVICE_NAME GSS_C_NT_HOSTBASED_SERVICE
/* This name form shall be represented by the Object Identifier {iso(1)
* member-body(2) United States(840) mit(113554) infosys(1) gssapi(2)
* generic(1) service_name(4)}. The previously recommended symbolic
* name for this type is "GSS_KRB5_NT_HOSTBASED_SERVICE_NAME". The
* currently preferred symbolic name for this type is
* "GSS_C_NT_HOSTBASED_SERVICE". */
/* 2.2.1. User Name Form */
#define GSS_KRB5_NT_USER_NAME GSS_C_NT_USER_NAME
/* This name form shall be represented by the Object Identifier {iso(1)
* member-body(2) United States(840) mit(113554) infosys(1) gssapi(2)
* generic(1) user_name(1)}. The recommended symbolic name for this
* type is "GSS_KRB5_NT_USER_NAME". */
/* 2.2.2. Machine UID Form */
#define GSS_KRB5_NT_MACHINE_UID_NAME GSS_C_NT_MACHINE_UID_NAME
/* This name form shall be represented by the Object Identifier {iso(1)
* member-body(2) United States(840) mit(113554) infosys(1) gssapi(2)
* generic(1) machine_uid_name(2)}. The recommended symbolic name for
* this type is "GSS_KRB5_NT_MACHINE_UID_NAME". */
/* 2.2.3. String UID Form */
#define GSS_KRB5_NT_STRING_UID_NAME GSS_C_NT_STRING_UID_NAME
/* This name form shall be represented by the Object Identifier {iso(1)
* member-body(2) United States(840) mit(113554) infosys(1) gssapi(2)
* generic(1) string_uid_name(3)}. The recommended symbolic name for
* this type is "GSS_KRB5_NT_STRING_UID_NAME". */
GSS_DLLIMP extern const gss_OID_desc * const gss_mech_krb5;
GSS_DLLIMP extern const gss_OID_desc * const gss_mech_krb5_old;
GSS_DLLIMP extern const gss_OID_desc * const gss_mech_krb5_wrong;
GSS_DLLIMP extern const gss_OID_set_desc * const gss_mech_set_krb5;
GSS_DLLIMP extern const gss_OID_set_desc * const gss_mech_set_krb5_old;
GSS_DLLIMP extern const gss_OID_set_desc * const gss_mech_set_krb5_both;
GSS_DLLIMP extern const gss_OID_desc * const gss_nt_krb5_name;
GSS_DLLIMP extern const gss_OID_desc * const gss_nt_krb5_principal;
GSS_DLLIMP extern const gss_OID_desc krb5_gss_oid_array[];
#define gss_krb5_nt_general_name gss_nt_krb5_name
#define gss_krb5_nt_principal gss_nt_krb5_principal
#define gss_krb5_nt_service_name gss_nt_service_name
#define gss_krb5_nt_user_name gss_nt_user_name
#define gss_krb5_nt_machine_uid_name gss_nt_machine_uid_name
#define gss_krb5_nt_string_uid_name gss_nt_string_uid_name
#if defined(_WIN32)
typedef unsigned __int64 gss_uint64;
#else /*windows*/
#ifdef _KERNEL
#include <sys/inttypes.h>
#else /* _KERNEL */
#include <inttypes.h>
#endif /* _KERNEL */
typedef uint64_t gss_uint64;
#endif
typedef struct gss_krb5_lucid_key {
OM_uint32 type; /* key encryption type */
OM_uint32 length; /* length of key data */
void * data; /* actual key data */
} gss_krb5_lucid_key_t;
typedef struct gss_krb5_rfc1964_keydata {
OM_uint32 sign_alg; /* signing algorthm */
OM_uint32 seal_alg; /* seal/encrypt algorthm */
gss_krb5_lucid_key_t ctx_key;
/* Context key
(Kerberos session key or subkey) */
} gss_krb5_rfc1964_keydata_t;
typedef struct gss_krb5_cfx_keydata {
OM_uint32 have_acceptor_subkey;
/* 1 if there is an acceptor_subkey
present, 0 otherwise */
gss_krb5_lucid_key_t ctx_key;
/* Context key
(Kerberos session key or subkey) */
gss_krb5_lucid_key_t acceptor_subkey;
/* acceptor-asserted subkey or
0's if no acceptor subkey */
} gss_krb5_cfx_keydata_t;
typedef struct gss_krb5_lucid_context_v1 {
OM_uint32 version; /* Structure version number (1)
MUST be at beginning of struct! */
OM_uint32 initiate; /* Are we the initiator? */
OM_uint32 endtime; /* expiration time of context */
gss_uint64 send_seq; /* sender sequence number */
gss_uint64 recv_seq; /* receive sequence number */
OM_uint32 protocol; /* 0: rfc1964,
1: draft-ietf-krb-wg-gssapi-cfx-07 */
/*
* if (protocol == 0) rfc1964_kd should be used
* and cfx_kd contents are invalid and should be zero
* if (protocol == 1) cfx_kd should be used
* and rfc1964_kd contents are invalid and should be zero
*/
gss_krb5_rfc1964_keydata_t rfc1964_kd;
gss_krb5_cfx_keydata_t cfx_kd;
} gss_krb5_lucid_context_v1_t;
/*
* Mask for determining the returned structure version.
* See example below for usage.
*/
typedef struct gss_krb5_lucid_context_version {
OM_uint32 version; /* Structure version number */
} gss_krb5_lucid_context_version_t;
/* Alias for Heimdal compat. */
#define gsskrb5_register_acceptor_identity krb5_gss_register_acceptor_identity
OM_uint32 KRB5_CALLCONV krb5_gss_register_acceptor_identity(const char *);
OM_uint32 KRB5_CALLCONV gss_krb5_copy_ccache
(OM_uint32 *minor_status,
gss_cred_id_t cred_handle,
krb5_ccache out_ccache);
OM_uint32 KRB5_CALLCONV gss_krb5_ccache_name
(OM_uint32 *minor_status, const char *name,
const char **out_name);
/*
* gss_krb5_set_allowable_enctypes
*
* This function may be called by a context initiator after calling
* gss_acquire_cred(), but before calling gss_init_sec_context(),
* to restrict the set of enctypes which will be negotiated during
* context establishment to those in the provided array.
*
* 'cred' must be a valid credential handle obtained via
* gss_acquire_cred(). It may not be GSS_C_NO_CREDENTIAL.
* gss_acquire_cred() may have been called to get a handle to
* the default credential.
*
* The purpose of this function is to limit the keys that may
* be exported via gss_krb5_export_lucid_sec_context(); thus it
* should limit the enctypes of all keys that will be needed
* after the security context has been established.
* (i.e. context establishment may use a session key with a
* stronger enctype than in the provided array, however a
* subkey must be established within the enctype limits
* established by this function.)
*
*/
OM_uint32 KRB5_CALLCONV
gss_krb5_set_allowable_enctypes(OM_uint32 *minor_status,
gss_cred_id_t cred,
OM_uint32 num_ktypes,
krb5_enctype *ktypes);
/*
* Returns a non-opaque (lucid) version of the internal context
* information.
*
* Note that context_handle must not be used again by the caller
* after this call. The GSS implementation is free to release any
* resources associated with the original context. It is up to the
* GSS implementation whether it returns pointers to existing data,
* or copies of the data. The caller should treat the returned
* lucid context as read-only.
*
* The caller must call gss_krb5_free_lucid_context() to free
* the context and allocated resources when it is finished with it.
*
* 'version' is an integer indicating the highest version of lucid
* context understood by the caller. The highest version
* understood by both the caller and the GSS implementation must
* be returned. The caller can determine which version of the
* structure was actually returned by examining the version field
* of the returned structure. gss_krb5_lucid_context_version_t
* may be used as a mask to examine the returned structure version.
*
* If there are no common versions, an error should be returned.
* (XXX Need error definition(s))
*
* For example:
* void *return_ctx;
* gss_krb5_lucid_context_v1_t *ctx;
* OM_uint32 min_stat, maj_stat;
* OM_uint32 vers;
* gss_ctx_id_t *ctx_handle;
*
* maj_stat = gss_krb5_export_lucid_sec_context(&min_stat,
* ctx_handle, 1, &return_ctx);
* // Verify success
*
* vers = ((gss_krb5_lucid_context_version_t *)return_ctx)->version;
* switch (vers) {
* case 1:
* ctx = (gss_krb5_lucid_context_v1_t *) return_ctx;
* break;
* default:
* // Error, unknown version returned
* break;
* }
*
*/
OM_uint32 KRB5_CALLCONV
gss_krb5_export_lucid_sec_context(OM_uint32 *minor_status,
gss_ctx_id_t *context_handle,
OM_uint32 version,
void **kctx);
/*
* Frees the allocated storage associated with an
* exported struct gss_krb5_lucid_context.
*/
OM_uint32 KRB5_CALLCONV
gss_krb5_free_lucid_sec_context(OM_uint32 *minor_status,
void *kctx);
OM_uint32 KRB5_CALLCONV
gsskrb5_extract_authz_data_from_sec_context(OM_uint32 *minor_status,
const gss_ctx_id_t context_handle,
int ad_type,
gss_buffer_t ad_data);
OM_uint32 KRB5_CALLCONV
gss_krb5_set_cred_rcache(OM_uint32 *minor_status,
gss_cred_id_t cred,
krb5_rcache rcache);
OM_uint32 KRB5_CALLCONV
gsskrb5_extract_authtime_from_sec_context(OM_uint32 *, gss_ctx_id_t, krb5_timestamp *);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* _GSSAPI_KRB5_H_ */
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* 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 "k5-int.h"
extern const struct krb5_hash_provider krb5int_hash_crc32;
extern const struct krb5_hash_provider krb5int_hash_md5;
extern const struct krb5_hash_provider krb5int_hash_sha1;
/*
* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Copyright (C) 1989,1990,1991,1992,1993,1994,1995,2000,2001, 2003,2006,2009 by the Massachusetts Institute of Technology,
* Cambridge, MA, USA. All Rights Reserved.
*
* This software is being provided to you, the LICENSEE, by the
* Massachusetts Institute of Technology (M.I.T.) under the following
* license. By obtaining, using and/or copying this software, you agree
* that you have read, understood, and will comply with these terms and
* conditions:
*
* 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 or
* royalty is hereby granted, provided that you agree to comply with the
* following copyright notice and statements, including the disclaimer, and
* that the same appear on ALL copies of the software and documentation,
* including modifications that you make for internal use or for
* distribution:
*
* THIS SOFTWARE IS PROVIDED "AS IS", AND M.I.T. MAKES NO REPRESENTATIONS
* OR WARRANTIES, EXPRESS OR IMPLIED. By way of example, but not
* limitation, M.I.T. MAKES NO REPRESENTATIONS OR WARRANTIES OF
* MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF
* THE LICENSED SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY
* PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
*
* The name of the Massachusetts Institute of Technology or M.I.T. may NOT
* be used in advertising or publicity pertaining to distribution of the
* software. Title to copyright in this software and any associated
* documentation shall at all times remain with M.I.T., and USER agrees to
* preserve same.
*
* 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.
*/
/*
* 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.
*/
/*
* This prototype for k5-int.h (Krb5 internals include file)
* includes the user-visible definitions from krb5.h and then
* includes other definitions that are not user-visible but are
* required for compiling Kerberos internal routines.
*
* John Gilmore, Cygnus Support, Sat Jan 21 22:45:52 PST 1995
*/
#ifndef _KRB5_INT_H
#define _KRB5_INT_H
#ifdef KRB5_GENERAL__
#error krb5.h included before k5-int.h
#endif /* KRB5_GENERAL__ */
#ifndef _KERNEL
#include <osconf.h>
#include <security/cryptoki.h>
#else
#include <sys/crypto/common.h>
#include <sys/crypto/api.h>
#endif
#ifdef DEBUG
#if !defined(KRB5_DEBUG)
#define KRB5_DEBUG
#endif
#ifndef KRB5_LOG_LVL
#define KRB5_LOG_LVL KRB5_ERR
#endif
#endif /* DEBUG */
#ifdef _KERNEL
#ifdef DEBUG
#include <sys/types.h>
#include <sys/cmn_err.h>
extern void prom_printf();
#endif /* DEBUG */
#else /* !_KERNEL */
#define prom_printf printf
#endif /* !_KERNEL */
#ifdef KRB5_LOG_LVL
/* krb5_log is used to set the logging level to determine what class of messages
* are output by the mech. Note, more than one logging level can be used by
* bit or'ing the log values together.
*
* All log messages are captured by syslog.
*/
extern unsigned int krb5_log;
/* Note, these defines should be mutually exclusive bit fields */
#define KRB5_ERR 1 /* Use this debug log level for error path logging. */
#define KRB5_INFO 2 /* Use this debug log level for informational messages. */
#ifdef _KERNEL
#define KRB5_LOG1(A, B, C, D) \
((void)((krb5_log) && (krb5_log & (A)) && (printf((B), (C), (D)), TRUE)))
#define KRB5_LOG(A, B, C) \
((void)((krb5_log) && (krb5_log & (A)) && (printf((B), (C)), TRUE)))
#define KRB5_LOG0(A, B) \
((void)((krb5_log) && (krb5_log & (A)) && (printf((B)), TRUE)))
#else /* !_KERNEL */
#include <syslog.h>
#define KRB5_LOG1(A, B, C, D) \
((void)((krb5_log) && (krb5_log & (A)) && \
(syslog(LOG_DEBUG, (B), (C), (D)), TRUE)))
#define KRB5_LOG(A, B, C) \
((void)((krb5_log) && (krb5_log & (A)) && \
(syslog(LOG_DEBUG, (B), (C)), TRUE)))
#define KRB5_LOG0(A, B) \
((void)((krb5_log) && (krb5_log & (A)) && \
(syslog(LOG_DEBUG, B), TRUE)))
#endif /* _KERNEL */
#else /* ! KRB5_LOG_LVL */
#define KRB5_LOG1(A, B, C, D)
#define KRB5_LOG(A, B, C)
#define KRB5_LOG0(A, B)
#endif /* KRB5_LOG_LVL */
#ifdef POSIX_TYPES
#define timetype time_t
#else
#define timetype long
#endif
/*
* Begin "k5-config.h"
*/
#ifndef KRB5_CONFIG__
#define KRB5_CONFIG__
/*
* Machine-type definitions: PC Clone 386 running Microloss Windows
*/
#if defined(_MSDOS) || defined(_WIN32)
#include "win-mac.h"
/* Kerberos Windows initialization file */
#define KERBEROS_INI "kerberos.ini"
#define INI_FILES "Files"
#define INI_KRB_CCACHE "krb5cc" /* Location of the ccache */
#define INI_KRB5_CONF "krb5.ini" /* Location of krb5.conf file */
#define ANSI_STDIO
#endif
#ifndef _KERNEL
#ifndef KRB5_AUTOCONF__
#define KRB5_AUTOCONF__
#include "autoconf.h"
#endif
#endif /* !_KERNEL */
#ifndef KRB5_SYSTYPES__
#define KRB5_SYSTYPES__
#ifndef _KERNEL
#ifdef HAVE_SYS_TYPES_H /* From autoconf.h */
#include <sys/types.h>
#else /* HAVE_SYS_TYPES_H */
typedef unsigned long u_long;
typedef unsigned int u_int;
typedef unsigned short u_short;
typedef unsigned char u_char;
#endif /* HAVE_SYS_TYPES_H */
#endif /* KRB5_SYSTYPES__ */
#endif /* !_KERNEL */
/* #include "k5-platform.h" SUNW XXX */
/* not used in krb5.h (yet) */
typedef uint64_t krb5_ui_8;
typedef int64_t krb5_int64;
#define DEFAULT_PWD_STRING1 "Enter password:"
#define DEFAULT_PWD_STRING2 "Re-enter password for verification:"
#define KRB5_KDB_MAX_LIFE (60*60*24) /* one day */
#define KRB5_KDB_MAX_RLIFE (60*60*24*365) /* one year */
#define KRB5_KDB_EXPIRATION 2145830400 /* Thu Jan 1 00:00:00 2038 UTC */
#define KRB5_DEFAULT_LIFE 60*60*10 /* 10 hours */
#define KRB5_DEFAULT_RENEW_LIFE 7*24*60*60 /* 7 Days */
/*
* Windows requires a different api interface to each function. Here
* just define it as NULL.
*/
#ifndef KRB5_CALLCONV
#define KRB5_CALLCONV
#define KRB5_CALLCONV_C
#endif
#ifndef O_BINARY
#define O_BINARY 0
#endif
#endif /* KRB5_CONFIG__ */
/*
* End "k5-config.h"
*/
/*
* After loading the configuration definitions, load the Kerberos definitions.
*/
#ifndef _KERNEL
#include <errno.h>
#include "profile.h"
#endif
#include <krb5.h>
#ifndef _KERNEL
#if 1 /* def NEED_SOCKETS */
#include <port-sockets.h>
#include <socket-utils.h>
#else
#ifndef SOCK_DGRAM
struct sockaddr;
#endif
#endif
#endif
/* Get mutex support; currently used only for the replay cache. */
#include "k5-thread.h"
/* krb5/krb5.h includes many other .h files in the krb5 subdirectory.
The ones that it doesn't include, we include below. */
/*
* Begin "k5-errors.h"
*/
#ifndef KRB5_ERRORS__
#define KRB5_ERRORS__
/* Error codes used in KRB_ERROR protocol messages.
Return values of library routines are based on a different error table
(which allows non-ambiguous error codes between subsystems) */
/* KDC errors */
#define KDC_ERR_NONE 0 /* No error */
#define KDC_ERR_NAME_EXP 1 /* Client's entry in DB expired */
#define KDC_ERR_SERVICE_EXP 2 /* Server's entry in DB expired */
#define KDC_ERR_BAD_PVNO 3 /* Requested pvno not supported */
#define KDC_ERR_C_OLD_MAST_KVNO 4 /* C's key encrypted in old master */
#define KDC_ERR_S_OLD_MAST_KVNO 5 /* S's key encrypted in old master */
#define KDC_ERR_C_PRINCIPAL_UNKNOWN 6 /* Client not found in Kerberos DB */
#define KDC_ERR_S_PRINCIPAL_UNKNOWN 7 /* Server not found in Kerberos DB */
#define KDC_ERR_PRINCIPAL_NOT_UNIQUE 8 /* Multiple entries in Kerberos DB */
#define KDC_ERR_NULL_KEY 9 /* The C or S has a null key */
#define KDC_ERR_CANNOT_POSTDATE 10 /* Tkt ineligible for postdating */
#define KDC_ERR_NEVER_VALID 11 /* Requested starttime > endtime */
#define KDC_ERR_POLICY 12 /* KDC policy rejects request */
#define KDC_ERR_BADOPTION 13 /* KDC can't do requested opt. */
#define KDC_ERR_ENCTYPE_NOSUPP 14 /* No support for encryption type */
#define KDC_ERR_SUMTYPE_NOSUPP 15 /* No support for checksum type */
#define KDC_ERR_PADATA_TYPE_NOSUPP 16 /* No support for padata type */
#define KDC_ERR_TRTYPE_NOSUPP 17 /* No support for transited type */
#define KDC_ERR_CLIENT_REVOKED 18 /* C's creds have been revoked */
#define KDC_ERR_SERVICE_REVOKED 19 /* S's creds have been revoked */
#define KDC_ERR_TGT_REVOKED 20 /* TGT has been revoked */
#define KDC_ERR_CLIENT_NOTYET 21 /* C not yet valid */
#define KDC_ERR_SERVICE_NOTYET 22 /* S not yet valid */
#define KDC_ERR_KEY_EXP 23 /* Password has expired */
#define KDC_ERR_PREAUTH_FAILED 24 /* Preauthentication failed */
#define KDC_ERR_PREAUTH_REQUIRED 25 /* Additional preauthentication */
/* required */
#define KDC_ERR_SERVER_NOMATCH 26 /* Requested server and */
/* ticket don't match*/
#define KDC_ERR_MUST_USE_USER2USER 27 /* Server principal valid for */
/* user2user only */
#define KDC_ERR_PATH_NOT_ACCEPTED 28 /* KDC policy rejected transited */
/* path */
#define KDC_ERR_SVC_UNAVAILABLE 29 /* A service is not
* available that is
* required to process the
* request */
/* Application errors */
#define KRB_AP_ERR_BAD_INTEGRITY 31 /* Decrypt integrity check failed */
#define KRB_AP_ERR_TKT_EXPIRED 32 /* Ticket expired */
#define KRB_AP_ERR_TKT_NYV 33 /* Ticket not yet valid */
#define KRB_AP_ERR_REPEAT 34 /* Request is a replay */
#define KRB_AP_ERR_NOT_US 35 /* The ticket isn't for us */
#define KRB_AP_ERR_BADMATCH 36 /* Ticket/authenticator don't match */
#define KRB_AP_ERR_SKEW 37 /* Clock skew too great */
#define KRB_AP_ERR_BADADDR 38 /* Incorrect net address */
#define KRB_AP_ERR_BADVERSION 39 /* Protocol version mismatch */
#define KRB_AP_ERR_MSG_TYPE 40 /* Invalid message type */
#define KRB_AP_ERR_MODIFIED 41 /* Message stream modified */
#define KRB_AP_ERR_BADORDER 42 /* Message out of order */
#define KRB_AP_ERR_BADKEYVER 44 /* Key version is not available */
#define KRB_AP_ERR_NOKEY 45 /* Service key not available */
#define KRB_AP_ERR_MUT_FAIL 46 /* Mutual authentication failed */
#define KRB_AP_ERR_BADDIRECTION 47 /* Incorrect message direction */
#define KRB_AP_ERR_METHOD 48 /* Alternative authentication */
/* method required */
#define KRB_AP_ERR_BADSEQ 49 /* Incorrect sequence numnber */
/* in message */
#define KRB_AP_ERR_INAPP_CKSUM 50 /* Inappropriate type of */
/* checksum in message */
#define KRB_AP_PATH_NOT_ACCEPTED 51 /* Policy rejects transited path */
#define KRB_ERR_RESPONSE_TOO_BIG 52 /* Response too big for UDP, */
/* retry with TCP */
/* other errors */
#define KRB_ERR_GENERIC 60 /* Generic error (description */
/* in e-text) */
#define KRB_ERR_FIELD_TOOLONG 61 /* Field is too long for impl. */
/* PKINIT server-reported errors */
#define KDC_ERR_CLIENT_NOT_TRUSTED 62 /* client cert not trusted */
#define KDC_ERR_INVALID_SIG 64 /* client signature verify failed */
#define KDC_ERR_DH_KEY_PARAMETERS_NOT_ACCEPTED 65 /* invalid Diffie-Hellman parameters */
#define KDC_ERR_CERTIFICATE_MISMATCH 66
#define KRB_AP_ERR_NO_TGT 67
#define KDC_ERR_WRONG_REALM 68
#define KRB_AP_ERR_USER_TO_USER_REQUIRED 69
#define KDC_ERR_CANT_VERIFY_CERTIFICATE 70 /* client cert not verifiable
to */
/* trusted root cert */
#define KDC_ERR_INVALID_CERTIFICATE 71 /* client cert had invalid signature */
#define KDC_ERR_REVOKED_CERTIFICATE 72 /* client cert was revoked */
#define KDC_ERR_REVOCATION_STATUS_UNKNOWN 73 /* client cert revoked, reason unknown */
#define KDC_ERR_CLIENT_NAME_MISMATCH 75 /* mismatch between client cert and */
/* principal name */
#define KDC_ERR_INCONSISTENT_KEY_PURPOSE 77 /* bad extended key use */
#define KDC_ERR_DIGEST_IN_CERT_NOT_ACCEPTED 78 /* bad digest algorithm in client cert */
#define KDC_ERR_PA_CHECKSUM_MUST_BE_INCLUDED 79 /* missing paChecksum in PA-PK-AS-REQ */
#define KDC_ERR_DIGEST_IN_SIGNED_DATA_NOT_ACCEPTED 80 /* bad digest algorithm in SignedData */
#define KDC_ERR_PUBLIC_KEY_ENCRYPTION_NOT_SUPPORTED 81
#endif /* KRB5_ERRORS__ */
/*
* End "k5-errors.h"
*/
/*
* This structure is returned in the e-data field of the KRB-ERROR
* message when the error calling for an alternative form of
* authentication is returned, KRB_AP_METHOD.
*/
typedef struct _krb5_alt_method {
krb5_magic magic;
krb5_int32 method;
unsigned int length;
krb5_octet *data;
} krb5_alt_method;
/*
* A null-terminated array of this structure is returned by the KDC as
* the data part of the ETYPE_INFO preauth type. It informs the
* client which encryption types are supported.
* The same data structure is used by both etype-info and etype-info2
* but s2kparams must be null when encoding etype-info.
*/
typedef struct _krb5_etype_info_entry {
krb5_magic magic;
krb5_enctype etype;
unsigned int length;
krb5_octet *salt;
krb5_data s2kparams;
} krb5_etype_info_entry;
/*
* This is essentially -1 without sign extension which can screw up
* comparisons on 64 bit machines. If the length is this value, then
* the salt data is not present. This is to distinguish between not
* being set and being of 0 length.
*/
#define KRB5_ETYPE_NO_SALT VALID_UINT_BITS
typedef krb5_etype_info_entry ** krb5_etype_info;
/* RFC 4537 */
typedef struct _krb5_etype_list {
int length;
krb5_enctype *etypes;
} krb5_etype_list;
/*
* a sam_challenge is returned for alternate preauth
*/
/*
SAMFlags ::= BIT STRING {
use-sad-as-key[0],
send-encrypted-sad[1],
must-pk-encrypt-sad[2]
}
*/
/*
PA-SAM-CHALLENGE ::= SEQUENCE {
sam-type[0] INTEGER,
sam-flags[1] SAMFlags,
sam-type-name[2] GeneralString OPTIONAL,
sam-track-id[3] GeneralString OPTIONAL,
sam-challenge-label[4] GeneralString OPTIONAL,
sam-challenge[5] GeneralString OPTIONAL,
sam-response-prompt[6] GeneralString OPTIONAL,
sam-pk-for-sad[7] EncryptionKey OPTIONAL,
sam-nonce[8] INTEGER OPTIONAL,
sam-cksum[9] Checksum OPTIONAL
}
*/
/* sam_type values -- informational only */
#define PA_SAM_TYPE_ENIGMA 1 /* Enigma Logic */
#define PA_SAM_TYPE_DIGI_PATH 2 /* Digital Pathways */
#define PA_SAM_TYPE_SKEY_K0 3 /* S/key where KDC has key 0 */
#define PA_SAM_TYPE_SKEY 4 /* Traditional S/Key */
#define PA_SAM_TYPE_SECURID 5 /* Security Dynamics */
#define PA_SAM_TYPE_CRYPTOCARD 6 /* CRYPTOCard */
#if 1 /* XXX need to figure out who has which numbers assigned */
#define PA_SAM_TYPE_ACTIVCARD_DEC 6 /* ActivCard decimal mode */
#define PA_SAM_TYPE_ACTIVCARD_HEX 7 /* ActivCard hex mode */
#define PA_SAM_TYPE_DIGI_PATH_HEX 8 /* Digital Pathways hex mode */
#endif
#define PA_SAM_TYPE_EXP_BASE 128 /* experimental */
#define PA_SAM_TYPE_GRAIL (PA_SAM_TYPE_EXP_BASE+0) /* testing */
#define PA_SAM_TYPE_SECURID_PREDICT (PA_SAM_TYPE_EXP_BASE+1) /* special */
typedef struct _krb5_predicted_sam_response {
krb5_magic magic;
krb5_keyblock sam_key;
krb5_flags sam_flags; /* Makes key munging easier */
krb5_timestamp stime; /* time on server, for replay detection */
krb5_int32 susec;
krb5_principal client;
krb5_data msd; /* mechanism specific data */
} krb5_predicted_sam_response;
typedef struct _krb5_sam_challenge {
krb5_magic magic;
krb5_int32 sam_type; /* information */
krb5_flags sam_flags; /* KRB5_SAM_* values */
krb5_data sam_type_name;
krb5_data sam_track_id;
krb5_data sam_challenge_label;
krb5_data sam_challenge;
krb5_data sam_response_prompt;
krb5_data sam_pk_for_sad;
krb5_int32 sam_nonce;
krb5_checksum sam_cksum;
} krb5_sam_challenge;
typedef struct _krb5_sam_key { /* reserved for future use */
krb5_magic magic;
krb5_keyblock sam_key;
} krb5_sam_key;
typedef struct _krb5_enc_sam_response_enc {
krb5_magic magic;
krb5_int32 sam_nonce;
krb5_timestamp sam_timestamp;
krb5_int32 sam_usec;
krb5_data sam_sad;
} krb5_enc_sam_response_enc;
typedef struct _krb5_sam_response {
krb5_magic magic;
krb5_int32 sam_type; /* informational */
krb5_flags sam_flags; /* KRB5_SAM_* values */
krb5_data sam_track_id; /* copied */
krb5_enc_data sam_enc_key; /* krb5_sam_key - future use */
krb5_enc_data sam_enc_nonce_or_ts; /* krb5_enc_sam_response_enc */
krb5_int32 sam_nonce;
krb5_timestamp sam_patimestamp;
} krb5_sam_response;
typedef struct _krb5_sam_challenge_2 {
krb5_data sam_challenge_2_body;
krb5_checksum **sam_cksum; /* Array of checksums */
} krb5_sam_challenge_2;
typedef struct _krb5_sam_challenge_2_body {
krb5_magic magic;
krb5_int32 sam_type; /* information */
krb5_flags sam_flags; /* KRB5_SAM_* values */
krb5_data sam_type_name;
krb5_data sam_track_id;
krb5_data sam_challenge_label;
krb5_data sam_challenge;
krb5_data sam_response_prompt;
krb5_data sam_pk_for_sad;
krb5_int32 sam_nonce;
krb5_enctype sam_etype;
} krb5_sam_challenge_2_body;
typedef struct _krb5_sam_response_2 {
krb5_magic magic;
krb5_int32 sam_type; /* informational */
krb5_flags sam_flags; /* KRB5_SAM_* values */
krb5_data sam_track_id; /* copied */
krb5_enc_data sam_enc_nonce_or_sad; /* krb5_enc_sam_response_enc */
krb5_int32 sam_nonce;
} krb5_sam_response_2;
typedef struct _krb5_enc_sam_response_enc_2 {
krb5_magic magic;
krb5_int32 sam_nonce;
krb5_data sam_sad;
} krb5_enc_sam_response_enc_2;
/*
* Keep the pkinit definitions in a separate file so that the plugin
* only has to include k5-int-pkinit.h rather than k5-int.h
*/
#include "k5-int-pkinit.h"
/*
* Begin "dbm.h"
*/
#ifndef _KERNEL
/*
* Since we are always using db, use the db-ndbm include header file.
*/
#include "db-ndbm.h"
#endif /* !KERNEL */
/*
* End "dbm.h"
*/
/*
* Begin "ext-proto.h"
*/
#ifndef KRB5_EXT_PROTO__
#define KRB5_EXT_PROTO__
#ifndef _KERNEL
#include <stdlib.h>
#include <string.h>
#endif /* !_KERNEL */
#ifndef HAVE_STRDUP
extern char *strdup (const char *);
#endif
#ifndef _KERNEL
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#endif /* !_KERNEL */
#endif /* KRB5_EXT_PROTO__ */
/*
* End "ext-proto.h"
*/
/*
* Begin "sysincl.h"
*/
#ifndef KRB5_SYSINCL__
#define KRB5_SYSINCL__
#ifndef KRB5_SYSTYPES__
#define KRB5_SYSTYPES__
/* needed for much of the rest -- but already handled in krb5.h? */
/* #include <sys/types.h> */
#endif /* KRB5_SYSTYPES__ */
#ifdef _KERNEL
#include <sys/time.h>
#else
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#ifdef TIME_WITH_SYS_TIME
#include <time.h>
#endif
#else
#include <time.h>
#endif
#endif /* _KERNEL */
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h> /* struct stat, stat() */
#endif
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h> /* MAXPATHLEN */
#endif
#ifdef HAVE_SYS_FILE_H
#include <sys/file.h> /* prototypes for file-related
syscalls; flags for open &
friends */
#endif
#ifdef _KERNEL
#include <sys/fcntl.h>
#else
#include <fcntl.h>
#endif
#endif /* KRB5_SYSINCL__ */
/*
* End "sysincl.h"
*/
/*
* Begin "los-proto.h"
*/
#ifndef KRB5_LIBOS_PROTO__
#define KRB5_LIBOS_PROTO__
#endif
#ifndef _KERNEL
#include <stdio.h>
struct addrlist;
struct sendto_callback_info;
#endif
/* libos.spec */
krb5_error_code krb5_lock_file (krb5_context, int, int);
krb5_error_code krb5_unlock_file (krb5_context, int);
krb5_error_code krb5_sendto_kdc (krb5_context, const krb5_data *,
const krb5_data *, krb5_data *, int *, int);
/* Solaris Kerberos */
krb5_error_code krb5_sendto_kdc2 (krb5_context, const krb5_data *,
const krb5_data *, krb5_data *, int *, int,
char **);
krb5_error_code krb5_get_krbhst (krb5_context, const krb5_data *, char *** );
krb5_error_code krb5_free_krbhst (krb5_context, char * const * );
krb5_error_code krb5_create_secure_file (krb5_context, const char * pathname);
int krb5_net_read (krb5_context, int , char *, int);
int krb5_net_write
(krb5_context, int , const char *, int);
krb5_error_code krb5_gen_replay_name
(krb5_context, const krb5_address *, const char *, char **);
#ifndef _KERNEL
krb5_error_code krb5_sync_disk_file (krb5_context, FILE *fp);
krb5_error_code
krb5_open_pkcs11_session(CK_SESSION_HANDLE *);
krb5_error_code krb5_read_message
(krb5_context, krb5_pointer, krb5_data *);
krb5_error_code krb5_write_message
(krb5_context, krb5_pointer, krb5_data *);
krb5_error_code krb5int_sendto (krb5_context context, const krb5_data *message,
const struct addrlist *addrs, struct sendto_callback_info* callback_info,
krb5_data *reply, struct sockaddr *localaddr, socklen_t *localaddrlen,
struct sockaddr *remoteaddr, socklen_t *remoteaddrlen, int *addr_used,
int (*msg_handler)(krb5_context, const krb5_data *, void *),
void *msg_handler_data);
krb5_error_code krb5int_get_fq_local_hostname (char *, size_t);
krb5_error_code krb5_set_debugging_time
(krb5_context, krb5_timestamp, krb5_int32);
krb5_error_code krb5_use_natural_time
(krb5_context);
krb5_error_code krb5_set_time_offsets
(krb5_context, krb5_timestamp, krb5_int32);
krb5_error_code krb5int_check_clockskew(krb5_context, krb5_timestamp);
#endif
/*
* Solaris Kerberos
* The following two functions are needed for better realm
* determination based on the DNS domain name.
*/
krb5_error_code krb5int_lookup_host(int , const char *, char **);
krb5_error_code krb5int_domain_get_realm(krb5_context, const char *,
char **);
krb5_error_code krb5int_fqdn_get_realm(krb5_context, const char *,
char **);
krb5_error_code krb5int_init_context_kdc(krb5_context *);
krb5_error_code krb5_os_init_context (krb5_context, krb5_boolean);
void krb5_os_free_context (krb5_context);
/* This function is needed by KfM's KerberosPreferences API
* because it needs to be able to specify "secure" */
#ifndef _KERNEL
krb5_error_code os_get_default_config_files
(profile_filespec_t **pfiles, krb5_boolean secure);
#endif
krb5_error_code krb5_os_hostaddr
(krb5_context, const char *, krb5_address ***);
#ifndef _KERNEL
/* N.B.: You need to include fake-addrinfo.h *before* k5-int.h if you're
going to use this structure. */
struct addrlist {
struct {
#ifdef FAI_DEFINED
struct addrinfo *ai;
#else
struct undefined_addrinfo *ai;
#endif
void (*freefn)(void *);
void *data;
} *addrs;
int naddrs;
int space;
};
#define ADDRLIST_INIT { 0, 0, 0 }
extern void krb5int_free_addrlist (struct addrlist *);
extern int krb5int_grow_addrlist (struct addrlist *, int);
extern int krb5int_add_host_to_list (struct addrlist *, const char *,
int, int, int, int);
#include <locate_plugin.h>
krb5_error_code
krb5int_locate_server (krb5_context, const krb5_data *realm,
struct addrlist *, enum locate_service_type svc,
int sockettype, int family);
#endif /* _KERNEL */
/* new encryption provider api */
struct krb5_enc_provider {
/* keybytes is the input size to make_key;
keylength is the output size */
size_t block_size, keybytes, keylength;
/* cipher-state == 0 fresh state thrown away at end */
krb5_error_code (*encrypt) (
krb5_context context,
krb5_const krb5_keyblock *key, krb5_const krb5_data *ivec,
krb5_const krb5_data *input, krb5_data *output);
krb5_error_code (*decrypt) (
krb5_context context,
krb5_const krb5_keyblock *key, krb5_const krb5_data *ivec,
krb5_const krb5_data *input, krb5_data *output);
krb5_error_code (*make_key)
(krb5_context, krb5_const krb5_data *, krb5_keyblock *);
krb5_error_code (*init_state) (krb5_context,
const krb5_keyblock *,
krb5_keyusage, krb5_data *);
krb5_error_code (*free_state) (krb5_context, krb5_data *);
};
struct krb5_hash_provider {
size_t hashsize, blocksize;
/* this takes multiple inputs to avoid lots of copying. */
krb5_error_code (*hash) (krb5_context context,
unsigned int icount, krb5_const krb5_data *input,
krb5_data *output);
};
struct krb5_keyhash_provider {
size_t hashsize;
krb5_error_code (*hash) (
krb5_context context,
krb5_const krb5_keyblock *key,
krb5_keyusage keyusage,
krb5_const krb5_data *ivec,
krb5_const krb5_data *input, krb5_data *output);
krb5_error_code (*verify) (
krb5_context context,
krb5_const krb5_keyblock *key,
krb5_keyusage keyusage,
krb5_const krb5_data *ivec,
krb5_const krb5_data *input,
krb5_const krb5_data *hash,
krb5_boolean *valid);
};
typedef void (*krb5_encrypt_length_func) (const struct krb5_enc_provider *enc,
const struct krb5_hash_provider *hash,
size_t inputlen, size_t *length);
typedef krb5_error_code (*krb5_crypt_func) (
krb5_context context,
krb5_const struct krb5_enc_provider *enc,
krb5_const struct krb5_hash_provider *hash,
krb5_const krb5_keyblock *key, krb5_keyusage usage,
krb5_const krb5_data *ivec,
krb5_const krb5_data *input, krb5_data *output);
#ifndef _KERNEL
typedef krb5_error_code (*krb5_str2key_func) (
krb5_context context,
krb5_const struct krb5_enc_provider *enc, krb5_const krb5_data *string,
krb5_const krb5_data *salt, krb5_const krb5_data *params,
krb5_keyblock *key);
#endif /* _KERNEL */
typedef krb5_error_code (*krb5_prf_func)(
const struct krb5_enc_provider *enc,
const struct krb5_hash_provider *hash,
const krb5_keyblock *key,
const krb5_data *in, krb5_data *out);
struct krb5_keytypes {
krb5_enctype etype;
char *in_string;
char *out_string;
const struct krb5_enc_provider *enc;
const struct krb5_hash_provider *hash;
krb5_encrypt_length_func encrypt_len;
krb5_crypt_func encrypt;
krb5_crypt_func decrypt;
krb5_cksumtype required_ctype;
#ifndef _KERNEL
/* Solaris Kerberos: strings to key conversion not done in the kernel */
krb5_str2key_func str2key;
#else /* _KERNEL */
char *mt_e_name;
char *mt_h_name;
crypto_mech_type_t kef_cipher_mt;
crypto_mech_type_t kef_hash_mt;
#endif /* _KERNEL */
};
struct krb5_cksumtypes {
krb5_cksumtype ctype;
unsigned int flags;
char *in_string;
char *out_string;
/* if the hash is keyed, this is the etype it is keyed with.
Actually, it can be keyed by any etype which has the same
enc_provider as the specified etype. DERIVE checksums can
be keyed with any valid etype. */
krb5_enctype keyed_etype;
/* I can't statically initialize a union, so I'm just going to use
two pointers here. The keyhash is used if non-NULL. If NULL,
then HMAC/hash with derived keys is used if the relevant flag
is set. Otherwise, a non-keyed hash is computed. This is all
kind of messy, but so is the krb5 api. */
const struct krb5_keyhash_provider *keyhash;
const struct krb5_hash_provider *hash;
/* This just gets uglier and uglier. In the key derivation case,
we produce an hmac. To make the hmac code work, we can't hack
the output size indicated by the hash provider, but we may want
a truncated hmac. If we want truncation, this is the number of
bytes we truncate to; it should be 0 otherwise. */
unsigned int trunc_size;
#ifdef _KERNEL
char *mt_c_name;
crypto_mech_type_t kef_cksum_mt;
#endif /* _KERNEL */
};
#define KRB5_CKSUMFLAG_DERIVE 0x0001
#define KRB5_CKSUMFLAG_NOT_COLL_PROOF 0x0002
/*
* in here to deal with stuff from lib/crypto
*/
void krb5_nfold
(unsigned int inbits, const unsigned char *in,
unsigned int outbits, unsigned char *out);
krb5_error_code krb5int_pbkdf2_hmac_sha1 (krb5_context,
const krb5_data *,
unsigned long,
krb5_enctype,
const krb5_data *,
const krb5_data *);
/* Make this a function eventually? */
#ifdef _WIN32
# define krb5int_zap_data(ptr, len) SecureZeroMemory(ptr, len)
#elif defined(__palmos__) && !defined(__GNUC__)
/* CodeWarrior 8.3 complains about passing a pointer to volatile in to
memset. On the other hand, we probably want it for gcc. */
# define krb5int_zap_data(ptr, len) memset(ptr, 0, len)
#else
# define krb5int_zap_data(ptr, len) memset((void *)ptr, 0, len)
# if defined(__GNUC__) && defined(__GLIBC__)
/* GNU libc generates multiple bogus initialization warnings if we
pass memset a volatile pointer. The compiler should do well enough
with memset even without GNU libc's attempt at optimization. */
# undef memset
# endif
#endif /* WIN32 */
#define zap(p,l) krb5int_zap_data(p,l)
krb5_error_code krb5int_des_init_state
( krb5_context,
const krb5_keyblock *,
krb5_keyusage, krb5_data *);
krb5_error_code krb5int_c_mandatory_cksumtype(
krb5_context,
krb5_enctype,
krb5_cksumtype *);
/*
* normally to free a cipher_state you can just memset the length to zero and
* free it.
*/
krb5_error_code krb5int_default_free_state
(krb5_context, krb5_data *);
/*
* Combine two keys (normally used by the hardware preauth mechanism)
*/
krb5_error_code krb5int_c_combine_keys
(krb5_context context, krb5_keyblock *key1, krb5_keyblock *key2,
krb5_keyblock *outkey);
#ifdef _KERNEL
int k5_ef_crypto(
const char *, char *,
long, krb5_keyblock *,
const krb5_data *, int);
krb5_error_code
krb5_hmac(krb5_context, const krb5_keyblock *,
krb5_const krb5_data *, krb5_data *);
#else
krb5_error_code krb5_hmac
(krb5_context,
krb5_const struct krb5_hash_provider *,
krb5_const krb5_keyblock *, krb5_const unsigned int,
krb5_const krb5_data *, krb5_data *);
#endif /* _KERNEL */
/*
* These declarations are here, so both krb5 and k5crypto
* can get to them.
* krb5 needs to get to them so it can make them available to libgssapi.
*/
extern const struct krb5_enc_provider krb5int_enc_arcfour;
extern const struct krb5_hash_provider krb5int_hash_md5;
/* #ifdef KRB5_OLD_CRYPTO XXX SUNW14resync */
krb5_error_code krb5_crypto_us_timeofday
(krb5_int32 *,
krb5_int32 *);
#ifndef _KERNEL
/* Solaris kerberos: for convenience */
time_t krb5int_gmt_mktime (struct tm *);
#endif /* ! _KERNEL */
/* #endif KRB5_OLD_CRYPTO */
/* this helper fct is in libkrb5, but it makes sense declared here. */
krb5_error_code krb5_encrypt_helper
(krb5_context context, const krb5_keyblock *key,
krb5_keyusage keyusage, const krb5_data *plain,
krb5_enc_data *cipher);
/*
* End "los-proto.h"
*/
/*
* Begin "libos.h"
*/
#ifndef KRB5_LIBOS__
#define KRB5_LIBOS__
typedef struct _krb5_os_context {
krb5_magic magic;
krb5_int32 time_offset;
krb5_int32 usec_offset;
krb5_int32 os_flags;
char * default_ccname;
} *krb5_os_context;
/*
* Flags for the os_flags field
*
* KRB5_OS_TOFFSET_VALID means that the time offset fields are valid.
* The intention is that this facility to correct the system clocks so
* that they reflect the "real" time, for systems where for some
* reason we can't set the system clock. Instead we calculate the
* offset between the system time and real time, and store the offset
* in the os context so that we can correct the system clock as necessary.
*
* KRB5_OS_TOFFSET_TIME means that the time offset fields should be
* returned as the time by the krb5 time routines. This should only
* be used for testing purposes (obviously!)
*/
#define KRB5_OS_TOFFSET_VALID 1
#define KRB5_OS_TOFFSET_TIME 2
/* lock mode flags */
#define KRB5_LOCKMODE_SHARED 0x0001
#define KRB5_LOCKMODE_EXCLUSIVE 0x0002
#define KRB5_LOCKMODE_DONTBLOCK 0x0004
#define KRB5_LOCKMODE_UNLOCK 0x0008
#endif /* KRB5_LIBOS__ */
/*
* End "libos.h"
*/
/*
* Define our view of the size of a DES key.
*/
#define KRB5_MIT_DES_KEYSIZE 8
/*
* Define a couple of SHA1 constants
*/
#define SHS_DATASIZE 64
#define SHS_DIGESTSIZE 20
/*
* Check if des_int.h has been included before us. If so, then check to see
* that our view of the DES key size is the same as des_int.h's.
*/
#ifdef MIT_DES_KEYSIZE
#if MIT_DES_KEYSIZE != KRB5_MIT_DES_KEYSIZE
error(MIT_DES_KEYSIZE does not equal KRB5_MIT_DES_KEYSIZE)
#endif /* MIT_DES_KEYSIZE != KRB5_MIT_DES_KEYSIZE */
#endif /* MIT_DES_KEYSIZE */
#ifndef _KERNEL
/* Solaris Kerberos: only define PROVIDE_DES3_CBC_SHA if the following are
* defined.
*/
#define PROVIDE_DES3_CBC_SHA 1
#define PROVIDE_NIST_SHA 1
#endif /* !_KERNEL */
/*
* Begin "preauth.h"
*
* (Originally written by Glen Machin at Sandia Labs.)
*/
/*
* Sandia National Laboratories also makes no representations about the
* suitability of the modifications, or additions to this software for
* any purpose. It is provided "as is" without express or implied warranty.
*
*/
#ifndef KRB5_PREAUTH__
#define KRB5_PREAUTH__
#include <preauth_plugin.h>
#define CLIENT_ROCK_MAGIC 0x4352434b
/* This structure is passed into the client preauth functions and passed
* back to the "get_data_proc" function so that it can locate the
* requested information. It is opaque to the plugin code and can be
* expanded in the future as new types of requests are defined which
* may require other things to be passed through. */
typedef struct _krb5_preauth_client_rock {
krb5_magic magic;
krb5_kdc_rep *as_reply;
} krb5_preauth_client_rock;
/* This structure lets us keep track of all of the modules which are loaded,
* turning the list of modules and their lists of implemented preauth types
* into a single list which we can walk easily. */
typedef struct _krb5_preauth_context {
int n_modules;
struct _krb5_preauth_context_module {
/* Which of the possibly more than one preauth types which the
* module supports we're using at this point in the list. */
krb5_preauthtype pa_type;
/* Encryption types which the client claims to support -- we
* copy them directly into the krb5_kdc_req structure during
* krb5_preauth_prepare_request(). */
krb5_enctype *enctypes;
/* The plugin's per-plugin context and a function to clear it. */
void *plugin_context;
preauth_client_plugin_fini_proc client_fini;
/* The module's table, and some of its members, copied here for
* convenience when we populated the list. */
struct krb5plugin_preauth_client_ftable_v1 *ftable;
const char *name;
int flags, use_count;
preauth_client_process_proc client_process;
preauth_client_tryagain_proc client_tryagain;
preauth_client_supply_gic_opts_proc client_supply_gic_opts;
preauth_client_request_init_proc client_req_init;
preauth_client_request_fini_proc client_req_fini;
/* The per-request context which the client_req_init() function
* might allocate, which we'll need to clean up later by
* calling the client_req_fini() function. */
void *request_context;
/* A pointer to the request_context pointer. All modules within
* a plugin will point at the request_context of the first
* module within the plugin. */
void **request_context_pp;
} *modules;
} krb5_preauth_context;
typedef struct _krb5_pa_enc_ts {
krb5_timestamp patimestamp;
krb5_int32 pausec;
} krb5_pa_enc_ts;
typedef struct _krb5_pa_for_user {
krb5_principal user;
krb5_checksum cksum;
krb5_data auth_package;
} krb5_pa_for_user;
enum {
KRB5_FAST_ARMOR_AP_REQUEST = 0x1
};
typedef struct _krb5_fast_armor {
krb5_int32 armor_type;
krb5_data armor_value;
} krb5_fast_armor;
typedef struct _krb5_fast_armored_req {
krb5_magic magic;
krb5_fast_armor *armor;
krb5_checksum req_checksum;
krb5_enc_data enc_part;
} krb5_fast_armored_req;
typedef struct _krb5_fast_req {
krb5_magic magic;
krb5_flags fast_options;
/* padata from req_body is used*/
krb5_kdc_req *req_body;
} krb5_fast_req;
/* Bits 0-15 are critical in fast options.*/
#define UNSUPPORTED_CRITICAL_FAST_OPTIONS 0x00ff
#define KRB5_FAST_OPTION_HIDE_CLIENT_NAMES 0x01
typedef struct _krb5_fast_finished {
krb5_timestamp timestamp;
krb5_int32 usec;
krb5_principal client;
krb5_checksum ticket_checksum;
} krb5_fast_finished;
typedef struct _krb5_fast_response {
krb5_magic magic;
krb5_pa_data **padata;
krb5_keyblock *strengthen_key;
krb5_fast_finished *finished;
krb5_int32 nonce;
} krb5_fast_response;
typedef krb5_error_code (*krb5_preauth_obtain_proc)
(krb5_context,
krb5_pa_data *,
krb5_etype_info,
krb5_keyblock *,
krb5_error_code ( * )(krb5_context,
const krb5_enctype,
krb5_data *,
krb5_const_pointer,
krb5_keyblock **),
krb5_const_pointer,
krb5_creds *,
krb5_kdc_req *,
krb5_pa_data **);
typedef krb5_error_code (*krb5_preauth_process_proc)
(krb5_context,
krb5_pa_data *,
krb5_kdc_req *,
krb5_kdc_rep *,
krb5_error_code ( * )(krb5_context,
const krb5_enctype,
krb5_data *,
krb5_const_pointer,
krb5_keyblock **),
krb5_const_pointer,
krb5_error_code ( * )(krb5_context,
const krb5_keyblock *,
krb5_const_pointer,
krb5_kdc_rep * ),
krb5_keyblock **,
krb5_creds *,
krb5_int32 *,
krb5_int32 *);
typedef struct _krb5_preauth_ops {
krb5_magic magic;
int type;
int flags;
krb5_preauth_obtain_proc obtain;
krb5_preauth_process_proc process;
} krb5_preauth_ops;
krb5_error_code krb5_obtain_padata
(krb5_context,
krb5_pa_data **,
krb5_error_code ( * )(krb5_context,
const krb5_enctype,
krb5_data *,
krb5_const_pointer,
krb5_keyblock **),
krb5_const_pointer,
krb5_creds *,
krb5_kdc_req *);
krb5_error_code krb5_process_padata
(krb5_context,
krb5_kdc_req *,
krb5_kdc_rep *,
krb5_error_code ( * )(krb5_context,
const krb5_enctype,
krb5_data *,
krb5_const_pointer,
krb5_keyblock **),
krb5_const_pointer,
krb5_error_code ( * )(krb5_context,
const krb5_keyblock *,
krb5_const_pointer,
krb5_kdc_rep * ),
krb5_keyblock **,
krb5_creds *,
krb5_int32 *);
void krb5_free_etype_info (krb5_context, krb5_etype_info);
/*
* Preauthentication property flags
*/
#define KRB5_PREAUTH_FLAGS_ENCRYPT 0x00000001
#define KRB5_PREAUTH_FLAGS_HARDWARE 0x00000002
#endif /* KRB5_PREAUTH__ */
/*
* End "preauth.h"
*/
/*
* Extending the krb5_get_init_creds_opt structure. The original
* krb5_get_init_creds_opt structure is defined publicly. The
* new extended version is private. The original interface
* assumed a pre-allocated structure which was passed to
* krb5_get_init_creds_init(). The new interface assumes that
* the caller will call krb5_get_init_creds_alloc() and
* krb5_get_init_creds_free().
*
* Callers MUST NOT call krb5_get_init_creds_init() after allocating an
* opts structure using krb5_get_init_creds_alloc(). To do so will
* introduce memory leaks. Unfortunately, there is no way to enforce
* this behavior.
*
* Two private flags are added for backward compatibility.
* KRB5_GET_INIT_CREDS_OPT_EXTENDED says that the structure was allocated
* with the new krb5_get_init_creds_opt_alloc() function.
* KRB5_GET_INIT_CREDS_OPT_SHADOWED is set to indicate that the extended
* structure is a shadow copy of an original krb5_get_init_creds_opt
* structure.
* If KRB5_GET_INIT_CREDS_OPT_SHADOWED is set after a call to
* krb5int_gic_opt_to_opte(), the resulting extended structure should be
* freed (using krb5_get_init_creds_free). Otherwise, the original
* structure was already extended and there is no need to free it.
*/
#define KRB5_GET_INIT_CREDS_OPT_EXTENDED 0x80000000
#define KRB5_GET_INIT_CREDS_OPT_SHADOWED 0x40000000
#define krb5_gic_opt_is_extended(s) \
((s) && ((s)->flags & KRB5_GET_INIT_CREDS_OPT_EXTENDED) ? 1 : 0)
#define krb5_gic_opt_is_shadowed(s) \
((s) && ((s)->flags & KRB5_GET_INIT_CREDS_OPT_SHADOWED) ? 1 : 0)
typedef struct _krb5_gic_opt_private {
int num_preauth_data;
krb5_gic_opt_pa_data *preauth_data;
} krb5_gic_opt_private;
typedef struct _krb5_gic_opt_ext {
krb5_flags flags;
krb5_deltat tkt_life;
krb5_deltat renew_life;
int forwardable;
int proxiable;
krb5_enctype *etype_list;
int etype_list_length;
krb5_address **address_list;
krb5_preauthtype *preauth_list;
int preauth_list_length;
krb5_data *salt;
/*
* Do not change anything above this point in this structure.
* It is identical to the public krb5_get_init_creds_opt structure.
* New members must be added below.
*/
krb5_gic_opt_private *opt_private;
} krb5_gic_opt_ext;
krb5_error_code
krb5int_gic_opt_to_opte(krb5_context context,
krb5_get_init_creds_opt *opt,
krb5_gic_opt_ext **opte,
unsigned int force,
const char *where);
krb5_error_code
krb5int_copy_data_contents (krb5_context, const krb5_data *, krb5_data *);
krb5_error_code
krb5int_copy_data_contents_add0 (krb5_context, const krb5_data *, krb5_data *);
#ifndef _KERNEL /* needed for lib/krb5/krb/ */
typedef krb5_error_code (*krb5_gic_get_as_key_fct)
(krb5_context,
krb5_principal,
krb5_enctype,
krb5_prompter_fct,
void *prompter_data,
krb5_data *salt,
krb5_data *s2kparams,
krb5_keyblock *as_key,
void *gak_data);
krb5_error_code KRB5_CALLCONV
krb5_get_init_creds
(krb5_context context,
krb5_creds *creds,
krb5_principal client,
krb5_prompter_fct prompter,
void *prompter_data,
krb5_deltat start_time,
char *in_tkt_service,
krb5_gic_opt_ext *gic_options,
krb5_gic_get_as_key_fct gak,
void *gak_data,
int *master,
krb5_kdc_rep **as_reply);
krb5_error_code krb5int_populate_gic_opt (
krb5_context, krb5_gic_opt_ext **,
krb5_flags options, krb5_address * const *addrs, krb5_enctype *ktypes,
krb5_preauthtype *pre_auth_types, krb5_creds *creds);
krb5_error_code KRB5_CALLCONV krb5_do_preauth
(krb5_context context,
krb5_kdc_req *request,
krb5_data *encoded_request_body,
krb5_data *encoded_previous_request,
krb5_pa_data **in_padata, krb5_pa_data ***out_padata,
krb5_data *salt, krb5_data *s2kparams,
krb5_enctype *etype, krb5_keyblock *as_key,
krb5_prompter_fct prompter, void *prompter_data,
krb5_gic_get_as_key_fct gak_fct, void *gak_data,
krb5_preauth_client_rock *get_data_rock,
krb5_gic_opt_ext *opte);
krb5_error_code KRB5_CALLCONV krb5_do_preauth_tryagain
(krb5_context context,
krb5_kdc_req *request,
krb5_data *encoded_request_body,
krb5_data *encoded_previous_request,
krb5_pa_data **in_padata, krb5_pa_data ***out_padata,
krb5_error *err_reply,
krb5_data *salt, krb5_data *s2kparams,
krb5_enctype *etype, krb5_keyblock *as_key,
krb5_prompter_fct prompter, void *prompter_data,
krb5_gic_get_as_key_fct gak_fct, void *gak_data,
krb5_preauth_client_rock *get_data_rock,
krb5_gic_opt_ext *opte);
void KRB5_CALLCONV krb5_init_preauth_context
(krb5_context);
void KRB5_CALLCONV krb5_free_preauth_context
(krb5_context);
void KRB5_CALLCONV krb5_clear_preauth_context_use_counts
(krb5_context);
void KRB5_CALLCONV krb5_preauth_prepare_request
(krb5_context, krb5_gic_opt_ext *, krb5_kdc_req *);
void KRB5_CALLCONV krb5_preauth_request_context_init
(krb5_context);
void KRB5_CALLCONV krb5_preauth_request_context_fini
(krb5_context);
#endif /* _KERNEL */
void KRB5_CALLCONV krb5_free_sam_challenge
(krb5_context, krb5_sam_challenge * );
void KRB5_CALLCONV krb5_free_sam_challenge_2
(krb5_context, krb5_sam_challenge_2 * );
void KRB5_CALLCONV krb5_free_sam_challenge_2_body
(krb5_context, krb5_sam_challenge_2_body *);
void KRB5_CALLCONV krb5_free_sam_response
(krb5_context, krb5_sam_response * );
void KRB5_CALLCONV krb5_free_sam_response_2
(krb5_context, krb5_sam_response_2 * );
void KRB5_CALLCONV krb5_free_predicted_sam_response
(krb5_context, krb5_predicted_sam_response * );
void KRB5_CALLCONV krb5_free_enc_sam_response_enc
(krb5_context, krb5_enc_sam_response_enc * );
void KRB5_CALLCONV krb5_free_enc_sam_response_enc_2
(krb5_context, krb5_enc_sam_response_enc_2 * );
void KRB5_CALLCONV krb5_free_sam_challenge_contents
(krb5_context, krb5_sam_challenge * );
void KRB5_CALLCONV krb5_free_sam_challenge_2_contents
(krb5_context, krb5_sam_challenge_2 * );
void KRB5_CALLCONV krb5_free_sam_challenge_2_body_contents
(krb5_context, krb5_sam_challenge_2_body * );
void KRB5_CALLCONV krb5_free_sam_response_contents
(krb5_context, krb5_sam_response * );
void KRB5_CALLCONV krb5_free_sam_response_2_contents
(krb5_context, krb5_sam_response_2 *);
void KRB5_CALLCONV krb5_free_predicted_sam_response_contents
(krb5_context, krb5_predicted_sam_response * );
void KRB5_CALLCONV krb5_free_enc_sam_response_enc_contents
(krb5_context, krb5_enc_sam_response_enc * );
void KRB5_CALLCONV krb5_free_enc_sam_response_enc_2_contents
(krb5_context, krb5_enc_sam_response_enc_2 * );
void KRB5_CALLCONV krb5_free_pa_enc_ts
(krb5_context, krb5_pa_enc_ts *);
/* #include "krb5/wordsize.h" -- comes in through base-defs.h. */
#ifndef _KERNEL
#include "com_err.h"
#include <krb5/k5-plugin.h>
#endif /* _KERNEL */
/*
* Solaris Kerberos: moved from sendto_kdc.c so other code can reference
*/
#define DEFAULT_UDP_PREF_LIMIT 1465
#ifndef _KERNEL
#include "profile.h"
#include <strings.h>
#endif /* _KERNEL */
#define KEY_CHANGED(k1, k2) \
(k1 == NULL || \
k1 != k2 || \
k1->enctype != k2->enctype || \
k1->length != k2->length || \
bcmp(k1->contents, k2->contents, k1->length))
#ifndef _KERNEL
typedef struct _arcfour_ctx {
CK_SESSION_HANDLE eSession; /* encrypt session handle */
CK_SESSION_HANDLE dSession; /* decrypt session handle */
CK_OBJECT_HANDLE eKey; /* encrypt key object */
CK_OBJECT_HANDLE dKey; /* decrype key object */
uchar_t initialized;
}arcfour_ctx_rec;
#endif /* !_KERNEL */
struct _krb5_context {
krb5_magic magic;
krb5_enctype *in_tkt_ktypes;
unsigned int in_tkt_ktype_count;
krb5_enctype *tgs_ktypes;
unsigned int tgs_ktype_count;
/* This used to be a void*, but since we always allocate them
together (though in different source files), and the types
are declared in the same header, might as well just combine
them.
The array[1] is so the existing code treating the field as
a pointer will still work. For cleanliness, it should
eventually get changed to a single element instead of an
array. */
struct _krb5_os_context os_context[1];
char *default_realm;
int ser_ctx_count;
krb5_boolean profile_secure;
void *ser_ctx;
#ifndef _KERNEL
profile_t profile;
void *db_context;
void *kdblog_context;
/* allowable clock skew */
krb5_deltat clockskew;
krb5_cksumtype kdc_req_sumtype;
krb5_cksumtype default_ap_req_sumtype;
krb5_cksumtype default_safe_sumtype;
krb5_flags kdc_default_options;
krb5_flags library_options;
int fcc_default_format;
int scc_default_format;
krb5_prompt_type *prompt_types;
/* Message size above which we'll try TCP first in send-to-kdc
type code. Aside from the 2**16 size limit, we put no
absolute limit on the UDP packet size. */
int udp_pref_limit;
/* This is the tgs_ktypes list as read from the profile, or
set to compiled-in defaults. The application code cannot
override it. This is used for session keys for
intermediate ticket-granting tickets used to acquire the
requested ticket (the session key of which may be
constrained by tgs_ktypes above). */
krb5_enctype *conf_tgs_ktypes;
int conf_tgs_ktypes_count;
/* Use the _configured version? */
krb5_boolean use_conf_ktypes;
#ifdef KRB5_DNS_LOOKUP
krb5_boolean profile_in_memory;
#endif /* KRB5_DNS_LOOKUP */
/* locate_kdc module stuff */
struct plugin_dir_handle libkrb5_plugins;
struct krb5plugin_service_locate_ftable *vtbl;
void (**locate_fptrs)(void);
pid_t pid; /* fork safety: PID of process that did last PKCS11 init */
/* Solaris Kerberos: handles for PKCS#11 crypto */
/*
* Warning, do not access hSession directly as this is not fork() safe.
* Instead use the krb_ctx_hSession() macro below.
*/
CK_SESSION_HANDLE hSession;
int cryptoki_initialized;
/* arcfour_ctx: used only for rcmd stuff so no fork safety issues apply */
arcfour_ctx_rec arcfour_ctx;
/* preauth module stuff */
struct plugin_dir_handle preauth_plugins;
krb5_preauth_context *preauth_context;
/* error detail info */
struct errinfo err;
#else /* ! KERNEL */
crypto_mech_type_t kef_cipher_mt;
crypto_mech_type_t kef_hash_mt;
crypto_mech_type_t kef_cksum_mt;
#endif /* ! KERNEL */
};
#ifndef _KERNEL
extern pid_t __krb5_current_pid;
CK_SESSION_HANDLE krb5_reinit_ef_handle(krb5_context);
/*
* fork safety: barring the ef_init code, every other function must use the
* krb_ctx_hSession() macro to access the hSession field in a krb context.
* Note, if the pid of the krb ctx == the current global pid then it is safe to
* use the ctx hSession otherwise it needs to be re-inited before it is returned
* to the caller.
*/
#define krb_ctx_hSession(ctx) \
((ctx)->pid == __krb5_current_pid) ? (ctx)->hSession : krb5_reinit_ef_handle((ctx))
#endif
#define MD5_CKSUM_LENGTH 16
#define RSA_MD5_CKSUM_LENGTH 16
#define MD5_BLOCKSIZE 64
/*
* Solaris Kerberos:
* This next section of prototypes and constants
* are all unique to the Solaris Kerberos implementation.
* Because Solaris uses the native encryption framework
* to provide crypto support, the following routines
* are needed to support this system.
*/
/*
* Begin Solaris Crypto Prototypes
*/
/*
* define constants that are used for creating the constant
* which is used to make derived keys.
*/
#define DK_ENCR_KEY_BYTE 0xAA
#define DK_HASH_KEY_BYTE 0x55
#define DK_CKSUM_KEY_BYTE 0x99
int init_derived_keydata(krb5_context, const struct krb5_enc_provider *,
krb5_keyblock *, krb5_keyusage,
krb5_keyblock **, krb5_keyblock **);
krb5_error_code add_derived_key(krb5_keyblock *, krb5_keyusage, uchar_t,
krb5_keyblock *);
krb5_keyblock *find_derived_key(krb5_keyusage, uchar_t, krb5_keyblock *);
krb5_keyblock *krb5_create_derived_keyblock(int);
#ifdef _KERNEL
int k5_ef_hash(krb5_context, int, const krb5_data *, krb5_data *);
int k5_ef_mac(krb5_context, krb5_keyblock *, krb5_data *,
const krb5_data *, krb5_data *);
void make_kef_key(krb5_keyblock *);
int init_key_kef(crypto_mech_type_t, krb5_keyblock *);
int update_key_template(krb5_keyblock *);
void setup_kef_keytypes();
void setup_kef_cksumtypes();
crypto_mech_type_t get_cipher_mech_type(krb5_context, krb5_keyblock *);
crypto_mech_type_t get_hash_mech_type(krb5_context, krb5_keyblock *);
#else
/*
* This structure is used to map Kerberos supported OID's,
* to PKCS11 mechanisms
*/
#define USE_ENCR 0x01
#define USE_HASH 0x02
typedef struct krb5_mech_2_pkcs {
uchar_t flags;
CK_MECHANISM_TYPE enc_algo;
CK_MECHANISM_TYPE hash_algo;
CK_MECHANISM_TYPE str2key_algo;
} KRB5_MECH_TO_PKCS;
#define ENC_DEFINED(x) (((x).flags & USE_ENCR))
#define HASH_DEFINED(x) (((x).flags & USE_HASH))
extern CK_RV get_algo(krb5_enctype etype, KRB5_MECH_TO_PKCS * algos);
extern CK_RV get_key_type (krb5_enctype etype, CK_KEY_TYPE * keyType);
extern krb5_error_code slot_supports_krb5 (CK_SLOT_ID_PTR slotid);
krb5_error_code init_key_uef(CK_SESSION_HANDLE, krb5_keyblock *);
krb5_error_code k5_ef_hash(krb5_context, CK_MECHANISM *,
unsigned int, const krb5_data *, krb5_data *);
krb5_error_code k5_ef_mac(krb5_context context,
krb5_keyblock *key, krb5_data *ivec,
krb5_const krb5_data *input, krb5_data *output);
#endif /* !_KERNEL */
krb5_error_code
derive_3des_keys(krb5_context, struct krb5_enc_provider *,
krb5_keyblock *, krb5_keyusage,
krb5_keyblock *, krb5_keyblock *);
/*
* End Solaris Crypto Prototypes
*/
#define KRB5_LIBOPT_SYNC_KDCTIME 0x0001
/* internal message representations */
typedef struct _krb5_safe {
krb5_magic magic;
krb5_data user_data; /* user data */
krb5_timestamp timestamp; /* client time, optional */
krb5_int32 usec; /* microsecond portion of time,
optional */
krb5_ui_4 seq_number; /* sequence #, optional */
krb5_address *s_address; /* sender address */
krb5_address *r_address; /* recipient address, optional */
krb5_checksum *checksum; /* data integrity checksum */
} krb5_safe;
typedef struct _krb5_priv {
krb5_magic magic;
krb5_enc_data enc_part; /* encrypted part */
} krb5_priv;
typedef struct _krb5_priv_enc_part {
krb5_magic magic;
krb5_data user_data; /* user data */
krb5_timestamp timestamp; /* client time, optional */
krb5_int32 usec; /* microsecond portion of time, opt. */
krb5_ui_4 seq_number; /* sequence #, optional */
krb5_address *s_address; /* sender address */
krb5_address *r_address; /* recipient address, optional */
} krb5_priv_enc_part;
void KRB5_CALLCONV krb5_free_safe
(krb5_context, krb5_safe * );
void KRB5_CALLCONV krb5_free_priv
(krb5_context, krb5_priv * );
void KRB5_CALLCONV krb5_free_priv_enc_part
(krb5_context, krb5_priv_enc_part * );
/*
* Begin "asn1.h"
*/
#ifndef KRB5_ASN1__
#define KRB5_ASN1__
/* ASN.1 encoding knowledge; KEEP IN SYNC WITH ASN.1 defs! */
/* here we use some knowledge of ASN.1 encodings */
/*
Ticket is APPLICATION 1.
Authenticator is APPLICATION 2.
AS_REQ is APPLICATION 10.
AS_REP is APPLICATION 11.
TGS_REQ is APPLICATION 12.
TGS_REP is APPLICATION 13.
AP_REQ is APPLICATION 14.
AP_REP is APPLICATION 15.
KRB_SAFE is APPLICATION 20.
KRB_PRIV is APPLICATION 21.
KRB_CRED is APPLICATION 22.
EncASRepPart is APPLICATION 25.
EncTGSRepPart is APPLICATION 26.
EncAPRepPart is APPLICATION 27.
EncKrbPrivPart is APPLICATION 28.
EncKrbCredPart is APPLICATION 29.
KRB_ERROR is APPLICATION 30.
*/
/* allow either constructed or primitive encoding, so check for bit 6
set or reset */
#define krb5_is_krb_ticket(dat)\
((dat) && (dat)->length && ((dat)->data[0] == 0x61 ||\
(dat)->data[0] == 0x41))
#define krb5_is_krb_authenticator(dat)\
((dat) && (dat)->length && ((dat)->data[0] == 0x62 ||\
(dat)->data[0] == 0x42))
#define krb5_is_as_req(dat)\
((dat) && (dat)->length && ((dat)->data[0] == 0x6a ||\
(dat)->data[0] == 0x4a))
#define krb5_is_as_rep(dat)\
((dat) && (dat)->length && ((dat)->data[0] == 0x6b ||\
(dat)->data[0] == 0x4b))
#define krb5_is_tgs_req(dat)\
((dat) && (dat)->length && ((dat)->data[0] == 0x6c ||\
(dat)->data[0] == 0x4c))
#define krb5_is_tgs_rep(dat)\
((dat) && (dat)->length && ((dat)->data[0] == 0x6d ||\
(dat)->data[0] == 0x4d))
#define krb5_is_ap_req(dat)\
((dat) && (dat)->length && ((dat)->data[0] == 0x6e ||\
(dat)->data[0] == 0x4e))
#define krb5_is_ap_rep(dat)\
((dat) && (dat)->length && ((dat)->data[0] == 0x6f ||\
(dat)->data[0] == 0x4f))
#define krb5_is_krb_safe(dat)\
((dat) && (dat)->length && ((dat)->data[0] == 0x74 ||\
(dat)->data[0] == 0x54))
#define krb5_is_krb_priv(dat)\
((dat) && (dat)->length && ((dat)->data[0] == 0x75 ||\
(dat)->data[0] == 0x55))
#define krb5_is_krb_cred(dat)\
((dat) && (dat)->length && ((dat)->data[0] == 0x76 ||\
(dat)->data[0] == 0x56))
#define krb5_is_krb_enc_as_rep_part(dat)\
((dat) && (dat)->length && ((dat)->data[0] == 0x79 ||\
(dat)->data[0] == 0x59))
#define krb5_is_krb_enc_tgs_rep_part(dat)\
((dat) && (dat)->length && ((dat)->data[0] == 0x7a ||\
(dat)->data[0] == 0x5a))
#define krb5_is_krb_enc_ap_rep_part(dat)\
((dat) && (dat)->length && ((dat)->data[0] == 0x7b ||\
(dat)->data[0] == 0x5b))
#define krb5_is_krb_enc_krb_priv_part(dat)\
((dat) && (dat)->length && ((dat)->data[0] == 0x7c ||\
(dat)->data[0] == 0x5c))
#define krb5_is_krb_enc_krb_cred_part(dat)\
((dat) && (dat)->length && ((dat)->data[0] == 0x7d ||\
(dat)->data[0] == 0x5d))
#define krb5_is_krb_error(dat)\
((dat) && (dat)->length && ((dat)->data[0] == 0x7e ||\
(dat)->data[0] == 0x5e))
/*************************************************************************
* Prototypes for krb5_encode.c
*************************************************************************/
/*
krb5_error_code encode_krb5_structure(const krb5_structure *rep,
krb5_data **code);
modifies *code
effects Returns the ASN.1 encoding of *rep in **code.
Returns ASN1_MISSING_FIELD if a required field is emtpy in *rep.
Returns ENOMEM if memory runs out.
*/
krb5_error_code encode_krb5_authenticator
(const krb5_authenticator *rep, krb5_data **code);
krb5_error_code encode_krb5_ticket
(const krb5_ticket *rep, krb5_data **code);
krb5_error_code encode_krb5_encryption_key
(const krb5_keyblock *rep, krb5_data **code);
krb5_error_code encode_krb5_enc_tkt_part
(const krb5_enc_tkt_part *rep, krb5_data **code);
krb5_error_code encode_krb5_enc_kdc_rep_part
(const krb5_enc_kdc_rep_part *rep, krb5_data **code);
/* yes, the translation is identical to that used for KDC__REP */
krb5_error_code encode_krb5_as_rep
(const krb5_kdc_rep *rep, krb5_data **code);
/* yes, the translation is identical to that used for KDC__REP */
krb5_error_code encode_krb5_tgs_rep
(const krb5_kdc_rep *rep, krb5_data **code);
krb5_error_code encode_krb5_ap_req
(const krb5_ap_req *rep, krb5_data **code);
krb5_error_code encode_krb5_ap_rep
(const krb5_ap_rep *rep, krb5_data **code);
krb5_error_code encode_krb5_ap_rep_enc_part
(const krb5_ap_rep_enc_part *rep, krb5_data **code);
krb5_error_code encode_krb5_as_req
(const krb5_kdc_req *rep, krb5_data **code);
krb5_error_code encode_krb5_tgs_req
(const krb5_kdc_req *rep, krb5_data **code);
krb5_error_code encode_krb5_kdc_req_body
(const krb5_kdc_req *rep, krb5_data **code);
krb5_error_code encode_krb5_safe
(const krb5_safe *rep, krb5_data **code);
struct krb5_safe_with_body {
krb5_safe *safe;
krb5_data *body;
};
krb5_error_code encode_krb5_safe_with_body
(const struct krb5_safe_with_body *rep, krb5_data **code);
krb5_error_code encode_krb5_priv
(const krb5_priv *rep, krb5_data **code);
krb5_error_code encode_krb5_enc_priv_part
(const krb5_priv_enc_part *rep, krb5_data **code);
krb5_error_code encode_krb5_cred
(const krb5_cred *rep, krb5_data **code);
krb5_error_code encode_krb5_enc_cred_part
(const krb5_cred_enc_part *rep, krb5_data **code);
krb5_error_code encode_krb5_error
(const krb5_error *rep, krb5_data **code);
krb5_error_code encode_krb5_authdata
(krb5_authdata *const *rep, krb5_data **code);
krb5_error_code encode_krb5_authdata_elt
(const krb5_authdata *rep, krb5_data **code);
krb5_error_code encode_krb5_pwd_sequence
(const passwd_phrase_element *rep, krb5_data **code);
krb5_error_code encode_krb5_pwd_data
(const krb5_pwd_data *rep, krb5_data **code);
krb5_error_code encode_krb5_padata_sequence
(krb5_pa_data *const *rep, krb5_data **code);
krb5_error_code encode_krb5_alt_method
(const krb5_alt_method *, krb5_data **code);
krb5_error_code encode_krb5_etype_info
(krb5_etype_info_entry *const *, krb5_data **code);
krb5_error_code encode_krb5_etype_info2
(krb5_etype_info_entry *const *, krb5_data **code);
krb5_error_code encode_krb5_enc_data
(const krb5_enc_data *, krb5_data **);
krb5_error_code encode_krb5_pa_enc_ts
(const krb5_pa_enc_ts *, krb5_data **);
krb5_error_code encode_krb5_sam_challenge
(const krb5_sam_challenge * , krb5_data **);
krb5_error_code encode_krb5_sam_key
(const krb5_sam_key * , krb5_data **);
krb5_error_code encode_krb5_enc_sam_response_enc
(const krb5_enc_sam_response_enc * , krb5_data **);
krb5_error_code encode_krb5_sam_response
(const krb5_sam_response * , krb5_data **);
krb5_error_code encode_krb5_sam_challenge_2
(const krb5_sam_challenge_2 * , krb5_data **);
krb5_error_code encode_krb5_sam_challenge_2_body
(const krb5_sam_challenge_2_body * , krb5_data **);
krb5_error_code encode_krb5_enc_sam_response_enc_2
(const krb5_enc_sam_response_enc_2 * , krb5_data **);
krb5_error_code encode_krb5_sam_response_2
(const krb5_sam_response_2 * , krb5_data **);
krb5_error_code encode_krb5_predicted_sam_response
(const krb5_predicted_sam_response * , krb5_data **);
struct krb5_setpw_req {
krb5_principal target;
krb5_data password;
};
krb5_error_code encode_krb5_setpw_req
(const struct krb5_setpw_req *rep, krb5_data **code);
/*************************************************************************
* End of prototypes for krb5_encode.c
*************************************************************************/
krb5_error_code decode_krb5_sam_challenge
(const krb5_data *, krb5_sam_challenge **);
krb5_error_code decode_krb5_enc_sam_key
(const krb5_data *, krb5_sam_key **);
krb5_error_code decode_krb5_enc_sam_response_enc
(const krb5_data *, krb5_enc_sam_response_enc **);
krb5_error_code decode_krb5_sam_response
(const krb5_data *, krb5_sam_response **);
krb5_error_code decode_krb5_predicted_sam_response
(const krb5_data *, krb5_predicted_sam_response **);
krb5_error_code decode_krb5_sam_challenge_2
(const krb5_data *, krb5_sam_challenge_2 **);
krb5_error_code decode_krb5_sam_challenge_2_body
(const krb5_data *, krb5_sam_challenge_2_body **);
krb5_error_code decode_krb5_enc_sam_response_enc_2
(const krb5_data *, krb5_enc_sam_response_enc_2 **);
krb5_error_code decode_krb5_sam_response_2
(const krb5_data *, krb5_sam_response_2 **);
/*************************************************************************
* Prototypes for krb5_decode.c
*************************************************************************/
krb5_error_code krb5_validate_times
(krb5_context,
krb5_ticket_times *);
/*
krb5_error_code decode_krb5_structure(const krb5_data *code,
krb5_structure **rep);
requires Expects **rep to not have been allocated;
a new *rep is allocated regardless of the old value.
effects Decodes *code into **rep.
Returns ENOMEM if memory is exhausted.
Returns asn1 and krb5 errors.
*/
krb5_error_code decode_krb5_authenticator
(const krb5_data *code, krb5_authenticator **rep);
krb5_error_code decode_krb5_ticket
(const krb5_data *code, krb5_ticket **rep);
krb5_error_code decode_krb5_encryption_key
(const krb5_data *output, krb5_keyblock **rep);
krb5_error_code decode_krb5_enc_tkt_part
(const krb5_data *output, krb5_enc_tkt_part **rep);
krb5_error_code decode_krb5_enc_kdc_rep_part
(const krb5_data *output, krb5_enc_kdc_rep_part **rep);
krb5_error_code decode_krb5_as_rep
(const krb5_data *output, krb5_kdc_rep **rep);
krb5_error_code decode_krb5_tgs_rep
(const krb5_data *output, krb5_kdc_rep **rep);
krb5_error_code decode_krb5_ap_req
(const krb5_data *output, krb5_ap_req **rep);
krb5_error_code decode_krb5_ap_rep
(const krb5_data *output, krb5_ap_rep **rep);
krb5_error_code decode_krb5_ap_rep_enc_part
(const krb5_data *output, krb5_ap_rep_enc_part **rep);
krb5_error_code decode_krb5_as_req
(const krb5_data *output, krb5_kdc_req **rep);
krb5_error_code decode_krb5_tgs_req
(const krb5_data *output, krb5_kdc_req **rep);
krb5_error_code decode_krb5_kdc_req_body
(const krb5_data *output, krb5_kdc_req **rep);
krb5_error_code decode_krb5_safe
(const krb5_data *output, krb5_safe **rep);
krb5_error_code decode_krb5_safe_with_body
(const krb5_data *output, krb5_safe **rep, krb5_data *body);
krb5_error_code decode_krb5_priv
(const krb5_data *output, krb5_priv **rep);
krb5_error_code decode_krb5_enc_priv_part
(const krb5_data *output, krb5_priv_enc_part **rep);
krb5_error_code decode_krb5_cred
(const krb5_data *output, krb5_cred **rep);
krb5_error_code decode_krb5_enc_cred_part
(const krb5_data *output, krb5_cred_enc_part **rep);
krb5_error_code decode_krb5_error
(const krb5_data *output, krb5_error **rep);
krb5_error_code decode_krb5_authdata
(const krb5_data *output, krb5_authdata ***rep);
krb5_error_code decode_krb5_pwd_sequence
(const krb5_data *output, passwd_phrase_element **rep);
krb5_error_code decode_krb5_pwd_data
(const krb5_data *output, krb5_pwd_data **rep);
krb5_error_code decode_krb5_padata_sequence
(const krb5_data *output, krb5_pa_data ***rep);
krb5_error_code decode_krb5_alt_method
(const krb5_data *output, krb5_alt_method **rep);
krb5_error_code decode_krb5_etype_info
(const krb5_data *output, krb5_etype_info_entry ***rep);
krb5_error_code decode_krb5_etype_info2
(const krb5_data *output, krb5_etype_info_entry ***rep);
krb5_error_code decode_krb5_enc_data
(const krb5_data *output, krb5_enc_data **rep);
krb5_error_code decode_krb5_pa_enc_ts
(const krb5_data *output, krb5_pa_enc_ts **rep);
krb5_error_code decode_krb5_sam_key
(const krb5_data *, krb5_sam_key **);
struct _krb5_key_data; /* kdb.h */
krb5_error_code
krb5int_ldap_encode_sequence_of_keys (struct _krb5_key_data *key_data,
krb5_int16 n_key_data,
krb5_int32 mkvno,
krb5_data **code);
krb5_error_code
krb5int_ldap_decode_sequence_of_keys (krb5_data *in,
struct _krb5_key_data **out,
krb5_int16 *n_key_data,
int *mkvno);
/*************************************************************************
* End of prototypes for krb5_decode.c
*************************************************************************/
#endif /* KRB5_ASN1__ */
/*
* End "asn1.h"
*/
/*
* Internal krb5 library routines
*/
krb5_error_code krb5_encrypt_tkt_part
(krb5_context,
const krb5_keyblock *,
krb5_ticket * );
krb5_error_code krb5_encode_kdc_rep
(krb5_context,
const krb5_msgtype,
const krb5_enc_kdc_rep_part *,
int using_subkey,
const krb5_keyblock *,
krb5_kdc_rep *,
krb5_data ** );
krb5_boolean krb5int_auth_con_chkseqnum
(krb5_context ctx, krb5_auth_context ac, krb5_ui_4 in_seq);
/*
* [De]Serialization Handle and operations.
*/
struct __krb5_serializer {
krb5_magic odtype;
krb5_error_code (*sizer) (krb5_context,
krb5_pointer,
size_t *);
krb5_error_code (*externalizer) (krb5_context,
krb5_pointer,
krb5_octet **,
size_t *);
krb5_error_code (*internalizer) (krb5_context,
krb5_pointer *,
krb5_octet **,
size_t *);
};
typedef const struct __krb5_serializer * krb5_ser_handle;
typedef struct __krb5_serializer krb5_ser_entry;
krb5_ser_handle krb5_find_serializer
(krb5_context,
krb5_magic);
krb5_error_code krb5_register_serializer
(krb5_context,
const krb5_ser_entry *);
/* Determine the external size of a particular opaque structure */
krb5_error_code KRB5_CALLCONV krb5_size_opaque
(krb5_context,
krb5_magic,
krb5_pointer,
size_t *);
/* Serialize the structure into a buffer */
krb5_error_code KRB5_CALLCONV krb5_externalize_opaque
(krb5_context,
krb5_magic,
krb5_pointer,
krb5_octet **,
size_t *);
/* Deserialize the structure from a buffer */
krb5_error_code KRB5_CALLCONV krb5_internalize_opaque
(krb5_context,
krb5_magic,
krb5_pointer *,
krb5_octet **,
size_t *);
/* Serialize data into a buffer */
krb5_error_code krb5_externalize_data
(krb5_context,
krb5_pointer,
krb5_octet **,
size_t *);
/*
* Initialization routines.
*/
/* Initialize serialization for krb5_[os_]context */
krb5_error_code KRB5_CALLCONV krb5_ser_context_init
(krb5_context);
/* Initialize serialization for krb5_auth_context */
krb5_error_code KRB5_CALLCONV krb5_ser_auth_context_init
(krb5_context);
/* Initialize serialization for krb5_keytab */
krb5_error_code KRB5_CALLCONV krb5_ser_keytab_init
(krb5_context);
/* Initialize serialization for krb5_ccache */
krb5_error_code KRB5_CALLCONV krb5_ser_ccache_init
(krb5_context);
/* Initialize serialization for krb5_rcache */
krb5_error_code KRB5_CALLCONV krb5_ser_rcache_init
(krb5_context);
/* [De]serialize 4-byte integer */
krb5_error_code KRB5_CALLCONV krb5_ser_pack_int32
(krb5_int32,
krb5_octet **,
size_t *);
krb5_error_code KRB5_CALLCONV krb5_ser_unpack_int32
(krb5_int32 *,
krb5_octet **,
size_t *);
/* [De]serialize 8-byte integer */
krb5_error_code KRB5_CALLCONV krb5_ser_pack_int64
(krb5_int64, krb5_octet **, size_t *);
krb5_error_code KRB5_CALLCONV krb5_ser_unpack_int64
(krb5_int64 *, krb5_octet **, size_t *);
/* [De]serialize byte string */
krb5_error_code KRB5_CALLCONV krb5_ser_pack_bytes
(krb5_octet *,
size_t,
krb5_octet **,
size_t *);
krb5_error_code KRB5_CALLCONV krb5_ser_unpack_bytes
(krb5_octet *,
size_t,
krb5_octet **,
size_t *);
krb5_error_code KRB5_CALLCONV krb5int_cc_default
(krb5_context, krb5_ccache *);
krb5_error_code KRB5_CALLCONV krb5_cc_retrieve_cred_default
(krb5_context, krb5_ccache, krb5_flags,
krb5_creds *, krb5_creds *);
krb5_boolean KRB5_CALLCONV
krb5_creds_compare (krb5_context in_context,
krb5_creds *in_creds,
krb5_creds *in_compare_creds);
void krb5int_set_prompt_types
(krb5_context, krb5_prompt_type *);
krb5_error_code
krb5int_generate_and_save_subkey (krb5_context, krb5_auth_context,
krb5_keyblock * /* Old keyblock, not new! */);
/* set and change password helpers */
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 krb5int_rd_chpw_rep
(krb5_context context, krb5_auth_context auth_context,
krb5_data *packet, int *result_code,
krb5_data *result_data);
krb5_error_code KRB5_CALLCONV krb5_chpw_result_code_string
(krb5_context context, int result_code,
char **result_codestr);
krb5_error_code krb5int_mk_setpw_req
(krb5_context context, krb5_auth_context auth_context,
krb5_data *ap_req, krb5_principal targetprinc, char *passwd, krb5_data *packet);
krb5_error_code krb5int_rd_setpw_rep
(krb5_context context, krb5_auth_context auth_context,
krb5_data *packet, int *result_code,
krb5_data *result_data);
krb5_error_code krb5int_setpw_result_code_string
(krb5_context context, int result_code,
const char **result_codestr);
struct srv_dns_entry {
struct srv_dns_entry *next;
int priority;
int weight;
unsigned short port;
char *host;
};
#ifdef KRB5_DNS_LOOKUP
krb5_error_code
krb5int_make_srv_query_realm(const krb5_data *realm,
const char *service,
const char *protocol,
struct srv_dns_entry **answers);
void krb5int_free_srv_dns_data(struct srv_dns_entry *);
#endif
/*
* Convenience function for structure magic number
*/
#define KRB5_VERIFY_MAGIC(structure,magic_number) \
if ((structure)->magic != (magic_number)) return (magic_number);
/* SUNW14resync XXX - see k5-util.h */
#if 0
int krb5_seteuid (int);
#endif
char * krb5_getenv(const char *);
int krb5_setenv (const char *, const char *, int);
void krb5_unsetenv (const char *);
/* SUNW14resync - (from here to EOF) not sure if we need this but will add it
for future resync sake */
/* To keep happy libraries which are (for now) accessing internal stuff */
/* Make sure to increment by one when changing the struct */
#define KRB5INT_ACCESS_STRUCT_VERSION 12
#ifndef ANAME_SZ
struct ktext; /* from krb.h, for krb524 support */
#endif
typedef struct _krb5int_access {
/* crypto stuff */
const struct krb5_hash_provider *md5_hash_provider;
const struct krb5_enc_provider *arcfour_enc_provider;
krb5_error_code (* krb5_hmac) (krb5_context, const struct krb5_hash_provider *hash,
const krb5_keyblock *key,
unsigned int icount, const krb5_data *input,
krb5_data *output);
/* service location and communication */
#ifndef _KERNEL
krb5_error_code (*sendto_udp) (krb5_context, const krb5_data *msg,
const struct addrlist *, struct sendto_callback_info*, krb5_data *reply,
struct sockaddr *, socklen_t *,struct sockaddr *,
socklen_t *, int *,
int (*msg_handler)(krb5_context, const krb5_data *, void *),
void *msg_handler_data);
krb5_error_code (*add_host_to_list)(struct addrlist *lp,
const char *hostname,
int port, int secport,
int socktype, int family);
void (*free_addrlist) (struct addrlist *);
#endif /* _KERNEL */
krb5_error_code (*make_srv_query_realm)(const krb5_data *realm,
const char *service,
const char *protocol,
struct srv_dns_entry **answers);
void (*free_srv_dns_data)(struct srv_dns_entry *);
int (*use_dns_kdc)(krb5_context);
krb5_error_code (*clean_hostname)(krb5_context, const char *, char *, size_t);
/* krb4 compatibility stuff -- may be null if not enabled */
krb5_int32 (*krb_life_to_time)(krb5_int32, int);
int (*krb_time_to_life)(krb5_int32, krb5_int32);
int (*krb524_encode_v4tkt)(struct ktext *, char *, unsigned int *);
krb5_error_code (*krb5int_c_mandatory_cksumtype)
(krb5_context, krb5_enctype, krb5_cksumtype *);
krb5_error_code (KRB5_CALLCONV *krb5_ser_pack_int64)
(krb5_int64, krb5_octet **, size_t *);
krb5_error_code (KRB5_CALLCONV *krb5_ser_unpack_int64)
(krb5_int64 *, krb5_octet **, size_t *);
/* Used for KDB LDAP back end. */
krb5_error_code
(*asn1_ldap_encode_sequence_of_keys) (struct _krb5_key_data *key_data,
krb5_int16 n_key_data,
krb5_int32 mkvno,
krb5_data **code);
krb5_error_code
(*asn1_ldap_decode_sequence_of_keys) (krb5_data *in,
struct _krb5_key_data **out,
krb5_int16 *n_key_data,
int *mkvno);
/*
* pkinit asn.1 encode/decode functions
*/
krb5_error_code (*encode_krb5_auth_pack)
(const krb5_auth_pack *rep, krb5_data **code);
krb5_error_code (*encode_krb5_auth_pack_draft9)
(const krb5_auth_pack_draft9 *rep, krb5_data **code);
krb5_error_code (*encode_krb5_kdc_dh_key_info)
(const krb5_kdc_dh_key_info *rep, krb5_data **code);
krb5_error_code (*encode_krb5_pa_pk_as_rep)
(const krb5_pa_pk_as_rep *rep, krb5_data **code);
krb5_error_code (*encode_krb5_pa_pk_as_rep_draft9)
(const krb5_pa_pk_as_rep_draft9 *rep, krb5_data **code);
krb5_error_code (*encode_krb5_pa_pk_as_req)
(const krb5_pa_pk_as_req *rep, krb5_data **code);
krb5_error_code (*encode_krb5_pa_pk_as_req_draft9)
(const krb5_pa_pk_as_req_draft9 *rep, krb5_data **code);
krb5_error_code (*encode_krb5_reply_key_pack)
(const krb5_reply_key_pack *, krb5_data **code);
krb5_error_code (*encode_krb5_reply_key_pack_draft9)
(const krb5_reply_key_pack_draft9 *, krb5_data **code);
krb5_error_code (*encode_krb5_td_dh_parameters)
(const krb5_algorithm_identifier **, krb5_data **code);
krb5_error_code (*encode_krb5_td_trusted_certifiers)
(const krb5_external_principal_identifier **, krb5_data **code);
krb5_error_code (*encode_krb5_typed_data)
(const krb5_typed_data **, krb5_data **code);
krb5_error_code (*decode_krb5_auth_pack)
(const krb5_data *, krb5_auth_pack **);
krb5_error_code (*decode_krb5_auth_pack_draft9)
(const krb5_data *, krb5_auth_pack_draft9 **);
krb5_error_code (*decode_krb5_pa_pk_as_req)
(const krb5_data *, krb5_pa_pk_as_req **);
krb5_error_code (*decode_krb5_pa_pk_as_req_draft9)
(const krb5_data *, krb5_pa_pk_as_req_draft9 **);
krb5_error_code (*decode_krb5_pa_pk_as_rep)
(const krb5_data *, krb5_pa_pk_as_rep **);
krb5_error_code (*decode_krb5_pa_pk_as_rep_draft9)
(const krb5_data *, krb5_pa_pk_as_rep_draft9 **);
krb5_error_code (*decode_krb5_kdc_dh_key_info)
(const krb5_data *, krb5_kdc_dh_key_info **);
krb5_error_code (*decode_krb5_principal_name)
(const krb5_data *, krb5_principal_data **);
krb5_error_code (*decode_krb5_reply_key_pack)
(const krb5_data *, krb5_reply_key_pack **);
krb5_error_code (*decode_krb5_reply_key_pack_draft9)
(const krb5_data *, krb5_reply_key_pack_draft9 **);
krb5_error_code (*decode_krb5_td_dh_parameters)
(const krb5_data *, krb5_algorithm_identifier ***);
krb5_error_code (*decode_krb5_td_trusted_certifiers)
(const krb5_data *, krb5_external_principal_identifier ***);
krb5_error_code (*decode_krb5_typed_data)
(const krb5_data *, krb5_typed_data ***);
krb5_error_code (*decode_krb5_as_req)
(const krb5_data *output, krb5_kdc_req **rep);
krb5_error_code (*encode_krb5_kdc_req_body)
(const krb5_kdc_req *rep, krb5_data **code);
void (KRB5_CALLCONV *krb5_free_kdc_req)
(krb5_context, krb5_kdc_req * );
void (*krb5int_set_prompt_types)
(krb5_context, krb5_prompt_type *);
krb5_error_code (*encode_krb5_authdata_elt)
(const krb5_authdata *rep, krb5_data **code);
} krb5int_access;
#define KRB5INT_ACCESS_VERSION \
(((krb5_int32)((sizeof(krb5int_access) & 0xFFFF) | \
(KRB5INT_ACCESS_STRUCT_VERSION << 16))) & 0xFFFFFFFF)
krb5_error_code KRB5_CALLCONV krb5int_accessor
(krb5int_access*, krb5_int32);
/* Ick -- some krb524 and krb4 support placed in the krb5 library,
because AFS (and potentially other applications?) use the krb4
object as an opaque token, which (in some implementations) is not
in fact a krb4 ticket, so we don't want to drag in the krb4 support
just to enable this. */
#define KRB524_SERVICE "krb524"
#define KRB524_PORT 4444
/* v4lifetime.c */
extern krb5_int32 krb5int_krb_life_to_time(krb5_int32, int);
extern int krb5int_krb_time_to_life(krb5_int32, krb5_int32);
/* conv_creds.c */
int krb5int_encode_v4tkt
(struct ktext *v4tkt, char *buf, unsigned int *encoded_len);
/* send524.c */
int krb5int_524_sendto_kdc
(krb5_context context, const krb5_data * message,
const krb5_data * realm, krb5_data * reply,
struct sockaddr *, socklen_t *);
/* temporary -- this should be under lib/krb5/ccache somewhere */
struct _krb5_ccache {
krb5_magic magic;
const struct _krb5_cc_ops *ops;
krb5_pointer data;
};
/*
* Per-type ccache cursor.
*/
struct krb5_cc_ptcursor {
const struct _krb5_cc_ops *ops;
krb5_pointer data;
};
typedef struct krb5_cc_ptcursor *krb5_cc_ptcursor;
struct _krb5_cc_ops {
krb5_magic magic;
char *prefix;
const char * (KRB5_CALLCONV *get_name) (krb5_context, krb5_ccache);
krb5_error_code (KRB5_CALLCONV *resolve) (krb5_context, krb5_ccache *,
const char *);
krb5_error_code (KRB5_CALLCONV *gen_new) (krb5_context, krb5_ccache *);
krb5_error_code (KRB5_CALLCONV *init) (krb5_context, krb5_ccache,
krb5_principal);
krb5_error_code (KRB5_CALLCONV *destroy) (krb5_context, krb5_ccache);
krb5_error_code (KRB5_CALLCONV *close) (krb5_context, krb5_ccache);
krb5_error_code (KRB5_CALLCONV *store) (krb5_context, krb5_ccache,
krb5_creds *);
krb5_error_code (KRB5_CALLCONV *retrieve) (krb5_context, krb5_ccache,
krb5_flags, krb5_creds *,
krb5_creds *);
krb5_error_code (KRB5_CALLCONV *get_princ) (krb5_context, krb5_ccache,
krb5_principal *);
krb5_error_code (KRB5_CALLCONV *get_first) (krb5_context, krb5_ccache,
krb5_cc_cursor *);
krb5_error_code (KRB5_CALLCONV *get_next) (krb5_context, krb5_ccache,
krb5_cc_cursor *, krb5_creds *);
krb5_error_code (KRB5_CALLCONV *end_get) (krb5_context, krb5_ccache,
krb5_cc_cursor *);
krb5_error_code (KRB5_CALLCONV *remove_cred) (krb5_context, krb5_ccache,
krb5_flags, krb5_creds *);
krb5_error_code (KRB5_CALLCONV *set_flags) (krb5_context, krb5_ccache,
krb5_flags);
krb5_error_code (KRB5_CALLCONV *get_flags) (krb5_context, krb5_ccache,
krb5_flags *);
krb5_error_code (KRB5_CALLCONV *ptcursor_new)(krb5_context,
krb5_cc_ptcursor *);
krb5_error_code (KRB5_CALLCONV *ptcursor_next)(krb5_context,
krb5_cc_ptcursor,
krb5_ccache *);
krb5_error_code (KRB5_CALLCONV *ptcursor_free)(krb5_context,
krb5_cc_ptcursor *);
krb5_error_code (KRB5_CALLCONV *move)(krb5_context, krb5_ccache);
krb5_error_code (KRB5_CALLCONV *lastchange)(krb5_context,
krb5_ccache, krb5_timestamp *);
krb5_error_code (KRB5_CALLCONV *wasdefault)(krb5_context, krb5_ccache,
krb5_timestamp *);
};
extern const krb5_cc_ops *krb5_cc_dfl_ops;
krb5_error_code
krb5int_cc_os_default_name(krb5_context context, char **name);
/*
* Cursor for iterating over ccache types
*/
struct krb5_cc_typecursor;
typedef struct krb5_cc_typecursor *krb5_cc_typecursor;
krb5_error_code
krb5int_cc_typecursor_new(krb5_context context, krb5_cc_typecursor *cursor);
krb5_error_code
krb5int_cc_typecursor_next(
krb5_context context,
krb5_cc_typecursor cursor,
const struct _krb5_cc_ops **ops);
krb5_error_code
krb5int_cc_typecursor_free(
krb5_context context,
krb5_cc_typecursor *cursor);
typedef struct _krb5_donot_replay {
krb5_magic magic;
krb5_ui_4 hash;
char *server; /* null-terminated */
char *client; /* null-terminated */
char *msghash; /* null-terminated */
krb5_int32 cusec;
krb5_timestamp ctime;
} krb5_donot_replay;
krb5_error_code krb5_rc_default
(krb5_context,
krb5_rcache *);
krb5_error_code krb5_rc_resolve_type
(krb5_context,
krb5_rcache *,char *);
krb5_error_code krb5_rc_resolve_full
(krb5_context,
krb5_rcache *,char *);
char * krb5_rc_get_type
(krb5_context,
krb5_rcache);
char * krb5_rc_default_type
(krb5_context);
char * krb5_rc_default_name
(krb5_context);
krb5_error_code krb5_auth_to_rep
(krb5_context,
krb5_tkt_authent *,
krb5_donot_replay *);
krb5_error_code KRB5_CALLCONV krb5_rc_initialize
(krb5_context, krb5_rcache,krb5_deltat);
krb5_error_code KRB5_CALLCONV krb5_rc_recover_or_initialize
(krb5_context, krb5_rcache,krb5_deltat);
krb5_error_code KRB5_CALLCONV krb5_rc_recover
(krb5_context, krb5_rcache);
krb5_error_code KRB5_CALLCONV krb5_rc_destroy
(krb5_context, krb5_rcache);
krb5_error_code KRB5_CALLCONV krb5_rc_close
(krb5_context, krb5_rcache);
krb5_error_code KRB5_CALLCONV krb5_rc_store
(krb5_context, krb5_rcache,krb5_donot_replay *);
krb5_error_code KRB5_CALLCONV krb5_rc_expunge
(krb5_context, krb5_rcache);
krb5_error_code KRB5_CALLCONV krb5_rc_get_lifespan
(krb5_context, krb5_rcache,krb5_deltat *);
char *KRB5_CALLCONV krb5_rc_get_name
(krb5_context, krb5_rcache);
krb5_error_code KRB5_CALLCONV krb5_rc_resolve
(krb5_context, krb5_rcache, char *);
typedef struct _krb5_kt_ops {
krb5_magic magic;
char *prefix;
/* routines always present */
krb5_error_code (KRB5_CALLCONV *resolve)
(krb5_context,
const char *,
krb5_keytab *);
krb5_error_code (KRB5_CALLCONV *get_name)
(krb5_context,
krb5_keytab,
char *,
unsigned int);
krb5_error_code (KRB5_CALLCONV *close)
(krb5_context,
krb5_keytab);
krb5_error_code (KRB5_CALLCONV *get)
(krb5_context,
krb5_keytab,
krb5_const_principal,
krb5_kvno,
krb5_enctype,
krb5_keytab_entry *);
krb5_error_code (KRB5_CALLCONV *start_seq_get)
(krb5_context,
krb5_keytab,
krb5_kt_cursor *);
krb5_error_code (KRB5_CALLCONV *get_next)
(krb5_context,
krb5_keytab,
krb5_keytab_entry *,
krb5_kt_cursor *);
krb5_error_code (KRB5_CALLCONV *end_get)
(krb5_context,
krb5_keytab,
krb5_kt_cursor *);
/* routines to be included on extended version (write routines) */
krb5_error_code (KRB5_CALLCONV *add)
(krb5_context,
krb5_keytab,
krb5_keytab_entry *);
krb5_error_code (KRB5_CALLCONV *remove)
(krb5_context,
krb5_keytab,
krb5_keytab_entry *);
/* Handle for serializer */
const krb5_ser_entry *serializer;
} krb5_kt_ops;
extern const krb5_kt_ops krb5_kt_dfl_ops;
extern krb5_error_code krb5int_translate_gai_error (int);
/* Not sure it's ready for exposure just yet. */
extern krb5_error_code
krb5int_c_mandatory_cksumtype (krb5_context, krb5_enctype, krb5_cksumtype *);
extern int krb5int_crypto_init (void);
extern int krb5int_prng_init(void);
/*
* SUNW14resync
* Hack (?) to neuter C99 "inline" which causes warnings w/our build.
*/
#define inline
/* Some data comparison and conversion functions. */
#if 0
static inline int data_cmp(krb5_data d1, krb5_data d2)
{
if (d1.length < d2.length) return -1;
if (d1.length > d2.length) return 1;
return memcmp(d1.data, d2.data, d1.length);
}
static inline int data_eq (krb5_data d1, krb5_data d2)
{
return data_cmp(d1, d2) == 0;
}
#else
static inline int data_eq (krb5_data d1, krb5_data d2)
{
return (d1.length == d2.length
&& !memcmp(d1.data, d2.data, d1.length));
}
#endif
static inline krb5_data string2data (char *str)
{
krb5_data d;
d.magic = KV5M_DATA;
d.length = strlen(str);
d.data = str;
return d;
}
/*LINTED*/
static inline int data_eq_string (krb5_data d, char *s)
{
return data_eq(d, string2data(s));
}
/*LINTED*/
static inline int authdata_eq (krb5_authdata a1, krb5_authdata a2)
{
return (a1.ad_type == a2.ad_type
&& a1.length == a2.length
&& !memcmp(a1.contents, a2.contents, a1.length));
}
/* Solaris kerberos */
krb5_boolean KRB5_CALLCONV is_in_keytype
(krb5_const krb5_enctype *keytype,
int numkeytypes, krb5_enctype enctype);
/*
* Solaris Kerberos
* Use krb5_getuid() to select the mechanism to obtain the uid.
*/
extern uid_t krb5_getuid();
/*
* Referral definitions, debugging hooks, and subfunctions.
*/
#define KRB5_REFERRAL_MAXHOPS 5
/* #define DEBUG_REFERRALS */
#ifdef DEBUG_REFERRALS
void krb5int_dbgref_dump_principal(char *, krb5_principal);
#endif
/* Common hostname-parsing code. */
krb5_error_code KRB5_CALLCONV krb5int_clean_hostname
(krb5_context,
const char *,
char *,
size_t);
/*
* Solaris Kerberos
* Kernel & user space realloc.
*/
void *krb5int_realloc
(void *oldp,
size_t new_size,
size_t old_size);
#endif /* _KRB5_INT_H */
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* k5-platform.h
*
* Copyright 2003, 2004, 2005 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.
*
*
* Some platform-dependent definitions to sync up the C support level.
* Some to a C99-ish level, some related utility code.
*
* Currently:
* + make "static inline" work
* + 64-bit types and load/store code
* + SIZE_MAX
* + shared library init/fini hooks
* + consistent getpwnam/getpwuid interfaces
*/
static unsigned short
load_16_be (unsigned char *p)
{
return (p[1] | (p[0] << 8));
}
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* k5-platform.h
*
* Copyright 2003, 2004, 2005 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.
*
*
* Some platform-dependent definitions to sync up the C support level.
* Some to a C99-ish level, some related utility code.
*
* Currently:
* + make "static inline" work
* + 64-bit types and load/store code
* + SIZE_MAX
* + shared library init/fini hooks
* + consistent getpwnam/getpwuid interfaces
*/
static unsigned int
load_32_be (unsigned char *p)
{
return (p[3] | (p[2] << 8) | (p[1] << 16) | (p[0] << 24));
}
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* k5-platform.h
*
* Copyright 2003, 2004, 2005 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.
*
*
* Some platform-dependent definitions to sync up the C support level.
* Some to a C99-ish level, some related utility code.
*
* Currently:
* + make "static inline" work
* + 64-bit types and load/store code
* + SIZE_MAX
* + shared library init/fini hooks
* + consistent getpwnam/getpwuid interfaces
*/
#include <k5-platform-load_32.h>
static UINT64_TYPE
load_64_be (unsigned char *p)
{
return ((UINT64_TYPE)load_32_be(p) << 32) | load_32_be(p+4);
}
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* k5-platform.h
*
* Copyright 2003, 2004, 2005 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.
*
*
* Some platform-dependent definitions to sync up the C support level.
* Some to a C99-ish level, some related utility code.
*
* Currently:
* + make "static inline" work
* + 64-bit types and load/store code
* + SIZE_MAX
* + shared library init/fini hooks
* + consistent getpwnam/getpwuid interfaces
*/
static void
store_16_be (unsigned int val, unsigned char *p)
{
p[0] = (val >> 8) & 0xff;
p[1] = (val ) & 0xff;
}
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* k5-platform.h
*
* Copyright 2003, 2004, 2005 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.
*
*
* Some platform-dependent definitions to sync up the C support level.
* Some to a C99-ish level, some related utility code.
*
* Currently:
* + make "static inline" work
* + 64-bit types and load/store code
* + SIZE_MAX
* + shared library init/fini hooks
* + consistent getpwnam/getpwuid interfaces
*/
static void
store_32_be (unsigned int val, unsigned char *p)
{
p[0] = (val >> 24) & 0xff;
p[1] = (val >> 16) & 0xff;
p[2] = (val >> 8) & 0xff;
p[3] = (val ) & 0xff;
}
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* k5-platform.h
*
* Copyright 2003, 2004, 2005 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.
*
*
* Some platform-dependent definitions to sync up the C support level.
* Some to a C99-ish level, some related utility code.
*
* Currently:
* + make "static inline" work
* + 64-bit types and load/store code
* + SIZE_MAX
* + shared library init/fini hooks
* + consistent getpwnam/getpwuid interfaces
*/
static void
store_64_be (UINT64_TYPE val, unsigned char *p)
{
p[0] = (unsigned char)((val >> 56) & 0xff);
p[1] = (unsigned char)((val >> 48) & 0xff);
p[2] = (unsigned char)((val >> 40) & 0xff);
p[3] = (unsigned char)((val >> 32) & 0xff);
p[4] = (unsigned char)((val >> 24) & 0xff);
p[5] = (unsigned char)((val >> 16) & 0xff);
p[6] = (unsigned char)((val >> 8) & 0xff);
p[7] = (unsigned char)((val ) & 0xff);
}
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* k5-platform.h
*
* Copyright 2003, 2004, 2005 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.
*
*
* Some platform-dependent definitions to sync up the C support level.
* Some to a C99-ish level, some related utility code.
*
* Currently:
* + make "static inline" work
* + 64-bit types and load/store code
* + SIZE_MAX
* + shared library init/fini hooks
* + consistent getpwnam/getpwuid interfaces
*/
#ifndef K5_PLATFORM_H
#define K5_PLATFORM_H
/* Solaris Kerberos */
#ifndef _KERNEL
#include <sys/types.h>
#include "autoconf.h"
/* Initialization and finalization function support for libraries.
At top level, before the functions are defined or even declared:
MAKE_INIT_FUNCTION(init_fn);
MAKE_FINI_FUNCTION(fini_fn);
Then:
int init_fn(void) { ... }
void fini_fn(void) { if (INITIALIZER_RAN(init_fn)) ... }
In code, in the same file:
err = CALL_INIT_FUNCTION(init_fn);
To trigger or verify the initializer invocation from another file,
a helper function must be created.
This model handles both the load-time execution (Windows) and
delayed execution (pthread_once) approaches, and should be able to
guarantee in both cases that the init function is run once, in one
thread, before other stuff in the library is done; furthermore, the
finalization code should only run if the initialization code did.
(Maybe I could've made the "if INITIALIZER_RAN" test implicit, via
another function hidden in macros, but this is hairy enough
already.)
The init_fn and fini_fn names should be chosen such that any
exported names staring with those names, and optionally followed by
additional characters, fits in with any namespace constraints on
the library in question.
There's also PROGRAM_EXITING() currently always defined as zero.
If there's some trivial way to find out if the fini function is
being called because the program that the library is linked into is
exiting, we can just skip all the work because the resources are
about to be freed up anyways. Generally this is likely to be the
same as distinguishing whether the library was loaded dynamically
while the program was running, or loaded as part of program
startup. On most platforms, I don't think we can distinguish these
cases easily, and it's probably not worth expending any significant
effort. (Note in particular that atexit() won't do, because if the
library is explicitly loaded and unloaded, it would have to be able
to deregister the atexit callback function. Also, the system limit
on atexit callbacks may be small.)
Implementation outline:
Windows: MAKE_FINI_FUNCTION creates a symbol with a magic name that
is sought at library build time, and code is added to invoke the
function when the library is unloaded. MAKE_INIT_FUNCTION does
likewise, but the function is invoked when the library is loaded,
and an extra variable is declared to hold an error code and a "yes
the initializer ran" flag. CALL_INIT_FUNCTION blows up if the flag
isn't set, otherwise returns the error code.
UNIX: MAKE_INIT_FUNCTION creates and initializes a variable with a
name derived from the function name, containing a k5_once_t
(pthread_once_t or int), an error code, and a pointer to the
function. The function itself is declared static, but the
associated variable has external linkage. CALL_INIT_FUNCTION
ensures thath the function is called exactly once (pthread_once or
just check the flag) and returns the stored error code (or the
pthread_once error).
(That's the basic idea. With some debugging assert() calls and
such, it's a bit more complicated. And we also need to handle
doing the pthread test at run time on systems where that works, so
we use the k5_once_t stuff instead.)
UNIX, with compiler support: MAKE_FINI_FUNCTION declares the
function as a destructor, and the run time linker support or
whatever will cause it to be invoked when the library is unloaded,
the program ends, etc.
UNIX, with linker support: MAKE_FINI_FUNCTION creates a symbol with
a magic name that is sought at library build time, and linker
options are used to mark it as a finalization function for the
library. The symbol must be exported.
UNIX, no library finalization support: The finalization function
never runs, and we leak memory. Tough.
DELAY_INITIALIZER will be defined by the configure script if we
want to use k5_once instead of load-time initialization. That'll
be the preferred method on most systems except Windows, where we
have to initialize some mutexes.
For maximum flexibility in defining the macros, the function name
parameter should be a simple name, not even a macro defined as
another name. The function should have a unique name, and should
conform to whatever namespace is used by the library in question.
(We do have export lists, but (1) they're not used for all
platforms, and (2) they're not used for static libraries.)
If the macro expansion needs the function to have been declared, it
must include a declaration. If it is not necessary for the symbol
name to be exported from the object file, the macro should declare
it as "static". Hence the signature must exactly match "void
foo(void)". (ANSI C allows a static declaration followed by a
non-static one; the result is internal linkage.) The macro
expansion has to come before the function, because gcc apparently
won't act on "__attribute__((constructor))" if it comes after the
function definition.
This is going to be compiler- and environment-specific, and may
require some support at library build time, and/or "asm"
statements. But through macro expansion and auxiliary functions,
we should be able to handle most things except #pragma.
It's okay for this code to require that the library be built
with the same compiler and compiler options throughout, but
we shouldn't require that the library and application use the
same compiler.
For static libraries, we don't really care about cleanup too much,
since it's all memory handling and mutex allocation which will all
be cleaned up when the program exits. Thus, it's okay if gcc-built
static libraries don't play nicely with cc-built executables when
it comes to static constructors, just as long as it doesn't cause
linking to fail.
For dynamic libraries on UNIX, we'll use pthread_once-type support
to do delayed initialization, so if finalization can't be made to
work, we'll only have memory leaks in a load/use/unload cycle. If
anyone (like, say, the OS vendor) complains about this, they can
tell us how to get a shared library finalization function invoked
automatically.
Currently there's --disable-delayed-initialization for preventing
the initialization from being delayed on UNIX, but that's mainly
just for testing the linker options for initialization, and will
probably be removed at some point. */
/* Helper macros. */
# define JOIN__2_2(A,B) A ## _ ## _ ## B
# define JOIN__2(A,B) JOIN__2_2(A,B)
/* XXX Should test USE_LINKER_INIT_OPTION early, and if it's set,
always provide a function by the expected name, even if we're
delaying initialization. */
#if defined(DELAY_INITIALIZER)
/* Run the initialization code during program execution, at the latest
possible moment. This means multiple threads may be active. */
# include "k5-thread.h"
typedef struct { k5_once_t once; int error, did_run; void (*fn)(void); } k5_init_t;
# ifdef USE_LINKER_INIT_OPTION
# define MAYBE_DUMMY_INIT(NAME) \
void JOIN__2(NAME, auxinit) () { }
# else
# define MAYBE_DUMMY_INIT(NAME)
# endif
# ifdef __GNUC__
/* Do it in macro form so we get the file/line of the invocation if
the assertion fails. */
# define k5_call_init_function(I) \
(__extension__ ({ \
k5_init_t *k5int_i = (I); \
int k5int_err = k5_once(&k5int_i->once, k5int_i->fn); \
(k5int_err \
? k5int_err \
: (assert(k5int_i->did_run != 0), k5int_i->error)); \
}))
# define MAYBE_DEFINE_CALLINIT_FUNCTION
# else
# define MAYBE_DEFINE_CALLINIT_FUNCTION \
static int k5_call_init_function(k5_init_t *i) \
{ \
int err; \
err = k5_once(&i->once, i->fn); \
if (err) \
return err; \
assert (i->did_run != 0); \
return i->error; \
}
# endif
# define MAKE_INIT_FUNCTION(NAME) \
static int NAME(void); \
MAYBE_DUMMY_INIT(NAME) \
/* forward declaration for use in initializer */ \
static void JOIN__2(NAME, aux) (void); \
static k5_init_t JOIN__2(NAME, once) = \
{ K5_ONCE_INIT, 0, 0, JOIN__2(NAME, aux) }; \
MAYBE_DEFINE_CALLINIT_FUNCTION \
static void JOIN__2(NAME, aux) (void) \
{ \
JOIN__2(NAME, once).did_run = 1; \
JOIN__2(NAME, once).error = NAME(); \
} \
/* so ';' following macro use won't get error */ \
static int NAME(void)
# define CALL_INIT_FUNCTION(NAME) \
k5_call_init_function(& JOIN__2(NAME, once))
/* This should be called in finalization only, so we shouldn't have
multiple active threads mucking around in our library at this
point. So ignore the once_t object and just look at the flag.
XXX Could we have problems with memory coherence between processors
if we don't invoke mutex/once routines? Probably not, the
application code should already be coordinating things such that
the library code is not in use by this point, and memory
synchronization will be needed there. */
# define INITIALIZER_RAN(NAME) \
(JOIN__2(NAME, once).did_run && JOIN__2(NAME, once).error == 0)
# define PROGRAM_EXITING() (0)
#elif defined(__GNUC__) && !defined(_WIN32) && defined(CONSTRUCTOR_ATTR_WORKS)
/* Run initializer at load time, via GCC/C++ hook magic. */
# ifdef USE_LINKER_INIT_OPTION
/* Both gcc and linker option?? Favor gcc. */
# define MAYBE_DUMMY_INIT(NAME) \
void JOIN__2(NAME, auxinit) () { }
# else
# define MAYBE_DUMMY_INIT(NAME)
# endif
typedef struct { int error; unsigned char did_run; } k5_init_t;
# define MAKE_INIT_FUNCTION(NAME) \
MAYBE_DUMMY_INIT(NAME) \
static k5_init_t JOIN__2(NAME, ran) \
= { 0, 2 }; \
static void JOIN__2(NAME, aux)(void) \
__attribute__((constructor)); \
static int NAME(void); \
static void JOIN__2(NAME, aux)(void) \
{ \
JOIN__2(NAME, ran).error = NAME(); \
JOIN__2(NAME, ran).did_run = 3; \
} \
static int NAME(void)
# define CALL_INIT_FUNCTION(NAME) \
(JOIN__2(NAME, ran).did_run == 3 \
? JOIN__2(NAME, ran).error \
: (abort(),0))
# define INITIALIZER_RAN(NAME) (JOIN__2(NAME,ran).did_run == 3 && JOIN__2(NAME, ran).error == 0)
# define PROGRAM_EXITING() (0)
#elif defined(USE_LINKER_INIT_OPTION) || defined(_WIN32)
/* Run initializer at load time, via linker magic, or in the
case of WIN32, win_glue.c hard-coded knowledge. */
typedef struct { int error; unsigned char did_run; } k5_init_t;
# define MAKE_INIT_FUNCTION(NAME) \
static k5_init_t JOIN__2(NAME, ran) \
= { 0, 2 }; \
static int NAME(void); \
void JOIN__2(NAME, auxinit)() \
{ \
JOIN__2(NAME, ran).error = NAME(); \
JOIN__2(NAME, ran).did_run = 3; \
} \
static int NAME(void)
# define CALL_INIT_FUNCTION(NAME) \
(JOIN__2(NAME, ran).did_run == 3 \
? JOIN__2(NAME, ran).error \
: (abort(),0))
# define INITIALIZER_RAN(NAME) \
(JOIN__2(NAME, ran).error == 0)
# define PROGRAM_EXITING() (0)
#else
# error "Don't know how to do load-time initializers for this configuration."
# define PROGRAM_EXITING() (0)
#endif
#if defined(USE_LINKER_FINI_OPTION) || defined(_WIN32)
/* If we're told the linker option will be used, it doesn't really
matter what compiler we're using. Do it the same way
regardless. */
# ifdef __hpux
/* On HP-UX, we need this auxiliary function. At dynamic load or
unload time (but *not* program startup and termination for
link-time specified libraries), the linker-indicated function
is called with a handle on the library and a flag indicating
whether it's being loaded or unloaded.
The "real" fini function doesn't need to be exported, so
declare it static.
As usual, the final declaration is just for syntactic
convenience, so the top-level invocation of this macro can be
followed by a semicolon. */
# include <dl.h>
# define MAKE_FINI_FUNCTION(NAME) \
static void NAME(void); \
void JOIN__2(NAME, auxfini)(shl_t, int); /* silence gcc warnings */ \
void JOIN__2(NAME, auxfini)(shl_t h, int l) { if (!l) NAME(); } \
static void NAME(void)
# else /* not hpux */
# define MAKE_FINI_FUNCTION(NAME) \
void NAME(void)
# endif
#elif defined(__GNUC__) && defined(DESTRUCTOR_ATTR_WORKS)
/* If we're using gcc, if the C++ support works, the compiler should
build executables and shared libraries that support the use of
static constructors and destructors. The C compiler supports a
function attribute that makes use of the same facility as C++.
XXX How do we know if the C++ support actually works? */
# define MAKE_FINI_FUNCTION(NAME) \
static void NAME(void) __attribute__((destructor))
#elif !defined(SHARED)
/* In this case, we just don't care about finalization.
The code will still define the function, but we won't do anything
with it. Annoying: This may generate unused-function warnings. */
# define MAKE_FINI_FUNCTION(NAME) \
static void NAME(void)
#else
# error "Don't know how to do unload-time finalization for this configuration."
#endif
#endif /* !_KERNEL */
/* 64-bit support: krb5_ui_8 and krb5_int64.
This should move to krb5.h eventually, but without the namespace
pollution from the autoconf macros. */
#if defined(HAVE_STDINT_H) || defined(HAVE_INTTYPES_H)
# ifdef HAVE_STDINT_H
# include <stdint.h>
# endif
# ifdef HAVE_INTTYPES_H
# include <inttypes.h>
# endif
# define INT64_TYPE int64_t
# define UINT64_TYPE uint64_t
#elif defined(_WIN32)
# define INT64_TYPE signed __int64
# define UINT64_TYPE unsigned __int64
#else /* not Windows, and neither stdint.h nor inttypes.h */
# define INT64_TYPE signed long long
# define UINT64_TYPE unsigned long long
#endif
#ifndef _KERNEL
#include <limits.h>
#endif /* !_KERNEL */
#ifndef SIZE_MAX
# define SIZE_MAX ((size_t)((size_t)0 - 1))
#endif
/* Read and write integer values as (unaligned) octet strings in
specific byte orders.
Add per-platform optimizations later if needed. (E.g., maybe x86
unaligned word stores and gcc/asm instructions for byte swaps,
etc.) */
/* Solaris Kerberos: To avoid problems with lint the following
functions can be found in separate header files. */
#if 0
static void
store_16_be (unsigned int val, unsigned char *p)
{
p[0] = (val >> 8) & 0xff;
p[1] = (val ) & 0xff;
}
static void
store_16_le (unsigned int val, unsigned char *p)
{
p[1] = (val >> 8) & 0xff;
p[0] = (val ) & 0xff;
}
static void
store_32_be (unsigned int val, unsigned char *p)
{
p[0] = (val >> 24) & 0xff;
p[1] = (val >> 16) & 0xff;
p[2] = (val >> 8) & 0xff;
p[3] = (val ) & 0xff;
}
static void
store_32_le (unsigned int val, unsigned char *p)
{
p[3] = (val >> 24) & 0xff;
p[2] = (val >> 16) & 0xff;
p[1] = (val >> 8) & 0xff;
p[0] = (val ) & 0xff;
}
static void
store_64_be (UINT64_TYPE val, unsigned char *p)
{
p[0] = (unsigned char)((val >> 56) & 0xff);
p[1] = (unsigned char)((val >> 48) & 0xff);
p[2] = (unsigned char)((val >> 40) & 0xff);
p[3] = (unsigned char)((val >> 32) & 0xff);
p[4] = (unsigned char)((val >> 24) & 0xff);
p[5] = (unsigned char)((val >> 16) & 0xff);
p[6] = (unsigned char)((val >> 8) & 0xff);
p[7] = (unsigned char)((val ) & 0xff);
}
static void
store_64_le (UINT64_TYPE val, unsigned char *p)
{
p[7] = (unsigned char)((val >> 56) & 0xff);
p[6] = (unsigned char)((val >> 48) & 0xff);
p[5] = (unsigned char)((val >> 40) & 0xff);
p[4] = (unsigned char)((val >> 32) & 0xff);
p[3] = (unsigned char)((val >> 24) & 0xff);
p[2] = (unsigned char)((val >> 16) & 0xff);
p[1] = (unsigned char)((val >> 8) & 0xff);
p[0] = (unsigned char)((val ) & 0xff);
}
static unsigned short
load_16_be (unsigned char *p)
{
return (p[1] | (p[0] << 8));
}
static unsigned short
load_16_le (unsigned char *p)
{
return (p[0] | (p[1] << 8));
}
static unsigned int
load_32_be (unsigned char *p)
{
return (p[3] | (p[2] << 8) | (p[1] << 16) | (p[0] << 24));
}
static unsigned int
load_32_le (unsigned char *p)
{
return (p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24));
}
static UINT64_TYPE
load_64_be (unsigned char *p)
{
return ((UINT64_TYPE)load_32_be(p) << 32) | load_32_be(p+4);
}
static UINT64_TYPE
load_64_le (unsigned char *p)
{
return ((UINT64_TYPE)load_32_le(p+4) << 32) | load_32_le(p);
}
#endif
/* Make the interfaces to getpwnam and getpwuid consistent.
Model the wrappers on the POSIX thread-safe versions, but
use the unsafe system versions if the safe ones don't exist
or we can't figure out their interfaces. */
/* SUNW15resync - just have Solaris relevant ones */
#define k5_getpwnam_r(NAME, REC, BUF, BUFSIZE, OUT) \
(*(OUT) = getpwnam_r(NAME,REC,BUF,BUFSIZE), *(OUT) == NULL ? -1 : 0)
#define k5_getpwuid_r(UID, REC, BUF, BUFSIZE, OUT) \
(*(OUT) = getpwuid_r(UID,REC,BUF,BUFSIZE), *(OUT) == NULL ? -1 : 0)
/* Return true if the snprintf return value RESULT reflects a buffer
overflow for the buffer size SIZE.
We cast the result to unsigned int for two reasons. First, old
implementations of snprintf (such as the one in Solaris 9 and
prior) return -1 on a buffer overflow. Casting the result to -1
will convert that value to UINT_MAX, which should compare larger
than any reasonable buffer size. Second, comparing signed and
unsigned integers will generate warnings with some compilers, and
can have unpredictable results, particularly when the relative
widths of the types is not known (size_t may be the same width as
int or larger).
*/
#define SNPRINTF_OVERFLOW(result, size) \
((unsigned int)(result) >= (size_t)(size))
#endif /* K5_PLATFORM_H */
/*
* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
*/
/*
* include/k5-thread.h
*
* Copyright 2004,2005,2006 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.
*
*
* Preliminary thread support.
*/
#ifndef K5_THREAD_H
#define K5_THREAD_H
#ifdef _KERNEL
#include <sys/ksynch.h>
typedef kmutex_t k5_mutex_t;
#define K5_MUTEX_PARTIAL_INITIALIZER {0}
/* ARGSUSED */
static void k5_mutex_assert_locked(k5_mutex_t *m) { }
static int
k5_mutex_lock(k5_mutex_t *m)
{
mutex_enter(m);
return (0);
}
static int
k5_mutex_unlock(k5_mutex_t *m)
{
mutex_exit(m);
return(0);
}
#else /* _KERNEL */
#include "autoconf.h"
#ifndef KRB5_CALLCONV
# define KRB5_CALLCONV
#endif
#ifndef KRB5_CALLCONV_C
# define KRB5_CALLCONV_C
#endif
/* Interface (tentative):
Mutex support:
// Between these two, we should be able to do pure compile-time
// and pure run-time initialization.
// POSIX: partial initializer is PTHREAD_MUTEX_INITIALIZER,
// finish does nothing
// Windows: partial initializer is an invalid handle,
// finish does the real initialization work
// debug: partial initializer sets one magic value,
// finish verifies and sets a new magic value for
// lock/unlock to check
k5_mutex_t foo_mutex = K5_MUTEX_PARTIAL_INITIALIZER;
int k5_mutex_finish_init(k5_mutex_t *);
// for dynamic allocation
int k5_mutex_init(k5_mutex_t *);
// Must work for both kinds of alloc, even if it means adding flags.
int k5_mutex_destroy(k5_mutex_t *);
// As before.
int k5_mutex_lock(k5_mutex_t *);
int k5_mutex_unlock(k5_mutex_t *);
In each library, one new function to finish the static mutex init,
and any other library-wide initialization that might be desired.
On POSIX, this function would be called via the second support
function (see below). On Windows, it would be called at library
load time. These functions, or functions they calls, should be the
only places that k5_mutex_finish_init gets called.
A second function or macro called at various possible "first" entry
points which either calls pthread_once on the first function
(POSIX), or checks some flag set by the first function (Windows,
debug support), and possibly returns an error. (In the
non-threaded case, a simple flag can be used to avoid multiple
invocations, and the mutexes don't need run-time initialization
anyways.)
A third function for library termination calls mutex_destroy on
each mutex for the library. This function would be called
automatically at library unload time. If it turns out to be needed
at exit time for libraries that don't get unloaded, perhaps we
should also use atexit(). Any static mutexes should be cleaned up
with k5_mutex_destroy here.
How does that second support function invoke the first support
function only once? Through something modelled on pthread_once
that I haven't written up yet. Probably:
k5_once_t foo_once = K5_ONCE_INIT;
k5_once(k5_once_t *, void (*)(void));
For POSIX: Map onto pthread_once facility.
For non-threaded case: A simple flag.
For Windows: Not needed; library init code takes care of it.
XXX: A general k5_once mechanism isn't possible for Windows,
without faking it through named mutexes or mutexes initialized at
startup. I was only using it in one place outside these headers,
so I'm dropping the general scheme. Eventually the existing uses
in k5-thread.h and k5-platform.h will be converted to pthread_once
or static variables.
Thread-specific data:
// TSD keys are limited in number in gssapi/krb5/com_err; enumerate
// them all. This allows support code init to allocate the
// necessary storage for pointers all at once, and avoids any
// possible error in key creation.
enum { ... } k5_key_t;
// Register destructor function. Called in library init code.
int k5_key_register(k5_key_t, void (*destructor)(void *));
// Returns NULL or data.
void *k5_getspecific(k5_key_t);
// Returns error if key out of bounds, or the pointer table can't
// be allocated. A call to k5_key_register must have happened first.
// This may trigger the calling of pthread_setspecific on POSIX.
int k5_setspecific(k5_key_t, void *);
// Called in library termination code.
// Trashes data in all threads, calling the registered destructor
// (but calling it from the current thread).
int k5_key_delete(k5_key_t);
For the non-threaded version, the support code will have a static
array indexed by k5_key_t values, and get/setspecific simply access
the array elements.
The TSD destructor table is global state, protected by a mutex if
threads are enabled.
Debug support: Not much. Might check if k5_key_register has been
called and abort if not.
Any actual external symbols will use the krb5int_ prefix. The k5_
names will be simple macros or inline functions to rename the
external symbols, or slightly more complex ones to expand the
implementation inline (e.g., map to POSIX versions and/or debug
code using __FILE__ and the like).
More to be added, perhaps. */
#undef DEBUG_THREADS /* SUNW14resync XXX */
#undef DEBUG_THREADS_LOC /* SUNW14resync XXX */
#undef DEBUG_THREADS_SLOW /* debugging stuff that'll slow things down? */
#undef DEBUG_THREADS_STATS
#ifndef _KERNEL
#include <assert.h>
#include <stdarg.h>
#define ASSERT assert
#endif
/* For tracking locations, of (e.g.) last lock or unlock of mutex. */
#ifdef DEBUG_THREADS_LOC
typedef struct {
const char *filename;
int lineno;
} k5_debug_loc;
#define K5_DEBUG_LOC_INIT { __FILE__, __LINE__ }
#if __GNUC__ >= 2
#define K5_DEBUG_LOC (__extension__ (k5_debug_loc)K5_DEBUG_LOC_INIT)
#else
static inline k5_debug_loc k5_debug_make_loc(const char *file, int line)
{
k5_debug_loc l;
l.filename = file;
l.lineno = line;
return l;
}
#define K5_DEBUG_LOC (k5_debug_make_loc(__FILE__,__LINE__))
#endif
#else /* ! DEBUG_THREADS_LOC */
typedef char k5_debug_loc;
#define K5_DEBUG_LOC_INIT 0
#define K5_DEBUG_LOC 0
#endif
#define k5_debug_update_loc(L) ((L) = K5_DEBUG_LOC)
/* Statistics gathering:
Currently incomplete, don't try enabling it.
Eventually: Report number of times locked, total and standard
deviation of the time the lock was held, total and std dev time
spent waiting for the lock. "Report" will probably mean "write a
line to a file if a magic environment variable is set." */
#ifdef DEBUG_THREADS_STATS
#if HAVE_TIME_H && (!defined(HAVE_SYS_TIME_H) || defined(TIME_WITH_SYS_TIME))
# include <time.h>
#endif
#if HAVE_SYS_TIME_H
# include <sys/time.h>
#endif
#ifdef HAVE_STDINT_H
# include <stdint.h>
#endif
/* for memset */
#include <string.h>
/* for uint64_t */
#include <inttypes.h>
typedef uint64_t k5_debug_timediff_t; /* or long double */
typedef struct timeval k5_debug_time_t;
static inline k5_debug_timediff_t
timediff(k5_debug_time_t t2, k5_debug_time_t t1)
{
return (t2.tv_sec - t1.tv_sec) * 1000000 + (t2.tv_usec - t1.tv_usec);
}
static inline k5_debug_time_t get_current_time(void)
{
struct timeval tv;
if (gettimeofday(&tv,0) < 0) { tv.tv_sec = tv.tv_usec = 0; }
return tv;
}
struct k5_timediff_stats {
k5_debug_timediff_t valmin, valmax, valsum, valsqsum;
};
typedef struct {
int count;
k5_debug_time_t time_acquired, time_created;
struct k5_timediff_stats lockwait, lockheld;
} k5_debug_mutex_stats;
#define k5_mutex_init_stats(S) \
(memset((S), 0, sizeof(k5_debug_mutex_stats)), \
(S)->time_created = get_current_time(), \
0)
#define k5_mutex_finish_init_stats(S) (0)
#define K5_MUTEX_STATS_INIT { 0, {0}, {0}, {0}, {0} }
typedef k5_debug_time_t k5_mutex_stats_tmp;
#define k5_mutex_stats_start() get_current_time()
void KRB5_CALLCONV krb5int_mutex_lock_update_stats(k5_debug_mutex_stats *m,
k5_mutex_stats_tmp start);
void KRB5_CALLCONV krb5int_mutex_unlock_update_stats(k5_debug_mutex_stats *m);
#define k5_mutex_lock_update_stats krb5int_mutex_lock_update_stats
#define k5_mutex_unlock_update_stats krb5int_mutex_unlock_update_stats
void KRB5_CALLCONV krb5int_mutex_report_stats(/* k5_mutex_t *m */);
#else
typedef char k5_debug_mutex_stats;
#define k5_mutex_init_stats(S) (*(S) = 's', 0)
#define k5_mutex_finish_init_stats(S) (0)
#define K5_MUTEX_STATS_INIT 's'
typedef int k5_mutex_stats_tmp;
#define k5_mutex_stats_start() (0)
#ifdef __GNUC__
static void
k5_mutex_lock_update_stats(k5_debug_mutex_stats *m, k5_mutex_stats_tmp t)
{
}
#else
# define k5_mutex_lock_update_stats(M,S) (S)
#endif
#define k5_mutex_unlock_update_stats(M) (*(M) = 's')
/* If statistics tracking isn't enabled, these functions don't actually
do anything. Declare anyways so we can do type checking etc. */
void KRB5_CALLCONV krb5int_mutex_lock_update_stats(k5_debug_mutex_stats *m,
k5_mutex_stats_tmp start);
void KRB5_CALLCONV krb5int_mutex_unlock_update_stats(k5_debug_mutex_stats *m);
void KRB5_CALLCONV krb5int_mutex_report_stats(/* k5_mutex_t *m */);
#define krb5int_mutex_report_stats(M) ((M)->stats = 'd')
#endif
/* Define the OS mutex bit. */
/* First, if we're not actually doing multiple threads, do we
want the debug support or not? */
#ifdef DEBUG_THREADS
enum k5_mutex_init_states {
K5_MUTEX_DEBUG_PARTLY_INITIALIZED = 0x12,
K5_MUTEX_DEBUG_INITIALIZED,
K5_MUTEX_DEBUG_DESTROYED
};
enum k5_mutex_flag_states {
K5_MUTEX_DEBUG_UNLOCKED = 0x23,
K5_MUTEX_DEBUG_LOCKED
};
typedef struct {
enum k5_mutex_init_states initialized;
enum k5_mutex_flag_states locked;
} k5_os_nothread_mutex;
# define K5_OS_NOTHREAD_MUTEX_PARTIAL_INITIALIZER \
{ K5_MUTEX_DEBUG_PARTLY_INITIALIZED, K5_MUTEX_DEBUG_UNLOCKED }
# define k5_os_nothread_mutex_finish_init(M) \
(ASSERT((M)->initialized != K5_MUTEX_DEBUG_INITIALIZED), \
ASSERT((M)->initialized == K5_MUTEX_DEBUG_PARTLY_INITIALIZED), \
ASSERT((M)->locked == K5_MUTEX_DEBUG_UNLOCKED), \
(M)->initialized = K5_MUTEX_DEBUG_INITIALIZED, 0)
# define k5_os_nothread_mutex_init(M) \
((M)->initialized = K5_MUTEX_DEBUG_INITIALIZED, \
(M)->locked = K5_MUTEX_DEBUG_UNLOCKED, 0)
# define k5_os_nothread_mutex_destroy(M) \
(ASSERT((M)->initialized == K5_MUTEX_DEBUG_INITIALIZED), \
(M)->initialized = K5_MUTEX_DEBUG_DESTROYED, 0)
# define k5_os_nothread_mutex_lock(M) \
(k5_os_nothread_mutex_assert_unlocked(M), \
(M)->locked = K5_MUTEX_DEBUG_LOCKED, 0)
# define k5_os_nothread_mutex_unlock(M) \
(k5_os_nothread_mutex_assert_locked(M), \
(M)->locked = K5_MUTEX_DEBUG_UNLOCKED, 0)
# define k5_os_nothread_mutex_assert_locked(M) \
(ASSERT((M)->initialized == K5_MUTEX_DEBUG_INITIALIZED), \
ASSERT((M)->locked != K5_MUTEX_DEBUG_UNLOCKED), \
ASSERT((M)->locked == K5_MUTEX_DEBUG_LOCKED))
# define k5_os_nothread_mutex_assert_unlocked(M) \
(ASSERT((M)->initialized == K5_MUTEX_DEBUG_INITIALIZED), \
ASSERT((M)->locked != K5_MUTEX_DEBUG_LOCKED), \
ASSERT((M)->locked == K5_MUTEX_DEBUG_UNLOCKED))
#else /* threads disabled and not debugging */
typedef char k5_os_nothread_mutex;
# define K5_OS_NOTHREAD_MUTEX_PARTIAL_INITIALIZER 0
/* Empty inline functions avoid the "statement with no effect"
warnings, and do better type-checking than functions that don't use
their arguments. */
/* SUNW 1.4resync, remove "inline" to avoid warning */
/* ARGSUSED */
/* LINTED */
static int k5_os_nothread_mutex_finish_init(k5_os_nothread_mutex *m) {
return 0;
}
/* ARGSUSED */
/* LINTED */
static int k5_os_nothread_mutex_init(k5_os_nothread_mutex *m) {
return 0;
}
/* ARGSUSED */
/* LINTED */
static int k5_os_nothread_mutex_destroy(k5_os_nothread_mutex *m) {
return 0;
}
/* ARGSUSED */
/* LINTED */
static int k5_os_nothread_mutex_lock(k5_os_nothread_mutex *m) {
return 0;
}
/* ARGSUSED */
/* LINTED */
static int k5_os_nothread_mutex_unlock(k5_os_nothread_mutex *m) {
return 0;
}
# define k5_os_nothread_mutex_assert_locked(M) ((void)0)
# define k5_os_nothread_mutex_assert_unlocked(M) ((void)0)
#endif
/* Values:
2 - function has not been run
3 - function has been run
4 - function is being run -- deadlock detected */
typedef unsigned char k5_os_nothread_once_t;
# define K5_OS_NOTHREAD_ONCE_INIT 2
# define k5_os_nothread_once(O,F) \
(*(O) == 3 ? 0 \
: *(O) == 2 ? (*(O) = 4, (F)(), *(O) = 3, 0) \
: (ASSERT(*(O) != 4), ASSERT(*(O) == 2 || *(O) == 3), 0))
#ifndef ENABLE_THREADS
typedef k5_os_nothread_mutex k5_os_mutex;
# define K5_OS_MUTEX_PARTIAL_INITIALIZER \
K5_OS_NOTHREAD_MUTEX_PARTIAL_INITIALIZER
# define k5_os_mutex_finish_init k5_os_nothread_mutex_finish_init
# define k5_os_mutex_init k5_os_nothread_mutex_init
# define k5_os_mutex_destroy k5_os_nothread_mutex_destroy
# define k5_os_mutex_lock k5_os_nothread_mutex_lock
# define k5_os_mutex_unlock k5_os_nothread_mutex_unlock
# define k5_os_mutex_assert_locked k5_os_nothread_mutex_assert_locked
# define k5_os_mutex_assert_unlocked k5_os_nothread_mutex_assert_unlocked
# define k5_once_t k5_os_nothread_once_t
# define K5_ONCE_INIT K5_OS_NOTHREAD_ONCE_INIT
# define k5_once k5_os_nothread_once
#elif HAVE_PTHREAD
# include <pthread.h>
/* Weak reference support, etc.
Linux: Stub mutex routines exist, but pthread_once does not.
Solaris: In libc there's a pthread_once that doesn't seem to do
anything. Bleah. But pthread_mutexattr_setrobust_np is defined
only in libpthread. However, some version of GNU libc (Red Hat's
Fedora Core 5, reportedly) seems to have that function, but no
declaration, so we'd have to declare it in order to test for its
address. We now have tests to see if pthread_once actually works,
so stick with that for now.
IRIX 6.5 stub pthread support in libc is really annoying. The
pthread_mutex_lock function returns ENOSYS for a program not linked
against -lpthread. No link-time failure, no weak symbols, etc.
The C library doesn't provide pthread_once; we can use weak
reference support for that.
If weak references are not available, then for now, we assume that
the pthread support routines will always be available -- either the
real thing, or functional stubs that merely prohibit creating
threads.
If we find a platform with non-functional stubs and no weak
references, we may have to resort to some hack like dlsym on the
symbol tables of the current process. */
#ifdef HAVE_PRAGMA_WEAK_REF
# pragma weak pthread_once
# pragma weak pthread_mutex_lock
# pragma weak pthread_mutex_unlock
# pragma weak pthread_mutex_destroy
# pragma weak pthread_mutex_init
# pragma weak pthread_self
# pragma weak pthread_equal
# ifdef HAVE_PTHREAD_MUTEXATTR_SETROBUST_NP_IN_THREAD_LIB
# pragma weak pthread_mutexattr_setrobust_np
# endif
# if !defined HAVE_PTHREAD_ONCE
# define K5_PTHREADS_LOADED (&pthread_once != 0)
# elif !defined HAVE_PTHREAD_MUTEXATTR_SETROBUST_NP \
&& defined HAVE_PTHREAD_MUTEXATTR_SETROBUST_NP_IN_THREAD_LIB
# define K5_PTHREADS_LOADED (&pthread_mutexattr_setrobust_np != 0)
# else
# define K5_PTHREADS_LOADED (1)
# endif
#else
/* no pragma weak support */
# define K5_PTHREADS_LOADED (1)
#endif
#if defined(__mips) && defined(__sgi) && (defined(_SYSTYPE_SVR4) || defined(__SYSTYPE_SVR4__))
/* IRIX 6.5 stub pthread support in libc is really annoying. The
pthread_mutex_lock function returns ENOSYS for a program not linked
against -lpthread. No link-time failure, no weak reference tests,
etc.
The C library doesn't provide pthread_once; we can use weak
reference support for that. */
# ifndef HAVE_PRAGMA_WEAK_REF
# if defined(__GNUC__) && __GNUC__ < 3
# error "Please update to a newer gcc with weak symbol support, or switch to native cc, reconfigure and recompile."
# else
# error "Weak reference support is required"
# endif
# endif
# define USE_PTHREAD_LOCK_ONLY_IF_LOADED
#endif
#if !defined(HAVE_PTHREAD_MUTEX_LOCK) && !defined(USE_PTHREAD_LOCK_ONLY_IF_LOADED)
# define USE_PTHREAD_LOCK_ONLY_IF_LOADED
#endif
#ifdef HAVE_PRAGMA_WEAK_REF
/* Can't rely on useful stubs -- see above regarding Solaris. */
typedef struct {
pthread_once_t o;
k5_os_nothread_once_t n;
} k5_once_t;
# define K5_ONCE_INIT { PTHREAD_ONCE_INIT, K5_OS_NOTHREAD_ONCE_INIT }
# define k5_once(O,F) (K5_PTHREADS_LOADED \
? pthread_once(&(O)->o,F) \
: k5_os_nothread_once(&(O)->n,F))
#else
typedef pthread_once_t k5_once_t;
# define K5_ONCE_INIT PTHREAD_ONCE_INIT
# define k5_once pthread_once
#endif
typedef struct {
pthread_mutex_t p;
#ifdef DEBUG_THREADS
pthread_t owner;
#endif
#ifdef USE_PTHREAD_LOCK_ONLY_IF_LOADED
k5_os_nothread_mutex n;
#endif
} k5_os_mutex;
#ifdef DEBUG_THREADS
# ifdef __GNUC__
# define k5_pthread_mutex_lock(M) \
({ \
k5_os_mutex *_m2 = (M); \
int _r2 = pthread_mutex_lock(&_m2->p); \
if (_r2 == 0) _m2->owner = pthread_self(); \
_r2; \
})
# else
static int
k5_pthread_mutex_lock(k5_os_mutex *m)
{
int r = pthread_mutex_lock(&m->p);
if (r)
return r;
m->owner = pthread_self();
return 0;
}
# endif
# define k5_pthread_assert_locked(M) \
(K5_PTHREADS_LOADED \
? ASSERT(pthread_equal((M)->owner, pthread_self())) \
: (void)0)
# define k5_pthread_mutex_unlock(M) \
(k5_pthread_assert_locked(M), \
(M)->owner = (pthread_t) 0, \
pthread_mutex_unlock(&(M)->p))
#else
# define k5_pthread_mutex_lock(M) pthread_mutex_lock(&(M)->p)
/* LINTED */
static void k5_pthread_assert_locked(k5_os_mutex *m) { }
# define k5_pthread_mutex_unlock(M) pthread_mutex_unlock(&(M)->p)
#endif
/* Define as functions to:
(1) eliminate "statement with no effect" warnings for "0"
(2) encourage type-checking in calling code */
/* LINTED */
static void k5_pthread_assert_unlocked(pthread_mutex_t *m) { }
#if defined(DEBUG_THREADS_SLOW) && HAVE_SCHED_H && (HAVE_SCHED_YIELD || HAVE_PRAGMA_WEAK_REF)
# include <sched.h>
# if !HAVE_SCHED_YIELD
# pragma weak sched_yield
# define MAYBE_SCHED_YIELD() ((void)((&sched_yield != NULL) ? sched_yield() : 0))
# else
# define MAYBE_SCHED_YIELD() ((void)sched_yield())
# endif
#else
# define MAYBE_SCHED_YIELD() ((void)0)
#endif
/* It may not be obvious why this function is desirable.
I want to call pthread_mutex_lock, then sched_yield, then look at
the return code from pthread_mutex_lock. That can't be implemented
in a macro without a temporary variable, or GNU C extensions.
There used to be an inline function which did it, with both
functions called from the inline function. But that messes with
the debug information on a lot of configurations, and you can't
tell where the inline function was called from. (Typically, gdb
gives you the name of the function from which the inline function
was called, and a line number within the inline function itself.)
With this auxiliary function, pthread_mutex_lock can be called at
the invoking site via a macro; once it returns, the inline function
is called (with messed-up line-number info for gdb hopefully
localized to just that call). */
#ifdef __GNUC__
#define return_after_yield(R) \
__extension__ ({ \
int _r = (R); \
MAYBE_SCHED_YIELD(); \
_r; \
})
#else
static int return_after_yield(int r)
{
MAYBE_SCHED_YIELD();
return r;
}
#endif
#ifdef USE_PTHREAD_LOCK_ONLY_IF_LOADED
# if defined(PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP) && defined(DEBUG_THREADS)
# define K5_OS_MUTEX_PARTIAL_INITIALIZER \
{ PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP, (pthread_t) 0, \
K5_OS_NOTHREAD_MUTEX_PARTIAL_INITIALIZER }
# elif defined(DEBUG_THREADS)
# define K5_OS_MUTEX_PARTIAL_INITIALIZER \
{ PTHREAD_MUTEX_INITIALIZER, (pthread_t) 0, \
K5_OS_NOTHREAD_MUTEX_PARTIAL_INITIALIZER }
# else
# define K5_OS_MUTEX_PARTIAL_INITIALIZER \
{ PTHREAD_MUTEX_INITIALIZER, K5_OS_NOTHREAD_MUTEX_PARTIAL_INITIALIZER }
# endif
asdfsdf
# define k5_os_mutex_finish_init(M) \
k5_os_nothread_mutex_finish_init(&(M)->n)
# define k5_os_mutex_init(M) \
(k5_os_nothread_mutex_init(&(M)->n), \
(K5_PTHREADS_LOADED \
? pthread_mutex_init(&(M)->p, 0) \
: 0))
# define k5_os_mutex_destroy(M) \
(k5_os_nothread_mutex_destroy(&(M)->n), \
(K5_PTHREADS_LOADED \
? pthread_mutex_destroy(&(M)->p) \
: 0))
# define k5_os_mutex_lock(M) \
return_after_yield(K5_PTHREADS_LOADED \
? k5_pthread_mutex_lock(M) \
: k5_os_nothread_mutex_lock(&(M)->n))
# define k5_os_mutex_unlock(M) \
(MAYBE_SCHED_YIELD(), \
(K5_PTHREADS_LOADED \
? k5_pthread_mutex_unlock(M) \
: k5_os_nothread_mutex_unlock(&(M)->n)))
# define k5_os_mutex_assert_unlocked(M) \
(K5_PTHREADS_LOADED \
? k5_pthread_assert_unlocked(&(M)->p) \
: k5_os_nothread_mutex_assert_unlocked(&(M)->n))
# define k5_os_mutex_assert_locked(M) \
(K5_PTHREADS_LOADED \
? k5_pthread_assert_locked(M) \
: k5_os_nothread_mutex_assert_locked(&(M)->n))
#else
# ifdef DEBUG_THREADS
# ifdef PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
# define K5_OS_MUTEX_PARTIAL_INITIALIZER \
{ PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP, (pthread_t) 0 }
# else
# define K5_OS_MUTEX_PARTIAL_INITIALIZER \
{ PTHREAD_MUTEX_INITIALIZER, (pthread_t) 0 }
# endif
# else
# define K5_OS_MUTEX_PARTIAL_INITIALIZER \
{ PTHREAD_MUTEX_INITIALIZER }
# endif
/* LINTED */
static int k5_os_mutex_finish_init(k5_os_mutex *m) { return 0; }
# define k5_os_mutex_init(M) pthread_mutex_init(&(M)->p, 0)
# define k5_os_mutex_destroy(M) pthread_mutex_destroy(&(M)->p)
# define k5_os_mutex_lock(M) return_after_yield(k5_pthread_mutex_lock(M))
# define k5_os_mutex_unlock(M) (MAYBE_SCHED_YIELD(),k5_pthread_mutex_unlock(M))
# define k5_os_mutex_assert_unlocked(M) k5_pthread_assert_unlocked(&(M)->p)
# define k5_os_mutex_assert_locked(M) k5_pthread_assert_locked(M)
#endif /* is pthreads always available? */
#elif defined _WIN32
typedef struct {
HANDLE h;
int is_locked;
} k5_os_mutex;
# define K5_OS_MUTEX_PARTIAL_INITIALIZER { INVALID_HANDLE_VALUE, 0 }
# define k5_os_mutex_finish_init(M) \
(ASSERT((M)->h == INVALID_HANDLE_VALUE), \
((M)->h = CreateMutex(NULL, FALSE, NULL)) ? 0 : GetLastError())
# define k5_os_mutex_init(M) \
((M)->is_locked = 0, \
((M)->h = CreateMutex(NULL, FALSE, NULL)) ? 0 : GetLastError())
# define k5_os_mutex_destroy(M) \
(CloseHandle((M)->h) ? ((M)->h = 0, 0) : GetLastError())
static int k5_os_mutex_lock(k5_os_mutex *m)
{
DWORD res;
res = WaitForSingleObject(m->h, INFINITE);
if (res == WAIT_FAILED)
return GetLastError();
/* Eventually these should be turned into some reasonable error
code. */
ASSERT(res != WAIT_TIMEOUT);
ASSERT(res != WAIT_ABANDONED);
ASSERT(res == WAIT_OBJECT_0);
/* Avoid locking twice. */
ASSERT(m->is_locked == 0);
m->is_locked = 1;
return 0;
}
# define k5_os_mutex_unlock(M) \
(ASSERT((M)->is_locked == 1), \
(M)->is_locked = 0, \
ReleaseMutex((M)->h) ? 0 : GetLastError())
# define k5_os_mutex_assert_unlocked(M) ((void)0)
# define k5_os_mutex_assert_locked(M) ((void)0)
#else
# error "Thread support enabled, but thread system unknown"
#endif
typedef struct {
k5_debug_loc loc_last, loc_created;
k5_os_mutex os;
k5_debug_mutex_stats stats;
} k5_mutex_t;
#define K5_MUTEX_PARTIAL_INITIALIZER \
{ K5_DEBUG_LOC_INIT, K5_DEBUG_LOC_INIT, \
K5_OS_MUTEX_PARTIAL_INITIALIZER, K5_MUTEX_STATS_INIT }
/* LINTED */
static int k5_mutex_init_1(k5_mutex_t *m, k5_debug_loc l)
{
int err = k5_os_mutex_init(&m->os);
if (err) return err;
m->loc_created = m->loc_last = l;
err = k5_mutex_init_stats(&m->stats);
ASSERT(err == 0);
return 0;
}
#define k5_mutex_init(M) k5_mutex_init_1((M), K5_DEBUG_LOC)
/* LINTED */
static int k5_mutex_finish_init_1(k5_mutex_t *m, k5_debug_loc l)
{
int err = k5_os_mutex_finish_init(&m->os);
if (err) return err;
m->loc_created = m->loc_last = l;
err = k5_mutex_finish_init_stats(&m->stats);
ASSERT(err == 0);
return 0;
}
#define k5_mutex_finish_init(M) k5_mutex_finish_init_1((M), K5_DEBUG_LOC)
#define k5_mutex_destroy(M) \
(k5_os_mutex_assert_unlocked(&(M)->os), \
k5_mutex_lock(M), (M)->loc_last = K5_DEBUG_LOC, k5_mutex_unlock(M), \
k5_os_mutex_destroy(&(M)->os))
#ifdef __GNUC__
#define k5_mutex_lock(M) \
__extension__ ({ \
int _err = 0; \
k5_mutex_t *_m = (M); \
_err = k5_os_mutex_lock(&_m->os); \
if (_err == 0) _m->loc_last = K5_DEBUG_LOC; \
_err; \
})
#else
/* LINTED */
static int k5_mutex_lock_1(k5_mutex_t *m, k5_debug_loc l)
{
int err = 0;
err = k5_os_mutex_lock(&m->os);
if (err)
return err;
m->loc_last = l;
return err;
}
#define k5_mutex_lock(M) k5_mutex_lock_1(M, K5_DEBUG_LOC)
#endif
#define k5_mutex_unlock(M) \
(k5_mutex_assert_locked(M), \
(M)->loc_last = K5_DEBUG_LOC, \
k5_os_mutex_unlock(&(M)->os))
#define k5_mutex_assert_locked(M) k5_os_mutex_assert_locked(&(M)->os)
#define k5_mutex_assert_unlocked(M) k5_os_mutex_assert_unlocked(&(M)->os)
#define k5_assert_locked k5_mutex_assert_locked
#define k5_assert_unlocked k5_mutex_assert_unlocked
/* Thread-specific data; implemented in a support file, because we'll
need to keep track of some global data for cleanup purposes.
Note that the callback function type is such that the C library
routine free() is a valid callback. */
typedef enum {
K5_KEY_COM_ERR,
K5_KEY_GSS_KRB5_SET_CCACHE_OLD_NAME,
K5_KEY_GSS_KRB5_CCACHE_NAME,
K5_KEY_GSS_KRB5_ERROR_MESSAGE,
K5_KEY_GSS_SPNEGO_ERROR_MESSAGE,
K5_KEY_MAX
} k5_key_t;
/* rename shorthand symbols for export */
#define k5_key_register krb5int_key_register
#define k5_getspecific krb5int_getspecific
#define k5_setspecific krb5int_setspecific
#define k5_key_delete krb5int_key_delete
extern int k5_key_register(k5_key_t, void (*)(void *));
extern void *k5_getspecific(k5_key_t);
extern int k5_setspecific(k5_key_t, void *);
extern int k5_key_delete(k5_key_t);
extern int KRB5_CALLCONV krb5int_mutex_alloc (k5_mutex_t **);
extern void KRB5_CALLCONV krb5int_mutex_free (k5_mutex_t *);
extern int KRB5_CALLCONV krb5int_mutex_lock (k5_mutex_t *);
extern int KRB5_CALLCONV krb5int_mutex_unlock (k5_mutex_t *);
/* In time, many of the definitions above should move into the support
library, and this file should be greatly simplified. For type
definitions, that'll take some work, since other data structures
incorporate mutexes directly, and our mutex type is dependent on
configuration options and system attributes. For most functions,
though, it should be relatively easy.
For now, plugins should use the exported functions, and not the
above macros, and use krb5int_mutex_alloc for allocations. */
#ifdef PLUGIN
#undef k5_mutex_lock
#define k5_mutex_lock krb5int_mutex_lock
#undef k5_mutex_unlock
#define k5_mutex_unlock krb5int_mutex_unlock
#endif
#endif /* _KERNEL */
#endif /* multiple inclusion? */
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* 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 "k5-int.h"
extern const struct krb5_keyhash_provider krb5int_keyhash_descbc;
extern const struct krb5_keyhash_provider krb5int_keyhash_md5des;
extern const struct krb5_keyhash_provider krb5int_keyhash_hmac_md5;
/*
* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
*/
/* This is the prologue to krb5.h */
/* Unfortunately some of these defines are compiler dependent */
#ifndef _KRB5_H
#define _KRB5_H
#define SIZEOF_INT 4
#ifdef _LP64
#define SIZEOF_LONG 8
#else
#define SIZEOF_LONG 4
#endif
#define SIZEOF_SHORT 2
#define HAVE_STDARG_H 1
#define HAVE_SYS_TYPES_H 1
/* End of prologue section */
/*
* include/krb5.h
*
* Copyright 1989,1990,1995,2001, 2003 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.
*
*
* General definitions for Kerberos version 5.
*/
/*
* 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.
*/
#ifndef KRB5_GENERAL__
#define KRB5_GENERAL__
#ifdef _KERNEL
#include <sys/systm.h>
#include <sys/kmem.h>
#include <sys/crypto/common.h>
#include <sys/crypto/api.h>
/*
* Just to be safe lets make sure the buffers are zero'ed after
* malloc() as some code assumes this is the case. To avoid warnings
* of duplicated defines let remove the old one if present.
*/
#ifdef MALLOC
#undef MALLOC
#endif
#define MALLOC(n) kmem_zalloc((n), KM_SLEEP)
#define FREE(x, n) kmem_free((x), (n))
#define CALLOC(n, s) kmem_zalloc((n)*(s), KM_SLEEP)
#define strcpy(dst,src,n) bcopy((src),(dst),(n))
#define mutex_lock(lck) mutex_enter(lck)
#define mutex_unlock(lck) mutex_exit(lck)
#else /* !_KERNEL */
#define MALLOC(n) malloc(n)
#define FREE(x, n) free(x)
#define CALLOC(n, s) calloc((n), (s))
#include <stdlib.h>
#include <thread.h>
#include <synch.h>
#include <security/cryptoki.h>
#include <limits.h> /* for *_MAX */
#endif /* _KERNEL */
/* By default, do not expose deprecated interfaces. */
/* SUNW14resync - we need to enable this for rlogind and such */
#ifndef KRB5_DEPRECATED
#define KRB5_DEPRECATED 1
#endif
/* Do not expose private interfaces. Build system will override. */
/* SUNW14resync - for the Solaris build we set it to 1 here */
#ifndef KRB5_PRIVATE
#define KRB5_PRIVATE 1
#endif
#if defined(__MACH__) && defined(__APPLE__)
# include <TargetConditionals.h>
# if TARGET_RT_MAC_CFM
# error "Use KfM 4.0 SDK headers for CFM compilation."
# endif
#endif
#if defined(_MSDOS) || defined(_WIN32)
#include <win-mac.h>
#endif
#ifndef KRB5_CONFIG__
#ifndef KRB5_CALLCONV
#define KRB5_CALLCONV
#define KRB5_CALLCONV_C
#endif /* !KRB5_CALLCONV */
#endif /* !KRB5_CONFIG__ */
#ifndef KRB5_CALLCONV_WRONG
#define KRB5_CALLCONV_WRONG
#endif
/* SUNW14resync XXX */
#include <sys/types.h>
#include <sys/socket.h>
#ifndef THREEPARAMOPEN
#define THREEPARAMOPEN(x,y,z) open(x,y,z)
#endif
/*
* Solaris Kerberos:
* Samba needs a couple of these interfaces so old crypto is enabled.
*/
#define KRB5_OLD_CRYPTO
#ifndef KRB5INT_BEGIN_DECLS
#if defined(__cplusplus)
#define KRB5INT_BEGIN_DECLS extern "C" {
#define KRB5INT_END_DECLS }
#else
#define KRB5INT_BEGIN_DECLS
#define KRB5INT_END_DECLS
#endif
#endif
KRB5INT_BEGIN_DECLS
#if TARGET_OS_MAC
# pragma options align=mac68k
#endif
/* from profile.h */
struct _profile_t;
/* typedef struct _profile_t *profile_t; */
/*
* begin wordsize.h
*/
/*
* Word-size related definition.
*/
typedef unsigned char krb5_octet;
#if INT_MAX == 0x7fff
typedef int krb5_int16;
typedef unsigned int krb5_ui_2;
#elif SHRT_MAX == 0x7fff
typedef short krb5_int16;
typedef unsigned short krb5_ui_2;
#else
#error undefined 16 bit type
#endif
#if INT_MAX == 0x7fffffffL
typedef int krb5_int32;
typedef unsigned int krb5_ui_4;
#elif LONG_MAX == 0x7fffffffL
typedef long krb5_int32;
typedef unsigned long krb5_ui_4;
#elif SHRT_MAX == 0x7fffffffL
typedef short krb5_int32;
typedef unsigned short krb5_ui_4;
#else
#error: undefined 32 bit type
#endif
#define VALID_INT_BITS INT_MAX
#define VALID_UINT_BITS UINT_MAX
#define KRB5_INT32_MAX 2147483647
/* this strange form is necessary since - is a unary operator, not a sign
indicator */
#define KRB5_INT32_MIN (-KRB5_INT32_MAX-1)
#define KRB5_INT16_MAX 65535
/* this strange form is necessary since - is a unary operator, not a sign
indicator */
#define KRB5_INT16_MIN (-KRB5_INT16_MAX-1)
/*
* end wordsize.h
*/
/*
* begin "base-defs.h"
*/
/*
* Basic definitions for Kerberos V5 library
*/
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
typedef unsigned int krb5_boolean;
typedef unsigned int krb5_msgtype;
typedef unsigned int krb5_kvno;
typedef krb5_int32 krb5_addrtype;
typedef krb5_int32 krb5_enctype;
typedef krb5_int32 krb5_cksumtype;
typedef krb5_int32 krb5_authdatatype;
typedef krb5_int32 krb5_keyusage;
typedef krb5_int32 krb5_preauthtype; /* This may change, later on */
typedef krb5_int32 krb5_flags;
typedef krb5_int32 krb5_timestamp;
typedef krb5_int32 krb5_error_code;
typedef krb5_int32 krb5_deltat;
typedef krb5_error_code krb5_magic;
typedef struct _krb5_data {
krb5_magic magic;
unsigned int length;
char *data;
} krb5_data;
typedef struct _krb5_octet_data {
krb5_magic magic;
unsigned int length;
krb5_octet *data;
} krb5_octet_data;
/*
* Hack length for crypto library to use the afs_string_to_key It is
* equivalent to -1 without possible sign extension
* We also overload for an unset salt type length - which is also -1, but
* hey, why not....
*/
#define SALT_TYPE_AFS_LENGTH UINT_MAX
#define SALT_TYPE_NO_LENGTH UINT_MAX
typedef void * krb5_pointer;
typedef void const * krb5_const_pointer;
typedef struct krb5_principal_data {
krb5_magic magic;
krb5_data realm;
krb5_data *data; /* An array of strings */
krb5_int32 length;
krb5_int32 type;
} krb5_principal_data;
typedef krb5_principal_data * krb5_principal;
/*
* Per V5 spec on definition of principal types
*/
/* Name type not known */
#define KRB5_NT_UNKNOWN 0
/* Just the name of the principal as in DCE, or for users */
#define KRB5_NT_PRINCIPAL 1
/* Service and other unique instance (krbtgt) */
#define KRB5_NT_SRV_INST 2
/* Service with host name as instance (telnet, rcommands) */
#define KRB5_NT_SRV_HST 3
/* Service with host as remaining components */
#define KRB5_NT_SRV_XHST 4
/* Unique ID */
#define KRB5_NT_UID 5
/* PKINIT */
#define KRB5_NT_X500_PRINCIPAL 6
/* Name in form of SMTP email name */
#define KRB5_NT_SMTP_NAME 7
/* Windows 2000 UPN */
#define KRB5_NT_ENTERPRISE_PRINCIPAL 10
/* Windows 2000 UPN and SID */
#define KRB5_NT_MS_PRINCIPAL -128
/* NT 4 style name */
#define KRB5_NT_MS_PRINCIPAL_AND_ID -129
/* NT 4 style name and SID */
#define KRB5_NT_ENT_PRINCIPAL_AND_ID -130
/* constant version thereof: */
typedef const krb5_principal_data *krb5_const_principal;
#define krb5_princ_realm(context, princ) (&(princ)->realm)
#define krb5_princ_set_realm(context, princ,value) ((princ)->realm = *(value))
#define krb5_princ_set_realm_length(context, princ,value) (princ)->realm.length = (value)
#define krb5_princ_set_realm_data(context, princ,value) (princ)->realm.data = (value)
#define krb5_princ_size(context, princ) (princ)->length
#define krb5_princ_type(context, princ) (princ)->type
#define krb5_princ_name(context, princ) (princ)->data
#define krb5_princ_component(context, princ,i) \
(((i) < krb5_princ_size(context, princ)) \
? (princ)->data + (i) \
: NULL)
/*
* Constants for realm referrals.
*/
#define KRB5_REFERRAL_REALM ""
/*
* Referral-specific functions.
*/
krb5_boolean KRB5_CALLCONV krb5_is_referral_realm(const krb5_data *);
/*
* end "base-defs.h"
*/
/*
* begin "hostaddr.h"
*/
/* structure for address */
typedef struct _krb5_address {
krb5_magic magic;
krb5_addrtype addrtype;
unsigned int length;
krb5_octet *contents;
} krb5_address;
/* per Kerberos v5 protocol spec */
#define ADDRTYPE_INET 0x0002
#define ADDRTYPE_CHAOS 0x0005
#define ADDRTYPE_XNS 0x0006
#define ADDRTYPE_ISO 0x0007
#define ADDRTYPE_DDP 0x0010
#define ADDRTYPE_INET6 0x0018
/* not yet in the spec... */
#define ADDRTYPE_ADDRPORT 0x0100
#define ADDRTYPE_IPPORT 0x0101
/* macros to determine if a type is a local type */
#define ADDRTYPE_IS_LOCAL(addrtype) (addrtype & 0x8000)
/*
* end "hostaddr.h"
*/
struct _krb5_context;
typedef struct _krb5_context * krb5_context;
struct _krb5_auth_context;
typedef struct _krb5_auth_context * krb5_auth_context;
struct _krb5_cryptosystem_entry;
/* SUNW EF (I assume) crypto mods ... */
struct _krb5_keyblock;
/*
* keyblocks will contain a list of derived keys,
* this structure will contain the derived key data.
*/
typedef struct _dk_node {
krb5_keyusage usage;
struct _krb5_keyblock *derived_key;
uchar_t dkid; /* derived key identifier byte */
struct _dk_node *next;
} krb5_dk_node;
/*
* begin "encryption.h"
*/
typedef struct _krb5_keyblock {
krb5_magic magic;
krb5_enctype enctype;
unsigned int length;
krb5_octet *contents;
krb5_dk_node *dk_list; /* list of keys derived from this key */
#ifdef _KERNEL
crypto_mech_type_t kef_mt;
crypto_key_t kef_key;
crypto_ctx_template_t key_tmpl;
#else
CK_OBJECT_HANDLE hKey; /* PKCS#11 key object handle */
pid_t pid; /* fork safety */
#endif /* _KERNEL */
} krb5_keyblock;
typedef struct _krb5_checksum {
krb5_magic magic;
krb5_cksumtype checksum_type; /* checksum type */
unsigned int length;
krb5_octet *contents;
} krb5_checksum;
typedef struct _krb5_encrypt_block {
krb5_magic magic;
krb5_enctype crypto_entry; /* to call krb5_encrypt_size, you need
this. it was a pointer, but it
doesn't have to be. gross. */
krb5_keyblock *key;
} krb5_encrypt_block;
typedef struct _krb5_enc_data {
krb5_magic magic;
krb5_enctype enctype;
krb5_kvno kvno;
krb5_data ciphertext;
} krb5_enc_data;
/* per Kerberos v5 protocol spec */
#define ENCTYPE_NULL 0x0000
#define ENCTYPE_DES_CBC_CRC 0x0001 /* DES cbc mode with CRC-32 */
#define ENCTYPE_DES_CBC_MD4 0x0002 /* DES cbc mode with RSA-MD4 */
#define ENCTYPE_DES_CBC_MD5 0x0003 /* DES cbc mode with RSA-MD5 */
#define ENCTYPE_DES_CBC_RAW 0x0004 /* DES cbc mode raw */
/* XXX deprecated? */
#define ENCTYPE_DES3_CBC_SHA 0x0005 /* DES-3 cbc mode with NIST-SHA */
#define ENCTYPE_DES3_CBC_RAW 0x0006 /* DES-3 cbc mode raw */
#define ENCTYPE_DES_HMAC_SHA1 0x0008
#define ENCTYPE_DES3_CBC_SHA1 0x0010
#define ENCTYPE_AES128_CTS_HMAC_SHA1_96 0x0011
#define ENCTYPE_AES256_CTS_HMAC_SHA1_96 0x0012
#define ENCTYPE_ARCFOUR_HMAC 0x0017
#define ENCTYPE_ARCFOUR_HMAC_EXP 0x0018
#define ENCTYPE_UNKNOWN 0x01ff
#define CKSUMTYPE_CRC32 0x0001
#define CKSUMTYPE_RSA_MD4 0x0002
#define CKSUMTYPE_RSA_MD4_DES 0x0003
#define CKSUMTYPE_DESCBC 0x0004
/* des-mac-k */
/* rsa-md4-des-k */
#define CKSUMTYPE_RSA_MD5 0x0007
#define CKSUMTYPE_RSA_MD5_DES 0x0008
#define CKSUMTYPE_NIST_SHA 0x0009
#define CKSUMTYPE_HMAC_SHA1_DES3 0x000c
#define CKSUMTYPE_HMAC_SHA1_96_AES128 0x000f
#define CKSUMTYPE_HMAC_SHA1_96_AES256 0x0010
#define CKSUMTYPE_HMAC_MD5_ARCFOUR -138 /*Microsoft md5 hmac cksumtype*/
/* The following are entropy source designations. Whenever
* krb5_C_random_add_entropy is called, one of these source ids is passed
* in. This allows the library to better estimate bits of
* entropy in the sample and to keep track of what sources of entropy have
* contributed enough entropy. Sources marked internal MUST NOT be
* used by applications outside the Kerberos library
*/
enum {
KRB5_C_RANDSOURCE_OLDAPI = 0, /*calls to krb5_C_RANDOM_SEED (INTERNAL)*/
KRB5_C_RANDSOURCE_OSRAND = 1, /* /dev/random or equivalent (internal)*/
KRB5_C_RANDSOURCE_TRUSTEDPARTY = 2, /* From KDC or other trusted party*/
/*This source should be used carefully; data in this category
* should be from a third party trusted to give random bits
* For example keys issued by the KDC in the application server.
*/
KRB5_C_RANDSOURCE_TIMING = 3, /* Timing of operations*/
KRB5_C_RANDSOURCE_EXTERNAL_PROTOCOL = 4, /*Protocol data possibly from attacker*/
KRB5_C_RANDSOURCE_MAX = 5 /*Do not use; maximum source ID*/
};
#ifndef krb5_roundup
/* round x up to nearest multiple of y */
#define krb5_roundup(x, y) ((((x) + (y) - 1)/(y))*(y))
#endif /* roundup */
/* macro function definitions to help clean up code */
#ifndef _KERNEL
#define krb5_x(ptr,args) ((ptr)?((*(ptr)) args):(abort(),1))
#define krb5_xc(ptr,args) ((ptr)?((*(ptr)) args):(abort(),(char*)0))
#else
#define krb5_x(ptr,args) ((*(ptr)) args)
#define krb5_xc(ptr,args) ((*(ptr)) args)
#endif
krb5_error_code KRB5_CALLCONV
krb5_c_encrypt
(krb5_context context, const krb5_keyblock *key,
krb5_keyusage usage, const krb5_data *cipher_state,
const krb5_data *input, krb5_enc_data *output);
krb5_error_code KRB5_CALLCONV
krb5_c_decrypt
(krb5_context context, const krb5_keyblock *key,
krb5_keyusage usage, const krb5_data *cipher_state,
const krb5_enc_data *input, krb5_data *output);
krb5_error_code KRB5_CALLCONV
krb5_c_encrypt_length
(krb5_context context, krb5_enctype enctype,
size_t inputlen, size_t *length);
krb5_error_code KRB5_CALLCONV
krb5_c_block_size
(krb5_context context, krb5_enctype enctype,
size_t *blocksize);
krb5_error_code KRB5_CALLCONV
krb5_c_keylengths
(krb5_context context, krb5_enctype enctype,
size_t *keybytes, size_t *keylength);
krb5_error_code KRB5_CALLCONV
krb5_c_init_state(krb5_context,
const krb5_keyblock *, krb5_keyusage,
krb5_data *);
krb5_error_code KRB5_CALLCONV
krb5_c_free_state(krb5_context,
const krb5_keyblock *, krb5_data *);
krb5_error_code KRB5_CALLCONV
krb5_c_make_random_key
(krb5_context context, krb5_enctype enctype,
krb5_keyblock *random_key);
krb5_error_code KRB5_CALLCONV
krb5_c_random_to_key
(krb5_context context, krb5_enctype enctype,
krb5_data *random_data, krb5_keyblock *k5_random_key);
/* Register a new entropy sample with the PRNG. may cause
* the PRNG to be reseeded, although this is not guaranteed. See previous randsource definitions
* for information on how each source should be used.
*/
krb5_error_code KRB5_CALLCONV
krb5_c_random_add_entropy
(krb5_context context, unsigned int randsource_id, const krb5_data *data);
krb5_error_code KRB5_CALLCONV
krb5_c_random_make_octets
(krb5_context context, krb5_data *data);
/*
* Collect entropy from the OS if possible. strong requests that as strong
* of a source of entropy as available be used. Setting strong may
* increase the probability of blocking and should not be used for normal
* applications. Good uses include seeding the PRNG for kadmind
* and realm setup.
* If successful is non-null, then successful is set to 1 if the OS provided
* entropy else zero.
*/
#if 0 /* SUNW14resync - not used in Solaris */
krb5_error_code KRB5_CALLCONV
krb5_c_random_os_entropy
(krb5_context context, int strong, int *success);
#endif
/*deprecated*/ krb5_error_code KRB5_CALLCONV
krb5_c_random_seed
(krb5_context context, krb5_data *data);
krb5_error_code KRB5_CALLCONV
krb5_c_string_to_key
(krb5_context context, krb5_enctype enctype,
const krb5_data *string, const krb5_data *salt,
krb5_keyblock *key);
krb5_error_code KRB5_CALLCONV
krb5_c_string_to_key_with_params(krb5_context context,
krb5_enctype enctype,
const krb5_data *string,
const krb5_data *salt,
const krb5_data *params,
krb5_keyblock *key);
krb5_error_code KRB5_CALLCONV
krb5_c_enctype_compare
(krb5_context context, krb5_enctype e1, krb5_enctype e2,
krb5_boolean *similar);
krb5_error_code KRB5_CALLCONV
krb5_c_make_checksum
(krb5_context context, krb5_cksumtype cksumtype,
const krb5_keyblock *key, krb5_keyusage usage,
const krb5_data *input, krb5_checksum *cksum);
krb5_error_code KRB5_CALLCONV
krb5_c_verify_checksum
(krb5_context context,
const krb5_keyblock *key, krb5_keyusage usage,
const krb5_data *data,
const krb5_checksum *cksum,
krb5_boolean *valid);
krb5_error_code KRB5_CALLCONV
krb5_c_checksum_length
(krb5_context context, krb5_cksumtype cksumtype,
size_t *length);
krb5_error_code KRB5_CALLCONV
krb5_c_keyed_checksum_types
(krb5_context context, krb5_enctype enctype,
unsigned int *count, krb5_cksumtype **cksumtypes);
#define KRB5_KEYUSAGE_AS_REQ_PA_ENC_TS 1
#define KRB5_KEYUSAGE_KDC_REP_TICKET 2
#define KRB5_KEYUSAGE_AS_REP_ENCPART 3
#define KRB5_KEYUSAGE_TGS_REQ_AD_SESSKEY 4
#define KRB5_KEYUSAGE_TGS_REQ_AD_SUBKEY 5
#define KRB5_KEYUSAGE_TGS_REQ_AUTH_CKSUM 6
#define KRB5_KEYUSAGE_TGS_REQ_AUTH 7
#define KRB5_KEYUSAGE_TGS_REP_ENCPART_SESSKEY 8
#define KRB5_KEYUSAGE_TGS_REP_ENCPART_SUBKEY 9
#define KRB5_KEYUSAGE_AP_REQ_AUTH_CKSUM 10
#define KRB5_KEYUSAGE_AP_REQ_AUTH 11
#define KRB5_KEYUSAGE_AP_REP_ENCPART 12
#define KRB5_KEYUSAGE_KRB_PRIV_ENCPART 13
#define KRB5_KEYUSAGE_KRB_CRED_ENCPART 14
#define KRB5_KEYUSAGE_KRB_SAFE_CKSUM 15
#define KRB5_KEYUSAGE_APP_DATA_ENCRYPT 16
#define KRB5_KEYUSAGE_APP_DATA_CKSUM 17
#define KRB5_KEYUSAGE_KRB_ERROR_CKSUM 18
#define KRB5_KEYUSAGE_AD_KDCISSUED_CKSUM 19
#define KRB5_KEYUSAGE_AD_MTE 20
#define KRB5_KEYUSAGE_AD_ITE 21
/* XXX need to register these */
#define KRB5_KEYUSAGE_GSS_TOK_MIC 22
#define KRB5_KEYUSAGE_GSS_TOK_WRAP_INTEG 23
#define KRB5_KEYUSAGE_GSS_TOK_WRAP_PRIV 24
/* Defined in hardware preauth draft */
#define KRB5_KEYUSAGE_PA_SAM_CHALLENGE_CKSUM 25
#define KRB5_KEYUSAGE_PA_SAM_CHALLENGE_TRACKID 26
#define KRB5_KEYUSAGE_PA_SAM_RESPONSE 27
/* Defined in KDC referrals draft */
#define KRB5_KEYUSAGE_PA_REFERRAL 26 /* XXX note conflict with above */
krb5_boolean KRB5_CALLCONV krb5_c_valid_enctype
(krb5_enctype ktype);
krb5_boolean KRB5_CALLCONV krb5_c_valid_cksumtype
(krb5_cksumtype ctype);
krb5_boolean KRB5_CALLCONV krb5_c_is_coll_proof_cksum
(krb5_cksumtype ctype);
krb5_boolean KRB5_CALLCONV krb5_c_is_keyed_cksum
(krb5_cksumtype ctype);
#if KRB5_PRIVATE
/* Use the above four instead. */
krb5_boolean KRB5_CALLCONV valid_enctype
(krb5_enctype ktype);
krb5_boolean KRB5_CALLCONV valid_cksumtype
(krb5_cksumtype ctype);
krb5_boolean KRB5_CALLCONV is_coll_proof_cksum
(krb5_cksumtype ctype);
krb5_boolean KRB5_CALLCONV is_keyed_cksum
(krb5_cksumtype ctype);
#endif
#ifdef KRB5_OLD_CRYPTO
/*
* old cryptosystem routine prototypes. These are now layered
* on top of the functions above.
*/
krb5_error_code KRB5_CALLCONV krb5_encrypt
(krb5_context context,
krb5_const_pointer inptr,
krb5_pointer outptr,
size_t size,
krb5_encrypt_block * eblock,
krb5_pointer ivec);
krb5_error_code KRB5_CALLCONV krb5_decrypt
(krb5_context context,
krb5_const_pointer inptr,
krb5_pointer outptr,
size_t size,
krb5_encrypt_block * eblock,
krb5_pointer ivec);
krb5_error_code KRB5_CALLCONV krb5_process_key
(krb5_context context,
krb5_encrypt_block * eblock,
const krb5_keyblock * key);
krb5_error_code KRB5_CALLCONV krb5_finish_key
(krb5_context context,
krb5_encrypt_block * eblock);
krb5_error_code KRB5_CALLCONV krb5_string_to_key
(krb5_context context,
const krb5_encrypt_block * eblock,
krb5_keyblock * keyblock,
const krb5_data * data,
const krb5_data * salt);
krb5_error_code KRB5_CALLCONV krb5_init_random_key
(krb5_context context,
const krb5_encrypt_block * eblock,
const krb5_keyblock * keyblock,
krb5_pointer * ptr);
krb5_error_code KRB5_CALLCONV krb5_finish_random_key
(krb5_context context,
const krb5_encrypt_block * eblock,
krb5_pointer * ptr);
krb5_error_code KRB5_CALLCONV krb5_random_key
(krb5_context context,
const krb5_encrypt_block * eblock,
krb5_pointer ptr,
krb5_keyblock ** keyblock);
krb5_enctype KRB5_CALLCONV krb5_eblock_enctype
(krb5_context context,
const krb5_encrypt_block * eblock);
krb5_error_code KRB5_CALLCONV krb5_use_enctype
(krb5_context context,
krb5_encrypt_block * eblock,
krb5_enctype enctype);
size_t KRB5_CALLCONV krb5_encrypt_size
(size_t length,
krb5_enctype crypto);
size_t KRB5_CALLCONV krb5_checksum_size
(krb5_context context,
krb5_cksumtype ctype);
krb5_error_code KRB5_CALLCONV krb5_calculate_checksum
(krb5_context context,
krb5_cksumtype ctype,
krb5_const_pointer in, size_t in_length,
krb5_const_pointer seed, size_t seed_length,
krb5_checksum * outcksum);
krb5_error_code KRB5_CALLCONV krb5_verify_checksum
(krb5_context context,
krb5_cksumtype ctype,
const krb5_checksum * cksum,
krb5_const_pointer in, size_t in_length,
krb5_const_pointer seed, size_t seed_length);
#if KRB5_PRIVATE
krb5_error_code KRB5_CALLCONV krb5_random_confounder
(size_t, krb5_pointer);
krb5_error_code krb5_encrypt_data
(krb5_context context, krb5_keyblock *key,
krb5_pointer ivec, krb5_data *data,
krb5_enc_data *enc_data);
krb5_error_code krb5_decrypt_data
(krb5_context context, krb5_keyblock *key,
krb5_pointer ivec, krb5_enc_data *data,
krb5_data *enc_data);
#endif
#endif /* KRB5_OLD_CRYPTO */
/*
* end "encryption.h"
*/
/*
* begin "fieldbits.h"
*/
/* kdc_options for kdc_request */
/* options is 32 bits; each host is responsible to put the 4 bytes
representing these bits into net order before transmission */
/* #define KDC_OPT_RESERVED 0x80000000 */
#define KDC_OPT_FORWARDABLE 0x40000000
#define KDC_OPT_FORWARDED 0x20000000
#define KDC_OPT_PROXIABLE 0x10000000
#define KDC_OPT_PROXY 0x08000000
#define KDC_OPT_ALLOW_POSTDATE 0x04000000
#define KDC_OPT_POSTDATED 0x02000000
/* #define KDC_OPT_UNUSED 0x01000000 */
#define KDC_OPT_RENEWABLE 0x00800000
/* #define KDC_OPT_UNUSED 0x00400000 */
/* #define KDC_OPT_RESERVED 0x00200000 */
/* #define KDC_OPT_RESERVED 0x00100000 */
/* #define KDC_OPT_RESERVED 0x00080000 */
/* #define KDC_OPT_RESERVED 0x00040000 */
#define KDC_OPT_REQUEST_ANONYMOUS 0x00020000
#define KDC_OPT_CANONICALIZE 0x00010000
/* #define KDC_OPT_RESERVED 0x00008000 */
/* #define KDC_OPT_RESERVED 0x00004000 */
/* #define KDC_OPT_RESERVED 0x00002000 */
/* #define KDC_OPT_RESERVED 0x00001000 */
/* #define KDC_OPT_RESERVED 0x00000800 */
/* #define KDC_OPT_RESERVED 0x00000400 */
/* #define KDC_OPT_RESERVED 0x00000200 */
/* #define KDC_OPT_RESERVED 0x00000100 */
/* #define KDC_OPT_RESERVED 0x00000080 */
/* #define KDC_OPT_RESERVED 0x00000040 */
#define KDC_OPT_DISABLE_TRANSITED_CHECK 0x00000020
#define KDC_OPT_RENEWABLE_OK 0x00000010
#define KDC_OPT_ENC_TKT_IN_SKEY 0x00000008
/* #define KDC_OPT_UNUSED 0x00000004 */
#define KDC_OPT_RENEW 0x00000002
#define KDC_OPT_VALIDATE 0x00000001
/*
* Mask of ticket flags in the TGT which should be converted into KDC
* options when using the TGT to get derivitive tickets.
*
* New mask = KDC_OPT_FORWARDABLE | KDC_OPT_PROXIABLE |
* KDC_OPT_ALLOW_POSTDATE | KDC_OPT_RENEWABLE
*/
#define KDC_TKT_COMMON_MASK 0x54800000
/* definitions for ap_options fields */
/* ap_options are 32 bits; each host is responsible to put the 4 bytes
representing these bits into net order before transmission */
#define AP_OPTS_RESERVED 0x80000000
#define AP_OPTS_USE_SESSION_KEY 0x40000000
#define AP_OPTS_MUTUAL_REQUIRED 0x20000000
/* #define AP_OPTS_RESERVED 0x10000000 */
/* #define AP_OPTS_RESERVED 0x08000000 */
/* #define AP_OPTS_RESERVED 0x04000000 */
/* #define AP_OPTS_RESERVED 0x02000000 */
/* #define AP_OPTS_RESERVED 0x01000000 */
/* #define AP_OPTS_RESERVED 0x00800000 */
/* #define AP_OPTS_RESERVED 0x00400000 */
/* #define AP_OPTS_RESERVED 0x00200000 */
/* #define AP_OPTS_RESERVED 0x00100000 */
/* #define AP_OPTS_RESERVED 0x00080000 */
/* #define AP_OPTS_RESERVED 0x00040000 */
/* #define AP_OPTS_RESERVED 0x00020000 */
/* #define AP_OPTS_RESERVED 0x00010000 */
/* #define AP_OPTS_RESERVED 0x00008000 */
/* #define AP_OPTS_RESERVED 0x00004000 */
/* #define AP_OPTS_RESERVED 0x00002000 */
/* #define AP_OPTS_RESERVED 0x00001000 */
/* #define AP_OPTS_RESERVED 0x00000800 */
/* #define AP_OPTS_RESERVED 0x00000400 */
/* #define AP_OPTS_RESERVED 0x00000200 */
/* #define AP_OPTS_RESERVED 0x00000100 */
/* #define AP_OPTS_RESERVED 0x00000080 */
/* #define AP_OPTS_RESERVED 0x00000040 */
/* #define AP_OPTS_RESERVED 0x00000020 */
/* #define AP_OPTS_RESERVED 0x00000010 */
/* #define AP_OPTS_RESERVED 0x00000008 */
/* #define AP_OPTS_RESERVED 0x00000004 */
/* #define AP_OPTS_RESERVED 0x00000002 */
#define AP_OPTS_USE_SUBKEY 0x00000001
#define AP_OPTS_WIRE_MASK 0xfffffff0
/* definitions for ad_type fields. */
#define AD_TYPE_RESERVED 0x8000
#define AD_TYPE_EXTERNAL 0x4000
#define AD_TYPE_REGISTERED 0x2000
#define AD_TYPE_FIELD_TYPE_MASK 0x1fff
/* Ticket flags */
/* flags are 32 bits; each host is responsible to put the 4 bytes
representing these bits into net order before transmission */
/* #define TKT_FLG_RESERVED 0x80000000 */
#define TKT_FLG_FORWARDABLE 0x40000000
#define TKT_FLG_FORWARDED 0x20000000
#define TKT_FLG_PROXIABLE 0x10000000
#define TKT_FLG_PROXY 0x08000000
#define TKT_FLG_MAY_POSTDATE 0x04000000
#define TKT_FLG_POSTDATED 0x02000000
#define TKT_FLG_INVALID 0x01000000
#define TKT_FLG_RENEWABLE 0x00800000
#define TKT_FLG_INITIAL 0x00400000
#define TKT_FLG_PRE_AUTH 0x00200000
#define TKT_FLG_HW_AUTH 0x00100000
#define TKT_FLG_TRANSIT_POLICY_CHECKED 0x00080000
#define TKT_FLG_OK_AS_DELEGATE 0x00040000
#define TKT_FLG_ANONYMOUS 0x00020000
/* #define TKT_FLG_RESERVED 0x00010000 */
/* #define TKT_FLG_RESERVED 0x00008000 */
/* #define TKT_FLG_RESERVED 0x00004000 */
/* #define TKT_FLG_RESERVED 0x00002000 */
/* #define TKT_FLG_RESERVED 0x00001000 */
/* #define TKT_FLG_RESERVED 0x00000800 */
/* #define TKT_FLG_RESERVED 0x00000400 */
/* #define TKT_FLG_RESERVED 0x00000200 */
/* #define TKT_FLG_RESERVED 0x00000100 */
/* #define TKT_FLG_RESERVED 0x00000080 */
/* #define TKT_FLG_RESERVED 0x00000040 */
/* #define TKT_FLG_RESERVED 0x00000020 */
/* #define TKT_FLG_RESERVED 0x00000010 */
/* #define TKT_FLG_RESERVED 0x00000008 */
/* #define TKT_FLG_RESERVED 0x00000004 */
/* #define TKT_FLG_RESERVED 0x00000002 */
/* #define TKT_FLG_RESERVED 0x00000001 */
/* definitions for lr_type fields. */
#define LR_TYPE_THIS_SERVER_ONLY 0x8000
#define LR_TYPE_INTERPRETATION_MASK 0x7fff
/* definitions for ad_type fields. */
#define AD_TYPE_EXTERNAL 0x4000
#define AD_TYPE_REGISTERED 0x2000
#define AD_TYPE_FIELD_TYPE_MASK 0x1fff
#define AD_TYPE_INTERNAL_MASK 0x3fff
/* definitions for msec direction bit for KRB_SAFE, KRB_PRIV */
#define MSEC_DIRBIT 0x8000
#define MSEC_VAL_MASK 0x7fff
/*
* end "fieldbits.h"
*/
/*
* begin "proto.h"
*/
/* Protocol version number */
#define KRB5_PVNO 5
/* Message types */
#define KRB5_AS_REQ ((krb5_msgtype)10) /* Req for initial authentication */
#define KRB5_AS_REP ((krb5_msgtype)11) /* Response to KRB_AS_REQ request */
#define KRB5_TGS_REQ ((krb5_msgtype)12) /* TGS request to server */
#define KRB5_TGS_REP ((krb5_msgtype)13) /* Response to KRB_TGS_REQ req */
#define KRB5_AP_REQ ((krb5_msgtype)14) /* application request to server */
#define KRB5_AP_REP ((krb5_msgtype)15) /* Response to KRB_AP_REQ_MUTUAL */
#define KRB5_SAFE ((krb5_msgtype)20) /* Safe application message */
#define KRB5_PRIV ((krb5_msgtype)21) /* Private application message */
#define KRB5_CRED ((krb5_msgtype)22) /* Credential forwarding message */
#define KRB5_ERROR ((krb5_msgtype)30) /* Error response */
/* LastReq types */
#define KRB5_LRQ_NONE 0
#define KRB5_LRQ_ALL_LAST_TGT 1
#define KRB5_LRQ_ONE_LAST_TGT (-1)
#define KRB5_LRQ_ALL_LAST_INITIAL 2
#define KRB5_LRQ_ONE_LAST_INITIAL (-2)
#define KRB5_LRQ_ALL_LAST_TGT_ISSUED 3
#define KRB5_LRQ_ONE_LAST_TGT_ISSUED (-3)
#define KRB5_LRQ_ALL_LAST_RENEWAL 4
#define KRB5_LRQ_ONE_LAST_RENEWAL (-4)
#define KRB5_LRQ_ALL_LAST_REQ 5
#define KRB5_LRQ_ONE_LAST_REQ (-5)
#define KRB5_LRQ_ALL_PW_EXPTIME 6
#define KRB5_LRQ_ONE_PW_EXPTIME (-6)
/* PADATA types */
#define KRB5_PADATA_NONE 0
#define KRB5_PADATA_AP_REQ 1
#define KRB5_PADATA_TGS_REQ KRB5_PADATA_AP_REQ
#define KRB5_PADATA_ENC_TIMESTAMP 2
#define KRB5_PADATA_PW_SALT 3
#if 0 /* Not used */
#define KRB5_PADATA_ENC_ENCKEY 4 /* Key encrypted within itself */
#endif
#define KRB5_PADATA_ENC_UNIX_TIME 5 /* timestamp encrypted in key */
#define KRB5_PADATA_ENC_SANDIA_SECURID 6 /* SecurId passcode */
#define KRB5_PADATA_SESAME 7 /* Sesame project */
#define KRB5_PADATA_OSF_DCE 8 /* OSF DCE */
#define KRB5_CYBERSAFE_SECUREID 9 /* Cybersafe */
#define KRB5_PADATA_AFS3_SALT 10 /* Cygnus */
#define KRB5_PADATA_ETYPE_INFO 11 /* Etype info for preauth */
#define KRB5_PADATA_SAM_CHALLENGE 12 /* draft challenge system */
#define KRB5_PADATA_SAM_RESPONSE 13 /* draft challenge system response */
#define KRB5_PADATA_PK_AS_REQ_OLD 14 /* PKINIT */
#define KRB5_PADATA_PK_AS_REP_OLD 15 /* PKINIT */
#define KRB5_PADATA_PK_AS_REQ 16 /* PKINIT */
#define KRB5_PADATA_PK_AS_REP 17 /* PKINIT */
#define KRB5_PADATA_ETYPE_INFO2 19
#define KRB5_PADATA_REFERRAL 25 /* draft referral system */
#define KRB5_PADATA_SAM_CHALLENGE_2 30 /* draft challenge system, updated */
#define KRB5_PADATA_SAM_RESPONSE_2 31 /* draft challenge system, updated */
#define KRB5_SAM_USE_SAD_AS_KEY 0x80000000
#define KRB5_SAM_SEND_ENCRYPTED_SAD 0x40000000
#define KRB5_SAM_MUST_PK_ENCRYPT_SAD 0x20000000 /* currently must be zero */
/* Reserved for SPX pre-authentication. */
#define KRB5_PADATA_DASS 16
/* Transited encoding types */
#define KRB5_DOMAIN_X500_COMPRESS 1
/* alternate authentication types */
#define KRB5_ALTAUTH_ATT_CHALLENGE_RESPONSE 64
/* authorization data types */
#define KRB5_AUTHDATA_IF_RELEVANT 1
#define KRB5_AUTHDATA_KDC_ISSUED 4
#define KRB5_AUTHDATA_AND_OR 5
#define KRB5_AUTHDATA_MANDATORY_FOR_KDC 8
#define KRB5_AUTHDATA_INITIAL_VERIFIED_CAS 9
#define KRB5_AUTHDATA_OSF_DCE 64
#define KRB5_AUTHDATA_SESAME 65
#define KRB5_AUTHDATA_WIN2K_PAC 128
#define KRB5_AUTHDATA_ETYPE_NEGOTIATION 129 /* RFC 4537 */
#define KRB5_AUTHDATA_FX_ARMOR 71
/* password change constants */
#define KRB5_KPASSWD_SUCCESS 0
#define KRB5_KPASSWD_MALFORMED 1
#define KRB5_KPASSWD_HARDERROR 2
#define KRB5_KPASSWD_AUTHERROR 3
#define KRB5_KPASSWD_SOFTERROR 4
/* These are Microsoft's extensions in RFC 3244, and it looks like
they'll become standardized, possibly with other additions. */
#define KRB5_KPASSWD_ACCESSDENIED 5 /* unused */
#define KRB5_KPASSWD_BAD_VERSION 6
#define KRB5_KPASSWD_INITIAL_FLAG_NEEDED 7 /* unused */
/*
* end "proto.h"
*/
/* Time set */
typedef struct _krb5_ticket_times {
krb5_timestamp authtime; /* XXX ? should ktime in KDC_REP == authtime
in ticket? otherwise client can't get this */
krb5_timestamp starttime; /* optional in ticket, if not present,
use authtime */
krb5_timestamp endtime;
krb5_timestamp renew_till;
} krb5_ticket_times;
/* structure for auth data */
typedef struct _krb5_authdata {
krb5_magic magic;
krb5_authdatatype ad_type;
unsigned int length;
krb5_octet *contents;
} krb5_authdata;
/* structure for transited encoding */
typedef struct _krb5_transited {
krb5_magic magic;
krb5_octet tr_type;
krb5_data tr_contents;
} krb5_transited;
typedef struct _krb5_enc_tkt_part {
krb5_magic magic;
/* to-be-encrypted portion */
krb5_flags flags; /* flags */
krb5_keyblock *session; /* session key: includes enctype */
krb5_principal client; /* client name/realm */
krb5_transited transited; /* list of transited realms */
krb5_ticket_times times; /* auth, start, end, renew_till */
krb5_address **caddrs; /* array of ptrs to addresses */
krb5_authdata **authorization_data; /* auth data */
} krb5_enc_tkt_part;
typedef struct _krb5_ticket {
krb5_magic magic;
/* cleartext portion */
krb5_principal server; /* server name/realm */
krb5_enc_data enc_part; /* encryption type, kvno, encrypted
encoding */
krb5_enc_tkt_part *enc_part2; /* ptr to decrypted version, if
available */
} krb5_ticket;
/* the unencrypted version */
typedef struct _krb5_authenticator {
krb5_magic magic;
krb5_principal client; /* client name/realm */
krb5_checksum *checksum; /* checksum, includes type, optional */
krb5_int32 cusec; /* client usec portion */
krb5_timestamp ctime; /* client sec portion */
krb5_keyblock *subkey; /* true session key, optional */
krb5_ui_4 seq_number; /* sequence #, optional */
krb5_authdata **authorization_data; /* New add by Ari, auth data */
} krb5_authenticator;
typedef struct _krb5_tkt_authent {
krb5_magic magic;
krb5_ticket *ticket;
krb5_authenticator *authenticator;
krb5_flags ap_options;
} krb5_tkt_authent;
/* credentials: Ticket, session key, etc. */
typedef struct _krb5_creds {
krb5_magic magic;
krb5_principal client; /* client's principal identifier */
krb5_principal server; /* server's principal identifier */
krb5_keyblock keyblock; /* session encryption key info */
krb5_ticket_times times; /* lifetime info */
krb5_boolean is_skey; /* true if ticket is encrypted in
another ticket's skey */
krb5_flags ticket_flags; /* flags in ticket */
krb5_address * *addresses; /* addrs in ticket */
krb5_data ticket; /* ticket string itself */
krb5_data second_ticket; /* second ticket, if related to
ticket (via DUPLICATE-SKEY or
ENC-TKT-IN-SKEY) */
krb5_authdata **authdata; /* authorization data */
} krb5_creds;
/* Last request fields */
typedef struct _krb5_last_req_entry {
krb5_magic magic;
krb5_int32 lr_type;
krb5_timestamp value;
} krb5_last_req_entry;
/* pre-authentication data */
typedef struct _krb5_pa_data {
krb5_magic magic;
krb5_preauthtype pa_type;
unsigned int length;
krb5_octet *contents;
} krb5_pa_data;
typedef struct _krb5_kdc_req {
krb5_magic magic;
krb5_msgtype msg_type; /* AS_REQ or TGS_REQ? */
krb5_pa_data **padata; /* e.g. encoded AP_REQ */
/* real body */
krb5_flags kdc_options; /* requested options */
krb5_principal client; /* includes realm; optional */
krb5_principal server; /* includes realm (only used if no
client) */
krb5_timestamp from; /* requested starttime */
krb5_timestamp till; /* requested endtime */
krb5_timestamp rtime; /* (optional) requested renew_till */
krb5_int32 nonce; /* nonce to match request/response */
int nktypes; /* # of ktypes, must be positive */
krb5_enctype *ktype; /* requested enctype(s) */
krb5_address **addresses; /* requested addresses, optional */
krb5_enc_data authorization_data; /* encrypted auth data; OPTIONAL */
krb5_authdata **unenc_authdata; /* unencrypted auth data,
if available */
krb5_ticket **second_ticket;/* second ticket array; OPTIONAL */
} krb5_kdc_req;
typedef struct _krb5_enc_kdc_rep_part {
krb5_magic magic;
/* encrypted part: */
krb5_msgtype msg_type; /* krb5 message type */
krb5_keyblock *session; /* session key */
krb5_last_req_entry **last_req; /* array of ptrs to entries */
krb5_int32 nonce; /* nonce from request */
krb5_timestamp key_exp; /* expiration date */
krb5_flags flags; /* ticket flags */
krb5_ticket_times times; /* lifetime info */
krb5_principal server; /* server's principal identifier */
krb5_address **caddrs; /* array of ptrs to addresses,
optional */
krb5_pa_data **enc_padata; /* Windows 2000 compat */
} krb5_enc_kdc_rep_part;
typedef struct _krb5_kdc_rep {
krb5_magic magic;
/* cleartext part: */
krb5_msgtype msg_type; /* AS_REP or KDC_REP? */
krb5_pa_data **padata; /* preauthentication data from KDC */
krb5_principal client; /* client's principal identifier */
krb5_ticket *ticket; /* ticket */
krb5_enc_data enc_part; /* encryption type, kvno, encrypted
encoding */
krb5_enc_kdc_rep_part *enc_part2;/* unencrypted version, if available */
} krb5_kdc_rep;
/* error message structure */
typedef struct _krb5_error {
krb5_magic magic;
/* some of these may be meaningless in certain contexts */
krb5_timestamp ctime; /* client sec portion; optional */
krb5_int32 cusec; /* client usec portion; optional */
krb5_int32 susec; /* server usec portion */
krb5_timestamp stime; /* server sec portion */
krb5_ui_4 error; /* error code (protocol error #'s) */
krb5_principal client; /* client's principal identifier;
optional */
krb5_principal server; /* server's principal identifier */
krb5_data text; /* descriptive text */
krb5_data e_data; /* additional error-describing data */
} krb5_error;
typedef struct _krb5_ap_req {
krb5_magic magic;
krb5_flags ap_options; /* requested options */
krb5_ticket *ticket; /* ticket */
krb5_enc_data authenticator; /* authenticator (already encrypted) */
} krb5_ap_req;
typedef struct _krb5_ap_rep {
krb5_magic magic;
krb5_enc_data enc_part;
} krb5_ap_rep;
typedef struct _krb5_ap_rep_enc_part {
krb5_magic magic;
krb5_timestamp ctime; /* client time, seconds portion */
krb5_int32 cusec; /* client time, microseconds portion */
krb5_keyblock *subkey; /* true session key, optional */
krb5_ui_4 seq_number; /* sequence #, optional */
} krb5_ap_rep_enc_part;
typedef struct _krb5_response {
krb5_magic magic;
krb5_octet message_type;
krb5_data response;
krb5_int32 expected_nonce; /* The expected nonce for KDC_REP messages */
krb5_timestamp request_time; /* When we made the request */
} krb5_response;
typedef struct _krb5_cred_info {
krb5_magic magic;
krb5_keyblock *session; /* session key used to encrypt */
/* ticket */
krb5_principal client; /* client name/realm, optional */
krb5_principal server; /* server name/realm, optional */
krb5_flags flags; /* ticket flags, optional */
krb5_ticket_times times; /* auth, start, end, renew_till, */
/* optional */
krb5_address **caddrs; /* array of ptrs to addresses */
} krb5_cred_info;
typedef struct _krb5_cred_enc_part {
krb5_magic magic;
krb5_int32 nonce; /* nonce, optional */
krb5_timestamp timestamp; /* client time */
krb5_int32 usec; /* microsecond portion of time */
krb5_address *s_address; /* sender address, optional */
krb5_address *r_address; /* recipient address, optional */
krb5_cred_info **ticket_info;
} krb5_cred_enc_part;
typedef struct _krb5_cred {
krb5_magic magic;
krb5_ticket **tickets; /* tickets */
krb5_enc_data enc_part; /* encrypted part */
krb5_cred_enc_part *enc_part2; /* unencrypted version, if available*/
} krb5_cred;
/* Sandia password generation structures */
typedef struct _passwd_phrase_element {
krb5_magic magic;
krb5_data *passwd;
krb5_data *phrase;
} passwd_phrase_element;
typedef struct _krb5_pwd_data {
krb5_magic magic;
int sequence_count;
passwd_phrase_element **element;
} krb5_pwd_data;
/* these need to be here so the typedefs are available for the prototypes */
typedef struct _krb5_pa_svr_referral_data {
/* Referred name, only realm is required */
krb5_principal principal;
} krb5_pa_svr_referral_data;
typedef struct _krb5_pa_server_referral_data {
krb5_data *referred_realm;
krb5_principal true_principal_name;
krb5_principal requested_principal_name;
krb5_timestamp referral_valid_until;
krb5_checksum rep_cksum;
} krb5_pa_server_referral_data;
typedef struct _krb5_pa_pac_req {
/* TRUE if a PAC should be included in TGS-REP */
krb5_boolean include_pac;
} krb5_pa_pac_req;
/*
* begin "safepriv.h"
*/
#define KRB5_AUTH_CONTEXT_DO_TIME 0x00000001
#define KRB5_AUTH_CONTEXT_RET_TIME 0x00000002
#define KRB5_AUTH_CONTEXT_DO_SEQUENCE 0x00000004
#define KRB5_AUTH_CONTEXT_RET_SEQUENCE 0x00000008
#define KRB5_AUTH_CONTEXT_PERMIT_ALL 0x00000010
#define KRB5_AUTH_CONTEXT_USE_SUBKEY 0x00000020
typedef struct krb5_replay_data {
krb5_timestamp timestamp;
krb5_int32 usec;
krb5_int32 seq;
} krb5_replay_data;
/* flags for krb5_auth_con_genaddrs() */
#define KRB5_AUTH_CONTEXT_GENERATE_LOCAL_ADDR 0x00000001
#define KRB5_AUTH_CONTEXT_GENERATE_REMOTE_ADDR 0x00000002
#define KRB5_AUTH_CONTEXT_GENERATE_LOCAL_FULL_ADDR 0x00000004
#define KRB5_AUTH_CONTEXT_GENERATE_REMOTE_FULL_ADDR 0x00000008
/* type of function used as a callback to generate checksum data for
* mk_req */
typedef krb5_error_code
(KRB5_CALLCONV * krb5_mk_req_checksum_func) (krb5_context, krb5_auth_context , void *,
krb5_data **);
/*
* end "safepriv.h"
*/
/*
* begin "ccache.h"
*/
typedef krb5_pointer krb5_cc_cursor; /* cursor for sequential lookup */
struct _krb5_ccache;
typedef struct _krb5_ccache *krb5_ccache;
struct _krb5_cc_ops;
typedef struct _krb5_cc_ops krb5_cc_ops;
/* for retrieve_cred */
#define KRB5_TC_MATCH_TIMES 0x00000001
#define KRB5_TC_MATCH_IS_SKEY 0x00000002
#define KRB5_TC_MATCH_FLAGS 0x00000004
#define KRB5_TC_MATCH_TIMES_EXACT 0x00000008
#define KRB5_TC_MATCH_FLAGS_EXACT 0x00000010
#define KRB5_TC_MATCH_AUTHDATA 0x00000020
#define KRB5_TC_MATCH_SRV_NAMEONLY 0x00000040
#define KRB5_TC_MATCH_2ND_TKT 0x00000080
#define KRB5_TC_MATCH_KTYPE 0x00000100
#define KRB5_TC_SUPPORTED_KTYPES 0x00000200
/* for set_flags and other functions */
#define KRB5_TC_OPENCLOSE 0x00000001
#define KRB5_TC_NOTICKET 0x00000002
krb5_error_code KRB5_CALLCONV
krb5_cc_gen_new (krb5_context context, krb5_ccache *cache);
krb5_error_code KRB5_CALLCONV
krb5_cc_initialize(krb5_context context, krb5_ccache cache,
krb5_principal principal);
krb5_error_code KRB5_CALLCONV
krb5_cc_destroy (krb5_context context, krb5_ccache cache);
krb5_error_code KRB5_CALLCONV
krb5_cc_close (krb5_context context, krb5_ccache cache);
krb5_error_code KRB5_CALLCONV
krb5_cc_store_cred (krb5_context context, krb5_ccache cache,
krb5_creds *creds);
krb5_error_code KRB5_CALLCONV
krb5_cc_retrieve_cred (krb5_context context, krb5_ccache cache,
krb5_flags flags, krb5_creds *mcreds,
krb5_creds *creds);
krb5_error_code KRB5_CALLCONV
krb5_cc_get_principal (krb5_context context, krb5_ccache cache,
krb5_principal *principal);
krb5_error_code KRB5_CALLCONV
krb5_cc_start_seq_get (krb5_context context, krb5_ccache cache,
krb5_cc_cursor *cursor);
krb5_error_code KRB5_CALLCONV
krb5_cc_next_cred (krb5_context context, krb5_ccache cache,
krb5_cc_cursor *cursor, krb5_creds *creds);
krb5_error_code KRB5_CALLCONV
krb5_cc_end_seq_get (krb5_context context, krb5_ccache cache,
krb5_cc_cursor *cursor);
krb5_error_code KRB5_CALLCONV
krb5_cc_remove_cred (krb5_context context, krb5_ccache cache, krb5_flags flags,
krb5_creds *creds);
krb5_error_code KRB5_CALLCONV
krb5_cc_set_flags (krb5_context context, krb5_ccache cache, krb5_flags flags);
krb5_error_code KRB5_CALLCONV
krb5_cc_get_flags (krb5_context context, krb5_ccache cache, krb5_flags *flags);
const char * KRB5_CALLCONV
krb5_cc_get_type (krb5_context context, krb5_ccache cache);
/* SUNW14resync - add_cred.c needs this func */
const char * KRB5_CALLCONV
krb5_cc_get_name (krb5_context context, krb5_ccache cache);
krb5_error_code KRB5_CALLCONV
krb5_cc_new_unique(
krb5_context context,
const char *type,
const char *hint,
krb5_ccache *id);
/*
* end "ccache.h"
*/
/*
* begin "rcache.h"
*/
struct krb5_rc_st;
typedef struct krb5_rc_st *krb5_rcache;
/*
* end "rcache.h"
*/
/*
* begin "keytab.h"
*/
/* XXX */
#define MAX_KEYTAB_NAME_LEN 1100 /* Long enough for MAXPATHLEN + some extra */
typedef krb5_pointer krb5_kt_cursor; /* XXX */
typedef struct krb5_keytab_entry_st {
krb5_magic magic;
krb5_principal principal; /* principal of this key */
krb5_timestamp timestamp; /* time entry written to keytable */
krb5_kvno vno; /* key version number */
krb5_keyblock key; /* the secret key */
} krb5_keytab_entry;
#if KRB5_PRIVATE
struct _krb5_kt_ops;
typedef struct _krb5_kt { /* should move into k5-int.h */
krb5_magic magic;
const struct _krb5_kt_ops *ops;
krb5_pointer data;
} *krb5_keytab;
#else
struct _krb5_kt;
typedef struct _krb5_kt *krb5_keytab;
#endif
char * KRB5_CALLCONV
krb5_kt_get_type (krb5_context, krb5_keytab keytab);
krb5_error_code KRB5_CALLCONV
krb5_kt_get_name(krb5_context context, krb5_keytab keytab, char *name,
unsigned int namelen);
krb5_error_code KRB5_CALLCONV
krb5_kt_close(krb5_context context, krb5_keytab keytab);
krb5_error_code KRB5_CALLCONV
krb5_kt_get_entry(krb5_context context, krb5_keytab keytab,
krb5_const_principal principal, krb5_kvno vno,
krb5_enctype enctype, krb5_keytab_entry *entry);
krb5_error_code KRB5_CALLCONV
krb5_kt_start_seq_get(krb5_context context, krb5_keytab keytab,
krb5_kt_cursor *cursor);
krb5_error_code KRB5_CALLCONV
krb5_kt_next_entry(krb5_context context, krb5_keytab keytab,
krb5_keytab_entry *entry, krb5_kt_cursor *cursor);
krb5_error_code KRB5_CALLCONV
krb5_kt_end_seq_get(krb5_context context, krb5_keytab keytab,
krb5_kt_cursor *cursor);
/* Solaris Kerberos */
krb5_error_code
krb5_kt_find_realm(krb5_context context, krb5_keytab keytab,
krb5_principal princ, krb5_data *realm);
/*
* end "keytab.h"
*/
/*
* begin "func-proto.h"
*/
/* Solaris Kerberos */
krb5_error_code krb5_init_ef_handle(krb5_context);
krb5_error_code krb5_free_ef_handle(krb5_context);
krb5_boolean krb5_privacy_allowed(void);
/*
* Solaris Kerberos:
* krb5_copy_keyblock_data is a new routine to hide the details
* of a keyblock copy operation.
*/
krb5_error_code KRB5_CALLCONV krb5_copy_keyblock_data
(krb5_context,
const krb5_keyblock *,
krb5_keyblock *);
krb5_error_code KRB5_CALLCONV krb5_init_context
(krb5_context *);
krb5_error_code KRB5_CALLCONV krb5_init_secure_context
(krb5_context *);
void KRB5_CALLCONV krb5_free_context
(krb5_context);
#if KRB5_PRIVATE
krb5_error_code krb5_set_default_in_tkt_ktypes
(krb5_context,
const krb5_enctype *);
krb5_error_code krb5_get_default_in_tkt_ktypes
(krb5_context,
krb5_enctype **);
krb5_error_code krb5_set_default_tgs_ktypes
(krb5_context,
const krb5_enctype *);
#endif
krb5_error_code KRB5_CALLCONV
krb5_set_default_tgs_enctypes
(krb5_context,
const krb5_enctype *);
#if KRB5_PRIVATE
krb5_error_code KRB5_CALLCONV krb5_get_tgs_ktypes
(krb5_context,
krb5_const_principal,
krb5_enctype **);
#endif
krb5_error_code KRB5_CALLCONV krb5_get_permitted_enctypes
(krb5_context, krb5_enctype **);
#if KRB5_PRIVATE
void KRB5_CALLCONV krb5_free_ktypes
(krb5_context, krb5_enctype *);
krb5_boolean krb5_is_permitted_enctype
(krb5_context, krb5_enctype);
#endif
krb5_boolean KRB5_CALLCONV krb5_is_thread_safe(void);
/* libkrb.spec */
#if KRB5_PRIVATE
krb5_error_code krb5_kdc_rep_decrypt_proc
(krb5_context,
const krb5_keyblock *,
krb5_const_pointer,
krb5_kdc_rep * );
krb5_error_code KRB5_CALLCONV krb5_decrypt_tkt_part
(krb5_context,
const krb5_keyblock *,
krb5_ticket * );
krb5_error_code krb5_get_cred_from_kdc
(krb5_context,
krb5_ccache, /* not const, as reading may save
state */
krb5_creds *,
krb5_creds **,
krb5_creds *** );
krb5_error_code krb5_get_cred_from_kdc_validate
(krb5_context,
krb5_ccache, /* not const, as reading may save
state */
krb5_creds *,
krb5_creds **,
krb5_creds *** );
krb5_error_code krb5_get_cred_from_kdc_renew
(krb5_context,
krb5_ccache, /* not const, as reading may save
state */
krb5_creds *,
krb5_creds **,
krb5_creds *** );
#endif
void KRB5_CALLCONV krb5_free_tgt_creds
(krb5_context,
krb5_creds **); /* XXX too hard to do with const */
#define KRB5_GC_USER_USER 1 /* want user-user ticket */
#define KRB5_GC_CACHED 2 /* want cached ticket only */
krb5_error_code KRB5_CALLCONV krb5_get_credentials
(krb5_context,
krb5_flags,
krb5_ccache,
krb5_creds *,
krb5_creds **);
krb5_error_code KRB5_CALLCONV krb5_get_credentials_validate
(krb5_context,
krb5_flags,
krb5_ccache,
krb5_creds *,
krb5_creds **);
krb5_error_code KRB5_CALLCONV krb5_get_credentials_renew
(krb5_context,
krb5_flags,
krb5_ccache,
krb5_creds *,
krb5_creds **);
#if KRB5_PRIVATE
krb5_error_code krb5_get_cred_via_tkt
(krb5_context,
krb5_creds *,
krb5_flags,
krb5_address * const *,
krb5_creds *,
krb5_creds **);
#endif
krb5_error_code KRB5_CALLCONV krb5_mk_req
(krb5_context,
krb5_auth_context *,
krb5_flags,
char *,
char *,
krb5_data *,
krb5_ccache,
krb5_data * );
krb5_error_code KRB5_CALLCONV krb5_mk_req_extended
(krb5_context,
krb5_auth_context *,
krb5_flags,
krb5_data *,
krb5_creds *,
krb5_data * );
krb5_error_code KRB5_CALLCONV krb5_mk_rep
(krb5_context,
krb5_auth_context,
krb5_data *);
krb5_error_code KRB5_CALLCONV krb5_rd_rep
(krb5_context,
krb5_auth_context,
const krb5_data *,
krb5_ap_rep_enc_part **);
krb5_error_code KRB5_CALLCONV krb5_mk_error
(krb5_context,
const krb5_error *,
krb5_data * );
krb5_error_code KRB5_CALLCONV krb5_rd_error
(krb5_context,
const krb5_data *,
krb5_error ** );
krb5_error_code KRB5_CALLCONV krb5_rd_safe
(krb5_context,
krb5_auth_context,
const krb5_data *,
krb5_data *,
krb5_replay_data *);
krb5_error_code KRB5_CALLCONV krb5_rd_priv
(krb5_context,
krb5_auth_context,
const krb5_data *,
krb5_data *,
krb5_replay_data *);
krb5_error_code KRB5_CALLCONV krb5_parse_name
(krb5_context,
const char *,
krb5_principal * );
#define KRB5_PRINCIPAL_PARSE_NO_REALM 0x1
#define KRB5_PRINCIPAL_PARSE_REQUIRE_REALM 0x2
#define KRB5_PRINCIPAL_PARSE_ENTERPRISE 0x4
krb5_error_code KRB5_CALLCONV krb5_parse_name_flags
(krb5_context,
const char *,
int,
krb5_principal * );
krb5_error_code KRB5_CALLCONV krb5_unparse_name
(krb5_context,
krb5_const_principal,
char ** );
krb5_error_code KRB5_CALLCONV krb5_unparse_name_ext
(krb5_context,
krb5_const_principal,
char **,
unsigned int *);
#define KRB5_PRINCIPAL_UNPARSE_SHORT 0x1
#define KRB5_PRINCIPAL_UNPARSE_NO_REALM 0x2
#define KRB5_PRINCIPAL_UNPARSE_DISPLAY 0x4
krb5_error_code KRB5_CALLCONV krb5_unparse_name_flags
(krb5_context,
krb5_const_principal,
int,
char **);
krb5_error_code KRB5_CALLCONV krb5_unparse_name_flags_ext
(krb5_context,
krb5_const_principal,
int,
char **,
unsigned int *);
krb5_error_code KRB5_CALLCONV krb5_set_principal_realm
(krb5_context, krb5_principal, const char *);
krb5_boolean KRB5_CALLCONV_WRONG krb5_address_search
(krb5_context,
const krb5_address *,
krb5_address * const *);
krb5_boolean KRB5_CALLCONV krb5_address_compare
(krb5_context,
const krb5_address *,
const krb5_address *);
int KRB5_CALLCONV krb5_address_order
(krb5_context,
const krb5_address *,
const krb5_address *);
krb5_boolean KRB5_CALLCONV krb5_realm_compare
(krb5_context,
krb5_const_principal,
krb5_const_principal);
krb5_boolean KRB5_CALLCONV krb5_principal_compare
(krb5_context,
krb5_const_principal,
krb5_const_principal);
krb5_error_code KRB5_CALLCONV krb5_init_keyblock
(krb5_context, krb5_enctype enctype,
size_t length, krb5_keyblock **out);
/* Initialize a new keyblock and allocate storage
* for the contents of the key, which will be freed along
* with the keyblock when krb5_free_keyblock is called.
* It is legal to pass in a length of 0, in which
* case contents are left unallocated.
*/
/*
* Solaris Kerberos
* Start - keyblock API (MIT will ship this also in a future release)
*/
/*
* Similiar to krb5_init_keyblock but this routine expects the
* keyblock to already be allocated.
*/
krb5_error_code KRB5_CALLCONV krb5_init_allocated_keyblock
(krb5_context,
krb5_enctype,
unsigned int,
krb5_keyblock *);
krb5_enctype KRB5_CALLCONV krb5_get_key_enctype
(krb5_keyblock *);
unsigned int KRB5_CALLCONV krb5_get_key_length
(krb5_keyblock *);
krb5_octet KRB5_CALLCONV *krb5_get_key_data
(krb5_keyblock *);
void KRB5_CALLCONV krb5_set_key_enctype
(krb5_keyblock *,
krb5_enctype);
void KRB5_CALLCONV krb5_set_key_data
(krb5_keyblock *,
krb5_octet *);
void KRB5_CALLCONV krb5_set_key_length
(krb5_keyblock *,
unsigned int);
/*
* Solaris Kerberos
* End - keyblock API
*/
krb5_error_code KRB5_CALLCONV krb5_copy_keyblock
(krb5_context,
const krb5_keyblock *,
krb5_keyblock **);
krb5_error_code KRB5_CALLCONV krb5_copy_keyblock_contents
(krb5_context,
const krb5_keyblock *,
krb5_keyblock *);
krb5_error_code KRB5_CALLCONV krb5_copy_creds
(krb5_context,
const krb5_creds *,
krb5_creds **);
krb5_error_code KRB5_CALLCONV krb5_copy_data
(krb5_context,
const krb5_data *,
krb5_data **);
krb5_error_code KRB5_CALLCONV krb5_copy_principal
(krb5_context,
krb5_const_principal,
krb5_principal *);
#if KRB5_PRIVATE
krb5_error_code KRB5_CALLCONV krb5_copy_addr
(krb5_context,
const krb5_address *,
krb5_address **);
#endif
krb5_error_code KRB5_CALLCONV krb5_copy_addresses
(krb5_context,
krb5_address * const *,
krb5_address ***);
krb5_error_code KRB5_CALLCONV krb5_copy_ticket
(krb5_context,
const krb5_ticket *,
krb5_ticket **);
krb5_error_code KRB5_CALLCONV krb5_copy_authdata
(krb5_context,
krb5_authdata * const *,
krb5_authdata ***);
krb5_error_code KRB5_CALLCONV krb5_merge_authdata
(krb5_context,
krb5_authdata * const *,
krb5_authdata *const *,
krb5_authdata ***);
/* Merge two authdata arrays, such as the array from a ticket
* and authenticator */
krb5_error_code KRB5_CALLCONV krb5_copy_authenticator
(krb5_context,
const krb5_authenticator *,
krb5_authenticator **);
krb5_error_code KRB5_CALLCONV krb5_copy_checksum
(krb5_context,
const krb5_checksum *,
krb5_checksum **);
#if KRB5_PRIVATE
void krb5_init_ets
(krb5_context);
void krb5_free_ets
(krb5_context);
krb5_error_code krb5_generate_subkey
(krb5_context,
const krb5_keyblock *, krb5_keyblock **);
krb5_error_code krb5_generate_seq_number
(krb5_context,
const krb5_keyblock *, krb5_ui_4 *);
#endif
krb5_error_code KRB5_CALLCONV krb5_get_server_rcache
(krb5_context,
const krb5_data *, krb5_rcache *);
krb5_error_code KRB5_CALLCONV_C krb5_build_principal_ext
(krb5_context, krb5_principal *, unsigned int, const char *, ...);
krb5_error_code KRB5_CALLCONV_C krb5_build_principal
(krb5_context, krb5_principal *, unsigned int, const char *, ...);
#ifdef va_start
/* XXX depending on varargs include file defining va_start... */
krb5_error_code KRB5_CALLCONV krb5_build_principal_va
(krb5_context,
krb5_principal, unsigned int, const char *, va_list);
#endif
krb5_error_code KRB5_CALLCONV krb5_425_conv_principal
(krb5_context,
const char *name,
const char *instance, const char *realm,
krb5_principal *princ);
krb5_error_code KRB5_CALLCONV krb5_524_conv_principal
(krb5_context context, krb5_const_principal princ,
char *name, char *inst, char *realm);
struct credentials;
int KRB5_CALLCONV krb5_524_convert_creds
(krb5_context context, krb5_creds *v5creds,
struct credentials *v4creds);
#if KRB5_DEPRECATED
#define krb524_convert_creds_kdc krb5_524_convert_creds
#define krb524_init_ets(x) (0)
#endif
/* libkt.spec */
#if KRB5_PRIVATE
krb5_error_code KRB5_CALLCONV krb5_kt_register
(krb5_context,
const struct _krb5_kt_ops * );
#endif
krb5_error_code KRB5_CALLCONV krb5_kt_resolve
(krb5_context,
const char *,
krb5_keytab * );
krb5_error_code KRB5_CALLCONV krb5_kt_default_name
(krb5_context,
char *,
int );
krb5_error_code KRB5_CALLCONV krb5_kt_default
(krb5_context,
krb5_keytab * );
krb5_error_code KRB5_CALLCONV krb5_free_keytab_entry_contents
(krb5_context,
krb5_keytab_entry * );
#if KRB5_PRIVATE
/* use krb5_free_keytab_entry_contents instead */
krb5_error_code KRB5_CALLCONV krb5_kt_free_entry
(krb5_context,
krb5_keytab_entry * );
#endif
/* remove and add are functions, so that they can return NOWRITE
if not a writable keytab */
krb5_error_code KRB5_CALLCONV krb5_kt_remove_entry
(krb5_context,
krb5_keytab,
krb5_keytab_entry * );
krb5_error_code KRB5_CALLCONV krb5_kt_add_entry
(krb5_context,
krb5_keytab,
krb5_keytab_entry * );
krb5_error_code KRB5_CALLCONV_WRONG krb5_principal2salt
(krb5_context,
krb5_const_principal, krb5_data *);
#if KRB5_PRIVATE
krb5_error_code krb5_principal2salt_norealm
(krb5_context,
krb5_const_principal, krb5_data *);
#endif
/* librc.spec--see rcache.h */
/* libcc.spec */
krb5_error_code KRB5_CALLCONV krb5_cc_resolve
(krb5_context,
const char *,
krb5_ccache * );
const char * KRB5_CALLCONV krb5_cc_default_name
(krb5_context);
krb5_error_code KRB5_CALLCONV krb5_cc_set_default_name
(krb5_context, const char *);
krb5_error_code KRB5_CALLCONV krb5_cc_default
(krb5_context,
krb5_ccache *);
#if KRB5_PRIVATE
unsigned int KRB5_CALLCONV krb5_get_notification_message
(void);
#endif
krb5_error_code KRB5_CALLCONV krb5_cc_copy_creds
(krb5_context context,
krb5_ccache incc,
krb5_ccache outcc);
/* chk_trans.c */
#if KRB5_PRIVATE
krb5_error_code krb5_check_transited_list
(krb5_context, const krb5_data *trans,
const krb5_data *realm1, const krb5_data *realm2);
#endif
/* free_rtree.c */
#if KRB5_PRIVATE
void krb5_free_realm_tree
(krb5_context,
krb5_principal *);
#endif
/* krb5_free.c */
void KRB5_CALLCONV krb5_free_principal
(krb5_context, krb5_principal );
void KRB5_CALLCONV krb5_free_authenticator
(krb5_context, krb5_authenticator * );
#if KRB5_PRIVATE
void KRB5_CALLCONV krb5_free_authenticator_contents
(krb5_context, krb5_authenticator * );
#endif
void KRB5_CALLCONV krb5_free_addresses
(krb5_context, krb5_address ** );
#if KRB5_PRIVATE
void KRB5_CALLCONV krb5_free_address
(krb5_context, krb5_address * );
#endif
void KRB5_CALLCONV krb5_free_authdata
(krb5_context, krb5_authdata ** );
#if KRB5_PRIVATE
void KRB5_CALLCONV krb5_free_enc_tkt_part
(krb5_context, krb5_enc_tkt_part * );
#endif
void KRB5_CALLCONV krb5_free_ticket
(krb5_context, krb5_ticket * );
#if KRB5_PRIVATE
void KRB5_CALLCONV krb5_free_tickets
(krb5_context, krb5_ticket ** );
void KRB5_CALLCONV krb5_free_kdc_req
(krb5_context, krb5_kdc_req * );
void KRB5_CALLCONV krb5_free_kdc_rep
(krb5_context, krb5_kdc_rep * );
void KRB5_CALLCONV krb5_free_last_req
(krb5_context, krb5_last_req_entry ** );
void KRB5_CALLCONV krb5_free_enc_kdc_rep_part
(krb5_context, krb5_enc_kdc_rep_part * );
#endif
void KRB5_CALLCONV krb5_free_error
(krb5_context, krb5_error * );
#if KRB5_PRIVATE
void KRB5_CALLCONV krb5_free_ap_req
(krb5_context, krb5_ap_req * );
void KRB5_CALLCONV krb5_free_ap_rep
(krb5_context, krb5_ap_rep * );
void KRB5_CALLCONV krb5_free_cred
(krb5_context, krb5_cred *);
#endif
void KRB5_CALLCONV krb5_free_creds
(krb5_context, krb5_creds *);
void KRB5_CALLCONV krb5_free_cred_contents
(krb5_context, krb5_creds *);
#if KRB5_PRIVATE
void KRB5_CALLCONV krb5_free_cred_enc_part
(krb5_context, krb5_cred_enc_part *);
#endif
void KRB5_CALLCONV krb5_free_checksum
(krb5_context, krb5_checksum *);
void KRB5_CALLCONV krb5_free_checksum_contents
(krb5_context, krb5_checksum *);
void KRB5_CALLCONV krb5_free_keyblock
(krb5_context, krb5_keyblock *);
void KRB5_CALLCONV krb5_free_keyblock_contents
(krb5_context, krb5_keyblock *);
#if KRB5_PRIVATE
void KRB5_CALLCONV krb5_free_pa_data
(krb5_context, krb5_pa_data **);
#endif
void KRB5_CALLCONV krb5_free_ap_rep_enc_part
(krb5_context, krb5_ap_rep_enc_part *);
#if KRB5_PRIVATE
void KRB5_CALLCONV krb5_free_tkt_authent
(krb5_context, krb5_tkt_authent *);
void KRB5_CALLCONV krb5_free_pwd_data
(krb5_context, krb5_pwd_data *);
void KRB5_CALLCONV krb5_free_pwd_sequences
(krb5_context, passwd_phrase_element **);
#endif
void KRB5_CALLCONV krb5_free_data
(krb5_context, krb5_data *);
void KRB5_CALLCONV krb5_free_data_contents
(krb5_context, krb5_data *);
void KRB5_CALLCONV krb5_free_unparsed_name
(krb5_context, char *);
void KRB5_CALLCONV krb5_free_cksumtypes
(krb5_context, krb5_cksumtype *);
/* From krb5/os but needed but by the outside world */
krb5_error_code KRB5_CALLCONV krb5_us_timeofday
(krb5_context,
krb5_int32 *,
krb5_int32 * );
krb5_error_code KRB5_CALLCONV krb5_timeofday
(krb5_context,
krb5_int32 * );
/* get all the addresses of this host */
krb5_error_code KRB5_CALLCONV krb5_os_localaddr
(krb5_context,
krb5_address ***);
krb5_error_code KRB5_CALLCONV krb5_get_default_realm
(krb5_context,
char ** );
krb5_error_code KRB5_CALLCONV krb5_set_default_realm
(krb5_context,
const char * );
void KRB5_CALLCONV krb5_free_default_realm
(krb5_context,
char * );
krb5_error_code KRB5_CALLCONV krb5_sname_to_principal
(krb5_context,
const char *,
const char *,
krb5_int32,
krb5_principal *);
krb5_error_code KRB5_CALLCONV
krb5_change_password
(krb5_context context, krb5_creds *creds, char *newpw,
int *result_code, krb5_data *result_code_string,
krb5_data *result_string);
krb5_error_code KRB5_CALLCONV
krb5_set_password
(krb5_context context, krb5_creds *creds, char *newpw, krb5_principal change_password_for,
int *result_code, krb5_data *result_code_string, krb5_data *result_string);
krb5_error_code KRB5_CALLCONV
krb5_set_password_using_ccache
(krb5_context context, krb5_ccache ccache, char *newpw, krb5_principal change_password_for,
int *result_code, krb5_data *result_code_string, krb5_data *result_string);
#if KRB5_PRIVATE
krb5_error_code krb5_set_config_files
(krb5_context, const char **);
krb5_error_code KRB5_CALLCONV krb5_get_default_config_files
(char ***filenames);
void KRB5_CALLCONV krb5_free_config_files
(char **filenames);
#endif
krb5_error_code KRB5_CALLCONV
krb5_get_profile
(krb5_context, struct _profile_t * /* profile_t */ *);
#if KRB5_PRIVATE
krb5_error_code krb5_send_tgs
(krb5_context,
krb5_flags,
const krb5_ticket_times *,
const krb5_enctype *,
krb5_const_principal,
krb5_address * const *,
krb5_authdata * const *,
krb5_pa_data * const *,
const krb5_data *,
krb5_creds *,
krb5_response * );
krb5_error_code krb5_send_tgs2
(krb5_context,
krb5_flags,
const krb5_ticket_times *,
const krb5_enctype *,
krb5_const_principal,
krb5_address * const *,
krb5_authdata * const *,
krb5_pa_data * const *,
const krb5_data *,
krb5_creds *,
krb5_response * ,
char **);
#endif
#if KRB5_DEPRECATED
krb5_error_code KRB5_CALLCONV krb5_get_in_tkt
(krb5_context,
krb5_flags,
krb5_address * const *,
krb5_enctype *,
krb5_preauthtype *,
krb5_error_code ( * )(krb5_context,
krb5_enctype,
krb5_data *,
krb5_const_pointer,
krb5_keyblock **),
krb5_const_pointer,
krb5_error_code ( * )(krb5_context,
const krb5_keyblock *,
krb5_const_pointer,
krb5_kdc_rep * ),
krb5_const_pointer,
krb5_creds *,
krb5_ccache,
krb5_kdc_rep ** );
krb5_error_code KRB5_CALLCONV krb5_get_in_tkt_with_password
(krb5_context,
krb5_flags,
krb5_address * const *,
krb5_enctype *,
krb5_preauthtype *,
const char *,
krb5_ccache,
krb5_creds *,
krb5_kdc_rep ** );
krb5_error_code KRB5_CALLCONV krb5_get_in_tkt_with_skey
(krb5_context,
krb5_flags,
krb5_address * const *,
krb5_enctype *,
krb5_preauthtype *,
const krb5_keyblock *,
krb5_ccache,
krb5_creds *,
krb5_kdc_rep ** );
krb5_error_code KRB5_CALLCONV krb5_get_in_tkt_with_keytab
(krb5_context,
krb5_flags,
krb5_address * const *,
krb5_enctype *,
krb5_preauthtype *,
krb5_keytab,
krb5_ccache,
krb5_creds *,
krb5_kdc_rep ** );
#endif /* KRB5_DEPRECATED */
#if KRB5_PRIVATE
krb5_error_code krb5_decode_kdc_rep
(krb5_context,
krb5_data *,
const krb5_keyblock *,
krb5_kdc_rep ** );
#endif
krb5_error_code KRB5_CALLCONV krb5_rd_req
(krb5_context,
krb5_auth_context *,
const krb5_data *,
krb5_const_principal,
krb5_keytab,
krb5_flags *,
krb5_ticket **);
#if KRB5_PRIVATE
krb5_error_code krb5_rd_req_decoded
(krb5_context,
krb5_auth_context *,
const krb5_ap_req *,
krb5_const_principal,
krb5_keytab,
krb5_flags *,
krb5_ticket **);
krb5_error_code krb5_rd_req_decoded_anyflag
(krb5_context,
krb5_auth_context *,
const krb5_ap_req *,
krb5_const_principal,
krb5_keytab,
krb5_flags *,
krb5_ticket **);
#endif
krb5_error_code KRB5_CALLCONV krb5_kt_read_service_key
(krb5_context,
krb5_pointer,
krb5_principal,
krb5_kvno,
krb5_enctype,
krb5_keyblock **);
krb5_error_code KRB5_CALLCONV krb5_mk_safe
(krb5_context,
krb5_auth_context,
const krb5_data *,
krb5_data *,
krb5_replay_data *);
krb5_error_code KRB5_CALLCONV krb5_mk_priv
(krb5_context,
krb5_auth_context,
const krb5_data *,
krb5_data *,
krb5_replay_data *);
#if KRB5_PRIVATE
krb5_error_code KRB5_CALLCONV krb5_cc_register
(krb5_context,
krb5_cc_ops *,
krb5_boolean );
#endif
krb5_error_code KRB5_CALLCONV krb5_sendauth
(krb5_context,
krb5_auth_context *,
krb5_pointer,
char *,
krb5_principal,
krb5_principal,
krb5_flags,
krb5_data *,
krb5_creds *,
krb5_ccache,
krb5_error **,
krb5_ap_rep_enc_part **,
krb5_creds **);
krb5_error_code KRB5_CALLCONV krb5_recvauth
(krb5_context,
krb5_auth_context *,
krb5_pointer,
char *,
krb5_principal,
krb5_int32,
krb5_keytab,
krb5_ticket **);
krb5_error_code KRB5_CALLCONV krb5_recvauth_version
(krb5_context,
krb5_auth_context *,
krb5_pointer,
krb5_principal,
krb5_int32,
krb5_keytab,
krb5_ticket **,
krb5_data *);
#if KRB5_PRIVATE
krb5_error_code krb5_walk_realm_tree
(krb5_context,
const krb5_data *,
const krb5_data *,
krb5_principal **,
int);
#endif
krb5_error_code KRB5_CALLCONV krb5_mk_ncred
(krb5_context,
krb5_auth_context,
krb5_creds **,
krb5_data **,
krb5_replay_data *);
krb5_error_code KRB5_CALLCONV krb5_mk_1cred
(krb5_context,
krb5_auth_context,
krb5_creds *,
krb5_data **,
krb5_replay_data *);
krb5_error_code KRB5_CALLCONV krb5_rd_cred
(krb5_context,
krb5_auth_context,
krb5_data *,
krb5_creds ***,
krb5_replay_data *);
krb5_error_code KRB5_CALLCONV krb5_fwd_tgt_creds
(krb5_context,
krb5_auth_context,
char *,
krb5_principal,
krb5_principal,
krb5_ccache,
int forwardable,
krb5_data *);
krb5_error_code KRB5_CALLCONV krb5_auth_con_init
(krb5_context,
krb5_auth_context *);
krb5_error_code KRB5_CALLCONV krb5_auth_con_free
(krb5_context,
krb5_auth_context);
krb5_error_code KRB5_CALLCONV krb5_auth_con_setflags
(krb5_context,
krb5_auth_context,
krb5_int32);
krb5_error_code KRB5_CALLCONV krb5_auth_con_getflags
(krb5_context,
krb5_auth_context,
krb5_int32 *);
krb5_error_code KRB5_CALLCONV
krb5_auth_con_set_checksum_func (krb5_context, krb5_auth_context,
krb5_mk_req_checksum_func, void *);
krb5_error_code KRB5_CALLCONV
krb5_auth_con_get_checksum_func( krb5_context, krb5_auth_context,
krb5_mk_req_checksum_func *, void **);
krb5_error_code KRB5_CALLCONV_WRONG krb5_auth_con_setaddrs
(krb5_context,
krb5_auth_context,
krb5_address *,
krb5_address *);
krb5_error_code KRB5_CALLCONV krb5_auth_con_getaddrs
(krb5_context,
krb5_auth_context,
krb5_address **,
krb5_address **);
krb5_error_code KRB5_CALLCONV krb5_auth_con_setports
(krb5_context,
krb5_auth_context,
krb5_address *,
krb5_address *);
krb5_error_code KRB5_CALLCONV krb5_auth_con_setuseruserkey
(krb5_context,
krb5_auth_context,
krb5_keyblock *);
krb5_error_code KRB5_CALLCONV krb5_auth_con_getkey
(krb5_context,
krb5_auth_context,
krb5_keyblock **);
krb5_error_code KRB5_CALLCONV krb5_auth_con_getsendsubkey(
krb5_context, krb5_auth_context, krb5_keyblock **);
krb5_error_code KRB5_CALLCONV krb5_auth_con_getrecvsubkey(
krb5_context, krb5_auth_context, krb5_keyblock **);
krb5_error_code KRB5_CALLCONV krb5_auth_con_setsendsubkey(
krb5_context, krb5_auth_context, krb5_keyblock *);
krb5_error_code KRB5_CALLCONV krb5_auth_con_setrecvsubkey(
krb5_context, krb5_auth_context, krb5_keyblock *);
#if KRB5_DEPRECATED
krb5_error_code KRB5_CALLCONV krb5_auth_con_getlocalsubkey
(krb5_context,
krb5_auth_context,
krb5_keyblock **);
krb5_error_code KRB5_CALLCONV krb5_auth_con_getremotesubkey
(krb5_context,
krb5_auth_context,
krb5_keyblock **);
#endif
#if KRB5_PRIVATE
krb5_error_code KRB5_CALLCONV krb5_auth_con_set_req_cksumtype
(krb5_context,
krb5_auth_context,
krb5_cksumtype);
krb5_error_code krb5_auth_con_set_safe_cksumtype
(krb5_context,
krb5_auth_context,
krb5_cksumtype);
#endif
krb5_error_code KRB5_CALLCONV krb5_auth_con_getlocalseqnumber
(krb5_context,
krb5_auth_context,
krb5_int32 *);
krb5_error_code KRB5_CALLCONV krb5_auth_con_getremoteseqnumber
(krb5_context,
krb5_auth_context,
krb5_int32 *);
#if KRB5_DEPRECATED
krb5_error_code KRB5_CALLCONV krb5_auth_con_initivector
(krb5_context,
krb5_auth_context);
#endif
#if KRB5_PRIVATE
krb5_error_code krb5_auth_con_setivector
(krb5_context,
krb5_auth_context,
krb5_pointer);
krb5_error_code krb5_auth_con_getivector
(krb5_context,
krb5_auth_context,
krb5_pointer *);
#endif
krb5_error_code KRB5_CALLCONV krb5_auth_con_setrcache
(krb5_context,
krb5_auth_context,
krb5_rcache);
krb5_error_code KRB5_CALLCONV_WRONG krb5_auth_con_getrcache
(krb5_context,
krb5_auth_context,
krb5_rcache *);
#if KRB5_PRIVATE
krb5_error_code krb5_auth_con_setpermetypes
(krb5_context,
krb5_auth_context,
const krb5_enctype *);
krb5_error_code krb5_auth_con_getpermetypes
(krb5_context,
krb5_auth_context,
krb5_enctype **);
#endif
krb5_error_code KRB5_CALLCONV krb5_auth_con_getauthenticator
(krb5_context,
krb5_auth_context,
krb5_authenticator **);
#define KRB5_REALM_BRANCH_CHAR '.'
/*
* end "func-proto.h"
*/
/*
* begin stuff from libos.h
*/
#if KRB5_PRIVATE
krb5_error_code krb5_read_message (krb5_context, krb5_pointer, krb5_data *);
krb5_error_code krb5_write_message (krb5_context, krb5_pointer, krb5_data *);
int krb5_net_read (krb5_context, int , char *, int);
int krb5_net_write (krb5_context, int , const char *, int);
#endif
krb5_error_code KRB5_CALLCONV krb5_read_password
(krb5_context,
const char *,
const char *,
char *,
unsigned int * );
krb5_error_code KRB5_CALLCONV krb5_aname_to_localname
(krb5_context,
krb5_const_principal,
int,
char * );
krb5_error_code KRB5_CALLCONV krb5_get_host_realm
(krb5_context,
const char *,
char *** );
krb5_error_code KRB5_CALLCONV krb5_get_fallback_host_realm
(krb5_context,
krb5_data *,
char *** );
krb5_error_code KRB5_CALLCONV krb5_free_host_realm
(krb5_context,
char * const * );
#if KRB5_PRIVATE
krb5_error_code KRB5_CALLCONV krb5_get_realm_domain
(krb5_context,
const char *,
char ** );
#endif
krb5_boolean KRB5_CALLCONV krb5_kuserok
(krb5_context,
krb5_principal, const char *);
krb5_error_code KRB5_CALLCONV krb5_auth_con_genaddrs
(krb5_context,
krb5_auth_context,
int, int);
#if KRB5_PRIVATE
krb5_error_code krb5_gen_portaddr
(krb5_context,
const krb5_address *,
krb5_const_pointer,
krb5_address **);
krb5_error_code krb5_gen_replay_name
(krb5_context,
const krb5_address *,
const char *,
char **);
krb5_error_code krb5_make_fulladdr
(krb5_context,
krb5_address *,
krb5_address *,
krb5_address *);
#endif
krb5_error_code KRB5_CALLCONV krb5_set_real_time
(krb5_context, krb5_int32, krb5_int32);
#if KRB5_PRIVATE
krb5_error_code krb5_set_debugging_time
(krb5_context, krb5_int32, krb5_int32);
krb5_error_code krb5_use_natural_time
(krb5_context);
#endif
krb5_error_code KRB5_CALLCONV krb5_get_time_offsets
(krb5_context, krb5_int32 *, krb5_int32 *);
#if KRB5_PRIVATE
krb5_error_code krb5_set_time_offsets
(krb5_context, krb5_int32, krb5_int32);
#endif
/* str_conv.c */
krb5_error_code KRB5_CALLCONV krb5_string_to_enctype
(char *, krb5_enctype *);
krb5_error_code KRB5_CALLCONV krb5_string_to_salttype
(char *, krb5_int32 *);
krb5_error_code KRB5_CALLCONV krb5_string_to_cksumtype
(char *, krb5_cksumtype *);
krb5_error_code KRB5_CALLCONV krb5_string_to_timestamp
(char *, krb5_timestamp *);
krb5_error_code KRB5_CALLCONV krb5_string_to_deltat
(char *, krb5_deltat *);
krb5_error_code KRB5_CALLCONV krb5_enctype_to_string
(krb5_enctype, char *, size_t);
/* Solaris Kerberos */
krb5_error_code KRB5_CALLCONV krb5_enctype_to_istring
(krb5_enctype, char *, size_t);
krb5_error_code KRB5_CALLCONV krb5_salttype_to_string
(krb5_int32, char *, size_t);
krb5_error_code KRB5_CALLCONV krb5_cksumtype_to_string
(krb5_cksumtype, char *, size_t);
krb5_error_code KRB5_CALLCONV krb5_timestamp_to_string
(krb5_timestamp, char *, size_t);
krb5_error_code KRB5_CALLCONV krb5_timestamp_to_sfstring
(krb5_timestamp, char *, size_t, char *);
krb5_error_code KRB5_CALLCONV krb5_deltat_to_string
(krb5_deltat, char *, size_t);
/*
* end stuff from libos.h
*/
/*
* begin "k5-free.h"
*/
/* to keep lint happy */
#ifdef _KERNEL
#define krb5_xfree_wrap(val,n) kmem_free((char *)(val),n)
#else
#define krb5_xfree_wrap(val,n) free((char *)(val))
#define krb5_xfree(val) free((char *)(val))
#endif
/*
* end "k5-free.h"
*/
/* The name of the Kerberos ticket granting service... and its size */
#define KRB5_TGS_NAME "krbtgt"
#define KRB5_TGS_NAME_SIZE 6
/* flags for recvauth */
#define KRB5_RECVAUTH_SKIP_VERSION 0x0001
#define KRB5_RECVAUTH_BADAUTHVERS 0x0002
/* initial ticket api functions */
typedef struct _krb5_prompt {
char *prompt;
int hidden;
krb5_data *reply;
} krb5_prompt;
typedef krb5_error_code (KRB5_CALLCONV *krb5_prompter_fct)(krb5_context context,
void *data,
const char *name,
const char *banner,
int num_prompts,
krb5_prompt prompts[]);
krb5_error_code KRB5_CALLCONV
krb5_prompter_posix (krb5_context context,
void *data,
const char *name,
const char *banner,
int num_prompts,
krb5_prompt prompts[]);
typedef struct _krb5_get_init_creds_opt {
krb5_flags flags;
krb5_deltat tkt_life;
krb5_deltat renew_life;
int forwardable;
int proxiable;
krb5_enctype *etype_list;
int etype_list_length;
krb5_address **address_list;
krb5_preauthtype *preauth_list;
int preauth_list_length;
krb5_data *salt;
} krb5_get_init_creds_opt;
#define KRB5_GET_INIT_CREDS_OPT_TKT_LIFE 0x0001
#define KRB5_GET_INIT_CREDS_OPT_RENEW_LIFE 0x0002
#define KRB5_GET_INIT_CREDS_OPT_FORWARDABLE 0x0004
#define KRB5_GET_INIT_CREDS_OPT_PROXIABLE 0x0008
#define KRB5_GET_INIT_CREDS_OPT_ETYPE_LIST 0x0010
#define KRB5_GET_INIT_CREDS_OPT_ADDRESS_LIST 0x0020
#define KRB5_GET_INIT_CREDS_OPT_PREAUTH_LIST 0x0040
#define KRB5_GET_INIT_CREDS_OPT_SALT 0x0080
#define KRB5_GET_INIT_CREDS_OPT_CHG_PWD_PRMPT 0x0100
krb5_error_code KRB5_CALLCONV
krb5_get_init_creds_opt_alloc
(krb5_context context,
krb5_get_init_creds_opt **opt);
void KRB5_CALLCONV
krb5_get_init_creds_opt_free
(krb5_context context,
krb5_get_init_creds_opt *opt);
void KRB5_CALLCONV
krb5_get_init_creds_opt_init
(krb5_get_init_creds_opt *opt);
void KRB5_CALLCONV
krb5_get_init_creds_opt_set_tkt_life
(krb5_get_init_creds_opt *opt,
krb5_deltat tkt_life);
void KRB5_CALLCONV
krb5_get_init_creds_opt_set_renew_life
(krb5_get_init_creds_opt *opt,
krb5_deltat renew_life);
void KRB5_CALLCONV
krb5_get_init_creds_opt_set_forwardable
(krb5_get_init_creds_opt *opt,
int forwardable);
void KRB5_CALLCONV
krb5_get_init_creds_opt_set_proxiable
(krb5_get_init_creds_opt *opt,
int proxiable);
void KRB5_CALLCONV
krb5_get_init_creds_opt_set_etype_list
(krb5_get_init_creds_opt *opt,
krb5_enctype *etype_list,
int etype_list_length);
void KRB5_CALLCONV
krb5_get_init_creds_opt_set_address_list
(krb5_get_init_creds_opt *opt,
krb5_address **addresses);
void KRB5_CALLCONV
krb5_get_init_creds_opt_set_preauth_list
(krb5_get_init_creds_opt *opt,
krb5_preauthtype *preauth_list,
int preauth_list_length);
void KRB5_CALLCONV
krb5_get_init_creds_opt_set_salt
(krb5_get_init_creds_opt *opt,
krb5_data *salt);
void KRB5_CALLCONV
krb5_get_init_creds_opt_set_change_password_prompt
(krb5_get_init_creds_opt *opt,
int prompt);
/* Generic preauth option attribute/value pairs */
typedef struct _krb5_gic_opt_pa_data {
char *attr;
char *value;
} krb5_gic_opt_pa_data;
/*
* This function allows the caller to supply options to preauth
* plugins. Preauth plugin modules are given a chance to look
* at each option at the time this function is called in ordre
* to check the validity of the option.
* The 'opt' pointer supplied to this function must have been
* obtained using krb5_get_init_creds_opt_alloc()
*/
krb5_error_code KRB5_CALLCONV
krb5_get_init_creds_opt_set_pa
(krb5_context context,
krb5_get_init_creds_opt *opt,
const char *attr,
const char *value);
krb5_error_code KRB5_CALLCONV
krb5_get_init_creds_password
(krb5_context context,
krb5_creds *creds,
krb5_principal client,
char *password,
krb5_prompter_fct prompter,
void *data,
krb5_deltat start_time,
char *in_tkt_service,
krb5_get_init_creds_opt *k5_gic_options);
krb5_error_code KRB5_CALLCONV
krb5_get_init_creds_keytab
(krb5_context context,
krb5_creds *creds,
krb5_principal client,
krb5_keytab arg_keytab,
krb5_deltat start_time,
char *in_tkt_service,
krb5_get_init_creds_opt *k5_gic_options);
typedef struct _krb5_verify_init_creds_opt {
krb5_flags flags;
int ap_req_nofail;
} krb5_verify_init_creds_opt;
#define KRB5_VERIFY_INIT_CREDS_OPT_AP_REQ_NOFAIL 0x0001
void KRB5_CALLCONV
krb5_verify_init_creds_opt_init
(krb5_verify_init_creds_opt *k5_vic_options);
void KRB5_CALLCONV
krb5_verify_init_creds_opt_set_ap_req_nofail
(krb5_verify_init_creds_opt *k5_vic_options,
int ap_req_nofail);
krb5_error_code KRB5_CALLCONV
krb5_verify_init_creds
(krb5_context context,
krb5_creds *creds,
krb5_principal ap_req_server,
krb5_keytab ap_req_keytab,
krb5_ccache *ccache,
krb5_verify_init_creds_opt *k5_vic_options);
krb5_error_code KRB5_CALLCONV
krb5_get_validated_creds
(krb5_context context,
krb5_creds *creds,
krb5_principal client,
krb5_ccache ccache,
char *in_tkt_service);
krb5_error_code KRB5_CALLCONV
krb5_get_renewed_creds
(krb5_context context,
krb5_creds *creds,
krb5_principal client,
krb5_ccache ccache,
char *in_tkt_service);
krb5_error_code KRB5_CALLCONV
krb5_decode_ticket
(const krb5_data *code,
krb5_ticket **rep);
void KRB5_CALLCONV
krb5_appdefault_string
(krb5_context context,
const char *appname,
const krb5_data *realm,
const char *option,
const char *default_value,
char ** ret_value);
void KRB5_CALLCONV
krb5_appdefault_boolean
(krb5_context context,
const char *appname,
const krb5_data *realm,
const char *option,
int default_value,
int *ret_value);
#if KRB5_PRIVATE
/*
* The realm iterator functions
*/
krb5_error_code KRB5_CALLCONV krb5_realm_iterator_create
(krb5_context context, void **iter_p);
krb5_error_code KRB5_CALLCONV krb5_realm_iterator
(krb5_context context, void **iter_p, char **ret_realm);
void KRB5_CALLCONV krb5_realm_iterator_free
(krb5_context context, void **iter_p);
void KRB5_CALLCONV krb5_free_realm_string
(krb5_context context, char *str);
#endif
/*
* The realm iterator functions
*/
krb5_error_code KRB5_CALLCONV krb5_realm_iterator_create
(krb5_context context, void **iter_p);
krb5_error_code KRB5_CALLCONV krb5_realm_iterator
(krb5_context context, void **iter_p, char **ret_realm);
void KRB5_CALLCONV krb5_realm_iterator_free
(krb5_context context, void **iter_p);
void KRB5_CALLCONV krb5_free_realm_string
(krb5_context context, char *str);
/*
* Prompter enhancements
*/
#define KRB5_PROMPT_TYPE_PASSWORD 0x1
#define KRB5_PROMPT_TYPE_NEW_PASSWORD 0x2
#define KRB5_PROMPT_TYPE_NEW_PASSWORD_AGAIN 0x3
#define KRB5_PROMPT_TYPE_PREAUTH 0x4
typedef krb5_int32 krb5_prompt_type;
krb5_prompt_type* KRB5_CALLCONV krb5_get_prompt_types
(krb5_context context);
/* Error reporting */
void KRB5_CALLCONV_C
krb5_set_error_message (krb5_context, krb5_error_code, const char *, ...);
#ifdef va_start
void KRB5_CALLCONV
krb5_vset_error_message (krb5_context, krb5_error_code, const char *, va_list);
#endif
/*
* The behavior of krb5_get_error_message is only defined the first
* time it is called after a failed call to a krb5 function using the
* same context, and only when the error code passed in is the same as
* that returned by the krb5 function. Future versions may return the
* same string for the second and following calls.
*
* The string returned by this function must be freed using
* krb5_free_error_message.
*/
const char * KRB5_CALLCONV
krb5_get_error_message (krb5_context, krb5_error_code);
void KRB5_CALLCONV
krb5_free_error_message (krb5_context, const char *);
void KRB5_CALLCONV
krb5_clear_error_message (krb5_context);
krb5_error_code KRB5_CALLCONV
krb5_decode_authdata_container(krb5_context context,
krb5_authdatatype type,
const krb5_authdata *container,
krb5_authdata ***authdata);
krb5_error_code KRB5_CALLCONV
krb5_encode_authdata_container(krb5_context context,
krb5_authdatatype type,
krb5_authdata * const*authdata,
krb5_authdata ***container);
/*
* Windows PAC
*/
struct krb5_pac_data;
typedef struct krb5_pac_data *krb5_pac;
krb5_error_code KRB5_CALLCONV
krb5_pac_add_buffer
(krb5_context context,
krb5_pac pac,
krb5_ui_4 type,
const krb5_data *data);
void KRB5_CALLCONV
krb5_pac_free
(krb5_context context,
krb5_pac pac);
krb5_error_code KRB5_CALLCONV
krb5_pac_get_buffer
(krb5_context context,
krb5_pac pac,
krb5_ui_4 type,
krb5_data *data);
krb5_error_code KRB5_CALLCONV
krb5_pac_get_types
(krb5_context context,
krb5_pac pac,
size_t *len,
krb5_ui_4 **types);
krb5_error_code KRB5_CALLCONV
krb5_pac_init
(krb5_context context,
krb5_pac *pac);
krb5_error_code KRB5_CALLCONV
krb5_pac_parse
(krb5_context context,
const void *ptr,
size_t len,
krb5_pac *pac);
krb5_error_code KRB5_CALLCONV
krb5_pac_verify
(krb5_context context,
const krb5_pac pac,
krb5_timestamp authtime,
krb5_const_principal principal,
const krb5_keyblock *server,
const krb5_keyblock *privsvr);
#if TARGET_OS_MAC
# pragma pack(pop)
#endif
KRB5INT_END_DECLS
/* Don't use this! We're going to phase it out. It's just here to keep
applications from breaking right away. */
#define krb5_const const
#endif /* KRB5_GENERAL__ */
/*
* Solaris Kerberos: the following differs from the MIT krb5.hin as that file is
* processed to produce their krb5.h. We do not process a krb5.hin so our
* krb5.h is manually edited.
*/
/*
* krb5_err.h:
* This file is automatically generated; please do not edit it.
*/
#define KRB5KDC_ERR_NONE (-1765328384L)
#define KRB5KDC_ERR_NAME_EXP (-1765328383L)
#define KRB5KDC_ERR_SERVICE_EXP (-1765328382L)
#define KRB5KDC_ERR_BAD_PVNO (-1765328381L)
#define KRB5KDC_ERR_C_OLD_MAST_KVNO (-1765328380L)
#define KRB5KDC_ERR_S_OLD_MAST_KVNO (-1765328379L)
#define KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN (-1765328378L)
#define KRB5KDC_ERR_S_PRINCIPAL_UNKNOWN (-1765328377L)
#define KRB5KDC_ERR_PRINCIPAL_NOT_UNIQUE (-1765328376L)
#define KRB5KDC_ERR_NULL_KEY (-1765328375L)
#define KRB5KDC_ERR_CANNOT_POSTDATE (-1765328374L)
#define KRB5KDC_ERR_NEVER_VALID (-1765328373L)
#define KRB5KDC_ERR_POLICY (-1765328372L)
#define KRB5KDC_ERR_BADOPTION (-1765328371L)
#define KRB5KDC_ERR_ETYPE_NOSUPP (-1765328370L)
#define KRB5KDC_ERR_SUMTYPE_NOSUPP (-1765328369L)
#define KRB5KDC_ERR_PADATA_TYPE_NOSUPP (-1765328368L)
#define KRB5KDC_ERR_TRTYPE_NOSUPP (-1765328367L)
#define KRB5KDC_ERR_CLIENT_REVOKED (-1765328366L)
#define KRB5KDC_ERR_SERVICE_REVOKED (-1765328365L)
#define KRB5KDC_ERR_TGT_REVOKED (-1765328364L)
#define KRB5KDC_ERR_CLIENT_NOTYET (-1765328363L)
#define KRB5KDC_ERR_SERVICE_NOTYET (-1765328362L)
#define KRB5KDC_ERR_KEY_EXP (-1765328361L)
#define KRB5KDC_ERR_PREAUTH_FAILED (-1765328360L)
#define KRB5KDC_ERR_PREAUTH_REQUIRED (-1765328359L)
#define KRB5KDC_ERR_SERVER_NOMATCH (-1765328358L)
#define KRB5KDC_ERR_MUST_USE_USER2USER (-1765328357L)
#define KRB5KDC_ERR_PATH_NOT_ACCEPTED (-1765328356L)
#define KRB5KDC_ERR_SVC_UNAVAILABLE (-1765328355L)
#define KRB5PLACEHOLD_30 (-1765328354L)
#define KRB5KRB_AP_ERR_BAD_INTEGRITY (-1765328353L)
#define KRB5KRB_AP_ERR_TKT_EXPIRED (-1765328352L)
#define KRB5KRB_AP_ERR_TKT_NYV (-1765328351L)
#define KRB5KRB_AP_ERR_REPEAT (-1765328350L)
#define KRB5KRB_AP_ERR_NOT_US (-1765328349L)
#define KRB5KRB_AP_ERR_BADMATCH (-1765328348L)
#define KRB5KRB_AP_ERR_SKEW (-1765328347L)
#define KRB5KRB_AP_ERR_BADADDR (-1765328346L)
#define KRB5KRB_AP_ERR_BADVERSION (-1765328345L)
#define KRB5KRB_AP_ERR_MSG_TYPE (-1765328344L)
#define KRB5KRB_AP_ERR_MODIFIED (-1765328343L)
#define KRB5KRB_AP_ERR_BADORDER (-1765328342L)
#define KRB5KRB_AP_ERR_ILL_CR_TKT (-1765328341L)
#define KRB5KRB_AP_ERR_BADKEYVER (-1765328340L)
#define KRB5KRB_AP_ERR_NOKEY (-1765328339L)
#define KRB5KRB_AP_ERR_MUT_FAIL (-1765328338L)
#define KRB5KRB_AP_ERR_BADDIRECTION (-1765328337L)
#define KRB5KRB_AP_ERR_METHOD (-1765328336L)
#define KRB5KRB_AP_ERR_BADSEQ (-1765328335L)
#define KRB5KRB_AP_ERR_INAPP_CKSUM (-1765328334L)
#define KRB5KRB_AP_PATH_NOT_ACCEPTED (-1765328333L)
#define KRB5KRB_ERR_RESPONSE_TOO_BIG (-1765328332L)
#define KRB5PLACEHOLD_53 (-1765328331L)
#define KRB5PLACEHOLD_54 (-1765328330L)
#define KRB5PLACEHOLD_55 (-1765328329L)
#define KRB5PLACEHOLD_56 (-1765328328L)
#define KRB5PLACEHOLD_57 (-1765328327L)
#define KRB5PLACEHOLD_58 (-1765328326L)
#define KRB5PLACEHOLD_59 (-1765328325L)
#define KRB5KRB_ERR_GENERIC (-1765328324L)
#define KRB5KRB_ERR_FIELD_TOOLONG (-1765328323L)
#define KRB5KDC_ERR_CLIENT_NOT_TRUSTED (-1765328322L)
#define KRB5KDC_ERR_KDC_NOT_TRUSTED (-1765328321L)
#define KRB5KDC_ERR_INVALID_SIG (-1765328320L)
#define KRB5KDC_ERR_DH_KEY_PARAMETERS_NOT_ACCEPTED (-1765328319L)
#define KRB5KDC_ERR_CERTIFICATE_MISMATCH (-1765328318L)
#define KRB5KRB_AP_ERR_NO_TGT (-1765328317L)
#define KRB5KDC_ERR_WRONG_REALM (-1765328316L)
#define KRB5KRB_AP_ERR_USER_TO_USER_REQUIRED (-1765328315L)
#define KRB5KDC_ERR_CANT_VERIFY_CERTIFICATE (-1765328314L)
#define KRB5KDC_ERR_INVALID_CERTIFICATE (-1765328313L)
#define KRB5KDC_ERR_REVOKED_CERTIFICATE (-1765328312L)
#define KRB5KDC_ERR_REVOCATION_STATUS_UNKNOWN (-1765328311L)
#define KRB5KDC_ERR_REVOCATION_STATUS_UNAVAILABLE (-1765328310L)
#define KRB5KDC_ERR_CLIENT_NAME_MISMATCH (-1765328309L)
#define KRB5KDC_ERR_KDC_NAME_MISMATCH (-1765328308L)
#define KRB5KDC_ERR_INCONSISTENT_KEY_PURPOSE (-1765328307L)
#define KRB5KDC_ERR_DIGEST_IN_CERT_NOT_ACCEPTED (-1765328306L)
#define KRB5KDC_ERR_PA_CHECKSUM_MUST_BE_INCLUDED (-1765328305L)
#define KRB5KDC_ERR_DIGEST_IN_SIGNED_DATA_NOT_ACCEPTED (-1765328304L)
#define KRB5KDC_ERR_PUBLIC_KEY_ENCRYPTION_NOT_SUPPORTED (-1765328303L)
#define KRB5PLACEHOLD_82 (-1765328302L)
#define KRB5PLACEHOLD_83 (-1765328301L)
#define KRB5PLACEHOLD_84 (-1765328300L)
#define KRB5PLACEHOLD_85 (-1765328299L)
#define KRB5PLACEHOLD_86 (-1765328298L)
#define KRB5PLACEHOLD_87 (-1765328297L)
#define KRB5PLACEHOLD_88 (-1765328296L)
#define KRB5PLACEHOLD_89 (-1765328295L)
#define KRB5PLACEHOLD_90 (-1765328294L)
#define KRB5PLACEHOLD_91 (-1765328293L)
#define KRB5PLACEHOLD_92 (-1765328292L)
#define KRB5PLACEHOLD_93 (-1765328291L)
#define KRB5PLACEHOLD_94 (-1765328290L)
#define KRB5PLACEHOLD_95 (-1765328289L)
#define KRB5PLACEHOLD_96 (-1765328288L)
#define KRB5PLACEHOLD_97 (-1765328287L)
#define KRB5PLACEHOLD_98 (-1765328286L)
#define KRB5PLACEHOLD_99 (-1765328285L)
#define KRB5PLACEHOLD_100 (-1765328284L)
#define KRB5PLACEHOLD_101 (-1765328283L)
#define KRB5PLACEHOLD_102 (-1765328282L)
#define KRB5PLACEHOLD_103 (-1765328281L)
#define KRB5PLACEHOLD_104 (-1765328280L)
#define KRB5PLACEHOLD_105 (-1765328279L)
#define KRB5PLACEHOLD_106 (-1765328278L)
#define KRB5PLACEHOLD_107 (-1765328277L)
#define KRB5PLACEHOLD_108 (-1765328276L)
#define KRB5PLACEHOLD_109 (-1765328275L)
#define KRB5PLACEHOLD_110 (-1765328274L)
#define KRB5PLACEHOLD_111 (-1765328273L)
#define KRB5PLACEHOLD_112 (-1765328272L)
#define KRB5PLACEHOLD_113 (-1765328271L)
#define KRB5PLACEHOLD_114 (-1765328270L)
#define KRB5PLACEHOLD_115 (-1765328269L)
#define KRB5PLACEHOLD_116 (-1765328268L)
#define KRB5PLACEHOLD_117 (-1765328267L)
#define KRB5PLACEHOLD_118 (-1765328266L)
#define KRB5PLACEHOLD_119 (-1765328265L)
#define KRB5PLACEHOLD_120 (-1765328264L)
#define KRB5PLACEHOLD_121 (-1765328263L)
#define KRB5PLACEHOLD_122 (-1765328262L)
#define KRB5PLACEHOLD_123 (-1765328261L)
#define KRB5PLACEHOLD_124 (-1765328260L)
#define KRB5PLACEHOLD_125 (-1765328259L)
#define KRB5PLACEHOLD_126 (-1765328258L)
#define KRB5PLACEHOLD_127 (-1765328257L)
#define KRB5_ERR_RCSID (-1765328256L)
#define KRB5_LIBOS_BADLOCKFLAG (-1765328255L)
#define KRB5_LIBOS_CANTREADPWD (-1765328254L)
#define KRB5_LIBOS_BADPWDMATCH (-1765328253L)
#define KRB5_LIBOS_PWDINTR (-1765328252L)
#define KRB5_PARSE_ILLCHAR (-1765328251L)
#define KRB5_PARSE_MALFORMED (-1765328250L)
#define KRB5_CONFIG_CANTOPEN (-1765328249L)
#define KRB5_CONFIG_BADFORMAT (-1765328248L)
#define KRB5_CONFIG_NOTENUFSPACE (-1765328247L)
#define KRB5_BADMSGTYPE (-1765328246L)
#define KRB5_CC_BADNAME (-1765328245L)
#define KRB5_CC_UNKNOWN_TYPE (-1765328244L)
#define KRB5_CC_NOTFOUND (-1765328243L)
#define KRB5_CC_END (-1765328242L)
#define KRB5_NO_TKT_SUPPLIED (-1765328241L)
#define KRB5KRB_AP_WRONG_PRINC (-1765328240L)
#define KRB5KRB_AP_ERR_TKT_INVALID (-1765328239L)
#define KRB5_PRINC_NOMATCH (-1765328238L)
#define KRB5_KDCREP_MODIFIED (-1765328237L)
#define KRB5_KDCREP_SKEW (-1765328236L)
#define KRB5_IN_TKT_REALM_MISMATCH (-1765328235L)
#define KRB5_PROG_ETYPE_NOSUPP (-1765328234L)
#define KRB5_PROG_KEYTYPE_NOSUPP (-1765328233L)
#define KRB5_WRONG_ETYPE (-1765328232L)
#define KRB5_PROG_SUMTYPE_NOSUPP (-1765328231L)
#define KRB5_REALM_UNKNOWN (-1765328230L)
#define KRB5_SERVICE_UNKNOWN (-1765328229L)
#define KRB5_KDC_UNREACH (-1765328228L)
#define KRB5_NO_LOCALNAME (-1765328227L)
#define KRB5_MUTUAL_FAILED (-1765328226L)
#define KRB5_RC_TYPE_EXISTS (-1765328225L)
#define KRB5_RC_MALLOC (-1765328224L)
#define KRB5_RC_TYPE_NOTFOUND (-1765328223L)
#define KRB5_RC_UNKNOWN (-1765328222L)
#define KRB5_RC_REPLAY (-1765328221L)
#define KRB5_RC_IO (-1765328220L)
#define KRB5_RC_NOIO (-1765328219L)
#define KRB5_RC_PARSE (-1765328218L)
#define KRB5_RC_IO_EOF (-1765328217L)
#define KRB5_RC_IO_MALLOC (-1765328216L)
#define KRB5_RC_IO_PERM (-1765328215L)
#define KRB5_RC_IO_IO (-1765328214L)
#define KRB5_RC_IO_UNKNOWN (-1765328213L)
#define KRB5_RC_IO_SPACE (-1765328212L)
#define KRB5_TRANS_CANTOPEN (-1765328211L)
#define KRB5_TRANS_BADFORMAT (-1765328210L)
#define KRB5_LNAME_CANTOPEN (-1765328209L)
#define KRB5_LNAME_NOTRANS (-1765328208L)
#define KRB5_LNAME_BADFORMAT (-1765328207L)
#define KRB5_CRYPTO_INTERNAL (-1765328206L)
#define KRB5_KT_BADNAME (-1765328205L)
#define KRB5_KT_UNKNOWN_TYPE (-1765328204L)
#define KRB5_KT_NOTFOUND (-1765328203L)
#define KRB5_KT_END (-1765328202L)
#define KRB5_KT_NOWRITE (-1765328201L)
#define KRB5_KT_IOERR (-1765328200L)
#define KRB5_NO_TKT_IN_RLM (-1765328199L)
#define KRB5DES_BAD_KEYPAR (-1765328198L)
#define KRB5DES_WEAK_KEY (-1765328197L)
#define KRB5_BAD_ENCTYPE (-1765328196L)
#define KRB5_BAD_KEYSIZE (-1765328195L)
#define KRB5_BAD_MSIZE (-1765328194L)
#define KRB5_CC_TYPE_EXISTS (-1765328193L)
#define KRB5_KT_TYPE_EXISTS (-1765328192L)
#define KRB5_CC_IO (-1765328191L)
#define KRB5_FCC_PERM (-1765328190L)
#define KRB5_FCC_NOFILE (-1765328189L)
#define KRB5_FCC_INTERNAL (-1765328188L)
#define KRB5_CC_WRITE (-1765328187L)
#define KRB5_CC_NOMEM (-1765328186L)
#define KRB5_CC_FORMAT (-1765328185L)
#define KRB5_CC_NOT_KTYPE (-1765328184L)
#define KRB5_INVALID_FLAGS (-1765328183L)
#define KRB5_NO_2ND_TKT (-1765328182L)
#define KRB5_NOCREDS_SUPPLIED (-1765328181L)
#define KRB5_SENDAUTH_BADAUTHVERS (-1765328180L)
#define KRB5_SENDAUTH_BADAPPLVERS (-1765328179L)
#define KRB5_SENDAUTH_BADRESPONSE (-1765328178L)
#define KRB5_SENDAUTH_REJECTED (-1765328177L)
#define KRB5_PREAUTH_BAD_TYPE (-1765328176L)
#define KRB5_PREAUTH_NO_KEY (-1765328175L)
#define KRB5_PREAUTH_FAILED (-1765328174L)
#define KRB5_RCACHE_BADVNO (-1765328173L)
#define KRB5_CCACHE_BADVNO (-1765328172L)
#define KRB5_KEYTAB_BADVNO (-1765328171L)
#define KRB5_PROG_ATYPE_NOSUPP (-1765328170L)
#define KRB5_RC_REQUIRED (-1765328169L)
#define KRB5_ERR_BAD_HOSTNAME (-1765328168L)
#define KRB5_ERR_HOST_REALM_UNKNOWN (-1765328167L)
#define KRB5_SNAME_UNSUPP_NAMETYPE (-1765328166L)
#define KRB5KRB_AP_ERR_V4_REPLY (-1765328165L)
#define KRB5_REALM_CANT_RESOLVE (-1765328164L)
#define KRB5_TKT_NOT_FORWARDABLE (-1765328163L)
#define KRB5_FWD_BAD_PRINCIPAL (-1765328162L)
#define KRB5_GET_IN_TKT_LOOP (-1765328161L)
#define KRB5_CONFIG_NODEFREALM (-1765328160L)
#define KRB5_SAM_UNSUPPORTED (-1765328159L)
#define KRB5_SAM_INVALID_ETYPE (-1765328158L)
#define KRB5_SAM_NO_CHECKSUM (-1765328157L)
#define KRB5_SAM_BAD_CHECKSUM (-1765328156L)
#define KRB5_KT_NAME_TOOLONG (-1765328155L)
#define KRB5_KT_KVNONOTFOUND (-1765328154L)
#define KRB5_APPL_EXPIRED (-1765328153L)
#define KRB5_LIB_EXPIRED (-1765328152L)
#define KRB5_CHPW_PWDNULL (-1765328151L)
#define KRB5_CHPW_FAIL (-1765328150L)
#define KRB5_KT_FORMAT (-1765328149L)
#define KRB5_NOPERM_ETYPE (-1765328148L)
#define KRB5_CONFIG_ETYPE_NOSUPP (-1765328147L)
#define KRB5_OBSOLETE_FN (-1765328146L)
#define KRB5_EAI_FAIL (-1765328145L)
#define KRB5_EAI_NODATA (-1765328144L)
#define KRB5_EAI_NONAME (-1765328143L)
#define KRB5_EAI_SERVICE (-1765328142L)
#define KRB5_ERR_NUMERIC_REALM (-1765328141L)
#define KRB5_ERR_BAD_S2K_PARAMS (-1765328140L)
#define KRB5_ERR_NO_SERVICE (-1765328139L)
#define KRB5_CC_READONLY (-1765328138L)
#define KRB5_CC_NOSUPP (-1765328137L)
/* NOTE! error values should not collide */
/* XXX Note KRB5_RC_BADNAME and KRB5_CONF_NOT_CONFIGURED are Solaris specific */
#define KRB5_RC_BADNAME (-1765328136L)
#define KRB5_CONF_NOT_CONFIGURED (-1765328135L)
#ifdef _KERNEL
/* XXX Note KRB5_KEF_ERROR and PKCS_ERR are Solaris specific */
#define KRB5_KEF_ERROR (-1765328134L)
#else
#define PKCS_ERR (-1765328134L)
#endif /* _KERNEL */
#define KRB5_DELTAT_BADFORMAT (-1765328133L)
#define KRB5_PLUGIN_NO_HANDLE (-1765328132L)
#define KRB5_PLUGIN_OP_NOTSUPP (-1765328131L)
/* SUNW17PACresync */
#define KRB5_ERR_INVALID_UTF8 (-1765328130L)
#define KRB5_ERR_FAST_REQUIRED (-1765328129L)
#define KRB5_LOCAL_ADDR_REQUIRED (-1765328128L)
#define KRB5_REMOTE_ADDR_REQUIRED (-1765328127L)
#define ERROR_TABLE_BASE_krb5 (-1765328384L)
/* for compatibility with older versions... */
#define krb5_err_base ERROR_TABLE_BASE_krb5
/*
* kdb5_err.h:
* This file is automatically generated; please do not edit it.
*/
#define KRB5_KDB_RCSID (-1780008448L)
#define KRB5_KDB_INUSE (-1780008447L)
#define KRB5_KDB_UK_SERROR (-1780008446L)
#define KRB5_KDB_UK_RERROR (-1780008445L)
#define KRB5_KDB_UNAUTH (-1780008444L)
#define KRB5_KDB_NOENTRY (-1780008443L)
#define KRB5_KDB_ILL_WILDCARD (-1780008442L)
#define KRB5_KDB_DB_INUSE (-1780008441L)
#define KRB5_KDB_DB_CHANGED (-1780008440L)
#define KRB5_KDB_TRUNCATED_RECORD (-1780008439L)
#define KRB5_KDB_RECURSIVELOCK (-1780008438L)
#define KRB5_KDB_NOTLOCKED (-1780008437L)
#define KRB5_KDB_BADLOCKMODE (-1780008436L)
#define KRB5_KDB_DBNOTINITED (-1780008435L)
#define KRB5_KDB_DBINITED (-1780008434L)
#define KRB5_KDB_ILLDIRECTION (-1780008433L)
#define KRB5_KDB_NOMASTERKEY (-1780008432L)
#define KRB5_KDB_BADMASTERKEY (-1780008431L)
#define KRB5_KDB_INVALIDKEYSIZE (-1780008430L)
#define KRB5_KDB_CANTREAD_STORED (-1780008429L)
#define KRB5_KDB_BADSTORED_MKEY (-1780008428L)
#define KRB5_KDB_CANTLOCK_DB (-1780008427L)
#define KRB5_KDB_DB_CORRUPT (-1780008426L)
#define KRB5_KDB_BAD_VERSION (-1780008425L)
#define KRB5_KDB_BAD_SALTTYPE (-1780008424L)
#define KRB5_KDB_BAD_ENCTYPE (-1780008423L)
#define KRB5_KDB_BAD_CREATEFLAGS (-1780008422L)
#define KRB5_KDB_NO_PERMITTED_KEY (-1780008421L)
#define KRB5_KDB_NO_MATCHING_KEY (-1780008420L)
/*
* Incremental propagation error codes
*/
#define KRB5_LOG_CONV (-1780008419L)
#define KRB5_LOG_UNSTABLE (-1780008418L)
#define KRB5_LOG_CORRUPT (-1780008417L)
#define KRB5_LOG_ERROR (-1780008416L)
#define KRB5_KDB_DBTYPE_NOTFOUND (-1780008415L)
#define KRB5_KDB_DBTYPE_NOSUP (-1780008414L)
#define KRB5_KDB_DBTYPE_INIT (-1780008413L)
#define KRB5_KDB_SERVER_INTERNAL_ERR (-1780008412L)
#define KRB5_KDB_ACCESS_ERROR (-1780008411L)
#define KRB5_KDB_INTERNAL_ERROR (-1780008410L)
#define KRB5_KDB_CONSTRAINT_VIOLATION (-1780008409L)
#define ERROR_TABLE_BASE_kdb5 (-1780008448L)
/* for compatibility with older versions... */
#define kdb5_err_base ERROR_TABLE_BASE_kdb5
/*
* kv5m_err.h:
* This file is automatically generated; please do not edit it.
*/
#define KV5M_NONE (-1760647424L)
#define KV5M_PRINCIPAL (-1760647423L)
#define KV5M_DATA (-1760647422L)
#define KV5M_KEYBLOCK (-1760647421L)
#define KV5M_CHECKSUM (-1760647420L)
#define KV5M_ENCRYPT_BLOCK (-1760647419L)
#define KV5M_ENC_DATA (-1760647418L)
#define KV5M_CRYPTOSYSTEM_ENTRY (-1760647417L)
#define KV5M_CS_TABLE_ENTRY (-1760647416L)
#define KV5M_CHECKSUM_ENTRY (-1760647415L)
#define KV5M_AUTHDATA (-1760647414L)
#define KV5M_TRANSITED (-1760647413L)
#define KV5M_ENC_TKT_PART (-1760647412L)
#define KV5M_TICKET (-1760647411L)
#define KV5M_AUTHENTICATOR (-1760647410L)
#define KV5M_TKT_AUTHENT (-1760647409L)
#define KV5M_CREDS (-1760647408L)
#define KV5M_LAST_REQ_ENTRY (-1760647407L)
#define KV5M_PA_DATA (-1760647406L)
#define KV5M_KDC_REQ (-1760647405L)
#define KV5M_ENC_KDC_REP_PART (-1760647404L)
#define KV5M_KDC_REP (-1760647403L)
#define KV5M_ERROR (-1760647402L)
#define KV5M_AP_REQ (-1760647401L)
#define KV5M_AP_REP (-1760647400L)
#define KV5M_AP_REP_ENC_PART (-1760647399L)
#define KV5M_RESPONSE (-1760647398L)
#define KV5M_SAFE (-1760647397L)
#define KV5M_PRIV (-1760647396L)
#define KV5M_PRIV_ENC_PART (-1760647395L)
#define KV5M_CRED (-1760647394L)
#define KV5M_CRED_INFO (-1760647393L)
#define KV5M_CRED_ENC_PART (-1760647392L)
#define KV5M_PWD_DATA (-1760647391L)
#define KV5M_ADDRESS (-1760647390L)
#define KV5M_KEYTAB_ENTRY (-1760647389L)
#define KV5M_CONTEXT (-1760647388L)
#define KV5M_OS_CONTEXT (-1760647387L)
#define KV5M_ALT_METHOD (-1760647386L)
#define KV5M_ETYPE_INFO_ENTRY (-1760647385L)
#define KV5M_DB_CONTEXT (-1760647384L)
#define KV5M_AUTH_CONTEXT (-1760647383L)
#define KV5M_KEYTAB (-1760647382L)
#define KV5M_RCACHE (-1760647381L)
#define KV5M_CCACHE (-1760647380L)
#define KV5M_PREAUTH_OPS (-1760647379L)
#define KV5M_SAM_CHALLENGE (-1760647378L)
#define KV5M_SAM_KEY (-1760647377L)
#define KV5M_ENC_SAM_RESPONSE_ENC (-1760647376L)
#define KV5M_ENC_SAM_RESPONSE_ENC_2 (-1760647374L)
#define KV5M_SAM_RESPONSE (-1760647373L)
#define KV5M_SAM_RESPONSE_2 (-1760647372L)
#define KV5M_PREDICTED_SAM_RESPONSE (-1760647371L)
#define KV5M_PASSWD_PHRASE_ELEMENT (-1760647370L)
#define KV5M_GSS_OID (-1760647369L)
#define KV5M_GSS_QUEUE (-1760647368L)
#define ERROR_TABLE_BASE_kv5m (-1760647424L)
/* for compatibility with older versions... */
#define kv5m_err_base ERROR_TABLE_BASE_kv5m
/*
* asn1_err.h:
* This file is automatically generated; please do not edit it.
*/
#define ASN1_BAD_TIMEFORMAT (1859794432L)
#define ASN1_MISSING_FIELD (1859794433L)
#define ASN1_MISPLACED_FIELD (1859794434L)
#define ASN1_TYPE_MISMATCH (1859794435L)
#define ASN1_OVERFLOW (1859794436L)
#define ASN1_OVERRUN (1859794437L)
#define ASN1_BAD_ID (1859794438L)
#define ASN1_BAD_LENGTH (1859794439L)
#define ASN1_BAD_FORMAT (1859794440L)
#define ASN1_PARSE_ERROR (1859794441L)
#define ASN1_BAD_GMTIME (1859794442L)
#define ASN1_MISMATCH_INDEF (1859794443L)
#define ASN1_MISSING_EOC (1859794444L)
#define ERROR_TABLE_BASE_asn1 (1859794432L)
/* for compatibility with older versions... */
#define asn1_err_base ERROR_TABLE_BASE_asn1
#endif /* _KRB5_H */
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* 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 "k5-int.h"
void krb5_old_encrypt_length
(const struct krb5_enc_provider *enc,
const struct krb5_hash_provider *hash,
size_t input, size_t *length);
krb5_error_code krb5_old_encrypt
(krb5_context context,
const struct krb5_enc_provider *enc,
const struct krb5_hash_provider *hash,
const krb5_keyblock *key, krb5_keyusage usage,
const krb5_data *ivec, const krb5_data *input,
krb5_data *output);
krb5_error_code krb5_old_decrypt
(krb5_context context,
const struct krb5_enc_provider *enc,
const struct krb5_hash_provider *hash,
const krb5_keyblock *key, krb5_keyusage usage,
const krb5_data *ivec, const krb5_data *input,
krb5_data *arg_output);
#ifndef _KERNEL
krb5_error_code krb5int_des_string_to_key
(krb5_context context,
const struct krb5_enc_provider *enc,
const krb5_data *string, const krb5_data *salt,
const krb5_data *params,
krb5_keyblock *key);
#endif /* _KERNEL */
/*
* 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 "k5-int.h"
void krb5_raw_encrypt_length
(const struct krb5_enc_provider *enc,
const struct krb5_hash_provider *hash,
size_t input, size_t *length);
krb5_error_code krb5_raw_encrypt
(krb5_context context,
const struct krb5_enc_provider *enc,
const struct krb5_hash_provider *hash,
const krb5_keyblock *key, krb5_keyusage usage,
const krb5_data *ivec, const krb5_data *input,
krb5_data *output);
krb5_error_code krb5_raw_decrypt
(krb5_context context,
const struct krb5_enc_provider *enc,
const struct krb5_hash_provider *hash,
const krb5_keyblock *key, krb5_keyusage usage,
const krb5_data *ivec, const krb5_data *input,
krb5_data *arg_output);
/*
* Copyright 2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* lib/crypto/md4/rsa-md4.h
*
* Copyright 1991 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.
*
*
* RSA MD4 header file, with Kerberos/STDC additions.
*/
#ifndef __KRB5_RSA_MD4_H__
#define __KRB5_RSA_MD4_H__
#ifdef unicos61
#include <sys/types.h>
#endif /* unicos61 */
/* 16 u_char's in the digest */
#define RSA_MD4_CKSUM_LENGTH 16
/* des blocksize is 8, so this works nicely... */
#define OLD_RSA_MD4_DES_CKSUM_LENGTH 16
#define NEW_RSA_MD4_DES_CKSUM_LENGTH 24
#define RSA_MD4_DES_CONFOUND_LENGTH 8
/*
**********************************************************************
** md4.h -- Header file for implementation of MD4 **
** RSA Data Security, Inc. MD4 Message Digest Algorithm **
** Created: 2/17/90 RLR **
** Revised: 12/27/90 SRD,AJ,BSK,JT Reference C version **
**********************************************************************
*/
/*
**********************************************************************
** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved. **
** **
** License to copy and use this software is granted provided that **
** it is identified as the "RSA Data Security, Inc. MD4 Message **
** Digest Algorithm" in all material mentioning or referencing this **
** software or this function. **
** **
** License is also granted to make and use derivative works **
** provided that such works are identified as "derived from the RSA **
** Data Security, Inc. MD4 Message Digest Algorithm" in all **
** material mentioning or referencing the derived work. **
** **
** RSA Data Security, Inc. makes no representations concerning **
** either the merchantability of this software or the suitability **
** of this software for any particular purpose. It is provided "as **
** is" without express or implied warranty of any kind. **
** **
** These notices must be retained in any copies of any part of this **
** documentation and/or software. **
**********************************************************************
*/
/* Data structure for MD4 (Message Digest) computation */
typedef struct {
krb5_ui_4 i[2]; /* number of _bits_ handled mod 2^64 */
krb5_ui_4 buf[4]; /* scratch buffer */
unsigned char in[64]; /* input buffer */
unsigned char digest[16]; /* actual digest after MD4Final call */
} krb5_MD4_CTX;
extern void krb5_MD4Init(krb5_MD4_CTX *);
extern void krb5_MD4Update(krb5_MD4_CTX *, const unsigned char *, unsigned int);
extern void krb5_MD4Final(krb5_MD4_CTX *);
/*
**********************************************************************
** End of md4.h **
******************************* (cut) ********************************
*/
#endif /* __KRB5_RSA_MD4_H__ */
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* lib/krb5/krb/copy_athctr.c
*
* Copyright 1990,1991 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.
*
*
* krb5_copy_authenticator()
*/
#include <k5-int.h>
krb5_error_code KRB5_CALLCONV
krb5_copy_authenticator(krb5_context context, const krb5_authenticator *authfrom, krb5_authenticator **authto)
{
krb5_error_code retval;
krb5_authenticator *tempto;
if (!(tempto = (krb5_authenticator *)MALLOC(sizeof(*tempto))))
return ENOMEM;
#ifdef HAVE_C_STRUCTURE_ASSIGNMENT
*tempto = *authfrom;
#else
(void) memcpy(tempto, authfrom, sizeof(krb5_authenticator));
#endif
retval = krb5_copy_principal(context, authfrom->client, &tempto->client);
if (retval) {
krb5_xfree_wrap(tempto, sizeof(*tempto));
return retval;
}
if (authfrom->checksum &&
(retval = krb5_copy_checksum(context, authfrom->checksum, &tempto->checksum))) {
krb5_free_principal(context, tempto->client);
krb5_xfree_wrap(tempto, sizeof(*tempto));
return retval;
}
if (authfrom->subkey) {
retval = krb5_copy_keyblock(context, authfrom->subkey, &tempto->subkey);
if (retval) {
krb5_xfree_wrap(tempto->subkey, sizeof(krb5_keyblock));
krb5_free_checksum(context, tempto->checksum);
krb5_free_principal(context, tempto->client);
krb5_xfree_wrap(tempto, sizeof(*tempto));
return retval;
}
}
if (authfrom->authorization_data) {
retval = krb5_copy_authdata(context, authfrom->authorization_data,
&tempto->authorization_data);
if (retval) {
krb5_xfree_wrap(tempto->subkey, sizeof(krb5_keyblock));
krb5_free_checksum(context, tempto->checksum);
krb5_free_principal(context, tempto->client);
krb5_free_authdata(context, tempto->authorization_data);
krb5_xfree_wrap(tempto, sizeof(*tempto));
return retval;
}
}
*authto = tempto;
return 0;
}
/*
* lib/krb5/krb/copy_auth.c
*
* Copyright 1990 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.
*
*
* krb5_copy_authdata()
*/
/*
* Copyright (c) 2006-2008, Novell, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * The copyright holder's name is not used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "k5-int.h"
static krb5_error_code
krb5_copy_authdatum(krb5_context context, const krb5_authdata *inad, krb5_authdata **outad)
{
krb5_authdata *tmpad;
if (!(tmpad = (krb5_authdata *)malloc(sizeof(*tmpad))))
return ENOMEM;
*tmpad = *inad;
if (!(tmpad->contents = (krb5_octet *)malloc(inad->length))) {
free(tmpad);
return ENOMEM;
}
(void) memcpy((char *)tmpad->contents, (char *)inad->contents, inad->length);
*outad = tmpad;
return 0;
}
/*
* Copy an authdata array, with fresh allocation.
*/
krb5_error_code KRB5_CALLCONV
krb5_merge_authdata(krb5_context context, krb5_authdata *const *inauthdat1, krb5_authdata * const *inauthdat2,
krb5_authdata ***outauthdat)
{
krb5_error_code retval;
krb5_authdata ** tempauthdat;
register unsigned int nelems = 0, nelems2 = 0;
*outauthdat = NULL;
if (!inauthdat1 && !inauthdat2) {
*outauthdat = 0;
return 0;
}
if (inauthdat1)
while (inauthdat1[nelems]) nelems++;
if (inauthdat2)
while (inauthdat2[nelems2]) nelems2++;
/* one more for a null terminated list */
if (!(tempauthdat = (krb5_authdata **) calloc(nelems+nelems2+1,
sizeof(*tempauthdat))))
return ENOMEM;
if (inauthdat1) {
for (nelems = 0; inauthdat1[nelems]; nelems++) {
retval = krb5_copy_authdatum(context, inauthdat1[nelems],
&tempauthdat[nelems]);
if (retval) {
krb5_free_authdata(context, tempauthdat);
return retval;
}
}
}
if (inauthdat2) {
for (nelems2 = 0; inauthdat2[nelems2]; nelems2++) {
retval = krb5_copy_authdatum(context, inauthdat2[nelems2],
&tempauthdat[nelems++]);
if (retval) {
krb5_free_authdata(context, tempauthdat);
return retval;
}
}
}
*outauthdat = tempauthdat;
return 0;
}
krb5_error_code KRB5_CALLCONV
krb5_copy_authdata(krb5_context context,
krb5_authdata *const *in_authdat, krb5_authdata ***out)
{
return krb5_merge_authdata(context, in_authdat, NULL, out);
}
krb5_error_code KRB5_CALLCONV
krb5_decode_authdata_container(krb5_context context,
krb5_authdatatype type,
const krb5_authdata *container,
krb5_authdata ***authdata)
{
krb5_error_code code;
krb5_data data;
*authdata = NULL;
if ((container->ad_type & AD_TYPE_FIELD_TYPE_MASK) != type)
return EINVAL;
data.length = container->length;
data.data = (char *)container->contents;
code = decode_krb5_authdata(&data, authdata);
if (code)
return code;
return 0;
}
krb5_error_code KRB5_CALLCONV
krb5_encode_authdata_container(krb5_context context,
krb5_authdatatype type,
krb5_authdata *const*authdata,
krb5_authdata ***container)
{
krb5_error_code code;
krb5_data *data;
krb5_authdata ad_datum;
krb5_authdata *ad_data[2];
*container = NULL;
code = encode_krb5_authdata((krb5_authdata * const *)authdata, &data);
if (code)
return code;
ad_datum.ad_type = type & AD_TYPE_FIELD_TYPE_MASK;
ad_datum.length = data->length;
ad_datum.contents = (unsigned char *)data->data;
ad_data[0] = &ad_datum;
ad_data[1] = NULL;
code = krb5_copy_authdata(context, ad_data, container);
krb5_free_data(context, data);
return code;
}
struct find_authdata_context {
krb5_authdata **out;
size_t space;
size_t length;
};
static krb5_error_code grow_find_authdata
(krb5_context context, struct find_authdata_context *fctx,
krb5_authdata *elem)
{
krb5_error_code retval = 0;
if (fctx->length == fctx->space) {
krb5_authdata **new;
if (fctx->space >= 256) {
krb5_set_error_message(context, ERANGE, "More than 256 authdata matched a query");
return ERANGE;
}
new = realloc(fctx->out,
sizeof (krb5_authdata *)*(2*fctx->space+1));
if (new == NULL)
return ENOMEM;
fctx->out = new;
fctx->space *=2;
}
fctx->out[fctx->length+1] = NULL;
retval = krb5_copy_authdatum(context, elem,
&fctx->out[fctx->length]);
if (retval == 0)
fctx->length++;
return retval;
}
static krb5_error_code find_authdata_1
(krb5_context context, krb5_authdata *const *in_authdat, krb5_authdatatype ad_type,
struct find_authdata_context *fctx)
{
int i = 0;
krb5_error_code retval=0;
for (i = 0; in_authdat[i]; i++) {
krb5_authdata *ad = in_authdat[i];
if (ad->ad_type == ad_type && retval ==0)
retval = grow_find_authdata(context, fctx, ad);
else switch (ad->ad_type) {
krb5_authdata **decoded_container;
case KRB5_AUTHDATA_IF_RELEVANT:
if (retval == 0)
retval = krb5_decode_authdata_container( context, ad->ad_type, ad, &decoded_container);
if (retval == 0) {
retval = find_authdata_1(context,
decoded_container, ad_type, fctx);
krb5_free_authdata(context, decoded_container);
}
break;
default:
break;
}
}
return retval;
}
krb5_error_code krb5int_find_authdata
(krb5_context context, krb5_authdata *const * ticket_authdata,
krb5_authdata * const *ap_req_authdata,
krb5_authdatatype ad_type,
krb5_authdata ***results)
{
krb5_error_code retval = 0;
struct find_authdata_context fctx;
fctx.length = 0;
fctx.space = 2;
fctx.out = calloc(fctx.space+1, sizeof (krb5_authdata *));
*results = NULL;
if (fctx.out == NULL)
return ENOMEM;
if (ticket_authdata)
retval = find_authdata_1( context, ticket_authdata, ad_type, &fctx);
if ((retval==0) && ap_req_authdata)
retval = find_authdata_1( context, ap_req_authdata, ad_type, &fctx);
if ((retval== 0) && fctx.length)
*results = fctx.out;
else krb5_free_authdata(context, fctx.out);
return retval;
}
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* lib/krb5/krb/copy_cksum.c
*
* Copyright 1990 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.
*
*
* krb5_copy_checksum()
*/
#include "k5-int.h"
/*ARGSUSED*/
krb5_error_code KRB5_CALLCONV
krb5_copy_checksum(krb5_context context, const krb5_checksum *ckfrom, krb5_checksum **ckto)
{
krb5_checksum *tempto;
if (!(tempto = (krb5_checksum *)MALLOC(sizeof(*tempto))))
return ENOMEM;
*tempto = *ckfrom;
if (!(tempto->contents =
(krb5_octet *)MALLOC(tempto->length))) {
krb5_xfree(tempto);
return ENOMEM;
}
(void) memcpy((char *) tempto->contents, (char *) ckfrom->contents,
ckfrom->length);
*ckto = tempto;
return 0;
}
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* lib/krb5/krb/copy_key.c
*
* Copyright 1990,1991 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.
*
*
* krb5_copy_keyblock()
*/
#include "k5-int.h"
/*
* krb5_copy_keyblock_data
*
* Utility for copying keyblock data structures safely.
* This assumes that the necessary storage areas are
* already allocated.
*/
krb5_error_code
krb5_copy_keyblock_data(krb5_context context,
const krb5_keyblock *from, krb5_keyblock *to)
{
krb5_error_code ret = 0;
/* If nothing to copy, return no error */
if (from == NULL || to == NULL)
return (0);
if ((to->contents == NULL || from->contents == NULL) &&
from->length > 0)
return (ENOMEM);
to->magic = from->magic;
to->enctype = from->enctype;
to->length = from->length;
to->dk_list = NULL;
if (from->length > 0)
(void) memcpy(to->contents, from->contents, from->length);
#ifdef _KERNEL
to->kef_mt = from->kef_mt;
to->kef_key.ck_data = NULL;
to->key_tmpl = NULL;
if ((ret = init_key_kef(context->kef_cipher_mt, to))) {
return (ret);
}
#else
/*
* Don't copy or try to initialize crypto framework
* data. This data gets initialized the first time it is
* used.
*/
to->hKey = CK_INVALID_HANDLE;
#endif /* _KERNEL */
return (ret);
}
/*
* Copy a keyblock, including alloc'ed storage.
*/
/*ARGSUSED*/
krb5_error_code KRB5_CALLCONV
krb5_copy_keyblock(context, from, to)
krb5_context context;
const krb5_keyblock *from;
krb5_keyblock **to;
{
krb5_keyblock *new_key;
krb5_error_code ret = 0;
if (!(new_key = (krb5_keyblock *) MALLOC(sizeof(krb5_keyblock))))
return (ENOMEM);
if (!(new_key->contents = (krb5_octet *)MALLOC(from->length))) {
FREE(new_key, sizeof(krb5_keyblock));
return (ENOMEM);
}
ret = krb5_copy_keyblock_data(context, from, new_key);
if (ret) {
krb5_free_keyblock(context, new_key);
return (ret);
}
*to = new_key;
return (ret);
}
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* lib/krb5/krb/copy_princ.c
*
* Copyright 1990 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.
*
*
* krb5_copy_principal()
*/
#include "k5-int.h"
/*
* Copy a principal structure, with fresh allocation.
*/
/*ARGSUSED*/
krb5_error_code KRB5_CALLCONV
krb5_copy_principal(krb5_context context, krb5_const_principal inprinc, krb5_principal *outprinc)
{
register krb5_principal tempprinc;
register int i, nelems;
tempprinc = (krb5_principal)MALLOC(sizeof(krb5_principal_data));
if (tempprinc == 0)
return ENOMEM;
*tempprinc = *inprinc;
nelems = (int) krb5_princ_size(context, inprinc);
tempprinc->data = MALLOC(nelems * sizeof(krb5_data));
if (tempprinc->data == 0) {
FREE((char *)tempprinc, sizeof(krb5_principal_data));
return ENOMEM;
}
for (i = 0; i < nelems; i++) {
unsigned int len = krb5_princ_component(context, inprinc, i)->length;
krb5_princ_component(context, tempprinc, i)->length = len;
/*
* Allocate one extra byte for trailing zero byte so string ops
* can be used on the components.
*/
if (len &&
((krb5_princ_component(context, tempprinc, i)->data =
MALLOC(len + 1)) == 0)) {
while (--i >= 0)
FREE(krb5_princ_component(context, tempprinc, i)->data,
krb5_princ_component(context, inprinc, i)->length + 1);
FREE (tempprinc->data, nelems * sizeof(krb5_data));
FREE (tempprinc,sizeof(krb5_principal_data));
return ENOMEM;
}
if (len)
(void) memcpy(krb5_princ_component(context, tempprinc, i)->data,
krb5_princ_component(context, inprinc, i)->data, len);
else
krb5_princ_component(context, tempprinc, i)->data = 0;
}
tempprinc->realm.length = inprinc->realm.length;
/*
* Allocate one extra byte for the realm name string terminator. The
* realm and principle component strings alway leave a null byte after
* 'length' bytes that needs to be malloc/freed.
*/
tempprinc->realm.data = MALLOC(tempprinc->realm.length + 1);
if (!tempprinc->realm.data) {
for (i = 0; i < nelems; i++)
FREE(krb5_princ_component(context, tempprinc, i)->data,
krb5_princ_component(context, inprinc, i)->length + 1);
FREE(tempprinc->data, nelems * sizeof(krb5_data));
FREE(tempprinc, sizeof(krb5_principal_data));
return ENOMEM;
}
memcpy(tempprinc->realm.data, inprinc->realm.data,
inprinc->realm.length);
tempprinc->realm.data[tempprinc->realm.length] = 0;
*outprinc = tempprinc;
return 0;
}
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* lib/krb5/krb/init_ctx.c
*
* Copyright 1994,1999,2000, 2002, 2003 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.
*
* krb5_init_contex()
*/
/*
* 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 "k5-int.h"
/*
* Solaris Kerberos: the code related to EF/pkcs11 and fork safety are mods Sun
* has made to the MIT code.
*/
#ifndef _KERNEL
#include <ctype.h>
pid_t __krb5_current_pid; /* fork safety: contains the current process ID */
#endif
#ifndef _KERNEL
#include <krb5_libinit.h>
#endif
/* The des-mdX entries are last for now, because it's easy to
configure KDCs to issue TGTs with des-mdX keys and then not accept
them. This'll be fixed, but for better compatibility, let's prefer
des-crc for now. */
/*
* Solaris Kerberos:
* Added arcfour-hmac-md5-exp as default enc type.
* Changed des3-hmac-sha1 to des3-cbc-sha1-kd, as specified in RFC3961.
*/
#define DEFAULT_ETYPE_LIST \
"aes256-cts-hmac-sha1-96 " \
"aes128-cts-hmac-sha1-96 " \
"des3-cbc-sha1-kd " \
"arcfour-hmac-md5 " \
"arcfour-hmac-md5-exp " \
"des-cbc-md5 " \
"des-cbc-crc"
/* The only functions that are needed from this file when in kernel are
* krb5_init_context and krb5_free_context.
* In krb5_init_context we need only os_init_context since we don'it need the
* profile info unless we do init/accept in kernel. Currently only mport,
* delete , sign/verify, wrap/unwrap routines are ported to the kernel.
*/
#if (defined(_WIN32))
extern krb5_error_code krb5_vercheck();
extern void krb5_win_ccdll_load(krb5_context context);
#endif
static krb5_error_code init_common (krb5_context *, krb5_boolean, krb5_boolean);
krb5_error_code KRB5_CALLCONV
krb5_init_context(krb5_context *context)
{
return init_common (context, FALSE, FALSE);
}
krb5_error_code KRB5_CALLCONV
krb5_init_secure_context(krb5_context *context)
{
#if 0 /* Solaris Kerberos */
/* This is to make gcc -Wall happy */
if(0) krb5_brand[0] = krb5_brand[0];
#endif
return init_common (context, TRUE, FALSE);
}
#ifndef _KERNEL
krb5_error_code
krb5int_init_context_kdc(krb5_context *context)
{
return init_common (context, FALSE, TRUE);
}
/* Solaris Kerberos */
krb5_error_code
krb5_open_pkcs11_session(CK_SESSION_HANDLE *hSession)
{
krb5_error_code retval = 0;
CK_RV rv;
CK_SLOT_ID_PTR slotlist = NULL_PTR;
CK_ULONG slotcount;
CK_ULONG i;
/* List of all Slots */
rv = C_GetSlotList(FALSE, NULL_PTR, &slotcount);
if (rv != CKR_OK) {
KRB5_LOG(KRB5_ERR, "C_GetSlotList failed with 0x%x.", rv);
retval = PKCS_ERR;
goto cleanup;
}
if (slotcount == 0) {
KRB5_LOG0(KRB5_ERR, "No slot is found in PKCS11.");
retval = PKCS_ERR;
goto cleanup;
}
slotlist = (CK_SLOT_ID_PTR)malloc(slotcount * sizeof(CK_SLOT_ID));
if (slotlist == NULL) {
KRB5_LOG0(KRB5_ERR, "malloc failed for slotcount.");
retval = PKCS_ERR;
goto cleanup;
}
rv = C_GetSlotList(FALSE, slotlist, &slotcount);
if (rv != CKR_OK) {
KRB5_LOG(KRB5_ERR, "C_GetSlotList failed with 0x%x", rv);
retval = PKCS_ERR;
goto cleanup;
}
for (i = 0; i < slotcount; i++) {
if (slot_supports_krb5(slotlist + i))
break;
}
if (i == slotcount){
KRB5_LOG0(KRB5_ERR, "Could not find slot which supports "
"Kerberos");
retval = PKCS_ERR;
goto cleanup;
}
rv = C_OpenSession(slotlist[i], CKF_SERIAL_SESSION, NULL_PTR, NULL_PTR,
hSession);
if (rv != CKR_OK) {
retval = PKCS_ERR;
}
cleanup:
if (slotlist != NULL)
free(slotlist);
return(retval);
}
/*
* krb5_reinit_ef_handle()
*
* deal with fork safety issue regarding the krb ctx and the pkcs11 hSession
* field. This function is called if it is determined that the krb ctx hSession
* is being accessed in a child process after a fork(). This function
* re-initilizes the pkcs11 session and returns the session handle.
*/
CK_SESSION_HANDLE
krb5_reinit_ef_handle(krb5_context ctx)
{
ctx->cryptoki_initialized = FALSE;
if (krb5_init_ef_handle(ctx) != 0) {
/*
* krb5_free_ef_handle() not needed here -- we assume that an equivalent
* of C_Finalize() was done in the child-side of the fork(), so all EF
* resources in this context will be invalid.
*/
return(CK_INVALID_HANDLE);
}
/* reset the ctx pid since we're in a new process (child) */
ctx->pid = __krb5_current_pid;
/* If the RC4 handles were initialized, reset them here */
if (ctx->arcfour_ctx.initialized) {
krb5_error_code ret;
ret = krb5_open_pkcs11_session(&ctx->arcfour_ctx.eSession);
if (ret) {
ctx->arcfour_ctx.initialized = 0;
ctx->arcfour_ctx.eSession = CK_INVALID_HANDLE;
C_CloseSession(ctx->hSession);
ctx->hSession = CK_INVALID_HANDLE;
}
ret = krb5_open_pkcs11_session(&ctx->arcfour_ctx.dSession);
if (ret) {
ctx->arcfour_ctx.initialized = 0;
ctx->arcfour_ctx.eSession = CK_INVALID_HANDLE;
ctx->arcfour_ctx.dSession = CK_INVALID_HANDLE;
C_CloseSession(ctx->hSession);
ctx->hSession = CK_INVALID_HANDLE;
}
}
/*
* It is safe for this function to access ctx->hSession directly. Do
* NOT use the krb_ctx_hSession() here.
*/
return(ctx->hSession);
}
/*
* krb5_pthread_atfork_child_handler() sets a global that indicates the current
* PID. This is an optimization to keep getpid() from being called a zillion
* times.
*/
void
krb5_pthread_atfork_child_handler()
{
/*
* __krb5_current_pid should always be set to current process ID, see the
* definition of krb_ctx_hSession() for more info
*/
__krb5_current_pid = getpid();
}
/*
* krb5_ld_init() contains code that will be executed at load time (via the
* ld -zinitarray directive).
*/
void
krb5_ld_init()
{
/*
* fork safety: __krb5_current_pid should always be set to current process
* ID, see the definition of krb_ctx_hSession() for more info
*/
__krb5_current_pid = getpid();
/*
* The child handler below will help reduce the number of times getpid() is
* called by updating a global PID var. with the current PID whenever a fork
* occurrs.
*/
(void) pthread_atfork(NULL, NULL, krb5_pthread_atfork_child_handler);
}
#endif /* !_KERNEL */
krb5_error_code
krb5_init_ef_handle(krb5_context ctx)
{
krb5_error_code retval = 0;
#ifndef _KERNEL
CK_RV rv = C_Initialize(NULL_PTR);
if ((rv != CKR_OK) && (rv != CKR_CRYPTOKI_ALREADY_INITIALIZED)) {
KRB5_LOG(KRB5_ERR, "C_Initialize failed with 0x%x.", rv);
return (PKCS_ERR);
}
/*
* It is safe for this function to access ctx->hSession directly. Do
* NOT use the krb_ctx_hSession() here.
*/
retval = krb5_open_pkcs11_session(&ctx->hSession);
if (retval != 0)
return (retval);
ctx->cryptoki_initialized = TRUE;
#else /* ! _KERNEL */
ctx->kef_cipher_mt = CRYPTO_MECH_INVALID;
ctx->kef_hash_mt = CRYPTO_MECH_INVALID;
ctx->kef_cksum_mt = CRYPTO_MECH_INVALID;
setup_kef_keytypes();
setup_kef_cksumtypes();
#endif /* ! _KERNEL */
return(retval);
}
#ifndef _KERNEL
krb5_error_code
krb5_free_ef_handle(krb5_context ctx)
{
/*
* fork safety: Don't free any PKCS state if we've forked since
* allocating the pkcs handles.
*/
if (ctx->cryptoki_initialized == TRUE &&
ctx->pid == __krb5_current_pid) {
/*
* It is safe for this function to access ctx->hSession
* directly. Do NOT use the krb_ctx_hSession() here.
*/
if (ctx->hSession) {
C_CloseSession(ctx->hSession);
ctx->hSession = 0;
}
if (ctx->arcfour_ctx.dKey) {
C_DestroyObject(ctx->arcfour_ctx.dSession,
ctx->arcfour_ctx.dKey);
ctx->arcfour_ctx.dKey = 0;
}
if (ctx->arcfour_ctx.eKey) {
C_DestroyObject(ctx->arcfour_ctx.eSession,
ctx->arcfour_ctx.eKey);
ctx->arcfour_ctx.eKey = 0;
}
if (ctx->arcfour_ctx.eSession) {
C_CloseSession(ctx->arcfour_ctx.eSession);
ctx->arcfour_ctx.eSession = 0;
}
if (ctx->arcfour_ctx.dSession) {
C_CloseSession(ctx->arcfour_ctx.dSession);
ctx->arcfour_ctx.eSession = 0;
}
ctx->arcfour_ctx.initialized = 0;
ctx->cryptoki_initialized = FALSE;
}
return(0);
}
#endif /* !_KERNEL */
static krb5_error_code
init_common (krb5_context *context, krb5_boolean secure, krb5_boolean kdc)
{
krb5_context ctx = 0;
krb5_error_code retval;
#ifndef _KERNEL
struct {
krb5_int32 now, now_usec;
long pid;
} seed_data;
krb5_data seed;
int tmp;
/* Solaris Kerberos */
#if 0
/* Verify some assumptions. If the assumptions hold and the
compiler is optimizing, this should result in no code being
executed. If we're guessing "unsigned long long" instead
of using uint64_t, the possibility does exist that we're
wrong. */
{
krb5_ui_8 i64;
assert(sizeof(i64) == 8);
i64 = 0, i64--, i64 >>= 62;
assert(i64 == 3);
i64 = 1, i64 <<= 31, i64 <<= 31, i64 <<= 1;
assert(i64 != 0);
i64 <<= 1;
assert(i64 == 0);
}
#endif
retval = krb5int_initialize_library();
if (retval)
return retval;
#endif
#if (defined(_WIN32))
/*
* Load the krbcc32.dll if necessary. We do this here so that
* we know to use API: later on during initialization.
* The context being NULL is ok.
*/
krb5_win_ccdll_load(ctx);
/*
* krb5_vercheck() is defined in win_glue.c, and this is
* where we handle the timebomb and version server checks.
*/
retval = krb5_vercheck();
if (retval)
return retval;
#endif
*context = 0;
ctx = MALLOC(sizeof(struct _krb5_context));
if (!ctx)
return ENOMEM;
(void) memset(ctx, 0, sizeof(struct _krb5_context));
ctx->magic = KV5M_CONTEXT;
ctx->profile_secure = secure;
if ((retval = krb5_os_init_context(ctx, kdc)))
goto cleanup;
/*
* Initialize the EF handle, its needed before doing
* the random seed.
*/
if ((retval = krb5_init_ef_handle(ctx)))
goto cleanup;
#ifndef _KERNEL
/* fork safety: set pid to current process ID for later checking */
ctx->pid = __krb5_current_pid;
/* Set the default encryption types, possible defined in krb5/conf */
if ((retval = krb5_set_default_in_tkt_ktypes(ctx, NULL)))
goto cleanup;
if ((retval = krb5_set_default_tgs_ktypes(ctx, NULL)))
goto cleanup;
if (ctx->tgs_ktype_count != 0) {
ctx->conf_tgs_ktypes = MALLOC(ctx->tgs_ktype_count *
sizeof(krb5_enctype));
if (ctx->conf_tgs_ktypes == NULL)
goto cleanup;
(void) memcpy(ctx->conf_tgs_ktypes, ctx->tgs_ktypes,
sizeof(krb5_enctype) * ctx->tgs_ktype_count);
}
ctx->conf_tgs_ktypes_count = ctx->tgs_ktype_count;
/* initialize the prng (not well, but passable) */
if ((retval = krb5_crypto_us_timeofday(&seed_data.now, &seed_data.now_usec)))
goto cleanup;
seed_data.pid = getpid ();
seed.length = sizeof(seed_data);
seed.data = (char *) &seed_data;
if ((retval = krb5_c_random_seed(ctx, &seed)))
/*
* Solaris Kerberos: we use /dev/urandom, which is
* automatically seeded, so its OK if this fails.
*/
retval = 0;
ctx->default_realm = 0;
profile_get_integer(ctx->profile, "libdefaults", "clockskew",
0, 5 * 60, &tmp);
ctx->clockskew = tmp;
#if 0
/* Default ticket lifetime is currently not supported */
profile_get_integer(ctx->profile, "libdefaults", "tkt_lifetime",
0, 10 * 60 * 60, &tmp);
ctx->tkt_lifetime = tmp;
#endif
/* DCE 1.1 and below only support CKSUMTYPE_RSA_MD4 (2) */
/* DCE add kdc_req_checksum_type = 2 to krb5.conf */
profile_get_integer(ctx->profile, "libdefaults",
"kdc_req_checksum_type", 0, CKSUMTYPE_RSA_MD5,
&tmp);
ctx->kdc_req_sumtype = tmp;
profile_get_integer(ctx->profile, "libdefaults",
"ap_req_checksum_type", 0, CKSUMTYPE_RSA_MD5,
&tmp);
ctx->default_ap_req_sumtype = tmp;
profile_get_integer(ctx->profile, "libdefaults",
"safe_checksum_type", 0,
CKSUMTYPE_RSA_MD5_DES, &tmp);
ctx->default_safe_sumtype = tmp;
profile_get_integer(ctx->profile, "libdefaults",
"kdc_default_options", 0,
KDC_OPT_RENEWABLE_OK, &tmp);
ctx->kdc_default_options = tmp;
#define DEFAULT_KDC_TIMESYNC 1
profile_get_integer(ctx->profile, "libdefaults",
"kdc_timesync", 0, DEFAULT_KDC_TIMESYNC,
&tmp);
ctx->library_options = tmp ? KRB5_LIBOPT_SYNC_KDCTIME : 0;
/*
* We use a default file credentials cache of 3. See
* lib/krb5/krb/ccache/file/fcc.h for a description of the
* credentials cache types.
*
* Note: DCE 1.0.3a only supports a cache type of 1
* DCE 1.1 supports a cache type of 2.
*/
#define DEFAULT_CCACHE_TYPE 4
profile_get_integer(ctx->profile, "libdefaults", "ccache_type",
0, DEFAULT_CCACHE_TYPE, &tmp);
ctx->fcc_default_format = tmp + 0x0500;
ctx->scc_default_format = tmp + 0x0500;
ctx->prompt_types = 0;
ctx->use_conf_ktypes = 0;
ctx->udp_pref_limit = -1;
#endif /* !_KERNEL */
*context = ctx;
return 0;
cleanup:
krb5_free_context(ctx);
return retval;
}
void KRB5_CALLCONV
krb5_free_context(krb5_context ctx)
{
KRB5_LOG0(KRB5_INFO,"krb5_free_context() start");
#ifndef _KERNEL
krb5_free_ef_handle(ctx);
if (ctx->conf_tgs_ktypes) {
FREE(ctx->conf_tgs_ktypes, sizeof(krb5_enctype) *(ctx->conf_tgs_ktypes_count));
ctx->conf_tgs_ktypes = 0;
ctx->conf_tgs_ktypes_count = 0;
}
krb5_clear_error_message(ctx);
#endif
krb5_os_free_context(ctx);
if (ctx->in_tkt_ktypes) {
FREE(ctx->in_tkt_ktypes, sizeof(krb5_enctype) *(ctx->in_tkt_ktype_count+1) );
ctx->in_tkt_ktypes = 0;
}
if (ctx->tgs_ktypes) {
FREE(ctx->tgs_ktypes, sizeof(krb5_enctype) *(ctx->tgs_ktype_count+1));
ctx->tgs_ktypes = 0;
}
if (ctx->default_realm) {
FREE(ctx->default_realm, strlen(ctx->default_realm) + 1);
ctx->default_realm = 0;
}
if (ctx->ser_ctx_count && ctx->ser_ctx) {
FREE(ctx->ser_ctx,sizeof(krb5_ser_entry) * (ctx->ser_ctx_count) );
ctx->ser_ctx = 0;
ctx->ser_ctx_count = 0;
}
ctx->magic = 0;
FREE(ctx, sizeof(struct _krb5_context));
}
#ifndef _KERNEL
/*
* Set the desired default ktypes, making sure they are valid.
*/
krb5_error_code
krb5_set_default_in_tkt_ktypes(krb5_context context, const krb5_enctype *ktypes)
{
krb5_enctype * new_ktypes;
int i;
if (ktypes) {
for (i = 0; ktypes[i]; i++) {
if (!krb5_c_valid_enctype(ktypes[i]))
return KRB5_PROG_ETYPE_NOSUPP;
}
/* Now copy the default ktypes into the context pointer */
if ((new_ktypes = (krb5_enctype *)malloc(sizeof(krb5_enctype) * i)))
(void) memcpy(new_ktypes, ktypes, sizeof(krb5_enctype) * i);
else
return ENOMEM;
} else {
i = 0;
new_ktypes = 0;
}
if (context->in_tkt_ktypes)
free(context->in_tkt_ktypes);
context->in_tkt_ktypes = new_ktypes;
context->in_tkt_ktype_count = i;
return 0;
}
static krb5_error_code
get_profile_etype_list(krb5_context context, krb5_enctype **ktypes, char *profstr,
unsigned int ctx_count, krb5_enctype *ctx_list)
{
krb5_enctype *old_ktypes = NULL;
if (ctx_count) {
/* application-set defaults */
if ((old_ktypes =
(krb5_enctype *)malloc(sizeof(krb5_enctype) *
(ctx_count + 1)))) {
(void) memcpy(old_ktypes, ctx_list,
sizeof(krb5_enctype) * ctx_count);
old_ktypes[ctx_count] = 0;
} else {
return ENOMEM;
}
} else {
/*
XXX - For now, we only support libdefaults
Perhaps this should be extended to allow for per-host / per-realm
session key types.
*/
char *retval = NULL;
char *sp, *ep;
int j, checked_enctypes, count;
krb5_error_code code;
code = profile_get_string(context->profile, "libdefaults", profstr,
NULL, DEFAULT_ETYPE_LIST, &retval);
if (code)
return code;
if (!retval) /* SUNW14resync - just in case */
return PROF_EINVAL; /* XXX */
count = 0;
sp = retval;
while (*sp) {
for (ep = sp; *ep && (*ep != ',') && !isspace((int) (*ep)); ep++)
;
if (*ep) {
*ep++ = '\0';
while (isspace((int) (*ep)) || *ep == ',')
*ep++ = '\0';
}
count++;
sp = ep;
}
if ((old_ktypes =
(krb5_enctype *)malloc(sizeof(krb5_enctype) * (count + 1))) ==
(krb5_enctype *) NULL)
return ENOMEM;
sp = retval;
j = checked_enctypes = 0;
/*CONSTCOND*/
while (TRUE) {
checked_enctypes++;
if (krb5_string_to_enctype(sp, &old_ktypes[j]))
old_ktypes[j] = (unsigned int)ENCTYPE_UNKNOWN;
/*
* If 'null' has been specified as a tkt_enctype in
* krb5.conf, we need to assign an ENCTYPE_UNKNOWN
* value to the corresponding old_ktypes[j] entry.
*/
if (old_ktypes[j] == (unsigned int)ENCTYPE_NULL)
old_ktypes[j] = (unsigned int)ENCTYPE_UNKNOWN;
/* Only include known/valid enctypes in the final list */
if (old_ktypes[j] != ENCTYPE_UNKNOWN) {
j++;
}
/* If we checked all the enctypes, we are done */
if (checked_enctypes == count) {
break;
}
/* skip to next token */
while (*sp) sp++;
while (! *sp) sp++;
}
old_ktypes[j] = (krb5_enctype) 0;
profile_release_string(retval);
}
if (old_ktypes[0] == 0) {
free (old_ktypes);
*ktypes = 0;
return KRB5_CONFIG_ETYPE_NOSUPP;
}
*ktypes = old_ktypes;
return 0;
}
krb5_error_code
krb5_get_default_in_tkt_ktypes(krb5_context context, krb5_enctype **ktypes)
{
return(get_profile_etype_list(context, ktypes, "default_tkt_enctypes",
context->in_tkt_ktype_count,
context->in_tkt_ktypes));
}
krb5_error_code KRB5_CALLCONV
krb5_set_default_tgs_enctypes (krb5_context context, const krb5_enctype *ktypes)
{
krb5_enctype * new_ktypes;
int i;
if (ktypes) {
for (i = 0; ktypes[i]; i++) {
if (!krb5_c_valid_enctype(ktypes[i]))
return KRB5_PROG_ETYPE_NOSUPP;
}
/* Now copy the default ktypes into the context pointer */
if ((new_ktypes = (krb5_enctype *)malloc(sizeof(krb5_enctype) * i)))
(void) memcpy(new_ktypes, ktypes, sizeof(krb5_enctype) * i);
else
return ENOMEM;
} else {
i = 0;
new_ktypes = (krb5_enctype *)NULL;
}
if (context->tgs_ktypes)
krb5_free_ktypes(context, context->tgs_ktypes);
context->tgs_ktypes = new_ktypes;
context->tgs_ktype_count = i;
return 0;
}
krb5_error_code krb5_set_default_tgs_ktypes
(krb5_context context, const krb5_enctype *etypes)
{
return (krb5_set_default_tgs_enctypes (context, etypes));
}
/*ARGSUSED*/
void
KRB5_CALLCONV
krb5_free_ktypes (krb5_context context, krb5_enctype *val)
{
free (val);
}
/*ARGSUSED*/
krb5_error_code
KRB5_CALLCONV
krb5_get_tgs_ktypes(krb5_context context, krb5_const_principal princ, krb5_enctype **ktypes)
{
if (context->use_conf_ktypes)
/* This one is set *only* by reading the config file; it's not
set by the application. */
return(get_profile_etype_list(context, ktypes, "default_tgs_enctypes",
context->conf_tgs_ktypes_count,
context->conf_tgs_ktypes));
else
return(get_profile_etype_list(context, ktypes, "default_tgs_enctypes",
context->tgs_ktype_count,
context->tgs_ktypes));
}
krb5_error_code
krb5_get_permitted_enctypes(krb5_context context, krb5_enctype **ktypes)
{
return(get_profile_etype_list(context, ktypes, "permitted_enctypes",
context->tgs_ktype_count,
context->tgs_ktypes));
}
krb5_boolean
krb5_is_permitted_enctype(krb5_context context, krb5_enctype etype)
{
krb5_enctype *list, *ptr;
krb5_boolean ret;
if (krb5_get_permitted_enctypes(context, &list))
return(0);
ret = 0;
for (ptr = list; *ptr; ptr++)
if (*ptr == etype)
ret = 1;
krb5_free_ktypes (context, list);
return(ret);
}
static krb5_error_code
copy_ktypes(krb5_context ctx,
unsigned int nktypes,
krb5_enctype *oldktypes,
krb5_enctype **newktypes)
{
unsigned int i;
*newktypes = NULL;
if (!nktypes)
return 0;
*newktypes = MALLOC(nktypes * sizeof(krb5_enctype));
if (*newktypes == NULL)
return ENOMEM;
for (i = 0; i < nktypes; i++)
(*newktypes)[i] = oldktypes[i];
return 0;
}
krb5_error_code KRB5_CALLCONV
krb5_copy_context(krb5_context ctx, krb5_context *nctx_out)
{
krb5_error_code ret;
krb5_context nctx;
*nctx_out = NULL;
if (ctx == NULL)
return EINVAL; /* XXX */
nctx = MALLOC(sizeof(*nctx));
if (nctx == NULL)
return ENOMEM;
*nctx = *ctx;
nctx->in_tkt_ktypes = NULL;
nctx->in_tkt_ktype_count = 0;
nctx->tgs_ktypes = NULL;
nctx->tgs_ktype_count = 0;
nctx->default_realm = NULL;
nctx->profile = NULL;
nctx->db_context = NULL;
nctx->ser_ctx_count = 0;
nctx->ser_ctx = NULL;
nctx->prompt_types = NULL;
nctx->os_context->default_ccname = NULL;
memset(&nctx->preauth_plugins, 0, sizeof(nctx->preauth_plugins));
nctx->preauth_context = NULL;
memset(&nctx->libkrb5_plugins, 0, sizeof(nctx->libkrb5_plugins));
nctx->vtbl = NULL;
nctx->locate_fptrs = NULL;
memset(&nctx->err, 0, sizeof(nctx->err));
ret = copy_ktypes(nctx, ctx->in_tkt_ktype_count,
ctx->in_tkt_ktypes, &nctx->in_tkt_ktypes);
if (ret)
goto errout;
nctx->in_tkt_ktype_count = ctx->in_tkt_ktype_count;
ret = copy_ktypes(nctx, ctx->tgs_ktype_count,
ctx->tgs_ktypes, &nctx->in_tkt_ktypes);
if (ret)
goto errout;
nctx->tgs_ktype_count = ctx->tgs_ktype_count;
if (ctx->os_context->default_ccname != NULL) {
nctx->os_context->default_ccname =
strdup(ctx->os_context->default_ccname);
if (nctx->os_context->default_ccname == NULL) {
ret = ENOMEM;
goto errout;
}
}
ret = krb5_get_profile(ctx, &nctx->profile);
if (ret)
goto errout;
errout:
if (ret) {
krb5_free_context(nctx);
} else {
*nctx_out = nctx;
}
return ret;
}
#endif /* !KERNEL */
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright 1990-1998 by the Massachusetts Institute of Technology.
*
* 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.
*
*
* krb5_free_address()
*/
#include "k5-int.h"
static void cleanup_dk_list(krb5_context, krb5_keyblock *);
/* ARGSUSED */
void KRB5_CALLCONV
krb5_free_address(krb5_context context, krb5_address *val)
{
if (val->contents)
krb5_xfree_wrap(val->contents, val->length);
krb5_xfree_wrap(val, sizeof(krb5_address));
}
#ifndef _KERNEL
void KRB5_CALLCONV
krb5_free_addresses(krb5_context context, krb5_address **val)
{
register krb5_address **temp;
for (temp = val; *temp; temp++) {
if ((*temp)->contents)
krb5_xfree((*temp)->contents);
krb5_xfree(*temp);
}
krb5_xfree(val);
}
void KRB5_CALLCONV
krb5_free_ap_rep(krb5_context context, register krb5_ap_rep *val)
{
if (val->enc_part.ciphertext.data) {
krb5_xfree(val->enc_part.ciphertext.data);
val->enc_part.ciphertext.data = 0;
}
krb5_xfree(val);
}
void KRB5_CALLCONV
krb5_free_ap_req(krb5_context context, register krb5_ap_req *val)
{
if (val->ticket) {
krb5_free_ticket(context, val->ticket);
val->ticket = 0;
}
if (val->authenticator.ciphertext.data) {
krb5_xfree(val->authenticator.ciphertext.data);
val->authenticator.ciphertext.data = 0;
}
krb5_xfree(val);
}
void KRB5_CALLCONV
krb5_free_ap_rep_enc_part(krb5_context context, krb5_ap_rep_enc_part *val)
{
if (val->subkey)
krb5_free_keyblock(context, val->subkey);
krb5_xfree(val);
}
#endif /* !_KERNEL */
void KRB5_CALLCONV
krb5_free_authenticator_contents(krb5_context context, krb5_authenticator *val)
{
if (val->checksum) {
krb5_free_checksum(context, val->checksum);
val->checksum = 0;
}
if (val->client) {
krb5_free_principal(context, val->client);
val->client = 0;
}
if (val->subkey) {
krb5_free_keyblock(context, val->subkey);
val->subkey = 0;
}
if (val->authorization_data) {
krb5_free_authdata(context, val->authorization_data);
val->authorization_data = 0;
}
}
/* ARGSUSED */
void KRB5_CALLCONV
krb5_free_authdata(krb5_context context, krb5_authdata **val)
{
register krb5_authdata **temp;
for (temp = val; *temp; temp++) {
if ((*temp)->contents)
krb5_xfree_wrap((*temp)->contents, (*temp)->length);
krb5_xfree_wrap(*temp, sizeof(krb5_authdata));
}
/* Note val points to an array of pointers and (++temp - val) is # of bytes
* in that array.
*/
krb5_xfree_wrap(val, (++temp - val));
}
void KRB5_CALLCONV
krb5_free_authenticator(krb5_context context, krb5_authenticator *val)
{
krb5_free_authenticator_contents(context, val);
krb5_xfree_wrap(val, sizeof(krb5_authenticator));
}
void KRB5_CALLCONV
krb5_free_checksum(krb5_context context, register krb5_checksum *val)
{
krb5_free_checksum_contents(context, val);
krb5_xfree_wrap(val, sizeof(krb5_checksum));
}
/* ARGSUSED */
void KRB5_CALLCONV
krb5_free_checksum_contents(krb5_context context, register krb5_checksum *val)
{
if (val->contents) {
krb5_xfree_wrap(val->contents, val->length);
val->length = 0;
val->contents = 0;
}
}
#ifndef _KERNEL
void KRB5_CALLCONV
krb5_free_cred(krb5_context context, register krb5_cred *val)
{
if (val->tickets) {
krb5_free_tickets(context, val->tickets);
val->tickets = 0;
}
if (val->enc_part.ciphertext.data) {
krb5_xfree(val->enc_part.ciphertext.data);
val->enc_part.ciphertext.data = 0;
}
krb5_xfree(val);
}
/*
* krb5_free_cred_contents zeros out the session key, and then frees
* the credentials structures
*/
void KRB5_CALLCONV
krb5_free_cred_contents(krb5_context context, krb5_creds *val)
{
if (val->client) {
krb5_free_principal(context, val->client);
val->client = 0;
}
if (val->server) {
krb5_free_principal(context, val->server);
val->server = 0;
}
krb5_free_keyblock_contents(context, &val->keyblock);
if (val->ticket.data) {
krb5_xfree(val->ticket.data);
val->ticket.data = 0;
}
if (val->second_ticket.data) {
krb5_xfree(val->second_ticket.data);
val->second_ticket.data = 0;
}
if (val->addresses) {
krb5_free_addresses(context, val->addresses);
val->addresses = 0;
}
if (val->authdata) {
krb5_free_authdata(context, val->authdata);
val->authdata = 0;
}
}
void KRB5_CALLCONV
krb5_free_cred_enc_part(krb5_context context, register krb5_cred_enc_part *val)
{
register krb5_cred_info **temp;
if (val->r_address) {
krb5_free_address(context, val->r_address);
val->r_address = 0;
}
if (val->s_address) {
krb5_free_address(context, val->s_address);
val->s_address = 0;
}
if (val->ticket_info) {
for (temp = val->ticket_info; *temp; temp++) {
if ((*temp)->session)
krb5_free_keyblock(context, (*temp)->session);
if ((*temp)->client)
krb5_free_principal(context, (*temp)->client);
if ((*temp)->server)
krb5_free_principal(context, (*temp)->server);
if ((*temp)->caddrs)
krb5_free_addresses(context, (*temp)->caddrs);
krb5_xfree((*temp));
}
krb5_xfree(val->ticket_info);
val->ticket_info = 0;
}
}
void KRB5_CALLCONV
krb5_free_creds(krb5_context context, krb5_creds *val)
{
krb5_free_cred_contents(context, val);
krb5_xfree(val);
}
/* ARGSUSED */
void KRB5_CALLCONV
krb5_free_data(krb5_context context, krb5_data *val)
{
if (val->data) {
krb5_xfree(val->data);
val->data = 0;
}
krb5_xfree(val);
}
#endif /* !_KERNEL */
/* ARGSUSED */
void KRB5_CALLCONV
krb5_free_data_contents(krb5_context context, krb5_data *val)
{
if (val->data) {
krb5_xfree_wrap(val->data, val->length);
val->length = 0;
val->data = 0;
}
}
#ifndef _KERNEL
void krb5_free_etype_info(krb5_context context, krb5_etype_info info)
{
int i;
for(i=0; info[i] != NULL; i++) {
if (info[i]->salt)
free(info[i]->salt);
krb5_free_data_contents(context, &info[i]->s2kparams);
free(info[i]);
}
free(info);
}
void KRB5_CALLCONV
krb5_free_enc_kdc_rep_part(krb5_context context, register krb5_enc_kdc_rep_part *val)
{
if (val->session)
krb5_free_keyblock(context, val->session);
if (val->last_req)
krb5_free_last_req(context, val->last_req);
if (val->server)
krb5_free_principal(context, val->server);
if (val->caddrs)
krb5_free_addresses(context, val->caddrs);
krb5_xfree(val);
}
void KRB5_CALLCONV
krb5_free_enc_tkt_part(krb5_context context, krb5_enc_tkt_part *val)
{
if (val->session) {
krb5_free_keyblock(context, val->session);
val->session = 0;
}
if (val->client)
krb5_free_principal(context, val->client);
if (val->transited.tr_contents.data) {
krb5_xfree(val->transited.tr_contents.data);
val->transited.tr_contents.data = 0;
}
if (val->caddrs)
krb5_free_addresses(context, val->caddrs);
if (val->authorization_data) {
krb5_free_authdata(context, val->authorization_data);
val->authorization_data = 0;
}
krb5_xfree(val);
}
#endif /* !_KERNEL */
void KRB5_CALLCONV
krb5_free_error(krb5_context context, register krb5_error *val)
{
if (val->client)
krb5_free_principal(context, val->client);
if (val->server)
krb5_free_principal(context, val->server);
if (val->text.data)
krb5_xfree_wrap(val->text.data, val->text.length);
if (val->e_data.data)
krb5_xfree_wrap(val->e_data.data, val->e_data.length);
krb5_xfree_wrap(val, sizeof (krb5_error));
}
#ifndef _KERNEL
void KRB5_CALLCONV
krb5_free_kdc_rep(krb5_context context, krb5_kdc_rep *val)
{
if (val->padata) {
krb5_free_pa_data(context, val->padata);
val->padata = 0;
}
if (val->client) {
krb5_free_principal(context, val->client);
val->client = 0;
}
if (val->ticket) {
krb5_free_ticket(context, val->ticket);
val->ticket = 0;
}
if (val->enc_part.ciphertext.data) {
krb5_xfree(val->enc_part.ciphertext.data);
val->enc_part.ciphertext.data = 0;
}
if (val->enc_part2) {
krb5_free_enc_kdc_rep_part(context, val->enc_part2);
val->enc_part2 = 0;
}
krb5_xfree(val);
}
void KRB5_CALLCONV
krb5_free_kdc_req(krb5_context context, krb5_kdc_req *val)
{
if (val->padata) {
krb5_free_pa_data(context, val->padata);
val->padata = 0;
}
if (val->client) {
krb5_free_principal(context, val->client);
val->client = 0;
}
if (val->server) {
krb5_free_principal(context, val->server);
val->server = 0;
}
if (val->ktype) {
krb5_xfree(val->ktype);
val->ktype = 0;
}
if (val->addresses) {
krb5_free_addresses(context, val->addresses);
val->addresses = 0;
}
if (val->authorization_data.ciphertext.data) {
krb5_xfree(val->authorization_data.ciphertext.data);
val->authorization_data.ciphertext.data = 0;
}
if (val->unenc_authdata) {
krb5_free_authdata(context, val->unenc_authdata);
val->unenc_authdata = 0;
}
if (val->second_ticket) {
krb5_free_tickets(context, val->second_ticket);
val->second_ticket = 0;
}
krb5_xfree(val);
}
#endif /* !_KERNEL */
/*
* Delete a key's derived key list
*/
static void
cleanup_dk_list(krb5_context context, krb5_keyblock *key)
{
krb5_dk_node *dn = key->dk_list;
krb5_dk_node *nxt;
while (dn != NULL) {
nxt = dn->next;
if (dn->derived_key != NULL) {
/*
* Some recursion here but its OK,
* it stops when a NULL dk_list
* is encountered.
*/
krb5_free_keyblock(context, dn->derived_key);
dn->derived_key = NULL;
}
FREE(dn, sizeof(krb5_dk_node));
dn = nxt;
}
key->dk_list = NULL;
}
/* ARGSUSED */
void KRB5_CALLCONV
krb5_free_keyblock_contents(krb5_context context, register krb5_keyblock *key)
{
if (key->contents) {
(void) memset(key->contents, 0, key->length);
krb5_xfree_wrap(key->contents, key->length);
key->length = 0;
key->contents = 0;
}
#ifdef _KERNEL
if (key->key_tmpl != NULL)
(void) crypto_destroy_ctx_template(key->key_tmpl);
#else
if (key->hKey != CK_INVALID_HANDLE) {
CK_RV rv;
rv = C_DestroyObject(krb_ctx_hSession(context), key->hKey);
if (rv != CKR_OK) {
KRB5_LOG(KRB5_ERR, "krb5_free_keyblock_contents: "
"C_DestroyObject = %0x", rv);
}
key->hKey = CK_INVALID_HANDLE;
}
#endif /* _KERNEL */
/*
* If the original key data is freed, we should also free
* any keys derived from that data.
* This saves us from making additional calls to "cleanup_dk_list"
* in all of the many function which have keyblock structures
* declared on the stack that re-use the keyblock data contents
* without freeing the entire keyblock record.
*/
cleanup_dk_list(context, key);
}
void KRB5_CALLCONV
krb5_free_keyblock(krb5_context context, register krb5_keyblock *val)
{
if (!val)
return;
krb5_free_keyblock_contents(context, val);
krb5_xfree_wrap(val, sizeof(krb5_keyblock));
}
#ifndef _KERNEL
void KRB5_CALLCONV
krb5_free_last_req(krb5_context context, krb5_last_req_entry **val)
{
register krb5_last_req_entry **temp;
for (temp = val; *temp; temp++)
krb5_xfree(*temp);
krb5_xfree(val);
}
void KRB5_CALLCONV
krb5_free_pa_data(krb5_context context, krb5_pa_data **val)
{
register krb5_pa_data **temp;
for (temp = val; *temp; temp++) {
if ((*temp)->contents)
krb5_xfree((*temp)->contents);
krb5_xfree(*temp);
}
krb5_xfree(val);
}
#endif /* !_KERNEL */
/* ARGSUSED */
void KRB5_CALLCONV
krb5_free_principal(krb5_context context, krb5_principal val)
{
register krb5_int32 i;
if (!val)
return;
if (val->data) {
i = krb5_princ_size(context, val);
while(--i >= 0)
FREE(krb5_princ_component(context, val, i)->data,
krb5_princ_component(context, val, i)->length+1);
krb5_xfree_wrap(val->data,
sizeof(krb5_data) * krb5_princ_size(context, val));
}
if (val->realm.data)
krb5_xfree_wrap(val->realm.data, val->realm.length+1);
krb5_xfree_wrap(val, sizeof (krb5_principal_data));
}
#ifndef _KERNEL
void KRB5_CALLCONV
krb5_free_priv(krb5_context context, register krb5_priv *val)
{
if (val->enc_part.ciphertext.data) {
krb5_xfree(val->enc_part.ciphertext.data);
val->enc_part.ciphertext.data = 0;
}
krb5_xfree(val);
}
void KRB5_CALLCONV
krb5_free_priv_enc_part(krb5_context context, register krb5_priv_enc_part *val)
{
if (val->user_data.data) {
krb5_xfree(val->user_data.data);
val->user_data.data = 0;
}
if (val->r_address) {
krb5_free_address(context, val->r_address);
val->r_address = 0;
}
if (val->s_address) {
krb5_free_address(context, val->s_address);
val->s_address = 0;
}
krb5_xfree(val);
}
void KRB5_CALLCONV
krb5_free_pwd_data(krb5_context context, krb5_pwd_data *val)
{
if (val->element)
krb5_free_pwd_sequences(context, val->element);
krb5_xfree(val);
}
void KRB5_CALLCONV
krb5_free_pwd_sequences(krb5_context context, passwd_phrase_element **val)
{
register passwd_phrase_element **temp;
for (temp = val; *temp; temp++) {
if ((*temp)->passwd) {
krb5_free_data(context, (*temp)->passwd);
(*temp)->passwd = 0;
}
if ((*temp)->phrase) {
krb5_free_data(context, (*temp)->phrase);
(*temp)->phrase = 0;
}
krb5_xfree(*temp);
}
krb5_xfree(val);
}
void KRB5_CALLCONV
krb5_free_safe(krb5_context context, register krb5_safe *val)
{
if (val->user_data.data) {
krb5_xfree(val->user_data.data);
val->user_data.data = 0;
}
if (val->r_address) {
krb5_free_address(context, val->r_address);
val->r_address = 0;
}
if (val->s_address) {
krb5_free_address(context, val->s_address);
val->s_address = 0;
}
if (val->checksum) {
krb5_free_checksum(context, val->checksum);
val->checksum = 0;
}
krb5_xfree(val);
}
void KRB5_CALLCONV
krb5_free_ticket(krb5_context context, krb5_ticket *val)
{
if (val->server)
krb5_free_principal(context, val->server);
if (val->enc_part.ciphertext.data) {
krb5_xfree(val->enc_part.ciphertext.data);
val->enc_part.ciphertext.data = 0;
}
if (val->enc_part2)
krb5_free_enc_tkt_part(context, val->enc_part2);
krb5_xfree(val);
}
void KRB5_CALLCONV
krb5_free_tickets(krb5_context context, krb5_ticket **val)
{
register krb5_ticket **temp;
for (temp = val; *temp; temp++)
krb5_free_ticket(context, *temp);
krb5_xfree(val);
}
void KRB5_CALLCONV
krb5_free_tgt_creds(krb5_context context, krb5_creds **tgts)
{
register krb5_creds **tgtpp;
for (tgtpp = tgts; *tgtpp; tgtpp++)
krb5_free_creds(context, *tgtpp);
krb5_xfree(tgts);
}
void KRB5_CALLCONV
krb5_free_tkt_authent(krb5_context context, krb5_tkt_authent *val)
{
if (val->ticket) {
krb5_free_ticket(context, val->ticket);
val->ticket = 0;
}
if (val->authenticator) {
krb5_free_authenticator(context, val->authenticator);
val->authenticator = 0;
}
krb5_xfree(val);
}
void KRB5_CALLCONV
krb5_free_unparsed_name(krb5_context context, char *val)
{
if (val) {
krb5_xfree(val);
}
}
void KRB5_CALLCONV
krb5_free_sam_challenge(krb5_context ctx, krb5_sam_challenge *sc)
{
if (!sc)
return;
krb5_free_sam_challenge_contents(ctx, sc);
krb5_xfree(sc);
}
void KRB5_CALLCONV
krb5_free_sam_challenge_2(krb5_context ctx, krb5_sam_challenge_2 *sc2)
{
if (!sc2)
return;
krb5_free_sam_challenge_2_contents(ctx, sc2);
krb5_xfree(sc2);
}
void KRB5_CALLCONV
krb5_free_sam_challenge_contents(krb5_context ctx, krb5_sam_challenge *sc)
{
if (!sc)
return;
if (sc->sam_type_name.data)
krb5_free_data_contents(ctx, &sc->sam_type_name);
if (sc->sam_track_id.data)
krb5_free_data_contents(ctx, &sc->sam_track_id);
if (sc->sam_challenge_label.data)
krb5_free_data_contents(ctx, &sc->sam_challenge_label);
if (sc->sam_challenge.data)
krb5_free_data_contents(ctx, &sc->sam_challenge);
if (sc->sam_response_prompt.data)
krb5_free_data_contents(ctx, &sc->sam_response_prompt);
if (sc->sam_pk_for_sad.data)
krb5_free_data_contents(ctx, &sc->sam_pk_for_sad);
if (sc->sam_cksum.contents) {
krb5_xfree(sc->sam_cksum.contents);
sc->sam_cksum.contents = 0;
}
}
void KRB5_CALLCONV
krb5_free_sam_challenge_2_contents(krb5_context ctx,
krb5_sam_challenge_2 *sc2)
{
krb5_checksum **cksump;
if (!sc2)
return;
if (sc2->sam_challenge_2_body.data)
krb5_free_data_contents(ctx, &sc2->sam_challenge_2_body);
if (sc2->sam_cksum) {
cksump = sc2->sam_cksum;
while (*cksump) {
krb5_free_checksum(ctx, *cksump);
cksump++;
}
krb5_xfree(sc2->sam_cksum);
sc2->sam_cksum = 0;
}
}
void KRB5_CALLCONV
krb5_free_sam_challenge_2_body(krb5_context ctx,
krb5_sam_challenge_2_body *sc2)
{
if (!sc2)
return;
krb5_free_sam_challenge_2_body_contents(ctx, sc2);
krb5_xfree(sc2);
}
void KRB5_CALLCONV
krb5_free_sam_challenge_2_body_contents(krb5_context ctx,
krb5_sam_challenge_2_body *sc2)
{
if (!sc2)
return;
if (sc2->sam_type_name.data)
krb5_free_data_contents(ctx, &sc2->sam_type_name);
if (sc2->sam_track_id.data)
krb5_free_data_contents(ctx, &sc2->sam_track_id);
if (sc2->sam_challenge_label.data)
krb5_free_data_contents(ctx, &sc2->sam_challenge_label);
if (sc2->sam_challenge.data)
krb5_free_data_contents(ctx, &sc2->sam_challenge);
if (sc2->sam_response_prompt.data)
krb5_free_data_contents(ctx, &sc2->sam_response_prompt);
if (sc2->sam_pk_for_sad.data)
krb5_free_data_contents(ctx, &sc2->sam_pk_for_sad);
}
void KRB5_CALLCONV
krb5_free_sam_response(krb5_context ctx, krb5_sam_response *sr)
{
if (!sr)
return;
krb5_free_sam_response_contents(ctx, sr);
krb5_xfree(sr);
}
void KRB5_CALLCONV
krb5_free_sam_response_2(krb5_context ctx, krb5_sam_response_2 *sr2)
{
if (!sr2)
return;
krb5_free_sam_response_2_contents(ctx, sr2);
krb5_xfree(sr2);
}
void KRB5_CALLCONV
krb5_free_sam_response_contents(krb5_context ctx, krb5_sam_response *sr)
{
if (!sr)
return;
if (sr->sam_track_id.data)
krb5_free_data_contents(ctx, &sr->sam_track_id);
if (sr->sam_enc_key.ciphertext.data)
krb5_free_data_contents(ctx, &sr->sam_enc_key.ciphertext);
if (sr->sam_enc_nonce_or_ts.ciphertext.data)
krb5_free_data_contents(ctx, &sr->sam_enc_nonce_or_ts.ciphertext);
}
void KRB5_CALLCONV
krb5_free_sam_response_2_contents(krb5_context ctx, krb5_sam_response_2 *sr2)
{
if (!sr2)
return;
if (sr2->sam_track_id.data)
krb5_free_data_contents(ctx, &sr2->sam_track_id);
if (sr2->sam_enc_nonce_or_sad.ciphertext.data)
krb5_free_data_contents(ctx, &sr2->sam_enc_nonce_or_sad.ciphertext);
}
void KRB5_CALLCONV
krb5_free_predicted_sam_response(krb5_context ctx,
krb5_predicted_sam_response *psr)
{
if (!psr)
return;
krb5_free_predicted_sam_response_contents(ctx, psr);
krb5_xfree(psr);
}
void KRB5_CALLCONV
krb5_free_predicted_sam_response_contents(krb5_context ctx,
krb5_predicted_sam_response *psr)
{
if (!psr)
return;
if (psr->sam_key.contents)
krb5_free_keyblock_contents(ctx, &psr->sam_key);
if (psr->client) {
krb5_free_principal(ctx, psr->client);
psr->client = 0;
}
if (psr->msd.data)
krb5_free_data_contents(ctx, &psr->msd);
}
void KRB5_CALLCONV
krb5_free_enc_sam_response_enc(krb5_context ctx,
krb5_enc_sam_response_enc *esre)
{
if (!esre)
return;
krb5_free_enc_sam_response_enc_contents(ctx, esre);
krb5_xfree(esre);
}
void KRB5_CALLCONV
krb5_free_enc_sam_response_enc_2(krb5_context ctx,
krb5_enc_sam_response_enc_2 *esre2)
{
if (!esre2)
return;
krb5_free_enc_sam_response_enc_2_contents(ctx, esre2);
krb5_xfree(esre2);
}
void KRB5_CALLCONV
krb5_free_enc_sam_response_enc_contents(krb5_context ctx,
krb5_enc_sam_response_enc *esre)
{
if (!esre)
return;
if (esre->sam_sad.data)
krb5_free_data_contents(ctx, &esre->sam_sad);
}
void KRB5_CALLCONV
krb5_free_enc_sam_response_enc_2_contents(krb5_context ctx,
krb5_enc_sam_response_enc_2 *esre2)
{
if (!esre2)
return;
if (esre2->sam_sad.data)
krb5_free_data_contents(ctx, &esre2->sam_sad);
}
void KRB5_CALLCONV
krb5_free_pa_enc_ts(krb5_context ctx, krb5_pa_enc_ts *pa_enc_ts)
{
if (!pa_enc_ts)
return;
krb5_xfree(pa_enc_ts);
}
#endif /* !_KERNEL */
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* lib/krb5/krb/parse.c
*
* Copyright 1990,1991,2008 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.
*
*
* krb5_parse_name() routine.
*
* Rewritten by Theodore Ts'o to properly handle arbitrary quoted
* characters in the principal name.
*/
#include "k5-int.h"
/*
* converts a single-string representation of the name to the
* multi-part principal format used in the protocols.
*
* principal will point to allocated storage which should be freed by
* the caller (using krb5_free_principal) after use.
*
* Conventions: / is used to separate components. If @ is present in the
* string, then the rest of the string after it represents the realm name.
* Otherwise the local realm name is used.
*
* error return:
* KRB5_PARSE_MALFORMED badly formatted string
*
* also returns system errors:
* ENOMEM malloc failed/out of memory
*
* get_default_realm() is called; it may return other errors.
*/
#define REALM_SEP '@'
#define COMPONENT_SEP '/'
#define QUOTECHAR '\\'
#define FCOMPNUM 10
/*
* May the fleas of a thousand camels infest the ISO, they who think
* that arbitrarily large multi-component names are a Good Thing.....
*/
static krb5_error_code
/*LINTED*/
k5_parse_name(krb5_context context, const char *name,
int flags, krb5_principal *nprincipal)
{
register const char *cp;
register char *q;
register int i,c,size;
int components = 0;
const char *parsed_realm = NULL;
int fcompsize[FCOMPNUM];
unsigned int realmsize = 0;
#ifndef _KERNEL
char *default_realm = NULL;
int default_realm_size = 0;
krb5_error_code retval;
#endif
char *tmpdata;
krb5_principal principal;
unsigned int enterprise = (flags & KRB5_PRINCIPAL_PARSE_ENTERPRISE);
int first_at;
*nprincipal = NULL;
/*
* Pass 1. Find out how many components there are to the name,
* and get string sizes for the first FCOMPNUM components. For
* enterprise principal names (UPNs), there is only a single
* component.
*/
size = 0;
/*LINTED*/
for (i=0,cp = name, first_at = 1; (c = *cp); cp++) {
if (c == QUOTECHAR) {
cp++;
/*LINTED*/
if (!(c = *cp))
/*
* QUOTECHAR can't be at the last
* character of the name!
*/
return(KRB5_PARSE_MALFORMED);
size++;
continue;
} else if (c == COMPONENT_SEP && !enterprise) {
if (parsed_realm)
/*
* Shouldn't see a component separator
* after we've parsed out the realm name!
*/
return(KRB5_PARSE_MALFORMED);
if (i < FCOMPNUM) {
fcompsize[i] = size;
}
size = 0;
i++;
} else if (c == REALM_SEP && (!enterprise || !first_at)) {
if (parsed_realm)
/*
* Multiple realm separaters
* not allowed; zero-length realms are.
*/
return(KRB5_PARSE_MALFORMED);
parsed_realm = cp + 1;
if (i < FCOMPNUM) {
fcompsize[i] = size;
}
size = 0;
} else {
if (c == REALM_SEP && enterprise && first_at)
first_at = 0;
size++;
}
}
if (parsed_realm != NULL)
realmsize = size;
else if (i < FCOMPNUM)
fcompsize[i] = size;
components = i + 1;
/*
* Now, we allocate the principal structure and all of its
* component pieces
*/
principal = (krb5_principal)MALLOC(sizeof(krb5_principal_data));
if (principal == NULL) {
return(ENOMEM);
}
principal->data = (krb5_data *)MALLOC(sizeof(krb5_data) * components);
if (principal->data == NULL) {
krb5_xfree_wrap(principal, sizeof(krb5_principal_data));
return ENOMEM;
}
principal->length = components;
/*
* If a realm was not found, then use the default realm, unless
* KRB5_PRINCIPAL_PARSE_NO_REALM was specified in which case the
* realm will be empty.
*/
#ifndef _KERNEL
if (!parsed_realm) {
if (flags & KRB5_PRINCIPAL_PARSE_REQUIRE_REALM) {
krb5_set_error_message(context, KRB5_PARSE_MALFORMED,
"Principal %s is missing required realm", name);
krb5_xfree_wrap(principal->data, principal->length);
krb5_xfree_wrap(principal, sizeof(krb5_principal_data));
return KRB5_PARSE_MALFORMED;
}
if (!default_realm && (flags & KRB5_PRINCIPAL_PARSE_NO_REALM) == 0) {
retval = krb5_get_default_realm(context, &default_realm);
if (retval) {
krb5_xfree_wrap(principal->data, principal->length);
krb5_xfree_wrap(principal, sizeof(krb5_principal_data));
return(retval);
}
default_realm_size = strlen(default_realm);
}
realmsize = default_realm_size;
} else if (flags & KRB5_PRINCIPAL_PARSE_NO_REALM) {
krb5_set_error_message(context, KRB5_PARSE_MALFORMED,
"Principal %s has realm present", name);
krb5_xfree_wrap(principal->data, principal->length);
krb5_xfree_wrap(principal, sizeof(krb5_principal_data));
return KRB5_PARSE_MALFORMED;
}
#endif
/*
* Pass 2. Happens only if there were more than FCOMPNUM
* component; if this happens, someone should be shot
* immediately. Nevertheless, we will attempt to handle said
* case..... <martyred sigh>
*/
if (components >= FCOMPNUM) {
size = 0;
parsed_realm = NULL;
/*LINTED*/
for (i=0,cp = name; (c = *cp); cp++) {
if (c == QUOTECHAR) {
cp++;
size++;
} else if (c == COMPONENT_SEP) {
if (krb5_princ_size(context, principal) > i)
krb5_princ_component(context, principal, i)->length = size;
size = 0;
i++;
} else if (c == REALM_SEP) {
if (krb5_princ_size(context, principal) > i)
krb5_princ_component(context, principal, i)->length = size;
size = 0;
parsed_realm = cp+1;
} else
size++;
}
if (parsed_realm)
krb5_princ_realm(context, principal)->length = size;
else
if (krb5_princ_size(context, principal) > i)
krb5_princ_component(context, principal, i)->length = size;
if (i + 1 != components) {
#ifndef _KERNEL
#if !defined(_WIN32)
fprintf(stderr,
"Programming error in krb5_parse_name!");
#endif
ASSERT(i + 1 == components);
abort();
#else
ASSERT(i + 1 == components);
#endif /* !_KERNEL */
}
} else {
/*
* If there were fewer than FCOMPSIZE components (the
* usual case), then just copy the sizes to the
* principal structure
*/
for (i=0; i < components; i++)
krb5_princ_component(context, principal, i)->length = fcompsize[i];
}
/*
* Now, we need to allocate the space for the strings themselves.....
*/
tmpdata = MALLOC(realmsize + 1);
if (tmpdata == 0) {
krb5_xfree_wrap(principal->data, principal->length);
krb5_xfree_wrap(principal, sizeof(krb5_principal_data));
#ifndef _KERNEL
krb5_xfree_wrap(default_realm, strlen(default_realm));
#endif
return ENOMEM;
}
krb5_princ_set_realm_length(context, principal, realmsize);
krb5_princ_set_realm_data(context, principal, tmpdata);
for (i=0; i < components; i++) {
char *tmpdata2 =
MALLOC(krb5_princ_component(context, principal, i)->length + 1);
if (tmpdata2 == NULL) {
for (i--; i >= 0; i--)
krb5_xfree_wrap(krb5_princ_component(context,
principal, i)->data,
krb5_princ_component(context,
principal, i)->length + 1);
krb5_xfree_wrap(krb5_princ_realm(context,
principal)->data, krb5_princ_realm(context,
principal)->length + 1);
krb5_xfree_wrap(principal->data, principal->length);
krb5_xfree_wrap(principal, sizeof(krb5_principal_data));
#ifndef _KERNEL
krb5_xfree_wrap(default_realm, strlen(default_realm));
#endif
return(ENOMEM);
}
krb5_princ_component(context, principal, i)->data = tmpdata2;
krb5_princ_component(context, principal, i)->magic = KV5M_DATA;
}
/*
* Pass 3. Now we go through the string a *third* time, this
* time filling in the krb5_principal structure which we just
* allocated.
*/
q = krb5_princ_component(context, principal, 0)->data;
/*LINTED*/
for (i=0,cp = name, first_at = 1; (c = *cp); cp++) {
if (c == QUOTECHAR) {
cp++;
switch (c = *cp) {
case 'n':
*q++ = '\n';
break;
case 't':
*q++ = '\t';
break;
case 'b':
*q++ = '\b';
break;
case '0':
*q++ = '\0';
break;
default:
*q++ = c;
break;
}
} else if (c == COMPONENT_SEP && !enterprise) {
i++;
*q++ = '\0';
q = krb5_princ_component(context, principal, i)->data;
} else if (c == REALM_SEP && (!enterprise || !first_at)) {
i++;
*q++ = '\0';
q = krb5_princ_realm(context, principal)->data;
} else {
if (c == REALM_SEP && enterprise && first_at)
first_at = 0;
*q++ = c;
}
}
*q++ = '\0';
/*LINTED*/
if (!parsed_realm) {
#ifndef _KERNEL
if (flags & KRB5_PRINCIPAL_PARSE_NO_REALM)
(krb5_princ_realm(context, principal)->data)[0] = '\0';
else
strlcpy(krb5_princ_realm(context, principal)->data, default_realm, realmsize+1);
#endif
}
/*
* Alright, we're done. Now stuff a pointer to this monstrosity
* into the return variable, and let's get out of here.
*/
if (enterprise)
krb5_princ_type(context, principal) = KRB5_NT_ENTERPRISE_PRINCIPAL;
else
krb5_princ_type(context, principal) = KRB5_NT_PRINCIPAL;
principal->magic = KV5M_PRINCIPAL;
principal->realm.magic = KV5M_DATA;
*nprincipal = principal;
#ifndef _KERNEL
if (default_realm != NULL)
krb5_xfree_wrap(default_realm, strlen(default_realm));
#endif
return(0);
}
krb5_error_code KRB5_CALLCONV
krb5_parse_name(krb5_context context, const char *name, krb5_principal *nprincipal)
{
return k5_parse_name(context, name, 0, nprincipal);
}
krb5_error_code KRB5_CALLCONV
krb5_parse_name_flags(krb5_context context, const char *name,
int flags, krb5_principal *nprincipal)
{
return k5_parse_name(context, name, flags, nprincipal);
}
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* lib/krb5/krb/ser_actx.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.
*
*/
/*
* ser_actx.c - Serialize krb5_auth_context structure.
*/
#include "k5-int.h"
#include "int-proto.h"
#include "auth_con.h"
#define TOKEN_RADDR 950916
#define TOKEN_RPORT 950917
#define TOKEN_LADDR 950918
#define TOKEN_LPORT 950919
#define TOKEN_KEYBLOCK 950920
#define TOKEN_LSKBLOCK 950921
#define TOKEN_RSKBLOCK 950922
/*
* Routines to deal with externalizing the krb5_auth_context:
* krb5_auth_context_size();
* krb5_auth_context_externalize();
* krb5_auth_context_internalize();
*/
static krb5_error_code krb5_auth_context_size
(krb5_context, krb5_pointer, size_t *);
static krb5_error_code krb5_auth_context_externalize
(krb5_context, krb5_pointer, krb5_octet **, size_t *);
static krb5_error_code krb5_auth_context_internalize
(krb5_context,krb5_pointer *, krb5_octet **, size_t *);
/*
* Other metadata serialization initializers.
*/
/* Local data */
static const krb5_ser_entry krb5_auth_context_ser_entry = {
KV5M_AUTH_CONTEXT, /* Type */
krb5_auth_context_size, /* Sizer routine */
krb5_auth_context_externalize, /* Externalize routine */
krb5_auth_context_internalize /* Internalize routine */
};
/*
* krb5_auth_context_size() - Determine the size required to externalize
* the krb5_auth_context.
*/
static krb5_error_code
krb5_auth_context_size(krb5_context kcontext, krb5_pointer arg, size_t *sizep)
{
krb5_error_code kret;
krb5_auth_context auth_context;
size_t required;
/*
* krb5_auth_context requires at minimum:
* krb5_int32 for KV5M_AUTH_CONTEXT
* krb5_int32 for auth_context_flags
* krb5_int32 for remote_seq_number
* krb5_int32 for local_seq_number
* krb5_int32 for req_cksumtype
* krb5_int32 for safe_cksumtype
* krb5_int32 for size of i_vector
* krb5_int32 for KV5M_AUTH_CONTEXT
*/
kret = EINVAL;
/* Solaris Kerberos */
auth_context = (krb5_auth_context) arg;
if (auth_context) {
kret = 0;
/* Calculate size required by i_vector - ptooey */
if (auth_context->i_vector && auth_context->keyblock) {
kret = krb5_c_block_size(kcontext, auth_context->keyblock->enctype,
&required);
} else {
required = 0;
}
required += sizeof(krb5_int32)*8;
/* Calculate size required by remote_addr, if appropriate */
if (!kret && auth_context->remote_addr) {
kret = krb5_size_opaque(kcontext,
KV5M_ADDRESS,
(krb5_pointer) auth_context->remote_addr,
&required);
if (!kret)
required += sizeof(krb5_int32);
}
/* Calculate size required by remote_port, if appropriate */
if (!kret && auth_context->remote_port) {
kret = krb5_size_opaque(kcontext,
KV5M_ADDRESS,
(krb5_pointer) auth_context->remote_port,
&required);
if (!kret)
required += sizeof(krb5_int32);
}
/* Calculate size required by local_addr, if appropriate */
if (!kret && auth_context->local_addr) {
kret = krb5_size_opaque(kcontext,
KV5M_ADDRESS,
(krb5_pointer) auth_context->local_addr,
&required);
if (!kret)
required += sizeof(krb5_int32);
}
/* Calculate size required by local_port, if appropriate */
if (!kret && auth_context->local_port) {
kret = krb5_size_opaque(kcontext,
KV5M_ADDRESS,
(krb5_pointer) auth_context->local_port,
&required);
if (!kret)
required += sizeof(krb5_int32);
}
/* Calculate size required by keyblock, if appropriate */
if (!kret && auth_context->keyblock) {
kret = krb5_size_opaque(kcontext,
KV5M_KEYBLOCK,
(krb5_pointer) auth_context->keyblock,
&required);
if (!kret)
required += sizeof(krb5_int32);
}
/* Calculate size required by send_subkey, if appropriate */
if (!kret && auth_context->send_subkey) {
kret = krb5_size_opaque(kcontext,
KV5M_KEYBLOCK,
(krb5_pointer) auth_context->send_subkey,
&required);
if (!kret)
required += sizeof(krb5_int32);
}
/* Calculate size required by recv_subkey, if appropriate */
if (!kret && auth_context->recv_subkey) {
kret = krb5_size_opaque(kcontext,
KV5M_KEYBLOCK,
(krb5_pointer) auth_context->recv_subkey,
&required);
if (!kret)
required += sizeof(krb5_int32);
}
/* Calculate size required by authentp, if appropriate */
if (!kret && auth_context->authentp)
kret = krb5_size_opaque(kcontext,
KV5M_AUTHENTICATOR,
(krb5_pointer) auth_context->authentp,
&required);
}
if (!kret)
*sizep += required;
return(kret);
}
/*
* krb5_auth_context_externalize() - Externalize the krb5_auth_context.
*/
static krb5_error_code
krb5_auth_context_externalize(krb5_context kcontext, krb5_pointer arg, krb5_octet **buffer, size_t *lenremain)
{
krb5_error_code kret;
krb5_auth_context auth_context;
size_t required;
krb5_octet *bp;
size_t remain;
size_t obuf;
krb5_int32 obuf32;
required = 0;
bp = *buffer;
remain = *lenremain;
kret = EINVAL;
/* Solaris Kerberos */
auth_context = (krb5_auth_context) arg;
if (auth_context) {
kret = ENOMEM;
if (!krb5_auth_context_size(kcontext, arg, &required) &&
(required <= remain)) {
/* Write fixed portion */
(void) krb5_ser_pack_int32(KV5M_AUTH_CONTEXT, &bp, &remain);
(void) krb5_ser_pack_int32(auth_context->auth_context_flags,
&bp, &remain);
(void) krb5_ser_pack_int32(auth_context->remote_seq_number,
&bp, &remain);
(void) krb5_ser_pack_int32(auth_context->local_seq_number,
&bp, &remain);
(void) krb5_ser_pack_int32((krb5_int32) auth_context->req_cksumtype,
&bp, &remain);
(void) krb5_ser_pack_int32((krb5_int32) auth_context->safe_cksumtype,
&bp, &remain);
kret = 0;
/* Now figure out the number of bytes for i_vector and write it */
if (auth_context->i_vector) {
kret = krb5_c_block_size(kcontext,
auth_context->keyblock->enctype,
&obuf);
} else {
obuf = 0;
}
/* Convert to signed 32 bit integer */
obuf32 = obuf;
if (kret == 0 && obuf != obuf32)
kret = EINVAL;
if (!kret)
(void) krb5_ser_pack_int32(obuf32, &bp, &remain);
/* Now copy i_vector */
if (!kret && auth_context->i_vector)
(void) krb5_ser_pack_bytes(auth_context->i_vector,
obuf,
&bp, &remain);
/* Now handle remote_addr, if appropriate */
if (!kret && auth_context->remote_addr) {
(void) krb5_ser_pack_int32(TOKEN_RADDR, &bp, &remain);
kret = krb5_externalize_opaque(kcontext,
KV5M_ADDRESS,
(krb5_pointer)
auth_context->remote_addr,
&bp,
&remain);
}
/* Now handle remote_port, if appropriate */
if (!kret && auth_context->remote_port) {
(void) krb5_ser_pack_int32(TOKEN_RPORT, &bp, &remain);
kret = krb5_externalize_opaque(kcontext,
KV5M_ADDRESS,
(krb5_pointer)
auth_context->remote_addr,
&bp,
&remain);
}
/* Now handle local_addr, if appropriate */
if (!kret && auth_context->local_addr) {
(void) krb5_ser_pack_int32(TOKEN_LADDR, &bp, &remain);
kret = krb5_externalize_opaque(kcontext,
KV5M_ADDRESS,
(krb5_pointer)
auth_context->local_addr,
&bp,
&remain);
}
/* Now handle local_port, if appropriate */
if (!kret && auth_context->local_port) {
(void) krb5_ser_pack_int32(TOKEN_LPORT, &bp, &remain);
kret = krb5_externalize_opaque(kcontext,
KV5M_ADDRESS,
(krb5_pointer)
auth_context->local_addr,
&bp,
&remain);
}
/* Now handle keyblock, if appropriate */
if (!kret && auth_context->keyblock) {
(void) krb5_ser_pack_int32(TOKEN_KEYBLOCK, &bp, &remain);
kret = krb5_externalize_opaque(kcontext,
KV5M_KEYBLOCK,
(krb5_pointer)
auth_context->keyblock,
&bp,
&remain);
}
/* Now handle subkey, if appropriate */
if (!kret && auth_context->send_subkey) {
(void) krb5_ser_pack_int32(TOKEN_LSKBLOCK, &bp, &remain);
kret = krb5_externalize_opaque(kcontext,
KV5M_KEYBLOCK,
(krb5_pointer)
auth_context->send_subkey,
&bp,
&remain);
}
/* Now handle subkey, if appropriate */
if (!kret && auth_context->recv_subkey) {
(void) krb5_ser_pack_int32(TOKEN_RSKBLOCK, &bp, &remain);
kret = krb5_externalize_opaque(kcontext,
KV5M_KEYBLOCK,
(krb5_pointer)
auth_context->recv_subkey,
&bp,
&remain);
}
/* Now handle authentp, if appropriate */
if (!kret && auth_context->authentp)
kret = krb5_externalize_opaque(kcontext,
KV5M_AUTHENTICATOR,
(krb5_pointer)
auth_context->authentp,
&bp,
&remain);
/*
* If we were successful, write trailer then update the pointer and
* remaining length;
*/
if (!kret) {
/* Write our trailer */
(void) krb5_ser_pack_int32(KV5M_AUTH_CONTEXT, &bp, &remain);
*buffer = bp;
*lenremain = remain;
}
}
}
return(kret);
}
/*
* krb5_auth_context_internalize() - Internalize the krb5_auth_context.
*/
static krb5_error_code
krb5_auth_context_internalize(krb5_context kcontext, krb5_pointer *argp, krb5_octet **buffer, size_t *lenremain)
{
krb5_error_code kret;
krb5_auth_context auth_context;
krb5_int32 ibuf;
krb5_octet *bp;
size_t remain;
krb5_int32 ivlen;
krb5_int32 tag;
bp = *buffer;
remain = *lenremain;
kret = EINVAL;
/* Read our magic number */
if (krb5_ser_unpack_int32(&ibuf, &bp, &remain))
ibuf = 0;
if (ibuf == KV5M_AUTH_CONTEXT) {
kret = ENOMEM;
/* Get memory for the auth_context */
if ((remain >= (5*sizeof(krb5_int32))) &&
(auth_context = (krb5_auth_context)
MALLOC(sizeof(struct _krb5_auth_context)))) {
(void) memset(auth_context, 0, sizeof(struct _krb5_auth_context));
/* Get auth_context_flags */
(void) krb5_ser_unpack_int32(&ibuf, &bp, &remain);
auth_context->auth_context_flags = ibuf;
/* Get remote_seq_number */
(void) krb5_ser_unpack_int32(&ibuf, &bp, &remain);
auth_context->remote_seq_number = ibuf;
/* Get local_seq_number */
(void) krb5_ser_unpack_int32(&ibuf, &bp, &remain);
auth_context->local_seq_number = ibuf;
/* Get req_cksumtype */
(void) krb5_ser_unpack_int32(&ibuf, &bp, &remain);
auth_context->req_cksumtype = (krb5_cksumtype) ibuf;
/* Get safe_cksumtype */
(void) krb5_ser_unpack_int32(&ibuf, &bp, &remain);
auth_context->safe_cksumtype = (krb5_cksumtype) ibuf;
/* Get length of i_vector */
(void) krb5_ser_unpack_int32(&ivlen, &bp, &remain);
if (ivlen) {
if ((auth_context->i_vector =
(krb5_pointer) MALLOC((size_t)ivlen)))
kret = krb5_ser_unpack_bytes(auth_context->i_vector,
(size_t) ivlen,
&bp,
&remain);
else
kret = ENOMEM;
}
else
kret = 0;
/* Peek at next token */
tag = 0;
if (!kret)
kret = krb5_ser_unpack_int32(&tag, &bp, &remain);
/* This is the remote_addr */
if (!kret && (tag == TOKEN_RADDR)) {
if (!(kret = krb5_internalize_opaque(kcontext,
KV5M_ADDRESS,
(krb5_pointer *)
&auth_context->
remote_addr,
&bp,
&remain)))
kret = krb5_ser_unpack_int32(&tag, &bp, &remain);
}
/* This is the remote_port */
if (!kret && (tag == TOKEN_RPORT)) {
if (!(kret = krb5_internalize_opaque(kcontext,
KV5M_ADDRESS,
(krb5_pointer *)
&auth_context->
remote_port,
&bp,
&remain)))
kret = krb5_ser_unpack_int32(&tag, &bp, &remain);
}
/* This is the local_addr */
if (!kret && (tag == TOKEN_LADDR)) {
if (!(kret = krb5_internalize_opaque(kcontext,
KV5M_ADDRESS,
(krb5_pointer *)
&auth_context->
local_addr,
&bp,
&remain)))
kret = krb5_ser_unpack_int32(&tag, &bp, &remain);
}
/* This is the local_port */
if (!kret && (tag == TOKEN_LPORT)) {
if (!(kret = krb5_internalize_opaque(kcontext,
KV5M_ADDRESS,
(krb5_pointer *)
&auth_context->
local_port,
&bp,
&remain)))
kret = krb5_ser_unpack_int32(&tag, &bp, &remain);
}
/* This is the keyblock */
if (!kret && (tag == TOKEN_KEYBLOCK)) {
if (!(kret = krb5_internalize_opaque(kcontext,
KV5M_KEYBLOCK,
(krb5_pointer *)
&auth_context->keyblock,
&bp,
&remain)))
kret = krb5_ser_unpack_int32(&tag, &bp, &remain);
}
/* This is the send_subkey */
if (!kret && (tag == TOKEN_LSKBLOCK)) {
if (!(kret = krb5_internalize_opaque(kcontext,
KV5M_KEYBLOCK,
(krb5_pointer *)
&auth_context->
send_subkey,
&bp,
&remain)))
kret = krb5_ser_unpack_int32(&tag, &bp, &remain);
}
/* This is the recv_subkey */
if (!kret) {
if (tag == TOKEN_RSKBLOCK) {
kret = krb5_internalize_opaque(kcontext,
KV5M_KEYBLOCK,
(krb5_pointer *)
&auth_context->
recv_subkey,
&bp,
&remain);
}
else {
/*
* We read the next tag, but it's not of any use here, so
* we effectively 'unget' it here.
*/
bp -= sizeof(krb5_int32);
remain += sizeof(krb5_int32);
}
}
/* Now find the authentp */
if (!kret) {
if ((kret = krb5_internalize_opaque(kcontext,
KV5M_AUTHENTICATOR,
(krb5_pointer *)
&auth_context->authentp,
&bp,
&remain))) {
if (kret == EINVAL)
kret = 0;
}
}
/* Finally, find the trailer */
if (!kret) {
kret = krb5_ser_unpack_int32(&ibuf, &bp, &remain);
if (!kret && (ibuf != KV5M_AUTH_CONTEXT))
kret = EINVAL;
}
if (!kret) {
*buffer = bp;
*lenremain = remain;
auth_context->magic = KV5M_AUTH_CONTEXT;
*argp = (krb5_pointer) auth_context;
}
/* We don't import the auth_context into the kernel */
#ifndef _KERNEL
else
krb5_auth_con_free(kcontext, auth_context);
#endif
}
}
return(kret);
}
/*
* Register the auth_context serializer.
*/
krb5_error_code KRB5_CALLCONV
krb5_ser_auth_context_init(krb5_context kcontext)
{
krb5_error_code kret;
kret = krb5_register_serializer(kcontext, &krb5_auth_context_ser_entry);
if (!kret)
kret = krb5_ser_authdata_init(kcontext);
if (!kret)
kret = krb5_ser_address_init(kcontext);
if (!kret)
kret = krb5_ser_authenticator_init(kcontext);
if (!kret)
kret = krb5_ser_checksum_init(kcontext);
if (!kret)
kret = krb5_ser_keyblock_init(kcontext);
if (!kret)
kret = krb5_ser_principal_init(kcontext);
return(kret);
}
/*
* lib/krb5/krb/ser_adata.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.
*
*/
/*
* ser_adata.c - Serialize a krb5_authdata structure.
*/
#include "k5-int.h"
#include "int-proto.h"
/*
* Routines to deal with externalizing the krb5_authdata:
* krb5_authdata_size();
* krb5_authdata_externalize();
* krb5_authdata_internalize();
*/
static krb5_error_code krb5_authdata_size
(krb5_context, krb5_pointer, size_t *);
static krb5_error_code krb5_authdata_externalize
(krb5_context, krb5_pointer, krb5_octet **, size_t *);
static krb5_error_code krb5_authdata_internalize
(krb5_context,krb5_pointer *, krb5_octet **, size_t *);
/* Local data */
static const krb5_ser_entry krb5_authdata_ser_entry = {
KV5M_AUTHDATA, /* Type */
krb5_authdata_size, /* Sizer routine */
krb5_authdata_externalize, /* Externalize routine */
krb5_authdata_internalize /* Internalize routine */
};
/*
* krb5_authdata_esize() - Determine the size required to externalize
* the krb5_authdata.
*/
/*ARGSUSED*/
static krb5_error_code
krb5_authdata_size(krb5_context kcontext, krb5_pointer arg, size_t *sizep)
{
krb5_error_code kret;
krb5_authdata *authdata;
/*
* krb5_authdata requires:
* krb5_int32 for KV5M_AUTHDATA
* krb5_int32 for ad_type
* krb5_int32 for length
* authdata->length for contents
* krb5_int32 for KV5M_AUTHDATA
*/
kret = EINVAL;
/* Solaris Kerberos */
authdata = (krb5_authdata *) arg;
if (authdata) {
*sizep += (sizeof(krb5_int32) +
sizeof(krb5_int32) +
sizeof(krb5_int32) +
sizeof(krb5_int32) +
(size_t) authdata->length);
kret = 0;
}
return(kret);
}
/*
* krb5_authdata_externalize() - Externalize the krb5_authdata.
*/
static krb5_error_code
krb5_authdata_externalize(krb5_context kcontext, krb5_pointer arg, krb5_octet **buffer, size_t *lenremain)
{
krb5_error_code kret;
krb5_authdata *authdata;
size_t required;
krb5_octet *bp;
size_t remain;
required = 0;
bp = *buffer;
remain = *lenremain;
kret = EINVAL;
/* Solaris Kerberos */
authdata = (krb5_authdata *) arg;
if (authdata) {
kret = ENOMEM;
if (!krb5_authdata_size(kcontext, arg, &required) &&
(required <= remain)) {
/* Our identifier */
(void) krb5_ser_pack_int32(KV5M_AUTHDATA, &bp, &remain);
/* Our ad_type */
(void) krb5_ser_pack_int32((krb5_int32) authdata->ad_type,
&bp, &remain);
/* Our length */
(void) krb5_ser_pack_int32((krb5_int32) authdata->length,
&bp, &remain);
/* Our contents */
(void) krb5_ser_pack_bytes(authdata->contents,
(size_t) authdata->length,
&bp, &remain);
/* Finally, our trailer */
(void) krb5_ser_pack_int32(KV5M_AUTHDATA, &bp, &remain);
kret = 0;
*buffer = bp;
*lenremain = remain;
}
}
return(kret);
}
/*
* krb5_authdata_internalize() - Internalize the krb5_authdata.
*/
/*ARGSUSED*/
static krb5_error_code
krb5_authdata_internalize(krb5_context kcontext, krb5_pointer *argp, krb5_octet **buffer, size_t *lenremain)
{
krb5_error_code kret;
krb5_authdata *authdata;
krb5_int32 ibuf;
krb5_octet *bp;
size_t remain;
bp = *buffer;
remain = *lenremain;
kret = EINVAL;
/* Read our magic number */
if (krb5_ser_unpack_int32(&ibuf, &bp, &remain))
ibuf = 0;
if (ibuf == KV5M_AUTHDATA) {
kret = ENOMEM;
/* Get a authdata */
if ((remain >= (2*sizeof(krb5_int32))) &&
(authdata = (krb5_authdata *) MALLOC(sizeof(krb5_authdata)))) {
(void) memset(authdata, 0, sizeof(krb5_authdata));
/* Get the ad_type */
(void) krb5_ser_unpack_int32(&ibuf, &bp, &remain);
authdata->ad_type = (krb5_authdatatype) ibuf;
/* Get the length */
(void) krb5_ser_unpack_int32(&ibuf, &bp, &remain);
authdata->length = (int) ibuf;
/* Get the string */
/* Solaris Kerberos */
authdata->contents = (krb5_octet *)
MALLOC((size_t) (ibuf));
if ((authdata->contents) &&
!(kret = krb5_ser_unpack_bytes(authdata->contents,
(size_t) ibuf,
&bp, &remain))) {
if ((kret = krb5_ser_unpack_int32(&ibuf, &bp, &remain)))
ibuf = 0;
if (ibuf == KV5M_AUTHDATA) {
authdata->magic = KV5M_AUTHDATA;
*buffer = bp;
*lenremain = remain;
*argp = (krb5_pointer) authdata;
}
else
kret = EINVAL;
}
if (kret) {
if (authdata->contents)
FREE(authdata->contents, authdata->length);
FREE(authdata, sizeof (krb5_authdata));
}
}
}
return(kret);
}
/*
* Register the authdata serializer.
*/
krb5_error_code
krb5_ser_authdata_init(krb5_context kcontext)
{
return(krb5_register_serializer(kcontext, &krb5_authdata_ser_entry));
}
/*
* lib/krb5/krb/ser_addr.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.
*
*/
/*
* ser_addr.c - Serialize a krb5_address structure.
*/
#include "k5-int.h"
#include "int-proto.h"
/*
* Routines to deal with externalizing the krb5_address:
* krb5_address_size();
* krb5_address_externalize();
* krb5_address_internalize();
*/
static krb5_error_code krb5_address_size
(krb5_context, krb5_pointer, size_t *);
static krb5_error_code krb5_address_externalize
(krb5_context, krb5_pointer, krb5_octet **, size_t *);
static krb5_error_code krb5_address_internalize
(krb5_context,krb5_pointer *, krb5_octet **, size_t *);
/* Local data */
static const krb5_ser_entry krb5_address_ser_entry = {
KV5M_ADDRESS, /* Type */
krb5_address_size, /* Sizer routine */
krb5_address_externalize, /* Externalize routine */
krb5_address_internalize /* Internalize routine */
};
/*
* krb5_address_size() - Determine the size required to externalize
* the krb5_address.
*/
/*ARGSUSED*/
static krb5_error_code
krb5_address_size(krb5_context kcontext, krb5_pointer arg, size_t *sizep)
{
krb5_error_code kret;
krb5_address *address;
/*
* krb5_address requires:
* krb5_int32 for KV5M_ADDRESS
* krb5_int32 for addrtype
* krb5_int32 for length
* address->length for contents
* krb5_int32 for KV5M_ADDRESS
*/
kret = EINVAL;
/* Solaris Kerberos */
address = (krb5_address *) arg;
if (address) {
*sizep += (sizeof(krb5_int32) +
sizeof(krb5_int32) +
sizeof(krb5_int32) +
sizeof(krb5_int32) +
(size_t) address->length);
kret = 0;
}
return(kret);
}
/*
* krb5_address_externalize() - Externalize the krb5_address.
*/
static krb5_error_code
krb5_address_externalize(krb5_context kcontext, krb5_pointer arg, krb5_octet **buffer, size_t *lenremain)
{
krb5_error_code kret;
krb5_address *address;
size_t required;
krb5_octet *bp;
size_t remain;
required = 0;
bp = *buffer;
remain = *lenremain;
kret = EINVAL;
/* Solaris Kerberos */
address = (krb5_address *) arg;
if (address) {
kret = ENOMEM;
if (!krb5_address_size(kcontext, arg, &required) &&
(required <= remain)) {
/* Our identifier */
(void) krb5_ser_pack_int32(KV5M_ADDRESS, &bp, &remain);
/* Our addrtype */
(void) krb5_ser_pack_int32((krb5_int32) address->addrtype,
&bp, &remain);
/* Our length */
(void) krb5_ser_pack_int32((krb5_int32) address->length,
&bp, &remain);
/* Our contents */
(void) krb5_ser_pack_bytes(address->contents,
(size_t) address->length,
&bp, &remain);
/* Finally, our trailer */
(void) krb5_ser_pack_int32(KV5M_ADDRESS, &bp, &remain);
kret = 0;
*buffer = bp;
*lenremain = remain;
}
}
return(kret);
}
/*
* krb5_address_internalize() - Internalize the krb5_address.
*/
/*ARGSUSED*/
static krb5_error_code
krb5_address_internalize(krb5_context kcontext, krb5_pointer *argp, krb5_octet **buffer, size_t *lenremain)
{
krb5_error_code kret;
krb5_address *address;
krb5_int32 ibuf;
krb5_octet *bp;
size_t remain;
bp = *buffer;
remain = *lenremain;
kret = EINVAL;
/* Read our magic number */
if (krb5_ser_unpack_int32(&ibuf, &bp, &remain))
ibuf = 0;
if (ibuf == KV5M_ADDRESS) {
kret = ENOMEM;
/* Get a address */
if ((remain >= (2*sizeof(krb5_int32))) &&
(address = (krb5_address *) MALLOC(sizeof(krb5_address)))) {
(void) memset(address, 0, sizeof(krb5_address));
address->magic = KV5M_ADDRESS;
/* Get the addrtype */
(void) krb5_ser_unpack_int32(&ibuf, &bp, &remain);
address->addrtype = (krb5_addrtype) ibuf;
/* Get the length */
(void) krb5_ser_unpack_int32(&ibuf, &bp, &remain);
address->length = (int) ibuf;
/* Get the string */
/* Solaris Kerberos */
address->contents = (krb5_octet *) MALLOC((size_t) (ibuf));
if ((address->contents) &&
!(kret = krb5_ser_unpack_bytes(address->contents,
(size_t) ibuf,
&bp, &remain))) {
/* Get the trailer */
if ((kret = krb5_ser_unpack_int32(&ibuf, &bp, &remain)))
ibuf = 0;
if (!kret && (ibuf == KV5M_ADDRESS)) {
address->magic = KV5M_ADDRESS;
*buffer = bp;
*lenremain = remain;
*argp = (krb5_pointer) address;
}
else
kret = EINVAL;
}
if (kret) {
if (address->contents)
FREE(address->contents, address->length);
FREE(address, sizeof (krb5_address));
}
}
}
return(kret);
}
/*
* Register the address serializer.
*/
krb5_error_code
krb5_ser_address_init(krb5_context kcontext)
{
return(krb5_register_serializer(kcontext, &krb5_address_ser_entry));
}
/*
* lib/krb5/krb/ser_auth.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.
*
*/
/*
* ser_auth.c - Serialize krb5_authenticator structure.
*/
#include "k5-int.h"
#include "int-proto.h"
/*
* Routines to deal with externalizing the krb5_authenticator:
* krb5_authenticator_size();
* krb5_authenticator_externalize();
* krb5_authenticator_internalize();
*/
static krb5_error_code krb5_authenticator_size
(krb5_context, krb5_pointer, size_t *);
static krb5_error_code krb5_authenticator_externalize
(krb5_context, krb5_pointer, krb5_octet **, size_t *);
static krb5_error_code krb5_authenticator_internalize
(krb5_context,krb5_pointer *, krb5_octet **, size_t *);
/* Local data */
static const krb5_ser_entry krb5_authenticator_ser_entry = {
KV5M_AUTHENTICATOR, /* Type */
krb5_authenticator_size, /* Sizer routine */
krb5_authenticator_externalize, /* Externalize routine */
krb5_authenticator_internalize /* Internalize routine */
};
/*
* krb5_authenticator_size() - Determine the size required to externalize
* the krb5_authenticator.
*/
static krb5_error_code
krb5_authenticator_size(krb5_context kcontext, krb5_pointer arg, size_t *sizep)
{
krb5_error_code kret;
krb5_authenticator *authenticator;
size_t required;
/*
* krb5_authenticator requires at minimum:
* krb5_int32 for KV5M_AUTHENTICATOR
* krb5_int32 for seconds
* krb5_int32 for cusec
* krb5_int32 for seq_number
* krb5_int32 for number in authorization_data array.
* krb5_int32 for KV5M_AUTHENTICATOR
*/
kret = EINVAL;
/* Solaris Kerberos */
authenticator = (krb5_authenticator *) arg;
if (authenticator) {
required = sizeof(krb5_int32)*6;
/* Calculate size required by client, if appropriate */
if (authenticator->client)
kret = krb5_size_opaque(kcontext,
KV5M_PRINCIPAL,
(krb5_pointer) authenticator->client,
&required);
else
kret = 0;
/* Calculate size required by checksum, if appropriate */
if (!kret && authenticator->checksum)
kret = krb5_size_opaque(kcontext,
KV5M_CHECKSUM,
(krb5_pointer) authenticator->checksum,
&required);
/* Calculate size required by subkey, if appropriate */
if (!kret && authenticator->subkey)
kret = krb5_size_opaque(kcontext,
KV5M_KEYBLOCK,
(krb5_pointer) authenticator->subkey,
&required);
/* Calculate size required by authorization_data, if appropriate */
if (!kret && authenticator->authorization_data) {
int i;
for (i=0; !kret && authenticator->authorization_data[i]; i++) {
kret = krb5_size_opaque(kcontext,
KV5M_AUTHDATA,
(krb5_pointer) authenticator->
authorization_data[i],
&required);
}
}
}
if (!kret)
*sizep += required;
return(kret);
}
/*
* krb5_authenticator_externalize() - Externalize the krb5_authenticator.
*/
static krb5_error_code
krb5_authenticator_externalize(krb5_context kcontext, krb5_pointer arg, krb5_octet **buffer, size_t *lenremain)
{
krb5_error_code kret;
krb5_authenticator *authenticator;
size_t required;
krb5_octet *bp;
size_t remain;
int i;
required = 0;
bp = *buffer;
remain = *lenremain;
kret = EINVAL;
/* Solaris Kerberos */
authenticator = (krb5_authenticator *) arg;
if (authenticator) {
kret = ENOMEM;
if (!krb5_authenticator_size(kcontext, arg, &required) &&
(required <= remain)) {
/* First write our magic number */
(void) krb5_ser_pack_int32(KV5M_AUTHENTICATOR, &bp, &remain);
/* Now ctime */
(void) krb5_ser_pack_int32((krb5_int32) authenticator->ctime,
&bp, &remain);
/* Now cusec */
(void) krb5_ser_pack_int32((krb5_int32) authenticator->cusec,
&bp, &remain);
/* Now seq_number */
(void) krb5_ser_pack_int32(authenticator->seq_number,
&bp, &remain);
/* Now handle client, if appropriate */
if (authenticator->client)
kret = krb5_externalize_opaque(kcontext,
KV5M_PRINCIPAL,
(krb5_pointer)
authenticator->client,
&bp,
&remain);
else
kret = 0;
/* Now handle checksum, if appropriate */
if (!kret && authenticator->checksum)
kret = krb5_externalize_opaque(kcontext,
KV5M_CHECKSUM,
(krb5_pointer)
authenticator->checksum,
&bp,
&remain);
/* Now handle subkey, if appropriate */
if (!kret && authenticator->subkey)
kret = krb5_externalize_opaque(kcontext,
KV5M_KEYBLOCK,
(krb5_pointer)
authenticator->subkey,
&bp,
&remain);
/* Now handle authorization_data, if appropriate */
if (!kret) {
if (authenticator->authorization_data)
for (i=0; authenticator->authorization_data[i]; i++);
else
i = 0;
(void) krb5_ser_pack_int32((krb5_int32) i, &bp, &remain);
/* Now pound out the authorization_data */
if (authenticator->authorization_data) {
for (i=0; !kret && authenticator->authorization_data[i];
i++)
kret = krb5_externalize_opaque(kcontext,
KV5M_AUTHDATA,
(krb5_pointer)
authenticator->
authorization_data[i],
&bp,
&remain);
}
}
/*
* If we were successful, write trailer then update the pointer and
* remaining length;
*/
if (!kret) {
/* Write our trailer */
(void) krb5_ser_pack_int32(KV5M_AUTHENTICATOR, &bp, &remain);
*buffer = bp;
*lenremain = remain;
}
}
}
return(kret);
}
/*
* krb5_authenticator_internalize() - Internalize the krb5_authenticator.
*/
static krb5_error_code
krb5_authenticator_internalize(krb5_context kcontext, krb5_pointer *argp, krb5_octet **buffer, size_t *lenremain)
{
krb5_error_code kret;
krb5_authenticator *authenticator;
krb5_int32 ibuf;
krb5_octet *bp;
size_t remain;
int i;
krb5_int32 nadata;
size_t len;
bp = *buffer;
remain = *lenremain;
kret = EINVAL;
/* Read our magic number */
if (krb5_ser_unpack_int32(&ibuf, &bp, &remain))
ibuf = 0;
if (ibuf == KV5M_AUTHENTICATOR) {
kret = ENOMEM;
/* Get memory for the authenticator */
if ((remain >= (3*sizeof(krb5_int32))) &&
(authenticator = (krb5_authenticator *)
MALLOC(sizeof(krb5_authenticator)))) {
(void) memset(authenticator, 0, sizeof(krb5_authenticator));
/* Get ctime */
(void) krb5_ser_unpack_int32(&ibuf, &bp, &remain);
authenticator->ctime = (krb5_timestamp) ibuf;
/* Get cusec */
(void) krb5_ser_unpack_int32(&ibuf, &bp, &remain);
authenticator->cusec = ibuf;
/* Get seq_number */
(void) krb5_ser_unpack_int32(&ibuf, &bp, &remain);
authenticator->seq_number = ibuf;
kret = 0;
/* Attempt to read in the client */
kret = krb5_internalize_opaque(kcontext,
KV5M_PRINCIPAL,
(krb5_pointer *)
&authenticator->client,
&bp,
&remain);
if (kret == EINVAL)
kret = 0;
/* Attempt to read in the checksum */
if (!kret) {
kret = krb5_internalize_opaque(kcontext,
KV5M_CHECKSUM,
(krb5_pointer *)
&authenticator->checksum,
&bp,
&remain);
if (kret == EINVAL)
kret = 0;
}
/* Attempt to read in the subkey */
if (!kret) {
kret = krb5_internalize_opaque(kcontext,
KV5M_KEYBLOCK,
(krb5_pointer *)
&authenticator->subkey,
&bp,
&remain);
if (kret == EINVAL)
kret = 0;
}
/* Attempt to read in the authorization data count */
if (!(kret = krb5_ser_unpack_int32(&ibuf, &bp, &remain))) {
nadata = ibuf;
len = (size_t) (nadata + 1);
/* Get memory for the authorization data pointers */
if ((authenticator->authorization_data = (krb5_authdata **)
MALLOC(sizeof(krb5_authdata *) * len))) {
(void) memset(authenticator->authorization_data, 0,
sizeof(krb5_authdata *) * len);
for (i=0; !kret && (i<nadata); i++) {
kret = krb5_internalize_opaque(kcontext,
KV5M_AUTHDATA,
(krb5_pointer *)
&authenticator->
authorization_data[i],
&bp,
&remain);
}
/* Finally, find the trailer */
if (!kret) {
kret = krb5_ser_unpack_int32(&ibuf, &bp, &remain);
if (!kret && (ibuf == KV5M_AUTHENTICATOR))
authenticator->magic = KV5M_AUTHENTICATOR;
else
kret = EINVAL;
}
}
}
if (!kret) {
*buffer = bp;
*lenremain = remain;
*argp = (krb5_pointer) authenticator;
}
else
krb5_free_authenticator(kcontext, authenticator);
}
}
return(kret);
}
/*
* Register the authenticator serializer.
*/
krb5_error_code
krb5_ser_authenticator_init(krb5_context kcontext)
{
return(krb5_register_serializer(kcontext, &krb5_authenticator_ser_entry));
}
/*
* lib/krb5/krb/ser_cksum.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.
*
*/
/*
* ser_cksum.c - Serialize a krb5_checksum structure.
*/
#include "k5-int.h"
#include "int-proto.h"
/*
* Routines to deal with externalizing the krb5_checksum:
* krb5_checksum_esize();
* krb5_checksum_externalize();
* krb5_checksum_internalize();
*/
static krb5_error_code krb5_checksum_esize
(krb5_context, krb5_pointer, size_t *);
static krb5_error_code krb5_checksum_externalize
(krb5_context, krb5_pointer, krb5_octet **, size_t *);
static krb5_error_code krb5_checksum_internalize
(krb5_context,krb5_pointer *, krb5_octet **, size_t *);
/* Local data */
static const krb5_ser_entry krb5_checksum_ser_entry = {
KV5M_CHECKSUM, /* Type */
krb5_checksum_esize, /* Sizer routine */
krb5_checksum_externalize, /* Externalize routine */
krb5_checksum_internalize /* Internalize routine */
};
/*
* krb5_checksum_esize() - Determine the size required to externalize
* the krb5_checksum.
*/
/*ARGSUSED*/
static krb5_error_code
krb5_checksum_esize(krb5_context kcontext, krb5_pointer arg, size_t *sizep)
{
krb5_error_code kret;
krb5_checksum *checksum;
/*
* krb5_checksum requires:
* krb5_int32 for KV5M_CHECKSUM
* krb5_int32 for checksum_type
* krb5_int32 for length
* krb5_int32 for KV5M_CHECKSUM
* checksum->length for contents
*/
kret = EINVAL;
/* Solaris Kerberos */
checksum = (krb5_checksum *) arg;
if (checksum) {
*sizep += (sizeof(krb5_int32) +
sizeof(krb5_int32) +
sizeof(krb5_int32) +
sizeof(krb5_int32) +
(size_t) checksum->length);
kret = 0;
}
return(kret);
}
/*
* krb5_checksum_externalize() - Externalize the krb5_checksum.
*/
static krb5_error_code
krb5_checksum_externalize(krb5_context kcontext, krb5_pointer arg, krb5_octet **buffer, size_t *lenremain)
{
krb5_error_code kret;
krb5_checksum *checksum;
size_t required;
krb5_octet *bp;
size_t remain;
required = 0;
bp = *buffer;
remain = *lenremain;
kret = EINVAL;
/* Solaris Kerberos */
checksum = (krb5_checksum *) arg;
if (checksum) {
kret = ENOMEM;
if (!krb5_checksum_esize(kcontext, arg, &required) &&
(required <= remain)) {
/* Our identifier */
(void) krb5_ser_pack_int32(KV5M_CHECKSUM, &bp, &remain);
/* Our checksum_type */
(void) krb5_ser_pack_int32((krb5_int32) checksum->checksum_type,
&bp, &remain);
/* Our length */
(void) krb5_ser_pack_int32((krb5_int32) checksum->length,
&bp, &remain);
/* Our contents */
(void) krb5_ser_pack_bytes(checksum->contents,
(size_t) checksum->length,
&bp, &remain);
/* Finally, our trailer */
(void) krb5_ser_pack_int32(KV5M_CHECKSUM, &bp, &remain);
kret = 0;
*buffer = bp;
*lenremain = remain;
}
}
return(kret);
}
/*
* krb5_checksum_internalize() - Internalize the krb5_checksum.
*/
/*ARGSUSED*/
static krb5_error_code
krb5_checksum_internalize(krb5_context kcontext, krb5_pointer *argp, krb5_octet **buffer, size_t *lenremain)
{
krb5_error_code kret;
krb5_checksum *checksum;
krb5_int32 ibuf;
krb5_octet *bp;
size_t remain;
bp = *buffer;
remain = *lenremain;
kret = EINVAL;
/* Read our magic number */
if (krb5_ser_unpack_int32(&ibuf, &bp, &remain))
ibuf = 0;
if (ibuf == KV5M_CHECKSUM) {
kret = ENOMEM;
/* Get a checksum */
if ((remain >= (2*sizeof(krb5_int32))) &&
(checksum = (krb5_checksum *) MALLOC(sizeof(krb5_checksum)))) {
(void) memset(checksum, 0, sizeof(krb5_checksum));
/* Get the checksum_type */
(void) krb5_ser_unpack_int32(&ibuf, &bp, &remain);
checksum->checksum_type = (krb5_cksumtype) ibuf;
/* Get the length */
(void) krb5_ser_unpack_int32(&ibuf, &bp, &remain);
checksum->length = (int) ibuf;
/* Get the string */
/* Solaris Kerberos */
if (ibuf)
checksum->contents = (krb5_octet *)
MALLOC((size_t) (ibuf));
if (!ibuf ||
((checksum->contents) &&
!(kret = krb5_ser_unpack_bytes(checksum->contents,
(size_t) ibuf,
&bp, &remain)))) {
/* Get the trailer */
kret = krb5_ser_unpack_int32(&ibuf, &bp, &remain);
if (!kret && (ibuf == KV5M_CHECKSUM)) {
checksum->magic = KV5M_CHECKSUM;
*buffer = bp;
*lenremain = remain;
*argp = (krb5_pointer) checksum;
}
else
kret = EINVAL;
}
if (kret) {
if (checksum->contents)
FREE(checksum->contents, checksum->length);
FREE(checksum, sizeof (krb5_checksum));
}
}
}
return(kret);
}
/*
* Register the checksum serializer.
*/
krb5_error_code
krb5_ser_checksum_init(krb5_context kcontext)
{
return(krb5_register_serializer(kcontext, &krb5_checksum_ser_entry));
}
/*
* lib/krb5/krb/ser_ctx.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.
*
*/
/*
* ser_ctx.c - Routines to deal with serializing the krb5_context and
* krb5_os_context structures.
*/
#include "k5-int.h"
/*
* Routines to deal with externalizing the krb5_context:
* krb5_context_size();
* krb5_context_externalize();
* krb5_context_internalize();
*
* Routines to deal with externalizing the krb5_os_context:
* krb5_oscontext_size();
* krb5_oscontext_externalize();
* krb5_oscontext_internalize();
*
* Routines to deal with externalizing the profile.
* profile_ser_size();
* profile_ser_externalize();
* profile_ser_internalize();
*
* Interface to initialize serializing of krb5_context and krb5_os_context:
* krb5_ser_context_init();
*/
static krb5_error_code krb5_context_size
(krb5_context, krb5_pointer, size_t *);
static krb5_error_code krb5_context_externalize
(krb5_context, krb5_pointer, krb5_octet **, size_t *);
static krb5_error_code krb5_context_internalize
(krb5_context,krb5_pointer *, krb5_octet **, size_t *);
static krb5_error_code krb5_oscontext_size
(krb5_context, krb5_pointer, size_t *);
static krb5_error_code krb5_oscontext_externalize
(krb5_context, krb5_pointer, krb5_octet **, size_t *);
static krb5_error_code krb5_oscontext_internalize
(krb5_context,krb5_pointer *, krb5_octet **, size_t *);
#ifndef _KERNEL
krb5_error_code profile_ser_size
(krb5_context, krb5_pointer, size_t *);
krb5_error_code profile_ser_externalize
(krb5_context, krb5_pointer, krb5_octet **, size_t *);
krb5_error_code profile_ser_internalize
(krb5_context,krb5_pointer *, krb5_octet **, size_t *);
#endif
/* Local data */
static const krb5_ser_entry krb5_context_ser_entry = {
KV5M_CONTEXT, /* Type */
krb5_context_size, /* Sizer routine */
krb5_context_externalize, /* Externalize routine */
krb5_context_internalize /* Internalize routine */
};
static const krb5_ser_entry krb5_oscontext_ser_entry = {
KV5M_OS_CONTEXT, /* Type */
krb5_oscontext_size, /* Sizer routine */
krb5_oscontext_externalize, /* Externalize routine */
krb5_oscontext_internalize /* Internalize routine */
};
#ifndef _KERNEL
static const krb5_ser_entry krb5_profile_ser_entry = {
PROF_MAGIC_PROFILE, /* Type */
profile_ser_size, /* Sizer routine */
profile_ser_externalize, /* Externalize routine */
profile_ser_internalize /* Internalize routine */
};
#endif
/*
* krb5_context_size() - Determine the size required to externalize the
* krb5_context.
*/
static krb5_error_code
krb5_context_size(krb5_context kcontext, krb5_pointer arg, size_t *sizep)
{
krb5_error_code kret;
size_t required;
krb5_context context;
/*
* The KRB5 context itself requires:
* krb5_int32 for KV5M_CONTEXT
* krb5_int32 for sizeof(default_realm)
* strlen(default_realm) for default_realm.
* krb5_int32 for n_in_tkt_ktypes*sizeof(krb5_int32)
* nktypes*sizeof(krb5_int32) for in_tkt_ktypes.
* krb5_int32 for n_tgs_ktypes*sizeof(krb5_int32)
* nktypes*sizeof(krb5_int32) for tgs_ktypes.
* krb5_int32 for clockskew
* krb5_int32 for kdc_req_sumtype
* krb5_int32 for ap_req_sumtype
* krb5_int32 for safe_sumtype
* krb5_int32 for kdc_default_options
* krb5_int32 for library_options
* krb5_int32 for profile_secure
* krb5_int32 for fcc_default_format
* krb5_int32 for scc_default_format
* <> for os_context
* <> for db_context
* <> for profile
* krb5_int32 for trailer.
*/
kret = EINVAL;
if ((context = (krb5_context) arg)) {
/* Calculate base length */
required = (14 * sizeof(krb5_int32) +
(context->in_tkt_ktype_count * sizeof(krb5_int32)) +
(context->tgs_ktype_count * sizeof(krb5_int32)));
if (context->default_realm)
required += strlen(context->default_realm);
/* Calculate size required by os_context, if appropriate */
if (context->os_context)
kret = krb5_size_opaque(kcontext,
KV5M_OS_CONTEXT,
(krb5_pointer) context->os_context,
&required);
/* Calculate size required by db_context, if appropriate */
if (!kret && context->db_context)
kret = krb5_size_opaque(kcontext,
KV5M_DB_CONTEXT,
(krb5_pointer) context->db_context,
&required);
/* Finally, calculate size required by profile, if appropriate */
if (!kret && context->profile)
kret = krb5_size_opaque(kcontext,
PROF_MAGIC_PROFILE,
(krb5_pointer) context->profile,
&required);
}
if (!kret)
*sizep += required;
return(kret);
}
/*
* krb5_context_externalize() - Externalize the krb5_context.
*/
static krb5_error_code
krb5_context_externalize(krb5_context kcontext, krb5_pointer arg, krb5_octet **buffer, size_t *lenremain)
{
krb5_error_code kret;
krb5_context context;
size_t required;
krb5_octet *bp;
size_t remain;
int i;
required = 0;
bp = *buffer;
remain = *lenremain;
context = (krb5_context) arg;
if (!context)
return (EINVAL);
KRB5_VERIFY_MAGIC(context, KV5M_CONTEXT);
if ((kret = krb5_context_size(kcontext, arg, &required)))
return (kret);
if (required > remain)
return (ENOMEM);
/* First write our magic number */
kret = krb5_ser_pack_int32(KV5M_CONTEXT, &bp, &remain);
if (kret)
return (kret);
/* Now sizeof default realm */
kret = krb5_ser_pack_int32((context->default_realm) ?
(krb5_int32) strlen(context->default_realm) : 0,
&bp, &remain);
if (kret)
return (kret);
/* Now default_realm bytes */
if (context->default_realm) {
kret = krb5_ser_pack_bytes((krb5_octet *) context->default_realm,
strlen(context->default_realm),
&bp, &remain);
if (kret)
return (kret);
}
/* Now number of initial ticket ktypes */
kret = krb5_ser_pack_int32((krb5_int32) context->in_tkt_ktype_count,
&bp, &remain);
if (kret)
return (kret);
/* Now serialize ktypes */
for (i=0; i<context->in_tkt_ktype_count; i++) {
kret = krb5_ser_pack_int32((krb5_int32) context->in_tkt_ktypes[i],
&bp, &remain);
if (kret)
return (kret);
}
/* Now number of default ktypes */
kret = krb5_ser_pack_int32((krb5_int32) context->tgs_ktype_count,
&bp, &remain);
if (kret)
return (kret);
/* Now serialize ktypes */
for (i=0; i<context->tgs_ktype_count; i++) {
kret = krb5_ser_pack_int32((krb5_int32) context->tgs_ktypes[i],
&bp, &remain);
if (kret)
return (kret);
}
/* Now allowable clockskew */
kret = krb5_ser_pack_int32((krb5_int32) context->clockskew,
&bp, &remain);
if (kret)
return (kret);
/* Now kdc_req_sumtype */
kret = krb5_ser_pack_int32((krb5_int32) context->kdc_req_sumtype,
&bp, &remain);
if (kret)
return (kret);
/* Now default ap_req_sumtype */
kret = krb5_ser_pack_int32((krb5_int32) context->default_ap_req_sumtype,
&bp, &remain);
if (kret)
return (kret);
/* Now default safe_sumtype */
kret = krb5_ser_pack_int32((krb5_int32) context->default_safe_sumtype,
&bp, &remain);
if (kret)
return (kret);
/* Now kdc_default_options */
kret = krb5_ser_pack_int32((krb5_int32) context->kdc_default_options,
&bp, &remain);
if (kret)
return (kret);
/* Now library_options */
kret = krb5_ser_pack_int32((krb5_int32) context->library_options,
&bp, &remain);
if (kret)
return (kret);
/* Now profile_secure */
kret = krb5_ser_pack_int32((krb5_int32) context->profile_secure,
&bp, &remain);
if (kret)
return (kret);
/* Now fcc_default_format */
kret = krb5_ser_pack_int32((krb5_int32) context->fcc_default_format,
&bp, &remain);
if (kret)
return (kret);
/* Now scc_default_format */
kret = krb5_ser_pack_int32((krb5_int32) context->scc_default_format,
&bp, &remain);
if (kret)
return (kret);
/* Now handle os_context, if appropriate */
if (context->os_context) {
kret = krb5_externalize_opaque(kcontext, KV5M_OS_CONTEXT,
(krb5_pointer) context->os_context,
&bp, &remain);
if (kret)
return (kret);
}
/* Now handle database context, if appropriate */
if (context->db_context) {
kret = krb5_externalize_opaque(kcontext, KV5M_DB_CONTEXT,
(krb5_pointer) context->db_context,
&bp, &remain);
if (kret)
return (kret);
}
/* Finally, handle profile, if appropriate */
if (context->profile) {
kret = krb5_externalize_opaque(kcontext, PROF_MAGIC_PROFILE,
(krb5_pointer) context->profile,
&bp, &remain);
if (kret)
return (kret);
}
/*
* If we were successful, write trailer then update the pointer and
* remaining length;
*/
kret = krb5_ser_pack_int32(KV5M_CONTEXT, &bp, &remain);
if (kret)
return (kret);
*buffer = bp;
*lenremain = remain;
return (0);
}
/*
* krb5_context_internalize() - Internalize the krb5_context.
*/
static krb5_error_code
krb5_context_internalize(krb5_context kcontext, krb5_pointer *argp, krb5_octet **buffer, size_t *lenremain)
{
krb5_error_code kret;
krb5_context context;
krb5_int32 ibuf;
krb5_octet *bp;
size_t remain;
int i;
bp = *buffer;
remain = *lenremain;
/* Read our magic number */
if ((kret = krb5_ser_unpack_int32(&ibuf, &bp, &remain)))
return (EINVAL);
if (ibuf != KV5M_CONTEXT)
return (EINVAL);
/* Get memory for the context */
context = (krb5_context) MALLOC(sizeof(struct _krb5_context));
if (!context)
return (ENOMEM);
(void) memset(context, 0, sizeof(struct _krb5_context));
/* Get the size of the default realm */
if ((kret = krb5_ser_unpack_int32(&ibuf, &bp, &remain)))
goto cleanup;
if (ibuf) {
context->default_realm = (char *) MALLOC((size_t) ibuf+1);
if (!context->default_realm) {
kret = ENOMEM;
goto cleanup;
}
kret = krb5_ser_unpack_bytes((krb5_octet *) context->default_realm,
(size_t) ibuf, &bp, &remain);
if (kret)
goto cleanup;
context->default_realm[ibuf] = '\0';
}
/* Get the number of in_tkt_ktypes */
if ((kret = krb5_ser_unpack_int32(&ibuf, &bp, &remain)))
goto cleanup;
context->in_tkt_ktype_count = (int) ibuf;
context->in_tkt_ktypes = (krb5_enctype *) MALLOC(sizeof(krb5_enctype) *
(context->in_tkt_ktype_count+1));
if (!context->in_tkt_ktypes) {
kret = ENOMEM;
goto cleanup;
}
(void) memset(context->in_tkt_ktypes, 0, (sizeof(krb5_enctype) *
(context->in_tkt_ktype_count + 1)));
for (i=0; i<context->in_tkt_ktype_count; i++) {
if ((kret = krb5_ser_unpack_int32(&ibuf, &bp, &remain)))
goto cleanup;
context->in_tkt_ktypes[i] = (krb5_enctype) ibuf;
}
/* Get the number of tgs_ktypes */
if ((kret = krb5_ser_unpack_int32(&ibuf, &bp, &remain)))
goto cleanup;
context->tgs_ktype_count = (int) ibuf;
context->tgs_ktypes = (krb5_enctype *) MALLOC(sizeof(krb5_enctype) *
(context->tgs_ktype_count+1));
if (!context->tgs_ktypes) {
kret = ENOMEM;
goto cleanup;
}
(void) memset(context->tgs_ktypes, 0, (sizeof(krb5_enctype) *
(context->tgs_ktype_count + 1)));
for (i=0; i<context->tgs_ktype_count; i++) {
if ((kret = krb5_ser_unpack_int32(&ibuf, &bp, &remain)))
goto cleanup;
context->tgs_ktypes[i] = (krb5_enctype) ibuf;
}
/* Allowable checksum */
if ((kret = krb5_ser_unpack_int32(&ibuf, &bp, &remain)))
goto cleanup;
context->clockskew = (krb5_deltat) ibuf;
/* kdc_req_sumtype */
if ((kret = krb5_ser_unpack_int32(&ibuf, &bp, &remain)))
goto cleanup;
context->kdc_req_sumtype = (krb5_cksumtype) ibuf;
/* default ap_req_sumtype */
if ((kret = krb5_ser_unpack_int32(&ibuf, &bp, &remain)))
goto cleanup;
context->default_ap_req_sumtype = (krb5_cksumtype) ibuf;
/* default_safe_sumtype */
if ((kret = krb5_ser_unpack_int32(&ibuf, &bp, &remain)))
goto cleanup;
context->default_safe_sumtype = (krb5_cksumtype) ibuf;
/* kdc_default_options */
if ((kret = krb5_ser_unpack_int32(&ibuf, &bp, &remain)))
goto cleanup;
context->kdc_default_options = (krb5_flags) ibuf;
/* library_options */
if ((kret = krb5_ser_unpack_int32(&ibuf, &bp, &remain)))
goto cleanup;
context->library_options = (krb5_flags) ibuf;
/* profile_secure */
if ((kret = krb5_ser_unpack_int32(&ibuf, &bp, &remain)))
goto cleanup;
context->profile_secure = (krb5_boolean) ibuf;
/* fcc_default_format */
if ((kret = krb5_ser_unpack_int32(&ibuf, &bp, &remain)))
goto cleanup;
context->fcc_default_format = (int) ibuf;
/* scc_default_format */
if ((kret = krb5_ser_unpack_int32(&ibuf, &bp, &remain)))
goto cleanup;
context->scc_default_format = (int) ibuf;
/* Attempt to read in the os_context. It's an array now, but
we still treat it in most places as a separate object with
a pointer. */
{
krb5_os_context osp = 0;
kret = krb5_internalize_opaque(kcontext, KV5M_OS_CONTEXT,
(krb5_pointer *) &osp,
&bp, &remain);
if (kret && (kret != EINVAL) && (kret != ENOENT))
goto cleanup;
/* Put the newly allocated data into the krb5_context
structure where we're really keeping it these days. */
if (osp)
*context->os_context = *osp;
free(osp);
}
/* Attempt to read in the db_context */
kret = krb5_internalize_opaque(kcontext, KV5M_DB_CONTEXT,
(krb5_pointer *) &context->db_context,
&bp, &remain);
if (kret && (kret != EINVAL) && (kret != ENOENT))
goto cleanup;
#ifndef _KERNEL
/* Attempt to read in the profile */
kret = krb5_internalize_opaque(kcontext, PROF_MAGIC_PROFILE,
(krb5_pointer *) &context->profile,
&bp, &remain);
#endif
if (kret && (kret != EINVAL) && (kret != ENOENT))
goto cleanup;
/* Finally, find the trailer */
if ((kret = krb5_ser_unpack_int32(&ibuf, &bp, &remain)))
goto cleanup;
if (ibuf != KV5M_CONTEXT) {
kret = EINVAL;
goto cleanup;
}
context->magic = KV5M_CONTEXT;
*buffer = bp;
*lenremain = remain;
*argp = (krb5_pointer) context;
return 0;
cleanup:
if (context)
krb5_free_context(context);
return(kret);
}
/*
* krb5_oscontext_size() - Determine the size required to externalize
* the krb5_os_context.
*/
/*ARGSUSED*/
static krb5_error_code
krb5_oscontext_size(krb5_context kcontext, krb5_pointer arg, size_t *sizep)
{
/*
* We need five 32-bit integers:
* two for header and trailer
* one each for time_offset, usec_offset and os_flags
*/
*sizep += (5*sizeof(krb5_int32));
return(0);
}
/*
* krb5_oscontext_externalize() - Externalize the krb5_os_context.
*/
static krb5_error_code
krb5_oscontext_externalize(krb5_context kcontext, krb5_pointer arg, krb5_octet **buffer, size_t *lenremain)
{
krb5_error_code kret;
krb5_os_context os_ctx;
size_t required;
krb5_octet *bp;
size_t remain;
required = 0;
bp = *buffer;
remain = *lenremain;
kret = EINVAL;
if ((os_ctx = (krb5_os_context) arg)) {
kret = ENOMEM;
if (!krb5_oscontext_size(kcontext, arg, &required) &&
(required <= remain)) {
(void) krb5_ser_pack_int32(KV5M_OS_CONTEXT, &bp, &remain);
(void) krb5_ser_pack_int32(os_ctx->time_offset, &bp, &remain);
(void) krb5_ser_pack_int32(os_ctx->usec_offset, &bp, &remain);
(void) krb5_ser_pack_int32(os_ctx->os_flags, &bp, &remain);
(void) krb5_ser_pack_int32(KV5M_OS_CONTEXT, &bp, &remain);
/* Handle any other OS context here */
kret = 0;
if (!kret) {
*buffer = bp;
*lenremain = remain;
}
}
}
return(kret);
}
/*
* krb5_oscontext_internalize() - Internalize the krb5_os_context.
*/
/*ARGSUSED*/
static krb5_error_code
krb5_oscontext_internalize(krb5_context kcontext, krb5_pointer *argp, krb5_octet **buffer, size_t *lenremain)
{
krb5_error_code kret;
krb5_os_context os_ctx;
krb5_int32 ibuf;
krb5_octet *bp;
size_t remain;
bp = *buffer;
remain = *lenremain;
kret = EINVAL;
os_ctx = (krb5_os_context) NULL;
/* Read our magic number */
if (krb5_ser_unpack_int32(&ibuf, &bp, &remain))
ibuf = 0;
if (ibuf == KV5M_OS_CONTEXT) {
kret = ENOMEM;
/* Get memory for the context */
if ((os_ctx = (krb5_os_context)
MALLOC(sizeof(struct _krb5_os_context))) &&
(remain >= 4*sizeof(krb5_int32))) {
(void) memset(os_ctx, 0, sizeof(struct _krb5_os_context));
os_ctx->magic = KV5M_OS_CONTEXT;
/* Read out our context */
(void) krb5_ser_unpack_int32(&os_ctx->time_offset, &bp, &remain);
(void) krb5_ser_unpack_int32(&os_ctx->usec_offset, &bp, &remain);
(void) krb5_ser_unpack_int32(&os_ctx->os_flags, &bp, &remain);
(void) krb5_ser_unpack_int32(&ibuf, &bp, &remain);
if (ibuf == KV5M_OS_CONTEXT) {
os_ctx->magic = KV5M_OS_CONTEXT;
kret = 0;
*buffer = bp;
*lenremain = remain;
} else
kret = EINVAL;
}
}
if (!kret) {
*argp = (krb5_pointer) os_ctx;
}
else {
if (os_ctx)
FREE(os_ctx, sizeof(struct _krb5_os_context));
}
return(kret);
}
/*
* Register the context serializers.
*/
krb5_error_code KRB5_CALLCONV
krb5_ser_context_init(krb5_context kcontext)
{
krb5_error_code kret;
kret = krb5_register_serializer(kcontext, &krb5_context_ser_entry);
if (!kret)
kret = krb5_register_serializer(kcontext, &krb5_oscontext_ser_entry);
/* Profile nformation need not be serialzied when we are importing the
* context into kernel. Besides the function pointers to file access
* routines can't be used in the kernel.
* Any info needed from the profile is already a part of the
* exported context obviating the need for importer to know about
* profile config files.
*/
#ifndef _KERNEL
if (!kret)
kret = krb5_register_serializer(kcontext, &krb5_profile_ser_entry);
#endif
return(kret);
}
/*
* lib/krb5/krb/ser_key.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. 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.
*
*/
/*
* ser_key.c - Serialize a krb5_keyblock structure.
*/
#include "k5-int.h"
#include "int-proto.h"
/*
* Routines to deal with externalizing the krb5_keyblock:
* krb5_keyblock_size();
* krb5_keyblock_externalize();
* krb5_keyblock_internalize();
*/
static krb5_error_code krb5_keyblock_size
(krb5_context, krb5_pointer, size_t *);
static krb5_error_code krb5_keyblock_externalize
(krb5_context, krb5_pointer, krb5_octet **, size_t *);
static krb5_error_code krb5_keyblock_internalize
(krb5_context,krb5_pointer *, krb5_octet **, size_t *);
/* Local data */
static const krb5_ser_entry krb5_keyblock_ser_entry = {
KV5M_KEYBLOCK, /* Type */
krb5_keyblock_size, /* Sizer routine */
krb5_keyblock_externalize, /* Externalize routine */
krb5_keyblock_internalize /* Internalize routine */
};
/*
* krb5_keyblock_size() - Determine the size required to externalize
* the krb5_keyblock.
*/
/*ARGSUSED*/
static krb5_error_code
krb5_keyblock_size(krb5_context kcontext, krb5_pointer arg, size_t *sizep)
{
krb5_error_code kret;
krb5_keyblock *keyblock;
/*
* krb5_keyblock requires:
* krb5_int32 for KV5M_KEYBLOCK
* krb5_int32 for enctype
* krb5_int32 for length
* keyblock->length for contents
* krb5_int32 for KV5M_KEYBLOCK
*/
kret = EINVAL;
/* Solaris Kerberos */
keyblock = (krb5_keyblock *) arg;
if (keyblock) {
*sizep += (sizeof(krb5_int32) +
sizeof(krb5_int32) +
sizeof(krb5_int32) +
sizeof(krb5_int32) +
sizeof(krb5_int32) +
(size_t) keyblock->length);
kret = 0;
}
return(kret);
}
/*
* krb5_keyblock_externalize() - Externalize the krb5_keyblock.
*/
static krb5_error_code
krb5_keyblock_externalize(krb5_context kcontext, krb5_pointer arg, krb5_octet **buffer, size_t *lenremain)
{
krb5_error_code kret;
krb5_keyblock *keyblock;
size_t required;
krb5_octet *bp;
size_t remain;
required = 0;
bp = *buffer;
remain = *lenremain;
kret = EINVAL;
/* Solaris Kerberos */
keyblock = (krb5_keyblock *) arg;
if (keyblock) {
kret = ENOMEM;
if (!krb5_keyblock_size(kcontext, arg, &required) &&
(required <= remain)) {
/* Our identifier */
(void) krb5_ser_pack_int32(KV5M_KEYBLOCK, &bp, &remain);
/* Our enctype */
(void) krb5_ser_pack_int32((krb5_int32) keyblock->enctype,
&bp, &remain);
/* Our length */
(void) krb5_ser_pack_int32((krb5_int32) keyblock->length,
&bp, &remain);
/* Our contents */
(void) krb5_ser_pack_bytes(keyblock->contents,
(size_t) keyblock->length,
&bp, &remain);
/* Finally, our trailer */
(void) krb5_ser_pack_int32(KV5M_KEYBLOCK, &bp, &remain);
kret = 0;
*buffer = bp;
*lenremain = remain;
}
}
return(kret);
}
/*
* krb5_keyblock_internalize() - Internalize the krb5_keyblock.
*/
/*ARGSUSED*/
static krb5_error_code
krb5_keyblock_internalize(krb5_context kcontext, krb5_pointer *argp, krb5_octet **buffer, size_t *lenremain)
{
krb5_error_code kret;
krb5_keyblock *keyblock;
krb5_int32 ibuf;
krb5_octet *bp;
size_t remain;
bp = *buffer;
remain = *lenremain;
kret = EINVAL;
/* Read our magic number */
if (krb5_ser_unpack_int32(&ibuf, &bp, &remain))
ibuf = 0;
if (ibuf == KV5M_KEYBLOCK) {
kret = ENOMEM;
/* Get a keyblock */
if ((remain >= (3*sizeof(krb5_int32))) &&
(keyblock = (krb5_keyblock *) MALLOC(sizeof(krb5_keyblock)))) {
(void) memset(keyblock, 0, sizeof(krb5_keyblock));
/* Get the enctype */
(void) krb5_ser_unpack_int32(&ibuf, &bp, &remain);
keyblock->enctype = (krb5_enctype) ibuf;
/* Get the length */
(void) krb5_ser_unpack_int32(&ibuf, &bp, &remain);
keyblock->length = (int) ibuf;
/* Get the string */
/* Solaris Kerberos */
keyblock->contents = (krb5_octet *) MALLOC((size_t) (ibuf));
if ((keyblock->contents)&&
!(kret = krb5_ser_unpack_bytes(keyblock->contents,
(size_t) ibuf,
&bp, &remain))) {
kret = krb5_ser_unpack_int32(&ibuf, &bp, &remain);
if (!kret && (ibuf == KV5M_KEYBLOCK)) {
kret = 0;
*buffer = bp;
*lenremain = remain;
keyblock->magic = KV5M_KEYBLOCK;
*argp = (krb5_pointer) keyblock;
}
else
kret = EINVAL;
}
if (kret) {
if (keyblock->contents)
FREE(keyblock->contents, keyblock->length);
FREE(keyblock, sizeof(krb5_keyblock));
}
}
}
return(kret);
}
/*
* Register the keyblock serializer.
*/
krb5_error_code
krb5_ser_keyblock_init(krb5_context kcontext)
{
return(krb5_register_serializer(kcontext, &krb5_keyblock_ser_entry));
}
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* lib/krb5/krb/ser_princ.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.
*
*/
/*
* ser_princ.c - Serialize a krb5_principal structure.
*/
#include "k5-int.h"
#include "int-proto.h"
/*
* Routines to deal with externalizing the krb5_principal:
* krb5_principal_size();
* krb5_principal_externalize();
* krb5_principal_internalize();
*/
static krb5_error_code krb5_principal_size
(krb5_context, krb5_pointer, size_t *);
static krb5_error_code krb5_principal_externalize
(krb5_context, krb5_pointer, krb5_octet **, size_t *);
static krb5_error_code krb5_principal_internalize
(krb5_context,krb5_pointer *, krb5_octet **, size_t *);
/* Local data */
static const krb5_ser_entry krb5_principal_ser_entry = {
KV5M_PRINCIPAL, /* Type */
krb5_principal_size, /* Sizer routine */
krb5_principal_externalize, /* Externalize routine */
krb5_principal_internalize /* Internalize routine */
};
/*
* krb5_principal_size() - Determine the size required to externalize
* the krb5_principal.
*/
static krb5_error_code
krb5_principal_size(krb5_context kcontext, krb5_pointer arg, size_t *sizep)
{
krb5_error_code kret;
krb5_principal principal;
char *fname;
/*
* krb5_principal requires:
* krb5_int32 for KV5M_PRINCIPAL
* krb5_int32 for flattened name size
* strlen(name) for name.
* krb5_int32 for KV5M_PRINCIPAL
*/
kret = EINVAL;
/* Solaris Kerberos */
principal = (krb5_principal) arg;
if ((principal) &&
!(kret = krb5_unparse_name(kcontext, principal, &fname))) {
*sizep += (3*sizeof(krb5_int32)) + strlen(fname);
/* Solaris Kerberos */
krb5_xfree_wrap(fname, strlen(fname) + 1);
}
return(kret);
}
/*
* krb5_principal_externalize() - Externalize the krb5_principal.
*/
static krb5_error_code
krb5_principal_externalize(krb5_context kcontext, krb5_pointer arg, krb5_octet **buffer, size_t *lenremain)
{
krb5_error_code kret;
krb5_principal principal;
size_t required;
krb5_octet *bp;
size_t remain;
char *fname;
required = 0;
bp = *buffer;
remain = *lenremain;
kret = EINVAL;
/* Solaris Kerberos */
principal = (krb5_principal) arg;
if (principal) {
kret = ENOMEM;
if (!krb5_principal_size(kcontext, arg, &required) &&
(required <= remain)) {
if (!(kret = krb5_unparse_name(kcontext, principal, &fname))) {
(void) krb5_ser_pack_int32(KV5M_PRINCIPAL, &bp, &remain);
(void) krb5_ser_pack_int32((krb5_int32) strlen(fname),
&bp, &remain);
(void) krb5_ser_pack_bytes((krb5_octet *) fname,
strlen(fname), &bp, &remain);
(void) krb5_ser_pack_int32(KV5M_PRINCIPAL, &bp, &remain);
*buffer = bp;
*lenremain = remain;
/* Solaris Kerberos */
krb5_xfree_wrap(fname, strlen(fname) + 1);
}
}
}
return(kret);
}
/*
* krb5_principal_internalize() - Internalize the krb5_principal.
*/
static krb5_error_code
krb5_principal_internalize(krb5_context kcontext, krb5_pointer *argp, krb5_octet **buffer, size_t *lenremain)
{
krb5_error_code kret;
krb5_principal principal;
krb5_int32 ibuf;
krb5_octet *bp;
size_t remain;
char *tmpname;
/* Solaris Kerberos */
int tmpsize;
bp = *buffer;
remain = *lenremain;
kret = EINVAL;
/* Read our magic number */
if (krb5_ser_unpack_int32(&ibuf, &bp, &remain))
ibuf = 0;
if (ibuf == KV5M_PRINCIPAL) {
kret = ENOMEM;
/* See if we have enough data for the length */
if (!(kret = krb5_ser_unpack_int32(&ibuf, &bp, &remain))) {
/* Get the string */
/* Solaris Kerberos */
tmpsize = ibuf+1;
tmpname = (char *) MALLOC(tmpsize);
if ((tmpname) &&
!(kret = krb5_ser_unpack_bytes((krb5_octet *) tmpname,
(size_t) ibuf,
&bp, &remain))) {
tmpname[ibuf] = '\0';
/* Parse the name to a principal structure */
principal = (krb5_principal) NULL;
kret = krb5_parse_name(kcontext, tmpname, &principal);
if (!kret) {
kret = krb5_ser_unpack_int32(&ibuf, &bp, &remain);
if (!kret && (ibuf == KV5M_PRINCIPAL)) {
*buffer = bp;
*lenremain = remain;
*argp = principal;
}
else
kret = EINVAL;
}
if (kret && principal)
krb5_free_principal(kcontext, principal);
/* Solaris Kerberos */
FREE(tmpname,tmpsize);
}
}
}
return(kret);
}
/*
* Register the context serializer.
*/
krb5_error_code
krb5_ser_principal_init(krb5_context kcontext)
{
return(krb5_register_serializer(kcontext, &krb5_principal_ser_entry));
}
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* lib/krb5/krb/serialize.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.
*
*/
/*
* Base routines to deal with serialization of Kerberos metadata.
*/
#include "k5-int.h"
/* Solaris Kerberos */
#include <k5-platform.h>
#include <k5-platform-store_64.h>
#include <k5-platform-load_64.h>
/*
* krb5_find_serializer() - See if a particular type is registered.
*/
krb5_ser_handle
krb5_find_serializer(krb5_context kcontext, krb5_magic odtype)
{
krb5_ser_handle res;
krb5_ser_handle sctx;
int i;
res = (krb5_ser_handle) NULL;
sctx = (krb5_ser_handle) kcontext->ser_ctx;
for (i=0; i<kcontext->ser_ctx_count; i++) {
if (sctx[i].odtype == odtype) {
res = &sctx[i];
break;
}
}
return(res);
}
/*
* krb5_register_serializer() - Register a particular serializer.
*/
krb5_error_code
krb5_register_serializer(krb5_context kcontext, const krb5_ser_entry *entry)
{
krb5_error_code kret;
krb5_ser_handle stable;
kret = 0;
/* See if it's already there, if so, we're good to go. */
if (!(stable = krb5_find_serializer(kcontext, entry->odtype))) {
/*
* Can't find our type. Create a new entry.
*/
if ((stable = (krb5_ser_handle) MALLOC(sizeof(krb5_ser_entry) *
(kcontext->ser_ctx_count+1)))) {
/* Copy in old table */
if (kcontext->ser_ctx_count)
(void) memcpy((void*)stable, kcontext->ser_ctx,
sizeof(krb5_ser_entry) * kcontext->ser_ctx_count);
/* Copy in new entry */
(void) memcpy((void*)&stable[kcontext->ser_ctx_count], entry,
sizeof(krb5_ser_entry));
if (kcontext->ser_ctx)
krb5_xfree_wrap(kcontext->ser_ctx,
sizeof(krb5_ser_entry) * (kcontext->ser_ctx_count));
kcontext->ser_ctx = (void *) stable;
kcontext->ser_ctx_count++;
}
else
kret = ENOMEM;
}
else
(void) memcpy((void*)stable, entry, sizeof(krb5_ser_entry));
return(kret);
}
/*
* krb5_size_opaque() - Determine the size necessary to serialize a given
* piece of opaque data.
*/
krb5_error_code KRB5_CALLCONV
krb5_size_opaque(krb5_context kcontext, krb5_magic odtype, krb5_pointer arg, size_t *sizep)
{
krb5_error_code kret;
krb5_ser_handle shandle;
kret = ENOENT;
/* See if the type is supported, if so, do it */
if ((shandle = krb5_find_serializer(kcontext, odtype)))
kret = (shandle->sizer) ? (*shandle->sizer)(kcontext, arg, sizep) : 0;
return(kret);
}
/*
* krb5_externalize_opaque() - Externalize a piece of opaque data.
*/
krb5_error_code KRB5_CALLCONV
krb5_externalize_opaque(krb5_context kcontext, krb5_magic odtype, krb5_pointer arg, krb5_octet **bufpp, size_t *sizep)
{
krb5_error_code kret;
krb5_ser_handle shandle;
kret = ENOENT;
/* See if the type is supported, if so, do it */
if ((shandle = krb5_find_serializer(kcontext, odtype)))
kret = (shandle->externalizer) ?
(*shandle->externalizer)(kcontext, arg, bufpp, sizep) : 0;
return(kret);
}
/*
* Externalize a piece of arbitrary data.
*/
krb5_error_code
krb5_externalize_data(krb5_context kcontext, krb5_pointer arg, krb5_octet **bufpp, size_t *sizep)
{
krb5_error_code kret;
krb5_magic *mp;
krb5_octet *buffer, *bp;
size_t bufsize, bsize;
mp = (krb5_magic *) arg;
bufsize = 0;
if (!(kret = krb5_size_opaque(kcontext, *mp, arg, &bufsize))) {
if ((buffer = (krb5_octet *) MALLOC(bufsize))) {
bp = buffer;
bsize = bufsize;
if (!(kret = krb5_externalize_opaque(kcontext,
*mp,
arg,
&bp,
&bsize))) {
if (bsize != 0)
bufsize -= bsize;
*bufpp = buffer;
*sizep = bufsize;
}
}
else
kret = ENOMEM;
}
return(kret);
}
/*
* krb5_internalize_opaque() - Convert external representation into a data
* structure.
*/
krb5_error_code KRB5_CALLCONV
krb5_internalize_opaque(krb5_context kcontext, krb5_magic odtype, krb5_pointer *argp, krb5_octet **bufpp, size_t *sizep)
{
krb5_error_code kret;
krb5_ser_handle shandle;
kret = ENOENT;
/* See if the type is supported, if so, do it */
if ((shandle = krb5_find_serializer(kcontext, odtype)))
kret = (shandle->internalizer) ?
(*shandle->internalizer)(kcontext, argp, bufpp, sizep) : 0;
return(kret);
}
/*
* krb5_ser_pack_int32() - Pack a 4-byte integer if space is available.
* Update buffer pointer and remaining space.
*/
krb5_error_code KRB5_CALLCONV
krb5_ser_pack_int32(krb5_int32 iarg, krb5_octet **bufp, size_t *remainp)
{
if (*remainp >= sizeof(krb5_int32)) {
(*bufp)[0] = (krb5_octet) ((iarg >> 24) & 0xff);
(*bufp)[1] = (krb5_octet) ((iarg >> 16) & 0xff);
(*bufp)[2] = (krb5_octet) ((iarg >> 8) & 0xff);
(*bufp)[3] = (krb5_octet) (iarg & 0xff);
*bufp += sizeof(krb5_int32);
*remainp -= sizeof(krb5_int32);
return(0);
}
else
return(ENOMEM);
}
/*
* krb5_ser_pack_int64() - Pack an 8-byte integer if space is available.
* Update buffer pointer and remaining space.
*/
krb5_error_code KRB5_CALLCONV
krb5_ser_pack_int64(krb5_int64 iarg, krb5_octet **bufp, size_t *remainp)
{
if (*remainp >= sizeof(krb5_int64)) {
store_64_be(iarg, (unsigned char *)*bufp);
*bufp += sizeof(krb5_int64);
*remainp -= sizeof(krb5_int64);
return(0);
}
else
return(ENOMEM);
}
/*
* krb5_ser_pack_bytes() - Pack a string of bytes.
*/
krb5_error_code KRB5_CALLCONV
krb5_ser_pack_bytes(krb5_octet *ostring, size_t osize, krb5_octet **bufp, size_t *remainp)
{
if (*remainp >= osize) {
(void) memcpy(*bufp, ostring, osize);
*bufp += osize;
*remainp -= osize;
return(0);
}
else
return(ENOMEM);
}
/*
* krb5_ser_unpack_int32() - Unpack a 4-byte integer if it's there.
*/
krb5_error_code KRB5_CALLCONV
krb5_ser_unpack_int32(krb5_int32 *intp, krb5_octet **bufp, size_t *remainp)
{
if (*remainp >= sizeof(krb5_int32)) {
*intp = (((krb5_int32) ((unsigned char) (*bufp)[0]) << 24) |
((krb5_int32) ((unsigned char) (*bufp)[1]) << 16) |
((krb5_int32) ((unsigned char) (*bufp)[2]) << 8) |
((krb5_int32) ((unsigned char) (*bufp)[3])));
*bufp += sizeof(krb5_int32);
*remainp -= sizeof(krb5_int32);
return(0);
}
else
return(ENOMEM);
}
/*
* krb5_ser_unpack_int64() - Unpack an 8-byte integer if it's there.
*/
krb5_error_code KRB5_CALLCONV
krb5_ser_unpack_int64(krb5_int64 *intp, krb5_octet **bufp, size_t *remainp)
{
if (*remainp >= sizeof(krb5_int64)) {
*intp = load_64_be((unsigned char *)*bufp);
*bufp += sizeof(krb5_int64);
*remainp -= sizeof(krb5_int64);
return(0);
}
else
return(ENOMEM);
}
/*
* krb5_ser_unpack_bytes() - Unpack a byte string if it's there.
*/
krb5_error_code KRB5_CALLCONV
krb5_ser_unpack_bytes(krb5_octet *istring, size_t isize, krb5_octet **bufp, size_t *remainp)
{
if (*remainp >= isize) {
(void) memcpy(istring, *bufp, isize);
*bufp += isize;
*remainp -= isize;
return(0);
}
else
return(ENOMEM);
}
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* lib/krb5/krb/unparse.c
*
* Copyright 1990, 2008 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.
*
*
* krb5_unparse_name() routine
*
* Rewritten by Theodore Ts'o to properly unparse principal names
* which have the component or realm separator as part of one of their
* components.
*/
#include "k5-int.h"
#ifndef _KERNEL
#include <stdio.h>
#endif
/*
* SUNW17PACresync / Solaris Kerberos
* This realloc works for both Solaris kernel and user space.
*/
void *
krb5int_realloc(
void *oldp,
size_t new_size,
size_t old_size)
{
#ifdef _KERNEL
char *newp = MALLOC(new_size);
bcopy(oldp, newp, old_size < new_size ? old_size : new_size);
FREE(oldp, old_size);
return (newp);
#else
return (realloc(oldp, new_size));
#endif
}
/*
* converts the multi-part principal format used in the protocols to a
* single-string representation of the name.
*
* The name returned is in allocated storage and should be freed by
* the caller when finished.
*
* Conventions: / is used to separate components; @ is used to
* separate the realm from the rest of the name. If '/', '@', or '\0'
* appear in any the component, they will be representing using
* backslash encoding. ("\/", "\@", or '\0', respectively)
*
* returns error
* KRB_PARSE_MALFORMED principal is invalid (does not contain
* at least 2 components)
* also returns system errors
* ENOMEM unable to allocate memory for string
*/
#define REALM_SEP '@'
#define COMPONENT_SEP '/'
static int
component_length_quoted(const krb5_data *src, int flags)
{
const char *cp = src->data;
int length = src->length;
int j;
int size = length;
if ((flags & KRB5_PRINCIPAL_UNPARSE_DISPLAY) == 0) {
int no_realm = (flags & KRB5_PRINCIPAL_UNPARSE_NO_REALM) &&
!(flags & KRB5_PRINCIPAL_UNPARSE_SHORT);
for (j = 0; j < length; j++,cp++)
if ((!no_realm && *cp == REALM_SEP) ||
*cp == COMPONENT_SEP ||
*cp == '\0' || *cp == '\\' || *cp == '\t' ||
*cp == '\n' || *cp == '\b')
size++;
}
return size;
}
static int
copy_component_quoting(char *dest, const krb5_data *src, int flags)
{
int j;
const char *cp = src->data;
char *q = dest;
int length = src->length;
if (flags & KRB5_PRINCIPAL_UNPARSE_DISPLAY) {
(void) memcpy(dest, src->data, src->length);
return src->length;
}
for (j=0; j < length; j++,cp++) {
int no_realm = (flags & KRB5_PRINCIPAL_UNPARSE_NO_REALM) &&
!(flags & KRB5_PRINCIPAL_UNPARSE_SHORT);
switch (*cp) {
case REALM_SEP:
if (no_realm) {
*q++ = *cp;
break;
}
/* FALLTHROUGH */
case COMPONENT_SEP:
case '\\':
*q++ = '\\';
*q++ = *cp;
break;
case '\t':
*q++ = '\\';
*q++ = 't';
break;
case '\n':
*q++ = '\\';
*q++ = 'n';
break;
case '\b':
*q++ = '\\';
*q++ = 'b';
break;
#if 0
/* Heimdal escapes spaces in principal names upon unparsing */
case ' ':
*q++ = '\\';
*q++ = ' ';
break;
#endif
case '\0':
*q++ = '\\';
*q++ = '0';
break;
default:
*q++ = *cp;
}
}
/*LINTED*/
return q - dest;
}
static krb5_error_code
/*LINTED*/
k5_unparse_name(krb5_context context, krb5_const_principal principal,
int flags, char **name, unsigned int *size)
{
#if 0
/* SUNW17PACresync - lint - cp/length not used */
char *cp;
int length;
#endif
char *q;
int i;
krb5_int32 nelem;
unsigned int totalsize = 0;
#ifndef _KERNEL
/* SUNW17PACresync - princ in kernel will always have realm */
char *default_realm = NULL;
#endif
krb5_error_code ret = 0;
if (!principal || !name)
return KRB5_PARSE_MALFORMED;
#ifndef _KERNEL
if (flags & KRB5_PRINCIPAL_UNPARSE_SHORT) {
/* omit realm if local realm */
krb5_principal_data p;
ret = krb5_get_default_realm(context, &default_realm);
if (ret != 0)
goto cleanup;
krb5_princ_realm(context, &p)->length = strlen(default_realm);
krb5_princ_realm(context, &p)->data = default_realm;
if (krb5_realm_compare(context, &p, principal))
flags |= KRB5_PRINCIPAL_UNPARSE_NO_REALM;
}
#endif
if ((flags & KRB5_PRINCIPAL_UNPARSE_NO_REALM) == 0) {
totalsize += component_length_quoted(krb5_princ_realm(context,
principal),
flags);
totalsize++; /* This is for the separator */
}
nelem = krb5_princ_size(context, principal);
for (i = 0; i < (int) nelem; i++) {
#if 0
/* SUNW17PACresync - lint - cp not used */
cp = krb5_princ_component(context, principal, i)->data;
#endif
totalsize += component_length_quoted(krb5_princ_component(context, principal, i), flags);
totalsize++; /* This is for the separator */
}
if (nelem == 0)
totalsize++;
/*
* Allocate space for the ascii string; if space has been
* provided, use it, realloc'ing it if necessary.
*
* We need only n-1 seperators for n components, but we need
* an extra byte for the NUL at the end.
*/
if (size) {
if (*name && (*size < totalsize)) {
/* SUNW17PACresync - works for both kernel&user */
*name = krb5int_realloc(*name, totalsize, *size);
} else {
*name = MALLOC(totalsize);
}
*size = totalsize;
} else {
*name = MALLOC(totalsize);
}
if (!*name) {
ret = ENOMEM;
goto cleanup;
}
q = *name;
for (i = 0; i < (int) nelem; i++) {
#if 0
/* SUNW17PACresync - lint - cp/length not used */
cp = krb5_princ_component(context, principal, i)->data;
length = krb5_princ_component(context, principal, i)->length;
#endif
q += copy_component_quoting(q,
krb5_princ_component(context,
principal,
i),
flags);
*q++ = COMPONENT_SEP;
}
if (i > 0)
q--; /* Back up last component separator */
if ((flags & KRB5_PRINCIPAL_UNPARSE_NO_REALM) == 0) {
*q++ = REALM_SEP;
q += copy_component_quoting(q, krb5_princ_realm(context, principal), flags);
}
*q++ = '\0';
cleanup:
#ifndef _KERNEL
if (default_realm != NULL)
krb5_free_default_realm(context, default_realm);
#endif
return ret;
}
krb5_error_code KRB5_CALLCONV
krb5_unparse_name(krb5_context context, krb5_const_principal principal, register char **name)
{
if (name != NULL) /* name == NULL will return error from _ext */
*name = NULL;
return k5_unparse_name(context, principal, 0, name, NULL);
}
krb5_error_code KRB5_CALLCONV
krb5_unparse_name_ext(krb5_context context, krb5_const_principal principal,
char **name, unsigned int *size)
{
return k5_unparse_name(context, principal, 0, name, size);
}
krb5_error_code KRB5_CALLCONV
krb5_unparse_name_flags(krb5_context context, krb5_const_principal principal,
int flags, char **name)
{
if (name != NULL)
*name = NULL;
return k5_unparse_name(context, principal, flags, name, NULL);
}
krb5_error_code KRB5_CALLCONV
krb5_unparse_name_flags_ext(krb5_context context, krb5_const_principal principal,
int flags, char **name, unsigned int *size)
{
return k5_unparse_name(context, principal, flags, name, size);
}
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* lib/crypto/os/c_ustime.c
*
* Copyright 1990,1991 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.
*
*
* krb5_mstimeofday for BSD 4.3
*/
#include "k5-int.h"
#include "k5-thread.h"
k5_mutex_t krb5int_us_time_mutex = K5_MUTEX_PARTIAL_INITIALIZER;
struct time_now { krb5_int32 sec, usec; };
#if defined(_WIN32)
/* Microsoft Windows NT and 95 (32bit) */
/* This one works for WOW (Windows on Windows, ntvdm on Win-NT) */
#include <time.h>
#include <sys/timeb.h>
#include <string.h>
static krb5_error_code
get_time_now(struct time_now *n)
{
struct _timeb timeptr;
_ftime(&timeptr);
n->sec = timeptr.time;
n->usec = timeptr.millitm * 1000;
return 0;
}
#else
/* Everybody else is UNIX, right? POSIX 1996 doesn't give us
gettimeofday, but what real OS doesn't? */
static krb5_error_code
get_time_now(struct time_now *n)
{
struct timeval tv;
#ifdef _KERNEL
timestruc_t now;
gethrestime(&now);
tv.tv_sec = now.tv_sec;
tv.tv_usec = now.tv_nsec / (NANOSEC / MICROSEC);
#else
if (gettimeofday(&tv, (struct timezone *)0) == -1)
return errno;
#endif
n->sec = tv.tv_sec;
n->usec = tv.tv_usec;
return 0;
}
#endif
static struct time_now last_time;
krb5_error_code
krb5_crypto_us_timeofday(krb5_int32 *seconds, krb5_int32 *microseconds)
{
struct time_now now;
krb5_error_code err;
err = get_time_now(&now);
if (err)
return err;
err = k5_mutex_lock(&krb5int_us_time_mutex);
if (err)
return err;
/* Just guessing: If the number of seconds hasn't changed, yet the
microseconds are moving backwards, we probably just got a third
instance of returning the same clock value from the system, so
the saved value was artificially incremented.
On Windows, where we get millisecond accuracy currently, that's
quite likely. On UNIX, it appears that we always get new
microsecond values, so this case should never trigger. */
if ((now.sec == last_time.sec) && (now.usec <= last_time.usec)) {
/* Same as last time??? */
now.usec = ++last_time.usec;
if (now.usec >= 1000000) {
++now.sec;
now.usec = 0;
}
/* For now, we're not worrying about the case of enough
returns of the same value that we roll over now.sec, and
the next call still gets the previous now.sec value. */
}
last_time.sec = now.sec; /* Remember for next time */
last_time.usec = now.usec;
(void) k5_mutex_unlock(&krb5int_us_time_mutex);
*seconds = now.sec;
*microseconds = now.usec;
return 0;
}
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* lib/krb5/os/init_ctx.c
*
* Copyright 1994 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.
*
* krb5_init_contex()
*/
#define NEED_WINDOWS
#include "k5-int.h"
#ifndef _KERNEL
#include "os-proto.h"
#if 0 /* Solaris Kerberos */
#include "prof_int.h" /* XXX for profile_copy, not public yet */
#endif
errcode_t KRB5_CALLCONV profile_copy (profile_t, profile_t *);
#endif
#ifdef USE_LOGIN_LIBRARY
#include "KerberosLoginPrivate.h"
#endif
#if defined(_WIN32)
#include <winsock.h>
static krb5_error_code
get_from_windows_dir(
char **pname
)
{
UINT size = GetWindowsDirectory(0, 0);
*pname = malloc(size + 1 +
strlen(DEFAULT_PROFILE_FILENAME) + 1);
if (*pname)
{
GetWindowsDirectory(*pname, size);
strcat(*pname, "\\");
strcat(*pname, DEFAULT_PROFILE_FILENAME);
return 0;
} else {
return KRB5_CONFIG_CANTOPEN;
}
}
static krb5_error_code
get_from_module_dir(
char **pname
)
{
const DWORD size = 1024; /* fixed buffer */
int found = 0;
char *p;
char *name;
struct _stat s;
*pname = 0;
name = MALLOC(size);
if (!name)
return ENOMEM;
if (!GetModuleFileName(GetModuleHandle("krb5_32"), name, size))
goto cleanup;
p = name + strlen(name);
while ((p >= name) && (*p != '\\') && (*p != '/')) p--;
if (p < name)
goto cleanup;
p++;
strncpy(p, DEFAULT_PROFILE_FILENAME, size - (p - name));
name[size - 1] = 0;
found = !_stat(name, &s);
cleanup:
if (found)
*pname = name;
else
if (name) FREE(name, size);
return 0;
}
/*
* get_from_registry
*
* This will find a profile in the registry. *pbuffer != 0 if we
* found something. Make sure to free(*pbuffer) when done. It will
* return an error code if there is an error the user should know
* about. We maintain the invariant: return value != 0 =>
* *pbuffer == 0.
*/
static krb5_error_code
get_from_registry(
char** pbuffer,
HKEY hBaseKey
)
{
HKEY hKey = 0;
LONG rc = 0;
DWORD size = 0;
krb5_error_code retval = 0;
const char *key_path = "Software\\MIT\\Kerberos5";
const char *value_name = "config";
/* a wannabe assertion */
if (!pbuffer)
{
/*
* We have a programming error! For now, we segfault :)
* There is no good mechanism to deal.
*/
}
*pbuffer = 0;
if ((rc = RegOpenKeyEx(hBaseKey, key_path, 0, KEY_QUERY_VALUE,
&hKey)) != ERROR_SUCCESS)
{
/* not a real error */
goto cleanup;
}
rc = RegQueryValueEx(hKey, value_name, 0, 0, 0, &size);
if ((rc != ERROR_SUCCESS) && (rc != ERROR_MORE_DATA))
{
/* not a real error */
goto cleanup;
}
*pbuffer = MALLOC(size);
if (!*pbuffer)
{
retval = ENOMEM;
goto cleanup;
}
if ((rc = RegQueryValueEx(hKey, value_name, 0, 0, *pbuffer, &size)) !=
ERROR_SUCCESS)
{
/*
* Let's not call it a real error in case it disappears, but
* we need to free so that we say we did not find anything.
*/
FREE(*pbuffer, size);
*pbuffer = 0;
goto cleanup;
}
cleanup:
if (hKey)
RegCloseKey(hKey);
if (retval && *pbuffer)
{
FREE(*pbuffer, size);
/* Let's say we did not find anything: */
*pbuffer = 0;
}
return retval;
}
#endif /* _WIN32 */
#ifndef _KERNEL
static void
free_filespecs(profile_filespec_t *files)
{
char **cp;
if (files == 0)
return;
for (cp = files; *cp; cp++)
free(*cp);
free(files);
}
/* This function is needed by KfM's KerberosPreferences API
* because it needs to be able to specify "secure" */
krb5_error_code
os_get_default_config_files(profile_filespec_t **pfiles, krb5_boolean secure)
{
profile_filespec_t* files;
#if defined(_WIN32)
krb5_error_code retval = 0;
char *name = 0;
if (!secure)
{
char *env = getenv("KRB5_CONFIG");
if (env)
{
name = malloc(strlen(env) + 1);
if (!name) return ENOMEM;
strcpy(name, env);
}
}
if (!name && !secure)
{
/* HKCU */
retval = get_from_registry(&name, HKEY_CURRENT_USER);
if (retval) return retval;
}
if (!name)
{
/* HKLM */
retval = get_from_registry(&name, HKEY_LOCAL_MACHINE);
if (retval) return retval;
}
if (!name && !secure)
{
/* module dir */
retval = get_from_module_dir(&name);
if (retval) return retval;
}
if (!name)
{
/* windows dir */
retval = get_from_windows_dir(&name);
}
if (retval)
return retval;
if (!name)
return KRB5_CONFIG_CANTOPEN; /* should never happen */
files = malloc(2 * sizeof(char *));
files[0] = name;
files[1] = 0;
#else /* !_WIN32 */
char* filepath = 0;
int n_entries, i;
unsigned int ent_len;
const char *s, *t;
#ifdef USE_LOGIN_LIBRARY
/* If __KLAllowHomeDirectoryAccess() == FALSE, we are probably
trying to authenticate to a fileserver for the user's homedir. */
if (!__KLAllowHomeDirectoryAccess ())
secure = 1;
#endif
if (secure) {
filepath = DEFAULT_SECURE_PROFILE_PATH;
} else {
filepath = getenv("KRB5_CONFIG");
if (!filepath) filepath = DEFAULT_PROFILE_PATH;
}
/* count the distinct filename components */
for(s = filepath, n_entries = 1; *s; s++) {
if (*s == ':')
n_entries++;
}
/* the array is NULL terminated */
files = (char**) MALLOC((n_entries+1) * sizeof(char*));
if (files == 0)
return ENOMEM;
/* measure, copy, and skip each one */
/*LINTED*/
for(s = filepath, i=0; (t = strchr(s, ':')) || (t=s+strlen(s)); s=t+1, i++)
{
ent_len = t-s;
files[i] = (char*) malloc(ent_len + 1);
if (files[i] == 0) {
/* if malloc fails, free the ones that worked */
while(--i >= 0) free(files[i]);
free(files);
return ENOMEM;
}
strncpy(files[i], s, ent_len);
files[i][ent_len] = 0;
if (*t == 0) {
i++;
break;
}
}
/* cap the array */
files[i] = 0;
#endif /* !_WIN32 */
*pfiles = (profile_filespec_t *)files;
return 0;
}
static krb5_error_code
add_kdc_config_file(profile_filespec_t **pfiles)
{
char *file;
size_t count;
profile_filespec_t *newfiles;
file = getenv(KDC_PROFILE_ENV);
if (file == NULL)
file = DEFAULT_KDC_PROFILE;
for (count = 0; (*pfiles)[count]; count++)
;
count += 2;
newfiles = malloc(count * sizeof(*newfiles));
if (newfiles == NULL)
return errno;
memcpy(newfiles + 1, *pfiles, (count-1) * sizeof(*newfiles));
newfiles[0] = strdup(file);
if (newfiles[0] == NULL) {
int e = errno;
free(newfiles);
return e;
}
free(*pfiles);
*pfiles = newfiles;
return 0;
}
/* Set the profile paths in the context. If secure is set to TRUE
then do not include user paths (from environment variables, etc).
If kdc is TRUE, include kdc.conf from whereever we expect to find
it. */
static krb5_error_code
os_init_paths(krb5_context ctx, krb5_boolean kdc)
{
krb5_error_code retval = 0;
profile_filespec_t *files = 0;
krb5_boolean secure = ctx->profile_secure;
#ifdef KRB5_DNS_LOOKUP
ctx->profile_in_memory = 0;
#endif /* KRB5_DNS_LOOKUP */
retval = os_get_default_config_files(&files, secure);
if (retval == 0 && kdc)
retval = add_kdc_config_file(&files);
if (!retval) {
retval = profile_init((const_profile_filespec_t *) files,
&ctx->profile);
#ifdef KRB5_DNS_LOOKUP
/* if none of the filenames can be opened use an empty profile */
if (retval == ENOENT) {
retval = profile_init(NULL, &ctx->profile);
if (!retval)
ctx->profile_in_memory = 1;
}
#endif /* KRB5_DNS_LOOKUP */
}
if (files)
free_filespecs(files);
if (retval)
ctx->profile = 0;
if (retval == ENOENT)
return KRB5_CONFIG_CANTOPEN;
if ((retval == PROF_SECTION_NOTOP) ||
(retval == PROF_SECTION_SYNTAX) ||
(retval == PROF_RELATION_SYNTAX) ||
(retval == PROF_EXTRA_CBRACE) ||
(retval == PROF_MISSING_OBRACE))
return KRB5_CONFIG_BADFORMAT;
return retval;
}
#endif /* !_KERNEL */
/*ARGSUSED1*/
krb5_error_code
krb5_os_init_context(krb5_context ctx, krb5_boolean kdc)
{
krb5_os_context os_ctx;
krb5_error_code retval = 0;
#ifdef _WIN32
WORD wVersionRequested;
WSADATA wsaData;
#endif /* _WIN32 */
os_ctx = ctx->os_context;
os_ctx->magic = KV5M_OS_CONTEXT;
os_ctx->time_offset = 0;
os_ctx->usec_offset = 0;
os_ctx->os_flags = 0;
os_ctx->default_ccname = 0;
#ifndef _KERNEL
ctx->vtbl = 0;
PLUGIN_DIR_INIT(&ctx->libkrb5_plugins);
PLUGIN_DIR_INIT(&ctx->preauth_plugins);
ctx->preauth_context = NULL;
retval = os_init_paths(ctx, kdc);
/*
* If there's an error in the profile, return an error. Just
* ignoring the error is a Bad Thing (tm).
*/
if (!retval) {
krb5_cc_set_default_name(ctx, NULL);
#ifdef _WIN32
/* We initialize winsock to version 1.1 but
* we do not care if we succeed or fail.
*/
wVersionRequested = 0x0101;
WSAStartup (wVersionRequested, &wsaData);
#endif /* _WIN32 */
}
#endif
return retval;
}
#ifndef _KERNEL
krb5_error_code KRB5_CALLCONV
krb5_get_profile (krb5_context ctx, profile_t *profile)
{
return profile_copy (ctx->profile, profile);
}
#endif
#ifndef _KERNEL
krb5_error_code
krb5_set_config_files(krb5_context ctx, const char **filenames)
{
krb5_error_code retval;
profile_t profile;
retval = profile_init(filenames, &profile);
if (retval)
return retval;
if (ctx->profile)
profile_release(ctx->profile);
ctx->profile = profile;
return 0;
}
krb5_error_code KRB5_CALLCONV
krb5_get_default_config_files(char ***pfilenames)
{
if (!pfilenames)
return EINVAL;
return os_get_default_config_files(pfilenames, FALSE);
}
void KRB5_CALLCONV
krb5_free_config_files(char **filenames)
{
free_filespecs(filenames);
}
#endif /* _KERNEL */
#ifndef _KERNEL
krb5_error_code
krb5_secure_config_files(krb5_context ctx)
{
/* Obsolete interface; always return an error.
This function should be removed next time a major version
number change happens. */
krb5_error_code retval;
if (ctx->profile) {
profile_release(ctx->profile);
ctx->profile = 0;
}
ctx->profile_secure = TRUE;
retval = os_init_paths(ctx, FALSE);
if (retval)
return retval;
return KRB5_OBSOLETE_FN;
}
#endif /* _KERNEL */
void
krb5_os_free_context(krb5_context ctx)
{
krb5_os_context os_ctx;
os_ctx = ctx->os_context;
if (os_ctx->default_ccname) {
FREE(os_ctx->default_ccname,
strlen(os_ctx->default_ccname) + 1);
os_ctx->default_ccname = 0;
}
os_ctx->magic = 0;
#ifndef _KERNEL
if (ctx->profile) {
profile_release(ctx->profile);
ctx->profile = 0;
}
if (ctx->preauth_context) {
krb5_free_preauth_context(ctx);
ctx->preauth_context = NULL;
}
krb5int_close_plugin_dirs (&ctx->preauth_plugins);
krb5int_close_plugin_dirs (&ctx->libkrb5_plugins);
#endif
}
#ifdef _WIN32
WSACleanup();
#endif /* _WIN32 */
/*
* Copyright 2002-2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <k5-int.h>
/*
* Note, there is no memset() in kernel land. This code is a replacement for
* use in the kerberos kernel mech.
* As a performance enhancement, bzero is called if the fill pattern is 0.
*/
void *
krb5_memset(void *sp1, int c, size_t n)
{
if (n > 0) {
if (c == 0) {
bzero(sp1, n);
} else {
unsigned char *sp = sp1;
do {
*sp++ = (unsigned char)c;
} while (--n != 0);
}
}
return (sp1);
}
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* lib/krb5/os/timeofday.c
*
* Copyright 1990 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.
*
*
* libos: krb5_timeofday function for BSD 4.3
*/
#include "k5-int.h"
#ifdef _KERNEL
#include <sys/time.h>
#else
#include <time.h>
#include <errno.h>
#endif
krb5_error_code KRB5_CALLCONV
krb5_timeofday(krb5_context context, register krb5_timestamp *timeret)
{
krb5_os_context os_ctx = context->os_context;
/* Solaris Kerberos */
krb5_int32 tval;
if (os_ctx->os_flags & KRB5_OS_TOFFSET_TIME) {
*timeret = os_ctx->time_offset;
return 0;
}
{
krb5_int32 usecs;
krb5_error_code kret;
if (kret = krb5_crypto_us_timeofday(&tval,
&usecs))
return kret;
}
/* Solaris Kerberos */
if (tval == (krb5_int32) -1)
#ifdef _KERNEL
return 1;
#else
return (krb5_error_code) errno;
#endif
if (os_ctx->os_flags & KRB5_OS_TOFFSET_VALID)
tval += os_ctx->time_offset;
*timeret = tval;
return 0;
}
/*
* lib/krb5/os/toffset.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.
*
* These routines manipulates the time offset fields in the os context.
*/
#include "k5-int.h"
/*
* This routine takes the "real time" as input, and sets the time
* offset field in the context structure so that the krb5 time
* routines will return the correct time as corrected by difference
* between the system time and the "real time" as passed to this
* routine
*/
krb5_error_code KRB5_CALLCONV
krb5_set_real_time(krb5_context context, krb5_timestamp seconds, krb5_int32 microseconds)
{
krb5_os_context os_ctx = context->os_context;
krb5_int32 sec, usec;
krb5_error_code retval;
retval = krb5_crypto_us_timeofday(&sec, &usec);
if (retval)
return retval;
os_ctx->time_offset = seconds - sec;
os_ctx->usec_offset = microseconds - usec;
os_ctx->os_flags = ((os_ctx->os_flags & ~KRB5_OS_TOFFSET_TIME) |
KRB5_OS_TOFFSET_VALID);
return 0;
}
/*
* This routine sets the krb5 time routines so that they will return
* the seconds and microseconds value as input to this function. This
* is useful for running the krb5 routines through test suites
*/
krb5_error_code
krb5_set_debugging_time(krb5_context context, krb5_timestamp seconds, krb5_int32 microseconds)
{
krb5_os_context os_ctx = context->os_context;
os_ctx->time_offset = seconds;
os_ctx->usec_offset = microseconds;
os_ctx->os_flags = ((os_ctx->os_flags & ~KRB5_OS_TOFFSET_VALID) |
KRB5_OS_TOFFSET_TIME);
return 0;
}
/*
* This routine turns off the time correction fields, so that the krb5
* routines return the "natural" time.
*/
krb5_error_code
krb5_use_natural_time(krb5_context context)
{
krb5_os_context os_ctx = context->os_context;
os_ctx->os_flags &= ~(KRB5_OS_TOFFSET_VALID|KRB5_OS_TOFFSET_TIME);
return 0;
}
/*
* This routine returns the current time offsets in use.
*/
krb5_error_code KRB5_CALLCONV
krb5_get_time_offsets(krb5_context context, krb5_timestamp *seconds, krb5_int32 *microseconds)
{
krb5_os_context os_ctx = context->os_context;
if (seconds)
*seconds = os_ctx->time_offset;
if (microseconds)
*microseconds = os_ctx->usec_offset;
return 0;
}
/*
* This routine sets the time offsets directly.
*/
krb5_error_code
krb5_set_time_offsets(krb5_context context, krb5_timestamp seconds, krb5_int32 microseconds)
{
krb5_os_context os_ctx = context->os_context;
os_ctx->time_offset = seconds;
os_ctx->usec_offset = microseconds;
os_ctx->os_flags = ((os_ctx->os_flags & ~KRB5_OS_TOFFSET_TIME) |
KRB5_OS_TOFFSET_VALID);
return 0;
}
/*
* 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 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
* Copyright (c) 2011 Bayard G. Bell. All rights reserved.
*
* A module for Kerberos V5 security mechanism.
*
*/
#include <sys/types.h>
#include <sys/modctl.h>
#include <sys/errno.h>
#include <mechglueP.h>
#include <gssapiP_krb5.h>
#include <gssapi_err_generic.h>
#include <gssapi/kgssapi_defs.h>
#include <sys/debug.h>
#include <k5-int.h>
/* mechglue wrappers */
static OM_uint32 k5glue_delete_sec_context
(void *, OM_uint32 *, /* minor_status */
gss_ctx_id_t *, /* context_handle */
gss_buffer_t, /* output_token */
OM_uint32);
static OM_uint32 k5glue_sign
(void *, OM_uint32 *, /* minor_status */
gss_ctx_id_t, /* context_handle */
int, /* qop_req */
gss_buffer_t, /* message_buffer */
gss_buffer_t, /* message_token */
OM_uint32);
static OM_uint32 k5glue_verify
(void *, OM_uint32 *, /* minor_status */
gss_ctx_id_t, /* context_handle */
gss_buffer_t, /* message_buffer */
gss_buffer_t, /* token_buffer */
int *, /* qop_state */
OM_uint32);
static OM_uint32 k5glue_seal
(void *, OM_uint32 *, /* minor_status */
gss_ctx_id_t, /* context_handle */
int, /* conf_req_flag */
int, /* qop_req */
gss_buffer_t, /* input_message_buffer */
int *, /* conf_state */
gss_buffer_t, /* output_message_buffer */
OM_uint32);
static OM_uint32 k5glue_unseal
(void *, OM_uint32 *, /* minor_status */
gss_ctx_id_t, /* context_handle */
gss_buffer_t, /* input_message_buffer */
gss_buffer_t, /* output_message_buffer */
int *, /* conf_state */
int *, /* qop_state */
OM_uint32);
static OM_uint32 k5glue_import_sec_context
(void *, OM_uint32 *, /* minor_status */
gss_buffer_t, /* interprocess_token */
gss_ctx_id_t *); /* context_handle */
static struct gss_config krb5_mechanism =
{{9, "\052\206\110\206\367\022\001\002\002"},
NULL, /* context */
NULL, /* next */
TRUE, /* uses_kmod */
k5glue_unseal,
k5glue_delete_sec_context,
k5glue_seal,
k5glue_import_sec_context,
k5glue_sign,
k5glue_verify,
};
static gss_mechanism
gss_mech_initialize()
{
return (&krb5_mechanism);
}
/*
* Module linkage information for the kernel.
*/
extern struct mod_ops mod_miscops;
static struct modlmisc modlmisc = {
&mod_miscops, "Krb5 GSS mechanism"
};
static struct modlinkage modlinkage = {
MODREV_1,
(void *)&modlmisc,
NULL
};
static int krb5_fini_code = EBUSY;
int
_init()
{
int retval;
gss_mechanism mech, tmp;
if ((retval = mod_install(&modlinkage)) != 0)
return (retval);
mech = gss_mech_initialize();
mutex_enter(&__kgss_mech_lock);
tmp = __kgss_get_mechanism(&mech->mech_type);
if (tmp != NULL) {
KRB5_LOG0(KRB5_INFO,
"KRB5 GSS mechanism: mechanism already in table.\n");
if (tmp->uses_kmod == TRUE) {
KRB5_LOG0(KRB5_INFO, "KRB5 GSS mechanism: mechanism "
"table supports kernel operations!\n");
}
/*
* keep us loaded, but let us be unloadable. This
* will give the developer time to trouble shoot
*/
krb5_fini_code = 0;
} else {
__kgss_add_mechanism(mech);
ASSERT(__kgss_get_mechanism(&mech->mech_type) == mech);
}
mutex_exit(&__kgss_mech_lock);
return (0);
}
int
_fini()
{
int ret = krb5_fini_code;
if (ret == 0) {
ret = (mod_remove(&modlinkage));
}
return (ret);
}
int
_info(struct modinfo *modinfop)
{
return (mod_info(&modlinkage, modinfop));
}
/* ARGSUSED */
static OM_uint32
k5glue_delete_sec_context(ctx, minor_status, context_handle, output_token,
gssd_ctx_verifier)
void *ctx;
OM_uint32 *minor_status;
gss_ctx_id_t *context_handle;
gss_buffer_t output_token;
OM_uint32 gssd_ctx_verifier;
{
return (krb5_gss_delete_sec_context(minor_status,
context_handle, output_token,
gssd_ctx_verifier));
}
/* V2 */
/* ARGSUSED */
static OM_uint32
k5glue_import_sec_context(ctx, minor_status, interprocess_token, context_handle)
void *ctx;
OM_uint32 *minor_status;
gss_buffer_t interprocess_token;
gss_ctx_id_t *context_handle;
{
return (krb5_gss_import_sec_context(minor_status,
interprocess_token,
context_handle));
}
/* V1 only */
/* ARGSUSED */
static OM_uint32
k5glue_seal(ctx, minor_status, context_handle, conf_req_flag, qop_req,
input_message_buffer, conf_state, output_message_buffer,
gssd_ctx_verifier)
void *ctx;
OM_uint32 *minor_status;
gss_ctx_id_t context_handle;
int conf_req_flag;
int qop_req;
gss_buffer_t input_message_buffer;
int *conf_state;
gss_buffer_t output_message_buffer;
OM_uint32 gssd_ctx_verifier;
{
return (krb5_gss_seal(minor_status, context_handle,
conf_req_flag, qop_req, input_message_buffer,
conf_state, output_message_buffer, gssd_ctx_verifier));
}
/* ARGSUSED */
static OM_uint32
k5glue_sign(ctx, minor_status, context_handle,
qop_req, message_buffer,
message_token, gssd_ctx_verifier)
void *ctx;
OM_uint32 *minor_status;
gss_ctx_id_t context_handle;
int qop_req;
gss_buffer_t message_buffer;
gss_buffer_t message_token;
OM_uint32 gssd_ctx_verifier;
{
return (krb5_gss_sign(minor_status, context_handle,
qop_req, message_buffer, message_token, gssd_ctx_verifier));
}
/* ARGSUSED */
static OM_uint32
k5glue_unseal(ctx, minor_status, context_handle, input_message_buffer,
output_message_buffer, conf_state, qop_state, gssd_ctx_verifier)
void *ctx;
OM_uint32 *minor_status;
gss_ctx_id_t context_handle;
gss_buffer_t input_message_buffer;
gss_buffer_t output_message_buffer;
int *conf_state;
int *qop_state;
OM_uint32 gssd_ctx_verifier;
{
return (krb5_gss_unseal(minor_status, context_handle,
input_message_buffer, output_message_buffer,
conf_state, qop_state, gssd_ctx_verifier));
}
/* V1 only */
/* ARGSUSED */
static OM_uint32
k5glue_verify(ctx, minor_status, context_handle, message_buffer,
token_buffer, qop_state, gssd_ctx_verifier)
void *ctx;
OM_uint32 *minor_status;
gss_ctx_id_t context_handle;
gss_buffer_t message_buffer;
gss_buffer_t token_buffer;
int *qop_state;
OM_uint32 gssd_ctx_verifier;
{
return (krb5_gss_verify(minor_status,
context_handle,
message_buffer,
token_buffer,
qop_state, gssd_ctx_verifier));
}
/*
* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Copyright 1993 by OpenVision Technologies, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appears in all copies and
* that both that copyright notice and this permission notice appear in
* supporting documentation, and that the name of OpenVision not be used
* in advertising or publicity pertaining to distribution of the software
* without specific, written prior permission. OpenVision makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
* OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
#include "gssapiP_krb5.h"
#include "mglueP.h" /* SUNW15resync - for KGSS_ macros */
/*
* $Id: delete_sec_context.c 18396 2006-07-25 20:29:43Z lxs $
*/
#ifdef _KERNEL
/* SUNW15resync - todo - unify these kernel rel oid funcs with user spc ones */
OM_uint32
krb5_gss_internal_release_oid(minor_status, oid)
OM_uint32 *minor_status;
gss_OID *oid;
{
/*
* This function only knows how to release internal OIDs. It will
* return GSS_S_CONTINUE_NEEDED for any OIDs it does not recognize.
*/
if ((*oid != gss_mech_krb5) &&
(*oid != gss_mech_krb5_old) &&
(*oid != gss_mech_krb5_wrong) &&
(*oid != gss_nt_krb5_name) &&
(*oid != gss_nt_krb5_principal)) {
/* We don't know about this OID */
return(GSS_S_CONTINUE_NEEDED);
}
else {
*oid = GSS_C_NO_OID;
*minor_status = 0;
return(GSS_S_COMPLETE);
}
}
OM_uint32
generic_gss_release_oid(minor_status, oid)
OM_uint32 *minor_status;
gss_OID *oid;
{
if (minor_status)
*minor_status = 0;
if (*oid == GSS_C_NO_OID)
return(GSS_S_COMPLETE);
if ((*oid != GSS_C_NT_USER_NAME) &&
(*oid != GSS_C_NT_MACHINE_UID_NAME) &&
(*oid != GSS_C_NT_STRING_UID_NAME) &&
(*oid != GSS_C_NT_HOSTBASED_SERVICE) &&
(*oid != GSS_C_NT_ANONYMOUS) &&
(*oid != GSS_C_NT_EXPORT_NAME) &&
(*oid != gss_nt_service_name)) {
FREE((*oid)->elements, (*oid)->length);
FREE(*oid, sizeof(gss_OID_desc));
}
*oid = GSS_C_NO_OID;
return(GSS_S_COMPLETE);
}
OM_uint32
krb5_gss_release_oid(minor_status, oid)
OM_uint32 *minor_status;
gss_OID *oid;
{
if (krb5_gss_internal_release_oid(minor_status, oid) != GSS_S_COMPLETE) {
/* Pawn it off on the generic routine */
return(generic_gss_release_oid(minor_status, oid));
}
else {
*oid = GSS_C_NO_OID;
*minor_status = 0;
return(GSS_S_COMPLETE);
}
}
#endif
/*ARGSUSED*/
OM_uint32
krb5_gss_delete_sec_context(minor_status,
context_handle,
output_token
#ifdef _KERNEL
, gssd_ctx_verifier
#endif
)
OM_uint32 *minor_status;
gss_ctx_id_t *context_handle;
gss_buffer_t output_token;
#ifdef _KERNEL
OM_uint32 gssd_ctx_verifier;
#endif
{
krb5_context context;
krb5_gss_ctx_id_rec *ctx;
if (output_token) {
output_token->length = 0;
output_token->value = NULL;
}
/*SUPPRESS 29*/
if (*context_handle == GSS_C_NO_CONTEXT) {
*minor_status = 0;
return(GSS_S_COMPLETE);
}
/*SUPPRESS 29*/
/* validate the context handle */
if (! kg_validate_ctx_id(*context_handle)) {
*minor_status = (OM_uint32) G_VALIDATE_FAILED;
return(GSS_S_NO_CONTEXT);
}
ctx = (krb5_gss_ctx_id_t) *context_handle;
context = ctx->k5_context;
/* construct a delete context token if necessary */
if (output_token) {
OM_uint32 major;
gss_buffer_desc empty;
empty.length = 0; empty.value = NULL;
if ((major = kg_seal(minor_status, *context_handle, 0,
GSS_C_QOP_DEFAULT,
&empty, NULL, output_token, KG_TOK_DEL_CTX))) {
save_error_info(*minor_status, context);
return(major);
}
}
/* invalidate the context handle */
(void)kg_delete_ctx_id(*context_handle);
/* free all the context state */
if (ctx->seqstate)
g_order_free(&(ctx->seqstate));
if (ctx->enc)
krb5_free_keyblock(context, ctx->enc);
if (ctx->seq)
krb5_free_keyblock(context, ctx->seq);
if (ctx->here)
krb5_free_principal(context, ctx->here);
if (ctx->there)
krb5_free_principal(context, ctx->there);
if (ctx->subkey)
krb5_free_keyblock(context, ctx->subkey);
if (ctx->acceptor_subkey)
krb5_free_keyblock(context, ctx->acceptor_subkey);
/* We never import the auth_context into the kernel */
#ifndef _KERNEL
if (ctx->auth_context) {
if (ctx->cred_rcache)
(void)krb5_auth_con_setrcache(context, ctx->auth_context, NULL);
krb5_auth_con_free(context, ctx->auth_context);
}
#endif
if (ctx->mech_used)
(void) KGSS_RELEASE_OID(minor_status, &ctx->mech_used);
if (ctx->authdata)
krb5_free_authdata(context, ctx->authdata);
if (ctx->k5_context)
krb5_free_context(ctx->k5_context);
/* Zero out context */
(void) memset(ctx, 0, sizeof(*ctx));
xfree_wrap(ctx, sizeof (krb5_gss_ctx_id_rec));
/* zero the handle itself */
*context_handle = GSS_C_NO_CONTEXT;
*minor_status = 0;
return(GSS_S_COMPLETE);
}
/*
* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Copyright 1993 by OpenVision Technologies, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appears in all copies and
* that both that copyright notice and this permission notice appear in
* supporting documentation, and that the name of OpenVision not be used
* in advertising or publicity pertaining to distribution of the software
* without specific, written prior permission. OpenVision makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
* OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
/*
* 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.
*/
/*
* $Id: gssapi_krb5.c 18343 2006-07-19 18:14:01Z lxs $
*/
/* For declaration of krb5_ser_context_init */
#include "k5-int.h"
#include "gssapiP_krb5.h"
#ifndef _KERNEL
#include "gss_libinit.h"
#endif
/*
* Solaris Kerberos
* Kernel kgssd module debugging aid. The global variable "krb5_log" is a bit
* mask which allows various types of log messages to be printed out.
*
* The log levels are defined in:
* usr/src/uts/common/gssapi/mechs/krb5/include/k5-int.h
*
* Note, KRB5_LOG_LVL can be assigned via the make invocation.
* See KRB5_DEFS in the various Makefiles.
*/
#ifdef KRB5_LOG_LVL
/* set the log level to that specified */
u_int krb5_log = KRB5_LOG_LVL;
#else
/* default log level */
u_int krb5_log = 0;
#endif /* KRB5_LOG_LVL */
/** exported constants defined in gssapi_krb5{,_nx}.h **/
/* these are bogus, but will compile */
/*
* The OID of the draft krb5 mechanism, assigned by IETF, is:
* iso(1) org(3) dod(5) internet(1) security(5)
* kerberosv5(2) = 1.3.5.1.5.2
* The OID of the krb5_name type is:
* iso(1) member-body(2) US(840) mit(113554) infosys(1) gssapi(2)
* krb5(2) krb5_name(1) = 1.2.840.113554.1.2.2.1
* The OID of the krb5_principal type is:
* iso(1) member-body(2) US(840) mit(113554) infosys(1) gssapi(2)
* krb5(2) krb5_principal(2) = 1.2.840.113554.1.2.2.2
* The OID of the proposed standard krb5 mechanism is:
* iso(1) member-body(2) US(840) mit(113554) infosys(1) gssapi(2)
* krb5(2) = 1.2.840.113554.1.2.2
* The OID of the proposed standard krb5 v2 mechanism is:
* iso(1) member-body(2) US(840) mit(113554) infosys(1) gssapi(2)
* krb5v2(3) = 1.2.840.113554.1.2.3
*
*/
/*
* Encoding rules: The first two values are encoded in one byte as 40
* * value1 + value2. Subsequent values are encoded base 128, most
* significant digit first, with the high bit (\200) set on all octets
* except the last in each value's encoding.
*/
const gss_OID_desc krb5_gss_oid_array[] = {
/* this is the official, rfc-specified OID */
{GSS_MECH_KRB5_OID_LENGTH, GSS_MECH_KRB5_OID},
/* this pre-RFC mech OID */
{GSS_MECH_KRB5_OLD_OID_LENGTH, GSS_MECH_KRB5_OLD_OID},
/* this is the unofficial, incorrect mech OID emitted by MS */
{GSS_MECH_KRB5_WRONG_OID_LENGTH, GSS_MECH_KRB5_WRONG_OID},
/* this is the v2 assigned OID */
{9, "\052\206\110\206\367\022\001\002\003"},
/* these two are name type OID's */
/* 2.1.1. Kerberos Principal Name Form: (rfc 1964)
* This name form shall be represented by the Object Identifier {iso(1)
* member-body(2) United States(840) mit(113554) infosys(1) gssapi(2)
* krb5(2) krb5_name(1)}. The recommended symbolic name for this type
* is "GSS_KRB5_NT_PRINCIPAL_NAME". */
{10, "\052\206\110\206\367\022\001\002\002\001"},
/* gss_nt_krb5_principal. Object identifier for a krb5_principal. Do not use. */
{10, "\052\206\110\206\367\022\001\002\002\002"},
{ 0, 0 }
};
const gss_OID_desc * const gss_mech_krb5 = krb5_gss_oid_array+0;
const gss_OID_desc * const gss_mech_krb5_old = krb5_gss_oid_array+1;
const gss_OID_desc * const gss_mech_krb5_wrong = krb5_gss_oid_array+2;
const gss_OID_desc * const gss_nt_krb5_name = krb5_gss_oid_array+4;
const gss_OID_desc * const gss_nt_krb5_principal = krb5_gss_oid_array+5;
const gss_OID_desc * const GSS_KRB5_NT_PRINCIPAL_NAME = krb5_gss_oid_array+4;
static const gss_OID_set_desc oidsets[] = {
{1, (gss_OID) krb5_gss_oid_array+0},
{1, (gss_OID) krb5_gss_oid_array+1},
{3, (gss_OID) krb5_gss_oid_array+0},
{1, (gss_OID) krb5_gss_oid_array+2},
{3, (gss_OID) krb5_gss_oid_array+0},
};
const gss_OID_set_desc * const gss_mech_set_krb5 = oidsets+0;
const gss_OID_set_desc * const gss_mech_set_krb5_old = oidsets+1;
const gss_OID_set_desc * const gss_mech_set_krb5_both = oidsets+2;
g_set kg_vdb = G_SET_INIT;
/** default credential support */
#ifndef _KERNEL
/*
* init_sec_context() will explicitly re-acquire default credentials,
* so handling the expiration/invalidation condition here isn't needed.
*/
OM_uint32
kg_get_defcred(minor_status, cred)
OM_uint32 *minor_status;
gss_cred_id_t *cred;
{
OM_uint32 major;
if ((major = krb5_gss_acquire_cred(minor_status,
(gss_name_t) NULL, GSS_C_INDEFINITE,
GSS_C_NULL_OID_SET, GSS_C_INITIATE,
cred, NULL, NULL)) && GSS_ERROR(major)) {
return(major);
}
*minor_status = 0;
return(GSS_S_COMPLETE);
}
OM_uint32
kg_sync_ccache_name (krb5_context context, OM_uint32 *minor_status)
{
OM_uint32 err = 0;
/*
* Sync up the context ccache name with the GSSAPI ccache name.
* If kg_ccache_name is NULL -- normal unless someone has called
* gss_krb5_ccache_name() -- then the system default ccache will
* be picked up and used by resetting the context default ccache.
* This is needed for platforms which support multiple ccaches.
*/
if (!err) {
/* if NULL, resets the context default ccache */
err = krb5_cc_set_default_name(context,
(char *) k5_getspecific(K5_KEY_GSS_KRB5_CCACHE_NAME));
}
*minor_status = err;
return (*minor_status == 0) ? GSS_S_COMPLETE : GSS_S_FAILURE;
}
/* This function returns whether or not the caller set a cccache name. Used by
* gss_acquire_cred to figure out if the caller wants to only look at this
* ccache or search the cache collection for the desired name */
OM_uint32
kg_caller_provided_ccache_name (OM_uint32 *minor_status,
int *out_caller_provided_name)
{
if (out_caller_provided_name) {
*out_caller_provided_name =
(k5_getspecific(K5_KEY_GSS_KRB5_CCACHE_NAME) != NULL);
}
*minor_status = 0;
return GSS_S_COMPLETE;
}
OM_uint32
kg_get_ccache_name (OM_uint32 *minor_status, const char **out_name)
{
const char *name = NULL;
OM_uint32 err = 0;
char *kg_ccache_name;
kg_ccache_name = k5_getspecific(K5_KEY_GSS_KRB5_CCACHE_NAME);
if (kg_ccache_name != NULL) {
name = strdup(kg_ccache_name);
if (name == NULL)
err = errno;
} else {
krb5_context context = NULL;
/* Reset the context default ccache (see text above), and then
retrieve it. */
err = krb5_gss_init_context(&context);
if (!err)
err = krb5_cc_set_default_name (context, NULL);
if (!err) {
name = krb5_cc_default_name(context);
if (name) {
name = strdup(name);
if (name == NULL)
err = ENOMEM;
}
}
if (err && context)
save_error_info(err, context);
if (context)
krb5_free_context(context);
}
if (!err) {
if (out_name) {
*out_name = name;
}
}
*minor_status = err;
return (*minor_status == 0) ? GSS_S_COMPLETE : GSS_S_FAILURE;
}
OM_uint32
kg_set_ccache_name (OM_uint32 *minor_status, const char *name)
{
char *new_name = NULL;
char *swap = NULL;
char *kg_ccache_name;
krb5_error_code kerr;
if (name) {
new_name = malloc(strlen(name) + 1);
if (new_name == NULL) {
*minor_status = ENOMEM;
return GSS_S_FAILURE;
}
strcpy(new_name, name);
}
kg_ccache_name = k5_getspecific(K5_KEY_GSS_KRB5_CCACHE_NAME);
swap = kg_ccache_name;
kg_ccache_name = new_name;
new_name = swap;
kerr = k5_setspecific(K5_KEY_GSS_KRB5_CCACHE_NAME, kg_ccache_name);
if (kerr != 0) {
/* Can't store, so free up the storage. */
free(kg_ccache_name);
/* ??? free(new_name); */
*minor_status = kerr;
return GSS_S_FAILURE;
}
free (new_name);
*minor_status = 0;
return GSS_S_COMPLETE;
}
#define g_OID_prefix_equal(o1, o2) \
(((o1)->length >= (o2)->length) && \
(memcmp((o1)->elements, (o2)->elements, (o2)->length) == 0))
/*
* gss_inquire_sec_context_by_oid() methods
*/
static struct {
gss_OID_desc oid;
OM_uint32 (*func)(OM_uint32 *, const gss_ctx_id_t, const gss_OID, gss_buffer_set_t *);
} krb5_gss_inquire_sec_context_by_oid_ops[] = {
{
{GSS_KRB5_GET_TKT_FLAGS_OID_LENGTH, GSS_KRB5_GET_TKT_FLAGS_OID},
gss_krb5int_get_tkt_flags
},
{
{GSS_KRB5_EXTRACT_AUTHZ_DATA_FROM_SEC_CONTEXT_OID_LENGTH, GSS_KRB5_EXTRACT_AUTHZ_DATA_FROM_SEC_CONTEXT_OID},
gss_krb5int_extract_authz_data_from_sec_context
},
{
{GSS_KRB5_INQ_SSPI_SESSION_KEY_OID_LENGTH, GSS_KRB5_INQ_SSPI_SESSION_KEY_OID},
gss_krb5int_inq_session_key
},
{
{GSS_KRB5_EXPORT_LUCID_SEC_CONTEXT_OID_LENGTH, GSS_KRB5_EXPORT_LUCID_SEC_CONTEXT_OID},
gss_krb5int_export_lucid_sec_context
},
{
{GSS_KRB5_EXTRACT_AUTHTIME_FROM_SEC_CONTEXT_OID_LENGTH, GSS_KRB5_EXTRACT_AUTHTIME_FROM_SEC_CONTEXT_OID},
gss_krb5int_extract_authtime_from_sec_context
}
};
OM_uint32
krb5_gss_inquire_sec_context_by_oid (OM_uint32 *minor_status,
const gss_ctx_id_t context_handle,
const gss_OID desired_object,
gss_buffer_set_t *data_set)
{
krb5_gss_ctx_id_rec *ctx;
size_t i;
if (minor_status == NULL)
return GSS_S_CALL_INACCESSIBLE_WRITE;
*minor_status = 0;
if (desired_object == GSS_C_NO_OID)
return GSS_S_CALL_INACCESSIBLE_READ;
if (data_set == NULL)
return GSS_S_CALL_INACCESSIBLE_WRITE;
*data_set = GSS_C_NO_BUFFER_SET;
if (!kg_validate_ctx_id(context_handle))
return GSS_S_NO_CONTEXT;
ctx = (krb5_gss_ctx_id_rec *) context_handle;
if (!ctx->established)
return GSS_S_NO_CONTEXT;
for (i = 0; i < sizeof(krb5_gss_inquire_sec_context_by_oid_ops)/
sizeof(krb5_gss_inquire_sec_context_by_oid_ops[0]); i++) {
if (g_OID_prefix_equal(desired_object, &krb5_gss_inquire_sec_context_by_oid_ops[i].oid)) {
return (*krb5_gss_inquire_sec_context_by_oid_ops[i].func)(minor_status,
context_handle,
desired_object,
data_set);
}
}
*minor_status = EINVAL;
return GSS_S_UNAVAILABLE;
}
#if 0 /* Solaris Kerberos - revisit for full 1.7/next resync */
MAKE_INIT_FUNCTION(gss_krb5int_lib_init);
MAKE_FINI_FUNCTION(gss_krb5int_lib_fini);
#endif
OM_uint32 gss_krb5int_initialize_library (void)
{
#if 0 /* Solaris Kerberos - revisit for full 1.7/next resync */
#ifdef _GSS_STATIC_LINK
return gssint_mechglue_initialize_library();
#else
return CALL_INIT_FUNCTION(gss_krb5int_lib_init);
#endif
#endif
return gssint_initialize_library();
}
#endif /* !KERNEL */
/*
* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
*/
/*
* lib/gssapi/krb5/import_sec_context.c
*
* Copyright 1995,2004 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.
*
*/
/*
* import_sec_context.c - Internalize the security context.
*/
#include "gssapiP_krb5.h"
/* for serialization initialization functions */
#include "k5-int.h"
#include "mglueP.h" /* SUNW15resync - for KGSS_ macros */
#ifdef _KERNEL
extern OM_uint32 kgss_release_oid(OM_uint32 *, gss_OID *);
#endif
/*
* Fix up the OID of the mechanism so that uses the static version of
* the OID if possible.
*/
gss_OID krb5_gss_convert_static_mech_oid(oid)
gss_OID oid;
{
const gss_OID_desc *p;
OM_uint32 minor_status;
for (p = krb5_gss_oid_array; p->length; p++) {
if ((oid->length == p->length) &&
(memcmp(oid->elements, p->elements, p->length) == 0)) {
(void) KGSS_RELEASE_OID(&minor_status, &oid);
return (gss_OID) p;
}
}
return oid;
}
krb5_error_code
krb5_gss_ser_init (krb5_context context)
{
krb5_error_code code;
static krb5_error_code (KRB5_CALLCONV *const fns[])(krb5_context) = {
krb5_ser_auth_context_init,
#ifndef _KERNEL
krb5_ser_context_init,
krb5_ser_ccache_init, krb5_ser_rcache_init, krb5_ser_keytab_init,
#endif
};
int i;
for (i = 0; i < sizeof(fns)/sizeof(fns[0]); i++)
if ((code = (fns[i])(context)) != 0)
return code;
return 0;
}
OM_uint32
krb5_gss_import_sec_context(minor_status, interprocess_token, context_handle)
OM_uint32 *minor_status;
gss_buffer_t interprocess_token;
gss_ctx_id_t *context_handle;
{
krb5_context context;
krb5_error_code kret = 0;
size_t blen;
krb5_gss_ctx_id_t ctx;
krb5_octet *ibp;
/* This is a bit screwy. We create a krb5 context because we need
one when calling the serialization code. However, one of the
objects we're unpacking is a krb5 context, so when we finish,
we can throw this one away. */
kret = KGSS_INIT_CONTEXT(&context);
if (kret) {
*minor_status = kret;
return GSS_S_FAILURE;
}
kret = krb5_gss_ser_init(context);
if (kret) {
*minor_status = kret;
save_error_info(*minor_status, context);
krb5_free_context(context);
return GSS_S_FAILURE;
}
/* Assume a tragic failure */
ctx = (krb5_gss_ctx_id_t) NULL;
*minor_status = 0;
/* Internalize the context */
ibp = (krb5_octet *) interprocess_token->value;
blen = (size_t) interprocess_token->length;
kret = kg_ctx_internalize(context, (krb5_pointer *) &ctx, &ibp, &blen);
/*
* SUNW15resync
*
* krb5_free_context(context);
* Previous versions of MIT(1.2ish)/Solaris did not serialize the
* k5_context but MIT 1.5 does. But we don't need all the userspace
* junk in the kernel so we continue to not serialize it.
* So we keep this context live here (see it's use in kg_ctx_internalize)
* and it will get freed by delete_sec_context.
*/
if (kret) {
*minor_status = (OM_uint32) kret;
save_error_info(*minor_status, context);
krb5_free_context(context);
return(GSS_S_FAILURE);
}
/* intern the context handle */
if (! kg_save_ctx_id((gss_ctx_id_t) ctx)) {
(void)krb5_gss_delete_sec_context(minor_status,
(gss_ctx_id_t *) &ctx, NULL
#ifdef _KERNEL
,0 /* gssd_ctx_verifier */
#endif
);
*minor_status = (OM_uint32) G_VALIDATE_FAILED;
return(GSS_S_FAILURE);
}
ctx->mech_used = krb5_gss_convert_static_mech_oid(ctx->mech_used);
*context_handle = (gss_ctx_id_t) ctx;
*minor_status = 0;
return (GSS_S_COMPLETE);
}
/*
* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Copyright 1993 by OpenVision Technologies, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appears in all copies and
* that both that copyright notice and this permission notice appear in
* supporting documentation, and that the name of OpenVision not be used
* in advertising or publicity pertaining to distribution of the software
* without specific, written prior permission. OpenVision makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
* OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
/*
* 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 "gssapiP_krb5.h"
#include <k5-int.h>
static krb5_error_code
make_seal_token_v1 (krb5_context context,
krb5_keyblock *enc,
krb5_keyblock *seq,
gssint_uint64 *seqnum,
int direction,
gss_buffer_t text,
gss_buffer_t token,
int signalg,
size_t cksum_size,
int sealalg,
int encrypt,
int toktype,
int bigend,
gss_OID oid)
{
krb5_error_code code;
size_t sumlen;
char *data_ptr;
krb5_data plaind;
krb5_checksum md5cksum;
krb5_checksum cksum;
/* msglen contains the message length
* we are signing/encrypting. tmsglen
* contains the length of the message
* we plan to write out to the token.
* tlen is the length of the token
* including header. */
unsigned conflen=0, tmsglen, tlen, msglen;
unsigned char *t, *ptr;
unsigned char *plain;
unsigned char pad;
krb5_keyusage sign_usage = KG_USAGE_SIGN;
OM_uint32 seqnum32;
/* Solaris Kerberos: check for recognized signalg and sealalg */
KRB5_LOG0(KRB5_INFO, "make_seal_token_v1() start\n");
#ifdef _KERNEL
/*
* Because the ARCFOUR code bypasses the standard
* crypto interfaces, we must make sure the kernel
* crypto framework mechanism types are properly
* initialized here.
*/
context->kef_cipher_mt = get_cipher_mech_type(context, seq);
context->kef_hash_mt = get_hash_mech_type(context, seq);
if ((code = init_key_kef(context->kef_cipher_mt, seq))) {
return (code);
}
if ((code = init_key_kef(context->kef_cipher_mt, enc))) {
return (code);
}
#endif /* _KERNEL */
/* create the token buffer */
/* Do we need confounder? */
if (encrypt || (!bigend && (toktype == KG_TOK_SEAL_MSG)))
conflen = kg_confounder_size(context, enc);
else conflen = 0;
if (toktype == KG_TOK_SEAL_MSG) {
switch (sealalg) {
case SEAL_ALG_MICROSOFT_RC4:
msglen = conflen + text->length+1;
pad = 1;
break;
default:
/* XXX knows that des block size is 8 */
msglen = (conflen+text->length+8)&(~7);
pad = 8-(text->length%8);
}
tmsglen = msglen;
} else {
tmsglen = 0;
msglen = text->length;
pad = 0;
}
tlen = g_token_size((gss_OID) oid, 14+cksum_size+tmsglen);
if ((t = (unsigned char *) xmalloc(tlen)) == NULL)
return(ENOMEM);
/*** fill in the token */
ptr = t;
g_make_token_header((gss_OID) oid, 14+cksum_size+tmsglen, &ptr, toktype);
/* 0..1 SIGN_ALG */
ptr[0] = (unsigned char) (signalg & 0xff);
ptr[1] = (unsigned char) ((signalg >> 8) & 0xff);
/* 2..3 SEAL_ALG or Filler */
if ((toktype == KG_TOK_SEAL_MSG) && encrypt) {
ptr[2] = (unsigned char) (sealalg & 0xff);
ptr[3] = (unsigned char) ((sealalg >> 8) & 0xff);
} else {
/* No seal */
ptr[2] = 0xff;
ptr[3] = 0xff;
}
/* 4..5 Filler */
ptr[4] = 0xff;
ptr[5] = 0xff;
/* pad the plaintext, encrypt if needed, and stick it in the token */
/* initialize the the cksum */
switch (signalg) {
case SGN_ALG_DES_MAC_MD5:
case SGN_ALG_MD2_5:
md5cksum.checksum_type = CKSUMTYPE_RSA_MD5;
break;
case SGN_ALG_HMAC_SHA1_DES3_KD:
md5cksum.checksum_type = CKSUMTYPE_HMAC_SHA1_DES3;
break;
case SGN_ALG_HMAC_MD5:
md5cksum.checksum_type = CKSUMTYPE_HMAC_MD5_ARCFOUR;
if (toktype != KG_TOK_SEAL_MSG)
sign_usage = 15;
break;
default:
KRB5_LOG(KRB5_ERR, "make_seal_token_v1() end, error2 signalg=%d\n",
signalg);
#ifndef _KERNEL
abort ();
#else
return (GSS_S_DEFECTIVE_TOKEN);
#endif /* _KERNEL */
}
code = krb5_c_checksum_length(context, md5cksum.checksum_type, &sumlen);
if (code) {
KRB5_LOG(KRB5_ERR, "make_seal_token_v1() end, krb5_c_checksum_length() "
"error code=%d\n", code);
return(code);
}
md5cksum.length = sumlen;
if ((plain = (unsigned char *) xmalloc(msglen ? msglen : 1)) == NULL) {
xfree_wrap(t, tlen);
return(ENOMEM);
}
if (conflen) {
if ((code = kg_make_confounder(context, enc, plain))) {
xfree_wrap(plain, msglen ? msglen : 1);
xfree_wrap(t, tlen);
KRB5_LOG(KRB5_ERR, "make_seal_token_v1() end, "
"kg_make_confounder() error code=%d\n", code);
return(code);
}
}
(void) memcpy(plain+conflen, text->value, text->length);
if (pad) (void) memset(plain+conflen+text->length, pad, pad);
/* compute the checksum */
/* 8 = head of token body as specified by mech spec */
if (! (data_ptr = (char *) xmalloc(8 +
(bigend ? text->length : msglen)))) {
xfree_wrap(plain, msglen ? msglen : 1);
xfree_wrap(t, tlen);
return(ENOMEM);
}
(void) memcpy(data_ptr, ptr-2, 8);
if (bigend)
(void) memcpy(data_ptr+8, text->value, text->length);
else
(void) memcpy(data_ptr+8, plain, msglen);
plaind.length = 8 + (bigend ? text->length : msglen);
plaind.data = data_ptr;
code = krb5_c_make_checksum(context, md5cksum.checksum_type, seq,
sign_usage, &plaind, &md5cksum);
xfree_wrap(data_ptr,8 + (bigend ? text->length : msglen));
if (code) {
KRB5_LOG(KRB5_ERR, "make_seal_token_v1() end, "
"krb5_c_make_checksum() error code=%d\n", code);
xfree_wrap(plain, msglen ? msglen : 1);
xfree_wrap(t, tlen);
return(code);
}
switch(signalg) {
case SGN_ALG_DES_MAC_MD5:
case 3:
if ((code = kg_encrypt(context, seq, KG_USAGE_SEAL,
(g_OID_equal(oid, gss_mech_krb5_old) ?
seq->contents : NULL),
md5cksum.contents, md5cksum.contents, 16))) {
xfree_wrap(md5cksum.contents, md5cksum.length);
xfree_wrap(t, tlen);
KRB5_LOG(KRB5_ERR, "make_seal_token_v1() end, kg_encrypt() "
"error code=%d\n", code);
return code;
}
cksum.length = cksum_size;
cksum.contents = md5cksum.contents + 16 - cksum.length;
(void) memcpy(ptr+14, cksum.contents, cksum.length);
break;
case SGN_ALG_HMAC_SHA1_DES3_KD:
/*
* Using key derivation, the call to krb5_c_make_checksum
* already dealt with encrypting.
*/
if (md5cksum.length != cksum_size)
{
KRB5_LOG1(KRB5_ERR, "make_seal_token_v1() end, error "
"md5cksum.length %u != "
"cksum_size %u\n",
(unsigned int)md5cksum.length,
(unsigned int) cksum_size);
#ifndef _KERNEL
abort ();
#else
return (GSS_S_DEFECTIVE_TOKEN);
#endif
}
(void) memcpy(ptr+14, md5cksum.contents, md5cksum.length);
break;
case SGN_ALG_HMAC_MD5:
KRB5_LOG(KRB5_INFO, "make_seal_token_v1() cksum_size = %u",
(unsigned int)cksum_size);
(void) memcpy(ptr+14, md5cksum.contents, cksum_size);
break;
}
xfree_wrap(md5cksum.contents, md5cksum.length);
/* create the seq_num */
seqnum32 = (OM_uint32)(*seqnum & 0xFFFFFFFF);
if ((code = kg_make_seq_num(context, seq, direction?0:0xff, seqnum32,
ptr+14, ptr+6))) {
xfree_wrap(t, tlen);
KRB5_LOG(KRB5_ERR, "make_seal_token_v1() end, kg_make_seq_num() "
"error code=%d\n", code);
return(code);
}
if (encrypt) {
switch(sealalg) {
case SEAL_ALG_MICROSOFT_RC4:
{
unsigned char bigend_seqnum[4];
krb5_keyblock *enc_key;
int i;
bigend_seqnum[0] = (*seqnum>>24) & 0xff;
bigend_seqnum[1] = (*seqnum>>16) & 0xff;
bigend_seqnum[2] = (*seqnum>>8) & 0xff;
bigend_seqnum[3] = *seqnum & 0xff;
code = krb5_copy_keyblock (context, enc, &enc_key);
if (code)
{
xfree_wrap(plain, msglen ? msglen : 1);
xfree_wrap(t, tlen);
return(code);
}
for (i = 0; i <= 15; i++)
((char *) enc_key->contents)[i] ^=0xf0;
code = kg_arcfour_docrypt (context, enc_key, 0,
bigend_seqnum, 4,
plain, tmsglen,
ptr+14+cksum_size);
krb5_free_keyblock (context, enc_key);
if (code)
{
xfree_wrap(plain, msglen ? msglen : 1);
xfree_wrap(t, tlen);
return(code);
}
}
break;
default:
if ((code = kg_encrypt(context, enc, KG_USAGE_SEAL, NULL,
(krb5_pointer) plain,
(krb5_pointer) (ptr+cksum_size+14),
tmsglen))) {
xfree_wrap(plain, msglen ? msglen : 1);
xfree_wrap(t, tlen);
return(code);
}
}
}else {
if (tmsglen)
(void) memcpy(ptr+14+cksum_size, plain, tmsglen);
}
xfree_wrap(plain, msglen ? msglen : 1);
/* that's it. return the token */
(*seqnum)++;
*seqnum &= (ulong_t)0xffffffffU;
token->length = tlen;
token->value = (void *) t;
KRB5_LOG0(KRB5_INFO, "make_seal_token_v1() end\n");
return(0);
}
/* if signonly is true, ignore conf_req, conf_state,
and do not encode the ENC_TYPE, MSG_LENGTH, or MSG_TEXT fields */
OM_uint32
kg_seal(minor_status, context_handle, conf_req_flag, qop_req,
input_message_buffer, conf_state, output_message_buffer, toktype)
OM_uint32 *minor_status;
gss_ctx_id_t context_handle;
int conf_req_flag;
int qop_req;
gss_buffer_t input_message_buffer;
int *conf_state;
gss_buffer_t output_message_buffer;
int toktype;
{
krb5_gss_ctx_id_rec *ctx;
krb5_error_code code;
krb5_timestamp now;
krb5_context context;
KRB5_LOG0(KRB5_INFO, "kg_seal() start");
output_message_buffer->length = 0;
output_message_buffer->value = NULL;
/* Only default qop or matching established cryptosystem is allowed.
There are NO EXTENSIONS to this set for AES and friends! The
new spec says "just use 0". The old spec plus extensions would
actually allow for certain non-zero values. Fix this to handle
them later. */
if (qop_req != 0) {
*minor_status = (OM_uint32) G_UNKNOWN_QOP;
KRB5_LOG0(KRB5_ERR, "kg_seal() end, error G_UNKNOWN_QOP\n");
return (GSS_S_BAD_QOP);
}
/* validate the context handle */
if (! kg_validate_ctx_id(context_handle)) {
*minor_status = (OM_uint32) G_VALIDATE_FAILED;
KRB5_LOG0(KRB5_ERR, "kg_seal() kg_validate_ctx_id() end, "
"error GSS_S_NO_CONTEXT\n");
return (GSS_S_NO_CONTEXT);
}
ctx = (krb5_gss_ctx_id_rec *) context_handle;
if (ctx->subkey == NULL && !ctx->established) {
*minor_status = KG_CTX_INCOMPLETE;
return(GSS_S_NO_CONTEXT);
}
context = ctx->k5_context;
if ((code = krb5_timeofday(context, &now))) {
*minor_status = code;
save_error_info(*minor_status, context);
KRB5_LOG(KRB5_ERR, "kg_seal() end, krb5_timeofday() error code=%d\n", code);
return (GSS_S_FAILURE);
}
switch (ctx->proto)
{
case 0:
code = make_seal_token_v1(context, ctx->enc, ctx->seq,
&ctx->seq_send, ctx->initiate,
input_message_buffer, output_message_buffer,
ctx->signalg, ctx->cksum_size, ctx->sealalg,
conf_req_flag, toktype, ctx->big_endian,
ctx->mech_used);
break;
case 1:
code = gss_krb5int_make_seal_token_v3(context, ctx,
input_message_buffer,
output_message_buffer,
conf_req_flag, toktype);
break;
default:
code = G_UNKNOWN_QOP; /* XXX */
break;
}
if (code) {
*minor_status = code;
save_error_info(*minor_status, context);
KRB5_LOG(KRB5_ERR, "kg_seal() end, make_seal_token_v1() "
"error code=%d\n", code);
return (GSS_S_FAILURE);
}
if (conf_state)
*conf_state = conf_req_flag;
*minor_status = 0;
if (ctx->endtime < now) {
(void) gss_release_buffer(minor_status, output_message_buffer);
KRB5_LOG(KRB5_ERR, "kg_seal() end, error GSS_S_CONTEXT_EXPIRED "
"ctx->endtime = %d\n", ctx->endtime);
return (GSS_S_CONTEXT_EXPIRED);
}
KRB5_LOG0(KRB5_INFO, "kg_seal() end\n");
return (GSS_S_COMPLETE);
}
/*
* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
*/
/*
* lib/gssapi/krb5/k5sealv3.c
*
* Copyright 2003,2004 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.
*
*
*/
/* draft-ietf-krb-wg-gssapi-cfx-05 */
#ifndef _KERNEL
#include <assert.h>
#include <stdarg.h>
#define ASSERT assert
#endif
/* Solaris Kerberos */
#include "k5-int.h" /* for zap() */
#include "k5-platform.h"
/* Solaris Kerberos */
#include "k5-platform-store_16.h"
#include "k5-platform-store_64.h"
#include "k5-platform-load_16.h"
#include "k5-platform-load_64.h"
#include "gssapiP_krb5.h"
#include <sys/int_limits.h>
static int
rotate_left (void *ptr, size_t bufsiz, size_t rc)
{
/* Optimize for receiving. After some debugging is done, the MIT
implementation won't do any rotates on sending, and while
debugging, they'll be randomly chosen.
Return 1 for success, 0 for failure (ENOMEM). */
void *tbuf;
if (bufsiz == 0)
return 1;
rc = rc % bufsiz;
if (rc == 0)
return 1;
tbuf = MALLOC(rc);
if (tbuf == 0)
return 0;
(void) memcpy(tbuf, ptr, rc);
(void) memmove(ptr, (char *)ptr + rc, bufsiz - rc);
(void) memcpy((char *)ptr + bufsiz - rc, tbuf, rc);
FREE(tbuf, rc);
return 1;
}
static const gss_buffer_desc empty_message = { 0, 0 };
#define FLAG_SENDER_IS_ACCEPTOR 0x01
#define FLAG_WRAP_CONFIDENTIAL 0x02
#define FLAG_ACCEPTOR_SUBKEY 0x04
krb5_error_code
gss_krb5int_make_seal_token_v3 (krb5_context context,
krb5_gss_ctx_id_rec *ctx,
const gss_buffer_desc * message,
gss_buffer_t token,
int conf_req_flag, int toktype)
{
size_t bufsize = 16;
unsigned char *outbuf = 0;
krb5_error_code err;
int key_usage;
unsigned char acceptor_flag;
const gss_buffer_desc *message2 = message;
#ifdef CFX_EXERCISE
size_t rrc;
#endif
size_t ec;
unsigned short tok_id;
krb5_checksum sum;
krb5_keyblock *key;
ASSERT(toktype != KG_TOK_SEAL_MSG || ctx->enc != 0);
ASSERT(ctx->big_endian == 0);
acceptor_flag = ctx->initiate ? 0 : FLAG_SENDER_IS_ACCEPTOR;
key_usage = (toktype == KG_TOK_WRAP_MSG
? (ctx->initiate
? KG_USAGE_INITIATOR_SEAL
: KG_USAGE_ACCEPTOR_SEAL)
: (ctx->initiate
? KG_USAGE_INITIATOR_SIGN
: KG_USAGE_ACCEPTOR_SIGN));
if (ctx->have_acceptor_subkey) {
key = ctx->acceptor_subkey;
} else {
key = ctx->enc;
}
#ifdef _KERNEL
context->kef_cipher_mt = get_cipher_mech_type(context, key);
context->kef_hash_mt = get_hash_mech_type(context, key);
if ((err = init_key_kef(context->kef_cipher_mt, key))) {
return (GSS_S_FAILURE);
}
#endif /* _KERNEL */
#ifdef CFX_EXERCISE
{
static int initialized = 0;
if (!initialized) {
srand(time(0));
initialized = 1;
}
}
#endif
if (toktype == KG_TOK_WRAP_MSG && conf_req_flag) {
krb5_data plain;
krb5_enc_data cipher;
size_t ec_max;
size_t tlen;
/* 300: Adds some slop. */
if (SIZE_MAX - 300 < message->length)
return ENOMEM;
ec_max = SIZE_MAX - message->length - 300;
if (ec_max > 0xffff)
ec_max = 0xffff;
/*
* EC should really be a multiple (1) of the number of octets that
* the cryptosystem would pad by if we didn't have the filler.
*
* For AES-CTS this will always be 0 and we expect no further
* enctypes, so there should be no issue here.
*/
ec = 0;
plain.length = message->length + 16 + ec;
plain.data = MALLOC(plain.length);
if (plain.data == NULL)
return ENOMEM;
/* Get size of ciphertext. */
if ((err = krb5_c_encrypt_length(context,
ctx->enc->enctype, plain.length, &tlen))) {
FREE(plain.data, plain.length);
return (err);
}
bufsize = 16 + tlen;
/* Allocate space for header plus encrypted data. */
outbuf = MALLOC(bufsize);
if (outbuf == NULL) {
FREE(plain.data, plain.length);
return ENOMEM;
}
/* TOK_ID */
store_16_be(0x0504, outbuf);
/* flags */
outbuf[2] = (acceptor_flag
| (conf_req_flag ? FLAG_WRAP_CONFIDENTIAL : 0)
| (ctx->have_acceptor_subkey ? FLAG_ACCEPTOR_SUBKEY : 0));
/* filler */
outbuf[3] = 0xff;
/* EC */
store_16_be(ec, outbuf+4);
/* RRC */
store_16_be(0, outbuf+6);
store_64_be(ctx->seq_send, outbuf+8);
(void) memcpy(plain.data, message->value, message->length);
(void) memset(plain.data + message->length, 'x', ec);
(void) memcpy(plain.data + message->length + ec, outbuf, 16);
/* Should really use scatter/gather crypto interfaces */
cipher.ciphertext.data = (char *)outbuf + 16;
cipher.ciphertext.length = bufsize - 16;
cipher.enctype = key->enctype;
err = krb5_c_encrypt(context, key, key_usage, 0, &plain, &cipher);
(void) bzero(plain.data, plain.length);
FREE(plain.data, plain.length);
plain.data = 0;
if (err)
goto error;
/* Now that we know we're returning a valid token.... */
ctx->seq_send++;
#ifdef CFX_EXERCISE
rrc = rand() & 0xffff;
if (rotate_left(outbuf+16, bufsize-16,
(bufsize-16) - (rrc % (bufsize - 16))))
store_16_be(rrc, outbuf+6);
/* If the rotate fails, don't worry about it. */
#endif
} else if (toktype == KG_TOK_WRAP_MSG && !conf_req_flag) {
krb5_data plain;
/* Here, message is the application-supplied data; message2 is
what goes into the output token. They may be the same, or
message2 may be empty (for MIC). */
tok_id = 0x0504;
wrap_with_checksum:
plain.length = message->length + 16;
plain.data = MALLOC(message->length + 16);
if (plain.data == NULL)
return ENOMEM;
if (ctx->cksum_size > 0xffff) {
FREE(plain.data, plain.length);
return EINVAL;
}
bufsize = 16 + message2->length + ctx->cksum_size;
outbuf = MALLOC(bufsize);
if (outbuf == NULL) {
FREE(plain.data, plain.length);
plain.data = 0;
err = ENOMEM;
goto error;
}
/* TOK_ID */
store_16_be(tok_id, outbuf);
/* flags */
outbuf[2] = (acceptor_flag
| (ctx->have_acceptor_subkey ? FLAG_ACCEPTOR_SUBKEY : 0));
/* filler */
outbuf[3] = 0xff;
if (toktype == KG_TOK_WRAP_MSG) {
/* Use 0 for checksum calculation, substitute
checksum length later. */
/* EC */
store_16_be(0, outbuf+4);
/* RRC */
store_16_be(0, outbuf+6);
} else {
/* MIC and DEL store 0xFF in EC and RRC. */
store_16_be(0xffff, outbuf+4);
store_16_be(0xffff, outbuf+6);
}
store_64_be(ctx->seq_send, outbuf+8);
(void) memcpy(plain.data, message->value, message->length);
(void) memcpy(plain.data + message->length, outbuf, 16);
/* Fill in the output token -- data contents, if any, and
space for the checksum. */
if (message2->length)
(void) memcpy(outbuf + 16, message2->value, message2->length);
sum.contents = outbuf + 16 + message2->length;
sum.length = ctx->cksum_size;
err = krb5_c_make_checksum(context, ctx->cksumtype, key,
key_usage, &plain, &sum);
bzero(plain.data, plain.length);
FREE(plain.data, plain.length);
plain.data = 0;
if (err) {
bzero(outbuf,bufsize);
err = KRB5KRB_AP_ERR_BAD_INTEGRITY;
goto error;
}
if (sum.length != ctx->cksum_size) {
err = KRB5KRB_AP_ERR_BAD_INTEGRITY;
goto error;
}
(void) memcpy(outbuf + 16 + message2->length, sum.contents,
ctx->cksum_size);
krb5_free_checksum_contents(context, &sum);
sum.contents = 0;
/* Now that we know we're actually generating the token... */
ctx->seq_send++;
if (toktype == KG_TOK_WRAP_MSG) {
#ifdef CFX_EXERCISE
rrc = rand() & 0xffff;
/* If the rotate fails, don't worry about it. */
if (rotate_left(outbuf+16, bufsize-16,
(bufsize-16) - (rrc % (bufsize - 16))))
store_16_be(rrc, outbuf+6);
#endif
/* Fix up EC field. */
store_16_be(ctx->cksum_size, outbuf+4);
} else {
store_16_be(0xffff, outbuf+6);
}
} else if (toktype == KG_TOK_MIC_MSG) {
tok_id = 0x0404;
message2 = &empty_message;
goto wrap_with_checksum;
} else if (toktype == KG_TOK_DEL_CTX) {
/*
* Solaris Kerberos:
* No token should be generated for context deletion. Just
* return.
*/
return 0;
} else {
err = KRB5KRB_AP_ERR_BAD_INTEGRITY;
goto error;
}
token->value = outbuf;
token->length = bufsize;
return 0;
error:
FREE(outbuf, bufsize);
token->value = NULL;
token->length = 0;
return err;
}
/* message_buffer is an input if SIGN, output if SEAL, and ignored if DEL_CTX
conf_state is only valid if SEAL. */
OM_uint32
gss_krb5int_unseal_token_v3(krb5_context *contextptr,
OM_uint32 *minor_status,
krb5_gss_ctx_id_rec *ctx,
unsigned char *ptr, int bodysize,
gss_buffer_t message_buffer,
int *conf_state, int *qop_state, int toktype)
{
krb5_context context = *contextptr;
krb5_data plain;
gssint_uint64 seqnum;
size_t ec, rrc;
int key_usage;
unsigned char acceptor_flag;
krb5_checksum sum;
krb5_error_code err;
krb5_boolean valid;
krb5_keyblock *key;
ASSERT(toktype != KG_TOK_SEAL_MSG || ctx->enc != 0);
ASSERT(ctx->big_endian == 0);
ASSERT(ctx->proto == 1);
if (qop_state)
*qop_state = GSS_C_QOP_DEFAULT;
acceptor_flag = ctx->initiate ? FLAG_SENDER_IS_ACCEPTOR : 0;
key_usage = (toktype == KG_TOK_WRAP_MSG
? (!ctx->initiate
? KG_USAGE_INITIATOR_SEAL
: KG_USAGE_ACCEPTOR_SEAL)
: (!ctx->initiate
? KG_USAGE_INITIATOR_SIGN
: KG_USAGE_ACCEPTOR_SIGN));
/* Oops. I wrote this code assuming ptr would be at the start of
the token header. */
ptr -= 2;
bodysize += 2;
if (bodysize < 16) {
defective:
*minor_status = 0;
return GSS_S_DEFECTIVE_TOKEN;
}
if ((ptr[2] & FLAG_SENDER_IS_ACCEPTOR) != acceptor_flag) {
*minor_status = (OM_uint32)G_BAD_DIRECTION;
return GSS_S_BAD_SIG;
}
/* Two things to note here.
First, we can't really enforce the use of the acceptor's subkey,
if we're the acceptor; the initiator may have sent messages
before getting the subkey. We could probably enforce it if
we're the initiator.
Second, if someone tweaks the code to not set the flag telling
the krb5 library to generate a new subkey in the AP-REP
message, the MIT library may include a subkey anyways --
namely, a copy of the AP-REQ subkey, if it was provided. So
the initiator may think we wanted a subkey, and set the flag,
even though we weren't trying to set the subkey. The "other"
key, the one not asserted by the acceptor, will have the same
value in that case, though, so we can just ignore the flag. */
if (ctx->have_acceptor_subkey && (ptr[2] & FLAG_ACCEPTOR_SUBKEY)) {
key = ctx->acceptor_subkey;
} else {
key = ctx->enc;
}
#ifdef _KERNEL
context->kef_cipher_mt = get_cipher_mech_type(context, key);
context->kef_hash_mt = get_hash_mech_type(context, key);
if ((err = init_key_kef(context->kef_cipher_mt, key))) {
return (GSS_S_FAILURE);
}
#endif /* _KERNEL */
if (toktype == KG_TOK_WRAP_MSG) {
if (load_16_be(ptr) != 0x0504)
goto defective;
if (ptr[3] != 0xff)
goto defective;
ec = load_16_be(ptr+4);
rrc = load_16_be(ptr+6);
seqnum = load_64_be(ptr+8);
if (!rotate_left(ptr+16, bodysize-16, rrc)) {
no_mem:
*minor_status = ENOMEM;
return GSS_S_FAILURE;
}
if (ptr[2] & FLAG_WRAP_CONFIDENTIAL) {
/* confidentiality */
krb5_enc_data cipher;
unsigned char *althdr;
size_t plainlen;
if (conf_state)
*conf_state = 1;
/* Do we have no decrypt_size function?
For all current cryptosystems, the ciphertext size will
be larger than the plaintext size. */
cipher.enctype = key->enctype;
cipher.ciphertext.length = bodysize - 16;
cipher.ciphertext.data = (char *)ptr + 16;
plain.length = plainlen = bodysize - 16;
plain.data = MALLOC(plain.length);
if (plain.data == NULL)
goto no_mem;
err = krb5_c_decrypt(context, key, key_usage, 0,
&cipher, &plain);
if (err) {
goto error;
}
/* Don't use bodysize here! Use the fact that
plain.length has been adjusted to the
correct length. */
althdr = (uchar_t *)plain.data + plain.length - 16;
if (load_16_be(althdr) != 0x0504
|| althdr[2] != ptr[2]
|| althdr[3] != ptr[3]
|| memcmp(althdr+8, ptr+8, 8)) {
FREE(plain.data, plainlen);
goto defective;
}
message_buffer->length = plain.length - ec - 16;
message_buffer->value = MALLOC(message_buffer->length);
if (message_buffer->value == NULL) {
FREE(plain.data, plainlen);
goto no_mem;
}
(void) memcpy(message_buffer->value, plain.data,
message_buffer->length);
FREE(plain.data, plainlen);
} else {
/* no confidentiality */
if (conf_state)
*conf_state = 0;
if (ec + 16 < ec)
/* overflow check */
goto defective;
if (ec + 16 > bodysize)
goto defective;
/* We have: header | msg | cksum.
We need cksum(msg | header).
Rotate the first two. */
store_16_be(0, ptr+4);
store_16_be(0, ptr+6);
plain.length = bodysize-ec;
plain.data = (char *)ptr;
if (!rotate_left(ptr, bodysize-ec, 16))
goto no_mem;
sum.length = ec;
if (sum.length != ctx->cksum_size) {
*minor_status = 0;
return GSS_S_BAD_SIG;
}
sum.contents = ptr+bodysize-ec;
sum.checksum_type = ctx->cksumtype;
err = krb5_c_verify_checksum(context, key, key_usage,
&plain, &sum, &valid);
if (err) {
*minor_status = err;
return GSS_S_BAD_SIG;
}
if (!valid) {
*minor_status = 0;
return GSS_S_BAD_SIG;
}
message_buffer->length = plain.length - 16;
message_buffer->value = MALLOC(message_buffer->length);
if (message_buffer->value == NULL)
goto no_mem;
(void) memcpy(message_buffer->value,
plain.data, message_buffer->length);
/*
* Solaris Kerberos: Restore the original token.
* This allows the token to be detected as a duplicate if it
* is passed in to gss_unwrap() again.
*/
if (!rotate_left(ptr, bodysize-ec, bodysize - ec - 16))
goto no_mem;
store_16_be(ec, ptr+4);
store_16_be(rrc, ptr+6);
}
err = g_order_check(&ctx->seqstate, seqnum);
*minor_status = 0;
return err;
} else if (toktype == KG_TOK_MIC_MSG) {
/* wrap token, no confidentiality */
if (load_16_be(ptr) != 0x0404)
goto defective;
verify_mic_1:
if (ptr[3] != 0xff)
goto defective;
if (load_32_be(ptr+4) != (ulong_t)0xffffffffU)
goto defective;
seqnum = load_64_be(ptr+8);
plain.length = message_buffer->length + 16;
plain.data = MALLOC(plain.length);
if (plain.data == NULL)
goto no_mem;
if (message_buffer->length)
(void) memcpy(plain.data,
message_buffer->value, message_buffer->length);
(void) memcpy(plain.data + message_buffer->length, ptr, 16);
sum.length = bodysize - 16;
sum.contents = ptr + 16;
sum.checksum_type = ctx->cksumtype;
err = krb5_c_verify_checksum(context, key, key_usage,
&plain, &sum, &valid);
if (err) {
error:
FREE(plain.data, plain.length);
*minor_status = err;
save_error_info(*minor_status, context);
return GSS_S_BAD_SIG; /* XXX */
}
FREE(plain.data, plain.length);
if (!valid) {
*minor_status = 0;
return GSS_S_BAD_SIG;
}
err = g_order_check(&ctx->seqstate, seqnum);
*minor_status = 0;
return err;
} else if (toktype == KG_TOK_DEL_CTX) {
if (load_16_be(ptr) != 0x0405)
goto defective;
message_buffer = (gss_buffer_t)&empty_message;
goto verify_mic_1;
} else {
goto defective;
}
}
/*
* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Copyright 2001 by the Massachusetts Institute of Technology.
* Copyright 1993 by OpenVision Technologies, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appears in all copies and
* that both that copyright notice and this permission notice appear in
* supporting documentation, and that the name of OpenVision not be used
* in advertising or publicity pertaining to distribution of the software
* without specific, written prior permission. OpenVision makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
* OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
/*
* 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 "gssapiP_krb5.h"
#include "k5-int.h"
/* message_buffer is an input if SIGN, output if SEAL, and ignored if DEL_CTX
conf_state is only valid if SEAL. */
static OM_uint32
kg_unseal_v1(context, minor_status, ctx, ptr, bodysize, message_buffer,
conf_state, qop_state, toktype)
krb5_context context;
OM_uint32 *minor_status;
krb5_gss_ctx_id_rec *ctx;
unsigned char *ptr;
int bodysize;
gss_buffer_t message_buffer;
int *conf_state;
int *qop_state;
int toktype;
{
krb5_error_code code;
int conflen = 0;
int signalg;
int sealalg;
gss_buffer_desc token;
krb5_checksum cksum;
krb5_checksum md5cksum;
krb5_data plaind;
char *data_ptr;
krb5_timestamp now;
unsigned char *plain;
unsigned int cksum_len = 0;
size_t plainlen;
int direction;
krb5_ui_4 seqnum;
OM_uint32 retval;
size_t sumlen, blocksize;
int tmsglen;
krb5_keyusage sign_usage = KG_USAGE_SIGN;
KRB5_LOG0(KRB5_INFO, "kg_unseal_v1() start\n");
/* Solaris Kerberos: make sure this is initialized */
*minor_status = 0;
if (toktype == KG_TOK_SEAL_MSG) {
message_buffer->length = 0;
message_buffer->value = NULL;
}
/* get the sign and seal algorithms */
signalg = ptr[0] + (ptr[1]<<8);
sealalg = ptr[2] + (ptr[3]<<8);
/* Sanity checks */
if ((ptr[4] != 0xff) || (ptr[5] != 0xff)) {
*minor_status = 0;
KRB5_LOG0(KRB5_ERR, "kg_unseal_v1() end, error GSS_S_DEFECTIVE_TOKEN\n");
return GSS_S_DEFECTIVE_TOKEN;
}
if ((toktype != KG_TOK_SEAL_MSG) &&
(sealalg != 0xffff)) {
*minor_status = 0;
KRB5_LOG0(KRB5_ERR, "kg_unseal_v1() end, error2 GSS_S_DEFECTIVE_TOKEN\n");
return GSS_S_DEFECTIVE_TOKEN;
}
/* in the current spec, there is only one valid seal algorithm per
key type, so a simple comparison is ok */
if ((toktype == KG_TOK_SEAL_MSG) &&
!((sealalg == 0xffff) ||
(sealalg == ctx->sealalg))) {
*minor_status = 0;
KRB5_LOG0(KRB5_ERR, "kg_unseal_v1() end, error3 GSS_S_DEFECTIVE_TOKEN\n");
return GSS_S_DEFECTIVE_TOKEN;
}
/* there are several mappings of seal algorithms to sign algorithms,
but few enough that we can try them all. */
if ((ctx->sealalg == SEAL_ALG_NONE && signalg > 1) ||
(ctx->sealalg == SEAL_ALG_1 && signalg != SGN_ALG_3) ||
(ctx->sealalg == SEAL_ALG_DES3KD &&
signalg != SGN_ALG_HMAC_SHA1_DES3_KD)||
(ctx->sealalg == SEAL_ALG_MICROSOFT_RC4 &&
signalg != SGN_ALG_HMAC_MD5)) {
*minor_status = 0;
KRB5_LOG0(KRB5_ERR, "kg_unseal_v1() end, error4 GSS_S_DEFECTIVE_TOKEN\n");
return GSS_S_DEFECTIVE_TOKEN;
}
KRB5_LOG(KRB5_INFO, "kg_unseal_v1() signalg = %d\n", signalg);
switch (signalg) {
case SGN_ALG_DES_MAC_MD5:
case SGN_ALG_MD2_5:
case SGN_ALG_HMAC_MD5:
cksum_len = 8;
if (toktype != KG_TOK_SEAL_MSG)
sign_usage = 15;
break;
case SGN_ALG_3:
cksum_len = 16;
break;
case SGN_ALG_HMAC_SHA1_DES3_KD:
cksum_len = 20;
break;
default:
*minor_status = 0;
KRB5_LOG(KRB5_ERR, "kg_unseal_v1() end, error signalg=%d\n", signalg);
return GSS_S_DEFECTIVE_TOKEN;
}
#ifdef _KERNEL
/*
* Because the ARCFOUR code bypasses the standard
* crypto interfaces, we must make sure the kernel
* crypto framework mechanism types are properly
* initialized here.
*/
context->kef_cipher_mt = get_cipher_mech_type(context,
ctx->seq);
context->kef_hash_mt = get_hash_mech_type(context,
ctx->seq);
if ((code = init_key_kef(context->kef_cipher_mt,
ctx->seq))) {
*minor_status = code;
return (GSS_S_FAILURE);
}
if ((code = init_key_kef(context->kef_cipher_mt,
ctx->enc))) {
*minor_status = code;
return (GSS_S_FAILURE);
}
#endif /* _KERNEL */
/* get the token parameters */
if ((code = kg_get_seq_num(context, ctx->seq, ptr+14, ptr+6, &direction,
&seqnum))) {
*minor_status = code;
return(GSS_S_BAD_SIG);
}
/* decode the message, if SEAL */
if (toktype == KG_TOK_SEAL_MSG) {
tmsglen = bodysize-(14+cksum_len);
KRB5_LOG1(KRB5_INFO, "kg_unseal_v1() tmsglen = %d cksum_len = %d",
tmsglen, cksum_len);
KRB5_LOG0(KRB5_INFO, "kg_unseal_v1() toktype == KG_TOK_SEAL_MSG\n");
if (sealalg != 0xffff) {
if ((plain = (unsigned char *) xmalloc(tmsglen)) == NULL) {
*minor_status = ENOMEM;
KRB5_LOG0(KRB5_ERR, "kg_unseal_v1() end, error ENOMEM\n");
return(GSS_S_FAILURE);
}
if (ctx->enc->enctype == ENCTYPE_ARCFOUR_HMAC) {
unsigned char bigend_seqnum[4];
krb5_keyblock *enc_key;
int i;
bigend_seqnum[0] = (seqnum>>24) & 0xff;
bigend_seqnum[1] = (seqnum>>16) & 0xff;
bigend_seqnum[2] = (seqnum>>8) & 0xff;
bigend_seqnum[3] = seqnum & 0xff;
code = krb5_copy_keyblock (context, ctx->enc, &enc_key);
if (code)
{
xfree_wrap(plain, tmsglen);
*minor_status = code;
return(GSS_S_FAILURE);
}
for (i = 0; i <= 15; i++)
((char *) enc_key->contents)[i] ^=0xf0;
#ifndef _KERNEL
/*
* The enc_key contents were modified, delete the
* key object so it doesn't get used later.
*/
if (enc_key->hKey != CK_INVALID_HANDLE) {
(void)C_DestroyObject(krb_ctx_hSession(context),
enc_key->hKey);
enc_key->hKey = CK_INVALID_HANDLE;
}
#endif
KRB5_LOG(KRB5_INFO, "kg_unseal_v1() enc_key->enctype = %d",
enc_key->enctype);
code = kg_arcfour_docrypt (context,
enc_key, 0,
&bigend_seqnum[0], 4,
ptr+14+cksum_len, tmsglen,
plain);
krb5_free_keyblock (context, enc_key);
} else {
code = kg_decrypt(context, ctx->enc, KG_USAGE_SEAL, NULL,
ptr+14+cksum_len, plain, tmsglen);
}
if (code) {
xfree_wrap(plain, tmsglen);
*minor_status = code;
return(GSS_S_FAILURE);
}
} else {
plain = ptr+14+cksum_len;
}
plainlen = tmsglen;
if ((sealalg == 0xffff) && ctx->big_endian) {
token.length = tmsglen;
} else {
conflen = kg_confounder_size(context, ctx->enc);
/*
* Solaris Kerberos: we want to perform a sanity check on the
* pad length, so we know it can not be more than the blocksize.
*/
code = krb5_c_block_size(context, ctx->enc->enctype, &blocksize);
if (code != 0) {
if (sealalg != 0xffff)
xfree_wrap(plain, tmsglen);
*minor_status = code;
return(GSS_S_FAILURE);
}
if (plain[tmsglen-1] > blocksize) {
if (sealalg != 0xffff)
xfree_wrap(plain, tmsglen);
*minor_status = KG_BAD_LENGTH;
return(GSS_S_FAILURE);
}
token.length = tmsglen - conflen - plain[tmsglen-1];
}
if (token.length) {
if ((token.value = (void *) xmalloc(token.length)) == NULL) {
if (sealalg != 0xffff)
xfree_wrap(plain, tmsglen);
*minor_status = ENOMEM;
KRB5_LOG0(KRB5_ERR, "kg_unseal_v1() end, error2 ENOMEM\n");
return(GSS_S_FAILURE);
}
(void) memcpy(token.value, plain+conflen, token.length);
} else {
token.value = NULL;
}
} else if (toktype == KG_TOK_SIGN_MSG) {
KRB5_LOG0(KRB5_INFO, "kg_unseal_v1() toktype == KG_TOK_SIGN_MSG\n");
token = *message_buffer;
plain = token.value;
plainlen = token.length;
} else {
KRB5_LOG0(KRB5_INFO, "kg_unseal_v1() toktype == NULL\n");
token.length = 0;
token.value = NULL;
plain = token.value;
plainlen = token.length;
}
/* compute the checksum of the message */
/* initialize the the cksum */
switch (signalg) {
case SGN_ALG_DES_MAC_MD5:
case SGN_ALG_MD2_5:
case SGN_ALG_DES_MAC:
case SGN_ALG_3:
md5cksum.checksum_type = CKSUMTYPE_RSA_MD5;
break;
case SGN_ALG_HMAC_MD5:
md5cksum.checksum_type = CKSUMTYPE_HMAC_MD5_ARCFOUR;
break;
case SGN_ALG_HMAC_SHA1_DES3_KD:
md5cksum.checksum_type = CKSUMTYPE_HMAC_SHA1_DES3;
break;
default:
KRB5_LOG(KRB5_ERR, "kg_unseal_v1() end, error2 signalg=%d\n", signalg);
#ifndef _KERNEL
abort ();
#else
*minor_status = 0;
return(GSS_S_DEFECTIVE_TOKEN);
#endif /* _KERNEL */
}
code = krb5_c_checksum_length(context, md5cksum.checksum_type, &sumlen);
if (code)
{
KRB5_LOG(KRB5_ERR, "kg_unseal_v1() end, krb5_c_checksum_length() error "
"code=%d\n", code);
return(code);
}
md5cksum.length = (size_t)sumlen;
switch (signalg) {
case SGN_ALG_DES_MAC_MD5:
case SGN_ALG_3:
/* compute the checksum of the message */
/* 8 = bytes of token body to be checksummed according to spec */
if (! (data_ptr = (void *)
xmalloc(8 + (ctx->big_endian ? token.length : plainlen)))) {
if (sealalg != 0xffff)
xfree_wrap(plain, tmsglen);
if (toktype == KG_TOK_SEAL_MSG) {
xfree_wrap(token.value, token.length);
/* Solaris Kerberos: just to be safe since token.value is an
* output parameter.
*/
token.value = NULL;
token.length = 0;
}
*minor_status = ENOMEM;
KRB5_LOG0(KRB5_ERR, "kg_unseal_v1() end, error3 ENOMEM\n");
return(GSS_S_FAILURE);
}
(void) memcpy(data_ptr, ptr-2, 8);
if (ctx->big_endian)
(void) memcpy(data_ptr+8, token.value, token.length);
else
(void) memcpy(data_ptr+8, plain, plainlen);
plaind.length = 8 + (ctx->big_endian ? token.length : plainlen);
plaind.data = data_ptr;
code = krb5_c_make_checksum(context, md5cksum.checksum_type,
ctx->seq, sign_usage,
&plaind, &md5cksum);
xfree_wrap(data_ptr, 8 + (ctx->big_endian ? token.length : plainlen));
if (code) {
if (toktype == KG_TOK_SEAL_MSG) {
xfree_wrap(token.value, token.length);
/* Solaris Kerberos: just to be safe since token.value is an
* output parameter.
*/
token.value = NULL;
token.length = 0;
}
*minor_status = code;
KRB5_LOG(KRB5_ERR, "kg_unseal_v1() end, krb5_c_make_checksum() "
"error code = %d\n", code);
return(GSS_S_FAILURE);
}
if ((code = kg_encrypt(context, ctx->seq, KG_USAGE_SEAL,
(g_OID_equal(ctx->mech_used, gss_mech_krb5_old) ?
ctx->seq->contents : NULL),
md5cksum.contents, md5cksum.contents, 16))) {
xfree_wrap(md5cksum.contents, md5cksum.length);
if (toktype == KG_TOK_SEAL_MSG) {
xfree_wrap(token.value, token.length);
/* Solaris Kerberos: just to be safe since token.value is an
* output parameter.
*/
token.value = NULL;
token.length = 0;
}
*minor_status = code;
KRB5_LOG(KRB5_ERR, "kg_unseal_v1() end, kg_encrypt() error"
"code = %d\n", code);
return GSS_S_FAILURE;
}
if (signalg == 0)
cksum.length = 8;
else
cksum.length = 16;
cksum.contents = md5cksum.contents + 16 - cksum.length;
code = memcmp(cksum.contents, ptr+14, cksum.length);
break;
case SGN_ALG_MD2_5:
if (!ctx->seed_init &&
(code = kg_make_seed(context, ctx->subkey, ctx->seed))) {
xfree_wrap(md5cksum.contents, md5cksum.length);
if (sealalg != 0xffff)
xfree_wrap(plain, tmsglen);
if (toktype == KG_TOK_SEAL_MSG) {
xfree_wrap(token.value, token.length);
/* Solaris Kerberos: just to be safe since token.value is an
* output parameter.
*/
token.value = NULL;
token.length = 0;
}
*minor_status = code;
return GSS_S_FAILURE;
}
if (! (data_ptr = (void *)
xmalloc(sizeof(ctx->seed) + 8 +
(ctx->big_endian ? token.length : plainlen)))) {
xfree_wrap(md5cksum.contents, md5cksum.length);
if (sealalg == 0)
xfree_wrap(plain, tmsglen);
if (toktype == KG_TOK_SEAL_MSG) {
xfree_wrap(token.value, token.length);
/* Solaris Kerberos: just to be safe since token.value is an
* output parameter.
*/
token.value = NULL;
token.length = 0;
}
*minor_status = ENOMEM;
return(GSS_S_FAILURE);
}
(void) memcpy(data_ptr, ptr-2, 8);
(void) memcpy(data_ptr+8, ctx->seed, sizeof(ctx->seed));
if (ctx->big_endian)
(void) memcpy(data_ptr+8+sizeof(ctx->seed),
token.value, token.length);
else
(void) memcpy(data_ptr+8+sizeof(ctx->seed),
plain, plainlen);
plaind.length = 8 + sizeof(ctx->seed) +
(ctx->big_endian ? token.length : plainlen);
plaind.data = data_ptr;
xfree_wrap(md5cksum.contents, md5cksum.length);
code = krb5_c_make_checksum(context, md5cksum.checksum_type,
ctx->seq, KG_USAGE_SIGN,
&plaind, &md5cksum);
xfree_wrap(data_ptr, 8 + sizeof(ctx->seed) +
(ctx->big_endian ? token.length : plainlen));
if (code) {
if (sealalg == 0)
xfree_wrap(plain, tmsglen);
if (toktype == KG_TOK_SEAL_MSG) {
xfree_wrap(token.value, token.length);
/* Solaris Kerberos: just to be safe since token.value is an
* output parameter.
*/
token.value = NULL;
token.length = 0;
}
*minor_status = code;
return(GSS_S_FAILURE);
}
code = memcmp(md5cksum.contents, ptr+14, 8);
/* Falls through to defective-token?? */
/* FALLTHROUGH */
default:
*minor_status = 0;
KRB5_LOG0(KRB5_ERR, "kg_unseal_v1() end, error SGN_ALG_MD2_5 "
"GSS_S_DEFECTIVE_TOKEN\n");
return(GSS_S_DEFECTIVE_TOKEN);
case SGN_ALG_HMAC_SHA1_DES3_KD:
case SGN_ALG_HMAC_MD5:
/* compute the checksum of the message */
/* 8 = bytes of token body to be checksummed according to spec */
if (! (data_ptr = (void *)
xmalloc(8 + (ctx->big_endian ? token.length : plainlen)))) {
if (sealalg != 0xffff)
xfree_wrap(plain, tmsglen);
if (toktype == KG_TOK_SEAL_MSG) {
xfree_wrap(token.value, token.length);
/* Solaris Kerberos: just to be safe since token.value is an
* output parameter.
*/
token.value = NULL;
token.length = 0;
}
*minor_status = ENOMEM;
return(GSS_S_FAILURE);
}
(void) memcpy(data_ptr, ptr-2, 8);
if (ctx->big_endian) {
KRB5_LOG0(KRB5_INFO, "kg_unseal_v1() ctx->big_endian = 1\n");
(void) memcpy(data_ptr+8, token.value, token.length);
}
else {
KRB5_LOG0(KRB5_INFO, "kg_unseal_v1() ctx->big_endian = 0\n");
(void) memcpy(data_ptr+8, plain, plainlen);
}
plaind.length = 8 + (ctx->big_endian ? token.length : plainlen);
plaind.data = data_ptr;
code = krb5_c_make_checksum(context, md5cksum.checksum_type,
ctx->seq, sign_usage,
&plaind, &md5cksum);
xfree_wrap(data_ptr, 8 + (ctx->big_endian ? token.length : plainlen));
if (code) {
if (toktype == KG_TOK_SEAL_MSG) {
xfree_wrap(token.value, token.length);
/* Solaris Kerberos: just to be safe since token.value is an
* output parameter.
*/
token.value = NULL;
token.length = 0;
}
*minor_status = code;
KRB5_LOG0(KRB5_ERR, "kg_unseal_v1() end, error "
"SGN_ALG_HMAC_SHA1_DES3_KD GSS_S_FAILURE\n");
return(GSS_S_FAILURE);
}
/* compare the computed checksum against the transmitted checksum */
code = memcmp(md5cksum.contents, ptr+14, cksum_len);
KRB5_LOG(KRB5_INFO, "kg_unseal_v1() memcmp %d bytes", cksum_len);
break;
}
xfree_wrap(md5cksum.contents, md5cksum.length);
if (sealalg != 0xffff)
xfree_wrap(plain, tmsglen);
if (code) {
if (toktype == KG_TOK_SEAL_MSG) {
xfree_wrap(token.value, token.length);
/* Solaris Kerberos: just to be safe since token.value is an
* output parameter.
*/
token.value = NULL;
token.length = 0;
}
*minor_status = 0;
KRB5_LOG0(KRB5_ERR, "kg_unseal_v1() end, error GSS_S_BAD_SIG\n");
return(GSS_S_BAD_SIG);
}
if (conf_state)
*conf_state = (sealalg != 0xffff);
if (qop_state)
*qop_state = GSS_C_QOP_DEFAULT;
if ((code = krb5_timeofday(context, &now))) {
*minor_status = code;
KRB5_LOG(KRB5_ERR, "kg_unseal_v1() end, krb5_timeofday()"
"error code = %d\n", code);
return(GSS_S_FAILURE);
}
if (now > ctx->endtime) {
*minor_status = 0;
KRB5_LOG1(KRB5_ERR, "kg_unseal_v1() end, error "
"now %d > ctx->endtime %d\n", now, ctx->endtime);
return(GSS_S_CONTEXT_EXPIRED);
}
/* do sequencing checks */
if ((ctx->initiate && direction != 0xff) ||
(!ctx->initiate && direction != 0)) {
if (toktype == KG_TOK_SEAL_MSG) {
xfree_wrap(token.value, token.length);
/* Solaris Kerberos: just to be safe since token.value is an
* output parameter.
*/
token.value = NULL;
token.length = 0;
}
*minor_status = (OM_uint32) G_BAD_DIRECTION;
KRB5_LOG1(KRB5_ERR, "kg_unseal_v1() end, error GSS_S_BAD_SIG "
"G_BAD_DIRECTION ctx->initiate = %d "
"direction = %d\n", ctx->initiate, direction);
return(GSS_S_BAD_SIG);
}
retval = g_order_check(&(ctx->seqstate), (gssint_uint64)seqnum);
/* It got through unscathed, adjust the output message buffer. */
if (retval == 0 && toktype == KG_TOK_SEAL_MSG)
*message_buffer = token;
*minor_status = 0;
KRB5_LOG(KRB5_INFO, "kg_unseal_v1() end, retval = %d\n", retval);
return(retval);
}
/* message_buffer is an input if SIGN, output if SEAL, and ignored if DEL_CTX
conf_state is only valid if SEAL. */
OM_uint32
kg_unseal(minor_status, context_handle, input_token_buffer,
message_buffer, conf_state, qop_state, toktype)
OM_uint32 *minor_status;
gss_ctx_id_t context_handle;
gss_buffer_t input_token_buffer;
gss_buffer_t message_buffer;
int *conf_state;
int *qop_state;
int toktype;
{
krb5_gss_ctx_id_rec *ctx;
unsigned char *ptr;
int bodysize;
int err;
int toktype2;
KRB5_LOG0(KRB5_INFO, "kg_unseal() start \n");
/* validate the context handle */
if (! kg_validate_ctx_id(context_handle)) {
*minor_status = (OM_uint32) G_VALIDATE_FAILED;
KRB5_LOG0(KRB5_ERR, "kg_unseal() end, kg_validate_ctx_id() error "
"G_VALIDATE_FAILED \n");
return(GSS_S_NO_CONTEXT);
}
ctx = (krb5_gss_ctx_id_rec *) context_handle;
if (! ctx->established) {
*minor_status = KG_CTX_INCOMPLETE;
KRB5_LOG0(KRB5_ERR, "kg_unseal() end, error ! ctx->established \n");
return(GSS_S_NO_CONTEXT);
}
/* parse the token, leave the data in message_buffer, setting conf_state */
/* verify the header */
ptr = (unsigned char *) input_token_buffer->value;
if (ctx->proto)
switch (toktype) {
case KG_TOK_SIGN_MSG:
toktype2 = 0x0404;
break;
case KG_TOK_SEAL_MSG:
toktype2 = 0x0504;
break;
case KG_TOK_DEL_CTX:
toktype2 = 0x0405;
break;
default:
toktype2 = toktype;
break;
}
else
toktype2 = toktype;
err = g_verify_token_header(ctx->mech_used,
(uint32_t *)&bodysize, &ptr, toktype2,
input_token_buffer->length,
!ctx->proto);
if (err) {
*minor_status = err;
return GSS_S_DEFECTIVE_TOKEN;
}
if (ctx->proto == 0) {
err = kg_unseal_v1(ctx->k5_context, minor_status, ctx, ptr, bodysize,
message_buffer, conf_state, qop_state,
toktype);
} else {
err = gss_krb5int_unseal_token_v3(&ctx->k5_context, minor_status, ctx,
ptr, bodysize, message_buffer,
conf_state, qop_state, toktype);
}
*minor_status = err;
#ifndef _KERNEL
if (err != 0)
save_error_info (*minor_status, ctx->k5_context);
#endif
KRB5_LOG(KRB5_INFO, "kg_unseal() end, err = %d", err);
return(err);
}
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright 1993 by OpenVision Technologies, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appears in all copies and
* that both that copyright notice and this permission notice appear in
* supporting documentation, and that the name of OpenVision not be used
* in advertising or publicity pertaining to distribution of the software
* without specific, written prior permission. OpenVision makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
* OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
#include "gssapiP_krb5.h"
/*
* $Id: seal.c 16171 2004-03-15 17:45:01Z raeburn $
*/
/*ARGSUSED*/
OM_uint32
krb5_gss_seal(minor_status, context_handle, conf_req_flag,
qop_req, input_message_buffer, conf_state,
output_message_buffer
#ifdef _KERNEL
, gssd_ctx_verifier
#endif
)
OM_uint32 *minor_status;
gss_ctx_id_t context_handle;
int conf_req_flag;
int qop_req;
gss_buffer_t input_message_buffer;
int *conf_state;
gss_buffer_t output_message_buffer;
#ifdef _KERNEL
OM_uint32 gssd_ctx_verifier;
#endif
{
#ifdef KRB5_NO_PRIVACY
/*
* conf_req_flag must be zero;
* encryption is disallowed
* for global version
*/
if (conf_req_flag)
return (GSS_S_FAILURE);
#endif
return(kg_seal(minor_status, context_handle, conf_req_flag,
qop_req, input_message_buffer, conf_state,
output_message_buffer, KG_TOK_SEAL_MSG));
}
/* V2 interface */
OM_uint32
krb5_gss_wrap(minor_status, context_handle, conf_req_flag,
qop_req, input_message_buffer, conf_state,
output_message_buffer)
OM_uint32 *minor_status;
gss_ctx_id_t context_handle;
int conf_req_flag;
gss_qop_t qop_req;
gss_buffer_t input_message_buffer;
int *conf_state;
gss_buffer_t output_message_buffer;
{
#ifdef KRB5_NO_PRIVACY
return (GSS_S_FAILURE);
#else
return(kg_seal(minor_status, context_handle, conf_req_flag,
(int) qop_req, input_message_buffer, conf_state,
output_message_buffer, KG_TOK_WRAP_MSG));
#endif
}
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* lib/gssapi/krb5/ser_sctx.c
*
* Copyright 1995, 2004 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.
*
*/
/*
* ser_sctx.c - Handle [de]serialization of GSSAPI security context.
*/
/* Solaris Kerberos: order is important here. include gssapiP_krb5.h
* before all others, otherwise we get a LINT error from MALLOC macro
* being redefined in mechglueP.h */
#include "gssapiP_krb5.h"
#include "k5-int.h"
/*
* This module contains routines to [de]serialize
* krb5_gss_enc_desc and krb5_gss_ctx_id_t.
* XXX This whole serialization abstraction is unnecessary in a
* non-messaging environment, which krb5 is. Someday, this should
* all get redone without the extra level of indirection. I've done
* some of this work here, since adding new serializers is an internal
* krb5 interface, and I won't use those. There is some more
* deobfuscation (no longer anonymizing pointers, mostly) which could
* still be done. --marc
*/
/*ARGSUSED*/
static krb5_error_code
kg_oid_externalize(kcontext, arg, buffer, lenremain)
krb5_context kcontext;
krb5_pointer arg;
krb5_octet **buffer;
size_t *lenremain;
{
gss_OID oid = (gss_OID) arg;
krb5_error_code err;
err = krb5_ser_pack_int32(KV5M_GSS_OID, buffer, lenremain);
if (err)
return err;
err = krb5_ser_pack_int32((krb5_int32) oid->length,
buffer, lenremain);
if (err)
return err;
err = krb5_ser_pack_bytes((krb5_octet *) oid->elements,
oid->length, buffer, lenremain);
if (err)
return err;
err = krb5_ser_pack_int32(KV5M_GSS_OID, buffer, lenremain);
return err;
}
/*ARGSUSED*/
static krb5_error_code
kg_oid_internalize(kcontext, argp, buffer, lenremain)
krb5_context kcontext;
krb5_pointer *argp;
krb5_octet **buffer;
size_t *lenremain;
{
gss_OID oid;
krb5_int32 ibuf;
krb5_octet *bp;
size_t remain;
bp = *buffer;
remain = *lenremain;
/* Read in and check our magic number */
if (krb5_ser_unpack_int32(&ibuf, &bp, &remain))
return (EINVAL);
if (ibuf != KV5M_GSS_OID)
return (EINVAL);
oid = (gss_OID) MALLOC(sizeof(gss_OID_desc));
if (oid == NULL)
return ENOMEM;
if (krb5_ser_unpack_int32(&ibuf, &bp, &remain)) {
FREE(oid, sizeof(gss_OID_desc));
return EINVAL;
}
oid->length = ibuf;
oid->elements = MALLOC(ibuf);
if (oid->elements == 0) {
FREE(oid, sizeof(gss_OID_desc));
return ENOMEM;
}
if (krb5_ser_unpack_bytes((krb5_octet *) oid->elements,
oid->length, &bp, &remain)) {
FREE(oid->elements, oid->length);
FREE(oid, sizeof(gss_OID_desc));
return EINVAL;
}
/* Read in and check our trailing magic number */
if (krb5_ser_unpack_int32(&ibuf, &bp, &remain)) {
FREE(oid->elements, oid->length);
FREE(oid, sizeof(gss_OID_desc));
return (EINVAL);
}
if (ibuf != KV5M_GSS_OID) {
FREE(oid->elements, oid->length);
FREE(oid, sizeof(gss_OID_desc));
return (EINVAL);
}
*buffer = bp;
*lenremain = remain;
*argp = (krb5_pointer) oid;
return 0;
}
/*ARGSUSED*/
static krb5_error_code
kg_oid_size(kcontext, arg, sizep)
krb5_context kcontext;
krb5_pointer arg;
size_t *sizep;
{
krb5_error_code kret;
gss_OID oid;
size_t required;
kret = EINVAL;
/*LINTED*/
if ((oid = (gss_OID) arg)) {
required = 2*sizeof(krb5_int32); /* For the header and trailer */
required += sizeof(krb5_int32);
required += oid->length;
kret = 0;
*sizep += required;
}
return(kret);
}
/*ARGSUSED*/
static krb5_error_code
kg_queue_externalize(kcontext, arg, buffer, lenremain)
krb5_context kcontext;
krb5_pointer arg;
krb5_octet **buffer;
size_t *lenremain;
{
krb5_error_code err;
err = krb5_ser_pack_int32(KV5M_GSS_QUEUE, buffer, lenremain);
if (err == 0)
err = g_queue_externalize(arg, buffer, lenremain);
if (err == 0)
err = krb5_ser_pack_int32(KV5M_GSS_QUEUE, buffer, lenremain);
return err;
}
/*ARGSUSED*/
static krb5_error_code
kg_queue_internalize(kcontext, argp, buffer, lenremain)
krb5_context kcontext;
krb5_pointer *argp;
krb5_octet **buffer;
size_t *lenremain;
{
krb5_int32 ibuf;
krb5_octet *bp;
size_t remain;
krb5_error_code err;
bp = *buffer;
remain = *lenremain;
/* Read in and check our magic number */
if (krb5_ser_unpack_int32(&ibuf, &bp, &remain))
return (EINVAL);
if (ibuf != KV5M_GSS_QUEUE)
return (EINVAL);
err = g_queue_internalize(argp, &bp, &remain);
if (err)
return err;
/* Read in and check our trailing magic number */
if (krb5_ser_unpack_int32(&ibuf, &bp, &remain)) {
g_order_free(argp);
return (EINVAL);
}
if (ibuf != KV5M_GSS_QUEUE) {
g_order_free(argp);
return (EINVAL);
}
*buffer = bp;
*lenremain = remain;
return 0;
}
/*ARGSUSED*/
static krb5_error_code
kg_queue_size(kcontext, arg, sizep)
krb5_context kcontext;
krb5_pointer arg;
size_t *sizep;
{
krb5_error_code kret;
size_t required;
kret = EINVAL;
if (arg) {
required = 2*sizeof(krb5_int32); /* For the header and trailer */
(void) g_queue_size(arg, &required);
kret = 0;
*sizep += required;
}
return(kret);
}
/*
* Determine the size required for this krb5_gss_ctx_id_rec.
*/
krb5_error_code
kg_ctx_size(kcontext, arg, sizep)
krb5_context kcontext;
krb5_pointer arg;
size_t *sizep;
{
krb5_error_code kret;
krb5_gss_ctx_id_rec *ctx;
size_t required;
/*
* krb5_gss_ctx_id_rec requires:
* krb5_int32 for KG_CONTEXT
* krb5_int32 for initiate.
* krb5_int32 for established.
* krb5_int32 for big_endian.
* krb5_int32 for have_acceptor_subkey.
* krb5_int32 for seed_init.
* krb5_int32 for gss_flags.
* sizeof(seed) for seed
* ... for here
* ... for there
* ... for subkey
* krb5_int32 for signalg.
* krb5_int32 for cksum_size.
* krb5_int32 for sealalg.
* ... for enc
* ... for seq
* krb5_int32 for endtime.
* krb5_int32 for flags.
* krb5_int64 for seq_send.
* krb5_int64 for seq_recv.
* ... for seqstate
* ... for auth_context
* ... for mech_used
* krb5_int32 for proto
* krb5_int32 for cksumtype
* ... for acceptor_subkey
* krb5_int32 for acceptor_key_cksumtype
* krb5_int32 for cred_rcache
* krb5_int32 for trailer.
*/
kret = EINVAL;
/*LINTED*/
if ((ctx = (krb5_gss_ctx_id_rec *) arg)) {
required = 17*sizeof(krb5_int32);
required += 2*sizeof(krb5_int64);
required += sizeof(ctx->seed);
kret = 0;
if (!kret && ctx->here)
kret = krb5_size_opaque(kcontext,
KV5M_PRINCIPAL,
(krb5_pointer) ctx->here,
&required);
if (!kret && ctx->there)
kret = krb5_size_opaque(kcontext,
KV5M_PRINCIPAL,
(krb5_pointer) ctx->there,
&required);
if (!kret && ctx->subkey)
kret = krb5_size_opaque(kcontext,
KV5M_KEYBLOCK,
(krb5_pointer) ctx->subkey,
&required);
if (!kret && ctx->enc)
kret = krb5_size_opaque(kcontext,
KV5M_KEYBLOCK,
(krb5_pointer) ctx->enc,
&required);
if (!kret && ctx->seq)
kret = krb5_size_opaque(kcontext,
KV5M_KEYBLOCK,
(krb5_pointer) ctx->seq,
&required);
if (!kret)
kret = kg_oid_size(kcontext,
(krb5_pointer) ctx->mech_used,
&required);
if (!kret && ctx->seqstate)
kret = kg_queue_size(kcontext, ctx->seqstate, &required);
#ifndef PROVIDE_KERNEL_IMPORT
if (!kret)
kret = krb5_size_opaque(kcontext,
KV5M_CONTEXT,
(krb5_pointer) ctx->k5_context,
&required);
if (!kret)
kret = krb5_size_opaque(kcontext,
KV5M_AUTH_CONTEXT,
(krb5_pointer) ctx->auth_context,
&required);
#endif
if (!kret && ctx->acceptor_subkey)
kret = krb5_size_opaque(kcontext,
KV5M_KEYBLOCK,
(krb5_pointer) ctx->acceptor_subkey,
&required);
if (!kret)
*sizep += required;
}
return(kret);
}
/*
* Externalize this krb5_gss_ctx_id_ret.
*/
krb5_error_code
kg_ctx_externalize(kcontext, arg, buffer, lenremain)
krb5_context kcontext;
krb5_pointer arg;
krb5_octet **buffer;
size_t *lenremain;
{
krb5_error_code kret;
krb5_gss_ctx_id_rec *ctx;
size_t required;
krb5_octet *bp;
size_t remain;
#ifndef _KERNEL
krb5int_access kaccess;
kret = krb5int_accessor (&kaccess, KRB5INT_ACCESS_VERSION);
if (kret)
return(kret);
#endif
required = 0;
bp = *buffer;
remain = *lenremain;
kret = EINVAL;
/*LINTED*/
if ((ctx = (krb5_gss_ctx_id_rec *) arg)) {
kret = ENOMEM;
if (!kg_ctx_size(kcontext, arg, &required) &&
(required <= remain)) {
/* Our identifier */
(void) krb5_ser_pack_int32(KG_CONTEXT, &bp, &remain);
/* Now static data */
(void) krb5_ser_pack_int32((krb5_int32) ctx->initiate,
&bp, &remain);
(void) krb5_ser_pack_int32((krb5_int32) ctx->established,
&bp, &remain);
(void) krb5_ser_pack_int32((krb5_int32) ctx->big_endian,
&bp, &remain);
(void) krb5_ser_pack_int32((krb5_int32) ctx->have_acceptor_subkey,
&bp, &remain);
(void) krb5_ser_pack_int32((krb5_int32) ctx->seed_init,
&bp, &remain);
(void) krb5_ser_pack_int32((krb5_int32) ctx->gss_flags,
&bp, &remain);
(void) krb5_ser_pack_bytes((krb5_octet *) ctx->seed,
sizeof(ctx->seed),
&bp, &remain);
(void) krb5_ser_pack_int32((krb5_int32) ctx->signalg,
&bp, &remain);
(void) krb5_ser_pack_int32((krb5_int32) ctx->cksum_size,
&bp, &remain);
(void) krb5_ser_pack_int32((krb5_int32) ctx->sealalg,
&bp, &remain);
(void) krb5_ser_pack_int32((krb5_int32) ctx->endtime,
&bp, &remain);
(void) krb5_ser_pack_int32((krb5_int32) ctx->krb_flags,
&bp, &remain);
#ifndef _KERNEL
(void) (*kaccess.krb5_ser_pack_int64)((krb5_int64) ctx->seq_send,
&bp, &remain);
(void) (*kaccess.krb5_ser_pack_int64)((krb5_int64) ctx->seq_recv,
&bp, &remain);
#else
(void) krb5_ser_pack_int64((krb5_int64) ctx->seq_send,
&bp, &remain);
(void) krb5_ser_pack_int64((krb5_int64) ctx->seq_recv,
&bp, &remain);
#endif
/* Now dynamic data */
kret = 0;
if (!kret && ctx->mech_used)
kret = kg_oid_externalize(kcontext, ctx->mech_used,
&bp, &remain);
if (!kret && ctx->here)
kret = krb5_externalize_opaque(kcontext,
KV5M_PRINCIPAL,
(krb5_pointer) ctx->here,
&bp, &remain);
if (!kret && ctx->there)
kret = krb5_externalize_opaque(kcontext,
KV5M_PRINCIPAL,
(krb5_pointer) ctx->there,
&bp, &remain);
if (!kret && ctx->subkey)
kret = krb5_externalize_opaque(kcontext,
KV5M_KEYBLOCK,
(krb5_pointer) ctx->subkey,
&bp, &remain);
if (!kret && ctx->enc)
kret = krb5_externalize_opaque(kcontext,
KV5M_KEYBLOCK,
(krb5_pointer) ctx->enc,
&bp, &remain);
if (!kret && ctx->seq)
kret = krb5_externalize_opaque(kcontext,
KV5M_KEYBLOCK,
(krb5_pointer) ctx->seq,
&bp, &remain);
if (!kret && ctx->seqstate)
kret = kg_queue_externalize(kcontext,
ctx->seqstate, &bp, &remain);
#ifndef PROVIDE_KERNEL_IMPORT
if (!kret)
kret = krb5_externalize_opaque(kcontext,
KV5M_CONTEXT,
(krb5_pointer) ctx->k5_context,
&bp, &remain);
if (!kret)
kret = krb5_externalize_opaque(kcontext,
KV5M_AUTH_CONTEXT,
(krb5_pointer) ctx->auth_context,
&bp, &remain);
#endif
if (!kret)
kret = krb5_ser_pack_int32((krb5_int32) ctx->proto,
&bp, &remain);
if (!kret)
kret = krb5_ser_pack_int32((krb5_int32) ctx->cksumtype,
&bp, &remain);
if (!kret && ctx->acceptor_subkey)
kret = krb5_externalize_opaque(kcontext,
KV5M_KEYBLOCK,
(krb5_pointer) ctx->acceptor_subkey,
&bp, &remain);
if (!kret)
kret = krb5_ser_pack_int32((krb5_int32) ctx->acceptor_subkey_cksumtype,
&bp, &remain);
if (!kret)
kret = krb5_ser_pack_int32((krb5_int32) ctx->cred_rcache,
&bp, &remain);
/* trailer */
if (!kret)
kret = krb5_ser_pack_int32(KG_CONTEXT, &bp, &remain);
if (!kret) {
*buffer = bp;
*lenremain = remain;
}
}
}
return(kret);
}
/*
* Internalize this krb5_gss_ctx_id_t.
*/
krb5_error_code
kg_ctx_internalize(kcontext, argp, buffer, lenremain)
krb5_context kcontext;
krb5_pointer *argp;
krb5_octet **buffer;
size_t *lenremain;
{
krb5_error_code kret;
krb5_gss_ctx_id_rec *ctx;
krb5_int32 ibuf;
krb5_octet *bp;
size_t remain;
#ifndef _KERNEL
krb5int_access kaccess;
kret = krb5int_accessor (&kaccess, KRB5INT_ACCESS_VERSION);
if (kret)
return(kret);
#endif
bp = *buffer;
remain = *lenremain;
kret = EINVAL;
/* Read our magic number */
if (krb5_ser_unpack_int32(&ibuf, &bp, &remain))
ibuf = 0;
if (ibuf == KG_CONTEXT) {
kret = ENOMEM;
/* Get a context */
if ((remain >= (17*sizeof(krb5_int32)
+ 2*sizeof(krb5_int64)
+ sizeof(ctx->seed))) &&
(ctx = (krb5_gss_ctx_id_rec *)
xmalloc(sizeof(krb5_gss_ctx_id_rec)))) {
(void) memset(ctx, 0, sizeof(krb5_gss_ctx_id_rec));
ctx->k5_context = kcontext;
/* Get static data */
(void) krb5_ser_unpack_int32(&ibuf, &bp, &remain);
ctx->initiate = (int) ibuf;
(void) krb5_ser_unpack_int32(&ibuf, &bp, &remain);
ctx->established = (int) ibuf;
(void) krb5_ser_unpack_int32(&ibuf, &bp, &remain);
ctx->big_endian = (int) ibuf;
(void) krb5_ser_unpack_int32(&ibuf, &bp, &remain);
ctx->have_acceptor_subkey = (int) ibuf;
(void) krb5_ser_unpack_int32(&ibuf, &bp, &remain);
ctx->seed_init = (int) ibuf;
(void) krb5_ser_unpack_int32(&ibuf, &bp, &remain);
ctx->gss_flags = (int) ibuf;
(void) krb5_ser_unpack_bytes((krb5_octet *) ctx->seed,
sizeof(ctx->seed),
&bp, &remain);
(void) krb5_ser_unpack_int32(&ibuf, &bp, &remain);
ctx->signalg = (int) ibuf;
(void) krb5_ser_unpack_int32(&ibuf, &bp, &remain);
ctx->cksum_size = (int) ibuf;
(void) krb5_ser_unpack_int32(&ibuf, &bp, &remain);
ctx->sealalg = (int) ibuf;
(void) krb5_ser_unpack_int32(&ibuf, &bp, &remain);
ctx->endtime = (krb5_timestamp) ibuf;
(void) krb5_ser_unpack_int32(&ibuf, &bp, &remain);
ctx->krb_flags = (krb5_flags) ibuf;
#ifndef _KERNEL
(void) (*kaccess.krb5_ser_unpack_int64)((krb5_int64 *)&ctx->seq_send, &bp, &remain);
kret = (*kaccess.krb5_ser_unpack_int64)((krb5_int64 *)&ctx->seq_recv, &bp, &remain);
#else
(void) krb5_ser_unpack_int64((krb5_int64 *) (&ctx->seq_send),
&bp, &remain);
kret = krb5_ser_unpack_int64((krb5_int64 *) (&ctx->seq_recv),
&bp, &remain);
#endif
if (kret) {
xfree_wrap(ctx, sizeof (krb5_gss_ctx_id_rec));
return kret;
}
if ((kret = kg_oid_internalize(kcontext,
(krb5_pointer *) &ctx->mech_used, &bp,
&remain))) {
if (kret == EINVAL)
kret = 0;
}
/* Now get substructure data */
if ((kret = krb5_internalize_opaque(kcontext,
KV5M_PRINCIPAL,
(krb5_pointer *) &ctx->here,
&bp, &remain))) {
if (kret == EINVAL)
kret = 0;
}
if (!kret &&
(kret = krb5_internalize_opaque(kcontext,
KV5M_PRINCIPAL,
(krb5_pointer *) &ctx->there,
&bp, &remain))) {
if (kret == EINVAL)
kret = 0;
}
if (!kret &&
(kret = krb5_internalize_opaque(kcontext,
KV5M_KEYBLOCK,
(krb5_pointer *) &ctx->subkey,
&bp, &remain))) {
if (kret == EINVAL)
kret = 0;
}
if (!kret &&
(kret = krb5_internalize_opaque(kcontext,
KV5M_KEYBLOCK,
(krb5_pointer *) &ctx->enc,
&bp, &remain))) {
if (kret == EINVAL)
kret = 0;
}
if (!kret &&
(kret = krb5_internalize_opaque(kcontext,
KV5M_KEYBLOCK,
(krb5_pointer *) &ctx->seq,
&bp, &remain))) {
if (kret == EINVAL)
kret = 0;
}
if (!kret) {
kret = kg_queue_internalize(kcontext, &ctx->seqstate,
&bp, &remain);
if (kret == EINVAL)
kret = 0;
}
#ifndef PROVIDE_KERNEL_IMPORT
if (!kret)
kret = krb5_internalize_opaque(kcontext,
KV5M_CONTEXT,
(krb5_pointer *) &ctx->k5_context,
&bp, &remain);
if (!kret)
kret = krb5_internalize_opaque(kcontext,
KV5M_AUTH_CONTEXT,
(krb5_pointer *) &ctx->auth_context,
&bp, &remain);
#endif
if (!kret)
kret = krb5_ser_unpack_int32(&ibuf, &bp, &remain);
ctx->proto = ibuf;
if (!kret)
kret = krb5_ser_unpack_int32(&ibuf, &bp, &remain);
ctx->cksumtype = ibuf;
if (!kret &&
(kret = krb5_internalize_opaque(kcontext,
KV5M_KEYBLOCK,
(krb5_pointer *) &ctx->acceptor_subkey,
&bp, &remain))) {
if (kret == EINVAL)
kret = 0;
}
if (!kret)
kret = krb5_ser_unpack_int32(&ibuf, &bp, &remain);
ctx->cred_rcache = ibuf;
if (!kret)
kret = krb5_ser_unpack_int32(&ibuf, &bp, &remain);
ctx->acceptor_subkey_cksumtype = ibuf;
/* Get trailer */
if (!kret)
kret = krb5_ser_unpack_int32(&ibuf, &bp, &remain);
if (!kret && ibuf != KG_CONTEXT)
kret = EINVAL;
if (!kret) {
*buffer = bp;
*lenremain = remain;
*argp = (krb5_pointer) ctx;
} else {
if (ctx->seq)
krb5_free_keyblock(kcontext, ctx->seq);
if (ctx->enc)
krb5_free_keyblock(kcontext, ctx->enc);
if (ctx->subkey)
krb5_free_keyblock(kcontext, ctx->subkey);
if (ctx->there)
krb5_free_principal(kcontext, ctx->there);
if (ctx->here)
krb5_free_principal(kcontext, ctx->here);
xfree_wrap(ctx, sizeof (krb5_gss_ctx_id_rec));
}
}
}
return(kret);
}
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright 1993 by OpenVision Technologies, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appears in all copies and
* that both that copyright notice and this permission notice appear in
* supporting documentation, and that the name of OpenVision not be used
* in advertising or publicity pertaining to distribution of the software
* without specific, written prior permission. OpenVision makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
* OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
#include "gssapiP_krb5.h"
/*
* $Id: sign.c 16171 2004-03-15 17:45:01Z raeburn $
*/
/*ARGSUSED*/
OM_uint32
krb5_gss_sign(minor_status, context_handle,
qop_req, message_buffer,
message_token
#ifdef _KERNEL
, gssd_ctx_verifier
#endif
)
OM_uint32 *minor_status;
gss_ctx_id_t context_handle;
int qop_req;
gss_buffer_t message_buffer;
gss_buffer_t message_token;
#ifdef _KERNEL
OM_uint32 gssd_ctx_verifier;
#endif
{
return(kg_seal(minor_status, context_handle, 0,
qop_req, message_buffer, NULL,
message_token, KG_TOK_SIGN_MSG));
}
/* V2 interface */
OM_uint32
krb5_gss_get_mic(minor_status, context_handle, qop_req,
message_buffer, message_token)
OM_uint32 *minor_status;
gss_ctx_id_t context_handle;
gss_qop_t qop_req;
gss_buffer_t message_buffer;
gss_buffer_t message_token;
{
return(kg_seal(minor_status, context_handle, 0,
(int) qop_req, message_buffer, NULL,
message_token, KG_TOK_MIC_MSG));
}
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright 1993 by OpenVision Technologies, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appears in all copies and
* that both that copyright notice and this permission notice appear in
* supporting documentation, and that the name of OpenVision not be used
* in advertising or publicity pertaining to distribution of the software
* without specific, written prior permission. OpenVision makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
* OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
#include "gssapiP_krb5.h"
/*
* $Id: unseal.c 16171 2004-03-15 17:45:01Z raeburn $
*/
/*ARGSUSED*/
OM_uint32
krb5_gss_unseal(minor_status, context_handle,
input_message_buffer, output_message_buffer,
conf_state, qop_state
#ifdef _KERNEL
, gssd_ctx_verifier
#endif
)
OM_uint32 *minor_status;
gss_ctx_id_t context_handle;
gss_buffer_t input_message_buffer;
gss_buffer_t output_message_buffer;
int *conf_state;
int *qop_state;
#ifdef _KERNEL
OM_uint32 gssd_ctx_verifier;
#endif
{
return(kg_unseal(minor_status, context_handle,
input_message_buffer, output_message_buffer,
conf_state, qop_state, KG_TOK_SEAL_MSG));
}
/* V2 interface */
OM_uint32
krb5_gss_unwrap(minor_status, context_handle,
input_message_buffer, output_message_buffer,
conf_state, qop_state)
OM_uint32 *minor_status;
gss_ctx_id_t context_handle;
gss_buffer_t input_message_buffer;
gss_buffer_t output_message_buffer;
int *conf_state;
gss_qop_t *qop_state;
{
#ifdef KRB5_NO_PRIVACY
return (GSS_S_FAILURE);
#else
OM_uint32 rstat;
int qstate;
rstat = kg_unseal(minor_status, context_handle,
input_message_buffer, output_message_buffer,
conf_state, &qstate, KG_TOK_WRAP_MSG);
if (!rstat && qop_state)
*qop_state = (gss_qop_t) qstate;
return(rstat);
#endif
}
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright2001 by the Massachusetts Institute of Technology.
* Copyright 1993 by OpenVision Technologies, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appears in all copies and
* that both that copyright notice and this permission notice appear in
* supporting documentation, and that the name of OpenVision not be used
* in advertising or publicity pertaining to distribution of the software
* without specific, written prior permission. OpenVision makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
* OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
/*
* 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.
*/
/* Solaris Kerberos: order is important here. include gssapiP_krb5.h
* before all others, otherwise we get a LINT error from MALLOC macro
* being redefined in mechglueP.h */
#include <gssapiP_krb5.h>
#include <k5-int.h>
/* Solaris Kerberos defines memory management macros in <krb5.h> */
/* #include <memory.h> */
/*
* $Id: util_crypt.c,v 1.11.6.3 2000/06/03 06:09:45 tlyu Exp $
*/
int
kg_confounder_size(context, key)
krb5_context context;
krb5_keyblock *key;
{
krb5_error_code code;
size_t blocksize;
/* We special case rc4*/
if (key->enctype == ENCTYPE_ARCFOUR_HMAC)
return 8;
code = krb5_c_block_size(context, key->enctype, &blocksize);
if (code)
return(-1); /* XXX */
return(blocksize);
}
krb5_error_code
kg_make_confounder(context, key, buf)
krb5_context context;
krb5_keyblock *key;
unsigned char *buf;
{
krb5_error_code code;
size_t blocksize;
krb5_data lrandom;
code = krb5_c_block_size(context, key->enctype, &blocksize);
if (code)
return(code);
lrandom.length = blocksize;
lrandom.data = (char *) buf;
return(krb5_c_random_make_octets(context, &lrandom));
}
int
kg_encrypt_size(context, key, n)
krb5_context context;
krb5_keyblock *key;
int n;
{
size_t enclen;
if (krb5_c_encrypt_length(context, key->enctype, n, &enclen) != 0)
return(-1); /* XXX */
return(enclen);
}
krb5_error_code
kg_encrypt(context, key, usage, iv, in, out, length)
krb5_context context;
krb5_keyblock *key;
int usage;
krb5_pointer iv;
krb5_const_pointer in;
krb5_pointer out;
unsigned int length;
{
krb5_error_code code;
size_t blocksize;
krb5_data ivd, *pivd, inputd;
krb5_enc_data outputd;
KRB5_LOG0(KRB5_INFO, "kg_encrypt() start.");
if (iv) {
code = krb5_c_block_size(context, key->enctype, &blocksize);
if (code)
return(code);
ivd.length = blocksize;
ivd.data = MALLOC(ivd.length);
if (ivd.data == NULL)
return ENOMEM;
(void) memcpy(ivd.data, iv, ivd.length);
pivd = &ivd;
} else {
pivd = NULL;
}
inputd.length = length;
inputd.data = (char *)in; /* Solaris Kerberos */
outputd.ciphertext.length = length;
outputd.ciphertext.data = out;
code = krb5_c_encrypt(context, key, usage, pivd, &inputd, &outputd);
if (pivd != NULL)
krb5_free_data_contents(context, pivd);
KRB5_LOG(KRB5_INFO, "kg_encrypt() end. code = %d", code);
return code;
}
/* length is the length of the cleartext. */
krb5_error_code
kg_decrypt(context, key, usage, iv, in, out, length)
krb5_context context;
krb5_keyblock *key;
int usage;
krb5_pointer iv;
krb5_const_pointer in;
krb5_pointer out;
unsigned int length;
{
krb5_error_code code;
size_t blocksize;
krb5_data ivd, *pivd, outputd;
krb5_enc_data inputd;
KRB5_LOG0(KRB5_INFO, "kg_decrypt() start.");
if (iv) {
code = krb5_c_block_size(context, key->enctype, &blocksize);
if (code)
return(code);
ivd.length = blocksize;
ivd.data = MALLOC(ivd.length);
if (ivd.data == NULL)
return ENOMEM;
(void) memcpy(ivd.data, iv, ivd.length);
pivd = &ivd;
} else {
pivd = NULL;
}
inputd.enctype = ENCTYPE_UNKNOWN;
inputd.ciphertext.length = length;
inputd.ciphertext.data = (char *)in; /* Solaris Kerberos */
outputd.length = length;
outputd.data = out;
code = krb5_c_decrypt(context, key, usage, pivd, &inputd, &outputd);
if (pivd != NULL)
krb5_free_data_contents(context, pivd);
KRB5_LOG(KRB5_INFO, "kg_decrypt() end. code = %d", code);
return code;
}
krb5_error_code
kg_arcfour_docrypt (krb5_context context,
const krb5_keyblock *longterm_key , int ms_usage,
const unsigned char *kd_data, size_t kd_data_len,
const unsigned char *input_buf, size_t input_len,
unsigned char *output_buf)
{
krb5_error_code code;
krb5_data input, output;
krb5_keyblock seq_enc_key, usage_key;
unsigned char t[4];
KRB5_LOG0(KRB5_INFO, "kg_arcfour_docrypt() start");
bzero(&usage_key, sizeof(krb5_keyblock));
bzero(&seq_enc_key, sizeof(krb5_keyblock));
usage_key.length = longterm_key->length;
usage_key.contents = MALLOC(usage_key.length);
usage_key.enctype = longterm_key->enctype;
usage_key.dk_list = NULL;
#ifdef _KERNEL
usage_key.kef_mt = longterm_key->kef_mt;
code = init_key_kef(longterm_key->kef_mt, &usage_key);
if (code)
return (code);
#endif /* _KERNEL */
if (usage_key.contents == NULL)
return (ENOMEM);
seq_enc_key.length = longterm_key->length;
seq_enc_key.contents = MALLOC(seq_enc_key.length);
seq_enc_key.enctype = longterm_key->enctype;
seq_enc_key.dk_list = NULL;
#ifdef _KERNEL
seq_enc_key.kef_mt = longterm_key->kef_mt;
code = init_key_kef(longterm_key->kef_mt, &seq_enc_key);
if (code)
return (code);
#endif /* _KERNEL */
if (seq_enc_key.contents == NULL) {
FREE ((void *) usage_key.contents, usage_key.length);
return (ENOMEM);
}
t[0] = ms_usage &0xff;
t[1] = (ms_usage>>8) & 0xff;
t[2] = (ms_usage>>16) & 0xff;
t[3] = (ms_usage>>24) & 0xff;
input.data = (void *) &t;
input.length = 4;
output.data = (void *) usage_key.contents;
output.length = usage_key.length;
#ifdef _KERNEL
code = krb5_hmac(context, longterm_key, &input, &output);
#else
code = krb5_hmac(context, &krb5int_hash_md5,
longterm_key, 1, &input, &output);
#endif /* _KERNEL */
if (code)
goto cleanup_arcfour;
input.data = ( void *) kd_data;
input.length = kd_data_len;
output.data = (void *) seq_enc_key.contents;
#ifdef _KERNEL
code = krb5_hmac(context, &usage_key, &input, &output);
#else
code = krb5_hmac(context, &krb5int_hash_md5,
&usage_key, 1, &input, &output);
#endif /* _KERNEL */
if (code)
goto cleanup_arcfour;
input.data = ( void * ) input_buf;
input.length = input_len;
output.data = (void * ) output_buf;
output.length = input_len;
/*
* Call the arcfour encryption method directly here, we cannot
* use the standard "krb5_c_encrypt" interface because we just
* want the arcfour algorithm applied and not the additional MD5-HMAC
* which are applied when using the standard interface.
*/
code = krb5int_enc_arcfour.encrypt(context, &seq_enc_key, 0, &input, &output);
cleanup_arcfour:
bzero ((void *) seq_enc_key.contents, seq_enc_key.length);
bzero ((void *) usage_key.contents, usage_key.length);
FREE ((void *) usage_key.contents, usage_key.length);
FREE ((void *) seq_enc_key.contents, seq_enc_key.length);
KRB5_LOG(KRB5_INFO, "kg_arcfour_docrypt() end code = %d", code);
return (code);
}
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright 1993 by OpenVision Technologies, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appears in all copies and
* that both that copyright notice and this permission notice appear in
* supporting documentation, and that the name of OpenVision not be used
* in advertising or publicity pertaining to distribution of the software
* without specific, written prior permission. OpenVision makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
* OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
/*
* $Id: util_ordering.c 19310 2007-03-29 21:36:38Z tlyu $
*/
/*
* SUNW15resync
* Left this alone (MIT version causes STC gss_verify_mic(6) test failure)
* as it has bug fixes that MIT does not yet.
*/
/*
* functions to check sequence numbers for replay and sequencing
*/
#include "mechglueP.h"
#include "gssapiP_generic.h"
#define QUEUE_LENGTH 20
typedef struct _queue {
int do_replay;
int do_sequence;
int start;
int length;
gssint_uint64 firstnum;
gssint_uint64 elem[QUEUE_LENGTH];
gssint_uint64 mask;
} queue;
/* rep invariant:
* - the queue is a circular queue. The first element (q->elem[q->start])
* is the oldest. The last element is the newest.
*/
#define QSIZE(q) (sizeof((q)->elem)/sizeof((q)->elem[0]))
#define QELEM(q,i) ((q)->elem[(i)%QSIZE(q)])
/*
* mask(max) is 2 ** 64 - 1, and half is 2 ** 63.
* |-------------------------------|-----------------------------|
* 0 half mask
* |-------------------------------|
* half range ( 2 ** 63 )
*
* Here, the distance between n1 and n2 is used, if it falls
* in the "half range", normal integer comparison is enough.
*
* If the distance is bigger than half of the range, one of them must
* have passed the 'mask' point while the other one didn't. In this
* case, the result should be the reverse of normal comparison, i.e.
* the smaller one is considered bigger.
*
* If we shift the smaller value by adding 'mask' to it,
* the distance will be in half range again.
*
* The assumption is that the out of order event will not
* happen too often. If the distance is really bigger than half range,
* (1 is expected, but half + 2 arrives) we really don't know if it's a
* GAP token or an OLD token that wrapped.
*/
static int
after(gssint_uint64 n1, gssint_uint64 n2, gssint_uint64 mask)
{
int bigger;
gssint_uint64 diff;
gssint_uint64 half;
/*
* rule 1: same number.
* This may be ambiguous, but the caller of this function,
* g_order_check already takes care of it.
*/
if (n1 == n2)
return (0);
half = 1 + (mask >> 1);
if (n1 > n2) {
diff = n1 - n2;
bigger = 1;
} else {
diff = n2 - n1;
bigger = 0;
}
/* rule 2: in the same half range, normal comparison is enough */
if (diff < half)
return bigger;
n1 &= half;
/* rule 3: different half, and n1 is on upper, n2 is bigger */
/* rule 4: different half, and n1 is on lower, n1 is bigger */
if (n1 != 0)
return (0);
return (1);
}
static void
queue_insert(queue *q, int after, gssint_uint64 seqnum)
{
/* insert. this is not the fastest way, but it's easy, and it's
optimized for insert at end, which is the common case */
int i;
/* common case: at end, after == q->start+q->length-1 */
/* move all the elements (after,last] up one slot */
for (i=q->start+q->length-1; i>after; i--)
QELEM(q,i+1) = QELEM(q,i);
/* fill in slot after+1 */
QELEM(q,after+1) = seqnum;
/* Either increase the length by one, or move the starting point up
one (deleting the first element, which got bashed above), as
appropriate. */
if (q->length == QSIZE(q)) {
q->start++;
if (q->start == QSIZE(q))
q->start = 0;
} else {
q->length++;
}
}
gss_int32
g_order_init(void **vqueue, gssint_uint64 seqnum,
int do_replay, int do_sequence, int wide_nums)
{
queue *q;
if ((q = (queue *) MALLOC(sizeof(queue))) == NULL)
return(ENOMEM);
q->do_replay = do_replay;
q->do_sequence = do_sequence;
q->mask = wide_nums ? ~(gssint_uint64)0 : 0xffffffffUL;
q->start = 0;
q->length = 1;
q->firstnum = seqnum;
q->elem[q->start] = ((gssint_uint64)0 - 1) & q->mask;
*vqueue = (void *) q;
return(0);
}
gss_int32
g_order_check(void **vqueue, gssint_uint64 seqnum)
{
queue *q;
int i;
gssint_uint64 expected;
q = (queue *) (*vqueue);
if (!q->do_replay && !q->do_sequence)
return(GSS_S_COMPLETE);
/* All checks are done relative to the initial sequence number, to
avoid (or at least put off) the pain of wrapping. */
seqnum -= q->firstnum;
/*
* If we're only doing 32-bit values, adjust for that again.
* Note that this will probably be the wrong thing to if we get
* 2**32 messages sent with 32-bit sequence numbers.
*/
seqnum &= q->mask;
/* rule 1: expected sequence number */
expected = (QELEM(q,q->start+q->length-1)+1) & q->mask;
if (seqnum == expected) {
queue_insert(q, q->start+q->length-1, seqnum);
return(GSS_S_COMPLETE);
}
/* rule 2: > expected sequence number */
if (after(seqnum, expected, q->mask)) {
queue_insert(q, q->start+q->length-1, seqnum);
if (q->do_replay && !q->do_sequence)
return(GSS_S_COMPLETE);
else
return(GSS_S_GAP_TOKEN);
}
/* rule 3: seqnum < seqnum(first) */
if (after(QELEM(q,q->start), seqnum, q->mask)) {
if (q->do_replay && !q->do_sequence)
return(GSS_S_OLD_TOKEN);
else
return(GSS_S_UNSEQ_TOKEN);
}
/* rule 4+5: seqnum in [seqnum(first),seqnum(last)] */
else {
if (seqnum == QELEM(q,q->start+q->length-1))
return(GSS_S_DUPLICATE_TOKEN);
for (i=q->start; i<q->start+q->length-1; i++) {
if (seqnum == QELEM(q,i))
return (GSS_S_DUPLICATE_TOKEN);
if (after(seqnum, QELEM(q,i), q->mask) &&
after(QELEM(q,i+1), seqnum, q->mask)) {
queue_insert(q, i, seqnum);
if (q->do_replay && !q->do_sequence)
return (GSS_S_COMPLETE);
else
return (GSS_S_UNSEQ_TOKEN);
}
}
}
/* this should never happen */
return(GSS_S_FAILURE);
}
void
g_order_free(void **vqueue)
{
queue *q;
q = (queue *) (*vqueue);
FREE (q, sizeof (queue));
*vqueue = NULL;
}
/*
* These support functions are for the serialization routines
*/
/*ARGSUSED*/
gss_uint32
g_queue_size(void *vqueue, size_t *sizep)
{
*sizep += sizeof(queue);
return 0;
}
gss_uint32
g_queue_externalize(void *vqueue, unsigned char **buf, size_t *lenremain)
{
(void) memcpy(*buf, vqueue, sizeof(queue));
*buf += sizeof(queue);
*lenremain -= sizeof(queue);
return 0;
}
gss_uint32
g_queue_internalize(void **vqueue, unsigned char **buf, size_t *lenremain)
{
void *q;
if ((q = (void *) MALLOC(sizeof(queue))) == 0)
return ENOMEM;
(void) memcpy(q, *buf, sizeof(queue));
*buf += sizeof(queue);
*lenremain -= sizeof(queue);
*vqueue = q;
return 0;
}
/*
* Copyright 1993 by OpenVision Technologies, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appears in all copies and
* that both that copyright notice and this permission notice appear in
* supporting documentation, and that the name of OpenVision not be used
* in advertising or publicity pertaining to distribution of the software
* without specific, written prior permission. OpenVision makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
* OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
#include "gssapiP_krb5.h"
#ifdef HAVE_MEMORY_H
#include <memory.h>
#endif
static const unsigned char zeros[16] = {0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0};
krb5_error_code
kg_make_seed(context, key, seed)
krb5_context context;
krb5_keyblock *key;
unsigned char *seed;
{
krb5_error_code code;
krb5_keyblock *tmpkey;
int i;
code = krb5_copy_keyblock(context, key, &tmpkey);
if (code)
return(code);
/* reverse the key bytes, as per spec */
for (i=0; i<tmpkey->length; i++)
tmpkey->contents[i] = key->contents[key->length - 1 - i];
code = kg_encrypt(context, tmpkey, KG_USAGE_SEAL, NULL, zeros, seed, 16);
krb5_free_keyblock(context, tmpkey);
return(code);
}
/*
* Copyright2001 by the Massachusetts Institute of Technology.
* Copyright 1993 by OpenVision Technologies, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appears in all copies and
* that both that copyright notice and this permission notice appear in
* supporting documentation, and that the name of OpenVision not be used
* in advertising or publicity pertaining to distribution of the software
* without specific, written prior permission. OpenVision makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
* OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
#include "gssapiP_krb5.h"
#include "k5-int.h"
/*
* $Id: util_seqnum.c 15007 2002-11-15 16:12:20Z epeisach $
*/
krb5_error_code
kg_make_seq_num(context, key, direction, seqnum, cksum, buf)
krb5_context context;
krb5_keyblock *key;
int direction;
krb5_ui_4 seqnum;
unsigned char *cksum;
unsigned char *buf;
{
unsigned char plain[8];
plain[4] = direction;
plain[5] = direction;
plain[6] = direction;
plain[7] = direction;
if (key->enctype == ENCTYPE_ARCFOUR_HMAC ) {
/* Yes, Microsoft used big-endian sequence number.*/
plain[0] = (seqnum>>24) & 0xff;
plain[1] = (seqnum>>16) & 0xff;
plain[2] = (seqnum>>8) & 0xff;
plain[3] = seqnum & 0xff;
return kg_arcfour_docrypt (context, key, 0,
cksum, 8,
&plain[0], 8,
buf);
}
plain[0] = (unsigned char) (seqnum&0xff);
plain[1] = (unsigned char) ((seqnum>>8)&0xff);
plain[2] = (unsigned char) ((seqnum>>16)&0xff);
plain[3] = (unsigned char) ((seqnum>>24)&0xff);
return(kg_encrypt(context, key, KG_USAGE_SEQ, cksum, plain, buf, 8));
}
krb5_error_code kg_get_seq_num(context, key, cksum, buf, direction, seqnum)
krb5_context context;
krb5_keyblock *key;
unsigned char *cksum;
unsigned char *buf;
int *direction;
krb5_ui_4 *seqnum;
{
krb5_error_code code;
unsigned char plain[8];
if (key->enctype == ENCTYPE_ARCFOUR_HMAC) {
code = kg_arcfour_docrypt (context, key, 0,
cksum, 8,
buf, 8,
plain);
} else {
code = kg_decrypt(context, key, KG_USAGE_SEQ, cksum, buf, plain, 8);
}
if (code)
return(code);
if ((plain[4] != plain[5]) ||
(plain[4] != plain[6]) ||
(plain[4] != plain[7]))
return((krb5_error_code) KG_BAD_SEQ);
*direction = plain[4];
if (key->enctype == ENCTYPE_ARCFOUR_HMAC) {
*seqnum = (plain[3]|(plain[2]<<8) | (plain[1]<<16)| (plain[0]<<24));
} else {
*seqnum = ((plain[0]) |
(plain[1]<<8) |
(plain[2]<<16) |
(plain[3]<<24));
}
return(0);
}
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright 1995 by OpenVision Technologies, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appears in all copies and
* that both that copyright notice and this permission notice appear in
* supporting documentation, and that the name of OpenVision not be used
* in advertising or publicity pertaining to distribution of the software
* without specific, written prior permission. OpenVision makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
* OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
/*
* $Id: util_set.c 16165 2004-03-14 05:31:43Z raeburn $
*/
#include <mechglueP.h> /* SUNW15resync - for MALLOC/FREE */
#include "gssapiP_generic.h"
struct _g_set_elt {
void *key;
void *value;
struct _g_set_elt *next;
};
int g_set_init(g_set_elt *s)
{
*s = NULL;
return(0);
}
#if 0
int g_set_destroy(g_set_elt *s)
{
g_set next;
while (*s) {
next = (*s)->next;
FREE(*s, sizeof(struct _g_set));
*s = next;
}
return(0);
}
#endif
int g_set_entry_add(g_set_elt *s, void *key, void *value)
{
g_set_elt first;
if ((first = (struct _g_set_elt *) MALLOC(sizeof(struct _g_set_elt))) == NULL)
return(ENOMEM);
first->key = key;
first->value = value;
first->next = *s;
*s = first;
return(0);
}
int g_set_entry_delete(g_set_elt *s, void *key)
{
g_set_elt *p;
for (p=s; *p; p = &((*p)->next)) {
if ((*p)->key == key) {
g_set_elt next = (*p)->next;
FREE(*p, sizeof(struct _g_set_elt));
*p = next;
return(0);
}
}
return(-1);
}
int g_set_entry_get(g_set_elt *s, void *key, void **value)
{
g_set_elt p;
for (p = *s; p; p = p->next) {
if (p->key == key) {
*value = p->value;
return(0);
}
}
*value = NULL;
return(-1);
}
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright 1993 by OpenVision Technologies, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appears in all copies and
* that both that copyright notice and this permission notice appear in
* supporting documentation, and that the name of OpenVision not be used
* in advertising or publicity pertaining to distribution of the software
* without specific, written prior permission. OpenVision makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
* OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
#include "gssapiP_generic.h"
#ifdef _KERNEL
#include <sys/systm.h>
#else
#ifdef HAVE_MEMORY_H
#include <memory.h>
#endif
#include <limits.h>
#include <string.h>
#endif /* _KERNEL */
/*
* $Id: util_token.c 17987 2006-05-09 11:31:02Z epeisach $
*/
/* XXXX this code currently makes the assumption that a mech oid will
never be longer than 127 bytes. This assumption is not inherent in
the interfaces, so the code can be fixed if the OSI namespace
balloons unexpectedly. */
/* Each token looks like this:
0x60 tag for APPLICATION 0, SEQUENCE
(constructed, definite-length)
<length> possible multiple bytes, need to parse/generate
0x06 tag for OBJECT IDENTIFIER
<moid_length> compile-time constant string (assume 1 byte)
<moid_bytes> compile-time constant string
<inner_bytes> the ANY containing the application token
bytes 0,1 are the token type
bytes 2,n are the token data
Note that the token type field is a feature of RFC 1964 mechanisms and
is not used by other GSSAPI mechanisms. As such, a token type of -1
is interpreted to mean that no token type should be expected or
generated.
For the purposes of this abstraction, the token "header" consists of
the sequence tag and length octets, the mech OID DER encoding, and the
first two inner bytes, which indicate the token type. The token
"body" consists of everything else.
*/
static unsigned int der_length_size(length)
int length;
{
if (length < (1<<7))
return(1);
else if (length < (1<<8))
return(2);
#if INT_MAX == 0x7fff
else
return(3);
#else
else if (length < (1<<16))
return(3);
else if (length < (1<<24))
return(4);
else
return(5);
#endif
}
static void der_write_length(buf, length)
unsigned char **buf;
int length;
{
if (length < (1<<7)) {
*(*buf)++ = (unsigned char) length;
} else {
*(*buf)++ = (unsigned char) (der_length_size(length)+127);
#if INT_MAX > 0x7fff
if (length >= (1<<24))
*(*buf)++ = (unsigned char) (length>>24);
if (length >= (1<<16))
*(*buf)++ = (unsigned char) ((length>>16)&0xff);
#endif
if (length >= (1<<8))
*(*buf)++ = (unsigned char) ((length>>8)&0xff);
*(*buf)++ = (unsigned char) (length&0xff);
}
}
/* returns decoded length, or < 0 on failure. Advances buf and
decrements bufsize */
static int der_read_length(buf, bufsize)
unsigned char **buf;
int *bufsize;
{
unsigned char sf;
int ret;
if (*bufsize < 1)
return(-1);
sf = *(*buf)++;
(*bufsize)--;
if (sf & 0x80) {
if ((sf &= 0x7f) > ((*bufsize)-1))
return(-1);
if (sf > sizeof(int))
return (-1);
ret = 0;
for (; sf; sf--) {
ret = (ret<<8) + (*(*buf)++);
(*bufsize)--;
}
} else {
ret = sf;
}
return(ret);
}
/* returns the length of a token, given the mech oid and the body size */
unsigned int g_token_size(mech, body_size)
const gss_OID_desc * mech;
unsigned int body_size;
{
/* set body_size to sequence contents size */
body_size += 4 + (int) mech->length; /* NEED overflow check */
return(1 + der_length_size((int) body_size) + body_size);
}
/* fills in a buffer with the token header. The buffer is assumed to
be the right size. buf is advanced past the token header */
void g_make_token_header(mech, body_size, buf, tok_type)
const gss_OID_desc * mech;
unsigned int body_size;
unsigned char **buf;
int tok_type;
{
*(*buf)++ = 0x60;
der_write_length(buf,
(tok_type == -1) ? 2 : (int) (4 + mech->length + body_size));
*(*buf)++ = 0x06;
*(*buf)++ = (unsigned char) mech->length;
TWRITE_STR(*buf, mech->elements, mech->length);
if (tok_type != -1) {
*(*buf)++ = (unsigned char) ((tok_type>>8)&0xff);
*(*buf)++ = (unsigned char) (tok_type&0xff);
}
}
/*
* Given a buffer containing a token, reads and verifies the token,
* leaving buf advanced past the token header, and setting body_size
* to the number of remaining bytes. Returns 0 on success,
* G_BAD_TOK_HEADER for a variety of errors, and G_WRONG_MECH if the
* mechanism in the token does not match the mech argument. buf and
* *body_size are left unmodified on error.
*/
gss_int32 g_verify_token_header(mech, body_size, buf_in, tok_type, toksize_in,
wrapper_required)
const gss_OID_desc * mech;
unsigned int *body_size;
unsigned char **buf_in;
int tok_type;
unsigned int toksize_in;
int wrapper_required;
{
unsigned char *buf = *buf_in;
int seqsize;
gss_OID_desc toid;
int toksize = toksize_in;
if ((toksize-=1) < 0)
return(G_BAD_TOK_HEADER);
if (*buf++ != 0x60) {
if (wrapper_required)
return(G_BAD_TOK_HEADER);
buf--;
toksize++;
goto skip_wrapper;
}
if ((seqsize = der_read_length(&buf, &toksize)) < 0)
return(G_BAD_TOK_HEADER);
if (seqsize != toksize)
return(G_BAD_TOK_HEADER);
if ((toksize-=1) < 0)
return(G_BAD_TOK_HEADER);
if (*buf++ != 0x06)
return(G_BAD_TOK_HEADER);
if ((toksize-=1) < 0)
return(G_BAD_TOK_HEADER);
toid.length = *buf++;
if ((toksize-=toid.length) < 0)
return(G_BAD_TOK_HEADER);
toid.elements = buf;
buf+=toid.length;
if (! g_OID_equal(&toid, mech))
return G_WRONG_MECH;
skip_wrapper:
if (tok_type != -1) {
if ((toksize-=2) < 0)
return(G_BAD_TOK_HEADER);
if ((*buf++ != ((tok_type>>8)&0xff)) ||
(*buf++ != (tok_type&0xff)))
return(G_WRONG_TOKID);
}
*buf_in = buf;
*body_size = toksize;
return 0;
}
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright 1993 by OpenVision Technologies, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appears in all copies and
* that both that copyright notice and this permission notice appear in
* supporting documentation, and that the name of OpenVision not be used
* in advertising or publicity pertaining to distribution of the software
* without specific, written prior permission. OpenVision makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
* OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
/*
* $Id: util_validate.c 18721 2006-10-16 16:18:29Z epeisach $
*/
/*
* functions to validate name, credential, and context handles
*/
#include "gssapiP_generic.h"
#ifndef _KERNEL
#include "gss_libinit.h"
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef _KERNEL
#include <sys/fcntl.h>
#else
#include <fcntl.h>
#include <limits.h>
#endif
#ifdef HAVE_BSD_DB
#include <sys/file.h>
#include <db.h>
static const int one = 1;
static const DBT dbtone = { (void *) &one, sizeof(one) };
typedef struct _vkey {
int type;
void *ptr;
} vkey;
#endif
#define V_NAME 1
#define V_CRED_ID 2
#define V_CTX_ID 3
#define V_LCTX_ID 4
/* SUNW15resync
beware some of the uses below of type look dubious but seem
to have been working in Solaris for a long time */
/* All these functions return 0 on failure, and non-zero on success */
static int g_save(db, type, ptr)
g_set *db;
int type;
void *ptr;
{
int ret;
#ifdef HAVE_BSD_DB
DB **vdb;
vkey vk;
DBT key;
#ifndef _KERNEL
ret = gssint_initialize_library();
if (ret)
return 0;
#endif
ret = k5_mutex_lock(&db->mutex);
if (ret)
return 0;
vdb = (DB **) &db->data;
if (!*vdb)
*vdb = dbopen(NULL, O_CREAT|O_RDWR, O_CREAT|O_RDWR, DB_HASH, NULL);
vk.type = type;
vk.ptr = ptr;
key.data = &vk;
key.size = sizeof(vk);
ret = ((*((*vdb)->put))(*vdb, &key, &dbtone, 0) == 0);
(void) k5_mutex_unlock(&db->mutex);
return ret;
#else
g_set_elt *gs;
#ifndef _KERNEL
ret = gssint_initialize_library();
if (ret)
return 0;
#endif
ret = k5_mutex_lock(&db->mutex);
if (ret)
return 0;
gs = (g_set_elt *) &db->data;
if (!*gs)
if (g_set_init(gs)) {
(void) k5_mutex_unlock(&db->mutex);
return(0);
}
/* SUNW15resync */
ret = (g_set_entry_add(gs, ptr, (void *)(intptr_t)type) == 0);
(void) k5_mutex_unlock(&db->mutex);
return ret;
#endif
}
static int g_validate(db, type, ptr)
g_set *db;
int type;
void *ptr;
{
int ret;
#ifdef HAVE_BSD_DB
DB **vdb;
vkey vk;
DBT key, value;
ret = k5_mutex_lock(&db->mutex);
if (ret)
return 0;
vdb = (DB **) &db->data;
if (!*vdb) {
(void) k5_mutex_unlock(&db->mutex);
return(0);
}
vk.type = type;
vk.ptr = ptr;
key.data = &vk;
key.size = sizeof(vk);
if ((*((*vdb)->get))(*vdb, &key, &value, 0)) {
(void) k5_mutex_unlock(&db->mutex);
return(0);
}
(void) k5_mutex_unlock(&db->mutex);
return((value.size == sizeof(one)) &&
(*((int *) value.data) == one));
#else
g_set_elt *gs;
void *value;
ret = k5_mutex_lock(&db->mutex);
if (ret)
return 0;
gs = (g_set_elt *) &db->data;
if (!*gs) {
(void) k5_mutex_unlock(&db->mutex);
return(0);
}
if (g_set_entry_get(gs, ptr, (void **) &value)) {
(void) k5_mutex_unlock(&db->mutex);
return(0);
}
(void) k5_mutex_unlock(&db->mutex);
return((intptr_t)value == (intptr_t)type); /* SUNW15resync */
#endif
}
/*ARGSUSED*/
static int g_delete(db, type, ptr)
g_set *db;
int type;
void *ptr;
{
int ret;
#ifdef HAVE_BSD_DB
DB **vdb;
vkey vk;
DBT key;
ret = k5_mutex_lock(&db->mutex);
if (ret)
return 0;
vdb = (DB **) &db->data;
if (!*vdb) {
(void) k5_mutex_unlock(&db->mutex);
return(0);
}
vk.type = type;
vk.ptr = ptr;
key.data = &vk;
key.size = sizeof(vk);
ret = ((*((*vdb)->del))(*vdb, &key, 0) == 0);
(void) k5_mutex_unlock(&db->mutex);
return ret;
#else
g_set_elt *gs;
ret = k5_mutex_lock(&db->mutex);
if (ret)
return 0;
gs = (g_set_elt *) &db->data;
if (!*gs) {
(void) k5_mutex_unlock(&db->mutex);
return(0);
}
if (g_set_entry_delete(gs, ptr)) {
(void) k5_mutex_unlock(&db->mutex);
return(0);
}
(void) k5_mutex_unlock(&db->mutex);
return(1);
#endif
}
/* functions for each type */
/* save */
int g_save_name(vdb, name)
g_set *vdb;
gss_name_t name;
{
return(g_save(vdb, V_NAME, (void *) name));
}
int g_save_cred_id(vdb, cred)
g_set *vdb;
gss_cred_id_t cred;
{
return(g_save(vdb, V_CRED_ID, (void *) cred));
}
int g_save_ctx_id(vdb, ctx)
g_set *vdb;
gss_ctx_id_t ctx;
{
return(g_save(vdb, V_CTX_ID, (void *) ctx));
}
int g_save_lucidctx_id(vdb, lctx)
g_set *vdb;
void *lctx;
{
return(g_save(vdb, V_LCTX_ID, (void *) lctx));
}
/* validate */
int g_validate_name(vdb, name)
g_set *vdb;
gss_name_t name;
{
return(g_validate(vdb, V_NAME, (void *) name));
}
int g_validate_cred_id(vdb, cred)
g_set *vdb;
gss_cred_id_t cred;
{
return(g_validate(vdb, V_CRED_ID, (void *) cred));
}
int g_validate_ctx_id(vdb, ctx)
g_set *vdb;
gss_ctx_id_t ctx;
{
return(g_validate(vdb, V_CTX_ID, (void *) ctx));
}
int g_validate_lucidctx_id(vdb, lctx)
g_set *vdb;
void *lctx;
{
return(g_validate(vdb, V_LCTX_ID, (void *) lctx));
}
/* delete */
int g_delete_name(vdb, name)
g_set *vdb;
gss_name_t name;
{
return(g_delete(vdb, V_NAME, (void *) name));
}
int g_delete_cred_id(vdb, cred)
g_set *vdb;
gss_cred_id_t cred;
{
return(g_delete(vdb, V_CRED_ID, (void *) cred));
}
int g_delete_ctx_id(vdb, ctx)
g_set *vdb;
gss_ctx_id_t ctx;
{
return(g_delete(vdb, V_CTX_ID, (void *) ctx));
}
int g_delete_lucidctx_id(vdb, lctx)
g_set *vdb;
void *lctx;
{
return(g_delete(vdb, V_LCTX_ID, (void *) lctx));
}
/*
* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Copyright 1997 by 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.
*
*/
#include "gssapiP_krb5.h"
/*
* Check to see whether or not a GSSAPI krb5 credential is valid. If
* it is not, return an error.
*/
OM_uint32
krb5_gss_validate_cred_1(OM_uint32 *minor_status, gss_cred_id_t cred_handle,
krb5_context context)
{
krb5_gss_cred_id_t cred;
krb5_error_code code;
krb5_principal princ;
if (!kg_validate_cred_id(cred_handle)) {
*minor_status = (OM_uint32) G_VALIDATE_FAILED;
return(GSS_S_CALL_BAD_STRUCTURE|GSS_S_DEFECTIVE_CREDENTIAL);
}
cred = (krb5_gss_cred_id_t) cred_handle;
code = k5_mutex_lock(&cred->lock);
if (code) {
*minor_status = code;
return GSS_S_FAILURE;
}
if (cred->ccache) {
if ((code = krb5_cc_get_principal(context, cred->ccache, &princ))) {
k5_mutex_unlock(&cred->lock);
*minor_status = code;
return(GSS_S_DEFECTIVE_CREDENTIAL);
}
if (!krb5_principal_compare(context, princ, cred->princ)) {
k5_mutex_unlock(&cred->lock);
*minor_status = KG_CCACHE_NOMATCH;
return(GSS_S_DEFECTIVE_CREDENTIAL);
}
(void)krb5_free_principal(context, princ);
}
*minor_status = 0;
return GSS_S_COMPLETE;
}
OM_uint32
krb5_gss_validate_cred(minor_status, cred_handle)
OM_uint32 *minor_status;
gss_cred_id_t cred_handle;
{
krb5_context context;
krb5_error_code code;
OM_uint32 maj;
code = krb5_gss_init_context(&context);
if (code) {
*minor_status = code;
return GSS_S_FAILURE;
}
maj = krb5_gss_validate_cred_1(minor_status, cred_handle, context);
if (maj == 0) {
krb5_gss_cred_id_t cred = (krb5_gss_cred_id_t) cred_handle;
k5_mutex_assert_locked(&cred->lock);
k5_mutex_unlock(&cred->lock);
} else /* Solaris Kerberos - added this else */
save_error_info(*minor_status, context);
krb5_free_context(context);
return maj;
}
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright 1993 by OpenVision Technologies, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appears in all copies and
* that both that copyright notice and this permission notice appear in
* supporting documentation, and that the name of OpenVision not be used
* in advertising or publicity pertaining to distribution of the software
* without specific, written prior permission. OpenVision makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
* OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
#include "gssapiP_krb5.h"
/*
* $Id: verify.c 16171 2004-03-15 17:45:01Z raeburn $
*/
/*ARGSUSED*/
OM_uint32
krb5_gss_verify(minor_status, context_handle,
message_buffer, token_buffer,
qop_state
#ifdef _KERNEL
, gssd_ctx_verifier
#endif
)
OM_uint32 *minor_status;
gss_ctx_id_t context_handle;
gss_buffer_t message_buffer;
gss_buffer_t token_buffer;
int *qop_state;
#ifdef _KERNEL
OM_uint32 gssd_ctx_verifier;
#endif
{
return(kg_unseal(minor_status, context_handle,
token_buffer, message_buffer,
NULL, qop_state, KG_TOK_SIGN_MSG));
}
/* V2 interface */
OM_uint32
krb5_gss_verify_mic(minor_status, context_handle,
message_buffer, token_buffer,
qop_state)
OM_uint32 *minor_status;
gss_ctx_id_t context_handle;
gss_buffer_t message_buffer;
gss_buffer_t token_buffer;
gss_qop_t *qop_state;
{
OM_uint32 rstat;
int qstate;
rstat = kg_unseal(minor_status, context_handle,
token_buffer, message_buffer,
NULL, &qstate, KG_TOK_MIC_MSG);
if (!rstat && qop_state)
*qop_state = (gss_qop_t) qstate;
return(rstat);
}
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright 2000 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.
*
*/
/*
* Copyright 1993 by OpenVision Technologies, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appears in all copies and
* that both that copyright notice and this permission notice appear in
* supporting documentation, and that the name of OpenVision not be used
* in advertising or publicity pertaining to distribution of the software
* without specific, written prior permission. OpenVision makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
* OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
/*
* 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 "gssapiP_krb5.h"
size_t KRB5_CALLCONV krb5_encrypt_size(size_t, krb5_enctype);
/* SUNW15resync - XXX find new home for this func */
#ifdef _KERNEL
size_t KRB5_CALLCONV
krb5_encrypt_size(size_t length, krb5_enctype crypto)
{
size_t ret;
if (krb5_c_encrypt_length(/* XXX */ 0, crypto, length, &ret))
/*LINTED*/
return(-1); /* XXX */
return(ret);
}
#endif
/* V2 interface */
OM_uint32
krb5_gss_wrap_size_limit(minor_status, context_handle, conf_req_flag,
qop_req, req_output_size, max_input_size)
OM_uint32 *minor_status;
gss_ctx_id_t context_handle;
int conf_req_flag;
gss_qop_t qop_req;
OM_uint32 req_output_size;
OM_uint32 *max_input_size;
{
krb5_gss_ctx_id_rec *ctx;
OM_uint32 data_size, conflen;
OM_uint32 ohlen;
int overhead;
/* Solaris Kerb - check to make sure we aren't writing to a NULL pointer */
if (!max_input_size)
return(GSS_S_CALL_INACCESSIBLE_WRITE);
/* only default qop is allowed */
/*
* SUNW15resync
* mit 1.2-6: if (qop_req != GSS_C_QOP_DEFAULT) {
* Go with Solaris version here, though not sure which is
* correct and RFC 2743 does not make it clear.
*/
if ((qop_req & GSS_KRB5_CONF_C_QOP_MASK) != GSS_C_QOP_DEFAULT) {
*minor_status = (OM_uint32) G_UNKNOWN_QOP;
/* SUNW15resync - RFC 2743 is clear here but
this is still GSS_S_FAILURE in MIT */
return(GSS_S_BAD_QOP);
}
/* validate the context handle */
if (! kg_validate_ctx_id(context_handle)) {
*minor_status = (OM_uint32) G_VALIDATE_FAILED;
return(GSS_S_NO_CONTEXT);
}
ctx = (krb5_gss_ctx_id_rec *) context_handle;
if (! ctx->established) {
*minor_status = KG_CTX_INCOMPLETE;
return(GSS_S_NO_CONTEXT);
}
if (ctx->proto == 1) {
/* No pseudo-ASN.1 wrapper overhead, so no sequence length and
OID. */
OM_uint32 sz = req_output_size;
/* Token header: 16 octets. */
if (conf_req_flag) {
while (sz > 0 && krb5_encrypt_size(sz, ctx->enc->enctype) + 16 > req_output_size)
sz--;
/* Allow for encrypted copy of header. */
if (sz > 16)
sz -= 16;
else
sz = 0;
#ifdef CFX_EXERCISE
/* Allow for EC padding. In the MIT implementation, only
added while testing. */
if (sz > 65535)
sz -= 65535;
else
sz = 0;
#endif
} else {
/* Allow for token header and checksum. */
if (sz < 16 + ctx->cksum_size)
sz = 0;
else
sz -= (16 + ctx->cksum_size);
}
*max_input_size = sz;
*minor_status = 0;
return GSS_S_COMPLETE;
}
/* Calculate the token size and subtract that from the output size */
overhead = 7 + ctx->mech_used->length;
data_size = req_output_size;
conflen = kg_confounder_size(ctx->k5_context, ctx->enc);
data_size = (conflen + data_size + 8) & (~(OM_uint32)7);
ohlen = g_token_size(ctx->mech_used,
(unsigned int) (data_size + ctx->cksum_size + 14))
- req_output_size;
if (ohlen+overhead < req_output_size)
/*
* Cannot have trailer length that will cause us to pad over our
* length.
*/
*max_input_size = (req_output_size - ohlen - overhead) & (~(OM_uint32)7);
else
*max_input_size = 0;
*minor_status = 0;
return(GSS_S_COMPLETE);
}
|