星期三, 11月 08, 2023

2008-07-30 如何快速顯示 IFS 目錄或檔案的使用者權限?(Command: DSPIFSAUT with API Qp0lGetAttr)


如何快速顯示 IFS 目錄或檔案的使用者權限?(Command: DSPIFSAUT with API Qp0lGetAttr)

File   : QRPGLESRC
Member : DSPIFSAUT
Type   : RPGLE
Usage  : CRTBNDRPG PGM(DSPIFSAUT) TGTRLS(V5R2M0)

     **
     **  Program . . : DspIfsAut
     **  Description : Display IFS File Authority (CPP of command DspIfsAut)
     **  Author  . . : Vengoal Chang
     **  Date    . . : 2008/07/30
     **
     **  Input parameters
     **   Description        Type  Size    How Used
     **   -----------        ----  ----    --------
     **   PxIfsObj           Char  5002    IFS object authority for display
     **
     **
     **  Compile options:
     **
     **    CrtBndRpg  Pgm( DspIfsAut )
     **               DbgView( *LIST ) TgtRls(V5R1M0)
     **
     **
     **-- Control specification:  --------------------------------------------**
     H Option( *SrcStmt )  BndDir( 'QC2LE' )  DecEdit( *JOBRUN )
     H DftActGrp(*NO)
     **-- Printer file:
     FQSYSPRT   O    F  132        Printer  InfDs( PrtLinInf )  OflInd( *InOf )
     F                                      UsrOpn
     **-- Printer file information:
     D PrtLinInf       Ds
     D  PlOvfLin                      5i 0  Overlay( PrtLinInf: 188 )
     D  PlCurLin                      5i 0  Overlay( PrtLinInf: 367 )
     D  PlCurPag                      5i 0  Overlay( PrtLinInf: 369 )

     **-- System information:
     D                SDs
     D  PsPgmNam         *Proc
     **-- 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                      256a

     **-- Global variables:
     D LstTim          s              6s 0
     D IfsObj          s            109a
     D LinTxt          s             40a
     D LinVal          s             50a
     D LinVal2         s            105a

     **
     D BufSizAvl       s             10u 0 Inz( 0 )
     D NbrBytRtn       s             10u 0 Inz( 0 )
     D ApiRcvSiz       s             10u 0
     D rc              s             10i 0
     D Idx             s             10i 0
     D pBuffer         s               *
     D ErrTxt          s            256a
     D MsgKey          s              4a

     **
     D ObjOwn          s             10a
     D ObjPgp          s             10a
     D AutLstNam       s             10a
     D UsrNam          s             10a
     D UsrDtaAut       s             10a
     **
     D AutObjMgm       s              1a
     D AutObjExs       s              1a
     D AutObjAlt       s              1a
     D AutObjRef       s              1a
     D AutObjOpr       s              1a
     D AutDtaRead      s              1a
     D AutDtaAdd       s              1a
     D AutDtaUpd       s              1a
     D AutDtaDlt       s              1a
     D AutDtaExe       s              1a
     D AutDtaExcl      s              1a

     **-- Spooled file information:
     D SPRL0100        Ds                  Qualified
     D  BytRtn                       10i 0
     D  BytAvl                       10i 0
     D  SplfNam                      10a
     D  JobNam                       10a
     D  UsrNam                       10a
     D  JobNbr                        6a
     D  SplfNbr                      10i 0
     D  JobSysNam                     8a
     D  SplfCrtDat                    7a
     D                                1a
     D  SplfCrtTim                    6a

     **-- File attributes:
     D QP0L_ATTR_AUTH  c                   11

     **-- API path constants:
     D CUR_CCSID       c                   0
     D CUR_CTRID       c                   x'0000'
     D CUR_LNGID       c                   x'000000'
     D CHR_DLM_1       c                   0

     **-- General authority format:
     D GenAut          Ds                  Qualified  Align  Based( pGenAut )
     D  ObjOwn                       10a
     D  PriGrp                       10a
     D  AutL                         10a
     D                               10a
     D  OfsUsrE                      10i 0
     D  NbrUsrE                      10i 0
     D  SizUsrE                      10i 0
     D                               12a
     **
     D UsrAut          Ds                  Qualified  Align  Based( pUsrAut )
     D  UsrNam                       10a
     D  UsrDtaAut                    10a
     D  ObjMgm                        1a
     D  ObjExs                        1a
     D  ObjAlt                        1a
     D  ObjRef                        1a
     D                               10a
     D  ObjOpr                        1a
     D  DtaRead                       1a
     D  DtaAdd                        1a
     D  DtaUpd                        1a
     D  DtaDlt                        1a
     D  DtaExe                        1a
     D  DtaExclude                    1a
     D                                7a
     **-- API path:
     D Path            Ds                  Qualified  Align
     D  CcsId                        10i 0 Inz( CUR_CCSID )
     D  CtrId                         2a   Inz( CUR_CTRID )
     D  LngId                         3a   Inz( CUR_LNGID )
     D                                3a   Inz( *Allx'00' )
     D  PthTypI                      10i 0 Inz( CHR_DLM_1 )
     D  PthNamLen                    10i 0
     D  PthNamDlm                     2a   Inz( '/ ' )
     D                               10a   Inz( *Allx'00' )
     D  PthNam                     5000a

     **
     D AtrIds          Ds                  Qualified  Align
     D  NbrAtr                       10i 0
     D  AtrId                        10i 0 Dim( 32 )
     **
     D Buffer          Ds                  Qualified  Align  Based( pBufferE )
     D  OfsNxtAtr                    10i 0
     D  AtrId                        10i 0
     D  SizAtr                       10i 0
     D                                4a
     D  AtrDta                     1024a
     D   AtrInt2                      5i 0 Overlay( AtrDta: 1 )
     D   AtrInt                      10i 0 Overlay( AtrDta: 1 )
     D   AtrUint                     10u 0 Overlay( AtrDta: 1 )
     D   AtrUint8                    20u 0 Overlay( AtrDta: 1 )
     **-- Get attributes:
     D GetAtr          Pr            10i 0 ExtProc( 'Qp0lGetAttr' )
     D  GaFilNam                       *   Value
     D  GaAtrLst                       *   Value
     D  GaBuffer                       *   Value
     D  GaBufSizPrv                  10u 0 Value
     D  GaBufSizAvl                  10u 0
     D  GaBufSizRtn                  10u 0
     D  GaFlwSymLnk                  10u 0 Value
     D  GaDots                       10i 0 Options( *NoPass )
     **-- Initialize memory:
     D memset          Pr            10i 0 ExtProc( 'memset' )
     D  pStg                           *   Value
     D  InzVal                        1a   Value
     D  InzByt                       10i 0 Value
     **-- Copy memory:
     D memcpy          Pr              *   ExtProc( '_MEMMOVE' )
     D  MemOut                         *   Value
     D  MemInp                         *   Value
     D  MemSiz                       10u 0 Value
     **-- Send program message:
     D SndPgmMsg       Pr                  ExtPgm( 'QMHSNDPM' )
     D  SpMsgId                       7a   Const
     D  SpMsgFq                      20a   Const
     D  SpMsgDta                    128a   Const
     D  SpMsgDtaLen                  10i 0 Const
     D  SpMsgTyp                     10a   Const
     D  SpCalStkE                    10a   Const  Options( *VarSize )
     D  SpCalStkCtr                  10i 0 Const
     D  SpMsgKey                      4a
     D  SpError                   32767a          Options( *VarSize )
     **-- Retrieve last spooled file identity:
     D RtvLstSplfId    Pr                  ExtPgm( 'QSPRILSP' )
     D  RsRcvVar                  32767a          Options( *VarSize )
     D  RsRcvVarLen                  10i 0 Const
     D  RsFmtNam                      8a   Const
     D  RsError                   32767a          Options( *VarSize )

     **-- Run system command:
     D system          Pr            10i 0 ExtProc( 'system' )
     D  command                        *   Value  Options( *String )

     **-- Write attribute line:
     D WrtAtrLin       Pr
     D  PxLinTxt                     40a   Const
     D  PxLinVal                     50a   Const
     **-- Write attribute line:
     D WrtAtrLin2      Pr
     D  PxLinVal                    100a   Const
     **-- Write blank line:
     D WrtBlkLin       Pr
     **-- Write list header:
     D WrtLstHdr       Pr
     D  PxOvrFlwRel                  10i 0 Const  Options( *NoPass )
     **-- Send escape message:
     D SndEscMsg       Pr            10i 0
     D  PxMsgDta                    512a   Const  Varying
     **-- Send completion message:
     D SndCmpMsg       Pr            10i 0
     D  PxMsgDta                    512a   Const  Varying
     **-- Error identification:
     D errno           Pr            10i 0
     **
     D strerror        Pr           128a   Varying

     D DSPIFSAUT       Pr
     D  PxIfsObj                   5002a   Varying
     **
     D DSPIFSAUT       Pi
     D  PxIfsObj                   5002a   Varying

      /Free

        Path.PthNam    = PxIfsObj;
        Path.PthNamLen = %Len( PxIfsObj );

        AtrIds.NbrAtr = 1;
        AtrIds.AtrId = QP0L_ATTR_AUTH;

        If  GetAtr( %Addr( Path )
                  : %Addr( AtrIds )
                  : *Null
                  : *Zero
                  : BufSizAvl
                  : NbrBytRtn
                  : 0
                  ) = 0;

          ApiRcvSiz = BufSizAvl;
          pBuffer   = %Alloc( ApiRcvSiz );

          memset( pBuffer: x'00': ApiRcvSiz );

          If  GetAtr( %Addr( Path )
                    : %Addr( AtrIds )
                    : pBuffer
                    : ApiRcvSiz
                    : BufSizAvl
                    : NbrBytRtn
                    : 0
                    ) = 0;

            pBufferE = pBuffer;

            //When  Buffer.AtrId = QP0L_ATTR_AUTH;
            pGenAut = %Addr( Buffer.AtrDta );

            ObjOwn = GenAut.ObjOwn;
            ObjPgp = GenAut.PriGrp;
            AutLstNam = GenAut.AutL;

            Open  QSYSPRT;

          WrtAtrLin( 'Authorization list . . . . . . . . . . :': AutLstNam );
          WrtAtrLin( 'Object primary group . . . . . . . . . :': ObjPgp );
          WrtBlkLin();
          WrtAtrLin( 'User authority . . . . :' : ' ');

          LinVal2 =  '              Data     --Object Authorities--  ' +
                     '-------------Data Authorities------------';
          WrtAtrLin2(LinVal2);
          LinVal2 =  'User        Authority  Exist  Mgt  Alter  Ref  ' +
                     'Objopr  Read  Add  Update  Delete  Execute';
          WrtAtrLin2(LinVal2);
          WrtBlkLin();

            pUsrAut = pBuffer + GenAut.OfsUsrE;

            For  Idx = 1  to GenAut.NbrUsrE;

              // Authorization entry available here
              LinVal2 = ' ';
              %SubSt(LinVal2:1 :10) = UsrAut.UsrNam;
              %SubSt(LinVal2:13:10) = UsrAut.UsrDtaAut;
              If UsrAut.ObjExs = X'01';
                 %SubSt(LinVal2:26: 1) = 'X';
              EndIf;
              If UsrAut.ObjMgm = X'01';
                 %SubSt(LinVal2:32: 1) = 'X';
              EndIf;
              If UsrAut.ObjAlt = X'01';
                 %SubSt(LinVal2:38: 1) = 'X';
              EndIf;
              If UsrAut.ObjRef = X'01';
                 %SubSt(LinVal2:44: 1) = 'X';
              EndIf;
              If UsrAut.ObjOpr = X'01';
                 %SubSt(LinVal2:50: 1) = 'X';
              EndIf;
              If UsrAut.DtaRead= X'01';
                 %SubSt(LinVal2:57: 1) = 'X';
              EndIf;
              If UsrAut.DtaAdd = X'01';
                 %SubSt(LinVal2:63: 1) = 'X';
              EndIf;
              If UsrAut.DtaUpd = X'01';
                 %SubSt(LinVal2:69: 1) = 'X';
              EndIf;
              If UsrAut.DtaDlt = X'01';
                 %SubSt(LinVal2:77: 1) = 'X';
              EndIf;
              If UsrAut.DtaExe = X'01';
                 %SubSt(LinVal2:86: 1) = 'X';
              EndIf;
          WrtAtrLin2( LinVal2 );
          WrtBlkLin();

              If  Idx < GenAut.NbrUsrE;
                pUsrAut += GenAut.SizUsrE;
              EndIf;
            EndFor;
            Close QSYSPRT;
            ExSr  DspSplf;
          EndIf;
        Else;

          SndEscMsg( %Char( Errno ) + ': ' + Strerror );
        EndIf;

        DeAlloc  pBuffer;

        *InLr = *On;
        Return;

        BegSr  DspSplf;

          RtvLstSplfId( SPRL0100: %Size( SPRL0100 ): 'SPRL0100': ERRC0100 );

          system( 'DSPSPLF FILE(' + %Trim( SPRL0100.SplfNam ) + ')' +
                          ' JOB(' + %Trim( SPRL0100.JobNbr )  + '/' +
                                    %Trim( SPRL0100.UsrNam )  + '/' +
                                    %Trim( SPRL0100.JobNam )  + ')' +
                          ' SPLNBR(' + %Char( SPRL0100.SplfNbr ) + ')'
          );

          system( 'DLTSPLF FILE(' + %Trim( SPRL0100.SplfNam ) + ')' +
                          ' JOB(' + %Trim( SPRL0100.JobNbr )  + '/' +
                                    %Trim( SPRL0100.UsrNam )  + '/' +
                                    %Trim( SPRL0100.JobNam )  + ')' +
                          ' SPLNBR(' + %Char( SPRL0100.SplfNbr ) + ')'
          );

          SndCmpMsg( 'IFS authority list has been displayed and deleted.' );

        EndSr;

        BegSr  *InzSr;

          LstTim = %Int( %Char( %Time(): *ISO0));

          If  %Len( PxIfsObj ) > %Size( IfsObj );

            EvalR  IfsObj = PxIfsObj;
            %Subst( IfsObj: 1: 3 ) = '...';
          Else;

            IfsObj = PxIfsObj;
          EndIf;

        EndSr;

      /End-Free

     **-- Printer file definition:  ------------------------------------------**
     OQSYSPRT   EF           Header         2  2
     O                       UDATE         Y      8
     O                       LstTim              18 '  :  :  '
     O                                           70 'Display IFS File Attribute-
     O                                              s'
     O                                          107 'Program:'
     O                       PsPgmNam           118
     O                                          126 'Page:'
     O                       PAGE             +   1
     OQSYSPRT   EF           LstHdr         1
     O                                           20 'Object . . . . . . :'
     O                       IfsObj             132
     OQSYSPRT   EF           DtlLin         1
     O                       LinTxt              40
     O                       LinVal              93
     OQSYSPRT   EF           DtlLin2        1
     O                       LinVal2            130
     OQSYSPRT   EF           DtlBlk         1
     **
     OQSYSPRT   EF           LstTrl      1
     O                                           26 '*  E N D  O F  L I S T  *'

     **-- Get runtime error number:  -----------------------------------------**
     P errno           B
     D                 Pi            10i 0
     D sys_errno       Pr              *    ExtProc( '__errno' )
     **
     D Error           s             10i 0  Based( pError )  NoOpt

      /Free

        pError = sys_errno;

        Return  Error;

      /End-Free

     P Errno           E
     **-- Get runtime error text:  -------------------------------------------**
     P strerror        B
     D                 Pi           128a    Varying
     D sys_strerror    Pr              *    ExtProc( 'strerror' )
     D                               10i 0  Value

      /Free

        Return  %Str( sys_strerror( Errno ));

      /End-Free

     P strerror        E
     **-- Write attribute line:  ---------------------------------------------**
     P WrtAtrLin       B
     D                 Pi
     D  PxLinTxt                     40a   Const
     D  PxLinVal                     50a   Const

      /Free

          WrtLstHdr( 3 );

          LinTxt = PxLinTxt;
          LinVal = PxLinVal;

          Except  DtlLin;

      /End-Free

     P WrtAtrLin       E
     **-- Write attribute line2: ---------------------------------------------**
     P WrtAtrLin2      B
     D                 Pi
     D  PxLinVal2                   100a   Const

      /Free

          WrtLstHdr( 3 );

          LinVal2= PxLinVal2;

          Except  DtlLin2;

      /End-Free

     P WrtAtrLin2      E
     **-- Write blank line:  -------------------------------------------------**
     P WrtBlkLin       B
     D                 Pi

      /Free

          WrtLstHdr( 2 );

          Except  DtlBlk;

      /End-Free

     P WrtBlkLin       E
     **-- Write list header:  ------------------------------------------------**
     P WrtLstHdr       B
     D                 Pi
     D  PxOvrFlwRel                  10i 0 Const  Options( *NoPass )

      /Free

        If  %Parms = *Zero;

          Except  Header;
          Except  LstHdr;
        Else;

          If  PlCurLin > PlOvfLin - PxOvrFlwRel;

            Except  Header;
            Except  LstHdr;
          EndIf;
        EndIf;

      /End-Free

     P WrtLstHdr       E
     **-- Send escape message:  ----------------------------------------------**
     P SndEscMsg       B
     D                 Pi            10i 0
     D  PxMsgDta                    512a   Const  Varying

      /Free

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

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

        Else;
          Return  0;

        EndIf;

      /End-Free

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

      /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


File   : QCMDSRC
Member : DSPIFSAUT
Type   : CMD
Usage  : CRTCMD CMD(DSPIFSAUT) PGM(DSPIFSAUT)
Sample : DSPIFSAUT OBJ('/tmp') 

/*  ===============================================================  */
/*  = Command....... DspIfsAut                                    =  */
/*  = CPP........... DspIfsAut                                    =  */
/*  = Description... Display IFS File Authority                   =  */
/*  =                                                             =  */
/*  = CrtCmd      Cmd( DspIfsAut )                                =  */
/*  =             Pgm( DspIfsAut )                                =  */
/*  =             SrcFile( YourSourceFile )                       =  */
/*  =                                                             =  */
/*  ===============================================================  */
/*  = Date  : 2008/07/30                                          =  */
/*  = Author: Vengoal Chang                                       =  */
/*  ===============================================================  */

     CMD        PROMPT('DISPLAY IFS FILE AUTHORITY')

     PARM       OBJ        *PNAME    5000             +
                MIN( 1 )                              +
                VARY( *YES *INT2 )                    +
                CASE( *MIXED )                        +
                PROMPT( 'OBJECT' )






沒有留言: