/* REXX */
/* CLS2REXXed by FSOX001 on 22 May 2017 at 11:09:30  */
Signal On NoValue
Call On Error
Signal On Failure
Signal On Syntax
Parse source opsys . exec_name .
Address ISREDIT
 
"MACRO"               /* CARM0004 EDIT TEMP4(*)  */
/*********************************************************************/
/* 05/05/2004 JL.NELSON CHANGED TO COLLECT NEW RACF FINDINGS         */
/* 06/15/2004 JL.NELSON ADDED EXIT CODE                              */
/* 11/11/2004 JL.NELSON Added profiles to group entries              */
/* 12/17/2004 JL.NELSON Changed to expand groups once per access     */
/*            level.                                                 */
/* 01/19/2005 JL.NELSON Changed to select users before SORT.         */
/* 01/28/2005 JL.NELSON Changed undefined UZIDs for reporting        */
/*            access.                                                */
/* 02/07/2005 JL.NELSON Correct GROUP(SUF) should be USER not        */
/*            SUFFIX.                                                */
/* 02/23/2005 JL.NELSON Changed constants to variables before        */
/*            rename.                                                */
/* 03/09/2005 JL.NELSON Changed LMMREP to LMMADD/LMMREP to avoid     */
/*            errors.                                                */
/* 04/21/2005 JL.NELSON Added TYPERUN to expand GROUPS for FSO       */
/*            audit.                                                 */
/* 06/09/2005 JL.NELSON Pass MAXCC in ZISPFRC variable.              */
/* 06/10/2005 JL.NELSON Fixed 804 error when &UZID = *.              */
/* 07/11/2005 JL.NELSON Expand groups/access only once per auditors. */
/* 07/18/2005 JL.NELSON Made LISTGRP a variable.                     */
/* 08/25/2005 JL.NELSON Added code to remove & in Name field.        */
/* 03/07/2006 JL.NELSON Made changes to avoid abend 920/932.         */
/* 09/10/2007 CL.Fenton Added record type process.  Chgd several     */
/*            variables used by process.                             */
/* 05/23/2017 CL.FENTON Converted script from CLIST to REXX.         */
/*            Also removed GROUPID user list processing (CARM0005),  */
/*            STS-017060.                                            */
/*                                                                   */
/*                                                                   */
/*********************************************************************/
pgmname = "CARM0004 05/23/17"
sysprompt = "OFF"                /* CONTROL NOPROMPT          */
sysflush = "OFF"                /* CONTROL NOFLUSH           */
sysasis = "ON"                 /* CONTROL ASIS - caps off   */
Address ISPEXEC "CONTROL NONDISPL ENTER"
Address ISPEXEC "CONTROL ERRORS RETURN"
 
/*******************************************/
/* VARIABLES ARE PASSED TO THIS MACRO      */
/*******************************************/
maxcc = 0
return_code = 0
Address ISPEXEC "VGET (CONSLIST COMLIST SYMLIST TERMMSGS",
  "CARM0005 TEMP5 RACFRPT TYPERUN LISTGRP ) ASIS"
rm04vget = return_code
If return_code <> 0 then do
  Say pgmname "VGET RC =" return_code  zerrsm
  Say pgmname "CONSLIST/"conslist "COMLIST/"comlist,
    "SYMLIST/"symlist "TERMMSGS/"termmsgs
  Say pgmname "CARM0005/"carm0005 "TEMP5/"temp5 "RACFRPT/"racfrpt,
    "TYPERUN/"typerun "LISTGRP/"listgrp
  return_code = return_code + 16
  SIGNAL ERR_EXIT
  end
 
If CONSLIST = "ON" | COMLIST = "ON" | SYMLIST = "ON" ,
  then Trace ?r
 
return_code = 0
 
