aboutsummaryrefslogtreecommitdiffstats
path: root/packet-smb-mailslot.c
blob: a6c8cf2a74d15b272e0b4ccbf5c95323101c00ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/* packet-smb-mailslot.c
 * Routines for SMB mailslot packet dissection
 * Copyright 2000, Jeffrey C. Foster <jfoste@woodward.com>
 *
 * $Id: packet-smb-mailslot.c,v 1.16 2001/08/07 08:39:56 guy Exp $
 *
 * Ethereal - Network traffic analyzer
 * By Gerald Combs <gerald@ethereal.com>
 * 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"
#include "packet-smb-mailslot.h"
#include "packet-smb-browse.h"
#include "packet-smb-logon.h"
#include "packet-smb-pipe.h"

static int proto_smb_msp = -1;
static int hf_opcode = -1;
static int hf_priority = -1;
static int hf_class = -1;
static int hf_size = -1;
static int hf_name = -1;

static int ett_smb_msp = -1;

static const value_string opcode_vals[] = {
	{1,	"Write Mail Slot"},
	{0,	NULL}
};

static const value_string class_vals[] = {
	{1,	"Reliable"},
	{2,	"Unreliable & Broadcast"},
	{0,	NULL}
};

/* decode the SMB mail slot protocol */
gboolean
dissect_mailslot_smb(tvbuff_t *setup_tvb, tvbuff_t *tvb, packet_info *pinfo,
		     proto_tree *parent_tree)
{
	struct smb_info *smb_info = pinfo->private;
	proto_tree      *tree = 0;
	proto_item      *item;
	tvbuff_t        *next_tvb = NULL;
	guint16         opcode;
	int             offset = 0;
	int             len;

	if (!proto_is_protocol_enabled(proto_smb_msp)) {
		return FALSE;
	}
	pinfo->current_proto = "SMB Mailslot";

	if (check_col(pinfo->fd, COL_PROTOCOL)) {
		col_set_str(pinfo->fd, COL_PROTOCOL, "SMB Mailslot");
	}

	if (smb_info->data_offset < 0) {
		/* Interim reply */
		col_set_str(pinfo->fd, COL_INFO, "Interim reply");
		return TRUE;
	}

	/* do the opcode field */
	opcode = tvb_get_letohs(setup_tvb, offset);

	if (check_col(pinfo->fd, COL_INFO)) {
		  col_add_str(pinfo->fd, COL_INFO,
		      val_to_str(opcode, opcode_vals, "Unknown opcode:0x%04x"));
	}

	if (parent_tree) {
		item = proto_tree_add_item(parent_tree, proto_smb_msp, setup_tvb,
			offset, tvb_length_remaining(setup_tvb, offset), FALSE);
		tree = proto_item_add_subtree(item, ett_smb_msp);

		/* opcode */
		proto_tree_add_uint(tree, hf_opcode, setup_tvb, offset, 2,
		    opcode);
		offset += 2;

		/* priority */
		proto_tree_add_item(tree, hf_priority, setup_tvb, offset, 2,
		    TRUE);
		offset += 2;

		/* class */
		proto_tree_add_item(tree, hf_class, setup_tvb, offset, 2, TRUE);
		offset += 2;

		/* size */
		proto_tree_add_item(tree, hf_size, setup_tvb, offset, 2, TRUE);
		offset += 2;

		/* mailslot name */
		len = tvb_strsize(setup_tvb, offset);
		proto_tree_add_item(tree, hf_name, setup_tvb, offset, len,
		    TRUE);
		offset += len;
	}

	/* Quit if we don't have the transaction command name (mailslot path) */
	if (smb_info->trans_cmd == NULL)
		return TRUE;

	/* create new tvb for subdissector */
	next_tvb = tvb_new_subset(tvb, smb_info->data_offset, -1, -1);

	/*** Decide what dissector to call based upon the command value ***/
	if (strcmp(smb_info->trans_cmd, "BROWSE") == 0) {
		return dissect_mailslot_browse(next_tvb, pinfo, parent_tree);
	} else if (strcmp(smb_info->trans_cmd, "LANMAN") == 0) {
		/* Decode a LANMAN browse */
		return dissect_mailslot_lanman(next_tvb, pinfo, parent_tree);
	} else if ((strncmp(smb_info->trans_cmd, "NET", strlen("NET")) == 0) ||
		   (strcmp(smb_info->trans_cmd, "TEMP\\NETLOGON") == 0) ||
		   (strcmp(smb_info->trans_cmd, "MSSP") == 0)) {
/* NOTE: use TEMP\\NETLOGON and MSSP because they seems very common,	*/
/* NOTE: may need a look up list to check for the mailslot names passed	*/
/*		by the logon request packet */
		return dissect_smb_logon(next_tvb, pinfo, parent_tree);
	}
	return TRUE;
}

void
register_proto_smb_mailslot(void)
{
	static hf_register_info hf[] = {
		{ &hf_opcode,
			{ "Opcode", "mailslot.opcode", FT_UINT16, BASE_DEC,
			VALS(opcode_vals), 0, "MAILSLOT OpCode", HFILL }},

		{ &hf_priority,
			{ "Priority", "mailslot.priority", FT_UINT16, BASE_DEC,
			NULL, 0, "MAILSLOT Priority of transaction", HFILL }},

		{ &hf_class,
			{ "Class", "mailslot.class", FT_UINT16, BASE_DEC,
			VALS(class_vals), 0, "MAILSLOT Class of transaction", HFILL }},

		{ &hf_size,
			{ "Size", "mailslot.size", FT_UINT16, BASE_DEC,
			NULL, 0, "MAILSLOT Total size of mail data", HFILL }},

		{ &hf_name,
			{ "Mailslot Name", "mailslot.name", FT_STRING, BASE_NONE,
			NULL, 0, "MAILSLOT Name of mailslot", HFILL }},

	};

	static gint *ett[] = {
		&ett_smb_msp
	};

	proto_smb_msp = proto_register_protocol(
		"SMB MailSlot Protocol", "SMB Mailslot", "mailslot");

	proto_register_field_array(proto_smb_msp, hf, array_length(hf));
	proto_register_subtree_array(ett, array_length(ett));
}