php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50542 scandir() cannot open UNC paths since PHP 5.3.1
Submitted: 2009-12-21 14:41 UTC Modified: 2010-11-12 08:53 UTC
Votes:3
Avg. Score:4.7 ± 0.5
Reproduced:3 of 3 (100.0%)
Same Version:2 (66.7%)
Same OS:3 (100.0%)
From: d_daemen at hotmail dot com Assigned: pajoye (profile)
Status: Closed Package: *Directory/Filesystem functions
PHP Version: 5.3.1 OS: win32 only - W2003
Private report: No CVE-ID: None
 [2009-12-21 14:41 UTC] d_daemen at hotmail dot com
Description:
------------
scandir() cannot open UNC paths since PHP 5.3.1 (Running under IIS 6)

I've upgraded from PHP 5.2.11 tot 5.3.1 and then this function does not work anymore.

this problem i have also with readdir, opendir, & glob.

PHP is configured on a virtual directory, i used the PHP 5.2.11 ISAPI module and use now the PHP 5.3.1 CGI Module.

I tried following path's:
$dir = "\\\\hdlsrv\\Company\\Documentatie";
$dir = "\\hdlsrv\Company\Documentatie";
$dir = "//hdlsrv/Company/Documentatie";
$dir = "///hdlsrv/Company/Documentatie";

IIS is configured to use 'integrated windows authentication' and 'digest authentication for windows domain servers'.

When a user opens the page, php-cgi.exe is running as the users logon name.

The user has access to the share.

Reproduce code:
---------------
<?php
	$dir = "\\\\hdlsrv\\Company\\Documentatie";
	$files = scandir($dir);
	print_r($files);
?>

Expected result:
----------------
Array ( [0] => . [1] => .. [2] => Article Ranges [3] => Bezoek Verslagen [4] => Demo cd [5] => Headline Info [6] => ParcRanges 2008 [7] => Software Manuals ) 

Actual result:
--------------
Warning: scandir(\\hdlsrv\Company\Documentatie) [function.scandir]: failed to open dir: No such file or directory in K:\Intranet\docs.php on line 3

Warning: scandir() [function.scandir]: (errno 2): No such file or directory in K:\Intranet\docs.php on line 3
PHP Warning: scandir(\\hdlsrv\Company\Documentatie) [function.scandir]: failed to open dir: No such file or directory in K:\Intranet\docs.php on line 3 PHP Warning: scandir() [function.scandir]: (errno 2): No such file or directory in K:\Intranet\docs.php on line 3 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-12-21 14:46 UTC] pajoye@php.net
I will test it once I'm back home after my holidays.

However,  I can say that it works just fine, having use this feature last week. Did you use impersonate? Or are you sure that the user running php has access to this share?
 [2009-12-21 14:49 UTC] dd at headlineweb dot nl
thanks pajoye,

yes, i use impersonate and the user has access to the share
 [2010-01-08 15:32 UTC] bramus at bram dot us
Having the same issue here, cannot access *any* file on an UNC path via fopen, file_put_contents, etc. Even file_exists returns false.

User has sufficient permissions (impersonate is active) + All worked fine under PHP 5.2.x (Additionally: even if I set permissions for "Everyone" to have full access to the given UNC path it will not work).

Running IIS7, PHP is configured as a FastCGI Module.
 [2010-01-08 16:49 UTC] pajoye@php.net
It works just fine here, using WS03 as server (where the UNC path is) or client (fetching from).

If one of you can give me a remote access to debug, I could help. But I'm not able to reproduce this problem using any of the tests system I use.
 [2010-01-08 19:57 UTC] bramus at bram dot us
pajoye,

I can provide you with an FTPS/WEB account on the server so that you can run some test files on it; I hope that's sufficient enough (or at least "a start") as I can not give you full access (viz. RDP access w. Admin privileges) to the server.

Regards,
Bram.
 [2010-01-09 08:47 UTC] dd at headlineweb dot nl
The server where PHP is running has RDP enabled, but our system administrator does not give permission.

if you want to do some test, maybe i can do the tests for you?

BTW: the call is as follows

