2 * Routines for TDS NetLib dissection
3 * Copyright 2000-2002, Brian Bruns <camber@ais.org>
4 * Copyright 2002, Steve Langasek <vorlon@netexpress.net>
8 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@ethereal.com>
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 ethereal-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>
163 #define TDS_QUERY_PKT 1
164 #define TDS_LOGIN_PKT 2
165 #define TDS_RPC_PKT 3
166 #define TDS_RESP_PKT 4
167 #define TDS_RAW_PKT 5
168 #define TDS_CANCEL_PKT 6
169 #define TDS_BULK_DATA_PKT 7
170 #define TDS_OPEN_CHN_PKT 8
171 #define TDS_CLOSE_CHN_PKT 9
172 #define TDS_RES_ERROR_PKT 10
173 #define TDS_LOG_CHN_ACK_PKT 11
174 #define TDS_ECHO_PKT 12
175 #define TDS_LOGOUT_CHN_PKT 13
176 #define TDS_QUERY5_PKT 15 /* or "Normal tokenized request or response */
177 #define TDS_LOGIN7_PKT 16 /* or "Urgent tokenized request or response */
178 #define TDS_NTLMAUTH_PKT 17
179 #define TDS_XXX7_PKT 18 /* seen in one capture */
181 #define is_valid_tds_type(x) ((x) >= TDS_QUERY_PKT && (x) <= TDS_XXX7_PKT)
183 /* The following constants are imported more or less directly from FreeTDS */
184 /* TODO Update from current version of FreeTDS tds.h */
186 #define TDS5_PARAMS_TOKEN 215 /* 0xD7 TDS 5.0 only */
187 #define TDS5_DYNAMIC_TOKEN 231 /* 0xE7 TDS 5.0 only */
188 #define TDS5_PARAMFMT_TOKEN 236 /* 0xEC TDS 5.0 only */
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 TDS7_RESULT_TOKEN 129 /* 0x81 TDS 7.0 only */
199 #define TDS_COL_NAME_TOKEN 160 /* 0xA0 TDS 4.2 only */
200 #define TDS_COL_INFO_TOKEN 161 /* 0xA1 TDS 4.2 only - TDS_COLFMT */
201 #define TDS5_DYNAMIC2_TOKEN 163 /* 0xA3 TDS 5.0 only */
202 /*#define TDS_TABNAME 164 */
203 /*#define TDS_COL_INFO 165 */
204 #define TDS_COMPUTE_NAMES_TOKEN 167 /* 0xA7 */
205 #define TDS_COMPUTE_RESULT_TOKEN 168 /* 0xA8 */
206 #define TDS_ORDER_BY_TOKEN 169 /* 0xA9 TDS_ORDER */
207 #define TDS_ERR_TOKEN 170 /* 0xAA */
208 #define TDS_MSG_TOKEN 171 /* 0xAB */
209 #define TDS_PARAM_TOKEN 172 /* 0xAC RETURNVALUE? */
210 #define TDS_LOGIN_ACK_TOKEN 173 /* 0xAD */
211 #define TDS_CONTROL_TOKEN 174 /* 0xAE TDS_CONTROL */
212 #define TDS_KEY_TOKEN 202 /* 0xCA */
213 #define TDS_ROW_TOKEN 209 /* 0xD1 */
214 #define TDS_CMP_ROW_TOKEN 211 /* 0xD3 */
215 #define TDS_CAP_TOKEN 226 /* 0xE2 */
216 #define TDS_ENV_CHG_TOKEN 227 /* 0xE3 */
217 #define TDS_EED_TOKEN 229 /* 0xE5 */
218 #define TDS_AUTH_TOKEN 237 /* 0xED */
219 #define TDS_RESULT_TOKEN 238 /* 0xEE */
220 #define TDS_DONE_TOKEN 253 /* 0xFD TDS_DONE */
221 #define TDS_DONEPROC_TOKEN 254 /* 0xFE TDS_DONEPROC */
222 #define TDS_DONEINPROC_TOKEN 255 /* 0xFF TDS_DONEINPROC */
224 /* Microsoft internal stored procedure id's */
226 #define TDS_SP_CURSOR 1
227 #define TDS_SP_CURSOROPEN 2
228 #define TDS_SP_CURSORPREPARE 3
229 #define TDS_SP_CURSOREXECUTE 4
230 #define TDS_SP_CURSORPREPEXEC 5
231 #define TDS_SP_CURSORUNPREPARE 6
232 #define TDS_SP_CURSORFETCH 7
233 #define TDS_SP_CURSOROPTION 8
234 #define TDS_SP_CURSORCLOSE 9
235 #define TDS_SP_EXECUTESQL 10
236 #define TDS_SP_PREPARE 11
237 #define TDS_SP_EXECUTE 12
238 #define TDS_SP_PREPEXEC 13
239 #define TDS_SP_PREPEXECRPC 14
240 #define TDS_SP_UNPREPARE 15
242 /* Sybase Data Types */
244 #define SYBCHAR 47 /* 0x2F */
245 #define SYBVARCHAR 39 /* 0x27 */
246 #define SYBINTN 38 /* 0x26 */
247 #define SYBINT1 48 /* 0x30 */
248 #define SYBINT2 52 /* 0x34 */
249 #define SYBINT4 56 /* 0x38 */
250 #define SYBINT8 127 /* 0x7F */
251 #define SYBFLT8 62 /* 0x3E */
252 #define SYBDATETIME 61 /* 0x3D */
253 #define SYBBIT 50 /* 0x32 */
254 #define SYBTEXT 35 /* 0x23 */
255 #define SYBNTEXT 99 /* 0x63 */
256 #define SYBIMAGE 34 /* 0x22 */
257 #define SYBMONEY4 122 /* 0x7A */
258 #define SYBMONEY 60 /* 0x3C */
259 #define SYBDATETIME4 58 /* 0x3A */
260 #define SYBREAL 59 /* 0x3B */
261 #define SYBBINARY 45 /* 0x2D */
262 #define SYBVOID 31 /* 0x1F */
263 #define SYBVARBINARY 37 /* 0x25 */
264 #define SYBNVARCHAR 103 /* 0x67 */
265 #define SYBBITN 104 /* 0x68 */
266 #define SYBNUMERIC 108 /* 0x6C */
267 #define SYBDECIMAL 106 /* 0x6A */
268 #define SYBFLTN 109 /* 0x6D */
269 #define SYBMONEYN 110 /* 0x6E */
270 #define SYBDATETIMN 111 /* 0x6F */
271 #define XSYBCHAR 167 /* 0xA7 */
272 #define XSYBVARCHAR 175 /* 0xAF */
273 #define XSYBNVARCHAR 231 /* 0xE7 */
274 #define XSYBNCHAR 239 /* 0xEF */
275 #define SYBUNIQUE 0x24
276 #define SYBVARIANT 0x62
278 #define is_fixed_coltype(x) (x==SYBINT1 || \
291 /* Initialize the protocol and registered fields */
292 static int proto_tds = -1;
293 static int hf_tds_type = -1;
294 static int hf_tds_status = -1;
295 static int hf_tds_size = -1;
296 static int hf_tds_channel = -1;
297 static int hf_tds_packet_number = -1;
298 static int hf_tds_window = -1;
299 static int hf_tds_reassembled_in = -1;
300 static int hf_tds_fragments = -1;
301 static int hf_tds_fragment = -1;
302 static int hf_tds_fragment_overlap = -1;
303 static int hf_tds_fragment_overlap_conflict = -1;
304 static int hf_tds_fragment_multiple_tails = -1;
305 static int hf_tds_fragment_too_long_fragment = -1;
306 static int hf_tds_fragment_error = -1;
308 static int hf_tds7_login_total_size = -1;
309 static int hf_tds7_version = -1;
310 static int hf_tds7_packet_size = -1;
311 static int hf_tds7_client_version = -1;
312 static int hf_tds7_client_pid = -1;
313 static int hf_tds7_connection_id = -1;
314 static int hf_tds7_option_flags1 = -1;
315 static int hf_tds7_option_flags2 = -1;
316 static int hf_tds7_sql_type_flags = -1;
317 static int hf_tds7_reserved_flags = -1;
318 static int hf_tds7_time_zone = -1;
319 static int hf_tds7_collation = -1;
320 static int hf_tds7_message = -1;
322 /* Initialize the subtree pointers */
323 static gint ett_tds = -1;
324 static gint ett_tds_fragments = -1;
325 static gint ett_tds_fragment = -1;
326 static gint ett_tds_token = -1;
327 static gint ett_tds7_login = -1;
328 static gint ett_tds7_query = 0;
329 static gint ett_tds7_hdr = -1;
331 /* Desegmentation of Netlib buffers crossing TCP segment boundaries. */
332 static gboolean tds_desegment = TRUE;
334 static const fragment_items tds_frag_items = {
339 &hf_tds_fragment_overlap,
340 &hf_tds_fragment_overlap_conflict,
341 &hf_tds_fragment_multiple_tails,
342 &hf_tds_fragment_too_long_fragment,
343 &hf_tds_fragment_error,
344 &hf_tds_reassembled_in,
348 /* Tables for reassembly of fragments. */
349 static GHashTable *tds_fragment_table = NULL;
350 static GHashTable *tds_reassembled_table = NULL;
352 /* defragmentation of multi-buffer TDS PDUs */
353 static gboolean tds_defragment = TRUE;
355 static dissector_handle_t tds_tcp_handle;
356 static dissector_handle_t ntlmssp_handle;
357 static dissector_handle_t gssapi_handle;
358 static dissector_handle_t data_handle;
360 /* TDS protocol type preference */
361 /* XXX: This preference is used as a 'hint' for cases where interpretation is ambiguous */
362 /* Currently the hint is global */
363 /* TODO: Consider storing protocol type with each conversation */
364 /* (when type is determined and using the preference as a default) ?? */
366 #define TDS_PROTOCOL_NOT_SPECIFIED 0
367 #define TDS_PROTOCOL_4 4
368 #define TDS_PROTOCOL_5 5
369 #define TDS_PROTOCOL_7 7
370 #define TDS_PROTOCOL_8 8
372 static gint tds_protocol_type = TDS_PROTOCOL_NOT_SPECIFIED;
374 const enum_val_t tds_protocol_type_options[] = {
375 {"not_specified", "Not Specified", TDS_PROTOCOL_NOT_SPECIFIED},
376 {"tds4", "TDS 4", TDS_PROTOCOL_4}, /* TDS 4.2 and TDS 4.6 */
377 {"tds5", "TDS 5", TDS_PROTOCOL_5},
378 {"tds7", "TDS 7", TDS_PROTOCOL_7},
379 {"tds8", "TDS 8", TDS_PROTOCOL_8},
383 #define TDS_PROTO_PREF_NOT_SPECIFIED (tds_protocol_type == TDS_NOT_SPECIFIED)
384 #define TDS_PROTO_PREF_TDS4 (tds_protocol_type == TDS_PROTOCOL_4)
385 #define TDS_PROTO_PREF_TDS5 (tds_protocol_type == TDS_PROTOCOL_5)
386 #define TDS_PROTO_PREF_TDS7 (tds_protocol_type == TDS_PROTOCOL_7)
387 #define TDS_PROTO_PREF_TDS8 (tds_protocol_type == TDS_PROTOCOL_8)
388 #define TDS_PROTO_PREF_TDS7_TDS8 ( TDS_PROTO_PREF_TDS7 || TDS_PROTO_PREF_TDS8 )
390 /* TDS "endian type" */
391 /* XXX: Assumption is that all TDS conversations being decoded in a particular capture */
392 /* have the same endian type */
393 /* TODO: consider storing endian type with each conversation */
394 /* (using pref as the default) */
396 static gint tds_little_endian = TRUE;
398 const enum_val_t tds_endian_type_options[] = {
399 {"little_endian", "Little Endian", TRUE},
400 {"big_endian" , "Big Endian" , FALSE},
405 /* TCP port preferences for TDS decode */
407 static range_t *tds_tcp_ports = NULL;
409 /* These correspond to the netlib packet type field */
410 static const value_string packet_type_names[] = {
411 {TDS_QUERY_PKT, "Query Packet"},
412 {TDS_LOGIN_PKT, "Login Packet"},
413 {TDS_RPC_PKT, "Remote Procedure Call Packet"},
414 {TDS_RESP_PKT, "Response Packet"},
415 {TDS_CANCEL_PKT, "Cancel Packet"},
416 {TDS_QUERY5_PKT, "TDS5 Query Packet"},
417 {TDS_LOGIN7_PKT, "TDS7/8 Login Packet"},
418 {TDS_XXX7_PKT, "TDS7/8 0x12 Packet"},
419 {TDS_NTLMAUTH_PKT, "NT Authentication Packet"},
423 /* The status field */
425 #define is_valid_tds_status(x) ((x) <= STATUS_EVENT_NOTIFICATION)
427 #define STATUS_NOT_LAST_BUFFER 0x00
428 #define STATUS_LAST_BUFFER 0x01
429 #define STATUS_ATTN_REQUEST_ACK 0x02
430 #define STATUS_ATTN_REQUEST 0x03
431 #define STATUS_EVENT_NOTIFICATION 0x04
433 static const value_string status_names[] = {
434 {STATUS_NOT_LAST_BUFFER, "Not last buffer"},
435 {STATUS_LAST_BUFFER, "Last buffer in request or response"},
436 {STATUS_ATTN_REQUEST_ACK, "Acknowledgment of last attention request"},
437 {STATUS_ATTN_REQUEST, "Attention request"},
438 {STATUS_EVENT_NOTIFICATION, "Event notification"},
442 /* The one byte token at the start of each TDS PDU */
443 static const value_string token_names[] = {
444 {TDS5_DYNAMIC_TOKEN, "TDS5 Dynamic SQL"},
445 {TDS5_PARAMFMT_TOKEN, "TDS5 Parameter Format"},
446 {TDS5_PARAMFMT2_TOKEN, "TDS5 Parameter2 Format"},
447 {TDS5_PARAMS_TOKEN, "TDS5 Parameters"},
448 {TDS_LANG_TOKEN, "Language"},
449 {TDS_LOGOUT_TOKEN, "Logout"},
450 {TDS_RET_STAT_TOKEN, "Return Status"},
451 {TDS_PROCID_TOKEN, "Proc ID"},
452 {TDS7_RESULT_TOKEN, "TDS7+ Results"},
453 {TDS_COL_NAME_TOKEN, "Column Names"},
454 {TDS_COL_INFO_TOKEN, "Column Info"},
455 {TDS_COMPUTE_NAMES_TOKEN, "Compute Names"},
456 {TDS_COMPUTE_RESULT_TOKEN, "Compute Results"},
457 {TDS_ORDER_BY_TOKEN, "Order By"},
458 {TDS_ERR_TOKEN, "Error Message"},
459 {TDS_MSG_TOKEN, "Info Message"},
460 {TDS_PARAM_TOKEN, "Parameter"},
461 {TDS_LOGIN_ACK_TOKEN, "Login Acknowledgement"},
462 {TDS_CONTROL_TOKEN, "TDS Control"},
463 {TDS_KEY_TOKEN, "TDS Key"},
464 {TDS_ROW_TOKEN, "Row"},
465 {TDS_CMP_ROW_TOKEN, "Compute Row"},
466 {TDS_CAP_TOKEN, "Capabilities"},
467 {TDS_ENV_CHG_TOKEN, "Environment Change"},
468 {TDS_EED_TOKEN, "Extended Error"},
469 {TDS_AUTH_TOKEN, "Authentication"},
470 {TDS_RESULT_TOKEN, "Results"},
471 {TDS_DONE_TOKEN, "Done"},
472 {TDS_DONEPROC_TOKEN, "Done Proc"},
473 {TDS_DONEINPROC_TOKEN, "Done In Proc"},
474 {TDS5_DYNAMIC2_TOKEN, "TDS5 Dynamic2"},
475 {TDS5_ORDERBY2_TOKEN, "TDS5 OrderBy2"},
476 {TDS5_CURDECLARE2_TOKEN, "TDS5 CurDeclare2"},
477 {TDS5_ROWFMT2_TOKEN, "TDS5 RowFmt2"},
478 {TDS5_MSG_TOKEN, "TDS5 Msg"},
483 static const value_string internal_stored_proc_id_names[] = {
484 {TDS_SP_CURSOR, "sp_cursor" },
485 {TDS_SP_CURSOROPEN, "sp_cursoropen" },
486 {TDS_SP_CURSORPREPARE, "sp_cursorprepare" },
487 {TDS_SP_CURSOREXECUTE, "sp_cursorexecute" },
488 {TDS_SP_CURSORPREPEXEC, "sp_cursorprepexec" },
489 {TDS_SP_CURSORUNPREPARE, "sp_cursorunprepare"},
490 {TDS_SP_CURSORFETCH, "sp_cursorfetch" },
491 {TDS_SP_CURSOROPTION, "sp_cursoroption" },
492 {TDS_SP_CURSORCLOSE, "sp_cursorclose" },
493 {TDS_SP_EXECUTESQL, "sp_executesql" },
494 {TDS_SP_PREPARE, "sp_prepare" },
495 {TDS_SP_EXECUTE, "sp_execute" },
496 {TDS_SP_PREPEXEC, "sp_prepexec" },
497 {TDS_SP_PREPEXECRPC, "sp_prepexecrpc" },
498 {TDS_SP_UNPREPARE, "sp_unprepare" },
502 static const value_string env_chg_names[] = {
507 {5, "Unicode Locale ID"},
508 {6, "Unicode Comparison Style"},
509 {7, "Collation Info"},
513 static const value_string login_field_names[] = {
522 {8, "Database Name"},
527 #define MAX_COLUMNS 256
530 * This is where we store the column information to be used in decoding the
531 * TDS_ROW_TOKEN tokens.
540 struct _netlib_data {
542 struct _tds_col *columns[MAX_COLUMNS];
545 struct tds7_login_packet_hdr {
546 guint32 total_packet_size;
549 guint32 client_version;
551 guint32 connection_id;
552 guint8 option_flags1;
553 guint8 option_flags2;
554 guint8 sql_type_flags;
555 guint8 reserved_flags;
560 /* all the standard memory management stuff */
561 #define tds_column_length (sizeof(struct _tds_col))
562 #define tds_column_init_count 40
564 static GMemChunk *tds_column = NULL;
566 /* support routines */
569 dissect_tds_nt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
570 guint offset, guint length)
574 nt_tvb = tvb_new_subset(tvb, offset, -1, length);
575 if(tvb_strneql(tvb, offset, "NTLMSSP", 7) == 0)
576 call_dissector(ntlmssp_handle, nt_tvb, pinfo, tree);
578 call_dissector(gssapi_handle, nt_tvb, pinfo, tree);
584 tds_tvb_get_xxtohs(tvbuff_t *tvb, gint offset, gint tds_little_endian) {
585 if (tds_little_endian)
586 return tvb_get_letohs(tvb, offset);
588 return tvb_get_ntohs(tvb, offset);
592 tds_tvb_get_xxtohl(tvbuff_t *tvb, gint offset, gint tds_little_endian) {
593 if (tds_little_endian)
594 return tvb_get_letohl(tvb, offset);
596 return tvb_get_ntohl(tvb, offset);
600 static int tds_token_is_fixed_size(guint8 token)
604 case TDS_DONEPROC_TOKEN:
605 case TDS_DONEINPROC_TOKEN:
606 case TDS_RET_STAT_TOKEN:
607 case TDS7_RESULT_TOKEN:
608 case TDS_PROCID_TOKEN:
609 case TDS_LOGOUT_TOKEN:
617 static int tds_get_fixed_token_size(guint8 token)
621 case TDS_DONEPROC_TOKEN:
622 case TDS_DONEINPROC_TOKEN:
623 case TDS_PROCID_TOKEN:
625 case TDS_RET_STAT_TOKEN:
627 case TDS_LOGOUT_TOKEN:
629 case TDS7_RESULT_TOKEN:
636 tds_get_variable_token_size(tvbuff_t *tvb, gint offset, guint8 token,
637 guint *len_field_size_p, guint *len_field_val_p)
640 /* some tokens have a 4 byte length field */
641 case TDS5_PARAMFMT2_TOKEN:
643 case TDS5_ORDERBY2_TOKEN:
644 case TDS5_CURDECLARE2_TOKEN:
645 case TDS5_ROWFMT2_TOKEN:
646 case TDS5_DYNAMIC2_TOKEN:
647 *len_field_size_p = 4;
648 *len_field_val_p = tds_tvb_get_xxtohl(tvb, offset, tds_little_endian);
650 /* some have a 1 byte length field */
652 *len_field_size_p = 1;
653 *len_field_val_p = tvb_get_guint8(tvb, offset);
655 /* and most have a 2 byte length field */
657 *len_field_size_p = 2;
658 *len_field_val_p = tds_tvb_get_xxtohs(tvb, offset, tds_little_endian);
661 return *len_field_val_p + *len_field_size_p + 1;
666 dissect_tds_query_packet(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree)
669 gboolean is_unicode = TRUE;
672 proto_item *query_hdr;
673 proto_tree *query_tree;
676 query_hdr = proto_tree_add_text(tree, tvb, offset, -1, "TDS Query Packet");
677 query_tree = proto_item_add_subtree(query_hdr, ett_tds7_query);
678 len = tvb_reported_length_remaining(tvb, offset);
680 if (TDS_PROTO_PREF_TDS4 ||
681 (!TDS_PROTO_PREF_TDS7_TDS8 &&
682 ((len < 2) || tvb_get_guint8(tvb, offset+1) != 0)))
686 msg = ep_tvb_fake_unicode(tvb, offset, len/2, TRUE);
688 msg = ep_tvb_get_string(tvb, offset, len);
690 proto_tree_add_text(query_tree, tvb, offset, len, "Query: %s", msg);
696 dissect_tds5_lang_token(tvbuff_t *tvb, guint offset, guint len, proto_tree *tree) {
697 gboolean is_unicode = FALSE;
700 proto_tree_add_text(tree, tvb, offset, 1 , "Status: %u", tvb_get_guint8(tvb, offset));
705 msg = ep_tvb_fake_unicode(tvb, offset, (len)/2, TRUE);
707 msg = ep_tvb_get_string(tvb, offset, len);
709 proto_tree_add_text(tree, tvb, offset, len, "Language text: %s", msg);
713 dissect_tds_query5_packet(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree)
717 guint token_len_field_size = 2;
718 guint token_len_field_val;
721 proto_item *query_hdr;
722 proto_tree *query_tree;
723 proto_item *token_item;
724 proto_tree *token_tree;
727 query_hdr = proto_tree_add_text(tree, tvb, offset, -1, "TDS5 Query Packet");
728 query_tree = proto_item_add_subtree(query_hdr, ett_tds7_query);
731 * Until we reach the end of the packet, read tokens.
734 while (tvb_reported_length_remaining(tvb, pos) > 0) {
737 token = tvb_get_guint8(tvb, pos);
738 if (tds_token_is_fixed_size(token))
739 token_sz = tds_get_fixed_token_size(token) + 1;
741 token_sz = tds_get_variable_token_size(tvb, pos+1, token, &token_len_field_size,
742 &token_len_field_val);
744 /* XXX - Should this check be done in tds_get_variable_token_size()
746 if ((int) token_sz < 0) {
747 proto_tree_add_text(tree, tvb, 0, 0, "Bogus token size: %u",
752 token_item = proto_tree_add_text(tree, tvb, pos, token_sz,
753 "Token 0x%02x %s", token,
754 val_to_str(token, token_names, "Unknown Token Type"));
755 token_tree = proto_item_add_subtree(token_item, ett_tds_token);
758 * If it's a variable token, put the length field in here
759 * instead of replicating this for each token subdissector.
761 if (!tds_token_is_fixed_size(token))
762 proto_tree_add_text(token_tree, tvb, pos+1, token_len_field_size, "Length: %u", token_len_field_val);
766 dissect_tds5_lang_token(tvb, pos + 5, token_sz -5, token_tree);
779 dissect_tds7_login(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
781 guint offset, i, offset2, len;
782 gboolean is_unicode = TRUE;
785 proto_item *login_hdr;
786 proto_tree *login_tree;
787 proto_item *header_hdr;
788 proto_tree *header_tree;
789 proto_item *length_hdr;
790 proto_tree *length_tree;
792 struct tds7_login_packet_hdr td7hdr;
793 gint length_remaining;
796 /* create display subtree for the protocol */
798 login_hdr = proto_tree_add_text(tree, tvb, offset, -1, "TDS7 Login Packet");
799 login_tree = proto_item_add_subtree(login_hdr, ett_tds7_login);
800 header_hdr = proto_tree_add_text(login_tree, tvb, offset, 36, "Login Packet Header");
801 header_tree = proto_item_add_subtree(header_hdr, ett_tds7_hdr);
803 td7hdr.total_packet_size = tvb_get_letohl(tvb, offset);
804 proto_tree_add_uint(header_tree, hf_tds7_login_total_size, tvb, offset,
805 sizeof(td7hdr.total_packet_size), td7hdr.total_packet_size);
806 offset += sizeof(td7hdr.total_packet_size);
808 td7hdr.tds_version = tvb_get_ntohl(tvb, offset);
809 proto_tree_add_uint(header_tree, hf_tds7_version, tvb, offset, sizeof(td7hdr.tds_version), td7hdr.tds_version);
810 offset += sizeof(td7hdr.tds_version);
812 td7hdr.packet_size = tvb_get_ntohl(tvb, offset);
813 proto_tree_add_uint(header_tree, hf_tds7_packet_size, tvb, offset, sizeof(td7hdr.packet_size), td7hdr.packet_size);
814 offset += sizeof(td7hdr.packet_size);
816 td7hdr.client_version = tvb_get_ntohl(tvb, offset);
817 proto_tree_add_uint(header_tree, hf_tds7_client_version, tvb, offset, sizeof(td7hdr.client_version), td7hdr.client_version);
818 offset += sizeof(td7hdr.client_version);
820 td7hdr.client_pid = tvb_get_letohl(tvb, offset);
821 proto_tree_add_uint(header_tree, hf_tds7_client_pid, tvb, offset, sizeof(td7hdr.client_pid), td7hdr.client_pid);
822 offset += sizeof(td7hdr.client_pid);
824 td7hdr.connection_id= tvb_get_letohl(tvb, offset);
825 proto_tree_add_uint(header_tree, hf_tds7_connection_id, tvb, offset, sizeof(td7hdr.connection_id), td7hdr.connection_id);
826 offset += sizeof(td7hdr.connection_id);
828 td7hdr.option_flags1 = tvb_get_guint8(tvb, offset);
829 proto_tree_add_uint(header_tree, hf_tds7_option_flags1, tvb, offset, sizeof(td7hdr.option_flags1), td7hdr.option_flags1);
830 offset += sizeof(td7hdr.option_flags1);
832 td7hdr.option_flags2 = tvb_get_guint8(tvb, offset);
833 proto_tree_add_uint(header_tree, hf_tds7_option_flags2, tvb, offset, sizeof(td7hdr.option_flags2), td7hdr.option_flags2);
834 offset += sizeof(td7hdr.option_flags2);
836 td7hdr.sql_type_flags = tvb_get_guint8(tvb, offset);
837 proto_tree_add_uint(header_tree, hf_tds7_sql_type_flags, tvb, offset, sizeof(td7hdr.sql_type_flags), td7hdr.sql_type_flags);
838 offset += sizeof(td7hdr.sql_type_flags);
840 td7hdr.reserved_flags = tvb_get_guint8(tvb, offset);
841 proto_tree_add_uint(header_tree, hf_tds7_reserved_flags, tvb, offset, sizeof(td7hdr.reserved_flags), td7hdr.reserved_flags);
842 offset += sizeof(td7hdr.reserved_flags);
844 td7hdr.time_zone = tvb_get_ntohl(tvb, offset);
845 proto_tree_add_uint(header_tree, hf_tds7_time_zone, tvb, offset, sizeof(td7hdr.time_zone), td7hdr.time_zone);
846 offset += sizeof(td7hdr.time_zone);
848 td7hdr.collation = tvb_get_ntohl(tvb, offset);
849 proto_tree_add_uint(header_tree, hf_tds7_collation, tvb, offset, sizeof(td7hdr.collation), td7hdr.collation);
850 offset += sizeof(td7hdr.collation);
852 length_hdr = proto_tree_add_text(login_tree, tvb, offset, 50, "Lengths and offsets");
853 length_tree = proto_item_add_subtree(length_hdr, ett_tds7_hdr);
855 for (i = 0; i < 9; i++) {
856 offset2 = tvb_get_letohs(tvb, offset + i*4);
857 len = tvb_get_letohs(tvb, offset + i*4 + 2);
858 proto_tree_add_text(length_tree, tvb, offset + i*4, 2,
860 val_to_str(i, login_field_names, "Unknown"),
862 proto_tree_add_text(length_tree, tvb, offset + i*4 + 2, 2,
864 val_to_str(i, login_field_names, "Unknown"),
868 if (is_unicode == TRUE) {
869 val = ep_tvb_fake_unicode(tvb, offset2, len, TRUE);
872 val = ep_tvb_get_string(tvb, offset2, len);
873 proto_tree_add_text(login_tree, tvb, offset2, len, "%s: %s", val_to_str(i, login_field_names, "Unknown"), val);
878 proto_tree_add_text(login_tree, tvb, offset2, len, "%s", val_to_str(i, login_field_names, "Unknown"));
884 * XXX - what about the client MAC address, etc.?
886 length_remaining = tvb_reported_length_remaining(tvb, offset2 + len);
887 if (length_remaining > 0) {
888 dissect_tds_nt(tvb, pinfo, login_tree, offset2 + len,
893 static int get_size_by_coltype(int servertype)
897 case SYBINT1: return 1; break;
898 case SYBINT2: return 2; break;
899 case SYBINT4: return 4; break;
900 case SYBINT8: return 8; break;
901 case SYBREAL: return 4; break;
902 case SYBFLT8: return 8; break;
903 case SYBDATETIME: return 8; break;
904 case SYBDATETIME4: return 4; break;
905 case SYBBIT: return 1; break;
906 case SYBBITN: return 1; break;
907 case SYBMONEY: return 8; break;
908 case SYBMONEY4: return 4; break;
909 case SYBUNIQUE: return 16; break;
910 default: return -1; break;
915 * data_to_string should take column data and turn it into something we can
916 * display on the tree.
918 static char *data_to_string(void *data, guint col_type, guint col_size)
920 static char result[256];
925 /* strncpy(result, (char *)data, col_size); */
926 for (i=0;i<col_size && i<(256-1);i++)
927 if (!isprint(((char *)data)[i])) result[i]='.';
928 else result[i]=((char *)data)[i];
932 sprintf(result, "%d", *(short *)data);
935 sprintf(result, "%d", *(int *)data);
938 sprintf(result, "Unexpected column_type %d", col_type);
946 * Since rows are special PDUs in that they are not fixed and lack a size field,
947 * the length must be computed using the column information seen in the result
948 * PDU. This function does just that.
951 tds_get_row_size(tvbuff_t *tvb, struct _netlib_data *nl_data, guint offset)
956 for (i = 0; i < nl_data->num_cols; i++) {
957 if (!is_fixed_coltype(nl_data->columns[i]->ctype)) {
958 csize = tvb_get_guint8(tvb, cur);
961 csize = get_size_by_coltype(nl_data->columns[i]->ctype);
965 return (cur - offset + 1);
969 * Process TDS 4 "COL_INFO" token and store relevant information in the
970 * _netlib_data structure for later use (see tds_get_row_size)
972 * XXX Can TDS 4 be "big-endian" ? we'll assume yes.
976 dissect_tds_col_info_token(tvbuff_t *tvb, struct _netlib_data *nl_data, guint offset)
981 next = offset + tds_tvb_get_xxtohs(tvb, offset+1, tds_little_endian) + 3;
987 if (col >= MAX_COLUMNS) {
988 nl_data->num_cols = 0;
992 nl_data->columns[col] = g_mem_chunk_alloc(tds_column);
994 nl_data->columns[col]->name[0] ='\0';
996 nl_data->columns[col]->utype = tds_tvb_get_xxtohs(tvb, cur, tds_little_endian);
999 cur += 2; /* unknown */
1001 nl_data->columns[col]->ctype = tvb_get_guint8(tvb,cur);
1004 if (!is_fixed_coltype(nl_data->columns[col]->ctype)) {
1005 nl_data->columns[col]->csize = tvb_get_guint8(tvb,cur);
1008 nl_data->columns[col]->csize =
1009 get_size_by_coltype(nl_data->columns[col]->ctype);
1016 nl_data->num_cols = col;
1022 * Read the results token and store the relevant information in the
1023 * _netlib_data structure for later use (see tds_get_row_size).
1025 * TODO: check we don't go past end of the token
1028 read_results_tds5(tvbuff_t *tvb, struct _netlib_data *nl_data, guint offset, guint len _U_)
1037 * This would be the logical place to check for little/big endianess
1038 * if we didn't see the login packet.
1039 * XXX: We'll take a hint
1041 nl_data->num_cols = tds_tvb_get_xxtohs(tvb, cur, tds_little_endian);
1042 if (nl_data->num_cols > MAX_COLUMNS) {
1043 nl_data->num_cols = 0;
1049 for (i = 0; i < nl_data->num_cols; i++) {
1050 nl_data->columns[i] = g_mem_chunk_alloc(tds_column);
1051 name_len = tvb_get_guint8(tvb,cur);
1055 cur++; /* unknown */
1057 nl_data->columns[i]->utype = tds_tvb_get_xxtohs(tvb, cur, tds_little_endian);
1060 cur += 2; /* unknown */
1062 nl_data->columns[i]->ctype = tvb_get_guint8(tvb,cur);
1065 if (!is_fixed_coltype(nl_data->columns[i]->ctype)) {
1066 nl_data->columns[i]->csize = tvb_get_guint8(tvb,cur);
1069 nl_data->columns[i]->csize =
1070 get_size_by_coltype(nl_data->columns[i]->ctype);
1072 cur++; /* unknown */
1078 * If the packet type from the netlib header is a login packet, then dig into
1079 * the packet to see if this is a supported TDS version and verify the otherwise
1080 * weak heuristics of the netlib check.
1083 netlib_check_login_pkt(tvbuff_t *tvb, guint offset, packet_info *pinfo, guint8 type)
1085 guint tds_major, bytes_avail;
1087 bytes_avail = tvb_length(tvb) - offset;
1089 * we have two login packet styles, one for TDS 4.2 and 5.0
1091 if (type==TDS_LOGIN_PKT) {
1092 /* Use major version number to validate TDS 4/5 login
1095 /* Login packet is first in stream and should not be fragmented...
1096 * if it is we are screwed */
1097 if (bytes_avail < 467) return FALSE;
1098 tds_major = tvb_get_guint8(tvb, 466);
1099 if (tds_major != 4 && tds_major != 5) {
1103 * and one added by Microsoft in SQL Server 7
1105 } else if (type==TDS_LOGIN7_PKT) {
1106 if (bytes_avail < 16) return FALSE;
1107 tds_major = tvb_get_guint8(tvb, 15);
1108 if (tds_major != 0x70 && tds_major != 0x80) {
1111 } else if (type==TDS_QUERY5_PKT) {
1112 if (bytes_avail < 9) return FALSE;
1113 /* if this is a TDS 5.0 query check the token */
1114 if (tvb_get_guint8(tvb, 8) != TDS_LANG_TOKEN) {
1119 * See if either tcp.destport or tcp.srcport is specified
1120 * in the preferences as being a TDS port.
1122 else if (!value_is_in_range(tds_tcp_ports, pinfo->srcport) &&
1123 !value_is_in_range(tds_tcp_ports, pinfo->destport)) {
1131 dissect_tds_env_chg(tvbuff_t *tvb, guint offset, guint token_sz,
1135 guint old_len, new_len, old_len_offset;
1136 char *new_val = NULL, *old_val = NULL;
1137 guint32 string_offset;
1138 gboolean is_unicode = FALSE;
1139 guint16 collate_codepage, collate_flags;
1140 guint8 collate_charset_id;
1142 env_type = tvb_get_guint8(tvb, offset);
1143 proto_tree_add_text(tree, tvb, offset, 1, "Type: %u (%s)", env_type,
1144 val_to_str(env_type, env_chg_names, "Unknown"));
1146 new_len = tvb_get_guint8(tvb, offset+1);
1147 old_len_offset = offset + new_len + 2;
1148 old_len = tvb_get_guint8(tvb, old_len_offset);
1151 * If our lengths plus the lengths of the type and the lengths
1152 * don't add up to the token size, it must be UCS2.
1154 if (old_len + new_len + 3 != token_sz) {
1156 old_len_offset = offset + (new_len * 2) + 2;
1157 old_len = tvb_get_guint8(tvb, old_len_offset);
1160 proto_tree_add_text(tree, tvb, offset + 1, 1, "New Value Length: %u",
1163 if (env_type != 7) { /* if it's not 'Collation Info - which is not textual! */
1164 string_offset = offset + 2;
1165 if (is_unicode == TRUE) {
1166 new_val = ep_tvb_fake_unicode(tvb, string_offset,
1170 new_val = ep_tvb_get_string(tvb, string_offset, new_len);
1171 proto_tree_add_text(tree, tvb, string_offset, new_len,
1172 "New Value: %s", new_val);
1174 else { /* parse collation info structure. From http://www.freetds.org/tds.html#collate */
1176 collate_codepage = tvb_get_letohs(tvb, offset);
1177 proto_tree_add_text(tree, tvb, offset, 2, "Codepage: %u" , collate_codepage);
1179 collate_flags = tvb_get_letohs(tvb, offset);
1180 proto_tree_add_text(tree, tvb, offset, 2, "Flags: 0x%x", collate_flags);
1182 collate_charset_id = tvb_get_guint8(tvb, offset);
1183 proto_tree_add_text(tree, tvb, offset, 1, "Charset ID: %u", collate_charset_id);
1188 proto_tree_add_text(tree, tvb, old_len_offset, 1, "Old Value Length: %u",
1191 string_offset = old_len_offset + 1;
1192 if (is_unicode == TRUE) {
1193 old_val = ep_tvb_fake_unicode(tvb, string_offset,
1197 old_val = ep_tvb_get_string(tvb, string_offset, old_len);
1198 proto_tree_add_text(tree, tvb, string_offset, old_len,
1199 "Old Value: %s", old_val);
1204 dissect_tds_err_token(tvbuff_t *tvb, guint offset, guint token_sz _U_, proto_tree *tree)
1207 guint8 srvr_len, proc_len;
1209 gboolean is_unicode = FALSE;
1211 proto_tree_add_text(tree, tvb, offset, 4, "SQL Error Number: %d", tds_tvb_get_xxtohl(tvb, offset, tds_little_endian));
1213 proto_tree_add_text(tree, tvb, offset, 1, "State: %u", tvb_get_guint8(tvb, offset));
1215 proto_tree_add_text(tree, tvb, offset, 1, "Severity Level: %u", tvb_get_guint8(tvb, offset));
1218 msg_len = tds_tvb_get_xxtohs(tvb, offset, tds_little_endian);
1219 proto_tree_add_text(tree, tvb, offset, 1, "Error message length: %u characters", msg_len);
1222 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 */
1226 msg = ep_tvb_fake_unicode(tvb, offset, msg_len, TRUE);
1229 msg = ep_tvb_get_string(tvb, offset, msg_len);
1231 proto_tree_add_text(tree, tvb, offset, msg_len, "Error: %s", format_text(msg, strlen(msg)));
1234 srvr_len = tvb_get_guint8(tvb, offset);
1236 proto_tree_add_text(tree, tvb, offset, 1, "Server name length: %u characters", srvr_len);
1240 msg = ep_tvb_fake_unicode(tvb, offset, srvr_len, TRUE);
1243 msg = ep_tvb_get_string(tvb, offset, srvr_len);
1245 proto_tree_add_text(tree, tvb, offset, srvr_len, "Server name: %s", msg);
1249 proc_len = tvb_get_guint8(tvb, offset);
1251 proto_tree_add_text(tree, tvb, offset, 1, "Process name length: %u characters", proc_len);
1255 msg = ep_tvb_fake_unicode(tvb, offset, proc_len, TRUE);
1258 msg = ep_tvb_get_string(tvb, offset, proc_len);
1260 proto_tree_add_text(tree, tvb, offset, proc_len, "Process name: %s", msg);
1264 proto_tree_add_text(tree, tvb, offset, 2, "line number: %d", tds_tvb_get_xxtohs(tvb, offset, tds_little_endian));
1268 dissect_tds_login_ack_token(tvbuff_t *tvb, guint offset, guint token_sz, proto_tree *tree)
1272 gboolean is_unicode = FALSE;
1274 proto_tree_add_text(tree, tvb, offset, 1, "Ack: %u", tvb_get_guint8(tvb, offset));
1276 proto_tree_add_text(tree, tvb, offset, 1, "Major version (may be incorrect): %d", tvb_get_guint8(tvb, offset));
1278 proto_tree_add_text(tree, tvb, offset, 1, "Minor version (may be incorrect): %d", tvb_get_guint8(tvb, offset));
1280 proto_tree_add_text(tree, tvb, offset, 2, "zero usually");
1283 msg_len = tvb_get_guint8(tvb, offset);
1284 proto_tree_add_text(tree, tvb, offset, 1, "Text length: %u characters", msg_len);
1287 if(msg_len + 6U + 3U != token_sz - 1) /* 6 is the length of ack(1), version (4), text length (1) fields */
1289 proto_tree_add_text(tree, tvb, offset, 0, "msg_len: %d, token_sz: %d, total: %d",msg_len, token_sz, msg_len + 6U + 3U);
1291 msg = ep_tvb_fake_unicode(tvb, offset, msg_len, TRUE);
1294 msg = ep_tvb_get_string(tvb, offset, msg_len);
1296 proto_tree_add_text(tree, tvb, offset, msg_len, "Text: %s", format_text(msg, strlen(msg)));
1299 proto_tree_add_text(tree, tvb, offset, 4, "Server Version");
1304 dissect_tds7_results_token(tvbuff_t *tvb, guint offset, proto_tree *tree)
1306 guint16 num_columns, table_len;
1307 guint8 type, msg_len;
1310 guint16 collate_codepage, collate_flags;
1311 guint8 collate_charset_id;
1313 num_columns = tvb_get_letohs(tvb, offset);
1314 proto_tree_add_text(tree, tvb, offset, 2, "Columns: %u", tvb_get_letohs(tvb, offset));
1316 for(i=0; i != num_columns; i++) {
1317 proto_tree_add_text(tree, tvb, offset, 0, "Column %d", i + 1);
1318 proto_tree_add_text(tree, tvb, offset, 2, "usertype: %d", tvb_get_letohs(tvb, offset));
1320 proto_tree_add_text(tree, tvb, offset, 2, "flags: %d", tvb_get_letohs(tvb, offset));
1322 type = tvb_get_guint8(tvb, offset);
1323 proto_tree_add_text(tree, tvb, offset, 1, "Type: %d", type);
1325 if(type == 38 || type == 104) { /* ugly, ugly hack. Wish I knew what it really means!*/
1326 proto_tree_add_text(tree, tvb, offset, 1, "unknown 1 byte (%x)", tvb_get_guint8(tvb, offset));
1329 else if (type == 35) {
1330 proto_tree_add_text(tree, tvb, offset, 4, "unknown 4 bytes (%x)", tvb_get_letohl(tvb, offset));
1332 collate_codepage = tvb_get_letohs(tvb, offset);
1333 proto_tree_add_text(tree, tvb, offset, 2, "Codepage: %u" , collate_codepage);
1335 collate_flags = tvb_get_letohs(tvb, offset);
1336 proto_tree_add_text(tree, tvb, offset, 2, "Flags: 0x%x", collate_flags);
1338 collate_charset_id = tvb_get_guint8(tvb, offset);
1339 proto_tree_add_text(tree, tvb, offset, 1, "Charset ID: %u", collate_charset_id);
1341 table_len = tvb_get_letohs(tvb, offset);
1343 if(table_len != 0) {
1344 msg = ep_tvb_fake_unicode(tvb, offset, table_len, TRUE);
1345 proto_tree_add_text(tree, tvb, offset, table_len*2, "Table name: %s", msg);
1346 offset += table_len*2;
1349 else if (type == 106) {
1350 proto_tree_add_text(tree, tvb, offset, 3, "unknown 3 bytes");
1354 proto_tree_add_text(tree, tvb, offset, 2, "Large type size: 0x%x", tvb_get_letohs(tvb, offset));
1356 collate_codepage = tvb_get_letohs(tvb, offset);
1357 proto_tree_add_text(tree, tvb, offset, 2, "Codepage: %u" , collate_codepage);
1359 collate_flags = tvb_get_letohs(tvb, offset);
1360 proto_tree_add_text(tree, tvb, offset, 2, "Flags: 0x%x", collate_flags);
1362 collate_charset_id = tvb_get_guint8(tvb, offset);
1363 proto_tree_add_text(tree, tvb, offset, 1, "Charset ID: %u", collate_charset_id);
1366 msg_len = tvb_get_guint8(tvb, offset);
1367 proto_tree_add_text(tree, tvb, offset, 1, "message length: %d",msg_len);
1370 msg = ep_tvb_fake_unicode(tvb, offset, msg_len, TRUE);
1371 proto_tree_add_text(tree, tvb, offset, msg_len*2, "Text: %s", msg);
1372 offset += msg_len*2;
1379 dissect_tds_done_token(tvbuff_t *tvb, guint offset, proto_tree *tree)
1381 proto_tree_add_text(tree, tvb, offset, 2, "Status flags");
1383 proto_tree_add_text(tree, tvb, offset, 2, "Operation");
1385 proto_tree_add_text(tree, tvb, offset, 4, "row count: %u", tds_tvb_get_xxtohl(tvb, offset, tds_little_endian));
1390 dissect_tds_rpc(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree)
1400 switch(tds_protocol_type) {
1401 case TDS_PROTOCOL_4:
1402 len = tvb_get_guint8(tvb, offset);
1403 proto_tree_add_text(tree, tvb, offset, 1, "RPC Name Length: %u", len);
1405 val = ep_tvb_get_string(tvb, offset, len);
1406 proto_tree_add_text(tree, tvb, offset, len, "RPC Name: %s", val);
1410 case TDS_PROTOCOL_7:
1411 case TDS_PROTOCOL_8:
1412 default: /* unspecified: try as if TDS7/TDS8 */
1413 len = tvb_get_letohs(tvb, offset);
1414 proto_tree_add_text(tree, tvb, offset, 2, "RPC Name Length: %u", len);
1416 if (len == 0xFFFF) {
1417 sp_id = tvb_get_letohs(tvb, offset);
1418 proto_tree_add_text(tree, tvb, offset, 2, "RPC Stored Proc ID: %u (%s)",
1420 val_to_str(sp_id, internal_stored_proc_id_names, "Unknown"));
1423 else if (len != 0) {
1424 val = ep_tvb_fake_unicode(tvb, offset, len, TRUE);
1426 proto_tree_add_text(tree, tvb, offset, len, "RPC Name: %s", val);
1431 proto_tree_add_text(tree, tvb, offset, -1, "Params (not dissected)");
1435 dissect_tds_resp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1438 proto_item *token_item;
1439 proto_tree *token_tree;
1440 guint pos, token_sz = 0;
1441 guint token_len_field_size = 2;
1442 guint token_len_field_val;
1444 struct _netlib_data nl_data;
1445 gint length_remaining;
1447 g_mem_chunk_reset(tds_column); /* in case exception thrown the previous time thru this code */
1449 memset(&nl_data, '\0', sizeof nl_data);
1452 * Until we reach the end of the packet, read tokens.
1455 while (tvb_reported_length_remaining(tvb, pos) > 0) {
1457 token = tvb_get_guint8(tvb, pos);
1459 /* TODO Handle TDS_PARAMFMT, TDS_PARAMS [similar to TDS_RESULTS, TDS_ROW] */
1460 if (tds_token_is_fixed_size(token)) {
1461 token_sz = tds_get_fixed_token_size(token) + 1;
1462 } else if (token == TDS_ROW_TOKEN) {
1464 * Rows are special; they have no size field and
1465 * aren't fixed length.
1467 token_sz = tds_get_row_size(tvb, &nl_data, pos + 1);
1469 token_sz = tds_get_variable_token_size(tvb, pos + 1,
1470 token, &token_len_field_size, &token_len_field_val);
1472 length_remaining = tvb_ensure_length_remaining(tvb, pos);
1474 if ((int) token_sz < 0) {
1475 proto_tree_add_text(tree, tvb, pos, 0, "Bogus token size: %u",
1479 if ((int) token_len_field_size < 0) {
1480 proto_tree_add_text(tree, tvb, pos, 0, "Bogus token length field size: %u",
1481 token_len_field_size);
1484 token_item = proto_tree_add_text(tree, tvb, pos, token_sz,
1485 "Token 0x%02x %s", token,
1486 val_to_str(token, token_names, "Unknown Token Type"));
1487 token_tree = proto_item_add_subtree(token_item, ett_tds_token);
1490 * If it's a variable token, put the length field in here
1491 * instead of replicating this for each token subdissector.
1493 if (!tds_token_is_fixed_size(token) && token != TDS_ROW_TOKEN) {
1494 proto_tree_add_text(token_tree, tvb, pos + 1,
1495 token_len_field_size, "Length: %u",
1496 token_len_field_val);
1499 if (token_sz > (guint)length_remaining)
1500 token_sz = (guint)length_remaining;
1504 case TDS_COL_NAME_TOKEN:
1507 * TODO dissect token to get "column names" to fill in _netlib_data
1511 case TDS_COL_INFO_TOKEN:
1513 * TDS 4.2: get the column info
1515 dissect_tds_col_info_token(tvb, &nl_data, pos);
1518 case TDS_RESULT_TOKEN:
1520 * If it's a result token, we need to stash the
1523 read_results_tds5(tvb, &nl_data, pos + 3, token_sz - 3);
1526 case TDS_ENV_CHG_TOKEN:
1527 dissect_tds_env_chg(tvb, pos + 3, token_sz - 3, token_tree);
1530 case TDS_AUTH_TOKEN:
1531 dissect_tds_nt(tvb, pinfo, token_tree, pos + 3, token_sz - 3);
1535 dissect_tds_err_token(tvb, pos + 3, token_sz - 3, token_tree);
1538 case TDS_DONE_TOKEN:
1539 case TDS_DONEPROC_TOKEN:
1540 case TDS_DONEINPROC_TOKEN:
1541 dissect_tds_done_token(tvb, pos + 1, token_tree);
1543 case TDS_LOGIN_ACK_TOKEN:
1544 dissect_tds_login_ack_token(tvb, pos + 3, token_sz - 3, token_tree);
1546 case TDS7_RESULT_TOKEN:
1547 pos = (dissect_tds7_results_token(tvb, pos + 1, token_tree)-1);
1551 /* and step to the end of the token, rinse, lather, repeat */
1554 /* reset tds_column mem_chunk since finished processing response */
1555 /* (pointers to atoms in nl_data being discarded) */
1556 g_mem_chunk_reset(tds_column);
1560 dissect_netlib_buffer(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1563 proto_item *tds_item = NULL;
1564 proto_tree *tds_tree = NULL;
1569 guint8 packet_number;
1570 gboolean save_fragmented;
1572 fragment_data *fd_head;
1576 /* create display subtree for the protocol */
1577 tds_item = proto_tree_add_item(tree, proto_tds, tvb, offset, -1,
1580 tds_tree = proto_item_add_subtree(tds_item, ett_tds);
1582 type = tvb_get_guint8(tvb, offset);
1584 proto_tree_add_uint(tds_tree, hf_tds_type, tvb, offset, 1,
1587 status = tvb_get_guint8(tvb, offset + 1);
1589 proto_tree_add_uint(tds_tree, hf_tds_status, tvb, offset + 1, 1,
1592 size = tvb_get_ntohs(tvb, offset + 2);
1594 proto_tree_add_uint(tds_tree, hf_tds_size, tvb, offset + 2, 2,
1597 channel = tvb_get_ntohs(tvb, offset + 4);
1599 proto_tree_add_uint(tds_tree, hf_tds_channel, tvb, offset + 4, 2,
1602 packet_number = tvb_get_guint8(tvb, offset + 6);
1604 proto_tree_add_uint(tds_tree, hf_tds_packet_number, tvb, offset + 6, 1,
1606 proto_tree_add_item(tds_tree, hf_tds_window, tvb, offset + 7, 1,
1609 offset += 8; /* skip Netlib header */
1612 * Deal with fragmentation.
1614 * TODO: handle case where netlib headers 'packet-number'.is always 0
1615 * use fragment_add_seq_next in this case ?
1618 save_fragmented = pinfo->fragmented;
1619 if (tds_defragment &&
1620 (packet_number > 1 || status == STATUS_NOT_LAST_BUFFER)) {
1621 if (status == STATUS_NOT_LAST_BUFFER) {
1622 if (check_col(pinfo->cinfo, COL_INFO))
1623 col_append_str(pinfo->cinfo, COL_INFO,
1624 " (Not last buffer)");
1626 len = tvb_reported_length_remaining(tvb, offset);
1628 * XXX - I've seen captures that start with a login
1629 * packet with a sequence number of 2.
1631 fd_head = fragment_add_seq_check(tvb, offset, pinfo, channel,
1632 tds_fragment_table, tds_reassembled_table,
1633 packet_number - 1, len, status == STATUS_NOT_LAST_BUFFER);
1634 next_tvb = process_reassembled_data(tvb, offset, pinfo,
1635 "Reassembled TDS", fd_head, &tds_frag_items, NULL,
1639 * If this isn't the last buffer, just show it as a fragment.
1640 * (XXX - it'd be nice to dissect it if it's the first
1641 * buffer, but we'd need to do reassembly in order to
1644 * If this is the last buffer, dissect it.
1645 * (XXX - it'd be nice to show it as a fragment if it's part
1646 * of a fragmented message, but we'd need to do reassembly
1647 * in order to discover that.)
1649 if (status == STATUS_NOT_LAST_BUFFER)
1652 next_tvb = tvb_new_subset(tvb, offset, -1, -1);
1656 if (next_tvb != NULL) {
1661 dissect_tds_rpc(next_tvb, pinfo, tds_tree);
1665 dissect_tds_resp(next_tvb, pinfo, tds_tree);
1668 case TDS_LOGIN7_PKT:
1669 dissect_tds7_login(next_tvb, pinfo, tds_tree);
1672 dissect_tds_query_packet(next_tvb, pinfo, tds_tree);
1674 case TDS_QUERY5_PKT:
1675 dissect_tds_query5_packet(next_tvb, pinfo, tds_tree);
1677 case TDS_NTLMAUTH_PKT:
1678 dissect_tds_nt(next_tvb, pinfo, tds_tree, offset - 8, -1);
1681 proto_tree_add_text(tds_tree, next_tvb, 0, -1,
1686 next_tvb = tvb_new_subset (tvb, offset, -1, -1);
1687 call_dissector(data_handle, next_tvb, pinfo, tds_tree);
1692 dissect_tds_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1694 volatile gboolean first_time = TRUE;
1695 volatile int offset = 0;
1696 guint length_remaining;
1701 proto_item *tds_item = NULL;
1702 proto_tree *tds_tree = NULL;
1704 while (tvb_reported_length_remaining(tvb, offset) != 0) {
1705 length_remaining = tvb_ensure_length_remaining(tvb, offset);
1708 * Can we do reassembly?
1710 if (tds_desegment && pinfo->can_desegment) {
1712 * Yes - is the fixed-length part of the PDU
1713 * split across segment boundaries?
1715 if (length_remaining < 8) {
1717 * Yes. Tell the TCP dissector where the
1718 * data for this message starts in the data
1719 * it handed us, and how many more bytes we
1722 pinfo->desegment_offset = offset;
1723 pinfo->desegment_len = 8 - length_remaining;
1728 type = tvb_get_guint8(tvb, offset);
1731 * Get the length of the PDU.
1733 plen = tvb_get_ntohs(tvb, offset + 2);
1736 * The length is less than the header length.
1737 * Put in the type, status, and length, and
1738 * report the length as bogus.
1741 /* create display subtree for the protocol */
1742 tds_item = proto_tree_add_item(tree, proto_tds,
1743 tvb, offset, -1, FALSE);
1745 tds_tree = proto_item_add_subtree(tds_item,
1747 proto_tree_add_uint(tds_tree, hf_tds_type, tvb,
1749 proto_tree_add_item(tds_tree, hf_tds_status,
1750 tvb, offset + 1, 1, FALSE);
1751 proto_tree_add_uint_format(tds_tree,
1752 hf_tds_size, tvb, offset + 2, 2, plen,
1753 "Size: %u (bogus, should be >= 8)", plen);
1757 * Give up - we can't dissect any more of this
1764 * Can we do reassembly?
1766 if (tds_desegment && pinfo->can_desegment) {
1768 * Yes - is the PDU split across segment boundaries?
1770 if (length_remaining < plen) {
1772 * Yes. Tell the TCP dissector where the
1773 * data for this message starts in the data
1774 * it handed us, and how many more bytes we
1777 pinfo->desegment_offset = offset;
1778 pinfo->desegment_len = plen - length_remaining;
1784 if (check_col(pinfo->cinfo, COL_PROTOCOL))
1785 col_set_str(pinfo->cinfo, COL_PROTOCOL, "TDS");
1788 * Set the packet description based on its TDS packet
1791 if (check_col(pinfo->cinfo, COL_INFO)) {
1792 col_add_str(pinfo->cinfo, COL_INFO,
1793 val_to_str(type, packet_type_names,
1794 "Unknown Packet Type: %u"));
1800 * Construct a tvbuff containing the amount of the payload
1801 * we have available. Make its reported length the amount
1802 * of data in the PDU.
1804 * XXX - if reassembly isn't enabled. the subdissector will
1805 * throw a BoundsError exception, rather than a
1806 * ReportedBoundsError exception. We really want a tvbuff
1807 * where the length is "length", the reported length is
1808 * "plen", and the "if the snapshot length were infinite"
1809 * length is the minimum of the reported length of the tvbuff
1810 * handed to us and "plen", with a new type of exception
1811 * thrown if the offset is within the reported length but
1812 * beyond that third length, with that exception getting the
1813 * "Unreassembled Packet" error.
1815 length = length_remaining;
1818 next_tvb = tvb_new_subset(tvb, offset, length, plen);
1821 * Dissect the Netlib buffer.
1823 * Catch the ReportedBoundsError exception; if this
1824 * particular Netlib buffer happens to get a
1825 * ReportedBoundsError exception, that doesn't mean
1826 * that we should stop dissecting PDUs within this frame
1827 * or chunk of reassembled data.
1829 * If it gets a BoundsError, we can stop, as there's nothing
1830 * more to see, so we just re-throw it.
1833 dissect_netlib_buffer(next_tvb, pinfo, tree);
1835 CATCH(BoundsError) {
1838 CATCH(ReportedBoundsError) {
1839 show_reported_bounds_error(tvb, pinfo, tree);
1844 * Step to the next Netlib buffer.
1851 dissect_tds_tcp_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1857 conversation_t *conv;
1860 * If we don't have even enough data for a Netlib header,
1861 * just say it's not TDS.
1863 if (!tvb_bytes_exist(tvb, offset, 8))
1867 * Quickly scan all the data we have in order to see if
1868 * everything in it looks like Netlib traffic.
1870 while (tvb_bytes_exist(tvb, offset, 1)) {
1872 * Check the type field.
1874 type = tvb_get_guint8(tvb, offset);
1875 if (!is_valid_tds_type(type))
1879 * Check the status field, if it's present.
1881 if (!tvb_bytes_exist(tvb, offset + 1, 1))
1883 status = tvb_get_guint8(tvb, offset + 1);
1884 if (!is_valid_tds_status(status))
1888 * Get the length of the PDU.
1890 if (!tvb_bytes_exist(tvb, offset + 2, 2))
1892 plen = tvb_get_ntohs(tvb, offset + 2);
1895 * The length is less than the header length.
1902 * If we're at the beginning of the segment, check the
1903 * payload if it's a login packet.
1906 if (!netlib_check_login_pkt(tvb, offset, pinfo, type))
1911 * Step to the next Netlib buffer.
1917 * OK, it passes the test; assume the rest of this conversation
1920 conv = find_conversation(pinfo->fd->num, &pinfo->src, &pinfo->dst, pinfo->ptype,
1921 pinfo->srcport, pinfo->destport, 0);
1924 * No conversation exists yet - create one.
1926 conv = conversation_new(pinfo->fd->num, &pinfo->src, &pinfo->dst,
1927 pinfo->ptype, pinfo->srcport, pinfo->destport, 0);
1929 conversation_set_dissector(conv, tds_tcp_handle);
1932 * Now dissect it as TDS.
1934 dissect_tds_tcp(tvb, pinfo, tree);
1942 * Initialize the fragment and reassembly tables.
1944 fragment_table_init(&tds_fragment_table);
1945 reassembled_table_init(&tds_reassembled_table);
1948 * Reinitialize the chunks of data for remembering row
1952 g_mem_chunk_destroy(tds_column);
1954 tds_column = g_mem_chunk_new("tds_column", tds_column_length,
1955 tds_column_init_count * tds_column_length,
1959 /* Register the protocol with Ethereal */
1961 /* this format is required because a script is used to build the C function
1962 that calls all the protocol registration.
1966 proto_register_netlib(void)
1968 static hf_register_info hf[] = {
1970 { "Type", "tds.type",
1971 FT_UINT8, BASE_HEX, VALS(packet_type_names), 0x0,
1972 "Packet Type", HFILL }
1975 { "Status", "tds.status",
1976 FT_UINT8, BASE_DEC, VALS(status_names), 0x0,
1977 "Frame status", HFILL }
1980 { "Size", "tds.size",
1981 FT_UINT16, BASE_DEC, NULL, 0x0,
1982 "Packet Size", HFILL }
1985 { "Channel", "tds.channel",
1986 FT_UINT16, BASE_DEC, NULL, 0x0,
1987 "Channel Number", HFILL }
1989 { &hf_tds_packet_number,
1990 { "Packet Number", "tds.packet_number",
1991 FT_UINT8, BASE_DEC, NULL, 0x0,
1992 "Packet Number", HFILL }
1995 { "Window", "tds.window",
1996 FT_UINT8, BASE_DEC, NULL, 0x0,
1999 { &hf_tds_fragment_overlap,
2000 { "Segment overlap", "tds.fragment.overlap",
2001 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
2002 "Fragment overlaps with other fragments", HFILL }
2004 { &hf_tds_fragment_overlap_conflict,
2005 { "Conflicting data in fragment overlap", "tds.fragment.overlap.conflict",
2006 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
2007 "Overlapping fragments contained conflicting data", HFILL }
2009 { &hf_tds_fragment_multiple_tails,
2010 { "Multiple tail fragments found", "tds.fragment.multipletails",
2011 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
2012 "Several tails were found when defragmenting the packet", HFILL }
2014 { &hf_tds_fragment_too_long_fragment,
2015 { "Segment too long", "tds.fragment.toolongfragment",
2016 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
2017 "Segment contained data past end of packet", HFILL }
2019 { &hf_tds_fragment_error,
2020 { "Defragmentation error", "tds.fragment.error",
2021 FT_FRAMENUM, BASE_NONE, NULL, 0x0,
2022 "Defragmentation error due to illegal fragments", HFILL }
2025 { "TDS Fragment", "tds.fragment",
2026 FT_FRAMENUM, BASE_NONE, NULL, 0x0,
2027 "TDS Fragment", HFILL }
2029 { &hf_tds_fragments,
2030 { "TDS Fragments", "tds.fragments",
2031 FT_NONE, BASE_NONE, NULL, 0x0,
2032 "TDS Fragments", HFILL }
2034 { &hf_tds_reassembled_in,
2035 { "Reassembled TDS in frame", "tds.reassembled_in",
2036 FT_FRAMENUM, BASE_NONE, NULL, 0x0,
2037 "This TDS packet is reassembled in this frame", HFILL }
2039 { &hf_tds7_login_total_size,
2040 { "Total Packet Length", "tds7login.total_len",
2041 FT_UINT32, BASE_DEC, NULL, 0x0,
2042 "TDS7 Login Packet total packet length", HFILL }
2045 { "TDS version", "tds7login.version",
2046 FT_UINT32, BASE_HEX, NULL, 0x0,
2047 "TDS version", HFILL }
2049 { &hf_tds7_packet_size,
2050 { "Packet Size", "tds7login.packet_size",
2051 FT_UINT32, BASE_DEC, NULL, 0x0,
2052 "Packet size", HFILL }
2054 { &hf_tds7_client_version,
2055 { "Client version", "tds7login.client_version",
2056 FT_UINT32, BASE_DEC, NULL, 0x0,
2057 "Client version", HFILL }
2059 { &hf_tds7_client_pid,
2060 { "Client PID", "tds7login.client_pid",
2061 FT_UINT32, BASE_DEC, NULL, 0x0,
2062 "Client PID", HFILL }
2064 { &hf_tds7_connection_id,
2065 { "Connection ID", "tds7login.connection_id",
2066 FT_UINT32, BASE_DEC, NULL, 0x0,
2067 "Connection ID", HFILL }
2069 { &hf_tds7_option_flags1,
2070 { "Option Flags 1", "tds7login.option_flags1",
2071 FT_UINT8, BASE_HEX, NULL, 0x0,
2072 "Option Flags 1", HFILL }
2074 { &hf_tds7_option_flags2,
2075 { "Option Flags 2", "tds7login.option_flags2",
2076 FT_UINT8, BASE_HEX, NULL, 0x0,
2077 "Option Flags 2", HFILL }
2079 { &hf_tds7_sql_type_flags,
2080 { "SQL Type Flags", "tds7login.sql_type_flags",
2081 FT_UINT8, BASE_HEX, NULL, 0x0,
2082 "SQL Type Flags", HFILL }
2084 { &hf_tds7_reserved_flags,
2085 { "Reserved Flags", "tds7login.reserved_flags",
2086 FT_UINT8, BASE_HEX, NULL, 0x0,
2087 "reserved flags", HFILL }
2089 { &hf_tds7_time_zone,
2090 { "Time Zone", "tds7login.time_zone",
2091 FT_UINT32, BASE_HEX, NULL, 0x0,
2092 "Time Zone", HFILL }
2094 { &hf_tds7_collation,
2095 { "Collation", "tds7login.collation",
2096 FT_UINT32, BASE_HEX, NULL, 0x0,
2097 "Collation", HFILL }
2100 { "Message", "tds7.message",
2101 FT_STRING, BASE_NONE, NULL, 0x0,
2106 static gint *ett[] = {
2114 module_t *tds_module;
2116 /* Register the protocol name and description */
2117 proto_tds = proto_register_protocol("Tabular Data Stream",
2120 /* Required function calls to register the header fields and subtrees used */
2121 proto_register_field_array(proto_tds, hf, array_length(hf));
2122 proto_register_subtree_array(ett, array_length(ett));
2124 tds_module = prefs_register_protocol(proto_tds, NULL);
2125 prefs_register_bool_preference(tds_module, "desegment_buffers",
2126 "Reassemble TDS buffers spanning multiple TCP segments",
2127 "Whether the TDS dissector should reassemble TDS buffers spanning multiple TCP segments. "
2128 "To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.",
2130 prefs_register_bool_preference(tds_module, "defragment",
2131 "Reassemble fragmented TDS messages with multiple buffers",
2132 "Whether the TDS dissector should defragment messages spanning multiple Netlib buffers",
2134 prefs_register_enum_preference(tds_module, "protocol_type",
2135 "TDS Protocol Type",
2136 "Hint as to version of TDS protocol being decoded",
2137 &tds_protocol_type, tds_protocol_type_options, FALSE);
2138 prefs_register_enum_preference(tds_module, "endian_type",
2140 "Hint as to whether to decode TDS protocol as little-endian or big-endian. (TDS7/8 always decoded as little-endian)",
2141 &tds_little_endian, tds_endian_type_options, FALSE);
2142 prefs_register_range_preference(tds_module, "tcp_ports",
2144 "Additional TCP ports to decode as TDS",
2145 &tds_tcp_ports, 0xFFFF);
2147 register_init_routine(tds_init);
2150 /* If this dissector uses sub-dissector registration add a registration routine.
2151 This format is required because a script is used to find these routines and
2152 create the code that calls these routines.
2155 proto_reg_handoff_tds(void)
2157 tds_tcp_handle = create_dissector_handle(dissect_tds_tcp, proto_tds);
2159 /* Initial TDS ports: MS SQL default ports */
2160 dissector_add("tcp.port", 1433, tds_tcp_handle);
2161 dissector_add("tcp.port", 2433, tds_tcp_handle);
2163 heur_dissector_add("tcp", dissect_tds_tcp_heur, proto_tds);
2165 ntlmssp_handle = find_dissector("ntlmssp");
2166 gssapi_handle = find_dissector("gssapi");
2167 data_handle = find_dissector("data");