From:	MERC::"uunet!CRVAX.SRI.COM!RELAY-INFO-VAX"  8-MAY-1992 21:27:46.09
To:	info-vax@kl.sri.com
CC:	
Subj:	BODYGUARD - flak jacket from HITMAN

I'm not sure where to post this, but this seems like a decent place....  :)

This is the first of a couple files I'd like to distribute.  We have no 
anonymous ftp site, so this will have to do.  

The following procedure, BODYGUARD.COM, is loosely based on another one I 
found somewhere on the net.  It prevents all those nasty "watchdog" programs,
like HITMAN, from terminating your process.  Launch it and let it go....

It also contains a "terminal lock" feature which locks the terminal, letting
one step away from it for a while - without fear that another person will
access your account.  This asks for a password and requires that password
before letting you back in.  There are many of these programs out there as
well.  This one has the additional feature of also protecting against the
previously mentioned "watchdog" programs at the same time.

The BODYGUARD.README file, mentioned in the text of BODYGUARD.COM is
included in the latter half of this post.  This contains documentation
on BODYGUARD, what it does, and how to use it.

Also, I usually put the first portion of the code in a "setup" file, and 
have all my utilities run off the pub$lib logical.  It's obviously not
necessary to have this be repeated each time BODYGUARD is run, but I put
it in there for completeness....

---
Michael Pye
email: mpye@csupomona.edu


---------------------- Cut Here for BODYGUARD.COM ------------------------
$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$!
$! BODYGUARD.COM -- keeps HITMAN at bay.
$! By: Michael Pye
$!
$!
$! BODYGUARD can be used to guard your terminal/process from HITMAN and other
$! would-be assassins.  BODYGUARD can be entered in three ways:
$!
$!   BODYGUARD        - Guards terminal/process against HITMAN.
$!   BODYGUARD STOP   - Stops the above guarding process.
$!   BODYGUARD LOCK   - Protects the terminal/process from both HITMAN
$!                      and wandering users.  It locks the terminal and 
$!                      requires a password to get back in.
$!
$! See the BODYGUARD.README file for more information.
$!
$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$!
$!
$! Find where this .COM file is located and set a logical to it.  All
$! symbols will be off of this logical.
$!
$ filsym = f$environment("PROCEDURE")	
$ devicesym = f$parse("''filsym'",,,"device","syntax_only")
$ define/nolog pub$disk 'devicesym'
$ disksym = f$parse("''filsym'",,,"directory","syntax_only")
$ define/nolog pub$lib pub$disk:'disksym'
$!
$! Define BODYGUARD executables.
$  BODYGUARD == "@pub$lib:bodyguard.com"
$  GUARD == "@pub$lib:bodyguard.com"
$  LOCK == "@pub$lib:bodyguard.com lock"
$!
$!
$!
$! *** Usual Start of BODYGUARD ***
$!
$ set symbol /scope=(nolocal,noglobal)
$ say = "write sys$output"
$ process_id = f$extract(4,4,f$getjpi("", "PID"))
$ guard_name = "GUARD_" + process_id
$ lock_name = "LOCK_" + process_id
$!
$!
$!
$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$!
$! Check to see how BODYGUARD was entered and branch appropriately.
$!
$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$!
$ if p1 .eqs. "STOP" then goto STOPGUARD
$ if p1 .eqs. "LOCK" then goto LOCK
$ if p1 .eqs. "LAUNCHED_GUARD" then goto LAUNCHED_GUARD
$ if p1 .eqs. "LAUNCHED_LOCK" then goto LAUNCHED_LOCK
$ if f$mode() .nes. "INTERACTIVE" then goto end
$ if f$getjpi( "", "TERMINAL" ) .eqs. "" then goto end
$!
$!
$!
$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$!
$! Check to see if process is already under guard.  If so, give an error
$! message and exit.  If not, start guarding it.
$!
$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$!
$ gosub check_guard
$ if (on_guard .eqs. "yes")
$   then
$      say ""
$      say "This process is already under guard by ''guard_name'."
$      say "Type GUARD STOP to terminate BODYGUARD."
$      say ""
$      goto end
$   else
$      goto guard_duty
$ endif
$ exit
$!
$!
$!
$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$!
$! Spawn the guarding process and give a message stating that the process
$! is now being guarded.  Exit.
$!
$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$!
$guard_duty:
$ spawn/nolog/nowait/input=nl:/proc='guard_name' -
	@'f$env("procedure")' LAUNCHED_GUARD 'guard_name'
