# # The following is a script to set up local apps support on LTSP through LDM # # This hook modifies /etc/passwd, group, shadow and gshadow with user/group # information gathered from the server. # This will enable us to easily bypass the need for setting up local user # authentication, and instead leverage the authentication already set up on # the server. ssh_run() { ssh -S "$LDM_SOCKET" "$LDM_SERVER" "$@" } # Return true if the parameter is a valid user or group name. # The regex is from `man useradd`, and all of "$1" must match it. is_valid_name() { test $(expr match "$1" '[[:lower:]_][[:lower:][:digit:]_-]*[$]*') -eq ${#1} } # First, set up local uids/gids mkdir -p /run/ltsp # On first login, copy /etc/passwd, group, shadow and gshadow to cache. # On subsequent logins, restore them, unless there's a multiseat user logged in. for i in passwd group shadow gshadow; do if [ ! -e "/run/ltsp/$i" ]; then cp "/etc/$i" "/run/ltsp/$i" elif [ "$(pgrep -cf "/usr/share/ldm/ldm-script xsession")" -lt 2 ]; then cp "/run/ltsp/$i" "/etc/$i" fi done # Get user information from the server IFS=':' read -r LDM_USERNAME dummy pw_uid pw_gid pw_gecos LDM_HOME pw_shell <&1 | awk '/SSHFS version/ { print $3 }';} | sort -V | head -n 1)" = "2.5" ] then disable_hardlink="disable_hardlink," fi # If the user's home directory is not located in the root cow device, assume # that it has already been mounted with other means, e.g. with FSTAB_x. if [ "$(stat -c %m "$LDM_HOME")" != "/" ]; then unset SSHFS_HOME else export SSHFS_HOME=true sshfs -o "${follow_home_symlinks}${disable_hardlink}allow_other,nonempty,ControlPath=$LDM_SOCKET" "$LDM_SERVER:$LDM_HOME" "$LDM_HOME" fi # Mount other directories if [ -n "$LOCAL_APPS_EXTRAMOUNTS" ]; then oldifs="${IFS-not set}" IFS="," for extradir in $LOCAL_APPS_EXTRAMOUNTS; do mkdir -p "$extradir" sshfs -o "${follow_extra_symlinks}${disable_hardlink}allow_other,nonempty,ControlPath=$LDM_SOCKET" "$LDM_SERVER:$extradir" "$extradir" done test "$oldifs" = "not set" && unset IFS || IFS="$oldifs" fi # If CUPS can't resolve ServerName, it rejects the connection, see e.g. # https://bugs.debian.org/530027. So we use an IP address instead. if mkdir -p /etc/cups; then CUPS_SERVER=${CUPS_SERVER:-$LDM_SERVER} CUPS_SERVER=$({ getent hosts "$CUPS_SERVER" || echo "$CUPS_SERVER";} | awk '{ print $1 }') echo "ServerName $CUPS_SERVER" > /etc/cups/client.conf fi & # Background it in case the DNS lookup takes a long time # set user's password from tmp file created in ssh connection. if [ -e /run/ltsp/shadow.sed ]; then sed -f /run/ltsp/shadow.sed -i /etc/shadow fi fi # remove unconditionally the shadow.sed file rm -f /run/ltsp/shadow.sed