************************************************************************
*M*      LOGRT    PERFORMS LOGON FUNCTIONS FOR BATCH USERS
***********************************************************************
*P*
*P*      NAME:    LOGRT
*P*
*P*      PURPOSE: TO VERIFY A USER'S AUTHORIZATION, SET UP USER RESOURCE,
*P*               PERIPHERAL AND SERVICE LIMITS IN JIT, STORE INFORMATION
*P*               FROM THE LOGON RECORD INTO THE JIT , AND TO GENERATE AN
*P*               ASSIGN-MERGE RECORD.
*P*
*P*      DESCRIPTION: LOGRT IS CALLED BY JOBR. THE :USERS FILE IS OPENED
*P*               AND A KEYED RECORD IS READ. THE KEY FOR THE RECORD IS
*P*               FORMED FROM THE USER'S ACCOUNT AND NAME. THE PRESENCE
*P*               OR ABSENCE OF THE KEYED RECORD D ETERMINES USER
*P*               AUTHORIZATION. WHEN :SYS,LBE IS SPECIFIED FOR NAME AND
*P*               ACCOUNT, A :USER FILE IS CREATED IF ONE DOES NOT
*P*               ALREADY EXIST. IF THE KEYED RECORD EXISTS, VALUES ARE
*P*               EXTRACTED FROM THE RECORD AND ENTERED INTO THE JIT.
*P*               RESOURCE LIMITS SPECIFIED ON A LIMIT CARD, WHICH ARE
*P*               PRE-SCANNED AND PASSED TO LOGRT BY RBBAT, ARE
*P*               CHECKED AGAINST AUTHORIZED LIMITS IN THE :USERS FILE
*P*               AND THE JOB ABORTED IF THEY EXCEED THOSE LIMITS.
*P*               OTHERWISE, THE VALUES ARE STORED IN THE JIT (JB:MAX).
*P*               PREIPHERAL DEVICE LIMITS ARE AUTHORIZED BY SETTING
*P*               BITS IN THE JIT(JH:LDCF) THAT CORRESPOND TO
*P*               PERIPHERALS SPECIFIED IN THE :USERS FILE.
*P*               SERVICE LIMIT VALUES SPECIFIED IN THE :USERS FILE
*P*               ARE TRANSFERRED TO THE JIT. ASSIGN-MERGE HEADER
*P*               INFORMATION (SUCH AS POINTERS,START DATE AND TIME,USER
*P*               NAME,SYSTEM ID,EXTENDED ACCOUNTING INFORMATION,
*P*               RATE STRUCTURE,PERMANENT RAD AND DISK SPACE) IS
*P*               PREPARED AND THE ASSIGN-MERGE RECORD WRITTEN.
*P*
*P*      REFERENCE: BATCH PROCESSING REFERENCE MANUAL
*P*
         SYSTEM  SIG7
         SYSTEM   BPM
*
* THIS SUBROUTINE WILL OPEN THE LOGIN FILE AND KEY-READ A RECORD;  THEN
* IT WILL STORE INFORMATION FROM THE LOGON RECORD INTO JIT. IF THE
* ROUTINE IS ABLE TO DO THIS OPERATION SUCCESSFULLY A ZERO WILL BE
* PLACED INTO SR3. IF THE OPERATION IS UNSUCCESSFUL THE CONTENTS OF SR3
* WILL BE NON-ZERO. THIS SUBROUTINE WILL ALSO CREATE A LOGIN FILE FOR
* THE MANAGEMENT ACCOUNT IF A FILE DOES NOT ALREADY EXIST.
*
DEBUG    EQU      0
         DEF      ASMGBUF           BUFFER FOR ASSIGN/MERGE READS/WRITES
         DEF      LOGRT             ENTRY POINT TO LOGRT
         DEF      CLOSLOG           FPT USED FOR CLOSING :USERS FILE
         DEF      LOGSZ             EQU; BYTE SIZE OF LOGON RECORD
         DEF      OPLOG             FPT FOR OPENING :USERS FILE
         DEF      CONCAT            STORE NAME AND ACCOUNT INTO KEYBUFF
*,*                                 TO CREATE KEY
         DEF      KEYBUFF           BUFFER CONTAINING KEY FOR READING
*,*                                 :USERS RECORD
         DEF      RECORD            BUFFER :USERS RECORD IS READ INTO
         REF      JACCN             INPUT-EQU; ACCOUNT NAME USED TO
*,*                                 GENERATE KEYED RECORD
         REF,1    JB:PRIV           OUTPUT-PRIVILEGE FROM :USERS RECORD
*,*                                 OUTPUT-BIT 2; SET IF SECURITY
*,*                                 SPECIFIED IN :USERS RECORD
         REF      J:XP              OUTPUT-LEFT HALF; STORE DEFAULT
*,*                                 RETENTION PERIOD FROM :USERS RECORD
*,*                                 OUTPUT-RIGHT HALF; STORE MAXIMUM
*,*                                 RETENTION PERIOD FROM :USERS RECORD
         REF      AM:HED            EQU; ASSIGN MERGE HEAD(INDEX TO
*,*                                 AVAILABLE AREA)
         REF      AM:ORG            OUTPUT-EQU; POINTER TO AVAIL. SPACE
         REF      AM:DATE           OUTPUT-EQU; CREATION YEAR AND DAY
         REF      AM:LOG            OUTPUT-EQU; LOGON TIME IN MINUTES