$ say ""
$ say "BODYGUARD is launched; type GUARD STOP (or log out) to terminate it."
$ say ""
$ goto end
$!
$!
$!
$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$!
$! The GUARD_xxxx process will bypass the above code and come immediately 
$! here to do it's duty.  The TWIDDLE_THUMBS subroutine creates a dummy
$! file every minute to convince HITMAN that the process is active and 
$! shouldn't be terminated.
$!
$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$!
$LAUNCHED_GUARD:
$ guard_name = p2
$!
$twiddle_thumbs:
$ on error then goto twiddle_thumbs
$ tmpfile := SYS$LOGIN:'guard_name'.temporary_guard_file
$ open/write file 'tmpfile'
$ write file " "
$ write file "This is a BODYGUARD temporary file.  It's okay to delete it."
$ write file " "
$ write file "And thank you for using BODYGUARD...."
$ write file " "
$ close file
$ gosub delete_tmpfile
$ wait 0:01:00
$ goto twiddle_thumbs
$!
$!
$!
$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$!
$! Entering STOP as the first parameter for BODYGUARD will cause it to 
$! branch down here.  It first checks to see if the process is, indeed,
$! being guarded.  If so, it kills the bodyguard, gives the user an 
$! appropriate message, deletes any temporary leftover files, and exits.
$! If not, it gives an error message and exits.
$!
$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$!
$STOPGUARD:
$ gosub check_guard
$ if (on_guard .eqs. "yes")
$   then 
$      stop 'guard_name'
$      say ""
$      say "BODYGUARD terminated.  This process is now vulnerable to HITMAN."
$      say ""
$      tmpfile = "SYS$LOGIN:guard*.temporary_guard_file"
$      gosub delete_tmpfile
$      goto end
$   else
$      say ""
$      say "BODYGUARD is not currently guarding this process."
$      say ""
$ endif
$ goto end
$!
$!
$!
$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$!
$! The CHECK_GUARD: subroutine goes through the list of processes to
$! see if any are GUARDs (or LOCKs - see below) for the current process.
$! It simply reports it's findings to the calling routine.
$!
$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$!
$check_guard:
$ context = ""
$ on_guard = ""
$check_pids:
$ temp_id = f$pid(context)
$ if (temp_id .eqs. "") then goto last_id
$ temp_name = f$getjpi(temp_id,"PRCNAM")
$ if (temp_name .eqs. guard_name)
$   then 
$      on_guard = "yes"
$      return
$   else
$      goto check_pids
$ endif
$last_id:
$ on_guard = "no"
$ return
$!
$!
$!
$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$!
$! DELETE_TMPFILE: is called from several places.  It looks for the file
$! contained in the variable 'tmpfile' and deletes any & all occurances.
$!
$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$!
$delete_tmpfile:
$ filespec = f$search("''tmpfile'")
$ if (filespec .nes. "")
$   then  
$      delete/nolog 'tmpfile';*        
$   endif
$ return
$!
$!
$!
$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$!
$! Exit the procedure.  
$!
$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$!
$end:
$ exit
$!
$!
$!
$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$!
$! The following code handles the LOCK function of BODYGUARD.
$! 
$! The LOCK option of BODYGUARD is intended so the user can temporarily step
$! away from the terminal without logging off - and without worrying that 
$! someone else will play with it while he's gone.
$!
$! See the BODYGUARD.README file for more details.
$! 
$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$!
$LOCK:
$ old_verify= f$verify(0)
$ say = "write sys$output"
$ set control=y
$ on control_y then goto exitlock
$ on control_c then goto exitlock
$ on warning then goto exitlock
$ set on
$ say ""
$ say ""
$!
$!
$! 
$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$!
$! Prompt for a password and verification.  If there's anything wrong with
$! the password, verification, or the two don't match - exit with an error.
$! Otherwise, spawn the LOCK process.  The LOCK process will immediately
$! jump to LAUNCHED_LOCK: below and do it's duty.
$! 
$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$!
$ set terminal/noecho
$ read/prompt=" Enter Password: " sys$command c_pw
$ say ""
$ if (c_pw .eqs. "")
$   then 
$      say "No password entered - lock aborted.
$      goto exitlock
$   endif
$!
$ read/prompt="Verify Password: " sys$command v_pw
$ if (c_pw .nes. v_pw)
$   then 
$     say ""
$     say "Password and Verification do not match - lock aborted."
$     goto exitlock
$   else
$     type/page nl:
$     spawn/nolog/nowait/input=nl:/proc='lock_name' -
	    @'f$env("procedure")' LAUNCHED_LOCK 'lock_name'
