For proto_tree_add_item(..., proto_xxx, ...)use ENC_NA as the encoding arg.
[obnox/wireshark/wip.git] / epan / dissectors / packet-smb-pipe.c
index 1db6c3adb8fa7ca17cdef514bd19b333409460e1..e7f69aa8ac79cb97177c4a950af36b78ac31685f 100644 (file)
@@ -1,5 +1,5 @@
 /*
-XXX  Fixme : shouldnt show [malformed frame] for long packets
+XXX  Fixme : shouldn't show [malformed frame] for long packets
 */
 
 /* packet-smb-pipe.c
@@ -35,8 +35,6 @@ XXX  Fixme : shouldnt show [malformed frame] for long packets
 # include "config.h"
 #endif
 
-#include <stdio.h>
-
 #include <time.h>
 #include <string.h>
 #include <glib.h>
@@ -71,6 +69,7 @@ static int hf_pipe_fragment_overlap_conflict = -1;
 static int hf_pipe_fragment_multiple_tails = -1;
 static int hf_pipe_fragment_too_long_fragment = -1;
 static int hf_pipe_fragment_error = -1;
+static int hf_pipe_fragment_count = -1;
 static int hf_pipe_reassembled_in = -1;
 static int hf_pipe_reassembled_length = -1;
 
@@ -88,6 +87,7 @@ static const fragment_items smb_pipe_frag_items = {
        &hf_pipe_fragment_multiple_tails,
        &hf_pipe_fragment_too_long_fragment,
        &hf_pipe_fragment_error,
+       &hf_pipe_fragment_count,
        NULL,
        &hf_pipe_reassembled_length,
        "fragments"
@@ -627,7 +627,7 @@ add_logon_hours(tvbuff_t *tvb, int offset, int count, packet_info *pinfo _U_,
                            TRUE);
                } else {
                        proto_tree_add_bytes_format(tree, hf_index, tvb,
-                           cptr, count, tvb_get_ptr(tvb, cptr, count),
+                           cptr, count, NULL,
                            "%s: %s (wrong length, should be 21, is %d",
                            proto_registrar_get_name(hf_index),
                            tvb_bytes_to_str(tvb, cptr, count), count);
@@ -694,21 +694,21 @@ add_logon_args(tvbuff_t *tvb, int offset, int count, packet_info *pinfo _U_,
        }
 
        /* user name */
-       proto_tree_add_item(tree, hf_user_name, tvb, offset, 21, TRUE);
+       proto_tree_add_item(tree, hf_user_name, tvb, offset, 21, ENC_ASCII|ENC_NA);
        offset += 21;
 
        /* pad1 */
        offset += 1;
 
        /* password */
-       proto_tree_add_item(tree, hf_password, tvb, offset, 15, TRUE);
+       proto_tree_add_item(tree, hf_password, tvb, offset, 15, ENC_ASCII|ENC_NA);
        offset += 15;
 
        /* pad2 */
        offset += 1;
 
        /* workstation name */
-       proto_tree_add_item(tree, hf_workstation_name, tvb, offset, 16, TRUE);
+       proto_tree_add_item(tree, hf_workstation_name, tvb, offset, 16, ENC_ASCII|ENC_NA);
        offset += 16;
        return offset;
 }
@@ -801,7 +801,7 @@ netshareenum_share_entry(tvbuff_t *tvb, proto_tree *tree, int offset)
 {
        if (tree) {
                return proto_tree_add_text(tree, tvb, offset, -1,
-                   "Share %.13s", tvb_get_ptr(tvb, offset, 13));
+                   "Share %.13s", tvb_get_ephemeral_string(tvb, offset, 13));
        } else
                return NULL;
 }
@@ -1001,7 +1001,7 @@ netserverenum2_server_entry(tvbuff_t *tvb, proto_tree *tree, int offset)
 {
        if (tree) {
                return proto_tree_add_text(tree, tvb, offset, -1,
-                           "Server %.16s", tvb_get_ptr(tvb, offset, 16));
+                           "Server %.16s", tvb_get_ephemeral_string(tvb, offset, 16));
        } else
                return NULL;
 }
@@ -1805,7 +1805,7 @@ dissect_request_parameters(tvbuff_t *tvb, int offset, packet_info *pinfo,
                         * 16-bit receive buffer length.
                         */
                        proto_tree_add_item(tree, hf_recv_buf_len, tvb,
-                           offset, 2, TRUE);
+                           offset, 2, ENC_LITTLE_ENDIAN);
                        offset += 2;
                        break;
 
