aboutsummaryrefslogtreecommitdiffstats
path: root/packet-pcnfsd.c
blob: 1d63c7e79817ae1cbb94be876efd0d287806d0e4 (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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
/* packet-pcnfsd.c
 * Routines for PCNFSD dissection
 *
 * $Id: packet-pcnfsd.c,v 1.12 2002/11/01 00:48:38 sahlberg Exp $
 *
 * Ethereal - Network traffic analyzer
 * By Gerald Combs <gerald@ethereal.com>
 * Copyright 1998 Gerald Combs
 *
 * Copied from packet-ypbind.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.
 */


/*
Protocol information comes from the book
	"NFS Illustrated" by Brent Callaghan, ISBN 0-201-32570-5
*/


#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <string.h>

#include "packet-rpc.h"
#include "packet-pcnfsd.h"

static int proto_pcnfsd = -1;
static int hf_pcnfsd_procedure_v1 = -1;
static int hf_pcnfsd_procedure_v2 = -1;
static int hf_pcnfsd_auth_client = -1;
static int hf_pcnfsd_auth_ident_obscure = -1;
static int hf_pcnfsd_auth_ident_clear = -1;
static int hf_pcnfsd_auth_password_obscure = -1;
static int hf_pcnfsd_auth_password_clear = -1;
static int hf_pcnfsd_comment = -1;
static int hf_pcnfsd_status = -1;
static int hf_pcnfsd_uid = -1;
static int hf_pcnfsd_gid = -1;
static int hf_pcnfsd_gids_count = -1;
static int hf_pcnfsd_homedir = -1;
static int hf_pcnfsd_def_umask = -1;
static int hf_pcnfsd_username = -1;


static gint ett_pcnfsd = -1;
static gint ett_pcnfsd_auth_ident = -1;
static gint ett_pcnfsd_auth_password = -1;
static gint ett_pcnfsd_gids = -1;

int
dissect_pcnfsd_username(tvbuff_t *tvb, int offset, proto_tree *tree)
{
	return dissect_rpc_string(tvb, tree, hf_pcnfsd_username, offset, NULL);
}

#define MAP_REQ_UID		0
#define MAP_REQ_GID		1
#define MAP_REQ_UNAME	2
#define MAP_REQ_GNAME	3

static const value_string names_mapreq[] =
{
	{	MAP_REQ_UID,	"MAP_REQ_UID"	},
	{	MAP_REQ_GID,	"MAP_REQ_GID"	},
	{	MAP_REQ_UNAME,	"MAP_REQ_UNAME"	},
	{	MAP_REQ_GNAME,	"MAP_REQ_GNAME"	},
	{	0,	NULL	}
};

int
dissect_pcnfsd_mapreq(tvbuff_t *tvb, int offset, proto_tree *tree)
{
	guint32 mapreq;

	mapreq = tvb_get_ntohl(tvb, offset + 0);

	if (tree)
		proto_tree_add_text(tree, tvb, offset, 4, "Request: %s (%u)",
			val_to_str(mapreq, names_mapreq, "%u"), mapreq);

	offset += 4;

	return offset;
}

int
dissect_pcnfsd2_dissect_mapreq_arg_item(tvbuff_t *tvb, int offset,
	packet_info *pinfo _U_, proto_tree *tree)
{
	offset = dissect_pcnfsd_mapreq(tvb, offset, tree);

	offset = dissect_rpc_uint32(tvb, tree, hf_pcnfsd_uid, offset);

	offset = dissect_pcnfsd_username(tvb, offset, tree);

	return offset;
}

int
dissect_pcnfsd2_mapid_call(tvbuff_t *tvb, int offset, packet_info *pinfo,
	proto_tree *tree)
{
	offset = dissect_rpc_string(tvb, tree, hf_pcnfsd_comment, offset, NULL);

	offset = dissect_rpc_list(tvb, pinfo, tree, offset,
		dissect_pcnfsd2_dissect_mapreq_arg_item);

	return offset;
}

#define MAP_RES_OK		0
#define MAP_RES_UNKNOWN	1
#define MAP_RES_DENIED	2

static const value_string names_maprstat[] =
{
	{	MAP_RES_OK,	"MAP_RES_OK"	},
	{	MAP_RES_UNKNOWN,	"MAP_RES_UNKNOWN"	},
	{	MAP_RES_DENIED,	"MAP_RES_DENIED"	},
	{	0,	NULL	}
};

int
dissect_pcnfsd2_dissect_mapreq_res_item(tvbuff_t *tvb, int offset,
	packet_info *pinfo _U_, proto_tree *tree)
{
	guint32 maprstat;

	offset = dissect_pcnfsd_mapreq(tvb, offset, tree);

	maprstat = tvb_get_ntohl(tvb, offset + 0);

	if (tree)
		proto_tree_add_text(tree, tvb, offset, 4, "Status: %s (%u)",
			val_to_str(maprstat, names_maprstat, "%u"), maprstat);

	offset += 4;

	offset = dissect_rpc_uint32(tvb, tree, hf_pcnfsd_uid, offset);

	offset = dissect_pcnfsd_username(tvb, offset, tree);

	return offset;
}

int
dissect_pcnfsd2_mapid_reply(tvbuff_t *tvb, int offset, packet_info *pinfo,
	proto_tree *tree)
{
	offset = dissect_rpc_string(tvb, tree, hf_pcnfsd_comment, offset, NULL);

	offset = dissect_rpc_list(tvb, pinfo, tree, offset,
		dissect_pcnfsd2_dissect_mapreq_res_item);

	return offset;
}

/* "NFS Illustrated 14.7.13 */
static void
pcnfsd_decode_obscure(char* data, int len)
{
	for ( ; len>0 ; len--, data++) {
		*data = (*data ^ 0x5b) & 0x7f;
	}
}


/* "NFS Illustrated" 14.7.13 */
static int
dissect_pcnfsd2_auth_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
	proto_tree *tree)
{
	int	newoffset;
	char	*ident = NULL;
	proto_item	*ident_item = NULL;
	proto_tree	*ident_tree = NULL;
	char	*password = NULL;
	proto_item	*password_item = NULL;
	proto_tree	*password_tree = NULL;

	offset = dissect_rpc_string(tvb, tree,
		hf_pcnfsd_auth_client, offset, NULL);

	if (tree) {
		ident_item = proto_tree_add_text(tree, tvb,
				offset, -1, "Authentication Ident");
		if (ident_item)
			ident_tree = proto_item_add_subtree(
				ident_item, ett_pcnfsd_auth_ident);
	}
	newoffset = dissect_rpc_string(tvb, ident_tree,
		hf_pcnfsd_auth_ident_obscure, offset, &ident);
	if (ident_item) {
		proto_item_set_len(ident_item, newoffset-offset);
	}

	if (ident) {
		pcnfsd_decode_obscure(ident, strlen(ident));
		if (ident_tree)
			proto_tree_add_string(ident_tree,
				hf_pcnfsd_auth_ident_clear,
				tvb, offset+4, strlen(ident), ident);
	}
	if (ident_item) {
		proto_item_set_text(ident_item, "Authentication Ident: %s",
			ident);
	}
	if (ident) {
		g_free(ident);
		ident = NULL;
	}

	offset = newoffset;

	if (tree) {
		password_item = proto_tree_add_text(tree, tvb,
				offset, -1, "Authentication Password");
		if (password_item)
			password_tree = proto_item_add_subtree(
				password_item, ett_pcnfsd_auth_password);
	}
	newoffset = dissect_rpc_string(tvb, password_tree,
		hf_pcnfsd_auth_password_obscure, offset, &password);
	if (password_item) {
		proto_item_set_len(password_item, newoffset-offset);
	}

	if (password) {
		pcnfsd_decode_obscure(password, strlen(password));
		if (password_tree)
			proto_tree_add_string(password_tree,
				hf_pcnfsd_auth_password_clear,
				tvb, offset+4, strlen(password), password);
	}
	if (password_item) {
		proto_item_set_text(password_item, "Authentication Password: %s",
			password);
	}
	if (password) {
		g_free(password);
		password = NULL;
	}

	offset = newoffset;

	offset = dissect_rpc_string(tvb, tree,
		hf_pcnfsd_comment, offset, NULL);

	return offset;
}


