IBM i Global

IBM i Global

Connect, learn, share, and engage with IBM Power.

 View Only
  • 1.  CL Program Error

    Posted Fri September 01, 2023 11:51 AM

    Hello everyone

    I am having an issue with a CL program that allows a user to reset their password. So when I run the command, in this case, RESETPWD, I get an error at the CHGUSRPRF command. I have the declared value, &USRPRF, but the command is expecting a specific user profile. How do I code this so any user can run the command and be able to change their password?



    ------------------------------
    Michael Ruth
    ------------------------------



  • 2.  RE: CL Program Error

    Posted Fri September 01, 2023 08:30 PM

    Dear Michael

    The error you posted is not enough.  When you encounter the program crash, you should run DSPJOBLOG OUTPUT(*PRINT) and use IBM i ACS --> Printer Output to download the QPJOBLOG file to a text file in your PC and attach it for us to see all the details.

    You should also post the entire code.  I think one key question is how do you supply the value for &USRPRF variable? 



    ------------------------------
    Chance favors only the prepared mind.
    -- Louis Pasteur
    ------------------------------
    Satid S.
    ------------------------------



  • 3.  RE: CL Program Error

    Posted Sun September 03, 2023 06:33 AM

    A couple of things to be aware of. 

    You say allow the command is to allow a user to reset "their" password... all they need to do is use the command CHGPWD.  

    I notice in the command that you are also enabling the profile - this would not be required for someone to change their own password as they'd have to be signed on to run the command and, by default, their profile would be enabled.

    If you expecting users to run this command for other users, you need to be very careful who you give the access to.  To change another persons profile requires elevated authority over the profile being amended and it's usual that the person doing the reset should not always have elevated authorities so it is usually done by changing the program to run under the owners authority and change the owner of the program to a profile with suitable authorities to amend other profiles.

    A word of caution with this type of command is that you should build in some validation checks to stop the user from resetting the password of profiles with even more authority - eg. QSECOFR.   For example, assuming your general users don't have many special authorities (maybe *SPLCTL and *JOBCTL), your code could retrieve the special authorities of the target profile and see if they have anything more than one of your general users. If the target profile does, then reject the request to reset the password. 

    We have developed a CL program for our service desk, with a display screen - not just directly using the CHGUSRPRF command so, for our errors, we set an indicator and display a message to the user. In the sample code below, you could just send the user a message directly instead of setting an indicator.

    Also, we retrieve the group and supplemental groups and make sure the target user is in a specific group. You don't need to do that, it's just something specific that we do.

    Tony.

    /*  Retrieve user profile details  */                                                                 
            RTVUSRPRF  USRPRF(&P1USER) SPCAUT(&P1AUT) +                      
                              GRPPRF(&P1GRP) TEXT(&P1TEXT) +                 
                              USRCLS(&P1CLAS) PWDEXP(&P1EXP) +               
                              STATUS(&P1STAT) SUPGRPPRF(&P1SUPGRP)           
                                                                             
    /*  See if user has *ALLOBJ authorities - set on error - IND 82 */ 
           CALL  PGM(QCLSCAN) PARM(&P1AUT &STRLEN &STRPOS +                  
                      '*ALLOBJ' &PATLEN &BLANK &BLANK &BLANK &RESULT)        
           IF  COND(&RESULT *NE 0) THEN(DO)                                  
                 CHGVAR     VAR(&IN82) VALUE('1')                            
                 GOTO       CMDLBL(DISPLAY)                                  
                 ENDDO                                                       
     
    /*  See if user has *SECADM authorities - set on error   TD002 - IND 82       */
           CALL  PGM(QCLSCAN) PARM(&P1AUT &STRLEN &STRPOS +                         
                  '*SECADM' &PATLEN &BLANK &BLANK &BLANK &RESULT)                   
           IF  COND(&RESULT *NE 0) THEN(DO)                                         
                 CHGVAR     VAR(&IN82) VALUE('1')                                   
                 GOTO       CMDLBL(DISPLAY)                                         
                 ENDDO      
     
    /*  See if user has XXGRPXX in Sup.Group or group profile  */
           CALL  PGM(QCLSCAN) PARM(&P1SUPGRP &STRLEN2 &STRPOS +              
                      'XXGRPXX' &PATLEN2 &BLANK &BLANK &BLANK &RESULT)     
           IF  COND(&RESULT *EQ 0 *AND &P1GRP¬='XXGRPXX') THEN(DO)         
                 CHGVAR     VAR(&IN71) VALUE('1')                            
                 ENDDO     

     



    ------------------------------
    Tony Davis
    ------------------------------



  • 4.  RE: CL Program Error

    Posted Sun September 03, 2023 10:09 PM
    Edited by Satid Singkorapoom Sun September 03, 2023 10:10 PM

    On my second thought, a more simplified way (no need to write a program) is for the system admin to run CHGUSRPRF against the profile that needs a password change and specify PWDEXP(*YES) with or without STATUS(*ENABLED) as needed and let that user sign on and be prompted by the system to change the password. 



    ------------------------------
    Chance favors only the prepared mind.
    -- Louis Pasteur
    ------------------------------
    Satid S.
    ------------------------------



  • 5.  RE: CL Program Error

    Posted Mon September 04, 2023 01:57 AM

    Hi Michael, 
    In order to be able to support you in solving your problem, we need the messages that appear in the JOBLOG before the MSG CPA0701. Only these messages provide information about the error. Would you please add this information to your post.
    Thanks 
    Thomas



    ------------------------------
    Thomas Goetze
    ------------------------------