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

Discussion in 'C++' started by Constantine, Dec 28, 2003.

  1. Constantine

    Constantine Guest

    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.
    Constantine, Dec 28, 2003
    #1
    1. Advertising

  2. Constantine

    Jeff Schwab Guest

    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
    Jeff Schwab, Dec 28, 2003
    #2
    1. Advertising

  3. Constantine

    Jeff Schwab Guest

    Constantine wrote:
    > On 2003-12-27 20:21, Jeff Schwab wrote:
    >
    >> 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.

    >>
    >>
    >> 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.


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

    -Jeff

    >
    > Thank you,
    > Constantine.
    Jeff Schwab, Dec 29, 2003
    #3
  4. Constantine

    Constantine Guest

    On 2003-12-27 20:21, Jeff Schwab wrote:

    > 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.

    >
    > 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.
    Constantine, Dec 29, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex
    Replies:
    2
    Views:
    1,218
  2. fabio

    strange behaviour geteuid()

    fabio, Oct 6, 2006, in forum: C Programming
    Replies:
    8
    Views:
    383
    Igmar Palsenberg
    Oct 9, 2006
  3. Replies:
    26
    Views:
    2,107
    Roland Pibinger
    Sep 1, 2006
  4. Leslie Viljoen

    getuid

    Leslie Viljoen, Aug 25, 2005, in forum: Ruby
    Replies:
    1
    Views:
    104
    Bruce Woodward
    Aug 25, 2005
  5. MaggotChild

    File::Copy::copy With File Handles

    MaggotChild, Oct 18, 2011, in forum: Perl Misc
    Replies:
    2
    Views:
    501
    Ilya Zakharevich
    Oct 22, 2011
Loading...

Share This Page