Fix various spelling errors
[nivanova/samba-autobuild/.git] / source4 / torture / vfs / fruit.c
1 /*
2    Unix SMB/CIFS implementation.
3
4    vfs_fruit tests
5
6    Copyright (C) Ralph Boehme 2014
7
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #include "includes.h"
23 #include "system/filesys.h"
24 #include "libcli/libcli.h"
25 #include "libcli/smb2/smb2.h"
26 #include "libcli/smb2/smb2_calls.h"
27 #include "libcli/smb/smb2_create_ctx.h"
28 #include "lib/cmdline/popt_common.h"
29 #include "param/param.h"
30 #include "libcli/resolve/resolve.h"
31 #include "MacExtensions.h"
32 #include "lib/util/tsort.h"
33
34 #include "torture/torture.h"
35 #include "torture/util.h"
36 #include "torture/smb2/proto.h"
37 #include "torture/vfs/proto.h"
38 #include "librpc/gen_ndr/ndr_ioctl.h"
39
40 #define BASEDIR "vfs_fruit_dir"
41 #define FNAME_CC_SRC "testfsctl.dat"
42 #define FNAME_CC_DST "testfsctl2.dat"
43
44 #define CHECK_STATUS(status, correct) do { \
45         if (!NT_STATUS_EQUAL(status, correct)) { \
46                 torture_result(tctx, TORTURE_FAIL, \
47                     "(%s) Incorrect status %s - should be %s\n", \
48                     __location__, nt_errstr(status), nt_errstr(correct)); \
49                 ret = false; \
50                 goto done; \
51         }} while (0)
52
53 #define CHECK_VALUE(v, correct) do { \
54         if ((v) != (correct)) { \
55                 torture_result(tctx, TORTURE_FAIL, \
56                                "(%s) Incorrect value %s=%u - should be %u\n", \
57                                __location__, #v, (unsigned)v, (unsigned)correct); \
58                 ret = false; \
59                 goto done; \
60         }} while (0)
61
62 static bool check_stream_list(struct smb2_tree *tree,
63                               struct torture_context *tctx,
64                               const char *fname,
65                               int num_exp,
66                               const char **exp,
67                               struct smb2_handle h);
68
69 static int qsort_string(char * const *s1, char * const *s2)
70 {
71         return strcmp(*s1, *s2);
72 }
73
74 static int qsort_stream(const struct stream_struct * s1, const struct stream_struct *s2)
75 {
76         return strcmp(s1->stream_name.s, s2->stream_name.s);
77 }
78
79 /*
80  * REVIEW:
81  * This is hokey, but what else can we do?
82  */
83 #if defined(HAVE_ATTROPEN) || defined(FREEBSD)
84 #define AFPINFO_EA_NETATALK "org.netatalk.Metadata"
85 #define AFPRESOURCE_EA_NETATALK "org.netatalk.ResourceFork"
86 #else
87 #define AFPINFO_EA_NETATALK "user.org.netatalk.Metadata"
88 #define AFPRESOURCE_EA_NETATALK "user.org.netatalk.ResourceFork"
89 #endif
90
91 /*
92 The metadata xattr char buf below contains the following attributes:
93
94 -------------------------------------------------------------------------------
95 Entry ID   : 00000008 : File Dates Info
96 Offset     : 00000162 : 354
97 Length     : 00000010 : 16
98
99 -DATE------:          : (GMT)                    : (Local)
100 create     : 1B442169 : Mon Jun 30 13:23:53 2014 : Mon Jun 30 15:23:53 2014
101 modify     : 1B442169 : Mon Jun 30 13:23:53 2014 : Mon Jun 30 15:23:53 2014
102 backup     : 80000000 : Unknown or Initial
103 access     : 1B442169 : Mon Jun 30 13:23:53 2014 : Mon Jun 30 15:23:53 2014
104
105 -RAW DUMP--:  0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F : (ASCII)
106 00000000   : 1B 44 21 69 1B 44 21 69 80 00 00 00 1B 44 21 69 : .D!i.D!i.....D!i
107
108 -------------------------------------------------------------------------------
109 Entry ID   : 00000009 : Finder Info
110 Offset     : 0000007A : 122
111 Length     : 00000020 : 32
112
113 -FInfo-----:
114 Type       : 42415252 : BARR
115 Creator    : 464F4F4F : FOOO
116 isAlias    : 0
117 Invisible  : 1
118 hasBundle  : 0
119 nameLocked : 0
120 Stationery : 0
121 CustomIcon : 0
122 Reserved   : 0
123 Inited     : 0
124 NoINITS    : 0
125 Shared     : 0
126 SwitchLaunc: 0
127 Hidden Ext : 0
128 color      : 000      : none
129 isOnDesk   : 0
130 Location v : 0000     : 0
131 Location h : 0000     : 0
132 Fldr       : 0000     : ..
133
134 -FXInfo----:
135 Rsvd|IconID: 0000     : 0
136 Rsvd       : 0000     : ..
137 Rsvd       : 0000     : ..
138 Rsvd       : 0000     : ..
139 AreInvalid : 0
140 unknown bit: 0
141 unknown bit: 0
142 unknown bit: 0
143 unknown bit: 0
144 unknown bit: 0
145 unknown bit: 0
146 CustomBadge: 0
147 ObjctIsBusy: 0
148 unknown bit: 0
149 unknown bit: 0
150 unknown bit: 0
151 unknown bit: 0
152 RoutingInfo: 0
153 unknown bit: 0
154 unknown bit: 0
155 Rsvd|commnt: 0000     : 0
156 PutAway    : 00000000 : 0
157
158 -RAW DUMP--:  0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F : (ASCII)
159 00000000   : 42 41 52 52 46 4F 4F 4F 40 00 00 00 00 00 00 00 : BARRFOOO@.......
160 00000010   : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 : ................
161
162 -------------------------------------------------------------------------------
163 Entry ID   : 0000000E : AFP File Info
164 Offset     : 00000172 : 370
165 Length     : 00000004 : 4
166
167 -RAW DUMP--:  0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F : (ASCII)
168 00000000   : 00 00 01 A1                                     : ....
169  */
170
171 char metadata_xattr[] = {
172         0x00, 0x05, 0x16, 0x07, 0x00, 0x02, 0x00, 0x00,
173         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
174         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
175         0x00, 0x08, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00,
176         0x00, 0x9a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
177         0x00, 0x08, 0x00, 0x00, 0x01, 0x62, 0x00, 0x00,
178         0x00, 0x10, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00,
179         0x00, 0x7a, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00,
180         0x00, 0x0e, 0x00, 0x00, 0x01, 0x72, 0x00, 0x00,
181         0x00, 0x04, 0x80, 0x44, 0x45, 0x56, 0x00, 0x00,
182         0x01, 0x76, 0x00, 0x00, 0x00, 0x08, 0x80, 0x49,
183         0x4e, 0x4f, 0x00, 0x00, 0x01, 0x7e, 0x00, 0x00,
184         0x00, 0x08, 0x80, 0x53, 0x59, 0x4e, 0x00, 0x00,
185         0x01, 0x86, 0x00, 0x00, 0x00, 0x08, 0x80, 0x53,
186         0x56, 0x7e, 0x00, 0x00, 0x01, 0x8e, 0x00, 0x00,
187         0x00, 0x04, 0x42, 0x41, 0x52, 0x52, 0x46, 0x4f,
188         0x4f, 0x4f, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
189         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
190         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
191         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
192         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
193         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
194         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
195         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
196         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
197         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
198         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
199         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
200         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
201         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
202         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
203         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
204         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
205         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
206         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
207         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
208         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
209         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
210         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
211         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
212         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
213         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
214         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
215         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
216         0x00, 0x00, 0x1b, 0x44, 0x21, 0x69, 0x1b, 0x44,
217         0x21, 0x69, 0x80, 0x00, 0x00, 0x00, 0x1b, 0x44,
218         0x21, 0x69, 0x00, 0x00, 0x01, 0xa1, 0x00, 0xfd,
219         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc1, 0x20,
220         0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf1, 0xe3,
221         0x86, 0x53, 0x00, 0x00, 0x00, 0x00, 0x3b, 0x01,
222         0x00, 0x00
223 };
224
225 /*
226 The buf below contains the following AppleDouble encoded data:
227
228 -------------------------------------------------------------------------------
229 MagicNumber: 00051607                                        : AppleDouble
230 Version    : 00020000                                        : Version 2
231 Filler     : 4D 61 63 20 4F 53 20 58 20 20 20 20 20 20 20 20 : Mac OS X
232 Num. of ent: 0002                                            : 2
233
234 -------------------------------------------------------------------------------
235 Entry ID   : 00000009 : Finder Info
236 Offset     : 00000032 : 50
237 Length     : 00000EB0 : 3760
238
239 -FInfo-----:
240 Type       : 54455854 : TEXT
241 Creator    : 21526368 : !Rch
242 ...
243
244 -EA--------:
245 pad        : 0000     : ..
246 magic      : 41545452 : ATTR
247 debug_tag  : 0007F98E : 522638
248 total_size : 00000EE2 : 3810
249 data_start : 00000078 : 120
250 data_length: 00000000 : 0
251 reserved[0]: 00000000 : ....
252 reserved[1]: 00000000 : ....
253 reserved[2]: 00000000 : ....
254 flags      : 0000     : ..
255 num_attrs  : 0000     : 0
256
257 -------------------------------------------------------------------------------
258 Entry ID   : 00000002 : Resource Fork
259 Offset     : 00000EE2 : 3810
260 Length     : 0000011E : 286
261
262 -RAW DUMP--:  0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F : (ASCII)
263 00000000   : 00 00 01 00 00 00 01 00 00 00 00 00 00 00 00 1E : ................
264 00000010   : 54 68 69 73 20 72 65 73 6F 75 72 63 65 20 66 6F : This resource fo
265 00000020   : 72 6B 20 69 6E 74 65 6E 74 69 6F 6E 61 6C 6C 79 : rk intentionally
266 00000030   : 20 6C 65 66 74 20 62 6C 61 6E 6B 20 20 20 00 00 :  left blank   ..
267 ...
268 00000110   : 00 00 00 00 00 00 00 00 00 1C 00 1E FF FF       : ..............
269 */
270 static char osx_adouble_w_xattr[] = {
271         0x00, 0x05, 0x16, 0x07, 0x00, 0x02, 0x00, 0x00,
272         0x4d, 0x61, 0x63, 0x20, 0x4f, 0x53, 0x20, 0x58,
273         0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
274         0x00, 0x02, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00,
275         0x00, 0x32, 0x00, 0x00, 0x0e, 0xb0, 0x00, 0x00,
276         0x00, 0x02, 0x00, 0x00, 0x0e, 0xe2, 0x00, 0x00,
277         0x01, 0x1e, 0x54, 0x45, 0x58, 0x54, 0x21, 0x52,
278         0x63, 0x68, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
279         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
280         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
281         0x00, 0x00, 0x00, 0x00, 0x41, 0x54, 0x54, 0x52,
282         0x00, 0x07, 0xf9, 0x8e, 0x00, 0x00, 0x0e, 0xe2,
283         0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x00,
284         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
285         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
286         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
287         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
288         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
289         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
290         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
291         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
292         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
293         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
294         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
295         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
296         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
297         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
298         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
299         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
300         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
301         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
302         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
303         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
304         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
305         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
306         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
307         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
308         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
309         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
310         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
311         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
312         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
313         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
314         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
315         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
316         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
317         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
318         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
319         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
320         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
321         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
322         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
323         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
324         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
325         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
326         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
327         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
328         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
329         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
330         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
331         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
332         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
333         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
334         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
335         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
336         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
337         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
338         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
339         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
340         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
341         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
342         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
343         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
344         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
345         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
346         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
347         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
348         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
349         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
350         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
351         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
352         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
353         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
354         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
355         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
356         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
357         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
358         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
359         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
360         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
361         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
362         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
363         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
364         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
365         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
366         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
367         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
368         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
369         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
370         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
371         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
372         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
373         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
374         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
375         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
376         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
377         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
378         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
379         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
380         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
381         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
382         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
383         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
384         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
385         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
386         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
387         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
388         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
389         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
390         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
391         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
392         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
393         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
394         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
395         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
396         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
397         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
398         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
399         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
400         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
401         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
402         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
403         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
404         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
405         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
406         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
407         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
408         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
409         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
410         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
411         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
412         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
413         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
414         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
415         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
416         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
417         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
418         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
419         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
420         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
421         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
422         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
423         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
424         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
425         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
426         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
427         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
428         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
429         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
430         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
431         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
432         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
433         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
434         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
435         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
436         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
437         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
438         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
439         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
440         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
441         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
442         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
443         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
444         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
445         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
446         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
447         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
448         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
449         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
450         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
451         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
452         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
453         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
454         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
455         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
456         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
457         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
458         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
459         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
460         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
461         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
462         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
463         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
464         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
465         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
466         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
467         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
468         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
469         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
470         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
471         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
472         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
473         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
474         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
475         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
476         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
477         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
478         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
479         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
480         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
481         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
482         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
483         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
484         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
485         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
486         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
487         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
488         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
489         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
490         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
491         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
492         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
493         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
494         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
495         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
496         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
497         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
498         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
499         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
500         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
501         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
502         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
503         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
504         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
505         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
506         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
507         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
508         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
509         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
510         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
511         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
512         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
513         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
514         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
515         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
516         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
517         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
518         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
519         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
520         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
521         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
522         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
523         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
524         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
525         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
526         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
527         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
528         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
529         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
530         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
531         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
532         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
533         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
534         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
535         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
536         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
537         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
538         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
539         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
540         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
541         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
542         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
543         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
544         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
545         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
546         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
547         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
548         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
549         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
550         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
551         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
552         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
553         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
554         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
555         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
556         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
557         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
558         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
559         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
560         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
561         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
562         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
563         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
564         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
565         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
566         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
567         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
568         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
569         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
570         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
571         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
572         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
573         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
574         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
575         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
576         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
577         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
578         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
579         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
580         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
581         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
582         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
583         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
584         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
585         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
586         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
587         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
588         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
589         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
590         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
591         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
592         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
593         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
594         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
595         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
596         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
597         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
598         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
599         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
600         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
601         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
602         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
603         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
604         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
605         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
606         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
607         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
608         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
609         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
610         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
611         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
612         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
613         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
614         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
615         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
616         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
617         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
618         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
619         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
620         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
621         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
622         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
623         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
624         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
625         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
626         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
627         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
628         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
629         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
630         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
631         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
632         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
633         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
634         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
635         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
636         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
637         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
638         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
639         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
640         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
641         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
642         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
643         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
644         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
645         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
646         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
647         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
648         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
649         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
650         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
651         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
652         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
653         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
654         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
655         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
656         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
657         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
658         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
659         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
660         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
661         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
662         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
663         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
664         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
665         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
666         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
667         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
668         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
669         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
670         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
671         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
672         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
673         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
674         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
675         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
676         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
677         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
678         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
679         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
680         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
681         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
682         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
683         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
684         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
685         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
686         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
687         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
688         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
689         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
690         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
691         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
692         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
693         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
694         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
695         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
696         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
697         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
698         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
699         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
700         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
701         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
702         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
703         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
704         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
705         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
706         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
707         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
708         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
709         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
710         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
711         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
712         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
713         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
714         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
715         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
716         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
717         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
718         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
719         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
720         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
721         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
722         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
723         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
724         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
725         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
726         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
727         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
728         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
729         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
730         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
731         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
732         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
733         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
734         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
735         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
736         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
737         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
738         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
739         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
740         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
741         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
742         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
743         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
744         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
745         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
746         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
747         0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
748         0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
749         0x00, 0x1e, 0x54, 0x68, 0x69, 0x73, 0x20, 0x72,
750         0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x20,
751         0x66, 0x6f, 0x72, 0x6b, 0x20, 0x69, 0x6e, 0x74,
752         0x65, 0x6e, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c,
753         0x6c, 0x79, 0x20, 0x6c, 0x65, 0x66, 0x74, 0x20,
754         0x62, 0x6c, 0x61, 0x6e, 0x6b, 0x20, 0x20, 0x20,
755         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
756         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
757         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
758         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
759         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
760         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
761         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
762         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
763         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
764         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
765         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
766         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
767         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
768         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
769         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
770         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
771         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
772         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
773         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
774         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
775         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
776         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
777         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
778         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
779         0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
780         0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
781         0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
782         0x00, 0x00, 0x00, 0x1c, 0x00, 0x1e, 0xff, 0xff
783 };
784
785 /**
786  * talloc and intialize an AfpInfo
787  **/
788 static AfpInfo *torture_afpinfo_new(TALLOC_CTX *mem_ctx)
789 {
790         AfpInfo *info;
791
792         info = talloc_zero(mem_ctx, AfpInfo);
793         if (info == NULL) {
794                 return NULL;
795         }
796
797         info->afpi_Signature = AFP_Signature;
798         info->afpi_Version = AFP_Version;
799         info->afpi_BackupTime = AFP_BackupTime;
800
801         return info;
802 }
803
804 /**
805  * Pack AfpInfo into a talloced buffer
806  **/
807 static char *torture_afpinfo_pack(TALLOC_CTX *mem_ctx,
808                                   AfpInfo *info)
809 {
810         char *buf;
811
812         buf = talloc_array(mem_ctx, char, AFP_INFO_SIZE);
813         if (buf == NULL) {
814                 return NULL;
815         }
816
817         RSIVAL(buf, 0, info->afpi_Signature);
818         RSIVAL(buf, 4, info->afpi_Version);
819         RSIVAL(buf, 12, info->afpi_BackupTime);
820         memcpy(buf + 16, info->afpi_FinderInfo, sizeof(info->afpi_FinderInfo));
821
822         return buf;
823 }
824
825 /**
826  * Unpack AfpInfo
827  **/
828 #if 0
829 static void torture_afpinfo_unpack(AfpInfo *info, char *data)
830 {
831         info->afpi_Signature = RIVAL(data, 0);
832         info->afpi_Version = RIVAL(data, 4);
833         info->afpi_BackupTime = RIVAL(data, 12);
834         memcpy(info->afpi_FinderInfo, (const char *)data + 16,
835                sizeof(info->afpi_FinderInfo));
836 }
837 #endif
838
839 static bool torture_write_afpinfo(struct smb2_tree *tree,
840                                   struct torture_context *tctx,
841                                   TALLOC_CTX *mem_ctx,
842                                   const char *fname,
843                                   AfpInfo *info)
844 {
845         struct smb2_handle handle;
846         struct smb2_create io;
847         NTSTATUS status;
848         const char *full_name;
849         char *infobuf;
850         bool ret = true;
851
852         full_name = talloc_asprintf(mem_ctx, "%s%s", fname, AFPINFO_STREAM);
853         if (full_name == NULL) {
854             torture_comment(tctx, "talloc_asprintf error\n");
855             return false;
856         }
857         ZERO_STRUCT(io);
858         io.in.desired_access = SEC_FILE_WRITE_DATA;
859         io.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
860         io.in.create_disposition = NTCREATEX_DISP_OVERWRITE_IF;
861         io.in.create_options = 0;
862         io.in.fname = full_name;
863
864         status = smb2_create(tree, mem_ctx, &io);
865         CHECK_STATUS(status, NT_STATUS_OK);
866
867         handle = io.out.file.handle;
868
869         infobuf = torture_afpinfo_pack(mem_ctx, info);
870         if (infobuf == NULL) {
871                 return false;
872         }
873
874         status = smb2_util_write(tree, handle, infobuf, 0, AFP_INFO_SIZE);
875         CHECK_STATUS(status, NT_STATUS_OK);
876
877         smb2_util_close(tree, handle);
878
879 done:
880         return ret;
881 }
882
883 /**
884  * Read 'count' bytes at 'offset' from stream 'fname:sname' and
885  * compare against buffer 'value'
886  **/
887 static bool check_stream(struct smb2_tree *tree,
888                          const char *location,
889                          struct torture_context *tctx,
890                          TALLOC_CTX *mem_ctx,
891                          const char *fname,
892                          const char *sname,
893                          off_t read_offset,
894                          size_t read_count,
895                          off_t comp_offset,
896                          size_t comp_count,
897                          const char *value)
898 {
899         struct smb2_handle handle;
900         struct smb2_create create;
901         struct smb2_read r;
902         NTSTATUS status;
903         const char *full_name;
904
905         full_name = talloc_asprintf(mem_ctx, "%s%s", fname, sname);
906         if (full_name == NULL) {
907             torture_comment(tctx, "talloc_asprintf error\n");
908             return false;
909         }
910         ZERO_STRUCT(create);
911         create.in.desired_access = SEC_FILE_READ_DATA;
912         create.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
913         create.in.create_disposition = NTCREATEX_DISP_OPEN;
914         create.in.fname = full_name;
915
916         torture_comment(tctx, "Open stream %s\n", full_name);
917
918         status = smb2_create(tree, mem_ctx, &create);
919         if (!NT_STATUS_IS_OK(status)) {
920                 if (value == NULL) {
921                         return true;
922                 } else {
923                         torture_comment(tctx, "Unable to open stream %s\n",
924                             full_name);
925                         sleep(10000000);
926                         return false;
927                 }
928         }
929
930         handle = create.out.file.handle;
931         if (value == NULL) {
932                 return true;
933         }
934
935
936         ZERO_STRUCT(r);
937         r.in.file.handle = handle;
938         r.in.length      = read_count;
939         r.in.offset      = read_offset;
940
941         status = smb2_read(tree, tree, &r);
942
943         if (!NT_STATUS_IS_OK(status)) {
944                 torture_comment(tctx, "(%s) Failed to read %lu bytes from "
945                     "stream '%s'\n", location, (long)strlen(value), full_name);
946                 return false;
947         }
948
949         if (memcmp(r.out.data.data + comp_offset, value, comp_count) != 0) {
950                 torture_comment(tctx, "(%s) Bad data in stream\n", location);
951                 return false;
952         }
953
954         smb2_util_close(tree, handle);
955         return true;
956 }
957
958 /**
959  * Read 'count' bytes at 'offset' from stream 'fname:sname' and
960  * compare against buffer 'value'
961  **/
962 static ssize_t read_stream(struct smb2_tree *tree,
963                            const char *location,
964                            struct torture_context *tctx,
965                            TALLOC_CTX *mem_ctx,
966                            const char *fname,
967                            const char *sname,
968                            off_t read_offset,
969                            size_t read_count)
970 {
971         struct smb2_handle handle;
972         struct smb2_create create;
973         struct smb2_read r;
974         NTSTATUS status;
975         const char *full_name;
976         bool ret = true;
977
978         full_name = talloc_asprintf(mem_ctx, "%s%s", fname, sname);
979         if (full_name == NULL) {
980             torture_comment(tctx, "talloc_asprintf error\n");
981             return -1;
982         }
983         ZERO_STRUCT(create);
984         create.in.desired_access = SEC_FILE_READ_DATA;
985         create.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
986         create.in.create_disposition = NTCREATEX_DISP_OPEN;
987         create.in.fname = full_name;
988
989         torture_comment(tctx, "Open stream %s\n", full_name);
990
991         status = smb2_create(tree, mem_ctx, &create);
992         if (!NT_STATUS_IS_OK(status)) {
993                 torture_comment(tctx, "Unable to open stream %s\n",
994                                 full_name);
995                 return -1;
996         }
997
998         handle = create.out.file.handle;
999
1000         ZERO_STRUCT(r);
1001         r.in.file.handle = handle;
1002         r.in.length      = read_count;
1003         r.in.offset      = read_offset;
1004
1005         status = smb2_read(tree, tree, &r);
1006         if (!NT_STATUS_IS_OK(status)) {
1007                 CHECK_STATUS(status, NT_STATUS_END_OF_FILE);
1008         }
1009
1010         smb2_util_close(tree, handle);
1011
1012 done:
1013         if (ret == false) {
1014                 return -1;
1015         }
1016         return r.out.data.length;
1017 }
1018
1019 /**
1020  * Read 'count' bytes at 'offset' from stream 'fname:sname' and
1021  * compare against buffer 'value'
1022  **/
1023 static bool write_stream(struct smb2_tree *tree,
1024                          const char *location,
1025                          struct torture_context *tctx,
1026                          TALLOC_CTX *mem_ctx,
1027                          const char *fname,
1028                          const char *sname,
1029                          off_t offset,
1030                          size_t size,
1031                          const char *value)
1032 {
1033         struct smb2_handle handle;
1034         struct smb2_create create;
1035         NTSTATUS status;
1036         const char *full_name;
1037
1038         full_name = talloc_asprintf(mem_ctx, "%s%s", fname, sname);
1039         if (full_name == NULL) {
1040             torture_comment(tctx, "talloc_asprintf error\n");
1041             return false;
1042         }
1043         ZERO_STRUCT(create);
1044         create.in.desired_access = SEC_FILE_WRITE_DATA;
1045         create.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
1046         create.in.create_disposition = NTCREATEX_DISP_OPEN_IF;
1047         create.in.fname = full_name;
1048
1049         status = smb2_create(tree, mem_ctx, &create);
1050         if (!NT_STATUS_IS_OK(status)) {
1051                 if (value == NULL) {
1052                         return true;
1053                 } else {
1054                         torture_comment(tctx, "Unable to open stream %s\n",
1055                             full_name);
1056                         sleep(10000000);
1057                         return false;
1058                 }
1059         }
1060
1061         handle = create.out.file.handle;
1062         if (value == NULL) {
1063                 return true;
1064         }
1065
1066         status = smb2_util_write(tree, handle, value, offset, size);
1067
1068         if (!NT_STATUS_IS_OK(status)) {
1069                 torture_comment(tctx, "(%s) Failed to write %lu bytes to "
1070                     "stream '%s'\n", location, (long)size, full_name);
1071                 return false;
1072         }
1073
1074         smb2_util_close(tree, handle);
1075         return true;
1076 }
1077
1078 static bool torture_setup_local_xattr(struct torture_context *tctx,
1079                                       const char *path_option,
1080                                       const char *name,
1081                                       const char *xattr,
1082                                       const char *metadata,
1083                                       size_t size)
1084 {
1085         int ret = true;
1086         int result;
1087         const char *spath;
1088         char *path;
1089
1090         spath = torture_setting_string(tctx, path_option, NULL);
1091         if (spath == NULL) {
1092                 printf("No sharepath for option %s\n", path_option);
1093                 return false;
1094         }
1095
1096         path = talloc_asprintf(tctx, "%s/%s", spath, name);
1097
1098         result = setxattr(path, xattr, metadata, size, 0);
1099         if (result != 0) {
1100                 ret = false;
1101         }
1102
1103         TALLOC_FREE(path);
1104
1105         return ret;
1106 }
1107
1108 static bool torture_setup_local_file(struct torture_context *tctx,
1109                                      const char *path_option,
1110                                      const char *name,
1111                                      const char *buf,
1112                                      size_t size)
1113 {
1114         int fd;
1115         const char *spath;
1116         char *path;
1117         ssize_t rsize;
1118
1119         spath = torture_setting_string(tctx, path_option, NULL);
1120         if (spath == NULL) {
1121                 printf("No sharepath for option %s\n", path_option);
1122                 return false;
1123         }
1124
1125         path = talloc_asprintf(tctx, "%s/%s", spath, name);
1126         if (path == NULL) {
1127                 return false;
1128         }
1129
1130         fd = creat(path, S_IRWXU);
1131         TALLOC_FREE(path);
1132         if (fd == -1) {
1133                 return false;
1134         }
1135
1136         if ((buf == NULL) || (size == 0)) {
1137                 close(fd);
1138                 return true;
1139         }
1140
1141         rsize = write(fd, buf, size);
1142         if (rsize != size) {
1143                 return false;
1144         }
1145
1146         close(fd);
1147
1148         return true;
1149 }
1150
1151 /**
1152  * Create a file or directory
1153  **/
1154 static bool torture_setup_file(TALLOC_CTX *mem_ctx, struct smb2_tree *tree,
1155                                const char *name, bool dir)
1156 {
1157         struct smb2_create io;
1158         NTSTATUS status;
1159
1160         smb2_util_unlink(tree, name);
1161         ZERO_STRUCT(io);
1162         io.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED;
1163         io.in.file_attributes   = FILE_ATTRIBUTE_NORMAL;
1164         io.in.create_disposition = NTCREATEX_DISP_OVERWRITE_IF;
1165         io.in.share_access =
1166                 NTCREATEX_SHARE_ACCESS_DELETE|
1167                 NTCREATEX_SHARE_ACCESS_READ|
1168                 NTCREATEX_SHARE_ACCESS_WRITE;
1169         io.in.create_options = 0;
1170         io.in.fname = name;
1171         if (dir) {
1172                 io.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1173                 io.in.share_access &= ~NTCREATEX_SHARE_ACCESS_DELETE;
1174                 io.in.file_attributes   = FILE_ATTRIBUTE_DIRECTORY;
1175                 io.in.create_disposition = NTCREATEX_DISP_CREATE;
1176         }
1177
1178         status = smb2_create(tree, mem_ctx, &io);
1179         if (!NT_STATUS_IS_OK(status)) {
1180                 return false;
1181         }
1182
1183         status = smb2_util_close(tree, io.out.file.handle);
1184         if (!NT_STATUS_IS_OK(status)) {
1185                 return false;
1186         }
1187
1188         return true;
1189 }
1190
1191 static bool test_read_atalk_metadata(struct torture_context *tctx,
1192                                      struct smb2_tree *tree1,
1193                                      struct smb2_tree *tree2)
1194 {
1195         TALLOC_CTX *mem_ctx = talloc_new(tctx);
1196         const char *fname = BASEDIR "\\torture_read_metadata";
1197         NTSTATUS status;
1198         struct smb2_handle testdirh;
1199         bool ret = true;
1200         ssize_t len;
1201
1202         torture_comment(tctx, "Checking metadata access\n");
1203
1204         smb2_util_unlink(tree1, fname);
1205
1206         status = torture_smb2_testdir(tree1, BASEDIR, &testdirh);
1207         CHECK_STATUS(status, NT_STATUS_OK);
1208         smb2_util_close(tree1, testdirh);
1209
1210         ret = torture_setup_file(mem_ctx, tree1, fname, false);
1211         if (ret == false) {
1212                 goto done;
1213         }
1214
1215         ret = torture_setup_local_xattr(tctx, "localdir",
1216                                         BASEDIR "/torture_read_metadata",
1217                                         AFPINFO_EA_NETATALK,
1218                                         metadata_xattr, sizeof(metadata_xattr));
1219         if (ret == false) {
1220                 goto done;
1221         }
1222
1223         ret &= check_stream(tree1, __location__, tctx, mem_ctx, fname, AFPINFO_STREAM,
1224                             0, 60, 0, 4, "AFP");
1225
1226         ret &= check_stream(tree1, __location__, tctx, mem_ctx, fname, AFPINFO_STREAM,
1227                             0, 60, 16, 8, "BARRFOOO");
1228
1229         ret &= check_stream(tree1, __location__, tctx, mem_ctx, fname, AFPINFO_STREAM,
1230                             16, 8, 0, 8, "BARRFOOO");
1231
1232         /* Check reading offset and read size > sizeof(AFPINFO_STREAM) */
1233
1234         len = read_stream(tree1, __location__, tctx, mem_ctx, fname,
1235                           AFPINFO_STREAM, 0, 61);
1236         CHECK_VALUE(len, 60);
1237
1238         len = read_stream(tree1, __location__, tctx, mem_ctx, fname,
1239                           AFPINFO_STREAM, 59, 2);
1240         CHECK_VALUE(len, 1);
1241
1242         len = read_stream(tree1, __location__, tctx, mem_ctx, fname,
1243                           AFPINFO_STREAM, 60, 1);
1244         CHECK_VALUE(len, 0);
1245
1246         len = read_stream(tree1, __location__, tctx, mem_ctx, fname,
1247                           AFPINFO_STREAM, 61, 1);
1248         CHECK_VALUE(len, 0);
1249
1250 done:
1251         smb2_deltree(tree1, BASEDIR);
1252         talloc_free(mem_ctx);
1253         return ret;
1254 }
1255
1256 static bool test_write_atalk_metadata(struct torture_context *tctx,
1257                                       struct smb2_tree *tree1,
1258                                       struct smb2_tree *tree2)
1259 {
1260         TALLOC_CTX *mem_ctx = talloc_new(tctx);
1261         const char *fname = BASEDIR "\\torture_write_metadata";
1262         const char *type_creator = "SMB,OLE!";
1263         NTSTATUS status;
1264         struct smb2_handle testdirh;
1265         bool ret = true;
1266         AfpInfo *info;
1267
1268         smb2_util_unlink(tree1, fname);
1269
1270         status = torture_smb2_testdir(tree1, BASEDIR, &testdirh);
1271         CHECK_STATUS(status, NT_STATUS_OK);
1272         smb2_util_close(tree1, testdirh);
1273
1274         ret = torture_setup_file(mem_ctx, tree1, fname, false);
1275         if (ret == false) {
1276                 goto done;
1277         }
1278
1279         info = torture_afpinfo_new(mem_ctx);
1280         if (info == NULL) {
1281                 goto done;
1282         }
1283
1284         memcpy(info->afpi_FinderInfo, type_creator, 8);
1285         ret = torture_write_afpinfo(tree1, tctx, mem_ctx, fname, info);
1286         ret &= check_stream(tree1, __location__, tctx, mem_ctx, fname, AFPINFO_STREAM,
1287                             0, 60, 16, 8, type_creator);
1288
1289 done:
1290         smb2_deltree(tree1, BASEDIR);
1291         talloc_free(mem_ctx);
1292         return ret;
1293 }
1294
1295 static bool test_write_atalk_rfork_io(struct torture_context *tctx,
1296                                       struct smb2_tree *tree1,
1297                                       struct smb2_tree *tree2)
1298 {
1299         TALLOC_CTX *mem_ctx = talloc_new(tctx);
1300         const char *fname = BASEDIR "\\torture_write_rfork_io";
1301         const char *rfork = BASEDIR "\\torture_write_rfork_io" AFPRESOURCE_STREAM;
1302         const char *rfork_content = "1234567890";
1303         NTSTATUS status;
1304         struct smb2_handle testdirh;
1305         bool ret = true;
1306
1307         union smb_open io;
1308         struct smb2_handle filehandle;
1309         union smb_fileinfo finfo;
1310         union smb_setfileinfo sinfo;
1311
1312         smb2_util_unlink(tree1, fname);
1313
1314         status = torture_smb2_testdir(tree1, BASEDIR, &testdirh);
1315         CHECK_STATUS(status, NT_STATUS_OK);
1316         smb2_util_close(tree1, testdirh);
1317
1318         ret = torture_setup_file(mem_ctx, tree1, fname, false);
1319         if (ret == false) {
1320                 goto done;
1321         }
1322
1323         torture_comment(tctx, "(%s) writing to resource fork\n",
1324             __location__);
1325
1326         ret &= write_stream(tree1, __location__, tctx, mem_ctx,
1327                             fname, AFPRESOURCE_STREAM,
1328                             10, 10, rfork_content);
1329
1330         ret &= check_stream(tree1, __location__, tctx, mem_ctx,
1331                             fname, AFPRESOURCE_STREAM,
1332                             0, 20, 10, 10, rfork_content);
1333
1334         /* Check size after write */
1335
1336         ZERO_STRUCT(io);
1337         io.smb2.in.create_disposition = NTCREATEX_DISP_OPEN;
1338         io.smb2.in.desired_access = SEC_FILE_READ_ATTRIBUTE |
1339                 SEC_FILE_WRITE_ATTRIBUTE;
1340         io.smb2.in.fname = rfork;
1341         status = smb2_create(tree1, mem_ctx, &(io.smb2));
1342         CHECK_STATUS(status, NT_STATUS_OK);
1343         filehandle = io.smb2.out.file.handle;
1344
1345         torture_comment(tctx, "(%s) check resource fork size after write\n",
1346             __location__);
1347
1348         ZERO_STRUCT(finfo);
1349         finfo.generic.level = RAW_FILEINFO_ALL_INFORMATION;
1350         finfo.generic.in.file.handle = filehandle;
1351         status = smb2_getinfo_file(tree1, mem_ctx, &finfo);
1352         CHECK_STATUS(status, NT_STATUS_OK);
1353         if (finfo.all_info.out.size != 20) {
1354                 torture_result(tctx, TORTURE_FAIL,
1355                                "(%s) Incorrect resource fork size\n",
1356                                __location__);
1357                 ret = false;
1358                 smb2_util_close(tree1, filehandle);
1359                 goto done;
1360         }
1361         smb2_util_close(tree1, filehandle);
1362
1363         /* Write at large offset */
1364
1365         torture_comment(tctx, "(%s) writing to resource fork at large offset\n",
1366                         __location__);
1367
1368         ret &= write_stream(tree1, __location__, tctx, mem_ctx,
1369                             fname, AFPRESOURCE_STREAM,
1370                             (off_t)1<<32, 10, rfork_content);
1371
1372         ret &= check_stream(tree1, __location__, tctx, mem_ctx,
1373                             fname, AFPRESOURCE_STREAM,
1374                             (off_t)1<<32, 10, 0, 10, rfork_content);
1375
1376         /* Truncate back to size of 1 byte */
1377
1378         torture_comment(tctx, "(%s) truncate resource fork and check size\n",
1379                         __location__);
1380
1381         ZERO_STRUCT(io);
1382         io.smb2.in.create_disposition = NTCREATEX_DISP_OPEN;
1383         io.smb2.in.desired_access = SEC_FILE_READ_ATTRIBUTE |
1384                 SEC_FILE_WRITE_ATTRIBUTE;
1385         io.smb2.in.fname = rfork;
1386         status = smb2_create(tree1, mem_ctx, &(io.smb2));
1387         CHECK_STATUS(status, NT_STATUS_OK);
1388         filehandle = io.smb2.out.file.handle;
1389
1390         ZERO_STRUCT(sinfo);
1391         sinfo.end_of_file_info.level =
1392                 RAW_SFILEINFO_END_OF_FILE_INFORMATION;
1393         sinfo.end_of_file_info.in.file.handle = filehandle;
1394         sinfo.end_of_file_info.in.size = 1;
1395         status = smb2_setinfo_file(tree1, &sinfo);
1396         CHECK_STATUS(status, NT_STATUS_OK);
1397
1398         smb2_util_close(tree1, filehandle);
1399
1400         /* Now check size */
1401         ZERO_STRUCT(io);
1402         io.smb2.in.create_disposition = NTCREATEX_DISP_OPEN;
1403         io.smb2.in.desired_access = SEC_FILE_READ_ATTRIBUTE |
1404                 SEC_FILE_WRITE_ATTRIBUTE;
1405         io.smb2.in.fname = rfork;
1406         status = smb2_create(tree1, mem_ctx, &(io.smb2));
1407         CHECK_STATUS(status, NT_STATUS_OK);
1408         filehandle = io.smb2.out.file.handle;
1409
1410         ZERO_STRUCT(finfo);
1411         finfo.generic.level = RAW_FILEINFO_ALL_INFORMATION;
1412         finfo.generic.in.file.handle = filehandle;
1413         status = smb2_getinfo_file(tree1, mem_ctx, &finfo);
1414         CHECK_STATUS(status, NT_STATUS_OK);
1415         if (finfo.all_info.out.size != 1) {
1416                 torture_result(tctx, TORTURE_FAIL,
1417                                "(%s) Incorrect resource fork size\n",
1418                                __location__);
1419                 ret = false;
1420                 smb2_util_close(tree1, filehandle);
1421                 goto done;
1422         }
1423         smb2_util_close(tree1, filehandle);
1424
1425 done:
1426         smb2_deltree(tree1, BASEDIR);
1427         talloc_free(mem_ctx);
1428         return ret;
1429 }
1430
1431 static bool test_rfork_truncate(struct torture_context *tctx,
1432                                 struct smb2_tree *tree1,
1433                                 struct smb2_tree *tree2)
1434 {
1435         TALLOC_CTX *mem_ctx = talloc_new(tctx);
1436         const char *fname = BASEDIR "\\torture_rfork_truncate";
1437         const char *rfork = BASEDIR "\\torture_rfork_truncate" AFPRESOURCE_STREAM;
1438         const char *rfork_content = "1234567890";
1439         NTSTATUS status;
1440         struct smb2_handle testdirh;
1441         bool ret = true;
1442         struct smb2_create create;
1443         struct smb2_handle fh1, fh2, fh3;
1444         union smb_setfileinfo sinfo;
1445
1446         smb2_util_unlink(tree1, fname);
1447
1448         status = torture_smb2_testdir(tree1, BASEDIR, &testdirh);
1449         torture_assert_ntstatus_ok_goto(tctx, status, ret, done, "torture_smb2_testdir");
1450         smb2_util_close(tree1, testdirh);
1451
1452         ret = torture_setup_file(mem_ctx, tree1, fname, false);
1453         if (ret == false) {
1454                 goto done;
1455         }
1456
1457         ret &= write_stream(tree1, __location__, tctx, mem_ctx,
1458                             fname, AFPRESOURCE_STREAM,
1459                             10, 10, rfork_content);
1460
1461         /* Truncate back to size 0, further access MUST return ENOENT */
1462
1463         torture_comment(tctx, "(%s) truncate resource fork to size 0\n",
1464                         __location__);
1465
1466         ZERO_STRUCT(create);
1467         create.in.create_disposition  = NTCREATEX_DISP_OPEN;
1468         create.in.desired_access      = SEC_STD_READ_CONTROL | SEC_FILE_ALL;
1469         create.in.file_attributes     = FILE_ATTRIBUTE_NORMAL;
1470         create.in.fname               = fname;
1471         create.in.share_access        = NTCREATEX_SHARE_ACCESS_DELETE |
1472                 NTCREATEX_SHARE_ACCESS_READ |
1473                 NTCREATEX_SHARE_ACCESS_WRITE;
1474         status = smb2_create(tree1, mem_ctx, &create);
1475         torture_assert_ntstatus_ok_goto(tctx, status, ret, done, "smb2_create");
1476         fh1 = create.out.file.handle;
1477
1478         ZERO_STRUCT(create);
1479         create.in.create_disposition  = NTCREATEX_DISP_OPEN_IF;
1480         create.in.desired_access      = SEC_STD_READ_CONTROL | SEC_FILE_ALL;
1481         create.in.file_attributes     = FILE_ATTRIBUTE_NORMAL;
1482         create.in.fname               = rfork;
1483         create.in.share_access        = NTCREATEX_SHARE_ACCESS_DELETE |
1484                 NTCREATEX_SHARE_ACCESS_READ |
1485                 NTCREATEX_SHARE_ACCESS_WRITE;
1486         status = smb2_create(tree1, mem_ctx, &create);
1487         torture_assert_ntstatus_ok_goto(tctx, status, ret, done, "smb2_create");
1488         fh2 = create.out.file.handle;
1489
1490         ZERO_STRUCT(sinfo);
1491         sinfo.end_of_file_info.level = RAW_SFILEINFO_END_OF_FILE_INFORMATION;
1492         sinfo.end_of_file_info.in.file.handle = fh2;
1493         sinfo.end_of_file_info.in.size = 0;
1494         status = smb2_setinfo_file(tree1, &sinfo);
1495         torture_assert_ntstatus_ok_goto(tctx, status, ret, done, "smb2_setinfo_file");
1496
1497         /*
1498          * Now check size, we should get OBJECT_NAME_NOT_FOUND (!)
1499          */
1500         ZERO_STRUCT(create);
1501         create.in.create_disposition  = NTCREATEX_DISP_OPEN;
1502         create.in.desired_access      = SEC_FILE_ALL;
1503         create.in.file_attributes     = FILE_ATTRIBUTE_NORMAL;
1504         create.in.fname               = rfork;
1505         create.in.share_access        = NTCREATEX_SHARE_ACCESS_DELETE |
1506                 NTCREATEX_SHARE_ACCESS_READ |
1507                 NTCREATEX_SHARE_ACCESS_WRITE;
1508         status = smb2_create(tree1, mem_ctx, &create);
1509         torture_assert_ntstatus_equal_goto(tctx, status, NT_STATUS_OBJECT_NAME_NOT_FOUND, ret, done, "smb2_create");
1510
1511         /*
1512          * Do another open on the rfork and write to the new handle. A
1513          * naive server might unlink the AppleDouble resource fork
1514          * file when its truncated to 0 bytes above, so in case both
1515          * open handles share the same underlying fd, the unlink would
1516          * cause the below write to be lost.
1517          */
1518         ZERO_STRUCT(create);
1519         create.in.create_disposition  = NTCREATEX_DISP_OPEN_IF;
1520         create.in.desired_access      = SEC_STD_READ_CONTROL | SEC_FILE_ALL;
1521         create.in.file_attributes     = FILE_ATTRIBUTE_NORMAL;
1522         create.in.fname               = rfork;
1523         create.in.share_access        = NTCREATEX_SHARE_ACCESS_DELETE |
1524                 NTCREATEX_SHARE_ACCESS_READ |
1525                 NTCREATEX_SHARE_ACCESS_WRITE;
1526         status = smb2_create(tree1, mem_ctx, &create);
1527         torture_assert_ntstatus_ok_goto(tctx, status, ret, done, "smb2_create");
1528         fh3 = create.out.file.handle;
1529
1530         status = smb2_util_write(tree1, fh3, "foo", 0, 3);
1531         torture_assert_ntstatus_ok_goto(tctx, status, ret, done, "smb2_util_write");
1532
1533         smb2_util_close(tree1, fh3);
1534         smb2_util_close(tree1, fh2);
1535         smb2_util_close(tree1, fh1);
1536
1537         ret = check_stream(tree1, __location__, tctx, mem_ctx, fname, AFPRESOURCE_STREAM,
1538                            0, 3, 0, 3, "foo");
1539         torture_assert_goto(tctx, ret == true, ret, done, "check_stream");
1540
1541 done:
1542         smb2_util_unlink(tree1, fname);
1543         smb2_deltree(tree1, BASEDIR);
1544         talloc_free(mem_ctx);
1545         return ret;
1546 }
1547
1548 static bool test_rfork_create(struct torture_context *tctx,
1549                               struct smb2_tree *tree1,
1550                               struct smb2_tree *tree2)
1551 {
1552         TALLOC_CTX *mem_ctx = talloc_new(tctx);
1553         const char *fname = BASEDIR "\\torture_rfork_create";
1554         const char *rfork = BASEDIR "\\torture_rfork_create" AFPRESOURCE_STREAM;
1555         NTSTATUS status;
1556         struct smb2_handle testdirh;
1557         bool ret = true;
1558         struct smb2_create create;
1559         struct smb2_handle fh1;
1560         const char *streams[] = {
1561                 "::$DATA"
1562         };
1563         union smb_fileinfo finfo;
1564
1565         smb2_util_unlink(tree1, fname);
1566
1567         status = torture_smb2_testdir(tree1, BASEDIR, &testdirh);
1568         torture_assert_ntstatus_ok_goto(tctx, status, ret, done, "torture_smb2_testdir");
1569         smb2_util_close(tree1, testdirh);
1570
1571         ret = torture_setup_file(mem_ctx, tree1, fname, false);
1572         if (ret == false) {
1573                 goto done;
1574         }
1575
1576         torture_comment(tctx, "(%s) open rfork, should return ENOENT\n",
1577                         __location__);
1578
1579         ZERO_STRUCT(create);
1580         create.in.create_disposition  = NTCREATEX_DISP_OPEN;
1581         create.in.desired_access      = SEC_STD_READ_CONTROL | SEC_FILE_ALL;
1582         create.in.file_attributes     = FILE_ATTRIBUTE_NORMAL;
1583         create.in.fname               = rfork;
1584         create.in.share_access        = NTCREATEX_SHARE_ACCESS_DELETE |
1585                 NTCREATEX_SHARE_ACCESS_READ |
1586                 NTCREATEX_SHARE_ACCESS_WRITE;
1587         status = smb2_create(tree1, mem_ctx, &create);
1588         torture_assert_ntstatus_equal_goto(tctx, status, NT_STATUS_OBJECT_NAME_NOT_FOUND, ret, done, "smb2_create");
1589
1590         torture_comment(tctx, "(%s) create resource fork\n", __location__);
1591
1592         ZERO_STRUCT(create);
1593         create.in.create_disposition  = NTCREATEX_DISP_OPEN_IF;
1594         create.in.desired_access      = SEC_STD_READ_CONTROL | SEC_FILE_ALL;
1595         create.in.file_attributes     = FILE_ATTRIBUTE_NORMAL;
1596         create.in.fname               = rfork;
1597         create.in.share_access        = NTCREATEX_SHARE_ACCESS_DELETE |
1598                 NTCREATEX_SHARE_ACCESS_READ |
1599                 NTCREATEX_SHARE_ACCESS_WRITE;
1600         status = smb2_create(tree1, mem_ctx, &create);
1601         torture_assert_ntstatus_ok_goto(tctx, status, ret, done, "smb2_create");
1602         fh1 = create.out.file.handle;
1603
1604         torture_comment(tctx, "(%s) getinfo on create handle\n",
1605                         __location__);
1606
1607         ZERO_STRUCT(finfo);
1608         finfo.generic.level = RAW_FILEINFO_ALL_INFORMATION;
1609         finfo.generic.in.file.handle = fh1;
1610         status = smb2_getinfo_file(tree1, mem_ctx, &finfo);
1611         torture_assert_ntstatus_ok_goto(tctx, status, ret, done, "smb2_getinfo_file");
1612         if (finfo.all_info.out.size != 0) {
1613                 torture_result(tctx, TORTURE_FAIL,
1614                                "(%s) Incorrect resource fork size\n",
1615                                __location__);
1616                 ret = false;
1617                 smb2_util_close(tree1, fh1);
1618                 goto done;
1619         }
1620
1621         torture_comment(tctx, "(%s) open rfork, should still return ENOENT\n",
1622                         __location__);
1623
1624         ZERO_STRUCT(create);
1625         create.in.create_disposition  = NTCREATEX_DISP_OPEN;
1626         create.in.desired_access      = SEC_STD_READ_CONTROL | SEC_FILE_ALL;
1627         create.in.file_attributes     = FILE_ATTRIBUTE_NORMAL;
1628         create.in.fname               = rfork;
1629         create.in.share_access        = NTCREATEX_SHARE_ACCESS_DELETE |
1630                 NTCREATEX_SHARE_ACCESS_READ |
1631                 NTCREATEX_SHARE_ACCESS_WRITE;
1632         status = smb2_create(tree1, mem_ctx, &create);
1633         torture_assert_ntstatus_equal_goto(tctx, status, NT_STATUS_OBJECT_NAME_NOT_FOUND, ret, done, "smb2_create");
1634
1635         ZERO_STRUCT(create);
1636         create.in.fname = fname;
1637         create.in.create_disposition = NTCREATEX_DISP_OPEN;
1638         create.in.desired_access = SEC_STD_READ_CONTROL | SEC_FILE_ALL;
1639         create.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
1640         status = smb2_create(tree1, mem_ctx, &create);
1641         torture_assert_ntstatus_ok_goto(tctx, status, ret, done, "smb2_create");
1642
1643         ret = check_stream_list(tree1, tctx, fname, 1, streams,
1644                                 create.out.file.handle);
1645         torture_assert_goto(tctx, ret == true, ret, done, "check_stream_list");
1646         smb2_util_close(tree1, create.out.file.handle);
1647
1648         torture_comment(tctx, "(%s) close empty created rfork, open should return ENOENT\n",
1649                         __location__);
1650         smb2_util_close(tree1, fh1);
1651         ZERO_STRUCT(create);
1652         create.in.create_disposition  = NTCREATEX_DISP_OPEN;
1653         create.in.desired_access      = SEC_STD_READ_CONTROL | SEC_FILE_ALL;
1654         create.in.file_attributes     = FILE_ATTRIBUTE_NORMAL;
1655         create.in.fname               = rfork;
1656         create.in.share_access        = NTCREATEX_SHARE_ACCESS_DELETE |
1657                 NTCREATEX_SHARE_ACCESS_READ |
1658                 NTCREATEX_SHARE_ACCESS_WRITE;
1659         status = smb2_create(tree1, mem_ctx, &create);
1660         torture_assert_ntstatus_equal_goto(tctx, status, NT_STATUS_OBJECT_NAME_NOT_FOUND, ret, done, "smb2_create");
1661
1662 done:
1663         smb2_util_unlink(tree1, fname);
1664         smb2_deltree(tree1, BASEDIR);
1665         talloc_free(mem_ctx);
1666         return ret;
1667 }
1668
1669 static bool test_adouble_conversion(struct torture_context *tctx,
1670                                     struct smb2_tree *tree1,
1671                                     struct smb2_tree *tree2)
1672 {
1673         TALLOC_CTX *mem_ctx = talloc_new(tctx);
1674         const char *fname = BASEDIR "\\test_adouble_conversion";
1675         const char *fname_local = BASEDIR "/test_adouble_conversion";
1676         const char *adname_local = BASEDIR "/._test_adouble_conversion";
1677         NTSTATUS status;
1678         struct smb2_handle testdirh;
1679         bool ret = true;
1680         const char *data = "This resource fork intentionally left blank";
1681         size_t datalen = strlen(data);
1682
1683         smb2_util_unlink(tree1, fname);
1684
1685         status = torture_smb2_testdir(tree1, BASEDIR, &testdirh);
1686         CHECK_STATUS(status, NT_STATUS_OK);
1687         smb2_util_close(tree1, testdirh);
1688
1689         ret = torture_setup_local_file(tctx, "localdir", fname_local,
1690                                        NULL, 0);
1691         if (ret == false) {
1692                 goto done;
1693         }
1694
1695         ret = torture_setup_local_file(tctx, "localdir", adname_local,
1696                                        osx_adouble_w_xattr,
1697                                        sizeof(osx_adouble_w_xattr));
1698         if (ret == false) {
1699                 goto done;
1700         }
1701
1702         torture_comment(tctx, "(%s) test OS X AppleDouble conversion\n",
1703             __location__);
1704
1705         ret &= check_stream(tree1, __location__, tctx, mem_ctx,
1706                             fname, AFPRESOURCE_STREAM,
1707                             16, datalen, 0, datalen, data);
1708
1709 done:
1710         smb2_deltree(tree1, BASEDIR);
1711         talloc_free(mem_ctx);
1712         return ret;
1713 }
1714
1715 static bool test_aapl(struct torture_context *tctx,
1716                       struct smb2_tree *tree1,
1717                       struct smb2_tree *tree2)
1718 {
1719         TALLOC_CTX *mem_ctx = talloc_new(tctx);
1720         const char *fname = BASEDIR "\\test_aapl";
1721         NTSTATUS status;
1722         struct smb2_handle testdirh;
1723         bool ret = true;
1724         struct smb2_create io;
1725         DATA_BLOB data;
1726         struct smb2_create_blob *aapl = NULL;
1727         AfpInfo *info;
1728         const char *type_creator = "SMB,OLE!";
1729         char type_creator_buf[9];
1730         uint32_t aapl_cmd;
1731         uint32_t aapl_reply_bitmap;
1732         uint32_t aapl_server_caps;
1733         uint32_t aapl_vol_caps;
1734         char *model;
1735         struct smb2_find f;
1736         unsigned int count;
1737         union smb_search_data *d;
1738         uint64_t rfork_len;
1739
1740         smb2_deltree(tree1, BASEDIR);
1741
1742         status = torture_smb2_testdir(tree1, BASEDIR, &testdirh);
1743         CHECK_STATUS(status, NT_STATUS_OK);
1744         smb2_util_close(tree1, testdirh);
1745
1746         ZERO_STRUCT(io);
1747         io.in.desired_access     = SEC_FLAG_MAXIMUM_ALLOWED;
1748         io.in.file_attributes    = FILE_ATTRIBUTE_NORMAL;
1749         io.in.create_disposition = NTCREATEX_DISP_OVERWRITE_IF;
1750         io.in.share_access = (NTCREATEX_SHARE_ACCESS_DELETE |
1751                               NTCREATEX_SHARE_ACCESS_READ |
1752                               NTCREATEX_SHARE_ACCESS_WRITE);
1753         io.in.fname = fname;
1754
1755         /*
1756          * Issuing an SMB2/CREATE with a suitably formed AAPL context,
1757          * controls behaviour of Apple's SMB2 extensions for the whole
1758          * session!
1759          */
1760
1761         data = data_blob_talloc(mem_ctx, NULL, 3 * sizeof(uint64_t));
1762         SBVAL(data.data, 0, SMB2_CRTCTX_AAPL_SERVER_QUERY);
1763         SBVAL(data.data, 8, (SMB2_CRTCTX_AAPL_SERVER_CAPS |
1764                              SMB2_CRTCTX_AAPL_VOLUME_CAPS |
1765                              SMB2_CRTCTX_AAPL_MODEL_INFO));
1766         SBVAL(data.data, 16, (SMB2_CRTCTX_AAPL_SUPPORTS_READ_DIR_ATTR |
1767                               SMB2_CRTCTX_AAPL_UNIX_BASED |
1768                               SMB2_CRTCTX_AAPL_SUPPORTS_NFS_ACE));
1769
1770         torture_comment(tctx, "Testing SMB2 create context AAPL\n");
1771         status = smb2_create_blob_add(tctx, &io.in.blobs, "AAPL", data);
1772         CHECK_STATUS(status, NT_STATUS_OK);
1773
1774         status = smb2_create(tree1, tctx, &io);
1775         CHECK_STATUS(status, NT_STATUS_OK);
1776         status = smb2_util_close(tree1, io.out.file.handle);
1777         CHECK_STATUS(status, NT_STATUS_OK);
1778
1779         /*
1780          * Now check returned AAPL context
1781          */
1782         torture_comment(tctx, "Comparing returned AAPL capabilities\n");
1783
1784         aapl = smb2_create_blob_find(&io.out.blobs,
1785                                      SMB2_CREATE_TAG_AAPL);
1786
1787         if (aapl->data.length != 50) {
1788                 /*
1789                  * uint32_t CommandCode = kAAPL_SERVER_QUERY
1790                  * uint32_t Reserved = 0;
1791                  * uint64_t ReplyBitmap = kAAPL_SERVER_CAPS |
1792                  *                        kAAPL_VOLUME_CAPS |
1793                  *                        kAAPL_MODEL_INFO;
1794                  * uint64_t ServerCaps = kAAPL_SUPPORTS_READDIR_ATTR |
1795                  *                       kAAPL_SUPPORTS_OSX_COPYFILE;
1796                  * uint64_t VolumeCaps = kAAPL_SUPPORT_RESOLVE_ID |
1797                  *                       kAAPL_CASE_SENSITIVE;
1798                  * uint32_t Pad2 = 0;
1799                  * uint32_t ModelStringLen = 10;
1800                  * ucs2_t ModelString[5] = "Samba";
1801                  */
1802                 ret = false;
1803                 goto done;
1804         }
1805
1806         aapl_cmd = IVAL(aapl->data.data, 0);
1807         if (aapl_cmd != SMB2_CRTCTX_AAPL_SERVER_QUERY) {
1808                 torture_result(tctx, TORTURE_FAIL,
1809                                "(%s) unexpected cmd: %d",
1810                                __location__, (int)aapl_cmd);
1811                 ret = false;
1812                 goto done;
1813         }
1814
1815         aapl_reply_bitmap = BVAL(aapl->data.data, 8);
1816         if (aapl_reply_bitmap != (SMB2_CRTCTX_AAPL_SERVER_CAPS |
1817                                   SMB2_CRTCTX_AAPL_VOLUME_CAPS |
1818                                   SMB2_CRTCTX_AAPL_MODEL_INFO)) {
1819                 torture_result(tctx, TORTURE_FAIL,
1820                                "(%s) unexpected reply_bitmap: %d",
1821                                __location__, (int)aapl_reply_bitmap);
1822                 ret = false;
1823                 goto done;
1824         }
1825
1826         aapl_server_caps = BVAL(aapl->data.data, 16);
1827         if (aapl_server_caps != (SMB2_CRTCTX_AAPL_UNIX_BASED |
1828                                  SMB2_CRTCTX_AAPL_SUPPORTS_READ_DIR_ATTR |
1829                                  SMB2_CRTCTX_AAPL_SUPPORTS_NFS_ACE |
1830                                  SMB2_CRTCTX_AAPL_SUPPORTS_OSX_COPYFILE)) {
1831                 torture_result(tctx, TORTURE_FAIL,
1832                                "(%s) unexpected server_caps: %d",
1833                                __location__, (int)aapl_server_caps);
1834                 ret = false;
1835                 goto done;
1836         }
1837
1838         aapl_vol_caps = BVAL(aapl->data.data, 24);
1839         if (aapl_vol_caps != SMB2_CRTCTX_AAPL_CASE_SENSITIVE) {
1840                 /* this will fail on a case insensitive fs ... */
1841                 torture_result(tctx, TORTURE_FAIL,
1842                                "(%s) unexpected vol_caps: %d",
1843                                __location__, (int)aapl_vol_caps);
1844                 ret = false;
1845                 goto done;
1846         }
1847
1848         ret = convert_string_talloc(mem_ctx,
1849                                     CH_UTF16LE, CH_UNIX,
1850                                     aapl->data.data + 40, 10,
1851                                     &model, NULL);
1852         if (ret == false) {
1853                 torture_result(tctx, TORTURE_FAIL,
1854                                "(%s) convert_string_talloc() failed",
1855                                __location__);
1856                 goto done;
1857         }
1858         torture_comment(tctx, "Got server model: \"%s\"\n", model);
1859
1860         /*
1861          * Now that Requested AAPL extensions are enabled, setup some
1862          * Mac files with metadata and resource fork
1863          */
1864         ret = torture_setup_file(mem_ctx, tree1, fname, false);
1865         if (ret == false) {
1866                 torture_result(tctx, TORTURE_FAIL,
1867                                "(%s) torture_setup_file() failed",
1868                                __location__);
1869                 goto done;
1870         }
1871
1872         info = torture_afpinfo_new(mem_ctx);
1873         if (info == NULL) {
1874                 torture_result(tctx, TORTURE_FAIL,
1875                                "(%s) torture_afpinfo_new() failed",
1876                                __location__);
1877                 ret = false;
1878                 goto done;
1879         }
1880
1881         memcpy(info->afpi_FinderInfo, type_creator, 8);
1882         ret = torture_write_afpinfo(tree1, tctx, mem_ctx, fname, info);
1883         if (ret == false) {
1884                 torture_result(tctx, TORTURE_FAIL,
1885                                "(%s) torture_write_afpinfo() failed",
1886                                __location__);
1887                 goto done;
1888         }
1889
1890         ret = write_stream(tree1, __location__, tctx, mem_ctx,
1891                            fname, AFPRESOURCE_STREAM,
1892                            0, 3, "foo");
1893         if (ret == false) {
1894                 torture_result(tctx, TORTURE_FAIL,
1895                                "(%s) write_stream() failed",
1896                                __location__);
1897                 goto done;
1898         }
1899
1900         /*
1901          * Ok, file is prepared, now call smb2/find
1902          */
1903
1904         ZERO_STRUCT(io);
1905         io.in.desired_access = SEC_RIGHTS_DIR_ALL;
1906         io.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1907         io.in.file_attributes = FILE_ATTRIBUTE_DIRECTORY;
1908         io.in.share_access = (NTCREATEX_SHARE_ACCESS_READ |
1909                               NTCREATEX_SHARE_ACCESS_WRITE |
1910                               NTCREATEX_SHARE_ACCESS_DELETE);
1911         io.in.create_disposition = NTCREATEX_DISP_OPEN;
1912         io.in.fname = BASEDIR;
1913         status = smb2_create(tree1, tctx, &io);
1914         CHECK_STATUS(status, NT_STATUS_OK);
1915
1916         ZERO_STRUCT(f);
1917         f.in.file.handle        = io.out.file.handle;
1918         f.in.pattern            = "test_aapl";
1919         f.in.continue_flags     = SMB2_CONTINUE_FLAG_SINGLE;
1920         f.in.max_response_size  = 0x1000;
1921         f.in.level              = SMB2_FIND_ID_BOTH_DIRECTORY_INFO;
1922
1923         status = smb2_find_level(tree1, tree1, &f, &count, &d);
1924         CHECK_STATUS(status, NT_STATUS_OK);
1925
1926         status = smb2_util_close(tree1, io.out.file.handle);
1927         CHECK_STATUS(status, NT_STATUS_OK);
1928
1929         if (strcmp(d[0].id_both_directory_info.name.s, "test_aapl") != 0) {
1930                 torture_result(tctx, TORTURE_FAIL,
1931                                "(%s) write_stream() failed",
1932                                __location__);
1933                 ret = false;
1934                 goto done;
1935         }
1936
1937         if (d[0].id_both_directory_info.short_name.private_length != 24) {
1938                 torture_result(tctx, TORTURE_FAIL,
1939                                "(%s) bad short_name length %" PRIu32 ", expected 24",
1940                                __location__, d[0].id_both_directory_info.short_name.private_length);
1941                 ret = false;
1942                 goto done;
1943         }
1944
1945         torture_comment(tctx, "short_name buffer:\n");
1946         dump_data(0, d[0].id_both_directory_info.short_name_buf, 24);
1947
1948         /*
1949          * Extract data as specified by the AAPL extension:
1950          * - ea_size contains max_access
1951          * - short_name contains resource fork length + FinderInfo
1952          * - reserved2 contains the unix mode
1953          */
1954         torture_comment(tctx, "mac_access: %" PRIx32 "\n",
1955                         d[0].id_both_directory_info.ea_size);
1956
1957         rfork_len = BVAL(d[0].id_both_directory_info.short_name_buf, 0);
1958         if (rfork_len != 3) {
1959                 torture_result(tctx, TORTURE_FAIL,
1960                                "(%s) expected resource fork length 3, got: %" PRIu64,
1961                                __location__, rfork_len);
1962                 ret = false;
1963                 goto done;
1964         }
1965
1966         memcpy(type_creator_buf, d[0].id_both_directory_info.short_name_buf + 8, 8);
1967         type_creator_buf[8] = 0;
1968         if (strcmp(type_creator, type_creator_buf) != 0) {
1969                 torture_result(tctx, TORTURE_FAIL,
1970                                "(%s) expected type/creator \"%s\" , got: %s",
1971                                __location__, type_creator, type_creator_buf);
1972                 ret = false;
1973                 goto done;
1974         }
1975
1976 done:
1977         talloc_free(mem_ctx);
1978         return ret;
1979 }
1980
1981 static uint64_t patt_hash(uint64_t off)
1982 {
1983         return off;
1984 }
1985
1986 static bool write_pattern(struct torture_context *torture,
1987                           struct smb2_tree *tree, TALLOC_CTX *mem_ctx,
1988                           struct smb2_handle h, uint64_t off, uint64_t len,
1989                           uint64_t patt_off)
1990 {
1991         NTSTATUS status;
1992         uint64_t i;
1993         uint8_t *buf;
1994         uint64_t io_sz = MIN(1024 * 64, len);
1995
1996         if (len == 0) {
1997                 return true;
1998         }
1999
2000         torture_assert(torture, (len % 8) == 0, "invalid write len");
2001
2002         buf = talloc_zero_size(mem_ctx, io_sz);
2003         torture_assert(torture, (buf != NULL), "no memory for file data buf");
2004
2005         while (len > 0) {
2006                 for (i = 0; i <= io_sz - 8; i += 8) {
2007                         SBVAL(buf, i, patt_hash(patt_off));
2008                         patt_off += 8;
2009                 }
2010
2011                 status = smb2_util_write(tree, h,
2012                                          buf, off, io_sz);
2013                 torture_assert_ntstatus_ok(torture, status, "file write");
2014
2015                 len -= io_sz;
2016                 off += io_sz;
2017         }
2018
2019         talloc_free(buf);
2020
2021         return true;
2022 }
2023
2024 static bool check_pattern(struct torture_context *torture,
2025                           struct smb2_tree *tree, TALLOC_CTX *mem_ctx,
2026                           struct smb2_handle h, uint64_t off, uint64_t len,
2027                           uint64_t patt_off)
2028 {
2029         if (len == 0) {
2030                 return true;
2031         }
2032
2033         torture_assert(torture, (len % 8) == 0, "invalid read len");
2034
2035         while (len > 0) {
2036                 uint64_t i;
2037                 struct smb2_read r;
2038                 NTSTATUS status;
2039                 uint64_t io_sz = MIN(1024 * 64, len);
2040
2041                 ZERO_STRUCT(r);
2042                 r.in.file.handle = h;
2043                 r.in.length      = io_sz;
2044                 r.in.offset      = off;
2045                 status = smb2_read(tree, mem_ctx, &r);
2046                 torture_assert_ntstatus_ok(torture, status, "read");
2047
2048                 torture_assert_u64_equal(torture, r.out.data.length, io_sz,
2049                                          "read data len mismatch");
2050
2051                 for (i = 0; i <= io_sz - 8; i += 8, patt_off += 8) {
2052                         uint64_t data = BVAL(r.out.data.data, i);
2053                         torture_assert_u64_equal(torture, data, patt_hash(patt_off),
2054                                                  talloc_asprintf(torture, "read data "
2055                                                                  "pattern bad at %llu\n",
2056                                                                  (unsigned long long)off + i));
2057                 }
2058                 talloc_free(r.out.data.data);
2059                 len -= io_sz;
2060                 off += io_sz;
2061         }
2062
2063         return true;
2064 }
2065
2066 static bool test_setup_open(struct torture_context *torture,
2067                             struct smb2_tree *tree, TALLOC_CTX *mem_ctx,
2068                             const char *fname,
2069                             struct smb2_handle *fh,
2070                             uint32_t desired_access,
2071                             uint32_t file_attributes)
2072 {
2073         struct smb2_create io;
2074         NTSTATUS status;
2075
2076         ZERO_STRUCT(io);
2077         io.in.desired_access = desired_access;
2078         io.in.file_attributes = file_attributes;
2079         io.in.create_disposition = NTCREATEX_DISP_OPEN_IF;
2080         io.in.share_access =
2081                 NTCREATEX_SHARE_ACCESS_DELETE|
2082                 NTCREATEX_SHARE_ACCESS_READ|
2083                 NTCREATEX_SHARE_ACCESS_WRITE;
2084         if (file_attributes & FILE_ATTRIBUTE_DIRECTORY) {
2085                 io.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
2086         }
2087         io.in.fname = fname;
2088
2089         status = smb2_create(tree, mem_ctx, &io);
2090         torture_assert_ntstatus_ok(torture, status, "file create");
2091
2092         *fh = io.out.file.handle;
2093
2094         return true;
2095 }
2096
2097 static bool test_setup_create_fill(struct torture_context *torture,
2098                                    struct smb2_tree *tree, TALLOC_CTX *mem_ctx,
2099                                    const char *fname,
2100                                    struct smb2_handle *fh,
2101                                    uint64_t size,
2102                                    uint32_t desired_access,
2103                                    uint32_t file_attributes)
2104 {
2105         bool ok;
2106
2107         ok = test_setup_open(torture, tree, mem_ctx,
2108                              fname,
2109                              fh,
2110                              desired_access,
2111                              file_attributes);
2112         torture_assert(torture, ok, "file open");
2113
2114         if (size > 0) {
2115                 ok = write_pattern(torture, tree, mem_ctx, *fh, 0, size, 0);
2116                 torture_assert(torture, ok, "write pattern");
2117         }
2118         return true;
2119 }
2120
2121 static bool test_setup_copy_chunk(struct torture_context *torture,
2122                                   struct smb2_tree *tree, TALLOC_CTX *mem_ctx,
2123                                   uint32_t nchunks,
2124                                   struct smb2_handle *src_h,
2125                                   uint64_t src_size,
2126                                   uint32_t src_desired_access,
2127                                   struct smb2_handle *dest_h,
2128                                   uint64_t dest_size,
2129                                   uint32_t dest_desired_access,
2130                                   struct srv_copychunk_copy *cc_copy,
2131                                   union smb_ioctl *io)
2132 {
2133         struct req_resume_key_rsp res_key;
2134         bool ok;
2135         NTSTATUS status;
2136         enum ndr_err_code ndr_ret;
2137
2138         ok = test_setup_create_fill(torture, tree, mem_ctx, FNAME_CC_SRC,
2139                                     src_h, src_size, src_desired_access,
2140                                     FILE_ATTRIBUTE_NORMAL);
2141         torture_assert(torture, ok, "src file create fill");
2142
2143         ok = test_setup_create_fill(torture, tree, mem_ctx, FNAME_CC_DST,
2144                                     dest_h, dest_size, dest_desired_access,
2145                                     FILE_ATTRIBUTE_NORMAL);
2146         torture_assert(torture, ok, "dest file create fill");
2147
2148         ZERO_STRUCTPN(io);
2149         io->smb2.level = RAW_IOCTL_SMB2;
2150         io->smb2.in.file.handle = *src_h;
2151         io->smb2.in.function = FSCTL_SRV_REQUEST_RESUME_KEY;
2152         /* Allow for Key + ContextLength + Context */
2153         io->smb2.in.max_response_size = 32;
2154         io->smb2.in.flags = SMB2_IOCTL_FLAG_IS_FSCTL;
2155
2156         status = smb2_ioctl(tree, mem_ctx, &io->smb2);
2157         torture_assert_ntstatus_ok(torture, status,
2158                                    "FSCTL_SRV_REQUEST_RESUME_KEY");
2159
2160         ndr_ret = ndr_pull_struct_blob(&io->smb2.out.out, mem_ctx, &res_key,
2161                         (ndr_pull_flags_fn_t)ndr_pull_req_resume_key_rsp);
2162
2163         torture_assert_ndr_success(torture, ndr_ret,
2164                                    "ndr_pull_req_resume_key_rsp");
2165
2166         ZERO_STRUCTPN(io);
2167         io->smb2.level = RAW_IOCTL_SMB2;
2168         io->smb2.in.file.handle = *dest_h;
2169         io->smb2.in.function = FSCTL_SRV_COPYCHUNK;
2170         io->smb2.in.max_response_size = sizeof(struct srv_copychunk_rsp);
2171         io->smb2.in.flags = SMB2_IOCTL_FLAG_IS_FSCTL;
2172
2173         ZERO_STRUCTPN(cc_copy);
2174         memcpy(cc_copy->source_key, res_key.resume_key, ARRAY_SIZE(cc_copy->source_key));
2175         cc_copy->chunk_count = nchunks;
2176         cc_copy->chunks = talloc_zero_array(mem_ctx, struct srv_copychunk, nchunks);
2177         torture_assert(torture, (cc_copy->chunks != NULL), "no memory for chunks");
2178
2179         return true;
2180 }
2181
2182
2183 static bool check_copy_chunk_rsp(struct torture_context *torture,
2184                                  struct srv_copychunk_rsp *cc_rsp,
2185                                  uint32_t ex_chunks_written,
2186                                  uint32_t ex_chunk_bytes_written,
2187                                  uint32_t ex_total_bytes_written)
2188 {
2189         torture_assert_int_equal(torture, cc_rsp->chunks_written,
2190                                  ex_chunks_written, "num chunks");
2191         torture_assert_int_equal(torture, cc_rsp->chunk_bytes_written,
2192                                  ex_chunk_bytes_written, "chunk bytes written");
2193         torture_assert_int_equal(torture, cc_rsp->total_bytes_written,
2194                                  ex_total_bytes_written, "chunk total bytes");
2195         return true;
2196 }
2197
2198 static bool neg_aapl_copyfile(struct torture_context *tctx,
2199                               struct smb2_tree *tree,
2200                               uint64_t flags)
2201 {
2202         TALLOC_CTX *mem_ctx = talloc_new(tctx);
2203         const char *fname = "aapl";
2204         NTSTATUS status;
2205         struct smb2_create io;
2206         DATA_BLOB data;
2207         struct smb2_create_blob *aapl = NULL;
2208         uint32_t aapl_cmd;
2209         uint32_t aapl_reply_bitmap;
2210         uint32_t aapl_server_caps;
2211         bool ret = true;
2212
2213         ZERO_STRUCT(io);
2214         io.in.desired_access     = SEC_FLAG_MAXIMUM_ALLOWED;
2215         io.in.file_attributes    = FILE_ATTRIBUTE_NORMAL;
2216         io.in.create_disposition = NTCREATEX_DISP_OVERWRITE_IF;
2217         io.in.share_access = (NTCREATEX_SHARE_ACCESS_DELETE |
2218                               NTCREATEX_SHARE_ACCESS_READ |
2219                               NTCREATEX_SHARE_ACCESS_WRITE);
2220         io.in.fname = fname;
2221
2222         data = data_blob_talloc(mem_ctx, NULL, 3 * sizeof(uint64_t));
2223         SBVAL(data.data, 0, SMB2_CRTCTX_AAPL_SERVER_QUERY);
2224         SBVAL(data.data, 8, (SMB2_CRTCTX_AAPL_SERVER_CAPS));
2225         SBVAL(data.data, 16, flags);
2226
2227         status = smb2_create_blob_add(tctx, &io.in.blobs, "AAPL", data);
2228         CHECK_STATUS(status, NT_STATUS_OK);
2229
2230         status = smb2_create(tree, tctx, &io);
2231         CHECK_STATUS(status, NT_STATUS_OK);
2232
2233         aapl = smb2_create_blob_find(&io.out.blobs,
2234                                      SMB2_CREATE_TAG_AAPL);
2235         if (aapl == NULL) {
2236                 ret = false;
2237                 goto done;
2238
2239         }
2240         if (aapl->data.length < 24) {
2241                 ret = false;
2242                 goto done;
2243         }
2244
2245         aapl_cmd = IVAL(aapl->data.data, 0);
2246         if (aapl_cmd != SMB2_CRTCTX_AAPL_SERVER_QUERY) {
2247                 torture_result(tctx, TORTURE_FAIL,
2248                                "(%s) unexpected cmd: %d",
2249                                __location__, (int)aapl_cmd);
2250                 ret = false;
2251                 goto done;
2252         }
2253
2254         aapl_reply_bitmap = BVAL(aapl->data.data, 8);
2255         if (!(aapl_reply_bitmap & SMB2_CRTCTX_AAPL_SERVER_CAPS)) {
2256                 torture_result(tctx, TORTURE_FAIL,
2257                                "(%s) unexpected reply_bitmap: %d",
2258                                __location__, (int)aapl_reply_bitmap);
2259                 ret = false;
2260                 goto done;
2261         }
2262
2263         aapl_server_caps = BVAL(aapl->data.data, 16);
2264         if (!(aapl_server_caps & flags)) {
2265                 torture_result(tctx, TORTURE_FAIL,
2266                                "(%s) unexpected server_caps: %d",
2267                                __location__, (int)aapl_server_caps);
2268                 ret = false;
2269                 goto done;
2270         }
2271
2272 done:
2273         status = smb2_util_close(tree, io.out.file.handle);
2274         CHECK_STATUS(status, NT_STATUS_OK);
2275
2276         smb2_util_unlink(tree, "aapl");
2277         talloc_free(mem_ctx);
2278         return ret;
2279 }
2280
2281 static bool test_copyfile(struct torture_context *torture,
2282                           struct smb2_tree *tree)
2283 {
2284         struct smb2_handle src_h;
2285         struct smb2_handle dest_h;
2286         NTSTATUS status;
2287         union smb_ioctl io;
2288         TALLOC_CTX *tmp_ctx = talloc_new(tree);
2289         struct srv_copychunk_copy cc_copy;
2290         struct srv_copychunk_rsp cc_rsp;
2291         enum ndr_err_code ndr_ret;
2292         bool ok;
2293
2294         /*
2295          * First test a copy_chunk with a 0 chunk count without having
2296          * enabled this via AAPL. The request must not fail and the
2297          * copied length in the response must be 0. This is verified
2298          * against Windows 2008r2.
2299          */
2300
2301         ok = test_setup_copy_chunk(torture, tree, tmp_ctx,
2302                                    0, /* 0 chunks, copyfile semantics */
2303                                    &src_h, 4096, /* fill 4096 byte src file */
2304                                    SEC_FILE_READ_DATA | SEC_FILE_WRITE_DATA,
2305                                    &dest_h, 0,  /* 0 byte dest file */
2306                                    SEC_FILE_READ_DATA | SEC_FILE_WRITE_DATA,
2307                                    &cc_copy,
2308                                    &io);
2309         if (!ok) {
2310                 torture_fail_goto(torture, done, "setup copy chunk error");
2311         }
2312
2313         ndr_ret = ndr_push_struct_blob(&io.smb2.in.out, tmp_ctx,
2314                                        &cc_copy,
2315                         (ndr_push_flags_fn_t)ndr_push_srv_copychunk_copy);
2316         torture_assert_ndr_success(torture, ndr_ret,
2317                                    "ndr_push_srv_copychunk_copy");
2318
2319         status = smb2_ioctl(tree, tmp_ctx, &io.smb2);
2320         torture_assert_ntstatus_ok_goto(torture, status, ok, done, "FSCTL_SRV_COPYCHUNK");
2321
2322         ndr_ret = ndr_pull_struct_blob(&io.smb2.out.out, tmp_ctx,
2323                                        &cc_rsp,
2324                         (ndr_pull_flags_fn_t)ndr_pull_srv_copychunk_rsp);
2325         torture_assert_ndr_success(torture, ndr_ret,
2326                                    "ndr_pull_srv_copychunk_rsp");
2327
2328         ok = check_copy_chunk_rsp(torture, &cc_rsp,
2329                                   0,    /* chunks written */
2330                                   0,    /* chunk bytes unsuccessfully written */
2331                                   0); /* total bytes written */
2332         if (!ok) {
2333                 torture_fail_goto(torture, done, "bad copy chunk response data");
2334         }
2335
2336         /*
2337          * Now enable AAPL copyfile and test again, the file and the
2338          * stream must be copied by the server.
2339          */
2340         ok = neg_aapl_copyfile(torture, tree,
2341                                SMB2_CRTCTX_AAPL_SUPPORTS_OSX_COPYFILE);
2342         if (!ok) {
2343                 torture_skip_goto(torture, done, "missing AAPL copyfile");
2344                 goto done;
2345         }
2346
2347         smb2_util_close(tree, src_h);
2348         smb2_util_close(tree, dest_h);
2349         smb2_util_unlink(tree, FNAME_CC_SRC);
2350         smb2_util_unlink(tree, FNAME_CC_DST);
2351
2352         ok = torture_setup_file(tmp_ctx, tree, FNAME_CC_SRC, false);
2353         if (!ok) {
2354                 torture_fail(torture, "setup file error");
2355         }
2356         ok = write_stream(tree, __location__, torture, tmp_ctx,
2357                             FNAME_CC_SRC, AFPRESOURCE_STREAM,
2358                             10, 10, "1234567890");
2359         if (!ok) {
2360                 torture_fail(torture, "setup stream error");
2361         }
2362
2363         ok = test_setup_copy_chunk(torture, tree, tmp_ctx,
2364                                    0, /* 0 chunks, copyfile semantics */
2365                                    &src_h, 4096, /* fill 4096 byte src file */
2366                                    SEC_FILE_READ_DATA | SEC_FILE_WRITE_DATA,
2367                                    &dest_h, 0,  /* 0 byte dest file */
2368                                    SEC_FILE_READ_DATA | SEC_FILE_WRITE_DATA,
2369                                    &cc_copy,
2370                                    &io);
2371         if (!ok) {
2372                 torture_fail_goto(torture, done, "setup copy chunk error");
2373         }
2374
2375         ndr_ret = ndr_push_struct_blob(&io.smb2.in.out, tmp_ctx,
2376                                        &cc_copy,
2377                         (ndr_push_flags_fn_t)ndr_push_srv_copychunk_copy);
2378         torture_assert_ndr_success(torture, ndr_ret,
2379                                    "ndr_push_srv_copychunk_copy");
2380
2381         status = smb2_ioctl(tree, tmp_ctx, &io.smb2);
2382         torture_assert_ntstatus_ok_goto(torture, status, ok, done, "FSCTL_SRV_COPYCHUNK");
2383
2384         ndr_ret = ndr_pull_struct_blob(&io.smb2.out.out, tmp_ctx,
2385                                        &cc_rsp,
2386                         (ndr_pull_flags_fn_t)ndr_pull_srv_copychunk_rsp);
2387         torture_assert_ndr_success(torture, ndr_ret,
2388                                    "ndr_pull_srv_copychunk_rsp");
2389
2390         ok = check_copy_chunk_rsp(torture, &cc_rsp,
2391                                   0,    /* chunks written */
2392                                   0,    /* chunk bytes unsuccessfully written */
2393                                   4096); /* total bytes written */
2394         if (!ok) {
2395                 torture_fail_goto(torture, done, "bad copy chunk response data");
2396         }
2397
2398         ok = test_setup_open(torture, tree, tmp_ctx, FNAME_CC_DST, &dest_h,
2399                              SEC_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL);
2400         if (!ok) {
2401                 torture_fail_goto(torture, done,"open failed");
2402         }
2403         ok = check_pattern(torture, tree, tmp_ctx, dest_h, 0, 4096, 0);
2404         if (!ok) {
2405                 torture_fail_goto(torture, done, "inconsistent file data");
2406         }
2407
2408         ok = check_stream(tree, __location__, torture, tmp_ctx,
2409                             FNAME_CC_DST, AFPRESOURCE_STREAM,
2410                             0, 20, 10, 10, "1234567890");
2411         if (!ok) {
2412                 torture_fail_goto(torture, done, "inconsistent stream data");
2413         }
2414
2415 done:
2416         smb2_util_close(tree, src_h);
2417         smb2_util_close(tree, dest_h);
2418         smb2_util_unlink(tree, FNAME_CC_SRC);
2419         smb2_util_unlink(tree, FNAME_CC_DST);
2420         talloc_free(tmp_ctx);
2421         return true;
2422 }
2423
2424 static bool check_stream_list(struct smb2_tree *tree,
2425                               struct torture_context *tctx,
2426                               const char *fname,
2427                               int num_exp,
2428                               const char **exp,
2429                               struct smb2_handle h)
2430 {
2431         union smb_fileinfo finfo;
2432         NTSTATUS status;
2433         int i;
2434         TALLOC_CTX *tmp_ctx = talloc_new(tctx);
2435         char **exp_sort;
2436         struct stream_struct *stream_sort;
2437
2438         finfo.generic.level = RAW_FILEINFO_STREAM_INFORMATION;
2439         finfo.generic.in.file.handle = h;
2440
2441         status = smb2_getinfo_file(tree, tctx, &finfo);
2442         torture_assert_ntstatus_ok(tctx, status, "get stream info");
2443
2444         torture_assert_int_equal(tctx, finfo.stream_info.out.num_streams, num_exp,
2445                                  "stream count");
2446
2447         if (num_exp == 0) {
2448                 TALLOC_FREE(tmp_ctx);
2449                 return true;
2450         }
2451
2452         exp_sort = talloc_memdup(tmp_ctx, exp, num_exp * sizeof(*exp));
2453         torture_assert(tctx, exp_sort != NULL, __location__);
2454
2455         TYPESAFE_QSORT(exp_sort, num_exp, qsort_string);
2456
2457         stream_sort = talloc_memdup(tmp_ctx, finfo.stream_info.out.streams,
2458                                     finfo.stream_info.out.num_streams *
2459                                     sizeof(*stream_sort));
2460         torture_assert(tctx, stream_sort != NULL, __location__);
2461
2462         TYPESAFE_QSORT(stream_sort, finfo.stream_info.out.num_streams, qsort_stream);
2463
2464         for (i=0; i<num_exp; i++) {
2465                 torture_comment(tctx, "i[%d] exp[%s] got[%s]\n",
2466                                 i, exp_sort[i], stream_sort[i].stream_name.s);
2467                 torture_assert_str_equal(tctx, stream_sort[i].stream_name.s, exp_sort[i],
2468                                          "stream name");
2469         }
2470
2471         TALLOC_FREE(tmp_ctx);
2472         return true;
2473 }
2474
2475 /*
2476   test stream names
2477 */
2478 static bool test_stream_names(struct torture_context *tctx,
2479                               struct smb2_tree *tree,
2480                               struct smb2_tree *tree2)
2481 {
2482         TALLOC_CTX *mem_ctx = talloc_new(tctx);
2483         NTSTATUS status;
2484         struct smb2_create create;
2485         struct smb2_handle h;
2486         const char *fname = BASEDIR "\\stream_names.txt";
2487         const char *sname1;
2488         bool ret;
2489         /* UTF8 private use are starts at 0xef 0x80 0x80 (0xf000) */
2490         const char *streams[] = {
2491                 ":foo" "\xef\x80\xa2" "bar:$DATA", /* "foo:bar:$DATA" */
2492                 ":bar" "\xef\x80\xa2" "baz:$DATA", /* "bar:baz:$DATA" */
2493                 "::$DATA"
2494         };
2495
2496         sname1 = talloc_asprintf(mem_ctx, "%s%s", fname, streams[0]);
2497
2498         /* clean slate ...*/
2499         smb2_util_unlink(tree, fname);
2500         smb2_deltree(tree, fname);
2501         smb2_deltree(tree, BASEDIR);
2502
2503         status = torture_smb2_testdir(tree, BASEDIR, &h);
2504         CHECK_STATUS(status, NT_STATUS_OK);
2505         smb2_util_close(tree, h);
2506
2507         torture_comment(tctx, "(%s) testing stream names\n", __location__);
2508         ZERO_STRUCT(create);
2509         create.in.desired_access = SEC_FILE_WRITE_DATA;
2510         create.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
2511         create.in.share_access =
2512                 NTCREATEX_SHARE_ACCESS_DELETE|
2513                 NTCREATEX_SHARE_ACCESS_READ|
2514                 NTCREATEX_SHARE_ACCESS_WRITE;
2515         create.in.create_disposition = NTCREATEX_DISP_CREATE;
2516         create.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
2517         create.in.fname = sname1;
2518
2519         status = smb2_create(tree, mem_ctx, &create);
2520         CHECK_STATUS(status, NT_STATUS_OK);
2521         smb2_util_close(tree, create.out.file.handle);
2522
2523         ret = torture_setup_local_xattr(tctx, "localdir", BASEDIR "/stream_names.txt",
2524                                         "user.DosStream.bar:baz:$DATA",
2525                                         "data", strlen("data"));
2526         CHECK_VALUE(ret, true);
2527
2528         ZERO_STRUCT(create);
2529         create.in.fname = fname;
2530         create.in.create_disposition = NTCREATEX_DISP_OPEN;
2531         create.in.desired_access = SEC_RIGHTS_FILE_ALL;
2532         create.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
2533         create.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
2534         status = smb2_create(tree, mem_ctx, &create);
2535         CHECK_STATUS(status, NT_STATUS_OK);
2536
2537         ret = check_stream_list(tree, tctx, fname, 3, streams,
2538                                 create.out.file.handle);
2539         CHECK_VALUE(ret, true);
2540
2541         smb2_util_close(tree, create.out.file.handle);
2542
2543 done:
2544         status = smb2_util_unlink(tree, fname);
2545         smb2_deltree(tree, BASEDIR);
2546         talloc_free(mem_ctx);
2547
2548         return ret;
2549 }
2550
2551 /*
2552  * Note: This test depends on "vfs objects = catia fruit
2553  * streams_xattr".  Note: To run this test, use
2554  * "--option=torture:share1=<SHARENAME1>
2555  * --option=torture:share2=<SHARENAME2>
2556  * --option=torture:localdir=<SHAREPATH>"
2557  */
2558 struct torture_suite *torture_vfs_fruit(void)
2559 {
2560         struct torture_suite *suite = torture_suite_create(
2561                 talloc_autofree_context(), "fruit");
2562
2563         suite->description = talloc_strdup(suite, "vfs_fruit tests");
2564
2565         torture_suite_add_1smb2_test(suite, "copyfile", test_copyfile);
2566         torture_suite_add_2ns_smb2_test(suite, "read metadata", test_read_atalk_metadata);
2567         torture_suite_add_2ns_smb2_test(suite, "write metadata", test_write_atalk_metadata);
2568         torture_suite_add_2ns_smb2_test(suite, "resource fork IO", test_write_atalk_rfork_io);
2569         torture_suite_add_2ns_smb2_test(suite, "OS X AppleDouble file conversion", test_adouble_conversion);
2570         torture_suite_add_2ns_smb2_test(suite, "SMB2/CREATE context AAPL", test_aapl);
2571         torture_suite_add_2ns_smb2_test(suite, "stream names", test_stream_names);
2572         torture_suite_add_2ns_smb2_test(suite, "truncate resource fork to 0 bytes", test_rfork_truncate);
2573         torture_suite_add_2ns_smb2_test(suite, "opening and creating resource fork", test_rfork_create);
2574
2575         return suite;
2576 }