$ endif
$!
$!
$! 
$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$!
$! RESET: sets up all the keys & things that could possibly break out of
$! LOCK and cuts em off at the knees.  Beware SET HOSTs, however.
$!
$! LOOP: continually checks for a password.  If none is entered, it does
$! nothing.  If an incorrect password is entered, it loops back and checks
$! again.  If a correct password was given, it breaks out and goes to ENDLOCK:
$! 
$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$!
$reset:
$ on control_y then goto reset
$ on control_c then goto reset
$ on warning then goto reset
$ set on
$!
$loop:
$ set noverify
$ read/end=loop/error=loop/prompt="" sys$command n_pw
$ if c_pw .eqs. n_pw then goto endlock
$ goto loop
$!
$!
$! 
$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$!
$! ENDLOCK: stops the LOCK process and gives the users an 'unlocked' message.
$!
$! EXITLOCK: resets the terminal to it's old state, kills any lingering 
$! temporary files, and exits.
$! 
$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$!
$endlock:
$ stop 'lock_name'
$ type/page nl:
$ say "Terminal unlocked."
$!
$exitlock:
$ set terminal/echo
$ old_verify:= f$verify(old_verify)
$ say ""
$ tmpfile = "SYS$LOGIN:lock*.temporary_lock_file"
$ gosub delete_tmpfile
$ goto end
$!
$!
$! 
$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$!
$! If the LOCK option spawned, the spawned process will jump down here.  
$! First, setup a few necessary variables.
$! 
$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$!
$LAUNCHED_LOCK:
$ lock_name = p2
$ esc[0,8] = %x1B
$ clear = esc + "[2J"
$ home = esc + "[1H"
$ reverse = esc + "[7m"
$ blink = esc + "[5m"
$ normal = esc + "[0m"
$ lead_in = clear + home + ""
$ tmpfile := SYS$LOGIN:'lock_name'.temporary_lock_file
$!
$!
$! 
$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$!
$! The LOCK process will stay down here in the DISPLAY_MESSAGE loop forever.
$! Or at least until it's stopped by the parent process.  It writes a message
$! out to a file.  Then it dumps that file to the screen, waits 30 seconds,
$! and does it all over again.
$! 
$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$!
$display_message:
$ time_string = lead_in + -
   f$extract( 0, 3, f$cvtime( , , "weekday" ) ) + " " -
 + f$edit( f$extract( 0, 17, f$time() ), "trim" )
$ open/write file 'tmpfile'
$ write file time_string
$ write file ""
$ write file "This terminal is in use.  Enter password to continue."
$ write file ""
$ write file ""
$ close file
$ copy 'tmpfile' sys$output
$ gosub delete_tmpfile
$ wait 0:00:30
$ goto display_message
--------------------------- End of BODYGUARD.COM ---------------------------


--------------------- Cut Here for BODYGUARD.README ------------------------

BODYGUARD -- keeps HITMAN at bay.

   BODYGUARD can be used to guard your terminal/process from HITMAN and other
   would-be assassins.  BODYGUARD can be entered in three ways:

      GUARD        - Guards terminal/process against HITMAN.
      GUARD STOP   - Stops the above guarding process.
      GUARD LOCK   - Protects the terminal/process from both HITMAN
                     and wandering users.  It locks the terminal and 
                     requires a password to get back in.

   For those unfamiliar with HITMAN, it is a system-level program that is 
   always running on the VAX.  HITMAN continually scans the VAX looking for
   idle users.  (HITMAN defines "idle users" as those who haven't done 
   anything for 45 minutes.)  Any users who haven't been active for 45 minutes
   will get a warning from HITMAN stating as much.  They'll get another
   warning at 55 minutes.  After one hour of inactivity, idle users are
   logged off by HITMAN.

   Enter the BODYGUARD.  BODYGUARD will guard your terminal/process and prevent
   HITMAN from terminating it (logging you off).  You may continue to work
   as normal - only you are in no danger from HITMAN.

   BODYGUARD accomplishes this by spawning a subprocess that stays active -
   whether the parent process does or not.  After launching BODYGUARD, you
   may notice a subprocess in the user list named GUARD_xxxx.  This process
   is BODYGUARD doing it's duty.  The bodyguard is automatically terminated
   when you log off.  If you wish to stop BODYGUARD from guarding your 
   process before logging off, enter STOP as the first parameter to bodyguard. 


GUARD LOCK - protecting your account from human-type assassins.

   The LOCK option of BODYGUARD was intended so a user can temporarily
   step away from the terminal without logging off - and without worrying
   that someone else will play with the account while he's gone.

   Typing GUARD LOCK will invoke the LOCK option of BODYGUARD.  This 
   will prompt you for a password.  Your password can be just about
   anything.  It will then prompt you to verify the password.  This
   is especially necessary since neither the password or the verification
   are shown when you type them.

   If the password and verification are both given, and agree, BODYGUARD
   proceeds to LOCK the terminal.  It first protects the terminal from 
   HITMAN.  It then displays a message on the terminal giving the date,
   time, and saying that the terminal is locked and a password is needed
   to continue.  This message is updated every 30 seconds.

   The terminal will stay like this until the correct password is entered.
   CTRL-Y, CTRL-C, etc. will not be able to break in.  (See SET HOST
   warning below.)  However, as soon as the correct password is entered,
   BODYGUARD unlocks the terminal and exits.  

   Note that once BODYGUARD exits from the LOCK option, it is also no 
   longer protecting against HITMAN.  If, however, a previous GUARD_xxxx 
   was on duty, it would not be affected by the LOCK option and would 
   continue to guard the process from HITMAN.


BODYGUARD - USAGE:

   Symbols should be made to point to BODYGUARD.COM.  Such as:

      $ GUARD == "@user_disk:[opr.mpye.public]:bodyguard.com"
      $ LOCK == "@user_disk:[opr.mpye.public]:bodyguard.com lock"

   Then, simply entering GUARD will protect the process from HITMAN.
   Entering LOCK will invoke the BODYGUARD LOCK option.



   * WARNING * WARNING * WARNING * WARNING * WARNING * WARNING * WARNING *
   * WARNING * WARNING * WARNING * WARNING * WARNING * WARNING * WARNING *
   * WARNING * WARNING * WARNING * WARNING * WARNING * WARNING * WARNING *

GENERAL WARNING: The purpose of HITMAN is two-fold:  

   1) It keeps the VAX accessible to as many users as possible.  There
      are a limited number of ports through which users can access the 
      system.  If someone forgets to log off, HITMAN will free this port
      after an hour to allow another to use it.

   2) HITMAN can actually be your friend.  If you forget to log off a
      public terminal, your account is vulnerable to other users passing
      by.  In this case, it would be desirable for HITMAN to log the 
      account off.

   Using BODYGUARD disables these two features.  For this reason, it 
   should be used "lightly" - only when you're certain you want your
   process to be guarded from HITMAN.  Above all, BODYGUARD should
   not be called from a LOGIN.COM file so that it is automatically
   invoked every time you log in.


WARNING - SET HOST and the LOCK option:

   GUARD LOCK cannot protect the originating process from a SET HOST
   command.  If you SET HOST to log into the VAX a second time and
   then invoke GUARD LOCK, the original process is still vulnerable.
   If someone happened to hit CTRL-Y a couple times on such a
   BODYGUARD protected process, the VAX DECNet software would allow
   them to return to the original process.  The other process - and
   BODYGUARD would be terminated.

