26
Tue, Nov
1 New Articles

Keeping User Profiles *NSYNC

Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

There are three words that you need to remember when dealing with any computer system, including the iSeries 400. They are backup, backup, and backup. If you want a restful night’s sleep, you’d better have a good backup of your data files, programs, and operating system.

But there are other management issues. For instance, if you are an application service provider (ASP), redundancy is an important issue. In today’s computing environment, downtime is not acceptable. If your customers experience an interruption in service, they may be someone else’s customers tomorrow. Consequently, if disaster strikes and your computer goes down, you need to be ready to automatically switch to an alternate server and continue running as if nothing had happened. In order to accomplish this lofty goal, you will need to find ways to replicate software, data, and other system objects, such as user profiles. In this article, we will deal with the last of these items.

User Profiles

One of the many challenges we addressed in our quest to become an ASP was how we were going to keep identical user profiles on separate iSeries 400 computers. In other words, when we added a new user to our primary system, we wanted that system to automatically call a program that would add the same user profile to our backup system. We accomplished this goal using two distinctive and infrequently used features of the iSeries 400 computer: exit points and remote data queues.

In this article, we will cover the basics of using an exit point to call a program automatically whenever a user performs a certain function. In our example, this will occur whenever a new user profile is added to the system. We will also discuss how you can use remote data queues to pass information from one system to another automatically. In our case, we will use remote data queues to pass the information about a newly created user profile from the primary system to a backup system.

Here We Go

Right off the bat, we are going to assume that you already have two iSeries 400 computers connected and “talking” to one another. We are not going to cover the mechanics of doing this.


When replicating user profiles on the iSeries 400, the first challenge is determining when a user profile is created on the primary system. One approach we could employ is to create a program that lists all of the user profiles on both systems to compare the differences. But this method would likely not run in a real-time environment, and, therefore, the user profiles on the two systems would rarely be in sync all of the time. The user profiles would be synchronized only up to the last date and time at which the synchronization program ran.

We wanted the system to run the synchronization program automatically whenever someone added a new user to the system. Fortunately, there is an exit point that provides this very capability. An exit point is a place (or point) in a system process at which the system will pause and call a user-written program. This user-written program is called an exit program. Figure 1 shows the partial code of an exit program that will get called every time a new user is added to the primary system.

You may be asking yourself how we told the system to run our program at a predefined exit point. The answer is that we do it by registering the exit point. Take a moment to look at the following command:

ADDEXITPGM +

EXITPNT(QIBM_QSY_CRT_PROFILE) +

FORMAT(CRTP0100) +

PGMNBR(*LOW) +

PGM(xxx/PGM001RG)

The Add Exit Program (ADDEXITPGM) command causes the sample program (PGM001RG) to execute whenever a new user profile is created.

Whether you were aware of it or not, there are many exit points on your system. If you are curious, simply run the Work with Registration Information (WRKREGINF) command. You will see a rather substantial list of exit points. You can attach exit programs to any of the exit points you see on this substantial list. Note that you could have more than one program called at each exit point. The sequence number you assign when you register your program will determine the order in which the exit programs get called.

Notice that we assigned the exit program in our example to the QIBM_QSY_CRT_PROFILE exit point. That is the exit point for which a user profile is created on your system. We chose this exit point because we were only interested in running our program when a user profile was added to the primary system. But also note the QSY_DLT_PROFILE and the QSY_CHG_PROFILE exit points. What do you suppose these exit points control? Depending on your environment, you may want to write your own exit programs for these delete user profile and change user profile exit points.

Boogie (with Exit Points)

The code snippet shown in Figure 1 is a subset of the complete program available at www.midrangecomputing.com/mc. Take a closer look at how this program works. The InData parameter that the system passes to the program is a 38-byte data structure in the format that this exit point delivers data to a program. You will find that part of the fun when dealing with exit points is “discovering” the documentation that defines the format of the parameters. There is not a single, central place that defines all of the exit points and their parameters. You have to dig through the manuals to find the gems.

In this particular case, the gem is the user profile name located in the last 10 positions of the data structure. Armed with this critical piece of information, we call the QSYRUSRI API, passing the user profile name to it and receiving back almost all the information in the user profile. The returned information is placed into a receiver variable (Receiver1) that we send over to the second machine using the QSNDDTAQ API. We’ll cover this technique in more detail in this article.


In Figure 1, you will see that the program calls the QSYRUSRI API twice. That’s because we are using an API handling technique that we have aptly termed the “double-call technique.” The reason we employ the double-call technique is that we don’t really know what the length of the receiver variable should be. But this API, like many others, will tell you what the length needs to be. All you need to do is to shelve that macho instinct for a minute and ask for input.

