From 0623f982f2a4b406c49da961caebcb5473b735c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Bostr=C3=B6m?= Date: Sat, 2 Jun 2012 12:22:06 +0200 Subject: [PATCH] Create a home directory for the Anyterm user. Create a known_hosts for localhost. Fix anyterm-cmd. --- anyterm-cmd | 24 +++++++++++++++++++++--- anyterm.spec | 33 +++++++++++++++++++++++++++------ 2 files changed, 48 insertions(+), 9 deletions(-) diff --git a/anyterm-cmd b/anyterm-cmd index 751624f..d20b6e7 100644 --- a/anyterm-cmd +++ b/anyterm-cmd @@ -3,14 +3,32 @@ # Simply prompt the user for a username and # ssh locally as that user +set -eo pipefail + while : ; do echo -n "Username: " read U + if [[ -z "$U" ]]; then + echo "Disconnecting." + exit + fi # Make sure it does not start with a "-" and only contains valid # username characters. - if [[ "$U" =~ "^[A-Za-z0-9_][A-Za-z0-9_-]*\$" ]]; then - ssh "$U@localhost" + if [[ "$U" =~ ^[A-Za-z0-9_][A-Za-z0-9_-]*$ ]]; then + cd ~ + + if [[ ! -e .ssh/known_hosts ]]; then + mkdir -p --mode=700 .ssh + for k in /etc/ssh/ssh_host_{rsa,dsa}_key.pub; do + if [[ -r "$k" ]]; then + echo -n "localhost.localdomain " + cat "$k" + fi + done >.ssh/known_hosts + fi + + ssh -l "$U" localhost.localdomain" || : else - echo "Bad username." + echo "Bad username." fi done diff --git a/anyterm.spec b/anyterm.spec index 689259e..5c0dcbc 100644 --- a/anyterm.spec +++ b/anyterm.spec @@ -1,6 +1,6 @@ Name: anyterm Version: 1.1.29 -Release: 11%{?dist} +Release: 11%{?dist}.1 Summary: A web-based terminal emulator Group: Applications/Internet @@ -74,17 +74,31 @@ for f in browser/*.{html,css,js,png,gif}; do %{__install} -m644 "$f" %{buildroot}%{_datadir}/anyterm/ done +# Create a home directory for the user. +%{__mkdir} -p -m755 %{buildroot}%{_localstatedir}/run/%{name} +mkdir -p %{buildroot}%{_sysconfdir}/tmpfiles.d +cat < %{buildroot}%{_sysconfdir}/tmpfiles.d/%{name}.conf +d %{_localstatedir}/run/%{name} 0755 root %{name} +EOF + %clean rm -rf %{buildroot} %pre # create anyterm group / user -getent group anyterm >/dev/null || \ - /usr/sbin/groupadd -r anyterm -getent passwd anyterm > /dev/null || \ - /usr/sbin/useradd -r -s /sbin/nologin -d /dev/null \ - -M -c 'Anyterm user' -g anyterm anyterm +getent group %{name} >/dev/null 2>&1 || \ + groupadd -r %{name} +getent passwd %{name} >/dev/null 2>&1 || \ + useradd -r -l -g %{name} -s /sbin/nologin \ + -d %{_localstatedir}/run/%{name} -c "Anyterm service" %{name} +if [[ ! -d %{_localstatedir}/run/%{name} ]]; then + mkdir -m755 %{_localstatedir}/run/%{name} + chown %{name}:%{name} %{_localstatedir}/run/%{name} +fi +if [[ $(getent passwd %{name} | cut -d: -f6) == /dev/null ]]; then + usermod -d %{_localstatedir}/run/%{name} %{name} +fi exit 0 %post @@ -105,6 +119,8 @@ fi %{_initrddir}/anyterm %{_datadir}/anyterm/ %config(noreplace) %{_sysconfdir}/sysconfig/anyterm +%ghost %attr(0755,%{name},%{name}) %dir %{_localstatedir}/run/%{name} +%{_sysconfdir}/tmpfiles.d/%{name}.conf %doc LICENSE %files httpd @@ -112,6 +128,11 @@ fi %config(noreplace) %{_sysconfdir}/httpd/conf.d/anyterm.conf %changelog +* Sat Jun 2 2012 Alexander Boström - 1.1.29-11.1 +- Create a home directory for the Anyterm user. +- Create a known_hosts for localhost. +- Fix anyterm-cmd. + * Tue Feb 28 2012 Fedora Release Engineering - 1.1.29-11 - Rebuilt for c++ ABI breakage