Client --HTTP--> W2003 Server --UNC--> Another W2003 Server
 [2010-01-20 11:43 UTC] blc at 3ds dot com
I have exactly the same problem since I moved from PHP 5.2 to 5.3.1
I have it using PHP in command line too when reading remote files through UNC path AND through drive: path.
Here is a sample code:
====================================================================
<?php
error_reporting(E_ALL);
$file="intel_a/RebasingDrop1.txt";
echo "CWD=".getcwd()."\n";
echo "FILE=$file\n";
// No permission problems to access the file
echo `ls -l $file`."\n";
echo `head $file`."\n";
// file_exists don't see it
echo (file_exists($file)?"file $file EXISTS":"file $file not found")."\n";
// opening it always fail
echo (fopen($file,'r')===FALSE?"Open FAILED":"Open worked")."\n";
echo (file($file)===FALSE?"File FAILED":"File worked")."\n";
echo (file_get_contents($file)===FALSE?"file_get_contents FAILED":"file_get_contents worked")."\n";
?>
====================================================================
Here is the result when running the script from W: (which is mapped on \\server\share)
====================================================================
CWD=W:\CXR20rel\BSF
FILE=intel_a/RebasingDrop1.txt
-r-xr-xr-a   1 DS\BSFR         DS\Domain+Users    6751 Oct  7  2002 intel_a/RebasingDrop1.txt

CATSYSPROXY.DLL
CATAPPLICATIONFRAME.DLL
JS0GROUP.DLL
JS0SPEXT.DLL
CATSYSMULTITHREADING.DLL
CATSYSALLOCATOR.DLL
JS0FM.DLL
CATINFINTERFACES.DLL
CATSYSCOMMUNICATION.DLL
CATAUTOITF.DLL

file intel_a/RebasingDrop1.txt not found
Warning: fopen(intel_a/RebasingDrop1.txt): failed to open stream: No such file or directory in E:\NoSave\DepsGraph_V7\release\bug.php on line 12
Open FAILED
Warning: file(intel_a/RebasingDrop1.txt): failed to open stream: No such file or directory in E:\NoSave\DepsGraph_V7\release\bug.php on line 13
File FAILED
Warning: file_get_contents(intel_a/RebasingDrop1.txt): failed to open stream: No such file or directory in E:\NoSave\DepsGraph_V7\release\bug.php on l
ine 14
file_get_contents FAILED
====================================================================
Here is the result when running the script from \\server\share
====================================================================
file intel_a/RebasingDrop1.txt not found
Warning: fopen(intel_a/RebasingDrop1.txt): failed to open stream: No such file or directory in E:\NoSave\DepsGraph_V7\release\bug.php on line 12
Open FAILED
Warning: file(intel_a/RebasingDrop1.txt): failed to open stream: No such file or directory in E:\NoSave\DepsGraph_V7\release\bug.php on line 13
File FAILED
Warning: file_get_contents(intel_a/RebasingDrop1.txt): failed to open stream: No such file or directory in E:\NoSave\DepsGraph_V7\release\bug.php on l
ine 14
file_get_contents FAILED
====================================================================
 [2010-01-20 11:49 UTC] pajoye@php.net
Do you use DFS?
 [2010-01-20 11:50 UTC] pajoye@php.net
DFS are the only case that may cause issues. I was not able to reproduce any other UNC related issues, mounted as drive or path, accessing directly using the UNC path, etc.
 [2010-01-20 11:51 UTC] pajoye@php.net
blc at 3ds dot com, which OS do you use? On the server and where PHP runs.
 [2010-01-20 11:56 UTC] dd at headlineweb dot nl
pajoye, Yes we use DFS on 2 windows 2003 R2 servers
 [2010-01-20 12:01 UTC] pajoye@php.net
Ok, thanks, that explains why I was not able to reproduce it here.

I have to setup a test environment for DFS locally, but I won't be able to do it in the next 2 weeks.

I could give it a try earlier if you can provide remotely accessible VMs/hosts to do some tests (have to install debugging tools on it too)?
 [2010-01-22 16:41 UTC] blc at 3ds dot com