And that is exactly what we do when we perform the first call to the API. We initially specify the size of the receiver variable as 8 bytes. In looking at the definition of this data structure, you will see that it is defined as two 10-digit integers, BytesRtn1 and BytesAvl1. After the first call to the API, BytesAvl1 will contain the number of bytes the API would return to the receiver variable if it could. So, we use the ALLOC op code and allocate the correct number of bytes for the receiver variable. We then call the API a second time using the returned information as the size of the receiver variable. This double-call technique is good to know when you’re dealing with many of the APIs that the system provides.

You might have noticed that we said the QSYUSRI API returns almost all of the information about a user profile. The missing piece of information is the password. (Wouldn’t you know it? Why would we need that?) So, the next thing the exit program must do is retrieve the password for the user profile.

You’re probably thinking, “I can get the password for a user profile? Wow! I can be king (or queen) of the computer! I can sign on as anybody and do anything! Way cool!” Well, we hate to burst your bubble, but it doesn’t work like that. There is an API that retrieves the password for a given user profile. That API is QSYRUPWD. The catch here is that it retrieves the encrypted form of the password. You cannot view it, so forget about being the king of all you survey. The only thing you can do with the encrypted form of the password is pass it along to the QSYSUPWD API, which will set the password for the user profile to the encrypted password. Also, you can only use the password on a user profile that has the same name as the one from which it was retrieved.

The program calls the RtvEncPwd procedure to retrieve the password of the user profile. This procedure accepts the user profile name, uses the double-call technique with the QSYRUPWD API, and then returns the data structure (with the encrypted password and user profile name) back to the caller of the procedure. We then concatenate the user profile information to the end of this password structure and write it to a remote data queue using the QSNDDTAQ API.

Primary to Backup: I Just Wanna Be with You

Let’s talk about data queues. A data queue is a straight line between two points. You put information in the queue on one end, and you can take that information off the queue on the other end. What’s especially appealing about data queues is that each end of the queue can be on a different computer! Your program doesn’t know or care. Take a moment to examine the following command to see how you go about creating a remote data queue:

CRTDTAQ +

DTAQ(QGPL/PASSUSER) +

TYPE(*DDM) +

MAXLEN(1000) +

SEQ(*KEYED) +

KEYLEN(4) +

RMTDTAQ(QGPL/PASSUSERRM) +

RMTLOCNAME(RMTNAME)

Did you notice the type parameter we used on the Create Data Queue (CRTDTAQ) command? We have specified a type of Distributed Data Management (DDM). As the name implies, the DDM value for the type parameter tells your AS/400 that the data queue being


created is really just a “pointer” to a data queue that will be located on a different system. When you create a DDM data queue, you must specify the name of the other computer using the Remote Location Name (RMTLOCNAME) parameter. In our example, we called the other computer RMTNAME.

Just as the RMTLOCNAME parameter told the system which computer the remote data queue resides on, the Remote Data Queue (RMTDTAQ) parameter tells the local machine the physical name and location of the data queue as it is defined on the remote system. In other words, this is where we specify the name of the data queue on the other computer that the DDM “pointer” will connect with. If you want this to work, you will need to create the standard (non-DDM) data queue on the other computer, and it must use the same name and location that you specified on the RMTDTAQ parameter.

That’s all there is to it on the primary computer. We have set up an exit point that will call the program whenever a user profile is created. We have also set up a remote data queue that the program will use to send information about the newly created user profile to the secondary machine. All that remains is to have a program take the information off the data queue and create a duplicate user profile on the secondary machine. Figure 2 shows most of the code that accomplishes this. You can find the complete program on the Midrange Computing Web site at www.midrangecomputing.com/mc.

The program on the remote system uses the QRCVDTAQ API to read the information from the data queue. It then formats a Create User Profile (CRTUSRPRF ) command and executes the command using the “system” procedure. If the program encounters an error, it uses the display op code to display the error number on the screen. If the program encounters no errors, it creates the user profile. All that remains is to set the correct password for it. We pull the encrypted password data structure off the data queue and use the QSYSUPWD API to set the correct password for the newly created user profile.

Bye, Bye, Bye

We have covered quite a few concepts and techniques in this article—remote data queues, exit points, and the API double-call technique for determining the proper length for a receiver variable. The combination of these functions will help you keep your user profiles in sync.

We would also like to apologize for the subtitles. Part of the price we pay for being parents of grade-school-aged daughters is feeling obligated to listen to “classics” sung by groups like *NSYNC. It really could have been worse: We could have made references to Britney Spears’ classic version of “I Can’t Get No Satisfaction.”


d Data S 1000
d DataQue S 10 inz('PASSUSERRM')
d DataQueLib S 10 inz('QGPL ')
d DataLength S 5 0 inz(1000)
D FormatName S 8 inz('USRI0300')
D InData S 38
d Key S 4 inz('0000')
d KeyLength S 3 0 inz(4)
D OI S 4 0
D ReceiveLen S 10i 0
D Receiver1 DS
D BytesRtn1 10i 0
D BytesAvl1 10i 0

