From:	SMTP%"RELAY-INFO-VAX@CRVAX.SRI.COM" 28-JUN-1993 09:48:24.76
To:	EVERHART
CC:	
Subj:	Re: Easy Programming Project ! $100!!

Date: Fri, 25 Jun 1993 13:26:50 -0400 (EDT)
From: George Walrod <GWALROD@earth.cwc.com>
To: Info-VAX@kl.sri.com
Cc: GWALROD@earth.cwc.com
Message-Id: <930625132650.afb@earth.eng.cwc.com>
Subject: Re: Easy Programming Project ! $100!!

> It has to keep track of how long a Username has been on for the day (0-23:59)
> and log them off after an adjustable ammount of time, say 4 hours (settable
> through some external parameter).  It then has to be able to be polled as a
> function to prevent the user from logging in again after they've been logged
> off, IE, in a SYULOGIN.COM file, to telll the user they have to log in
> tomorrow.  It also has to reset everything at midnight so the hours can start
> again.  I dont care how it's done, but some folks have suggested using locks to
> keep track of when a person logs out.  Oh yes, it also has to handle unfriendly
> disconnects, like a STOP/ID or a dialup-hangup... so you can't just call a
> program or function when the user logs out.  It might have to be a single
> process that monitors all the other ones (other interactive ones that is).

I gave your problem some thought,  I would suggest you use something like
the public domain idle process kill program. Modifying it to create a INTRUDER 
record, but with a name unique (.i.e. ">BADUSER", so not in found by LOGINOUT).
Then in your SYLOGIN.COM file, use another program to check for the intruder
record or redirect SHOW INTRUDER to file and use the SEARCH utility if the
record exists.  If the record exists give that use a nice message.  If you want 
delete grant the user a reprieve use the command DELETE/INT ">BADUSER".  The 
normal maintainence of deleting the intruder record is done automatically by VMS.

Below is the program CLD and Source

usrcia.cld :

DEFINE VERB CHKCIA
	IMAGE "SYS$LOGIN:CHKCIA.EXE"
	PARAMETER P1, VALUE(REQUIRED), PROMPT="Username"
DEFINE VERB ADDCIA
	IMAGE "SYS$LOGIN:ADDCIA.EXE"
	PARAMETER P1, VALUE(REQUIRED), PROMPT="Username"
	PARAMETER P2, VALUE(REQUIRED,TYPE=$DATETIME), PROMPT="Expiration Time"

chkcia.mar :

 	.TITLE	CHKCIA		- Check for Username in CIA
	.IDENT	'V01-001'

;++
;
; Facility:	System Utilities
;
; Abstract:	This Program check if a Username is in the CIA intruder
;		list.
;
; Environment:	Kernel mode
;
; Modifications:
;	None
;
; Notes:
;	None
;
;--
	.SBTTL	DECLARATIONS
;
; Include Files and Libraries
;

	.LIBRARY	/SYS$LIBRARY:LIB/
	.LINK		"SYS$SYSTEM:SYS.STB" /SELECTIVE_SEARCH

;
; Equated Symbols
;

	$CIADEF				; CIA Definitions
	$SSDEF				; System Services Definitions
	$DSCDEF				; Descriptor Definitions

;
;  Routine Argument Offsets
;

	$OFFDEF	SEARCH,	-		; Search CIA List
		<USRNAM>		;  Username Descriptor
;
; Own Storage
;

P1_DESC:				; Username Parameter
	.ASCID	\P1\

USERNAME_DESC:				; Username Descriptor
USERNAME_LENGTH:			;  Length of Username
	.WORD	CIA$S_DATA
	.WORD	0
	.ADDRESS 10$
10$:	.BLKB	CIA$S_DATA		;  Username String Buffer

SEARCH_ARGLIST:				; Search Routine Argument List
	.LONG	SEARCH$_NARGS		;  Number of Arguments
	.ADDRESS USERNAME_DESC		;  Username Descriptor

;
;  Executable Code
;

	.ENTRY	CHKCIA, ^M<>

;
;  Get the Username from Command Line
;

	PUSHAW	USERNAME_LENGTH		;  Username Length
	PUSHAQ	USERNAME_DESC		;  Username Descriptor
	PUSHAQ	P1_DESC			;  Parameter Descriptor
	CALLS	#3,G^CLI$GET_VALUE	; Get Username
	BLBC	R0, 10$

;
;  Search for Username in CIA Intruder List
;

	$CMKRNL_S	-		; Search CIA Intruder List
		routin	= SEARCH, -
		arglst	= SEARCH_ARGLIST
10$:	RET				; Auf Wiedersehen!

