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