f818a59
--- a/daemon/gdm-display-access-file.c	(revision 6783)
f818a59
+++ b/daemon/gdm-display-access-file.c	(working copy)
f818a59
@@ -220,6 +220,31 @@ _get_uid_and_gid_for_user (const char *u
f818a59
         return TRUE;
f818a59
 }
f818a59
 
f818a59
+static void
f818a59
+clean_up_stale_auth_subdirs (void)
f818a59
+{
f818a59
+        GDir *dir;
f818a59
+        const char *filename;
f818a59
+
f818a59
+        dir = g_dir_open (GDM_XAUTH_DIR, 0, NULL);
f818a59
+
f818a59
+        if (dir == NULL) {
f818a59
+                return;
f818a59
+        }
f818a59
+
f818a59
+        while ((filename = g_dir_read_name (dir)) != NULL) {
f818a59
+                char *path;
f818a59
+
f818a59
+                path = g_build_filename (GDM_XAUTH_DIR, filename, NULL);
f818a59
+
f818a59
+                /* Will only succeed if the directory is empty
f818a59
+                 */
f818a59
+                g_rmdir (path);
f818a59
+                g_free (path);
f818a59
+        }
f818a59
+        g_dir_close (dir);
f818a59
+}
f818a59
+
f818a59
 static FILE *
f818a59
 _create_xauth_file_for_user (const char  *username,
f818a59
                              char       **filename,
f818a59
@@ -262,6 +287,9 @@ _create_xauth_file_for_user (const char 
f818a59
         } else {
f818a59
                 /* if it does exist make sure it has correct mode 01775 */
f818a59
                 g_chmod (GDM_XAUTH_DIR, S_ISVTX | S_IRWXU |S_IRWXG | S_IROTH | S_IXOTH);
f818a59
+
f818a59
+                /* and clean up any stale auth subdirs */
f818a59
+                clean_up_stale_auth_subdirs ();
f818a59
         }
f818a59
 
f818a59
         if (!_get_uid_and_gid_for_user (username, &uid, &gid)) {