;
AUTOLOGIN.MAR og in a specified username to a specified terminal
;From: deleyd@netcom.com
;Subj: Re: UIC of detached proc. using LOGINOUT? (Ive RTFM and am puzzled)
;Date: Wed, 5 Oct 1994 04:01:38 GMT
;
;> However, the real problem is that if I detach a process using LOGINOUT,
;> despite specifying a different UIC, the UIC of the detached process is
;> still the UIC of process creating the detached process.
;
;You'll need DETACH privilege to specify a different UIC. As for the username,
;we solve the problem by temporarily changing the username to what you
;want the detached process to be, creating the detached process, and
;then resetting the username back to our own username. The sample
;MACRO32 code below does this. Maybe it will give some ideas. Maybe
;someone else has a better example that's not in MACRO32.
;
;Another idea is to create a batch job which starts the detached process,
;and then use $ SUBMIT/NAME=username
;to submit the batch job. This requires CMKRNL priv. There's probably
;some other good ideas someone else will come up with.
;
;-David Deley
;deleyd@netcom.com
;
;Below is a sample program in MACRO:
; This code requires CMKRNL privilege. It has been tested on VAX/VMS.
;I don't know how to do this yet on an AXP/OpenVMS system.
;
;[DAVID.AUTOLOGIN] (VAX/VMS. Concept has not been tested
; on AXP/OpenVMS systems)
;
;This example MACRO program will log in a specified username to a
;specified terminal as if someone had entered their username and password
;interactively at the terminal. The terminal will "jump to life" by
;itself.
;
;This example program as set up here logs in username VISIT to terminal
;TXF4: with process name "sys_immoVAULT"
;
;Change NEW_USRNAM: to the username you want to login
;Change TERMINAL: to the terminal you want username to log into
;Change PROC_NAME: to the process name you want username to use
;
;(Leave PRIVS: as is. Privileges and all other process details are set
; by LOGINOUT.EXE according to username listing in
; SYSUAF.DAT as set by AUTHORIZE.)
;
;
;This program executes some code in kernel mode. As you know errors in
;kernel mode can crash the system, so test it gingerly keeping that in
;mind. It does establish a crash handler so if an error should occur it
;should terminate the image with a stack dump rather than crash the whole
;system.
;
;The key to this program is the use of the flag PRC$M_NOPASSWORD in the
;call to $CREPRC. See the VAX/VMS System Service Reference Manual
;documentation of the $CREPRC system service for further information.
;This program has been tested on VMS 4.4 and VMS 5.3 .
;
;David W. Deley
;
;$!Compile and link AUTOLOGIN program
;$ MACRO AUTOLOGIN
;$ LINK AUTOLOGIN
;$ EXIT
;
.TITLE AUTOLOGIN
.LIBRARY /SYS$LIBRARY:LIB/
.LINK 'SYS$SYSTEM:SYS.STB' /SELECTIVE_SEARCH
.PSECT DATA, WRT, NOEXE, RD
$CHFDEF
$JIBDEF
$PCBDEF
$PRCDEF
PRIVS: .LONG ^xFFFFFFFF
.LONG ^xFFFFFFFF
IMGNAM: .ASCID /SYS$SYSTEM:LOGINOUT.EXE/ ;Creprc runs LOGINOUT
;TERMINAL: .ASCID /TXF4:/
TERMINAL: .ASCID /LTA28:/
PROC_NAME: .ASCID /sys_immoVAULT/
OLD_USRNAM: .BLKB 12
NEW_USRNAM: .ASCII /VISIT/
NEW_USRNAMLEN=.-NEW_USRNAM
ERRMSG: .ASCIZ /AUTOLOGIN KERNEL MODE ERROR/
;------------------------------------------------------------------------------
.PSECT CODE, NOWRT, EXE
.ENTRY AUTOLOGIN, ^M<>
$CMKRNL_S routin=SAVE_USERNAME ;Save our username
BLBC R0,EXIT
$CMKRNL_S routin=SET_USERNAME ;Set new username
BLBC R0,EXIT
$CREPRC_S - ;AUTOLOGIN PROCESS
image=imgnam, - ;run LOGINOUT.EXE
input=terminal, - ;assign SYS$INPUT
output=terminal, - ;assign SYS$OUTPUT
error=terminal, - ;assign SYS$ERROR
prvadr=privs, - ;Privs get set by loginout according to UAF
prcnam=proc_name, - ;Set process name
baspri=#4, - ;Set base priority
STSFLG=#
BLBC R0,EXIT
$CMKRNL_S routin=RESTORE_USERNAME
EXIT: $EXIT_S R0
;------------------------------------------------------------------------------
.ENTRY SAVE_USERNAME, ^M<> ; R4 contains PCB address (supplied by CMKRNL)
MOVAL HANDLER,(FP) ; Establish crash handler
MOVL PCB$L_JIB(R4), R4
MOVC3 #12, JIB$T_USERNAME(R4), OLD_USRNAM
MOVL #SS$_NORMAL,R0
RET
.ENTRY SET_USERNAME, ^M<> ; R4 contains PCB address (supplied by CMKRNL)
MOVAL HANDLER,(FP) ; Establish crash handler
MOVL PCB$L_JIB(R4), R4
MOVC5 #NEW_USRNAMLEN, NEW_USRNAM, #32, #12, JIB$T_USERNAME(R4)
MOVL #SS$_NORMAL,R0
RET
.ENTRY RESTORE_USERNAME, ^M<> ; R4 contains PCB address (supplied by CMKRNL)
MOVAL HANDLER,(FP) ; Establish crash handler
MOVL PCB$L_JIB(R4), R4
MOVC3 #12, OLD_USRNAM, JIB$T_USERNAME(R4)
MOVL #SS$_NORMAL,R0
RET
.ENTRY HANDLER ^M<>
MOVL CHF$L_SIGARGLST(AP),R0 ;Get address of signal args
CMPL #SS$_UNWIND,- ;Check for unwind operation
CHF$L_SIG_NAME(R0)
BEQL 1$ ;Return if unwinding
PUSHL AP ;Address of sigargs
PUSHAL ERRMSG ;Address of ASCIZ string
CALLS #2,G^EXE$EXCMSG ;Dump error message
CALLG (AP),G^LIB$SIG_TO_RET ;Unwind stack and return to caller
1$: RET
.END AUTOLOGIN