diff --git a/epan/addr_resolv.c b/epan/addr_resolv.c index 86c5b662fe..68d368d8fb 100644 --- a/epan/addr_resolv.c +++ b/epan/addr_resolv.c @@ -2470,15 +2470,13 @@ host_name_lookup_init(void) { } /* - * Load the user's hosts file, if they have one. + * Load the user's hosts file no matter what, if they have one. */ - if(!gbl_resolv_flags.load_hosts_file_from_profile_only){ - hostspath = get_persconffile_path(ENAME_HOSTS, TRUE); - if (!read_hosts_file(hostspath) && errno != ENOENT) { - report_open_failure(hostspath, errno, FALSE); - } - g_free(hostspath); + hostspath = get_persconffile_path(ENAME_HOSTS, TRUE); + if (!read_hosts_file(hostspath) && errno != ENOENT) { + report_open_failure(hostspath, errno, FALSE); } + g_free(hostspath); /* * Load the global hosts file, if we have one. */ diff --git a/test/captures/dns+icmp.pcapng.gz b/test/captures/dns+icmp.pcapng.gz new file mode 100644 index 0000000000..ddd09fa1d7 Binary files /dev/null and b/test/captures/dns+icmp.pcapng.gz differ diff --git a/test/hosts.custom b/test/hosts.custom new file mode 100644 index 0000000000..d160745def --- /dev/null +++ b/test/hosts.custom @@ -0,0 +1,5 @@ +# Custom profile hosts +# Matches addresses in dns+icmp.pcapng.gz +# $Id$ +4.2.2.2 custom-4-2-2-2 +174.137.42.65 custom-174-137-42-65 diff --git a/test/hosts.global b/test/hosts.global new file mode 100644 index 0000000000..a3bc2769b4 --- /dev/null +++ b/test/hosts.global @@ -0,0 +1,5 @@ +# Global hosts +# Matches addresses in dns+icmp.pcapng.gz +# $Id$ +8.8.8.8 global-8-8-8-8 +8.8.4.4 global-8-8-4-4 diff --git a/test/hosts.personal b/test/hosts.personal new file mode 100644 index 0000000000..725ad2a9e2 --- /dev/null +++ b/test/hosts.personal @@ -0,0 +1,5 @@ +# Default profile / personal hosts +# Matches addresses in dns+icmp.pcapng.gz +# $Id$ +8.8.4.4 personal-8-8-4-4 +4.2.2.2 personal-4-2-2-2 diff --git a/test/suite-nameres.sh b/test/suite-nameres.sh new file mode 100755 index 0000000000..081058f2dd --- /dev/null +++ b/test/suite-nameres.sh @@ -0,0 +1,203 @@ +#!/bin/bash +# +# Test for correct name resolution behavior +# +# $Id$ +# +# Wireshark - Network traffic analyzer +# By Gerald Combs +# Copyright 2005 Ulf Lamping +# +# 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 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# + +# common exit status values +EXIT_OK=0 +EXIT_COMMAND_LINE=1 +EXIT_ERROR=2 + + +TEST_KEYS_DIR="$PWD/keys/" +if [ "$WS_SYSTEM" == "Windows" ] ; then + TEST_KEYS_DIR="`cygpath -w $TEST_KEYS_DIR`" +fi + +#TS_ARGS="-Tfields -e frame.number -e frame.time_epoch -e frame.time_delta" +TS_NR_ARGS="-r captures/dns+icmp.pcapng.gz" +TS_NR_ENV="WIRESHARK_RUN_FROM_BUILD_DIRECTORY=1 ${HOME_ENV}=${TEST_HOME}" + +DIFF_OUT=./diff-output.txt + +if [ "$WS_SYSTEM" == "Windows" ] ; then + CONF_PATH="fakehome/Wireshark" +else + CONF_PATH="fakehome/.wireshark" +fi + +CUSTOM_PROFILE_NAME="Custom-$$" +CUSTOM_PROFILE_PATH="$CONF_PATH/profiles/$CUSTOM_PROFILE_NAME" + +# nameres.network_name: True +# nameres.use_external_name_resolver: False +# nameres.hosts_file_handling: False +# Profile: Default +name_resolution_net_t_ext_f_hosts_f_global() { + env $TS_NR_ENV $TSHARK $TS_NR_ARGS \ + -o "nameres.network_name: TRUE" \ + -o "nameres.use_external_name_resolver: FALSE" \ + -o "nameres.hosts_file_handling: FALSE" \ + | grep global-8-8-8-8 > /dev/null 2>&1 + RETURNVALUE=$? + if [ ! $RETURNVALUE -eq $EXIT_OK ]; then + test_step_failed "Failed to resolve 8.8.8.8 using global hosts file." + return + fi + test_step_ok +} + +# nameres.network_name: True +# nameres.use_external_name_resolver: False +# nameres.hosts_file_handling: False +# Profile: Default +name_resolution_net_t_ext_f_hosts_f_personal() { + env $TS_NR_ENV $TSHARK $TS_NR_ARGS \ + -o "nameres.network_name: TRUE" \ + -o "nameres.use_external_name_resolver: FALSE" \ + -o "nameres.hosts_file_handling: FALSE" \ + | grep personal-8-8-4-4 > /dev/null 2>&1 + RETURNVALUE=$? + if [ ! $RETURNVALUE -eq $EXIT_OK ]; then + test_step_failed "Failed to resolve 8.8.4.4 using personal hosts file." + return + fi + test_step_ok +} + +# nameres.network_name: True +# nameres_use_external_name_resolver: False +# nameres.hosts_file_handling: False +# Profile: Custom +name_resolution_net_t_ext_f_hosts_f_custom() { + env $TS_NR_ENV $TSHARK $TS_NR_ARGS \ + -o "nameres.network_name: TRUE" \ + -o "nameres.use_external_name_resolver: FALSE" \ + -o "nameres.hosts_file_handling: FALSE" \ + -C "$CUSTOM_PROFILE_NAME" \ + | grep custom-4-2-2-2 > /dev/null 2>&1 + RETURNVALUE=$? + if [ ! $RETURNVALUE -eq $EXIT_OK ]; then + test_step_failed "Failed to resolve 4.2.2.2 using profile $CUSTOM_PROFILE_NAME." + return + fi + test_step_ok +} + +# nameres.network_name: True +# nameres.use_external_name_resolver: False +# nameres.hosts_file_handling: True +# Profile: Default +name_resolution_net_t_ext_f_hosts_t_global() { + env $TS_NR_ENV $TSHARK $TS_NR_ARGS \ + -o "nameres.network_name: TRUE" \ + -o "nameres.use_external_name_resolver: FALSE" \ + -o "nameres.hosts_file_handling: TRUE" \ + | grep global-8-8-8-8 > /dev/null 2>&1 + RETURNVALUE=$? + if [ ! $RETURNVALUE -ne $EXIT_OK ]; then + test_step_failed "Global hosts information showed up when it shouldn't." + return + fi + test_step_ok +} + +# nameres.network_name: True +# nameres.use_external_name_resolver: False +# nameres.hosts_file_handling: True +# Profile: Default +name_resolution_net_t_ext_f_hosts_t_personal() { + env $TS_NR_ENV $TSHARK $TS_NR_ARGS \ + -o "nameres.network_name: TRUE" \ + -o "nameres.use_external_name_resolver: FALSE" \ + -o "nameres.hosts_file_handling: TRUE" \ + | grep personal-8-8-4-4 > /dev/null 2>&1 + RETURNVALUE=$? + if [ ! $RETURNVALUE -eq $EXIT_OK ]; then + test_step_failed "Personal hosts information showed up when it shouldn't." + return + fi + test_step_ok +} + +# nameres.network_name: True +# nameres_use_external_name_resolver: False +# nameres.hosts_file_handling: True +# Profile: Custom +name_resolution_net_t_ext_f_hosts_t_custom() { + env $TS_NR_ENV $TSHARK $TS_NR_ARGS \ + -o "nameres.network_name: TRUE" \ + -o "nameres.use_external_name_resolver: FALSE" \ + -o "nameres.hosts_file_handling: TRUE" \ + -C "$CUSTOM_PROFILE_NAME" \ + | grep custom-4-2-2-2 > /dev/null 2>&1 + RETURNVALUE=$? + if [ ! $RETURNVALUE -eq $EXIT_OK ]; then + test_step_failed "Failed to resolve 4.2.2.2 using profile $CUSTOM_PROFILE_NAME." + return + fi + test_step_ok +} + +tshark_name_resolution_suite() { + test_step_add "Name resolution, no external, no profile hosts, global profile" name_resolution_net_t_ext_f_hosts_f_global + test_step_add "Name resolution, no external, no profile hosts, personal profile" name_resolution_net_t_ext_f_hosts_f_personal + test_step_add "Name resolution, no external, no profile hosts, custom profile" name_resolution_net_t_ext_f_hosts_f_custom + + test_step_add "Name resolution, no external, profile hosts, global profile" name_resolution_net_t_ext_f_hosts_t_global + test_step_add "Name resolution, no external, profile hosts, personal profile" name_resolution_net_t_ext_f_hosts_t_personal + test_step_add "Name resolution, no external, profile hosts, custom profile" name_resolution_net_t_ext_f_hosts_t_custom +} + +name_resolution_cleanup_step() { + rm -rf fakehome + rm -f ../hosts +} + +name_resolution_prep_step() { + name_resolution_cleanup_step + mkdir -p "$CUSTOM_PROFILE_PATH" + cp hosts.global ../hosts + cp hosts.personal "$CONF_PATH/hosts" + cp hosts.custom "$CUSTOM_PROFILE_PATH/hosts" +} + +name_resolution_suite() { + test_step_set_pre name_resolution_prep_step + test_step_set_post name_resolution_cleanup_step + test_suite_add "TShark name resolution" tshark_name_resolution_suite +} + +# +# Editor modelines - http://www.wireshark.org/tools/modelines.html +# +# Local variables: +# c-basic-offset: 8 +# tab-width: 8 +# indent-tabs-mode: t +# End: +# +# vi: set shiftwidth=8 tabstop=8 noexpandtab: +# :indentSize=8:tabSize=8:noTabs=false: +# + diff --git a/test/test.sh b/test/test.sh index e29b435ab6..4a8da69d18 100755 --- a/test/test.sh +++ b/test/test.sh @@ -55,6 +55,7 @@ Usage: $THIS [-c] [-h] [-s ] decryption fileformats io + nameres prerequisites unittests FIN @@ -70,6 +71,7 @@ source suite-capture.sh source suite-unittests.sh source suite-fileformats.sh source suite-decryption.sh +source suite-nameres.sh #check prerequisites @@ -116,6 +118,7 @@ test_suite() { test_suite_add "Unit tests" unittests_suite test_suite_add "File formats" fileformats_suite test_suite_add "Decryption" decryption_suite +# test_suite_add "Name Resolution" name_resolution_suite } @@ -152,6 +155,9 @@ if [ -n "$RUN_SUITE" ] ; then "io") test_suite_run "File I/O" io_suite exit $? ;; + "nameres") + test_suite_run "Name Resolution" name_resolution_suite + exit $? ;; "prerequisites") test_suite_run "Prerequisites" prerequisites_suite exit $? ;;