Remove "text2pcap-scanner.obj" and "tools\lemon\lemon.obj" when a "nmake
[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.19 2001/11/03 00:58:49 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 const value_string opcode_vals[] = {
44         {1,     "Write Mail Slot"},
45         {0,     NULL}
46 };
47
48 static const value_string class_vals[] = {
49         {1,     "Reliable"},
50         {2,     "Unreliable & Broadcast"},
51         {0,     NULL}
52 };
53
54 /* decode the SMB mail slot protocol */
55 gboolean
56 dissect_mailslot_smb(tvbuff_t *setup_tvb, tvbuff_t *tvb, packet_info *pinfo,
57                      proto_tree *parent_tree)
58 {
59         struct smb_info *smb_info = pinfo->private_data;
60         proto_tree      *tree = 0;
61         proto_item      *item;
62         tvbuff_t        *next_tvb = NULL;
63         guint16         opcode;
64         int             offset = 0;
65         int             len;
66
67         if (!proto_is_protocol_enabled(proto_smb_msp)) {
68                 return FALSE;
69         }
70         pinfo->current_proto = "SMB Mailslot";
71
72         if (check_col(pinfo->fd, COL_PROTOCOL)) {
73                 col_set_str(pinfo->fd, COL_PROTOCOL, "SMB Mailslot");
74         }
75
76         if (smb_info->data_offset < 0) {
77                 /* Interim reply */
78                 col_set_str(pinfo->fd, COL_INFO, "Interim reply");
79                 return TRUE;
80         }
81
82         /* do the opcode field */
83         opcode = tvb_get_letohs(setup_tvb, offset);
84
85         if (check_col(pinfo->fd, COL_INFO)) {
86                   col_add_str(pinfo->fd, COL_INFO,
87                       val_to_str(opcode, opcode_vals, "Unknown opcode:0x%04x"));
88         }
89
90         if (parent_tree) {
91                 item = proto_tree_add_item(parent_tree, proto_smb_msp, setup_tvb,
92                         offset, tvb_length_remaining(setup_tvb, offset), FALSE);
93                 tree = proto_item_add_subtree(item, ett_smb_msp);
94
95                 /* opcode */
96                 proto_tree_add_uint(tree, hf_opcode, setup_tvb, offset, 2,
97                     opcode);
98                 offset += 2;
99
100                 /* priority */
101                 proto_tree_add_item(tree, hf_priority, setup_tvb, offset, 2,
102                     TRUE);
103                 offset += 2;
104
105                 /* class */
106                 proto_tree_add_item(tree, hf_class, setup_tvb, offset, 2, TRUE);
107                 offset += 2;
108
109                 /* size */
110                 proto_tree_add_item(tree, hf_size, setup_tvb, offset, 2, TRUE);
111                 offset += 2;
112
113                 /* mailslot name */
114                 len = tvb_strsize(setup_tvb, offset);
115                 proto_tree_add_item(tree, hf_name, setup_tvb, offset, len,
116                     TRUE);
117                 offset += len;
118         }
119
120         /* Quit if we don't have the transaction command name (mailslot path) */
121         if (smb_info->trans_cmd == NULL) {
122                 /* Dump it as data */
123                 dissect_data(tvb, smb_info->data_offset, pinfo, parent_tree);
124                 return TRUE;
125         }
126
127         /* create new tvb for subdissector */
128         next_tvb = tvb_new_subset(tvb, smb_info->data_offset, -1, -1);
129
130         /*** Decide what dissector to call based upon the command value ***/
131         if (strcmp(smb_info->trans_cmd, "BROWSE") == 0) {
132                 if (dissect_mailslot_browse(next_tvb, pinfo, parent_tree))
133                         return TRUE;
134         } else if (strcmp(smb_info->trans_cmd, "LANMAN") == 0) {
135                 /* Decode a LANMAN browse */
136                 if (dissect_mailslot_lanman(next_tvb, pinfo, parent_tree))
137                         return TRUE;
138         } else if ((strncmp(smb_info->trans_cmd, "NET", strlen("NET")) == 0) ||
139                    (strcmp(smb_info->trans_cmd, "TEMP\\NETLOGON") == 0) ||
140                    (strcmp(smb_info->trans_cmd, "MSSP") == 0)) {
141 /* NOTE: use TEMP\\NETLOGON and MSSP because they seems very common,    */
142 /* NOTE: may need a look up list to check for the mailslot names passed */
143 /*              by the logon request packet */
144                 if (dissect_smb_logon(next_tvb, pinfo, parent_tree))
145                         return TRUE;
146         }
147         /* Dump it as data */
148         dissect_data(next_tvb, 0, pinfo, parent_tree);
149         return TRUE;
150 }
151
152 void
153 register_proto_smb_mailslot(void)
154 {
155         static hf_register_info hf[] = {
156                 { &hf_opcode,
157                         { "Opcode", "mailslot.opcode", FT_UINT16, BASE_DEC,
158                         VALS(opcode_vals), 0, "MAILSLOT OpCode", HFILL }},
159
160                 { &hf_priority,
161                         { "Priority", "mailslot.priority", FT_UINT16, BASE_DEC,
162                         NULL, 0, "MAILSLOT Priority of transaction", HFILL }},
163
164                 { &hf_class,
165                         { "Class", "mailslot.class", FT_UINT16, BASE_DEC,
166                         VALS(class_vals), 0, "MAILSLOT Class of transaction", HFILL }},
167
168                 { &hf_size,
169                         { "Size", "mailslot.size", FT_UINT16, BASE_DEC,
170                         NULL, 0, "MAILSLOT Total size of mail data", HFILL }},
171
172                 { &hf_name,
173                         { "Mailslot Name", "mailslot.name", FT_STRING, BASE_NONE,
174                         NULL, 0, "MAILSLOT Name of mailslot", HFILL }},
175
176         };
177
178         static gint *ett[] = {
179                 &ett_smb_msp
180         };
181
182         proto_smb_msp = proto_register_protocol(
183                 "SMB MailSlot Protocol", "SMB Mailslot", "mailslot");
184
185         proto_register_field_array(proto_smb_msp, hf, array_length(hf));
186         proto_register_subtree_array(ett, array_length(ett));
187 }