*,*                                 FROM MIDNIGHT
         REF      AMH:BILL          OUTPUT-EQU; BILLING RATE
         REF      AM:XACC           OUTPUT-EQU; EXTENDED ACCOUNTING INFO.
         REF      AM:PRMAX          OUTPUT-EQU;
         REF      AM:PRCUR          OUTPUT-EQU;
         REF      AM:LNK            OUTPUT-EQU; ZERO OUT LINK TO FIRST
*,*                                 ENTRY
         REF      :LOGSZ            EQU; LOGON RECORD SIZE
         REF      J:JIT             INPUT/OUTPUT USER INFORMATION
         REF      PRDCRM            INPUT-MAXIMUM AMOUNT OF PERMANENT
*,*                                 RAD SPACE AVAILABLE
*,*                                 OUTPUT-SAVE PERMANENT RAD SPACE
*,*                                 REMAINING
         REF      PRDPRM            INPUT-GET MAXIMUM AMOUNT OF PERMANENT
*,*                                 PACK SPACE AVAILABLE
*,*                                 OUTPUT-SAVE PERMANENT PACK SPACE
*,*                                 REMAINING
         REF      TMDCRM            OUTPUT-SAVE TEMPORARY RAD SPACE
*,*                                 REMAINING
         REF      TMDPRM            OUTPUT-SAVE TEMPORARY PACK SPACE
*,*                                 REMAINING
         REF      TMPDCPK           OUTPUT-SAVE PEAK TEMPORARY RAD SPACE
         REF      TMPDPPK           OUTPUT-STORE PEAK TEMPORARY PACK SPACE
         REF      JUNAME            INPUT-USED TO FORM KEYED :USERS
*,*                                 RECORD AND ASSIGN/MERGE RECORD
         REF      M:EO              DCB USED TO READ/WRITE :USERS RECORD
         REF      DATEON            INPUT-START DATE(YY,DD) STORED IN
*,*                                 ASSIGN/MERGE RECORD
         REF      UPASSW            INPUT-DETERMINE PASSWORD VALIDITY
         REF,1    JB:ORG            INPUT-DETERMINE JOB ORIGIN FOR
*,*                                 PASSWORD VERIFICATION
         REF      LGNTM             INPUT-LOGON TIME STORED IN ASSIGN-
*,*                                 MERGE RECORD
         REF      EXTACC            INPUT-EXTENDED ACCOUNTING
*,*                                 INFORMATION STORED IN ASSIGN-MERGE
*,*                                 RECORD
         REF      LMXCDCD           EQU; ERROR CODE CONSTANT
         REF      ACCNER            EQU; ERROR CODE CONSTANT
         REF      J:ASSIGN          OUTPUT-BIT 3; SET READ=NONE IF
*,*                                 READ NOT SPECIFIED IN :USERS RECORD
         REF      SV:FTYM           INPUT-LOGICAL DEVICE LIMIT TABLE
*,*                                 SIZE
         REF      SH:SYMT           INPUT-PERIPHERAL DEVICE NAME TABLE
*,*                                 USED IN OBTAINING LOGICAL DEVICE IN
*,*                                 TABLE
         REF,2    JH:LDCF           OUTPUT-LOGICAL DEVICE FLAGS SET FOR
*,*                                 DEVICES SPECIFIED IN :USERS RECORD
         REF      SV:RSIZ           EQU; RESOURCE NAME TABLE SIZE
         REF      SH:RNM            INPUT; TABLE USED TO DETERMINE VALUE
*,*                                 OF RESOURCE SPECIFIED IN JB:MAX
         REF      JB:MAX            INPUT; TABLE CONTAINING RESOURCE VALUES
*,*                                 SPECIFIED ON LIMIT CONTROL COMMAND
*,*                                 OR SYSTEM SYSTEM DEFAULT LIMITS
         REF      Y8                MASK
         REF      JB:CUR            INPUT; SYSTEM MAXIMUM VALUES FOR
*,*                                 RESOURCES
         REF      TSTACK            INPUT/OUTPUT-PRESERVE REGISTERS
         REF      SV:LIM            EQU; SERVICE LIMIT NAME TABLE SIZE
         REF      SL:NAME           INPUT-STORE SERVICE LIMIT VALUES FROM
*,*                                 :USERS RECORD IF RESOURCE EXISTS IN
*,*                                 TABLE
         REF      J:TITLE           INPUT/OUTPUT-USED TO RETAIN SYSTEM
*,*                                 MAXIMUM VALUES FOR SERVICE LIMITS
         REF      YFFFE             MASK
         REF      Y002              MASK
         REF      Y03               MASK
         REF      XFFFF             MASK
         REF      MRT               OUTPUT-RETAIN MAXIMUM RUN TIME
*,*                                 (DEFAULT OR :USER SPECIFIED)
         REF      MPPO              OUTPUT-RETAIN MAXIMUM LO (DEFAULT OR
*,*                                 :USER SPECIFIED)
         REF      MPO               OUTPUT-RETAIN MAXIMUM PO (DEFAULT OR
*,*                                 :USER SPECIFIED)
         REF      MDPO              OUTPUT-RETAIN MAXIMUM DO (DEFAULT OR
*,*                                 :USER SPECIFIED)
         REF      MUPO              OUTPUT-RETAIN MAXIMUM UO (DEFAULT OR
*,*                                 :USER SPECIFIED)
         REF,1    JB:NFPOOL         OUTPUT-RETAIN MAXIMUM FPOOLS (DEFAULT
*,*                                 OR :USER SPECIFIED)
         REF      BLANK             INPUT-DETERMINE IF EXTENDED
*,*                                 ACCOUNTING ON JOB COMMAND
         REF      WAMR              WRITE THE ASSIGN-MERGE RECORD
         REF      NRESERR           ERROR CODE CONSTANT
         REF      PASSERCD          ERROR CODE CONSTANT
