From:	CSBVAX::CSBVAX::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX" 20-MAR-1989 15:20
To:	MRGATE::"ARISIA::EVERHART"
Subj:	fixed SETUSER 1 of 3


Received: From KL.SRI.COM by CRVAX.SRI.COM with TCP; Fri, 10 MAR 89 10:26:23 PDT
Received: from ucbvax.Berkeley.EDU by KL.SRI.COM with TCP; Fri, 10 Mar 89 09:51:07 PST
Received: by ucbvax.Berkeley.EDU (5.61/1.36)
	id AA13122; Fri, 10 Mar 89 09:46: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: 10 Mar 89 03:29:39 GMT
From: rochester!rit!ultb!awpsys@cu-arpa.cs.cornell.edu  (Andrew W. Potter)
Organization: Information Systems and Computing @ RIT, Rochester, New York
Subject: fixed SETUSER 1 of 3
Message-Id: <408@ultb.UUCP>
Sender: info-vax-request@kl.sri.com
To: info-vax@kl.sri.com


$! ................... Cut between dotted lines and save. ...................
$!...........................................................................
$! VAX/VMS archive file created by VMS_SHARE V06.10 7-FEB-1989.
$!
$! 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 AWPSYS
$! on  9-MAR-1989 22:18:54.57.
$!
$! 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 10 files:
$!        AAAREADME.TXT
$!        BUILD_SETUSER.COM
$!        MAKEFILE.MAK
$!        MESSAGES.MSG
$!        OLD.DIR
$!        OPRMSG.MAR
$!        SETUSER.CLD
$!        SET_LOGICAL.MAR
$!        SET_PRCNAM.MAR
$!        SET_USER.MAR
$!
$!============================================================================
$ 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.10 7-FEB-1989 requires VMS V4.4 or higher."
$ EXIT 44 ! SS$_ABORT
$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 ) ); LOOP EXITIF SEARCH( SPAN( ' ' )@r_trail 
& LINE_END, FORWARD) = 0; POSITION( r_trail ); ERASE( r_trail ); ENDLOOP
; 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 
); COPY_TEXT( ASCII( INT( ERASE_CHARACTER( 3 ) ) ) ); 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 = "AAAREADME.TXT"
$ CHECKSUM_IS = 108284734
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X        SETUSER a Ultilty to a priviliged user to become another user.
X
V*****************************************************************************
X**
X`009   NOTE: READ warning in SETUSER.MAR before using this software
V*****************************************************************************
X**
X
X
X                Author:         Andrew W. Potter
X                                Rochester Institute of Technology
X                                One Lomb Memorial Drive
X                                Rochester, New York 14632
X
X        DESCRIPTION:
X
X        This program allows a privileged user (CMKRNL, PSWAPM, privs plus
X        read access to sysuaf) to change his username. It also changes
X        the users Account name, UIC, Process name, and Default Directory
X        to that of the specified user.
X
X        It now changes the group logical name table and changes the
X        owner of the JOB table. (14-Oct-1986).
X
X`009NOTE: READ WARNING in SETUSER.MAR!!!!!!!
X
X        It is now written entirely in MACRO, and kernel mode stuff is
X        all done in one call. (12-JUL-1988)
X
X`009Modified to run under VMS V5.0, 5.0-1, 5.0-2 and 5.1 only!
X
X    `032
X
X        AAAREADME.TXT                   This file.
X        BUILD_SETUSER.COM               Build SETUSER from scratch.
X        MAKEFILE.MAK                    Makefile for use with MAKE.
X        MESSAGES.MSG                    Error message source.
X        MESSAGES.OBJ                    Error message object.
X        OPRMSG.MAR                      Operator message source.
X        OPRMSG.OBJ                      Operator message object.
X        SETUSER.EXE                     Executable image.
V        SET_LOGICAL.MAR                 Module that defines the logicals (sou
Xrce).
V        SET_LOGICAL.OBJ                 Module that defines the logicals (obj
Xect).
V        SET_PRCNAM.MAR                  Module that sets the process name (so
Xurce).
V        SET_PRCNAM.OBJ                  Module that sets the process name (ob
Xject).
V        SET_USER.MAR                    Module that contains the main code (s
Xource).
V        SET_USER.OBJ                    Module that contains the main code (o
Xbject).
X
X        INSTALLATION:
X
X        1) Build SETUSER.  Using BUILD_SETUSER.COM
X
X        2) Place SETUSER in some utility directory.
X
X
X           SETUSER is invoked as a foreign command
X
X                $ SETUSER == "$DISK:[DIRECTORY]SETUSER"
X
X
X        To use SETUSER:
X
X        $ SETUSER username
X
X        EX:
X
X           $ SETUSER system
X
X           Username:  SYSTEM
X           Directory: SYS$SYSROOT:[SYSMGR]
X           UIC:       [1,4]
X           PID:       0000002D
X           Account:   SYSTEM
X
X           The user is now SYSTEM.
$ GOSUB UNPACK_FILE

