2000-02-14 04:05:53 +00:00
|
|
|
/* packet-smb-common.c
|
2000-02-14 04:02:21 +00:00
|
|
|
* Common routines for smb packet dissection
|
|
|
|
* Copyright 2000, Jeffrey C. Foster <jfoste@woodward.com>
|
|
|
|
*
|
2002-06-16 00:39:30 +00:00
|
|
|
* $Id: packet-smb-common.c,v 1.12 2002/06/16 00:39:30 guy Exp $
|
2000-02-14 04:02:21 +00:00
|
|
|
*
|
|
|
|
* Ethereal - Network traffic analyzer
|
2001-07-08 11:32:02 +00:00
|
|
|
* By Gerald Combs <gerald@ethereal.com>
|
2000-02-14 04:02:21 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
|
|
|
* Copied from packet-pop.c
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "packet-smb-common.h"
|
|
|
|
|
2002-05-24 10:57:38 +00:00
|
|
|
/*
|
|
|
|
* Share type values - used in LANMAN and in SRVSVC.
|
2002-06-16 00:39:30 +00:00
|
|
|
*
|
|
|
|
* XXX - should we dissect share type values, at least in SRVSVC, as
|
|
|
|
* a subtree with bitfields, as the 0x80000000 bit appears to be a
|
|
|
|
* hidden bit, with some number of bits at the bottom being the share
|
|
|
|
* type?
|
|
|
|
*
|
|
|
|
* Does LANMAN use that bit?
|
2002-05-24 10:57:38 +00:00
|
|
|
*/
|
|
|
|
const value_string share_type_vals[] = {
|
|
|
|
{0, "Directory tree"},
|
|
|
|
{1, "Printer queue"},
|
|
|
|
{2, "Communications device"},
|
|
|
|
{3, "IPC"},
|
2002-05-27 04:11:06 +00:00
|
|
|
{0x80000000, "Hidden Directory tree"},
|
|
|
|
{0x80000001, "Hidden Printer queue"},
|
|
|
|
{0x80000002, "Hidden Communications device"},
|
|
|
|
{0x80000003, "Hidden IPC"},
|
2002-05-24 10:57:38 +00:00
|
|
|
{0, NULL}
|
|
|
|
};
|
|
|
|
|
2002-04-30 11:03:08 +00:00
|
|
|
int display_ms_string(tvbuff_t *tvb, proto_tree *tree, int offset, int hf_index)
|
2001-07-08 11:32:02 +00:00
|
|
|
{
|
2001-07-08 20:38:26 +00:00
|
|
|
char *str;
|
2001-07-08 11:32:02 +00:00
|
|
|
int len;
|
2000-02-14 04:02:21 +00:00
|
|
|
|
2001-07-08 11:32:02 +00:00
|
|
|
/* display a string from the tree and return the new offset */
|
2000-02-14 04:02:21 +00:00
|
|
|
|
2001-07-08 19:26:33 +00:00
|
|
|
len = tvb_strnlen(tvb, offset, -1);
|
|
|
|
if (len == -1) {
|
|
|
|
/*
|
|
|
|
* XXX - throw an exception?
|
|
|
|
*/
|
|
|
|
len = tvb_length_remaining(tvb, offset);
|
|
|
|
}
|
|
|
|
str = g_malloc(len+1);
|
|
|
|
tvb_memcpy(tvb, (guint8 *)str, offset, len);
|
|
|
|
str[len] = '\0';
|
2000-02-14 04:02:21 +00:00
|
|
|
|
2001-07-08 19:26:33 +00:00
|
|
|
proto_tree_add_string(tree, hf_index, tvb, offset, len+1, str);
|
2000-02-14 04:02:21 +00:00
|
|
|
|
2001-07-08 19:26:33 +00:00
|
|
|
/*
|
|
|
|
* XXX - "proto_tree_add_string()" mallocates a copy; it'd
|
|
|
|
* be nice not to have it copy the string, but just to
|
|
|
|
* make it the value, avoiding both the copy and the free
|
|
|
|
* on the next line.
|
|
|
|
*/
|
|
|
|
g_free(str);
|
|
|
|
|
2001-07-08 11:32:02 +00:00
|
|
|
return offset+len+1;
|
2000-02-14 04:02:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-04-30 11:03:08 +00:00
|
|
|
int display_unicode_string(tvbuff_t *tvb, proto_tree *tree, int offset, int hf_index)
|
2001-07-08 11:32:02 +00:00
|
|
|
{
|
2002-06-16 00:39:30 +00:00
|
|
|
char *str, *p;
|
|
|
|
int len;
|
|
|
|
int charoffset;
|
|
|
|
guint16 character;
|
|
|
|
|
2001-07-08 11:32:02 +00:00
|
|
|
/* display a unicode string from the tree and return new offset */
|
2000-02-14 04:02:21 +00:00
|
|
|
|
2002-06-16 00:39:30 +00:00
|
|
|
/*
|
|
|
|
* Get the length of the string.
|
|
|
|
* XXX - is it a bug or a feature that this will throw an exception
|
|
|
|
* if we don't find the '\0'? I think it's a feature.
|
|
|
|
*/
|
|
|
|
len = 0;
|
|
|
|
while ((character = tvb_get_letohs(tvb, offset + len)) != '\0')
|
|
|
|
len += 2;
|
|
|
|
len += 2; /* count the '\0' too */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate a buffer for the string; "len" is the length in
|
|
|
|
* bytes, not the length in characters.
|
|
|
|
*/
|
|
|
|
str = g_malloc(len/2);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX - this assumes the string is just ISO 8859-1; we need
|
|
|
|
* to better handle multiple character sets in Ethereal,
|
|
|
|
* including Unicode/ISO 10646, and multiple encodings of
|
|
|
|
* that character set (UCS-2, UTF-8, etc.).
|
|
|
|
*/
|
|
|
|
charoffset = offset;
|
|
|
|
p = str;
|
|
|
|
while ((character = tvb_get_letohs(tvb, charoffset)) != '\0') {
|
|
|
|
*p++ = character;
|
|
|
|
charoffset += 2;
|
|
|
|
}
|
|
|
|
*p = '\0';
|
2000-02-14 04:02:21 +00:00
|
|
|
|
2002-06-16 00:39:30 +00:00
|
|
|
proto_tree_add_string(tree, hf_index, tvb, offset, len, str);
|
|
|
|
|
|
|
|
g_free(str);
|
2000-02-14 04:02:21 +00:00
|
|
|
|
2002-06-16 00:39:30 +00:00
|
|
|
return offset+len;
|
2000-02-14 04:02:21 +00:00
|
|
|
}
|
|
|
|
|
2001-07-08 11:32:02 +00:00
|
|
|
int
|
2002-04-30 11:03:08 +00:00
|
|
|
dissect_smb_unknown(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int offset)
|
2001-07-08 11:32:02 +00:00
|
|
|
{
|
|
|
|
/* display data as unknown */
|
2000-02-14 04:02:21 +00:00
|
|
|
|
2002-01-24 09:20:54 +00:00
|
|
|
proto_tree_add_text(tree, tvb, offset, -1, "Data (%u bytes)",
|
|
|
|
tvb_reported_length_remaining(tvb, offset));
|
2000-02-14 04:02:21 +00:00
|
|
|
|
2002-01-24 09:20:54 +00:00
|
|
|
return offset+tvb_length_remaining(tvb, offset);
|
2000-02-14 04:02:21 +00:00
|
|
|
}
|