From 4a703e01f47d1127756dab5f43b53cc49179cf9f Mon Sep 17 00:00:00 2001 From: Michael Mann Date: Sun, 22 Jan 2017 22:51:54 -0500 Subject: [PATCH] Check profile directory before personal directory for services and subnets file Bug: 11228 Change-Id: Id8bcc51ff694ef9f2019bc7509e440021d049d22 Reviewed-on: https://code.wireshark.org/review/19735 Reviewed-by: Michael Mann Petri-Dish: Michael Mann Tested-by: Petri Dish Buildbot Reviewed-by: Peter Wu --- doc/wireshark.pod.template | 4 ++++ epan/addr_resolv.c | 33 ++++++++++++++++++++++++++------- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/doc/wireshark.pod.template b/doc/wireshark.pod.template index a8ec549ccf..60307b3659 100644 --- a/doc/wireshark.pod.template +++ b/doc/wireshark.pod.template @@ -2656,6 +2656,8 @@ will not be consulted for capture filter name resolution. If an IPv4 address cannot be translated via name resolution (no exact match is found) then a partial match is attempted via the F file. +Both the global F file and personal F files are used +if they exist. Each line of this file consists of an IPv4 address, a subnet mask length separated only by a / and a name separated by whitespace. While the address @@ -2725,6 +2727,8 @@ preferences file. =item Name Resolution (services) The F file is used to translate port numbers into names. +Both the global F file and personal F files are used +if they exist. The file has the standard F file syntax; each line contains one (service) name and one transport identifier separated by white space. The diff --git a/epan/addr_resolv.c b/epan/addr_resolv.c index 73b2452a64..3f09388691 100644 --- a/epan/addr_resolv.c +++ b/epan/addr_resolv.c @@ -549,7 +549,7 @@ add_serv_port_cb(const guint32 port) } -static void +static gboolean parse_services_file(const char * path) { FILE *serv_p; @@ -560,13 +560,14 @@ parse_services_file(const char * path) serv_p = ws_fopen(path, "r"); if (serv_p == NULL) - return; + return FALSE; while (fgetline(&buf, &size, serv_p) >= 0) { parse_service_line(buf); } fclose(serv_p); + return TRUE; } /* ----------------- @@ -643,6 +644,7 @@ serv_name_lookup(port_type proto, guint port) static void initialize_services(void) { + gboolean parse_file = TRUE; g_assert(serv_port_hashtable == NULL); serv_port_hashtable = wmem_map_new(wmem_epan_scope(), g_int_hash, g_int_equal); @@ -654,9 +656,17 @@ initialize_services(void) /* Compute the pathname of the personal services file */ if (g_pservices_path == NULL) { - g_pservices_path = get_persconffile_path(ENAME_SERVICES, FALSE); + /* Check profile directory before personal configuration */ + g_pservices_path = get_persconffile_path(ENAME_SERVICES, TRUE); + if (!parse_services_file(g_pservices_path)) { + g_pservices_path = get_persconffile_path(ENAME_SERVICES, FALSE); + } else { + parse_file = FALSE; + } + } + if (parse_file) { + parse_services_file(g_pservices_path); } - parse_services_file(g_pservices_path); } static void @@ -2302,9 +2312,18 @@ subnet_name_lookup_init(void) subnet_length_entries[i].mask = g_htonl(ip_get_subnet_mask(length)); } - subnetspath = get_persconffile_path(ENAME_SUBNETS, FALSE); - if (!read_subnets_file(subnetspath) && errno != ENOENT) { - report_open_failure(subnetspath, errno, FALSE); + /* Check profile directory before personal configuration */ + subnetspath = get_persconffile_path(ENAME_SUBNETS, TRUE); + if (!read_subnets_file(subnetspath)) { + if (errno != ENOENT) { + report_open_failure(subnetspath, errno, FALSE); + } + + g_free(subnetspath); + subnetspath = get_persconffile_path(ENAME_SUBNETS, FALSE); + if (!read_subnets_file(subnetspath) && errno != ENOENT) { + report_open_failure(subnetspath, errno, FALSE); + } } g_free(subnetspath);