2 * Routines for X.511 (X.500 Directory Asbtract Service) and X.519 DAP packet dissection
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
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.
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.
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.
31 #include <epan/packet.h>
32 #include <epan/prefs.h>
33 #include <epan/conversation.h>
34 #include <epan/oids.h>
35 #include <epan/asn1.h>
40 #include "packet-ber.h"
41 #include "packet-acse.h"
42 #include "packet-ros.h"
44 #include "packet-x509if.h"
45 #include "packet-x509af.h"
46 #include "packet-x509sat.h"
47 #include "packet-crmf.h"
49 #include "packet-dsp.h"
50 #include "packet-disp.h"
51 #include "packet-dap.h"
52 #include <epan/strutil.h>
54 /* we don't have a separate dissector for X519 -
55 most of DAP is defined in X511 */
56 #define PNAME "X.519 Directory Access Protocol"
60 static guint global_dap_tcp_port = 102;
61 static guint tcp_port = 0;
62 static dissector_handle_t tpkt_handle = NULL;
63 void prefs_register_dap(void); /* forwad declaration for use in preferences registration */
66 /* Initialize the protocol and registered fields */
69 static struct SESSION_DATA_STRUCTURE* session = NULL;
71 #include "packet-dap-hf.c"
73 /* Initialize the subtree pointers */
74 static gint ett_dap = -1;
75 #include "packet-dap-ett.c"
77 #include "packet-dap-fn.c"
80 * Dissect DAP PDUs inside a ROS PDUs
83 dissect_dap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
87 proto_item *item=NULL;
88 proto_tree *tree=NULL;
89 int (*dap_dissector)(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, asn1_ctx_t *actx, proto_tree *tree, int hf_index _U_) = NULL;
93 asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
95 /* do we have operation information from the ROS dissector? */
96 if( !pinfo->private_data ){
98 proto_tree_add_text(parent_tree, tvb, offset, -1,
99 "Internal error: can't get operation information from ROS dissector.");
103 session = ( (struct SESSION_DATA_STRUCTURE*)(pinfo->private_data) );
107 item = proto_tree_add_item(parent_tree, proto_dap, tvb, 0, -1, FALSE);
108 tree = proto_item_add_subtree(item, ett_dap);
110 if (check_col(pinfo->cinfo, COL_PROTOCOL))
111 col_set_str(pinfo->cinfo, COL_PROTOCOL, "DAP");
112 if (check_col(pinfo->cinfo, COL_INFO))
113 col_clear(pinfo->cinfo, COL_INFO);
115 switch(session->ros_op & ROS_OP_MASK) {
116 case (ROS_OP_BIND | ROS_OP_ARGUMENT): /* BindInvoke */
117 dap_dissector = dissect_dap_DirectoryBindArgument;
118 dap_op_name = "Bind-Argument";
120 case (ROS_OP_BIND | ROS_OP_RESULT): /* BindResult */
121 dap_dissector = dissect_dap_DirectoryBindResult;
122 dap_op_name = "Bind-Result";
124 case (ROS_OP_BIND | ROS_OP_ERROR): /* BindError */
125 dap_dissector = dissect_dap_DirectoryBindError;
126 dap_op_name = "Bind-Error";
128 case (ROS_OP_INVOKE | ROS_OP_ARGUMENT): /* Invoke Argument */
129 switch(session->ros_op & ROS_OP_OPCODE_MASK) {
131 dap_dissector = dissect_dap_ReadArgument;
132 dap_op_name = "Read-Argument";
134 case 2: /* compare */
135 dap_dissector = dissect_dap_CompareArgument;
136 dap_op_name = "Compare-Argument";
138 case 3: /* abandon */
139 dap_dissector = dissect_dap_AbandonArgument;
140 dap_op_name = "Abandon-Argument";
143 dap_dissector = dissect_dap_ListArgument;
144 dap_op_name = "List-Argument";
147 dap_dissector = dissect_dap_SearchArgument;
148 dap_op_name = "Search-Argument";
150 case 6: /* addEntry */
151 dap_dissector = dissect_dap_AddEntryArgument;
152 dap_op_name = "Add-Entry-Argument";
154 case 7: /* removeEntry */
155 dap_dissector = dissect_dap_RemoveEntryArgument;
156 dap_op_name = "Remove-Entry-Argument";
158 case 8: /* modifyEntry */
159 dap_dissector = dissect_dap_ModifyEntryArgument;
160 dap_op_name = "Modify-Entry-Argument";
162 case 9: /* modifyDN */
163 dap_dissector = dissect_dap_ModifyDNArgument;
164 dap_op_name = "Modify-DN-Argument";
167 proto_tree_add_text(tree, tvb, offset, -1,"Unsupported DAP opcode (%d)",
168 session->ros_op & ROS_OP_OPCODE_MASK);
172 case (ROS_OP_INVOKE | ROS_OP_RESULT): /* Return Result */
173 switch(session->ros_op & ROS_OP_OPCODE_MASK) {
175 dap_dissector = dissect_dap_ReadResult;
176 dap_op_name = "Read-Result";
178 case 2: /* compare */
179 dap_dissector = dissect_dap_CompareResult;
180 dap_op_name = "Compare-Result";
182 case 3: /* abandon */
183 dap_dissector = dissect_dap_AbandonResult;
184 dap_op_name = "Abandon-Result";
187 dap_dissector = dissect_dap_ListResult;
188 dap_op_name = "List-Result";
191 dap_dissector = dissect_dap_SearchResult;
192 dap_op_name = "Search-Result";
194 case 6: /* addEntry */
195 dap_dissector = dissect_dap_AddEntryResult;
196 dap_op_name = "Add-Entry-Result";
198 case 7: /* removeEntry */
199 dap_dissector = dissect_dap_RemoveEntryResult;
200 dap_op_name = "Remove-Entry-Result";
202 case 8: /* modifyEntry */
203 dap_dissector = dissect_dap_ModifyEntryResult;
204 dap_op_name = "Modify-Entry-Result";
206 case 9: /* modifyDN */
207 dap_dissector = dissect_dap_ModifyDNResult;
208 dap_op_name = "Modify-DN-Result";
211 proto_tree_add_text(tree, tvb, offset, -1,"Unsupported DAP opcode");
215 case (ROS_OP_INVOKE | ROS_OP_ERROR): /* Return Error */
216 switch(session->ros_op & ROS_OP_OPCODE_MASK) {
217 case 1: /* attributeError */
218 dap_dissector = dissect_dap_AttributeError;
219 dap_op_name = "Attribute-Error";
221 case 2: /* nameError */
222 dap_dissector = dissect_dap_NameError;
223 dap_op_name = "Name-Error";
225 case 3: /* serviceError */
226 dap_dissector = dissect_dap_ServiceError;
227 dap_op_name = "Service-Error";
229 case 4: /* referral */
230 dap_dissector = dissect_dap_Referral;
231 dap_op_name = "Referral";
233 case 5: /* abandoned */
234 dap_dissector = dissect_dap_Abandoned;
235 dap_op_name = "Abandoned";
237 case 6: /* securityError */
238 dap_dissector = dissect_dap_SecurityError;
239 dap_op_name = "Security-Error";
241 case 7: /* abandonFailed */
242 dap_dissector = dissect_dap_AbandonFailedError;
243 dap_op_name = "Abandon-Failed-Error";
245 case 8: /* updateError */
246 dap_dissector = dissect_dap_UpdateError;
247 dap_op_name = "Update-Error";
250 proto_tree_add_text(tree, tvb, offset, -1,"Unsupported DAP errcode");
255 proto_tree_add_text(tree, tvb, offset, -1,"Unsupported DAP PDU");
260 if (check_col(pinfo->cinfo, COL_INFO))
261 col_add_str(pinfo->cinfo, COL_INFO, dap_op_name);
263 while (tvb_reported_length_remaining(tvb, offset) > 0){
265 offset=(*dap_dissector)(FALSE, tvb, offset, &asn1_ctx, tree, -1);
266 if(offset == old_offset){
267 proto_tree_add_text(tree, tvb, offset, -1,"Internal error, zero-byte DAP PDU");
268 offset = tvb_length(tvb);
276 /*--- proto_register_dap -------------------------------------------*/
277 void proto_register_dap(void) {
280 static hf_register_info hf[] =
282 #include "packet-dap-hfarr.c"
285 /* List of subtrees */
286 static gint *ett[] = {
288 #include "packet-dap-ettarr.c"
290 module_t *dap_module;
292 /* Register protocol */
293 proto_dap = proto_register_protocol(PNAME, PSNAME, PFNAME);
294 register_dissector("dap", dissect_dap, proto_dap);
296 /* Register fields and subtrees */
297 proto_register_field_array(proto_dap, hf, array_length(hf));
298 proto_register_subtree_array(ett, array_length(ett));
300 /* Register our configuration options for DAP, particularly our port */
302 #ifdef PREFERENCE_GROUPING
303 dap_module = prefs_register_protocol_subtree("OSI/X.500", proto_dap, prefs_register_dap);
305 dap_module = prefs_register_protocol(proto_dap, prefs_register_dap);
308 prefs_register_uint_preference(dap_module, "tcp.port", "DAP TCP Port",
309 "Set the port for DAP operations (if other"
310 " than the default of 102)",
311 10, &global_dap_tcp_port);
316 /*--- proto_reg_handoff_dap --- */
317 void proto_reg_handoff_dap(void) {
318 dissector_handle_t handle = NULL;
320 /* #include "packet-dap-dis-tab.c" */
322 /* APPLICATION CONTEXT */
324 add_oid_str_name("2.5.3.1", "id-ac-directory-access");
326 /* ABSTRACT SYNTAXES */
328 /* Register DAP with ROS (with no use of RTSE) */
329 if((handle = find_dissector("dap"))) {
330 register_ros_oid_dissector_handle("2.5.9.1", handle, 0, "id-as-directory-access", FALSE);
333 /* remember the tpkt handler for change in preferences */
334 tpkt_handle = find_dissector("tpkt");
336 /* AttributeValueAssertions */
337 x509if_register_fmt(hf_dap_equality, "=");
338 x509if_register_fmt(hf_dap_greaterOrEqual, ">=");
339 x509if_register_fmt(hf_dap_lessOrEqual, "<=");
340 x509if_register_fmt(hf_dap_approximateMatch, "=~");
342 x509if_register_fmt(hf_dap_present, "= *");
348 void prefs_register_dap(void) {
350 /* de-register the old port */
351 /* port 102 is registered by TPKT - don't undo this! */
352 if((tcp_port != 102) && tpkt_handle)
353 dissector_delete("tcp.port", tcp_port, tpkt_handle);
355 /* Set our port number for future use */
356 tcp_port = global_dap_tcp_port;
358 if((tcp_port > 0) && (tcp_port != 102) && tpkt_handle)
359 dissector_add("tcp.port", global_dap_tcp_port, tpkt_handle);