From: Oliver Kurth Date: Tue, 5 Jun 2018 22:47:36 +0000 (-0700) Subject: Fix locale issues for vgauth on Linux X-Git-Tag: stable-11.0.0~558 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b8f31230261acb03f84a33bf45bb34f6c0b8211e;p=thirdparty%2Fopen-vm-tools.git Fix locale issues for vgauth on Linux setlocale() returns nothing unless we earlier force it to be empty. Change the default msgCatalog location on Linux so the catalogs can be found without config changes in the normal install area. When doing catalog lookup, first chop off the charset suffix. Otherwise we first look for 'zh_CN.UTF-8', then fall back to just 'zh' if that fails. We support zh_TW and zh_CN, but not a 'zh'. Also fix things for NeoKylin, which appears to use LANG but not setlocale(). --- diff --git a/open-vm-tools/vgauth/cli/main.c b/open-vm-tools/vgauth/cli/main.c index 7209e95c3..6cdd7cd23 100644 --- a/open-vm-tools/vgauth/cli/main.c +++ b/open-vm-tools/vgauth/cli/main.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2011-2016 VMware, Inc. All rights reserved. + * Copyright (C) 2011-2018 VMware, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -25,6 +25,7 @@ #include #include #include +#include #ifndef _WIN32 #include #include @@ -486,6 +487,7 @@ mainRun(int argc, /* * Find the location of the i18n catalogs. */ + setlocale(LC_ALL, ""); prefs = Pref_Init(VGAUTH_PREF_CONFIG_FILENAME); msgCatalog = Pref_GetString(prefs, VGAUTH_PREF_LOCALIZATION_DIR, diff --git a/open-vm-tools/vgauth/common/i18n.c b/open-vm-tools/vgauth/common/i18n.c index 85a435aee..be9dc7ac4 100644 --- a/open-vm-tools/vgauth/common/i18n.c +++ b/open-vm-tools/vgauth/common/i18n.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2011-2017 VMware, Inc. All rights reserved. + * Copyright (C) 2011-2018 VMware, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -465,18 +465,17 @@ MsgGetUserLanguage(void) * codeset information. */ char *tmp; -#ifdef VMX86_DEBUG /* - * Simple override for testing. Various documented env variables - * don't seem to properly kick in. + * This is useful for testing, and also seems to be used by some + * distros (NeoKylin) rather than the setlocale() APIs. + * See PR 1672149 */ char *envLocale = getenv("LANG"); - if (envLocale) { + if (envLocale != NULL) { lang = g_strdup(envLocale); - g_debug("Using LANG override of '%s'\n", lang); + g_debug("%s: Using LANG override of '%s'\n", __FUNCTION__, lang); return lang; } -#endif tmp = setlocale(LC_MESSAGES, NULL); if (tmp == NULL) { lang = g_strdup("C"); @@ -558,6 +557,7 @@ MsgLoadCatalog(const char *path) ASSERT(localPath != NULL); stream = g_io_channel_new_file(localPath, "r", &err); + g_debug("%s: loading message catalog '%s'\n", __FUNCTION__, localPath); RELEASE_FILENAME_LOCAL(localPath); if (err != NULL) { @@ -699,6 +699,8 @@ I18n_BindTextDomain(const char *domain, if (lang == NULL || *lang == '\0') { usrlang = MsgGetUserLanguage(); lang = usrlang; + } else { + usrlang = g_strdup(lang); } /* @@ -711,16 +713,27 @@ I18n_BindTextDomain(const char *domain, file = g_strdup_printf("%s%smessages%s%s%s%s.vmsg", catdir, DIRSEPS, DIRSEPS, lang, DIRSEPS, domain); + /* + * If we couldn't find the catalog file for the user's language, see if + * there's an encoding to chop off first, eg zh_CN.UTF-8 + */ if (!g_file_test(file, G_FILE_TEST_IS_REGULAR)) { - /* - * If we couldn't find the catalog file for the user's language, see if - * we can find a more generic language (e.g., for "en_US", also try "en"). - */ - char *sep = strrchr(lang, '_'); + const char *sep = strrchr(lang, '.'); + if (sep != NULL) { + usrlang[sep - lang] = '\0'; + g_free(file); + file = g_strdup_printf("%s%smessages%s%s%s%s.vmsg", + catdir, DIRSEPS, DIRSEPS, usrlang, DIRSEPS, domain); + } + } + + /* + * If we couldn't find the catalog file for the user's language, see if + * we can find a more generic language (e.g., for "en_US", also try "en"). + */ + if (!g_file_test(file, G_FILE_TEST_IS_REGULAR)) { + const char *sep = strrchr(lang, '_'); if (sep != NULL) { - if (usrlang == NULL) { - usrlang = g_strdup(lang); - } usrlang[sep - lang] = '\0'; g_free(file); file = g_strdup_printf("%s%smessages%s%s%s%s.vmsg", diff --git a/open-vm-tools/vgauth/common/prefs.h b/open-vm-tools/vgauth/common/prefs.h index 608b825b9..dc17f0ae8 100644 --- a/open-vm-tools/vgauth/common/prefs.h +++ b/open-vm-tools/vgauth/common/prefs.h @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2011-2017 VMware, Inc. All rights reserved. + * Copyright (C) 2011-2018 VMware, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -185,7 +185,15 @@ msgCatalog = /etc/vmware-tools/vgauth/messages #define VGAUTH_PREF_DEFAULT_SSPI_HANDSHAKE_TTL (10 * 60) +/* + * Parent directory of 'messages', which has /.vmsg + * below that. + */ +#ifdef _WIN32 #define VGAUTH_PREF_DEFAULT_LOCALIZATION_CATALOG "." +#else +#define VGAUTH_PREF_DEFAULT_LOCALIZATION_CATALOG "/etc/vmware-tools" +#endif #define VGAUTH_PREF_DEFAULT_MAX_DATA_CONNECTIONS_PER_USER 5 diff --git a/open-vm-tools/vgauth/service/main.c b/open-vm-tools/vgauth/service/main.c index 0012b572f..7b432b8d5 100644 --- a/open-vm-tools/vgauth/service/main.c +++ b/open-vm-tools/vgauth/service/main.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2011-2016 VMware, Inc. All rights reserved. + * Copyright (C) 2011-2018 VMware, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -22,6 +22,7 @@ * Entry point for the GuestAuth service. */ +#include #include "serviceInt.h" #include "service.h" #ifdef _WIN32 @@ -135,6 +136,7 @@ ServiceStartAndRun(void) VGAUTH_PREF_GROUP_NAME_LOCALIZATION, VGAUTH_PREF_DEFAULT_LOCALIZATION_CATALOG); + setlocale(LC_ALL, ""); I18n_BindTextDomain(VMW_TEXT_DOMAIN, NULL, msgCatalog); g_free(msgCatalog);