Changing Object Authorities and Ownership for an Entire Library
January 18, 2006 Hey, Joe
I want to change all the objects in a library so that they all have the same *PUBLIC and user authorities. My third party software also requires us to change the owner for all these objects, so that each program object in the library can be run under the adoptive authority of the primary software user. Do you have any suggestions for how I can do this?
In this case, performing these two tasks is easy. It just involves executing a couple of CL commands–the Revoke Object Authority (RVKOBJAUT) command and the Grant Object Authority (GRTOBJAUT) command–and creating a CL program to change object ownership across an entire library.
Here how I use the RVKOBJAUT and GRTOBJAUT commands to change the *PUBLIC authorities from *CHANGE to *USE for all objects in a library.
First, I run the RVKOBJAUT command as follows to remove all *PUBLIC authority from every object in my target library.
RVKOBJAUT OBJ(Library_name /*ALL) OBJTYPE(*ALL) USER(*PUBLIC) AUT(*ALL)
This command removes all authorities for the *PUBLIC user from each library object, changing each object’s *PUBLIC authority to *EXCLUDE. The Object and library parameter of ‘Library_name /*ALL’ specifies that authority should be revoked for all objects in the library; the Object type parameter (OBJTYPE), which is set to *ALL, specifies that all library objects should be effected by this command regardless of their object type; and the User (USER) and Authority (AUT) parameters of *PUBLIC and *ALL, respectively, specify that I want to revoke any previous authority settings for the *PUBLIC user on these objects.
Once the *PUBLIC object authority is revoked (meaning, cleared), I want to reset *PUBLIC authority to *USE for each library object. I can do this by running the GRTOBJAUT command like this:
GRTOBJAUT OBJ(Library_name /*ALL) OBJTYPE(*ALL) USER(*PUBLIC) AUT(*USE)
Like the RTVOBJAUT I just ran, GRTOBJAUT also runs over all the library objects that I just revoked *PUBLIC authority for. But this time I changed the Authority parameter for each object’s authority to *USE. By using these two commands in sequence, I can easily clear and reset *PUBLIC authority to *USE for each object in my target library. If I wanted to reset and change all library object authorities for any other user, I can easily run RVKOBJAUT and GRTOBJAUT again, with the name of the specific user (or a list of users) that I want to change the authority for.
Your second goal, changing object ownership to the same user for all library objects, takes just a little more time to set up, but it is not an overwhelming job. For this part of the project, I need to use the Change Object Owner command (CHGOBJOWN) on each object in my library. This is an easy enough command to run, but the kicker is that because it does not allow a *ALL parameter for the object name, I cannot run it over every object in a library like I can with the RVKOBJAUT and GRTOBJAUT commands. The solution I found is a two-step process that enables me to change the object owner for each object in a library without manually running a CHGOBJOWN command for each object. Here are the steps I follow for performing this task:
1. I first create a permanent template file for capturing and reading information from every object in a library. For our purposes, this file will be called LIBOBJINFO, it will reside in the QGPL library, and I can easily create it by using the following Display Object Description command (DSPOBJD):
DSPOBJD OBJ(QGPL/*ALL) OBJTYPE(*ALL) +
This command will capture all available information about every single object in the QGPL library and then store it in another new file in QGPL called LIBOBJINFO. The LIBOBJINFO file can then be used to compile programs that perform specific processing on all library objects. Creating the object in this way, however, produces no DDS file field specifications but I can view the file field names by executing the following Display File Field command (DSPFFD):
2. At this point, I have a file for capturing object information as well as all the field layouts for processing the captured information. I can then create a CL program using the following code to cycle through every object in my target library and change the object owner to a specified user. Here’s the CL code I put together to perform this task:
PGM PARM(&INLIB &NEWOWNER) DCLF FILE(QGPL/LIBOBJINFO) DCL VAR(&INLIB) TYPE(*CHAR) LEN(10) DCL VAR(&NEWOWNER) TYPE(*CHAR) LEN(10) DSPOBJD OBJ(&INLIB/*ALL) OBJTYPE(*ALL) + OUTPUT(*OUTFILE) OUTFILE(QTEMP/LIBOBJINFO) OVRDBF FILE(LIBOBJINFO) TOFILE(QTEMP/LIBOBJINFO) + MBR(*FIRST) SECURE(*YES) GETIT: RCVF MONMSG MSGID(CPF0864) EXEC(GOTO CMDLBL(ENDPGM)) CHGOBJOWN OBJ(&ODLBNM/&ODOBNM) OBJTYPE(&ODOBTP) + NEWOWN(&NEWOWNER) GOTO CMDLBL(GETIT) ENDPGM: DLTOVR FILE(*ALL) ENDPGM
This is a very simple program that can be used to change the object owner names for every object in my target library. I call the program with two parameters, the target library name to change object owners for (&INLIBL) and the name of the user ID that I want to make the new object owner of each object in that library (&NEWOWNER). Here’s how the code works.
First, the library name and user name parameters are passed into the program. The target library name is used in the DSPOBJD command to create another version of the LIBOBJINFO file in the QTEMP library. While the new QTEMP version contains the same file field layouts as my original template file in QGPL, it also contains all the object information for each object in my target library. The program then uses the Override with Database File command (OVRDBF) to override any program references to LIBOBJINFO with the new object that was just created in QTEMP.
Next, the program cycles through the LIBOBJINFO file by using the Receive File command (RCVF). Using the fields in each object information record (where there is one record describing each object in the library), it then changes the owner of each object to the user ID name that was passed into the program. This is accomplished by using the CHGOBJOWN command. To get the field names for the CHGOBJOWN parameters, I used the DSPFFD command on the LIBOBJINFO file to retrieve the Object name (&ODOBNM), Object library (&ODLBNM), and object type (&ODOBTP) field names that the program retrieves from its LIBOBJINFO file.
Once the program cycles through all the program objects, it deletes the file overrides and ends, leaving each object with a new owner. And the LIBOBJINFO file that it created in QTEMP will be automatically removed from the system once the job running this CL code ends, so there is no permanent storage used because of this CL program.
By using the RTVOBJAUT, GRTOBJAUT, and the CL code in this program, it’s fairly easy to accomplish your goals. If you wanted to, you could incorporate the RTVOBJAUT and GRTOBJAUT commands for changing authority into the CL code so that you can create one program that addresses library *PUBLIC authority and object ownership issues at the same time. And the nice thing about this code is that it can be easily modified to perform any other operation you might want to execute over all objects in a library.