How To
Summary
This document describes a procedure for identifying and reverting changes to object ownership on IBM i systems using data from the Audit Journal. By leveraging the AUDIT_JOURNAL_OW service and SQL-based analysis, administrators can restore previous owners for library objects, stream files, and directories.
Objective
This document describes a procedure for identifying and reversing changes to object ownership on the IBM i system using data from the Audit Journal. By leveraging the AUDIT_JOURNAL_OW service and SQL-based analysis, administrators can restore previous owners for library objects, stream files, and directories efficiently.
Environment
Steps
First, verify that the QAUDJRN journal exists and that you are tracking for *SECRUN or *SECURITY operations. Use the DSPSECAUD command and make sure the following settings are configured on your system:
Security journal QAUDJRN exists . . . . . : YES
Current QAUDCTL system value . . . . . . : *AUDLVL
Current QAUDLVL system value . . . . . . : *SECRUN *SECURITY Disclaimer
The SQL code provided in this document is offered as-is, without any warranties or guarantees. IBM is not responsible for the use, performance, or results of this sample code. No updates, support, or maintenance will be provided for this example. Users are encouraged to validate and test the code in their own environments before deploying it in production.
WITH TEMPOWN AS (
SELECT
TRIM(PREVIOUS_OWNER) AS PREV_OWNER, -- new owner to set
TRIM(NEW_OWNER) AS NEW_OWNER, -- current new owner per audit (kept for reference)
TRIM(OBJECT_LIBRARY) AS OBJLIB,
TRIM(OBJECT_NAME) AS OBJNAME,
TRIM(OBJECT_TYPE) AS OBJTYPE
FROM TABLE (
SYSTOOLS.AUDIT_JOURNAL_OW(
STARTING_TIMESTAMP => TIMESTAMP('2025-10-31 07:00:00'),
ENDING_TIMESTAMP => TIMESTAMP('2025-10-31 09:00:00')
)
)
WHERE PATH_NAME IS NULL -- exclude IFS; process only library objects
)
SELECT
PREV_OWNER AS PREVIOUS_OWNER,
NEW_OWNER,
OBJLIB AS OBJECT_LIBRARY,
OBJNAME AS OBJECT_NAME,
OBJTYPE AS OBJECT_TYPE,
/* QSYS2.QCMDEXC scalar function returns 1 on success, -1 on failure */
QSYS2.QCMDEXC(
'CHGOBJOWN OBJ('
|| OBJLIB || '/' || OBJNAME
|| ') OBJTYPE(' || OBJTYPE || ') NEWOWN(' || PREV_OWNER || ')'
) AS "Success?"
FROM TEMPOWN;- Adjust the Time Frame.
- The SQL in this document executes without a confirmation prompt and will programmatically revert all object ownership changes within the specified time range to the previous owner.
- A '1' on the Success column indicates that the CHGOBJOWN completed normally, a '-1' indicates that it failed.
- This document describes an SQL procedure that restores an object’s ownership to its previous owner using IBM i Audit Journal data. Before executing the procedure, users should carefully review its scope and assess the potential impact of reverting ownership changes.
- This SQL is supported only on IBM i release R730 and above.
Sample Results:
| PREVIOUS_OWNER | NEW_OWNER | OBJECT_LIBRARY | OBJECT_NAME | OBJECT_TYPE | Success? |
| V6CASTIL | HUGO | V6CASTIL | QAUDITPW | *FILE | 1 |
| V6CASTIL | HUGO | V6CASTIL | QAUDITCA | *FILE | 1 |
| V6CASTIL | HUGO | V6CASTIL | QAUDITJS | *FILE | 1 |
WITH TEMPOWN AS (
SELECT TRIM(PREVIOUS_OWNER) AS PREV_OWNER,
TRIM(NEW_OWNER) AS NEW_OWNER,
PATH_NAME,
PATH_NAME_INDICATOR
FROM TABLE (
SYSTOOLS.AUDIT_JOURNAL_OW(
STARTING_TIMESTAMP => TIMESTAMP('2025-10-30 07:00:00'), ENDING_TIMESTAMP => TIMESTAMP(
'2025-10-30 09:00:00'))
)
WHERE PATH_NAME_INDICATOR = 'YES' -- process only absolute IFS paths
)
SELECT PREV_OWNER AS PREVIOUS_OWNER,
NEW_OWNER,
PATH_NAME,
/* returns 1 on success, -1 on failure */
QSYS2.QCMDEXC('CHGOWN OBJ(''' || REPLACE(PATH_NAME, '''', '''''') || -- escape embedded quotes
''') NEWOWN(' || PREV_OWNER || ')') AS "Success?"
FROM TEMPOWN;
- Adjust the Time Frame.
- The SQL in this document executes without a confirmation prompt and will programmatically revert all object ownership changes within the specified time range to the previous owner.
- A '1' on the Success column indicates that the CHGOWN completed normally, a '-1' indicates that it failed.
- This document describes an SQL procedure that restores an object’s ownership to its previous owner using IBM i Audit Journal data. Before executing the procedure, users should carefully review its scope and assess the potential impact of reverting ownership changes.
- This SQL is supported only on IBM i release R730 and above.
Sample Results:
| PREVIOUS_OWNER | NEW_OWNER | PATH_NAME | Success? |
| V6CASTIL | HUGO | /home/v6castil | 1 |
| V6CASTIL | HUGO | /home/v6castil/test.txt | 1 |
| V6CASTIL | HUGO | /home/v6castil/.cache/javasharedresources | 1 |
| V6CASTIL | HUGO | /home/v6castil/.cache | 1 |
| V6CASTIL | HUGO | /home/v6castil/sales invoice.txt | 1 |
| V6CASTIL | HUGO | /home/v6castil/sales invoice feb.txt | 1 |
| V6CASTIL | HUGO | /home/v6castil/sales invoice mar.txt | 1 |
Additional Information:
AUDIT_JOURNAL_OW (Ownership Change) table function
Document Location
Worldwide
Was this topic helpful?
Document Information
Modified date:
26 November 2025
UID
ibm17249838