/*******************************************/
/* TURN ON MESSAGES                        */
/*******************************************/
syssymlist = symlist          /* CONTROL SYMLIST/NOSYMLIST */
sysconlist = conslist         /* CONTROL CONLIST/NOCONLIST */
syslist = comlist          /* CONTROL LIST/NOLIST       */
sysmsg = termmsgs         /* CONTROL MSG/NOMSG         */
"(MEMBER) = MEMBER"
"NULLS OFF"
"CAPS OFF"
omember = member
blank = " "
ind1 = "  "
ind2 = "    "
sep30 = "- - - - - - - - - - - - - - -"
lp = "("
rp = ")"
spc = "          "
sp80 = spc""spc""spc""spc""spc""spc""spc""spc
uzid_list = "#"
"(ENDER) = LINENUM .ZLAST"
If ender < 1 then,
  SIGNAL  END_EDIT
sysouttrap = 3
 
 
CHK_UZID:
do row = 1 to ender
  return_code = 0
  "CURSOR =" row 0
 
  "FIND 'GROUPID'"
  If return_code <> 0 then leave
  "(ROW,COL) = CURSOR"
  "(DATA) = LINE" row
  uzid = substr(data,54,8)
  If pos(uzid"#",uzid_list) <> 0 then iterate
  uzid_list = uzid_list""uzid"#"
  name = "NAME=Unknown"
  x = outtrap("line.",3)
  return_code = 0
  cmd = "LISTUSER" uzid
  Address TSO cmd
  listu_rc = return_code
  If return_code = 0 then do
    do x = 1 to 3
      If "U" = left(line.x,1) then,
        parse var line.x . "NAME=" name " OWNER=" .
      end
    name = left("NAME="name,42)
    "X ALL"
    "FIND ALL '"uzid"' 54"
    cf = "'8GROUPID'"
    ct = "'7 USERID'"
    "CHANGE" cf ct "ALL NX 45"
    cf = "'                                          '"
    ct = "'"name"'"
    "CHANGE" cf ct "ALL NX 83"
    "RESET"
    iterate
    end
  return_code = 0
  cmd = "LISTGRP" uzid
  Address TSO cmd
  listg_rc = return_code
  If return_code <> 0 then do
    name = left("NAME=Not found U="listu_rc" G="listg_rc,42)
    "X ALL"
    "FIND ALL '"uzid"' 54"
    cf = "'8GROUPID'"
    ct = "'5NOT_DEF'"
    "CHANGE" cf ct "ALL NX 45"
    cf = "'                                          '"
    ct = "'"name"'"
    "CHANGE" cf ct "ALL NX 83"
    "RESET"
    end
  end
 
 
SORT:
return_code = 0
"SORT 1 62"
If return_code > 4 then do
  Say pgmname "SORT_RC =" return_code  member  zerrsm
  return_code = 0
  SIGNAL  ERR_EXIT
  end
/*******************************************/
/* MAIN LOOP                               */
/*******************************************/
prevpro1 = ""
prevpro2 = ""
prevuid = ""
group_list = "#"
 
 
LOOP_PROFILE:
do curline = 1 to ender /* goto end_edit */
  return_code = 0
  "(DATA) = LINE" curline
  racfpro = left(data,44)
  rectype = substr(data,45,1)
 
 
