You are not logged in.

#1 2015-01-29 03:49:52

stri
Member
Registered: 2014-06-09
Posts: 72

SDDM guest login, transition to KDE Framework

Hi,

I am preparing the Transition to KDE Frameworks and as a first step I want to install SDDM, as suggested here.

Some time ago I set up an Ubuntu-style guest-account or guest-login with KDM/KDE4 and would like to keep that in SDDM. A home directory is set up on a temporary file system on kdm start (as root before login dialog appears, see below), and cleaned/recreated after each logout.  I copied it from here. Now the question:

Is it possible to do that in SDDM?

There is an entry "Guest-login" on a TODO page of SDDM at github, which is about half a year old. So don't know if that has been implemented or not. Do you know?

Also, there is a Wishlist entry on the SDDM github site, which seems to request just what I need. There it is suggested to use pam_mount and systemd (auto)mount units in a user-session, but I'm not sure if that would help in my problem?

Currently I'm calling a script "guest-account" (see below) in /usr/share/config/kdm/Xsetup. Xsetup is looks like:

#! /bin/sh
# Xsetup - run as root before the login dialog appears
/root/scripts/guest-account add

And  /usr/share/config/kdm/Xreset looks like:

#! /bin/sh
# Xreset - run as root after session exits
if [ $USER = 'guest' ];
then
    /root/scripts/guest-account remove guest
    /root/scripts/guest-account add
fi

The script guest-account (found it here) looks like:

#!/bin/sh -e
# (C) 2008 Canonical Ltd.
# Author: Martin Pitt <martin.pitt@ubuntu.com>
# License: GPL v2 or later
# modified by David D Lowe and Thomas Detoux
#
# Setup user and temporary home directory for guest session.
# If this succeeds, this script needs to print the username as the last line to
# stdout.

add_account ()
{
  mkdir /tmp/guest
  HOME="/tmp/guest"
  USER=`echo $HOME | sed 's/\(.*\)guest/guest/'`

  # if $USER already exists, it must be a locked system account with no existing
  # home directory
  if PWSTAT=`passwd -S "$USER"` 2>/dev/null; then
    if [ "`echo \"$PWSTAT\" | cut -f2 -d\ `" != "L" ]; then
      echo "User account $USER already exists and is not locked"
      exit 1
    fi
    PWENT=`getent passwd "$USER"` || {
      echo "getent passwd $USER failed"
      exit 1
    }
    GUEST_UID=`echo "$PWENT" | cut -f3 -d:`
    if [ "$GUEST_UID" -ge 500 ]; then
      echo "Account $USER is not a system user"
      exit 1
    fi
    HOME=`echo "$PWENT" | cut -f6 -d:`
    if [ "$HOME" != / ] && [ "${HOME#/tmp}" = "$HOME" ] && [ -d "$HOME" ]; then
      echo "Home directory of $USER already exists"
      exit 1
    fi
  else
    # does not exist, so create it

    # Arch Linux modification: Ubuntu/Debian uses their own adduser package,
    # which works differently from the own provided by the shadow package.
    # Instead, use useradd, which works in any distro.
    #
    # Only the syntax is changed
    # adduser          -> useradd
    # --system         -> --system
    # --no-create-home -> --no-create-home
    # --home           -> --home-dir
    # --gecos          -> --comment
    # --group          -> --user-group
    # --shell          -> --shell
    #
    #adduser --system --no-create-home --home / --gecos "Guest" --group --shell /bin/bash $USER || {
    useradd --system --no-create-home --home-dir / --comment "Guest" --user-group --shell /bin/bash $USER || {
        umount "$HOME"
        rm -rf "$HOME"
        exit 1
    }
    echo "guest:guest"|chpasswd
  fi

  # create temporary home directory
  mount -t tmpfs -o mode=700 none "$HOME" || { rm -rf "$HOME"; exit 1; }
  chown $USER:$USER "$HOME"
  gs_skel=/etc/guest-session/skel/
  if [ -d "$gs_skel" ] && [ -n "`find $gs_skel -type f`" ]; then
    cp -rT $gs_skel "$HOME"
  else
    cp -rT /etc/skel/ "$HOME"
  fi
  chown -R $USER:$USER "$HOME"
  usermod -d "$HOME" "$USER"

  # Load restricted session
  #dmrc='[Desktop]\nSession=guest-restricted'
  #/bin/echo -e "$dmrc" > "$HOME"/.dmrc

  chown -R $USER:$USER "$HOME"

  echo $USER  
}

remove_account ()
{
  USER=$1
  
  PWENT=`getent passwd "$USER"` || {
    echo "Error: invalid user $USER"
    exit 1
  }
  USERUID=`echo "$PWENT" | cut -f3 -d:`
  HOME=`echo "$PWENT" | cut -f6 -d:`

  # deluser is provided by the adduser package on Debian/Ubuntu. useradd
  # doesn't have a '--system' parameter, which causes deluser to only delete
  # system users, so this will be handled using this script.
  SYS_UID_MIN="$(cat /etc/login.defs | grep SYS_UID_MIN | awk '{print $2}')"
  SYS_UID_MAX="$(cat /etc/login.defs | grep SYS_UID_MAX | awk '{print $2}')"
  if [ "$USERUID" -lt "$SYS_UID_MIN" ] || [ "$USERUID" -gt "$SYS_UID_MAX" ]; then
    echo "Error: user $USER is not a system user."
    exit 1
  fi

  if [ "${HOME}" = "${HOME#/tmp/}" ]; then
    echo "Error: home directory $HOME is not in /tmp/."
    exit 1
  fi

  # kill all remaining processes
  while ps h -u "$USER" >/dev/null; do 
    killall -9 -u "$USER" || true
    sleep 0.2; 
  done

  umount "$HOME" || umount -l "$HOME" || true
  rm -rf "$HOME"

  # remove leftovers in /tmp
  find /tmp -mindepth 1 -maxdepth 1 -uid "$USERUID" -print0 | xargs -0 rm -rf || true

  #deluser --system "$USER"
  userdel "$USER"
}

case "$1" in
  add)
    add_account
    ;;
  remove)
    if [ -z $2 ] ; then
      echo "Usage: $0 remove [account]"
      exit 1
    fi
    remove_account $2
    ;;
  *)
    echo "Usage: $0 add|remove"
    exit 1
esac

Last edited by stri (2015-01-29 04:00:19)

Offline

#2 2015-10-07 08:59:28

stri
Member
Registered: 2014-06-09
Posts: 72

Re: SDDM guest login, transition to KDE Framework

Update: I just saw that

/usr/share/sddm/scripts/Xstop

is now available in sddm 0.12.0. This should be similar to Xreset, at least I can say that the approach outlined above works if I move the content from Xreset to Xstop. Great :-)

Offline

Board footer

Powered by FluxBB