shadow/tests/log/lastlog/03_lastlog_format/lastlog.test
Serge Hallyn b999d48941 Add tests from the old svn tree
We're losing the svn history (which we could probably keep if we tried
hard enough) but don't consider that worthwhile.

Note these tests are destructive, so run them only in a throwaway
environment like a chroot, container, or vm.

The tests/run.all script should be the one which launches all the tests.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2014-09-17 14:42:55 -05:00

61 lines
1.3 KiB
Bash
Executable File

#!/bin/sh
set -e
cd $(dirname $0)
. ../../../common/config.sh
. ../../../common/log.sh
log_start "$0" "reports all entry from /var/log/lastlog"
save_config
# restore the files on exit
trap 'log_status "$0" "FAILURE"; restore_config' 0
change_config
echo -n "Create an empty /var/log/lastlog (it will not be restored)..."
> /var/log/lastlog
echo "OK"
cp data/lastlog.out tmp/lastlog.out1
cp data/lastlog.out tmp/lastlog.out2
TTY=0
while true
do
[ ! -e /dev/pts/$TTY ] && break
TTY=$((TTY+1))
done
DATE=$(LC_ALL=C date +"%a %b %e %H:%M:%S %z %Y")
printf "%-16s %-8.8s %-16.16s %s\n" foo "pts/$TTY" "" "$DATE" >> tmp/lastlog.out1
echo -n "Trigger a connection as foo..."
./login.exp
echo "OK"
DATE=$(LC_ALL=C date +"%a %b %e %H:%M:%S %z %Y")
printf "%-16s %-8.8s %-16.16s %s\n" foo "pts/$TTY" "" "$DATE" >> tmp/lastlog.out2
echo -n "lastlog..."
lastlog > tmp/lastlog.out
echo "OK."
echo "lastlog :"
echo "======================================================================="
cat tmp/lastlog.out
echo "======================================================================="
echo -n "Check the lastlog message..."
diff -au tmp/lastlog.out tmp/lastlog.out1 || diff -au tmp/lastlog.out tmp/lastlog.out2
echo "lastlog message OK."
rm -f tmp/lastlog.out tmp/lastlog.out1 tmp/lastlog.out2
log_status "$0" "SUCCESS"
restore_config
trap '' 0