I run my PHP script on Windows XP 
The remote file system is UNIX

so I guess there is some NFS in between (samba or ...) and some DFS on the SMB/windows side
 [2010-01-22 16:51 UTC] pajoye@php.net
Please try using:

http://downloads.php.net/pierre/php-5.3.3-dev-nts-Win32-VC9-x86-dfsfix.zip

in CLI, or using FCGI (IIS or mod_fcgi).

Final fix will be in all versions :)
 [2010-01-22 23:18 UTC] dd at headlineweb dot nl
Hi pajoye,

Thanks for the update!

I tried http://downloads.php.net/pierre/php-5.3.3-dev-nts-Win32-VC9-x86-dfsfix.zip but unfortunately with this version i have the same issue, PHP works but not accessing UNC paths.
 [2010-01-23 01:16 UTC] pajoye@php.net
dd at headlineweb dot nl:
It works just fine here on 2k3 accessing share via DFS.

I will need an access as well as a list of the paths you are trying to access to debug.

If it is not possible, please describe your configuration exactly:
- path to the DFS, their root and namespace as well
- which function you use


 [2010-01-25 12:12 UTC] blc at 3ds dot com
Hello,

Thanks for the quick update. I have just installed it and re-run my previous test code:

- it worked for me when used in UNC directory \\server\path
- it did NOT when used in drive (letter:) mapped on the same path
 [2010-01-25 13:28 UTC] pajoye@php.net
@blc at 3ds dot com

"- it worked for me when used in UNC directory \\server\path
- it did NOT when used in drive (letter:) mapped on the same path"

Ok, thanks for testing! :)

I have now to test the mapped version (mounted path or drive), that's a real mess on windows with shares and mounted paths/mapped drives.
 [2010-01-25 14:16 UTC] blc at 3ds dot com
Maybe it can help: 
I've noticed that with your patch, when using drive path to access file, file_exists('W:/path/to/my/file.txt') now returned TRUE (=the file exists) even if fopen/file/file_get_contents were unable to read it and say "No such file or directory"
 [2010-01-27 00:46 UTC] pajoye@php.net
@blc at 3ds dot com 

I made some tested with shares mounted as drive letters and it works, is_* or reading/writing files contents.

Can you describe exactly your configuration please? For the shares and for the php side as well as how you mounted the shares (GUI, junction, etc.).
 [2010-01-27 08:15 UTC] dd at headlineweb dot nl
i do not have the problem wich blc at 3ds dot com has.

I have a weird thing: when i install php 5.3.3 it works for the 1st time i run the script in the browser. after that it never works again. (also all other users not) when i remove php completely and reinstall it still does not work (also not the 1st time) when i wait 1 day, and install php again, it works again for the first time, and after F5 it wont never work again.

when i try following commandline:

C:\WINDOWS>c:\php53\php -f k:\intranet\doc.php

i get following output:

Array
(
    [0] => .
    [1] => ..
    [2] => Article Ranges
    [3] => Bezoek Verslagen
    [4] => Demo cd
    [5] => Headline Info
    [6] => ParcRanges 2008
    [7] => Software Manuals
)

and that output i get every time i run the commmand, also when i try as another user.
 [2010-01-27 08:27 UTC] pajoye@php.net
@dd at headlineweb dot nl 

Not sure what's happening in your setup. Everything works now as expected in my test configurations, to read, test or write files or directories, using normal shares or DFS.

However we use IIs7, I will have to verify if there is any open bugs in IIS6 in this area (impersonation).

When you say, "it does not work", what is happening? Can you try to post a link to the outpout of processmonitor?
 [2010-01-27 14:41 UTC] blc at 3ds dot com
Hi pajoye

I use php 5.3.1 from the latest xampp installation kit (1.7.3)
It is running on a Windows XP 64bits 2003 SP2
The remote files are on a NetApp server
In between there is only DFS
The only change in my configuration was moving from PHP 5.2.8 to 5.3.1

Today I have the same weird problem than dd at headlineweb dot nl:
when using letter mapping (mapped through GUI) it had worked well once and now 'file_exists' return FALSE !?
 [2010-01-27 14:45 UTC] pajoye@php.net
