Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm using a custom compiled installation of Apache + PHP, listening on port 80.

Apache is configured to run as a normal user, with the proper settings User and Group of the httpd.conf file.

After running apache as a service, with apachectl, there's one process httpd running by root, and 4 others running by that normal user.

The problem is this:

  • When I run an external command by PHP (using exec or passthru for instance), it's run by the proper normal user, but $HOME environment variable points to /root.

For example, with the following very simple code:

<?php
echo "Home: " . `echo \$HOME`;
echo "<br />";
echo "Id: " . `id`;

I get:

Home: /root
Id: uid=1000(normaluser) gid=100(users) groups=100(users),17(audio),33(video)

Any command run this way, is actually run by the normal user, so there's no security problem. The major problem is when an external command is run, and that command tries to write and/or read something from the home directory.

share|improve this question
    
I asked this question on superuser site, but it didn't receive enough attention, so I deleted it and re-asked it here. –  nozimica May 15 '13 at 15:20
    
What's normaluser's entry in /etc/passwd? –  ott-- May 15 '13 at 18:06

1 Answer 1

I expect that the echo $HOME just reads the environment variable set by whatever shell starts httpd (the Apache process). Unless something does export HOME=/home/whatever, the value of environment variable HOME will stay the same.

I'm not sure that your last paragraph is correct at all. As far as no security problem, does PATH get set to that of normaluser? What if /home/normaluser/bin contains a very special ls executable, that does unusual things, like produce downloadable HTTP output of any file on the system? On my Apache/PHP setup, PATH gets set to /usr/local/bin:/bin:/usr/bin:/u/bediger/bin for the PHP program.

Your assertion about the major problem, reading/writing something from the home directory, doesn't make sense either. The value of HOME isn't important for partially-qualified file names, the current working directory matters. httpd seems to set that correctly for my test PHP program. My Apache/PHP setup sets current working directory to the document root, which is where my PHP lives.

<html>
<head><title>Test</title></head>
<body>
<p>
<?php
    echo "Home: " . `echo \$HOME`;
    echo "<br />";
    echo "Id: " . `id`;
    echo "<br />";
    echo "PWD: " . `pwd`;
    echo "<br />";
    echo "PATH: " . `echo \$PATH`;
?>
</p>
</body>
</html>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.