c *entry Plist
c Parm InData

* Retrieve the user profile information
C Call 'QSYRUSRI'
C Parm Receiver1
C Parm 8 ReceiveLen
C Parm FormatName
C Parm UsrProfile
C Parm QusEc
c Alloc BytesAvl1 ReceivePtr
C Call 'QSYRUSRI'
C Parm QSYI0300
C Parm BytesAvl1 ReceiveLen
C Parm FormatName
C Parm UsrProfile
C Parm QusEc

* Retrieve the encrypted password data
c Eval PassWordDs = RtvEncPwd(UsrProfile)
c Eval DataLength = BytesAvl1 + 38
c Eval Data = PassWordDs + Qsyi0300

* Write the information to the DDM data queue
c CALL 'QSNDDTAQ'
C PARM DataQue
C PARM DataQueLib
C PARM DataLength
C PARM Data
C PARM KeyLength
C PARM Key

c Eval *inlr = *on

* procedure RtvEncPwd: Retrieve encrypted password for given user
P RtvEncPwd B export
d RtvEncPwd PI 38
d PmProfile 10 const

DQSYD0100 DS Based(ReceivePtr)
D* Qsy RUPWD UPWD0100
D QSYBRTN04 1 4B 0
D* Bytes Returned
D QSYBAVL04 5 8B 0
D* Bytes Available
D QSYPN06 9 18
D* Profile Name
D PassWord 19 38

D Receiver1 DS
D BytesRtn1 10i 0
D BytesAvl1 10i 0

DQUSEC DS 116 inz
D QUSBPRV 1 4B 0 inz(116)
D QUSBAVL 5 8B 0 inz(0)
D QUSEI 9 15
D QUSERVED 16 16
D QUSED01 17 116

D FormatName S 8 Inz('UPWD0100')
D InProfile S 10
D ReceiveLen S 10i 0

c Eval InProfile = PmProfile
C Call 'QSYRUPWD'
C Parm Receiver1
C Parm 8 ReceiveLen
C Parm FormatName
C Parm InProfile
C Parm QusEc
c Alloc BytesAvl1 ReceivePtr
C Call 'QSYRUPWD'
C Parm QsyD0100
C Parm BytesAvl1 ReceiveLen


C Parm FormatName
C Parm InProfile
C Parm QusEc

c Return QsyD0100
P RtvEncPwd E

Figure 1: This exit program will be called every time a new user is added to the primary system.


d System PR 10i 0 extproc('system')
d Cmd * value options(*string)
d CpfMsgId s 7 import('_EXCP_MSGID')
d FormatCmd PR 1000
d UsrProfile 10 const
d SetEncPwd PR
d PwdStruct 38

DPassWordDs DS 38
DReceiveDs DS 1000
d ProfData 39 1000

DQSYI0300 DS
D QSYUP03 9 18
D* User Profile
D QSYURITY00 519 519
D* Security

d DataQue S 10 inz('PASSUSERRM')
d DataQueLib S 10 inz('QGPL ')
d DataLength S 5 0 inz(1000)
d Key S 4 inz('0000')
d KeyLength S 3 0 inz(4)
d KeyOrder S 2 inz('EQ')
d SenderInf S 50
d SenderLen S 3 0 inz(50)
d WaitLength S 5 0 inz(-1)

* Read the data queue as entries arrive
c CALL 'QRCVDTAQ'
C PARM DataQue
C PARM DataQueLib
C PARM DataLength
C PARM ReceiveDs
C PARM WaitLength
C PARM KeyOrder
C PARM KeyLength
C PARM Key
C PARM SenderLen
C PARM SenderInf
c Movel ReceiveDs PassWordDs
c Movel ProfData Qsyi0300

* execute the command to create the user profile
c If System(FormatCmd(QsyUp03)) 0 * If procedure returned not zero, display the error msgid
c CpfMsgId dsply
c Else

* Set the password the same as in the original profile
c Callp SetEncPwd(PassWordDs)

c
c Endif
c
c eval *inlr = *on

P SetEncPwd B export
d SetEncPwd PI
d QSYSD0100 38

DQUSEC DS 116 inz
D QUSBPRV 1 4B 0 inz(116)
D QUSBAVL 5 8B 0 inz(0)
D QUSEI 9 15
D QUSERVED 16 16
D QUSED01 17 116

D FormatName S 8 Inz('UPWD0100')

C Call 'QSYSUPWD'
C Parm QsysD0100
C Parm FormatName
C Parm QusEc

c Return
P SetEncPwd E

Figure 2: This program duplicates a user profile onto a secondary machine.


BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: