Strange access issue with Ruby and network drives #242
Comments
|
Where'd you get your ruby from? |
|
RubyInstaller. Version 2.1.5p273. |
|
Do both folders contain files or is one of them empty? |
|
Can you show the output from: |
|
Both have files obviously. Did you mean Dir["//server1/other/path/"]? |
|
|
It is not obvious at all, and why would it be? I wanted you to reply with what I asked for as I want to see if MSYS2 mangles your arguments. |
|
The output is just the same without Dir. If there weren't files and it would return an empty list, why would I file an issue? |
|
Can you check the command lines that are used to invoke ruby in Process Monitor? (It's the "Process Start" event.) |
|
You weren't clear about what "One works, while the other doesn't" meant. Github mangled my "*"'s, I wanted to see the output of: .. but the Process Start command lines should be enough anyway. |
|
The Process Start looks the same for both paths: |
|
Do they look the same when started from MSYS and MSYS2? |
|
Exactly the same. It's the same also on cmd. |
|
I wonder what else could be affecting the results. What terminals are you using? Can you also try from Cygwin? |
|
Doesn't work in cygwin (both 32 and 64 bit). |
|
And terminals? Is it possible that the difference between the working environments and the non-woking ones is in mintty? |
|
On cygwin I use the default terminal. Which other terminals are available? |
|
The two basic options are the Windows console host and mintty. I don't know which one is the default for Cygwin, but MSYS2 uses mintty as default and AFAIK MSYS1 uses the Windows console. |
|
The default of MSYS1 (which works) looks exactly like the default for Cygwin (which fails). MSYS2 uses mintty here, so it doesn't look related to the terminal type. |
|
Cygwin and MSYS2 both use a very recent mintty, MSYS1 uses a very old mintty. |
|
Is there a way to pick an alternative shell with cygwin? |
|
From cmd.exe, do: .. and see what results you get. |
|
Fails. |
|
.. and finally, same thing without --login -i |
|
Fails. |
|
So bash or MSYS2 is somehow poisoning the environment .. which MSYS2 are you running? The WIP git-for-Windows one or ours? |
|
Tried both. But official cygwin also fails. |
|
I'm fairly out of ideas; if you are able to post detailed procmon logs somewhere then we can scan those for differences. |
|
This is a full procmon log filtered by ruby.exe process name. The working server is //netapp1/CM/CompilationResults, the failing one is //aclnas01/versions/CompilationResults. The log contains 2 successful executions with MSYS1 which succeed (1 for each server), then a successful execution with MSYS2 to netapp1, and the last one is for aclnas01 which fails (notice ACCESS DENIED at line 9902). |
|
The servers seem to have different access permissions. Non working one has: A is archiving .. are these both just normal smb shares? Can you remove archiving flag to see if it makes any difference? |
|
This may be of interest too: http://blogs.msdn.com/b/oldnewthing/archive/2009/02/19/9432917.aspx A could mean "needs archiving" but it could also mean encrypted or compressed. |
|
Also, MSYS1: vs MSYS2: I'm not sure what this "Open For Backup" means, but it does sound archiving-related. |
|
This thread looks very interesting in this regard: |
AFAIK, this is primarily used for archiving purposes, but is also used by Cygwin to gain access to files that would be inaccessible without it (in case the user/process possesses SeBackupPrivilege), probably to emulate the all-doors-open rights of root accounts in the POSIX world. |
|
Out of curiosity, I built the MSYS2 runtime with all occurrences of "Open for Backup" flag removed: msys-runtime, msys2-runtime.sig, msys-runtime-devel, msys2-runtime-devel.sig. I'm not sure if I actually succeeded, but give it a try. |
|
@elieux: Thanks for your effort. Unfortunately, it doesn't solve the issue. |
@mingwandroid I only have read access to these servers. I can't test that. |
|
Ok, I was able to reproduce with a minimal working example: Any ideas how to investigate it further? |
|
2 days ago I posted this bug report to the cygwin mailing list. It still wasn't answered. Some more insights follow. Using Wireshark, I discovered that aclnas01 uses SMB, while netapp1 uses SMB2. For some reason, when executed from command prompt, a FIND_FIRST2 request is sent and the server replies, while with cygwin a "NT Create AndX" request is sent and denied. To minimize the captured packets, I executed the application twice, and captured only the second execution (to avoid session initiation). Working capture Does cygwin implement SMB on its own, or is this difference a |
|
I just found another SMB1 linux server, which does work. It first has a "NT Create AndX" request for path , which succeeds. Then it issues Trans2 FIND_FIRST2 request for the real path (\a). This issue might be related to the Archive bit which is set on aclnas01. |
|
Hi, After investigation, I found that the root cause for this problem is Commenting out these 2 lines solves the problem for me. I have no idea if it breaks anything. |
|
Ok, I was able to fix the issue by removing the privileges in my script. If anyone with this problem reaches here, the script follows: def remove_privileges
return unless RUBY_PLATFORM.include?('mingw')
require 'win32/api'
_AdjustTokenPrivileges = Win32::API.new('AdjustTokenPrivileges', 'LBPLPP', 'B', 'advapi32')
_OpenProcessToken = Win32::API.new('OpenProcessToken', 'LLP', 'B', 'advapi32')
_GetCurrentProcess = Win32::API.new('GetCurrentProcess', 'V', 'L', 'kernel32')
_TOKEN_ADJUST_PRIVILEGES = 0x0020
token = [0].pack('l')
_OpenProcessToken.call(_GetCurrentProcess.call, _TOKEN_ADJUST_PRIVILEGES, token)
token = token.unpack('l').first
_AdjustTokenPrivileges.call(token, true, 0, 0, 0, 0)
end |
Hi,
I'm trying to access 2 network drives from msys2 shell using ruby. One works, while the other doesn't.
The same command works with msys1.
Needless to say, the same version of Ruby is used on both environments.
Process Monitor shows that for server2 CreateFile is invoked for
//server2/other/path/with a trailing slash, which results in Access Denied, while with msys1 or cmd, and for server1 even with msys2, there isn't a trailing slash.The path length is the same for both servers (1 share name, 1 path under it).
I have no idea what type of servers these are.
Is there a way to debug this problem?
The text was updated successfully, but these errors were encountered: