From:	CSBVAX::MRGATE!RELAY-INFO-VAX@CRVAX.SRI.COM@SMTP 16-SEP-1988 09:02
To:	ARISIA::EVERHART
Subj:	Termlock v1.05 (part 1 of 3)


Received: From KL.SRI.COM by CRVAX.SRI.COM with TCP; Fri, 16 SEP 88 05:07:10 PDT
Received: from ucbvax.Berkeley.EDU by KL.SRI.COM with TCP; Fri, 16 Sep 88 04:59:40 PDT
Received: by ucbvax.Berkeley.EDU (5.59/1.31)
	id AA28295; Tue, 13 Sep 88 05:42:24 PDT
Received: from USENET by ucbvax.Berkeley.EDU with netnews
	for info-vax@kl.sri.com (info-vax@kl.sri.com)
	(contact usenet@ucbvax.Berkeley.EDU if you have questions)
Date: 8 Sep 88 23:39:01 GMT
From: mcmi!hdr!unocss!dent@uunet.uu.net  (Dave Caplinger)
Organization: U. of Nebraska at Omaha
Subject: Termlock v1.05 (part 1 of 3)
Message-Id: <401@unocss.UUCP>
Sender: info-vax-request@kl.sri.com
To: info-vax@kl.sri.com

Below is the first part of Termlock v1.05, in VMS_SHARE format (finally).

Among the changes from the previously posted version (besides being in VMS_
SHARE) are:

	o   Allow editing of the TERMLOCK.LOG file as well as viewing
	o   Last-resort error handler to log out process in case of
	     some error condition that I haven't thought of. (The previous
	     version would on occasion stack-dump, apparently because of
	     a recursive call to an AST routine.)

For more detailed information about the changes, just read the top portion
of the source code.

Instructions for compiling the program are in the comment section as well,
but if you don't have a C compiler and still want to run TERMLOCK, and
happen to be on BITNET as well, running JNET (obviously), then I would be
happy to send you the executable.  (Though some system managers would
understandably cringe at an executable without any source code...)

As always, bug reports, flames, comments, suggestions, etc. to:

-/ Dave Caplinger /--------------+--------------------------------------------
 Microcomputer Specialist        | Internet: UNOCC07%ZEUS.DNET@FERGVAX.UNL.EDU
 Campus Computing                | UUCP:     uunet!unocss!dent
 University of Nebraska at Omaha | Bitnet:   UNOCC07@UNOMA1
 Omaha, NE 68182                 |   or      dc3a+@andrew.cmu.edu

$!.............................................................................
$! VAX/VMS archive file created by VMS_SHARE V06.00 26-May-1988.
$!
$! VMS_SHARE was written by James Gray (Gray:OSBUSouth@Xerox.COM) from
$! VMS_SHAR by Michael Bednarek (U3369429@ucsvc.dn.mu.oz.au).
$!
$! To unpack, simply save, concatinate all parts into one file and
$! execute (@) that file.
$!
$! This archive was created by user UNOCC07
$! on  8-SEP-1988 18:25:35.19.
$!
$! ATTENTION: To keep each article below 31 blocks (15872 bytes), this
$!            program has been transmitted in 3 parts.  You should
$!            concatenate ALL parts to ONE file and execute (@) that file.
$!
$! It contains the following 1 file:
$!        TERMLOCK.C
$!
$!==============================================================================
$ SET SYMBOL/SCOPE=( NOLOCAL, NOGLOBAL )
$ VERSION = F$GETSYI( "VERSION" )
$ IF VERSION .GES "V4.4" THEN GOTO VERSION_OK
$ WRITE SYS$OUTPUT "You are running VMS ''VERSION'; ", -
    "VMS_SHARE V06.00 26-May-1988 requires VMS V4.4 or higher."
$ EXIT 44 
$VERSION_OK:
$ GOTO START
$
$UNPACK_FILE:
$ WRITE SYS$OUTPUT "Creating ''FILE_IS'"
$ DEFINE/USER_MODE SYS$OUTPUT NL:
$ EDIT/TPU/COMMAND=SYS$INPUT/NODISPLAY/OUTPUT='FILE_IS'/NOSECTION -
    VMS_SHARE_DUMMY.DUMMY
