From Didier Gautheron:
[obnox/wireshark/wip.git] / epan / dissectors / packet-smb2.c
1 /* packet-smb2.c
2  * Routines for smb2 packet dissection
3  * Ronnie Sahlberg 2005
4  *
5  * See http://wiki.wireshark.org/SMB2  for documentation of
6  * this protocol.
7  * If you edit this file, keep the wiki updated as well.
8  *
9  * $Id$
10  *
11  * Wireshark - Network traffic analyzer
12  * By Gerald Combs <gerald@wireshark.org>
13  * Copyright 1998 Gerald Combs
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version 2
18  * of the License, or (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
28  */
29
30 #ifdef HAVE_CONFIG_H
31 # include "config.h"
32 #endif
33
34 #include <epan/packet.h>
35 #include <epan/conversation.h>
36 #include <epan/tap.h>
37 #include <epan/emem.h>
38
39 #include "packet-smb2.h"
40 #include "packet-dcerpc.h"
41 #include "packet-ntlmssp.h"
42 #include "packet-windows-common.h"
43 #include "packet-smb-common.h"
44 #include "packet-smb.h"
45 #include "packet-dcerpc-nt.h"
46 #include <string.h>
47
48
49
50 static int proto_smb2 = -1;
51 static int hf_smb2_cmd = -1;
52 static int hf_smb2_nt_status = -1;
53 static int hf_smb2_response_to = -1;
54 static int hf_smb2_response_in = -1;
55 static int hf_smb2_time = -1;
56 static int hf_smb2_header_len = -1;
57 static int hf_smb2_seqnum = -1;
58 static int hf_smb2_pid = -1;
59 static int hf_smb2_tid = -1;
60 static int hf_smb2_aid = -1;
61 static int hf_smb2_sesid = -1;
62 static int hf_smb2_previous_sesid = -1;
63 static int hf_smb2_flags_response = -1;
64 static int hf_smb2_flags_async_cmd = -1;
65 static int hf_smb2_flags_dfs_op = -1;
66 static int hf_smb2_flags_chained = -1;
67 static int hf_smb2_flags_signature = -1;
68 static int hf_smb2_chain_offset = -1;
69 static int hf_smb2_response_buffer_offset = -1;
70 static int hf_smb2_security_blob_offset = -1;
71 static int hf_smb2_security_blob_len = -1;
72 static int hf_smb2_security_blob = -1;
73 static int hf_smb2_ioctl_in_data = -1;
74 static int hf_smb2_ioctl_out_data = -1;
75 static int hf_smb2_unknown = -1;
76 static int hf_smb2_unknown_timestamp = -1;
77 static int hf_smb2_create_timestamp = -1;
78 static int hf_smb2_oplock = -1;
79 static int hf_smb2_close_flags = -1;
80 static int hf_smb2_notify_flags = -1;
81 static int hf_smb2_last_access_timestamp = -1;
82 static int hf_smb2_last_write_timestamp = -1;
83 static int hf_smb2_last_change_timestamp = -1;
84 static int hf_smb2_current_time = -1;
85 static int hf_smb2_boot_time = -1;
86 static int hf_smb2_filename = -1;
87 static int hf_smb2_filename_len = -1;
88 static int hf_smb2_nlinks = -1;
89 static int hf_smb2_delete_pending = -1;
90 static int hf_smb2_is_directory = -1;
91 static int hf_smb2_file_id = -1;
92 static int hf_smb2_allocation_size = -1;
93 static int hf_smb2_end_of_file = -1;
94 static int hf_smb2_tree = -1;
95 static int hf_smb2_find_pattern = -1;
96 static int hf_smb2_find_info_level = -1;
97 static int hf_smb2_find_info_blob = -1;
98 static int hf_smb2_client_guid = -1;
99 static int hf_smb2_server_guid = -1;
100 static int hf_smb2_object_id = -1;
101 static int hf_smb2_birth_volume_id = -1;
102 static int hf_smb2_birth_object_id = -1;
103 static int hf_smb2_domain_id = -1;
104 static int hf_smb2_class = -1;
105 static int hf_smb2_infolevel = -1;
106 static int hf_smb2_infolevel_file_info = -1;
107 static int hf_smb2_infolevel_fs_info = -1;
108 static int hf_smb2_infolevel_sec_info = -1;
109 static int hf_smb2_max_response_size = -1;
110 static int hf_smb2_max_ioctl_in_size = -1;
111 static int hf_smb2_max_ioctl_out_size = -1;
112 static int hf_smb2_required_buffer_size = -1;
113 static int hf_smb2_response_size = -1;
114 static int hf_smb2_setinfo_size = -1;
115 static int hf_smb2_setinfo_offset = -1;
116 static int hf_smb2_file_basic_info = -1;
117 static int hf_smb2_file_standard_info = -1;
118 static int hf_smb2_file_internal_info = -1;
119 static int hf_smb2_file_ea_info = -1;
120 static int hf_smb2_file_access_info = -1;
121 static int hf_smb2_file_rename_info = -1;
122 static int hf_smb2_file_disposition_info = -1;
123 static int hf_smb2_file_position_info = -1;
124 static int hf_smb2_file_info_0f = -1;
125 static int hf_smb2_file_mode_info = -1;
126 static int hf_smb2_file_alignment_info = -1;
127 static int hf_smb2_file_all_info = -1;
128 static int hf_smb2_file_allocation_info = -1;
129 static int hf_smb2_file_endoffile_info = -1;
130 static int hf_smb2_file_alternate_name_info = -1;
131 static int hf_smb2_file_stream_info = -1;
132 static int hf_smb2_file_pipe_info = -1;
133 static int hf_smb2_file_compression_info = -1;
134 static int hf_smb2_file_network_open_info = -1;
135 static int hf_smb2_file_attribute_tag_info = -1;
136 static int hf_smb2_fs_info_01 = -1;
137 static int hf_smb2_fs_info_03 = -1;
138 static int hf_smb2_fs_info_04 = -1;
139 static int hf_smb2_fs_info_05 = -1;
140 static int hf_smb2_fs_info_06 = -1;
141 static int hf_smb2_fs_info_07 = -1;
142 static int hf_smb2_fs_objectid_info = -1;
143 static int hf_smb2_sec_info_00 = -1;
144 static int hf_smb2_fid = -1;
145 static int hf_smb2_write_length = -1;
146 static int hf_smb2_write_data = -1;
147 static int hf_smb2_read_length = -1;
148 static int hf_smb2_read_remaining = -1;
149 static int hf_smb2_file_offset = -1;
150 static int hf_smb2_read_data = -1;
151 static int hf_smb2_disposition_delete_on_close = -1;
152 static int hf_smb2_create_disposition = -1;
153 static int hf_smb2_create_chain_offset = -1;
154 static int hf_smb2_create_chain_data = -1;
155 static int hf_smb2_data_offset = -1;
156 static int hf_smb2_data_length = -1;
157 static int hf_smb2_extrainfo = -1;
158 static int hf_smb2_create_action = -1;
159 static int hf_smb2_next_offset = -1;
160 static int hf_smb2_ea_size = -1;
161 static int hf_smb2_ea_flags = -1;
162 static int hf_smb2_ea_name_len = -1;
163 static int hf_smb2_ea_data_len = -1;
164 static int hf_smb2_ea_name = -1;
165 static int hf_smb2_ea_data = -1;
166 static int hf_smb2_buffer_code_len = -1;
167 static int hf_smb2_buffer_code_flags_dyn = -1;
168 static int hf_smb2_olb_offset = -1;
169 static int hf_smb2_olb_length = -1;
170 static int hf_smb2_tag = -1;
171 static int hf_smb2_impersonation_level = -1;
172 static int hf_smb2_ioctl_function = -1;
173 static int hf_smb2_ioctl_function_device = -1;
174 static int hf_smb2_ioctl_function_access = -1;
175 static int hf_smb2_ioctl_function_function = -1;
176 static int hf_smb2_ioctl_function_method = -1;
177 static int hf_smb2_ioctl_shadow_copy_num_volumes = -1;
178 static int hf_smb2_ioctl_shadow_copy_num_labels = -1;
179 static int hf_smb2_ioctl_shadow_copy_count = -1;
180 static int hf_smb2_ioctl_shadow_copy_label = -1;
181 static int hf_smb2_compression_format = -1;
182 static int hf_smb2_FILE_OBJECTID_BUFFER = -1;
183 static int hf_smb2_acct_name = -1;
184 static int hf_smb2_domain_name = -1;
185 static int hf_smb2_host_name = -1;
186 static int hf_smb2_auth_frame = -1;
187 static int hf_smb2_tcon_frame = -1;
188 static int hf_smb2_share_type = -1;
189 static int hf_smb2_signature = -1;
190 static int hf_smb2_epoch = -1;
191 static int hf_smb2_credits_requested = -1;
192 static int hf_smb2_credits_granted = -1;
193 static int hf_smb2_dialect_count = -1;
194 static int hf_smb2_security_mode = -1;
195 static int hf_smb2_secmode_flags_sign_required = -1;
196 static int hf_smb2_secmode_flags_sign_enabled = -1;
197 static int hf_smb2_capabilities = -1;
198 static int hf_smb2_cap_dfs = -1;
199 static int hf_smb2_dialect = -1;
200 static int hf_smb2_max_trans_size = -1;
201 static int hf_smb2_max_read_size = -1;
202 static int hf_smb2_max_write_size = -1;
203 static int hf_smb2_vcnum = -1;
204 static int hf_smb2_channel = -1;
205 static int hf_smb2_session_flags = -1;
206 static int hf_smb2_ses_flags_guest = -1;
207 static int hf_smb2_ses_flags_null = -1;
208 static int hf_smb2_share_flags = -1;
209 static int hf_smb2_share_flags_dfs = -1;
210 static int hf_smb2_share_flags_dfs_root = -1;
211 static int hf_smb2_share_flags_restrict_exclusive_opens = -1;
212 static int hf_smb2_share_flags_force_shared_delete = -1;
213 static int hf_smb2_share_flags_allow_namespace_caching = -1;
214 static int hf_smb2_share_flags_access_based_dir_enum = -1;
215 static int hf_smb2_share_caching = -1;
216 static int hf_smb2_share_caps = -1;
217 static int hf_smb2_share_caps_dfs = -1;
218 static int hf_smb2_create_flags = -1;
219 static int hf_smb2_lock_count = -1;
220 static int hf_smb2_min_count = -1;
221 static int hf_smb2_remaining_bytes = -1;
222 static int hf_smb2_channel_info_offset = -1;
223 static int hf_smb2_channel_info_length = -1;
224 static int hf_smb2_ioctl_flags = -1;
225 static int hf_smb2_ioctl_is_fsctl = -1;
226 static int hf_smb2_close_pq_attrib = -1;
227 static int hf_smb2_notify_watch_tree = -1;
228 static int hf_smb2_output_buffer_len = -1;
229 static int hf_smb2_notify_out_data = -1;
230 static int hf_smb2_find_flags = -1;
231 static int hf_smb2_find_flags_restart_scans = -1;
232 static int hf_smb2_find_flags_single_entry = -1;
233 static int hf_smb2_find_flags_index_specified = -1;
234 static int hf_smb2_find_flags_reopen = -1;
235 static int hf_smb2_file_index = -1;
236 static int hf_smb2_file_directory_info = -1;
237 static int hf_smb2_both_directory_info = -1;
238 static int hf_smb2_short_name_len = -1;
239 static int hf_smb2_short_name = -1;
240 static int hf_smb2_id_both_directory_info = -1;
241 static int hf_smb2_full_directory_info = -1;
242 static int hf_smb2_file_name_info = -1;
243 static int hf_smb2_lock_info = -1;
244 static int hf_smb2_lock_length = -1;
245 static int hf_smb2_lock_flags = -1;
246 static int hf_smb2_lock_flags_shared = -1;
247 static int hf_smb2_lock_flags_exclusive = -1;
248 static int hf_smb2_lock_flags_unlock = -1;
249 static int hf_smb2_lock_flags_fail_immediately = -1;
250 static int hf_smb2_error_byte_count = -1;
251 static int hf_smb2_error_data = -1;
252 static int hf_smb2_error_reserved = -1;
253
254 static gint ett_smb2 = -1;
255 static gint ett_smb2_olb = -1;
256 static gint ett_smb2_ea = -1;
257 static gint ett_smb2_header = -1;
258 static gint ett_smb2_command = -1;
259 static gint ett_smb2_secblob = -1;
260 static gint ett_smb2_file_basic_info = -1;
261 static gint ett_smb2_file_standard_info = -1;
262 static gint ett_smb2_file_internal_info = -1;
263 static gint ett_smb2_file_ea_info = -1;
264 static gint ett_smb2_file_access_info = -1;
265 static gint ett_smb2_file_position_info = -1;
266 static gint ett_smb2_file_mode_info = -1;
267 static gint ett_smb2_file_alignment_info = -1;
268 static gint ett_smb2_file_all_info = -1;
269 static gint ett_smb2_file_allocation_info = -1;
270 static gint ett_smb2_file_endoffile_info = -1;
271 static gint ett_smb2_file_alternate_name_info = -1;
272 static gint ett_smb2_file_stream_info = -1;
273 static gint ett_smb2_file_pipe_info = -1;
274 static gint ett_smb2_file_compression_info = -1;
275 static gint ett_smb2_file_network_open_info = -1;
276 static gint ett_smb2_file_attribute_tag_info = -1;
277 static gint ett_smb2_file_rename_info = -1;
278 static gint ett_smb2_file_disposition_info = -1;
279 static gint ett_smb2_file_info_0f = -1;
280 static gint ett_smb2_fs_info_01 = -1;
281 static gint ett_smb2_fs_info_03 = -1;
282 static gint ett_smb2_fs_info_04 = -1;
283 static gint ett_smb2_fs_info_05 = -1;
284 static gint ett_smb2_fs_info_06 = -1;
285 static gint ett_smb2_fs_info_07 = -1;
286 static gint ett_smb2_fs_objectid_info = -1;
287 static gint ett_smb2_sec_info_00 = -1;
288 static gint ett_smb2_tid_tree = -1;
289 static gint ett_smb2_sesid_tree = -1;
290 static gint ett_smb2_create_chain_element = -1;
291 static gint ett_smb2_MxAc_buffer = -1;
292 static gint ett_smb2_ioctl_function = -1;
293 static gint ett_smb2_FILE_OBJECTID_BUFFER = -1;
294 static gint ett_smb2_flags = -1;
295 static gint ett_smb2_sec_mode = -1;
296 static gint ett_smb2_capabilities = -1;
297 static gint ett_smb2_ses_flags = -1;
298 static gint ett_smb2_share_flags = -1;
299 static gint ett_smb2_share_caps = -1;
300 static gint ett_smb2_ioctl_flags = -1;
301 static gint ett_smb2_close_flags = -1;
302 static gint ett_smb2_notify_flags = -1;
303 static gint ett_smb2_find_flags = -1;
304 static gint ett_smb2_file_directory_info = -1;
305 static gint ett_smb2_both_directory_info = -1;
306 static gint ett_smb2_id_both_directory_info = -1;
307 static gint ett_smb2_full_directory_info = -1;
308 static gint ett_smb2_file_name_info = -1;
309 static gint ett_smb2_lock_info = -1;
310 static gint ett_smb2_lock_flags = -1;
311
312 static int smb2_tap = -1;
313
314 static dissector_handle_t gssapi_handle = NULL;
315 static dissector_handle_t ntlmssp_handle = NULL;
316
317 static heur_dissector_list_t smb2_heur_subdissector_list;
318
319 #define SMB2_CLASS_FILE_INFO    0x01
320 #define SMB2_CLASS_FS_INFO      0x02
321 #define SMB2_CLASS_SEC_INFO     0x03
322 static const value_string smb2_class_vals[] = {
323         { SMB2_CLASS_FILE_INFO, "FILE_INFO"},
324         { SMB2_CLASS_FS_INFO,   "FS_INFO"},
325         { SMB2_CLASS_SEC_INFO,  "SEC_INFO"},
326         { 0, NULL }
327 };
328
329 #define SMB2_SHARE_TYPE_FILE    0x0001
330 #define SMB2_SHARE_TYPE_IPC     0x0002
331 #define SMB2_SHARE_TYPE_PRINT   0x0003
332 static const value_string smb2_share_type_vals[] = {
333         { SMB2_SHARE_TYPE_FILE,         "File Share" },
334         { SMB2_SHARE_TYPE_IPC,          "IPC share" },
335         { SMB2_SHARE_TYPE_PRINT,        "Print Share" },
336         { 0, NULL }
337 };
338
339
340 #define SMB2_FILE_BASIC_INFO    0x04
341 #define SMB2_FILE_STANDARD_INFO 0x05
342 #define SMB2_FILE_INTERNAL_INFO 0x06
343 #define SMB2_FILE_EA_INFO       0x07
344 #define SMB2_FILE_ACCESS_INFO   0x08
345 #define SMB2_FILE_RENAME_INFO   0x0a
346 #define SMB2_FILE_DISPOSITION_INFO      0x0d
347 #define SMB2_FILE_POSITION_INFO 0x0e
348 #define SMB2_FILE_INFO_0f       0x0f
349 #define SMB2_FILE_MODE_INFO     0x10
350 #define SMB2_FILE_ALIGNMENT_INFO        0x11
351 #define SMB2_FILE_ALL_INFO      0x12
352 #define SMB2_FILE_ALLOCATION_INFO       0x13
353 #define SMB2_FILE_ENDOFFILE_INFO        0x14
354 #define SMB2_FILE_ALTERNATE_NAME_INFO   0x15
355 #define SMB2_FILE_STREAM_INFO           0x16
356 #define SMB2_FILE_PIPE_INFO             0x17
357 #define SMB2_FILE_COMPRESSION_INFO      0x1c
358 #define SMB2_FILE_NETWORK_OPEN_INFO     0x22
359 #define SMB2_FILE_ATTRIBUTE_TAG_INFO    0x23
360 static const value_string smb2_file_info_levels[] = {
361         {SMB2_FILE_BASIC_INFO,          "SMB2_FILE_BASIC_INFO" },
362         {SMB2_FILE_STANDARD_INFO,       "SMB2_FILE_STANDARD_INFO" },
363         {SMB2_FILE_INTERNAL_INFO,       "SMB2_FILE_INTERNAL_INFO" },
364         {SMB2_FILE_EA_INFO,             "SMB2_FILE_EA_INFO" },
365         {SMB2_FILE_ACCESS_INFO,         "SMB2_FILE_ACCESS_INFO" },
366         {SMB2_FILE_RENAME_INFO,         "SMB2_FILE_RENAME_INFO" },
367         {SMB2_FILE_DISPOSITION_INFO,    "SMB2_FILE_DISPOSITION_INFO" },
368         {SMB2_FILE_POSITION_INFO,       "SMB2_FILE_POSITION_INFO" },
369         {SMB2_FILE_INFO_0f,             "SMB2_FILE_INFO_0f" },
370         {SMB2_FILE_MODE_INFO,           "SMB2_FILE_MODE_INFO" },
371         {SMB2_FILE_ALIGNMENT_INFO,      "SMB2_FILE_ALIGNMENT_INFO" },
372         {SMB2_FILE_ALL_INFO,            "SMB2_FILE_ALL_INFO" },
373         {SMB2_FILE_ALLOCATION_INFO,     "SMB2_FILE_ALLOCATION_INFO" },
374         {SMB2_FILE_ENDOFFILE_INFO,      "SMB2_FILE_ENDOFFILE_INFO" },
375         {SMB2_FILE_ALTERNATE_NAME_INFO, "SMB2_FILE_ALTERNATE_NAME_INFO" },
376         {SMB2_FILE_STREAM_INFO,         "SMB2_FILE_STREAM_INFO" },
377         {SMB2_FILE_PIPE_INFO,           "SMB2_FILE_PIPE_INFO" },
378         {SMB2_FILE_COMPRESSION_INFO,    "SMB2_FILE_COMPRESSION_INFO" },
379         {SMB2_FILE_NETWORK_OPEN_INFO,   "SMB2_FILE_NETWORK_OPEN_INFO" },
380         {SMB2_FILE_ATTRIBUTE_TAG_INFO,  "SMB2_FILE_ATTRIBUTE_TAG_INFO" },
381         { 0, NULL }
382 };
383
384
385
386 #define SMB2_FS_INFO_01         0x01
387 #define SMB2_FS_INFO_03         0x03
388 #define SMB2_FS_INFO_04         0x04
389 #define SMB2_FS_INFO_05         0x05
390 #define SMB2_FS_INFO_06         0x06
391 #define SMB2_FS_INFO_07         0x07
392 #define SMB2_FS_OBJECTID_INFO   0x08
393 static const value_string smb2_fs_info_levels[] = {
394         {SMB2_FS_INFO_01,       "SMB2_FS_INFO_01" },
395         {SMB2_FS_INFO_03,       "SMB2_FS_INFO_03" },
396         {SMB2_FS_INFO_04,       "SMB2_FS_INFO_04" },
397         {SMB2_FS_INFO_05,       "SMB2_FS_INFO_05" },
398         {SMB2_FS_INFO_06,       "SMB2_FS_INFO_06" },
399         {SMB2_FS_INFO_07,       "SMB2_FS_INFO_07" },
400         {SMB2_FS_OBJECTID_INFO, "SMB2_FS_OBJECTID_INFO" },
401         { 0, NULL }
402 };
403
404 #define SMB2_SEC_INFO_00        0x00
405 static const value_string smb2_sec_info_levels[] = {
406         {SMB2_SEC_INFO_00,      "SMB2_SEC_INFO_00" },
407         { 0, NULL }
408 };
409
410 #define SMB2_FIND_DIRECTORY_INFO         0x01
411 #define SMB2_FIND_FULL_DIRECTORY_INFO    0x02
412 #define SMB2_FIND_BOTH_DIRECTORY_INFO    0x03
413 #define SMB2_FIND_INDEX_SPECIFIED        0x04
414 #define SMB2_FIND_NAME_INFO              0x0C
415 #define SMB2_FIND_ID_BOTH_DIRECTORY_INFO 0x25
416 #define SMB2_FIND_ID_FULL_DIRECTORY_INFO 0x26
417 static const value_string smb2_find_info_levels[] = {
418         { SMB2_FIND_DIRECTORY_INFO,             "SMB2_FIND_DIRECTORY_INFO" },
419         { SMB2_FIND_FULL_DIRECTORY_INFO,        "SMB2_FIND_FULL_DIRECTORY_INFO" },
420         { SMB2_FIND_BOTH_DIRECTORY_INFO,        "SMB2_FIND_BOTH_DIRECTORY_INFO" },
421         { SMB2_FIND_INDEX_SPECIFIED,            "SMB2_FIND_INDEX_SPECIFIED" },
422         { SMB2_FIND_NAME_INFO,                  "SMB2_FIND_NAME_INFO" },
423         { SMB2_FIND_ID_BOTH_DIRECTORY_INFO,     "SMB2_FIND_ID_BOTH_DIRECTORY_INFO" },
424         { SMB2_FIND_ID_FULL_DIRECTORY_INFO,     "SMB2_FIND_ID_FULL_DIRECTORY_INFO" },
425         { 0, NULL }
426 };
427
428 /* unmatched smb_saved_info structures.
429    For unmatched smb_saved_info structures we store the smb_saved_info
430    structure using the SEQNUM field.
431 */
432 static gint
433 smb2_saved_info_equal_unmatched(gconstpointer k1, gconstpointer k2)
434 {
435         smb2_saved_info_t *key1 = (smb2_saved_info_t *)k1;
436         smb2_saved_info_t *key2 = (smb2_saved_info_t *)k2;
437         return key1->seqnum==key2->seqnum;
438 }
439 static guint
440 smb2_saved_info_hash_unmatched(gconstpointer k)
441 {
442         smb2_saved_info_t *key = (smb2_saved_info_t *)k;
443         guint32 hash;
444
445         hash=(guint32) (key->seqnum&0xffffffff);
446         return hash;
447 }
448
449 /* matched smb_saved_info structures.
450    For matched smb_saved_info structures we store the smb_saved_info
451    structure using the SEQNUM field.
452 */
453 static gint
454 smb2_saved_info_equal_matched(gconstpointer k1, gconstpointer k2)
455 {
456         smb2_saved_info_t *key1 = (smb2_saved_info_t *)k1;
457         smb2_saved_info_t *key2 = (smb2_saved_info_t *)k2;
458         return key1->seqnum==key2->seqnum;
459 }
460 static guint
461 smb2_saved_info_hash_matched(gconstpointer k)
462 {
463         smb2_saved_info_t *key = (smb2_saved_info_t *)k;
464         guint32 hash;
465
466         hash=(guint32) (key->seqnum&0xffffffff);
467         return hash;
468 }
469
470 /* For Tids of a specific conversation.
471    This keeps track of tid->sharename mappings and other information about the
472    tid.
473    qqq
474    We might need to refine this if it occurs that tids are reused on a single
475    conversation.   we dont worry about that yet for simplicity
476 */
477 static gint
478 smb2_tid_info_equal(gconstpointer k1, gconstpointer k2)
479 {
480         smb2_tid_info_t *key1 = (smb2_tid_info_t *)k1;
481         smb2_tid_info_t *key2 = (smb2_tid_info_t *)k2;
482         return key1->tid==key2->tid;
483 }
484 static guint
485 smb2_tid_info_hash(gconstpointer k)
486 {
487         smb2_tid_info_t *key = (smb2_tid_info_t *)k;
488         guint32 hash;
489
490         hash=key->tid;
491         return hash;
492 }
493
494 /* For Uids of a specific conversation.
495    This keeps track of uid->acct_name mappings and other information about the
496    uid.
497    qqq
498    We might need to refine this if it occurs that uids are reused on a single
499    conversation.   we dont worry about that yet for simplicity
500 */
501 static gint
502 smb2_sesid_info_equal(gconstpointer k1, gconstpointer k2)
503 {
504         smb2_sesid_info_t *key1 = (smb2_sesid_info_t *)k1;
505         smb2_sesid_info_t *key2 = (smb2_sesid_info_t *)k2;
506         return key1->sesid==key2->sesid;
507 }
508 static guint
509 smb2_sesid_info_hash(gconstpointer k)
510 {
511         smb2_sesid_info_t *key = (smb2_sesid_info_t *)k;
512         guint32 hash;
513
514         hash=(guint32)( ((key->sesid>>32)&0xffffffff)+((key->sesid)&0xffffffff) );
515         return hash;
516 }
517
518 static int dissect_smb2_file_info_0f(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int offset, smb2_info_t *si);
519
520
521 /* This is a helper to dissect the common string type
522  * uint16 offset
523  * uint16 length
524  * ...
525  * char *string
526  *
527  * This function is called twice, first to decode the offset/length and
528  * second time to dissect the actual string.
529  * It is done this way since there is no guarantee that we have the full packet and we dont
530  * want to abort dissection too early if the packet ends somewhere between the
531  * length/offset and the actual buffer.
532  *
533  */
534 enum offset_length_buffer_offset_size {
535         OLB_O_UINT16_S_UINT16,
536         OLB_O_UINT16_S_UINT32,
537         OLB_O_UINT32_S_UINT32,
538         OLB_S_UINT32_O_UINT32
539 };
540 typedef struct _offset_length_buffer_t {
541         guint32 off;
542         guint32 len;
543         int off_offset;
544         int len_offset;
545         enum offset_length_buffer_offset_size offset_size;
546         int hfindex;
547 } offset_length_buffer_t;
548 static int
549 dissect_smb2_olb_length_offset(tvbuff_t *tvb, int offset, offset_length_buffer_t *olb,
550                                enum offset_length_buffer_offset_size offset_size, int hfindex)
551 {
552         olb->hfindex=hfindex;
553         olb->offset_size=offset_size;
554         switch(offset_size){
555         case OLB_O_UINT16_S_UINT16:
556                 olb->off=tvb_get_letohs(tvb, offset);
557                 olb->off_offset=offset;
558                 offset += 2;
559                 olb->len=tvb_get_letohs(tvb, offset);
560                 olb->len_offset=offset;
561                 offset += 2;
562                 break;
563         case OLB_O_UINT16_S_UINT32:
564                 olb->off=tvb_get_letohs(tvb, offset);
565                 olb->off_offset=offset;
566                 offset += 2;
567                 olb->len=tvb_get_letohl(tvb, offset);
568                 olb->len_offset=offset;
569                 offset += 4;
570                 break;
571         case OLB_O_UINT32_S_UINT32:
572                 olb->off=tvb_get_letohl(tvb, offset);
573                 olb->off_offset=offset;
574                 offset += 4;
575                 olb->len=tvb_get_letohl(tvb, offset);
576                 olb->len_offset=offset;
577                 offset += 4;
578                 break;
579         case OLB_S_UINT32_O_UINT32:
580                 olb->len=tvb_get_letohl(tvb, offset);
581                 olb->len_offset=offset;
582                 offset += 4;
583                 olb->off=tvb_get_letohl(tvb, offset);
584                 olb->off_offset=offset;
585                 offset += 4;
586                 break;
587         }
588
589         return offset;
590 }
591
592 #define OLB_TYPE_UNICODE_STRING         0x01
593 #define OLB_TYPE_ASCII_STRING           0x02
594 static const char *
595 dissect_smb2_olb_string(packet_info *pinfo, proto_tree *parent_tree, tvbuff_t *tvb, offset_length_buffer_t *olb, int type)
596 {
597         int len, off;
598         proto_item *item=NULL;
599         proto_tree *tree=NULL;
600         const char *name=NULL;
601         guint16 bc;
602         int offset;
603
604         offset=olb->off;
605         len=olb->len;
606         off=olb->off;
607         bc=tvb_length_remaining(tvb, offset);
608
609
610         /* sanity check */
611         tvb_ensure_bytes_exist(tvb, off, len);
612         if(((off+len)<off)
613         || ((off+len)>(off+tvb_reported_length_remaining(tvb, off)))){
614                 proto_tree_add_text(tree, tvb, offset, tvb_length_remaining(tvb, offset),
615                                     "Invalid offset/length. Malformed packet");
616
617                 col_append_str(pinfo->cinfo, COL_INFO, " [Malformed packet]");
618
619                 return NULL;
620         }
621
622
623         switch(type){
624         case OLB_TYPE_UNICODE_STRING:
625                 name = get_unicode_or_ascii_string(tvb, &off,
626                         TRUE, &len, TRUE, TRUE, &bc);
627                 if(!name){
628                         name="";
629                 }
630                 if(parent_tree){
631                         item = proto_tree_add_string(parent_tree, olb->hfindex, tvb, offset, len, name);
632                         tree = proto_item_add_subtree(item, ett_smb2_olb);
633                 }
634                 break;
635         case OLB_TYPE_ASCII_STRING:
636                 name = get_unicode_or_ascii_string(tvb, &off,
637                         FALSE, &len, TRUE, TRUE, &bc);
638                 if(!name){
639                         name="";
640                 }
641                 if(parent_tree){
642                         item = proto_tree_add_string(parent_tree, olb->hfindex, tvb, offset, len, name);
643                         tree = proto_item_add_subtree(item, ett_smb2_olb);
644                 }
645                 break;
646         }
647
648         switch(olb->offset_size){
649         case OLB_O_UINT16_S_UINT16:
650                 proto_tree_add_item(tree, hf_smb2_olb_offset, tvb, olb->off_offset, 2, TRUE);
651                 proto_tree_add_item(tree, hf_smb2_olb_length, tvb, olb->len_offset, 2, TRUE);
652                 break;
653         case OLB_O_UINT16_S_UINT32:
654                 proto_tree_add_item(tree, hf_smb2_olb_offset, tvb, olb->off_offset, 2, TRUE);
655                 proto_tree_add_item(tree, hf_smb2_olb_length, tvb, olb->len_offset, 4, TRUE);
656                 break;
657         case OLB_O_UINT32_S_UINT32:
658                 proto_tree_add_item(tree, hf_smb2_olb_offset, tvb, olb->off_offset, 4, TRUE);
659                 proto_tree_add_item(tree, hf_smb2_olb_length, tvb, olb->len_offset, 4, TRUE);
660                 break;
661         case OLB_S_UINT32_O_UINT32:
662                 proto_tree_add_item(tree, hf_smb2_olb_length, tvb, olb->len_offset, 4, TRUE);
663                 proto_tree_add_item(tree, hf_smb2_olb_offset, tvb, olb->off_offset, 4, TRUE);
664                 break;
665         }
666
667         return name;
668 }
669
670 static void
671 dissect_smb2_olb_buffer(packet_info *pinfo, proto_tree *parent_tree, tvbuff_t *tvb,
672                         offset_length_buffer_t *olb, smb2_info_t *si,
673                         void (*dissector)(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, smb2_info_t *si))
674 {
675         int len, off;
676         proto_item *sub_item=NULL;
677         proto_tree *sub_tree=NULL;
678         tvbuff_t *sub_tvb=NULL;
679         guint16 bc;
680         int offset;
681
682         offset=olb->off;
683         len=olb->len;
684         off=olb->off;
685         bc=tvb_length_remaining(tvb, offset);
686
687         /* sanity check */
688         tvb_ensure_bytes_exist(tvb, off, len);
689         if(((off+len)<off)
690         || ((off+len)>(off+tvb_reported_length_remaining(tvb, off)))){
691                 proto_tree_add_text(parent_tree, tvb, offset, tvb_length_remaining(tvb, offset),
692                                     "Invalid offset/length. Malformed packet");
693
694                 col_append_str(pinfo->cinfo, COL_INFO, " [Malformed packet]");
695
696                 return;
697         }
698
699         /* if we dont want/need a subtree */
700         if(olb->hfindex==-1){
701                 sub_item=parent_tree;
702                 sub_tree=parent_tree;
703         } else {
704                 if(parent_tree){
705                         sub_item = proto_tree_add_item(parent_tree, olb->hfindex, tvb, offset, len, TRUE);
706                         sub_tree = proto_item_add_subtree(sub_item, ett_smb2_olb);
707                 }
708         }
709
710         switch(olb->offset_size){
711         case OLB_O_UINT16_S_UINT16:
712                 proto_tree_add_item(sub_tree, hf_smb2_olb_offset, tvb, olb->off_offset, 2, TRUE);
713                 proto_tree_add_item(sub_tree, hf_smb2_olb_length, tvb, olb->len_offset, 2, TRUE);
714                 break;
715         case OLB_O_UINT16_S_UINT32:
716                 proto_tree_add_item(sub_tree, hf_smb2_olb_offset, tvb, olb->off_offset, 2, TRUE);
717                 proto_tree_add_item(sub_tree, hf_smb2_olb_length, tvb, olb->len_offset, 4, TRUE);
718                 break;
719         case OLB_O_UINT32_S_UINT32:
720                 proto_tree_add_item(sub_tree, hf_smb2_olb_offset, tvb, olb->off_offset, 4, TRUE);
721                 proto_tree_add_item(sub_tree, hf_smb2_olb_length, tvb, olb->len_offset, 4, TRUE);
722                 break;
723         case OLB_S_UINT32_O_UINT32:
724                 proto_tree_add_item(sub_tree, hf_smb2_olb_length, tvb, olb->len_offset, 4, TRUE);
725                 proto_tree_add_item(sub_tree, hf_smb2_olb_offset, tvb, olb->off_offset, 4, TRUE);
726                 break;
727         }
728
729         if (off == 0 || len == 0) {
730                 proto_item_append_text(sub_item, ": NO DATA");
731                 return;
732         }
733
734         if (!dissector) {
735                 return;
736         }
737
738         sub_tvb=tvb_new_subset(tvb, off, MIN((int)len, tvb_length_remaining(tvb, off)), len);
739
740         dissector(sub_tvb, pinfo, sub_tree, si);
741
742         return;
743 }
744
745 static int
746 dissect_smb2_olb_tvb_max_offset(int offset, offset_length_buffer_t *olb)
747 {
748         if (olb->off == 0) {
749                 return offset;
750         }
751         return MAX(offset, (int)(olb->off + olb->len));
752 }
753
754 typedef struct _smb2_function {
755        int (*request)(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, smb2_info_t *si);
756        int (*response)(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, smb2_info_t *si);
757 } smb2_function;
758
759 static const true_false_string tfs_flags_response = {
760         "This is a RESPONSE",
761         "This is a REQUEST"
762 };
763
764 static const true_false_string tfs_flags_async_cmd = {
765         "This is an ASYNC command",
766         "This is a SYNC command"
767 };
768
769 static const true_false_string tfs_flags_dfs_op = {
770         "This is a DFS OPERATION",
771         "This is a normal operation"
772 };
773
774 static const true_false_string tfs_flags_chained = {
775         "This pdu a CHAINED command",
776         "This pdu is NOT a chained command"
777 };
778
779 static const true_false_string tfs_flags_signature = {
780         "This pdu is SIGNED",
781         "This pdu is NOT signed"
782 };
783
784 static const true_false_string tfs_cap_dfs = {
785         "This host supports DFS",
786         "This host does NOT support DFS"
787 };
788
789 static const value_string compression_format_vals[] = {
790   { 0, "COMPRESSION_FORMAT_NONE" },
791   { 1, "COMPRESSION_FORMAT_DEFAULT" },
792   { 2, "COMPRESSION_FORMAT_LZNT1" },
793   { 0, NULL }
794 };
795
796
797 static const value_string smb2_ioctl_vals[] = {
798   /* dissector implemented */
799   {0x0011c017, "IOCTL_DO_DCERPC"},
800   {0x00144064, "FSCTL_GET_SHADOW_COPY_DATA"},
801   {0x000900C0, "FSCTL_CREATE_OR_GET_OBJECT_ID"},
802   {0x0009009C, "FSCTL_GET_OBJECT_ID"},
803   {0x000980A0, "FSCTL_DELETE_OBJECT_ID"}, /* no data in/out */
804   {0x00098098, "FSCTL_SET_OBJECT_ID"},
805   {0x000980BC, "FSCTL_SET_OBJECT_ID_EXTENDED"},
806   {0x0009003C, "FSCTL_GET_COMPRESSION"},
807   {0x0009C040, "FSCTL_SET_COMPRESSION"},
808
809   /* dissector not yet implemented */
810   {0x00090000, "FSCTL_REQUEST_OPLOCK_LEVEL_1"},
811   {0x00090004, "FSCTL_REQUEST_OPLOCK_LEVEL_2"},
812   {0x00090008, "FSCTL_REQUEST_BATCH_OPLOCK"},
813   {0x0009000C, "FSCTL_OPLOCK_BREAK_ACKNOWLEDGE"},
814   {0x00090010, "FSCTL_OPBATCH_ACK_CLOSE_PENDING"},
815   {0x00090014, "FSCTL_OPLOCK_BREAK_NOTIFY"},
816   {0x00090018, "FSCTL_LOCK_VOLUME"},
817   {0x0009001C, "FSCTL_UNLOCK_VOLUME"},
818   {0x00090020, "FSCTL_DISMOUNT_VOLUME"},
819   {0x00090028, "FSCTL_IS_VOLUME_MOUNTED"},
820   {0x0009002C, "FSCTL_IS_PATHNAME_VALID"},
821   {0x00090030, "FSCTL_MARK_VOLUME_DIRTY"},
822   {0x0009003B, "FSCTL_QUERY_RETRIEVAL_POINTERS"},
823   {0x0009004F, "FSCTL_MARK_AS_SYSTEM_HIVE"},
824   {0x00090050, "FSCTL_OPLOCK_BREAK_ACK_NO_2"},
825   {0x00090054, "FSCTL_INVALIDATE_VOLUMES"},
826   {0x00090058, "FSCTL_QUERY_FAT_BPB"},
827   {0x0009005C, "FSCTL_REQUEST_FILTER_OPLOCK"},
828   {0x00090060, "FSCTL_FILESYSTEM_GET_STATISTICS"},
829   {0x00090064, "FSCTL_GET_NTFS_VOLUME_DATA"},
830   {0x00090068, "FSCTL_GET_NTFS_FILE_RECORD"},
831   {0x0009006F, "FSCTL_GET_VOLUME_BITMAP"},
832   {0x00090073, "FSCTL_GET_RETRIEVAL_POINTERS"},
833   {0x00090074, "FSCTL_MOVE_FILE"},
834   {0x00090078, "FSCTL_IS_VOLUME_DIRTY"},
835   {0x0009007C, "FSCTL_GET_HFS_INFORMATION"},
836   {0x00090083, "FSCTL_ALLOW_EXTENDED_DASD_IO"},
837   {0x00090087, "FSCTL_READ_PROPERTY_DATA"},
838   {0x0009008B, "FSCTL_WRITE_PROPERTY_DATA"},
839   {0x0009008F, "FSCTL_FIND_FILES_BY_SID"},
840   {0x00090097, "FSCTL_DUMP_PROPERTY_DATA"},
841   {0x000980A4, "FSCTL_SET_REPARSE_POINT"},
842   {0x000900A8, "FSCTL_GET_REPARSE_POINT"},
843   {0x000980AC, "FSCTL_DELETE_REPARSE_POINT"},
844   {0x000940B3, "FSCTL_ENUM_USN_DATA"},
845   {0x000940B7, "FSCTL_SECURITY_ID_CHECK"},
846   {0x000940BB, "FSCTL_READ_USN_JOURNAL"},
847   {0x000980C4, "FSCTL_SET_SPARSE"},
848   {0x000980C8, "FSCTL_SET_ZERO_DATA"},
849   {0x000940CF, "FSCTL_QUERY_ALLOCATED_RANGES"},
850   {0x000980D0, "FSCTL_ENABLE_UPGRADE"},
851   {0x000900D4, "FSCTL_SET_ENCRYPTION"},
852   {0x000900DB, "FSCTL_ENCRYPTION_FSCTL_IO"},
853   {0x000900DF, "FSCTL_WRITE_RAW_ENCRYPTED"},
854   {0x000900E3, "FSCTL_READ_RAW_ENCRYPTED"},
855   {0x000940E7, "FSCTL_CREATE_USN_JOURNAL"},
856   {0x000940EB, "FSCTL_READ_FILE_USN_DATA"},
857   {0x000940EF, "FSCTL_WRITE_USN_CLOSE_RECORD"},
858   {0x000900F0, "FSCTL_EXTEND_VOLUME"},
859   { 0, NULL }
860 };
861
862
863 static const value_string smb2_ioctl_device_vals[] = {
864   { 0x0001, "BEEP" },
865   { 0x0002, "CD_ROM" },
866   { 0x0003, "CD_ROM_FILE_SYSTEM" },
867   { 0x0004, "CONTROLLER" },
868   { 0x0005, "DATALINK" },
869   { 0x0006, "DFS" },
870   { 0x0007, "DISK" },
871   { 0x0008, "DISK_FILE_SYSTEM" },
872   { 0x0009, "FILE_SYSTEM" },
873   { 0x000a, "INPORT_PORT" },
874   { 0x000b, "KEYBOARD" },
875   { 0x000c, "MAILSLOT" },
876   { 0x000d, "MIDI_IN" },
877   { 0x000e, "MIDI_OUT" },
878   { 0x000f, "MOUSE" },
879   { 0x0010, "MULTI_UNC_PROVIDER" },
880   { 0x0011, "NAMED_PIPE" },
881   { 0x0012, "NETWORK" },
882   { 0x0013, "NETWORK_BROWSER" },
883   { 0x0014, "NETWORK_FILE_SYSTEM" },
884   { 0x0015, "NULL" },
885   { 0x0016, "PARALLEL_PORT" },
886   { 0x0017, "PHYSICAL_NETCARD" },
887   { 0x0018, "PRINTER" },
888   { 0x0019, "SCANNER" },
889   { 0x001a, "SERIAL_MOUSE_PORT" },
890   { 0x001b, "SERIAL_PORT" },
891   { 0x001c, "SCREEN" },
892   { 0x001d, "SOUND" },
893   { 0x001e, "STREAMS" },
894   { 0x001f, "TAPE" },
895   { 0x0020, "TAPE_FILE_SYSTEM" },
896   { 0x0021, "TRANSPORT" },
897   { 0x0022, "UNKNOWN" },
898   { 0x0023, "VIDEO" },
899   { 0x0024, "VIRTUAL_DISK" },
900   { 0x0025, "WAVE_IN" },
901   { 0x0026, "WAVE_OUT" },
902   { 0x0027, "8042_PORT" },
903   { 0x0028, "NETWORK_REDIRECTOR" },
904   { 0x0029, "BATTERY" },
905   { 0x002a, "BUS_EXTENDER" },
906   { 0x002b, "MODEM" },
907   { 0x002c, "VDM" },
908   { 0x002d, "MASS_STORAGE" },
909   { 0x002e, "SMB" },
910   { 0x002f, "KS" },
911   { 0x0030, "CHANGER" },
912   { 0x0031, "SMARTCARD" },
913   { 0x0032, "ACPI" },
914   { 0x0033, "DVD" },
915   { 0x0034, "FULLSCREEN_VIDEO" },
916   { 0x0035, "DFS_FILE_SYSTEM" },
917   { 0x0036, "DFS_VOLUME" },
918   { 0x0037, "SERENUM" },
919   { 0x0038, "TERMSRV" },
920   { 0x0039, "KSEC" },
921   { 0, NULL }
922 };
923
924 static const value_string smb2_ioctl_access_vals[] = {
925   { 0x00, "FILE_ANY_ACCESS" },
926   { 0x01, "FILE_READ_ACCESS" },
927   { 0x02, "FILE_WRITE_ACCESS" },
928   { 0x03, "FILE_READ_WRITE_ACCESS" },
929   { 0, NULL }
930 };
931
932 static const value_string smb2_ioctl_method_vals[] = {
933   { 0x00, "METHOD_BUFFERED" },
934   { 0x01, "METHOD_IN_DIRECT" },
935   { 0x02, "METHOD_OUT_DIRECT" },
936   { 0x03, "METHOD_NEITHER" },
937   { 0, NULL }
938 };
939
940 /* this is called from both smb and smb2. */
941 int
942 dissect_smb2_ioctl_function(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int offset, guint32 *ioctlfunc)
943 {
944         proto_item *item=NULL;
945         proto_tree *tree=NULL;
946         guint32 ioctl_function;
947
948         if(parent_tree){
949                 item = proto_tree_add_item(parent_tree, hf_smb2_ioctl_function, tvb, offset, 4, TRUE);
950                 tree = proto_item_add_subtree(item, ett_smb2_ioctl_function);
951         }
952
953         ioctl_function=tvb_get_letohl(tvb, offset);
954         *ioctlfunc=ioctl_function;
955         if(ioctl_function){
956                 /* device */
957                 proto_tree_add_item(tree, hf_smb2_ioctl_function_device, tvb, offset, 4, TRUE);
958                 if (check_col(pinfo->cinfo, COL_INFO)){
959                         col_append_fstr(
960                                 pinfo->cinfo, COL_INFO, " %s",
961                                 val_to_str((ioctl_function>>16)&0xffff, smb2_ioctl_device_vals,
962                                 "Unknown (0x%08X)"));
963                 }
964
965                 /* access */
966                 proto_tree_add_item(tree, hf_smb2_ioctl_function_access, tvb, offset, 4, TRUE);
967
968                 /* function */
969                 proto_tree_add_item(tree, hf_smb2_ioctl_function_function, tvb, offset, 4, TRUE);
970                 if (check_col(pinfo->cinfo, COL_INFO)){
971                         col_append_fstr(
972                                 pinfo->cinfo, COL_INFO, " Function:0x%04x",
973                                 (ioctl_function>>2)&0x0fff);
974                 }
975
976                 /* method */
977                 proto_tree_add_item(tree, hf_smb2_ioctl_function_method, tvb, offset, 4, TRUE);
978         }
979
980         offset += 4;
981
982         return offset;
983 }
984
985 /* fake the dce/rpc support structures so we can piggy back on
986  * dissect_nt_policy_hnd()   since this will allow us
987  * a cheap way to track where FIDs are opened, closed
988  * and fid->filename mappings
989  * if we want to do those things in the future.
990  */
991 #define FID_MODE_OPEN           0
992 #define FID_MODE_CLOSE          1
993 #define FID_MODE_USE            2
994 #define FID_MODE_DHNQ           3
995 #define FID_MODE_DHNC           4
996 static int
997 dissect_smb2_fid(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, smb2_info_t *si, int mode)
998 {
999         guint8 drep[4] = { 0x10, 0x00, 0x00, 0x00}; /* fake DREP struct */
1000         static dcerpc_info di;  /* fake dcerpc_info struct */
1001         static dcerpc_call_value call_data;
1002         void *old_private_data;
1003         e_ctx_hnd policy_hnd;
1004         proto_item *hnd_item=NULL;
1005         char *fid_name;
1006         guint32 open_frame = 0, close_frame = 0;
1007
1008         di.conformant_run=0;
1009         /* we need di->call_data->flags.NDR64 == 0 */
1010         di.call_data=&call_data;
1011         old_private_data=pinfo->private_data;
1012         pinfo->private_data=&di;
1013
1014         switch(mode){
1015         case FID_MODE_OPEN:
1016                 offset = dissect_nt_guid_hnd(tvb, offset, pinfo, tree, drep, hf_smb2_fid, &policy_hnd, &hnd_item, TRUE, FALSE);
1017                 if(!pinfo->fd->flags.visited){
1018                         if(si->saved && si->saved->extra_info_type==SMB2_EI_FILENAME){
1019                                 fid_name = se_strdup_printf("File: %s", (char *)si->saved->extra_info);
1020                         } else {
1021                                 fid_name = se_strdup_printf("File: ");
1022                         }
1023                         dcerpc_store_polhnd_name(&policy_hnd, pinfo,
1024                                                   fid_name);
1025                 }
1026                 break;
1027         case FID_MODE_CLOSE:
1028                 offset = dissect_nt_guid_hnd(tvb, offset, pinfo, tree, drep, hf_smb2_fid, &policy_hnd, &hnd_item, FALSE, TRUE);
1029                 break;
1030         case FID_MODE_USE:
1031         case FID_MODE_DHNQ:
1032         case FID_MODE_DHNC:
1033                 offset = dissect_nt_guid_hnd(tvb, offset, pinfo, tree, drep, hf_smb2_fid, &policy_hnd, &hnd_item, FALSE, FALSE);
1034                 break;
1035         }
1036
1037         pinfo->private_data=old_private_data;
1038
1039
1040         /* put the filename in col_info */
1041         if (dcerpc_fetch_polhnd_data(&policy_hnd, &fid_name, NULL, &open_frame, &close_frame, pinfo->fd->num)) {
1042                 if(fid_name){
1043                         if(hnd_item){
1044                                 proto_item_append_text(hnd_item, " %s", fid_name);
1045                         }
1046                         if (check_col(pinfo->cinfo, COL_INFO)){
1047                                 col_append_fstr(pinfo->cinfo, COL_INFO, " %s", fid_name);
1048                         }
1049                 }
1050         }
1051
1052         return offset;
1053 }
1054
1055
1056 /* this info level is unique to SMB2 and differst from the corresponding
1057  * SMB_FILE_ALL_INFO in SMB
1058  */
1059 static int
1060 dissect_smb2_file_all_info(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *parent_tree, int offset, smb2_info_t *si _U_)
1061 {
1062         proto_item *item=NULL;
1063         proto_tree *tree=NULL;
1064         int length;
1065         const char *name="";
1066         guint16 bc;
1067
1068         if(parent_tree){
1069                 item = proto_tree_add_item(parent_tree, hf_smb2_file_all_info, tvb, offset, -1, TRUE);
1070                 tree = proto_item_add_subtree(item, ett_smb2_file_all_info);
1071         }
1072
1073         /* create time */
1074         offset = dissect_nt_64bit_time(tvb, tree, offset, hf_smb2_create_timestamp);
1075
1076         /* last access */
1077         offset = dissect_nt_64bit_time(tvb, tree, offset, hf_smb2_last_access_timestamp);
1078
1079         /* last write */
1080         offset = dissect_nt_64bit_time(tvb, tree, offset, hf_smb2_last_write_timestamp);
1081
1082         /* last change */
1083         offset = dissect_nt_64bit_time(tvb, tree, offset, hf_smb2_last_change_timestamp);
1084
1085         /* File Attributes */
1086         offset = dissect_file_attributes(tvb, tree, offset, 4);
1087
1088         /* some unknown bytes */
1089         proto_tree_add_item(tree, hf_smb2_unknown, tvb, offset, 4, FALSE);
1090         offset += 4;
1091
1092         /* allocation size */
1093         proto_tree_add_item(tree, hf_smb2_allocation_size, tvb, offset, 8, TRUE);
1094         offset += 8;
1095
1096         /* end of file */
1097         proto_tree_add_item(tree, hf_smb2_end_of_file, tvb, offset, 8, TRUE);
1098         offset += 8;
1099
1100         /* number of links */
1101         proto_tree_add_item(tree, hf_smb2_nlinks, tvb, offset, 4, TRUE);
1102         offset += 4;
1103
1104         /* delete pending */
1105         proto_tree_add_item(tree, hf_smb2_delete_pending, tvb, offset, 1, TRUE);
1106         offset += 1;
1107
1108         /* is directory */
1109         proto_tree_add_item(tree, hf_smb2_is_directory, tvb, offset, 1, TRUE);
1110         offset += 1;
1111
1112         /* padding */
1113         offset += 2;
1114
1115         /* file id */
1116         proto_tree_add_item(tree, hf_smb2_file_id, tvb, offset, 8, TRUE);
1117         offset += 8;
1118
1119         /* ea size */
1120         proto_tree_add_item(tree, hf_smb2_ea_size, tvb, offset, 4, TRUE);
1121         offset += 4;
1122
1123         /* access mask */
1124         offset = dissect_smb_access_mask(tvb, tree, offset);
1125
1126         /* some unknown bytes */
1127         proto_tree_add_item(tree, hf_smb2_unknown, tvb, offset, 16, FALSE);
1128         offset += 16;
1129
1130         /* file name length */
1131         length=tvb_get_letohs(tvb, offset);
1132         proto_tree_add_item(tree, hf_smb2_filename_len, tvb, offset, 2, TRUE);
1133         offset += 2;
1134
1135         /* some unknown bytes */
1136         proto_tree_add_item(tree, hf_smb2_unknown, tvb, offset, 2, FALSE);
1137         offset += 2;
1138
1139         /* file name */
1140         if(length){
1141                 bc=tvb_length_remaining(tvb, offset);
1142                 name = get_unicode_or_ascii_string(tvb, &offset,
1143                         TRUE, &length, TRUE, TRUE, &bc);
1144                 if(name){
1145                         proto_tree_add_string(tree, hf_smb2_filename, tvb,
1146                                 offset, length, name);
1147                 }
1148
1149         }
1150         offset += length;
1151
1152
1153         return offset;
1154 }
1155
1156
1157 static int
1158 dissect_smb2_file_allocation_info(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *parent_tree, int offset, smb2_info_t *si _U_)
1159 {
1160         proto_item *item=NULL;
1161         proto_tree *tree=NULL;
1162         guint16 bc;
1163         gboolean trunc;
1164
1165         if(parent_tree){
1166                 item = proto_tree_add_item(parent_tree, hf_smb2_file_allocation_info, tvb, offset, -1, TRUE);
1167                 tree = proto_item_add_subtree(item, ett_smb2_file_allocation_info);
1168         }
1169
1170         bc=tvb_length_remaining(tvb, offset);
1171         offset = dissect_qfi_SMB_FILE_ALLOCATION_INFO(tvb, pinfo, tree, offset, &bc, &trunc);
1172
1173         return offset;
1174 }
1175
1176 static int
1177 dissect_smb2_file_endoffile_info(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *parent_tree, int offset, smb2_info_t *si _U_)
1178 {
1179         proto_item *item=NULL;
1180         proto_tree *tree=NULL;
1181         guint16 bc;
1182         gboolean trunc;
1183
1184         if(parent_tree){
1185                 item = proto_tree_add_item(parent_tree, hf_smb2_file_endoffile_info, tvb, offset, -1, TRUE);
1186                 tree = proto_item_add_subtree(item, ett_smb2_file_endoffile_info);
1187         }
1188
1189         bc=tvb_length_remaining(tvb, offset);
1190         offset = dissect_qfi_SMB_FILE_ENDOFFILE_INFO(tvb, pinfo, tree, offset, &bc, &trunc);
1191
1192         return offset;
1193 }
1194
1195 static int
1196 dissect_smb2_file_alternate_name_info(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *parent_tree, int offset, smb2_info_t *si _U_)
1197 {
1198         proto_item *item=NULL;
1199         proto_tree *tree=NULL;
1200         guint16 bc;
1201         gboolean trunc;
1202
1203         if(parent_tree){
1204                 item = proto_tree_add_item(parent_tree, hf_smb2_file_alternate_name_info, tvb, offset, -1, TRUE);
1205                 tree = proto_item_add_subtree(item, ett_smb2_file_alternate_name_info);
1206         }
1207
1208         bc=tvb_length_remaining(tvb, offset);
1209         offset = dissect_qfi_SMB_FILE_ALTERNATE_NAME_INFO(tvb, pinfo, tree, offset, &bc, &trunc);
1210
1211         return offset;
1212 }
1213
1214
1215 static int
1216 dissect_smb2_file_basic_info(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *parent_tree, int offset, smb2_info_t *si _U_)
1217 {
1218         proto_item *item=NULL;
1219         proto_tree *tree=NULL;
1220
1221         if(parent_tree){
1222                 item = proto_tree_add_item(parent_tree, hf_smb2_file_basic_info, tvb, offset, -1, TRUE);
1223                 tree = proto_item_add_subtree(item, ett_smb2_file_basic_info);
1224         }
1225
1226         /* create time */
1227         offset = dissect_nt_64bit_time(tvb, tree, offset, hf_smb2_create_timestamp);
1228
1229         /* last access */
1230         offset = dissect_nt_64bit_time(tvb, tree, offset, hf_smb2_last_access_timestamp);
1231
1232         /* last write */
1233         offset = dissect_nt_64bit_time(tvb, tree, offset, hf_smb2_last_write_timestamp);
1234
1235         /* last change */
1236         offset = dissect_nt_64bit_time(tvb, tree, offset, hf_smb2_last_change_timestamp);
1237
1238         /* File Attributes */
1239         offset = dissect_file_attributes(tvb, tree, offset, 4);
1240
1241         /* some unknown bytes */
1242         proto_tree_add_item(tree, hf_smb2_unknown, tvb, offset, 4, FALSE);
1243         offset += 4;
1244
1245         return offset;
1246 }
1247
1248 static int
1249 dissect_smb2_file_standard_info(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *parent_tree, int offset, smb2_info_t *si _U_)
1250 {
1251         proto_item *item=NULL;
1252         proto_tree *tree=NULL;
1253         guint16 bc;
1254         gboolean trunc;
1255
1256         if(parent_tree){
1257                 item = proto_tree_add_item(parent_tree, hf_smb2_file_standard_info, tvb, offset, -1, TRUE);
1258                 tree = proto_item_add_subtree(item, ett_smb2_file_standard_info);
1259         }
1260
1261         bc=tvb_length_remaining(tvb, offset);
1262         offset = dissect_qfi_SMB_FILE_STANDARD_INFO(tvb, pinfo, tree, offset, &bc, &trunc);
1263
1264         return offset;
1265 }
1266 static int
1267 dissect_smb2_file_internal_info(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *parent_tree, int offset, smb2_info_t *si _U_)
1268 {
1269         proto_item *item=NULL;
1270         proto_tree *tree=NULL;
1271         guint16 bc;
1272         gboolean trunc;
1273
1274         if(parent_tree){
1275                 item = proto_tree_add_item(parent_tree, hf_smb2_file_internal_info, tvb, offset, -1, TRUE);
1276                 tree = proto_item_add_subtree(item, ett_smb2_file_internal_info);
1277         }
1278
1279         bc=tvb_length_remaining(tvb, offset);
1280         offset = dissect_qfi_SMB_FILE_INTERNAL_INFO(tvb, pinfo, tree, offset, &bc, &trunc);
1281
1282         return offset;
1283 }
1284 static int
1285 dissect_smb2_file_mode_info(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *parent_tree, int offset, smb2_info_t *si _U_)
1286 {
1287         proto_item *item=NULL;
1288         proto_tree *tree=NULL;
1289         guint16 bc;
1290         gboolean trunc;
1291
1292         if(parent_tree){
1293                 item = proto_tree_add_item(parent_tree, hf_smb2_file_mode_info, tvb, offset, -1, TRUE);
1294                 tree = proto_item_add_subtree(item, ett_smb2_file_mode_info);
1295         }
1296
1297         bc=tvb_length_remaining(tvb, offset);
1298         offset = dissect_qfi_SMB_FILE_MODE_INFO(tvb, pinfo, tree, offset, &bc, &trunc);
1299
1300         return offset;
1301 }
1302 static int
1303 dissect_smb2_file_alignment_info(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *parent_tree, int offset, smb2_info_t *si _U_)
1304 {
1305         proto_item *item=NULL;
1306         proto_tree *tree=NULL;
1307         guint16 bc;
1308         gboolean trunc;
1309
1310         if(parent_tree){
1311                 item = proto_tree_add_item(parent_tree, hf_smb2_file_alignment_info, tvb, offset, -1, TRUE);
1312                 tree = proto_item_add_subtree(item, ett_smb2_file_alignment_info);
1313         }
1314
1315         bc=tvb_length_remaining(tvb, offset);
1316         offset = dissect_qfi_SMB_FILE_ALIGNMENT_INFO(tvb, pinfo, tree, offset, &bc, &trunc);
1317
1318         return offset;
1319 }
1320 static int
1321 dissect_smb2_file_position_info(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *parent_tree, int offset, smb2_info_t *si _U_)
1322 {
1323         proto_item *item=NULL;
1324         proto_tree *tree=NULL;
1325         guint16 bc;
1326         gboolean trunc;
1327
1328         if(parent_tree){
1329                 item = proto_tree_add_item(parent_tree, hf_smb2_file_position_info, tvb, offset, -1, TRUE);
1330                 tree = proto_item_add_subtree(item, ett_smb2_file_position_info);
1331         }
1332
1333         bc=tvb_length_remaining(tvb, offset);
1334         offset = dissect_qfi_SMB_FILE_POSITION_INFO(tvb, pinfo, tree, offset, &bc, &trunc);
1335
1336         return offset;
1337 }
1338
1339 static int
1340 dissect_smb2_file_access_info(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *parent_tree, int offset, smb2_info_t *si _U_)
1341 {
1342         proto_item *item=NULL;
1343         proto_tree *tree=NULL;
1344
1345         if(parent_tree){
1346                 item = proto_tree_add_item(parent_tree, hf_smb2_file_access_info, tvb, offset, -1, TRUE);
1347                 tree = proto_item_add_subtree(item, ett_smb2_file_access_info);
1348         }
1349
1350         /* access mask */
1351         offset = dissect_smb_access_mask(tvb, tree, offset);
1352
1353         return offset;
1354 }
1355
1356 static int
1357 dissect_smb2_file_ea_info(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *parent_tree, int offset, smb2_info_t *si _U_)
1358 {
1359         proto_item *item=NULL;
1360         proto_tree *tree=NULL;
1361         guint16 bc;
1362         gboolean trunc;
1363
1364         if(parent_tree){
1365                 item = proto_tree_add_item(parent_tree, hf_smb2_file_ea_info, tvb, offset, -1, TRUE);
1366                 tree = proto_item_add_subtree(item, ett_smb2_file_ea_info);
1367         }
1368
1369         bc=tvb_length_remaining(tvb, offset);
1370         offset = dissect_qfi_SMB_FILE_EA_INFO(tvb, pinfo, tree, offset, &bc, &trunc);
1371
1372         return offset;
1373 }
1374
1375 static int
1376 dissect_smb2_file_stream_info(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *parent_tree, int offset, smb2_info_t *si _U_)
1377 {
1378         proto_item *item=NULL;
1379         proto_tree *tree=NULL;
1380         guint16 bc;
1381         gboolean trunc;
1382
1383         if(parent_tree){
1384                 item = proto_tree_add_item(parent_tree, hf_smb2_file_stream_info, tvb, offset, -1, TRUE);
1385                 tree = proto_item_add_subtree(item, ett_smb2_file_stream_info);
1386         }
1387
1388         bc=tvb_length_remaining(tvb, offset);
1389         offset = dissect_qfi_SMB_FILE_STREAM_INFO(tvb, pinfo, tree, offset, &bc, &trunc, TRUE);
1390
1391         return offset;
1392 }
1393
1394 static int
1395 dissect_smb2_file_pipe_info(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *parent_tree, int offset, smb2_info_t *si _U_)
1396 {
1397         proto_item *item=NULL;
1398         proto_tree *tree=NULL;
1399         guint16 bc;
1400         gboolean trunc;
1401
1402         if(parent_tree){
1403                 item = proto_tree_add_item(parent_tree, hf_smb2_file_pipe_info, tvb, offset, -1, TRUE);
1404                 tree = proto_item_add_subtree(item, ett_smb2_file_pipe_info);
1405         }
1406
1407         bc=tvb_length_remaining(tvb, offset);
1408         offset = dissect_sfi_SMB_FILE_PIPE_INFO(tvb, pinfo, tree, offset, &bc, &trunc);
1409
1410         return offset;
1411 }
1412
1413 static int
1414 dissect_smb2_file_compression_info(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *parent_tree, int offset, smb2_info_t *si _U_)
1415 {
1416         proto_item *item=NULL;
1417         proto_tree *tree=NULL;
1418         guint16 bc;
1419         gboolean trunc;
1420
1421         if(parent_tree){
1422                 item = proto_tree_add_item(parent_tree, hf_smb2_file_compression_info, tvb, offset, -1, TRUE);
1423                 tree = proto_item_add_subtree(item, ett_smb2_file_compression_info);
1424         }
1425
1426         bc=tvb_length_remaining(tvb, offset);
1427         offset = dissect_qfi_SMB_FILE_COMPRESSION_INFO(tvb, pinfo, tree, offset, &bc, &trunc);
1428
1429         return offset;
1430 }
1431
1432 static int
1433 dissect_smb2_file_network_open_info(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *parent_tree, int offset, smb2_info_t *si _U_)
1434 {
1435         proto_item *item=NULL;
1436         proto_tree *tree=NULL;
1437         guint16 bc;
1438         gboolean trunc;
1439
1440         if(parent_tree){
1441                 item = proto_tree_add_item(parent_tree, hf_smb2_file_network_open_info, tvb, offset, -1, TRUE);
1442                 tree = proto_item_add_subtree(item, ett_smb2_file_network_open_info);
1443         }
1444
1445
1446         bc=tvb_length_remaining(tvb, offset);
1447         offset = dissect_qfi_SMB_FILE_NETWORK_OPEN_INFO(tvb, pinfo, tree, offset, &bc, &trunc);
1448
1449         return offset;
1450 }
1451
1452 static int
1453 dissect_smb2_file_attribute_tag_info(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *parent_tree, int offset, smb2_info_t *si _U_)
1454 {
1455         proto_item *item=NULL;
1456         proto_tree *tree=NULL;
1457         guint16 bc;
1458         gboolean trunc;
1459
1460         if(parent_tree){
1461                 item = proto_tree_add_item(parent_tree, hf_smb2_file_attribute_tag_info, tvb, offset, -1, TRUE);
1462                 tree = proto_item_add_subtree(item, ett_smb2_file_attribute_tag_info);
1463         }
1464
1465
1466         bc=tvb_length_remaining(tvb, offset);
1467         offset = dissect_qfi_SMB_FILE_ATTRIBUTE_TAG_INFO(tvb, pinfo, tree, offset, &bc, &trunc);
1468
1469         return offset;
1470 }
1471
1472 static const true_false_string tfs_disposition_delete_on_close = {
1473         "DELETE this file when closed",
1474         "Normal access, do not delete on close"
1475 };
1476
1477 static int
1478 dissect_smb2_file_disposition_info(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *parent_tree, int offset, smb2_info_t *si _U_)
1479 {
1480         proto_item *item=NULL;
1481         proto_tree *tree=NULL;
1482
1483         if(parent_tree){
1484                 item = proto_tree_add_item(parent_tree, hf_smb2_file_disposition_info, tvb, offset, -1, TRUE);
1485                 tree = proto_item_add_subtree(item, ett_smb2_file_disposition_info);
1486         }
1487
1488         /* file disposition */
1489         proto_tree_add_item(tree, hf_smb2_disposition_delete_on_close, tvb, offset, 1, TRUE);
1490
1491         return offset;
1492 }
1493
1494 static int
1495 dissect_smb2_file_info_0f(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *parent_tree, int offset, smb2_info_t *si _U_)
1496 {
1497         proto_item *item=NULL;
1498         proto_tree *tree=NULL;
1499         guint32 next_offset;
1500         guint8 ea_name_len, ea_data_len;
1501
1502         if(parent_tree){
1503                 item = proto_tree_add_item(parent_tree, hf_smb2_file_info_0f, tvb, offset, -1, TRUE);
1504                 tree = proto_item_add_subtree(item, ett_smb2_file_info_0f);
1505         }
1506
1507         while(1){
1508                 int length;
1509                 const char *name="";
1510                 const char *data="";
1511                 guint16 bc;
1512                 int start_offset=offset;
1513                 proto_item *ea_item=NULL;
1514                 proto_tree *ea_tree=NULL;
1515
1516                 if(tree){
1517                         ea_item = proto_tree_add_text(tree, tvb, offset, -1, "EA:");
1518                         ea_tree = proto_item_add_subtree(ea_item, ett_smb2_ea);
1519                 }
1520
1521                 /* next offset */
1522                 next_offset=tvb_get_letohl(tvb, offset);
1523                 proto_tree_add_item(ea_tree, hf_smb2_next_offset, tvb, offset, 4, TRUE);
1524                 offset += 4;
1525
1526                 /* EA flags */
1527                 proto_tree_add_item(ea_tree, hf_smb2_ea_flags, tvb, offset, 1, TRUE);
1528                 offset += 1;
1529
1530                 /* EA Name Length */
1531                 ea_name_len=tvb_get_guint8(tvb, offset);
1532                 proto_tree_add_item(ea_tree, hf_smb2_ea_name_len, tvb, offset, 1, TRUE);
1533                 offset += 1;
1534
1535                 /* EA Data Length */
1536                 ea_data_len=tvb_get_guint8(tvb, offset);
1537                 proto_tree_add_item(ea_tree, hf_smb2_ea_data_len, tvb, offset, 1, TRUE);
1538                 offset += 1;
1539
1540                 /* some unknown bytes */
1541                 proto_tree_add_item(ea_tree, hf_smb2_unknown, tvb, offset, 1, TRUE);
1542                 offset += 1;
1543
1544                 /* ea name */
1545                 length=ea_name_len;
1546                 if(length){
1547                         bc=tvb_length_remaining(tvb, offset);
1548                         name = get_unicode_or_ascii_string(tvb, &offset,
1549                                 FALSE, &length, TRUE, TRUE, &bc);
1550                         if(name){
1551                                 proto_tree_add_string(ea_tree, hf_smb2_ea_name, tvb,
1552                                         offset, length, name);
1553                         }
1554                 }
1555                 offset += ea_name_len;
1556
1557                 /* separator byte */
1558                 offset += 1;
1559
1560                 /* ea data */
1561                 length=ea_data_len;
1562                 if(length){
1563                         bc=tvb_length_remaining(tvb, offset);
1564                         data = get_unicode_or_ascii_string(tvb, &offset,
1565                                 FALSE, &length, TRUE, TRUE, &bc);
1566                         if(data){
1567                                 proto_tree_add_string(ea_tree, hf_smb2_ea_data, tvb,
1568                                         offset, length, data);
1569                         }
1570                 }
1571                 offset += ea_data_len;
1572
1573
1574                 if(ea_item){
1575                         proto_item_append_text(ea_item, " %s := %s", name, data);
1576                 }
1577                 proto_item_set_len(ea_item, offset-start_offset);
1578
1579
1580                 if(!next_offset){
1581                         break;
1582                 }
1583                 if(next_offset>256){
1584                         break;
1585                 }
1586
1587                 offset = start_offset+next_offset;
1588         }
1589
1590         return offset;
1591 }
1592
1593 static int
1594 dissect_smb2_file_rename_info(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *parent_tree, int offset, smb2_info_t *si _U_)
1595 {
1596         proto_item *item=NULL;
1597         proto_tree *tree=NULL;
1598         int length;
1599         const char *name="";
1600         guint16 bc;
1601
1602
1603         if(parent_tree){
1604                 item = proto_tree_add_item(parent_tree, hf_smb2_file_rename_info, tvb, offset, -1, TRUE);
1605                 tree = proto_item_add_subtree(item, ett_smb2_file_rename_info);
1606         }
1607
1608         /* some unknown bytes */
1609         proto_tree_add_item(tree, hf_smb2_unknown, tvb, offset, 16, FALSE);
1610         offset += 16;
1611
1612         /* file name length */
1613         length=tvb_get_letohs(tvb, offset);
1614         proto_tree_add_item(tree, hf_smb2_filename_len, tvb, offset, 2, TRUE);
1615         offset += 2;
1616
1617         /* some unknown bytes */
1618         proto_tree_add_item(tree, hf_smb2_unknown, tvb, offset, 2, FALSE);
1619         offset += 2;
1620
1621         /* file name */
1622         if(length){
1623                 bc=tvb_length_remaining(tvb, offset);
1624                 name = get_unicode_or_ascii_string(tvb, &offset,
1625                         TRUE, &length, TRUE, TRUE, &bc);
1626                 if(name){
1627                         proto_tree_add_string(tree, hf_smb2_filename, tvb,
1628                                 offset, length, name);
1629                 }
1630
1631                 if (check_col(pinfo->cinfo, COL_INFO)){
1632                         col_append_fstr(pinfo->cinfo, COL_INFO, " NewName:%s",
1633                         name);
1634                 }
1635         }
1636         offset += length;
1637
1638         /* some unknown bytes */
1639         proto_tree_add_item(tree, hf_smb2_unknown, tvb, offset, 4, FALSE);
1640         offset += 4;
1641
1642         return offset;
1643 }
1644
1645 static int
1646 dissect_smb2_sec_info_00(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *parent_tree, int offset, smb2_info_t *si _U_)
1647 {
1648         proto_item *item=NULL;
1649         proto_tree *tree=NULL;
1650
1651         if(parent_tree){
1652                 item = proto_tree_add_item(parent_tree, hf_smb2_sec_info_00, tvb, offset, -1, TRUE);
1653                 tree = proto_item_add_subtree(item, ett_smb2_sec_info_00);
1654         }
1655
1656         /* security descriptor */
1657         offset = dissect_nt_sec_desc(tvb, offset, pinfo, tree, NULL, TRUE, tvb_length_remaining(tvb, offset), NULL);
1658
1659         return offset;
1660 }
1661
1662 static int
1663 dissect_smb2_fs_info_05(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *parent_tree, int offset, smb2_info_t *si _U_)
1664 {
1665         proto_item *item=NULL;
1666         proto_tree *tree=NULL;
1667         guint16 bc;
1668
1669         if(parent_tree){
1670                 item = proto_tree_add_item(parent_tree, hf_smb2_fs_info_05, tvb, offset, -1, TRUE);
1671                 tree = proto_item_add_subtree(item, ett_smb2_fs_info_05);
1672         }
1673
1674         bc=tvb_length_remaining(tvb, offset);
1675         offset=dissect_qfsi_FS_ATTRIBUTE_INFO(tvb, pinfo, tree, offset, &bc, TRUE);
1676
1677         return offset;
1678 }
1679
1680 static int
1681 dissect_smb2_fs_info_06(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *parent_tree, int offset, smb2_info_t *si _U_)
1682 {
1683         proto_item *item=NULL;
1684         proto_tree *tree=NULL;
1685         guint16 bc;
1686
1687         if(parent_tree){
1688                 item = proto_tree_add_item(parent_tree, hf_smb2_fs_info_06, tvb, offset, -1, TRUE);
1689                 tree = proto_item_add_subtree(item, ett_smb2_fs_info_06);
1690         }
1691
1692         bc=tvb_length_remaining(tvb, offset);
1693         offset=dissect_nt_quota(tvb, tree, offset, &bc);
1694
1695         return offset;
1696 }
1697
1698 static int
1699 dissect_smb2_FS_OBJECTID_INFO(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *parent_tree, int offset, smb2_info_t *si _U_)
1700 {
1701         proto_item *item=NULL;
1702         proto_tree *tree=NULL;
1703
1704         if(parent_tree){
1705                 item = proto_tree_add_item(parent_tree, hf_smb2_fs_objectid_info, tvb, offset, -1, TRUE);
1706                 tree = proto_item_add_subtree(item, ett_smb2_fs_objectid_info);
1707         }
1708
1709         /* FILE_OBJECTID_BUFFER */
1710         offset=dissect_smb2_FILE_OBJECTID_BUFFER(tvb, pinfo, tree, offset);
1711
1712         return offset;
1713 }
1714
1715 static int
1716 dissect_smb2_fs_info_07(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *parent_tree, int offset, smb2_info_t *si _U_)
1717 {
1718         proto_item *item=NULL;
1719         proto_tree *tree=NULL;
1720         guint16 bc;
1721
1722         if(parent_tree){
1723                 item = proto_tree_add_item(parent_tree, hf_smb2_fs_info_07, tvb, offset, -1, TRUE);
1724                 tree = proto_item_add_subtree(item, ett_smb2_fs_info_07);
1725         }
1726
1727         bc=tvb_length_remaining(tvb, offset);
1728         offset=dissect_qfsi_FS_FULL_SIZE_INFO(tvb, pinfo, tree, offset, &bc);
1729
1730         return offset;
1731 }
1732
1733 static int
1734 dissect_smb2_fs_info_01(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *parent_tree, int offset, smb2_info_t *si _U_)
1735 {
1736         proto_item *item=NULL;
1737         proto_tree *tree=NULL;
1738         guint16 bc;
1739
1740         if(parent_tree){
1741                 item = proto_tree_add_item(parent_tree, hf_smb2_fs_info_01, tvb, offset, -1, TRUE);
1742                 tree = proto_item_add_subtree(item, ett_smb2_fs_info_01);
1743         }
1744
1745
1746         bc=tvb_length_remaining(tvb, offset);
1747         offset=dissect_qfsi_FS_VOLUME_INFO(tvb, pinfo, tree, offset, &bc, TRUE);
1748
1749         return offset;
1750 }
1751
1752 static int
1753 dissect_smb2_fs_info_03(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *parent_tree, int offset, smb2_info_t *si _U_)
1754 {
1755         proto_item *item=NULL;
1756         proto_tree *tree=NULL;
1757         guint16 bc;
1758
1759         if(parent_tree){
1760                 item = proto_tree_add_item(parent_tree, hf_smb2_fs_info_03, tvb, offset, -1, TRUE);
1761                 tree = proto_item_add_subtree(item, ett_smb2_fs_info_03);
1762         }
1763
1764
1765         bc=tvb_length_remaining(tvb, offset);
1766         offset=dissect_qfsi_FS_SIZE_INFO(tvb, pinfo, tree, offset, &bc);
1767
1768         return offset;
1769 }
1770
1771 static int
1772 dissect_smb2_fs_info_04(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *parent_tree, int offset, smb2_info_t *si _U_)
1773 {
1774         proto_item *item=NULL;
1775         proto_tree *tree=NULL;
1776         guint16 bc;
1777
1778         if(parent_tree){
1779                 item = proto_tree_add_item(parent_tree, hf_smb2_fs_info_04, tvb, offset, -1, TRUE);
1780                 tree = proto_item_add_subtree(item, ett_smb2_fs_info_04);
1781         }
1782
1783
1784         bc=tvb_length_remaining(tvb, offset);
1785         offset=dissect_qfsi_FS_DEVICE_INFO(tvb, pinfo, tree, offset, &bc);
1786
1787         return offset;
1788 }
1789
1790 static const value_string oplock_vals[] = {
1791         { 0x00, "No oplock" },
1792         { 0x01, "Level2 oplock" },
1793         { 0x08, "Exclusive oplock" },
1794         { 0x09, "Batch oplock" },
1795         { 0, NULL }
1796 };
1797
1798 static int
1799 dissect_smb2_oplock(proto_tree *parent_tree, tvbuff_t *tvb, int offset)
1800 {
1801         proto_tree_add_item(parent_tree, hf_smb2_oplock, tvb, offset, 1, TRUE);
1802
1803         offset += 1;
1804         return offset;
1805 }
1806
1807 static int
1808 dissect_smb2_buffercode(proto_tree *tree, tvbuff_t *tvb, int offset, guint16 *length)
1809 {
1810         guint16 buffer_code;
1811
1812         /* dissect the first 2 bytes of the command PDU */
1813         buffer_code = tvb_get_letohs(tvb, offset);
1814         proto_tree_add_uint(tree, hf_smb2_buffer_code_len, tvb, offset, 2, buffer_code&0xfffe);
1815         proto_tree_add_item(tree, hf_smb2_buffer_code_flags_dyn, tvb, offset, 2, TRUE);
1816         offset += 2;
1817
1818         if(length){
1819                 *length=buffer_code&0xfffe;
1820         }
1821
1822         return offset;
1823 }
1824
1825 #define NEGPROT_CAP_DFS         0x00000001
1826 static int
1827 dissect_smb2_capabilities(proto_tree *parent_tree, tvbuff_t *tvb, int offset)
1828 {
1829         guint32 cap;
1830         proto_item *item=NULL;
1831         proto_tree *tree=NULL;
1832
1833         cap = tvb_get_letohl(tvb, offset);
1834
1835         item = proto_tree_add_item(parent_tree, hf_smb2_capabilities, tvb, offset, 4, TRUE);
1836         tree = proto_item_add_subtree(item, ett_smb2_capabilities);
1837
1838
1839         proto_tree_add_boolean(tree, hf_smb2_cap_dfs, tvb, offset, 4, cap);
1840
1841
1842         offset += 4;
1843
1844         return offset;
1845 }
1846
1847
1848
1849 #define NEGPROT_SIGN_REQ        0x0002
1850 #define NEGPROT_SIGN_ENABLED    0x0001
1851
1852 static int
1853 dissect_smb2_secmode(proto_tree *parent_tree, tvbuff_t *tvb, int offset)
1854 {
1855         guint8 sm;
1856         proto_item *item=NULL;
1857         proto_tree *tree=NULL;
1858
1859         sm = tvb_get_guint8(tvb, offset);
1860
1861         item = proto_tree_add_item(parent_tree, hf_smb2_security_mode, tvb, offset, 1, TRUE);
1862         tree = proto_item_add_subtree(item, ett_smb2_sec_mode);
1863
1864
1865         proto_tree_add_boolean(tree, hf_smb2_secmode_flags_sign_required, tvb, offset, 1, sm);
1866         proto_tree_add_boolean(tree, hf_smb2_secmode_flags_sign_enabled, tvb, offset, 1, sm);
1867
1868
1869         offset += 1;
1870
1871         return offset;
1872 }
1873
1874 #define SES_FLAGS_GUEST         0x0001
1875 #define SES_FLAGS_NULL          0x0002
1876
1877 static int
1878 dissect_smb2_ses_flags(proto_tree *parent_tree, tvbuff_t *tvb, int offset)
1879 {
1880         guint16 sf;
1881         proto_item *item=NULL;
1882         proto_tree *tree=NULL;
1883
1884         sf = tvb_get_letohs(tvb, offset);
1885
1886         item = proto_tree_add_item(parent_tree, hf_smb2_session_flags, tvb, offset, 2, TRUE);
1887         tree = proto_item_add_subtree(item, ett_smb2_ses_flags);
1888
1889
1890         proto_tree_add_boolean(tree, hf_smb2_ses_flags_null, tvb, offset, 2, sf);
1891         proto_tree_add_boolean(tree, hf_smb2_ses_flags_guest, tvb, offset, 2, sf);
1892
1893
1894         offset += 2;
1895
1896         return offset;
1897 }
1898
1899 #define SHARE_FLAGS_manual_caching              0x00000000
1900 #define SHARE_FLAGS_auto_caching                0x00000010
1901 #define SHARE_FLAGS_vdo_caching                 0x00000020
1902 #define SHARE_FLAGS_no_caching                  0x00000030
1903
1904 static const value_string share_cache_vals[] = {
1905         { SHARE_FLAGS_manual_caching,   "manual_caching" },
1906         { SHARE_FLAGS_auto_caching,     "auto_caching" },
1907         { SHARE_FLAGS_vdo_caching,      "vdo_caching" },
1908         { SHARE_FLAGS_no_caching,       "no_caching" },
1909         { 0, NULL }
1910 };
1911
1912 #define SHARE_FLAGS_dfs                         0x00000001
1913 #define SHARE_FLAGS_dfs_root                    0x00000002
1914 #define SHARE_FLAGS_restrict_exclusive_opens    0x00000100
1915 #define SHARE_FLAGS_force_shared_delete         0x00000200
1916 #define SHARE_FLAGS_allow_namespace_caching     0x00000400
1917 #define SHARE_FLAGS_access_based_dir_enum       0x00000800
1918
1919 static int
1920 dissect_smb2_share_flags(proto_tree *tree, tvbuff_t *tvb, int offset)
1921 {
1922         static const int *sf_fields[] = {
1923                 &hf_smb2_share_flags_dfs,
1924                 &hf_smb2_share_flags_dfs_root,
1925                 &hf_smb2_share_flags_restrict_exclusive_opens,
1926                 &hf_smb2_share_flags_force_shared_delete,
1927                 &hf_smb2_share_flags_allow_namespace_caching,
1928                 &hf_smb2_share_flags_access_based_dir_enum,
1929                 NULL
1930         };
1931         proto_item *item;
1932         guint32 cp;
1933
1934         item = proto_tree_add_bitmask(tree, tvb, offset, hf_smb2_share_flags, ett_smb2_share_flags, sf_fields, TRUE);
1935
1936         cp = tvb_get_letohl(tvb, offset);
1937         cp &= 0x00000030;
1938         proto_tree_add_uint_format(item, hf_smb2_share_caching, tvb, offset, 4, cp, "Caching policy: %s (%08x)", val_to_str(cp, share_cache_vals, "Unknown:%u"), cp);
1939
1940
1941         offset += 4;
1942
1943         return offset;
1944 }
1945
1946 #define SHARE_CAPS_DFS          0x00000008
1947
1948 static int
1949 dissect_smb2_share_caps(proto_tree *tree, tvbuff_t *tvb, int offset)
1950 {
1951         static const int *sc_fields[] = {
1952                 &hf_smb2_share_caps_dfs,
1953                 NULL
1954         };
1955         proto_item *item;
1956
1957         item = proto_tree_add_bitmask(tree, tvb, offset, hf_smb2_share_caps, ett_smb2_share_caps, sc_fields, TRUE);
1958
1959
1960         offset += 4;
1961
1962         return offset;
1963 }
1964
1965 static void
1966 dissect_smb2_secblob(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, smb2_info_t *si _U_)
1967 {
1968         if( (tvb_length(tvb)>=7)
1969         &&  (!tvb_memeql(tvb, 0, "NTLMSSP", 7))){
1970                 call_dissector(ntlmssp_handle, tvb, pinfo, tree);
1971         } else {
1972                 call_dissector(gssapi_handle, tvb, pinfo, tree);
1973         }
1974         return;
1975 }
1976
1977 static int
1978 dissect_smb2_session_setup_request(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, smb2_info_t *si)
1979 {
1980         offset_length_buffer_t s_olb;
1981         const ntlmssp_header_t *ntlmssph;
1982         static int ntlmssp_tap_id = 0;
1983         int idx;
1984
1985         if(!ntlmssp_tap_id){
1986                 GString *error_string;
1987                 /* We dont specify any callbacks at all.
1988                  * Instead we manually fetch the tapped data after the
1989                  * security blob has been fully dissected and before
1990                  * we exit from this dissector.
1991                  */
1992                 error_string=register_tap_listener("ntlmssp", NULL, NULL,
1993                     0, NULL, NULL, NULL);
1994                 if(!error_string){
1995                         ntlmssp_tap_id=find_tap_id("ntlmssp");
1996                 }
1997         }
1998
1999
2000         /* buffer code */
2001         offset = dissect_smb2_buffercode(tree, tvb, offset, NULL);
2002         /* some unknown bytes */
2003
2004         /* num vcs */
2005         proto_tree_add_item(tree, hf_smb2_vcnum, tvb, offset, 1, TRUE);
2006         offset += 1;
2007
2008         /* security mode */
2009         offset = dissect_smb2_secmode(tree, tvb, offset);
2010
2011         /* capabilities */
2012         offset = dissect_smb2_capabilities(tree, tvb, offset);
2013
2014         /* channel */
2015         proto_tree_add_item(tree, hf_smb2_channel, tvb, offset, 4, TRUE);
2016         offset += 4;
2017
2018         /* security blob offset/length */
2019         offset = dissect_smb2_olb_length_offset(tvb, offset, &s_olb, OLB_O_UINT16_S_UINT16, hf_smb2_security_blob);
2020
2021         /* previous session id */
2022         proto_tree_add_item(tree, hf_smb2_previous_sesid, tvb, offset, 8, TRUE);
2023         offset += 8;
2024
2025
2026         /* the security blob itself */
2027         dissect_smb2_olb_buffer(pinfo, tree, tvb, &s_olb, si, dissect_smb2_secblob);
2028
2029         offset = dissect_smb2_olb_tvb_max_offset(offset, &s_olb);
2030
2031         /* If we have found a uid->acct_name mapping, store it */
2032         if(!pinfo->fd->flags.visited){
2033                 idx=0;
2034                 while((ntlmssph=fetch_tapped_data(ntlmssp_tap_id, idx++)) != NULL){
2035                         if(ntlmssph && ntlmssph->type==3){
2036                                 smb2_sesid_info_t *sesid;
2037                                 sesid=se_alloc(sizeof(smb2_sesid_info_t));
2038                                 sesid->sesid=si->sesid;
2039                                 sesid->acct_name=se_strdup(ntlmssph->acct_name);
2040                                 sesid->domain_name=se_strdup(ntlmssph->domain_name);
2041                                 sesid->host_name=se_strdup(ntlmssph->host_name);
2042                                 sesid->auth_frame=pinfo->fd->num;
2043                                 sesid->tids= g_hash_table_new(smb2_tid_info_hash, smb2_tid_info_equal);
2044                                 g_hash_table_insert(si->conv->sesids, sesid, sesid);
2045                         }
2046                 }
2047         }
2048
2049         return offset;
2050 }
2051
2052 static int
2053 dissect_smb2_error_response(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int offset, smb2_info_t *si _U_)
2054 {
2055         gint byte_count;
2056
2057         /* buffer code */
2058         offset = dissect_smb2_buffercode(tree, tvb, offset, NULL);
2059
2060
2061         /* Reserved (2 bytes) */
2062         proto_tree_add_item(tree, hf_smb2_error_reserved, tvb, offset, 2, TRUE);
2063         offset += 2;
2064
2065         /* ByteCount (4 bytes): The number of bytes of data contained in ErrorData[]. */
2066         byte_count = tvb_get_ntohl(tvb, offset);
2067         proto_tree_add_item(tree, hf_smb2_error_byte_count, tvb, offset, 4, TRUE);
2068         offset += 4;
2069
2070         /* If the ByteCount field is zero then the server MUST supply an ErrorData field 
2071            that is one byte in length */
2072         if (byte_count == 0) byte_count = 1;
2073
2074         /* ErrorData (variable): A variable-length data field that contains extended 
2075            error information.*/
2076         proto_tree_add_item(tree, hf_smb2_error_data, tvb, offset, byte_count, TRUE);
2077         offset += byte_count;
2078
2079         return offset;
2080 }
2081
2082 static int
2083 dissect_smb2_session_setup_response(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, smb2_info_t *si _U_)
2084 {
2085         offset_length_buffer_t s_olb;
2086
2087         /* session_setup is special and we don't use dissect_smb2_error_response() here! */
2088
2089         /* buffer code */
2090         offset = dissect_smb2_buffercode(tree, tvb, offset, NULL);
2091
2092         /* session flags */
2093         offset = dissect_smb2_ses_flags(tree, tvb, offset);
2094
2095         /* security blob offset/length */
2096         offset = dissect_smb2_olb_length_offset(tvb, offset, &s_olb, OLB_O_UINT16_S_UINT16, hf_smb2_security_blob);
2097
2098         /* the security blob itself */
2099         dissect_smb2_olb_buffer(pinfo, tree, tvb, &s_olb, si, dissect_smb2_secblob);
2100
2101         offset = dissect_smb2_olb_tvb_max_offset(offset, &s_olb);
2102
2103         return offset;
2104 }
2105
2106 static int
2107 dissect_smb2_tree_connect_request(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, smb2_info_t *si _U_)
2108 {
2109         offset_length_buffer_t olb;
2110         const char *buf;
2111
2112         /* buffer code */
2113         offset = dissect_smb2_buffercode(tree, tvb, offset, NULL);
2114
2115         /* reserved */
2116         offset += 2;
2117
2118         /* tree  offset/length */
2119         offset = dissect_smb2_olb_length_offset(tvb, offset, &olb, OLB_O_UINT16_S_UINT16, hf_smb2_tree);
2120
2121         /* tree string */
2122         buf = dissect_smb2_olb_string(pinfo, tree, tvb, &olb, OLB_TYPE_UNICODE_STRING);
2123
2124         offset = dissect_smb2_olb_tvb_max_offset(offset, &olb);
2125
2126         /* treelen  +1 is overkill here if the string is unicode,
2127          * but who ever has more than a handful of TCON in a trace anyways
2128          */
2129         if(!pinfo->fd->flags.visited && si->saved && buf && olb.len){
2130                 si->saved->extra_info_type=SMB2_EI_TREENAME;
2131                 si->saved->extra_info=se_alloc(olb.len+1);
2132                 g_snprintf((char *)si->saved->extra_info,olb.len+1,"%s",buf);
2133         }
2134
2135         if (check_col(pinfo->cinfo, COL_INFO)){
2136                 col_append_fstr(pinfo->cinfo, COL_INFO, " Tree: %s", buf);
2137         }
2138
2139
2140         return offset;
2141 }
2142 static int
2143 dissect_smb2_tree_connect_response(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, smb2_info_t *si _U_)
2144 {
2145         guint16 share_type;
2146
2147         switch (si->status) {
2148         case 0x00000000: break;
2149         default: return dissect_smb2_error_response(tvb, pinfo, tree, offset, si);
2150         }
2151
2152         /* buffer code */
2153         offset = dissect_smb2_buffercode(tree, tvb, offset, NULL);
2154
2155         /* share type */
2156         share_type = tvb_get_letohs(tvb, offset);
2157         proto_tree_add_item(tree, hf_smb2_share_type, tvb, offset, 2, TRUE);
2158         offset += 2;
2159
2160         if(!pinfo->fd->flags.visited && si->saved && si->saved->extra_info_type==SMB2_EI_TREENAME && si->session) {
2161                 smb2_tid_info_t *tid, tid_key;
2162
2163                 tid_key.tid=si->tid;
2164                 tid=g_hash_table_lookup(si->session->tids, &tid_key);
2165                 if(tid){
2166                         g_hash_table_remove(si->session->tids, &tid_key);
2167                 }
2168                 tid=se_alloc(sizeof(smb2_tid_info_t));
2169                 tid->tid=si->tid;
2170                 tid->name=(char *)si->saved->extra_info;
2171                 tid->connect_frame=pinfo->fd->num;
2172                 tid->share_type=share_type;
2173
2174                 g_hash_table_insert(si->session->tids, tid, tid);
2175
2176                 si->saved->extra_info_type=SMB2_EI_NONE;
2177                 si->saved->extra_info=NULL;
2178         }
2179
2180         /* share flags */
2181         offset = dissect_smb2_share_flags(tree, tvb, offset);
2182
2183         /* share capabilities */
2184         offset = dissect_smb2_share_caps(tree, tvb, offset);
2185
2186         /* this is some sort of access mask */
2187         offset = dissect_smb_access_mask(tvb, tree, offset);
2188
2189         return offset;
2190 }
2191
2192 static int
2193 dissect_smb2_tree_disconnect_request(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int offset, smb2_info_t *si _U_)
2194 {
2195         /* buffer code */
2196         offset = dissect_smb2_buffercode(tree, tvb, offset, NULL);
2197
2198         /* reserved */
2199         offset += 2;
2200
2201         return offset;
2202 }
2203
2204 static int
2205 dissect_smb2_tree_disconnect_response(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int offset, smb2_info_t *si _U_)
2206 {
2207         switch (si->status) {
2208         case 0x00000000: break;
2209         default: return dissect_smb2_error_response(tvb, pinfo, tree, offset, si);
2210         }
2211
2212         /* buffer code */
2213         offset = dissect_smb2_buffercode(tree, tvb, offset, NULL);
2214
2215         /* reserved */
2216         offset += 2;
2217
2218         return offset;
2219 }
2220
2221 static int
2222 dissect_smb2_sessionlogoff_request(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int offset, smb2_info_t *si _U_)
2223 {
2224         /* buffer code */
2225         offset = dissect_smb2_buffercode(tree, tvb, offset, NULL);
2226
2227         /* reserved bytes */
2228         offset += 2;
2229
2230         return offset;
2231 }
2232
2233 static int
2234 dissect_smb2_sessionlogoff_response(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int offset, smb2_info_t *si _U_)
2235 {
2236         switch (si->status) {
2237         case 0x00000000: break;
2238         default: return dissect_smb2_error_response(tvb, pinfo, tree, offset, si);
2239         }
2240
2241         /* buffer code */
2242         offset = dissect_smb2_buffercode(tree, tvb, offset, NULL);
2243
2244         /* reserved bytes */
2245         offset += 2;
2246
2247         return offset;
2248 }
2249
2250 static int
2251 dissect_smb2_keepalive_request(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int offset, smb2_info_t *si _U_)
2252 {
2253         /* buffer code */
2254         offset = dissect_smb2_buffercode(tree, tvb, offset, NULL);
2255
2256         /* some unknown bytes */
2257         proto_tree_add_item(tree, hf_smb2_unknown, tvb, offset, 2, TRUE);
2258         offset += 2;
2259
2260         return offset;
2261 }
2262
2263 static int
2264 dissect_smb2_keepalive_response(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int offset, smb2_info_t *si _U_)
2265 {
2266         switch (si->status) {
2267         case 0x00000000: break;
2268         default: return dissect_smb2_error_response(tvb, pinfo, tree, offset, si);
2269         }
2270
2271         /* buffer code */
2272         offset = dissect_smb2_buffercode(tree, tvb, offset, NULL);
2273
2274         /* some unknown bytes */
2275         proto_tree_add_item(tree, hf_smb2_unknown, tvb, offset, 2, TRUE);
2276         offset += 2;
2277
2278         return offset;
2279 }
2280
2281 static int
2282 dissect_smb2_notify_request(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, smb2_info_t *si)
2283 {
2284         proto_tree *flags_tree = NULL;
2285         proto_item *flags_item = NULL;
2286
2287         /* buffer code */
2288         offset = dissect_smb2_buffercode(tree, tvb, offset, NULL);
2289
2290         /* notify flags */
2291         if (tree) {
2292                 flags_item = proto_tree_add_item(tree, hf_smb2_notify_flags, tvb, offset, 2, TRUE);
2293                 flags_tree = proto_item_add_subtree(flags_item, ett_smb2_notify_flags);
2294         }
2295         proto_tree_add_item(flags_tree, hf_smb2_notify_watch_tree, tvb, offset, 2, TRUE);
2296         offset += 2;
2297
2298         /* output buffer length */
2299         proto_tree_add_item(tree, hf_smb2_output_buffer_len, tvb, offset, 4, TRUE);
2300         offset += 4;
2301
2302         /* fid */
2303         offset = dissect_smb2_fid(tvb, pinfo, tree, offset, si, FID_MODE_USE);
2304
2305         /* completion filter */
2306         offset = dissect_nt_notify_completion_filter(tvb, tree, offset);
2307
2308         /* reserved */
2309         offset += 4;
2310
2311         return offset;
2312 }
2313
2314 static void
2315 dissect_smb2_notify_data_out(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, smb2_info_t *si _U_)
2316 {
2317         proto_tree_add_item(tree, hf_smb2_unknown, tvb, 0, tvb_length(tvb), TRUE);
2318 }
2319
2320 static int
2321 dissect_smb2_notify_response(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int offset, smb2_info_t *si)
2322 {
2323         offset_length_buffer_t olb;
2324
2325         switch (si->status) {
2326         case 0x00000000: break;
2327         default: return dissect_smb2_error_response(tvb, pinfo, tree, offset, si);
2328         }
2329
2330         /* buffer code */
2331         offset = dissect_smb2_buffercode(tree, tvb, offset, NULL);
2332
2333         /* out buffer offset/length */
2334         offset = dissect_smb2_olb_length_offset(tvb, offset, &olb, OLB_O_UINT16_S_UINT32, hf_smb2_notify_out_data);
2335
2336         /* out buffer */
2337         dissect_smb2_olb_buffer(pinfo, tree, tvb, &olb, si, dissect_smb2_notify_data_out);
2338         offset = dissect_smb2_olb_tvb_max_offset(offset, &olb);
2339
2340         return offset;
2341 }
2342
2343 #define SMB2_FIND_FLAG_RESTART_SCANS            0x01
2344 #define SMB2_FIND_FLAG_SINGLE_ENTRY             0x02
2345 #define SMB2_FIND_FLAG_INDEX_SPECIFIED          0x04
2346 #define SMB2_FIND_FLAG_REOPEN                   0x10
2347
2348 static int
2349 dissect_smb2_find_request(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, smb2_info_t *si)
2350 {
2351         offset_length_buffer_t olb;
2352         const char *buf;
2353         guint8 il;
2354         static const int *f_fields[] = {
2355                 &hf_smb2_find_flags_restart_scans,
2356                 &hf_smb2_find_flags_single_entry,
2357                 &hf_smb2_find_flags_index_specified,
2358                 &hf_smb2_find_flags_reopen,
2359                 NULL
2360         };
2361
2362         /* buffer code */
2363         offset = dissect_smb2_buffercode(tree, tvb, offset, NULL);
2364
2365         il=tvb_get_guint8(tvb, offset);
2366         if(si->saved){
2367                 si->saved->infolevel=il;
2368         }
2369
2370         /* infolevel */
2371         proto_tree_add_uint(tree, hf_smb2_find_info_level, tvb, offset, 1, il);
2372         offset += 1;
2373
2374         /* find flags */
2375         proto_tree_add_bitmask(tree, tvb, offset, hf_smb2_find_flags, ett_smb2_find_flags, f_fields, TRUE);
2376         offset += 1;
2377
2378         /* file index */
2379         proto_tree_add_item(tree, hf_smb2_file_index, tvb, offset, 4, TRUE);
2380         offset += 4;
2381
2382         /* fid */
2383         offset = dissect_smb2_fid(tvb, pinfo, tree, offset, si, FID_MODE_USE);
2384
2385         /* search pattern  offset/length */
2386         offset = dissect_smb2_olb_length_offset(tvb, offset, &olb, OLB_O_UINT16_S_UINT16, hf_smb2_find_pattern);
2387
2388         /* output buffer length */
2389         proto_tree_add_item(tree, hf_smb2_output_buffer_len, tvb, offset, 4, TRUE);
2390         offset += 4;
2391
2392         /* search pattern */
2393         buf = dissect_smb2_olb_string(pinfo, tree, tvb, &olb, OLB_TYPE_UNICODE_STRING);
2394
2395         offset = dissect_smb2_olb_tvb_max_offset(offset, &olb);
2396
2397         if(!pinfo->fd->flags.visited && si->saved && olb.len){
2398                 si->saved->extra_info_type=SMB2_EI_FINDPATTERN;
2399                 si->saved->extra_info=g_malloc(olb.len+1);
2400                 g_snprintf((char *)si->saved->extra_info,olb.len+1,"%s",buf);
2401         }
2402
2403         if (check_col(pinfo->cinfo, COL_INFO)){
2404                 col_append_fstr(pinfo->cinfo, COL_INFO, " %s Pattern: %s",
2405                         val_to_str(il, smb2_find_info_levels, "(Level:0x%02x)"),
2406                         buf);
2407         }
2408
2409         return offset;
2410 }
2411
2412 static void dissect_smb2_file_directory_info(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *parent_tree, smb2_info_t *si _U_)
2413 {
2414         int offset = 0;
2415         proto_item *item=NULL;
2416         proto_tree *tree=NULL;
2417         const char *name=NULL;
2418         guint16 bc;
2419
2420         while(tvb_length_remaining(tvb, offset) > 4){
2421                 int old_offset = offset;
2422                 int next_offset;
2423                 int file_name_len;
2424
2425                 if(parent_tree){
2426                         item = proto_tree_add_item(parent_tree, hf_smb2_file_directory_info, tvb, offset, -1, TRUE);
2427                         tree = proto_item_add_subtree(item, ett_smb2_file_directory_info);
2428                 }
2429
2430                 /* next offset */       
2431                 next_offset = tvb_get_letohl(tvb, offset);
2432                 proto_tree_add_item(tree, hf_smb2_next_offset, tvb, offset, 4, TRUE);
2433                 offset += 4;
2434
2435                 /* file index */
2436                 proto_tree_add_item(tree, hf_smb2_file_index, tvb, offset, 4, TRUE);
2437                 offset += 4;
2438
2439                 /* create time */
2440                 offset = dissect_nt_64bit_time(tvb, tree, offset, hf_smb2_create_timestamp);
2441
2442                 /* last access */
2443                 offset = dissect_nt_64bit_time(tvb, tree, offset, hf_smb2_last_access_timestamp);
2444
2445                 /* last write */
2446                 offset = dissect_nt_64bit_time(tvb, tree, offset, hf_smb2_last_write_timestamp);
2447
2448                 /* last change */
2449                 offset = dissect_nt_64bit_time(tvb, tree, offset, hf_smb2_last_change_timestamp);
2450
2451                 /* end of file */
2452                 proto_tree_add_item(tree, hf_smb2_end_of_file, tvb, offset, 8, TRUE);
2453                 offset += 8;
2454
2455                 /* allocation size */
2456                 proto_tree_add_item(tree, hf_smb2_allocation_size, tvb, offset, 8, TRUE);
2457                 offset += 8;
2458
2459                 /* File Attributes */
2460                 offset = dissect_file_attributes(tvb, tree, offset, 4);
2461
2462                 /* file name length */
2463                 file_name_len=tvb_get_letohl(tvb, offset);
2464                 proto_tree_add_item(tree, hf_smb2_filename_len, tvb, offset, 4, TRUE);
2465                 offset += 4;
2466
2467                 /* file name */
2468                 if(file_name_len){
2469                         bc=file_name_len;
2470                         name = get_unicode_or_ascii_string(tvb, &offset,
2471                                 TRUE, &file_name_len, TRUE, TRUE, &bc);
2472                         if(name){
2473                                 proto_tree_add_string(tree, hf_smb2_filename, tvb,
2474                                         offset, file_name_len, name);
2475                                 proto_item_append_text(item, ": %s", name);
2476
2477                         }
2478                 }
2479
2480                 proto_item_set_len(item, offset-old_offset);
2481
2482                 if (next_offset == 0){
2483                         return;
2484                 }
2485
2486                 offset = old_offset+next_offset;
2487                 if (offset < old_offset) {
2488                         proto_tree_add_text(tree, tvb, offset, tvb_length_remaining(tvb, offset),
2489                                     "Invalid offset/length. Malformed packet");
2490                         return;
2491                 }
2492         }
2493         return;
2494 }
2495
2496 static void dissect_smb2_full_directory_info(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *parent_tree, smb2_info_t *si _U_)
2497 {
2498         int offset = 0;
2499         proto_item *item=NULL;
2500         proto_tree *tree=NULL;
2501         const char *name=NULL;
2502         guint16 bc;
2503
2504         while(tvb_length_remaining(tvb, offset) > 4){
2505                 int old_offset = offset;
2506                 int next_offset;
2507                 int file_name_len;
2508
2509                 if(parent_tree){
2510                         item = proto_tree_add_item(parent_tree, hf_smb2_full_directory_info, tvb, offset, -1, TRUE);
2511                         tree = proto_item_add_subtree(item, ett_smb2_full_directory_info);
2512                 }
2513
2514                 /* next offset */       
2515                 next_offset = tvb_get_letohl(tvb, offset);
2516                 proto_tree_add_item(tree, hf_smb2_next_offset, tvb, offset, 4, TRUE);
2517                 offset += 4;
2518
2519                 /* file index */
2520                 proto_tree_add_item(tree, hf_smb2_file_index, tvb, offset, 4, TRUE);
2521                 offset += 4;
2522
2523                 /* create time */
2524                 offset = dissect_nt_64bit_time(tvb, tree, offset, hf_smb2_create_timestamp);
2525
2526                 /* last access */
2527                 offset = dissect_nt_64bit_time(tvb, tree, offset, hf_smb2_last_access_timestamp);
2528
2529                 /* last write */
2530                 offset = dissect_nt_64bit_time(tvb, tree, offset, hf_smb2_last_write_timestamp);
2531
2532                 /* last change */
2533                 offset = dissect_nt_64bit_time(tvb, tree, offset, hf_smb2_last_change_timestamp);
2534
2535                 /* end of file */
2536                 proto_tree_add_item(tree, hf_smb2_end_of_file, tvb, offset, 8, TRUE);
2537                 offset += 8;
2538
2539                 /* allocation size */
2540                 proto_tree_add_item(tree, hf_smb2_allocation_size, tvb, offset, 8, TRUE);
2541                 offset += 8;
2542
2543                 /* File Attributes */
2544                 offset = dissect_file_attributes(tvb, tree, offset, 4);
2545
2546                 /* file name length */
2547                 file_name_len=tvb_get_letohl(tvb, offset);
2548                 proto_tree_add_item(tree, hf_smb2_filename_len, tvb, offset, 4, TRUE);
2549                 offset += 4;
2550
2551                 /* ea size */
2552                 proto_tree_add_item(tree, hf_smb2_ea_size, tvb, offset, 4, TRUE);
2553                 offset += 4;
2554
2555                 /* file name */
2556                 if(file_name_len){
2557                         bc=file_name_len;
2558                         name = get_unicode_or_ascii_string(tvb, &offset,
2559                                 TRUE, &file_name_len, TRUE, TRUE, &bc);
2560                         if(name){
2561                                 proto_tree_add_string(tree, hf_smb2_filename, tvb,
2562                                         offset, file_name_len, name);
2563                                 proto_item_append_text(item, ": %s", name);
2564
2565                         }
2566                 }
2567
2568                 proto_item_set_len(item, offset-old_offset);
2569
2570                 if (next_offset == 0){
2571                         return;
2572                 }
2573
2574                 offset = old_offset+next_offset;
2575                 if (offset < old_offset) {
2576                         proto_tree_add_text(tree, tvb, offset, tvb_length_remaining(tvb, offset),
2577                                     "Invalid offset/length. Malformed packet");
2578                         return;
2579                 }
2580         }
2581         return;
2582 }
2583
2584 static void dissect_smb2_both_directory_info(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *parent_tree, smb2_info_t *si _U_)
2585 {
2586         int offset = 0;
2587         proto_item *item=NULL;
2588         proto_tree *tree=NULL;
2589         const char *name=NULL;
2590         guint16 bc;
2591
2592         while(tvb_length_remaining(tvb, offset) > 4){
2593                 int old_offset = offset;
2594                 int next_offset;
2595                 int file_name_len;
2596                 int ea_size;
2597                 int short_name_len;
2598
2599                 if(parent_tree){
2600                         item = proto_tree_add_item(parent_tree, hf_smb2_both_directory_info, tvb, offset, -1, TRUE);
2601                         tree = proto_item_add_subtree(item, ett_smb2_both_directory_info);
2602                 }
2603
2604                 /* next offset */       
2605                 next_offset = tvb_get_letohl(tvb, offset);
2606                 proto_tree_add_item(tree, hf_smb2_next_offset, tvb, offset, 4, TRUE);
2607                 offset += 4;
2608
2609                 /* file index */
2610                 proto_tree_add_item(tree, hf_smb2_file_index, tvb, offset, 4, TRUE);
2611                 offset += 4;
2612
2613                 /* create time */
2614                 offset = dissect_nt_64bit_time(tvb, tree, offset, hf_smb2_create_timestamp);
2615
2616                 /* last access */
2617                 offset = dissect_nt_64bit_time(tvb, tree, offset, hf_smb2_last_access_timestamp);
2618
2619                 /* last write */
2620                 offset = dissect_nt_64bit_time(tvb, tree, offset, hf_smb2_last_write_timestamp);
2621
2622                 /* last change */
2623                 offset = dissect_nt_64bit_time(tvb, tree, offset, hf_smb2_last_change_timestamp);
2624
2625                 /* end of file */
2626                 proto_tree_add_item(tree, hf_smb2_end_of_file, tvb, offset, 8, TRUE);
2627                 offset += 8;
2628
2629                 /* allocation size */
2630                 proto_tree_add_item(tree, hf_smb2_allocation_size, tvb, offset, 8, TRUE);
2631                 offset += 8;
2632
2633                 /* File Attributes */
2634                 offset = dissect_file_attributes(tvb, tree, offset, 4);
2635
2636                 /* file name length */
2637                 file_name_len=tvb_get_letohl(tvb, offset);
2638                 proto_tree_add_item(tree, hf_smb2_filename_len, tvb, offset, 4, TRUE);
2639                 offset += 4;
2640
2641                 /* ea size */
2642                 ea_size=tvb_get_letohl(tvb, offset);
2643                 proto_tree_add_item(tree, hf_smb2_ea_size, tvb, offset, 4, TRUE);
2644                 offset += 4;
2645
2646                 /* short name length */
2647                 short_name_len=tvb_get_guint8(tvb, offset);
2648                 proto_tree_add_item(tree, hf_smb2_short_name_len, tvb, offset, 1, TRUE);
2649                 offset += 1;
2650
2651                 /* reserved */
2652                 offset += 1;
2653
2654                 /* short name */
2655                 if(short_name_len){
2656                         bc=short_name_len;
2657                         name = get_unicode_or_ascii_string(tvb, &offset,
2658                                 TRUE, &short_name_len, TRUE, TRUE, &bc);
2659                         if(name){
2660                                 proto_tree_add_string(tree, hf_smb2_short_name, tvb,
2661                                         offset, short_name_len, name);
2662                         }
2663                 }
2664                 offset += 24;
2665
2666                 /* file name */
2667                 if(file_name_len){
2668                         bc=file_name_len;
2669                         name = get_unicode_or_ascii_string(tvb, &offset,
2670                                 TRUE, &file_name_len, TRUE, TRUE, &bc);
2671                         if(name){
2672                                 proto_tree_add_string(tree, hf_smb2_filename, tvb,
2673                                         offset, file_name_len, name);
2674                                 proto_item_append_text(item, ": %s", name);
2675
2676                         }
2677                 }
2678
2679                 proto_item_set_len(item, offset-old_offset);
2680
2681                 if (next_offset == 0){
2682                         return;
2683                 }
2684
2685                 offset = old_offset+next_offset;
2686                 if (offset < old_offset) {
2687                         proto_tree_add_text(tree, tvb, offset, tvb_length_remaining(tvb, offset),
2688                                     "Invalid offset/length. Malformed packet");
2689                         return;
2690                 }
2691         }
2692         return;
2693 }
2694
2695 static void dissect_smb2_file_name_info(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *parent_tree, smb2_info_t *si _U_)
2696 {
2697         int offset = 0;
2698         proto_item *item=NULL;
2699         proto_tree *tree=NULL;
2700         const char *name=NULL;
2701         guint16 bc;
2702
2703         while(tvb_length_remaining(tvb, offset) > 4){
2704                 int old_offset = offset;
2705                 int next_offset;
2706                 int file_name_len;
2707
2708                 if(parent_tree){
2709                         item = proto_tree_add_item(parent_tree, hf_smb2_both_directory_info, tvb, offset, -1, TRUE);
2710                         tree = proto_item_add_subtree(item, ett_smb2_both_directory_info);
2711                 }
2712
2713                 /* next offset */       
2714                 next_offset = tvb_get_letohl(tvb, offset);
2715                 proto_tree_add_item(tree, hf_smb2_next_offset, tvb, offset, 4, TRUE);
2716                 offset += 4;
2717
2718                 /* file index */
2719                 proto_tree_add_item(tree, hf_smb2_file_index, tvb, offset, 4, TRUE);
2720                 offset += 4;
2721
2722                 /* file name length */
2723                 file_name_len=tvb_get_letohl(tvb, offset);
2724                 proto_tree_add_item(tree, hf_smb2_filename_len, tvb, offset, 4, TRUE);
2725                 offset += 4;
2726
2727                 /* file name */
2728                 if(file_name_len){
2729                         bc=file_name_len;
2730                         name = get_unicode_or_ascii_string(tvb, &offset,
2731                                 TRUE, &file_name_len, TRUE, TRUE, &bc);
2732                         if(name){
2733                                 proto_tree_add_string(tree, hf_smb2_filename, tvb,
2734                                         offset, file_name_len, name);
2735                                 proto_item_append_text(item, ": %s", name);
2736
2737                         }
2738                 }
2739
2740                 proto_item_set_len(item, offset-old_offset);
2741
2742                 if (next_offset == 0){
2743                         return;
2744                 }
2745
2746                 offset = old_offset+next_offset;
2747                 if (offset < old_offset) {
2748                         proto_tree_add_text(tree, tvb, offset, tvb_length_remaining(tvb, offset),
2749                                     "Invalid offset/length. Malformed packet");
2750                         return;
2751                 }
2752         }
2753         return;
2754 }
2755
2756 static void dissect_smb2_id_both_directory_info(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *parent_tree, smb2_info_t *si _U_)
2757 {
2758         int offset = 0;
2759         proto_item *item=NULL;
2760         proto_tree *tree=NULL;
2761         const char *name=NULL;
2762         guint16 bc;
2763
2764         while(tvb_length_remaining(tvb, offset) > 4){
2765                 int old_offset = offset;
2766                 int next_offset;
2767                 int file_name_len;
2768                 int ea_size;
2769                 int short_name_len;
2770
2771                 if(parent_tree){
2772                         item = proto_tree_add_item(parent_tree, hf_smb2_id_both_directory_info, tvb, offset, -1, TRUE);
2773                         tree = proto_item_add_subtree(item, ett_smb2_id_both_directory_info);
2774                 }
2775
2776                 /* next offset */       
2777                 next_offset = tvb_get_letohl(tvb, offset);
2778                 proto_tree_add_item(tree, hf_smb2_next_offset, tvb, offset, 4, TRUE);
2779                 offset += 4;
2780
2781                 /* file index */
2782                 proto_tree_add_item(tree, hf_smb2_file_index, tvb, offset, 4, TRUE);
2783                 offset += 4;
2784
2785                 /* create time */
2786                 offset = dissect_nt_64bit_time(tvb, tree, offset, hf_smb2_create_timestamp);
2787
2788                 /* last access */
2789                 offset = dissect_nt_64bit_time(tvb, tree, offset, hf_smb2_last_access_timestamp);
2790
2791                 /* last write */
2792                 offset = dissect_nt_64bit_time(tvb, tree, offset, hf_smb2_last_write_timestamp);
2793
2794                 /* last change */
2795                 offset = dissect_nt_64bit_time(tvb, tree, offset, hf_smb2_last_change_timestamp);
2796
2797                 /* end of file */
2798                 proto_tree_add_item(tree, hf_smb2_end_of_file, tvb, offset, 8, TRUE);
2799                 offset += 8;
2800
2801                 /* allocation size */
2802                 proto_tree_add_item(tree, hf_smb2_allocation_size, tvb, offset, 8, TRUE);
2803                 offset += 8;
2804
2805                 /* File Attributes */
2806                 offset = dissect_file_attributes(tvb, tree, offset, 4);
2807
2808                 /* file name length */
2809                 file_name_len=tvb_get_letohl(tvb, offset);
2810                 proto_tree_add_item(tree, hf_smb2_filename_len, tvb, offset, 4, TRUE);
2811                 offset += 4;
2812
2813                 /* ea size */
2814                 ea_size=tvb_get_letohl(tvb, offset);
2815                 proto_tree_add_item(tree, hf_smb2_ea_size, tvb, offset, 4, TRUE);
2816                 offset += 4;
2817
2818                 /* short name length */
2819                 short_name_len=tvb_get_guint8(tvb, offset);
2820                 proto_tree_add_item(tree, hf_smb2_short_name_len, tvb, offset, 1, TRUE);
2821                 offset += 1;
2822
2823                 /* reserved */
2824                 offset += 1;
2825
2826                 /* short name */
2827                 if(short_name_len){
2828                         bc=short_name_len;
2829                         name = get_unicode_or_ascii_string(tvb, &offset,
2830                                 TRUE, &short_name_len, TRUE, TRUE, &bc);
2831                         if(name){
2832                                 proto_tree_add_string(tree, hf_smb2_short_name, tvb,
2833                                         offset, short_name_len, name);
2834                         }
2835                 }
2836                 offset += 24;
2837
2838                 /* reserved */
2839                 offset += 2;
2840
2841                 /* file id */
2842                 proto_tree_add_item(tree, hf_smb2_file_id, tvb, offset, 8, TRUE);
2843                 offset += 8;
2844
2845                 /* file name */
2846                 if(file_name_len){
2847                         bc=file_name_len;
2848                         name = get_unicode_or_ascii_string(tvb, &offset,
2849                                 TRUE, &file_name_len, TRUE, TRUE, &bc);
2850                         if(name){
2851                                 proto_tree_add_string(tree, hf_smb2_filename, tvb,
2852                                         offset, file_name_len, name);
2853                                 proto_item_append_text(item, ": %s", name);
2854
2855                         }
2856                 }
2857
2858                 proto_item_set_len(item, offset-old_offset);
2859
2860                 if (next_offset == 0){
2861                         return;
2862                 }
2863
2864                 offset = old_offset+next_offset;
2865                 if (offset < old_offset) {
2866                         proto_tree_add_text(tree, tvb, offset, tvb_length_remaining(tvb, offset),
2867                                     "Invalid offset/length. Malformed packet");
2868                         return;
2869                 }
2870         }
2871         return;
2872 }
2873
2874
2875 typedef struct _smb2_find_dissector_t {
2876         guint32 level;
2877         void (*dissector)(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, smb2_info_t *si);
2878 } smb2_find_dissector_t;
2879
2880 smb2_find_dissector_t smb2_find_dissectors[] = {
2881         {SMB2_FIND_DIRECTORY_INFO,      dissect_smb2_file_directory_info},
2882         {SMB2_FIND_FULL_DIRECTORY_INFO, dissect_smb2_full_directory_info},
2883         {SMB2_FIND_BOTH_DIRECTORY_INFO, dissect_smb2_both_directory_info},
2884         {SMB2_FIND_NAME_INFO,           dissect_smb2_file_name_info},
2885         {SMB2_FIND_ID_BOTH_DIRECTORY_INFO,dissect_smb2_id_both_directory_info},
2886         {0, NULL}
2887 };
2888
2889 static void
2890 dissect_smb2_find_data(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, smb2_info_t *si)
2891 {
2892         smb2_find_dissector_t *dis = smb2_find_dissectors;
2893
2894         while(dis->dissector){
2895                 if(si && si->saved && si->saved){
2896                         if(dis->level ==si->saved->infolevel){
2897                                 dis->dissector(tvb, pinfo, tree, si);
2898                                 return;
2899                         }
2900                 }
2901                 dis++;
2902         }
2903
2904         proto_tree_add_item(tree, hf_smb2_unknown, tvb, 0, tvb_length(tvb), FALSE);
2905         return;
2906 }
2907
2908 static int
2909 dissect_smb2_find_response(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int offset, smb2_info_t *si _U_)
2910 {
2911         offset_length_buffer_t olb;
2912         proto_item *item=NULL;
2913
2914         if(si->saved){
2915                 /* infolevel */
2916                 item=proto_tree_add_uint(tree, hf_smb2_find_info_level, tvb, offset, 0, si->saved->infolevel);
2917                 PROTO_ITEM_SET_GENERATED(item);
2918         }
2919
2920         if(!pinfo->fd->flags.visited && si->saved && si->saved->extra_info_type==SMB2_EI_FINDPATTERN) {
2921                 if (check_col(pinfo->cinfo, COL_INFO)){
2922                         col_append_fstr(pinfo->cinfo, COL_INFO, " %s Pattern: %s",
2923                                 val_to_str(si->saved->infolevel, smb2_find_info_levels, "(Level:0x%02x)"),
2924                                 (const char *)si->saved->extra_info);
2925                 }
2926
2927                 g_free(si->saved->extra_info);
2928                 si->saved->extra_info_type=SMB2_EI_NONE;
2929                 si->saved->extra_info=NULL;
2930         }
2931         
2932         switch (si->status) {
2933         case 0x00000000: break;
2934         default: return dissect_smb2_error_response(tvb, pinfo, tree, offset, si);
2935         }
2936
2937         /* buffer code */
2938         offset = dissect_smb2_buffercode(tree, tvb, offset, NULL);
2939
2940         /* findinfo offset */
2941         offset = dissect_smb2_olb_length_offset(tvb, offset, &olb, OLB_O_UINT16_S_UINT32, hf_smb2_find_info_blob);
2942
2943         /* the buffer */
2944         dissect_smb2_olb_buffer(pinfo, tree, tvb, &olb, si, dissect_smb2_find_data);
2945
2946         offset = dissect_smb2_olb_tvb_max_offset(offset, &olb);
2947
2948         return offset;
2949 }
2950
2951 static int
2952 dissect_smb2_negotiate_protocol_request(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int offset, smb2_info_t *si _U_)
2953 {
2954         guint16 dc;
2955
2956         /* buffer code */
2957         offset = dissect_smb2_buffercode(tree, tvb, offset, NULL);
2958
2959         /* dialect count */
2960         dc = tvb_get_letohs(tvb, offset);
2961         proto_tree_add_item(tree, hf_smb2_dialect_count, tvb, offset, 2, TRUE);
2962         offset += 2;
2963
2964         /* security mode, skip second byte */
2965         offset = dissect_smb2_secmode(tree, tvb, offset);
2966         offset++;
2967
2968
2969         /* reserved */
2970         offset += 2;
2971
2972         /* capabilities */
2973         offset = dissect_smb2_capabilities(tree, tvb, offset);
2974
2975         /* client guid */
2976         proto_tree_add_item(tree, hf_smb2_client_guid, tvb, offset, 16, TRUE);
2977         offset += 16;
2978
2979         /* client boot time */
2980         dissect_nt_64bit_time(tvb, tree, offset, hf_smb2_boot_time);
2981         offset += 8;
2982
2983         for(;dc>0;dc--){
2984                 proto_tree_add_item(tree, hf_smb2_dialect, tvb, offset, 2, TRUE);
2985                 offset += 2;
2986         }
2987
2988         return offset;
2989 }
2990
2991 static int
2992 dissect_smb2_negotiate_protocol_response(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, smb2_info_t *si _U_)
2993 {
2994         offset_length_buffer_t s_olb;
2995
2996         switch (si->status) {
2997         case 0x00000000: break;
2998         default: return dissect_smb2_error_response(tvb, pinfo, tree, offset, si);
2999         }
3000
3001         /* buffer code */
3002         offset = dissect_smb2_buffercode(tree, tvb, offset, NULL);
3003
3004         /* security mode, skip second byte */
3005         offset = dissect_smb2_secmode(tree, tvb, offset);
3006         offset++;
3007
3008         /* dialect picked */
3009         proto_tree_add_item(tree, hf_smb2_dialect, tvb, offset, 2, TRUE);
3010         offset += 2;
3011
3012         /* reserved */
3013         offset += 2;
3014
3015         /* server GUID */
3016         proto_tree_add_item(tree, hf_smb2_server_guid, tvb, offset, 16, TRUE);
3017         offset += 16;
3018
3019         /* capabilities */
3020         offset = dissect_smb2_capabilities(tree, tvb, offset);
3021
3022         /* max trans size */
3023         proto_tree_add_item(tree, hf_smb2_max_trans_size, tvb, offset, 4, TRUE);
3024         offset += 4;
3025
3026         /* max read size */
3027         proto_tree_add_item(tree, hf_smb2_max_read_size, tvb, offset, 4, TRUE);
3028         offset += 4;
3029
3030         /* max write size */
3031         proto_tree_add_item(tree, hf_smb2_max_write_size, tvb, offset, 4, TRUE);
3032         offset += 4;
3033
3034         /* current time */
3035         dissect_nt_64bit_time(tvb, tree, offset, hf_smb2_current_time);
3036         offset += 8;
3037
3038         /* boot time */
3039         dissect_nt_64bit_time(tvb, tree, offset, hf_smb2_boot_time);
3040         offset += 8;
3041
3042         /* security blob offset/length */
3043         offset = dissect_smb2_olb_length_offset(tvb, offset, &s_olb, OLB_O_UINT16_S_UINT16, hf_smb2_security_blob);
3044
3045         /* the security blob itself */
3046         dissect_smb2_olb_buffer(pinfo, tree, tvb, &s_olb, si, dissect_smb2_secblob);
3047
3048         /* reserved */
3049         offset += 4;
3050
3051         offset = dissect_smb2_olb_tvb_max_offset(offset, &s_olb);
3052
3053         return offset;
3054 }
3055
3056 static void
3057 dissect_smb2_getinfo_parameters(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int offset, smb2_info_t *si)
3058 {
3059         switch(si->saved->class){
3060         case SMB2_CLASS_FILE_INFO:
3061                 switch(si->saved->infolevel){
3062                 default:
3063                         /* we dont handle this infolevel yet */
3064                         proto_tree_add_item(tree, hf_smb2_unknown, tvb, offset, 16, TRUE);
3065                         offset += tvb_length_remaining(tvb, offset);
3066                 }
3067                 break;
3068         case SMB2_CLASS_FS_INFO:
3069                 switch(si->saved->infolevel){
3070                 default:
3071                         /* we dont handle this infolevel yet */
3072                         proto_tree_add_item(tree, hf_smb2_unknown, tvb, offset, 16, TRUE);
3073                         offset += tvb_length_remaining(tvb, offset);
3074                 }
3075                 break;
3076         case SMB2_CLASS_SEC_INFO:
3077                 switch(si->saved->infolevel){
3078                 case SMB2_SEC_INFO_00:
3079                         dissect_security_information_mask(tvb, tree, offset+8);
3080                         break;
3081                 default:
3082                         /* we dont handle this infolevel yet */
3083                         proto_tree_add_item(tree, hf_smb2_unknown, tvb, offset, 16, TRUE);
3084                         offset += tvb_length_remaining(tvb, offset);
3085                 }
3086                 break;
3087         default:
3088                 /* we dont handle this class yet */
3089                 proto_tree_add_item(tree, hf_smb2_unknown, tvb, offset, 16, TRUE);
3090         }
3091 }
3092
3093
3094 static int
3095 dissect_smb2_class_infolevel(packet_info *pinfo, tvbuff_t *tvb, int offset, proto_tree *tree, smb2_info_t *si)
3096 {
3097         char cl, il;
3098         proto_item *item;
3099         int hfindex;
3100         static const value_string dummy_value_string[] = {
3101                 { 0, NULL }
3102         };
3103         const value_string *vs;
3104
3105         if(si->flags & SMB2_FLAGS_RESPONSE){
3106                 if(!si->saved){
3107                         return offset;
3108                 }
3109                 cl=si->saved->class;
3110                 il=si->saved->infolevel;
3111         } else {
3112                 cl=tvb_get_guint8(tvb, offset);
3113                 il=tvb_get_guint8(tvb, offset+1);
3114                 if(si->saved){
3115                         si->saved->class=cl;
3116                         si->saved->infolevel=il;
3117                 }
3118         }
3119
3120
3121         switch(cl){
3122         case SMB2_CLASS_FILE_INFO:
3123                 hfindex=hf_smb2_infolevel_file_info;
3124                 vs=smb2_file_info_levels;
3125                 break;
3126         case SMB2_CLASS_FS_INFO:
3127                 hfindex=hf_smb2_infolevel_fs_info;
3128                 vs=smb2_fs_info_levels;
3129                 break;
3130         case SMB2_CLASS_SEC_INFO:
3131                 hfindex=hf_smb2_infolevel_sec_info;
3132                 vs=smb2_sec_info_levels;
3133                 break;
3134         default:
3135                 hfindex=hf_smb2_infolevel;
3136                 vs=dummy_value_string;
3137         }
3138
3139
3140         /* class */
3141         item=proto_tree_add_uint(tree, hf_smb2_class, tvb, offset, 1, cl);
3142         if(si->flags & SMB2_FLAGS_RESPONSE){
3143                 PROTO_ITEM_SET_GENERATED(item);
3144         }
3145         /* infolevel */
3146         item=proto_tree_add_uint(tree, hfindex, tvb, offset+1, 1, il);
3147         if(si->flags & SMB2_FLAGS_RESPONSE){
3148                 PROTO_ITEM_SET_GENERATED(item);
3149         }
3150         offset += 2;
3151
3152         if(!(si->flags & SMB2_FLAGS_RESPONSE)){
3153                 /* Only update COL_INFO for requests. It clutters the
3154                  * display ab bit too much if we do it for replies
3155                  * as well.
3156                  */
3157                 if (check_col(pinfo->cinfo, COL_INFO)){
3158                         col_append_fstr(pinfo->cinfo, COL_INFO, " %s/%s",
3159                                 val_to_str(cl, smb2_class_vals, "(Class:0x%02x)"),
3160                                 val_to_str(il, vs, "(Level:0x%02x)"));
3161                 }
3162         }
3163
3164         return offset;
3165 }
3166
3167 static int
3168 dissect_smb2_getinfo_request(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, smb2_info_t *si)
3169 {
3170         /* buffer code */
3171         offset = dissect_smb2_buffercode(tree, tvb, offset, NULL);
3172
3173         /* class and info level */
3174         offset = dissect_smb2_class_infolevel(pinfo, tvb, offset, tree, si);
3175
3176         /* max response size */
3177         proto_tree_add_item(tree, hf_smb2_max_response_size, tvb, offset, 4, TRUE);
3178         offset += 4;
3179
3180         /* parameters */
3181         if(si->saved){
3182                 dissect_smb2_getinfo_parameters(tvb, pinfo, tree, offset, si);
3183         } else {
3184                 /* some unknown bytes */
3185                 proto_tree_add_item(tree, hf_smb2_unknown, tvb, offset, 16, TRUE);
3186         }
3187         offset += 16;
3188
3189         /* fid */
3190         offset = dissect_smb2_fid(tvb, pinfo, tree, offset, si, FID_MODE_USE);
3191
3192         return offset;
3193 }
3194
3195 static void
3196 dissect_smb2_infolevel(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int offset, smb2_info_t *si, guint8 class, guint8 infolevel)
3197 {
3198         int old_offset = offset;
3199
3200         switch(class){
3201         case SMB2_CLASS_FILE_INFO:
3202                 switch(infolevel){
3203                 case SMB2_FILE_BASIC_INFO:
3204                         dissect_smb2_file_basic_info(tvb, pinfo, tree, offset, si);
3205                         break;
3206                 case SMB2_FILE_STANDARD_INFO:
3207                         dissect_smb2_file_standard_info(tvb, pinfo, tree, offset, si);
3208                         break;
3209                 case SMB2_FILE_INTERNAL_INFO:
3210                         dissect_smb2_file_internal_info(tvb, pinfo, tree, offset, si);
3211                         break;
3212                 case SMB2_FILE_EA_INFO:
3213                         dissect_smb2_file_ea_info(tvb, pinfo, tree, offset, si);
3214                         break;
3215                 case SMB2_FILE_ACCESS_INFO:
3216                         dissect_smb2_file_access_info(tvb, pinfo, tree, offset, si);
3217                         break;
3218                 case SMB2_FILE_RENAME_INFO:
3219                         dissect_smb2_file_rename_info(tvb, pinfo, tree, offset, si);
3220                         break;
3221                 case SMB2_FILE_DISPOSITION_INFO:
3222                         dissect_smb2_file_disposition_info(tvb, pinfo, tree, offset, si);
3223                         break;
3224                 case SMB2_FILE_POSITION_INFO:
3225                         dissect_smb2_file_position_info(tvb, pinfo, tree, offset, si);
3226                         break;
3227                 case SMB2_FILE_INFO_0f:
3228                         dissect_smb2_file_info_0f(tvb, pinfo, tree, offset, si);
3229                         break;
3230                 case SMB2_FILE_MODE_INFO:
3231                         dissect_smb2_file_mode_info(tvb, pinfo, tree, offset, si);
3232                         break;
3233                 case SMB2_FILE_ALIGNMENT_INFO:
3234                         dissect_smb2_file_alignment_info(tvb, pinfo, tree, offset, si);
3235                         break;
3236                 case SMB2_FILE_ALL_INFO:
3237                         dissect_smb2_file_all_info(tvb, pinfo, tree, offset, si);
3238                         break;
3239                 case SMB2_FILE_ALLOCATION_INFO:
3240                         dissect_smb2_file_allocation_info(tvb, pinfo, tree, offset, si);
3241                         break;
3242                 case SMB2_FILE_ENDOFFILE_INFO:
3243                         dissect_smb2_file_endoffile_info(tvb, pinfo, tree, offset, si);
3244                         break;
3245                 case SMB2_FILE_ALTERNATE_NAME_INFO:
3246                         dissect_smb2_file_alternate_name_info(tvb, pinfo, tree, offset, si);
3247                         break;
3248                 case SMB2_FILE_STREAM_INFO:
3249                         dissect_smb2_file_stream_info(tvb, pinfo, tree, offset, si);
3250                         break;
3251                 case SMB2_FILE_PIPE_INFO:
3252                         dissect_smb2_file_pipe_info(tvb, pinfo, tree, offset, si);
3253                         break;
3254                 case SMB2_FILE_COMPRESSION_INFO:
3255                         dissect_smb2_file_compression_info(tvb, pinfo, tree, offset, si);
3256                         break;
3257                 case SMB2_FILE_NETWORK_OPEN_INFO:
3258                         dissect_smb2_file_network_open_info(tvb, pinfo, tree, offset, si);
3259                         break;
3260                 case SMB2_FILE_ATTRIBUTE_TAG_INFO:
3261                         dissect_smb2_file_attribute_tag_info(tvb, pinfo, tree, offset, si);
3262                         break;
3263                 default:
3264                         /* we dont handle this infolevel yet */
3265                         proto_tree_add_item(tree, hf_smb2_unknown, tvb, offset, tvb_length_remaining(tvb, offset), TRUE);
3266                         offset += tvb_length_remaining(tvb, offset);
3267                 }
3268                 break;
3269         case SMB2_CLASS_FS_INFO:
3270                 switch(infolevel){
3271                 case SMB2_FS_INFO_01:
3272                         dissect_smb2_fs_info_01(tvb, pinfo, tree, offset, si);
3273                         break;
3274                 case SMB2_FS_INFO_03:
3275                         dissect_smb2_fs_info_03(tvb, pinfo, tree, offset, si);
3276                         break;
3277                 case SMB2_FS_INFO_04:
3278                         dissect_smb2_fs_info_04(tvb, pinfo, tree, offset, si);
3279                         break;
3280                 case SMB2_FS_INFO_05:
3281                         dissect_smb2_fs_info_05(tvb, pinfo, tree, offset, si);
3282                         break;
3283                 case SMB2_FS_INFO_06:
3284                         dissect_smb2_fs_info_06(tvb, pinfo, tree, offset, si);
3285                         break;
3286                 case SMB2_FS_INFO_07:
3287                         dissect_smb2_fs_info_07(tvb, pinfo, tree, offset, si);
3288                         break;
3289                 case SMB2_FS_OBJECTID_INFO:
3290                         dissect_smb2_FS_OBJECTID_INFO(tvb, pinfo, tree, offset, si);
3291                         break;
3292                 default:
3293                         /* we dont handle this infolevel yet */
3294                         proto_tree_add_item(tree, hf_smb2_unknown, tvb, offset, tvb_length_remaining(tvb, offset), TRUE);
3295                         offset += tvb_length_remaining(tvb, offset);
3296                 }
3297                 break;
3298         case SMB2_CLASS_SEC_INFO:
3299                 switch(infolevel){
3300                 case SMB2_SEC_INFO_00:
3301                         dissect_smb2_sec_info_00(tvb, pinfo, tree, offset, si);
3302                         break;
3303                 default:
3304                         /* we dont handle this infolevel yet */
3305                         proto_tree_add_item(tree, hf_smb2_unknown, tvb, offset, tvb_length_remaining(tvb, offset), TRUE);
3306                         offset += tvb_length_remaining(tvb, offset);
3307                 }
3308                 break;
3309         default:
3310                 /* we dont handle this class yet */
3311                 proto_tree_add_item(tree, hf_smb2_unknown, tvb, offset, tvb_length_remaining(tvb, offset), TRUE);
3312         }
3313
3314         /* if we get BUFFER_OVERFLOW there will be truncated data */
3315         if (si->status == 0x80000005) {
3316                 proto_item *item;
3317                 item=proto_tree_add_text(tree, tvb, old_offset, 0, "Truncated...");
3318                 PROTO_ITEM_SET_GENERATED(item);
3319         }
3320 }
3321
3322 static void
3323 dissect_smb2_getinfo_response_data(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, smb2_info_t *si)
3324 {
3325         /* data */
3326         if(si->saved){
3327                 dissect_smb2_infolevel(tvb, pinfo, tree, 0, si, si->saved->class, si->saved->infolevel);
3328         } else {
3329                 /* some unknown bytes */
3330                 proto_tree_add_item(tree, hf_smb2_unknown, tvb, 0, tvb_length(tvb), FALSE);
3331         }
3332
3333         return;
3334 }
3335
3336
3337 static int
3338 dissect_smb2_getinfo_response(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, smb2_info_t *si)
3339 {
3340         offset_length_buffer_t olb;
3341
3342         /* class/infolevel */
3343         dissect_smb2_class_infolevel(pinfo, tvb, offset, tree, si);
3344
3345         switch (si->status) {
3346         case 0x00000000: break;
3347         /* if we get BUFFER_OVERFLOW there will be truncated data */
3348         case 0x80000005: break;
3349         /* if we get BUFFER_TOO_SMALL there will not be any data there, only
3350          * a guin32 specifying how big the buffer needs to be
3351          */
3352         case 0xc0000023:
3353                 offset = dissect_smb2_buffercode(tree, tvb, offset, NULL);
3354                 offset = dissect_smb2_olb_length_offset(tvb, offset, &olb, OLB_O_UINT16_S_UINT32, -1);
3355                 proto_tree_add_item(tree, hf_smb2_required_buffer_size, tvb, offset, 4, TRUE);
3356                 offset += 4;
3357
3358                 return offset;
3359         default: return dissect_smb2_error_response(tvb, pinfo, tree, offset, si);
3360         }
3361
3362
3363         /* buffer code */
3364         offset = dissect_smb2_buffercode(tree, tvb, offset, NULL);
3365          /* response buffer offset  and size */
3366         offset = dissect_smb2_olb_length_offset(tvb, offset, &olb, OLB_O_UINT16_S_UINT32, -1);
3367
3368         /* response data*/
3369         dissect_smb2_olb_buffer(pinfo, tree, tvb, &olb, si, dissect_smb2_getinfo_response_data);
3370
3371         return offset;
3372 }
3373
3374 static int
3375 dissect_smb2_close_request(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, smb2_info_t *si)
3376 {
3377         proto_tree *flags_tree = NULL;
3378         proto_item *flags_item = NULL;
3379
3380         /* buffer code */
3381         offset = dissect_smb2_buffercode(tree, tvb, offset, NULL);
3382
3383         /* close flags */
3384         if (tree) {
3385                 flags_item = proto_tree_add_item(tree, hf_smb2_close_flags, tvb, offset, 2, TRUE);
3386                 flags_tree = proto_item_add_subtree(flags_item, ett_smb2_close_flags);
3387         }
3388         proto_tree_add_item(flags_tree, hf_smb2_close_pq_attrib, tvb, offset, 2, TRUE);
3389         offset += 2;
3390
3391         /* padding */
3392         offset += 4;
3393
3394         /* fid */
3395         offset = dissect_smb2_fid(tvb, pinfo, tree, offset, si, FID_MODE_CLOSE);
3396
3397         return offset;
3398 }
3399
3400 static int
3401 dissect_smb2_close_response(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int offset, smb2_info_t *si _U_)
3402 {
3403         proto_tree *flags_tree = NULL;
3404         proto_item *flags_item = NULL;
3405
3406         switch (si->status) {
3407         case 0x00000000: break;
3408         default: return dissect_smb2_error_response(tvb, pinfo, tree, offset, si);
3409         }
3410
3411         /* buffer code */
3412         offset = dissect_smb2_buffercode(tree, tvb, offset, NULL);
3413
3414         /* close flags */
3415         if (tree) {
3416                 flags_item = proto_tree_add_item(tree, hf_smb2_close_flags, tvb, offset, 2, TRUE);
3417                 flags_tree = proto_item_add_subtree(flags_item, ett_smb2_close_flags);
3418         }
3419         offset += 2;
3420
3421         /* reserved */
3422         offset += 4;
3423
3424         /* create time */
3425         offset = dissect_nt_64bit_time(tvb, tree, offset, hf_smb2_create_timestamp);
3426
3427         /* last access */
3428         offset = dissect_nt_64bit_time(tvb, tree, offset, hf_smb2_last_access_timestamp);
3429
3430         /* last write */
3431         offset = dissect_nt_64bit_time(tvb, tree, offset, hf_smb2_last_write_timestamp);
3432
3433         /* last change */
3434         offset = dissect_nt_64bit_time(tvb, tree, offset, hf_smb2_last_change_timestamp);
3435
3436         /* allocation size */
3437         proto_tree_add_item(tree, hf_smb2_allocation_size, tvb, offset, 8, TRUE);
3438         offset += 8;
3439
3440         /* end of file */
3441         proto_tree_add_item(tree, hf_smb2_end_of_file, tvb, offset, 8, TRUE);
3442         offset += 8;
3443
3444         /* File Attributes */
3445         offset = dissect_file_attributes(tvb, tree, offset, 4);
3446
3447         return offset;
3448 }
3449
3450 static int
3451 dissect_smb2_flush_request(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, smb2_info_t *si)
3452 {
3453         /* buffer code */
3454         offset = dissect_smb2_buffercode(tree, tvb, offset, NULL);
3455
3456         /* some unknown bytes */
3457         proto_tree_add_item(tree, hf_smb2_unknown, tvb, offset, 6, TRUE);
3458         offset += 6;
3459
3460         /* fid */
3461         offset = dissect_smb2_fid(tvb, pinfo, tree, offset, si, FID_MODE_USE);
3462
3463         return offset;
3464 }
3465
3466 static int
3467 dissect_smb2_flush_response(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int offset, smb2_info_t *si _U_)
3468 {
3469         switch (si->status) {
3470         case 0x00000000: break;
3471         default: return dissect_smb2_error_response(tvb, pinfo, tree, offset, si);
3472         }
3473
3474         /* buffer code */
3475         offset = dissect_smb2_buffercode(tree, tvb, offset, NULL);
3476
3477         /* some unknown bytes */
3478         proto_tree_add_item(tree, hf_smb2_unknown, tvb, offset, 2, TRUE);
3479         offset += 2;
3480
3481         return offset;
3482 }
3483
3484
3485 static int
3486 dissect_smb2_lock_request(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, smb2_info_t *si)
3487 {
3488         guint16 lock_count;
3489
3490         /* buffer code */
3491         offset = dissect_smb2_buffercode(tree, tvb, offset, NULL);
3492
3493         /* lock count */
3494         lock_count = tvb_get_letohs(tvb, offset);
3495         proto_tree_add_item(tree, hf_smb2_lock_count, tvb, offset, 2, TRUE);
3496         offset += 2;
3497
3498         /* reserved */
3499         offset += 4;
3500
3501         /* fid */
3502         offset = dissect_smb2_fid(tvb, pinfo, tree, offset, si, FID_MODE_USE);
3503
3504         while (lock_count--) {
3505                 proto_item *lock_item=NULL;
3506                 proto_tree *lock_tree=NULL;
3507                 static const int *lf_fields[] = {       
3508                         &hf_smb2_lock_flags_shared,
3509                         &hf_smb2_lock_flags_exclusive,
3510                         &hf_smb2_lock_flags_unlock,
3511                         &hf_smb2_lock_flags_fail_immediately,
3512                         NULL
3513                 };
3514
3515                 if(tree){
3516                         lock_item = proto_tree_add_item(tree, hf_smb2_lock_info, tvb, offset, 24, TRUE);
3517                         lock_tree = proto_item_add_subtree(lock_item, ett_smb2_lock_info);
3518                 }
3519
3520                 /* offset */
3521                 proto_tree_add_item(tree, hf_smb2_file_offset, tvb, offset, 8, TRUE);
3522                 offset += 8;
3523
3524                 /* count */
3525                 proto_tree_add_item(lock_tree, hf_smb2_lock_length, tvb, offset, 8, TRUE);
3526                 offset += 8;
3527
3528                 /* flags */
3529                 proto_tree_add_bitmask(lock_tree, tvb, offset, hf_smb2_lock_flags, ett_smb2_lock_flags, lf_fields, TRUE);
3530                 offset += 4;
3531
3532                 /* reserved */
3533                 offset += 4;
3534         }
3535
3536         return offset;
3537 }
3538
3539 static int
3540 dissect_smb2_lock_response(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int offset, smb2_info_t *si _U_)
3541 {
3542         switch (si->status) {
3543         case 0x00000000: break;
3544         default: return dissect_smb2_error_response(tvb, pinfo, tree, offset, si);
3545         }
3546
3547         /* buffer code */
3548         offset = dissect_smb2_buffercode(tree, tvb, offset, NULL);
3549
3550         /* some unknown bytes */
3551         proto_tree_add_item(tree, hf_smb2_unknown, tvb, offset, 2, TRUE);
3552         offset += 2;
3553
3554         return offset;
3555 }
3556 static int
3557 dissect_smb2_cancel_request(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int offset, smb2_info_t *si _U_)
3558 {
3559         /* buffer code */
3560         offset = dissect_smb2_buffercode(tree, tvb, offset, NULL);
3561
3562         /* some unknown bytes */
3563         proto_tree_add_item(tree, hf_smb2_unknown, tvb, offset, 2, TRUE);
3564         offset += 2;
3565
3566         return offset;
3567 }
3568
3569
3570 static int
3571 dissect_file_data_dcerpc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree _U_, int offset, guint32 datalen, proto_tree *top_tree)
3572 {
3573         int tvblen;
3574         int result;
3575
3576         tvbuff_t *dcerpc_tvb;
3577         tvblen = tvb_length_remaining(tvb, offset);
3578         dcerpc_tvb = tvb_new_subset(tvb, offset, MIN((int)datalen, tvb_length_remaining(tvb, offset)), datalen);
3579
3580         /* dissect the full PDU */
3581         result = dissector_try_heuristic(smb2_heur_subdissector_list, dcerpc_tvb, pinfo, top_tree);
3582
3583
3584         offset += datalen;
3585
3586         return offset;
3587 }
3588
3589
3590 static int
3591 dissect_smb2_write_request(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, smb2_info_t *si)
3592 {
3593         guint32 length;
3594         guint64 off;
3595
3596         /* buffer code */
3597         offset = dissect_smb2_buffercode(tree, tvb, offset, NULL);
3598
3599         /* data offset */
3600         proto_tree_add_item(tree, hf_smb2_data_offset, tvb, offset, 2, TRUE);
3601         offset += 2;
3602
3603         /* length */
3604         length=tvb_get_letohl(tvb, offset);
3605         proto_tree_add_item(tree, hf_smb2_write_length, tvb, offset, 4, TRUE);
3606         offset += 4;
3607
3608         /* offset */
3609         off=tvb_get_letoh64(tvb, offset);
3610         proto_tree_add_item(tree, hf_smb2_file_offset, tvb, offset, 8, TRUE);
3611         offset += 8;
3612
3613         if (check_col(pinfo->cinfo, COL_INFO)){
3614                 col_append_fstr(pinfo->cinfo, COL_INFO, " Len:%d Off:%" G_GINT64_MODIFIER "u", length, off);
3615         }
3616
3617         /* fid */
3618         offset = dissect_smb2_fid(tvb, pinfo, tree, offset, si, FID_MODE_USE);
3619
3620         /* some unknown bytes */
3621         proto_tree_add_item(tree, hf_smb2_unknown, tvb, offset, 16, TRUE);
3622         offset += 16;
3623
3624
3625         /* data or dcerpc ?*/
3626         if(length && si->tree && si->tree->share_type == SMB2_SHARE_TYPE_IPC){
3627                 offset = dissect_file_data_dcerpc(tvb, pinfo, tree, offset, length, si->top_tree);
3628                 return offset;
3629         }
3630
3631         /* just ordinary data */
3632         proto_tree_add_item(tree, hf_smb2_write_data, tvb, offset, length, TRUE);
3633         offset += MIN(length,(guint32)tvb_length_remaining(tvb, offset));
3634
3635         return offset;
3636 }
3637
3638
3639 static int
3640 dissect_smb2_write_response(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int offset, smb2_info_t *si _U_)
3641 {
3642         switch (si->status) {
3643         case 0x00000000: break;
3644         default: return dissect_smb2_error_response(tvb, pinfo, tree, offset, si);
3645         }
3646
3647         /* buffer code */
3648         offset = dissect_smb2_buffercode(tree, tvb, offset, NULL);
3649         /* some unknown bytes */
3650         proto_tree_add_item(tree, hf_smb2_unknown, tvb, offset, 2, TRUE);
3651         offset += 2;
3652
3653         /* length */
3654         proto_tree_add_item(tree, hf_smb2_write_length, tvb, offset, 4, TRUE);
3655         offset += 4;
3656
3657         /* some unknown bytes */
3658         proto_tree_add_item(tree, hf_smb2_unknown, tvb, offset, 9, TRUE);
3659         offset += 9;
3660
3661         return offset;
3662 }
3663
3664 static void
3665 dissect_smb2_IOCTL_DO_DCERPC(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, proto_tree *top_tree, gboolean data_in _U_)
3666 {
3667         dissect_file_data_dcerpc(tvb, pinfo, tree, offset, tvb_length_remaining(tvb, offset), top_tree);
3668
3669         return;
3670 }
3671
3672 static void
3673 dissect_smb2_FSCTL_GET_SHADOW_COPY_DATA(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int offset, gboolean data_in)
3674 {
3675         guint32 num_volumes, num_labels;
3676
3677         /* There is no in data */
3678         if(data_in){
3679                 return;
3680         }
3681
3682         /* num volumes */
3683         num_volumes=tvb_get_letohl(tvb, offset);
3684         proto_tree_add_item(tree, hf_smb2_ioctl_shadow_copy_num_volumes, tvb, offset, 4, TRUE);
3685         offset += 4;
3686
3687         /* num labels */
3688         num_labels=tvb_get_letohl(tvb, offset);
3689         proto_tree_add_item(tree, hf_smb2_ioctl_shadow_copy_num_labels, tvb, offset, 4, TRUE);
3690         offset += 4;
3691
3692         /* count */
3693         proto_tree_add_item(tree, hf_smb2_ioctl_shadow_copy_count, tvb, offset, 4, TRUE);
3694         offset += 4;
3695
3696         while(num_volumes--){
3697                 const char *name;
3698                 guint16 bc;
3699                 int len=0;
3700                 int old_offset=offset;
3701
3702                 bc=tvb_length_remaining(tvb, offset);
3703                 name = get_unicode_or_ascii_string(tvb, &offset,
3704                         TRUE, &len, TRUE, FALSE, &bc);
3705                 proto_tree_add_string(tree, hf_smb2_ioctl_shadow_copy_label, tvb, old_offset, len, name);
3706
3707                 offset = old_offset+len;
3708
3709                 if(!len){
3710                         break;
3711                 }
3712         }
3713
3714         return;
3715 }
3716
3717 int
3718 dissect_smb2_FILE_OBJECTID_BUFFER(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *parent_tree, int offset)
3719 {
3720         proto_item *item=NULL;
3721         proto_tree *tree=NULL;
3722
3723         /* FILE_OBJECTID_BUFFER */
3724         if(parent_tree){
3725                 item = proto_tree_add_item(parent_tree, hf_smb2_FILE_OBJECTID_BUFFER, tvb, offset, 64, TRUE);
3726                 tree = proto_item_add_subtree(item, ett_smb2_FILE_OBJECTID_BUFFER);
3727         }
3728
3729         /* Object ID */
3730         proto_tree_add_item(tree, hf_smb2_object_id, tvb, offset, 16, TRUE);
3731         offset += 16;
3732
3733         /* Birth Volume ID */
3734         proto_tree_add_item(tree, hf_smb2_birth_volume_id, tvb, offset, 16, TRUE);
3735         offset += 16;
3736
3737         /* Birth Object ID */
3738         proto_tree_add_item(tree, hf_smb2_birth_object_id, tvb, offset, 16, TRUE);
3739         offset += 16;
3740
3741         /* Domain ID */
3742         proto_tree_add_item(tree, hf_smb2_domain_id, tvb, offset, 16, TRUE);
3743         offset += 16;
3744
3745         return offset;
3746 }
3747
3748 static void
3749 dissect_smb2_FSCTL_CREATE_OR_GET_OBJECT_ID(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int offset, gboolean data_in)
3750 {
3751
3752         /* There is no in data */
3753         if(data_in){
3754                 return;
3755         }
3756
3757         /* FILE_OBJECTID_BUFFER */
3758         offset=dissect_smb2_FILE_OBJECTID_BUFFER(tvb, pinfo, tree, offset);
3759
3760         return;
3761 }
3762
3763 static void
3764 dissect_smb2_FSCTL_GET_COMPRESSION(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int offset, gboolean data_in)
3765 {
3766
3767         /* There is no in data */
3768         if(data_in){
3769                 return;
3770         }
3771
3772         /* compression format */
3773         proto_tree_add_item(tree, hf_smb2_compression_format, tvb, offset, 2, TRUE);
3774         offset += 2;
3775
3776         return;
3777 }
3778 static void
3779 dissect_smb2_FSCTL_SET_COMPRESSION(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int offset, gboolean data_in)
3780 {
3781
3782         /* There is no out data */
3783         if(!data_in){
3784                 return;
3785         }
3786
3787         /* compression format */
3788         proto_tree_add_item(tree, hf_smb2_compression_format, tvb, offset, 2, TRUE);
3789         offset += 2;
3790
3791         return;
3792 }
3793
3794 static void
3795 dissect_smb2_FSCTL_SET_OBJECT_ID(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int offset, gboolean data_in)
3796 {
3797
3798         /* There is no out data */
3799         if(!data_in){
3800                 return;
3801         }
3802
3803         /* FILE_OBJECTID_BUFFER */
3804         offset=dissect_smb2_FILE_OBJECTID_BUFFER(tvb, pinfo, tree, offset);
3805
3806         return;
3807 }
3808
3809 static void
3810 dissect_smb2_FSCTL_SET_OBJECT_ID_EXTENDED(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int offset, gboolean data_in)
3811 {
3812
3813         /* There is no out data */
3814         if(!data_in){
3815                 return;
3816         }
3817
3818         /* FILE_OBJECTID_BUFFER->ExtendedInfo */
3819
3820         /* Birth Volume ID */
3821         proto_tree_add_item(tree, hf_smb2_birth_volume_id, tvb, offset, 16, TRUE);
3822         offset += 16;
3823
3824         /* Birth Object ID */
3825         proto_tree_add_item(tree, hf_smb2_birth_object_id, tvb, offset, 16, TRUE);
3826         offset += 16;
3827
3828         /* Domain ID */
3829         proto_tree_add_item(tree, hf_smb2_domain_id, tvb, offset, 16, TRUE);
3830         offset += 16;
3831
3832         return;
3833 }
3834
3835 void
3836 dissect_smb2_ioctl_data(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_tree *top_tree, guint32 ioctl_function, gboolean data_in)
3837 {
3838         switch(ioctl_function){
3839         case 0x0011c017:
3840                 dissect_smb2_IOCTL_DO_DCERPC(tvb, pinfo, tree, 0, top_tree, data_in);
3841                 break;
3842         case 0x00144064: /* FSCTL_GET_SHADOW_COPY_DATA */
3843                 dissect_smb2_FSCTL_GET_SHADOW_COPY_DATA(tvb, pinfo, tree, 0, data_in);
3844                 break;
3845         case 0x0009009C: /* FSCTL_GET_OBJECT_ID */
3846         case 0x000900c0: /* FSCTL_CREATE_OR_GET_OBJECT_ID */
3847                 dissect_smb2_FSCTL_CREATE_OR_GET_OBJECT_ID(tvb, pinfo, tree, 0, data_in);
3848                 break;
3849         case 0x00098098: /* FSCTL_SET_OBJECT_ID */
3850                 dissect_smb2_FSCTL_SET_OBJECT_ID(tvb, pinfo, tree, 0, data_in);
3851                 break;
3852         case 0x000980BC: /* FSCTL_SET_OBJECT_ID_EXTENDED */
3853                 dissect_smb2_FSCTL_SET_OBJECT_ID_EXTENDED(tvb, pinfo, tree, 0, data_in);
3854                 break;
3855         case 0x0009003C: /* FSCTL_GET_COMPRESSION */
3856                 dissect_smb2_FSCTL_GET_COMPRESSION(tvb, pinfo, tree, 0, data_in);
3857                 break;
3858         case 0x0009C040: /* FSCTL_SET_COMPRESSION */
3859                 dissect_smb2_FSCTL_SET_COMPRESSION(tvb, pinfo, tree, 0, data_in);
3860                 break;
3861         default:
3862                 proto_tree_add_item(tree, hf_smb2_unknown, tvb, 0, tvb_length(tvb), TRUE);
3863         }
3864
3865         return;
3866 }
3867
3868 static void
3869 dissect_smb2_ioctl_data_in(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, smb2_info_t *si)
3870 {
3871         dissect_smb2_ioctl_data(tvb, pinfo, tree, si->top_tree, si->ioctl_function, TRUE);
3872 }
3873
3874 static void
3875 dissect_smb2_ioctl_data_out(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, smb2_info_t *si)
3876 {
3877         dissect_smb2_ioctl_data(tvb, pinfo, tree, si->top_tree, si->ioctl_function, FALSE);
3878 }
3879
3880 static int
3881 dissect_smb2_ioctl_request(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, smb2_info_t *si)
3882 {
3883         offset_length_buffer_t o_olb;
3884         offset_length_buffer_t i_olb;
3885         proto_tree *flags_tree = NULL;
3886         proto_item *flags_item = NULL;
3887
3888         /* buffer code */
3889         offset = dissect_smb2_buffercode(tree, tvb, offset, NULL);
3890
3891         /* reserved */
3892         offset += 2;
3893
3894         /* ioctl function */
3895         offset = dissect_smb2_ioctl_function(tvb, pinfo, tree, offset, &si->ioctl_function);
3896
3897         /* fid */
3898         offset = dissect_smb2_fid(tvb, pinfo, tree, offset, si, FID_MODE_USE);
3899
3900         /* in buffer offset/length */
3901         offset = dissect_smb2_olb_length_offset(tvb, offset, &i_olb, OLB_O_UINT32_S_UINT32, hf_smb2_ioctl_in_data);
3902
3903         /* max ioctl in size */
3904         proto_tree_add_item(tree, hf_smb2_max_ioctl_in_size, tvb, offset, 4, TRUE);
3905         offset += 4;
3906
3907         /* out buffer offset/length */
3908         offset = dissect_smb2_olb_length_offset(tvb, offset, &o_olb, OLB_O_UINT32_S_UINT32, hf_smb2_ioctl_out_data);
3909
3910         /* max ioctl out size */
3911         proto_tree_add_item(tree, hf_smb2_max_ioctl_out_size, tvb, offset, 4, TRUE);
3912         offset += 4;
3913
3914         /* flags */
3915         if(tree){
3916                 flags_item = proto_tree_add_item(tree, hf_smb2_ioctl_flags, tvb, offset, 4, TRUE);
3917                 flags_tree = proto_item_add_subtree(flags_item, ett_smb2_ioctl_flags);
3918         }
3919         proto_tree_add_item(flags_tree, hf_smb2_ioctl_is_fsctl, tvb, offset, 4, TRUE);
3920         offset += 4;
3921
3922         /* reserved */
3923         offset += 4;
3924
3925         /* try to decode these blobs in the order they were encoded
3926          * so that for "short" packets we will dissect as much as possible
3927          * before aborting with "short packet"
3928          */
3929         if(i_olb.off>o_olb.off){
3930                 /* out buffer */
3931                 dissect_smb2_olb_buffer(pinfo, tree, tvb, &o_olb, si, dissect_smb2_ioctl_data_out);
3932                 /* in buffer */
3933                 dissect_smb2_olb_buffer(pinfo, tree, tvb, &i_olb, si, dissect_smb2_ioctl_data_in);
3934         } else {
3935                 /* in buffer */
3936                 dissect_smb2_olb_buffer(pinfo, tree, tvb, &i_olb, si, dissect_smb2_ioctl_data_in);
3937                 /* out buffer */
3938                 dissect_smb2_olb_buffer(pinfo, tree, tvb, &o_olb, si, dissect_smb2_ioctl_data_out);
3939         }
3940
3941         offset = dissect_smb2_olb_tvb_max_offset(offset, &o_olb);
3942         offset = dissect_smb2_olb_tvb_max_offset(offset, &i_olb);
3943
3944         return offset;
3945 }
3946
3947 static int
3948 dissect_smb2_ioctl_response(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, smb2_info_t *si)
3949 {
3950         offset_length_buffer_t o_olb;
3951         offset_length_buffer_t i_olb;
3952         proto_tree *flags_tree = NULL;
3953         proto_item *flags_item = NULL;
3954
3955         switch (si->status) {
3956         case 0x00000000: break;
3957         default: return dissect_smb2_error_response(tvb, pinfo, tree, offset, si);
3958         }
3959
3960         /* buffer code */
3961         offset = dissect_smb2_buffercode(tree, tvb, offset, NULL);
3962
3963         /* some unknown bytes */
3964         proto_tree_add_item(tree, hf_smb2_unknown, tvb, offset, 2, TRUE);
3965         offset += 2;
3966
3967         /* ioctl function */
3968         offset = dissect_smb2_ioctl_function(tvb, pinfo, tree, offset, &si->ioctl_function);
3969
3970         /* fid */
3971         offset = dissect_smb2_fid(tvb, pinfo, tree, offset, si, FID_MODE_USE);
3972
3973         /* in buffer offset/length */
3974         offset = dissect_smb2_olb_length_offset(tvb, offset, &i_olb, OLB_O_UINT32_S_UINT32, hf_smb2_ioctl_in_data);
3975
3976         /* out buffer offset/length */
3977         offset = dissect_smb2_olb_length_offset(tvb, offset, &o_olb, OLB_O_UINT32_S_UINT32, hf_smb2_ioctl_out_data);
3978
3979
3980         /* flags */
3981         if(tree){
3982                 flags_item = proto_tree_add_item(tree, hf_smb2_ioctl_flags, tvb, offset, 4, TRUE);
3983                 flags_tree = proto_item_add_subtree(flags_item, ett_smb2_ioctl_flags);
3984         }
3985         offset += 4;
3986
3987         /* reserved */
3988         offset += 4;
3989
3990         /* try to decode these blobs in the order they were encoded
3991          * so that for "short" packets we will dissect as much as possible
3992          * before aborting with "short packet"
3993          */
3994         if(i_olb.off>o_olb.off){
3995                 /* out buffer */
3996                 dissect_smb2_olb_buffer(pinfo, tree, tvb, &o_olb, si, dissect_smb2_ioctl_data_out);
3997                 /* in buffer */
3998                 dissect_smb2_olb_buffer(pinfo, tree, tvb, &i_olb, si, dissect_smb2_ioctl_data_in);
3999         } else {
4000                 /* in buffer */
4001                 dissect_smb2_olb_buffer(pinfo, tree, tvb, &i_olb, si, dissect_smb2_ioctl_data_in);
4002                 /* out buffer */
4003                 dissect_smb2_olb_buffer(pinfo, tree, tvb, &o_olb, si, dissect_smb2_ioctl_data_out);
4004         }
4005
4006         offset = dissect_smb2_olb_tvb_max_offset(offset, &i_olb);
4007         offset = dissect_smb2_olb_tvb_max_offset(offset, &o_olb);
4008
4009         return offset;
4010 }
4011
4012
4013 static int
4014 dissect_smb2_read_request(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, smb2_info_t *si)
4015 {
4016         guint32 len;
4017         guint64 off;
4018
4019         /* buffer code */
4020         offset = dissect_smb2_buffercode(tree, tvb, offset, NULL);
4021
4022         /* padding and reserved */
4023         offset += 2;
4024
4025         /* length */
4026         len=tvb_get_letohl(tvb, offset);
4027         proto_tree_add_item(tree, hf_smb2_read_length, tvb, offset, 4, TRUE);
4028         offset += 4;
4029
4030         /* offset */
4031         off=tvb_get_letoh64(tvb, offset);
4032         proto_tree_add_item(tree, hf_smb2_file_offset, tvb, offset, 8, TRUE);
4033         offset += 8;
4034
4035         if (check_col(pinfo->cinfo, COL_INFO)){
4036                 col_append_fstr(pinfo->cinfo, COL_INFO, " Len:%d Off:%" G_GINT64_MODIFIER "u", len, off);
4037         }
4038
4039         /* fid */
4040         offset = dissect_smb2_fid(tvb, pinfo, tree, offset, si, FID_MODE_USE);
4041
4042         /* minimum count */
4043         proto_tree_add_item(tree, hf_smb2_min_count, tvb, offset, 4, TRUE);
4044
4045         /* channel */
4046         proto_tree_add_item(tree, hf_smb2_channel, tvb, offset, 4, TRUE);
4047         offset += 4;
4048
4049         /* remaining bytes */
4050         proto_tree_add_item(tree, hf_smb2_remaining_bytes, tvb, offset, 4, TRUE);
4051         offset += 4;
4052
4053         /* channel info offset */
4054         proto_tree_add_item(tree, hf_smb2_channel_info_offset, tvb, offset, 2, TRUE);
4055         offset += 2;
4056
4057         /* channel info length */
4058         proto_tree_add_item(tree, hf_smb2_channel_info_length, tvb, offset, 2, TRUE);
4059         offset += 2;
4060
4061         /* there is a buffer here   but it is never used (yet) */
4062
4063         return offset;
4064 }
4065
4066
4067 static int
4068 dissect_smb2_read_response(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, smb2_info_t *si _U_)
4069 {
4070         guint32 length;
4071
4072         switch (si->status) {
4073         case 0x00000000: break;
4074         default: return dissect_smb2_error_response(tvb, pinfo, tree, offset, si);
4075         }
4076
4077         /* buffer code */
4078         offset = dissect_smb2_buffercode(tree, tvb, offset, NULL);
4079
4080         /* data offset */
4081         proto_tree_add_item(tree, hf_smb2_data_offset, tvb, offset, 2, TRUE);
4082         offset += 2;
4083
4084         /* length  might even be 64bits if they are ambitious*/
4085         length=tvb_get_letohl(tvb, offset);
4086         proto_tree_add_item(tree, hf_smb2_read_length, tvb, offset, 4, TRUE);
4087         offset += 4;
4088
4089         /* remaining */
4090         proto_tree_add_item(tree, hf_smb2_read_remaining, tvb, offset, 4, TRUE);
4091         offset += 4;
4092
4093         /* reserved */
4094         offset += 4;
4095
4096         /* data or dcerpc ?
4097          * If the pidvalid flag is set we assume it is a deferred
4098          * STATUS_PENDING read and thus a named pipe (==dcerpc)
4099          */
4100         if(length && ( (si->tree && si->tree->share_type == SMB2_SHARE_TYPE_IPC)||(si->flags & SMB2_FLAGS_ASYNC_CMD))){
4101                 offset = dissect_file_data_dcerpc(tvb, pinfo, tree, offset, length, si->top_tree);
4102                 return offset;
4103         }
4104
4105         /* data */
4106         proto_tree_add_item(tree, hf_smb2_read_data, tvb, offset, length, TRUE);
4107         offset += MIN(length,(guint32)tvb_length_remaining(tvb, offset));
4108
4109         return offset;
4110 }
4111
4112 static void
4113 dissect_smb2_ExtA_buffer(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, smb2_info_t *si)
4114 {
4115         proto_item *item=NULL;
4116         if (tree) {
4117                 item = proto_tree_get_parent(tree);
4118                 proto_item_append_text(item, ": SMB2_FILE_INFO_0f");
4119         }
4120         dissect_smb2_file_info_0f(tvb, pinfo, tree, 0, si);
4121         return;
4122 }
4123
4124 static void
4125 dissect_smb2_TWrp_buffer(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, smb2_info_t *si _U_)
4126 {
4127         proto_item *item=NULL;
4128         if (tree) {
4129                 item = proto_tree_get_parent(tree);
4130                 proto_item_append_text(item, ": Timestamp");
4131         }
4132         dissect_nt_64bit_time(tvb, tree, 0, hf_smb2_unknown_timestamp);
4133
4134         return;
4135 }
4136
4137
4138 static void
4139 dissect_smb2_AlSi_buffer(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, smb2_info_t *si _U_)
4140 {
4141         proto_tree_add_item(tree, hf_smb2_allocation_size, tvb, 0, 8, TRUE);
4142 }
4143
4144 static void
4145 dissect_smb2_DHnQ_buffer(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, smb2_info_t *si)
4146 {
4147         dissect_smb2_fid(tvb, pinfo, tree, 0, si, FID_MODE_DHNQ);
4148 }
4149
4150 static void
4151 dissect_smb2_DHnC_buffer(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, smb2_info_t *si)
4152 {
4153         dissect_smb2_fid(tvb, pinfo, tree, 0, si, FID_MODE_DHNC);
4154 }
4155
4156 static void
4157 dissect_smb2_MxAc_buffer(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, smb2_info_t *si _U_)
4158 {
4159         int offset=0;
4160         proto_item *item=NULL;
4161         proto_item *sub_item=NULL;
4162         proto_tree *sub_tree=NULL;
4163
4164         if (tree) {
4165                 item = proto_tree_get_parent(tree);
4166         }
4167
4168         if (tvb_length(tvb) == 0) {
4169                 if (item) {
4170                         proto_item_append_text(item, ": NO DATA");
4171                 }
4172                 return;
4173         }
4174
4175         if (item) {
4176                 proto_item_append_text(item, ": MxAc INFO");
4177                 sub_item = proto_tree_add_text(tree, tvb, offset, -1, "MxAc INFO");
4178                 sub_tree = proto_item_add_subtree(sub_item, ett_smb2_MxAc_buffer);
4179         }
4180
4181         proto_tree_add_item(sub_tree, hf_smb2_unknown, tvb, offset, 4, FALSE);
4182         offset += 4;
4183
4184         offset = dissect_smb_access_mask(tvb, sub_tree, offset);
4185
4186         return;
4187 }
4188
4189 static void
4190 dissect_smb2_create_extra_info(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, smb2_info_t *si)
4191 {
4192         offset_length_buffer_t tag_olb;
4193         offset_length_buffer_t data_olb;
4194         const char *tag;
4195         guint16 chain_offset;
4196         int offset=0;
4197         int len=-1;
4198         void (*dissector)(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, smb2_info_t *si);
4199         proto_item *sub_item=NULL;
4200         proto_tree *sub_tree=NULL;
4201         proto_item *parent_item=NULL;
4202
4203         chain_offset=tvb_get_letohl(tvb, offset);
4204         if (chain_offset) {
4205                 len = chain_offset;
4206         }
4207
4208         if(parent_tree){
4209                 sub_item = proto_tree_add_text(parent_tree, tvb, offset, len, "Chain Element");
4210                 sub_tree = proto_item_add_subtree(sub_item, ett_smb2_create_chain_element);
4211                 parent_item = proto_tree_get_parent(parent_tree);
4212         }
4213
4214         /* chain offset */
4215         proto_tree_add_item(sub_tree, hf_smb2_create_chain_offset, tvb, offset, 4, TRUE);
4216         offset += 4;
4217
4218         /* tag  offset/length */
4219         offset = dissect_smb2_olb_length_offset(tvb, offset, &tag_olb, OLB_O_UINT16_S_UINT32, hf_smb2_tag);
4220
4221         /* data  offset/length */
4222         offset = dissect_smb2_olb_length_offset(tvb, offset, &data_olb, OLB_O_UINT16_S_UINT32, hf_smb2_create_chain_data);
4223
4224         /* tag string */
4225         tag = dissect_smb2_olb_string(pinfo, sub_tree, tvb, &tag_olb, OLB_TYPE_ASCII_STRING);
4226
4227         proto_item_append_text(parent_item, " %s", tag);
4228         proto_item_append_text(sub_item, ": %s", tag);
4229
4230         /* data */
4231         dissector = NULL;
4232         if(!strcmp(tag, "ExtA")){
4233                 dissector = dissect_smb2_ExtA_buffer;
4234         } else if(!strcmp(tag, "AlSi")){
4235                 dissector = dissect_smb2_AlSi_buffer;
4236         } else if(!strcmp(tag, "MxAc")){
4237                 dissector = dissect_smb2_MxAc_buffer;
4238         } else if(!strcmp(tag, "DHnQ")){
4239                 dissector = dissect_smb2_DHnQ_buffer;
4240         } else if(!strcmp(tag, "DHnC")){
4241                 dissector = dissect_smb2_DHnC_buffer;
4242         } else if(!strcmp(tag, "TWrp")){
4243                 dissector = dissect_smb2_TWrp_buffer;
4244         }
4245
4246         dissect_smb2_olb_buffer(pinfo, sub_tree, tvb, &data_olb, si, dissector);
4247
4248         if(chain_offset){
4249                 tvbuff_t *chain_tvb;
4250                 chain_tvb=tvb_new_subset(tvb, chain_offset, tvb_length_remaining(tvb, chain_offset), tvb_reported_length_remaining(tvb, chain_offset));
4251
4252                 /* next extra info */
4253                 dissect_smb2_create_extra_info(chain_tvb, pinfo, parent_tree, si);
4254         }
4255         return;
4256 }
4257
4258 static int
4259 dissect_smb2_create_request(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, smb2_info_t *si)
4260 {
4261         offset_length_buffer_t f_olb, e_olb;
4262         const char *fname;
4263
4264         /* buffer code */
4265         offset = dissect_smb2_buffercode(tree, tvb, offset, NULL);
4266
4267         /* security flags */
4268         offset++;
4269
4270         /* oplock */
4271         offset = dissect_smb2_oplock(tree, tvb, offset);
4272
4273         /* impersonation level */
4274         proto_tree_add_item(tree, hf_smb2_impersonation_level, tvb, offset, 4, TRUE);
4275         offset += 4;
4276
4277         /* create flags */
4278         proto_tree_add_item(tree, hf_smb2_create_flags, tvb, offset, 8, TRUE);
4279         offset += 8;
4280
4281         /* reserved */
4282         offset += 8;
4283
4284         /* access mask */
4285         offset = dissect_smb_access_mask(tvb, tree, offset);
4286
4287         /* File Attributes */
4288         offset = dissect_file_attributes(tvb, tree, offset, 4);
4289
4290         /* share access */
4291         offset = dissect_nt_share_access(tvb, tree, offset);
4292
4293         /* create disposition */
4294         proto_tree_add_item(tree, hf_smb2_create_disposition, tvb, offset, 4, TRUE);
4295         offset += 4;
4296
4297         /* create options */
4298         offset = dissect_nt_create_options(tvb, tree, offset);
4299
4300         /* filename  offset/length */
4301         offset = dissect_smb2_olb_length_offset(tvb, offset, &f_olb, OLB_O_UINT16_S_UINT16, hf_smb2_filename);
4302
4303         /* extrainfo offset */
4304         offset = dissect_smb2_olb_length_offset(tvb, offset, &e_olb, OLB_O_UINT32_S_UINT32, hf_smb2_extrainfo);
4305
4306         /* filename string */
4307         fname = dissect_smb2_olb_string(pinfo, tree, tvb, &f_olb, OLB_TYPE_UNICODE_STRING);
4308         if (check_col(pinfo->cinfo, COL_INFO)){
4309                 col_append_fstr(pinfo->cinfo, COL_INFO, " File: %s", fname);
4310         }
4311
4312         /* save the name if it looks sane */
4313         if(!pinfo->fd->flags.visited){
4314                 if(si->saved && si->saved->extra_info_type==SMB2_EI_FILENAME){
4315                         g_free(si->saved->extra_info);
4316                         si->saved->extra_info=NULL;
4317                         si->saved->extra_info_type=SMB2_EI_NONE;
4318                 }
4319                 if(si->saved && f_olb.len && f_olb.len<256){
4320                         si->saved->extra_info_type=SMB2_EI_FILENAME;
4321                         si->saved->extra_info=g_malloc(f_olb.len+1);
4322                         g_snprintf(si->saved->extra_info, f_olb.len+1, "%s", fname);
4323                 }
4324         }
4325
4326         /* If extrainfo_offset is non-null then this points to another
4327          * buffer. The offset is relative to the start of the smb packet
4328          */
4329         dissect_smb2_olb_buffer(pinfo, tree, tvb, &e_olb, si, dissect_smb2_create_extra_info);
4330
4331         offset = dissect_smb2_olb_tvb_max_offset(offset, &f_olb);
4332         offset = dissect_smb2_olb_tvb_max_offset(offset, &e_olb);
4333
4334         return offset;
4335 }
4336
4337 static int
4338 dissect_smb2_create_response(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, smb2_info_t *si)
4339 {
4340         offset_length_buffer_t e_olb;
4341
4342         switch (si->status) {
4343         case 0x00000000: break;
4344         default: return dissect_smb2_error_response(tvb, pinfo, tree, offset, si);
4345         }
4346
4347         /* buffer code */
4348         offset = dissect_smb2_buffercode(tree, tvb, offset, NULL);
4349
4350         /* oplock */
4351         offset = dissect_smb2_oplock(tree, tvb, offset);
4352
4353         /* reserved */
4354         offset++;
4355
4356         /* create action */
4357         proto_tree_add_item(tree, hf_smb2_create_action, tvb, offset, 4, TRUE);
4358         offset += 4;
4359
4360         /* create time */
4361         offset = dissect_nt_64bit_time(tvb, tree, offset, hf_smb2_create_timestamp);
4362
4363         /* last access */
4364         offset = dissect_nt_64bit_time(tvb, tree, offset, hf_smb2_last_access_timestamp);
4365
4366         /* last write */
4367         offset = dissect_nt_64bit_time(tvb, tree, offset, hf_smb2_last_write_timestamp);
4368
4369         /* last change */
4370         offset = dissect_nt_64bit_time(tvb, tree, offset, hf_smb2_last_change_timestamp);
4371
4372         /* allocation size */
4373         proto_tree_add_item(tree, hf_smb2_allocation_size, tvb, offset, 8, TRUE);
4374         offset += 8;
4375
4376         /* end of file */
4377         proto_tree_add_item(tree, hf_smb2_end_of_file, tvb, offset, 8, TRUE);
4378         offset += 8;
4379
4380         /* File Attributes */
4381         offset = dissect_file_attributes(tvb, tree, offset, 4);
4382
4383         /* reserved */
4384         offset += 4;
4385
4386         /* fid */
4387         offset = dissect_smb2_fid(tvb, pinfo, tree, offset, si, FID_MODE_OPEN);
4388
4389         /* extrainfo offset */
4390         offset = dissect_smb2_olb_length_offset(tvb, offset, &e_olb, OLB_O_UINT32_S_UINT32, hf_smb2_extrainfo);
4391
4392         /* If extrainfo_offset is non-null then this points to another
4393          * buffer. The offset is relative to the start of the smb packet
4394          */
4395         dissect_smb2_olb_buffer(pinfo, tree, tvb, &e_olb, si, dissect_smb2_create_extra_info);
4396
4397         offset = dissect_smb2_olb_tvb_max_offset(offset, &e_olb);
4398
4399         /* free si->saved->extra_info   we dont need it any more */
4400         if(si->saved && si->saved->extra_info_type==SMB2_EI_FILENAME){
4401                 g_free(si->saved->extra_info);
4402                 si->saved->extra_info=NULL;
4403                 si->saved->extra_info_type=SMB2_EI_NONE;
4404         }
4405
4406         return offset;
4407 }
4408
4409
4410 static int
4411 dissect_smb2_setinfo_request(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, smb2_info_t *si)
4412 {
4413         guint32 setinfo_size;
4414         guint16 setinfo_offset;
4415
4416         /* buffer code */
4417         offset = dissect_smb2_buffercode(tree, tvb, offset, NULL);
4418
4419         /* class and info level */
4420         offset = dissect_smb2_class_infolevel(pinfo, tvb, offset, tree, si);
4421
4422         /* size */
4423         setinfo_size=tvb_get_letohl(tvb, offset);
4424         proto_tree_add_item(tree, hf_smb2_setinfo_size, tvb, offset, 4, TRUE);
4425         offset += 4;
4426
4427         /* offset */
4428         setinfo_offset=tvb_get_letohs(tvb, offset);
4429         proto_tree_add_item(tree, hf_smb2_setinfo_offset, tvb, offset, 2, TRUE);
4430         offset += 2;
4431
4432         /* some unknown bytes */
4433         proto_tree_add_item(tree, hf_smb2_unknown, tvb, offset, 6, TRUE);
4434         offset += 6;
4435
4436         /* fid */
4437         offset = dissect_smb2_fid(tvb, pinfo, tree, offset, si, FID_MODE_USE);
4438
4439         /* data */
4440         if(si->saved)
4441           dissect_smb2_infolevel(tvb, pinfo, tree, setinfo_offset, si, si->saved->class, si->saved->infolevel);
4442         offset = setinfo_offset + setinfo_size;
4443
4444         return offset;
4445 }
4446
4447 static int
4448 dissect_smb2_setinfo_response(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, smb2_info_t *si)
4449 {
4450         /* class/infolevel */
4451         dissect_smb2_class_infolevel(pinfo, tvb, offset, tree, si);
4452
4453         switch (si->status) {
4454         case 0x00000000: break;
4455         default: return dissect_smb2_error_response(tvb, pinfo, tree, offset, si);
4456         }
4457
4458         /* buffer code */
4459         offset = dissect_smb2_buffercode(tree, tvb, offset, NULL);
4460
4461         return offset;
4462 }
4463
4464 static int
4465 dissect_smb2_break_request(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, smb2_info_t *si)
4466 {
4467         /* buffer code */
4468         offset = dissect_smb2_buffercode(tree, tvb, offset, NULL);
4469
4470         /* oplock */
4471         offset = dissect_smb2_oplock(tree, tvb, offset);
4472
4473         /* reserved */
4474         offset += 1;
4475
4476         /* reserved */
4477         offset += 4;
4478
4479         /* fid */
4480         offset = dissect_smb2_fid(tvb, pinfo, tree, offset, si, FID_MODE_USE);
4481
4482         return offset;
4483 }
4484
4485 static int
4486 dissect_smb2_break_response(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, smb2_info_t *si)
4487 {
4488         switch (si->status) {
4489         case 0x00000000: break;
4490         default: return dissect_smb2_error_response(tvb, pinfo, tree, offset, si);
4491         }
4492
4493         /* buffer code */
4494         offset = dissect_smb2_buffercode(tree, tvb, offset, NULL);
4495
4496         /* oplock */
4497         offset = dissect_smb2_oplock(tree, tvb, offset);
4498
4499         /* reserved */
4500         offset += 1;
4501
4502         /* reserved */
4503         offset += 4;
4504
4505         /* fid */
4506         offset = dissect_smb2_fid(tvb, pinfo, tree, offset, si, FID_MODE_USE);
4507
4508         /* in break requests from server to client here're 24 byte zero bytes
4509          * which are likely a bug in windows (they may use 2* 24 bytes instead of just
4510          * 1 *24 bytes
4511          */
4512
4513         return offset;
4514 }
4515
4516 /* names here are just until we find better names for these functions */
4517 const value_string smb2_cmd_vals[] = {
4518   { 0x00, "NegotiateProtocol" },
4519   { 0x01, "SessionSetup" },
4520   { 0x02, "SessionLogoff" },
4521   { 0x03, "TreeConnect" },
4522   { 0x04, "TreeDisconnect" },
4523   { 0x05, "Create" },
4524   { 0x06, "Close" },
4525   { 0x07, "Flush" },
4526   { 0x08, "Read" },
4527   { 0x09, "Write" },
4528   { 0x0A, "Lock" },
4529   { 0x0B, "Ioctl" },
4530   { 0x0C, "Cancel" },
4531   { 0x0D, "KeepAlive" },
4532   { 0x0E, "Find" },
4533   { 0x0F, "Notify" },
4534   { 0x10, "GetInfo" },
4535   { 0x11, "SetInfo" },
4536   { 0x12, "Break" },
4537   { 0x13, "unknown-0x13" },
4538   { 0x14, "unknown-0x14" },
4539   { 0x15, "unknown-0x15" },
4540   { 0x16, "unknown-0x16" },
4541   { 0x17, "unknown-0x17" },
4542   { 0x18, "unknown-0x18" },
4543   { 0x19, "unknown-0x19" },
4544   { 0x1A, "unknown-0x1A" },
4545   { 0x1B, "unknown-0x1B" },
4546   { 0x1C, "unknown-0x1C" },
4547   { 0x1D, "unknown-0x1D" },
4548   { 0x1E, "unknown-0x1E" },
4549   { 0x1F, "unknown-0x1F" },
4550   { 0x20, "unknown-0x20" },
4551   { 0x21, "unknown-0x21" },
4552   { 0x22, "unknown-0x22" },
4553   { 0x23, "unknown-0x23" },
4554   { 0x24, "unknown-0x24" },
4555   { 0x25, "unknown-0x25" },
4556   { 0x26, "unknown-0x26" },
4557   { 0x27, "unknown-0x27" },
4558   { 0x28, "unknown-0x28" },
4559   { 0x29, "unknown-0x29" },
4560   { 0x2A, "unknown-0x2A" },
4561   { 0x2B, "unknown-0x2B" },
4562   { 0x2C, "unknown-0x2C" },
4563   { 0x2D, "unknown-0x2D" },
4564   { 0x2E, "unknown-0x2E" },
4565   { 0x2F, "unknown-0x2F" },
4566   { 0x30, "unknown-0x30" },
4567   { 0x31, "unknown-0x31" },
4568   { 0x32, "unknown-0x32" },
4569   { 0x33, "unknown-0x33" },
4570   { 0x34, "unknown-0x34" },
4571   { 0x35, "unknown-0x35" },
4572   { 0x36, "unknown-0x36" },
4573   { 0x37, "unknown-0x37" },
4574   { 0x38, "unknown-0x38" },
4575   { 0x39, "unknown-0x39" },
4576   { 0x3A, "unknown-0x3A" },
4577   { 0x3B, "unknown-0x3B" },
4578   { 0x3C, "unknown-0x3C" },
4579   { 0x3D, "unknown-0x3D" },
4580   { 0x3E, "unknown-0x3E" },
4581   { 0x3F, "unknown-0x3F" },
4582   { 0x40, "unknown-0x40" },
4583   { 0x41, "unknown-0x41" },
4584   { 0x42, "unknown-0x42" },
4585   { 0x43, "unknown-0x43" },
4586   { 0x44, "unknown-0x44" },
4587   { 0x45, "unknown-0x45" },
4588   { 0x46, "unknown-0x46" },
4589   { 0x47, "unknown-0x47" },
4590   { 0x48, "unknown-0x48" },
4591   { 0x49, "unknown-0x49" },
4592   { 0x4A, "unknown-0x4A" },
4593   { 0x4B, "unknown-0x4B" },
4594   { 0x4C, "unknown-0x4C" },
4595   { 0x4D, "unknown-0x4D" },
4596   { 0x4E, "unknown-0x4E" },
4597   { 0x4F, "unknown-0x4F" },
4598   { 0x50, "unknown-0x50" },
4599   { 0x51, "unknown-0x51" },
4600   { 0x52, "unknown-0x52" },
4601   { 0x53, "unknown-0x53" },
4602   { 0x54, "unknown-0x54" },
4603   { 0x55, "unknown-0x55" },
4604   { 0x56, "unknown-0x56" },
4605   { 0x57, "unknown-0x57" },
4606   { 0x58, "unknown-0x58" },
4607   { 0x59, "unknown-0x59" },
4608   { 0x5A, "unknown-0x5A" },
4609   { 0x5B, "unknown-0x5B" },
4610   { 0x5C, "unknown-0x5C" },
4611   { 0x5D, "unknown-0x5D" },
4612   { 0x5E, "unknown-0x5E" },
4613   { 0x5F, "unknown-0x5F" },
4614   { 0x60, "unknown-0x60" },
4615   { 0x61, "unknown-0x61" },
4616   { 0x62, "unknown-0x62" },
4617   { 0x63, "unknown-0x63" },
4618   { 0x64, "unknown-0x64" },
4619   { 0x65, "unknown-0x65" },
4620   { 0x66, "unknown-0x66" },
4621   { 0x67, "unknown-0x67" },
4622   { 0x68, "unknown-0x68" },
4623   { 0x69, "unknown-0x69" },
4624   { 0x6A, "unknown-0x6A" },
4625   { 0x6B, "unknown-0x6B" },
4626   { 0x6C, "unknown-0x6C" },
4627   { 0x6D, "unknown-0x6D" },
4628   { 0x6E, "unknown-0x6E" },
4629   { 0x6F, "unknown-0x6F" },
4630   { 0x70, "unknown-0x70" },
4631   { 0x71, "unknown-0x71" },
4632   { 0x72, "unknown-0x72" },
4633   { 0x73, "unknown-0x73" },
4634   { 0x74, "unknown-0x74" },
4635   { 0x75, "unknown-0x75" },
4636   { 0x76, "unknown-0x76" },
4637   { 0x77, "unknown-0x77" },
4638   { 0x78, "unknown-0x78" },
4639   { 0x79, "unknown-0x79" },
4640   { 0x7A, "unknown-0x7A" },
4641   { 0x7B, "unknown-0x7B" },
4642   { 0x7C, "unknown-0x7C" },
4643   { 0x7D, "unknown-0x7D" },
4644   { 0x7E, "unknown-0x7E" },
4645   { 0x7F, "unknown-0x7F" },
4646   { 0x80, "unknown-0x80" },
4647   { 0x81, "unknown-0x81" },
4648   { 0x82, "unknown-0x82" },
4649   { 0x83, "unknown-0x83" },
4650   { 0x84, "unknown-0x84" },
4651   { 0x85, "unknown-0x85" },
4652   { 0x86, "unknown-0x86" },
4653   { 0x87, "unknown-0x87" },
4654   { 0x88, "unknown-0x88" },
4655   { 0x89, "unknown-0x89" },
4656   { 0x8A, "unknown-0x8A" },
4657   { 0x8B, "unknown-0x8B" },
4658   { 0x8C, "unknown-0x8C" },
4659   { 0x8D, "unknown-0x8D" },
4660   { 0x8E, "unknown-0x8E" },
4661   { 0x8F, "unknown-0x8F" },
4662   { 0x90, "unknown-0x90" },
4663   { 0x91, "unknown-0x91" },
4664   { 0x92, "unknown-0x92" },
4665   { 0x93, "unknown-0x93" },
4666   { 0x94, "unknown-0x94" },
4667   { 0x95, "unknown-0x95" },
4668   { 0x96, "unknown-0x96" },
4669   { 0x97, "unknown-0x97" },
4670   { 0x98, "unknown-0x98" },
4671   { 0x99, "unknown-0x99" },
4672   { 0x9A, "unknown-0x9A" },
4673   { 0x9B, "unknown-0x9B" },
4674   { 0x9C, "unknown-0x9C" },
4675   { 0x9D, "unknown-0x9D" },
4676   { 0x9E, "unknown-0x9E" },
4677   { 0x9F, "unknown-0x9F" },
4678   { 0xA0, "unknown-0xA0" },
4679   { 0xA1, "unknown-0xA1" },
4680   { 0xA2, "unknown-0xA2" },
4681   { 0xA3, "unknown-0xA3" },
4682   { 0xA4, "unknown-0xA4" },
4683   { 0xA5, "unknown-0xA5" },
4684   { 0xA6, "unknown-0xA6" },
4685   { 0xA7, "unknown-0xA7" },
4686   { 0xA8, "unknown-0xA8" },
4687   { 0xA9, "unknown-0xA9" },
4688   { 0xAA, "unknown-0xAA" },
4689   { 0xAB, "unknown-0xAB" },
4690   { 0xAC, "unknown-0xAC" },
4691   { 0xAD, "unknown-0xAD" },
4692   { 0xAE, "unknown-0xAE" },
4693   { 0xAF, "unknown-0xAF" },
4694   { 0xB0, "unknown-0xB0" },
4695   { 0xB1, "unknown-0xB1" },
4696   { 0xB2, "unknown-0xB2" },
4697   { 0xB3, "unknown-0xB3" },
4698   { 0xB4, "unknown-0xB4" },
4699   { 0xB5, "unknown-0xB5" },
4700   { 0xB6, "unknown-0xB6" },
4701   { 0xB7, "unknown-0xB7" },
4702   { 0xB8, "unknown-0xB8" },
4703   { 0xB9, "unknown-0xB9" },
4704   { 0xBA, "unknown-0xBA" },
4705   { 0xBB, "unknown-0xBB" },
4706   { 0xBC, "unknown-0xBC" },
4707   { 0xBD, "unknown-0xBD" },
4708   { 0xBE, "unknown-0xBE" },
4709   { 0xBF, "unknown-0xBF" },
4710   { 0xC0, "unknown-0xC0" },
4711   { 0xC1, "unknown-0xC1" },
4712   { 0xC2, "unknown-0xC2" },
4713   { 0xC3, "unknown-0xC3" },
4714   { 0xC4, "unknown-0xC4" },
4715   { 0xC5, "unknown-0xC5" },
4716   { 0xC6, "unknown-0xC6" },
4717   { 0xC7, "unknown-0xC7" },
4718   { 0xC8, "unknown-0xC8" },
4719   { 0xC9, "unknown-0xC9" },
4720   { 0xCA, "unknown-0xCA" },
4721   { 0xCB, "unknown-0xCB" },
4722   { 0xCC, "unknown-0xCC" },
4723   { 0xCD, "unknown-0xCD" },
4724   { 0xCE, "unknown-0xCE" },
4725   { 0xCF, "unknown-0xCF" },
4726   { 0xD0, "unknown-0xD0" },
4727   { 0xD1, "unknown-0xD1" },
4728   { 0xD2, "unknown-0xD2" },
4729   { 0xD3, "unknown-0xD3" },
4730   { 0xD4, "unknown-0xD4" },
4731   { 0xD5, "unknown-0xD5" },
4732   { 0xD6, "unknown-0xD6" },
4733   { 0xD7, "unknown-0xD7" },
4734   { 0xD8, "unknown-0xD8" },
4735   { 0xD9, "unknown-0xD9" },
4736   { 0xDA, "unknown-0xDA" },
4737   { 0xDB, "unknown-0xDB" },
4738   { 0xDC, "unknown-0xDC" },
4739   { 0xDD, "unknown-0xDD" },
4740   { 0xDE, "unknown-0xDE" },
4741   { 0xDF, "unknown-0xDF" },
4742   { 0xE0, "unknown-0xE0" },
4743   { 0xE1, "unknown-0xE1" },
4744   { 0xE2, "unknown-0xE2" },
4745   { 0xE3, "unknown-0xE3" },
4746   { 0xE4, "unknown-0xE4" },
4747   { 0xE5, "unknown-0xE5" },
4748   { 0xE6, "unknown-0xE6" },
4749   { 0xE7, "unknown-0xE7" },
4750   { 0xE8, "unknown-0xE8" },
4751   { 0xE9, "unknown-0xE9" },
4752   { 0xEA, "unknown-0xEA" },
4753   { 0xEB, "unknown-0xEB" },
4754   { 0xEC, "unknown-0xEC" },
4755   { 0xED, "unknown-0xED" },
4756   { 0xEE, "unknown-0xEE" },
4757   { 0xEF, "unknown-0xEF" },
4758   { 0xF0, "unknown-0xF0" },
4759   { 0xF1, "unknown-0xF1" },
4760   { 0xF2, "unknown-0xF2" },
4761   { 0xF3, "unknown-0xF3" },
4762   { 0xF4, "unknown-0xF4" },
4763   { 0xF5, "unknown-0xF5" },
4764   { 0xF6, "unknown-0xF6" },
4765   { 0xF7, "unknown-0xF7" },
4766   { 0xF8, "unknown-0xF8" },
4767   { 0xF9, "unknown-0xF9" },
4768   { 0xFA, "unknown-0xFA" },
4769   { 0xFB, "unknown-0xFB" },
4770   { 0xFC, "unknown-0xFC" },
4771   { 0xFD, "unknown-0xFD" },
4772   { 0xFE, "unknown-0xFE" },
4773   { 0xFF, "unknown-0xFF" },
4774   { 0x00, NULL },
4775 };
4776 static const char *decode_smb2_name(guint16 cmd)
4777 {
4778   if (cmd > 0xFF) return "unknown";
4779   return(smb2_cmd_vals[cmd & 0xFF].strptr);
4780 }
4781
4782 static smb2_function smb2_dissector[256] = {
4783   /* 0x00 NegotiateProtocol*/
4784         {dissect_smb2_negotiate_protocol_request,
4785          dissect_smb2_negotiate_protocol_response},
4786   /* 0x01 SessionSetup*/
4787         {dissect_smb2_session_setup_request,
4788          dissect_smb2_session_setup_response},
4789   /* 0x02 SessionLogoff*/
4790         {dissect_smb2_sessionlogoff_request,
4791          dissect_smb2_sessionlogoff_response},
4792   /* 0x03 TreeConnect*/
4793         {dissect_smb2_tree_connect_request,
4794          dissect_smb2_tree_connect_response},
4795   /* 0x04 TreeDisconnect*/
4796         {dissect_smb2_tree_disconnect_request,
4797          dissect_smb2_tree_disconnect_response},
4798   /* 0x05 Create*/
4799         {dissect_smb2_create_request,
4800          dissect_smb2_create_response},
4801   /* 0x06 Close*/
4802         {dissect_smb2_close_request,
4803          dissect_smb2_close_response},
4804   /* 0x07 Flush*/
4805         {dissect_smb2_flush_request,
4806          dissect_smb2_flush_response},
4807   /* 0x08 Read*/
4808         {dissect_smb2_read_request,
4809          dissect_smb2_read_response},
4810   /* 0x09 Writew*/
4811         {dissect_smb2_write_request,
4812          dissect_smb2_write_response},
4813   /* 0x0a Lock */
4814         {dissect_smb2_lock_request,
4815          dissect_smb2_lock_response},
4816   /* 0x0b Ioctl*/
4817         {dissect_smb2_ioctl_request,
4818          dissect_smb2_ioctl_response},
4819   /* 0x0c Cancel*/
4820         {dissect_smb2_cancel_request,
4821          NULL},
4822   /* 0x0d KeepAlive*/
4823         {dissect_smb2_keepalive_request,
4824          dissect_smb2_keepalive_response},
4825   /* 0x0e Find*/
4826         {dissect_smb2_find_request,
4827          dissect_smb2_find_response},
4828   /* 0x0f Notify*/
4829         {dissect_smb2_notify_request,
4830          dissect_smb2_notify_response},
4831   /* 0x10 GetInfo*/
4832         {dissect_smb2_getinfo_request,
4833          dissect_smb2_getinfo_response},
4834   /* 0x11 SetInfo*/
4835         {dissect_smb2_setinfo_request,
4836          dissect_smb2_setinfo_response},
4837   /* 0x12 Break */
4838         {dissect_smb2_break_request,
4839          dissect_smb2_break_response},
4840   /* 0x13 */  {NULL, NULL},
4841   /* 0x14 */  {NULL, NULL},
4842   /* 0x15 */  {NULL, NULL},
4843   /* 0x16 */  {NULL, NULL},
4844   /* 0x17 */  {NULL, NULL},
4845   /* 0x18 */  {NULL, NULL},
4846   /* 0x19 */  {NULL, NULL},
4847   /* 0x1a */  {NULL, NULL},
4848   /* 0x1b */  {NULL, NULL},
4849   /* 0x1c */  {NULL, NULL},
4850   /* 0x1d */  {NULL, NULL},
4851   /* 0x1e */  {NULL, NULL},
4852   /* 0x1f */  {NULL, NULL},
4853   /* 0x20 */  {NULL, NULL},
4854   /* 0x21 */  {NULL, NULL},
4855   /* 0x22 */  {NULL, NULL},
4856   /* 0x23 */  {NULL, NULL},
4857   /* 0x24 */  {NULL, NULL},
4858   /* 0x25 */  {NULL, NULL},
4859   /* 0x26 */  {NULL, NULL},
4860   /* 0x27 */  {NULL, NULL},
4861   /* 0x28 */  {NULL, NULL},
4862   /* 0x29 */  {NULL, NULL},
4863   /* 0x2a */  {NULL, NULL},
4864   /* 0x2b */  {NULL, NULL},
4865   /* 0x2c */  {NULL, NULL},
4866   /* 0x2d */  {NULL, NULL},
4867   /* 0x2e */  {NULL, NULL},
4868   /* 0x2f */  {NULL, NULL},
4869   /* 0x30 */  {NULL, NULL},
4870   /* 0x31 */  {NULL, NULL},
4871   /* 0x32 */  {NULL, NULL},
4872   /* 0x33 */  {NULL, NULL},
4873   /* 0x34 */  {NULL, NULL},
4874   /* 0x35 */  {NULL, NULL},
4875   /* 0x36 */  {NULL, NULL},
4876   /* 0x37 */  {NULL, NULL},
4877   /* 0x38 */  {NULL, NULL},
4878   /* 0x39 */  {NULL, NULL},
4879   /* 0x3a */  {NULL, NULL},
4880   /* 0x3b */  {NULL, NULL},
4881   /* 0x3c */  {NULL, NULL},
4882   /* 0x3d */  {NULL, NULL},
4883   /* 0x3e */  {NULL, NULL},
4884   /* 0x3f */  {NULL, NULL},
4885   /* 0x40 */  {NULL, NULL},
4886   /* 0x41 */  {NULL, NULL},
4887   /* 0x42 */  {NULL, NULL},
4888   /* 0x43 */  {NULL, NULL},
4889   /* 0x44 */  {NULL, NULL},
4890   /* 0x45 */  {NULL, NULL},
4891   /* 0x46 */  {NULL, NULL},
4892   /* 0x47 */  {NULL, NULL},
4893   /* 0x48 */  {NULL, NULL},
4894   /* 0x49 */  {NULL, NULL},
4895   /* 0x4a */  {NULL, NULL},
4896   /* 0x4b */  {NULL, NULL},
4897   /* 0x4c */  {NULL, NULL},
4898   /* 0x4d */  {NULL, NULL},
4899   /* 0x4e */  {NULL, NULL},
4900   /* 0x4f */  {NULL, NULL},
4901   /* 0x50 */  {NULL, NULL},
4902   /* 0x51 */  {NULL, NULL},
4903   /* 0x52 */  {NULL, NULL},
4904   /* 0x53 */  {NULL, NULL},
4905   /* 0x54 */  {NULL, NULL},
4906   /* 0x55 */  {NULL, NULL},
4907   /* 0x56 */  {NULL, NULL},
4908   /* 0x57 */  {NULL, NULL},
4909   /* 0x58 */  {NULL, NULL},
4910   /* 0x59 */  {NULL, NULL},
4911   /* 0x5a */  {NULL, NULL},
4912   /* 0x5b */  {NULL, NULL},
4913   /* 0x5c */  {NULL, NULL},
4914   /* 0x5d */  {NULL, NULL},
4915   /* 0x5e */  {NULL, NULL},
4916   /* 0x5f */  {NULL, NULL},
4917   /* 0x60 */  {NULL, NULL},
4918   /* 0x61 */  {NULL, NULL},
4919   /* 0x62 */  {NULL, NULL},
4920   /* 0x63 */  {NULL, NULL},
4921   /* 0x64 */  {NULL, NULL},
4922   /* 0x65 */  {NULL, NULL},
4923   /* 0x66 */  {NULL, NULL},
4924   /* 0x67 */  {NULL, NULL},
4925   /* 0x68 */  {NULL, NULL},
4926   /* 0x69 */  {NULL, NULL},
4927   /* 0x6a */  {NULL, NULL},
4928   /* 0x6b */  {NULL, NULL},
4929   /* 0x6c */  {NULL, NULL},
4930   /* 0x6d */  {NULL, NULL},
4931   /* 0x6e */  {NULL, NULL},
4932   /* 0x6f */  {NULL, NULL},
4933   /* 0x70 */  {NULL, NULL},
4934   /* 0x71 */  {NULL, NULL},
4935   /* 0x72 */  {NULL, NULL},
4936   /* 0x73 */  {NULL, NULL},
4937   /* 0x74 */  {NULL, NULL},
4938   /* 0x75 */  {NULL, NULL},
4939   /* 0x76 */  {NULL, NULL},
4940   /* 0x77 */  {NULL, NULL},
4941   /* 0x78 */  {NULL, NULL},
4942   /* 0x79 */  {NULL, NULL},
4943   /* 0x7a */  {NULL, NULL},
4944   /* 0x7b */  {NULL, NULL},
4945   /* 0x7c */  {NULL, NULL},
4946   /* 0x7d */  {NULL, NULL},
4947   /* 0x7e */  {NULL, NULL},
4948   /* 0x7f */  {NULL, NULL},
4949   /* 0x80 */  {NULL, NULL},
4950   /* 0x81 */  {NULL, NULL},
4951   /* 0x82 */  {NULL, NULL},
4952   /* 0x83 */  {NULL, NULL},
4953   /* 0x84 */  {NULL, NULL},
4954   /* 0x85 */  {NULL, NULL},
4955   /* 0x86 */  {NULL, NULL},
4956   /* 0x87 */  {NULL, NULL},
4957   /* 0x88 */  {NULL, NULL},
4958   /* 0x89 */  {NULL, NULL},
4959   /* 0x8a */  {NULL, NULL},
4960   /* 0x8b */  {NULL, NULL},
4961   /* 0x8c */  {NULL, NULL},
4962   /* 0x8d */  {NULL, NULL},
4963   /* 0x8e */  {NULL, NULL},
4964   /* 0x8f */  {NULL, NULL},
4965   /* 0x90 */  {NULL, NULL},
4966   /* 0x91 */  {NULL, NULL},
4967   /* 0x92 */  {NULL, NULL},
4968   /* 0x93 */  {NULL, NULL},
4969   /* 0x94 */  {NULL, NULL},
4970   /* 0x95 */  {NULL, NULL},
4971   /* 0x96 */  {NULL, NULL},
4972   /* 0x97 */  {NULL, NULL},
4973   /* 0x98 */  {NULL, NULL},
4974   /* 0x99 */  {NULL, NULL},
4975   /* 0x9a */  {NULL, NULL},
4976   /* 0x9b */  {NULL, NULL},
4977   /* 0x9c */  {NULL, NULL},
4978   /* 0x9d */  {NULL, NULL},
4979   /* 0x9e */  {NULL, NULL},
4980   /* 0x9f */  {NULL, NULL},
4981   /* 0xa0 */  {NULL, NULL},
4982   /* 0xa1 */  {NULL, NULL},
4983   /* 0xa2 */  {NULL, NULL},
4984   /* 0xa3 */  {NULL, NULL},
4985   /* 0xa4 */  {NULL, NULL},
4986   /* 0xa5 */  {NULL, NULL},
4987   /* 0xa6 */  {NULL, NULL},
4988   /* 0xa7 */  {NULL, NULL},
4989   /* 0xa8 */  {NULL, NULL},
4990   /* 0xa9 */  {NULL, NULL},
4991   /* 0xaa */  {NULL, NULL},
4992   /* 0xab */  {NULL, NULL},
4993   /* 0xac */  {NULL, NULL},
4994   /* 0xad */  {NULL, NULL},
4995   /* 0xae */  {NULL, NULL},
4996   /* 0xaf */  {NULL, NULL},
4997   /* 0xb0 */  {NULL, NULL},
4998   /* 0xb1 */  {NULL, NULL},
4999   /* 0xb2 */  {NULL, NULL},
5000   /* 0xb3 */  {NULL, NULL},
5001   /* 0xb4 */  {NULL, NULL},
5002   /* 0xb5 */  {NULL, NULL},
5003   /* 0xb6 */  {NULL, NULL},
5004   /* 0xb7 */  {NULL, NULL},
5005   /* 0xb8 */  {NULL, NULL},
5006   /* 0xb9 */  {NULL, NULL},
5007   /* 0xba */  {NULL, NULL},
5008   /* 0xbb */  {NULL, NULL},
5009   /* 0xbc */  {NULL, NULL},
5010   /* 0xbd */  {NULL, NULL},
5011   /* 0xbe */  {NULL, NULL},
5012   /* 0xbf */  {NULL, NULL},
5013   /* 0xc0 */  {NULL, NULL},
5014   /* 0xc1 */  {NULL, NULL},
5015   /* 0xc2 */  {NULL, NULL},
5016   /* 0xc3 */  {NULL, NULL},
5017   /* 0xc4 */  {NULL, NULL},
5018   /* 0xc5 */  {NULL, NULL},
5019   /* 0xc6 */  {NULL, NULL},
5020   /* 0xc7 */  {NULL, NULL},
5021   /* 0xc8 */  {NULL, NULL},
5022   /* 0xc9 */  {NULL, NULL},
5023   /* 0xca */  {NULL, NULL},
5024   /* 0xcb */  {NULL, NULL},
5025   /* 0xcc */  {NULL, NULL},
5026   /* 0xcd */  {NULL, NULL},
5027   /* 0xce */  {NULL, NULL},
5028   /* 0xcf */  {NULL, NULL},
5029   /* 0xd0 */  {NULL, NULL},
5030   /* 0xd1 */  {NULL, NULL},
5031   /* 0xd2 */  {NULL, NULL},
5032   /* 0xd3 */  {NULL, NULL},
5033   /* 0xd4 */  {NULL, NULL},
5034   /* 0xd5 */  {NULL, NULL},
5035   /* 0xd6 */  {NULL, NULL},
5036   /* 0xd7 */  {NULL, NULL},
5037   /* 0xd8 */  {NULL, NULL},
5038   /* 0xd9 */  {NULL, NULL},
5039   /* 0xda */  {NULL, NULL},
5040   /* 0xdb */  {NULL, NULL},
5041   /* 0xdc */  {NULL, NULL},
5042   /* 0xdd */  {NULL, NULL},
5043   /* 0xde */  {NULL, NULL},
5044   /* 0xdf */  {NULL, NULL},
5045   /* 0xe0 */  {NULL, NULL},
5046   /* 0xe1 */  {NULL, NULL},
5047   /* 0xe2 */  {NULL, NULL},
5048   /* 0xe3 */  {NULL, NULL},
5049   /* 0xe4 */  {NULL, NULL},
5050   /* 0xe5 */  {NULL, NULL},
5051   /* 0xe6 */  {NULL, NULL},
5052   /* 0xe7 */  {NULL, NULL},
5053   /* 0xe8 */  {NULL, NULL},
5054   /* 0xe9 */  {NULL, NULL},
5055   /* 0xea */  {NULL, NULL},
5056   /* 0xeb */  {NULL, NULL},
5057   /* 0xec */  {NULL, NULL},
5058   /* 0xed */  {NULL, NULL},
5059   /* 0xee */  {NULL, NULL},
5060   /* 0xef */  {NULL, NULL},
5061   /* 0xf0 */  {NULL, NULL},
5062   /* 0xf1 */  {NULL, NULL},
5063   /* 0xf2 */  {NULL, NULL},
5064   /* 0xf3 */  {NULL, NULL},
5065   /* 0xf4 */  {NULL, NULL},
5066   /* 0xf5 */  {NULL, NULL},
5067   /* 0xf6 */  {NULL, NULL},
5068   /* 0xf7 */  {NULL, NULL},
5069   /* 0xf8 */  {NULL, NULL},
5070   /* 0xf9 */  {NULL, NULL},
5071   /* 0xfa */  {NULL, NULL},
5072   /* 0xfb */  {NULL, NULL},
5073   /* 0xfc */  {NULL, NULL},
5074   /* 0xfd */  {NULL, NULL},
5075   /* 0xfe */  {NULL, NULL},
5076   /* 0xff */  {NULL, NULL},
5077 };
5078
5079
5080 static int
5081 dissect_smb2_command(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset, smb2_info_t *si)
5082 {
5083         int (*cmd_dissector)(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, smb2_info_t *si);
5084         proto_item *cmd_item;
5085         proto_tree *cmd_tree;
5086         int old_offset = offset;
5087
5088         cmd_item = proto_tree_add_text(tree, tvb, offset, -1,
5089                         "%s %s (0x%02x)",
5090                         decode_smb2_name(si->opcode),
5091                         (si->flags & SMB2_FLAGS_RESPONSE)?"Response":"Request",
5092                         si->opcode);
5093         cmd_tree = proto_item_add_subtree(cmd_item, ett_smb2_command);
5094
5095
5096         cmd_dissector=(si->flags & SMB2_FLAGS_RESPONSE)?
5097                 smb2_dissector[si->opcode&0xff].response:
5098                 smb2_dissector[si->opcode&0xff].request;
5099         if(cmd_dissector){
5100                 offset=(*cmd_dissector)(tvb, pinfo, cmd_tree, offset, si);
5101         } else {
5102                 proto_tree_add_item(cmd_tree, hf_smb2_unknown, tvb, offset, -1, FALSE);
5103                 offset=tvb_length(tvb);
5104         }
5105
5106         proto_item_set_len(cmd_item, offset-old_offset);
5107
5108         return offset;
5109 }
5110
5111 static int
5112 dissect_smb2_tid_sesid(packet_info *pinfo _U_, proto_tree *tree, tvbuff_t *tvb, int offset, smb2_info_t *si)
5113 {
5114         proto_item *tid_item=NULL;
5115         proto_tree *tid_tree=NULL;
5116         smb2_tid_info_t tid_key;
5117         int tid_offset = 0;
5118         proto_item *sesid_item=NULL;
5119         proto_tree *sesid_tree=NULL;
5120         smb2_sesid_info_t sesid_key;
5121         int sesid_offset;
5122         proto_item *item;
5123         unsigned int pid;
5124
5125
5126         if (si->flags&SMB2_FLAGS_ASYNC_CMD) {
5127                 proto_tree_add_item(tree, hf_smb2_aid, tvb, offset, 8, TRUE);
5128                 offset += 8;
5129         } else {
5130                 /* Process ID */
5131                 pid=tvb_get_letohl(tvb, offset);
5132                 proto_tree_add_uint_format(tree, hf_smb2_pid, tvb, offset, 4, pid, "Process Id: %08x",pid);
5133                 offset += 4;
5134
5135                 /* Tree ID */
5136                 tid_offset = offset;
5137                 si->tid=tvb_get_letohl(tvb, offset);
5138                 tid_item=proto_tree_add_item(tree, hf_smb2_tid, tvb, offset, 4, TRUE);
5139                 if(tree){
5140                         tid_tree=proto_item_add_subtree(tid_item, ett_smb2_tid_tree);
5141                 }
5142                 offset += 4;
5143         }
5144
5145         /* Session ID */
5146         sesid_offset = offset;
5147         si->sesid=tvb_get_letoh64(tvb, offset);
5148         sesid_item=proto_tree_add_item(tree, hf_smb2_sesid, tvb, offset, 8, TRUE);
5149         if(tree){
5150                 sesid_tree=proto_item_add_subtree(sesid_item, ett_smb2_sesid_tree);
5151         }
5152         offset += 8;
5153
5154         /* now we need to first lookup the uid session */
5155         sesid_key.sesid=si->sesid;
5156         si->session=g_hash_table_lookup(si->conv->sesids, &sesid_key);
5157         if(!si->session) {
5158                 if (si->opcode != 0x03) return offset;
5159
5160                 /* if we come to a session that is unknown, and the operation is
5161                  * a tree connect, we create a dummy sessison, so we can hang the
5162                  * tree data on it
5163                  */
5164                 si->session=se_alloc(sizeof(smb2_sesid_info_t));
5165                 si->session->sesid=si->sesid;
5166                 si->session->acct_name=NULL;
5167                 si->session->domain_name=NULL;
5168                 si->session->host_name=NULL;
5169                 si->session->auth_frame=(guint32)-1;
5170                 si->session->tids= g_hash_table_new(smb2_tid_info_hash, smb2_tid_info_equal);
5171                 g_hash_table_insert(si->conv->sesids, si->session, si->session);
5172
5173                 return offset;
5174         }
5175
5176         if (si->session->auth_frame != (guint32)-1) {
5177                 item=proto_tree_add_string(sesid_tree, hf_smb2_acct_name, tvb, sesid_offset, 0, si->session->acct_name);
5178                 PROTO_ITEM_SET_GENERATED(item);
5179                 proto_item_append_text(sesid_item, " Acct:%s", si->session->acct_name);
5180
5181                 item=proto_tree_add_string(sesid_tree, hf_smb2_domain_name, tvb, sesid_offset, 0, si->session->domain_name);
5182                 PROTO_ITEM_SET_GENERATED(item);
5183                 proto_item_append_text(sesid_item, " Domain:%s", si->session->domain_name);
5184
5185                 item=proto_tree_add_string(sesid_tree, hf_smb2_host_name, tvb, sesid_offset, 0, si->session->host_name);
5186                 PROTO_ITEM_SET_GENERATED(item);
5187                 proto_item_append_text(sesid_item, " Host:%s", si->session->host_name);
5188
5189                 item=proto_tree_add_uint(sesid_tree, hf_smb2_auth_frame, tvb, sesid_offset, 0, si->session->auth_frame);
5190                 PROTO_ITEM_SET_GENERATED(item);
5191         }
5192
5193         if (!(si->flags&SMB2_FLAGS_ASYNC_CMD)) {
5194                 /* see if we can find the name for this tid */
5195                 tid_key.tid=si->tid;
5196                 si->tree=g_hash_table_lookup(si->session->tids, &tid_key);
5197                 if(!si->tree) return offset;
5198
5199                 item=proto_tree_add_string(tid_tree, hf_smb2_tree, tvb, tid_offset, 4, si->tree->name);
5200                 PROTO_ITEM_SET_GENERATED(item);
5201                 proto_item_append_text(tid_item, "  %s", si->tree->name);
5202
5203                 item=proto_tree_add_uint(tid_tree, hf_smb2_share_type, tvb, tid_offset, 0, si->tree->share_type);
5204                 PROTO_ITEM_SET_GENERATED(item);
5205         
5206                 item=proto_tree_add_uint(tid_tree, hf_smb2_tcon_frame, tvb, tid_offset, 0, si->tree->connect_frame);
5207                 PROTO_ITEM_SET_GENERATED(item);
5208         }
5209
5210         return offset;
5211 }
5212
5213 static int
5214 dissect_smb2(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, gboolean first_in_chain)
5215 {
5216         proto_item *seqnum_item;
5217         proto_item *item=NULL;
5218         proto_tree *tree=NULL;
5219         proto_item *header_item=NULL;
5220         proto_tree *header_tree=NULL;
5221         proto_item *flags_item=NULL;
5222         proto_tree *flags_tree=NULL;
5223         int offset = 0;
5224         int chain_offset = 0;
5225         guint16 header_len;
5226         conversation_t *conversation;
5227         smb2_saved_info_t *ssi=NULL, ssi_key;
5228         smb2_info_t *si;
5229
5230         si=ep_alloc(sizeof(smb2_info_t));
5231         si->conv=NULL;
5232         si->saved=NULL;
5233         si->tree=NULL;
5234         si->top_tree=parent_tree;
5235
5236         /* find which conversation we are part of and get the data for that
5237          * conversation
5238          */
5239         conversation = find_conversation(pinfo->fd->num, &pinfo->src, &pinfo->dst, pinfo->ptype,  pinfo->srcport, pinfo->destport, 0);
5240         if(!conversation){
5241                 /* OK this is a new conversation so lets create it */
5242                 conversation = conversation_new(pinfo->fd->num, &pinfo->src, &pinfo->dst,
5243                         pinfo->ptype, pinfo->srcport, pinfo->destport, 0);
5244         }
5245         si->conv=conversation_get_proto_data(conversation, proto_smb2);
5246         if(!si->conv){
5247                 /* no smb2_into_t structure for this conversation yet,
5248                  * create it.
5249                  */
5250                 si->conv=se_alloc(sizeof(smb2_conv_info_t));
5251                 /* qqq this leaks memory for now since we never free
5252                    the hashtables */
5253                 si->conv->matched= g_hash_table_new(smb2_saved_info_hash_matched,
5254                         smb2_saved_info_equal_matched);
5255                 si->conv->unmatched= g_hash_table_new(smb2_saved_info_hash_unmatched,
5256                         smb2_saved_info_equal_unmatched);
5257                 si->conv->sesids= g_hash_table_new(smb2_sesid_info_hash,
5258                         smb2_sesid_info_equal);
5259
5260                 conversation_add_proto_data(conversation, proto_smb2, si->conv);
5261         }
5262
5263
5264         col_set_str(pinfo->cinfo, COL_PROTOCOL, "SMB2");
5265         if (check_col(pinfo->cinfo, COL_INFO)){
5266                 if (first_in_chain) {
5267                         /* first packet */
5268                         col_clear(pinfo->cinfo, COL_INFO);
5269                 } else {
5270                         col_append_str(pinfo->cinfo, COL_INFO, ";");
5271                 }
5272         }
5273
5274         if (parent_tree) {
5275                 item = proto_tree_add_item(parent_tree, proto_smb2, tvb, offset,
5276                         -1, FALSE);
5277                 tree = proto_item_add_subtree(item, ett_smb2);
5278         }
5279
5280
5281         if (tree) {
5282                 header_item = proto_tree_add_text(tree, tvb, offset, -1, "SMB2 Header");
5283                 header_tree = proto_item_add_subtree(header_item, ett_smb2_header);
5284         }
5285
5286         /* Decode the header */
5287         /* SMB2 marker */
5288         proto_tree_add_text(header_tree, tvb, offset, 4, "Server Component: SMB2");
5289         offset += 4;
5290
5291         /* header length */
5292         header_len=tvb_get_letohs(tvb, offset);
5293         proto_tree_add_item(header_tree, hf_smb2_header_len, tvb, offset, 2, TRUE);
5294         offset += 2;
5295
5296         /* epoch */
5297         proto_tree_add_item(header_tree, hf_smb2_epoch, tvb, offset, 2, TRUE);
5298         offset += 2;
5299
5300         /* Status Code */
5301         si->status=tvb_get_letohl(tvb, offset);
5302         proto_tree_add_item(header_tree, hf_smb2_nt_status, tvb, offset, 4, TRUE);
5303         offset += 4;
5304
5305
5306         /* opcode */
5307         si->opcode=tvb_get_letohs(tvb, offset);
5308         proto_tree_add_item(header_tree, hf_smb2_cmd, tvb, offset, 2, TRUE);
5309         offset += 2;
5310
5311         /* we need the flags before we know how to parse the credits field */
5312         si->flags=tvb_get_letohl(tvb, offset+2);
5313
5314         /* credits */
5315         if (si->flags & SMB2_FLAGS_RESPONSE) {
5316                 proto_tree_add_item(header_tree, hf_smb2_credits_granted, tvb, offset, 2, TRUE);
5317         } else {
5318                 proto_tree_add_item(header_tree, hf_smb2_credits_requested, tvb, offset, 2, TRUE);
5319         }
5320         offset += 2;
5321
5322         /* flags */
5323         if(header_tree){
5324                 flags_item = proto_tree_add_text(header_tree, tvb, offset, 4,
5325                         "Flags: 0x%08x", si->flags);
5326                 flags_tree = proto_item_add_subtree(flags_item, ett_smb2_flags);
5327         }
5328         proto_tree_add_boolean(flags_tree, hf_smb2_flags_dfs_op, tvb, offset, 4, si->flags);
5329         proto_tree_add_boolean(flags_tree, hf_smb2_flags_signature, tvb, offset, 4, si->flags);
5330         proto_tree_add_boolean(flags_tree, hf_smb2_flags_chained, tvb, offset, 4, si->flags);
5331         proto_tree_add_boolean(flags_tree, hf_smb2_flags_async_cmd, tvb, offset, 4, si->flags);
5332         proto_tree_add_boolean(flags_tree, hf_smb2_flags_response, tvb, offset, 4, si->flags);
5333
5334         offset += 4;
5335
5336         /* some unknown bytes */
5337         chain_offset=tvb_get_letohl(tvb, offset);
5338         proto_tree_add_item(header_tree, hf_smb2_chain_offset, tvb, offset, 4, FALSE);
5339         offset += 4;
5340
5341         /* command sequence number*/
5342         si->seqnum=tvb_get_letoh64(tvb, offset);
5343         ssi_key.seqnum=si->seqnum;
5344         seqnum_item=proto_tree_add_item(header_tree, hf_smb2_seqnum, tvb, offset, 8, TRUE);
5345         if(seqnum_item && (si->seqnum==-1)){
5346                 proto_item_append_text(seqnum_item, " (unsolicited response)");
5347         }
5348         offset += 8;
5349
5350         /* Tree ID and Session ID */
5351         offset = dissect_smb2_tid_sesid(pinfo, header_tree, tvb, offset, si);
5352
5353         /* Signature */
5354         proto_tree_add_item(header_tree, hf_smb2_signature, tvb, offset, 16, FALSE);
5355         offset += 16;
5356
5357         proto_item_set_len(header_item, offset);
5358
5359
5360         if (check_col(pinfo->cinfo, COL_INFO)){
5361                 col_append_fstr(pinfo->cinfo, COL_INFO, "%s %s",
5362                         decode_smb2_name(si->opcode),
5363                         (si->flags & SMB2_FLAGS_RESPONSE)?"Response":"Request");
5364                 if(si->status){
5365                         col_append_fstr(
5366                                 pinfo->cinfo, COL_INFO, ", Error: %s",
5367                                 val_to_str(si->status, NT_errors,
5368                                 "Unknown (0x%08X)"));
5369                 }
5370         }
5371
5372
5373         if(!pinfo->fd->flags.visited){
5374                 /* see if we can find this seqnum in the unmatched table */
5375                 ssi=g_hash_table_lookup(si->conv->unmatched, &ssi_key);
5376
5377                 if(!(si->flags & SMB2_FLAGS_RESPONSE)){
5378                         /* This is a request */
5379                         if(ssi){
5380                                 /* this is a request and we already found
5381                                  * an older ssi so just delete the previous
5382                                  * one
5383                                  */
5384                                 g_hash_table_remove(si->conv->unmatched, ssi);
5385                                 ssi=NULL;
5386                         }
5387
5388                         if(!ssi){
5389                                 /* no we couldnt find it, so just add it then
5390                                  * if was a request we are decoding
5391                                  */
5392                                 ssi=se_alloc(sizeof(smb2_saved_info_t));
5393                                 ssi->class=0;
5394                                 ssi->infolevel=0;
5395                                 ssi->seqnum=ssi_key.seqnum;
5396                                 ssi->frame_req=pinfo->fd->num;
5397                                 ssi->frame_res=0;
5398                                 ssi->req_time=pinfo->fd->abs_ts;
5399                                 ssi->extra_info=NULL;
5400                                 ssi->extra_info_type=SMB2_EI_NONE;
5401                                 g_hash_table_insert(si->conv->unmatched, ssi, ssi);
5402                         }
5403                 } else {
5404                         /* This is a response */
5405                         if(ssi){
5406                                 /* just  set the response frame and move it to the matched table */
5407                                 ssi->frame_res=pinfo->fd->num;
5408                                 g_hash_table_remove(si->conv->unmatched, ssi);
5409                                 g_hash_table_insert(si->conv->matched, ssi, ssi);
5410                         }
5411                 }
5412         } else {
5413                 /* see if we can find this seqnum in the matched table */
5414                 ssi=g_hash_table_lookup(si->conv->matched, &ssi_key);
5415                 /* if we couldnt find it in the matched table, it might still
5416                  * be in the unmatched table
5417                  */
5418                 if(!ssi){
5419                         ssi=g_hash_table_lookup(si->conv->unmatched, &ssi_key);
5420                 }
5421         }
5422
5423         if(ssi){
5424                 if(!(si->flags & SMB2_FLAGS_RESPONSE)){
5425                         if(ssi->frame_res){
5426                                 proto_item *tmp_item;
5427                                 tmp_item=proto_tree_add_uint(header_tree, hf_smb2_response_in, tvb, 0, 0, ssi->frame_res);
5428                                 PROTO_ITEM_SET_GENERATED(tmp_item);
5429                         }
5430                 } else {
5431                         if(ssi->frame_req){
5432                                 proto_item *tmp_item;
5433                                 nstime_t t, deltat;
5434
5435                                 tmp_item=proto_tree_add_uint(header_tree, hf_smb2_response_to, tvb, 0, 0, ssi->frame_req);
5436                                 PROTO_ITEM_SET_GENERATED(tmp_item);
5437                                 t = pinfo->fd->abs_ts;
5438                                 nstime_delta(&deltat, &t, &ssi->req_time);
5439                                 tmp_item=proto_tree_add_time(header_tree, hf_smb2_time, tvb,
5440                                     0, 0, &deltat);
5441                                 PROTO_ITEM_SET_GENERATED(tmp_item);
5442                         }
5443                 }
5444         }
5445         /* if we dont have ssi yet we must fake it */
5446         /*qqq*/
5447         si->saved=ssi;
5448
5449         tap_queue_packet(smb2_tap, pinfo, si);
5450
5451         /* Decode the payload */
5452         offset = dissect_smb2_command(pinfo, tree, tvb, offset, si);
5453
5454         if (chain_offset > 0) {
5455                 tvbuff_t *next_tvb;
5456
5457                 if (chain_offset < offset) {
5458                         THROW(ReportedBoundsError);
5459                 }
5460                 proto_item_set_len(item, chain_offset);
5461
5462                 next_tvb = tvb_new_subset_remaining(tvb, chain_offset);
5463                 offset = dissect_smb2(next_tvb, pinfo, parent_tree, FALSE);
5464         }
5465
5466         return offset;
5467 }
5468
5469 static gboolean
5470 dissect_smb2_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
5471 {
5472         int offset = 0;
5473
5474         /* must check that this really is a smb2 packet */
5475         if (tvb_length(tvb) < 4)
5476                 return FALSE;
5477
5478         if( (tvb_get_guint8(tvb, 0) != 0xfe)
5479             || (tvb_get_guint8(tvb, 1) != 'S')
5480             || (tvb_get_guint8(tvb, 2) != 'M')
5481             || (tvb_get_guint8(tvb, 3) != 'B') ){
5482                 return FALSE;
5483         }
5484
5485         offset = dissect_smb2(tvb, pinfo, parent_tree, TRUE);
5486
5487         return TRUE;
5488 }
5489
5490 void
5491 proto_register_smb2(void)
5492 {
5493         static hf_register_info hf[] = {
5494         { &hf_smb2_cmd,
5495                 { "Command", "smb2.cmd", FT_UINT16, BASE_DEC,
5496                 VALS(smb2_cmd_vals), 0, "SMB2 Command Opcode", HFILL }},
5497         { &hf_smb2_response_to,
5498                 { "Response to", "smb2.response_to", FT_FRAMENUM, BASE_NONE,
5499                 NULL, 0, "This packet is a response to the packet in this frame", HFILL }},
5500         { &hf_smb2_response_in,
5501                 { "Response in", "smb2.response_in", FT_FRAMENUM, BASE_NONE,
5502                 NULL, 0, "The response to this packet is in this packet", HFILL }},
5503         { &hf_smb2_time,
5504                 { "Time from request", "smb2.time", FT_RELATIVE_TIME, BASE_NONE,
5505                 NULL, 0, "Time between Request and Response for SMB2 cmds", HFILL }},
5506         { &hf_smb2_header_len,
5507                 { "Header Length", "smb2.header_len", FT_UINT16, BASE_DEC,
5508                 NULL, 0, "SMB2 Size of Header", HFILL }},
5509         { &hf_smb2_nt_status,
5510                 { "NT Status", "smb2.nt_status", FT_UINT32, BASE_HEX,
5511                 VALS(NT_errors), 0, "NT Status code", HFILL }},
5512         { &hf_smb2_seqnum,
5513                 { "Command Sequence Number", "smb2.seq_num", FT_INT64, BASE_DEC,
5514                 NULL, 0, "SMB2 Command Sequence Number", HFILL }},
5515         { &hf_smb2_tid,
5516                 { "Tree Id", "smb2.tid", FT_UINT32, BASE_HEX,
5517                 NULL, 0, "SMB2 Tree Id", HFILL }},
5518         { &hf_smb2_aid,
5519                 { "Async Id", "smb2.aid", FT_UINT64, BASE_HEX,
5520                 NULL, 0, "SMB2 Async Id", HFILL }},
5521         { &hf_smb2_sesid,
5522                 { "Session Id", "smb2.sesid", FT_UINT64, BASE_HEX,
5523                 NULL, 0, "SMB2 Session Id", HFILL }},
5524         { &hf_smb2_previous_sesid,
5525                 { "Previous Session Id", "smb2.previous_sesid", FT_UINT64, BASE_HEX,
5526                 NULL, 0, "SMB2 Previous Session Id", HFILL }},
5527         { &hf_smb2_chain_offset,
5528                 { "Chain Offset", "smb2.chain_offset", FT_UINT32, BASE_HEX,
5529                 NULL, 0, "SMB2 Chain Offset", HFILL }},
5530         { &hf_smb2_end_of_file,
5531                 { "End Of File", "smb2.eof", FT_UINT64, BASE_DEC,
5532                 NULL, 0, "SMB2 End Of File/File size", HFILL }},
5533         { &hf_smb2_nlinks,
5534                 { "Number of Links", "smb2.nlinks", FT_UINT32, BASE_DEC,
5535                 NULL, 0, "Number of links to this object", HFILL }},
5536         { &hf_smb2_file_id,
5537                 { "File Id", "smb2.file_id", FT_UINT64, BASE_HEX,
5538                 NULL, 0, "SMB2 File Id", HFILL }},
5539         { &hf_smb2_allocation_size,
5540                 { "Allocation Size", "smb2.allocation_size", FT_UINT64, BASE_DEC,
5541                 NULL, 0, "SMB2 Allocation Size for this object", HFILL }},
5542         { &hf_smb2_max_response_size,
5543                 { "Max Response Size", "smb2.max_response_size", FT_UINT32, BASE_DEC,
5544                 NULL, 0, "SMB2 Maximum response size", HFILL }},
5545         { &hf_smb2_setinfo_size,
5546                 { "Setinfo Size", "smb2.setinfo_size", FT_UINT32, BASE_DEC,
5547                 NULL, 0, "SMB2 setinfo size", HFILL }},
5548         { &hf_smb2_setinfo_offset,
5549                 { "Setinfo Offset", "smb2.setinfo_offset", FT_UINT16, BASE_HEX,
5550                 NULL, 0, "SMB2 setinfo offset", HFILL }},
5551         { &hf_smb2_max_ioctl_out_size,
5552                 { "Max Ioctl Out Size", "smb2.max_ioctl_out_size", FT_UINT32, BASE_DEC,
5553                 NULL, 0, "SMB2 Maximum ioctl out size", HFILL }},
5554         { &hf_smb2_max_ioctl_in_size,
5555                 { "Max Ioctl In Size", "smb2.max_ioctl_in_size", FT_UINT32, BASE_DEC,
5556                 NULL, 0, "SMB2 Maximum ioctl out size", HFILL }},
5557         { &hf_smb2_response_size,
5558                 { "Response Size", "smb2.response_size", FT_UINT32, BASE_DEC,
5559                 NULL, 0, "SMB2 response size", HFILL }},
5560         { &hf_smb2_required_buffer_size,
5561                 { "Required Buffer Size", "smb2.required_size", FT_UINT32, BASE_DEC,
5562                 NULL, 0, "SMB2 required buffer size", HFILL }},
5563         { &hf_smb2_pid,
5564                 { "Process Id", "smb2.pid", FT_UINT32, BASE_HEX,
5565                 NULL, 0, "SMB2 Process Id", HFILL }},
5566         { &hf_smb2_flags_response,
5567                 { "Response", "smb2.flags.response", FT_BOOLEAN, 32,
5568                 TFS(&tfs_flags_response), SMB2_FLAGS_RESPONSE, "Whether this is an SMB2 Request or Response", HFILL }},
5569         { &hf_smb2_flags_async_cmd,
5570                 { "Async command", "smb2.flags.async", FT_BOOLEAN, 32,
5571                 TFS(&tfs_flags_async_cmd), SMB2_FLAGS_ASYNC_CMD, NULL, HFILL }},
5572         { &hf_smb2_flags_dfs_op,
5573                 { "DFS operation", "smb2.flags.dfs", FT_BOOLEAN, 32,
5574                 TFS(&tfs_flags_dfs_op), SMB2_FLAGS_DFS_OP, NULL, HFILL }},
5575         { &hf_smb2_flags_chained,
5576                 { "Chained", "smb2.flags.chained", FT_BOOLEAN, 32,
5577                 TFS(&tfs_flags_chained), SMB2_FLAGS_CHAINED, "Whether the pdu continues a chain or not", HFILL }},
5578         { &hf_smb2_flags_signature,
5579                 { "Signing", "smb2.flags.signature", FT_BOOLEAN, 32,
5580                 TFS(&tfs_flags_signature), SMB2_FLAGS_SIGNATURE, "Whether the pdu is signed or not", HFILL }},
5581         { &hf_smb2_tree,
5582                 { "Tree", "smb2.tree", FT_STRING, BASE_NONE,
5583                 NULL, 0, "Name of the Tree/Share", HFILL }},
5584         { &hf_smb2_filename,
5585                 { "Filename", "smb2.filename", FT_STRING, BASE_NONE,
5586                 NULL, 0, "Name of the file", HFILL }},
5587         { &hf_smb2_filename_len,
5588                 { "Filename Length", "smb2.filename.len", FT_UINT32, BASE_DEC,
5589                 NULL, 0, "Length of the file name", HFILL }},
5590
5591         { &hf_smb2_security_blob_len,
5592                 { "Security Blob Length", "smb2.security_blob_len", FT_UINT16, BASE_DEC,
5593                 NULL, 0, "Security blob length", HFILL }},
5594
5595         { &hf_smb2_security_blob_offset,
5596                 { "Security Blob Offset", "smb2.security_blob_offset", FT_UINT16, BASE_HEX,
5597                 NULL, 0, "Offset into the SMB2 PDU of the blob", HFILL }},
5598
5599         { &hf_smb2_response_buffer_offset,
5600                 { "Response Buffer Offset", "smb2.response_buffer_offset", FT_UINT16, BASE_HEX,
5601                 NULL, 0, "Offset of the response buffer", HFILL }},
5602
5603         { &hf_smb2_data_offset,
5604                 { "Data Offset", "smb2.data_offset", FT_UINT16, BASE_HEX,
5605                 NULL, 0, "Offset to data", HFILL }},
5606
5607         { &hf_smb2_find_info_level,
5608                 { "Info Level", "smb2.find.infolevel", FT_UINT32, BASE_DEC,
5609                 VALS(smb2_find_info_levels), 0, "Find_Info Infolevel", HFILL }},
5610         { &hf_smb2_find_flags,
5611                 { "Find Flags", "smb2.find.flags", FT_UINT8, BASE_HEX,
5612                 NULL, 0, NULL, HFILL }},
5613
5614         { &hf_smb2_find_pattern,
5615                 { "Search Pattern", "smb2.find.pattern", FT_STRING, BASE_NONE,
5616                 NULL, 0, "Find pattern", HFILL }},
5617
5618         { &hf_smb2_find_info_blob,
5619                 { "Info", "smb2.security_blob", FT_BYTES, BASE_NONE,
5620                 NULL, 0, "Find Info", HFILL }},
5621
5622         { &hf_smb2_ea_size,
5623                 { "EA Size", "smb2.ea_size", FT_UINT32, BASE_DEC,
5624                 NULL, 0, "Size of EA data", HFILL }},
5625
5626         { &hf_smb2_class,
5627                 { "Class", "smb2.class", FT_UINT8, BASE_HEX,
5628                 VALS(smb2_class_vals), 0, "Info class", HFILL }},
5629
5630         { &hf_smb2_infolevel,
5631                 { "InfoLevel", "smb2.infolevel", FT_UINT8, BASE_HEX,
5632                 NULL, 0, "Infolevel", HFILL }},
5633
5634         { &hf_smb2_infolevel_file_info,
5635                 { "InfoLevel", "smb2.file_info.infolevel", FT_UINT8, BASE_HEX,
5636                 VALS(smb2_file_info_levels), 0, "File_Info Infolevel", HFILL }},
5637
5638         { &hf_smb2_infolevel_fs_info,
5639                 { "InfoLevel", "smb2.fs_info.infolevel", FT_UINT8, BASE_HEX,
5640                 VALS(smb2_fs_info_levels), 0, "Fs_Info Infolevel", HFILL }},
5641
5642         { &hf_smb2_infolevel_sec_info,
5643                 { "InfoLevel", "smb2.sec_info.infolevel", FT_UINT8, BASE_HEX,
5644                 VALS(smb2_sec_info_levels), 0, "Sec_Info Infolevel", HFILL }},
5645
5646         { &hf_smb2_write_length,
5647                 { "Write Length", "smb2.write_length", FT_UINT32, BASE_DEC,
5648                 NULL, 0, "Amount of data to write", HFILL }},
5649
5650         { &hf_smb2_read_length,
5651                 { "Read Length", "smb2.read_length", FT_UINT32, BASE_DEC,
5652                 NULL, 0, "Amount of data to read", HFILL }},
5653
5654         { &hf_smb2_read_remaining,
5655                 { "Read Remaining", "smb2.read_remaining", FT_UINT32, BASE_DEC,
5656                 NULL, 0, NULL, HFILL }},
5657
5658         { &hf_smb2_create_flags,
5659                 { "Create Flags", "smb2.create_flags", FT_UINT64, BASE_HEX,
5660                 NULL, 0, NULL, HFILL }},
5661
5662         { &hf_smb2_file_offset,
5663                 { "File Offset", "smb2.file_offset", FT_UINT64, BASE_DEC,
5664                 NULL, 0, NULL, HFILL }},
5665
5666         { &hf_smb2_security_blob,
5667                 { "Security Blob", "smb2.security_blob", FT_BYTES, BASE_NONE,
5668                 NULL, 0, "Security blob", HFILL }},
5669
5670         { &hf_smb2_ioctl_out_data,
5671                 { "Out Data", "smb2.ioctl.out", FT_NONE, BASE_NONE,
5672                 NULL, 0, "Ioctl Out", HFILL }},
5673
5674         { &hf_smb2_ioctl_in_data,
5675                 { "In Data", "smb2.ioctl.in", FT_NONE, BASE_NONE,
5676                 NULL, 0, "Ioctl In", HFILL }},
5677
5678         { &hf_smb2_server_guid,
5679           { "Server Guid", "smb2.server_guid", FT_GUID, BASE_NONE,
5680                 NULL, 0, "Server GUID", HFILL }},
5681
5682         { &hf_smb2_client_guid,
5683           { "Client Guid", "smb2.client_guid", FT_GUID, BASE_NONE,
5684                 NULL, 0, "Client GUID", HFILL }},
5685
5686         { &hf_smb2_object_id,
5687           { "ObjectId", "smb2.object_id", FT_GUID, BASE_NONE,
5688                 NULL, 0, "ObjectID for this FID", HFILL }},
5689
5690         { &hf_smb2_birth_volume_id,
5691           { "BirthVolumeId", "smb2.birth_volume_id", FT_GUID, BASE_NONE,
5692                 NULL, 0, "ObjectID for the volume where this FID was originally created", HFILL }},
5693
5694         { &hf_smb2_birth_object_id,
5695           { "BirthObjectId", "smb2.birth_object_id", FT_GUID, BASE_NONE,
5696                 NULL, 0, "ObjectID for this FID when it was originally created", HFILL }},
5697
5698         { &hf_smb2_domain_id,
5699           { "DomainId", "smb2.domain_id", FT_GUID, BASE_NONE,
5700                 NULL, 0, NULL, HFILL }},
5701
5702         { &hf_smb2_create_timestamp,
5703                 { "Create", "smb2.create.time", FT_ABSOLUTE_TIME, BASE_NONE,
5704                 NULL, 0, "Time when this object was created", HFILL }},
5705
5706         { &hf_smb2_fid,
5707                 { "File Id", "smb2.fid", FT_GUID, BASE_NONE,
5708                 NULL, 0, "SMB2 File Id", HFILL }},
5709
5710         { &hf_smb2_write_data,
5711                 { "Write Data", "smb2.write_data", FT_BYTES, BASE_NONE,
5712                 NULL, 0, "SMB2 Data to be written", HFILL }},
5713
5714         { &hf_smb2_read_data,
5715                 { "Read Data", "smb2.read_data", FT_BYTES, BASE_NONE,
5716                 NULL, 0, "SMB2 Data that is read", HFILL }},
5717
5718         { &hf_smb2_last_access_timestamp,
5719                 { "Last Access", "smb2.last_access.time", FT_ABSOLUTE_TIME, BASE_NONE,
5720                 NULL, 0, "Time when this object was last accessed", HFILL }},
5721
5722         { &hf_smb2_last_write_timestamp,
5723                 { "Last Write", "smb2.last_write.time", FT_ABSOLUTE_TIME, BASE_NONE,
5724                 NULL, 0, "Time when this object was last written to", HFILL }},
5725
5726         { &hf_smb2_last_change_timestamp,
5727                 { "Last Change", "smb2.last_change.time", FT_ABSOLUTE_TIME, BASE_NONE,
5728                 NULL, 0, "Time when this object was last changed", HFILL }},
5729
5730         { &hf_smb2_file_all_info,
5731                 { "SMB2_FILE_ALL_INFO", "smb2.smb2_file_all_info", FT_NONE, BASE_NONE,
5732                 NULL, 0, "SMB2_FILE_ALL_INFO structure", HFILL }},
5733
5734         { &hf_smb2_file_allocation_info,
5735                 { "SMB2_FILE_ALLOCATION_INFO", "smb2.smb2_file_allocation_info", FT_NONE, BASE_NONE,
5736                 NULL, 0, "SMB2_FILE_ALLOCATION_INFO structure", HFILL }},
5737
5738         { &hf_smb2_file_endoffile_info,
5739                 { "SMB2_FILE_ENDOFFILE_INFO", "smb2.smb2_file_endoffile_info", FT_NONE, BASE_NONE,
5740                 NULL, 0, "SMB2_FILE_ENDOFFILE_INFO structure", HFILL }},
5741
5742         { &hf_smb2_file_alternate_name_info,
5743                 { "SMB2_FILE_ALTERNATE_NAME_INFO", "smb2.smb2_file_alternate_name_info", FT_NONE, BASE_NONE,
5744                 NULL, 0, "SMB2_FILE_ALTERNATE_NAME_INFO structure", HFILL }},
5745
5746         { &hf_smb2_file_stream_info,
5747                 { "SMB2_FILE_STREAM_INFO", "smb2.smb2_file_stream_info", FT_NONE, BASE_NONE,
5748                 NULL, 0, "SMB2_FILE_STREAM_INFO structure", HFILL }},
5749
5750         { &hf_smb2_file_pipe_info,
5751                 { "SMB2_FILE_PIPE_INFO", "smb2.smb2_file_pipe_info", FT_NONE, BASE_NONE,
5752                 NULL, 0, "SMB2_FILE_PIPE_INFO structure", HFILL }},
5753
5754         { &hf_smb2_file_compression_info,
5755                 { "SMB2_FILE_COMPRESSION_INFO", "smb2.smb2_file_compression_info", FT_NONE, BASE_NONE,
5756                 NULL, 0, "SMB2_FILE_COMPRESSION_INFO structure", HFILL }},
5757
5758         { &hf_smb2_file_basic_info,
5759                 { "SMB2_FILE_BASIC_INFO", "smb2.smb2_file_basic_info", FT_NONE, BASE_NONE,
5760                 NULL, 0, "SMB2_FILE_BASIC_INFO structure", HFILL }},
5761
5762         { &hf_smb2_file_standard_info,
5763                 { "SMB2_FILE_STANDARD_INFO", "smb2.smb2_file_standard_info", FT_NONE, BASE_NONE,
5764                 NULL, 0, "SMB2_FILE_STANDARD_INFO structure", HFILL }},
5765
5766         { &hf_smb2_file_internal_info,
5767                 { "SMB2_FILE_INTERNAL_INFO", "smb2.smb2_file_internal_info", FT_NONE, BASE_NONE,
5768                 NULL, 0, "SMB2_FILE_INTERNAL_INFO structure", HFILL }},
5769
5770         { &hf_smb2_file_mode_info,
5771                 { "SMB2_FILE_MODE_INFO", "smb2.smb2_file_mode_info", FT_NONE, BASE_NONE,
5772                 NULL, 0, "SMB2_FILE_MODE_INFO structure", HFILL }},
5773
5774         { &hf_smb2_file_alignment_info,
5775                 { "SMB2_FILE_ALIGNMENT_INFO", "smb2.smb2_file_alignment_info", FT_NONE, BASE_NONE,
5776                 NULL, 0, "SMB2_FILE_ALIGNMENT_INFO structure", HFILL }},
5777
5778         { &hf_smb2_file_position_info,
5779                 { "SMB2_FILE_POSITION_INFO", "smb2.smb2_file_position_info", FT_NONE, BASE_NONE,
5780                 NULL, 0, "SMB2_FILE_POSITION_INFO structure", HFILL }},
5781
5782         { &hf_smb2_file_access_info,
5783                 { "SMB2_FILE_ACCESS_INFO", "smb2.smb2_file_access_info", FT_NONE, BASE_NONE,
5784                 NULL, 0, "SMB2_FILE_ACCESS_INFO structure", HFILL }},
5785
5786         { &hf_smb2_file_ea_info,
5787                 { "SMB2_FILE_EA_INFO", "smb2.smb2_file_ea_info", FT_NONE, BASE_NONE,
5788                 NULL, 0, "SMB2_FILE_EA_INFO structure", HFILL }},
5789
5790         { &hf_smb2_file_network_open_info,
5791                 { "SMB2_FILE_NETWORK_OPEN_INFO", "smb2.smb2_file_network_open_info", FT_NONE, BASE_NONE,
5792                 NULL, 0, "SMB2_FILE_NETWORK_OPEN_INFO structure", HFILL }},
5793
5794         { &hf_smb2_file_attribute_tag_info,
5795                 { "SMB2_FILE_ATTRIBUTE_TAG_INFO", "smb2.smb2_file_attribute_tag_info", FT_NONE, BASE_NONE,
5796                 NULL, 0, "SMB2_FILE_ATTRIBUTE_TAG_INFO structure", HFILL }},
5797
5798         { &hf_smb2_file_disposition_info,
5799                 { "SMB2_FILE_DISPOSITION_INFO", "smb2.smb2_file_disposition_info", FT_NONE, BASE_NONE,
5800                 NULL, 0, "SMB2_FILE_DISPOSITION_INFO structure", HFILL }},
5801
5802         { &hf_smb2_file_info_0f,
5803                 { "SMB2_FILE_INFO_0f", "smb2.smb2_file_info_0f", FT_NONE, BASE_NONE,
5804                 NULL, 0, "SMB2_FILE_INFO_0f structure", HFILL }},
5805
5806         { &hf_smb2_file_rename_info,
5807                 { "SMB2_FILE_RENAME_INFO", "smb2.smb2_file_rename_info", FT_NONE, BASE_NONE,
5808                 NULL, 0, "SMB2_FILE_RENAME_INFO structure", HFILL }},
5809
5810         { &hf_smb2_fs_info_01,
5811                 { "SMB2_FS_INFO_01", "smb2.smb2_fs_info_01", FT_NONE, BASE_NONE,
5812                 NULL, 0, "SMB2_FS_INFO_01 structure", HFILL }},
5813
5814         { &hf_smb2_fs_info_03,
5815                 { "SMB2_FS_INFO_03", "smb2.smb2_fs_info_03", FT_NONE, BASE_NONE,
5816                 NULL, 0, "SMB2_FS_INFO_03 structure", HFILL }},
5817
5818         { &hf_smb2_fs_info_04,
5819                 { "SMB2_FS_INFO_04", "smb2.smb2_fs_info_04", FT_NONE, BASE_NONE,
5820                 NULL, 0, "SMB2_FS_INFO_04 structure", HFILL }},
5821
5822         { &hf_smb2_fs_info_05,
5823                 { "SMB2_FS_INFO_05", "smb2.smb2_fs_info_05", FT_NONE, BASE_NONE,
5824                 NULL, 0, "SMB2_FS_INFO_05 structure", HFILL }},
5825
5826         { &hf_smb2_fs_info_06,
5827                 { "SMB2_FS_INFO_06", "smb2.smb2_fs_info_06", FT_NONE, BASE_NONE,
5828                 NULL, 0, "SMB2_FS_INFO_06 structure", HFILL }},
5829
5830         { &hf_smb2_fs_info_07,
5831                 { "SMB2_FS_INFO_07", "smb2.smb2_fs_info_07", FT_NONE, BASE_NONE,
5832                 NULL, 0, "SMB2_FS_INFO_07 structure", HFILL }},
5833
5834         { &hf_smb2_fs_objectid_info,
5835                 { "SMB2_FS_OBJECTID_INFO", "smb2.smb2_fs_objectid_info", FT_NONE, BASE_NONE,
5836                 NULL, 0, "SMB2_FS_OBJECTID_INFO structure", HFILL }},
5837
5838         { &hf_smb2_sec_info_00,
5839                 { "SMB2_SEC_INFO_00", "smb2.smb2_sec_info_00", FT_NONE, BASE_NONE,
5840                 NULL, 0, "SMB2_SEC_INFO_00 structure", HFILL }},
5841
5842         { &hf_smb2_disposition_delete_on_close,
5843           { "Delete on close", "smb2.disposition.delete_on_close", FT_BOOLEAN, 8,
5844                 TFS(&tfs_disposition_delete_on_close), 0x01, NULL, HFILL }},
5845
5846
5847         { &hf_smb2_create_disposition,
5848                 { "Disposition", "smb2.create.disposition", FT_UINT32, BASE_DEC,
5849                 VALS(create_disposition_vals), 0, "Create disposition, what to do if the file does/does not exist", HFILL }},
5850
5851         { &hf_smb2_create_action,
5852                 { "Create Action", "smb2.create.action", FT_UINT32, BASE_DEC,
5853                 VALS(oa_open_vals), 0, NULL, HFILL }},
5854
5855         { &hf_smb2_extrainfo,
5856                 { "ExtraInfo", "smb2.create.extrainfo", FT_NONE, BASE_NONE,
5857                 NULL, 0, "Create ExtraInfo", HFILL }},
5858
5859         { &hf_smb2_create_chain_offset,
5860                 { "Chain Offset", "smb2.create.chain_offset", FT_UINT32, BASE_HEX,
5861                 NULL, 0, "Offset to next entry in chain or 0", HFILL }},
5862
5863         { &hf_smb2_create_chain_data,
5864                 { "Data", "smb2.create.chain_data", FT_NONE, BASE_NONE,
5865                 NULL, 0, "Chain Data", HFILL }},
5866
5867         { &hf_smb2_FILE_OBJECTID_BUFFER,
5868                 { "FILE_OBJECTID_BUFFER", "smb2.FILE_OBJECTID_BUFFER", FT_NONE, BASE_NONE,
5869                 NULL, 0, "A FILE_OBJECTID_BUFFER structure", HFILL }},
5870
5871         { &hf_smb2_data_length,
5872                 { "Data Length", "smb2.create.data_length", FT_UINT32, BASE_DEC,
5873                 NULL, 0, "Length Data or 0", HFILL }},
5874
5875         { &hf_smb2_next_offset,
5876                 { "Next Offset", "smb2.next_offset", FT_UINT32, BASE_DEC,
5877                 NULL, 0, "Offset to next buffer or 0", HFILL }},
5878
5879         { &hf_smb2_current_time,
5880                 { "Current Time", "smb2.current_time", FT_ABSOLUTE_TIME, BASE_NONE,
5881                 NULL, 0, "Current Time at server", HFILL }},
5882
5883         { &hf_smb2_boot_time,
5884                 { "Boot Time", "smb2.boot_time", FT_ABSOLUTE_TIME, BASE_NONE,
5885                 NULL, 0, "Boot Time at server", HFILL }},
5886
5887         { &hf_smb2_ea_flags,
5888                 { "EA Flags", "smb2.ea.flags", FT_UINT8, BASE_HEX,
5889                 NULL, 0, NULL, HFILL }},
5890
5891         { &hf_smb2_ea_name_len,
5892                 { "EA Name Length", "smb2.ea.name_len", FT_UINT8, BASE_DEC,
5893                 NULL, 0, NULL, HFILL }},
5894
5895         { &hf_smb2_ea_data_len,
5896                 { "EA Data Length", "smb2.ea.data_len", FT_UINT8, BASE_DEC,
5897                 NULL, 0, NULL, HFILL }},
5898
5899         { &hf_smb2_delete_pending,
5900                 { "Delete Pending", "smb2.delete_pending", FT_UINT8, BASE_DEC,
5901                 NULL, 0, NULL, HFILL }},
5902
5903         { &hf_smb2_is_directory,
5904                 { "Is Directory", "smb2.is_directory", FT_UINT8, BASE_DEC,
5905                 NULL, 0, "Is this a directory?", HFILL }},
5906
5907         { &hf_smb2_oplock,
5908                 { "Oplock", "smb2.create.oplock", FT_UINT8, BASE_HEX,
5909                 VALS(oplock_vals), 0, "Oplock type", HFILL }},
5910
5911         { &hf_smb2_close_flags,
5912                 { "Close Flags", "smb2.close.flags", FT_UINT16, BASE_HEX,
5913                 NULL, 0, "close flags", HFILL }},
5914
5915         { &hf_smb2_notify_flags,
5916                 { "Notify Flags", "smb2.notify.flags", FT_UINT16, BASE_HEX,
5917                 NULL, 0, NULL, HFILL }},
5918
5919         { &hf_smb2_buffer_code_len,
5920                 { "Length", "smb2.buffer_code.length", FT_UINT16, BASE_DEC,
5921                 NULL, 0, "Length of fixed portion of PDU", HFILL }},
5922
5923         { &hf_smb2_olb_length,
5924                 { "Length", "smb2.olb.length", FT_UINT32, BASE_DEC,
5925                 NULL, 0, "Length of the buffer", HFILL }},
5926
5927         { &hf_smb2_olb_offset,
5928                 { "Offset", "smb2.olb.offset", FT_UINT32, BASE_HEX,
5929                 NULL, 0, "Offset to the buffer", HFILL }},
5930
5931         { &hf_smb2_buffer_code_flags_dyn,
5932                 { "Dynamic Part", "smb2.buffer_code.dynamic", FT_BOOLEAN, 16,
5933                 NULL, 0x0001, "Whether a dynamic length blob follows", HFILL }},
5934
5935         { &hf_smb2_ea_data,
5936                 { "EA Data", "smb2.ea.data", FT_STRING, BASE_NONE,
5937                 NULL, 0, NULL, HFILL }},
5938
5939         { &hf_smb2_ea_name,
5940                 { "EA Name", "smb2.ea.name", FT_STRING, BASE_NONE,
5941                 NULL, 0, NULL, HFILL }},
5942
5943         { &hf_smb2_impersonation_level,
5944                 { "Impersonation", "smb2.impersonation.level", FT_UINT32, BASE_DEC,
5945                 VALS(impersonation_level_vals), 0, "Impersonation level", HFILL }},
5946
5947         { &hf_smb2_ioctl_function,
5948                 { "Function", "smb2.ioctl.function", FT_UINT32, BASE_HEX,
5949                 VALS(smb2_ioctl_vals), 0, "Ioctl function", HFILL }},
5950
5951         { &hf_smb2_ioctl_function_device,
5952                 { "Device", "smb2.ioctl.function.device", FT_UINT32, BASE_HEX,
5953                 VALS(smb2_ioctl_device_vals), 0xffff0000, "Device for Ioctl", HFILL }},
5954
5955         { &hf_smb2_ioctl_function_access,
5956                 { "Access", "smb2.ioctl.function.access", FT_UINT32, BASE_HEX,
5957                 VALS(smb2_ioctl_access_vals), 0x0000c000, "Access for Ioctl", HFILL }},
5958
5959         { &hf_smb2_ioctl_function_function,
5960                 { "Function", "smb2.ioctl.function.function", FT_UINT32, BASE_HEX,
5961                 NULL, 0x00003ffc, "Function for Ioctl", HFILL }},
5962
5963         { &hf_smb2_ioctl_function_method,
5964                 { "Method", "smb2.ioctl.function.method", FT_UINT32, BASE_HEX,
5965                 VALS(smb2_ioctl_method_vals), 0x00000003, "Method for Ioctl", HFILL }},
5966
5967         { &hf_smb2_ioctl_shadow_copy_num_volumes,
5968                 { "Num Volumes", "smb2.ioctl.shadow_copy.num_volumes", FT_UINT32, BASE_DEC,
5969                 NULL, 0, "Number of shadow copy volumes", HFILL }},
5970
5971         { &hf_smb2_ioctl_shadow_copy_num_labels,
5972                 { "Num Labels", "smb2.ioctl.shadow_copy.num_labels", FT_UINT32, BASE_DEC,
5973                 NULL, 0, "Number of shadow copy labels", HFILL }},
5974
5975         { &hf_smb2_ioctl_shadow_copy_label,
5976                 { "Label", "smb2.ioctl.shadow_copy.label", FT_STRING, BASE_NONE,
5977                 NULL, 0, "Shadow copy label", HFILL }},
5978
5979         { &hf_smb2_compression_format,
5980                 { "Compression Format", "smb2.compression_format", FT_UINT16, BASE_DEC,
5981                 VALS(compression_format_vals), 0, "Compression to use", HFILL }},
5982
5983         { &hf_smb2_share_type,
5984                 { "Share Type", "smb2.share_type", FT_UINT16, BASE_DEC,
5985                 VALS(smb2_share_type_vals), 0, "Type of share", HFILL }},
5986
5987         { &hf_smb2_epoch,
5988                 { "Epoch", "smb2.epoch", FT_UINT16, BASE_DEC,
5989                 NULL, 0, NULL, HFILL }},
5990
5991         { &hf_smb2_credits_requested,
5992                 { "Credits requested", "smb2.credits.requested", FT_UINT16, BASE_DEC,
5993                 NULL, 0, NULL, HFILL }},
5994
5995         { &hf_smb2_credits_granted,
5996                 { "Credits granted", "smb2.credits.granted", FT_UINT16, BASE_DEC,
5997                 NULL, 0, NULL, HFILL }},
5998
5999         { &hf_smb2_dialect_count,
6000                 { "Dialect count", "smb2.dialect_count", FT_UINT16, BASE_DEC,
6001                 NULL, 0, NULL, HFILL }},
6002
6003         { &hf_smb2_dialect,
6004                 { "Dialect", "smb2.dialect", FT_UINT16, BASE_HEX,
6005                 NULL, 0, NULL, HFILL }},
6006
6007         { &hf_smb2_security_mode,
6008                 { "Security mode", "smb2.sec_mode", FT_UINT8, BASE_HEX,
6009                 NULL, 0, NULL, HFILL }},
6010
6011         { &hf_smb2_session_flags,
6012                 { "Session Flags", "smb2.session_flags", FT_UINT16, BASE_HEX,
6013                 NULL, 0, NULL, HFILL }},
6014
6015         { &hf_smb2_lock_count,
6016                 { "Lock Count", "smb2.lock_count", FT_UINT16, BASE_DEC,
6017                 NULL, 0, NULL, HFILL }},
6018
6019         { &hf_smb2_capabilities,
6020                 { "Capabilities", "smb2.capabilities", FT_UINT32, BASE_HEX,
6021                 NULL, 0, NULL, HFILL }},
6022
6023         { &hf_smb2_ioctl_shadow_copy_count,
6024                 { "Count", "smb2.ioctl.shadow_copy.count", FT_UINT32, BASE_DEC,
6025                 NULL, 0, "Number of bytes for shadow copy label strings", HFILL }},
6026
6027         { &hf_smb2_auth_frame,
6028                 { "Authenticated in Frame", "smb2.auth_frame", FT_UINT32, BASE_DEC,
6029                 NULL, 0, "Which frame this user was authenticated in", HFILL }},
6030
6031         { &hf_smb2_tcon_frame,
6032                 { "Connected in Frame", "smb2.tcon_frame", FT_UINT32, BASE_DEC,
6033                 NULL, 0, "Which frame this share was connected in", HFILL }},
6034
6035         { &hf_smb2_tag,
6036                 { "Tag", "smb2.tag", FT_STRING, BASE_NONE,
6037                 NULL, 0, "Tag of chain entry", HFILL }},
6038
6039         { &hf_smb2_acct_name,
6040                 { "Account", "smb2.acct", FT_STRING, BASE_NONE,
6041                 NULL, 0, "Account Name", HFILL }},
6042
6043         { &hf_smb2_domain_name,
6044                 { "Domain", "smb2.domain", FT_STRING, BASE_NONE,
6045                 NULL, 0, "Domain Name", HFILL }},
6046
6047         { &hf_smb2_host_name,
6048                 { "Host", "smb2.host", FT_STRING, BASE_NONE,
6049                 NULL, 0, "Host Name", HFILL }},
6050
6051         { &hf_smb2_signature,
6052                 { "Signature", "smb2.signature", FT_BYTES, BASE_NONE,
6053                 NULL, 0, NULL, HFILL }},
6054
6055         { &hf_smb2_unknown,
6056                 { "unknown", "smb2.unknown", FT_BYTES, BASE_NONE,
6057                 NULL, 0, "Unknown bytes", HFILL }},
6058
6059         { &hf_smb2_unknown_timestamp,
6060                 { "Timestamp", "smb2.unknown.timestamp", FT_ABSOLUTE_TIME, BASE_NONE,
6061                 NULL, 0, "Unknown timestamp", HFILL }},
6062
6063         { &hf_smb2_ses_flags_guest,
6064                 { "Guest", "smb2.ses_flags.guest", FT_BOOLEAN, 16,
6065                 NULL, SES_FLAGS_GUEST, NULL, HFILL }},
6066
6067         { &hf_smb2_ses_flags_null,
6068                 { "Null", "smb2.ses_flags.null", FT_BOOLEAN, 16,
6069                 NULL, SES_FLAGS_NULL, NULL, HFILL }},
6070
6071         { &hf_smb2_secmode_flags_sign_required,
6072                 { "Signing required", "smb2.sec_mode.sign_required", FT_BOOLEAN, 8,
6073                 NULL, NEGPROT_SIGN_REQ, "Is signing required", HFILL }},
6074
6075         { &hf_smb2_secmode_flags_sign_enabled,
6076                 { "Signing enabled", "smb2.sec_mode.sign_enabled", FT_BOOLEAN, 8,
6077                 NULL, NEGPROT_SIGN_ENABLED, "Is signing enabled", HFILL }},
6078
6079         { &hf_smb2_cap_dfs,
6080                 { "DFS", "smb2.capabilities.dfs", FT_BOOLEAN, 32,
6081                 TFS(&tfs_cap_dfs), NEGPROT_CAP_DFS, "If the host supports dfs", HFILL }},
6082
6083         { &hf_smb2_max_trans_size,
6084                 { "Max Transaction Size", "smb2.max_trans_size", FT_UINT32, BASE_DEC,
6085                 NULL, 0, "Maximum size of a transaction", HFILL }},
6086
6087         { &hf_smb2_max_read_size,
6088                 { "Max Read Size", "smb2.max_read_size", FT_UINT32, BASE_DEC,
6089                 NULL, 0, "Maximum size of a read", HFILL }},
6090
6091         { &hf_smb2_max_write_size,
6092                 { "Max Write Size", "smb2.max_write_size", FT_UINT32, BASE_DEC,
6093                 NULL, 0, "Maximum size of a write", HFILL }},
6094
6095         { &hf_smb2_vcnum,
6096                 { "VC Num", "smb2.num_vc", FT_UINT8, BASE_DEC,
6097                 NULL, 0, "Number of VCs", HFILL }},
6098
6099         { &hf_smb2_channel,
6100                 { "Channel", "smb2.channel", FT_UINT32, BASE_DEC,
6101                 NULL, 0, NULL, HFILL }},
6102
6103         { &hf_smb2_share_flags,
6104                 { "Share flags", "smb2.share_flags", FT_UINT32, BASE_HEX,
6105                 NULL, 0, "share flags", HFILL }},
6106
6107         { &hf_smb2_share_flags_dfs,
6108                 { "dfs", "smb2.share_flags.dfs", FT_BOOLEAN, 32,
6109                 NULL, SHARE_FLAGS_dfs, NULL, HFILL }},
6110
6111         { &hf_smb2_share_flags_dfs_root,
6112                 { "dfs_root", "smb2.share_flags.dfs_root", FT_BOOLEAN, 32,
6113                 NULL, SHARE_FLAGS_dfs_root, NULL, HFILL }},
6114
6115         { &hf_smb2_share_flags_restrict_exclusive_opens,
6116                 { "restrict_exclusive_opens", "smb2.share_flags.restrict_exclusive_opens", FT_BOOLEAN, 32,
6117                 NULL, SHARE_FLAGS_restrict_exclusive_opens, NULL, HFILL }},
6118
6119         { &hf_smb2_share_flags_force_shared_delete,
6120                 { "force_shared_delete", "smb2.share_flags.force_shared_delete", FT_BOOLEAN, 32,
6121                 NULL, SHARE_FLAGS_force_shared_delete, NULL, HFILL }},
6122
6123         { &hf_smb2_share_flags_allow_namespace_caching,
6124                 { "allow_namespace_caching", "smb2.share_flags.allow_namespace_caching", FT_BOOLEAN, 32,
6125                 NULL, SHARE_FLAGS_allow_namespace_caching, NULL, HFILL }},
6126
6127         { &hf_smb2_share_flags_access_based_dir_enum,
6128                 { "access_based_dir_enum", "smb2.share_flags.access_based_dir_enum", FT_BOOLEAN, 32,
6129                 NULL, SHARE_FLAGS_access_based_dir_enum, NULL, HFILL }},
6130
6131         { &hf_smb2_share_caching,
6132                 { "Caching policy", "smb2.share.caching", FT_UINT32, BASE_HEX,
6133                 VALS(share_cache_vals), 0, NULL, HFILL }},
6134
6135         { &hf_smb2_share_caps,
6136                 { "Share Capabilities", "smb2.share_caps", FT_UINT32, BASE_HEX,
6137                 NULL, 0, NULL, HFILL }},
6138
6139         { &hf_smb2_ioctl_flags,
6140                 { "Flags", "smb2.ioctl.flags", FT_UINT32, BASE_HEX,
6141                 NULL, 0, NULL, HFILL }},
6142
6143         { &hf_smb2_min_count,
6144                 { "Min Count", "smb2.min_count", FT_UINT32, BASE_DEC,
6145                 NULL, 0, NULL, HFILL }},
6146
6147         { &hf_smb2_remaining_bytes,
6148                 { "Remaining Bytes", "smb2.remaining_bytes", FT_UINT32, BASE_DEC,               NULL, 0, NULL, HFILL }},
6149
6150         { &hf_smb2_channel_info_offset,
6151                 { "Channel Info Offset", "smb2.channel_info_offset", FT_UINT16, BASE_DEC,
6152                 NULL, 0, NULL, HFILL }},
6153
6154         { &hf_smb2_channel_info_length,
6155                 { "Channel Info Length", "smb2.channel_info_length", FT_UINT16, BASE_DEC,
6156                 NULL, 0, NULL, HFILL }},
6157
6158         { &hf_smb2_share_caps_dfs,
6159                 { "dfs", "smb2.share_caps.dfs", FT_BOOLEAN, 32,
6160                 NULL, SHARE_CAPS_DFS, NULL, HFILL }},
6161
6162         { &hf_smb2_ioctl_is_fsctl,
6163                 { "Is FSCTL", "smb2.ioctl.is_fsctl", FT_BOOLEAN, 32,
6164                 NULL, 0x00000001, NULL, HFILL }},
6165
6166         { &hf_smb2_output_buffer_len,
6167                 { "Output Buffer Length", "smb2.output_buffer_len", FT_UINT16, BASE_DEC,
6168                 NULL, 0, NULL, HFILL }},
6169
6170         { &hf_smb2_close_pq_attrib,
6171                 { "PostQuery Attrib", "smb2.close.pq_attrib", FT_BOOLEAN, 16,
6172                 NULL, 0x0001, NULL, HFILL }},
6173
6174         { &hf_smb2_notify_watch_tree,
6175                 { "Watch Tree", "smb2.notify.watch_tree", FT_BOOLEAN, 16,
6176                 NULL, 0x0001, NULL, HFILL }},
6177
6178         { &hf_smb2_notify_out_data,
6179                 { "Out Data", "smb2.notify.out", FT_NONE, BASE_NONE,
6180                 NULL, 0, NULL, HFILL }},
6181
6182         { &hf_smb2_find_flags_restart_scans,
6183                 { "Restart Scans", "smb2.find.restart_scans", FT_BOOLEAN, 8,
6184                 NULL, SMB2_FIND_FLAG_RESTART_SCANS, NULL, HFILL }},
6185
6186         { &hf_smb2_find_flags_single_entry,
6187                 { "Single Entry", "smb2.find.single_entry", FT_BOOLEAN, 8,
6188                 NULL, SMB2_FIND_FLAG_SINGLE_ENTRY, NULL, HFILL }},
6189
6190         { &hf_smb2_find_flags_index_specified,
6191                 { "Index Specified", "smb2.find.index_specified", FT_BOOLEAN, 8,
6192                 NULL, SMB2_FIND_FLAG_INDEX_SPECIFIED, NULL, HFILL }},
6193
6194         { &hf_smb2_find_flags_reopen,
6195                 { "Reopen", "smb2.find.reopen", FT_BOOLEAN, 8,
6196                 NULL, SMB2_FIND_FLAG_REOPEN, NULL, HFILL }},
6197
6198         { &hf_smb2_file_index,
6199                 { "File Index", "smb2.file_index", FT_UINT32, BASE_HEX,
6200                 NULL, 0, NULL, HFILL }},
6201
6202         { &hf_smb2_file_directory_info,
6203                 { "FileDirectoryInfo", "smb2.find.file_directory_info", FT_NONE, BASE_NONE,
6204                 NULL, 0, NULL, HFILL }},
6205
6206         { &hf_smb2_full_directory_info,
6207                 { "FullDirectoryInfo", "smb2.find.full_directory_info", FT_NONE, BASE_NONE,
6208                 NULL, 0, NULL, HFILL }},
6209
6210         { &hf_smb2_both_directory_info,
6211                 { "FileBothDirectoryInfo", "smb2.find.both_directory_info", FT_NONE, BASE_NONE,
6212                 NULL, 0, NULL, HFILL }},
6213
6214         { &hf_smb2_id_both_directory_info,
6215                 { "FileIdBothDirectoryInfo", "smb2.find.id_both_directory_info", FT_NONE, BASE_NONE,
6216                 NULL, 0, NULL, HFILL }},
6217
6218         { &hf_smb2_short_name_len,
6219                 { "Short Name Length", "smb2.short_name_len", FT_UINT8, BASE_DEC,
6220                 NULL, 0, NULL, HFILL }},
6221  
6222         { &hf_smb2_short_name,
6223                 { "Short Name", "smb2.shortname", FT_STRING, BASE_NONE,
6224                 NULL, 0, NULL, HFILL }},
6225         { &hf_smb2_file_name_info,
6226                 { "FileNameInfo", "smb2.find.name_info", FT_NONE, BASE_NONE,
6227                 NULL, 0, NULL, HFILL }},
6228
6229         { &hf_smb2_lock_info,
6230                 { "Lock Info", "smb2.lock_info", FT_NONE, BASE_NONE,
6231                 NULL, 0, NULL, HFILL }},
6232
6233         { &hf_smb2_lock_length,
6234                 { "Length", "smb2.lock_length", FT_UINT64, BASE_DEC,
6235                 NULL, 0, NULL, HFILL }},
6236
6237         { &hf_smb2_lock_flags,
6238                 { "Flags", "smb2.lock_flags", FT_UINT32, BASE_HEX,
6239                 NULL, 0, NULL, HFILL }},
6240
6241         { &hf_smb2_lock_flags_shared,
6242                 { "Shared", "smb2.lock_flags.shared", FT_BOOLEAN, 32,
6243                 NULL, 0x00000001, NULL, HFILL }},
6244
6245         { &hf_smb2_lock_flags_exclusive,
6246                 { "Exclusive", "smb2.lock_flags.exclusive", FT_BOOLEAN, 32,
6247                 NULL, 0x00000002, NULL, HFILL }},
6248
6249         { &hf_smb2_lock_flags_unlock,
6250                 { "Unlock", "smb2.lock_flags.unlock", FT_BOOLEAN, 32,
6251                 NULL, 0x00000004, NULL, HFILL }},
6252
6253         { &hf_smb2_lock_flags_fail_immediately,
6254                 { "Fail Immediately", "smb2.lock_flags.fail_immediately", FT_BOOLEAN, 32,
6255                 NULL, 0x00000010, NULL, HFILL }},
6256
6257         { &hf_smb2_error_reserved,
6258                 { "Reserved", "smb2.error.reserved", FT_UINT16, BASE_HEX,
6259                 NULL, 0, NULL, HFILL }},
6260
6261         { &hf_smb2_error_byte_count,
6262                 { "Byte Count", "smb2.error.byte_count", FT_UINT32, BASE_DEC,
6263                 NULL, 0, NULL, HFILL }},
6264
6265         { &hf_smb2_error_data,
6266                 { "Error Data", "smb2.error.data", FT_BYTES, BASE_NONE,
6267                 NULL, 0, NULL, HFILL }},
6268
6269         };
6270
6271         static gint *ett[] = {
6272                 &ett_smb2,
6273                 &ett_smb2_ea,
6274                 &ett_smb2_olb,
6275                 &ett_smb2_header,
6276                 &ett_smb2_command,
6277                 &ett_smb2_secblob,
6278                 &ett_smb2_file_basic_info,
6279                 &ett_smb2_file_standard_info,
6280                 &ett_smb2_file_internal_info,
6281                 &ett_smb2_file_ea_info,
6282                 &ett_smb2_file_access_info,
6283                 &ett_smb2_file_rename_info,
6284                 &ett_smb2_file_disposition_info,
6285                 &ett_smb2_file_position_info,
6286                 &ett_smb2_file_info_0f,
6287                 &ett_smb2_file_mode_info,
6288                 &ett_smb2_file_alignment_info,
6289                 &ett_smb2_file_all_info,
6290                 &ett_smb2_file_allocation_info,
6291                 &ett_smb2_file_endoffile_info,
6292                 &ett_smb2_file_alternate_name_info,
6293                 &ett_smb2_file_stream_info,
6294                 &ett_smb2_file_pipe_info,
6295                 &ett_smb2_file_compression_info,
6296                 &ett_smb2_file_network_open_info,
6297                 &ett_smb2_file_attribute_tag_info,
6298                 &ett_smb2_fs_info_01,
6299                 &ett_smb2_fs_info_03,
6300                 &ett_smb2_fs_info_04,
6301                 &ett_smb2_fs_info_05,
6302                 &ett_smb2_fs_info_06,
6303                 &ett_smb2_fs_info_07,
6304                 &ett_smb2_fs_objectid_info,
6305                 &ett_smb2_sec_info_00,
6306                 &ett_smb2_tid_tree,
6307                 &ett_smb2_sesid_tree,
6308                 &ett_smb2_create_chain_element,
6309                 &ett_smb2_MxAc_buffer,
6310                 &ett_smb2_ioctl_function,
6311                 &ett_smb2_FILE_OBJECTID_BUFFER,
6312                 &ett_smb2_flags,
6313                 &ett_smb2_sec_mode,
6314                 &ett_smb2_capabilities,
6315                 &ett_smb2_ses_flags,
6316                 &ett_smb2_share_flags,
6317                 &ett_smb2_share_caps,
6318                 &ett_smb2_ioctl_flags,
6319                 &ett_smb2_close_flags,
6320                 &ett_smb2_notify_flags,
6321                 &ett_smb2_find_flags,
6322                 &ett_smb2_file_directory_info,
6323                 &ett_smb2_both_directory_info,
6324                 &ett_smb2_id_both_directory_info,
6325                 &ett_smb2_full_directory_info,
6326                 &ett_smb2_file_name_info,
6327                 &ett_smb2_lock_info,
6328                 &ett_smb2_lock_flags,
6329         };
6330
6331         proto_smb2 = proto_register_protocol("SMB2 (Server Message Block Protocol version 2)",
6332             "SMB2", "smb2");
6333         proto_register_subtree_array(ett, array_length(ett));
6334         proto_register_field_array(proto_smb2, hf, array_length(hf));
6335
6336         register_heur_dissector_list("smb2_heur_subdissectors", &smb2_heur_subdissector_list);
6337         smb2_tap = register_tap("smb2");
6338 }
6339
6340 void
6341 proto_reg_handoff_smb2(void)
6342 {
6343         gssapi_handle = find_dissector("gssapi");
6344         ntlmssp_handle = find_dissector("ntlmssp");
6345         heur_dissector_add("netbios", dissect_smb2_heur, proto_smb2);
6346 }