$ FILE_IS = "BUILD_SETUSER.COM"
$ CHECKSUM_IS = 487201372
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X$
X$! Creating SETUSER
X$
X$!
X$ write sys$output " "
X$ write sys$output -
X     "Have you read and understood the Warning found in SETUSER.MAR?"`032
X$ write sys$output " "
X$ inquire foo "Answer NO now if you are in over your head!"`032
X$ if foo.eqs."" THEN FOO = "NO"
X$ if .not.foo then write sys$Output " "
X$ if .not.foo then write sys$Output "Thats probably the smart choice"
X$ if .not.foo then write sys$Output "Have a nice day "
X$ if .not.foo then exit
X$
X$
X$ write sys$output " "
X$ write sys$output " "
X$ write sys$output "ASSEMBLING AND LINKING SETUSER"
X$!
X$ if "''p1'".nes."" then goto link
X$ macro/nodebug set_user, set_logical, set_prcnam, oprmsg
X$ message messages
X$link:
V$ link/exe=setuser/nodebug/notrace set_user, set_logical, set_prcnam, oprmsg,
X messages
$ GOSUB UNPACK_FILE

$ FILE_IS = "MAKEFILE.MAK"
$ CHECKSUM_IS = 671963993
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
V#****************************************************************************
X***
V#* Makefile for SETUSER                                                  `032
X     *
V#*                                                                       `032
X     *
V#* Created:  12-JUL-1988                                                 `032
X     *
V#****************************************************************************
X***
X
XMAR_QUAL = /nodebug
XLINK_QUAL = /exe\=setuser/nodebug/notrace
XMODULES = set_user \
X          set_logical \
X          set_prcnam \
X          oprmsg
X
Xsetuser.exe : $(MODULES).obj messages.obj
X        link $(LINK_QUAL) $(MODULES), messages
X
X$(MODULES).obj : $*.mar
X
Xmessages.obj : messages.msg
$ GOSUB UNPACK_FILE

$ FILE_IS = "MESSAGES.MSG"
$ CHECKSUM_IS = 640767282
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X.title          SETUSER messages
X
X.facility       SETUSER,1
X.severity       ERROR
XERROPENUAF      <Error opening SYSUAF>/fao=0
XERRCLOSUAF      <Error closing SYSUAF>/fao=0
XERRSEARCH       <Error searching for username !AS>/fao=1
XGETJPIERR       <Error in getting Job/Process Information>/fao=0
X.severity       WARNING
XCRELNMFAIL      <Failure to create logical name !AS, in !AS mode>/fao=2
X.end
$ GOSUB UNPACK_FILE

$ FILE_IS = "OLD.DIR"
$ CHECKSUM_IS = 0
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X
$ GOSUB UNPACK_FILE