*                                   (ONLY THE HEAD,I.E.22 WDS)
LOGSZ    EQU      :LOGSZ+:LOGSZ+:LOGSZ+:LOGSZ
M:XX     EQU      M:EO
LR:FG    EQU      5                 READ ALL AND FLAG FIELDS
LR:PW    EQU      6                 PASSWORD
LR:BIL   EQU      15                BILLING
LR:PRIV  EQU      16                PRIVILEGE
LR:ACRAD EQU      18                ACCU PERM RAD SPACE
LR:DMR   EQU      20                DEF AND MAX FILE RETENTION PERIODS
LR:ACDIS EQU      22                ACCU PERM DISK SPACE
LR:EACCT EQU      24                EXTENDED ACCOUNTING INFORMATION
LR:UNMR  EQU      94
LR:UBMR  EQU      102
LR:UPFLGS EQU     122
LR:UNMP  EQU      114
LR:UNML  EQU      30
LR:UBML  EQU      46
***********************************************************************
R0       EQU      0
R1       EQU      1
R2       EQU      2
R3       EQU      3
R4       EQU      4
R5       EQU      5
R6       EQU      6
R7       EQU      7
SR1      EQU      8
SR2      EQU      9
SR3      EQU      10
SR4      EQU      11
D1       EQU      12
D2       EQU      13
D3       EQU      14
D4       EQU      15
***********************************************************************
X7F      DATA     X'7F'
TXTPSTO  TEXT     'PSTO'
TXTPDIS  TEXT     'PDIS'
*
RECORD   EQU      %
         TEXT     ':SYS    LBE         '   LOGON NEEDS THIS
         DO1      11
         DATA     0
         DATA,1   X'C0',X'C0',0,0  AND THIS
*                                   WHEN CCI WRITES FIRST REC'D OF FILE.
         DO1      109
         DATA     0
KEYBUFF  DO1      6
         DATA     0
*ASSIGN MERGE TABLE
ASMGBUF  DO1      8                 FIRST 8  WORDS IN A-M TABLE
         DATA     0
         DATA     0                 DATE(YY,DD) AT JOB START
         DO1      3                 USERS NAME,3 WDS
         DATA     X'40404040'
         DATA     0                 LOGON TIME
         DATA     0                 BILLING
         DO1      6                 EXTENDED ACCNT. INFO.FIELD
         DATA     X'40404040'
         DATA     0                 PERM RMNG RAD SPACE ALLCTED
         DATA     0                 PERM RMNG DISK SPACE ALCTD
*
***********************************************************************
*
* PLIST FOR OPENING THE LOGON FILE
*
         CSECT    1
OPLOG    GEN,8,7,17 X'14',0,M:XX
         DO       DEBUG
         DATA     X'CF480019'
         ELSE
         GEN,8,8,8,8  X'CF',X'48',X'02',X'19' FOR UTS
         FIN
         GEN,1,31 1,R6              ERROR RETURN
         GEN,1,31 1,R7              ABNORMAL RETURN
         GEN,32   10                MAXIMUM RECOVERY TRIES
         GEN,32   2                 KEYED FILE
         GEN,32   2                 DIRRECT ACCESS
         GEN,1,14,17 1,0,R1         WHEN R1=1,MODE=IN;R1=8,MODE=OUTIN
         GEN,32   2                 SAVE
         GEN,32   21                MAXIMUM KEY LENGHT
         GEN,8,8,8,8 1,0,2,2        FILE NAME
          TEXTC     ':USERS'
         GEN,8,8,8,8    2,0,2,2
SECAT    EQU      %
         DO       DEBUG
         TEXT     'CPVCHK'
         ELSE
         TEXT     ':SYS'
         TEXT      '    '
         FIN
         DO       DEBUG
         DATA     0
         DATA     0
         DATA     0
         ELSE
         GEN,8,8,8,8 3,0,2,2        PASSWORD
         DATA     X'DFEF803F',X'AFC0BF9F'
         FIN
         GEN,8,8,8,8 5,1,1,1        READ ACCOUNT NUMBER
         TEXT     'NONE'
*
*
* PLIST FOR READING THE LOGON FILE
*
KEYREAD  GEN,8,24 X'10',M:XX
         DATA     X'F8000010'
         DATA     NOACCESS          PHYSICAL IO ERROR RETURN
         DATA     OPNABRT           ABNORMAL RETURN
         DATA     RECORD            BUFFER ADDRESS
         DATA     LOGSZ             BUFFER SIZE NOW EXPANDED
         DATA     KEYBUFF           KEY ADDRESS
*
* PLIST FOR WRITING A RECORD
*
WRITLOG  GEN,8,24 X'11',M:XX
         DATA     X'B8000020'
         GEN,15,17 0,NOACCESS       PHYSICAL IO ERROR RETURN
         GEN,15,17  0,RECORD        BUFFER ADDRESS
         DATA     LOGSZ             BUFFER SIZE NOW EXPANDED
         DATA     KEYBUFF           KEY ADDRESS
*
* PLIST FOR CLOSING THE LOGIN FILE
*
CLOSLOG  GEN,8,7,17 X'15',0,M:XX
         GEN,1,31 1,0
         GEN,32   2                 ALWAYS SAVE THE FILE
*
*
*        PUSH OF PULL N WORDS SPECIFIED BY 1ST ARGUMENT
*        INTO REG'S STARTING AT 2ND ARGUMENT
PUSH     CNAME    X'9',X'B'
PULL     CNAME    X'8',X'A'
         PROC
         DO       NUM(AF)=1
