ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

ID Swap mystery

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • ID Swap mystery

    Good morning (or afternoon, or evening )

    I'm working on a request where a third-party software (Thingworx) is being used to perform a transaction on the ISeries. In order to do this, they call a procedure and pass a user ID, password, and the parameters for the transaction.

    The first thing I do is swap to the new ID.

    The code snippet below works if I use it in iNavigator (with a test ID), or when the user uses a test ID; however, whenever he tries to use his own ID, he gets Invalid Credentials. When he uses any other user ID, he gets Invalid Credentials.

    No one at my company has a lot of experience with using these. Does anyone have any suggestions for us? Please? ANY hints or thoughts will be greatly appreciated!

    PHP Code:
          **** API to get the profile handle (current user/swapping "from" userinc
         D GetCurUsr       PR                  ExtPgm
    ('QSYGETPH')
         
    D   Current                     10A   options(*varsize) const
         
    D   Currpass                    10A   options(*varsize) const
         
    D   CurHandle                   12A

          
    **** API to get the profile handle
         D GetProfile      PR                  ExtPgm
    ('QSYGETPH')
         
    D   UserID                      10A   options(*varsize) const
         
    D   Password                    10A   options(*varsize) const
         
    D   NewHandle                   12A
         D   ErrorCode                  256A   options
    (*varsize)
         
    D  len                          10i 0 const
         
    D  CCSID                        10i 0 const                         



    //  SUBROUTINES --->
           
    BEGSR $GetProfile;
           
    //  * Get profile handle for current user  INC0306416
              
    Callp GetCurUsr('*CURRENT  ' :CURPWD :OLDHANDLE);

             If        
    ErrBytesA 0;
                 
    // handle "invalid user profile" error
               
    OutMsg 'OLD HANDLE PROBLEM! ' ErrMsgID  ;
               
    wkERROR 'Y';
             Endif;


             
    // authenticate using API QSYGETPH
             
    callp     GetProfile(%TRIMR(InappID) : %TRIMR(INAUTH1) : newHandle:
                                                   
    Errords );
             If        
    ErrBytesA 0;
                 
    // handle "invalid user profile" error
               
    OutMsg 'INVALID CREDENTIALS ' ErrMsgID ' ' + %TRIMR(INAPPID) ;
               
    wkERROR 'Y';
             Endif;

           
    ENDSR

  • #2
    Hi Melissa,

    You say that the code works in iNavigator. I don't understand what you mean? How do you call a program from iNavigator?

    You say that he gets "Invalid Credentials" with either his own ID or any other ID. Have you run this in debug and made sure the inputs to the API are correct? You appear to be using options(*varsize) incorrectly, which worries me... but, since you are using stuff like %TRIM to make it into an expression, it seems like it should still give you the correct result, even though you've coded it wrong. What is the contents of ErrorDS when GetProfile() fails?

    Also, I noticed that the first call to GetCurUsr() does not do error handling properly. It does not pass any error data structure, yet it seems to be trying to check a field named ErrBytesA, which presumably is from an error data structure? Since the DS wasn't passed, that'll never be set. This doesn't relate to the current problem since GetCurUsr seems to be working, but I wanted to point it out.

    Comment


    • #3
      Scott,

      Thank you - I fixed the error handling. I'll revisit *VARSIZE so I understand it. I guess I really don't.

      The good news is that I've figured out part of my problem. It was really a stupid error (which I make a lot of!). The password length in GetProfile! I had it coded to 8 when I was testing with my ID, but the other ID was 9! DUH. Now I have that as a variable so it works much better.

      Oh - and the way I test this using iNavigator is to call the procedure using SQL - which is what the end user does with Thingworx.

      My next issue with this is getting the library list set up. Silly me, I thought that I could get the JOBD information, but our security is set up by GROUPS so the library list in the JOBD doesn't match the way the groups are set up. (That's not a question - I haven't started looking at that yet )

      Thank you again, for all your good advice, your time, and your help - your examples and documents have been a life-saver for me ! (Well, a job-saver, anyway)

      I hope you and yours are safe and well.

      Comment


      • #4
        *VARSIZE means the caller can pass a smaller value (e.g. a variable that is only char(5)) and the compiler won't complain. But the receiving program is therefore responsible for knowing how much to actually use, and not trying to read past the end. E.g. if you were to do this:
        Code:
              // Note is only 5 chars
             D  myPassword     S              5A
        
                  Callp GetCurUsr('*CURRENT  ' :myPassword :OLDHANDLE);
        Then the compiler will let you pass the 5 char myPassword variable into the 10 char Currpass parameter. But if the GetCurUsr API is not programmed to account for that parameter being *varsize then it will assume the 5 bytes of memory after myPassword's location are part of myPassword, when in fact they are not and could be anything.

        This is (I think) why many IBM APIs that do support *VARSIZE (like QCMDEXC) have corresponding length parameters. So they can know how much of the parameter they are allowed to use.

        Comment


        • #5
          OH! Thank you. That helps. I think I'm getting there. That's why it worked when I added the %Trim, but there could be times when that doesn't work. I'll go back and re-read some of my documents and examples I was using and double-check my code.

          It's times like these my degree in radio and television production just doesn't help!
          But before y'all give up on me - I've been a developer since 1998 - after a great on-the-job training program at the former American States Insurance. Mostly after that, it's been trial by fire, though. (Sometimes the documentation still confuses me.)

          Thank you once again.

          Comment

          Working...
          X