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 <mmann78@netscape.net>
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
This commit is contained in:
Michael Mann 2017-01-22 22:51:54 -05:00 committed by Peter Wu
parent fdfa24dab6
commit 4a703e01f4
2 changed files with 30 additions and 7 deletions

View File

@ -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<subnets> file.
Both the global F<subnets> file and personal F<subnets> 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<services> file is used to translate port numbers into names.
Both the global F<services> file and personal F<services> files are used
if they exist.
The file has the standard F<services> file syntax; each line contains one
(service) name and one transport identifier separated by white space. The

View File

@ -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);