change the signature that asn2wrs generates for functions to marm all parameters...
[obnox/wireshark/wip.git] / epan / dissectors / 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$
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
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 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <string.h>
33
34 #include <glib.h>
35
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"
42
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;
49
50 static int ett_smb_msp = -1;
51
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;
56
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
63
64 static const value_string opcode_vals[] = {
65         {1,     "Write Mail Slot"},
66         {0,     NULL}
67 };
68
69 static const value_string class_vals[] = {
70         {1,     "Reliable"},
71         {2,     "Unreliable & Broadcast"},
72         {0,     NULL}
73 };
74
75 /* decode the SMB mail slot protocol
76    for requests
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.
79    for responses
80      mailslot is NULL
81      si->trans_subcmd gives us which mailslot this response refers to.
82 */
83
84 gboolean
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)
88 {
89         smb_info_t *smb_info;
90         smb_transact_info_t *tri;
91         int             trans_subcmd;
92         proto_tree      *tree = NULL;
93         proto_item      *item = NULL;
94         guint16         opcode;
95         int             offset = 0;
96         int             len;
97
98         if (!proto_is_protocol_enabled(find_protocol_by_id(proto_smb_msp))) {
99                 return FALSE;
100         }
101         pinfo->current_proto = "SMB Mailslot";
102
103         if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
104                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "SMB Mailslot");
105         }
106
107         if ((tvb==NULL) || (tvb_reported_length(tvb)==0)) {
108                 /* Interim reply */
109                 if (check_col (pinfo->cinfo, COL_INFO)) {
110                         col_set_str(pinfo->cinfo, COL_INFO, "Interim reply");
111                 }
112                 return TRUE;
113         }
114
115         if (check_col(pinfo->cinfo, COL_INFO)) {
116                 col_clear(pinfo->cinfo, COL_INFO);
117         }
118
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;
122         else
123                 tri = NULL;
124
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;
138                 }
139                 if (!pinfo->fd->flags.visited) {
140                         if (tri != NULL)
141                                 tri->trans_subcmd = trans_subcmd;
142                 }
143         } else {
144                 if(!tri){
145                         return FALSE;
146                 } else {
147                         trans_subcmd = tri->trans_subcmd;
148                 }
149         }
150
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
153         */
154         if(mshdr_tvb && setup_tvb){
155                 if (parent_tree) {
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);
159                 }
160
161                 /* do the opcode field */
162                 opcode = tvb_get_letohs(setup_tvb, offset);
163
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"));
167                 }
168
169
170                 /* These are in the setup words; use "setup_tvb". */
171
172                 /* opcode */
173                 proto_tree_add_uint(tree, hf_opcode, setup_tvb, offset, 2,
174                     opcode);
175                 offset += 2;
176
177                 /* priority */
178                 proto_tree_add_item(tree, hf_priority, setup_tvb, offset, 2,
179                     TRUE);
180                 offset += 2;
181
182                 /* class */
183                 proto_tree_add_item(tree, hf_class, setup_tvb, offset, 2, TRUE);
184                 offset += 2;
185
186                 /* These are in the rest of the data; use "mshdr_tvb", which
187                    starts at the same place "setup_tvb" does. */
188
189                 /* size */
190                 /* this is actually bytecount in the SMB Transaction command */
191                 proto_tree_add_item(tree, hf_size, mshdr_tvb, offset, 2, TRUE);
192                 offset += 2;
193
194                 /* mailslot name */
195                 len = tvb_strsize(mshdr_tvb, offset);
196                 proto_tree_add_item(tree, hf_name, mshdr_tvb, offset, len, TRUE);
197                 offset += len;
198                 proto_item_set_len(item, offset);
199         }
200
201         switch(trans_subcmd){
202         case MAILSLOT_BROWSE:
203                 call_dissector(mailslot_browse_handle, tvb, pinfo,
204                     parent_tree);
205                 break;
206
207         case MAILSLOT_LANMAN:
208                 call_dissector(mailslot_lanman_handle, tvb, pinfo,
209                     parent_tree);
210                 break;
211
212         case MAILSLOT_NET:
213         case MAILSLOT_TEMP_NETLOGON:
214         case MAILSLOT_MSSP:
215                 call_dissector(netlogon_handle, tvb, pinfo,
216                     parent_tree);
217                 break;
218
219         default:
220                 /*
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
224                  * stuff.
225                  */
226                 call_dissector(data_handle ,tvb, pinfo, parent_tree);
227                 break;
228         }
229         return TRUE;
230 }
231
232 void
233 proto_register_smb_mailslot(void)
234 {
235         static hf_register_info hf[] = {
236                 { &hf_opcode,
237                         { "Opcode", "mailslot.opcode", FT_UINT16, BASE_DEC,
238                         VALS(opcode_vals), 0, "MAILSLOT OpCode", HFILL }},
239
240                 { &hf_priority,
241                         { "Priority", "mailslot.priority", FT_UINT16, BASE_DEC,
242                         NULL, 0, "MAILSLOT Priority of transaction", HFILL }},
243
244                 { &hf_class,
245                         { "Class", "mailslot.class", FT_UINT16, BASE_DEC,
246                         VALS(class_vals), 0, "MAILSLOT Class of transaction", HFILL }},
247
248                 { &hf_size,
249                         { "Size", "mailslot.size", FT_UINT16, BASE_DEC,
250                         NULL, 0, "MAILSLOT Total size of mail data", HFILL }},
251
252                 { &hf_name,
253                         { "Mailslot Name", "mailslot.name", FT_STRING, BASE_NONE,
254                         NULL, 0, "MAILSLOT Name of mailslot", HFILL }},
255
256         };
257
258         static gint *ett[] = {
259                 &ett_smb_msp
260         };
261
262         proto_smb_msp = proto_register_protocol(
263                 "SMB MailSlot Protocol", "SMB Mailslot", "mailslot");
264
265         proto_register_field_array(proto_smb_msp, hf, array_length(hf));
266         proto_register_subtree_array(ett, array_length(ett));
267 }
268
269 void
270 proto_reg_handoff_smb_mailslot(void)
271 {
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");
276 }