sshfs-win icon indicating copy to clipboard operation
sshfs-win copied to clipboard

When running with administrative privileges, creating a file with some content causes "Access is denied" error at the first attempt, but the second attempt succeeds

Open Lissanro opened this issue 2 years ago • 7 comments

I do not know if this is a bug or misconfiguration on my end. This how to reproduce. I open one cmd as a normal user and one as an administrator. First, in normal Command Prompt I check that the network drive is not mounted:

c:\>z:
The system cannot find the drive specified.

Then in Administrator Command Prompt I do the same check and I mount the network drive (it is a root filesystem of Linux computer):

c:\>z:
The system cannot find the drive specified.
c:\>net use z: \\sshfs.k\[email protected]\\\\ /Persistent:Yes
The command completed successfully.

Afterwards, I experience different behaviour in them. When I create a file in normal Command Prompt, I get no errors, as expected:

c:\>cd z:\tmp
c:\>z:
z:\tmp>echo test > test.txt
z:\tmp>del test.txt

When I try the same in Administrator Command Prompt, I get "Access is denied" after the first attempt but then the second one succeeds:

c:\>cd z:\tmp
c:\>z:
z:\tmp>echo test > test.txt
Access is denied.
z:\tmp>echo test > test.txt
z:\tmp>del test.txt

This makes no sense to me, "access is denied" but not really? After the first attempt, 0 byte test.txt file is created. After second attempt, the content is actually written to it. Any ideas why it does not work the first time and how to fix it?

This is really strange... If it is permission problem, I would have expected this to be the other way around, when normal users get access denied errors but the administrator who mounted the network drive can do anything.

This issue breaks many scripts and executables which need to create and write to new files, because none of them expects that after denied access error they need just try again to get the job done.

Lissanro avatar Nov 28 '21 01:11 Lissanro

In general when launching SSHFS-Win using net use only the account that launched the file system gets proper access rights. Other accounts may or may not get proper rights depending on how you configured the SSHFS-Win command line.

The reason for this is that the UNIX permission model (that SSHFS-Win uses) and the Windows permission model differ. There is a mapping between the two, but it is by no means perfect.

To troubleshoot such issues you can try the fsptool utility located in \Program Files (x86)\WinFsp\bin. For example, try the following from both the normal prompt and the Administrator prompt.

.\fsptool-x64.exe id
.\fsptool-x64.exe perm Z:\
.\fsptool-x64.exe perm Z:\tmp
.\fsptool-x64.exe perm Z:\tmp\test.txt

This will give us more insight into what permission problem you are having.

billziss-gh avatar Nov 29 '21 12:11 billziss-gh

In general when launching SSHFS-Win using net use only the account that launched the file system gets proper access rights.

This is what I expected too but not what I'm observing. First, I right click on PowerShell and choose to run as Administrator, and then in Administrator PowerShell (in cmd results are the same, but PowerShell is a bit more convenient) I mount z: with command net use z: \\sshfs.k\[email protected]\\\\ /persistent:Yes and then run few more commands (test.txt does not exist until I try to create it):

PS C:\Windows\system32> net use z: \\sshfs.k\[email protected]\\\\ /persistent:Yes
The command completed successfully.

PS C:\Windows\system32> & 'C:\Program Files (x86)\WinFsp\bin\fsptool-x64.exe' id
User=S-1-5-21-2932393898-244610722-2614320368-1001(WINDOWS\Lissanro Rayen) (uid=197609)
Owner=S-1-5-32-544(BUILTIN\Administrators) (uid=544)
Group=S-1-5-21-2932393898-244610722-2614320368-513(WINDOWS\None) (gid=197121)
PS C:\Windows\system32> & 'C:\Program Files (x86)\WinFsp\bin\fsptool-x64.exe' perm z:\
O:S-1-5-21-2932393898-244610722-2614320368-1001G:S-1-5-21-2932393898-244610722-2614320368-513D:P(A;;FA;;;S-1-5-21-2932393898-244610722-2614320368-1001)(A;;0x1200a9;;;S-1-5-21-2932393898-244610722-2614320368-513)(A;;0x1200a9;;;WD) (perm=197609:197121:0755)
PS C:\Windows\system32> & 'C:\Program Files (x86)\WinFsp\bin\fsptool-x64.exe' perm z:\tmp
O:S-1-5-21-2932393898-244610722-2614320368-1001G:S-1-5-21-2932393898-244610722-2614320368-513D:P(A;;FA;;;S-1-5-21-2932393898-244610722-2614320368-1001)(A;;0x1201af;;;S-1-5-21-2932393898-244610722-2614320368-513)(A;;0x1201af;;;WD) (perm=197609:197121:1777)
PS C:\Windows\system32> echo test > z:\tmp\test.txt
out-file : Access to the path 'z:\tmp\test.txt' is denied.
At line:1 char:1
+ echo test > z:\tmp\test.txt
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OpenError: (:) [Out-File], UnauthorizedAccessException
    + FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.OutFileCommand

