midrange.com code scratchpad
Name:
Use QCMDCHK to screen CALL commands
Scriptlanguage:
Plain Text
Tabwidth:
4
Date:
12/14/2008 04:28:11 am
IP:
Logged
Description:
This program calls QCMDCHK in order to prompt a CALL command and to return the full CALL command string. The PGM() parm is extracted from the string. Both the library and the program names are then extracted. Any programs that shouldn't be called or libraries that shouldn't be accessed can cause an exit. If all is well, QCMDEXC will execute the CALL.
Code:
  1.  /* Run QCMDEXC to execute a prompted CALL command. But use        */
  2.  /*   QCMDCHK to prompt the command and check the command string   */
  3.  /*   to see what programs are being called.                       */
  4.  
  5. pgm
  6.  
  7.    dcl   &cmdStr      *char   2000
  8.    dcl   &pgmStr      *char     21
  9.  
  10.    dcl   &obj         *char     10
  11.    dcl   &lib         *char     10
  12.    dcl   &pgm         *char     10
  13.    dcl   &char        *char      1
  14.    dcl   &f_char      *lgl             value( '0' )
  15.    dcl   &f_pgm       *lgl             value( '0' )
  16.    dcl   &f_lib       *lgl             value( '0' )
  17.    dcl   &i           *int             value( 0 )
  18.    dcl   &len         *int             value( 0 )
  19.    dcl   &pos         *int             value( 1 )
  20.  
  21.  
  22.    chgvar     &cmdStr      '?CALL'
  23.  
  24.  /* Pass [?CALL] to QCMDCHK. The command is prompted and all       */
  25.  /*   values may be entered. The resulting command is returned to  */
  26.  /*   this program. We'll check the PGM() parm to see if it will   */
  27.  /*   be allowed.                                                  */
  28.  
  29.    call       QCMDCHK    ( +
  30.                            &cmdStr     +
  31.                            2000        +
  32.                          )
  33.    monmsg   ( CPF6801 )  exec( do ) /* User pressed <F12> */
  34.       return
  35.    enddo
  36.  
  37. /* check [PGM()] */
  38. /* Four possibilities:                       */
  39. /*   PGM( pgm )                              */
  40. /*   PGM( lib/pgm )                          */
  41. /*   PGM( *LIBL/pgm )                        */
  42. /*   PGM( *CURLIB/pgm )                      */
  43.  
  44.    chgvar     &pgmstr      %sst( &cmdstr 10 21 )
  45.  
  46.    chgvar     &i         ( 1 )
  47.  
  48.    dountil    ( &f_char *or &i *gt 21 )
  49.       chgvar  &char        %sst( &pgmstr &i 1 )
  50.       select
  51.          when ( &char *eq '/' )  do     /* &lib delimiter */
  52.             chgvar   &f_char   ( '1' )
  53.             chgvar   &f_lib    ( '1' )
  54.          enddo
  55.          when ( &char *eq ')' )  do     /* no &lib delimiter */
  56.             chgvar   &f_char   ( '1' )
  57.             chgvar   &f_pgm    ( '1' )
  58.          enddo
  59.          when ( &char *eq ' ' )  do     /* no delimiter??? */
  60.             chgvar   &f_char   ( '1' )
  61.          enddo
  62.          otherwise  +
  63.             chgvar   &i        ( &i + 1 )
  64.       endselect
  65.    enddo
  66.  
  67.    chgvar     &len       ( &i - 1 )
  68.  
  69.  /* If we found a library spec, we account for for the delimiter,  */
  70.  /*   and then find the program spec...                            */
  71.  
  72.    if ( &f_lib )  do                    /* found &lib */
  73.  
  74.       chgvar  &pos       ( &i + 1 )
  75.       chgvar  &lib         %sst( &pgmstr 1 &len )
  76.  
  77.       dountil    ( &char *eq ')' *or &i *gt 21 )
  78.          chgvar  &char        %sst( &pgmstr &i 1 )
  79.          chgvar  &i         ( &i + 1 )
  80.       enddo
  81.  
  82.       if ( &char *eq ')' )  +
  83.          chgvar  &i         ( &i - 1 )
  84.  
  85.    enddo
  86.  
  87.  /* Otherwise we just assume *LIBL... */
  88.  
  89.    else  +
  90.       chgvar  &lib         '*LIBL'
  91.  
  92.  /* Wherever &lib was, we pull &pgm from what remains... */
  93.  
  94.    chgvar     &len       ( &i - &pos )
  95.    chgvar     &pgm         %sst( &pgmstr &pos &len )
  96.  
  97.  /* Note whatever was found... */
  98.  
  99.    sndpgmmsg  msgid( CPF9898 ) msgf( QCPFMSG ) +
  100.                 msgdta( +
  101.                         &lib *tcat '/' *cat &pgm +
  102.                       )
  103.  
  104.  /* Decide what pgms and libs are acceptable... */
  105.  
  106.    if ( &pgm *eq 'QCMD' *or  +
  107.         &pgm *eq 'QCMDEXC' *or  +
  108.         &pgm *eq 'QUSCMDLN' *or  +
  109.         &pgm *eq 'QCAPCMD' )  do
  110.       return
  111.    enddo
  112.  
  113.    if ( &lib *eq 'QSYS' )  do
  114.       return
  115.    enddo
  116.  
  117.  /* Run what's acceptable... */
  118.  
  119.    call       QCMDEXC    ( +
  120.                            &cmdStr     +
  121.                            2000        +
  122.                          )
  123.    monmsg   ( CPF0006 )  /* Program not found */
  124.  
  125.    return
  126.  
  127. endpgm
  128.  
© 2004-2019 by midrange.com generated in 0.006s valid xhtml & css