From Kovarththanan Rajaratnam via bug 3548:
[obnox/wireshark/wip.git] / epan / dissectors / packet-yppasswd.c
1 /* packet-yppasswd.c
2  * Routines for yppasswd dissection
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23  */
24
25 #ifdef HAVE_CONFIG_H
26 #include "config.h"
27 #endif
28
29
30
31 #include "packet-rpc.h"
32 #include "packet-yppasswd.h"
33
34 static int proto_yppasswd = -1;
35 static int hf_yppasswd_procedure_v1 = -1;
36 static int hf_yppasswd_status = -1;
37 static int hf_yppasswd_oldpass = -1;
38 static int hf_yppasswd_newpw = -1;
39 static int hf_yppasswd_newpw_name = -1;
40 static int hf_yppasswd_newpw_passwd = -1;
41 static int hf_yppasswd_newpw_uid = -1;
42 static int hf_yppasswd_newpw_gid = -1;
43 static int hf_yppasswd_newpw_gecos = -1;
44 static int hf_yppasswd_newpw_dir = -1;
45 static int hf_yppasswd_newpw_shell = -1;
46
47 static gint ett_yppasswd = -1;
48 static gint ett_yppasswd_newpw = -1;
49
50 static int
51 dissect_yppasswd_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
52 {
53         proto_item *lock_item = NULL;
54         proto_tree *lock_tree = NULL;
55
56         offset = dissect_rpc_string(tvb, tree, hf_yppasswd_oldpass,
57                         offset, NULL);
58
59         lock_item = proto_tree_add_item(tree, hf_yppasswd_newpw, tvb,
60                         offset, -1, FALSE);
61
62         lock_tree = proto_item_add_subtree(lock_item, ett_yppasswd_newpw);
63
64         offset = dissect_rpc_string(tvb, lock_tree,
65                         hf_yppasswd_newpw_name, offset, NULL);
66         offset = dissect_rpc_string(tvb, lock_tree,
67                         hf_yppasswd_newpw_passwd, offset, NULL);
68         offset = dissect_rpc_uint32(tvb, lock_tree,
69                         hf_yppasswd_newpw_uid, offset);
70         offset = dissect_rpc_uint32(tvb, lock_tree,
71                         hf_yppasswd_newpw_gid, offset);
72         offset = dissect_rpc_string(tvb, lock_tree,
73                         hf_yppasswd_newpw_gecos, offset, NULL);
74         offset = dissect_rpc_string(tvb, lock_tree,
75                         hf_yppasswd_newpw_dir, offset, NULL);
76         offset = dissect_rpc_string(tvb, lock_tree,
77                         hf_yppasswd_newpw_shell, offset, NULL);
78
79         return offset;
80 }
81
82 static int
83 dissect_yppasswd_reply(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
84 {
85         offset = dissect_rpc_uint32(tvb, tree, hf_yppasswd_status, offset);
86
87         return offset;
88 }
89
90 /* proc number, "proc name", dissect_request, dissect_reply */
91 /* NULL as function pointer means: type of arguments is "void". */
92 static const vsff yppasswd1_proc[] = {
93         { YPPASSWDPROC_NULL,    "NULL",
94                 NULL,           NULL },
95         { YPPASSWDPROC_UPDATE,  "UPDATE",
96                 dissect_yppasswd_call,  dissect_yppasswd_reply },
97         { 0,    NULL,           NULL,                           NULL }
98 };
99 static const value_string yppasswd1_proc_vals[] = {
100         { YPPASSWDPROC_NULL,    "NULL" },
101         { YPPASSWDPROC_UPDATE,  "UPDATE" },
102         { 0,    NULL }
103 };
104
105 void
106 proto_register_yppasswd(void)
107 {
108         static hf_register_info hf[] = {
109                 { &hf_yppasswd_procedure_v1, {
110                         "V1 Procedure", "yppasswd.procedure_v1", FT_UINT32, BASE_DEC,
111                         VALS(yppasswd1_proc_vals), 0, NULL, HFILL }},
112                 { &hf_yppasswd_status, {
113                         "status", "yppasswd.status", FT_UINT32, BASE_DEC,
114                         NULL, 0, "YPPasswd update status", HFILL }},
115
116                 { &hf_yppasswd_oldpass, {
117                         "oldpass", "yppasswd.oldpass", FT_STRING, BASE_NONE,
118                         NULL, 0, "Old encrypted password", HFILL }},
119
120                 { &hf_yppasswd_newpw, {
121                         "newpw", "yppasswd.newpw", FT_NONE, BASE_NONE,
122                         NULL, 0, "New passwd entry", HFILL }},
123
124                 { &hf_yppasswd_newpw_name, {
125                         "name", "yppasswd.newpw.name", FT_STRING, BASE_NONE,
126                         NULL, 0, "Username", HFILL }},
127
128                 { &hf_yppasswd_newpw_passwd, {
129                         "passwd", "yppasswd.newpw.passwd", FT_STRING, BASE_NONE,
130                         NULL, 0, "Encrypted passwd", HFILL }},
131
132                 { &hf_yppasswd_newpw_uid, {
133                         "uid", "yppasswd.newpw.uid", FT_UINT32, BASE_DEC,
134                         NULL, 0, "UserID", HFILL }},
135
136                 { &hf_yppasswd_newpw_gid, {
137                         "gid", "yppasswd.newpw.gid", FT_UINT32, BASE_DEC,
138                         NULL, 0, "GroupID", HFILL }},
139
140                 { &hf_yppasswd_newpw_gecos, {
141                         "gecos", "yppasswd.newpw.gecos", FT_STRING, BASE_NONE,
142                         NULL, 0, "In real life name", HFILL }},
143
144                 { &hf_yppasswd_newpw_dir, {
145                         "dir", "yppasswd.newpw.dir", FT_STRING, BASE_NONE,
146                         NULL, 0, "Home Directory", HFILL }},
147
148                 { &hf_yppasswd_newpw_shell, {
149                         "shell", "yppasswd.newpw.shell", FT_STRING, BASE_NONE,
150                         NULL, 0, "Default shell", HFILL }},
151
152         };
153
154         static gint *ett[] = {
155                 &ett_yppasswd,
156                 &ett_yppasswd_newpw,
157         };
158
159         proto_yppasswd = proto_register_protocol("Yellow Pages Passwd",
160             "YPPASSWD", "yppasswd");
161         proto_register_field_array(proto_yppasswd, hf, array_length(hf));
162         proto_register_subtree_array(ett, array_length(ett));
163 }
164
165 void
166 proto_reg_handoff_yppasswd(void)
167 {
168         /* Register the protocol as RPC */
169         rpc_init_prog(proto_yppasswd, YPPASSWD_PROGRAM, ett_yppasswd);
170         /* Register the procedure tables */
171         rpc_init_proc_table(YPPASSWD_PROGRAM, 1, yppasswd1_proc, hf_yppasswd_procedure_v1);
172 }
173