Export "protocol_t" as an opaque type.
[obnox/wireshark/wip.git] / packet-dcerpc.h
1 /* packet-dcerpc.h
2  * Copyright 2001, Todd Sabin <tas@webspan.net>
3  * Copyright 2003, Tim Potter <tpot@samba.org>
4  *
5  * $Id: packet-dcerpc.h,v 1.37 2003/11/16 23:17:17 guy 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 #ifndef __PACKET_DCERPC_H__
27 #define __PACKET_DCERPC_H__
28
29 #include <epan/conversation.h>
30
31 typedef struct _e_uuid_t {
32     guint32 Data1;
33     guint16 Data2;
34     guint16 Data3;
35     guint8 Data4[8];
36 } e_uuid_t;
37
38 /* %08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x */
39 #define DCERPC_UUID_STR_LEN 36+1
40
41 typedef struct _e_ctx_hnd {
42     guint32 Data1;
43     e_uuid_t uuid;
44 } e_ctx_hnd;
45
46 typedef struct _e_dce_cn_common_hdr_t {
47     guint8 rpc_ver;
48     guint8 rpc_ver_minor;
49     guint8 ptype;
50     guint8 flags;
51     guint8 drep[4];
52     guint16 frag_len;
53     guint16 auth_len;
54     guint32 call_id;
55 } e_dce_cn_common_hdr_t;
56
57 typedef struct _e_dce_dg_common_hdr_t {
58     guint8 rpc_ver;
59     guint8 ptype;
60     guint8 flags1;
61     guint8 flags2;
62     guint8 drep[3];
63     guint8 serial_hi;
64     e_uuid_t obj_id;
65     e_uuid_t if_id;
66     e_uuid_t act_id;
67     guint32 server_boot;
68     guint32 if_ver;
69     guint32 seqnum;
70     guint16 opnum;
71     guint16 ihint;
72     guint16 ahint;
73     guint16 frag_len;
74     guint16 frag_num;
75     guint8 auth_proto;
76     guint8 serial_lo;
77 } e_dce_dg_common_hdr_t;
78
79 typedef struct _dcerpc_auth_info {
80   guint8 auth_pad_len;
81   guint8 auth_level;
82   guint8 auth_type;
83   guint32 auth_size;
84   tvbuff_t *auth_data;
85 } dcerpc_auth_info;
86
87 #define PDU_REQ         0
88 #define PDU_PING        1
89 #define PDU_RESP        2
90 #define PDU_FAULT       3
91 #define PDU_WORKING     4
92 #define PDU_NOCALL      5
93 #define PDU_REJECT      6
94 #define PDU_ACK         7
95 #define PDU_CL_CANCEL   8
96 #define PDU_FACK        9
97 #define PDU_CANCEL_ACK 10
98 #define PDU_BIND       11
99 #define PDU_BIND_ACK   12
100 #define PDU_BIND_NAK   13
101 #define PDU_ALTER      14
102 #define PDU_ALTER_ACK  15
103 #define PDU_AUTH3      16
104 #define PDU_SHUTDOWN   17
105 #define PDU_CO_CANCEL  18
106 #define PDU_ORPHANED   19
107
108
109 /*
110  * helpers for packet-dcerpc.c and packet-dcerpc-ndr.c
111  * If you're writing a subdissector, you almost certainly want the
112  * NDR functions below.
113  */
114 guint16 dcerpc_tvb_get_ntohs (tvbuff_t *tvb, gint offset, char *drep);
115 guint32 dcerpc_tvb_get_ntohl (tvbuff_t *tvb, gint offset, char *drep);
116 void dcerpc_tvb_get_uuid (tvbuff_t *tvb, gint offset, char *drep, e_uuid_t *uuid);
117 int dissect_dcerpc_uint8 (tvbuff_t *tvb, gint offset, packet_info *pinfo,
118                           proto_tree *tree, char *drep,
119                           int hfindex, guint8 *pdata);
120 int dissect_dcerpc_uint16 (tvbuff_t *tvb, gint offset, packet_info *pinfo,
121                            proto_tree *tree, char *drep,
122                            int hfindex, guint16 *pdata);
123 int dissect_dcerpc_uint32 (tvbuff_t *tvb, gint offset, packet_info *pinfo,
124                            proto_tree *tree, char *drep,
125                            int hfindex, guint32 *pdata);
126 int dissect_dcerpc_uint64 (tvbuff_t *tvb, gint offset, packet_info *pinfo,
127                            proto_tree *tree, char *drep,
128                            int hfindex, unsigned char *pdata);
129 int dissect_dcerpc_float  (tvbuff_t *tvb, gint offset, packet_info *pinfo,
130                            proto_tree *tree, char *drep, 
131                            int hfindex, gfloat *pdata);
132 int dissect_dcerpc_double (tvbuff_t *tvb, gint offset, packet_info *pinfo,
133                            proto_tree *tree, char *drep, 
134                            int hfindex, gdouble *pdata);
135 int dissect_dcerpc_time_t (tvbuff_t *tvb, gint offset, packet_info *pinfo,
136                            proto_tree *tree, char *drep, 
137                            int hfindex, guint32 *pdata);
138 /*
139  * NDR routines for subdissectors.
140  */
141 int dissect_ndr_uint8 (tvbuff_t *tvb, gint offset, packet_info *pinfo,
142                        proto_tree *tree, char *drep,
143                        int hfindex, guint8 *pdata);
144 int dissect_ndr_uint16 (tvbuff_t *tvb, gint offset, packet_info *pinfo,
145                         proto_tree *tree, char *drep,
146                         int hfindex, guint16 *pdata);
147 int dissect_ndr_uint32 (tvbuff_t *tvb, gint offset, packet_info *pinfo,
148                         proto_tree *tree, char *drep,
149                         int hfindex, guint32 *pdata);
150 int dissect_ndr_uint64 (tvbuff_t *tvb, gint offset, packet_info *pinfo,
151                         proto_tree *tree, char *drep,
152                         int hfindex, unsigned char *pdata);
153 int dissect_ndr_float (tvbuff_t *tvb, gint offset, packet_info *pinfo,
154                         proto_tree *tree, char *drep, 
155                         int hfindex, gfloat *pdata);
156 int dissect_ndr_double (tvbuff_t *tvb, gint offset, packet_info *pinfo,
157                         proto_tree *tree, char *drep, 
158                         int hfindex, gdouble *pdata);
159 int dissect_ndr_time_t (tvbuff_t *tvb, gint offset, packet_info *pinfo,
160                         proto_tree *tree, char *drep, 
161                         int hfindex, guint32 *pdata);
162 int dissect_ndr_uuid_t (tvbuff_t *tvb, gint offset, packet_info *pinfo,
163                         proto_tree *tree, char *drep,
164                         int hfindex, e_uuid_t *pdata);
165 int dissect_ndr_ctx_hnd (tvbuff_t *tvb, gint offset, packet_info *pinfo,
166                          proto_tree *tree, char *drep,
167                          int hfindex, e_ctx_hnd *pdata);
168
169 typedef int (dcerpc_dissect_fnct_t)(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, char *drep);
170
171 typedef void (dcerpc_callback_fnct_t)(packet_info *pinfo, proto_tree *tree, proto_item *item, tvbuff_t *tvb, int start_offset, int end_offset, void *callback_args);
172
173 #define NDR_POINTER_REF         1
174 #define NDR_POINTER_UNIQUE      2
175 #define NDR_POINTER_PTR         3
176
177 int dissect_ndr_pointer_cb(tvbuff_t *tvb, gint offset, packet_info *pinfo,
178                            proto_tree *tree, char *drep,
179                            dcerpc_dissect_fnct_t *fnct, int type, char *text, 
180                            int hf_index, dcerpc_callback_fnct_t *callback,
181                            void *callback_args);
182
183 int dissect_ndr_pointer(tvbuff_t *tvb, gint offset, packet_info *pinfo,
184                         proto_tree *tree, char *drep,
185                         dcerpc_dissect_fnct_t *fnct, int type, char *text, 
186                         int hf_index);
187
188 /* dissect a NDR unidimensional conformant array */
189 int dissect_ndr_ucarray(tvbuff_t *tvb, gint offset, packet_info *pinfo,
190                         proto_tree *tree, char *drep,
191                         dcerpc_dissect_fnct_t *fnct);
192
193 /* dissect a NDR unidimensional conformant and varying array */
194 int dissect_ndr_ucvarray(tvbuff_t *tvb, gint offset, packet_info *pinfo,
195                         proto_tree *tree, char *drep,
196                         dcerpc_dissect_fnct_t *fnct);
197
198 int dissect_ndr_byte_array(tvbuff_t *tvb, int offset, packet_info *pinfo, 
199                            proto_tree *tree, char *drep);
200
201 int dissect_ndr_cvstring(tvbuff_t *tvb, int offset, packet_info *pinfo, 
202                          proto_tree *tree, char *drep, int size_is,
203                          int hfinfo, gboolean add_subtree,
204                          char **data);
205 int dissect_ndr_char_cvstring(tvbuff_t *tvb, int offset, packet_info *pinfo, 
206                            proto_tree *tree, char *drep);
207 int dissect_ndr_wchar_cvstring(tvbuff_t *tvb, int offset, packet_info *pinfo, 
208                             proto_tree *tree, char *drep);
209
210 typedef struct _dcerpc_sub_dissector {
211     guint16 num;
212     gchar   *name;
213     dcerpc_dissect_fnct_t *dissect_rqst;
214     dcerpc_dissect_fnct_t *dissect_resp;
215 } dcerpc_sub_dissector;
216
217 /* registration function for subdissectors */
218 void dcerpc_init_uuid (int proto, int ett, e_uuid_t *uuid, guint16 ver, dcerpc_sub_dissector *procs, int opnum_hf);
219 char *dcerpc_get_proto_name(e_uuid_t *uuid, guint16 ver);
220 int dcerpc_get_proto_hf_opnum(e_uuid_t *uuid, guint16 ver);
221 dcerpc_sub_dissector *dcerpc_get_proto_sub_dissector(e_uuid_t *uuid, guint16 ver);
222
223 /* Create a opnum, name value_string from a subdissector list */
224
225 value_string *value_string_from_subdissectors(dcerpc_sub_dissector *sd);
226
227 /* Private data structure to pass to DCERPC dissector. This is used to
228    pass transport specific information down to the dissector from the
229    dissector that parsed this encapsulated calls. */
230
231 #define DCERPC_TRANSPORT_SMB  1
232
233 typedef struct _dcerpc_private_info {
234     int transport_type;         /* Tag */
235
236     union {
237         struct {                /* DCERPC_TRANSPORT_SMB */
238             guint16 fid;
239         } smb;
240     } data;
241 } dcerpc_private_info;
242
243 /* Private data passed to subdissectors from the main DCERPC dissector. */
244 typedef struct _dcerpc_call_value {
245     e_uuid_t uuid;
246     guint16 ver;
247     guint16 opnum;
248     guint32 req_frame;
249     nstime_t req_time;
250     guint32 rep_frame;
251     guint32 max_ptr;
252     void *private_data;
253 } dcerpc_call_value;
254
255 typedef struct _dcerpc_info {
256         conversation_t *conv;   /* Which TCP stream we are in */
257         guint32 call_id;        /* Context id for this call */
258         guint16 smb_fid;        /* FID for DCERPC over SMB */
259         gboolean request;
260         gboolean conformant_run;
261         gint32 conformant_eaten; /* how many bytes did the conformant run eat?*/
262         guint32 array_max_count;        /* max_count for conformant arrays */
263         guint32 array_max_count_offset;
264         guint32 array_offset;
265         guint32 array_offset_offset;
266         guint32 array_actual_count;
267         guint32 array_actual_count_offset;
268         int hf_index;
269         dcerpc_call_value *call_data;
270         void *private_data;
271 } dcerpc_info;
272
273
274 /* the registered subdissectors */
275 extern GHashTable *dcerpc_uuids;
276
277 typedef struct _dcerpc_uuid_key {
278     e_uuid_t uuid;
279     guint16 ver;
280 } dcerpc_uuid_key;
281
282 typedef struct _dcerpc_uuid_value {
283     protocol_t *proto;
284     int proto_id;
285     int ett;
286     gchar *name;
287     dcerpc_sub_dissector *procs;
288     int opnum_hf;
289 } dcerpc_uuid_value;
290
291 /* Authenticated pipe registration functions and miscellanea */
292
293 typedef tvbuff_t *(dcerpc_decode_data_fnct_t)(tvbuff_t *tvb, int offset, 
294                                               packet_info *pinfo,
295                                               dcerpc_auth_info *auth_info);
296
297 typedef struct _dcerpc_auth_subdissector_fns {
298
299         /* Dissect credentials and verifiers */
300
301         dcerpc_dissect_fnct_t *bind_fn;
302         dcerpc_dissect_fnct_t *bind_ack_fn;
303         dcerpc_dissect_fnct_t *auth3_fn;
304         dcerpc_dissect_fnct_t *req_verf_fn;
305         dcerpc_dissect_fnct_t *resp_verf_fn;
306
307         /* Decrypt encrypted requests/response PDUs */
308
309         dcerpc_decode_data_fnct_t *req_data_fn;
310         dcerpc_decode_data_fnct_t *resp_data_fn;
311
312 } dcerpc_auth_subdissector_fns;
313
314 void register_dcerpc_auth_subdissector(guint8 auth_level, guint8 auth_type,
315                                        dcerpc_auth_subdissector_fns *fns);
316
317 /* Authentication services */
318
319 #define DCE_C_RPC_AUTHN_PROTOCOL_NONE           0
320 #define DCE_C_RPC_AUTHN_PROTOCOL_KRB5           1
321 #define DCE_C_RPC_AUTHN_PROTOCOL_SPNEGO         9
322 #define DCE_C_RPC_AUTHN_PROTOCOL_NTLMSSP        10
323 #define DCE_C_RPC_AUTHN_PROTOCOL_SEC_CHAN       68
324
325 /* Protection levels */
326
327 #define DCE_C_AUTHN_LEVEL_NONE          1
328 #define DCE_C_AUTHN_LEVEL_CONNECT       2
329 #define DCE_C_AUTHN_LEVEL_CALL          3
330 #define DCE_C_AUTHN_LEVEL_PKT           4
331 #define DCE_C_AUTHN_LEVEL_PKT_INTEGRITY 5
332 #define DCE_C_AUTHN_LEVEL_PKT_PRIVACY   6
333
334 #endif /* packet-dcerpc.h */