LF       GEN,1,7,4,3,17 0,NAME(1),AF(1),0,TSTACK
         ELSE
         DO       AF(1)=1
LF       GEN,1,7,4,3,17 0,NAME(1),AF(2),0,TSTACK
         ELSE
         DO       AF(1)=16
LF       LCI      0
         ELSE
LF       LCI      AF(1)
         FIN
         GEN,1,7,4,3,17 0,NAME(2),AF(2),0,TSTACK
         FIN
         FIN
         PEND
***PLIST FOR RELEASING RESOURCES
L500     GEN,1,7,8,16 1,X'15',0,R6  RELEASED QUANTITY IN SR1
         PAGE
***********************************************************************
***********************************************************************
*
LOGRT    EQU      %
         LI,R4    0                 CLEAR COUNTER FOR KEY
         LI,R3    KEYBUFF           LOAD ADDRESS OF KEY BUFFER
         LI,R7    8                 LOAD LENGHT LIMIT FOR ACCOUNT
         LI,R2    J:JIT+JACCN       LOAD ADDRESS OF ACCOUNT
         BAL,SR1  CONCAT            GO PUT ACCOUNT INTO THE KEY
         AI,R4     1                 INSERT SPACE CHR
         LI,R6     X'40'             .BETWEEN ACCOUNT
         STB,R6    *R3,R4            ..AND NAME FIELDS.
         LI,R7    12                LOAD LENGHT LIMIT FOR NAME
         LI,R2    J:JIT+JUNAME      **FOR TESTING ONLY**
         BAL,SR1  CONCAT            GO PUT NAME INTO THE KEY
         STB,R4   *R3               PUT KEY LENGHT INTO KEY
         LCI      2
         LM,D3    SECAT             GET SECRET  ACCOUNT
         XW,D3    J:JIT+JACCN       EXCHANGE SECRET ACCT. WITH JIT ACCT.
         XW,D4    J:JIT+JACCN+1     EXCHANGE SECRET ACCT. WITH JIT ACCT.
         LI,R1    1                 SET MODE TO IN
         LI,R6    NOACCESS          LOAD ERROR RETURN ADDR.
         LI,R7    OPNABRT           LOAD ABN. RETURN ADDR.
OPN      LI,SR3   0
         CAL1,1   OPLOG
         CAL1,1   KEYREAD           KEY READ THE LOGIN FILE
         CAL1,1   CLOSLOG           CLOSE THE LOGIN FILE
*PERFORM VALIDITY TEST ON PASSWORD
         MTW,0    LR:PW+RECORD      WAS A PASSWORD SPEC'D IN :USERS
         BEZ      L003              NO
         LI,R2    JB:ORG            WAS ORIGIN ON-LINE BATCH
         LB,R2    0,R2
         CI,R2    1                 DON'T PERFORM PASSWORD CHECK AS USER
         BE       L003              HAD TO KNOW PASSWORD TO LOG ON
         LCI      2                 GET USER'S PASSWORD
         LM,R2    LR:PW+RECORD
         CD,R2    UPASSW            DOES PASSWORD MATCH
         BNE      INVPASS           NO, ABORT USER
L003     EQU      %
         LCI      2
         STM,D3   J:JIT+JACCN       PUT ORIGINAL ACCT. BACK INTO JIT
*PROCESS EXTENDED ACCOUNTING
         LW,R1    EXTACC            USE EXT. ACTG. FROM !JOB IF SPEC.
         CW,R1    BLANK
         BNE      L007
         LI,R1    -6                NOT SPECIFIED
L005     EQU      %
         LW,R2    RECORD+LR:EACCT+6,R1 HENCE, USE EXT. ACCTG. FROM :USERS REC.
         BEZ      L007
         STW,R2   EXTACC+6,R1
         BIR,R1   L005
L007     EQU      %
*PROCESS SERVICE LIMITS
         LI,R2    15                PRESET SCAN COUNTER.
L010     EQU      %
         LW,R3    RECORD+LR:UNML,R2 DOES CURRENT ENTRY CONTAIN
         BNEZ     L030              .AUTHORIZED SERVICE NAME.-YES.
L020     EQU      %
         BDR,R2   L010              -NO. IS SCAN FINISHED.-NO
         B        L100              -YES. END.
L030     EQU      %
         BAL,SR1  SLSRCH            WAS USER LIMIT NAME FOUND IN SL:NAME
         BNE      L020              NO, GET NEXT
         LW,R4    RECORD+LR:UBML,R2 USE USERS SERVICE LIMIT
         STW,R4   J:TITLE,R1
         LI,R7    J:JIT
         LW,R3    LIMINFO,R1        GET STORAGE INFO.
         LB,R6    R3                SHIFT VALUE AND RESOLUTION
         SCS,R4   0,R6              VALUE TO PROPER FIELD IN JIT
         SLS,R6   -6                RESOLUTION
         LI,R5    -1                LOAD PROPER MASK
         CI,R1    LIMINFOA
         BGE      %+2
         LW,R5    YFFFE
         EXU      LIMSTORE,R6       STORE IT
         BDR,R2   L010              GET NEXT
* SET PROPER MAX. IN J:TITLE FOR PSTORE AND PDISK WHEN NOT SPEC'D
* IN USERS FILE. MAX. USED BY LIMR.
L100     EQU      %
         LI,R2    15                CALC. MAX FOR PSTORE
         LW,R3    TXTPSTO
