core icon indicating copy to clipboard operation
core copied to clipboard

New Users on Windows Systems can`t login

Open ForumSchlampe opened this issue 13 years ago • 18 comments

When new user try to login the php-cgi.exe runs in a loop and log gets spammed with the following entries: {"app":"PHP","message":"readdir() expects parameter 1 to be resource, boolean given at C:\inetpub\OwnCloud\lib\files\storage\mappedlocal.php#48","level":2,"time":"2013-09-18T06:54:14+00:00"}

I think this is caused by OC isnt able to create a user datadir cause of the / \ difference of unix/Windows Systems (privileges are correct).

When you create the user datadir manually or let it create through run "php console.php files:scan --all" the login is successfull and all works fine.

Hope someone can fix this

ForumSchlampe avatar Sep 18 '13 09:09 ForumSchlampe

@ForumSchlampe which version of oc are you running? @ringmaster Can you have a look? THX

DeepDiver1975 avatar Sep 18 '13 09:09 DeepDiver1975

I'm also having this issue on ownCloud 5.0.11

mattman86 avatar Sep 18 '13 19:09 mattman86

@DeepDiver1975 Hi DeepDiver, i use OC 5.0.11 with php5.3 and 5.4 on Windows Server 2008 R2 (but problem can be reproduced on any Windowssystem i think) There are also others with the same problem see http://forum.owncloud.org/viewtopic.php?f=23&t=15829 and http://forum.owncloud.org/viewtopic.php?f=23&t=15811 and myself http://forum.owncloud.org/viewtopic.php?f=23&t=16053

I think this is a serious one cause it prevents users completely from using OC 5.0.11 hosted on Windows without workaround (in case of a clean/new install).

ForumSchlampe avatar Sep 19 '13 06:09 ForumSchlampe

from: http://forum.owncloud.org/viewtopic.php?f=23&t=15829&p=41871#p41830

modifying the line 48 of /lib/files/storage/mappedlocal.php file

change while (($file = readdir($dh)) !== false) {

to while ($file = readdir($dh)) {

mockodin avatar Sep 20 '13 22:09 mockodin

Works for me...

ForumSchlampe avatar Sep 23 '13 08:09 ForumSchlampe

it does not work instead does not even let the admin user login ,after the change once admin tries to log in ,it right away comes up with this error message

The website cannot display the page

HTTP 500

thanks

qazi1214 avatar Sep 23 '13 15:09 qazi1214

@qazi1214 please recheck your changes, note that one ( after the while has to be remove, too! HTTP 500 after this change indicates you broke the code but the given code is valid....so you must have pasted somthing wrong ;)

ForumSchlampe avatar Sep 23 '13 18:09 ForumSchlampe

I just ran an install on IIS 7.5 & PHP 5.4.14 of ownCloud 5.0.11, and it's working fine for me.

I would not expect the above hack to solve any Windows-related problems, since readdir() returns boolean false when there are no more directories to read. If you just evaluate the return value, and you have a directory named "false" (one of many examples), then it'll evaluate to false and skip any remaining directories. So I think this is not a viable solution, and even then don't know how it's fixing the issues you describe (which I admittedly don't see).

Do you have any more information about your environment that might narrow down why this is happening for you and not for me? Some explicit steps to repeat that maybe I didn't start out with?

ringmaster avatar Sep 23 '13 21:09 ringmaster

@ringmaster If you were looking at something like while (readdir($dh)) { then yes it evaluates readdir() as $true or $false however while ($file = readdir($dh)) { evaluates if $file is successfully set to a path value. If while ($file = readdir($dh)) { did as you indicated it would be an endless loop because setting $file = $false would be evaluated as success

If what I'm saying is incorrect then PHP is diverging (and it does at time) from other coding languages such as perl, c#, etc...

-edit- As far as setups differences. In my case, brand new installation, I moved my data directory at one point. However with permissions being validated and such, nothing presented itself as obviously incorrect. I'm also running Windows 2012 which may have an impact but I see that as unlikely without further information at this point. Only my initial admin user auto created the folder. I think a few times I saw creation occur if I manually pasted url to another screen after attempting log-in.. I haven't purposefully tested that however so thus it is unconfirmed.

mockodin avatar Sep 23 '13 23:09 mockodin

@ringmaster @mockodin hm i can reproduce this behaviour with php IIS 7, 7.5 and 8 with PHP 5.4.19 and 5.5.3 used as fastcgi All on clean installations and i think the config i use is correct so far because it works like expected after the change.

@ringmaster can you provide your php.ini and an icacls output of your datadir? (maybe the web.config, too?) So i can recheck if i have done something wrong (and all those others with the same problem)

rechecked it with php 5.4.14, i can reproduce the reported problem....after the code change it works like expected (but i dont have any knowledge in php coding ;) )

ForumSchlampe avatar Sep 24 '13 12:09 ForumSchlampe

@mockodin Sorry for the confusion. What I mean is that if readdir() returns a string value that evaluates to boolean false (my mistake was saying that 'false' is one of these, which it is not, but "0" and others are), then the loop will exit prematurely.

The !== false compares the value of the assigned variable $file to boolean false, rather than using implied typecasting of string values to booleans. Omitting that part of the evaluation should only cause bad things to happen. Some sample code might help explain: http://codepad.org/3LUCc8CX

If changing this evaluation does fix the issue, learning why it does could yield a proper solution, but I remain skeptical that this is a true fix.

@ForumSchlampe I'll try it again today on a clean 2012 VM and see if I can get you that, but this server is pretty stock.

ringmaster avatar Sep 24 '13 13:09 ringmaster

Test Process:

  • Deleted contents of wwwroot directory, dropped OC5 database, dropped oc_admin user, created OC5 database.
  • Extracted 5.0.11 zip to wwwroot.
  • Created data directory. Assigned Full permissions to "IUSR" account for data, apps, and config directories.
  • Ran installer to connect to OC5 database. Installer reports expected WebDAV errors.
  • In ownCloud user admin, added user "alice" with password "password". no group selected.
  • Logged out, logged in as "alice".

Failure achieved. Investigating... Ok, I think I've figured this out.

On every login, ownCloud does a garbage collection run through the file cache that exists in the user directory. Of course, when the user first logs in, their user directory hasn't been created yet. false is returned for the handle from the $dh = opendir($physicalPath) call because the directory doesn't exist, and the subsequent call to $file = readdir($dh) generates an error because $dh is false, not a valid directory handle. Thus, an endless supply of log errors. And if the directory is successfully created, the handle is properly returned and everything runs smoothly.

The fix seems simple: Wrap the while() loop with an if() that verifies the integrity of the directory handle.

edit - For those interested in why it worked for me before, there is apparently some issue with directory permissions. If I allow the Users group edit permissions to the whole webroot (something I did during the course of testing so I could edit some source), I don't get the error at all. But if I confine edit permissions to the IUSR group, as well an administrator should, then the error occurs. I'm not sure why that is exactly, but since the error happens in the more correct security posture, it's probably for the best to fix the issue rather than attribute it to a file permission setting.

ringmaster avatar Sep 24 '13 16:09 ringmaster

@ringmaster

Confirmed, I might suggest to reduce the code a bit to simply alter the while() line

From: while (($file = readdir($dh)) !== false) {

To:

while ($dh && ($file = readdir($dh)) !== false) {

mockodin avatar Sep 24 '13 16:09 mockodin

Clarity > Brevity

Also, if the $dh is in the while(), it needs to evaluate it in each loop pass, so not accounting for optimization, this should also turn out to be slower. :wink: Stick with the if()?

ringmaster avatar Sep 24 '13 17:09 ringmaster

@ringmaster Fair enough, you are quite correct; for smaller environments (less than a few thousand users) likely the impact would be unnoticeable but then no need to introduce unneeded cycles regardless of size/impact :-)

mockodin avatar Sep 24 '13 17:09 mockodin

And what do you know, this is already fixed in OC6. This commit can probably be cherry-picked to stable5.

ringmaster avatar Sep 24 '13 17:09 ringmaster

Nothing like spending all that time testing to find out your issue is fixed downstream. It's also in stable5 already: 86eab2ee6c272e36a0757b38eeb192f9fd1d1f98 But it's not in the release zip for 5.0.11...

ringmaster avatar Sep 24 '13 20:09 ringmaster

@ringmaster thanks for testing :-) So is it "safe" to use the changes in https://github.com/owncloud/core/commit/86eab2ee6c272e36a0757b38eeb192f9fd1d1f98 ? (works for me)

I think i can close this, right?

ForumSchlampe avatar Sep 25 '13 13:09 ForumSchlampe