Using 5.3.1 will not have the fix. Please try using the binary I posted here earlier this week.
 [2010-01-27 16:01 UTC] dd at headlineweb dot nl
I've tried now with different versions of PHP (5.2.11 / 5.3.1 / 5.3.3) all of these versions have problems accessing that share when i install it as CGI module. the 5.2.11 ISAPI module works fine.

i've tried also locally on my XP SP3 & IIS 5 computer with 5.2.11 & 5.3.3 but CGI does not work, ISAPI works fine.

i've tried also on a Vista SP2 IIS 7, but also some results here: CGI does not work, ISAPI works fine.
 [2010-01-27 16:30 UTC] pajoye@php.net
Sorry, but it is just confusing. ISAPI is not the problem and is not maintained anymore either.

The only thing I need to know is whether the binary I gave works in your scenario or not. The one you reported initially.

And to be sure that we are talking about the same thing, are you sure that this share is a DFS (Distributed File System) path?

Anyway, all tests pass here, using the binary I gave earlier:

http://downloads.php.net/pierre/php-5.3.3-dev-nts-Win32-VC9-x86-dfsfix.zip

It is pointless to use 5.3.1, 5.3.0 or 5.2.x as they do not contain the fix about DFS. However 5.3.1 works just fine with normal shares (normal shared path on a given host).

 [2010-01-27 16:46 UTC] svn@php.net
Automatic comment from SVN on behalf of pajoye
Revision: http://svn.php.net/viewvc/?view=revision&revision=294102
Log: - don't go through the reparse code when we have a share or DFS path (should fix #50542)
 [2010-01-28 07:42 UTC] dd at headlineweb dot nl
are you using DFS: Yes
are you sure that this share is a DFS: No, this share itself is not DFS i thought you where talking about the server and not the path.

As you see in my example code: hdlsrv is a DFS enabled server, but the share itself is not DFS.

i'm sorry, maybe i misunderstood the question.

the package you have me http://downloads.php.net/pierre/php-5.3.3-dev-nts-Win32-VC9-x86-dfsfix.zip does not solve the problem.
 [2010-02-13 12:15 UTC] pajoye@php.net
PHP 5.3.2RC2 has been released and contains a fix for network share. It would rock if you can give it a try.

I also asked our test team to setup an environment to reproduce this issue (it works just fine for me in my local 2k3 servers).
 [2010-02-14 13:20 UTC] dd at headlineweb dot nl
Hi pajoye,

sorry, but it still does not solve my problem with this package:

php-5.3.2RC2-nts-Win32-VC9-x86.zip
 [2010-02-17 22:49 UTC] pajoye@php.net
@dd at headlineweb dot nl 

We have setup a test environment with two windows server 2003. File/dir operations work as expected using 5.3.2RC2.

However, it is important to verify that the php user (IUSR_xxx for example) actually has access to the share. That's also means that impersonate must be set. The default IIS user did not have access to the shares (or any other resources but www).

You said earlier that impersonate is set and the user has access to the share. Can you verify that it is actually set? If it still fails, then we will cruelly need access to your config or at least the exact details about the settings you use on each server. So we can setup the exact same config in our labs (at Microsoft).


 [2010-03-09 15:34 UTC] bramus at bram dot us
Just tested both the PHP 5.3.2 and the (in this thread posted) PHP 5.3.3-dev builds and the problem still remains.

The problem occurs on both WIN2K8 (IIS7) and WIN2K8R2 (IIS7.5) servers.
Haven't tested on WIN2K3 though.

