Don't remove a preference, make it obsolete instead.
[obnox/wireshark/wip.git] / epan / dissectors / packet-ldap.c
index d4c495ab1f63bc27ce83e4e52e0ab4354eaa18d2..666dce0af5092eb91302544e2869ffceecb32cc3 100644 (file)
@@ -98,6 +98,7 @@
 
 #include "packet-frame.h"
 #include "packet-ldap.h"
+#include "packet-ntlmssp.h"
 
 #include "packet-ber.h"
 #include "packet-per.h"
@@ -156,6 +157,10 @@ static int hf_ldap_AccessMask_ADS_CONTROL_ACCESS = -1;
 /*--- Included file: packet-ldap-hf.c ---*/
 #line 1 "packet-ldap-hf.c"
 static int hf_ldap_LDAPMessage_PDU = -1;          /* LDAPMessage */
+static int hf_ldap_SearchControlValue_PDU = -1;   /* SearchControlValue */
+static int hf_ldap_SortKeyList_PDU = -1;          /* SortKeyList */
+static int hf_ldap_SortResult_PDU = -1;           /* SortResult */
+static int hf_ldap_ReplControlValue_PDU = -1;     /* ReplControlValue */
 static int hf_ldap_messageID = -1;                /* MessageID */
 static int hf_ldap_protocolOp = -1;               /* ProtocolOp */
 static int hf_ldap_controls = -1;                 /* Controls */
@@ -193,15 +198,18 @@ static int hf_ldap_Referral_item = -1;            /* LDAPURL */
 static int hf_ldap_Controls_item = -1;            /* Control */
 static int hf_ldap_controlType = -1;              /* ControlType */
 static int hf_ldap_criticality = -1;              /* BOOLEAN */
-static int hf_ldap_controlValue = -1;             /* OCTET_STRING */
+static int hf_ldap_controlValue = -1;             /* T_controlValue */
 static int hf_ldap_version = -1;                  /* INTEGER_1_127 */
 static int hf_ldap_name = -1;                     /* LDAPDN */
 static int hf_ldap_authentication = -1;           /* AuthenticationChoice */
 static int hf_ldap_simple = -1;                   /* Simple */
 static int hf_ldap_sasl = -1;                     /* SaslCredentials */
+static int hf_ldap_ntlmsspNegotiate = -1;         /* T_ntlmsspNegotiate */
+static int hf_ldap_ntlmsspAuth = -1;              /* T_ntlmsspAuth */
 static int hf_ldap_mechanism = -1;                /* Mechanism */
 static int hf_ldap_credentials = -1;              /* Credentials */
 static int hf_ldap_bindResponse_resultCode = -1;  /* BindResponse_resultCode */
+static int hf_ldap_matchedDN1 = -1;               /* T_matchedDN */
 static int hf_ldap_serverSaslCreds = -1;          /* ServerSaslCreds */
 static int hf_ldap_baseObject = -1;               /* LDAPDN */
 static int hf_ldap_scope = -1;                    /* T_scope */
@@ -252,9 +260,18 @@ static int hf_ldap_requestValue = -1;             /* OCTET_STRING */
 static int hf_ldap_extendedResponse_resultCode = -1;  /* ExtendedResponse_resultCode */
 static int hf_ldap_responseName = -1;             /* ResponseName */
 static int hf_ldap_response = -1;                 /* OCTET_STRING */
+static int hf_ldap_size = -1;                     /* INTEGER */
+static int hf_ldap_cookie = -1;                   /* OCTET_STRING */
+static int hf_ldap_SortKeyList_item = -1;         /* SortKeyList_item */
+static int hf_ldap_attributeType = -1;            /* AttributeDescription */
+static int hf_ldap_orderingRule = -1;             /* MatchingRuleId */
+static int hf_ldap_reverseOrder = -1;             /* BOOLEAN */
+static int hf_ldap_sortResult = -1;               /* T_sortResult */
+static int hf_ldap_parentsFirst = -1;             /* INTEGER */
+static int hf_ldap_maxReturnLength = -1;          /* INTEGER */
 
 /*--- End of included file: packet-ldap-hf.c ---*/
-#line 148 "packet-ldap-template.c"
+#line 149 "packet-ldap-template.c"
 
 /* Initialize the subtree pointers */
 static gint ett_ldap = -1;
@@ -303,15 +320,22 @@ static gint ett_ldap_ModifyDNRequest = -1;
 static gint ett_ldap_CompareRequest = -1;
 static gint ett_ldap_ExtendedRequest = -1;
 static gint ett_ldap_ExtendedResponse = -1;
+static gint ett_ldap_SearchControlValue = -1;
+static gint ett_ldap_SortKeyList = -1;
+static gint ett_ldap_SortKeyList_item = -1;
+static gint ett_ldap_SortResult = -1;
+static gint ett_ldap_ReplControlValue = -1;
 
 /*--- End of included file: packet-ldap-ett.c ---*/
-#line 157 "packet-ldap-template.c"
+#line 158 "packet-ldap-template.c"
 
 static dissector_table_t ldap_name_dissector_table=NULL;
+static const char *object_identifier_id = NULL; /* LDAP OID */
 
 /* desegmentation of LDAP */
 static gboolean ldap_desegment = TRUE;
 static guint    ldap_tcp_port = 389;
+
 static gboolean do_protocolop = FALSE;
 static gchar    *attr_type = NULL;
 static gboolean is_binary_attr_type = FALSE;
@@ -322,6 +346,7 @@ static gboolean is_binary_attr_type = FALSE;
 
 static dissector_handle_t gssapi_handle;
 static dissector_handle_t gssapi_wrap_handle;
+static dissector_handle_t ntlmssp_handle = NULL;
 
 
 /* different types of rpc calls ontop of ms cldap */
@@ -365,7 +390,6 @@ typedef struct ldap_conv_info_t {
   GHashTable *unmatched;
   GHashTable *matched;
   gboolean is_mscldap;
-  gboolean first_time;
   guint32  num_results;
 } ldap_conv_info_t;
 static ldap_conv_info_t *ldap_info_items;
