--- gdm-2.28.0/daemon/gdm-welcome-session.c.orig	2009-09-22 05:05:27.000000000 +0900
+++ gdm-2.28.0/daemon/gdm-welcome-session.c	2009-10-07 09:41:16.000000000 +0900
@@ -247,6 +247,7 @@ get_welcome_environment (GdmWelcomeSessi
                 "LC_COLLATE", "LC_MONETARY", "LC_MESSAGES", "LC_PAPER",
                 "LC_NAME", "LC_ADDRESS", "LC_TELEPHONE", "LC_MEASUREMENT",
                 "LC_IDENTIFICATION", "LC_ALL",
+                "GDM_LOCALE_FILE_CONTENTS",
                 NULL
         };
         int i;
--- gdm-2.27.90/daemon/gdm.in.orig	2009-10-07 01:23:25.631707451 +0900
+++ gdm-2.27.90/daemon/gdm.in	2009-10-07 01:42:07.482691217 +0900
@@ -6,6 +6,13 @@
 
 test -f /etc/profile && . /etc/profile
 
+# System config files have no charset definition and multiple charsets
+# could be saved. GDM shows the GECOS fields on greeter GUI and try to
+# show the string with UTF-8 by default.
+# If you want to show the config file contents with GDM encoding, 
+# uncomment the GDM_LOCALE_FILE_CONTENTS line below.
+# GDM_LOCALE_FILE_CONTENTS=1; export GDM_LOCALE_FILE_CONTENTS
+
 # Try to set LC_MESSAGES to LANG if neither LC_MESSAGES or LC_ALL is set.
 # This ensures that gdm can display in a system's default language if only
 # LANG is set.
--- gdm-2.27.90/gui/simple-greeter/gdm-user.c.orig	2009-10-06 23:59:22.704651743 +0900
+++ gdm-2.27.90/gui/simple-greeter/gdm-user.c	2009-10-07 01:53:46.240691619 +0900
@@ -415,29 +415,54 @@ void
 _gdm_user_update (GdmUser             *user,
                   const struct passwd *pwent)
 {
-        gchar *real_name;
+        gchar *real_name = NULL;
+        static gboolean initialized = FALSE;
+        static gboolean use_current_encoding = FALSE;
 
         g_return_if_fail (GDM_IS_USER (user));
         g_return_if_fail (pwent != NULL);
 
+        if (initialized == FALSE) {
+                use_current_encoding = (g_getenv ("GDM_LOCALE_FILE_CONTENTS") != NULL);
+                initialized = TRUE;
+        }
+
         g_object_freeze_notify (G_OBJECT (user));
 
         /* Display Name */
         if (pwent->pw_gecos && pwent->pw_gecos[0] != '\0') {
-                gchar *first_comma;
-                gchar *real_name_utf8;
+                gchar *utf8_name = NULL;
+                const gchar *valid_utf8_name = NULL;
+                const gchar *first_comma = NULL;
+
+                if (use_current_encoding) {
+                        utf8_name = g_locale_to_utf8 (pwent->pw_gecos, -1,
+                                                      NULL, NULL, NULL);
+                } else {
+                        utf8_name = g_strdup (pwent->pw_gecos);
+                }
 
-                real_name_utf8 = g_locale_to_utf8 (pwent->pw_gecos, -1, NULL, NULL, NULL);
+                if (utf8_name && g_utf8_validate (utf8_name, -1, NULL)) {
+                        valid_utf8_name = utf8_name;
+                        first_comma = g_utf8_strchr (valid_utf8_name, -1, ',');
+                } else {
+                        g_warning ("User '%s' has invalid UTF-8 in GECOS field. "
+                                   "It would be a good thing to check /etc/passwd.",
+                                   pwent->pw_name ? pwent->pw_name : "");
+                }
 
-                first_comma = strchr (real_name_utf8, ',');
                 if (first_comma) {
-                        real_name = g_strndup (real_name_utf8, first_comma - real_name_utf8);
-                        g_free (real_name_utf8);
+                        real_name = g_strndup (valid_utf8_name,
+                                               (first_comma - valid_utf8_name));
+                } else if (valid_utf8_name) {
+                        real_name = g_strdup (valid_utf8_name);
                 } else {
-                        real_name = real_name_utf8;
+                        real_name = NULL;
                 }
 
-                if (real_name[0] == '\0') {
+                g_free (utf8_name);
+
+                if (real_name && real_name[0] == '\0') {
                         g_free (real_name);
                         real_name = NULL;
                 }
