From:	CSBVAX::CSBVAX::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX" 27-FEB-1989 15:07
To:	MRGATE::"ARISIA::EVERHART"
Subj:	setuser 2 of 3


Received: From KL.SRI.COM by CRVAX.SRI.COM with TCP; Sat, 25 FEB 89 01:31:30 PDT
Received: from ucbvax.Berkeley.EDU by KL.SRI.COM with TCP; Sat, 25 Feb 89 01:33:22 PST
Received: by ucbvax.Berkeley.EDU (5.61/1.34)
	id AA20746; Sat, 25 Feb 89 01:22:53 -0800
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: 24 Feb 89 20:45:13 GMT
From: rochester!rit!ultb!awpsys@rutgers.edu  (Andrew W. Potter)
Organization: Information Systems and Computing @ RIT, Rochester, New York
Subject: setuser 2 of 3
Message-Id: <383@ultb.UUCP>
Sender: info-vax-request@kl.sri.com
To: info-vax@kl.sri.com


+-+-+-+ Beginning of part 2 +-+-+-+
Xist
V                movl    4(r11), lnm_buf_adr     ; - for the following logical
Xs
X                $crelnm_s -
X                        tabnam = job_table, -
X                        lognam = sys_login_dev, -
X                        acmode = exec_mode, -
V                        itmlst = lnm_item       ; Define SYS$LOGIN_DEVICE in
X EXEC
X                blbs    r0, 40$
X;
X                pushl   r0
X                pushal  exec_mode_str
X                pushal  sys_login_dev
X                pushl   #2
X                pushl   #SETUSER_CRELNMFAIL
X                calls   #5, g`094lib$signal
X;
X40$:            $crelnm_s -
X                        tabnam = proc_table, -
X                        lognam = sys_disk, -
X                        acmode = exec_mode, -
X                        itmlst = lnm_item       ; Define SYS$DISK in EXEC
X                blbs    r0, 50$
X;
X                pushl   r0
X                pushal  exec_mode_str
X                pushal  sys_disk
X                pushl   #2
X                pushl   #SETUSER_CRELNMFAIL
X                calls   #5, g`094lib$signal
X;
X50$:            $crelnm_s -
X                        tabnam = proc_table, -
X                        lognam = sys_disk, -
X                        acmode = supr_mode, -
X                        itmlst = lnm_item       ; Define SYS$DISK in USER
X                blbs    r0, 60$
X;
X                pushl   r0
X                pushal  supr_mode_str
X                pushal  sys_disk
X                pushl   #2
X                pushl   #SETUSER_CRELNMFAIL
X                calls   #5, g`094lib$signal
X;
X60$:            movl    #1, r0                  ; We completed successfully
X                ret
X;
X                .end
$ GOSUB UNPACK_FILE

$ FILE_IS = "SET_PRCNAM.MAR"
$ CHECKSUM_IS = 1081357908
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X                .title  SET_PRCNAM
X                .ident  /01.2/
V;****************************************************************************
X***
V;* Set_prcnam                                                            `032
X     *
V;*      This routine is intended to set the current process's name to the`032
X     *
V;* given string.  If it fails, it attempts to add a ":n", where "n" is a `032
X     *
V;* number from 0-99 inclusive.                                           `032
X     *
V;****************************************************************************
X***
X;
X                .psect  prc_data, noexe, pic, noshr
X;
Vprc_ctrl_str:   .ascid  /!AS:!UB/               ; Control string to set prcna
Xme
Xprocess_name:   .long   15
X                .address prc_str                ; New process name descriptor
Xprc_str:        .byte   32[15]
X;
X;
X;
X                .psect  prc_code, exe, pic, shr, nowrt
X;
X                .entry  set_prcnam, `094m<r10, r11>
X;
V                movl    4(ap), r10              ; Save the username descripto
Xr
X                pushl   r10                     ; Try to set process name to
X                calls   #1, g`094sys$setprn        ; - the new username
X                blbc    r0, try_again
X;
X                ret                             ; Leave, we set it
X;
Xtry_again:      clrl    r11                     ; Init our counter
Vloop:           movl    #15, process_name       ; Make sure we only have 15 c
Xh.
X;
X                pushl   r11
X                pushl   r10
X                pushal  process_name
X                pushal  process_name
X                pushal  prc_ctrl_str
V                calls   #5, g`094sys$fao           ; Format username with num
Xber
X;
X                pushal  process_name
X                calls   #1, g`094sys$setprn        ; Try to set process name
X                blbs    r0, leave
X;
X                aobleq  #99, r11, loop          ; Try only 100 times
X;
Vleave:          ret                             ; Leave whether or not it wor
Xked
X;
X                .end
$ GOSUB UNPACK_FILE