;++
;
; MODULE:	SEARCH
;
; ABSTRACT:	Locate Username in CIA Intruder
;
; ENVIRONMENT:	Kernel Mode, Privileged Code
;
; INPUT PARAMETERS:
;	4(AP)	Address of Username Descriptor
;
; OUTPUT PARAMETERS:
;	R0	= 1		- Username Found
;		= 3		- Username Not Found
;
; SIDE EFFECTS:
;	None
;
;--
	.ENTRY	SEARCH, ^M<R2,R3,R4,R5,R6,R7,R8>

	MOVAB	G^CIA$GL_MUTEX, R0
	JSB	G^SCH$LOCKW		; Write Lock CIA Database

	MOVAB	@SEARCH$_USRNAM(AP), R8	; Get the Access of Username

	MOVAB	G^CIA$GQ_INTRUDER, R7	; Load Address of Database Link List
	MOVL	R7, R6			; Point to New Intruder

10$:	MOVZWL	#3, R0			; Clear the Status
	MOVL	CIA$L_FLINK(R6), R6	; Get the Address of Next Intruder
	CMPL	R6, R7			; Is it the End of the List
	BEQL	20$			; Yep!

	CMPB	CIA$B_SUBTYPE(R6), -	; Only Want to Look at Username
			#CIA$K_USERNAME
	BNEQ	10$

	CMPC5	DSC$W_LENGTH(R8), -	; Check if the Name Matches
		@DSC$A_POINTER(R8), #^A/ /, #CIA$S_DATA, CIA$T_DATA(R6)
	BNEQ	10$

	INCW	CIA$W_COUNT(R6)		; Since they were found Add to Count

	MOVZWL	#1, R0			; Set Successful Status
20$:	PUSHL	R0			; Save Status Registers
	MOVAB	G^CIA$GL_MUTEX, R0
	MOVL	G^CTL$GL_PCB, R4
	JSB	G^SCH$UNLOCK		; Unlock Database
	POPL	R0			; Restore Status Registers
	RET
	.END	CHKCIA

addcia.mar :

 	.TITLE	ADDCIA		- Add a User in CIA
	.IDENT	'V01-001'

;++
;
; Facility:	System Utilities
;
; Abstract:	This Program will add user in the CIA intruder list.
;
; Environment:	Kernel mode
;
; Modifications:
;	None
;
; Notes:
;	None
;
;--
	.SBTTL	DECLARATIONS
;
; Include Files and Libraries
;

	.LIBRARY	/SYS$LIBRARY:LIB/
	.LINK		"SYS$SYSTEM:SYS.STB" /SELECTIVE_SEARCH

;
; Equated Symbols
;

	$CIADEF				; CIA Definitions
	$DYNDEF				; Dynmanic Type Definitions
	$SSDEF				; System Services Definitions
	$DSCDEF				; Descriptor Definitions

;
;  Routine Argument Offsets
;

	$OFFDEF	SEARCH,	-		; Search CIA List
		<USRNAM, -		;  Username Descriptor
		 EXPTIM>		;  Expiration Binary Time

;
; Own Storage
;

P1_DESC:				; Username Parameter
	.ASCID	\P1\

USERNAME_DESC:				; Username Descriptor
USERNAME_LENGTH:			;  Length of Username
	.WORD	CIA$S_DATA
	.WORD	0
	.ADDRESS 10$
10$:	.BLKB	CIA$S_DATA		;  Username String Buffer

P2_DESC:				; Expiration Parameter
	.ASCID	\P2\

EXPTIME_DESC:				; Expiration Time Descriptor
EXPTIME_LENGTH:				;  Length of Expiration
	.WORD	23
	.WORD	0
	.ADDRESS 10$
10$:	.BLKB	23			;  Expiration String Buffer
EXPTIME:				; Binary Expiration Time
	.BLKQ	1

SEARCH_ARGLIST:				; Search Routine Argument List
	.LONG	SEARCH$_NARGS		;  Number of Arguments
	.ADDRESS USERNAME_DESC		;  Username Descriptor
	.ADDRESS EXPTIME		;  Expiration Time

;
;  Executable Code
;

	.ENTRY	ADDCIA, ^M<>

;
;  Get the Username from Command Line
;

	PUSHAW	USERNAME_LENGTH		;  Username Length
	PUSHAQ	USERNAME_DESC		;  Username Descriptor
	PUSHAQ	P1_DESC			;  Parameter Descriptor
	CALLS	#3,G^CLI$GET_VALUE	; Get Username
	BLBC	R0, 10$

;
;  Get the Expiration Date from Command Line and Convert to Binary
;

	PUSHAW	EXPTIME_LENGTH		;  Expiration Time Length
	PUSHAQ	EXPTIME_DESC		;  Expiration Time Descriptor
	PUSHAQ	P2_DESC			;  Parameter Descriptor
	CALLS	#3,G^CLI$GET_VALUE	; Get Expiration Date Time
	BLBC	R0, 10$

	$BINTIM_S	-		; Binary Time
		timbuf	= exptime_desc, -
		timadr	= exptime
	BLBC	R0, 10$

