removed some gcc warnings (hopefully)
[obnox/wireshark/wip.git] / epan / dissectors / packet-kpasswd.c
1 /* packet-kpasswd.c
2  * Routines for kpasswd packet dissection
3  *    Ronnie Sahlberg 2003
4  *
5  * See RFC 3244 
6  *
7  * $Id$
8  *
9  * Ethereal - Network traffic analyzer
10  * By Gerald Combs <gerald@ethereal.com>
11  * Copyright 1998 Gerald Combs
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
26  */
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <epan/packet.h>
33 #include "packet-kerberos.h"
34 #include <epan/prefs.h>
35
36 static int proto_kpasswd = -1;
37 static int hf_kpasswd_message_len = -1;
38 static int hf_kpasswd_version = -1;
39 static int hf_kpasswd_ap_req_len = -1;
40 static int hf_kpasswd_ap_req_data = -1;
41 static int hf_kpasswd_krb_priv_message = -1;
42
43 static gint ett_kpasswd = -1;
44 static gint ett_ap_req_data = -1;
45 static gint ett_krb_priv_message = -1;
46
47
48
49 #define UDP_PORT_KPASSWD                464
50
51
52 static const value_string vers_vals[] = {
53         { 0x0001,       "Reply" },
54         { 0xff80,       "Request" },
55         { 0,    NULL },
56 };
57
58
59 static void
60 dissect_kpasswd_ap_req_data(packet_info *pinfo _U_, tvbuff_t *tvb, proto_tree *parent_tree)
61 {
62         proto_item *it;
63         proto_tree *tree=NULL;
64
65         if(parent_tree){
66                 it=proto_tree_add_item(parent_tree, hf_kpasswd_ap_req_data, tvb, 0, -1, FALSE);
67                 tree=proto_item_add_subtree(it, ett_ap_req_data);
68         }
69         dissect_kerberos_main(tvb, pinfo, tree, FALSE, NULL);
70 }
71
72 static void
73 dissect_kpasswd_krb_priv_message(packet_info *pinfo _U_, tvbuff_t *tvb, proto_tree *parent_tree)
74 {
75         proto_item *it;
76         proto_tree *tree=NULL;
77
78         if(parent_tree){
79                 it=proto_tree_add_item(parent_tree, hf_kpasswd_krb_priv_message, tvb, 0, -1, FALSE);
80                 tree=proto_item_add_subtree(it, ett_krb_priv_message);
81         }
82         dissect_kerberos_main(tvb, pinfo, tree, FALSE, NULL);
83 }
84
85
86 static void
87 dissect_kpasswd(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
88 {
89         proto_item *kpasswd_item;
90         proto_tree *kpasswd_tree=NULL;
91         int offset = 0;
92         guint16 message_len, version, ap_req_len;
93         tvbuff_t *next_tvb;
94
95         if (check_col(pinfo->cinfo, COL_PROTOCOL))
96                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "KPASSWD");
97         if (check_col(pinfo->cinfo, COL_INFO))
98                 col_clear(pinfo->cinfo, COL_INFO);
99
100         message_len=tvb_get_ntohs(tvb, offset);
101         version=tvb_get_ntohs(tvb, offset+2);
102         ap_req_len=tvb_get_ntohs(tvb, offset+4);
103         if(tree){
104                 kpasswd_item=proto_tree_add_item(tree, proto_kpasswd, tvb, offset, message_len, FALSE);
105                 kpasswd_tree=proto_item_add_subtree(kpasswd_item, ett_kpasswd);
106         }
107
108         proto_tree_add_uint(kpasswd_tree, hf_kpasswd_message_len, tvb, offset, 2, message_len);
109         proto_tree_add_uint(kpasswd_tree, hf_kpasswd_version, tvb, offset+2, 2, version);
110         if (check_col(pinfo->cinfo, COL_INFO))
111                 col_set_str(pinfo->cinfo, COL_INFO, val_to_str(version, vers_vals, "Unknown command"));
112         proto_tree_add_uint(kpasswd_tree, hf_kpasswd_ap_req_len, tvb, offset+4, 2, ap_req_len);
113         offset+=6;
114
115         /* AP_REQ data */
116         next_tvb=tvb_new_subset(tvb, offset, ap_req_len, ap_req_len);
117         dissect_kpasswd_ap_req_data(pinfo, next_tvb, kpasswd_tree);
118         offset+=ap_req_len;
119
120         /* KRB-PRIB message */
121         next_tvb=tvb_new_subset(tvb, offset, -1, -1);
122         dissect_kpasswd_krb_priv_message(pinfo, next_tvb, kpasswd_tree);
123
124 }
125
126
127 void
128 proto_register_kpasswd(void)
129 {
130         static hf_register_info hf[] = {
131         { &hf_kpasswd_message_len,
132                 { "Message Length", "kpasswd.message_len", FT_UINT16, BASE_DEC,
133                 NULL, 0, "Message Length", HFILL }},
134         { &hf_kpasswd_ap_req_len,
135                 { "AP_REQ Length", "kpasswd.ap_req_len", FT_UINT16, BASE_DEC,
136                 NULL, 0, "Length of AP_REQ data", HFILL }},
137         { &hf_kpasswd_version,
138                 { "Version", "kpasswd.version", FT_UINT16, BASE_HEX,
139                 VALS(vers_vals), 0, "Version", HFILL }},
140         { &hf_kpasswd_ap_req_data,
141                 { "AP_REQ", "kpasswd.ap_req", FT_NONE, BASE_NONE,
142                 NULL, 0, "AP_REQ structure", HFILL }},
143         { &hf_kpasswd_krb_priv_message,
144                 { "KRB-PRIV", "kpasswd.krb_priv", FT_NONE, BASE_NONE,
145                 NULL, 0, "KRB-PRIV message", HFILL }},
146         };
147
148         static gint *ett[] = {
149                 &ett_kpasswd,
150                 &ett_ap_req_data,
151                 &ett_krb_priv_message,
152         };
153
154         proto_kpasswd = proto_register_protocol("MS Kpasswd",
155                 "Kpasswd", "kpasswd");
156         proto_register_field_array(proto_kpasswd, hf, array_length(hf));
157         proto_register_subtree_array(ett, array_length(ett));
158 }
159
160 void
161 proto_reg_handoff_kpasswd(void)
162 {
163         dissector_handle_t kpasswd_handle;
164
165         kpasswd_handle = create_dissector_handle(dissect_kpasswd, proto_kpasswd);
166         dissector_add("udp.port", UDP_PORT_KPASSWD, kpasswd_handle);
167 }