2004-01-16 01:32:20 +00:00
|
|
|
/* packet-multipart.c
|
|
|
|
* Routines for multipart media encapsulation dissection
|
2004-03-08 22:03:59 +00:00
|
|
|
* Copyright 2004, Anders Broman.
|
|
|
|
* Copyright 2004, Olivier Biot.
|
2004-01-16 01:32:20 +00:00
|
|
|
*
|
2004-07-18 00:24:25 +00:00
|
|
|
* $Id$
|
2004-03-08 22:03:59 +00:00
|
|
|
*
|
|
|
|
* Refer to the AUTHORS file or the AUTHORS section in the man page
|
|
|
|
* for contacting the author(s) of this file.
|
2004-01-16 01:32:20 +00:00
|
|
|
*
|
2006-05-21 04:49:01 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2004-01-16 01:32:20 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-06-28 23:18:38 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2004-01-16 01:32:20 +00:00
|
|
|
*
|
|
|
|
* References for "media-type multipart/mixed :
|
|
|
|
* http://www.iana.org/assignments/media-types/index.html
|
2007-08-09 12:17:56 +00:00
|
|
|
* http://www.ietf.org/rfc/rfc2045.txt?number=2045
|
2004-01-16 01:32:20 +00:00
|
|
|
* http://www.rfc-editor.org/rfc/rfc2046.txt
|
|
|
|
* http://www.rfc-editor.org/rfc/rfc2047.txt
|
|
|
|
* http://www.rfc-editor.org/rfc/rfc2048.txt
|
|
|
|
* http://www.rfc-editor.org/rfc/rfc2049.txt
|
|
|
|
*
|
|
|
|
* Part of the code is modeled from the SIP and HTTP dissectors
|
|
|
|
*
|
|
|
|
* General format of a MIME multipart document:
|
|
|
|
* [ preamble line-end ]
|
|
|
|
* dash-boundary transport-padding line-end
|
|
|
|
* body-part
|
|
|
|
* *encapsulation
|
|
|
|
* close-delimiter transport-padding
|
|
|
|
* [ line-end epilogue ]
|
|
|
|
*
|
|
|
|
* Where:
|
|
|
|
* dash-boundary := "--" boundary
|
|
|
|
* encapsulation := delimiter transport-padding line-end body-part
|
|
|
|
* delimiter := line-end body-part
|
|
|
|
* close-delimiter := delimiter "--"
|
|
|
|
* body-part := MIME-part-headers [ line-end *OCTET ]
|
|
|
|
* transport-padding := *LWSP-char
|
2011-06-19 19:13:26 +00:00
|
|
|
*
|
2004-01-16 01:32:20 +00:00
|
|
|
* Note that line-end is often a LF instead of a CRLF.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
2012-05-15 19:23:35 +00:00
|
|
|
|
|
|
|
#include <glib.h>
|
2004-01-16 01:32:20 +00:00
|
|
|
|
|
|
|
#include <epan/packet.h>
|
2012-05-15 19:23:35 +00:00
|
|
|
#include <epan/prefs.h>
|
|
|
|
#include <epan/base64.h>
|
|
|
|
#include <epan/emem.h>
|
2004-01-16 01:32:20 +00:00
|
|
|
|
2007-07-14 09:19:35 +00:00
|
|
|
#include "packet-imf.h"
|
|
|
|
|
2004-02-06 01:07:51 +00:00
|
|
|
/* Dissector table for media requiring special attention in multipart
|
|
|
|
* encapsulation. */
|
|
|
|
static dissector_table_t multipart_media_subdissector_table;
|
2004-01-16 01:32:20 +00:00
|
|
|
|
|
|
|
/* Initialize the protocol and registered fields */
|
|
|
|
static int proto_multipart = -1;
|
|
|
|
|
|
|
|
/* Initialize the subtree pointers */
|
|
|
|
static gint ett_multipart = -1;
|
|
|
|
static gint ett_multipart_main = -1;
|
|
|
|
static gint ett_multipart_body = -1;
|
|
|
|
|
|
|
|
/* Not sure that compact_name exists for multipart, but choose to keep
|
|
|
|
* the structure from SIP dissector, all the content- is also from SIP */
|
|
|
|
|
|
|
|
|
2005-01-20 01:26:34 +00:00
|
|
|
typedef struct {
|
2005-07-30 16:34:38 +00:00
|
|
|
const char *name;
|
|
|
|
const char *compact_name;
|
2005-01-20 01:26:34 +00:00
|
|
|
} multipart_header_t;
|
|
|
|
|
|
|
|
static const multipart_header_t multipart_headers[] = {
|
|
|
|
{ "Unknown-header", NULL }, /* Pad so that the real headers start at index 1 */
|
|
|
|
{ "Content-Disposition", NULL },
|
|
|
|
{ "Content-Encoding", "e" },
|
2006-09-20 12:12:18 +00:00
|
|
|
{ "Content-Id", NULL },
|
2005-01-20 01:26:34 +00:00
|
|
|
{ "Content-Language", NULL },
|
|
|
|
{ "Content-Length", "l" },
|
2006-09-20 12:12:18 +00:00
|
|
|
{ "Content-Transfer-Encoding", NULL },
|
2005-01-20 01:26:34 +00:00
|
|
|
{ "Content-Type", "c" },
|
2004-01-16 01:32:20 +00:00
|
|
|
};
|
|
|
|
|
2006-09-20 12:12:18 +00:00
|
|
|
#define POS_CONTENT_DISPOSITION 1
|
|
|
|
#define POS_CONTENT_ENCODING 2
|
|
|
|
#define POS_CONTENT_ID 3
|
|
|
|
#define POS_CONTENT_LANGUAGE 4
|
|
|
|
#define POS_CONTENT_LENGTH 5
|
|
|
|
#define POS_CONTENT_TRANSFER_ENCODING 6
|
|
|
|
#define POS_CONTENT_TYPE 7
|
2004-01-16 01:32:20 +00:00
|
|
|
|
|
|
|
/* Initialize the header fields */
|
|
|
|
static gint hf_multipart_type = -1;
|
2006-11-16 14:35:52 +00:00
|
|
|
static gint hf_multipart_part = -1;
|
|
|
|
|
2004-01-16 01:32:20 +00:00
|
|
|
static gint hf_header_array[] = {
|
|
|
|
-1, /* "Unknown-header" - Pad so that the real headers start at index 1 */
|
|
|
|
-1, /* "Content-Disposition" */
|
|
|
|
-1, /* "Content-Encoding" */
|
2006-09-20 12:12:18 +00:00
|
|
|
-1, /* "Content-Id" */
|
2004-01-16 01:32:20 +00:00
|
|
|
-1, /* "Content-Language" */
|
|
|
|
-1, /* "Content-Length" */
|
2006-09-20 12:12:18 +00:00
|
|
|
-1, /* "Content-Transfer-Encoding" */
|
2004-01-16 01:32:20 +00:00
|
|
|
-1, /* "Content-Type" */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Define media_type/Content type table */
|
|
|
|
static dissector_table_t media_type_dissector_table;
|
|
|
|
|
2004-04-30 17:07:21 +00:00
|
|
|
/* Data and media dissector handles */
|
2004-01-16 01:32:20 +00:00
|
|
|
static dissector_handle_t data_handle;
|
2004-04-30 17:07:21 +00:00
|
|
|
static dissector_handle_t media_handle;
|
2004-01-16 01:32:20 +00:00
|
|
|
|
|
|
|
/* Determins if bodies with no media type dissector shoud be displayed
|
|
|
|
* as raw text, may cause problems with images sound etc
|
|
|
|
* TODO improve to check for different content types ?
|
|
|
|
*/
|
|
|
|
static gboolean display_unknown_body_as_text = FALSE;
|
2007-07-14 09:19:35 +00:00
|
|
|
static gboolean remove_base64_encoding = FALSE;
|
2004-01-16 01:32:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
2004-01-16 22:22:31 +00:00
|
|
|
const char *type; /* Type of multipart */
|
2004-01-16 01:32:20 +00:00
|
|
|
char *boundary; /* Boundary string (enclosing quotes removed if any) */
|
|
|
|
guint boundary_length; /* Length of the boundary string */
|
|
|
|
} multipart_info_t;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static gint
|
|
|
|
find_first_boundary(tvbuff_t *tvb, gint start, const guint8 *boundary,
|
|
|
|
gint boundary_len, gint *boundary_line_len, gboolean *last_boundary);
|
|
|
|
static gint
|
|
|
|
find_next_boundary(tvbuff_t *tvb, gint start, const guint8 *boundary,
|
|
|
|
gint boundary_len, gint *boundary_line_len, gboolean *last_boundary);
|
|
|
|
static gint
|
|
|
|
process_preamble(proto_tree *tree, tvbuff_t *tvb, const guint8 *boundary,
|
|
|
|
gint boundary_len, gboolean *last_boundary);
|
|
|
|
static gint
|
|
|
|
process_body_part(proto_tree *tree, tvbuff_t *tvb, const guint8 *boundary,
|
|
|
|
gint boundary_len, packet_info *pinfo, gint start,
|
|
|
|
gboolean *last_boundary);
|
|
|
|
static gint
|
|
|
|
is_known_multipart_header(const char *header_str, guint len);
|
|
|
|
static gint
|
|
|
|
index_of_char(const char *str, const char c);
|
2009-03-29 22:16:26 +00:00
|
|
|
static char *
|
2004-01-16 01:32:20 +00:00
|
|
|
unfold_and_compact_mime_header(const char *lines, gint *first_colon_offset);
|
|
|
|
|
2007-07-14 09:19:35 +00:00
|
|
|
|
|
|
|
/* Return a tvb that contains the binary representation of a base64
|
|
|
|
string */
|
|
|
|
|
|
|
|
static tvbuff_t *
|
|
|
|
base64_decode(packet_info *pinfo, tvbuff_t *b64_tvb, char *name)
|
|
|
|
{
|
|
|
|
char *data;
|
2008-08-03 15:44:26 +00:00
|
|
|
tvbuff_t *tvb;
|
2007-10-23 05:50:00 +00:00
|
|
|
data = g_strdup(tvb_get_ephemeral_string(b64_tvb, 0, tvb_length(b64_tvb)));
|
2007-07-14 09:19:35 +00:00
|
|
|
|
2009-05-13 19:46:11 +00:00
|
|
|
tvb = base64_to_tvb(b64_tvb, data);
|
2008-08-03 15:44:26 +00:00
|
|
|
add_new_data_source(pinfo, tvb, name);
|
2007-07-14 09:19:35 +00:00
|
|
|
|
2008-08-03 15:44:26 +00:00
|
|
|
return tvb;
|
2007-07-14 09:19:35 +00:00
|
|
|
}
|
|
|
|
|
2004-01-16 01:32:20 +00:00
|
|
|
/*
|
|
|
|
* Unfold and clean up a MIME-like header, and process LWS as follows:
|
|
|
|
* o Preserves LWS in quoted text
|
|
|
|
* o Remove LWS before and after a separator
|
|
|
|
* o Remove trailing LWS
|
|
|
|
* o Replace other LWS with a single space
|
2011-06-19 19:13:26 +00:00
|
|
|
* Set value to the start of the value
|
2004-01-16 01:32:20 +00:00
|
|
|
* Return the cleaned-up RFC2822 header (buffer must be freed).
|
|
|
|
*/
|
2009-03-29 22:16:26 +00:00
|
|
|
static char *
|
2004-01-16 01:32:20 +00:00
|
|
|
unfold_and_compact_mime_header(const char *lines, gint *first_colon_offset)
|
|
|
|
{
|
|
|
|
const char *p = lines;
|
|
|
|
char c;
|
|
|
|
char *ret, *q;
|
|
|
|
char sep_seen = 0; /* Did we see a separator ":;," */
|
|
|
|
char lws = FALSE; /* Did we see LWS (incl. folding) */
|
|
|
|
gint colon = -1;
|
|
|
|
|
|
|
|
if (! lines) return NULL;
|
|
|
|
|
|
|
|
c = *p;
|
|
|
|
ret = g_malloc(strlen(lines) + 1);
|
|
|
|
q = ret;
|
|
|
|
|
|
|
|
while (c) {
|
|
|
|
if (c == ':') {
|
|
|
|
lws = FALSE; /* Prevent leading LWS from showing up */
|
|
|
|
if (colon == -1) {/* First colon */
|
2009-04-06 00:08:46 +00:00
|
|
|
colon = (gint) (q - ret);
|
2004-01-16 01:32:20 +00:00
|
|
|
}
|
|
|
|
*(q++) = sep_seen = c;
|
|
|
|
p++;
|
|
|
|
} else if (c == ';' || c == ',' || c == '=') {
|
|
|
|
lws = FALSE; /* Prevent leading LWS from showing up */
|
|
|
|
*(q++) = sep_seen = c;
|
|
|
|
p++;
|
|
|
|
} else if (c == ' ' || c == '\t') {
|
|
|
|
lws = TRUE;
|
|
|
|
p++;
|
|
|
|
} else if (c == '\n') {
|
|
|
|
lws = FALSE; /* Skip trailing LWS */
|
|
|
|
if ((c = *(p+1))) {
|
|
|
|
if (c == ' ' || c == '\t') { /* Header unfolding */
|
|
|
|
lws = TRUE;
|
|
|
|
p += 2;
|
|
|
|
} else {
|
|
|
|
*q = c = 0; /* Stop */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (c == '\r') {
|
|
|
|
lws = FALSE;
|
|
|
|
if ((c = *(p+1))) {
|
|
|
|
if (c == '\n') {
|
|
|
|
if ((c = *(p+2))) {
|
|
|
|
if (c == ' ' || c == '\t') { /* Header unfolding */
|
|
|
|
lws = TRUE;
|
|
|
|
p += 3;
|
|
|
|
} else {
|
|
|
|
*q = c = 0; /* Stop */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (c == ' ' || c == '\t') { /* Header unfolding */
|
|
|
|
lws = TRUE;
|
|
|
|
p += 2;
|
|
|
|
} else {
|
|
|
|
*q = c = 0; /* Stop */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (c == '"') { /* Start of quoted-string */
|
|
|
|
lws = FALSE;
|
|
|
|
*(q++) = c;
|
|
|
|
while (c) {
|
|
|
|
c = *(q++) = *(++p);
|
|
|
|
if (c == '"') {
|
|
|
|
p++; /* Skip closing quote */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-10-16 23:13:21 +00:00
|
|
|
/* if already zero terminated now, rewind one char to avoid an "off by one" */
|
|
|
|
if(c == 0) {
|
|
|
|
q--;
|
|
|
|
}
|
2004-01-16 01:32:20 +00:00
|
|
|
} else { /* Regular character */
|
|
|
|
if (sep_seen) {
|
|
|
|
sep_seen = 0;
|
|
|
|
lws = FALSE;
|
|
|
|
} else {
|
|
|
|
if (lws) {
|
|
|
|
*(q++) = ' ';
|
|
|
|
lws = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lws = FALSE;
|
|
|
|
*(q++) = c;
|
|
|
|
p++; /* OK */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c) {
|
|
|
|
c = *p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*q = 0;
|
|
|
|
|
|
|
|
*first_colon_offset = colon;
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the index of a given char in the given string,
|
|
|
|
* or -1 if not found.
|
|
|
|
*/
|
|
|
|
static gint
|
|
|
|
index_of_char(const char *str, const char c)
|
|
|
|
{
|
|
|
|
gint len = 0;
|
|
|
|
const char *p = str;
|
|
|
|
|
|
|
|
while (*p && *p != c) {
|
|
|
|
p++;
|
|
|
|
len++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*p)
|
|
|
|
return len;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-07-14 09:19:35 +00:00
|
|
|
static char *find_parameter(char *parameters, const char *key, int *retlen)
|
2004-01-16 01:32:20 +00:00
|
|
|
{
|
2007-07-14 09:19:35 +00:00
|
|
|
char *start, *p;
|
|
|
|
int keylen = 0;
|
|
|
|
int len = 0;
|
2004-01-16 01:32:20 +00:00
|
|
|
|
2009-04-06 00:08:46 +00:00
|
|
|
if(!parameters || !*parameters || !key || strlen(key) == 0)
|
2007-07-14 09:19:35 +00:00
|
|
|
/* we won't be able to find anything */
|
2004-01-16 01:32:20 +00:00
|
|
|
return NULL;
|
|
|
|
|
2009-04-06 00:08:46 +00:00
|
|
|
keylen = (int) strlen(key);
|
2004-01-16 01:32:20 +00:00
|
|
|
p = parameters;
|
2007-07-14 09:19:35 +00:00
|
|
|
|
2007-07-05 16:31:12 +00:00
|
|
|
while (*p) {
|
2007-07-05 16:19:36 +00:00
|
|
|
|
2007-07-05 16:31:12 +00:00
|
|
|
while ((*p) && isspace((guchar)*p))
|
|
|
|
p++; /* Skip white space */
|
2011-06-19 19:13:26 +00:00
|
|
|
|
strcasecmp(), strncasecmp(), g_strcasecmp(), and g_strncasecmp() delenda
est. Use g_ascii_strcasecmp() and g_ascii_strncasecmp(), and supply our
own versions if they're missing from GLib (as is the case with GLib
1.x).
In the code to build the list of named fields for Diameter, don't use
g_strdown(); do our own g_ascii_-style upper-case to lower-case mapping
in the hash function and use g_ascii_strcasecmp() in the compare
function.
We do this because there is no guarantee that toupper(), tolower(), and
functions that use them will, for example, map between "I" and "i" in
all locales; in Turkish locales, for example, there are, in both
upper case and lower case, versions of "i" with and without a dot, and
the upper-case version of "i" is "I"-with-a-dot and the lower-case
version of "I" is "i"-without-a-dot. This causes strings that should
match not to match.
This finishes fixing bug 2010 - an earlier checkin prevented the crash
(as there are other ways to produce the same crash, e.g. a bogus
dictionary.xml file), but didn't fix the case-insensitive string matching.
svn path=/trunk/; revision=23623
2007-11-27 18:52:51 +00:00
|
|
|
if (g_ascii_strncasecmp(p, key, keylen) == 0)
|
2004-01-16 01:32:20 +00:00
|
|
|
break;
|
|
|
|
/* Skip to next parameter */
|
|
|
|
p = strchr(p, ';');
|
|
|
|
if (p == NULL)
|
2005-01-05 10:38:50 +00:00
|
|
|
{
|
2004-01-16 01:32:20 +00:00
|
|
|
return NULL;
|
2005-01-05 10:38:50 +00:00
|
|
|
}
|
2004-01-16 01:32:20 +00:00
|
|
|
p++; /* Skip semicolon */
|
2007-07-05 16:19:36 +00:00
|
|
|
|
2004-01-16 01:32:20 +00:00
|
|
|
}
|
2007-07-14 09:19:35 +00:00
|
|
|
start = p + keylen;
|
2004-01-16 01:32:20 +00:00
|
|
|
if (start[0] == 0) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process the parameter value
|
|
|
|
*/
|
|
|
|
if (start[0] == '"') {
|
|
|
|
/*
|
2007-07-14 09:19:35 +00:00
|
|
|
* Parameter value is a quoted-string
|
2004-01-16 01:32:20 +00:00
|
|
|
*/
|
|
|
|
start++; /* Skip the quote */
|
|
|
|
len = index_of_char(start, '"');
|
|
|
|
if (len < 0) {
|
|
|
|
/*
|
|
|
|
* No closing quote
|
|
|
|
*/
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Look for end of boundary
|
|
|
|
*/
|
|
|
|
p = start;
|
|
|
|
while (*p) {
|
2004-02-11 09:19:54 +00:00
|
|
|
if (*p == ';' || isspace((guchar)*p))
|
2004-01-16 01:32:20 +00:00
|
|
|
break;
|
|
|
|
p++;
|
|
|
|
len++;
|
|
|
|
}
|
|
|
|
}
|
2007-07-14 09:19:35 +00:00
|
|
|
|
|
|
|
if(retlen)
|
|
|
|
(*retlen) = len;
|
|
|
|
|
|
|
|
return start;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Retrieve the media information from pinfo->private_data,
|
|
|
|
* and compute the boundary string and its length.
|
|
|
|
* Return a pointer to a filled-in multipart_info_t, or NULL on failure.
|
2011-06-19 19:13:26 +00:00
|
|
|
*
|
2007-07-14 09:19:35 +00:00
|
|
|
* Boundary delimiters must not appear within the encapsulated material,
|
|
|
|
* and must be no longer than 70 characters, not counting the two
|
|
|
|
* leading hyphens. (quote from rfc2046)
|
|
|
|
*/
|
|
|
|
static multipart_info_t *
|
|
|
|
get_multipart_info(packet_info *pinfo)
|
|
|
|
{
|
|
|
|
const char *start;
|
|
|
|
int len = 0;
|
|
|
|
multipart_info_t *m_info = NULL;
|
|
|
|
const char *type = pinfo->match_string;
|
|
|
|
char *parameters;
|
|
|
|
gint dummy;
|
|
|
|
|
|
|
|
if ((type == NULL) || (pinfo->private_data == NULL)) {
|
|
|
|
/*
|
|
|
|
* We need both a content type AND parameters
|
|
|
|
* for multipart dissection.
|
|
|
|
*/
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clean up the parameters */
|
|
|
|
parameters = unfold_and_compact_mime_header(pinfo->private_data, &dummy);
|
|
|
|
|
|
|
|
start = find_parameter(parameters, "boundary=", &len);
|
|
|
|
|
|
|
|
if(!start) {
|
|
|
|
g_free(parameters);
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-06-19 19:13:26 +00:00
|
|
|
|
2004-01-16 01:32:20 +00:00
|
|
|
/*
|
|
|
|
* There is a value for the boundary string
|
|
|
|
*/
|
|
|
|
m_info = g_malloc(sizeof(multipart_info_t));
|
|
|
|
m_info->type = type;
|
|
|
|
m_info->boundary = g_strndup(start, len);
|
|
|
|
m_info->boundary_length = len;
|
2005-01-05 10:38:50 +00:00
|
|
|
g_free(parameters);
|
2004-01-16 01:32:20 +00:00
|
|
|
|
|
|
|
return m_info;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cleanup_multipart_info(void *data)
|
|
|
|
{
|
|
|
|
multipart_info_t *m_info = data;
|
|
|
|
if (m_info) {
|
2009-03-13 22:06:48 +00:00
|
|
|
g_free(m_info->boundary);
|
2004-01-16 01:32:20 +00:00
|
|
|
g_free(m_info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The first boundary does not implicitly contain the leading
|
|
|
|
* line-end sequence.
|
|
|
|
*
|
|
|
|
* Return the offset to the 1st byte of the boundary delimiter line.
|
|
|
|
* Set boundary_line_len to the length of the entire boundary delimiter.
|
|
|
|
* Set last_boundary to TRUE if we've seen the last-boundary delimiter.
|
|
|
|
*/
|
|
|
|
static gint
|
|
|
|
find_first_boundary(tvbuff_t *tvb, gint start, const guint8 *boundary,
|
|
|
|
gint boundary_len, gint *boundary_line_len, gboolean *last_boundary)
|
|
|
|
{
|
|
|
|
gint offset = start, next_offset, line_len, boundary_start;
|
|
|
|
|
|
|
|
while (tvb_length_remaining(tvb, offset + 2 + boundary_len) > 0) {
|
|
|
|
boundary_start = offset;
|
|
|
|
if (((tvb_strneql(tvb, offset, (const guint8 *)"--", 2) == 0)
|
|
|
|
&& (tvb_strneql(tvb, offset + 2, boundary, boundary_len) == 0)))
|
|
|
|
{
|
|
|
|
/* Boundary string; now check if last */
|
|
|
|
if ((tvb_length_remaining(tvb, offset + 2 + boundary_len + 2) >= 0)
|
|
|
|
&& (tvb_strneql(tvb, offset + 2 + boundary_len,
|
|
|
|
(const guint8 *)"--", 2) == 0)) {
|
|
|
|
*last_boundary = TRUE;
|
|
|
|
} else {
|
|
|
|
*last_boundary = FALSE;
|
|
|
|
}
|
|
|
|
/* Look for line end of the boundary line */
|
|
|
|
line_len = tvb_find_line_end(tvb, offset, -1, &offset, FALSE);
|
|
|
|
if (line_len == -1) {
|
|
|
|
*boundary_line_len = -1;
|
|
|
|
} else {
|
|
|
|
*boundary_line_len = offset - boundary_start;
|
|
|
|
}
|
|
|
|
return boundary_start;
|
|
|
|
}
|
|
|
|
line_len = tvb_find_line_end(tvb, offset, -1, &next_offset, FALSE);
|
|
|
|
if (line_len == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
offset = next_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unless the first boundary, subsequent boundaries include a line-end sequence
|
|
|
|
* before the dashed boundary string.
|
|
|
|
*
|
|
|
|
* Return the offset to the 1st byte of the boundary delimiter line.
|
|
|
|
* Set boundary_line_len to the length of the entire boundary delimiter.
|
|
|
|
* Set last_boundary to TRUE if we've seen the last-boundary delimiter.
|
|
|
|
*/
|
|
|
|
static gint
|
|
|
|
find_next_boundary(tvbuff_t *tvb, gint start, const guint8 *boundary,
|
|
|
|
gint boundary_len, gint *boundary_line_len, gboolean *last_boundary)
|
|
|
|
{
|
|
|
|
gint offset = start, next_offset, line_len, boundary_start;
|
|
|
|
|
|
|
|
while (tvb_length_remaining(tvb, offset + 2 + boundary_len) > 0) {
|
|
|
|
line_len = tvb_find_line_end(tvb, offset, -1, &next_offset, FALSE);
|
|
|
|
if (line_len == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
boundary_start = offset + line_len;
|
|
|
|
if (((tvb_strneql(tvb, next_offset, (const guint8 *)"--", 2) == 0)
|
|
|
|
&& (tvb_strneql(tvb, next_offset + 2, boundary, boundary_len) == 0)))
|
|
|
|
{
|
|
|
|
/* Boundary string; now check if last */
|
|
|
|
if ((tvb_length_remaining(tvb, next_offset + 2 + boundary_len + 2) >= 0)
|
|
|
|
&& (tvb_strneql(tvb, next_offset + 2 + boundary_len,
|
|
|
|
(const guint8 *)"--", 2) == 0)) {
|
|
|
|
*last_boundary = TRUE;
|
|
|
|
} else {
|
|
|
|
*last_boundary = FALSE;
|
|
|
|
}
|
|
|
|
/* Look for line end of the boundary line */
|
|
|
|
line_len = tvb_find_line_end(tvb, next_offset, -1, &offset, FALSE);
|
|
|
|
if (line_len == -1) {
|
|
|
|
*boundary_line_len = -1;
|
|
|
|
} else {
|
|
|
|
*boundary_line_len = offset - boundary_start;
|
|
|
|
}
|
|
|
|
return boundary_start;
|
|
|
|
}
|
|
|
|
offset = next_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process the multipart preamble:
|
|
|
|
* [ preamble line-end ] dashed-boundary transport-padding line-end
|
|
|
|
*
|
|
|
|
* Return the offset to the start of the first body-part.
|
|
|
|
*/
|
|
|
|
static gint
|
|
|
|
process_preamble(proto_tree *tree, tvbuff_t *tvb, const guint8 *boundary,
|
|
|
|
gint boundary_len, gboolean *last_boundary)
|
|
|
|
{
|
2010-01-18 23:16:10 +00:00
|
|
|
gint boundary_start, boundary_line_len;
|
2004-01-16 01:32:20 +00:00
|
|
|
|
|
|
|
boundary_start = find_first_boundary(tvb, 0, boundary, boundary_len,
|
|
|
|
&boundary_line_len, last_boundary);
|
|
|
|
if (boundary_start == 0) {
|
|
|
|
if (tree) {
|
|
|
|
proto_tree_add_text(tree, tvb, boundary_start, boundary_line_len,
|
|
|
|
"First boundary: %s",
|
|
|
|
tvb_format_text(tvb, boundary_start, boundary_line_len));
|
|
|
|
}
|
|
|
|
return boundary_start + boundary_line_len;
|
|
|
|
} else if (boundary_start > 0) {
|
|
|
|
if (boundary_line_len > 0) {
|
|
|
|
gint body_part_start = boundary_start + boundary_line_len;
|
|
|
|
|
|
|
|
if (tree) {
|
|
|
|
if (body_part_start > 0) {
|
|
|
|
proto_tree_add_text(tree, tvb, 0, body_part_start,
|
|
|
|
"Preamble");
|
|
|
|
}
|
|
|
|
proto_tree_add_text(tree, tvb, boundary_start,
|
|
|
|
boundary_line_len, "First boundary: %s",
|
|
|
|
tvb_format_text(tvb, boundary_start,
|
|
|
|
boundary_line_len));
|
|
|
|
}
|
|
|
|
return body_part_start;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process a multipart body-part:
|
|
|
|
* MIME-part-headers [ line-end *OCTET ]
|
|
|
|
* line-end dashed-boundary transport-padding line-end
|
|
|
|
*
|
|
|
|
* If applicable, call a media subdissector.
|
|
|
|
*
|
|
|
|
* Return the offset to the start of the next body-part.
|
|
|
|
*/
|
|
|
|
static gint
|
|
|
|
process_body_part(proto_tree *tree, tvbuff_t *tvb, const guint8 *boundary,
|
|
|
|
gint boundary_len, packet_info *pinfo, gint start,
|
|
|
|
gboolean *last_boundary)
|
|
|
|
{
|
|
|
|
proto_tree *subtree = NULL;
|
|
|
|
proto_item *ti = NULL;
|
2007-07-14 10:15:52 +00:00
|
|
|
gint offset = start, next_offset = 0;
|
2004-01-16 01:32:20 +00:00
|
|
|
char *parameters = NULL;
|
|
|
|
gint body_start, boundary_start, boundary_line_len;
|
|
|
|
|
|
|
|
char *content_type_str = NULL;
|
2007-07-14 09:19:35 +00:00
|
|
|
char *content_encoding_str = NULL;
|
|
|
|
char *filename = NULL;
|
|
|
|
char *typename = NULL;
|
|
|
|
int len = 0;
|
|
|
|
gboolean last_field = FALSE;
|
2004-01-16 01:32:20 +00:00
|
|
|
|
|
|
|
if (tree) {
|
2011-10-15 18:46:26 +00:00
|
|
|
ti = proto_tree_add_item(tree, hf_multipart_part, tvb, start, 0, ENC_ASCII|ENC_NA);
|
2004-01-16 01:32:20 +00:00
|
|
|
subtree = proto_item_add_subtree(ti, ett_multipart_body);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Process the MIME-part-headers
|
|
|
|
*/
|
|
|
|
|
2007-07-14 09:19:35 +00:00
|
|
|
while (!last_field)
|
2004-01-16 01:32:20 +00:00
|
|
|
{
|
|
|
|
gint colon_offset;
|
2007-07-14 09:19:35 +00:00
|
|
|
char *hdr_str;
|
2005-01-05 10:38:50 +00:00
|
|
|
char *header_str;
|
2004-01-16 01:32:20 +00:00
|
|
|
|
2011-06-19 19:13:26 +00:00
|
|
|
/* Look for the end of the header (denoted by cr)
|
2007-08-09 12:17:56 +00:00
|
|
|
* 3:d argument to imf_find_field_end() maxlen; must be last offset in the tvb.
|
|
|
|
*/
|
|
|
|
next_offset = imf_find_field_end(tvb, offset, tvb_length_remaining(tvb, offset)+offset, &last_field);
|
2007-07-17 11:54:22 +00:00
|
|
|
/* If cr not found, won't have advanced - get out to avoid infinite loop! */
|
|
|
|
if (next_offset == offset) {
|
|
|
|
break;
|
|
|
|
}
|
2007-07-14 09:19:35 +00:00
|
|
|
|
|
|
|
hdr_str = tvb_get_ephemeral_string(tvb, offset, next_offset - offset);
|
|
|
|
|
2005-01-05 10:38:50 +00:00
|
|
|
header_str = unfold_and_compact_mime_header(hdr_str, &colon_offset);
|
2004-01-16 01:32:20 +00:00
|
|
|
if (colon_offset <= 0) {
|
|
|
|
if (tree) {
|
|
|
|
proto_tree_add_text(subtree, tvb, offset, next_offset - offset,
|
|
|
|
"%s",
|
|
|
|
tvb_format_text(tvb, offset, next_offset - offset));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
gint hf_index;
|
|
|
|
|
|
|
|
/* Split header name from header value */
|
|
|
|
header_str[colon_offset] = '\0';
|
|
|
|
hf_index = is_known_multipart_header(header_str, colon_offset);
|
|
|
|
|
|
|
|
if (hf_index == -1) {
|
|
|
|
if (tree) {
|
|
|
|
proto_tree_add_text(subtree, tvb, offset,
|
|
|
|
next_offset - offset,
|
|
|
|
"%s",
|
|
|
|
tvb_format_text(tvb, offset, next_offset - offset));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
char *value_str = header_str + colon_offset + 1;
|
|
|
|
|
|
|
|
if (tree) {
|
|
|
|
proto_tree_add_string_format(subtree,
|
|
|
|
hf_header_array[hf_index], tvb,
|
|
|
|
offset, next_offset - offset,
|
|
|
|
(const char *)value_str, "%s",
|
|
|
|
tvb_format_text(tvb, offset, next_offset - offset));
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (hf_index) {
|
|
|
|
case POS_CONTENT_TYPE:
|
|
|
|
{
|
|
|
|
/* The Content-Type starts at colon_offset + 1 */
|
|
|
|
gint semicolon_offset = index_of_char(
|
|
|
|
value_str, ';');
|
|
|
|
|
|
|
|
if (semicolon_offset > 0) {
|
|
|
|
value_str[semicolon_offset] = '\0';
|
2005-09-05 13:20:56 +00:00
|
|
|
parameters = ep_strdup(value_str + semicolon_offset + 1);
|
2004-01-16 01:32:20 +00:00
|
|
|
} else {
|
|
|
|
parameters = NULL;
|
|
|
|
}
|
2008-04-07 05:22:54 +00:00
|
|
|
|
2004-01-16 01:32:20 +00:00
|
|
|
content_type_str = g_ascii_strdown(value_str, -1);
|
2008-04-07 05:22:54 +00:00
|
|
|
|
2006-11-16 14:35:52 +00:00
|
|
|
/* Show content-type in root 'part' label */
|
|
|
|
proto_item_append_text(ti, " (%s)", content_type_str);
|
2011-06-19 19:13:26 +00:00
|
|
|
|
2007-07-14 09:19:35 +00:00
|
|
|
/* find the "name" parameter in case we don't find a content disposition "filename" */
|
2007-07-14 09:58:08 +00:00
|
|
|
if((typename = find_parameter(parameters, "name=", &len)) != NULL) {
|
2007-07-14 09:19:35 +00:00
|
|
|
typename = g_strndup(typename, len);
|
|
|
|
}
|
2004-01-16 01:32:20 +00:00
|
|
|
}
|
2007-07-14 09:19:35 +00:00
|
|
|
|
|
|
|
|
2004-01-16 01:32:20 +00:00
|
|
|
break;
|
2007-07-14 09:19:35 +00:00
|
|
|
case POS_CONTENT_TRANSFER_ENCODING:
|
|
|
|
{
|
|
|
|
/* The Content-Transfeing starts at colon_offset + 1 */
|
|
|
|
gint cr_offset = index_of_char(value_str, '\r');
|
2004-01-16 01:32:20 +00:00
|
|
|
|
2007-07-14 09:19:35 +00:00
|
|
|
if (cr_offset > 0) {
|
|
|
|
value_str[cr_offset] = '\0';
|
|
|
|
}
|
2008-04-07 05:22:54 +00:00
|
|
|
|
2007-07-14 09:19:35 +00:00
|
|
|
content_encoding_str = g_ascii_strdown(value_str, -1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case POS_CONTENT_DISPOSITION:
|
|
|
|
{
|
|
|
|
/* find the "filename" parameter */
|
2007-07-14 09:58:08 +00:00
|
|
|
if((filename = find_parameter(value_str, "filename=", &len)) != NULL) {
|
2007-07-14 09:19:35 +00:00
|
|
|
filename = g_strndup(filename, len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2004-01-16 01:32:20 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-01-05 10:38:50 +00:00
|
|
|
g_free(header_str);
|
2004-01-16 01:32:20 +00:00
|
|
|
offset = next_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
body_start = next_offset;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process the body
|
|
|
|
*/
|
|
|
|
|
|
|
|
boundary_start = find_next_boundary(tvb, body_start, boundary, boundary_len,
|
|
|
|
&boundary_line_len, last_boundary);
|
|
|
|
if (boundary_start > 0) {
|
|
|
|
gint body_len = boundary_start - body_start;
|
|
|
|
tvbuff_t *tmp_tvb = tvb_new_subset(tvb, body_start,
|
|
|
|
body_len, body_len);
|
|
|
|
|
|
|
|
if (content_type_str) {
|
2007-07-14 09:19:35 +00:00
|
|
|
|
2004-01-16 01:32:20 +00:00
|
|
|
/*
|
|
|
|
* subdissection
|
|
|
|
*/
|
|
|
|
void *save_private_data = pinfo->private_data;
|
|
|
|
gboolean dissected;
|
|
|
|
|
2011-06-19 19:13:26 +00:00
|
|
|
/*
|
2007-07-14 09:19:35 +00:00
|
|
|
* Try and remove any content transfer encoding so that each sub-dissector
|
2011-06-19 19:13:26 +00:00
|
|
|
* doesn't have to do it itself
|
2007-07-14 09:19:35 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
if(content_encoding_str && remove_base64_encoding) {
|
|
|
|
|
strcasecmp(), strncasecmp(), g_strcasecmp(), and g_strncasecmp() delenda
est. Use g_ascii_strcasecmp() and g_ascii_strncasecmp(), and supply our
own versions if they're missing from GLib (as is the case with GLib
1.x).
In the code to build the list of named fields for Diameter, don't use
g_strdown(); do our own g_ascii_-style upper-case to lower-case mapping
in the hash function and use g_ascii_strcasecmp() in the compare
function.
We do this because there is no guarantee that toupper(), tolower(), and
functions that use them will, for example, map between "I" and "i" in
all locales; in Turkish locales, for example, there are, in both
upper case and lower case, versions of "i" with and without a dot, and
the upper-case version of "i" is "I"-with-a-dot and the lower-case
version of "I" is "i"-without-a-dot. This causes strings that should
match not to match.
This finishes fixing bug 2010 - an earlier checkin prevented the crash
(as there are other ways to produce the same crash, e.g. a bogus
dictionary.xml file), but didn't fix the case-insensitive string matching.
svn path=/trunk/; revision=23623
2007-11-27 18:52:51 +00:00
|
|
|
if(!g_ascii_strncasecmp(content_encoding_str, "base64", 6))
|
2007-07-14 09:19:35 +00:00
|
|
|
tmp_tvb = base64_decode(pinfo, tmp_tvb, filename ? filename : (typename ? typename : content_type_str));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2004-01-16 01:32:20 +00:00
|
|
|
pinfo->private_data = parameters;
|
2004-02-06 01:07:51 +00:00
|
|
|
/*
|
|
|
|
* First try the dedicated multipart dissector table
|
|
|
|
*/
|
|
|
|
dissected = dissector_try_string(multipart_media_subdissector_table,
|
|
|
|
content_type_str, tmp_tvb, pinfo, subtree);
|
|
|
|
if (! dissected) {
|
|
|
|
/*
|
|
|
|
* Fall back to the default media dissector table
|
|
|
|
*/
|
|
|
|
dissected = dissector_try_string(media_type_dissector_table,
|
2004-01-16 01:32:20 +00:00
|
|
|
content_type_str, tmp_tvb, pinfo, subtree);
|
2004-02-06 01:07:51 +00:00
|
|
|
}
|
2005-09-05 11:59:22 +00:00
|
|
|
if (! dissected) {
|
|
|
|
const char *save_match_string = pinfo->match_string;
|
|
|
|
pinfo->match_string = content_type_str;
|
|
|
|
call_dissector(media_handle, tmp_tvb, pinfo, subtree);
|
|
|
|
pinfo->match_string = save_match_string;
|
|
|
|
}
|
2004-01-16 01:32:20 +00:00
|
|
|
pinfo->private_data = save_private_data;
|
|
|
|
g_free(content_type_str);
|
|
|
|
content_type_str = NULL;
|
|
|
|
parameters = NULL; /* Shares same memory as content_type_str */
|
|
|
|
} else {
|
|
|
|
call_dissector(data_handle, tmp_tvb, pinfo, subtree);
|
|
|
|
}
|
|
|
|
if (tree) {
|
2005-09-05 11:59:22 +00:00
|
|
|
proto_item_set_len(ti, boundary_start - start);
|
2004-01-16 01:32:20 +00:00
|
|
|
if (*last_boundary == TRUE) {
|
|
|
|
proto_tree_add_text(tree, tvb,
|
|
|
|
boundary_start, boundary_line_len,
|
|
|
|
"Last boundary: %s",
|
|
|
|
tvb_format_text(tvb, boundary_start,
|
|
|
|
boundary_line_len));
|
|
|
|
} else {
|
|
|
|
proto_tree_add_text(tree, tvb,
|
|
|
|
boundary_start, boundary_line_len,
|
|
|
|
"Boundary: %s",
|
|
|
|
tvb_format_text(tvb, boundary_start,
|
|
|
|
boundary_line_len));
|
|
|
|
}
|
|
|
|
}
|
2007-07-14 09:19:35 +00:00
|
|
|
|
2009-03-13 22:06:48 +00:00
|
|
|
g_free(filename);
|
|
|
|
g_free(typename);
|
2007-07-14 09:19:35 +00:00
|
|
|
|
2004-01-16 01:32:20 +00:00
|
|
|
return boundary_start + boundary_line_len;
|
|
|
|
}
|
|
|
|
|
2012-04-30 15:57:39 +00:00
|
|
|
g_free(filename);
|
|
|
|
g_free(typename);
|
|
|
|
|
2004-01-16 01:32:20 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call this method to actually dissect the multipart body.
|
|
|
|
* NOTE - Only do so if a boundary string has been found!
|
|
|
|
*/
|
|
|
|
static void dissect_multipart(tvbuff_t *tvb, packet_info *pinfo,
|
|
|
|
proto_tree *tree)
|
|
|
|
{
|
|
|
|
proto_tree *subtree = NULL;
|
|
|
|
proto_item *ti = NULL;
|
|
|
|
multipart_info_t *m_info = get_multipart_info(pinfo);
|
|
|
|
gint header_start = 0;
|
|
|
|
guint8 *boundary;
|
|
|
|
gint boundary_len;
|
|
|
|
gboolean last_boundary = FALSE;
|
|
|
|
|
|
|
|
if (m_info == NULL) {
|
|
|
|
/*
|
|
|
|
* We can't get the required multipart information
|
|
|
|
*/
|
|
|
|
proto_tree_add_text(tree, tvb, 0, -1,
|
|
|
|
"The multipart dissector could not find "
|
|
|
|
"the required boundary parameter.");
|
|
|
|
call_dissector(data_handle, tvb, pinfo, tree);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
boundary = (guint8 *)m_info->boundary;
|
|
|
|
boundary_len = m_info->boundary_length;
|
|
|
|
/* Clean up the memory if an exception is thrown */
|
|
|
|
/* CLEANUP_PUSH(cleanup_multipart_info, m_info); */
|
|
|
|
|
|
|
|
/* Add stuff to the protocol tree */
|
|
|
|
if (tree) {
|
2006-09-26 13:01:27 +00:00
|
|
|
proto_item *type_ti;
|
2004-01-16 01:32:20 +00:00
|
|
|
ti = proto_tree_add_item(tree, proto_multipart,
|
2011-10-21 02:10:19 +00:00
|
|
|
tvb, 0, -1, ENC_NA);
|
2004-01-16 01:32:20 +00:00
|
|
|
subtree = proto_item_add_subtree(ti, ett_multipart);
|
|
|
|
proto_item_append_text(ti, ", Type: %s, Boundary: \"%s\"",
|
|
|
|
m_info->type, m_info->boundary);
|
2006-09-26 13:01:27 +00:00
|
|
|
|
|
|
|
/* Show multi-part type as a generated field */
|
|
|
|
type_ti = proto_tree_add_string(subtree, hf_multipart_type,
|
|
|
|
tvb, 0, 0, pinfo->match_string);
|
|
|
|
PROTO_ITEM_SET_GENERATED(type_ti);
|
2004-01-16 01:32:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make no entries in Protocol column and Info column on summary display,
|
|
|
|
* but stop sub-dissectors from clearing entered text in summary display.
|
|
|
|
*/
|
2011-09-26 17:50:54 +00:00
|
|
|
col_set_fence(pinfo->cinfo, COL_INFO);
|
2004-01-16 01:32:20 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Process the multipart preamble
|
|
|
|
*/
|
|
|
|
header_start = process_preamble(subtree, tvb, boundary,
|
|
|
|
boundary_len, &last_boundary);
|
|
|
|
if (header_start == -1) {
|
|
|
|
call_dissector(data_handle, tvb, pinfo, subtree);
|
|
|
|
/* Clean up the dynamically allocated memory */
|
|
|
|
cleanup_multipart_info(m_info);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Process the encapsulated bodies
|
|
|
|
*/
|
|
|
|
while (last_boundary == FALSE) {
|
|
|
|
header_start = process_body_part(subtree, tvb, boundary, boundary_len,
|
|
|
|
pinfo, header_start, &last_boundary);
|
|
|
|
if (header_start == -1) {
|
|
|
|
/* Clean up the dynamically allocated memory */
|
|
|
|
cleanup_multipart_info(m_info);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Process the multipart trailer
|
|
|
|
*/
|
|
|
|
if (tree) {
|
|
|
|
if (tvb_length_remaining(tvb, header_start) > 0) {
|
|
|
|
proto_tree_add_text(subtree, tvb, header_start, -1, "Trailer");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Clean up the dynamically allocated memory */
|
|
|
|
cleanup_multipart_info(m_info);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns index of method in multipart_headers */
|
|
|
|
static gint
|
|
|
|
is_known_multipart_header(const char *header_str, guint len)
|
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
for (i = 1; i < array_length(multipart_headers); i++) {
|
2005-01-20 01:26:34 +00:00
|
|
|
if (len == strlen(multipart_headers[i].name) &&
|
strcasecmp(), strncasecmp(), g_strcasecmp(), and g_strncasecmp() delenda
est. Use g_ascii_strcasecmp() and g_ascii_strncasecmp(), and supply our
own versions if they're missing from GLib (as is the case with GLib
1.x).
In the code to build the list of named fields for Diameter, don't use
g_strdown(); do our own g_ascii_-style upper-case to lower-case mapping
in the hash function and use g_ascii_strcasecmp() in the compare
function.
We do this because there is no guarantee that toupper(), tolower(), and
functions that use them will, for example, map between "I" and "i" in
all locales; in Turkish locales, for example, there are, in both
upper case and lower case, versions of "i" with and without a dot, and
the upper-case version of "i" is "I"-with-a-dot and the lower-case
version of "I" is "i"-without-a-dot. This causes strings that should
match not to match.
This finishes fixing bug 2010 - an earlier checkin prevented the crash
(as there are other ways to produce the same crash, e.g. a bogus
dictionary.xml file), but didn't fix the case-insensitive string matching.
svn path=/trunk/; revision=23623
2007-11-27 18:52:51 +00:00
|
|
|
g_ascii_strncasecmp(header_str, multipart_headers[i].name, len) == 0)
|
2005-01-20 01:26:34 +00:00
|
|
|
return i;
|
|
|
|
if (multipart_headers[i].compact_name != NULL &&
|
|
|
|
len == strlen(multipart_headers[i].compact_name) &&
|
strcasecmp(), strncasecmp(), g_strcasecmp(), and g_strncasecmp() delenda
est. Use g_ascii_strcasecmp() and g_ascii_strncasecmp(), and supply our
own versions if they're missing from GLib (as is the case with GLib
1.x).
In the code to build the list of named fields for Diameter, don't use
g_strdown(); do our own g_ascii_-style upper-case to lower-case mapping
in the hash function and use g_ascii_strcasecmp() in the compare
function.
We do this because there is no guarantee that toupper(), tolower(), and
functions that use them will, for example, map between "I" and "i" in
all locales; in Turkish locales, for example, there are, in both
upper case and lower case, versions of "i" with and without a dot, and
the upper-case version of "i" is "I"-with-a-dot and the lower-case
version of "I" is "i"-without-a-dot. This causes strings that should
match not to match.
This finishes fixing bug 2010 - an earlier checkin prevented the crash
(as there are other ways to produce the same crash, e.g. a bogus
dictionary.xml file), but didn't fix the case-insensitive string matching.
svn path=/trunk/; revision=23623
2007-11-27 18:52:51 +00:00
|
|
|
g_ascii_strncasecmp(header_str, multipart_headers[i].compact_name, len) == 0)
|
2004-01-16 01:32:20 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2006-05-21 04:49:01 +00:00
|
|
|
* Register the protocol with Wireshark.
|
2004-01-16 01:32:20 +00:00
|
|
|
*
|
|
|
|
* This format is required because a script is used to build the C function
|
|
|
|
* that calls all the protocol registration.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
proto_register_multipart(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Setup list of header fields See Section 1.6.1 for details */
|
|
|
|
static hf_register_info hf[] = {
|
|
|
|
{ &hf_multipart_type,
|
|
|
|
{ "Type",
|
|
|
|
"mime_multipart.type",
|
|
|
|
FT_STRING, BASE_NONE, NULL, 0x00,
|
2006-09-26 13:01:27 +00:00
|
|
|
"MIME multipart encapsulation type", HFILL
|
2004-01-16 01:32:20 +00:00
|
|
|
}
|
|
|
|
},
|
2006-11-16 14:35:52 +00:00
|
|
|
{ &hf_multipart_part,
|
|
|
|
{ "Encapsulated multipart part",
|
|
|
|
"mime_multipart.part",
|
|
|
|
FT_STRING, BASE_NONE, NULL, 0x00,
|
From Kovarththanan Rajaratnam via bug 3548:
(1) Trailing/leading spaces are removed from 'name's/'blurb's
(2) Duplicate 'blurb's are replaced with NULL
(3) Empty ("") 'blurb's are replaced with NULL
(4) BASE_NONE, NULL, 0x0 are used for 'display', 'strings' and 'bitmask' fields
for FT_NONE, FT_BYTES, FT_IPv4, FT_IPv6, FT_ABSOLUTE_TIME, FT_RELATIVE_TIME,
FT_PROTOCOL, FT_STRING and FT_STRINGZ field types
(5) Only allow non-zero value for 'display' if 'bitmask' is non-zero
svn path=/trunk/; revision=28770
2009-06-18 21:30:42 +00:00
|
|
|
NULL, HFILL
|
2006-11-16 14:35:52 +00:00
|
|
|
}
|
|
|
|
},
|
2004-01-16 01:32:20 +00:00
|
|
|
{ &hf_header_array[POS_CONTENT_DISPOSITION],
|
|
|
|
{ "Content-Disposition",
|
|
|
|
"mime_multipart.header.content-disposition",
|
|
|
|
FT_STRING, BASE_NONE, NULL, 0x00,
|
2006-09-26 13:01:27 +00:00
|
|
|
"RFC 2183: Content-Disposition Header", HFILL
|
2004-01-16 01:32:20 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{ &hf_header_array[POS_CONTENT_ENCODING],
|
|
|
|
{ "Content-Encoding",
|
|
|
|
"mime_multipart.header.content-encoding",
|
|
|
|
FT_STRING, BASE_NONE, NULL, 0x00,
|
2006-09-26 13:01:27 +00:00
|
|
|
"Content-Encoding Header", HFILL
|
2004-01-16 01:32:20 +00:00
|
|
|
}
|
|
|
|
},
|
2006-09-20 12:12:18 +00:00
|
|
|
{ &hf_header_array[POS_CONTENT_ID],
|
|
|
|
{ "Content-Id",
|
|
|
|
"mime_multipart.header.content-id",
|
|
|
|
FT_STRING, BASE_NONE, NULL, 0x00,
|
|
|
|
"RFC 2045: Content-Id Header", HFILL
|
|
|
|
}
|
|
|
|
},
|
2004-01-16 01:32:20 +00:00
|
|
|
{ &hf_header_array[POS_CONTENT_LANGUAGE],
|
|
|
|
{ "Content-Language",
|
|
|
|
"mime_multipart.header.content-language",
|
|
|
|
FT_STRING, BASE_NONE, NULL, 0x00,
|
2006-09-26 13:01:27 +00:00
|
|
|
"Content-Language Header", HFILL
|
2004-01-16 01:32:20 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{ &hf_header_array[POS_CONTENT_LENGTH],
|
|
|
|
{ "Content-Length",
|
|
|
|
"mime_multipart.header.content-length",
|
|
|
|
FT_STRING, BASE_NONE, NULL, 0x0,
|
2006-09-26 13:01:27 +00:00
|
|
|
"Content-Length Header", HFILL
|
2004-01-16 01:32:20 +00:00
|
|
|
}
|
|
|
|
},
|
2006-09-20 12:12:18 +00:00
|
|
|
{ &hf_header_array[POS_CONTENT_TRANSFER_ENCODING],
|
|
|
|
{ "Content-Transfer-Encoding",
|
|
|
|
"mime_multipart.header.content-transfer-encoding",
|
|
|
|
FT_STRING, BASE_NONE, NULL, 0x00,
|
|
|
|
"RFC 2045: Content-Transfer-Encoding Header", HFILL
|
|
|
|
}
|
|
|
|
},
|
2004-01-16 01:32:20 +00:00
|
|
|
{ &hf_header_array[POS_CONTENT_TYPE],
|
|
|
|
{ "Content-Type",
|
|
|
|
"mime_multipart.header.content-type",
|
|
|
|
FT_STRING, BASE_NONE,NULL,0x0,
|
2006-09-26 13:01:27 +00:00
|
|
|
"Content-Type Header", HFILL
|
2004-01-16 01:32:20 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Preferences
|
|
|
|
*/
|
|
|
|
module_t *multipart_module;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup protocol subtree array
|
|
|
|
*/
|
|
|
|
static gint *ett[] = {
|
|
|
|
&ett_multipart,
|
|
|
|
&ett_multipart_main,
|
|
|
|
&ett_multipart_body,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Register the protocol name and description
|
|
|
|
*/
|
|
|
|
proto_multipart = proto_register_protocol(
|
|
|
|
"MIME Multipart Media Encapsulation",
|
|
|
|
"MIME multipart",
|
|
|
|
"mime_multipart");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Required function calls to register
|
|
|
|
* the header fields and subtrees used.
|
|
|
|
*/
|
|
|
|
proto_register_field_array(proto_multipart, hf, array_length(hf));
|
|
|
|
proto_register_subtree_array(ett, array_length(ett));
|
|
|
|
|
|
|
|
multipart_module = prefs_register_protocol(proto_multipart, NULL);
|
|
|
|
|
|
|
|
prefs_register_bool_preference(multipart_module,
|
|
|
|
"display_unknown_body_as_text",
|
|
|
|
"Display bodies without media type as text",
|
|
|
|
"Display multipart bodies with no media type dissector"
|
|
|
|
" as raw text (may cause problems with binary data).",
|
|
|
|
&display_unknown_body_as_text);
|
2004-02-06 01:07:51 +00:00
|
|
|
|
2007-07-14 09:19:35 +00:00
|
|
|
prefs_register_bool_preference(multipart_module,
|
|
|
|
"remove_base64_encoding",
|
|
|
|
"Remove base64 encoding from bodies",
|
|
|
|
"Remove any base64 content-transfer encoding from bodies. "
|
|
|
|
"This supports export of the body and its further dissection.",
|
|
|
|
&remove_base64_encoding);
|
|
|
|
|
2004-02-06 01:07:51 +00:00
|
|
|
/*
|
|
|
|
* Dissectors requiring different behavior in cases where the media
|
|
|
|
* is contained in a multipart entity should register their multipart
|
|
|
|
* dissector in the dissector table below, which is similar to the
|
|
|
|
* "media_type" dissector table defined in the HTTP dissector code.
|
|
|
|
*/
|
|
|
|
multipart_media_subdissector_table = register_dissector_table(
|
|
|
|
"multipart_media_type",
|
|
|
|
"Internet media type (for multipart processing)",
|
|
|
|
FT_STRING, BASE_NONE);
|
2004-01-16 01:32:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* If this dissector uses sub-dissector registration add a registration routine.
|
|
|
|
This format is required because a script is used to find these routines and
|
|
|
|
create the code that calls these routines.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
proto_reg_handoff_multipart(void)
|
|
|
|
{
|
|
|
|
dissector_handle_t multipart_handle;
|
|
|
|
|
|
|
|
/*
|
2004-04-30 17:07:21 +00:00
|
|
|
* When we cannot display the data, call the data dissector.
|
|
|
|
* When there is no dissector for the given media, call the media dissector.
|
2004-01-16 01:32:20 +00:00
|
|
|
*/
|
|
|
|
data_handle = find_dissector("data");
|
2004-04-30 17:07:21 +00:00
|
|
|
media_handle = find_dissector("media");
|
2004-01-16 01:32:20 +00:00
|
|
|
|
2008-11-13 01:31:57 +00:00
|
|
|
/*
|
|
|
|
* Get the content type and Internet media type table
|
|
|
|
*/
|
|
|
|
media_type_dissector_table = find_dissector_table("media_type");
|
|
|
|
|
2004-01-16 01:32:20 +00:00
|
|
|
/*
|
|
|
|
* Handle for multipart dissection
|
|
|
|
*/
|
|
|
|
multipart_handle = create_dissector_handle(
|
|
|
|
dissect_multipart, proto_multipart);
|
|
|
|
|
|
|
|
dissector_add_string("media_type",
|
|
|
|
"multipart/mixed", multipart_handle);
|
|
|
|
dissector_add_string("media_type",
|
|
|
|
"multipart/related", multipart_handle);
|
|
|
|
dissector_add_string("media_type",
|
|
|
|
"multipart/alternative", multipart_handle);
|
2004-01-22 23:47:59 +00:00
|
|
|
dissector_add_string("media_type",
|
|
|
|
"multipart/form-data", multipart_handle);
|
2011-10-06 19:26:21 +00:00
|
|
|
dissector_add_string("media_type",
|
|
|
|
"multipart/report", multipart_handle);
|
2004-01-16 01:32:20 +00:00
|
|
|
|
2010-10-27 06:48:39 +00:00
|
|
|
/*
|
|
|
|
* Supply an entry to use for unknown multipart subtype.
|
|
|
|
* See RFC 2046, section 5.1.3
|
|
|
|
*/
|
|
|
|
dissector_add_string("media_type",
|
|
|
|
"multipart/", multipart_handle);
|
2004-01-16 01:32:20 +00:00
|
|
|
}
|