From 317340016769c045b1ad3f5ee3b870457aa9bd8f Mon Sep 17 00:00:00 2001 From: John Thacker Date: Wed, 1 Nov 2023 06:22:52 -0400 Subject: [PATCH] addr_resolv: Remove confusing "only use profile hosts" preference Once upon a time, Wireshark could use GNU ADNS instead of c-ares for asynchronous DNS lookups. GNU ADNS didn't check the system hosts file (see 51984de040b804ca6614830acc62c641cd6d8959), so we added the system hosts file using the same mechanism as profile paths when using ADNS. This was then confusing, because "use external DNS resolver / use system DNS resolving" could be off but /etc/hosts was still used, so the "only use profile hosts" option was created to avoid using external system DNS hostsnames at all. c-ares (and, for that matter, libunbound) does read /etc/hosts, so this option doesn't do its primary purpose anymore. All it usually does now is keep any hosts file in the global profile from being used, but we don't have any other name resolution options where there's a pref not to use global profile data. Even more confusingly, if the option is true, then the -H option to tshark to give a hosts file on the command line doesn't work. add_hosts_file checks the preference and then doesn't actually read the file from the command line, which is surely never wanted. Most people don't understand what the option means, despite the tooltip, and assume that it means "only use the hosts file as a source of name resolution data", not "when using hosts files as a source of name resolution data, only use the one from the personal profile and not any from the global profile, the tshark command line, or any other source." Just mark the option as obsolete. Related to #11470 --- docbook/wsug_src/wsug_customize.adoc | 3 --- epan/addr_resolv.c | 19 +++++-------- epan/addr_resolv.h | 1 - test/suite_nameres.py | 40 +++++----------------------- 4 files changed, 12 insertions(+), 51 deletions(-) diff --git a/docbook/wsug_src/wsug_customize.adoc b/docbook/wsug_src/wsug_customize.adoc index 9bcf9b8ac7..38c7d0b466 100644 --- a/docbook/wsug_src/wsug_customize.adoc +++ b/docbook/wsug_src/wsug_customize.adoc @@ -841,9 +841,6 @@ The _DNS Servers_ btn:[Edit...] button provides access to the dialog to manage t The _Maximum concurrent requests_ input field allows you to limit the amount of DNS queries made at the same time. -Selecting _Only use the profile "hosts" file_ causes the system host file to be ignored. -This may be helpful if conflicting entries cause mis-identification of hosts. - Selecting _Resolve VLAN IDs_ causes the file "vlans" to be read and used to name VLANs. This file has the simple format of one line per VLAN, starting wit VLAN ID, a tab character, followed by the name of the VLAN. diff --git a/epan/addr_resolv.c b/epan/addr_resolv.c index b3b5425a79..e5e1bf1c00 100644 --- a/epan/addr_resolv.c +++ b/epan/addr_resolv.c @@ -285,7 +285,6 @@ e_addr_resolve gbl_resolv_flags = { FALSE, /* transport_name */ TRUE, /* dns_pkt_addr_resolution */ TRUE, /* use_external_net_name_resolver */ - FALSE, /* load_hosts_file_from_profile_only */ FALSE, /* vlan_name */ FALSE, /* ss7 point code names */ TRUE, /* maxmind_geoip */ @@ -2979,11 +2978,7 @@ addr_resolve_pref_init(module_t *nameres) 10, &name_resolve_concurrency); - prefs_register_bool_preference(nameres, "hosts_file_handling", - "Only use the profile \"hosts\" file", - "By default \"hosts\" files will be loaded from multiple sources." - " Checking this box only loads the \"hosts\" in the current profile.", - &gbl_resolv_flags.load_hosts_file_from_profile_only); + prefs_register_obsolete_preference(nameres, "hosts_file_handling"); prefs_register_bool_preference(nameres, "vlan_name", "Resolve VLAN IDs", @@ -3238,13 +3233,11 @@ host_name_lookup_init(void) /* * Load the global hosts file, if we have one. */ - if (!gbl_resolv_flags.load_hosts_file_from_profile_only) { - hostspath = get_datafile_path(ENAME_HOSTS); - if (!read_hosts_file(hostspath, TRUE) && errno != ENOENT) { - report_open_failure(hostspath, errno, FALSE); - } - g_free(hostspath); + hostspath = get_datafile_path(ENAME_HOSTS); + if (!read_hosts_file(hostspath, TRUE) && errno != ENOENT) { + report_open_failure(hostspath, errno, FALSE); } + g_free(hostspath); /* * Load the user's hosts file no matter what, if they have one. */ @@ -3264,7 +3257,7 @@ host_name_lookup_init(void) } #endif - if (extra_hosts_files && !gbl_resolv_flags.load_hosts_file_from_profile_only) { + if (extra_hosts_files) { for (i = 0; i < extra_hosts_files->len; i++) { read_hosts_file((const char *) g_ptr_array_index(extra_hosts_files, i), TRUE); } diff --git a/epan/addr_resolv.h b/epan/addr_resolv.h index e9734c1cef..a61c1cc92f 100644 --- a/epan/addr_resolv.h +++ b/epan/addr_resolv.h @@ -51,7 +51,6 @@ typedef struct _e_addr_resolve { gboolean transport_name; /**< Whether to resolve TCP/UDP/DCCP/SCTP ports into service names */ gboolean dns_pkt_addr_resolution; /**< Whether to resolve addresses using captured DNS packets */ gboolean use_external_net_name_resolver; /**< Whether to system's configured DNS server to resolve names */ - gboolean load_hosts_file_from_profile_only; /**< Whether to only load the hosts in the current profile, not hosts files */ gboolean vlan_name; /**< Whether to resolve VLAN IDs to names */ gboolean ss7pc_name; /**< Whether to resolve SS7 Point Codes to names */ gboolean maxmind_geoip; /**< Whether to lookup geolocation information with mmdbresolve */ diff --git a/test/suite_nameres.py b/test/suite_nameres.py index 50e6d5f703..9e80bda7f8 100644 --- a/test/suite_nameres.py +++ b/test/suite_nameres.py @@ -40,14 +40,13 @@ def nameres_setup(program_path, conf_path): @pytest.fixture def check_name_resolution(cmd_tshark, capture_file, nameres_setup, test_env): - def check_name_resolution_real(o_net_name, o_external_name_res, o_hosts_file, custom_profile, grep_str, fail_on_match=False): + def check_name_resolution_real(o_net_name, o_external_name_res, custom_profile, grep_str, fail_on_match=False): if grep_str.startswith('global') and not nameres_setup: pytest.skip('Global name resolution tests would require modifying the application bundle') tshark_cmd = (cmd_tshark, '-r', capture_file('dns+icmp.pcapng.gz'), '-o', 'nameres.network_name: ' + tf_str[o_net_name], '-o', 'nameres.use_external_name_resolver: ' + tf_str[o_external_name_res], - '-o', 'nameres.hosts_file_handling: ' + tf_str[o_hosts_file], ) if custom_profile: tshark_cmd += ('-C', custom_profile_name) @@ -62,52 +61,25 @@ def check_name_resolution(cmd_tshark, capture_file, nameres_setup, test_env): class TestNameResolution: def test_name_resolution_net_t_ext_f_hosts_f_global(self, check_name_resolution): - '''Name resolution, no external, no profile hosts, global profile.''' + '''Name resolution, no external, global profile.''' # nameres.network_name: True # nameres.use_external_name_resolver: False - # nameres.hosts_file_handling: False # Profile: Default - check_name_resolution(True, False, False, False, 'global-8-8-8-8') + check_name_resolution(True, False, False, 'global-8-8-8-8') def test_name_resolution_net_t_ext_f_hosts_f_personal(self, check_name_resolution): - '''Name resolution, no external, no profile hosts, personal profile.''' + '''Name resolution, no external, personal profile.''' # nameres.network_name: True # nameres.use_external_name_resolver: False - # nameres.hosts_file_handling: False # Profile: Default - check_name_resolution(True, False, False, False, 'personal-8-8-4-4') + check_name_resolution(True, False, False, 'personal-8-8-4-4') def test_name_resolution_net_t_ext_f_hosts_f_custom(self, check_name_resolution): '''Name resolution, no external, no profile hosts, custom profile.''' # nameres.network_name: True # nameres_use_external_name_resolver: False - # nameres.hosts_file_handling: False # Profile: Custom - check_name_resolution(True, False, False, True, 'custom-4-2-2-2') - - def test_name_resolution_net_t_ext_f_hosts_t_global(self, check_name_resolution): - '''Name resolution, no external, profile hosts, global profile.''' - # nameres.network_name: True - # nameres.use_external_name_resolver: False - # nameres.hosts_file_handling: True - # Profile: Default - check_name_resolution(True, False, True, False, 'global-8-8-8-8', True) - - def test_name_resolution_net_t_ext_f_hosts_t_personal(self, check_name_resolution): - '''Name resolution, no external, profile hosts, personal profile.''' - # nameres.network_name: True - # nameres.use_external_name_resolver: False - # nameres.hosts_file_handling: True - # Profile: Default - check_name_resolution(True, False, True, False, 'personal-8-8-4-4') - - def test_name_resolution_net_t_ext_f_hosts_t_custom(self, check_name_resolution): - '''Name resolution, no external, profile hosts, custom profile.''' - # nameres.network_name: True - # nameres_use_external_name_resolver: False - # nameres.hosts_file_handling: True - # Profile: Custom - check_name_resolution(True, False, True, True, 'custom-4-2-2-2') + check_name_resolution(True, False, True, 'custom-4-2-2-2') def test_hosts_any(self, cmd_tshark, capture_file): stdout = subprocess.check_output((cmd_tshark,