Fix typos and spelling (mostly in text strings)
[obnox/wireshark/wip.git] / epan / dissectors / packet-pcnfsd.c
1 /* packet-pcnfsd.c
2  * Routines for PCNFSD dissection
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
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 #include <string.h>
39
40 #include "packet-rpc.h"
41 #include "packet-pcnfsd.h"
42
43 static int proto_pcnfsd = -1;
44 static int hf_pcnfsd_procedure_v1 = -1;
45 static int hf_pcnfsd_procedure_v2 = -1;
46 static int hf_pcnfsd_auth_client = -1;
47 static int hf_pcnfsd_auth_ident_obscure = -1;
48 static int hf_pcnfsd_auth_ident_clear = -1;
49 static int hf_pcnfsd_auth_password_obscure = -1;
50 static int hf_pcnfsd_auth_password_clear = -1;
51 static int hf_pcnfsd_comment = -1;
52 static int hf_pcnfsd_status = -1;
53 static int hf_pcnfsd_uid = -1;
54 static int hf_pcnfsd_gid = -1;
55 static int hf_pcnfsd_gids_count = -1;
56 static int hf_pcnfsd_homedir = -1;
57 static int hf_pcnfsd_def_umask = -1;
58 static int hf_pcnfsd_username = -1;
59
60
61 static gint ett_pcnfsd = -1;
62 static gint ett_pcnfsd_auth_ident = -1;
63 static gint ett_pcnfsd_auth_password = -1;
64 static gint ett_pcnfsd_gids = -1;
65
66 static int
67 dissect_pcnfsd_username(tvbuff_t *tvb, int offset, proto_tree *tree)
68 {
69         return dissect_rpc_string(tvb, tree, hf_pcnfsd_username, offset, NULL);
70 }
71
72 #define MAP_REQ_UID             0
73 #define MAP_REQ_GID             1
74 #define MAP_REQ_UNAME   2
75 #define MAP_REQ_GNAME   3
76
77 static const value_string names_mapreq[] =
78 {
79         {       MAP_REQ_UID,    "MAP_REQ_UID"   },
80         {       MAP_REQ_GID,    "MAP_REQ_GID"   },
81         {       MAP_REQ_UNAME,  "MAP_REQ_UNAME" },
82         {       MAP_REQ_GNAME,  "MAP_REQ_GNAME" },
83         {       0,      NULL    }
84 };
85
86 static int
87 dissect_pcnfsd_mapreq(tvbuff_t *tvb, int offset, proto_tree *tree)
88 {
89         guint32 mapreq;
90
91         mapreq = tvb_get_ntohl(tvb, offset + 0);
92
93         if (tree)
94                 proto_tree_add_text(tree, tvb, offset, 4, "Request: %s (%u)",
95                         val_to_str(mapreq, names_mapreq, "%u"), mapreq);
96
97         offset += 4;
98
99         return offset;
100 }
101
102 static int
103 dissect_pcnfsd2_dissect_mapreq_arg_item(tvbuff_t *tvb, int offset,
104         packet_info *pinfo _U_, proto_tree *tree)
105 {
106         offset = dissect_pcnfsd_mapreq(tvb, offset, tree);
107
108         offset = dissect_rpc_uint32(tvb, tree, hf_pcnfsd_uid, offset);
109
110         offset = dissect_pcnfsd_username(tvb, offset, tree);
111
112         return offset;
113 }
114
115 static int
116 dissect_pcnfsd2_mapid_call(tvbuff_t *tvb, int offset, packet_info *pinfo,
117         proto_tree *tree)
118 {
119         offset = dissect_rpc_string(tvb, tree, hf_pcnfsd_comment, offset, NULL);
120
121         offset = dissect_rpc_list(tvb, pinfo, tree, offset,
122                 dissect_pcnfsd2_dissect_mapreq_arg_item);
123
124         return offset;
125 }
126
127 #define MAP_RES_OK              0
128 #define MAP_RES_UNKNOWN 1
129 #define MAP_RES_DENIED  2
130
131 static const value_string names_maprstat[] =
132 {
133         {       MAP_RES_OK,     "MAP_RES_OK"    },
134         {       MAP_RES_UNKNOWN,        "MAP_RES_UNKNOWN"       },
135         {       MAP_RES_DENIED, "MAP_RES_DENIED"        },
136         {       0,      NULL    }
137 };
138
139 static int
140 dissect_pcnfsd2_dissect_mapreq_res_item(tvbuff_t *tvb, int offset,
141         packet_info *pinfo _U_, proto_tree *tree)
142 {
143         guint32 maprstat;
144
145         offset = dissect_pcnfsd_mapreq(tvb, offset, tree);
146
147         maprstat = tvb_get_ntohl(tvb, offset + 0);
148
149         if (tree)
150                 proto_tree_add_text(tree, tvb, offset, 4, "Status: %s (%u)",
151                         val_to_str(maprstat, names_maprstat, "%u"), maprstat);
152
153         offset += 4;
154
155         offset = dissect_rpc_uint32(tvb, tree, hf_pcnfsd_uid, offset);
156
157         offset = dissect_pcnfsd_username(tvb, offset, tree);
158
159         return offset;
160 }
161
162 static int
163 dissect_pcnfsd2_mapid_reply(tvbuff_t *tvb, int offset, packet_info *pinfo,
164         proto_tree *tree)
165 {
166         offset = dissect_rpc_string(tvb, tree, hf_pcnfsd_comment, offset, NULL);
167
168         offset = dissect_rpc_list(tvb, pinfo, tree, offset,
169                 dissect_pcnfsd2_dissect_mapreq_res_item);
170
171         return offset;
172 }
173
174 /* "NFS Illustrated 14.7.13 */
175 static void
176 pcnfsd_decode_obscure(char* data, int len)
177 {
178         for ( ; len>0 ; len--, data++) {
179                 *data = (*data ^ 0x5b) & 0x7f;
180         }
181 }
182
183
184 /* "NFS Illustrated" 14.7.13 */
185 static int
186 dissect_pcnfsd2_auth_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
187         proto_tree *tree)
188 {
189         int     newoffset;
190         char    *ident = NULL;
191         proto_item      *ident_item = NULL;
192         proto_tree      *ident_tree = NULL;
193         char    *password = NULL;
194         proto_item      *password_item = NULL;
195         proto_tree      *password_tree = NULL;
196
197         offset = dissect_rpc_string(tvb, tree,
198                 hf_pcnfsd_auth_client, offset, NULL);
199
200         if (tree) {
201                 ident_item = proto_tree_add_text(tree, tvb,
202                                 offset, -1, "Authentication Ident");
203                 if (ident_item)
204                         ident_tree = proto_item_add_subtree(
205                                 ident_item, ett_pcnfsd_auth_ident);
206         }
207         newoffset = dissect_rpc_string(tvb, ident_tree,
208                 hf_pcnfsd_auth_ident_obscure, offset, &ident);
209         if (ident_item) {
210                 proto_item_set_len(ident_item, newoffset-offset);
211         }
212
213         if (ident) {
214                 pcnfsd_decode_obscure(ident, strlen(ident));
215                 if (ident_tree)
216                         proto_tree_add_string(ident_tree,
217                                 hf_pcnfsd_auth_ident_clear,
218                                 tvb, offset+4, strlen(ident), ident);
219         }
220         if (ident_item) {
221                 proto_item_set_text(ident_item, "Authentication Ident: %s",
222                         ident);
223         }
224
225         offset = newoffset;
226
227         if (tree) {
228                 password_item = proto_tree_add_text(tree, tvb,
229                                 offset, -1, "Authentication Password");
230                 if (password_item)
231                         password_tree = proto_item_add_subtree(
232                                 password_item, ett_pcnfsd_auth_password);
233         }
234         newoffset = dissect_rpc_string(tvb, password_tree,
235                 hf_pcnfsd_auth_password_obscure, offset, &password);
236         if (password_item) {
237                 proto_item_set_len(password_item, newoffset-offset);
238         }
239
240         if (password) {
241                 pcnfsd_decode_obscure(password, strlen(password));
242                 if (password_tree)
243                         proto_tree_add_string(password_tree,
244                                 hf_pcnfsd_auth_password_clear,
245                                 tvb, offset+4, strlen(password), password);
246         }
247         if (password_item) {
248                 proto_item_set_text(password_item, "Authentication Password: %s",
249                         password);
250         }
251
252         offset = newoffset;
253
254         offset = dissect_rpc_string(tvb, tree,
255                 hf_pcnfsd_comment, offset, NULL);
256
257         return offset;
258 }
259
260
261 /* "NFS Illustrated" 14.7.13 */
262 static int
263 dissect_pcnfsd2_auth_reply(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
264         proto_tree *tree)
265 {
266         int     gids_count;
267         proto_item      *gitem = NULL;
268         proto_tree      *gtree = NULL;
269         int     gids_i;
270
271         offset = dissect_rpc_uint32(tvb, tree, hf_pcnfsd_status, offset);
272         offset = dissect_rpc_uint32(tvb, tree, hf_pcnfsd_uid, offset);
273         offset = dissect_rpc_uint32(tvb, tree, hf_pcnfsd_gid, offset);
274         gids_count = tvb_get_ntohl(tvb,offset+0);
275         if (tree) {
276                 gitem = proto_tree_add_text(tree, tvb,
277                         offset, 4+gids_count*4, "Group IDs: %d", gids_count);
278                 gtree = proto_item_add_subtree(gitem, ett_pcnfsd_gids);
279         }
280         if (gtree) {
281                 proto_tree_add_item(gtree, hf_pcnfsd_gids_count, tvb, offset, 4, FALSE);
282         }
283         offset += 4;
284         for (gids_i = 0 ; gids_i < gids_count ; gids_i++) {
285                 offset = dissect_rpc_uint32(tvb, gtree,
286                                 hf_pcnfsd_gid, offset);
287         }
288         offset = dissect_rpc_string(tvb, tree,
289                 hf_pcnfsd_homedir, offset, NULL);
290         /* should be signed int32 */
291         offset = dissect_rpc_uint32(tvb, tree, hf_pcnfsd_def_umask, offset);
292         offset = dissect_rpc_string(tvb, tree,
293                 hf_pcnfsd_comment, offset, NULL);
294
295         return offset;
296 }
297
298
299 /* "NFS Illustrated", 14.6 */
300 /* proc number, "proc name", dissect_request, dissect_reply */
301 /* NULL as function pointer means: type of arguments is "void". */
302 static const vsff pcnfsd1_proc[] = {
303         { 0,    "NULL",         NULL,                           NULL },
304         { 1,    "AUTH",         NULL,                           NULL },
305         { 2,    "PR_INIT",      NULL,                           NULL },
306         { 3,    "PR_START",     NULL,                           NULL },
307         { 0,    NULL,           NULL,                           NULL }
308 };
309 static const value_string pcnfsd1_proc_vals[] = {
310         { 0,    "NULL" },
311         { 1,    "AUTH" },
312         { 2,    "PR_INIT" },
313         { 3,    "PR_START" },
314         { 0,    NULL }
315 };
316 /* end of PCNFS version 1 */
317
318
319 /* "NFS Illustrated", 14.7 */
320 static const vsff pcnfsd2_proc[] = {
321         { 0,    "NULL",         NULL,                           NULL },
322         { 1,    "INFO",         NULL,                           NULL },
323         { 2,    "PR_INIT",      NULL,                           NULL },
324         { 3,    "PR_START",     NULL,                           NULL },
325         { 4,    "PR_LIST",      NULL,                           NULL },
326         { 5,    "PR_QUEUE",     NULL,                           NULL },
327         { 6,    "PR_STATUS",    NULL,                           NULL },
328         { 7,    "PR_CANCEL",    NULL,                           NULL },
329         { 8,    "PR_ADMIN",     NULL,                           NULL },
330         { 9,    "PR_REQUEUE",   NULL,                           NULL },
331         { 10,   "PR_HOLD",      NULL,                           NULL },
332         { 11,   "PR_RELEASE",   NULL,                           NULL },
333         { 12,   "MAPID",
334         dissect_pcnfsd2_mapid_call, dissect_pcnfsd2_mapid_reply },
335         { 13,   "AUTH",
336         dissect_pcnfsd2_auth_call,      dissect_pcnfsd2_auth_reply },
337         { 14,   "ALERT",        NULL,                           NULL },
338         { 0,    NULL,           NULL,                           NULL }
339 };
340 static const value_string pcnfsd2_proc_vals[] = {
341         { 0,    "NULL" },
342         { 1,    "INFO" },
343         { 2,    "PR_INIT" },
344         { 3,    "PR_START" },
345         { 4,    "PR_LIST" },
346         { 5,    "PR_QUEUE" },
347         { 6,    "PR_STATUS" },
348         { 7,    "PR_CANCEL" },
349         { 8,    "PR_ADMIN" },
350         { 9,    "PR_REQUEUE" },
351         { 10,   "PR_HOLD" },
352         { 11,   "PR_RELEASE" },
353         { 12,   "MAPID" },
354         { 13,   "AUTH" },
355         { 14,   "ALERT" },
356         { 0,    NULL }
357 };
358 /* end of PCNFS version 2 */
359
360
361 void
362 proto_register_pcnfsd(void)
363 {
364         static hf_register_info hf[] = {
365                 { &hf_pcnfsd_procedure_v1, {
366                         "V1 Procedure", "pcnfsd.procedure_v1", FT_UINT32, BASE_DEC,
367                         VALS(pcnfsd1_proc_vals), 0, "V1 Procedure", HFILL }},
368                 { &hf_pcnfsd_procedure_v2, {
369                         "V2 Procedure", "pcnfsd.procedure_v2", FT_UINT32, BASE_DEC,
370                         VALS(pcnfsd2_proc_vals), 0, "V2 Procedure", HFILL }},
371                 { &hf_pcnfsd_auth_client, {
372                         "Authentication Client", "pcnfsd.auth.client", FT_STRING, BASE_DEC,
373                         NULL, 0, "Authentication Client", HFILL }},
374                 { &hf_pcnfsd_auth_ident_obscure, {
375                         "Obscure Ident", "pcnfsd.auth.ident.obscure", FT_STRING, BASE_DEC,
376                         NULL, 0, "Authentication Obscure Ident", HFILL }},
377                 { &hf_pcnfsd_auth_ident_clear, {
378                         "Clear Ident", "pcnfsd.auth.ident.clear", FT_STRING, BASE_DEC,
379                         NULL, 0, "Authentication Clear Ident", HFILL }},
380                 { &hf_pcnfsd_auth_password_obscure, {
381                         "Obscure Password", "pcnfsd.auth.password.obscure", FT_STRING, BASE_DEC,
382                         NULL, 0, "Authentication Obscure Password", HFILL }},
383                 { &hf_pcnfsd_auth_password_clear, {
384                         "Clear Password", "pcnfsd.auth.password.clear", FT_STRING, BASE_DEC,
385                         NULL, 0, "Authentication Clear Password", HFILL }},
386                 { &hf_pcnfsd_comment, {
387                         "Comment", "pcnfsd.comment", FT_STRING, BASE_DEC,
388                         NULL, 0, "Comment", HFILL }},
389                 { &hf_pcnfsd_status, {
390                         "Reply Status", "pcnfsd.status", FT_UINT32, BASE_DEC,
391                         NULL, 0, "Status", HFILL }},
392                 { &hf_pcnfsd_uid, {
393                         "User ID", "pcnfsd.uid", FT_UINT32, BASE_DEC,
394                         NULL, 0, "User ID", HFILL }},
395                 { &hf_pcnfsd_gid, {
396                         "Group ID", "pcnfsd.gid", FT_UINT32, BASE_DEC,
397                         NULL, 0, "Group ID", HFILL }},
398                 { &hf_pcnfsd_gids_count, {
399                         "Group ID Count", "pcnfsd.gids.count", FT_UINT32, BASE_DEC,
400                         NULL, 0, "Group ID Count", HFILL }},
401                 { &hf_pcnfsd_homedir, {
402                         "Home Directory", "pcnfsd.homedir", FT_STRING, BASE_DEC,
403                         NULL, 0, "Home Directory", HFILL }},
404                 { &hf_pcnfsd_def_umask, {
405                         "def_umask", "pcnfsd.def_umask", FT_UINT32, BASE_OCT,
406                         NULL, 0, "def_umask", HFILL }},
407                 { &hf_pcnfsd_username, {
408                         "User name", "pcnfsd.username", FT_STRING, BASE_DEC,
409                         NULL, 0, "pcnfsd.username", HFILL }},
410         };
411
412         static gint *ett[] = {
413                 &ett_pcnfsd,
414                 &ett_pcnfsd_auth_ident,
415                 &ett_pcnfsd_auth_password,
416                 &ett_pcnfsd_gids
417         };
418
419         proto_pcnfsd = proto_register_protocol("PC NFS",
420             "PCNFSD", "pcnfsd");
421         proto_register_field_array(proto_pcnfsd, hf, array_length(hf));
422         proto_register_subtree_array(ett, array_length(ett));
423 }
424
425 void
426 proto_reg_handoff_pcnfsd(void)
427 {
428         /* Register the protocol as RPC */
429         rpc_init_prog(proto_pcnfsd, PCNFSD_PROGRAM, ett_pcnfsd);
430         /* Register the procedure tables */
431         rpc_init_proc_table(PCNFSD_PROGRAM, 1, pcnfsd1_proc, hf_pcnfsd_procedure_v1);
432         rpc_init_proc_table(PCNFSD_PROGRAM, 2, pcnfsd2_proc, hf_pcnfsd_procedure_v2);
433 }
434