/* "NFS Illustrated" 14.7.13 */
static int
dissect_pcnfsd2_auth_reply(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
	proto_tree *tree)
{
	int	gids_count;
	proto_item	*gitem = NULL;
	proto_tree	*gtree = NULL;
	int	gids_i;

	offset = dissect_rpc_uint32(tvb, tree, hf_pcnfsd_status, offset);
	offset = dissect_rpc_uint32(tvb, tree, hf_pcnfsd_uid, offset);
	offset = dissect_rpc_uint32(tvb, tree, hf_pcnfsd_gid, offset);
	gids_count = tvb_get_ntohl(tvb,offset+0);
	if (tree) {
		gitem = proto_tree_add_text(tree, tvb,
			offset, 4+gids_count*4, "Group IDs: %d", gids_count);
		gtree = proto_item_add_subtree(gitem, ett_pcnfsd_gids);
	}
	if (gtree) {
		proto_tree_add_item(gtree, hf_pcnfsd_gids_count, tvb, offset, 4, FALSE);
	}
	offset += 4;
	for (gids_i = 0 ; gids_i < gids_count ; gids_i++) {
		offset = dissect_rpc_uint32(tvb, gtree,
				hf_pcnfsd_gid, offset);
	}
	offset = dissect_rpc_string(tvb, tree,
                hf_pcnfsd_homedir, offset, NULL);
	/* should be signed int32 */
	offset = dissect_rpc_uint32(tvb, tree, hf_pcnfsd_def_umask, offset);
	offset = dissect_rpc_string(tvb, tree,
                hf_pcnfsd_comment, offset, NULL);

	return offset;
}


