Added mockups for LSA_SECRET and LSA_SECURITY_DESCRIPTOR inside
[obnox/wireshark/wip.git] / packet-stat.c
1 /* packet-stat.c
2  * Routines for stat dissection
3  *
4  * $Id: packet-stat.c,v 1.14 2002/03/05 11:04:15 guy Exp $
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@ethereal.com>
8  * Copyright 1998 Gerald Combs
9  *
10  * Copied from packet-smb.c
11  *
12  * 2001  Ronnie Sahlberg <See AUTHORS for email>
13  *     Added the dissectors for STAT protocol
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version 2
18  * of the License, or (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
28  */
29
30 #ifdef HAVE_CONFIG_H
31 #include "config.h"
32 #endif
33
34
35 #ifdef HAVE_SYS_TYPES_H
36 #include <sys/types.h>
37 #endif
38
39 #include "packet-rpc.h"
40 #include "packet-stat.h"
41
42 static int proto_stat = -1;
43 static int hf_stat_mon_name = -1;
44 static int hf_stat_stat_res = -1;
45 static int hf_stat_stat_res_res = -1;
46 static int hf_stat_stat_res_state = -1;
47 static int hf_stat_state = -1;
48 static int hf_stat_mon = -1;
49 static int hf_stat_mon_id_name = -1;
50 static int hf_stat_my_id = -1;
51 static int hf_stat_my_id_hostname = -1;
52 static int hf_stat_my_id_prog = -1;
53 static int hf_stat_my_id_vers = -1;
54 static int hf_stat_my_id_proc = -1;
55 static int hf_stat_priv = -1;
56 static int hf_stat_stat_chge = -1;
57
58 static gint ett_stat = -1;
59 static gint ett_stat_stat_res = -1;
60 static gint ett_stat_mon = -1;
61 static gint ett_stat_my_id = -1;
62 static gint ett_stat_stat_chge = -1;
63
64 #define STAT_SUCC       0
65 #define STAT_FAIL       1
66
67 static const value_string stat_res[] =
68 {
69         {       0,      "STAT_SUCC" },
70         {       1,      "STAT_FAIL" },
71         {       0,      NULL }
72 };
73
74 /* Calculate length (including padding) of my_id structure. 
75  * First read the length of the string and round it upwards to nearest 
76  * multiple of 4, then add 16 (4*uint32)
77  */
78 static int
79 my_id_len(tvbuff_t *tvb, int offset)
80 {
81         int len;
82
83         len = tvb_get_ntohl(tvb, offset);
84         if(len&0x03)
85                 len = (len&0xfc)+4;
86
87         len += 16;
88
89         return len;
90 }
91
92 /* Calculate length (including padding) of my_id structure. 
93  * First read the length of the string and round it upwards to nearest 
94  * multiple of 4, then add 4 (string len) and size of my_id struct.
95  */
96 static int
97 mon_id_len(tvbuff_t *tvb, int offset)
98 {
99         int len;
100
101         len = tvb_get_ntohl(tvb, offset);
102         if(len&0x03){
103                 len = (len&0xfc)+4;
104         }
105
106         len += 4;
107
108         return len+my_id_len(tvb,offset+len);
109 }
110
111 static int
112 dissect_stat_stat(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
113 {
114         if (tree)
115         {
116                 offset = dissect_rpc_string(tvb,pinfo,tree,hf_stat_mon_name,offset,NULL);
117         }
118
119         return offset;
120 }
121
122 static int
123 dissect_stat_stat_res(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
124 {
125         proto_item* sub_item = NULL;
126         proto_tree* sub_tree = NULL;
127         gint32 res;
128         gint32 state;
129
130         if (tree) {
131                 sub_item = proto_tree_add_item(tree, hf_stat_stat_res, tvb,
132                                 offset, -1, FALSE);
133                 if (sub_item)
134                         sub_tree = proto_item_add_subtree(sub_item, ett_stat_stat_res);
135         }
136
137         res = tvb_get_ntohl(tvb, offset);
138         offset = dissect_rpc_uint32(tvb,pinfo,sub_tree,hf_stat_stat_res_res,offset);
139
140         if (res==STAT_SUCC) {
141                 state = tvb_get_ntohl(tvb, offset);
142                 offset = dissect_rpc_uint32(tvb,pinfo,sub_tree,hf_stat_stat_res_state,offset);
143         } else {
144                 offset += 4;
145         }
146
147         return offset;
148 }       
149
150 static int
151 dissect_stat_my_id(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
152 {
153         proto_item* sub_item = NULL;
154         proto_tree* sub_tree = NULL;
155
156         if (tree) {
157                 sub_item = proto_tree_add_item(tree, hf_stat_my_id, tvb,
158                                 offset, my_id_len(tvb,offset), FALSE);
159                 if (sub_item)
160                         sub_tree = proto_item_add_subtree(sub_item, ett_stat_my_id);
161         }
162
163         offset = dissect_rpc_string(tvb,pinfo,sub_tree,hf_stat_my_id_hostname,offset,NULL);
164         offset = dissect_rpc_uint32(tvb,pinfo,sub_tree,hf_stat_my_id_prog,offset);
165         offset = dissect_rpc_uint32(tvb,pinfo,sub_tree,hf_stat_my_id_vers,offset);
166         offset = dissect_rpc_uint32(tvb,pinfo,sub_tree,hf_stat_my_id_proc,offset);
167
168         return offset;
169 }
170
171 static int
172 dissect_stat_mon_id(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
173 {
174         proto_item* sub_item = NULL;
175         proto_tree* sub_tree = NULL;
176
177         if (tree) {
178                 sub_item = proto_tree_add_item(tree, hf_stat_mon, tvb,
179                                 offset, mon_id_len(tvb,offset), FALSE);
180                 if (sub_item)
181                         sub_tree = proto_item_add_subtree(sub_item, ett_stat_mon);
182         }
183
184
185         offset = dissect_rpc_string(tvb,pinfo,sub_tree,hf_stat_mon_id_name,offset,NULL);
186
187         offset = dissect_stat_my_id(tvb,offset,pinfo,sub_tree);
188
189         return offset;
190 }
191
192 static int
193 dissect_stat_priv(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
194 {
195         proto_tree_add_item(tree, hf_stat_priv, tvb, offset, 16, FALSE);
196         offset += 16;
197
198         return offset;
199 }
200
201 static int
202 dissect_stat_mon(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
203 {
204         
205         offset = dissect_stat_mon_id(tvb,offset,pinfo,tree);
206
207         offset = dissect_stat_priv(tvb,offset,pinfo,tree);
208         return offset;
209 }
210
211 static int
212 dissect_stat_state(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
213 {
214         offset = dissect_rpc_uint32(tvb,pinfo,tree,hf_stat_state,offset);
215
216         return offset;
217 }       
218
219 static int
220 dissect_stat_notify(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
221 {
222         proto_item* sub_item = NULL;
223         proto_tree* sub_tree = NULL;
224         int start_offset = offset;
225
226         if (tree) {
227                 sub_item = proto_tree_add_item(tree, hf_stat_stat_chge, tvb,
228                                 offset, -1, FALSE);
229                 if (sub_item)
230                         sub_tree = proto_item_add_subtree(sub_item, ett_stat_stat_chge);
231         }
232
233         offset = dissect_rpc_string(tvb,pinfo,sub_tree,hf_stat_mon_id_name,offset,NULL);
234         
235         offset = dissect_rpc_uint32(tvb,pinfo,tree,hf_stat_state,offset);
236
237         if(sub_item)
238                 proto_item_set_len(sub_item, offset - start_offset);
239
240         return offset;
241 }
242
243 static int
244 dissect_stat_umon_all(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
245 {
246         offset = dissect_stat_my_id(tvb,offset,pinfo,tree);
247
248         return offset;
249 }
250
251 /* proc number, "proc name", dissect_request, dissect_reply */
252 /* NULL as function pointer means: type of arguments is "void". */
253
254 static const vsff stat_proc[] = {
255     { 0, "NULL", NULL, NULL },
256     { STATPROC_STAT,   "STAT",      
257                 dissect_stat_stat, dissect_stat_stat_res },
258     { STATPROC_MON,   "MON",      
259                 dissect_stat_mon, dissect_stat_stat_res },
260     { STATPROC_UNMON, "UNMON",        
261                 dissect_stat_mon_id, dissect_stat_state },
262     { STATPROC_UNMON_ALL, "UNMON_ALL",        
263                 dissect_stat_umon_all, dissect_stat_state },
264     { STATPROC_SIMU_CRASH, "SIMU_CRASH",        
265                 NULL, NULL },
266     { STATPROC_NOTIFY, "NOTIFY",        
267                 dissect_stat_notify, NULL },
268     { 0, NULL, NULL, NULL }
269 };
270 /* end of stat version 1 */
271
272
273 void
274 proto_register_stat(void)
275 {
276         static hf_register_info hf[] = {
277                 { &hf_stat_mon_name, {
278                         "Name", "stat.name", FT_STRING, BASE_DEC,
279                         NULL, 0, "Name", HFILL }},
280                 { &hf_stat_stat_res, {
281                         "Status Result", "stat.stat_res", FT_NONE,0,
282                         NULL, 0, "Status Result", HFILL }}, 
283                 { &hf_stat_stat_res_res, {
284                         "Result", "stat.stat_res.res", FT_UINT32, BASE_DEC,
285                         VALS(stat_res), 0, "Result", HFILL }},
286                 { &hf_stat_stat_res_state, {
287                         "State", "stat.stat_res.state", FT_UINT32, BASE_DEC,
288                         NULL, 0, "State", HFILL }},
289                 { &hf_stat_mon, {
290                         "Monitor", "stat.mon", FT_NONE, 0,
291                         NULL, 0, "Monitor Host", HFILL }},
292                 { &hf_stat_mon_id_name, {
293                         "Monitor ID Name", "stat.mon_id.name", FT_STRING, BASE_DEC,
294                         NULL, 0, "Monitor ID Name", HFILL }},
295                 { &hf_stat_my_id, {
296                         "My ID", "stat.my_id", FT_NONE,0,
297                         NULL, 0, "My_ID structure", HFILL }}, 
298                 { &hf_stat_my_id_hostname, {
299                         "Hostname", "stat.my_id.hostname", FT_STRING, BASE_DEC,
300                         NULL, 0, "My_ID Host to callback", HFILL }},
301                 { &hf_stat_my_id_prog, {
302                         "Program", "stat.my_id.prog", FT_UINT32, BASE_DEC,
303                         NULL, 0, "My_ID Program to callback", HFILL }},
304                 { &hf_stat_my_id_vers, {
305                         "Version", "stat.my_id.vers", FT_UINT32, BASE_DEC,
306                         NULL, 0, "My_ID Version of callback", HFILL }},
307                 { &hf_stat_my_id_proc, {
308                         "Procedure", "stat.my_id.proc", FT_UINT32, BASE_DEC,
309                         NULL, 0, "My_ID Procedure to callback", HFILL }},
310                 { &hf_stat_priv, {
311                         "Priv", "stat.priv", FT_BYTES, BASE_HEX,
312                         NULL, 0, "Private client supplied opaque data", HFILL }},
313                 { &hf_stat_state, {
314                         "State", "stat.state", FT_UINT32, BASE_DEC,
315                         NULL, 0, "State of local NSM", HFILL }},
316                 { &hf_stat_stat_chge, {
317                         "Status Change", "stat.stat_chge", FT_NONE, 0,
318                         NULL, 0, "Status Change structure", HFILL }},
319         };
320         
321         static gint *ett[] = {
322                 &ett_stat,
323                 &ett_stat_stat_res,
324                 &ett_stat_mon,
325                 &ett_stat_my_id,
326                 &ett_stat_stat_chge,
327         };
328
329         proto_stat = proto_register_protocol("Network Status Monitor Protocol", "STAT", "stat");
330         proto_register_field_array(proto_stat, hf, array_length(hf));
331         proto_register_subtree_array(ett, array_length(ett));
332 }
333
334 void
335 proto_reg_handoff_stat(void)
336 {
337         /* Register the protocol as RPC */
338         rpc_init_prog(proto_stat, STAT_PROGRAM, ett_stat);
339         /* Register the procedure tables */
340         rpc_init_proc_table(STAT_PROGRAM, 1, stat_proc);
341 }