Renamed init_dissect_x25() to reinit_x25_hashtable() and actually used it !
[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.3 2000/02/14 04:21:04 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
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
75         proto_tree      *smb_msp_tree = 0;
76         proto_item      *ti;
77
78         guint16  Temp16; 
79         const char *StrPtr;
80    
81  /* do the Op code field */
82  
83         Temp16 = GSHORT(pd, offset);            /* get Op code */
84
85         if (check_col(fd, COL_PROTOCOL))
86                 col_add_str(fd, COL_PROTOCOL, "SMB Mailslot");
87
88         if (check_col(fd, COL_INFO))
89                   col_add_fstr(fd, COL_INFO, "%s",
90                       ( Temp16 == 1 ? "Write Mail slot" : "Unknown"));
91
92
93         if (tree) {
94                 ti = proto_tree_add_item( parent, proto_smb_msp, offset,
95                         END_OF_FRAME, NULL);
96                 smb_msp_tree = proto_item_add_subtree(ti, ett_smb_msp);
97
98                 proto_tree_add_text(smb_msp_tree, offset, 2, "Op code: %u (%s)",
99                         Temp16, ( Temp16 == 1 ? "Write Mail slot" : "Unknown"));
100
101                 offset += 2;
102  
103                                                 /* do the Priority field */
104                 Temp16 = GSHORT(pd, offset);
105                 proto_tree_add_text(smb_msp_tree, offset, 2,
106                         "Priority of transaction: %u", Temp16);
107         
108                 offset += 2;
109
110                                                 /* do the Class field */
111                 Temp16 = GSHORT(pd, offset);
112      
113                 proto_tree_add_text(smb_msp_tree, offset, 2, "Class: %u (%s)",
114                         Temp16, ( Temp16 == 1) ? "Reliable" : (( Temp16 == 2) ?
115                         "Unreliable & Broadcast" : "Unknown"));
116         
117                 offset += 2;
118
119                                                 /* do the data size field */
120                 Temp16 = GSHORT(pd, offset);
121                 proto_tree_add_text(smb_msp_tree, offset, 2,
122                         "Total size of mail data: %u", Temp16);
123
124                 offset += 2;
125         }else {                                 /* no tree value adjust offset*/
126                 offset += 8;
127         }               
128
129                                         /* Build display for: MailSlot Name */
130
131         StrPtr = &pd[offset];           /* load pointer to name */
132
133         if (smb_msp_tree) {
134                 proto_tree_add_text(smb_msp_tree, offset, strlen( StrPtr) + 1,
135                         "Mailslot Name: %s", StrPtr);
136         }
137
138         offset += strlen( StrPtr) + 1;
139  
140 /*** Decide what dissector to call based upon the command value ***/
141  
142         if (strcmp(command, "BROWSE") == 0) { /* Decode a browse */
143
144                 return dissect_mailslot_browse(pd, offset, fd, parent, tree,
145                         si, max_data, SMB_offset, errcode, dirn, command,
146                         DataOffset, DataCount);
147         }
148
149         else if (strcmp(command, "LANMAN") == 0) {
150
151                 return dissect_pipe_lanman(pd, offset, fd, parent, tree, si,
152                         max_data, SMB_offset, errcode, dirn, command,
153                         DataOffset, DataCount, ParameterOffset, ParameterCount);
154         }
155
156 /* NOTE: use TEMP\\NETLOGON and MSSP because they seems very common,    */
157 /* NOTE: may need a look up list to check for the mailslot names passed */
158 /*              by the logon request packet */
159         
160         else if ((strncmp(command, "NET", strlen("NET")) == 0) 
161                         || (strcmp(command, "TEMP\\NETLOGON") == 0)
162                         || (strcmp(command, "MSSP") == 0)){
163
164                 return dissect_smb_logon(pd, DataOffset, fd, parent, tree,
165                         si, max_data, SMB_offset, errcode, dirn,
166                         command, DataOffset, DataCount);
167                 
168          }
169         return 1;
170 }
171
172
173 void
174 register_proto_smb_mailslot( void){
175
176
177         static gint *ett[] = {
178                 &ett_smb_msp
179         };
180
181         proto_smb_msp = proto_register_protocol(
182                 "SMB MailSlot Protocol", "mailslot");
183
184         proto_register_subtree_array(ett, array_length(ett));
185 }