Additional RAP error code for password changes sent to a BDC, from Devin
[obnox/wireshark/wip.git] / packet-smb-pipe.c
1 /*
2 XXX  Fixme : shouldnt show [malformed frame] for long packets
3 */
4
5 /* packet-smb-pipe.c
6  * Routines for SMB named pipe packet dissection
7  * Copyright 1999, Richard Sharpe <rsharpe@ns.aus.com>
8  * significant rewrite to tvbuffify the dissector, Ronnie Sahlberg and
9  * Guy Harris 2001
10  *
11  * $Id: packet-smb-pipe.c,v 1.75 2002/04/29 22:43:21 guy Exp $
12  *
13  * Ethereal - Network traffic analyzer
14  * By Gerald Combs <gerald@ethereal.com>
15  * Copyright 1998 Gerald Combs
16  *
17  * Copied from packet-pop.c
18  * 
19  * This program is free software; you can redistribute it and/or
20  * modify it under the terms of the GNU General Public License
21  * as published by the Free Software Foundation; either version 2
22  * of the License, or (at your option) any later version.
23  * 
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27  * GNU General Public License for more details.
28  * 
29  * You should have received a copy of the GNU General Public License
30  * along with this program; if not, write to the Free Software
31  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
32  */
33
34 #ifdef HAVE_CONFIG_H
35 # include "config.h"
36 #endif
37
38 #include <stdio.h>
39
40 #ifdef HAVE_SYS_TYPES_H
41 # include <sys/types.h>
42 #endif
43
44 #ifdef HAVE_NETINET_IN_H
45 # include <netinet/in.h>
46 #endif
47
48 #include <time.h>
49 #include <string.h>
50 #include <glib.h>
51 #include <ctype.h>
52 #include <epan/packet.h>
53 #include <epan/conversation.h>
54 #include "smb.h"
55 #include "packet-smb-pipe.h"
56 #include "packet-smb-browse.h"
57 #include "packet-dcerpc.h"
58 #include "reassemble.h"
59
60 static int proto_smb_pipe = -1;
61 static int hf_pipe_function = -1;
62 static int hf_pipe_priority = -1;
63 static int hf_pipe_peek_available = -1;
64 static int hf_pipe_peek_remaining = -1;
65 static int hf_pipe_peek_status = -1;
66 static int hf_pipe_getinfo_info_level = -1;
67 static int hf_pipe_getinfo_output_buffer_size = -1;
68 static int hf_pipe_getinfo_input_buffer_size = -1;
69 static int hf_pipe_getinfo_maximum_instances = -1;
70 static int hf_pipe_getinfo_current_instances = -1;
71 static int hf_pipe_getinfo_pipe_name_length = -1;
72 static int hf_pipe_getinfo_pipe_name = -1;
73 static int hf_pipe_write_raw_bytes_written = -1;
74
75 static gint ett_smb_pipe = -1;
76 static gint ett_smb_pipe_fragments = -1;
77
78 static int proto_smb_lanman = -1;
79 static int hf_function_code = -1;
80 static int hf_param_desc = -1;
81 static int hf_return_desc = -1;
82 static int hf_aux_data_desc = -1;
83 static int hf_detail_level = -1;
84 static int hf_recv_buf_len = -1;
85 static int hf_send_buf_len = -1;
86 static int hf_continuation_from = -1;
87 static int hf_status = -1;
88 static int hf_convert = -1;
89 static int hf_ecount = -1;
90 static int hf_acount = -1;
91 static int hf_share_name = -1;
92 static int hf_share_type = -1;
93 static int hf_share_comment = -1;
94 static int hf_share_permissions = -1;
95 static int hf_share_max_uses = -1;
96 static int hf_share_current_uses = -1;
97 static int hf_share_path = -1;
98 static int hf_share_password = -1;
99 static int hf_server_name = -1;
100 static int hf_server_major = -1;
101 static int hf_server_minor = -1;
102 static int hf_server_comment = -1;
103 static int hf_abytes = -1;
104 static int hf_current_time = -1;
105 static int hf_msecs = -1;
106 static int hf_hour = -1;
107 static int hf_minute = -1;
108 static int hf_second = -1;
109 static int hf_hundredths = -1;
110 static int hf_tzoffset = -1;
111 static int hf_timeinterval = -1;
112 static int hf_day = -1;
113 static int hf_month = -1;
114 static int hf_year = -1;
115 static int hf_weekday = -1;
116 static int hf_enumeration_domain = -1;
117 static int hf_computer_name = -1;
118 static int hf_user_name = -1;
119 static int hf_group_name = -1;
120 static int hf_workstation_domain = -1;
121 static int hf_workstation_major = -1;
122 static int hf_workstation_minor = -1;
123 static int hf_logon_domain = -1;
124 static int hf_other_domains = -1;
125 static int hf_password = -1;
126 static int hf_workstation_name = -1;
127 static int hf_ustruct_size = -1;
128 static int hf_logon_code = -1;
129 static int hf_privilege_level = -1;
130 static int hf_operator_privileges = -1;
131 static int hf_num_logons = -1;
132 static int hf_bad_pw_count = -1;
133 static int hf_last_logon = -1;
134 static int hf_last_logoff = -1;
135 static int hf_logoff_time = -1;
136 static int hf_kickoff_time = -1;
137 static int hf_password_age = -1;
138 static int hf_password_can_change = -1;
139 static int hf_password_must_change = -1;
140 static int hf_script_path = -1;
141 static int hf_logoff_code = -1;
142 static int hf_duration = -1;
143 static int hf_comment = -1;
144 static int hf_user_comment = -1;
145 static int hf_full_name = -1;
146 static int hf_homedir = -1;
147 static int hf_parameters = -1;
148 static int hf_logon_server = -1;
149 static int hf_country_code = -1;
150 static int hf_workstations = -1;
151 static int hf_max_storage = -1;
152 static int hf_units_per_week = -1;
153 static int hf_logon_hours = -1;
154 static int hf_code_page = -1;
155 static int hf_new_password = -1;
156 static int hf_old_password = -1;
157 static int hf_reserved = -1;
158
159 static gint ett_lanman = -1;
160 static gint ett_lanman_unknown_entries = -1;
161 static gint ett_lanman_unknown_entry = -1;
162 static gint ett_lanman_shares = -1;
163 static gint ett_lanman_share = -1;
164 static gint ett_lanman_groups = -1;
165 static gint ett_lanman_servers = -1;
166 static gint ett_lanman_server = -1;
167
168 static dissector_handle_t data_handle;
169
170 /*
171  * See
172  *
173  *      ftp://ftp.microsoft.com/developr/drg/CIFS/cifsrap2.txt
174  *
175  * among other documents.
176  */
177
178 static const value_string status_vals[] = {
179         {0,     "Success"},
180         {5,     "User has insufficient privilege"},
181         {65,    "Network access is denied"},
182         {86,    "The specified password is invalid"},
183         {SMBE_moredata, "Additional data is available"},
184         {2114,  "Service is not running on the remote computer"},
185         {2123,  "Supplied buffer is too small"},
186         {2141,  "Server is not configured for transactions (IPC$ not shared)"},
187         {2212,  "An error occurred while loading or running the logon script"},
188         {2214,  "The logon was not validated by any server"},
189         {2217,  "The logon server is running an older software version"},
190         {2221,  "The user name was not found"},
191         {2226,  "Operation not permitted on Backup Domain Controller"},
192         {2240,  "The user is not allowed to logon from this computer"},
193         {2241,  "The user is not allowed to logon at this time"},
194         {2242,  "The user password has expired"},
195         {2243,  "The password cannot be changed"},
196         {2246,  "The password is too short"},
197         {0,     NULL}
198 };
199
200 static const value_string share_type_vals[] = {
201         {0, "Directory tree"},
202         {1, "Printer queue"},
203         {2, "Communications device"},
204         {3, "IPC"},
205         {0, NULL}
206 };
207
208 static const value_string privilege_vals[] = {
209         {0, "Guest"},
210         {1, "User"},
211         {2, "Administrator"},
212         {0, NULL}
213 };
214
215 static const value_string op_privilege_vals[] = {
216         {0, "Print operator"},
217         {1, "Communications operator"},
218         {2, "Server operator"},
219         {3, "Accounts operator"},
220         {0, NULL}
221 };
222
223 static const value_string weekday_vals[] = {
224         {0, "Sunday"},
225         {1, "Monday"},
226         {2, "Tuesday"},
227         {3, "Wednesday"},
228         {4, "Thursday"},
229         {5, "Friday"},
230         {6, "Saturday"},
231         {0, NULL}
232 };
233
234 static int
235 add_word_param(tvbuff_t *tvb, int offset, int count, packet_info *pinfo,
236     proto_tree *tree, int convert, int hf_index)
237 {
238         guint16 WParam;
239
240         if (hf_index != -1)
241                 proto_tree_add_item(tree, hf_index, tvb, offset, 2, TRUE);
242         else {
243                 WParam = tvb_get_letohs(tvb, offset);
244                 proto_tree_add_text(tree, tvb, offset, 2,
245                     "Word Param: %u (0x%04X)", WParam, WParam);
246         }
247         offset += 2;
248         return offset;
249 }
250
251 static int
252 add_dword_param(tvbuff_t *tvb, int offset, int count, packet_info *pinfo,
253     proto_tree *tree, int convert, int hf_index)
254 {
255         guint32 LParam;
256
257         if (hf_index != -1)
258                 proto_tree_add_item(tree, hf_index, tvb, offset, 4, TRUE);
259         else {
260                 LParam = tvb_get_letohl(tvb, offset);
261                 proto_tree_add_text(tree, tvb, offset, 4,
262                     "Doubleword Param: %u (0x%08X)", LParam, LParam);
263         }
264         offset += 4;
265         return offset;
266 }
267
268 static int
269 add_byte_param(tvbuff_t *tvb, int offset, int count, packet_info *pinfo,
270     proto_tree *tree, int convert, int hf_index)
271 {
272         guint8 BParam;
273
274         if (hf_index != -1)
275                 proto_tree_add_item(tree, hf_index, tvb, offset, count, TRUE);
276         else {
277                 if (count == 1) {
278                         BParam = tvb_get_guint8(tvb, offset);
279                         proto_tree_add_text(tree, tvb, offset, count,
280                             "Byte Param: %u (0x%02X)",
281                             BParam, BParam);
282                 } else {
283                         proto_tree_add_text(tree, tvb, offset, count,
284                             "Byte Param: %s",
285                             tvb_bytes_to_str(tvb, offset, count));
286                 }
287         }
288         offset += count;
289         return offset;
290 }
291
292 static int
293 add_pad_param(tvbuff_t *tvb, int offset, int count, packet_info *pinfo,
294     proto_tree *tree, int convert, int hf_index)
295 {
296         /*
297          * This is for parameters that have descriptor entries but that
298          * are, in practice, just padding.
299          */
300         offset += count;
301         return offset;
302 }
303
304 static void
305 add_null_pointer_param(tvbuff_t *tvb, int offset, int count,
306     packet_info *pinfo, proto_tree *tree, int convert, int hf_index)
307 {
308         if (hf_index != -1) {
309                 proto_tree_add_text(tree, tvb, offset, 0,
310                   "%s (Null pointer)",
311                   proto_registrar_get_name(hf_index));
312         } else {
313                 proto_tree_add_text(tree, tvb, offset, 0,
314                     "String Param (Null pointer)");
315         }
316 }
317
318 static int
319 add_string_param(tvbuff_t *tvb, int offset, int count, packet_info *pinfo,
320     proto_tree *tree, int convert, int hf_index)
321 {
322         guint string_len;
323
324         string_len = tvb_strsize(tvb, offset);
325         if (hf_index != -1) {
326                 proto_tree_add_item(tree, hf_index, tvb, offset, string_len,
327                     TRUE);
328         } else {
329                 proto_tree_add_text(tree, tvb, offset, string_len,
330                     "String Param: %s",
331                     tvb_format_text(tvb, offset, string_len));
332         }
333         offset += string_len;
334         return offset;
335 }
336
337 static const char *
338 get_stringz_pointer_value(tvbuff_t *tvb, int offset, int convert, int *cptrp,
339     int *lenp)
340 {
341         int cptr;
342         gint string_len;
343
344         /* pointer to string */
345         cptr = (tvb_get_letohl(tvb, offset)&0xffff)-convert;
346         *cptrp = cptr;
347
348         /* string */
349         if (tvb_offset_exists(tvb, cptr) &&
350             (string_len = tvb_strnlen(tvb, cptr, -1)) != -1) {
351                 string_len++;   /* include the terminating '\0' */
352                 *lenp = string_len;
353                 return tvb_format_text(tvb, cptr, string_len - 1);
354         } else
355                 return NULL;
356 }
357
358 static int
359 add_stringz_pointer_param(tvbuff_t *tvb, int offset, int count,
360     packet_info *pinfo, proto_tree *tree, int convert, int hf_index)
361 {
362         int cptr;
363         const char *string;
364         gint string_len;
365
366         string = get_stringz_pointer_value(tvb, offset, convert, &cptr,
367             &string_len);
368         offset += 4;
369
370         /* string */
371         if (string != NULL) {
372                 if (hf_index != -1) {
373                         proto_tree_add_item(tree, hf_index, tvb, cptr,
374                             string_len, TRUE);
375                 } else {
376                         proto_tree_add_text(tree, tvb, cptr, string_len,
377                             "String Param: %s", string);
378                 }
379         } else {
380                 if (hf_index != -1) {
381                         proto_tree_add_text(tree, tvb, 0, 0,
382                             "%s: <String goes past end of frame>",
383                             proto_registrar_get_name(hf_index));
384                 } else {
385                         proto_tree_add_text(tree, tvb, 0, 0,
386                             "String Param: <String goes past end of frame>");
387                 }
388         }
389
390         return offset;
391 }
392
393 static int
394 add_bytes_pointer_param(tvbuff_t *tvb, int offset, int count,
395     packet_info *pinfo, proto_tree *tree, int convert, int hf_index)
396 {
397         int cptr;
398
399         /* pointer to byte array */
400         cptr = (tvb_get_letohl(tvb, offset)&0xffff)-convert;
401         offset += 4;
402
403         /* bytes */
404         if (tvb_bytes_exist(tvb, cptr, count)) {
405                 if (hf_index != -1) {
406                         proto_tree_add_item(tree, hf_index, tvb, cptr,
407                             count, TRUE);
408                 } else {
409                         proto_tree_add_text(tree, tvb, cptr, count,
410                             "Byte Param: %s",
411                             tvb_bytes_to_str(tvb, cptr, count));
412                 }
413         } else {
414                 if (hf_index != -1) {
415                         proto_tree_add_text(tree, tvb, 0, 0,
416                             "%s: <Bytes go past end of frame>",
417                             proto_registrar_get_name(hf_index));
418                 } else {
419                         proto_tree_add_text(tree, tvb, 0, 0,
420                             "Byte Param: <Bytes goes past end of frame>");
421                 }
422         }
423
424         return offset;
425 }
426
427 static int
428 add_detail_level(tvbuff_t *tvb, int offset, int count, packet_info *pinfo,
429     proto_tree *tree, int convert, int hf_index)
430 {
431         struct smb_info *smb_info = pinfo->private_data;
432         smb_transact_info_t *trp = smb_info->sip->extra_info;
433         guint16 level;
434
435         level = tvb_get_letohs(tvb, offset);
436         if (!pinfo->fd->flags.visited)
437                 trp->info_level = level;        /* remember this for the response */
438         proto_tree_add_uint(tree, hf_index, tvb, offset, 2, level);
439         offset += 2;
440         return offset;
441 }
442
443 static int
444 add_max_uses(tvbuff_t *tvb, int offset, int count, packet_info *pinfo,
445     proto_tree *tree, int convert, int hf_index)
446 {
447         guint16 WParam;
448
449         WParam = tvb_get_letohs(tvb, offset);
450         if (WParam == 0xffff) { /* -1 */
451                 proto_tree_add_uint_format(tree, hf_index, tvb,
452                     offset, 2, WParam,
453                     "%s: No limit",
454                     proto_registrar_get_name(hf_index));
455         } else {
456                 proto_tree_add_uint(tree, hf_index, tvb,
457                             offset, 2, WParam);
458         }
459         offset += 2;
460         return offset;
461 }
462
463 static int
464 add_server_type(tvbuff_t *tvb, int offset, int count,
465     packet_info *pinfo, proto_tree *tree, int convert, int hf_index)
466 {
467         dissect_smb_server_type_flags(tvb, pinfo, tree, offset, FALSE);
468         offset += 4;
469         return offset;
470 }
471
472 static int
473 add_server_type_info(tvbuff_t *tvb, int offset, int count,
474     packet_info *pinfo, proto_tree *tree, int convert, int hf_index)
475 {
476         dissect_smb_server_type_flags(tvb, pinfo, tree, offset, TRUE);
477         offset += 4;
478         return offset;
479 }
480
481 static int
482 add_reltime(tvbuff_t *tvb, int offset, int count, packet_info *pinfo,
483     proto_tree *tree, int convert, int hf_index)
484 {
485         nstime_t nstime;
486
487         nstime.secs = tvb_get_letohl(tvb, offset);
488         nstime.nsecs = 0;
489         proto_tree_add_time_format(tree, hf_index, tvb, offset, 4,
490             &nstime, "%s: %s", proto_registrar_get_name(hf_index),
491             time_secs_to_str(nstime.secs));
492         offset += 4;
493         return offset;
494 }
495
496 /*
497  * Sigh.  These are for handling Microsoft's annoying almost-UNIX-time-but-
498  * it's-local-time-not-UTC time.
499  */
500 static int
501 add_abstime_common(tvbuff_t *tvb, int offset, int count,
502     packet_info *pinfo, proto_tree *tree, int convert, int hf_index,
503     const char *absent_name)
504 {
505         nstime_t nstime;
506         struct tm *tmp;
507
508         nstime.secs = tvb_get_letohl(tvb, offset);
509         nstime.nsecs = 0;
510         /*
511          * Sigh.  Sometimes it appears that -1 means "unknown", and
512          * sometimes it appears that 0 means "unknown", for the last
513          * logoff date/time.
514          */
515         if (nstime.secs == -1 || nstime.secs == 0) {
516                 proto_tree_add_time_format(tree, hf_index, tvb, offset, 4,
517                     &nstime, "%s: %s", proto_registrar_get_name(hf_index),
518                     absent_name);
519         } else {
520                 /*
521                  * Run it through "gmtime()" to break it down, and then
522                  * run it through "mktime()" to put it back together
523                  * as UTC.
524                  */
525                 tmp = gmtime(&nstime.secs);
526                 tmp->tm_isdst = -1;     /* we don't know if it's DST or not */
527                 nstime.secs = mktime(tmp);
528                 proto_tree_add_time(tree, hf_index, tvb, offset, 4,
529                     &nstime);
530         }
531         offset += 4;
532         return offset;
533 }
534
535 static int
536 add_abstime_absent_never(tvbuff_t *tvb, int offset, int count,
537     packet_info *pinfo, proto_tree *tree, int convert, int hf_index)
538 {
539         return add_abstime_common(tvb, offset, count, pinfo, tree,
540             convert, hf_index, "Never");
541 }
542
543 static int
544 add_abstime_absent_unknown(tvbuff_t *tvb, int offset, int count,
545     packet_info *pinfo, proto_tree *tree, int convert, int hf_index)
546 {
547         return add_abstime_common(tvb, offset, count, pinfo, tree,
548             convert, hf_index, "Unknown");
549 }
550
551 static int
552 add_nlogons(tvbuff_t *tvb, int offset, int count, packet_info *pinfo,
553     proto_tree *tree, int convert, int hf_index)
554 {
555         guint16 nlogons;
556
557         nlogons = tvb_get_letohs(tvb, offset);
558         if (nlogons == 0xffff)  /* -1 */
559                 proto_tree_add_uint_format(tree, hf_index, tvb, offset, 2,
560                     nlogons, "%s: Unknown",
561                     proto_registrar_get_name(hf_index));
562         else
563                 proto_tree_add_uint(tree, hf_index, tvb, offset, 2,
564                     nlogons);
565         offset += 2;
566         return offset;
567 }
568
569 static int
570 add_max_storage(tvbuff_t *tvb, int offset, int count, packet_info *pinfo,
571     proto_tree *tree, int convert, int hf_index)
572 {
573         guint32 max_storage;
574
575         max_storage = tvb_get_letohl(tvb, offset);
576         if (max_storage == 0xffffffff)
577                 proto_tree_add_uint_format(tree, hf_index, tvb, offset, 4,
578                     max_storage, "%s: No limit",
579                     proto_registrar_get_name(hf_index));
580         else
581                 proto_tree_add_uint(tree, hf_index, tvb, offset, 4,
582                     max_storage);
583         offset += 4;
584         return offset;
585 }
586
587 static int
588 add_logon_hours(tvbuff_t *tvb, int offset, int count, packet_info *pinfo,
589     proto_tree *tree, int convert, int hf_index)
590 {
591         int cptr;
592
593         /* pointer to byte array */
594         cptr = (tvb_get_letohl(tvb, offset)&0xffff)-convert;
595         offset += 4;
596
597         /* bytes */
598         if (tvb_bytes_exist(tvb, cptr, count)) {
599                 if (count == 21) {
600                         /*
601                          * The logon hours should be exactly 21 bytes long.
602                          *
603                          * XXX - should actually carve up the bits;
604                          * we need the units per week to do that, though.
605                          */
606                         proto_tree_add_item(tree, hf_index, tvb, cptr, count,
607                             TRUE);
608                 } else {
609                         proto_tree_add_bytes_format(tree, hf_index, tvb,
610                             cptr, count, tvb_get_ptr(tvb, cptr, count),
611                             "%s: %s (wrong length, should be 21, is %d",
612                             proto_registrar_get_name(hf_index),
613                             tvb_bytes_to_str(tvb, cptr, count), count);
614                 }
615         } else {
616                 proto_tree_add_text(tree, tvb, 0, 0,
617                     "%s: <Bytes go past end of frame>",
618                     proto_registrar_get_name(hf_index));
619         }
620
621         return offset;
622 }
623
624 static int
625 add_tzoffset(tvbuff_t *tvb, int offset, int count, packet_info *pinfo,
626     proto_tree *tree, int convert, int hf_index)
627 {
628         gint16 tzoffset;
629
630         tzoffset = tvb_get_letohs(tvb, offset);
631         if (tzoffset < 0) {
632                 proto_tree_add_int_format(tree, hf_tzoffset, tvb, offset, 2,
633                     tzoffset, "%s: %s east of UTC",
634                     proto_registrar_get_name(hf_index),
635                     time_secs_to_str(-tzoffset*60));
636         } else if (tzoffset > 0) {
637                 proto_tree_add_int_format(tree, hf_tzoffset, tvb, offset, 2,
638                     tzoffset, "%s: %s west of UTC",
639                     proto_registrar_get_name(hf_index),
640                     time_secs_to_str(tzoffset*60));
641         } else {
642                 proto_tree_add_int_format(tree, hf_tzoffset, tvb, offset, 2,
643                     tzoffset, "%s: at UTC",
644                     proto_registrar_get_name(hf_index));
645         }
646         offset += 2;
647         return offset;
648 }
649
650 static int
651 add_timeinterval(tvbuff_t *tvb, int offset, int count, packet_info *pinfo,
652     proto_tree *tree, int convert, int hf_index)
653 {
654         guint16 timeinterval;
655
656         timeinterval = tvb_get_letohs(tvb, offset);
657         proto_tree_add_uint_format(tree, hf_timeinterval, tvb, offset, 2,
658            timeinterval, "%s: %f seconds", proto_registrar_get_name(hf_index),
659            timeinterval*.0001);
660         offset += 2;
661         return offset;
662 }
663
664 static int
665 add_logon_args(tvbuff_t *tvb, int offset, int count, packet_info *pinfo,
666     proto_tree *tree, int convert, int hf_index)
667 {
668         if (count != 54) {
669                 proto_tree_add_text(tree, tvb, offset, count,
670                    "Bogus NetWkstaUserLogon parameters: length is %d, should be 54",
671                    count);
672                 offset += count;
673                 return offset;
674         }
675
676         /* user name */
677         proto_tree_add_item(tree, hf_user_name, tvb, offset, 21, TRUE);
678         offset += 21;
679
680         /* pad1 */
681         offset += 1;
682
683         /* password */
684         proto_tree_add_item(tree, hf_password, tvb, offset, 15, TRUE);
685         offset += 15;
686
687         /* pad2 */
688         offset += 1;
689
690         /* workstation name */
691         proto_tree_add_item(tree, hf_workstation_name, tvb, offset, 16, TRUE);
692         offset += 16;
693         return offset;
694 }
695
696 /* 
697  * The following data structure describes the Remote API requests we
698  * understand.
699  *
700  * Simply fill in the number and parameter information.
701  * Try to keep them in order.
702  *
703  * We will extend this data structure as we try to decode more.
704  */
705
706 /*
707  * This is a pointer to a function to process an item.
708  */
709 typedef int     (*item_func)(tvbuff_t *, int, int, packet_info *, proto_tree *,
710                              int, int);
711
712 /*
713  * Type of an item; determines what parameter strings are valid for
714  * the item.
715  */
716 typedef enum {
717         PARAM_NONE,     /* for the end-of-list stopper */
718         PARAM_WORD,     /* 'W' or 'h' - 16-bit word */
719         PARAM_DWORD,    /* 'D' or 'i' - 32-bit word */
720         PARAM_BYTES,    /* 'B' or 'b' or 'g' or 'O' - one or more bytes */
721         PARAM_STRINGZ,  /* 'z' or 'O' - null-terminated string */
722 } param_type_t;
723
724 /*
725  * This structure describes an item; "hf_index" points to the index
726  * for the field corresponding to that item, "func" points to the
727  * function to use to add that item to the tree, and "type" is the
728  * type that the item is supposed to have.
729  */
730 typedef struct {
731         int             *hf_index;
732         item_func       func;
733         param_type_t    type;
734 } item_t;
735
736 /*
737  * This structure describes a list of items; each list of items
738  * has a corresponding detail level.
739  */
740 typedef struct {
741         int             level;
742         const item_t    *item_list;
743 } item_list_t;
744
745 struct lanman_desc {
746         int             lanman_num;
747         const item_t    *req;
748         proto_item      *(*req_data_item)(tvbuff_t *, packet_info *,
749                                           proto_tree *, int);
750         gint            *ett_req_data;
751         const item_t    *req_data;
752         const item_t    *req_aux_data;
753         const item_t    *resp;
754         const gchar     *resp_data_entry_list_label;
755         gint            *ett_data_entry_list;
756         proto_item      *(*resp_data_element_item)(tvbuff_t *, packet_info *,
757                                                    proto_tree *, int);
758         gint            *ett_resp_data_element_item;
759         const item_list_t *resp_data_list;
760         const item_t    *resp_aux_data;
761 };
762
763 static int no_hf = -1;  /* for padding crap */
764
765 static const item_t lm_params_req_netshareenum[] = {
766         { &hf_detail_level, add_detail_level, PARAM_WORD },
767         { &hf_recv_buf_len, add_word_param, PARAM_WORD },
768         { NULL, NULL, PARAM_NONE }
769 };
770
771 static const item_t lm_params_resp_netshareenum[] = {
772         { &hf_acount, add_word_param, PARAM_WORD },
773         { NULL, NULL, PARAM_NONE }
774 };
775
776 /*
777  * Create a subtree for a share.
778  */
779 static proto_item *
780 netshareenum_share_entry(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
781     int offset)
782 {
783         if (tree) {
784                 return proto_tree_add_text(tree, tvb, offset, -1,
785                     "Share %.13s", tvb_get_ptr(tvb, offset, 13));
786         } else
787                 return NULL;
788 }
789
790 static const item_t lm_null[] = {
791         { NULL, NULL, PARAM_NONE }
792 };
793
794 static const item_list_t lm_null_list[] = {
795         { -1, lm_null }
796 };
797
798 static const item_t lm_data_resp_netshareenum_1[] = {
799         { &hf_share_name, add_byte_param, PARAM_BYTES },
800         { &no_hf, add_pad_param, PARAM_BYTES },
801         { &hf_share_type, add_word_param, PARAM_WORD },
802         { &hf_share_comment, add_stringz_pointer_param, PARAM_STRINGZ },
803         { NULL, NULL, PARAM_NONE }
804 };
805
806 static const item_list_t lm_data_resp_netshareenum[] = {
807         { 1, lm_data_resp_netshareenum_1 },
808         { -1, lm_null }
809 };
810
811 static const item_t lm_params_req_netsharegetinfo[] = {
812         { &hf_share_name, add_string_param, PARAM_STRINGZ },
813         { &hf_detail_level, add_detail_level, PARAM_WORD },
814         { NULL, NULL, PARAM_NONE }
815 };
816
817 static const item_t lm_params_resp_netsharegetinfo[] = {
818         { &hf_abytes, add_word_param, PARAM_WORD },
819         { NULL, NULL, PARAM_NONE }
820 };
821
822 static const item_t lm_data_resp_netsharegetinfo_0[] = {
823         { &hf_share_name, add_byte_param, PARAM_BYTES },
824         { NULL, NULL, PARAM_NONE }
825 };
826
827 static const item_t lm_data_resp_netsharegetinfo_1[] = {
828         { &hf_share_name, add_byte_param, PARAM_BYTES },
829         { &no_hf, add_pad_param, PARAM_BYTES },
830         { &hf_share_type, add_word_param, PARAM_WORD },
831         { &hf_share_comment, add_stringz_pointer_param, PARAM_STRINGZ },
832         { NULL, NULL, PARAM_NONE }
833 };
834
835 static const item_t lm_data_resp_netsharegetinfo_2[] = {
836         { &hf_share_name, add_byte_param, PARAM_BYTES },
837         { &no_hf, add_pad_param, PARAM_BYTES },
838         { &hf_share_type, add_word_param, PARAM_WORD },
839         { &hf_share_comment, add_stringz_pointer_param, PARAM_STRINGZ },
840         { &hf_share_permissions, add_word_param, PARAM_WORD }, /* XXX - do as bit fields */
841         { &hf_share_max_uses, add_max_uses, PARAM_WORD },
842         { &hf_share_current_uses, add_word_param, PARAM_WORD },
843         { &hf_share_path, add_stringz_pointer_param, PARAM_STRINGZ },
844         { &hf_share_password, add_byte_param, PARAM_BYTES },
845         { NULL, NULL, PARAM_NONE }
846 };
847
848 static const item_list_t lm_data_resp_netsharegetinfo[] = {
849         { 0, lm_data_resp_netsharegetinfo_0 },
850         { 1, lm_data_resp_netsharegetinfo_1 },
851         { 2, lm_data_resp_netsharegetinfo_2 },
852         { -1, lm_null }
853 };
854
855 static const item_t lm_params_req_netservergetinfo[] = {
856         { &hf_detail_level, add_detail_level, PARAM_WORD },
857         { NULL, NULL, PARAM_NONE }
858 };
859
860 static const item_t lm_params_resp_netservergetinfo[] = {
861         { &hf_abytes, add_word_param, PARAM_WORD },
862         { NULL, NULL, PARAM_NONE }
863 };
864
865 static const item_t lm_data_serverinfo_0[] = {
866         { &hf_server_name, add_byte_param, PARAM_BYTES },
867         { NULL, NULL, PARAM_NONE }
868 };
869
870 static const item_t lm_data_serverinfo_1[] = {
871         { &hf_server_name, add_byte_param, PARAM_BYTES },
872         { &hf_server_major, add_byte_param, PARAM_BYTES },
873         { &hf_server_minor, add_byte_param, PARAM_BYTES },
874         { &no_hf, add_server_type, PARAM_DWORD },
875         { &hf_server_comment, add_stringz_pointer_param, PARAM_STRINGZ },
876         { NULL, NULL, PARAM_NONE }
877 };
878
879 static const item_list_t lm_data_serverinfo[] = {
880         { 0, lm_data_serverinfo_0 },
881         { 1, lm_data_serverinfo_1 },
882         { -1, lm_null }
883 };
884
885 static const item_t lm_params_req_netusergetinfo[] = {
886         { &hf_user_name, add_string_param, PARAM_STRINGZ },
887         { &hf_detail_level, add_detail_level, PARAM_WORD },
888         { NULL, NULL, PARAM_NONE }
889 };
890
891 static const item_t lm_params_resp_netusergetinfo[] = {
892         { &hf_abytes, add_word_param, PARAM_WORD },
893         { NULL, NULL, PARAM_NONE }
894 };
895
896 static const item_t lm_data_resp_netusergetinfo_11[] = {
897         { &hf_user_name, add_byte_param, PARAM_BYTES },
898         { &no_hf, add_pad_param, PARAM_BYTES },
899         { &hf_comment, add_stringz_pointer_param, PARAM_STRINGZ },
900         { &hf_user_comment, add_stringz_pointer_param, PARAM_STRINGZ },
901         { &hf_full_name, add_stringz_pointer_param, PARAM_STRINGZ },
902         { &hf_privilege_level, add_word_param, PARAM_WORD },
903         { &hf_operator_privileges, add_dword_param, PARAM_DWORD },
904         { &hf_password_age, add_reltime, PARAM_DWORD },
905         { &hf_homedir, add_stringz_pointer_param, PARAM_STRINGZ },
906         { &hf_parameters, add_stringz_pointer_param, PARAM_STRINGZ },
907         { &hf_last_logon, add_abstime_absent_unknown, PARAM_DWORD },
908         { &hf_last_logoff, add_abstime_absent_unknown, PARAM_DWORD },
909         { &hf_bad_pw_count, add_word_param, PARAM_WORD },
910         { &hf_num_logons, add_nlogons, PARAM_WORD },
911         { &hf_logon_server, add_stringz_pointer_param, PARAM_STRINGZ },
912         { &hf_country_code, add_word_param, PARAM_WORD },
913         { &hf_workstations, add_stringz_pointer_param, PARAM_STRINGZ },
914         { &hf_max_storage, add_max_storage, PARAM_DWORD },
915         { &hf_units_per_week, add_word_param, PARAM_WORD },
916         { &hf_logon_hours, add_logon_hours, PARAM_BYTES },
917         { &hf_code_page, add_word_param, PARAM_WORD },
918         { NULL, NULL, PARAM_NONE }
919 };
920
921 static const item_list_t lm_data_resp_netusergetinfo[] = {
922         { 11, lm_data_resp_netusergetinfo_11 },
923         { -1, lm_null }
924 };
925
926 static const item_t lm_params_req_netusergetgroups[] = {
927         { &hf_user_name, add_string_param, PARAM_STRINGZ },
928         { &hf_detail_level, add_detail_level, PARAM_WORD },
929         { NULL, NULL, PARAM_NONE }
930 };
931
932 static const item_t lm_params_resp_netusergetgroups[] = {
933         { &hf_abytes, add_word_param, PARAM_WORD },
934         { NULL, NULL, PARAM_NONE }
935 };
936
937 static const item_t lm_data_resp_netusergetgroups_0[] = {
938         { &hf_group_name, add_byte_param, PARAM_BYTES },
939         { NULL, NULL, PARAM_NONE }
940 };
941
942 static const item_list_t lm_data_resp_netusergetgroups[] = {
943         { 0, lm_data_resp_netusergetgroups_0 },
944         { -1, lm_null }
945 };
946
947 /*
948  * Has no detail level; make it the default.
949  */
950 static const item_t lm_data_resp_netremotetod_nolevel[] = {
951         { &hf_current_time, add_abstime_absent_unknown, PARAM_DWORD },
952         { &hf_msecs, add_dword_param, PARAM_DWORD },
953         { &hf_hour, add_byte_param, PARAM_BYTES },
954         { &hf_minute, add_byte_param, PARAM_BYTES },
955         { &hf_second, add_byte_param, PARAM_BYTES },
956         { &hf_hundredths, add_byte_param, PARAM_BYTES },
957         { &hf_tzoffset, add_tzoffset, PARAM_WORD },
958         { &hf_timeinterval, add_timeinterval, PARAM_WORD },
959         { &hf_day, add_byte_param, PARAM_BYTES },
960         { &hf_month, add_byte_param, PARAM_BYTES },
961         { &hf_year, add_word_param, PARAM_WORD },
962         { &hf_weekday, add_byte_param, PARAM_BYTES },
963         { NULL, NULL, PARAM_NONE }
964 };
965
966 static const item_list_t lm_data_resp_netremotetod[] = {
967         { -1, lm_data_resp_netremotetod_nolevel },
968 };
969
970 static const item_t lm_params_req_netserverenum2[] = {
971         { &hf_detail_level, add_detail_level, PARAM_WORD },
972         { &no_hf, add_server_type_info, PARAM_DWORD },
973         { &hf_enumeration_domain, add_string_param, PARAM_STRINGZ },
974         { NULL, NULL, PARAM_NONE }
975 };
976
977 /*
978  * Create a subtree for a server.
979  */
980 static proto_item *
981 netserverenum2_server_entry(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
982     int offset)
983 {
984         if (tree) {
985                 return proto_tree_add_text(tree, tvb, offset, -1,
986                             "Server %.16s", tvb_get_ptr(tvb, offset, 16));
987         } else
988                 return NULL;
989 }
990
991 static const item_t lm_params_resp_netserverenum2[] = {
992         { &hf_acount, add_word_param, PARAM_WORD },
993         { NULL, NULL, PARAM_NONE }
994 };
995
996 static const item_t lm_params_req_netwkstagetinfo[] = {
997         { &hf_detail_level, add_detail_level, PARAM_WORD },
998         { NULL, NULL, PARAM_NONE }
999 };
1000
1001 static const item_t lm_params_resp_netwkstagetinfo[] = {
1002         { &hf_abytes, add_word_param, PARAM_WORD },
1003         { NULL, NULL, PARAM_NONE }
1004 };
1005
1006 static const item_t lm_data_resp_netwkstagetinfo_10[] = {
1007         { &hf_computer_name, add_stringz_pointer_param, PARAM_STRINGZ },
1008         { &hf_user_name, add_stringz_pointer_param, PARAM_STRINGZ },
1009         { &hf_workstation_domain, add_stringz_pointer_param, PARAM_STRINGZ },
1010         { &hf_workstation_major, add_byte_param, PARAM_BYTES },
1011         { &hf_workstation_minor, add_byte_param, PARAM_BYTES },
1012         { &hf_logon_domain, add_stringz_pointer_param, PARAM_STRINGZ },
1013         { &hf_other_domains, add_stringz_pointer_param, PARAM_STRINGZ },
1014         { NULL, NULL, PARAM_NONE }
1015 };
1016
1017 static const item_list_t lm_data_resp_netwkstagetinfo[] = {
1018         { 10, lm_data_resp_netwkstagetinfo_10 },
1019         { -1, lm_null }
1020 };
1021
1022 static const item_t lm_params_req_netwkstauserlogon[] = {
1023         { &no_hf, add_stringz_pointer_param, PARAM_STRINGZ },
1024         { &no_hf, add_stringz_pointer_param, PARAM_STRINGZ },
1025         { &hf_detail_level, add_detail_level, PARAM_WORD },
1026         { &no_hf, add_logon_args, PARAM_BYTES },
1027         { &hf_ustruct_size, add_word_param, PARAM_WORD },
1028         { NULL, NULL, PARAM_NONE }
1029 };
1030
1031 static const item_t lm_params_resp_netwkstauserlogon[] = {
1032         { &hf_abytes, add_word_param, PARAM_WORD },
1033         { NULL, NULL, PARAM_NONE }
1034 };
1035
1036 static const item_t lm_data_resp_netwkstauserlogon_1[] = {
1037         { &hf_logon_code, add_word_param, PARAM_WORD },
1038         { &hf_user_name, add_byte_param, PARAM_BYTES },
1039         { &no_hf, add_pad_param, PARAM_BYTES },
1040         { &hf_privilege_level, add_word_param, PARAM_WORD },
1041         { &hf_operator_privileges, add_dword_param, PARAM_DWORD },
1042         { &hf_num_logons, add_nlogons, PARAM_WORD },
1043         { &hf_bad_pw_count, add_word_param, PARAM_WORD },
1044         { &hf_last_logon, add_abstime_absent_unknown, PARAM_DWORD },
1045         { &hf_last_logoff, add_abstime_absent_unknown, PARAM_DWORD },
1046         { &hf_logoff_time, add_abstime_absent_never, PARAM_DWORD },
1047         { &hf_kickoff_time, add_abstime_absent_never, PARAM_DWORD },
1048         { &hf_password_age, add_reltime, PARAM_DWORD },
1049         { &hf_password_can_change, add_abstime_absent_never, PARAM_DWORD },
1050         { &hf_password_must_change, add_abstime_absent_never, PARAM_DWORD },
1051         { &hf_server_name, add_stringz_pointer_param, PARAM_STRINGZ },
1052         { &hf_logon_domain, add_stringz_pointer_param, PARAM_STRINGZ },
1053         { &hf_script_path, add_stringz_pointer_param, PARAM_STRINGZ },
1054         { &hf_reserved, add_dword_param, PARAM_DWORD },
1055         { NULL, NULL, PARAM_NONE }
1056 };
1057
1058 static const item_list_t lm_data_resp_netwkstauserlogon[] = {
1059         { 1, lm_data_resp_netwkstauserlogon_1 },
1060         { -1, lm_null }
1061 };
1062
1063 static const item_t lm_params_req_netwkstauserlogoff[] = {
1064         { &hf_user_name, add_byte_param, PARAM_BYTES },
1065         { &no_hf, add_pad_param, PARAM_BYTES },
1066         { &hf_workstation_name, add_byte_param, PARAM_BYTES },
1067         { NULL, NULL, PARAM_NONE }
1068 };
1069
1070 static const item_t lm_params_resp_netwkstauserlogoff[] = {
1071         { &hf_abytes, add_word_param, PARAM_WORD },
1072         { NULL, NULL, PARAM_NONE }
1073 };
1074
1075 static const item_t lm_data_resp_netwkstauserlogoff_1[] = {
1076         { &hf_logoff_code, add_word_param, PARAM_WORD },
1077         { &hf_duration, add_reltime, PARAM_DWORD },
1078         { &hf_num_logons, add_nlogons, PARAM_WORD },
1079         { NULL, NULL, PARAM_NONE }
1080 };
1081
1082 static const item_list_t lm_data_resp_netwkstauserlogoff[] = {
1083         { 1, lm_data_resp_netwkstauserlogoff_1 },
1084         { -1, lm_null }
1085 };
1086
1087 static const item_t lm_params_req_samoemchangepassword[] = {
1088         { &hf_user_name, add_string_param, PARAM_STRINGZ },
1089         { NULL, NULL, PARAM_NONE }
1090 };
1091
1092 static const item_t lm_data_req_samoemchangepassword[] = {
1093         { &hf_new_password, add_byte_param, PARAM_BYTES },
1094         { &hf_old_password, add_byte_param, PARAM_BYTES },
1095         { NULL, NULL, PARAM_NONE }
1096 };
1097
1098 #define API_NetShareEnum                0
1099 #define API_NetShareGetInfo             1
1100 #define API_NetShareSetInfo             2
1101 #define API_NetShareAdd                 3
1102 #define API_NetShareDel                 4
1103 #define API_NetShareCheck               5
1104 #define API_NetSessionEnum              6
1105 #define API_NetSessionGetInfo           7
1106 #define API_NetSessionDel               8
1107 #define API_WconnectionEnum             9
1108 #define API_NetFileEnum                 10
1109 #define API_NetFileGetInfo              11
1110 #define API_NetFileClose                12
1111 #define API_NetServerGetInfo            13
1112 #define API_NetServerSetInfo            14
1113 #define API_NetServerDiskEnum           15
1114 #define API_NetServerAdminCommand       16
1115 #define API_NetAuditOpen                17
1116 #define API_NetAuditClear               18
1117 #define API_NetErrorLogOpen             19
1118 #define API_NetErrorLogClear            20
1119 #define API_NetCharDevEnum              21
1120 #define API_NetCharDevGetInfo           22
1121 #define API_NetCharDevControl           23
1122 #define API_NetCharDevQEnum             24
1123 #define API_NetCharDevQGetInfo          25
1124 #define API_NetCharDevQSetInfo          26
1125 #define API_NetCharDevQPurge            27
1126 #define API_NetCharDevQPurgeSelf        28
1127 #define API_NetMessageNameEnum          29
1128 #define API_NetMessageNameGetInfo       30
1129 #define API_NetMessageNameAdd           31
1130 #define API_NetMessageNameDel           32
1131 #define API_NetMessageNameFwd           33
1132 #define API_NetMessageNameUnFwd         34
1133 #define API_NetMessageBufferSend        35
1134 #define API_NetMessageFileSend          36
1135 #define API_NetMessageLogFileSet        37
1136 #define API_NetMessageLogFileGet        38
1137 #define API_NetServiceEnum              39
1138 #define API_NetServiceInstall           40
1139 #define API_NetServiceControl           41
1140 #define API_NetAccessEnum               42
1141 #define API_NetAccessGetInfo            43
1142 #define API_NetAccessSetInfo            44
1143 #define API_NetAccessAdd                45
1144 #define API_NetAccessDel                46
1145 #define API_NetGroupEnum                47
1146 #define API_NetGroupAdd                 48
1147 #define API_NetGroupDel                 49
1148 #define API_NetGroupAddUser             50
1149 #define API_NetGroupDelUser             51
1150 #define API_NetGroupGetUsers            52
1151 #define API_NetUserEnum                 53
1152 #define API_NetUserAdd                  54
1153 #define API_NetUserDel                  55
1154 #define API_NetUserGetInfo              56
1155 #define API_NetUserSetInfo              57
1156 #define API_NetUserPasswordSet          58
1157 #define API_NetUserGetGroups            59
1158 /*This line and number replaced a Dead Entry for 60 */
1159 /*This line and number replaced a Dead Entry for 61 */
1160 #define API_NetWkstaSetUID              62
1161 #define API_NetWkstaGetInfo             63
1162 #define API_NetWkstaSetInfo             64
1163 #define API_NetUseEnum                  65
1164 #define API_NetUseAdd                   66
1165 #define API_NetUseDel                   67
1166 #define API_NetUseGetInfo               68
1167 #define API_WPrintQEnum                 69
1168 #define API_WPrintQGetInfo              70
1169 #define API_WPrintQSetInfo              71
1170 #define API_WPrintQAdd                  72
1171 #define API_WPrintQDel                  73
1172 #define API_WPrintQPause                74
1173 #define API_WPrintQContinue             75
1174 #define API_WPrintJobEnum               76
1175 #define API_WPrintJobGetInfo            77
1176 #define API_WPrintJobSetInfo_OLD        78
1177 /* This line and number replaced a Dead Entry for 79 */
1178 /* This line and number replaced a Dead Entry for 80 */
1179 #define API_WPrintJobDel                81
1180 #define API_WPrintJobPause              82
1181 #define API_WPrintJobContinue           83
1182 #define API_WPrintDestEnum              84
1183 #define API_WPrintDestGetInfo           85
1184 #define API_WPrintDestControl           86
1185 #define API_NetProfileSave              87
1186 #define API_NetProfileLoad              88
1187 #define API_NetStatisticsGet            89
1188 #define API_NetStatisticsClear          90
1189 #define API_NetRemoteTOD                91
1190 #define API_WNetBiosEnum                92
1191 #define API_WNetBiosGetInfo             93
1192 #define API_NetServerEnum               94
1193 #define API_I_NetServerEnum             95
1194 #define API_NetServiceGetInfo           96
1195 /* This line and number replaced a Dead Entry for 97 */
1196 /* This line and number replaced a Dead Entry for 98 */
1197 /* This line and number replaced a Dead Entry for 99 */
1198 /* This line and number replaced a Dead Entry for 100 */
1199 /* This line and number replaced a Dead Entry for 101 */
1200 /* This line and number replaced a Dead Entry for 102 */
1201 #define API_WPrintQPurge                103
1202 #define API_NetServerEnum2              104
1203 #define API_NetAccessGetUserPerms       105
1204 #define API_NetGroupGetInfo             106
1205 #define API_NetGroupSetInfo             107
1206 #define API_NetGroupSetUsers            108
1207 #define API_NetUserSetGroups            109
1208 #define API_NetUserModalsGet            110
1209 #define API_NetUserModalsSet            111
1210 #define API_NetFileEnum2                112
1211 #define API_NetUserAdd2                 113
1212 #define API_NetUserSetInfo2             114
1213 #define API_NetUserPasswordSet2         115
1214 #define API_I_NetServerEnum2            116
1215 #define API_NetConfigGet2               117
1216 #define API_NetConfigGetAll2            118
1217 #define API_NetGetDCName                119
1218 #define API_NetHandleGetInfo            120
1219 #define API_NetHandleSetInfo            121
1220 #define API_NetStatisticsGet2           122
1221 #define API_WBuildGetInfo               123
1222 #define API_NetFileGetInfo2             124
1223 #define API_NetFileClose2               125
1224 #define API_NetServerReqChallenge       126
1225 #define API_NetServerAuthenticate       127
1226 #define API_NetServerPasswordSet        128
1227 #define API_WNetAccountDeltas           129
1228 #define API_WNetAccountSync             130
1229 #define API_NetUserEnum2                131
1230 #define API_NetWkstaUserLogon           132
1231 #define API_NetWkstaUserLogoff          133
1232 #define API_NetLogonEnum                134
1233 #define API_NetErrorLogRead             135
1234 #define API_I_NetPathType               136
1235 #define API_I_NetPathCanonicalize       137
1236 #define API_I_NetPathCompare            138
1237 #define API_I_NetNameValidate           139
1238 #define API_I_NetNameCanonicalize       140
1239 #define API_I_NetNameCompare            141
1240 #define API_NetAuditRead                142
1241 #define API_WPrintDestAdd               143
1242 #define API_WPrintDestSetInfo           144
1243 #define API_WPrintDestDel               145
1244 #define API_NetUserValidate2            146
1245 #define API_WPrintJobSetInfo            147
1246 #define API_TI_NetServerDiskEnum        148
1247 #define API_TI_NetServerDiskGetInfo     149
1248 #define API_TI_FTVerifyMirror           150
1249 #define API_TI_FTAbortVerify            151
1250 #define API_TI_FTGetInfo                152
1251 #define API_TI_FTSetInfo                153
1252 #define API_TI_FTLockDisk               154
1253 #define API_TI_FTFixError               155
1254 #define API_TI_FTAbortFix               156
1255 #define API_TI_FTDiagnoseError          157
1256 #define API_TI_FTGetDriveStats          158
1257 /* This line and number replaced a Dead Entry for 159 */
1258 #define API_TI_FTErrorGetInfo           160
1259 /* This line and number replaced a Dead Entry for 161 */
1260 /* This line and number replaced a Dead Entry for 162 */
1261 #define API_NetAccessCheck              163
1262 #define API_NetAlertRaise               164
1263 #define API_NetAlertStart               165
1264 #define API_NetAlertStop                166
1265 #define API_NetAuditWrite               167
1266 #define API_NetIRemoteAPI               168
1267 #define API_NetServiceStatus            169
1268 #define API_I_NetServerRegister         170
1269 #define API_I_NetServerDeregister       171
1270 #define API_I_NetSessionEntryMake       172
1271 #define API_I_NetSessionEntryClear      173
1272 #define API_I_NetSessionEntryGetInfo    174
1273 #define API_I_NetSessionEntrySetInfo    175
1274 #define API_I_NetConnectionEntryMake    176
1275 #define API_I_NetConnectionEntryClear   177
1276 #define API_I_NetConnectionEntrySetInfo 178
1277 #define API_I_NetConnectionEntryGetInfo 179
1278 #define API_I_NetFileEntryMake          180
1279 #define API_I_NetFileEntryClear         181
1280 #define API_I_NetFileEntrySetInfo       182
1281 #define API_I_NetFileEntryGetInfo       183
1282 #define API_AltSrvMessageBufferSend     184
1283 #define API_AltSrvMessageFileSend       185
1284 #define API_wI_NetRplWkstaEnum          186
1285 #define API_wI_NetRplWkstaGetInfo       187
1286 #define API_wI_NetRplWkstaSetInfo       188
1287 #define API_wI_NetRplWkstaAdd           189
1288 #define API_wI_NetRplWkstaDel           190
1289 #define API_wI_NetRplProfileEnum        191
1290 #define API_wI_NetRplProfileGetInfo     192
1291 #define API_wI_NetRplProfileSetInfo     193
1292 #define API_wI_NetRplProfileAdd         194
1293 #define API_wI_NetRplProfileDel         195
1294 #define API_wI_NetRplProfileClone       196
1295 #define API_wI_NetRplBaseProfileEnum    197
1296 /* This line and number replaced a Dead Entry for 198 */
1297 /* This line and number replaced a Dead Entry for 199 */
1298 /* This line and number replaced a Dead Entry for 200 */
1299 #define API_WIServerSetInfo             201
1300 /* This line and number replaced a Dead Entry for 202 */
1301 /* This line and number replaced a Dead Entry for 203 */
1302 /* This line and number replaced a Dead Entry for 204 */
1303 #define API_WPrintDriverEnum            205
1304 #define API_WPrintQProcessorEnum        206
1305 #define API_WPrintPortEnum              207
1306 #define API_WNetWriteUpdateLog          208
1307 #define API_WNetAccountUpdate           209
1308 #define API_WNetAccountConfirmUpdate    210
1309 #define API_NetConfigSet                211
1310 #define API_WAccountsReplicate          212
1311 /* 213 is used by WfW */
1312 #define API_SamOEMChgPasswordUser2_P    214
1313 #define API_NetServerEnum3              215
1314 /* XXX - what about 216 through 249? */
1315 #define API_WPrintDriverGetInfo         250
1316 #define API_WPrintDriverSetInfo         251
1317 #define API_NetAliasAdd                 252
1318 #define API_NetAliasDel                 253
1319 #define API_NetAliasGetInfo             254
1320 #define API_NetAliasSetInfo             255
1321 #define API_NetAliasEnum                256
1322 #define API_NetUserGetLogonAsn          257
1323 #define API_NetUserSetLogonAsn          258
1324 #define API_NetUserGetAppSel            259
1325 #define API_NetUserSetAppSel            260
1326 #define API_NetAppAdd                   261
1327 #define API_NetAppDel                   262
1328 #define API_NetAppGetInfo               263
1329 #define API_NetAppSetInfo               264
1330 #define API_NetAppEnum                  265
1331 #define API_NetUserDCDBInit             266
1332 #define API_NetDASDAdd                  267
1333 #define API_NetDASDDel                  268
1334 #define API_NetDASDGetInfo              269
1335 #define API_NetDASDSetInfo              270
1336 #define API_NetDASDEnum                 271
1337 #define API_NetDASDCheck                272
1338 #define API_NetDASDCtl                  273
1339 #define API_NetUserRemoteLogonCheck     274
1340 #define API_NetUserPasswordSet3         275
1341 #define API_NetCreateRIPLMachine        276
1342 #define API_NetDeleteRIPLMachine        277
1343 #define API_NetGetRIPLMachineInfo       278
1344 #define API_NetSetRIPLMachineInfo       279
1345 #define API_NetEnumRIPLMachine          280
1346 #define API_I_ShareAdd                  281
1347 #define API_I_AliasEnum                 282
1348 #define API_NetAccessApply              283
1349 #define API_WPrt16Query                 284
1350 #define API_WPrt16Set                   285
1351 #define API_NetUserDel100               286
1352 #define API_NetUserRemoteLogonCheck2    287
1353 #define API_WRemoteTODSet               294
1354 #define API_WPrintJobMoveAll            295
1355 #define API_W16AppParmAdd               296
1356 #define API_W16AppParmDel               297
1357 #define API_W16AppParmGet               298
1358 #define API_W16AppParmSet               299
1359 #define API_W16RIPLMachineCreate        300
1360 #define API_W16RIPLMachineGetInfo       301
1361 #define API_W16RIPLMachineSetInfo       302
1362 #define API_W16RIPLMachineEnum          303
1363 #define API_W16RIPLMachineListParmEnum  304
1364 #define API_W16RIPLMachClassGetInfo     305
1365 #define API_W16RIPLMachClassEnum        306
1366 #define API_W16RIPLMachClassCreate      307
1367 #define API_W16RIPLMachClassSetInfo     308
1368 #define API_W16RIPLMachClassDelete      309
1369 #define API_W16RIPLMachClassLPEnum      310
1370 #define API_W16RIPLMachineDelete        311
1371 #define API_W16WSLevelGetInfo           312
1372 #define API_NetServerNameAdd            313
1373 #define API_NetServerNameDel            314
1374 #define API_NetServerNameEnum           315
1375 #define API_I_WDASDEnum                 316
1376 #define API_I_WDASDEnumTerminate        317
1377 #define API_I_WDASDSetInfo2             318
1378
1379 static const struct lanman_desc lmd[] = {
1380         { API_NetShareEnum,
1381           lm_params_req_netshareenum,
1382           NULL,
1383           NULL,
1384           lm_null,
1385           lm_null,
1386           lm_params_resp_netshareenum,
1387           "Available Shares",
1388           &ett_lanman_shares,
1389           netshareenum_share_entry,
1390           &ett_lanman_share,
1391           lm_data_resp_netshareenum,
1392           lm_null },
1393
1394         { API_NetShareGetInfo,
1395           lm_params_req_netsharegetinfo,
1396           NULL,
1397           NULL,
1398           lm_null,
1399           lm_null,
1400           lm_params_resp_netsharegetinfo,
1401           NULL,
1402           NULL,
1403           NULL,
1404           NULL,
1405           lm_data_resp_netsharegetinfo,
1406           lm_null },
1407
1408         { API_NetServerGetInfo, 
1409           lm_params_req_netservergetinfo,
1410           NULL,
1411           NULL,
1412           lm_null,
1413           lm_null,
1414           lm_params_resp_netservergetinfo,
1415           NULL,
1416           NULL,
1417           NULL,
1418           NULL,
1419           lm_data_serverinfo,
1420           lm_null },
1421
1422         { API_NetUserGetInfo,
1423           lm_params_req_netusergetinfo,
1424           NULL,
1425           NULL,
1426           lm_null,
1427           lm_null,
1428           lm_params_resp_netusergetinfo,
1429           NULL,
1430           NULL,
1431           NULL,
1432           NULL,
1433           lm_data_resp_netusergetinfo,
1434           lm_null },
1435
1436         { API_NetUserGetGroups,
1437           lm_params_req_netusergetgroups,
1438           NULL,
1439           NULL,
1440           lm_null,
1441           lm_null,
1442           lm_params_resp_netusergetgroups,
1443           "Groups",
1444           &ett_lanman_groups,
1445           NULL,
1446           NULL,
1447           lm_data_resp_netusergetgroups,
1448           lm_null },
1449
1450         { API_NetRemoteTOD,
1451           lm_null,
1452           NULL,
1453           NULL,
1454           lm_null,
1455           lm_null,
1456           lm_null,
1457           NULL,
1458           NULL,
1459           NULL,
1460           NULL,
1461           lm_data_resp_netremotetod,
1462           lm_null },
1463
1464         { API_NetServerEnum2,
1465           lm_params_req_netserverenum2,
1466           NULL,
1467           NULL,
1468           lm_null,
1469           lm_null,
1470           lm_params_resp_netserverenum2,
1471           "Servers",
1472           &ett_lanman_servers,
1473           netserverenum2_server_entry,
1474           &ett_lanman_server,
1475           lm_data_serverinfo,
1476           lm_null },
1477
1478         { API_NetWkstaGetInfo,
1479           lm_params_req_netwkstagetinfo,
1480           NULL,
1481           NULL,
1482           lm_null,
1483           lm_null,
1484           lm_params_resp_netwkstagetinfo,
1485           NULL,
1486           NULL,
1487           NULL,
1488           NULL,
1489           lm_data_resp_netwkstagetinfo,
1490           lm_null },
1491
1492         { API_NetWkstaUserLogon,
1493           lm_params_req_netwkstauserlogon,
1494           NULL,
1495           NULL,
1496           lm_null,
1497           lm_null,
1498           lm_params_resp_netwkstauserlogon,
1499           NULL,
1500           NULL,
1501           NULL,
1502           NULL,
1503           lm_data_resp_netwkstauserlogon,
1504           lm_null },
1505
1506         { API_NetWkstaUserLogoff,
1507           lm_params_req_netwkstauserlogoff,
1508           NULL,
1509           NULL,
1510           lm_null,
1511           lm_null,
1512           lm_params_resp_netwkstauserlogoff,
1513           NULL,
1514           NULL,
1515           NULL,
1516           NULL,
1517           lm_data_resp_netwkstauserlogoff,
1518           lm_null },
1519
1520         { API_SamOEMChgPasswordUser2_P,
1521           lm_params_req_samoemchangepassword,
1522           NULL,
1523           NULL,
1524           lm_data_req_samoemchangepassword,
1525           lm_null,
1526           lm_null,
1527           NULL,
1528           NULL,
1529           NULL,
1530           NULL,
1531           lm_null_list,
1532           lm_null },
1533
1534         { -1,
1535           lm_null,
1536           NULL,
1537           NULL,
1538           lm_null,
1539           lm_null,
1540           lm_null,
1541           NULL,
1542           NULL,
1543           NULL,
1544           &ett_lanman_unknown_entry,
1545           lm_null_list,
1546           lm_null }
1547 };
1548
1549 static const struct lanman_desc *
1550 find_lanman(int lanman_num)
1551 {
1552         int i;
1553
1554         for (i = 0; lmd[i].lanman_num != -1; i++) {
1555                 if (lmd[i].lanman_num == lanman_num)
1556                         break;
1557         }
1558         return &lmd[i];
1559 }
1560
1561 static const guchar *
1562 get_count(const guchar *desc, int *countp)
1563 {
1564         int count = 0;
1565         guchar c;
1566
1567         if (!isdigit(*desc)) {
1568                 *countp = 1;    /* no count was supplied */
1569                 return desc;
1570         }
1571
1572         while ((c = *desc) != '\0' && isdigit(c)) {
1573                 count = (count * 10) + c - '0';
1574                 desc++;
1575         }
1576
1577         *countp = count;        /* XXX - what if it's 0? */
1578         return desc;
1579 }
1580
1581 static int
1582 dissect_request_parameters(tvbuff_t *tvb, int offset, packet_info *pinfo,
1583     proto_tree *tree, const guchar *desc, const item_t *items,
1584     gboolean *has_data_p)
1585 {
1586         guint c;
1587         guint16 WParam;
1588         guint32 LParam;
1589         guint string_len;
1590         int count;
1591
1592         *has_data_p = FALSE;
1593         while ((c = *desc++) != '\0') {
1594                 switch (c) {
1595
1596                 case 'W':
1597                         /*
1598                          * A 16-bit word value in the request.
1599                          */
1600                         if (items->func == NULL) {
1601                                 /*
1602                                  * We've run out of items in the table;
1603                                  * fall back on the default.
1604                                  */
1605                                 offset = add_word_param(tvb, offset, 0, pinfo,
1606                                     tree, 0, -1);
1607                         } else if (items->type != PARAM_WORD) {
1608                                 /*
1609                                  * Descriptor character is 'W', but this
1610                                  * isn't a word parameter.
1611                                  */
1612                                 WParam = tvb_get_letohs(tvb, offset);
1613                                 proto_tree_add_text(tree, tvb, offset, 2,
1614                                     "%s: Value is %u (0x%04X), type is wrong (W)",
1615                                     (*items->hf_index == -1) ?
1616                                       "Word Param" :
1617                                       proto_registrar_get_name(*items->hf_index),
1618                                     WParam, WParam);
1619                                 offset += 2;
1620                                 items++;
1621                         } else {
1622                                 offset = (*items->func)(tvb, offset, 0, pinfo,
1623                                     tree, 0, *items->hf_index);
1624                                 items++;
1625                         }
1626                         break;
1627
1628                 case 'D':
1629                         /*
1630                          * A 32-bit doubleword value in the request.
1631                          */
1632                         if (items->func == NULL) {
1633                                 /*
1634                                  * We've run out of items in the table;
1635                                  * fall back on the default.
1636                                  */
1637                                 offset = add_dword_param(tvb, offset, 0, pinfo,
1638                                     tree, 0, -1);
1639                         } else if (items->type != PARAM_DWORD) {
1640                                 /*
1641                                  * Descriptor character is 'D', but this
1642                                  * isn't a doubleword parameter.
1643                                  */
1644                                 LParam = tvb_get_letohl(tvb, offset);
1645                                 proto_tree_add_text(tree, tvb, offset, 2,
1646                                     "%s: Value is %u (0x%08X), type is wrong (D)",
1647                                     (*items->hf_index == -1) ?
1648                                       "Doubleword Param" :
1649                                       proto_registrar_get_name(*items->hf_index),
1650                                     LParam, LParam);
1651                                 offset += 4;
1652                                 items++;
1653                         } else {
1654                                 offset = (*items->func)(tvb, offset, 0, pinfo,
1655                                     tree, 0, *items->hf_index);
1656                                 items++;
1657                         }
1658                         break;
1659
1660                 case 'b':
1661                         /*
1662                          * A byte or multi-byte value in the request.
1663                          */
1664                         desc = get_count(desc, &count);
1665                         if (items->func == NULL) {
1666                                 /*
1667                                  * We've run out of items in the table;
1668                                  * fall back on the default.
1669                                  */
1670                                 offset = add_byte_param(tvb, offset, count,
1671                                     pinfo, tree, 0, -1);
1672                         } else if (items->type != PARAM_BYTES) {
1673                                 /*
1674                                  * Descriptor character is 'b', but this
1675                                  * isn't a byte/bytes parameter.
1676                                  */
1677                                 proto_tree_add_text(tree, tvb, offset, count,
1678                                     "%s: Value is %s, type is wrong (b)",
1679                                     (*items->hf_index == -1) ?
1680                                       "Byte Param" :
1681                                       proto_registrar_get_name(*items->hf_index),
1682                                     tvb_bytes_to_str(tvb, offset, count));
1683                                 offset += count;
1684                                 items++;
1685                         } else {
1686                                 offset = (*items->func)(tvb, offset, count,
1687                                     pinfo, tree, 0, *items->hf_index);
1688                                 items++;
1689                         }
1690                         break;
1691
1692                 case 'O':
1693                         /*
1694                          * A null pointer.
1695                          */
1696                         if (items->func == NULL) {
1697                                 /*
1698                                  * We've run out of items in the table;
1699                                  * fall back on the default.
1700                                  */
1701                                 add_null_pointer_param(tvb, offset, 0,
1702                                     pinfo, tree, 0, -1);
1703                         } else {
1704                                 /*
1705                                  * If "*items->hf_index" is -1, this is
1706                                  * a reserved must-be-null field; don't
1707                                  * clutter the protocol tree by putting
1708                                  * it in.
1709                                  */
1710                                 if (*items->hf_index != -1) {
1711                                         add_null_pointer_param(tvb,
1712                                             offset, 0, pinfo, tree, 0,
1713                                             *items->hf_index);
1714                                 }
1715                                 items++;
1716                         }
1717                         break;
1718
1719                 case 'z':
1720                         /*
1721                          * A null-terminated ASCII string.
1722                          */
1723                         if (items->func == NULL) {
1724                                 /*
1725                                  * We've run out of items in the table;
1726                                  * fall back on the default.
1727                                  */
1728                                 offset = add_string_param(tvb, offset, 0,
1729                                     pinfo, tree, 0, -1);
1730                         } else if (items->type != PARAM_STRINGZ) {
1731                                 /*
1732                                  * Descriptor character is 'z', but this
1733                                  * isn't a string parameter.
1734                                  */
1735                                 string_len = tvb_strsize(tvb, offset);
1736                                 proto_tree_add_text(tree, tvb, offset, string_len,
1737                                     "%s: Value is %s, type is wrong (z)",
1738                                     (*items->hf_index == -1) ?
1739                                       "String Param" :
1740                                       proto_registrar_get_name(*items->hf_index),
1741                                     tvb_format_text(tvb, offset, string_len));
1742                                 offset += string_len;
1743                                 items++;
1744                         } else {
1745                                 offset = (*items->func)(tvb, offset, 0,
1746                                     pinfo, tree, 0, *items->hf_index);
1747                                 items++;
1748                         }
1749                         break;
1750
1751                 case 'F':
1752                         /*
1753                          * One or more pad bytes.
1754                          */
1755                         desc = get_count(desc, &count);
1756                         proto_tree_add_text(tree, tvb, offset, count,
1757                             "%s", "Padding");
1758                         offset += count;
1759                         break;
1760
1761                 case 'L':
1762                         /*
1763                          * 16-bit receive buffer length.
1764                          */
1765                         proto_tree_add_item(tree, hf_recv_buf_len, tvb,
1766                             offset, 2, TRUE);
1767                         offset += 2;
1768                         break;
1769
1770                 case 's':
1771                         /*
1772                          * 32-bit send buffer offset.
1773                          * This appears not to be sent over the wire.
1774                          */
1775                         *has_data_p = TRUE;
1776                         break;
1777
1778                 case 'T':
1779                         /*
1780                          * 16-bit send buffer length.
1781                          * This also appears not to be sent over the wire.
1782                          */
1783                         break;
1784
1785                 default:
1786                         break;
1787                 }
1788         }
1789         return offset;
1790 }
1791
1792 static int
1793 dissect_response_parameters(tvbuff_t *tvb, int offset, packet_info *pinfo,
1794     proto_tree *tree, const guchar *desc, const item_t *items,
1795     gboolean *has_data_p, gboolean *has_ent_count_p, guint16 *ent_count_p)
1796 {
1797         guint c;
1798         guint16 WParam;
1799         guint32 LParam;
1800         int count;
1801
1802         *has_data_p = FALSE;
1803         *has_ent_count_p = FALSE;
1804         while ((c = *desc++) != '\0') {
1805                 switch (c) {
1806
1807                 case 'r':
1808                         /*
1809                          * 32-bit receive buffer offset.
1810                          */
1811                         *has_data_p = TRUE;
1812                         break;
1813
1814                 case 'g':
1815                         /*
1816                          * A byte or series of bytes is returned.
1817                          */
1818                         desc = get_count(desc, &count);
1819                         if (items->func == NULL) {
1820                                 /*
1821                                  * We've run out of items in the table;
1822                                  * fall back on the default.
1823                                  */
1824                                 offset = add_byte_param(tvb, offset, count,
1825                                     pinfo, tree, 0, -1);
1826                         } else if (items->type != PARAM_BYTES) {
1827                                 /*
1828                                  * Descriptor character is 'b', but this
1829                                  * isn't a byte/bytes parameter.
1830                                  */
1831                                 proto_tree_add_text(tree, tvb, offset, count,
1832                                     "%s: Value is %s, type is wrong (g)",
1833                                     (*items->hf_index == -1) ?
1834                                       "Byte Param" :
1835                                       proto_registrar_get_name(*items->hf_index),
1836                                     tvb_bytes_to_str(tvb, offset, count));
1837                                 offset += count;
1838                                 items++;
1839                         } else {
1840                                 offset = (*items->func)(tvb, offset, count,
1841                                     pinfo, tree, 0, *items->hf_index);
1842                                 items++;
1843                         }
1844                         break;
1845
1846                 case 'h':
1847                         /*
1848                          * A 16-bit word is received.
1849                          */
1850                         if (items->func == NULL) {
1851                                 /*
1852                                  * We've run out of items in the table;
1853                                  * fall back on the default.
1854                                  */
1855                                 offset = add_word_param(tvb, offset, 0, pinfo,
1856                                     tree, 0, -1);
1857                         } else if (items->type != PARAM_WORD) {
1858                                 /*
1859                                  * Descriptor character is 'h', but this
1860                                  * isn't a word parameter.
1861                                  */
1862                                 WParam = tvb_get_letohs(tvb, offset);
1863                                 proto_tree_add_text(tree, tvb, offset, 2,
1864                                     "%s: Value is %u (0x%04X), type is wrong (W)",
1865                                     (*items->hf_index == -1) ?
1866                                       "Word Param" :
1867                                       proto_registrar_get_name(*items->hf_index),
1868                                     WParam, WParam);
1869                                 offset += 2;
1870                                 items++;
1871                         } else {
1872                                 offset = (*items->func)(tvb, offset, 0, pinfo,
1873                                     tree, 0, *items->hf_index);
1874                                 items++;
1875                         }
1876                         break;
1877
1878                 case 'i':
1879                         /*
1880                          * A 32-bit doubleword is received.
1881                          */
1882                         if (items->func == NULL) {
1883                                 /*
1884                                  * We've run out of items in the table;
1885                                  * fall back on the default.
1886                                  */
1887                                 offset = add_dword_param(tvb, offset, 0, pinfo,
1888                                     tree, 0, -1);
1889                         } else if (items->type != PARAM_DWORD) {
1890                                 /*
1891                                  * Descriptor character is 'i', but this
1892                                  * isn't a doubleword parameter.
1893                                  */
1894                                 LParam = tvb_get_letohl(tvb, offset);
1895                                 proto_tree_add_text(tree, tvb, offset, 2,
1896                                     "%s: Value is %u (0x%08X), type is wrong (i)",
1897                                     (*items->hf_index == -1) ?
1898                                       "Doubleword Param" :
1899                                       proto_registrar_get_name(*items->hf_index),
1900                                     LParam, LParam);
1901                                 offset += 4;
1902                                 items++;
1903                         } else {
1904                                 offset = (*items->func)(tvb, offset, 0, pinfo,
1905                                     tree, 0, *items->hf_index);
1906                                 items++;
1907                         }
1908                         break;
1909
1910                 case 'e':
1911                         /*
1912                          * A 16-bit entry count is returned.
1913                          */
1914                         WParam = tvb_get_letohs(tvb, offset);
1915                         proto_tree_add_uint(tree, hf_ecount, tvb, offset, 2,
1916                             WParam);
1917                         offset += 2;
1918                         *has_ent_count_p = TRUE;
1919                         *ent_count_p = WParam;  /* Save this for later retrieval */
1920                         break;
1921
1922                 default:
1923                         break;
1924                 }
1925         }
1926         return offset;
1927 }
1928
1929 static int
1930 dissect_transact_data(tvbuff_t *tvb, int offset, int convert,
1931     packet_info *pinfo, proto_tree *tree, const guchar *desc,
1932     const item_t *items, guint16 *aux_count_p)
1933 {
1934         guint c;
1935         guint16 WParam;
1936         guint32 LParam;
1937         int count;
1938         int cptr;
1939         const char *string;
1940         gint string_len;
1941
1942         if (aux_count_p != NULL)
1943                 *aux_count_p = 0;
1944
1945         while ((c = *desc++) != '\0') {
1946                 switch (c) {
1947
1948                 case 'W':
1949                         /*
1950                          * A 16-bit word value.
1951                          * XXX - handle the count?
1952                          */
1953                         desc = get_count(desc, &count);
1954                         if (items->func == NULL) {
1955                                 /*
1956                                  * We've run out of items in the table;
1957                                  * fall back on the default.
1958                                  */
1959                                 offset = add_word_param(tvb, offset, 0, pinfo,
1960                                     tree, convert, -1);
1961                         } else if (items->type != PARAM_WORD) {
1962                                 /*
1963                                  * Descriptor character is 'W', but this
1964                                  * isn't a word parameter.
1965                                  */
1966                                 WParam = tvb_get_letohs(tvb, offset);
1967                                 proto_tree_add_text(tree, tvb, offset, 2,
1968                                     "%s: Value is %u (0x%04X), type is wrong (W)",
1969                                     (*items->hf_index == -1) ?
1970                                       "Word Param" :
1971                                       proto_registrar_get_name(*items->hf_index),
1972                                     WParam, WParam);
1973                                 offset += 2;
1974                                 items++;
1975                         } else {
1976                                 offset = (*items->func)(tvb, offset, 0, pinfo,
1977                                     tree, convert, *items->hf_index);
1978                                 items++;
1979                         }
1980                         break;
1981
1982                 case 'D':
1983                         /*
1984                          * A 32-bit doubleword value.
1985                          * XXX - handle the count?
1986                          */
1987                         desc = get_count(desc, &count);
1988                         if (items->func == NULL) {
1989                                 /*
1990                                  * We've run out of items in the table;
1991                                  * fall back on the default.
1992                                  */
1993                                 offset = add_dword_param(tvb, offset, 0, pinfo,
1994                                     tree, convert, -1);
1995                         } else if (items->type != PARAM_DWORD) {
1996                                 /*
1997                                  * Descriptor character is 'D', but this
1998                                  * isn't a doubleword parameter.
1999                                  */
2000                                 LParam = tvb_get_letohl(tvb, offset);
2001                                 proto_tree_add_text(tree, tvb, offset, 2,
2002                                     "%s: Value is %u (0x%08X), type is wrong (D)",
2003                                     (*items->hf_index == -1) ?
2004                                       "Doubleword Param" :
2005                                       proto_registrar_get_name(*items->hf_index),
2006                                     LParam, LParam);
2007                                 offset += 4;
2008                                 items++;
2009                         } else {
2010                                 offset = (*items->func)(tvb, offset, 0, pinfo,
2011                                     tree, convert, *items->hf_index);
2012                                 items++;
2013                         }
2014                         break;
2015
2016                 case 'B':
2017                         /*
2018                          * A byte or multi-byte value.
2019                          */
2020                         desc = get_count(desc, &count);
2021                         if (items->func == NULL) {
2022                                 /*
2023                                  * We've run out of items in the table;
2024                                  * fall back on the default.
2025                                  */
2026                                 offset = add_byte_param(tvb, offset, count,
2027                                     pinfo, tree, convert, -1);
2028                         } else if (items->type != PARAM_BYTES) {
2029                                 /*
2030                                  * Descriptor character is 'B', but this
2031                                  * isn't a byte/bytes parameter.
2032                                  */
2033                                 proto_tree_add_text(tree, tvb, offset, count,
2034                                     "%s: Value is %s, type is wrong (B)",
2035                                     (*items->hf_index == -1) ?
2036                                       "Byte Param" :
2037                                       proto_registrar_get_name(*items->hf_index),
2038                                     tvb_bytes_to_str(tvb, offset, count));
2039                                 offset += count;
2040                                 items++;
2041                         } else {
2042                                 offset = (*items->func)(tvb, offset, count,
2043                                     pinfo, tree, convert, *items->hf_index);
2044                                 items++;
2045                         }
2046                         break;
2047
2048                 case 'O':
2049                         /*
2050                          * A null pointer.
2051                          */
2052                         if (items->func == NULL) {
2053                                 /*
2054                                  * We've run out of items in the table;
2055                                  * fall back on the default.
2056                                  */
2057                                 add_null_pointer_param(tvb, offset, 0,
2058                                     pinfo, tree, convert, -1);
2059                         } else {
2060                                 /*
2061                                  * If "*items->hf_index" is -1, this is
2062                                  * a reserved must-be-null field; don't
2063                                  * clutter the protocol tree by putting
2064                                  * it in.
2065                                  */
2066                                 if (*items->hf_index != -1) {
2067                                         add_null_pointer_param(tvb,
2068                                             offset, 0, pinfo, tree, convert,
2069                                             *items->hf_index);
2070                                 }
2071                                 items++;
2072                         }
2073                         break;
2074
2075                 case 'z':
2076                         /*
2077                          * A pointer to a null-terminated ASCII string.
2078                          */
2079                         if (items->func == NULL) {
2080                                 /*
2081                                  * We've run out of items in the table;
2082                                  * fall back on the default.
2083                                  */
2084                                 offset = add_stringz_pointer_param(tvb, offset,
2085                                     0, pinfo, tree, convert, -1);
2086                         } else if (items->type != PARAM_STRINGZ) {
2087                                 /*
2088                                  * Descriptor character is 'z', but this
2089                                  * isn't a string parameter.
2090                                  */
2091                                 string = get_stringz_pointer_value(tvb, offset,
2092                                     convert, &cptr, &string_len);
2093                                 offset += 4;
2094                                 proto_tree_add_text(tree, tvb, cptr, string_len,
2095                                     "%s: Value is %s, type is wrong (z)",
2096                                     (*items->hf_index == -1) ?
2097                                       "String Param" :
2098                                       proto_registrar_get_name(*items->hf_index),
2099                                     string);
2100                                 items++;
2101                         } else {
2102                                 offset = (*items->func)(tvb, offset, 0,
2103                                     pinfo, tree, convert, *items->hf_index);
2104                                 items++;
2105                         }
2106                         break;
2107
2108                 case 'b':
2109                         /*
2110                          * A pointer to a byte or multi-byte value.
2111                          */
2112                         desc = get_count(desc, &count);
2113                         if (items->func == NULL) {
2114                                 /*
2115                                  * We've run out of items in the table;
2116                                  * fall back on the default.
2117                                  */
2118                                 offset = add_bytes_pointer_param(tvb, offset,
2119                                     count, pinfo, tree, convert, -1);
2120                         } else if (items->type != PARAM_BYTES) {
2121                                 /*
2122                                  * Descriptor character is 'b', but this
2123                                  * isn't a byte/bytes parameter.
2124                                  */
2125                                 cptr = (tvb_get_letohl(tvb, offset)&0xffff)-convert;
2126                                 offset += 4;
2127                                 proto_tree_add_text(tree, tvb, offset, count,
2128                                     "%s: Value is %s, type is wrong (b)",
2129                                     (*items->hf_index == -1) ?
2130                                       "Byte Param" :
2131                                       proto_registrar_get_name(*items->hf_index),
2132                                     tvb_bytes_to_str(tvb, cptr, count));
2133                                 items++;
2134                         } else {
2135                                 offset = (*items->func)(tvb, offset, count,
2136                                     pinfo, tree, convert, *items->hf_index);
2137                                 items++;
2138                         }
2139                         break;
2140
2141                 case 'N':
2142                         /*
2143                          * 16-bit auxiliary data structure count.
2144                          * XXX - hf_acount?
2145                          */
2146                         WParam = tvb_get_letohs(tvb, offset);
2147                         proto_tree_add_text(tree, tvb, offset, 2,
2148                             "%s: %u (0x%04X)",
2149                             "Auxiliary data structure count",
2150                             WParam, WParam);
2151                         offset += 2;
2152                         if (aux_count_p != NULL)
2153                                 *aux_count_p = WParam;  /* Save this for later retrieval */
2154                         break;
2155
2156                 default:
2157                         break;
2158                 }
2159         }
2160         return offset;
2161 }
2162
2163 static const value_string commands[] = {
2164         {API_NetShareEnum,                      "NetShareEnum"},
2165         {API_NetShareGetInfo,                   "NetShareGetInfo"},
2166         {API_NetShareSetInfo,                   "NetShareSetInfo"},
2167         {API_NetShareAdd,                       "NetShareAdd"},
2168         {API_NetShareDel,                       "NetShareDel"},
2169         {API_NetShareCheck,                     "NetShareCheck"},
2170         {API_NetSessionEnum,                    "NetSessionEnum"},
2171         {API_NetSessionGetInfo,                 "NetSessionGetInfo"},
2172         {API_NetSessionDel,                     "NetSessionDel"},
2173         {API_WconnectionEnum,                   "NetConnectionEnum"},
2174         {API_NetFileEnum,                       "NetFileEnum"},
2175         {API_NetFileGetInfo,                    "NetFileGetInfo"},
2176         {API_NetFileClose,                      "NetFileClose"},
2177         {API_NetServerGetInfo,                  "NetServerGetInfo"},
2178         {API_NetServerSetInfo,                  "NetServerSetInfo"},
2179         {API_NetServerDiskEnum,                 "NetServerDiskEnum"},
2180         {API_NetServerAdminCommand,             "NetServerAdminCommand"},
2181         {API_NetAuditOpen,                      "NetAuditOpen"},
2182         {API_NetAuditClear,                     "NetAuditClear"},
2183         {API_NetErrorLogOpen,                   "NetErrorLogOpen"},
2184         {API_NetErrorLogClear,                  "NetErrorLogClear"},
2185         {API_NetCharDevEnum,                    "NetCharDevEnum"},
2186         {API_NetCharDevGetInfo,                 "NetCharDevGetInfo"},
2187         {API_NetCharDevControl,                 "NetCharDevControl"},
2188         {API_NetCharDevQEnum,                   "NetCharDevQEnum"},
2189         {API_NetCharDevQGetInfo,                "NetCharDevQGetInfo"},
2190         {API_NetCharDevQSetInfo,                "NetCharDevQSetInfo"},
2191         {API_NetCharDevQPurge,                  "NetCharDevQPurge"},
2192         {API_NetCharDevQPurgeSelf,              "NetCharDevQPurgeSelf"},
2193         {API_NetMessageNameEnum,                "NetMessageNameEnum"},
2194         {API_NetMessageNameGetInfo,             "NetMessageNameGetInfo"},
2195         {API_NetMessageNameAdd,                 "NetMessageNameAdd"},
2196         {API_NetMessageNameDel,                 "NetMessageNameDel"},
2197         {API_NetMessageNameFwd,                 "NetMessageNameFwd"},
2198         {API_NetMessageNameUnFwd,               "NetMessageNameUnFwd"},
2199         {API_NetMessageBufferSend,              "NetMessageBufferSend"},
2200         {API_NetMessageFileSend,                "NetMessageFileSend"},
2201         {API_NetMessageLogFileSet,              "NetMessageLogFileSet"},
2202         {API_NetMessageLogFileGet,              "NetMessageLogFileGet"},
2203         {API_NetServiceEnum,                    "NetServiceEnum"},
2204         {API_NetServiceInstall,                 "NetServiceInstall"},
2205         {API_NetServiceControl,                 "NetServiceControl"},
2206         {API_NetAccessEnum,                     "NetAccessEnum"},
2207         {API_NetAccessGetInfo,                  "NetAccessGetInfo"},
2208         {API_NetAccessSetInfo,                  "NetAccessSetInfo"},
2209         {API_NetAccessAdd,                      "NetAccessAdd"},
2210         {API_NetAccessDel,                      "NetAccessDel"},
2211         {API_NetGroupEnum,                      "NetGroupEnum"},
2212         {API_NetGroupAdd,                       "NetGroupAdd"},
2213         {API_NetGroupDel,                       "NetGroupDel"},
2214         {API_NetGroupAddUser,                   "NetGroupAddUser"},
2215         {API_NetGroupDelUser,                   "NetGroupDelUser"},
2216         {API_NetGroupGetUsers,                  "NetGroupGetUsers"},
2217         {API_NetUserEnum,                       "NetUserEnum"},
2218         {API_NetUserAdd,                        "NetUserAdd"},
2219         {API_NetUserDel,                        "NetUserDel"},
2220         {API_NetUserGetInfo,                    "NetUserGetInfo"},
2221         {API_NetUserSetInfo,                    "NetUserSetInfo"},
2222         {API_NetUserPasswordSet,                "NetUserPasswordSet"},
2223         {API_NetUserGetGroups,                  "NetUserGetGroups"},
2224         {API_NetWkstaSetUID,                    "NetWkstaSetUID"},
2225         {API_NetWkstaGetInfo,                   "NetWkstaGetInfo"},
2226         {API_NetWkstaSetInfo,                   "NetWkstaSetInfo"},
2227         {API_NetUseEnum,                        "NetUseEnum"},
2228         {API_NetUseAdd,                         "NetUseAdd"},
2229         {API_NetUseDel,                         "NetUseDel"},
2230         {API_NetUseGetInfo,                     "NetUseGetInfo"},
2231         {API_WPrintQEnum,                       "WPrintQEnum"},
2232         {API_WPrintQGetInfo,                    "WPrintQGetInfo"},
2233         {API_WPrintQSetInfo,                    "WPrintQSetInfo"},
2234         {API_WPrintQAdd,                        "WPrintQAdd"},
2235         {API_WPrintQDel,                        "WPrintQDel"},
2236         {API_WPrintQPause,                      "WPrintQPause"},
2237         {API_WPrintQContinue,                   "WPrintQContinue"},
2238         {API_WPrintJobEnum,                     "WPrintJobEnum"},
2239         {API_WPrintJobGetInfo,                  "WPrintJobGetInfo"},
2240         {API_WPrintJobSetInfo_OLD,              "WPrintJobSetInfo_OLD"},
2241         {API_WPrintJobDel,                      "WPrintJobDel"},
2242         {API_WPrintJobPause,                    "WPrintJobPause"},
2243         {API_WPrintJobContinue,                 "WPrintJobContinue"},
2244         {API_WPrintDestEnum,                    "WPrintDestEnum"},
2245         {API_WPrintDestGetInfo,                 "WPrintDestGetInfo"},
2246         {API_WPrintDestControl,                 "WPrintDestControl"},
2247         {API_NetProfileSave,                    "NetProfileSave"},
2248         {API_NetProfileLoad,                    "NetProfileLoad"},
2249         {API_NetStatisticsGet,                  "NetStatisticsGet"},
2250         {API_NetStatisticsClear,                "NetStatisticsClear"},
2251         {API_NetRemoteTOD,                      "NetRemoteTOD"},
2252         {API_WNetBiosEnum,                      "WNetBiosEnum"},
2253         {API_WNetBiosGetInfo,                   "WNetBiosGetInfo"},
2254         {API_NetServerEnum,                     "NetServerEnum"},
2255         {API_I_NetServerEnum,                   "I_NetServerEnum"},
2256         {API_NetServiceGetInfo,                 "NetServiceGetInfo"},
2257         {API_WPrintQPurge,                      "WPrintQPurge"},
2258         {API_NetServerEnum2,                    "NetServerEnum2"},
2259         {API_NetAccessGetUserPerms,             "NetAccessGetUserPerms"},
2260         {API_NetGroupGetInfo,                   "NetGroupGetInfo"},
2261         {API_NetGroupSetInfo,                   "NetGroupSetInfo"},
2262         {API_NetGroupSetUsers,                  "NetGroupSetUsers"},
2263         {API_NetUserSetGroups,                  "NetUserSetGroups"},
2264         {API_NetUserModalsGet,                  "NetUserModalsGet"},
2265         {API_NetUserModalsSet,                  "NetUserModalsSet"},
2266         {API_NetFileEnum2,                      "NetFileEnum2"},
2267         {API_NetUserAdd2,                       "NetUserAdd2"},
2268         {API_NetUserSetInfo2,                   "NetUserSetInfo2"},
2269         {API_NetUserPasswordSet2,               "SetUserPassword"},
2270         {API_I_NetServerEnum2,                  "I_NetServerEnum2"},
2271         {API_NetConfigGet2,                     "NetConfigGet2"},
2272         {API_NetConfigGetAll2,                  "NetConfigGetAll2"},
2273         {API_NetGetDCName,                      "NetGetDCName"},
2274         {API_NetHandleGetInfo,                  "NetHandleGetInfo"},
2275         {API_NetHandleSetInfo,                  "NetHandleSetInfo"},
2276         {API_NetStatisticsGet2,                 "NetStatisticsGet2"},
2277         {API_WBuildGetInfo,                     "WBuildGetInfo"},
2278         {API_NetFileGetInfo2,                   "NetFileGetInfo2"},
2279         {API_NetFileClose2,                     "NetFileClose2"},
2280         {API_NetServerReqChallenge,             "NetServerReqChallenge"},
2281         {API_NetServerAuthenticate,             "NetServerAuthenticate"},
2282         {API_NetServerPasswordSet,              "NetServerPasswordSet"},
2283         {API_WNetAccountDeltas,                 "WNetAccountDeltas"},
2284         {API_WNetAccountSync,                   "WNetAccountSync"},
2285         {API_NetUserEnum2,                      "NetUserEnum2"},
2286         {API_NetWkstaUserLogon,                 "NetWkstaUserLogon"},
2287         {API_NetWkstaUserLogoff,                "NetWkstaUserLogoff"},
2288         {API_NetLogonEnum,                      "NetLogonEnum"},
2289         {API_NetErrorLogRead,                   "NetErrorLogRead"},
2290         {API_I_NetPathType,                     "I_NetPathType"},
2291         {API_I_NetPathCanonicalize,             "I_NetPathCanonicalize"},
2292         {API_I_NetPathCompare,                  "I_NetPathCompare"},
2293         {API_I_NetNameValidate,                 "I_NetNameValidate"},
2294         {API_I_NetNameCanonicalize,             "I_NetNameCanonicalize"},
2295         {API_I_NetNameCompare,                  "I_NetNameCompare"},
2296         {API_NetAuditRead,                      "NetAuditRead"},
2297         {API_WPrintDestAdd,                     "WPrintDestAdd"},
2298         {API_WPrintDestSetInfo,                 "WPrintDestSetInfo"},
2299         {API_WPrintDestDel,                     "WPrintDestDel"},
2300         {API_NetUserValidate2,                  "NetUserValidate2"},
2301         {API_WPrintJobSetInfo,                  "WPrintJobSetInfo"},
2302         {API_TI_NetServerDiskEnum,              "TI_NetServerDiskEnum"},
2303         {API_TI_NetServerDiskGetInfo,           "TI_NetServerDiskGetInfo"},
2304         {API_TI_FTVerifyMirror,                 "TI_FTVerifyMirror"},
2305         {API_TI_FTAbortVerify,                  "TI_FTAbortVerify"},
2306         {API_TI_FTGetInfo,                      "TI_FTGetInfo"},
2307         {API_TI_FTSetInfo,                      "TI_FTSetInfo"},
2308         {API_TI_FTLockDisk,                     "TI_FTLockDisk"},
2309         {API_TI_FTFixError,                     "TI_FTFixError"},
2310         {API_TI_FTAbortFix,                     "TI_FTAbortFix"},
2311         {API_TI_FTDiagnoseError,                "TI_FTDiagnoseError"},
2312         {API_TI_FTGetDriveStats,                "TI_FTGetDriveStats"},
2313         {API_TI_FTErrorGetInfo,                 "TI_FTErrorGetInfo"},
2314         {API_NetAccessCheck,                    "NetAccessCheck"},
2315         {API_NetAlertRaise,                     "NetAlertRaise"},
2316         {API_NetAlertStart,                     "NetAlertStart"},
2317         {API_NetAlertStop,                      "NetAlertStop"},
2318         {API_NetAuditWrite,                     "NetAuditWrite"},
2319         {API_NetIRemoteAPI,                     "NetIRemoteAPI"},
2320         {API_NetServiceStatus,                  "NetServiceStatus"},
2321         {API_I_NetServerRegister,               "I_NetServerRegister"},
2322         {API_I_NetServerDeregister,             "I_NetServerDeregister"},
2323         {API_I_NetSessionEntryMake,             "I_NetSessionEntryMake"},
2324         {API_I_NetSessionEntryClear,            "I_NetSessionEntryClear"},
2325         {API_I_NetSessionEntryGetInfo,          "I_NetSessionEntryGetInfo"},
2326         {API_I_NetSessionEntrySetInfo,          "I_NetSessionEntrySetInfo"},
2327         {API_I_NetConnectionEntryMake,          "I_NetConnectionEntryMake"},
2328         {API_I_NetConnectionEntryClear,         "I_NetConnectionEntryClear"},
2329         {API_I_NetConnectionEntrySetInfo,       "I_NetConnectionEntrySetInfo"},
2330         {API_I_NetConnectionEntryGetInfo,       "I_NetConnectionEntryGetInfo"},
2331         {API_I_NetFileEntryMake,                "I_NetFileEntryMake"},
2332         {API_I_NetFileEntryClear,               "I_NetFileEntryClear"},
2333         {API_I_NetFileEntrySetInfo,             "I_NetFileEntrySetInfo"},
2334         {API_I_NetFileEntryGetInfo,             "I_NetFileEntryGetInfo"},
2335         {API_AltSrvMessageBufferSend,           "AltSrvMessageBufferSend"},
2336         {API_AltSrvMessageFileSend,             "AltSrvMessageFileSend"},
2337         {API_wI_NetRplWkstaEnum,                "wI_NetRplWkstaEnum"},
2338         {API_wI_NetRplWkstaGetInfo,             "wI_NetRplWkstaGetInfo"},
2339         {API_wI_NetRplWkstaSetInfo,             "wI_NetRplWkstaSetInfo"},
2340         {API_wI_NetRplWkstaAdd,                 "wI_NetRplWkstaAdd"},
2341         {API_wI_NetRplWkstaDel,                 "wI_NetRplWkstaDel"},
2342         {API_wI_NetRplProfileEnum,              "wI_NetRplProfileEnum"},
2343         {API_wI_NetRplProfileGetInfo,           "wI_NetRplProfileGetInfo"},
2344         {API_wI_NetRplProfileSetInfo,           "wI_NetRplProfileSetInfo"},
2345         {API_wI_NetRplProfileAdd,               "wI_NetRplProfileAdd"},
2346         {API_wI_NetRplProfileDel,               "wI_NetRplProfileDel"},
2347         {API_wI_NetRplProfileClone,             "wI_NetRplProfileClone"},
2348         {API_wI_NetRplBaseProfileEnum,          "wI_NetRplBaseProfileEnum"},
2349         {API_WIServerSetInfo,                   "WIServerSetInfo"},
2350         {API_WPrintDriverEnum,                  "WPrintDriverEnum"},
2351         {API_WPrintQProcessorEnum,              "WPrintQProcessorEnum"},
2352         {API_WPrintPortEnum,                    "WPrintPortEnum"},
2353         {API_WNetWriteUpdateLog,                "WNetWriteUpdateLog"},
2354         {API_WNetAccountUpdate,                 "WNetAccountUpdate"},
2355         {API_WNetAccountConfirmUpdate,          "WNetAccountConfirmUpdate"},
2356         {API_NetConfigSet,                      "NetConfigSet"},
2357         {API_WAccountsReplicate,                "WAccountsReplicate"},
2358         {API_SamOEMChgPasswordUser2_P,          "SamOEMChangePassword"},
2359         {API_NetServerEnum3,                    "NetServerEnum3"},
2360         {API_WPrintDriverGetInfo,               "WPrintDriverGetInfo"},
2361         {API_WPrintDriverSetInfo,               "WPrintDriverSetInfo"},
2362         {API_NetAliasAdd,                       "NetAliasAdd"},
2363         {API_NetAliasDel,                       "NetAliasDel"},
2364         {API_NetAliasGetInfo,                   "NetAliasGetInfo"},
2365         {API_NetAliasSetInfo,                   "NetAliasSetInfo"},
2366         {API_NetAliasEnum,                      "NetAliasEnum"},
2367         {API_NetUserGetLogonAsn,                "NetUserGetLogonAsn"},
2368         {API_NetUserSetLogonAsn,                "NetUserSetLogonAsn"},
2369         {API_NetUserGetAppSel,                  "NetUserGetAppSel"},
2370         {API_NetUserSetAppSel,                  "NetUserSetAppSel"},
2371         {API_NetAppAdd,                         "NetAppAdd"},
2372         {API_NetAppDel,                         "NetAppDel"},
2373         {API_NetAppGetInfo,                     "NetAppGetInfo"},
2374         {API_NetAppSetInfo,                     "NetAppSetInfo"},
2375         {API_NetAppEnum,                        "NetAppEnum"},
2376         {API_NetUserDCDBInit,                   "NetUserDCDBInit"},
2377         {API_NetDASDAdd,                        "NetDASDAdd"},
2378         {API_NetDASDDel,                        "NetDASDDel"},
2379         {API_NetDASDGetInfo,                    "NetDASDGetInfo"},
2380         {API_NetDASDSetInfo,                    "NetDASDSetInfo"},
2381         {API_NetDASDEnum,                       "NetDASDEnum"},
2382         {API_NetDASDCheck,                      "NetDASDCheck"},
2383         {API_NetDASDCtl,                        "NetDASDCtl"},
2384         {API_NetUserRemoteLogonCheck,           "NetUserRemoteLogonCheck"},
2385         {API_NetUserPasswordSet3,               "NetUserPasswordSet3"},
2386         {API_NetCreateRIPLMachine,              "NetCreateRIPLMachine"},
2387         {API_NetDeleteRIPLMachine,              "NetDeleteRIPLMachine"},
2388         {API_NetGetRIPLMachineInfo,             "NetGetRIPLMachineInfo"},
2389         {API_NetSetRIPLMachineInfo,             "NetSetRIPLMachineInfo"},
2390         {API_NetEnumRIPLMachine,                "NetEnumRIPLMachine"},
2391         {API_I_ShareAdd,                        "I_ShareAdd"},
2392         {API_I_AliasEnum,                       "I_AliasEnum"},
2393         {API_NetAccessApply,                    "NetAccessApply"},
2394         {API_WPrt16Query,                       "WPrt16Query"},
2395         {API_WPrt16Set,                         "WPrt16Set"},
2396         {API_NetUserDel100,                     "NetUserDel100"},
2397         {API_NetUserRemoteLogonCheck2,          "NetUserRemoteLogonCheck2"},
2398         {API_WRemoteTODSet,                     "WRemoteTODSet"},
2399         {API_WPrintJobMoveAll,                  "WPrintJobMoveAll"},
2400         {API_W16AppParmAdd,                     "W16AppParmAdd"},
2401         {API_W16AppParmDel,                     "W16AppParmDel"},
2402         {API_W16AppParmGet,                     "W16AppParmGet"},
2403         {API_W16AppParmSet,                     "W16AppParmSet"},
2404         {API_W16RIPLMachineCreate,              "W16RIPLMachineCreate"},
2405         {API_W16RIPLMachineGetInfo,             "W16RIPLMachineGetInfo"},
2406         {API_W16RIPLMachineSetInfo,             "W16RIPLMachineSetInfo"},
2407         {API_W16RIPLMachineEnum,                "W16RIPLMachineEnum"},
2408         {API_W16RIPLMachineListParmEnum,        "W16RIPLMachineListParmEnum"},
2409         {API_W16RIPLMachClassGetInfo,           "W16RIPLMachClassGetInfo"},
2410         {API_W16RIPLMachClassEnum,              "W16RIPLMachClassEnum"},
2411         {API_W16RIPLMachClassCreate,            "W16RIPLMachClassCreate"},
2412         {API_W16RIPLMachClassSetInfo,           "W16RIPLMachClassSetInfo"},
2413         {API_W16RIPLMachClassDelete,            "W16RIPLMachClassDelete"},
2414         {API_W16RIPLMachClassLPEnum,            "W16RIPLMachClassLPEnum"},
2415         {API_W16RIPLMachineDelete,              "W16RIPLMachineDelete"},
2416         {API_W16WSLevelGetInfo,                 "W16WSLevelGetInfo"},
2417         {API_NetServerNameAdd,                  "NetServerNameAdd"},
2418         {API_NetServerNameDel,                  "NetServerNameDel"},
2419         {API_NetServerNameEnum,                 "NetServerNameEnum"},
2420         {API_I_WDASDEnum,                       "I_WDASDEnum"},
2421         {API_I_WDASDEnumTerminate,              "I_WDASDEnumTerminate"},
2422         {API_I_WDASDSetInfo2,                   "I_WDASDSetInfo2"},
2423         {0,                                     NULL}
2424 };
2425
2426 static void
2427 dissect_response_data(tvbuff_t *tvb, packet_info *pinfo, int convert,
2428     proto_tree *tree, struct smb_info *smb_info,
2429     const struct lanman_desc *lanman, gboolean has_ent_count,
2430     guint16 ent_count)
2431 {
2432         smb_transact_info_t *trp = smb_info->sip->extra_info;
2433         const item_list_t *resp_data_list;
2434         int offset, start_offset;
2435         const char *label;
2436         gint ett;
2437         const item_t *resp_data;
2438         proto_item *data_item;
2439         proto_tree *data_tree;
2440         proto_item *entry_item;
2441         proto_tree *entry_tree;
2442         guint i, j;
2443         guint16 aux_count;
2444
2445         /*
2446          * Find the item table for the matching request's detail level.
2447          */
2448         for (resp_data_list = lanman->resp_data_list;
2449             resp_data_list->level != -1; resp_data_list++) {
2450                 if (resp_data_list->level == trp->info_level)
2451                         break;
2452         }
2453         resp_data = resp_data_list->item_list;
2454
2455         offset = 0;
2456         if (has_ent_count) {
2457                 /*
2458                  * The data is a list of entries; create a protocol tree item
2459                  * for it.
2460                  */
2461                 if (tree) {
2462                         label = lanman->resp_data_entry_list_label;
2463                         if (label == NULL)
2464                                 label = "Entries";
2465                         if (lanman->ett_data_entry_list != NULL)
2466                                 ett = *lanman->ett_data_entry_list;
2467                         else
2468                                 ett = ett_lanman_unknown_entries;
2469                         data_item = proto_tree_add_text(tree, tvb, offset, -1,
2470                             label);
2471                         data_tree = proto_item_add_subtree(data_item, ett);
2472                 } else {
2473                         data_item = NULL;
2474                         data_tree = NULL;
2475                 }
2476         } else {
2477                 /*
2478                  * Just leave it at the top level.
2479                  */
2480                 data_item = NULL;
2481                 data_tree = tree;
2482         }
2483
2484         if (trp->data_descrip == NULL) {
2485                 /*
2486                  * This could happen if we only dissected
2487                  * part of the request to which this is a
2488                  * reply, e.g. if the request was split
2489                  * across TCP segments and we weren't doing
2490                  * TCP desegmentation, or if we had a snapshot
2491                  * length that was too short.
2492                  *
2493                  * We can't dissect the data; just show it
2494                  * as raw data.
2495                  */
2496                 proto_tree_add_text(tree, tvb, offset, -1,
2497                     "Data (no descriptor available)");
2498                 offset += tvb_length_remaining(tvb, offset);
2499         } else {
2500                 /*
2501                  * If we have an entry count, show all the entries,
2502                  * with each one having a protocol tree item.
2503                  *
2504                  * Otherwise, we just show one returned item, with
2505                  * no protocol tree item.
2506                  */
2507                 if (!has_ent_count)
2508                         ent_count = 1;
2509                 for (i = 0; i < ent_count; i++) {
2510                         start_offset = offset;
2511                         if (has_ent_count &&
2512                             lanman->resp_data_element_item != NULL) {
2513                                 /*
2514                                  * Create a protocol tree item for the
2515                                  * entry.
2516                                  */
2517                                 entry_item =
2518                                     (*lanman->resp_data_element_item)
2519                                       (tvb, pinfo, data_tree, offset);
2520                                 entry_tree = proto_item_add_subtree(
2521                                     entry_item,
2522                                     *lanman->ett_resp_data_element_item);
2523                         } else {
2524                                 /*
2525                                  * Just leave it at the current
2526                                  * level.
2527                                  */
2528                                 entry_item = NULL;
2529                                 entry_tree = data_tree;
2530                         }
2531
2532                         offset = dissect_transact_data(tvb, offset,
2533                             convert, pinfo, entry_tree,
2534                             trp->data_descrip, resp_data, &aux_count);
2535
2536                         /* auxiliary data */
2537                         if (trp->aux_data_descrip != NULL) {
2538                                 for (j = 0; j < aux_count; j++) {
2539                                         offset = dissect_transact_data(
2540                                             tvb, offset, convert,
2541                                             pinfo, entry_tree,
2542                                             trp->data_descrip,
2543                                             lanman->resp_aux_data, NULL);
2544                                 }
2545                         }
2546
2547                         if (entry_item != NULL) {
2548                                 /*
2549                                  * Set the length of the protocol tree
2550                                  * item for the entry.
2551                                  */
2552                                 proto_item_set_len(entry_item,
2553                                     offset - start_offset);
2554                         }
2555                 }
2556         }
2557
2558         if (data_item != NULL) {
2559                 /*
2560                  * Set the length of the protocol tree item
2561                  * for the data.
2562                  */
2563                 proto_item_set_len(data_item, offset);
2564         }
2565 }
2566
2567 static gboolean
2568 dissect_pipe_lanman(tvbuff_t *pd_tvb, tvbuff_t *p_tvb, tvbuff_t *d_tvb,
2569                     packet_info *pinfo, proto_tree *parent_tree)
2570 {
2571         smb_info_t *smb_info = pinfo->private_data;
2572         smb_transact_info_t *trp = smb_info->sip->extra_info;
2573         int offset = 0, start_offset;
2574         guint16 cmd;
2575         guint16 status;
2576         int convert;
2577         const struct lanman_desc *lanman;
2578         proto_item *item = NULL;
2579         proto_tree *tree = NULL;
2580         guint descriptor_len;
2581         const gchar *param_descrip, *data_descrip, *aux_data_descrip = NULL;
2582         gboolean has_data;
2583         gboolean has_ent_count;
2584         guint16 ent_count, aux_count;
2585         guint i;
2586         proto_item *data_item;
2587         proto_tree *data_tree;
2588
2589         if (!proto_is_protocol_enabled(proto_smb_lanman))
2590                 return FALSE;
2591         if (smb_info->request && p_tvb == NULL) {
2592                 /*
2593                  * Requests must have parameters.
2594                  */
2595                 return FALSE;
2596         }
2597         pinfo->current_proto = "LANMAN";
2598
2599         if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
2600                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "LANMAN");
2601         }
2602
2603         if (parent_tree) {
2604                 item = proto_tree_add_item(parent_tree, proto_smb_lanman,
2605                         pd_tvb, 0, -1, FALSE);
2606                 tree = proto_item_add_subtree(item, ett_lanman);
2607         }
2608
2609         if (smb_info->request) { /* this is a request */
2610                 /* function code */
2611                 cmd = tvb_get_letohs(p_tvb, offset);
2612                 if (check_col(pinfo->cinfo, COL_INFO)) {
2613                         col_add_fstr(pinfo->cinfo, COL_INFO, "%s Request", val_to_str(cmd, commands, "Unknown Command (%u)"));
2614                 }
2615                 proto_tree_add_uint(tree, hf_function_code, p_tvb, offset, 2,
2616                     cmd);
2617                 offset += 2;
2618
2619                 /*
2620                  * If we haven't already done so, save the function code in
2621                  * the structure we were handed, so that it's available to
2622                  * the code parsing the reply, and initialize the detail
2623                  * level to -1, meaning "unknown".
2624                  */
2625                 if (!pinfo->fd->flags.visited) {
2626                         trp->lanman_cmd = cmd;
2627                         trp->info_level = -1;
2628                         trp->param_descrip=NULL;
2629                         trp->data_descrip=NULL;
2630                         trp->aux_data_descrip=NULL;
2631                 }
2632
2633                 /* parameter descriptor */
2634                 descriptor_len = tvb_strsize(p_tvb, offset);
2635                 proto_tree_add_item(tree, hf_param_desc, p_tvb, offset,
2636                     descriptor_len, TRUE);
2637                 param_descrip = tvb_get_ptr(p_tvb, offset, descriptor_len);
2638                 if (!pinfo->fd->flags.visited) {
2639                         /*
2640                          * Save the parameter descriptor for future use.
2641                          */
2642                         g_assert(trp->param_descrip == NULL);
2643                         trp->param_descrip = g_strdup(param_descrip);
2644                 }
2645                 offset += descriptor_len;
2646
2647                 /* return descriptor */
2648                 descriptor_len = tvb_strsize(p_tvb, offset);
2649                 proto_tree_add_item(tree, hf_return_desc, p_tvb, offset,
2650                     descriptor_len, TRUE);
2651                 data_descrip = tvb_get_ptr(p_tvb, offset, descriptor_len);
2652                 if (!pinfo->fd->flags.visited) {
2653                         /*
2654                          * Save the return descriptor for future use.
2655                          */
2656                         g_assert(trp->data_descrip == NULL);
2657                         trp->data_descrip = g_strdup(data_descrip);
2658                 }
2659                 offset += descriptor_len;
2660
2661                 lanman = find_lanman(cmd);
2662
2663                 /* request parameters */
2664                 start_offset = offset;
2665                 offset = dissect_request_parameters(p_tvb, offset, pinfo, tree,
2666                     param_descrip, lanman->req, &has_data);
2667
2668                 /* auxiliary data descriptor */
2669                 if (tvb_reported_length_remaining(p_tvb, offset) > 0){
2670                         /*
2671                          * There are more parameters left, so the next
2672                          * item is the auxiliary data descriptor.
2673                          */
2674                         descriptor_len = tvb_strsize(p_tvb, offset);
2675                         proto_tree_add_item(tree, hf_aux_data_desc, p_tvb, offset,
2676                             descriptor_len, TRUE);
2677                         aux_data_descrip = tvb_get_ptr(p_tvb, offset, descriptor_len);
2678                         if (!pinfo->fd->flags.visited) {
2679                                 /*
2680                                  * Save the auxiliary data descriptor for
2681                                  * future use.
2682                                  */
2683                                 g_assert(trp->aux_data_descrip == NULL);
2684                                 trp->aux_data_descrip =
2685                                     g_strdup(aux_data_descrip);
2686                         }
2687                         offset += descriptor_len;
2688                 }
2689
2690                 /* reset offset, we now start dissecting the data area */
2691                 offset = 0;
2692                 if (has_data && d_tvb && tvb_reported_length(d_tvb) != 0) {
2693                         /*
2694                          * There's a send buffer item in the descriptor
2695                          * string, and the data count in the transaction
2696                          * is non-zero, so there's data to dissect.
2697                          */
2698
2699                         if (lanman->req_data_item != NULL) {
2700                                 /*
2701                                  * Create a protocol tree item for the data.
2702                                  */
2703                                 data_item = (*lanman->req_data_item)(d_tvb,
2704                                     pinfo, tree, offset);
2705                                 data_tree = proto_item_add_subtree(data_item,
2706                                     *lanman->ett_req_data);
2707                         } else {
2708                                 /*
2709                                  * Just leave it at the top level.
2710                                  */
2711                                 data_item = NULL;
2712                                 data_tree = tree;
2713                         }
2714
2715                         /* data */
2716                         offset = dissect_transact_data(d_tvb, offset, -1,
2717                             pinfo, data_tree, data_descrip, lanman->req_data,
2718                             &aux_count);        /* XXX - what about strings? */
2719
2720                         /* auxiliary data */
2721                         if (aux_data_descrip != NULL) {
2722                                 for (i = 0; i < aux_count; i++) {
2723                                         offset = dissect_transact_data(d_tvb,
2724                                             offset, -1, pinfo, data_tree,
2725                                             aux_data_descrip,
2726                                             lanman->req_aux_data, NULL);
2727                                 }
2728                         }
2729
2730                         if (data_item != NULL) {
2731                                 /*
2732                                  * Set the length of the protocol tree item
2733                                  * for the data.
2734                                  */
2735                                 proto_item_set_len(data_item, offset);
2736                         }
2737                 }
2738         } else {
2739                 /*
2740                  * This is a response.
2741                  * Have we seen the request to which it's a response?
2742                  */
2743                 if (trp == NULL)
2744                         return FALSE;   /* no - can't dissect it */
2745
2746                 /* ok we have seen this one before */
2747
2748                 /* if it looks like an interim response, update COL_INFO and return */
2749                 if( ( (p_tvb==NULL) || (tvb_reported_length(p_tvb)==0) )
2750                 &&  ( (d_tvb==NULL) || (tvb_reported_length(d_tvb)==0) ) ){
2751                         /* command */
2752                         if (check_col(pinfo->cinfo, COL_INFO)) {
2753                                 col_add_fstr(pinfo->cinfo, COL_INFO, "%s Interim Response",
2754                                              val_to_str(trp->lanman_cmd, commands, "Unknown Command (%u)"));
2755                         }
2756                         proto_tree_add_uint(tree, hf_function_code, p_tvb, 0, 0, trp->lanman_cmd);
2757                         return TRUE;
2758                 }
2759
2760                 /* command */
2761                 if (check_col(pinfo->cinfo, COL_INFO)) {
2762                         col_add_fstr(pinfo->cinfo, COL_INFO, "%s Response",
2763                                      val_to_str(trp->lanman_cmd, commands, "Unknown Command (%u)"));
2764                 }
2765                 proto_tree_add_uint(tree, hf_function_code, p_tvb, 0, 0,
2766                     trp->lanman_cmd);
2767
2768                 lanman = find_lanman(trp->lanman_cmd);
2769
2770                 /* response parameters */
2771
2772                 /* status */
2773                 status = tvb_get_letohs(p_tvb, offset);
2774                 proto_tree_add_uint(tree, hf_status, p_tvb, offset, 2, status);
2775                 offset += 2;
2776
2777                 /* convert */
2778                 convert = tvb_get_letohs(p_tvb, offset);
2779                 proto_tree_add_uint(tree, hf_convert, p_tvb, offset, 2, convert);
2780                 offset += 2;
2781
2782                 /* rest of the parameters */
2783                 offset = dissect_response_parameters(p_tvb, offset, pinfo, tree,
2784                     trp->param_descrip, lanman->resp, &has_data,
2785                     &has_ent_count, &ent_count);
2786
2787                 /* reset offset, we now start dissecting the data area */
2788                 offset = 0;
2789                 /* data */
2790                 if (has_data && d_tvb && tvb_reported_length(d_tvb) > 0) {
2791                         /*
2792                          * There's a receive buffer item in the descriptor
2793                          * string, and the data count in the transaction
2794                          * is non-zero, so there's data to dissect.
2795                          */
2796                         dissect_response_data(d_tvb, pinfo, convert, tree,
2797                             smb_info, lanman, has_ent_count, ent_count);
2798                 }
2799         }
2800
2801         return TRUE;
2802 }
2803
2804 void
2805 proto_register_pipe_lanman(void)
2806 {
2807         static hf_register_info hf[] = {
2808                 { &hf_function_code,
2809                         { "Function Code", "lanman.function_code", FT_UINT16, BASE_DEC,
2810                         VALS(commands), 0, "LANMAN Function Code/Command", HFILL }},
2811
2812                 { &hf_param_desc,
2813                         { "Parameter Descriptor", "lanman.param_desc", FT_STRING, BASE_NONE,
2814                         NULL, 0, "LANMAN Parameter Descriptor", HFILL }},
2815
2816                 { &hf_return_desc,
2817                         { "Return Descriptor", "lanman.ret_desc", FT_STRING, BASE_NONE,
2818                         NULL, 0, "LANMAN Return Descriptor", HFILL }},
2819
2820                 { &hf_aux_data_desc,
2821                         { "Auxiliary Data Descriptor", "lanman.aux_data_desc", FT_STRING, BASE_NONE,
2822                         NULL, 0, "LANMAN Auxiliary Data Descriptor", HFILL }},
2823
2824                 { &hf_detail_level,
2825                         { "Detail Level", "lanman.level", FT_UINT16, BASE_DEC,
2826                         NULL, 0, "LANMAN Detail Level", HFILL }},
2827
2828                 { &hf_recv_buf_len,
2829                         { "Receive Buffer Length", "lanman.recv_buf_len", FT_UINT16, BASE_DEC,
2830                         NULL, 0, "LANMAN Receive Buffer Length", HFILL }},
2831
2832                 { &hf_send_buf_len,
2833                         { "Send Buffer Length", "lanman.send_buf_len", FT_UINT16, BASE_DEC,
2834                         NULL, 0, "LANMAN Send Buffer Length", HFILL }},
2835
2836                 { &hf_continuation_from,
2837                         { "Continuation from message in frame", "lanman.continuation_from", FT_UINT32, BASE_DEC,
2838                         NULL, 0, "This is a LANMAN continuation from the message in the frame in question", HFILL }},
2839
2840                 { &hf_status,
2841                         { "Status", "lanman.status", FT_UINT16, BASE_DEC,
2842                         VALS(status_vals), 0, "LANMAN Return status", HFILL }},
2843
2844                 { &hf_convert,
2845                         { "Convert", "lanman.convert", FT_UINT16, BASE_DEC,
2846                         NULL, 0, "LANMAN Convert", HFILL }},
2847
2848                 { &hf_ecount,
2849                         { "Entry Count", "lanman.entry_count", FT_UINT16, BASE_DEC,
2850                         NULL, 0, "LANMAN Number of Entries", HFILL }},
2851
2852                 { &hf_acount,
2853                         { "Available Entries", "lanman.available_count", FT_UINT16, BASE_DEC,
2854                         NULL, 0, "LANMAN Number of Available Entries", HFILL }},
2855
2856                 { &hf_share_name,
2857                         { "Share Name", "lanman.share.name", FT_STRING, BASE_NONE,
2858                         NULL, 0, "LANMAN Name of Share", HFILL }},
2859
2860                 { &hf_share_type,
2861                         { "Share Type", "lanman.share.type", FT_UINT16, BASE_DEC,
2862                         VALS(share_type_vals), 0, "LANMAN Type of Share", HFILL }},
2863
2864                 { &hf_share_comment,
2865                         { "Share Comment", "lanman.share.comment", FT_STRING, BASE_NONE,
2866                         NULL, 0, "LANMAN Share Comment", HFILL }},
2867
2868                 { &hf_share_permissions,
2869                         { "Share Permissions", "lanman.share.permissions", FT_UINT16, BASE_DEC,
2870                         NULL, 0, "LANMAN Permissions on share", HFILL }},
2871
2872                 { &hf_share_max_uses,
2873                         { "Share Max Uses", "lanman.share.max_uses", FT_UINT16, BASE_DEC,
2874                         NULL, 0, "LANMAN Max connections allowed to share", HFILL }},
2875
2876                 { &hf_share_current_uses,
2877                         { "Share Current Uses", "lanman.share.current_uses", FT_UINT16, BASE_DEC,
2878                         NULL, 0, "LANMAN Current connections to share", HFILL }},
2879
2880                 { &hf_share_path,
2881                         { "Share Path", "lanman.share.path", FT_STRING, BASE_NONE,
2882                         NULL, 0, "LANMAN Share Path", HFILL }},
2883
2884                 { &hf_share_password,
2885                         { "Share Password", "lanman.share.password", FT_STRING, BASE_NONE,
2886                         NULL, 0, "LANMAN Share Password", HFILL }},
2887
2888                 { &hf_server_name,
2889                         { "Server Name", "lanman.server.name", FT_STRING, BASE_NONE,
2890                         NULL, 0, "LANMAN Name of Server", HFILL }},
2891
2892                 { &hf_server_major,
2893                         { "Major Version", "lanman.server.major", FT_UINT8, BASE_DEC,
2894                         NULL, 0, "LANMAN Server Major Version", HFILL }},
2895
2896                 { &hf_server_minor,
2897                         { "Minor Version", "lanman.server.minor", FT_UINT8, BASE_DEC,
2898                         NULL, 0, "LANMAN Server Minor Version", HFILL }},
2899
2900                 { &hf_server_comment,
2901                         { "Server Comment", "lanman.server.comment", FT_STRING, BASE_NONE,
2902                         NULL, 0, "LANMAN Server Comment", HFILL }},
2903
2904                 { &hf_abytes,
2905                         { "Available Bytes", "lanman.available_bytes", FT_UINT16, BASE_DEC,
2906                         NULL, 0, "LANMAN Number of Available Bytes", HFILL }},
2907
2908                 { &hf_current_time,
2909                         { "Current Date/Time", "lanman.current_time", FT_ABSOLUTE_TIME, BASE_NONE,
2910                         NULL, 0, "LANMAN Current date and time, in seconds since 00:00:00, January 1, 1970", HFILL }},
2911
2912                 { &hf_msecs,
2913                         { "Milliseconds", "lanman.msecs", FT_UINT32, BASE_DEC,
2914                         NULL, 0, "LANMAN Milliseconds since arbitrary time in the past (typically boot time)", HFILL }},
2915
2916                 { &hf_hour,
2917                         { "Hour", "lanman.hour", FT_UINT8, BASE_DEC,
2918                         NULL, 0, "LANMAN Current hour", HFILL }},
2919
2920                 { &hf_minute,
2921                         { "Minute", "lanman.minute", FT_UINT8, BASE_DEC,
2922                         NULL, 0, "LANMAN Current minute", HFILL }},
2923
2924                 { &hf_second,
2925                         { "Second", "lanman.second", FT_UINT8, BASE_DEC,
2926                         NULL, 0, "LANMAN Current second", HFILL }},
2927
2928                 { &hf_hundredths,
2929                         { "Hundredths of a second", "lanman.hundredths", FT_UINT8, BASE_DEC,
2930                         NULL, 0, "LANMAN Current hundredths of a second", HFILL }},
2931
2932                 { &hf_tzoffset,
2933                         { "Time Zone Offset", "lanman.tzoffset", FT_INT16, BASE_DEC,
2934                         NULL, 0, "LANMAN Offset of time zone from GMT, in minutes", HFILL }},
2935
2936                 { &hf_timeinterval,
2937                         { "Time Interval", "lanman.timeinterval", FT_UINT16, BASE_DEC,
2938                         NULL, 0, "LANMAN .0001 second units per clock tick", HFILL }},
2939
2940                 { &hf_day,
2941                         { "Day", "lanman.day", FT_UINT8, BASE_DEC,
2942                         NULL, 0, "LANMAN Current day", HFILL }},
2943
2944                 { &hf_month,
2945                         { "Month", "lanman.month", FT_UINT8, BASE_DEC,
2946                         NULL, 0, "LANMAN Current month", HFILL }},
2947
2948                 { &hf_year,
2949                         { "Year", "lanman.year", FT_UINT16, BASE_DEC,
2950                         NULL, 0, "LANMAN Current year", HFILL }},
2951
2952                 { &hf_weekday,
2953                         { "Weekday", "lanman.weekday", FT_UINT8, BASE_DEC,
2954                         VALS(weekday_vals), 0, "LANMAN Current day of the week", HFILL }},
2955
2956                 { &hf_enumeration_domain,
2957                         { "Enumeration Domain", "lanman.enumeration_domain", FT_STRING, BASE_NONE,
2958                         NULL, 0, "LANMAN Domain in which to enumerate servers", HFILL }},
2959
2960                 { &hf_computer_name,
2961                         { "Computer Name", "lanman.computer_name", FT_STRING, BASE_NONE,
2962                         NULL, 0, "LANMAN Computer Name", HFILL }},
2963
2964                 { &hf_user_name,
2965                         { "User Name", "lanman.user_name", FT_STRING, BASE_NONE,
2966                         NULL, 0, "LANMAN User Name", HFILL }},
2967
2968                 { &hf_group_name,
2969                         { "Group Name", "lanman.group_name", FT_STRING, BASE_NONE,
2970                         NULL, 0, "LANMAN Group Name", HFILL }},
2971
2972                 { &hf_workstation_domain,
2973                         { "Workstation Domain", "lanman.workstation_domain", FT_STRING, BASE_NONE,
2974                         NULL, 0, "LANMAN Workstation Domain", HFILL }},
2975
2976                 { &hf_workstation_major,
2977                         { "Workstation Major Version", "lanman.workstation_major", FT_UINT8, BASE_DEC,
2978                         NULL, 0, "LANMAN Workstation Major Version", HFILL }},
2979
2980                 { &hf_workstation_minor,
2981                         { "Workstation Minor Version", "lanman.workstation_minor", FT_UINT8, BASE_DEC,
2982                         NULL, 0, "LANMAN Workstation Minor Version", HFILL }},
2983
2984                 { &hf_logon_domain,
2985                         { "Logon Domain", "lanman.logon_domain", FT_STRING, BASE_NONE,
2986                         NULL, 0, "LANMAN Logon Domain", HFILL }},
2987
2988                 { &hf_other_domains,
2989                         { "Other Domains", "lanman.other_domains", FT_STRING, BASE_NONE,
2990                         NULL, 0, "LANMAN Other Domains", HFILL }},
2991
2992                 { &hf_password,
2993                         { "Password", "lanman.password", FT_STRING, BASE_NONE,
2994                         NULL, 0, "LANMAN Password", HFILL }},
2995
2996                 { &hf_workstation_name,
2997                         { "Workstation Name", "lanman.workstation_name", FT_STRING, BASE_NONE,
2998                         NULL, 0, "LANMAN Workstation Name", HFILL }},
2999
3000                 { &hf_ustruct_size,
3001                         { "Length of UStruct", "lanman.ustruct_size", FT_UINT16, BASE_DEC,
3002                         NULL, 0, "LANMAN UStruct Length", HFILL }},
3003
3004                 { &hf_logon_code,
3005                         { "Logon Code", "lanman.logon_code", FT_UINT16, BASE_DEC,
3006                         VALS(status_vals), 0, "LANMAN Logon Code", HFILL }},
3007
3008                 { &hf_privilege_level,
3009                         { "Privilege Level", "lanman.privilege_level", FT_UINT16, BASE_DEC,
3010                         VALS(privilege_vals), 0, "LANMAN Privilege Level", HFILL }},
3011
3012                 { &hf_operator_privileges,
3013                         { "Operator Privileges", "lanman.operator_privileges", FT_UINT32, BASE_DEC,
3014                         VALS(op_privilege_vals), 0, "LANMAN Operator Privileges", HFILL }},
3015
3016                 { &hf_num_logons,
3017                         { "Number of Logons", "lanman.num_logons", FT_UINT16, BASE_DEC,
3018                         NULL, 0, "LANMAN Number of Logons", HFILL }},
3019
3020                 { &hf_bad_pw_count,
3021                         { "Bad Password Count", "lanman.bad_pw_count", FT_UINT16, BASE_DEC,
3022                         NULL, 0, "LANMAN Number of incorrect passwords entered since last successful login", HFILL }},
3023
3024                 { &hf_last_logon,
3025                         { "Last Logon Date/Time", "lanman.last_logon", FT_ABSOLUTE_TIME, BASE_NONE,
3026                         NULL, 0, "LANMAN Date and time of last logon", HFILL }},
3027
3028                 { &hf_last_logoff,
3029                         { "Last Logoff Date/Time", "lanman.last_logoff", FT_ABSOLUTE_TIME, BASE_NONE,
3030                         NULL, 0, "LANMAN Date and time of last logoff", HFILL }},
3031
3032                 { &hf_logoff_time,
3033                         { "Logoff Date/Time", "lanman.logoff_time", FT_ABSOLUTE_TIME, BASE_NONE,
3034                         NULL, 0, "LANMAN Date and time when user should log off", HFILL }},
3035
3036                 { &hf_kickoff_time,
3037                         { "Kickoff Date/Time", "lanman.kickoff_time", FT_ABSOLUTE_TIME, BASE_NONE,
3038                         NULL, 0, "LANMAN Date and time when user will be logged off", HFILL }},
3039
3040                 { &hf_password_age,
3041                         { "Password Age", "lanman.password_age", FT_RELATIVE_TIME, BASE_NONE,
3042                         NULL, 0, "LANMAN Time since user last changed his/her password", HFILL }},
3043
3044                 { &hf_password_can_change,
3045                         { "Password Can Change", "lanman.password_can_change", FT_ABSOLUTE_TIME, BASE_NONE,
3046                         NULL, 0, "LANMAN Date and time when user can change their password", HFILL }},
3047
3048                 { &hf_password_must_change,
3049                         { "Password Must Change", "lanman.password_must_change", FT_ABSOLUTE_TIME, BASE_NONE,
3050                         NULL, 0, "LANMAN Date and time when user must change their password", HFILL }},
3051
3052                 { &hf_script_path,
3053                         { "Script Path", "lanman.script_path", FT_STRING, BASE_NONE,
3054                         NULL, 0, "LANMAN Pathname of user's logon script", HFILL }},
3055
3056                 { &hf_logoff_code,
3057                         { "Logoff Code", "lanman.logoff_code", FT_UINT16, BASE_DEC,
3058                         VALS(status_vals), 0, "LANMAN Logoff Code", HFILL }},
3059
3060                 { &hf_duration,
3061                         { "Duration of Session", "lanman.duration", FT_RELATIVE_TIME, BASE_NONE,
3062                         NULL, 0, "LANMAN Number of seconds the user was logged on", HFILL }},
3063
3064                 { &hf_comment,
3065                         { "Comment", "lanman.comment", FT_STRING, BASE_NONE,
3066                         NULL, 0, "LANMAN Comment", HFILL }},
3067
3068                 { &hf_user_comment,
3069                         { "User Comment", "lanman.user_comment", FT_STRING, BASE_NONE,
3070                         NULL, 0, "LANMAN User Comment", HFILL }},
3071
3072                 { &hf_full_name,
3073                         { "Full Name", "lanman.full_name", FT_STRING, BASE_NONE,
3074                         NULL, 0, "LANMAN Full Name", HFILL }},
3075
3076                 { &hf_homedir,
3077                         { "Home Directory", "lanman.homedir", FT_STRING, BASE_NONE,
3078                         NULL, 0, "LANMAN Home Directory", HFILL }},
3079
3080                 { &hf_parameters,
3081                         { "Parameters", "lanman.parameters", FT_STRING, BASE_NONE,
3082                         NULL, 0, "LANMAN Parameters", HFILL }},
3083
3084                 { &hf_logon_server,
3085                         { "Logon Server", "lanman.logon_server", FT_STRING, BASE_NONE,
3086                         NULL, 0, "LANMAN Logon Server", HFILL }},
3087
3088                 /* XXX - we should have a value_string table for this */
3089                 { &hf_country_code,
3090                         { "Country Code", "lanman.country_code", FT_UINT16, BASE_DEC,
3091                         VALS(ms_country_codes), 0, "LANMAN Country Code", HFILL }},
3092
3093                 { &hf_workstations,
3094                         { "Workstations", "lanman.workstations", FT_STRING, BASE_NONE,
3095                         NULL, 0, "LANMAN Workstations", HFILL }},
3096
3097                 { &hf_max_storage,
3098                         { "Max Storage", "lanman.max_storage", FT_UINT32, BASE_DEC,
3099                         NULL, 0, "LANMAN Max Storage", HFILL }},
3100
3101                 { &hf_units_per_week,
3102                         { "Units Per Week", "lanman.units_per_week", FT_UINT16, BASE_DEC,
3103                         NULL, 0, "LANMAN Units Per Week", HFILL }},
3104
3105                 { &hf_logon_hours,
3106                         { "Logon Hours", "lanman.logon_hours", FT_BYTES, BASE_NONE,
3107                         NULL, 0, "LANMAN Logon Hours", HFILL }},
3108
3109                 /* XXX - we should have a value_string table for this */
3110                 { &hf_code_page,
3111                         { "Code Page", "lanman.code_page", FT_UINT16, BASE_DEC,
3112                         NULL, 0, "LANMAN Code Page", HFILL }},
3113
3114                 { &hf_new_password,
3115                         { "New Password", "lanman.new_password", FT_BYTES, BASE_HEX,
3116                         NULL, 0, "LANMAN New Password (encrypted)", HFILL }},
3117
3118                 { &hf_old_password,
3119                         { "Old Password", "lanman.old_password", FT_BYTES, BASE_HEX,
3120                         NULL, 0, "LANMAN Old Password (encrypted)", HFILL }},
3121
3122                 { &hf_reserved,
3123                         { "Reserved", "lanman.reserved", FT_UINT32, BASE_HEX,
3124                         NULL, 0, "LANMAN Reserved", HFILL }},
3125
3126         };
3127         static gint *ett[] = {
3128                 &ett_lanman,
3129                 &ett_lanman_unknown_entries,
3130                 &ett_lanman_unknown_entry,
3131                 &ett_lanman_servers,
3132                 &ett_lanman_server,
3133                 &ett_lanman_groups,
3134                 &ett_lanman_shares,
3135                 &ett_lanman_share,
3136         };
3137
3138         proto_smb_lanman = proto_register_protocol(
3139                 "Microsoft Windows Lanman Remote API Protocol", "LANMAN", "lanman");
3140         proto_register_field_array(proto_smb_lanman, hf, array_length(hf));
3141         proto_register_subtree_array(ett, array_length(ett));
3142 }
3143
3144 static heur_dissector_list_t smb_transact_heur_subdissector_list;
3145
3146 gboolean
3147 dissect_pipe_dcerpc(tvbuff_t *d_tvb, packet_info *pinfo, proto_tree *parent_tree,
3148     proto_tree *tree, guint32 fid)
3149 {
3150         dcerpc_private_info dcerpc_priv;
3151         smb_info_t *smb_priv = (smb_info_t *)pinfo->private_data;
3152         gboolean result;
3153         gboolean save_fragmented;
3154
3155         dcerpc_priv.transport_type = DCERPC_TRANSPORT_SMB;
3156         dcerpc_priv.data.smb.fid = fid;
3157
3158         pinfo->private_data = &dcerpc_priv;
3159
3160         /* offer desegmentation service to DCERPC */
3161         pinfo->can_desegment=0;
3162         pinfo->desegment_offset = 0;
3163         pinfo->desegment_len = 0;
3164         if(smb_dcerpc_reassembly){ 
3165                 pinfo->can_desegment=2;
3166         }
3167
3168         save_fragmented = pinfo->fragmented;
3169
3170         /* see if this packet is already desegmented */
3171         if(smb_dcerpc_reassembly && pinfo->fd->flags.visited){
3172                 fragment_data *fd_head;
3173                 tvbuff_t *new_tvb;
3174
3175                 fd_head=fragment_get(pinfo, pinfo->fd->num , 
3176                         dcerpc_fragment_table);
3177                 if(fd_head && fd_head->flags&FD_DEFRAGMENTED){
3178                         proto_tree *tr;
3179                         proto_item *it;
3180                         fragment_data *fd;
3181                 
3182                         new_tvb = tvb_new_real_data(fd_head->data,
3183                                   fd_head->datalen, fd_head->datalen);
3184                         tvb_set_child_real_data_tvbuff(d_tvb, new_tvb);
3185                         add_new_data_source(pinfo->fd, new_tvb,
3186                                   "DCERPC over SMB");
3187                         pinfo->fragmented=FALSE;
3188
3189                         d_tvb=new_tvb;
3190
3191                         /* list what segments we have */
3192                         it = proto_tree_add_text(tree, d_tvb, 0, -1, "Fragments");
3193                         tr = proto_item_add_subtree(it, ett_smb_pipe_fragments);
3194                         for(fd=fd_head->next;fd;fd=fd->next){
3195                                 proto_tree_add_text(tr, d_tvb, fd->offset, fd->len,
3196                                             "Frame:%u Data:%u-%u",
3197                                             fd->frame, fd->offset,
3198                                             fd->offset+fd->len-1);
3199                         }
3200                 }
3201         }
3202
3203         result = dissector_try_heuristic(smb_transact_heur_subdissector_list, d_tvb,
3204                                          pinfo, parent_tree);
3205         pinfo->private_data = smb_priv;
3206
3207         /* check if dissector wanted us to desegment the data */
3208         if(smb_dcerpc_reassembly && !pinfo->fd->flags.visited && pinfo->desegment_len){
3209                 fragment_add(d_tvb, 0, pinfo, pinfo->fd->num,
3210                         dcerpc_fragment_table,
3211                         0, tvb_length(d_tvb), TRUE);
3212                 fragment_set_tot_len(pinfo, pinfo->fd->num, 
3213                         dcerpc_fragment_table, 
3214                         pinfo->desegment_len+tvb_length(d_tvb));
3215                 /* since the other fragments are in normal ReadAndX and WriteAndX calls
3216                    we must make sure we can map FID values to this defragmentation
3217                    session */
3218                 /* first remove any old mappings */
3219                 if(g_hash_table_lookup(smb_priv->ct->dcerpc_fid_to_frame, (void *)fid)){
3220                         g_hash_table_remove(smb_priv->ct->dcerpc_fid_to_frame, (void *)fid);
3221                 }
3222                 g_hash_table_insert(smb_priv->ct->dcerpc_fid_to_frame, (void *)fid, 
3223                         (void *)pinfo->fd->num);
3224         }
3225         /* clear out the variables */
3226         pinfo->can_desegment=0;
3227         pinfo->desegment_offset = 0;
3228         pinfo->desegment_len = 0;
3229
3230         if (!result)
3231                 call_dissector(data_handle, d_tvb, pinfo, parent_tree);
3232
3233         pinfo->fragmented = save_fragmented;
3234         return TRUE;
3235 }
3236
3237 void
3238 proto_register_pipe_dcerpc(void)
3239 {
3240         register_heur_dissector_list("smb_transact", &smb_transact_heur_subdissector_list);
3241 }
3242
3243 #define CALL_NAMED_PIPE         0x54
3244 #define WAIT_NAMED_PIPE         0x53
3245 #define PEEK_NAMED_PIPE         0x23
3246 #define Q_NM_P_HAND_STATE       0x21
3247 #define SET_NM_P_HAND_STATE     0x01
3248 #define Q_NM_PIPE_INFO          0x22
3249 #define TRANSACT_NM_PIPE        0x26
3250 #define RAW_READ_NM_PIPE        0x11
3251 #define RAW_WRITE_NM_PIPE       0x31
3252
3253 static const value_string functions[] = {
3254         {CALL_NAMED_PIPE,       "CallNamedPipe"},
3255         {WAIT_NAMED_PIPE,       "WaitNamedPipe"},
3256         {PEEK_NAMED_PIPE,       "PeekNamedPipe"},
3257         {Q_NM_P_HAND_STATE,     "QNmPHandState"},
3258         {SET_NM_P_HAND_STATE,   "SetNmPHandState"},
3259         {Q_NM_PIPE_INFO,        "QNmPipeInfo"},
3260         {TRANSACT_NM_PIPE,      "TransactNmPipe"},
3261         {RAW_READ_NM_PIPE,      "RawReadNmPipe"},
3262         {RAW_WRITE_NM_PIPE,     "RawWriteNmPipe"},
3263         {0,                     NULL}
3264 };
3265
3266 static const value_string pipe_status[] = {
3267         {1,     "Disconnected by server"},
3268         {2,     "Listening"},
3269         {3,     "Connection to server is OK"},
3270         {4,     "Server end of pipe is closed"},
3271         {0,     NULL}
3272 };
3273
3274 #define PIPE_LANMAN     1
3275 #define PIPE_DCERPC     2
3276
3277 /* decode the SMB pipe protocol
3278    for requests
3279     pipe is the name of the pipe, e.g. LANMAN
3280     smb_info->trans_subcmd is set to the symbolic constant matching the mailslot name
3281   for responses
3282     pipe is NULL
3283     smb_info->trans_subcmd gives us which pipe this response is for
3284 */
3285 gboolean
3286 dissect_pipe_smb(tvbuff_t *sp_tvb, tvbuff_t *s_tvb, tvbuff_t *pd_tvb,
3287                  tvbuff_t *p_tvb, tvbuff_t *d_tvb, const char *pipe,
3288                  packet_info *pinfo, proto_tree *tree)
3289 {
3290         smb_info_t *smb_info;
3291         smb_transact_info_t *tri;
3292         guint sp_len;
3293         proto_item *pipe_item = NULL;
3294         proto_tree *pipe_tree = NULL;
3295         int offset;
3296         int trans_subcmd;
3297         int function;
3298         int fid = -1;
3299         guint16 info_level;
3300
3301         if (!proto_is_protocol_enabled(proto_smb_pipe))
3302                 return FALSE;
3303         pinfo->current_proto = "SMB Pipe";
3304
3305         smb_info = pinfo->private_data;
3306
3307         /*
3308          * Set the columns.
3309          */
3310         if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
3311                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "SMB Pipe");
3312         }
3313         if (check_col(pinfo->cinfo, COL_INFO)) {
3314                 col_set_str(pinfo->cinfo, COL_INFO,
3315                     smb_info->request ? "Request" : "Response");
3316         }
3317
3318         if (smb_info->sip != NULL)
3319                 tri = smb_info->sip->extra_info;
3320         else
3321                 tri = NULL;
3322
3323         /*
3324          * Set up a subtree for the pipe protocol.  (It might not contain
3325          * anything.)
3326          */
3327         if (sp_tvb != NULL)
3328                 sp_len = tvb_length(sp_tvb);
3329         else
3330                 sp_len = 0;
3331         if (tree) {
3332                 pipe_item = proto_tree_add_item(tree, proto_smb_pipe,
3333                     sp_tvb, 0, sp_len, FALSE);
3334                 pipe_tree = proto_item_add_subtree(pipe_item, ett_smb_pipe);
3335         }
3336         offset = 0;
3337
3338         /*
3339          * Do we have any setup words at all?
3340          */
3341         if (s_tvb != NULL && tvb_length(s_tvb) != 0) {
3342                 /*
3343                  * Yes.  The first of them is the function.
3344                  */
3345                 function = tvb_get_letohs(s_tvb, offset);
3346                 proto_tree_add_uint(pipe_tree, hf_pipe_function, s_tvb,
3347                     offset, 2, function);
3348                 offset += 2;
3349                 if (check_col(pinfo->cinfo, COL_INFO)) {
3350                         col_add_fstr(pinfo->cinfo, COL_INFO, "%s %s",
3351                             val_to_str(function, functions, "Unknown function (0x%04x)"),
3352                             smb_info->request ? "Request" : "Response");
3353                 }
3354                 if (tri != NULL)
3355                         tri->function = function;
3356
3357                 /*
3358                  * The second of them depends on the function.
3359                  */
3360                 switch (function) {
3361
3362                 case CALL_NAMED_PIPE:
3363                 case WAIT_NAMED_PIPE:
3364                         /*
3365                          * It's a priority.
3366                          */
3367                         proto_tree_add_item(pipe_tree, hf_pipe_priority, s_tvb,
3368                             offset, 2, TRUE);
3369                         break;
3370
3371                 case PEEK_NAMED_PIPE:
3372                 case Q_NM_P_HAND_STATE:
3373                 case SET_NM_P_HAND_STATE:
3374                 case Q_NM_PIPE_INFO:
3375                 case TRANSACT_NM_PIPE:
3376                 case RAW_READ_NM_PIPE:
3377                 case RAW_WRITE_NM_PIPE:
3378                         /*
3379                          * It's a FID.
3380                          */
3381                         fid = tvb_get_letohs(s_tvb, 2);
3382                         add_fid(s_tvb, pinfo, pipe_tree, offset, 2, fid);
3383                         if (tri != NULL)
3384                                 tri->fid = fid;
3385                         break;
3386
3387                 default:
3388                         /*
3389                          * It's something unknown.
3390                          * XXX - put it into the tree?
3391                          */
3392                         break;
3393                 }
3394                 offset += 2;
3395         } else {
3396                 /*
3397                  * This is either a response or a pipe transaction with
3398                  * no setup information.
3399                  *
3400                  * In the former case, we can get that information from
3401                  * the matching request, if we saw it.
3402                  *
3403                  * In the latter case, there is no function or FID.
3404                  */
3405                 if (tri != NULL && tri->function != -1) {
3406                         function = tri->function;
3407                         proto_tree_add_uint(pipe_tree, hf_pipe_function, NULL,
3408                             0, 0, function);
3409                         if (check_col(pinfo->cinfo, COL_INFO)) {
3410                                 col_add_fstr(pinfo->cinfo, COL_INFO, "%s %s",
3411                                     val_to_str(function, functions, "Unknown function (0x%04x)"),
3412                                     smb_info->request ? "Request" : "Response");
3413                         }
3414                         fid = tri->fid;
3415                         if (fid != -1)
3416                                 add_fid(NULL, pinfo, pipe_tree, 0, 0, fid);
3417                 } else {
3418                         function = -1;
3419                         fid = -1;
3420                 }
3421         }
3422
3423         /*
3424          * XXX - put the byte count and the pipe name into the tree as well;
3425          * that requires us to fetch a possibly-Unicode string.
3426          */
3427
3428         if(smb_info->request){
3429                 if(strncmp(pipe,"LANMAN",6) == 0){
3430                         trans_subcmd=PIPE_LANMAN;
3431                 } else {
3432                         /* assume it is DCERPC */
3433                         trans_subcmd=PIPE_DCERPC;
3434                 }
3435                 
3436                 if (!pinfo->fd->flags.visited)
3437                         tri->trans_subcmd = trans_subcmd;
3438         } else
3439                 trans_subcmd = tri->trans_subcmd;
3440
3441         if (tri == NULL) {
3442                 /*
3443                  * We don't know what type of pipe transaction this
3444                  * was, so indicate that we didn't dissect it.
3445                  */
3446                 return FALSE;
3447         }
3448
3449         switch (function) {
3450
3451         case CALL_NAMED_PIPE:
3452         case TRANSACT_NM_PIPE:
3453                 switch(trans_subcmd){
3454
3455                 case PIPE_LANMAN:
3456                         return dissect_pipe_lanman(pd_tvb, p_tvb, d_tvb, pinfo,
3457                             tree);
3458                         break;
3459
3460                 case PIPE_DCERPC:
3461                         /*
3462                          * Only dissect this if we know the FID.
3463                          */
3464                         if (fid != -1) {
3465                                 if (d_tvb == NULL)
3466                                         return FALSE;
3467                                 return dissect_pipe_dcerpc(d_tvb, pinfo, tree,
3468                                     pipe_tree, fid);
3469                         }
3470                         break;
3471                 }
3472                 break;
3473
3474         case -1:
3475                 /*
3476                  * We don't know the function; we dissect only LANMAN
3477                  * pipe messages, not RPC pipe messages, in that case.
3478                  */
3479                 switch(trans_subcmd){
3480                 case PIPE_LANMAN:
3481                         return dissect_pipe_lanman(pd_tvb, p_tvb, d_tvb, pinfo,
3482                             tree);
3483                         break;
3484                 }
3485                 break;
3486
3487         case WAIT_NAMED_PIPE:
3488                 break;
3489
3490         case PEEK_NAMED_PIPE:
3491                 /*
3492                  * Request contains no parameters or data.
3493                  */
3494                 if (!smb_info->request) {
3495                         if (p_tvb == NULL)
3496                                 return FALSE;
3497                         offset = 0;
3498                         proto_tree_add_item(pipe_tree, hf_pipe_peek_available,
3499                             p_tvb, offset, 2, TRUE);
3500                         offset += 2;
3501                         proto_tree_add_item(pipe_tree, hf_pipe_peek_remaining,
3502                             p_tvb, offset, 2, TRUE);
3503                         offset += 2;
3504                         proto_tree_add_item(pipe_tree, hf_pipe_peek_status,
3505                             p_tvb, offset, 2, TRUE);
3506                         offset += 2;
3507                 }
3508                 break;
3509
3510         case Q_NM_P_HAND_STATE:
3511                 /*
3512                  * Request contains no parameters or data.
3513                  */
3514                 if (!smb_info->request) {
3515                         if (p_tvb == NULL)
3516                                 return FALSE;
3517                         offset = dissect_ipc_state(p_tvb, pinfo, pipe_tree, 0,
3518                             FALSE);
3519                 }
3520                 break;
3521
3522         case SET_NM_P_HAND_STATE:
3523                 /*
3524                  * Response contains no parameters or data.
3525                  */
3526                 if (smb_info->request) {
3527                         if (p_tvb == NULL)
3528                                 return FALSE;
3529                         offset = dissect_ipc_state(p_tvb, pinfo, pipe_tree, 0,
3530                             TRUE);
3531                 }
3532                 break;
3533
3534         case Q_NM_PIPE_INFO:
3535                 offset = 0;
3536                 if (smb_info->request) {
3537                         if (p_tvb == NULL)
3538                                 return FALSE;
3539
3540                         /*
3541                          * Request contains an information level.
3542                          */
3543                         info_level = tvb_get_letohs(p_tvb, offset);
3544                         proto_tree_add_uint(pipe_tree, hf_pipe_getinfo_info_level,
3545                             p_tvb, offset, 2, info_level);
3546                         offset += 2;
3547                         if (!pinfo->fd->flags.visited)
3548                                 tri->info_level = info_level;
3549                 } else {
3550                         guint8 pipe_namelen;
3551
3552                         if (d_tvb == NULL)
3553                                 return FALSE;
3554
3555                         switch (tri->info_level) {
3556
3557                         case 1:
3558                                 proto_tree_add_item(pipe_tree,
3559                                     hf_pipe_getinfo_output_buffer_size,
3560                                     d_tvb, offset, 2, TRUE);
3561                                 offset += 2;
3562                                 proto_tree_add_item(pipe_tree,
3563                                     hf_pipe_getinfo_input_buffer_size,
3564                                     d_tvb, offset, 2, TRUE);
3565                                 offset += 2;
3566                                 proto_tree_add_item(pipe_tree,
3567                                     hf_pipe_getinfo_maximum_instances,
3568                                     d_tvb, offset, 1, TRUE);
3569                                 offset += 1;
3570                                 proto_tree_add_item(pipe_tree,
3571                                     hf_pipe_getinfo_current_instances,
3572                                     d_tvb, offset, 1, TRUE);
3573                                 offset += 1;
3574                                 pipe_namelen = tvb_get_guint8(d_tvb, offset);
3575                                 proto_tree_add_uint(pipe_tree,
3576                                     hf_pipe_getinfo_pipe_name_length,
3577                                     d_tvb, offset, 1, pipe_namelen);
3578                                 offset += 1;
3579                                 /* XXX - can this be Unicode? */
3580                                 proto_tree_add_item(pipe_tree,
3581                                     hf_pipe_getinfo_pipe_name,
3582                                     d_tvb, offset, pipe_namelen, TRUE);
3583                                 break;
3584                         }
3585                 }
3586                 break;
3587
3588         case RAW_READ_NM_PIPE:
3589                 /*
3590                  * Request contains no parameters or data.
3591                  */
3592                 if (!smb_info->request) {
3593                         if (d_tvb == NULL)
3594                                 return FALSE;
3595
3596                         offset = dissect_file_data(d_tvb, pinfo, pipe_tree, 0,
3597                             tvb_reported_length(d_tvb),
3598                             tvb_reported_length(d_tvb));
3599                 }
3600                 break;
3601
3602         case RAW_WRITE_NM_PIPE:
3603                 offset = 0;
3604                 if (smb_info->request) {
3605                         if (d_tvb == NULL)
3606                                 return FALSE;
3607
3608                         offset = dissect_file_data(d_tvb, pinfo, pipe_tree,
3609                             offset, tvb_reported_length(d_tvb),
3610                             tvb_reported_length(d_tvb));
3611                 } else {
3612                         if (p_tvb == NULL)
3613                                 return FALSE;
3614                         proto_tree_add_item(pipe_tree,
3615                             hf_pipe_write_raw_bytes_written,
3616                             p_tvb, offset, 2, TRUE);
3617                         offset += 2;
3618                 }
3619                 break;
3620         }
3621         return TRUE;
3622 }
3623
3624 void
3625 proto_register_smb_pipe(void)
3626 {
3627         static hf_register_info hf[] = {
3628                 { &hf_pipe_function,
3629                         { "Function", "pipe.function", FT_UINT16, BASE_HEX,
3630                         VALS(functions), 0, "SMB Pipe Function Code", HFILL }},
3631                 { &hf_pipe_priority,
3632                         { "Priority", "pipe.priority", FT_UINT16, BASE_DEC,
3633                         NULL, 0, "SMB Pipe Priority", HFILL }},
3634                 { &hf_pipe_peek_available,
3635                         { "Available Bytes", "pipe.peek.available_bytes", FT_UINT16, BASE_DEC,
3636                         NULL, 0, "Total number of bytes available to be read from the pipe", HFILL }},
3637                 { &hf_pipe_peek_remaining,
3638                         { "Bytes Remaining", "pipe.peek.remaining_bytes", FT_UINT16, BASE_DEC,
3639                         NULL, 0, "Total number of bytes remaining in the message at the head of the pipe", HFILL }},
3640                 { &hf_pipe_peek_status,
3641                         { "Pipe Status", "pipe.peek.status", FT_UINT16, BASE_DEC,
3642                         VALS(pipe_status), 0, "Pipe status", HFILL }},
3643                 { &hf_pipe_getinfo_info_level,
3644                         { "Information Level", "pipe.getinfo.info_level", FT_UINT16, BASE_DEC,
3645                         NULL, 0, "Information level of information to return", HFILL }},
3646                 { &hf_pipe_getinfo_output_buffer_size,
3647                         { "Output Buffer Size", "pipe.getinfo.output_buffer_size", FT_UINT16, BASE_DEC,
3648                         NULL, 0, "Actual size of buffer for outgoing (server) I/O", HFILL }},
3649                 { &hf_pipe_getinfo_input_buffer_size,
3650                         { "Input Buffer Size", "pipe.getinfo.input_buffer_size", FT_UINT16, BASE_DEC,
3651                         NULL, 0, "Actual size of buffer for incoming (client) I/O", HFILL }},
3652                 { &hf_pipe_getinfo_maximum_instances,
3653                         { "Maximum Instances", "pipe.getinfo.maximum_instances", FT_UINT8, BASE_DEC,
3654                         NULL, 0, "Maximum allowed number of instances", HFILL }},
3655                 { &hf_pipe_getinfo_current_instances,
3656                         { "Current Instances", "pipe.getinfo.current_instances", FT_UINT8, BASE_DEC,
3657                         NULL, 0, "Current number of instances", HFILL }},
3658                 { &hf_pipe_getinfo_pipe_name_length,
3659                         { "Pipe Name Length", "pipe.getinfo.pipe_name_length", FT_UINT8, BASE_DEC,
3660                         NULL, 0, "Length of pipe name", HFILL }},
3661                 { &hf_pipe_getinfo_pipe_name,
3662                         { "Pipe Name", "pipe.getinfo.pipe_name", FT_STRING, BASE_NONE,
3663                         NULL, 0, "Name of pipe", HFILL }},
3664                 { &hf_pipe_write_raw_bytes_written,
3665                         { "Bytes Written", "pipe.write_raw.bytes_written", FT_UINT16, BASE_DEC,
3666                         NULL, 0, "Number of bytes written to the pipe", HFILL }},
3667         };
3668         static gint *ett[] = {
3669                 &ett_smb_pipe,
3670                 &ett_smb_pipe_fragments,
3671         };
3672
3673         proto_smb_pipe = proto_register_protocol(
3674                 "SMB Pipe Protocol", "SMB Pipe", "pipe");
3675
3676         proto_register_field_array(proto_smb_pipe, hf, array_length(hf));
3677         proto_register_subtree_array(ett, array_length(ett));
3678 }
3679
3680 void
3681 proto_reg_handoff_smb_pipe(void)
3682 {
3683         data_handle = find_dissector("data");
3684 }