b_part := CREATE_BUFFER( "{Part}", GET_INFO( COMMAND_LINE, "file_name" ) )
; s_file_spec := GET_INFO( COMMAND_LINE, "output_file" ); SET( OUTPUT_FILE
, b_part, s_file_spec ); b_errors := CREATE_BUFFER( "{Errors}" ); i_errors 
:= 0; pat_beg_1 := ANCHOR & "-+-+-+ Beginning"; pat_beg_2 := LINE_BEGIN 
& "+-+-+-+ Beginning"; pat_end := ANCHOR & "+-+-+-+-+ End"; POSITION
( BEGINNING_OF( b_part ) ); i_append_line := 0; LOOP EXITIF MARK( NONE 
) = END_OF( b_part ); s_x := ERASE_CHARACTER( 1 ); IF s_x = "+" THEN r_skip 
:= SEARCH( pat_beg_1, FORWARD, EXACT ); IF r_skip <> 0 THEN s_x := ""
; MOVE_HORIZONTAL( -CURRENT_OFFSET ); ERASE_LINE; ENDIF; ENDIF
; IF s_x = "-" THEN r_skip := SEARCH( pat_end, FORWARD, EXACT ); IF r_skip <
> 0 THEN s_x := ""; MOVE_HORIZONTAL( -CURRENT_OFFSET ); m_skip := MARK( NONE )
; r_skip := SEARCH( pat_beg_2, FORWARD, EXACT ); IF r_skip <> 0 THEN POSITION
( END_OF( r_skip ) ); MOVE_HORIZONTAL( -CURRENT_OFFSET ); MOVE_VERTICAL( 1 )
; MOVE_HORIZONTAL( -1 ); ELSE POSITION( END_OF( b_part ) ); ENDIF; ERASE
( CREATE_RANGE( m_skip, MARK( NONE ), NONE ) ); ENDIF; ENDIF
; IF s_x = "V" THEN s_x := ""; IF i_append_line <> 0 THEN APPEND_LINE
; MOVE_HORIZONTAL( -CURRENT_OFFSET ); ENDIF; i_append_line := 1; MOVE_VERTICAL
( 1 ); ENDIF; IF s_x = "X" THEN s_x := ""; IF i_append_line <
> 0 THEN APPEND_LINE; MOVE_HORIZONTAL( -CURRENT_OFFSET ); ENDIF
; i_append_line := 0; MOVE_VERTICAL( 1 ); ENDIF; IF s_x <> "" THEN i_errors 
:= i_errors + 1; s_text := CURRENT_LINE; POSITION( b_errors ); COPY_TEXT
( "The following line could not be unpacked properly:" ); SPLIT_LINE
; COPY_TEXT( s_x ); COPY_TEXT( s_text ); POSITION( b_part ); MOVE_VERTICAL( 1 
); ENDIF; ENDLOOP; POSITION( BEGINNING_OF( b_part ) ); LOOP r_x := SEARCH( "`"
, FORWARD, EXACT ); EXITIF r_x = 0; POSITION( r_x ); ERASE_CHARACTER( 1 )
; IF CURRENT_CHARACTER = "`" THEN MOVE_HORIZONTAL( 1 ); ELSE COPY_TEXT( ASCII
( INT( ERASE_CHARACTER( 3 ) ) ) ); ENDIF; ENDLOOP; IF i_errors = 0 THEN SET
( NO_WRITE, b_errors, ON ); ELSE POSITION( BEGINNING_OF( b_errors ) )
; COPY_TEXT( FAO( "The following !UL errors were detected while unpacking !AS"
, i_errors, s_file_spec ) ); SPLIT_LINE; SET( OUTPUT_FILE, b_errors
, "SYS$COMMAND" ); ENDIF; EXIT; 
$ DELETE VMS_SHARE_DUMMY.DUMMY;*
$ CHECKSUM 'FILE_IS
$ WRITE SYS$OUTPUT " CHECKSUM ", -
  F$ELEMENT( CHECKSUM_IS .EQ. CHECKSUM$CHECKSUM, ",", "failed!,passed." )
