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