@@ -458,8 +482,7 @@ dissect_ldap_AssertionValue(gboolean implicit_tag, tvbuff_t *tvb, int offset, pa
                /* this octet string contains an NT SID */
                sid_tvb=tvb_new_subset(tvb, offset, len, len);
                dissect_nt_sid(sid_tvb, 0, tree, "SID", &tmpstr, hf_index);
-               ldapvalue_string=ep_strdup(tmpstr);
-               g_free(tmpstr);
+               ldapvalue_string=tmpstr;
 
                goto finished;
        } else if ( (len==16) /* GUIDs are always 16 bytes */
@@ -707,7 +730,7 @@ static int dissect_ldap_Filter(gboolean implicit_tag, tvbuff_t *tvb, int offset,
 
 static int
 dissect_ldap_MessageID(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
-#line 53 "ldap.cnf"
+#line 68 "ldap.cnf"
 
     offset = dissect_ber_integer(implicit_tag, pinfo, tree, tvb, offset, hf_index,
                                   &MessageID);
@@ -740,7 +763,7 @@ static int dissect_version(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb,
 
 static int
 dissect_ldap_LDAPString(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
-#line 240 "ldap.cnf"
+#line 255 "ldap.cnf"
   tvbuff_t     *parameter_tvb = NULL;
   char          *ldapstring;
   gchar                *sc = NULL; /* semi-colon pointer */
@@ -759,12 +782,19 @@ dissect_ldap_LDAPString(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, pa
         ldapstring = "<ROOT>";
 
      if(hf_index == hf_ldap_baseObject) {
-       /* this is search - but it on the scanline */
+       /* this is search - put it on the scanline */
        if(check_col(pinfo->cinfo, COL_INFO)) 
          col_append_fstr(pinfo->cinfo, COL_INFO, "\"%s\" ", ldapstring);
   
        if(ldm_tree)
          proto_item_append_text(ldm_tree, " \"%s\"", ldapstring); 
+
+
+       if(!parameter_tvb) {
+
+         proto_item_append_text(ber_last_created_item, " (%s)", ldapstring); 
+       }
+
      } else if ((hf_index == hf_ldap_errorMessage) && result) { /* only show message if not success */
        if(check_col(pinfo->cinfo, COL_INFO)) 
           col_append_fstr(pinfo->cinfo, COL_INFO, "(%s) ", ldapstring);     
@@ -864,7 +894,7 @@ static int dissect_newSuperior_impl(packet_info *pinfo, proto_tree *tree, tvbuff
 
 static int
 dissect_ldap_Simple(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
-#line 103 "ldap.cnf"
+#line 118 "ldap.cnf"
 ldap_conv_info_t *ldap_info;
 
   offset = dissect_ber_octet_string(implicit_tag, pinfo, tree, tvb, offset, hf_index,
@@ -888,7 +918,7 @@ static int dissect_simple_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *t
 
 static int
 dissect_ldap_Mechanism(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
-#line 114 "ldap.cnf"
+#line 129 "ldap.cnf"
 
 ldap_conv_info_t *ldap_info;
 tvbuff_t       *parameter_tvb;
@@ -940,7 +970,7 @@ static int dissect_mechanism(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb
 
 static int
 dissect_ldap_Credentials(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
-#line 153 "ldap.cnf"
+#line 168 "ldap.cnf"
 
 tvbuff_t       *parameter_tvb;
 ldap_conv_info_t *ldap_info;
@@ -994,21 +1024,63 @@ static int dissect_sasl_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb
 }
 
 
+
+static int
+dissect_ldap_T_ntlmsspNegotiate(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
+#line 624 "ldap.cnf"
+       /* make sure the protocol op comes first */
+               ldap_do_protocolop(pinfo);
+
+       call_dissector(ntlmssp_handle, tvb, pinfo, tree);
+       offset+=tvb_length_remaining(tvb, offset);
+
+
+
+  return offset;
+}
+static int dissect_ntlmsspNegotiate_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
+  return dissect_ldap_T_ntlmsspNegotiate(TRUE, tvb, offset, pinfo, tree, hf_ldap_ntlmsspNegotiate);
+}
+
+
+
+static int
+dissect_ldap_T_ntlmsspAuth(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
+#line 631 "ldap.cnf"
+       /* make sure the protocol op comes first */
+               ldap_do_protocolop(pinfo);
+
+       call_dissector(ntlmssp_handle, tvb, pinfo, tree);
+       offset+=tvb_length_remaining(tvb, offset);
+
+
+
+  return offset;
+}
+static int dissect_ntlmsspAuth_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
+  return dissect_ldap_T_ntlmsspAuth(TRUE, tvb, offset, pinfo, tree, hf_ldap_ntlmsspAuth);
+}
+
+
 static const value_string ldap_AuthenticationChoice_vals[] = {
   {   0, "simple" },
   {   3, "sasl" },
+  {  10, "ntlmsspNegotiate" },
+  {  11, "ntlmsspAuth" },
   { 0, NULL }
 };
 
 static const ber_choice_t AuthenticationChoice_choice[] = {
   {   0, BER_CLASS_CON, 0, BER_FLAGS_IMPLTAG, dissect_simple_impl },
   {   3, BER_CLASS_CON, 3, BER_FLAGS_IMPLTAG, dissect_sasl_impl },
+  {  10, BER_CLASS_CON, 10, BER_FLAGS_IMPLTAG, dissect_ntlmsspNegotiate_impl },
+  {  11, BER_CLASS_CON, 11, BER_FLAGS_IMPLTAG, dissect_ntlmsspAuth_impl },
   { 0, 0, 0, 0, NULL }
 };
 
 static int
 dissect_ldap_AuthenticationChoice(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
-#line 415 "ldap.cnf"
+#line 437 "ldap.cnf"
   gint branch = -1;
   gint auth = -1;
   const gchar *valstr;
@@ -1025,7 +1097,8 @@ dissect_ldap_AuthenticationChoice(gboolean implicit_tag _U_, tvbuff_t *tvb, int
 
   valstr = val_to_str(auth, ldap_AuthenticationChoice_vals, "Unknown auth(%u)");
   
-  if (check_col(pinfo->cinfo, COL_INFO))
+  /* If auth is NTLM (10 or 11) don't add to column as the NTLM dissection will do this */
+  if (check_col(pinfo->cinfo, COL_INFO) && (auth !=  10) && (auth != 11))
     col_append_fstr(pinfo->cinfo, COL_INFO, "%s ", valstr);
   
   if(ldm_tree)
@@ -1106,7 +1179,7 @@ static const value_string ldap_BindResponse_resultCode_vals[] = {
 
 static int
 dissect_ldap_BindResponse_resultCode(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
-#line 357 "ldap.cnf"
+#line 379 "ldap.cnf"
 
   const gchar *valstr;
 
@@ -1139,6 +1212,34 @@ static int dissect_bindResponse_resultCode(packet_info *pinfo, proto_tree *tree,
 
 
 
+static int
+dissect_ldap_T_matchedDN(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
+#line 638 "ldap.cnf"
+       tvbuff_t *new_tvb=NULL;
+
+       offset = dissect_ber_octet_string(FALSE, pinfo, tree, tvb, offset, hf_ldap_matchedDN, &new_tvb);
+
+       if(  new_tvb
+       &&  (tvb_length(new_tvb)>=7)
+       &&  (!tvb_memeql(new_tvb, 0, "NTLMSSP", 7))){
+
+               /* make sure the protocol op comes first */
+               ldap_do_protocolop(pinfo);
+
+               call_dissector(ntlmssp_handle, new_tvb, pinfo, tree);
+       }
+       return offset;
+
+
+
+  return offset;
+}
+static int dissect_matchedDN1(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
+  return dissect_ldap_T_matchedDN(FALSE, tvb, offset, pinfo, tree, hf_ldap_matchedDN1);
+}
+
+
+
 static int
 dissect_ldap_ErrorMessage(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
   offset = dissect_ldap_LDAPString(implicit_tag, tvb, offset, pinfo, tree, hf_index);
@@ -1153,7 +1254,12 @@ static int dissect_errorMessage(packet_info *pinfo, proto_tree *tree, tvbuff_t *
 
 static int
 dissect_ldap_LDAPURL(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
-  offset = dissect_ldap_LDAPString(implicit_tag, tvb, offset, pinfo, tree, hf_index);
+  offset = dissect_ber_octet_string(implicit_tag, pinfo, tree, tvb, offset, hf_index,
+                                       NULL);
+
+#line 38 "ldap.cnf"
+       PROTO_ITEM_SET_URL(get_ber_last_created_item());
+
 
   return offset;
 }
@@ -1184,7 +1290,7 @@ static int dissect_referral_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t
 
 static int
 dissect_ldap_ServerSaslCreds(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
-#line 179 "ldap.cnf"
+#line 194 "ldap.cnf"
 
 tvbuff_t       *parameter_tvb;
 ldap_conv_info_t *ldap_info;
@@ -1256,7 +1362,7 @@ static int dissect_serverSaslCreds_impl(packet_info *pinfo, proto_tree *tree, tv
 
 static const ber_sequence_t BindResponse_sequence[] = {
   { BER_CLASS_UNI, BER_UNI_TAG_ENUMERATED, BER_FLAGS_NOOWNTAG, dissect_bindResponse_resultCode },
-  { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_matchedDN },
+  { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_matchedDN1 },
   { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_errorMessage },
   { BER_CLASS_CON, 3, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_referral_impl },
   { BER_CLASS_CON, 7, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_serverSaslCreds_impl },
@@ -1278,7 +1384,7 @@ static int dissect_bindResponse(packet_info *pinfo, proto_tree *tree, tvbuff_t *
 
 static int
 dissect_ldap_UnbindRequest(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
-#line 436 "ldap.cnf"
+#line 459 "ldap.cnf"
 
  implicit_tag = TRUE; /* correct problem with asn2wrs */
 
@@ -1310,7 +1416,7 @@ static const value_string ldap_T_scope_vals[] = {
 
 static int
 dissect_ldap_T_scope(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
-#line 316 "ldap.cnf"
+#line 338 "ldap.cnf"
 
   gint         scope;
   const gchar *valstr;
@@ -1378,7 +1484,7 @@ static int dissect_timeLimit(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb
 
 static int
 dissect_ldap_BOOLEAN(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
-#line 529 "ldap.cnf"
+#line 552 "ldap.cnf"
        gboolean val;
 
        offset = dissect_ber_boolean_value(implicit_tag, pinfo, tree, tvb, offset, hf_index, &val);
@@ -1403,6 +1509,9 @@ static int dissect_dnAttributes_impl(packet_info *pinfo, proto_tree *tree, tvbuf
 static int dissect_deleteoldrdn(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
   return dissect_ldap_BOOLEAN(FALSE, tvb, offset, pinfo, tree, hf_ldap_deleteoldrdn);
 }
+static int dissect_reverseOrder_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
+  return dissect_ldap_BOOLEAN(TRUE, tvb, offset, pinfo, tree, hf_ldap_reverseOrder);
+}
 
 
 
@@ -1410,7 +1519,7 @@ static int
 dissect_ldap_T_and_item(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
   offset = dissect_ldap_Filter(implicit_tag, tvb, offset, pinfo, tree, hf_index);
 
-#line 470 "ldap.cnf"
+#line 493 "ldap.cnf"
        if(and_filter_string){
                and_filter_string=ep_strdup_printf("(&%s%s)",and_filter_string,Filter_string);
        } else {
@@ -1431,7 +1540,7 @@ static const ber_sequence_t T_and_set_of[1] = {
 
 static int
 dissect_ldap_T_and(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
-#line 477 "ldap.cnf"
+#line 500 "ldap.cnf"
        const ber_sequence_t and_set_of[1] = {  { BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_and_item },
 };
        proto_tree *tr=NULL;
@@ -1464,7 +1573,7 @@ static int
 dissect_ldap_T_or_item(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
   offset = dissect_ldap_Filter(implicit_tag, tvb, offset, pinfo, tree, hf_index);
 
-#line 496 "ldap.cnf"
+#line 519 "ldap.cnf"
        if(or_filter_string){
                or_filter_string=ep_strdup_printf("(|%s%s)",or_filter_string,Filter_string);
        } else {
@@ -1486,7 +1595,7 @@ static const ber_sequence_t T_or_set_of[1] = {
 
 static int
 dissect_ldap_T_or(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
-#line 504 "ldap.cnf"
+#line 527 "ldap.cnf"
        const ber_sequence_t or_set_of[1] = {  { BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_or_item },
 };
        proto_tree *tr=NULL;
@@ -1519,7 +1628,7 @@ static int
 dissect_ldap_T_not(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
   offset = dissect_ldap_Filter(implicit_tag, tvb, offset, pinfo, tree, hf_index);
 
-#line 526 "ldap.cnf"
+#line 549 "ldap.cnf"
        Filter_string=ep_strdup_printf("(!%s)",Filter_string);
 
 
@@ -1549,6 +1658,12 @@ static int dissect_type(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int
 static int dissect_type_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
   return dissect_ldap_AttributeDescription(TRUE, tvb, offset, pinfo, tree, hf_ldap_type);
 }
+static int dissect_attributeType(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
+  return dissect_ldap_AttributeDescription(FALSE, tvb, offset, pinfo, tree, hf_ldap_attributeType);
+}
+static int dissect_attributeType_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
+  return dissect_ldap_AttributeDescription(TRUE, tvb, offset, pinfo, tree, hf_ldap_attributeType);
+}
 
 static int dissect_assertionValue(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
   return dissect_ldap_AssertionValue(FALSE, tvb, offset, pinfo, tree, hf_ldap_assertionValue);
@@ -1581,7 +1696,7 @@ static int
 dissect_ldap_T_equalityMatch(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
   offset = dissect_ldap_AttributeValueAssertion(implicit_tag, tvb, offset, pinfo, tree, hf_index);
 
-#line 455 "ldap.cnf"
+#line 478 "ldap.cnf"
        Filter_string=ep_strdup_printf("(%s=%s)",attributedesc_string,ldapvalue_string);
 
 
@@ -1613,7 +1728,7 @@ dissect_ldap_T_substringFilter_substrings_item(gboolean implicit_tag _U_, tvbuff
                                  T_substringFilter_substrings_item_choice, hf_index, ett_ldap_T_substringFilter_substrings_item,
                                  NULL);
 
-#line 552 "ldap.cnf"
+#line 575 "ldap.cnf"
        if (substring_item_final) {
                substring_value=ep_strdup_printf("%s%s",
                                                 (substring_value?substring_value:"*"),
@@ -1659,7 +1774,7 @@ static const ber_sequence_t SubstringFilter_sequence[] = {
 
 static int
 dissect_ldap_SubstringFilter(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
-#line 566 "ldap.cnf"
+#line 589 "ldap.cnf"
        proto_tree *tr=NULL;
        proto_item *it=NULL;
        char *old_substring_value=substring_value;
@@ -1694,7 +1809,7 @@ static int
 dissect_ldap_T_greaterOrEqual(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
   offset = dissect_ldap_AttributeValueAssertion(implicit_tag, tvb, offset, pinfo, tree, hf_index);
 
-#line 459 "ldap.cnf"
+#line 482 "ldap.cnf"
        Filter_string=ep_strdup_printf("(%s>=%s)",attributedesc_string,ldapvalue_string);
 
 
@@ -1711,7 +1826,7 @@ static int
 dissect_ldap_T_lessOrEqual(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
   offset = dissect_ldap_AttributeValueAssertion(implicit_tag, tvb, offset, pinfo, tree, hf_index);
 
-#line 463 "ldap.cnf"
+#line 486 "ldap.cnf"
        Filter_string=ep_strdup_printf("(%s<=%s)",attributedesc_string,ldapvalue_string);
 
 
@@ -1728,7 +1843,7 @@ static int
 dissect_ldap_T_present(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
   offset = dissect_ldap_AttributeDescription(implicit_tag, tvb, offset, pinfo, tree, hf_index);
 
-#line 523 "ldap.cnf"
+#line 546 "ldap.cnf"
        Filter_string=ep_strdup_printf("(%s=*)",Filter_string);
 
 
@@ -1744,7 +1859,7 @@ static int
 dissect_ldap_T_approxMatch(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
   offset = dissect_ldap_AttributeValueAssertion(implicit_tag, tvb, offset, pinfo, tree, hf_index);
 
-#line 467 "ldap.cnf"
+#line 490 "ldap.cnf"
        Filter_string=ep_strdup_printf("(%s~=%s)",attributedesc_string,ldapvalue_string);
 
 
@@ -1765,6 +1880,9 @@ dissect_ldap_MatchingRuleId(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset
 static int dissect_matchingRule_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
   return dissect_ldap_MatchingRuleId(TRUE, tvb, offset, pinfo, tree, hf_ldap_matchingRule);
 }
+static int dissect_orderingRule_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
+  return dissect_ldap_MatchingRuleId(TRUE, tvb, offset, pinfo, tree, hf_ldap_orderingRule);
+}
 
 
 static const ber_sequence_t MatchingRuleAssertion_sequence[] = {
@@ -1787,7 +1905,7 @@ dissect_ldap_MatchingRuleAssertion(gboolean implicit_tag _U_, tvbuff_t *tvb, int
 
 static int
 dissect_ldap_T_extensibleMatch(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
-#line 538 "ldap.cnf"
+#line 561 "ldap.cnf"
        attr_type=NULL;
        matching_rule_string=NULL;
        ldapvalue_string=NULL;
@@ -1796,7 +1914,7 @@ dissect_ldap_T_extensibleMatch(gboolean implicit_tag _U_, tvbuff_t *tvb, int off
 
   offset = dissect_ldap_MatchingRuleAssertion(implicit_tag, tvb, offset, pinfo, tree, hf_index);
 
-#line 544 "ldap.cnf"
+#line 567 "ldap.cnf"
        Filter_string=ep_strdup_printf("(%s:%s%s%s=%s)",
                                        (attr_type?attr_type:""),
                                        (matching_rule_dnattr?"dn:":""),
@@ -1842,7 +1960,7 @@ static const ber_choice_t Filter_choice[] = {
 
 static int
 dissect_ldap_Filter(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
-#line 587 "ldap.cnf"
+#line 610 "ldap.cnf"
        proto_tree *tr=NULL;
        proto_item *it=NULL;
 
@@ -1865,13 +1983,13 @@ dissect_ldap_Filter(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet
 
 static int
 dissect_ldap_T_filter(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
-#line 448 "ldap.cnf"
+#line 471 "ldap.cnf"
        Filter_string=NULL;
 
 
   offset = dissect_ldap_Filter(implicit_tag, tvb, offset, pinfo, tree, hf_index);
 
-#line 451 "ldap.cnf"
+#line 474 "ldap.cnf"
        Filter_string=NULL;
        and_filter_string=NULL;
 
@@ -1926,7 +2044,7 @@ static int dissect_searchRequest(packet_info *pinfo, proto_tree *tree, tvbuff_t
 
 static int
 dissect_ldap_AttributeValue(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
-#line 378 "ldap.cnf"
+#line 400 "ldap.cnf"
 
   tvbuff_t     *next_tvb;
   gchar                *string;
@@ -2086,7 +2204,7 @@ static const value_string ldap_T_resultCode_vals[] = {
 
 static int
 dissect_ldap_T_resultCode(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
-#line 335 "ldap.cnf"
+#line 357 "ldap.cnf"
 
   const gchar *valstr;
 
@@ -2441,23 +2559,29 @@ static int dissect_abandonRequest(packet_info *pinfo, proto_tree *tree, tvbuff_t
 
 static int
 dissect_ldap_LDAPOID(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
-#line 33 "ldap.cnf"
+#line 42 "ldap.cnf"
 
        tvbuff_t        *parameter_tvb;
        const gchar *name;
        proto_item      *item = NULL;
 
 
-
   offset = dissect_ber_octet_string(implicit_tag, pinfo, tree, tvb, offset, hf_index,
                                        &parameter_tvb);
 
-#line 40 "ldap.cnf"
+#line 48 "ldap.cnf"
+       
+       object_identifier_id = NULL;
+
        if (!parameter_tvb)
                return offset;
-       item = get_ber_last_created_item();
-       name = get_oid_str_name(tvb_get_string(parameter_tvb, 0, tvb_length_remaining(parameter_tvb,0)));
+
+       object_identifier_id = tvb_get_string(parameter_tvb, 0, tvb_length_remaining(parameter_tvb,0));
+       name = get_oid_str_name(object_identifier_id);
+
        if(name){
+               item = get_ber_last_created_item();
+
                proto_item_append_text(item, " (%s)", name);
                proto_item_append_text(tree, " %s", name);      
        }
@@ -2479,15 +2603,15 @@ dissect_ldap_OCTET_STRING(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset,
 
   return offset;
 }
-static int dissect_controlValue(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
-  return dissect_ldap_OCTET_STRING(FALSE, tvb, offset, pinfo, tree, hf_ldap_controlValue);
-}
 static int dissect_requestValue_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
   return dissect_ldap_OCTET_STRING(TRUE, tvb, offset, pinfo, tree, hf_ldap_requestValue);
 }
 static int dissect_response_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
   return dissect_ldap_OCTET_STRING(TRUE, tvb, offset, pinfo, tree, hf_ldap_response);
 }
+static int dissect_cookie(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
+  return dissect_ldap_OCTET_STRING(FALSE, tvb, offset, pinfo, tree, hf_ldap_cookie);
+}
 
 
 static const ber_sequence_t ExtendedRequest_sequence[] = {
@@ -2648,7 +2772,7 @@ static const ber_choice_t ProtocolOp_choice[] = {
 
 static int
 dissect_ldap_ProtocolOp(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
-#line 61 "ldap.cnf"
+#line 76 "ldap.cnf"
 
   ldap_call_response_t *lcrp;
   ldap_conv_info_t *ldap_info = (ldap_conv_info_t *)pinfo->private_data;
@@ -2659,7 +2783,7 @@ dissect_ldap_ProtocolOp(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, pa
                                  ProtocolOp_choice, hf_index, ett_ldap_ProtocolOp,
                                  &ProtocolOp);
 
-#line 67 "ldap.cnf"
+#line 82 "ldap.cnf"
 
   lcrp=ldap_match_call_response(tvb, pinfo, tree, MessageID, ProtocolOp);
   if(lcrp){
@@ -2715,6 +2839,38 @@ static int dissect_controlType(packet_info *pinfo, proto_tree *tree, tvbuff_t *t
 }
 
 
+
+static int
+dissect_ldap_T_controlValue(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
+#line 654 "ldap.cnf"
+       gint8 class;
+       gboolean pc, ind;
+       gint32 tag;
+       guint32 len;
+       
+       if((object_identifier_id != NULL) && oid_has_dissector(object_identifier_id)) {
+               /* remove the OCTET STRING encoding */          
+               offset=dissect_ber_identifier(pinfo, NULL, tvb, offset, &class, &pc, &tag);
+               offset=dissect_ber_length(pinfo, NULL, tvb, offset, &len, &ind);
+
+               call_ber_oid_callback(object_identifier_id, tvb, offset, pinfo, tree);
+
+               offset += len;
+       } else {
+                 offset = dissect_ber_octet_string(implicit_tag, pinfo, tree, tvb, offset, hf_index,
+                                       NULL);
+
+       }
+
+
+
+  return offset;
+}
+static int dissect_controlValue(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
+  return dissect_ldap_T_controlValue(FALSE, tvb, offset, pinfo, tree, hf_ldap_controlValue);
+}
+
+
 static const ber_sequence_t Control_sequence[] = {
   { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_controlType },
   { BER_CLASS_UNI, BER_UNI_TAG_BOOLEAN, BER_FLAGS_OPTIONAL|BER_FLAGS_NOOWNTAG, dissect_criticality },
@@ -2767,15 +2923,152 @@ dissect_ldap_LDAPMessage(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, p
 
 
 
+
+
+static int
+dissect_ldap_INTEGER(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
+  offset = dissect_ber_integer(implicit_tag, pinfo, tree, tvb, offset, hf_index,
+                                  NULL);
+
+  return offset;
+}
+static int dissect_size(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
+  return dissect_ldap_INTEGER(FALSE, tvb, offset, pinfo, tree, hf_ldap_size);
+}
+static int dissect_parentsFirst(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
+  return dissect_ldap_INTEGER(FALSE, tvb, offset, pinfo, tree, hf_ldap_parentsFirst);
+}
+static int dissect_maxReturnLength(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
+  return dissect_ldap_INTEGER(FALSE, tvb, offset, pinfo, tree, hf_ldap_maxReturnLength);
+}
+
+
+static const ber_sequence_t SearchControlValue_sequence[] = {
+  { BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_size },
+  { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_cookie },
+  { 0, 0, 0, NULL }
+};
+
+static int
+dissect_ldap_SearchControlValue(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
+  offset = dissect_ber_sequence(implicit_tag, pinfo, tree, tvb, offset,
+                                   SearchControlValue_sequence, hf_index, ett_ldap_SearchControlValue);
+
+  return offset;
+}
+
+
+static const ber_sequence_t SortKeyList_item_sequence[] = {
+  { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_attributeType },
+  { BER_CLASS_CON, 0, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_orderingRule_impl },
+  { BER_CLASS_CON, 1, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_reverseOrder_impl },
+  { 0, 0, 0, NULL }
+};
+
+static int
+dissect_ldap_SortKeyList_item(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
+  offset = dissect_ber_sequence(implicit_tag, pinfo, tree, tvb, offset,
+                                   SortKeyList_item_sequence, hf_index, ett_ldap_SortKeyList_item);
+
+  return offset;
+}
+static int dissect_SortKeyList_item(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
+  return dissect_ldap_SortKeyList_item(FALSE, tvb, offset, pinfo, tree, hf_ldap_SortKeyList_item);
+}
+
+
+static const ber_sequence_t SortKeyList_sequence_of[1] = {
+  { BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_SortKeyList_item },
+};
+
+static int
+dissect_ldap_SortKeyList(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
+  offset = dissect_ber_sequence_of(implicit_tag, pinfo, tree, tvb, offset,
+                                      SortKeyList_sequence_of, hf_index, ett_ldap_SortKeyList);
+
+  return offset;
+}
+
+
+static const value_string ldap_T_sortResult_vals[] = {
+  {   0, "success" },
+  {   1, "operationsError" },
+  {   3, "timeLimitExceeded" },
+  {   8, "strongAuthRequired" },
+  {  11, "adminLimitExceeded" },
+  {  16, "noSuchAttribute" },
+  {  18, "inappropriateMatching" },
+  {  50, "insufficientAccessRights" },
+  {  51, "busy" },
+  {  53, "unwillingToPerform" },
+  {  80, "other" },
+  { 0, NULL }
+};
+
+
+static int
+dissect_ldap_T_sortResult(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
+  offset = dissect_ber_integer(implicit_tag, pinfo, tree, tvb, offset, hf_index,
+                                  NULL);
+
+  return offset;
+}
+static int dissect_sortResult(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
+  return dissect_ldap_T_sortResult(FALSE, tvb, offset, pinfo, tree, hf_ldap_sortResult);
+}
+
+
+static const ber_sequence_t SortResult_sequence[] = {
+  { BER_CLASS_UNI, BER_UNI_TAG_ENUMERATED, BER_FLAGS_NOOWNTAG, dissect_sortResult },
+  { BER_CLASS_CON, 0, BER_FLAGS_OPTIONAL|BER_FLAGS_IMPLTAG, dissect_attributeType_impl },
+  { 0, 0, 0, NULL }
+};
+
+static int
+dissect_ldap_SortResult(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
+  offset = dissect_ber_sequence(implicit_tag, pinfo, tree, tvb, offset,
+                                   SortResult_sequence, hf_index, ett_ldap_SortResult);
+
+  return offset;
+}
+
+
+static const ber_sequence_t ReplControlValue_sequence[] = {
+  { BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_parentsFirst },
+  { BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_maxReturnLength },
+  { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_cookie },
+  { 0, 0, 0, NULL }
+};
+
+static int
+dissect_ldap_ReplControlValue(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
+  offset = dissect_ber_sequence(implicit_tag, pinfo, tree, tvb, offset,
+                                   ReplControlValue_sequence, hf_index, ett_ldap_ReplControlValue);
+
+  return offset;
+}
+
 /*--- PDUs ---*/
 
 static void dissect_LDAPMessage_PDU(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
   dissect_ldap_LDAPMessage(FALSE, tvb, 0, pinfo, tree, hf_ldap_LDAPMessage_PDU);
 }
+static void dissect_SearchControlValue_PDU(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
+  dissect_ldap_SearchControlValue(FALSE, tvb, 0, pinfo, tree, hf_ldap_SearchControlValue_PDU);
+}
+static void dissect_SortKeyList_PDU(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
+  dissect_ldap_SortKeyList(FALSE, tvb, 0, pinfo, tree, hf_ldap_SortKeyList_PDU);
+}
+static void dissect_SortResult_PDU(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
+  dissect_ldap_SortResult(FALSE, tvb, 0, pinfo, tree, hf_ldap_SortResult_PDU);
+}
+static void dissect_ReplControlValue_PDU(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
+  dissect_ldap_ReplControlValue(FALSE, tvb, 0, pinfo, tree, hf_ldap_ReplControlValue_PDU);
+}
 
 
 /*--- End of included file: packet-ldap-fn.c ---*/
-#line 540 "packet-ldap-template.c"
+#line 542 "packet-ldap-template.c"
 
 static void
 dissect_ldap_payload(tvbuff_t *tvb, packet_info *pinfo,
@@ -2783,7 +3076,6 @@ dissect_ldap_payload(tvbuff_t *tvb, packet_info *pinfo,
                     gboolean rest_is_pad, gboolean is_mscldap)
 {
   int offset = 0;
-  gboolean first_time = TRUE;
   guint length_remaining;
   guint msg_len = 0;
   int messageOffset = 0;
@@ -2794,12 +3086,6 @@ dissect_ldap_payload(tvbuff_t *tvb, packet_info *pinfo,
   gboolean pc, ind = 0;
   gint32 ber_tag;
 
-  while (tvb_reported_length_remaining(tvb, offset) > 0) {
-    /*
-     * This will throw an exception if we don't have any data left.
-     * That's what we want.  (See "tcp_dissect_pdus()", which is
-     * similar)
-     */
     length_remaining = tvb_ensure_length_remaining(tvb, offset);
 
     if (rest_is_pad && length_remaining < 6) return;
@@ -2860,8 +3146,6 @@ dissect_ldap_payload(tvbuff_t *tvb, packet_info *pinfo,
      * Now dissect the LDAP message.
      */
 
-    /*dissect_ldap_message(msg_tvb, 0, pinfo, msg_tree, msg_item, first_time, ldap_info, is_mscldap);*/
-       ldap_info->first_time= first_time;
        ldap_info->is_mscldap = is_mscldap;
        pinfo->private_data = ldap_info;
        dissect_LDAPMessage_PDU(msg_tvb, pinfo, tree);
@@ -2869,8 +3153,6 @@ dissect_ldap_payload(tvbuff_t *tvb, packet_info *pinfo,
 
     offset += msg_len;
 
-    first_time = FALSE;
-  }
 }
 
 static void
@@ -2934,17 +3216,6 @@ dissect_ldap_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gboolean i
     }
   }
 
-  while (tvb_reported_length_remaining(tvb, offset) > 0) {
-
-    /*
-     * This will throw an exception if we don't have any data left.
-     * That's what we want.  (See "tcp_dissect_pdus()", which is
-     * similar, but doesn't have to deal with the SASL issues.
-     * XXX - can we make "tcp_dissect_pdus()" provide enough information
-     * to the "get_pdu_len" routine so that we could have one dealing
-     * with the SASL issues, have that routine deal with SASL and
-     * ASN.1, and just use "tcp_dissect_pdus()"?)
-     */
     length_remaining = tvb_ensure_length_remaining(tvb, offset);
 
     /* It might still be a packet containing a SASL security layer
@@ -3153,10 +3424,7 @@ dissect_ldap_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gboolean i
     } else {
        /* plain LDAP, so dissect the payload */
        dissect_ldap_payload(tvb, pinfo, ldap_tree, ldap_info, FALSE, is_mscldap);
-       /* dissect_ldap_payload() has it's own loop so go out here */
-       break;
     }
-  }
 }
 
 static int dissect_mscldap_string(tvbuff_t *tvb, int offset, char *str, int maxlen, gboolean prepend_dot)
@@ -3390,7 +3658,7 @@ static void dissect_NetLogon_PDU(tvbuff_t *tvb, packet_info *pinfo, proto_tree *
 
 
 static guint
-get_sasl_ldap_pdu_len(tvbuff_t *tvb, int offset)
+get_sasl_ldap_pdu_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset)
 {
        /* sasl encapsulated ldap is 4 bytes plus the length in size */
        return tvb_get_ntohl(tvb, offset)+4;
@@ -3404,18 +3672,18 @@ dissect_sasl_ldap_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 }
 
 static guint
-get_normal_ldap_pdu_len(tvbuff_t *tvb, int offset)
+get_normal_ldap_pdu_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset)
 {
        guint32 len;
        gboolean ind;
        int data_offset;
 
        /* normal ldap is tag+len bytes plus the length
-        * offset==0 is where the tag is
-        * offset==1 is where length starts
+        * offset is where the tag is
+        * offset+1 is where length starts
         */
-       data_offset=get_ber_length(NULL, tvb, 1, &len, &ind);
-       return len+data_offset;
+       data_offset=get_ber_length(NULL, tvb, offset+1, &len, &ind);
+       return len+data_offset-offset;
 }
 
 static void
@@ -3428,7 +3696,8 @@ dissect_normal_ldap_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 static void
 dissect_ldap_oid(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 {
-       char *oid, *oidname;
+       char *oid;
+       const char *oidname;
 
        /* tvb here contains an ascii string that is really an oid */
 /* XXX   we should convert the string oid into a real oid so we can use
@@ -3537,8 +3806,7 @@ dissect_ldap_sid(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 
        /* this octet string contains an NT SID */
        dissect_nt_sid(tvb, 0, tree, "SID", &tmpstr, hf_ldap_sid);
-       ldapvalue_string=ep_strdup(tmpstr);
-       g_free(tmpstr);
+       ldapvalue_string=tmpstr;
 }
 
 static void
@@ -3560,71 +3828,83 @@ dissect_ldap_guid(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 }
 
 static void
-dissect_ldap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
+dissect_ldap_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 {
+       guint32 sasl_len;
+       guint32 gss_len;
+       guint32 ldap_len;
+       int offset;
+       gboolean ind;
+
         ldm_tree = NULL;
 
-       /* Here we must take care of reassembly but this is tricky since
-        * depending on whether SASL is present or not, the heuristics
-        * will be very different.
+       /* This is a bit tricky. We have to find out whether SASL is used
+        * so that we know how big a header we are supposed to pass
+        * to tcp_dissect_pdus()
         */
-       if(ldap_desegment && (tvb_length(tvb)==tvb_reported_length(tvb))){
-               guint32 len;
-
-               /* check for a SASL header, i.e. four byte integer where the
-                * first two bytes are 0x00 and the value is <64k and >2
-                * (>2 to fight false positives, 0x00000000 is a common
-                *     "random" tcp payload)
-                * (no SASL ldap PDUs are ever going to be >64k in size?)
-                *
-                * Following the SASL header is a GSSAPI blob so the next byte
-                * is always 0x60. (only true for MS SASL LDAP, there are other
-                * blobs that may follow in real-world)
-                */
-               len=tvb_get_ntohl(tvb, 0);
-               if( (len<65535)
-               &&  (len>2)
-               &&  (tvb_get_guint8(tvb, 4)==0x60)){
-                       if(len<=tvb_length_remaining(tvb, 4)){
-                               /* we have a full ldap pdu */
-                               dissect_ldap_pdu(tvb, pinfo, tree, FALSE);
-                               return;
-                       } else {
-                               /* we have to do reassembly */
-                               tcp_dissect_pdus(tvb, pinfo, tree, ldap_desegment, 4, get_sasl_ldap_pdu_len, dissect_sasl_ldap_pdu);
-                               return;
-                       }
-               }
-               /* check if it is a normal BER encoded LDAP packet
-                * i.e. first byte is 0x30 followed by a length that is
-                * <64k
-                * (no ldap PDUs are ever >64kb? )
-                */
-               if(tvb_get_guint8(tvb, 0)==0x30){
-                       gboolean ind;
-                       int data_offset;
-
-                       /* check that length makes sense */
-                       data_offset=get_ber_length(NULL, tvb, 1, &len, &ind);
-
-                       /* dont check ind since indefinite length is never used for ldap (famous last words)*/
-                       if(len<2 || len>65535){
-                               return;
-                       }
-
-                       if(len<=tvb_length_remaining(tvb, data_offset)){
-                               /* we have a full ldap pdu */
-                               dissect_ldap_pdu(tvb, pinfo, tree, FALSE);
-                               return;
-                       } else {
-                               /* we have to do reassembly */
-                               tcp_dissect_pdus(tvb, pinfo, tree, ldap_desegment, 4, get_normal_ldap_pdu_len, dissect_normal_ldap_pdu);
-                               return;
-                       }
-               }
+       /* check for a SASL header, i.e. assume it is SASL if 
+        * 1, first four bytes (SASL length) is an integer 
+        *    with a value that must be <64k and >2
+        *    (>2 to fight false positives, 0x00000000 is a common
+        *        "random" tcp payload)
+        * (no SASL ldap PDUs are ever going to be >64k in size?)
+        *
+        * Following the SASL header is a GSSAPI blob so the next byte
+        * is always 0x60. (only true for MS SASL LDAP, there are other
+        * blobs that may follow in real-world)
+        *
+        * 2, Then one byte with the value 0x60 indicating the GSSAPI blob
+        *
+        * 3, Then X bytes describing the BER encoded lengtyh of the blob.
+        *    This length should point to the same end-of-pdu as 1,
+        *
+        * 4, finally a byte 0x06 indicating that the next object is an OID
+        */
+       sasl_len=tvb_get_ntohl(tvb, 0);
+       if( sasl_len<2 ){
+               goto this_was_not_sasl;
        }
 
-       dissect_ldap_pdu(tvb, pinfo, tree, FALSE);
+       if(tvb_get_guint8(tvb, 4)!=0x60){
+               goto this_was_not_sasl;
+       }
+               
+       offset=get_ber_length(NULL, tvb, 5, &gss_len, &ind);
+       if(sasl_len!=(gss_len+offset-4)){
+               goto this_was_not_sasl;
+       }
+
+       if(tvb_get_guint8(tvb, offset)!=0x06){
+               goto this_was_not_sasl;
+       }
+
+       tcp_dissect_pdus(tvb, pinfo, tree, ldap_desegment, 4, get_sasl_ldap_pdu_len, dissect_sasl_ldap_pdu);
+
+
+this_was_not_sasl:
+       /* check if it is a normal BER encoded LDAP packet
+        * i.e. first byte is 0x30 followed by a length that is
+        * <64k
+        * (no ldap PDUs are ever >64kb? )
+        */
+       if(tvb_get_guint8(tvb, 0)!=0x30){
+               goto this_was_not_normal_ldap;
+       }
+
+       /* check that length makes sense */
+       offset=get_ber_length(NULL, tvb, 1, &ldap_len, &ind);
+
+       /* dont check ind since indefinite length is never used for ldap (famous last words)*/
+       if(ldap_len<2){
+               goto this_was_not_normal_ldap;
+       }
+
+       tcp_dissect_pdus(tvb, pinfo, tree, ldap_desegment, 4, get_normal_ldap_pdu_len, dissect_normal_ldap_pdu);
+
+
+this_was_not_normal_ldap:
+
        return;
 }
 
@@ -3849,394 +4129,458 @@ void proto_register_ldap(void) {
     { &hf_ldap_LDAPMessage_PDU,
       { "LDAPMessage", "ldap.LDAPMessage",
         FT_NONE, BASE_NONE, NULL, 0,
-        "LDAPMessage", HFILL }},
+        "ldap.LDAPMessage", HFILL }},
+    { &hf_ldap_SearchControlValue_PDU,
+      { "SearchControlValue", "ldap.SearchControlValue",
+        FT_NONE, BASE_NONE, NULL, 0,
+        "ldap.SearchControlValue", HFILL }},
+    { &hf_ldap_SortKeyList_PDU,
+      { "SortKeyList", "ldap.SortKeyList",
+        FT_UINT32, BASE_DEC, NULL, 0,
+        "ldap.SortKeyList", HFILL }},
+    { &hf_ldap_SortResult_PDU,
+      { "SortResult", "ldap.SortResult",
+        FT_NONE, BASE_NONE, NULL, 0,
+        "ldap.SortResult", HFILL }},
+    { &hf_ldap_ReplControlValue_PDU,
+      { "ReplControlValue", "ldap.ReplControlValue",
+        FT_NONE, BASE_NONE, NULL, 0,
+        "ldap.ReplControlValue", HFILL }},
     { &hf_ldap_messageID,
       { "messageID", "ldap.messageID",
         FT_UINT32, BASE_DEC, NULL, 0,
-        "LDAPMessage/messageID", HFILL }},
+        "ldap.MessageID", HFILL }},
     { &hf_ldap_protocolOp,
       { "protocolOp", "ldap.protocolOp",
         FT_UINT32, BASE_DEC, VALS(ldap_ProtocolOp_vals), 0,
-        "LDAPMessage/protocolOp", HFILL }},
+        "ldap.ProtocolOp", HFILL }},
     { &hf_ldap_controls,
       { "controls", "ldap.controls",
         FT_UINT32, BASE_DEC, NULL, 0,
-        "LDAPMessage/controls", HFILL }},
+        "ldap.Controls", HFILL }},
     { &hf_ldap_bindRequest,
       { "bindRequest", "ldap.bindRequest",
         FT_NONE, BASE_NONE, NULL, 0,
-        "ProtocolOp/bindRequest", HFILL }},
+        "ldap.BindRequest", HFILL }},
     { &hf_ldap_bindResponse,
       { "bindResponse", "ldap.bindResponse",
         FT_NONE, BASE_NONE, NULL, 0,
-        "ProtocolOp/bindResponse", HFILL }},
+        "ldap.BindResponse", HFILL }},
     { &hf_ldap_unbindRequest,
       { "unbindRequest", "ldap.unbindRequest",
         FT_NONE, BASE_NONE, NULL, 0,
-        "ProtocolOp/unbindRequest", HFILL }},
+        "ldap.UnbindRequest", HFILL }},
     { &hf_ldap_searchRequest,
       { "searchRequest", "ldap.searchRequest",
         FT_NONE, BASE_NONE, NULL, 0,
-        "ProtocolOp/searchRequest", HFILL }},
+        "ldap.SearchRequest", HFILL }},
     { &hf_ldap_searchResEntry,
       { "searchResEntry", "ldap.searchResEntry",
         FT_NONE, BASE_NONE, NULL, 0,
-        "ProtocolOp/searchResEntry", HFILL }},
+        "ldap.SearchResultEntry", HFILL }},
     { &hf_ldap_searchResDone,
       { "searchResDone", "ldap.searchResDone",
         FT_NONE, BASE_NONE, NULL, 0,
-        "ProtocolOp/searchResDone", HFILL }},
+        "ldap.SearchResultDone", HFILL }},
     { &hf_ldap_searchResRef,
       { "searchResRef", "ldap.searchResRef",
         FT_UINT32, BASE_DEC, NULL, 0,
-        "ProtocolOp/searchResRef", HFILL }},
+        "ldap.SearchResultReference", HFILL }},
     { &hf_ldap_modifyRequest,
       { "modifyRequest", "ldap.modifyRequest",
         FT_NONE, BASE_NONE, NULL, 0,
-        "ProtocolOp/modifyRequest", HFILL }},
+        "ldap.ModifyRequest", HFILL }},
     { &hf_ldap_modifyResponse,
       { "modifyResponse", "ldap.modifyResponse",
         FT_NONE, BASE_NONE, NULL, 0,
-        "ProtocolOp/modifyResponse", HFILL }},
+        "ldap.ModifyResponse", HFILL }},
     { &hf_ldap_addRequest,
       { "addRequest", "ldap.addRequest",
         FT_NONE, BASE_NONE, NULL, 0,
-        "ProtocolOp/addRequest", HFILL }},
+        "ldap.AddRequest", HFILL }},
     { &hf_ldap_addResponse,
       { "addResponse", "ldap.addResponse",
         FT_NONE, BASE_NONE, NULL, 0,
-        "ProtocolOp/addResponse", HFILL }},
+        "ldap.AddResponse", HFILL }},
     { &hf_ldap_delRequest,
       { "delRequest", "ldap.delRequest",
         FT_STRING, BASE_NONE, NULL, 0,
-        "ProtocolOp/delRequest", HFILL }},
+        "ldap.DelRequest", HFILL }},
     { &hf_ldap_delResponse,
       { "delResponse", "ldap.delResponse",
         FT_NONE, BASE_NONE, NULL, 0,
-        "ProtocolOp/delResponse", HFILL }},
+        "ldap.DelResponse", HFILL }},
     { &hf_ldap_modDNRequest,
       { "modDNRequest", "ldap.modDNRequest",
         FT_NONE, BASE_NONE, NULL, 0,
-        "ProtocolOp/modDNRequest", HFILL }},
+        "ldap.ModifyDNRequest", HFILL }},
     { &hf_ldap_modDNResponse,
       { "modDNResponse", "ldap.modDNResponse",
         FT_NONE, BASE_NONE, NULL, 0,
-        "ProtocolOp/modDNResponse", HFILL }},
+        "ldap.ModifyDNResponse", HFILL }},
     { &hf_ldap_compareRequest,
       { "compareRequest", "ldap.compareRequest",
         FT_NONE, BASE_NONE, NULL, 0,
-        "ProtocolOp/compareRequest", HFILL }},
+        "ldap.CompareRequest", HFILL }},
     { &hf_ldap_compareResponse,
       { "compareResponse", "ldap.compareResponse",
         FT_NONE, BASE_NONE, NULL, 0,
-        "ProtocolOp/compareResponse", HFILL }},
+        "ldap.CompareResponse", HFILL }},
     { &hf_ldap_abandonRequest,
       { "abandonRequest", "ldap.abandonRequest",
         FT_UINT32, BASE_DEC, NULL, 0,
-        "ProtocolOp/abandonRequest", HFILL }},
+        "ldap.AbandonRequest", HFILL }},
     { &hf_ldap_extendedReq,
       { "extendedReq", "ldap.extendedReq",
         FT_NONE, BASE_NONE, NULL, 0,
-        "ProtocolOp/extendedReq", HFILL }},
+        "ldap.ExtendedRequest", HFILL }},
     { &hf_ldap_extendedResp,
       { "extendedResp", "ldap.extendedResp",
         FT_NONE, BASE_NONE, NULL, 0,
-        "ProtocolOp/extendedResp", HFILL }},
+        "ldap.ExtendedResponse", HFILL }},
     { &hf_ldap_AttributeDescriptionList_item,
       { "Item", "ldap.AttributeDescriptionList_item",
         FT_STRING, BASE_NONE, NULL, 0,
-        "AttributeDescriptionList/_item", HFILL }},
+        "ldap.AttributeDescription", HFILL }},
     { &hf_ldap_attributeDesc,
       { "attributeDesc", "ldap.attributeDesc",
         FT_STRING, BASE_NONE, NULL, 0,
-        "AttributeValueAssertion/attributeDesc", HFILL }},
+        "ldap.AttributeDescription", HFILL }},
     { &hf_ldap_assertionValue,
       { "assertionValue", "ldap.assertionValue",
         FT_STRING, BASE_NONE, NULL, 0,
-        "AttributeValueAssertion/assertionValue", HFILL }},
+        "ldap.AssertionValue", HFILL }},
     { &hf_ldap_type,
       { "type", "ldap.type",
         FT_STRING, BASE_NONE, NULL, 0,
-        "", HFILL }},
+        "ldap.AttributeDescription", HFILL }},
     { &hf_ldap_vals,
       { "vals", "ldap.vals",
         FT_UINT32, BASE_DEC, NULL, 0,
-        "", HFILL }},
+        "ldap.SET_OF_AttributeValue", HFILL }},
     { &hf_ldap_vals_item,
       { "Item", "ldap.vals_item",
         FT_BYTES, BASE_HEX, NULL, 0,
-        "", HFILL }},
+        "ldap.AttributeValue", HFILL }},
     { &hf_ldap_resultCode,
       { "resultCode", "ldap.resultCode",
         FT_UINT32, BASE_DEC, VALS(ldap_T_resultCode_vals), 0,
-        "LDAPResult/resultCode", HFILL }},
+        "ldap.T_resultCode", HFILL }},
     { &hf_ldap_matchedDN,
       { "matchedDN", "ldap.matchedDN",
         FT_STRING, BASE_NONE, NULL, 0,
-        "", HFILL }},
+        "ldap.LDAPDN", HFILL }},
     { &hf_ldap_errorMessage,
       { "errorMessage", "ldap.errorMessage",
         FT_STRING, BASE_NONE, NULL, 0,
-        "", HFILL }},
+        "ldap.ErrorMessage", HFILL }},
     { &hf_ldap_referral,
       { "referral", "ldap.referral",
         FT_UINT32, BASE_DEC, NULL, 0,
-        "", HFILL }},
+        "ldap.Referral", HFILL }},
     { &hf_ldap_Referral_item,
       { "Item", "ldap.Referral_item",
         FT_STRING, BASE_NONE, NULL, 0,
-        "Referral/_item", HFILL }},
+        "ldap.LDAPURL", HFILL }},
     { &hf_ldap_Controls_item,
       { "Item", "ldap.Controls_item",
         FT_NONE, BASE_NONE, NULL, 0,
-        "Controls/_item", HFILL }},
+        "ldap.Control", HFILL }},
     { &hf_ldap_controlType,
       { "controlType", "ldap.controlType",
         FT_STRING, BASE_NONE, NULL, 0,
-        "Control/controlType", HFILL }},
+        "ldap.ControlType", HFILL }},
     { &hf_ldap_criticality,
       { "criticality", "ldap.criticality",
         FT_BOOLEAN, 8, NULL, 0,
-        "Control/criticality", HFILL }},
+        "ldap.BOOLEAN", HFILL }},
     { &hf_ldap_controlValue,
       { "controlValue", "ldap.controlValue",
         FT_BYTES, BASE_HEX, NULL, 0,
-        "Control/controlValue", HFILL }},
+        "ldap.T_controlValue", HFILL }},
     { &hf_ldap_version,
       { "version", "ldap.version",
         FT_UINT32, BASE_DEC, NULL, 0,
-        "BindRequest/version", HFILL }},
+        "ldap.INTEGER_1_127", HFILL }},
     { &hf_ldap_name,
       { "name", "ldap.name",
         FT_STRING, BASE_NONE, NULL, 0,
-        "BindRequest/name", HFILL }},
+        "ldap.LDAPDN", HFILL }},
     { &hf_ldap_authentication,
       { "authentication", "ldap.authentication",
         FT_UINT32, BASE_DEC, VALS(ldap_AuthenticationChoice_vals), 0,
-        "BindRequest/authentication", HFILL }},
+        "ldap.AuthenticationChoice", HFILL }},
     { &hf_ldap_simple,
       { "simple", "ldap.simple",
         FT_BYTES, BASE_HEX, NULL, 0,
-        "AuthenticationChoice/simple", HFILL }},
+        "ldap.Simple", HFILL }},
     { &hf_ldap_sasl,
       { "sasl", "ldap.sasl",
         FT_NONE, BASE_NONE, NULL, 0,
-        "AuthenticationChoice/sasl", HFILL }},
+        "ldap.SaslCredentials", HFILL }},
+    { &hf_ldap_ntlmsspNegotiate,
+      { "ntlmsspNegotiate", "ldap.ntlmsspNegotiate",
+        FT_BYTES, BASE_HEX, NULL, 0,
+        "ldap.T_ntlmsspNegotiate", HFILL }},
+    { &hf_ldap_ntlmsspAuth,
+      { "ntlmsspAuth", "ldap.ntlmsspAuth",
+        FT_BYTES, BASE_HEX, NULL, 0,
+        "ldap.T_ntlmsspAuth", HFILL }},
     { &hf_ldap_mechanism,
       { "mechanism", "ldap.mechanism",
         FT_STRING, BASE_NONE, NULL, 0,
-        "SaslCredentials/mechanism", HFILL }},
+        "ldap.Mechanism", HFILL }},
     { &hf_ldap_credentials,
       { "credentials", "ldap.credentials",
         FT_BYTES, BASE_HEX, NULL, 0,
-        "SaslCredentials/credentials", HFILL }},
+        "ldap.Credentials", HFILL }},
     { &hf_ldap_bindResponse_resultCode,
       { "resultCode", "ldap.resultCode",
         FT_UINT32, BASE_DEC, VALS(ldap_BindResponse_resultCode_vals), 0,
-        "BindResponse/resultCode", HFILL }},
+        "ldap.BindResponse_resultCode", HFILL }},
+    { &hf_ldap_matchedDN1,
+      { "matchedDN", "ldap.matchedDN",
+        FT_STRING, BASE_NONE, NULL, 0,
+        "ldap.T_matchedDN", HFILL }},
     { &hf_ldap_serverSaslCreds,
       { "serverSaslCreds", "ldap.serverSaslCreds",
         FT_BYTES, BASE_HEX, NULL, 0,
-        "BindResponse/serverSaslCreds", HFILL }},
+        "ldap.ServerSaslCreds", HFILL }},
     { &hf_ldap_baseObject,
       { "baseObject", "ldap.baseObject",
         FT_STRING, BASE_NONE, NULL, 0,
-        "SearchRequest/baseObject", HFILL }},
+        "ldap.LDAPDN", HFILL }},
     { &hf_ldap_scope,
       { "scope", "ldap.scope",
         FT_UINT32, BASE_DEC, VALS(ldap_T_scope_vals), 0,
-        "SearchRequest/scope", HFILL }},
+        "ldap.T_scope", HFILL }},
     { &hf_ldap_derefAliases,
       { "derefAliases", "ldap.derefAliases",
         FT_UINT32, BASE_DEC, VALS(ldap_T_derefAliases_vals), 0,
-        "SearchRequest/derefAliases", HFILL }},
+        "ldap.T_derefAliases", HFILL }},
     { &hf_ldap_sizeLimit,
       { "sizeLimit", "ldap.sizeLimit",
         FT_UINT32, BASE_DEC, NULL, 0,
-        "SearchRequest/sizeLimit", HFILL }},
+        "ldap.INTEGER_0_maxInt", HFILL }},
     { &hf_ldap_timeLimit,
       { "timeLimit", "ldap.timeLimit",
         FT_UINT32, BASE_DEC, NULL, 0,
-        "SearchRequest/timeLimit", HFILL }},
+        "ldap.INTEGER_0_maxInt", HFILL }},
     { &hf_ldap_typesOnly,
       { "typesOnly", "ldap.typesOnly",
         FT_BOOLEAN, 8, NULL, 0,
-        "SearchRequest/typesOnly", HFILL }},
+        "ldap.BOOLEAN", HFILL }},
     { &hf_ldap_filter,
       { "filter", "ldap.filter",
         FT_UINT32, BASE_DEC, VALS(ldap_Filter_vals), 0,
-        "SearchRequest/filter", HFILL }},
+        "ldap.T_filter", HFILL }},
     { &hf_ldap_searchRequest_attributes,
       { "attributes", "ldap.attributes",
         FT_UINT32, BASE_DEC, NULL, 0,
-        "SearchRequest/attributes", HFILL }},
+        "ldap.AttributeDescriptionList", HFILL }},
     { &hf_ldap_and,
       { "and", "ldap.and",
         FT_UINT32, BASE_DEC, NULL, 0,
-        "Filter/and", HFILL }},
+        "ldap.T_and", HFILL }},
     { &hf_ldap_and_item,
       { "Item", "ldap.and_item",
         FT_UINT32, BASE_DEC, VALS(ldap_Filter_vals), 0,
-        "Filter/and/_item", HFILL }},
+        "ldap.T_and_item", HFILL }},
     { &hf_ldap_or,
       { "or", "ldap.or",
         FT_UINT32, BASE_DEC, NULL, 0,
-        "Filter/or", HFILL }},
+        "ldap.T_or", HFILL }},
     { &hf_ldap_or_item,
       { "Item", "ldap.or_item",
         FT_UINT32, BASE_DEC, VALS(ldap_Filter_vals), 0,
-        "Filter/or/_item", HFILL }},
+        "ldap.T_or_item", HFILL }},
     { &hf_ldap_not,
       { "not", "ldap.not",
         FT_UINT32, BASE_DEC, VALS(ldap_Filter_vals), 0,
-        "Filter/not", HFILL }},
+        "ldap.T_not", HFILL }},
     { &hf_ldap_equalityMatch,
       { "equalityMatch", "ldap.equalityMatch",
         FT_NONE, BASE_NONE, NULL, 0,
-        "Filter/equalityMatch", HFILL }},
+        "ldap.T_equalityMatch", HFILL }},
     { &hf_ldap_substrings,
       { "substrings", "ldap.substrings",
         FT_NONE, BASE_NONE, NULL, 0,
-        "Filter/substrings", HFILL }},
+        "ldap.SubstringFilter", HFILL }},
     { &hf_ldap_greaterOrEqual,
       { "greaterOrEqual", "ldap.greaterOrEqual",
         FT_NONE, BASE_NONE, NULL, 0,
-        "Filter/greaterOrEqual", HFILL }},
+        "ldap.T_greaterOrEqual", HFILL }},
     { &hf_ldap_lessOrEqual,
       { "lessOrEqual", "ldap.lessOrEqual",
         FT_NONE, BASE_NONE, NULL, 0,
-        "Filter/lessOrEqual", HFILL }},
+        "ldap.T_lessOrEqual", HFILL }},
     { &hf_ldap_present,
       { "present", "ldap.present",
         FT_STRING, BASE_NONE, NULL, 0,
-        "Filter/present", HFILL }},
+        "ldap.T_present", HFILL }},
     { &hf_ldap_approxMatch,
       { "approxMatch", "ldap.approxMatch",
         FT_NONE, BASE_NONE, NULL, 0,
-        "Filter/approxMatch", HFILL }},
+        "ldap.T_approxMatch", HFILL }},
     { &hf_ldap_extensibleMatch,
       { "extensibleMatch", "ldap.extensibleMatch",
         FT_NONE, BASE_NONE, NULL, 0,
-        "Filter/extensibleMatch", HFILL }},
+        "ldap.T_extensibleMatch", HFILL }},
     { &hf_ldap_substringFilter_substrings,
       { "substrings", "ldap.substrings",
         FT_UINT32, BASE_DEC, NULL, 0,
-        "SubstringFilter/substrings", HFILL }},
+        "ldap.T_substringFilter_substrings", HFILL }},
     { &hf_ldap_substringFilter_substrings_item,
       { "Item", "ldap.substrings_item",
         FT_UINT32, BASE_DEC, VALS(ldap_T_substringFilter_substrings_item_vals), 0,
-        "SubstringFilter/substrings/_item", HFILL }},
+        "ldap.T_substringFilter_substrings_item", HFILL }},
     { &hf_ldap_initial,
       { "initial", "ldap.initial",
         FT_STRING, BASE_NONE, NULL, 0,
-        "SubstringFilter/substrings/_item/initial", HFILL }},
+        "ldap.LDAPString", HFILL }},
     { &hf_ldap_any,
       { "any", "ldap.any",
         FT_STRING, BASE_NONE, NULL, 0,
-        "SubstringFilter/substrings/_item/any", HFILL }},
+        "ldap.LDAPString", HFILL }},
     { &hf_ldap_final,
       { "final", "ldap.final",
         FT_STRING, BASE_NONE, NULL, 0,
-        "SubstringFilter/substrings/_item/final", HFILL }},
+        "ldap.LDAPString", HFILL }},
     { &hf_ldap_matchingRule,
       { "matchingRule", "ldap.matchingRule",
         FT_STRING, BASE_NONE, NULL, 0,
-        "MatchingRuleAssertion/matchingRule", HFILL }},
+        "ldap.MatchingRuleId", HFILL }},
     { &hf_ldap_matchValue,
       { "matchValue", "ldap.matchValue",
         FT_STRING, BASE_NONE, NULL, 0,
-        "MatchingRuleAssertion/matchValue", HFILL }},
+        "ldap.AssertionValue", HFILL }},
     { &hf_ldap_dnAttributes,
       { "dnAttributes", "ldap.dnAttributes",
         FT_BOOLEAN, 8, NULL, 0,
-        "MatchingRuleAssertion/dnAttributes", HFILL }},
+        "ldap.BOOLEAN", HFILL }},
     { &hf_ldap_objectName,
       { "objectName", "ldap.objectName",
         FT_STRING, BASE_NONE, NULL, 0,
-        "SearchResultEntry/objectName", HFILL }},
+        "ldap.LDAPDN", HFILL }},
     { &hf_ldap_searchResultEntry_attributes,
       { "attributes", "ldap.attributes",
         FT_UINT32, BASE_DEC, NULL, 0,
-        "SearchResultEntry/attributes", HFILL }},
+        "ldap.PartialAttributeList", HFILL }},
     { &hf_ldap_PartialAttributeList_item,
       { "Item", "ldap.PartialAttributeList_item",
         FT_NONE, BASE_NONE, NULL, 0,
-        "PartialAttributeList/_item", HFILL }},
+        "ldap.PartialAttributeList_item", HFILL }},
     { &hf_ldap_SearchResultReference_item,
       { "Item", "ldap.SearchResultReference_item",
         FT_STRING, BASE_NONE, NULL, 0,
-        "SearchResultReference/_item", HFILL }},
+        "ldap.LDAPURL", HFILL }},
     { &hf_ldap_object,
       { "object", "ldap.object",
         FT_STRING, BASE_NONE, NULL, 0,
-        "ModifyRequest/object", HFILL }},
+        "ldap.LDAPDN", HFILL }},
     { &hf_ldap_modifyRequest_modification,
       { "modification", "ldap.modification",
         FT_UINT32, BASE_DEC, NULL, 0,
-        "ModifyRequest/modification", HFILL }},
+        "ldap.ModifyRequest_modification", HFILL }},
     { &hf_ldap_modifyRequest_modification_item,
       { "Item", "ldap.modification_item",
         FT_NONE, BASE_NONE, NULL, 0,
-        "ModifyRequest/modification/_item", HFILL }},
+        "ldap.T_modifyRequest_modification_item", HFILL }},
     { &hf_ldap_operation,
       { "operation", "ldap.operation",
         FT_UINT32, BASE_DEC, VALS(ldap_T_operation_vals), 0,
-        "ModifyRequest/modification/_item/operation", HFILL }},
+        "ldap.T_operation", HFILL }},
     { &hf_ldap_modification,
       { "modification", "ldap.modification",
         FT_NONE, BASE_NONE, NULL, 0,
-        "ModifyRequest/modification/_item/modification", HFILL }},
+        "ldap.AttributeTypeAndValues", HFILL }},
     { &hf_ldap_entry,
       { "entry", "ldap.entry",
         FT_STRING, BASE_NONE, NULL, 0,
-        "", HFILL }},
+        "ldap.LDAPDN", HFILL }},
     { &hf_ldap_attributes,
       { "attributes", "ldap.attributes",
         FT_UINT32, BASE_DEC, NULL, 0,
-        "AddRequest/attributes", HFILL }},
+        "ldap.AttributeList", HFILL }},
     { &hf_ldap_AttributeList_item,
       { "Item", "ldap.AttributeList_item",
         FT_NONE, BASE_NONE, NULL, 0,
-        "AttributeList/_item", HFILL }},
+        "ldap.AttributeList_item", HFILL }},
     { &hf_ldap_newrdn,
       { "newrdn", "ldap.newrdn",
         FT_STRING, BASE_NONE, NULL, 0,
-        "ModifyDNRequest/newrdn", HFILL }},
+        "ldap.RelativeLDAPDN", HFILL }},
     { &hf_ldap_deleteoldrdn,
       { "deleteoldrdn", "ldap.deleteoldrdn",
         FT_BOOLEAN, 8, NULL, 0,
-        "ModifyDNRequest/deleteoldrdn", HFILL }},
+        "ldap.BOOLEAN", HFILL }},
     { &hf_ldap_newSuperior,
       { "newSuperior", "ldap.newSuperior",
         FT_STRING, BASE_NONE, NULL, 0,
-        "ModifyDNRequest/newSuperior", HFILL }},
+        "ldap.LDAPDN", HFILL }},
     { &hf_ldap_ava,
       { "ava", "ldap.ava",
         FT_NONE, BASE_NONE, NULL, 0,
-        "CompareRequest/ava", HFILL }},
+        "ldap.AttributeValueAssertion", HFILL }},
     { &hf_ldap_requestName,
       { "requestName", "ldap.requestName",
         FT_STRING, BASE_NONE, NULL, 0,
-        "ExtendedRequest/requestName", HFILL }},
+        "ldap.LDAPOID", HFILL }},
     { &hf_ldap_requestValue,
       { "requestValue", "ldap.requestValue",
         FT_BYTES, BASE_HEX, NULL, 0,
-        "ExtendedRequest/requestValue", HFILL }},
+        "ldap.OCTET_STRING", HFILL }},
     { &hf_ldap_extendedResponse_resultCode,
       { "resultCode", "ldap.resultCode",
         FT_UINT32, BASE_DEC, VALS(ldap_ExtendedResponse_resultCode_vals), 0,
-        "ExtendedResponse/resultCode", HFILL }},
+        "ldap.ExtendedResponse_resultCode", HFILL }},
     { &hf_ldap_responseName,
       { "responseName", "ldap.responseName",
         FT_STRING, BASE_NONE, NULL, 0,
-        "ExtendedResponse/responseName", HFILL }},
+        "ldap.ResponseName", HFILL }},
     { &hf_ldap_response,
       { "response", "ldap.response",
         FT_BYTES, BASE_HEX, NULL, 0,
-        "ExtendedResponse/response", HFILL }},
+        "ldap.OCTET_STRING", HFILL }},
+    { &hf_ldap_size,
+      { "size", "ldap.size",
+        FT_INT32, BASE_DEC, NULL, 0,
+        "ldap.INTEGER", HFILL }},
+    { &hf_ldap_cookie,
+      { "cookie", "ldap.cookie",
+        FT_BYTES, BASE_HEX, NULL, 0,
+        "ldap.OCTET_STRING", HFILL }},
+    { &hf_ldap_SortKeyList_item,
+      { "Item", "ldap.SortKeyList_item",
+        FT_NONE, BASE_NONE, NULL, 0,
+        "ldap.SortKeyList_item", HFILL }},
+    { &hf_ldap_attributeType,
+      { "attributeType", "ldap.attributeType",
+        FT_STRING, BASE_NONE, NULL, 0,
+        "ldap.AttributeDescription", HFILL }},
+    { &hf_ldap_orderingRule,
+      { "orderingRule", "ldap.orderingRule",
+        FT_STRING, BASE_NONE, NULL, 0,
+        "ldap.MatchingRuleId", HFILL }},
+    { &hf_ldap_reverseOrder,
+      { "reverseOrder", "ldap.reverseOrder",
+        FT_BOOLEAN, 8, NULL, 0,
+        "ldap.BOOLEAN", HFILL }},
+    { &hf_ldap_sortResult,
+      { "sortResult", "ldap.sortResult",
+        FT_UINT32, BASE_DEC, VALS(ldap_T_sortResult_vals), 0,
+        "ldap.T_sortResult", HFILL }},
+    { &hf_ldap_parentsFirst,
+      { "parentsFirst", "ldap.parentsFirst",
+        FT_INT32, BASE_DEC, NULL, 0,
+        "ldap.INTEGER", HFILL }},
+    { &hf_ldap_maxReturnLength,
+      { "maxReturnLength", "ldap.maxReturnLength",
+        FT_INT32, BASE_DEC, NULL, 0,
+        "ldap.INTEGER", HFILL }},
 
 /*--- End of included file: packet-ldap-hfarr.c ---*/
