Hi
I think you need to write a script that does the chown for you and then only allow this script to be executed for the fnsrr group.
The script could be called /usr/local/bin/safe_chown.sh for instance with the following contents:
#!/bin/bash
if [[ $# -ne 2 ]]; then
echo "Usage: $0 <new_owner>:<new_group> <file>"
exit 1
fi
NEW_OWNER_GROUP=$1 TARGET_FILE=$2
FILE_GROUP=$(stat -c "%G" "$TARGET_FILE")
if [[ "$FILE_GROUP" != "fnsrr" ]]; then
echo "Error: You can only modify ownership of files in the fnsrr group."
exit 1
fi
/usr/bin/chown "$NEW_OWNER_GROUP" "$TARGET_FILE"
---
Save the script and set permissions and ownership as root.
sudo chmod 755 /usr/local/bin/safe_chown.sh
sudo chown root:root /usr/local/bin/safe_chown.sh
Then visudo and add:
%fnsrr ALL=(ALL) NOPASSWD: /usr/local/bin/safe_chown.sh
%fnsrr ALL=(ALL) !/bin/chown, !/usr/bin/chown #prevents users from running chown except via the safe_chown.sh script.
In that way you dont use normal chown but only via the script will it work.
Hope that helps or gives direction.
------------------------------
Lance Martincich
ERP Systems Engineer
City of Cape Town
Cape Town
+27832856514
------------------------------