Directory permissions changed by apache via PHP

Discussion in 'Apache' started by ghollins, Jun 16, 2010.

  1. #1
    Hi,

    I'm having an issue where a PHP page running under apache alters destructively a directory's permissions. A very simple script that lists a directory's contents seems to cause this:

    <?php
      $cmd = "ls -la /Volumes/ 2>&1";
      exec($cmd, $execOut, $exitCode);
      echo "<PRE>EXIT CODE = $exitCode<BR/>";
      foreach($execOut as $line) {
        echo "$line <BR/>";
      }
      echo "</PRE>";
    ?>
    PHP:
    When I hit this page it usually succeeds, but it sometimes (randomly) produces this output:

    EXIT CODE = 1
    ls: myshare: Permission denied 
    total 8 
    drwxrwxrwt@  4 root  admin   136 Jun 14 12:34 . 
    drwxrwxr-t  30 root  admin  1088 Jun  4 13:09 .. 
    lrwxr-xr-x   1 root  admin     1 Jun 11 16:05 galenhd -> / 
    Code (markup):

    When it succeeds it looks like:

    EXIT CODE = 0
    total 40 
    drwxrwxrwt@  4 root   admin    136 Jun 14 12:34 . 
    drwxrwxr-t  30 root   admin   1088 Jun  4 13:09 .. 
    drwx------   1 galen  staff  16384 Jun 14 09:28 myshare 
    lrwxr-xr-x   1 root   admin      1 Jun 11 16:05 galenhd -> / 
    Code (markup):
    There should be no reason why consecutive hits of the same page should do something functionally different.
    I'm pretty confident this bug/issue involves Apache to some degree, because when I take Apache out of the equation, for example by running PHP standalone, I don't see any problems.

    OTHER DETAILS:
    • Running on mac Snow Leopard
    • using out-of-the-box Apache and PHP on mac
    • mounted myshare directory via Finder (i.e. smb://myserver/myshare via Go-->Connect to Server... menu)
    • If command is changed to remove "-l" option, it doesn't cause failure
    • SMB server is Windows 2003, although I've also tested this on a linux SMB server, and it also fails, so I don't think the server is at fault
    • Running the same PHP script from the command-line doesn't cause problem -- it only fails when run under Apache
    • Running "sudo ls -la /Volumes" repairs permissions on directory
    • Failure has been occurring for me roughly 1 out of every 20 page hits, but in a random fashion

    Surely someone has run into this seemingly simple use case?

    Thanks,
    Galen
     
    Last edited: Jun 16, 2010
    ghollins, Jun 16, 2010 IP
  2. ghollins

    ghollins Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I've narrowed this problem down to the default Apache/PHP installation on Snow Leopard. Here is what FAILS on the code in the previous post:

    SNOW LEOPARD out-of-the-box
    user$ apachectl -v
    Server version: Apache/2.2.14 (Unix)
    Server built: Feb 10 2010 22:22:39
    -------------------
    php -v
    PHP 5.3.1 (cli) (built: Feb 11 2010 02:32:22)
    Copyright (c) 1997-2009 The PHP Group
    Zend Engine v2.3.0, Copyright (c) 1998-2009 Zend Technologies


    The following configurations WORK:

    MAMP (on Snow Leopard)
    /Applications/MAMP/Library/bin/apachectl -v
    Server version: Apache/2.0.63
    Server built: Mar 5 2010 14:55:50
    ---------
    PHP 5.2.2

    Apache/PHP on Ubuntu
    apache2ctl -v
    Server version: Apache/2.2.12 (Ubuntu)
    Server built: Mar 9 2010 22:11:44
    -------------
    php -v
    PHP 5.2.10-2ubuntu6.4 with Suhosin-Patch 0.9.7 (cli) (built: Jan 6 2010 22:56:44)
    Copyright (c) 1997-2009 The PHP Group
    Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies


    So this appears to be an Apache or a PHP bug in out-of-the-box Snow Leopard.

    All of the above configurations were pointing to the exact same SMB share...
     
    ghollins, Jun 18, 2010 IP