Can't get unlink to work in PHP

Hi folks,

hope some kind soul can help me out on this - I’m banging my head since two weeks …
I’m working on a rather old - but stable! - SuSE Linux 10.0 LAMP-box (I know, this version of Linux is old and discontinued, but it’s a production webserver, so I have to live with it for the tine being.
Now the problem is, that I realized, that the function unlink(fname) does not work. Our homebrew CMS creates folders and files and now we want to move some of them around or delete them via the CMS as well. Since all folders and the folders above have been created by the CMS they all do belong to the Apache user. They also have a umask of 0775, files have a umask of 664, so it’s not a security issue.
When I use unlink() in a PHP-script, it comes back with an OK, but the file is still there. Using rename() to move a dir from one place to another (both within the webdocs-tree), it gets even more strange: it creates an exact copy in the new destination (just as expected), but only deletes the JPEGs from the original folder, but leaves the text-files in place and since the original directory is not empty then, it cannot delete it. Both jpegs and text-files have the same owner and permission.
Save_mode is off (setting in php.ini) and checked via phpinfo(). The really bizarre thing is, that I do not get any error messages which may be related to that issue, even though the error level is set to E_ALL.
I also checked for open files with lsof, which may prevent deleting files, but there aren’t any.
I even tried to download a new version of php from php.net and compiled it and exchanged it with the vanilla php from SuSE - same effect. So I don’t think it’s a bug in PHP, but rather some obscure security setting on the box. Although there is nothing special with it, it has been set-up from the original SuSE Linux 10.0 DVD, with no tinkering. I guess I ploughed through any available docs, but with no luck :frowning:
Any what I could try next?
Any help is greatly appreciated, I’m really desperate by now !!!

Cheers, Stefan!

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Get your Apache access_log and error_log files as those may be useful from
the time period when this happens.

Also, 0644 and 0755 are not umasks… they are permissions affected by
the default umask in place on creation of those files or directories.
Technicality, but those matter in a technical field (if not all of life).

Finally, the ability to delete a file requires write permissions on the
directory itself. These would also be required to create new files. My
guess is that your graphical files are in a directory where you can write
while your text-based files may not be. Seems strange that some files
would be this way but it’s the only thing that really makes sense. To
test the permissions side of things go to the command line, become root,
and then ‘su’ to your Apache server user and try the same move command:

su - wwwrun #if the user is wwwrun
su - apache #if the user is apache

Once there go into /srv/www/htdocs (or wherever) and test the move or
delete commands (be sure you have backups before you break things) and see
if it works. If it does then PHP or Apache’s httpd server is in your way.
If it does not, the filesystem permissions are stopping you.

Good luck.

On 04/28/2010 12:26 PM, stefvienna wrote:
>
> Hi folks,
>
> hope some kind soul can help me out on this - I’m banging my head since
> two weeks …
> I’m working on a rather old - but stable! - SuSE Linux 10.0 LAMP-box (I
> know, this version of Linux is old and discontinued, but it’s a
> production webserver, so I have to live with it for the tine being.
> Now the problem is, that I realized, that the function unlink(fname)
> does not work. Our homebrew CMS creates folders and files and now we
> want to move some of them around or delete them via the CMS as well.
> Since all folders and the folders above have been created by the CMS
> they all do belong to the Apache user. They also have a umask of 0775,
> files have a umask of 664, so it’s not a security issue.
> When I use unlink() in a PHP-script, it comes back with an OK, but the
> file is still there. Using rename() to move a dir from one place to
> another (both within the webdocs-tree), it gets even more strange: it
> creates an exact copy in the new destination (just as expected), but
> only deletes the JPEGs from the original folder, but leaves the
> text-files in place and since the original directory is not empty then,
> it cannot delete it. Both jpegs and text-files have the same owner and
> permission.
> Save_mode is off (setting in php.ini) and checked via phpinfo(). The
> really bizarre thing is, that I do not get any error messages which may
> be related to that issue, even though the error level is set to E_ALL.
> I also checked for open files with lsof, which may prevent deleting
> files, but there aren’t any.
> I even tried to download a new version of php from php.net and compiled
> it and exchanged it with the vanilla php from SuSE - same effect. So I
> don’t think it’s a bug in PHP, but rather some obscure security setting
> on the box. Although there is nothing special with it, it has been
> set-up from the original SuSE Linux 10.0 DVD, with no tinkering. I guess
> I ploughed through any available docs, but with no luck :frowning:
> Any what I could try next?
> Any help is greatly appreciated, I’m really desperate by now !!!
>
> Cheers, Stefan!
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.12 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJL2ICwAAoJEF+XTK08PnB5fY8P/1s8DQ2RdwtDyf/IxCJhrZHw
wTnkkHnnsG9Ny9nzTOlIOLbNOrBCaTfwSkAAPLnJx5lqWR762u7RoVAb1Y2x97+m
/8Yz1oZUmaHVIgefAWkLCvxLFmIXrsQejDCUmb6YZUye+GklgZt1uReYRiS2fYDU
ukdE499WwdiI0sVx8tx5IJ83a1gmxa/EPn3KQGz5GH9AYU3DWNH7vYAOiTnDEtlp
9I5QjS/bGz1RShXWkRKO7pie8PaJbgPr6vUbduaw/qE/WZi1qBDpP1lzu69Ih9IC
3XOeREsyq5qRXWtRwFYM4hklOXjBhnUYnyId/BGdT1vg7le5LqIi1EB8shAstowV
ZbuOiV3LqP9IQaxECWQgkN7N+WG/egA06O9pPOMF4MhwcwPX3PH3PW2k2uRUyu7B
PClqSWWOU8UfboDoYkYUDygbVmmsZM64CmSKBtDByr1czbpIJBbVIlVhuoB/cgF3
u5KBtPsXRTE5a7sE3gHFJQMEdzQFWjZbaPNVovrE3YwgjPNEE1dd+7mOhZQ2zRlt
QF1WRXyW/LjO3j2yZNzUwktSlJ/zAjdE2RALUllHDfbAwIq1j8h4S7lE1tBev0yL
AbmBiWHbA9KGNpRAI8jFMujIy98/SC/ELFKvb/Ce3z/Vf1lKMXMGjOwlMjBfuUFA
YvLmDJvVjFSMFYLIN+zd
=FzG0
-----END PGP SIGNATURE-----

You might also want to check if you are affected by PHP’s safe mode:

PHP: Functions restricted/disabled by safe mode - Manual

Hi,

thanks for your answers, but I’ve checked that already.
Safe_mode is off - at least according to phpinfo() and the parent dirs are writable by apache.

Bye, Stefan!

You could strace the PHP process to see what happens to the unlink, although it might be a bit of a hassle to locate the appropriate httpd process id.