L102     EQU      %
         CW,R3    RECORD+LR:UNML,R2  WAS PSTORE FOUND IN USERS
         BE       L103              YES, DONT SET MAX
         BDR,R2   L102
         BAL,SR1  SLSRCH            SEARCH SL:NAME TABLE FOR PSTORE
         BNE      L103
         LW,R2    J:TITLE,R1        GET SYS. MAX
         SW,R2    RECORD+LR:ACRAD
         BGEZ     %+2
         LI,R2    0
         STW,R2   J:TITLE,R1        SET MAX=SYS MAX-ACCU.
L103     EQU      %
         LI,R2    15                CALC. MAX FOR PDISK
         LW,R3    TXTPDIS
L104     EQU      %
         CW,R3    RECORD+LR:UNML,R2  WAS PDISK FOUND IN USERS
         BE       L105              YES, DONT SET MAX
         BDR,R2   L104
         BAL,SR1  SLSRCH            SEARCH SL:NAME TABLE FOR PDISK
         BNE      L105
         LW,R2    J:TITLE,R1        GET SYS. MAX
         SW,R2    RECORD+LR:ACDIS
         BGEZ     %+2
         LI,R2    0
         STW,R2   J:TITLE,R1        SET MAX=SYS MAX-ACCU.
*PROCESS RESOURCE LIMITS
L105     EQU      %
         LI,R1    SV:RSIZ           SET COUNT TO CYCLE THRU
*                                   .RESOURCE NAME TABLE.
L110     EQU      %
         LH,R6    SH:RNM,R1         IS CURRENT
         BNEZ     L200              .ENTRY ZERO. -NO.
L120     EQU      %
         BDR,R1   L110              -YES. END OF TABLE. -NO.
         STB,R1   JB:MAX            BYTE 0 RESET MEANS RES. PROC. O.K.
**PRIVILEGE                         -YES.
         LI,R3    BA(RECORD+LR:PRIV) GET ADDR OF PRIV. LEVEL.
         LB,R2    0,R3              GET PRIV LEVEL FROM LOGON RECORD
         CI,R2    0                 DOES THE BYTE HAVE SOMETHING IN IT
         BEZ      %+3               NO
         LI,R3    JB:PRIV
         STB,R2   0,R3              STORE PRIVELEGE INTO JIT
**FILE READ ('ALL' OPTION)
         LW,R2    RECORD+LR:FG      GET THE DESIRED WORD
         CW,R2    =X'80000000'
         BAZ      %+3               OPTION BIT NOT SET(I.E. READ ALL)
         LW,R3    =X'10000000'
         STS,R3   J:ASSIGN          SET BIT 3 IN J:ASSIGN(READ NONE)
** EXEC. ONLY(XOS),RESTR. PROCESSOR(RP),SECURITY(SE)
         LI,R3    2                 IF SE BIT SET
         AND,R3   R2
         BEZ      L125
         LI,R4    JB:PRIV           SET BIT 2 IN JB:PRIV
         LB,R7    0,R4
         OR,R7    R3
         STB,R7   0,R4
L125     EQU      %
         SLS,R2   22                SET XOS AND RP BITS IN JIT
         LW,R3    Y03
         STS,R2   J:ASSIGN
** PERM RAD SPACE RMNG=PERM RAD SPACE LIMIT-ACCU PERM RAD SPACE
         LW,R2    J:JIT+PRDCRM      GET LIMIT FROM JIT
         SW,R2    RECORD+LR:ACRAD   GET ACCU. RAD SPACE FROM :USERS
         BGEZ     PERM5
         LI,R2    0                 MINUS ACCU. SET=0
PERM5    EQU      %
         STW,R2   J:JIT+PRDCRM      RMNG SPACE TO JIT
** PERM PACK SPACE RMNG=PERM PACK LIMIT-ACCU. PERM PACK SPACE
         LW,R2    J:JIT+PRDPRM      GET LIMIT FROM JIT
         SW,R2    RECORD+LR:ACDIS   GET ACCU. PACK SPACE FROM :USERS
         BGEZ     PERM10
         LI,R2    0                 MINUS ACCU. SET=0
PERM10   EQU      %
         STW,R2   J:JIT+PRDPRM      RMNG SPACE TO JIT
*PROCESS LOGICAL LIMITS
         LI,R7    0                 AUTHORIZE DEVICES FOR BATCH
         LI,R4    RECORD+LR:UNMP    ADDR OF :UNMP TABLE.
         LI,R5    RECORD+LR:UPFLGS  ADDR OF :UPFLGS.
         PUSH     SR4
         BAL,SR4  SETLDCF           SET BITS IN JH:LDCF FOR
*                                   .PERIPHERALS SPEC'D IN :USERS
         PULL     SR4
**FILE RETENTION PERIODS
**** NONE--0(DEFAULT), NEVER--FFFF
RETENT   EQU      %
         LH,R2    RECORD+LR:DMR     GET DEF. RETN PERIOD
         BEZ      %+2               IF ZERO,USE DEFAULT IN JIT
         STH,R2   J:XP              STORE DEF. RETN. INTO JIT
         LI,R3    1                 HW INDEX
         LH,R2    RECORD+LR:DMR,R3  GET MAX RETN PERIOD
         BEZ      %+2               USE DEFAULT
         STH,R2   J:XP,R3           STORE MAX RETN INTO JIT
*NOW THAT ALL NEC. INFO. IN LOG REC PROCESSED,
*PREPARE AND WRITE THE ASSIGN-MERGE RECORD
*
BAM      EQU      %
         LI,R7    ASMGBUF
         LI,R2    AM:HED            STORE POINTER TO AVAILABLE SPACE
         STW,R2   AM:ORG,R7
*
         LW,R2    DATEON            STORE DATE FROM JOBR
         STW,R2   AM:DATE,R7
