I'm currently developing a script to clean out certain directories based on age and name. Part of the assignment is to ensure that the cleaning of a directory is done under the user id of the owner (script is running as root). I have a few ideas on how to do this, but I'd like to hear your opinions/ideas/suggestions on these (maybe I've missed something):
- Move the relevant parts into a separate script which gets called by su
- Built a separate script in memory and pass it to su <uid> -c 'bash -c' (probably going to end in quoting ****)
- As above, but write to a temporary location
- ?
Ideally, I'd like a mechanism like setuid/seteuid to make a temporary privilege deescalation for a certain block, saving me the hassle of passing parameters between those scripts.