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 import array
38 import struct
39 import pike.model
40 import pike.smb2
41 import pike.test
42
43 share_all = pike.smb2.FILE_SHARE_READ | \
44 pike.smb2.FILE_SHARE_WRITE | \
45 pike.smb2.FILE_SHARE_DELETE
46 access_rwd = pike.smb2.GENERIC_READ | \
47 pike.smb2.GENERIC_WRITE | \
48 pike.smb2.DELETE
49 null_fid = array.array('B', [0]*32)
50
52 test_files = [ "qfid_file.bin", "qfid_same_file.bin",
53 "qfid_diff_file1.bin", "qfid_diff_file2.bin" ]
54
56 """
57 Pull out the Query On Disk ID file_id field and return it
58 """
59 create_res = qfid_res = None
60 for child in response:
61 if isinstance(child, pike.smb2.CreateResponse):
62 create_res = child
63 break
64 self.assertIsNotNone(create_res,
65 "response didn't contain a "
66 "CreateResponse: {0}".format(response))
67 for child in create_res:
68 if isinstance(child, pike.smb2.QueryOnDiskIDResponse):
69 qfid_res = child
70 break
71 self.assertIsNotNone(qfid_res,
72 "CreateResponse didn't contain a "
73 "QueryOnDiskIDResponse: {0}".format(create_res))
74 return qfid_res.file_id
75
93
95 """
96 Opening the same file from different sessions should return the same id
97 """
98
99 chan1, tree1 = self.tree_connect()
100 chan2, tree2 = self.tree_connect()
101 open_future1 = chan1.create(tree1,
102 "qfid_same_file.bin",
103 access=access_rwd,
104 share=share_all,
105 disposition=pike.smb2.FILE_SUPERSEDE,
106 options=pike.smb2.FILE_DELETE_ON_CLOSE,
107 query_on_disk_id=True)
108 fh1 = open_future1.result()
109 fid1 = self.extract_file_id(open_future1.request_future.result())
110 open_future2 = chan2.create(tree2,
111 "qfid_same_file.bin",
112 access=access_rwd,
113 share=share_all,
114 disposition=pike.smb2.FILE_OPEN,
115 query_on_disk_id=True)
116 fh2 = open_future2.result()
117 fid2 = self.extract_file_id(open_future2.request_future.result())
118 self.assertNotEqual(fid1,
119 null_fid,
120 "On disk file_id was null")
121 self.assertEqual(fid1, fid2,
122 "On disk file_id for same file didn't match")
123
125 """
126 Opening a different file from different sessions should NOT return
127 the same id
128 """
129
130 chan1, tree1 = self.tree_connect()
131 chan2, tree2 = self.tree_connect()
132 open_future1 = chan1.create(tree1,
133 "qfid_diff_file1.bin",
134 access=access_rwd,
135 disposition=pike.smb2.FILE_SUPERSEDE,
136 options=pike.smb2.FILE_DELETE_ON_CLOSE,
137 query_on_disk_id=True)
138 fh1 = open_future1.result()
139 fid1 = self.extract_file_id(open_future1.request_future.result())
140 open_future2 = chan2.create(tree2,
141 "qfid_diff_file2.bin",
142 access=access_rwd,
143 disposition=pike.smb2.FILE_SUPERSEDE,
144 options=pike.smb2.FILE_DELETE_ON_CLOSE,
145 query_on_disk_id=True)
146 fh2 = open_future2.result()
147 fid2 = self.extract_file_id(open_future2.request_future.result())
148 self.assertNotEqual(fid1,
149 null_fid,
150 "On disk file_id was null")
151 self.assertNotEqual(fid1, fid2,
152 "On disk file_id for different files was the same")
153
155 """
156 Opening the same file name after closing the first file should return
157 the same on disk id
158 """
159
160 chan, tree = self.tree_connect()
161 open_future = chan.create(tree,
162 "qfid_file.bin",
163 access=access_rwd,
164 disposition=pike.smb2.FILE_SUPERSEDE,
165 query_on_disk_id=True)
166 fh = open_future.result()
167 fid = self.extract_file_id(open_future.request_future.result())
168 self.assertNotEqual(fid,
169 null_fid,
170 "On disk file_id was null")
171 first_fid = fid
172 chan.close(fh)
173
174 open_future = chan.create(tree,
175 "qfid_file.bin",
176 access=access_rwd,
177 disposition=pike.smb2.FILE_OPEN,
178 options=pike.smb2.FILE_DELETE_ON_CLOSE,
179 query_on_disk_id=True)
180 fh = open_future.result()
181 fid = self.extract_file_id(open_future.request_future.result())
182 self.assertNotEqual(fid,
183 null_fid,
184 "On disk file_id was null")
185 self.assertEqual(fid, first_fid,
186 "Subsequent open returns different file id")
187
189 """
190 Opening the same file name after deleting the first file should return
191 a different on disk id
192 """
193
194 chan, tree = self.tree_connect()
195 open_future = chan.create(tree,
196 "qfid_file.bin",
197 access=access_rwd,
198 disposition=pike.smb2.FILE_SUPERSEDE,
199 options=pike.smb2.FILE_DELETE_ON_CLOSE,
200 query_on_disk_id=True)
201 fh = open_future.result()
202 fid = self.extract_file_id(open_future.request_future.result())
203 self.assertNotEqual(fid,
204 null_fid,
205 "On disk file_id was null")
206 first_fid = fid
207 chan.close(fh)
208
209 open_future = chan.create(tree,
210 "qfid_file.bin",
211 access=access_rwd,
212 disposition=pike.smb2.FILE_CREATE,
213 options=pike.smb2.FILE_DELETE_ON_CLOSE,
214 query_on_disk_id=True)
215 fh = open_future.result()
216 fid = self.extract_file_id(open_future.request_future.result())
217 self.assertNotEqual(fid,
218 null_fid,
219 "On disk file_id was null")
220 self.assertNotEqual(fid, first_fid,
221 "Subsequent open after delete returns same file id")
222