LDAP attribute type dissector framework including support for "netlogon" attribute...
[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 Ethereal dissector compiler    */
3 /* ./packet-ldap.c                                                            */
4 /* ../../tools/asn2eth.py -X -b -e -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  * Ethereal - Network traffic analyzer
17  * By Gerald Combs <gerald@ethereal.com>
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 asn2eth compiler
75  * Anders Broman <anders.broman@ericsson.com>
76  */
77
78 #ifdef HAVE_CONFIG_H
79 # include "config.h"
80 #endif
81
82 #include <stdio.h>
83 #include <string.h>
84
85 #include <glib.h>
86
87 #include <epan/packet.h>
88 #include <epan/conversation.h>
89 #include <epan/prefs.h>
90 #include <epan/tap.h>
91 #include <epan/emem.h>
92 #include <epan/oid_resolv.h>
93 #include <epan/strutil.h>
94
95 #include "packet-frame.h"
96 #include "packet-ldap.h"
97
98 #include "packet-ber.h"
99 #include "packet-per.h"
100
101 #define PNAME  "Lightweight-Directory-Access-Protocol"
102 #define PSNAME "LDAP"
103 #define PFNAME "ldap"
104
105 /* Initialize the protocol and registered fields */
106 static int ldap_tap = -1;
107 static int proto_ldap = -1;
108 static int proto_cldap = -1;
109
110 static int hf_ldap_sasl_buffer_length = -1;
111 static int hf_ldap_response_in = -1;
112 static int hf_ldap_response_to = -1;
113 static int hf_ldap_time = -1;
114
115 static int hf_mscldap_netlogon_type = -1;
116 static int hf_mscldap_netlogon_flags = -1;
117 static int hf_mscldap_netlogon_flags_pdc = -1;
118 static int hf_mscldap_netlogon_flags_gc = -1;
119 static int hf_mscldap_netlogon_flags_ldap = -1;
120 static int hf_mscldap_netlogon_flags_ds = -1;
121 static int hf_mscldap_netlogon_flags_kdc = -1;
122 static int hf_mscldap_netlogon_flags_timeserv = -1;
123 static int hf_mscldap_netlogon_flags_closest = -1;
124 static int hf_mscldap_netlogon_flags_writable = -1;
125 static int hf_mscldap_netlogon_flags_good_timeserv = -1;
126 static int hf_mscldap_netlogon_flags_ndnc = -1;
127 static int hf_mscldap_domain_guid = -1;
128 static int hf_mscldap_forest = -1;
129 static int hf_mscldap_domain = -1;
130 static int hf_mscldap_hostname = -1;
131 static int hf_mscldap_nb_domain = -1;
132 static int hf_mscldap_nb_hostname = -1;
133 static int hf_mscldap_username = -1;
134 static int hf_mscldap_sitename = -1;
135 static int hf_mscldap_clientsitename = -1;
136 static int hf_mscldap_netlogon_version = -1;
137 static int hf_mscldap_netlogon_lm_token = -1;
138 static int hf_mscldap_netlogon_nt_token = -1;
139
140
141 /*--- Included file: packet-ldap-hf.c ---*/
142 #line 1 "packet-ldap-hf.c"
143 static int hf_ldap_LDAPMessage_PDU = -1;          /* LDAPMessage */
144 static int hf_ldap_messageID = -1;                /* MessageID */
145 static int hf_ldap_protocolOp = -1;               /* ProtocolOp */
146 static int hf_ldap_controls = -1;                 /* Controls */
147 static int hf_ldap_bindRequest = -1;              /* BindRequest */
148 static int hf_ldap_bindResponse = -1;             /* BindResponse */
149 static int hf_ldap_unbindRequest = -1;            /* UnbindRequest */
150 static int hf_ldap_searchRequest = -1;            /* SearchRequest */
151 static int hf_ldap_searchResEntry = -1;           /* SearchResultEntry */
152 static int hf_ldap_searchResDone = -1;            /* SearchResultDone */
153 static int hf_ldap_searchResRef = -1;             /* SearchResultReference */
154 static int hf_ldap_modifyRequest = -1;            /* ModifyRequest */
155 static int hf_ldap_modifyResponse = -1;           /* ModifyResponse */
156 static int hf_ldap_addRequest = -1;               /* AddRequest */
157 static int hf_ldap_addResponse = -1;              /* AddResponse */
158 static int hf_ldap_delRequest = -1;               /* DelRequest */
159 static int hf_ldap_delResponse = -1;              /* DelResponse */
160 static int hf_ldap_modDNRequest = -1;             /* ModifyDNRequest */
161 static int hf_ldap_modDNResponse = -1;            /* ModifyDNResponse */
162 static int hf_ldap_compareRequest = -1;           /* CompareRequest */
163 static int hf_ldap_compareResponse = -1;          /* CompareResponse */
164 static int hf_ldap_abandonRequest = -1;           /* AbandonRequest */
165 static int hf_ldap_extendedReq = -1;              /* ExtendedRequest */
166 static int hf_ldap_extendedResp = -1;             /* ExtendedResponse */
167 static int hf_ldap_AttributeDescriptionList_item = -1;  /* AttributeDescription */
168 static int hf_ldap_attributeDesc = -1;            /* AttributeDescription */
169 static int hf_ldap_assertionValue = -1;           /* AssertionValue */
170 static int hf_ldap_type = -1;                     /* AttributeDescription */
171 static int hf_ldap_vals = -1;                     /* SET_OF_AttributeValue */
172 static int hf_ldap_vals_item = -1;                /* AttributeValue */
173 static int hf_ldap_resultCode = -1;               /* T_resultCode */
174 static int hf_ldap_matchedDN = -1;                /* LDAPDN */
175 static int hf_ldap_errorMessage = -1;             /* ErrorMessage */
176 static int hf_ldap_referral = -1;                 /* Referral */
177 static int hf_ldap_Referral_item = -1;            /* LDAPURL */
178 static int hf_ldap_Controls_item = -1;            /* Control */
179 static int hf_ldap_controlType = -1;              /* ControlType */
180 static int hf_ldap_criticality = -1;              /* BOOLEAN */
181 static int hf_ldap_controlValue = -1;             /* OCTET_STRING */
182 static int hf_ldap_version = -1;                  /* INTEGER_1_127 */
183 static int hf_ldap_name = -1;                     /* LDAPDN */
184 static int hf_ldap_authentication = -1;           /* AuthenticationChoice */
185 static int hf_ldap_simple = -1;                   /* Simple */
186 static int hf_ldap_sasl = -1;                     /* SaslCredentials */
187 static int hf_ldap_mechanism = -1;                /* Mechanism */
188 static int hf_ldap_credentials = -1;              /* Credentials */
189 static int hf_ldap_bindResponse_resultCode = -1;  /* BindResponse_resultCode */
190 static int hf_ldap_serverSaslCreds = -1;          /* ServerSaslCreds */
191 static int hf_ldap_baseObject = -1;               /* LDAPDN */
192 static int hf_ldap_scope = -1;                    /* T_scope */
193 static int hf_ldap_derefAliases = -1;             /* T_derefAliases */
194 static int hf_ldap_sizeLimit = -1;                /* INTEGER_0_maxInt */
195 static int hf_ldap_timeLimit = -1;                /* INTEGER_0_maxInt */
196 static int hf_ldap_typesOnly = -1;                /* BOOLEAN */
197 static int hf_ldap_filter = -1;                   /* Filter */
198 static int hf_ldap_searchRequest_attributes = -1;  /* AttributeDescriptionList */
199 static int hf_ldap_and = -1;                      /* SET_OF_Filter */
200 static int hf_ldap_and_item = -1;                 /* Filter */
201 static int hf_ldap_or = -1;                       /* SET_OF_Filter */
202 static int hf_ldap_or_item = -1;                  /* Filter */
203 static int hf_ldap_not = -1;                      /* Filter */
204 static int hf_ldap_equalityMatch = -1;            /* AttributeValueAssertion */
205 static int hf_ldap_substrings = -1;               /* SubstringFilter */
206 static int hf_ldap_greaterOrEqual = -1;           /* AttributeValueAssertion */
207 static int hf_ldap_lessOrEqual = -1;              /* AttributeValueAssertion */
208 static int hf_ldap_present = -1;                  /* AttributeDescription */
209 static int hf_ldap_approxMatch = -1;              /* AttributeValueAssertion */
210 static int hf_ldap_extensibleMatch = -1;          /* MatchingRuleAssertion */
211 static int hf_ldap_substringFilter_substrings = -1;  /* T_substrings */
212 static int hf_ldap_substrings_item = -1;          /* T_substrings_item */
213 static int hf_ldap_initial = -1;                  /* LDAPString */
214 static int hf_ldap_any = -1;                      /* LDAPString */
215 static int hf_ldap_final = -1;                    /* LDAPString */
216 static int hf_ldap_matchingRule = -1;             /* MatchingRuleId */
217 static int hf_ldap_matchValue = -1;               /* AssertionValue */
218 static int hf_ldap_dnAttributes = -1;             /* BOOLEAN */
219 static int hf_ldap_objectName = -1;               /* LDAPDN */
220 static int hf_ldap_searchResultEntry_attributes = -1;  /* PartialAttributeList */
221 static int hf_ldap_PartialAttributeList_item = -1;  /* PartialAttributeList_item */
222 static int hf_ldap_SearchResultReference_item = -1;  /* LDAPURL */
223 static int hf_ldap_object = -1;                   /* LDAPDN */
224 static int hf_ldap_modifyRequest_modification = -1;  /* ModifyRequest_modification */
225 static int hf_ldap_modification_item = -1;        /* T_modification_item */
226 static int hf_ldap_operation = -1;                /* T_operation */
227 static int hf_ldap_modification = -1;             /* AttributeTypeAndValues */
228 static int hf_ldap_entry = -1;                    /* LDAPDN */
229 static int hf_ldap_attributes = -1;               /* AttributeList */
230 static int hf_ldap_AttributeList_item = -1;       /* AttributeList_item */
231 static int hf_ldap_newrdn = -1;                   /* RelativeLDAPDN */
232 static int hf_ldap_deleteoldrdn = -1;             /* BOOLEAN */
233 static int hf_ldap_newSuperior = -1;              /* LDAPDN */
234 static int hf_ldap_ava = -1;                      /* AttributeValueAssertion */
235 static int hf_ldap_requestName = -1;              /* LDAPOID */
236 static int hf_ldap_requestValue = -1;             /* OCTET_STRING */
237 static int hf_ldap_extendedResponse_resultCode = -1;  /* ExtendedResponse_resultCode */
238 static int hf_ldap_responseName = -1;             /* ResponseName */
239 static int hf_ldap_response = -1;                 /* OCTET_STRING */
240
241 /*--- End of included file: packet-ldap-hf.c ---*/
242 #line 133 "packet-ldap-template.c"
243
244 /* Initialize the subtree pointers */
245 static gint ett_ldap = -1;
246 static gint ett_ldap_msg = -1;
247 static gint ett_ldap_sasl_blob = -1;
248 static guint ett_ldap_payload = -1;
249 static gint ett_mscldap_netlogon_flags = -1;
250
251
252 /*--- Included file: packet-ldap-ett.c ---*/
253 #line 1 "packet-ldap-ett.c"
254 static gint ett_ldap_LDAPMessage = -1;
255 static gint ett_ldap_ProtocolOp = -1;
256 static gint ett_ldap_AttributeDescriptionList = -1;
257 static gint ett_ldap_AttributeValueAssertion = -1;
258 static gint ett_ldap_Attribute = -1;
259 static gint ett_ldap_SET_OF_AttributeValue = -1;
260 static gint ett_ldap_LDAPResult = -1;
261 static gint ett_ldap_Referral = -1;
262 static gint ett_ldap_Controls = -1;
263 static gint ett_ldap_Control = -1;
264 static gint ett_ldap_BindRequest = -1;
265 static gint ett_ldap_AuthenticationChoice = -1;
266 static gint ett_ldap_SaslCredentials = -1;
267 static gint ett_ldap_BindResponse = -1;
268 static gint ett_ldap_SearchRequest = -1;
269 static gint ett_ldap_Filter = -1;
270 static gint ett_ldap_SET_OF_Filter = -1;
271 static gint ett_ldap_SubstringFilter = -1;
272 static gint ett_ldap_T_substrings = -1;
273 static gint ett_ldap_T_substrings_item = -1;
274 static gint ett_ldap_MatchingRuleAssertion = -1;
275 static gint ett_ldap_SearchResultEntry = -1;
276 static gint ett_ldap_PartialAttributeList = -1;
277 static gint ett_ldap_PartialAttributeList_item = -1;
278 static gint ett_ldap_SearchResultReference = -1;
279 static gint ett_ldap_ModifyRequest = -1;
280 static gint ett_ldap_ModifyRequest_modification = -1;
281 static gint ett_ldap_T_modification_item = -1;
282 static gint ett_ldap_AttributeTypeAndValues = -1;
283 static gint ett_ldap_AddRequest = -1;
284 static gint ett_ldap_AttributeList = -1;
285 static gint ett_ldap_AttributeList_item = -1;
286 static gint ett_ldap_ModifyDNRequest = -1;
287 static gint ett_ldap_CompareRequest = -1;
288 static gint ett_ldap_ExtendedRequest = -1;
289 static gint ett_ldap_ExtendedResponse = -1;
290
291 /*--- End of included file: packet-ldap-ett.c ---*/
292 #line 142 "packet-ldap-template.c"
293
294 static dissector_table_t ldap_name_dissector_table=NULL;
295
296 /* desegmentation of LDAP */
297 static gboolean ldap_desegment = TRUE;
298 static guint    ldap_tcp_port = 389;
299 static gboolean do_protocolop = FALSE;
300 static gchar    *attr_type = NULL;
301 static gboolean is_binary_attr_type = FALSE;
302
303 #define TCP_PORT_LDAP                   389
304 #define UDP_PORT_CLDAP                  389
305 #define TCP_PORT_GLOBALCAT_LDAP         3268 /* Windows 2000 Global Catalog */
306
307 static dissector_handle_t gssapi_handle;
308 static dissector_handle_t gssapi_wrap_handle;
309
310
311 /* different types of rpc calls ontop of ms cldap */
312 #define MSCLDAP_RPC_NETLOGON    1
313
314 /* Message type Choice values */
315 static const value_string ldap_ProtocolOp_choice_vals[] = {
316   {   0, "bindRequest" },
317   {   1, "bindResponse" },
318   {   2, "unbindRequest" },
319   {   3, "searchRequest" },
320   {   4, "searchResEntry" },
321   {   5, "searchResDone" },
322   {       6, "searchResRef" },
323   {   7, "modifyRequest" },
324   {   8, "modifyResponse" },
325   {   9, "addRequest" },
326   {  10, "addResponse" },
327   {  11, "delRequest" },
328   {  12, "delResponse" },
329   {  13, "modDNRequest" },
330   {  14, "modDNResponse" },
331   {  15, "compareRequest" },
332   {  16, "compareResponse" },
333   {  17, "abandonRequest" },
334   {  18, "extendedReq" },
335   {  19, "extendedResp" },
336   { 0, NULL }
337 };
338 /*
339  * Data structure attached to a conversation, giving authentication
340  * information from a bind request.
341  * We keep a linked list of them, so that we can free up all the
342  * authentication mechanism strings.
343  */
344 typedef struct ldap_conv_info_t {
345   struct ldap_conv_info_t *next;
346   guint auth_type;              /* authentication type */
347   char *auth_mech;              /* authentication mechanism */
348   guint32 first_auth_frame;     /* first frame that would use a security layer */
349   GHashTable *unmatched;
350   GHashTable *matched;
351   gboolean is_mscldap;
352   gboolean first_time;
353   guint32  num_results;
354 } ldap_conv_info_t;
355 static ldap_conv_info_t *ldap_info_items;
356
357 static guint
358 ldap_info_hash_matched(gconstpointer k)
359 {
360   const ldap_call_response_t *key = k;
361
362   return key->messageId;
363 }
364
365 static gint
366 ldap_info_equal_matched(gconstpointer k1, gconstpointer k2)
367 {
368   const ldap_call_response_t *key1 = k1;
369   const ldap_call_response_t *key2 = k2;
370
371   if( key1->req_frame && key2->req_frame && (key1->req_frame!=key2->req_frame) ){
372     return 0;
373   }
374   /* a response may span multiple frames
375   if( key1->rep_frame && key2->rep_frame && (key1->rep_frame!=key2->rep_frame) ){
376     return 0;
377   }
378   */
379
380   return key1->messageId==key2->messageId;
381 }
382
383 static guint
384 ldap_info_hash_unmatched(gconstpointer k)
385 {
386   const ldap_call_response_t *key = k;
387
388   return key->messageId;
389 }
390
391 static gint
392 ldap_info_equal_unmatched(gconstpointer k1, gconstpointer k2)
393 {
394   const ldap_call_response_t *key1 = k1;
395   const ldap_call_response_t *key2 = k2;
396
397   return key1->messageId==key2->messageId;
398 }
399
400 /* Global variables */
401 char *mechanism = NULL;
402 static gint MessageID =-1;
403 static gint ProtocolOp = -1;
404 static gint result = 0;
405 static proto_item *ldm_tree = NULL; /* item to add text to */
406
407 static void ldap_do_protocolop(packet_info *pinfo)
408 {
409   const gchar* valstr;
410
411   if (do_protocolop)  {
412
413     valstr = val_to_str(ProtocolOp, ldap_ProtocolOp_choice_vals, "Unknown (%%u)");
414
415     if(check_col(pinfo->cinfo, COL_INFO))
416       col_append_fstr(pinfo->cinfo, COL_INFO, "%s(%u) ", valstr, MessageID);
417
418     if(ldm_tree)
419       proto_item_append_text(ldm_tree, " %s(%d)", valstr, MessageID); 
420
421     do_protocolop = FALSE;
422
423   }
424 }
425
426 static ldap_call_response_t *
427 ldap_match_call_response(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint messageId, guint protocolOpTag)
428 {
429   ldap_call_response_t lcr, *lcrp=NULL;
430   ldap_conv_info_t *ldap_info = (ldap_conv_info_t *)pinfo->private_data;
431
432   /* first see if we have already matched this */
433
434       lcr.messageId=messageId;
435       switch(protocolOpTag){
436         case LDAP_REQ_BIND:
437         case LDAP_REQ_SEARCH:
438         case LDAP_REQ_MODIFY:
439         case LDAP_REQ_ADD:
440         case LDAP_REQ_DELETE:
441         case LDAP_REQ_MODRDN:
442         case LDAP_REQ_COMPARE:
443           lcr.is_request=TRUE;
444           lcr.req_frame=pinfo->fd->num;
445           lcr.rep_frame=0;
446           break;
447         case LDAP_RES_BIND:
448         case LDAP_RES_SEARCH_ENTRY:
449         case LDAP_RES_SEARCH_REF:
450         case LDAP_RES_SEARCH_RESULT:
451         case LDAP_RES_MODIFY:
452         case LDAP_RES_ADD:
453         case LDAP_RES_DELETE:
454         case LDAP_RES_MODRDN:
455         case LDAP_RES_COMPARE:
456           lcr.is_request=FALSE;
457           lcr.req_frame=0;
458           lcr.rep_frame=pinfo->fd->num;
459           break;
460       }
461       lcrp=g_hash_table_lookup(ldap_info->matched, &lcr);
462
463       if(lcrp){
464
465         lcrp->is_request=lcr.is_request;
466
467       } else {
468
469                   /* we haven't found a match - try and match it up */
470
471   switch(protocolOpTag){
472       case LDAP_REQ_BIND:
473       case LDAP_REQ_SEARCH:
474       case LDAP_REQ_MODIFY:
475       case LDAP_REQ_ADD:
476       case LDAP_REQ_DELETE:
477       case LDAP_REQ_MODRDN:
478       case LDAP_REQ_COMPARE:
479
480                 /* this a a request - add it to the unmatched list */
481
482         /* check that we dont already have one of those in the
483            unmatched list and if so remove it */
484
485         lcr.messageId=messageId;
486         lcrp=g_hash_table_lookup(ldap_info->unmatched, &lcr);
487         if(lcrp){
488           g_hash_table_remove(ldap_info->unmatched, lcrp);
489         }
490         /* if we cant reuse the old one, grab a new chunk */
491         if(!lcrp){
492           lcrp=se_alloc(sizeof(ldap_call_response_t));
493         }
494         lcrp->messageId=messageId;
495         lcrp->req_frame=pinfo->fd->num;
496         lcrp->req_time=pinfo->fd->abs_ts;
497         lcrp->rep_frame=0;
498         lcrp->protocolOpTag=protocolOpTag;
499         lcrp->is_request=TRUE;
500         g_hash_table_insert(ldap_info->unmatched, lcrp, lcrp);
501         return NULL;
502         break;
503       case LDAP_RES_BIND:
504       case LDAP_RES_SEARCH_ENTRY:
505       case LDAP_RES_SEARCH_REF:
506       case LDAP_RES_SEARCH_RESULT:
507       case LDAP_RES_MODIFY:
508       case LDAP_RES_ADD:
509       case LDAP_RES_DELETE:
510       case LDAP_RES_MODRDN:
511       case LDAP_RES_COMPARE:
512
513                 /* this is a result - it should be in our unmatched list */
514
515         lcr.messageId=messageId;
516         lcrp=g_hash_table_lookup(ldap_info->unmatched, &lcr);
517
518         if(lcrp){
519
520           if(!lcrp->rep_frame){
521             g_hash_table_remove(ldap_info->unmatched, lcrp);
522             lcrp->rep_frame=pinfo->fd->num;
523             lcrp->is_request=FALSE;
524             g_hash_table_insert(ldap_info->matched, lcrp, lcrp);
525           }
526         }
527
528         break;
529           }
530
531         }
532     /* we have found a match */
533
534     if(lcrp){
535       if(lcrp->is_request){
536         proto_tree_add_uint(tree, hf_ldap_response_in, tvb, 0, 0, lcrp->rep_frame);
537       } else {
538         nstime_t ns;
539         proto_tree_add_uint(tree, hf_ldap_response_to, tvb, 0, 0, lcrp->req_frame);
540         nstime_delta(&ns, &pinfo->fd->abs_ts, &lcrp->req_time);
541         proto_tree_add_time(tree, hf_ldap_time, tvb, 0, 0, &ns);
542       }
543     }
544
545     return lcrp;
546 }
547
548
549 /*--- Included file: packet-ldap-fn.c ---*/
550 #line 1 "packet-ldap-fn.c"
551 /*--- Cyclic dependencies ---*/
552
553 /* Filter -> Filter/and -> Filter */
554 /* Filter -> Filter */
555 static int dissect_ldap_Filter(gboolean implicit_tag, tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, int hf_index);
556
557 static int dissect_filter(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
558   return dissect_ldap_Filter(FALSE, tvb, offset, pinfo, tree, hf_ldap_filter);
559 }
560 static int dissect_and_item(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
561   return dissect_ldap_Filter(FALSE, tvb, offset, pinfo, tree, hf_ldap_and_item);
562 }
563 static int dissect_or_item(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
564   return dissect_ldap_Filter(FALSE, tvb, offset, pinfo, tree, hf_ldap_or_item);
565 }
566 static int dissect_not_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
567   return dissect_ldap_Filter(TRUE, tvb, offset, pinfo, tree, hf_ldap_not);
568 }
569
570
571 /*--- Fields for imported types ---*/
572
573
574
575
576 static int
577 dissect_ldap_MessageID(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
578 #line 52 "ldap.cnf"
579
580     offset = dissect_ber_integer(implicit_tag, pinfo, tree, tvb, offset, hf_index,
581                                   &MessageID);
582
583   
584   ldm_tree = tree;
585
586
587
588   return offset;
589 }
590 static int dissect_messageID(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
591   return dissect_ldap_MessageID(FALSE, tvb, offset, pinfo, tree, hf_ldap_messageID);
592 }
593
594
595
596 static int
597 dissect_ldap_INTEGER_1_127(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
598   offset = dissect_ber_integer(implicit_tag, pinfo, tree, tvb, offset, hf_index,
599                                   NULL);
600
601   return offset;
602 }
603 static int dissect_version(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
604   return dissect_ldap_INTEGER_1_127(FALSE, tvb, offset, pinfo, tree, hf_ldap_version);
605 }
606
607
608
609 static int
610 dissect_ldap_LDAPString(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
611 #line 239 "ldap.cnf"
612   tvbuff_t      *parameter_tvb = NULL;
613   char          *ldapstring;
614   gchar         *sc = NULL; /* semi-colon pointer */
615  
616     offset = dissect_ber_octet_string(implicit_tag, pinfo, tree, tvb, offset, hf_index,
617                                        &parameter_tvb);
618
619
620   if (parameter_tvb || (hf_index == hf_ldap_baseObject)) {
621   
622      ldap_do_protocolop(pinfo);
623
624      if(parameter_tvb)
625         ldapstring = tvb_get_string(parameter_tvb, 0, tvb_length_remaining(parameter_tvb, 0));
626      else
627         ldapstring = "<ROOT>";
628
629      if(hf_index == hf_ldap_baseObject) {
630         /* this is search - but it on the scanline */
631         if(check_col(pinfo->cinfo, COL_INFO)) 
632           col_append_fstr(pinfo->cinfo, COL_INFO, "\"%s\" ", ldapstring);
633   
634         if(ldm_tree)
635           proto_item_append_text(ldm_tree, " \"%s\"", ldapstring); 
636      } else if ((hf_index == hf_ldap_errorMessage) && result) { /* only show message if not success */
637         if(check_col(pinfo->cinfo, COL_INFO)) 
638           col_append_fstr(pinfo->cinfo, COL_INFO, "(%s) ", ldapstring);     
639
640         if(ldm_tree)
641           proto_item_append_text(ldm_tree, " (%s)", ldapstring); 
642      } else if (hf_index == hf_ldap_objectName) {
643         if(check_col(pinfo->cinfo, COL_INFO)) 
644           col_append_fstr(pinfo->cinfo, COL_INFO, "\"%s\" ", ldapstring);     
645
646         if(ldm_tree)
647           proto_item_append_text(ldm_tree, " \"%s\"", ldapstring); 
648      } else if (hf_index == hf_ldap_type) {
649         /* remember attribute type name */
650         attr_type = ep_strdup(ldapstring);
651
652         /* append it to the parent entry */
653         proto_item_append_text(tree, " %s", attr_type);
654
655         /* remove the ";binary" component if present */
656         if((sc = strchr(attr_type, ';')) != NULL) {
657                 if(!strcmp(sc, ";binary")) {
658                         *sc = '\0'; /* terminate the string */
659                         is_binary_attr_type = TRUE;
660                 }
661         } else {
662                 is_binary_attr_type = FALSE;
663         }
664
665      }
666      
667      if(parameter_tvb && ldapstring)
668         g_free(ldapstring);
669   }
670
671
672
673   return offset;
674 }
675 static int dissect_initial_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
676   return dissect_ldap_LDAPString(TRUE, tvb, offset, pinfo, tree, hf_ldap_initial);
677 }
678 static int dissect_any_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
679   return dissect_ldap_LDAPString(TRUE, tvb, offset, pinfo, tree, hf_ldap_any);
680 }
681 static int dissect_final_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
682   return dissect_ldap_LDAPString(TRUE, tvb, offset, pinfo, tree, hf_ldap_final);
683 }
684
685
686
687 static int
688 dissect_ldap_LDAPDN(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
689   offset = dissect_ldap_LDAPString(implicit_tag, tvb, offset, pinfo, tree, hf_index);
690
691   return offset;
692 }
693 static int dissect_matchedDN(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
694   return dissect_ldap_LDAPDN(FALSE, tvb, offset, pinfo, tree, hf_ldap_matchedDN);
695 }
696 static int dissect_name(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
697   return dissect_ldap_LDAPDN(FALSE, tvb, offset, pinfo, tree, hf_ldap_name);
698 }
699 static int dissect_baseObject(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
700   return dissect_ldap_LDAPDN(FALSE, tvb, offset, pinfo, tree, hf_ldap_baseObject);
701 }
702 static int dissect_objectName(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
703   return dissect_ldap_LDAPDN(FALSE, tvb, offset, pinfo, tree, hf_ldap_objectName);
704 }
705 static int dissect_object(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
706   return dissect_ldap_LDAPDN(FALSE, tvb, offset, pinfo, tree, hf_ldap_object);
707 }
708 static int dissect_entry(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
709   return dissect_ldap_LDAPDN(FALSE, tvb, offset, pinfo, tree, hf_ldap_entry);
710 }
711 static int dissect_newSuperior_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
712   return dissect_ldap_LDAPDN(TRUE, tvb, offset, pinfo, tree, hf_ldap_newSuperior);
713 }
714
715
716
717 static int
718 dissect_ldap_Simple(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
719 #line 102 "ldap.cnf"
720 ldap_conv_info_t *ldap_info;
721
722   offset = dissect_ber_octet_string(implicit_tag, pinfo, tree, tvb, offset, hf_index,
723                                        NULL);
724
725         
726         ldap_info = pinfo->private_data;
727         ldap_info->auth_type = LDAP_AUTH_SIMPLE;
728
729         pinfo->private_data = ldap_info;
730
731
732
733   return offset;
734 }
735 static int dissect_simple_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
736   return dissect_ldap_Simple(TRUE, tvb, offset, pinfo, tree, hf_ldap_simple);
737 }
738
739
740
741 static int
742 dissect_ldap_Mechanism(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
743 #line 113 "ldap.cnf"
744
745 ldap_conv_info_t *ldap_info;
746 tvbuff_t        *parameter_tvb;
747 char *mechanism = NULL;
748   offset = dissect_ber_octet_string(implicit_tag, pinfo, tree, tvb, offset, hf_index,
749                                        &parameter_tvb);
750
751         ldap_info = pinfo->private_data;
752         ldap_info->auth_type = LDAP_AUTH_SASL;
753
754         if (!parameter_tvb)
755                 return offset;
756
757     /*
758      * We need to remember the authentication type and mechanism for this
759      * conversation.
760      *
761      * XXX - actually, we might need to remember more than one
762      * type and mechanism, if you can unbind and rebind with a
763      * different type and/or mechanism.
764      */
765     mechanism = tvb_get_string(parameter_tvb, 0, tvb_length_remaining(parameter_tvb,0));
766     ldap_info->first_auth_frame = 0;    /* not known until we see the bind reply */
767     /*
768      * If the mechanism in this request is an empty string (which is
769      * returned as a null pointer), use the saved mechanism instead.
770      * Otherwise, if the saved mechanism is an empty string (null),
771      * save this mechanism.
772      */
773     if (mechanism == NULL)
774         mechanism = ldap_info->auth_mech;
775     else {
776       if (ldap_info->auth_mech == NULL) {
777         g_free(ldap_info->auth_mech);
778       }
779       ldap_info->auth_mech = mechanism;
780     }
781         pinfo->private_data = ldap_info;
782
783
784
785   return offset;
786 }
787 static int dissect_mechanism(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
788   return dissect_ldap_Mechanism(FALSE, tvb, offset, pinfo, tree, hf_ldap_mechanism);
789 }
790
791
792
793 static int
794 dissect_ldap_Credentials(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
795 #line 152 "ldap.cnf"
796
797 tvbuff_t        *parameter_tvb;
798 ldap_conv_info_t *ldap_info;
799
800   offset = dissect_ber_octet_string(implicit_tag, pinfo, tree, tvb, offset, hf_index,
801                                        &parameter_tvb);
802
803         if (!parameter_tvb)
804                 return offset;
805
806         ldap_info = pinfo->private_data;
807         if (ldap_info->auth_mech != NULL && strcmp(ldap_info->auth_mech, "GSS-SPNEGO") == 0) {
808                 /*
809          * This is a GSS-API token ancapsulated within GSS-SPNEGO.
810                  */
811                  if (parameter_tvb)
812                         call_dissector(gssapi_handle, parameter_tvb, pinfo, tree);
813         } else if (ldap_info->auth_mech != NULL && strcmp(ldap_info->auth_mech, "GSSAPI") == 0) {
814         /*
815          * This is a raw GSS-API token.
816          */
817                  if (parameter_tvb)
818                         call_dissector(gssapi_handle, parameter_tvb, pinfo, tree);
819         }
820         pinfo->private_data = ldap_info;
821
822
823
824   return offset;
825 }
826 static int dissect_credentials(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
827   return dissect_ldap_Credentials(FALSE, tvb, offset, pinfo, tree, hf_ldap_credentials);
828 }
829
830
831 static const ber_sequence_t SaslCredentials_sequence[] = {
832   { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_mechanism },
833   { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_OPTIONAL|BER_FLAGS_NOOWNTAG, dissect_credentials },
834   { 0, 0, 0, NULL }
835 };
836
837 static int
838 dissect_ldap_SaslCredentials(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
839   offset = dissect_ber_sequence(implicit_tag, pinfo, tree, tvb, offset,
840                                    SaslCredentials_sequence, hf_index, ett_ldap_SaslCredentials);
841
842   return offset;
843 }
844 static int dissect_sasl_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
845   return dissect_ldap_SaslCredentials(TRUE, tvb, offset, pinfo, tree, hf_ldap_sasl);
846 }
847
848
849 static const value_string ldap_AuthenticationChoice_vals[] = {
850   {   0, "simple" },
851   {   3, "sasl" },
852   { 0, NULL }
853 };
854
855 static const ber_choice_t AuthenticationChoice_choice[] = {
856   {   0, BER_CLASS_CON, 0, 0, dissect_simple_impl },
857   {   3, BER_CLASS_CON, 3, 0, dissect_sasl_impl },
858   { 0, 0, 0, 0, NULL }
859 };
860
861 static int
862 dissect_ldap_AuthenticationChoice(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
863 #line 398 "ldap.cnf"
864   gint branch = -1;
865   gint auth = -1;
866   const gchar *valstr;
867   
868     offset = dissect_ber_choice(pinfo, tree, tvb, offset,
869                                  AuthenticationChoice_choice, hf_index, ett_ldap_AuthenticationChoice,
870                                  &branch);
871
872   
873   ldap_do_protocolop(pinfo);
874   
875   if((branch > -1) && (branch < (gint)(sizeof AuthenticationChoice_choice/sizeof AuthenticationChoice_choice[0])))
876     auth = AuthenticationChoice_choice[branch].value;
877
878   valstr = val_to_str(auth, ldap_AuthenticationChoice_vals, "Unknown auth(%u)");
879   
880   if (check_col(pinfo->cinfo, COL_INFO))
881     col_append_fstr(pinfo->cinfo, COL_INFO, "%s ", valstr);
882   
883   if(ldm_tree)
884     proto_item_append_text(ldm_tree, " %s", valstr);
885
886
887
888
889   return offset;
890 }
891 static int dissect_authentication(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
892   return dissect_ldap_AuthenticationChoice(FALSE, tvb, offset, pinfo, tree, hf_ldap_authentication);
893 }
894
895
896 static const ber_sequence_t BindRequest_sequence[] = {
897   { BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_version },
898   { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_name },
899   { BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_authentication },
900   { 0, 0, 0, NULL }
901 };
902
903 static int
904 dissect_ldap_BindRequest(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
905   offset = dissect_ber_sequence(implicit_tag, pinfo, tree, tvb, offset,
906                                    BindRequest_sequence, hf_index, ett_ldap_BindRequest);
907
908   return offset;
909 }
910 static int dissect_bindRequest(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
911   return dissect_ldap_BindRequest(FALSE, tvb, offset, pinfo, tree, hf_ldap_bindRequest);
912 }
913
914
915 static const value_string ldap_BindResponse_resultCode_vals[] = {
916   {   0, "success" },
917   {   1, "operationsError" },
918   {   2, "protocolError" },
919   {   3, "timeLimitExceeded" },
920   {   4, "sizeLimitExceeded" },
921   {   5, "compareFalse" },
922   {   6, "compareTrue" },
923   {   7, "authMethodNotSupported" },
924   {   8, "strongAuthRequired" },
925   {  10, "referral" },
926   {  11, "adminLimitExceeded" },
927   {  12, "unavailableCriticalExtension" },
928   {  13, "confidentialityRequired" },
929   {  14, "saslBindInProgress" },
930   {  16, "noSuchAttribute" },
931   {  17, "undefinedAttributeType" },
932   {  18, "inappropriateMatching" },
933   {  19, "constraintViolation" },
934   {  20, "attributeOrValueExists" },
935   {  21, "invalidAttributeSyntax" },
936   {  32, "noSuchObject" },
937   {  33, "aliasProblem" },
938   {  34, "invalidDNSyntax" },
939   {  36, "aliasDereferencingProblem" },
940   {  48, "inappropriateAuthentication" },
941   {  49, "invalidCredentials" },
942   {  50, "insufficientAccessRights" },
943   {  51, "busy" },
944   {  52, "unavailable" },
945   {  53, "unwillingToPerform" },
946   {  54, "loopDetect" },
947   {  64, "namingViolation" },
948   {  65, "objectClassViolation" },
949   {  66, "notAllowedOnNonLeaf" },
950   {  67, "notAllowedOnRDN" },
951   {  68, "entryAlreadyExists" },
952   {  69, "objectClassModsProhibited" },
953   {  71, "affectsMultipleDSAs" },
954   {  80, "other" },
955   { 0, NULL }
956 };
957
958
959 static int
960 dissect_ldap_BindResponse_resultCode(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
961 #line 340 "ldap.cnf"
962
963   const gchar *valstr;
964
965     offset = dissect_ber_integer(implicit_tag, pinfo, tree, tvb, offset, hf_index,
966                                   &result);
967
968
969   ldap_do_protocolop(pinfo);
970
971   if(result) {
972   
973     valstr = val_to_str(result, ldap_BindResponse_resultCode_vals, "Unknown result(%u)");
974
975     if (check_col(pinfo->cinfo, COL_INFO))
976       col_append_fstr(pinfo->cinfo, COL_INFO, "%s ", valstr);
977
978     if(ldm_tree)
979       proto_item_append_text(ldm_tree, " %s", valstr); 
980
981   }
982
983   
984
985
986   return offset;
987 }
988 static int dissect_bindResponse_resultCode(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
989   return dissect_ldap_BindResponse_resultCode(FALSE, tvb, offset, pinfo, tree, hf_ldap_bindResponse_resultCode);
990 }
991
992
993
994 static int
995 dissect_ldap_ErrorMessage(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
996   offset = dissect_ldap_LDAPString(implicit_tag, tvb, offset, pinfo, tree, hf_index);
997
998   return offset;
999 }
1000 static int dissect_errorMessage(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1001   return dissect_ldap_ErrorMessage(FALSE, tvb, offset, pinfo, tree, hf_ldap_errorMessage);
1002 }
1003
1004
1005
1006 static int
1007 dissect_ldap_LDAPURL(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1008   offset = dissect_ldap_LDAPString(implicit_tag, tvb, offset, pinfo, tree, hf_index);
1009
1010   return offset;
1011 }
1012 static int dissect_Referral_item(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1013   return dissect_ldap_LDAPURL(FALSE, tvb, offset, pinfo, tree, hf_ldap_Referral_item);
1014 }
1015 static int dissect_SearchResultReference_item(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1016   return dissect_ldap_LDAPURL(FALSE, tvb, offset, pinfo, tree, hf_ldap_SearchResultReference_item);
1017 }
1018
1019
1020 static const ber_sequence_t Referral_sequence_of[1] = {
1021   { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_Referral_item },
1022 };
1023
1024 static int
1025 dissect_ldap_Referral(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1026   offset = dissect_ber_sequence_of(implicit_tag, pinfo, tree, tvb, offset,
1027                                       Referral_sequence_of, hf_index, ett_ldap_Referral);
1028
1029   return offset;
1030 }
1031 static int dissect_referral_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1032   return dissect_ldap_Referral(TRUE, tvb, offset, pinfo, tree, hf_ldap_referral);
1033 }
1034
1035
1036
1037 static int
1038 dissect_ldap_ServerSaslCreds(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1039 #line 178 "ldap.cnf"
1040
1041 tvbuff_t        *parameter_tvb;
1042 ldap_conv_info_t *ldap_info;
1043
1044   offset = dissect_ber_octet_string(implicit_tag, pinfo, tree, tvb, offset, hf_index,
1045                                        &parameter_tvb);
1046
1047         if (!parameter_tvb)
1048                 return offset;
1049         ldap_info = pinfo->private_data;
1050     switch (ldap_info->auth_type) {
1051
1052       /* For Kerberos V4, dissect it as a ticket. */
1053       /* XXX - what about LDAP_AUTH_SIMPLE? */
1054
1055     case LDAP_AUTH_SASL:
1056       /*
1057        * All frames after this are assumed to use a security layer.
1058        *
1059        * XXX - won't work if there's another reply, with the security
1060        * layer, starting in the same TCP segment that ends this
1061        * reply, but as LDAP is a request/response protocol, and
1062        * as the client probably can't start using authentication until
1063        * it gets the bind reply and the server won't send a reply until
1064        * it gets a request, that probably won't happen.
1065        *
1066        * XXX - that assumption is invalid; it's not clear where the
1067        * hell you find out whether there's any security layer.  In
1068        * one capture, we have two GSS-SPNEGO negotiations, both of
1069        * which select MS KRB5, and the only differences in the tokens
1070        * is in the RC4-HMAC ciphertext.  The various
1071        * draft-ietf--cat-sasl-gssapi-NN.txt drafts seem to imply
1072        * that the RFC 2222 spoo with the bitmask and maximum
1073        * output message size stuff is done - but where does that
1074        * stuff show up?  Is it in the ciphertext, which means it's
1075        * presumably encrypted?
1076        *
1077        * Grrr.  We have to do a gross heuristic, checking whether the
1078        * putative LDAP message begins with 0x00 or not, making the
1079        * assumption that we won't have more than 2^24 bytes of
1080        * encapsulated stuff.
1081        */
1082       ldap_info->first_auth_frame = pinfo->fd->num + 1;
1083       if (ldap_info->auth_mech != NULL &&
1084           strcmp(ldap_info->auth_mech, "GSS-SPNEGO") == 0) {
1085         /*
1086          * This is a GSS-API token.
1087          */
1088         call_dissector(gssapi_handle, parameter_tvb, pinfo, tree);
1089       } else if (ldap_info->auth_mech != NULL &&
1090           strcmp(ldap_info->auth_mech, "GSSAPI") == 0) {
1091         /*
1092          * This is a GSS-API token.
1093          */
1094         call_dissector(gssapi_handle, parameter_tvb, pinfo, tree);
1095                 }
1096         break;
1097         }
1098         pinfo->private_data = ldap_info;
1099
1100
1101
1102   return offset;
1103 }
1104 static int dissect_serverSaslCreds_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1105   return dissect_ldap_ServerSaslCreds(TRUE, tvb, offset, pinfo, tree, hf_ldap_serverSaslCreds);
1106 }
1107
1108
1109 static const ber_sequence_t BindResponse_sequence[] = {
1110   { BER_CLASS_UNI, BER_UNI_TAG_ENUMERATED, BER_FLAGS_NOOWNTAG, dissect_bindResponse_resultCode },
1111   { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_matchedDN },
1112   { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_errorMessage },
1113   { BER_CLASS_CON, 3, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_referral_impl },
1114   { BER_CLASS_CON, 7, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_serverSaslCreds_impl },
1115   { 0, 0, 0, NULL }
1116 };
1117
1118 static int
1119 dissect_ldap_BindResponse(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1120   offset = dissect_ber_sequence(implicit_tag, pinfo, tree, tvb, offset,
1121                                    BindResponse_sequence, hf_index, ett_ldap_BindResponse);
1122
1123   return offset;
1124 }
1125 static int dissect_bindResponse(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1126   return dissect_ldap_BindResponse(FALSE, tvb, offset, pinfo, tree, hf_ldap_bindResponse);
1127 }
1128
1129
1130
1131 static int
1132 dissect_ldap_UnbindRequest(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1133 #line 419 "ldap.cnf"
1134
1135  implicit_tag = TRUE; /* correct problem with asn2eth */
1136
1137    offset = dissect_ber_null(implicit_tag, pinfo, tree, tvb, offset, hf_index);
1138
1139
1140  ldap_do_protocolop(pinfo);  
1141
1142
1143
1144   return offset;
1145 }
1146 static int dissect_unbindRequest(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1147   return dissect_ldap_UnbindRequest(FALSE, tvb, offset, pinfo, tree, hf_ldap_unbindRequest);
1148 }
1149
1150
1151 static const value_string ldap_T_scope_vals[] = {
1152   {   0, "baseObject" },
1153   {   1, "singleLevel" },
1154   {   2, "wholeSubtree" },
1155   { 0, NULL }
1156 };
1157
1158
1159 static int
1160 dissect_ldap_T_scope(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1161 #line 299 "ldap.cnf"
1162
1163   gint  scope;
1164   const gchar *valstr;
1165
1166     offset = dissect_ber_integer(implicit_tag, pinfo, tree, tvb, offset, hf_index,
1167                                   &scope);
1168
1169
1170   ldap_do_protocolop(pinfo);
1171
1172   valstr = val_to_str(scope, ldap_T_scope_vals, "Unknown scope(%u)");
1173
1174   if (check_col(pinfo->cinfo, COL_INFO))
1175     col_append_fstr(pinfo->cinfo, COL_INFO, "%s ", valstr);    
1176     
1177   if(ldm_tree)
1178     proto_item_append_text(ldm_tree, " %s", valstr); 
1179
1180
1181
1182   return offset;
1183 }
1184 static int dissect_scope(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1185   return dissect_ldap_T_scope(FALSE, tvb, offset, pinfo, tree, hf_ldap_scope);
1186 }
1187
1188
1189 static const value_string ldap_T_derefAliases_vals[] = {
1190   {   0, "neverDerefAliases" },
1191   {   1, "derefInSearching" },
1192   {   2, "derefFindingBaseObj" },
1193   {   3, "derefAlways" },
1194   { 0, NULL }
1195 };
1196
1197
1198 static int
1199 dissect_ldap_T_derefAliases(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1200   offset = dissect_ber_integer(implicit_tag, pinfo, tree, tvb, offset, hf_index,
1201                                   NULL);
1202
1203   return offset;
1204 }
1205 static int dissect_derefAliases(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1206   return dissect_ldap_T_derefAliases(FALSE, tvb, offset, pinfo, tree, hf_ldap_derefAliases);
1207 }
1208
1209
1210
1211 static int
1212 dissect_ldap_INTEGER_0_maxInt(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1213   offset = dissect_ber_integer(implicit_tag, pinfo, tree, tvb, offset, hf_index,
1214                                   NULL);
1215
1216   return offset;
1217 }
1218 static int dissect_sizeLimit(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1219   return dissect_ldap_INTEGER_0_maxInt(FALSE, tvb, offset, pinfo, tree, hf_ldap_sizeLimit);
1220 }
1221 static int dissect_timeLimit(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1222   return dissect_ldap_INTEGER_0_maxInt(FALSE, tvb, offset, pinfo, tree, hf_ldap_timeLimit);
1223 }
1224
1225
1226
1227 static int
1228 dissect_ldap_BOOLEAN(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1229   offset = dissect_ber_boolean(implicit_tag, pinfo, tree, tvb, offset, hf_index);
1230
1231   return offset;
1232 }
1233 static int dissect_criticality(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1234   return dissect_ldap_BOOLEAN(FALSE, tvb, offset, pinfo, tree, hf_ldap_criticality);
1235 }
1236 static int dissect_typesOnly(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1237   return dissect_ldap_BOOLEAN(FALSE, tvb, offset, pinfo, tree, hf_ldap_typesOnly);
1238 }
1239 static int dissect_dnAttributes_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1240   return dissect_ldap_BOOLEAN(TRUE, tvb, offset, pinfo, tree, hf_ldap_dnAttributes);
1241 }
1242 static int dissect_deleteoldrdn(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1243   return dissect_ldap_BOOLEAN(FALSE, tvb, offset, pinfo, tree, hf_ldap_deleteoldrdn);
1244 }
1245
1246
1247 static const ber_sequence_t SET_OF_Filter_set_of[1] = {
1248   { BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_and_item },
1249 };
1250
1251 static int
1252 dissect_ldap_SET_OF_Filter(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1253   offset = dissect_ber_set_of(implicit_tag, pinfo, tree, tvb, offset,
1254                                  SET_OF_Filter_set_of, hf_index, ett_ldap_SET_OF_Filter);
1255
1256   return offset;
1257 }
1258 static int dissect_and_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1259   return dissect_ldap_SET_OF_Filter(TRUE, tvb, offset, pinfo, tree, hf_ldap_and);
1260 }
1261 static int dissect_or_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1262   return dissect_ldap_SET_OF_Filter(TRUE, tvb, offset, pinfo, tree, hf_ldap_or);
1263 }
1264
1265
1266
1267 static int
1268 dissect_ldap_AttributeDescription(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1269   offset = dissect_ldap_LDAPString(implicit_tag, tvb, offset, pinfo, tree, hf_index);
1270
1271   return offset;
1272 }
1273 static int dissect_AttributeDescriptionList_item(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1274   return dissect_ldap_AttributeDescription(FALSE, tvb, offset, pinfo, tree, hf_ldap_AttributeDescriptionList_item);
1275 }
1276 static int dissect_attributeDesc(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1277   return dissect_ldap_AttributeDescription(FALSE, tvb, offset, pinfo, tree, hf_ldap_attributeDesc);
1278 }
1279 static int dissect_type(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1280   return dissect_ldap_AttributeDescription(FALSE, tvb, offset, pinfo, tree, hf_ldap_type);
1281 }
1282 static int dissect_type_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1283   return dissect_ldap_AttributeDescription(TRUE, tvb, offset, pinfo, tree, hf_ldap_type);
1284 }
1285 static int dissect_present_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1286   return dissect_ldap_AttributeDescription(TRUE, tvb, offset, pinfo, tree, hf_ldap_present);
1287 }
1288
1289
1290
1291 static int
1292 dissect_ldap_AssertionValue(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1293   offset = dissect_ber_octet_string(implicit_tag, pinfo, tree, tvb, offset, hf_index,
1294                                        NULL);
1295
1296   return offset;
1297 }
1298 static int dissect_assertionValue(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1299   return dissect_ldap_AssertionValue(FALSE, tvb, offset, pinfo, tree, hf_ldap_assertionValue);
1300 }
1301 static int dissect_matchValue_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1302   return dissect_ldap_AssertionValue(TRUE, tvb, offset, pinfo, tree, hf_ldap_matchValue);
1303 }
1304
1305
1306 static const ber_sequence_t AttributeValueAssertion_sequence[] = {
1307   { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_attributeDesc },
1308   { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_assertionValue },
1309   { 0, 0, 0, NULL }
1310 };
1311
1312 static int
1313 dissect_ldap_AttributeValueAssertion(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1314   offset = dissect_ber_sequence(implicit_tag, pinfo, tree, tvb, offset,
1315                                    AttributeValueAssertion_sequence, hf_index, ett_ldap_AttributeValueAssertion);
1316
1317   return offset;
1318 }
1319 static int dissect_equalityMatch_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1320   return dissect_ldap_AttributeValueAssertion(TRUE, tvb, offset, pinfo, tree, hf_ldap_equalityMatch);
1321 }
1322 static int dissect_greaterOrEqual_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1323   return dissect_ldap_AttributeValueAssertion(TRUE, tvb, offset, pinfo, tree, hf_ldap_greaterOrEqual);
1324 }
1325 static int dissect_lessOrEqual_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1326   return dissect_ldap_AttributeValueAssertion(TRUE, tvb, offset, pinfo, tree, hf_ldap_lessOrEqual);
1327 }
1328 static int dissect_approxMatch_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1329   return dissect_ldap_AttributeValueAssertion(TRUE, tvb, offset, pinfo, tree, hf_ldap_approxMatch);
1330 }
1331 static int dissect_ava(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1332   return dissect_ldap_AttributeValueAssertion(FALSE, tvb, offset, pinfo, tree, hf_ldap_ava);
1333 }
1334
1335
1336 static const value_string ldap_T_substrings_item_vals[] = {
1337   {   0, "initial" },
1338   {   1, "any" },
1339   {   2, "final" },
1340   { 0, NULL }
1341 };
1342
1343 static const ber_choice_t T_substrings_item_choice[] = {
1344   {   0, BER_CLASS_CON, 0, 0, dissect_initial_impl },
1345   {   1, BER_CLASS_CON, 1, 0, dissect_any_impl },
1346   {   2, BER_CLASS_CON, 2, 0, dissect_final_impl },
1347   { 0, 0, 0, 0, NULL }
1348 };
1349
1350 static int
1351 dissect_ldap_T_substrings_item(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1352   offset = dissect_ber_choice(pinfo, tree, tvb, offset,
1353                                  T_substrings_item_choice, hf_index, ett_ldap_T_substrings_item,
1354                                  NULL);
1355
1356   return offset;
1357 }
1358 static int dissect_substrings_item(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1359   return dissect_ldap_T_substrings_item(FALSE, tvb, offset, pinfo, tree, hf_ldap_substrings_item);
1360 }
1361
1362
1363 static const ber_sequence_t T_substrings_sequence_of[1] = {
1364   { BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_substrings_item },
1365 };
1366
1367 static int
1368 dissect_ldap_T_substrings(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1369   offset = dissect_ber_sequence_of(implicit_tag, pinfo, tree, tvb, offset,
1370                                       T_substrings_sequence_of, hf_index, ett_ldap_T_substrings);
1371
1372   return offset;
1373 }
1374 static int dissect_substringFilter_substrings(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1375   return dissect_ldap_T_substrings(FALSE, tvb, offset, pinfo, tree, hf_ldap_substringFilter_substrings);
1376 }
1377
1378
1379 static const ber_sequence_t SubstringFilter_sequence[] = {
1380   { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_type },
1381   { BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_substringFilter_substrings },
1382   { 0, 0, 0, NULL }
1383 };
1384
1385 static int
1386 dissect_ldap_SubstringFilter(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1387   offset = dissect_ber_sequence(implicit_tag, pinfo, tree, tvb, offset,
1388                                    SubstringFilter_sequence, hf_index, ett_ldap_SubstringFilter);
1389
1390   return offset;
1391 }
1392 static int dissect_substrings_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1393   return dissect_ldap_SubstringFilter(TRUE, tvb, offset, pinfo, tree, hf_ldap_substrings);
1394 }
1395
1396
1397
1398 static int
1399 dissect_ldap_MatchingRuleId(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1400   offset = dissect_ldap_LDAPString(implicit_tag, tvb, offset, pinfo, tree, hf_index);
1401
1402   return offset;
1403 }
1404 static int dissect_matchingRule_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1405   return dissect_ldap_MatchingRuleId(TRUE, tvb, offset, pinfo, tree, hf_ldap_matchingRule);
1406 }
1407
1408
1409 static const ber_sequence_t MatchingRuleAssertion_sequence[] = {
1410   { BER_CLASS_CON, 1, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_matchingRule_impl },
1411   { BER_CLASS_CON, 2, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_type_impl },
1412   { BER_CLASS_CON, 3, BER_FLAGS_IMPLTAG, dissect_matchValue_impl },
1413   { BER_CLASS_CON, 4, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_dnAttributes_impl },
1414   { 0, 0, 0, NULL }
1415 };
1416
1417 static int
1418 dissect_ldap_MatchingRuleAssertion(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1419   offset = dissect_ber_sequence(implicit_tag, pinfo, tree, tvb, offset,
1420                                    MatchingRuleAssertion_sequence, hf_index, ett_ldap_MatchingRuleAssertion);
1421
1422   return offset;
1423 }
1424 static int dissect_extensibleMatch_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1425   return dissect_ldap_MatchingRuleAssertion(TRUE, tvb, offset, pinfo, tree, hf_ldap_extensibleMatch);
1426 }
1427
1428
1429 static const value_string ldap_Filter_vals[] = {
1430   {   0, "and" },
1431   {   1, "or" },
1432   {   2, "not" },
1433   {   3, "equalityMatch" },
1434   {   4, "substrings" },
1435   {   5, "greaterOrEqual" },
1436   {   6, "lessOrEqual" },
1437   {   7, "present" },
1438   {   8, "approxMatch" },
1439   {   9, "extensibleMatch" },
1440   { 0, NULL }
1441 };
1442
1443 static const ber_choice_t Filter_choice[] = {
1444   {   0, BER_CLASS_CON, 0, 0, dissect_and_impl },
1445   {   1, BER_CLASS_CON, 1, 0, dissect_or_impl },
1446   {   2, BER_CLASS_CON, 2, 0, dissect_not_impl },
1447   {   3, BER_CLASS_CON, 3, 0, dissect_equalityMatch_impl },
1448   {   4, BER_CLASS_CON, 4, 0, dissect_substrings_impl },
1449   {   5, BER_CLASS_CON, 5, 0, dissect_greaterOrEqual_impl },
1450   {   6, BER_CLASS_CON, 6, 0, dissect_lessOrEqual_impl },
1451   {   7, BER_CLASS_CON, 7, 0, dissect_present_impl },
1452   {   8, BER_CLASS_CON, 8, 0, dissect_approxMatch_impl },
1453   {   9, BER_CLASS_CON, 9, 0, dissect_extensibleMatch_impl },
1454   { 0, 0, 0, 0, NULL }
1455 };
1456
1457 static int
1458 dissect_ldap_Filter(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1459   offset = dissect_ber_choice(pinfo, tree, tvb, offset,
1460                                  Filter_choice, hf_index, ett_ldap_Filter,
1461                                  NULL);
1462
1463   return offset;
1464 }
1465
1466
1467 static const ber_sequence_t AttributeDescriptionList_sequence_of[1] = {
1468   { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_AttributeDescriptionList_item },
1469 };
1470
1471 static int
1472 dissect_ldap_AttributeDescriptionList(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1473   offset = dissect_ber_sequence_of(implicit_tag, pinfo, tree, tvb, offset,
1474                                       AttributeDescriptionList_sequence_of, hf_index, ett_ldap_AttributeDescriptionList);
1475
1476   return offset;
1477 }
1478 static int dissect_searchRequest_attributes(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1479   return dissect_ldap_AttributeDescriptionList(FALSE, tvb, offset, pinfo, tree, hf_ldap_searchRequest_attributes);
1480 }
1481
1482
1483 static const ber_sequence_t SearchRequest_sequence[] = {
1484   { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_baseObject },
1485   { BER_CLASS_UNI, BER_UNI_TAG_ENUMERATED, BER_FLAGS_NOOWNTAG, dissect_scope },
1486   { BER_CLASS_UNI, BER_UNI_TAG_ENUMERATED, BER_FLAGS_NOOWNTAG, dissect_derefAliases },
1487   { BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_sizeLimit },
1488   { BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_timeLimit },
1489   { BER_CLASS_UNI, BER_UNI_TAG_BOOLEAN, BER_FLAGS_NOOWNTAG, dissect_typesOnly },
1490   { BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_filter },
1491   { BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_searchRequest_attributes },
1492   { 0, 0, 0, NULL }
1493 };
1494
1495 static int
1496 dissect_ldap_SearchRequest(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1497   offset = dissect_ber_sequence(implicit_tag, pinfo, tree, tvb, offset,
1498                                    SearchRequest_sequence, hf_index, ett_ldap_SearchRequest);
1499
1500   return offset;
1501 }
1502 static int dissect_searchRequest(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1503   return dissect_ldap_SearchRequest(FALSE, tvb, offset, pinfo, tree, hf_ldap_searchRequest);
1504 }
1505
1506
1507
1508 static int
1509 dissect_ldap_AttributeValue(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1510 #line 361 "ldap.cnf"
1511
1512   tvbuff_t      *next_tvb;
1513   gchar         *string;
1514   guint32       i, len;
1515   proto_item    *pi;
1516   int           old_offset = offset;
1517
1518   /* extract the value of the octetstring */
1519   offset = dissect_ber_octet_string(FALSE, pinfo, NULL, tvb, offset, hf_index, &next_tvb);
1520
1521   /* if we have an attribute type that isn't binary see if there is a better dissector */
1522   if(!attr_type || !dissector_try_string(ldap_name_dissector_table, attr_type, next_tvb, pinfo, tree)) {
1523         offset = old_offset;
1524         
1525         /* do the default thing */
1526           offset = dissect_ber_octet_string(implicit_tag, pinfo, tree, tvb, offset, hf_index,
1527                                        NULL);
1528         
1529
1530   } 
1531
1532   len = tvb_length_remaining(next_tvb, 0);
1533   
1534   for(i = 0; i < len; i++) 
1535     if(!g_ascii_isprint(tvb_get_guint8(next_tvb, i)))
1536       break;
1537   
1538   if(i == len) {
1539     string = tvb_get_string(next_tvb, 0, tvb_length_remaining(next_tvb, 0));
1540  
1541     pi = get_ber_last_created_item();
1542      
1543     proto_item_set_text(pi, string);
1544
1545   }
1546   
1547
1548
1549   return offset;
1550 }
1551 static int dissect_vals_item(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1552   return dissect_ldap_AttributeValue(FALSE, tvb, offset, pinfo, tree, hf_ldap_vals_item);
1553 }
1554
1555
1556 static const ber_sequence_t SET_OF_AttributeValue_set_of[1] = {
1557   { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_vals_item },
1558 };
1559
1560 static int
1561 dissect_ldap_SET_OF_AttributeValue(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1562   offset = dissect_ber_set_of(implicit_tag, pinfo, tree, tvb, offset,
1563                                  SET_OF_AttributeValue_set_of, hf_index, ett_ldap_SET_OF_AttributeValue);
1564
1565   return offset;
1566 }
1567 static int dissect_vals(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1568   return dissect_ldap_SET_OF_AttributeValue(FALSE, tvb, offset, pinfo, tree, hf_ldap_vals);
1569 }
1570
1571
1572 static const ber_sequence_t PartialAttributeList_item_sequence[] = {
1573   { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_type },
1574   { BER_CLASS_UNI, BER_UNI_TAG_SET, BER_FLAGS_NOOWNTAG, dissect_vals },
1575   { 0, 0, 0, NULL }
1576 };
1577
1578 static int
1579 dissect_ldap_PartialAttributeList_item(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1580   offset = dissect_ber_sequence(implicit_tag, pinfo, tree, tvb, offset,
1581                                    PartialAttributeList_item_sequence, hf_index, ett_ldap_PartialAttributeList_item);
1582
1583   return offset;
1584 }
1585 static int dissect_PartialAttributeList_item(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1586   return dissect_ldap_PartialAttributeList_item(FALSE, tvb, offset, pinfo, tree, hf_ldap_PartialAttributeList_item);
1587 }
1588
1589
1590 static const ber_sequence_t PartialAttributeList_sequence_of[1] = {
1591   { BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_PartialAttributeList_item },
1592 };
1593
1594 static int
1595 dissect_ldap_PartialAttributeList(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1596   offset = dissect_ber_sequence_of(implicit_tag, pinfo, tree, tvb, offset,
1597                                       PartialAttributeList_sequence_of, hf_index, ett_ldap_PartialAttributeList);
1598
1599   return offset;
1600 }
1601 static int dissect_searchResultEntry_attributes(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1602   return dissect_ldap_PartialAttributeList(FALSE, tvb, offset, pinfo, tree, hf_ldap_searchResultEntry_attributes);
1603 }
1604
1605
1606 static const ber_sequence_t SearchResultEntry_sequence[] = {
1607   { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_objectName },
1608   { BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_searchResultEntry_attributes },
1609   { 0, 0, 0, NULL }
1610 };
1611
1612 static int
1613 dissect_ldap_SearchResultEntry(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1614   offset = dissect_ber_sequence(implicit_tag, pinfo, tree, tvb, offset,
1615                                    SearchResultEntry_sequence, hf_index, ett_ldap_SearchResultEntry);
1616
1617   return offset;
1618 }
1619 static int dissect_searchResEntry(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1620   return dissect_ldap_SearchResultEntry(FALSE, tvb, offset, pinfo, tree, hf_ldap_searchResEntry);
1621 }
1622
1623
1624 static const value_string ldap_T_resultCode_vals[] = {
1625   {   0, "success" },
1626   {   1, "operationsError" },
1627   {   2, "protocolError" },
1628   {   3, "timeLimitExceeded" },
1629   {   4, "sizeLimitExceeded" },
1630   {   5, "compareFalse" },
1631   {   6, "compareTrue" },
1632   {   7, "authMethodNotSupported" },
1633   {   8, "strongAuthRequired" },
1634   {  10, "referral" },
1635   {  11, "adminLimitExceeded" },
1636   {  12, "unavailableCriticalExtension" },
1637   {  13, "confidentialityRequired" },
1638   {  14, "saslBindInProgress" },
1639   {  16, "noSuchAttribute" },
1640   {  17, "undefinedAttributeType" },
1641   {  18, "inappropriateMatching" },
1642   {  19, "constraintViolation" },
1643   {  20, "attributeOrValueExists" },
1644   {  21, "invalidAttributeSyntax" },
1645   {  32, "noSuchObject" },
1646   {  33, "aliasProblem" },
1647   {  34, "invalidDNSyntax" },
1648   {  36, "aliasDereferencingProblem" },
1649   {  48, "inappropriateAuthentication" },
1650   {  49, "invalidCredentials" },
1651   {  50, "insufficientAccessRights" },
1652   {  51, "busy" },
1653   {  52, "unavailable" },
1654   {  53, "unwillingToPerform" },
1655   {  54, "loopDetect" },
1656   {  64, "namingViolation" },
1657   {  65, "objectClassViolation" },
1658   {  66, "notAllowedOnNonLeaf" },
1659   {  67, "notAllowedOnRDN" },
1660   {  68, "entryAlreadyExists" },
1661   {  69, "objectClassModsProhibited" },
1662   {  71, "affectsMultipleDSAs" },
1663   {  80, "other" },
1664   { 0, NULL }
1665 };
1666
1667
1668 static int
1669 dissect_ldap_T_resultCode(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1670 #line 318 "ldap.cnf"
1671
1672   const gchar *valstr;
1673
1674     offset = dissect_ber_integer(implicit_tag, pinfo, tree, tvb, offset, hf_index,
1675                                   &result);
1676
1677
1678   ldap_do_protocolop(pinfo);
1679
1680   if(result) {
1681   
1682     valstr = val_to_str(result, ldap_T_resultCode_vals, "Unknown result(%u)");
1683
1684     if (check_col(pinfo->cinfo, COL_INFO))
1685       col_append_fstr(pinfo->cinfo, COL_INFO, "%s ", valstr);
1686
1687     if(ldm_tree)
1688       proto_item_append_text(ldm_tree, " %s", valstr); 
1689
1690   }
1691
1692
1693
1694   return offset;
1695 }
1696 static int dissect_resultCode(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1697   return dissect_ldap_T_resultCode(FALSE, tvb, offset, pinfo, tree, hf_ldap_resultCode);
1698 }
1699
1700
1701 static const ber_sequence_t LDAPResult_sequence[] = {
1702   { BER_CLASS_UNI, BER_UNI_TAG_ENUMERATED, BER_FLAGS_NOOWNTAG, dissect_resultCode },
1703   { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_matchedDN },
1704   { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_errorMessage },
1705   { BER_CLASS_CON, 3, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_referral_impl },
1706   { 0, 0, 0, NULL }
1707 };
1708
1709 static int
1710 dissect_ldap_LDAPResult(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1711   offset = dissect_ber_sequence(implicit_tag, pinfo, tree, tvb, offset,
1712                                    LDAPResult_sequence, hf_index, ett_ldap_LDAPResult);
1713
1714   return offset;
1715 }
1716
1717
1718
1719 static int
1720 dissect_ldap_SearchResultDone(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1721   offset = dissect_ldap_LDAPResult(implicit_tag, tvb, offset, pinfo, tree, hf_index);
1722
1723   return offset;
1724 }
1725 static int dissect_searchResDone(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1726   return dissect_ldap_SearchResultDone(FALSE, tvb, offset, pinfo, tree, hf_ldap_searchResDone);
1727 }
1728
1729
1730 static const ber_sequence_t SearchResultReference_sequence_of[1] = {
1731   { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_SearchResultReference_item },
1732 };
1733
1734 static int
1735 dissect_ldap_SearchResultReference(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1736   offset = dissect_ber_sequence_of(implicit_tag, pinfo, tree, tvb, offset,
1737                                       SearchResultReference_sequence_of, hf_index, ett_ldap_SearchResultReference);
1738
1739   return offset;
1740 }
1741 static int dissect_searchResRef(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1742   return dissect_ldap_SearchResultReference(FALSE, tvb, offset, pinfo, tree, hf_ldap_searchResRef);
1743 }
1744
1745
1746 static const value_string ldap_T_operation_vals[] = {
1747   {   0, "add" },
1748   {   1, "delete" },
1749   {   2, "replace" },
1750   { 0, NULL }
1751 };
1752
1753
1754 static int
1755 dissect_ldap_T_operation(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1756   offset = dissect_ber_integer(implicit_tag, pinfo, tree, tvb, offset, hf_index,
1757                                   NULL);
1758
1759   return offset;
1760 }
1761 static int dissect_operation(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1762   return dissect_ldap_T_operation(FALSE, tvb, offset, pinfo, tree, hf_ldap_operation);
1763 }
1764
1765
1766 static const ber_sequence_t AttributeTypeAndValues_sequence[] = {
1767   { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_type },
1768   { BER_CLASS_UNI, BER_UNI_TAG_SET, BER_FLAGS_NOOWNTAG, dissect_vals },
1769   { 0, 0, 0, NULL }
1770 };
1771
1772 static int
1773 dissect_ldap_AttributeTypeAndValues(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1774   offset = dissect_ber_sequence(implicit_tag, pinfo, tree, tvb, offset,
1775                                    AttributeTypeAndValues_sequence, hf_index, ett_ldap_AttributeTypeAndValues);
1776
1777   return offset;
1778 }
1779 static int dissect_modification(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1780   return dissect_ldap_AttributeTypeAndValues(FALSE, tvb, offset, pinfo, tree, hf_ldap_modification);
1781 }
1782
1783
1784 static const ber_sequence_t T_modification_item_sequence[] = {
1785   { BER_CLASS_UNI, BER_UNI_TAG_ENUMERATED, BER_FLAGS_NOOWNTAG, dissect_operation },
1786   { BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_modification },
1787   { 0, 0, 0, NULL }
1788 };
1789
1790 static int
1791 dissect_ldap_T_modification_item(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1792   offset = dissect_ber_sequence(implicit_tag, pinfo, tree, tvb, offset,
1793                                    T_modification_item_sequence, hf_index, ett_ldap_T_modification_item);
1794
1795   return offset;
1796 }
1797 static int dissect_modification_item(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1798   return dissect_ldap_T_modification_item(FALSE, tvb, offset, pinfo, tree, hf_ldap_modification_item);
1799 }
1800
1801
1802 static const ber_sequence_t ModifyRequest_modification_sequence_of[1] = {
1803   { BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_modification_item },
1804 };
1805
1806 static int
1807 dissect_ldap_ModifyRequest_modification(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1808   offset = dissect_ber_sequence_of(implicit_tag, pinfo, tree, tvb, offset,
1809                                       ModifyRequest_modification_sequence_of, hf_index, ett_ldap_ModifyRequest_modification);
1810
1811   return offset;
1812 }
1813 static int dissect_modifyRequest_modification(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1814   return dissect_ldap_ModifyRequest_modification(FALSE, tvb, offset, pinfo, tree, hf_ldap_modifyRequest_modification);
1815 }
1816
1817
1818 static const ber_sequence_t ModifyRequest_sequence[] = {
1819   { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_object },
1820   { BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_modifyRequest_modification },
1821   { 0, 0, 0, NULL }
1822 };
1823
1824 static int
1825 dissect_ldap_ModifyRequest(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1826   offset = dissect_ber_sequence(implicit_tag, pinfo, tree, tvb, offset,
1827                                    ModifyRequest_sequence, hf_index, ett_ldap_ModifyRequest);
1828
1829   return offset;
1830 }
1831 static int dissect_modifyRequest(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1832   return dissect_ldap_ModifyRequest(FALSE, tvb, offset, pinfo, tree, hf_ldap_modifyRequest);
1833 }
1834
1835
1836
1837 static int
1838 dissect_ldap_ModifyResponse(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1839   offset = dissect_ldap_LDAPResult(implicit_tag, tvb, offset, pinfo, tree, hf_index);
1840
1841   return offset;
1842 }
1843 static int dissect_modifyResponse(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1844   return dissect_ldap_ModifyResponse(FALSE, tvb, offset, pinfo, tree, hf_ldap_modifyResponse);
1845 }
1846
1847
1848 static const ber_sequence_t AttributeList_item_sequence[] = {
1849   { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_type },
1850   { BER_CLASS_UNI, BER_UNI_TAG_SET, BER_FLAGS_NOOWNTAG, dissect_vals },
1851   { 0, 0, 0, NULL }
1852 };
1853
1854 static int
1855 dissect_ldap_AttributeList_item(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1856   offset = dissect_ber_sequence(implicit_tag, pinfo, tree, tvb, offset,
1857                                    AttributeList_item_sequence, hf_index, ett_ldap_AttributeList_item);
1858
1859   return offset;
1860 }
1861 static int dissect_AttributeList_item(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1862   return dissect_ldap_AttributeList_item(FALSE, tvb, offset, pinfo, tree, hf_ldap_AttributeList_item);
1863 }
1864
1865
1866 static const ber_sequence_t AttributeList_sequence_of[1] = {
1867   { BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_AttributeList_item },
1868 };
1869
1870 static int
1871 dissect_ldap_AttributeList(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1872   offset = dissect_ber_sequence_of(implicit_tag, pinfo, tree, tvb, offset,
1873                                       AttributeList_sequence_of, hf_index, ett_ldap_AttributeList);
1874
1875   return offset;
1876 }
1877 static int dissect_attributes(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1878   return dissect_ldap_AttributeList(FALSE, tvb, offset, pinfo, tree, hf_ldap_attributes);
1879 }
1880
1881
1882 static const ber_sequence_t AddRequest_sequence[] = {
1883   { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_entry },
1884   { BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_attributes },
1885   { 0, 0, 0, NULL }
1886 };
1887
1888 static int
1889 dissect_ldap_AddRequest(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1890   offset = dissect_ber_sequence(implicit_tag, pinfo, tree, tvb, offset,
1891                                    AddRequest_sequence, hf_index, ett_ldap_AddRequest);
1892
1893   return offset;
1894 }
1895 static int dissect_addRequest(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1896   return dissect_ldap_AddRequest(FALSE, tvb, offset, pinfo, tree, hf_ldap_addRequest);
1897 }
1898
1899
1900
1901 static int
1902 dissect_ldap_AddResponse(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1903   offset = dissect_ldap_LDAPResult(implicit_tag, tvb, offset, pinfo, tree, hf_index);
1904
1905   return offset;
1906 }
1907 static int dissect_addResponse(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1908   return dissect_ldap_AddResponse(FALSE, tvb, offset, pinfo, tree, hf_ldap_addResponse);
1909 }
1910
1911
1912
1913 static int
1914 dissect_ldap_DelRequest(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1915   offset = dissect_ldap_LDAPDN(implicit_tag, tvb, offset, pinfo, tree, hf_index);
1916
1917   return offset;
1918 }
1919 static int dissect_delRequest(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1920   return dissect_ldap_DelRequest(FALSE, tvb, offset, pinfo, tree, hf_ldap_delRequest);
1921 }
1922
1923
1924
1925 static int
1926 dissect_ldap_DelResponse(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1927   offset = dissect_ldap_LDAPResult(implicit_tag, tvb, offset, pinfo, tree, hf_index);
1928
1929   return offset;
1930 }
1931 static int dissect_delResponse(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1932   return dissect_ldap_DelResponse(FALSE, tvb, offset, pinfo, tree, hf_ldap_delResponse);
1933 }
1934
1935
1936
1937 static int
1938 dissect_ldap_RelativeLDAPDN(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1939   offset = dissect_ldap_LDAPString(implicit_tag, tvb, offset, pinfo, tree, hf_index);
1940
1941   return offset;
1942 }
1943 static int dissect_newrdn(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1944   return dissect_ldap_RelativeLDAPDN(FALSE, tvb, offset, pinfo, tree, hf_ldap_newrdn);
1945 }
1946
1947
1948 static const ber_sequence_t ModifyDNRequest_sequence[] = {
1949   { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_entry },
1950   { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_newrdn },
1951   { BER_CLASS_UNI, BER_UNI_TAG_BOOLEAN, BER_FLAGS_NOOWNTAG, dissect_deleteoldrdn },
1952   { BER_CLASS_CON, 0, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_newSuperior_impl },
1953   { 0, 0, 0, NULL }
1954 };
1955
1956 static int
1957 dissect_ldap_ModifyDNRequest(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1958   offset = dissect_ber_sequence(implicit_tag, pinfo, tree, tvb, offset,
1959                                    ModifyDNRequest_sequence, hf_index, ett_ldap_ModifyDNRequest);
1960
1961   return offset;
1962 }
1963 static int dissect_modDNRequest(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1964   return dissect_ldap_ModifyDNRequest(FALSE, tvb, offset, pinfo, tree, hf_ldap_modDNRequest);
1965 }
1966
1967
1968
1969 static int
1970 dissect_ldap_ModifyDNResponse(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1971   offset = dissect_ldap_LDAPResult(implicit_tag, tvb, offset, pinfo, tree, hf_index);
1972
1973   return offset;
1974 }
1975 static int dissect_modDNResponse(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1976   return dissect_ldap_ModifyDNResponse(FALSE, tvb, offset, pinfo, tree, hf_ldap_modDNResponse);
1977 }
1978
1979
1980 static const ber_sequence_t CompareRequest_sequence[] = {
1981   { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_entry },
1982   { BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_ava },
1983   { 0, 0, 0, NULL }
1984 };
1985
1986 static int
1987 dissect_ldap_CompareRequest(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1988   offset = dissect_ber_sequence(implicit_tag, pinfo, tree, tvb, offset,
1989                                    CompareRequest_sequence, hf_index, ett_ldap_CompareRequest);
1990
1991   return offset;
1992 }
1993 static int dissect_compareRequest(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1994   return dissect_ldap_CompareRequest(FALSE, tvb, offset, pinfo, tree, hf_ldap_compareRequest);
1995 }
1996
1997
1998
1999 static int
2000 dissect_ldap_CompareResponse(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2001   offset = dissect_ldap_LDAPResult(implicit_tag, tvb, offset, pinfo, tree, hf_index);
2002
2003   return offset;
2004 }
2005 static int dissect_compareResponse(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
2006   return dissect_ldap_CompareResponse(FALSE, tvb, offset, pinfo, tree, hf_ldap_compareResponse);
2007 }
2008
2009
2010
2011 static int
2012 dissect_ldap_AbandonRequest(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2013   offset = dissect_ldap_MessageID(implicit_tag, tvb, offset, pinfo, tree, hf_index);
2014
2015   return offset;
2016 }
2017 static int dissect_abandonRequest(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
2018   return dissect_ldap_AbandonRequest(FALSE, tvb, offset, pinfo, tree, hf_ldap_abandonRequest);
2019 }
2020
2021
2022
2023 static int
2024 dissect_ldap_LDAPOID(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2025 #line 32 "ldap.cnf"
2026
2027         tvbuff_t        *parameter_tvb;
2028         const gchar *name;
2029         proto_item      *item = NULL;
2030
2031
2032
2033   offset = dissect_ber_octet_string(implicit_tag, pinfo, tree, tvb, offset, hf_index,
2034                                        &parameter_tvb);
2035
2036 #line 39 "ldap.cnf"
2037         if (!parameter_tvb)
2038                 return offset;
2039         item = get_ber_last_created_item();
2040         name = get_oid_str_name(tvb_get_string(parameter_tvb, 0, tvb_length_remaining(parameter_tvb,0)));
2041         if(name){
2042                 proto_item_append_text(item, " (%s)", name);
2043                 proto_item_append_text(tree, " %s", name);      
2044         }
2045
2046
2047
2048   return offset;
2049 }
2050 static int dissect_requestName_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
2051   return dissect_ldap_LDAPOID(TRUE, tvb, offset, pinfo, tree, hf_ldap_requestName);
2052 }
2053
2054
2055
2056 static int
2057 dissect_ldap_OCTET_STRING(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2058   offset = dissect_ber_octet_string(implicit_tag, pinfo, tree, tvb, offset, hf_index,
2059                                        NULL);
2060
2061   return offset;
2062 }
2063 static int dissect_controlValue(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
2064   return dissect_ldap_OCTET_STRING(FALSE, tvb, offset, pinfo, tree, hf_ldap_controlValue);
2065 }
2066 static int dissect_requestValue_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
2067   return dissect_ldap_OCTET_STRING(TRUE, tvb, offset, pinfo, tree, hf_ldap_requestValue);
2068 }
2069 static int dissect_response_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
2070   return dissect_ldap_OCTET_STRING(TRUE, tvb, offset, pinfo, tree, hf_ldap_response);
2071 }
2072
2073
2074 static const ber_sequence_t ExtendedRequest_sequence[] = {
2075   { BER_CLASS_CON, 0, BER_FLAGS_IMPLTAG, dissect_requestName_impl },
2076   { BER_CLASS_CON, 1, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_requestValue_impl },
2077   { 0, 0, 0, NULL }
2078 };
2079
2080 static int
2081 dissect_ldap_ExtendedRequest(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2082   offset = dissect_ber_sequence(implicit_tag, pinfo, tree, tvb, offset,
2083                                    ExtendedRequest_sequence, hf_index, ett_ldap_ExtendedRequest);
2084
2085   return offset;
2086 }
2087 static int dissect_extendedReq(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
2088   return dissect_ldap_ExtendedRequest(FALSE, tvb, offset, pinfo, tree, hf_ldap_extendedReq);
2089 }
2090
2091
2092 static const value_string ldap_ExtendedResponse_resultCode_vals[] = {
2093   {   0, "success" },
2094   {   1, "operationsError" },
2095   {   2, "protocolError" },
2096   {   3, "timeLimitExceeded" },
2097   {   4, "sizeLimitExceeded" },
2098   {   5, "compareFalse" },
2099   {   6, "compareTrue" },
2100   {   7, "authMethodNotSupported" },
2101   {   8, "strongAuthRequired" },
2102   {  10, "referral" },
2103   {  11, "adminLimitExceeded" },
2104   {  12, "unavailableCriticalExtension" },
2105   {  13, "confidentialityRequired" },
2106   {  14, "saslBindInProgress" },
2107   {  16, "noSuchAttribute" },
2108   {  17, "undefinedAttributeType" },
2109   {  18, "inappropriateMatching" },
2110   {  19, "constraintViolation" },
2111   {  20, "attributeOrValueExists" },
2112   {  21, "invalidAttributeSyntax" },
2113   {  32, "noSuchObject" },
2114   {  33, "aliasProblem" },
2115   {  34, "invalidDNSyntax" },
2116   {  36, "aliasDereferencingProblem" },
2117   {  48, "inappropriateAuthentication" },
2118   {  49, "invalidCredentials" },
2119   {  50, "insufficientAccessRights" },
2120   {  51, "busy" },
2121   {  52, "unavailable" },
2122   {  53, "unwillingToPerform" },
2123   {  54, "loopDetect" },
2124   {  64, "namingViolation" },
2125   {  65, "objectClassViolation" },
2126   {  66, "notAllowedOnNonLeaf" },
2127   {  67, "notAllowedOnRDN" },
2128   {  68, "entryAlreadyExists" },
2129   {  69, "objectClassModsProhibited" },
2130   {  71, "affectsMultipleDSAs" },
2131   {  80, "other" },
2132   { 0, NULL }
2133 };
2134
2135
2136 static int
2137 dissect_ldap_ExtendedResponse_resultCode(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2138   offset = dissect_ber_integer(implicit_tag, pinfo, tree, tvb, offset, hf_index,
2139                                   NULL);
2140
2141   return offset;
2142 }
2143 static int dissect_extendedResponse_resultCode(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
2144   return dissect_ldap_ExtendedResponse_resultCode(FALSE, tvb, offset, pinfo, tree, hf_ldap_extendedResponse_resultCode);
2145 }
2146
2147
2148
2149 static int
2150 dissect_ldap_ResponseName(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2151   offset = dissect_ldap_LDAPOID(implicit_tag, tvb, offset, pinfo, tree, hf_index);
2152
2153   return offset;
2154 }
2155 static int dissect_responseName_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
2156   return dissect_ldap_ResponseName(TRUE, tvb, offset, pinfo, tree, hf_ldap_responseName);
2157 }
2158
2159
2160 static const ber_sequence_t ExtendedResponse_sequence[] = {
2161   { BER_CLASS_UNI, BER_UNI_TAG_ENUMERATED, BER_FLAGS_NOOWNTAG, dissect_extendedResponse_resultCode },
2162   { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_matchedDN },
2163   { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_errorMessage },
2164   { BER_CLASS_CON, 3, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_referral_impl },
2165   { BER_CLASS_CON, 10, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_responseName_impl },
2166   { BER_CLASS_CON, 11, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_response_impl },
2167   { 0, 0, 0, NULL }
2168 };
2169
2170 static int
2171 dissect_ldap_ExtendedResponse(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2172   offset = dissect_ber_sequence(implicit_tag, pinfo, tree, tvb, offset,
2173                                    ExtendedResponse_sequence, hf_index, ett_ldap_ExtendedResponse);
2174
2175   return offset;
2176 }
2177 static int dissect_extendedResp(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
2178   return dissect_ldap_ExtendedResponse(FALSE, tvb, offset, pinfo, tree, hf_ldap_extendedResp);
2179 }
2180
2181
2182 static const value_string ldap_ProtocolOp_vals[] = {
2183   {   0, "bindRequest" },
2184   {   1, "bindResponse" },
2185   {   2, "unbindRequest" },
2186   {   3, "searchRequest" },
2187   {   4, "searchResEntry" },
2188   {   5, "searchResDone" },
2189   {  19, "searchResRef" },
2190   {   6, "modifyRequest" },
2191   {   7, "modifyResponse" },
2192   {   8, "addRequest" },
2193   {   9, "addResponse" },
2194   {  10, "delRequest" },
2195   {  11, "delResponse" },
2196   {  12, "modDNRequest" },
2197   {  13, "modDNResponse" },
2198   {  14, "compareRequest" },
2199   {  15, "compareResponse" },
2200   {  16, "abandonRequest" },
2201   {  23, "extendedReq" },
2202   {  24, "extendedResp" },
2203   { 0, NULL }
2204 };
2205
2206 static const ber_choice_t ProtocolOp_choice[] = {
2207   {   0, BER_CLASS_APP, 0, BER_FLAGS_NOOWNTAG, dissect_bindRequest },
2208   {   1, BER_CLASS_APP, 1, BER_FLAGS_NOOWNTAG, dissect_bindResponse },
2209   {   2, BER_CLASS_APP, 2, BER_FLAGS_NOOWNTAG, dissect_unbindRequest },
2210   {   3, BER_CLASS_APP, 3, BER_FLAGS_NOOWNTAG, dissect_searchRequest },
2211   {   4, BER_CLASS_APP, 4, BER_FLAGS_NOOWNTAG, dissect_searchResEntry },
2212   {   5, BER_CLASS_APP, 5, BER_FLAGS_NOOWNTAG, dissect_searchResDone },
2213   {  19, BER_CLASS_APP, 19, BER_FLAGS_NOOWNTAG, dissect_searchResRef },
2214   {   6, BER_CLASS_APP, 6, BER_FLAGS_NOOWNTAG, dissect_modifyRequest },
2215   {   7, BER_CLASS_APP, 7, BER_FLAGS_NOOWNTAG, dissect_modifyResponse },
2216   {   8, BER_CLASS_APP, 8, BER_FLAGS_NOOWNTAG, dissect_addRequest },
2217   {   9, BER_CLASS_APP, 9, BER_FLAGS_NOOWNTAG, dissect_addResponse },
2218   {  10, BER_CLASS_APP, 10, BER_FLAGS_NOOWNTAG, dissect_delRequest },
2219   {  11, BER_CLASS_APP, 11, BER_FLAGS_NOOWNTAG, dissect_delResponse },
2220   {  12, BER_CLASS_APP, 12, BER_FLAGS_NOOWNTAG, dissect_modDNRequest },
2221   {  13, BER_CLASS_APP, 13, BER_FLAGS_NOOWNTAG, dissect_modDNResponse },
2222   {  14, BER_CLASS_APP, 14, BER_FLAGS_NOOWNTAG, dissect_compareRequest },
2223   {  15, BER_CLASS_APP, 15, BER_FLAGS_NOOWNTAG, dissect_compareResponse },
2224   {  16, BER_CLASS_APP, 16, BER_FLAGS_NOOWNTAG, dissect_abandonRequest },
2225   {  23, BER_CLASS_APP, 23, BER_FLAGS_NOOWNTAG, dissect_extendedReq },
2226   {  24, BER_CLASS_APP, 24, BER_FLAGS_NOOWNTAG, dissect_extendedResp },
2227   { 0, 0, 0, 0, NULL }
2228 };
2229
2230 static int
2231 dissect_ldap_ProtocolOp(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2232 #line 60 "ldap.cnf"
2233
2234   ldap_call_response_t *lcrp;
2235   ldap_conv_info_t *ldap_info = (ldap_conv_info_t *)pinfo->private_data;
2236   do_protocolop = TRUE;
2237
2238
2239   offset = dissect_ber_choice(pinfo, tree, tvb, offset,
2240                                  ProtocolOp_choice, hf_index, ett_ldap_ProtocolOp,
2241                                  &ProtocolOp);
2242
2243 #line 66 "ldap.cnf"
2244
2245   lcrp=ldap_match_call_response(tvb, pinfo, tree, MessageID, ProtocolOp);
2246   if(lcrp){
2247     tap_queue_packet(ldap_tap, pinfo, lcrp);
2248   }
2249   
2250   /* XXX: the count will not work if the results span multiple TCP packets */
2251
2252   if(ldap_info && tree) { /* only count once - on tree pass */
2253     switch(ProtocolOp) {
2254   
2255     case LDAP_RES_SEARCH_ENTRY:
2256         ldap_info->num_results++;
2257
2258         proto_item_append_text(tree, " [%d result%s]", 
2259                         ldap_info->num_results, ldap_info->num_results == 1 ? "" : "s");
2260
2261         break;
2262
2263     case LDAP_RES_SEARCH_RESULT:
2264   
2265         if (check_col(pinfo->cinfo, COL_INFO))
2266           col_append_fstr(pinfo->cinfo, COL_INFO, " [%d result%s]", 
2267                         ldap_info->num_results, ldap_info->num_results == 1 ? "" : "s");
2268                         
2269         proto_item_append_text(tree, " [%d result%s]", 
2270                         ldap_info->num_results, ldap_info->num_results == 1 ? "" : "s");
2271                         
2272         ldap_info->num_results = 0;
2273         break;
2274      default:
2275         break;
2276     } 
2277   }
2278   
2279
2280   return offset;
2281 }
2282 static int dissect_protocolOp(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
2283   return dissect_ldap_ProtocolOp(FALSE, tvb, offset, pinfo, tree, hf_ldap_protocolOp);
2284 }
2285
2286
2287
2288 static int
2289 dissect_ldap_ControlType(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2290   offset = dissect_ldap_LDAPOID(implicit_tag, tvb, offset, pinfo, tree, hf_index);
2291
2292   return offset;
2293 }
2294 static int dissect_controlType(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
2295   return dissect_ldap_ControlType(FALSE, tvb, offset, pinfo, tree, hf_ldap_controlType);
2296 }
2297
2298
2299 static const ber_sequence_t Control_sequence[] = {
2300   { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_controlType },
2301   { BER_CLASS_UNI, BER_UNI_TAG_BOOLEAN, BER_FLAGS_OPTIONAL|BER_FLAGS_NOOWNTAG, dissect_criticality },
2302   { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_OPTIONAL|BER_FLAGS_NOOWNTAG, dissect_controlValue },
2303   { 0, 0, 0, NULL }
2304 };
2305
2306 static int
2307 dissect_ldap_Control(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2308   offset = dissect_ber_sequence(implicit_tag, pinfo, tree, tvb, offset,
2309                                    Control_sequence, hf_index, ett_ldap_Control);
2310
2311   return offset;
2312 }
2313 static int dissect_Controls_item(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
2314   return dissect_ldap_Control(FALSE, tvb, offset, pinfo, tree, hf_ldap_Controls_item);
2315 }
2316
2317
2318 static const ber_sequence_t Controls_sequence_of[1] = {
2319   { BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_Controls_item },
2320 };
2321
2322 static int
2323 dissect_ldap_Controls(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2324   offset = dissect_ber_sequence_of(implicit_tag, pinfo, tree, tvb, offset,
2325                                       Controls_sequence_of, hf_index, ett_ldap_Controls);
2326
2327   return offset;
2328 }
2329 static int dissect_controls_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
2330   return dissect_ldap_Controls(TRUE, tvb, offset, pinfo, tree, hf_ldap_controls);
2331 }
2332
2333
2334 static const ber_sequence_t LDAPMessage_sequence[] = {
2335   { BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_messageID },
2336   { BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_protocolOp },
2337   { BER_CLASS_CON, 0, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_controls_impl },
2338   { 0, 0, 0, NULL }
2339 };
2340
2341 static int
2342 dissect_ldap_LDAPMessage(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2343   offset = dissect_ber_sequence(implicit_tag, pinfo, tree, tvb, offset,
2344                                    LDAPMessage_sequence, hf_index, ett_ldap_LDAPMessage);
2345
2346   return offset;
2347 }
2348
2349
2350
2351 /*--- PDUs ---*/
2352
2353 static void dissect_LDAPMessage_PDU(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
2354   dissect_ldap_LDAPMessage(FALSE, tvb, 0, pinfo, tree, hf_ldap_LDAPMessage_PDU);
2355 }
2356
2357
2358 /*--- End of included file: packet-ldap-fn.c ---*/
2359 #line 398 "packet-ldap-template.c"
2360
2361 static void
2362 dissect_ldap_payload(tvbuff_t *tvb, packet_info *pinfo,
2363                      proto_tree *tree, ldap_conv_info_t *ldap_info,
2364                      gboolean rest_is_pad, gboolean is_mscldap)
2365 {
2366   int offset = 0;
2367   gboolean first_time = TRUE;
2368   guint length_remaining;
2369   guint msg_len = 0;
2370   int messageOffset = 0;
2371   guint headerLength = 0;
2372   guint length = 0;
2373   tvbuff_t *msg_tvb = NULL;
2374   gint8 class;
2375   gboolean pc, ind = 0;
2376   gint32 ber_tag;
2377
2378   while (tvb_reported_length_remaining(tvb, offset) > 0) {
2379     /*
2380      * This will throw an exception if we don't have any data left.
2381      * That's what we want.  (See "tcp_dissect_pdus()", which is
2382      * similar)
2383      */
2384     length_remaining = tvb_ensure_length_remaining(tvb, offset);
2385
2386     if (rest_is_pad && length_remaining < 6) return;
2387
2388     /*
2389      * The frame begins
2390      * with a "Sequence Of" header.
2391      * Can we do reassembly?
2392      */
2393     if (ldap_desegment && pinfo->can_desegment) {
2394         /*
2395          * Yes - is the "Sequence Of" header split across segment
2396          * boundaries?  We require at least 6 bytes for the header
2397          * which allows for a 4 byte length (ASN.1 BER).
2398          */
2399         if (length_remaining < 6) {
2400           /* stop if the caller says that we are given all data and the rest is padding
2401            * this is for the SASL GSSAPI case when the data is only signed and not sealed
2402            */
2403           pinfo->desegment_offset = offset;
2404           pinfo->desegment_len = 6 - length_remaining;
2405           return;
2406         }
2407     }
2408
2409     /*
2410      * OK, try to read the "Sequence Of" header; this gets the total
2411      * length of the LDAP message.
2412      */
2413         messageOffset = get_ber_identifier(tvb, offset, &class, &pc, &ber_tag);
2414         messageOffset = get_ber_length(tree, tvb, messageOffset, &msg_len, &ind);
2415
2416     if (ber_tag == BER_UNI_TAG_SEQUENCE) {
2417         /*
2418          * Add the length of the "Sequence Of" header to the message
2419          * length.
2420          */
2421         headerLength = messageOffset - offset;
2422         msg_len += headerLength;
2423         if (msg_len < headerLength) {
2424             /*
2425              * The message length was probably so large that the total length
2426              * overflowed.
2427              *
2428              * Report this as an error.
2429              */
2430             show_reported_bounds_error(tvb, pinfo, tree);
2431             return;
2432         }
2433     } else {
2434         /*
2435          * We couldn't parse the header; just make it the amount of data
2436          * remaining in the tvbuff, so we'll give up on this segment
2437          * after attempting to parse the message - there's nothing more
2438          * we can do.  "dissect_ldap_message()" will display the error.
2439          */
2440         msg_len = length_remaining;
2441     }
2442
2443     /*
2444      * Is the message split across segment boundaries?
2445      */
2446     if (length_remaining < msg_len) {
2447         /* provide a hint to TCP where the next PDU starts */
2448         pinfo->want_pdu_tracking=2;
2449         pinfo->bytes_until_next_pdu= msg_len - length_remaining;
2450         /*
2451          * Can we do reassembly?
2452          */
2453         if (ldap_desegment && pinfo->can_desegment) {
2454             /*
2455              * Yes.  Tell the TCP dissector where the data for this message
2456              * starts in the data it handed us, and how many more bytes
2457              * we need, and return.
2458              */
2459             pinfo->desegment_offset = offset;
2460             pinfo->desegment_len = msg_len - length_remaining;
2461
2462             return;
2463         }
2464     }
2465
2466     /*
2467      * Construct a tvbuff containing the amount of the payload we have
2468      * available.  Make its reported length the amount of data in the
2469      * LDAP message.
2470      *
2471      * XXX - if reassembly isn't enabled. the subdissector will throw a
2472      * BoundsError exception, rather than a ReportedBoundsError exception.
2473      * We really want a tvbuff where the length is "length", the reported
2474      * length is "plen", and the "if the snapshot length were infinite"
2475      * length is the minimum of the reported length of the tvbuff handed
2476      * to us and "plen", with a new type of exception thrown if the offset
2477      * is within the reported length but beyond that third length, with
2478      * that exception getting the "Unreassembled Packet" error.
2479      */
2480     length = length_remaining;
2481     if (length > msg_len) length = msg_len;
2482     msg_tvb = tvb_new_subset(tvb, offset, length, msg_len);
2483
2484     /*
2485      * Now dissect the LDAP message.
2486      */
2487
2488     /*dissect_ldap_message(msg_tvb, 0, pinfo, msg_tree, msg_item, first_time, ldap_info, is_mscldap);*/
2489         ldap_info->first_time= first_time;
2490         ldap_info->is_mscldap = is_mscldap;
2491         pinfo->private_data = ldap_info;
2492         dissect_LDAPMessage_PDU(msg_tvb, pinfo, tree);
2493
2494
2495     offset += msg_len;
2496
2497     first_time = FALSE;
2498   }
2499 }
2500
2501 static void
2502 dissect_ldap_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gboolean is_mscldap)
2503 {
2504   int offset = 0;
2505   conversation_t *conversation;
2506   gboolean doing_sasl_security = FALSE;
2507   guint length_remaining;
2508   ldap_conv_info_t *ldap_info = NULL;
2509   proto_item *ldap_item = NULL;
2510   proto_tree *ldap_tree = NULL;
2511
2512   /*
2513    * Do we have a conversation for this connection?
2514    */
2515   conversation = find_conversation(pinfo->fd->num, &pinfo->src, &pinfo->dst,
2516                                    pinfo->ptype, pinfo->srcport,
2517                                    pinfo->destport, 0);
2518   if (conversation == NULL) {
2519     /* We don't yet have a conversation, so create one. */
2520     conversation = conversation_new(pinfo->fd->num, &pinfo->src, &pinfo->dst,
2521                                     pinfo->ptype, pinfo->srcport,
2522                                     pinfo->destport, 0);
2523
2524   }
2525
2526   /*
2527    * Do we already have a type and mechanism?
2528    */
2529   ldap_info = conversation_get_proto_data(conversation, proto_ldap);
2530   if (ldap_info == NULL) {
2531     /* No.  Attach that information to the conversation, and add
2532      * it to the list of information structures.
2533      */
2534     ldap_info = se_alloc(sizeof(ldap_conv_info_t));
2535     ldap_info->auth_type = 0;
2536     ldap_info->auth_mech = 0;
2537     ldap_info->first_auth_frame = 0;
2538     ldap_info->matched=g_hash_table_new(ldap_info_hash_matched, ldap_info_equal_matched);
2539     ldap_info->unmatched=g_hash_table_new(ldap_info_hash_unmatched, ldap_info_equal_unmatched);
2540     ldap_info->num_results = 0;
2541
2542     conversation_add_proto_data(conversation, proto_ldap, ldap_info);
2543
2544     ldap_info->next = ldap_info_items;
2545     ldap_info_items = ldap_info;
2546
2547   }
2548
2549   switch (ldap_info->auth_type) {
2550     case LDAP_AUTH_SASL:
2551     /*
2552      * It's SASL; are we using a security layer?
2553      */
2554     if (ldap_info->first_auth_frame != 0 &&
2555        pinfo->fd->num >= ldap_info->first_auth_frame) {
2556         doing_sasl_security = TRUE;     /* yes */
2557     }
2558   }
2559
2560   while (tvb_reported_length_remaining(tvb, offset) > 0) {
2561
2562     /*
2563      * This will throw an exception if we don't have any data left.
2564      * That's what we want.  (See "tcp_dissect_pdus()", which is
2565      * similar, but doesn't have to deal with the SASL issues.
2566      * XXX - can we make "tcp_dissect_pdus()" provide enough information
2567      * to the "get_pdu_len" routine so that we could have one dealing
2568      * with the SASL issues, have that routine deal with SASL and
2569      * ASN.1, and just use "tcp_dissect_pdus()"?)
2570      */
2571     length_remaining = tvb_ensure_length_remaining(tvb, offset);
2572
2573     /*
2574      * Try to find out if we have a plain LDAP buffer
2575      * with a "Sequence Of" header or a SASL buffer with
2576      * Can we do reassembly?
2577      */
2578     if (ldap_desegment && pinfo->can_desegment) {
2579         /*
2580          * Yes - is the "Sequence Of" header split across segment
2581          * boundaries?  We require at least 6 bytes for the header
2582          * which allows for a 4 byte length (ASN.1 BER).
2583          * For the SASL case we need at least 4 bytes, so this is
2584          * no problem here because we check for 6 bytes ans sasl buffers
2585          * with less than 2 bytes should not exist...
2586          */
2587         if (length_remaining < 6) {
2588             pinfo->desegment_offset = offset;
2589             pinfo->desegment_len = 6 - length_remaining;
2590             return;
2591         }
2592     }
2593
2594     /* It might still be a packet containing a SASL security layer
2595      * but its just that we never saw the BIND packet.
2596      * check if it looks like it could be a SASL blob here
2597      * and in that case just assume it is GSS-SPNEGO
2598      */
2599     if(!doing_sasl_security && (tvb_bytes_exist(tvb, offset, 5))
2600       &&(tvb_get_ntohl(tvb, offset)<=(guint)(tvb_reported_length_remaining(tvb, offset)-4))
2601       &&(tvb_get_guint8(tvb, offset+4)==0x60) ){
2602         ldap_info->auth_type=LDAP_AUTH_SASL;
2603         ldap_info->first_auth_frame=pinfo->fd->num;
2604         ldap_info->auth_mech=g_strdup("GSS-SPNEGO");
2605         doing_sasl_security=TRUE;
2606     }
2607
2608     /*
2609      * This is the first PDU, set the Protocol column and clear the
2610      * Info column.
2611      */
2612     if (check_col(pinfo->cinfo, COL_PROTOCOL)) col_set_str(pinfo->cinfo, COL_PROTOCOL, pinfo->current_proto);
2613     if (check_col(pinfo->cinfo, COL_INFO)) col_clear(pinfo->cinfo, COL_INFO);
2614
2615     ldap_item = proto_tree_add_item(tree, proto_ldap, tvb, 0, -1, FALSE);
2616     ldap_tree = proto_item_add_subtree(ldap_item, ett_ldap);
2617
2618     /*
2619      * Might we be doing a SASL security layer and, if so, *are* we doing
2620      * one?
2621      *
2622      * Just because we've seen a bind reply for SASL, that doesn't mean
2623      * that we're using a SASL security layer; I've seen captures in
2624      * which some SASL negotiations lead to a security layer being used
2625      * and other negotiations don't, and it's not obvious what's different
2626      * in the two negotiations.  Therefore, we assume that if the first
2627      * byte is 0, it's a length for a SASL security layer (that way, we
2628      * never reassemble more than 16 megabytes, protecting us from
2629      * chewing up *too* much memory), and otherwise that it's an LDAP
2630      * message (actually, if it's an LDAP message it should begin with 0x30,
2631      * but we want to parse garbage as LDAP messages rather than really
2632      * huge lengths).
2633      */
2634
2635     if (doing_sasl_security && tvb_get_guint8(tvb, offset) == 0) {
2636       proto_item *sasl_item = NULL;
2637       proto_tree *sasl_tree = NULL;
2638       tvbuff_t *sasl_tvb;
2639       guint sasl_len, sasl_msg_len, length;
2640       /*
2641        * Yes.  The frame begins with a 4-byte big-endian length.
2642        * And we know we have at least 6 bytes
2643        */
2644
2645       /*
2646        * Get the SASL length, which is the length of data in the buffer
2647        * following the length (i.e., it's 4 less than the total length).
2648        *
2649        * XXX - do we need to reassemble buffers?  For now, we
2650        * assume that each LDAP message is entirely contained within
2651        * a buffer.
2652        */
2653       sasl_len = tvb_get_ntohl(tvb, offset);
2654       sasl_msg_len = sasl_len + 4;
2655       if (sasl_msg_len < 4) {
2656         /*
2657          * The message length was probably so large that the total length
2658          * overflowed.
2659          *
2660          * Report this as an error.
2661          */
2662         show_reported_bounds_error(tvb, pinfo, tree);
2663         return;
2664       }
2665
2666       /*
2667        * Is the buffer split across segment boundaries?
2668        */
2669       if (length_remaining < sasl_msg_len) {
2670         /* provide a hint to TCP where the next PDU starts */
2671         pinfo->want_pdu_tracking = 2;
2672         pinfo->bytes_until_next_pdu= sasl_msg_len - length_remaining;
2673         /*
2674          * Can we do reassembly?
2675          */
2676         if (ldap_desegment && pinfo->can_desegment) {
2677           /*
2678            * Yes.  Tell the TCP dissector where the data for this message
2679            * starts in the data it handed us, and how many more bytes we
2680            * need, and return.
2681            */
2682           pinfo->desegment_offset = offset;
2683           pinfo->desegment_len = sasl_msg_len - length_remaining;
2684           return;
2685         }
2686       }
2687
2688       /*
2689        * Construct a tvbuff containing the amount of the payload we have
2690        * available.  Make its reported length the amount of data in the PDU.
2691        *
2692        * XXX - if reassembly isn't enabled. the subdissector will throw a
2693        * BoundsError exception, rather than a ReportedBoundsError exception.
2694        * We really want a tvbuff where the length is "length", the reported
2695        * length is "plen", and the "if the snapshot length were infinite"
2696        * length is the minimum of the reported length of the tvbuff handed
2697        * to us and "plen", with a new type of exception thrown if the offset
2698        * is within the reported length but beyond that third length, with
2699        * that exception getting the "Unreassembled Packet" error.
2700        */
2701       length = length_remaining;
2702       if (length > sasl_msg_len) length = sasl_msg_len;
2703       sasl_tvb = tvb_new_subset(tvb, offset, length, sasl_msg_len);
2704
2705       if (ldap_tree) {
2706         proto_tree_add_uint(ldap_tree, hf_ldap_sasl_buffer_length, sasl_tvb, 0, 4,
2707                             sasl_len);
2708
2709         sasl_item = proto_tree_add_text(ldap_tree, sasl_tvb, 0,  sasl_msg_len, "SASL buffer");
2710         sasl_tree = proto_item_add_subtree(sasl_item, ett_ldap_sasl_blob);
2711       }
2712
2713       if (ldap_info->auth_mech != NULL &&
2714           strcmp(ldap_info->auth_mech, "GSS-SPNEGO") == 0) {
2715           tvbuff_t *gssapi_tvb, *plain_tvb = NULL, *decr_tvb= NULL;
2716           int ver_len;
2717           int length;
2718
2719           /*
2720            * This is GSS-API (using SPNEGO, but we should be done with
2721            * the negotiation by now).
2722            *
2723            * Dissect the GSS_Wrap() token; it'll return the length of
2724            * the token, from which we compute the offset in the tvbuff at
2725            * which the plaintext data, i.e. the LDAP message, begins.
2726            */
2727           length = tvb_length_remaining(sasl_tvb, 4);
2728           if ((guint)length > sasl_len)
2729               length = sasl_len;
2730           gssapi_tvb = tvb_new_subset(sasl_tvb, 4, length, sasl_len);
2731
2732           /* Attempt decryption of the GSSAPI wrapped data if possible */
2733           pinfo->decrypt_gssapi_tvb=DECRYPT_GSSAPI_NORMAL;
2734           pinfo->gssapi_wrap_tvb=NULL;
2735           pinfo->gssapi_encrypted_tvb=NULL;
2736           pinfo->gssapi_decrypted_tvb=NULL;
2737           ver_len = call_dissector(gssapi_wrap_handle, gssapi_tvb, pinfo, sasl_tree);
2738           /* if we could unwrap, do a tvb shuffle */
2739           if(pinfo->gssapi_decrypted_tvb){
2740                 decr_tvb=pinfo->gssapi_decrypted_tvb;
2741           }
2742           /* tidy up */
2743           pinfo->decrypt_gssapi_tvb=0;
2744           pinfo->gssapi_wrap_tvb=NULL;
2745           pinfo->gssapi_encrypted_tvb=NULL;
2746           pinfo->gssapi_decrypted_tvb=NULL;
2747
2748           /*
2749            * if len is 0 it probably mean that we got a PDU that is not
2750            * aligned to the start of the segment.
2751            */
2752           if(ver_len==0){
2753              return;
2754           }
2755
2756           /*
2757            * if we don't have unwrapped data,
2758            * see if the wrapping involved encryption of the
2759            * data; if not, just use the plaintext data.
2760            */
2761           if (!decr_tvb) {
2762             if(!pinfo->gssapi_data_encrypted){
2763               plain_tvb = tvb_new_subset(gssapi_tvb,  ver_len, -1, -1);
2764             }
2765           }
2766
2767           if (decr_tvb) {
2768             proto_item *enc_item = NULL;
2769             proto_tree *enc_tree = NULL;
2770
2771             /*
2772              * The LDAP message was encrypted in the packet, and has
2773              * been decrypted; dissect the decrypted LDAP message.
2774              */
2775             if (sasl_tree) {
2776               enc_item = proto_tree_add_text(sasl_tree, gssapi_tvb, ver_len, -1,
2777                                 "GSS-API Encrypted payload (%d byte%s)",
2778                                 sasl_len - ver_len,
2779                                 plurality(sasl_len - ver_len, "", "s"));
2780               enc_tree = proto_item_add_subtree(enc_item, ett_ldap_payload);
2781             }
2782             dissect_ldap_payload(decr_tvb, pinfo, enc_tree, ldap_info, TRUE, is_mscldap);
2783           } else if (plain_tvb) {
2784             proto_item *plain_item = NULL;
2785             proto_tree *plain_tree = NULL;
2786
2787             /*
2788              * The LDAP message wasn't encrypted in the packet;
2789              * dissect the plain LDAP message.
2790              */
2791             if (sasl_tree) {
2792               plain_item = proto_tree_add_text(sasl_tree, gssapi_tvb, ver_len, -1,
2793                                 "GSS-API payload (%d byte%s)",
2794                                 sasl_len - ver_len,
2795                                 plurality(sasl_len - ver_len, "", "s"));
2796               plain_tree = proto_item_add_subtree(plain_item, ett_ldap_payload);
2797             }
2798
2799            dissect_ldap_payload(plain_tvb, pinfo, plain_tree, ldap_info, TRUE, is_mscldap);
2800           } else {
2801             /*
2802              * The LDAP message was encrypted in the packet, and was
2803              * not decrypted; just show it as encrypted data.
2804              */
2805             if (check_col(pinfo->cinfo, COL_INFO)) {
2806                     col_add_fstr(pinfo->cinfo, COL_INFO, "LDAP GSS-API Encrypted payload (%d byte%s)",
2807                                  sasl_len - ver_len,
2808                                  plurality(sasl_len - ver_len, "", "s"));
2809             }
2810             if (sasl_tree) {
2811               proto_tree_add_text(sasl_tree, gssapi_tvb, ver_len, -1,
2812                                 "GSS-API Encrypted payload (%d byte%s)",
2813                                 sasl_len - ver_len,
2814                                 plurality(sasl_len - ver_len, "", "s"));
2815             }
2816           }
2817       }
2818       offset += sasl_msg_len;
2819     } else {
2820         /* plain LDAP, so dissect the payload */
2821         dissect_ldap_payload(tvb, pinfo, ldap_tree, ldap_info, FALSE, is_mscldap);
2822         /* dissect_ldap_payload() has it's own loop so go out here */
2823         break;
2824     }
2825   }
2826 }
2827
2828 static int dissect_mscldap_string(tvbuff_t *tvb, int offset, char *str, int maxlen, gboolean prepend_dot)
2829 {
2830   guint8 len;
2831
2832   len=tvb_get_guint8(tvb, offset);
2833   offset+=1;
2834   *str=0;
2835
2836   while(len){
2837     /* add potential field separation dot */
2838     if(prepend_dot){
2839       if(!maxlen){
2840         *str=0;
2841         return offset;
2842       }
2843       maxlen--;
2844       *str++='.';
2845       *str=0;
2846     }
2847
2848     if(len==0xc0){
2849       int new_offset;
2850       /* ops its a mscldap compressed string */
2851
2852       new_offset=tvb_get_guint8(tvb, offset);
2853       if (new_offset == offset - 1)
2854         THROW(ReportedBoundsError);
2855       offset+=1;
2856
2857       dissect_mscldap_string(tvb, new_offset, str, maxlen, FALSE);
2858
2859       return offset;
2860     }
2861
2862     prepend_dot=TRUE;
2863
2864     if(maxlen<=len){
2865       if(maxlen>3){
2866         *str++='.';
2867         *str++='.';
2868         *str++='.';
2869       }
2870       *str=0;
2871       return offset; /* will mess up offset in caller, is unlikely */
2872     }
2873     tvb_memcpy(tvb, str, offset, len);
2874     str+=len;
2875     *str=0;
2876     maxlen-=len;
2877     offset+=len;
2878
2879
2880     len=tvb_get_guint8(tvb, offset);
2881     offset+=1;
2882   }
2883   *str=0;
2884   return offset;
2885 }
2886
2887 /* These flag bits were found to be defined in the samba sources.
2888  * I hope they are correct (but have serious doubts about the CLOSEST
2889  * bit being used or being meaningful).
2890  */
2891 static const true_false_string tfs_ads_pdc = {
2892         "This is a PDC",
2893         "This is NOT a pdc"
2894 };
2895 static const true_false_string tfs_ads_gc = {
2896         "This is a GLOBAL CATALOGUE of forest",
2897         "This is NOT a global catalog of forest"
2898 };
2899 static const true_false_string tfs_ads_ldap = {
2900         "This is an LDAP server",
2901         "This is NOT an ldap server"
2902 };
2903 static const true_false_string tfs_ads_ds = {
2904         "This dc supports DS",
2905         "This dc does NOT support ds"
2906 };
2907 static const true_false_string tfs_ads_kdc = {
2908         "This is a KDC (kerberos)",
2909         "This is NOT a kdc (kerberos)"
2910 };
2911 static const true_false_string tfs_ads_timeserv = {
2912         "This dc is running TIME SERVICES (ntp)",
2913         "This dc is NOT running time services (ntp)"
2914 };
2915 static const true_false_string tfs_ads_closest = {
2916         "This is the CLOSEST dc (unreliable?)",
2917         "This is NOT the closest dc"
2918 };
2919 static const true_false_string tfs_ads_writable = {
2920         "This dc is WRITABLE",
2921         "This dc is NOT writable"
2922 };
2923 static const true_false_string tfs_ads_good_timeserv = {
2924         "This dc has a GOOD TIME SERVICE (i.e. hardware clock)",
2925         "This dc does NOT have a good time service (i.e. no hardware clock)"
2926 };
2927 static const true_false_string tfs_ads_ndnc = {
2928         "Domain is NON-DOMAIN NC serviced by ldap server",
2929         "Domain is NOT non-domain nc serviced by ldap server"
2930 };
2931 static int dissect_mscldap_netlogon_flags(proto_tree *parent_tree, tvbuff_t *tvb, int offset)
2932 {
2933   guint32 flags;
2934   proto_item *item;
2935   proto_tree *tree=NULL;
2936   guint fields[] = { hf_mscldap_netlogon_flags_ndnc,
2937                      hf_mscldap_netlogon_flags_good_timeserv,
2938                      hf_mscldap_netlogon_flags_writable,
2939                      hf_mscldap_netlogon_flags_closest,
2940                      hf_mscldap_netlogon_flags_timeserv,
2941                      hf_mscldap_netlogon_flags_kdc,
2942                      hf_mscldap_netlogon_flags_ds,
2943                      hf_mscldap_netlogon_flags_ldap,
2944                      hf_mscldap_netlogon_flags_gc,
2945                      hf_mscldap_netlogon_flags_pdc,
2946                      0 };
2947   guint  *field;
2948   header_field_info *hfi;
2949   gboolean one_bit_set = FALSE;
2950
2951   flags=tvb_get_letohl(tvb, offset);
2952   item=proto_tree_add_item(parent_tree, hf_mscldap_netlogon_flags, tvb, offset, 4, TRUE);
2953   if(parent_tree){
2954     tree = proto_item_add_subtree(item, ett_mscldap_netlogon_flags);
2955   }
2956
2957   proto_item_append_text(item, " (");
2958
2959   for(field = fields; *field; field++) {
2960     proto_tree_add_boolean(tree, *field, tvb, offset, 4, flags);
2961     hfi = proto_registrar_get_nth(*field);
2962     
2963     if(flags & hfi->bitmask) {
2964
2965       if(one_bit_set)
2966         proto_item_append_text(item, ", ");     
2967       else
2968         one_bit_set = TRUE;
2969
2970       proto_item_append_text(item, hfi->name);
2971
2972     }
2973   }
2974
2975   proto_item_append_text(item, ")");
2976
2977   offset += 4;
2978
2979   return offset;
2980 }
2981
2982 static void dissect_NetLogon_PDU(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
2983 {
2984   int old_offset, offset=0;
2985   char str[256];
2986
2987 /*qqq*/
2988
2989   /* Type */
2990   /*XXX someone that knows what the type means should add that knowledge here*/
2991   proto_tree_add_item(tree, hf_mscldap_netlogon_type, tvb, offset, 4, TRUE);
2992   offset += 4;
2993
2994   /* Flags */
2995   offset = dissect_mscldap_netlogon_flags(tree, tvb, offset);
2996
2997   /* Domain GUID */
2998   proto_tree_add_item(tree, hf_mscldap_domain_guid, tvb, offset, 16, TRUE);
2999   offset += 16;
3000
3001   /* Forest */
3002   old_offset=offset;
3003   offset=dissect_mscldap_string(tvb, offset, str, 255, FALSE);
3004   proto_tree_add_string(tree, hf_mscldap_forest, tvb, old_offset, offset-old_offset, str);
3005   
3006   /* Domain */
3007   old_offset=offset;
3008   offset=dissect_mscldap_string(tvb, offset, str, 255, FALSE);
3009   proto_tree_add_string(tree, hf_mscldap_domain, tvb, old_offset, offset-old_offset, str);
3010   
3011   /* Hostname */
3012   old_offset=offset;
3013   offset=dissect_mscldap_string(tvb, offset, str, 255, FALSE);
3014   proto_tree_add_string(tree, hf_mscldap_hostname, tvb, old_offset, offset-old_offset, str);
3015   
3016   /* NetBios Domain */
3017   old_offset=offset;
3018   offset=dissect_mscldap_string(tvb, offset, str, 255, FALSE);
3019   proto_tree_add_string(tree, hf_mscldap_nb_domain, tvb, old_offset, offset-old_offset, str);
3020   
3021   /* NetBios Hostname */
3022   old_offset=offset;
3023   offset=dissect_mscldap_string(tvb, offset, str, 255, FALSE);
3024   proto_tree_add_string(tree, hf_mscldap_nb_hostname, tvb, old_offset, offset-old_offset, str);
3025   
3026   /* User */
3027   old_offset=offset;
3028   offset=dissect_mscldap_string(tvb, offset, str, 255, FALSE);
3029   proto_tree_add_string(tree, hf_mscldap_username, tvb, old_offset, offset-old_offset, str);
3030   
3031   /* Site */
3032   old_offset=offset;
3033   offset=dissect_mscldap_string(tvb, offset, str, 255, FALSE);
3034   proto_tree_add_string(tree, hf_mscldap_sitename, tvb, old_offset, offset-old_offset, str);
3035   
3036   /* Client Site */
3037   old_offset=offset;
3038   offset=dissect_mscldap_string(tvb, offset, str, 255, FALSE);
3039   proto_tree_add_string(tree, hf_mscldap_clientsitename, tvb, old_offset, offset-old_offset, str);
3040   
3041   /* Version */
3042   proto_tree_add_item(tree, hf_mscldap_netlogon_version, tvb, offset, 4, TRUE);
3043   offset += 4;
3044
3045   /* LM Token */
3046   proto_tree_add_item(tree, hf_mscldap_netlogon_lm_token, tvb, offset, 2, TRUE);
3047   offset += 2;
3048
3049   /* NT Token */
3050   proto_tree_add_item(tree, hf_mscldap_netlogon_nt_token, tvb, offset, 2, TRUE);
3051   offset += 2;
3052
3053 }
3054
3055
3056 static void
3057 dissect_ldap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
3058 {
3059         dissect_ldap_pdu(tvb, pinfo, tree, FALSE);
3060         return;
3061 }
3062
3063 static void
3064 dissect_mscldap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
3065 {
3066         dissect_ldap_pdu(tvb, pinfo, tree, TRUE);
3067         return;
3068 }
3069
3070
3071 static void
3072 ldap_reinit(void)
3073 {
3074   ldap_conv_info_t *ldap_info;
3075
3076   /* Free up state attached to the ldap_info structures */
3077   for (ldap_info = ldap_info_items; ldap_info != NULL; ldap_info = ldap_info->next) {
3078     if (ldap_info->auth_mech != NULL) {
3079       g_free(ldap_info->auth_mech);
3080       ldap_info->auth_mech=NULL;
3081     }
3082     g_hash_table_destroy(ldap_info->matched);
3083     ldap_info->matched=NULL;
3084     g_hash_table_destroy(ldap_info->unmatched);
3085     ldap_info->unmatched=NULL;
3086   }
3087
3088   ldap_info_items = NULL;
3089
3090 }
3091
3092 void
3093 register_ldap_name_dissector_handle(const char *attr_type, dissector_handle_t dissector)
3094 {
3095         dissector_add_string("ldap.name", attr_type, dissector);
3096 }
3097
3098 void
3099 register_ldap_name_dissector(const char *attr_type, dissector_t dissector, int proto)
3100 {
3101         dissector_handle_t dissector_handle;
3102
3103         dissector_handle=create_dissector_handle(dissector, proto);
3104         register_ldap_name_dissector_handle(attr_type, dissector_handle);
3105 }
3106
3107
3108 /*--- proto_register_ldap -------------------------------------------*/
3109 void proto_register_ldap(void) {
3110
3111   /* List of fields */
3112
3113   static hf_register_info hf[] = {
3114
3115                 { &hf_ldap_sasl_buffer_length,
3116                   { "SASL Buffer Length",       "ldap.sasl_buffer_length",
3117                         FT_UINT32, BASE_DEC, NULL, 0x0,
3118                         "SASL Buffer Length", HFILL }},
3119             { &hf_ldap_response_in,
3120               { "Response In", "ldap.response_in",
3121                 FT_FRAMENUM, BASE_DEC, NULL, 0x0,
3122                 "The response to this LDAP request is in this frame", HFILL }},
3123             { &hf_ldap_response_to,
3124               { "Response To", "ldap.response_to",
3125                 FT_FRAMENUM, BASE_DEC, NULL, 0x0,
3126                 "This is a response to the LDAP request in this frame", HFILL }},
3127             { &hf_ldap_time,
3128               { "Time", "ldap.time",
3129                 FT_RELATIVE_TIME, BASE_NONE, NULL, 0x0,
3130                 "The time between the Call and the Reply", HFILL }},
3131
3132     { &hf_mscldap_netlogon_type,
3133       { "Type", "mscldap.netlogon.type",
3134         FT_UINT32, BASE_DEC, NULL, 0x0,
3135         "Type of <please tell ethereal developers what this type is>", HFILL }},
3136
3137     { &hf_mscldap_netlogon_version,
3138       { "Version", "mscldap.netlogon.version",
3139         FT_UINT32, BASE_DEC, NULL, 0x0,
3140         "Version of <please tell ethereal developers what this type is>", HFILL }},
3141
3142     { &hf_mscldap_netlogon_lm_token,
3143       { "LM Token", "mscldap.netlogon.lm_token",
3144         FT_UINT16, BASE_HEX, NULL, 0x0,
3145         "LM Token", HFILL }},
3146
3147     { &hf_mscldap_netlogon_nt_token,
3148       { "NT Token", "mscldap.netlogon.nt_token",
3149         FT_UINT16, BASE_HEX, NULL, 0x0,
3150         "NT Token", HFILL }},
3151
3152     { &hf_mscldap_netlogon_flags,
3153       { "Flags", "mscldap.netlogon.flags",
3154         FT_UINT32, BASE_HEX, NULL, 0x0,
3155         "Netlogon flags describing the DC properties", HFILL }},
3156
3157     { &hf_mscldap_domain_guid,
3158       { "Domain GUID", "mscldap.domain.guid",
3159         FT_BYTES, BASE_HEX, NULL, 0x0,
3160         "Domain GUID", HFILL }},
3161
3162     { &hf_mscldap_forest,
3163       { "Forest", "mscldap.forest",
3164         FT_STRING, BASE_NONE, NULL, 0x0,
3165         "Forest", HFILL }},
3166
3167     { &hf_mscldap_domain,
3168       { "Domain", "mscldap.domain",
3169         FT_STRING, BASE_NONE, NULL, 0x0,
3170         "Domainname", HFILL }},
3171
3172     { &hf_mscldap_hostname,
3173       { "Hostname", "mscldap.hostname",
3174         FT_STRING, BASE_NONE, NULL, 0x0,
3175         "Hostname", HFILL }},
3176
3177     { &hf_mscldap_nb_domain,
3178       { "NetBios Domain", "mscldap.nb_domain",
3179         FT_STRING, BASE_NONE, NULL, 0x0,
3180         "NetBios Domainname", HFILL }},
3181
3182     { &hf_mscldap_nb_hostname,
3183       { "NetBios Hostname", "mscldap.nb_hostname",
3184         FT_STRING, BASE_NONE, NULL, 0x0,
3185         "NetBios Hostname", HFILL }},
3186
3187     { &hf_mscldap_username,
3188       { "User", "mscldap.username",
3189         FT_STRING, BASE_NONE, NULL, 0x0,
3190         "User name", HFILL }},
3191
3192     { &hf_mscldap_sitename,
3193       { "Site", "mscldap.sitename",
3194         FT_STRING, BASE_NONE, NULL, 0x0,
3195         "Site name", HFILL }},
3196
3197     { &hf_mscldap_clientsitename,
3198       { "Client Site", "mscldap.clientsitename",
3199         FT_STRING, BASE_NONE, NULL, 0x0,
3200         "Client Site name", HFILL }},
3201
3202     { &hf_mscldap_netlogon_flags_pdc,
3203       { "PDC", "mscldap.netlogon.flags.pdc", FT_BOOLEAN, 32,
3204         TFS(&tfs_ads_pdc), 0x00000001, "Is this DC a PDC or not?", HFILL }},
3205
3206     { &hf_mscldap_netlogon_flags_gc,
3207       { "GC", "mscldap.netlogon.flags.gc", FT_BOOLEAN, 32,
3208         TFS(&tfs_ads_gc), 0x00000004, "Does this dc service as a GLOBAL CATALOGUE?", HFILL }},
3209
3210     { &hf_mscldap_netlogon_flags_ldap,
3211       { "LDAP", "mscldap.netlogon.flags.ldap", FT_BOOLEAN, 32,
3212         TFS(&tfs_ads_ldap), 0x00000008, "Does this DC act as an LDAP server?", HFILL }},
3213
3214     { &hf_mscldap_netlogon_flags_ds,
3215       { "DS", "mscldap.netlogon.flags.ds", FT_BOOLEAN, 32,
3216         TFS(&tfs_ads_ds), 0x00000010, "Does this dc provide DS services?", HFILL }},
3217
3218     { &hf_mscldap_netlogon_flags_kdc,
3219       { "KDC", "mscldap.netlogon.flags.kdc", FT_BOOLEAN, 32,
3220         TFS(&tfs_ads_kdc), 0x00000020, "Does this dc act as a KDC?", HFILL }},
3221
3222     { &hf_mscldap_netlogon_flags_timeserv,
3223       { "Time Serv", "mscldap.netlogon.flags.timeserv", FT_BOOLEAN, 32,
3224         TFS(&tfs_ads_timeserv), 0x00000040, "Does this dc provide time services (ntp) ?", HFILL }},
3225
3226     { &hf_mscldap_netlogon_flags_closest,
3227       { "Closest", "mscldap.netlogon.flags.closest", FT_BOOLEAN, 32,
3228         TFS(&tfs_ads_closest), 0x00000080, "Is this the closest dc? (is this used at all?)", HFILL }},
3229
3230     { &hf_mscldap_netlogon_flags_writable,
3231       { "Writable", "mscldap.netlogon.flags.writable", FT_BOOLEAN, 32,
3232         TFS(&tfs_ads_writable), 0x00000100, "Is this dc writable? (i.e. can it update the AD?)", HFILL }},
3233
3234     { &hf_mscldap_netlogon_flags_good_timeserv,
3235       { "Good Time Serv", "mscldap.netlogon.flags.good_timeserv", FT_BOOLEAN, 32,
3236         TFS(&tfs_ads_good_timeserv), 0x00000200, "Is this a Good Time Server? (i.e. does it have a hardware clock)", HFILL }},
3237
3238     { &hf_mscldap_netlogon_flags_ndnc,
3239       { "NDNC", "mscldap.netlogon.flags.ndnc", FT_BOOLEAN, 32,
3240         TFS(&tfs_ads_ndnc), 0x00000400, "Is this an NDNC dc?", HFILL }},
3241
3242
3243 /*--- Included file: packet-ldap-hfarr.c ---*/
3244 #line 1 "packet-ldap-hfarr.c"
3245     { &hf_ldap_LDAPMessage_PDU,
3246       { "LDAPMessage", "ldap.LDAPMessage",
3247         FT_NONE, BASE_NONE, NULL, 0,
3248         "LDAPMessage", HFILL }},
3249     { &hf_ldap_messageID,
3250       { "messageID", "ldap.messageID",
3251         FT_UINT32, BASE_DEC, NULL, 0,
3252         "LDAPMessage/messageID", HFILL }},
3253     { &hf_ldap_protocolOp,
3254       { "protocolOp", "ldap.protocolOp",
3255         FT_UINT32, BASE_DEC, VALS(ldap_ProtocolOp_vals), 0,
3256         "LDAPMessage/protocolOp", HFILL }},
3257     { &hf_ldap_controls,
3258       { "controls", "ldap.controls",
3259         FT_UINT32, BASE_DEC, NULL, 0,
3260         "LDAPMessage/controls", HFILL }},
3261     { &hf_ldap_bindRequest,
3262       { "bindRequest", "ldap.bindRequest",
3263         FT_NONE, BASE_NONE, NULL, 0,
3264         "ProtocolOp/bindRequest", HFILL }},
3265     { &hf_ldap_bindResponse,
3266       { "bindResponse", "ldap.bindResponse",
3267         FT_NONE, BASE_NONE, NULL, 0,
3268         "ProtocolOp/bindResponse", HFILL }},
3269     { &hf_ldap_unbindRequest,
3270       { "unbindRequest", "ldap.unbindRequest",
3271         FT_NONE, BASE_NONE, NULL, 0,
3272         "ProtocolOp/unbindRequest", HFILL }},
3273     { &hf_ldap_searchRequest,
3274       { "searchRequest", "ldap.searchRequest",
3275         FT_NONE, BASE_NONE, NULL, 0,
3276         "ProtocolOp/searchRequest", HFILL }},
3277     { &hf_ldap_searchResEntry,
3278       { "searchResEntry", "ldap.searchResEntry",
3279         FT_NONE, BASE_NONE, NULL, 0,
3280         "ProtocolOp/searchResEntry", HFILL }},
3281     { &hf_ldap_searchResDone,
3282       { "searchResDone", "ldap.searchResDone",
3283         FT_NONE, BASE_NONE, NULL, 0,
3284         "ProtocolOp/searchResDone", HFILL }},
3285     { &hf_ldap_searchResRef,
3286       { "searchResRef", "ldap.searchResRef",
3287         FT_UINT32, BASE_DEC, NULL, 0,
3288         "ProtocolOp/searchResRef", HFILL }},
3289     { &hf_ldap_modifyRequest,
3290       { "modifyRequest", "ldap.modifyRequest",
3291         FT_NONE, BASE_NONE, NULL, 0,
3292         "ProtocolOp/modifyRequest", HFILL }},
3293     { &hf_ldap_modifyResponse,
3294       { "modifyResponse", "ldap.modifyResponse",
3295         FT_NONE, BASE_NONE, NULL, 0,
3296         "ProtocolOp/modifyResponse", HFILL }},
3297     { &hf_ldap_addRequest,
3298       { "addRequest", "ldap.addRequest",
3299         FT_NONE, BASE_NONE, NULL, 0,
3300         "ProtocolOp/addRequest", HFILL }},
3301     { &hf_ldap_addResponse,
3302       { "addResponse", "ldap.addResponse",
3303         FT_NONE, BASE_NONE, NULL, 0,
3304         "ProtocolOp/addResponse", HFILL }},
3305     { &hf_ldap_delRequest,
3306       { "delRequest", "ldap.delRequest",
3307         FT_STRING, BASE_NONE, NULL, 0,
3308         "ProtocolOp/delRequest", HFILL }},
3309     { &hf_ldap_delResponse,
3310       { "delResponse", "ldap.delResponse",
3311         FT_NONE, BASE_NONE, NULL, 0,
3312         "ProtocolOp/delResponse", HFILL }},
3313     { &hf_ldap_modDNRequest,
3314       { "modDNRequest", "ldap.modDNRequest",
3315         FT_NONE, BASE_NONE, NULL, 0,
3316         "ProtocolOp/modDNRequest", HFILL }},
3317     { &hf_ldap_modDNResponse,
3318       { "modDNResponse", "ldap.modDNResponse",
3319         FT_NONE, BASE_NONE, NULL, 0,
3320         "ProtocolOp/modDNResponse", HFILL }},
3321     { &hf_ldap_compareRequest,
3322       { "compareRequest", "ldap.compareRequest",
3323         FT_NONE, BASE_NONE, NULL, 0,
3324         "ProtocolOp/compareRequest", HFILL }},
3325     { &hf_ldap_compareResponse,
3326       { "compareResponse", "ldap.compareResponse",
3327         FT_NONE, BASE_NONE, NULL, 0,
3328         "ProtocolOp/compareResponse", HFILL }},
3329     { &hf_ldap_abandonRequest,
3330       { "abandonRequest", "ldap.abandonRequest",
3331         FT_UINT32, BASE_DEC, NULL, 0,
3332         "ProtocolOp/abandonRequest", HFILL }},
3333     { &hf_ldap_extendedReq,
3334       { "extendedReq", "ldap.extendedReq",
3335         FT_NONE, BASE_NONE, NULL, 0,
3336         "ProtocolOp/extendedReq", HFILL }},
3337     { &hf_ldap_extendedResp,
3338       { "extendedResp", "ldap.extendedResp",
3339         FT_NONE, BASE_NONE, NULL, 0,
3340         "ProtocolOp/extendedResp", HFILL }},
3341     { &hf_ldap_AttributeDescriptionList_item,
3342       { "Item", "ldap.AttributeDescriptionList_item",
3343         FT_STRING, BASE_NONE, NULL, 0,
3344         "AttributeDescriptionList/_item", HFILL }},
3345     { &hf_ldap_attributeDesc,
3346       { "attributeDesc", "ldap.attributeDesc",
3347         FT_STRING, BASE_NONE, NULL, 0,
3348         "AttributeValueAssertion/attributeDesc", HFILL }},
3349     { &hf_ldap_assertionValue,
3350       { "assertionValue", "ldap.assertionValue",
3351         FT_BYTES, BASE_HEX, NULL, 0,
3352         "AttributeValueAssertion/assertionValue", HFILL }},
3353     { &hf_ldap_type,
3354       { "type", "ldap.type",
3355         FT_STRING, BASE_NONE, NULL, 0,
3356         "", HFILL }},
3357     { &hf_ldap_vals,
3358       { "vals", "ldap.vals",
3359         FT_UINT32, BASE_DEC, NULL, 0,
3360         "", HFILL }},
3361     { &hf_ldap_vals_item,
3362       { "Item", "ldap.vals_item",
3363         FT_BYTES, BASE_HEX, NULL, 0,
3364         "", HFILL }},
3365     { &hf_ldap_resultCode,
3366       { "resultCode", "ldap.resultCode",
3367         FT_UINT32, BASE_DEC, VALS(ldap_T_resultCode_vals), 0,
3368         "LDAPResult/resultCode", HFILL }},
3369     { &hf_ldap_matchedDN,
3370       { "matchedDN", "ldap.matchedDN",
3371         FT_STRING, BASE_NONE, NULL, 0,
3372         "", HFILL }},
3373     { &hf_ldap_errorMessage,
3374       { "errorMessage", "ldap.errorMessage",
3375         FT_STRING, BASE_NONE, NULL, 0,
3376         "", HFILL }},
3377     { &hf_ldap_referral,
3378       { "referral", "ldap.referral",
3379         FT_UINT32, BASE_DEC, NULL, 0,
3380         "", HFILL }},
3381     { &hf_ldap_Referral_item,
3382       { "Item", "ldap.Referral_item",
3383         FT_STRING, BASE_NONE, NULL, 0,
3384         "Referral/_item", HFILL }},
3385     { &hf_ldap_Controls_item,
3386       { "Item", "ldap.Controls_item",
3387         FT_NONE, BASE_NONE, NULL, 0,
3388         "Controls/_item", HFILL }},
3389     { &hf_ldap_controlType,
3390       { "controlType", "ldap.controlType",
3391         FT_STRING, BASE_NONE, NULL, 0,
3392         "Control/controlType", HFILL }},
3393     { &hf_ldap_criticality,
3394       { "criticality", "ldap.criticality",
3395         FT_BOOLEAN, 8, NULL, 0,
3396         "Control/criticality", HFILL }},
3397     { &hf_ldap_controlValue,
3398       { "controlValue", "ldap.controlValue",
3399         FT_BYTES, BASE_HEX, NULL, 0,
3400         "Control/controlValue", HFILL }},
3401     { &hf_ldap_version,
3402       { "version", "ldap.version",
3403         FT_UINT32, BASE_DEC, NULL, 0,
3404         "BindRequest/version", HFILL }},
3405     { &hf_ldap_name,
3406       { "name", "ldap.name",
3407         FT_STRING, BASE_NONE, NULL, 0,
3408         "BindRequest/name", HFILL }},
3409     { &hf_ldap_authentication,
3410       { "authentication", "ldap.authentication",
3411         FT_UINT32, BASE_DEC, VALS(ldap_AuthenticationChoice_vals), 0,
3412         "BindRequest/authentication", HFILL }},
3413     { &hf_ldap_simple,
3414       { "simple", "ldap.simple",
3415         FT_BYTES, BASE_HEX, NULL, 0,
3416         "AuthenticationChoice/simple", HFILL }},
3417     { &hf_ldap_sasl,
3418       { "sasl", "ldap.sasl",
3419         FT_NONE, BASE_NONE, NULL, 0,
3420         "AuthenticationChoice/sasl", HFILL }},
3421     { &hf_ldap_mechanism,
3422       { "mechanism", "ldap.mechanism",
3423         FT_STRING, BASE_NONE, NULL, 0,
3424         "SaslCredentials/mechanism", HFILL }},
3425     { &hf_ldap_credentials,
3426       { "credentials", "ldap.credentials",
3427         FT_BYTES, BASE_HEX, NULL, 0,
3428         "SaslCredentials/credentials", HFILL }},
3429     { &hf_ldap_bindResponse_resultCode,
3430       { "resultCode", "ldap.resultCode",
3431         FT_UINT32, BASE_DEC, VALS(ldap_BindResponse_resultCode_vals), 0,
3432         "BindResponse/resultCode", HFILL }},
3433     { &hf_ldap_serverSaslCreds,
3434       { "serverSaslCreds", "ldap.serverSaslCreds",
3435         FT_BYTES, BASE_HEX, NULL, 0,
3436         "BindResponse/serverSaslCreds", HFILL }},
3437     { &hf_ldap_baseObject,
3438       { "baseObject", "ldap.baseObject",
3439         FT_STRING, BASE_NONE, NULL, 0,
3440         "SearchRequest/baseObject", HFILL }},
3441     { &hf_ldap_scope,
3442       { "scope", "ldap.scope",
3443         FT_UINT32, BASE_DEC, VALS(ldap_T_scope_vals), 0,
3444         "SearchRequest/scope", HFILL }},
3445     { &hf_ldap_derefAliases,
3446       { "derefAliases", "ldap.derefAliases",
3447         FT_UINT32, BASE_DEC, VALS(ldap_T_derefAliases_vals), 0,
3448         "SearchRequest/derefAliases", HFILL }},
3449     { &hf_ldap_sizeLimit,
3450       { "sizeLimit", "ldap.sizeLimit",
3451         FT_UINT32, BASE_DEC, NULL, 0,
3452         "SearchRequest/sizeLimit", HFILL }},
3453     { &hf_ldap_timeLimit,
3454       { "timeLimit", "ldap.timeLimit",
3455         FT_UINT32, BASE_DEC, NULL, 0,
3456         "SearchRequest/timeLimit", HFILL }},
3457     { &hf_ldap_typesOnly,
3458       { "typesOnly", "ldap.typesOnly",
3459         FT_BOOLEAN, 8, NULL, 0,
3460         "SearchRequest/typesOnly", HFILL }},
3461     { &hf_ldap_filter,
3462       { "filter", "ldap.filter",
3463         FT_UINT32, BASE_DEC, VALS(ldap_Filter_vals), 0,
3464         "SearchRequest/filter", HFILL }},
3465     { &hf_ldap_searchRequest_attributes,
3466       { "attributes", "ldap.attributes",
3467         FT_UINT32, BASE_DEC, NULL, 0,
3468         "SearchRequest/attributes", HFILL }},
3469     { &hf_ldap_and,
3470       { "and", "ldap.and",
3471         FT_UINT32, BASE_DEC, NULL, 0,
3472         "Filter/and", HFILL }},
3473     { &hf_ldap_and_item,
3474       { "Item", "ldap.and_item",
3475         FT_UINT32, BASE_DEC, VALS(ldap_Filter_vals), 0,
3476         "Filter/and/_item", HFILL }},
3477     { &hf_ldap_or,
3478       { "or", "ldap.or",
3479         FT_UINT32, BASE_DEC, NULL, 0,
3480         "Filter/or", HFILL }},
3481     { &hf_ldap_or_item,
3482       { "Item", "ldap.or_item",
3483         FT_UINT32, BASE_DEC, VALS(ldap_Filter_vals), 0,
3484         "Filter/or/_item", HFILL }},
3485     { &hf_ldap_not,
3486       { "not", "ldap.not",
3487         FT_UINT32, BASE_DEC, VALS(ldap_Filter_vals), 0,
3488         "Filter/not", HFILL }},
3489     { &hf_ldap_equalityMatch,
3490       { "equalityMatch", "ldap.equalityMatch",
3491         FT_NONE, BASE_NONE, NULL, 0,
3492         "Filter/equalityMatch", HFILL }},
3493     { &hf_ldap_substrings,
3494       { "substrings", "ldap.substrings",
3495         FT_NONE, BASE_NONE, NULL, 0,
3496         "Filter/substrings", HFILL }},
3497     { &hf_ldap_greaterOrEqual,
3498       { "greaterOrEqual", "ldap.greaterOrEqual",
3499         FT_NONE, BASE_NONE, NULL, 0,
3500         "Filter/greaterOrEqual", HFILL }},
3501     { &hf_ldap_lessOrEqual,
3502       { "lessOrEqual", "ldap.lessOrEqual",
3503         FT_NONE, BASE_NONE, NULL, 0,
3504         "Filter/lessOrEqual", HFILL }},
3505     { &hf_ldap_present,
3506       { "present", "ldap.present",
3507         FT_STRING, BASE_NONE, NULL, 0,
3508         "Filter/present", HFILL }},
3509     { &hf_ldap_approxMatch,
3510       { "approxMatch", "ldap.approxMatch",
3511         FT_NONE, BASE_NONE, NULL, 0,
3512         "Filter/approxMatch", HFILL }},
3513     { &hf_ldap_extensibleMatch,
3514       { "extensibleMatch", "ldap.extensibleMatch",
3515         FT_NONE, BASE_NONE, NULL, 0,
3516         "Filter/extensibleMatch", HFILL }},
3517     { &hf_ldap_substringFilter_substrings,
3518       { "substrings", "ldap.substrings",
3519         FT_UINT32, BASE_DEC, NULL, 0,
3520         "SubstringFilter/substrings", HFILL }},
3521     { &hf_ldap_substrings_item,
3522       { "Item", "ldap.substrings_item",
3523         FT_UINT32, BASE_DEC, VALS(ldap_T_substrings_item_vals), 0,
3524         "SubstringFilter/substrings/_item", HFILL }},
3525     { &hf_ldap_initial,
3526       { "initial", "ldap.initial",
3527         FT_STRING, BASE_NONE, NULL, 0,
3528         "SubstringFilter/substrings/_item/initial", HFILL }},
3529     { &hf_ldap_any,
3530       { "any", "ldap.any",
3531         FT_STRING, BASE_NONE, NULL, 0,
3532         "SubstringFilter/substrings/_item/any", HFILL }},
3533     { &hf_ldap_final,
3534       { "final", "ldap.final",
3535         FT_STRING, BASE_NONE, NULL, 0,
3536         "SubstringFilter/substrings/_item/final", HFILL }},
3537     { &hf_ldap_matchingRule,
3538       { "matchingRule", "ldap.matchingRule",
3539         FT_STRING, BASE_NONE, NULL, 0,
3540         "MatchingRuleAssertion/matchingRule", HFILL }},
3541     { &hf_ldap_matchValue,
3542       { "matchValue", "ldap.matchValue",
3543         FT_BYTES, BASE_HEX, NULL, 0,
3544         "MatchingRuleAssertion/matchValue", HFILL }},
3545     { &hf_ldap_dnAttributes,
3546       { "dnAttributes", "ldap.dnAttributes",
3547         FT_BOOLEAN, 8, NULL, 0,
3548         "MatchingRuleAssertion/dnAttributes", HFILL }},
3549     { &hf_ldap_objectName,
3550       { "objectName", "ldap.objectName",
3551         FT_STRING, BASE_NONE, NULL, 0,
3552         "SearchResultEntry/objectName", HFILL }},
3553     { &hf_ldap_searchResultEntry_attributes,
3554       { "attributes", "ldap.attributes",
3555         FT_UINT32, BASE_DEC, NULL, 0,
3556         "SearchResultEntry/attributes", HFILL }},
3557     { &hf_ldap_PartialAttributeList_item,
3558       { "Item", "ldap.PartialAttributeList_item",
3559         FT_NONE, BASE_NONE, NULL, 0,
3560         "PartialAttributeList/_item", HFILL }},
3561     { &hf_ldap_SearchResultReference_item,
3562       { "Item", "ldap.SearchResultReference_item",
3563         FT_STRING, BASE_NONE, NULL, 0,
3564         "SearchResultReference/_item", HFILL }},
3565     { &hf_ldap_object,
3566       { "object", "ldap.object",
3567         FT_STRING, BASE_NONE, NULL, 0,
3568         "ModifyRequest/object", HFILL }},
3569     { &hf_ldap_modifyRequest_modification,
3570       { "modification", "ldap.modification",
3571         FT_UINT32, BASE_DEC, NULL, 0,
3572         "ModifyRequest/modification", HFILL }},
3573     { &hf_ldap_modification_item,
3574       { "Item", "ldap.modification_item",
3575         FT_NONE, BASE_NONE, NULL, 0,
3576         "ModifyRequest/modification/_item", HFILL }},
3577     { &hf_ldap_operation,
3578       { "operation", "ldap.operation",
3579         FT_UINT32, BASE_DEC, VALS(ldap_T_operation_vals), 0,
3580         "ModifyRequest/modification/_item/operation", HFILL }},
3581     { &hf_ldap_modification,
3582       { "modification", "ldap.modification",
3583         FT_NONE, BASE_NONE, NULL, 0,
3584         "ModifyRequest/modification/_item/modification", HFILL }},
3585     { &hf_ldap_entry,
3586       { "entry", "ldap.entry",
3587         FT_STRING, BASE_NONE, NULL, 0,
3588         "", HFILL }},
3589     { &hf_ldap_attributes,
3590       { "attributes", "ldap.attributes",
3591         FT_UINT32, BASE_DEC, NULL, 0,
3592         "AddRequest/attributes", HFILL }},
3593     { &hf_ldap_AttributeList_item,
3594       { "Item", "ldap.AttributeList_item",
3595         FT_NONE, BASE_NONE, NULL, 0,
3596         "AttributeList/_item", HFILL }},
3597     { &hf_ldap_newrdn,
3598       { "newrdn", "ldap.newrdn",
3599         FT_STRING, BASE_NONE, NULL, 0,
3600         "ModifyDNRequest/newrdn", HFILL }},
3601     { &hf_ldap_deleteoldrdn,
3602       { "deleteoldrdn", "ldap.deleteoldrdn",
3603         FT_BOOLEAN, 8, NULL, 0,
3604         "ModifyDNRequest/deleteoldrdn", HFILL }},
3605     { &hf_ldap_newSuperior,
3606       { "newSuperior", "ldap.newSuperior",
3607         FT_STRING, BASE_NONE, NULL, 0,
3608         "ModifyDNRequest/newSuperior", HFILL }},
3609     { &hf_ldap_ava,
3610       { "ava", "ldap.ava",
3611         FT_NONE, BASE_NONE, NULL, 0,
3612         "CompareRequest/ava", HFILL }},
3613     { &hf_ldap_requestName,
3614       { "requestName", "ldap.requestName",
3615         FT_STRING, BASE_NONE, NULL, 0,
3616         "ExtendedRequest/requestName", HFILL }},
3617     { &hf_ldap_requestValue,
3618       { "requestValue", "ldap.requestValue",
3619         FT_BYTES, BASE_HEX, NULL, 0,
3620         "ExtendedRequest/requestValue", HFILL }},
3621     { &hf_ldap_extendedResponse_resultCode,
3622       { "resultCode", "ldap.resultCode",
3623         FT_UINT32, BASE_DEC, VALS(ldap_ExtendedResponse_resultCode_vals), 0,
3624         "ExtendedResponse/resultCode", HFILL }},
3625     { &hf_ldap_responseName,
3626       { "responseName", "ldap.responseName",
3627         FT_STRING, BASE_NONE, NULL, 0,
3628         "ExtendedResponse/responseName", HFILL }},
3629     { &hf_ldap_response,
3630       { "response", "ldap.response",
3631         FT_BYTES, BASE_HEX, NULL, 0,
3632         "ExtendedResponse/response", HFILL }},
3633
3634 /*--- End of included file: packet-ldap-hfarr.c ---*/
3635 #line 1281 "packet-ldap-template.c"
3636   };
3637
3638   /* List of subtrees */
3639   static gint *ett[] = {
3640     &ett_ldap,
3641     &ett_ldap_payload,
3642     &ett_ldap_sasl_blob,
3643     &ett_ldap_msg,
3644     &ett_mscldap_netlogon_flags,
3645
3646
3647 /*--- Included file: packet-ldap-ettarr.c ---*/
3648 #line 1 "packet-ldap-ettarr.c"
3649     &ett_ldap_LDAPMessage,
3650     &ett_ldap_ProtocolOp,
3651     &ett_ldap_AttributeDescriptionList,
3652     &ett_ldap_AttributeValueAssertion,
3653     &ett_ldap_Attribute,
3654     &ett_ldap_SET_OF_AttributeValue,
3655     &ett_ldap_LDAPResult,
3656     &ett_ldap_Referral,
3657     &ett_ldap_Controls,
3658     &ett_ldap_Control,
3659     &ett_ldap_BindRequest,
3660     &ett_ldap_AuthenticationChoice,
3661     &ett_ldap_SaslCredentials,
3662     &ett_ldap_BindResponse,
3663     &ett_ldap_SearchRequest,
3664     &ett_ldap_Filter,
3665     &ett_ldap_SET_OF_Filter,
3666     &ett_ldap_SubstringFilter,
3667     &ett_ldap_T_substrings,
3668     &ett_ldap_T_substrings_item,
3669     &ett_ldap_MatchingRuleAssertion,
3670     &ett_ldap_SearchResultEntry,
3671     &ett_ldap_PartialAttributeList,
3672     &ett_ldap_PartialAttributeList_item,
3673     &ett_ldap_SearchResultReference,
3674     &ett_ldap_ModifyRequest,
3675     &ett_ldap_ModifyRequest_modification,
3676     &ett_ldap_T_modification_item,
3677     &ett_ldap_AttributeTypeAndValues,
3678     &ett_ldap_AddRequest,
3679     &ett_ldap_AttributeList,
3680     &ett_ldap_AttributeList_item,
3681     &ett_ldap_ModifyDNRequest,
3682     &ett_ldap_CompareRequest,
3683     &ett_ldap_ExtendedRequest,
3684     &ett_ldap_ExtendedResponse,
3685
3686 /*--- End of included file: packet-ldap-ettarr.c ---*/
3687 #line 1292 "packet-ldap-template.c"
3688   };
3689
3690     module_t *ldap_module;
3691
3692   /* Register protocol */
3693   proto_ldap = proto_register_protocol(PNAME, PSNAME, PFNAME);
3694   /* Register fields and subtrees */
3695   proto_register_field_array(proto_ldap, hf, array_length(hf));
3696   proto_register_subtree_array(ett, array_length(ett));
3697
3698
3699   register_dissector("ldap", dissect_ldap, proto_ldap);
3700
3701   ldap_module = prefs_register_protocol(proto_ldap, NULL);
3702   prefs_register_bool_preference(ldap_module, "desegment_ldap_messages",
3703     "Reassemble LDAP messages spanning multiple TCP segments",
3704     "Whether the LDAP dissector should reassemble messages spanning multiple TCP segments."
3705     " To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings, and disable \"Verify length\" in the BER protocol settings",
3706     &ldap_desegment);
3707
3708   prefs_register_uint_preference(ldap_module, "tcp.port", "LDAP TCP Port",
3709                                  "Set the port for LDAP operations",
3710                                  10, &ldap_tcp_port);
3711
3712   proto_cldap = proto_register_protocol(
3713           "Connectionless Lightweight Directory Access Protocol",
3714           "CLDAP", "cldap");
3715
3716   register_init_routine(ldap_reinit);
3717   ldap_tap=register_tap("ldap");
3718
3719   ldap_name_dissector_table = register_dissector_table("ldap.name", "LDAP Attribute Type Dissectors", FT_STRING, BASE_NONE);
3720
3721
3722 }
3723
3724
3725 /*--- proto_reg_handoff_ldap ---------------------------------------*/
3726 void
3727 proto_reg_handoff_ldap(void)
3728 {
3729         dissector_handle_t ldap_handle, cldap_handle;
3730         ldap_handle = create_dissector_handle(dissect_ldap, proto_ldap);
3731
3732         dissector_add("tcp.port", ldap_tcp_port, ldap_handle);
3733         dissector_add("tcp.port", TCP_PORT_GLOBALCAT_LDAP, ldap_handle);
3734
3735         cldap_handle = create_dissector_handle(dissect_mscldap, proto_cldap);
3736         dissector_add("udp.port", UDP_PORT_CLDAP, cldap_handle);
3737
3738         gssapi_handle = find_dissector("gssapi");
3739         gssapi_wrap_handle = find_dissector("gssapi_verf");
3740
3741 /*  http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dsml/dsml/ldap_controls_and_session_support.asp */
3742         register_ber_oid_name("1.2.840.113556.1.4.319","LDAP_PAGED_RESULT_OID_STRING");
3743         register_ber_oid_name("1.2.840.113556.1.4.417","LDAP_SERVER_SHOW_DELETED_OID");
3744         register_ber_oid_name("1.2.840.113556.1.4.473","LDAP_SERVER_SORT_OID");
3745         register_ber_oid_name("1.2.840.113556.1.4.521","LDAP_SERVER_CROSSDOM_MOVE_TARGET_OID");
3746         register_ber_oid_name("1.2.840.113556.1.4.528","LDAP_SERVER_NOTIFICATION_OID");
3747         register_ber_oid_name("1.2.840.113556.1.4.529","LDAP_SERVER_EXTENDED_DN_OID");
3748         register_ber_oid_name("1.2.840.113556.1.4.619","LDAP_SERVER_LAZY_COMMIT_OID");
3749         register_ber_oid_name("1.2.840.113556.1.4.801","LDAP_SERVER_SD_FLAGS_OID");
3750         register_ber_oid_name("1.2.840.113556.1.4.805","LDAP_SERVER_TREE_DELETE_OID");
3751         register_ber_oid_name("1.2.840.113556.1.4.841","LDAP_SERVER_DIRSYNC_OID");
3752         register_ber_oid_name("1.2.840.113556.1.4.970 ","None");
3753         register_ber_oid_name("1.2.840.113556.1.4.1338","LDAP_SERVER_VERIFY_NAME_OID");
3754         register_ber_oid_name("1.2.840.113556.1.4.1339","LDAP_SERVER_DOMAIN_SCOPE_OID");
3755         register_ber_oid_name("1.2.840.113556.1.4.1340","LDAP_SERVER_SEARCH_OPTIONS_OID");
3756         register_ber_oid_name("1.2.840.113556.1.4.1413","LDAP_SERVER_PERMISSIVE_MODIFY_OID");
3757         register_ber_oid_name("1.2.840.113556.1.4.1504","LDAP_SERVER_ASQ_OID");
3758         register_ber_oid_name("1.2.840.113556.1.4.1781","LDAP_SERVER_FAST_BIND_OID");
3759         register_ber_oid_name("1.3.6.1.4.1.1466.101.119.1","None");
3760         register_ber_oid_name("1.3.6.1.4.1.1466.20037","LDAP_START_TLS_OID");
3761         register_ber_oid_name("2.16.840.1.113730.3.4.9","LDAP_CONTROL_VLVREQUEST VLV");
3762
3763         register_ldap_name_dissector("netlogon", dissect_NetLogon_PDU, proto_cldap);
3764
3765 }
3766
3767