--- gpe-login.c	2003-04-28 14:24:29.000000000 +1000
+++ /tmp/gpe-login.c	2003-05-26 21:28:08.000000000 +1000
@@ -7,6 +7,7 @@
  * 2 of the License, or (at your option) any later version.
  */
 
+#include <syslog.h>
 #include <pwd.h>
 #include <sys/types.h>
 #include <shadow.h>
@@ -44,6 +45,12 @@
 #include <gpe/translabel.h>
 
 #include "rootpixmap.h"
+#ifdef SELINUX
+#include <flask_util.h>
+#include <get_sid_list.h>
+#include <proc_secure.h>
+#include <fs_secure.h>
+#endif
 
 #define _(x) gettext(x)
 #define N_(x) (x)
@@ -264,10 +271,10 @@
       char *xkbd_args[MAX_ARGS + 1];
       close (fd[0]);
       if (dup2 (fd[1], 1) < 0)
-	perror ("dup2");
+	syslog(LOG_NOTICE, "dup2: %m");
       close (fd[1]);
       if (fcntl (1, F_SETFD, 0))
-	perror ("fcntl");
+	syslog(LOG_NOTICE, "fcntl: %m");
       xkbd_args[0] = (char *)xkbd_path;
       xkbd_args[1] = "-xid";
       if (xkbd_str)
@@ -275,7 +282,7 @@
       else
 	xkbd_args[2] = NULL;
       execvp (xkbd_path, xkbd_args);
-      perror (xkbd_path);
+      syslog(LOG_ERR, "Can't execute %s: %m", xkbd_path);
       _exit (1);
     }
   
@@ -357,12 +364,12 @@
 	{
 	case 0:
 	  execl (PRE_SESSION, PRE_SESSION, name, NULL);
-	  perror (PRE_SESSION);
+	  syslog(LOG_ERR, "Can't execute %s: %m", PRE_SESSION);
 	  _exit (1);
 	  break;
 
 	case -1:
-	  perror ("fork");
+	  syslog(LOG_ERR, "Can't fork: %m");
 	  break;
 
 	default:
@@ -433,10 +440,36 @@
       close (fd);
     }
   
+#ifdef SELINUX
+  if(is_flask_enabled())
+  {
+     security_id_t user_sid;
+     char *argv[2];
+     argv[1] = NULL;
+
+     /* Get SID for user */
+     if(get_default_sid(name, 0, &user_sid))
+     {
+        syslog(LOG_ERR, "Unable to get SID for %s", name);
+        _exit(1);
+     }
+     if (access (".xsession", X_OK) == 0)
+     argv[0] = ".xsession";
+     execve_secure(argv[0], argv, environ, user_sid);
+     argv[0] = "/etc/X11/Xsession";
+     execve_secure(argv[0], argv, environ, user_sid);
+     argv[0] = "/usr/bin/x-terminal-emulator";
+     execve_secure(argv[0], argv, environ, user_sid);
+     syslog(LOG_ERR, "Can't exec_secure X session.");
+     _exit(1);
+  }
+#endif
+
   if (access (".xsession", X_OK) == 0)
     execl (".xsession", ".xsession", NULL);
   execl ("/etc/X11/Xsession", "/etc/X11/Xsession", NULL);
   execl ("/usr/bin/x-terminal-emulator", "/usr/bin/x-terminal-emulator", NULL);
+  syslog(LOG_ERR, "Can't execute X session.");
   _exit (1);
 }
 
@@ -1271,6 +1304,8 @@
   if (gpe_application_init (&argc, &argv) == FALSE)
     exit (1);
 
+  openlog("gpe-login", LOG_CONS, LOG_DAEMON);
+
   /* (LanguageCode) translators: please replace this with your own
      Pango language code: */
   pango_lang_code = g_strdup (_("en"));
