From Todd Sabin: allocate the buffer for the decrypted payload, rather
[obnox/wireshark/wip.git] / packet-dcerpc-conv.c
1 /* packet-dcerpc-conv.c
2  * Routines for dcerpc conv dissection
3  * Copyright 2001, Todd Sabin <tas@webspan.net>
4  *
5  * $Id: packet-dcerpc-conv.c,v 1.6 2002/09/26 06:13:07 sahlberg Exp $
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@ethereal.com>
9  * Copyright 1998 Gerald Combs
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24  */
25
26 #ifdef HAVE_CONFIG_H
27 #include "config.h"
28 #endif
29
30
31 #ifdef HAVE_SYS_TYPES_H
32 #include <sys/types.h>
33 #endif
34
35 #include <string.h>
36
37 #include <glib.h>
38 #include <epan/packet.h>
39 #include "packet-dcerpc.h"
40 #include "packet-dcerpc-dce122.h"
41
42
43 static int proto_conv = -1;
44 static int hf_conv_opnum = -1;
45 static int hf_conv_rc = -1;
46 static int hf_conv_who_are_you_resp_seq = -1;
47 static int hf_conv_who_are_you_rqst_actuid = -1;
48 static int hf_conv_who_are_you_rqst_boot_time = -1;
49 static int hf_conv_who_are_you2_resp_seq = -1;
50 static int hf_conv_who_are_you2_resp_casuuid = -1;
51 static int hf_conv_who_are_you2_rqst_actuid = -1;
52 static int hf_conv_who_are_you2_rqst_boot_time = -1;
53
54 static gint ett_conv = -1;
55
56
57 static e_uuid_t uuid_conv = { 0x333a2276, 0x0000, 0x0000, { 0x0d, 0x00, 0x00, 0x80, 0x9c, 0x00, 0x00, 0x00 } };
58 static guint16  ver_conv = 3;
59
60
61 static int
62 conv_dissect_who_are_you_rqst (tvbuff_t *tvb, int offset,
63                                  packet_info *pinfo, proto_tree *tree,
64                                  char *drep)
65 {
66         /*
67          *         [in]    uuid_t          *actuid,
68          *         [in]    unsigned32      boot_time,
69          */
70        e_uuid_t actuid;
71
72        offset = dissect_ndr_uuid_t (tvb, offset, pinfo, tree, drep, hf_conv_who_are_you_rqst_actuid, &actuid);
73        offset = dissect_ndr_time_t (tvb, offset, pinfo, tree, drep, hf_conv_who_are_you_rqst_boot_time, NULL);
74
75        if (check_col(pinfo->cinfo, COL_INFO)) {
76          col_add_fstr(pinfo->cinfo, COL_INFO,
77              "conv_who_are_you request actuid: %08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
78               actuid.Data1, actuid.Data2, actuid.Data3, actuid.Data4[0], actuid.Data4[1],
79               actuid.Data4[2], actuid.Data4[3], actuid.Data4[4], actuid.Data4[5], actuid.Data4[6], actuid.Data4[7]);
80         }
81                 
82         return offset;
83 }
84
85 static int
86 conv_dissect_who_are_you_resp (tvbuff_t *tvb, int offset,
87                                  packet_info *pinfo, proto_tree *tree,
88                                  char *drep)
89 {
90         /*
91          *         [out]   unsigned32      *seq,
92          *         [out]   unsigned32      *st
93          */
94        guint32 seq, st;
95
96        offset = dissect_ndr_uint32 (tvb, offset, pinfo, tree, drep, hf_conv_who_are_you_resp_seq, &seq);
97        offset = dissect_ndr_uint32 (tvb, offset, pinfo, tree, drep, hf_conv_rc, &st);
98         
99
100        if (check_col(pinfo->cinfo, COL_INFO)) {
101          col_add_fstr(pinfo->cinfo, COL_INFO, "conv_who_are_you reply seq:%u st:%s", 
102                seq, val_to_str(st, dce_error_vals, "%u")); 
103        }
104
105        return offset;
106 }
107
108
109
110 static int
111 conv_dissect_who_are_you2_rqst (tvbuff_t *tvb, int offset,
112                                  packet_info *pinfo, proto_tree *tree,
113                                  char *drep)
114 {
115         /*
116          *         [in]    uuid_t          *actuid,
117          *         [in]    unsigned32      boot_time,
118          */
119         e_uuid_t actuid;
120
121         offset = dissect_ndr_uuid_t (tvb, offset, pinfo, tree, drep, hf_conv_who_are_you2_rqst_actuid, &actuid);
122         offset = dissect_ndr_time_t (tvb, offset, pinfo, tree, drep, hf_conv_who_are_you2_rqst_boot_time, NULL);
123
124         if (check_col(pinfo->cinfo, COL_INFO)) {
125            col_add_fstr(pinfo->cinfo, COL_INFO,
126                 "conv_who_are_you request actuid: %08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
127                  actuid.Data1, actuid.Data2, actuid.Data3, actuid.Data4[0], actuid.Data4[1],
128                  actuid.Data4[2], actuid.Data4[3], actuid.Data4[4], actuid.Data4[5], actuid.Data4[6], actuid.Data4[7]);
129         }
130                 
131         return offset;
132 }
133 static int
134 conv_dissect_who_are_you2_resp (tvbuff_t *tvb, int offset,
135                                  packet_info *pinfo, proto_tree *tree,
136                                  char *drep)
137 {
138         /*
139          *         [out]   unsigned32      *seq,
140          *         [out]   uuid_t          *cas_uuid,
141          *                  
142          *         [out]   unsigned32      *st
143          */
144        guint32 seq, st;
145        e_uuid_t cas_uuid;
146
147        offset = dissect_ndr_uint32 (tvb, offset, pinfo, tree, drep, hf_conv_who_are_you2_resp_seq, &seq);
148        offset = dissect_ndr_uuid_t (tvb, offset, pinfo, tree, drep, hf_conv_who_are_you2_resp_casuuid, &cas_uuid);
149        offset = dissect_ndr_uint32 (tvb, offset, pinfo, tree, drep, hf_conv_rc, &st);
150
151        if (check_col(pinfo->cinfo, COL_INFO)) {
152          col_add_fstr(pinfo->cinfo, COL_INFO, 
153                "conv_who_are_you2 reply seq:%u st:%s cas:%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", 
154                 seq, val_to_str(st, dce_error_vals, "%u"), 
155                 cas_uuid.Data1, cas_uuid.Data2, cas_uuid.Data3, cas_uuid.Data4[0], cas_uuid.Data4[1],
156                 cas_uuid.Data4[2], cas_uuid.Data4[3], cas_uuid.Data4[4], cas_uuid.Data4[5], cas_uuid.Data4[6], cas_uuid.Data4[7]); 
157         }
158
159         return offset;
160 }
161
162
163 static dcerpc_sub_dissector conv_dissectors[] = {
164     { 0, "who_are_you", 
165           conv_dissect_who_are_you_rqst, conv_dissect_who_are_you_resp },
166     { 1, "who_are_you2", 
167           conv_dissect_who_are_you2_rqst, conv_dissect_who_are_you2_resp },
168     { 2, "are_you_there", NULL, NULL },
169     { 3, "who_are_you_auth", NULL, NULL },
170     { 4, "who_are_you_auth_more", NULL, NULL },
171     { 0, NULL, NULL, NULL }
172 };
173
174 static const value_string conv_opnum_vals[] = {
175     { 0, "who_are_you" }, 
176     { 1, "who_are_you2" }, 
177     { 2, "are_you_there" },
178     { 3, "who_are_you_auth" },
179     { 4, "who_are_you_auth_more" },
180     { 0, NULL }
181 };
182
183
184 void
185 proto_register_conv (void)
186 {
187         static hf_register_info hf[] = {
188         { &hf_conv_opnum,
189             { "Operation", "conv.opnum", FT_UINT16, BASE_DEC, VALS(conv_opnum_vals), 0x0, "Operation", HFILL }},
190         { &hf_conv_who_are_you_resp_seq,
191             {"hf_conv_who_are_you_resp_seq", "conv.who_are_you_resp_seq", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
192         { &hf_conv_rc,
193             {"Status", "conv.status", FT_UINT32, BASE_DEC, VALS(dce_error_vals), 0x0, "", HFILL }},
194         { &hf_conv_who_are_you_rqst_actuid,
195             {"hf_conv_who_are_you_rqst_actuid", "conv.who_are_you_rqst_actuid", FT_STRING, BASE_NONE, NULL, 0x0, "UUID", HFILL }},
196         { &hf_conv_who_are_you_rqst_boot_time,
197             {"hf_conv_who_are_you_rqst_boot_time", "conv.who_are_you_rqst_boot_time", FT_ABSOLUTE_TIME, BASE_NONE, NULL, 0x0, "", HFILL }},
198         { &hf_conv_who_are_you2_rqst_actuid,
199             {"hf_conv_who_are_you2_rqst_actuid", "conv.who_are_you2_rqst_actuid", FT_STRING, BASE_NONE, NULL, 0x0, "UUID", HFILL }},
200         { &hf_conv_who_are_you2_rqst_boot_time,
201             {"hf_conv_who_are_you2_rqst_boot_time", "conv.who_are_you2_rqst_boot_time", FT_ABSOLUTE_TIME, BASE_NONE, NULL, 0x0, "", HFILL }},
202         { &hf_conv_who_are_you2_resp_seq,
203             {"hf_conv_who_are_you2_resp_seq", "conv.who_are_you2_resp_seq", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
204         { &hf_conv_who_are_you2_resp_casuuid,
205             {"hf_conv_who_are_you2_resp_casuuid", "conv.who_are_you2_resp_casuuid", FT_STRING, BASE_NONE, NULL, 0x0, "UUID", HFILL }}
206         };
207
208         static gint *ett[] = {
209                 &ett_conv
210         };
211         proto_conv = proto_register_protocol ("DCE/RPC Conversation Manager", "CONV", "conv");
212         proto_register_field_array (proto_conv, hf, array_length (hf));
213         proto_register_subtree_array (ett, array_length (ett));
214 }
215
216 void
217 proto_reg_handoff_conv (void)
218 {
219         /* Register the protocol as dcerpc */
220         dcerpc_init_uuid (proto_conv, ett_conv, &uuid_conv, ver_conv, conv_dissectors, hf_conv_opnum);
221 }
222