tags:

views:

1822

answers:

3

Hi folks,

I'm on a foreign linux system and need to determine the user that apache runs on (and so does php).

The aim: I need to get the owner of the script (this is no problem as I can use SplFileInfo) and compare it to the owner of the apache process.

I'm open to any alternative proposals.

Regards, Mario

Edit: Additional info:

The script is a thumbnail generator, that uses an XML file to generate thumbs from larger images. The script needs to create folders and write files. As I cannot influence the php configuration and I do not have any shell access, this has to be done very silently. The creation process stopps via exception and sends a mail on failue. As most of php's function cannot throw exceptions on failue, I need some manual checks to determine the environment I'm in. Therefore I need the apache user to compare it to some directory or fileowner.

A: 

phpinfo will dump a lot of system information. For apache2 installs, there is a section that displays the apache user and group ids. Try creating a php script that just has one line, a call to phpinfo(), and open it in your web browser.

zombat
Thats not the aim ;)I know how to get the user via php info ... i need to aquire the names as strings from within a script.
Mario Mueller
... and parsing the phpinfo(INFO_MODULES) is NOT an alternative ;)
Mario Mueller
+5  A: 

You can call the php exec function to execute whoami:

<?php echo exec('whoami'); ?>

grant

grantc
thanx grant! thanx to the anon.,both methods provided here are very well suited. I will use grant's method, as I cannot assert that the posix function are available.
Mario Mueller
exec() won't work if safe_mode is enabled and whoami is outside of safe_mode_exec_dir.
Anonymous
absolutely correct, but for my target environment this is the best solution. (no safe_mode ;))
Mario Mueller
+1  A: 

see posix_getuid() and posix_getpwuid()

Anonymous