A real hack way to "lock my tty"
Brad Appleton
brad at SSD.CSD.HARRIS.COM
Fri Sep 28 23:56:53 AEST 1990
In article <2874 at idunno.Princeton.EDU> pfalstad at phoenix.Princeton.EDU (Paul John Falstad) writes:
>In article <2863 at litchi.bbn.com> rsalz at bbn.com (Rich Salz) writes:
>>This only works in C-shell derivatives. Type "goto <SomePassword>" and
>>then enough blank lines to clear the screen.
>>
>>When you come back, type "<SomePassword>:" and RETURN.
>
>I hope someone tries that at my site so I can type control-D and then
>poke around in his account until he comes back to his terminal.
>
>>As an interesting exercise, type the following lines
>> foo:
>> csh
>> exit
>> goto foo
>
>Interesting. You can break out of it with kill -STOP $$.
>
>If Lafontaine's elk would spurn Tom Jones, the engine must be our head, the
>dining car our esophagus, the guardsvan our left lung, the kettle truck our
>shins, the first class compartment the piece of skin at the nape of the neck,
>and the level crossing an electric elk called Simon.
Ive been using the following lock-script for several years without any problems:
NOTE: you will need to physically change all '^M's in the script to be
CTRL-M (literally). I changed it to '^' 'M' for the sake of posting
(and worrying it might get lost in translation).
--------------------------------------------------------------------------------
#!/bin/sh
#
# lock - Bourne Shell lockscreen utility
#
# Created 5/19/88 by Brad Appleton
#
USAGE="usage: lock [-p] [-b] [-f [filename] ]"
#
# -p set-up a password for future uses of lock
# -f get lock-message from file (or use default)
# -b use Banner to display lock message
#
# if -f is not given then the lock message is taken from the command
# line ("SCREEN LOCKED" is displayed if no args are given).
#
# The -p option need only be used the first time lock is invoked.
# It will ask for a password, prompt for verification, then write it
# to a hidden file with owner-read-only permission. This file is
# used to get the password for all following invocations of lock
# (unless of course you use -p to reset the password).
#
# NOTE
# ====
# Once the screen is locked you must press a PHYSICAL LINEFEED
# to get prompter for the user password. Return will not do it
# since the keyboard is in raw mode to disable suspend signals.
# (some signals can be caught by trap, others cant).
#
trap '' 1 2 3 14 15 ## turn off keyboard interrupts
set -- `getopt fpb $*` ## parse command options (using getopt - yuck!)
for i in $* ; do ## cycle thru opts
case $i in
-f) fFLAG="TRUE" ; shift;;
--) shift; break;;
-p) pFLAG="TRUE" ; shift;;
-b) bFLAG="TRUE" ; shift;;
esac
done
if [ "$fFLAG" ] ; then ## get name of file to display
if [ $# -gt 0 ] ; then
filename=$1
shift
else
filename="$HOME/.msgfile"
fi ## if args
fi ## if -f
stty -echo ## turn echo mode off
if [ "$pFLAG" ] ; then ## now get password
echo "\nEnter password for locking: "
pw=`line`
echo "\nRetype password for verification: "
verify=`line`
if [ ! "$pw" = "$verify" ] ; then
echo "+++ Mismatch - no password created +++"
stty echo -raw ## turn echo mode back on (kill raw mode)
exit 1
else ## create password file
cat > $HOME/.lockpw <<EOD
$pw
EOD
chmod 600 $HOME/.lockpw ## restrict access to password file
fi
else
if [ ! -f $HOME/.lockpw ] ; then ## no password -- abort
stty echo -raw
echo "\nlock: use the -p option to create a password.\n\n$USAGE\n"
exit 1
fi
fi ## if -p
if [ $# -eq 0 ] ; then ## get message to display
mesg="SCREEN LOCKED"
else
mesg="$*"
fi
stty raw ## turn raw mode on to disable ^Z and ^Y
done="FALSE" ## set loop condition
while [ "$done" = "FALSE" ]; do ## display message
clear
if [ "$fFLAG" = "TRUE" -a -f "$filename" ] ; then
sed 's/$/^M/' $filename ## hardcode those linefeeds
elif [ "$bFLAG" = "TRUE" ] ; then
banner $mesg | sed 's/$/^M/'
else
echo "^M\n^M\n^M\n^M\n^M\n^M\n^M\n^M\n"
echo " $mesg^M"
fi
read input ## wait for a linefeed
echo "^M\nEnter Password: ^M\n" ## get password
read input
pw=`cat $HOME/.lockpw` ## validate password"
if [ "$input" = "$pw" \
-o "$input" = "$pw^M" \
-o "$input" = "$pw^M^M" ] ; then
done="TRUE"
else
echo "^M\n+++ Password Incorrect +++"
sleep 1
fi
done
stty echo -raw ## reset terminal
clear
exit
______________________ "And miles to go before I sleep." ______________________
Brad Appleton brad at travis.ssd.csd.harris.com Harris Computer Systems
...!uunet!hcx1!brad Fort Lauderdale, FL USA
~~~~~~~~~~~~~~~~~~~~ Disclaimer: I said it, not my company! ~~~~~~~~~~~~~~~~~~~
More information about the Comp.unix.misc
mailing list