$ FILE_IS = "SET_USER.MAR"
$ CHECKSUM_IS = 1562030928
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X;
X;`009Please note.   This code has been converted from VMS V4 and
X;       will run on VMS Version 5.0, 5.0-1, 5.0-2 and 5.1.
X;
X;  * WARNING * WARNING * WARNING * WARNING * * WARNING * WARNING *
X;
X;
X;
X;       This routine uses the executive routine LMM$SEARCHLOG.  Under VMS V5
X;       LMN$SEARCHLOG is not a global routine.  In order to continue using
X;       this routine, we had to resort a major kluge.  DEC did make the
X;       routine LMN$SEARCH_ONE globally vectorized.  We find the address
X;       of LMN$SEARCH_ONE in the vector table and subtract the length
X;       of LNM$SEARCHLOG from it (LNM$SEARCHLOG is positioned right
X;       in front of LNM$SEARCH_ONE in the image LOGICAL_NAMES.EXE).
X;       this calculation gives us the address of LNM$SEARCH_LOG.
X;
X;       WARNING.  If DEC does ANYTHING to change the length of`032
X;       LNM$SEARCHLOG or relocates it relative to LNM$SEARCH_ONE, This
X;       program will BREAK.  Although a Kernal mode handler is established
X;       to attempt to prevent a crash, you can't guarentee anything when
X;       you blindly hop into system space in Kernal mode at IPL 2.
X;
X;       SO:  WARNING!   Before attempting to run this code on
X;       any version of VMS other than the ones I have listed above, VERIFY
X;       with SDA that the start of LNM$SEARCHLOG occurs exactly 93 Hex bytes
X;       in front of LNM$SEARCH_LOG. Having the MicroFiche helps.
X;
X;`009You could also check by checking to see if DEC relinked`032
X;       SYS$LOADABLE_IMAGES:LOGICAL_NAMES.EXE with ANALYZE/IMAGE.
X;
X;   Why all this trouble just to change the ownership of the JOB table??
X;
X;       We feel that a Change USERNAME program is not complete without
X;       being able to change the ownership of the JOB logical name table.
X;       This version uses LNM$SEARCH_LOG to find the address of the
X;       JOB logical name table to facilitate this change.
X;
X;       By changing the ownership of the table, you can then remove
X;       privileges (except for TMPMBX) and spawn giving a good
X;       approximation of of non-privileged context for testing
X;       questionable software.  If you don't change ownership
X;       of the JOB table, then SPAWN will be unable to place its
X;       logical name for the DCL context mailbox into the JOB table.
X;;
X;
X;       `032
X                .title  SET_USER
X                .ident  /01.2/
X;
X                .library        /SYS$LIBRARY:LIB.MLB/
X                .link           "SYS$SYSTEM:SYS.STB"/SELECTIVE_SEARCH
X;
X;
V                $pcbdef                         ; Process Control Block offse
Xts
V                $jibdef                         ; Job Information Block offse
Xts
V                $phddef                         ; Process Header Block offset
Xs
X                $lnmstrdef                      ; Logical name definitions
X                $orbdef                         ; Object rights block defs
X                $lnmdef                         ; Logical name defs
X                $ipldef                         ; Processor IPL defs
X                $psldef                         ; PSL bit defs
X                $uafdef                         ; User Auth Database offsets
X;
X;
X;
X                .psect  rms_data, noexe, pic, noshr
X;+
X; Data used in retrieving SYSUAF records through RMS
X;-
Xinfab:          $fab    fac = get -
X                        fnm = <sysuaf> -
X                        dnm = <sys$system:.dat> -
X                        shr = <put,get,del,upd>
X;
Xinrab:          $rab    fab = infab -
X                        kbf = usekey+8 -
X                        krf = 0 -
X                        ksz = 12 -
X                        rac = key -
X                        rop = nlk -
X                        ubf = inbuff -
X                        usz = 2048
X;
Xusekey:         .ascid  /            /
Xinpline:        .word   0
Xusrprmt:        .ascid  /Username: /
X;
Xdir_descr:      .long   32
X                .address defdir
Xdefdir:         .byte   32[32]
X;
Xdev_descr:      .long   16
X                .address defdev
Xdefdev:         .byte   32[16]
X;
Xdef_descr:      .long   48
X                .address def_buf
Xdef_buf:        .byte   32[48]
X;
X;
X;
X                .psect  fao_data, noexe, pic, noshr
X;+
X; Data used in formating messages to screen and operators console
X;-
Vterm_ctrl_str:  .ascid  "!/Username:  !AS!/Directory: !AS!/UIC:       !%U!/PI
XD:       !XL!/Account:   !AS!/"
Xterm_message:   .long   256
X                .address term_msg
Xterm_msg:       .byte   32[256]
Xterm_fao_arg:   .long   8
X                .address term_ctrl_str
X                .address term_message
X                .address term_message
X                .address user_descr
X                .address def_descr
Xterm_uic:       .long   0
Xterm_pid:       .long   0
X                .address acct_descr
X;
Voper_ctrl_str:  .ascid  /SETUSER: User !AS, (PID: !XL) became !AS, (UIC: !%U)
X/
Xoper_message:   .long   80
X                .address oper_msg
Xoper_msg:       .byte   32[80]
Xoper_fao_arg:   .long   7
X                .address oper_ctrl_str
X                .address oper_message
X                .address oper_message
X                .address old_user_descr
Xoper_pid:       .long   0
X                .address user_descr
Xoper_uic:       .long   0
X;
X;
X;
X                .psect  jpi_data, noexe, pic, noshr
X;+
X; Data returned from SYS$GETJPIW
X;-
Xuic:            .long   0                       ; Process's UIC
Xgroup:          .long   0                       ; Process's group number
Xmember:         .long   0                       ; Process's member number
Xpid:            .long   0                       ; Process's ID number
X;
Xacct_descr:     .long   8
X                .address account
Xaccount:        .blkb   8                       ; Descriptor for account
X;
Xold_user_descr: .long   12
X                .address old_user_name
Xold_user_name:  .blkb   12                      ; Descriptor for old username
X;
Xuser_descr:     .long   12
X                .address username
Xusername:       .blkb   12                      ; Descriptor for username
X;
Xterm_descr:     .long   7
X                .address terminal
Xterminal:       .blkb   7                       ; Descriptor for terminal
X;
Xretlength:      .long   0                       ; Dummy return length place
X;
Xold_username:   .word   12                      ; Length for the username
X                .word   JPI$_USERNAME           ; We want the username
X                .address old_user_name          ; Where to put the username
X                .address old_user_descr         ; How long our username is
X;
X                .long   0                       ; End of single request
X;
Xjpi_item:       .word   4                       ; Length for the processs ID
X                .word   JPI$_PID                ; We want the process ID
V                .address pid                    ; Where to store the process
X ID
X                .address retlength              ; Dummy return length
X;
X                .word   4                       ; Length for the process UIC
X                .word   JPI$_UIC                ; We want the process's UIC
X                .address uic                    ; Where to store the UIC
X                .address retlength              ; Dummy return length
X;
X                .word   12                      ; Length for the username
X                .word   JPI$_USERNAME           ; We want the username
X                .address username               ; Where to put the username
X                .address user_descr             ; How long our username is
X;
X                .word   8                       ; Length for the account
X                .word   JPI$_ACCOUNT            ; We want the account
X                .address account                ; Where to put the account
X                .address retlength              ; Dummy return length
X;
V                .word   7                       ; Length want for the termina
Xl
V                .word   JPI$_TERMINAL           ; Get the terminal of the pro
Xcess
X                .address terminal               ; Where to put the terminal
X                .address term_descr             ; Dummy return length
X;
V                .word   4                       ; Length for the member numbe
Xr
X                .word   JPI$_MEM                ; We want a member number
V                .address member                 ; Where to put the member num
Xber
X                .address retlength              ; Dummy return length
X;
X                .word   4                       ; Length for the group number
X                .word   JPI$_GRP                ; We want a the group number
V                .address group                  ; Where to put the group numb
Xer
X                .address retlength              ; Dummy return length
X;
X                .long   0                       ; End of JPI list
X;
X;
X;
X                .psect  krnl_data, noexe, pic, noshr
X;+
X; Data used in kernel mode
X;-
Xlock_dat_beg:   .long   0
Xlock_dat_end:   .long   0
Xlock_code_beg:  .long   0
Xlock_code_end:  .long   0
X;
Xnew_uic:        .long   0
Xinbuff:         .blkb   2048
X;
Xtable:          .ascid  /LNM$JOB/
Xlognam:         .ascid  /SYS$LOGIN/
Xmutex_flag:     .long   0
X;
Vend_dat:                                        ; End of data used in KRNL mo
Xde
X;
X;
X;
X                .psect  user_code, exe, pic, shr, nowrt
X;+
X; Main program entry point
X;-
X                .entry  set_user, `094m<>
X;
X                $getjpiw_s -
X                        itmlst = old_username   ; Get the old username
X;
X                blbs    r0, 10$
X;
X                pushl   r0
X                pushl   #0
X                pushl   #SETUSER_GETJPIERR
X                calls   #3, g`094lib$stop
X;
X10$:            pushaw  inpline
X                pushal  usrprmt
X                pushal  usekey
X                calls   #3, g`094lib$get_foreign   ; Get username
X                blbs    r0, 20$
X;
X                ret                             ; Exit on error
X;
X20$:            pushal  usekey
X                pushal  usekey
X                pushal  usekey
V                calls   #3, g`094str$trim          ; Trim the username read i
Xn
X;
X                tstw    usekey                  ; Test if anything is there
X                bneq    open_uaf
X;
X                movl    #1, r0                  ; Leave with no error
X                ret
X;
Xopen_uaf:       $open   fab = infab             ; Open SYSUAF
X                blbs    r0, connect_uaf
X;
X                pushl   r0
X                pushl   #0
X                pushl   #SETUSER_ERROPENUAF
X                calls   #3, g`094lib$stop
X;
Xconnect_uaf:    $connect rab = inrab            ; Establish a connection
X                blbs    r0, get_rec
X;
X                pushl   r0
X                pushl   #0
X                pushl   #SETUSER_ERROPENUAF
X                calls   #3, g`094lib$stop
X;
Xget_rec:        $get    rab = inrab             ; Read UAF record
X                cmpl    r0, #RMS$_RNF
-+-+-+-+-+ End of part 2 +-+-+-+-+-
-- 
Andrew W. Potter                         Email: awpsys@ritvax.BITNET
Systems Programmer                          awp8101%ritcv@cs.rit.edu
Information Systems and Computing
Rochester Institute of Technology, Rochester NY, 14623 (716) 475-6994