*
         LW,R2    LGNTM             STORE LOGON TIME FROM JOBR
         STW,R2   AM:LOG,R7
*
         LI,R3    BA(RECORD+LR:BIL) GET RATE STRUCTURE FROM LOGON REC.
         LB,R2    0,R3
         BEZ      W3                EMPTY
         LI,R3    HA(AMH:BILL)      STORE INTO LEFT HALFWORD
         STH,R2   *R7,R3
*
W3       EQU      %
         LCI      6                 STORE EXT. ACCT. FROM JOBR
         LM,R0    EXTACC
         STM,R0   AM:XACC,R7
*
         LW,R2    J:JIT+PRDCRM      PERM RAD SPACE REMAINING
         STW,R2   AM:ORG+20,R7
*
         LW,R2    J:JIT+PRDPRM      OERM DISK SPACE REMAINING
         STW,R2   AM:ORG+21,R7
*
         LI,R2    0
         STW,R2   AM:PRMAX,R7
         STW,R2   AM:PRCUR,R7
         STW,R2   AM:LNK,R7         LINK EXPECTED=0 BY COMMAND FILE EXEC.
*
         PUSH     3,SR2
         LW,R3    Y002              CLOSE :USERS FILE IF OPEN
         CW,R3    M:XX
         BAZ      W4
         CAL1,1   CLOSLOG
W4       EQU      %
         LI,SR2   ASMGBUF           BUFFER ADDRESS
         BAL,SR4  WAMR              WRITE A/M RECORD
         STW,SR3  R3                SAVE A/M WRITE CODE TEMP.
         PULL     3,SR2
         CI,SR3   0                 ANY ERRORS PRIOR TO A/M WRITE
         BNE      W5                YES
         LW,SR2   R3                NO, HONOR A/M WRITE ERROR IF ANY
         LW,SR3   R3
W5       EQU      %
*
*NOW CLOSE THE LOGON FILE
*
*  AND PROVIDE ADDRESS OF COPY OF LOGON RECORD
*   FOR THE INSTALLATION ACCOUNTING ROUTINE
*
         LI,R3    RECORD
*
         B        *SR4              EXIT LOGRT
*
INVPASS  EQU      %
*E*      MESSAGE: INVALID PASSWORD
         LI,SR2   PASSERCD          ERROR CODE FOR PASSWORD
         B        NOACC3
*
NOACCESS EQU      %                 USER NOT ABLE TO ACCESS USERS FILE
*E*      MESSAGE: INVALID NAME OR ACCOUNT
         LI,SR2   ACCNER            ERROR CODE FOR NAME/ACCOUNT
NOACC3   EQU      %
         LCI      2
         STM,D3   J:JIT+JACCN       RESTORE USER'S ACCT. TO JIT
         LI,R2    SV:RSIZ           RESET SYSTEM DEFAULT RESOURCE BIT
NOACC5   EQU      %                 SO THAT RESOURCE VALUES ARE
         LB,SR3   JB:MAX,R2         CORRECT ON THE ACCOUNTING SUMMARY
         AND,SR3  X7F               PRINTOUT AT LOGOFF TIME.
         STB,SR3  JB:MAX,R2
         BDR,R2   NOACC5
         LI,SR3   1                 PUT A ONE INTO SR3
         B        BAM               *BUILD AM BEFORE ABORT
*
OPNABRT  SLS,SR3  -17               AN ABNORMAL CONDITION OCCURRED
         CI,SR3   X'A01'            WAS THE FILE BEING UPDATED
         BNE      OPNABRT5          NO
         M:WAIT   1                 YES, WAIT 1.2 SEC.
         B        OPN               TRY TO OPEN IT AGAIN
OPNABRT5 EQU      %
         SLS,SR3  -7                NO; SHIFT OFF END BYTE
         CI,SR3   3                 DOES THE FILE EXIST
         BNE      NOACCESS          YES,THERE WAS SOME OTHER ABNOMAL
         CW,D3    L(C':SYS')
         BNE      NOACCESS          NOT MANAGER,SO NO ACCESS
         CW,D4    =X'40404040'      TEST 2ND WORD IN ACCOUNT
         BNE      NOACCESS          IT IS NOT SO NO ACCESS
         LW,R2    J:JIT+JUNAME
         CW,R2    L(C'LBE ')        SEE IF IT'S MANAGER'S NAME
         BNE      NOACCESS          IT ISN'T SO NO ACCESS
* USER IS :SYS,LBE, AND 1ST TIME AROUND
* CREATE A LOGON RECORD FOR HIM
*
         LI,R1    8                 OPEN IN OUTIN MODE
         LI,R6    NOACCESS          LOAD ERROR RETURN ADDR.
         LI,R7    OPNABRT           LOAD ABN. RETURN ADDR.
         CAL1,1   OPLOG
         CAL1,1   WRITLOG           WRITE FIRST RECORD
         CAL1,1   CLOSLOG           CLOSE THE LOGIN FILE
         LCI      2
         STM,D3   J:JIT+JACCN       RESTORE USER'S ACCT TO JIT
         LI,SR3   0
         B        LOGRT             WAS *SR2;SO THAT NO MORE FIRST
*                                   TIME PROBLEM
*
*
CONCAT   EQU      %                 THIS ROUTINE CREATES A KEY
         LI,R5    0                 LOAD POINTER TO FIELD
