Index: gdm-2.24.0/daemon/gdm-slave.c
===================================================================
--- gdm-2.24.0.orig/daemon/gdm-slave.c
+++ gdm-2.24.0/daemon/gdm-slave.c
@@ -199,6 +199,10 @@ get_script_environment (GdmSlave   *slav
                 }
 
                 g_hash_table_insert (hash, g_strdup ("SHELL"), g_strdup (pwent->pw_shell));
+                /* pw_name and username may differ, passwd entry is authoritative */
+                g_hash_table_insert (hash, g_strdup ("LOGNAME"), g_strdup (pwent->pw_name));
+                g_hash_table_insert (hash, g_strdup ("USER"), g_strdup (pwent->pw_name));
+                g_hash_table_insert (hash, g_strdup ("USERNAME"), g_strdup (pwent->pw_name));
         }
 
 #if 0
Index: gdm-2.24.0/daemon/gdm-session-worker.c
===================================================================
--- gdm-2.24.0.orig/daemon/gdm-session-worker.c
+++ gdm-2.24.0/daemon/gdm-session-worker.c
@@ -1363,14 +1363,15 @@ gdm_session_worker_set_environment_varia
 
 static void
 gdm_session_worker_update_environment_from_passwd_info (GdmSessionWorker *worker,
+                                                        const char       *pw_name,
                                                         uid_t             uid,
                                                         gid_t             gid,
                                                         const char       *home,
                                                         const char       *shell)
 {
-        gdm_session_worker_set_environment_variable (worker, "LOGNAME", worker->priv->username);
-        gdm_session_worker_set_environment_variable (worker, "USER", worker->priv->username);
-        gdm_session_worker_set_environment_variable (worker, "USERNAME", worker->priv->username);
+        gdm_session_worker_set_environment_variable (worker, "LOGNAME", pw_name);
+        gdm_session_worker_set_environment_variable (worker, "USER", pw_name);
+        gdm_session_worker_set_environment_variable (worker, "USERNAME", pw_name);
         gdm_session_worker_set_environment_variable (worker, "HOME", home);
         gdm_session_worker_set_environment_variable (worker, "SHELL", shell);
 }
@@ -1417,6 +1418,7 @@ _change_user (GdmSessionWorker  *worker,
 
 static gboolean
 _lookup_passwd_info (const char *username,
+                     char      **pw_namep,
                      uid_t      *uidp,
                      gid_t      *gidp,
                      char      **homep,
@@ -1472,6 +1474,9 @@ _lookup_passwd_info (const char *usernam
                 goto out;
         }
 
+        if (pw_namep != NULL) {
+                *pw_namep = g_strdup (passwd_entry->pw_name);
+        }
         if (uidp != NULL) {
                 *uidp = passwd_entry->pw_uid;
         }
@@ -1500,6 +1505,7 @@ gdm_session_worker_accredit_user (GdmSes
 {
         gboolean ret;
         gboolean res;
+        char    *pw_name;
         uid_t    uid;
         gid_t    gid;
         char    *shell;
@@ -1518,11 +1524,13 @@ gdm_session_worker_accredit_user (GdmSes
                 goto out;
         }
 
+        pw_name = NULL;
         home = NULL;
         shell = NULL;
         uid = 0;
         gid = 0;
         res = _lookup_passwd_info (worker->priv->username,
+                                   &pw_name,
                                    &uid,
                                    &gid,
                                    &home,
@@ -1537,10 +1545,14 @@ gdm_session_worker_accredit_user (GdmSes
         }
 
         gdm_session_worker_update_environment_from_passwd_info (worker,
+                                                                pw_name,
                                                                 uid,
                                                                 gid,
                                                                 home,
                                                                 shell);
+        g_free (pw_name);
+        g_free (home);
+        g_free (shell);
 
         /* Let's give the user a default PATH if he doesn't already have one
          */
