Dynamically create DCERPC opnum value_strings from the subdissector
[obnox/wireshark/wip.git] / packet-dcerpc-rs_acct.c
1 /* packet-dcerpc-rs_acct.c
2  *
3  * Routines for DFS/RS_ACCT
4  * Copyright 2002, Jaime Fournier <jafour1@yahoo.com>
5  * This information is based off the released idl files from opengroup.
6  * ftp://ftp.opengroup.org/pub/dce122/dce/src/security.tar.gz security/idl/rs_acct.idl
7  *      
8  * $Id: packet-dcerpc-rs_acct.c,v 1.4 2003/06/26 04:30:29 tpot Exp $
9  *
10  * Ethereal - Network traffic analyzer
11  * By Gerald Combs <gerald@ethereal.com>
12  * Copyright 1998 Gerald Combs
13  *
14  * This program is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU General Public License
16  * as published by the Free Software Foundation; either version 2
17  * of the License, or (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the Free Software
26  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
27  */
28
29 #ifdef HAVE_CONFIG_H
30 #include "config.h"
31 #endif
32
33
34 #ifdef HAVE_SYS_TYPES_H
35 #include <sys/types.h>
36 #endif
37
38 #include <string.h>
39
40 #include <glib.h>
41 #include <epan/packet.h>
42 #include "packet-dcerpc.h"
43
44
45 static int proto_rs_acct = -1;
46 static int hf_rs_acct_opnum = -1;
47 static int hf_rs_acct_lookup_rqst_var = -1;
48 static int hf_rs_acct_lookup_rqst_key_size = -1;
49 static int hf_rs_acct_lookup_rqst_key_t = -1;
50 static int hf_rs_acct_get_projlist_rqst_var1 = -1;
51 static int hf_rs_acct_get_projlist_rqst_key_size = -1;
52 static int hf_rs_acct_get_projlist_rqst_key_t = -1;
53
54
55 static gint ett_rs_acct = -1;
56
57
58
59 static e_uuid_t uuid_rs_acct = { 0x4c878280, 0x2000, 0x0000, { 0x0d, 0x00, 0x02, 0x87, 0x14, 0x00, 0x00, 0x00 } };
60 static guint16  ver_rs_acct = 1;
61
62
63 static int
64 rs_acct_dissect_lookup_rqst (tvbuff_t *tvb, int offset,
65                 packet_info *pinfo, proto_tree *tree, char *drep)
66 {
67         guint32 key_size;
68         const char *key_t = NULL;
69
70         offset = dissect_ndr_uint32 (tvb, offset, pinfo, tree, drep, 
71                         hf_rs_acct_lookup_rqst_var, NULL);
72         offset = dissect_ndr_uint32 (tvb, offset, pinfo, tree, drep, 
73                         hf_rs_acct_lookup_rqst_key_size, &key_size);
74
75         if (key_size){ /* Not able to yet decipher the OTHER versions of this call just yet. */
76                 proto_tree_add_string (tree, hf_rs_acct_lookup_rqst_key_t, tvb, offset, hf_rs_acct_lookup_rqst_key_size, tvb_get_ptr (tvb, offset, key_size));
77                 key_t = (const char *)tvb_get_ptr(tvb,offset,key_size);
78                 offset += key_size;
79
80                 if (check_col(pinfo->cinfo, COL_INFO)) {
81                         col_append_fstr(pinfo->cinfo, COL_INFO,
82                                 " Request for: %s ", key_t);
83                 }
84         } else {
85                 if (check_col(pinfo->cinfo, COL_INFO)) {
86                         col_append_str(pinfo->cinfo, COL_INFO, 
87                                 " Request (other)");
88                 }
89         }
90
91         return offset;
92 };
93
94
95
96 static int
97 rs_acct_dissect_get_projlist_rqst (tvbuff_t *tvb, int offset,
98                 packet_info *pinfo, proto_tree *tree, char *drep)
99 {
100         guint32 key_size;
101         const char *key_t = NULL;
102
103         offset = dissect_ndr_uint32 (tvb, offset, pinfo, tree, drep, 
104                         hf_rs_acct_get_projlist_rqst_var1, NULL);
105         offset = dissect_ndr_uint32 (tvb, offset, pinfo, tree, drep, 
106                         hf_rs_acct_get_projlist_rqst_key_size, &key_size);
107
108         proto_tree_add_string (tree, hf_rs_acct_get_projlist_rqst_key_t, 
109                         tvb, offset, hf_rs_acct_get_projlist_rqst_key_size, 
110                         tvb_get_ptr (tvb, offset, key_size));
111         key_t = (const char *)tvb_get_ptr(tvb,offset,key_size);
112         offset += key_size;
113
114         if (check_col(pinfo->cinfo, COL_INFO)) {
115                 col_append_fstr(pinfo->cinfo, COL_INFO, 
116                         " Request for: %s", key_t);
117         }
118
119         return offset;
120 }
121
122
123 static dcerpc_sub_dissector rs_acct_dissectors[] = {
124         { 0, "rs_acct_add", NULL, NULL},
125         { 1, "rs_acct_delete", NULL, NULL},
126         { 2, "rs_acct_rename", NULL, NULL},
127         { 3, "rs_acct_lookup", rs_acct_dissect_lookup_rqst, NULL},
128         { 4, "rs_acct_replace", NULL, NULL},
129         { 5, "rs_acct_get_projlist", rs_acct_dissect_get_projlist_rqst, NULL},
130         { 0, NULL, NULL, NULL }
131 };
132
133 void
134 proto_register_rs_acct (void)
135 {
136         static hf_register_info hf[] = {
137         { &hf_rs_acct_opnum,
138                 { "Operation", "rs_acct.opnum", FT_UINT16, BASE_DEC, NULL, 0x0, "Operation", HFILL }},
139         { &hf_rs_acct_lookup_rqst_var,
140                 { "Var", "rs_acct.lookup_rqst_var", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
141         { &hf_rs_acct_lookup_rqst_key_size,
142                 { "Key Size", "rs_acct.lookup_rqst_key_size", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
143         { &hf_rs_acct_lookup_rqst_key_t,
144                 { "Key", "rs_lookup.get_rqst_key_t", FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL }},
145         { &hf_rs_acct_get_projlist_rqst_var1,
146                 { "Var1", "rs_acct.get_projlist_rqst_var1", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
147         { &hf_rs_acct_get_projlist_rqst_key_size,
148                 { "Var1", "rs_acct.get_projlist_rqst_key_size", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
149         { &hf_rs_acct_get_projlist_rqst_key_t,
150                 { "Var1", "rs_acct.get_projlist_rqst_key_t", FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL }}
151         };
152
153         static gint *ett[] = {
154                 &ett_rs_acct,
155         };
156         proto_rs_acct = proto_register_protocol ("DCE/RPC RS_ACCT", "RS_ACCT", "rs_acct");
157         proto_register_field_array (proto_rs_acct, hf, array_length (hf));
158         proto_register_subtree_array (ett, array_length (ett));
159 }
160
161
162
163 void
164 proto_reg_handoff_rs_acct (void)
165 {
166         header_field_info *hf_info;
167
168         /* Register the protocol as dcerpc */
169         dcerpc_init_uuid (proto_rs_acct, ett_rs_acct, &uuid_rs_acct, ver_rs_acct, rs_acct_dissectors, hf_rs_acct_opnum);
170
171         /* Set opnum strings from subdissector list */
172
173         hf_info = proto_registrar_get_nth(hf_rs_acct_opnum);
174         hf_info->strings = value_string_from_subdissectors(
175                 rs_acct_dissectors, array_length(rs_acct_dissectors));
176
177 }