DOIT     LB,R6    *R2,R5            GET A CHARACTER FROM FIELD
         AI,R5    1                 INCREMENT POINTER
         CI,R6    X'40'
         BE       *SR1              YES; GO BACK TO MAIN ROUTINE
         AI,R4    1                 INCREMENT BYTE COUNT FOR KEY
         STB,R6   *R3,R4            STORE THE CHARACTER INTO THE KEY
         CW,R5    R7                HAS THE END OF FIELD BEEN REACHED
         BE       *SR1              YES; GO BACK TO THE MAIN ROUTINE
         B        DOIT              NO;
*
* EXIT HERE AND CLOSE LOGON FILE IF USER VIOLATED
*  AUTHORIZATION RECORD
*   ERROR CODE ALREADY SET UP IN SR2
*
VIOLATE  EQU      %
         LI,SR3   -1                ERROR, SET GEN-ACCTG. FLAG
         B        BAM               BUILD A-M BEFORE ABORT
L200     EQU      %
         LI,R2    15                :UNML SIZE.
L210     EQU      %
*                                   COMPARE RESOURCE NAME
*                                   .TABLE ITEM AGAINST
         CH,R6    RECORD+LR:UNMR,R2 ..RESOURCE LIMIT
         BE       L212              ...NAME. -EQ.
         BDR,R2   L210              END RNM TABLE. -NO/
         B        L330              -YES.
L212     EQU      %
         AND,R6   XFFFF
         LB,SR1   JB:MAX,R1         -EQ. IS MAX A SYSTEM
         CB,SR1   Y8                .DEFAULT OR USER SPEC'D.
         BAZ      L370              -USER SPEC'D.
         AND,SR1  X7F               -SYSTEM DEFAULT.
         LB,R7    RECORD+LR:UBMR,R2 IS SYSTEM DEFAULT GRTR.
         CI,R6    X'C3D6'           IF RESOURCE IS CORE
         BNE      L215
         SLS,R7   -1
L215     EQU      %
         CW,SR1   R7                ..THAN USERS
         BLE      L340              ...REQUIREMENT. -NO.
         STW,SR1  R3
         SW,SR1   R7                -YES. RELEASE RESOURCES
         CI,R6    X'C3D6'           IS RESOURCE CORE
         BNE      L220
         SLS,SR1  1                 MUST CONVERT TO PAGES
         SLS,R3   1                 BEFORE RELEASING CORE
L220     EQU      %
         STB,R3   JB:MAX,R1         STORE RESOURCE
         LI,R7    0                 MUST ZERO CUR BEFORE RELEASING CORE
         STB,R7   JB:CUR,R1
         CAL1,8   L500              .NOT NEEDED BY USER.
         B        L120
L300     EQU      %
         LI,R7    0                 ZERO OUT CURRENT
         STB,R7   JB:CUR,R1         .RESOURCE COUNT.
         LH,R7    SH:RNM,R1         IS THIS
         AND,R7   XFFFF             SYSTEM
         CI,R7    X'C3D6'           RESOURCE
         BNE      L120              ..CORE. -NO.
         LB,R6    JB:MAX,R1         -YES. CHANGE
         SLS,R6   1                 .TO PAGES
         STB,R6   JB:MAX,R1         NO. SO STORE.
         B        L120
* COME HERE IF NO RESOURCE SPECIFIED IN :USERS RECORD.
L330     EQU      %                 -YES.
         LB,SR1   JB:MAX,R1         IS MAXIMUM A SYSTEM
         CB,SR1   Y8                .DEFAULT OR USER SPEC'D.
         BAZ      L350              .USER SPEC'D.
         AND,SR1  X7F               SET FLAG TO INDICATE
L340     EQU      %
         STB,SR1  JB:MAX,R1         .USER SPECIFIED.
         B        L300
L350     EQU      %
         CB,SR1   JB:CUR,R1         IS USER SPEC'D MAX
         BLE      L300              .GRTR THAN SYSTEM MAX.
L360     EQU      %
         STW,R6   NRESERR           SAVE NAME OF RESOURCE FOR ERROR
*                                   FLAGGING WHEN SCANNING LIMIT CC.
         LI,R7    0                 CLEAR
L365     EQU      %
         STB,R7   JB:CUR,R1         REMAINING ENTRIES.
         LB,SR2   JB:MAX,R1         RESET DEFAULT BITS.
         AND,SR2  X7F
         LH,R6    SH:RNM,R1         GET RESOURCE NAME
         AND,R6   XFFFF
         CI,R6    X'C3D6'           IF RESOURCE IS CORE
         BNE      %+2
         SLS,SR2  1                 CONVERT TO PAGES
         STB,SR2  JB:MAX,R1
         BDR,R1   L365
         STB,R1   JB:MAX            SET CORE-CONVERTED-PAGES FLAG (=0)
*E*      MESSAGE: SPECIFIED LIMIT EXCEEDS MAXIMUM
*E*      DESCRIPTION: A RESOURCE LIMIT SPECIFIED ON THE LIMIT CARD
*E*               EXCEEDS THE MAXIMUM SPECIFIED IN THE :USERS FILE.
         LI,SR2   LMXCDCD           LIMIT VALUE ERROR.
         B        VIOLATE           ABORT AFTER A/M WRITE
L370     EQU      %
         CI,R6    X'C3D6'           IF RESOURCE IS CORE
         BNE      L375
         SLS,SR1  1                 CONVERT TO PAGES
L375     EQU      %
         CB,SR1   RECORD+LR:UBMR,R2 COMPARE USER SPEC'D LIMIT
         BLE      L300              WITH AUTHORIZED LIMIT
         B        L360
         PAGE
