Add a missing space in a tooltip.
[obnox/wireshark/wip.git] / epan / dissectors / packet-ldap.c
1 /* Do not modify this file.                                                   */
2 /* It is created automatically by the ASN.1 to Wireshark dissector compiler   */
3 /* packet-ldap.c                                                              */
4 /* ../../tools/asn2wrs.py -b -p ldap -c ldap.cnf -s packet-ldap-template Lightweight-Directory-Access-Protocol-V3.asn */
5
6 /* Input file: packet-ldap-template.c */
7
8 #line 1 "packet-ldap-template.c"
9 /* packet-ldap.c
10  * Routines for ldap packet dissection
11  *
12  * See RFC 1777 (LDAP v2), RFC 2251 (LDAP v3), and RFC 2222 (SASL).
13  *
14  * $Id$
15  *
16  * Wireshark - Network traffic analyzer
17  * By Gerald Combs <gerald@wireshark.org>
18  * Copyright 1998 Gerald Combs
19  *
20  * This program is free software; you can redistribute it and/or
21  * modify it under the terms of the GNU General Public License
22  * as published by the Free Software Foundation; either version 2
23  * of the License, or (at your option) any later version.
24  *
25  * This program is distributed in the hope that it will be useful,
26  * but WITHOUT ANY WARRANTY; without even the implied warranty of
27  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28  * GNU General Public License for more details.
29  *
30  * You should have received a copy of the GNU General Public License
31  * along with this program; if not, write to the Free Software
32  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
33  */
34
35 /*
36  * This is not a complete implementation. It doesn't handle the full version 3, more specifically,
37  * it handles only the commands of version 2, but any additional characteristics of the ver3 command are supported.
38  * It's also missing extensible search filters.
39  *
40  * There should probably be alot more error checking, I simply assume that if we have a full packet, it will be a complete
41  * and correct packet.
42  *
43  * AFAIK, it will handle all messages used by the OpenLDAP 1.2.9 server and libraries which was my goal. I do plan to add
44  * the remaining commands as time permits but this is not a priority to me. Send me an email if you need it and I'll see what
45  * I can do.
46  *
47  * Doug Nazar
48  * nazard@dragoninc.on.ca
49  */
50
51 /*
52  * 11/11/2002 - Fixed problem when decoding LDAP with desegmentation enabled and the
53  *              ASN.1 BER Universal Class Tag: "Sequence Of" header is encapsulated across 2
54  *              TCP segments.
55  *
56  * Ronald W. Henderson
57  * ronald.henderson@cognicaseusa.com
58  */
59
60 /*
61  * 20-JAN-2004 - added decoding of MS-CLDAP netlogon RPC
62  *               using information from the SNIA 2003 conference paper :
63  *               Active Directory Domain Controller Location Service
64  *                    by Anthony Liguori
65  * ronnie sahlberg
66  */
67
68 /*
69  * 17-DEC-2004 - added basic decoding for LDAP Controls
70  * 20-DEC-2004 - added handling for GSS-API encrypted blobs
71  *
72  * Stefan Metzmacher <metze@samba.org>
73  *
74  * 15-NOV-2005 - Changed to use the asn2wrs compiler
75  * Anders Broman <anders.broman@ericsson.com>
76  */
77
78 /*
79  * 3-AUG-2008 - Extended the cldap support to include all netlogon data types.
80  *                              Updated cldap_netlogon_flags to include Windows 2008 flags
81  *                              Expanded the ntver ldap option with bit field
82  *
83  * Gary Reynolds <gazzadownunder@yahoo.co.uk>
84  */
85
86 #ifdef HAVE_CONFIG_H
87 # include "config.h"
88 #endif
89
90 #include <stdio.h>
91 #include <string.h>
92 #include <ctype.h>
93
94 #include <glib.h>
95
96 #include <epan/packet.h>
97 #include <epan/conversation.h>
98 #include <epan/prefs.h>
99 #include <epan/tap.h>
100 #include <epan/emem.h>
101 #include <epan/oids.h>
102 #include <epan/strutil.h>
103 #include <epan/dissectors/packet-tcp.h>
104 #include <epan/dissectors/packet-windows-common.h>
105 #include <epan/dissectors/packet-dcerpc.h>
106 #include <epan/asn1.h>
107
108 #include "packet-frame.h"
109 #include "packet-ldap.h"
110 #include "packet-ntlmssp.h"
111 #include "packet-ssl.h"
112 #include "packet-smb-common.h"
113
114 #include "packet-ber.h"
115 #include "packet-per.h"
116
117 #define PNAME  "Lightweight-Directory-Access-Protocol"
118 #define PSNAME "LDAP"
119 #define PFNAME "ldap"
120
121 /* Initialize the protocol and registered fields */
122 static int ldap_tap = -1;
123 static int proto_ldap = -1;
124 static int proto_cldap = -1;
125
126 static int hf_ldap_sasl_buffer_length = -1;
127 static int hf_ldap_response_in = -1;
128 static int hf_ldap_response_to = -1;
129 static int hf_ldap_time = -1;
130 static int hf_ldap_guid = -1;
131
132 static int hf_mscldap_ntver_flags = -1;
133 static int hf_mscldap_ntver_flags_v1 = -1;
134 static int hf_mscldap_ntver_flags_v5 = -1;
135 static int hf_mscldap_ntver_flags_v5ex = -1;
136 static int hf_mscldap_ntver_flags_v5ip = -1;
137 static int hf_mscldap_ntver_flags_v5cs = -1;
138 static int hf_mscldap_ntver_flags_nt4 = -1;
139 static int hf_mscldap_ntver_flags_pdc = -1;
140 static int hf_mscldap_ntver_flags_local = -1;
141 static int hf_mscldap_ntver_flags_ip = -1;
142 static int hf_mscldap_ntver_flags_gc = -1;
143 static int hf_mscldap_netlogon_ipaddress_family = -1;
144 static int hf_mscldap_netlogon_ipaddress_port = -1;
145 static int hf_mscldap_netlogon_ipaddress = -1;
146 static int hf_mscldap_netlogon_ipaddress_ipv4 = -1;
147 static int hf_mscldap_netlogon_type = -1;
148 static int hf_mscldap_netlogon_length = -1;
149 static int hf_mscldap_netlogon_flags = -1;
150 static int hf_mscldap_netlogon_flags_pdc = -1;
151 static int hf_mscldap_netlogon_flags_gc = -1;
152 static int hf_mscldap_netlogon_flags_ldap = -1;
153 static int hf_mscldap_netlogon_flags_ds = -1;
154 static int hf_mscldap_netlogon_flags_kdc = -1;
155 static int hf_mscldap_netlogon_flags_timeserv = -1;
156 static int hf_mscldap_netlogon_flags_closest = -1;
157 static int hf_mscldap_netlogon_flags_writable = -1;
158 static int hf_mscldap_netlogon_flags_good_timeserv = -1;
159 static int hf_mscldap_netlogon_flags_ndnc = -1;
160 static int hf_mscldap_netlogon_flags_fnc = -1;
161 static int hf_mscldap_netlogon_flags_dnc = -1;
162 static int hf_mscldap_netlogon_flags_dns = -1;
163 static int hf_mscldap_netlogon_flags_wdc = -1;
164 static int hf_mscldap_netlogon_flags_rodc = -1;
165 static int hf_mscldap_domain_guid = -1;
166 static int hf_mscldap_forest = -1;
167 static int hf_mscldap_domain = -1;
168 static int hf_mscldap_hostname = -1;
169 static int hf_mscldap_nb_domain = -1;
170 static int hf_mscldap_nb_hostname = -1;
171 static int hf_mscldap_username = -1;
172 static int hf_mscldap_sitename = -1;
173 static int hf_mscldap_clientsitename = -1;
174 static int hf_mscldap_netlogon_version = -1;
175 static int hf_mscldap_netlogon_lm_token = -1;
176 static int hf_mscldap_netlogon_nt_token = -1;
177 static int hf_ldap_sid = -1;
178 static int hf_ldap_AccessMask_ADS_CREATE_CHILD = -1;
179 static int hf_ldap_AccessMask_ADS_DELETE_CHILD = -1;
180 static int hf_ldap_AccessMask_ADS_LIST = -1;
181 static int hf_ldap_AccessMask_ADS_SELF_WRITE = -1;
182 static int hf_ldap_AccessMask_ADS_READ_PROP = -1;
183 static int hf_ldap_AccessMask_ADS_WRITE_PROP = -1;
184 static int hf_ldap_AccessMask_ADS_DELETE_TREE = -1;
185 static int hf_ldap_AccessMask_ADS_LIST_OBJECT = -1;
186 static int hf_ldap_AccessMask_ADS_CONTROL_ACCESS = -1;
187
188
189 /*--- Included file: packet-ldap-hf.c ---*/
190 #line 1 "packet-ldap-hf.c"
191 static int hf_ldap_LDAPMessage_PDU = -1;          /* LDAPMessage */
192 static int hf_ldap_SearchControlValue_PDU = -1;   /* SearchControlValue */
193 static int hf_ldap_SortKeyList_PDU = -1;          /* SortKeyList */
194 static int hf_ldap_SortResult_PDU = -1;           /* SortResult */
195 static int hf_ldap_ReplControlValue_PDU = -1;     /* ReplControlValue */
196 static int hf_ldap_PasswdModifyRequestValue_PDU = -1;  /* PasswdModifyRequestValue */
197 static int hf_ldap_CancelRequestValue_PDU = -1;   /* CancelRequestValue */
198 static int hf_ldap_messageID = -1;                /* MessageID */
199 static int hf_ldap_protocolOp = -1;               /* ProtocolOp */
200 static int hf_ldap_controls = -1;                 /* Controls */
201 static int hf_ldap_bindRequest = -1;              /* BindRequest */
202 static int hf_ldap_bindResponse = -1;             /* BindResponse */
203 static int hf_ldap_unbindRequest = -1;            /* UnbindRequest */
204 static int hf_ldap_searchRequest = -1;            /* SearchRequest */
205 static int hf_ldap_searchResEntry = -1;           /* SearchResultEntry */
206 static int hf_ldap_searchResDone = -1;            /* SearchResultDone */
207 static int hf_ldap_searchResRef = -1;             /* SearchResultReference */
208 static int hf_ldap_modifyRequest = -1;            /* ModifyRequest */
209 static int hf_ldap_modifyResponse = -1;           /* ModifyResponse */
210 static int hf_ldap_addRequest = -1;               /* AddRequest */
211 static int hf_ldap_addResponse = -1;              /* AddResponse */
212 static int hf_ldap_delRequest = -1;               /* DelRequest */
213 static int hf_ldap_delResponse = -1;              /* DelResponse */
214 static int hf_ldap_modDNRequest = -1;             /* ModifyDNRequest */
215 static int hf_ldap_modDNResponse = -1;            /* ModifyDNResponse */
216 static int hf_ldap_compareRequest = -1;           /* CompareRequest */
217 static int hf_ldap_compareResponse = -1;          /* CompareResponse */
218 static int hf_ldap_abandonRequest = -1;           /* AbandonRequest */
219 static int hf_ldap_extendedReq = -1;              /* ExtendedRequest */
220 static int hf_ldap_extendedResp = -1;             /* ExtendedResponse */
221 static int hf_ldap_AttributeDescriptionList_item = -1;  /* AttributeDescription */
222 static int hf_ldap_attributeDesc = -1;            /* AttributeDescription */
223 static int hf_ldap_assertionValue = -1;           /* AssertionValue */
224 static int hf_ldap_type = -1;                     /* AttributeDescription */
225 static int hf_ldap_vals = -1;                     /* SET_OF_AttributeValue */
226 static int hf_ldap_vals_item = -1;                /* AttributeValue */
227 static int hf_ldap_resultCode = -1;               /* T_resultCode */
228 static int hf_ldap_matchedDN = -1;                /* LDAPDN */
229 static int hf_ldap_errorMessage = -1;             /* ErrorMessage */
230 static int hf_ldap_referral = -1;                 /* Referral */
231 static int hf_ldap_Referral_item = -1;            /* LDAPURL */
232 static int hf_ldap_Controls_item = -1;            /* Control */
233 static int hf_ldap_controlType = -1;              /* ControlType */
234 static int hf_ldap_criticality = -1;              /* BOOLEAN */
235 static int hf_ldap_controlValue = -1;             /* T_controlValue */
236 static int hf_ldap_version = -1;                  /* INTEGER_1_127 */
237 static int hf_ldap_name = -1;                     /* LDAPDN */
238 static int hf_ldap_authentication = -1;           /* AuthenticationChoice */
239 static int hf_ldap_simple = -1;                   /* Simple */
240 static int hf_ldap_sasl = -1;                     /* SaslCredentials */
241 static int hf_ldap_ntlmsspNegotiate = -1;         /* T_ntlmsspNegotiate */
242 static int hf_ldap_ntlmsspAuth = -1;              /* T_ntlmsspAuth */
243 static int hf_ldap_mechanism = -1;                /* Mechanism */
244 static int hf_ldap_credentials = -1;              /* Credentials */
245 static int hf_ldap_bindResponse_resultCode = -1;  /* BindResponse_resultCode */
246 static int hf_ldap_bindResponse_matchedDN = -1;   /* T_bindResponse_matchedDN */
247 static int hf_ldap_serverSaslCreds = -1;          /* ServerSaslCreds */
248 static int hf_ldap_baseObject = -1;               /* LDAPDN */
249 static int hf_ldap_scope = -1;                    /* T_scope */
250 static int hf_ldap_derefAliases = -1;             /* T_derefAliases */
251 static int hf_ldap_sizeLimit = -1;                /* INTEGER_0_maxInt */
252 static int hf_ldap_timeLimit = -1;                /* INTEGER_0_maxInt */
253 static int hf_ldap_typesOnly = -1;                /* BOOLEAN */
254 static int hf_ldap_filter = -1;                   /* T_filter */
255 static int hf_ldap_searchRequest_attributes = -1;  /* AttributeDescriptionList */
256 static int hf_ldap_and = -1;                      /* T_and */
257 static int hf_ldap_and_item = -1;                 /* T_and_item */
258 static int hf_ldap_or = -1;                       /* T_or */
259 static int hf_ldap_or_item = -1;                  /* T_or_item */
260 static int hf_ldap_not = -1;                      /* T_not */
261 static int hf_ldap_equalityMatch = -1;            /* T_equalityMatch */
262 static int hf_ldap_substrings = -1;               /* SubstringFilter */
263 static int hf_ldap_greaterOrEqual = -1;           /* T_greaterOrEqual */
264 static int hf_ldap_lessOrEqual = -1;              /* T_lessOrEqual */
265 static int hf_ldap_present = -1;                  /* T_present */
266 static int hf_ldap_approxMatch = -1;              /* T_approxMatch */
267 static int hf_ldap_extensibleMatch = -1;          /* T_extensibleMatch */
268 static int hf_ldap_substringFilter_substrings = -1;  /* T_substringFilter_substrings */
269 static int hf_ldap_substringFilter_substrings_item = -1;  /* T_substringFilter_substrings_item */
270 static int hf_ldap_initial = -1;                  /* LDAPString */
271 static int hf_ldap_any = -1;                      /* LDAPString */
272 static int hf_ldap_final = -1;                    /* LDAPString */
273 static int hf_ldap_matchingRule = -1;             /* MatchingRuleId */
274 static int hf_ldap_matchValue = -1;               /* AssertionValue */
275 static int hf_ldap_dnAttributes = -1;             /* T_dnAttributes */
276 static int hf_ldap_objectName = -1;               /* LDAPDN */
277 static int hf_ldap_searchResultEntry_attributes = -1;  /* PartialAttributeList */
278 static int hf_ldap_PartialAttributeList_item = -1;  /* PartialAttributeList_item */
279 static int hf_ldap__untag_item = -1;              /* LDAPURL */
280 static int hf_ldap_object = -1;                   /* LDAPDN */
281 static int hf_ldap_modifyRequest_modification = -1;  /* ModifyRequest_modification */
282 static int hf_ldap_modifyRequest_modification_item = -1;  /* T_modifyRequest_modification_item */
283 static int hf_ldap_operation = -1;                /* T_operation */
284 static int hf_ldap_modification = -1;             /* AttributeTypeAndValues */
285 static int hf_ldap_entry = -1;                    /* LDAPDN */
286 static int hf_ldap_attributes = -1;               /* AttributeList */
287 static int hf_ldap_AttributeList_item = -1;       /* AttributeList_item */
288 static int hf_ldap_newrdn = -1;                   /* RelativeLDAPDN */
289 static int hf_ldap_deleteoldrdn = -1;             /* BOOLEAN */
290 static int hf_ldap_newSuperior = -1;              /* LDAPDN */
291 static int hf_ldap_ava = -1;                      /* AttributeValueAssertion */
292 static int hf_ldap_requestName = -1;              /* LDAPOID */
293 static int hf_ldap_requestValue = -1;             /* T_requestValue */
294 static int hf_ldap_extendedResponse_resultCode = -1;  /* ExtendedResponse_resultCode */
295 static int hf_ldap_responseName = -1;             /* ResponseName */
296 static int hf_ldap_response = -1;                 /* OCTET_STRING */
297 static int hf_ldap_size = -1;                     /* INTEGER */
298 static int hf_ldap_cookie = -1;                   /* OCTET_STRING */
299 static int hf_ldap_SortKeyList_item = -1;         /* SortKeyList_item */
300 static int hf_ldap_attributeType = -1;            /* AttributeDescription */
301 static int hf_ldap_orderingRule = -1;             /* MatchingRuleId */
302 static int hf_ldap_reverseOrder = -1;             /* BOOLEAN */
303 static int hf_ldap_sortResult = -1;               /* T_sortResult */
304 static int hf_ldap_parentsFirst = -1;             /* INTEGER */
305 static int hf_ldap_maxReturnLength = -1;          /* INTEGER */
306 static int hf_ldap_userIdentity = -1;             /* OCTET_STRING */
307 static int hf_ldap_oldPasswd = -1;                /* OCTET_STRING */
308 static int hf_ldap_newPasswd = -1;                /* OCTET_STRING */
309 static int hf_ldap_genPasswd = -1;                /* OCTET_STRING */
310 static int hf_ldap_cancelID = -1;                 /* MessageID */
311
312 /*--- End of included file: packet-ldap-hf.c ---*/
313 #line 181 "packet-ldap-template.c"
314
315 /* Initialize the subtree pointers */
316 static gint ett_ldap = -1;
317 static gint ett_ldap_msg = -1;
318 static gint ett_ldap_sasl_blob = -1;
319 static guint ett_ldap_payload = -1;
320 static gint ett_mscldap_netlogon_flags = -1;
321 static gint ett_mscldap_ntver_flags = -1;
322 static gint ett_mscldap_ipdetails = -1;
323
324
325 /*--- Included file: packet-ldap-ett.c ---*/
326 #line 1 "packet-ldap-ett.c"
327 static gint ett_ldap_LDAPMessage = -1;
328 static gint ett_ldap_ProtocolOp = -1;
329 static gint ett_ldap_AttributeDescriptionList = -1;
330 static gint ett_ldap_AttributeValueAssertion = -1;
331 static gint ett_ldap_Attribute = -1;
332 static gint ett_ldap_SET_OF_AttributeValue = -1;
333 static gint ett_ldap_LDAPResult = -1;
334 static gint ett_ldap_Referral = -1;
335 static gint ett_ldap_Controls = -1;
336 static gint ett_ldap_Control = -1;
337 static gint ett_ldap_BindRequest_U = -1;
338 static gint ett_ldap_AuthenticationChoice = -1;
339 static gint ett_ldap_SaslCredentials = -1;
340 static gint ett_ldap_BindResponse_U = -1;
341 static gint ett_ldap_SearchRequest_U = -1;
342 static gint ett_ldap_Filter = -1;
343 static gint ett_ldap_T_and = -1;
344 static gint ett_ldap_T_or = -1;
345 static gint ett_ldap_SubstringFilter = -1;
346 static gint ett_ldap_T_substringFilter_substrings = -1;
347 static gint ett_ldap_T_substringFilter_substrings_item = -1;
348 static gint ett_ldap_MatchingRuleAssertion = -1;
349 static gint ett_ldap_SearchResultEntry_U = -1;
350 static gint ett_ldap_PartialAttributeList = -1;
351 static gint ett_ldap_PartialAttributeList_item = -1;
352 static gint ett_ldap_SEQUENCE_OF_LDAPURL = -1;
353 static gint ett_ldap_ModifyRequest_U = -1;
354 static gint ett_ldap_ModifyRequest_modification = -1;
355 static gint ett_ldap_T_modifyRequest_modification_item = -1;
356 static gint ett_ldap_AttributeTypeAndValues = -1;
357 static gint ett_ldap_AddRequest_U = -1;
358 static gint ett_ldap_AttributeList = -1;
359 static gint ett_ldap_AttributeList_item = -1;
360 static gint ett_ldap_ModifyDNRequest_U = -1;
361 static gint ett_ldap_CompareRequest_U = -1;
362 static gint ett_ldap_ExtendedRequest_U = -1;
363 static gint ett_ldap_ExtendedResponse_U = -1;
364 static gint ett_ldap_SearchControlValue = -1;
365 static gint ett_ldap_SortKeyList = -1;
366 static gint ett_ldap_SortKeyList_item = -1;
367 static gint ett_ldap_SortResult = -1;
368 static gint ett_ldap_ReplControlValue = -1;
369 static gint ett_ldap_PasswdModifyRequestValue = -1;
370 static gint ett_ldap_PasswdModifyResponseValue = -1;
371 static gint ett_ldap_CancelRequestValue = -1;
372
373 /*--- End of included file: packet-ldap-ett.c ---*/
374 #line 192 "packet-ldap-template.c"
375
376 static dissector_table_t ldap_name_dissector_table=NULL;
377 static const char *object_identifier_id = NULL; /* LDAP OID */
378
379 static gboolean do_protocolop = FALSE;
380 static gchar    *attr_type = NULL;
381 static gboolean is_binary_attr_type = FALSE;
382 static guint32 last_frame_seen = 0;
383
384 #define TCP_PORT_LDAP                   389
385 #define TCP_PORT_LDAPS                  636
386 #define UDP_PORT_CLDAP                  389
387 #define TCP_PORT_GLOBALCAT_LDAP         3268 /* Windows 2000 Global Catalog */
388
389 /* desegmentation of LDAP */
390 static gboolean ldap_desegment = TRUE;
391 static guint global_ldap_tcp_port = TCP_PORT_LDAP;
392 static guint global_ldaps_tcp_port = TCP_PORT_LDAPS;
393 static guint tcp_port = 0;
394 static guint ssl_port = 0;
395
396 static dissector_handle_t gssapi_handle = NULL;
397 static dissector_handle_t gssapi_wrap_handle = NULL;
398 static dissector_handle_t ntlmssp_handle = NULL;
399 static dissector_handle_t spnego_handle = NULL;
400 static dissector_handle_t ssl_handle = NULL;
401 static dissector_handle_t ldap_handle = NULL;
402
403 void prefs_register_ldap(void); /* forward declaration for use in preferences registration */
404
405
406 /* different types of rpc calls ontop of ms cldap */
407 #define MSCLDAP_RPC_NETLOGON    1
408
409 /* Message type Choice values */
410 static const value_string ldap_ProtocolOp_choice_vals[] = {
411   {   0, "bindRequest" },
412   {   1, "bindResponse" },
413   {   2, "unbindRequest" },
414   {   3, "searchRequest" },
415   {   4, "searchResEntry" },
416   {   5, "searchResDone" },
417   {       6, "searchResRef" },
418   {   7, "modifyRequest" },
419   {   8, "modifyResponse" },
420   {   9, "addRequest" },
421   {  10, "addResponse" },
422   {  11, "delRequest" },
423   {  12, "delResponse" },
424   {  13, "modDNRequest" },
425   {  14, "modDNResponse" },
426   {  15, "compareRequest" },
427   {  16, "compareResponse" },
428   {  17, "abandonRequest" },
429   {  18, "extendedReq" },
430   {  19, "extendedResp" },
431   { 0, NULL }
432 };
433 /*
434  * Data structure attached to a conversation, giving authentication
435  * information from a bind request.
436  * We keep a linked list of them, so that we can free up all the
437  * authentication mechanism strings.
438  */
439 typedef struct ldap_conv_info_t {
440   struct ldap_conv_info_t *next;
441   guint auth_type;              /* authentication type */
442   char *auth_mech;              /* authentication mechanism */
443   guint32 first_auth_frame;     /* first frame that would use a security layer */
444   GHashTable *unmatched;
445   GHashTable *matched;
446   gboolean is_mscldap;
447   guint32  num_results;
448   gboolean start_tls_pending;
449   guint32  start_tls_frame;
450 } ldap_conv_info_t;
451 static ldap_conv_info_t *ldap_info_items;
452
453 static guint
454 ldap_info_hash_matched(gconstpointer k)
455 {
456   const ldap_call_response_t *key = k;
457
458   return key->messageId;
459 }
460
461 static gint
462 ldap_info_equal_matched(gconstpointer k1, gconstpointer k2)
463 {
464   const ldap_call_response_t *key1 = k1;
465   const ldap_call_response_t *key2 = k2;
466
467   if( key1->req_frame && key2->req_frame && (key1->req_frame!=key2->req_frame) ){
468     return 0;
469   }
470   /* a response may span multiple frames
471   if( key1->rep_frame && key2->rep_frame && (key1->rep_frame!=key2->rep_frame) ){
472     return 0;
473   }
474   */
475
476   return key1->messageId==key2->messageId;
477 }
478
479 static guint
480 ldap_info_hash_unmatched(gconstpointer k)
481 {
482   const ldap_call_response_t *key = k;
483
484   return key->messageId;
485 }
486
487 static gint
488 ldap_info_equal_unmatched(gconstpointer k1, gconstpointer k2)
489 {
490   const ldap_call_response_t *key1 = k1;
491   const ldap_call_response_t *key2 = k2;
492
493   return key1->messageId==key2->messageId;
494 }
495
496
497  /* These are the NtVer flags
498         http://msdn.microsoft.com/en-us/library/cc201035.aspx
499  */
500
501 static const true_false_string tfs_ntver_v1 = {
502         "Client requested V1 netlogon response",
503         "V1 netlogon response not requested"
504 };
505
506 static const true_false_string tfs_ntver_v5 = {
507         "Client requested V5 netlogon response",
508         "V5 netlogon response not requested"
509 };
510 static const true_false_string tfs_ntver_v5ex = {
511         "Client requested V5 extended netlogon response",
512         "V5 extended response not requested"
513 };
514 static const true_false_string tfs_ntver_v5ip = {
515         "Client has requested IP information of the DC",
516         "IP information not requested"
517 };
518 static const true_false_string tfs_ntver_v5cs = {
519         "Client has asked for the closest site information",
520         "Closest site information not requested"
521 };
522 static const true_false_string tfs_ntver_nt4 = {
523         "Client has set Neutralize NT4 emulation",
524         "Only full AD DS requested"
525 };
526 static const true_false_string tfs_ntver_pdc = {
527         "Client has requested the PDC server",
528         "PDC server not requested"
529 };
530 static const true_false_string tfs_ntver_local = {
531         "Client indicated that it is the local machine",
532         "Client is not local"
533 };
534 static const true_false_string tfs_ntver_ip = {
535         "Client has requested IP details (obsolete)",
536         "IP details not requested"
537 };static const true_false_string tfs_ntver_gc = {
538         "Client has requested a Global Catalog server",
539         "Global Catalog not requested"
540 };
541
542
543 static int dissect_mscldap_ntver_flags(proto_tree *parent_tree, tvbuff_t *tvb, int offset)
544 {
545   guint32 flags;
546   proto_item *item;
547   proto_tree *tree=NULL;
548   guint fields[] = { 
549                      hf_mscldap_ntver_flags_v1,
550                      hf_mscldap_ntver_flags_v5,
551                      hf_mscldap_ntver_flags_v5ex,
552                      hf_mscldap_ntver_flags_v5ip,
553                      hf_mscldap_ntver_flags_v5cs,
554                      hf_mscldap_ntver_flags_nt4,
555                      hf_mscldap_ntver_flags_pdc,
556                          hf_mscldap_ntver_flags_ip,
557                      hf_mscldap_ntver_flags_local,
558                      hf_mscldap_ntver_flags_gc,
559                      0 };
560   
561   guint  *field;
562   header_field_info *hfi;
563   gboolean one_bit_set = FALSE;
564
565   flags=tvb_get_letohl(tvb, offset); 
566   item=proto_tree_add_item(parent_tree, hf_mscldap_ntver_flags, tvb, offset, 4, TRUE);
567   if(parent_tree){
568     tree = proto_item_add_subtree(item, ett_mscldap_ntver_flags);
569   }
570
571   proto_item_append_text(item, " (");
572
573   for(field = fields; *field; field++) {
574     proto_tree_add_boolean(tree, *field, tvb, offset, 4, flags);
575     hfi = proto_registrar_get_nth(*field);
576
577     if(flags & hfi->bitmask) {
578
579       if(one_bit_set)
580         proto_item_append_text(item, ", ");
581       else
582         one_bit_set = TRUE;
583
584       proto_item_append_text(item, hfi->name);
585
586     }
587   }
588  
589   proto_item_append_text(item, ")"); 
590
591   offset += 4;
592
593   return offset;
594 }
595
596 /* This string contains the last LDAPString that was decoded */
597 static char *attributedesc_string=NULL;
598
599 /* This string contains the last AssertionValue that was decoded */
600 static char *ldapvalue_string=NULL;
601
602 /* if the octet string contain all printable ASCII characters, then
603  * display it as a string, othervise just display it in hex.
604  */
605 static int
606 dissect_ldap_AssertionValue(gboolean implicit_tag, tvbuff_t *tvb, int offset, asn1_ctx_t *actx _U_, proto_tree *tree, int hf_index)
607 {
608         gint8 class;
609         gboolean pc, ind, is_ascii;
610         gint32 tag;
611         guint32 len, i;
612         const guchar *str;
613
614         if(!implicit_tag){
615                 offset=get_ber_identifier(tvb, offset, &class, &pc, &tag);
616                 offset=get_ber_length(tvb, offset, &len, &ind);
617         } else {
618                 len=tvb_length_remaining(tvb,offset);
619         }
620
621         if(len==0){
622                 return offset;
623         }
624
625
626         /*
627          * Some special/wellknown attributes in common LDAP (read AD)
628          * are neither ascii strings nor blobs of hex data.
629          * Special case these attributes and decode them more nicely.
630          *
631          * Add more special cases as required to prettify further
632          * (there cant be that many ones that are truly interesting)
633          */
634         if(attributedesc_string && !strncmp("DomainSid", attributedesc_string, 9)){
635                 tvbuff_t *sid_tvb;
636                 char *tmpstr;
637
638                 /* this octet string contains an NT SID */
639                 sid_tvb=tvb_new_subset(tvb, offset, len, len);
640                 dissect_nt_sid(sid_tvb, 0, tree, "SID", &tmpstr, hf_index);
641                 ldapvalue_string=tmpstr;
642
643                 goto finished;
644         } else if ( (len==16) /* GUIDs are always 16 bytes */
645         && (attributedesc_string && !strncmp("DomainGuid", attributedesc_string, 10))) {
646                 guint8 drep[4] = { 0x10, 0x00, 0x00, 0x00}; /* fake DREP struct */
647                 e_uuid_t uuid;
648
649                 /* This octet string contained a GUID */
650                 dissect_dcerpc_uuid_t(tvb, offset, actx->pinfo, tree, drep, hf_ldap_guid, &uuid);
651
652                 ldapvalue_string=ep_alloc(1024);
653                 g_snprintf(ldapvalue_string, 1023, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
654                           uuid.Data1, uuid.Data2, uuid.Data3,
655                           uuid.Data4[0], uuid.Data4[1],
656                           uuid.Data4[2], uuid.Data4[3],
657                           uuid.Data4[4], uuid.Data4[5],
658                           uuid.Data4[6], uuid.Data4[7]);
659
660                 goto finished;
661         } else if (attributedesc_string && !strncmp("NtVer", attributedesc_string, 5)){
662                 guint32 flags;
663
664                 len = 0;
665                 /* get flag value to populate ldapvalue_string */
666                 flags=tvb_get_letohl(tvb, offset);
667                 
668                 ldapvalue_string=ep_alloc(1024);
669                 g_snprintf(ldapvalue_string, 1023, "0x%08x",flags);
670
671                 /* populate bitmask subtree */
672                 offset = dissect_mscldap_ntver_flags(tree, tvb, offset);
673
674                 goto finished;
675
676
677         }
678
679         /*
680          * It was not one of our "wellknown" attributes so make the best
681          * we can and just try to see if it is an ascii string or if it
682          * is a binary blob.
683          *
684          * XXX - should we support reading RFC 2252-style schemas
685          * for LDAP, and using that to determine how to display
686          * attribute values and assertion values?
687          *
688          * -- I dont think there are full schemas available that describe the
689          *  interesting cases i.e. AD -- ronnie
690          */
691         str=tvb_get_ptr(tvb, offset, len);
692         is_ascii=TRUE;
693         for(i=0;i<len;i++){
694                 if(!isascii(str[i]) || !isprint(str[i])){
695                         is_ascii=FALSE;
696                         break;
697                 }
698         }
699
700         /* convert the string into a printable string */
701         if(is_ascii){
702                 ldapvalue_string=ep_alloc(len+1);
703                 memcpy(ldapvalue_string,str,len);
704                 ldapvalue_string[i]=0;
705         } else {
706                 ldapvalue_string=ep_alloc(3*len);
707                 for(i=0;i<len;i++){
708                         g_snprintf(ldapvalue_string+i*3,3,"%02x",str[i]&0xff);
709                         ldapvalue_string[3*i+2]=':';
710                 }
711                 ldapvalue_string[3*len-1]=0;
712         }
713
714         proto_tree_add_string(tree, hf_index, tvb, offset, len, ldapvalue_string);
715
716
717 finished:
718         offset+=len;
719         return offset;
720 }
721
722 /* This string contains the last Filter item that was decoded */
723 static char *Filter_string=NULL;
724 static char *and_filter_string=NULL;
725 static char *or_filter_string=NULL;
726 static char *substring_value=NULL;
727 static char *substring_item_init=NULL;
728 static char *substring_item_any=NULL;
729 static char *substring_item_final=NULL;
730 static char *matching_rule_string=NULL;
731 static gboolean matching_rule_dnattr=FALSE;
732
733 /* Global variables */
734 char *mechanism = NULL;
735 static gint MessageID =-1;
736 static gint ProtocolOp = -1;
737 static gint result = 0;
738 static proto_item *ldm_tree = NULL; /* item to add text to */
739
740 static void ldap_do_protocolop(packet_info *pinfo)
741 {
742   const gchar* valstr;
743
744   if (do_protocolop)  {
745
746     valstr = val_to_str(ProtocolOp, ldap_ProtocolOp_choice_vals, "Unknown (%%u)");
747
748     if(check_col(pinfo->cinfo, COL_INFO))
749       col_append_fstr(pinfo->cinfo, COL_INFO, "%s(%u) ", valstr, MessageID);
750
751     if(ldm_tree)
752       proto_item_append_text(ldm_tree, " %s(%d)", valstr, MessageID);
753
754     do_protocolop = FALSE;
755
756   }
757 }
758
759 static ldap_call_response_t *
760 ldap_match_call_response(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint messageId, guint protocolOpTag)
761 {
762   ldap_call_response_t lcr, *lcrp=NULL;
763   ldap_conv_info_t *ldap_info = (ldap_conv_info_t *)pinfo->private_data;
764
765   /* first see if we have already matched this */
766
767       lcr.messageId=messageId;
768       switch(protocolOpTag){
769         case LDAP_REQ_BIND:
770         case LDAP_REQ_SEARCH:
771         case LDAP_REQ_MODIFY:
772         case LDAP_REQ_ADD:
773         case LDAP_REQ_DELETE:
774         case LDAP_REQ_MODRDN:
775         case LDAP_REQ_COMPARE:
776         case LDAP_REQ_EXTENDED:
777           lcr.is_request=TRUE;
778           lcr.req_frame=pinfo->fd->num;
779           lcr.rep_frame=0;
780           break;
781         case LDAP_RES_BIND:
782         case LDAP_RES_SEARCH_ENTRY:
783         case LDAP_RES_SEARCH_REF:
784         case LDAP_RES_SEARCH_RESULT:
785         case LDAP_RES_MODIFY:
786         case LDAP_RES_ADD:
787         case LDAP_RES_DELETE:
788         case LDAP_RES_MODRDN:
789         case LDAP_RES_COMPARE:
790         case LDAP_RES_EXTENDED:
791           lcr.is_request=FALSE;
792           lcr.req_frame=0;
793           lcr.rep_frame=pinfo->fd->num;
794           break;
795       }
796       lcrp=g_hash_table_lookup(ldap_info->matched, &lcr);
797
798       if(lcrp){
799
800         lcrp->is_request=lcr.is_request;
801
802       } else {
803
804                   /* we haven't found a match - try and match it up */
805
806   switch(protocolOpTag){
807       case LDAP_REQ_BIND:
808       case LDAP_REQ_SEARCH:
809       case LDAP_REQ_MODIFY:
810       case LDAP_REQ_ADD:
811       case LDAP_REQ_DELETE:
812       case LDAP_REQ_MODRDN:
813       case LDAP_REQ_COMPARE:
814       case LDAP_REQ_EXTENDED:
815
816                 /* this a a request - add it to the unmatched list */
817
818         /* check that we dont already have one of those in the
819            unmatched list and if so remove it */
820
821         lcr.messageId=messageId;
822         lcrp=g_hash_table_lookup(ldap_info->unmatched, &lcr);
823         if(lcrp){
824           g_hash_table_remove(ldap_info->unmatched, lcrp);
825         }
826         /* if we cant reuse the old one, grab a new chunk */
827         if(!lcrp){
828           lcrp=se_alloc(sizeof(ldap_call_response_t));
829         }
830         lcrp->messageId=messageId;
831         lcrp->req_frame=pinfo->fd->num;
832         lcrp->req_time=pinfo->fd->abs_ts;
833         lcrp->rep_frame=0;
834         lcrp->protocolOpTag=protocolOpTag;
835         lcrp->is_request=TRUE;
836         g_hash_table_insert(ldap_info->unmatched, lcrp, lcrp);
837         return NULL;
838         break;
839       case LDAP_RES_BIND:
840       case LDAP_RES_SEARCH_ENTRY:
841       case LDAP_RES_SEARCH_REF:
842       case LDAP_RES_SEARCH_RESULT:
843       case LDAP_RES_MODIFY:
844       case LDAP_RES_ADD:
845       case LDAP_RES_DELETE:
846       case LDAP_RES_MODRDN:
847       case LDAP_RES_COMPARE:
848       case LDAP_RES_EXTENDED:
849
850                 /* this is a result - it should be in our unmatched list */
851
852         lcr.messageId=messageId;
853         lcrp=g_hash_table_lookup(ldap_info->unmatched, &lcr);
854
855         if(lcrp){
856
857           if(!lcrp->rep_frame){
858             g_hash_table_remove(ldap_info->unmatched, lcrp);
859             lcrp->rep_frame=pinfo->fd->num;
860             lcrp->is_request=FALSE;
861             g_hash_table_insert(ldap_info->matched, lcrp, lcrp);
862           }
863         }
864
865         break;
866           }
867
868         }
869     /* we have found a match */
870
871     if(lcrp){
872       proto_item *it;
873
874       if(lcrp->is_request){
875         it=proto_tree_add_uint(tree, hf_ldap_response_in, tvb, 0, 0, lcrp->rep_frame);
876         PROTO_ITEM_SET_GENERATED(it);
877       } else {
878         nstime_t ns;
879         it=proto_tree_add_uint(tree, hf_ldap_response_to, tvb, 0, 0, lcrp->req_frame);
880         PROTO_ITEM_SET_GENERATED(it);
881         nstime_delta(&ns, &pinfo->fd->abs_ts, &lcrp->req_time);
882         it=proto_tree_add_time(tree, hf_ldap_time, tvb, 0, 0, &ns);
883         PROTO_ITEM_SET_GENERATED(it);
884       }
885     }
886
887     return lcrp;
888 }
889
890
891 /*--- Included file: packet-ldap-fn.c ---*/
892 #line 1 "packet-ldap-fn.c"
893 /*--- Cyclic dependencies ---*/
894
895 /* Filter -> Filter/and -> Filter/and/_item -> Filter */
896 /* Filter -> Filter/or -> Filter/or/_item -> Filter */
897 /* Filter -> Filter/not -> Filter */
898 static int dissect_ldap_Filter(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_);
899
900
901
902
903 static int
904 dissect_ldap_MessageID(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
905 #line 92 "ldap.cnf"
906
907     offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
908                                                 &MessageID);
909
910
911   ldm_tree = tree;
912
913
914
915   return offset;
916 }
917
918
919
920 static int
921 dissect_ldap_INTEGER_1_127(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
922   offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
923                                                 NULL);
924
925   return offset;
926 }
927
928
929
930 static int
931 dissect_ldap_LDAPString(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
932 #line 322 "ldap.cnf"
933   tvbuff_t      *parameter_tvb = NULL;
934   char          *ldapstring = NULL;
935   gchar         *sc = NULL; /* semi-colon pointer */
936
937     offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index,
938                                        &parameter_tvb);
939
940
941   if (parameter_tvb || (hf_index == hf_ldap_baseObject)) {
942
943      ldap_do_protocolop(actx->pinfo);
944
945      if(parameter_tvb)
946         ldapstring = tvb_get_ephemeral_string(parameter_tvb, 0, tvb_length_remaining(parameter_tvb, 0));
947
948      if(hf_index == hf_ldap_baseObject) {
949         /* this is search - put it on the scanline */
950         if(!ldapstring || !*ldapstring)
951           ldapstring = "<ROOT>";
952
953         if(check_col(actx->pinfo->cinfo, COL_INFO))
954           col_append_fstr(actx->pinfo->cinfo, COL_INFO, "\"%s\" ", ldapstring);
955
956         if(ldm_tree)
957           proto_item_append_text(ldm_tree, " \"%s\"", ldapstring);
958
959
960         if(!parameter_tvb) {
961
962           proto_item_append_text(actx->created_item, " (%s)", ldapstring);
963         }
964
965      } else if ((hf_index == hf_ldap_errorMessage) && ldapstring && *ldapstring) { /* only show message if not success */
966         if(check_col(actx->pinfo->cinfo, COL_INFO))
967           col_append_fstr(actx->pinfo->cinfo, COL_INFO, "(%s) ", ldapstring);
968
969         if(ldm_tree)
970           proto_item_append_text(ldm_tree, " (%s)", ldapstring);
971
972      } else if ((hf_index == hf_ldap_objectName) ||
973                 (hf_index == hf_ldap_name) ||
974                 (hf_index == hf_ldap_entry) ||
975                 (hf_index == hf_ldap_object) ||
976                 (hf_index == hf_ldap_delRequest) ) {
977
978         if(!ldapstring || !*ldapstring)
979           ldapstring = "<ROOT>";
980
981         if(check_col(actx->pinfo->cinfo, COL_INFO))
982           col_append_fstr(actx->pinfo->cinfo, COL_INFO, "\"%s\" ", ldapstring);
983
984         if(ldm_tree)
985           proto_item_append_text(ldm_tree, " \"%s\"", ldapstring);
986      } else if (hf_index == hf_ldap_attributeDesc){
987         /* remember the attribute description */
988         attributedesc_string=ldapstring;
989      } else if (hf_index == hf_ldap_initial){
990         /* remember the substring item */
991         substring_item_init=ldapstring;
992      } else if (hf_index == hf_ldap_any){
993         /* remember the substring item */
994         substring_item_any=ldapstring;
995      } else if (hf_index == hf_ldap_final){
996         /* remember the substring item */
997         substring_item_final=ldapstring;
998      } else if (hf_index == hf_ldap_matchingRule){
999         /* remember the matching rule */
1000         matching_rule_string=ldapstring;
1001      } else if (hf_index == hf_ldap_present){
1002         /* remember the present name */
1003         Filter_string=ldapstring;
1004      } else if (hf_index == hf_ldap_type) {
1005         /* remember attribute type name */
1006         attr_type = ep_strdup(ldapstring);
1007
1008         /* append it to the parent entry */
1009         proto_item_append_text(tree, " %s", attr_type);
1010
1011         /* remove the ";binary" component if present */
1012         if((sc = strchr(attr_type, ';')) != NULL) {
1013                 if(!strcmp(sc, ";binary")) {
1014                         *sc = '\0'; /* terminate the string */
1015                         is_binary_attr_type = TRUE;
1016                 }
1017         } else {
1018                 is_binary_attr_type = FALSE;
1019         }
1020
1021      }
1022
1023   }
1024
1025
1026
1027   return offset;
1028 }
1029
1030
1031
1032 static int
1033 dissect_ldap_LDAPDN(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1034   offset = dissect_ldap_LDAPString(implicit_tag, tvb, offset, actx, tree, hf_index);
1035
1036   return offset;
1037 }
1038
1039
1040
1041 static int
1042 dissect_ldap_Simple(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1043 #line 163 "ldap.cnf"
1044 ldap_conv_info_t *ldap_info;
1045
1046   offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index,
1047                                        NULL);
1048
1049
1050         ldap_info = actx->pinfo->private_data;
1051         ldap_info->auth_type = LDAP_AUTH_SIMPLE;
1052
1053         actx->pinfo->private_data = ldap_info;
1054
1055
1056
1057   return offset;
1058 }
1059
1060
1061
1062 static int
1063 dissect_ldap_Mechanism(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1064 #line 173 "ldap.cnf"
1065
1066 ldap_conv_info_t *ldap_info;
1067 tvbuff_t        *parameter_tvb;
1068 char *mechanism = NULL;
1069   offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index,
1070                                        &parameter_tvb);
1071
1072         ldap_info = actx->pinfo->private_data;
1073         ldap_info->auth_type = LDAP_AUTH_SASL;
1074
1075         if (!parameter_tvb)
1076                 return offset;
1077
1078     /*
1079      * We need to remember the authentication type and mechanism for this
1080      * conversation.
1081      *
1082      * XXX - actually, we might need to remember more than one
1083      * type and mechanism, if you can unbind and rebind with a
1084      * different type and/or mechanism.
1085      */
1086     if(!actx->pinfo->fd->flags.visited) {
1087         mechanism = tvb_get_string(parameter_tvb, 0, tvb_length_remaining(parameter_tvb,0));
1088         ldap_info->first_auth_frame = 0;        /* not known until we see the bind reply */
1089         /*
1090          * If the mechanism in this request is an empty string (which is
1091          * returned as a null pointer), use the saved mechanism instead.
1092          * Otherwise, if the saved mechanism is an empty string (null),
1093          * save this mechanism.
1094          */
1095         if (mechanism == NULL) {
1096             mechanism = ldap_info->auth_mech;
1097         } else {
1098           if (ldap_info->auth_mech != NULL) {
1099               g_free(ldap_info->auth_mech);
1100           }
1101           ldap_info->auth_mech = mechanism;
1102         }
1103         actx->pinfo->private_data = ldap_info;
1104     }
1105
1106
1107   return offset;
1108 }
1109
1110
1111
1112 static int
1113 dissect_ldap_Credentials(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1114 #line 212 "ldap.cnf"
1115
1116 tvbuff_t        *parameter_tvb;
1117 ldap_conv_info_t *ldap_info;
1118 gint8 class;
1119 gboolean pc;
1120 gint32 tag;
1121
1122   offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index,
1123                                        &parameter_tvb);
1124
1125
1126         if (!parameter_tvb)
1127                 return offset;
1128
1129         ldap_info = actx->pinfo->private_data;
1130         get_ber_identifier(parameter_tvb, 0, &class, &pc, &tag);
1131
1132         /*if ((ldap_info->auth_mech != NULL) && (strcmp(ldap_info->auth_mech, "GSS-SPNEGO") == 0) && (class==BER_CLASS_CON)) {*/
1133         if ((ldap_info->auth_mech != NULL) && (class==BER_CLASS_CON)) {
1134           /*
1135            * This is a GSS-API token ancapsulated within GSS-SPNEGO.
1136            * We need to check the first byte to check whether the blob
1137            * contains SPNEGO or GSSAPI.
1138            * All SPNEGO PDUs are of class CONSTRUCTED while
1139            * GSS PDUs are class APPLICATION
1140            */
1141           if (parameter_tvb && (tvb_length(parameter_tvb) > 0))
1142             call_dissector(spnego_handle, parameter_tvb, actx->pinfo, tree);
1143         }
1144         /*if ((ldap_info->auth_mech != NULL) && ((strcmp(ldap_info->auth_mech, "GSSAPI") == 0) || (class==BER_CLASS_APP))) {*/
1145         if ((ldap_info->auth_mech != NULL) && (class==BER_CLASS_APP)) {
1146           /*
1147            * This is a raw GSS-API token.
1148            */
1149           if (parameter_tvb && (tvb_length(parameter_tvb) > 0)) {
1150             call_dissector(gssapi_handle, parameter_tvb, actx->pinfo, tree);
1151           }
1152         }
1153         actx->pinfo->private_data = ldap_info;
1154
1155
1156
1157
1158   return offset;
1159 }
1160
1161
1162 static const ber_sequence_t SaslCredentials_sequence[] = {
1163   { &hf_ldap_mechanism      , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_ldap_Mechanism },
1164   { &hf_ldap_credentials    , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_OPTIONAL|BER_FLAGS_NOOWNTAG, dissect_ldap_Credentials },
1165   { NULL, 0, 0, 0, NULL }
1166 };
1167
1168 static int
1169 dissect_ldap_SaslCredentials(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1170   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
1171                                    SaslCredentials_sequence, hf_index, ett_ldap_SaslCredentials);
1172
1173   return offset;
1174 }
1175
1176
1177
1178 static int
1179 dissect_ldap_T_ntlmsspNegotiate(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1180 #line 697 "ldap.cnf"
1181         /* make sure the protocol op comes first */
1182         ldap_do_protocolop(actx->pinfo);
1183
1184         call_dissector(ntlmssp_handle, tvb, actx->pinfo, tree);
1185         offset+=tvb_length_remaining(tvb, offset);
1186
1187
1188
1189   return offset;
1190 }
1191
1192
1193
1194 static int
1195 dissect_ldap_T_ntlmsspAuth(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1196 #line 704 "ldap.cnf"
1197         /* make sure the protocol op comes first */
1198         ldap_do_protocolop(actx->pinfo);
1199
1200         call_dissector(ntlmssp_handle, tvb, actx->pinfo, tree);
1201         offset+=tvb_length_remaining(tvb, offset);
1202
1203
1204
1205   return offset;
1206 }
1207
1208
1209 static const value_string ldap_AuthenticationChoice_vals[] = {
1210   {   0, "simple" },
1211   {   3, "sasl" },
1212   {  10, "ntlmsspNegotiate" },
1213   {  11, "ntlmsspAuth" },
1214   { 0, NULL }
1215 };
1216
1217 static const ber_choice_t AuthenticationChoice_choice[] = {
1218   {   0, &hf_ldap_simple         , BER_CLASS_CON, 0, BER_FLAGS_IMPLTAG, dissect_ldap_Simple },
1219   {   3, &hf_ldap_sasl           , BER_CLASS_CON, 3, BER_FLAGS_IMPLTAG, dissect_ldap_SaslCredentials },
1220   {  10, &hf_ldap_ntlmsspNegotiate, BER_CLASS_CON, 10, BER_FLAGS_IMPLTAG, dissect_ldap_T_ntlmsspNegotiate },
1221   {  11, &hf_ldap_ntlmsspAuth    , BER_CLASS_CON, 11, BER_FLAGS_IMPLTAG, dissect_ldap_T_ntlmsspAuth },
1222   { 0, NULL, 0, 0, 0, NULL }
1223 };
1224
1225 static int
1226 dissect_ldap_AuthenticationChoice(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1227 #line 497 "ldap.cnf"
1228   gint branch = -1;
1229   gint auth = -1;
1230   const gchar *valstr;
1231
1232     offset = dissect_ber_choice(actx, tree, tvb, offset,
1233                                  AuthenticationChoice_choice, hf_index, ett_ldap_AuthenticationChoice,
1234                                  &branch);
1235
1236
1237   ldap_do_protocolop(actx->pinfo);
1238
1239   if((branch > -1) && (branch < (gint)(sizeof AuthenticationChoice_choice/sizeof AuthenticationChoice_choice[0])))
1240     auth = AuthenticationChoice_choice[branch].value;
1241
1242   valstr = val_to_str(auth, ldap_AuthenticationChoice_vals, "Unknown auth(%u)");
1243
1244   /* If auth is NTLM (10 or 11) don't add to column as the NTLM dissection will do this */
1245   if (check_col(actx->pinfo->cinfo, COL_INFO) && (auth !=  10) && (auth != 11))
1246     col_append_fstr(actx->pinfo->cinfo, COL_INFO, "%s ", valstr);
1247
1248   if(ldm_tree)
1249     proto_item_append_text(ldm_tree, " %s", valstr);
1250
1251
1252
1253
1254   return offset;
1255 }
1256
1257
1258 static const ber_sequence_t BindRequest_U_sequence[] = {
1259   { &hf_ldap_version        , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_ldap_INTEGER_1_127 },
1260   { &hf_ldap_name           , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_ldap_LDAPDN },
1261   { &hf_ldap_authentication , BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_ldap_AuthenticationChoice },
1262   { NULL, 0, 0, 0, NULL }
1263 };
1264
1265 static int
1266 dissect_ldap_BindRequest_U(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1267   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
1268                                    BindRequest_U_sequence, hf_index, ett_ldap_BindRequest_U);
1269
1270   return offset;
1271 }
1272
1273
1274
1275 static int
1276 dissect_ldap_BindRequest(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1277   offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
1278                                       hf_index, BER_CLASS_APP, 0, TRUE, dissect_ldap_BindRequest_U);
1279
1280   return offset;
1281 }
1282
1283
1284 static const value_string ldap_BindResponse_resultCode_vals[] = {
1285   {   0, "success" },
1286   {   1, "operationsError" },
1287   {   2, "protocolError" },
1288   {   3, "timeLimitExceeded" },
1289   {   4, "sizeLimitExceeded" },
1290   {   5, "compareFalse" },
1291   {   6, "compareTrue" },
1292   {   7, "authMethodNotSupported" },
1293   {   8, "strongAuthRequired" },
1294   {  10, "referral" },
1295   {  11, "adminLimitExceeded" },
1296   {  12, "unavailableCriticalExtension" },
1297   {  13, "confidentialityRequired" },
1298   {  14, "saslBindInProgress" },
1299   {  16, "noSuchAttribute" },
1300   {  17, "undefinedAttributeType" },
1301   {  18, "inappropriateMatching" },
1302   {  19, "constraintViolation" },
1303   {  20, "attributeOrValueExists" },
1304   {  21, "invalidAttributeSyntax" },
1305   {  32, "noSuchObject" },
1306   {  33, "aliasProblem" },
1307   {  34, "invalidDNSyntax" },
1308   {  36, "aliasDereferencingProblem" },
1309   {  48, "inappropriateAuthentication" },
1310   {  49, "invalidCredentials" },
1311   {  50, "insufficientAccessRights" },
1312   {  51, "busy" },
1313   {  52, "unavailable" },
1314   {  53, "unwillingToPerform" },
1315   {  54, "loopDetect" },
1316   {  64, "namingViolation" },
1317   {  65, "objectClassViolation" },
1318   {  66, "notAllowedOnNonLeaf" },
1319   {  67, "notAllowedOnRDN" },
1320   {  68, "entryAlreadyExists" },
1321   {  69, "objectClassModsProhibited" },
1322   {  71, "affectsMultipleDSAs" },
1323   {  80, "other" },
1324   { 118, "canceled" },
1325   { 119, "noSuchOperation" },
1326   { 120, "tooLate" },
1327   { 121, "cannotCancel" },
1328   { 0, NULL }
1329 };
1330
1331
1332 static int
1333 dissect_ldap_BindResponse_resultCode(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1334 #line 447 "ldap.cnf"
1335
1336   const gchar *valstr;
1337
1338     offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
1339                                   &result);
1340
1341
1342   ldap_do_protocolop(actx->pinfo);
1343
1344   valstr = val_to_str(result, ldap_BindResponse_resultCode_vals, "Unknown result(%u)");
1345
1346   if (check_col(actx->pinfo->cinfo, COL_INFO))
1347     col_append_fstr(actx->pinfo->cinfo, COL_INFO, "%s ", valstr);
1348
1349   if(ldm_tree)
1350     proto_item_append_text(ldm_tree, " %s", valstr);
1351
1352
1353
1354
1355   return offset;
1356 }
1357
1358
1359
1360 static int
1361 dissect_ldap_T_bindResponse_matchedDN(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1362 #line 711 "ldap.cnf"
1363         tvbuff_t *new_tvb=NULL;
1364
1365         offset = dissect_ber_octet_string(FALSE, actx, tree, tvb, offset, hf_ldap_matchedDN, &new_tvb);
1366
1367         if(  new_tvb
1368         &&  (tvb_length(new_tvb)>=7)
1369         &&  (!tvb_memeql(new_tvb, 0, "NTLMSSP", 7))){
1370
1371                 /* make sure the protocol op comes first */
1372                 ldap_do_protocolop(actx->pinfo);
1373
1374                 call_dissector(ntlmssp_handle, new_tvb, actx->pinfo, tree);
1375         }
1376         return offset;
1377
1378
1379
1380   return offset;
1381 }
1382
1383
1384
1385 static int
1386 dissect_ldap_ErrorMessage(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1387   offset = dissect_ldap_LDAPString(implicit_tag, tvb, offset, actx, tree, hf_index);
1388
1389   return offset;
1390 }
1391
1392
1393
1394 static int
1395 dissect_ldap_LDAPURL(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1396   offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index,
1397                                        NULL);
1398
1399 #line 43 "ldap.cnf"
1400         PROTO_ITEM_SET_URL(actx->created_item);
1401
1402
1403   return offset;
1404 }
1405
1406
1407 static const ber_sequence_t Referral_sequence_of[1] = {
1408   { &hf_ldap_Referral_item  , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_ldap_LDAPURL },
1409 };
1410
1411 static int
1412 dissect_ldap_Referral(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1413   offset = dissect_ber_sequence_of(implicit_tag, actx, tree, tvb, offset,
1414                                       Referral_sequence_of, hf_index, ett_ldap_Referral);
1415
1416   return offset;
1417 }
1418
1419
1420
1421 static int
1422 dissect_ldap_ServerSaslCreds(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1423 #line 252 "ldap.cnf"
1424
1425 tvbuff_t        *parameter_tvb;
1426 ldap_conv_info_t *ldap_info;
1427
1428   offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index,
1429                                        &parameter_tvb);
1430
1431         if (!parameter_tvb)
1432                 return offset;
1433         ldap_info = actx->pinfo->private_data;
1434     switch (ldap_info->auth_type) {
1435
1436       /* For Kerberos V4, dissect it as a ticket. */
1437       /* XXX - what about LDAP_AUTH_SIMPLE? */
1438
1439     case LDAP_AUTH_SASL:
1440       /*
1441        * All frames after this are assumed to use a security layer.
1442        *
1443        * XXX - won't work if there's another reply, with the security
1444        * layer, starting in the same TCP segment that ends this
1445        * reply, but as LDAP is a request/response protocol, and
1446        * as the client probably can't start using authentication until
1447        * it gets the bind reply and the server won't send a reply until
1448        * it gets a request, that probably won't happen.
1449        *
1450        * XXX - that assumption is invalid; it's not clear where the
1451        * hell you find out whether there's any security layer.  In
1452        * one capture, we have two GSS-SPNEGO negotiations, both of
1453        * which select MS KRB5, and the only differences in the tokens
1454        * is in the RC4-HMAC ciphertext.  The various
1455        * draft-ietf--cat-sasl-gssapi-NN.txt drafts seem to imply
1456        * that the RFC 2222 spoo with the bitmask and maximum
1457        * output message size stuff is done - but where does that
1458        * stuff show up?  Is it in the ciphertext, which means it's
1459        * presumably encrypted?
1460        *
1461        * Grrr.  We have to do a gross heuristic, checking whether the
1462        * putative LDAP message begins with 0x00 or not, making the
1463        * assumption that we won't have more than 2^24 bytes of
1464        * encapsulated stuff.
1465        */
1466       ldap_info->first_auth_frame = actx->pinfo->fd->num + 1;
1467       if (ldap_info->auth_mech != NULL &&
1468           strcmp(ldap_info->auth_mech, "GSS-SPNEGO") == 0) {
1469         /* It could be the second leg of GSS-SPNEGO wrapping NTLMSSP
1470          * which might not be wrapped in GSS-SPNEGO but be a raw
1471          * NTLMSSP blob
1472          */
1473         if ( (tvb_length(parameter_tvb)>=7)
1474         &&   (!tvb_memeql(parameter_tvb, 0, "NTLMSSP", 7))){
1475           call_dissector(ntlmssp_handle, parameter_tvb, actx->pinfo, tree);
1476           break;
1477         }
1478         /*
1479          * This is a GSS-API token.
1480          */
1481         if(parameter_tvb && (tvb_length(parameter_tvb) > 0))
1482           call_dissector(spnego_handle, parameter_tvb, actx->pinfo, tree);
1483       } else if (ldap_info->auth_mech != NULL &&
1484           strcmp(ldap_info->auth_mech, "GSSAPI") == 0) {
1485         /*
1486          * This is a GSS-API token.
1487          */
1488         if(parameter_tvb && (tvb_length(parameter_tvb) > 0))
1489           call_dissector(gssapi_handle, parameter_tvb, actx->pinfo, tree);
1490                 }
1491         break;
1492         }
1493         actx->pinfo->private_data = ldap_info;
1494
1495
1496
1497   return offset;
1498 }
1499
1500
1501 static const ber_sequence_t BindResponse_U_sequence[] = {
1502   { &hf_ldap_bindResponse_resultCode, BER_CLASS_UNI, BER_UNI_TAG_ENUMERATED, BER_FLAGS_NOOWNTAG, dissect_ldap_BindResponse_resultCode },
1503   { &hf_ldap_bindResponse_matchedDN, BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_ldap_T_bindResponse_matchedDN },
1504   { &hf_ldap_errorMessage   , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_ldap_ErrorMessage },
1505   { &hf_ldap_referral       , BER_CLASS_CON, 3, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_ldap_Referral },
1506   { &hf_ldap_serverSaslCreds, BER_CLASS_CON, 7, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_ldap_ServerSaslCreds },
1507   { NULL, 0, 0, 0, NULL }
1508 };
1509
1510 static int
1511 dissect_ldap_BindResponse_U(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1512   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
1513                                    BindResponse_U_sequence, hf_index, ett_ldap_BindResponse_U);
1514
1515   return offset;
1516 }
1517
1518
1519
1520 static int
1521 dissect_ldap_BindResponse(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1522   offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
1523                                       hf_index, BER_CLASS_APP, 1, TRUE, dissect_ldap_BindResponse_U);
1524
1525   return offset;
1526 }
1527
1528
1529
1530 static int
1531 dissect_ldap_NULL(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1532   offset = dissect_ber_null(implicit_tag, actx, tree, tvb, offset, hf_index);
1533
1534   return offset;
1535 }
1536
1537
1538
1539 static int
1540 dissect_ldap_UnbindRequest(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1541 #line 519 "ldap.cnf"
1542
1543  implicit_tag = TRUE; /* correct problem with asn2wrs */
1544
1545    offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
1546                                       hf_index, BER_CLASS_APP, 2, TRUE, dissect_ldap_NULL);
1547
1548
1549  ldap_do_protocolop(actx->pinfo);
1550
1551
1552
1553
1554
1555
1556
1557   return offset;
1558 }
1559
1560
1561 static const value_string ldap_T_scope_vals[] = {
1562   {   0, "baseObject" },
1563   {   1, "singleLevel" },
1564   {   2, "wholeSubtree" },
1565   { 0, NULL }
1566 };
1567
1568
1569 static int
1570 dissect_ldap_T_scope(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1571 #line 413 "ldap.cnf"
1572
1573   gint  scope;
1574   const gchar *valstr;
1575
1576     offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
1577                                   &scope);
1578
1579
1580   ldap_do_protocolop(actx->pinfo);
1581
1582   valstr = val_to_str(scope, ldap_T_scope_vals, "Unknown scope(%u)");
1583
1584   if (check_col(actx->pinfo->cinfo, COL_INFO))
1585     col_append_fstr(actx->pinfo->cinfo, COL_INFO, "%s ", valstr);
1586
1587   if(ldm_tree)
1588     proto_item_append_text(ldm_tree, " %s", valstr);
1589
1590
1591
1592   return offset;
1593 }
1594
1595
1596 static const value_string ldap_T_derefAliases_vals[] = {
1597   {   0, "neverDerefAliases" },
1598   {   1, "derefInSearching" },
1599   {   2, "derefFindingBaseObj" },
1600   {   3, "derefAlways" },
1601   { 0, NULL }
1602 };
1603
1604
1605 static int
1606 dissect_ldap_T_derefAliases(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1607   offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
1608                                   NULL);
1609
1610   return offset;
1611 }
1612
1613
1614
1615 static int
1616 dissect_ldap_INTEGER_0_maxInt(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1617   offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
1618                                                 NULL);
1619
1620   return offset;
1621 }
1622
1623
1624
1625 static int
1626 dissect_ldap_BOOLEAN(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1627   offset = dissect_ber_boolean(implicit_tag, actx, tree, tvb, offset, hf_index, NULL);
1628
1629   return offset;
1630 }
1631
1632
1633
1634 static int
1635 dissect_ldap_T_and_item(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1636   offset = dissect_ldap_Filter(implicit_tag, tvb, offset, actx, tree, hf_index);
1637
1638 #line 569 "ldap.cnf"
1639         if(and_filter_string){
1640                 and_filter_string=ep_strdup_printf("(&%s%s)",and_filter_string,Filter_string);
1641         } else {
1642                 and_filter_string=Filter_string;
1643         }
1644
1645
1646   return offset;
1647 }
1648
1649
1650 static const ber_sequence_t T_and_set_of[1] = {
1651   { &hf_ldap_and_item       , BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_ldap_T_and_item },
1652 };
1653
1654 static int
1655 dissect_ldap_T_and(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1656 #line 576 "ldap.cnf"
1657         proto_tree *tr=NULL;
1658         proto_item *it=NULL;
1659         char *old_and_filter_string=and_filter_string;
1660
1661         and_filter_string=NULL;
1662         if(tree){
1663                 it=proto_tree_add_text(tree, tvb, offset, tvb_length_remaining(tvb, offset), "and: ");
1664                 tr=proto_item_add_subtree(it, ett_ldap_T_and);
1665                 tree = tr;
1666         }
1667
1668   offset = dissect_ber_set_of(implicit_tag, actx, tree, tvb, offset,
1669                                  T_and_set_of, hf_index, ett_ldap_T_and);
1670
1671
1672         if(and_filter_string) {
1673                 proto_item_append_text(it, "%s", and_filter_string);
1674                 Filter_string=ep_strdup_printf("%s",and_filter_string);
1675         }
1676         and_filter_string=old_and_filter_string;
1677
1678
1679
1680   return offset;
1681 }
1682
1683
1684
1685 static int
1686 dissect_ldap_T_or_item(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1687   offset = dissect_ldap_Filter(implicit_tag, tvb, offset, actx, tree, hf_index);
1688
1689 #line 596 "ldap.cnf"
1690         if(or_filter_string){
1691                 or_filter_string=ep_strdup_printf("(|%s%s)",or_filter_string,Filter_string);
1692         } else {
1693                 or_filter_string=Filter_string;
1694         }
1695
1696
1697
1698   return offset;
1699 }
1700
1701
1702 static const ber_sequence_t T_or_set_of[1] = {
1703   { &hf_ldap_or_item        , BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_ldap_T_or_item },
1704 };
1705
1706 static int
1707 dissect_ldap_T_or(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1708 #line 604 "ldap.cnf"
1709         proto_tree *tr=NULL;
1710         proto_item *it=NULL;
1711         char *old_or_filter_string=or_filter_string;
1712
1713         or_filter_string=NULL;
1714         if(tree){
1715                 it=proto_tree_add_text(tree, tvb, offset, tvb_length_remaining(tvb, offset), "or: ");
1716                 tr=proto_item_add_subtree(it, ett_ldap_T_or);
1717                 tree = tr;
1718         }
1719   offset = dissect_ber_set_of(implicit_tag, actx, tree, tvb, offset,
1720                                  T_or_set_of, hf_index, ett_ldap_T_or);
1721
1722         if(or_filter_string) {
1723                 proto_item_append_text(it, "%s", or_filter_string);
1724                 Filter_string=ep_strdup_printf("%s",or_filter_string);
1725         }
1726         or_filter_string=old_or_filter_string;
1727
1728
1729
1730   return offset;
1731 }
1732
1733
1734
1735 static int
1736 dissect_ldap_T_not(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1737   offset = dissect_ldap_Filter(implicit_tag, tvb, offset, actx, tree, hf_index);
1738
1739 #line 625 "ldap.cnf"
1740         Filter_string=ep_strdup_printf("(!%s)",Filter_string);
1741
1742
1743   return offset;
1744 }
1745
1746
1747
1748 static int
1749 dissect_ldap_AttributeDescription(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1750   offset = dissect_ldap_LDAPString(implicit_tag, tvb, offset, actx, tree, hf_index);
1751
1752   return offset;
1753 }
1754
1755
1756
1757 static const ber_sequence_t AttributeValueAssertion_sequence[] = {
1758   { &hf_ldap_attributeDesc  , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_ldap_AttributeDescription },
1759   { &hf_ldap_assertionValue , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_ldap_AssertionValue },
1760   { NULL, 0, 0, 0, NULL }
1761 };
1762
1763 static int
1764 dissect_ldap_AttributeValueAssertion(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1765   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
1766                                    AttributeValueAssertion_sequence, hf_index, ett_ldap_AttributeValueAssertion);
1767
1768   return offset;
1769 }
1770
1771
1772
1773 static int
1774 dissect_ldap_T_equalityMatch(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1775   offset = dissect_ldap_AttributeValueAssertion(implicit_tag, tvb, offset, actx, tree, hf_index);
1776
1777 #line 538 "ldap.cnf"
1778         Filter_string=ep_strdup_printf("(%s=%s)",
1779                                        attributedesc_string ?
1780                                        attributedesc_string : "(null)",
1781                                        ldapvalue_string ?
1782                                        ldapvalue_string : "(null)");
1783
1784
1785
1786   return offset;
1787 }
1788
1789
1790 static const value_string ldap_T_substringFilter_substrings_item_vals[] = {
1791   {   0, "initial" },
1792   {   1, "any" },
1793   {   2, "final" },
1794   { 0, NULL }
1795 };
1796
1797 static const ber_choice_t T_substringFilter_substrings_item_choice[] = {
1798   {   0, &hf_ldap_initial        , BER_CLASS_CON, 0, BER_FLAGS_IMPLTAG, dissect_ldap_LDAPString },
1799   {   1, &hf_ldap_any            , BER_CLASS_CON, 1, BER_FLAGS_IMPLTAG, dissect_ldap_LDAPString },
1800   {   2, &hf_ldap_final          , BER_CLASS_CON, 2, BER_FLAGS_IMPLTAG, dissect_ldap_LDAPString },
1801   { 0, NULL, 0, 0, 0, NULL }
1802 };
1803
1804 static int
1805 dissect_ldap_T_substringFilter_substrings_item(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1806   offset = dissect_ber_choice(actx, tree, tvb, offset,
1807                                  T_substringFilter_substrings_item_choice, hf_index, ett_ldap_T_substringFilter_substrings_item,
1808                                  NULL);
1809
1810 #line 651 "ldap.cnf"
1811         if (substring_item_final) {
1812                 substring_value=ep_strdup_printf("%s%s",
1813                                                  (substring_value?substring_value:"*"),
1814                                                  substring_item_final);
1815         } else if (substring_item_any) {
1816                 substring_value=ep_strdup_printf("%s%s*",
1817                                                  (substring_value?substring_value:"*"),
1818                                                  substring_item_any);
1819         } else if (substring_item_init) {
1820                 substring_value=ep_strdup_printf("%s*",
1821                                                  substring_item_init);
1822         }
1823
1824
1825   return offset;
1826 }
1827
1828
1829 static const ber_sequence_t T_substringFilter_substrings_sequence_of[1] = {
1830   { &hf_ldap_substringFilter_substrings_item, BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_ldap_T_substringFilter_substrings_item },
1831 };
1832
1833 static int
1834 dissect_ldap_T_substringFilter_substrings(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1835   offset = dissect_ber_sequence_of(implicit_tag, actx, tree, tvb, offset,
1836                                       T_substringFilter_substrings_sequence_of, hf_index, ett_ldap_T_substringFilter_substrings);
1837
1838   return offset;
1839 }
1840
1841
1842 static const ber_sequence_t SubstringFilter_sequence[] = {
1843   { &hf_ldap_type           , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_ldap_AttributeDescription },
1844   { &hf_ldap_substringFilter_substrings, BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_ldap_T_substringFilter_substrings },
1845   { NULL, 0, 0, 0, NULL }
1846 };
1847
1848 static int
1849 dissect_ldap_SubstringFilter(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1850 #line 665 "ldap.cnf"
1851         proto_tree *tr=NULL;
1852         proto_item *it=NULL;
1853         char *old_substring_value=substring_value;
1854
1855         substring_value=NULL;
1856         substring_item_init=NULL;
1857         substring_item_any=NULL;
1858         substring_item_final=NULL;
1859         if(tree){
1860                 it=proto_tree_add_text(tree, tvb, offset, tvb_length_remaining(tvb, offset), "substring: ");
1861                 tr=proto_item_add_subtree(it, ett_ldap_SubstringFilter);
1862                 tree = tr;
1863         }
1864   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
1865                                    SubstringFilter_sequence, hf_index, ett_ldap_SubstringFilter);
1866
1867         Filter_string=ep_strdup_printf("(%s=%s)",attr_type,substring_value);
1868         proto_item_append_text(it, "%s", Filter_string);
1869         substring_value=old_substring_value;
1870
1871
1872
1873   return offset;
1874 }
1875
1876
1877
1878 static int
1879 dissect_ldap_T_greaterOrEqual(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1880   offset = dissect_ldap_AttributeValueAssertion(implicit_tag, tvb, offset, actx, tree, hf_index);
1881
1882 #line 546 "ldap.cnf"
1883         Filter_string=ep_strdup_printf("(%s>=%s)",
1884                                        attributedesc_string ?
1885                                        attributedesc_string : "(null)",
1886                                        ldapvalue_string ?
1887                                        ldapvalue_string : "(null)");
1888
1889
1890
1891   return offset;
1892 }
1893
1894
1895
1896 static int
1897 dissect_ldap_T_lessOrEqual(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1898   offset = dissect_ldap_AttributeValueAssertion(implicit_tag, tvb, offset, actx, tree, hf_index);
1899
1900 #line 554 "ldap.cnf"
1901         Filter_string=ep_strdup_printf("(%s<=%s)",
1902                                        attributedesc_string ?
1903                                        attributedesc_string : "(null)",
1904                                        ldapvalue_string ?
1905                                        ldapvalue_string : "(null)");
1906
1907
1908
1909   return offset;
1910 }
1911
1912
1913
1914 static int
1915 dissect_ldap_T_present(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1916   offset = dissect_ldap_AttributeDescription(implicit_tag, tvb, offset, actx, tree, hf_index);
1917
1918 #line 622 "ldap.cnf"
1919         Filter_string=ep_strdup_printf("(%s=*)",Filter_string);
1920
1921
1922   return offset;
1923 }
1924
1925
1926
1927 static int
1928 dissect_ldap_T_approxMatch(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1929   offset = dissect_ldap_AttributeValueAssertion(implicit_tag, tvb, offset, actx, tree, hf_index);
1930
1931 #line 562 "ldap.cnf"
1932         Filter_string=ep_strdup_printf("(%s~=%s)",
1933                                        attributedesc_string ?
1934                                        attributedesc_string : "(null)",
1935                                        ldapvalue_string ?
1936                                        ldapvalue_string : "(null)");
1937
1938
1939   return offset;
1940 }
1941
1942
1943
1944 static int
1945 dissect_ldap_MatchingRuleId(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1946   offset = dissect_ldap_LDAPString(implicit_tag, tvb, offset, actx, tree, hf_index);
1947
1948   return offset;
1949 }
1950
1951
1952
1953 static int
1954 dissect_ldap_T_dnAttributes(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1955 #line 628 "ldap.cnf"
1956         gboolean val;
1957
1958 offset = dissect_ber_boolean(implicit_tag, actx, tree, tvb, offset, hf_index, &val);
1959
1960
1961                 matching_rule_dnattr = val;
1962
1963
1964
1965
1966   return offset;
1967 }
1968
1969
1970 static const ber_sequence_t MatchingRuleAssertion_sequence[] = {
1971   { &hf_ldap_matchingRule   , BER_CLASS_CON, 1, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_ldap_MatchingRuleId },
1972   { &hf_ldap_type           , BER_CLASS_CON, 2, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_ldap_AttributeDescription },
1973   { &hf_ldap_matchValue     , BER_CLASS_CON, 3, BER_FLAGS_IMPLTAG, dissect_ldap_AssertionValue },
1974   { &hf_ldap_dnAttributes   , BER_CLASS_CON, 4, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_ldap_T_dnAttributes },
1975   { NULL, 0, 0, 0, NULL }
1976 };
1977
1978 static int
1979 dissect_ldap_MatchingRuleAssertion(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1980   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
1981                                    MatchingRuleAssertion_sequence, hf_index, ett_ldap_MatchingRuleAssertion);
1982
1983   return offset;
1984 }
1985
1986
1987
1988 static int
1989 dissect_ldap_T_extensibleMatch(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1990 #line 637 "ldap.cnf"
1991         attr_type=NULL;
1992         matching_rule_string=NULL;
1993         ldapvalue_string=NULL;
1994         matching_rule_dnattr=FALSE;
1995
1996
1997   offset = dissect_ldap_MatchingRuleAssertion(implicit_tag, tvb, offset, actx, tree, hf_index);
1998
1999 #line 643 "ldap.cnf"
2000         Filter_string=ep_strdup_printf("(%s:%s%s%s=%s)",
2001                                         (attr_type?attr_type:""),
2002                                         (matching_rule_dnattr?"dn:":""),
2003                                         (matching_rule_string?matching_rule_string:""),
2004                                         (matching_rule_string?":":""),
2005                                         ldapvalue_string);
2006
2007
2008   return offset;
2009 }
2010
2011
2012 static const value_string ldap_Filter_vals[] = {
2013   {   0, "and" },
2014   {   1, "or" },
2015   {   2, "not" },
2016   {   3, "equalityMatch" },
2017   {   4, "substrings" },
2018   {   5, "greaterOrEqual" },
2019   {   6, "lessOrEqual" },
2020   {   7, "present" },
2021   {   8, "approxMatch" },
2022   {   9, "extensibleMatch" },
2023   { 0, NULL }
2024 };
2025
2026 static const ber_choice_t Filter_choice[] = {
2027   {   0, &hf_ldap_and            , BER_CLASS_CON, 0, BER_FLAGS_IMPLTAG, dissect_ldap_T_and },
2028   {   1, &hf_ldap_or             , BER_CLASS_CON, 1, BER_FLAGS_IMPLTAG, dissect_ldap_T_or },
2029   {   2, &hf_ldap_not            , BER_CLASS_CON, 2, BER_FLAGS_IMPLTAG, dissect_ldap_T_not },
2030   {   3, &hf_ldap_equalityMatch  , BER_CLASS_CON, 3, BER_FLAGS_IMPLTAG, dissect_ldap_T_equalityMatch },
2031   {   4, &hf_ldap_substrings     , BER_CLASS_CON, 4, BER_FLAGS_IMPLTAG, dissect_ldap_SubstringFilter },
2032   {   5, &hf_ldap_greaterOrEqual , BER_CLASS_CON, 5, BER_FLAGS_IMPLTAG, dissect_ldap_T_greaterOrEqual },
2033   {   6, &hf_ldap_lessOrEqual    , BER_CLASS_CON, 6, BER_FLAGS_IMPLTAG, dissect_ldap_T_lessOrEqual },
2034   {   7, &hf_ldap_present        , BER_CLASS_CON, 7, BER_FLAGS_IMPLTAG, dissect_ldap_T_present },
2035   {   8, &hf_ldap_approxMatch    , BER_CLASS_CON, 8, BER_FLAGS_IMPLTAG, dissect_ldap_T_approxMatch },
2036   {   9, &hf_ldap_extensibleMatch, BER_CLASS_CON, 9, BER_FLAGS_IMPLTAG, dissect_ldap_T_extensibleMatch },
2037   { 0, NULL, 0, 0, 0, NULL }
2038 };
2039
2040 static int
2041 dissect_ldap_Filter(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2042 #line 684 "ldap.cnf"
2043         proto_tree *tr=NULL;
2044         proto_item *it=NULL;
2045
2046         if(tree){
2047                 it=proto_tree_add_text(tree, tvb, offset, tvb_length_remaining(tvb, offset), "Filter: ");
2048                 tr=proto_item_add_subtree(it, ett_ldap_Filter);
2049                 tree = tr;
2050         }
2051   offset = dissect_ber_choice(actx, tree, tvb, offset,
2052                                  Filter_choice, hf_index, ett_ldap_Filter,
2053                                  NULL);
2054
2055         if(Filter_string)
2056                 proto_item_append_text(it, "%s", Filter_string);
2057
2058
2059
2060   return offset;
2061 }
2062
2063
2064
2065 static int
2066 dissect_ldap_T_filter(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2067 #line 531 "ldap.cnf"
2068         Filter_string=NULL;
2069
2070
2071   offset = dissect_ldap_Filter(implicit_tag, tvb, offset, actx, tree, hf_index);
2072
2073 #line 534 "ldap.cnf"
2074         Filter_string=NULL;
2075         and_filter_string=NULL;
2076
2077
2078   return offset;
2079 }
2080
2081
2082 static const ber_sequence_t AttributeDescriptionList_sequence_of[1] = {
2083   { &hf_ldap_AttributeDescriptionList_item, BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_ldap_AttributeDescription },
2084 };
2085
2086 static int
2087 dissect_ldap_AttributeDescriptionList(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2088   offset = dissect_ber_sequence_of(implicit_tag, actx, tree, tvb, offset,
2089                                       AttributeDescriptionList_sequence_of, hf_index, ett_ldap_AttributeDescriptionList);
2090
2091   return offset;
2092 }
2093
2094
2095 static const ber_sequence_t SearchRequest_U_sequence[] = {
2096   { &hf_ldap_baseObject     , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_ldap_LDAPDN },
2097   { &hf_ldap_scope          , BER_CLASS_UNI, BER_UNI_TAG_ENUMERATED, BER_FLAGS_NOOWNTAG, dissect_ldap_T_scope },
2098   { &hf_ldap_derefAliases   , BER_CLASS_UNI, BER_UNI_TAG_ENUMERATED, BER_FLAGS_NOOWNTAG, dissect_ldap_T_derefAliases },
2099   { &hf_ldap_sizeLimit      , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_ldap_INTEGER_0_maxInt },
2100   { &hf_ldap_timeLimit      , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_ldap_INTEGER_0_maxInt },
2101   { &hf_ldap_typesOnly      , BER_CLASS_UNI, BER_UNI_TAG_BOOLEAN, BER_FLAGS_NOOWNTAG, dissect_ldap_BOOLEAN },
2102   { &hf_ldap_filter         , BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_ldap_T_filter },
2103   { &hf_ldap_searchRequest_attributes, BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_ldap_AttributeDescriptionList },
2104   { NULL, 0, 0, 0, NULL }
2105 };
2106
2107 static int
2108 dissect_ldap_SearchRequest_U(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2109   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
2110                                    SearchRequest_U_sequence, hf_index, ett_ldap_SearchRequest_U);
2111
2112   return offset;
2113 }
2114
2115
2116
2117 static int
2118 dissect_ldap_SearchRequest(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2119   offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
2120                                       hf_index, BER_CLASS_APP, 3, TRUE, dissect_ldap_SearchRequest_U);
2121
2122   return offset;
2123 }
2124
2125
2126
2127 static int
2128 dissect_ldap_AttributeValue(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2129 #line 464 "ldap.cnf"
2130
2131   tvbuff_t      *next_tvb;
2132   gchar         *string;
2133   guint32       i, len;
2134   int           old_offset = offset;
2135
2136   /* extract the value of the octetstring */
2137   offset = dissect_ber_octet_string(FALSE, actx, NULL, tvb, offset, hf_index, &next_tvb);
2138
2139   /* if we have an attribute type that isn't binary see if there is a better dissector */
2140   if(!attr_type || !dissector_try_string(ldap_name_dissector_table, attr_type, next_tvb, actx->pinfo, tree)) {
2141         offset = old_offset;
2142
2143         /* do the default thing */
2144           offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index,
2145                                        NULL);
2146
2147
2148   }
2149
2150   len = tvb_length_remaining(next_tvb, 0);
2151
2152   for(i = 0; i < len; i++)
2153     if(!g_ascii_isprint(tvb_get_guint8(next_tvb, i)))
2154       break;
2155
2156   if(i == len) {
2157     string = tvb_get_ephemeral_string(next_tvb, 0, tvb_length_remaining(next_tvb, 0));
2158
2159
2160     proto_item_set_text(actx->created_item, "%s", string);
2161
2162   }
2163
2164
2165
2166   return offset;
2167 }
2168
2169
2170 static const ber_sequence_t SET_OF_AttributeValue_set_of[1] = {
2171   { &hf_ldap_vals_item      , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_ldap_AttributeValue },
2172 };
2173
2174 static int
2175 dissect_ldap_SET_OF_AttributeValue(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2176   offset = dissect_ber_set_of(implicit_tag, actx, tree, tvb, offset,
2177                                  SET_OF_AttributeValue_set_of, hf_index, ett_ldap_SET_OF_AttributeValue);
2178
2179   return offset;
2180 }
2181
2182
2183 static const ber_sequence_t PartialAttributeList_item_sequence[] = {
2184   { &hf_ldap_type           , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_ldap_AttributeDescription },
2185   { &hf_ldap_vals           , BER_CLASS_UNI, BER_UNI_TAG_SET, BER_FLAGS_NOOWNTAG, dissect_ldap_SET_OF_AttributeValue },
2186   { NULL, 0, 0, 0, NULL }
2187 };
2188
2189 static int
2190 dissect_ldap_PartialAttributeList_item(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2191   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
2192                                    PartialAttributeList_item_sequence, hf_index, ett_ldap_PartialAttributeList_item);
2193
2194   return offset;
2195 }
2196
2197
2198 static const ber_sequence_t PartialAttributeList_sequence_of[1] = {
2199   { &hf_ldap_PartialAttributeList_item, BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_ldap_PartialAttributeList_item },
2200 };
2201
2202 static int
2203 dissect_ldap_PartialAttributeList(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2204   offset = dissect_ber_sequence_of(implicit_tag, actx, tree, tvb, offset,
2205                                       PartialAttributeList_sequence_of, hf_index, ett_ldap_PartialAttributeList);
2206
2207   return offset;
2208 }
2209
2210
2211 static const ber_sequence_t SearchResultEntry_U_sequence[] = {
2212   { &hf_ldap_objectName     , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_ldap_LDAPDN },
2213   { &hf_ldap_searchResultEntry_attributes, BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_ldap_PartialAttributeList },
2214   { NULL, 0, 0, 0, NULL }
2215 };
2216
2217 static int
2218 dissect_ldap_SearchResultEntry_U(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2219   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
2220                                    SearchResultEntry_U_sequence, hf_index, ett_ldap_SearchResultEntry_U);
2221
2222   return offset;
2223 }
2224
2225
2226
2227 static int
2228 dissect_ldap_SearchResultEntry(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2229   offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
2230                                       hf_index, BER_CLASS_APP, 4, TRUE, dissect_ldap_SearchResultEntry_U);
2231
2232   return offset;
2233 }
2234
2235
2236 static const value_string ldap_T_resultCode_vals[] = {
2237   {   0, "success" },
2238   {   1, "operationsError" },
2239   {   2, "protocolError" },
2240   {   3, "timeLimitExceeded" },
2241   {   4, "sizeLimitExceeded" },
2242   {   5, "compareFalse" },
2243   {   6, "compareTrue" },
2244   {   7, "authMethodNotSupported" },
2245   {   8, "strongAuthRequired" },
2246   {  10, "referral" },
2247   {  11, "adminLimitExceeded" },
2248   {  12, "unavailableCriticalExtension" },
2249   {  13, "confidentialityRequired" },
2250   {  14, "saslBindInProgress" },
2251   {  16, "noSuchAttribute" },
2252   {  17, "undefinedAttributeType" },
2253   {  18, "inappropriateMatching" },
2254   {  19, "constraintViolation" },
2255   {  20, "attributeOrValueExists" },
2256   {  21, "invalidAttributeSyntax" },
2257   {  32, "noSuchObject" },
2258   {  33, "aliasProblem" },
2259   {  34, "invalidDNSyntax" },
2260   {  36, "aliasDereferencingProblem" },
2261   {  48, "inappropriateAuthentication" },
2262   {  49, "invalidCredentials" },
2263   {  50, "insufficientAccessRights" },
2264   {  51, "busy" },
2265   {  52, "unavailable" },
2266   {  53, "unwillingToPerform" },
2267   {  54, "loopDetect" },
2268   {  64, "namingViolation" },
2269   {  65, "objectClassViolation" },
2270   {  66, "notAllowedOnNonLeaf" },
2271   {  67, "notAllowedOnRDN" },
2272   {  68, "entryAlreadyExists" },
2273   {  69, "objectClassModsProhibited" },
2274   {  71, "affectsMultipleDSAs" },
2275   {  80, "other" },
2276   { 118, "canceled" },
2277   { 119, "noSuchOperation" },
2278   { 120, "tooLate" },
2279   { 121, "cannotCancel" },
2280   { 0, NULL }
2281 };
2282
2283
2284 static int
2285 dissect_ldap_T_resultCode(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2286 #line 430 "ldap.cnf"
2287
2288   const gchar *valstr;
2289
2290     offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
2291                                   &result);
2292
2293
2294   ldap_do_protocolop(actx->pinfo);
2295
2296   valstr = val_to_str(result, ldap_T_resultCode_vals, "Unknown result(%u)");
2297
2298   if (check_col(actx->pinfo->cinfo, COL_INFO))
2299     col_append_fstr(actx->pinfo->cinfo, COL_INFO, "%s ", valstr);
2300
2301   if(ldm_tree)
2302     proto_item_append_text(ldm_tree, " %s", valstr);
2303
2304
2305
2306
2307   return offset;
2308 }
2309
2310
2311 static const ber_sequence_t LDAPResult_sequence[] = {
2312   { &hf_ldap_resultCode     , BER_CLASS_UNI, BER_UNI_TAG_ENUMERATED, BER_FLAGS_NOOWNTAG, dissect_ldap_T_resultCode },
2313   { &hf_ldap_matchedDN      , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_ldap_LDAPDN },
2314   { &hf_ldap_errorMessage   , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_ldap_ErrorMessage },
2315   { &hf_ldap_referral       , BER_CLASS_CON, 3, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_ldap_Referral },
2316   { NULL, 0, 0, 0, NULL }
2317 };
2318
2319 static int
2320 dissect_ldap_LDAPResult(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2321   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
2322                                    LDAPResult_sequence, hf_index, ett_ldap_LDAPResult);
2323
2324   return offset;
2325 }
2326
2327
2328
2329 static int
2330 dissect_ldap_SearchResultDone(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2331   offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
2332                                       hf_index, BER_CLASS_APP, 5, TRUE, dissect_ldap_LDAPResult);
2333
2334   return offset;
2335 }
2336
2337
2338 static const ber_sequence_t SEQUENCE_OF_LDAPURL_sequence_of[1] = {
2339   { &hf_ldap__untag_item    , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_ldap_LDAPURL },
2340 };
2341
2342 static int
2343 dissect_ldap_SEQUENCE_OF_LDAPURL(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2344   offset = dissect_ber_sequence_of(implicit_tag, actx, tree, tvb, offset,
2345                                       SEQUENCE_OF_LDAPURL_sequence_of, hf_index, ett_ldap_SEQUENCE_OF_LDAPURL);
2346
2347   return offset;
2348 }
2349
2350
2351
2352 static int
2353 dissect_ldap_SearchResultReference(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2354 #line 754 "ldap.cnf"
2355
2356    offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
2357                                       hf_index, BER_CLASS_APP, 19, TRUE, dissect_ldap_SEQUENCE_OF_LDAPURL);
2358
2359
2360  ldap_do_protocolop(actx->pinfo);
2361
2362
2363
2364
2365   return offset;
2366 }
2367
2368
2369 static const value_string ldap_T_operation_vals[] = {
2370   {   0, "add" },
2371   {   1, "delete" },
2372   {   2, "replace" },
2373   { 0, NULL }
2374 };
2375
2376
2377 static int
2378 dissect_ldap_T_operation(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2379   offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
2380                                   NULL);
2381
2382   return offset;
2383 }
2384
2385
2386 static const ber_sequence_t AttributeTypeAndValues_sequence[] = {
2387   { &hf_ldap_type           , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_ldap_AttributeDescription },
2388   { &hf_ldap_vals           , BER_CLASS_UNI, BER_UNI_TAG_SET, BER_FLAGS_NOOWNTAG, dissect_ldap_SET_OF_AttributeValue },
2389   { NULL, 0, 0, 0, NULL }
2390 };
2391
2392 static int
2393 dissect_ldap_AttributeTypeAndValues(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2394   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
2395                                    AttributeTypeAndValues_sequence, hf_index, ett_ldap_AttributeTypeAndValues);
2396
2397   return offset;
2398 }
2399
2400
2401 static const ber_sequence_t T_modifyRequest_modification_item_sequence[] = {
2402   { &hf_ldap_operation      , BER_CLASS_UNI, BER_UNI_TAG_ENUMERATED, BER_FLAGS_NOOWNTAG, dissect_ldap_T_operation },
2403   { &hf_ldap_modification   , BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_ldap_AttributeTypeAndValues },
2404   { NULL, 0, 0, 0, NULL }
2405 };
2406
2407 static int
2408 dissect_ldap_T_modifyRequest_modification_item(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2409   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
2410                                    T_modifyRequest_modification_item_sequence, hf_index, ett_ldap_T_modifyRequest_modification_item);
2411
2412   return offset;
2413 }
2414
2415
2416 static const ber_sequence_t ModifyRequest_modification_sequence_of[1] = {
2417   { &hf_ldap_modifyRequest_modification_item, BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_ldap_T_modifyRequest_modification_item },
2418 };
2419
2420 static int
2421 dissect_ldap_ModifyRequest_modification(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2422   offset = dissect_ber_sequence_of(implicit_tag, actx, tree, tvb, offset,
2423                                       ModifyRequest_modification_sequence_of, hf_index, ett_ldap_ModifyRequest_modification);
2424
2425   return offset;
2426 }
2427
2428
2429 static const ber_sequence_t ModifyRequest_U_sequence[] = {
2430   { &hf_ldap_object         , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_ldap_LDAPDN },
2431   { &hf_ldap_modifyRequest_modification, BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_ldap_ModifyRequest_modification },
2432   { NULL, 0, 0, 0, NULL }
2433 };
2434
2435 static int
2436 dissect_ldap_ModifyRequest_U(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2437   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
2438                                    ModifyRequest_U_sequence, hf_index, ett_ldap_ModifyRequest_U);
2439
2440   return offset;
2441 }
2442
2443
2444
2445 static int
2446 dissect_ldap_ModifyRequest(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2447   offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
2448                                       hf_index, BER_CLASS_APP, 6, TRUE, dissect_ldap_ModifyRequest_U);
2449
2450   return offset;
2451 }
2452
2453
2454
2455 static int
2456 dissect_ldap_ModifyResponse(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2457   offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
2458                                       hf_index, BER_CLASS_APP, 7, TRUE, dissect_ldap_LDAPResult);
2459
2460   return offset;
2461 }
2462
2463
2464 static const ber_sequence_t AttributeList_item_sequence[] = {
2465   { &hf_ldap_type           , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_ldap_AttributeDescription },
2466   { &hf_ldap_vals           , BER_CLASS_UNI, BER_UNI_TAG_SET, BER_FLAGS_NOOWNTAG, dissect_ldap_SET_OF_AttributeValue },
2467   { NULL, 0, 0, 0, NULL }
2468 };
2469
2470 static int
2471 dissect_ldap_AttributeList_item(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2472   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
2473                                    AttributeList_item_sequence, hf_index, ett_ldap_AttributeList_item);
2474
2475   return offset;
2476 }
2477
2478
2479 static const ber_sequence_t AttributeList_sequence_of[1] = {
2480   { &hf_ldap_AttributeList_item, BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_ldap_AttributeList_item },
2481 };
2482
2483 static int
2484 dissect_ldap_AttributeList(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2485   offset = dissect_ber_sequence_of(implicit_tag, actx, tree, tvb, offset,
2486                                       AttributeList_sequence_of, hf_index, ett_ldap_AttributeList);
2487
2488   return offset;
2489 }
2490
2491
2492 static const ber_sequence_t AddRequest_U_sequence[] = {
2493   { &hf_ldap_entry          , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_ldap_LDAPDN },
2494   { &hf_ldap_attributes     , BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_ldap_AttributeList },
2495   { NULL, 0, 0, 0, NULL }
2496 };
2497
2498 static int
2499 dissect_ldap_AddRequest_U(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2500   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
2501                                    AddRequest_U_sequence, hf_index, ett_ldap_AddRequest_U);
2502
2503   return offset;
2504 }
2505
2506
2507
2508 static int
2509 dissect_ldap_AddRequest(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2510   offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
2511                                       hf_index, BER_CLASS_APP, 8, TRUE, dissect_ldap_AddRequest_U);
2512
2513   return offset;
2514 }
2515
2516
2517
2518 static int
2519 dissect_ldap_AddResponse(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2520   offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
2521                                       hf_index, BER_CLASS_APP, 9, TRUE, dissect_ldap_LDAPResult);
2522
2523   return offset;
2524 }
2525
2526
2527
2528 static int
2529 dissect_ldap_DelRequest(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2530   offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
2531                                       hf_index, BER_CLASS_APP, 10, TRUE, dissect_ldap_LDAPDN);
2532
2533   return offset;
2534 }
2535
2536
2537
2538 static int
2539 dissect_ldap_DelResponse(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2540   offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
2541                                       hf_index, BER_CLASS_APP, 11, TRUE, dissect_ldap_LDAPResult);
2542
2543   return offset;
2544 }
2545
2546
2547
2548 static int
2549 dissect_ldap_RelativeLDAPDN(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2550   offset = dissect_ldap_LDAPString(implicit_tag, tvb, offset, actx, tree, hf_index);
2551
2552   return offset;
2553 }
2554
2555
2556 static const ber_sequence_t ModifyDNRequest_U_sequence[] = {
2557   { &hf_ldap_entry          , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_ldap_LDAPDN },
2558   { &hf_ldap_newrdn         , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_ldap_RelativeLDAPDN },
2559   { &hf_ldap_deleteoldrdn   , BER_CLASS_UNI, BER_UNI_TAG_BOOLEAN, BER_FLAGS_NOOWNTAG, dissect_ldap_BOOLEAN },
2560   { &hf_ldap_newSuperior    , BER_CLASS_CON, 0, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_ldap_LDAPDN },
2561   { NULL, 0, 0, 0, NULL }
2562 };
2563
2564 static int
2565 dissect_ldap_ModifyDNRequest_U(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2566   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
2567                                    ModifyDNRequest_U_sequence, hf_index, ett_ldap_ModifyDNRequest_U);
2568
2569   return offset;
2570 }
2571
2572
2573
2574 static int
2575 dissect_ldap_ModifyDNRequest(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2576   offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
2577                                       hf_index, BER_CLASS_APP, 12, TRUE, dissect_ldap_ModifyDNRequest_U);
2578
2579   return offset;
2580 }
2581
2582
2583
2584 static int
2585 dissect_ldap_ModifyDNResponse(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2586   offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
2587                                       hf_index, BER_CLASS_APP, 13, TRUE, dissect_ldap_LDAPResult);
2588
2589   return offset;
2590 }
2591
2592
2593 static const ber_sequence_t CompareRequest_U_sequence[] = {
2594   { &hf_ldap_entry          , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_ldap_LDAPDN },
2595   { &hf_ldap_ava            , BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_ldap_AttributeValueAssertion },
2596   { NULL, 0, 0, 0, NULL }
2597 };
2598
2599 static int
2600 dissect_ldap_CompareRequest_U(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2601   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
2602                                    CompareRequest_U_sequence, hf_index, ett_ldap_CompareRequest_U);
2603
2604   return offset;
2605 }
2606
2607
2608
2609 static int
2610 dissect_ldap_CompareRequest(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2611   offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
2612                                       hf_index, BER_CLASS_APP, 14, TRUE, dissect_ldap_CompareRequest_U);
2613
2614   return offset;
2615 }
2616
2617
2618
2619 static int
2620 dissect_ldap_CompareResponse(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2621   offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
2622                                       hf_index, BER_CLASS_APP, 15, TRUE, dissect_ldap_LDAPResult);
2623
2624   return offset;
2625 }
2626
2627
2628
2629 static int
2630 dissect_ldap_AbandonRequest(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2631 #line 761 "ldap.cnf"
2632
2633    offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
2634                                       hf_index, BER_CLASS_APP, 16, TRUE, dissect_ldap_MessageID);
2635
2636
2637  ldap_do_protocolop(actx->pinfo);
2638
2639
2640
2641
2642   return offset;
2643 }
2644
2645
2646
2647 static int
2648 dissect_ldap_LDAPOID(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2649 #line 46 "ldap.cnf"
2650
2651         tvbuff_t        *parameter_tvb;
2652         const gchar *name;
2653
2654
2655   offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index,
2656                                        &parameter_tvb);
2657
2658 #line 53 "ldap.cnf"
2659
2660         object_identifier_id = NULL;
2661
2662         if (!parameter_tvb)
2663                 return offset;
2664
2665         object_identifier_id = tvb_get_ephemeral_string(parameter_tvb, 0, tvb_length_remaining(parameter_tvb,0));
2666         name = oid_resolved_from_string(object_identifier_id);
2667
2668         if(name){
2669                 proto_item_append_text(actx->created_item, " (%s)", name);
2670
2671                 if((hf_index == hf_ldap_requestName) || (hf_index == hf_ldap_responseName)) {
2672                         ldap_do_protocolop(actx->pinfo);
2673
2674                         if(check_col(actx->pinfo->cinfo, COL_INFO))
2675                               col_append_fstr(actx->pinfo->cinfo, COL_INFO, "%s ", name);
2676                 }
2677         }
2678
2679         if(((hf_index == hf_ldap_responseName) || (hf_index == hf_ldap_requestName)) &&
2680             !strcmp(object_identifier_id, "1.3.6.1.4.1.1466.20037")) {
2681
2682                 /* we have agreed start_tls */
2683                 ldap_conv_info_t *ldap_info = NULL;
2684
2685                 ldap_info = (ldap_conv_info_t *)actx->pinfo->private_data;
2686
2687                 if(ldap_info) {
2688                         if(hf_index == hf_ldap_responseName)
2689                                 /* TLS in the next frame */
2690                                 ldap_info->start_tls_frame = (actx->pinfo->fd->num) + 1;
2691                         else
2692                                 /* remember we have asked to start_tls */
2693                                 ldap_info->start_tls_pending = TRUE;
2694                 }
2695         }
2696
2697
2698   return offset;
2699 }
2700
2701
2702
2703 static int
2704 dissect_ldap_T_requestValue(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2705 #line 746 "ldap.cnf"
2706
2707         if((object_identifier_id != NULL) && oid_has_dissector(object_identifier_id)) {
2708                 offset = call_ber_oid_callback(object_identifier_id, tvb, offset, actx->pinfo, tree);
2709         } else {
2710                   offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index,
2711                                        NULL);
2712
2713         }
2714
2715
2716
2717   return offset;
2718 }
2719
2720
2721 static const ber_sequence_t ExtendedRequest_U_sequence[] = {
2722   { &hf_ldap_requestName    , BER_CLASS_CON, 0, BER_FLAGS_IMPLTAG, dissect_ldap_LDAPOID },
2723   { &hf_ldap_requestValue   , BER_CLASS_CON, 1, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_ldap_T_requestValue },
2724   { NULL, 0, 0, 0, NULL }
2725 };
2726
2727 static int
2728 dissect_ldap_ExtendedRequest_U(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2729   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
2730                                    ExtendedRequest_U_sequence, hf_index, ett_ldap_ExtendedRequest_U);
2731
2732   return offset;
2733 }
2734
2735
2736
2737 static int
2738 dissect_ldap_ExtendedRequest(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2739   offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
2740                                       hf_index, BER_CLASS_APP, 23, TRUE, dissect_ldap_ExtendedRequest_U);
2741
2742   return offset;
2743 }
2744
2745
2746 static const value_string ldap_ExtendedResponse_resultCode_vals[] = {
2747   {   0, "success" },
2748   {   1, "operationsError" },
2749   {   2, "protocolError" },
2750   {   3, "timeLimitExceeded" },
2751   {   4, "sizeLimitExceeded" },
2752   {   5, "compareFalse" },
2753   {   6, "compareTrue" },
2754   {   7, "authMethodNotSupported" },
2755   {   8, "strongAuthRequired" },
2756   {  10, "referral" },
2757   {  11, "adminLimitExceeded" },
2758   {  12, "unavailableCriticalExtension" },
2759   {  13, "confidentialityRequired" },
2760   {  14, "saslBindInProgress" },
2761   {  16, "noSuchAttribute" },
2762   {  17, "undefinedAttributeType" },
2763   {  18, "inappropriateMatching" },
2764   {  19, "constraintViolation" },
2765   {  20, "attributeOrValueExists" },
2766   {  21, "invalidAttributeSyntax" },
2767   {  32, "noSuchObject" },
2768   {  33, "aliasProblem" },
2769   {  34, "invalidDNSyntax" },
2770   {  36, "aliasDereferencingProblem" },
2771   {  48, "inappropriateAuthentication" },
2772   {  49, "invalidCredentials" },
2773   {  50, "insufficientAccessRights" },
2774   {  51, "busy" },
2775   {  52, "unavailable" },
2776   {  53, "unwillingToPerform" },
2777   {  54, "loopDetect" },
2778   {  64, "namingViolation" },
2779   {  65, "objectClassViolation" },
2780   {  66, "notAllowedOnNonLeaf" },
2781   {  67, "notAllowedOnRDN" },
2782   {  68, "entryAlreadyExists" },
2783   {  69, "objectClassModsProhibited" },
2784   {  71, "affectsMultipleDSAs" },
2785   {  80, "other" },
2786   { 118, "canceled" },
2787   { 119, "noSuchOperation" },
2788   { 120, "tooLate" },
2789   { 121, "cannotCancel" },
2790   { 0, NULL }
2791 };
2792
2793
2794 static int
2795 dissect_ldap_ExtendedResponse_resultCode(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2796   offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
2797                                   NULL);
2798
2799   return offset;
2800 }
2801
2802
2803
2804 static int
2805 dissect_ldap_ResponseName(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2806   offset = dissect_ldap_LDAPOID(implicit_tag, tvb, offset, actx, tree, hf_index);
2807
2808   return offset;
2809 }
2810
2811
2812
2813 static int
2814 dissect_ldap_OCTET_STRING(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2815   offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index,
2816                                        NULL);
2817
2818   return offset;
2819 }
2820
2821
2822 static const ber_sequence_t ExtendedResponse_U_sequence[] = {
2823   { &hf_ldap_extendedResponse_resultCode, BER_CLASS_UNI, BER_UNI_TAG_ENUMERATED, BER_FLAGS_NOOWNTAG, dissect_ldap_ExtendedResponse_resultCode },
2824   { &hf_ldap_matchedDN      , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_ldap_LDAPDN },
2825   { &hf_ldap_errorMessage   , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_ldap_ErrorMessage },
2826   { &hf_ldap_referral       , BER_CLASS_CON, 3, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_ldap_Referral },
2827   { &hf_ldap_responseName   , BER_CLASS_CON, 10, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_ldap_ResponseName },
2828   { &hf_ldap_response       , BER_CLASS_CON, 11, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_ldap_OCTET_STRING },
2829   { NULL, 0, 0, 0, NULL }
2830 };
2831
2832 static int
2833 dissect_ldap_ExtendedResponse_U(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2834   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
2835                                    ExtendedResponse_U_sequence, hf_index, ett_ldap_ExtendedResponse_U);
2836
2837   return offset;
2838 }
2839
2840
2841
2842 static int
2843 dissect_ldap_ExtendedResponse(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2844   offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
2845                                       hf_index, BER_CLASS_APP, 24, TRUE, dissect_ldap_ExtendedResponse_U);
2846
2847   return offset;
2848 }
2849
2850
2851 static const value_string ldap_ProtocolOp_vals[] = {
2852   {   0, "bindRequest" },
2853   {   1, "bindResponse" },
2854   {   2, "unbindRequest" },
2855   {   3, "searchRequest" },
2856   {   4, "searchResEntry" },
2857   {   5, "searchResDone" },
2858   {  19, "searchResRef" },
2859   {   6, "modifyRequest" },
2860   {   7, "modifyResponse" },
2861   {   8, "addRequest" },
2862   {   9, "addResponse" },
2863   {  10, "delRequest" },
2864   {  11, "delResponse" },
2865   {  12, "modDNRequest" },
2866   {  13, "modDNResponse" },
2867   {  14, "compareRequest" },
2868   {  15, "compareResponse" },
2869   {  16, "abandonRequest" },
2870   {  23, "extendedReq" },
2871   {  24, "extendedResp" },
2872   { 0, NULL }
2873 };
2874
2875 static const ber_choice_t ProtocolOp_choice[] = {
2876   {   0, &hf_ldap_bindRequest    , BER_CLASS_APP, 0, BER_FLAGS_NOOWNTAG, dissect_ldap_BindRequest },
2877   {   1, &hf_ldap_bindResponse   , BER_CLASS_APP, 1, BER_FLAGS_NOOWNTAG, dissect_ldap_BindResponse },
2878   {   2, &hf_ldap_unbindRequest  , BER_CLASS_APP, 2, BER_FLAGS_NOOWNTAG, dissect_ldap_UnbindRequest },
2879   {   3, &hf_ldap_searchRequest  , BER_CLASS_APP, 3, BER_FLAGS_NOOWNTAG, dissect_ldap_SearchRequest },
2880   {   4, &hf_ldap_searchResEntry , BER_CLASS_APP, 4, BER_FLAGS_NOOWNTAG, dissect_ldap_SearchResultEntry },
2881   {   5, &hf_ldap_searchResDone  , BER_CLASS_APP, 5, BER_FLAGS_NOOWNTAG, dissect_ldap_SearchResultDone },
2882   {  19, &hf_ldap_searchResRef   , BER_CLASS_APP, 19, BER_FLAGS_NOOWNTAG, dissect_ldap_SearchResultReference },
2883   {   6, &hf_ldap_modifyRequest  , BER_CLASS_APP, 6, BER_FLAGS_NOOWNTAG, dissect_ldap_ModifyRequest },
2884   {   7, &hf_ldap_modifyResponse , BER_CLASS_APP, 7, BER_FLAGS_NOOWNTAG, dissect_ldap_ModifyResponse },
2885   {   8, &hf_ldap_addRequest     , BER_CLASS_APP, 8, BER_FLAGS_NOOWNTAG, dissect_ldap_AddRequest },
2886   {   9, &hf_ldap_addResponse    , BER_CLASS_APP, 9, BER_FLAGS_NOOWNTAG, dissect_ldap_AddResponse },
2887   {  10, &hf_ldap_delRequest     , BER_CLASS_APP, 10, BER_FLAGS_NOOWNTAG, dissect_ldap_DelRequest },
2888   {  11, &hf_ldap_delResponse    , BER_CLASS_APP, 11, BER_FLAGS_NOOWNTAG, dissect_ldap_DelResponse },
2889   {  12, &hf_ldap_modDNRequest   , BER_CLASS_APP, 12, BER_FLAGS_NOOWNTAG, dissect_ldap_ModifyDNRequest },
2890   {  13, &hf_ldap_modDNResponse  , BER_CLASS_APP, 13, BER_FLAGS_NOOWNTAG, dissect_ldap_ModifyDNResponse },
2891   {  14, &hf_ldap_compareRequest , BER_CLASS_APP, 14, BER_FLAGS_NOOWNTAG, dissect_ldap_CompareRequest },
2892   {  15, &hf_ldap_compareResponse, BER_CLASS_APP, 15, BER_FLAGS_NOOWNTAG, dissect_ldap_CompareResponse },
2893   {  16, &hf_ldap_abandonRequest , BER_CLASS_APP, 16, BER_FLAGS_NOOWNTAG, dissect_ldap_AbandonRequest },
2894   {  23, &hf_ldap_extendedReq    , BER_CLASS_APP, 23, BER_FLAGS_NOOWNTAG, dissect_ldap_ExtendedRequest },
2895   {  24, &hf_ldap_extendedResp   , BER_CLASS_APP, 24, BER_FLAGS_NOOWNTAG, dissect_ldap_ExtendedResponse },
2896   { 0, NULL, 0, 0, 0, NULL }
2897 };
2898
2899 static int
2900 dissect_ldap_ProtocolOp(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2901 #line 100 "ldap.cnf"
2902
2903   ldap_call_response_t *lcrp;
2904   ldap_conv_info_t *ldap_info = (ldap_conv_info_t *)actx->pinfo->private_data;
2905   do_protocolop = TRUE;
2906
2907
2908   offset = dissect_ber_choice(actx, tree, tvb, offset,
2909                                  ProtocolOp_choice, hf_index, ett_ldap_ProtocolOp,
2910                                  &ProtocolOp);
2911
2912 #line 106 "ldap.cnf"
2913
2914   if (ProtocolOp == -1) {
2915     return offset;
2916   }
2917
2918   /* ProtocolOp is the index, not the tag so convert it to the tag value */
2919   ProtocolOp = ldap_ProtocolOp_vals[ProtocolOp].value;
2920
2921   lcrp=ldap_match_call_response(tvb, actx->pinfo, tree, MessageID, ProtocolOp);
2922   if(lcrp){
2923     tap_queue_packet(ldap_tap, actx->pinfo, lcrp);
2924   }
2925
2926   /* XXX: the count will not work if the results span multiple TCP packets */
2927
2928   if(ldap_info && tree) { /* only count once - on tree pass */
2929     switch(ProtocolOp) {
2930
2931     case LDAP_RES_SEARCH_ENTRY:
2932         ldap_info->num_results++;
2933
2934         proto_item_append_text(tree, " [%d result%s]",
2935                         ldap_info->num_results, ldap_info->num_results == 1 ? "" : "s");
2936
2937         break;
2938
2939     case LDAP_RES_SEARCH_RESULT:
2940
2941         if (check_col(actx->pinfo->cinfo, COL_INFO))
2942           col_append_fstr(actx->pinfo->cinfo, COL_INFO, " [%d result%s]",
2943                         ldap_info->num_results, ldap_info->num_results == 1 ? "" : "s");
2944
2945         proto_item_append_text(tree, " [%d result%s]",
2946                         ldap_info->num_results, ldap_info->num_results == 1 ? "" : "s");
2947
2948         ldap_info->num_results = 0;
2949         break;
2950      default:
2951         break;
2952     }
2953   }
2954
2955   if(ldap_info && (ProtocolOp == LDAP_RES_EXTENDED)) {
2956         /* this is an extend result */
2957
2958         if(ldap_info->start_tls_pending && !ldap_info->start_tls_frame) {
2959                 /* XXX: some directories do not correctly return the responseName in the extendedResponse so we don't know start_tls has been negotiated */
2960
2961                 if(check_col(actx->pinfo->cinfo, COL_INFO))
2962                       col_append_fstr(actx->pinfo->cinfo, COL_INFO, "[LDAP_START_TLS_OID responseName missing] ");
2963                 ldap_info->start_tls_frame = (actx->pinfo->fd->num) + 1;
2964         }
2965
2966         ldap_info->start_tls_pending = FALSE;
2967   }
2968
2969
2970   return offset;
2971 }
2972
2973
2974
2975 static int
2976 dissect_ldap_ControlType(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2977   offset = dissect_ldap_LDAPOID(implicit_tag, tvb, offset, actx, tree, hf_index);
2978
2979   return offset;
2980 }
2981
2982
2983
2984 static int
2985 dissect_ldap_T_controlValue(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2986 #line 727 "ldap.cnf"
2987         gint8 class;
2988         gboolean pc, ind;
2989         gint32 tag;
2990         guint32 len;
2991
2992         if((object_identifier_id != NULL) && oid_has_dissector(object_identifier_id)) {
2993                 /* remove the OCTET STRING encoding */
2994                 offset=dissect_ber_identifier(actx->pinfo, NULL, tvb, offset, &class, &pc, &tag);
2995                 offset=dissect_ber_length(actx->pinfo, NULL, tvb, offset, &len, &ind);
2996
2997                 call_ber_oid_callback(object_identifier_id, tvb, offset, actx->pinfo, tree);
2998
2999                 offset += len;
3000         } else {
3001                   offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index,
3002                                        NULL);
3003
3004         }
3005
3006
3007
3008
3009   return offset;
3010 }
3011
3012
3013 static const ber_sequence_t Control_sequence[] = {
3014   { &hf_ldap_controlType    , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_ldap_ControlType },
3015   { &hf_ldap_criticality    , BER_CLASS_UNI, BER_UNI_TAG_BOOLEAN, BER_FLAGS_OPTIONAL|BER_FLAGS_NOOWNTAG, dissect_ldap_BOOLEAN },
3016   { &hf_ldap_controlValue   , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_OPTIONAL|BER_FLAGS_NOOWNTAG, dissect_ldap_T_controlValue },
3017   { NULL, 0, 0, 0, NULL }
3018 };
3019
3020 static int
3021 dissect_ldap_Control(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
3022   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
3023                                    Control_sequence, hf_index, ett_ldap_Control);
3024
3025   return offset;
3026 }
3027
3028
3029 static const ber_sequence_t Controls_sequence_of[1] = {
3030   { &hf_ldap_Controls_item  , BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_ldap_Control },
3031 };
3032
3033 static int
3034 dissect_ldap_Controls(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
3035   offset = dissect_ber_sequence_of(implicit_tag, actx, tree, tvb, offset,
3036                                       Controls_sequence_of, hf_index, ett_ldap_Controls);
3037
3038   return offset;
3039 }
3040
3041
3042 static const ber_sequence_t LDAPMessage_sequence[] = {
3043   { &hf_ldap_messageID      , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_ldap_MessageID },
3044   { &hf_ldap_protocolOp     , BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_ldap_ProtocolOp },
3045   { &hf_ldap_controls       , BER_CLASS_CON, 0, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_ldap_Controls },
3046   { NULL, 0, 0, 0, NULL }
3047 };
3048
3049 static int
3050 dissect_ldap_LDAPMessage(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
3051   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
3052                                    LDAPMessage_sequence, hf_index, ett_ldap_LDAPMessage);
3053
3054   return offset;
3055 }
3056
3057
3058
3059
3060
3061 static int
3062 dissect_ldap_INTEGER(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
3063   offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
3064                                                 NULL);
3065
3066   return offset;
3067 }
3068
3069
3070 static const ber_sequence_t SearchControlValue_sequence[] = {
3071   { &hf_ldap_size           , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_ldap_INTEGER },
3072   { &hf_ldap_cookie         , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_ldap_OCTET_STRING },
3073   { NULL, 0, 0, 0, NULL }
3074 };
3075
3076 static int
3077 dissect_ldap_SearchControlValue(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
3078   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
3079                                    SearchControlValue_sequence, hf_index, ett_ldap_SearchControlValue);
3080
3081   return offset;
3082 }
3083
3084
3085 static const ber_sequence_t SortKeyList_item_sequence[] = {
3086   { &hf_ldap_attributeType  , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_ldap_AttributeDescription },
3087   { &hf_ldap_orderingRule   , BER_CLASS_CON, 0, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_ldap_MatchingRuleId },
3088   { &hf_ldap_reverseOrder   , BER_CLASS_CON, 1, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_ldap_BOOLEAN },
3089   { NULL, 0, 0, 0, NULL }
3090 };
3091
3092 static int
3093 dissect_ldap_SortKeyList_item(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
3094   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
3095                                    SortKeyList_item_sequence, hf_index, ett_ldap_SortKeyList_item);
3096
3097   return offset;
3098 }
3099
3100
3101 static const ber_sequence_t SortKeyList_sequence_of[1] = {
3102   { &hf_ldap_SortKeyList_item, BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_ldap_SortKeyList_item },
3103 };
3104
3105 static int
3106 dissect_ldap_SortKeyList(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
3107   offset = dissect_ber_sequence_of(implicit_tag, actx, tree, tvb, offset,
3108                                       SortKeyList_sequence_of, hf_index, ett_ldap_SortKeyList);
3109
3110   return offset;
3111 }
3112
3113
3114 static const value_string ldap_T_sortResult_vals[] = {
3115   {   0, "success" },
3116   {   1, "operationsError" },
3117   {   3, "timeLimitExceeded" },
3118   {   8, "strongAuthRequired" },
3119   {  11, "adminLimitExceeded" },
3120   {  16, "noSuchAttribute" },
3121   {  18, "inappropriateMatching" },
3122   {  50, "insufficientAccessRights" },
3123   {  51, "busy" },
3124   {  53, "unwillingToPerform" },
3125   {  80, "other" },
3126   { 0, NULL }
3127 };
3128
3129
3130 static int
3131 dissect_ldap_T_sortResult(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
3132   offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
3133                                   NULL);
3134
3135   return offset;
3136 }
3137
3138
3139 static const ber_sequence_t SortResult_sequence[] = {
3140   { &hf_ldap_sortResult     , BER_CLASS_UNI, BER_UNI_TAG_ENUMERATED, BER_FLAGS_NOOWNTAG, dissect_ldap_T_sortResult },
3141   { &hf_ldap_attributeType  , BER_CLASS_CON, 0, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_ldap_AttributeDescription },
3142   { NULL, 0, 0, 0, NULL }
3143 };
3144
3145 static int
3146 dissect_ldap_SortResult(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
3147   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
3148                                    SortResult_sequence, hf_index, ett_ldap_SortResult);
3149
3150   return offset;
3151 }
3152
3153
3154 static const ber_sequence_t ReplControlValue_sequence[] = {
3155   { &hf_ldap_parentsFirst   , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_ldap_INTEGER },
3156   { &hf_ldap_maxReturnLength, BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_ldap_INTEGER },
3157   { &hf_ldap_cookie         , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_ldap_OCTET_STRING },
3158   { NULL, 0, 0, 0, NULL }
3159 };
3160
3161 static int
3162 dissect_ldap_ReplControlValue(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
3163   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
3164                                    ReplControlValue_sequence, hf_index, ett_ldap_ReplControlValue);
3165
3166   return offset;
3167 }
3168
3169
3170 static const ber_sequence_t PasswdModifyRequestValue_sequence[] = {
3171   { &hf_ldap_userIdentity   , BER_CLASS_CON, 0, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_ldap_OCTET_STRING },
3172   { &hf_ldap_oldPasswd      , BER_CLASS_CON, 1, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_ldap_OCTET_STRING },
3173   { &hf_ldap_newPasswd      , BER_CLASS_CON, 2, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_ldap_OCTET_STRING },
3174   { NULL, 0, 0, 0, NULL }
3175 };
3176
3177 static int
3178 dissect_ldap_PasswdModifyRequestValue(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
3179   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
3180                                    PasswdModifyRequestValue_sequence, hf_index, ett_ldap_PasswdModifyRequestValue);
3181
3182   return offset;
3183 }
3184
3185
3186 static const ber_sequence_t PasswdModifyResponseValue_sequence[] = {
3187   { &hf_ldap_genPasswd      , BER_CLASS_CON, 0, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_ldap_OCTET_STRING },
3188   { NULL, 0, 0, 0, NULL }
3189 };
3190
3191 static int
3192 dissect_ldap_PasswdModifyResponseValue(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
3193   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
3194                                    PasswdModifyResponseValue_sequence, hf_index, ett_ldap_PasswdModifyResponseValue);
3195
3196   return offset;
3197 }
3198
3199
3200 static const ber_sequence_t CancelRequestValue_sequence[] = {
3201   { &hf_ldap_cancelID       , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_ldap_MessageID },
3202   { NULL, 0, 0, 0, NULL }
3203 };
3204
3205 static int
3206 dissect_ldap_CancelRequestValue(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
3207   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
3208                                    CancelRequestValue_sequence, hf_index, ett_ldap_CancelRequestValue);
3209
3210   return offset;
3211 }
3212
3213 /*--- PDUs ---*/
3214
3215 static void dissect_LDAPMessage_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_) {
3216   asn1_ctx_t asn1_ctx;
3217   asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
3218   dissect_ldap_LDAPMessage(FALSE, tvb, 0, &asn1_ctx, tree, hf_ldap_LDAPMessage_PDU);
3219 }
3220 static void dissect_SearchControlValue_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_) {
3221   asn1_ctx_t asn1_ctx;
3222   asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
3223   dissect_ldap_SearchControlValue(FALSE, tvb, 0, &asn1_ctx, tree, hf_ldap_SearchControlValue_PDU);
3224 }
3225 static void dissect_SortKeyList_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_) {
3226   asn1_ctx_t asn1_ctx;
3227   asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
3228   dissect_ldap_SortKeyList(FALSE, tvb, 0, &asn1_ctx, tree, hf_ldap_SortKeyList_PDU);
3229 }
3230 static void dissect_SortResult_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_) {
3231   asn1_ctx_t asn1_ctx;
3232   asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
3233   dissect_ldap_SortResult(FALSE, tvb, 0, &asn1_ctx, tree, hf_ldap_SortResult_PDU);
3234 }
3235 static void dissect_ReplControlValue_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_) {
3236   asn1_ctx_t asn1_ctx;
3237   asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
3238   dissect_ldap_ReplControlValue(FALSE, tvb, 0, &asn1_ctx, tree, hf_ldap_ReplControlValue_PDU);
3239 }
3240 static void dissect_PasswdModifyRequestValue_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_) {
3241   asn1_ctx_t asn1_ctx;
3242   asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
3243   dissect_ldap_PasswdModifyRequestValue(FALSE, tvb, 0, &asn1_ctx, tree, hf_ldap_PasswdModifyRequestValue_PDU);
3244 }
3245 static void dissect_CancelRequestValue_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_) {
3246   asn1_ctx_t asn1_ctx;
3247   asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
3248   dissect_ldap_CancelRequestValue(FALSE, tvb, 0, &asn1_ctx, tree, hf_ldap_CancelRequestValue_PDU);
3249 }
3250
3251
3252 /*--- End of included file: packet-ldap-fn.c ---*/
3253 #line 708 "packet-ldap-template.c"
3254
3255 static void
3256 dissect_ldap_payload(tvbuff_t *tvb, packet_info *pinfo,
3257                      proto_tree *tree, ldap_conv_info_t *ldap_info,
3258                      gboolean is_mscldap)
3259 {
3260   int offset = 0;
3261   guint length_remaining;
3262   guint msg_len = 0;
3263   int messageOffset = 0;
3264   guint headerLength = 0;
3265   guint length = 0;
3266   tvbuff_t *msg_tvb = NULL;
3267   gint8 class;
3268   gboolean pc, ind = 0;
3269   gint32 ber_tag;
3270
3271
3272 one_more_pdu:
3273
3274     length_remaining = tvb_ensure_length_remaining(tvb, offset);
3275
3276     if (length_remaining < 6) return;
3277
3278     /*
3279      * OK, try to read the "Sequence Of" header; this gets the total
3280      * length of the LDAP message.
3281      */
3282         messageOffset = get_ber_identifier(tvb, offset, &class, &pc, &ber_tag);
3283         messageOffset = get_ber_length(tvb, messageOffset, &msg_len, &ind);
3284
3285     /* sanity check */
3286     if((msg_len<4) || (msg_len>10000000)) return;
3287
3288     if ( (class==BER_CLASS_UNI) && (ber_tag==BER_UNI_TAG_SEQUENCE) ) {
3289         /*
3290          * Add the length of the "Sequence Of" header to the message
3291          * length.
3292          */
3293         headerLength = messageOffset - offset;
3294         msg_len += headerLength;
3295         if (msg_len < headerLength) {
3296             /*
3297              * The message length was probably so large that the total length
3298              * overflowed.
3299              *
3300              * Report this as an error.
3301              */
3302             show_reported_bounds_error(tvb, pinfo, tree);
3303             return;
3304         }
3305     } else {
3306         /*
3307          * We couldn't parse the header; just make it the amount of data
3308          * remaining in the tvbuff, so we'll give up on this segment
3309          * after attempting to parse the message - there's nothing more
3310          * we can do.  "dissect_ldap_message()" will display the error.
3311          */
3312         msg_len = length_remaining;
3313     }
3314
3315     /*
3316      * Construct a tvbuff containing the amount of the payload we have
3317      * available.  Make its reported length the amount of data in the
3318      * LDAP message.
3319      *
3320      * XXX - if reassembly isn't enabled. the subdissector will throw a
3321      * BoundsError exception, rather than a ReportedBoundsError exception.
3322      * We really want a tvbuff where the length is "length", the reported
3323      * length is "plen", and the "if the snapshot length were infinite"
3324      * length is the minimum of the reported length of the tvbuff handed
3325      * to us and "plen", with a new type of exception thrown if the offset
3326      * is within the reported length but beyond that third length, with
3327      * that exception getting the "Unreassembled Packet" error.
3328      */
3329     length = length_remaining;
3330     if (length > msg_len) length = msg_len;
3331     msg_tvb = tvb_new_subset(tvb, offset, length, msg_len);
3332
3333     /*
3334      * Now dissect the LDAP message.
3335      */
3336     ldap_info->is_mscldap = is_mscldap;
3337     pinfo->private_data = ldap_info;
3338     dissect_LDAPMessage_PDU(msg_tvb, pinfo, tree);
3339
3340     offset += msg_len;
3341
3342     /* If this was a sasl blob there might be another PDU following in the
3343      * same blob
3344      */
3345     if(tvb_length_remaining(tvb, offset)>=6){
3346         tvb = tvb_new_subset(tvb, offset, tvb_length_remaining(tvb, offset), -1);
3347         offset = 0;
3348
3349         goto one_more_pdu;
3350     }
3351
3352 }
3353
3354 static void
3355 dissect_ldap_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gboolean is_mscldap)
3356 {
3357   int offset = 0;
3358   conversation_t *conversation;
3359   gboolean doing_sasl_security = FALSE;
3360   guint length_remaining;
3361   ldap_conv_info_t *ldap_info = NULL;
3362   proto_item *ldap_item = NULL;
3363   proto_tree *ldap_tree = NULL;
3364
3365   ldm_tree = NULL;
3366
3367   /*
3368    * Do we have a conversation for this connection?
3369    */
3370   conversation = find_conversation(pinfo->fd->num, &pinfo->src, &pinfo->dst,
3371                                    pinfo->ptype, pinfo->srcport,
3372                                    pinfo->destport, 0);
3373   if (conversation == NULL) {
3374     /* We don't yet have a conversation, so create one. */
3375     conversation = conversation_new(pinfo->fd->num, &pinfo->src, &pinfo->dst,
3376                                     pinfo->ptype, pinfo->srcport,
3377                                     pinfo->destport, 0);
3378
3379   }
3380
3381   /*
3382    * Do we already have a type and mechanism?
3383    */
3384   ldap_info = conversation_get_proto_data(conversation, proto_ldap);
3385   if (ldap_info == NULL) {
3386     /* No.  Attach that information to the conversation, and add
3387      * it to the list of information structures.
3388      */
3389     ldap_info = g_malloc(sizeof(ldap_conv_info_t));
3390     ldap_info->auth_type = 0;
3391     ldap_info->auth_mech = 0;
3392     ldap_info->first_auth_frame = 0;
3393     ldap_info->matched=g_hash_table_new(ldap_info_hash_matched, ldap_info_equal_matched);
3394     ldap_info->unmatched=g_hash_table_new(ldap_info_hash_unmatched, ldap_info_equal_unmatched);
3395     ldap_info->num_results = 0;
3396     ldap_info->start_tls_frame = 0;
3397     ldap_info->start_tls_pending = FALSE;
3398
3399     conversation_add_proto_data(conversation, proto_ldap, ldap_info);
3400
3401     ldap_info->next = ldap_info_items;
3402     ldap_info_items = ldap_info;
3403
3404   }
3405   
3406   switch (ldap_info->auth_type) {
3407     case LDAP_AUTH_SASL:
3408     /*
3409      * It's SASL; are we using a security layer?
3410      */
3411     if (ldap_info->first_auth_frame != 0 &&
3412        pinfo->fd->num >= ldap_info->first_auth_frame) {
3413         doing_sasl_security = TRUE;     /* yes */
3414     }
3415   }
3416
3417     length_remaining = tvb_ensure_length_remaining(tvb, offset);
3418
3419     /* It might still be a packet containing a SASL security layer
3420      * but its just that we never saw the BIND packet.
3421      * check if it looks like it could be a SASL blob here
3422      * and in that case just assume it is GSS-SPNEGO
3423      */
3424     if(!doing_sasl_security && (tvb_bytes_exist(tvb, offset, 5))
3425       &&(tvb_get_ntohl(tvb, offset)<=(guint)(tvb_reported_length_remaining(tvb, offset)-4))
3426       &&(tvb_get_guint8(tvb, offset+4)==0x60) ){
3427         ldap_info->auth_type=LDAP_AUTH_SASL;
3428         ldap_info->first_auth_frame=pinfo->fd->num;
3429         ldap_info->auth_mech=g_strdup("GSS-SPNEGO");
3430         doing_sasl_security=TRUE;
3431     }
3432
3433     /*
3434      * This is the first PDU, set the Protocol column and clear the
3435      * Info column.
3436      */
3437     if (check_col(pinfo->cinfo, COL_PROTOCOL)) col_set_str(pinfo->cinfo, COL_PROTOCOL, pinfo->current_proto);
3438
3439     if(last_frame_seen == pinfo->fd->num) {
3440       /* we have already dissected an ldap PDU in this frame - add a separator and set a fence */
3441       if (check_col(pinfo->cinfo, COL_INFO)) {
3442         col_append_str(pinfo->cinfo, COL_INFO, "| ");
3443         col_set_fence(pinfo->cinfo, COL_INFO);
3444       }
3445     } else
3446       if (check_col(pinfo->cinfo, COL_INFO)) col_clear(pinfo->cinfo, COL_INFO);
3447
3448     last_frame_seen = pinfo->fd->num;
3449
3450     ldap_item = proto_tree_add_item(tree, is_mscldap?proto_cldap:proto_ldap, tvb, 0, -1, FALSE);
3451     ldap_tree = proto_item_add_subtree(ldap_item, ett_ldap);
3452
3453     /*
3454      * Might we be doing a SASL security layer and, if so, *are* we doing
3455      * one?
3456      *
3457      * Just because we've seen a bind reply for SASL, that doesn't mean
3458      * that we're using a SASL security layer; I've seen captures in
3459      * which some SASL negotiations lead to a security layer being used
3460      * and other negotiations don't, and it's not obvious what's different
3461      * in the two negotiations.  Therefore, we assume that if the first
3462      * byte is 0, it's a length for a SASL security layer (that way, we
3463      * never reassemble more than 16 megabytes, protecting us from
3464      * chewing up *too* much memory), and otherwise that it's an LDAP
3465      * message (actually, if it's an LDAP message it should begin with 0x30,
3466      * but we want to parse garbage as LDAP messages rather than really
3467      * huge lengths).
3468      */
3469
3470     if (doing_sasl_security && tvb_get_guint8(tvb, offset) == 0) {
3471       proto_item *sasl_item = NULL;
3472       proto_tree *sasl_tree = NULL;
3473       tvbuff_t *sasl_tvb;
3474       guint sasl_len, sasl_msg_len, length;
3475       /*
3476        * Yes.  The frame begins with a 4-byte big-endian length.
3477        * And we know we have at least 6 bytes
3478        */
3479
3480       /*
3481        * Get the SASL length, which is the length of data in the buffer
3482        * following the length (i.e., it's 4 less than the total length).
3483        *
3484        * XXX - do we need to reassemble buffers?  For now, we
3485        * assume that each LDAP message is entirely contained within
3486        * a buffer.
3487        */
3488       sasl_len = tvb_get_ntohl(tvb, offset);
3489       sasl_msg_len = sasl_len + 4;
3490       if (sasl_msg_len < 4) {
3491         /*
3492          * The message length was probably so large that the total length
3493          * overflowed.
3494          *
3495          * Report this as an error.
3496          */
3497         show_reported_bounds_error(tvb, pinfo, tree);
3498         return;
3499       }
3500
3501       /*
3502        * Construct a tvbuff containing the amount of the payload we have
3503        * available.  Make its reported length the amount of data in the PDU.
3504        *
3505        * XXX - if reassembly isn't enabled. the subdissector will throw a
3506        * BoundsError exception, rather than a ReportedBoundsError exception.
3507        * We really want a tvbuff where the length is "length", the reported
3508        * length is "plen", and the "if the snapshot length were infinite"
3509        * length is the minimum of the reported length of the tvbuff handed
3510        * to us and "plen", with a new type of exception thrown if the offset
3511        * is within the reported length but beyond that third length, with
3512        * that exception getting the "Unreassembled Packet" error.
3513        */
3514       length = length_remaining;
3515       if (length > sasl_msg_len) length = sasl_msg_len;
3516       sasl_tvb = tvb_new_subset(tvb, offset, length, sasl_msg_len);
3517
3518       if (ldap_tree) {
3519         proto_tree_add_uint(ldap_tree, hf_ldap_sasl_buffer_length, sasl_tvb, 0, 4,
3520                             sasl_len);
3521
3522         sasl_item = proto_tree_add_text(ldap_tree, sasl_tvb, 0,  sasl_msg_len, "SASL Buffer");
3523         sasl_tree = proto_item_add_subtree(sasl_item, ett_ldap_sasl_blob);
3524       }
3525
3526       if (ldap_info->auth_mech != NULL &&
3527           ((strcmp(ldap_info->auth_mech, "GSS-SPNEGO") == 0) ||
3528            /* auth_mech may have been set from the bind */
3529            (strcmp(ldap_info->auth_mech, "GSSAPI") == 0))) {
3530           tvbuff_t *gssapi_tvb, *plain_tvb = NULL, *decr_tvb= NULL;
3531           int ver_len;
3532           int length;
3533
3534           /*
3535            * This is GSS-API (using SPNEGO, but we should be done with
3536            * the negotiation by now).
3537            *
3538            * Dissect the GSS_Wrap() token; it'll return the length of
3539            * the token, from which we compute the offset in the tvbuff at
3540            * which the plaintext data, i.e. the LDAP message, begins.
3541            */
3542           length = tvb_length_remaining(sasl_tvb, 4);
3543           if ((guint)length > sasl_len)
3544               length = sasl_len;
3545           gssapi_tvb = tvb_new_subset(sasl_tvb, 4, length, sasl_len);
3546
3547           /* Attempt decryption of the GSSAPI wrapped data if possible */
3548           pinfo->decrypt_gssapi_tvb=DECRYPT_GSSAPI_NORMAL;
3549           pinfo->gssapi_wrap_tvb=NULL;
3550           pinfo->gssapi_encrypted_tvb=NULL;
3551           pinfo->gssapi_decrypted_tvb=NULL;
3552           ver_len = call_dissector(gssapi_wrap_handle, gssapi_tvb, pinfo, sasl_tree);
3553           /* if we could unwrap, do a tvb shuffle */
3554           if(pinfo->gssapi_decrypted_tvb){
3555                 decr_tvb=pinfo->gssapi_decrypted_tvb;
3556           }
3557           /* tidy up */
3558           pinfo->decrypt_gssapi_tvb=0;
3559           pinfo->gssapi_wrap_tvb=NULL;
3560           pinfo->gssapi_encrypted_tvb=NULL;
3561           pinfo->gssapi_decrypted_tvb=NULL;
3562
3563           /*
3564            * if len is 0 it probably mean that we got a PDU that is not
3565            * aligned to the start of the segment.
3566            */
3567           if(ver_len==0){
3568              return;
3569           }
3570
3571           /*
3572            * if we don't have unwrapped data,
3573            * see if the wrapping involved encryption of the
3574            * data; if not, just use the plaintext data.
3575            */
3576           if (!decr_tvb) {
3577             if(!pinfo->gssapi_data_encrypted){
3578               plain_tvb = tvb_new_subset(gssapi_tvb,  ver_len, -1, -1);
3579             }
3580           }
3581
3582           if (decr_tvb) {
3583             proto_item *enc_item = NULL;
3584             proto_tree *enc_tree = NULL;
3585
3586             /*
3587              * The LDAP message was encrypted in the packet, and has
3588              * been decrypted; dissect the decrypted LDAP message.
3589              */
3590             if (check_col(pinfo->cinfo, COL_INFO)) {
3591                                 col_set_str(pinfo->cinfo, COL_INFO, "SASL GSS-API Privacy (decrypted): ");
3592             }
3593
3594             if (sasl_tree) {
3595               enc_item = proto_tree_add_text(sasl_tree, gssapi_tvb, ver_len, -1,
3596                                 "GSS-API Encrypted payload (%d byte%s)",
3597                                 sasl_len - ver_len,
3598                                 plurality(sasl_len - ver_len, "", "s"));
3599               enc_tree = proto_item_add_subtree(enc_item, ett_ldap_payload);
3600             }
3601             dissect_ldap_payload(decr_tvb, pinfo, enc_tree, ldap_info, is_mscldap);
3602           } else if (plain_tvb) {
3603             proto_item *plain_item = NULL;
3604             proto_tree *plain_tree = NULL;
3605
3606             /*
3607              * The LDAP message wasn't encrypted in the packet;
3608              * dissect the plain LDAP message.
3609              */
3610             if (check_col(pinfo->cinfo, COL_INFO)) {
3611                                 col_set_str(pinfo->cinfo, COL_INFO, "SASL GSS-API Integrity: ");
3612             }
3613
3614             if (sasl_tree) {
3615               plain_item = proto_tree_add_text(sasl_tree, gssapi_tvb, ver_len, -1,
3616                                 "GSS-API payload (%d byte%s)",
3617                                 sasl_len - ver_len,
3618                                 plurality(sasl_len - ver_len, "", "s"));
3619               plain_tree = proto_item_add_subtree(plain_item, ett_ldap_payload);
3620             }
3621
3622            dissect_ldap_payload(plain_tvb, pinfo, plain_tree, ldap_info, is_mscldap);
3623           } else {
3624             /*
3625              * The LDAP message was encrypted in the packet, and was
3626              * not decrypted; just show it as encrypted data.
3627              */
3628             if (check_col(pinfo->cinfo, COL_INFO)) {
3629                     col_add_fstr(pinfo->cinfo, COL_INFO, "SASL GSS-API Privacy: payload (%d byte%s)",
3630                                  sasl_len - ver_len,
3631                                  plurality(sasl_len - ver_len, "", "s"));
3632             }
3633             if (sasl_tree) {
3634               proto_tree_add_text(sasl_tree, gssapi_tvb, ver_len, -1,
3635                                 "GSS-API Encrypted payload (%d byte%s)",
3636                                 sasl_len - ver_len,
3637                                 plurality(sasl_len - ver_len, "", "s"));
3638             }
3639           }
3640       }
3641       offset += sasl_msg_len;
3642     } else {
3643         /* plain LDAP, so dissect the payload */
3644         dissect_ldap_payload(tvb, pinfo, ldap_tree, ldap_info, is_mscldap);
3645     }
3646 }
3647
3648 static int dissect_mscldap_string(tvbuff_t *tvb, int offset, char *str, int maxlen, gboolean prepend_dot)
3649 {
3650   guint8 len;
3651
3652   len=tvb_get_guint8(tvb, offset);
3653   offset+=1;
3654   *str=0;
3655
3656   while(len){
3657     /* add potential field separation dot */
3658     if(prepend_dot){
3659       if(!maxlen){
3660         *str=0;
3661         return offset;
3662       }
3663       maxlen--;
3664       *str++='.';
3665       *str=0;
3666     }
3667
3668     if(len==0xc0){
3669       int new_offset;
3670       /* ops its a mscldap compressed string */
3671
3672       new_offset=tvb_get_guint8(tvb, offset);
3673       if (new_offset == offset - 1)
3674         THROW(ReportedBoundsError);
3675       offset+=1;
3676
3677       dissect_mscldap_string(tvb, new_offset, str, maxlen, FALSE);
3678
3679       return offset;
3680     }
3681
3682     prepend_dot=TRUE;
3683
3684     if(maxlen<=len){
3685       if(maxlen>3){
3686         *str++='.';
3687         *str++='.';
3688         *str++='.';
3689       }
3690       *str=0;
3691       return offset; /* will mess up offset in caller, is unlikely */
3692     }
3693     tvb_memcpy(tvb, str, offset, len);
3694     str+=len;
3695     *str=0;
3696     maxlen-=len;
3697     offset+=len;
3698
3699
3700     len=tvb_get_guint8(tvb, offset);
3701     offset+=1;
3702   }
3703   *str=0;
3704   return offset;
3705 }
3706
3707
3708 /* These are the cldap DC flags 
3709    http://msdn.microsoft.com/en-us/library/cc201036.aspx
3710  */
3711 static const true_false_string tfs_ads_pdc = {
3712         "This is a PDC",
3713         "This is NOT a pdc"
3714 };
3715 static const true_false_string tfs_ads_gc = {
3716         "This is a GLOBAL CATALOGUE of forest",
3717         "This is NOT a global catalog of forest"
3718 };
3719 static const true_false_string tfs_ads_ldap = {
3720         "This is an LDAP server",
3721         "This is NOT an ldap server"
3722 };
3723 static const true_false_string tfs_ads_ds = {
3724         "This dc supports DS",
3725         "This dc does NOT support ds"
3726 };
3727 static const true_false_string tfs_ads_kdc = {
3728         "This is a KDC (kerberos)",
3729         "This is NOT a kdc (kerberos)"
3730 };
3731 static const true_false_string tfs_ads_timeserv = {
3732         "This dc is running TIME SERVICES (ntp)",
3733         "This dc is NOT running time services (ntp)"
3734 };
3735 static const true_false_string tfs_ads_closest = {
3736         "This is the CLOSEST dc",
3737         "This is NOT the closest dc"
3738 };
3739 static const true_false_string tfs_ads_writable = {
3740         "This dc is WRITABLE",
3741         "This dc is NOT writable"
3742 };
3743 static const true_false_string tfs_ads_good_timeserv = {
3744         "This dc has a GOOD TIME SERVICE (i.e. hardware clock)",
3745         "This dc does NOT have a good time service (i.e. no hardware clock)"
3746 };
3747 static const true_false_string tfs_ads_ndnc = {
3748         "Domain is NON-DOMAIN NC serviced by ldap server",
3749         "Domain is NOT non-domain nc serviced by ldap server"
3750 };
3751 static const true_false_string tfs_ads_rodc = {
3752         "Domain controller is a Windows 2008 RODC",
3753         "Domain controller is not a Windows 2008 RODC"
3754 };
3755 static const true_false_string tfs_ads_wdc = {
3756         "Domain controller is a Windows 2008 writable NC",
3757         "Domain controller is not a Windows 2008 writable NC"
3758 };
3759 static const true_false_string tfs_ads_dns = {
3760         "Server name is in DNS format (Windows 2008)",
3761         "Server name is not in DNS format (Windows 2008)"
3762 };
3763 static const true_false_string tfs_ads_dnc = {
3764         "The NC is the default NC (Windows 2008)",
3765         "The NC is not the default NC (Windows 2008)"
3766 };
3767 static const true_false_string tfs_ads_fnc = {
3768         "The NC is the default forest NC(Windows 2008)",
3769         "The NC is not the default forest NC (Windows 2008)"
3770 };
3771 static int dissect_mscldap_netlogon_flags(proto_tree *parent_tree, tvbuff_t *tvb, int offset)
3772 {
3773   guint32 flags;
3774   proto_item *item;
3775   proto_tree *tree=NULL;
3776   guint fields[] = { 
3777                          hf_mscldap_netlogon_flags_fnc,
3778                      hf_mscldap_netlogon_flags_dnc,
3779                      hf_mscldap_netlogon_flags_dns,
3780                      hf_mscldap_netlogon_flags_wdc,
3781                      hf_mscldap_netlogon_flags_rodc,
3782                          hf_mscldap_netlogon_flags_ndnc,
3783                      hf_mscldap_netlogon_flags_good_timeserv,
3784                      hf_mscldap_netlogon_flags_writable,
3785                      hf_mscldap_netlogon_flags_closest,
3786                      hf_mscldap_netlogon_flags_timeserv,
3787                      hf_mscldap_netlogon_flags_kdc,
3788                      hf_mscldap_netlogon_flags_ds,
3789                      hf_mscldap_netlogon_flags_ldap,
3790                      hf_mscldap_netlogon_flags_gc,
3791                      hf_mscldap_netlogon_flags_pdc,
3792                          0 };
3793   guint  *field;
3794   header_field_info *hfi;
3795   gboolean one_bit_set = FALSE;
3796
3797   flags=tvb_get_letohl(tvb, offset);
3798   item=proto_tree_add_item(parent_tree, hf_mscldap_netlogon_flags, tvb, offset, 4, TRUE);
3799   if(parent_tree){
3800     tree = proto_item_add_subtree(item, ett_mscldap_netlogon_flags);
3801   }
3802
3803   proto_item_append_text(item, " (");
3804
3805   for(field = fields; *field; field++) {
3806     proto_tree_add_boolean(tree, *field, tvb, offset, 4, flags);
3807     hfi = proto_registrar_get_nth(*field);
3808
3809     if(flags & hfi->bitmask) {
3810
3811       if(one_bit_set)
3812         proto_item_append_text(item, ", ");
3813       else
3814         one_bit_set = TRUE;
3815
3816       proto_item_append_text(item, hfi->name);
3817
3818     }
3819   }
3820
3821   proto_item_append_text(item, ")");
3822
3823   offset += 4;
3824
3825   return offset;
3826 }
3827
3828 static void dissect_NetLogon_PDU(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree)
3829 {
3830   int old_offset, offset=0;
3831   char str[256];
3832   guint16 itype;
3833   guint16 len;
3834   guint32 version;
3835   const char *fn;
3836   int fn_len;
3837   guint16 bc;
3838   proto_item *item;
3839
3840   ldm_tree = NULL;
3841
3842
3843   /* Get the length of the buffer */
3844   len=tvb_length_remaining(tvb,offset);
3845
3846   /* check the len if it is to small return */
3847   if (len < 10) return;
3848   
3849   /* Type */
3850   itype = tvb_get_letohs(tvb, offset);
3851
3852   /* get the version number from the end of the buffer, as the 
3853      length is variable and the version determines what fields
3854          need to be decoded */
3855   
3856   version = tvb_get_letohl(tvb,len-8);
3857   
3858   switch(itype){
3859                 
3860                 case LOGON_SAM_LOGON_RESPONSE: 
3861                         /* Type */
3862                         proto_tree_add_uint_format(tree, hf_mscldap_netlogon_type, tvb,offset, 2, itype,"Type: LOGON_SAM_LOGON_RESPONSE (19)" );
3863                         offset = 2;
3864
3865                         /* logon server name */
3866                         fn = get_unicode_or_ascii_string(tvb,&offset,TRUE,&fn_len,FALSE,FALSE,&bc);
3867                         proto_tree_add_string(tree, hf_mscldap_nb_hostname, tvb,offset, fn_len, fn);
3868                         offset +=fn_len;
3869
3870                         /* username */
3871                         fn = get_unicode_or_ascii_string(tvb,&offset,TRUE,&fn_len,FALSE,FALSE,&bc);
3872                         proto_tree_add_string(tree, hf_mscldap_username, tvb,offset, fn_len, fn);
3873                         offset +=fn_len;
3874
3875                         /* domain name */
3876                         fn = get_unicode_or_ascii_string(tvb,&offset,TRUE,&fn_len,FALSE,FALSE,&bc);
3877                         proto_tree_add_string(tree, hf_mscldap_nb_domain, tvb,offset, fn_len, fn);
3878                         offset +=fn_len;
3879
3880                         /* include the extra version 5 fields */
3881                         if ((version & NETLOGON_NT_VERSION_5) == NETLOGON_NT_VERSION_5){
3882
3883                                 /* domain guid */
3884                                 proto_tree_add_item(tree, hf_mscldap_domain_guid, tvb, offset, 16, TRUE);
3885                                 offset += 16;
3886                                 
3887                                 /* domain guid part 2
3888                                    there is another 16 byte guid but this is alway zero, so we will skip it */
3889                                 offset += 16;
3890
3891                                 /* Forest */
3892                                 old_offset=offset;
3893                                 offset=dissect_mscldap_string(tvb, offset, str, 255, FALSE);
3894                                 proto_tree_add_string(tree, hf_mscldap_forest, tvb, old_offset, offset-old_offset, str);
3895
3896                                 /* Domain */
3897                                 old_offset=offset;
3898                                 offset=dissect_mscldap_string(tvb, offset, str, 255, FALSE);
3899                                 proto_tree_add_string(tree, hf_mscldap_domain, tvb, old_offset, offset-old_offset, str);
3900
3901                                 /* Hostname */
3902                                 old_offset=offset;
3903                                 offset=dissect_mscldap_string(tvb, offset, str, 255, FALSE);
3904                                 proto_tree_add_string(tree, hf_mscldap_hostname, tvb, old_offset, offset-old_offset, str);
3905
3906                                 /* DC IP Address */
3907                                 proto_tree_add_ipv4(tree, hf_mscldap_netlogon_ipaddress, tvb, offset, 4, tvb_get_ntohl(tvb,offset));
3908                                 offset += 4;
3909
3910                                 /* Flags */
3911                                 offset = dissect_mscldap_netlogon_flags(tree, tvb, offset);
3912         
3913                         }
3914
3915                         break;
3916
3917                 case LOGON_SAM_LOGON_RESPONSE_EX:
3918
3919                         /* Type */
3920                         proto_tree_add_uint_format(tree, hf_mscldap_netlogon_type, tvb, offset, 2, itype,"Type: LOGON_SAM_LOGON_RESPONSE_EX (23)" );
3921                         offset += 4;
3922
3923
3924                         /* Flags */
3925                         offset = dissect_mscldap_netlogon_flags(tree, tvb, offset);
3926
3927                         /* Domain GUID */
3928                         proto_tree_add_item(tree, hf_mscldap_domain_guid, tvb, offset, 16, TRUE);
3929                         offset += 16;
3930
3931                         /* Forest */
3932                         old_offset=offset;
3933                         offset=dissect_mscldap_string(tvb, offset, str, 255, FALSE);
3934                         proto_tree_add_string(tree, hf_mscldap_forest, tvb, old_offset, offset-old_offset, str);
3935
3936                         /* Domain */
3937                         old_offset=offset;
3938                         offset=dissect_mscldap_string(tvb, offset, str, 255, FALSE);
3939                         proto_tree_add_string(tree, hf_mscldap_domain, tvb, old_offset, offset-old_offset, str);
3940
3941                         /* Hostname */
3942                         old_offset=offset;
3943                         offset=dissect_mscldap_string(tvb, offset, str, 255, FALSE);
3944                         proto_tree_add_string(tree, hf_mscldap_hostname, tvb, old_offset, offset-old_offset, str);
3945
3946                         /* NetBios Domain */
3947                         old_offset=offset;
3948                         offset=dissect_mscldap_string(tvb, offset, str, 255, FALSE);
3949                         proto_tree_add_string(tree, hf_mscldap_nb_domain, tvb, old_offset, offset-old_offset, str);
3950
3951                         /* NetBios Hostname */
3952                         old_offset=offset;
3953                         offset=dissect_mscldap_string(tvb, offset, str, 255, FALSE);
3954                         proto_tree_add_string(tree, hf_mscldap_nb_hostname, tvb, old_offset, offset-old_offset, str);
3955
3956                         /* User */
3957                         old_offset=offset;
3958                         offset=dissect_mscldap_string(tvb, offset, str, 255, FALSE);
3959                         proto_tree_add_string(tree, hf_mscldap_username, tvb, old_offset, offset-old_offset, str);
3960
3961                         /* Site */
3962                         old_offset=offset;
3963                         offset=dissect_mscldap_string(tvb, offset, str, 255, FALSE);
3964                         proto_tree_add_string(tree, hf_mscldap_sitename, tvb, old_offset, offset-old_offset, str);
3965
3966                         /* Client Site */
3967                         old_offset=offset;
3968                         offset=dissect_mscldap_string(tvb, offset, str, 255, FALSE);
3969                         proto_tree_add_string(tree, hf_mscldap_clientsitename, tvb, old_offset, offset-old_offset, str);
3970                         
3971                         /* include the extra fields for version 5 with IP s */
3972                         if ((version & NETLOGON_NT_VERSION_5EX_WITH_IP) == NETLOGON_NT_VERSION_5EX_WITH_IP){
3973                                 
3974
3975                                 /* The ip address is returned as a sockaddr_in structure
3976                                  *  
3977                                  *  This section may need to be updated if the base Windows APIs
3978                                  *  are changed to support ipv6, which currently is not the case.
3979                                  *
3980                                  *  The desector assumes the length is based on ipv4 and
3981                                  *  ignores the length
3982                                  */
3983                                 
3984                                 /* skip the length of the sockaddr_in */ 
3985                                 
3986                                 offset +=1;
3987
3988                                 /* add IP address and desect the sockaddr_in structure */
3989                                 
3990                                 old_offset = offset + 4;
3991                                 item = proto_tree_add_ipv4(tree, hf_mscldap_netlogon_ipaddress, tvb, old_offset, 4, tvb_get_ipv4(tvb,old_offset));
3992
3993                                 if (tree){
3994                                         proto_tree *subtree;
3995
3996                                         subtree = proto_item_add_subtree(item, ett_mscldap_ipdetails);
3997                                         
3998                                         /* get sockaddr family */
3999                                         proto_tree_add_item(subtree, hf_mscldap_netlogon_ipaddress_family, tvb, offset, 2, TRUE);
4000                                         offset +=2;             
4001
4002                                         /* get sockaddr port */
4003                                         proto_tree_add_item(subtree, hf_mscldap_netlogon_ipaddress_port, tvb, offset, 2, TRUE);
4004                                         offset +=2;     
4005                                         
4006                                         /* get IP address */
4007                                         proto_tree_add_ipv4(subtree, hf_mscldap_netlogon_ipaddress_ipv4, tvb, offset, 4, tvb_get_ipv4(tvb,offset));
4008                                         offset +=4;
4009
4010                                         /* skip the 8 bytes of zeros in the sockaddr structure */
4011                                         offset += 8;
4012                                 }
4013
4014                         }
4015
4016                         break;
4017
4018                 default:
4019                         proto_tree_add_uint_format(tree, hf_mscldap_netlogon_type, tvb, offset, 2, itype,"Type: Unknown type (%d)", itype );
4020                         
4021   }                             
4022
4023
4024  /* complete the decode with the version and token details */
4025
4026   offset = len-8;
4027  
4028   /* Version */
4029   proto_tree_add_item(tree, hf_mscldap_netlogon_version, tvb, offset, 4, TRUE);
4030   offset += 4;
4031
4032   /* LM Token */
4033   proto_tree_add_item(tree, hf_mscldap_netlogon_lm_token, tvb, offset, 2, TRUE);
4034   offset += 2;
4035
4036   /* NT Token */
4037   proto_tree_add_item(tree, hf_mscldap_netlogon_nt_token, tvb, offset, 2, TRUE);
4038   offset += 2;
4039
4040 }
4041
4042
4043 static guint
4044 get_sasl_ldap_pdu_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset)
4045 {
4046         /* sasl encapsulated ldap is 4 bytes plus the length in size */
4047         return tvb_get_ntohl(tvb, offset)+4;
4048 }
4049
4050 static void
4051 dissect_sasl_ldap_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
4052 {
4053         dissect_ldap_pdu(tvb, pinfo, tree, FALSE);
4054         return;
4055 }
4056
4057 static guint
4058 get_normal_ldap_pdu_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset)
4059 {
4060         guint32 len;
4061         gboolean ind;
4062         int data_offset;
4063
4064         /* normal ldap is tag+len bytes plus the length
4065          * offset is where the tag is
4066          * offset+1 is where length starts
4067          */
4068         data_offset=get_ber_length(tvb, offset+1, &len, &ind);
4069         return len+data_offset-offset;
4070 }
4071
4072 static void
4073 dissect_normal_ldap_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
4074 {
4075         dissect_ldap_pdu(tvb, pinfo, tree, FALSE);
4076         return;
4077 }
4078
4079 static void
4080 dissect_ldap_oid(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree)
4081 {
4082         char *oid;
4083         const char *oidname;
4084
4085         /* tvb here contains an ascii string that is really an oid */
4086 /* XXX   we should convert the string oid into a real oid so we can use
4087  *       proto_tree_add_oid() instead.
4088  */
4089
4090         oid=tvb_get_ephemeral_string(tvb, 0, tvb_length(tvb));
4091         if(!oid){
4092                 return;
4093         }
4094
4095         oidname=oid_resolved_from_string(oid);
4096
4097         if(oidname){
4098                 proto_tree_add_text(tree, tvb, 0, tvb_length(tvb), "OID: %s (%s)",oid,oidname);
4099         } else {
4100                 proto_tree_add_text(tree, tvb, 0, tvb_length(tvb), "OID: %s",oid);
4101         }
4102 }
4103
4104 #define LDAP_ACCESSMASK_ADS_CREATE_CHILD        0x00000001
4105 static const true_false_string ldap_AccessMask_ADS_CREATE_CHILD_tfs = {
4106    "ADS CREATE CHILD is SET",
4107    "Ads create child is NOT set",
4108 };
4109
4110 #define LDAP_ACCESSMASK_ADS_DELETE_CHILD        0x00000002
4111 static const true_false_string ldap_AccessMask_ADS_DELETE_CHILD_tfs = {
4112    "ADS DELETE CHILD is SET",
4113    "Ads delete child is NOT set",
4114 };
4115 #define LDAP_ACCESSMASK_ADS_LIST                0x00000004
4116 static const true_false_string ldap_AccessMask_ADS_LIST_tfs = {
4117    "ADS LIST is SET",
4118    "Ads list is NOT set",
4119 };
4120 #define LDAP_ACCESSMASK_ADS_SELF_WRITE          0x00000008
4121 static const true_false_string ldap_AccessMask_ADS_SELF_WRITE_tfs = {
4122    "ADS SELF WRITE is SET",
4123    "Ads self write is NOT set",
4124 };
4125 #define LDAP_ACCESSMASK_ADS_READ_PROP           0x00000010
4126 static const true_false_string ldap_AccessMask_ADS_READ_PROP_tfs = {
4127    "ADS READ PROP is SET",
4128    "Ads read prop is NOT set",
4129 };
4130 #define LDAP_ACCESSMASK_ADS_WRITE_PROP          0x00000020
4131 static const true_false_string ldap_AccessMask_ADS_WRITE_PROP_tfs = {
4132    "ADS WRITE PROP is SET",
4133    "Ads write prop is NOT set",
4134 };
4135 #define LDAP_ACCESSMASK_ADS_DELETE_TREE         0x00000040
4136 static const true_false_string ldap_AccessMask_ADS_DELETE_TREE_tfs = {
4137    "ADS DELETE TREE is SET",
4138    "Ads delete tree is NOT set",
4139 };
4140 #define LDAP_ACCESSMASK_ADS_LIST_OBJECT         0x00000080
4141 static const true_false_string ldap_AccessMask_ADS_LIST_OBJECT_tfs = {
4142    "ADS LIST OBJECT is SET",
4143    "Ads list object is NOT set",
4144 };
4145 #define LDAP_ACCESSMASK_ADS_CONTROL_ACCESS      0x00000100
4146 static const true_false_string ldap_AccessMask_ADS_CONTROL_ACCESS_tfs = {
4147    "ADS CONTROL ACCESS is SET",
4148    "Ads control access is NOT set",
4149 };
4150
4151 static void
4152 ldap_specific_rights(tvbuff_t *tvb, gint offset, proto_tree *tree, guint32 access)
4153 {
4154         proto_tree_add_boolean(tree, hf_ldap_AccessMask_ADS_CONTROL_ACCESS, tvb, offset, 4, access);
4155
4156         proto_tree_add_boolean(tree, hf_ldap_AccessMask_ADS_LIST_OBJECT, tvb, offset, 4, access);
4157
4158         proto_tree_add_boolean(tree, hf_ldap_AccessMask_ADS_DELETE_TREE, tvb, offset, 4, access);
4159
4160         proto_tree_add_boolean(tree, hf_ldap_AccessMask_ADS_WRITE_PROP, tvb, offset, 4, access);
4161
4162         proto_tree_add_boolean(tree, hf_ldap_AccessMask_ADS_READ_PROP, tvb, offset, 4, access);
4163
4164         proto_tree_add_boolean(tree, hf_ldap_AccessMask_ADS_SELF_WRITE, tvb, offset, 4, access);
4165
4166         proto_tree_add_boolean(tree, hf_ldap_AccessMask_ADS_LIST, tvb, offset, 4, access);
4167
4168         proto_tree_add_boolean(tree, hf_ldap_AccessMask_ADS_DELETE_CHILD, tvb, offset, 4, access);
4169
4170         proto_tree_add_boolean(tree, hf_ldap_AccessMask_ADS_CREATE_CHILD, tvb, offset, 4, access);
4171 }
4172 struct access_mask_info ldap_access_mask_info = {
4173         "LDAP",                 /* Name of specific rights */
4174         ldap_specific_rights,   /* Dissection function */
4175         NULL,                   /* Generic mapping table */
4176         NULL                    /* Standard mapping table */
4177 };
4178
4179 static void
4180 dissect_ldap_nt_sec_desc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
4181 {
4182         dissect_nt_sec_desc(tvb, 0, pinfo, tree, NULL, TRUE, tvb_length(tvb), &ldap_access_mask_info);
4183 }
4184
4185 static void
4186 dissect_ldap_sid(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree)
4187 {
4188         char *tmpstr;
4189
4190         /* this octet string contains an NT SID */
4191         dissect_nt_sid(tvb, 0, tree, "SID", &tmpstr, hf_ldap_sid);
4192         ldapvalue_string=tmpstr;
4193 }
4194
4195 static void
4196 dissect_ldap_guid(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
4197 {
4198         guint8 drep[4] = { 0x10, 0x00, 0x00, 0x00}; /* fake DREP struct */
4199         e_uuid_t uuid;
4200
4201         /* This octet string contained a GUID */
4202         dissect_dcerpc_uuid_t(tvb, 0, pinfo, tree, drep, hf_ldap_guid, &uuid);
4203
4204         ldapvalue_string=ep_alloc(1024);
4205         g_snprintf(ldapvalue_string, 1023, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
4206                    uuid.Data1, uuid.Data2, uuid.Data3,
4207                    uuid.Data4[0], uuid.Data4[1],
4208                    uuid.Data4[2], uuid.Data4[3],
4209                    uuid.Data4[4], uuid.Data4[5],
4210                    uuid.Data4[6], uuid.Data4[7]);
4211 }
4212
4213 static void
4214 dissect_ldap_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
4215 {
4216         guint32 sasl_len;
4217         guint32 ldap_len;
4218         int offset;
4219         gboolean ind;
4220         conversation_t *conversation;
4221         ldap_conv_info_t *ldap_info = NULL;
4222  
4223         /*
4224          * Do we have a conversation for this connection?
4225          */
4226         conversation = find_conversation(pinfo->fd->num, 
4227                                 &pinfo->src, &pinfo->dst,
4228                                 pinfo->ptype, pinfo->srcport,
4229                                 pinfo->destport, 0);
4230         if(conversation){
4231                 ldap_info = conversation_get_proto_data(conversation, proto_ldap);
4232         }
4233
4234         ldm_tree = NULL;
4235
4236         /* This is a bit tricky. We have to find out whether SASL is used
4237          * so that we know how big a header we are supposed to pass
4238          * to tcp_dissect_pdus()
4239          * We must also cope with the case when a client connects to LDAP
4240          * and performs a few unauthenticated searches of LDAP before
4241          * it performs the bind on the same tcp connection.
4242          */
4243         /* check for a SASL header, i.e. assume it is SASL if 
4244          * 1, first four bytes (SASL length) is an integer 
4245          *    with a value that must be <LDAP_SASL_MAX_BUF and >2
4246          *    (>2 to fight false positives, 0x00000000 is a common
4247          *        "random" tcp payload)
4248          * (SASL ldap PDUs might be >64k in size, which is why 
4249          * LDAP_SASL_MAX_BUF is used - defined in packet-ldap.h)
4250          *
4251          * 2, we must have a conversation and the auth type must
4252          *    be LDAP_AUTH_SASL
4253          */
4254         sasl_len=tvb_get_ntohl(tvb, 0);
4255  
4256         if( sasl_len<2 ){
4257                 goto this_was_not_sasl;
4258         }
4259
4260         if( sasl_len>LDAP_SASL_MAX_BUF ){
4261                 goto this_was_not_sasl;
4262         }
4263                 
4264         if((!ldap_info) || (ldap_info->auth_type!=LDAP_AUTH_SASL) ){
4265                 goto this_was_not_sasl;
4266         }
4267
4268         tcp_dissect_pdus(tvb, pinfo, tree, ldap_desegment, 4, get_sasl_ldap_pdu_len, dissect_sasl_ldap_pdu);
4269         return;
4270
4271 this_was_not_sasl:
4272         /* check if it is a normal BER encoded LDAP packet
4273          * i.e. first byte is 0x30 followed by a length that is
4274          * <64k
4275          * (no ldap PDUs are ever >64kb? )
4276          */
4277         if(tvb_get_guint8(tvb, 0)!=0x30){
4278                 goto this_was_not_normal_ldap;
4279         }
4280
4281         /* check that length makes sense */
4282         offset=get_ber_length(tvb, 1, &ldap_len, &ind);
4283
4284         /* dont check ind since indefinite length is never used for ldap (famous last words)*/
4285         if(ldap_len<2){
4286                 goto this_was_not_normal_ldap;
4287         }
4288
4289         tcp_dissect_pdus(tvb, pinfo, tree, ldap_desegment, 4, get_normal_ldap_pdu_len, dissect_normal_ldap_pdu);
4290
4291         goto end;
4292
4293 this_was_not_normal_ldap:
4294
4295         /* perhaps it was SSL? */
4296         if(ldap_info && 
4297            ldap_info->start_tls_frame && 
4298            ( pinfo->fd->num >= ldap_info->start_tls_frame)) {
4299
4300           /* we have started TLS and so this may be an SSL layer */
4301           guint32 old_start_tls_frame;
4302
4303           /* temporarily dissect this port as SSL */
4304           dissector_delete("tcp.port", tcp_port, ldap_handle); 
4305           ssl_dissector_add(tcp_port, "ldap", TRUE);
4306     
4307           old_start_tls_frame = ldap_info->start_tls_frame;
4308           ldap_info->start_tls_frame = 0; /* make sure we don't call SSL again */
4309           pinfo->can_desegment++; /* ignore this LDAP layer so SSL can use the TCP resegment */
4310
4311           offset = call_dissector(ssl_handle, tvb, pinfo, tree);
4312
4313           ldap_info->start_tls_frame = old_start_tls_frame;
4314           ssl_dissector_delete(tcp_port, "ldap", TRUE);
4315
4316           /* restore ldap as the dissector for this port */
4317           dissector_add("tcp.port", tcp_port, ldap_handle);
4318
4319           /* we are done */
4320           return;
4321         }
4322  end:
4323         return;
4324 }
4325
4326 static void
4327 dissect_mscldap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
4328 {
4329         dissect_ldap_pdu(tvb, pinfo, tree, TRUE);
4330         return;
4331 }
4332
4333
4334 static void
4335 ldap_reinit(void)
4336 {
4337   ldap_conv_info_t *ldap_info;
4338
4339   /* Free up state attached to the ldap_info structures */
4340   for (ldap_info = ldap_info_items; ldap_info != NULL; ) {
4341     ldap_conv_info_t *next;
4342
4343     if (ldap_info->auth_mech != NULL) {
4344       g_free(ldap_info->auth_mech);
4345       ldap_info->auth_mech=NULL;
4346     }
4347     g_hash_table_destroy(ldap_info->matched);
4348     ldap_info->matched=NULL;
4349     g_hash_table_destroy(ldap_info->unmatched);
4350     ldap_info->unmatched=NULL;
4351
4352     next = ldap_info->next;
4353     g_free(ldap_info);
4354     ldap_info = next;
4355   }
4356
4357   ldap_info_items = NULL;
4358   last_frame_seen = 0;
4359
4360 }
4361
4362 void
4363 register_ldap_name_dissector_handle(const char *attr_type, dissector_handle_t dissector)
4364 {
4365         dissector_add_string("ldap.name", attr_type, dissector);
4366 }
4367
4368 void
4369 register_ldap_name_dissector(const char *attr_type, dissector_t dissector, int proto)
4370 {
4371         dissector_handle_t dissector_handle;
4372
4373         dissector_handle=create_dissector_handle(dissector, proto);
4374         register_ldap_name_dissector_handle(attr_type, dissector_handle);
4375 }
4376
4377
4378 /*--- proto_register_ldap -------------------------------------------*/
4379 void proto_register_ldap(void) {
4380
4381   /* List of fields */
4382
4383   static hf_register_info hf[] = {
4384
4385                 { &hf_ldap_sasl_buffer_length,
4386                   { "SASL Buffer Length",       "ldap.sasl_buffer_length",
4387                         FT_UINT32, BASE_DEC, NULL, 0x0,
4388                         "SASL Buffer Length", HFILL }},
4389             { &hf_ldap_response_in,
4390               { "Response In", "ldap.response_in",
4391                 FT_FRAMENUM, BASE_DEC, NULL, 0x0,
4392                 "The response to this LDAP request is in this frame", HFILL }},
4393             { &hf_ldap_response_to,
4394               { "Response To", "ldap.response_to",
4395                 FT_FRAMENUM, BASE_DEC, NULL, 0x0,
4396                 "This is a response to the LDAP request in this frame", HFILL }},
4397             { &hf_ldap_time,
4398               { "Time", "ldap.time",
4399                 FT_RELATIVE_TIME, BASE_NONE, NULL, 0x0,
4400                 "The time between the Call and the Reply", HFILL }},
4401
4402     { &hf_mscldap_netlogon_type,
4403       { "Type", "mscldap.netlogon.type",
4404         FT_UINT16, BASE_DEC, NULL, 0x0,
4405         "NetLogon Response type", HFILL }},
4406
4407     { &hf_mscldap_netlogon_version,
4408       { "Version", "mscldap.netlogon.version",
4409         FT_UINT32, BASE_DEC, NULL, 0x0,
4410         "Version", HFILL }},
4411
4412     { &hf_mscldap_netlogon_ipaddress_family,
4413       { "Family", "mscldap.netlogon.ipaddress.family",
4414         FT_UINT16, BASE_DEC, NULL, 0x0,
4415         "Family", HFILL }},
4416
4417     { &hf_mscldap_netlogon_ipaddress_ipv4,
4418       { "IPv4", "mscldap.netlogon.ipaddress.ipv4",
4419         FT_IPv4, BASE_DEC, NULL, 0x0,
4420         "IP Address", HFILL }},
4421
4422         { &hf_mscldap_netlogon_ipaddress_port,
4423       { "Port", "mscldap.netlogon.ipaddress.port",
4424         FT_UINT16, BASE_DEC, NULL, 0x0,
4425         "Port", HFILL }},
4426
4427         { &hf_mscldap_netlogon_ipaddress,
4428       { "IP Address","mscldap.netlogon.ipaddress",
4429                 FT_IPv4, BASE_NONE, NULL, 0x0,
4430                         "Domain Controller IP Address ", HFILL }},
4431
4432     { &hf_mscldap_netlogon_lm_token,
4433       { "LM Token", "mscldap.netlogon.lm_token",
4434         FT_UINT16, BASE_HEX, NULL, 0x0,
4435         "LM Token", HFILL }},
4436
4437     { &hf_mscldap_netlogon_nt_token,
4438       { "NT Token", "mscldap.netlogon.nt_token",
4439         FT_UINT16, BASE_HEX, NULL, 0x0,
4440         "NT Token", HFILL }},
4441
4442     { &hf_mscldap_netlogon_flags,
4443       { "Flags", "mscldap.netlogon.flags",
4444         FT_UINT32, BASE_HEX, NULL, 0x0,
4445         "Netlogon flags describing the DC properties", HFILL }},
4446     
4447         { &hf_mscldap_ntver_flags,
4448       { "Search Flags", "mscldap.ntver.searchflags",
4449         FT_UINT32, BASE_HEX, NULL, 0x0,
4450         "cldap Netlogon request flags", HFILL }},
4451         
4452         { &hf_mscldap_domain_guid,
4453       { "Domain GUID", "mscldap.domain.guid",
4454         FT_BYTES, BASE_HEX, NULL, 0x0,
4455         "Domain GUID", HFILL }},
4456
4457     { &hf_mscldap_forest,
4458       { "Forest", "mscldap.forest",
4459         FT_STRING, BASE_NONE, NULL, 0x0,
4460         "Forest", HFILL }},
4461
4462     { &hf_mscldap_domain,
4463       { "Domain", "mscldap.domain",
4464         FT_STRING, BASE_NONE, NULL, 0x0,
4465         "Domainname", HFILL }},
4466
4467     { &hf_mscldap_hostname,
4468       { "Hostname", "mscldap.hostname",
4469         FT_STRING, BASE_NONE, NULL, 0x0,
4470         "Hostname", HFILL }},
4471
4472     { &hf_mscldap_nb_domain,
4473       { "NetBios Domain", "mscldap.nb_domain",
4474         FT_STRING, BASE_NONE, NULL, 0x0,
4475         "NetBios Domainname", HFILL }},
4476
4477     { &hf_mscldap_nb_hostname,
4478       { "NetBios Hostname", "mscldap.nb_hostname",
4479         FT_STRING, BASE_NONE, NULL, 0x0,
4480         "NetBios Hostname", HFILL }},
4481
4482     { &hf_mscldap_username,
4483       { "Username", "mscldap.username",
4484         FT_STRING, BASE_NONE, NULL, 0x0,
4485         "User name", HFILL }},
4486
4487     { &hf_mscldap_sitename,
4488       { "Site", "mscldap.sitename",
4489         FT_STRING, BASE_NONE, NULL, 0x0,
4490         "Site name", HFILL }},
4491
4492     { &hf_mscldap_clientsitename,
4493       { "Client Site", "mscldap.clientsitename",
4494         FT_STRING, BASE_NONE, NULL, 0x0,
4495         "Client Site name", HFILL }},
4496
4497     { &hf_ldap_sid,
4498       { "Sid", "ldap.sid",
4499         FT_STRING, BASE_NONE, NULL, 0x0,
4500         "Sid", HFILL }},
4501
4502         { &hf_mscldap_ntver_flags_v5cs,
4503       { "V5CS", "mscldap.ntver.searchflags.v5cs", FT_BOOLEAN, 32,
4504         TFS(&tfs_ntver_v5cs), 0x00000010, "", HFILL }},
4505
4506         { &hf_mscldap_ntver_flags_v5ip,
4507       { "V5IP", "mscldap.ntver.searchflags.v5ip", FT_BOOLEAN, 32,
4508         TFS(&tfs_ntver_v5ip), 0x00000008, "", HFILL }},
4509
4510         { &hf_mscldap_ntver_flags_v5ex,
4511       { "V5EX", "mscldap.ntver.searchflags.v5ex", FT_BOOLEAN, 32,
4512         TFS(&tfs_ntver_v5ex), 0x00000004, "", HFILL }},
4513
4514         { &hf_mscldap_ntver_flags_v5,
4515       { "V5", "mscldap.ntver.searchflags.v5", FT_BOOLEAN, 32,
4516         TFS(&tfs_ntver_v5), 0x00000002, "", HFILL }},
4517
4518         { &hf_mscldap_ntver_flags_v1,
4519       { "V1", "mscldap.ntver.searchflags.v1", FT_BOOLEAN, 32,
4520         TFS(&tfs_ntver_v1), 0x00000001, "", HFILL }},
4521
4522         { &hf_mscldap_ntver_flags_gc,
4523       { "GC", "mscldap.ntver.searchflags.gc", FT_BOOLEAN, 32,
4524         TFS(&tfs_ntver_gc), 0x80000000, "", HFILL }},
4525
4526         { &hf_mscldap_ntver_flags_local,
4527       { "Local", "mscldap.ntver.searchflags.local", FT_BOOLEAN, 32,
4528         TFS(&tfs_ntver_local), 0x40000000, "", HFILL }},
4529
4530         { &hf_mscldap_ntver_flags_ip,
4531       { "IP", "mscldap.ntver.searchflags.ip", FT_BOOLEAN, 32,
4532         TFS(&tfs_ntver_ip), 0x20000000, "", HFILL }},
4533         
4534         { &hf_mscldap_ntver_flags_pdc,
4535       { "PDC", "mscldap.ntver.searchflags.pdc", FT_BOOLEAN, 32,
4536         TFS(&tfs_ntver_pdc), 0x10000000, "", HFILL }},
4537
4538         { &hf_mscldap_ntver_flags_nt4,
4539       { "NT4", "mscldap.ntver.searchflags.nt4", FT_BOOLEAN, 32,
4540         TFS(&tfs_ntver_nt4), 0x01000000, "", HFILL }},
4541
4542         { &hf_mscldap_netlogon_flags_pdc,
4543       { "PDC", "mscldap.netlogon.flags.pdc", FT_BOOLEAN, 32,
4544         TFS(&tfs_ads_pdc), 0x00000001, "Is this DC a PDC or not?", HFILL }},
4545
4546     { &hf_mscldap_netlogon_flags_gc,
4547       { "GC", "mscldap.netlogon.flags.gc", FT_BOOLEAN, 32,
4548         TFS(&tfs_ads_gc), 0x00000004, "Does this dc service as a GLOBAL CATALOGUE?", HFILL }},
4549
4550     { &hf_mscldap_netlogon_flags_ldap,
4551       { "LDAP", "mscldap.netlogon.flags.ldap", FT_BOOLEAN, 32,
4552         TFS(&tfs_ads_ldap), 0x00000008, "Does this DC act as an LDAP server?", HFILL }},
4553
4554     { &hf_mscldap_netlogon_flags_ds,
4555       { "DS", "mscldap.netlogon.flags.ds", FT_BOOLEAN, 32,
4556         TFS(&tfs_ads_ds), 0x00000010, "Does this dc provide DS services?", HFILL }},
4557
4558     { &hf_mscldap_netlogon_flags_kdc,
4559       { "KDC", "mscldap.netlogon.flags.kdc", FT_BOOLEAN, 32,
4560         TFS(&tfs_ads_kdc), 0x00000020, "Does this dc act as a KDC?", HFILL }},
4561
4562     { &hf_mscldap_netlogon_flags_timeserv,
4563       { "Time Serv", "mscldap.netlogon.flags.timeserv", FT_BOOLEAN, 32,
4564         TFS(&tfs_ads_timeserv), 0x00000040, "Does this dc provide time services (ntp) ?", HFILL }},
4565
4566     { &hf_mscldap_netlogon_flags_closest,
4567       { "Closest", "mscldap.netlogon.flags.closest", FT_BOOLEAN, 32,
4568         TFS(&tfs_ads_closest), 0x00000080, "Is this the closest dc?", HFILL }},
4569
4570     { &hf_mscldap_netlogon_flags_writable,
4571       { "Writable", "mscldap.netlogon.flags.writable", FT_BOOLEAN, 32,
4572         TFS(&tfs_ads_writable), 0x00000100, "Is this dc writable?", HFILL }},
4573
4574     { &hf_mscldap_netlogon_flags_good_timeserv,
4575       { "Good Time Serv", "mscldap.netlogon.flags.good_timeserv", FT_BOOLEAN, 32,
4576         TFS(&tfs_ads_good_timeserv), 0x00000200, "Is this a Good Time Server? (i.e. does it have a hardware clock)", HFILL }},
4577
4578     { &hf_mscldap_netlogon_flags_ndnc,
4579       { "NDNC", "mscldap.netlogon.flags.ndnc", FT_BOOLEAN, 32,
4580         TFS(&tfs_ads_ndnc), 0x00000400, "Is this an NDNC dc?", HFILL }},
4581
4582         { &hf_mscldap_netlogon_flags_rodc,
4583       { "RODC", "mscldap.netlogon.flags.rodc", FT_BOOLEAN, 32,
4584         TFS(&tfs_ads_rodc), 0x00000800, "Is this an read only dc?", HFILL }},
4585
4586         { &hf_mscldap_netlogon_flags_wdc,
4587       { "WDC", "mscldap.netlogon.flags.writabledc.", FT_BOOLEAN, 32,
4588         TFS(&tfs_ads_wdc), 0x00001000, "Is this an writable dc (Windows 2008)?", HFILL }},
4589
4590         { &hf_mscldap_netlogon_flags_dns,
4591       { "DNS", "mscldap.netlogon.flags.dnsname", FT_BOOLEAN, 32,
4592         TFS(&tfs_ads_dns), 0x20000000, "Does the server have a dns name (Windows 2008)?", HFILL }},
4593
4594     { &hf_mscldap_netlogon_flags_dnc,
4595       { "DNC", "mscldap.netlogon.flags.defaultnc", FT_BOOLEAN, 32,
4596         TFS(&tfs_ads_dnc), 0x40000000, "Is this the default NC (Windows 2008)?", HFILL }},
4597
4598     { &hf_mscldap_netlogon_flags_fnc,
4599       { "FDC", "mscldap.netlogon.flags.forestnc", FT_BOOLEAN, 32,
4600         TFS(&tfs_ads_fnc), 0x80000000, "Is the the NC the default forest root(Windows 2008)?", HFILL }},
4601
4602     { &hf_ldap_guid,
4603       { "GUID", "ldap.guid", FT_GUID, BASE_NONE,
4604         NULL, 0, "GUID", HFILL }},
4605
4606     { &hf_ldap_AccessMask_ADS_CREATE_CHILD, 
4607           { "Create Child", "ldap.AccessMask.ADS_CREATE_CHILD", FT_BOOLEAN, 32, TFS(&ldap_AccessMask_ADS_CREATE_CHILD_tfs), LDAP_ACCESSMASK_ADS_CREATE_CHILD, "", HFILL }},
4608
4609     { &hf_ldap_AccessMask_ADS_DELETE_CHILD, 
4610           { "Delete Child", "ldap.AccessMask.ADS_DELETE_CHILD", FT_BOOLEAN, 32, TFS(&ldap_AccessMask_ADS_DELETE_CHILD_tfs), LDAP_ACCESSMASK_ADS_DELETE_CHILD, "", HFILL }},
4611
4612     { &hf_ldap_AccessMask_ADS_LIST, 
4613           { "List", "ldap.AccessMask.ADS_LIST", FT_BOOLEAN, 32, TFS(&ldap_AccessMask_ADS_LIST_tfs), LDAP_ACCESSMASK_ADS_LIST, "", HFILL }},
4614
4615     { &hf_ldap_AccessMask_ADS_SELF_WRITE, 
4616           { "Self Write", "ldap.AccessMask.ADS_SELF_WRITE", FT_BOOLEAN, 32, TFS(&ldap_AccessMask_ADS_SELF_WRITE_tfs), LDAP_ACCESSMASK_ADS_SELF_WRITE, "", HFILL }},
4617
4618     { &hf_ldap_AccessMask_ADS_READ_PROP, 
4619           { "Read Prop", "ldap.AccessMask.ADS_READ_PROP", FT_BOOLEAN, 32, TFS(&ldap_AccessMask_ADS_READ_PROP_tfs), LDAP_ACCESSMASK_ADS_READ_PROP, "", HFILL }},
4620
4621     { &hf_ldap_AccessMask_ADS_WRITE_PROP, 
4622           { "Write Prop", "ldap.AccessMask.ADS_WRITE_PROP", FT_BOOLEAN, 32, TFS(&ldap_AccessMask_ADS_WRITE_PROP_tfs), LDAP_ACCESSMASK_ADS_WRITE_PROP, "", HFILL }},
4623
4624     { &hf_ldap_AccessMask_ADS_DELETE_TREE, 
4625           { "Delete Tree", "ldap.AccessMask.ADS_DELETE_TREE", FT_BOOLEAN, 32, TFS(&ldap_AccessMask_ADS_DELETE_TREE_tfs), LDAP_ACCESSMASK_ADS_DELETE_TREE, "", HFILL }},
4626
4627     { &hf_ldap_AccessMask_ADS_LIST_OBJECT, 
4628           { "List Object", "ldap.AccessMask.ADS_LIST_OBJECT", FT_BOOLEAN, 32, TFS(&ldap_AccessMask_ADS_LIST_OBJECT_tfs), LDAP_ACCESSMASK_ADS_LIST_OBJECT, "", HFILL }},
4629
4630     { &hf_ldap_AccessMask_ADS_CONTROL_ACCESS, 
4631           { "Control Access", "ldap.AccessMask.ADS_CONTROL_ACCESS", FT_BOOLEAN, 32, TFS(&ldap_AccessMask_ADS_CONTROL_ACCESS_tfs), LDAP_ACCESSMASK_ADS_CONTROL_ACCESS, "", HFILL }},
4632
4633
4634 /*--- Included file: packet-ldap-hfarr.c ---*/
4635 #line 1 "packet-ldap-hfarr.c"
4636     { &hf_ldap_LDAPMessage_PDU,
4637       { "LDAPMessage", "ldap.LDAPMessage",
4638         FT_NONE, BASE_NONE, NULL, 0,
4639         "ldap.LDAPMessage", HFILL }},
4640     { &hf_ldap_SearchControlValue_PDU,
4641       { "SearchControlValue", "ldap.SearchControlValue",
4642         FT_NONE, BASE_NONE, NULL, 0,
4643         "ldap.SearchControlValue", HFILL }},
4644     { &hf_ldap_SortKeyList_PDU,
4645       { "SortKeyList", "ldap.SortKeyList",
4646         FT_UINT32, BASE_DEC, NULL, 0,
4647         "ldap.SortKeyList", HFILL }},
4648     { &hf_ldap_SortResult_PDU,
4649       { "SortResult", "ldap.SortResult",
4650         FT_NONE, BASE_NONE, NULL, 0,
4651         "ldap.SortResult", HFILL }},
4652     { &hf_ldap_ReplControlValue_PDU,
4653       { "ReplControlValue", "ldap.ReplControlValue",
4654         FT_NONE, BASE_NONE, NULL, 0,
4655         "ldap.ReplControlValue", HFILL }},
4656     { &hf_ldap_PasswdModifyRequestValue_PDU,
4657       { "PasswdModifyRequestValue", "ldap.PasswdModifyRequestValue",
4658         FT_NONE, BASE_NONE, NULL, 0,
4659         "ldap.PasswdModifyRequestValue", HFILL }},
4660     { &hf_ldap_CancelRequestValue_PDU,
4661       { "CancelRequestValue", "ldap.CancelRequestValue",
4662         FT_NONE, BASE_NONE, NULL, 0,
4663         "ldap.CancelRequestValue", HFILL }},
4664     { &hf_ldap_messageID,
4665       { "messageID", "ldap.messageID",
4666         FT_UINT32, BASE_DEC, NULL, 0,
4667         "ldap.MessageID", HFILL }},
4668     { &hf_ldap_protocolOp,
4669       { "protocolOp", "ldap.protocolOp",
4670         FT_UINT32, BASE_DEC, VALS(ldap_ProtocolOp_vals), 0,
4671         "ldap.ProtocolOp", HFILL }},
4672     { &hf_ldap_controls,
4673       { "controls", "ldap.controls",
4674         FT_UINT32, BASE_DEC, NULL, 0,
4675         "ldap.Controls", HFILL }},
4676     { &hf_ldap_bindRequest,
4677       { "bindRequest", "ldap.bindRequest",
4678         FT_NONE, BASE_NONE, NULL, 0,
4679         "ldap.BindRequest", HFILL }},
4680     { &hf_ldap_bindResponse,
4681       { "bindResponse", "ldap.bindResponse",
4682         FT_NONE, BASE_NONE, NULL, 0,
4683         "ldap.BindResponse", HFILL }},
4684     { &hf_ldap_unbindRequest,
4685       { "unbindRequest", "ldap.unbindRequest",
4686         FT_NONE, BASE_NONE, NULL, 0,
4687         "ldap.UnbindRequest", HFILL }},
4688     { &hf_ldap_searchRequest,
4689       { "searchRequest", "ldap.searchRequest",
4690         FT_NONE, BASE_NONE, NULL, 0,
4691         "ldap.SearchRequest", HFILL }},
4692     { &hf_ldap_searchResEntry,
4693       { "searchResEntry", "ldap.searchResEntry",
4694         FT_NONE, BASE_NONE, NULL, 0,
4695         "ldap.SearchResultEntry", HFILL }},
4696     { &hf_ldap_searchResDone,
4697       { "searchResDone", "ldap.searchResDone",
4698         FT_NONE, BASE_NONE, NULL, 0,
4699         "ldap.SearchResultDone", HFILL }},
4700     { &hf_ldap_searchResRef,
4701       { "searchResRef", "ldap.searchResRef",
4702         FT_UINT32, BASE_DEC, NULL, 0,
4703         "ldap.SearchResultReference", HFILL }},
4704     { &hf_ldap_modifyRequest,
4705       { "modifyRequest", "ldap.modifyRequest",
4706         FT_NONE, BASE_NONE, NULL, 0,
4707         "ldap.ModifyRequest", HFILL }},
4708     { &hf_ldap_modifyResponse,
4709       { "modifyResponse", "ldap.modifyResponse",
4710         FT_NONE, BASE_NONE, NULL, 0,
4711         "ldap.ModifyResponse", HFILL }},
4712     { &hf_ldap_addRequest,
4713       { "addRequest", "ldap.addRequest",
4714         FT_NONE, BASE_NONE, NULL, 0,
4715         "ldap.AddRequest", HFILL }},
4716     { &hf_ldap_addResponse,
4717       { "addResponse", "ldap.addResponse",
4718         FT_NONE, BASE_NONE, NULL, 0,
4719         "ldap.AddResponse", HFILL }},
4720     { &hf_ldap_delRequest,
4721       { "delRequest", "ldap.delRequest",
4722         FT_STRING, BASE_NONE, NULL, 0,
4723         "ldap.DelRequest", HFILL }},
4724     { &hf_ldap_delResponse,
4725       { "delResponse", "ldap.delResponse",
4726         FT_NONE, BASE_NONE, NULL, 0,
4727         "ldap.DelResponse", HFILL }},
4728     { &hf_ldap_modDNRequest,
4729       { "modDNRequest", "ldap.modDNRequest",
4730         FT_NONE, BASE_NONE, NULL, 0,
4731         "ldap.ModifyDNRequest", HFILL }},
4732     { &hf_ldap_modDNResponse,
4733       { "modDNResponse", "ldap.modDNResponse",
4734         FT_NONE, BASE_NONE, NULL, 0,
4735         "ldap.ModifyDNResponse", HFILL }},
4736     { &hf_ldap_compareRequest,
4737       { "compareRequest", "ldap.compareRequest",
4738         FT_NONE, BASE_NONE, NULL, 0,
4739         "ldap.CompareRequest", HFILL }},
4740     { &hf_ldap_compareResponse,
4741       { "compareResponse", "ldap.compareResponse",
4742         FT_NONE, BASE_NONE, NULL, 0,
4743         "ldap.CompareResponse", HFILL }},
4744     { &hf_ldap_abandonRequest,
4745       { "abandonRequest", "ldap.abandonRequest",
4746         FT_UINT32, BASE_DEC, NULL, 0,
4747         "ldap.AbandonRequest", HFILL }},
4748     { &hf_ldap_extendedReq,
4749       { "extendedReq", "ldap.extendedReq",
4750         FT_NONE, BASE_NONE, NULL, 0,
4751         "ldap.ExtendedRequest", HFILL }},
4752     { &hf_ldap_extendedResp,
4753       { "extendedResp", "ldap.extendedResp",
4754         FT_NONE, BASE_NONE, NULL, 0,
4755         "ldap.ExtendedResponse", HFILL }},
4756     { &hf_ldap_AttributeDescriptionList_item,
4757       { "AttributeDescriptionList", "ldap.AttributeDescriptionList_item",
4758         FT_STRING, BASE_NONE, NULL, 0,
4759         "ldap.AttributeDescription", HFILL }},
4760     { &hf_ldap_attributeDesc,
4761       { "attributeDesc", "ldap.attributeDesc",
4762         FT_STRING, BASE_NONE, NULL, 0,
4763         "ldap.AttributeDescription", HFILL }},
4764     { &hf_ldap_assertionValue,
4765       { "assertionValue", "ldap.assertionValue",
4766         FT_STRING, BASE_NONE, NULL, 0,
4767         "ldap.AssertionValue", HFILL }},
4768     { &hf_ldap_type,
4769       { "type", "ldap.type",
4770         FT_STRING, BASE_NONE, NULL, 0,
4771         "ldap.AttributeDescription", HFILL }},
4772     { &hf_ldap_vals,
4773       { "vals", "ldap.vals",
4774         FT_UINT32, BASE_DEC, NULL, 0,
4775         "ldap.SET_OF_AttributeValue", HFILL }},
4776     { &hf_ldap_vals_item,
4777       { "vals", "ldap.vals_item",
4778         FT_BYTES, BASE_HEX, NULL, 0,
4779         "ldap.AttributeValue", HFILL }},
4780     { &hf_ldap_resultCode,
4781       { "resultCode", "ldap.resultCode",
4782         FT_UINT32, BASE_DEC, VALS(ldap_T_resultCode_vals), 0,
4783         "ldap.T_resultCode", HFILL }},
4784     { &hf_ldap_matchedDN,
4785       { "matchedDN", "ldap.matchedDN",
4786         FT_STRING, BASE_NONE, NULL, 0,
4787         "ldap.LDAPDN", HFILL }},
4788     { &hf_ldap_errorMessage,
4789       { "errorMessage", "ldap.errorMessage",
4790         FT_STRING, BASE_NONE, NULL, 0,
4791         "ldap.ErrorMessage", HFILL }},
4792     { &hf_ldap_referral,
4793       { "referral", "ldap.referral",
4794         FT_UINT32, BASE_DEC, NULL, 0,
4795         "ldap.Referral", HFILL }},
4796     { &hf_ldap_Referral_item,
4797       { "Referral", "ldap.Referral_item",
4798         FT_STRING, BASE_NONE, NULL, 0,
4799         "ldap.LDAPURL", HFILL }},
4800     { &hf_ldap_Controls_item,
4801       { "Controls", "ldap.Controls_item",
4802         FT_NONE, BASE_NONE, NULL, 0,
4803         "ldap.Control", HFILL }},
4804     { &hf_ldap_controlType,
4805       { "controlType", "ldap.controlType",
4806         FT_STRING, BASE_NONE, NULL, 0,
4807         "ldap.ControlType", HFILL }},
4808     { &hf_ldap_criticality,
4809       { "criticality", "ldap.criticality",
4810         FT_BOOLEAN, 8, NULL, 0,
4811         "ldap.BOOLEAN", HFILL }},
4812     { &hf_ldap_controlValue,
4813       { "controlValue", "ldap.controlValue",
4814         FT_BYTES, BASE_HEX, NULL, 0,
4815         "ldap.T_controlValue", HFILL }},
4816     { &hf_ldap_version,
4817       { "version", "ldap.version",
4818         FT_UINT32, BASE_DEC, NULL, 0,
4819         "ldap.INTEGER_1_127", HFILL }},
4820     { &hf_ldap_name,
4821       { "name", "ldap.name",
4822         FT_STRING, BASE_NONE, NULL, 0,
4823         "ldap.LDAPDN", HFILL }},
4824     { &hf_ldap_authentication,
4825       { "authentication", "ldap.authentication",
4826         FT_UINT32, BASE_DEC, VALS(ldap_AuthenticationChoice_vals), 0,
4827         "ldap.AuthenticationChoice", HFILL }},
4828     { &hf_ldap_simple,
4829       { "simple", "ldap.simple",
4830         FT_BYTES, BASE_HEX, NULL, 0,
4831         "ldap.Simple", HFILL }},
4832     { &hf_ldap_sasl,
4833       { "sasl", "ldap.sasl",
4834         FT_NONE, BASE_NONE, NULL, 0,
4835         "ldap.SaslCredentials", HFILL }},
4836     { &hf_ldap_ntlmsspNegotiate,
4837       { "ntlmsspNegotiate", "ldap.ntlmsspNegotiate",
4838         FT_BYTES, BASE_HEX, NULL, 0,
4839         "ldap.T_ntlmsspNegotiate", HFILL }},
4840     { &hf_ldap_ntlmsspAuth,
4841       { "ntlmsspAuth", "ldap.ntlmsspAuth",
4842         FT_BYTES, BASE_HEX, NULL, 0,
4843         "ldap.T_ntlmsspAuth", HFILL }},
4844     { &hf_ldap_mechanism,
4845       { "mechanism", "ldap.mechanism",
4846         FT_STRING, BASE_NONE, NULL, 0,
4847         "ldap.Mechanism", HFILL }},
4848     { &hf_ldap_credentials,
4849       { "credentials", "ldap.credentials",
4850         FT_BYTES, BASE_HEX, NULL, 0,
4851         "ldap.Credentials", HFILL }},
4852     { &hf_ldap_bindResponse_resultCode,
4853       { "resultCode", "ldap.resultCode",
4854         FT_UINT32, BASE_DEC, VALS(ldap_BindResponse_resultCode_vals), 0,
4855         "ldap.BindResponse_resultCode", HFILL }},
4856     { &hf_ldap_bindResponse_matchedDN,
4857       { "matchedDN", "ldap.matchedDN",
4858         FT_STRING, BASE_NONE, NULL, 0,
4859         "ldap.T_bindResponse_matchedDN", HFILL }},
4860     { &hf_ldap_serverSaslCreds,
4861       { "serverSaslCreds", "ldap.serverSaslCreds",
4862         FT_BYTES, BASE_HEX, NULL, 0,
4863         "ldap.ServerSaslCreds", HFILL }},
4864     { &hf_ldap_baseObject,
4865       { "baseObject", "ldap.baseObject",
4866         FT_STRING, BASE_NONE, NULL, 0,
4867         "ldap.LDAPDN", HFILL }},
4868     { &hf_ldap_scope,
4869       { "scope", "ldap.scope",
4870         FT_UINT32, BASE_DEC, VALS(ldap_T_scope_vals), 0,
4871         "ldap.T_scope", HFILL }},
4872     { &hf_ldap_derefAliases,
4873       { "derefAliases", "ldap.derefAliases",
4874         FT_UINT32, BASE_DEC, VALS(ldap_T_derefAliases_vals), 0,
4875         "ldap.T_derefAliases", HFILL }},
4876     { &hf_ldap_sizeLimit,
4877       { "sizeLimit", "ldap.sizeLimit",
4878         FT_UINT32, BASE_DEC, NULL, 0,
4879         "ldap.INTEGER_0_maxInt", HFILL }},
4880     { &hf_ldap_timeLimit,
4881       { "timeLimit", "ldap.timeLimit",
4882         FT_UINT32, BASE_DEC, NULL, 0,
4883         "ldap.INTEGER_0_maxInt", HFILL }},
4884     { &hf_ldap_typesOnly,
4885       { "typesOnly", "ldap.typesOnly",
4886         FT_BOOLEAN, 8, NULL, 0,
4887         "ldap.BOOLEAN", HFILL }},
4888     { &hf_ldap_filter,
4889       { "filter", "ldap.filter",
4890         FT_UINT32, BASE_DEC, VALS(ldap_Filter_vals), 0,
4891         "ldap.T_filter", HFILL }},
4892     { &hf_ldap_searchRequest_attributes,
4893       { "attributes", "ldap.attributes",
4894         FT_UINT32, BASE_DEC, NULL, 0,
4895         "ldap.AttributeDescriptionList", HFILL }},
4896     { &hf_ldap_and,
4897       { "and", "ldap.and",
4898         FT_UINT32, BASE_DEC, NULL, 0,
4899         "ldap.T_and", HFILL }},
4900     { &hf_ldap_and_item,
4901       { "and", "ldap.and_item",
4902         FT_UINT32, BASE_DEC, VALS(ldap_Filter_vals), 0,
4903         "ldap.T_and_item", HFILL }},
4904     { &hf_ldap_or,
4905       { "or", "ldap.or",
4906         FT_UINT32, BASE_DEC, NULL, 0,
4907         "ldap.T_or", HFILL }},
4908     { &hf_ldap_or_item,
4909       { "or", "ldap.or_item",
4910         FT_UINT32, BASE_DEC, VALS(ldap_Filter_vals), 0,
4911         "ldap.T_or_item", HFILL }},
4912     { &hf_ldap_not,
4913       { "not", "ldap.not",
4914         FT_UINT32, BASE_DEC, VALS(ldap_Filter_vals), 0,
4915         "ldap.T_not", HFILL }},
4916     { &hf_ldap_equalityMatch,
4917       { "equalityMatch", "ldap.equalityMatch",
4918         FT_NONE, BASE_NONE, NULL, 0,
4919         "ldap.T_equalityMatch", HFILL }},
4920     { &hf_ldap_substrings,
4921       { "substrings", "ldap.substrings",
4922         FT_NONE, BASE_NONE, NULL, 0,
4923         "ldap.SubstringFilter", HFILL }},
4924     { &hf_ldap_greaterOrEqual,
4925       { "greaterOrEqual", "ldap.greaterOrEqual",
4926         FT_NONE, BASE_NONE, NULL, 0,
4927         "ldap.T_greaterOrEqual", HFILL }},
4928     { &hf_ldap_lessOrEqual,
4929       { "lessOrEqual", "ldap.lessOrEqual",
4930         FT_NONE, BASE_NONE, NULL, 0,
4931         "ldap.T_lessOrEqual", HFILL }},
4932     { &hf_ldap_present,
4933       { "present", "ldap.present",
4934         FT_STRING, BASE_NONE, NULL, 0,
4935         "ldap.T_present", HFILL }},
4936     { &hf_ldap_approxMatch,
4937       { "approxMatch", "ldap.approxMatch",
4938         FT_NONE, BASE_NONE, NULL, 0,
4939         "ldap.T_approxMatch", HFILL }},
4940     { &hf_ldap_extensibleMatch,
4941       { "extensibleMatch", "ldap.extensibleMatch",
4942         FT_NONE, BASE_NONE, NULL, 0,
4943         "ldap.T_extensibleMatch", HFILL }},
4944     { &hf_ldap_substringFilter_substrings,
4945       { "substrings", "ldap.substrings",
4946         FT_UINT32, BASE_DEC, NULL, 0,
4947         "ldap.T_substringFilter_substrings", HFILL }},
4948     { &hf_ldap_substringFilter_substrings_item,
4949       { "substrings", "ldap.substrings_item",
4950         FT_UINT32, BASE_DEC, VALS(ldap_T_substringFilter_substrings_item_vals), 0,
4951         "ldap.T_substringFilter_substrings_item", HFILL }},
4952     { &hf_ldap_initial,
4953       { "initial", "ldap.initial",
4954         FT_STRING, BASE_NONE, NULL, 0,
4955         "ldap.LDAPString", HFILL }},
4956     { &hf_ldap_any,
4957       { "any", "ldap.any",
4958         FT_STRING, BASE_NONE, NULL, 0,
4959         "ldap.LDAPString", HFILL }},
4960     { &hf_ldap_final,
4961       { "final", "ldap.final",
4962         FT_STRING, BASE_NONE, NULL, 0,
4963         "ldap.LDAPString", HFILL }},
4964     { &hf_ldap_matchingRule,
4965       { "matchingRule", "ldap.matchingRule",
4966         FT_STRING, BASE_NONE, NULL, 0,
4967         "ldap.MatchingRuleId", HFILL }},
4968     { &hf_ldap_matchValue,
4969       { "matchValue", "ldap.matchValue",
4970         FT_STRING, BASE_NONE, NULL, 0,
4971         "ldap.AssertionValue", HFILL }},
4972     { &hf_ldap_dnAttributes,
4973       { "dnAttributes", "ldap.dnAttributes",
4974         FT_BOOLEAN, 8, NULL, 0,
4975         "ldap.T_dnAttributes", HFILL }},
4976     { &hf_ldap_objectName,
4977       { "objectName", "ldap.objectName",
4978         FT_STRING, BASE_NONE, NULL, 0,
4979         "ldap.LDAPDN", HFILL }},
4980     { &hf_ldap_searchResultEntry_attributes,
4981       { "attributes", "ldap.attributes",
4982         FT_UINT32, BASE_DEC, NULL, 0,
4983         "ldap.PartialAttributeList", HFILL }},
4984     { &hf_ldap_PartialAttributeList_item,
4985       { "PartialAttributeList", "ldap.PartialAttributeList_item",
4986         FT_NONE, BASE_NONE, NULL, 0,
4987         "ldap.PartialAttributeList_item", HFILL }},
4988     { &hf_ldap__untag_item,
4989       { "_untag", "ldap._untag_item",
4990         FT_STRING, BASE_NONE, NULL, 0,
4991         "ldap.LDAPURL", HFILL }},
4992     { &hf_ldap_object,
4993       { "object", "ldap.object",
4994         FT_STRING, BASE_NONE, NULL, 0,
4995         "ldap.LDAPDN", HFILL }},
4996     { &hf_ldap_modifyRequest_modification,
4997       { "modification", "ldap.modification",
4998         FT_UINT32, BASE_DEC, NULL, 0,
4999         "ldap.ModifyRequest_modification", HFILL }},
5000     { &hf_ldap_modifyRequest_modification_item,
5001       { "modification", "ldap.modification_item",
5002         FT_NONE, BASE_NONE, NULL, 0,
5003         "ldap.T_modifyRequest_modification_item", HFILL }},
5004     { &hf_ldap_operation,
5005       { "operation", "ldap.operation",
5006         FT_UINT32, BASE_DEC, VALS(ldap_T_operation_vals), 0,
5007         "ldap.T_operation", HFILL }},
5008     { &hf_ldap_modification,
5009       { "modification", "ldap.modification",
5010         FT_NONE, BASE_NONE, NULL, 0,
5011         "ldap.AttributeTypeAndValues", HFILL }},
5012     { &hf_ldap_entry,
5013       { "entry", "ldap.entry",
5014         FT_STRING, BASE_NONE, NULL, 0,
5015         "ldap.LDAPDN", HFILL }},
5016     { &hf_ldap_attributes,
5017       { "attributes", "ldap.attributes",
5018         FT_UINT32, BASE_DEC, NULL, 0,
5019         "ldap.AttributeList", HFILL }},
5020     { &hf_ldap_AttributeList_item,
5021       { "AttributeList", "ldap.AttributeList_item",
5022         FT_NONE, BASE_NONE, NULL, 0,
5023         "ldap.AttributeList_item", HFILL }},
5024     { &hf_ldap_newrdn,
5025       { "newrdn", "ldap.newrdn",
5026         FT_STRING, BASE_NONE, NULL, 0,
5027         "ldap.RelativeLDAPDN", HFILL }},
5028     { &hf_ldap_deleteoldrdn,
5029       { "deleteoldrdn", "ldap.deleteoldrdn",
5030         FT_BOOLEAN, 8, NULL, 0,
5031         "ldap.BOOLEAN", HFILL }},
5032     { &hf_ldap_newSuperior,
5033       { "newSuperior", "ldap.newSuperior",
5034         FT_STRING, BASE_NONE, NULL, 0,
5035         "ldap.LDAPDN", HFILL }},
5036     { &hf_ldap_ava,
5037       { "ava", "ldap.ava",
5038         FT_NONE, BASE_NONE, NULL, 0,
5039         "ldap.AttributeValueAssertion", HFILL }},
5040     { &hf_ldap_requestName,
5041       { "requestName", "ldap.requestName",
5042         FT_STRING, BASE_NONE, NULL, 0,
5043         "ldap.LDAPOID", HFILL }},
5044     { &hf_ldap_requestValue,
5045       { "requestValue", "ldap.requestValue",
5046         FT_BYTES, BASE_HEX, NULL, 0,
5047         "ldap.T_requestValue", HFILL }},
5048     { &hf_ldap_extendedResponse_resultCode,
5049       { "resultCode", "ldap.resultCode",
5050         FT_UINT32, BASE_DEC, VALS(ldap_ExtendedResponse_resultCode_vals), 0,
5051         "ldap.ExtendedResponse_resultCode", HFILL }},
5052     { &hf_ldap_responseName,
5053       { "responseName", "ldap.responseName",
5054         FT_STRING, BASE_NONE, NULL, 0,
5055         "ldap.ResponseName", HFILL }},
5056     { &hf_ldap_response,
5057       { "response", "ldap.response",
5058         FT_BYTES, BASE_HEX, NULL, 0,
5059         "ldap.OCTET_STRING", HFILL }},
5060     { &hf_ldap_size,
5061       { "size", "ldap.size",
5062         FT_INT32, BASE_DEC, NULL, 0,
5063         "ldap.INTEGER", HFILL }},
5064     { &hf_ldap_cookie,
5065       { "cookie", "ldap.cookie",
5066         FT_BYTES, BASE_HEX, NULL, 0,
5067         "ldap.OCTET_STRING", HFILL }},
5068     { &hf_ldap_SortKeyList_item,
5069       { "SortKeyList", "ldap.SortKeyList_item",
5070         FT_NONE, BASE_NONE, NULL, 0,
5071         "ldap.SortKeyList_item", HFILL }},
5072     { &hf_ldap_attributeType,
5073       { "attributeType", "ldap.attributeType",
5074         FT_STRING, BASE_NONE, NULL, 0,
5075         "ldap.AttributeDescription", HFILL }},
5076     { &hf_ldap_orderingRule,
5077       { "orderingRule", "ldap.orderingRule",
5078         FT_STRING, BASE_NONE, NULL, 0,
5079         "ldap.MatchingRuleId", HFILL }},
5080     { &hf_ldap_reverseOrder,
5081       { "reverseOrder", "ldap.reverseOrder",
5082         FT_BOOLEAN, 8, NULL, 0,
5083         "ldap.BOOLEAN", HFILL }},
5084     { &hf_ldap_sortResult,
5085       { "sortResult", "ldap.sortResult",
5086         FT_UINT32, BASE_DEC, VALS(ldap_T_sortResult_vals), 0,
5087         "ldap.T_sortResult", HFILL }},
5088     { &hf_ldap_parentsFirst,
5089       { "parentsFirst", "ldap.parentsFirst",
5090         FT_INT32, BASE_DEC, NULL, 0,
5091         "ldap.INTEGER", HFILL }},
5092     { &hf_ldap_maxReturnLength,
5093       { "maxReturnLength", "ldap.maxReturnLength",
5094         FT_INT32, BASE_DEC, NULL, 0,
5095         "ldap.INTEGER", HFILL }},
5096     { &hf_ldap_userIdentity,
5097       { "userIdentity", "ldap.userIdentity",
5098         FT_BYTES, BASE_HEX, NULL, 0,
5099         "ldap.OCTET_STRING", HFILL }},
5100     { &hf_ldap_oldPasswd,
5101       { "oldPasswd", "ldap.oldPasswd",
5102         FT_BYTES, BASE_HEX, NULL, 0,
5103         "ldap.OCTET_STRING", HFILL }},
5104     { &hf_ldap_newPasswd,
5105       { "newPasswd", "ldap.newPasswd",
5106         FT_BYTES, BASE_HEX, NULL, 0,
5107         "ldap.OCTET_STRING", HFILL }},
5108     { &hf_ldap_genPasswd,
5109       { "genPasswd", "ldap.genPasswd",
5110         FT_BYTES, BASE_HEX, NULL, 0,
5111         "ldap.OCTET_STRING", HFILL }},
5112     { &hf_ldap_cancelID,
5113       { "cancelID", "ldap.cancelID",
5114         FT_UINT32, BASE_DEC, NULL, 0,
5115         "ldap.MessageID", HFILL }},
5116
5117 /*--- End of included file: packet-ldap-hfarr.c ---*/
5118 #line 2088 "packet-ldap-template.c"
5119   };
5120
5121   /* List of subtrees */
5122   static gint *ett[] = {
5123     &ett_ldap,
5124     &ett_ldap_payload,
5125     &ett_ldap_sasl_blob,
5126     &ett_ldap_msg,
5127     &ett_mscldap_netlogon_flags,
5128         &ett_mscldap_ntver_flags,
5129         &ett_mscldap_ipdetails,
5130
5131
5132 /*--- Included file: packet-ldap-ettarr.c ---*/
5133 #line 1 "packet-ldap-ettarr.c"
5134     &ett_ldap_LDAPMessage,
5135     &ett_ldap_ProtocolOp,
5136     &ett_ldap_AttributeDescriptionList,
5137     &ett_ldap_AttributeValueAssertion,
5138     &ett_ldap_Attribute,
5139     &ett_ldap_SET_OF_AttributeValue,
5140     &ett_ldap_LDAPResult,
5141     &ett_ldap_Referral,
5142     &ett_ldap_Controls,
5143     &ett_ldap_Control,
5144     &ett_ldap_BindRequest_U,
5145     &ett_ldap_AuthenticationChoice,
5146     &ett_ldap_SaslCredentials,
5147     &ett_ldap_BindResponse_U,
5148     &ett_ldap_SearchRequest_U,
5149     &ett_ldap_Filter,
5150     &ett_ldap_T_and,
5151     &ett_ldap_T_or,
5152     &ett_ldap_SubstringFilter,
5153     &ett_ldap_T_substringFilter_substrings,
5154     &ett_ldap_T_substringFilter_substrings_item,
5155     &ett_ldap_MatchingRuleAssertion,
5156     &ett_ldap_SearchResultEntry_U,
5157     &ett_ldap_PartialAttributeList,
5158     &ett_ldap_PartialAttributeList_item,
5159     &ett_ldap_SEQUENCE_OF_LDAPURL,
5160     &ett_ldap_ModifyRequest_U,
5161     &ett_ldap_ModifyRequest_modification,
5162     &ett_ldap_T_modifyRequest_modification_item,
5163     &ett_ldap_AttributeTypeAndValues,
5164     &ett_ldap_AddRequest_U,
5165     &ett_ldap_AttributeList,
5166     &ett_ldap_AttributeList_item,
5167     &ett_ldap_ModifyDNRequest_U,
5168     &ett_ldap_CompareRequest_U,
5169     &ett_ldap_ExtendedRequest_U,
5170     &ett_ldap_ExtendedResponse_U,
5171     &ett_ldap_SearchControlValue,
5172     &ett_ldap_SortKeyList,
5173     &ett_ldap_SortKeyList_item,
5174     &ett_ldap_SortResult,
5175     &ett_ldap_ReplControlValue,
5176     &ett_ldap_PasswdModifyRequestValue,
5177     &ett_ldap_PasswdModifyResponseValue,
5178     &ett_ldap_CancelRequestValue,
5179
5180 /*--- End of included file: packet-ldap-ettarr.c ---*/
5181 #line 2101 "packet-ldap-template.c"
5182   };
5183
5184     module_t *ldap_module;
5185
5186   /* Register protocol */
5187   proto_ldap = proto_register_protocol(PNAME, PSNAME, PFNAME);
5188   /* Register fields and subtrees */
5189   proto_register_field_array(proto_ldap, hf, array_length(hf));
5190   proto_register_subtree_array(ett, array_length(ett));
5191
5192
5193   register_dissector("ldap", dissect_ldap_tcp, proto_ldap);
5194
5195   ldap_module = prefs_register_protocol(proto_ldap, prefs_register_ldap);
5196   prefs_register_bool_preference(ldap_module, "desegment_ldap_messages",
5197     "Reassemble LDAP messages spanning multiple TCP segments",
5198     "Whether the LDAP dissector should reassemble messages spanning multiple TCP segments."
5199     " To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.",
5200     &ldap_desegment);
5201
5202   prefs_register_uint_preference(ldap_module, "tcp.port", "LDAP TCP Port",
5203                                  "Set the port for LDAP operations",
5204                                  10, &global_ldap_tcp_port);
5205
5206   prefs_register_uint_preference(ldap_module, "ssl.port", "LDAPS TCP Port",
5207                                  "Set the port for LDAP operations over SSL",
5208                                  10, &global_ldaps_tcp_port);
5209
5210   prefs_register_obsolete_preference(ldap_module, "max_pdu");
5211
5212   proto_cldap = proto_register_protocol(
5213           "Connectionless Lightweight Directory Access Protocol",
5214           "CLDAP", "cldap");
5215
5216   register_init_routine(ldap_reinit);
5217   ldap_tap=register_tap("ldap");
5218
5219   ldap_name_dissector_table = register_dissector_table("ldap.name", "LDAP Attribute Type Dissectors", FT_STRING, BASE_NONE);
5220
5221 }
5222
5223
5224 /*--- proto_reg_handoff_ldap ---------------------------------------*/
5225 void
5226 proto_reg_handoff_ldap(void)
5227 {
5228         dissector_handle_t cldap_handle;
5229         ldap_handle = create_dissector_handle(dissect_ldap_tcp, proto_ldap);
5230
5231         dissector_add("tcp.port", global_ldap_tcp_port, ldap_handle);
5232         dissector_add("tcp.port", TCP_PORT_GLOBALCAT_LDAP, ldap_handle);
5233
5234         ssl_dissector_add(global_ldaps_tcp_port, "ldap", TRUE);
5235
5236         cldap_handle = create_dissector_handle(dissect_mscldap, proto_cldap);
5237         dissector_add("udp.port", UDP_PORT_CLDAP, cldap_handle);
5238
5239         gssapi_handle = find_dissector("gssapi");
5240         gssapi_wrap_handle = find_dissector("gssapi_verf");
5241         spnego_handle = find_dissector("spnego");
5242
5243         ntlmssp_handle = find_dissector("ntlmssp");
5244
5245         ssl_handle = find_dissector("ssl");
5246
5247 /*  http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dsml/dsml/ldap_controls_and_session_support.asp */
5248         oid_add_from_string("LDAP_PAGED_RESULT_OID_STRING","1.2.840.113556.1.4.319");
5249         oid_add_from_string("LDAP_SERVER_SHOW_DELETED_OID","1.2.840.113556.1.4.417");
5250         oid_add_from_string("LDAP_SERVER_SORT_OID","1.2.840.113556.1.4.473");
5251         oid_add_from_string("LDAP_CONTROL_SORT_RESP_OID","1.2.840.113556.1.4.474");
5252         oid_add_from_string("LDAP_SERVER_CROSSDOM_MOVE_TARGET_OID","1.2.840.113556.1.4.521");
5253         oid_add_from_string("LDAP_SERVER_NOTIFICATION_OID","1.2.840.113556.1.4.528");
5254         oid_add_from_string("LDAP_SERVER_EXTENDED_DN_OID","1.2.840.113556.1.4.529");
5255         oid_add_from_string("meetingAdvertiseScope","1.2.840.113556.1.4.582");
5256         oid_add_from_string("LDAP_SERVER_LAZY_COMMIT_OID","1.2.840.113556.1.4.619");
5257         oid_add_from_string("mhsORAddress","1.2.840.113556.1.4.650");
5258         oid_add_from_string("managedObjects","1.2.840.113556.1.4.654");
5259         oid_add_from_string("LDAP_CAP_ACTIVE_DIRECTORY_OID","1.2.840.113556.1.4.800");
5260         oid_add_from_string("LDAP_SERVER_SD_FLAGS_OID","1.2.840.113556.1.4.801");
5261         oid_add_from_string("LDAP_OID_COMPARATOR_OR","1.2.840.113556.1.4.804");
5262         oid_add_from_string("LDAP_SERVER_TREE_DELETE_OID","1.2.840.113556.1.4.805");
5263         oid_add_from_string("LDAP_SERVER_DIRSYNC_OID","1.2.840.113556.1.4.841");
5264         oid_add_from_string("None","1.2.840.113556.1.4.970");
5265         oid_add_from_string("LDAP_SERVER_VERIFY_NAME_OID","1.2.840.113556.1.4.1338");
5266         oid_add_from_string("LDAP_SERVER_DOMAIN_SCOPE_OID","1.2.840.113556.1.4.1339");
5267         oid_add_from_string("LDAP_SERVER_SEARCH_OPTIONS_OID","1.2.840.113556.1.4.1340");
5268         oid_add_from_string("LDAP_SERVER_PERMISSIVE_MODIFY_OID","1.2.840.113556.1.4.1413");
5269         oid_add_from_string("LDAP_SERVER_ASQ_OID","1.2.840.113556.1.4.1504");
5270         oid_add_from_string("LDAP_CAP_ACTIVE_DIRECTORY_V51_OID","1.2.840.113556.1.4.1670");
5271         oid_add_from_string("LDAP_SERVER_FAST_BIND_OID","1.2.840.113556.1.4.1781");
5272         oid_add_from_string("LDAP_CAP_ACTIVE_DIRECTORY_LDAP_INTEG_OID","1.2.840.113556.1.4.1791");
5273         oid_add_from_string("msDS-ObjectReference","1.2.840.113556.1.4.1840");
5274         oid_add_from_string("msDS-QuotaEffective","1.2.840.113556.1.4.1848");
5275         oid_add_from_string("LDAP_CAP_ACTIVE_DIRECTORY_ADAM_OID","1.2.840.113556.1.4.1851");
5276         oid_add_from_string("msDS-PortSSL","1.2.840.113556.1.4.1860");
5277         oid_add_from_string("msDS-isRODC","1.2.840.113556.1.4.1960");
5278         oid_add_from_string("msDS-SDReferenceDomain","1.2.840.113556.1.4.1711");
5279         oid_add_from_string("msDS-AdditionalDnsHostName","1.2.840.113556.1.4.1717");
5280         oid_add_from_string("None","1.3.6.1.4.1.1466.101.119.1");
5281         oid_add_from_string("LDAP_START_TLS_OID","1.3.6.1.4.1.1466.20037");
5282         oid_add_from_string("LDAP_CONTROL_VLVREQUEST VLV","2.16.840.1.113730.3.4.9");
5283         oid_add_from_string("LDAP_CONTROL_VLVRESPONSE VLV","2.16.840.1.113730.3.4.10");
5284
5285         register_ldap_name_dissector("netlogon", dissect_NetLogon_PDU, proto_cldap);
5286         register_ldap_name_dissector("objectGUID", dissect_ldap_guid, proto_ldap);
5287         register_ldap_name_dissector("supportedControl", dissect_ldap_oid, proto_ldap);
5288         register_ldap_name_dissector("supportedCapabilities", dissect_ldap_oid, proto_ldap);
5289         register_ldap_name_dissector("objectSid", dissect_ldap_sid, proto_ldap);
5290         register_ldap_name_dissector("nTSecurityDescriptor", dissect_ldap_nt_sec_desc, proto_ldap);
5291
5292
5293 /*--- Included file: packet-ldap-dis-tab.c ---*/
5294 #line 1 "packet-ldap-dis-tab.c"
5295   register_ber_oid_dissector("1.2.840.113556.1.4.319", dissect_SearchControlValue_PDU, proto_ldap, "pagedResultsControl");
5296   register_ber_oid_dissector("1.2.840.113556.1.4.473", dissect_SortKeyList_PDU, proto_ldap, "sortKeyList");
5297   register_ber_oid_dissector("1.2.840.113556.1.4.474", dissect_SortResult_PDU, proto_ldap, "sortResult");
5298   register_ber_oid_dissector("1.2.840.113556.1.4.841", dissect_ReplControlValue_PDU, proto_ldap, "replControlValue");
5299   register_ber_oid_dissector("1.3.6.1.4.1.4203.1.11.1", dissect_PasswdModifyRequestValue_PDU, proto_ldap, "passwdModifyOID");
5300   register_ber_oid_dissector("1.3.6.1.1.8", dissect_CancelRequestValue_PDU, proto_ldap, "cancelRequstOID");
5301
5302
5303 /*--- End of included file: packet-ldap-dis-tab.c ---*/
5304 #line 2212 "packet-ldap-template.c"
5305         
5306
5307 }
5308
5309 void prefs_register_ldap(void) {
5310
5311   if(tcp_port != global_ldap_tcp_port) {
5312     if(tcp_port)
5313       dissector_delete("tcp.port", tcp_port, ldap_handle);
5314
5315     /* Set our port number for future use */
5316     tcp_port = global_ldap_tcp_port;
5317
5318     if(tcp_port) 
5319       dissector_add("tcp.port", tcp_port, ldap_handle);
5320
5321   }
5322
5323   if(ssl_port != global_ldaps_tcp_port) {
5324     if(ssl_port)
5325       ssl_dissector_delete(ssl_port, "ldap", TRUE);
5326
5327     /* Set our port number for future use */
5328     ssl_port = global_ldaps_tcp_port;
5329
5330     if(ssl_port) 
5331       ssl_dissector_add(ssl_port, "ldap", TRUE);
5332   }
5333
5334 }