Finish the dissection of what we know here. My, Ronnie has made this easy.
[obnox/wireshark/wip.git] / packet-smb-mailslot.c
1 /* packet-smb-mailslot.c
2  * Routines for SMB mailslot packet dissection
3  * Copyright 2000, Jeffrey C. Foster <jfoste@woodward.com>
4  *
5  * $Id: packet-smb-mailslot.c,v 1.33 2002/08/28 21:00:31 jmayer Exp $
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@ethereal.com>
9  * Copyright 1998 Gerald Combs
10  *
11  * Copied from packet-pop.c
12  *
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.
17  *
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.
22  *
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.
26  */
27
28 #include <string.h>
29 #include "packet-smb-common.h"
30 #include "packet-smb-mailslot.h"
31 #include "packet-smb-browse.h"
32 #include "packet-smb-logon.h"
33 #include "packet-smb-pipe.h"
34
35 static int proto_smb_msp = -1;
36 static int hf_opcode = -1;
37 static int hf_priority = -1;
38 static int hf_class = -1;
39 static int hf_size = -1;
40 static int hf_name = -1;
41
42 static int ett_smb_msp = -1;
43
44 static dissector_handle_t data_handle;
45
46 #define MAILSLOT_UNKNOWN              0
47 #define MAILSLOT_BROWSE               1
48 #define MAILSLOT_LANMAN               2
49 #define MAILSLOT_NET                  3
50 #define MAILSLOT_TEMP_NETLOGON        4
51 #define MAILSLOT_MSSP                 5
52
53 static const value_string opcode_vals[] = {
54         {1,     "Write Mail Slot"},
55         {0,     NULL}
56 };
57
58 static const value_string class_vals[] = {
59         {1,     "Reliable"},
60         {2,     "Unreliable & Broadcast"},
61         {0,     NULL}
62 };
63
64 /* decode the SMB mail slot protocol
65    for requests
66      mailslot is the name of the mailslot, e.g. BROWSE
67      si->trans_subcmd is set to the symbolic constant matching the mailslot name.
68    for responses
69      mailslot is NULL
70      si->trans_subcmd gives us which mailslot this response refers to.
71 */
72
73 gboolean
74 dissect_mailslot_smb(tvbuff_t *mshdr_tvb, tvbuff_t *setup_tvb,
75                      tvbuff_t *tvb, const char *mailslot, packet_info *pinfo,
76                      proto_tree *parent_tree)
77 {
78         smb_info_t *smb_info;
79         smb_transact_info_t *tri;
80         int             trans_subcmd;
81         proto_tree      *tree = NULL;
82         proto_item      *item = NULL;
83         guint16         opcode;
84         int             offset = 0;
85         int             len;
86         gboolean        dissected;
87
88         if (!proto_is_protocol_enabled(proto_smb_msp)) {
89                 return FALSE;
90         }
91         pinfo->current_proto = "SMB Mailslot";
92
93         if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
94                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "SMB Mailslot");
95         }
96
97         if ((tvb==NULL) || (tvb_reported_length(tvb)==0)) {
98                 /* Interim reply */
99                 col_set_str(pinfo->cinfo, COL_INFO, "Interim reply");
100                 return TRUE;
101         }
102
103         if (check_col(pinfo->cinfo, COL_INFO)) {
104                 col_clear(pinfo->cinfo, COL_INFO);
105         }
106
107         smb_info = pinfo->private_data;
108         if (smb_info->sip != NULL)
109                 tri = smb_info->sip->extra_info;
110         else
111                 tri = NULL;
112
113         /* check which mailslot this is about */
114         trans_subcmd=MAILSLOT_UNKNOWN;
115         if(smb_info->request){
116                 if(strncmp(mailslot,"BROWSE",6) == 0){
117                         trans_subcmd=MAILSLOT_BROWSE;
118                 } else if(strncmp(mailslot,"LANMAN",6) == 0){
119                         trans_subcmd=MAILSLOT_LANMAN;
120                 } else if(strncmp(mailslot,"NET",3) == 0){
121                         trans_subcmd=MAILSLOT_NET;
122                 } else if(strncmp(mailslot,"TEMP\\NETLOGON",13) == 0){
123                         trans_subcmd=MAILSLOT_TEMP_NETLOGON;
124                 } else if(strncmp(mailslot,"MSSP",4) == 0){
125                         trans_subcmd=MAILSLOT_MSSP;
126                 }
127                 if (!pinfo->fd->flags.visited) {
128                         if (tri != NULL)
129                                 tri->trans_subcmd = trans_subcmd;
130                 }
131         } else {
132                 trans_subcmd = tri->trans_subcmd;
133         }
134
135         /* Only do these ones if we have them. For fragmented SMB Transactions
136            we may only have the setup area for the first fragment
137         */
138         if(mshdr_tvb && setup_tvb){
139                 if (parent_tree) {
140                         item = proto_tree_add_item(parent_tree, proto_smb_msp,
141                                                    mshdr_tvb, 0, -1, FALSE);
142                         tree = proto_item_add_subtree(item, ett_smb_msp);
143                 }
144
145                 /* do the opcode field */
146                 opcode = tvb_get_letohs(setup_tvb, offset);
147
148                 if (check_col(pinfo->cinfo, COL_INFO)) {
149                         col_add_str(pinfo->cinfo, COL_INFO,
150                                     val_to_str(opcode, opcode_vals, "Unknown opcode: 0x%04x"));
151                 }
152
153
154                 /* These are in the setup words; use "setup_tvb". */
155
156                 /* opcode */
157                 proto_tree_add_uint(tree, hf_opcode, setup_tvb, offset, 2,
158                     opcode);
159                 offset += 2;
160
161                 /* priority */
162                 proto_tree_add_item(tree, hf_priority, setup_tvb, offset, 2,
163                     TRUE);
164                 offset += 2;
165
166                 /* class */
167                 proto_tree_add_item(tree, hf_class, setup_tvb, offset, 2, TRUE);
168                 offset += 2;
169
170                 /* These are in the rest of the data; use "mshdr_tvb", which
171                    starts at the same place "setup_tvb" does. */
172
173                 /* size */
174                 /* this is actually bytecount in the SMB Transaction command */
175                 proto_tree_add_item(tree, hf_size, mshdr_tvb, offset, 2, TRUE);
176                 offset += 2;
177
178                 /* mailslot name */
179                 len = tvb_strsize(mshdr_tvb, offset);
180                 proto_tree_add_item(tree, hf_name, mshdr_tvb, offset, len, TRUE);
181                 offset += len;
182                 proto_item_set_len(item, offset);
183         }
184
185         dissected = FALSE;
186         switch(trans_subcmd){
187         case MAILSLOT_BROWSE:
188                 dissected = dissect_mailslot_browse(tvb, pinfo, parent_tree);
189                 break;
190         case MAILSLOT_LANMAN:
191                 dissected = dissect_mailslot_lanman(tvb, pinfo, parent_tree);
192                 break;
193         case MAILSLOT_NET:
194         case MAILSLOT_TEMP_NETLOGON:
195         case MAILSLOT_MSSP:
196                 dissected = dissect_smb_logon(tvb, pinfo, parent_tree);
197                 break;
198         }
199         if (!dissected) {
200                 /*
201                  * We dissected the mailslot header, but not the
202                  * message; dissect the latter as data, but indicate
203                  * that we successfully dissected the mailslot stuff.
204                  */
205                 call_dissector(data_handle,tvb, pinfo, parent_tree);
206         }
207         return TRUE;
208 }
209
210 void
211 proto_register_smb_mailslot(void)
212 {
213         static hf_register_info hf[] = {
214                 { &hf_opcode,
215                         { "Opcode", "mailslot.opcode", FT_UINT16, BASE_DEC,
216                         VALS(opcode_vals), 0, "MAILSLOT OpCode", HFILL }},
217
218                 { &hf_priority,
219                         { "Priority", "mailslot.priority", FT_UINT16, BASE_DEC,
220                         NULL, 0, "MAILSLOT Priority of transaction", HFILL }},
221
222                 { &hf_class,
223                         { "Class", "mailslot.class", FT_UINT16, BASE_DEC,
224                         VALS(class_vals), 0, "MAILSLOT Class of transaction", HFILL }},
225
226                 { &hf_size,
227                         { "Size", "mailslot.size", FT_UINT16, BASE_DEC,
228                         NULL, 0, "MAILSLOT Total size of mail data", HFILL }},
229
230                 { &hf_name,
231                         { "Mailslot Name", "mailslot.name", FT_STRING, BASE_NONE,
232                         NULL, 0, "MAILSLOT Name of mailslot", HFILL }},
233
234         };
235
236         static gint *ett[] = {
237                 &ett_smb_msp
238         };
239
240         proto_smb_msp = proto_register_protocol(
241                 "SMB MailSlot Protocol", "SMB Mailslot", "mailslot");
242
243         proto_register_field_array(proto_smb_msp, hf, array_length(hf));
244         proto_register_subtree_array(ett, array_length(ett));
245 }
246
247 void
248 proto_reg_handoff_smb_mailslot(void)
249 {
250         data_handle = find_dissector("data");
251 }