	PROGRAM		NETJOB
!****************************************************************************
!*                                                                          *
!*  COPYRIGHT (c) 1982, 1987                                                *
!*  By Westinghouse Electric Corporation                                    *
!*                                                                          *
!*  THIS SOFTWARE IS FURNISHED WITHOUT LICENSE AND MAY BE USED AND COPIED   *
!*  ONLY WITH THE INCLUSION OF THE ABOVE COPYRIGHT NOTICE.                  *
!*                                                                          *
!*  THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE    *
!*  AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY WESTINGHOUSE.            *
!*                                                                          *
!*  WESTINGHOUSE ASSUMES NO RESPONSIBILITY FOR THE USE OR  RELIABILITY      *
!*  OF THIS SOFTWARE.                                                       *
!*                                                                          *
!****************************************************************************
C
C       LINK/NOTRAC NETJOB,SETUSER,SETACC,SYS$SYSTEM:SYS.STB/SELECTIVE
C
C       NOTE :  CMKRNL & SYSPRV privileges are required to run NETJOB
C
C       NOTE :  The fourth argument is a flag indicating whether the account
C               number was validated on the remote system or it was specified
C               as an option on the REMPRINT command line.
C                  0 -- already validated for user just validate account
C                  1 -- validate both the user and the account.  (user must
C                       have at least an entry into the accounting file.)

	IMPLICIT INTEGER (A-Z)

        INCLUDE         '($JPIDEF)'
	INCLUDE		'($LNMDEF)'
	INCLUDE		'($SSDEF)'
	PARAMETER	PCB$V_NETWRK = '15'X

	INTEGER		itmlst(4), iosb(2), ln_opt
	INTEGER         sts,l,lchar,larg,type,ln_un,ln_a,ln_ob,ln_obn
	CHARACTER	username*12, account*15, object*23, objname*255
        CHARACTER       temp*3, option*1
        LOGICAL         valid, validate_account

	itmlst(1) = ISHFT(JPI$_STS,16) + 4
	itmlst(2) = %LOC(sts)
	itmlst(3) = 0
	itmlst(4) = 0
	STATUS = SYS$GETJPIW(,,,itmlst,iosb,,)
	IF (.NOT. STATUS) CALL LIB$SIGNAL(%VAL(STATUS))
        IF (.NOT. BTEST(sts,PRC$V_NETWRK)) GOTO 999

	lchar = 0	
	CALL cliargs(lchar,username,type,ln_un)
        CALL cliargs(lchar,account,type,ln_a)
	CALL cliargs(lchar,object,type,ln_ob)
	IF (ln_ob .le. 0) GO TO 999
        temp = object(ln_ob - 2 : ln_ob)
	CALL cliargs(lchar,option,type,ln_opt)
        valid = .false.
        IF (ln_opt .eq. 1) THEN
          IF (option .eq. '0') THEN
            valid = validate_account(account,username,0)
          ELSE
            valid = validate_account(account,username,1)
          END IF
        ELSE
          valid = validate_account(account,username,0)
        END IF
        IF (.NOT. valid) GOTO 998
C
C  SYS$NET should contain the name of the DECnet object invoked.
C  The third argument on the command line should be that object name.
C
	itmlst(1) = ISHFT(LNM$_STRING,16) + 255
	itmlst(2) = %LOC(objname)
	itmlst(3) = %LOC(ln_obn)
	STATUS = SYS$TRNLNM(,'LNM$PROCESS_TABLE','SYS$NET',,ITMLST)
	IF ((.NOT. STATUS) .OR. (ln_obn .LE. 0)) GO TO 999
c	IF (INDEX(OBJNAME(1:ln_obn),OBJECT(1:ln_ob)) .EQ. 0) GOTO 999
	IF (INDEX(OBJNAME(1:ln_obn),temp) .EQ. 0) GOTO 999

        STATUS = setuser (username)
	IF (STATUS .EQ. SS$_NOPRIV) CALL EXIT(SS$_NOPRIV)

	CALL str$upcase (account, account)
	account(8:8) = '!'
	STATUS = setacc (%ref(account))
	IF (STATUS .EQ. SS$_NOPRIV) CALL EXIT(SS$_NOPRIV)
	CALL EXIT

  998	TYPE *,'%REMPRINT-F-NETJOB A valid account is needed for REMPRINT'
        !  the two error messages are needed to convey the error to the
        !      DCL command procedure
	CALL EXIT(SS$_NOPRIV)

  999	TYPE *,'%NETJOB-F-USEERR Intended for use only with REMPRINT'
	CALL EXIT(SS$_NOPRIV)
	END
