diff options
Diffstat (limited to '')
-rw-r--r-- | epan/dissectors/packet-xml.c | 432 |
1 files changed, 306 insertions, 126 deletions
diff --git a/epan/dissectors/packet-xml.c b/epan/dissectors/packet-xml.c index e7a7a960..6a126454 100644 --- a/epan/dissectors/packet-xml.c +++ b/epan/dissectors/packet-xml.c @@ -26,8 +26,12 @@ #include <epan/prefs.h> #include <epan/expert.h> #include <epan/iana_charsets.h> +#include <epan/asn1.h> #include <wsutil/str_util.h> #include <wsutil/report_message.h> +#include <wsutil/wsgcrypt.h> +#include "packet-kerberos.h" +#include "read_keytab_file.h" #include "packet-xml.h" #include "packet-acdr.h" @@ -37,26 +41,31 @@ void proto_reg_handoff_xml(void); struct _attr_reg_data { wmem_array_t *hf; - const gchar *basename; + const char *basename; }; -static gint ett_dtd = -1; -static gint ett_xmpli = -1; +static int ett_dtd; +static int ett_xmpli; -static int hf_unknowwn_attrib = -1; -static int hf_comment = -1; -static int hf_xmlpi = -1; -static int hf_dtd_tag = -1; -static int hf_doctype = -1; -static int hf_cdatasection = -1; +static int hf_unknowwn_attrib; +static int hf_comment; +static int hf_xmlpi; +static int hf_dtd_tag; +static int hf_doctype; +static int hf_cdatasection; -static expert_field ei_xml_closing_unopened_tag = EI_INIT; -static expert_field ei_xml_closing_unopened_xmpli_tag = EI_INIT; -static expert_field ei_xml_unrecognized_text = EI_INIT; +static expert_field ei_xml_closing_unopened_tag; +static expert_field ei_xml_closing_unopened_xmpli_tag; +static expert_field ei_xml_unrecognized_text; /* dissector handles */ static dissector_handle_t xml_handle; +static dissector_handle_t gssapi_handle; + +/* Port 3702 is IANA-registered for Web Service Discovery, which uses + * SOAP-over-UDP to send XML */ +#define XML_UDP_PORT_RANGE "3702" /* parser definitions */ static tvbparse_wanted_t *want; @@ -70,8 +79,8 @@ static xml_ns_t xml_ns = {"xml", "/", -1, -1, -1, NULL, NULL, NULL}; static xml_ns_t unknown_ns = {"unknown", "?", -1, -1, -1, NULL, NULL, NULL}; static xml_ns_t *root_ns; -static gboolean pref_heuristic_unicode = FALSE; -static gint pref_default_encoding = IANA_CS_UTF_8; +static bool pref_heuristic_unicode; +static int pref_default_encoding = IANA_CS_UTF_8; #define XML_CDATA -1000 @@ -82,7 +91,7 @@ static wmem_array_t *hf_arr; static GArray *ett_arr; static GRegex* encoding_pattern; -static const gchar *default_media_types[] = { +static const char *default_media_types[] = { "text/xml", "text/vnd.wap.wml", "text/vnd.wap.si", @@ -256,18 +265,18 @@ static void insert_xml_frame(xml_frame_t *parent, xml_frame_t *new_child) /* Try to get the 'encoding' attribute from XML declaration, and convert it to * Wireshark character encoding. */ -static guint -get_char_encoding(tvbuff_t* tvb, packet_info* pinfo, gchar** ret_encoding_name) { - guint32 iana_charset_id; - guint ws_encoding_id; - gchar* encoding_str; +static unsigned +get_char_encoding(tvbuff_t* tvb, packet_info* pinfo, char** ret_encoding_name) { + uint32_t iana_charset_id; + unsigned ws_encoding_id; + char* encoding_str; GMatchInfo* match_info; - const gchar* xmldecl = (gchar*)tvb_get_string_enc(pinfo->pool, tvb, 0, + const char* xmldecl = (char*)tvb_get_string_enc(pinfo->pool, tvb, 0, MIN(100, tvb_captured_length(tvb)), ENC_UTF_8); g_regex_match(encoding_pattern, xmldecl, 0, &match_info); if (g_match_info_matches(match_info)) { - gchar* match_ret = g_match_info_fetch(match_info, 1); + char* match_ret = g_match_info_fetch(match_info, 1); encoding_str = ascii_strup_inplace(wmem_strdup(pinfo->pool, match_ret)); g_free(match_ret); /* Get the iana charset enum number by the name of the charset. */ @@ -281,7 +290,7 @@ get_char_encoding(tvbuff_t* tvb, packet_info* pinfo, gchar** ret_encoding_name) } g_match_info_free(match_info); - ws_encoding_id = mibenum_charset_to_encoding((guint)iana_charset_id); + ws_encoding_id = mibenum_charset_to_encoding((unsigned)iana_charset_id); /* UTF-8 compatible with ASCII */ if (ws_encoding_id == (ENC_NA | ENC_ASCII)) { @@ -302,10 +311,10 @@ dissect_xml(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_) xml_frame_t *current_frame; const char *colinfo_str; tvbuff_t *decoded; - guint16 try_bom; + uint16_t try_bom; if (stack != NULL) - g_ptr_array_free(stack, TRUE); + g_ptr_array_free(stack, true); stack = g_ptr_array_new(); current_frame = wmem_new(wmem_packet_scope(), xml_frame_t); @@ -321,28 +330,28 @@ dissect_xml(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_) try_bom = tvb_get_ntohs(tvb, 0); if (try_bom == 0xFEFF) { /* UTF-16BE */ - const guint8 *data_str = tvb_get_string_enc(pinfo->pool, tvb, 0, tvb_captured_length(tvb), ENC_UTF_16|ENC_BIG_ENDIAN); + const uint8_t *data_str = tvb_get_string_enc(pinfo->pool, tvb, 0, tvb_captured_length(tvb), ENC_UTF_16|ENC_BIG_ENDIAN); size_t l = strlen(data_str); - decoded = tvb_new_child_real_data(tvb, data_str, (guint)l, (gint)l); + decoded = tvb_new_child_real_data(tvb, data_str, (unsigned)l, (int)l); add_new_data_source(pinfo, decoded, "Decoded UTF-16BE text"); } else if(try_bom == 0xFFFE) { /* UTF-16LE (or possibly UTF-32LE, but Wireshark doesn't support UTF-32) */ - const guint8 *data_str = tvb_get_string_enc(pinfo->pool, tvb, 0, tvb_captured_length(tvb), ENC_UTF_16|ENC_LITTLE_ENDIAN); + const uint8_t *data_str = tvb_get_string_enc(pinfo->pool, tvb, 0, tvb_captured_length(tvb), ENC_UTF_16|ENC_LITTLE_ENDIAN); size_t l = strlen(data_str); - decoded = tvb_new_child_real_data(tvb, data_str, (guint)l, (gint)l); + decoded = tvb_new_child_real_data(tvb, data_str, (unsigned)l, (int)l); add_new_data_source(pinfo, decoded, "Decoded UTF-16LE text"); } /* Could also test if try_bom is 0xnn00 or 0x00nn to guess endianness if we wanted */ else { /* Get character encoding according to XML declaration or preference. */ - gchar* encoding_name; - guint encoding = get_char_encoding(tvb, pinfo, &encoding_name); + char* encoding_name; + unsigned encoding = get_char_encoding(tvb, pinfo, &encoding_name); /* Encoding string with encoding, either with or without BOM */ - const guint8 *data_str = tvb_get_string_enc(pinfo->pool, tvb, 0, tvb_captured_length(tvb), encoding); + const uint8_t *data_str = tvb_get_string_enc(pinfo->pool, tvb, 0, tvb_captured_length(tvb), encoding); size_t l = strlen(data_str); - decoded = tvb_new_child_real_data(tvb, data_str, (guint)l, (gint)l); + decoded = tvb_new_child_real_data(tvb, data_str, (unsigned)l, (int)l); add_new_data_source(pinfo, decoded, wmem_strdup_printf(pinfo->pool, "Decoded %s text", encoding_name)); } @@ -350,6 +359,8 @@ dissect_xml(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_) current_frame->start_offset = 0; current_frame->length = tvb_captured_length(decoded); + current_frame->decryption_keys = wmem_map_new(wmem_packet_scope(), g_str_hash, g_str_equal); + root_ns = NULL; if (pinfo->match_string) @@ -381,17 +392,17 @@ dissect_xml(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_) return tvb_captured_length(tvb); } -static gboolean dissect_xml_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) +static bool dissect_xml_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) { if (tvbparse_peek(tvbparse_init(pinfo->pool, tvb, 0, -1, NULL, want_ignore), want_heur)) { dissect_xml(tvb, pinfo, tree, data); - return TRUE; + return true; } else if (pref_heuristic_unicode) { - const guint8 *data_str; + const uint8_t *data_str; tvbuff_t *unicode_tvb; - guint16 try_bom; + uint16_t try_bom; /* XXX - UCS-2, or UTF-16? */ - gint enc = ENC_UCS_2|ENC_LITTLE_ENDIAN; + int enc = ENC_UCS_2|ENC_LITTLE_ENDIAN; size_t l; try_bom = tvb_get_ntohs(tvb, 0); @@ -404,17 +415,17 @@ static gboolean dissect_xml_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree * data_str = tvb_get_string_enc(pinfo->pool, tvb, 0, tvb_captured_length(tvb), enc); l = strlen(data_str); - unicode_tvb = tvb_new_child_real_data(tvb, data_str, (guint)l, (gint)l); + unicode_tvb = tvb_new_child_real_data(tvb, data_str, (unsigned)l, (int)l); if (tvbparse_peek(tvbparse_init(pinfo->pool, unicode_tvb, 0, -1, NULL, want_ignore), want_heur)) { add_new_data_source(pinfo, unicode_tvb, "UTF8"); dissect_xml(unicode_tvb, pinfo, tree, data); - return TRUE; + return true; } } - return FALSE; + return false; } -xml_frame_t *xml_get_tag(xml_frame_t *frame, const gchar *name) +xml_frame_t *xml_get_tag(xml_frame_t *frame, const char *name) { xml_frame_t *tag = NULL; @@ -435,7 +446,7 @@ xml_frame_t *xml_get_tag(xml_frame_t *frame, const gchar *name) return tag; } -xml_frame_t *xml_get_attrib(xml_frame_t *frame, const gchar *name) +xml_frame_t *xml_get_attrib(xml_frame_t *frame, const char *name) { xml_frame_t *attr = NULL; @@ -473,13 +484,14 @@ static void after_token(void *tvbparse_data, const void *wanted_data _U_, tvbpar GPtrArray *stack = (GPtrArray *)tvbparse_data; xml_frame_t *current_frame = (xml_frame_t *)g_ptr_array_index(stack, stack->len - 1); int hfid; - gboolean is_cdata = FALSE; + bool is_cdata = false; proto_item *pi; - xml_frame_t *new_frame; + xml_frame_t *new_frame = NULL; + char *text = NULL; if (tok->id == XML_CDATA) { hfid = current_frame->ns ? current_frame->ns->hf_cdata : xml_ns.hf_cdata; - is_cdata = TRUE; + is_cdata = true; } else if ( tok->id > 0) { hfid = tok->id; } else { @@ -488,8 +500,8 @@ static void after_token(void *tvbparse_data, const void *wanted_data _U_, tvbpar pi = proto_tree_add_item(current_frame->tree, hfid, tok->tvb, tok->offset, tok->len, ENC_UTF_8|ENC_NA); - proto_item_set_text(pi, "%s", - tvb_format_text(wmem_packet_scope(), tok->tvb, tok->offset, tok->len)); + text = tvb_format_text(wmem_packet_scope(), tok->tvb, tok->offset, tok->len); + proto_item_set_text(pi, "%s", text); if (is_cdata) { new_frame = wmem_new(wmem_packet_scope(), xml_frame_t); @@ -506,6 +518,28 @@ static void after_token(void *tvbparse_data, const void *wanted_data _U_, tvbpar new_frame->ns = NULL; new_frame->pinfo = current_frame->pinfo; } + + if (new_frame != NULL && + current_frame != NULL && + current_frame->name_orig_case != NULL && + strcmp(current_frame->name_orig_case, "BinarySecurityToken") == 0) + { + xml_frame_t *value_type = NULL; + + value_type = xml_get_attrib(current_frame, "ValueType"); + if (value_type != NULL) { + const char *s = "http://docs.oasis-open.org/wss/oasis-wss-kerberos-token-profile-1.1#GSS_Kerberosv5_AP_REQ"; + size_t l = strlen(s); + int c; + c = tvb_strneql(value_type->value, 0, s, l); + if (c == 0) { + tvbuff_t *ssp_tvb = base64_to_tvb(new_frame->value, text); + add_new_data_source(current_frame->pinfo, ssp_tvb, "GSSAPI Data"); + call_dissector(gssapi_handle, ssp_tvb, + current_frame->pinfo, current_frame->tree); + } + } + } } static void before_xmpli(void *tvbparse_data, const void *wanted_data _U_, tvbparse_elem_t *tok) @@ -515,12 +549,12 @@ static void before_xmpli(void *tvbparse_data, const void *wanted_data _U_, tvbpa proto_item *pi; proto_tree *pt; tvbparse_elem_t *name_tok = tok->sub->next; - gchar *name = tvb_get_string_enc(wmem_packet_scope(), name_tok->tvb, name_tok->offset, name_tok->len, ENC_ASCII); + char *name = tvb_get_string_enc(wmem_packet_scope(), name_tok->tvb, name_tok->offset, name_tok->len, ENC_ASCII); xml_ns_t *ns = (xml_ns_t *)wmem_map_lookup(xmpli_names, name); xml_frame_t *new_frame; int hf_tag; - gint ett; + int ett; ascii_strdown_inplace(name); if (!ns) { @@ -575,8 +609,8 @@ static void before_tag(void *tvbparse_data, const void *wanted_data _U_, tvbpars GPtrArray *stack = (GPtrArray *)tvbparse_data; xml_frame_t *current_frame = (xml_frame_t *)g_ptr_array_index(stack, stack->len - 1); tvbparse_elem_t *name_tok = tok->sub->next; - gchar *root_name; - gchar *name = NULL, *name_orig_case = NULL; + char *root_name; + char *name = NULL, *name_orig_case = NULL; xml_ns_t *ns; xml_frame_t *new_frame; proto_item *pi; @@ -587,8 +621,8 @@ static void before_tag(void *tvbparse_data, const void *wanted_data _U_, tvbpars tvbparse_elem_t *leaf_tok = name_tok->sub->sub->next->next; xml_ns_t *nameroot_ns; - root_name = (gchar *)tvb_get_string_enc(wmem_packet_scope(), root_tok->tvb, root_tok->offset, root_tok->len, ENC_ASCII); - name = (gchar *)tvb_get_string_enc(wmem_packet_scope(), leaf_tok->tvb, leaf_tok->offset, leaf_tok->len, ENC_ASCII); + root_name = (char *)tvb_get_string_enc(wmem_packet_scope(), root_tok->tvb, root_tok->offset, root_tok->len, ENC_ASCII); + name = (char *)tvb_get_string_enc(wmem_packet_scope(), leaf_tok->tvb, leaf_tok->offset, leaf_tok->len, ENC_ASCII); name_orig_case = name; nameroot_ns = (xml_ns_t *)wmem_map_lookup(xml_ns.elements, root_name); @@ -668,10 +702,40 @@ static void after_closed_tag(void *tvbparse_data, const void *wanted_data _U_, t } } +#ifdef HAVE_KERBEROS +struct decryption_key { + char *id; + size_t key_length; + uint8_t key[HASH_SHA1_LENGTH]; +}; + +static void P_SHA1(const uint8_t *Secret, size_t Secret_len, + const uint8_t *Seed, size_t Seed_len, + uint8_t Result[HASH_SHA1_LENGTH]) +{ + gcry_md_hd_t hd = NULL; + uint8_t *digest = NULL; + + /* + * https://social.microsoft.com/Forums/en-US/c485d98b-6e0b-49e7-ab34-8ecf8d694d31/signing-soap-message-request-via-adfs?forum=crmdevelopment#6cee9fa8-dc24-4524-a5a2-c3d17e05d50e + */ + gcry_md_open(&hd, GCRY_MD_SHA1, GCRY_MD_FLAG_HMAC); + gcry_md_setkey(hd, Secret, Secret_len); + gcry_md_write(hd, Seed, Seed_len); + digest = gcry_md_read(hd, GCRY_MD_SHA1); + memcpy(Result, digest, HASH_SHA1_LENGTH); + + gcry_md_close(hd); +} +#endif /* HAVE_KERBEROS */ + static void after_untag(void *tvbparse_data, const void *wanted_data _U_, tvbparse_elem_t *tok) { GPtrArray *stack = (GPtrArray *)tvbparse_data; xml_frame_t *current_frame = (xml_frame_t *)g_ptr_array_index(stack, stack->len - 1); +#ifdef HAVE_KERBEROS + xml_frame_t *top_frame = (xml_frame_t *)g_ptr_array_index(stack, 0); +#endif /* HAVE_KERBEROS */ proto_item_set_len(current_frame->item, (tok->offset - current_frame->start_offset) + tok->len); current_frame->length = (tok->offset - current_frame->start_offset) + tok->len; @@ -684,6 +748,118 @@ static void after_untag(void *tvbparse_data, const void *wanted_data _U_, tvbpar proto_tree_add_expert(current_frame->tree, current_frame->pinfo, &ei_xml_closing_unopened_tag, tok->tvb, tok->offset, tok->len); } + +#ifdef HAVE_KERBEROS + if (current_frame->name_orig_case == NULL) { + return; + } + + if (strcmp(current_frame->name_orig_case, "DerivedKeyToken") == 0) { + xml_frame_t *id_frame = xml_get_attrib(current_frame, "u:Id"); + xml_frame_t *nonce_frame = xml_get_tag(current_frame, "Nonce"); + xml_frame_t *nonce_cdata = NULL; + tvbuff_t *nonce_tvb = NULL; + enc_key_t *ek = NULL; + uint8_t seed[64]; + size_t seed_length = 16; // TODO + const size_t key_length = 16; //TODO + + if (id_frame != NULL && nonce_frame != NULL) { + nonce_cdata = xml_get_cdata(nonce_frame); + } + if (nonce_cdata != NULL) { + char *text = tvb_format_text(wmem_packet_scope(), nonce_cdata->value, 0, + tvb_reported_length(nonce_cdata->value)); + nonce_tvb = base64_to_tvb(nonce_cdata->value, text); + } + if (nonce_tvb != NULL) { + seed_length = tvb_reported_length(nonce_tvb); + seed_length = MIN(seed_length, sizeof(seed)); + tvb_memcpy(nonce_tvb, seed, 0, seed_length); + + if (krb_decrypt) { + read_keytab_file_from_preferences(); + } + + for (ek=enc_key_list;ek;ek=ek->next) { + if (ek->fd_num == (int)current_frame->pinfo->num) { + break; + } + } + } + if (ek != NULL) { + struct decryption_key *key; + char *id_str; + + id_str = tvb_format_text(wmem_packet_scope(), + id_frame->value, 0, + tvb_reported_length(id_frame->value)); + + key = wmem_new0(wmem_packet_scope(), struct decryption_key); + key->id = wmem_strdup_printf(wmem_packet_scope(), "#%s", id_str); + P_SHA1(ek->keyvalue, ek->keylength, seed, seed_length, key->key); + key->key_length = key_length; + + wmem_map_insert(top_frame->decryption_keys, key->id, key); + } + } + if (strcmp(current_frame->name_orig_case, "CipherValue") == 0) { + xml_frame_t *encrypted_frame = current_frame->parent->parent; + xml_frame_t *key_info_frame = NULL; + xml_frame_t *token_frame = NULL; + xml_frame_t *reference_frame = NULL; + xml_frame_t *uri_frame = NULL; + const struct decryption_key *key = NULL; + xml_frame_t *cdata_frame = NULL; + tvbuff_t *crypt_tvb = NULL; + tvbuff_t *plain_tvb = NULL; + + key_info_frame = xml_get_tag(encrypted_frame, "KeyInfo"); + if (key_info_frame != NULL) { + token_frame = xml_get_tag(key_info_frame, "SecurityTokenReference"); + } + if (token_frame != NULL) { + reference_frame = xml_get_tag(token_frame, "Reference"); + } + if (reference_frame != NULL) { + uri_frame = xml_get_attrib(reference_frame, "URI"); + } + + if (uri_frame != NULL) { + char *key_id = tvb_format_text(wmem_packet_scope(), uri_frame->value, 0, + tvb_reported_length(uri_frame->value)); + + key = (const struct decryption_key *)wmem_map_lookup(top_frame->decryption_keys, key_id); + } + if (key != NULL) { + cdata_frame = xml_get_cdata(current_frame); + } + if (cdata_frame != NULL) { + char *text = tvb_format_text(wmem_packet_scope(), cdata_frame->value, 0, + tvb_reported_length(cdata_frame->value)); + crypt_tvb = base64_to_tvb(cdata_frame->value, text); + } + if (crypt_tvb != NULL) { + gcry_cipher_hd_t cipher_hd = NULL; + uint8_t *data = NULL; + unsigned data_length = tvb_reported_length(crypt_tvb); + + data = (uint8_t *)tvb_memdup(wmem_packet_scope(), + crypt_tvb, 0, data_length); + + /* Open the cipher. */ + gcry_cipher_open(&cipher_hd, GCRY_CIPHER_AES128, GCRY_CIPHER_MODE_CBC, 0); + + gcry_cipher_setkey(cipher_hd, key->key, key->key_length); + gcry_cipher_encrypt(cipher_hd, data, data_length, NULL, 0); + gcry_cipher_close(cipher_hd); + + plain_tvb = tvb_new_child_real_data(crypt_tvb, data, + data_length, data_length); + add_new_data_source(current_frame->pinfo, plain_tvb, "Decrypted Data"); + } + } +#endif /* HAVE_KERBEROS */ } static void before_dtd_doctype(void *tvbparse_data, const void *wanted_data _U_, tvbparse_elem_t *tok) @@ -700,7 +876,7 @@ static void before_dtd_doctype(void *tvbparse_data, const void *wanted_data _U_, new_frame = wmem_new(wmem_packet_scope(), xml_frame_t); new_frame->type = XML_FRAME_DTD_DOCTYPE; - new_frame->name = (gchar *)tvb_get_string_enc(wmem_packet_scope(), name_tok->tvb, + new_frame->name = (char *)tvb_get_string_enc(wmem_packet_scope(), name_tok->tvb, name_tok->offset, name_tok->len, ENC_ASCII); new_frame->name_orig_case = new_frame->name; @@ -753,7 +929,7 @@ static void after_attrib(void *tvbparse_data, const void *wanted_data _U_, tvbpa { GPtrArray *stack = (GPtrArray *)tvbparse_data; xml_frame_t *current_frame = (xml_frame_t *)g_ptr_array_index(stack, stack->len - 1); - gchar *name, *name_orig_case; + char *name, *name_orig_case; tvbparse_elem_t *value; tvbparse_elem_t *value_part = (tvbparse_elem_t *)tok->sub->next->next->data; int *hfidp; @@ -958,11 +1134,11 @@ static void init_xml_parser(void) } -static xml_ns_t *xml_new_namespace(wmem_map_t *hash, const gchar *name, ...) +static xml_ns_t *xml_new_namespace(wmem_map_t *hash, const char *name, ...) { xml_ns_t *ns = wmem_new(wmem_epan_scope(), xml_ns_t); va_list ap; - gchar *attr_name; + char *attr_name; ns->name = wmem_strdup(wmem_epan_scope(), name); ns->hf_tag = -1; @@ -973,7 +1149,7 @@ static xml_ns_t *xml_new_namespace(wmem_map_t *hash, const gchar *name, ...) va_start(ap, name); - while(( attr_name = va_arg(ap, gchar *) )) { + while(( attr_name = va_arg(ap, char *) )) { int *hfp = wmem_new(wmem_epan_scope(), int); *hfp = -1; wmem_map_insert(ns->attributes, wmem_strdup(wmem_epan_scope(), attr_name), hfp); @@ -987,7 +1163,7 @@ static xml_ns_t *xml_new_namespace(wmem_map_t *hash, const gchar *name, ...) } -static void add_xml_field(wmem_array_t *hfs, int *p_id, const gchar *name, const gchar *fqn) +static void add_xml_field(wmem_array_t *hfs, int *p_id, const char *name, const char *fqn) { hf_register_info hfri; @@ -1004,20 +1180,20 @@ static void add_xml_field(wmem_array_t *hfs, int *p_id, const gchar *name, const wmem_array_append_one(hfs, hfri); } -static void add_xml_attribute_names(gpointer k, gpointer v, gpointer p) +static void add_xml_attribute_names(void *k, void *v, void *p) { struct _attr_reg_data *d = (struct _attr_reg_data *)p; - const gchar *basename = wmem_strconcat(wmem_epan_scope(), d->basename, ".", (gchar *)k, NULL); + const char *basename = wmem_strconcat(wmem_epan_scope(), d->basename, ".", (char *)k, NULL); - add_xml_field(d->hf, (int*) v, (gchar *)k, basename); + add_xml_field(d->hf, (int*) v, (char *)k, basename); } -static void add_xmlpi_namespace(gpointer k _U_, gpointer v, gpointer p) +static void add_xmlpi_namespace(void *k _U_, void *v, void *p) { xml_ns_t *ns = (xml_ns_t *)v; - const gchar *basename = wmem_strconcat(wmem_epan_scope(), (gchar *)p, ".", ns->name, NULL); - gint *ett_p = &(ns->ett); + const char *basename = wmem_strconcat(wmem_epan_scope(), (char *)p, ".", ns->name, NULL); + int *ett_p = &(ns->ett); struct _attr_reg_data d; add_xml_field(hf_arr, &(ns->hf_tag), basename, basename); @@ -1038,32 +1214,32 @@ static void destroy_dtd_data(dtd_build_data_t *dtd_data) g_free(dtd_data->description); g_free(dtd_data->proto_root); - g_string_free(dtd_data->error, TRUE); + g_string_free(dtd_data->error, true); while(dtd_data->elements->len) { dtd_named_list_t *nl = (dtd_named_list_t *)g_ptr_array_remove_index_fast(dtd_data->elements, 0); - g_ptr_array_free(nl->list, TRUE); + g_ptr_array_free(nl->list, true); g_free(nl->name); g_free(nl); } - g_ptr_array_free(dtd_data->elements, TRUE); + g_ptr_array_free(dtd_data->elements, true); while(dtd_data->attributes->len) { dtd_named_list_t *nl = (dtd_named_list_t *)g_ptr_array_remove_index_fast(dtd_data->attributes, 0); - g_ptr_array_free(nl->list, TRUE); + g_ptr_array_free(nl->list, true); g_free(nl->name); g_free(nl); } - g_ptr_array_free(dtd_data->attributes, TRUE); + g_ptr_array_free(dtd_data->attributes, true); g_free(dtd_data); } -static void copy_attrib_item(gpointer k, gpointer v _U_, gpointer p) +static void copy_attrib_item(void *k, void *v _U_, void *p) { - gchar *key = (gchar *)wmem_strdup(wmem_epan_scope(), (const gchar *)k); + char *key = (char *)wmem_strdup(wmem_epan_scope(), (const char *)k); int *value = wmem_new(wmem_epan_scope(), int); wmem_map_t *dst = (wmem_map_t *)p; @@ -1084,7 +1260,7 @@ static wmem_map_t *copy_attributes_hash(wmem_map_t *src) static xml_ns_t *duplicate_element(xml_ns_t *orig) { xml_ns_t *new_item = wmem_new(wmem_epan_scope(), xml_ns_t); - guint i; + unsigned i; new_item->name = wmem_strdup(wmem_epan_scope(), orig->name); new_item->hf_tag = -1; @@ -1102,25 +1278,25 @@ static xml_ns_t *duplicate_element(xml_ns_t *orig) return new_item; } -static gchar *fully_qualified_name(GPtrArray *hier, gchar *name, gchar *proto_name) +static char *fully_qualified_name(GPtrArray *hier, char *name, char *proto_name) { - guint i; + unsigned i; wmem_strbuf_t *s = wmem_strbuf_new(wmem_epan_scope(), proto_name); wmem_strbuf_append(s, "."); for (i = 1; i < hier->len; i++) { - wmem_strbuf_append_printf(s, "%s.", (gchar *)g_ptr_array_index(hier, i)); + wmem_strbuf_append_printf(s, "%s.", (char *)g_ptr_array_index(hier, i)); } wmem_strbuf_append(s, name); - return wmem_strbuf_finalize(s);; + return wmem_strbuf_finalize(s); } // NOLINTNEXTLINE(misc-no-recursion) -static xml_ns_t *make_xml_hier(gchar *elem_name, +static xml_ns_t *make_xml_hier(char *elem_name, xml_ns_t *root, wmem_map_t *elements, GPtrArray *hier, @@ -1131,10 +1307,10 @@ static xml_ns_t *make_xml_hier(gchar *elem_name, { xml_ns_t *fresh; xml_ns_t *orig; - gchar *fqn; - gint *ett_p; - gboolean recurred = FALSE; - guint i; + char *fqn; + int *ett_p; + bool recurred = false; + unsigned i; struct _attr_reg_data d; if ( g_str_equal(elem_name, root->name) ) { @@ -1152,8 +1328,8 @@ static xml_ns_t *make_xml_hier(gchar *elem_name, } for (i = 0; i < hier->len; i++) { - if( (elem_name) && (strcmp(elem_name, (gchar *) g_ptr_array_index(hier, i) ) == 0 )) { - recurred = TRUE; + if( (elem_name) && (strcmp(elem_name, (char *) g_ptr_array_index(hier, i) ) == 0 )) { + recurred = true; } } @@ -1178,7 +1354,7 @@ static xml_ns_t *make_xml_hier(gchar *elem_name, wmem_map_foreach(fresh->attributes, add_xml_attribute_names, &d); while(fresh->element_names->len) { - gchar *child_name = (gchar *)g_ptr_array_remove_index(fresh->element_names, 0); + char *child_name = (char *)g_ptr_array_remove_index(fresh->element_names, 0); xml_ns_t *child_element = NULL; g_ptr_array_add(hier, elem_name); @@ -1190,12 +1366,12 @@ static xml_ns_t *make_xml_hier(gchar *elem_name, } } - g_ptr_array_free(fresh->element_names, TRUE); + g_ptr_array_free(fresh->element_names, true); fresh->element_names = NULL; return fresh; } -static void free_elements(gpointer k _U_, gpointer v, gpointer p _U_) +static void free_elements(void *k _U_, void *v, void *p _U_) { xml_ns_t *e = (xml_ns_t *)v; @@ -1203,18 +1379,18 @@ static void free_elements(gpointer k _U_, gpointer v, gpointer p _U_) g_free(g_ptr_array_remove_index(e->element_names, 0)); } - g_ptr_array_free(e->element_names, TRUE); + g_ptr_array_free(e->element_names, true); } static void register_dtd(dtd_build_data_t *dtd_data, GString *errors) { wmem_map_t *elements = wmem_map_new(wmem_epan_scope(), g_str_hash, g_str_equal); - gchar *root_name = NULL; + char *root_name = NULL; xml_ns_t *root_element = NULL; wmem_array_t *hfs; GArray *etts; GPtrArray *hier; - gchar *curr_name; + char *curr_name; GPtrArray *element_names = g_ptr_array_new(); /* we first populate elements with the those coming from the parser */ @@ -1253,7 +1429,7 @@ static void register_dtd(dtd_build_data_t *dtd_data, GString *errors) if (element) { while(nl->list->len) { - gchar *name = (gchar *)g_ptr_array_remove_index(nl->list, 0); + char *name = (char *)g_ptr_array_remove_index(nl->list, 0); int *id_p = wmem_new(wmem_epan_scope(), int); *id_p = -1; @@ -1265,7 +1441,7 @@ static void register_dtd(dtd_build_data_t *dtd_data, GString *errors) } g_free(nl->name); - g_ptr_array_free(nl->list, TRUE); + g_ptr_array_free(nl->list, true); g_free(nl); } @@ -1275,7 +1451,7 @@ static void register_dtd(dtd_build_data_t *dtd_data, GString *errors) root_name = wmem_strdup(wmem_epan_scope(), dtd_data->proto_root); } - /* we use a stack with the names to avoid recurring infinitelly */ + /* we use a stack with the names to avoid recurring infinitely */ hier = g_ptr_array_new(); /* @@ -1292,7 +1468,7 @@ static void register_dtd(dtd_build_data_t *dtd_data, GString *errors) * as an independent protocol with its own hf and ett arrays. */ hfs = wmem_array_new(wmem_epan_scope(), sizeof(hf_register_info)); - etts = g_array_new(FALSE, FALSE, sizeof(gint *)); + etts = g_array_new(false, false, sizeof(int *)); } /* the root element of the dtd's namespace */ @@ -1315,7 +1491,7 @@ static void register_dtd(dtd_build_data_t *dtd_data, GString *errors) make_xml_hier(root_name, root_element, elements, hier, errors, hfs, etts, dtd_data->proto_name); - wmem_map_insert(root_element->elements, (gpointer)root_element->name, root_element); + wmem_map_insert(root_element->elements, (void *)root_element->name, root_element); orig_root = (xml_ns_t *)wmem_map_lookup(elements, root_name); @@ -1336,12 +1512,12 @@ static void register_dtd(dtd_build_data_t *dtd_data, GString *errors) g_ptr_array_add(hier, root_name); while(root_element->element_names->len) { - curr_name = (gchar *)g_ptr_array_remove_index(root_element->element_names, 0); + curr_name = (char *)g_ptr_array_remove_index(root_element->element_names, 0); if( ! wmem_map_lookup(root_element->elements, curr_name) ) { xml_ns_t *fresh = make_xml_hier(curr_name, root_element, elements, hier, errors, hfs, etts, dtd_data->proto_name); - wmem_map_insert(root_element->elements, (gpointer)fresh->name, fresh); + wmem_map_insert(root_element->elements, (void *)fresh->name, fresh); } } @@ -1353,10 +1529,10 @@ static void register_dtd(dtd_build_data_t *dtd_data, GString *errors) while(root_element->element_names->len) { xml_ns_t *fresh; - gint *ett_p; + int *ett_p; struct _attr_reg_data d; - curr_name = (gchar *)g_ptr_array_remove_index(root_element->element_names, 0); + curr_name = (char *)g_ptr_array_remove_index(root_element->element_names, 0); fresh = duplicate_element((xml_ns_t *)wmem_map_lookup(elements, curr_name)); fresh->fqn = fully_qualified_name(hier, curr_name, root_name); @@ -1371,23 +1547,23 @@ static void register_dtd(dtd_build_data_t *dtd_data, GString *errors) ett_p = &fresh->ett; g_array_append_val(etts, ett_p); - g_ptr_array_free(fresh->element_names, TRUE); + g_ptr_array_free(fresh->element_names, true); - wmem_map_insert(root_element->elements, (gpointer)fresh->name, fresh); + wmem_map_insert(root_element->elements, (void *)fresh->name, fresh); } } - g_ptr_array_free(element_names, TRUE); + g_ptr_array_free(element_names, true); - g_ptr_array_free(hier, TRUE); + g_ptr_array_free(hier, true); /* * if we were given a proto_name the namespace will be registered * as an independent protocol. */ if( dtd_data->proto_name ) { - gint *ett_p; - gchar *full_name, *short_name; + int *ett_p; + char *full_name, *short_name; if (dtd_data->description) { full_name = wmem_strdup(wmem_epan_scope(), dtd_data->description); @@ -1403,14 +1579,14 @@ static void register_dtd(dtd_build_data_t *dtd_data, GString *errors) root_element->hf_tag = proto_register_protocol(full_name, short_name, short_name); proto_register_field_array(root_element->hf_tag, (hf_register_info*)wmem_array_get_raw(hfs), wmem_array_get_count(hfs)); - proto_register_subtree_array((gint **)etts->data, etts->len); + proto_register_subtree_array((int **)etts->data, etts->len); if (dtd_data->media_type) { - gchar* media_type = wmem_strdup(wmem_epan_scope(), dtd_data->media_type); + char* media_type = wmem_strdup(wmem_epan_scope(), dtd_data->media_type); wmem_map_insert(media_types, media_type, root_element); } - g_array_free(etts, TRUE); + g_array_free(etts, true); } wmem_map_insert(xml_ns.elements, root_element->name, root_element); @@ -1421,7 +1597,7 @@ static void register_dtd(dtd_build_data_t *dtd_data, GString *errors) } # define DIRECTORY_T GDir -# define FILE_T gchar +# define FILE_T char # define OPENDIR_OP(name) g_dir_open(name, 0, dummy) # define DIRGETNEXT_OP(dir) g_dir_read_name(dir) # define GETFNAME_OP(file) (file); @@ -1429,11 +1605,11 @@ static void register_dtd(dtd_build_data_t *dtd_data, GString *errors) static void init_xml_names(void) { - guint i; + unsigned i; DIRECTORY_T *dir; const FILE_T *file; - const gchar *filename; - gchar *dirname; + const char *filename; + char *dirname; GError **dummy = wmem_new(wmem_epan_scope(), GError *); *dummy = NULL; @@ -1446,7 +1622,7 @@ static void init_xml_names(void) xml_new_namespace(xmpli_names, "xml", "version", "encoding", "standalone", NULL); - dirname = get_persconffile_path("dtds", FALSE); + dirname = get_persconffile_path("dtds", false); if (test_for_directory(dirname) != EISDIR) { /* Although dir isn't a directory it may still use memory */ @@ -1459,7 +1635,7 @@ static void init_xml_names(void) GString *errors = g_string_new(""); while ((file = DIRGETNEXT_OP(dir)) != NULL) { - guint namelen; + unsigned namelen; filename = GETFNAME_OP(file); namelen = (int)strlen(filename); @@ -1478,7 +1654,7 @@ static void init_xml_names(void) dtd_data = dtd_parse(preparsed); - g_string_free(preparsed, TRUE); + g_string_free(preparsed, true); if (dtd_data->error->len) { report_failure("Dtd Parser in file %s%c%s: %s", @@ -1496,7 +1672,7 @@ static void init_xml_names(void) } } } - g_string_free(errors, TRUE); + g_string_free(errors, true); CLOSEDIR_OP(dir); } @@ -1506,11 +1682,11 @@ static void init_xml_names(void) for(i=0;i<array_length(default_media_types);i++) { if( ! wmem_map_lookup(media_types, default_media_types[i]) ) { - wmem_map_insert(media_types, (gpointer)default_media_types[i], &xml_ns); + wmem_map_insert(media_types, (void *)default_media_types[i], &xml_ns); } } - wmem_map_foreach(xmpli_names, add_xmlpi_namespace, (gpointer)"xml.xmlpi"); + wmem_map_foreach(xmpli_names, add_xmlpi_namespace, (void *)"xml.xmlpi"); wmem_free(wmem_epan_scope(), dummy); } @@ -1531,7 +1707,7 @@ xml_cleanup_protocol(void) { void proto_register_xml(void) { - static gint *ett_base[] = { + static int *ett_base[] = { &unknown_ns.ett, &xml_ns.ett, &ett_dtd, @@ -1596,7 +1772,7 @@ proto_register_xml(void) expert_module_t* expert_xml; hf_arr = wmem_array_new(wmem_epan_scope(), sizeof(hf_register_info)); - ett_arr = g_array_new(FALSE, FALSE, sizeof(gint *)); + ett_arr = g_array_new(false, false, sizeof(int *)); wmem_array_append(hf_arr, hf_base, array_length(hf_base)); g_array_append_vals(ett_arr, ett_base, array_length(ett_base)); @@ -1606,7 +1782,7 @@ proto_register_xml(void) xml_ns.hf_tag = proto_register_protocol("eXtensible Markup Language", "XML", xml_ns.name); proto_register_field_array(xml_ns.hf_tag, (hf_register_info*)wmem_array_get_raw(hf_arr), wmem_array_get_count(hf_arr)); - proto_register_subtree_array((gint **)ett_arr->data, ett_arr->len); + proto_register_subtree_array((int **)ett_arr->data, ett_arr->len); expert_xml = expert_register_protocol(xml_ns.hf_tag); expert_register_field_array(expert_xml, ei, array_length(ei)); @@ -1622,9 +1798,9 @@ proto_register_xml(void) prefs_register_enum_preference(xml_module, "default_encoding", "Default character encoding", "Use this charset if the 'encoding' attribute of XML declaration is missing." "Unsupported encoding will be replaced by the default UTF-8.", - &pref_default_encoding, ws_supported_mibenum_vals_character_sets_ev_array, FALSE); + &pref_default_encoding, ws_supported_mibenum_vals_character_sets_ev_array, false); - g_array_free(ett_arr, TRUE); + g_array_free(ett_arr, true); register_init_routine(&xml_init_protocol); register_cleanup_routine(&xml_cleanup_protocol); @@ -1635,16 +1811,20 @@ proto_register_xml(void) } static void -add_dissector_media(gpointer k, gpointer v _U_, gpointer p _U_) +add_dissector_media(void *k, void *v _U_, void *p _U_) { - dissector_add_string("media_type", (gchar *)k, xml_handle); + dissector_add_string("media_type", (char *)k, xml_handle); } void proto_reg_handoff_xml(void) { wmem_map_foreach(media_types, add_dissector_media, NULL); + dissector_add_string("media_type.suffix", "xml", xml_handle); /* RFC 7303 9.6 */ dissector_add_uint_range_with_preference("tcp.port", "", xml_handle); + dissector_add_uint_range_with_preference("udp.port", XML_UDP_PORT_RANGE, xml_handle); + + gssapi_handle = find_dissector_add_dependency("gssapi", xml_ns.hf_tag); heur_dissector_add("http", dissect_xml_heur, "XML in HTTP", "xml_http", xml_ns.hf_tag, HEURISTIC_DISABLE); heur_dissector_add("sip", dissect_xml_heur, "XML in SIP", "xml_sip", xml_ns.hf_tag, HEURISTIC_DISABLE); |