NTDirectoryFileSystem: Pass-through LockFile / UnlockFile requests

This commit is contained in:
Tal Aloni 2017-08-31 15:58:43 +03:00
parent e7da671877
commit dfbda03f6c
2 changed files with 14 additions and 4 deletions

View file

@ -32,6 +32,7 @@ namespace SMBLibrary
STATUS_DATA_ERROR = 0xC000003E, // IO error
STATUS_SHARING_VIOLATION = 0xC0000043,
STATUS_FILE_LOCK_CONFLICT = 0xC0000054,
STATUS_LOCK_NOT_GRANTED = 0xC0000055,
STATUS_PRIVILEGE_NOT_HELD = 0xC0000061,
STATUS_LOGON_FAILURE = 0xC000006D, // Authentication failure.
STATUS_ACCOUNT_RESTRICTION = 0xC000006E, // The user has an empty password, which is not allowed
@ -39,6 +40,7 @@ namespace SMBLibrary
STATUS_INVALID_WORKSTATION = 0xC0000070,
STATUS_PASSWORD_EXPIRED = 0xC0000071,
STATUS_ACCOUNT_DISABLED = 0xC0000072,
STATUS_RANGE_NOT_LOCKED = 0xC000007E,
STATUS_DISK_FULL = 0xC000007F,
STATUS_INSUFFICIENT_RESOURCES = 0xC000009A,
STATUS_MEDIA_WRITE_PROTECTED = 0xC00000A2,

View file

@ -73,7 +73,7 @@ namespace SMBLibrary.Win32
[DllImport("ntdll.dll", ExactSpelling = true, SetLastError = false)]
private static extern NTStatus NtClose(IntPtr handle);
[DllImport("ntdll.dll", ExactSpelling = true, SetLastError = false)]
private static extern NTStatus NtReadFile(IntPtr handle, IntPtr evt, IntPtr apcRoutine, IntPtr apcContext, out IO_STATUS_BLOCK ioStatusBlock, byte[] buffer, uint length, ref long byteOffset, IntPtr key);
@ -82,7 +82,13 @@ namespace SMBLibrary.Win32
[DllImport("ntdll.dll", ExactSpelling = true, SetLastError = false)]
private static extern NTStatus NtFlushBuffersFile(IntPtr handle, out IO_STATUS_BLOCK ioStatusBlock);
[DllImport("ntdll.dll", ExactSpelling = true, SetLastError = false)]
private static extern NTStatus NtLockFile(IntPtr handle, IntPtr evt, IntPtr apcRoutine, IntPtr apcContext, out IO_STATUS_BLOCK ioStatusBlock, ref long byteOffset, ref long length, uint key, bool failImmediately, bool exclusiveLock);
[DllImport("ntdll.dll", ExactSpelling = true, SetLastError = false)]
private static extern NTStatus NtUnlockFile(IntPtr handle, out IO_STATUS_BLOCK ioStatusBlock, ref long byteOffset, ref long length, uint key);
[DllImport("ntdll.dll", ExactSpelling = true, SetLastError = false)]
private static extern NTStatus NtQueryDirectoryFile(IntPtr handle, IntPtr evt, IntPtr apcRoutine, IntPtr apcContext, out IO_STATUS_BLOCK ioStatusBlock, byte[] fileInformation, uint length, uint fileInformationClass, bool returnSingleEntry, ref UNICODE_STRING fileName, bool restartScan);
@ -227,12 +233,14 @@ namespace SMBLibrary.Win32
public NTStatus LockFile(object handle, long byteOffset, long length, bool exclusiveLock)
{
return NTStatus.STATUS_NOT_SUPPORTED;
IO_STATUS_BLOCK ioStatusBlock;
return NtLockFile((IntPtr)handle, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, out ioStatusBlock, ref byteOffset, ref length, 0, true, exclusiveLock);
}
public NTStatus UnlockFile(object handle, long byteOffset, long length)
{
return NTStatus.STATUS_NOT_SUPPORTED;
IO_STATUS_BLOCK ioStatusBlock;
return NtUnlockFile((IntPtr)handle, out ioStatusBlock, ref byteOffset, ref length, 0);
}
public NTStatus QueryDirectory(out List<QueryDirectoryFileInformation> result, object handle, string fileName, FileInformationClass informationClass)