I have a homework question about kernel programming in Linux. The question is:

What Linux-specific privilege is required to preserve ownership of a file when it's copied, and how do you get it?

Through experimentation, I've found that I need to be root or a superuser to get this to work. Is there a more specific way to explain this effect?

link|improve this question
feedback

1 Answer

up vote 3 down vote accepted

See the capabilities(7) manual page – you need the CAP_CHOWN capability to change file ownership via chown(). (Root has all capabilities enabled automatically. The manual page explains how to obtain capabilities in other cases.)

There is no separate method/capability to just preserve ownership, as Linux file copies are made by simply reading/writing data to the destination file, then doing the same with metadata. (For comparison, Windows NT has SeBackupPrivilege and SeRestorePrivilege privileges and the BackupRead()/BackupWrite() calls.)

link|improve this answer
Sweet, thank you. I had no idea where to look. – anthony-arnold Aug 21 '11 at 12:09
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.