     **
     **  Program . . : SEC104
     **  Description : Copy User Auditing - CPP
     **  Author  . . : Carsten Flensburg
     **
     **
     **  Program description:
     **    Command processing program for the Copy User Auditing (CPYUSRAUD)
     **    command.
     **
     **
     **  Compile options:
     **    CrtRpgMod Module( SEC104 )
     **              DbgView( *LIST )
     **
     **    CrtPgm    Pgm( SEC104 )
     **              Module( SEC104 )
     **              ActGrp( *NEW )
     **
     **
     **-- Control specification:  --------------------------------------------**
     H Option( *SrcStmt )

     **-- System information:
     D PgmSts         SDs                  Qualified
     D  PgmNam           *Proc
     D  CurJob                       10a   Overlay( PgmSts: 244 )
     D  UsrPrf                       10a   Overlay( PgmSts: 254 )
     D  JobNbr                        6a   Overlay( PgmSts: 264 )
     D  CurUsr                       10a   Overlay( PgmSts: 358 )
     **-- API error information:
     D ERRC0100        Ds                  Qualified
     D  BytPro                       10i 0 Inz( %Size( ERRC0100 ))
     D  BytAvl                       10i 0
     D  MsgId                         7a
     D                                1a
     D  MsgDta                      512a

     **-- User information:
     D USRI0300        Ds                  Qualified
     D  BytRtn                       10i 0
     D  BytAvl                       10i 0
     D  UsrPrf                       10a
     D  ObjAudVal                    10a   Overlay( USRI0300: 501 )
     D  UsrAudVal                          Overlay( USRI0300: 511 )
     D                                     LikeDs( AudLvl )
     **
     D AudLvl          Ds                  Qualified
     D  Cmd                           1a
     D  Create                        1a
     D  Delete                        1a
     D  JobDta                        1a
     D  ObjMgt                        1a
     D  OfcSrv                        1a
     D  PgmAdp                        1a
     D  SavRst                        1a
     D  Security                      1a
     D  Service                       1a
     D  SplfDta                       1a
     D  SysMgt                        1a
     D  Optical                       1a
     D  AutFail                       1a
     D  JobBas                        1a
     D  JobChgUsr                     1a
     D  NetBas                        1a
     D  NetClu                        1a
     D  NetCmn                        1a
     D  NetFail                       1a
     D  NetSck                        1a
     D  PgmFail                       1a
     D  PrtDta                        1a
     D  SecCfg                        1a
     D  SecDirSrv                     1a
     D  SecIpc                        1a
     D  SecNas                        1a
     D  SecRun                        1a
     D  SecSckD                       1a
     D  SecVfy                        1a
     D  SecVldL                       1a

     **-- Global constants:
     D ADP_PRV_INVLVL  c                   1
     D NULL            c                   ''
     **-- Global variables:
     D SpcAutLst       s             10a   Dim( 8 )
     D AutFlg          s              1a
     D CmdStr          s           4096a

     **-- Retrieve user information:
     D RtvUsrInf       Pr                  ExtPgm( 'QSYRUSRI' )
     D  RcvVar                    32767a          Options( *VarSize )
     D  RcvVarLen                    10i 0 Const
     D  FmtNam                       10a   Const
     D  UsrPrf                       10a   Const
     D  Error                     32767a          Options( *VarSize )
     **-- Check special authority
     D ChkSpcAut       Pr                  ExtPgm( 'QSYCUSRS' )
     D  AutInf                        1a
     D  UsrPrf                       10a   Const
     D  SpcAut                       10a   Const  Dim( 8 )  Options( *VarSize )
     D  NbrAut                       10i 0 Const
     D  CalLvl                       10i 0 Const
     D  Error                     32767a          Options( *VarSize )
     **-- Process commands:
     D PrcCmds         Pr                  ExtPgm( 'QCAPCMD' )
     D  SrcCmd                    32702a   Const  Options( *VarSize )
     D  SrcCmdLen                    10i 0 Const
     D  OptCtlBlk                    20a   Const
     D  OptCtlBlkLn                  10i 0 Const
     D  OptCtlBlkFm                   8a   Const
     D  ChgCmd                    32767a          Options( *VarSize )
     D  ChgCmdLen                    10i 0 Const
     D  ChgCmdLenAv                  10i 0
     D  Error                     32767a          Options( *VarSize )
     **-- Send program message:
     D SndPgmMsg       Pr                  ExtPgm( 'QMHSNDPM' )
     D  MsgId                         7a   Const
     D  MsgFq                        20a   Const
     D  MsgDta                      128a   Const
     D  MsgDtaLen                    10i 0 Const
     D  MsgTyp                       10a   Const
     D  CalStkE                      10a   Const  Options( *VarSize )
     D  CalStkCtr                    10i 0 Const
     D  MsgKey                        4a
     D  Error                     32767a          Options( *VarSize )

     **-- Retrieve user audit:
     D RtvUsrAud       Pr             1a
     D  PxUsrPrf                     10a   Value
     D  PxAudVal                     10a   Value
     **-- Format user audit level values:
     D FmtAudLvl       Pr           512a   Varying
     D  PxAudLvl                           LikeDs( AudLvl )
     **-- Process command:
     D PrcCmd          Pr            10i 0
     D  CmdStr                     4096a   Const  Varying
     **-- Send completion message:
     D SndCmpMsg       Pr            10i 0
     D  PxMsgDta                    512a   Const  Varying
     **-- Send escape message:
     D SndEscMsg       Pr            10i 0
     D  PxMsgId                       7a   Const
     D  PxMsgF                       10a   Const
     D  PxMsgDta                    512a   Const  Varying

     **-- Entry parameters:
     D SEC104          Pr
     D  PxUsrPrf                     10a
     D  PxTgtPrf                     10a
     **
     D SEC104          Pi
     D  PxUsrPrf                     10a
     D  PxTgtPrf                     10a

      /Free

        CmdStr = NULL;

        SpcAutLst( 1 ) = '*AUDIT';

        ChkSpcAut( AutFlg
                 : PgmSts.UsrPrf
                 : SpcAutLst
                 : 1
                 : ADP_PRV_INVLVL
                 : ERRC0100
                 );

        If  ERRC0100.BytAvl = *Zero  And  AutFlg = 'Y';

          RtvUsrInf( USRI0300
                   : %Size( USRI0300 )
                   : 'USRI0300'
                   : PxUsrPrf
                   : ERRC0100
                   );

          ExSr  BldCmdStr;
        EndIf;

        *InLr = *On;
        Return;


        BegSr  BldCmdStr;

          CmdStr = 'CHGUSRAUD USRPRF(' + %TrimR( PxTgtPrf ) +
                             ') '  +
                             'OBJAUD(' + %TrimR( USRI0300.ObjAudVal ) +
                             ') '  +
                             'AUDLVL(' + FmtAudLvl( USRI0300.UsrAudVal ) +
                             ')';

          If  PrcCmd( CmdStr ) = *Zero;
            SndCmpMsg( 'User profile ' + %Trim( PxTgtPrf ) +
                       ' auditing values changed.'
                     );
          EndIf;

        EndSr;

      /End-Free

     **-- Format user audit level values:
     P FmtAudLvl       B
     D                 Pi           512a   Varying
     D  PxAudLvl                           LikeDs( AudLvl )

     **-- Local variables
     D RtnAudVal       s            512a   Varying

      /Free

        If  %Scan( 'Y': PxAudLvl ) = *Zero;
          RtnAudVal = '*NONE';

        Else;
          If  PxAudLvl.AutFail = 'Y';
            RtnAudVal += '*AUTFAIL' + ' ';
          EndIf;

          If  PxAudLvl.Cmd    = 'Y';
            RtnAudVal += '*CMD' + ' ';
          EndIf;

          If  PxAudLvl.Create = 'Y';
            RtnAudVal += '*CREATE' + ' ';
          EndIf;

          If  PxAudLvl.Delete   = 'Y';
            RtnAudVal += '*DELETE' + ' ';
          EndIf;

          If  PxAudLvl.JobBas   = 'Y';
            RtnAudVal += '*JOBBAS' + ' ';
          EndIf;

          If  PxAudLvl.JobDta   = 'Y';
            RtnAudVal += '*JOBDTA' + ' ';
          EndIf;

          If  PxAudLvl.JobChgUsr = 'Y';
            RtnAudVal += '*JOBCHGUSR' + ' ';
          EndIf;

          If  PxAudLvl.NetBas   = 'Y';
            RtnAudVal += '*NETBAS' + ' ';
          EndIf;

          If  PxAudLvl.NetClu   = 'Y';
            RtnAudVal += '*NETCLU' + ' ';
          EndIf;

          If  PxAudLvl.NetCmn   = 'Y';
            RtnAudVal += '*NETCMN' + ' ';
          EndIf;

          If  PxAudLvl.NetFail  = 'Y';
            RtnAudVal += '*NETFAIL' + ' ';
          EndIf;

          If  PxAudLvl.NetSck   = 'Y';
            RtnAudVal += '*NETSCK' + ' ';
          EndIf;

          If  PxAudLvl.ObjMgt   = 'Y';
            RtnAudVal += '*OBJMGT' + ' ';
          EndIf;

          If  PxAudLvl.OfcSrv   = 'Y';
            RtnAudVal += '*OFCSRV' + ' ';
          EndIf;

          If  PxAudLvl.Optical  = 'Y';
            RtnAudVal += '*OPTICAL' + ' ';
          EndIf;

          If  PxAudLvl.PgmAdp   = 'Y';
            RtnAudVal += '*PGMADP' + ' ';
          EndIf;

          If  PxAudLvl.PgmFail  = 'Y';
            RtnAudVal += '*PGMFAIL' + ' ';
          EndIf;

          If  PxAudLvl.PrtDta   = 'Y';
            RtnAudVal += '*PRTDTA' + ' ';
          EndIf;

          If  PxAudLvl.SecCfg   = 'Y';
            RtnAudVal += '*SECCFG' + ' ';
          EndIf;

          If  PxAudLvl.SecDirSrv = 'Y';
            RtnAudVal += '*SECDIRSRV' + ' ';
          EndIf;

          If  PxAudLvl.SecIpc   = 'Y';
            RtnAudVal += '*SECIPC' + ' ';
          EndIf;

          If  PxAudLvl.SecNas   = 'Y';
            RtnAudVal += '*SECNAS' + ' ';
          EndIf;

          If  PxAudLvl.SecRun   = 'Y';
            RtnAudVal += '*SECRUN' + ' ';
          EndIf;

          If  PxAudLvl.SecSckD  = 'Y';
            RtnAudVal += '*SECSCKD' + ' ';
          EndIf;

          If  PxAudLvl.SecVfy   = 'Y';
            RtnAudVal += '*SECVFY' + ' ';
          EndIf;

          If  PxAudLvl.SecVldL  = 'Y';
            RtnAudVal += '*SECVLDL' + ' ';
          EndIf;

          If  PxAudLvl.SavRst   = 'Y';
            RtnAudVal += '*SAVRST' + ' ';
          EndIf;

          If  PxAudLvl.Security = 'Y';
            RtnAudVal += '*SECURITY' + ' ';
          EndIf;

          If  PxAudLvl.Service  = 'Y';
            RtnAudVal += '*SERVICE' + ' ';
          EndIf;

          If  PxAudLvl.SplfDta  = 'Y';
            RtnAudVal += '*SPLFDTA' + ' ';
          EndIf;

          If  PxAudLvl.SysMgt   = 'Y';
            RtnAudVal += '*SYSMGT' + ' ';
          EndIf;
        EndIf;

        Return  %TrimR( RtnAudVal );

      /End-Free

     P FmtAudLvl       E
     **-- Process command:
     P PrcCmd          B
     D                 Pi            10i 0
     D  PxCmdStr                   4096a   Const  Varying

     **-- Local variables:
     D CPOP0100        Ds                  Qualified
     D  TypPrc                       10i 0 Inz( 2 )
     D  DBCS                          1a   Inz( '0' )
     D  PmtAct                        1a   Inz( '2' )
     D  CmdStx                        1a   Inz( '0' )
     D  MsgRtvKey                     4a   Inz( *Allx'00' )
     D  Rsv                           9a   Inz( *Allx'00' )
     **
     D ChgCmd          s          32767a
     D ChgCmdAvl       s             10i 0

      /Free

        PrcCmds( PxCmdStr
               : %Len( PxCmdStr )
               : CPOP0100
               : %Size( CPOP0100 )
               : 'CPOP0100'
               : ChgCmd
               : %Size( ChgCmd )
               : ChgCmdAvl
               : ERRC0100
               );

        If  ERRC0100.BytAvl > *Zero;
          Return  -1;
        Else;
          Return  *Zero;
        EndIf;

      /End-Free

     P PrcCmd          E
     **-- Send completion message:
     P SndCmpMsg       B
     D                 Pi            10i 0
     D  PxMsgDta                    512a   Const  Varying
     **
     D MsgKey          s              4a

      /Free

        SndPgmMsg( 'CPF9897'
                 : 'QCPFMSG   *LIBL'
                 : PxMsgDta
                 : %Len( PxMsgDta )
                 : '*COMP'
                 : '*PGMBDY'
                 : 1
                 : MsgKey
                 : ERRC0100
                 );

        If  ERRC0100.BytAvl > *Zero;
          Return  -1;

        Else;
          Return  0;

        EndIf;

      /End-Free

     P SndCmpMsg       E
     **-- Send escape message:
     P SndEscMsg       B
     D                 Pi            10i 0
     D  PxMsgId                       7a   Const
     D  PxMsgF                       10a   Const
     D  PxMsgDta                    512a   Const  Varying
     **
     D MsgKey          s              4a

      /Free

        SndPgmMsg( PxMsgId
                 : PxMsgF + '*LIBL'
                 : PxMsgDta
                 : %Len( PxMsgDta )
                 : '*ESCAPE'
                 : '*PGMBDY'
                 : 1
                 : MsgKey
                 : ERRC0100
                 );

        If  ERRC0100.BytAvl > *Zero;
          Return  -1;

        Else;
          Return   0;
        EndIf;

      /End-Free

     P SndEscMsg       E
