× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi Charles,

I recently added user profile swapping to our process for using QNTC to archive files onto a different server.

I pasted most of what I did into http://code.midrange.com/16beeae70c.html
There might be bits missing here and there, but that should be able to get you started.

Sometimes I'm not sure what I'm able to share, but since I got started based on Shannon's article on user swapping, I figured that was clearance enough. ;)

His article suggested that giving the common user *Use authority would be enough to get the user profile handle didn't seem to be enough. My method was to have the current user retrieve the user profile handle, and then save it so it could be swapped back to at a later time.

-Kurt

-----Original Message-----
From: midrange-l-bounces@xxxxxxxxxxxx [mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of Charles Pascoe
Sent: Friday, May 31, 2013 7:44 AM
To: 'Midrange Systems Technical Discussion'
Subject: RE: Swapping User Profiles within CLP via RPGLE using CALLP.

Hi Scott,

Thanks for this example.

Sorry about not responding quicker, but I got swamped at work the past couple of days. I will be looking at your solution and the one from Gary Monnier this coming weekend. What I am wanting to do, is from within the lengthy job stream that I have for creating a report that is to be converted into an XLS or XLSX document (which BTW we use DRV software to accomplish) is just prior to calling the DRV program - I would call the swap user program to swap to the common user; then call the convert to XLS program; then call the swap user program to swap back to the original user. I will be doing more testing this weekend and trying to finalize this process. When I finish, I will publish my results back to the Midrange Lists.

Thanks for your help - it is really appreciated,

Charles Pascoe
Programming Supervisor
cpascoe@xxxxxxxxxxxxxxxxx

-----Original Message-----
From: midrange-l-bounces@xxxxxxxxxxxx [mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of Scott Klement
Sent: May 30, 2013 11:07 PM
To: Midrange Systems Technical Discussion
Subject: Re: Swapping User Profiles within CLP via RPGLE using CALLP.


Hi Charles,

On 5/29/2013 10:48 PM, Charles Pascoe wrote:

The ultimate goal of this process (for us) is to imbed a call to the
program to swap users to a common user that exists on the Windows Network
and create an .XLS or .XLSX file from a spool file and write it out to a
Network Folder.


I haven't heard any further info from you on what you're trying to do (swap with password, or swap without?)

But here's a very simple example of using these APIs to swap without passwords. This is intended for a situation where the calling user has (at least) *USE authority to the "common" user profile, and so can swap to it without needing a password.

PGM

DCL VAR(&ORIGUSER) TYPE(*CHAR) LEN(12)
DCL VAR(&SFTPUSER) TYPE(*CHAR) LEN(12)

MONMSG (CPF0000 MCH0000) EXEC(GOTO DONE)

CALL PGM(QSYGETPH) PARM(*CURRENT *NOPWD &ORIGUSER)
CALL PGM(QSYGETPH) PARM(the-common-user *NOPWD &SFTPUSER)

CALL PGM(QWTSETP) PARM(&SFTPUSER)


/* ... RUN THE EXCEL STUFF HERE ... */


DONE: CALL PGM(QWTSETP) PARM(&ORIGUSER)

CALL PGM(QSYRLSPH) PARM(&ORIGUSER)
CALL PGM(QSYRLSPH) PARM(&SFTPUSER)

ENDPGM


As you can see... it's pretty simple, I didn't need another special program to implement this, I just called the APIs directly from the CL.

I start by calling QSYGETPH with *CURRENT to get a handle for the current userid -- that way, I don't have to worry about whether the common user has authority, because I have the handle before I swap. The current user always has authority to his own user profile :-)

Then, I get the profile handle for the common user with QSYGETPH.
(You'll need to replace 'the-common-user' with the proper user profile
name.) Assuming that you have at least *USE authority to that profile, you should be able to get the profile handle without needing a password.

Then, it calls QWTSETP to do the actual swap -- and we're set, we can do the special stuff that requires the common user profile.

After doing that, it calls QWTSETP to switch back to the original user profile, and releases both profile handles with QSYRLSPH, to prevent the possible memory leak.

It's important to note that there's a global MONMSG here so that if something should go wrong, it'll still swap back to the original profile
and release the profile handles. But, the error message will be sent
to the job log, too, so you'll be able to view the job log to see what went wrong.
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list To post a message email: MIDRANGE-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at http://archive.midrange.com/midrange-l.

--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list To post a message email: MIDRANGE-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at http://archive.midrange.com/midrange-l.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.