RE: [PHP] tar and ownership
| From: | Nigel Jones | Date: | Fri, 21 Nov 2003 19:41:41 +0000 |
| Subject: | RE: [PHP] tar and ownership | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-170615@lists.php.net to get a copy of this message | ||
I think if you are using the Unix Tar Version you can do
tar -C /scripts/ -zxv -f
./scripts/mailfiles.tar.gz --owner=REPLACEME --group=REPLACEME
>> -----Original Message-----
>> From: Wouter van Vliet [mailto:wouter@springt.nl]
>> Sent: Saturday, November 22, 2003 7:42 AM
>> To: 'Rodney Green'; php-general@lists.php.net
>> Subject: RE: [PHP] tar and ownership
>>
>>
>> Rodney Green wrote:
>> > Marek Kilimajer wrote:
>> >
>> >> Rodney Green wrote:
>> >>
>> >>> Greetings!
>> >>>
>> >>> I'm writing a script that downloads a tarball from an FTP server and
>> >>> unpacks it into a directory. Here's the line of code that does this.
>> >>>
>> >>> exec("tar -C /scripts/ -zxv --preserve-permissions -f " .
>> >>> "/scripts/mailfiles.tar.gz") or die('Tar failed!');
>> >>>
>> >>> My problem is that the files' ownership is changed when the tarball
>> >>> is unpacked. I'm executing the script from a web browser and Apache
>> >>> is running as the user "apache" so the files are unpacked and
>> >>> ownership given to the user apache. How can I make it so the files
>> >>> will keep the original ownerships? This is important because the
>> >>> files are mail files and the script is used to restore the mail
>> >>> files from backup so the users can access them.
>> >>
>> >>
>> >> Only root can change file ownership.
>> >>
>> > Thanks for replying. Any suggestions on how to do this then?
>> >
>> > Rod
>>
>> Multiple solutions, some better, easier, faster or securer than others
>>
>> - Make a 'cron' script, executing as root, which handles ownerships.
>> - Make a 'cron' script, executing as your own user, that extracts
>> the tarball
>> - Use the suexec wrapper, to change the using user of your virtual
>> host
>> - Run Apache as another user
>> - Make the users member of group 'apache', and give g+r file
>> permissions (group gets read)
>>
>> With some inspiration you can probably come up with a few more, just as I
>> could if I wanted too ;P
>>
>> Good luck!
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>