UNIX: getuid(), geteuid(): how to copy user's file to my personalspace

C

Constantine

Hello,

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.

Thank you,
Constantine.
 
J

Jeff Schwab

Constantine said:
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
 
J

Jeff Schwab

Constantine said:
Will cp utility have access to both users' directories, if run from the
programme with suid? If so, how could I get the summary of what files
were copied? Each time, there will be around 2 to 5 files to be copied,
and I need to know which ones were copied successfully.

That depends on your system. Try posting in an appropriate newsgroup.

-Jeff
 
C

Constantine

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

Will cp utility have access to both users' directories, if run from the
programme with suid? If so, how could I get the summary of what files
were copied? Each time, there will be around 2 to 5 files to be copied,
and I need to know which ones were copied successfully.

Thank you,
Constantine.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top