connectionless cancel PDU's don't have a dg_server_accepting_cancels field
[obnox/wireshark/wip.git] / packet-rquota.c
1 /* packet-rquota.c
2  * Routines for rquota dissection
3  * Copyright 2001, Mike Frisch <frisch@hummingbird.com>
4  *
5  * $Id: packet-rquota.c,v 1.11 2002/11/01 00:48:38 sahlberg Exp $
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@ethereal.com>
9  * Copyright 1998 Gerald Combs
10  *
11  * Copied from packet-ypxfr.c
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
26  */
27
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
31
32
33
34 #include "packet-rpc.h"
35 #include "packet-rquota.h"
36
37 static int proto_rquota = -1;
38 static int hf_rquota_procedure_v1 = -1;
39 static int hf_rquota_pathp = -1;
40 static int hf_rquota_uid = -1;
41 static int hf_rquota_status = -1;
42 static int hf_rquota_rquota = -1;
43 static int hf_rquota_bsize = -1;
44 static int hf_rquota_active = -1;
45 static int hf_rquota_bhardlimit = -1;
46 static int hf_rquota_bsoftlimit = -1;
47 static int hf_rquota_curblocks = -1;
48 static int hf_rquota_fhardlimit = -1;
49 static int hf_rquota_fsoftlimit = -1;
50 static int hf_rquota_curfiles = -1;
51 static int hf_rquota_btimeleft = -1;
52 static int hf_rquota_ftimeleft = -1;
53
54 static gint ett_rquota = -1;
55 static gint ett_rquota_rquota = -1;
56
57 static const value_string names_rquota_status[] =
58 {
59 #define Q_OK            1
60         {       Q_OK,           "OK"    },
61 #define Q_NOQUOTA       2
62         {       Q_NOQUOTA,      "NOQUOTA"       },
63 #define Q_EPERM         3
64         {       Q_EPERM,        "EPERM" },
65         {       0,              NULL }
66 };
67
68
69 static int
70 dissect_rquota(tvbuff_t *tvb, int offset, proto_tree *tree)
71 {
72
73         proto_item *lock_item = NULL;
74         proto_tree *lock_tree = NULL;
75
76         lock_item = proto_tree_add_item(tree, hf_rquota_rquota, tvb,
77                         offset, -1, FALSE);
78
79         lock_tree = proto_item_add_subtree(lock_item, ett_rquota_rquota);
80
81         offset = dissect_rpc_uint32(tvb, lock_tree,
82                         hf_rquota_bsize, offset);
83
84         offset = dissect_rpc_bool(tvb, lock_tree,
85                         hf_rquota_active, offset);
86
87         offset = dissect_rpc_uint32(tvb, lock_tree,
88                         hf_rquota_bhardlimit, offset);
89
90         offset = dissect_rpc_uint32(tvb, lock_tree,
91                         hf_rquota_bsoftlimit, offset);
92
93         offset = dissect_rpc_uint32(tvb, lock_tree,
94                         hf_rquota_curblocks, offset);
95
96         offset = dissect_rpc_uint32(tvb, lock_tree,
97                         hf_rquota_fhardlimit, offset);
98
99         offset = dissect_rpc_uint32(tvb, lock_tree,
100                         hf_rquota_fsoftlimit, offset);
101
102         offset = dissect_rpc_uint32(tvb, lock_tree,
103                         hf_rquota_curfiles, offset);
104
105         offset = dissect_rpc_uint32(tvb, lock_tree,
106                         hf_rquota_btimeleft, offset);
107
108         offset = dissect_rpc_uint32(tvb, lock_tree,
109                         hf_rquota_ftimeleft, offset);
110
111         return offset;
112 }
113
114 static int
115 dissect_getquota_result(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
116 {
117         gint32  status;
118
119         status = tvb_get_ntohl(tvb, offset);
120
121         offset = dissect_rpc_uint32(tvb, tree,
122                         hf_rquota_status, offset);
123
124         if (status==Q_OK) {
125                 offset = dissect_rquota(tvb, offset, tree);
126         }
127
128         return offset;
129 }
130
131 static int
132 dissect_getquota_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
133 {
134         offset = dissect_rpc_string(tvb, tree,
135                         hf_rquota_pathp, offset, NULL);
136
137         offset = dissect_rpc_uint32(tvb, tree,
138                         hf_rquota_uid, offset);
139
140         return offset;
141 }
142
143 /* proc number, "proc name", dissect_request, dissect_reply */
144 /* NULL as function pointer means: type of arguments is "void". */
145 static const vsff rquota1_proc[] = {
146         { RQUOTAPROC_NULL,              "NULL",
147                 NULL,                           NULL },
148         { RQUOTAPROC_GETQUOTA,          "GETQUOTA",
149                 dissect_getquota_call,          dissect_getquota_result },
150         { RQUOTAPROC_GETACTIVEQUOTA,    "GETACTIVEQUOTA",
151                 dissect_getquota_call,          dissect_getquota_result },
152         { 0,                            NULL,
153                 NULL,                           NULL }
154 };
155 static const value_string rquota1_proc_vals[] = {
156         { RQUOTAPROC_NULL,              "NULL" },
157         { RQUOTAPROC_GETQUOTA,          "GETQUOTA" },
158         { RQUOTAPROC_GETACTIVEQUOTA,    "GETACTIVEQUOTA" },
159         { 0,                            NULL }
160 };
161 /* end of RQUOTA version 1 */
162
163 void
164 proto_register_rquota(void)
165 {
166         static struct true_false_string tfs_active = { "Quota is ACTIVE", "Quota is NOT active" };
167
168         static hf_register_info hf[] = {
169                 { &hf_rquota_procedure_v1, {
170                         "V1 Procedure", "rquota.procedure_v1", FT_UINT32, BASE_DEC,
171                         VALS(rquota1_proc_vals), 0, "V1 Procedure", HFILL }},
172                 { &hf_rquota_uid, {
173                         "uid", "rquota.uid", FT_UINT32, BASE_DEC,
174                         NULL, 0, "User ID", HFILL }},
175
176                 { &hf_rquota_pathp, {
177                         "pathp", "rquota.pathp", FT_STRING, BASE_DEC,
178                         NULL, 0, "Filesystem of interest", HFILL }},
179
180                 { &hf_rquota_status, {
181                         "status", "rquota.status", FT_UINT32, BASE_DEC,
182                         VALS(names_rquota_status), 0, "Status code", HFILL }},
183
184                 { &hf_rquota_rquota, {
185                         "rquota", "rquota.rquota", FT_NONE, BASE_NONE,
186                         NULL, 0, "Rquota structure", HFILL }},
187
188                 { &hf_rquota_bsize, {
189                         "bsize", "rquota.bsize", FT_UINT32, BASE_DEC,
190                         NULL, 0, "Block size", HFILL }},
191
192                 { &hf_rquota_active, {
193                         "active", "rquota.active", FT_BOOLEAN, BASE_NONE,
194                         &tfs_active, 0, "Indicates whether quota is active", HFILL }},
195
196                 { &hf_rquota_bhardlimit, {
197                         "bhardlimit", "rquota.bhardlimit", FT_UINT32, BASE_DEC,
198                         NULL, 0, "Hard limit for blocks", HFILL }},
199
200                 { &hf_rquota_bsoftlimit, {
201                         "bsoftlimit", "rquota.bsoftlimit", FT_UINT32, BASE_DEC,
202                         NULL, 0, "Soft limit for blocks", HFILL }},
203
204                 { &hf_rquota_curblocks, {
205                         "curblocks", "rquota.curblocks", FT_UINT32, BASE_DEC,
206                         NULL, 0, "Current block count", HFILL }},
207
208                 { &hf_rquota_fhardlimit, {
209                         "fhardlimit", "rquota.fhardlimit", FT_UINT32, BASE_DEC,
210                         NULL, 0, "Hard limit on allocated files", HFILL }},
211
212                 { &hf_rquota_fsoftlimit, {
213                         "fsoftlimit", "rquota.fsoftlimit", FT_UINT32, BASE_DEC,
214                         NULL, 0, "Soft limit of allocated files", HFILL }},
215
216                 { &hf_rquota_curfiles, {
217                         "curfiles", "rquota.curfiles", FT_UINT32, BASE_DEC,
218                         NULL, 0, "Current # allocated files", HFILL }},
219
220                 { &hf_rquota_btimeleft, {
221                         "btimeleft", "rquota.btimeleft", FT_UINT32, BASE_DEC,
222                         NULL, 0, "Time left for excessive disk use", HFILL }},
223
224                 { &hf_rquota_ftimeleft, {
225                         "ftimeleft", "rquota.ftimeleft", FT_UINT32, BASE_DEC,
226                         NULL, 0, "Time left for excessive files", HFILL }},
227
228         };
229
230         static gint *ett[] = {
231                 &ett_rquota,
232                 &ett_rquota_rquota,
233         };
234
235         proto_rquota = proto_register_protocol("Remote Quota",
236             "RQUOTA", "rquota");
237
238         proto_register_field_array(proto_rquota, hf, array_length(hf));
239
240         proto_register_subtree_array(ett, array_length(ett));
241 }
242
243 void
244 proto_reg_handoff_rquota(void)
245 {
246         /* Register the protocol as RPC */
247         rpc_init_prog(proto_rquota, RQUOTA_PROGRAM, ett_rquota);
248         /* Register the procedure tables */
249         rpc_init_proc_table(RQUOTA_PROGRAM, 1, rquota1_proc, hf_rquota_procedure_v1);
250 }
251
252
253