4

I'm using the OpenVPN Web GUI and I'm having some problems because the program doesn't see one of the necessary files. The ls -l for the file is as follows:

-rw-r--r-- 1 root www 4153 Dec 20 10:12 /etc/openvpn/inn.crt

But when I run the program, it claims that the file doesn't exist. I tried this sprintf('%d', fileperms($sLongFileName));, which raises the "can't stat" warning. file_exists() also returns false. There exists another file that's visible to PHP:

-rw-r--r-- 1 root www 581 Dec 21 12:52 /etc/openvpn/crl.pem

What's the cause of this?

EDIT: I had the program do this for both files:

file_put_contents("_dumpfile", "\n<<".$sLongFileName.">>\n", FILE_APPEND);

And the result is this:

>>/etc/openvpn/inn.crt

<</etc/openvpn/crl.pem>>

Is there some problem with the file path?

hakre
  • 193,403
  • 52
  • 435
  • 836
Mg D
  • 147
  • 1
  • 4
  • 7
  • Try using the full page in the fileperms() function. Next would be to check file ownership issues. – frustratedtech Dec 23 '11 at 15:43
  • What do you get if you `var_dump($sLongFileName);`? Seems like that must not contain the right file path, especially since `file_exists() also returns false` – DaveRandom Dec 23 '11 at 15:45
  • On which Distro do you run? If you have Ubuntu or Suse you might need to look at AppArmor - have seen this quite often – Eugen Rieck Dec 23 '11 at 15:46
  • Please hexdump the output file, it looks really strange – Eugen Rieck Dec 23 '11 at 15:48
  • The file may be readable by the webserver, but what about the `/etc/openvpn` directory? You can grant all the permissions you want on the file itself, but if the directory doesn't allow access, you won't be able to touch the file. – Marc B Dec 23 '11 at 16:18
  • @Marc: Both files are in the same directory and one is readable. – Mg D Dec 23 '11 at 17:20
  • The file might be locked by some other process. That's a feature in many operating systems: file-locking. Do not only look for the rights that are specified in the file-system, but also those that are applied within the operating system while the computer is running. – hakre Dec 23 '11 at 18:34

1 Answers1

4

Next to the physical existance of a file, there can be different other things that can prevent you from accessing the file under a specific user.

You need to verify if you can access the file and the directory the file is located with the user that is used by your PHP script to perform these calls (that depends on your server and PHP configuration). So first find out which is the username.

Then check your system configuration if utilities like SELinux are preventing access on files for a reason, e.g. webrequest results in file access on files it's not allowed to.

hakre
  • 193,403
  • 52
  • 435
  • 836
  • Turns out there was a trailing carriage return; the `chomp()` in the program didn't trim these, only newlines. – Mg D Dec 27 '11 at 12:09
  • Okay, so then the filename was wrong. Consider using a hexdump of a string to find these flaws, see: [How can I get a hex dump of a string in PHP?](http://stackoverflow.com/questions/1057572/how-can-i-get-a-hex-dump-of-a-string-in-php) – hakre Dec 27 '11 at 12:12