2 * Routines for DCERPC packet disassembly
3 * Copyright 2001, Todd Sabin <tas@webspan.net>
5 * $Id: packet-dcerpc.c,v 1.72 2002/08/21 21:25:23 tpot Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@ethereal.com>
9 * Copyright 1998 Gerald Combs
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.
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.
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.
34 #include <epan/packet.h>
35 #include "packet-dcerpc.h"
36 #include <epan/conversation.h>
38 #include "reassemble.h"
40 static const value_string pckt_vals[] = {
41 { PDU_REQ, "Request"},
43 { PDU_RESP, "Response"},
44 { PDU_FAULT, "Fault"},
45 { PDU_WORKING, "Working"},
46 { PDU_NOCALL, "Nocall"},
47 { PDU_REJECT, "Reject"},
49 { PDU_CL_CANCEL, "Cl_cancel"},
51 { PDU_CANCEL_ACK, "Cancel_ack"},
53 { PDU_BIND_ACK, "Bind_ack"},
54 { PDU_BIND_NAK, "Bind_nak"},
55 { PDU_ALTER, "Alter_context"},
56 { PDU_ALTER_ACK, "Alter_context_resp"},
57 { PDU_AUTH3, "AUTH3?"},
58 { PDU_SHUTDOWN, "Shutdown"},
59 { PDU_CO_CANCEL, "Co_cancel"},
60 { PDU_ORPHANED, "Orphaned"},
64 static const value_string drep_byteorder_vals[] = {
66 { 1, "Little-endian" },
70 static const value_string drep_character_vals[] = {
76 static const value_string drep_fp_vals[] = {
85 * Authentication services.
87 #define DCE_C_RPC_AUTHN_PROTOCOL_NONE 0
88 #define DCE_C_RPC_AUTHN_PROTOCOL_KRB5 1
89 #define DCE_C_RPC_AUTHN_PROTOCOL_SNEGO 9
90 #define DCE_C_RPC_AUTHN_PROTOCOL_NTLMSSP 10
92 static const value_string authn_protocol_vals[] = {
93 { DCE_C_RPC_AUTHN_PROTOCOL_NONE, "None" },
94 { DCE_C_RPC_AUTHN_PROTOCOL_KRB5, "Kerberos 5" },
95 { DCE_C_RPC_AUTHN_PROTOCOL_SNEGO, "Snego" },
96 { DCE_C_RPC_AUTHN_PROTOCOL_NTLMSSP, "NTLMSSP" },
103 #define DCE_C_AUTHN_LEVEL_NONE 1
104 #define DCE_C_AUTHN_LEVEL_CONNECT 2
105 #define DCE_C_AUTHN_LEVEL_CALL 3
106 #define DCE_C_AUTHN_LEVEL_PKT 4
107 #define DCE_C_AUTHN_LEVEL_PKT_INTEGRITY 5
108 #define DCE_C_AUTHN_LEVEL_PKT_PRIVACY 6
110 static const value_string authn_level_vals[] = {
111 { DCE_C_AUTHN_LEVEL_NONE, "None" },
112 { DCE_C_AUTHN_LEVEL_CONNECT, "Connect" },
113 { DCE_C_AUTHN_LEVEL_CALL, "Call" },
114 { DCE_C_AUTHN_LEVEL_PKT, "Packet" },
115 { DCE_C_AUTHN_LEVEL_PKT_INTEGRITY, "Packet integrity" },
116 { DCE_C_AUTHN_LEVEL_PKT_PRIVACY, "Packet privacy" },
121 * Flag bits in first flag field in connectionless PDU header.
123 #define PFCL1_RESERVED_01 0x01 /* Reserved for use by implementations */
124 #define PFCL1_LASTFRAG 0x02 /* If set, the PDU is the last
125 * fragment of a multi-PDU
127 #define PFCL1_FRAG 0x04 /* If set, the PDU is a fragment of
128 a multi-PDU transmission */
129 #define PFCL1_NOFACK 0x08 /* If set, the receiver is not
130 * requested to send a `fack' PDU
131 * for the fragment */
132 #define PFCL1_MAYBE 0x10 /* If set, the PDU is for a `maybe'
134 #define PFCL1_IDEMPOTENT 0x20 /* If set, the PDU is for an idempotent
136 #define PFCL1_BROADCAST 0x40 /* If set, the PDU is for a broadcast
138 #define PFCL1_RESERVED_80 0x80 /* Reserved for use by implementations */
141 * Flag bits in second flag field in connectionless PDU header.
143 #define PFCL2_RESERVED_01 0x01 /* Reserved for use by implementations */
144 #define PFCL2_CANCEL_PENDING 0x02 /* Cancel pending at the call end */
145 #define PFCL2_RESERVED_04 0x04 /* Reserved for future use */
146 #define PFCL2_RESERVED_08 0x08 /* Reserved for future use */
147 #define PFCL2_RESERVED_10 0x10 /* Reserved for future use */
148 #define PFCL2_RESERVED_20 0x20 /* Reserved for future use */
149 #define PFCL2_RESERVED_40 0x40 /* Reserved for future use */
150 #define PFCL2_RESERVED_80 0x80 /* Reserved for future use */
153 * Flag bits in connection-oriented PDU header.
155 #define PFC_FIRST_FRAG 0x01 /* First fragment */
156 #define PFC_LAST_FRAG 0x02 /* Last fragment */
157 #define PFC_PENDING_CANCEL 0x04 /* Cancel was pending at sender */
158 #define PFC_RESERVED_1 0x08
159 #define PFC_CONC_MPX 0x10 /* suports concurrent multiplexing
160 * of a single connection. */
161 #define PFC_DID_NOT_EXECUTE 0x20 /* only meaningful on `fault' packet;
162 * if true, guaranteed call did not
164 #define PFC_MAYBE 0x40 /* `maybe' call semantics requested */
165 #define PFC_OBJECT_UUID 0x80 /* if true, a non-nil object UUID
166 * was specified in the handle, and
167 * is present in the optional object
168 * field. If false, the object field
172 * Tests whether a connection-oriented PDU is fragmented; returns TRUE if
173 * it's not fragmented (i.e., this is both the first *and* last fragment),
174 * and FALSE otherwise.
176 #define PFC_NOT_FRAGMENTED(hdr) \
177 ((hdr->flags&(PFC_FIRST_FRAG|PFC_LAST_FRAG))==(PFC_FIRST_FRAG|PFC_LAST_FRAG))
180 * Presentation context negotiation result.
182 static const value_string p_cont_result_vals[] = {
184 { 1, "User rejection" },
185 { 2, "Provider rejection" },
190 * Presentation context negotiation rejection reasons.
192 static const value_string p_provider_reason_vals[] = {
193 { 0, "Reason not specified" },
194 { 1, "Abstract syntax not supported" },
195 { 2, "Proposed transfer syntaxes not supported" },
196 { 3, "Local limit exceeded" },
203 #define REASON_NOT_SPECIFIED 0
204 #define TEMPORARY_CONGESTION 1
205 #define LOCAL_LIMIT_EXCEEDED 2
206 #define CALLED_PADDR_UNKNOWN 3 /* not used */
207 #define PROTOCOL_VERSION_NOT_SUPPORTED 4
208 #define DEFAULT_CONTEXT_NOT_SUPPORTED 5 /* not used */
209 #define USER_DATA_NOT_READABLE 6 /* not used */
210 #define NO_PSAP_AVAILABLE 7 /* not used */
212 static const value_string reject_reason_vals[] = {
213 { REASON_NOT_SPECIFIED, "Reason not specified" },
214 { TEMPORARY_CONGESTION, "Temporary congestion" },
215 { LOCAL_LIMIT_EXCEEDED, "Local limit exceeded" },
216 { CALLED_PADDR_UNKNOWN, "Called paddr unknown" },
217 { PROTOCOL_VERSION_NOT_SUPPORTED, "Protocol version not supported" },
218 { DEFAULT_CONTEXT_NOT_SUPPORTED, "Default context not supported" },
219 { USER_DATA_NOT_READABLE, "User data not readable" },
220 { NO_PSAP_AVAILABLE, "No PSAP available" },
225 * Reject status codes.
227 static const value_string reject_status_vals[] = {
228 { 0, "Stub-defined exception" },
229 { 0x1c000001, "nca_s_fault_int_div_by_zero" },
230 { 0x1c000002, "nca_s_fault_addr_error" },
231 { 0x1c000003, "nca_s_fault_fp_div_zero" },
232 { 0x1c000004, "nca_s_fault_fp_underflow" },
233 { 0x1c000005, "nca_s_fault_fp_overflow" },
234 { 0x1c000006, "nca_s_fault_invalid_tag" },
235 { 0x1c000007, "nca_s_fault_invalid_bound" },
236 { 0x1c000008, "nca_rpc_version_mismatch" },
237 { 0x1c000009, "nca_unspec_reject" },
238 { 0x1c00000a, "nca_s_bad_actid" },
239 { 0x1c00000b, "nca_who_are_you_failed" },
240 { 0x1c00000c, "nca_manager_not_entered" },
241 { 0x1c00000d, "nca_s_fault_cancel" },
242 { 0x1c00000e, "nca_s_fault_ill_inst" },
243 { 0x1c00000f, "nca_s_fault_fp_error" },
244 { 0x1c000010, "nca_s_fault_int_overflow" },
245 { 0x1c000014, "nca_s_fault_pipe_empty" },
246 { 0x1c000015, "nca_s_fault_pipe_closed" },
247 { 0x1c000016, "nca_s_fault_pipe_order" },
248 { 0x1c000017, "nca_s_fault_pipe_discipline" },
249 { 0x1c000018, "nca_s_fault_pipe_comm_error" },
250 { 0x1c000019, "nca_s_fault_pipe_memory" },
251 { 0x1c00001a, "nca_s_fault_context_mismatch" },
252 { 0x1c00001b, "nca_s_fault_remote_no_memory" },
253 { 0x1c00001c, "nca_invalid_pres_context_id" },
254 { 0x1c00001d, "nca_unsupported_authn_level" },
255 { 0x1c00001f, "nca_invalid_checksum" },
256 { 0x1c000020, "nca_invalid_crc" },
257 { 0x1c000021, "ncs_s_fault_user_defined" },
258 { 0x1c000022, "nca_s_fault_tx_open_failed" },
259 { 0x1c000023, "nca_s_fault_codeset_conv_error" },
260 { 0x1c000024, "nca_s_fault_object_not_found" },
261 { 0x1c000025, "nca_s_fault_no_client_stub" },
262 { 0x1c010002, "nca_op_rng_error" },
263 { 0x1c010003, "nca_unk_if"},
264 { 0x1c010006, "nca_wrong_boot_time" },
265 { 0x1c010009, "nca_s_you_crashed" },
266 { 0x1c01000b, "nca_proto_error" },
267 { 0x1c010013, "nca_out_args_too_big" },
268 { 0x1c010014, "nca_server_too_busy" },
269 { 0x1c010017, "nca_unsupported_type" },
273 static int proto_dcerpc = -1;
276 static int hf_dcerpc_request_in = -1;
277 static int hf_dcerpc_response_in = -1;
278 static int hf_dcerpc_ver = -1;
279 static int hf_dcerpc_ver_minor = -1;
280 static int hf_dcerpc_packet_type = -1;
281 static int hf_dcerpc_cn_flags = -1;
282 static int hf_dcerpc_cn_flags_first_frag = -1;
283 static int hf_dcerpc_cn_flags_last_frag = -1;
284 static int hf_dcerpc_cn_flags_cancel_pending = -1;
285 static int hf_dcerpc_cn_flags_reserved = -1;
286 static int hf_dcerpc_cn_flags_mpx = -1;
287 static int hf_dcerpc_cn_flags_dne = -1;
288 static int hf_dcerpc_cn_flags_maybe = -1;
289 static int hf_dcerpc_cn_flags_object = -1;
290 static int hf_dcerpc_drep = -1;
291 static int hf_dcerpc_drep_byteorder = -1;
292 static int hf_dcerpc_drep_character = -1;
293 static int hf_dcerpc_drep_fp = -1;
294 static int hf_dcerpc_cn_frag_len = -1;
295 static int hf_dcerpc_cn_auth_len = -1;
296 static int hf_dcerpc_cn_call_id = -1;
297 static int hf_dcerpc_cn_max_xmit = -1;
298 static int hf_dcerpc_cn_max_recv = -1;
299 static int hf_dcerpc_cn_assoc_group = -1;
300 static int hf_dcerpc_cn_num_ctx_items = -1;
301 static int hf_dcerpc_cn_ctx_id = -1;
302 static int hf_dcerpc_cn_num_trans_items = -1;
303 static int hf_dcerpc_cn_bind_if_id = -1;
304 static int hf_dcerpc_cn_bind_if_ver = -1;
305 static int hf_dcerpc_cn_bind_if_ver_minor = -1;
306 static int hf_dcerpc_cn_bind_trans_id = -1;
307 static int hf_dcerpc_cn_bind_trans_ver = -1;
308 static int hf_dcerpc_cn_alloc_hint = -1;
309 static int hf_dcerpc_cn_sec_addr_len = -1;
310 static int hf_dcerpc_cn_sec_addr = -1;
311 static int hf_dcerpc_cn_num_results = -1;
312 static int hf_dcerpc_cn_ack_result = -1;
313 static int hf_dcerpc_cn_ack_reason = -1;
314 static int hf_dcerpc_cn_ack_trans_id = -1;
315 static int hf_dcerpc_cn_ack_trans_ver = -1;
316 static int hf_dcerpc_cn_reject_reason = -1;
317 static int hf_dcerpc_cn_num_protocols = -1;
318 static int hf_dcerpc_cn_protocol_ver_major = -1;
319 static int hf_dcerpc_cn_protocol_ver_minor = -1;
320 static int hf_dcerpc_cn_cancel_count = -1;
321 static int hf_dcerpc_cn_status = -1;
322 static int hf_dcerpc_auth_type = -1;
323 static int hf_dcerpc_auth_level = -1;
324 static int hf_dcerpc_auth_pad_len = -1;
325 static int hf_dcerpc_auth_rsrvd = -1;
326 static int hf_dcerpc_auth_ctx_id = -1;
327 static int hf_dcerpc_dg_flags1 = -1;
328 static int hf_dcerpc_dg_flags1_rsrvd_01 = -1;
329 static int hf_dcerpc_dg_flags1_last_frag = -1;
330 static int hf_dcerpc_dg_flags1_frag = -1;
331 static int hf_dcerpc_dg_flags1_nofack = -1;
332 static int hf_dcerpc_dg_flags1_maybe = -1;
333 static int hf_dcerpc_dg_flags1_idempotent = -1;
334 static int hf_dcerpc_dg_flags1_broadcast = -1;
335 static int hf_dcerpc_dg_flags1_rsrvd_80 = -1;
336 static int hf_dcerpc_dg_flags2 = -1;
337 static int hf_dcerpc_dg_flags2_rsrvd_01 = -1;
338 static int hf_dcerpc_dg_flags2_cancel_pending = -1;
339 static int hf_dcerpc_dg_flags2_rsrvd_04 = -1;
340 static int hf_dcerpc_dg_flags2_rsrvd_08 = -1;
341 static int hf_dcerpc_dg_flags2_rsrvd_10 = -1;
342 static int hf_dcerpc_dg_flags2_rsrvd_20 = -1;
343 static int hf_dcerpc_dg_flags2_rsrvd_40 = -1;
344 static int hf_dcerpc_dg_flags2_rsrvd_80 = -1;
345 static int hf_dcerpc_dg_serial_hi = -1;
346 static int hf_dcerpc_obj_id = -1;
347 static int hf_dcerpc_dg_if_id = -1;
348 static int hf_dcerpc_dg_act_id = -1;
349 static int hf_dcerpc_dg_serial_lo = -1;
350 static int hf_dcerpc_dg_ahint = -1;
351 static int hf_dcerpc_dg_ihint = -1;
352 static int hf_dcerpc_dg_frag_len = -1;
353 static int hf_dcerpc_dg_frag_num = -1;
354 static int hf_dcerpc_dg_auth_proto = -1;
355 static int hf_dcerpc_opnum = -1;
356 static int hf_dcerpc_dg_seqnum = -1;
357 static int hf_dcerpc_dg_server_boot = -1;
358 static int hf_dcerpc_dg_if_ver = -1;
359 static int hf_dcerpc_dg_cancel_vers = -1;
360 static int hf_dcerpc_dg_cancel_id = -1;
361 static int hf_dcerpc_dg_server_accepting_cancels = -1;
362 static int hf_dcerpc_dg_fack_vers = -1;
363 static int hf_dcerpc_dg_fack_window_size = -1;
364 static int hf_dcerpc_dg_fack_max_tsdu = -1;
365 static int hf_dcerpc_dg_fack_max_frag_size = -1;
366 static int hf_dcerpc_dg_fack_serial_num = -1;
367 static int hf_dcerpc_dg_fack_selack_len = -1;
368 static int hf_dcerpc_dg_fack_selack = -1;
369 static int hf_dcerpc_dg_status = -1;
370 static int hf_dcerpc_array_max_count = -1;
371 static int hf_dcerpc_array_offset = -1;
372 static int hf_dcerpc_array_actual_count = -1;
373 static int hf_dcerpc_op = -1;
374 static int hf_dcerpc_referent_id = -1;
375 static int hf_dcerpc_fragments = -1;
376 static int hf_dcerpc_fragment = -1;
377 static int hf_dcerpc_fragment_overlap = -1;
378 static int hf_dcerpc_fragment_overlap_conflict = -1;
379 static int hf_dcerpc_fragment_multiple_tails = -1;
380 static int hf_dcerpc_fragment_too_long_fragment = -1;
381 static int hf_dcerpc_fragment_error = -1;
383 static gint ett_dcerpc = -1;
384 static gint ett_dcerpc_cn_flags = -1;
385 static gint ett_dcerpc_drep = -1;
386 static gint ett_dcerpc_dg_flags1 = -1;
387 static gint ett_dcerpc_dg_flags2 = -1;
388 static gint ett_dcerpc_pointer_data = -1;
389 static gint ett_dcerpc_fragments = -1;
390 static gint ett_dcerpc_fragment = -1;
392 static dissector_handle_t ntlmssp_handle=NULL;
394 fragment_items dcerpc_frag_items = {
395 &ett_dcerpc_fragments,
396 &ett_dcerpc_fragment,
398 &hf_dcerpc_fragments,
400 &hf_dcerpc_fragment_overlap,
401 &hf_dcerpc_fragment_overlap_conflict,
402 &hf_dcerpc_fragment_multiple_tails,
403 &hf_dcerpc_fragment_too_long_fragment,
404 &hf_dcerpc_fragment_error,
409 /* try to desegment big DCE/RPC packets over TCP? */
410 static gboolean dcerpc_cn_desegment = TRUE;
412 /* reassemble DCE/RPC fragments */
413 /* reassembly of dcerpc fragments will not work for the case where ONE frame
414 might contain multiple dcerpc fragments for different PDUs.
415 this case would be so unusual/weird so if you got captures like that:
418 static gboolean dcerpc_reassemble = FALSE;
419 static GHashTable *dcerpc_co_reassemble_table = NULL;
420 static GHashTable *dcerpc_cl_reassemble_table = NULL;
423 dcerpc_reassemble_init(void)
425 fragment_table_init(&dcerpc_co_reassemble_table);
426 fragment_table_init(&dcerpc_cl_reassemble_table);
433 /* the registered subdissectors */
434 static GHashTable *dcerpc_uuids;
436 typedef struct _dcerpc_uuid_key {
441 typedef struct _dcerpc_uuid_value {
445 dcerpc_sub_dissector *procs;
450 dcerpc_uuid_equal (gconstpointer k1, gconstpointer k2)
452 dcerpc_uuid_key *key1 = (dcerpc_uuid_key *)k1;
453 dcerpc_uuid_key *key2 = (dcerpc_uuid_key *)k2;
454 return ((memcmp (&key1->uuid, &key2->uuid, sizeof (e_uuid_t)) == 0)
455 && (key1->ver == key2->ver));
459 dcerpc_uuid_hash (gconstpointer k)
461 dcerpc_uuid_key *key = (dcerpc_uuid_key *)k;
462 /* This isn't perfect, but the Data1 part of these is almost always
464 return key->uuid.Data1;
468 dcerpc_init_uuid (int proto, int ett, e_uuid_t *uuid, guint16 ver,
469 dcerpc_sub_dissector *procs, int opnum_hf)
471 dcerpc_uuid_key *key = g_malloc (sizeof (*key));
472 dcerpc_uuid_value *value = g_malloc (sizeof (*value));
477 value->proto = proto;
479 value->name = proto_get_protocol_short_name (proto);
480 value->procs = procs;
481 value->opnum_hf = opnum_hf;
483 g_hash_table_insert (dcerpc_uuids, key, value);
488 * To keep track of ctx_id mappings.
490 * Everytime we see a bind call we update this table.
491 * Note that we always specify a SMB FID. For non-SMB transports this
494 static GHashTable *dcerpc_binds=NULL;
496 typedef struct _dcerpc_bind_key {
497 conversation_t *conv;
502 typedef struct _dcerpc_bind_value {
507 static GMemChunk *dcerpc_bind_key_chunk=NULL;
508 static GMemChunk *dcerpc_bind_value_chunk=NULL;
511 dcerpc_bind_equal (gconstpointer k1, gconstpointer k2)
513 dcerpc_bind_key *key1 = (dcerpc_bind_key *)k1;
514 dcerpc_bind_key *key2 = (dcerpc_bind_key *)k2;
515 return (key1->conv == key2->conv
516 && key1->ctx_id == key2->ctx_id
517 && key1->smb_fid == key2->smb_fid);
521 dcerpc_bind_hash (gconstpointer k)
523 dcerpc_bind_key *key = (dcerpc_bind_key *)k;
524 return ((guint)key->conv) + key->ctx_id + key->smb_fid;
528 * To keep track of callid mappings. Should really use some generic
529 * conversation support instead.
531 static GHashTable *dcerpc_calls=NULL;
533 typedef struct _dcerpc_call_key {
534 conversation_t *conv;
539 static GMemChunk *dcerpc_call_key_chunk=NULL;
541 static GMemChunk *dcerpc_call_value_chunk=NULL;
544 dcerpc_call_equal (gconstpointer k1, gconstpointer k2)
546 dcerpc_call_key *key1 = (dcerpc_call_key *)k1;
547 dcerpc_call_key *key2 = (dcerpc_call_key *)k2;
548 return (key1->conv == key2->conv
549 && key1->call_id == key2->call_id
550 && key1->smb_fid == key2->smb_fid);
554 dcerpc_call_hash (gconstpointer k)
556 dcerpc_call_key *key = (dcerpc_call_key *)k;
557 return ((guint32)key->conv) + key->call_id + key->smb_fid;
561 /* to keep track of matched calls/responses
562 this one uses the same value struct as calls, but the key is the frame id
564 static GHashTable *dcerpc_matched=NULL;
566 dcerpc_matched_equal (gconstpointer k1, gconstpointer k2)
568 return (guint32)k1 == (guint32)k2;
572 dcerpc_matched_hash (gconstpointer k)
580 * Utility functions. Modeled after packet-rpc.c
584 dissect_dcerpc_uint8 (tvbuff_t *tvb, gint offset, packet_info *pinfo _U_,
585 proto_tree *tree, char *drep,
586 int hfindex, guint8 *pdata)
590 data = tvb_get_guint8 (tvb, offset);
592 proto_tree_add_item (tree, hfindex, tvb, offset, 1, (drep[0] & 0x10));
600 dissect_dcerpc_uint16 (tvbuff_t *tvb, gint offset, packet_info *pinfo _U_,
601 proto_tree *tree, char *drep,
602 int hfindex, guint16 *pdata)
606 data = ((drep[0] & 0x10)
607 ? tvb_get_letohs (tvb, offset)
608 : tvb_get_ntohs (tvb, offset));
611 proto_tree_add_item (tree, hfindex, tvb, offset, 2, (drep[0] & 0x10));
619 dissect_dcerpc_uint32 (tvbuff_t *tvb, gint offset, packet_info *pinfo _U_,
620 proto_tree *tree, char *drep,
621 int hfindex, guint32 *pdata)
625 data = ((drep[0] & 0x10)
626 ? tvb_get_letohl (tvb, offset)
627 : tvb_get_ntohl (tvb, offset));
630 proto_tree_add_item (tree, hfindex, tvb, offset, 4, (drep[0] & 0x10));
638 dissect_dcerpc_uint64 (tvbuff_t *tvb, gint offset, packet_info *pinfo _U_,
639 proto_tree *tree, char *drep,
640 int hfindex, unsigned char *pdata)
643 tvb_memcpy(tvb, pdata, offset, 8);
644 if(drep[0] & 0x10){/* XXX this might be the wrong way around */
646 data=pdata[0];pdata[0]=pdata[7];pdata[7]=data;
647 data=pdata[1];pdata[1]=pdata[6];pdata[6]=data;
648 data=pdata[2];pdata[2]=pdata[5];pdata[5]=data;
649 data=pdata[3];pdata[3]=pdata[4];pdata[4]=data;
654 proto_tree_add_item(tree, hfindex, tvb, offset, 8, (drep[0] & 0x10));
661 * a couple simpler things
664 dcerpc_tvb_get_ntohs (tvbuff_t *tvb, gint offset, char *drep)
666 if (drep[0] & 0x10) {
667 return tvb_get_letohs (tvb, offset);
669 return tvb_get_ntohs (tvb, offset);
674 dcerpc_tvb_get_ntohl (tvbuff_t *tvb, gint offset, char *drep)
676 if (drep[0] & 0x10) {
677 return tvb_get_letohl (tvb, offset);
679 return tvb_get_ntohl (tvb, offset);
684 dcerpc_tvb_get_uuid (tvbuff_t *tvb, gint offset, char *drep, e_uuid_t *uuid)
687 uuid->Data1 = dcerpc_tvb_get_ntohl (tvb, offset, drep);
688 uuid->Data2 = dcerpc_tvb_get_ntohs (tvb, offset+4, drep);
689 uuid->Data3 = dcerpc_tvb_get_ntohs (tvb, offset+6, drep);
691 for (i=0; i<sizeof (uuid->Data4); i++) {
692 uuid->Data4[i] = tvb_get_guint8 (tvb, offset+8+i);
699 /* function to dissect a unidimensional conformant array */
701 dissect_ndr_ucarray(tvbuff_t *tvb, gint offset, packet_info *pinfo,
702 proto_tree *tree, char *drep,
703 dcerpc_dissect_fnct_t *fnct)
709 di=pinfo->private_data;
710 if(di->conformant_run){
711 /* conformant run, just dissect the max_count header */
713 di->conformant_run=0;
714 offset = dissect_ndr_uint32 (tvb, offset, pinfo, tree, drep,
715 hf_dcerpc_array_max_count, &di->array_max_count);
716 di->array_max_count_offset=offset-4;
717 di->conformant_run=1;
718 di->conformant_eaten=offset-old_offset;
720 /* we dont dont remember where in the bytestream this fields was */
721 proto_tree_add_uint(tree, hf_dcerpc_array_max_count, tvb, di->array_max_count_offset, 4, di->array_max_count);
723 /* real run, dissect the elements */
724 for(i=0;i<di->array_max_count;i++){
725 offset = (*fnct)(tvb, offset, pinfo, tree, drep);
731 /* function to dissect a unidimensional conformant and varying array */
733 dissect_ndr_ucvarray(tvbuff_t *tvb, gint offset, packet_info *pinfo,
734 proto_tree *tree, char *drep,
735 dcerpc_dissect_fnct_t *fnct)
741 di=pinfo->private_data;
742 if(di->conformant_run){
743 /* conformant run, just dissect the max_count header */
745 di->conformant_run=0;
746 offset = dissect_ndr_uint32 (tvb, offset, pinfo, tree, drep,
747 hf_dcerpc_array_max_count, &di->array_max_count);
748 di->array_max_count_offset=offset-4;
749 offset = dissect_ndr_uint32 (tvb, offset, pinfo, tree, drep,
750 hf_dcerpc_array_offset, &di->array_offset);
751 di->array_offset_offset=offset-4;
752 offset = dissect_ndr_uint32 (tvb, offset, pinfo, tree, drep,
753 hf_dcerpc_array_actual_count, &di->array_actual_count);
754 di->array_actual_count_offset=offset-4;
755 di->conformant_run=1;
756 di->conformant_eaten=offset-old_offset;
758 /* we dont dont remember where in the bytestream these fields were */
759 proto_tree_add_uint(tree, hf_dcerpc_array_max_count, tvb, di->array_max_count_offset, 4, di->array_max_count);
760 proto_tree_add_uint(tree, hf_dcerpc_array_offset, tvb, di->array_offset_offset, 4, di->array_offset);
761 proto_tree_add_uint(tree, hf_dcerpc_array_actual_count, tvb, di->array_actual_count_offset, 4, di->array_actual_count);
763 /* real run, dissect the elements */
764 for(i=0;i<di->array_actual_count;i++){
765 offset = (*fnct)(tvb, offset, pinfo, tree, drep);
773 /* ndr pointer handling */
774 /* list of pointers encountered so far */
775 static GSList *ndr_pointer_list = NULL;
777 /* position where in the list to insert newly encountered pointers */
778 static int ndr_pointer_list_pos=0;
780 /* boolean controlling whether pointers are top-level or embedded */
781 static gboolean pointers_are_top_level = TRUE;
783 /* as a kludge, we represent all embedded reference pointers as id==-1
784 hoping that his will not collide with any non-ref pointers */
785 typedef struct ndr_pointer_data {
788 dcerpc_dissect_fnct_t *fnct; /*if non-NULL, we have not called it yet*/
791 } ndr_pointer_data_t;
794 init_ndr_pointer_list(packet_info *pinfo)
798 di=pinfo->private_data;
799 di->conformant_run=0;
801 while(ndr_pointer_list){
802 ndr_pointer_data_t *npd;
804 npd=g_slist_nth_data(ndr_pointer_list, 0);
805 ndr_pointer_list=g_slist_remove(ndr_pointer_list, npd);
811 ndr_pointer_list=NULL;
812 ndr_pointer_list_pos=0;
813 pointers_are_top_level=TRUE;
817 dissect_deferred_pointers(packet_info *pinfo, tvbuff_t *tvb, int offset, char *drep)
819 int found_new_pointer;
823 di=pinfo->private_data;
828 len=g_slist_length(ndr_pointer_list);
830 ndr_pointer_data_t *tnpd;
831 tnpd=g_slist_nth_data(ndr_pointer_list, i);
833 dcerpc_dissect_fnct_t *fnct;
838 ndr_pointer_list_pos=i+1;
839 di->hf_index=tnpd->hf_index;
840 di->levels=tnpd->levels;
841 /* first a run to handle any conformant
843 di->conformant_run=1;
844 di->conformant_eaten=0;
846 offset = (*(fnct))(tvb, offset, pinfo, NULL, drep);
848 g_assert((offset-old_offset)==di->conformant_eaten);
849 /* This is to check for any bugs in the dissectors.
851 * Basically, the NDR representation will store all
852 * arrays in two blocks, one block with the dimension
853 * discreption, like size, number of elements and such,
854 * and another block that contains the actual data stored
856 * If the array is embedded directly inside another,
857 * encapsulating aggregate type, like a union or struct,
858 * then these two blocks will be stored at different places
859 * in the bytestream, with other data between the blocks.
861 * For this reason, all pointers to types (both aggregate
862 * and scalar, for simplicity no distinction is made)
863 * will have its dissector called twice.
864 * The dissector will first be called with conformant_run==1
865 * in which mode the dissector MUST NOT consume any data from
866 * the tvbuff (i.e. may not dissect anything) except the
867 * initial control block for arrays.
868 * The second time the dissector is called, with
869 * conformant_run==0, all other data for the type will be
872 * All dissect_ndr_<type> dissectors are already prepared
873 * for this and knows when it should eat data from the tvb
874 * and when not to, so implementors of dissectors will
875 * normally not need to worry about this or even know about
876 * it. However, if a dissector for an aggregate type calls
877 * a subdissector from outside packet-dcerpc.c, such as
878 * the dissector in packet-smb.c for NT Security Descriptors
879 * as an example, then it is VERY important to encapsulate
880 * this call to an external subdissector with the appropriate
881 * test for conformant_run, i.e. it will need something like
885 * di=pinfo->private_data;
886 * if(di->conformant_run){
890 * to make sure it makes the right thing.
891 * This assert will signal when someone has forgotten to
892 * make the dissector aware of this requirement.
895 /* now we dissect the actual pointer */
896 di->conformant_run=0;
897 offset = (*(fnct))(tvb, offset, pinfo, tnpd->tree, drep);
901 } while(found_new_pointer);
908 add_pointer_to_list(packet_info *pinfo, proto_tree *tree,
909 dcerpc_dissect_fnct_t *fnct, guint32 id, int hf_index, int levels)
911 ndr_pointer_data_t *npd;
913 /* check if this pointer is valid */
916 dcerpc_call_value *value;
918 di=pinfo->private_data;
922 if(!(pinfo->fd->flags.visited)){
923 if(id>value->max_ptr){
928 /* if we havent seen the request bail out since we cant
929 know whether this is the first non-NULL instance
931 if(value->req_frame==0){
932 /* XXX THROW EXCEPTION */
935 /* We saw this one in the request frame, nothing to
937 if(id<=value->max_ptr){
943 npd=g_malloc(sizeof(ndr_pointer_data_t));
947 npd->hf_index=hf_index;
949 ndr_pointer_list = g_slist_insert(ndr_pointer_list, npd,
950 ndr_pointer_list_pos);
951 ndr_pointer_list_pos++;
956 find_pointer_index(guint32 id)
958 ndr_pointer_data_t *npd;
961 len=g_slist_length(ndr_pointer_list);
963 npd=g_slist_nth_data(ndr_pointer_list, i);
974 /* This function dissects an NDR pointer and stores the callback for later
975 * deferred dissection.
977 * fnct is the callback function for when we have reached this object in
980 * type is what type of pointer.
982 * this is text is what text we should put in any created tree node.
984 * hf_index is what hf value we want to pass to the callback function when
985 * it is called, the callback can later pich this one up from di->hf_index.
987 * levels is a generic int we want to pass to teh callback function. the
988 * callback can later pick it up from di->levels
990 * See packet-dcerpc-samr.c for examples
993 dissect_ndr_pointer(tvbuff_t *tvb, gint offset, packet_info *pinfo,
994 proto_tree *tree, char *drep, dcerpc_dissect_fnct_t *fnct,
995 int type, char *text, int hf_index, int levels)
999 di=pinfo->private_data;
1000 if(di->conformant_run){
1001 /* this call was only for dissecting the header for any
1002 embedded conformant array. we will not parse any
1003 pointers in this mode.
1008 /*TOP LEVEL REFERENCE POINTER*/
1009 if( pointers_are_top_level
1010 &&(type==NDR_POINTER_REF) ){
1014 /* we must find out a nice way to do the length here */
1015 item=proto_tree_add_text(tree, tvb, offset, 0,
1017 tr=proto_item_add_subtree(item,ett_dcerpc_pointer_data);
1019 add_pointer_to_list(pinfo, tr, fnct, 0xffffffff, hf_index, levels);
1023 /*TOP LEVEL FULL POINTER*/
1024 if( pointers_are_top_level
1025 && (type==NDR_POINTER_PTR) ){
1031 /* get the referent id */
1032 offset = dissect_ndr_uint32(tvb, offset, pinfo, NULL, drep, -1, &id);
1034 /* we got a NULL pointer */
1036 proto_tree_add_text(tree, tvb, offset-4, 4,
1037 "(NULL pointer) %s",text);
1041 /* see if we have seen this pointer before */
1042 idx=find_pointer_index(id);
1044 /* we have seen this pointer before */
1046 proto_tree_add_text(tree, tvb, offset-4, 4,
1047 "(duplicate PTR) %s",text);
1052 item=proto_tree_add_text(tree, tvb, offset-4, 4,
1054 tr=proto_item_add_subtree(item,ett_dcerpc_pointer_data);
1055 proto_tree_add_uint(tr, hf_dcerpc_referent_id, tvb, offset-4, 4, id);
1056 add_pointer_to_list(pinfo, tr, fnct, id, hf_index, levels);
1059 /*TOP LEVEL UNIQUE POINTER*/
1060 if( pointers_are_top_level
1061 && (type==NDR_POINTER_UNIQUE) ){
1066 /* get the referent id */
1067 offset = dissect_ndr_uint32(tvb, offset, pinfo, NULL, drep, -1, &id);
1069 /* we got a NULL pointer */
1071 proto_tree_add_text(tree, tvb, offset-4, 4,
1072 "(NULL pointer) %s",text);
1077 item=proto_tree_add_text(tree, tvb, offset-4, 4,
1079 tr=proto_item_add_subtree(item,ett_dcerpc_pointer_data);
1080 proto_tree_add_uint(tr, hf_dcerpc_referent_id, tvb, offset-4, 4, id);
1081 add_pointer_to_list(pinfo, tr, fnct, 0xffffffff, hf_index, levels);
1085 /*EMBEDDED REFERENCE POINTER*/
1086 if( (!pointers_are_top_level)
1087 && (type==NDR_POINTER_REF) ){
1092 /* get the referent id */
1093 offset = dissect_ndr_uint32(tvb, offset, pinfo, NULL, drep, -1, &id);
1096 item=proto_tree_add_text(tree, tvb, offset-4, 4,
1098 tr=proto_item_add_subtree(item,ett_dcerpc_pointer_data);
1099 proto_tree_add_uint(tr, hf_dcerpc_referent_id, tvb, offset-4, 4, id);
1100 add_pointer_to_list(pinfo, tr, fnct, 0xffffffff, hf_index, levels);
1104 /*EMBEDDED UNIQUE POINTER*/
1105 if( (!pointers_are_top_level)
1106 && (type==NDR_POINTER_UNIQUE) ){
1111 /* get the referent id */
1112 offset = dissect_ndr_uint32(tvb, offset, pinfo, NULL, drep, -1, &id);
1114 /* we got a NULL pointer */
1116 proto_tree_add_text(tree, tvb, offset-4, 4,
1117 "(NULL pointer) %s", text);
1122 item=proto_tree_add_text(tree, tvb, offset-4, 4,
1124 tr=proto_item_add_subtree(item,ett_dcerpc_pointer_data);
1125 proto_tree_add_uint(tr, hf_dcerpc_referent_id, tvb, offset-4, 4, id);
1126 add_pointer_to_list(pinfo, tr, fnct, 0xffffffff, hf_index, levels);
1130 /*EMBEDDED FULL POINTER*/
1131 if( (!pointers_are_top_level)
1132 && (type==NDR_POINTER_PTR) ){
1138 /* get the referent id */
1139 offset = dissect_ndr_uint32(tvb, offset, pinfo, NULL, drep, -1, &id);
1141 /* we got a NULL pointer */
1143 proto_tree_add_text(tree, tvb, offset-4, 4,
1144 "(NULL pointer) %s",text);
1148 /* see if we have seen this pointer before */
1149 idx=find_pointer_index(id);
1151 /* we have seen this pointer before */
1153 proto_tree_add_text(tree, tvb, offset-4, 4,
1154 "(duplicate PTR) %s",text);
1159 item=proto_tree_add_text(tree, tvb, offset-4, 4,
1161 tr=proto_item_add_subtree(item,ett_dcerpc_pointer_data);
1162 proto_tree_add_uint(tr, hf_dcerpc_referent_id, tvb, offset-4, 4, id);
1163 add_pointer_to_list(pinfo, tr, fnct, id, hf_index, levels);
1169 /* After each top level pointer we have dissected we have to
1170 dissect all deferrals before we move on to the next top level
1172 if(pointers_are_top_level==TRUE){
1173 pointers_are_top_level=FALSE;
1174 offset = dissect_deferred_pointers(pinfo, tvb, offset, drep);
1175 pointers_are_top_level=TRUE;
1184 dcerpc_try_handoff (packet_info *pinfo, proto_tree *tree,
1185 proto_tree *dcerpc_tree,
1186 tvbuff_t *tvb, gint offset,
1187 char *drep, dcerpc_info *info,
1190 dcerpc_uuid_key key;
1191 dcerpc_uuid_value *sub_proto;
1193 proto_tree *sub_tree = NULL;
1194 dcerpc_sub_dissector *proc;
1196 dcerpc_dissect_fnct_t *sub_dissect;
1197 const char *saved_proto;
1198 void *saved_private_data;
1200 key.uuid = info->call_data->uuid;
1201 key.ver = info->call_data->ver;
1204 if ((sub_proto = g_hash_table_lookup (dcerpc_uuids, &key)) == NULL
1205 || !proto_is_protocol_enabled(sub_proto->proto)) {
1207 * We don't have a dissector for this UUID, or the protocol
1208 * for that UUID is disabled.
1210 length = tvb_length_remaining (tvb, offset);
1212 proto_tree_add_text (dcerpc_tree, tvb, offset, length,
1213 "Stub data (%d byte%s)", length,
1214 plurality(length, "", "s"));
1219 for (proc = sub_proto->procs; proc->name; proc++) {
1220 if (proc->num == info->call_data->opnum) {
1229 if (check_col (pinfo->cinfo, COL_PROTOCOL)) {
1230 col_set_str (pinfo->cinfo, COL_PROTOCOL, sub_proto->name);
1233 if (check_col (pinfo->cinfo, COL_INFO)) {
1234 col_add_fstr (pinfo->cinfo, COL_INFO, "%s %s",
1235 name, info->request ? "request" : "reply");
1239 proto_item *sub_item;
1240 sub_item = proto_tree_add_item (tree, sub_proto->proto, tvb, offset,
1244 sub_tree = proto_item_add_subtree (sub_item, sub_proto->ett);
1248 * Put the operation number into the tree along with
1249 * the operation's name.
1252 if (sub_proto->opnum_hf != -1)
1253 proto_tree_add_uint_format(sub_tree, sub_proto->opnum_hf,
1254 tvb, 0, 0, info->call_data->opnum,
1255 "Operation: %s (%u)",
1256 name, info->call_data->opnum);
1258 proto_tree_add_uint_format(sub_tree, hf_dcerpc_op, tvb,
1259 0, 0, info->call_data->opnum,
1260 "Operation: %s (%u)",
1261 name, info->call_data->opnum);
1265 * If the authentication level is DCE_C_AUTHN_LEVEL_PKT_PRIVACY,
1266 * the stub data is encrypted, and we can't dissect it.
1268 if (auth_level == DCE_C_AUTHN_LEVEL_PKT_PRIVACY) {
1269 length = tvb_length_remaining (tvb, offset);
1271 proto_tree_add_text(sub_tree, tvb, offset, length,
1272 "Encrypted stub data (%d byte%s)",
1273 length, plurality(length, "", "s"));
1276 sub_dissect = info->request ? proc->dissect_rqst : proc->dissect_resp;
1278 saved_proto = pinfo->current_proto;
1279 saved_private_data = pinfo->private_data;
1280 pinfo->current_proto = sub_proto->name;
1281 pinfo->private_data = (void *)info;
1283 init_ndr_pointer_list(pinfo);
1284 offset = sub_dissect (tvb, offset, pinfo, sub_tree, drep);
1286 pinfo->current_proto = saved_proto;
1287 pinfo->private_data = saved_private_data;
1289 length = tvb_length_remaining (tvb, offset);
1291 proto_tree_add_text (sub_tree, tvb, offset, length,
1292 "Stub data (%d byte%s)", length,
1293 plurality(length, "", "s"));
1301 dissect_dcerpc_cn_auth (tvbuff_t *tvb, packet_info *pinfo, proto_tree *dcerpc_tree,
1302 e_dce_cn_common_hdr_t *hdr, int *auth_level_p)
1305 guint8 auth_pad_len;
1310 * Initially set "*auth_level_p" to -1 to indicate that we haven't
1311 * yet seen any authentication level information.
1313 if (auth_level_p != NULL)
1317 * The authentication information is at the *end* of the PDU; in
1318 * request and response PDUs, the request and response stub data
1321 * If the full packet is here, and we've got an auth len, and it's
1322 * valid, then dissect the auth info.
1324 if (tvb_length (tvb) >= hdr->frag_len
1326 && (hdr->auth_len + 8 <= hdr->frag_len)) {
1328 offset = hdr->frag_len - (hdr->auth_len + 8);
1330 offset = dissect_dcerpc_uint8 (tvb, offset, pinfo, dcerpc_tree, hdr->drep,
1331 hf_dcerpc_auth_type, &auth_type);
1332 offset = dissect_dcerpc_uint8 (tvb, offset, pinfo, dcerpc_tree, hdr->drep,
1333 hf_dcerpc_auth_level, &auth_level);
1334 if (auth_level_p != NULL)
1335 *auth_level_p = auth_level;
1336 offset = dissect_dcerpc_uint8 (tvb, offset, pinfo, dcerpc_tree, hdr->drep,
1337 hf_dcerpc_auth_pad_len, &auth_pad_len);
1338 offset = dissect_dcerpc_uint8 (tvb, offset, pinfo, dcerpc_tree, hdr->drep,
1339 hf_dcerpc_auth_rsrvd, NULL);
1340 offset = dissect_dcerpc_uint32 (tvb, offset, pinfo, dcerpc_tree, hdr->drep,
1341 hf_dcerpc_auth_ctx_id, NULL);
1343 /* Dissect the authentication data as NTLMSSP Parameters if the
1344 auth_type is DCE_C_RPC_AUTHN_PROTOCOL_NTLMSSP and this is a
1345 BIND request, BIND response, or AUTH3.
1346 Otherwise just show it as "Auth Data".
1347 XXX - dissect it for other authentication types?
1349 if ((auth_type == DCE_C_RPC_AUTHN_PROTOCOL_NTLMSSP) &&
1350 ((hdr->ptype == PDU_BIND) || (hdr->ptype == PDU_BIND_ACK) ||
1351 (hdr->ptype == PDU_AUTH3))) {
1352 tvbuff_t *ntlmssp_tvb;
1353 ntlmssp_tvb = tvb_new_subset(tvb, offset, hdr->auth_len,
1355 call_dissector(ntlmssp_handle, ntlmssp_tvb, pinfo, dcerpc_tree);
1357 proto_tree_add_text (dcerpc_tree, tvb, offset, hdr->auth_len,
1361 /* figure out where the auth padding starts */
1362 offset = hdr->frag_len - (hdr->auth_len + 8 + auth_pad_len);
1363 if (offset > 0 && auth_pad_len) {
1364 proto_tree_add_text (dcerpc_tree, tvb, offset,
1365 auth_pad_len, "Auth padding");
1366 return hdr->auth_len + 8 + auth_pad_len;
1368 return hdr->auth_len + 8;
1376 /* We need to hash in the SMB fid number to generate a unique hash table
1377 key as DCERPC over SMB allows several pipes over the same TCP/IP
1380 static guint16 get_smb_fid (void *private_data)
1382 dcerpc_private_info *priv = (dcerpc_private_info *)private_data;
1385 return 0; /* Nothing to see here */
1387 /* DCERPC over smb */
1389 if (priv->transport_type == DCERPC_TRANSPORT_SMB)
1390 return priv->data.smb.fid;
1392 /* Some other transport... */
1398 * Connection oriented packet types
1402 dissect_dcerpc_cn_bind (tvbuff_t *tvb, packet_info *pinfo, proto_tree *dcerpc_tree,
1403 e_dce_cn_common_hdr_t *hdr)
1405 conversation_t *conv = NULL;
1406 guint8 num_ctx_items;
1408 gboolean saw_ctx_item = FALSE;
1410 guint16 num_trans_items;
1415 guint16 if_ver, if_ver_minor;
1418 offset = dissect_dcerpc_uint16 (tvb, offset, pinfo, dcerpc_tree, hdr->drep,
1419 hf_dcerpc_cn_max_xmit, NULL);
1421 offset = dissect_dcerpc_uint16 (tvb, offset, pinfo, dcerpc_tree, hdr->drep,
1422 hf_dcerpc_cn_max_recv, NULL);
1424 offset = dissect_dcerpc_uint32 (tvb, offset, pinfo, dcerpc_tree, hdr->drep,
1425 hf_dcerpc_cn_assoc_group, NULL);
1427 offset = dissect_dcerpc_uint8 (tvb, offset, pinfo, dcerpc_tree, hdr->drep,
1428 hf_dcerpc_cn_num_ctx_items, &num_ctx_items);
1433 for (i = 0; i < num_ctx_items; i++) {
1434 offset = dissect_dcerpc_uint16 (tvb, offset, pinfo, dcerpc_tree, hdr->drep,
1435 hf_dcerpc_cn_ctx_id, &ctx_id);
1437 offset = dissect_dcerpc_uint16 (tvb, offset, pinfo, dcerpc_tree, hdr->drep,
1438 hf_dcerpc_cn_num_trans_items, &num_trans_items);
1440 dcerpc_tvb_get_uuid (tvb, offset, hdr->drep, &if_id);
1442 proto_tree_add_string_format (dcerpc_tree, hf_dcerpc_cn_bind_if_id, tvb,
1444 "Interface UUID: %08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
1445 if_id.Data1, if_id.Data2, if_id.Data3,
1446 if_id.Data4[0], if_id.Data4[1],
1447 if_id.Data4[2], if_id.Data4[3],
1448 if_id.Data4[4], if_id.Data4[5],
1449 if_id.Data4[6], if_id.Data4[7]);
1453 if (hdr->drep[0] & 0x10) {
1454 offset = dissect_dcerpc_uint16 (tvb, offset, pinfo, dcerpc_tree, hdr->drep,
1455 hf_dcerpc_cn_bind_if_ver, &if_ver);
1456 offset = dissect_dcerpc_uint16 (tvb, offset, pinfo, dcerpc_tree, hdr->drep,
1457 hf_dcerpc_cn_bind_if_ver_minor, &if_ver_minor);
1459 offset = dissect_dcerpc_uint16 (tvb, offset, pinfo, dcerpc_tree, hdr->drep,
1460 hf_dcerpc_cn_bind_if_ver_minor, &if_ver_minor);
1461 offset = dissect_dcerpc_uint16 (tvb, offset, pinfo, dcerpc_tree, hdr->drep,
1462 hf_dcerpc_cn_bind_if_ver, &if_ver);
1465 if (!saw_ctx_item) {
1466 conv = find_conversation (&pinfo->src, &pinfo->dst, pinfo->ptype,
1467 pinfo->srcport, pinfo->destport, 0);
1469 conv = conversation_new (&pinfo->src, &pinfo->dst, pinfo->ptype,
1470 pinfo->srcport, pinfo->destport, 0);
1473 /* if this is the first time we see this packet, we need to
1474 update the dcerpc_binds table so that any later calls can
1475 match to the interface.
1476 XXX We assume that BINDs will NEVER be fragmented.
1478 if(!(pinfo->fd->flags.visited)){
1479 dcerpc_bind_key *key;
1480 dcerpc_bind_value *value;
1482 key = g_mem_chunk_alloc (dcerpc_bind_key_chunk);
1484 key->ctx_id = ctx_id;
1485 key->smb_fid = get_smb_fid(pinfo->private_data);
1487 value = g_mem_chunk_alloc (dcerpc_bind_value_chunk);
1488 value->uuid = if_id;
1489 value->ver = if_ver;
1491 /* add this entry to the bind table, first removing any
1492 previous ones that are identical
1494 if(g_hash_table_lookup(dcerpc_binds, key)){
1495 g_hash_table_remove(dcerpc_binds, key);
1497 g_hash_table_insert (dcerpc_binds, key, value);
1500 if (check_col (pinfo->cinfo, COL_INFO)) {
1501 dcerpc_uuid_key key;
1502 dcerpc_uuid_value *value;
1507 if ((value = g_hash_table_lookup(dcerpc_uuids, &key)))
1508 col_append_fstr(pinfo->cinfo, COL_INFO, " UUID: %s", value->name);
1510 col_append_fstr(pinfo->cinfo, COL_INFO, " UUID: %08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x ver %u.%u",
1511 if_id.Data1, if_id.Data2, if_id.Data3,
1512 if_id.Data4[0], if_id.Data4[1],
1513 if_id.Data4[2], if_id.Data4[3],
1514 if_id.Data4[4], if_id.Data4[5],
1515 if_id.Data4[6], if_id.Data4[7],
1516 if_ver, if_ver_minor);
1518 saw_ctx_item = TRUE;
1521 for (j = 0; j < num_trans_items; j++) {
1522 dcerpc_tvb_get_uuid (tvb, offset, hdr->drep, &trans_id);
1524 proto_tree_add_string_format (dcerpc_tree, hf_dcerpc_cn_bind_trans_id, tvb,
1526 "Transfer Syntax: %08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
1527 trans_id.Data1, trans_id.Data2, trans_id.Data3,
1528 trans_id.Data4[0], trans_id.Data4[1],
1529 trans_id.Data4[2], trans_id.Data4[3],
1530 trans_id.Data4[4], trans_id.Data4[5],
1531 trans_id.Data4[6], trans_id.Data4[7]);
1535 offset = dissect_dcerpc_uint32 (tvb, offset, pinfo, dcerpc_tree, hdr->drep,
1536 hf_dcerpc_cn_bind_trans_ver, &trans_ver);
1541 * XXX - we should save the authentication type *if* we have
1542 * an authentication header, and associate it with an authentication
1543 * context, so subsequent PDUs can use that context.
1545 dissect_dcerpc_cn_auth (tvb, pinfo, dcerpc_tree, hdr, NULL);
1549 dissect_dcerpc_cn_bind_ack (tvbuff_t *tvb, packet_info *pinfo, proto_tree *dcerpc_tree,
1550 e_dce_cn_common_hdr_t *hdr)
1552 guint16 max_xmit, max_recv;
1553 guint16 sec_addr_len;
1563 offset = dissect_dcerpc_uint16 (tvb, offset, pinfo, dcerpc_tree, hdr->drep,
1564 hf_dcerpc_cn_max_xmit, &max_xmit);
1566 offset = dissect_dcerpc_uint16 (tvb, offset, pinfo, dcerpc_tree, hdr->drep,
1567 hf_dcerpc_cn_max_recv, &max_recv);
1569 offset = dissect_dcerpc_uint32 (tvb, offset, pinfo, dcerpc_tree, hdr->drep,
1570 hf_dcerpc_cn_assoc_group, NULL);
1572 offset = dissect_dcerpc_uint16 (tvb, offset, pinfo, dcerpc_tree, hdr->drep,
1573 hf_dcerpc_cn_sec_addr_len, &sec_addr_len);
1574 if (sec_addr_len != 0) {
1575 proto_tree_add_item (dcerpc_tree, hf_dcerpc_cn_sec_addr, tvb, offset,
1576 sec_addr_len, FALSE);
1577 offset += sec_addr_len;
1581 offset += 4 - offset % 4;
1584 offset = dissect_dcerpc_uint8 (tvb, offset, pinfo, dcerpc_tree, hdr->drep,
1585 hf_dcerpc_cn_num_results, &num_results);
1590 for (i = 0; i < num_results; i++) {
1591 offset = dissect_dcerpc_uint16 (tvb, offset, pinfo, dcerpc_tree,
1592 hdr->drep, hf_dcerpc_cn_ack_result,
1595 offset = dissect_dcerpc_uint16 (tvb, offset, pinfo, dcerpc_tree,
1596 hdr->drep, hf_dcerpc_cn_ack_reason,
1600 * The reason for rejection isn't meaningful, and often isn't
1601 * set, when the syntax was accepted.
1606 dcerpc_tvb_get_uuid (tvb, offset, hdr->drep, &trans_id);
1608 proto_tree_add_string_format (dcerpc_tree, hf_dcerpc_cn_ack_trans_id, tvb,
1610 "Transfer Syntax: %08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
1611 trans_id.Data1, trans_id.Data2, trans_id.Data3,
1612 trans_id.Data4[0], trans_id.Data4[1],
1613 trans_id.Data4[2], trans_id.Data4[3],
1614 trans_id.Data4[4], trans_id.Data4[5],
1615 trans_id.Data4[6], trans_id.Data4[7]);
1619 offset = dissect_dcerpc_uint32 (tvb, offset, pinfo, dcerpc_tree, hdr->drep,
1620 hf_dcerpc_cn_ack_trans_ver, &trans_ver);
1624 * XXX - do we need to do anything with the authentication level
1625 * we get back from this?
1627 dissect_dcerpc_cn_auth (tvb, pinfo, dcerpc_tree, hdr, NULL);
1629 if (check_col (pinfo->cinfo, COL_INFO)) {
1630 if (num_results != 0 && result == 0) {
1631 /* XXX - only checks the last result */
1632 col_append_fstr (pinfo->cinfo, COL_INFO,
1633 " accept max_xmit: %u max_recv: %u",
1634 max_xmit, max_recv);
1636 /* XXX - only shows the last result and reason */
1637 col_append_fstr (pinfo->cinfo, COL_INFO, " %s, reason: %s",
1638 val_to_str(result, p_cont_result_vals,
1639 "Unknown result (%u)"),
1640 val_to_str(reason, p_provider_reason_vals,
1647 dissect_dcerpc_cn_bind_nak (tvbuff_t *tvb, packet_info *pinfo, proto_tree *dcerpc_tree,
1648 e_dce_cn_common_hdr_t *hdr)
1651 guint8 num_protocols;
1656 offset = dissect_dcerpc_uint16 (tvb, offset, pinfo, dcerpc_tree,
1657 hdr->drep, hf_dcerpc_cn_reject_reason,
1660 if (check_col (pinfo->cinfo, COL_INFO)) {
1661 col_append_fstr (pinfo->cinfo, COL_INFO, " reason: %s",
1662 val_to_str(reason, reject_reason_vals, "Unknown (%u)"));
1665 if (reason == PROTOCOL_VERSION_NOT_SUPPORTED) {
1666 offset = dissect_dcerpc_uint8 (tvb, offset, pinfo, dcerpc_tree, hdr->drep,
1667 hf_dcerpc_cn_num_protocols,
1670 for (i = 0; i < num_protocols; i++) {
1671 offset = dissect_dcerpc_uint8 (tvb, offset, pinfo, dcerpc_tree,
1672 hdr->drep, hf_dcerpc_cn_protocol_ver_major,
1674 offset = dissect_dcerpc_uint8 (tvb, offset, pinfo, dcerpc_tree,
1675 hdr->drep, hf_dcerpc_cn_protocol_ver_minor,
1682 dissect_dcerpc_cn_stub (tvbuff_t *tvb, int offset, packet_info *pinfo,
1683 proto_tree *dcerpc_tree, proto_tree *tree,
1684 e_dce_cn_common_hdr_t *hdr, dcerpc_info *di,
1685 int auth_sz, int auth_level, guint32 alloc_hint,
1688 int length, reported_length, stub_length;
1689 gboolean save_fragmented;
1691 length = tvb_length_remaining(tvb, offset);
1692 reported_length = tvb_reported_length_remaining(tvb, offset);
1693 stub_length = hdr->frag_len - offset - auth_sz;
1694 if (length > stub_length)
1695 length = stub_length;
1696 if (reported_length > stub_length)
1697 reported_length = stub_length;
1699 save_fragmented = pinfo->fragmented;
1701 /* If we don't have reassembly enabled, or this packet contains
1702 the entire PDU, or if this is a short frame (or a frame
1703 not reassembled at a lower layer) that doesn't include all
1704 the data in the fragment, just call the handoff directly if
1705 this is the first fragment or the PDU isn't fragmented. */
1706 if( (!dcerpc_reassemble) || PFC_NOT_FRAGMENTED(hdr) ||
1707 stub_length > length ){
1708 if(hdr->flags&PFC_FIRST_FRAG){
1709 /* First fragment, possibly the only fragment */
1710 pinfo->fragmented = !PFC_NOT_FRAGMENTED(hdr);
1711 dcerpc_try_handoff (pinfo, tree, dcerpc_tree,
1712 tvb_new_subset (tvb, offset, length,
1714 0, hdr->drep, di, auth_level);
1716 /* PDU is fragmented and this isn't the first fragment */
1717 if (check_col(pinfo->cinfo, COL_INFO)) {
1718 col_append_fstr(pinfo->cinfo, COL_INFO,
1719 " [DCE/RPC fragment]");
1723 proto_tree_add_text (dcerpc_tree, tvb, offset, length,
1724 "Fragment data (%d byte%s)", length,
1725 plurality(length, "", "s"));
1730 /* Reassembly is enabled, the PDU is fragmented, and
1731 we have all the data in the fragment; the first two
1732 of those mean we should attempt reassembly, and the
1733 third means we can attempt reassembly. */
1736 proto_tree_add_text (dcerpc_tree, tvb, offset, length,
1737 "Fragment data (%d byte%s)", length,
1738 plurality(length, "", "s"));
1741 if(hdr->flags&PFC_FIRST_FRAG){ /* FIRST fragment */
1742 if( (!pinfo->fd->flags.visited) && frame){
1743 fragment_add(tvb, offset, pinfo, frame,
1744 dcerpc_co_reassemble_table,
1748 fragment_set_tot_len(pinfo, frame,
1749 dcerpc_co_reassemble_table, alloc_hint);
1751 if (check_col(pinfo->cinfo, COL_INFO)) {
1752 col_append_fstr(pinfo->cinfo, COL_INFO,
1753 " [DCE/RPC fragment]");
1755 } else if(hdr->flags&PFC_LAST_FRAG){ /* LAST fragment */
1757 fragment_data *fd_head;
1760 tot_len = fragment_get_tot_len(pinfo, frame,
1761 dcerpc_co_reassemble_table);
1762 fd_head = fragment_add(tvb, offset, pinfo,
1764 dcerpc_co_reassemble_table,
1770 /* We completed reassembly */
1773 next_tvb = tvb_new_real_data(fd_head->data, fd_head->datalen, fd_head->datalen);
1774 tvb_set_child_real_data_tvbuff(tvb, next_tvb);
1775 add_new_data_source(pinfo, next_tvb, "Reassembled DCE/RPC");
1776 show_fragment_tree(fd_head, &dcerpc_frag_items,
1777 dcerpc_tree, pinfo, next_tvb);
1779 pinfo->fragmented = FALSE;
1780 dcerpc_try_handoff (pinfo, tree, dcerpc_tree, next_tvb,
1781 0, hdr->drep, di, auth_level);
1783 /* Reassembly not complete - some fragments
1785 if (check_col(pinfo->cinfo, COL_INFO)) {
1786 col_append_fstr(pinfo->cinfo, COL_INFO,
1787 " [DCE/RPC fragment]");
1791 } else { /* MIDDLE fragment(s) */
1792 if( (!pinfo->fd->flags.visited) && frame ){
1794 tot_len = fragment_get_tot_len(pinfo, frame,
1795 dcerpc_co_reassemble_table);
1796 fragment_add(tvb, offset, pinfo, frame,
1797 dcerpc_co_reassemble_table,
1802 if (check_col(pinfo->cinfo, COL_INFO)) {
1803 col_append_fstr(pinfo->cinfo, COL_INFO,
1804 " [DCE/RPC fragment]");
1808 pinfo->fragmented = save_fragmented;
1812 dissect_dcerpc_cn_rqst (tvbuff_t *tvb, packet_info *pinfo, proto_tree *dcerpc_tree,
1813 proto_tree *tree, e_dce_cn_common_hdr_t *hdr)
1815 conversation_t *conv;
1825 offset = dissect_dcerpc_uint32 (tvb, offset, pinfo, dcerpc_tree, hdr->drep,
1826 hf_dcerpc_cn_alloc_hint, &alloc_hint);
1828 offset = dissect_dcerpc_uint16 (tvb, offset, pinfo, dcerpc_tree, hdr->drep,
1829 hf_dcerpc_cn_ctx_id, &ctx_id);
1831 offset = dissect_dcerpc_uint16 (tvb, offset, pinfo, dcerpc_tree, hdr->drep,
1832 hf_dcerpc_opnum, &opnum);
1834 if (check_col (pinfo->cinfo, COL_INFO)) {
1835 col_append_fstr (pinfo->cinfo, COL_INFO, " opnum: %u ctx_id: %u",
1839 if (hdr->flags & PFC_OBJECT_UUID) {
1840 dcerpc_tvb_get_uuid (tvb, offset, hdr->drep, &obj_id);
1842 proto_tree_add_string_format (dcerpc_tree, hf_dcerpc_obj_id, tvb,
1844 "Object UUID: %08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
1845 obj_id.Data1, obj_id.Data2, obj_id.Data3,
1859 * XXX - what if this was set when the connection was set up,
1860 * and we just have a security context?
1862 auth_sz = dissect_dcerpc_cn_auth (tvb, pinfo, dcerpc_tree, hdr,
1865 conv = find_conversation (&pinfo->src, &pinfo->dst, pinfo->ptype,
1866 pinfo->srcport, pinfo->destport, 0);
1870 dcerpc_call_value *value;
1872 /* !!! we can NOT check flags.visited here since this will interact
1873 badly with when SMB handles (i.e. calls the subdissector)
1874 and desegmented pdu's .
1875 Instead we check if this pdu is already in the matched table or not
1877 if(!g_hash_table_lookup(dcerpc_matched, (void *)pinfo->fd->num)){
1878 dcerpc_bind_key bind_key;
1879 dcerpc_bind_value *bind_value;
1882 bind_key.ctx_id=ctx_id;
1883 bind_key.smb_fid=get_smb_fid(pinfo->private_data);
1885 if((bind_value=g_hash_table_lookup(dcerpc_binds, &bind_key))){
1886 dcerpc_call_key *call_key;
1887 dcerpc_call_value *call_value;
1889 /* We found the binding so just add the call
1890 to both the call table and the matched table
1892 call_key=g_mem_chunk_alloc (dcerpc_call_key_chunk);
1893 call_key->conv=conv;
1894 call_key->call_id=hdr->call_id;
1895 call_key->smb_fid=get_smb_fid(pinfo->private_data);
1897 /* if there is already a matching call in the table
1898 remove it so it is replaced with the new one */
1899 if(g_hash_table_lookup(dcerpc_calls, call_key)){
1900 g_hash_table_remove(dcerpc_calls, call_key);
1903 call_value=g_mem_chunk_alloc (dcerpc_call_value_chunk);
1904 call_value->uuid = bind_value->uuid;
1905 call_value->ver = bind_value->ver;
1906 call_value->opnum = opnum;
1907 call_value->req_frame=pinfo->fd->num;
1908 call_value->rep_frame=0;
1909 call_value->max_ptr=0;
1910 call_value->private_data = NULL;
1911 g_hash_table_insert (dcerpc_calls, call_key, call_value);
1913 g_hash_table_insert (dcerpc_matched, (void *)pinfo->fd->num, call_value);
1917 value=g_hash_table_lookup (dcerpc_matched, (void *)pinfo->fd->num);
1922 /* handoff this call */
1924 di.call_id = hdr->call_id;
1925 di.smb_fid = get_smb_fid(pinfo->private_data);
1927 di.call_data = value;
1929 if(value->rep_frame!=0){
1930 proto_tree_add_uint(dcerpc_tree, hf_dcerpc_response_in,
1931 tvb, 0, 0, value->rep_frame);
1934 dissect_dcerpc_cn_stub (tvb, offset, pinfo, dcerpc_tree, tree,
1935 hdr, &di, auth_sz, auth_level, alloc_hint,
1938 length = tvb_length_remaining (tvb, offset);
1940 proto_tree_add_text (dcerpc_tree, tvb, offset, length,
1941 "Stub data (%d byte%s)", length,
1942 plurality(length, "", "s"));
1949 dissect_dcerpc_cn_resp (tvbuff_t *tvb, packet_info *pinfo, proto_tree *dcerpc_tree,
1950 proto_tree *tree, e_dce_cn_common_hdr_t *hdr)
1952 dcerpc_call_value *value = NULL;
1953 conversation_t *conv;
1961 offset = dissect_dcerpc_uint32 (tvb, offset, pinfo, dcerpc_tree, hdr->drep,
1962 hf_dcerpc_cn_alloc_hint, &alloc_hint);
1964 offset = dissect_dcerpc_uint16 (tvb, offset, pinfo, dcerpc_tree, hdr->drep,
1965 hf_dcerpc_cn_ctx_id, &ctx_id);
1967 if (check_col (pinfo->cinfo, COL_INFO)) {
1968 col_append_fstr (pinfo->cinfo, COL_INFO, " ctx_id: %u", ctx_id);
1971 offset = dissect_dcerpc_uint8 (tvb, offset, pinfo, dcerpc_tree, hdr->drep,
1972 hf_dcerpc_cn_cancel_count, NULL);
1977 * XXX - what if this was set when the connection was set up,
1978 * and we just have a security context?
1980 auth_sz = dissect_dcerpc_cn_auth (tvb, pinfo, dcerpc_tree, hdr,
1983 conv = find_conversation (&pinfo->src, &pinfo->dst, pinfo->ptype,
1984 pinfo->srcport, pinfo->destport, 0);
1986 /* no point in creating one here, really */
1989 /* !!! we can NOT check flags.visited here since this will interact
1990 badly with when SMB handles (i.e. calls the subdissector)
1991 and desegmented pdu's .
1992 Instead we check if this pdu is already in the matched table or not
1994 if(!g_hash_table_lookup(dcerpc_matched, (void *)pinfo->fd->num)){
1995 dcerpc_call_key call_key;
1996 dcerpc_call_value *call_value;
1999 call_key.call_id=hdr->call_id;
2000 call_key.smb_fid=get_smb_fid(pinfo->private_data);
2002 if((call_value=g_hash_table_lookup(dcerpc_calls, &call_key))){
2003 g_hash_table_insert (dcerpc_matched, (void *)pinfo->fd->num, call_value);
2004 if(call_value->rep_frame==0){
2005 call_value->rep_frame=pinfo->fd->num;
2011 value=g_hash_table_lookup(dcerpc_matched, (void *)pinfo->fd->num);
2016 /* handoff this call */
2018 di.call_id = hdr->call_id;
2019 di.smb_fid = get_smb_fid(pinfo->private_data);
2021 di.call_data = value;
2023 proto_tree_add_uint (dcerpc_tree, hf_dcerpc_opnum, tvb, 0, 0, value->opnum);
2024 if(value->req_frame!=0){
2025 proto_tree_add_uint(dcerpc_tree, hf_dcerpc_request_in,
2026 tvb, 0, 0, value->req_frame);
2029 dissect_dcerpc_cn_stub (tvb, offset, pinfo, dcerpc_tree, tree,
2030 hdr, &di, auth_sz, auth_level, alloc_hint,
2033 length = tvb_length_remaining (tvb, offset);
2035 proto_tree_add_text (dcerpc_tree, tvb, offset, length,
2036 "Stub data (%d byte%s)", length,
2037 plurality(length, "", "s"));
2044 dissect_dcerpc_cn_fault (tvbuff_t *tvb, packet_info *pinfo,
2045 proto_tree *dcerpc_tree, e_dce_cn_common_hdr_t *hdr)
2047 dcerpc_call_value *value = NULL;
2048 conversation_t *conv;
2056 offset = dissect_dcerpc_uint32 (tvb, offset, pinfo, dcerpc_tree, hdr->drep,
2057 hf_dcerpc_cn_alloc_hint, &alloc_hint);
2059 offset = dissect_dcerpc_uint16 (tvb, offset, pinfo, dcerpc_tree, hdr->drep,
2060 hf_dcerpc_cn_ctx_id, &ctx_id);
2062 offset = dissect_dcerpc_uint8 (tvb, offset, pinfo, dcerpc_tree, hdr->drep,
2063 hf_dcerpc_cn_cancel_count, NULL);
2067 offset = dissect_dcerpc_uint32 (tvb, offset, pinfo, dcerpc_tree, hdr->drep,
2068 hf_dcerpc_cn_status, &status);
2070 if (check_col (pinfo->cinfo, COL_INFO)) {
2071 col_append_fstr (pinfo->cinfo, COL_INFO,
2072 " ctx_id: %u status: %s", ctx_id,
2073 val_to_str(status, reject_status_vals,
2074 "Unknown (0x%08x)"));
2081 * XXX - what if this was set when the connection was set up,
2082 * and we just have a security context?
2084 auth_sz = dissect_dcerpc_cn_auth (tvb, pinfo, dcerpc_tree, hdr,
2087 conv = find_conversation (&pinfo->src, &pinfo->dst, pinfo->ptype,
2088 pinfo->srcport, pinfo->destport, 0);
2090 /* no point in creating one here, really */
2093 /* !!! we can NOT check flags.visited here since this will interact
2094 badly with when SMB handles (i.e. calls the subdissector)
2095 and desegmented pdu's .
2096 Instead we check if this pdu is already in the matched table or not
2098 if(!g_hash_table_lookup(dcerpc_matched, (void *)pinfo->fd->num)){
2099 dcerpc_call_key call_key;
2100 dcerpc_call_value *call_value;
2103 call_key.call_id=hdr->call_id;
2104 call_key.smb_fid=get_smb_fid(pinfo->private_data);
2106 if((call_value=g_hash_table_lookup(dcerpc_calls, &call_key))){
2107 g_hash_table_insert (dcerpc_matched, (void *)pinfo->fd->num, call_value);
2108 if(call_value->rep_frame==0){
2109 call_value->rep_frame=pinfo->fd->num;
2115 value=g_hash_table_lookup(dcerpc_matched, (void *)pinfo->fd->num);
2118 int length, reported_length, stub_length;
2121 /* handoff this call */
2123 di.call_id = hdr->call_id;
2124 di.smb_fid = get_smb_fid(pinfo->private_data);
2126 di.call_data = value;
2128 proto_tree_add_uint (dcerpc_tree, hf_dcerpc_opnum, tvb, 0, 0, value->opnum);
2129 if(value->req_frame!=0){
2130 proto_tree_add_uint(dcerpc_tree, hf_dcerpc_request_in,
2131 tvb, 0, 0, value->req_frame);
2134 length = tvb_length_remaining(tvb, offset);
2135 reported_length = tvb_reported_length_remaining(tvb, offset);
2136 stub_length = hdr->frag_len - offset - auth_sz;
2137 if (length > stub_length)
2138 length = stub_length;
2139 if (reported_length > stub_length)
2140 reported_length = stub_length;
2142 /* If we don't have reassembly enabled, or this packet contains
2143 the entire PDU, or if this is a short frame (or a frame
2144 not reassembled at a lower layer) that doesn't include all
2145 the data in the fragment, just call the handoff directly if
2146 this is the first fragment or the PDU isn't fragmented. */
2147 if( (!dcerpc_reassemble) || PFC_NOT_FRAGMENTED(hdr) ||
2148 stub_length > length ){
2149 if(hdr->flags&PFC_FIRST_FRAG){
2150 /* First fragment, possibly the only fragment */
2152 * XXX - should there be a third routine for each
2153 * function in an RPC subdissector, to handle
2154 * fault responses? The DCE RPC 1.1 spec says
2155 * three's "stub data" here, which I infer means
2156 * that it's protocol-specific and call-specific.
2158 * It should probably get passed the status code
2159 * as well, as that might be protocol-specific.
2163 proto_tree_add_text (dcerpc_tree, tvb, offset, length,
2164 "Fault stub data (%d byte%s)", length,
2165 plurality(length, "", "s"));
2169 /* PDU is fragmented and this isn't the first fragment */
2170 if (check_col(pinfo->cinfo, COL_INFO)) {
2171 col_append_fstr(pinfo->cinfo, COL_INFO,
2172 " [DCE/RPC fragment]");
2176 proto_tree_add_text (dcerpc_tree, tvb, offset, length,
2177 "Fragment data (%d byte%s)", length,
2178 plurality(length, "", "s"));
2183 /* Reassembly is enabled, the PDU is fragmented, and
2184 we have all the data in the fragment; the first two
2185 of those mean we should attempt reassembly, and the
2186 third means we can attempt reassembly. */
2189 proto_tree_add_text (dcerpc_tree, tvb, offset, length,
2190 "Fragment data (%d byte%s)", length,
2191 plurality(length, "", "s"));
2194 if(hdr->flags&PFC_FIRST_FRAG){ /* FIRST fragment */
2195 if( (!pinfo->fd->flags.visited) && value->rep_frame ){
2196 fragment_add(tvb, offset, pinfo, value->rep_frame,
2197 dcerpc_co_reassemble_table,
2201 fragment_set_tot_len(pinfo, value->rep_frame,
2202 dcerpc_co_reassemble_table, alloc_hint);
2204 if (check_col(pinfo->cinfo, COL_INFO)) {
2205 col_append_fstr(pinfo->cinfo, COL_INFO,
2206 " [DCE/RPC fragment]");
2208 } else if(hdr->flags&PFC_LAST_FRAG){ /* LAST fragment */
2209 if( value->rep_frame ){
2210 fragment_data *fd_head;
2213 tot_len = fragment_get_tot_len(pinfo, value->rep_frame,
2214 dcerpc_co_reassemble_table);
2215 fd_head = fragment_add(tvb, offset, pinfo,
2217 dcerpc_co_reassemble_table,
2223 /* We completed reassembly */
2226 next_tvb = tvb_new_real_data(fd_head->data, fd_head->datalen, fd_head->datalen);
2227 tvb_set_child_real_data_tvbuff(tvb, next_tvb);
2228 add_new_data_source(pinfo, next_tvb, "Reassembled DCE/RPC");
2229 show_fragment_tree(fd_head, &dcerpc_frag_items,
2230 dcerpc_tree, pinfo, next_tvb);
2233 * XXX - should there be a third routine for each
2234 * function in an RPC subdissector, to handle
2235 * fault responses? The DCE RPC 1.1 spec says
2236 * three's "stub data" here, which I infer means
2237 * that it's protocol-specific and call-specific.
2239 * It should probably get passed the status code
2240 * as well, as that might be protocol-specific.
2244 proto_tree_add_text (dcerpc_tree, tvb, offset, length,
2245 "Fault stub data (%d byte%s)", length,
2246 plurality(length, "", "s"));
2250 /* Reassembly not complete - some fragments
2252 if (check_col(pinfo->cinfo, COL_INFO)) {
2253 col_append_fstr(pinfo->cinfo, COL_INFO,
2254 " [DCE/RPC fragment]");
2258 } else { /* MIDDLE fragment(s) */
2259 if( (!pinfo->fd->flags.visited) && value->rep_frame ){
2261 tot_len = fragment_get_tot_len(pinfo, value->rep_frame,
2262 dcerpc_co_reassemble_table);
2263 fragment_add(tvb, offset, pinfo, value->rep_frame,
2264 dcerpc_co_reassemble_table,
2269 if (check_col(pinfo->cinfo, COL_INFO)) {
2270 col_append_fstr(pinfo->cinfo, COL_INFO,
2271 " [DCE/RPC fragment]");
2280 * DCERPC dissector for connection oriented calls
2283 dissect_dcerpc_cn (tvbuff_t *tvb, int offset, packet_info *pinfo,
2284 proto_tree *tree, gboolean can_desegment)
2286 static char nulls[4] = { 0 };
2289 proto_item *ti = NULL;
2290 proto_item *tf = NULL;
2291 proto_tree *dcerpc_tree = NULL;
2292 proto_tree *cn_flags_tree = NULL;
2293 proto_tree *drep_tree = NULL;
2294 e_dce_cn_common_hdr_t hdr;
2297 * when done over nbt, dcerpc requests are padded with 4 bytes of null
2298 * data for some reason.
2300 * XXX - if that's always the case, the right way to do this would
2301 * be to have a "dissect_dcerpc_cn_nb" routine which strips off
2302 * the 4 bytes of null padding, and make that the dissector
2303 * used for "netbios".
2305 if (tvb_bytes_exist (tvb, offset, 4) &&
2306 tvb_memeql (tvb, offset, nulls, 4) == 0) {
2316 * Check if this looks like a C/O DCERPC call
2318 if (!tvb_bytes_exist (tvb, offset, sizeof (hdr))) {
2321 start_offset = offset;
2322 hdr.rpc_ver = tvb_get_guint8 (tvb, offset++);
2323 if (hdr.rpc_ver != 5)
2325 hdr.rpc_ver_minor = tvb_get_guint8 (tvb, offset++);
2326 if (hdr.rpc_ver_minor != 0 && hdr.rpc_ver_minor != 1)
2328 hdr.ptype = tvb_get_guint8 (tvb, offset++);
2332 if (check_col (pinfo->cinfo, COL_PROTOCOL))
2333 col_set_str (pinfo->cinfo, COL_PROTOCOL, "DCERPC");
2334 if (check_col (pinfo->cinfo, COL_INFO))
2335 col_add_str (pinfo->cinfo, COL_INFO, pckt_vals[hdr.ptype].strptr);
2337 hdr.flags = tvb_get_guint8 (tvb, offset++);
2338 tvb_memcpy (tvb, (guint8 *)hdr.drep, offset, sizeof (hdr.drep));
2339 offset += sizeof (hdr.drep);
2341 hdr.frag_len = dcerpc_tvb_get_ntohs (tvb, offset, hdr.drep);
2343 hdr.auth_len = dcerpc_tvb_get_ntohs (tvb, offset, hdr.drep);
2345 hdr.call_id = dcerpc_tvb_get_ntohl (tvb, offset, hdr.drep);
2348 offset = start_offset;
2349 if (can_desegment && pinfo->can_desegment
2350 && hdr.frag_len > tvb_length_remaining (tvb, offset)) {
2351 pinfo->desegment_offset = offset;
2352 pinfo->desegment_len = hdr.frag_len - tvb_length_remaining (tvb, offset);
2353 return 0; /* desegmentation required */
2356 if (check_col (pinfo->cinfo, COL_INFO))
2357 col_append_fstr (pinfo->cinfo, COL_INFO, ": call_id: %u", hdr.call_id);
2359 ti = proto_tree_add_item (tree, proto_dcerpc, tvb, offset, hdr.frag_len, FALSE);
2361 dcerpc_tree = proto_item_add_subtree (ti, ett_dcerpc);
2363 proto_tree_add_uint (dcerpc_tree, hf_dcerpc_ver, tvb, offset++, 1, hdr.rpc_ver);
2364 proto_tree_add_uint (dcerpc_tree, hf_dcerpc_ver_minor, tvb, offset++, 1, hdr.rpc_ver_minor);
2365 proto_tree_add_uint (dcerpc_tree, hf_dcerpc_packet_type, tvb, offset++, 1, hdr.ptype);
2366 tf = proto_tree_add_uint (dcerpc_tree, hf_dcerpc_cn_flags, tvb, offset, 1, hdr.flags);
2367 cn_flags_tree = proto_item_add_subtree (tf, ett_dcerpc_cn_flags);
2368 if (cn_flags_tree) {
2369 proto_tree_add_boolean (cn_flags_tree, hf_dcerpc_cn_flags_object, tvb, offset, 1, hdr.flags);
2370 proto_tree_add_boolean (cn_flags_tree, hf_dcerpc_cn_flags_maybe, tvb, offset, 1, hdr.flags);
2371 proto_tree_add_boolean (cn_flags_tree, hf_dcerpc_cn_flags_dne, tvb, offset, 1, hdr.flags);
2372 proto_tree_add_boolean (cn_flags_tree, hf_dcerpc_cn_flags_mpx, tvb, offset, 1, hdr.flags);
2373 proto_tree_add_boolean (cn_flags_tree, hf_dcerpc_cn_flags_reserved, tvb, offset, 1, hdr.flags);
2374 proto_tree_add_boolean (cn_flags_tree, hf_dcerpc_cn_flags_cancel_pending, tvb, offset, 1, hdr.flags);
2375 proto_tree_add_boolean (cn_flags_tree, hf_dcerpc_cn_flags_last_frag, tvb, offset, 1, hdr.flags);
2376 proto_tree_add_boolean (cn_flags_tree, hf_dcerpc_cn_flags_first_frag, tvb, offset, 1, hdr.flags);
2380 tf = proto_tree_add_bytes (dcerpc_tree, hf_dcerpc_drep, tvb, offset, 4, hdr.drep);
2381 drep_tree = proto_item_add_subtree (tf, ett_dcerpc_drep);
2383 proto_tree_add_uint(drep_tree, hf_dcerpc_drep_byteorder, tvb, offset, 1, hdr.drep[0] >> 4);
2384 proto_tree_add_uint(drep_tree, hf_dcerpc_drep_character, tvb, offset, 1, hdr.drep[0] & 0x0f);
2385 proto_tree_add_uint(drep_tree, hf_dcerpc_drep_fp, tvb, offset+1, 1, hdr.drep[1]);
2387 offset += sizeof (hdr.drep);
2389 proto_tree_add_uint (dcerpc_tree, hf_dcerpc_cn_frag_len, tvb, offset, 2, hdr.frag_len);
2392 proto_tree_add_uint (dcerpc_tree, hf_dcerpc_cn_auth_len, tvb, offset, 2, hdr.auth_len);
2395 proto_tree_add_uint (dcerpc_tree, hf_dcerpc_cn_call_id, tvb, offset, 4, hdr.call_id);
2401 * Packet type specific stuff is next.
2403 switch (hdr.ptype) {
2406 dissect_dcerpc_cn_bind (tvb, pinfo, dcerpc_tree, &hdr);
2411 dissect_dcerpc_cn_bind_ack (tvb, pinfo, dcerpc_tree, &hdr);
2415 dissect_dcerpc_cn_rqst (tvb, pinfo, dcerpc_tree, tree, &hdr);
2419 dissect_dcerpc_cn_resp (tvb, pinfo, dcerpc_tree, tree, &hdr);
2423 dissect_dcerpc_cn_fault (tvb, pinfo, dcerpc_tree, &hdr);
2427 dissect_dcerpc_cn_bind_nak (tvb, pinfo, dcerpc_tree, &hdr);
2433 * Nothing after the common header other than an authentication
2436 dissect_dcerpc_cn_auth (tvb, pinfo, dcerpc_tree, &hdr, NULL);
2441 * Nothing after the common header, not even an authentication
2447 /* might as well dissect the auth info */
2448 dissect_dcerpc_cn_auth (tvb, pinfo, dcerpc_tree, &hdr, NULL);
2451 return hdr.frag_len + padding;
2455 * DCERPC dissector for connection oriented calls over packet-oriented
2459 dissect_dcerpc_cn_pk (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
2462 * Only one PDU per transport packet, and only one transport
2465 if (dissect_dcerpc_cn (tvb, 0, pinfo, tree, FALSE) == -1) {
2467 * It wasn't a DCERPC PDU.
2479 * DCERPC dissector for connection oriented calls over byte-stream
2483 dissect_dcerpc_cn_bs (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
2487 gboolean ret = FALSE;
2490 * There may be multiple PDUs per transport packet; keep
2493 while (tvb_reported_length_remaining(tvb, offset) != 0) {
2494 pdu_len = dissect_dcerpc_cn (tvb, offset, pinfo, tree,
2495 dcerpc_cn_desegment);
2496 if (pdu_len == -1) {
2504 * Well, we've seen at least one DCERPC PDU.
2510 * Desegmentation required - bail now.
2516 * Step to the next PDU.
2524 dissect_dcerpc_dg_auth (tvbuff_t *tvb, int offset, proto_tree *dcerpc_tree,
2525 e_dce_dg_common_hdr_t *hdr, int *auth_level_p)
2528 * Initially set "*auth_level_p" to -1 to indicate that we haven't
2529 * yet seen any authentication level information.
2531 if (auth_level_p != NULL)
2535 * The authentication information is at the *end* of the PDU; in
2536 * request and response PDUs, the request and response stub data
2539 * If the full packet is here, and there's data past the end of the
2540 * packet body, then dissect the auth info.
2542 offset += hdr->frag_len;
2543 if (tvb_length_remaining(tvb, offset) > 0)
2544 proto_tree_add_text (dcerpc_tree, tvb, offset, -1, "Auth data");
2548 dissect_dcerpc_dg_cancel_ack (tvbuff_t *tvb, int offset, packet_info *pinfo,
2549 proto_tree *dcerpc_tree,
2550 e_dce_dg_common_hdr_t *hdr)
2554 offset = dissect_dcerpc_uint32 (tvb, offset, pinfo, dcerpc_tree,
2555 hdr->drep, hf_dcerpc_dg_cancel_vers,
2561 /* The only version we know about */
2562 offset = dissect_dcerpc_uint32 (tvb, offset, pinfo, dcerpc_tree,
2563 hdr->drep, hf_dcerpc_dg_cancel_id,
2565 offset = dissect_dcerpc_uint8 (tvb, offset, pinfo, dcerpc_tree,
2566 hdr->drep, hf_dcerpc_dg_server_accepting_cancels,
2573 dissect_dcerpc_dg_cancel (tvbuff_t *tvb, int offset, packet_info *pinfo,
2574 proto_tree *dcerpc_tree,
2575 e_dce_dg_common_hdr_t *hdr)
2579 offset = dissect_dcerpc_uint32 (tvb, offset, pinfo, dcerpc_tree,
2580 hdr->drep, hf_dcerpc_dg_cancel_vers,
2586 /* The only version we know about */
2587 offset = dissect_dcerpc_uint32 (tvb, offset, pinfo, dcerpc_tree,
2588 hdr->drep, hf_dcerpc_dg_cancel_id,
2590 /* XXX - are NDR booleans 32 bits? */
2591 offset = dissect_dcerpc_uint32 (tvb, offset, pinfo, dcerpc_tree,
2592 hdr->drep, hf_dcerpc_dg_server_accepting_cancels,
2599 dissect_dcerpc_dg_fack (tvbuff_t *tvb, int offset, packet_info *pinfo,
2600 proto_tree *dcerpc_tree,
2601 e_dce_dg_common_hdr_t *hdr)
2608 offset = dissect_dcerpc_uint8 (tvb, offset, pinfo, dcerpc_tree,
2609 hdr->drep, hf_dcerpc_dg_fack_vers,
2616 case 0: /* The only version documented in the DCE RPC 1.1 spec */
2617 case 1: /* This appears to be the same */
2618 offset = dissect_dcerpc_uint16 (tvb, offset, pinfo, dcerpc_tree,
2619 hdr->drep, hf_dcerpc_dg_fack_window_size,
2621 offset = dissect_dcerpc_uint32 (tvb, offset, pinfo, dcerpc_tree,
2622 hdr->drep, hf_dcerpc_dg_fack_max_tsdu,
2624 offset = dissect_dcerpc_uint32 (tvb, offset, pinfo, dcerpc_tree,
2625 hdr->drep, hf_dcerpc_dg_fack_max_frag_size,
2627 offset = dissect_dcerpc_uint16 (tvb, offset, pinfo, dcerpc_tree,
2628 hdr->drep, hf_dcerpc_dg_fack_serial_num,
2630 if (check_col (pinfo->cinfo, COL_INFO)) {
2631 col_append_fstr (pinfo->cinfo, COL_INFO, " serial_num: %u",
2634 offset = dissect_dcerpc_uint16 (tvb, offset, pinfo, dcerpc_tree,
2635 hdr->drep, hf_dcerpc_dg_fack_selack_len,
2637 for (i = 0; i < selack_len; i++) {
2638 offset = dissect_dcerpc_uint32 (tvb, offset, pinfo, dcerpc_tree,
2639 hdr->drep, hf_dcerpc_dg_fack_selack,
2648 dissect_dcerpc_dg_reject_fault (tvbuff_t *tvb, int offset, packet_info *pinfo,
2649 proto_tree *dcerpc_tree,
2650 e_dce_dg_common_hdr_t *hdr)
2654 offset = dissect_dcerpc_uint32 (tvb, offset, pinfo, dcerpc_tree,
2655 hdr->drep, hf_dcerpc_dg_status,
2658 if (check_col (pinfo->cinfo, COL_INFO)) {
2659 col_append_fstr (pinfo->cinfo, COL_INFO,
2661 val_to_str(status, reject_status_vals, "Unknown (0x%08x)"));
2666 dissect_dcerpc_dg_stub (tvbuff_t *tvb, int offset, packet_info *pinfo,
2667 proto_tree *dcerpc_tree, proto_tree *tree,
2668 e_dce_dg_common_hdr_t *hdr, dcerpc_info *di)
2670 int length, reported_length, stub_length;
2671 gboolean save_fragmented;
2672 fragment_data *fd_head;
2674 if (check_col (pinfo->cinfo, COL_INFO)) {
2675 col_append_fstr (pinfo->cinfo, COL_INFO, " opnum: %u",
2676 di->call_data->opnum);
2679 length = tvb_length_remaining (tvb, offset);
2680 reported_length = tvb_reported_length_remaining (tvb, offset);
2681 stub_length = hdr->frag_len;
2682 if (length > stub_length)
2683 length = stub_length;
2684 if (reported_length > stub_length)
2685 reported_length = stub_length;
2687 save_fragmented = pinfo->fragmented;
2689 /* If we don't have reassembly enabled, or this packet contains
2690 the entire PDU, or if this is a short frame (or a frame
2691 not reassembled at a lower layer) that doesn't include all
2692 the data in the fragment, just call the handoff directly if
2693 this is the first fragment or the PDU isn't fragmented. */
2694 if( (!dcerpc_reassemble) || !(hdr->flags1 & PFCL1_FRAG) ||
2695 stub_length > length ) {
2696 if(hdr->frag_num == 0) {
2697 /* First fragment, possibly the only fragment */
2700 * XXX - authentication level?
2702 pinfo->fragmented = (hdr->flags1 & PFCL1_FRAG);
2703 dcerpc_try_handoff (pinfo, tree, dcerpc_tree,
2704 tvb_new_subset (tvb, offset, length,
2706 0, hdr->drep, di, 0);
2708 /* PDU is fragmented and this isn't the first fragment */
2709 if (check_col(pinfo->cinfo, COL_INFO)) {
2710 col_append_fstr(pinfo->cinfo, COL_INFO, " [DCE/RPC fragment]");
2714 proto_tree_add_text (dcerpc_tree, tvb, offset, length,
2715 "Fragment data (%d byte%s)", length,
2716 plurality(length, "", "s"));
2721 /* Reassembly is enabled, the PDU is fragmented, and
2722 we have all the data in the fragment; the first two
2723 of those mean we should attempt reassembly, and the
2724 third means we can attempt reassembly. */
2727 proto_tree_add_text (dcerpc_tree, tvb, offset, length,
2728 "Fragment data (%d byte%s)", length,
2729 plurality(length, "", "s"));
2733 fd_head = fragment_add_seq(tvb, offset, pinfo,
2734 hdr->seqnum, dcerpc_cl_reassemble_table,
2735 hdr->frag_num, length, !(hdr->flags1 & PFCL1_LASTFRAG));
2736 if (fd_head != NULL) {
2737 /* We completed reassembly */
2740 next_tvb = tvb_new_real_data(fd_head->data, fd_head->len, fd_head->len);
2741 tvb_set_child_real_data_tvbuff(tvb, next_tvb);
2742 add_new_data_source(pinfo, next_tvb, "Reassembled DCE/RPC");
2743 show_fragment_seq_tree(fd_head, &dcerpc_frag_items,
2744 dcerpc_tree, pinfo, next_tvb);
2747 * XXX - authentication level?
2749 pinfo->fragmented = FALSE;
2750 dcerpc_try_handoff (pinfo, tree, dcerpc_tree, next_tvb,
2751 0, hdr->drep, di, 0);
2753 /* Reassembly isn't completed yet */
2754 if (check_col(pinfo->cinfo, COL_INFO)) {
2755 col_append_fstr(pinfo->cinfo, COL_INFO, " [DCE/RPC fragment]");
2759 pinfo->fragmented = save_fragmented;
2763 dissect_dcerpc_dg_rqst (tvbuff_t *tvb, int offset, packet_info *pinfo,
2764 proto_tree *dcerpc_tree, proto_tree *tree,
2765 e_dce_dg_common_hdr_t *hdr, conversation_t *conv)
2768 dcerpc_call_value *value, v;
2770 if(!(pinfo->fd->flags.visited)){
2771 dcerpc_call_value *call_value;
2772 dcerpc_call_key *call_key;
2774 call_key=g_mem_chunk_alloc (dcerpc_call_key_chunk);
2775 call_key->conv=conv;
2776 call_key->call_id=hdr->seqnum;
2777 call_key->smb_fid=get_smb_fid(pinfo->private_data);
2779 call_value=g_mem_chunk_alloc (dcerpc_call_value_chunk);
2780 call_value->uuid = hdr->if_id;
2781 call_value->ver = hdr->if_ver;
2782 call_value->opnum = hdr->opnum;
2783 call_value->req_frame=pinfo->fd->num;
2784 call_value->rep_frame=0;
2785 call_value->max_ptr=0;
2786 call_value->private_data = NULL;
2787 g_hash_table_insert (dcerpc_calls, call_key, call_value);
2789 g_hash_table_insert (dcerpc_matched, (void *)pinfo->fd->num, call_value);
2792 value=g_hash_table_lookup(dcerpc_matched, (void *)pinfo->fd->num);
2794 v.uuid = hdr->if_id;
2795 v.ver = hdr->if_ver;
2796 v.opnum = hdr->opnum;
2797 v.req_frame = pinfo->fd->num;
2800 v.private_data=NULL;
2805 di.call_id = hdr->seqnum;
2808 di.call_data = value;
2810 dissect_dcerpc_dg_stub (tvb, offset, pinfo, dcerpc_tree, tree, hdr, &di);
2814 dissect_dcerpc_dg_resp (tvbuff_t *tvb, int offset, packet_info *pinfo,
2815 proto_tree *dcerpc_tree, proto_tree *tree,
2816 e_dce_dg_common_hdr_t *hdr, conversation_t *conv)
2819 dcerpc_call_value *value, v;
2821 if(!(pinfo->fd->flags.visited)){
2822 dcerpc_call_value *call_value;
2823 dcerpc_call_key call_key;
2826 call_key.call_id=hdr->seqnum;
2827 call_key.smb_fid=get_smb_fid(pinfo->private_data);
2829 if((call_value=g_hash_table_lookup(dcerpc_calls, &call_key))){
2830 g_hash_table_insert (dcerpc_matched, (void *)pinfo->fd->num, call_value);
2831 if(call_value->rep_frame==0){
2832 call_value->rep_frame=pinfo->fd->num;
2837 value=g_hash_table_lookup(dcerpc_matched, (void *)pinfo->fd->num);
2839 v.uuid = hdr->if_id;
2840 v.ver = hdr->if_ver;
2841 v.opnum = hdr->opnum;
2843 v.rep_frame=pinfo->fd->num;
2844 v.private_data=NULL;
2852 di.call_data = value;
2854 dissect_dcerpc_dg_stub (tvb, offset, pinfo, dcerpc_tree, tree, hdr, &di);
2858 * DCERPC dissector for connectionless calls
2861 dissect_dcerpc_dg (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
2863 proto_item *ti = NULL;
2864 proto_item *tf = NULL;
2865 proto_tree *dcerpc_tree = NULL;
2866 proto_tree *dg_flags1_tree = NULL;
2867 proto_tree *dg_flags2_tree = NULL;
2868 proto_tree *drep_tree = NULL;
2869 e_dce_dg_common_hdr_t hdr;
2871 conversation_t *conv;
2874 * Check if this looks like a CL DCERPC call. All dg packets
2875 * have an 80 byte header on them. Which starts with
2876 * version (4), pkt_type.
2878 if (!tvb_bytes_exist (tvb, 0, sizeof (hdr))) {
2881 hdr.rpc_ver = tvb_get_guint8 (tvb, offset++);
2882 if (hdr.rpc_ver != 4)
2884 hdr.ptype = tvb_get_guint8 (tvb, offset++);
2888 if (check_col (pinfo->cinfo, COL_PROTOCOL))
2889 col_set_str (pinfo->cinfo, COL_PROTOCOL, "DCERPC");
2890 if (check_col (pinfo->cinfo, COL_INFO))
2891 col_add_str (pinfo->cinfo, COL_INFO, pckt_vals[hdr.ptype].strptr);
2893 hdr.flags1 = tvb_get_guint8 (tvb, offset++);
2894 hdr.flags2 = tvb_get_guint8 (tvb, offset++);
2895 tvb_memcpy (tvb, (guint8 *)hdr.drep, offset, sizeof (hdr.drep));
2896 offset += sizeof (hdr.drep);
2897 hdr.serial_hi = tvb_get_guint8 (tvb, offset++);
2898 dcerpc_tvb_get_uuid (tvb, offset, hdr.drep, &hdr.obj_id);
2900 dcerpc_tvb_get_uuid (tvb, offset, hdr.drep, &hdr.if_id);
2902 dcerpc_tvb_get_uuid (tvb, offset, hdr.drep, &hdr.act_id);
2904 hdr.server_boot = dcerpc_tvb_get_ntohl (tvb, offset, hdr.drep);
2906 hdr.if_ver = dcerpc_tvb_get_ntohl (tvb, offset, hdr.drep);
2908 hdr.seqnum = dcerpc_tvb_get_ntohl (tvb, offset, hdr.drep);
2910 hdr.opnum = dcerpc_tvb_get_ntohs (tvb, offset, hdr.drep);
2912 hdr.ihint = dcerpc_tvb_get_ntohs (tvb, offset, hdr.drep);
2914 hdr.ahint = dcerpc_tvb_get_ntohs (tvb, offset, hdr.drep);
2916 hdr.frag_len = dcerpc_tvb_get_ntohs (tvb, offset, hdr.drep);
2918 hdr.frag_num = dcerpc_tvb_get_ntohs (tvb, offset, hdr.drep);
2920 hdr.auth_proto = tvb_get_guint8 (tvb, offset++);
2921 hdr.serial_lo = tvb_get_guint8 (tvb, offset++);
2924 ti = proto_tree_add_item (tree, proto_dcerpc, tvb, 0, -1, FALSE);
2926 dcerpc_tree = proto_item_add_subtree(ti, ett_dcerpc);
2932 proto_tree_add_uint (dcerpc_tree, hf_dcerpc_ver, tvb, offset, 1, hdr.rpc_ver);
2936 proto_tree_add_uint (dcerpc_tree, hf_dcerpc_packet_type, tvb, offset, 1, hdr.ptype);
2940 tf = proto_tree_add_uint (dcerpc_tree, hf_dcerpc_dg_flags1, tvb, offset, 1, hdr.flags1);
2941 dg_flags1_tree = proto_item_add_subtree (tf, ett_dcerpc_dg_flags1);
2942 if (dg_flags1_tree) {
2943 proto_tree_add_boolean (dg_flags1_tree, hf_dcerpc_dg_flags1_rsrvd_80, tvb, offset, 1, hdr.flags1);
2944 proto_tree_add_boolean (dg_flags1_tree, hf_dcerpc_dg_flags1_broadcast, tvb, offset, 1, hdr.flags1);
2945 proto_tree_add_boolean (dg_flags1_tree, hf_dcerpc_dg_flags1_idempotent, tvb, offset, 1, hdr.flags1);
2946 proto_tree_add_boolean (dg_flags1_tree, hf_dcerpc_dg_flags1_maybe, tvb, offset, 1, hdr.flags1);
2947 proto_tree_add_boolean (dg_flags1_tree, hf_dcerpc_dg_flags1_nofack, tvb, offset, 1, hdr.flags1);
2948 proto_tree_add_boolean (dg_flags1_tree, hf_dcerpc_dg_flags1_frag, tvb, offset, 1, hdr.flags1);
2949 proto_tree_add_boolean (dg_flags1_tree, hf_dcerpc_dg_flags1_last_frag, tvb, offset, 1, hdr.flags1);
2950 proto_tree_add_boolean (dg_flags1_tree, hf_dcerpc_dg_flags1_rsrvd_01, tvb, offset, 1, hdr.flags1);
2956 tf = proto_tree_add_uint (dcerpc_tree, hf_dcerpc_dg_flags2, tvb, offset, 1, hdr.flags2);
2957 dg_flags2_tree = proto_item_add_subtree (tf, ett_dcerpc_dg_flags2);
2958 if (dg_flags2_tree) {
2959 proto_tree_add_boolean (dg_flags2_tree, hf_dcerpc_dg_flags2_rsrvd_80, tvb, offset, 1, hdr.flags2);
2960 proto_tree_add_boolean (dg_flags2_tree, hf_dcerpc_dg_flags2_rsrvd_40, tvb, offset, 1, hdr.flags2);
2961 proto_tree_add_boolean (dg_flags2_tree, hf_dcerpc_dg_flags2_rsrvd_20, tvb, offset, 1, hdr.flags2);
2962 proto_tree_add_boolean (dg_flags2_tree, hf_dcerpc_dg_flags2_rsrvd_10, tvb, offset, 1, hdr.flags2);
2963 proto_tree_add_boolean (dg_flags2_tree, hf_dcerpc_dg_flags2_rsrvd_08, tvb, offset, 1, hdr.flags2);
2964 proto_tree_add_boolean (dg_flags2_tree, hf_dcerpc_dg_flags2_rsrvd_04, tvb, offset, 1, hdr.flags2);
2965 proto_tree_add_boolean (dg_flags2_tree, hf_dcerpc_dg_flags2_cancel_pending, tvb, offset, 1, hdr.flags2);
2966 proto_tree_add_boolean (dg_flags2_tree, hf_dcerpc_dg_flags2_rsrvd_01, tvb, offset, 1, hdr.flags2);
2972 tf = proto_tree_add_bytes (dcerpc_tree, hf_dcerpc_drep, tvb, offset, sizeof (hdr.drep), hdr.drep);
2973 drep_tree = proto_item_add_subtree (tf, ett_dcerpc_drep);
2975 proto_tree_add_uint(drep_tree, hf_dcerpc_drep_byteorder, tvb, offset, 1, hdr.drep[0] >> 4);
2976 proto_tree_add_uint(drep_tree, hf_dcerpc_drep_character, tvb, offset, 1, hdr.drep[0] & 0x0f);
2977 proto_tree_add_uint(drep_tree, hf_dcerpc_drep_fp, tvb, offset+1, 1, hdr.drep[1]);
2980 offset += sizeof (hdr.drep);
2983 proto_tree_add_uint (dcerpc_tree, hf_dcerpc_dg_serial_hi, tvb, offset, 1, hdr.serial_hi);
2987 proto_tree_add_string_format (dcerpc_tree, hf_dcerpc_obj_id, tvb,
2989 "Object: %08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
2990 hdr.obj_id.Data1, hdr.obj_id.Data2, hdr.obj_id.Data3,
2991 hdr.obj_id.Data4[0],
2992 hdr.obj_id.Data4[1],
2993 hdr.obj_id.Data4[2],
2994 hdr.obj_id.Data4[3],
2995 hdr.obj_id.Data4[4],
2996 hdr.obj_id.Data4[5],
2997 hdr.obj_id.Data4[6],
2998 hdr.obj_id.Data4[7]);
3003 proto_tree_add_string_format (dcerpc_tree, hf_dcerpc_dg_if_id, tvb,
3005 "Interface: %08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
3006 hdr.if_id.Data1, hdr.if_id.Data2, hdr.if_id.Data3,
3014 hdr.if_id.Data4[7]);
3019 proto_tree_add_string_format (dcerpc_tree, hf_dcerpc_dg_act_id, tvb,
3021 "Activity: %08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
3022 hdr.act_id.Data1, hdr.act_id.Data2, hdr.act_id.Data3,
3023 hdr.act_id.Data4[0],
3024 hdr.act_id.Data4[1],
3025 hdr.act_id.Data4[2],
3026 hdr.act_id.Data4[3],
3027 hdr.act_id.Data4[4],
3028 hdr.act_id.Data4[5],
3029 hdr.act_id.Data4[6],
3030 hdr.act_id.Data4[7]);
3035 proto_tree_add_uint (dcerpc_tree, hf_dcerpc_dg_server_boot, tvb, offset, 4, hdr.server_boot);
3039 proto_tree_add_uint (dcerpc_tree, hf_dcerpc_dg_if_ver, tvb, offset, 4, hdr.if_ver);
3043 proto_tree_add_uint (dcerpc_tree, hf_dcerpc_dg_seqnum, tvb, offset, 4, hdr.seqnum);
3044 if (check_col (pinfo->cinfo, COL_INFO)) {
3045 col_append_fstr (pinfo->cinfo, COL_INFO, ": seq_num: %u", hdr.seqnum);
3050 proto_tree_add_uint (dcerpc_tree, hf_dcerpc_opnum, tvb, offset, 2, hdr.opnum);
3054 proto_tree_add_uint (dcerpc_tree, hf_dcerpc_dg_ihint, tvb, offset, 2, hdr.ihint);
3058 proto_tree_add_uint (dcerpc_tree, hf_dcerpc_dg_ahint, tvb, offset, 2, hdr.ahint);
3062 proto_tree_add_uint (dcerpc_tree, hf_dcerpc_dg_frag_len, tvb, offset, 2, hdr.frag_len);
3066 proto_tree_add_uint (dcerpc_tree, hf_dcerpc_dg_frag_num, tvb, offset, 2, hdr.frag_num);
3067 if (check_col (pinfo->cinfo, COL_INFO)) {
3068 if (hdr.flags1 & PFCL1_FRAG) {
3069 /* Fragmented - put the fragment number into the Info column */
3070 col_append_fstr (pinfo->cinfo, COL_INFO, " frag_num: %u",
3077 proto_tree_add_uint (dcerpc_tree, hf_dcerpc_dg_auth_proto, tvb, offset, 1, hdr.auth_proto);
3081 proto_tree_add_uint (dcerpc_tree, hf_dcerpc_dg_serial_lo, tvb, offset, 1, hdr.serial_lo);
3082 if (check_col (pinfo->cinfo, COL_INFO)) {
3083 if (hdr.flags1 & PFCL1_FRAG) {
3084 /* Fragmented - put the serial number into the Info column */
3085 col_append_fstr (pinfo->cinfo, COL_INFO, " serial_num: %u",
3086 (hdr.serial_hi << 8) | hdr.serial_lo);
3093 * XXX - for Kerberos, we can get a protection level; if it's
3094 * DCE_C_AUTHN_LEVEL_PKT_PRIVACY, we can't dissect the
3097 dissect_dcerpc_dg_auth (tvb, offset, dcerpc_tree, &hdr, NULL);
3101 * keeping track of the conversation shouldn't really be necessary
3102 * for connectionless packets, because everything we need to know
3103 * to dissect is in the header for each packet. Unfortunately,
3104 * Microsoft's implementation is buggy and often puts the
3105 * completely wrong if_id in the header. go figure. So, keep
3106 * track of the seqnum and use that if possible. Note: that's not
3107 * completely correct. It should really be done based on both the
3108 * activity_id and seqnum. I haven't seen anywhere that it would
3109 * make a difference, but for future reference...
3111 conv = find_conversation (&pinfo->src, &pinfo->dst, pinfo->ptype,
3112 pinfo->srcport, pinfo->destport, 0);
3114 conv = conversation_new (&pinfo->src, &pinfo->dst, pinfo->ptype,
3115 pinfo->srcport, pinfo->destport, 0);
3119 * Packet type specific stuff is next.
3122 switch (hdr.ptype) {
3124 case PDU_CANCEL_ACK:
3125 /* Body is optional */
3126 /* XXX - we assume "frag_len" is the length of the body */
3127 if (hdr.frag_len != 0)
3128 dissect_dcerpc_dg_cancel_ack (tvb, offset, pinfo, dcerpc_tree, &hdr);
3133 * XXX - The DCE RPC 1.1 spec doesn't say the body is optional,
3134 * but in at least one capture none of the Cl_cancel PDUs had a
3137 /* XXX - we assume "frag_len" is the length of the body */
3138 if (hdr.frag_len != 0)
3139 dissect_dcerpc_dg_cancel (tvb, offset, pinfo, dcerpc_tree, &hdr);
3143 /* Body is optional; if present, it's the same as PDU_FACK */
3144 /* XXX - we assume "frag_len" is the length of the body */
3145 if (hdr.frag_len != 0)
3146 dissect_dcerpc_dg_fack (tvb, offset, pinfo, dcerpc_tree, &hdr);
3150 dissect_dcerpc_dg_fack (tvb, offset, pinfo, dcerpc_tree, &hdr);
3155 dissect_dcerpc_dg_reject_fault (tvb, offset, pinfo, dcerpc_tree, &hdr);
3159 dissect_dcerpc_dg_rqst (tvb, offset, pinfo, dcerpc_tree, tree, &hdr, conv);
3163 dissect_dcerpc_dg_resp (tvb, offset, pinfo, dcerpc_tree, tree, &hdr, conv);
3166 /* these requests have no body */
3178 dcerpc_init_protocol (void)
3180 /* structures and data for BIND */
3182 g_hash_table_destroy (dcerpc_binds);
3184 dcerpc_binds = g_hash_table_new (dcerpc_bind_hash, dcerpc_bind_equal);
3186 if (dcerpc_bind_key_chunk){
3187 g_mem_chunk_destroy (dcerpc_bind_key_chunk);
3189 dcerpc_bind_key_chunk = g_mem_chunk_new ("dcerpc_bind_key_chunk",
3190 sizeof (dcerpc_bind_key),
3191 200 * sizeof (dcerpc_bind_key),
3193 if (dcerpc_bind_value_chunk){
3194 g_mem_chunk_destroy (dcerpc_bind_value_chunk);
3196 dcerpc_bind_value_chunk = g_mem_chunk_new ("dcerpc_bind_value_chunk",
3197 sizeof (dcerpc_bind_value),
3198 200 * sizeof (dcerpc_bind_value),
3200 /* structures and data for CALL */
3202 g_hash_table_destroy (dcerpc_calls);
3204 dcerpc_calls = g_hash_table_new (dcerpc_call_hash, dcerpc_call_equal);
3205 if (dcerpc_call_key_chunk){
3206 g_mem_chunk_destroy (dcerpc_call_key_chunk);
3208 dcerpc_call_key_chunk = g_mem_chunk_new ("dcerpc_call_key_chunk",
3209 sizeof (dcerpc_call_key),
3210 200 * sizeof (dcerpc_call_key),
3212 if (dcerpc_call_value_chunk){
3213 g_mem_chunk_destroy (dcerpc_call_value_chunk);
3215 dcerpc_call_value_chunk = g_mem_chunk_new ("dcerpc_call_value_chunk",
3216 sizeof (dcerpc_call_value),
3217 200 * sizeof (dcerpc_call_value),
3220 /* structure and data for MATCHED */
3221 if (dcerpc_matched){
3222 g_hash_table_destroy (dcerpc_matched);
3224 dcerpc_matched = g_hash_table_new (dcerpc_matched_hash, dcerpc_matched_equal);
3229 proto_register_dcerpc (void)
3231 static hf_register_info hf[] = {
3232 { &hf_dcerpc_request_in,
3233 { "Request in", "dcerpc.request_in", FT_UINT32, BASE_DEC,
3234 NULL, 0, "This packet is a response to the packet in this frame", HFILL }},
3235 { &hf_dcerpc_response_in,
3236 { "Response in", "dcerpc.response_in", FT_UINT32, BASE_DEC,
3237 NULL, 0, "The response to this packet is in this packet", HFILL }},
3238 { &hf_dcerpc_referent_id,
3239 { "Referent ID", "dcerpc.referent_id", FT_UINT32, BASE_HEX,
3240 NULL, 0, "Referent ID for this NDR encoded pointer", HFILL }},
3242 { "Version", "dcerpc.ver", FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
3243 { &hf_dcerpc_ver_minor,
3244 { "Version (minor)", "dcerpc.ver_minor", FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
3245 { &hf_dcerpc_packet_type,
3246 { "Packet type", "dcerpc.pkt_type", FT_UINT8, BASE_DEC, VALS (pckt_vals), 0x0, "", HFILL }},
3247 { &hf_dcerpc_cn_flags,
3248 { "Packet Flags", "dcerpc.cn_flags", FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL }},
3249 { &hf_dcerpc_cn_flags_first_frag,
3250 { "First Frag", "dcerpc.cn_flags.first_frag", FT_BOOLEAN, 8, TFS (&flags_set_truth), PFC_FIRST_FRAG, "", HFILL }},
3251 { &hf_dcerpc_cn_flags_last_frag,
3252 { "Last Frag", "dcerpc.cn_flags.last_frag", FT_BOOLEAN, 8, TFS (&flags_set_truth), PFC_LAST_FRAG, "", HFILL }},
3253 { &hf_dcerpc_cn_flags_cancel_pending,
3254 { "Cancel Pending", "dcerpc.cn_flags.cancel_pending", FT_BOOLEAN, 8, TFS (&flags_set_truth), PFC_PENDING_CANCEL, "", HFILL }},
3255 { &hf_dcerpc_cn_flags_reserved,
3256 { "Reserved", "dcerpc.cn_flags.reserved", FT_BOOLEAN, 8, TFS (&flags_set_truth), PFC_RESERVED_1, "", HFILL }},
3257 { &hf_dcerpc_cn_flags_mpx,
3258 { "Multiplex", "dcerpc.cn_flags.mpx", FT_BOOLEAN, 8, TFS (&flags_set_truth), PFC_CONC_MPX, "", HFILL }},
3259 { &hf_dcerpc_cn_flags_dne,
3260 { "Did Not Execute", "dcerpc.cn_flags.dne", FT_BOOLEAN, 8, TFS (&flags_set_truth), PFC_DID_NOT_EXECUTE, "", HFILL }},
3261 { &hf_dcerpc_cn_flags_maybe,
3262 { "Maybe", "dcerpc.cn_flags.maybe", FT_BOOLEAN, 8, TFS (&flags_set_truth), PFC_MAYBE, "", HFILL }},
3263 { &hf_dcerpc_cn_flags_object,
3264 { "Object", "dcerpc.cn_flags.object", FT_BOOLEAN, 8, TFS (&flags_set_truth), PFC_OBJECT_UUID, "", HFILL }},
3266 { "Data Representation", "dcerpc.drep", FT_BYTES, BASE_HEX, NULL, 0x0, "", HFILL }},
3267 { &hf_dcerpc_drep_byteorder,
3268 { "Byte order", "dcerpc.drep.byteorder", FT_UINT8, BASE_DEC, VALS (drep_byteorder_vals), 0x0, "", HFILL }},
3269 { &hf_dcerpc_drep_character,
3270 { "Character", "dcerpc.drep.character", FT_UINT8, BASE_DEC, VALS (drep_character_vals), 0x0, "", HFILL }},
3271 { &hf_dcerpc_drep_fp,
3272 { "Floating-point", "dcerpc.drep.fp", FT_UINT8, BASE_DEC, VALS (drep_fp_vals), 0x0, "", HFILL }},
3273 { &hf_dcerpc_cn_frag_len,
3274 { "Frag Length", "dcerpc.cn_frag_len", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL }},
3275 { &hf_dcerpc_cn_auth_len,
3276 { "Auth Length", "dcerpc.cn_auth_len", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL }},
3277 { &hf_dcerpc_cn_call_id,
3278 { "Call ID", "dcerpc.cn_call_id", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
3279 { &hf_dcerpc_cn_max_xmit,
3280 { "Max Xmit Frag", "dcerpc.cn_max_xmit", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL }},
3281 { &hf_dcerpc_cn_max_recv,
3282 { "Max Recv Frag", "dcerpc.cn_max_recv", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL }},
3283 { &hf_dcerpc_cn_assoc_group,
3284 { "Assoc Group", "dcerpc.cn_assoc_group", FT_UINT32, BASE_HEX, NULL, 0x0, "", HFILL }},
3285 { &hf_dcerpc_cn_num_ctx_items,
3286 { "Num Ctx Items", "dcerpc.cn_num_ctx_items", FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
3287 { &hf_dcerpc_cn_ctx_id,
3288 { "Context ID", "dcerpc.cn_ctx_id", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL }},
3289 { &hf_dcerpc_cn_num_trans_items,
3290 { "Num Trans Items", "dcerpc.cn_num_trans_items", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL }},
3291 { &hf_dcerpc_cn_bind_if_id,
3292 { "Interface UUID", "dcerpc.cn_bind_to_uuid", FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL }},
3293 { &hf_dcerpc_cn_bind_if_ver,
3294 { "Interface Ver", "dcerpc.cn_bind_if_ver", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL }},
3295 { &hf_dcerpc_cn_bind_if_ver_minor,
3296 { "Interface Ver Minor", "dcerpc.cn_bind_if_ver_minor", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL }},
3297 { &hf_dcerpc_cn_bind_trans_id,
3298 { "Transfer Syntax", "dcerpc.cn_bind_trans_id", FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL }},
3299 { &hf_dcerpc_cn_bind_trans_ver,
3300 { "Syntax ver", "dcerpc.cn_bind_trans_ver", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
3301 { &hf_dcerpc_cn_alloc_hint,
3302 { "Alloc hint", "dcerpc.cn_alloc_hint", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
3303 { &hf_dcerpc_cn_sec_addr_len,
3304 { "Scndry Addr len", "dcerpc.cn_sec_addr_len", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL }},
3305 { &hf_dcerpc_cn_sec_addr,
3306 { "Scndry Addr", "dcerpc.cn_sec_addr", FT_STRINGZ, BASE_NONE, NULL, 0x0, "", HFILL }},
3307 { &hf_dcerpc_cn_num_results,
3308 { "Num results", "dcerpc.cn_num_results", FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
3309 { &hf_dcerpc_cn_ack_result,
3310 { "Ack result", "dcerpc.cn_ack_result", FT_UINT16, BASE_DEC, VALS(p_cont_result_vals), 0x0, "", HFILL }},
3311 { &hf_dcerpc_cn_ack_reason,
3312 { "Ack reason", "dcerpc.cn_ack_reason", FT_UINT16, BASE_DEC, VALS(p_provider_reason_vals), 0x0, "", HFILL }},
3313 { &hf_dcerpc_cn_ack_trans_id,
3314 { "Transfer Syntax", "dcerpc.cn_ack_trans_id", FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL }},
3315 { &hf_dcerpc_cn_ack_trans_ver,
3316 { "Syntax ver", "dcerpc.cn_ack_trans_ver", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
3317 { &hf_dcerpc_cn_reject_reason,
3318 { "Reject reason", "dcerpc.cn_reject_reason", FT_UINT16, BASE_DEC, VALS(reject_reason_vals), 0x0, "", HFILL }},
3319 { &hf_dcerpc_cn_num_protocols,
3320 { "Number of protocols", "dcerpc.cn_num_protocols", FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
3321 { &hf_dcerpc_cn_protocol_ver_major,
3322 { "Protocol major version", "dcerpc.cn_protocol_ver_major", FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
3323 { &hf_dcerpc_cn_protocol_ver_minor,
3324 { "Protocol minor version", "dcerpc.cn_protocol_ver_minor", FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
3325 { &hf_dcerpc_cn_cancel_count,
3326 { "Cancel count", "dcerpc.cn_cancel_count", FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
3327 { &hf_dcerpc_cn_status,
3328 { "Status", "dcerpc.cn_status", FT_UINT32, BASE_HEX, VALS(reject_status_vals), 0x0, "", HFILL }},
3329 { &hf_dcerpc_auth_type,
3330 { "Auth type", "dcerpc.auth_type", FT_UINT8, BASE_DEC, VALS (authn_protocol_vals), 0x0, "", HFILL }},
3331 { &hf_dcerpc_auth_level,
3332 { "Auth level", "dcerpc.auth_level", FT_UINT8, BASE_DEC, VALS (authn_level_vals), 0x0, "", HFILL }},
3333 { &hf_dcerpc_auth_pad_len,
3334 { "Auth pad len", "dcerpc.auth_pad_len", FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
3335 { &hf_dcerpc_auth_rsrvd,
3336 { "Auth Rsrvd", "dcerpc.auth_rsrvd", FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
3337 { &hf_dcerpc_auth_ctx_id,
3338 { "Auth Context ID", "dcerpc.auth_ctx_id", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
3339 { &hf_dcerpc_dg_flags1,
3340 { "Flags1", "dcerpc.dg_flags1", FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL }},
3341 { &hf_dcerpc_dg_flags1_rsrvd_01,
3342 { "Reserved", "dcerpc.dg_flags1_rsrvd_01", FT_BOOLEAN, 8, TFS (&flags_set_truth), PFCL1_RESERVED_01, "", HFILL }},
3343 { &hf_dcerpc_dg_flags1_last_frag,
3344 { "Last Fragment", "dcerpc.dg_flags1_last_frag", FT_BOOLEAN, 8, TFS (&flags_set_truth), PFCL1_LASTFRAG, "", HFILL }},
3345 { &hf_dcerpc_dg_flags1_frag,
3346 { "Fragment", "dcerpc.dg_flags1_frag", FT_BOOLEAN, 8, TFS (&flags_set_truth), PFCL1_FRAG, "", HFILL }},
3347 { &hf_dcerpc_dg_flags1_nofack,
3348 { "No Fack", "dcerpc.dg_flags1_nofack", FT_BOOLEAN, 8, TFS (&flags_set_truth), PFCL1_NOFACK, "", HFILL }},
3349 { &hf_dcerpc_dg_flags1_maybe,
3350 { "Maybe", "dcerpc.dg_flags1_maybe", FT_BOOLEAN, 8, TFS (&flags_set_truth), PFCL1_MAYBE, "", HFILL }},
3351 { &hf_dcerpc_dg_flags1_idempotent,
3352 { "Idempotent", "dcerpc.dg_flags1_idempotent", FT_BOOLEAN, 8, TFS (&flags_set_truth), PFCL1_IDEMPOTENT, "", HFILL }},
3353 { &hf_dcerpc_dg_flags1_broadcast,
3354 { "Broadcast", "dcerpc.dg_flags1_broadcast", FT_BOOLEAN, 8, TFS (&flags_set_truth), PFCL1_BROADCAST, "", HFILL }},
3355 { &hf_dcerpc_dg_flags1_rsrvd_80,
3356 { "Reserved", "dcerpc.dg_flags1_rsrvd_80", FT_BOOLEAN, 8, TFS (&flags_set_truth), PFCL1_RESERVED_80, "", HFILL }},
3357 { &hf_dcerpc_dg_flags2,
3358 { "Flags2", "dcerpc.dg_flags2", FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL }},
3359 { &hf_dcerpc_dg_flags2_rsrvd_01,
3360 { "Reserved", "dcerpc.dg_flags2_rsrvd_01", FT_BOOLEAN, 8, TFS (&flags_set_truth), PFCL2_RESERVED_01, "", HFILL }},
3361 { &hf_dcerpc_dg_flags2_cancel_pending,
3362 { "Cancel Pending", "dcerpc.dg_flags2_cancel_pending", FT_BOOLEAN, 8, TFS (&flags_set_truth), PFCL2_CANCEL_PENDING, "", HFILL }},
3363 { &hf_dcerpc_dg_flags2_rsrvd_04,
3364 { "Reserved", "dcerpc.dg_flags2_rsrvd_04", FT_BOOLEAN, 8, TFS (&flags_set_truth), PFCL2_RESERVED_04, "", HFILL }},
3365 { &hf_dcerpc_dg_flags2_rsrvd_08,
3366 { "Reserved", "dcerpc.dg_flags2_rsrvd_08", FT_BOOLEAN, 8, TFS (&flags_set_truth), PFCL2_RESERVED_08, "", HFILL }},
3367 { &hf_dcerpc_dg_flags2_rsrvd_10,
3368 { "Reserved", "dcerpc.dg_flags2_rsrvd_10", FT_BOOLEAN, 8, TFS (&flags_set_truth), PFCL2_RESERVED_10, "", HFILL }},
3369 { &hf_dcerpc_dg_flags2_rsrvd_20,
3370 { "Reserved", "dcerpc.dg_flags2_rsrvd_20", FT_BOOLEAN, 8, TFS (&flags_set_truth), PFCL2_RESERVED_20, "", HFILL }},
3371 { &hf_dcerpc_dg_flags2_rsrvd_40,
3372 { "Reserved", "dcerpc.dg_flags2_rsrvd_40", FT_BOOLEAN, 8, TFS (&flags_set_truth), PFCL2_RESERVED_40, "", HFILL }},
3373 { &hf_dcerpc_dg_flags2_rsrvd_80,
3374 { "Reserved", "dcerpc.dg_flags2_rsrvd_80", FT_BOOLEAN, 8, TFS (&flags_set_truth), PFCL2_RESERVED_80, "", HFILL }},
3375 { &hf_dcerpc_dg_serial_lo,
3376 { "Serial Low", "dcerpc.dg_serial_lo", FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL }},
3377 { &hf_dcerpc_dg_serial_hi,
3378 { "Serial High", "dcerpc.dg_serial_hi", FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL }},
3379 { &hf_dcerpc_dg_ahint,
3380 { "Activity Hint", "dcerpc.dg_ahint", FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL }},
3381 { &hf_dcerpc_dg_ihint,
3382 { "Interface Hint", "dcerpc.dg_ihint", FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL }},
3383 { &hf_dcerpc_dg_frag_len,
3384 { "Fragment len", "dcerpc.dg_frag_len", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL }},
3385 { &hf_dcerpc_dg_frag_num,
3386 { "Fragment num", "dcerpc.dg_frag_num", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL }},
3387 { &hf_dcerpc_dg_auth_proto,
3388 { "Auth proto", "dcerpc.dg_auth_proto", FT_UINT8, BASE_DEC, VALS (authn_protocol_vals), 0x0, "", HFILL }},
3389 { &hf_dcerpc_dg_seqnum,
3390 { "Sequence num", "dcerpc.dg_seqnum", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
3391 { &hf_dcerpc_dg_server_boot,
3392 { "Server boot time", "dcerpc.dg_server_boot", FT_UINT32, BASE_HEX, NULL, 0x0, "", HFILL }},
3393 { &hf_dcerpc_dg_if_ver,
3394 { "Interface Ver", "dcerpc.dg_if_ver", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
3395 { &hf_dcerpc_obj_id,
3396 { "Object", "dcerpc.obj_id", FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL }},
3397 { &hf_dcerpc_dg_if_id,
3398 { "Interface", "dcerpc.dg_if_id", FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL }},
3399 { &hf_dcerpc_dg_act_id,
3400 { "Activitiy", "dcerpc.dg_act_id", FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL }},
3402 { "Opnum", "dcerpc.opnum", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL }},
3404 { &hf_dcerpc_dg_cancel_vers,
3405 { "Cancel Version", "dcerpc.dg_cancel_vers", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
3407 { &hf_dcerpc_dg_cancel_id,
3408 { "Cancel ID", "dcerpc.dg_cancel_id", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
3410 { &hf_dcerpc_dg_server_accepting_cancels,
3411 { "Server accepting cancels", "dcerpc.server_accepting_cancels", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "", HFILL }},
3413 { &hf_dcerpc_dg_fack_vers,
3414 { "FACK Version", "dcerpc.fack_vers", FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
3416 { &hf_dcerpc_dg_fack_window_size,
3417 { "Window Size", "dcerpc.fack_window size", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL }},
3419 { &hf_dcerpc_dg_fack_max_tsdu,
3420 { "Max TSDU", "dcerpc.fack_max_tsdu", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
3422 { &hf_dcerpc_dg_fack_max_frag_size,
3423 { "Max Frag Size", "dcerpc.fack_max_frag_size", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
3425 { &hf_dcerpc_dg_fack_serial_num,
3426 { "Serial Num", "dcerpc.fack_serial_num", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL }},
3428 { &hf_dcerpc_dg_fack_selack_len,
3429 { "Selective ACK Len", "dcerpc.fack_selack_len", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL }},
3431 { &hf_dcerpc_dg_fack_selack,
3432 { "Selective ACK", "dcerpc.fack_selack", FT_UINT32, BASE_HEX, NULL, 0x0, "", HFILL }},
3434 { &hf_dcerpc_dg_status,
3435 { "Status", "dcerpc.dg_status", FT_UINT32, BASE_HEX, VALS(reject_status_vals), 0x0, "", HFILL }},
3437 { &hf_dcerpc_array_max_count,
3438 { "Max Count", "dcerpc.array.max_count", FT_UINT32, BASE_DEC, NULL, 0x0, "Maximum Count: Number of elements in the array", HFILL }},
3440 { &hf_dcerpc_array_offset,
3441 { "Offset", "dcerpc.array.offset", FT_UINT32, BASE_DEC, NULL, 0x0, "Offset for first element in array", HFILL }},
3443 { &hf_dcerpc_array_actual_count,
3444 { "Actual Count", "dcerpc.array.actual_count", FT_UINT32, BASE_DEC, NULL, 0x0, "Actual Count: Actual number of elements in the array", HFILL }},
3447 { "Operation", "dcerpc.op", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL }},
3449 { &hf_dcerpc_fragments,
3450 { "DCE/RPC Fragments", "dcerpc.fragments", FT_NONE, BASE_NONE,
3451 NULL, 0x0, "DCE/RPC Fragments", HFILL }},
3453 { &hf_dcerpc_fragment,
3454 { "DCE/RPC Fragment", "dcerpc.fragment", FT_NONE, BASE_NONE,
3455 NULL, 0x0, "DCE/RPC Fragment", HFILL }},
3457 { &hf_dcerpc_fragment_overlap,
3458 { "Fragment overlap", "dcerpc.fragment.overlap", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "Fragment overlaps with other fragments", HFILL }},
3460 { &hf_dcerpc_fragment_overlap_conflict,
3461 { "Conflicting data in fragment overlap", "dcerpc.fragment.overlap.conflict", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "Overlapping fragments contained conflicting data", HFILL }},
3463 { &hf_dcerpc_fragment_multiple_tails,
3464 { "Multiple tail fragments found", "dcerpc.fragment.multipletails", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "Several tails were found when defragmenting the packet", HFILL }},
3466 { &hf_dcerpc_fragment_too_long_fragment,
3467 { "Fragment too long", "dcerpc.fragment.toolongfragment", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "Fragment contained data past end of packet", HFILL }},
3469 { &hf_dcerpc_fragment_error,
3470 { "Defragmentation error", "dcerpc.fragment.error", FT_NONE, BASE_NONE, NULL, 0x0, "Defragmentation error due to illegal fragments", HFILL }},
3473 static gint *ett[] = {
3475 &ett_dcerpc_cn_flags,
3477 &ett_dcerpc_dg_flags1,
3478 &ett_dcerpc_dg_flags2,
3479 &ett_dcerpc_pointer_data,
3480 &ett_dcerpc_fragments,
3481 &ett_dcerpc_fragment,
3483 module_t *dcerpc_module;
3485 proto_dcerpc = proto_register_protocol ("DCE RPC", "DCERPC", "dcerpc");
3486 proto_register_field_array (proto_dcerpc, hf, array_length (hf));
3487 proto_register_subtree_array (ett, array_length (ett));
3488 register_init_routine (dcerpc_init_protocol);
3489 dcerpc_module = prefs_register_protocol (proto_dcerpc, NULL);
3490 prefs_register_bool_preference (dcerpc_module,
3492 "Desegment all DCE/RPC over TCP",
3493 "Whether the DCE/RPC dissector should desegment all DCE/RPC over TCP",
3494 &dcerpc_cn_desegment);
3495 prefs_register_bool_preference (dcerpc_module,
3496 "reassemble_dcerpc",
3497 "Reassemble DCE/RPC fragments",
3498 "Whether the DCE/RPC dissector should reassemble all fragmented PDUs",
3499 &dcerpc_reassemble);
3500 register_init_routine(dcerpc_reassemble_init);
3501 dcerpc_uuids = g_hash_table_new (dcerpc_uuid_hash, dcerpc_uuid_equal);
3505 proto_reg_handoff_dcerpc (void)
3507 heur_dissector_add ("tcp", dissect_dcerpc_cn_bs, proto_dcerpc);
3508 heur_dissector_add ("netbios", dissect_dcerpc_cn_pk, proto_dcerpc);
3509 heur_dissector_add ("udp", dissect_dcerpc_dg, proto_dcerpc);
3510 heur_dissector_add ("smb_transact", dissect_dcerpc_cn_bs, proto_dcerpc);
3511 ntlmssp_handle = find_dissector("ntlmssp");