From: gavron@spades.aces.com (Ehud Gavron 602-570-2000 x. 2546)
Newsgroups: comp.os.vms
Subject: Re: VMSMAIL: %MAIL-E-NOTISAM (file organization changed)
Date: 13 Nov 92 17:44:00 GMT
Reply-To: gavron@ACES.COM
Organization: ACES Consulting Inc.
News-Software: VAX/VMS VNEWS 1.4-b1

In article <1992Nov12.200152.11582@dxcern.cern.ch>, aimar@dxbt00.cern.ch 
(Alberto Aimar SL/BT tel 2564) babbles...

#But I also got a very unpolite answer (the only one) who was posted by
#carl@SOL1.GPS.CALTECH.EDU (Carl J Lydick) to whom I explain how he
#could have used his spare time in better ways then posting useless insults.

Is that right?  Can you believe it?  Carl sent out USELESS insults?  I
am sorry!  Really!  The thought that he would send out USELESS insults
is horrifying.  Carl, did you really do this?

Listen you no good moron mail-stomping whining laut of a yoyo - Carl
knows his stuff.  If he (quite correctly) took the time to point out
WHERE your head is up your ASS then perhaps you should take his
advice and PULL IT OUT instead of whining about Carl being a bad boy.

#As most of you will not care about Carl's problems,

Carl isn't the one who posted the stupid problem - you were.  Next time
don't scrozzle your mail file and try and blame Carl for your inadequacies.
When he points out to you that you include no information, bow respectfully
and say "thank you", don't be a smart ass, because since you aren't smart,
you just end up as an ass.


#Sincerely Alberto Aimar.
# 
#        ``Carl, my dear, why dont you go to see a good doctor ?''

Alberto.  My dear.  Why don't you pick on someone your own size.  Pee Wee.

#Alberto Aimar.                "Who Wills, Can
#aimar@vxcrna.cern.ch           Who Tries, Does
#CERN Geneva (CH)               Who Loves, Lives" (Anne McCaffery)

It's sad when the rifraff come out and play.  Still it happens every
September. 

Ehud

--
Ehud Gavron        (EG76)     
gavron@aces.com
I liked it so much I bought the company.

Obligatory technical info:

	.TITLE	CHECK_EXE$GRANT_LICENSE	List all license checks on a node
	.IDENT	/V1.0.0-13Nov92/
;++
;
; CHECK_EXE$GRANT_LICENSE	13-Nov-1992			Ehud Gavron
;
; For those times you want to know what licenses are seeking validation,
; this image patches the executive to notify you about license checks.
;
; Although no merchantability is expressed or implied, this
; code was developed for and will work under V5.4-2.
;
;       Ehud Gavron             gavron@Spades.ACES.COM
;
;--
; V1.0.0        Created because I'm not getting enough interesting
;               kernel-coding to do in my regular job.
;
;
; Linking modifications:
;
			.link	"sys$system:sys.stb"/selective_search
;
; Definitions:
;
iif ndf $opdef,	.library "sys$library:lib.mlb"
iif ndf op$_jmp,	$opdef
iif ndf prt$c_urkw,	$prtdef
iif ndf pte$v_prot,	$ptedef
iif ndf ss$_normal,	$ssdef

;
; Offsets I stole from the VAX Architecture manual which indicate the
; location in the SCB of the pointers to the change mode handlers:
;
SCB_L_CMKRNL	=	^X40
SCB_L_CMEXEC	=	^X44

;
; Location of vector symbol and addresses:
;
fv_symbol:	.blkl	1	; The global symbol to find the code for
fv_vector:	.blkl	1	; The address of the code
;
; Argument list to pass it to FIND_VECTOR:
;
fv_arglst:	.long	2
		.address fv_symbol
		.address fv_vector
;
; Macros:
;
	.macro	cmd_store	cmd,cmdargs	; Store a command as a string
'cmd'_inst: 'cmd' 'cmdargs'			; Descriptor.  Eventually this
'cmd'_len = . - 'cmd'_inst			; will lead to a generic patch-
'cmd'_desc:	.long	'cmd'_len		; in-memory routine.
		.address 'cmd'_inst
	.endm

	.macro	FIND_AND_DESTROY symb		; A temporary macro to avoid
	movl	#symb,fv_symbol			; Having repetitious-looking
	$cmkrnl_s	routin=find_vector,-	; source-code.  This one will
			arglst=fv_arglst	; find a symbol, and call the
	$cmkrnl_s	routin=fixup_k,-	; fixup routine.
			arglst=fv_arglst
	.endm

