Constantine wrote:
What is the best way to copy a file? I need to copy a file that belongs
to the user who ran my programme to my own directory. suid is set on the
binary file that is to perform the job. Any details would be appreciated.
This is a newsgroup for discussion of the C++ programming language. Did
you have a question or comment about that? If not, please try posting
your question in a newsgroup dedicated to your OS.
The usual approach is just to call system( "/bin/cp source destination"
) from your program. If you prefer not to do this, you can use the
read() and write() system calls. Your system also may provide a special
function for copying files; try man unlink, and look under SEE ALSO. If
you're having trouble making the program write to your directory when
it's called by a user, make sure geteuid returns your uid. If not, your
filesystem may have been mounted "nosuid" (a common practice among
superstitious admin's). In that case, consider using a separate
directory for these files, with group write permission and the SETGID
bit high. Then, all files in the directory will be owned collectively
by the same group that owns the directory. You may have to get your
admin to create a special group.
Good luck,
Jeff