$ RETURN
$
$START:
$ FILE_IS = "TERMLOCK.C"
$ CHECKSUM_IS = 1342889697
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X/***********************************************************************/
X/*                                                                     */
X/*   TERMLOCK`009`009`009`009`009`009`009       */
X/*`009`009`009`009`009`009`009`009       */
X/*`009This program will automatically reply to user messages, phone  */
X/*   requests, and network files with a different message depending on */
X/*   the type of message received.  The standard user-message reply    */
X/*   can be redefined by the user by 1) defining TERMLOCK as a foreign */
X/*   command (i.e. $ termlock :== $the$disk:[the.path]the.file ), and  */
X/*   2) adding an additional argument in quotes.  The TERMLOCK program */
X/*   additionally provides the ability to lock the terminal with a     */
X/*   user-defined password, so the user can run the program with a msg */
X/*   like: TERMLOCK "I'm at lunch right now, be back at 12:45.", lock  */
X/*   the terminal, and leave the office without having to worry about  */
X/*   someone walking in, hitting 'Q', and damaging his or her account. */
X/*`009TERMLOCK logs all messages it receives in a file called        */
X/*   TERMLOCK.LOG in the user's login directory (sys$login).  The file */
X/*   can be deleted when the log is no longer wanted.`009`009       */
X/*`009`009`009`009`009`009`009`009       */
X/*   Many thanks to Eric Rostetter of the University of Toledo for the */
X/*   original program "REPLY", which was the inspiriation for (and     */
X/*   indeed the very basis of) this program.  Several of the routines  */
X/*   included here are written by him.  (The majority of, as a matter  */
X/*   of fact! :-)  Many thanks also to Tim Russell, CONSLT32@UNOMA1,   */
X/*   for his invaluble help in programming and extensive testing.      */
X/*
X     Bug reports, comments, questions, etc to:
X
X-/ Dave Caplinger /---------------+----------------------------------------
X  Microcomputer Specialist        | Internet: unocc07%zeus@crcvms.unl.edu
X  Campus Computing                | uucp:     uunet!ugn!unocss!dent
X  University of Nebraska at Omaha | Bitnet:   UNOCC07@UNOMA1
X  Omaha, NE 68182                 | (Last Resort: dc3a+@andrew.cmu.edu)
X
X*/
X/***********************************************************************/
X/*`009`009`009`009`009`009`009`009       */
X/* This program will correctly handle the following types of messages: */
X/*                                                                     */
X/*`009Message Type`009`009`009       Log    Reply  Display   */
X/*                                                                     */
X/*`009SEND user "msg"`009`009`009`009x`009x`009       */
X/*`009SEND user@node "msg"`009`009`009x`009x`009       */
X/*`009SEND node::user "msg"`009`009`009x`009x`009       */
X/*`009SEND/FILE file user`009`009`009x`009x`009       */
X/*`009SEND/FILE file user@node`009`009x`009x`009       */
X/*`009SEND/FILE file node::user`009`009x`009x`009       */
X/*`009PHONE user`009`009`009`009x`009x`009       */
X/*`009PHONE node::user`009`009`009x`009x`009       */
X/*`009REPLY (from operator)`009`009`009x`009`009x      */
X/*`009REPLY/URGENT`009`009`009`009x`009`009x      */
X/*`009REPLY/SHUTDOWN`009`009`009`009x`009`009x      */
X/*`009(New Mail...)`009`009`009`009x`009`009       */
X/*`009(Job completed...)`009`009`009x`009`009       */
X/*`009`009`009`009`009`009`009`009       */
X/*`009NOTE: messages from the person running the program not logged  */
X/*`009  and not replied to (this would start an infinite loop).      */
X/*`009  Also, messages received that begin with * are ignored.       */
X/*`009  (This prevents replies to servers, other TERMLOCKs running   */
X/*`009  at the same time, etc.)  Lastly, messages received from      */
X/*`009  machines themselves (i.e. the response from something like   */
X/*`009  SEND @UNOMA1 FINGER UNOCC07) are ignored.                    */
X/*                                                                     */
X/***********************************************************************/
X/*                                                                     */
X/* Modification History: (For REPLY, written by Eric Rostetter)        */
X/*                                                                     */
X/*      21-JAN-1986     Finished initial coding of program version 1.0 */
X/*      21-APR-1986     Update for the new version of JNET (user@node) */
X/*      18-JUN-1986     Fix GET_NAME bug,  make it ignore csnews@maine */
X/*      16-SEP-1986     Added code to save and restore terminal stuffs */
X/*      19-SEP-1986     Added code to allow the user to supply message */
X/*      23-SEP-1986     Added code to display time and date on  screen */
X/*       9-OCT-1986     Removed SMG routines and added mailbox routine */
X/*      14-OCT-1986     Cleaned up the screen I/O and what have you... */
X/*      20-OCT-1986     Add code to stop the infinite loop problems... */
X/*       2-DEC-1986     Fixed reply_to_msg so screen is always updated */
X/*      17-DEC-1986     Fixed 'logout' bug caused by network/blank msg */
X/*      11-FEB-1987     Kludged bug in UPDATE_TIME,  added ^C/^Y traps */
X/*      31-MAR-1987     Added logical name translation,  fixed isvalid */
X/*       9-APR-1987     Removed reference to LNMDEF.H for compatibilty */
X/*      13-APR-1987     Added third counter, reset counters code, etc. */
X/*      14-APR-1987     Cleaned up the code, made slight modifications */
X/*      19-AUG-1987     Changed logicals for JNET version 3.2 supports */
X/*      14-DEC-1987     Add startup message to let one know it's going */
X/*       8-FEB-1988     Changed editor command to use callable editors */
X/*       9-FEB-1988     Added '$' to list of good node/name characters */
X/*      29-JUN-1988     Cleaned up code some, added reply for files... */
X/*                                                                     */
X/***********************************************************************/
X/*                                                                     */
X/* Modifications made for TERMLOCK.C by Dave Caplinger and Tim Russell */
X/*                                                                     */
X/*`00918-JUL-1988`009Changed reply message to indicate program      */
X/*`009`009`009Modified reply_to_file to only reply to        */
X/*`009`009`009`009users on the same node.                */
X/*`009`009`009Disabled ^Y and ^C completely - bell rings     */
X/*`009`009`009Removed editor support - added MORE-like view. */
X/*`009`009`009Added password support to lock terminal.       */
X/*`009`009`009Added log of # of failed unlock attempts       */
X/*`009`009`009Disabled control-t so people can't fill file   */
X/*`00920-JUL-1988`009Cleaned up 'V' option to add percent and 'Q'.  */
X/*`009`009`009Added control-w to redraw screen (usefull for  */
X/*`009`009`009`009multi-session terminals).              */
X/*`00924-JUL-1988`009Added special handling for (local) PHONE msgs. */
X/*`009`009`009Ignored messages from user running TERMLOCK.   */
X/*`009 7-AUG-1988`009Finished version 1.0 of TERMLOCK.C, including  */
X/*`009`009`009`009automatic prepending reply message     */
X/*`009`009`009`009with "* " if not there (to follow the  */
X/*`009`009`009`009convention of messages beginning with  */
X/*`009`009`009`009"*" coming from programs, servers, and */
X/*`009`009`009`009the like.  Special handling of REPLY   */
X/*`009`009`009`009messages from an OPERATOR; REPLY msgs  */
X/*`009`009`009`009are now echoed to the screen as well   */
X/*`009`009`009`009in case of system down-time notices,   */
X/*`009`009`009`009etc.  (Still logged.)`009`009       */
X/*`00911-AUG-1988`009Fixed bug with user-defined reply message not  */
X/*`009`009`009`009being allowed to be > ~60 chars, fixed */
X/*`009`009`009`009idiotic bug of using '\013' for <CR>   */
X/*`009`009`009`009instead of '\0x0D' or whatever. :-)    */
X/*`00915-AUG-1988`009Reincarnated the EDIT command, "back by        */
X/*`009`009`009`009popular demand".  Minor bug fixes.     */
X/*`00920-AUG-1988`009Replies to SEND/FILE now include remote sites  */
X/*`00924-AUG-1988`009Introduced "bad_signal()" generic exception    */
X/*`009`009`009`009handler to log out the TERMLOCK        */
X/*`009`009`009`009process(s) if something happens that   */
X/*`009`009`009`009TERMLOCK wasn't designed to handle (In */
X/*`009`009`009`009other words, bail out as a last resort */
X/*`009`009`009`009instead of stack-dump) (up to v1.05)   */
X/***********************************************************************/
X/*`009`009`009`009`009`009`009`009       */
X/*  To compile:`009`009`009`009`009`009`009       */
X/*`009`009`009`009`009`009`009`009       */
X/*`009$ cc termlock`009`009`009`009`009`009       */
X/*`009$ link/notrace termlock,sys$input:/opt`009`009`009       */
X/*`009sys$share:vaxcrtl/share`009`009`009`009`009       */
X/*`009<CTRL-Z>`009`009`009`009`009`009       */
X/*`009`009`009`009`009`009`009`009       */
X/***********************************************************************/
X
X#include <stdio>
X#include <descrip>
X#include <ctype>
X#include <iodef>
X#include <ttdef>
X#include <tt2def>
X#include <ssdef>
X#include <jpidef>
X#include <errno>
X
X#define esc 27
X#define odd( stat )`009( (stat) & 1 )
X#define LNM$_STRING 2
X#define LNM$M_CASE_BLIND 33554432
X 
X/***********************************************************************/
X/* First define all the needed global data structures for the programs */
X/***********************************************************************/
X 
XFILE    *fp;                            /* output file id for messages. */
X 
Xint     status;                         /* return status from functions */
Xint     user_cnt, sys_cnt, old_cnt;`009/* number of messages that came */
Xint     tt_chan,mbx_chan,msg_chan,pid;  /* kb and mbx luns, process ids */
Xint     old_term_char,old_extended;     /* old terminal characteristics */
Xint`009bad_tries = 0;`009`009`009/* number of unsuccessfull 'U's */
Xint`009ignore,send,file,phone,mail,job,local,reply; /* type flags for msgs. */
X
Xunsigned old_ctrl, no_ctrlt = 1048576;`009/* control enable masks         */
X
Xint`009mypid;
Xchar`009myprocname[16];
Xchar    password[11];`009`009`009/* lock password                */
Xchar`009who[9],where[9],what[20];`009/* who@where sent what.         */
X
Xchar    *decnet_node,
X`009*bitnet_node;
Xchar`009myself[L_cuserid];`009`009/* The user running this prgm   */
X
Xchar    *tranlog( char *s, int flag);   /* tranlate logicals subroutine */
X
Xchar`009send_msg[110];
Xchar    reply_string[110] =
X`009"* Away from terminal -- Message logged, Will reply ASAP.";
Xchar`009phone_string[110] =
X`009"* Away from terminal -- cannot answer phone.  Please send a message.";
X 
Xstruct  {                               /* the date and time of message */
X        char    weekday[10];            /* --> the day of the week here */
X        char    filler[1];              /* --> always contains a space! */
X        char    date[12];               /* --> the date in ascii please */
X        char    time[08];               /* --> the time in ascii please */
X        } header;
X 
Xstruct {unsigned class          :8;     /* --> terminal class goes here */
X        unsigned type           :8;     /* --> the terminal type please */
X        unsigned page_width     :16;    /* --> terminal width goes here */
-+-+-+-+-+ End of part 1 +-+-+-+-+-