/* "NFS Illustrated", 14.6 */
/* proc number, "proc name", dissect_request, dissect_reply */
/* NULL as function pointer means: type of arguments is "void". */
static const vsff pcnfsd1_proc[] = {
	{ 0,	"NULL",		NULL,				NULL },
	{ 1,	"AUTH",		NULL,				NULL },
	{ 2,	"PR_INIT",	NULL,				NULL },
	{ 3,	"PR_START",	NULL,				NULL },
	{ 0,	NULL,		NULL,				NULL }
};
static const value_string pcnfsd1_proc_vals[] = {
	{ 0,	"NULL" },
	{ 1,	"AUTH" },
	{ 2,	"PR_INIT" },
	{ 3,	"PR_START" },
	{ 0,	NULL }
};
/* end of PCNFS version 1 */


/* "NFS Illustrated", 14.7 */
static const vsff pcnfsd2_proc[] = {
	{ 0,	"NULL",		NULL,				NULL },
	{ 1,	"INFO",		NULL,				NULL },
	{ 2,	"PR_INIT",	NULL,				NULL },
	{ 3,	"PR_START",	NULL,				NULL },
	{ 4,	"PR_LIST",	NULL,				NULL },
	{ 5,	"PR_QUEUE",	NULL,				NULL },
	{ 6,	"PR_STATUS",	NULL,				NULL },
	{ 7,	"PR_CANCEL",	NULL,				NULL },
	{ 8,	"PR_ADMIN",	NULL,				NULL },
	{ 9,	"PR_REQUEUE",	NULL,				NULL },
	{ 10,	"PR_HOLD",	NULL,				NULL },
	{ 11,	"PR_RELEASE",	NULL,				NULL },
	{ 12,	"MAPID",
	dissect_pcnfsd2_mapid_call, dissect_pcnfsd2_mapid_reply },
	{ 13,	"AUTH",
	dissect_pcnfsd2_auth_call,	dissect_pcnfsd2_auth_reply },
	{ 14,	"ALERT",	NULL,				NULL },
	{ 0,	NULL,		NULL,				NULL }
};
static const value_string pcnfsd2_proc_vals[] = {
	{ 0,	"NULL" },
	{ 1,	"INFO" },
	{ 2,	"PR_INIT" },
	{ 3,	"PR_START" },
	{ 4,	"PR_LIST" },
	{ 5,	"PR_QUEUE" },
	{ 6,	"PR_STATUS" },
	{ 7,	"PR_CANCEL" },
	{ 8,	"PR_ADMIN" },
	{ 9,	"PR_REQUEUE" },
	{ 10,	"PR_HOLD" },
	{ 11,	"PR_RELEASE" },
	{ 12,	"MAPID" },
	{ 13,	"AUTH" },
	{ 14,	"ALERT" },
	{ 0,	NULL }
};
/* end of PCNFS version 2 */