SELECT_RECTYPE:
  Select
    When rectype = 1 then do
      If prevpro1 <> racfpro & prevpro1 <> " " then do
        ac = sep30" "sep30" "sep30" "sep30
        Address ISPEXEC "LMPUT DATAID("temp5") MODE(INVAR)",
          "DATALOC(AC) DATALEN("length(ac)") MEMBER("omember")"
        end
      If prevpro1 <> racfpro then do
        prevpro1 = racfpro
        prevuid = ""
        univ = substr(data,46)
        ac = left(racfpro,53)univ
        Address ISPEXEC "LMPUT DATAID("temp5") MODE(INVAR)",
          "DATALOC(AC) DATALEN("length(ac)") MEMBER("omember")"
        end
      end
    When rectype = 4 then do
      dsn = substr(data,55)
      If left(data,4) <> "    " then do
        ac = ind1""dsn
        Address ISPEXEC "LMPUT DATAID("temp5") MODE(INVAR)",
          "DATALOC(AC) DATALEN("length(ac)") MEMBER("omember")"
        end
      Else do
        ac = left(racfpro,53)dsn
        Address ISPEXEC "LMPUT DATAID("temp5") MODE(INVAR)",
          "DATALOC(AC) DATALEN("length(ac)") MEMBER("omember")"
        end
      end
    When rectype = 5 | rectype = 6 | rectype = 7 then do
      uzid = substr(data,54,8)
      If prevuid <> uzid then do
        prevuid = uzid
        grpusr = substr(data,46,17)
        grpacc = substr(data,65,16)
        name = substr(data,83,26)
        ac = ind2""grpusr"                   "
        ac = left(ind2""grpusr,22)grpacc
        Select
          When rectype = 5 then do
            ac = left(ac,39)"USER=NOT_DEF*"
            ac = left(ac,53)name
            ac = left(ac,79)racfpro
            end
          When rectype = 6 then do
            ac = left(ac,79)racfpro
            end
          When rectype = 7 then do
            ac = left(ac,39)"USER="uzid
            ac = left(ac,53)name
            ac = left(ac,79)racfpro
            end
          Otherwise nop
          end
        Address ISPEXEC "LMPUT DATAID("temp5") MODE(INVAR)",
          "DATALOC(AC) DATALEN("length(ac)") MEMBER("omember")"
        end
      end
    Otherwise nop
    end
  If rectype <> 8 then iterate
  uzid = substr(data,54,8)
  If prevuid = uzid then iterate
  If uzid = " " then iterate
  prevuid = uzid
  grpusr = substr(data,46,17)
  grpacc = substr(data,65,16)
  acc1 = strip(substr(data,72,8))
  group = "G"
  name = "NAME="
NEXT_PROCESS:
  return_code = 0
  ac = left(ind2""grpusr,22)grpacc
  Address ISPEXEC "LMPUT DATAID("temp5") MODE(INVAR) DATALOC(AC)",
    "DATALEN("length(ac)") MEMBER("omember")"
  If acc1 = "NONE" then iterate
  If acc1 = "EXECUTE" then iterate
  If pos("#"uzid""acc1,group_list) <> 0 then iterate
  group_list = group_list""uzid""acc1"#"
  Address ISPEXEC "VPUT (OMEMBER UZID GRPUSR GRPACC RACFPRO) ASIS"
  return_code = 0
  /*Address ISPEXEC "EDIT DATAID("racfrpt") MACRO("carm0005")",
    "MEMBER("listgrp")"
  If return_code > 4 then do
    Say pgmname "EDIT RACFRPT" listgrp "RC =" return_code zerrsm
    end*/
  end
 
 
END_EDIT:
return_code = 0
Address ISPEXEC "LMMADD DATAID("temp5") MEMBER("omember")"
If return_code = 4 then do
  return_code = 0
  Address ISPEXEC "LMMREP DATAID("temp5") MEMBER("omember")"
  If return_code <> 0 then,
    Say pgmname "LMMREP_TEMP5_RCODE =" return_code omember zerrsm
  end
Else do
  If return_code <> 0 then,
    Say pgmname "LMMADD_TEMP5_RCODE =" return_code omember zerrsm
  end
return_code = 0
/*******************************************/
/* SAVE OUTPUT                             */
/*******************************************/
ERR_EXIT:
If /*!*/maxcc >= 16 | return_code > 8 then do
  Address ISPEXEC "VGET (ZISPFRC) SHARED"
  If /*!*/maxcc > zispfrc then,
    zispfrc = /*!*/maxcc
  Else
    zispfrc = return_code
  Address ISPEXEC "VPUT (ZISPFRC) SHARED"
  Say pgmname "ZISPFRC =" zispfrc
  end
rm004rc = return_code
Address ISPEXEC "VPUT (RM04VGET RM004RC) ASIS"
"END"
Exit 0
 
 
NoValue:
Failure:
Syntax:
say pgmname 'REXX error' rc 'in line' sigl':' strip(ERRORTEXT(rc))
say SOURCELINE(sigl)
SIGNAL ERR_EXIT
 
 
Error:
return_code = RC
if RC >= 16 then do
  say pgmname "LASTCC =" RC strip(zerrlm)
  say pgmname 'REXX error' rc 'in line' sigl':' strip(ERRORTEXT(rc))
  say SOURCELINE(sigl)
  end
if return_code > maxcc then
  maxcc = return_code
return
 
 
