Bug #71883 [NEW]: PHP exec() over UNC path on Windows

From: Date: Tue, 22 Mar 2016 21:10:56 +0000
Subject: Bug #71883 [NEW]: PHP exec() over UNC path on Windows
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-200046@lists.php.net to get a copy of this message
From:             hobbes at visionfriendly dot com
Operating system: Windows 2012R2
PHP version:      5.6.19
Package:          IIS related
Bug Type:         Bug
Bug description:PHP exec() over UNC path on Windows

Description:
------------
My environment is Windows Server 2012 R2, IIS 8, Active Directory, and a
file share. IIS, AD, and the file share are all separate VMs.

I have a website, www.example.com, set up in IIS. The application pool
identity is set up as the AD user IUSR_example, which has "full control"
permissions on the folder containing the site files. The site files are
on the file share, which IIS references via UNC path.

In general, the site works in that it can serve up PHP, ASP.Net, and ASP
Classic pages, and the code can even create new files.

However, I am having a problem that seems specific to PHP exec(). I've
tried calling whoami, dir, and ffmpeg, and I get nothing returned from
them. Using Sysinternals Procmon I have confirmed that the executable
never starts.

Weirdly enough, I am able to make the exact same calls with ASP Classic
(using WScript.Shell), and it works perfectly. I am also able to get PHP
exec() working when the scripts are NOT running over the UNC path. 

Here's what I've tried/found:

•When using ASP, procmon reports that w3wp.exe spawns a cmd.exe
process, which in turn spawns conhost.exe and (for example) ffmpeg.exe.
The output file from ffmpeg successfully appears.
•When using PHP, procmon reports that w3wp.exe spawns a php-cgi.exe
process, which in turn creates a cmd.exe and a conhost.exe. A thread for
ffmpeg.exe never appears.
•cmd.exe is invoked with a command line that looks like this: cmd.exe
/c ""--the command to be executed--""
•The command line for the cmd.exe process is exactly the same for both
ASP Classic and PHP.
•In Procmon, the user is always reported as IUSR_example 
•I've tried adding 2>&1 to the end of the command
•I've tried giving the IUSR to the "Replace Process-level Token"
right
•I've tried turning off FastCGI impersonation and switching between
"NamedPipe" and "TCP" under Process Model > Advanced Settings
•There are no errors in the PHP error log
•There are no errors in any of the Windows Event logs

Note that this is not specific to ffmpeg. Any other use of exec() also
fails. Also, I would prefer not to use WScript.Shell from within PHP
because eventually we will be using WordPress plugins that rely on
exec().

How can I further troubleshoot this?

(I posted this on ServerFault, but so far there haven't been any
answers.)

Test script:
---------------
$cmd =
'"\\\\myShare\\inetpub\\wwwroot\\example.com\\ffmpeg\\bin\\ffmpeg" -i
"\\\\myShare\\inetpub\\wwwroot\\example.com\\input.jpg" -vf 
"crop=100:100:70:80"
"\\\\myShare\\inetpub\\wwwroot\\example.com\\output.jpg"';

exec($cmd, $output, $return_var);

Expected result:
----------------
Procmon indicates that ffmpeg starts.

A new file appears called output.jpg

Actual result:
--------------
Procmon does not indicate that ffmpeg starts.

Output.jpg does not appear

-- 
Edit bug report at https://bugs.php.net/bug.php?id=71883&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=71883&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=71883&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=71883&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=71883&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=71883&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=71883&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=71883&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=71883&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=71883&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=71883&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=71883&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=71883&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=71883&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71883&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=71883&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=71883&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=71883&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=71883&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=71883&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=71883&r=mysqlcfg



Thread (4 messages)

« previous php.bugs (#200046) next »