PS C:\Windows\system32> & 'C:\Program Files (x86)\WinFsp\bin\fsptool-x64.exe' perm z:\tmp\test.txt
O:S-1-5-21-2932393898-244610722-2614320368-1001G:S-1-5-21-2932393898-244610722-2614320368-513D:P(A;;0x1f01bf;;;S-1-5-21-2932393898-244610722-2614320368-1001)(A;;0x120088;;;S-1-5-21-2932393898-244610722-2614320368-513)(A;;0x120088;;;WD) (perm=197609:197121:0700)
PS C:\Windows\system32> echo test > z:\tmp\test.txt
PS C:\Windows\system32> & 'C:\Program Files (x86)\WinFsp\bin\fsptool-x64.exe' perm z:\tmp\test.txt
O:S-1-5-21-2932393898-244610722-2614320368-1001G:S-1-5-21-2932393898-244610722-2614320368-513D:P(A;;0x1f01bf;;;S-1-5-21-2932393898-244610722-2614320368-1001)(A;;0x120088;;;S-1-5-21-2932393898-244610722-2614320368-513)(A;;0x120088;;;WD) (perm=197609:197121:0700)
PS C:\Windows\system32> del z:\tmp\test.txt

Then I run the same commands in normal PowerShell:

PS C:\Users\Lissanro Rayen> & 'C:\Program Files (x86)\WinFsp\bin\fsptool-x64.exe' id
User=S-1-5-21-2932393898-244610722-2614320368-1001(WINDOWS\Lissanro Rayen) (uid=197609)
Owner=S-1-5-21-2932393898-244610722-2614320368-1001(WINDOWS\Lissanro Rayen) (uid=197609)
Group=S-1-5-21-2932393898-244610722-2614320368-513(WINDOWS\None) (gid=197121)
PS C:\Users\Lissanro Rayen> & 'C:\Program Files (x86)\WinFsp\bin\fsptool-x64.exe' perm z:\
O:S-1-5-21-2932393898-244610722-2614320368-1001G:S-1-5-21-2932393898-244610722-2614320368-513D:P(A;;FA;;;S-1-5-21-2932393898-244610722-2614320368-1001)(A;;0x1200a9;;;S-1-5-21-2932393898-244610722-2614320368-513)(A;;0x1200a9;;;WD) (perm=197609:197121:0755)
PS C:\Users\Lissanro Rayen> & 'C:\Program Files (x86)\WinFsp\bin\fsptool-x64.exe' perm z:\tmp
O:S-1-5-21-2932393898-244610722-2614320368-1001G:S-1-5-21-2932393898-244610722-2614320368-513D:P(A;;FA;;;S-1-5-21-2932393898-244610722-2614320368-1001)(A;;0x1201af;;;S-1-5-21-2932393898-244610722-2614320368-513)(A;;0x1201af;;;WD) (perm=197609:197121:1777)
PS C:\Users\Lissanro Rayen> echo test > z:\tmp\test.txt
PS C:\Users\Lissanro Rayen> & 'C:\Program Files (x86)\WinFsp\bin\fsptool-x64.exe' perm z:\tmp\test.txt
O:S-1-5-21-2932393898-244610722-2614320368-1001G:S-1-5-21-2932393898-244610722-2614320368-513D:P(A;;0x1f01bf;;;S-1-5-21-2932393898-244610722-2614320368-1001)(A;;0x120088;;;S-1-5-21-2932393898-244610722-2614320368-513)(A;;0x120088;;;WD) (perm=197609:197121:0700)
PS C:\Users\Lissanro Rayen> del z:\tmp\test.txt

I'm not really familiar with Windows permission system, so I would appreciate any ideas what could be wrong, why I am getting "Access denied" error in Administrator PowerShell (the same is true if I do this in cmd), but despite the error, a file of 0 length is created, and then on second try I can write to it? And even though I mount the z: disk in Administrator PowerShell, as normal user I encounter no issues writing to a new file.

Lissanro avatar Dec 05 '21 13:12 Lissanro

Hello everyone, I'm stuck on this problem. Does anyone have a solution? Thanks for help. Regards,

PS:

  • winfsp-1.9.21096
  • sshfs-win-3.5.20357-x64

rascalos avatar Jan 13 '22 09:01 rascalos

I bring some information on my problem. I am using sshfs from windows 7 sp1 to share a directory of a machine in RHEL5. When I am logged in with the Administrator account and want to create a folder, I get a "Windows explorer has stopped working" message. I select the option "Restart the program". When I want to create a text file, I get the error "Unable to create the file" New Document.txt ', the parameter is incorrect ". When I refresh the display I see that two files have been created" New Document "and" New Document (2) ". While the same commands on a Windows 7 machine user account work fine. I hope I have provided you with the information you need to resolve this problem. Thanks for your help. Regards,

rascalos avatar Jan 13 '22 10:01 rascalos

+1 Really suffering from this one on a Win 10 Insider Dev VM hosted in openSUSE 15.3. Rolling back to previous versions that used to work does not help.

ssgromov avatar Feb 01 '22 19:02 ssgromov

Could this be because you have a Space in your username?

JonasDev17 avatar Mar 10 '22 15:03 JonasDev17

As far as I remember, the issue wan't caused by a space in Windows username, and the UNIX username is without space. Anyway, in newer Windows installation where my Windows name is without spaces, it does not work any better.

Lissanro avatar Jul 10 '22 19:07 Lissanro