Correctly handle Interim responses to TRANSACTION requests.
[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.10 2001/03/18 03:23:30 guy Exp $
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@zing.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
29 #include "packet-smb-common.h"
30 #include "packet-smb-mailslot.h"
31 #include "packet-smb-pipe.h"
32
33 static int proto_smb_msp = -1;
34
35 static int ett_smb_msp = -1;
36
37
38 /***  External dissectors called from here      */
39
40 extern guint32 
41 dissect_mailslot_browse(const u_char *pd, int offset, frame_data *fd,
42         proto_tree *parent, proto_tree *tree, struct smb_info si, int max_data,
43         int SMB_offset, int errcode, int dirn, const u_char *command,
44         int DataOffset, int DataCount);
45
46 extern guint32 
47 dissect_smb_ntlogon(const u_char *pd, int offset, frame_data *fd,
48         proto_tree *parent, proto_tree *tree, struct smb_info si, int max_data,
49         int SMB_offset, int errcode, int dirn, const u_char *command,
50         int DataOffset, int DataCount);
51
52
53 extern guint32 
54 dissect_smb_logon(const u_char *pd, int offset, frame_data *fd,
55         proto_tree *parent, proto_tree *tree, struct smb_info si, int max_data,
56         int SMB_offset, int errcode, int dirn, const u_char *command,
57         int DataOffset, int DataCount);
58
59
60
61 gboolean
62 dissect_mailslot_smb(const u_char *pd, int offset, frame_data *fd,
63         proto_tree *parent, proto_tree *tree, struct smb_info si, int max_data,
64         int SMB_offset, int errcode, int dirn, const u_char *command,
65         int DataOffset, int DataCount, int ParameterOffset, int ParameterCount){
66
67
68 /* decode the SMB mail slot protocol */
69
70         proto_tree      *smb_msp_tree = 0;
71         proto_item      *ti;
72
73         guint16  Temp16; 
74         const char *StrPtr;
75
76         if (!proto_is_protocol_enabled(proto_smb_msp))
77                 return FALSE;
78    
79         if (check_col(fd, COL_PROTOCOL))
80                 col_set_str(fd, COL_PROTOCOL, "SMB Mailslot");
81
82         if (DataOffset < 0) {
83                 /* Interim reply */
84                 col_set_str(fd, COL_INFO, "Interim reply");
85                 return TRUE;
86         }
87
88  /* do the Op code field */
89  
90         Temp16 = GSHORT(pd, offset);            /* get Op code */
91
92         if (check_col(fd, COL_INFO))
93                   col_set_str(fd, COL_INFO,
94                       ( Temp16 == 1 ? "Write Mail slot" : "Unknown"));
95
96
97         if (tree) {
98                 ti = proto_tree_add_item( parent, proto_smb_msp, NullTVB, offset,
99                         END_OF_FRAME, FALSE);
100                 smb_msp_tree = proto_item_add_subtree(ti, ett_smb_msp);
101
102                 proto_tree_add_text(smb_msp_tree, NullTVB, offset, 2, "Op code: %u (%s)",
103                         Temp16, ( Temp16 == 1 ? "Write Mail slot" : "Unknown"));
104
105                 offset += 2;
106  
107                                                 /* do the Priority field */
108                 Temp16 = GSHORT(pd, offset);
109                 proto_tree_add_text(smb_msp_tree, NullTVB, offset, 2,
110                         "Priority of transaction: %u", Temp16);
111         
112                 offset += 2;
113
114                                                 /* do the Class field */
115                 Temp16 = GSHORT(pd, offset);
116      
117                 proto_tree_add_text(smb_msp_tree, NullTVB, offset, 2, "Class: %u (%s)",
118                         Temp16, ( Temp16 == 1) ? "Reliable" : (( Temp16 == 2) ?
119                         "Unreliable & Broadcast" : "Unknown"));
120         
121                 offset += 2;
122
123                                                 /* do the data size field */
124                 Temp16 = GSHORT(pd, offset);
125                 proto_tree_add_text(smb_msp_tree, NullTVB, offset, 2,
126                         "Total size of mail data: %u", Temp16);
127
128                 offset += 2;
129         }else {                                 /* no tree value adjust offset*/
130                 offset += 8;
131         }               
132
133                                         /* Build display for: MailSlot Name */
134
135         StrPtr = &pd[offset];           /* load pointer to name */
136
137         if (smb_msp_tree) {
138                 proto_tree_add_text(smb_msp_tree, NullTVB, offset, strlen( StrPtr) + 1,
139                         "Mailslot Name: %s", StrPtr);
140         }
141
142         offset += strlen( StrPtr) + 1;
143  
144 /*** Decide what dissector to call based upon the command value ***/
145  
146         if (command != NULL && strcmp(command, "BROWSE") == 0) { /* Decode a browse */
147
148                 return dissect_mailslot_browse(pd, offset, fd, parent, tree,
149                         si, max_data, SMB_offset, errcode, dirn, command,
150                         DataOffset, DataCount);
151         }
152
153         else if (command != NULL && strcmp(command, "LANMAN") == 0) {
154
155                 return dissect_pipe_lanman(pd, offset, fd, parent, tree, si,
156                         max_data, SMB_offset, errcode, dirn, command,
157                         DataOffset, DataCount, ParameterOffset, ParameterCount);
158         }
159
160 /* NOTE: use TEMP\\NETLOGON and MSSP because they seems very common,    */
161 /* NOTE: may need a look up list to check for the mailslot names passed */
162 /*              by the logon request packet */
163         
164         else if (((command != NULL) &&
165                   strncmp(command, "NET", strlen("NET")) == 0) ||
166                  (strcmp(command, "TEMP\\NETLOGON") == 0) ||
167                  (strcmp(command, "MSSP") == 0)){
168
169                 return dissect_smb_logon(pd, DataOffset, fd, parent, tree,
170                         si, max_data, SMB_offset, errcode, dirn,
171                         command, DataOffset, DataCount);
172                 
173          }
174         return TRUE;
175 }
176
177
178 void
179 register_proto_smb_mailslot( void){
180
181
182         static gint *ett[] = {
183                 &ett_smb_msp
184         };
185
186         proto_smb_msp = proto_register_protocol(
187                 "SMB MailSlot Protocol", "SMB Mailslot", "mailslot");
188
189         proto_register_subtree_array(ett, array_length(ett));
190 }