Implement plugins status save/restore :
[obnox/wireshark/wip.git] / packet-tacacs.c
1 /* packet-tacacs.c
2  * Routines for cisco tacacs/tacplus/AAA packet dissection
3  *
4  * $Id: packet-tacacs.c,v 1.1 1999/12/03 21:50:29 nneul Exp $
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@unicom.net>
8  * Copyright 1998 Gerald Combs
9  *
10  * Copied from packet-tftp.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 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #include <stdio.h>
32
33 #ifdef HAVE_SYS_TYPES_H
34 # include <sys/types.h>
35 #endif
36
37 #ifdef HAVE_NETINET_IN_H
38 # include <netinet/in.h>
39 #endif
40
41 #include <string.h>
42 #include <glib.h>
43 #include "packet.h"
44
45 static int proto_tacacs = -1;
46 static int hf_tacacs_request = -1;
47 static int hf_tacacs_response = -1;
48 static int hf_tacacs_version = -1;
49
50 static gint ett_tacacs = -1;
51
52 void
53 dissect_tacacs(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
54 {
55         proto_tree      *tacacs_tree, *ti;
56
57         if (check_col(fd, COL_PROTOCOL))
58         col_add_str(fd, COL_PROTOCOL, "TACACS");
59
60         if (check_col(fd, COL_INFO))
61         {
62                 col_add_fstr(fd, COL_INFO, "%s", 
63                         (pi.match_port == pi.destport) ? "Request" : "Response");         
64         }
65
66         if (tree) 
67         {
68                 ti = proto_tree_add_item(tree, proto_tacacs, offset, END_OF_FRAME, NULL);
69                 tacacs_tree = proto_item_add_subtree(ti, ett_tacacs);
70
71                 proto_tree_add_item(tacacs_tree, hf_tacacs_version, 0, 0, "XTacacs");
72
73                 if (pi.match_port == pi.destport)
74                 {
75                         proto_tree_add_item_hidden(tacacs_tree, hf_tacacs_request,
76                                                    offset, END_OF_FRAME, TRUE);
77                         proto_tree_add_text(tacacs_tree, offset, 
78                                 END_OF_FRAME, "Request: <opaque data>" );
79                 }
80                 else
81                 {
82                         proto_tree_add_item_hidden(tacacs_tree, hf_tacacs_response,
83                                                    offset, END_OF_FRAME, TRUE);
84                         proto_tree_add_text(tacacs_tree, offset, 
85                                 END_OF_FRAME, "Response: <opaque data>");
86                 }
87         }
88 }
89
90 void
91 dissect_tacplus(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
92 {
93         proto_tree      *tacacs_tree, *ti;
94
95         if (check_col(fd, COL_PROTOCOL))
96         col_add_str(fd, COL_PROTOCOL, "TACACS");
97
98         if (check_col(fd, COL_INFO))
99         {
100                 col_add_fstr(fd, COL_INFO, "%s", 
101                         (pi.match_port == pi.destport) ? "Request" : "Response");         
102         }
103
104         if (tree) 
105         {
106                 ti = proto_tree_add_item(tree, proto_tacacs, offset, END_OF_FRAME, NULL);
107                 tacacs_tree = proto_item_add_subtree(ti, ett_tacacs);
108
109                 proto_tree_add_item(tacacs_tree, hf_tacacs_version, 0, 0, "Tacacs+");
110
111                 if (pi.match_port == pi.destport)
112                 {
113                         proto_tree_add_item_hidden(tacacs_tree, hf_tacacs_request,
114                                                    offset, END_OF_FRAME, TRUE);
115                         proto_tree_add_text(tacacs_tree, offset, 
116                                 END_OF_FRAME, "Request: <opaque data>" );
117                 }
118                 else
119                 {
120                         proto_tree_add_item_hidden(tacacs_tree, hf_tacacs_response,
121                                                    offset, END_OF_FRAME, TRUE);
122                         proto_tree_add_text(tacacs_tree, offset, 
123                                 END_OF_FRAME, "Response: <opaque data>");
124                 }
125         }
126 }
127
128 void
129 proto_register_tacacs(void)
130 {
131         static hf_register_info hf[] = {
132           { &hf_tacacs_version,
133             { "Tacacs Version",           "tacacs.version",
134               FT_STRING, BASE_NONE, NULL, 0x0,
135               "xtacacs or tacplus" }},
136           { &hf_tacacs_response,
137             { "Response",           "tacacs.response",
138               FT_BOOLEAN, BASE_NONE, NULL, 0x0,
139               "TRUE if TACACS response" }},
140           { &hf_tacacs_request,
141             { "Request",            "tacacs.request",
142               FT_BOOLEAN, BASE_NONE, NULL, 0x0,
143               "TRUE if TACACS request" }}
144         };
145
146         static gint *ett[] = {
147                 &ett_tacacs,
148         };
149         proto_tacacs = proto_register_protocol("TACACS", "tacacs");
150         proto_register_field_array(proto_tacacs, hf, array_length(hf));
151         proto_register_subtree_array(ett, array_length(ett));
152 }