Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / asn1 / dop / packet-dop-template.c
blob265a5982994bb11fcf836d23a3d3ee15f7f361e2
1 /* packet-dop.c
2 * Routines for X.501 (DSA Operational Attributes) packet dissection
3 * Graeme Lunt 2005
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
12 #include "config.h"
14 #include <epan/packet.h>
15 #include <epan/prefs.h>
16 #include <epan/oids.h>
17 #include <epan/asn1.h>
18 #include <epan/expert.h>
19 #include <wsutil/array.h>
21 #include "packet-ber.h"
22 #include "packet-acse.h"
23 #include "packet-ros.h"
25 #include "packet-x509sat.h"
26 #include "packet-x509af.h"
27 #include "packet-x509if.h"
28 #include "packet-dap.h"
29 #include "packet-dsp.h"
30 #include "packet-crmf.h"
33 #include "packet-dop.h"
35 #define PNAME "X.501 Directory Operational Binding Management Protocol"
36 #define PSNAME "DOP"
37 #define PFNAME "dop"
39 void proto_register_dop(void);
40 void proto_reg_handoff_dop(void);
42 /* Initialize the protocol and registered fields */
43 static int proto_dop;
45 static const char *binding_type; /* binding_type */
47 static int call_dop_oid_callback(const char *base_string, tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, const char *col_info, void* data);
49 #include "packet-dop-hf.c"
51 /* Initialize the subtree pointers */
52 static int ett_dop;
53 static int ett_dop_unknown;
54 #include "packet-dop-ett.c"
56 static expert_field ei_dop_unknown_binding_parameter;
57 static expert_field ei_dop_unsupported_opcode;
58 static expert_field ei_dop_unsupported_errcode;
59 static expert_field ei_dop_unsupported_pdu;
60 static expert_field ei_dop_zero_pdu;
62 static dissector_handle_t dop_handle;
64 /* Dissector table */
65 static dissector_table_t dop_dissector_table;
67 static void append_oid(packet_info *pinfo, const char *oid)
69 const char *name = NULL;
71 name = oid_resolved_from_string(pinfo->pool, oid);
72 col_append_fstr(pinfo->cinfo, COL_INFO, " %s", name ? name : oid);
75 #include "packet-dop-fn.c"
77 static int
78 call_dop_oid_callback(const char *base_string, tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, const char *col_info, void* data)
80 char* binding_param;
82 binding_param = wmem_strdup_printf(pinfo->pool, "%s.%s", base_string, binding_type ? binding_type : "");
84 col_append_fstr(pinfo->cinfo, COL_INFO, " %s", col_info);
86 if (dissector_try_string_with_data(dop_dissector_table, binding_param, tvb, pinfo, tree, true, data)) {
87 offset = tvb_reported_length (tvb);
88 } else {
89 proto_item *item;
90 proto_tree *next_tree;
92 next_tree = proto_tree_add_subtree_format(tree, tvb, 0, -1, ett_dop_unknown, &item,
93 "Dissector for parameter %s OID:%s not implemented. Contact Wireshark developers if you want this supported", base_string, binding_type ? binding_type : "<empty>");
95 offset = dissect_unknown_ber(pinfo, tvb, offset, next_tree);
96 expert_add_info(pinfo, item, &ei_dop_unknown_binding_parameter);
99 return offset;
104 * Dissect DOP PDUs inside a ROS PDUs
106 static int
107 dissect_dop(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void* data)
109 int offset = 0;
110 int old_offset;
111 proto_item *item;
112 proto_tree *tree;
113 struct SESSION_DATA_STRUCTURE* session;
114 int (*dop_dissector)(bool implicit_tag _U_, tvbuff_t *tvb, int offset, asn1_ctx_t *actx, proto_tree *tree, int hf_index _U_) = NULL;
115 const char *dop_op_name;
116 asn1_ctx_t asn1_ctx;
118 /* do we have operation information from the ROS dissector? */
119 if (data == NULL)
120 return 0;
121 session = (struct SESSION_DATA_STRUCTURE*)data;
123 asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, true, pinfo);
125 item = proto_tree_add_item(parent_tree, proto_dop, tvb, 0, -1, ENC_NA);
126 tree = proto_item_add_subtree(item, ett_dop);
128 col_set_str(pinfo->cinfo, COL_PROTOCOL, "DOP");
129 col_clear(pinfo->cinfo, COL_INFO);
131 asn1_ctx.private_data = session;
133 switch(session->ros_op & ROS_OP_MASK) {
134 case (ROS_OP_BIND | ROS_OP_ARGUMENT): /* BindInvoke */
135 dop_dissector = dissect_dop_DSAOperationalManagementBindArgument;
136 dop_op_name = "DSA-Operational-Bind-Argument";
137 break;
138 case (ROS_OP_BIND | ROS_OP_RESULT): /* BindResult */
139 dop_dissector = dissect_dop_DSAOperationalManagementBindResult;
140 dop_op_name = "DSA-Operational-Bind-Result";
141 break;
142 case (ROS_OP_BIND | ROS_OP_ERROR): /* BindError */
143 dop_dissector = dissect_dop_DSAOperationalManagementBindError;
144 dop_op_name = "DSA-Operational-Management-Bind-Error";
145 break;
146 case (ROS_OP_INVOKE | ROS_OP_ARGUMENT): /* Invoke Argument */
147 switch(session->ros_op & ROS_OP_OPCODE_MASK) {
148 case 100: /* establish */
149 dop_dissector = dissect_dop_EstablishOperationalBindingArgument;
150 dop_op_name = "Establish-Operational-Binding-Argument";
151 break;
152 case 101: /* terminate */
153 dop_dissector = dissect_dop_TerminateOperationalBindingArgument;
154 dop_op_name = "Terminate-Operational-Binding-Argument";
155 break;
156 case 102: /* modify */
157 dop_dissector = dissect_dop_ModifyOperationalBindingArgument;
158 dop_op_name = "Modify-Operational-Binding-Argument";
159 break;
160 default:
161 proto_tree_add_expert_format(tree, pinfo, &ei_dop_unsupported_opcode, tvb, offset, -1,
162 "Unsupported DOP Argument opcode (%d)", session->ros_op & ROS_OP_OPCODE_MASK);
163 break;
165 break;
166 case (ROS_OP_INVOKE | ROS_OP_RESULT): /* Return Result */
167 switch(session->ros_op & ROS_OP_OPCODE_MASK) {
168 case 100: /* establish */
169 dop_dissector = dissect_dop_EstablishOperationalBindingResult;
170 dop_op_name = "Establish-Operational-Binding-Result";
171 break;
172 case 101: /* terminate */
173 dop_dissector = dissect_dop_TerminateOperationalBindingResult;
174 dop_op_name = "Terminate-Operational-Binding-Result";
175 break;
176 case 102: /* modify */
177 dop_dissector = dissect_dop_ModifyOperationalBindingResult;
178 dop_op_name = "Modify-Operational-Binding-Result";
179 break;
180 default:
181 proto_tree_add_expert_format(tree, pinfo, &ei_dop_unsupported_opcode, tvb, offset, -1,
182 "Unsupported DOP Result opcode (%d)", session->ros_op & ROS_OP_OPCODE_MASK);
183 break;
185 break;
186 case (ROS_OP_INVOKE | ROS_OP_ERROR): /* Return Error */
187 switch(session->ros_op & ROS_OP_OPCODE_MASK) {
188 case 100: /* operational-binding */
189 dop_dissector = dissect_dop_OpBindingErrorParam;
190 dop_op_name = "Operational-Binding-Error";
191 break;
192 default:
193 proto_tree_add_expert_format(tree, pinfo, &ei_dop_unsupported_errcode, tvb, offset, -1,
194 "Unsupported DOP Error opcode (%d)", session->ros_op & ROS_OP_OPCODE_MASK);
195 break;
197 break;
198 default:
199 proto_tree_add_expert(tree, pinfo, &ei_dop_unsupported_pdu, tvb, offset, -1);
200 return tvb_captured_length(tvb);
203 if(dop_dissector) {
204 col_set_str(pinfo->cinfo, COL_INFO, dop_op_name);
206 while (tvb_reported_length_remaining(tvb, offset) > 0){
207 old_offset=offset;
208 offset=(*dop_dissector)(false, tvb, offset, &asn1_ctx, tree, -1);
209 if(offset == old_offset){
210 proto_tree_add_expert(tree, pinfo, &ei_dop_zero_pdu, tvb, offset, -1);
211 break;
216 return tvb_captured_length(tvb);
221 /*--- proto_register_dop -------------------------------------------*/
222 void proto_register_dop(void) {
224 /* List of fields */
225 static hf_register_info hf[] =
227 #include "packet-dop-hfarr.c"
230 /* List of subtrees */
231 static int *ett[] = {
232 &ett_dop,
233 &ett_dop_unknown,
234 #include "packet-dop-ettarr.c"
237 static ei_register_info ei[] = {
238 { &ei_dop_unknown_binding_parameter, { "dop.unknown_binding_parameter", PI_UNDECODED, PI_WARN, "Unknown binding-parameter", EXPFILL }},
239 { &ei_dop_unsupported_opcode, { "dop.unsupported_opcode", PI_UNDECODED, PI_WARN, "Unsupported DOP opcode", EXPFILL }},
240 { &ei_dop_unsupported_errcode, { "dop.unsupported_errcode", PI_UNDECODED, PI_WARN, "Unsupported DOP errcode", EXPFILL }},
241 { &ei_dop_unsupported_pdu, { "dop.unsupported_pdu", PI_UNDECODED, PI_WARN, "Unsupported DOP PDU", EXPFILL }},
242 { &ei_dop_zero_pdu, { "dop.zero_pdu", PI_PROTOCOL, PI_ERROR, "Internal error, zero-byte DOP PDU", EXPFILL }},
245 expert_module_t* expert_dop;
246 module_t *dop_module;
248 /* Register protocol */
249 proto_dop = proto_register_protocol(PNAME, PSNAME, PFNAME);
251 dop_handle = register_dissector("dop", dissect_dop, proto_dop);
253 dop_dissector_table = register_dissector_table("dop.oid", "DOP OID", proto_dop, FT_STRING, STRING_CASE_SENSITIVE);
255 /* Register fields and subtrees */
256 proto_register_field_array(proto_dop, hf, array_length(hf));
257 proto_register_subtree_array(ett, array_length(ett));
258 expert_dop = expert_register_protocol(proto_dop);
259 expert_register_field_array(expert_dop, ei, array_length(ei));
261 /* Register our configuration options for DOP, particularly our port */
263 dop_module = prefs_register_protocol_subtree("OSI/X.500", proto_dop, NULL);
265 prefs_register_obsolete_preference(dop_module, "tcp.port");
267 prefs_register_static_text_preference(dop_module, "tcp_port_info",
268 "The TCP ports used by the DOP protocol should be added to the TPKT preference \"TPKT TCP ports\", or by selecting \"TPKT\" as the \"Transport\" protocol in the \"Decode As\" dialog.",
269 "DOP TCP Port preference moved information");
274 /*--- proto_reg_handoff_dop --- */
275 void proto_reg_handoff_dop(void) {
277 #include "packet-dop-dis-tab.c"
278 /* APPLICATION CONTEXT */
280 oid_add_from_string("id-ac-directory-operational-binding-management","2.5.3.3");
282 /* ABSTRACT SYNTAXES */
284 /* Register DOP with ROS (with no use of RTSE) */
285 register_ros_oid_dissector_handle("2.5.9.4", dop_handle, 0, "id-as-directory-operational-binding-management", false);
287 /* BINDING TYPES */
289 oid_add_from_string("shadow-agreement","2.5.19.1");
290 oid_add_from_string("hierarchical-agreement","2.5.19.2");
291 oid_add_from_string("non-specific-hierarchical-agreement","2.5.19.3");
293 /* ACCESS CONTROL SCHEMES */
294 oid_add_from_string("basic-ACS","2.5.28.1");
295 oid_add_from_string("simplified-ACS","2.5.28.2");
296 oid_add_from_string("ruleBased-ACS","2.5.28.3");
297 oid_add_from_string("ruleAndBasic-ACS","2.5.28.4");
298 oid_add_from_string("ruleAndSimple-ACS","2.5.28.5");
300 /* ADMINISTRATIVE ROLES */
301 oid_add_from_string("id-ar-autonomousArea","2.5.23.1");
302 oid_add_from_string("id-ar-accessControlSpecificArea","2.5.23.2");
303 oid_add_from_string("id-ar-accessControlInnerArea","2.5.23.3");
304 oid_add_from_string("id-ar-subschemaAdminSpecificArea","2.5.23.4");
305 oid_add_from_string("id-ar-collectiveAttributeSpecificArea","2.5.23.5");
306 oid_add_from_string("id-ar-collectiveAttributeInnerArea","2.5.23.6");
307 oid_add_from_string("id-ar-contextDefaultSpecificArea","2.5.23.7");
308 oid_add_from_string("id-ar-serviceSpecificArea","2.5.23.8");