|
Posted by Richard Lynch on 02/09/05 21:43
ADNET Ghislain wrote:
> I am trying to make upload files to belong to the ftp user of the
> website and not the apache user.
>
> As i run in module i tried to do this:
>
> 1/ create a temp dir on the website outside the documentroot, chown the
> temp dir to my ftp user and allow the group to write,, put the same
> group as the webserver on the tmp dir too.
>
> 2/ then chmod u+s it (so with suid on the directory) and at the end
> i put my upload_tmp_dir setting to this directory.
>
> I was quite sure it would solve the issue BUT ... (there is allway a
> BUT... ;)
>
> when i run the simple script at php.net it gives me this output :
>
> --------------------------------------------------------------------------
>
> File is valid, and was successfully uploaded.
> Here is some more debugging info:Array
> (
> [userfile] => Array
> (
> [name] => afnic-adherent-200x80.gif
> [type] => image/gif
> [tmp_name] => /var/tmp/php2L6xR7
> [error] => 0
> [size] => 17710
> )
>
> )
>
> ------------------------------------------------------------------------
>
> You see :
>
> [tmp_name] => /var/tmp/php2L6xR7
>
> and the file belong to the apache user... not the ftp one :(
>
> So really i wonder if anyone found a solution to this problem, or can
> explain me why this setup fails ?
Apache was still the user that created the file, and therefore it will
belong to Apache until somebody does a 'chown' on the file.
Only the superuser can 'chown' a file.
Thus, you will need a sudo script of some kind to do the chown, or some
way to let the FTP user create the file, then the Apache user's data to go
in it.
So, some options:
1. Write a cron job as root to "chown ftp:ftp /var/tmp/php*"
This has the severe down-side of maybe someday changing stuff you *WANT*
to be owned by Apache.
2. Let Apache move the files somewhere else, like, say:
/var/to_ftp/
and then do #1 above.
3. When a file is uploaded, have PHP be able to execute a shell command
that has the FTP user create a temp file, writable by Apache, and then
Apache can copy its temp file to the FTP temp file by doing
fopen/fwrite/fclose. It will still be owned by FTP user, but Apache can
fill it up with whatever data it wants. You should add some serious
sanity checking on the data when you READ these files, however, if you
have untrusted users on the system. Or a routine audit/sweep of all these
files to be SURE they are kosher, or...
4. Provide a shell script which allows the Apache user to chown *ONLY*
files within /var/tmp, and *ONLY* files that start with 'php' and then
Apache can chown the files to the FTP user. Don't give Apache free rein
to chown any old file it wants! [shudder]
5. Easiest: Let Apache move_uploaded_file somewhere, and make it readable
by FTP user. Have FTP user copy over files from the Apache storage space.
When the FTP user creates the new file, it will be owned by the FTP user.
Again, you want to put some controls/checks on this to be sure it's not
abused.
--
Like Music?
http://l-i-e.com/artists.htm
Navigation:
[Reply to this message]
|