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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
34 #include <epan/packet.h>
35 #include <epan/dissectors/packet-smb.h>
36 #include "packet-smb-mailslot.h"
37 #include "packet-smb-browse.h"
38 #include "packet-smb-pipe.h"
40 static int proto_smb_msp
= -1;
41 static int hf_opcode
= -1;
42 static int hf_priority
= -1;
43 static int hf_class
= -1;
44 static int hf_size
= -1;
45 static int hf_name
= -1;
47 static int ett_smb_msp
= -1;
49 static dissector_handle_t mailslot_browse_handle
;
50 static dissector_handle_t mailslot_lanman_handle
;
51 static dissector_handle_t netlogon_handle
;
52 static dissector_handle_t data_handle
;
54 #define MAILSLOT_UNKNOWN 0
55 #define MAILSLOT_BROWSE 1
56 #define MAILSLOT_LANMAN 2
57 #define MAILSLOT_NET 3
58 #define MAILSLOT_TEMP_NETLOGON 4
59 #define MAILSLOT_MSSP 5
61 static const value_string opcode_vals
[] = {
62 {1, "Write Mail Slot"},
66 static const value_string class_vals
[] = {
68 {2, "Unreliable & Broadcast"},
72 /* decode the SMB mail slot protocol
74 mailslot is the name of the mailslot, e.g. BROWSE
75 si->trans_subcmd is set to the symbolic constant matching the mailslot name.
78 si->trans_subcmd gives us which mailslot this response refers to.
82 dissect_mailslot_smb(tvbuff_t
*mshdr_tvb
, tvbuff_t
*setup_tvb
,
83 tvbuff_t
*tvb
, const char *mailslot
, packet_info
*pinfo
,
84 proto_tree
*parent_tree
, smb_info_t
* smb_info
)
86 smb_transact_info_t
*tri
;
88 proto_tree
*tree
= NULL
;
89 proto_item
*item
= NULL
;
94 if (!proto_is_protocol_enabled(find_protocol_by_id(proto_smb_msp
))) {
97 pinfo
->current_proto
= "SMB Mailslot";
99 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "SMB Mailslot");
101 if ((tvb
==NULL
) || (tvb_reported_length(tvb
)==0)) {
103 col_set_str(pinfo
->cinfo
, COL_INFO
, "Interim reply");
107 col_clear(pinfo
->cinfo
, COL_INFO
);
109 if (smb_info
->sip
!= NULL
&& smb_info
->sip
->extra_info_type
== SMB_EI_TRI
)
110 tri
= (smb_transact_info_t
*)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
;
136 trans_subcmd
= tri
->trans_subcmd
;
140 /* Only do these ones if we have them. For fragmented SMB Transactions
141 we may only have the setup area for the first fragment
143 if(mshdr_tvb
&& setup_tvb
){
145 item
= proto_tree_add_item(parent_tree
, proto_smb_msp
,
146 mshdr_tvb
, 0, -1, ENC_NA
);
147 tree
= proto_item_add_subtree(item
, ett_smb_msp
);
150 /* do the opcode field */
151 opcode
= tvb_get_letohs(setup_tvb
, offset
);
153 col_add_str(pinfo
->cinfo
, COL_INFO
,
154 val_to_str(opcode
, opcode_vals
, "Unknown opcode: 0x%04x"));
157 /* These are in the setup words; use "setup_tvb". */
160 proto_tree_add_uint(tree
, hf_opcode
, setup_tvb
, offset
, 2,
165 proto_tree_add_item(tree
, hf_priority
, setup_tvb
, offset
, 2,
170 proto_tree_add_item(tree
, hf_class
, setup_tvb
, offset
, 2, ENC_LITTLE_ENDIAN
);
173 /* These are in the rest of the data; use "mshdr_tvb", which
174 starts at the same place "setup_tvb" does. */
177 /* this is actually bytecount in the SMB Transaction command */
178 proto_tree_add_item(tree
, hf_size
, mshdr_tvb
, offset
, 2, ENC_LITTLE_ENDIAN
);
182 len
= tvb_strsize(mshdr_tvb
, offset
);
183 proto_tree_add_item(tree
, hf_name
, mshdr_tvb
, offset
, len
, ENC_ASCII
|ENC_NA
);
185 proto_item_set_len(item
, offset
);
188 switch(trans_subcmd
){
189 case MAILSLOT_BROWSE
:
190 call_dissector(mailslot_browse_handle
, tvb
, pinfo
,
194 case MAILSLOT_LANMAN
:
195 call_dissector(mailslot_lanman_handle
, tvb
, pinfo
,
200 case MAILSLOT_TEMP_NETLOGON
:
202 call_dissector(netlogon_handle
, tvb
, pinfo
,
208 * We dissected the mailslot header, but we don't know
209 * how to dissect the message; dissect the latter as data,
210 * but indicate that we successfully dissected the mailslot
213 call_dissector(data_handle
,tvb
, pinfo
, parent_tree
);
220 proto_register_smb_mailslot(void)
222 static hf_register_info hf
[] = {
224 { "Opcode", "mailslot.opcode", FT_UINT16
, BASE_DEC
,
225 VALS(opcode_vals
), 0, "MAILSLOT OpCode", HFILL
}},
228 { "Priority", "mailslot.priority", FT_UINT16
, BASE_DEC
,
229 NULL
, 0, "MAILSLOT Priority of transaction", HFILL
}},
232 { "Class", "mailslot.class", FT_UINT16
, BASE_DEC
,
233 VALS(class_vals
), 0, "MAILSLOT Class of transaction", HFILL
}},
236 { "Size", "mailslot.size", FT_UINT16
, BASE_DEC
,
237 NULL
, 0, "MAILSLOT Total size of mail data", HFILL
}},
240 { "Mailslot Name", "mailslot.name", FT_STRING
, BASE_NONE
,
241 NULL
, 0, "MAILSLOT Name of mailslot", HFILL
}},
245 static gint
*ett
[] = {
249 proto_smb_msp
= proto_register_protocol(
250 "SMB MailSlot Protocol", "SMB Mailslot", "mailslot");
252 proto_register_field_array(proto_smb_msp
, hf
, array_length(hf
));
253 proto_register_subtree_array(ett
, array_length(ett
));
257 proto_reg_handoff_smb_mailslot(void)
259 mailslot_browse_handle
= find_dissector("mailslot_browse");
260 mailslot_lanman_handle
= find_dissector("mailslot_lanman");
261 netlogon_handle
= find_dissector("smb_netlogon");
262 data_handle
= find_dissector("data");