From Ronnie Sahlberg:
[obnox/wireshark/wip.git] / packet-yppasswd.c
1 /* packet-yppasswd.c
2  * Routines for yppasswd dissection
3  *
4  * $Id: packet-yppasswd.c,v 1.5 2002/01/24 09:20:54 guy Exp $
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@ethereal.com>
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 #ifdef HAVE_SYS_TYPES_H
31 #include <sys/types.h>
32 #endif
33
34
35 #include "packet-rpc.h"
36 #include "packet-yppasswd.h"
37
38 static int proto_yppasswd = -1;
39 static int hf_yppasswd_status = -1;
40 static int hf_yppasswd_oldpass = -1;
41 static int hf_yppasswd_newpw = -1;
42 static int hf_yppasswd_newpw_name = -1;
43 static int hf_yppasswd_newpw_passwd = -1;
44 static int hf_yppasswd_newpw_uid = -1;
45 static int hf_yppasswd_newpw_gid = -1;
46 static int hf_yppasswd_newpw_gecos = -1;
47 static int hf_yppasswd_newpw_dir = -1;
48 static int hf_yppasswd_newpw_shell = -1;
49
50 static gint ett_yppasswd = -1;
51 static gint ett_yppasswd_newpw = -1;
52
53 static int
54 dissect_yppasswd_call(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
55 {
56         proto_item *lock_item = NULL;
57         proto_tree *lock_tree = NULL;
58
59         offset = dissect_rpc_string(tvb, pinfo, tree, hf_yppasswd_oldpass, 
60                         offset, NULL);
61
62         lock_item = proto_tree_add_item(tree, hf_yppasswd_newpw, tvb,
63                         offset, -1, FALSE);
64
65         lock_tree = proto_item_add_subtree(lock_item, ett_yppasswd_newpw);
66
67         offset = dissect_rpc_string(tvb, pinfo, lock_tree, 
68                         hf_yppasswd_newpw_name, offset, NULL);
69         offset = dissect_rpc_string(tvb, pinfo, lock_tree, 
70                         hf_yppasswd_newpw_passwd, offset, NULL);
71         offset = dissect_rpc_uint32(tvb, pinfo, lock_tree, 
72                         hf_yppasswd_newpw_uid, offset);
73         offset = dissect_rpc_uint32(tvb, pinfo, lock_tree, 
74                         hf_yppasswd_newpw_gid, offset);
75         offset = dissect_rpc_string(tvb, pinfo, lock_tree, 
76                         hf_yppasswd_newpw_gecos, offset, NULL);
77         offset = dissect_rpc_string(tvb, pinfo, lock_tree, 
78                         hf_yppasswd_newpw_dir, offset, NULL);
79         offset = dissect_rpc_string(tvb, pinfo, lock_tree, 
80                         hf_yppasswd_newpw_shell, offset, NULL);
81
82         return offset;
83 }
84
85 static int
86 dissect_yppasswd_reply(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
87 {
88         offset = dissect_rpc_uint32(tvb, pinfo, tree, hf_yppasswd_status, offset);
89
90         return offset;
91 }
92
93 /* proc number, "proc name", dissect_request, dissect_reply */
94 /* NULL as function pointer means: type of arguments is "void". */
95 static const vsff yppasswd1_proc[] = {
96         { YPPASSWDPROC_UPDATE,  "UPDATE",
97                 dissect_yppasswd_call,  dissect_yppasswd_reply },
98         { 0,    NULL,           NULL,                           NULL }
99 };
100
101 void
102 proto_register_yppasswd(void)
103 {
104         static hf_register_info hf[] = {
105                 { &hf_yppasswd_status, {
106                         "status", "yppasswd.status", FT_UINT32, BASE_DEC,
107                         NULL, 0, "YPPasswd update status", HFILL }},
108
109                 { &hf_yppasswd_oldpass, {
110                         "oldpass", "yppasswd.oldpass", FT_STRING, BASE_DEC,
111                         NULL, 0, "Old encrypted password", HFILL }},
112
113                 { &hf_yppasswd_newpw, {
114                         "newpw", "yppasswd.newpw", FT_NONE, 0,
115                         NULL, 0, "New passwd entry", HFILL }},
116
117                 { &hf_yppasswd_newpw_name, {
118                         "name", "yppasswd.newpw.name", FT_STRING, BASE_DEC,
119                         NULL, 0, "Username", HFILL }},
120
121                 { &hf_yppasswd_newpw_passwd, {
122                         "passwd", "yppasswd.newpw.passwd", FT_STRING, BASE_DEC,
123                         NULL, 0, "Encrypted passwd", HFILL }},
124
125                 { &hf_yppasswd_newpw_uid, {
126                         "uid", "yppasswd.newpw.uid", FT_UINT32, BASE_DEC,
127                         NULL, 0, "UserID", HFILL }},
128
129                 { &hf_yppasswd_newpw_gid, {
130                         "gid", "yppasswd.newpw.gid", FT_UINT32, BASE_DEC,
131                         NULL, 0, "GroupID", HFILL }},
132
133                 { &hf_yppasswd_newpw_gecos, {
134                         "gecos", "yppasswd.newpw.gecos", FT_STRING, BASE_DEC,
135                         NULL, 0, "In real life name", HFILL }},
136
137                 { &hf_yppasswd_newpw_dir, {
138                         "dir", "yppasswd.newpw.dir", FT_STRING, BASE_DEC,
139                         NULL, 0, "Home Directory", HFILL }},
140
141                 { &hf_yppasswd_newpw_shell, {
142                         "shell", "yppasswd.newpw.shell", FT_STRING, BASE_DEC,
143                         NULL, 0, "Default shell", HFILL }},
144
145         };
146
147         static gint *ett[] = {
148                 &ett_yppasswd,
149                 &ett_yppasswd_newpw,
150         };
151
152         proto_yppasswd = proto_register_protocol("Yellow Pages Passwd",
153             "YPPASSWD", "yppasswd");
154         proto_register_field_array(proto_yppasswd, hf, array_length(hf));
155         proto_register_subtree_array(ett, array_length(ett));
156 }
157
158 void
159 proto_reg_handoff_yppasswd(void)
160 {
161         /* Register the protocol as RPC */
162         rpc_init_prog(proto_yppasswd, YPPASSWD_PROGRAM, ett_yppasswd);
163         /* Register the procedure tables */
164         rpc_init_proc_table(YPPASSWD_PROGRAM, 1, yppasswd1_proc);
165 }
166