void
proto_register_pcnfsd(void)
{
	static hf_register_info hf[] = {
		{ &hf_pcnfsd_procedure_v1, {
			"V1 Procedure", "pcnfsd.procedure_v1", FT_UINT32, BASE_DEC,
			VALS(pcnfsd1_proc_vals), 0, "V1 Procedure", HFILL }},
		{ &hf_pcnfsd_procedure_v2, {
			"V2 Procedure", "pcnfsd.procedure_v2", FT_UINT32, BASE_DEC,
			VALS(pcnfsd2_proc_vals), 0, "V2 Procedure", HFILL }},
		{ &hf_pcnfsd_auth_client, {
			"Authentication Client", "pcnfsd.auth.client", FT_STRING, BASE_DEC,
			NULL, 0, "Authentication Client", HFILL }},
		{ &hf_pcnfsd_auth_ident_obscure, {
			"Obscure Ident", "pcnfsd.auth.ident.obscure", FT_STRING, BASE_DEC,
			NULL, 0, "Athentication Obscure Ident", HFILL }},
		{ &hf_pcnfsd_auth_ident_clear, {
			"Clear Ident", "pcnfsd.auth.ident.clear", FT_STRING, BASE_DEC,
			NULL, 0, "Authentication Clear Ident", HFILL }},
		{ &hf_pcnfsd_auth_password_obscure, {
			"Obscure Password", "pcnfsd.auth.password.obscure", FT_STRING, BASE_DEC,
			NULL, 0, "Athentication Obscure Password", HFILL }},
		{ &hf_pcnfsd_auth_password_clear, {
			"Clear Password", "pcnfsd.auth.password.clear", FT_STRING, BASE_DEC,
			NULL, 0, "Authentication Clear Password", HFILL }},
		{ &hf_pcnfsd_comment, {
			"Comment", "pcnfsd.comment", FT_STRING, BASE_DEC,
			NULL, 0, "Comment", HFILL }},
		{ &hf_pcnfsd_status, {
                        "Reply Status", "pcnfsd.status", FT_UINT32, BASE_DEC,
                        NULL, 0, "Status", HFILL }},
		{ &hf_pcnfsd_uid, {
                        "User ID", "pcnfsd.uid", FT_UINT32, BASE_DEC,
                        NULL, 0, "User ID", HFILL }},
		{ &hf_pcnfsd_gid, {
                        "Group ID", "pcnfsd.gid", FT_UINT32, BASE_DEC,
                        NULL, 0, "Group ID", HFILL }},
		{ &hf_pcnfsd_gids_count, {
                        "Group ID Count", "pcnfsd.gids.count", FT_UINT32, BASE_DEC,
                        NULL, 0, "Group ID Count", HFILL }},
		{ &hf_pcnfsd_homedir, {
			"Home Directory", "pcnfsd.homedir", FT_STRING, BASE_DEC,
			NULL, 0, "Home Directory", HFILL }},
		{ &hf_pcnfsd_def_umask, {
                        "def_umask", "pcnfsd.def_umask", FT_INT32, BASE_OCT,
                        NULL, 0, "def_umask", HFILL }},
		{ &hf_pcnfsd_username, {
			"User name", "pcnfsd.username", FT_STRING, BASE_DEC,
			NULL, 0, "pcnfsd.username", HFILL }},
	};

	static gint *ett[] = {
		&ett_pcnfsd,
		&ett_pcnfsd_auth_ident,
		&ett_pcnfsd_auth_password,
		&ett_pcnfsd_gids
	};

	proto_pcnfsd = proto_register_protocol("PC NFS",
	    "PCNFSD", "pcnfsd");
	proto_register_field_array(proto_pcnfsd, hf, array_length(hf));
	proto_register_subtree_array(ett, array_length(ett));
}

void
proto_reg_handoff_pcnfsd(void)
{
	/* Register the protocol as RPC */
	rpc_init_prog(proto_pcnfsd, PCNFSD_PROGRAM, ett_pcnfsd);
	/* Register the procedure tables */
	rpc_init_proc_table(PCNFSD_PROGRAM, 1, pcnfsd1_proc, hf_pcnfsd_procedure_v1);
	rpc_init_proc_table(PCNFSD_PROGRAM, 2, pcnfsd2_proc, hf_pcnfsd_procedure_v2);
}