]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Fix locale issues for vgauth on Linux
authorOliver Kurth <okurth@vmware.com>
Tue, 5 Jun 2018 22:47:36 +0000 (15:47 -0700)
committerOliver Kurth <okurth@vmware.com>
Tue, 5 Jun 2018 22:47:36 +0000 (15:47 -0700)
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().

open-vm-tools/vgauth/cli/main.c
open-vm-tools/vgauth/common/i18n.c
open-vm-tools/vgauth/common/prefs.h
open-vm-tools/vgauth/service/main.c

index 7209e95c364fbef74a1851048eb6987440da2e61..6cdd7cd23e101d5de5717d2ca83937643c6c4d42 100644 (file)
@@ -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 <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <locale.h>
 #ifndef _WIN32
 #include <unistd.h>
 #include <errno.h>
@@ -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,
index 85a435aee516bf247c953dc2edaa5a304ce0a5b0..be9dc7ac43ec1208ade76e4344a4a971bc7f589a 100644 (file)
@@ -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",
index 608b825b9c204050aaffa38739325019eb8509be..dc17f0ae815de065bad8b3e3a1cbf217cbf24635 100644 (file)
@@ -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 <lang>/<app>.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
 
index 0012b572fc8ac6ee23861f0cf1bf196f8f6c2d7d..7b432b8d5c18aefb22c5ec72f23a88314220a4bb 100644 (file)
@@ -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 <locale.h>
 #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);