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/dissectors/packet-smb.h>
38 #include "packet-smb-mailslot.h"
39 #include "packet-smb-browse.h"
40 #include "packet-smb-pipe.h"
42 static int proto_smb_msp = -1;
43 static int hf_opcode = -1;
44 static int hf_priority = -1;
45 static int hf_class = -1;
46 static int hf_size = -1;
47 static int hf_name = -1;
49 static int ett_smb_msp = -1;
51 static dissector_handle_t mailslot_browse_handle;
52 static dissector_handle_t mailslot_lanman_handle;
53 static dissector_handle_t netlogon_handle;
54 static dissector_handle_t data_handle;
56 #define MAILSLOT_UNKNOWN 0
57 #define MAILSLOT_BROWSE 1
58 #define MAILSLOT_LANMAN 2
59 #define MAILSLOT_NET 3
60 #define MAILSLOT_TEMP_NETLOGON 4
61 #define MAILSLOT_MSSP 5
63 static const value_string opcode_vals[] = {
64 {1, "Write Mail Slot"},
68 static const value_string class_vals[] = {
70 {2, "Unreliable & Broadcast"},
74 /* decode the SMB mail slot protocol
76 mailslot is the name of the mailslot, e.g. BROWSE
77 si->trans_subcmd is set to the symbolic constant matching the mailslot name.
80 si->trans_subcmd gives us which mailslot this response refers to.
84 dissect_mailslot_smb(tvbuff_t *mshdr_tvb, tvbuff_t *setup_tvb,
85 tvbuff_t *tvb, const char *mailslot, packet_info *pinfo,
86 proto_tree *parent_tree)
89 smb_transact_info_t *tri;
91 proto_tree *tree = NULL;
92 proto_item *item = NULL;
97 if (!proto_is_protocol_enabled(find_protocol_by_id(proto_smb_msp))) {
100 pinfo->current_proto = "SMB Mailslot";
102 if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
103 col_set_str(pinfo->cinfo, COL_PROTOCOL, "SMB Mailslot");
106 if ((tvb==NULL) || (tvb_reported_length(tvb)==0)) {
108 if (check_col (pinfo->cinfo, COL_INFO)) {
109 col_set_str(pinfo->cinfo, COL_INFO, "Interim reply");
114 if (check_col(pinfo->cinfo, COL_INFO)) {
115 col_clear(pinfo->cinfo, COL_INFO);
118 smb_info = pinfo->private_data;
119 if (smb_info->sip != NULL && smb_info->sip->extra_info_type == SMB_EI_TRI)
120 tri = smb_info->sip->extra_info;
124 /* check which mailslot this is about */
125 trans_subcmd=MAILSLOT_UNKNOWN;
126 if(smb_info->request){
127 if(strncmp(mailslot,"BROWSE",6) == 0){
128 trans_subcmd=MAILSLOT_BROWSE;
129 } else if(strncmp(mailslot,"LANMAN",6) == 0){
130 trans_subcmd=MAILSLOT_LANMAN;
131 } else if(strncmp(mailslot,"NET",3) == 0){
132 trans_subcmd=MAILSLOT_NET;
133 } else if(strncmp(mailslot,"TEMP\\NETLOGON",13) == 0){
134 trans_subcmd=MAILSLOT_TEMP_NETLOGON;
135 } else if(strncmp(mailslot,"MSSP",4) == 0){
136 trans_subcmd=MAILSLOT_MSSP;
138 if (!pinfo->fd->flags.visited) {
140 tri->trans_subcmd = trans_subcmd;
146 trans_subcmd = tri->trans_subcmd;
150 /* Only do these ones if we have them. For fragmented SMB Transactions
151 we may only have the setup area for the first fragment
153 if(mshdr_tvb && setup_tvb){
155 item = proto_tree_add_item(parent_tree, proto_smb_msp,
156 mshdr_tvb, 0, -1, FALSE);
157 tree = proto_item_add_subtree(item, ett_smb_msp);
160 /* do the opcode field */
161 opcode = tvb_get_letohs(setup_tvb, offset);
163 if (check_col(pinfo->cinfo, COL_INFO)) {
164 col_add_str(pinfo->cinfo, COL_INFO,
165 val_to_str(opcode, opcode_vals, "Unknown opcode: 0x%04x"));
169 /* These are in the setup words; use "setup_tvb". */
172 proto_tree_add_uint(tree, hf_opcode, setup_tvb, offset, 2,
177 proto_tree_add_item(tree, hf_priority, setup_tvb, offset, 2,
182 proto_tree_add_item(tree, hf_class, setup_tvb, offset, 2, TRUE);
185 /* These are in the rest of the data; use "mshdr_tvb", which
186 starts at the same place "setup_tvb" does. */
189 /* this is actually bytecount in the SMB Transaction command */
190 proto_tree_add_item(tree, hf_size, mshdr_tvb, offset, 2, TRUE);
194 len = tvb_strsize(mshdr_tvb, offset);
195 proto_tree_add_item(tree, hf_name, mshdr_tvb, offset, len, TRUE);
197 proto_item_set_len(item, offset);
200 switch(trans_subcmd){
201 case MAILSLOT_BROWSE:
202 call_dissector(mailslot_browse_handle, tvb, pinfo,
206 case MAILSLOT_LANMAN:
207 call_dissector(mailslot_lanman_handle, tvb, pinfo,
212 case MAILSLOT_TEMP_NETLOGON:
214 call_dissector(netlogon_handle, tvb, pinfo,
220 * We dissected the mailslot header, but we don't know
221 * how to dissect the message; dissect the latter as data,
222 * but indicate that we successfully dissected the mailslot
225 call_dissector(data_handle ,tvb, pinfo, parent_tree);
232 proto_register_smb_mailslot(void)
234 static hf_register_info hf[] = {
236 { "Opcode", "mailslot.opcode", FT_UINT16, BASE_DEC,
237 VALS(opcode_vals), 0, "MAILSLOT OpCode", HFILL }},
240 { "Priority", "mailslot.priority", FT_UINT16, BASE_DEC,
241 NULL, 0, "MAILSLOT Priority of transaction", HFILL }},
244 { "Class", "mailslot.class", FT_UINT16, BASE_DEC,
245 VALS(class_vals), 0, "MAILSLOT Class of transaction", HFILL }},
248 { "Size", "mailslot.size", FT_UINT16, BASE_DEC,
249 NULL, 0, "MAILSLOT Total size of mail data", HFILL }},
252 { "Mailslot Name", "mailslot.name", FT_STRING, BASE_NONE,
253 NULL, 0, "MAILSLOT Name of mailslot", HFILL }},
257 static gint *ett[] = {
261 proto_smb_msp = proto_register_protocol(
262 "SMB MailSlot Protocol", "SMB Mailslot", "mailslot");
264 proto_register_field_array(proto_smb_msp, hf, array_length(hf));
265 proto_register_subtree_array(ett, array_length(ett));
269 proto_reg_handoff_smb_mailslot(void)
271 mailslot_browse_handle = find_dissector("mailslot_browse");
272 mailslot_lanman_handle = find_dissector("mailslot_lanman");
273 netlogon_handle = find_dissector("smb_netlogon");
274 data_handle = find_dissector("data");