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
|
# Basic expect script for Kerberos tests.
# This is a DejaGnu test script.
# Written by Ian Lance Taylor, Cygnus Support, <ian@cygnus.com>.
# This script is automatically run by DejaGnu before running any of
# the Kerberos test scripts.
# This file provides several functions which deal with a local
# Kerberos database. We have to do this such that we don't interfere
# with any existing Kerberos database. We will create all the files
# in the directory $tmppwd, which will have been created by the
# testsuite default script. We will use $REALMNAME as our Kerberos
# realm name, defaulting to KRBTEST.COM.
set timeout 100
set stty_init {erase \^h kill \^u}
set env(TERM) dumb
set des3_krbtgt 0
set tgt_support_desmd5 0
set supported_enctypes "des-cbc-crc:normal"
set kdc_supported_enctypes "des-cbc-crc:normal"
# The names of the individual passes must be unique; lots of things
# depend on it. The PASSES variable may not contain comments; only
# small pieces get evaluated, so comments will do strange things.
# Most of the purpose of using multiple passes is to exercise the
# dependency of various bugs on configuration file settings,
# particularly with regards to encryption types.
# The des.no-kdc-md5 pass will fail if the KDC does not constrain
# session key enctypes to those in its permitted_enctypes list. It
# works by assuming enctype similarity, thus allowing the client to
# request a des-cbc-md4 session key. Since only des-cbc-crc is in the
# KDC's permitted_enctypes list, the TGT will be unusable.
# The des.des3-tgt.no-kdc-des3 pass will fail if the KDC doesn't
# constrain ticket key enctypes to those in permitted_enctypes. It
# does this by not putting des3 in the permitted_enctypes, while
# creating a TGT princpal that has a des3 key as well as a des key.
# XXX -- master_key_type is fragile w.r.t. permitted_enctypes; it is
# possible to configure things such that you have a master_key_type
# that is not permitted, and the error message used to be cryptic.
set passes {
{
des
des3_krbtgt=0
{supported_enctypes=des-cbc-crc:normal}
{kdc_supported_enctypes=des-cbc-crc:normal}
{dummy=[verbose -log "DES TGT, DES enctype"]}
}
{
des.des3tgt
des3_krbtgt=1
{supported_enctypes=des-cbc-crc:normal}
{kdc_supported_enctypes=des3-cbc-sha1:normal des-cbc-crc:normal}
{dummy=[verbose -log "DES3 TGT, DES enctype"]}
}
{
des3
des3_krbtgt=1
{supported_enctypes=des3-cbc-sha1:normal des-cbc-crc:normal}
{kdc_supported_enctypes=des3-cbc-sha1:normal des-cbc-crc:normal}
{dummy=[verbose -log "DES3 TGT, DES3 + DES enctypes"]}
}
{
des-v4
des3_krbtgt=0
{supported_enctypes=des-cbc-crc:v4}
{kdc_supported_enctypes=des-cbc-crc:v4}
{default_tkt_enctypes(client)=des-cbc-crc}
{dummy=[verbose -log "DES TGT, DES-CRC enctype, V4 salt"]}
}
{
des-md5-v4
des3_krbtgt=0
{supported_enctypes=des-cbc-md5:v4 des-cbc-crc:v4}
{kdc_supported_enctypes=des-cbc-md5:v4 des-cbc-crc:v4}
{default_tkt_enctypes(client)=des-cbc-md5 des-cbc-crc}
{dummy=[verbose -log "DES TGT, DES-MD5 and -CRC enctypes, V4 salt"]}
}
{
all-des-des3-enctypes
des3_krbtgt=1
{supported_enctypes=des3-cbc-sha1:normal des-cbc-crc:normal \
des-cbc-md5:normal des-cbc-crc:v4 des-cbc-md5:norealm \
des-cbc-md4:normal}
{kdc_supported_enctypes=des3-cbc-sha1:normal des-cbc-crc:normal \
des-cbc-md5:normal des-cbc-crc:v4 des-cbc-md5:norealm \
des-cbc-md4:normal}
{dummy=[verbose -log "DES3 TGT, many DES3 + DES enctypes"]}
}
{
des.no-kdc-md5
des3_krbtgt=0
tgt_support_desmd5=0
{permitted_enctypes(kdc)=des-cbc-crc}
{default_tgs_enctypes(client)=des-cbc-md5 des-cbc-md4 des-cbc-crc}
{default_tkt_enctypes(client)=des-cbc-md5 des-cbc-md4 des-cbc-crc}
{supported_enctypes=des-cbc-crc:normal}
{kdc_supported_enctypes=des-cbc-crc:normal}
{master_key_type=des-cbc-crc}
{dummy=[verbose -log \
"DES TGT, KDC permitting only des-cbc-crc"]}
}
{
des.des3-tgt.no-kdc-des3
tgt_support_desmd5=0
{permitted_enctypes(kdc)=des-cbc-crc}
{default_tgs_enctypes(client)=des-cbc-crc}
{default_tkt_enctypes(client)=des-cbc-crc}
{supported_enctypes=des3-cbc-sha1:normal des-cbc-crc:normal}
{kdc_supported_enctypes=des3-cbc-sha1:normal des-cbc-crc:normal}
{master_key_type=des-cbc-crc}
{dummy=[verbose -log \
"DES3 TGT, KDC permitting only des-cbc-crc"]}
}
}
# des.md5-tgt is set as unused, since it won't trigger the error case
# if SUPPORT_DESMD5 isn't honored.
# The des.md5-tgt pass will fail if enctype similarity is inconsisent;
# between 1.0.x and 1.1, the decrypt functions became more strict
# about matching enctypes, while the KDB retrieval functions didn't
# coerce the enctype to match what was requested. It works by setting
# SUPPORT_DESMD5 on the TGT principal, forcing an enctype of
# des-cbc-md5 on the TGT key. Since the database only contains a
# des-cbc-crc key, the decrypt will fail if enctypes are not coerced.
# des.no-kdc-md5.client-md4-skey is retained in unsed_passes, even
# though des.no-kdc-md5 is roughly equivalent, since the associated
# comment needs additional investigation at some point re the kadmin
# client.
# The des.no-kdc-md5.client-md4-skey will fail on TGS requests due to
# the KDC issuing session keys that it won't accept. It will also
# fail for a kadmin client, but for different reasons, since the kadm5
# library does some curious filtering of enctypes, and also uses
# get_in_tkt() rather than get_init_creds(); the former does an
# intersection of the enctypes provided by the caller and those listed
# in the config file!
set unused_passes {
{
des.md5-tgt
des3_krbtgt=0
tgt_support_desmd5=1
supported_enctypes=des-cbc-crc:normal
kdc_supported_enctypes=des-cbc-crc:normal
{permitted_enctypes(kdc)=des-cbc-md5 des-cbc-md4 des-cbc-crc}
{permitted_enctypes(client)=des-cbc-md5 des-cbc-md4 des-cbc-crc}
{dummy=[verbose -log "DES TGT, SUPPORTS_DESMD5"]}
}
{
des.md5-tgt.no-kdc-md5
des3_krbtgt=0
tgt_support_desmd5=1
{permitted_enctypes(kdc)=des-cbc-crc}
{default_tgs_enctypes(client)=des-cbc-crc}
{default_tkt_enctypes(client)=des-cbc-crc}
{supported_enctypes=des-cbc-crc:normal}
{kdc_supported_enctypes=des-cbc-crc:normal}
{master_key_type=des-cbc-crc}
{dummy=[verbose -log \
"DES TGT, SUPPORTS_DESMD5, KDC permitting only des-cbc-crc"]}
}
{
des.no-kdc-md5.client-md4-skey
des3_krbtgt=0
{permitted_enctypes(kdc)=des-cbc-crc}
{permitted_enctypes(client)=des-cbc-crc des-cbc-md4}
{default_tgs_enctypes(client)=des-cbc-crc des-cbc-md4}
{default_tkt_enctypes(client)=des-cbc-md4}
{supported_enctypes=des-cbc-crc:normal}
{kdc_supported_enctypes=des-cbc-crc:normal}
{dummy=[verbose -log \
"DES TGT, DES enctype, KDC permitting only des-cbc-crc, client requests des-cbc-md4 session key"]}
}
{
all-enctypes
des3_krbtgt=1
{supported_enctypes=\
rijndael256-hmac-sha1:normal rijndael192-hmac-sha1:normal rijndael128-hmac-sha1:normal \
serpent256-hmac-sha1:normal serpent192-hmac-sha1:norealm serpent128-hmac-sha1:normal \
twofish256-hmac-sha1:normal twofish192-hmac-sha1:norealm twofish128-hmac-sha1:normal \
des3-cbc-sha1:normal des3-cbc-sha1:none \
des-cbc-md5:normal des-cbc-md4:normal des-cbc-crc:normal \
des-cbc-md5:v4 des-cbc-md4:v4 des-cbc-crc:v4 \
}
{kdc_supported_enctypes=\
rijndael256-hmac-sha1:normal rijndael192-hmac-sha1:normal rijndael128-hmac-sha1:normal \
serpent256-hmac-sha1:normal serpent192-hmac-sha1:norealm serpent128-hmac-sha1:normal \
twofish256-hmac-sha1:normal twofish192-hmac-sha1:norealm twofish128-hmac-sha1:normal \
des3-cbc-sha1:normal des3-cbc-sha1:none \
des-cbc-md5:normal des-cbc-md4:normal des-cbc-crc:normal \
des-cbc-md5:v4 des-cbc-md4:v4 des-cbc-crc:v4 \
}
{dummy=[verbose -log "DES3 TGT, default enctypes"]}
}
{
aes
des3_krbtgt=0
{supported_enctypes=des-cbc-md5:normal des-cbc-crc:normal twofish256-hmac-sha1:normal}
{kdc_supported_enctypes=des-cbc-md5:normal des-cbc-crc:normal twofish256-hmac-sha1:normal}
{default_tgs_enctypes=rijndael256-hmac-sha1 des-cbc-crc}
{default_tkt_enctypes=rijndael256-hmac-sha1 des-cbc-crc}
{dummy=[verbose -log "DES3 TGT, default enctypes"]}
}
}
# {supported_enctypes=des-cbc-md5:normal des-cbc-crc:normal twofish256-hmac-sha1:normal }
# {kdc_supported_enctypes= des-cbc-md5:normal des-cbc-crc:normal twofish256-hmac-sha1:normal}
# This shouldn't be necessary on dejagnu-1.4 and later, but 1.3 seems
# to need it because its runtest.exp doesn't deal with PASS at all.
if [info exists PASS] {
foreach pass $passes {
if { [lsearch -exact $PASS [lindex $pass 0]] >= 0 } {
lappend MULTIPASS $pass
}
}
} else {
set MULTIPASS $passes
}
set last_passname_conf ""
set last_passname_db ""
# We do everything in a temporary directory.
if ![info exists TMPDIR] {
set tmppwd "[pwd]/tmpdir"
if ![file isdirectory $tmppwd] {
catch "exec mkdir $tmppwd" status
}
} else {
set tmppwd $TMPDIR
}
verbose "tmppwd=$tmppwd"
# On Ultrix, use /bin/sh5 in preference to /bin/sh.
if ![info exists BINSH] {
if [file exists /bin/sh5] {
set BINSH /bin/sh5
} else {
set BINSH /bin/sh
}
}
# For security, we must not use generally known passwords. This is
# because some of the tests may be run as root. If the passwords were
# generally know, then somebody could work out the appropriate
# Kerberos ticket to use, and come in when, say, the telnetd daemon
# was being tested by root. The window for doing this is very very
# small, so the password does not have to be perfect, it just can't be
# constant.
if ![info exists KEY] {
catch {exec $BINSH -c "echo $$"} KEY
verbose "KEY is $KEY"
set keyfile [open $tmppwd/KEY w]
puts $keyfile "$KEY"
close $keyfile
}
# Clear away any files left over from a previous run.
# We can't use them now because we don't know the right KEY.
# krb5.conf might change if running tests on another host
catch "exec rm -f $tmppwd/db.ok $tmppwd/srvtab $tmppwd/krb5.conf $tmppwd/kdc.conf $tmppwd/cpw_srvtab $tmppwd/krb.realms $tmppwd/krb.conf"
# Put the installed kerberos directories on PATH.
# This needs to be fixed for V5.
# set env(PATH) $env(PATH):/usr/kerberos/bin:/usr/kerberos/etc
# verbose "PATH=$env(PATH)"
# Some of the tests expect $env(USER) to be set.
if ![info exists env(USER)] {
if [info exists env(LOGNAME)] {
set env(USER) $env(LOGNAME)
} else {
if [info exists logname] {
set env(USER) $logname
} else {
catch "exec whoami" env(USER)
}
}
}
# set the realm. The user can override this on the runtest line.
if ![info exists REALMNAME] {
set REALMNAME "KRBTEST.COM"
}
verbose "Test realm is $REALMNAME"
# Find some programs we need. We use the binaries from the build tree
# if they exist. If they do not, then they must be in PATH. We
# expect $objdir to be ...tests/dejagnu.
foreach i {
{KDB5_UTIL $objdir/../../kadmin/dbutil/kdb5_util}
{KRB5KDC $objdir/../../kdc/krb5kdc}
{KADMIND $objdir/../../kadmin/server/kadmind}
{KADMIN $objdir/../../kadmin/cli/kadmin}
{KADMIN_LOCAL $objdir/../../kadmin/cli/kadmin.local}
{KINIT $objdir/../../clients/kinit/kinit}
{KTUTIL $objdir/../../kadmin/ktutil/ktutil}
{KLIST $objdir/../../clients/klist/klist}
{KDESTROY $objdir/../../clients/kdestroy/kdestroy}
{RESOLVE $objdir/../resolve/resolve}
{T_INETD $objdir/t_inetd}
} {
set varname [lindex $i 0]
if ![info exists $varname] {
eval set varval [lindex $i 1]
set varval [findfile $varval]
set $varname $varval
verbose "$varname=$varval"
} {
eval set varval \$$varname
verbose "$varname already set to $varval"
}
}
if ![info exists RLOGIN] {
set RLOGIN rlogin
}
if ![info exists RLOGIN_FLAGS] {
set RLOGIN_FLAGS ""
}
# We use a couple of variables to hold shell prompts which may be
# overridden by the user.
if ![info exists ROOT_PROMPT] {
set ROOT_PROMPT "(%|#|>|\\$) $"
}
if ![info exists SHELL_PROMPT] {
set SHELL_PROMPT "(%|#|>|\\$) $"
}
verbose "setting up onexit handler (old handler=[exit -onexit])"
exit -onexit [concat {
verbose "calling stop_kerberos_daemons (onexit handler)"
stop_kerberos_daemons;
} [exit -onexit]]
# check_k5login
# Most of the tests won't work if the user has a .k5login file, unless
# the user's name appears with $REALMNAME in .k5login
# This procedure returns 1 if the .k5login file appears to be OK, 0
# otherwise. This check is not foolproof.
# Note that this previously checked for a username with no realm; this
# works for krb4's kuserok() but not for krb5_kuserok(), due to some
# implementation details. *sigh*
proc check_k5login { testname } {
global env
global REALMNAME
if {![file exists ~/.k5login]} {
if {$env(USER) == "root"} {
return 0
} else {
return 1
}
}
verbose "looking for $env(USER)@$REALMNAME in ~/.k5login" 2
set file [open ~/.k5login r]
while { [gets $file principal] != -1 } {
verbose " found $principal" 2
if { $principal == "$env(USER)@$REALMNAME" } {
close $file
return 1
}
}
close $file
note "$testname test requires that your name appear in your ~/.k5login"
note "file in the form $env(USER)@$REALMNAME"
unsupported "$testname"
return 0
}
proc check_klogin { testname } {
global env
global REALMNAME
if {![file exists ~/.klogin]} {
if {$env(USER) == "root"} {
return 0
} else {
return 1
}
}
verbose "looking for $env(USER) in ~/.klogin" 2
set file [open ~/.klogin r]
while { [gets $file principal] != -1 } {
verbose " found $principal" 2
if { $principal == "$env(USER)" \
|| $principal == "$env(USER)@$REALMNAME" } {
close $file
return 1
}
}
close $file
note "$testname test requires that your name appear in your ~/.klogin"
note "file without a realm."
unsupported "$testname"
return 0
}
# check_exit_status
# Check the exit status of a spawned program. Returns 1 if the
# program succeeded, 0 if it failed.
proc check_exit_status { testname } {
global spawn_id
verbose "about to wait ($testname)"
set status_list [wait -i $spawn_id]
verbose "wait -i $spawn_id returned $status_list ($testname)"
catch "close -i $spawn_id"
if { [lindex $status_list 2] != 0 || [lindex $status_list 3] != 0 } {
verbose -log "exit status: $status_list"
fail "$testname"
return 0
} else {
return 1
}
}
#
# ENVSTACK
#
# These procedures implement an environment variable stack. They use
# the global variable $envvars_tosave for the purpose of identifying
# which environment variables to save. They also track which ones are
# unset at any particular point. The stack pointer is $envstackp,
# which is an integer. The arrays $envstack$envstackp and
# $unenvstack$envstackp store respectively the set of old environment
# variables/values pushed onto the stack and the set of old unset
# environment variables for a given value of $envstackp.
# Changing the value of $envvars_tosave after performing the first
# push operation may result in strangeness.
#
# envstack_push
#
# Push set of current environment variables.
#
proc envstack_push { } {
global env
global envvars_tosave
global envstackp
global envstack$envstackp
global unenvstack$envstackp
verbose "envstack_push: starting, sp=$envstackp"
foreach i $envvars_tosave {
if [info exists env($i)] {
verbose "envstack_push: saving $i=$env($i)"
set envstack${envstackp}($i) $env($i)
} {
verbose "envstack_push: marking $i as unset"
set unenvstack${envstackp}($i) unset
}
}
incr envstackp
verbose "envstack_push: exiting, sp=$envstackp"
}
#
# envstack_pop
#
# Pop set of current environment variables.
#
proc envstack_pop { } {
global env
global envstackp
verbose "envstack_pop: starting, sp=$envstackp"
incr envstackp -1
global envstack$envstackp # YUCK!!! no obvious better way though...
global unenvstack$envstackp
if {$envstackp < 0} {
perror "envstack_pop: stack underflow!"
return
}
if [info exists envstack$envstackp] {
foreach i [array names envstack$envstackp] {
if [info exists env($i)] {
verbose "envstack_pop: $i was $env($i)"
}
eval set env($i) \$envstack${envstackp}($i)
verbose "envstack_pop: restored $i to $env($i)"
}
unset envstack$envstackp
}
if [info exists unenvstack$envstackp] {
foreach i [array names unenvstack$envstackp] {
if [info exists env($i)] {
verbose "envstack_pop: $i was $env($i)"
unset env($i)
verbose "envstack_pop: $i unset"
} {
verbose "envstack_pop: ignoring already unset $i"
}
}
unset unenvstack$envstackp
}
verbose "envstack_pop: exiting, sp=$envstackp"
}
#
# Initialize the envstack
#
set envvars_tosave {
KRB5_CONFIG KRB5CCNAME KRBTKFILE KRB5RCACHEDIR
KERBEROS_SERVER KRB5_KDC_PROFILE
}
set krb5_init_vars [list ]
# XXX -- fix me later!
foreach i $runvarlist {
verbose "processing $i"
if {[regexp "^(\[^=\]*)=(.*)" $i foo evar evalue]} {
verbose "adding $evar to savelist"
lappend envvars_tosave $evar
verbose "savelist $envvars_tosave"
lappend krb5_init_vars $i
}
}
set envstackp 0
envstack_push
# setup_runtime_flags
# Sets the proper flags for shared libraries.
# Configuration is through a site.exp and the runvarlist variable
# Returns 1 if variables were already set, otherwise 0
proc setup_runtime_env { } {
global env
global krb5_init_vars
# Set the variables
foreach i $krb5_init_vars {
regexp "^(\[^=\]*)=(.*)" $i foo evar evalue
set env($evar) "$evalue"
verbose "$evar=$evalue"
}
return 0
}
# get_hostname
# This procedure will get the local hostname. It sets the global
# variables hostname (the full name) and localhostname (the first part
# of the name). Returns 1 on success, 0 on failure.
proc get_hostname { } {
global RESOLVE
global hostname
global localhostname
global domain
global tmppwd
if {[info exists hostname] && [info exists localhostname]} {
return 1
}
envstack_push
setup_runtime_env
catch "exec $RESOLVE -q >$tmppwd/hostname" exec_output
envstack_pop
if ![string match "" $exec_output] {
verbose -log $exec_output
perror "can't get hostname"
return 0
}
set file [open $tmppwd/hostname r]
if { [ gets $file hostname ] == -1 } {
perror "no output from hostname"
return 0
}
close $file
catch "exec rm -f $tmppwd/hostname" exec_output
regexp "^(\[^.\]*)\\.(.*)$" $hostname foo localhostname domain
set hostname [string tolower $hostname]
set localhostname [string tolower $localhostname]
set domain [string tolower $domain]
verbose "hostname: $hostname; localhostname: $localhostname; domain $domain"
return 1
}
# modify_principal name options...
proc modify_principal { name args } {
global KADMIN_LOCAL
global REALMNAME
spawn $KADMIN_LOCAL -r $REALMNAME
expect_after {
eof {
fail "modprinc (kadmin.local)"
return 0
}
timeout {
fail "modprinc (kadmin.local)"
return 0
}
}
expect "kadmin.local: "
send "modprinc $args $name\r"
expect -re "modprinc \[^\n\r\]* $name"
expect -re "Principal .* modified."
send "quit\r"
expect eof
catch expect_after
if ![check_exit_status "kadmin.local modprinc"] {
perror "kadmin.local modprinc exited abnormally"
}
return 1
}
# setup_kerberos_files
# This procedure will create some Kerberos files which must be created
# manually before trying to run any Kerberos programs. Returns 1 on
# success, 0 on failure.
proc setup_kerberos_files { } {
global REALMNAME
global hostname
global domain
global tmppwd
global supported_enctypes
global kdc_supported_enctypes
global last_passname_conf
global multipass_name
global master_key_type
if ![get_hostname] {
return 0
}
setup_krb5_conf client
setup_krb5_conf server
setup_krb5_conf kdc
# Create a kdc.conf file.
if { ![file exists $tmppwd/kdc.conf] \
|| $last_passname_conf != $multipass_name } {
if ![info exists master_key_type] {
set master_key_type des-cbc-md5
}
set conffile [open $tmppwd/kdc.conf w]
puts $conffile "\[kdcdefaults\]"
puts $conffile " kdc_ports = 3085,3086,3087,3088,3089"
puts $conffile ""
puts $conffile "\[realms\]"
puts $conffile " $REALMNAME = \{"
puts $conffile " database_name = $tmppwd/db"
puts $conffile " admin_database_name = $tmppwd/adb"
puts $conffile " admin_database_lockfile = $tmppwd/adb.lock"
puts $conffile " admin_keytab = $tmppwd/admin-keytab"
puts $conffile " key_stash_file = $tmppwd/stash"
puts $conffile " acl_file = $tmppwd/acl"
puts $conffile " kadmind_port = 3750"
puts $conffile " kpasswd_port = 3751"
puts $conffile " max_life = 1:00:00"
puts $conffile " max_renewable_life = 3:00:00"
puts $conffile " master_key_type = $master_key_type"
puts $conffile " master_key_name = master/key"
puts $conffile " supported_enctypes = $supported_enctypes"
puts $conffile " kdc_supported_enctypes = $kdc_supported_enctypes"
puts $conffile " kdc_ports = 3088"
puts $conffile " default_principal_expiration = 2037.12.31.23.59.59"
puts $conffile " default_principal_flags = -postdateable forwardable"
puts $conffile " dict_file = $tmppwd/dictfile"
puts $conffile " \}"
puts $conffile ""
close $conffile
}
# Create ACL file.
if ![file exists $tmppwd/acl] {
set aclfile [open $tmppwd/acl w]
puts $aclfile "krbtest/admin@$REALMNAME *"
close $aclfile
}
# Create krb.conf file
if ![file exists $tmppwd/krb.conf] {
set conffile [open $tmppwd/krb.conf w]
puts $conffile "$REALMNAME"
puts $conffile "$REALMNAME $hostname:3088 admin server"
close $conffile
}
# Create krb.realms file
if ![file exists $tmppwd/krb.realms] {
set conffile [open $tmppwd/krb.realms w]
puts $conffile ".[string toupper $domain] $REALMNAME"
puts $conffile "[string toupper $domain]. $REALMNAME"
close $conffile
}
# Create dictfile file.
if ![file exists $tmppwd/dictfile] {
set dictfile [open $tmppwd/dictfile w]
puts $dictfile "weak_password"
close $dictfile
}
set last_passname_conf $multipass_name
return 1
}
proc setup_krb5_conf { {type client} } {
global tmppwd
global hostname
global domain
global REALMNAME
global last_passname_conf
global multipass_name
global default_tgs_enctypes
global default_tkt_enctypes
global permitted_enctypes
# Create a krb5.conf file.
if { ![file exists $tmppwd/krb5.$type.conf] \
|| $last_passname_conf != $multipass_name } {
set conffile [open $tmppwd/krb5.$type.conf w]
puts $conffile "\[libdefaults\]"
puts $conffile " default_realm = $REALMNAME"
if [info exists default_tgs_enctypes($type)] {
puts $conffile \
" default_tgs_enctypes = $default_tgs_enctypes($type)"
}
if [info exists default_tkt_enctypes($type)] {
puts $conffile \
" default_tkt_enctypes = $default_tkt_enctypes($type)"
}
if [info exists permitted_enctypes($type)] {
puts $conffile \
" permitted_enctypes = $permitted_enctypes($type)"
}
puts $conffile " krb4_config = $tmppwd/krb.conf"
puts $conffile " krb4_realms = $tmppwd/krb.realms"
puts $conffile " krb4_srvtab = $tmppwd/v4srvtab"
puts $conffile ""
puts $conffile "\[realms\]"
puts $conffile " $REALMNAME = \{"
puts $conffile " kdc = $hostname:3088"
puts $conffile " admin_server = $hostname:3750"
puts $conffile " kpasswd_server = $hostname:3751"
puts $conffile " default_domain = $domain"
puts $conffile " krb524_server = $hostname:3752"
puts $conffile " \}"
puts $conffile ""
puts $conffile "\[domain_realm\]"
puts $conffile " .$domain = $REALMNAME"
puts $conffile " $domain = $REALMNAME"
puts $conffile ""
puts $conffile "\[logging\]"
puts $conffile " admin_server = FILE:$tmppwd/kadmind5.log"
puts $conffile " kdc = FILE:$tmppwd/kdc.log"
puts $conffile " default = FILE:$tmppwd/others.log"
close $conffile
}
}
# Save the original values of the environment variables we are going
# to muck with.
# XXX deal with envstack later.
if [info exists env(KRB5_CONFIG)] {
set orig_krb5_conf $env(KRB5_CONFIG)
} else {
catch "unset orig_krb5_config"
}
if [info exists env(KRB5CCNAME)] {
set orig_krb5ccname $env(KRB5CCNAME)
} else {
catch "unset orig_krb5ccname"
}
if [ info exists env(KRB5RCACHEDIR)] {
set orig_krb5rcachedir $env(KRB5RCACHEDIR)
} else {
catch "unset orig_krb5rcachedir"
}
if [ info exists env(KERBEROS_SERVER)] {
set orig_kerberos_server $env(KERBEROS_SERVER)
} else {
catch "unset orig_kerberos_server"
}
# setup_kerberos_env
# Set the environment variables needed to run Kerberos programs.
proc setup_kerberos_env { {type client} } {
global REALMNAME
global env
global tmppwd
global hostname
global krb5_init_vars
# Set the environment variable KRB5_CONFIG to point to our krb5.conf file.
# All the Kerberos tools check KRB5_CONFIG.
# Actually, V5 doesn't currently use this.
set env(KRB5_CONFIG) $tmppwd/krb5.$type.conf
verbose "KRB5_CONFIG=$env(KRB5_CONFIG)"
# Direct the Kerberos programs at a local ticket file.
set env(KRB5CCNAME) $tmppwd/tkt
verbose "KRB5CCNAME=$env(KRB5CCNAME)"
# Direct the Kerberos programs at a local ticket file.
set env(KRBTKFILE) $tmppwd/tktv4
verbose "KRBTKFILE=$env(KRBTKFILE)"
# Direct the Kerberos server at a cache file stored in the
# temporary directory.
set env(KRB5RCACHEDIR) $tmppwd
verbose "KRB5RCACHEDIR=$env(KRB5RCACHEDIR)"
# Tell the Kerberos tools how to contact the $REALMNAME server.
set env(KERBEROS_SERVER) "$REALMNAME:$hostname:3088"
verbose "KERBEROS_SERVER=$env(KERBEROS_SERVER)"
# Get the run time environment variables... (including LD_LIBRARY_PATH)
setup_runtime_env
# Set our kdc config file.
set env(KRB5_KDC_PROFILE) $tmppwd/kdc.conf
verbose "KRB5_KDC_PROFILE=$env(KRB5_KDC_PROFILE)"
# Create an environment setup script. (For convenience)
if ![file exists $tmppwd/env.sh] {
set envfile [open $tmppwd/env.sh w]
puts $envfile "KRB5_CONFIG=$env(KRB5_CONFIG)"
puts $envfile "KRB5CCNAME=$env(KRB5CCNAME)"
puts $envfile "KRB5RCACHEDIR=$env(KRB5RCACHEDIR)"
puts $envfile "KERBEROS_SERVER=$env(KERBEROS_SERVER)"
puts $envfile "KRB5_KDC_PROFILE=$env(KRB5_KDC_PROFILE)"
puts $envfile "export KRB5_CONFIG KRB5CCNAME KRB5RCACHEDIR"
puts $envfile "export KERBEROS_SERVER KRB5_KDC_PROFILE"
foreach i $krb5_init_vars {
regexp "^(\[^=\]*)=(.*)" $i foo evar evalue
puts $envfile "$evar=$env($evar)"
puts $envfile "export $evar"
}
close $envfile
}
if ![file exists $tmppwd/env.csh] {
set envfile [open $tmppwd/env.csh w]
puts $envfile "setenv KRB5_CONFIG $env(KRB5_CONFIG)"
puts $envfile "setenv KRB5CCNAME $env(KRB5CCNAME)"
puts $envfile "setenv KRB5RCACHEDIR $env(KRB5RCACHEDIR)"
puts $envfile "setenv KERBEROS_SERVER $env(KERBEROS_SERVER)"
puts $envfile "setenv KRB5_KDC_PROFILE $env(KRB5_KDC_PROFILE)"
foreach i $krb5_init_vars {
regexp "^(\[^=\]*)=(.*)" $i foo evar evalue
puts $envfile "setenv $evar $env($evar)"
}
close $envfile
}
return 1
}
# Restore the Kerberos environment, in case setup_kerberos_env was
# already called by an earlier test.
proc restore_kerberos_env { } {
global env
global orig_krb5_config
global orig_krb5ccname
global orig_krb5rcachedir
global orig_kerberos_server
if [info exists orig_krb5_config] {
set env(KRB5_CONFIG) $orig_krb5_config
} else {
catch "unset env(KRB5_CONFIG)"
}
if [info exists orig_krb5ccname] {
set env(KRB5CCNAME) $orig_krb5ccname
} else {
catch "unset env(KRB5CCNAME)"
}
if [info exists orig_krb5rcachedir] {
set env(KRB5RCACHEDIR) $orig_krb5rcachedir
} else {
catch "unset env(KRB5RCACHEDIR)"
}
if [info exists orig_kerberos_server] {
set env(KERBEROS_SERVER) $orig_kerberos_server
} else {
catch "unset env(KERBEROS_SERVER)"
}
}
# setup_kadmind_srvtab
# A procedure to build the srvtab for kadmind5 so that kadmin5 and it
# may successfully communicate.
# Returns 1 on success, 0 on failure.
proc setup_kadmind_srvtab { } {
global REALMNAME
global KADMIN_LOCAL
global KEY
global tmppwd
catch "exec rm -f $tmppwd/admin-keytab"
envstack_push
setup_kerberos_env kdc
spawn $KADMIN_LOCAL -r $REALMNAME
envstack_pop
catch expect_after
expect_after {
-re "(.*)\r\nkadmin.local: " {
fail "kadmin.local admin-keytab (unmatched output: $expect_out(1,string)"
catch "exec rm -f $tmppwd/admin-keytab"
catch "expect_after"
return 0
}
timeout {
fail "kadmin.local admin-keytab (timeout)"
catch "exec rm -f $tmppwd/admin-keytab"
catch "expect_after"
return 0
}
eof {
fail "kadmin.local admin-keytab (eof)"
catch "exec rm -f $tmppwd/admin-keytab"
catch "expect_after"
return 0
}
}
expect "kadmin.local: "
send "xst -k admin-new-srvtab kadmin/admin\r"
expect "xst -k admin-new-srvtab kadmin/admin\r\n"
expect -re ".*Entry for principal kadmin/admin.* added to keytab WRFILE:admin-new-srvtab."
expect "kadmin.local: "
catch "exec mv -f admin-new-srvtab changepw-new-srvtab" exec_output
if ![string match "" $exec_output] {
verbose -log "$exec_output"
perror "can't mv admin-new-srvtab"
catch expect_after
return 0
}
send "xst -k changepw-new-srvtab kadmin/changepw\r"
expect "xst -k changepw-new-srvtab kadmin/changepw\r\n"
expect -re ".*Entry for principal kadmin/changepw.* added to keytab WRFILE:changepw-new-srvtab."
expect "kadmin.local: "
send "quit\r"
expect eof
catch expect_after
if ![check_exit_status "kadmin.local admin-keytab"] {
catch "exec rm -f $tmppwd/admin-keytab"
perror "kadmin.local admin-keytab exited abnormally"
return 0
}
catch "exec mv -f changepw-new-srvtab $tmppwd/admin-keytab" exec_output
if ![string match "" $exec_output] {
verbose -log "$exec_output"
perror "can't mv new admin-keytab"
return 0
}
# Make the srvtab file globally readable in case we are using a
# root shell and the srvtab is NFS mounted.
catch "exec chmod a+r $tmppwd/admin-keytab"
return 1
}
# setup_kerberos_db
# Initialize the Kerberos database. If the argument is non-zero, call
# pass at relevant points. Returns 1 on success, 0 on failure.
proc setup_kerberos_db { standalone } {
global REALMNAME
global KDB5_UTIL
global KADMIN_LOCAL
global KEY
global tmppwd
global spawn_id
global des3_krbtgt
global tgt_support_desmd5
global multipass_name
global last_passname_db
set failall 0
if {!$standalone && [file exists $tmppwd/db.ok] \
&& $last_passname_db == $multipass_name} {
return 1
}
catch "exec rm -f [glob -nocomplain $tmppwd/db* $tmppwd/adb*]"
# Creating a new database means we need a new srvtab.
catch "exec rm -f $tmppwd/srvtab"
envstack_push
if { ![setup_kerberos_files] || ![setup_kerberos_env kdc] } {
set failall 1
}
# Set up a common expect_after for use in multiple places.
set def_exp_after {
timeout {
set test "$test (timeout)"
break
}
eof {
set test "$test (eof)"
break
}
}
set test "kdb5_util create"
set body {
if $failall {
break
}
#exec xterm
verbose "starting $test"
spawn $KDB5_UTIL -r $REALMNAME create
expect_after $def_exp_after
expect "Enter KDC database master key:"
set test "kdb5_util create (verify)"
send "masterkey$KEY\r"
expect "Re-enter KDC database master key to verify:"
set test "kdb5_util create"
send "masterkey$KEY\r"
expect {
-re "\[Cc\]ouldn't" {
expect eof
break
}
"Cannot find/read stored" exp_continue
"Warning: proceeding without master key" exp_continue
eof { }
}
catch expect_after
if ![check_exit_status kdb5_util] {
break
}
}
set ret [catch $body]
catch expect_after
if $ret {
set failall 1
if $standalone {
fail $test
}
} else {
if $standalone {
pass $test
}
}
# Stash the master key in a file.
set test "kdb5_util stash"
set body {
if $failall {
break
}
spawn $KDB5_UTIL -r $REALMNAME stash
verbose "starting $test"
expect_after $def_exp_after
expect "Enter KDC database master key:"
send "masterkey$KEY\r"
expect eof
catch expect_after
if ![check_exit_status kdb5_util] {
break
}
}
set ret [catch $body]
catch "expect eof"
catch expect_after
if $ret {
set failall 1
if $standalone {
fail $test
} else {
catch "exec rm -f $tmppwd/db.ok $tmppwd/adb.db"
}
} else {
if $standalone {
pass $test
}
}
# Add an admin user.
#send_user "will run: $KADMIN_LOCAL -r $REALMNAME\n"
#exec xterm
set test "kadmin.local ank krbtest/admin"
set body {
if $failall {
break
}
spawn $KADMIN_LOCAL -r $REALMNAME
verbose "starting $test"
expect_after $def_exp_after
expect "kadmin.local: "
send "ank krbtest/admin@$REALMNAME\r"
# It echos...
expect "ank krbtest/admin@$REALMNAME\r"
expect "Enter password for principal \"krbtest/admin@$REALMNAME\":"
send "adminpass$KEY\r"
expect "Re-enter password for principal \"krbtest/admin@$REALMNAME\":"
send "adminpass$KEY\r"
expect {
"Principal \"krbtest/admin@$REALMNAME\" created" { }
"Principal or policy already exists while creating*" { }
}
expect "kadmin.local: "
send "quit\r"
expect eof
catch expect_after
if ![check_exit_status kadmin_local] {
break
}
}
set ret [catch $body]
catch "expect eof"
catch expect_after
if $ret {
set failall 1
if $standalone {
fail $test
} else {
catch "exec rm -f $tmppwd/db.ok $tmppwd/adb.db"
}
} else {
if $standalone {
pass $test
}
}
if $des3_krbtgt {
# Set the TGT key to DES3.
set test "kadmin.local TGT to DES3"
set body {
if $failall {
break
}
spawn $KADMIN_LOCAL -r $REALMNAME -e des3-cbc-sha1:normal
verbose "starting $test"
expect_after $def_exp_after
expect "kadmin.local: "
send "cpw -randkey krbtgt/$REALMNAME@$REALMNAME\r"
# It echos...
expect "cpw -randkey krbtgt/$REALMNAME@$REALMNAME\r"
expect {
"Key for \"krbtgt/$REALMNAME@$REALMNAME\" randomized." { }
}
expect "kadmin.local: "
send "quit\r"
expect eof
catch expect_after
if ![check_exit_status kadmin_local] {
break
}
}
set ret [catch $body]
catch "expect eof"
catch expect_after
if $ret {
set failall 1
if $standalone {
fail $test
} else {
catch "exec rm -f $tmppwd/db.ok $tmppwd/adb.db"
}
} else {
if $standalone {
pass $test
}
}
}
if $tgt_support_desmd5 {
# Make TGT support des-cbc-md5
set test "kadmin.local TGT to SUPPORT_DESMD5"
set body {
if $failall {
break
}
spawn $KADMIN_LOCAL -r $REALMNAME
verbose "starting $test"
expect_after $def_exp_after
expect "kadmin.local: "
send "modprinc +support_desmd5 krbtgt/$REALMNAME@$REALMNAME\r"
# It echos...
expect "modprinc +support_desmd5 krbtgt/$REALMNAME@$REALMNAME\r"
expect {
"Principal \"krbtgt/$REALMNAME@$REALMNAME\" modified.\r\n" { }
}
expect "kadmin.local: "
send "quit\r"
expect eof
catch expect_after
if ![check_exit_status kadmin_local] {
break
}
}
set ret [catch $body]
catch "expect eof"
catch expect_after
if $ret {
set failall 1
if $standalone {
fail $test
} else {
catch "exec rm -f $tmppwd/db.ok $tmppwd/adb.db"
}
} else {
if $standalone {
pass $test
}
}
}
# XXX should deal with envstack inside setup_kadmind_srvtab too
set ret [setup_kadmind_srvtab]
envstack_pop
if !$ret {
return 0
}
# create the admin database lock file
catch "exec touch $tmppwd/adb.lock"
set last_passname_db $multipass_name
return 1
}
# start_kerberos_daemons
# A procedure to build a Kerberos database and start up the kerberos
# and kadmind daemons. This sets the global variables kdc_pid,
# kdc_spawn_id, kadmind_pid, and kadmind_spawn_id. The procedure
# stop_kerberos_daemons should be used to stop the daemons. If the
# argument is non-zero, call pass at relevant points. Returns 1 on
# success, 0 on failure.
proc start_kerberos_daemons { standalone } {
global BINSH
global REALMNAME
global KRB5KDC
global KADMIND
global KEY
global kdc_pid
global kdc_spawn_id
global kadmind_pid
global kadmind_spawn_id
global tmppwd
global env
if ![setup_kerberos_db 0] {
return 0
}
if {$standalone} {
catch "exec rm -f $tmppwd/krb.log"
catch "exec rm -f $tmppwd/kadmind.log"
catch "exec rm -f $tmppwd/krb5kdc_rcache"
}
# Start up the kerberos daemon
# Why are we doing all this with the log file you may ask.
# We need a handle on when the server starts. If we log the output
# of the server to say stderr, then if we stop looking for output,
# buffers will fill and the server will stop working....
# So, we look to see when a line is added to the log file and then
# check it..
# The same thing is done a little later for the kadmind
set kdc_lfile $tmppwd/kdc.log
set kadmind_lfile $tmppwd/kadmind5.log
if ![file exists $kdc_lfile] then {
catch [touch $kdc_lfile]
}
spawn tail -f $kdc_lfile
set tailf_spawn_id $spawn_id
set tailf_pid [exp_pid]
set markstr "===MARK $tailf_pid [exec date] ==="
set f [open $kdc_lfile a]
puts $f $markstr
close $f
expect {
-i $tailf_spawn_id
-ex "$markstr\r\n" { }
timeout {
if {$standalone} {
verbose -log "tail -f timed out looking for mark"
fail "krb5kdc"
} else {
perror "krbkdc tail -f timed out looking for mark"
}
stop_kerberos_daemons
exec kill $tailf_pid
expect -i $tailf_spawn_id eof
wait -i $tailf_spawn_id
return 0
}
}
envstack_push
setup_kerberos_env kdc
spawn $KRB5KDC -r $REALMNAME -n
envstack_pop
set kdc_pid [exp_pid]
set kdc_spawn_id $spawn_id
expect {
-i $tailf_spawn_id
-re "commencing operation\r\n" { }
timeout {
if {$standalone} {
verbose -log "krb5kdc startup timed out"
fail "krb5kdc"
} else {
perror "krb5kdc startup timed out"
}
stop_kerberos_daemons
exec kill $tailf_pid
expect -i $tailf_spawn_id eof
wait -i $tailf_spawn_id
return 0
}
}
exec kill $tailf_pid
expect -i $tailf_spawn_id eof
wait -i $tailf_spawn_id
if {$standalone} {
pass "krb5kdc"
}
# Give the kerberos daemon a few seconds to get set up.
# sleep 2
#
# Save setting of KRB5_KTNAME. We do not want to override kdc.conf
# file during kadmind startup. (this is in case user has KRB5_KTNAME
# set before starting make check)
#
if [info exists env(KRB5_KTNAME)] {
set start_save_ktname $env(KRB5_KTNAME)
}
catch "unset env(KRB5_KTNAME)"
if ![file exists $kadmind_lfile] then {
catch [touch $kadmind_lfile]
}
spawn tail -f $kadmind_lfile
set tailf_spawn_id $spawn_id
set tailf_pid [exp_pid]
set markstr "===MARK $tailf_pid [exec date] ==="
set f [open $kadmind_lfile a]
puts $f $markstr
close $f
expect {
-i $tailf_spawn_id
-ex "$markstr\r\n" { }
timeout {
if {$standalone} {
verbose -log "tail -f timed out looking for mark"
fail "kadmind"
} else {
perror "kadmind tail -f timed out looking for mark"
}
stop_kerberos_daemons
exec kill $tailf_pid
expect -i $tailf_spawn_id eof
wait -i $tailf_spawn_id
return 0
}
}
# Start up the kadmind daemon
# XXXX kadmind uses stderr a lot. the sh -c and redirect can be
# removed when this is fixed
envstack_push
setup_kerberos_env kdc
spawn $BINSH -c "exec $KADMIND -r $REALMNAME -nofork 2>>$kadmind_lfile"
envstack_pop
set kadmind_pid [exp_pid]
set kadmind_spawn_id $spawn_id
# Restore KRB5_KTNAME
if [info exists start_save_ktname] {
set env(KRB5_KTNAME) $start_save_ktname
unset start_save_ktname
}
expect {
-i $tailf_spawn_id
"Seeding random number" exp_continue
"cannont initialize network" {
if {$standalone} {
verbose -log "kadmind failed network init"
fail "kadmind"
} else {
perror "kadmind failed network init"
}
stop_kerberos_daemons
exec kill $tailf_pid
expect -i $tailf_spawn_id eof
wait -i $tailf_spawn_id
return 0
}
"cannot bind to network address" {
if {$standalone} {
verbose -log "kadmind failed to bind socket"
fail "kadmind"
} else {
perror "kadmind failed to bind socket"
}
stop_kerberos_daemons
exec kill $tailf_pid
expect -i $tailf_spawn_id eof
wait -i $tailf_spawn_id
return 0
}
"starting" { }
timeout {
if {$standalone} {
verbose -log "kadmind failed to start"
fail "kadmind"
} else {
verbose -log "kadmind failed to start"
perror "kadmind failed to start"
}
#sleep 10
stop_kerberos_daemons
exec kill $tailf_pid
expect -i $tailf_spawn_id eof
wait -i $tailf_spawn_id
return 0
}
}
exec kill $tailf_pid
expect -i $tailf_spawn_id eof
wait -i $tailf_spawn_id
if {$standalone} {
pass "kadmind"
}
# Give the kadmind daemon a few seconds to get set up.
# sleep 2
return 1
}
# stop_kerberos_daemons
# Stop the kerberos daemons. Returns 1 on success, 0 on failure.
proc stop_kerberos_daemons { } {
global kdc_pid
global kdc_spawn_id
global kadmind_pid
global kadmind_spawn_id
verbose "entered stop_kerberos_daemons"
if [info exists kdc_pid] {
catch "exec kill $kdc_pid"
catch "expect eof"
set kdc_list [wait -i $kdc_spawn_id]
verbose "wait -i $kdc_spawn_id returned $kdc_list (kdc)"
unset kdc_pid
unset kdc_list
}
if [info exists kadmind_pid] {
catch "exec kill $kadmind_pid"
catch "expect eof"
set kadmind_list [wait -i $kadmind_spawn_id]
verbose "wait -i $kadmind_spawn_id returned $kadmind_list (kadmind5)"
unset kadmind_pid
unset kadmind_list
}
verbose "exiting stop_kerberos_daemons"
return 1
}
# add_kerberos_key
# Add an key to the Kerberos database. start_kerberos_daemons must be
# called before this procedure. If the standalone argument is
# non-zero, call pass at relevant points. Returns 1 on success, 0 on
# failure.
proc add_kerberos_key { kkey standalone } {
global REALMNAME
global KADMIN
global KEY
global spawn_id
# Use kadmin to add an key.
set test "kadmin ank $kkey"
set body {
envstack_push
setup_kerberos_env client
spawn $KADMIN -p krbtest/admin@$REALMNAME -q "ank $kkey@$REALMNAME"
envstack_pop
verbose "starting $test"
expect_after {
"Cannot contact any KDC" {
set test "$test (lost KDC)"
break
}
timeout {
set test "$test (timeout)"
break
}
eof {
set test "$test (eof)"
break
}
}
expect "Enter password:"
send "adminpass$KEY\r"
expect "Enter password for principal \"$kkey@$REALMNAME\":"
send "$kkey"
send "$KEY\r"
expect "Re-enter password for principal \"$kkey@$REALMNAME\":"
send "$kkey"
send "$KEY\r"
expect {
"Principal \"$kkey@$REALMNAME\" created" { }
"Principal or policy already exists while creating*" { }
}
expect eof
if ![check_exit_status kadmin] {
break
}
}
set ret [catch $body]
catch "expect eof"
catch expect_after
if $ret {
if $standalone {
fail $test
}
return 0
} else {
if $standalone {
pass $test
}
return 1
}
}
# add_random_key
# Add a key with a random password to the Kerberos database.
# start_kerberos_daemons must be called before this procedure. If the
# standalone argument is non-zero, call pass at relevant points.
# Returns 1 on success, 0 on failure.
proc add_random_key { kkey standalone } {
global REALMNAME
global KADMIN
global KEY
global spawn_id
# Use kadmin to add an key.
set test "kadmin ark $kkey"
set body {
envstack_push
setup_kerberos_env client
spawn $KADMIN -p krbtest/admin@$REALMNAME -q "ank -randkey $kkey@$REALMNAME"
envstack_pop
expect_after {
timeout {
set test "$test (timeout)"
break
}
eof {
set test "$test (eof)"
break
}
}
expect "Enter password:"
send "adminpass$KEY\r"
expect {
"Principal \"$kkey@$REALMNAME\" created" { }
"Principal or policy already exists while creating*" { }
}
expect eof
if ![check_exit_status kadmin] {
break
}
}
if [catch $body] {
catch expect_after
if $standalone {
fail $test
}
return 0
} else {
catch expect_after
if $standalone {
pass $test
}
return 1
}
}
# setup_srvtab
# Set up a srvtab file. start_kerberos_daemons and add_random_key
# $id/$hostname must be called before this procedure. If the
# argument is non-zero, call pass at relevant points. Returns 1 on
# success, 0 on failure. If the id field is not provided, host is used.
proc setup_srvtab { standalone {id host} } {
global REALMNAME
global KADMIN_LOCAL
global KEY
global tmppwd
global hostname
global spawn_id
global last_service
if {!$standalone && [file exists $tmppwd/srvtab] && $last_service == $id} {
return 1
}
catch "exec rm -f $tmppwd/srvtab $tmppwd/srvtab.old"
if ![get_hostname] {
return 0
}
catch "exec rm -f $hostname-new-srvtab"
envstack_push
setup_kerberos_env kdc
spawn $KADMIN_LOCAL -r $REALMNAME
envstack_pop
expect_after {
-re "(.*)\r\nkadmin.local: " {
fail "kadmin.local srvtab (unmatched output: $expect_out(1,string))"
if {!$standalone} {
catch "exec rm -f $tmppwd/srvtab"
}
catch "expect_after"
return 0
}
timeout {
fail "kadmin.local srvtab"
if {!$standalone} {
catch "exec rm -f $tmppwd/srvtab"
}
catch "expect_after"
return 0
}
eof {
fail "kadmin.local srvtab"
if {!$standalone} {
catch "exec rm -f $tmppwd/srvtab"
}
catch "expect_after"
return 0
}
}
expect "kadmin.local: "
send "xst -k $hostname-new-srvtab $id/$hostname\r"
expect "xst -k $hostname-new-srvtab $id/$hostname\r\n"
expect {
-re ".*Entry for principal $id/$hostname.* added to keytab WRFILE:$hostname-new-srvtab." { }
-re "\r\nkadmin.local: " {
if {$standalone} {
fail "kadmin.local srvtab"
} else {
catch "exec rm -f $tmppwd/srvtab"
}
catch expect_after
return 0
}
}
expect "kadmin.local: "
send "quit\r"
expect eof
catch expect_after
if ![check_exit_status "kadmin.local srvtab"] {
if {!$standalone} {
catch "exec rm -f $tmppwd/srvtab"
}
return 0
}
catch "exec mv -f $hostname-new-srvtab $tmppwd/srvtab" exec_output
if ![string match "" $exec_output] {
verbose -log "$exec_output"
perror "can't mv new srvtab"
return 0
}
if {$standalone} {
pass "kadmin.local srvtab"
}
# Make the srvtab file globally readable in case we are using a
# root shell and the srvtab is NFS mounted.
catch "exec chmod a+r $tmppwd/srvtab"
# Remember what we just extracted
set last_service $id
return 1
}
# kinit
# Use kinit to get a ticket. If the argument is non-zero, call pass
# at relevant points. Returns 1 on success, 0 on failure.
proc kinit { name pass standalone } {
global REALMNAME
global KINIT
global spawn_id
# Use kinit to get a ticket.
#
# For now always get forwardable tickets. Later when we need to make
# tests that distiguish between forwardable tickets and otherwise
# we should but another option to this proc. --proven
#
spawn $KINIT -5 -f $name@$REALMNAME
expect {
"Password for $name@$REALMNAME:" {
verbose "kinit started"
}
timeout {
fail "kinit"
return 0
}
eof {
fail "kinit"
return 0
}
}
send "$pass\r"
expect eof
if ![check_exit_status kinit] {
return 0
}
if {$standalone} {
pass "kinit"
}
return 1
}
proc kinit_kt { name keytab standalone testname } {
global REALMNAME
global KINIT
global spawn_id
# Use kinit to get a ticket.
#
# For now always get forwardable tickets. Later when we need to make
# tests that distiguish between forwardable tickets and otherwise
# we should but another option to this proc. --proven
#
spawn $KINIT -5 -f -k -t $keytab $name@$REALMNAME
expect {
timeout {
fail "kinit $testname"
return 0
}
eof { }
}
if ![check_exit_status "kinit $testname"] {
return 0
}
if {$standalone} {
pass "kinit $testname"
}
return 1
}
# List tickets. Requires client and server names, and test name.
# Checks that klist exist status is zero.
# Records pass or fail, and returns 1 or 0.
proc do_klist { myname servname testname } {
global KLIST
global tmppwd
spawn $KLIST -5 -e
expect {
-re "Ticket cache:\[ \]*(.+:)?$tmppwd/tkt.*Default principal:\[ \]*$myname.*$servname\r\n" {
verbose "klist started"
}
timeout {
fail $testname
return 0
}
eof {
fail $testname
return 0
}
}
expect {
"\r" { }
eof { }
}
if ![check_exit_status $testname] {
return 0
}
pass $testname
return 1
}
proc do_klist_kt { keytab testname } {
global KLIST
global tmppwd
spawn $KLIST -5 -e -k $keytab
expect {
-re "Keytab name:\[ \]*(.+:)?.*KVNO Principal\r\n---- -*\r\n" {
verbose "klist started"
}
timeout {
fail $testname
return 0
}
eof {
fail $testname
return 0
}
}
set more 1
while {$more} {
expect {
-re { *[0-9][0-9]* *[a-zA-Z/@.-]* \([/a-zA-Z 0-9-]*\) *\r\n} {
verbose -log "key: $expect_out(buffer)"
}
eof { set more 0 }
}
}
if ![check_exit_status $testname] {
return 0
}
pass $testname
return 1
}
proc do_klist_err { testname } {
global KLIST
global spawn_id
spawn $KLIST -5
# Might say "credentials cache" or "credentials cache file".
expect {
-re "klist: No credentials cache.*found.*\r\n" {
verbose "klist started"
}
timeout {
fail $testname
return 0
}
eof {
fail $testname
return 0
}
}
# We can't use check_exit_status, because we expect an exit status
# of 1.
set status_list [wait -i $spawn_id]
verbose "wait -i $spawn_id returned $status_list ($testname)"
if { [lindex $status_list 2] != 0 } {
fail "$testname (bad exit status) $status_list"
return 0
} else { if { [lindex $status_list 3] != 1 } {
fail "$testname (bad exit status) $status_list"
return 0
} else {
pass $testname
} }
return 1
}
proc do_kdestroy { testname } {
global KDESTROY
spawn $KDESTROY -5
if ![check_exit_status $testname] {
fail $testname
return 0
}
pass $testname
return 1
}
proc xst { keytab name } {
global KADMIN_LOCAL
global REALMNAME
envstack_push
setup_kerberos_env kdc
spawn $KADMIN_LOCAL -r $REALMNAME
envstack_pop
catch expect_after
expect_after {
-re "(.*)\r\nkadmin.local: " {
fail "kadmin.local xst $keytab (unmatched output: $expect_out(1,string)"
catch "expect_after"
return 0
}
timeout {
fail "kadmin.local xst $keytab (timeout)"
catch "expect_after"
return 0
}
eof {
fail "kadmin.local xst $keytab (eof)"
catch "expect_after"
return 0
}
}
expect "kadmin.local: "
send "xst -k $keytab $name\r"
expect -re "xst -k \[^\r\n\]*\r\n.*Entry for principal .* added to keytab WRFILE:.*\r\nkadmin.local: "
send "quit\r"
expect eof
catch expect_after
if ![check_exit_status "kadmin.local $keytab"] {
perror "kadmin.local xst $keytab exited abnormally"
return 0
}
return 1
}
# v4_compatible_enctype
# Returns 1 if v4 testing is enabled this passes encryption types are compatable with kerberos 4 work
proc v4_compatible_enctype {} {
global supported_enctypes
global KRBIV
if ![info exists KRBIV] {
return 0;
}
if { $KRBIV && [string first des-cbc-crc:v4 "$supported_enctypes"] >= 0} {
return 1
} else {
return 0
}
}
# kinit
# Use kinit to get a ticket. If the argument is non-zero, call pass
# at relevant points. Returns 1 on success, 0 on failure.
proc v4kinit { name pass standalone } {
global REALMNAME
global KINIT
global spawn_id
# Use kinit to get a ticket.
#
# For now always get forwardable tickets. Later when we need to make
# tests that distiguish between forwardable tickets and otherwise
# we should but another option to this proc. --proven
#
spawn $KINIT -4 $name@$REALMNAME
expect {
"Password for $name@$REALMNAME:" {
verbose "v4kinit started"
}
timeout {
fail "v4kinit"
return 0
}
eof {
fail "v4kinit"
return 0
}
}
send "$pass\r"
expect eof
if ![check_exit_status kinit] {
return 0
}
if {$standalone} {
pass "v4kinit"
}
return 1
}
proc v4kinit_kt { name keytab standalone } {
global REALMNAME
global KINIT
global spawn_id
# Use kinit to get a ticket.
#
# For now always get forwardable tickets. Later when we need to make
# tests that distiguish between forwardable tickets and otherwise
# we should but another option to this proc. --proven
#
spawn $KINIT -4 -k -t $keytab $name@$REALMNAME
expect {
timeout {
fail "v4kinit"
return 0
}
eof { }
}
if ![check_exit_status kinit] {
return 0
}
if {$standalone} {
pass "v4kinit"
}
return 1
}
# List v4 tickets.
# Client and server are regular expressions.
proc v4klist { client server testname } {
global KLIST
global tmppwd
spawn $KLIST -4
expect {
-re "Kerberos 4 ticket cache:\[ \]*(.+:)?$tmppwd/tkt.*Principal:\[ \]*$client.*$server\r\n" {
verbose "klist started"
}
timeout {
fail $testname
return 0
}
eof {
fail $testname
return 0
}
}
expect {
"\r" { }
eof { }
}
if ![check_exit_status $testname] {
return 0
}
pass $testname
return 1
}
# Destroy tickets.
proc v4kdestroy { testname } {
global KDESTROY
spawn $KDESTROY -4
if ![check_exit_status $testname] {
return 0
}
pass $testname
return 1
}
# Try to list the krb4 tickets -- there shouldn't be any ticket file.
proc v4klist_none { testname } {
global KLIST
global tmppwd
# Double check that the ticket was destroyed.
spawn $KLIST -4
expect {
-re "Kerberos 4 ticket cache:\[ \]*(.+:)?$tmppwd/tkt.*klist: You have no tickets cached.*\r\n" {
verbose "v4klist started"
pass "$testname (output)"
}
timeout {
fail "$testname (output)"
# Skip the 'wait' below, if it's taking too long.
untested "$testname (exit status)"
return 0
}
eof {
fail "$testname (output)"
}
}
# We can't use check_exit_status, because we expect an exit status
# of 1.
set status_list [wait -i $spawn_id]
verbose "wait -i $spawn_id returned $status_list (v4klist)"
if { [lindex $status_list 2] != 0 } {
fail "$testname (exit status)"
return 0
} else {
if { [lindex $status_list 3] != 1 } {
fail "$testname (exit status)"
return 0
} else {
pass "$testname (exit status)"
}
}
return 1
}
# Set up a root shell using rlogin $hostname -l root. This is used
# when testing the daemons that must be run as root, such as telnetd
# or rlogind. This sets the global variables rlogin_spawn_id and
# rlogin_pid. Returns 1 on success, 0 on failure.
#
# This procedure will only succeed if the person running the test has
# a valid ticket for a name listed in the /.klogin file. Naturally,
# Kerberos must already be installed on this machine. It's a pain,
# but I can't think of a better approach.
proc setup_root_shell { testname } {
global BINSH
global ROOT_PROMPT
global KEY
global RLOGIN
global RLOGIN_FLAGS
global hostname
global rlogin_spawn_id
global rlogin_pid
global tmppwd
global env
global krb5_init_vars
global timeout
# Make sure we are using the original values of the environment
# variables. This means that the caller must call
# setup_kerberos_env after calling this procedure.
# XXX fixme to deal with envstack
restore_kerberos_env
setup_runtime_env
set me [exec whoami]
if [string match root $me] {
return [setup_root_shell_noremote $testname]
}
if ![get_hostname] {
return 0
}
# If you have not installed Kerberos on your system, and you want
# to run these tests, you can do it if you are willing to put your
# root password in this file (this is not a very good idea, but
# it's safe enough if you disconnect from the network and remember
# to remove the password later). Change the rlogin in the next
# line to be /usr/ucb/rlogin (or whatever is appropriate for your
# system). Then change the lines after "word:" a few lines
# farther down to be
# send "rootpassword\r"
# exp_continue
eval spawn $RLOGIN $hostname -l root $RLOGIN_FLAGS
set rlogin_spawn_id $spawn_id
set rlogin_pid [exp_pid]
set old_timeout $timeout
set timeout 300
expect {
-re "word:|erberos rlogin failed|ection refused|ection reset by peer" {
note "$testname test requires ability to rlogin as root"
unsupported "$testname"
set timeout $old_timeout
stop_root_shell
return 0
}
-re "$ROOT_PROMPT" { }
timeout {
perror "timeout from rlogin $hostname -l root"
perror "If you have an unusual root prompt,"
perror "try running with ROOT_PROMPT=\"regexp\""
set timeout $old_timeout
stop_root_shell
return 0
}
eof {
perror "eof from rlogin $hostname -l root"
stop_root_shell
set timeout $old_timeout
catch "expect_after"
return 0
}
}
expect_after {
timeout {
perror "timeout from rlogin $hostname -l root"
stop_root_shell
set timeout $old_timeout
catch "expect_after"
return 0
}
eof {
perror "eof from rlogin $hostname -l root"
stop_root_shell
set timeout $old_timeout
catch "expect_after"
return 0
}
}
# Make sure the root shell is using /bin/sh.
send "$BINSH\r"
expect {
-re "$ROOT_PROMPT" { }
}
# Set up a shell variable tmppwd. The callers use this to keep
# command line lengths down. The command line length is important
# because we are feeding input to a shell via a pty. On some
# systems a pty will only accept 255 characters.
send "tmppwd=$tmppwd\r"
expect {
-re "$ROOT_PROMPT" { }
}
# Set up our krb5.conf
send "KRB5_CONFIG=$tmppwd/krb5.server.conf\r"
expect {
-re "$ROOT_PROMPT" { }
}
send "export KRB5_CONFIG\r"
expect {
-re "$ROOT_PROMPT" { }
}
# For all of our runtime environment variables - send them over...
foreach i $krb5_init_vars {
regexp "^(\[^=\]*)=(.*)" $i foo evar evalue
send "$evar=$env($evar)\r"
expect {
-re "$ROOT_PROMPT" { }
}
send "export $evar\r"
expect {
-re "$ROOT_PROMPT" { }
}
}
# Move over to the right directory.
set dir [pwd]
send "cd $dir\r"
expect {
-re "$ROOT_PROMPT" { }
"$dir:" {
perror "root shell can not cd to $dir"
set timeout $old_timeout
stop_root_shell
return 0
}
}
expect_after
set timeout $old_timeout
return 1
}
proc setup_root_shell_noremote { testname } {
global BINSH
global ROOT_PROMPT
global KEY
global hostname
global rlogin_spawn_id
global rlogin_pid
global tmppwd
global env
global krb5_init_vars
eval spawn $BINSH
set rlogin_spawn_id $spawn_id
set rlogin_pid [exp_pid]
expect_after {
timeout {
perror "timeout from root shell"
stop_root_shell
catch "expect_after"
return 0
}
eof {
perror "eof from root shell"
stop_root_shell
catch "expect_after"
return 0
}
}
expect {
-re "$ROOT_PROMPT" { }
}
# Set up a shell variable tmppwd. The callers use this to keep
# command line lengths down. The command line length is important
# because we are feeding input to a shell via a pty. On some
# systems a pty will only accept 255 characters.
send "tmppwd=$tmppwd\r"
expect {
-re "$ROOT_PROMPT" { }
}
# Set up our krb5.conf
send "KRB5_CONFIG=$tmppwd/krb5.server.conf\r"
expect {
-re "$ROOT_PROMPT" { }
}
send "export KRB5_CONFIG\r"
expect {
-re "$ROOT_PROMPT" { }
}
# For all of our runtime environment variables - send them over...
foreach i $krb5_init_vars {
regexp "^(\[^=\]*)=(.*)" $i foo evar evalue
send "$evar=$env($evar)\r"
expect {
-re "$ROOT_PROMPT" { }
}
send "export $evar\r"
expect {
-re "$ROOT_PROMPT" { }
}
}
# Move over to the right directory.
set dir [pwd]
send "cd $dir\r"
expect {
-re "$ROOT_PROMPT" { }
"$dir:" {
perror "root shell can not cd to $dir"
stop_root_shell
return 0
}
}
expect_after
return 1
}
# Kill off a root shell started by setup_root_shell.
proc stop_root_shell { } {
global rlogin_spawn_id
global rlogin_pid
catch "close -i $rlogin_spawn_id"
catch "exec kill $rlogin_pid"
sleep 1
catch "exec kill -9 $rlogin_pid"
catch "wait -i $rlogin_spawn_id"
}
# Check the date. The string will be the output of date on this
# system, and we must make sure that it is in the same timezone as the
# output of date run a second time. The first date will be run on an
# rlogin or some such connection to the local system. This is to test
# to make sure that the TZ environment variable is handled correctly.
# Returns 1 on sucess, 0 on failure.
proc check_date { date } {
catch "exec date" ndate
set atz ""
set ntz ""
scan $date "%s %s %d %d:%d:%d %s %d" adow amon adom ahr amn asc atz ayr
scan $ndate "%s %s %d %d:%d:%d %s %d" ndow nmon ndom nhr nmn nsc ntz nyr
if { $atz != $ntz } {
verbose -log "date check failed: $atz != $ntz"
return 0
}
return 1
}
proc touch { file } {
set f [open $file "a"]
puts $f ""
close $f
}
# Implement this in tcl someday?
proc tail1 { file } {
exec tail -1 $file
}
# setup_wrapper
# Sets up a wraper script to set the runtime shared library environment
# variables and then executes a specific command. This is used to allow
# a "rsh klist" or telnetd to execute login.krb5.
proc setup_wrapper { file command } {
global BINSH
global env
global krb5_init_vars
# We will start with a BINSH script
catch "exec rm -f $file"
set f [open $file "w" 0777]
puts $f "#!$BINSH"
puts $f "KRB5_CONFIG=$env(KRB5_CONFIG)"
puts $f "export KRB5_CONFIG"
foreach i $krb5_init_vars {
regexp "^(\[^=\]*)=(.*)" $i foo evar evalue
puts $f "$evar=$env($evar)"
puts $f "export $evar"
}
puts $f "exec $command"
close $f
return 1
}
proc krb_exit { } {
stop_kerberos_daemons
}
# helpful sometimes for debugging the test suite
proc spawn_xterm { } {
global env
foreach i {KDB5_UTIL KRB5KDC KADMIND KADMIN KADMIN_LOCAL KINIT KTUTIL KLIST} {
global $i
set env($i) [set $i]
}
exec "xterm"
}
|