1       %title "UAFHIT.BAS" 
 !This VAX BASIC example opens the System Authorization File (SYSUAF.DAT) and&
 !randomly accesses records by Username to get the last login date/time.     &
 !                                                                           &
 !CAUTION:  This sample program has been tested using BASIC V2.4 on          &
 !VAX/VMS V4.3.  However, we cannot guarantee its effectiveness because of   &
 !the possibility of error in transmitting or implementing it.  It is meant  &
 !to be used as a template for writing your own program, and it may require  &
 !modification for use on your system.                                       
        !
        on error goto 19000
        external long function sys$asctim

        ! Create the template for the UAF record.  Here we
        ! define only those fields that we wish to access.
        ! The field offsets are defined in the UAFDEF macro.
        !
10	!XF> LIB$GET_FOREIGN = Get foreign command line library function.
	!XF> SYS$PUTMSG      = Put message system service.
	!XF> SYS$SETPRV      = Set privilege system service.
	!XF> FORCE           = Force input to terminal.
	!
	EXTERNAL LONG FUNCTION	LIB$GET_FOREIGN, &
				SYS$PUTMSG, &
				SYS$SETPRV

	external long function sys$exit(long by value)

	!XC> SS$_BUFFEROVF   = Buffer overflow.
	!XC> SS$_NORMAL      = Normal successful completion return status.
	!XC> PRV$V_CMKRNL    = Change mode kernel privilege bit.
	!
	EXTERNAL LONG CONSTANT	SS$_BUFFEROVF, &
				SS$_NORMAL, &
				PRV$V_CMKRNL
	!The UAF record is defined here
	%include %from %cdd "cdd$top.cdd$record.uaf_record"
        map (sysuaf) uaf_rec uaf
        map (time_buffer) string tim_buf = 23%
 	!
	!> SYS_INPUT$ = Buffer for data from SYS$INPUT.
	!
 	!MAP 	    (SYS_INPUT) string user$ = 12%, qual$ = 15%
	!MAP 	    (SYS_INPUT) string user1$ = 12%, qual1$ = 15%
        !declare uaf_rec uaf
	declare long stat,                                              &
                string user_name

        ! Get the username and convert to uppercase.
        !
100	! Get any foreign command line.
	!
	STATUS% = LIB$GET_FOREIGN(FOREIGN$,, FOR_LEN%,)
	IF	STATUS% AND SS$_NORMAL
	THEN	IF	FOR_LEN%
		THEN	Z% = INSTR(1%, FOREIGN$ + " ", " ")
			USER$    = LEFT$(FOREIGN$, Z%-1%)
			FM.EP% = 2%
		END IF
	END IF
2000	! If we didn't get the username as a parameter on a foreign
	! command line then prompt for it.
	!
	IF	USER$ = NULL$
	THEN	input "VMS username ";user1$
		!
		! Extract username and qualifier data on same line.
		!
		Z% = INSTR(1%, user1$ + " ", " ")
		user$    = EDIT$(LEFT$(user1$, Z%-1%), 447%)
		IF  user$ = NULL$ then GOTO 2000  
	END IF


3000    ! Open the System Authorization File.  Note that the
        ! RECORDTYPE clause is required, and also that Basic
        ! allows you to open an existing indexed file without
        ! specifying a key clause.
        !
        open 'SYS$SYSTEM:SYSUAF.DAT' for input as file #2%,             &
                organization indexed variable,                          &
                access read,                                            &
                allow modify,                                           &
                recordtype none,                                        &
                recordsize 1412%,                                       &
                map sysuaf
        ! Read the file randomly by Username.
        !
        get #2%, key #0 eq user$

		if (uaf::l_flags and 512%) = 512%
		then
			sys_status = sys$exit(3%)
		end if           

        goto 32767

19000   print 'ERROR '; err, ert$(err)
        if err = 155
            then resume 100
            else resume 32767
        end if

32767   end                    
