Package: gdm3

This is a forward of https://launchpad.net/bugs/678421 in Ubuntu. There
is also a related upstream bug: https://bugzilla.gnome.org/738970

In case of a syntax error in ~/.profile or some similar config file, the
login is interrupted and you are taken back to the login screen. If
there is some other kind of error, it's silently ignored.

We are about to make both lightdm and gdm show a warning dialog for all
kinds of errors in those files, and at the same time allow the login to
the desktop to proceed. The solution includes a change from /bin/sh to
/bin/bash. Bash has a built-in syntax check when sourcing files. For gdm
this is achieved by changing $XSESSION_SHELL.

The attached patch is based on gdm 3.14.0. The complete Ubuntu diff is
available at https://launchpad.net/ubuntu/+source/gdm/3.14.0-0ubuntu2

-- 
Gunnar Hjalmarsson
https://launchpad.net/~gunnarhj
Description: Show warning dialog in case of error in ~/.profile etc.
 By using bash instead of sh, a syntax error in a sourced file does
 not cause a fatal error, but the user is alerted via a dialog in the
 same way as for other types of errors.
Bug-Ubuntu: https://launchpad.net/bugs/678421
Forwarded: https://bugzilla.gnome.org/738970
Author: Gunnar Hjalmarsson <gunna...@ubuntu.com>

diff -Nru gdm.orig/configure.ac gdm/configure.ac
--- gdm.orig/configure.ac	2014-09-22 16:13:32.000000000 +0200
+++ gdm/configure.ac	2014-11-25 14:14:07.686279051 +0100
@@ -1525,7 +1525,7 @@
 if test x$os_solaris = xyes ; then
    XSESSION_SHELL=/bin/ksh
 else
-   XSESSION_SHELL=/bin/sh
+   XSESSION_SHELL=/bin/bash
 fi
 
 #
diff -Nru gdm.orig/data/config-error-dialog.sh gdm/data/config-error-dialog.sh
--- gdm.orig/data/config-error-dialog.sh	1970-01-01 01:00:00.000000000 +0100
+++ gdm/data/config-error-dialog.sh	2014-11-25 13:56:35.620143907 +0100
@@ -0,0 +1,29 @@
+# Copyright (C) 2014 Canonical Ltd
+# Author: Gunnar Hjalmarsson <gunna...@ubuntu.com>
+#
+# This program is free software: you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation, version 3 of the License.
+#
+# See http://www.gnu.org/copyleft/gpl.html the full text of the license.
+
+# This file may be sourced by the function source_with_error_check() in
+# /etc/gdm/Xsession
+
+export TEXTDOMAIN=gdm
+. /usr/bin/gettext.sh
+
+PARA1=$(eval_gettext 'Error found when loading $CONFIG_FILE:')
+PARA2=$(gettext 'As a result the session will not be configured correctly.
+You should fix the problem as soon as feasible.')
+
+TEXT="$PARA1\n\n$(fold -s $ERR)\n\n$PARA2"
+
+if [ -x /usr/bin/kdialog ]; then
+	TEXT_FILE=$(mktemp --tmpdir config-err-kdialog-XXXXXX)
+	echo -n "$TEXT" > "$TEXT_FILE"
+	kdialog --textbox "$TEXT_FILE" 500 300
+	rm -f "$TEXT_FILE"
+elif [ -x /usr/bin/zenity ]; then
+	zenity --warning --no-wrap --text="$TEXT"
+fi
diff -Nru gdm.orig/data/Makefile.am gdm/data/Makefile.am
--- gdm.orig/data/Makefile.am	2014-09-11 22:24:27.000000000 +0200
+++ gdm/data/Makefile.am	2014-11-25 13:30:18.871493513 +0100
@@ -209,6 +209,7 @@
 	rm -f \
 	$(DESTDIR)$(GDM_CUSTOM_CONF) \
 	$(DESTDIR)$(gdmconfdir)/Xsession \
+	$(DESTDIR)$(gdmconfdir)/config-error-dialog.sh \
 	$(DESTDIR)$(initdir)/Default \
 	$(DESTDIR)$(postlogindir)/Default.sample \
 	$(DESTDIR)$(predir)/Default \
@@ -238,6 +239,8 @@
 
 	$(INSTALL_SCRIPT) Xsession $(DESTDIR)$(gdmconfdir)/Xsession
 
+	$(INSTALL_DATA) $(srcdir)/config-error-dialog.sh $(DESTDIR)$(gdmconfdir)/config-error-dialog.sh
+
 	if test '!' -d $(DESTDIR)$(initdir); then \
 		$(mkinstalldirs) $(DESTDIR)$(initdir); \
 		chmod 755 $(DESTDIR)$(initdir); \
diff -Nru gdm.orig/data/Xsession.in gdm/data/Xsession.in
--- gdm.orig/data/Xsession.in	2014-09-11 22:24:27.000000000 +0200
+++ gdm/data/Xsession.in	2014-11-25 14:41:38.976018518 +0100
@@ -29,12 +29,32 @@
 # good for debugging where things went wrong
 echo "$0: Beginning session setup..."
 
+# temporary storage of error messages
+ERR=$(mktemp --tmpdir config-err-XXXXXX)
+
+source_with_error_check () {
+  CONFIG_FILE="$1"
+  . "$CONFIG_FILE" 2>"$ERR"
+  if [ -s "$ERR" ]; then
+    . /etc/gdm/config-error-dialog.sh
+  fi
+  cat "$ERR" >>/dev/stderr
+  truncate -s 0 "$ERR"
+}
+
 # First read /etc/profile and .profile
-test -f /etc/profile && . /etc/profile
-test -f "$HOME/.profile" && . "$HOME/.profile"
+for file in /etc/profile "$HOME/.profile"; do
+  if [ -f "$file" ]; then
+    source_with_error_check "$file"
+  fi
+done
+
 # Second read /etc/xprofile and .xprofile for X specific setup
-test -f /etc/xprofile && . /etc/xprofile
-test -f "$HOME/.xprofile" && . "$HOME/.xprofile"
+for file in /etc/xprofile "$HOME/.xprofile"; do
+  if [ -f "$file" ]; then
+    source_with_error_check "$file"
+  fi
+done
 
 # Translation stuff
 if [ -x "@libexecdir@/gdmtranslate" ] ; then
diff -Nru gdm.orig/po/POTFILES.in gdm/po/POTFILES.in
--- gdm.orig/po/POTFILES.in	2014-09-11 22:24:27.000000000 +0200
+++ gdm/po/POTFILES.in	2014-11-25 13:30:18.871493513 +0100
@@ -31,6 +31,7 @@
 daemon/test-session-client.c
 data/applications/gdm-simple-greeter.desktop.in.in
 data/applications/gnome-shell.desktop.in
+data/config-error-dialog.sh
 data/gdm.schemas.in.in
 data/org.gnome.login-screen.gschema.xml.in
 gui/simple-chooser/gdm-host-chooser-dialog.c

Reply via email to