And yes, impersonate is enabled (as per instructions as seen on http://learn.iis.net/page.aspx/246/using-fastcgi-to-host-php-applications-on-iis-70/) and the IIS user has access to the needed folder and files (the given site runs fine when PHP 5.2.x is used).

Right now I'm getting this (both PHP 5.3.2 as PHP 5.3.3-dev) returned on a file where the IIS User + the magic "Everyone" has access to:
- file_exists: false
- filesize: stat failed for $file
- file_get_contents: permission denied
- etc.

Regards,
Bram.
 [2010-03-09 15:59 UTC] pajoye@php.net
-Status: No Feedback +Status: Feedback
 [2010-03-09 15:59 UTC] pajoye@php.net
hi Bram,

This doc (IIS link) is incomplete, it is important to remember that the IUSR(_xxx) is impersonate and anonymous. See:

http://support.microsoft.com/kb/207671

This user also has limitations per default, which limits access to remote resources. The reasons and possible workarounds are explain in this kb.

PHP 5.2 impersonation was only partial and fails to actually run a process under the choosen users.

We have tested 5.3 share access (normal shares or DFS) successfully using 2k3, 2k8 (incl. R2 for both). To test it:

- create a userĀ“(site1user for example)
- Open the IIS manager
- change the Physical Path Credentials (iis 7.x) and set it to this new users
- be sure that this user has access to the remote shares
 [2010-03-09 16:26 UTC] bramus at bram dot us
Hi Pajoye,

thanks for your fast reply. I've dugg a bit deeper (thanks to your link) and got it working by leaving ""Physical Path Credentials" untouched (viz. take over the credentials from the Application Pool) and by changing the "Physical Path Credentials Logon Type" from "ClearText" to "Network".

By doing so it now works fine.

Regards and thanks for your help,
Bram.
 [2010-03-09 16:42 UTC] pajoye@php.net
Ah! I was beginning to think that I was either stupid, blind or both :)

Can I consider this issue as solved (but need to be documented, cruelly)?
 [2010-03-09 17:01 UTC] bramus at bram dot us
Hi Pajoye,

my last comment was wrong (had a cached version of a test I ran, therefore I had wrong results).

The correct solution is to actually set the "Physical Path Credentials" and leave "Physical Path Credentials Logon Type" as it is (viz. "ClearText").

This however raises an IIS bug that the credentials of the Application Pool don't get passed to the path correctly, although it's set to take over the App Pool credentials.

Anywho, for now the issue indeed is solved indeed; A tad bit of documentation would be handy indeed ;-)

Regards,
B!
 [2010-03-23 11:57 UTC] dd at headlineweb dot nl
-Status: Feedback +Status: Open
 [2010-03-23 11:57 UTC] dd at headlineweb dot nl
But the above solution does not apply IIS 6, Only > 7?
 [2010-03-23 12:11 UTC] pajoye@php.net
-Status: Open +Status: Feedback
 [2010-03-23 12:11 UTC] pajoye@php.net
It may be different in the various IIS versions (different ways to configure it, between 5, 6 or 7.x) but the principle is exactly the same.

We have tested using IIS6 and 7.x and it works perfectly.
 [2010-06-02 11:18 UTC] dd at headlineweb dot nl
-Status: Feedback +Status: Open
 [2010-06-02 11:18 UTC] dd at headlineweb dot nl
hi all,

its long time ago, but i've solved my problem partially.

i have not been working on this problem a long time till yesterday.

if i deselect "integrated windows authentication" and select "basic authentication" and fill in the realm and default domain boxes. the problem is solved and unc works fine, but then i get a login screen when i open the page. (so IE does not send my credentials anymore)

if i switch it back to the old config, the page loads without login box (IE sends my credentials to the website) but UNC paths wont work.

what can i do about this?
 [2010-06-02 17:20 UTC] sbalazic at gmail dot com
Hi all,
is there any solution for this problem?
I have the same problem
I have this configuration:
- W2k3
- IIS 6.0
- PHP version 5.2.6 (triend with PHP 5.2.13)

If someone of you can give me some more information about solving this issue will be very appreciate.

thnks
 [2010-06-02 17:25 UTC] pajoye@php.net
-Status: Open +Status: Closed
 [2010-06-02 17:25 UTC] pajoye@php.net
It works fine using the correct configuration. See the other comments. Also I'm referring to PHP 5.3 here, not 5.2.
 [2010-11-12 08:53 UTC] d_daemen at hotmail dot com
-: dd@headlineweb.nl +: d_daemen at hotmail dot com
 [2010-11-12 08:53 UTC] d_daemen at hotmail dot com
changed email adress
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 13:01:28 2024 UTC