Control Cl Commands With Command Exit Program 2

Embed Size (px)

Citation preview

  • 7/27/2019 Control Cl Commands With Command Exit Program 2

    1/7

    System iNetwork Head NavSubscribe My Profile Contact Us AdvertiseSearch

    Primary linksForums Archives Code Blogs Podcasts Webcasts e-Learning Guides Newsletters AboutUs Contact Us About the Network Tech Editor Profiles Editorial Calendar WritersKit Advertise Join Network

    CategoriesRPG ProgrammingOther LanguagesApplication DevelopmentDatabase/SQLAvailabilitySecuritySystems ManagementNetworking/ConnectivityIT Management/CareersSite LinksSolutionsStore

    EventsJobsSystem iPortalHome ContentControl CL Commands with Command Exit Programs - Part 2Article ID: 18426Posted July 16th, 2007 in RPG Programming Systems ManagementBy:Dan RiehlDo you want to be alerted when someone tries to restore objects onto your system, starts a TCP/IP server program, or saves a particular library? In the past, itwas difficult to collect these events in realtime, but with the i5/OS capabilit

    y to monitor for sensitive commands, collecting these events becomes a rather trivial task.

    In part one of this series, I focused on the exit points available for CL commands, and dealt specifically with the Change Command exit point (article ID 54958at SystemiNetwork.com). As noted in that article, another exit point can be usedto monitor and audit commands as they are executing. This is the Command Analyzer Retrieve exit point.

    This capability lets you capture commands as they execute and use the information that you collect. Unlike the Command Analyzer Change exit point discussed lastmonth, the Command Analyzer Retrieve exit point does not let you send information back to the command analyzer. This limits the capabilities of this exit point

    to essentially only a logging and auditing exit point.

    The example program in this article is called whenever someone executes the Restore Object (RSTOBJ) command. The program retrieves the command information and records the RSTOBJ command string and other useful information in the system's QHST history log. You can certainly do other things with the command string data,but the purpose of this simple example is to illustrate the process of creatingand registering a CL command exit program.

    The Command Analyzer Retrieve Exit Point

  • 7/27/2019 Control Cl Commands With Command Exit Program 2

    2/7

    Each IBM-supplied exit point has an assigned name and an exit-point interface. The exit-point interface is a list of parameters that the command analyzer exchanges with your exit program. The name of the exit point for the Command AnalyzerRetrieve command exit point is QIBM_QCA_RTV_COMMAND. This exit point occurs after the command analyzer has done much of its work but before control is passed tothe Command Processing Program (CPP).

    Because this exit program is called before the CPP, the exit program cannot predict whether the command will complete normally or abnormally. It only knows thatthe command is being attempted, with no knowledge of, or potential impact on, the outcome of the CPP (i.e., whether the operation will fail or succeed).

    The name of the exit-point interface for this exit point is named RTVC0100. Thisexit-point interface is similar to the CHGC0100 interface discussed in the lastissue. The exit program is passed the RTVC0100 interface as one big lump of data. Your program needs to parse out the individual data elements of the RTVC0100parameter as illustrated in Figure 1.

    Figure 1: The Retrieve Command Exit-Point Interface

    Parameter 1

    DescriptionValuesType and Length

    Exit Point NameQIBM_QCA_RTV_COMMANDChar 20Exit Point Interface Format NameRTVC0100Char 8Command NameName of the command for which the exit program is registeredChar 10

    Command Library NameName of the library where the command residesChar 10Reserved for Future Use

    Char 4Offset to original Command StringThe offset to the beginning of the original command stringBinary (4)

  • 7/27/2019 Control Cl Commands With Command Exit Program 2

    3/7

    Length of Original Command StringThe length of the original command stringBinary (4)Offset to Replacement Command StringThe offset to the beginning of the replacement command string if the command was changed by the Change Command exit point.

    Otherwise, the value is 0.Binary (4)Length of Replacement Command StringThe length of the replacement command string if the command was changed by theChange command exit point.

    Otherwise, the value is 0.Binary (4)Original Command StringThe original command string before any changesChar * (Variable Length)Replacement Command String

    The command string that you want to run in place of the original commandChar * (Variable Length)

    As with all registered exit points, you can add your own exit point program using the Add Exit Program (ADDEXITPGM) command. In the case of the Retrieve Commandexit point, you need to specify the name of the command and the library in which the command resides in the PGMDTA parameter. For the Retrieve command exit point, you can register up to 10 programs per command, incrementing the PGMNBR parameter for each consecutive program. This lets you run a sequence of programs, athird party, or vendor-supplied exit program and still run your own program.

    ADDEXITPGM EXITPNT(QIBM_QCA_RTV_COMMAND) +

    FORMAT(RTVC0100) +PGMNBR(1) +PGM(MYLIB/RSTOBJEXIT) +TEXT('Exit program for RSTOBJ') +PGMDTA(*JOB 20 'RSTOBJ QSYS')The PGMDTA parameter must be specifie

    d with a data length of 20. You must specify the command name in the first 10 positions and the command library in the next 10 positions. The command analyzer is directed to use the exit program RSTOBJEXIT in library MYLIB whenever a request is made to run the RSTOBJ command found in the QSYS library.

    Figure 2 contains a sample exit program that can be used for the RSTOBJ command.The sample is written in pre-V5R3 CL syntax, so it can be used by all readers on V5R4 and higher. The exit program sends a message to a message queue each time

    the RSTOBJ command is used. It also sends a message to the QHST history log. The processing performed in this program is quite simple, however it does providea template that you can use to create your own program.

    Note that this exit program is registered to monitor for the usage of only the RSTOBJ command. However, you can use the same program to monitor for all RSTxxx commands by adding the same exit point program (ADDEXITPGM) for each RSTxxx command (e.g., RSTLIB, RST, RSTLICPGM, etc).

    Figure 2: Command Exit Point Program Example

  • 7/27/2019 Control Cl Commands With Command Exit Program 2

    4/7

    --------------------------------------------------------------------------------

    /* Program Name: RSTOBJEXIT *//* Purpose: This is the exit program for the Command RSTOBJ. *//* Exit Point is QIBM_QCA_RTV_COMMAND *//* Parameter format is RTVC0100. *//* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *//* Copyright 2007 Dan Riehl, All rights reserved */

    PGM PARM(&ExitInfo)

    DCL &Exitinfo *Char 2000 /* RTVC0100 Interface Data */

    DCL &User *Char 10DCL &JobName *Char 10

    DCL &OffsetDec *Dec (7 0)DCL &CmdLenDec *Dec (7 0)

    /* Exit point interface RTVC0100 for QIBM_CA_RTV_COMMAND exit point */DCL &ExitPoint *CHAR 20 /* Exit Point name */DCL &ExitFormat *CHAR 8 /* Exit Point Format */DCL &CmdName *CHAR 10 /* Command name being executed */

    DCL &CmdLib *CHAR 10 /* Command Library */DCL &OffsetO *CHAR 4 /* Offset to command string */

    DCL &CmdLengthO *CHAR 4 /* Command string length */DCL &OffsetR *CHAR 4 /* Offset to command string */DCL &CmdLengthR *CHAR 4 /* Command string length */

    DCL &CmdString *CHAR 2000 /* Command String */

    /* Error handling variables */DCL &MsgID *CHAR 7DCL &MsgFile *CHAR 10DCL &MsgFLib *CHAR 10

    DCL &MsgData *CHAR 512

    MONMSG CPF0000 EXEC(GOTO ERROR)

    /* Parse out the exit info data */CHGVAR &ExitPoint %SST(&ExitInfo 1 20)CHGVAR &ExitFormat %SST(&ExitInfo 21 8)CHGVAR &CmdName %SST(&ExitInfo 29 10)CHGVAR &CmdLib %SST(&ExitInfo 39 10)CHGVAR &OffsetO %SST(&ExitInfo 53 4)CHGVAR &CmdLengthO %SST(&ExitInfo 57 4)CHGVAR &OffsetR %SST(&ExitInfo 61 4)CHGVAR &CmdLengthR %SST(&ExitInfo 65 4)

    /* Check to see whether command was replaced by Change Command Exit */IF (%BIN(&OffsetR) = 0) DO /* Command not replaced */

    CHGVAR &CmdLenDec %BIN(&CmdlengthO)CHGVAR &OffsetDec (%BIN(&OffsetO) + 1) /* Set offset */

    ENDDOELSE DO /* Command was replaced */

    CHGVAR &CmdLenDec %BIN(&CmdlengthR)CHGVAR &OffsetDec (%BIN(&OffsetR) + 1) /* Set offset */

    ENDDO

  • 7/27/2019 Control Cl Commands With Command Exit Program 2

    5/7

    CHGVAR &CmdString %SST(&ExitInfo &OffsetDec &CmdLenDec)

    RTVJOBA JOB(&JobName) USER(&User)

    SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('Restore +operation in progress from user' *BCAT +&User *BCAT 'from job' *BCAT &JobName +*TCAT '. The command executed is:' *BCAT +&CmdString) TOMSGQ(RESTORE QHST)

    ENDIT: RETURN /* Normal end of Program */

    /* Error handling */ERROR: RCVMSG MSGTYPE(*LAST) MSGDTA(&MsgData) +

    MSGID(&MsgID) MSGF(&MsgFile) +SNDMSGFLIB(&MsgFLib)

    MONMSG CPF0000 EXEC(RETURN)

    SNDPGMMSG MSGID(&MsgID) MSGF(&MSGFLIB/&MsgFile) +MSGDTA(&MsgData) MSGTYPE(*ESCAPE)

    MONMSG CPF0000 EXEC(RETURN)ENDPGM

    --------------------------------------------------------------------------------

    Examining the RSTOBJ Command Exit ProgramThe exit program receives only one parameter. As previously mentioned, this parameter contains the RTVC0100 data structure that must be parsed into its individual fields. In Figure 2, the fields defined are those that will be used to storethe RTVC0100 format data after it is parsed. Then the RTVC0100 format is parsedinto it's component parts.

    Next, a determination is made as to whether the original command was replaced bya Command Analyzer Change exit program. If it was replaced, the command stringthat is being executed is found at the offset stored in the variable &OFFSETR, otherwise the offset to the command is found in the variable &OFFSETO. As you cansee, the determination is made by checking the replacement offset (&OFFSETR) fo

    r a value of zero. If the replacement offset is zero, the command was not replaced by a Command Analyzer Change exit program.

    Later in the code, the User and Job name are retrieved from the job running theRSTOBJ command. This information is collected so that it can be included in theinformational message that is sent. The message is sent to the message queues RESTORE and QHST. You can replace these in the code to suit your individual requirements.

    Figure 3 shows the resulting Display Messages screen after a few RSTOBJ commandsare executed. The same information is written to the QHST history log to help audit for the use of the RSTOBJ command.

    Figure 3: Resulting Display Messages Screen

    --------------------------------------------------------------------------------

    Display MessagesSystem: MYAS400

    Queue . . . . . : RESTORE Program . . . . : *DSPMSGLibrary . . . : QUSRSYS Library . . . :

    Severity . . . : 00 Delivery . . . : *BREAK

  • 7/27/2019 Control Cl Commands With Command Exit Program 2

    6/7

    Type reply (if required), press Enter.Restore operation in progress from user TESTUSER from job QPADEV0013. The

    command executed is: RSTOBJ OBJ(QXXXXX) SAVLIB(MYLIB) DEV(*SAVF)SAVF(MYSAVF).

    Restore operation in progress from user ANYUSER from job QPADEV0015. Thecommand executed is: RSTOBJ OBJ(QCLSRC) SAVLIB(YOURLIB) DEV(*SAVF)

    SAVF(ANYSAVF).

    Restore operation in progress from user QSYSOPR from job QPADEV0010. The

    command executed is: RSTOBJ OBJ(MYPROGRAM) SAVLIB(QGPL) DEV(*SAVF)SAVF(OPERSAVE).

    BottomF3=Exit F11=Remove a message F12=CancelF13=Remove all F16=Remove all except unanswered F24=More keys--------------------------------------------------------------------------------

    Time to Exit?IBM has added numerous exit points over the last several releases. As you becomefamiliar with command exit points and the customized processing that you can perform, you may want to delve further into more of the exit points. There are exit points for all kinds of things including Save and Restore functions, User Profile maintenance, and Network Access Control for functions such as FTP, ODBC, rem

    ote commands, and more. Third party software is often available for those of usthat do not want to write and maintain dozens of exit programs. You can use exitpoint programs to make your system administration tasks easier than they mighthave been in the past.

    Bookmark/Search this post with:Email this page Printer-friendly version Post new comment

    Your name:E-mail:The content of this field is kept private and will not be shown publicly.Comment: *Web page addresses and e-mail addresses turn into links automatically.Allowed HTML tags:

    Lines and paragraphs break automatically.More information about formatting options

    Math Question: * 1 + 4 =Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.

    Related LinksIBM-Supplied Help Text Generator for User-Written CommandsEnhance Security with CL Command Exit Point ProgramsManaging Restricted CommandsHaving Problems Passing Parameter Variables Using SBMJOB?

    Killer Club Tech

    ProVIP Sponsors

    ProVIP Sponsors

    Featured LinksIT Leaders Forum - Gartner, IBM, and more in Denver.

  • 7/27/2019 Control Cl Commands With Command Exit Program 2

    7/7

    Sponsored LinksGO GREEN: Reduce energy cost & data center space. Get IBM's free eKit.Automate iSeries Report Distribution as PDF, Excel, Forms... Try it Free!.Replacing Query/400? View "Elevator, Act 1" with Randall Munson.Hear how your peers have evolved their legacy apps with RAMP from LANSAModernize CA 2E and CA Plex applications automatically -- ADC AustinModernize to J2EE/JSF/RPGILE- with X-Analysis & Rational Webinar

    Footer Site LinksHome Subscribe Now Advertise Contact Us Feedback Terms & Conditions Trademarks Privacy Policy Copyright Penton Media