;
;  Search for Username in CIA Intruder List
;

	$CMKRNL_S	-		; Search CIA Intruder List
		routin	= SEARCH, -
		arglst	= SEARCH_ARGLIST
10$:	RET				; Auf Wiedersehen!

;++
;
; MODULE:	SEARCH
;
; ABSTRACT:	Locate Username in CIA Intruder, and add them.
;
; ENVIRONMENT:	Kernel Mode, Privileged Code
;
; INPUT PARAMETERS:
;	4(AP)	Address of Username Descriptor
;	8(AP)	Address of Binary Expiration Time
;
; OUTPUT PARAMETERS:
;	R0	= SS$_NORMAL	- Username Added
;
; SIDE EFFECTS:
;	None
;
;--
	.ENTRY	SEARCH, ^M<R2,R3,R4,R5,R6,R7,R8>

	MOVAB	G^CIA$GL_MUTEX, R0
	JSB	G^SCH$LOCKW		; Write Lock CIA Database

	MOVAB	@SEARCH$_USRNAM(AP), R8	; Get the Access of Username

	MOVAB	G^CIA$GQ_INTRUDER, R7	; Load Address of Database Link List
	MOVL	R7, R6			; Point to New Intruder

10$:	MOVL	CIA$L_FLINK(R6), R6	; Get the Address of Next Intruder
	CMPL	R6, R7			; Is it the End of the List
	BEQL	20$			; Yep!

	CMPB	CIA$B_SUBTYPE(R6), -	; Only Want to Look at Username
			#CIA$K_USERNAME
	BNEQ	10$

	CMPC5	DSC$W_LENGTH(R8), -	; Check if the Name Matches
		@DSC$A_POINTER(R8), #^A/ /, #CIA$S_DATA, CIA$T_DATA(R6)
	BEQL	30$			; Found it Just go Increment
	BRB	10$

20$:	MOVZWL	#CIA$K_LENGTH, R1	;  Size of CIA Entry
	JSB	G^EXE$ALONONPAGED	; Allocate Non-Paged Pool for Entry
	BLBC	R0, 40$

	MOVAB	(R2), R6		; Get the Address of Structure
	CLRQ	CIA$L_FLINK(R6)		; Clear the Forward/Backwards Link
	MOVW	R1, CIA$W_SIZE(R6)	; Size of Block
	MOVB	#DYN$C_SLAVCEB, -	; Type of Block Slave Common Mem. Blk
			CIA$B_TYPE(R6)
	MOVB	#CIA$K_USERNAME, -	; Username Intruder
			CIA$B_SUBTYPE(R6)
	CLRW	CIA$W_FLAGS(R6)		; Only a Suspect
	CLRW	CIA$W_COUNT(R6)		; Clear the Count Take of Later
	MOVQ    @SEARCH$_EXPTIM(AP), -	; Set the Expiration Time
			CIA$Q_TIME(R6)
	MOVC5	DSC$W_LENGTH(R8), -	; Set the Username
		@DSC$A_POINTER(R8), #^A/ /, #CIA$S_DATA, CIA$T_DATA(R6)
	INSQUE	CIA$L_FLINK(R6), -	; Add to Tail of Queue
			@CIA$L_BLINK(R7)

30$:	INCW	CIA$W_COUNT(R6)		; Since they were found Add to Count

	MOVZWL	#1, R0			; Set Successful Status
40$:	PUSHL	R0			; Save Status Registers
	MOVAB	G^CIA$GL_MUTEX, R0
	MOVL	G^CTL$GL_PCB, R4
	JSB	G^SCH$UNLOCK		; Unlock Database
	POPL	R0			; Restore Status Registers
	RET
	.END	ADDCIA

To add a intruder record

  $ SET COMMAND USRCIA
  $ ADDCIA >MARTIN "+5"     ! User Martin will not be to login for 5 hours

To check for user

  $ SET COMMAND USRCIA
  $ CHKCIA >MARTIN          ! Check if user Martin is a intruder
  $ IF $STATUS .EQS. 1 THEN LOGOUT

To delete the record
  $ DELETE/I >MARTIN

> If it all runs well, I'll pay you $100... the price is somewhat
> negotiable.  Oh yeah, I'd like the source at the end, if possible,
> but it will still be owned by you...

I believe in the free exchange if information in this forum, donate the
money to Children's Hospital.

P.S. Do want you want with the source.

+-----------------------------+
+ George "Dogcatcher" Walrod  +
+ gwalrod@earth.eng.cwc.com   +
+ (703)734-4405 (301)474-2971 +
+-----------------------------+