@@ -1822,7 +1822,7 @@ dissect_request_parameters(tvbuff_t *tvb, int offset, packet_info *pinfo,
                         * 16-bit send buffer length.
                         */
                        proto_tree_add_item(tree, hf_send_buf_len, tvb,
-                           offset, 2, TRUE);
+                           offset, 2, ENC_LITTLE_ENDIAN);
                        offset += 2;
                        break;
 
@@ -2140,7 +2140,7 @@ dissect_transact_data(tvbuff_t *tvb, int offset, int convert,
                                    (*items->hf_index == -1) ?
                                      "String Param" :
                                      proto_registrar_get_name(*items->hf_index),
-                                   string);
+                                   string ? string : "(null)");
                                items++;
                        } else {
                                offset = (*items->func)(tvb, offset, 0,
@@ -2467,6 +2467,8 @@ static const value_string commands[] = {
        {0,                                     NULL}
 };
 
+static value_string_ext commands_ext = VALUE_STRING_EXT_INIT(commands);
+
 static void
 dissect_response_data(tvbuff_t *tvb, packet_info *pinfo, int convert,
     proto_tree *tree, struct smb_info *smb_info,
@@ -2624,7 +2626,7 @@ dissect_pipe_lanman(tvbuff_t *pd_tvb, tvbuff_t *p_tvb, tvbuff_t *d_tvb,
 {
        smb_info_t *smb_info = pinfo->private_data;
        smb_transact_info_t *trp = NULL;
-       int offset = 0, start_offset;
+       int offset = 0/*, start_offset*/;
        guint16 cmd;
        guint16 status;
        int convert;
@@ -2657,7 +2659,7 @@ dissect_pipe_lanman(tvbuff_t *pd_tvb, tvbuff_t *p_tvb, tvbuff_t *d_tvb,
 
        if (parent_tree) {
                item = proto_tree_add_item(parent_tree, proto_smb_lanman,
-                       pd_tvb, 0, -1, FALSE);
+                       pd_tvb, 0, -1, ENC_NA);
                tree = proto_item_add_subtree(item, ett_lanman);
        }
 
@@ -2665,7 +2667,7 @@ dissect_pipe_lanman(tvbuff_t *pd_tvb, tvbuff_t *p_tvb, tvbuff_t *d_tvb,
                /* function code */
                cmd = tvb_get_letohs(p_tvb, offset);
                if (check_col(pinfo->cinfo, COL_INFO)) {
-                       col_add_fstr(pinfo->cinfo, COL_INFO, "%s Request", val_to_str(cmd, commands, "Unknown Command (%u)"));
+                       col_add_fstr(pinfo->cinfo, COL_INFO, "%s Request", val_to_str_ext(cmd, &commands_ext, "Unknown Command (%u)"));
                }
                proto_tree_add_uint(tree, hf_function_code, p_tvb, offset, 2,
                    cmd);
@@ -2690,10 +2692,9 @@ dissect_pipe_lanman(tvbuff_t *pd_tvb, tvbuff_t *p_tvb, tvbuff_t *d_tvb,
                }
 
                /* parameter descriptor */
-               descriptor_len = tvb_strsize(p_tvb, offset);
+               param_descrip = tvb_get_const_stringz(p_tvb, offset, &descriptor_len);
                proto_tree_add_item(tree, hf_param_desc, p_tvb, offset,
-                   descriptor_len, TRUE);
-               param_descrip = tvb_get_ptr(p_tvb, offset, descriptor_len);
+                   descriptor_len, ENC_ASCII|ENC_NA);
                if (!pinfo->fd->flags.visited) {
                        /*
                         * Save the parameter descriptor for future use.
@@ -2704,10 +2705,9 @@ dissect_pipe_lanman(tvbuff_t *pd_tvb, tvbuff_t *p_tvb, tvbuff_t *d_tvb,
                offset += descriptor_len;
 
                /* return descriptor */
-               descriptor_len = tvb_strsize(p_tvb, offset);
+               data_descrip = tvb_get_const_stringz(p_tvb, offset, &descriptor_len);
                proto_tree_add_item(tree, hf_return_desc, p_tvb, offset,
-                   descriptor_len, TRUE);
-               data_descrip = tvb_get_ptr(p_tvb, offset, descriptor_len);
+                   descriptor_len, ENC_ASCII|ENC_NA);
                if (!pinfo->fd->flags.visited) {
                        /*
                         * Save the return descriptor for future use.
@@ -2720,7 +2720,7 @@ dissect_pipe_lanman(tvbuff_t *pd_tvb, tvbuff_t *p_tvb, tvbuff_t *d_tvb,
                lanman = find_lanman(cmd);
 
                /* request parameters */
-               start_offset = offset;
+               /*start_offset = offset;*/
                offset = dissect_request_parameters(p_tvb, offset, pinfo, tree,
                    param_descrip, lanman->req, &has_data);
 
@@ -2730,10 +2730,9 @@ dissect_pipe_lanman(tvbuff_t *pd_tvb, tvbuff_t *p_tvb, tvbuff_t *d_tvb,
                         * There are more parameters left, so the next
                         * item is the auxiliary data descriptor.
                         */
-                       descriptor_len = tvb_strsize(p_tvb, offset);
+                       aux_data_descrip = tvb_get_const_stringz(p_tvb, offset, &descriptor_len);
                        proto_tree_add_item(tree, hf_aux_data_desc, p_tvb, offset,
-                           descriptor_len, TRUE);
-                       aux_data_descrip = tvb_get_ptr(p_tvb, offset, descriptor_len);
+                           descriptor_len, ENC_ASCII|ENC_NA);
                        if (!pinfo->fd->flags.visited) {
                                /*
                                 * Save the auxiliary data descriptor for
@@ -2810,7 +2809,7 @@ dissect_pipe_lanman(tvbuff_t *pd_tvb, tvbuff_t *p_tvb, tvbuff_t *d_tvb,
                        /* command */
                        if (check_col(pinfo->cinfo, COL_INFO)) {
                                col_add_fstr(pinfo->cinfo, COL_INFO, "%s Interim Response",
-                                            val_to_str(trp->lanman_cmd, commands, "Unknown Command (%u)"));
+                                            val_to_str_ext(trp->lanman_cmd, &commands_ext, "Unknown Command (%u)"));
                        }
                        proto_tree_add_uint(tree, hf_function_code, p_tvb, 0, 0, trp->lanman_cmd);
                        return TRUE;
@@ -2819,7 +2818,7 @@ dissect_pipe_lanman(tvbuff_t *pd_tvb, tvbuff_t *p_tvb, tvbuff_t *d_tvb,
                /* command */
                if (check_col(pinfo->cinfo, COL_INFO)) {
                        col_add_fstr(pinfo->cinfo, COL_INFO, "%s Response",
-                                    val_to_str(trp->lanman_cmd, commands, "Unknown Command (%u)"));
+                                    val_to_str_ext(trp->lanman_cmd, &commands_ext, "Unknown Command (%u)"));
                }
                proto_tree_add_uint(tree, hf_function_code, p_tvb, 0, 0,
                    trp->lanman_cmd);
@@ -2906,8 +2905,8 @@ proto_register_pipe_lanman(void)
 {
        static hf_register_info hf[] = {
                { &hf_function_code,
-                       { "Function Code", "lanman.function_code", FT_UINT16, BASE_DEC,
-                       VALS(commands), 0, "LANMAN Function Code/Command", HFILL }},
+                       { "Function Code", "lanman.function_code", FT_UINT16, BASE_DEC|BASE_EXT_STRING,
+                       &commands_ext, 0, "LANMAN Function Code/Command", HFILL }},
 
                { &hf_param_desc,
                        { "Parameter Descriptor", "lanman.param_desc", FT_STRING, BASE_NONE,
@@ -3560,7 +3559,7 @@ dissect_pipe_smb(tvbuff_t *sp_tvb, tvbuff_t *s_tvb, tvbuff_t *pd_tvb,
                sp_len = 0;
        if (tree) {
                pipe_item = proto_tree_add_item(tree, proto_smb_pipe,
-                   sp_tvb, 0, sp_len, FALSE);
+                   sp_tvb, 0, sp_len, ENC_NA);
                pipe_tree = proto_item_add_subtree(pipe_item, ett_smb_pipe);
        }
        offset = 0;
@@ -3595,7 +3594,7 @@ dissect_pipe_smb(tvbuff_t *sp_tvb, tvbuff_t *s_tvb, tvbuff_t *pd_tvb,
                         * It's a priority.
                         */
                        proto_tree_add_item(pipe_tree, hf_pipe_priority, s_tvb,
-                           offset, 2, TRUE);
+                           offset, 2, ENC_LITTLE_ENDIAN);
                        break;
 
                case PEEK_NAMED_PIPE:
@@ -3730,13 +3729,13 @@ dissect_pipe_smb(tvbuff_t *sp_tvb, tvbuff_t *s_tvb, tvbuff_t *pd_tvb,
                                return FALSE;
                        offset = 0;
                        proto_tree_add_item(pipe_tree, hf_pipe_peek_available,
-                           p_tvb, offset, 2, TRUE);
+                           p_tvb, offset, 2, ENC_LITTLE_ENDIAN);
                        offset += 2;
                        proto_tree_add_item(pipe_tree, hf_pipe_peek_remaining,
-                           p_tvb, offset, 2, TRUE);
+                           p_tvb, offset, 2, ENC_LITTLE_ENDIAN);
                        offset += 2;
                        proto_tree_add_item(pipe_tree, hf_pipe_peek_status,
-                           p_tvb, offset, 2, TRUE);
+                           p_tvb, offset, 2, ENC_LITTLE_ENDIAN);
                        offset += 2;
                }
                break;
@@ -3789,19 +3788,19 @@ dissect_pipe_smb(tvbuff_t *sp_tvb, tvbuff_t *s_tvb, tvbuff_t *pd_tvb,
                        case 1:
                                proto_tree_add_item(pipe_tree,
                                    hf_pipe_getinfo_output_buffer_size,
-                                   d_tvb, offset, 2, TRUE);
+                                   d_tvb, offset, 2, ENC_LITTLE_ENDIAN);
                                offset += 2;
                                proto_tree_add_item(pipe_tree,
                                    hf_pipe_getinfo_input_buffer_size,
-                                   d_tvb, offset, 2, TRUE);
+                                   d_tvb, offset, 2, ENC_LITTLE_ENDIAN);
                                offset += 2;
                                proto_tree_add_item(pipe_tree,
                                    hf_pipe_getinfo_maximum_instances,
-                                   d_tvb, offset, 1, TRUE);
+                                   d_tvb, offset, 1, ENC_LITTLE_ENDIAN);
                                offset += 1;
                                proto_tree_add_item(pipe_tree,
                                    hf_pipe_getinfo_current_instances,
-                                   d_tvb, offset, 1, TRUE);
+                                   d_tvb, offset, 1, ENC_LITTLE_ENDIAN);
                                offset += 1;
                                pipe_namelen = tvb_get_guint8(d_tvb, offset);
                                proto_tree_add_uint(pipe_tree,
@@ -3811,7 +3810,7 @@ dissect_pipe_smb(tvbuff_t *sp_tvb, tvbuff_t *s_tvb, tvbuff_t *pd_tvb,
                                /* XXX - can this be Unicode? */
                                proto_tree_add_item(pipe_tree,
                                    hf_pipe_getinfo_pipe_name,
-                                   d_tvb, offset, pipe_namelen, TRUE);
+                                   d_tvb, offset, pipe_namelen, ENC_ASCII|ENC_NA);
                                break;
                        }
                }
@@ -3845,7 +3844,7 @@ dissect_pipe_smb(tvbuff_t *sp_tvb, tvbuff_t *s_tvb, tvbuff_t *pd_tvb,
                                return FALSE;
                        proto_tree_add_item(pipe_tree,
                            hf_pipe_write_raw_bytes_written,
-                           p_tvb, offset, 2, TRUE);
+                           p_tvb, offset, 2, ENC_LITTLE_ENDIAN);
                        offset += 2;
                }
                break;
@@ -3871,7 +3870,7 @@ proto_register_smb_pipe(void)
                        NULL, 0, "Total number of bytes remaining in the message at the head of the pipe", HFILL }},
                { &hf_pipe_peek_status,
                        { "Pipe Status", "pipe.peek.status", FT_UINT16, BASE_DEC,
-                       VALS(pipe_status), 0, "Pipe status", HFILL }},
+                       VALS(pipe_status), 0, NULL, HFILL }},
                { &hf_pipe_getinfo_info_level,
                        { "Information Level", "pipe.getinfo.info_level", FT_UINT16, BASE_DEC,
                        NULL, 0, "Information level of information to return", HFILL }},
