2 * Routines for smb packet dissection
3 * Copyright 1999, Richard Sharpe <rsharpe@ns.aus.com>
5 * $Id: packet-smb-pipe.c,v 1.9 2000/05/31 05:07:41 guy Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@zing.org>
9 * Copyright 1998 Gerald Combs
11 * Copied from packet-pop.c
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 #ifdef HAVE_SYS_TYPES_H
35 # include <sys/types.h>
38 #ifdef HAVE_NETINET_IN_H
39 # include <netinet/in.h>
47 #include "conversation.h"
49 #include "alignment.h"
51 static int proto_smb_lanman = -1;
53 static gint ett_lanman = -1;
54 static gint ett_lanman_servers = -1;
55 static gint ett_lanman_server = -1;
56 static gint ett_lanman_shares = -1;
57 static gint ett_lanman_share = -1;
58 static gint ett_lanman_flags = -1;
63 * ftp://ftp.microsoft.com/developr/drg/CIFS/cifsrap2.txt
65 * among other documents.
69 * The following data structure describes the LANMAN requests we understand
71 * Simply fill in the number, name, and parameter names if you know them
72 * Try to keep them in order
74 * We will extend this data structure as we try to decode more ...
81 char **req_data; /* Hmmm, not flexible enough */
86 static char *lm_params_req_0[] = {"Detail Level", "Return Buffer Size", NULL};
87 static char *lm_params_req_1[] = {"Share Name", "Detail Level", "Receive Buffer Size", NULL};
88 static char *lm_params_resp_1[] = {"Returned Data Len", NULL};
89 static char *lm_params_req_13[] = {"Detail Level", "Receive Buffer Size", NULL};
90 static char *lm_params_req_56[] = {"User Name", "Detail Level", "Receive Buffer Size", NULL};
91 static char *lm_params_req_104[] = {"Detail Level", "Return Buffer Size", "Server Type", "Domain", NULL};
92 static char *lm_params_req_132[] = {"Reserved1", "Reserved2", "Detail Level", "UserInfoStruct?", "Length of UStruct", "Receive Buffer Size", NULL};
93 static char *lm_params_req_133[] = {"Reserved1", "Reserved2", "Detail Level", "UserInfoStruct?", "Length of UStruct", "Receive Buffer Size", NULL};
95 static char *lm_null_params[] = {NULL};
97 struct lanman_desc lmd[] = {
98 {0, "NetShareEnum", lm_params_req_0, lm_null_params, lm_null_params, lm_null_params},
99 {1, "NetShareGetInfo", lm_params_req_1, lm_null_params, lm_params_resp_1, lm_null_params},
100 {13, "NetServerGetInfo", lm_params_req_13, lm_null_params, lm_null_params, lm_null_params},
101 {52, "NetGroupGetUsers", lm_null_params, lm_null_params, lm_null_params, lm_null_params},
102 {56, "NetUserGetInfo", lm_params_req_56, lm_null_params, lm_null_params, lm_null_params},
103 {59, "NetUserGetGroups", lm_null_params, lm_null_params, lm_null_params, lm_null_params},
104 {63, "NetWkstaGetInfo", lm_null_params, lm_null_params, lm_null_params, lm_null_params},
105 {69, "DOSPrintQEnum", lm_null_params, lm_null_params, lm_null_params, lm_null_params},
106 {70, "DOSPrintQGetInfo", lm_null_params, lm_null_params, lm_null_params, lm_null_params},
107 {74, "WPrintQueuePause", lm_null_params, lm_null_params, lm_null_params, lm_null_params},
108 {75, "WPrintQueueResume", lm_null_params, lm_null_params, lm_null_params, lm_null_params},
109 {76, "WPrintJobEnumerate", lm_null_params, lm_null_params, lm_null_params, lm_null_params},
110 {77, "WPrintJobGetInfo", lm_null_params, lm_null_params, lm_null_params, lm_null_params},
111 {81, "RDOSPrintJobDel", lm_null_params, lm_null_params, lm_null_params, lm_null_params},
112 {82, "RDOSPrintJobPause", lm_null_params, lm_null_params, lm_null_params, lm_null_params},
113 {83, "RDOSPrintJobResume", lm_null_params, lm_null_params, lm_null_params, lm_null_params},
114 {84, "WPrintDestEnum", lm_null_params, lm_null_params, lm_null_params, lm_null_params},
115 {85, "WPrintDestGetInfo", lm_null_params, lm_null_params, lm_null_params, lm_null_params},
116 {91, "NetRemoteTOD", lm_null_params, lm_null_params, lm_null_params, lm_null_params},
117 {103, "WPrintQueuePurge", lm_null_params, lm_null_params, lm_null_params, lm_null_params},
118 {104, "NetServerEnum2", lm_params_req_104, lm_null_params, lm_null_params, lm_null_params},
119 {105, "WAccessGetUserPerms", lm_null_params, lm_null_params, lm_null_params, lm_null_params},
120 {115, "SetUserPassword", lm_null_params, lm_null_params, lm_null_params, lm_null_params},
121 {132, "NetWkstaUserLogon", lm_params_req_132, lm_null_params, lm_null_params, lm_null_params},
122 {133, "NetWkstaUserLogoff", lm_params_req_133, lm_null_params, lm_null_params, lm_null_params},
123 {147, "PrintJobInfo", lm_null_params, lm_null_params, lm_null_params, lm_null_params},
124 {205, "WPrintDriverEnum", lm_null_params, lm_null_params, lm_null_params, lm_null_params},
125 {206, "WPrintQProcEnum", lm_null_params, lm_null_params, lm_null_params, lm_null_params},
126 {207, "WPrintPortEnum", lm_null_params, lm_null_params, lm_null_params, lm_null_params},
127 {214, "SamOEMChangePassword", lm_null_params, lm_null_params, lm_null_params, lm_null_params},
128 {-1, NULL, NULL,NULL, NULL, NULL}
132 find_lanman(int lanman_num)
136 /* FIXME, This could be more efficient */
138 while (lmd[i].lanman_num != -1) {
140 if (lmd[i].lanman_num == lanman_num) {
155 #define NETSHAREENUM 0x00 /* 00 */
156 #define NETSERVERENUM2 0x68 /* 104 */
158 void dissect_server_flags(proto_tree *tree, int offset, int length, int flags)
160 proto_tree_add_text(tree, NullTVB, offset, length, "%s",
161 decode_boolean_bitfield(flags, 0x0001, length*8, "Workstation", "Not Workstation"));
162 proto_tree_add_text(tree, NullTVB, offset, length, "%s",
163 decode_boolean_bitfield(flags, 0x0002, length*8, "Server", "Not Server"));
164 proto_tree_add_text(tree, NullTVB, offset, length, "%s",
165 decode_boolean_bitfield(flags, 0x0004, length*8, "SQL Server", "Not SQL Server"));
166 proto_tree_add_text(tree, NullTVB, offset, length, "%s",
167 decode_boolean_bitfield(flags, 0x0008, length*8, "Domain Controller", "Not Domain Controller"));
168 proto_tree_add_text(tree, NullTVB, offset, length, "%s",
169 decode_boolean_bitfield(flags, 0x0010, length*8, "Backup Controller", "Not Backup Controller"));
170 proto_tree_add_text(tree, NullTVB, offset, 4, "%s",
171 decode_boolean_bitfield(flags, 0x0020, length*8, "Time Source", "Not Time Source"));
172 proto_tree_add_text(tree, NullTVB, offset, length, "%s",
173 decode_boolean_bitfield(flags, 0x0040, length*8, "Apple Server", "Not Apple Server"));
174 proto_tree_add_text(tree, NullTVB, offset, length, "%s",
175 decode_boolean_bitfield(flags, 0x0080, length*8, "Novell Server", "Not Novell Server"));
176 proto_tree_add_text(tree, NullTVB, offset, length, "%s",
177 decode_boolean_bitfield(flags, 0x0100, length*8, "Domain Member Server", "Not Domain Member Server"));
178 proto_tree_add_text(tree, NullTVB, offset, length, "%s",
179 decode_boolean_bitfield(flags, 0x0200, length*8, "Print Queue Server", "Not Print Queue Server"));
180 proto_tree_add_text(tree, NullTVB, offset, length, "%s",
181 decode_boolean_bitfield(flags, 0x0400, length*8, "Dialin Server", "Not Dialin Server"));
182 proto_tree_add_text(tree, NullTVB, offset, length, "%s",
183 decode_boolean_bitfield(flags, 0x0800, length*8, "Xenix Server", "Not Xenix Server"));
184 proto_tree_add_text(tree, NullTVB, offset, length, "%s",
185 decode_boolean_bitfield(flags, 0x1000, length*8, "NT Workstation", "Not NT Workstation"));
186 proto_tree_add_text(tree, NullTVB, offset, length, "%s",
187 decode_boolean_bitfield(flags, 0x2000, length*8, "Windows for Workgroups", "Not Windows for Workgroups"));
188 proto_tree_add_text(tree, NullTVB, offset, length, "%s",
189 decode_boolean_bitfield(flags, 0x8000, length*8, "NT Server", "Not NT Server"));
190 proto_tree_add_text(tree, NullTVB, offset, length, "%s",
191 decode_boolean_bitfield(flags, 0x10000, length*8, "Potential Browser", "Not Potential Browser"));
192 proto_tree_add_text(tree, NullTVB, offset, length, "%s",
193 decode_boolean_bitfield(flags, 0x20000, length*8, "Backup Browser", "Not Backup Browser"));
194 proto_tree_add_text(tree, NullTVB, offset, length, "%s",
195 decode_boolean_bitfield(flags, 0x40000, length*8, "Master Browser", "Not Master Browser"));
196 proto_tree_add_text(tree, NullTVB, offset, length, "%s",
197 decode_boolean_bitfield(flags, 0x80000, length*8, "Domain Master Browser", "Not Domain Master Browser"));
198 proto_tree_add_text(tree, NullTVB, offset, length, "%s",
199 decode_boolean_bitfield(flags, 0x100000, length*8, "OSF", "Not OSF"));
200 proto_tree_add_text(tree, NullTVB, offset, length, "%s",
201 decode_boolean_bitfield(flags, 0x200000, length*8, "VMS", "Not VMS"));
202 proto_tree_add_text(tree, NullTVB, offset, length, "%s",
203 decode_boolean_bitfield(flags, 0x400000, length*8, "Windows 95 or above", "Not Windows 95 or above"));
204 proto_tree_add_text(tree, NullTVB, offset, length, "%s",
205 decode_boolean_bitfield(flags, 0x40000000, length*8, "Local List Only", "Not Local List Only"));
206 proto_tree_add_text(tree, NullTVB, offset, length, "%s",
207 decode_boolean_bitfield(flags, 0x80000000, length*8, "Domain Enum", "Not Domain Enum"));
213 static char *p_desc = NULL, *d_desc = NULL, *data = NULL, *params = NULL;
214 static int p_count, d_count, p_offset, d_offset, d_current = 0, p_current = 0;
215 static int pd_p_current = 0, pd_d_current = 0, in_params = 0, need_data = 0;
216 static int lm_ent_count = 0, lm_act_count = 0;
218 /* Initialize the various data structure */
220 dissect_transact_engine_init(const u_char *pd, const char *param_desc, const char *data_desc, int SMB_offset, int ParameterOffset, int ParameterCount, int DataOffset, int DataCount)
224 p_count = ParameterCount;
229 lm_ent_count = lm_act_count = 0;
230 pd_d_current = DataOffset;
231 pd_p_current = ParameterOffset;
232 in_params = need_data = 0;
234 if (p_desc) g_free(p_desc);
235 p_desc = g_malloc(strlen(param_desc) + 1);
236 strcpy(p_desc, param_desc);
238 if (d_desc) g_free(d_desc);
239 d_desc= g_malloc(strlen(data_desc) + 1);
240 strcpy(d_desc, data_desc);
242 if (params) g_free(params);
243 params = g_malloc(p_count);
244 memcpy(params, pd + ParameterOffset, ParameterCount);
246 if (data) g_free(data);
247 data = g_malloc(d_count);
248 memcpy(data, pd + DataOffset, DataCount);
266 int get_byte_count(const u_char *p_data)
269 int count = 0, off = 0;
271 while (p_data[off] && isdigit(p_data[off])) {
273 count = (count * 10) + (int)p_data[off++] - (int)'0';
281 /* Dissect the next item, if Name is null, call it by its data type */
282 /* We pull out the next item in the appropriate place and display it */
283 /* We display the parameters first, then the data, then any auxilliary data */
285 int dissect_transact_next(const u_char *pd, char *Name, int dirn, proto_tree *tree)
290 const char /**Bytes,*/ *AsciiZ = NULL;
295 if (p_desc[p_offset] == 0) return 0; /* No more ... */
299 case 0: /* We are in the params area ... */
301 switch (p_desc[p_offset++]) {
305 if (dirn == 0) { /* We need to process the data ... */
313 case 'h': /* A WORD parameter received */
317 WParam = GSHORT(pd, pd_p_current);
319 proto_tree_add_text(tree, NullTVB, pd_p_current, 2, "%s: %u (%04X)", (Name) ? Name : "Returned Word", WParam, WParam);
323 lm_act_count = WParam;
331 case 'e': /* An ent count .. */
333 if (dirn == 0) { /* Only relevant in a response */
335 WParam = GSHORT(pd, pd_p_current);
337 proto_tree_add_text(tree, NullTVB, pd_p_current, 2, "%s: (%04X)", (Name) ? Name : "Entry Count", WParam);
341 lm_ent_count = WParam; /* Save this for later retrieval */
349 case 'W': /* Word Parameter */
351 if (dirn == 1) { /* A request ... */
353 /* Insert a word param */
355 WParam = GSHORT(pd, pd_p_current);
357 proto_tree_add_text(tree, NullTVB, pd_p_current, 2, "%s: %u (%04X)", (Name) ? Name : "Word Param", WParam, WParam);
361 return 1; /* That's it here ... we have dissected a param */
367 case 'i': /* A long word is returned */
371 LParam = GWORD(pd, pd_p_current);
373 proto_tree_add_text(tree, NullTVB, pd_p_current, 4, "%s: %u (0x%08X)", (Name) ? Name : "Returned Long Word", LParam, LParam);
383 case 'D': /* Double Word parameter */
387 LParam = GWORD(pd, pd_p_current);
389 proto_tree_add_text(tree, NullTVB, pd_p_current, 4, "%s: %u (0x%08X)", (Name) ? Name : "DWord Param", LParam, LParam);
393 return 1; /* That's it here */
399 case 'g': /* A byte or series of bytes is returned */
403 bc = get_byte_count(p_desc + p_offset);
405 proto_tree_add_text(tree, NullTVB, pd_p_current, bc, "%s%u: %s", (Name) ? Name : "B", (bc) ? bc : 1, format_text( pd + pd_p_current, (bc) ? bc : 1));
407 pd_p_current += (bc) ? bc : 1;
415 case 'b': /* A byte or series of bytes */
419 bc = get_byte_count(p_desc + p_offset); /* This is not clean */
421 /*Bytes = g_malloc(bc + 1); / * Is this needed ? */
423 proto_tree_add_text(tree, NullTVB, pd_p_current, bc, "%s%u: %s", (Name) ? Name : "B", (bc) ? bc : 1, format_text(pd + pd_p_current, (bc) ? bc : 1));
425 pd_p_current += (bc) ? bc : 1;
427 return 1; /* That's it here ... */
433 case 'O': /* A null pointer */
437 proto_tree_add_text(tree, NullTVB, pd_p_current, 0, "%s: Null Pointer", (Name) ? Name : "Unknown");
439 return 1; /* That's it here */
445 case 'z': /* An AsciiZ string */
449 AsciiZ = pd + pd_p_current;
451 proto_tree_add_text(tree, NullTVB, pd_p_current, strlen(AsciiZ) + 1, "%s: %s", (Name) ? Name : "AsciiZ", AsciiZ);
453 pd_p_current += strlen(AsciiZ) + 1;
455 return 1; /* That's it here ... */
461 case 'F': /* One or more pad bytes */
465 bc = get_byte_count(pd);
467 proto_tree_add_text(tree, NullTVB, pd_p_current, bc, "%s%u: %s", (Name) ? Name : "Pad", bc, format_text(pd + pd_p_current, bc));
471 return 1; /* That's it here */
477 case 'L': /* Receive buffer len: Short */
481 WParam = GSHORT(pd, pd_p_current);
483 proto_tree_add_text(tree, NullTVB, pd_p_current, 2, "%s: %u (0x%04X)", (Name) ? Name : "Receive Buffer Len", WParam, WParam);
487 return 1; /* That's it here ... */
493 case 's': /* Send buf ... */
499 LParam = GWORD(pd, pd_p_current);
501 proto_tree_add_text(tree, NullTVB, pd_p_current, 4, "%s: %u", (Name) ? Name : "Send Buffer Ptr", LParam);
505 return 1; /* That's it here ... */
515 WParam = GSHORT(pd, pd_p_current);
517 proto_tree_add_text(tree, NullTVB, pd_p_current, 2, "%s: %u", (Name) ? Name : "Send Buffer Len", WParam);
535 case 1: /* We are in the data area ... */
547 static const value_string share_type_vals[] = {
548 {0, "Directory tree"},
549 {1, "Printer queue"},
550 {2, "Communications device"},
556 dissect_pipe_lanman(const u_char *pd, int offset, frame_data *fd,
557 proto_tree *parent, proto_tree *tree, struct smb_info si,
558 int max_data, int SMB_offset, int errcode, int dirn,
559 const u_char *command, int DataOffset, int DataCount,
560 int ParameterOffset, int ParameterCount) {
563 guint32 loc_offset = SMB_offset + ParameterOffset;
564 guint16 FunctionCode;
568 const char *ParameterDescriptor;
569 const char *ReturnDescriptor;
570 proto_tree *lanman_tree = NULL, *flags_tree = NULL;
572 struct lanman_desc *lanman;
573 guint32 string_offset;
575 if (check_col(fd, COL_PROTOCOL))
576 col_add_fstr(fd, COL_PROTOCOL, "LANMAN");
578 if (dirn == 1) { /* The request side */
580 FunctionCode = GSHORT(pd, loc_offset);
582 si.request_val -> last_lanman_cmd = FunctionCode;
584 switch (FunctionCode) {
586 case NETSHAREENUM: /* Never decode this at the moment ... */
588 if (check_col(fd, COL_INFO)) {
590 col_add_fstr(fd, COL_INFO, "NetShareEnum Request");
596 ti = proto_tree_add_item(parent, proto_smb_lanman, NullTVB, SMB_offset + ParameterOffset, ParameterCount, FALSE);
597 lanman_tree = proto_item_add_subtree(ti, ett_lanman);
599 proto_tree_add_text(lanman_tree, NullTVB, loc_offset, 2, "Function Code: NetShareEnum");
605 ParameterDescriptor = pd + loc_offset;
607 si.request_val -> trans_response_seen = 0;
609 if (si.request_val -> last_param_descrip) g_free(si.request_val -> last_param_descrip);
610 si.request_val -> last_param_descrip = g_malloc(strlen(ParameterDescriptor) + 1);
611 if (si.request_val -> last_param_descrip)
612 strcpy(si.request_val -> last_param_descrip, ParameterDescriptor);
616 proto_tree_add_text(lanman_tree, NullTVB, loc_offset, strlen(ParameterDescriptor) + 1, "Parameter Descriptor: %s", ParameterDescriptor);
620 loc_offset += strlen(ParameterDescriptor) + 1;
622 ReturnDescriptor = pd + loc_offset;
624 if (si.request_val -> last_data_descrip) g_free(si.request_val -> last_data_descrip);
625 si.request_val -> last_data_descrip = g_malloc(strlen(ReturnDescriptor) + 1);
626 if (si.request_val -> last_data_descrip)
627 strcpy(si.request_val -> last_data_descrip, ReturnDescriptor);
631 proto_tree_add_text(lanman_tree, NullTVB, loc_offset, strlen(ReturnDescriptor) + 1, "Return Descriptor: %s", ReturnDescriptor);
635 loc_offset += strlen(ReturnDescriptor) + 1;
637 Level = GSHORT(pd, loc_offset);
641 proto_tree_add_text(lanman_tree, NullTVB, loc_offset, 2, "Detail Level: %u", Level);
647 RecvBufLen = GSHORT(pd, loc_offset);
651 proto_tree_add_text(lanman_tree, NullTVB, loc_offset, 2, "Receive Buffer Length: %u", RecvBufLen);
659 case NETSERVERENUM2: /* Process a NetServerEnum2 */
661 if (check_col(fd, COL_INFO)) {
663 col_add_fstr(fd, COL_INFO, "NetServerEnum2 %s", dirn ? "Request" : "Response");
669 ti = proto_tree_add_item(parent, proto_smb_lanman, NullTVB, SMB_offset + ParameterOffset, ParameterCount, FALSE);
670 lanman_tree = proto_item_add_subtree(ti, ett_lanman);
672 proto_tree_add_text(lanman_tree, NullTVB, loc_offset, 2, "Function Code: NetServerEnum2");
678 ParameterDescriptor = pd + loc_offset;
680 /* Now, save these for later */
682 si.request_val -> trans_response_seen = 0;
684 if (si.request_val -> last_param_descrip) g_free(si.request_val -> last_param_descrip);
685 si.request_val -> last_param_descrip = g_malloc(strlen(ParameterDescriptor) + 1);
686 if (si.request_val -> last_param_descrip)
687 strcpy(si.request_val -> last_param_descrip, ParameterDescriptor);
691 proto_tree_add_text(lanman_tree, NullTVB, loc_offset, strlen(ParameterDescriptor) + 1, "Parameter Descriptor: %s", ParameterDescriptor);
695 loc_offset += strlen(ParameterDescriptor) + 1;
697 ReturnDescriptor = pd + loc_offset;
699 if (si.request_val -> last_data_descrip) g_free(si.request_val -> last_data_descrip);
701 si.request_val -> last_data_descrip = g_malloc(strlen(ReturnDescriptor) + 1);
702 if (si.request_val -> last_data_descrip)
703 strcpy(si.request_val -> last_data_descrip, ReturnDescriptor);
707 proto_tree_add_text(lanman_tree, NullTVB, loc_offset, strlen(ReturnDescriptor) + 1, "Return Descriptor: %s", ReturnDescriptor);
711 loc_offset += strlen(ReturnDescriptor) + 1;
713 Level = GSHORT(pd, loc_offset);
714 si.request_val -> last_level = Level;
718 proto_tree_add_text(lanman_tree, NullTVB, loc_offset, 2, "Info Detail Level: %u", Level);
724 RecvBufLen = GSHORT(pd, loc_offset);
728 proto_tree_add_text(lanman_tree, NullTVB, loc_offset, 2, "Receive Buffer Length: %u", RecvBufLen);
734 Flags = GWORD(pd, loc_offset);
738 ti = proto_tree_add_text(lanman_tree, NullTVB, loc_offset, 4, "Server Types Required: 0x%08X", Flags);
739 flags_tree = proto_item_add_subtree(ti, ett_lanman_flags);
740 dissect_server_flags(flags_tree, loc_offset, 4, Flags);
749 default: /* Just try to handle what is there ... */
751 lanman = find_lanman(FunctionCode);
753 if (check_col(fd, COL_INFO)) {
756 col_add_fstr(fd, COL_INFO, "%s Request", lanman -> lanman_name);
759 col_add_fstr(fd, COL_INFO, "Unknown LANMAN Request: %u", FunctionCode);
765 ti = proto_tree_add_item(parent, proto_smb_lanman, NullTVB, SMB_offset + ParameterOffset, ParameterCount, FALSE);
766 lanman_tree = proto_item_add_subtree(ti, ett_lanman);
769 proto_tree_add_text(lanman_tree, NullTVB, loc_offset, 2, "%s Request", lanman -> lanman_name);
772 proto_tree_add_text(lanman_tree, NullTVB, loc_offset, 2, "Function Code: Unknown LANMAN Request: %u", FunctionCode);
779 ParameterDescriptor = pd + loc_offset;
781 si.request_val -> trans_response_seen = 0;
783 if (si.request_val -> last_param_descrip) g_free(si.request_val -> last_param_descrip);
784 si.request_val -> last_param_descrip = g_malloc(strlen(ParameterDescriptor) + 1);
785 if (si.request_val -> last_param_descrip)
786 strcpy(si.request_val -> last_param_descrip, ParameterDescriptor);
790 proto_tree_add_text(lanman_tree, NullTVB, loc_offset, strlen(ParameterDescriptor) + 1, "Parameter Descriptor: %s", ParameterDescriptor);
794 loc_offset += strlen(ParameterDescriptor) + 1;
796 ReturnDescriptor = pd + loc_offset;
798 if (si.request_val -> last_data_descrip) g_free(si.request_val -> last_data_descrip);
799 si.request_val -> last_data_descrip = g_malloc(strlen(ReturnDescriptor) + 1);
800 if (si.request_val -> last_data_descrip)
801 strcpy(si.request_val -> last_data_descrip, ReturnDescriptor);
805 proto_tree_add_text(lanman_tree, NullTVB, loc_offset, strlen(ReturnDescriptor) + 1, "Return Descriptor: %s", ReturnDescriptor);
809 loc_offset += strlen(ReturnDescriptor) + 1;
813 int i = 0; /* Counter for names below */
816 dissect_transact_engine_init(pd, ParameterDescriptor, ReturnDescriptor,SMB_offset, loc_offset, ParameterCount, DataOffset, DataCount);
818 if (lanman) name = lanman -> req[i]; /* Must be OK ... */
820 while (dissect_transact_next(pd, name, dirn, lanman_tree))
821 if (name) name = lanman -> req[++i];
828 else { /* Dirn == 0, response */
833 guint32 loc_offset = 0;
835 proto_tree *server_tree = NULL, *flags_tree = NULL, *share_tree = NULL;
837 FunctionCode = si.request_val -> last_lanman_cmd;
840 * If we have already seen the response to this transact, simply
841 * record it as a continuation ...
844 /*$$ printf("TransResponseSeen = %u\n", si.request_val -> trans_response_seen);
846 if (si.request_val -> trans_response_seen == 1) {
848 if (check_col(fd, COL_INFO)) {
849 col_add_fstr(fd, COL_INFO, "Transact Continuation");
854 ti = proto_tree_add_item(parent, proto_smb_lanman, NullTVB, SMB_offset + DataOffset, END_OF_FRAME, FALSE);
856 lanman_tree = proto_item_add_subtree(ti, ett_lanman);
858 proto_tree_add_text(lanman_tree, NullTVB, loc_offset, END_OF_FRAME, "Payload: %s", format_text(pd + SMB_offset + DataOffset, END_OF_FRAME));
867 si.request_val -> trans_response_seen = 1;
869 switch (FunctionCode) {
873 if (check_col(fd, COL_INFO)) {
875 col_add_fstr(fd, COL_INFO, "NetShareEnum Response");
881 ti = proto_tree_add_item(parent, proto_smb_lanman, NullTVB, SMB_offset + ParameterOffset, END_OF_FRAME, FALSE);
882 lanman_tree = proto_item_add_subtree(ti, ett_lanman);
884 proto_tree_add_text(lanman_tree, NullTVB, loc_offset, 0, "Function Code: NetShareEnum");
888 si.request_val -> trans_response_seen = 1;
890 loc_offset = SMB_offset + ParameterOffset;
892 Status = GSHORT(pd, loc_offset);
896 proto_tree_add_text(lanman_tree, NullTVB, loc_offset, 2, "Status: %u", Status);
902 Convert = GSHORT(pd, loc_offset);
906 proto_tree_add_text(lanman_tree, NullTVB, loc_offset, 2, "Convert: %u", Convert);
912 EntCount = GSHORT(pd, loc_offset);
916 proto_tree_add_text(lanman_tree, NullTVB, loc_offset, 2, "Entry Count: %u", EntCount);
922 AvailCount = GSHORT(pd, loc_offset);
926 proto_tree_add_text(lanman_tree, NullTVB, loc_offset, 2, "Available Entries: %u", AvailCount);
934 ti = proto_tree_add_text(lanman_tree, NullTVB, loc_offset, AvailCount * 20, "Available Shares");
936 share_tree = proto_item_add_subtree(ti, ett_lanman_shares);
940 for (i = 1; i <= EntCount; i++) {
941 const gchar *Share = pd + loc_offset;
943 const gchar *Comment;
944 proto_tree *share = NULL;
945 proto_item *ti = NULL;
949 ti = proto_tree_add_text(share_tree, NullTVB, loc_offset, 20, "Share %s", Share);
950 share = proto_item_add_subtree(ti, ett_lanman_share);
957 proto_tree_add_text(share, NullTVB, loc_offset, 13, "Share Name: %s", Share);
963 loc_offset += 1; /* Pad byte ... */
965 Flags = GSHORT(pd, loc_offset);
969 proto_tree_add_text(share, NullTVB, loc_offset, 2, "Share Type: %s",
970 val_to_str(Flags, share_type_vals, "Unknown (%u)"));
976 /* XXX - should check whether all of the string is within the
978 string_offset = SMB_offset + DataOffset + (GWORD(pd, loc_offset) & 0xFFFF) - Convert;
979 if (IS_DATA_IN_FRAME(string_offset))
980 Comment = pd + string_offset;
982 Comment = "<String goes past end of frame>";
986 proto_tree_add_text(share, NullTVB, loc_offset, 4, "Share Comment: %s", Comment);
998 if (check_col(fd, COL_INFO)) {
1000 col_add_fstr(fd, COL_INFO, "NetServerEnum2 %s", dirn ? "Request" : "Response");
1006 ti = proto_tree_add_item(parent, proto_smb_lanman, NullTVB, SMB_offset + ParameterOffset, END_OF_FRAME, FALSE);
1007 lanman_tree = proto_item_add_subtree(ti, ett_lanman);
1009 proto_tree_add_text(lanman_tree, NullTVB, loc_offset, 2, "Function Code: NetServerEnum2");
1013 loc_offset = SMB_offset + ParameterOffset;
1014 Status = GSHORT(pd, loc_offset);
1018 proto_tree_add_text(lanman_tree, NullTVB, loc_offset, 2, "Status: %u", Status);
1024 Convert = GSHORT(pd, loc_offset);
1028 proto_tree_add_text(lanman_tree, NullTVB, loc_offset, 2, "Convert: %u", Convert);
1034 EntCount = GSHORT(pd, loc_offset);
1038 proto_tree_add_text(lanman_tree, NullTVB, loc_offset, 2, "Entry Count: %u", EntCount);
1044 AvailCount = GSHORT(pd, loc_offset);
1048 proto_tree_add_text(lanman_tree, NullTVB, loc_offset, 2, "Available Entries: %u", AvailCount);
1056 ti = proto_tree_add_text(lanman_tree, NullTVB, loc_offset, 26 * AvailCount, "Servers");
1059 printf("Null value returned from proto_tree_add_text\n");
1064 server_tree = proto_item_add_subtree(ti, ett_lanman_servers);
1068 /* Make sure we don't go past the end of the capture buffer */
1070 for (i = 1; (i <= EntCount) && ((pi.captured_len - loc_offset) > 16); i++) {
1071 const gchar *Server = pd + loc_offset;
1074 guint32 ServerFlags;
1075 const gchar *Comment;
1076 proto_tree *server = NULL;
1081 ti = proto_tree_add_text(server_tree, NullTVB, loc_offset,
1082 (si.request_val -> last_level) ? 26 : 16,
1083 "Server %s", Server);
1084 server = proto_item_add_subtree(ti, ett_lanman_server);
1091 proto_tree_add_text(server, NullTVB, loc_offset, 16, "Server Name: %s", Server);
1097 if (si.request_val -> last_level) { /* Print out the rest of the info */
1099 ServerMajor = GBYTE(pd, loc_offset);
1103 proto_tree_add_text(server, NullTVB, loc_offset, 1, "Major Version: %u", ServerMajor);
1109 ServerMinor = GBYTE(pd, loc_offset);
1113 proto_tree_add_text(server, NullTVB, loc_offset, 1, "Minor Version: %u", ServerMinor);
1119 ServerFlags = GWORD(pd, loc_offset);
1123 ti = proto_tree_add_text(server, NullTVB, loc_offset, 4, "Server Type: 0x%08X", ServerFlags);
1124 flags_tree = proto_item_add_subtree(ti, ett_lanman_flags);
1125 dissect_server_flags(flags_tree, loc_offset, 4, ServerFlags);
1131 /* XXX - should check whether all of the string is within the
1133 string_offset = SMB_offset + DataOffset + (GWORD(pd, loc_offset) & 0xFFFF) - Convert;
1134 if (IS_DATA_IN_FRAME(string_offset))
1135 Comment = pd + string_offset;
1137 Comment = "<String goes past end of frame>";
1141 proto_tree_add_text(server, NullTVB, loc_offset, 4, "Server Comment: %s", Comment);
1155 lanman = find_lanman(si.request_val -> last_lanman_cmd);
1157 if (check_col(fd, COL_INFO)) {
1160 col_add_fstr(fd, COL_INFO, "%s Response", lanman -> lanman_name);
1163 col_add_fstr(fd, COL_INFO, "Unknown LANMAN Response: %u", FunctionCode);
1169 ti = proto_tree_add_item(parent, proto_smb_lanman, NullTVB, SMB_offset + ParameterOffset, END_OF_FRAME, FALSE);
1170 lanman_tree = proto_item_add_subtree(ti, ett_lanman);
1172 proto_tree_add_text(lanman_tree, NullTVB, 0, 0, "%s Response", lanman -> lanman_name);
1175 proto_tree_add_text(lanman_tree, NullTVB, loc_offset, 0, "Function Code: Unknown LANMAN Response: %u", FunctionCode);
1179 loc_offset = SMB_offset + ParameterOffset;
1181 Status = GSHORT(pd, loc_offset);
1185 proto_tree_add_text(lanman_tree, NullTVB, loc_offset, 2, "Status: %u", Status);
1191 Convert = GSHORT(pd, loc_offset);
1195 proto_tree_add_text(lanman_tree, NullTVB, loc_offset, 2, "Convert: %u", Convert);
1206 dissect_transact_engine_init(pd, si.request_val -> last_param_descrip, si.request_val -> last_data_descrip, SMB_offset, loc_offset, ParameterCount, DataOffset, DataCount);
1208 if (lanman) name = lanman -> resp[i];
1210 while (dissect_transact_next(pd, name, dirn, lanman_tree))
1211 if (name) name = lanman -> resp[++i];
1227 dissect_pipe_smb(const u_char *pd, int offset, frame_data *fd, proto_tree *parent, proto_tree *tree, struct smb_info si, int max_data, int SMB_offset, int errcode, int dirn, const u_char *command, int DataOffset, int DataCount, int ParameterOffset, int ParameterCount)
1230 if (strcmp(command, "LANMAN") == 0) { /* Try to decode a LANMAN */
1232 return dissect_pipe_lanman(pd, offset, fd, parent, tree, si, max_data, SMB_offset, errcode, dirn, command, DataOffset, DataCount, ParameterOffset, ParameterCount);
1244 register_proto_smb_pipe( void){
1247 static gint *ett[] = {
1250 &ett_lanman_servers,
1258 proto_smb_lanman = proto_register_protocol(
1259 "Microsoft Windows Lanman Protocol", "lanman");
1261 proto_register_subtree_array(ett, array_length(ett));