-#line 1608 "packet-ldap-template.c"
+#line 1597 "packet-ldap-template.c"
   };
 
   /* List of subtrees */
@@ -4287,9 +4631,14 @@ void proto_register_ldap(void) {
     &ett_ldap_CompareRequest,
     &ett_ldap_ExtendedRequest,
     &ett_ldap_ExtendedResponse,
+    &ett_ldap_SearchControlValue,
+    &ett_ldap_SortKeyList,
+    &ett_ldap_SortKeyList_item,
+    &ett_ldap_SortResult,
+    &ett_ldap_ReplControlValue,
 
 /*--- End of included file: packet-ldap-ettarr.c ---*/
-#line 1619 "packet-ldap-template.c"
+#line 1608 "packet-ldap-template.c"
   };
 
     module_t *ldap_module;
@@ -4301,19 +4650,21 @@ void proto_register_ldap(void) {
   proto_register_subtree_array(ett, array_length(ett));
 
 
-  register_dissector("ldap", dissect_ldap, proto_ldap);
+  register_dissector("ldap", dissect_ldap_tcp, proto_ldap);
 
   ldap_module = prefs_register_protocol(proto_ldap, NULL);
   prefs_register_bool_preference(ldap_module, "desegment_ldap_messages",
     "Reassemble LDAP messages spanning multiple TCP segments",
     "Whether the LDAP dissector should reassemble messages spanning multiple TCP segments."
-    " 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",
+    "To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.",
     &ldap_desegment);
 
   prefs_register_uint_preference(ldap_module, "tcp.port", "LDAP TCP Port",
                                 "Set the port for LDAP operations",
                                 10, &ldap_tcp_port);
 
+  prefs_register_obsolete_preference(ldap_module, "max_pdu");
+
   proto_cldap = proto_register_protocol(
          "Connectionless Lightweight Directory Access Protocol",
          "CLDAP", "cldap");
@@ -4331,7 +4682,7 @@ void
 proto_reg_handoff_ldap(void)
 {
        dissector_handle_t ldap_handle, cldap_handle;
-       ldap_handle = create_dissector_handle(dissect_ldap, proto_ldap);
+       ldap_handle = create_dissector_handle(dissect_ldap_tcp, proto_ldap);
 
        dissector_add("tcp.port", ldap_tcp_port, ldap_handle);
        dissector_add("tcp.port", TCP_PORT_GLOBALCAT_LDAP, ldap_handle);
@@ -4342,6 +4693,8 @@ proto_reg_handoff_ldap(void)
        gssapi_handle = find_dissector("gssapi");
        gssapi_wrap_handle = find_dissector("gssapi_verf");
 
+       ntlmssp_handle = find_dissector("ntlmssp");
+
 /*  http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dsml/dsml/ldap_controls_and_session_support.asp */
        add_oid_str_name("1.2.840.113556.1.4.319","LDAP_PAGED_RESULT_OID_STRING");
        add_oid_str_name("1.2.840.113556.1.4.417","LDAP_SERVER_SHOW_DELETED_OID");
@@ -4377,6 +4730,20 @@ proto_reg_handoff_ldap(void)
        register_ldap_name_dissector("supportedCapabilities", dissect_ldap_oid, proto_ldap);
        register_ldap_name_dissector("objectSid", dissect_ldap_sid, proto_ldap);
        register_ldap_name_dissector("nTSecurityDescriptor", dissect_ldap_nt_sec_desc, proto_ldap);
+
+
+/*--- Included file: packet-ldap-dis-tab.c ---*/
+#line 1 "packet-ldap-dis-tab.c"
+  register_ber_oid_dissector("1.2.840.113556.1.4.319", dissect_SearchControlValue_PDU, proto_ldap, "pagedResultsControl");
+  register_ber_oid_dissector("1.2.840.113556.1.4.473", dissect_SortKeyList_PDU, proto_ldap, "sortKeyList");
+  register_ber_oid_dissector("1.2.840.113556.1.4.474", dissect_SortResult_PDU, proto_ldap, "sortResult");
+  register_ber_oid_dissector("1.2.840.113556.1.4.841", dissect_ReplControlValue_PDU, proto_ldap, "replControlValue");
+
+
+/*--- End of included file: packet-ldap-dis-tab.c ---*/
+#line 1701 "packet-ldap-template.c"
+       
+
 }