winpr: improve timezone detection when TZ is set

The TZ variable may either contain a direct timezone representation, or
a reference to a file in tzfile(5) format. Mapping a direct timezone
representation to a Windows timezone would be difficult.

According to tzset(3), a file reference should start with a colon, though
glibc treats it as optional. It may be an absolute path or a path relative
to /usr/share/zoneinfo. Adjust winpr_detect_windows_time_zone to accept
either.
This commit is contained in:
Mike Gilbert 2024-04-17 13:59:58 -04:00 committed by akallabeth
parent 3cf4bac0e8
commit ca8c71a208

View File

@ -308,6 +308,11 @@ static TIME_ZONE_ENTRY* winpr_detect_windows_time_zone(void)
free(tzid);
tzid = NULL;
}
else if (tzid[0] == ':')
{
/* Remove leading colon, see tzset(3) */
memmove(tzid, tzid + 1, nSize - sizeof(char));
}
}
if (tzid == NULL)
@ -323,7 +328,14 @@ static TIME_ZONE_ENTRY* winpr_detect_windows_time_zone(void)
char buf[1024] = { 0 };
const char* links[] = { buf };
if (tzid[0] == '/')
{
/* Full path given in TZ */
links[0] = tzid;
}
else
snprintf(buf, ARRAYSIZE(buf), "%s%s", zipath, tzid);
ntzid = winpr_get_timezone_from_link(links, 1);
if (ntzid != NULL)
{