1 /* packet-smb-mailslot.c
2 * Routines for SMB mailslot packet dissection
3 * Copyright 2000, Jeffrey C. Foster <jfoste@woodward.com>
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.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.
36 #include <epan/packet.h>
37 #include <epan/emem.h>
38 #include <epan/dissectors/packet-smb.h>
39 #include "packet-smb-mailslot.h"
40 #include "packet-smb-browse.h"
41 #include "packet-smb-pipe.h"
43 static int proto_smb_msp = -1;
44 static int hf_opcode = -1;
45 static int hf_priority = -1;
46 static int hf_class = -1;
47 static int hf_size = -1;
48 static int hf_name = -1;
50 static int ett_smb_msp = -1;
52 static dissector_handle_t mailslot_browse_handle;
53 static dissector_handle_t mailslot_lanman_handle;
54 static dissector_handle_t netlogon_handle;
55 static dissector_handle_t data_handle;
57 #define MAILSLOT_UNKNOWN 0
58 #define MAILSLOT_BROWSE 1
59 #define MAILSLOT_LANMAN 2
60 #define MAILSLOT_NET 3
61 #define MAILSLOT_TEMP_NETLOGON 4
62 #define MAILSLOT_MSSP 5
64 static const value_string opcode_vals[] = {
65 {1, "Write Mail Slot"},
69 static const value_string class_vals[] = {
71 {2, "Unreliable & Broadcast"},
75 /* decode the SMB mail slot protocol
77 mailslot is the name of the mailslot, e.g. BROWSE
78 si->trans_subcmd is set to the symbolic constant matching the mailslot name.
81 si->trans_subcmd gives us which mailslot this response refers to.
85 dissect_mailslot_smb(tvbuff_t *mshdr_tvb, tvbuff_t *setup_tvb,
86 tvbuff_t *tvb, const char *mailslot, packet_info *pinfo,
87 proto_tree *parent_tree)
90 smb_transact_info_t *tri;
92 proto_tree *tree = NULL;
93 proto_item *item = NULL;
98 if (!proto_is_protocol_enabled(find_protocol_by_id(proto_smb_msp))) {
101 pinfo->current_proto = "SMB Mailslot";
103 if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
104 col_set_str(pinfo->cinfo, COL_PROTOCOL, "SMB Mailslot");
107 if ((tvb==NULL) || (tvb_reported_length(tvb)==0)) {
109 if (check_col (pinfo->cinfo, COL_INFO)) {
110 col_set_str(pinfo->cinfo, COL_INFO, "Interim reply");
115 if (check_col(pinfo->cinfo, COL_INFO)) {
116 col_clear(pinfo->cinfo, COL_INFO);
119 smb_info = pinfo->private_data;
120 if (smb_info->sip != NULL && smb_info->sip->extra_info_type == SMB_EI_TRI)
121 tri = smb_info->sip->extra_info;
125 /* check which mailslot this is about */
126 trans_subcmd=MAILSLOT_UNKNOWN;
127 if(smb_info->request){
128 if(strncmp(mailslot,"BROWSE",6) == 0){
129 trans_subcmd=MAILSLOT_BROWSE;
130 } else if(strncmp(mailslot,"LANMAN",6) == 0){
131 trans_subcmd=MAILSLOT_LANMAN;
132 } else if(strncmp(mailslot,"NET",3) == 0){
133 trans_subcmd=MAILSLOT_NET;
134 } else if(strncmp(mailslot,"TEMP\\NETLOGON",13) == 0){
135 trans_subcmd=MAILSLOT_TEMP_NETLOGON;
136 } else if(strncmp(mailslot,"MSSP",4) == 0){
137 trans_subcmd=MAILSLOT_MSSP;
139 if (!pinfo->fd->flags.visited) {
141 tri->trans_subcmd = trans_subcmd;
147 trans_subcmd = tri->trans_subcmd;
151 /* Only do these ones if we have them. For fragmented SMB Transactions
152 we may only have the setup area for the first fragment
154 if(mshdr_tvb && setup_tvb){
156 item = proto_tree_add_item(parent_tree, proto_smb_msp,
157 mshdr_tvb, 0, -1, FALSE);
158 tree = proto_item_add_subtree(item, ett_smb_msp);
161 /* do the opcode field */
162 opcode = tvb_get_letohs(setup_tvb, offset);
164 if (check_col(pinfo->cinfo, COL_INFO)) {
165 col_add_str(pinfo->cinfo, COL_INFO,
166 val_to_str(opcode, opcode_vals, "Unknown opcode: 0x%04x"));
170 /* These are in the setup words; use "setup_tvb". */
173 proto_tree_add_uint(tree, hf_opcode, setup_tvb, offset, 2,
178 proto_tree_add_item(tree, hf_priority, setup_tvb, offset, 2,
183 proto_tree_add_item(tree, hf_class, setup_tvb, offset, 2, TRUE);
186 /* These are in the rest of the data; use "mshdr_tvb", which
187 starts at the same place "setup_tvb" does. */
190 /* this is actually bytecount in the SMB Transaction command */
191 proto_tree_add_item(tree, hf_size, mshdr_tvb, offset, 2, TRUE);
195 len = tvb_strsize(mshdr_tvb, offset);
196 proto_tree_add_item(tree, hf_name, mshdr_tvb, offset, len, TRUE);
198 proto_item_set_len(item, offset);
201 switch(trans_subcmd){
202 case MAILSLOT_BROWSE:
203 call_dissector(mailslot_browse_handle, tvb, pinfo,
207 case MAILSLOT_LANMAN:
208 call_dissector(mailslot_lanman_handle, tvb, pinfo,
213 case MAILSLOT_TEMP_NETLOGON:
215 call_dissector(netlogon_handle, tvb, pinfo,
221 * We dissected the mailslot header, but we don't know
222 * how to dissect the message; dissect the latter as data,
223 * but indicate that we successfully dissected the mailslot
226 call_dissector(data_handle ,tvb, pinfo, parent_tree);
233 proto_register_smb_mailslot(void)
235 static hf_register_info hf[] = {
237 { "Opcode", "mailslot.opcode", FT_UINT16, BASE_DEC,
238 VALS(opcode_vals), 0, "MAILSLOT OpCode", HFILL }},
241 { "Priority", "mailslot.priority", FT_UINT16, BASE_DEC,
242 NULL, 0, "MAILSLOT Priority of transaction", HFILL }},
245 { "Class", "mailslot.class", FT_UINT16, BASE_DEC,
246 VALS(class_vals), 0, "MAILSLOT Class of transaction", HFILL }},
249 { "Size", "mailslot.size", FT_UINT16, BASE_DEC,
250 NULL, 0, "MAILSLOT Total size of mail data", HFILL }},
253 { "Mailslot Name", "mailslot.name", FT_STRING, BASE_NONE,
254 NULL, 0, "MAILSLOT Name of mailslot", HFILL }},
258 static gint *ett[] = {
262 proto_smb_msp = proto_register_protocol(
263 "SMB MailSlot Protocol", "SMB Mailslot", "mailslot");
265 proto_register_field_array(proto_smb_msp, hf, array_length(hf));
266 proto_register_subtree_array(ett, array_length(ett));
270 proto_reg_handoff_smb_mailslot(void)
272 mailslot_browse_handle = find_dissector("mailslot_browse");
273 mailslot_lanman_handle = find_dissector("mailslot_lanman");
274 netlogon_handle = find_dissector("smb_netlogon");
275 data_handle = find_dissector("data");