;
; Start of user-mode code:
;
	.Entry	Fixup,^m<>			
	find_and_destroy	exe$grant_license	; Go patch it!
	ret
;
; Start of kernel-mode code:
;
	.entry	FIND_VECTOR,^m<r2,r3,r4,r5,r6,r7,r8,r9,r10,r11>
;
; Find out which system service or jump vector it is today...
;
	movl	@4(ap),r7		; Address of vector requested
	cmpw	(r7),#op$_jmp!<^x9f00>	; Check for JMP @#
	beql	10$			; It is, go use it
	addl	#2,r7			; Move past the entry mask
	cmpw	(r7),#op$_jmp!<^x9f00>	; Is it a JMP @#
	beql	10$			; Yup, go deal with it
	movl	#SCB_l_cmkrnl,r10	; Prepare for it being a CHMK
	cmpb	(r7),#op$_chmk		; Is it a CHMK #n
	beql	20$			; Yup, go deal with it
	movl	#SCB_l_cmexec,r10	; Prepare for it being a CHME
	cmpb	(r7),#op$_chme		; Is it a CHME #n
	beql	20$			; Yup, go deal with it
	movl	#ss$_unsupported,-	; Eeek, don't know what it is...
		r0			; So tell user it's unsupported
	ret				; and go back to user mode!

;
; So now we extract the address from the JMP instruction:
;
10$:
	addl2	#2,r7			; Get nn from JMP @#nn
	movl	(r7),@8(ap)
	movl	r7,@4(ap)
	movl	#ss$_normal,r0
	ret
;
; So now we get the number of the exception...
;
20$:
	addl2	#2,r7			; Get address of #nn from CHMx #nn
	movzbl	(r7),r8			; Get nn into R8
;
; So now we find the dispatcher address
;
	movl	@#exe$gl_scb,r1		; Get address of System Control Block
	addl2	r10,r1			; Get address of correct dispatcher
	movl	(r1),r1			; Get address of exe$cmodxxxx where
					; xxxx is either krnl or exec
;
; We look in its code for the dispatch vector table
;
	movab	movaq_inst,r2		; Address of our MOVAQ instruction	
	movzwl	(r2),r5
	addl3	#^xff,r1,r3		; Address past MOVAQ fer shure
30$:
	movzwl	(r1),r6
	cmpw	r6,r5			; Have we found a MOVAQ?
	beql	40$			; Yup!
	aobleq	r3,r1,30$
	movl	#ss$_nodata,r0		; Whoops, couldn't find it...
	ret				; So go back to user mode... sigh

;
; Ok, here R1 points to the start of a MOVAQ instruction that looks like:
; 	MOVAQ CMOD$AR_mode_DISPATCH_VECTOR[R1],R1
; which translates to bytes:	51hhllCF417E with hhll being the offset
; from the last byte (51).  We first save this current R1
;
40$:
	movl	r1,r9			; Address of MOVAQ
	movl	r1,r7			; Saved
;
; Then we find the offset
;
	addl2	#3,r9			; Address of hhll (word)
	movzwl	(r9),r3			; R3 = offset
;
; Then we add get the address of the end of the instruction
;
	addl2	#5,r7			; Address of last byte of instruction
;
; Then we add the offset
;
	addl2	r3,r7			; R7 = CMOD$AR_mode_DISPATCH_VECTOR
;
; Then we take our CHMn code and multiply by 8 (quadword vectors) and add
;
	ashl	#3,r8,r6		; Vector offset
	addl2	r6,r7			; Our vector
	addl2	#4,r7			; The address [2nd longword of vector]
	movl	(r7),@8(ap)		; Return this address
	movl	r7,@4(ap)		; Return address of address
	movl	#ss$_normal,r0
	ret


	.entry FIXUP_K,^m<r2,r3,r4,r5,r6,r7,r8,r9,r10,r11>
;++
; Make EXE$SETPRV ignore a particular username
;--
;
; Allocate a buffer in system space (nonpaged pool) to hold
; all the code to do this stuff...
;
	movl	#code_len,r1
	jsb	g^exe$alononpaged
	blbs	r0,10$
	ret
