2 * Routines for TDS NetLib dissection
3 * Copyright 2000-2002, Brian Bruns <camber@ais.org>
4 * Copyright 2002, Steve Langasek <vorlon@netexpress.net>
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 * The NETLIB protocol is a small blocking protocol designed to allow TDS
29 * to be placed within different transports (TCP, DECNet, IPX/SPX). A
30 * NETLIB packet starts with an eight byte header containing:
32 * a one-byte packet type field;
34 * a one-byte status field;
36 * a two-byte big-endian size field giving the size of the packet,
37 * including the header;
39 * a two-byte big-endian channel number, used when multiple sessions
40 * are being multiplexed on a single connection;
42 * a one-byte packet number, giving "the frame number of a multiplexed
43 * message, modulo 256";
45 * a one-byte window, which is the number of frames to be sent
46 * before an acknowledgment message is received.
48 * followed by payload whose size is the value in the size field minus
51 * Microsoft Network Monitor 2.x dissects the 4 byte field (and indicates
52 * that the one-byte last packet indicator also contains other bits).
54 * The TDS protocol consists of a number of protocol data units (PDUs) that
55 * appear to be assembled from NETLIB packets, in the form of zero or more
56 * NETLIB packets with the last packet indicator clear and a final NETLIB
57 * packet with the last packet indicator set. The type of the TDS PDU is
58 * specified by the packet type field of the NETLIB header (presumably that
59 * field has the same value for all NETLIB packets that make up a TDS PDU).
61 * The "server response" PDU consists of a sequence of multiple items, each
62 * one beginning with a one byte type field at the start of the PDU. Some
63 * items are fixed length, some are variable length with a two byte size
64 * field following the item type, and then there is TDS_ROW_TOKEN in which
65 * size is determined by analyzing the result set returned from the server.
66 * This in effect means that we are hopelessly lost if we haven't seen the
67 * result set. Also, TDS 4/5 is byte order negotiable, which is specified
68 * in the login packet. We can attempt to determine it later on, but not
71 * Some preliminary documentation on the packet format can be found at
72 * http://www.freetds.org/tds.html
74 * Some more information can be found in
75 * http://download.nai.com/products/media/sniffer/support/sdos/sybase.pdf
77 * Much of this code was originally developed for the FreeTDS project.
78 * http://www.freetds.org
82 * Excerpts from Brian's posting to wireshark-dev:
84 * The TDS Protocol is actually a protocol within a protocol. On the outside
85 * there is netlib which is not so much a encapsulation as a blocking of the
86 * data, typically to 512 or 4096 bytes. Between this are the protocol data
87 * units for TDS. Netlib packets may be split over real packets, multiple
88 * netlib packets may appear in single real packets. TDS PDUs may be split
89 * over netlib packets (and real packets) and most certainly can appear
90 * multiple times within a netlib packet.
92 * Because of this, I abandoned my earlier attempt at making two dissectors,
93 * one for netlib and one for TDS. Counterintuitively, a single dissector
94 * turned out to be simpler than splitting it up.
96 * Here are some of the (hefty) limitations of the current code
98 * . We currently do not handle netlib headers that cross packet boundaries.
99 * This should be an easy fix.
100 * . I probably could have used the packet reassembly stuff, but I started
101 * this at version 0.8.20, so c'est la vie. It wouldn't have covered the
102 * netlib stuff anyway, so no big loss.
103 * . The older two layer version of the code dissected the PDU's, but the new
104 * version does not yet, it only labels the names. I need an elegant way to
105 * deal with dissecting data crossing (netlib and tcp) packet boundries. I
106 * think I have one, but ran out of time to do it.
107 * . It will only work on little endian platforms. Or rather I should say,
108 * the client that was captured must be little endian. TDS 7.0/8.0 is
109 * always LE; for TDS 4.2/5.0 look in the code for tvb_get_le*() functions,
110 * there are fields in the login packet which determine byte order.
111 * . result sets that span netlib packets are not working
112 * . TDS 7 and 4.2 result sets are not working yet
114 * All that said, the code does deal gracefully with different boudary
115 * conditions and what remains are the easier bits, IMHO.
117 * XXX - "real packets" means "TCP segments", for TCP.
119 * XXX - is it *REALLY* true that you can have more than one TDS PDU (as
120 * opposed to more than one server response item) per NETLIB packet? Or is
121 * all the data in a NETLIB packet put into a single TDS PDU? If so, then
122 * we can reassemble NETLIB packets using the standard TCP desegmentation
123 * code, and can reassemble TDS PDUs using "fragment_add_seq_check()",
124 * and more cleanly separate the NETLIB and TDS dissectors (although the
125 * "is this NETLIB" heuristic would have to look at TDS information past
126 * the NETLIB header, in order to make the heuristic strong enough not
127 * to get too many false positives; note that the heuristic should reject
128 * any putative NETLIB packet with a length field with a value < 8).
130 * That would substantially clean the dissector up, eliminating most of
131 * the per-packet data (we might still need information to handle
132 * TDS_ROW_TOKEN), getting rid of the stuff to handle data split across
133 * TCP segment boundaries in favor of simple reassembly code, and
134 * fixing some otherwise nasty-looking crashing bugs.
136 * NOTE: we assume that all the data in a NETLIB packet *can* be put into
137 * a single TDS PTU, so that we have separate reassembly of NETLIB
138 * packets and TDS PDUs; it seems to work, and it really did clean stuff
139 * up and fix crashes.
155 #include <epan/packet.h>
156 #include <epan/conversation.h>
157 #include <epan/strutil.h>
159 #include "packet-frame.h"
160 #include <epan/reassemble.h>
161 #include <epan/prefs.h>
162 #include <epan/emem.h>
164 #define TDS_QUERY_PKT 1
165 #define TDS_LOGIN_PKT 2
166 #define TDS_RPC_PKT 3
167 #define TDS_RESP_PKT 4
168 #define TDS_RAW_PKT 5
169 #define TDS_CANCEL_PKT 6
170 #define TDS_BULK_DATA_PKT 7
171 #define TDS_OPEN_CHN_PKT 8
172 #define TDS_CLOSE_CHN_PKT 9
173 #define TDS_RES_ERROR_PKT 10
174 #define TDS_LOG_CHN_ACK_PKT 11
175 #define TDS_ECHO_PKT 12
176 #define TDS_LOGOUT_CHN_PKT 13
177 #define TDS_QUERY5_PKT 15 /* or "Normal tokenized request or response */
178 #define TDS_LOGIN7_PKT 16 /* or "Urgent tokenized request or response */
179 #define TDS_NTLMAUTH_PKT 17
180 #define TDS_XXX7_PKT 18 /* seen in one capture */
182 #define is_valid_tds_type(x) ((x) >= TDS_QUERY_PKT && (x) <= TDS_XXX7_PKT)
184 /* The following constants are imported more or less directly from FreeTDS */
185 /* Updated from FreeTDS v0.63 tds.h */
186 /* "$Id: tds.h,v 1.192 2004/10/28 12:42:12 freddy77]" */
187 /* Note: [###] below means 'not defined in FreeTDS tds.h' */
189 #define TDS5_PARAMFMT2_TOKEN 32 /* 0x20 TDS 5.0 only */
190 #define TDS_LANG_TOKEN 33 /* 0x21 TDS 5.0 only */
191 #define TDS5_ORDERBY2_TOKEN 34 /* 0x22 TDS 5.0 only */
192 #define TDS5_CURDECLARE2_TOKEN 35 /* 0x23 TDS 5.0 only [###] */
193 #define TDS5_ROWFMT2_TOKEN 97 /* 0x61 TDS 5.0 only */
194 #define TDS5_MSG_TOKEN 101 /* 0x65 TDS 5.0 only [###] */
195 #define TDS_LOGOUT_TOKEN 113 /* 0x71 TDS 5.0 only? ct_close() */
196 #define TDS_RET_STAT_TOKEN 121 /* 0x79 */
197 #define TDS_PROCID_TOKEN 124 /* 0x7C TDS 4.2 only - TDS_PROCID */
198 #define TDS_CURCLOSE_TOKEN 128 /* 0x80 TDS 5.0 only */
199 #define TDS7_RESULT_TOKEN 129 /* 0x81 TDS 7.0 only */
200 #define TDS_CURFETCH_TOKEN 130 /* 0x82 TDS 5.0 only */
201 #define TDS_CURINFO_TOKEN 131 /* 0x83 TDS 5.0 only */
202 #define TDS_CUROPEN_TOKEN 132 /* 0x84 TDS 5.0 only */
203 #define TDS_CURDECLARE_TOKEN 134 /* 0x86 TDS 5.0 only */
204 #define TDS7_COMPUTE_RESULT_TOKEN 136 /* 0x88 TDS 7.0 only */
205 #define TDS_COL_NAME_TOKEN 160 /* 0xA0 TDS 4.2 only */
206 #define TDS_COL_INFO_TOKEN 161 /* 0xA1 TDS 4.2 only - TDS_COLFMT */
207 #define TDS5_DYNAMIC2_TOKEN 163 /* 0xA3 TDS 5.0 only */
208 #if 0 /* XX: Why commented out ? These are 'live' in FreeTDS tds.h */
209 #define TDS_TABNAME 164 /* 0xA4 */
210 #define TDS_COL_INFO 165 /* 0xA5 */
212 #define TDS_OPTIONCMD_TOKEN 166 /* 0xA6 */
213 #define TDS_COMPUTE_NAMES_TOKEN 167 /* 0xA7 */
214 #define TDS_COMPUTE_RESULT_TOKEN 168 /* 0xA8 */
215 #define TDS_ORDER_BY_TOKEN 169 /* 0xA9 TDS_ORDER */
216 #define TDS_ERR_TOKEN 170 /* 0xAA */
217 #define TDS_MSG_TOKEN 171 /* 0xAB */
218 #define TDS_PARAM_TOKEN 172 /* 0xAC RETURNVALUE? */
219 #define TDS_LOGIN_ACK_TOKEN 173 /* 0xAD */
220 #define TDS_CONTROL_TOKEN 174 /* 0xAE TDS_CONTROL */
221 #define TDS_KEY_TOKEN 202 /* 0xCA [###] */
222 #define TDS_ROW_TOKEN 209 /* 0xD1 */
223 #define TDS_CMP_ROW_TOKEN 211 /* 0xD3 */
224 #define TDS5_PARAMS_TOKEN 215 /* 0xD7 TDS 5.0 only */
225 #define TDS_CAP_TOKEN 226 /* 0xE2 */
226 #define TDS_ENV_CHG_TOKEN 227 /* 0xE3 */
227 #define TDS_EED_TOKEN 229 /* 0xE5 */
228 #define TDS_DBRPC_TOKEN 230 /* 0xE6 */
229 #define TDS5_DYNAMIC_TOKEN 231 /* 0xE7 TDS 5.0 only */
230 #define TDS5_PARAMFMT_TOKEN 236 /* 0xEC TDS 5.0 only */
231 #define TDS_AUTH_TOKEN 237 /* 0xED */
232 #define TDS_RESULT_TOKEN 238 /* 0xEE */
233 #define TDS_DONE_TOKEN 253 /* 0xFD TDS_DONE */
234 #define TDS_DONEPROC_TOKEN 254 /* 0xFE TDS_DONEPROC */
235 #define TDS_DONEINPROC_TOKEN 255 /* 0xFF TDS_DONEINPROC */
237 /* Microsoft internal stored procedure id's */
239 #define TDS_SP_CURSOR 1
240 #define TDS_SP_CURSOROPEN 2
241 #define TDS_SP_CURSORPREPARE 3
242 #define TDS_SP_CURSOREXECUTE 4
243 #define TDS_SP_CURSORPREPEXEC 5
244 #define TDS_SP_CURSORUNPREPARE 6
245 #define TDS_SP_CURSORFETCH 7
246 #define TDS_SP_CURSOROPTION 8
247 #define TDS_SP_CURSORCLOSE 9
248 #define TDS_SP_EXECUTESQL 10
249 #define TDS_SP_PREPARE 11
250 #define TDS_SP_EXECUTE 12
251 #define TDS_SP_PREPEXEC 13
252 #define TDS_SP_PREPEXECRPC 14
253 #define TDS_SP_UNPREPARE 15
255 /* Sybase Data Types */
257 #define SYBCHAR 47 /* 0x2F */
258 #define SYBVARCHAR 39 /* 0x27 */
259 #define SYBINTN 38 /* 0x26 */
260 #define SYBINT1 48 /* 0x30 */
261 #define SYBINT2 52 /* 0x34 */
262 #define SYBINT4 56 /* 0x38 */
263 #define SYBINT8 127 /* 0x7F */
264 #define SYBFLT8 62 /* 0x3E */
265 #define SYBDATETIME 61 /* 0x3D */
266 #define SYBBIT 50 /* 0x32 */
267 #define SYBTEXT 35 /* 0x23 */
268 #define SYBNTEXT 99 /* 0x63 */
269 #define SYBIMAGE 34 /* 0x22 */
270 #define SYBMONEY4 122 /* 0x7A */
271 #define SYBMONEY 60 /* 0x3C */
272 #define SYBDATETIME4 58 /* 0x3A */
273 #define SYBREAL 59 /* 0x3B */
274 #define SYBBINARY 45 /* 0x2D */
275 #define SYBVOID 31 /* 0x1F */
276 #define SYBVARBINARY 37 /* 0x25 */
277 #define SYBNVARCHAR 103 /* 0x67 */
278 #define SYBBITN 104 /* 0x68 */
279 #define SYBNUMERIC 108 /* 0x6C */
280 #define SYBDECIMAL 106 /* 0x6A */
281 #define SYBFLTN 109 /* 0x6D */
282 #define SYBMONEYN 110 /* 0x6E */
283 #define SYBDATETIMN 111 /* 0x6F */
284 #define XSYBCHAR 175 /* 0xA7 */
285 #define XSYBVARCHAR 167 /* 0xAF */
286 #define XSYBNVARCHAR 231 /* 0xE7 */
287 #define XSYBNCHAR 239 /* 0xEF */
288 #define XSYBVARBINARY 165 /* 0xA5 */
289 #define XSYBBINARY 173 /* 0xAD */
290 #define SYBLONGBINARY 225 /* 0xE1 */
291 #define SYBSINT1 64 /* 0x40 */
292 #define SYBUINT2 65 /* 0x41 */
293 #define SYBUINT4 66 /* 0x42 */
294 #define SYBUINT8 67 /* 0x43 */
295 #define SYBUNIQUE 36 /* 0x24 */
296 #define SYBVARIANT 98 /* 0x62 */
298 #define is_fixed_coltype(x) (x==SYBINT1 || \
311 /* Initialize the protocol and registered fields */
312 static int proto_tds = -1;
313 static int hf_tds_type = -1;
314 static int hf_tds_status = -1;
315 static int hf_tds_size = -1;
316 static int hf_tds_channel = -1;
317 static int hf_tds_packet_number = -1;
318 static int hf_tds_window = -1;
319 static int hf_tds_reassembled_in = -1;
320 static int hf_tds_fragments = -1;
321 static int hf_tds_fragment = -1;
322 static int hf_tds_fragment_overlap = -1;
323 static int hf_tds_fragment_overlap_conflict = -1;
324 static int hf_tds_fragment_multiple_tails = -1;
325 static int hf_tds_fragment_too_long_fragment = -1;
326 static int hf_tds_fragment_error = -1;
328 static int hf_tds7_login_total_size = -1;
329 static int hf_tds7_version = -1;
330 static int hf_tds7_packet_size = -1;
331 static int hf_tds7_client_version = -1;
332 static int hf_tds7_client_pid = -1;
333 static int hf_tds7_connection_id = -1;
334 static int hf_tds7_option_flags1 = -1;
335 static int hf_tds7_option_flags2 = -1;
336 static int hf_tds7_sql_type_flags = -1;
337 static int hf_tds7_reserved_flags = -1;
338 static int hf_tds7_time_zone = -1;
339 static int hf_tds7_collation = -1;
340 static int hf_tds7_message = -1;
342 /* Initialize the subtree pointers */
343 static gint ett_tds = -1;
344 static gint ett_tds_fragments = -1;
345 static gint ett_tds_fragment = -1;
346 static gint ett_tds_token = -1;
347 static gint ett_tds7_login = -1;
348 static gint ett_tds7_query = 0;
349 static gint ett_tds7_hdr = -1;
351 /* Desegmentation of Netlib buffers crossing TCP segment boundaries. */
352 static gboolean tds_desegment = TRUE;
354 static const fragment_items tds_frag_items = {
359 &hf_tds_fragment_overlap,
360 &hf_tds_fragment_overlap_conflict,
361 &hf_tds_fragment_multiple_tails,
362 &hf_tds_fragment_too_long_fragment,
363 &hf_tds_fragment_error,
364 &hf_tds_reassembled_in,
368 /* Tables for reassembly of fragments. */
369 static GHashTable *tds_fragment_table = NULL;
370 static GHashTable *tds_reassembled_table = NULL;
372 /* defragmentation of multi-buffer TDS PDUs */
373 static gboolean tds_defragment = TRUE;
375 static dissector_handle_t tds_tcp_handle;
376 static dissector_handle_t ntlmssp_handle;
377 static dissector_handle_t gssapi_handle;
378 static dissector_handle_t data_handle;
380 /* TDS protocol type preference */
381 /* XXX: This preference is used as a 'hint' for cases where interpretation is ambiguous */
382 /* Currently the hint is global */
383 /* TODO: Consider storing protocol type with each conversation */
384 /* (when type is determined and using the preference as a default) ?? */
386 #define TDS_PROTOCOL_NOT_SPECIFIED 0
387 #define TDS_PROTOCOL_4 4
388 #define TDS_PROTOCOL_5 5
389 #define TDS_PROTOCOL_7 7
390 #define TDS_PROTOCOL_8 8
392 static gint tds_protocol_type = TDS_PROTOCOL_NOT_SPECIFIED;
394 const enum_val_t tds_protocol_type_options[] = {
395 {"not_specified", "Not Specified", TDS_PROTOCOL_NOT_SPECIFIED},
396 {"tds4", "TDS 4", TDS_PROTOCOL_4}, /* TDS 4.2 and TDS 4.6 */
397 {"tds5", "TDS 5", TDS_PROTOCOL_5},
398 {"tds7", "TDS 7", TDS_PROTOCOL_7},
399 {"tds8", "TDS 8", TDS_PROTOCOL_8},
403 #define TDS_PROTO_PREF_NOT_SPECIFIED (tds_protocol_type == TDS_NOT_SPECIFIED)
404 #define TDS_PROTO_PREF_TDS4 (tds_protocol_type == TDS_PROTOCOL_4)
405 #define TDS_PROTO_PREF_TDS5 (tds_protocol_type == TDS_PROTOCOL_5)
406 #define TDS_PROTO_PREF_TDS7 (tds_protocol_type == TDS_PROTOCOL_7)
407 #define TDS_PROTO_PREF_TDS8 (tds_protocol_type == TDS_PROTOCOL_8)
408 #define TDS_PROTO_PREF_TDS7_TDS8 ( TDS_PROTO_PREF_TDS7 || TDS_PROTO_PREF_TDS8 )
410 /* TDS "endian type" */
411 /* XXX: Assumption is that all TDS conversations being decoded in a particular capture */
412 /* have the same endian type */
413 /* TODO: consider storing endian type with each conversation */
414 /* (using pref as the default) */
416 static gint tds_little_endian = TRUE;
418 const enum_val_t tds_endian_type_options[] = {
419 {"little_endian", "Little Endian", TRUE},
420 {"big_endian" , "Big Endian" , FALSE},
425 /* TCP port preferences for TDS decode */
427 static range_t *tds_tcp_ports = NULL;
429 /* These correspond to the netlib packet type field */
430 static const value_string packet_type_names[] = {
431 {TDS_QUERY_PKT, "Query Packet"},
432 {TDS_LOGIN_PKT, "Login Packet"},
433 {TDS_RPC_PKT, "Remote Procedure Call Packet"},
434 {TDS_RESP_PKT, "Response Packet"},
435 {TDS_CANCEL_PKT, "Cancel Packet"},
436 {TDS_QUERY5_PKT, "TDS5 Query Packet"},
437 {TDS_LOGIN7_PKT, "TDS7/8 Login Packet"},
438 {TDS_XXX7_PKT, "TDS7/8 0x12 Packet"},
439 {TDS_NTLMAUTH_PKT, "NT Authentication Packet"},
443 /* The status field */
445 #define is_valid_tds_status(x) ((x) <= STATUS_EVENT_NOTIFICATION)
447 #define STATUS_NOT_LAST_BUFFER 0x00
448 #define STATUS_LAST_BUFFER 0x01
449 #define STATUS_ATTN_REQUEST_ACK 0x02
450 #define STATUS_ATTN_REQUEST 0x03
451 #define STATUS_EVENT_NOTIFICATION 0x04
453 static const value_string status_names[] = {
454 {STATUS_NOT_LAST_BUFFER, "Not last buffer"},
455 {STATUS_LAST_BUFFER, "Last buffer in request or response"},
456 {STATUS_ATTN_REQUEST_ACK, "Acknowledgment of last attention request"},
457 {STATUS_ATTN_REQUEST, "Attention request"},
458 {STATUS_EVENT_NOTIFICATION, "Event notification"},
462 /* The one byte token at the start of each TDS PDU */
463 static const value_string token_names[] = {
464 {TDS5_DYNAMIC_TOKEN, "TDS5 Dynamic SQL"},
465 {TDS5_PARAMFMT_TOKEN, "TDS5 Parameter Format"},
466 {TDS5_PARAMFMT2_TOKEN, "TDS5 Parameter2 Format"},
467 {TDS5_PARAMS_TOKEN, "TDS5 Parameters"},
468 {TDS_LANG_TOKEN, "Language"},
469 {TDS_LOGOUT_TOKEN, "Logout"},
470 {TDS_RET_STAT_TOKEN, "Return Status"},
471 {TDS_PROCID_TOKEN, "Proc ID"},
472 {TDS7_RESULT_TOKEN, "TDS7+ Results"},
473 {TDS_COL_NAME_TOKEN, "Column Names"},
474 {TDS_COL_INFO_TOKEN, "Column Info"},
475 {TDS_COMPUTE_NAMES_TOKEN, "Compute Names"},
476 {TDS_COMPUTE_RESULT_TOKEN, "Compute Results"},
477 {TDS_ORDER_BY_TOKEN, "Order By"},
478 {TDS_ERR_TOKEN, "Error Message"},
479 {TDS_MSG_TOKEN, "Info Message"},
480 {TDS_PARAM_TOKEN, "Parameter"},
481 {TDS_LOGIN_ACK_TOKEN, "Login Acknowledgement"},
482 {TDS_CONTROL_TOKEN, "TDS Control"},
483 {TDS_KEY_TOKEN, "TDS Key"},
484 {TDS_ROW_TOKEN, "Row"},
485 {TDS_CMP_ROW_TOKEN, "Compute Row"},
486 {TDS_CAP_TOKEN, "Capabilities"},
487 {TDS_ENV_CHG_TOKEN, "Environment Change"},
488 {TDS_EED_TOKEN, "Extended Error"},
489 {TDS_AUTH_TOKEN, "Authentication"},
490 {TDS_RESULT_TOKEN, "Results"},
491 {TDS_DONE_TOKEN, "Done"},
492 {TDS_DONEPROC_TOKEN, "Done Proc"},
493 {TDS_DONEINPROC_TOKEN, "Done In Proc"},
494 {TDS5_DYNAMIC2_TOKEN, "TDS5 Dynamic2"},
495 {TDS5_ORDERBY2_TOKEN, "TDS5 OrderBy2"},
496 {TDS5_CURDECLARE2_TOKEN, "TDS5 CurDeclare2"},
497 {TDS5_ROWFMT2_TOKEN, "TDS5 RowFmt2"},
498 {TDS5_MSG_TOKEN, "TDS5 Msg"},
503 static const value_string internal_stored_proc_id_names[] = {
504 {TDS_SP_CURSOR, "sp_cursor" },
505 {TDS_SP_CURSOROPEN, "sp_cursoropen" },
506 {TDS_SP_CURSORPREPARE, "sp_cursorprepare" },
507 {TDS_SP_CURSOREXECUTE, "sp_cursorexecute" },
508 {TDS_SP_CURSORPREPEXEC, "sp_cursorprepexec" },
509 {TDS_SP_CURSORUNPREPARE, "sp_cursorunprepare"},
510 {TDS_SP_CURSORFETCH, "sp_cursorfetch" },
511 {TDS_SP_CURSOROPTION, "sp_cursoroption" },
512 {TDS_SP_CURSORCLOSE, "sp_cursorclose" },
513 {TDS_SP_EXECUTESQL, "sp_executesql" },
514 {TDS_SP_PREPARE, "sp_prepare" },
515 {TDS_SP_EXECUTE, "sp_execute" },
516 {TDS_SP_PREPEXEC, "sp_prepexec" },
517 {TDS_SP_PREPEXECRPC, "sp_prepexecrpc" },
518 {TDS_SP_UNPREPARE, "sp_unprepare" },
522 static const value_string env_chg_names[] = {
527 {5, "Unicode Locale ID"},
528 {6, "Unicode Comparison Style"},
529 {7, "Collation Info"},
533 static const value_string login_field_names[] = {
542 {8, "Database Name"},
547 #define MAX_COLUMNS 256
550 * This is where we store the column information to be used in decoding the
551 * TDS_ROW_TOKEN tokens.
560 struct _netlib_data {
562 struct _tds_col *columns[MAX_COLUMNS];
565 struct tds7_login_packet_hdr {
566 guint32 total_packet_size;
569 guint32 client_version;
571 guint32 connection_id;
572 guint8 option_flags1;
573 guint8 option_flags2;
574 guint8 sql_type_flags;
575 guint8 reserved_flags;
580 /* support routines */
583 dissect_tds_nt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
584 guint offset, guint length)
588 nt_tvb = tvb_new_subset(tvb, offset, -1, length);
589 if(tvb_strneql(tvb, offset, "NTLMSSP", 7) == 0)
590 call_dissector(ntlmssp_handle, nt_tvb, pinfo, tree);
592 call_dissector(gssapi_handle, nt_tvb, pinfo, tree);
598 tds_tvb_get_xxtohs(tvbuff_t *tvb, gint offset, gint tds_little_endian) {
599 if (tds_little_endian)
600 return tvb_get_letohs(tvb, offset);
602 return tvb_get_ntohs(tvb, offset);
606 tds_tvb_get_xxtohl(tvbuff_t *tvb, gint offset, gint tds_little_endian) {
607 if (tds_little_endian)
608 return tvb_get_letohl(tvb, offset);
610 return tvb_get_ntohl(tvb, offset);
614 static int tds_token_is_fixed_size(guint8 token)
618 case TDS_DONEPROC_TOKEN:
619 case TDS_DONEINPROC_TOKEN:
620 case TDS_RET_STAT_TOKEN:
621 case TDS7_RESULT_TOKEN:
622 case TDS_PROCID_TOKEN:
623 case TDS_LOGOUT_TOKEN:
631 static int tds_get_fixed_token_size(guint8 token)
635 case TDS_DONEPROC_TOKEN:
636 case TDS_DONEINPROC_TOKEN:
637 case TDS_PROCID_TOKEN:
639 case TDS_RET_STAT_TOKEN:
641 case TDS_LOGOUT_TOKEN:
643 case TDS7_RESULT_TOKEN:
650 tds_get_variable_token_size(tvbuff_t *tvb, gint offset, guint8 token,
651 guint *len_field_size_p, guint *len_field_val_p)
654 /* some tokens have a 4 byte length field */
655 case TDS5_PARAMFMT2_TOKEN:
657 case TDS5_ORDERBY2_TOKEN:
658 case TDS5_CURDECLARE2_TOKEN:
659 case TDS5_ROWFMT2_TOKEN:
660 case TDS5_DYNAMIC2_TOKEN:
661 *len_field_size_p = 4;
662 *len_field_val_p = tds_tvb_get_xxtohl(tvb, offset, tds_little_endian);
664 /* some have a 1 byte length field */
666 *len_field_size_p = 1;
667 *len_field_val_p = tvb_get_guint8(tvb, offset);
669 /* and most have a 2 byte length field */
671 *len_field_size_p = 2;
672 *len_field_val_p = tds_tvb_get_xxtohs(tvb, offset, tds_little_endian);
675 return *len_field_val_p + *len_field_size_p + 1;
680 dissect_tds_query_packet(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree)
683 gboolean is_unicode = TRUE;
686 proto_item *query_hdr;
687 proto_tree *query_tree;
690 query_hdr = proto_tree_add_text(tree, tvb, offset, -1, "TDS Query Packet");
691 query_tree = proto_item_add_subtree(query_hdr, ett_tds7_query);
692 len = tvb_reported_length_remaining(tvb, offset);
694 if (TDS_PROTO_PREF_TDS4 ||
695 (!TDS_PROTO_PREF_TDS7_TDS8 &&
696 ((len < 2) || tvb_get_guint8(tvb, offset+1) != 0)))
700 msg = tvb_get_ephemeral_faked_unicode(tvb, offset, len/2, TRUE);
702 msg = (gchar*)tvb_get_ephemeral_string(tvb, offset, len);
704 proto_tree_add_text(query_tree, tvb, offset, len, "Query: %s", msg);
710 dissect_tds5_lang_token(tvbuff_t *tvb, guint offset, guint len, proto_tree *tree) {
711 gboolean is_unicode = FALSE;
714 proto_tree_add_text(tree, tvb, offset, 1 , "Status: %u", tvb_get_guint8(tvb, offset));
719 msg = tvb_get_ephemeral_faked_unicode(tvb, offset, (len)/2, TRUE);
721 msg = (gchar*)tvb_get_ephemeral_string(tvb, offset, len);
723 proto_tree_add_text(tree, tvb, offset, len, "Language text: %s", msg);
727 dissect_tds_query5_packet(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree)
731 guint token_len_field_size = 2;
732 guint token_len_field_val = 0;
735 proto_item *query_hdr;
736 proto_tree *query_tree;
737 proto_item *token_item;
738 proto_tree *token_tree;
741 query_hdr = proto_tree_add_text(tree, tvb, offset, -1, "TDS5 Query Packet");
742 query_tree = proto_item_add_subtree(query_hdr, ett_tds7_query);
745 * Until we reach the end of the packet, read tokens.
748 while (tvb_reported_length_remaining(tvb, pos) > 0) {
751 token = tvb_get_guint8(tvb, pos);
752 if (tds_token_is_fixed_size(token))
753 token_sz = tds_get_fixed_token_size(token) + 1;
755 token_sz = tds_get_variable_token_size(tvb, pos+1, token, &token_len_field_size,
756 &token_len_field_val);
758 /* XXX - Should this check be done in tds_get_variable_token_size()
760 if ((int) token_sz < 0) {
761 proto_tree_add_text(tree, tvb, 0, 0, "Bogus token size: %u",
766 token_item = proto_tree_add_text(tree, tvb, pos, token_sz,
767 "Token 0x%02x %s", token,
768 val_to_str(token, token_names, "Unknown Token Type"));
769 token_tree = proto_item_add_subtree(token_item, ett_tds_token);
772 * If it's a variable token, put the length field in here
773 * instead of replicating this for each token subdissector.
775 if (!tds_token_is_fixed_size(token))
776 proto_tree_add_text(token_tree, tvb, pos+1, token_len_field_size, "Length: %u", token_len_field_val);
780 dissect_tds5_lang_token(tvb, pos + 5, token_sz -5, token_tree);
793 dissect_tds7_login(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
795 guint offset, i, j, k, offset2, len;
798 proto_item *login_hdr;
799 proto_tree *login_tree;
800 proto_item *header_hdr;
801 proto_tree *header_tree;
802 proto_item *length_hdr;
803 proto_tree *length_tree;
805 struct tds7_login_packet_hdr td7hdr;
806 gint length_remaining;
809 /* create display subtree for the protocol */
811 login_hdr = proto_tree_add_text(tree, tvb, offset, -1, "TDS7 Login Packet");
812 login_tree = proto_item_add_subtree(login_hdr, ett_tds7_login);
813 header_hdr = proto_tree_add_text(login_tree, tvb, offset, 36, "Login Packet Header");
814 header_tree = proto_item_add_subtree(header_hdr, ett_tds7_hdr);
816 td7hdr.total_packet_size = tvb_get_letohl(tvb, offset);
817 proto_tree_add_uint(header_tree, hf_tds7_login_total_size, tvb, offset,
818 sizeof(td7hdr.total_packet_size), td7hdr.total_packet_size);
819 offset += sizeof(td7hdr.total_packet_size);
821 td7hdr.tds_version = tvb_get_ntohl(tvb, offset);
822 proto_tree_add_uint(header_tree, hf_tds7_version, tvb, offset, sizeof(td7hdr.tds_version), td7hdr.tds_version);
823 offset += sizeof(td7hdr.tds_version);
825 td7hdr.packet_size = tvb_get_ntohl(tvb, offset);
826 proto_tree_add_uint(header_tree, hf_tds7_packet_size, tvb, offset, sizeof(td7hdr.packet_size), td7hdr.packet_size);
827 offset += sizeof(td7hdr.packet_size);
829 td7hdr.client_version = tvb_get_ntohl(tvb, offset);
830 proto_tree_add_uint(header_tree, hf_tds7_client_version, tvb, offset, sizeof(td7hdr.client_version), td7hdr.client_version);
831 offset += sizeof(td7hdr.client_version);
833 td7hdr.client_pid = tvb_get_letohl(tvb, offset);
834 proto_tree_add_uint(header_tree, hf_tds7_client_pid, tvb, offset, sizeof(td7hdr.client_pid), td7hdr.client_pid);
835 offset += sizeof(td7hdr.client_pid);
837 td7hdr.connection_id= tvb_get_letohl(tvb, offset);
838 proto_tree_add_uint(header_tree, hf_tds7_connection_id, tvb, offset, sizeof(td7hdr.connection_id), td7hdr.connection_id);
839 offset += sizeof(td7hdr.connection_id);
841 td7hdr.option_flags1 = tvb_get_guint8(tvb, offset);
842 proto_tree_add_uint(header_tree, hf_tds7_option_flags1, tvb, offset, sizeof(td7hdr.option_flags1), td7hdr.option_flags1);
843 offset += sizeof(td7hdr.option_flags1);
845 td7hdr.option_flags2 = tvb_get_guint8(tvb, offset);
846 proto_tree_add_uint(header_tree, hf_tds7_option_flags2, tvb, offset, sizeof(td7hdr.option_flags2), td7hdr.option_flags2);
847 offset += sizeof(td7hdr.option_flags2);
849 td7hdr.sql_type_flags = tvb_get_guint8(tvb, offset);
850 proto_tree_add_uint(header_tree, hf_tds7_sql_type_flags, tvb, offset, sizeof(td7hdr.sql_type_flags), td7hdr.sql_type_flags);
851 offset += sizeof(td7hdr.sql_type_flags);
853 td7hdr.reserved_flags = tvb_get_guint8(tvb, offset);
854 proto_tree_add_uint(header_tree, hf_tds7_reserved_flags, tvb, offset, sizeof(td7hdr.reserved_flags), td7hdr.reserved_flags);
855 offset += sizeof(td7hdr.reserved_flags);
857 td7hdr.time_zone = tvb_get_ntohl(tvb, offset);
858 proto_tree_add_uint(header_tree, hf_tds7_time_zone, tvb, offset, sizeof(td7hdr.time_zone), td7hdr.time_zone);
859 offset += sizeof(td7hdr.time_zone);
861 td7hdr.collation = tvb_get_ntohl(tvb, offset);
862 proto_tree_add_uint(header_tree, hf_tds7_collation, tvb, offset, sizeof(td7hdr.collation), td7hdr.collation);
863 offset += sizeof(td7hdr.collation);
865 length_hdr = proto_tree_add_text(login_tree, tvb, offset, 50, "Lengths and offsets");
866 length_tree = proto_item_add_subtree(length_hdr, ett_tds7_hdr);
868 for (i = 0; i < 9; i++) {
869 offset2 = tvb_get_letohs(tvb, offset + i*4);
870 len = tvb_get_letohs(tvb, offset + i*4 + 2);
871 proto_tree_add_text(length_tree, tvb, offset + i*4, 2,
873 val_to_str(i, login_field_names, "Unknown"),
875 proto_tree_add_text(length_tree, tvb, offset + i*4 + 2, 2,
877 val_to_str(i, login_field_names, "Unknown"),
881 /* tds 7 is always unicode */
882 val = tvb_get_ephemeral_faked_unicode(tvb, offset2, len, TRUE);
884 proto_tree_add_text(login_tree, tvb, offset2, len, "%s: %s", val_to_str(i, login_field_names, "Unknown"), val);
886 /* This field is the password. We retrieve it from the packet
887 * as a non-unicode string and then perform two operations on it
888 * to "decrypt" it. Finally, we create a new string that consists
889 * of ASCII characters instead of unicode by skipping every other
890 * byte in the original string.
894 val = (gchar*)tvb_get_ephemeral_string(tvb, offset2, len);
895 val2 = g_malloc((len/2)+1);
897 for(j = 0, k = 0; j < len; j += 2, k++) {
900 /* Swap the most and least significant bits */
901 val[j] = ((val[j] & 0x0F) << 4) | ((val[j] & 0xF0) >> 4);
905 val2[k] = '\0'; /* Null terminate our new string */
907 proto_tree_add_text(login_tree, tvb, offset2, len, "%s: %s", val_to_str(i, login_field_names, "Unknown"), val2);
914 * XXX - what about the client MAC address, etc.?
916 length_remaining = tvb_reported_length_remaining(tvb, offset2 + len);
917 if (length_remaining > 0) {
918 dissect_tds_nt(tvb, pinfo, login_tree, offset2 + len,
923 static int get_size_by_coltype(int servertype)
927 case SYBINT1: return 1;
928 case SYBINT2: return 2;
929 case SYBINT4: return 4;
930 case SYBINT8: return 8;
931 case SYBREAL: return 4;
932 case SYBFLT8: return 8;
933 case SYBDATETIME: return 8;
934 case SYBDATETIME4: return 4;
935 case SYBBIT: return 1;
936 case SYBBITN: return 1;
937 case SYBMONEY: return 8;
938 case SYBMONEY4: return 4;
939 case SYBUNIQUE: return 16;
945 * data_to_string should take column data and turn it into something we can
946 * display on the tree.
948 static char *data_to_string(void *data, guint col_type, guint col_size)
953 result=ep_alloc(256);
956 /* strncpy(result, (char *)data, col_size); */
957 for (i=0;i<col_size && i<(256-1);i++)
958 if (!isprint(((char *)data)[i])) result[i]='.';
959 else result[i]=((char *)data)[i];
963 g_snprintf(result, 256, "%d", *(short *)data);
966 g_snprintf(result, 256, "%d", *(int *)data);
969 g_snprintf(result, 256, "Unexpected column_type %d", col_type);
977 * Since rows are special PDUs in that they are not fixed and lack a size field,
978 * the length must be computed using the column information seen in the result
979 * PDU. This function does just that.
982 tds_get_row_size(tvbuff_t *tvb, struct _netlib_data *nl_data, guint offset)
987 for (i = 0; i < nl_data->num_cols; i++) {
988 if (!is_fixed_coltype(nl_data->columns[i]->ctype)) {
989 csize = tvb_get_guint8(tvb, cur);
992 csize = get_size_by_coltype(nl_data->columns[i]->ctype);
996 return (cur - offset + 1);
1000 * Process TDS 4 "COL_INFO" token and store relevant information in the
1001 * _netlib_data structure for later use (see tds_get_row_size)
1003 * XXX Can TDS 4 be "big-endian" ? we'll assume yes.
1007 dissect_tds_col_info_token(tvbuff_t *tvb, struct _netlib_data *nl_data, guint offset)
1012 next = offset + tds_tvb_get_xxtohs(tvb, offset+1, tds_little_endian) + 3;
1016 while (cur < next) {
1018 if (col >= MAX_COLUMNS) {
1019 nl_data->num_cols = 0;
1023 nl_data->columns[col] = ep_alloc(sizeof(struct _tds_col));
1025 nl_data->columns[col]->name[0] ='\0';
1027 nl_data->columns[col]->utype = tds_tvb_get_xxtohs(tvb, cur, tds_little_endian);
1030 cur += 2; /* unknown */
1032 nl_data->columns[col]->ctype = tvb_get_guint8(tvb,cur);
1035 if (!is_fixed_coltype(nl_data->columns[col]->ctype)) {
1036 nl_data->columns[col]->csize = tvb_get_guint8(tvb,cur);
1039 nl_data->columns[col]->csize =
1040 get_size_by_coltype(nl_data->columns[col]->ctype);
1047 nl_data->num_cols = col;
1053 * Read the results token and store the relevant information in the
1054 * _netlib_data structure for later use (see tds_get_row_size).
1056 * TODO: check we don't go past end of the token
1059 read_results_tds5(tvbuff_t *tvb, struct _netlib_data *nl_data, guint offset, guint len _U_)
1068 * This would be the logical place to check for little/big endianess
1069 * if we didn't see the login packet.
1070 * XXX: We'll take a hint
1072 nl_data->num_cols = tds_tvb_get_xxtohs(tvb, cur, tds_little_endian);
1073 if (nl_data->num_cols > MAX_COLUMNS) {
1074 nl_data->num_cols = 0;
1080 for (i = 0; i < nl_data->num_cols; i++) {
1081 nl_data->columns[i] = ep_alloc(sizeof(struct _tds_col));
1082 name_len = tvb_get_guint8(tvb,cur);
1086 cur++; /* unknown */
1088 nl_data->columns[i]->utype = tds_tvb_get_xxtohs(tvb, cur, tds_little_endian);
1091 cur += 2; /* unknown */
1093 nl_data->columns[i]->ctype = tvb_get_guint8(tvb,cur);
1096 if (!is_fixed_coltype(nl_data->columns[i]->ctype)) {
1097 nl_data->columns[i]->csize = tvb_get_guint8(tvb,cur);
1100 nl_data->columns[i]->csize =
1101 get_size_by_coltype(nl_data->columns[i]->ctype);
1103 cur++; /* unknown */
1109 * If the packet type from the netlib header is a login packet, then dig into
1110 * the packet to see if this is a supported TDS version and verify the otherwise
1111 * weak heuristics of the netlib check.
1114 netlib_check_login_pkt(tvbuff_t *tvb, guint offset, packet_info *pinfo, guint8 type)
1116 guint tds_major, bytes_avail;
1118 bytes_avail = tvb_length(tvb) - offset;
1120 * we have two login packet styles, one for TDS 4.2 and 5.0
1122 if (type==TDS_LOGIN_PKT) {
1123 /* Use major version number to validate TDS 4/5 login
1126 /* Login packet is first in stream and should not be fragmented...
1127 * if it is we are screwed */
1128 if (bytes_avail < 467) return FALSE;
1129 tds_major = tvb_get_guint8(tvb, 466);
1130 if (tds_major != 4 && tds_major != 5) {
1134 * and one added by Microsoft in SQL Server 7
1136 } else if (type==TDS_LOGIN7_PKT) {
1137 if (bytes_avail < 16) return FALSE;
1138 tds_major = tvb_get_guint8(tvb, 15);
1139 if (tds_major != 0x70 && tds_major != 0x80) {
1142 } else if (type==TDS_QUERY5_PKT) {
1143 if (bytes_avail < 9) return FALSE;
1144 /* if this is a TDS 5.0 query check the token */
1145 if (tvb_get_guint8(tvb, 8) != TDS_LANG_TOKEN) {
1150 * See if either tcp.destport or tcp.srcport is specified
1151 * in the preferences as being a TDS port.
1153 else if (!value_is_in_range(tds_tcp_ports, pinfo->srcport) &&
1154 !value_is_in_range(tds_tcp_ports, pinfo->destport)) {
1162 dissect_tds_env_chg(tvbuff_t *tvb, guint offset, guint token_sz,
1166 guint old_len, new_len, old_len_offset;
1167 char *new_val = NULL, *old_val = NULL;
1168 guint32 string_offset;
1169 gboolean is_unicode = FALSE;
1170 guint16 collate_codepage, collate_flags;
1171 guint8 collate_charset_id;
1173 env_type = tvb_get_guint8(tvb, offset);
1174 proto_tree_add_text(tree, tvb, offset, 1, "Type: %u (%s)", env_type,
1175 val_to_str(env_type, env_chg_names, "Unknown"));
1177 new_len = tvb_get_guint8(tvb, offset+1);
1178 old_len_offset = offset + new_len + 2;
1179 old_len = tvb_get_guint8(tvb, old_len_offset);
1182 * If our lengths plus the lengths of the type and the lengths
1183 * don't add up to the token size, it must be UCS2.
1185 if (old_len + new_len + 3 != token_sz) {
1187 old_len_offset = offset + (new_len * 2) + 2;
1188 old_len = tvb_get_guint8(tvb, old_len_offset);
1191 proto_tree_add_text(tree, tvb, offset + 1, 1, "New Value Length: %u",
1194 if (env_type != 7) { /* if it's not 'Collation Info - which is not textual! */
1195 string_offset = offset + 2;
1196 if (is_unicode == TRUE) {
1197 new_val = tvb_get_ephemeral_faked_unicode(tvb, string_offset,
1201 new_val = (gchar*)tvb_get_ephemeral_string(tvb, string_offset, new_len);
1202 proto_tree_add_text(tree, tvb, string_offset, new_len,
1203 "New Value: %s", new_val);
1205 else { /* parse collation info structure. From http://www.freetds.org/tds.html#collate */
1207 collate_codepage = tvb_get_letohs(tvb, offset);
1208 proto_tree_add_text(tree, tvb, offset, 2, "Codepage: %u" , collate_codepage);
1210 collate_flags = tvb_get_letohs(tvb, offset);
1211 proto_tree_add_text(tree, tvb, offset, 2, "Flags: 0x%x", collate_flags);
1213 collate_charset_id = tvb_get_guint8(tvb, offset);
1214 proto_tree_add_text(tree, tvb, offset, 1, "Charset ID: %u", collate_charset_id);
1219 proto_tree_add_text(tree, tvb, old_len_offset, 1, "Old Value Length: %u",
1222 string_offset = old_len_offset + 1;
1223 if (is_unicode == TRUE) {
1224 old_val = tvb_get_ephemeral_faked_unicode(tvb, string_offset,
1228 old_val = (gchar*)tvb_get_ephemeral_string(tvb, string_offset, old_len);
1229 proto_tree_add_text(tree, tvb, string_offset, old_len,
1230 "Old Value: %s", old_val);
1235 dissect_tds_err_token(tvbuff_t *tvb, guint offset, guint token_sz _U_, proto_tree *tree)
1238 guint8 srvr_len, proc_len;
1240 gboolean is_unicode = FALSE;
1242 proto_tree_add_text(tree, tvb, offset, 4, "SQL Error Number: %d", tds_tvb_get_xxtohl(tvb, offset, tds_little_endian));
1244 proto_tree_add_text(tree, tvb, offset, 1, "State: %u", tvb_get_guint8(tvb, offset));
1246 proto_tree_add_text(tree, tvb, offset, 1, "Severity Level: %u", tvb_get_guint8(tvb, offset));
1249 msg_len = tds_tvb_get_xxtohs(tvb, offset, tds_little_endian);
1250 proto_tree_add_text(tree, tvb, offset, 1, "Error message length: %u characters", msg_len);
1253 if(tvb_get_guint8(tvb, offset+1) == 0) /* FIXME: It's probably unicode, if the 2nd byte of the message is zero. It's not a good detection method, but it works */
1257 msg = tvb_get_ephemeral_faked_unicode(tvb, offset, msg_len, TRUE);
1260 msg = (gchar*)tvb_get_ephemeral_string(tvb, offset, msg_len);
1262 proto_tree_add_text(tree, tvb, offset, msg_len, "Error: %s", format_text((guchar*)msg, strlen(msg)));
1265 srvr_len = tvb_get_guint8(tvb, offset);
1267 proto_tree_add_text(tree, tvb, offset, 1, "Server name length: %u characters", srvr_len);
1271 msg = tvb_get_ephemeral_faked_unicode(tvb, offset, srvr_len, TRUE);
1274 msg = (gchar*)tvb_get_ephemeral_string(tvb, offset, srvr_len);
1276 proto_tree_add_text(tree, tvb, offset, srvr_len, "Server name: %s", msg);
1280 proc_len = tvb_get_guint8(tvb, offset);
1282 proto_tree_add_text(tree, tvb, offset, 1, "Process name length: %u characters", proc_len);
1286 msg = tvb_get_ephemeral_faked_unicode(tvb, offset, proc_len, TRUE);
1289 msg = (gchar*)tvb_get_ephemeral_string(tvb, offset, proc_len);
1291 proto_tree_add_text(tree, tvb, offset, proc_len, "Process name: %s", msg);
1295 proto_tree_add_text(tree, tvb, offset, 2, "line number: %d", tds_tvb_get_xxtohs(tvb, offset, tds_little_endian));
1299 dissect_tds_login_ack_token(tvbuff_t *tvb, guint offset, guint token_sz, proto_tree *tree)
1303 gboolean is_unicode = FALSE;
1305 proto_tree_add_text(tree, tvb, offset, 1, "Ack: %u", tvb_get_guint8(tvb, offset));
1307 proto_tree_add_text(tree, tvb, offset, 1, "Major version (may be incorrect): %d", tvb_get_guint8(tvb, offset));
1309 proto_tree_add_text(tree, tvb, offset, 1, "Minor version (may be incorrect): %d", tvb_get_guint8(tvb, offset));
1311 proto_tree_add_text(tree, tvb, offset, 2, "zero usually");
1314 msg_len = tvb_get_guint8(tvb, offset);
1315 proto_tree_add_text(tree, tvb, offset, 1, "Text length: %u characters", msg_len);
1318 if(msg_len + 6U + 3U != token_sz - 1) /* 6 is the length of ack(1), version (4), text length (1) fields */
1320 proto_tree_add_text(tree, tvb, offset, 0, "msg_len: %d, token_sz: %d, total: %d",msg_len, token_sz, msg_len + 6U + 3U);
1322 msg = tvb_get_ephemeral_faked_unicode(tvb, offset, msg_len, TRUE);
1325 msg = (gchar*)tvb_get_ephemeral_string(tvb, offset, msg_len);
1327 proto_tree_add_text(tree, tvb, offset, msg_len, "Text: %s", format_text((guchar*)msg, strlen(msg)));
1330 proto_tree_add_text(tree, tvb, offset, 4, "Server Version");
1335 dissect_tds7_results_token(tvbuff_t *tvb, guint offset, proto_tree *tree)
1337 guint16 num_columns, table_len;
1338 guint8 type, msg_len;
1341 guint16 collate_codepage, collate_flags;
1342 guint8 collate_charset_id;
1344 num_columns = tvb_get_letohs(tvb, offset);
1345 proto_tree_add_text(tree, tvb, offset, 2, "Columns: %u", tvb_get_letohs(tvb, offset));
1347 for(i=0; i != num_columns; i++) {
1348 proto_tree_add_text(tree, tvb, offset, 0, "Column %d", i + 1);
1349 proto_tree_add_text(tree, tvb, offset, 2, "usertype: %d", tvb_get_letohs(tvb, offset));
1351 proto_tree_add_text(tree, tvb, offset, 2, "flags: %d", tvb_get_letohs(tvb, offset));
1353 type = tvb_get_guint8(tvb, offset);
1354 proto_tree_add_text(tree, tvb, offset, 1, "Type: %d", type);
1356 if(type == 38 || type == 104 || type == 109 || type == 111) { /* ugly, ugly hack. Wish I knew what it really means!*/
1357 proto_tree_add_text(tree, tvb, offset, 1, "unknown 1 byte (%x)", tvb_get_guint8(tvb, offset));
1360 else if (type == 35) {
1361 proto_tree_add_text(tree, tvb, offset, 4, "unknown 4 bytes (%x)", tvb_get_letohl(tvb, offset));
1363 collate_codepage = tvb_get_letohs(tvb, offset);
1364 proto_tree_add_text(tree, tvb, offset, 2, "Codepage: %u" , collate_codepage);
1366 collate_flags = tvb_get_letohs(tvb, offset);
1367 proto_tree_add_text(tree, tvb, offset, 2, "Flags: 0x%x", collate_flags);
1369 collate_charset_id = tvb_get_guint8(tvb, offset);
1370 proto_tree_add_text(tree, tvb, offset, 1, "Charset ID: %u", collate_charset_id);
1372 table_len = tvb_get_letohs(tvb, offset);
1374 if(table_len != 0) {
1375 msg = tvb_get_ephemeral_faked_unicode(tvb, offset, table_len, TRUE);
1376 proto_tree_add_text(tree, tvb, offset, table_len*2, "Table name: %s", msg);
1377 offset += table_len*2;
1380 else if (type == 106 || type == 108) {
1381 proto_tree_add_text(tree, tvb, offset, 3, "unknown 3 bytes");
1384 else if(type > 128) {
1385 proto_tree_add_text(tree, tvb, offset, 2, "Large type size: 0x%x", tvb_get_letohs(tvb, offset));
1388 collate_codepage = tvb_get_letohs(tvb, offset);
1389 proto_tree_add_text(tree, tvb, offset, 2, "Codepage: %u" , collate_codepage);
1391 collate_flags = tvb_get_letohs(tvb, offset);
1392 proto_tree_add_text(tree, tvb, offset, 2, "Flags: 0x%x", collate_flags);
1394 collate_charset_id = tvb_get_guint8(tvb, offset);
1395 proto_tree_add_text(tree, tvb, offset, 1, "Charset ID: %u", collate_charset_id);
1399 msg_len = tvb_get_guint8(tvb, offset);
1400 proto_tree_add_text(tree, tvb, offset, 1, "message length: %d",msg_len);
1403 msg = tvb_get_ephemeral_faked_unicode(tvb, offset, msg_len, TRUE);
1404 proto_tree_add_text(tree, tvb, offset, msg_len*2, "Text: %s", msg);
1405 offset += msg_len*2;
1412 dissect_tds_done_token(tvbuff_t *tvb, guint offset, proto_tree *tree)
1414 proto_tree_add_text(tree, tvb, offset, 2, "Status flags");
1416 proto_tree_add_text(tree, tvb, offset, 2, "Operation");
1418 proto_tree_add_text(tree, tvb, offset, 4, "row count: %u", tds_tvb_get_xxtohl(tvb, offset, tds_little_endian));
1423 dissect_tds_rpc(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree)
1433 switch(tds_protocol_type) {
1434 case TDS_PROTOCOL_4:
1435 len = tvb_get_guint8(tvb, offset);
1436 proto_tree_add_text(tree, tvb, offset, 1, "RPC Name Length: %u", len);
1438 val = (gchar*)tvb_get_ephemeral_string(tvb, offset, len);
1439 proto_tree_add_text(tree, tvb, offset, len, "RPC Name: %s", val);
1443 case TDS_PROTOCOL_7:
1444 case TDS_PROTOCOL_8:
1445 default: /* unspecified: try as if TDS7/TDS8 */
1446 len = tvb_get_letohs(tvb, offset);
1447 proto_tree_add_text(tree, tvb, offset, 2, "RPC Name Length: %u", len);
1449 if (len == 0xFFFF) {
1450 sp_id = tvb_get_letohs(tvb, offset);
1451 proto_tree_add_text(tree, tvb, offset, 2, "RPC Stored Proc ID: %u (%s)",
1453 val_to_str(sp_id, internal_stored_proc_id_names, "Unknown"));
1456 else if (len != 0) {
1457 val = tvb_get_ephemeral_faked_unicode(tvb, offset, len, TRUE);
1459 proto_tree_add_text(tree, tvb, offset, len, "RPC Name: %s", val);
1464 proto_tree_add_text(tree, tvb, offset, -1, "Params (not dissected)");
1468 dissect_tds_resp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1471 proto_item *token_item;
1472 proto_tree *token_tree;
1473 guint pos, token_sz = 0;
1474 guint token_len_field_size = 2;
1475 guint token_len_field_val = 0;
1477 struct _netlib_data nl_data;
1478 gint length_remaining;
1480 memset(&nl_data, '\0', sizeof nl_data);
1483 * Until we reach the end of the packet, read tokens.
1486 while (tvb_reported_length_remaining(tvb, pos) > 0) {
1488 token = tvb_get_guint8(tvb, pos);
1490 /* TODO Handle TDS_PARAMFMT, TDS_PARAMS [similar to TDS_RESULTS, TDS_ROW] */
1491 if (tds_token_is_fixed_size(token)) {
1492 token_sz = tds_get_fixed_token_size(token) + 1;
1493 } else if (token == TDS_ROW_TOKEN) {
1495 * Rows are special; they have no size field and
1496 * aren't fixed length.
1498 token_sz = tds_get_row_size(tvb, &nl_data, pos + 1);
1500 token_sz = tds_get_variable_token_size(tvb, pos + 1,
1501 token, &token_len_field_size, &token_len_field_val);
1503 length_remaining = tvb_ensure_length_remaining(tvb, pos);
1505 if ((int) token_sz < 0) {
1506 proto_tree_add_text(tree, tvb, pos, 0, "Bogus token size: %u",
1510 if ((int) token_len_field_size < 0) {
1511 proto_tree_add_text(tree, tvb, pos, 0, "Bogus token length field size: %u",
1512 token_len_field_size);
1515 token_item = proto_tree_add_text(tree, tvb, pos, token_sz,
1516 "Token 0x%02x %s", token,
1517 val_to_str(token, token_names, "Unknown Token Type"));
1518 token_tree = proto_item_add_subtree(token_item, ett_tds_token);
1521 * If it's a variable token, put the length field in here
1522 * instead of replicating this for each token subdissector.
1524 if (!tds_token_is_fixed_size(token) && token != TDS_ROW_TOKEN) {
1525 proto_tree_add_text(token_tree, tvb, pos + 1,
1526 token_len_field_size, "Length: %u",
1527 token_len_field_val);
1530 if (token_sz > (guint)length_remaining)
1531 token_sz = (guint)length_remaining;
1535 case TDS_COL_NAME_TOKEN:
1538 * TODO dissect token to get "column names" to fill in _netlib_data
1542 case TDS_COL_INFO_TOKEN:
1544 * TDS 4.2: get the column info
1546 dissect_tds_col_info_token(tvb, &nl_data, pos);
1549 case TDS_RESULT_TOKEN:
1551 * If it's a result token, we need to stash the
1554 read_results_tds5(tvb, &nl_data, pos + 3, token_sz - 3);
1557 case TDS_ENV_CHG_TOKEN:
1558 dissect_tds_env_chg(tvb, pos + 3, token_sz - 3, token_tree);
1561 case TDS_AUTH_TOKEN:
1562 dissect_tds_nt(tvb, pinfo, token_tree, pos + 3, token_sz - 3);
1566 dissect_tds_err_token(tvb, pos + 3, token_sz - 3, token_tree);
1569 case TDS_DONE_TOKEN:
1570 case TDS_DONEPROC_TOKEN:
1571 case TDS_DONEINPROC_TOKEN:
1572 dissect_tds_done_token(tvb, pos + 1, token_tree);
1574 case TDS_LOGIN_ACK_TOKEN:
1575 dissect_tds_login_ack_token(tvb, pos + 3, token_sz - 3, token_tree);
1577 case TDS7_RESULT_TOKEN:
1578 pos = (dissect_tds7_results_token(tvb, pos + 1, token_tree)-1);
1582 /* and step to the end of the token, rinse, lather, repeat */
1588 dissect_netlib_buffer(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1591 proto_item *tds_item = NULL;
1592 proto_tree *tds_tree = NULL;
1597 guint8 packet_number;
1598 gboolean save_fragmented;
1600 fragment_data *fd_head;
1604 /* create display subtree for the protocol */
1605 tds_item = proto_tree_add_item(tree, proto_tds, tvb, offset, -1,
1608 tds_tree = proto_item_add_subtree(tds_item, ett_tds);
1610 type = tvb_get_guint8(tvb, offset);
1612 proto_tree_add_uint(tds_tree, hf_tds_type, tvb, offset, 1,
1615 status = tvb_get_guint8(tvb, offset + 1);
1617 proto_tree_add_uint(tds_tree, hf_tds_status, tvb, offset + 1, 1,
1620 size = tvb_get_ntohs(tvb, offset + 2);
1622 proto_tree_add_uint(tds_tree, hf_tds_size, tvb, offset + 2, 2,
1625 channel = tvb_get_ntohs(tvb, offset + 4);
1627 proto_tree_add_uint(tds_tree, hf_tds_channel, tvb, offset + 4, 2,
1630 packet_number = tvb_get_guint8(tvb, offset + 6);
1632 proto_tree_add_uint(tds_tree, hf_tds_packet_number, tvb, offset + 6, 1,
1634 proto_tree_add_item(tds_tree, hf_tds_window, tvb, offset + 7, 1,
1637 offset += 8; /* skip Netlib header */
1640 * Deal with fragmentation.
1642 * TODO: handle case where netlib headers 'packet-number'.is always 0
1643 * use fragment_add_seq_next in this case ?
1646 save_fragmented = pinfo->fragmented;
1647 if (tds_defragment &&
1648 (packet_number > 1 || status == STATUS_NOT_LAST_BUFFER)) {
1649 if (status == STATUS_NOT_LAST_BUFFER) {
1650 if (check_col(pinfo->cinfo, COL_INFO))
1651 col_append_str(pinfo->cinfo, COL_INFO,
1652 " (Not last buffer)");
1654 len = tvb_reported_length_remaining(tvb, offset);
1656 * XXX - I've seen captures that start with a login
1657 * packet with a sequence number of 2.
1659 fd_head = fragment_add_seq_check(tvb, offset, pinfo, channel,
1660 tds_fragment_table, tds_reassembled_table,
1661 packet_number - 1, len, status == STATUS_NOT_LAST_BUFFER);
1662 next_tvb = process_reassembled_data(tvb, offset, pinfo,
1663 "Reassembled TDS", fd_head, &tds_frag_items, NULL,
1667 * If this isn't the last buffer, just show it as a fragment.
1668 * (XXX - it'd be nice to dissect it if it's the first
1669 * buffer, but we'd need to do reassembly in order to
1672 * If this is the last buffer, dissect it.
1673 * (XXX - it'd be nice to show it as a fragment if it's part
1674 * of a fragmented message, but we'd need to do reassembly
1675 * in order to discover that.)
1677 if (status == STATUS_NOT_LAST_BUFFER)
1680 next_tvb = tvb_new_subset(tvb, offset, -1, -1);
1684 if (next_tvb != NULL) {
1689 dissect_tds_rpc(next_tvb, pinfo, tds_tree);
1693 dissect_tds_resp(next_tvb, pinfo, tds_tree);
1696 case TDS_LOGIN7_PKT:
1697 dissect_tds7_login(next_tvb, pinfo, tds_tree);
1700 dissect_tds_query_packet(next_tvb, pinfo, tds_tree);
1702 case TDS_QUERY5_PKT:
1703 dissect_tds_query5_packet(next_tvb, pinfo, tds_tree);
1705 case TDS_NTLMAUTH_PKT:
1706 dissect_tds_nt(next_tvb, pinfo, tds_tree, offset - 8, -1);
1709 proto_tree_add_text(tds_tree, next_tvb, 0, -1,
1714 next_tvb = tvb_new_subset (tvb, offset, -1, -1);
1715 call_dissector(data_handle, next_tvb, pinfo, tds_tree);
1720 dissect_tds_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1722 volatile gboolean first_time = TRUE;
1723 volatile int offset = 0;
1724 guint length_remaining;
1728 tvbuff_t *volatile next_tvb;
1729 proto_item *tds_item = NULL;
1730 proto_tree *tds_tree = NULL;
1732 while (tvb_reported_length_remaining(tvb, offset) != 0) {
1733 length_remaining = tvb_ensure_length_remaining(tvb, offset);
1736 * Can we do reassembly?
1738 if (tds_desegment && pinfo->can_desegment) {
1740 * Yes - is the fixed-length part of the PDU
1741 * split across segment boundaries?
1743 if (length_remaining < 8) {
1745 * Yes. Tell the TCP dissector where the
1746 * data for this message starts in the data
1747 * it handed us, and how many more bytes we
1750 pinfo->desegment_offset = offset;
1751 pinfo->desegment_len = 8 - length_remaining;
1756 type = tvb_get_guint8(tvb, offset);
1759 * Get the length of the PDU.
1761 plen = tvb_get_ntohs(tvb, offset + 2);
1764 * The length is less than the header length.
1765 * Put in the type, status, and length, and
1766 * report the length as bogus.
1769 /* create display subtree for the protocol */
1770 tds_item = proto_tree_add_item(tree, proto_tds,
1771 tvb, offset, -1, FALSE);
1773 tds_tree = proto_item_add_subtree(tds_item,
1775 proto_tree_add_uint(tds_tree, hf_tds_type, tvb,
1777 proto_tree_add_item(tds_tree, hf_tds_status,
1778 tvb, offset + 1, 1, FALSE);
1779 proto_tree_add_uint_format(tds_tree,
1780 hf_tds_size, tvb, offset + 2, 2, plen,
1781 "Size: %u (bogus, should be >= 8)", plen);
1785 * Give up - we can't dissect any more of this
1792 * Can we do reassembly?
1794 if (tds_desegment && pinfo->can_desegment) {
1796 * Yes - is the PDU split across segment boundaries?
1798 if (length_remaining < plen) {
1800 * Yes. Tell the TCP dissector where the
1801 * data for this message starts in the data
1802 * it handed us, and how many more bytes we
1805 pinfo->desegment_offset = offset;
1806 pinfo->desegment_len = plen - length_remaining;
1812 if (check_col(pinfo->cinfo, COL_PROTOCOL))
1813 col_set_str(pinfo->cinfo, COL_PROTOCOL, "TDS");
1816 * Set the packet description based on its TDS packet
1819 if (check_col(pinfo->cinfo, COL_INFO)) {
1820 col_add_str(pinfo->cinfo, COL_INFO,
1821 val_to_str(type, packet_type_names,
1822 "Unknown Packet Type: %u"));
1828 * Construct a tvbuff containing the amount of the payload
1829 * we have available. Make its reported length the amount
1830 * of data in the PDU.
1832 * XXX - if reassembly isn't enabled. the subdissector will
1833 * throw a BoundsError exception, rather than a
1834 * ReportedBoundsError exception. We really want a tvbuff
1835 * where the length is "length", the reported length is
1836 * "plen", and the "if the snapshot length were infinite"
1837 * length is the minimum of the reported length of the tvbuff
1838 * handed to us and "plen", with a new type of exception
1839 * thrown if the offset is within the reported length but
1840 * beyond that third length, with that exception getting the
1841 * "Unreassembled Packet" error.
1843 length = length_remaining;
1846 next_tvb = tvb_new_subset(tvb, offset, length, plen);
1849 * Dissect the Netlib buffer.
1851 * Catch the ReportedBoundsError exception; if this
1852 * particular Netlib buffer happens to get a
1853 * ReportedBoundsError exception, that doesn't mean
1854 * that we should stop dissecting PDUs within this frame
1855 * or chunk of reassembled data.
1857 * If it gets a BoundsError, we can stop, as there's nothing
1858 * more to see, so we just re-throw it.
1861 dissect_netlib_buffer(next_tvb, pinfo, tree);
1863 CATCH(BoundsError) {
1866 CATCH(ReportedBoundsError) {
1867 show_reported_bounds_error(tvb, pinfo, tree);
1872 * Step to the next Netlib buffer.
1879 dissect_tds_tcp_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1885 conversation_t *conv;
1888 * If we don't have even enough data for a Netlib header,
1889 * just say it's not TDS.
1891 if (tvb_length(tvb) < 8)
1895 * Quickly scan all the data we have in order to see if
1896 * everything in it looks like Netlib traffic.
1898 while (tvb_bytes_exist(tvb, offset, 1)) {
1900 * Check the type field.
1902 type = tvb_get_guint8(tvb, offset);
1903 if (!is_valid_tds_type(type))
1907 * Check the status field, if it's present.
1909 if (!tvb_bytes_exist(tvb, offset + 1, 1))
1911 status = tvb_get_guint8(tvb, offset + 1);
1912 if (!is_valid_tds_status(status))
1916 * Get the length of the PDU.
1918 if (!tvb_bytes_exist(tvb, offset + 2, 2))
1920 plen = tvb_get_ntohs(tvb, offset + 2);
1923 * The length is less than the header length.
1930 * If we're at the beginning of the segment, check the
1931 * payload if it's a login packet.
1934 if (!netlib_check_login_pkt(tvb, offset, pinfo, type))
1939 * Step to the next Netlib buffer.
1945 * OK, it passes the test; assume the rest of this conversation
1948 conv = find_conversation(pinfo->fd->num, &pinfo->src, &pinfo->dst, pinfo->ptype,
1949 pinfo->srcport, pinfo->destport, 0);
1952 * No conversation exists yet - create one.
1954 conv = conversation_new(pinfo->fd->num, &pinfo->src, &pinfo->dst,
1955 pinfo->ptype, pinfo->srcport, pinfo->destport, 0);
1957 conversation_set_dissector(conv, tds_tcp_handle);
1960 * Now dissect it as TDS.
1962 dissect_tds_tcp(tvb, pinfo, tree);
1970 * Initialize the fragment and reassembly tables.
1972 fragment_table_init(&tds_fragment_table);
1973 reassembled_table_init(&tds_reassembled_table);
1977 /* Register the protocol with Wireshark */
1979 /* this format is required because a script is used to build the C function
1980 that calls all the protocol registration.
1984 proto_register_tds(void)
1986 static hf_register_info hf[] = {
1988 { "Type", "tds.type",
1989 FT_UINT8, BASE_HEX, VALS(packet_type_names), 0x0,
1990 "Packet Type", HFILL }
1993 { "Status", "tds.status",
1994 FT_UINT8, BASE_DEC, VALS(status_names), 0x0,
1995 "Frame status", HFILL }
1998 { "Size", "tds.size",
1999 FT_UINT16, BASE_DEC, NULL, 0x0,
2000 "Packet Size", HFILL }
2003 { "Channel", "tds.channel",
2004 FT_UINT16, BASE_DEC, NULL, 0x0,
2005 "Channel Number", HFILL }
2007 { &hf_tds_packet_number,
2008 { "Packet Number", "tds.packet_number",
2009 FT_UINT8, BASE_DEC, NULL, 0x0,
2013 { "Window", "tds.window",
2014 FT_UINT8, BASE_DEC, NULL, 0x0,
2017 { &hf_tds_fragment_overlap,
2018 { "Segment overlap", "tds.fragment.overlap",
2019 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
2020 "Fragment overlaps with other fragments", HFILL }
2022 { &hf_tds_fragment_overlap_conflict,
2023 { "Conflicting data in fragment overlap", "tds.fragment.overlap.conflict",
2024 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
2025 "Overlapping fragments contained conflicting data", HFILL }
2027 { &hf_tds_fragment_multiple_tails,
2028 { "Multiple tail fragments found", "tds.fragment.multipletails",
2029 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
2030 "Several tails were found when defragmenting the packet", HFILL }
2032 { &hf_tds_fragment_too_long_fragment,
2033 { "Segment too long", "tds.fragment.toolongfragment",
2034 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
2035 "Segment contained data past end of packet", HFILL }
2037 { &hf_tds_fragment_error,
2038 { "Defragmentation error", "tds.fragment.error",
2039 FT_FRAMENUM, BASE_NONE, NULL, 0x0,
2040 "Defragmentation error due to illegal fragments", HFILL }
2043 { "TDS Fragment", "tds.fragment",
2044 FT_FRAMENUM, BASE_NONE, NULL, 0x0,
2047 { &hf_tds_fragments,
2048 { "TDS Fragments", "tds.fragments",
2049 FT_NONE, BASE_NONE, NULL, 0x0,
2052 { &hf_tds_reassembled_in,
2053 { "Reassembled TDS in frame", "tds.reassembled_in",
2054 FT_FRAMENUM, BASE_NONE, NULL, 0x0,
2055 "This TDS packet is reassembled in this frame", HFILL }
2057 { &hf_tds7_login_total_size,
2058 { "Total Packet Length", "tds7login.total_len",
2059 FT_UINT32, BASE_DEC, NULL, 0x0,
2060 "TDS7 Login Packet total packet length", HFILL }
2063 { "TDS version", "tds7login.version",
2064 FT_UINT32, BASE_HEX, NULL, 0x0,
2067 { &hf_tds7_packet_size,
2068 { "Packet Size", "tds7login.packet_size",
2069 FT_UINT32, BASE_DEC, NULL, 0x0,
2070 "Packet size", HFILL }
2072 { &hf_tds7_client_version,
2073 { "Client version", "tds7login.client_version",
2074 FT_UINT32, BASE_DEC, NULL, 0x0,
2077 { &hf_tds7_client_pid,
2078 { "Client PID", "tds7login.client_pid",
2079 FT_UINT32, BASE_DEC, NULL, 0x0,
2082 { &hf_tds7_connection_id,
2083 { "Connection ID", "tds7login.connection_id",
2084 FT_UINT32, BASE_DEC, NULL, 0x0,
2087 { &hf_tds7_option_flags1,
2088 { "Option Flags 1", "tds7login.option_flags1",
2089 FT_UINT8, BASE_HEX, NULL, 0x0,
2092 { &hf_tds7_option_flags2,
2093 { "Option Flags 2", "tds7login.option_flags2",
2094 FT_UINT8, BASE_HEX, NULL, 0x0,
2097 { &hf_tds7_sql_type_flags,
2098 { "SQL Type Flags", "tds7login.sql_type_flags",
2099 FT_UINT8, BASE_HEX, NULL, 0x0,
2102 { &hf_tds7_reserved_flags,
2103 { "Reserved Flags", "tds7login.reserved_flags",
2104 FT_UINT8, BASE_HEX, NULL, 0x0,
2105 "reserved flags", HFILL }
2107 { &hf_tds7_time_zone,
2108 { "Time Zone", "tds7login.time_zone",
2109 FT_UINT32, BASE_HEX, NULL, 0x0,
2112 { &hf_tds7_collation,
2113 { "Collation", "tds7login.collation",
2114 FT_UINT32, BASE_HEX, NULL, 0x0,
2118 { "Message", "tds7.message",
2119 FT_STRING, BASE_NONE, NULL, 0x0,
2124 static gint *ett[] = {
2132 module_t *tds_module;
2134 /* Register the protocol name and description */
2135 proto_tds = proto_register_protocol("Tabular Data Stream",
2138 /* Required function calls to register the header fields and subtrees used */
2139 proto_register_field_array(proto_tds, hf, array_length(hf));
2140 proto_register_subtree_array(ett, array_length(ett));
2142 /* Allow dissector to be found by name. */
2143 register_dissector("tds", dissect_tds_tcp, proto_tds);
2145 tds_module = prefs_register_protocol(proto_tds, NULL);
2146 prefs_register_bool_preference(tds_module, "desegment_buffers",
2147 "Reassemble TDS buffers spanning multiple TCP segments",
2148 "Whether the TDS dissector should reassemble TDS buffers spanning multiple TCP segments. "
2149 "To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.",
2151 prefs_register_bool_preference(tds_module, "defragment",
2152 "Reassemble fragmented TDS messages with multiple buffers",
2153 "Whether the TDS dissector should defragment messages spanning multiple Netlib buffers",
2155 prefs_register_enum_preference(tds_module, "protocol_type",
2156 "TDS Protocol Type",
2157 "Hint as to version of TDS protocol being decoded",
2158 &tds_protocol_type, tds_protocol_type_options, FALSE);
2159 prefs_register_enum_preference(tds_module, "endian_type",
2161 "Hint as to whether to decode TDS protocol as little-endian or big-endian. (TDS7/8 always decoded as little-endian)",
2162 &tds_little_endian, tds_endian_type_options, FALSE);
2163 prefs_register_range_preference(tds_module, "tcp_ports",
2165 "Additional TCP ports to decode as TDS",
2166 &tds_tcp_ports, 0xFFFF);
2168 register_init_routine(tds_init);
2171 /* If this dissector uses sub-dissector registration add a registration routine.
2172 This format is required because a script is used to find these routines and
2173 create the code that calls these routines.
2176 proto_reg_handoff_tds(void)
2178 tds_tcp_handle = create_dissector_handle(dissect_tds_tcp, proto_tds);
2180 /* Initial TDS ports: MS SQL default ports */
2181 dissector_add("tcp.port", 1433, tds_tcp_handle);
2182 dissector_add("tcp.port", 2433, tds_tcp_handle);
2184 heur_dissector_add("tcp", dissect_tds_tcp_heur, proto_tds);
2186 ntlmssp_handle = find_dissector("ntlmssp");
2187 gssapi_handle = find_dissector("gssapi");
2188 data_handle = find_dissector("data");