quota update partial NTGetUserQuota support
[obnox/wireshark/wip.git] / packet-pcnfsd.c
1 /* packet-pcnfsd.c
2  * Routines for PCNFSD dissection
3  *
4  * $Id: packet-pcnfsd.c,v 1.5 2002/01/30 23:08:26 guy Exp $
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@ethereal.com>
8  * Copyright 1998 Gerald Combs
9  *
10  * Copied from packet-ypbind.c
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25  */
26
27
28 /*
29 Protocol information comes from the book
30         "NFS Illustrated" by Brent Callaghan, ISBN 0-201-32570-5
31 */
32
33
34 #ifdef HAVE_CONFIG_H
35 #include "config.h"
36 #endif
37
38 #ifdef HAVE_SYS_TYPES_H
39 #include <sys/types.h>
40 #endif
41
42 #include <string.h>
43
44 #include "packet-rpc.h"
45 #include "packet-pcnfsd.h"
46
47 static int proto_pcnfsd = -1;
48
49 static int hf_pcnfsd_auth_client = -1;
50 static int hf_pcnfsd_auth_ident_obscure = -1;
51 static int hf_pcnfsd_auth_ident_clear = -1;
52 static int hf_pcnfsd_auth_password_obscure = -1;
53 static int hf_pcnfsd_auth_password_clear = -1;
54 static int hf_pcnfsd_comment = -1;
55 static int hf_pcnfsd_status = -1;
56 static int hf_pcnfsd_uid = -1;
57 static int hf_pcnfsd_gid = -1;
58 static int hf_pcnfsd_gids_count = -1;
59 static int hf_pcnfsd_homedir = -1;
60 static int hf_pcnfsd_def_umask = -1;
61
62
63 static gint ett_pcnfsd = -1;
64 static gint ett_pcnfsd_auth_ident = -1;
65 static gint ett_pcnfsd_auth_password = -1;
66 static gint ett_pcnfsd_gids = -1;
67
68 /* "NFS Illustrated 14.7.13 */
69 void
70 pcnfsd_decode_obscure(char* data, int len)
71 {
72         for ( ; len>0 ; len--, data++) {
73                 *data = (*data ^ 0x5b) & 0x7f;
74         }
75 }
76
77
78 /* "NFS Illustrated" 14.7.13 */
79 int
80 dissect_pcnfsd2_auth_call(tvbuff_t *tvb, int offset, packet_info *pinfo,
81         proto_tree *tree)
82 {
83         int     newoffset;
84         char    *ident = NULL;
85         proto_item      *ident_item = NULL;
86         proto_tree      *ident_tree = NULL;
87         char    *password = NULL;
88         proto_item      *password_item = NULL;
89         proto_tree      *password_tree = NULL;
90
91         offset = dissect_rpc_string(tvb, pinfo, tree,
92                 hf_pcnfsd_auth_client, offset, NULL);
93
94         if (tree) {
95                 ident_item = proto_tree_add_text(tree, tvb,
96                                 offset, -1, "Authentication Ident");
97                 if (ident_item)
98                         ident_tree = proto_item_add_subtree(
99                                 ident_item, ett_pcnfsd_auth_ident);
100         }
101         newoffset = dissect_rpc_string(tvb, pinfo, ident_tree,
102                 hf_pcnfsd_auth_ident_obscure, offset, &ident);
103         if (ident_item) {
104                 proto_item_set_len(ident_item, newoffset-offset);
105         }
106         
107         if (ident) {
108                 pcnfsd_decode_obscure(ident, strlen(ident));
109                 if (ident_tree)
110                         proto_tree_add_string(ident_tree,
111                                 hf_pcnfsd_auth_ident_clear,
112                                 tvb, offset+4, strlen(ident), ident);
113         }
114         if (ident_item) {
115                 proto_item_set_text(ident_item, "Authentication Ident: %s",
116                         ident);
117         }
118         if (ident) {
119                 g_free(ident);
120                 ident = NULL;
121         }
122
123         offset = newoffset;
124
125         if (tree) {
126                 password_item = proto_tree_add_text(tree, tvb,
127                                 offset, -1, "Authentication Password");
128                 if (password_item)
129                         password_tree = proto_item_add_subtree(
130                                 password_item, ett_pcnfsd_auth_password);
131         }
132         newoffset = dissect_rpc_string(tvb, pinfo, password_tree,
133                 hf_pcnfsd_auth_password_obscure, offset, &password);
134         if (password_item) {
135                 proto_item_set_len(password_item, newoffset-offset);
136         }
137         
138         if (password) {
139                 pcnfsd_decode_obscure(password, strlen(password));
140                 if (password_tree)
141                         proto_tree_add_string(password_tree,
142                                 hf_pcnfsd_auth_password_clear,
143                                 tvb, offset+4, strlen(password), password);
144         }
145         if (password_item) {
146                 proto_item_set_text(password_item, "Authentication Password: %s",
147                         password);
148         }
149         if (password) {
150                 g_free(password);
151                 password = NULL;
152         }
153
154         offset = newoffset;
155
156         offset = dissect_rpc_string(tvb, pinfo, tree,
157                 hf_pcnfsd_comment, offset, NULL);
158
159         return offset;
160 }
161
162
163 /* "NFS Illustrated" 14.7.13 */
164 int
165 dissect_pcnfsd2_auth_reply(tvbuff_t *tvb, int offset, packet_info *pinfo,
166         proto_tree *tree)
167 {
168         int     gids_count;
169         proto_item      *gitem = NULL;
170         proto_tree      *gtree = NULL;
171         int     gids_i;
172
173         offset = dissect_rpc_uint32(tvb, pinfo, tree, hf_pcnfsd_status, offset);
174         offset = dissect_rpc_uint32(tvb, pinfo, tree, hf_pcnfsd_uid, offset);
175         offset = dissect_rpc_uint32(tvb, pinfo, tree, hf_pcnfsd_gid, offset);
176         gids_count = tvb_get_ntohl(tvb,offset+0);
177         if (tree) {
178                 gitem = proto_tree_add_text(tree, tvb,
179                         offset, 4+gids_count*4, "Group IDs: %d", gids_count);
180                 gtree = proto_item_add_subtree(gitem, ett_pcnfsd_gids);
181         }
182         if (gtree) {
183                 proto_tree_add_item(gtree, hf_pcnfsd_gids_count, tvb, offset, 4, FALSE);
184         }
185         offset += 4;
186         for (gids_i = 0 ; gids_i < gids_count ; gids_i++) {
187                 offset = dissect_rpc_uint32(tvb, pinfo, gtree,
188                                 hf_pcnfsd_gid, offset);
189         }
190         offset = dissect_rpc_string(tvb, pinfo, tree,
191                 hf_pcnfsd_homedir, offset, NULL);
192         /* should be signed int32 */
193         offset = dissect_rpc_uint32(tvb, pinfo, tree, hf_pcnfsd_def_umask, offset);
194         offset = dissect_rpc_string(tvb, pinfo, tree,
195                 hf_pcnfsd_comment, offset, NULL);
196
197         return offset;
198 }
199
200
201 /* "NFS Illustrated", 14.6 */
202 /* proc number, "proc name", dissect_request, dissect_reply */
203 /* NULL as function pointer means: type of arguments is "void". */
204 static const vsff pcnfsd1_proc[] = {
205         { 0,    "NULL",         NULL,                           NULL },
206         { 1,    "AUTH",         NULL,                           NULL },
207         { 2,    "PR_INIT",      NULL,                           NULL },
208         { 3,    "PR_START",     NULL,                           NULL },
209         { 0,    NULL,           NULL,                           NULL }
210 };
211 /* end of PCNFS version 1 */
212
213
214 /* "NFS Illustrated", 14.7 */
215 static const vsff pcnfsd2_proc[] = {
216         { 0,    "NULL",         NULL,                           NULL },
217         { 1,    "INFO",         NULL,                           NULL },
218         { 2,    "PR_INIT",      NULL,                           NULL },
219         { 3,    "PR_START",     NULL,                           NULL },
220         { 4,    "PR_LIST",      NULL,                           NULL },
221         { 5,    "PR_QUEUE",     NULL,                           NULL },
222         { 6,    "PR_STATUS",    NULL,                           NULL },
223         { 7,    "PR_CANCEL",    NULL,                           NULL },
224         { 8,    "PR_ADMIN",     NULL,                           NULL },
225         { 9,    "PR_REQUEUE",   NULL,                           NULL },
226         { 10,   "PR_HOLD",      NULL,                           NULL },
227         { 11,   "PR_RELEASE",   NULL,                           NULL },
228         { 12,   "MAPID",        NULL,                           NULL },
229         { 13,   "AUTH",         
230         dissect_pcnfsd2_auth_call,      dissect_pcnfsd2_auth_reply },
231         { 14,   "ALERT",        NULL,                           NULL },
232         { 0,    NULL,           NULL,                           NULL }
233 };
234 /* end of PCNFS version 2 */
235
236
237 void
238 proto_register_pcnfsd(void)
239 {
240         static hf_register_info hf[] = {
241                 { &hf_pcnfsd_auth_client, {
242                         "Authentication Client", "pcnfsd.auth.client", FT_STRING, BASE_DEC,
243                         NULL, 0, "Authentication Client", HFILL }},
244                 { &hf_pcnfsd_auth_ident_obscure, {
245                         "Obscure Ident", "pcnfsd.auth.ident.obscure", FT_STRING, BASE_DEC,
246                         NULL, 0, "Athentication Obscure Ident", HFILL }},
247                 { &hf_pcnfsd_auth_ident_clear, {
248                         "Clear Ident", "pcnfsd.auth.ident.clear", FT_STRING, BASE_DEC,
249                         NULL, 0, "Authentication Clear Ident", HFILL }},
250                 { &hf_pcnfsd_auth_password_obscure, {
251                         "Obscure Password", "pcnfsd.auth.password.obscure", FT_STRING, BASE_DEC,
252                         NULL, 0, "Athentication Obscure Password", HFILL }},
253                 { &hf_pcnfsd_auth_password_clear, {
254                         "Clear Password", "pcnfsd.auth.password.clear", FT_STRING, BASE_DEC,
255                         NULL, 0, "Authentication Clear Password", HFILL }},
256                 { &hf_pcnfsd_comment, {
257                         "Comment", "pcnfsd.comment", FT_STRING, BASE_DEC,
258                         NULL, 0, "Comment", HFILL }},
259                 { &hf_pcnfsd_status, {
260                         "Reply Status", "pcnfsd.status", FT_UINT32, BASE_DEC,
261                         NULL, 0, "Status", HFILL }},
262                 { &hf_pcnfsd_uid, {
263                         "User ID", "pcnfsd.uid", FT_UINT32, BASE_DEC,
264                         NULL, 0, "User ID", HFILL }},
265                 { &hf_pcnfsd_gid, {
266                         "Group ID", "pcnfsd.gid", FT_UINT32, BASE_DEC,
267                         NULL, 0, "Group ID", HFILL }},
268                 { &hf_pcnfsd_gids_count, {
269                         "Group ID Count", "pcnfsd.gids.count", FT_UINT32, BASE_DEC,
270                         NULL, 0, "Group ID Count", HFILL }},
271                 { &hf_pcnfsd_homedir, {
272                         "Home Directory", "pcnfsd.homedir", FT_STRING, BASE_DEC,
273                         NULL, 0, "Home Directory", HFILL }},
274                 { &hf_pcnfsd_def_umask, {
275                         "def_umask", "pcnfsd.def_umask", FT_INT32, BASE_OCT,
276                         NULL, 0, "def_umask", HFILL }},
277         };
278
279         static gint *ett[] = {
280                 &ett_pcnfsd,
281                 &ett_pcnfsd_auth_ident,
282                 &ett_pcnfsd_auth_password,
283                 &ett_pcnfsd_gids
284         };
285
286         proto_pcnfsd = proto_register_protocol("PC NFS",
287             "PCNFSD", "pcnfsd");
288         proto_register_field_array(proto_pcnfsd, hf, array_length(hf));
289         proto_register_subtree_array(ett, array_length(ett));
290 }
291
292 void
293 proto_reg_handoff_pcnfsd(void)
294 {
295         /* Register the protocol as RPC */
296         rpc_init_prog(proto_pcnfsd, PCNFSD_PROGRAM, ett_pcnfsd);
297         /* Register the procedure tables */
298         rpc_init_proc_table(PCNFSD_PROGRAM, 1, pcnfsd1_proc);
299         rpc_init_proc_table(PCNFSD_PROGRAM, 2, pcnfsd2_proc);
300 }
301