* THE SETLDCF ROUTINE AUTHORIZES ACCESS TO LOGICAL DEVICE PERIPHERALS
* BY SETTING PERTINENT BITS IN JIT (JH:LDCF) FOR THOSE PERIPHERALS
* SPECIFIED IN THE :USERS FILE.
*        ENTER    BAL,SR4  SETLDCF
*        INPUT    R7=0 - AUTHORIZE DEVICES FOR BATCH.
*                 R7=1 - AUTHORIZE DEVICES FOR ON-LINE.
*                 R7=2 - AUTHORIZE DEVICES FOR GHOST.
*                 R4= - ADDRESS OF :UNMP TABLE IN :USERS FILE.
*                 R5= - ADDRESS OF :UPFLGS TABLE IN :USERS FILE.
*                 REG.USED R1,R2,R3,R6
*
SETLDCF  RES      0
         LI,R1    SV:FTYM           GET LOGICAL DEVICE LIMIT TABLE SIZE
         STB,R7   SR4               SAVE FLAG TEMPORARILY
SETLDCF2 LH,R2    SH:SYMT,R1        GET PERIPHERAL DEVICE NAME
         LI,R3    15
SETLDCF4 CH,R2    *R4,R3            WAS DEVICE NAME IN :USERS FILE
         BE       SETLDCF6          YES, SET FLAG
         BDR,R3   SETLDCF4
         B        SETLDCF8          NO, GET NEXT DEVICE NAME
*
SETLDCF6 LB,R6    *R5,R3            GET PERIPHERAL FLAF FROM :USERS
         AI,R7    8
         SLS,R6   0,R7              SHIFT SPEC. FLAG(BATCH,O/L,GHOST) TO
*                                   BIT 16
         LCW,R3   R1                SHIFT MASK FOR PERIPHERAL FLAG
         LI,R7    X'8000'
         SLS,R7   0,R3
         SLS,R6   0,R3              SHIFT PERIPHERAL FLAG
*
         LI,R2    JH:LDCF           GET LOGICAL DEVICE CONTROL FLAGS
         LH,R3    0,R2
         STS,R6   R3
         STH,R3   0,R2
         LB,R7    SR4               RESTORE FLAG
SETLDCF8 BDR,R1   SETLDCF2          GET NEXT DEVICE NAME
         B        *SR4
         PAGE
* THE SLSRCH ROUTINE SEARCHES THE SL:NAME TABLE FOR A SPECIFIED
* SERVICE LIMIT.
*        ENTER    BAL,SR1  SLSRCH
*        INPUT    R3 - SERVICE LIMIT NAME TO SEARCH FOR
*        OUTPUT   R1 - INDEX OF SERVICE LIMIT NAME
*        REGS. USED R1
SLSRCH   EQU      %
         LI,R1    SV:LIM            PRESET SCAN COUNTER
SLSRCH5  EQU      %
         CW,R3    SL:NAME,R1        DOES USER LIMIT NAME MATCH
         BE       *SR1              YES, RETURN
         BDR,R1   SLSRCH5           NO, GET NEXT
         B        *SR1
         PAGE
*DRIVE TABLES FOR LIMIT DEFAULT STORING.
*THE POSITION OF ENTRY WITHIN THE TABLE IS KEYED DIR. TO TABLE SL:NAME.
LIM      COM,2,6,24 CF(2),AF(1),AF(2)
LIMSTORE EQU      %
         STS,R4   *R7,R3
         STB,R4   *R7,R3
         STH,R4   *R7,R3
         BAL,SR1  0,R3
LIMINFO  RES      1
         LIM,SPEC 0,TIMST           TIME
         LIM,WORD 17,MPPO           LO
         LIM,WORD 17,MPO            PO
         LIM,WORD 17,MDPO           DO
         LIM,WORD 17,MUPO           UO
LIMINFOA EQU      %-LIMINFO
         LIM,SPEC 0,PSTST           PSTORE
         LIM,SPEC 0,TSTST           TSTORE
         LIM,BYTE 0,JB:NFPOOL-BA(J:JIT) FPOOL
         LIM,SPEC 0,TSTDI           TDISK
         LIM,SPEC 0,PDIST           PDISK
WORD     EQU      0
BYTE     EQU      1
SPEC     EQU      3
PSTST    EQU      %
         STW,R4   PRDCRM,R7         PERM RAD SPACE
         SW,R4    RECORD+LR:ACRAD   CALC. PROPER MAX(USERS-ACCU=MAX)
         BGEZ     %+2
         LI,R4    0
         STW,R4   J:TITLE,R1        STORE IN J:TITLE FOR USE BY LIMR
         B        *SR1
TSTST    EQU      %
         STW,R4   TMDCRM,R7         TEMP DISC SPACE
         STW,R4   TMPDCPK,R7        PEAK TEMP RAD SPACE USED
         B        *SR1
TSTDI    EQU      %
         STW,R4   TMDPRM,R7
         STW,R4   TMPDPPK,R7        PEAK TEMP PACK SPACE USED
         B        *SR1
PDIST    EQU      %
         STW,R4   PRDPRM,R7         PERM DISK SPACE
         SW,R4    RECORD+LR:ACDIS   CALC. PROPER MAX(USERS-ACCU=MAX)
         BGEZ     %+2
         LI,R4    0
         STW,R4   J:TITLE,R1        STORE IN J:TITLE FOR USE BY LIMR
         B        *SR1
* J:MRT = SYSTEM DEFAULT OR LIMIT VALUE(USER SPEC'D)
TIMST    EQU      %
         LW,R5    R4
         MI,R5    30000
         CW,R5    MRT,R7            IS :USERS<LIMIT OR SYS. DEFAULT
         BG       TIMST5
         STW,R5   MRT,R7            YES, STORE AS MAX. RUN TIME
TIMST5   EQU      %
         B        *SR1
        END

