Advanced Linux file permission question (ownership change during write operation)
- by Kent
By default the umask is 0022:
usera@cmp$ touch somefile; ls -l
total 0
-rw-r--r-- 1 usera usera 0 2009-09-22 22:30 somefile
The directory /home/shared/ is meant for shared files and should be owned by root and the shared group. Files created here by usern (any user) are automatically owned by the shared group. There is a cron-job taking care of changing owning user and owning group (of any moved files) once per day:
usera@cmp$ cat /etc/cron.daily/sharedscript
#!/bin/bash
chown -R root:shared /home/shared/
chmod -R 770 /home/shared/
I was writing a really large file to the shared directory. It had me (usera) as owning user and the shared group as group owner. During the write operation the cron job was run, and I still had no problem completing the write process.
You see. I thought this would happen:
I am writing the file. The file permissions and ownership data for the file looks like this: -rw-r--r-- usera shared
The cron job kicks in! The chown line is processed and now the file is owned by the root user and the shared group.
As the owning group only has read access to the file I get a file write error! Boom! End of story.
Why did the operation succeed? A link to some kind of reference documentation to back up the reason would be very welcome (as I could use it to study more details).