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