aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-rquota.c
blob: c875ce30b0f29d2ab2577d53c2c5880b3cd036a8 (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
/* packet-rquota.c
 * Routines for rquota dissection
 * Copyright 2001, Mike Frisch <frisch@hummingbird.com>
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * Copied from packet-ypxfr.c
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include "config.h"

#include "packet-rpc.h"

void proto_register_rquota(void);
void proto_reg_handoff_rquota(void);

static int proto_rquota = -1;
static int hf_rquota_procedure_v1 = -1;
static int hf_rquota_procedure_v2 = -1;
static int hf_rquota_pathp = -1;
static int hf_rquota_uid = -1;
static int hf_rquota_type = -1;
static int hf_rquota_id = -1;
static int hf_rquota_status = -1;
static int hf_rquota_rquota = -1;
static int hf_rquota_bsize = -1;
static int hf_rquota_active = -1;
static int hf_rquota_bhardlimit = -1;
static int hf_rquota_bsoftlimit = -1;
static int hf_rquota_curblocks = -1;
static int hf_rquota_fhardlimit = -1;
static int hf_rquota_fsoftlimit = -1;
static int hf_rquota_curfiles = -1;
static int hf_rquota_btimeleft = -1;
static int hf_rquota_ftimeleft = -1;

static gint ett_rquota = -1;
static gint ett_rquota_rquota = -1;

#define RQUOTAPROC_NULL 		0
#define RQUOTAPROC_GETQUOTA		1
#define RQUOTAPROC_GETACTIVEQUOTA	2
#define RQUOTAPROC_SETQUOTA		3
#define RQUOTAPROC_SETACTIVEQUOTA	4

#define RQUOTA_PROGRAM 100011

static const value_string names_rquota_status[] =
{
#define Q_OK		1
	{	Q_OK,		"OK"	},
#define Q_NOQUOTA	2
	{	Q_NOQUOTA,	"NOQUOTA"	},
#define Q_EPERM		3
	{	Q_EPERM,	"EPERM"	},
	{	0,		NULL }
};


static int
dissect_rquota(tvbuff_t *tvb, int offset, proto_tree *tree)
{

	proto_item *lock_item = NULL;
	proto_tree *lock_tree = NULL;

	lock_item = proto_tree_add_item(tree, hf_rquota_rquota, tvb,
			offset, -1, ENC_NA);

	lock_tree = proto_item_add_subtree(lock_item, ett_rquota_rquota);

	offset = dissect_rpc_uint32(tvb, lock_tree,
			hf_rquota_bsize, offset);

	offset = dissect_rpc_bool(tvb, lock_tree,
			hf_rquota_active, offset);

	offset = dissect_rpc_uint32(tvb, lock_tree,
			hf_rquota_bhardlimit, offset);

	offset = dissect_rpc_uint32(tvb, lock_tree,
			hf_rquota_bsoftlimit, offset);

	offset = dissect_rpc_uint32(tvb, lock_tree,
			hf_rquota_curblocks, offset);

	offset = dissect_rpc_uint32(tvb, lock_tree,
			hf_rquota_fhardlimit, offset);

	offset = dissect_rpc_uint32(tvb, lock_tree,
			hf_rquota_fsoftlimit, offset);

	offset = dissect_rpc_uint32(tvb, lock_tree,
			hf_rquota_curfiles, offset);

	offset = dissect_rpc_uint32(tvb, lock_tree,
			hf_rquota_btimeleft, offset);

	offset = dissect_rpc_uint32(tvb, lock_tree,
			hf_rquota_ftimeleft, offset);

	return offset;
}

static int
dissect_getquota_result(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, void* data _U_)
{
	gint32	status;
	int offset = 0;

	status = tvb_get_ntohl(tvb, offset);

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

	if (status==Q_OK) {
		offset = dissect_rquota(tvb, offset, tree);
	}

	return offset;
}

static int
dissect_getquota_call(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, void* data _U_)
{
	int offset = 0;

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

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

	return offset;
}

/* proc number, "proc name", dissect_request, dissect_reply */
static const vsff rquota1_proc[] = {
	{ RQUOTAPROC_NULL,		"NULL",
		dissect_rpc_void,		dissect_rpc_void },
	{ RQUOTAPROC_GETQUOTA,		"GETQUOTA",
		dissect_getquota_call,		dissect_getquota_result	},
	{ RQUOTAPROC_GETACTIVEQUOTA,	"GETACTIVEQUOTA",
		dissect_getquota_call,		dissect_getquota_result	},
	{ 0,				NULL,
		NULL,				NULL }
};
static const value_string rquota1_proc_vals[] = {
	{ RQUOTAPROC_NULL,		"NULL" },
	{ RQUOTAPROC_GETQUOTA,		"GETQUOTA" },
	{ RQUOTAPROC_GETACTIVEQUOTA,	"GETACTIVEQUOTA" },
	{ RQUOTAPROC_SETQUOTA,		"SETQUOTA" },
	{ RQUOTAPROC_SETACTIVEQUOTA,	"SETACTIVEQUOTA" },
	{ 0,				NULL }
};
/* end of RQUOTA version 1 */


static int
dissect_getquota2_call(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, void* data _U_)
{
	int offset = 0;

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

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

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

	return offset;
}


static const vsff rquota2_proc[] = {
	{ RQUOTAPROC_NULL,		"NULL",
		dissect_rpc_void,		dissect_rpc_void },
	{ RQUOTAPROC_GETQUOTA,		"GETQUOTA",
		dissect_getquota2_call,		dissect_getquota_result	},
	{ RQUOTAPROC_GETACTIVEQUOTA,	"GETACTIVEQUOTA",
		dissect_getquota2_call,		dissect_getquota_result	},
	{ 0,				NULL,
		NULL,				NULL }
};
static const value_string rquota2_proc_vals[] = {
	{ RQUOTAPROC_NULL,		"NULL" },
	{ RQUOTAPROC_GETQUOTA,		"GETQUOTA" },
	{ RQUOTAPROC_GETACTIVEQUOTA,	"GETACTIVEQUOTA" },
	{ RQUOTAPROC_SETQUOTA,		"SETQUOTA" },
	{ RQUOTAPROC_SETACTIVEQUOTA,	"SETACTIVEQUOTA" },
	{ 0,				NULL }
};
/* end of RQUOTA version 2 */

static const rpc_prog_vers_info rquota_vers_info[] = {
	{ 1, rquota1_proc, &hf_rquota_procedure_v1 },
	{ 2, rquota2_proc, &hf_rquota_procedure_v2 },
};

void
proto_register_rquota(void)
{
	static struct true_false_string tfs_active = { "Quota is ACTIVE", "Quota is NOT active" };

	static hf_register_info hf[] = {
		{ &hf_rquota_procedure_v1, {
			"V1 Procedure", "rquota.procedure_v1", FT_UINT32, BASE_DEC,
			VALS(rquota1_proc_vals), 0, NULL, HFILL }},
		{ &hf_rquota_procedure_v2, {
			"V2 Procedure", "rquota.procedure_v2", FT_UINT32, BASE_DEC,
			VALS(rquota2_proc_vals), 0, NULL, HFILL }},
		{ &hf_rquota_uid, {
			"uid", "rquota.uid", FT_UINT32, BASE_DEC,
			NULL, 0, "User ID", HFILL }},
		{ &hf_rquota_type, {
			"type", "rquota.type", FT_UINT32, BASE_DEC,
			NULL, 0, NULL, HFILL }},
		{ &hf_rquota_id, {
			"id", "rquota.id", FT_UINT32, BASE_DEC,
			NULL, 0, NULL, HFILL }},

		{ &hf_rquota_pathp, {
			"pathp", "rquota.pathp", FT_STRING, BASE_NONE,
			NULL, 0, "Filesystem of interest", HFILL }},

		{ &hf_rquota_status, {
			"status", "rquota.status", FT_UINT32, BASE_DEC,
			VALS(names_rquota_status), 0, "Status code", HFILL }},

		{ &hf_rquota_rquota, {
			"rquota", "rquota.rquota", FT_NONE, BASE_NONE,
			NULL, 0, "Rquota structure", HFILL }},

		{ &hf_rquota_bsize, {
			"bsize", "rquota.bsize", FT_UINT32, BASE_DEC,
			NULL, 0, "Block size", HFILL }},

		{ &hf_rquota_active, {
			"active", "rquota.active", FT_BOOLEAN, BASE_NONE,
			TFS(&tfs_active), 0x0, "Indicates whether quota is active", HFILL }},

		{ &hf_rquota_bhardlimit, {
			"bhardlimit", "rquota.bhardlimit", FT_UINT32, BASE_DEC,
			NULL, 0, "Hard limit for blocks", HFILL }},

		{ &hf_rquota_bsoftlimit, {
			"bsoftlimit", "rquota.bsoftlimit", FT_UINT32, BASE_DEC,
			NULL, 0, "Soft limit for blocks", HFILL }},

		{ &hf_rquota_curblocks, {
			"curblocks", "rquota.curblocks", FT_UINT32, BASE_DEC,
			NULL, 0, "Current block count", HFILL }},

		{ &hf_rquota_fhardlimit, {
			"fhardlimit", "rquota.fhardlimit", FT_UINT32, BASE_DEC,
			NULL, 0, "Hard limit on allocated files", HFILL }},

		{ &hf_rquota_fsoftlimit, {
			"fsoftlimit", "rquota.fsoftlimit", FT_UINT32, BASE_DEC,
			NULL, 0, "Soft limit of allocated files", HFILL }},

		{ &hf_rquota_curfiles, {
			"curfiles", "rquota.curfiles", FT_UINT32, BASE_DEC,
			NULL, 0, "Current # allocated files", HFILL }},

		{ &hf_rquota_btimeleft, {
			"btimeleft", "rquota.btimeleft", FT_UINT32, BASE_DEC,
			NULL, 0, "Time left for excessive disk use", HFILL }},

		{ &hf_rquota_ftimeleft, {
			"ftimeleft", "rquota.ftimeleft", FT_UINT32, BASE_DEC,
			NULL, 0, "Time left for excessive files", HFILL }},

	};

	static gint *ett[] = {
		&ett_rquota,
		&ett_rquota_rquota,
	};

	proto_rquota = proto_register_protocol("Remote Quota",
	    "RQUOTA", "rquota");

	proto_register_field_array(proto_rquota, hf, array_length(hf));

	proto_register_subtree_array(ett, array_length(ett));
}

void
proto_reg_handoff_rquota(void)
{
	/* Register the protocol as RPC */
	rpc_init_prog(proto_rquota, RQUOTA_PROGRAM, ett_rquota,
	    G_N_ELEMENTS(rquota_vers_info), rquota_vers_info);
}

/*
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
 *
 * Local variables:
 * c-basic-offset: 8
 * tab-width: 8
 * indent-tabs-mode: t
 * End:
 *
 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
 * :indentSize=8:tabSize=8:noTabs=false:
 */