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
|
/*
Unix SMB/CIFS implementation.
test suite for various lock operations
Copyright (C) Andrew Tridgell 2003
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "includes.h"
#include "torture/torture.h"
#include "libcli/raw/libcliraw.h"
#include "libcli/raw/raw_proto.h"
#include "system/time.h"
#include "system/filesys.h"
#include "libcli/libcli.h"
#include "torture/util.h"
#include "libcli/composite/composite.h"
#include "libcli/smb_composite/smb_composite.h"
#include "lib/cmdline/cmdline.h"
#include "param/param.h"
#include "torture/raw/proto.h"
#define CHECK_STATUS(status, correct) do { \
if (!NT_STATUS_EQUAL(status, correct)) { \
torture_result(tctx, TORTURE_FAIL, \
"(%s) Incorrect status %s - should be %s\n", \
__location__, nt_errstr(status), nt_errstr(correct)); \
ret = false; \
goto done; \
}} while (0)
#define CHECK_STATUS_CONT(status, correct) do { \
if (!NT_STATUS_EQUAL(status, correct)) { \
torture_result(tctx, TORTURE_FAIL, \
"(%s) Incorrect status %s - should be %s\n", \
__location__, nt_errstr(status), nt_errstr(correct)); \
ret = false; \
}} while (0)
#define CHECK_STATUS_OR(status, correct1, correct2) do { \
if ((!NT_STATUS_EQUAL(status, correct1)) && \
(!NT_STATUS_EQUAL(status, correct2))) { \
torture_result(tctx, TORTURE_FAIL, \
"(%s) Incorrect status %s - should be %s or %s\n", \
__location__, nt_errstr(status), nt_errstr(correct1), \
nt_errstr(correct2)); \
ret = false; \
goto done; \
}} while (0)
#define CHECK_STATUS_OR_CONT(status, correct1, correct2) do { \
if ((!NT_STATUS_EQUAL(status, correct1)) && \
(!NT_STATUS_EQUAL(status, correct2))) { \
torture_result(tctx, TORTURE_FAIL, \
"(%s) Incorrect status %s - should be %s or %s\n", \
__location__, nt_errstr(status), nt_errstr(correct1), \
nt_errstr(correct2)); \
ret = false; \
}} while (0)
#define BASEDIR "\\testlock"
#define TARGET_IS_W2K8(_tctx) (torture_setting_bool(_tctx, "w2k8", false))
#define TARGET_IS_WIN7(_tctx) (torture_setting_bool(_tctx, "win7", false))
#define TARGET_IS_WINDOWS(_tctx) \
((torture_setting_bool(_tctx, "w2k3", false)) || \
(torture_setting_bool(_tctx, "w2k8", false)) || \
(torture_setting_bool(_tctx, "win7", false)))
#define TARGET_IS_SAMBA3(_tctx) (torture_setting_bool(_tctx, "samba3", false))
#define TARGET_IS_SAMBA4(_tctx) (torture_setting_bool(_tctx, "samba4", false))
#define TARGET_SUPPORTS_INVALID_LOCK_RANGE(_tctx) \
(torture_setting_bool(_tctx, "invalid_lock_range_support", true))
#define TARGET_SUPPORTS_SMBEXIT(_tctx) \
(torture_setting_bool(_tctx, "smbexit_pdu_support", true))
#define TARGET_SUPPORTS_SMBLOCK(_tctx) \
(torture_setting_bool(_tctx, "smblock_pdu_support", true))
#define TARGET_SUPPORTS_OPENX_DENY_DOS(_tctx) \
(torture_setting_bool(_tctx, "openx_deny_dos_support", true))
#define TARGET_RETURNS_RANGE_NOT_LOCKED(_tctx) \
(torture_setting_bool(_tctx, "range_not_locked_on_file_close", true))
/*
test SMBlock and SMBunlock ops
*/
static bool test_lock(struct torture_context *tctx, struct smbcli_state *cli)
{
union smb_lock io;
NTSTATUS status;
bool ret = true;
int fnum;
const char *fname = BASEDIR "\\test.txt";
if (!TARGET_SUPPORTS_SMBLOCK(tctx))
torture_skip(tctx, "Target does not support the SMBlock PDU");
torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
torture_comment(tctx, "Testing RAW_LOCK_LOCK\n");
io.generic.level = RAW_LOCK_LOCK;
fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
torture_assert(tctx,(fnum != -1), talloc_asprintf(tctx,
"Failed to create %s - %s\n",
fname, smbcli_errstr(cli->tree)));
torture_comment(tctx, "Trying 0/0 lock\n");
io.lock.level = RAW_LOCK_LOCK;
io.lock.in.file.fnum = fnum;
io.lock.in.count = 0;
io.lock.in.offset = 0;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
cli->session->pid++;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
cli->session->pid--;
io.lock.level = RAW_LOCK_UNLOCK;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
torture_comment(tctx, "Trying 0/1 lock\n");
io.lock.level = RAW_LOCK_LOCK;
io.lock.in.file.fnum = fnum;
io.lock.in.count = 1;
io.lock.in.offset = 0;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
cli->session->pid++;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
cli->session->pid--;
io.lock.level = RAW_LOCK_UNLOCK;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
io.lock.level = RAW_LOCK_UNLOCK;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
torture_comment(tctx, "Trying 0xEEFFFFFF lock\n");
io.lock.level = RAW_LOCK_LOCK;
io.lock.in.file.fnum = fnum;
io.lock.in.count = 4000;
io.lock.in.offset = 0xEEFFFFFF;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
cli->session->pid++;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
cli->session->pid--;
io.lock.level = RAW_LOCK_UNLOCK;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
io.lock.level = RAW_LOCK_UNLOCK;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
torture_comment(tctx, "Trying 0xEEFFFFFF lock\n");
io.lock.level = RAW_LOCK_LOCK;
io.lock.in.file.fnum = fnum;
io.lock.in.count = 4000;
io.lock.in.offset = 0xEEFFFFFF;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
cli->session->pid++;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
cli->session->pid--;
io.lock.level = RAW_LOCK_UNLOCK;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
io.lock.level = RAW_LOCK_UNLOCK;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
torture_comment(tctx, "Trying max lock\n");
io.lock.level = RAW_LOCK_LOCK;
io.lock.in.file.fnum = fnum;
io.lock.in.count = 4000;
io.lock.in.offset = 0xEF000000;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
cli->session->pid++;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
cli->session->pid--;
io.lock.level = RAW_LOCK_UNLOCK;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
io.lock.level = RAW_LOCK_UNLOCK;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
torture_comment(tctx, "Trying wrong pid unlock\n");
io.lock.level = RAW_LOCK_LOCK;
io.lock.in.file.fnum = fnum;
io.lock.in.count = 4002;
io.lock.in.offset = 10001;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
cli->session->pid++;
io.lock.level = RAW_LOCK_UNLOCK;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
cli->session->pid--;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
done:
smbcli_close(cli->tree, fnum);
smb_raw_exit(cli->session);
smbcli_deltree(cli->tree, BASEDIR);
return ret;
}
/*
test locking&X ops
*/
static bool test_lockx(struct torture_context *tctx, struct smbcli_state *cli)
{
union smb_lock io;
struct smb_lock_entry lock[1];
NTSTATUS status;
bool ret = true;
int fnum;
const char *fname = BASEDIR "\\test.txt";
torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
torture_comment(tctx, "Testing RAW_LOCK_LOCKX\n");
io.generic.level = RAW_LOCK_LOCKX;
fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
torture_assert(tctx,(fnum != -1), talloc_asprintf(tctx,
"Failed to create %s - %s\n",
fname, smbcli_errstr(cli->tree)));
io.lockx.level = RAW_LOCK_LOCKX;
io.lockx.in.file.fnum = fnum;
io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
io.lockx.in.timeout = 0;
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
lock[0].pid = cli->session->pid;
lock[0].offset = 10;
lock[0].count = 1;
io.lockx.in.locks = &lock[0];
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
torture_comment(tctx, "Trying 0xEEFFFFFF lock\n");
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
lock[0].count = 4000;
lock[0].offset = 0xEEFFFFFF;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
lock[0].pid++;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
lock[0].pid--;
io.lockx.in.ulock_cnt = 1;
io.lockx.in.lock_cnt = 0;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
torture_comment(tctx, "Trying 0xEF000000 lock\n");
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
lock[0].count = 4000;
lock[0].offset = 0xEF000000;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
lock[0].pid++;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
lock[0].pid--;
io.lockx.in.ulock_cnt = 1;
io.lockx.in.lock_cnt = 0;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
torture_comment(tctx, "Trying zero lock\n");
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
lock[0].count = 0;
lock[0].offset = ~0;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
lock[0].pid++;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
lock[0].pid--;
io.lockx.in.ulock_cnt = 1;
io.lockx.in.lock_cnt = 0;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
torture_comment(tctx, "Trying max lock\n");
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
lock[0].count = 0;
lock[0].offset = ~0;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
lock[0].pid++;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
lock[0].pid--;
io.lockx.in.ulock_cnt = 1;
io.lockx.in.lock_cnt = 0;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
torture_comment(tctx, "Trying 2^63\n");
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
lock[0].count = 1;
lock[0].offset = 1;
lock[0].offset <<= 63;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
lock[0].pid++;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
lock[0].pid--;
io.lockx.in.ulock_cnt = 1;
io.lockx.in.lock_cnt = 0;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
torture_comment(tctx, "Trying 2^63 - 1\n");
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
lock[0].count = 1;
lock[0].offset = 1;
lock[0].offset <<= 63;
lock[0].offset--;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
lock[0].pid++;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
lock[0].pid--;
io.lockx.in.ulock_cnt = 1;
io.lockx.in.lock_cnt = 0;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
torture_comment(tctx, "Trying max lock 2\n");
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
lock[0].count = 1;
lock[0].offset = ~0;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
lock[0].pid++;
lock[0].count = 2;
status = smb_raw_lock(cli->tree, &io);
if (TARGET_SUPPORTS_INVALID_LOCK_RANGE(tctx))
CHECK_STATUS(status, NT_STATUS_INVALID_LOCK_RANGE);
else
CHECK_STATUS(status, NT_STATUS_OK);
lock[0].pid--;
io.lockx.in.ulock_cnt = 1;
io.lockx.in.lock_cnt = 0;
lock[0].count = 1;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
done:
smbcli_close(cli->tree, fnum);
smb_raw_exit(cli->session);
smbcli_deltree(cli->tree, BASEDIR);
return ret;
}
/*
test high pid
*/
static bool test_pidhigh(struct torture_context *tctx,
struct smbcli_state *cli)
{
union smb_lock io;
struct smb_lock_entry lock[1];
NTSTATUS status;
bool ret = true;
int fnum;
const char *fname = BASEDIR "\\test.txt";
uint8_t c = 1;
torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
torture_comment(tctx, "Testing high pid\n");
io.generic.level = RAW_LOCK_LOCKX;
cli->session->pid = 1;
fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
torture_assert(tctx,(fnum != -1), talloc_asprintf(tctx,
"Failed to create %s - %s\n",
fname, smbcli_errstr(cli->tree)));
if (smbcli_write(cli->tree, fnum, 0, &c, 0, 1) != 1) {
torture_result(tctx, TORTURE_FAIL,
"Failed to write 1 byte - %s\n",
smbcli_errstr(cli->tree));
ret = false;
goto done;
}
io.lockx.level = RAW_LOCK_LOCKX;
io.lockx.in.file.fnum = fnum;
io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
io.lockx.in.timeout = 0;
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
lock[0].pid = cli->session->pid;
lock[0].offset = 0;
lock[0].count = 0xFFFFFFFF;
io.lockx.in.locks = &lock[0];
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
if (smbcli_read(cli->tree, fnum, &c, 0, 1) != 1) {
torture_result(tctx, TORTURE_FAIL,
"Failed to read 1 byte - %s\n",
smbcli_errstr(cli->tree));
ret = false;
goto done;
}
cli->session->pid = 2;
if (smbcli_read(cli->tree, fnum, &c, 0, 1) == 1) {
torture_result(tctx, TORTURE_FAIL,
"pid is incorrect handled for read with lock!\n");
ret = false;
goto done;
}
cli->session->pid = 0x10001;
if (smbcli_read(cli->tree, fnum, &c, 0, 1) != 1) {
torture_result(tctx, TORTURE_FAIL,
"High pid is used on this server!\n");
ret = false;
} else {
torture_warning(tctx, "High pid is not used on this server (correct)\n");
}
done:
smbcli_close(cli->tree, fnum);
smb_raw_exit(cli->session);
smbcli_deltree(cli->tree, BASEDIR);
return ret;
}
/*
test locking&X async operation
*/
static bool test_async(struct torture_context *tctx,
struct smbcli_state *cli)
{
struct smbcli_session *session;
struct smb_composite_sesssetup setup;
struct smbcli_tree *tree;
union smb_tcon tcon;
const char *host, *share;
union smb_lock io;
struct smb_lock_entry lock[2];
NTSTATUS status;
bool ret = true;
int fnum;
const char *fname = BASEDIR "\\test.txt";
time_t t;
struct smbcli_request *req, *req2;
struct smbcli_session_options options;
torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
lpcfg_smbcli_session_options(tctx->lp_ctx, &options);
torture_comment(tctx, "Testing LOCKING_ANDX_CANCEL_LOCK\n");
io.generic.level = RAW_LOCK_LOCKX;
fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
torture_assert(tctx,(fnum != -1), talloc_asprintf(tctx,
"Failed to create %s - %s\n",
fname, smbcli_errstr(cli->tree)));
io.lockx.level = RAW_LOCK_LOCKX;
io.lockx.in.file.fnum = fnum;
io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
io.lockx.in.timeout = 0;
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
lock[0].pid = cli->session->pid;
lock[0].offset = 100;
lock[0].count = 10;
lock[1].pid = cli->session->pid;
lock[1].offset = 110;
lock[1].count = 10;
io.lockx.in.locks = &lock[0];
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
t = time_mono(NULL);
torture_comment(tctx, "Testing cancel by CANCEL_LOCK\n");
/* setup a timed lock */
io.lockx.in.timeout = 10000;
req = smb_raw_lock_send(cli->tree, &io);
torture_assert(tctx,(req != NULL), talloc_asprintf(tctx,
"Failed to setup timed lock (%s)\n", __location__));
/* cancel the wrong range */
lock[0].offset = 0;
io.lockx.in.timeout = 0;
io.lockx.in.mode = LOCKING_ANDX_CANCEL_LOCK;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_DOS(ERRDOS, ERRcancelviolation));
/* cancel with the wrong bits set */
lock[0].offset = 100;
io.lockx.in.timeout = 0;
io.lockx.in.mode = LOCKING_ANDX_CANCEL_LOCK;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_DOS(ERRDOS, ERRcancelviolation));
/* cancel the right range */
lock[0].offset = 100;
io.lockx.in.timeout = 0;
io.lockx.in.mode = LOCKING_ANDX_CANCEL_LOCK | LOCKING_ANDX_LARGE_FILES;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
/* receive the failed lock request */
status = smbcli_request_simple_recv(req);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
torture_assert(tctx,!(time_mono(NULL) > t+2), talloc_asprintf(tctx,
"lock cancel was not immediate (%s)\n", __location__));
/* MS-CIFS (2.2.4.32.1) states that a cancel is honored if and only
* if the lock vector contains one entry. When given multiple cancel
* requests in a single PDU we expect the server to return an
* error. Samba4 handles this correctly. Windows servers seem to
* accept the request but only cancel the first lock. Samba3
* now does what Windows does (JRA).
*/
torture_comment(tctx, "Testing multiple cancel\n");
/* acquire second lock */
io.lockx.in.timeout = 0;
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
io.lockx.in.locks = &lock[1];
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
/* setup 2 timed locks */
t = time_mono(NULL);
io.lockx.in.timeout = 10000;
io.lockx.in.lock_cnt = 1;
io.lockx.in.locks = &lock[0];
req = smb_raw_lock_send(cli->tree, &io);
torture_assert(tctx,(req != NULL), talloc_asprintf(tctx,
"Failed to setup timed lock (%s)\n", __location__));
io.lockx.in.locks = &lock[1];
req2 = smb_raw_lock_send(cli->tree, &io);
torture_assert(tctx,(req2 != NULL), talloc_asprintf(tctx,
"Failed to setup timed lock (%s)\n", __location__));
/* try to cancel both locks in the same packet */
io.lockx.in.timeout = 0;
io.lockx.in.lock_cnt = 2;
io.lockx.in.mode = LOCKING_ANDX_CANCEL_LOCK | LOCKING_ANDX_LARGE_FILES;
io.lockx.in.locks = lock;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
torture_warning(tctx, "Target server accepted a lock cancel "
"request with multiple locks. This violates "
"MS-CIFS 2.2.4.32.1.\n");
/* receive the failed lock requests */
status = smbcli_request_simple_recv(req);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
torture_assert(tctx,!(time_mono(NULL) > t+2), talloc_asprintf(tctx,
"first lock was not cancelled immediately (%s)\n",
__location__));
/* send cancel to second lock */
io.lockx.in.timeout = 0;
io.lockx.in.lock_cnt = 1;
io.lockx.in.mode = LOCKING_ANDX_CANCEL_LOCK |
LOCKING_ANDX_LARGE_FILES;
io.lockx.in.locks = &lock[1];
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
status = smbcli_request_simple_recv(req2);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
torture_assert(tctx,!(time_mono(NULL) > t+2), talloc_asprintf(tctx,
"second lock was not cancelled immediately (%s)\n",
__location__));
/* cleanup the second lock */
io.lockx.in.ulock_cnt = 1;
io.lockx.in.lock_cnt = 0;
io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
io.lockx.in.locks = &lock[1];
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
/* If a lock request contained multiple ranges and we are cancelling
* one while it's still pending, what happens? */
torture_comment(tctx, "Testing cancel 1/2 lock request\n");
/* Send request with two ranges */
io.lockx.in.timeout = -1;
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 2;
io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
io.lockx.in.locks = lock;
req = smb_raw_lock_send(cli->tree, &io);
torture_assert(tctx,(req != NULL), talloc_asprintf(tctx,
"Failed to setup pending lock (%s)\n", __location__));
/* Try to cancel the first lock range */
io.lockx.in.timeout = 0;
io.lockx.in.lock_cnt = 1;
io.lockx.in.mode = LOCKING_ANDX_CANCEL_LOCK | LOCKING_ANDX_LARGE_FILES;
io.lockx.in.locks = &lock[0];
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
/* Locking request should've failed and second range should be
* unlocked */
status = smbcli_request_simple_recv(req);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
io.lockx.in.timeout = 0;
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
io.lockx.in.locks = &lock[1];
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
/* Cleanup both locks */
io.lockx.in.ulock_cnt = 2;
io.lockx.in.lock_cnt = 0;
io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
io.lockx.in.locks = lock;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
torture_comment(tctx, "Testing cancel 2/2 lock request\n");
/* Lock second range so it contends */
io.lockx.in.timeout = 0;
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
io.lockx.in.locks = &lock[1];
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
/* Send request with two ranges */
io.lockx.in.timeout = -1;
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 2;
io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
io.lockx.in.locks = lock;
req = smb_raw_lock_send(cli->tree, &io);
torture_assert(tctx,(req != NULL), talloc_asprintf(tctx,
"Failed to setup pending lock (%s)\n", __location__));
/* Try to cancel the second lock range */
io.lockx.in.timeout = 0;
io.lockx.in.lock_cnt = 1;
io.lockx.in.mode = LOCKING_ANDX_CANCEL_LOCK | LOCKING_ANDX_LARGE_FILES;
io.lockx.in.locks = &lock[1];
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
/* Locking request should've failed and first range should be
* unlocked */
status = smbcli_request_simple_recv(req);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
io.lockx.in.timeout = 0;
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
io.lockx.in.locks = &lock[0];
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
/* Cleanup both locks */
io.lockx.in.ulock_cnt = 2;
io.lockx.in.lock_cnt = 0;
io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
io.lockx.in.locks = lock;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
torture_comment(tctx, "Testing cancel by unlock\n");
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
io.lockx.in.timeout = 0;
io.lockx.in.locks = &lock[0];
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
io.lockx.in.timeout = 5000;
req = smb_raw_lock_send(cli->tree, &io);
torture_assert(tctx,(req != NULL), talloc_asprintf(tctx,
"Failed to setup timed lock (%s)\n", __location__));
io.lockx.in.ulock_cnt = 1;
io.lockx.in.lock_cnt = 0;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
t = time_mono(NULL);
status = smbcli_request_simple_recv(req);
CHECK_STATUS(status, NT_STATUS_OK);
torture_assert(tctx,!(time_mono(NULL) > t+2), talloc_asprintf(tctx,
"lock cancel by unlock was not immediate (%s) - took %d secs\n",
__location__, (int)(time_mono(NULL)-t)));
torture_comment(tctx, "Testing cancel by close\n");
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
io.lockx.in.timeout = 0;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
{
/*
* Make the test block on the second lock
* request. This is to regression-test 64c0367.
*/
uint64_t tmp = lock[1].offset;
lock[1].offset = lock[0].offset;
lock[0].offset = tmp;
}
t = time_mono(NULL);
io.lockx.in.timeout = 10000;
io.lockx.in.lock_cnt = 2;
req = smb_raw_lock_send(cli->tree, &io);
torture_assert(tctx,(req != NULL), talloc_asprintf(tctx,
"Failed to setup timed lock (%s)\n", __location__));
status = smbcli_close(cli->tree, fnum);
CHECK_STATUS(status, NT_STATUS_OK);
status = smbcli_request_simple_recv(req);
if (TARGET_RETURNS_RANGE_NOT_LOCKED(tctx))
CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
else
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
torture_assert(tctx,!(time_mono(NULL) > t+2), talloc_asprintf(tctx,
"lock cancel by close was not immediate (%s)\n", __location__));
{
/*
* Undo the change for 64c0367
*/
uint64_t tmp = lock[1].offset;
lock[1].offset = lock[0].offset;
lock[0].offset = tmp;
}
torture_comment(tctx, "create a new sessions\n");
session = smbcli_session_init(cli->transport, tctx, false, options);
setup.in.sesskey = cli->transport->negotiate.sesskey;
setup.in.capabilities = cli->transport->negotiate.capabilities;
setup.in.workgroup = lpcfg_workgroup(tctx->lp_ctx);
setup.in.credentials = samba_cmdline_get_creds();
setup.in.gensec_settings = lpcfg_gensec_settings(tctx, tctx->lp_ctx);
status = smb_composite_sesssetup(session, &setup);
CHECK_STATUS(status, NT_STATUS_OK);
session->vuid = setup.out.vuid;
torture_comment(tctx, "create new tree context\n");
share = torture_setting_string(tctx, "share", NULL);
host = torture_setting_string(tctx, "host", NULL);
tree = smbcli_tree_init(session, tctx, false);
tcon.generic.level = RAW_TCON_TCONX;
tcon.tconx.in.flags = TCONX_FLAG_EXTENDED_RESPONSE;
tcon.tconx.in.password = data_blob(NULL, 0);
tcon.tconx.in.path = talloc_asprintf(tctx, "\\\\%s\\%s", host, share);
tcon.tconx.in.device = "A:";
status = smb_raw_tcon(tree, tctx, &tcon);
CHECK_STATUS(status, NT_STATUS_OK);
tree->tid = tcon.tconx.out.tid;
torture_comment(tctx, "Testing cancel by exit\n");
if (TARGET_SUPPORTS_SMBEXIT(tctx)) {
fname = BASEDIR "\\test_exit.txt";
fnum = smbcli_open(tree, fname, O_RDWR|O_CREAT, DENY_NONE);
torture_assert(tctx,(fnum != -1), talloc_asprintf(tctx,
"Failed to reopen %s - %s\n",
fname, smbcli_errstr(tree)));
io.lockx.level = RAW_LOCK_LOCKX;
io.lockx.in.file.fnum = fnum;
io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
io.lockx.in.timeout = 0;
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
lock[0].pid = session->pid;
lock[0].offset = 100;
lock[0].count = 10;
io.lockx.in.locks = &lock[0];
status = smb_raw_lock(tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
io.lockx.in.timeout = 0;
status = smb_raw_lock(tree, &io);
CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
io.lockx.in.timeout = 10000;
t = time_mono(NULL);
req = smb_raw_lock_send(tree, &io);
torture_assert(tctx,(req != NULL), talloc_asprintf(tctx,
"Failed to setup timed lock (%s)\n",
__location__));
status = smb_raw_exit(session);
CHECK_STATUS(status, NT_STATUS_OK);
status = smbcli_request_simple_recv(req);
if (TARGET_RETURNS_RANGE_NOT_LOCKED(tctx))
CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
else
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
torture_assert(tctx,!(time_mono(NULL) > t+2), talloc_asprintf(tctx,
"lock cancel by exit was not immediate (%s)\n",
__location__));
}
else {
torture_comment(tctx,
" skipping test, SMBExit not supported\n");
}
torture_comment(tctx, "Testing cancel by ulogoff\n");
fname = BASEDIR "\\test_ulogoff.txt";
fnum = smbcli_open(tree, fname, O_RDWR|O_CREAT, DENY_NONE);
torture_assert(tctx,(fnum != -1), talloc_asprintf(tctx,
"Failed to reopen %s - %s\n",
fname, smbcli_errstr(tree)));
io.lockx.level = RAW_LOCK_LOCKX;
io.lockx.in.file.fnum = fnum;
io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
io.lockx.in.timeout = 0;
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
lock[0].pid = session->pid;
lock[0].offset = 100;
lock[0].count = 10;
io.lockx.in.locks = &lock[0];
status = smb_raw_lock(tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
io.lockx.in.timeout = 0;
status = smb_raw_lock(tree, &io);
CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
io.lockx.in.timeout = 10000;
t = time_mono(NULL);
req = smb_raw_lock_send(tree, &io);
torture_assert(tctx,(req != NULL), talloc_asprintf(tctx,
"Failed to setup timed lock (%s)\n", __location__));
status = smb_raw_ulogoff(session);
CHECK_STATUS(status, NT_STATUS_OK);
status = smbcli_request_simple_recv(req);
if (TARGET_RETURNS_RANGE_NOT_LOCKED(tctx)) {
if (NT_STATUS_EQUAL(NT_STATUS_FILE_LOCK_CONFLICT, status)) {
torture_result(tctx, TORTURE_FAIL,
"lock not canceled by ulogoff - %s "
"(ignored because of vfs_vifs fails it)\n",
nt_errstr(status));
smb_tree_disconnect(tree);
smb_raw_exit(session);
goto done;
}
CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
} else {
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
}
torture_assert(tctx,!(time_mono(NULL) > t+2), talloc_asprintf(tctx,
"lock cancel by ulogoff was not immediate (%s)\n", __location__));
torture_comment(tctx, "Testing cancel by tdis\n");
tree->session = cli->session;
fname = BASEDIR "\\test_tdis.txt";
fnum = smbcli_open(tree, fname, O_RDWR|O_CREAT, DENY_NONE);
torture_assert(tctx,(fnum != -1), talloc_asprintf(tctx,
"Failed to reopen %s - %s\n",
fname, smbcli_errstr(tree)));
io.lockx.level = RAW_LOCK_LOCKX;
io.lockx.in.file.fnum = fnum;
io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
io.lockx.in.timeout = 0;
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
lock[0].pid = cli->session->pid;
lock[0].offset = 100;
lock[0].count = 10;
io.lockx.in.locks = &lock[0];
status = smb_raw_lock(tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
status = smb_raw_lock(tree, &io);
CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
io.lockx.in.timeout = 10000;
t = time_mono(NULL);
req = smb_raw_lock_send(tree, &io);
torture_assert(tctx,(req != NULL), talloc_asprintf(tctx,
"Failed to setup timed lock (%s)\n", __location__));
status = smb_tree_disconnect(tree);
CHECK_STATUS(status, NT_STATUS_OK);
status = smbcli_request_simple_recv(req);
if (TARGET_RETURNS_RANGE_NOT_LOCKED(tctx))
CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
else
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
torture_assert(tctx,!(time_mono(NULL) > t+2), talloc_asprintf(tctx,
"lock cancel by tdis was not immediate (%s)\n", __location__));
done:
smb_raw_exit(cli->session);
smbcli_deltree(cli->tree, BASEDIR);
return ret;
}
/*
test NT_STATUS_LOCK_NOT_GRANTED vs. NT_STATUS_FILE_LOCK_CONFLICT
*/
static bool test_errorcode(struct torture_context *tctx,
struct smbcli_state *cli)
{
union smb_lock io;
union smb_open op;
struct smb_lock_entry lock[2];
NTSTATUS status;
bool ret = true;
int fnum, fnum2;
const char *fname;
struct smbcli_request *req;
time_t start;
int t;
int delay;
uint16_t deny_mode = 0;
torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
torture_comment(tctx, "Testing LOCK_NOT_GRANTED vs. FILE_LOCK_CONFLICT\n");
torture_comment(tctx, "Testing with timeout = 0\n");
fname = BASEDIR "\\test0.txt";
t = 0;
/*
* the first run is with t = 0,
* the second with t > 0 (=1)
*/
next_run:
/*
* use the DENY_DOS mode, that creates two fnum's of one low-level
* file handle, this demonstrates that the cache is per fnum, not
* per file handle
*/
if (TARGET_SUPPORTS_OPENX_DENY_DOS(tctx))
deny_mode = OPENX_MODE_DENY_DOS;
else
deny_mode = OPENX_MODE_DENY_NONE;
op.openx.level = RAW_OPEN_OPENX;
op.openx.in.fname = fname;
op.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
op.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR | deny_mode;
op.openx.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
op.openx.in.search_attrs = 0;
op.openx.in.file_attrs = 0;
op.openx.in.write_time = 0;
op.openx.in.size = 0;
op.openx.in.timeout = 0;
status = smb_raw_open(cli->tree, tctx, &op);
CHECK_STATUS(status, NT_STATUS_OK);
fnum = op.openx.out.file.fnum;
status = smb_raw_open(cli->tree, tctx, &op);
CHECK_STATUS(status, NT_STATUS_OK);
fnum2 = op.openx.out.file.fnum;
io.lockx.level = RAW_LOCK_LOCKX;
io.lockx.in.file.fnum = fnum;
io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
io.lockx.in.timeout = t;
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
lock[0].pid = cli->session->pid;
lock[0].offset = 100;
lock[0].count = 10;
io.lockx.in.locks = &lock[0];
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
/*
* demonstrate that the first conflicting lock on each handle give LOCK_NOT_GRANTED
* this also demonstrates that the error code cache is per file handle
* (LOCK_NOT_GRANTED is only be used when timeout is 0!)
*/
io.lockx.in.file.fnum = fnum2;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
io.lockx.in.file.fnum = fnum;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
/* demonstrate that each following conflict gives FILE_LOCK_CONFLICT */
io.lockx.in.file.fnum = fnum;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
io.lockx.in.file.fnum = fnum2;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
io.lockx.in.file.fnum = fnum;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
io.lockx.in.file.fnum = fnum2;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
/* demonstrate that the smbpid doesn't matter */
lock[0].pid++;
io.lockx.in.file.fnum = fnum;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
io.lockx.in.file.fnum = fnum2;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
lock[0].pid--;
/*
* demonstrate the a successful lock with count = 0 and the same offset,
* doesn't reset the error cache
*/
lock[0].offset = 100;
lock[0].count = 0;
io.lockx.in.file.fnum = fnum;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
io.lockx.in.file.fnum = fnum2;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
lock[0].offset = 100;
lock[0].count = 10;
io.lockx.in.file.fnum = fnum;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
io.lockx.in.file.fnum = fnum2;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
/*
* demonstrate the a successful lock with count = 0 and outside the locked range,
* doesn't reset the error cache
*/
lock[0].offset = 110;
lock[0].count = 0;
io.lockx.in.file.fnum = fnum;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
io.lockx.in.file.fnum = fnum2;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
lock[0].offset = 100;
lock[0].count = 10;
io.lockx.in.file.fnum = fnum;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
io.lockx.in.file.fnum = fnum2;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
lock[0].offset = 99;
lock[0].count = 0;
io.lockx.in.file.fnum = fnum;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
io.lockx.in.file.fnum = fnum2;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
lock[0].offset = 100;
lock[0].count = 10;
io.lockx.in.file.fnum = fnum;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
io.lockx.in.file.fnum = fnum2;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
/* demonstrate that a changing count doesn't reset the error cache */
lock[0].offset = 100;
lock[0].count = 5;
io.lockx.in.file.fnum = fnum;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
io.lockx.in.file.fnum = fnum2;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
lock[0].offset = 100;
lock[0].count = 15;
io.lockx.in.file.fnum = fnum;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
io.lockx.in.file.fnum = fnum2;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
/*
* demonstrate the a lock with count = 0 and inside the locked range,
* fails and resets the error cache
*/
lock[0].offset = 101;
lock[0].count = 0;
io.lockx.in.file.fnum = fnum;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
io.lockx.in.file.fnum = fnum2;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
lock[0].offset = 100;
lock[0].count = 10;
io.lockx.in.file.fnum = fnum;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
io.lockx.in.file.fnum = fnum2;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
/* demonstrate the a changing offset, resets the error cache */
lock[0].offset = 105;
lock[0].count = 10;
io.lockx.in.file.fnum = fnum;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
io.lockx.in.file.fnum = fnum2;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
lock[0].offset = 100;
lock[0].count = 10;
io.lockx.in.file.fnum = fnum;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
io.lockx.in.file.fnum = fnum2;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
lock[0].offset = 95;
lock[0].count = 9;
io.lockx.in.file.fnum = fnum;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
io.lockx.in.file.fnum = fnum2;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
lock[0].offset = 100;
lock[0].count = 10;
io.lockx.in.file.fnum = fnum;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
io.lockx.in.file.fnum = fnum2;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
/*
* demonstrate the a successful lock in a different range,
* doesn't reset the cache, the failing lock on the 2nd handle
* resets the cache
*/
lock[0].offset = 120;
lock[0].count = 15;
io.lockx.in.file.fnum = fnum;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
io.lockx.in.file.fnum = fnum2;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
lock[0].offset = 100;
lock[0].count = 10;
io.lockx.in.file.fnum = fnum;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
io.lockx.in.file.fnum = fnum2;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
/* end of the loop */
if (t == 0) {
smb_raw_exit(cli->session);
t = 1;
torture_comment(tctx, "Testing with timeout > 0 (=%d)\n",
t);
fname = BASEDIR "\\test1.txt";
goto next_run;
}
t = 4000;
torture_comment(tctx, "Testing special cases with timeout > 0 (=%d)\n",
t);
/*
* the following 3 test sections demonstrate that
* the cache is only set when the error is reported
* to the client (after the timeout went by)
*/
smb_raw_exit(cli->session);
torture_comment(tctx, "Testing a conflict while a lock is pending\n");
fname = BASEDIR "\\test2.txt";
fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
torture_assert(tctx,(fnum != -1), talloc_asprintf(tctx,
"Failed to reopen %s - %s\n",
fname, smbcli_errstr(cli->tree)));
io.lockx.level = RAW_LOCK_LOCKX;
io.lockx.in.file.fnum = fnum;
io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
io.lockx.in.timeout = 0;
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
lock[0].pid = cli->session->pid;
lock[0].offset = 100;
lock[0].count = 10;
io.lockx.in.locks = &lock[0];
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
start = time_mono(NULL);
io.lockx.in.timeout = t;
req = smb_raw_lock_send(cli->tree, &io);
torture_assert(tctx,(req != NULL), talloc_asprintf(tctx,
"Failed to setup timed lock (%s)\n", __location__));
io.lockx.in.timeout = 0;
lock[0].offset = 105;
lock[0].count = 10;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
status = smbcli_request_simple_recv(req);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
delay = t / 1000;
if (TARGET_IS_W2K8(tctx) || TARGET_IS_WIN7(tctx)) {
delay /= 2;
}
torture_assert(tctx,!(time_mono(NULL) < start+delay), talloc_asprintf(tctx,
"lock comes back to early timeout[%d] delay[%d]"
"(%s)\n", t, delay, __location__));
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
smbcli_close(cli->tree, fnum);
fname = BASEDIR "\\test3.txt";
fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
torture_assert(tctx,(fnum != -1), talloc_asprintf(tctx,
"Failed to reopen %s - %s\n",
fname, smbcli_errstr(cli->tree)));
io.lockx.level = RAW_LOCK_LOCKX;
io.lockx.in.file.fnum = fnum;
io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
io.lockx.in.timeout = 0;
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
lock[0].pid = cli->session->pid;
lock[0].offset = 100;
lock[0].count = 10;
io.lockx.in.locks = &lock[0];
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
start = time_mono(NULL);
io.lockx.in.timeout = t;
req = smb_raw_lock_send(cli->tree, &io);
torture_assert(tctx,(req != NULL), talloc_asprintf(tctx,
"Failed to setup timed lock (%s)\n", __location__));
io.lockx.in.timeout = 0;
lock[0].offset = 105;
lock[0].count = 10;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
status = smbcli_request_simple_recv(req);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
delay = t / 1000;
if (TARGET_IS_W2K8(tctx) || TARGET_IS_WIN7(tctx)) {
delay /= 2;
}
torture_assert(tctx,!(time_mono(NULL) < start+delay), talloc_asprintf(tctx,
"lock comes back to early timeout[%d] delay[%d]"
"(%s)\n", t, delay, __location__));
lock[0].offset = 100;
lock[0].count = 10;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
smbcli_close(cli->tree, fnum);
fname = BASEDIR "\\test4.txt";
fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
torture_assert(tctx,(fnum != -1), talloc_asprintf(tctx,
"Failed to reopen %s - %s\n",
fname, smbcli_errstr(cli->tree)));
io.lockx.level = RAW_LOCK_LOCKX;
io.lockx.in.file.fnum = fnum;
io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
io.lockx.in.timeout = 0;
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
lock[0].pid = cli->session->pid;
lock[0].offset = 100;
lock[0].count = 10;
io.lockx.in.locks = &lock[0];
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
start = time_mono(NULL);
io.lockx.in.timeout = t;
req = smb_raw_lock_send(cli->tree, &io);
torture_assert(tctx,(req != NULL), talloc_asprintf(tctx,
"Failed to setup timed lock (%s)\n", __location__));
io.lockx.in.timeout = 0;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
status = smbcli_request_simple_recv(req);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
delay = t / 1000;
if (TARGET_IS_W2K8(tctx) || TARGET_IS_WIN7(tctx)) {
delay /= 2;
}
torture_assert(tctx,!(time_mono(NULL) < start+delay), talloc_asprintf(tctx,
"lock comes back to early timeout[%d] delay[%d]"
"(%s)\n", t, delay, __location__));
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
done:
smb_raw_exit(cli->session);
smbcli_deltree(cli->tree, BASEDIR);
return ret;
}
/*
test LOCKING_ANDX_CHANGE_LOCKTYPE
*/
static bool test_changetype(struct torture_context *tctx,
struct smbcli_state *cli)
{
union smb_lock io;
struct smb_lock_entry lock[2];
NTSTATUS status;
bool ret = true;
int fnum;
uint8_t c = 0;
const char *fname = BASEDIR "\\test.txt";
torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
torture_comment(tctx, "Testing LOCKING_ANDX_CHANGE_LOCKTYPE\n");
io.generic.level = RAW_LOCK_LOCKX;
fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
torture_assert(tctx,(fnum != -1), talloc_asprintf(tctx,
"Failed to create %s - %s\n",
fname, smbcli_errstr(cli->tree)));
io.lockx.level = RAW_LOCK_LOCKX;
io.lockx.in.file.fnum = fnum;
io.lockx.in.mode = LOCKING_ANDX_SHARED_LOCK;
io.lockx.in.timeout = 0;
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
lock[0].pid = cli->session->pid;
lock[0].offset = 100;
lock[0].count = 10;
io.lockx.in.locks = &lock[0];
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
if (smbcli_write(cli->tree, fnum, 0, &c, 100, 1) == 1) {
torture_result(tctx, TORTURE_FAIL,
"allowed write on read locked region (%s)\n", __location__);
ret = false;
goto done;
}
/* windows server don't seem to support this */
io.lockx.in.mode = LOCKING_ANDX_CHANGE_LOCKTYPE;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_DOS(ERRDOS, ERRnoatomiclocks));
if (smbcli_write(cli->tree, fnum, 0, &c, 100, 1) == 1) {
torture_result(tctx, TORTURE_FAIL,
"allowed write after lock change (%s)\n", __location__);
ret = false;
goto done;
}
done:
smbcli_close(cli->tree, fnum);
smb_raw_exit(cli->session);
smbcli_deltree(cli->tree, BASEDIR);
return ret;
}
struct double_lock_test {
struct smb_lock_entry lock1;
struct smb_lock_entry lock2;
NTSTATUS exp_status;
};
/**
* Tests zero byte locks.
*/
static struct double_lock_test zero_byte_tests[] = {
/* {pid, offset, count}, {pid, offset, count}, status */
/** First, takes a zero byte lock at offset 10. Then:
* - Taking 0 byte lock at 10 should succeed.
* - Taking 1 byte locks at 9,10,11 should succeed.
* - Taking 2 byte lock at 9 should fail.
* - Taking 2 byte lock at 10 should succeed.
* - Taking 3 byte lock at 9 should fail.
*/
{{1000, 10, 0}, {1001, 10, 0}, NT_STATUS_OK},
{{1000, 10, 0}, {1001, 9, 1}, NT_STATUS_OK},
{{1000, 10, 0}, {1001, 10, 1}, NT_STATUS_OK},
{{1000, 10, 0}, {1001, 11, 1}, NT_STATUS_OK},
{{1000, 10, 0}, {1001, 9, 2}, NT_STATUS_LOCK_NOT_GRANTED},
{{1000, 10, 0}, {1001, 10, 2}, NT_STATUS_OK},
{{1000, 10, 0}, {1001, 9, 3}, NT_STATUS_LOCK_NOT_GRANTED},
/** Same, but opposite order. */
{{1001, 10, 0}, {1000, 10, 0}, NT_STATUS_OK},
{{1001, 9, 1}, {1000, 10, 0}, NT_STATUS_OK},
{{1001, 10, 1}, {1000, 10, 0}, NT_STATUS_OK},
{{1001, 11, 1}, {1000, 10, 0}, NT_STATUS_OK},
{{1001, 9, 2}, {1000, 10, 0}, NT_STATUS_LOCK_NOT_GRANTED},
{{1001, 10, 2}, {1000, 10, 0}, NT_STATUS_OK},
{{1001, 9, 3}, {1000, 10, 0}, NT_STATUS_LOCK_NOT_GRANTED},
/** Zero zero case. */
{{1000, 0, 0}, {1001, 0, 0}, NT_STATUS_OK},
};
static bool test_zerobytelocks(struct torture_context *tctx, struct smbcli_state *cli)
{
union smb_lock io;
NTSTATUS status;
bool ret = true;
int fnum, i;
const char *fname = BASEDIR "\\zero.txt";
torture_comment(tctx, "Testing zero length byte range locks:\n");
torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
io.generic.level = RAW_LOCK_LOCKX;
fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
torture_assert(tctx,(fnum != -1), talloc_asprintf(tctx,
"Failed to create %s - %s\n",
fname, smbcli_errstr(cli->tree)));
/* Setup initial parameters */
io.lockx.level = RAW_LOCK_LOCKX;
io.lockx.in.file.fnum = fnum;
io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES; /* Exclusive */
io.lockx.in.timeout = 0;
/* Try every combination of locks in zero_byte_tests. The first lock is
* assumed to succeed. The second lock may contend, depending on the
* expected status. */
for (i = 0;
i < ARRAY_SIZE(zero_byte_tests);
i++) {
torture_comment(tctx, " ... {%d, %llu, %llu} + {%d, %llu, %llu} = %s\n",
zero_byte_tests[i].lock1.pid,
(unsigned long long) zero_byte_tests[i].lock1.offset,
(unsigned long long) zero_byte_tests[i].lock1.count,
zero_byte_tests[i].lock2.pid,
(unsigned long long) zero_byte_tests[i].lock2.offset,
(unsigned long long) zero_byte_tests[i].lock2.count,
nt_errstr(zero_byte_tests[i].exp_status));
/* Lock both locks. */
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
io.lockx.in.locks = discard_const_p(struct smb_lock_entry,
&zero_byte_tests[i].lock1);
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
io.lockx.in.locks = discard_const_p(struct smb_lock_entry,
&zero_byte_tests[i].lock2);
status = smb_raw_lock(cli->tree, &io);
if (NT_STATUS_EQUAL(zero_byte_tests[i].exp_status,
NT_STATUS_LOCK_NOT_GRANTED)) {
/* Allow either of the failure messages and keep going
* if we see the wrong status. */
CHECK_STATUS_OR_CONT(status,
NT_STATUS_LOCK_NOT_GRANTED,
NT_STATUS_FILE_LOCK_CONFLICT);
} else {
CHECK_STATUS_CONT(status,
zero_byte_tests[i].exp_status);
}
/* Unlock both locks. */
io.lockx.in.ulock_cnt = 1;
io.lockx.in.lock_cnt = 0;
if (NT_STATUS_EQUAL(status, NT_STATUS_OK)) {
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
}
io.lockx.in.locks = discard_const_p(struct smb_lock_entry,
&zero_byte_tests[i].lock1);
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
}
done:
smbcli_close(cli->tree, fnum);
smb_raw_exit(cli->session);
smbcli_deltree(cli->tree, BASEDIR);
return ret;
}
static bool test_unlock(struct torture_context *tctx, struct smbcli_state *cli)
{
union smb_lock io;
NTSTATUS status;
bool ret = true;
int fnum1, fnum2;
const char *fname = BASEDIR "\\unlock.txt";
struct smb_lock_entry lock1;
struct smb_lock_entry lock2;
torture_comment(tctx, "Testing LOCKX unlock:\n");
torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
torture_assert(tctx,(fnum1 != -1), talloc_asprintf(tctx,
"Failed to create %s - %s\n",
fname, smbcli_errstr(cli->tree)));
fnum2 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
torture_assert(tctx,(fnum2 != -1), talloc_asprintf(tctx,
"Failed to create %s - %s\n",
fname, smbcli_errstr(cli->tree)));
/* Setup initial parameters */
io.lockx.level = RAW_LOCK_LOCKX;
io.lockx.in.timeout = 0;
lock1.pid = cli->session->pid;
lock1.offset = 0;
lock1.count = 10;
lock2.pid = cli->session->pid - 1;
lock2.offset = 0;
lock2.count = 10;
/**
* Take exclusive lock, then unlock it with a shared-unlock call.
*/
torture_comment(tctx, " taking exclusive lock.\n");
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
io.lockx.in.mode = 0;
io.lockx.in.file.fnum = fnum1;
io.lockx.in.locks = &lock1;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
torture_comment(tctx, " unlock the exclusive with a shared unlock call.\n");
io.lockx.in.ulock_cnt = 1;
io.lockx.in.lock_cnt = 0;
io.lockx.in.mode = LOCKING_ANDX_SHARED_LOCK;
io.lockx.in.file.fnum = fnum1;
io.lockx.in.locks = &lock1;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
torture_comment(tctx, " try shared lock on pid2/fnum2, testing the unlock.\n");
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
io.lockx.in.mode = LOCKING_ANDX_SHARED_LOCK;
io.lockx.in.file.fnum = fnum2;
io.lockx.in.locks = &lock2;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
/**
* Unlock a shared lock with an exclusive-unlock call.
*/
torture_comment(tctx, " unlock new shared lock with exclusive unlock call.\n");
io.lockx.in.ulock_cnt = 1;
io.lockx.in.lock_cnt = 0;
io.lockx.in.mode = 0;
io.lockx.in.file.fnum = fnum2;
io.lockx.in.locks = &lock2;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
torture_comment(tctx, " try exclusive lock on pid1, testing the unlock.\n");
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
io.lockx.in.mode = 0;
io.lockx.in.file.fnum = fnum1;
io.lockx.in.locks = &lock1;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
/* cleanup */
io.lockx.in.ulock_cnt = 1;
io.lockx.in.lock_cnt = 0;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
/**
* Test unlocking of 0-byte locks.
*/
torture_comment(tctx, " lock shared and exclusive 0-byte locks, testing that Windows "
"always unlocks the exclusive first.\n");
lock1.pid = cli->session->pid;
lock1.offset = 10;
lock1.count = 0;
lock2.pid = cli->session->pid;
lock2.offset = 5;
lock2.count = 10;
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
io.lockx.in.file.fnum = fnum1;
io.lockx.in.locks = &lock1;
/* lock 0-byte shared
* Note: Order of the shared/exclusive locks doesn't matter. */
io.lockx.in.mode = LOCKING_ANDX_SHARED_LOCK;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
/* lock 0-byte exclusive */
io.lockx.in.mode = 0;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
/* test contention */
io.lockx.in.mode = LOCKING_ANDX_SHARED_LOCK;
io.lockx.in.locks = &lock2;
io.lockx.in.file.fnum = fnum2;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS_OR(status, NT_STATUS_LOCK_NOT_GRANTED,
NT_STATUS_FILE_LOCK_CONFLICT);
/* unlock */
io.lockx.in.ulock_cnt = 1;
io.lockx.in.lock_cnt = 0;
io.lockx.in.file.fnum = fnum1;
io.lockx.in.locks = &lock1;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
/* test - can we take a shared lock? */
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
io.lockx.in.mode = LOCKING_ANDX_SHARED_LOCK;
io.lockx.in.file.fnum = fnum2;
io.lockx.in.locks = &lock2;
status = smb_raw_lock(cli->tree, &io);
/* XXX Samba 3 will fail this test. This is temporary(because this isn't
* new to Win7, it succeeds in WinXP too), until I can come to a
* resolution as to whether Samba should support this or not. There is
* code to preference unlocking exclusive locks before shared locks,
* but its wrapped with "#ifdef ZERO_ZERO". -zkirsch */
if (TARGET_IS_SAMBA3(tctx)) {
CHECK_STATUS_OR(status, NT_STATUS_LOCK_NOT_GRANTED,
NT_STATUS_FILE_LOCK_CONFLICT);
} else {
CHECK_STATUS(status, NT_STATUS_OK);
}
/* cleanup */
io.lockx.in.ulock_cnt = 1;
io.lockx.in.lock_cnt = 0;
status = smb_raw_lock(cli->tree, &io);
/* XXX Same as above. */
if (TARGET_IS_SAMBA3(tctx)) {
CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
} else {
CHECK_STATUS(status, NT_STATUS_OK);
}
io.lockx.in.file.fnum = fnum1;
io.lockx.in.locks = &lock1;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
done:
smbcli_close(cli->tree, fnum1);
smbcli_close(cli->tree, fnum2);
smb_raw_exit(cli->session);
smbcli_deltree(cli->tree, BASEDIR);
return ret;
}
static bool test_multiple_unlock(struct torture_context *tctx, struct smbcli_state *cli)
{
union smb_lock io;
NTSTATUS status;
bool ret = true;
int fnum1;
const char *fname = BASEDIR "\\unlock_multiple.txt";
struct smb_lock_entry lock1;
struct smb_lock_entry lock2;
struct smb_lock_entry locks[2];
torture_comment(tctx, "Testing LOCKX multiple unlock:\n");
torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
torture_assert(tctx,(fnum1 != -1), talloc_asprintf(tctx,
"Failed to create %s - %s\n",
fname, smbcli_errstr(cli->tree)));
/* Setup initial parameters */
io.lockx.level = RAW_LOCK_LOCKX;
io.lockx.in.timeout = 0;
lock1.pid = cli->session->pid;
lock1.offset = 0;
lock1.count = 10;
lock2.pid = cli->session->pid;
lock2.offset = 10;
lock2.count = 10;
locks[0] = lock1;
locks[1] = lock2;
io.lockx.in.file.fnum = fnum1;
io.lockx.in.mode = 0; /* exclusive */
/** Test1: Take second lock, but not first. */
torture_comment(tctx, " unlock 2 locks, first one not locked. Expect no locks "
"unlocked. \n");
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
io.lockx.in.locks = &lock2;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
/* Try to unlock both locks. */
io.lockx.in.ulock_cnt = 2;
io.lockx.in.lock_cnt = 0;
io.lockx.in.locks = locks;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
/* Second lock should not be unlocked. */
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
io.lockx.in.locks = &lock2;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
/* cleanup */
io.lockx.in.ulock_cnt = 1;
io.lockx.in.lock_cnt = 0;
io.lockx.in.locks = &lock2;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
/** Test2: Take first lock, but not second. */
torture_comment(tctx, " unlock 2 locks, second one not locked. Expect first lock "
"unlocked.\n");
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
io.lockx.in.locks = &lock1;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
/* Try to unlock both locks. */
io.lockx.in.ulock_cnt = 2;
io.lockx.in.lock_cnt = 0;
io.lockx.in.locks = locks;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
/* First lock should be unlocked. */
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
io.lockx.in.locks = &lock1;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
/* cleanup */
io.lockx.in.ulock_cnt = 1;
io.lockx.in.lock_cnt = 0;
io.lockx.in.locks = &lock1;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
/* Test3: Request 2 locks, second will contend. What happens to the
* first? */
torture_comment(tctx, " request 2 locks, second one will contend. "
"Expect both to fail.\n");
/* Lock the second range */
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
io.lockx.in.locks = &lock2;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
/* Request both locks */
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 2;
io.lockx.in.locks = locks;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
/* First lock should be unlocked. */
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
io.lockx.in.locks = &lock1;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
/* cleanup */
io.lockx.in.ulock_cnt = 2;
io.lockx.in.lock_cnt = 0;
io.lockx.in.locks = locks;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
/* Test4: Request unlock and lock. The lock contends, is the unlock
* then re-locked? */
torture_comment(tctx, " request unlock and lock, second one will "
"contend. Expect the unlock to succeed.\n");
/* Lock both ranges */
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 2;
io.lockx.in.locks = locks;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
/* Attempt to unlock the first range and lock the second */
io.lockx.in.ulock_cnt = 1;
io.lockx.in.lock_cnt = 1;
io.lockx.in.locks = locks;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
/* The first lock should've been unlocked */
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
io.lockx.in.locks = &lock1;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
/* cleanup */
io.lockx.in.ulock_cnt = 2;
io.lockx.in.lock_cnt = 0;
io.lockx.in.locks = locks;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
done:
smbcli_close(cli->tree, fnum1);
smb_raw_exit(cli->session);
smbcli_deltree(cli->tree, BASEDIR);
return ret;
}
/**
* torture_locktest5 covers stacking pretty well, but its missing two tests:
* - stacking an exclusive on top of shared fails
* - stacking two exclusives fail
*/
static bool test_stacking(struct torture_context *tctx, struct smbcli_state *cli)
{
union smb_lock io;
NTSTATUS status;
bool ret = true;
int fnum1;
const char *fname = BASEDIR "\\stacking.txt";
struct smb_lock_entry lock1;
torture_comment(tctx, "Testing stacking:\n");
torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
io.generic.level = RAW_LOCK_LOCKX;
fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
torture_assert(tctx,(fnum1 != -1), talloc_asprintf(tctx,
"Failed to create %s - %s\n",
fname, smbcli_errstr(cli->tree)));
/* Setup initial parameters */
io.lockx.level = RAW_LOCK_LOCKX;
io.lockx.in.timeout = 0;
lock1.pid = cli->session->pid;
lock1.offset = 0;
lock1.count = 10;
/**
* Try to take a shared lock, then stack an exclusive.
*/
torture_comment(tctx, " stacking an exclusive on top of a shared lock fails.\n");
io.lockx.in.file.fnum = fnum1;
io.lockx.in.locks = &lock1;
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
io.lockx.in.mode = LOCKING_ANDX_SHARED_LOCK;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
io.lockx.in.mode = 0;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS_OR(status, NT_STATUS_LOCK_NOT_GRANTED,
NT_STATUS_FILE_LOCK_CONFLICT);
/* cleanup */
io.lockx.in.ulock_cnt = 1;
io.lockx.in.lock_cnt = 0;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
/**
* Prove that two exclusive locks do not stack.
*/
torture_comment(tctx, " two exclusive locks do not stack.\n");
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
io.lockx.in.mode = 0;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS_OR(status, NT_STATUS_LOCK_NOT_GRANTED,
NT_STATUS_FILE_LOCK_CONFLICT);
/* cleanup */
io.lockx.in.ulock_cnt = 1;
io.lockx.in.lock_cnt = 0;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
done:
smbcli_close(cli->tree, fnum1);
smb_raw_exit(cli->session);
smbcli_deltree(cli->tree, BASEDIR);
return ret;
}
/**
* Test how 0-byte read requests contend with byte range locks
*/
static bool test_zerobyteread(struct torture_context *tctx,
struct smbcli_state *cli)
{
union smb_lock io;
union smb_read rd;
NTSTATUS status;
bool ret = true;
int fnum1, fnum2;
const char *fname = BASEDIR "\\zerobyteread.txt";
struct smb_lock_entry lock1;
uint8_t c = 1;
torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
io.generic.level = RAW_LOCK_LOCKX;
fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
torture_assert(tctx,(fnum1 != -1), talloc_asprintf(tctx,
"Failed to create %s - %s\n",
fname, smbcli_errstr(cli->tree)));
fnum2 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
torture_assert(tctx,(fnum2 != -1), talloc_asprintf(tctx,
"Failed to create %s - %s\n",
fname, smbcli_errstr(cli->tree)));
/* Setup initial parameters */
io.lockx.level = RAW_LOCK_LOCKX;
io.lockx.in.timeout = 0;
lock1.pid = cli->session->pid;
lock1.offset = 0;
lock1.count = 10;
ZERO_STRUCT(rd);
rd.readx.level = RAW_READ_READX;
torture_comment(tctx, "Testing zero byte read on lock range:\n");
/* Take an exclusive lock */
torture_comment(tctx, " taking exclusive lock.\n");
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
io.lockx.in.mode = LOCKING_ANDX_EXCLUSIVE_LOCK;
io.lockx.in.file.fnum = fnum1;
io.lockx.in.locks = &lock1;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
/* Try a zero byte read */
torture_comment(tctx, " reading 0 bytes.\n");
rd.readx.in.file.fnum = fnum2;
rd.readx.in.offset = 5;
rd.readx.in.mincnt = 0;
rd.readx.in.maxcnt = 0;
rd.readx.in.remaining = 0;
rd.readx.in.read_for_execute = false;
rd.readx.out.data = &c;
status = smb_raw_read(cli->tree, &rd);
torture_assert_int_equal_goto(tctx, rd.readx.out.nread, 0, ret, done,
"zero byte read did not return 0 bytes");
CHECK_STATUS(status, NT_STATUS_OK);
/* Unlock lock */
io.lockx.in.ulock_cnt = 1;
io.lockx.in.lock_cnt = 0;
io.lockx.in.mode = LOCKING_ANDX_EXCLUSIVE_LOCK;
io.lockx.in.file.fnum = fnum1;
io.lockx.in.locks = &lock1;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
torture_comment(tctx, "Testing zero byte read on zero byte lock "
"range:\n");
/* Take an exclusive lock */
torture_comment(tctx, " taking exclusive 0-byte lock.\n");
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
io.lockx.in.mode = LOCKING_ANDX_EXCLUSIVE_LOCK;
io.lockx.in.file.fnum = fnum1;
io.lockx.in.locks = &lock1;
lock1.offset = 5;
lock1.count = 0;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
/* Try a zero byte read before the lock */
torture_comment(tctx, " reading 0 bytes before the lock.\n");
rd.readx.in.file.fnum = fnum2;
rd.readx.in.offset = 4;
rd.readx.in.mincnt = 0;
rd.readx.in.maxcnt = 0;
rd.readx.in.remaining = 0;
rd.readx.in.read_for_execute = false;
rd.readx.out.data = &c;
status = smb_raw_read(cli->tree, &rd);
torture_assert_int_equal_goto(tctx, rd.readx.out.nread, 0, ret, done,
"zero byte read did not return 0 bytes");
CHECK_STATUS(status, NT_STATUS_OK);
/* Try a zero byte read on the lock */
torture_comment(tctx, " reading 0 bytes on the lock.\n");
rd.readx.in.file.fnum = fnum2;
rd.readx.in.offset = 5;
rd.readx.in.mincnt = 0;
rd.readx.in.maxcnt = 0;
rd.readx.in.remaining = 0;
rd.readx.in.read_for_execute = false;
rd.readx.out.data = &c;
status = smb_raw_read(cli->tree, &rd);
torture_assert_int_equal_goto(tctx, rd.readx.out.nread, 0, ret, done,
"zero byte read did not return 0 bytes");
CHECK_STATUS(status, NT_STATUS_OK);
/* Try a zero byte read after the lock */
torture_comment(tctx, " reading 0 bytes after the lock.\n");
rd.readx.in.file.fnum = fnum2;
rd.readx.in.offset = 6;
rd.readx.in.mincnt = 0;
rd.readx.in.maxcnt = 0;
rd.readx.in.remaining = 0;
rd.readx.in.read_for_execute = false;
rd.readx.out.data = &c;
status = smb_raw_read(cli->tree, &rd);
torture_assert_int_equal_goto(tctx, rd.readx.out.nread, 0, ret, done,
"zero byte read did not return 0 bytes");
CHECK_STATUS(status, NT_STATUS_OK);
/* Unlock lock */
io.lockx.in.ulock_cnt = 1;
io.lockx.in.lock_cnt = 0;
io.lockx.in.mode = LOCKING_ANDX_EXCLUSIVE_LOCK;
io.lockx.in.file.fnum = fnum1;
io.lockx.in.locks = &lock1;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
done:
smbcli_close(cli->tree, fnum1);
smbcli_close(cli->tree, fnum2);
smb_raw_exit(cli->session);
smbcli_deltree(cli->tree, BASEDIR);
return ret;
}
/*
test multi Locking&X operation
*/
static bool test_multilock(struct torture_context *tctx,
struct smbcli_state *cli)
{
union smb_lock io;
struct smb_lock_entry lock[2];
NTSTATUS status;
bool ret = true;
int fnum;
const char *fname = BASEDIR "\\multilock_test.txt";
time_t t;
struct smbcli_request *req;
struct smbcli_session_options options;
torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
lpcfg_smbcli_session_options(tctx->lp_ctx, &options);
torture_comment(tctx, "Testing LOCKING_ANDX multi-lock\n");
io.generic.level = RAW_LOCK_LOCKX;
/* Create the test file. */
fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
torture_assert(tctx,(fnum != -1), talloc_asprintf(tctx,
"Failed to create %s - %s\n",
fname, smbcli_errstr(cli->tree)));
/*
* Lock regions 100->109, 120->129 as
* two separate write locks in one request.
*/
io.lockx.level = RAW_LOCK_LOCKX;
io.lockx.in.file.fnum = fnum;
io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
io.lockx.in.timeout = 0;
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 2;
io.lockx.in.mode = LOCKING_ANDX_EXCLUSIVE_LOCK;
lock[0].pid = cli->session->pid;
lock[0].offset = 100;
lock[0].count = 10;
lock[1].pid = cli->session->pid;
lock[1].offset = 120;
lock[1].count = 10;
io.lockx.in.locks = &lock[0];
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
/*
* Now request the same locks on a different
* context as blocking locks with infinite timeout.
*/
io.lockx.in.timeout = 20000;
lock[0].pid = cli->session->pid+1;
lock[1].pid = cli->session->pid+1;
req = smb_raw_lock_send(cli->tree, &io);
torture_assert(tctx,(req != NULL), talloc_asprintf(tctx,
"Failed to setup timed locks (%s)\n", __location__));
/* Unlock lock[0] */
io.lockx.in.timeout = 0;
io.lockx.in.ulock_cnt = 1;
io.lockx.in.lock_cnt = 0;
io.lockx.in.locks = &lock[0];
lock[0].pid = cli->session->pid;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
/* Start the clock. */
t = time_mono(NULL);
/* Unlock lock[1] */
io.lockx.in.timeout = 0;
io.lockx.in.ulock_cnt = 1;
io.lockx.in.lock_cnt = 0;
io.lockx.in.locks = &lock[1];
lock[1].pid = cli->session->pid;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
/* receive the successful blocked lock requests */
status = smbcli_request_simple_recv(req);
CHECK_STATUS(status, NT_STATUS_OK);
/* Fail if this took more than 2 seconds. */
torture_assert(tctx,!(time_mono(NULL) > t+2), talloc_asprintf(tctx,
"Blocking locks were not granted immediately (%s)\n",
__location__));
done:
smb_raw_exit(cli->session);
smbcli_deltree(cli->tree, BASEDIR);
return ret;
}
/*
test multi2 Locking&X operation
This test is designed to show that
lock precedence on the server is based
on the order received, not on the ability
to grant. For example:
A blocked lock request containing 2 locks
will be satified before a subsequent blocked
lock request over one of the same regions,
even if that region is then unlocked. E.g.
(a) lock 100->109, 120->129 (granted)
(b) lock 100->109, 120-129 (blocks)
(c) lock 100->109 (blocks)
(d) unlock 100->109
lock (c) will not be granted as lock (b)
will take precedence.
*/
static bool test_multilock2(struct torture_context *tctx,
struct smbcli_state *cli)
{
union smb_lock io;
struct smb_lock_entry lock[2];
NTSTATUS status;
bool ret = true;
int fnum;
const char *fname = BASEDIR "\\multilock2_test.txt";
time_t t;
struct smbcli_request *req;
struct smbcli_request *req2;
struct smbcli_session_options options;
torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
lpcfg_smbcli_session_options(tctx->lp_ctx, &options);
torture_comment(tctx, "Testing LOCKING_ANDX multi-lock 2\n");
io.generic.level = RAW_LOCK_LOCKX;
/* Create the test file. */
fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
torture_assert(tctx,(fnum != -1), talloc_asprintf(tctx,
"Failed to create %s - %s\n",
fname, smbcli_errstr(cli->tree)));
/*
* Lock regions 100->109, 120->129 as
* two separate write locks in one request.
*/
io.lockx.level = RAW_LOCK_LOCKX;
io.lockx.in.file.fnum = fnum;
io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
io.lockx.in.timeout = 0;
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 2;
io.lockx.in.mode = LOCKING_ANDX_EXCLUSIVE_LOCK;
lock[0].pid = cli->session->pid;
lock[0].offset = 100;
lock[0].count = 10;
lock[1].pid = cli->session->pid;
lock[1].offset = 120;
lock[1].count = 10;
io.lockx.in.locks = &lock[0];
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
/*
* Now request the same locks on a different
* context as blocking locks.
*/
io.lockx.in.timeout = 20000;
lock[0].pid = cli->session->pid+1;
lock[1].pid = cli->session->pid+1;
req = smb_raw_lock_send(cli->tree, &io);
torture_assert(tctx,(req != NULL), talloc_asprintf(tctx,
"Failed to setup timed locks (%s)\n", __location__));
/*
* Request the first lock again on a separate context.
* Wait 2 seconds. This should time out (the previous
* multi-lock request should take precedence).
*/
io.lockx.in.timeout = 2000;
lock[0].pid = cli->session->pid+2;
io.lockx.in.lock_cnt = 1;
req2 = smb_raw_lock_send(cli->tree, &io);
torture_assert(tctx,(req2 != NULL), talloc_asprintf(tctx,
"Failed to setup timed locks (%s)\n", __location__));
/* Unlock lock[0] */
io.lockx.in.timeout = 0;
io.lockx.in.ulock_cnt = 1;
io.lockx.in.lock_cnt = 0;
io.lockx.in.locks = &lock[0];
lock[0].pid = cli->session->pid;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
/* Did the second lock complete (should time out) ? */
status = smbcli_request_simple_recv(req2);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
torture_assert(tctx, req->state <= SMBCLI_REQUEST_RECV,
"req should still wait");
/* Start the clock. */
t = time_mono(NULL);
/* Unlock lock[1] */
io.lockx.in.timeout = 0;
io.lockx.in.ulock_cnt = 1;
io.lockx.in.lock_cnt = 0;
io.lockx.in.locks = &lock[1];
lock[1].pid = cli->session->pid;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
/* receive the successful blocked lock requests */
status = smbcli_request_simple_recv(req);
CHECK_STATUS(status, NT_STATUS_OK);
/* Fail if this took more than 2 seconds. */
torture_assert(tctx,!(time_mono(NULL) > t+2), talloc_asprintf(tctx,
"Blocking locks were not granted immediately (%s)\n",
__location__));
done:
smb_raw_exit(cli->session);
smbcli_deltree(cli->tree, BASEDIR);
return ret;
}
/*
test multi3 Locking&X operation
This test is designed to show that
lock precedence on the server is based
on the order received, not on the ability
to grant.
Compared to test_multilock2() (above)
this test demonstrates that completely
unrelated ranges work independently.
For example:
A blocked lock request containing 2 locks
will be satified before a subsequent blocked
lock request over one of the same regions,
even if that region is then unlocked. But
a lock of a different region goes through. E.g.
All locks are LOCKING_ANDX_EXCLUSIVE_LOCK (rw).
(a) lock 100->109, 120->129 (granted)
(b) lock 100->109, 120->129 (blocks, timeout=20s)
(c) lock 100->109 (blocks, timeout=2s)
(d) lock 110->119 (granted)
(e) lock 110->119 (blocks, timeout=20s)
(f) unlock 100->109 (a)
(g) lock 100->109 (not granted, blocked by (b))
(h) lock 100->109 (not granted, blocked by itself (b))
(i) lock (c) will not be granted(conflict, times out)
as lock (b) will take precedence.
(j) unlock 110-119 (d)
(k) lock (e) completes and is not blocked by (a) nor (b)
(l) lock 100->109 (not granted(conflict), blocked by (b))
(m) lock 100->109 (not granted(conflict), blocked by itself (b))
(n) unlock 120-129 (a)
(o) lock (b) completes
*/
static bool test_multilock3(struct torture_context *tctx,
struct smbcli_state *cli)
{
union smb_lock io;
struct smb_lock_entry lock[2];
union smb_lock io3;
struct smb_lock_entry lock3[1];
NTSTATUS status;
bool ret = true;
int fnum;
const char *fname = BASEDIR "\\multilock3_test.txt";
time_t t;
struct smbcli_request *req = NULL;
struct smbcli_request *req2 = NULL;
struct smbcli_request *req4 = NULL;
torture_assert(tctx, torture_setup_dir(cli, BASEDIR),
"Failed to setup up test directory: " BASEDIR);
torture_comment(tctx, "Testing LOCKING_ANDX multi-lock 3\n");
io.generic.level = RAW_LOCK_LOCKX;
/* Create the test file. */
fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
torture_assert(tctx,(fnum != -1), talloc_asprintf(tctx,
"Failed to create %s - %s\n",
fname, smbcli_errstr(cli->tree)));
/*
* a)
* Lock regions 100->109, 120->129 as
* two separate write locks in one request.
*/
io.lockx.level = RAW_LOCK_LOCKX;
io.lockx.in.file.fnum = fnum;
io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
io.lockx.in.timeout = 0;
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 2;
io.lockx.in.mode = LOCKING_ANDX_EXCLUSIVE_LOCK;
lock[0].pid = cli->session->pid;
lock[0].offset = 100;
lock[0].count = 10;
lock[1].pid = cli->session->pid;
lock[1].offset = 120;
lock[1].count = 10;
io.lockx.in.locks = &lock[0];
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
/*
* b)
* Now request the same locks on a different
* context as blocking locks.
*/
io.lockx.in.timeout = 20000;
lock[0].pid = cli->session->pid+1;
lock[1].pid = cli->session->pid+1;
req = smb_raw_lock_send(cli->tree, &io);
torture_assert(tctx,(req != NULL), talloc_asprintf(tctx,
"Failed to setup timed locks (%s)\n", __location__));
/*
* c)
* Request the first lock again on a separate context.
* Wait 2 seconds. This should time out (the previous
* multi-lock request should take precedence).
*/
io.lockx.in.timeout = 2000;
lock[0].pid = cli->session->pid+2;
io.lockx.in.lock_cnt = 1;
req2 = smb_raw_lock_send(cli->tree, &io);
torture_assert(tctx,(req2 != NULL), talloc_asprintf(tctx,
"Failed to setup timed locks (%s)\n", __location__));
/*
* d)
* Lock regions 110->119
*/
io3.lockx.level = RAW_LOCK_LOCKX;
io3.lockx.in.file.fnum = fnum;
io3.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
io3.lockx.in.timeout = 0;
io3.lockx.in.ulock_cnt = 0;
io3.lockx.in.lock_cnt = 1;
io3.lockx.in.mode = LOCKING_ANDX_EXCLUSIVE_LOCK;
lock3[0].pid = cli->session->pid+3;
lock3[0].offset = 110;
lock3[0].count = 10;
io3.lockx.in.locks = &lock3[0];
status = smb_raw_lock(cli->tree, &io3);
CHECK_STATUS(status, NT_STATUS_OK);
/*
* e)
* try 110-119 again
*/
io3.lockx.in.timeout = 20000;
lock3[0].pid = cli->session->pid+4;
req4 = smb_raw_lock_send(cli->tree, &io3);
torture_assert(tctx,(req4 != NULL), talloc_asprintf(tctx,
"Failed to setup timed locks (%s)\n", __location__));
/*
* f)
* Unlock (a) lock[0] 100-109
*/
io.lockx.in.timeout = 0;
io.lockx.in.ulock_cnt = 1;
io.lockx.in.lock_cnt = 0;
io.lockx.in.locks = &lock[0];
lock[0].pid = cli->session->pid;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
/*
* g)
* try to lock lock[0] 100-109 again
*/
lock[0].pid = cli->session->pid+5;
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
/*
* h)
* try to lock lock[0] 100-109 again with
* the pid that's still waiting
*/
lock[0].pid = cli->session->pid+1;
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
torture_assert(tctx, req2->state <= SMBCLI_REQUEST_RECV,
"req2 should still wait");
/*
* i)
* Did the second lock complete (should time out) ?
*/
status = smbcli_request_simple_recv(req2);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
torture_assert(tctx, req->state <= SMBCLI_REQUEST_RECV,
"req should still wait");
torture_assert(tctx, req4->state <= SMBCLI_REQUEST_RECV,
"req4 should still wait");
/*
* j)
* Unlock (d) lock[0] 110-119
*/
io3.lockx.in.timeout = 0;
io3.lockx.in.ulock_cnt = 1;
io3.lockx.in.lock_cnt = 0;
lock3[0].pid = cli->session->pid+3;
status = smb_raw_lock(cli->tree, &io3);
CHECK_STATUS(status, NT_STATUS_OK);
/*
* k)
* receive the successful blocked lock request (e)
* on 110-119 while the 100-109/120-129 is still waiting.
*/
status = smbcli_request_simple_recv(req4);
CHECK_STATUS(status, NT_STATUS_OK);
/*
* l)
* try to lock lock[0] 100-109 again
*/
lock[0].pid = cli->session->pid+6;
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
torture_assert(tctx, req->state <= SMBCLI_REQUEST_RECV,
"req should still wait");
/*
* m)
* try to lock lock[0] 100-109 again with
* the pid that's still waiting
*/
lock[0].pid = cli->session->pid+1;
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
torture_assert(tctx, req->state <= SMBCLI_REQUEST_RECV,
"req should still wait");
/* Start the clock. */
t = time_mono(NULL);
/*
* n)
* Unlock lock[1] 120-129 */
io.lockx.in.timeout = 0;
io.lockx.in.ulock_cnt = 1;
io.lockx.in.lock_cnt = 0;
io.lockx.in.locks = &lock[1];
lock[1].pid = cli->session->pid;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
/*
* o)
* receive the successful blocked lock request (b)
*/
status = smbcli_request_simple_recv(req);
CHECK_STATUS(status, NT_STATUS_OK);
/* Fail if this took more than 2 seconds. */
torture_assert(tctx,!(time_mono(NULL) > t+2), talloc_asprintf(tctx,
"Blocking locks were not granted immediately (%s)\n",
__location__));
done:
smb_raw_exit(cli->session);
smbcli_deltree(cli->tree, BASEDIR);
return ret;
}
/*
test multi4 Locking&X operation
This test is designed to show that
lock precedence on the server is based
on the order received, not on the ability
to grant.
Compared to test_multilock3() (above)
this test demonstrates that pending read-only/shared
locks doesn't block shared locks others.
The outstanding requests build an implicit
database that's checked before checking
the already granted locks in the real database.
For example:
A blocked read-lock request containing 2 locks
will be still be blocked, while one region
is still write-locked. While it doesn't block
other read-lock requests for the other region. E.g.
(a) lock(rw) 100->109, 120->129 (granted)
(b) lock(ro) 100->109, 120->129 (blocks, timeout=20s)
(c) lock(ro) 100->109 (blocks, timeout=MAX)
(d) lock(rw) 110->119 (granted)
(e) lock(rw) 110->119 (blocks, timeout=20s)
(f) unlock 100->109 (a)
(g) lock(ro) (c) completes and is not blocked by (a) nor (b)
(h) lock(rw) 100->109 (not granted, blocked by (c))
(i) lock(rw) 100->109 (pid (b)) (not granted(conflict), blocked by (c))
(j) unlock 110-119
(k) lock (e) completes and is not blocked by (a) nor (b)
(l) lock 100->109 (not granted(conflict), blocked by (b))
(m) lock 100->109 (pid (b)) (not granted(conflict), blocked by itself (b))
(n) unlock 120-129 (a)
(o) lock (b) completes
*/
static bool test_multilock4(struct torture_context *tctx,
struct smbcli_state *cli)
{
union smb_lock io;
struct smb_lock_entry lock[2];
union smb_lock io3;
struct smb_lock_entry lock3[1];
NTSTATUS status;
bool ret = true;
int fnum;
const char *fname = BASEDIR "\\multilock4_test.txt";
time_t t;
struct smbcli_request *req = NULL;
struct smbcli_request *req2 = NULL;
struct smbcli_request *req4 = NULL;
torture_assert(tctx, torture_setup_dir(cli, BASEDIR),
"Failed to setup up test directory: " BASEDIR);
torture_comment(tctx, "Testing LOCKING_ANDX multi-lock 4\n");
io.generic.level = RAW_LOCK_LOCKX;
/* Create the test file. */
fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
torture_assert(tctx,(fnum != -1), talloc_asprintf(tctx,
"Failed to create %s - %s\n",
fname, smbcli_errstr(cli->tree)));
/*
* a)
* Lock regions 100->109, 120->129 as
* two separate write locks in one request.
*/
io.lockx.level = RAW_LOCK_LOCKX;
io.lockx.in.file.fnum = fnum;
io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
io.lockx.in.timeout = 0;
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 2;
io.lockx.in.mode = LOCKING_ANDX_EXCLUSIVE_LOCK;
lock[0].pid = cli->session->pid;
lock[0].offset = 100;
lock[0].count = 10;
lock[1].pid = cli->session->pid;
lock[1].offset = 120;
lock[1].count = 10;
io.lockx.in.locks = &lock[0];
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
/*
* b)
* Now request the same locks on a different
* context as blocking locks. But readonly.
*/
io.lockx.in.timeout = 20000;
io.lockx.in.mode = LOCKING_ANDX_SHARED_LOCK;
lock[0].pid = cli->session->pid+1;
lock[1].pid = cli->session->pid+1;
req = smb_raw_lock_send(cli->tree, &io);
torture_assert(tctx,(req != NULL), talloc_asprintf(tctx,
"Failed to setup timed locks (%s)\n", __location__));
/*
* c)
* Request the first lock again on a separate context.
* Wait forever. The previous multi-lock request (b)
* should take precedence. Also readonly.
*/
io.lockx.in.timeout = UINT32_MAX;
lock[0].pid = cli->session->pid+2;
io.lockx.in.lock_cnt = 1;
req2 = smb_raw_lock_send(cli->tree, &io);
torture_assert(tctx,(req2 != NULL), talloc_asprintf(tctx,
"Failed to setup timed locks (%s)\n", __location__));
/*
* d)
* Lock regions 110->119
*/
io3.lockx.level = RAW_LOCK_LOCKX;
io3.lockx.in.file.fnum = fnum;
io3.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
io3.lockx.in.timeout = 0;
io3.lockx.in.ulock_cnt = 0;
io3.lockx.in.lock_cnt = 1;
io3.lockx.in.mode = LOCKING_ANDX_EXCLUSIVE_LOCK;
lock3[0].pid = cli->session->pid+3;
lock3[0].offset = 110;
lock3[0].count = 10;
io3.lockx.in.locks = &lock3[0];
status = smb_raw_lock(cli->tree, &io3);
CHECK_STATUS(status, NT_STATUS_OK);
/*
* e)
* try 110-119 again
*/
io3.lockx.in.timeout = 20000;
lock3[0].pid = cli->session->pid+4;
req4 = smb_raw_lock_send(cli->tree, &io3);
torture_assert(tctx,(req4 != NULL), talloc_asprintf(tctx,
"Failed to setup timed locks (%s)\n", __location__));
/*
* f)
* Unlock (a) lock[0] 100-109
*/
io.lockx.in.mode = LOCKING_ANDX_EXCLUSIVE_LOCK;
io.lockx.in.timeout = 0;
io.lockx.in.ulock_cnt = 1;
io.lockx.in.lock_cnt = 0;
io.lockx.in.locks = &lock[0];
lock[0].pid = cli->session->pid;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
/*
* g)
* receive the successful blocked lock request (c)
* on 110-119 while (b) 100-109/120-129 is still waiting.
*/
status = smbcli_request_simple_recv(req2);
CHECK_STATUS(status, NT_STATUS_OK);
/*
* h)
* try to lock lock[0] 100-109 again
* (read/write)
*/
lock[0].pid = cli->session->pid+5;
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
/*
* i)
* try to lock lock[0] 100-109 again with the pid (b)
* that's still waiting.
*/
lock[0].pid = cli->session->pid+1;
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
torture_assert(tctx, req->state <= SMBCLI_REQUEST_RECV,
"req should still wait");
torture_assert(tctx, req4->state <= SMBCLI_REQUEST_RECV,
"req4 should still wait");
/*
* j)
* Unlock (d) lock[0] 110-119
*/
io3.lockx.in.timeout = 0;
io3.lockx.in.ulock_cnt = 1;
io3.lockx.in.lock_cnt = 0;
lock3[0].pid = cli->session->pid+3;
status = smb_raw_lock(cli->tree, &io3);
CHECK_STATUS(status, NT_STATUS_OK);
/*
* k)
* receive the successful blocked
* lock request (e) on 110-119.
*/
status = smbcli_request_simple_recv(req4);
CHECK_STATUS(status, NT_STATUS_OK);
/*
* l)
* try to lock lock[0] 100-109 again
*/
lock[0].pid = cli->session->pid+6;
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
/*
* m)
* try to lock lock[0] 100-109 again with the pid (b)
* that's still waiting
*/
lock[0].pid = cli->session->pid+1;
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
torture_assert(tctx, req->state <= SMBCLI_REQUEST_RECV,
"req should still wait");
/* Start the clock. */
t = time_mono(NULL);
/*
* n)
* Unlock (a) lock[1] 120-129
*/
io.lockx.in.timeout = 0;
io.lockx.in.ulock_cnt = 1;
io.lockx.in.lock_cnt = 0;
io.lockx.in.locks = &lock[1];
lock[1].pid = cli->session->pid;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
/*
* o)
* receive the successful blocked lock request (b)
*/
status = smbcli_request_simple_recv(req);
CHECK_STATUS(status, NT_STATUS_OK);
/* Fail if this took more than 2 seconds. */
torture_assert(tctx,!(time_mono(NULL) > t+2), talloc_asprintf(tctx,
"Blocking locks were not granted immediately (%s)\n",
__location__));
done:
smb_raw_exit(cli->session);
smbcli_deltree(cli->tree, BASEDIR);
return ret;
}
/*
test multi5 Locking&X operation
This test is designed to show that
lock precedence on the server is based
on the order received, not on the ability
to grant.
Compared to test_multilock3() (above)
this test demonstrates that the initial
lock request that block the following
exclusive locks can be a shared lock.
For example:
All locks except (a) are LOCKING_ANDX_EXCLUSIVE_LOCK (rw).
(a) lock(ro) 100->109, 120->129 (granted)
(b) lock 100->109, 120->129 (blocks, timeout=20s)
(c) lock 100->109 (blocks, timeout=2s)
(d) lock 110->119 (granted)
(e) lock 110->119 (blocks, timeout=20s)
(f) unlock 100->109 (a)
(g) lock 100->109 (not granted, blocked by (b))
(h) lock 100->109 (not granted, blocked by itself (b))
(i) lock (c) will not be granted(conflict, times out)
as lock (b) will take precedence.
(j) unlock 110-119 (d)
(k) lock (e) completes and is not blocked by (a) nor (b)
(l) lock 100->109 (not granted(conflict), blocked by (b))
(m) lock 100->109 (not granted(conflict), blocked by itself (b))
(n) unlock 120-129 (a)
(o) lock (b) completes
*/
static bool test_multilock5(struct torture_context *tctx,
struct smbcli_state *cli)
{
union smb_lock io;
struct smb_lock_entry lock[2];
union smb_lock io3;
struct smb_lock_entry lock3[1];
NTSTATUS status;
bool ret = true;
int fnum;
const char *fname = BASEDIR "\\multilock5_test.txt";
time_t t;
struct smbcli_request *req = NULL;
struct smbcli_request *req2 = NULL;
struct smbcli_request *req4 = NULL;
torture_assert(tctx, torture_setup_dir(cli, BASEDIR),
"Failed to setup up test directory: " BASEDIR);
torture_comment(tctx, "Testing LOCKING_ANDX multi-lock 5\n");
io.generic.level = RAW_LOCK_LOCKX;
/* Create the test file. */
fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
torture_assert(tctx,(fnum != -1), talloc_asprintf(tctx,
"Failed to create %s - %s\n",
fname, smbcli_errstr(cli->tree)));
/*
* a)
* Lock regions 100->109, 120->129 as
* two separate write locks in one request.
* (read only)
*/
io.lockx.level = RAW_LOCK_LOCKX;
io.lockx.in.file.fnum = fnum;
io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
io.lockx.in.timeout = 0;
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 2;
io.lockx.in.mode = LOCKING_ANDX_SHARED_LOCK;
lock[0].pid = cli->session->pid;
lock[0].offset = 100;
lock[0].count = 10;
lock[1].pid = cli->session->pid;
lock[1].offset = 120;
lock[1].count = 10;
io.lockx.in.locks = &lock[0];
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
/*
* b)
* Now request the same locks on a different
* context as blocking locks.
* (read write)
*/
io.lockx.in.timeout = 20000;
io.lockx.in.mode = LOCKING_ANDX_EXCLUSIVE_LOCK;
lock[0].pid = cli->session->pid+1;
lock[1].pid = cli->session->pid+1;
req = smb_raw_lock_send(cli->tree, &io);
torture_assert(tctx,(req != NULL), talloc_asprintf(tctx,
"Failed to setup timed locks (%s)\n", __location__));
/*
* c)
* Request the first lock again on a separate context.
* Wait 2 seconds. This should time out (the previous
* multi-lock request should take precedence).
* (read write)
*/
io.lockx.in.timeout = 2000;
lock[0].pid = cli->session->pid+2;
io.lockx.in.lock_cnt = 1;
req2 = smb_raw_lock_send(cli->tree, &io);
torture_assert(tctx,(req2 != NULL), talloc_asprintf(tctx,
"Failed to setup timed locks (%s)\n", __location__));
/*
* d)
* Lock regions 110->119
*/
io3.lockx.level = RAW_LOCK_LOCKX;
io3.lockx.in.file.fnum = fnum;
io3.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
io3.lockx.in.timeout = 0;
io3.lockx.in.ulock_cnt = 0;
io3.lockx.in.lock_cnt = 1;
io3.lockx.in.mode = LOCKING_ANDX_EXCLUSIVE_LOCK;
lock3[0].pid = cli->session->pid+3;
lock3[0].offset = 110;
lock3[0].count = 10;
io3.lockx.in.locks = &lock3[0];
status = smb_raw_lock(cli->tree, &io3);
CHECK_STATUS(status, NT_STATUS_OK);
/*
* e)
* try 110-119 again
*/
io3.lockx.in.timeout = 20000;
lock3[0].pid = cli->session->pid+4;
req4 = smb_raw_lock_send(cli->tree, &io3);
torture_assert(tctx,(req4 != NULL), talloc_asprintf(tctx,
"Failed to setup timed locks (%s)\n", __location__));
/*
* f)
* Unlock (a) lock[0] 100-109
*
* Note we send LOCKING_ANDX_EXCLUSIVE_LOCK
* while the lock used LOCKING_ANDX_SHARED_LOCK
* to check if that also works.
*/
io.lockx.in.timeout = 0;
io.lockx.in.ulock_cnt = 1;
io.lockx.in.lock_cnt = 0;
io.lockx.in.locks = &lock[0];
lock[0].pid = cli->session->pid;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
/*
* g)
* try to lock lock[0] 100-109 again
*/
lock[0].pid = cli->session->pid+5;
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
/*
* h)
* try to lock lock[0] 100-109 again with the pid (b)
* that's still waiting.
* (read write)
*/
lock[0].pid = cli->session->pid+1;
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
torture_assert(tctx, req2->state <= SMBCLI_REQUEST_RECV,
"req2 should still wait");
/*
* i)
* Did the second lock complete (should time out) ?
*/
status = smbcli_request_simple_recv(req2);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
torture_assert(tctx, req->state <= SMBCLI_REQUEST_RECV,
"req should still wait");
torture_assert(tctx, req4->state <= SMBCLI_REQUEST_RECV,
"req4 should still wait");
/*
* j)
* Unlock (d) lock[0] 110-119
*/
io3.lockx.in.timeout = 0;
io3.lockx.in.ulock_cnt = 1;
io3.lockx.in.lock_cnt = 0;
lock3[0].pid = cli->session->pid+3;
status = smb_raw_lock(cli->tree, &io3);
CHECK_STATUS(status, NT_STATUS_OK);
/*
* k)
* receive the successful blocked lock requests
* on 110-119 while the 100-109/120-129 is still waiting.
*/
status = smbcli_request_simple_recv(req4);
CHECK_STATUS(status, NT_STATUS_OK);
/*
* l)
* try to lock lock[0] 100-109 again
*/
lock[0].pid = cli->session->pid+6;
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
/*
* m)
* try to lock lock[0] 100-109 again with the pid (b)
* that's still waiting
*/
lock[0].pid = cli->session->pid+1;
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
torture_assert(tctx, req->state <= SMBCLI_REQUEST_RECV,
"req should still wait");
/* Start the clock. */
t = time_mono(NULL);
/*
* n)
* Unlock (a) lock[1] 120-129
*/
io.lockx.in.timeout = 0;
io.lockx.in.ulock_cnt = 1;
io.lockx.in.lock_cnt = 0;
io.lockx.in.locks = &lock[1];
lock[1].pid = cli->session->pid;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
/*
* o)
* receive the successful blocked lock request (b)
*/
status = smbcli_request_simple_recv(req);
CHECK_STATUS(status, NT_STATUS_OK);
/* Fail if this took more than 2 seconds. */
torture_assert(tctx,!(time_mono(NULL) > t+2), talloc_asprintf(tctx,
"Blocking locks were not granted immediately (%s)\n",
__location__));
done:
smb_raw_exit(cli->session);
smbcli_deltree(cli->tree, BASEDIR);
return ret;
}
/*
test multi6 Locking&X operation
This test is designed to show that
lock precedence on the server is based
on the order received, not on the ability
to grant.
Compared to test_multilock4() (above)
this test demonstrates the behavior if
only just the first blocking lock
being a shared lock.
For example:
All locks except (b) are LOCKING_ANDX_EXCLUSIVE_LOCK (rw).
(a) lock 100->109, 120->129 (granted)
(b) lock(ro) 100->109, 120->129 (blocks, timeout=20s)
(c) lock 100->109 (blocks, timeout=2s)
(d) lock 110->119 (granted)
(e) lock 110->119 (blocks, timeout=20s)
(f) unlock 100->109 (a)
(g) lock 100->109 (not granted, blocked by (b))
(h) lock 100->109 (not granted, blocked by itself (b))
(i) lock (c) will not be granted(conflict, times out)
as lock (b) will take precedence.
(j) unlock 110-119 (d)
(k) lock (e) completes and is not blocked by (a) nor (b)
(l) lock 100->109 (not granted(conflict), blocked by (b))
(m) lock 100->109 (not granted(conflict), blocked by itself (b))
(n) unlock 120-129 (a)
(o) lock (b) completes
*/
static bool test_multilock6(struct torture_context *tctx,
struct smbcli_state *cli)
{
union smb_lock io;
struct smb_lock_entry lock[2];
union smb_lock io3;
struct smb_lock_entry lock3[1];
NTSTATUS status;
bool ret = true;
int fnum;
const char *fname = BASEDIR "\\multilock6_test.txt";
time_t t;
struct smbcli_request *req = NULL;
struct smbcli_request *req2 = NULL;
struct smbcli_request *req4 = NULL;
torture_assert(tctx, torture_setup_dir(cli, BASEDIR),
"Failed to setup up test directory: " BASEDIR);
torture_comment(tctx, "Testing LOCKING_ANDX multi-lock 6\n");
io.generic.level = RAW_LOCK_LOCKX;
/* Create the test file. */
fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
torture_assert(tctx,(fnum != -1), talloc_asprintf(tctx,
"Failed to create %s - %s\n",
fname, smbcli_errstr(cli->tree)));
/*
* a)
* Lock regions 100->109, 120->129 as
* two separate write locks in one request.
*/
io.lockx.level = RAW_LOCK_LOCKX;
io.lockx.in.file.fnum = fnum;
io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
io.lockx.in.timeout = 0;
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 2;
io.lockx.in.mode = LOCKING_ANDX_EXCLUSIVE_LOCK;
lock[0].pid = cli->session->pid;
lock[0].offset = 100;
lock[0].count = 10;
lock[1].pid = cli->session->pid;
lock[1].offset = 120;
lock[1].count = 10;
io.lockx.in.locks = &lock[0];
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
/*
* b)
* Now request the same locks on a different
* context as blocking locks.
* (read only)
*/
io.lockx.in.timeout = 20000;
io.lockx.in.mode = LOCKING_ANDX_SHARED_LOCK;
lock[0].pid = cli->session->pid+1;
lock[1].pid = cli->session->pid+1;
req = smb_raw_lock_send(cli->tree, &io);
torture_assert(tctx,(req != NULL), talloc_asprintf(tctx,
"Failed to setup timed locks (%s)\n", __location__));
/*
* c)
* Request the first lock again on a separate context.
* Wait 2 seconds. This should time out (the previous
* multi-lock request should take precedence).
*/
io.lockx.in.timeout = 2000;
io.lockx.in.mode = LOCKING_ANDX_EXCLUSIVE_LOCK;
lock[0].pid = cli->session->pid+2;
io.lockx.in.lock_cnt = 1;
req2 = smb_raw_lock_send(cli->tree, &io);
torture_assert(tctx,(req2 != NULL), talloc_asprintf(tctx,
"Failed to setup timed locks (%s)\n", __location__));
/*
* d)
* Lock regions 110->119
*/
io3.lockx.level = RAW_LOCK_LOCKX;
io3.lockx.in.file.fnum = fnum;
io3.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
io3.lockx.in.timeout = 0;
io3.lockx.in.ulock_cnt = 0;
io3.lockx.in.lock_cnt = 1;
io3.lockx.in.mode = LOCKING_ANDX_EXCLUSIVE_LOCK;
lock3[0].pid = cli->session->pid+3;
lock3[0].offset = 110;
lock3[0].count = 10;
io3.lockx.in.locks = &lock3[0];
status = smb_raw_lock(cli->tree, &io3);
CHECK_STATUS(status, NT_STATUS_OK);
/*
* e)
* try 110-119 again
*/
io3.lockx.in.timeout = 20000;
lock3[0].pid = cli->session->pid+4;
req4 = smb_raw_lock_send(cli->tree, &io3);
torture_assert(tctx,(req4 != NULL), talloc_asprintf(tctx,
"Failed to setup timed locks (%s)\n", __location__));
/*
* f)
* Unlock (a) lock[0] 100-109
*/
io.lockx.in.timeout = 0;
io.lockx.in.ulock_cnt = 1;
io.lockx.in.lock_cnt = 0;
io.lockx.in.locks = &lock[0];
lock[0].pid = cli->session->pid;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
/*
* g)
* try to lock lock[0] 100-109 again
*/
lock[0].pid = cli->session->pid+5;
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
/*
* h)
* try to lock lock[0] 100-109 again with the pid (b)
* that's still waiting
*/
lock[0].pid = cli->session->pid+1;
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
torture_assert(tctx, req2->state <= SMBCLI_REQUEST_RECV,
"req2 should still wait");
/*
* i)
* Did the second lock (c) complete (should time out) ?
*/
status = smbcli_request_simple_recv(req2);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
torture_assert(tctx, req->state <= SMBCLI_REQUEST_RECV,
"req should still wait");
torture_assert(tctx, req4->state <= SMBCLI_REQUEST_RECV,
"req4 should still wait");
/*
* j)
* Unlock (d) lock[0] 110-119
*/
io3.lockx.in.timeout = 0;
io3.lockx.in.ulock_cnt = 1;
io3.lockx.in.lock_cnt = 0;
lock3[0].pid = cli->session->pid+3;
status = smb_raw_lock(cli->tree, &io3);
CHECK_STATUS(status, NT_STATUS_OK);
/*
* k)
* receive the successful blocked lock request (e)
* on 110-119 while (b) 100-109/120-129 is still waiting.
*/
status = smbcli_request_simple_recv(req4);
CHECK_STATUS(status, NT_STATUS_OK);
/*
* l)
* try to lock lock[0] 100-109 again
*/
lock[0].pid = cli->session->pid+6;
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
/*
* m)
* try to lock lock[0] 100-109 again with the pid (b)
* that's still waiting
*/
lock[0].pid = cli->session->pid+1;
io.lockx.in.ulock_cnt = 0;
io.lockx.in.lock_cnt = 1;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
torture_assert(tctx, req->state <= SMBCLI_REQUEST_RECV,
"req should still wait");
/* Start the clock. */
t = time_mono(NULL);
/*
* n)
* Unlock (a) lock[1] 120-129
*/
io.lockx.in.timeout = 0;
io.lockx.in.ulock_cnt = 1;
io.lockx.in.lock_cnt = 0;
io.lockx.in.locks = &lock[1];
lock[1].pid = cli->session->pid;
status = smb_raw_lock(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_OK);
/*
* o)
* receive the successful blocked lock request (b)
*/
status = smbcli_request_simple_recv(req);
CHECK_STATUS(status, NT_STATUS_OK);
/* Fail if this took more than 2 seconds. */
torture_assert(tctx,!(time_mono(NULL) > t+2), talloc_asprintf(tctx,
"Blocking locks were not granted immediately (%s)\n",
__location__));
done:
smb_raw_exit(cli->session);
smbcli_deltree(cli->tree, BASEDIR);
return ret;
}
/*
basic testing of lock calls
*/
struct torture_suite *torture_raw_lock(TALLOC_CTX *mem_ctx)
{
struct torture_suite *suite = torture_suite_create(mem_ctx, "lock");
torture_suite_add_1smb_test(suite, "lockx", test_lockx);
torture_suite_add_1smb_test(suite, "lock", test_lock);
torture_suite_add_1smb_test(suite, "pidhigh", test_pidhigh);
torture_suite_add_1smb_test(suite, "async", test_async);
torture_suite_add_1smb_test(suite, "errorcode", test_errorcode);
torture_suite_add_1smb_test(suite, "changetype", test_changetype);
torture_suite_add_1smb_test(suite, "stacking", test_stacking);
torture_suite_add_1smb_test(suite, "unlock", test_unlock);
torture_suite_add_1smb_test(suite, "multiple_unlock",
test_multiple_unlock);
torture_suite_add_1smb_test(suite, "zerobytelocks", test_zerobytelocks);
torture_suite_add_1smb_test(suite, "zerobyteread", test_zerobyteread);
torture_suite_add_1smb_test(suite, "multilock", test_multilock);
torture_suite_add_1smb_test(suite, "multilock2", test_multilock2);
torture_suite_add_1smb_test(suite, "multilock3", test_multilock3);
torture_suite_add_1smb_test(suite, "multilock4", test_multilock4);
torture_suite_add_1smb_test(suite, "multilock5", test_multilock5);
torture_suite_add_1smb_test(suite, "multilock6", test_multilock6);
return suite;
}
|