1 /* packet-smb-mailslot.c
2 * Routines for SMB mailslot packet dissection
3 * Copyright 2000, Jeffrey C. Foster <jfoste@woodward.com>
5 * $Id: packet-smb-mailslot.c,v 1.35 2003/11/19 03:53:33 guy Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@ethereal.com>
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.
29 #include "packet-smb-common.h"
30 #include "packet-smb-mailslot.h"
31 #include "packet-smb-browse.h"
32 #include "packet-smb-pipe.h"
34 static int proto_smb_msp = -1;
35 static int hf_opcode = -1;
36 static int hf_priority = -1;
37 static int hf_class = -1;
38 static int hf_size = -1;
39 static int hf_name = -1;
41 static int ett_smb_msp = -1;
43 static dissector_handle_t mailslot_browse_handle;
44 static dissector_handle_t mailslot_lanman_handle;
45 static dissector_handle_t netlogon_handle;
46 static dissector_handle_t data_handle;
48 #define MAILSLOT_UNKNOWN 0
49 #define MAILSLOT_BROWSE 1
50 #define MAILSLOT_LANMAN 2
51 #define MAILSLOT_NET 3
52 #define MAILSLOT_TEMP_NETLOGON 4
53 #define MAILSLOT_MSSP 5
55 static const value_string opcode_vals[] = {
56 {1, "Write Mail Slot"},
60 static const value_string class_vals[] = {
62 {2, "Unreliable & Broadcast"},
66 /* decode the SMB mail slot protocol
68 mailslot is the name of the mailslot, e.g. BROWSE
69 si->trans_subcmd is set to the symbolic constant matching the mailslot name.
72 si->trans_subcmd gives us which mailslot this response refers to.
76 dissect_mailslot_smb(tvbuff_t *mshdr_tvb, tvbuff_t *setup_tvb,
77 tvbuff_t *tvb, const char *mailslot, packet_info *pinfo,
78 proto_tree *parent_tree)
81 smb_transact_info_t *tri;
83 proto_tree *tree = NULL;
84 proto_item *item = NULL;
89 if (!proto_is_protocol_enabled(find_protocol_by_id(proto_smb_msp))) {
92 pinfo->current_proto = "SMB Mailslot";
94 if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
95 col_set_str(pinfo->cinfo, COL_PROTOCOL, "SMB Mailslot");
98 if ((tvb==NULL) || (tvb_reported_length(tvb)==0)) {
100 col_set_str(pinfo->cinfo, COL_INFO, "Interim reply");
104 if (check_col(pinfo->cinfo, COL_INFO)) {
105 col_clear(pinfo->cinfo, COL_INFO);
108 smb_info = pinfo->private_data;
109 if (smb_info->sip != NULL)
110 tri = smb_info->sip->extra_info;
114 /* check which mailslot this is about */
115 trans_subcmd=MAILSLOT_UNKNOWN;
116 if(smb_info->request){
117 if(strncmp(mailslot,"BROWSE",6) == 0){
118 trans_subcmd=MAILSLOT_BROWSE;
119 } else if(strncmp(mailslot,"LANMAN",6) == 0){
120 trans_subcmd=MAILSLOT_LANMAN;
121 } else if(strncmp(mailslot,"NET",3) == 0){
122 trans_subcmd=MAILSLOT_NET;
123 } else if(strncmp(mailslot,"TEMP\\NETLOGON",13) == 0){
124 trans_subcmd=MAILSLOT_TEMP_NETLOGON;
125 } else if(strncmp(mailslot,"MSSP",4) == 0){
126 trans_subcmd=MAILSLOT_MSSP;
128 if (!pinfo->fd->flags.visited) {
130 tri->trans_subcmd = trans_subcmd;
133 trans_subcmd = tri->trans_subcmd;
136 /* Only do these ones if we have them. For fragmented SMB Transactions
137 we may only have the setup area for the first fragment
139 if(mshdr_tvb && setup_tvb){
141 item = proto_tree_add_item(parent_tree, proto_smb_msp,
142 mshdr_tvb, 0, -1, FALSE);
143 tree = proto_item_add_subtree(item, ett_smb_msp);
146 /* do the opcode field */
147 opcode = tvb_get_letohs(setup_tvb, offset);
149 if (check_col(pinfo->cinfo, COL_INFO)) {
150 col_add_str(pinfo->cinfo, COL_INFO,
151 val_to_str(opcode, opcode_vals, "Unknown opcode: 0x%04x"));
155 /* These are in the setup words; use "setup_tvb". */
158 proto_tree_add_uint(tree, hf_opcode, setup_tvb, offset, 2,
163 proto_tree_add_item(tree, hf_priority, setup_tvb, offset, 2,
168 proto_tree_add_item(tree, hf_class, setup_tvb, offset, 2, TRUE);
171 /* These are in the rest of the data; use "mshdr_tvb", which
172 starts at the same place "setup_tvb" does. */
175 /* this is actually bytecount in the SMB Transaction command */
176 proto_tree_add_item(tree, hf_size, mshdr_tvb, offset, 2, TRUE);
180 len = tvb_strsize(mshdr_tvb, offset);
181 proto_tree_add_item(tree, hf_name, mshdr_tvb, offset, len, TRUE);
183 proto_item_set_len(item, offset);
186 switch(trans_subcmd){
187 case MAILSLOT_BROWSE:
188 call_dissector(mailslot_browse_handle, tvb, pinfo,
192 case MAILSLOT_LANMAN:
193 call_dissector(mailslot_lanman_handle, tvb, pinfo,
198 case MAILSLOT_TEMP_NETLOGON:
200 call_dissector(netlogon_handle, tvb, pinfo,
206 * We dissected the mailslot header, but we don't know
207 * how to dissect the message; dissect the latter as data,
208 * but indicate that we successfully dissected the mailslot
211 call_dissector(data_handle,tvb, pinfo, parent_tree);
218 proto_register_smb_mailslot(void)
220 static hf_register_info hf[] = {
222 { "Opcode", "mailslot.opcode", FT_UINT16, BASE_DEC,
223 VALS(opcode_vals), 0, "MAILSLOT OpCode", HFILL }},
226 { "Priority", "mailslot.priority", FT_UINT16, BASE_DEC,
227 NULL, 0, "MAILSLOT Priority of transaction", HFILL }},
230 { "Class", "mailslot.class", FT_UINT16, BASE_DEC,
231 VALS(class_vals), 0, "MAILSLOT Class of transaction", HFILL }},
234 { "Size", "mailslot.size", FT_UINT16, BASE_DEC,
235 NULL, 0, "MAILSLOT Total size of mail data", HFILL }},
238 { "Mailslot Name", "mailslot.name", FT_STRING, BASE_NONE,
239 NULL, 0, "MAILSLOT Name of mailslot", HFILL }},
243 static gint *ett[] = {
247 proto_smb_msp = proto_register_protocol(
248 "SMB MailSlot Protocol", "SMB Mailslot", "mailslot");
250 proto_register_field_array(proto_smb_msp, hf, array_length(hf));
251 proto_register_subtree_array(ett, array_length(ett));
255 proto_reg_handoff_smb_mailslot(void)
257 mailslot_browse_handle = find_dissector("mailslot_browse");
258 mailslot_lanman_handle = find_dissector("mailslot_lanman");
259 netlogon_handle = find_dissector("netlogon");
260 data_handle = find_dissector("data");