midrange.com code scratchpad
Name:
FTP exit points (Logon and Command)
Scriptlanguage:
Plain Text
Tabwidth:
4
Date:
10/10/2008 07:20:40 pm
IP:
Logged
Description:
2 exit point programs. The first one (FTPLOGON) controls whi can sign on to the server. The second one (FTPCMDREQ) controls which commands are used.
Code:
  1. FTPLOGON 
  2.  
  3.       // MAKE SURE TO USE ADOPTED AUTHORITY WITH OWNER OF QSECOFR                                   
  4.       //                                                                                            
  5.       //-----------------------------------------------------------------+                          
  6.       //.Name.....> FTPLOGON                                             +                          
  7.       //.Author...> Glenn Hopwood                   +                          
  8.       //.Date.....> 02/02/2007                                                     +                
  9.       //.Called By> QIBM_QTMF_SVR_LOGON exit point.                           +                     
  10.       //.Errors...>                                                      +                          
  11.       //.Recovery:>                                                      +                          
  12.       //.Timing...> On demand                                            +                          
  13.       //.Reports..>                                                      +                          
  14.       //.Calls....>                                                      +                          
  15.       //.Parm/LDA.> *see 'inputparms'                                                               
  16.       //.                                                                +                          
  17.       //.                                                                +                          
  18.       //.Narrative> Called on QIBM_QTMF_SVR_LOGON exit point.            +                          
  19.       //.  This program is called whenever someone logs onto regional's                             
  20.       //.  FTP server. (Look at WRKREGINF for the exit point above)      +                          
  21.       //.                                                                +                          
  22.       //.  We want to allow certain users to sign on and block others.   +                          
  23.       //.  In order to get the req'd user info we need to call an API    +                          
  24.       //.  called QSYRUSRI. From that we will get the user's 'class' and                            
  25.       //.  group profile.                                                +                          
  26.       //.----------------------------------------------------------------+                          
  27.       //.Revision:    Date:        Scan:         Pgmr:      Pj#:         +                          
  28.       //.             Reason/Function                                    +                          
  29.       //.                                                                +                          
  30.       //.----------------------------------------------------------------+                          
  31.       //.File Notes:                                                     +                          
  32.       //.                                                                +                          
  33.       //.Indicators:                                                     +                          
  34.       //.-----------                                                     +                          
  35.       //.  01 -                                                          +                          
  36.       //.                                                                +                          
  37.       //.----------------------------------------------------------------+                          
  38.      H option(*srcstmt : *nodebugio)                                                                                                                
  39.       //                                                                                            
  40.       //                                                                                            
  41.       //.----------------------------------------------------------------+                          
  42.       // Prototypes                                                                                 
  43.       //                                                                                            
  44.      Dinputparms       pr                  EXTPGM('FTPLOGON')                                       
  45.      D AppId                          9b 0                                                          
  46.      D UsrId                      32766A   options(*varsize)                                        
  47.      D UsrIdLen                       9b 0                                                          
  48.      D PsWrd                      32766A   options(*varsize)                                        
  49.      D PsWrdLen                       9b 0                                                          
  50.      D ClntIP                     32766A   options(*varsize)                                        
  51.      D ClntIPLen                      9b 0                                                          
  52.      D RetCode                        9b 0                                                          
  53.      D OvrUsrPrf                     10                                                             
  54.      D OvrPswrd                      10                                                             
  55.      D OvrIntLib                     10                                                             
  56.                                                                                                     
  57.      Dinputparms       pi                                                                           
  58.      D iAppId                         9b 0                                                          
  59.      D iUsrId                     32766A   options(*varsize)                                        
  60.      D iUsrIdLen                      9b 0                                                          
  61.      D iPsWrd                     32766A   options(*varsize)                                        
  62.      D iPsWrdLen                      9b 0                                                          
  63.      D iClntIP                    32766A   options(*varsize)                                        
  64.      D iClntIPLen                     9b 0                                                          
  65.      D oRetCode                       9b 0                                                          
  66.      D oOvrUsrPrf                    10                                                             
  67.      D oOvrPswrd                     10                                                             
  68.      D oOvrIntLib                    10                                                             
  69.                                                                                                     
  70.      DrtvUsrPrf        pr                  EXTPGM('QSYRUSRI')                                       
  71.      D xRcvVar                    32766a                                                            
  72.      D xRcvVarLen                     9b 0                                                          
  73.      D xFormat                        8a                                                            
  74.      D xUsrPrf                       10a                                                            
  75.      D xError                     32766a                                                            
  76.                                                                                                     
  77.       /copy qsysinc/qrpglesrc,qsyrusri                                                              
  78.       /copy qsysinc/qrpglesrc,qtes                                                                  
  79.       /copy qsysinc/qrpglesrc,qsy                                                                   
  80.                                                                                                     
  81.       //.----------------------------------------------------------------+                          
  82.       // Data Structures                                                                            
  83.       //.----------------------------------------------------------------+                          
  84.       // File Information Data Structure for Display information                                    
  85.      D*FIL#D$        E DS                                                                           
  86.       //                                                                                            
  87.       // Program Data Structure for Display information                                             
  88.      D UTP#DS        ESDS                                                                           
  89.                                                                                                     
  90.      D rtnData         ds                  qualified based(prtnData)                                
  91.      D  data                               likeds(QSYI0200)                                         
  92.      D  extra                      1000a                                                            
  93.       //.----------------------------------------------------------------+                          
  94.       // Variables                                                                                  
  95.       //              **  constants **                                                              
  96.       //              **  keys  **                                                                                                                                 
  97.       //              **  work fields  **                                                           
  98.      D prtnData        s               *                                                            
  99.      D wRcvVar         s          32766a                                                            
  100.      D wRcvVarLen      s              9b 0 inz(%len(rtnData))                                       
  101.      D wFormat         s              8a   inz('USRI0200')                                          
  102.      D wUsrPrf         s             10a                                                            
  103.      D wError          s          32766a                                                            
  104.      D wData           s             30a                                                            
  105.       //              **  hold fields  **                                                           
  106.       //              **  date fields  **                                                           
  107.                                                                                                     
  108.       /FREE                                                                                         
  109.                                                                                                                                                                            
  110.                                                                                                    
  111.        // Retrieve user profile data                                                                
  112.        exsr @RTVUSRINF;                                                                             
  113.                                                                                                     
  114.        // Don't allow any Q* profiles to log on                                                     
  115.        if %subst(FUSRID:1:1) = 'Q';                                                                 
  116.          oRetCode = 0;                                                                              
  117.                                                                                                     
  118.        // Any class other then *USER is OK (*PGMR, *SECOFR, etc..)                                  
  119.        elseif rtnData.data.QSYUC <> '*USER' and                                                     
  120.               rtnData.data.QSYUC <> '*NONE' and                                                     
  121.               rtnData.data.QSYUC <> ' ';                                                            
  122.          oRetCode = 1;                                                                              
  123.                                                                                                     
  124.        // Group profile of 'FTPUSER' is OK                                                          
  125.        elseif rtnData.data.QSYGP01 = 'FTPUSER';                                                     
  126.          oRetCode = 1;                                                                              
  127.                                                                                                     
  128.        // Default to 'NO'                                                                           
  129.        else;                                                                                        
  130.          oRetCode = 0;                                                                              
  131.                                                                                                     
  132.        endif;                                                                                       
  133.                                                                                                                                                                         
  134.                                                                                                     
  135.        *inlr = *on;                                                                                 
  136.        return;                                                                                      
  137.                                                                                                     
  138.        //-------------------------------------------------------------------                        
  139.        // @RTVUSRINF                                                                                
  140.        //-------------------------------------------------------------------                        
  141.        begsr @RTVUSRINF;                                                                            
  142.                                                                                                     
  143.         wUsrPrf = FUSRID;                                                                           
  144.                                                                                                     
  145.         // Get user profile data in the format specified in wFormat                                 
  146.         callp rtvUsrPrf(wRcvVar   :                                                                 
  147.                         wRcvVarLen:                                                                 
  148.                         wFormat   :                                                                 
  149.                         wUsrPrf   :                                                                 
  150.                         wError     );                                                               
  151.                                                                                                     
  152.         // Overlay the basing pointer of the rtnData DS to the                                      
  153.         //  receiver variable wRcvVar                                                               
  154.         prtnData = %addr(wRcvVar);                                                                  
  155.                                                                                                     
  156.        endsr;                                                                                       
  157.                                                                                                     
  158.       /END-FREE  
  159.  
  160. FTPCMDREQ - This program also logs the attempts see FTPCMDREQF below
  161.  
  162.       //-----------------------------------------------------------------+                          
  163.       //.Name.....>                                                      +                          
  164.       //.Author...> Glenn Hopwood (Electric Mobility)                    +                          
  165.       //.Date.....>                                                                +                
  166.       //.Called By>                                                           +                     
  167.       //.Errors...>                                                      +                          
  168.       //.Recovery:>                                                      +                          
  169.       //.Timing...> On demand                                            +                          
  170.       //.Reports..>                                                      +                          
  171.       //.Calls....>                                                      +                          
  172.       //.Parm/LDA.>                                                      +                          
  173.       //.                                                                +                          
  174.       //.                                                                +                          
  175.       //.Narrative> Called on QIBM_QTMF_SERVER_REQ exit point.           +                          
  176.       //.                                                                +                          
  177.       //.                                                                +                          
  178.       //.----------------------------------------------------------------+                          
  179.       //.Revision:    Date:        Scan:         Pgmr:      Pj#:         +                          
  180.       //.             Reason/Function                                    +                          
  181.       //.                                                                +                          
  182.       //.----------------------------------------------------------------+                          
  183.       //.File Notes:                                                     +                          
  184.       //.                                                                +                          
  185.       //.Indicators:                                                     +                          
  186.       //.-----------                                                     +                          
  187.       //.  01 -                                                          +                          
  188.       //.                                                                +                          
  189.       //.----------------------------------------------------------------+                          
  190.      H option(*srcstmt : *nodebugio)                                                                
  191.       //                                                                                            
  192.       //                                                                                            
  193.      FFTPCMDREQFUF A E           k Disk                                                             
  194.       //                                                                                            
  195.       //                                                                                            
  196.       //.----------------------------------------------------------------+                          
  197.       // Prototypes                                                                                 
  198.       //                                                                                            
  199.      Dinputparms       pr                  EXTPGM('FTPCMDREQ')                                      
  200.      D AppId                          9b 0                                                          
  201.      D OpId                           9b 0                                                          
  202.      D UsrId                         10A                                                            
  203.      D ClntIP                     32766A   options(*varsize)                                        
  204.      D ClntIPLen                      9b 0                                                          
  205.      D OpInfo                     32766A   options(*varsize)                                        
  206.      D OpInfoLen                      9b 0                                                          
  207.      D RetCode                        9b 0                                                          
  208.                                                                                                     
  209.      Dinputparms       pi                                                                           
  210.      D iAppId                         9b 0                                                          
  211.      D iOpId                          9b 0                                                          
  212.      D iUsrId                        10A                                                            
  213.      D iClntIP                    32766A   options(*varsize)                                        
  214.      D iClntIPLen                     9b 0                                                          
  215.      D iOpInfo                    32766A   options(*varsize)                                        
  216.      D iOpInfoLen                     9b 0                                                          
  217.      D oRetCode                       9b 0                                                          
  218.                                                                                                     
  219.      DrtvUsrPrf        pr                  EXTPGM('QSYRUSRI')                                       
  220.      D xRcvVar                    32766a                                                            
  221.      D xRcvVarLen                     9b 0                                                          
  222.      D xFormat                        8a                                                            
  223.      D xUsrPrf                       10a                                                            
  224.      D xError                     32766a                                                            
  225.                                                                                                     
  226.       /copy qsysinc/qrpglesrc,qsyrusri                                                              
  227.       /copy qsysinc/qrpglesrc,qtes                                                                  
  228.       /copy qsysinc/qrpglesrc,qsy                                                                   
  229.                                                                                                     
  230.       //.----------------------------------------------------------------+                          
  231.       // Data Structures                                                                            
  232.       //.----------------------------------------------------------------+                          
  233.       // File Information Data Structure for Display information                                    
  234.      D*FIL#D$        E DS                                                                           
  235.       //                                                                                            
  236.       // Program Data Structure for Display information                                             
  237.      D UTP#DS        ESDS                                                                           
  238.                                                                                                     
  239.      D rtnData         ds                  qualified based(prtnData)                                
  240.      D  data                               likeds(QSYI0300)                                         
  241.      D  extra                      1000a                                                            
  242.                                                                                                     
  243.      D homedir         ds                  qualified based(pHomeDir)                                
  244.      D  info                               likeds(QSYPI)                                            
  245.      D  str                        1000c   varying                                                  
  246.       //.----------------------------------------------------------------+                          
  247.       // Variables                                                                                  
  248.       //              **  constants **                                                              
  249.      D STR_SESSION     s              9b 0 inz(0)                                                   
  250.      D CRTDIR          s              9b 0 inz(1)                                                   
  251.      D DLTDIR          s              9b 0 inz(2)                                                   
  252.      D CHGCURDIR       s              9b 0 inz(3)                                                   
  253.      D LSTDIR          s              9b 0 inz(4)                                                   
  254.      D DLTF            s              9b 0 inz(5)                                                   
  255.      D SNDF            s              9b 0 inz(6)                                                   
  256.      D RCVF            s              9b 0 inz(7)                                                   
  257.      D RNMF            s              9b 0 inz(8)                                                   
  258.      D EXEC_CL         s              9b 0 inz(9)                                                   
  259.      D NEVERALLOW      s              9b 0 inz(-1)                                                  
  260.      D REJECT          s              9b 0 inz(0)                                                   
  261.      D ALLOW           s              9b 0 inz(1)                                                   
  262.      D ALWYSALLOW      s              9b 0 inz(2)                                                   
  263.       //              **  keys  **                                                                  
  264.      D*keyPRDNO        s             15                                                             
  265.       //              **  work fields  **                                                           
  266.      D prtnData        s               *                                                            
  267.      D wRcvVar         s          32766a                                                            
  268.      D wRcvVarLen      s              9b 0 inz(%len(rtnData))                                       
  269.      D wFormat         s              8a   inz('USRI0300')                                          
  270.      D wUsrPrf         s             10a                                                            
  271.      D wError          s          32766a                                                            
  272.      D wHomeDir        s          32766    varying                                                  
  273.      D wHomeDirL       s              9  0                                                          
  274.      D hldHomeD        s           1000    varying                                                  
  275.      D i               s              5  0                                                          
  276.       //              **  hold fields  **                                                           
  277.       //              **  date fields  **                                                           
  278.      D Today           s               d   inz(*sys)                                                
  279.                                                                                                     
  280.       /FREE                                                                                         
  281.                                                                                                     
  282.        exsr @RTVUSRINF;                                                                             
  283.                                                                                                     
  284.        // Default value                                                                             
  285.        oRetCode = REJECT;                                                                           
  286.                                                                                                     
  287.        // Decide what to do based on iOpId (Operation ID) and some user data                        
  288.        select;                                                                                      
  289.                                                                                                     
  290.          // always allow a session - assume the LOGON exit point is working                         
  291.          when iOpId = STR_SESSION;                                                                  
  292.            oRetCode = ALLOW;                                                                        
  293.                                                                                                     
  294.          // If the user's class is more then *user, allow all                                       
  295.          when rtnData.data.QSYUC00 = '*SECOFR' or                                                   
  296.               rtnData.data.QSYUC00 = '*SECADM' or                                                   
  297.               rtnData.data.QSYUC00 = '*PGMR'   or                                                   
  298.               rtnData.data.QSYUC00 = '*SYSOPR';                                                     
  299.            oRetCode = ALWYSALLOW;                                                                   
  300.                                                                                                     
  301.          // NEVER ALLOW a non-pgmr, secofr or sysopr user class to run cmds                         
  302.          when iOpId = EXEC_CL;                                                                      
  303.            oRetCode = NEVERALLOW;                                                                   
  304.                                                                                                     
  305.          // All others...see subroutine for comments                                                
  306.          other;                                                                                     
  307.            exsr @CKHOMEDIR;                                                                         
  308.                                                                                                     
  309.        endsl;                                                                                       
  310.                                                                                                     
  311.        exsr @WRTLOG;                                                                                
  312.                                                                                                     
  313.        *inlr = *on;                                                                                 
  314.        return;                                                                                      
  315.                                                                                                     
  316.        //-------------------------------------------------------------------                        
  317.        // @RTVUSRINF                                                                                
  318.        //-------------------------------------------------------------------                        
  319.        begsr @RTVUSRINF;                                                                            
  320.                                                                                                     
  321.         wUsrPrf = iUsrId;                                                                           
  322.                                                                                                     
  323.         // Get user profile data in the format specified in wFormat                                 
  324.         callp rtvUsrPrf(wRcvVar   :                                                                 
  325.                         wRcvVarLen:                                                                 
  326.                         wFormat   :                                                                 
  327.                         wUsrPrf   :                                                                 
  328.                         wError     );                                                               
  329.                                                                                                     
  330.         // Overlay the basing pointer of the rtnData DS to the                                      
  331.         //  receiver variable wRcvVar                                                               
  332.         prtnData = %addr(wRcvVar);                                                                  
  333.                                                                                                     
  334.         // Overlay the basing pointer of the homedir DS to the                                      
  335.         //  proper place in the receiver variable wRcvVar                                           
  336.         pHomeDir = %addr(wRcvVar) + rtnData.data.QSYHDO;                                            
  337.         wHomeDir  = %char(%trim(homedir.str));                                                      
  338.         wHomeDirL = homedir.info.QSYBYTES/2;                                                        
  339.                                                                                                     
  340.         hldHomeD = %subst(wHomeDir:1:wHomeDirL-1);                                                  
  341.                                                                                                     
  342.        endsr;                                                                                       
  343.                                                                                                     
  344.        //-------------------------------------------------------------------                        
  345.        // @CKHOMEDIR - We will allow a user to do just about anything, as                           
  346.        //  long as it is only in their own home directory.                                          
  347.        //    1 - Retrieve the user's home directory                                                 
  348.        //    2 - Compare it to the operation specific info                                          
  349.        //                                                                                           
  350.        //  if the user is trying to do something to an object not contained                         
  351.        //   in their home dir, don't allow it.                                                      
  352.        //  if the user is trying to do a DLTDIR to their own home dir,                              
  353.        //   don't allow it.                                                                         
  354.        //-------------------------------------------------------------------                        
  355.        begsr @CKHOMEDIR;                                                                            
  356.                                                                                                     
  357.         // if the length of the string containing the op specific data                              
  358.         //  is shorter then the home dir, reject                                                    
  359.         if %len(%trim(wHomeDir)) > %len(%trim(iOpInfo));                                            
  360.           oRetCode = REJECT;                                                                        
  361.           leavesr;                                                                                  
  362.         endif;                                                                                      
  363.                                                                                                     
  364.         // Scan for the user's home dir in the op specific data                                     
  365.         i = %scan(%trim(hldHomeD):%trim(iOpInfo));                                                  
  366.                                                                                                     
  367.         // if iOpInfo doesn't contain the users home dir, reject                                    
  368.         if i <= 0;                                                                                  
  369.           oRetCode = REJECT;                                                                        
  370.           leavesr;                                                                                  
  371.         endif;                                                                                      
  372.                                                                                                     
  373.         // If the op ID is DLTDIR and the op specific data is the same                              
  374.         //  length as the wHomeDir then they are trying to delete their                             
  375.         //  home dir                                                                                
  376.         if %len(%trim(wHomeDir)) = %len(%trim(iOpInfo)) and                                         
  377.            iOpId = DLTDIR;                                                                          
  378.           oRetCode = REJECT;                                                                        
  379.           leavesr;                                                                                  
  380.         endif;                                                                                      
  381.                                                                                                     
  382.         // If you passed the tests above....                                                        
  383.         oRetCode = ALLOW;                                                                           
  384.                                                                                                     
  385.        endsr;                                                                                       
  386.                                                                                                     
  387.        //-------------------------------------------------------------------                        
  388.        // @WRTLOG                                                                                   
  389.        //-------------------------------------------------------------------                        
  390.        begsr @WRTLOG;                                                                               
  391.                                                                                                     
  392.         chain (iUsrId) FTPCMDREQF;                                                                  
  393.                                                                                                     
  394.         FAPPID   = iAppId;                                                                          
  395.         FOPID    = iOpId;                                                                           
  396.         FUSRID   = iUsrId;                                                                          
  397.         FCLNTIP  = %subst(iClntIP:1:iClntIPLen) + ' HD:' + %trim(hldHomeD);                         
  398.         FOPER    = iOpInfo;                                                                         
  399.         FDATE    = %date();                                                                         
  400.         FTIME    = %time();                                                                         
  401.         FRETCODE = oRetCode;                                                                        
  402.                                                                                                     
  403.         if %found(FTPCMDREQF);                                                                      
  404.           update FTPCMDREQR;                                                                        
  405.         else;                                                                                       
  406.           write FTPCMDREQR;                                                                         
  407.         endif;                                                                                      
  408.                                                                                                     
  409.        endsr;                                                                                       
  410.                                                                                                     
  411.       /END-FREE                                                                                     
  412.  
  413.                 R FTPCMDREQR                                                                        
  414.       *                                                                                             
  415.                   FUSRID        10          TEXT('User ID')                                         
  416.                   FAPPID         9B 0       TEXT('App ID')                                          
  417.                   FOPID          9B 0       TEXT('Operation ID')                                    
  418.                   FRETCODE       9B 0       TEXT('Operation ID')                                    
  419.                   FCLNTIP       50          TEXT('Client IP')                                       
  420.                   FOPER        256          TEXT('Operation Specifics')                             
  421.       *                                                                                             
  422.                   FDATE           L                                                                 
  423.                   FTIME           T                                                                 
  424.       *                                                                                             
  425.                 K FUSRID                                                                            
  426.  
  427.  
  428.  
© 2004-2019 by midrange.com generated in 0.013s valid xhtml & css