I have the following directory structure:
+ public/
|-+ pics/
| |-- a
| `-- b
`-+ thumbs/
|-- a
`-- b
I would like all the files in the tree to be owned by gallery:http with ug=rwX,o= mode set.
The script which happens to create directories within pics and thumbs runs
as the gallery user. I set SUID/SGID bits on public, pics and thumbs.
Now the problem is that the a directory will get created with owners gallery:http as it should, but it won't have the x permission for the group. If I call chmod, I'll clear the SGID bit. (Strange behavior, but that
will really happen, likely because http is not the user-owner of the file.)
I can't call chown as non-root user to set mode first and then the owners.
The only solution seems to be to set umask to ug=rwx,o=, create all the directories and then either change the umask before I create any regular file, or create the regular files and then change their mode to ug=rw,o=.
Is there a better, less ugly solution which I don't see?