sized envelope ...
authorStefan Metzmacher <metze@samba.org>
Fri, 24 Nov 2017 17:51:56 +0000 (18:51 +0100)
committerStefan Metzmacher <metze@samba.org>
Sun, 20 Jan 2019 22:14:58 +0000 (23:14 +0100)
Change-Id: Iaef4d2ca4cdfdc2110cdfcebba7dc38945233804

epan/dissectors/packet-nmf.c

index 217388e..e6526b6 100644 (file)
@@ -38,6 +38,8 @@ void proto_reg_handoff_nmf(void);
 static dissector_handle_t gssapi_handle;
 static dissector_handle_t gssapi_wrap_handle;
 
+static dissector_handle_t xml_handle;
+
 static int proto_nmf = -1;
 
 static gint ett_nmf = -1;
@@ -51,6 +53,7 @@ static int hf_nmf_mode_value = -1;
 static int hf_nmf_via_length = -1;
 static int hf_nmf_via_value = -1;
 static int hf_nmf_known_mode_value = -1;
+static int hf_nmf_sized_envelope_length = -1;
 static int hf_nmf_upgrade_length = -1;
 static int hf_nmf_upgrade_protocol = -1;
 static int hf_nmf_negotiate_type = -1;
@@ -161,6 +164,8 @@ dissect_nmf_record(tvbuff_t *tvb, packet_info *pinfo,
        enum nmf_record_type record_type;
        guint32 size = 0;
        const guint8 *str = NULL;
+       tvbuff_t *payload_tvb = NULL;
+       tvbuff_t *xml_tvb = NULL;
 
        record_item = proto_tree_add_item(tree, hf_nmf_record, tvb, offset, -1, ENC_NA);
        proto_item_append_text(record_item, ", start_offset=0x%x, ", (guint)offset);
@@ -217,7 +222,37 @@ dissect_nmf_record(tvbuff_t *tvb, packet_info *pinfo,
                /* TODO */
                break;
        case NMF_SIZED_ENVELOPE_RECORD:
-               /* TODO */
+               offset = dissect_nmf_record_size(tvb, record_tree,
+                                                hf_nmf_sized_envelope_length,
+                                                offset, &size);
+               if (offset <= 0) {
+                       return -1;
+               }
+
+               payload_tvb = tvb_new_subset_length(tvb, offset, size);
+               offset += size;
+               proto_item_append_text(record_item, ": Payload (%u byte%s)",
+                                      size, plurality(size, "", "s"));
+               proto_tree_add_format_text(record_tree, payload_tvb, 0, size);
+               if (0) {
+                       /* TODO:
+                        *
+                        * 1. reassemble payload
+                        * 2. use
+                        *    [MC-NBFSE] .NET Binary Format: SOAP Extension
+                        *    [MC-NBFS]  .NET Binary Format: SOAP Data Structure
+                        *    [MC-NBFX]  .NET Binary Format: XML Data Structure
+                        *    to generate XML
+                        * 3. call the XML dissector.
+                        */
+                       if (payload_tvb != NULL) {
+                               xml_tvb = NULL;
+                       }
+               }
+               if (xml_tvb != NULL) {
+                       call_dissector_with_data(xml_handle, xml_tvb, pinfo,
+                                                record_tree, NULL);
+               }
                break;
        case NMF_END_RECORD:
                /* TODO */
@@ -327,7 +362,12 @@ nmf_get_pdu_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset, void *_info)
                /* TODO */
                break;
        case NMF_SIZED_ENVELOPE_RECORD:
-               /* TODO */
+               offset = dissect_nmf_record_size(tvb, NULL, -1,
+                                                offset, &size);
+               if (offset <= 0) {
+                       return 0;
+               }
+               offset += size;
                break;
        case NMF_END_RECORD:
                /* TODO */
@@ -357,6 +397,25 @@ nmf_get_pdu_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset, void *_info)
        return offset - start_offset;
 }
 
+static int
+dissect_nmf_payload(tvbuff_t *tvb, packet_info *pinfo,
+                   proto_tree *tree, nmf_conv_info_t *nmf_info)
+{
+       int offset = 0;
+
+       while (tvb_reported_length_remaining(tvb, offset) > 0) {
+               int ret;
+
+               ret = dissect_nmf_record(tvb, pinfo, nmf_info, tree, offset);
+               if (ret <= 0) {
+                       return -1;
+               }
+               offset += ret;
+       }
+
+       return offset;
+}
+
 static int
 dissect_nmf_pdu(tvbuff_t *tvb, packet_info *pinfo,
                proto_tree *tree, void *_info)
@@ -435,8 +494,7 @@ dissect_nmf_pdu(tvbuff_t *tvb, packet_info *pinfo,
               ett_nmf_payload, NULL, "GSS-API Encrypted payload (%d byte%s)",
               decr_len, plurality(decr_len, "", "s"));
           }
-         proto_tree_add_format_text(enc_tree, decr_tvb, 0, decr_len);
-          //dissect_ldap_payload(decr_tvb, pinfo, enc_tree, ldap_info, is_mscldap);
+          dissect_nmf_payload(decr_tvb, pinfo, enc_tree, nmf_info);
         } else if (plain_tvb) {
           proto_tree *plain_tree = NULL;
           guint plain_len = tvb_reported_length(plain_tvb);
@@ -449,8 +507,7 @@ dissect_nmf_pdu(tvbuff_t *tvb, packet_info *pinfo,
               plain_len, plurality(plain_len, "", "s"));
           }
 
-         proto_tree_add_format_text(plain_tree, plain_tvb, 0, plain_len);
-          //dissect_ldap_payload(plain_tvb, pinfo, plain_tree, ldap_info, is_mscldap);
+          dissect_nmf_payload(plain_tvb, pinfo, plain_tree, nmf_info);
         } else {
           col_add_fstr(pinfo->cinfo, COL_INFO, "NMF GSS-API Privacy: payload (%d byte%s)",
             len,
@@ -570,6 +627,9 @@ void proto_register_nmf(void)
        { &hf_nmf_known_mode_value,
                { "Mode", "nmf.known_mode.value",
                FT_UINT8, BASE_DEC, VALS(known_mode_values), 0, NULL, HFILL }},
+       { &hf_nmf_sized_envelope_length,
+               { "Length", "nmf.sized_envelope.length",
+               FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }},
        { &hf_nmf_upgrade_length,
                { "Length", "nmf.upgrade.length",
                FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }},
@@ -612,4 +672,6 @@ proto_reg_handoff_nmf(void)
 
        gssapi_handle = find_dissector_add_dependency("gssapi", proto_nmf);
        gssapi_wrap_handle = find_dissector_add_dependency("gssapi_verf", proto_nmf);
+
+       xml_handle = find_dissector_add_dependency("xml", proto_nmf);
 }