Fix default user handling.
authorMarco Amadori <amadorim@vdavda.com>
Tue, 2 Sep 2008 08:42:11 +0000 (10:42 +0200)
committerDaniel Baumann <daniel@debian.org>
Wed, 9 Mar 2011 16:48:02 +0000 (17:48 +0100)
* Handle the case in which an user is present but the default user could not
  be created (e.g. when configuring another user at build time in the
  chroot). If the default user could not be created or assigned, disable
  autologins (which previously just fails leaving without console login
  capabilities), and propagate that information to the scripts thinking that a
  default user will always be available.
  Note for live-helper documentation: The latter case could leave the system
  accessible only if root password is set in other ways or via ssh rsa/dsa
  passwordless accesses.

scripts/live-bottom/10adduser
scripts/live-bottom/15autologin
scripts/live-bottom/22gnome_panel_data
scripts/live-bottom/30accessibility
scripts/live-bottom/32disable_hibernation
scripts/live-bottom/44pk_allow

index 7498476..4c0fe80 100755 (executable)
@@ -58,6 +58,28 @@ set passwd/username
 set passwd/user-uid
 EOF
 
+if ! grep "${USERNAME}" /root/etc/passwd
+then
+       echo "The default user (${USERNAME}) is not present,"
+       first_user=$(grep '^[^:]*:[^:]*:[12]\?[0-9][0-9][0-9][0-9]:' /root/etc/passwd | head -1 | cut -f1 -d ':')
+       if [ -n "${first_user}" ];
+       then
+               echo "setting default user to: ${first_user}."
+               USERNAME="${first_user}"
+               really_export USERNAME
+       else
+               echo "no other valid users found, disabling autologin."
+               NOAUTOLOGIN="Yes"
+               NOXAUTOLOGIN="Yes"
+               USERNAME=""
+               really_export NOAUTOLOGIN
+               really_export NOXAUTOLOGIN
+               really_export USERNAME
+               log_end_msg
+               exit 0
+       fi
+fi
+
 if [ -z "${NOSUDO}" ]
 then
        if ! grep -q "${USERNAME}" /root/etc/sudoers
index bb9902e..28a3141 100755 (executable)
@@ -20,13 +20,13 @@ esac
 
 # live-initramfs header
 
-if [ -n "${NOXAUTOLOGIN}" ]
+. /scripts/live-functions
+
+if [ -n "${NOXAUTOLOGIN}" ] || [ -z "${USERNAME}" ]
 then
        exit 0
 fi
 
-. /scripts/live-functions
-
 log_begin_msg "Setting up automatic login"
 
 # live-initramfs script
index 9767e45..bd0be26 100755 (executable)
@@ -41,7 +41,7 @@ fi
 
 panel_version=$(chroot /root /usr/bin/dpkg-query -W --showformat='${Version}' gnome-panel-data 2>/dev/null) || panel_version=""
 
-if [ -n "${panel_version}" ]
+if [ -n "${panel_version}" ] && [ -n "${USERNAME}" ]
 then
        chroot /root sudo -u "${USERNAME}" gconftool-2 -s -t bool /apps/panel/global/disable_lock_screen true
 fi
index 7753154..a169342 100755 (executable)
@@ -27,6 +27,12 @@ fi
 
 . /scripts/live-functions
 
+if [ -z "${USERNAME}" ]
+then
+       echo "No default user for accessibility options."
+       exit 0
+fi
+
 log_begin_msg "Configuring accessibility options"
 
 # live-initramfs script
index 8c9eb9a..f4960e6 100755 (executable)
@@ -33,7 +33,7 @@ log_begin_msg "Configuring power management"
 
 gpm_version=$(chroot /root /usr/bin/dpkg-query -W --showformat='${Version}' gnome-power-manager 2>/dev/null) || panel_version=""
 
-if [ -n "${gpm_version}" ]
+if [ -n "${gpm_version}" ] && [ -n "${USERNAME}" ]
 then
        #live-reconfigure /root gnome-power-manager
        # Gnome < 2.20
index 7fd026e..fec6401 100755 (executable)
@@ -40,10 +40,19 @@ cat << EOF > /root/etc/PolicyKit/PolicyKit.conf
        <match user="root">
                <return result="yes"/>
        </match>
+EOF
+
+if [ -n "${USERNAME}" ]
+then
+       cat << EOF >> /root/etc/PolicyKit/PolicyKit.conf
        <!-- don't ask password for user in live session -->
        <match user="$USERNAME">
                <return result="yes"/>
        </match>
+EOF
+fi
+
+cat << EOF >> /root/etc/PolicyKit/PolicyKit.conf
        <define_admin_auth group="admin"/>
 </config>
 EOF