;
; Copy the code into the pool.
;
10$:	movl	r2,r6			; Save pointer to new npagedyn
	movc3	#code_len,-		; Copy code into npagedyn
		w^code,(r6)
;
; First we prepare the JMP instruction to stick in the front of the old
; EXE$GRANT_LICENSE.  We do this because it can be JSB'd to from Kernel
; mode.  If that occurs then just revectoring the CHMK vector doesn't
; help...
;
; Take the second jump at the end of the code and make it point to here...
;
	addl3	#<jump2-code+2>,r6,r2
	movl	r6,(r2)
;
; Now we change the jump instruction at the end to point to the real
; exe$setprv plus a couple of instructions.  Then we'll overwrite the
; first few instructions with the jump2 we prepared.  Finally at the
; end of our code segment are the instructions (from the listing) that
; we overwrote...
;
	movl	@4(ap),r2		; Address of entry point to exe$setprv
	addl3	#<jump-code+2>,r6,r7	; Address of jump data
	addl3	(r2),#^x07,r3		; R3 --> exe$grant_license+9(-2)
	movl	r3,(r7)			; Make jump go to exe$grant_license+9
	movl	r2,r7			; Save pointer
	movl	(r2),r8			; R8 --> exe$setprv
	movl	#prt$c_urkw,r9			; Set for URKW
	lock	lockname=MMG,-		; Raise IPL, acquire spinlock
		lockipl=#IPL$_MMG,-
		preserve=NO
	jsb	g^mmg$svaptechk		; Get SVAPTE in R3
	extzv	#pte$v_prot,#pte$s_prot,(r3),r10
	insv 	r9,#pte$v_prot,#pte$s_prot,(r3)
	invalidate_tb
	movl	r8,r2
	jsb	g^mmg$svaptechk
	extzv	#pte$v_prot,#pte$s_prot,(r3),r10
	insv 	r9,#pte$v_prot,#pte$s_prot,(r3)
	invalidate_tb 			; Translation Buffer Invalidate All
	movl	r6,(r7)			; Update vector
	movc3	#jump_len,-
		<jump2-code>(r6),(r8)	; Put the second jump in...

	unlock	lockname=MMG,-		; Release lock
		newipl=#0
	
	movl	#ss$_normal,r0
	ret


;
; The following code will be run each time EXE$GRANT_LICENSE is invoked.  It
; will spit out the name of the license on the console.
;
;
code:
	pushr	#^m<r0,r1,r2,r3,r4,r5,r6,r7,r8,r9>
IIF DF XDELTA, JSB G^INI$BRK
	movab	flag,r2		; Are we being quiet
	tstl	(r2)
	beql	out		; Yup, don't do anything
	movab	stringlen,r7	; r7 --> string length byte
	movl	04(ap),r0	; r0 --> string descriptor
	movzbl	(r0),(r7)	; string length byte set
	movzbl	(r0),r8		; r8 = length
	movl	04(r0),r9	; r9 --> string address
	movab	stringbuf,r7	; r7 --> string itself
	movc3	r8,(r9),(r7)	; copy string
	find_cpu_data r6	; r6 --> cpu database
	movab	stringlen,r1	; primary
	movab	string2,r2	; secondary
	jsb	g^smp$write_opa0
out:
	popr	#^m<r0,r1,r2,r3,r4,r5,r6,r7,r8,r9>

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;EXE$GRANT_LICENSE+00002:  MOVAL   @#CTL$GL_KRPFL,R0
;EXE$GRANT_LICENSE+00009:  REMQUE  @04(R0),R7
;EXE$GRANT_LICENSE+0000D:  BVS     SYSLICENSE+00028
;EXE$GRANT_LICENSE+0000F:  MOVC5   #00,(R7),#00,#0200,(R7)
;
	moval	@#ctl$gl_krpfl,r0
;;	remque	@04(r0),r7
;
; End of Digital code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

jump:						; This code will jump back in
	jmp	@#00000000
jump_len = . - jump
jump2:						; This jump will point to the
	jmp	@#00000000			; start of our code...
Data_area:
flag:	.long 1					; Quiet flag, 1 = noisy
stringlen:	.blkb	1			; Length of string
stringbuf:	.blkb	256			; String
string2:	.ascic <013><010>
code_len = . - code
        cmd_store       movaq   <w^10[r1],r1>
	.end 	fixup