$ FILE_IS = "OPRMSG.MAR"
$ CHECKSUM_IS = 1194747475
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X                .title  /Operator Message/
X;
X                $opcdef
X                $opcmsg
X;
X                .psect  opr_data, noexe, pic, noshr
X;
Vopmsg:          .byte   OPC$_RQ_RQST            ; We want to request to the o
Xperator
V                .byte   OPC$M_NM_CENTRL         ; Send it to the central oper
Xator
X                .word   0                       ; Just null space
X                .long   0                       ; Just null space
Vtext:           .blkb   80                      ; Place to put the message st
Xring
VOPMSGLEN = . - opmsg                            ; Length of the operator mess
Xage
X;
Vmsgdsc:         .long   OPMSGLEN                ; Length of string to pass to
X sys$sndopr
X                .long   opmsg                   ; Where the string is
X;
X;
X;
V;****************************************************************************
X***
V;* Oprmsg                                                                `032
X     *
V;*      This procedure takes a string of up to 72 characters and sends it to
X   *
V;* the operators console.                                                `032
X     *
V;****************************************************************************
X***
X;
X                .psect  opr_code, exe, pic, shr, nowrt
X;
X                .entry  oprmsg, `094m<>
X;
X                movl    4(ap), r0               ; Save string to send
X;
V                movc5   (r0), @4(r0), #32, #80, text ; Move the user string i
Xn
X                $sndopr_s msgdsc                ; Send request
X;
X                ret                             ; End of oprmsg
X;
X                .end
$ GOSUB UNPACK_FILE

$ FILE_IS = "SETUSER.CLD"
$ CHECKSUM_IS = 1518096718
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
Xdefine verb setuser
X        image mer$exe:setuser
X        parameter p1, label=USERNAME, prompt="Username"
$ GOSUB UNPACK_FILE

$ FILE_IS = "SET_LOGICAL.MAR"
$ CHECKSUM_IS = 359222454
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X                .title  SET_LOGICAL
X                .ident  /01.2/
V;****************************************************************************
X***
V;* Set_logical                                                           `032
X     *
V;*      This routine is intended to set all the necessary logical names for
X    *
V;* correct user context switch.                                          `032
X     *
V;****************************************************************************
X***
X;
X                .library /SYS$LIBRARY:LIB.MLB/
X;
X                $psldef
X                $lnmdef
X;
X                .psect  lnm_data, noexe, pic, noshr, wrt
X;+
X; Data for logical name redefinition
X;-
Xproc_direc:     .ascid  /LNM$PROCESS_DIRECTORY/
Xgroup_log:      .ascid  /LNM$GROUP/
Xjob_table:      .ascid  /LNM$JOB/
Xproc_table:     .ascid  /LNM$PROCESS_TABLE/
Xsys_disk:       .ascid  /SYS$DISK/
Xsys_scratch:    .ascid  /SYS$SCRATCH/
Xsys_login:      .ascid  /SYS$LOGIN/
Xsys_login_dev:  .ascid  /SYS$LOGIN_DEVICE/
Xkrnl_mode:      .byte   PSL$C_KERNEL
Xkrnl_mode_str:  .ascid  /KERNEL/
Xexec_mode:      .byte   PSL$C_EXEC
Xexec_mode_str:  .ascid  /EXECUTIVE/
Xsupr_mode:      .byte   PSL$C_SUPER
Xsupr_mode_str:  .ascid  /SUPERVISOR/
Xuser_mode:      .byte   PSL$C_USER
Xuser_mode_str:  .ascid  /USER/
Xlnm_item:
Xlnm_buf_len:    .word   16
X                .word   LNM$_STRING
Xlnm_buf_adr:    .address group_table
X                .address retlength
X                .long   0                       ; End of item list
Xlnm_ctrl_str:   .ascid  /LNM$GROUP_!6OL/
Xgrp_tab_des:    .long   16
X                .address group_table
Xgroup_table:    .byte   32[16]
Xretlength:      .long   0                       ; Dummy return length
X;
X;
X;
X                .psect  lnm_code, exe, pic, shr, nowrt
X;
X                .entry  set_logical, `094m<r9, r10, r11>
X;
X                movl    4(ap), r11              ; Save the device string
V                movl    8(ap), r10              ; Save the default directory
X str
X                movl    12(ap), r9              ; Save the group
X;
X                pushl   r9
X                pushab  grp_tab_des
X                pushab  lnm_buf_len
X                pushab  lnm_ctrl_str
V                calls   #4, g`094sys$fao           ; Format the group table n
Xame
X;
X                $crelnm_s -
X                        tabnam = proc_direc, -
X                        lognam = group_log, -
X                        acmode = krnl_mode, -
V                        itmlst = lnm_item       ; Redefine group table in KRN
XL
X                blbs    r0, 10$
X;
X                pushl   r0
X                pushal  krnl_mode_str
X                pushal  group_log
X                pushl   #2
X                pushl   #SETUSER_CRELNMFAIL
X                calls   #5, g`094lib$signal
X;
V10$:            movw    (r10), lnm_buf_len      ; Move home dir into item lis
Xt
V                movl    4(r10), lnm_buf_adr     ; - for the following logical
Xs
X                $crelnm_s -
X                        tabnam = job_table, -
X                        lognam = sys_login, -
X                        acmode = exec_mode, -
X                        itmlst = lnm_item       ; Define SYS$LOGIN in EXEC
X                blbs    r0, 20$
X;
X                pushl   r0
X                pushal  exec_mode_str
X                pushal  sys_login
X                pushl   #2
X                pushl   #SETUSER_CRELNMFAIL
X                calls   #5, g`094lib$signal
X;
X20$:            $crelnm_s -
X                        tabnam = job_table, -
X                        lognam = sys_scratch, -
-+-+-+-+-+ End of part 1 +-+-+-+-+-
-- 
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

