Correctly dissect LSA security descriptors, at least as they appear
[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.31 2002/02/10 02:25:14 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
134         /* Only do these ones if we have them. For fragmented SMB Transactions
135            we may only have the setup area for the first fragment
136         */
137         if(mshdr_tvb && setup_tvb){
138                 if (parent_tree) {
139                         item = proto_tree_add_item(parent_tree, proto_smb_msp,
140                                                    mshdr_tvb, 0, -1, FALSE);
141                         tree = proto_item_add_subtree(item, ett_smb_msp);
142                 }
143
144                 /* do the opcode field */
145                 opcode = tvb_get_letohs(setup_tvb, offset);
146
147                 if (check_col(pinfo->cinfo, COL_INFO)) {
148                         col_add_str(pinfo->cinfo, COL_INFO,
149                                     val_to_str(opcode, opcode_vals, "Unknown opcode: 0x%04x"));
150                 }
151
152
153                 /* These are in the setup words; use "setup_tvb". */
154
155                 /* opcode */
156                 proto_tree_add_uint(tree, hf_opcode, setup_tvb, offset, 2,
157                     opcode);
158                 offset += 2;
159
160                 /* priority */
161                 proto_tree_add_item(tree, hf_priority, setup_tvb, offset, 2,
162                     TRUE);
163                 offset += 2;
164
165                 /* class */
166                 proto_tree_add_item(tree, hf_class, setup_tvb, offset, 2, TRUE);
167                 offset += 2;
168
169                 /* These are in the rest of the data; use "mshdr_tvb", which
170                    starts at the same place "setup_tvb" does. */
171
172                 /* size */
173                 /* this is actually bytecount in the SMB Transaction command */
174                 proto_tree_add_item(tree, hf_size, mshdr_tvb, offset, 2, TRUE);
175                 offset += 2;
176
177                 /* mailslot name */
178                 len = tvb_strsize(mshdr_tvb, offset);
179                 proto_tree_add_item(tree, hf_name, mshdr_tvb, offset, len, TRUE);
180                 offset += len;
181                 proto_item_set_len(item, offset);
182         }
183
184         dissected = FALSE;
185         switch(trans_subcmd){
186         case MAILSLOT_BROWSE:
187                 dissected = dissect_mailslot_browse(tvb, pinfo, parent_tree);
188                 break;
189         case MAILSLOT_LANMAN:
190                 dissected = dissect_mailslot_lanman(tvb, pinfo, parent_tree);
191                 break;
192         case MAILSLOT_NET:
193         case MAILSLOT_TEMP_NETLOGON:
194         case MAILSLOT_MSSP:
195                 dissected = dissect_smb_logon(tvb, pinfo, parent_tree);
196                 break;
197         }
198         if (!dissected) {
199                 /*
200                  * We dissected the mailslot header, but not the
201                  * message; dissect the latter as data, but indicate
202                  * that we successfully dissected the mailslot stuff.
203                  */
204                 call_dissector(data_handle,tvb, pinfo, parent_tree);
205         }
206         return TRUE;
207 }
208
209 void
210 proto_register_smb_mailslot(void)
211 {
212         static hf_register_info hf[] = {
213                 { &hf_opcode,
214                         { "Opcode", "mailslot.opcode", FT_UINT16, BASE_DEC,
215                         VALS(opcode_vals), 0, "MAILSLOT OpCode", HFILL }},
216
217                 { &hf_priority,
218                         { "Priority", "mailslot.priority", FT_UINT16, BASE_DEC,
219                         NULL, 0, "MAILSLOT Priority of transaction", HFILL }},
220
221                 { &hf_class,
222                         { "Class", "mailslot.class", FT_UINT16, BASE_DEC,
223                         VALS(class_vals), 0, "MAILSLOT Class of transaction", HFILL }},
224
225                 { &hf_size,
226                         { "Size", "mailslot.size", FT_UINT16, BASE_DEC,
227                         NULL, 0, "MAILSLOT Total size of mail data", HFILL }},
228
229                 { &hf_name,
230                         { "Mailslot Name", "mailslot.name", FT_STRING, BASE_NONE,
231                         NULL, 0, "MAILSLOT Name of mailslot", HFILL }},
232
233         };
234
235         static gint *ett[] = {
236                 &ett_smb_msp
237         };
238
239         proto_smb_msp = proto_register_protocol(
240                 "SMB MailSlot Protocol", "SMB Mailslot", "mailslot");
241
242         proto_register_field_array(proto_smb_msp, hf, array_length(hf));
243         proto_register_subtree_array(ett, array_length(ett));
244 }
245
246 void
247 proto_reg_handoff_smb_mailslot(void)
248 {
249         data_handle = find_dissector("data");
250 }