Add support for SNA-over-X.25. Add QLLC dissector. I still need to
[obnox/wireshark/wip.git] / packet-pcnfsd.c
1 /* packet-pcnfsd.c
2  * Routines for PCNFSD dissection
3  *
4  * $Id: packet-pcnfsd.c,v 1.3 2001/11/07 07:05:58 girlich Exp $
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@zing.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
39 #ifdef HAVE_SYS_TYPES_H
40 #include <sys/types.h>
41 #endif
42
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, tvb_length_remaining(tvb, offset),
97                                 "Authentication Ident");
98                 if (ident_item)
99                         ident_tree = proto_item_add_subtree(
100                                 ident_item, ett_pcnfsd_auth_ident);
101         }
102         newoffset = dissect_rpc_string(tvb, pinfo, ident_tree,
103                 hf_pcnfsd_auth_ident_obscure, offset, &ident);
104         if (ident_item) {
105                 proto_item_set_len(ident_item, newoffset-offset);
106         }
107         
108         if (ident) {
109                 pcnfsd_decode_obscure(ident, strlen(ident));
110                 if (ident_tree)
111                         proto_tree_add_string(ident_tree,
112                                 hf_pcnfsd_auth_ident_clear,
113                                 tvb, offset+4, strlen(ident), ident);
114         }
115         if (ident_item) {
116                 proto_item_set_text(ident_item, "Authentication Ident: %s",
117                         ident);
118         }
119         if (ident) {
120                 g_free(ident);
121                 ident = NULL;
122         }
123
124         offset = newoffset;
125
126         if (tree) {
127                 password_item = proto_tree_add_text(tree, tvb,
128                                 offset, tvb_length_remaining(tvb, offset),
129                                 "Authentication Password");
130                 if (password_item)
131                         password_tree = proto_item_add_subtree(
132                                 password_item, ett_pcnfsd_auth_password);
133         }
134         newoffset = dissect_rpc_string(tvb, pinfo, password_tree,
135                 hf_pcnfsd_auth_password_obscure, offset, &password);
136         if (password_item) {
137                 proto_item_set_len(password_item, newoffset-offset);
138         }
139         
140         if (password) {
141                 pcnfsd_decode_obscure(password, strlen(password));
142                 if (password_tree)
143                         proto_tree_add_string(password_tree,
144                                 hf_pcnfsd_auth_password_clear,
145                                 tvb, offset+4, strlen(password), password);
146         }
147         if (password_item) {
148                 proto_item_set_text(password_item, "Authentication Password: %s",
149                         password);
150         }
151         if (password) {
152                 g_free(password);
153                 password = NULL;
154         }
155
156         offset = newoffset;
157
158         offset = dissect_rpc_string(tvb, pinfo, tree,
159                 hf_pcnfsd_comment, offset, NULL);
160
161         return offset;
162 }
163
164
165 /* "NFS Illustrated" 14.7.13 */
166 int
167 dissect_pcnfsd2_auth_reply(tvbuff_t *tvb, int offset, packet_info *pinfo,
168         proto_tree *tree)
169 {
170         int     gids_count;
171         proto_item      *gitem = NULL;
172         proto_tree      *gtree = NULL;
173         int     gids_i;
174
175         offset = dissect_rpc_uint32(tvb, pinfo, tree, hf_pcnfsd_status, offset);
176         offset = dissect_rpc_uint32(tvb, pinfo, tree, hf_pcnfsd_uid, offset);
177         offset = dissect_rpc_uint32(tvb, pinfo, tree, hf_pcnfsd_gid, offset);
178         gids_count = tvb_get_ntohl(tvb,offset+0);
179         if (tree) {
180                 gitem = proto_tree_add_text(tree, tvb,
181                         offset, 4+gids_count*4, "Group IDs: %d", gids_count);
182                 gtree = proto_item_add_subtree(gitem, ett_pcnfsd_gids);
183         }
184         if (gtree) {
185                 proto_tree_add_item(gtree, hf_pcnfsd_gids_count, tvb, offset, 4, FALSE);
186         }
187         offset += 4;
188         for (gids_i = 0 ; gids_i < gids_count ; gids_i++) {
189                 offset = dissect_rpc_uint32(tvb, pinfo, gtree,
190                                 hf_pcnfsd_gid, offset);
191         }
192         offset = dissect_rpc_string(tvb, pinfo, tree,
193                 hf_pcnfsd_homedir, offset, NULL);
194         /* should be signed int32 */
195         offset = dissect_rpc_uint32(tvb, pinfo, tree, hf_pcnfsd_def_umask, offset);
196         offset = dissect_rpc_string(tvb, pinfo, tree,
197                 hf_pcnfsd_comment, offset, NULL);
198
199         return offset;
200 }
201
202
203 /* "NFS Illustrated", 14.6 */
204 /* proc number, "proc name", dissect_request, dissect_reply */
205 /* NULL as function pointer means: type of arguments is "void". */
206 static const vsff pcnfsd1_proc[] = {
207         { 0,    "NULL",         NULL,                           NULL },
208         { 1,    "AUTH",         NULL,                           NULL },
209         { 2,    "PR_INIT",      NULL,                           NULL },
210         { 3,    "PR_START",     NULL,                           NULL },
211         { 0,    NULL,           NULL,                           NULL }
212 };
213 /* end of PCNFS version 1 */
214
215
216 /* "NFS Illustrated", 14.7 */
217 static const vsff pcnfsd2_proc[] = {
218         { 0,    "NULL",         NULL,                           NULL },
219         { 1,    "INFO",         NULL,                           NULL },
220         { 2,    "PR_INIT",      NULL,                           NULL },
221         { 3,    "PR_START",     NULL,                           NULL },
222         { 4,    "PR_LIST",      NULL,                           NULL },
223         { 5,    "PR_QUEUE",     NULL,                           NULL },
224         { 6,    "PR_STATUS",    NULL,                           NULL },
225         { 7,    "PR_CANCEL",    NULL,                           NULL },
226         { 8,    "PR_ADMIN",     NULL,                           NULL },
227         { 9,    "PR_REQUEUE",   NULL,                           NULL },
228         { 10,   "PR_HOLD",      NULL,                           NULL },
229         { 11,   "PR_RELEASE",   NULL,                           NULL },
230         { 12,   "MAPID",        NULL,                           NULL },
231         { 13,   "AUTH",         
232         dissect_pcnfsd2_auth_call,      dissect_pcnfsd2_auth_reply },
233         { 14,   "ALERT",        NULL,                           NULL },
234         { 0,    NULL,           NULL,                           NULL }
235 };
236 /* end of PCNFS version 2 */
237
238
239 void
240 proto_register_pcnfsd(void)
241 {
242         static hf_register_info hf[] = {
243                 { &hf_pcnfsd_auth_client, {
244                         "Authentication Client", "pcnfsd.auth.client", FT_STRING, BASE_DEC,
245                         NULL, 0, "Authentication Client", HFILL }},
246                 { &hf_pcnfsd_auth_ident_obscure, {
247                         "Obscure Ident", "pcnfsd.auth.ident.obscure", FT_STRING, BASE_DEC,
248                         NULL, 0, "Athentication Obscure Ident", HFILL }},
249                 { &hf_pcnfsd_auth_ident_clear, {
250                         "Clear Ident", "pcnfsd.auth.ident.clear", FT_STRING, BASE_DEC,
251                         NULL, 0, "Authentication Clear Ident", HFILL }},
252                 { &hf_pcnfsd_auth_password_obscure, {
253                         "Obscure Password", "pcnfsd.auth.password.obscure", FT_STRING, BASE_DEC,
254                         NULL, 0, "Athentication Obscure Password", HFILL }},
255                 { &hf_pcnfsd_auth_password_clear, {
256                         "Clear Password", "pcnfsd.auth.password.clear", FT_STRING, BASE_DEC,
257                         NULL, 0, "Authentication Clear Password", HFILL }},
258                 { &hf_pcnfsd_comment, {
259                         "Comment", "pcnfsd.comment", FT_STRING, BASE_DEC,
260                         NULL, 0, "Comment", HFILL }},
261                 { &hf_pcnfsd_status, {
262                         "Reply Status", "pcnfsd.status", FT_UINT32, BASE_DEC,
263                         NULL, 0, "Status", HFILL }},
264                 { &hf_pcnfsd_uid, {
265                         "User ID", "pcnfsd.uid", FT_UINT32, BASE_DEC,
266                         NULL, 0, "User ID", HFILL }},
267                 { &hf_pcnfsd_gid, {
268                         "Group ID", "pcnfsd.gid", FT_UINT32, BASE_DEC,
269                         NULL, 0, "Group ID", HFILL }},
270                 { &hf_pcnfsd_gids_count, {
271                         "Group ID Count", "pcnfsd.gids.count", FT_UINT32, BASE_DEC,
272                         NULL, 0, "Group ID Count", HFILL }},
273                 { &hf_pcnfsd_homedir, {
274                         "Home Directory", "pcnfsd.homedir", FT_STRING, BASE_DEC,
275                         NULL, 0, "Home Directory", HFILL }},
276                 { &hf_pcnfsd_def_umask, {
277                         "def_umask", "pcnfsd.def_umask", FT_INT32, BASE_OCT,
278                         NULL, 0, "def_umask", HFILL }},
279         };
280
281         static gint *ett[] = {
282                 &ett_pcnfsd,
283                 &ett_pcnfsd_auth_ident,
284                 &ett_pcnfsd_auth_password,
285                 &ett_pcnfsd_gids
286         };
287
288         proto_pcnfsd = proto_register_protocol("PC NFS",
289             "PCNFSD", "pcnfsd");
290         proto_register_field_array(proto_pcnfsd, hf, array_length(hf));
291         proto_register_subtree_array(ett, array_length(ett));
292 }
293
294 void
295 proto_reg_handoff_pcnfsd(void)
296 {
297         /* Register the protocol as RPC */
298         rpc_init_prog(proto_pcnfsd, PCNFSD_PROGRAM, ett_pcnfsd);
299         /* Register the procedure tables */
300         rpc_init_proc_table(PCNFSD_PROGRAM, 1, pcnfsd1_proc);
301         rpc_init_proc_table(PCNFSD_PROGRAM, 2, pcnfsd2_proc);
302 }
303