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>
38 #include "packet-ber.h"
39 #include "packet-acse.h"
40 #include "packet-ros.h"
42 #include "packet-x509if.h"
43 #include "packet-x509af.h"
44 #include "packet-x509sat.h"
45 #include "packet-crmf.h"
47 #include "packet-dsp.h"
48 #include "packet-disp.h"
49 #include "packet-dap.h"
50 #include <epan/strutil.h>
52 /* we don't have a separate dissector for X519 -
53 most of DAP is defined in X511 */
54 #define PNAME "X.519 Directory Access Protocol"
58 static guint global_dap_tcp_port = 102;
59 static guint tcp_port = 0;
60 static dissector_handle_t tpkt_handle = NULL;
61 void prefs_register_dap(void); /* forwad declaration for use in preferences registration */
64 /* Initialize the protocol and registered fields */
67 static struct SESSION_DATA_STRUCTURE* session = NULL;
69 #include "packet-dap-hf.c"
71 /* Initialize the subtree pointers */
72 static gint ett_dap = -1;
73 #include "packet-dap-ett.c"
75 #include "packet-dap-fn.c"
78 * Dissect DAP PDUs inside a ROS PDUs
81 dissect_dap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
85 proto_item *item=NULL;
86 proto_tree *tree=NULL;
87 int (*dap_dissector)(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) = NULL;
90 /* do we have operation information from the ROS dissector? */
91 if( !pinfo->private_data ){
93 proto_tree_add_text(parent_tree, tvb, offset, -1,
94 "Internal error: can't get operation information from ROS dissector.");
98 session = ( (struct SESSION_DATA_STRUCTURE*)(pinfo->private_data) );
102 item = proto_tree_add_item(parent_tree, proto_dap, tvb, 0, -1, FALSE);
103 tree = proto_item_add_subtree(item, ett_dap);
105 if (check_col(pinfo->cinfo, COL_PROTOCOL))
106 col_set_str(pinfo->cinfo, COL_PROTOCOL, "DAP");
107 if (check_col(pinfo->cinfo, COL_INFO))
108 col_clear(pinfo->cinfo, COL_INFO);
110 switch(session->ros_op & ROS_OP_MASK) {
111 case (ROS_OP_BIND | ROS_OP_ARGUMENT): /* BindInvoke */
112 dap_dissector = dissect_dap_DirectoryBindArgument;
113 dap_op_name = "Bind-Argument";
115 case (ROS_OP_BIND | ROS_OP_RESULT): /* BindResult */
116 dap_dissector = dissect_dap_DirectoryBindResult;
117 dap_op_name = "Bind-Result";
119 case (ROS_OP_BIND | ROS_OP_ERROR): /* BindError */
120 dap_dissector = dissect_dap_DirectoryBindError;
121 dap_op_name = "Bind-Error";
123 case (ROS_OP_INVOKE | ROS_OP_ARGUMENT): /* Invoke Argument */
124 switch(session->ros_op & ROS_OP_OPCODE_MASK) {
126 dap_dissector = dissect_dap_ReadArgument;
127 dap_op_name = "Read-Argument";
129 case 2: /* compare */
130 dap_dissector = dissect_dap_CompareArgument;
131 dap_op_name = "Compare-Argument";
133 case 3: /* abandon */
134 dap_dissector = dissect_dap_AbandonArgument;
135 dap_op_name = "Abandon-Argument";
138 dap_dissector = dissect_dap_ListArgument;
139 dap_op_name = "List-Argument";
142 dap_dissector = dissect_dap_SearchArgument;
143 dap_op_name = "Search-Argument";
145 case 6: /* addEntry */
146 dap_dissector = dissect_dap_AddEntryArgument;
147 dap_op_name = "Add-Entry-Argument";
149 case 7: /* removeEntry */
150 dap_dissector = dissect_dap_RemoveEntryArgument;
151 dap_op_name = "Remove-Entry-Argument";
153 case 8: /* modifyEntry */
154 dap_dissector = dissect_dap_ModifyEntryArgument;
155 dap_op_name = "Modify-Entry-Argument";
157 case 9: /* modifyDN */
158 dap_dissector = dissect_dap_ModifyDNArgument;
159 dap_op_name = "Modify-DN-Argument";
162 proto_tree_add_text(tree, tvb, offset, -1,"Unsupported DAP opcode (%d)",
163 session->ros_op & ROS_OP_OPCODE_MASK);
167 case (ROS_OP_INVOKE | ROS_OP_RESULT): /* Return Result */
168 switch(session->ros_op & ROS_OP_OPCODE_MASK) {
170 dap_dissector = dissect_dap_ReadResult;
171 dap_op_name = "Read-Result";
173 case 2: /* compare */
174 dap_dissector = dissect_dap_CompareResult;
175 dap_op_name = "Compare-Result";
177 case 3: /* abandon */
178 dap_dissector = dissect_dap_AbandonResult;
179 dap_op_name = "Abandon-Result";
182 dap_dissector = dissect_dap_ListResult;
183 dap_op_name = "List-Result";
186 dap_dissector = dissect_dap_SearchResult;
187 dap_op_name = "Search-Result";
189 case 6: /* addEntry */
190 dap_dissector = dissect_dap_AddEntryResult;
191 dap_op_name = "Add-Entry-Result";
193 case 7: /* removeEntry */
194 dap_dissector = dissect_dap_RemoveEntryResult;
195 dap_op_name = "Remove-Entry-Result";
197 case 8: /* modifyEntry */
198 dap_dissector = dissect_dap_ModifyEntryResult;
199 dap_op_name = "Modify-Entry-Result";
201 case 9: /* modifyDN */
202 dap_dissector = dissect_dap_ModifyDNResult;
203 dap_op_name = "Modify-DN-Result";
206 proto_tree_add_text(tree, tvb, offset, -1,"Unsupported DAP opcode");
210 case (ROS_OP_INVOKE | ROS_OP_ERROR): /* Return Error */
211 switch(session->ros_op & ROS_OP_OPCODE_MASK) {
212 case 1: /* attributeError */
213 dap_dissector = dissect_dap_AttributeError;
214 dap_op_name = "Attribute-Error";
216 case 2: /* nameError */
217 dap_dissector = dissect_dap_NameError;
218 dap_op_name = "Name-Error";
220 case 3: /* serviceError */
221 dap_dissector = dissect_dap_ServiceError;
222 dap_op_name = "Service-Error";
224 case 4: /* referral */
225 dap_dissector = dissect_dap_Referral;
226 dap_op_name = "Referral";
228 case 5: /* abandoned */
229 dap_dissector = dissect_dap_Abandoned;
230 dap_op_name = "Abandoned";
232 case 6: /* securityError */
233 dap_dissector = dissect_dap_SecurityError;
234 dap_op_name = "Security-Error";
236 case 7: /* abandonFailed */
237 dap_dissector = dissect_dap_AbandonFailedError;
238 dap_op_name = "Abandon-Failed-Error";
240 case 8: /* updateError */
241 dap_dissector = dissect_dap_UpdateError;
242 dap_op_name = "Update-Error";
245 proto_tree_add_text(tree, tvb, offset, -1,"Unsupported DAP errcode");
250 proto_tree_add_text(tree, tvb, offset, -1,"Unsupported DAP PDU");
255 if (check_col(pinfo->cinfo, COL_INFO))
256 col_add_str(pinfo->cinfo, COL_INFO, dap_op_name);
258 while (tvb_reported_length_remaining(tvb, offset) > 0){
260 offset=(*dap_dissector)(FALSE, tvb, offset, pinfo , tree, -1);
261 if(offset == old_offset){
262 proto_tree_add_text(tree, tvb, offset, -1,"Internal error, zero-byte DAP PDU");
263 offset = tvb_length(tvb);
271 /*--- proto_register_dap -------------------------------------------*/
272 void proto_register_dap(void) {
275 static hf_register_info hf[] =
277 #include "packet-dap-hfarr.c"
280 /* List of subtrees */
281 static gint *ett[] = {
283 #include "packet-dap-ettarr.c"
285 module_t *dap_module;
287 /* Register protocol */
288 proto_dap = proto_register_protocol(PNAME, PSNAME, PFNAME);
289 register_dissector("dap", dissect_dap, proto_dap);
291 /* Register fields and subtrees */
292 proto_register_field_array(proto_dap, hf, array_length(hf));
293 proto_register_subtree_array(ett, array_length(ett));
295 /* Register our configuration options for DAP, particularly our port */
297 #ifdef PREFERENCE_GROUPING
298 dap_module = prefs_register_protocol_subtree("OSI/X.500", proto_dap, prefs_register_dap);
300 dap_module = prefs_register_protocol(proto_dap, prefs_register_dap);
303 prefs_register_uint_preference(dap_module, "tcp.port", "DAP TCP Port",
304 "Set the port for DAP operations (if other"
305 " than the default of 102)",
306 10, &global_dap_tcp_port);
311 /*--- proto_reg_handoff_dap --- */
312 void proto_reg_handoff_dap(void) {
313 dissector_handle_t handle = NULL;
315 /* #include "packet-dap-dis-tab.c" */
317 /* APPLICATION CONTEXT */
319 register_ber_oid_name("2.5.3.1", "id-ac-directory-access");
321 /* ABSTRACT SYNTAXES */
323 /* Register DAP with ROS (with no use of RTSE) */
324 if((handle = find_dissector("dap"))) {
325 register_ros_oid_dissector_handle("2.5.9.1", handle, 0, "id-as-directory-access", FALSE);
328 /* remember the tpkt handler for change in preferences */
329 tpkt_handle = find_dissector("tpkt");
331 /* AttributeValueAssertions */
332 x509if_register_fmt(hf_dap_equality, "=");
333 x509if_register_fmt(hf_dap_greaterOrEqual, ">=");
334 x509if_register_fmt(hf_dap_lessOrEqual, "<=");
335 x509if_register_fmt(hf_dap_approximateMatch, "=~");
337 x509if_register_fmt(hf_dap_present, "= *");
343 void prefs_register_dap(void) {
345 /* de-register the old port */
346 /* port 102 is registered by TPKT - don't undo this! */
347 if((tcp_port != 102) && tpkt_handle)
348 dissector_delete("tcp.port", tcp_port, tpkt_handle);
350 /* Set our port number for future use */
351 tcp_port = global_dap_tcp_port;
353 if((tcp_port > 0) && (tcp_port != 102) && tpkt_handle)
354 dissector_add("tcp.port", global_dap_tcp_port, tpkt_handle);