name change
[obnox/wireshark/wip.git] / asn1 / dop / packet-dop-template.c
1 /* packet-dop.c
2  * Routines for X.501 (DSA Operational Attributes)  packet dissection
3  * Graeme Lunt 2005
4  *
5  * $Id$
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
9  * Copyright 1998 Gerald Combs
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24  */
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include <glib.h>
31 #include <epan/packet.h>
32 #include <epan/prefs.h>
33 #include <epan/conversation.h>
34
35 #include <stdio.h>
36 #include <string.h>
37
38 #include "packet-ber.h"
39 #include "packet-acse.h"
40 #include "packet-ros.h"
41
42 #include "packet-x509sat.h"
43 #include "packet-x509af.h"
44 #include "packet-x509if.h"
45 #include "packet-dap.h"
46 #include "packet-dsp.h"
47 #include "packet-crmf.h"
48
49
50 #include "packet-dop.h"
51
52 #define PNAME  "X.501 Directory Operational Binding Management Protocol"
53 #define PSNAME "DOP"
54 #define PFNAME "dop"
55
56 static guint global_dop_tcp_port = 102;
57 static guint tcp_port = 0;
58 static dissector_handle_t tpkt_handle = NULL;
59 void prefs_register_dop(void); /* forwad declaration for use in preferences registration */
60
61 /* Initialize the protocol and registered fields */
62 int proto_dop = -1;
63
64 static struct SESSION_DATA_STRUCTURE* session = NULL;
65 static const char *binding_type = NULL; /* binding_type */
66
67 static int call_dop_oid_callback(char *base_oid, tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, char *col_info);
68
69 #include "packet-dop-hf.c"
70
71 /* Initialize the subtree pointers */
72 static gint ett_dop = -1;
73 #include "packet-dop-ett.c"
74
75 #include "packet-dop-fn.c"
76
77 static int
78 call_dop_oid_callback(char *base_oid, tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, char *col_info)
79 {
80   char binding_param[BER_MAX_OID_STR_LEN];
81
82   g_snprintf(binding_param, BER_MAX_OID_STR_LEN, "%s.%s", base_oid, binding_type ? binding_type : "");  
83
84   if (col_info && (check_col(pinfo->cinfo, COL_INFO))) 
85     col_append_fstr(pinfo->cinfo, COL_INFO, " %s", col_info);
86
87   return call_ber_oid_callback(binding_param, tvb, offset, pinfo, tree);
88 }
89
90
91 /*
92 * Dissect DOP PDUs inside a ROS PDUs
93 */
94 static void
95 dissect_dop(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
96 {
97         int offset = 0;
98         int old_offset;
99         proto_item *item=NULL;
100         proto_tree *tree=NULL;
101         int (*dop_dissector)(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) = NULL;
102         char *dop_op_name;
103
104         /* do we have operation information from the ROS dissector?  */
105         if( !pinfo->private_data ){
106                 if(parent_tree){
107                         proto_tree_add_text(parent_tree, tvb, offset, -1,
108                                 "Internal error: can't get operation information from ROS dissector.");
109                 } 
110                 return  ;
111         } else {
112                 session  = ( (struct SESSION_DATA_STRUCTURE*)(pinfo->private_data) );
113         }
114
115         if(parent_tree){
116                 item = proto_tree_add_item(parent_tree, proto_dop, tvb, 0, -1, FALSE);
117                 tree = proto_item_add_subtree(item, ett_dop);
118         }
119         if (check_col(pinfo->cinfo, COL_PROTOCOL))
120                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "DOP");
121         if (check_col(pinfo->cinfo, COL_INFO))
122                 col_clear(pinfo->cinfo, COL_INFO);
123
124         switch(session->ros_op & ROS_OP_MASK) {
125         case (ROS_OP_BIND | ROS_OP_ARGUMENT):   /*  BindInvoke */
126           dop_dissector = dissect_dop_DSAOperationalManagementBindArgument;
127           dop_op_name = "DSA-Operational-Bind-Argument";
128           break;
129         case (ROS_OP_BIND | ROS_OP_RESULT):     /*  BindResult */
130           dop_dissector = dissect_dop_DSAOperationalManagementBindResult;
131           dop_op_name = "DSA-Operational-Bind-Result";
132           break;
133         case (ROS_OP_BIND | ROS_OP_ERROR):      /*  BindError */
134           dop_dissector = dissect_dop_DSAOperationalManagementBindError;
135           dop_op_name = "DSA-Operational-Management-Bind-Error";
136           break;
137         case (ROS_OP_INVOKE | ROS_OP_ARGUMENT): /*  Invoke Argument */
138           switch(session->ros_op & ROS_OP_OPCODE_MASK) {
139           case 100: /* establish */
140             dop_dissector = dissect_dop_EstablishOperationalBindingArgument;
141             dop_op_name = "Establish-Operational-Binding-Argument";
142             break;
143           case 101: /* terminate */
144             dop_dissector = dissect_dop_TerminateOperationalBindingArgument;
145             dop_op_name = "Terminate-Operational-Binding-Argument";
146             break;
147           case 102: /* modify */
148             dop_dissector = dissect_dop_ModifyOperationalBindingArgument;
149             dop_op_name = "Modify-Operational-Binding-Argument";
150             break;
151           default:
152             proto_tree_add_text(tree, tvb, offset, -1,"Unsupported DOP Argument opcode (%d)",
153                                 session->ros_op & ROS_OP_OPCODE_MASK);
154             break;
155           }
156           break;
157         case (ROS_OP_INVOKE | ROS_OP_RESULT):   /*  Return Result */
158           switch(session->ros_op & ROS_OP_OPCODE_MASK) {
159           case 100: /* establish */
160             dop_dissector = dissect_dop_EstablishOperationalBindingResult;
161             dop_op_name = "Establish-Operational-Binding-Result";
162             break;
163           case 101: /* terminate */
164             dop_dissector = dissect_dop_TerminateOperationalBindingResult;
165             dop_op_name = "Terminate-Operational-Binding-Result";
166             break;
167           case 102: /* modify */
168             dop_dissector = dissect_dop_ModifyOperationalBindingResult;
169             dop_op_name = "Modify-Operational-Binding-Result";
170             break;
171           default:
172             proto_tree_add_text(tree, tvb, offset, -1,"Unsupported DOP Result opcode (%d)",
173                                 session->ros_op & ROS_OP_OPCODE_MASK);
174             break;
175           }
176           break;
177         case (ROS_OP_INVOKE | ROS_OP_ERROR):    /*  Return Error */
178           switch(session->ros_op & ROS_OP_OPCODE_MASK) {
179           case 100: /* operational-binding */
180             dop_dissector = dissect_dop_OpBindingErrorParam;
181             dop_op_name = "Operational-Binding-Error";
182             break;
183           default:
184             proto_tree_add_text(tree, tvb, offset, -1,"Unsupported DOP Error opcode (%d)",
185                                 session->ros_op & ROS_OP_OPCODE_MASK);
186             break;
187           }
188           break;
189         default:
190           proto_tree_add_text(tree, tvb, offset, -1,"Unsupported DOP PDU");
191           return;
192         }
193
194         if(dop_dissector) {
195           if (check_col(pinfo->cinfo, COL_INFO))
196             col_add_str(pinfo->cinfo, COL_INFO, dop_op_name);
197
198           while (tvb_reported_length_remaining(tvb, offset) > 0){
199             old_offset=offset;
200             offset=(*dop_dissector)(FALSE, tvb, offset, pinfo , tree, -1);
201             if(offset == old_offset){
202               proto_tree_add_text(tree, tvb, offset, -1,"Internal error, zero-byte DOP PDU");
203               offset = tvb_length(tvb);
204               break;
205             }
206           }
207         }
208 }
209
210
211
212 /*--- proto_register_dop -------------------------------------------*/
213 void proto_register_dop(void) {
214
215   /* List of fields */
216   static hf_register_info hf[] =
217   {
218 #include "packet-dop-hfarr.c"
219   };
220
221   /* List of subtrees */
222   static gint *ett[] = {
223     &ett_dop,
224 #include "packet-dop-ettarr.c"
225   };
226
227   module_t *dop_module;
228
229   /* Register protocol */
230   proto_dop = proto_register_protocol(PNAME, PSNAME, PFNAME);
231
232   register_dissector("dop", dissect_dop, proto_dop);
233
234   /* Register fields and subtrees */
235   proto_register_field_array(proto_dop, hf, array_length(hf));
236   proto_register_subtree_array(ett, array_length(ett));
237
238   /* Register our configuration options for DOP, particularly our port */
239
240 #ifdef PREFERENCE_GROUPING
241   dop_module = prefs_register_protocol_subtree("OSI/X.500", proto_dop, prefs_register_dop);
242 #else
243   dop_module = prefs_register_protocol(proto_dop, prefs_register_dop);
244 #endif 
245
246   prefs_register_uint_preference(dop_module, "tcp.port", "DOP TCP Port",
247                                  "Set the port for DOP operations (if other"
248                                  " than the default of 102)",
249                                  10, &global_dop_tcp_port);
250
251
252 }
253
254
255 /*--- proto_reg_handoff_dop --- */
256 void proto_reg_handoff_dop(void) {
257   dissector_handle_t handle = NULL;
258
259 #include "packet-dop-dis-tab.c" 
260   /* APPLICATION CONTEXT */
261
262   register_ber_oid_name("2.5.3.3", "id-ac-directory-operational-binding-management");
263
264   /* ABSTRACT SYNTAXES */
265     
266   /* Register DOP with ROS (with no use of RTSE) */
267   if((handle = find_dissector("dop"))) {
268     register_ros_oid_dissector_handle("2.5.9.4", handle, 0, "id-as-directory-operational-binding-management", FALSE); 
269   }
270
271   /* BINDING TYPES */
272
273   register_ber_oid_name("2.5.19.1", "shadow-agreement");
274   register_ber_oid_name("2.5.19.2", "hierarchical-agreement");
275   register_ber_oid_name("2.5.19.3", "non-specific-hierarchical-agreement");
276
277   /* ACCESS CONTROL SCHEMES */
278   register_ber_oid_name("2.5.28.1", "basic-ACS");
279   register_ber_oid_name("2.5.28.2", "simplified-ACS");
280   register_ber_oid_name("2.5.28.3", "ruleBased-ACS");
281   register_ber_oid_name("2.5.28.4", "ruleAndBasic-ACS");
282   register_ber_oid_name("2.5.28.5", "ruleAndSimple-ACS");
283
284   /* ADMINISTRATIVE ROLES */
285   register_ber_oid_name("2.5.23.1", "id-ar-autonomousArea");
286   register_ber_oid_name("2.5.23.2", "id-ar-accessControlSpecificArea");
287   register_ber_oid_name("2.5.23.3", "id-ar-accessControlInnerArea");
288   register_ber_oid_name("2.5.23.4", "id-ar-subschemaAdminSpecificArea");
289   register_ber_oid_name("2.5.23.5", "id-ar-collectiveAttributeSpecificArea");
290   register_ber_oid_name("2.5.23.6", "id-ar-collectiveAttributeInnerArea");
291   register_ber_oid_name("2.5.23.7", "id-ar-contextDefaultSpecificArea");
292   register_ber_oid_name("2.5.23.8", "id-ar-serviceSpecificArea");
293
294   /* remember the tpkt handler for change in preferences */
295   tpkt_handle = find_dissector("tpkt");
296
297 }
298
299 void prefs_register_dop(void) {
300
301   /* de-register the old port */
302   /* port 102 is registered by TPKT - don't undo this! */
303   if((tcp_port != 102) && tpkt_handle)
304     dissector_delete("tcp.port", tcp_port, tpkt_handle);
305
306   /* Set our port number for future use */
307   tcp_port = global_dop_tcp_port;
308
309   if((tcp_port > 0) && (tcp_port != 102) && tpkt_handle)
310     dissector_add("tcp.port", global_dop_tcp_port, tpkt_handle);
311
312 }