My task is: access some files on SMB share, for which the current Windows user has no access.
My solution is: LogonUser(NEW_CREDENTIALS) + ImpersonateLoggedOnUser, then do all CreateFile calls under this impersonation. Actually, each CreateFile is wrapped around by ImpersonateLoggedOnUser/RevertToSelf.
When I’m just plain opening 1 file to read it sequentially - this works.
But now I need to access some files whose format I don’t know, via the calls to 3rd party source-less DLL which can access these files as their “engine”.
I also wrap each call to this DLL via ImpersonateLoggedOnUser/RevertToSelf.
In this case, the thing usually (but not always) fails, in a very nasty mode.
First, it hangs for about 30 seconds in NtQueryDirectoryFile (called by the DLL). Then this syscall usually (not always) fails with STATUS_CONNECTION_DISCONNECTED.
Adding WNetAddConnection2 call just before the DLL calls solves the issue.
The question is: is LogonUser(NEW_CREDENTIALS) really supported for SMB work? if not - can I call something similar to WNetAddConnection2 but without cleartext credentials, the same logic but which will use the current thread’s token and its LSA context instead of username/password pair?
Also - what is going on? what is the reason for the SMB redir (OS: 2008 non-R2 both sides) to wait for such a long time and then fail with STATUS_CONNECTION_DISCONNECTED? can somebody with source access respond? I just cannot understand this status code in the scenario where I have not call any WNet APIs and just opened the file.
–
Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com