Removed many senseless pinfo parameters in RPC dissection and the layers above.
[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.7 2002/04/03 13:24:13 girlich 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 #ifdef HAVE_SYS_TYPES_H
34 #include <sys/types.h>
35 #endif
36
37
38 #include "packet-rpc.h"
39 #include "packet-rquota.h"
40
41 static int proto_rquota = -1;
42 static int hf_rquota_pathp = -1;
43 static int hf_rquota_uid = -1;
44 static int hf_rquota_status = -1;
45 static int hf_rquota_rquota = -1;
46 static int hf_rquota_bsize = -1;
47 static int hf_rquota_active = -1;
48 static int hf_rquota_bhardlimit = -1;
49 static int hf_rquota_bsoftlimit = -1;
50 static int hf_rquota_curblocks = -1;
51 static int hf_rquota_fhardlimit = -1;
52 static int hf_rquota_fsoftlimit = -1;
53 static int hf_rquota_curfiles = -1;
54 static int hf_rquota_btimeleft = -1;
55 static int hf_rquota_ftimeleft = -1;
56
57 static gint ett_rquota = -1;
58 static gint ett_rquota_rquota = -1;
59
60 static const value_string names_rquota_status[] =
61 {
62 #define Q_OK            1
63         {       Q_OK,           "OK"    },
64 #define Q_NOQUOTA       2
65         {       Q_NOQUOTA,      "NOQUOTA"       },
66 #define Q_EPERM         3
67         {       Q_EPERM,        "EPERM" },
68         {       0,              NULL }
69 };
70
71
72 static int
73 dissect_rquota(tvbuff_t *tvb, int offset, proto_tree *tree)
74 {
75
76         proto_item *lock_item = NULL;
77         proto_tree *lock_tree = NULL;
78
79         lock_item = proto_tree_add_item(tree, hf_rquota_rquota, tvb,
80                         offset, -1, FALSE);
81
82         lock_tree = proto_item_add_subtree(lock_item, ett_rquota_rquota);
83
84         offset = dissect_rpc_uint32(tvb, lock_tree, 
85                         hf_rquota_bsize, offset);
86
87         offset = dissect_rpc_bool(tvb, lock_tree,
88                         hf_rquota_active, offset);
89
90         offset = dissect_rpc_uint32(tvb, lock_tree, 
91                         hf_rquota_bhardlimit, offset);
92
93         offset = dissect_rpc_uint32(tvb, lock_tree, 
94                         hf_rquota_bsoftlimit, offset);
95
96         offset = dissect_rpc_uint32(tvb, lock_tree, 
97                         hf_rquota_curblocks, offset);
98
99         offset = dissect_rpc_uint32(tvb, lock_tree, 
100                         hf_rquota_fhardlimit, offset);
101
102         offset = dissect_rpc_uint32(tvb, lock_tree, 
103                         hf_rquota_fsoftlimit, offset);
104
105         offset = dissect_rpc_uint32(tvb, lock_tree, 
106                         hf_rquota_curfiles, offset);
107
108         offset = dissect_rpc_uint32(tvb, lock_tree, 
109                         hf_rquota_btimeleft, offset);
110
111         offset = dissect_rpc_uint32(tvb, lock_tree, 
112                         hf_rquota_ftimeleft, offset);
113
114         return offset;
115 }
116
117 static int
118 dissect_getquota_result(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
119 {
120         gint32  status;
121
122         status = tvb_get_ntohl(tvb, offset);
123
124         offset = dissect_rpc_uint32(tvb, tree, 
125                         hf_rquota_status, offset);
126
127         if (status==Q_OK) {
128                 offset = dissect_rquota(tvb, offset, tree);
129         }
130
131         return offset;
132 }
133
134 static int
135 dissect_getquota_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
136 {
137         offset = dissect_rpc_string(tvb, tree, 
138                         hf_rquota_pathp, offset, NULL);
139
140         offset = dissect_rpc_uint32(tvb, tree, 
141                         hf_rquota_uid, offset);
142
143         return offset;
144 }
145
146 /* proc number, "proc name", dissect_request, dissect_reply */
147 /* NULL as function pointer means: type of arguments is "void". */
148 static const vsff rquota1_proc[] = {
149         { RQUOTAPROC_NULL,              "NULL",         
150                 NULL,                           NULL },
151         { RQUOTAPROC_GETQUOTA,          "GETQUOTA",
152                 dissect_getquota_call,          dissect_getquota_result },
153         { RQUOTAPROC_GETACTIVEQUOTA,    "GETACTIVEQUOTA",
154                 dissect_getquota_call,          dissect_getquota_result },
155         { 0,                            NULL,           
156                 NULL,                           NULL }
157 };
158 /* end of RQUOTA version 1 */
159
160 void
161 proto_register_rquota(void)
162 {
163         static struct true_false_string tfs_active = { "Quota is ACTIVE", "Quota is NOT active" };
164
165         static hf_register_info hf[] = {
166                 { &hf_rquota_uid, {
167                         "uid", "rquota.uid", FT_UINT32, BASE_DEC,
168                         NULL, 0, "User ID", HFILL }},
169
170                 { &hf_rquota_pathp, {
171                         "pathp", "rquota.pathp", FT_STRING, BASE_DEC,
172                         NULL, 0, "Filesystem of interest", HFILL }},
173
174                 { &hf_rquota_status, {
175                         "status", "rquota.status", FT_UINT32, BASE_DEC,
176                         VALS(names_rquota_status), 0, "Status code", HFILL }},
177
178                 { &hf_rquota_rquota, {
179                         "rquota", "rquota.rquota", FT_NONE, BASE_NONE,
180                         NULL, 0, "Rquota structure", HFILL }},
181
182                 { &hf_rquota_bsize, {
183                         "bsize", "rquota.bsize", FT_UINT32, BASE_DEC,
184                         NULL, 0, "Block size", HFILL }},
185
186                 { &hf_rquota_active, {
187                         "active", "rquota.active", FT_BOOLEAN, BASE_NONE,
188                         &tfs_active, 0, "Indicates whether quota is active", HFILL }},
189
190                 { &hf_rquota_bhardlimit, {
191                         "bhardlimit", "rquota.bhardlimit", FT_UINT32, BASE_DEC,
192                         NULL, 0, "Hard limit for blocks", HFILL }},
193
194                 { &hf_rquota_bsoftlimit, {
195                         "bsoftlimit", "rquota.bsoftlimit", FT_UINT32, BASE_DEC,
196                         NULL, 0, "Soft limit for blocks", HFILL }},
197
198                 { &hf_rquota_curblocks, {
199                         "curblocks", "rquota.curblocks", FT_UINT32, BASE_DEC,
200                         NULL, 0, "Current block count", HFILL }},
201
202                 { &hf_rquota_fhardlimit, {
203                         "fhardlimit", "rquota.fhardlimit", FT_UINT32, BASE_DEC,
204                         NULL, 0, "Hard limit on allocated files", HFILL }},
205
206                 { &hf_rquota_fsoftlimit, {
207                         "fsoftlimit", "rquota.fsoftlimit", FT_UINT32, BASE_DEC,
208                         NULL, 0, "Soft limit of allocated files", HFILL }},
209
210                 { &hf_rquota_curfiles, {
211                         "curfiles", "rquota.curfiles", FT_UINT32, BASE_DEC,
212                         NULL, 0, "Current # allocated files", HFILL }},
213
214                 { &hf_rquota_btimeleft, {
215                         "btimeleft", "rquota.btimeleft", FT_UINT32, BASE_DEC,
216                         NULL, 0, "Time left for excessive disk use", HFILL }},
217
218                 { &hf_rquota_ftimeleft, {
219                         "ftimeleft", "rquota.ftimeleft", FT_UINT32, BASE_DEC,
220                         NULL, 0, "Time left for excessive files", HFILL }},
221
222         };
223
224         static gint *ett[] = {
225                 &ett_rquota,
226                 &ett_rquota_rquota,
227         };
228
229         proto_rquota = proto_register_protocol("Remote Quota",
230             "RQUOTA", "rquota");
231
232         proto_register_field_array(proto_rquota, hf, array_length(hf));
233
234         proto_register_subtree_array(ett, array_length(ett));
235 }
236
237 void
238 proto_reg_handoff_rquota(void)
239 {
240         /* Register the protocol as RPC */
241         rpc_init_prog(proto_rquota, RQUOTA_PROGRAM, ett_rquota);
242         /* Register the procedure tables */
243         rpc_init_proc_table(RQUOTA_PROGRAM, 1, rquota1_proc);
244 }
245
246
247