Skip to content

Conversation

@ATorrise
Copy link
Contributor

@ATorrise ATorrise commented Sep 22, 2025

WHAT IT DOES

  • fixes the bug where zowex uss chown (zusf_chown_uss_file_or_dir) silently succeeded with exit code 0 when a non-existent/invalid user or group was supplied.
  • Splits user:group correctly and validates both parts (numeric IDs or names via getpwnam/getgrnam), returning a clear error instead of passing -1 to chown()
  • Adds a guard to reject the no-op case (neither user or group specified)
  • Keeps current behavior of following symlinks (stat/chown); open question left in PR description whether we should switch to lstat/lchown in a follow-up for possibly safer/consisten behavior.

AUTOMATED TESTS
image

TEST PREP
Find values to test with

whoami      # copy this as YOUR_USER
id -Gn      # pick any one shown as YOUR_GROUP

# Use nosuchuser_xyz / nosuchgroup_xyz as obviously invalid values.

Create a test file

echo hello > demo.txt

TESTING (manual)

  1. $\textcolor{red}{\text{Invalid user change → error}}$
zowex uss chown nosuchuser_xyz demo.txt ; echo  "rc=$?"

# Expected Output
chown error: invalid user 'nosuchuser_xyz'
rc=255
# Note: use a real file because path gets evaluated first and you will miss the user error!
  1. $\textcolor{red}{\text{Invalid group change → error}}$
zowex uss chown YOUR_USER:nosuchgroup_xyz demo.txt ; echo "rc=$?"

# Expected Output
chown error: invalid group 'nosuchgroup_xyz'
rc=255
  1. $\textcolor{green}{\text{Valid user change → success}}$
zowex uss chown YOUR_USER demo.txt ; echo "rc=$?"

# Expected Output
USS path 'demo.txt' owner changed to 'YOUR_USER'
rc=0
  1. $\textcolor{green}{\text{Valid group-only change → success (if you own file and are in group)}}$
zowex uss chown :YOUR_GROUP demo.txt ; echo "rc=$?"

# Expected Output
USS path 'demo.txt' owner changed to ':YOUR_GROUP'
rc=0
  1. $\textcolor{green}{\text{Valid user+group change → success (privilege dependent)}}$
zowex uss chown YOUR_USER:YOUR_GROUP demo.txt ; echo "rc=$?"

# Expected Output
USS path 'demo.txt' owner changed to 'YOUR_USER:YOUR_GROUP'
rc=0
  1. $\textcolor{red}{\text{No-op (neither user nor group changed) → error}}$
zowex uss chown : demo.txt ; echo "rc=$?"

# Expected Output
chown error: neither user nor group specified
rc=255
  1. $\textcolor{green}{\text{Directory recursive check → all nested files get new owner/group}}$
# Create a small file tree
mkdir -p project_dir/subdir1/subdir2
echo "first" > project_dir/file_top.txt
echo "second"  > project_dir/subdir1/file_mid.txt
echo "third" > project_dir/subdir1/subdir2/file_bottom.txt

# Change ownership recursively
zowex uss chown YOUR_USER:YOUR_GROUP project_dir --recursive ; echo "rc=$?"

# Verify all levels
ls -lR project_dir
# Expect all three files (and the dirs) to show YOUR_USER YOUR_GROUP
  1. $\textcolor{green}{\text{Symlink check → follows link to target}}$
    (removal of this test case+ logic tbd)
# Create a real file and a symlink
echo "hello world" > real_target.txt
ln -s real_target.txt symlink_to_target.txt

# Change ownership using the symlink path
zowex uss chown YOUR_USER:YOUR_GROUP symlink_to_target.txt ; echo "rc=$?"

# Check that the real file’s ownership changed
ls -l real_target.txt    # should show YOUR_USER YOUR_GROUP

# Check the symlink shows the link
ls -l symlink_to_target.txt  # symlink still points to real_target.txt

REVIEW CHECKLIST
I certify that I have:

ADDITIONAL COMMENTS

Important

Feedback is welcome on whether to switch to lstat/lchown in a future PR to avoid following symlinks.

@github-project-automation github-project-automation bot moved this to New Issues in Zowe CLI Squad Sep 22, 2025
@zowe-robot zowe-robot moved this from New Issues to In Progress in Zowe CLI Squad Sep 22, 2025
@ATorrise ATorrise linked an issue Sep 22, 2025 that may be closed by this pull request
@github-actions
Copy link

github-actions bot commented Sep 22, 2025

Signed-off-by: Amber <[email protected]>
@ATorrise ATorrise marked this pull request as ready for review September 22, 2025 20:23
@zowe-robot zowe-robot moved this from In Progress to Review/QA in Zowe CLI Squad Sep 22, 2025
@github-actions
Copy link

github-actions bot commented Sep 22, 2025

@ATorrise ATorrise requested a review from jace-roell September 23, 2025 17:29
Copy link
Member

@traeok traeok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this Amber! I have a small request for modifying the function definition/declaration but the changes & test cases make sense to me.

Also, I noticed some of the files had formatting changes after saving on my end - you might want to run clang-format to adjust formatting - or you can install the "Clang" extension in VS Code and use that to install clang & run the formatter.

@ATorrise ATorrise requested a review from traeok October 6, 2025 19:18
@sonarqubecloud
Copy link

sonarqubecloud bot commented Oct 6, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
6 Security Hotspots
15.1% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@t1m0thyj t1m0thyj self-requested a review October 7, 2025 14:17
@ATorrise ATorrise requested a review from pujal0909 October 7, 2025 14:37
Copy link
Member

@t1m0thyj t1m0thyj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Review/QA

Development

Successfully merging this pull request may close these issues.

zowex: uss chown does not error when given an invalid owner

4 participants