@@ -3911,6 +3910,9 @@ proto_register_smb_pipe(void)
                { &hf_pipe_fragment_error,
                        { "Defragmentation error", "pipe.fragment.error", FT_FRAMENUM,
                        BASE_NONE, NULL, 0x0, "Defragmentation error due to illegal fragments", HFILL }},
+               { &hf_pipe_fragment_count,
+                       { "Fragment count", "pipe.fragment.count", FT_UINT32,
+                       BASE_DEC, NULL, 0x0, NULL, HFILL }},
                { &hf_pipe_fragment,
                        { "Fragment", "pipe.fragment", FT_FRAMENUM,
                        BASE_NONE, NULL, 0x0, "Pipe Fragment", HFILL }},
@@ -3921,7 +3923,7 @@ proto_register_smb_pipe(void)
                        { "This PDU is reassembled in", "pipe.reassembled_in", FT_FRAMENUM,
                        BASE_NONE, NULL, 0x0, "The DCE/RPC PDU is completely reassembled in this frame", HFILL }},
                { &hf_pipe_reassembled_length,
-                       { "Reassembled length", "pipe.reassembled_length", FT_UINT32,
+                       { "Reassembled SMB Pipe length", "pipe.reassembled.length", FT_UINT32,
                        BASE_DEC, NULL, 0x0, "The total length of the reassembled payload", HFILL }},
        };
        static gint *ett[] = {