My IT department made an error and chowned every file on the filesystem to root:OurGroup
. Then their automatic backup (i.e. .snapshop
) system created a snapshot, so we no longer have a reference of what the permissions were before.
I'm trying to work with them to make a script which will have the set-uid bit set and owned by root that users can call to re-chown files/directories back to them as needed.
I'm anticipating that they won't want a script that'll chown just anything to them, but may instead be willing to create a new user, chown everything to that user, then have a script users can call which will own chown files to them if it's owned by this other user.
However, to avoid race conditions, I want to find a way to chown if-and-only-if the file is owned by this users. There's a race condition here though: if I do this in two separate calls and two users run this script on a file at the same time, it can cause collisions. Instead I'd like to "change owner if the owner is user" in one call, instead of "if owner is user" followed by "change owner"
Is there an atomic compare-and-exchange primitive for file ownership?
I'm trying to work with them to make a script which will have the set-uid bit set and owned by root that users can call to re-chown files/directories back to them as needed.
Not possible. You could usesudo
instead.