mirror of
				https://github.com/winfsp/winfsp.git
				synced 2025-10-30 19:48:38 -05:00 
			
		
		
		
	winfsp-tests: getfileattr_test
This commit is contained in:
		| @@ -28,6 +28,136 @@ | ||||
|  | ||||
| #include "winfsp-tests.h" | ||||
|  | ||||
| void getfileattr_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInfoTimeout) | ||||
| { | ||||
|     void *memfs = memfs_start_ex(Flags, FileInfoTimeout); | ||||
|  | ||||
|     HANDLE Handle; | ||||
|     BOOL Success; | ||||
|     WCHAR Dir1Path[MAX_PATH]; | ||||
|     WCHAR FilePath[MAX_PATH]; | ||||
|     DWORD FileAttributes; | ||||
|     PSECURITY_DESCRIPTOR SecurityDescriptor; | ||||
|     SECURITY_ATTRIBUTES SecurityAttributes = { 0 }; | ||||
|  | ||||
|     StringCbPrintfW(FilePath, sizeof FilePath, L"%s%s\\file0", | ||||
|         Prefix ? L"" : L"\\\\?\\GLOBALROOT", Prefix ? Prefix : memfs_volumename(memfs)); | ||||
|  | ||||
|     Handle = CreateFileW(FilePath, | ||||
|         GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, | ||||
|         CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0); | ||||
|     ASSERT(INVALID_HANDLE_VALUE != Handle); | ||||
|  | ||||
|     FileAttributes = GetFileAttributesW(FilePath); | ||||
|     ASSERT(INVALID_FILE_ATTRIBUTES != FileAttributes); | ||||
|  | ||||
|     CloseHandle(Handle); | ||||
|  | ||||
|     Success = DeleteFileW(FilePath); | ||||
|     ASSERT(Success); | ||||
|  | ||||
|     StringCbPrintfW(Dir1Path, sizeof Dir1Path, L"%s%s\\dir1", | ||||
|         Prefix ? L"" : L"\\\\?\\GLOBALROOT", Prefix ? Prefix : memfs_volumename(memfs)); | ||||
|  | ||||
|     StringCbPrintfW(FilePath, sizeof FilePath, L"%s%s\\dir1\\file0", | ||||
|         Prefix ? L"" : L"\\\\?\\GLOBALROOT", Prefix ? Prefix : memfs_volumename(memfs)); | ||||
|  | ||||
|     /* create directory with SYNCHRONIZE|DELETE|FILE_READ_ATTRIBUTES|FILE_ADD_FILE access only */ | ||||
|     Success = ConvertStringSecurityDescriptorToSecurityDescriptorW( | ||||
|         L"D:P(A;;0x00110082;;;SY)(A;;0x00110082;;;BA)(A;;0x00110082;;;WD)", SDDL_REVISION_1, &SecurityDescriptor, 0); | ||||
|     ASSERT(Success); | ||||
|     SecurityAttributes.nLength = sizeof SecurityAttributes; | ||||
|     SecurityAttributes.lpSecurityDescriptor = SecurityDescriptor; | ||||
|     Success = CreateDirectoryW(Dir1Path, &SecurityAttributes); | ||||
|     ASSERT(Success); | ||||
|     LocalFree(SecurityDescriptor); | ||||
|  | ||||
|     /* create file with DELETE access only */ | ||||
|     Success = ConvertStringSecurityDescriptorToSecurityDescriptorW( | ||||
|         L"D:P(A;;SD;;;SY)(A;;SD;;;BA)(A;;SD;;;WD)", SDDL_REVISION_1, &SecurityDescriptor, 0); | ||||
|     ASSERT(Success); | ||||
|     SecurityAttributes.nLength = sizeof SecurityAttributes; | ||||
|     SecurityAttributes.lpSecurityDescriptor = SecurityDescriptor; | ||||
|     Handle = CreateFileW(FilePath, | ||||
|         GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, &SecurityAttributes, | ||||
|         CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0); | ||||
|     ASSERT(INVALID_HANDLE_VALUE != Handle); | ||||
|     LocalFree(SecurityDescriptor); | ||||
|  | ||||
|     FileAttributes = GetFileAttributesW(FilePath); | ||||
|     ASSERT(INVALID_FILE_ATTRIBUTES == FileAttributes); | ||||
|     ASSERT(ERROR_ACCESS_DENIED == GetLastError()); | ||||
|  | ||||
|     CloseHandle(Handle); | ||||
|  | ||||
|     Success = DeleteFileW(FilePath); | ||||
|     ASSERT(Success); | ||||
|  | ||||
|     Success = RemoveDirectoryW(Dir1Path); | ||||
|     ASSERT(Success); | ||||
|  | ||||
|     StringCbPrintfW(Dir1Path, sizeof Dir1Path, L"%s%s\\dir2", | ||||
|         Prefix ? L"" : L"\\\\?\\GLOBALROOT", Prefix ? Prefix : memfs_volumename(memfs)); | ||||
|  | ||||
|     StringCbPrintfW(FilePath, sizeof FilePath, L"%s%s\\dir2\\file0", | ||||
|         Prefix ? L"" : L"\\\\?\\GLOBALROOT", Prefix ? Prefix : memfs_volumename(memfs)); | ||||
|  | ||||
|     /* create directory with SYNCHRONIZE|DELETE|FILE_READ_ATTRIBUTES|FILE_ADD_FILE|FILE_LIST_DIRECTORY access only */ | ||||
|     Success = ConvertStringSecurityDescriptorToSecurityDescriptorW( | ||||
|         L"D:P(A;;0x00110083;;;SY)(A;;0x00110083;;;BA)(A;;0x00110083;;;WD)", SDDL_REVISION_1, &SecurityDescriptor, 0); | ||||
|     ASSERT(Success); | ||||
|     SecurityAttributes.nLength = sizeof SecurityAttributes; | ||||
|     SecurityAttributes.lpSecurityDescriptor = SecurityDescriptor; | ||||
|     Success = CreateDirectoryW(Dir1Path, &SecurityAttributes); | ||||
|     ASSERT(Success); | ||||
|     LocalFree(SecurityDescriptor); | ||||
|  | ||||
|     /* create file with DELETE access only */ | ||||
|     Success = ConvertStringSecurityDescriptorToSecurityDescriptorW( | ||||
|         L"D:P(A;;SD;;;SY)(A;;SD;;;BA)(A;;SD;;;WD)", SDDL_REVISION_1, &SecurityDescriptor, 0); | ||||
|     ASSERT(Success); | ||||
|     SecurityAttributes.nLength = sizeof SecurityAttributes; | ||||
|     SecurityAttributes.lpSecurityDescriptor = SecurityDescriptor; | ||||
|     Handle = CreateFileW(FilePath, | ||||
|         GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, &SecurityAttributes, | ||||
|         CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0); | ||||
|     ASSERT(INVALID_HANDLE_VALUE != Handle); | ||||
|     LocalFree(SecurityDescriptor); | ||||
|  | ||||
|     FileAttributes = GetFileAttributesW(FilePath); | ||||
|     ASSERT(INVALID_FILE_ATTRIBUTES != FileAttributes); | ||||
|  | ||||
|     CloseHandle(Handle); | ||||
|  | ||||
|     Success = DeleteFileW(FilePath); | ||||
|     ASSERT(Success); | ||||
|  | ||||
|     Success = RemoveDirectoryW(Dir1Path); | ||||
|     ASSERT(Success); | ||||
|  | ||||
|     memfs_stop(memfs); | ||||
| } | ||||
|  | ||||
| void getfileattr_test(void) | ||||
| { | ||||
|     if (NtfsTests) | ||||
|     { | ||||
|         WCHAR DirBuf[MAX_PATH]; | ||||
|         GetTestDirectory(DirBuf); | ||||
|         getfileattr_dotest(-1, DirBuf, 0); | ||||
|     } | ||||
|     if (WinFspDiskTests) | ||||
|     { | ||||
|         getfileattr_dotest(MemfsDisk, 0, 0); | ||||
|         getfileattr_dotest(MemfsDisk, 0, 1000); | ||||
|     } | ||||
|     if (WinFspNetTests) | ||||
|     { | ||||
|         getfileattr_dotest(MemfsNet, L"\\\\memfs\\share", 0); | ||||
|         getfileattr_dotest(MemfsNet, L"\\\\memfs\\share", 1000); | ||||
|     } | ||||
| } | ||||
|  | ||||
| void getfileinfo_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInfoTimeout) | ||||
| { | ||||
|     void *memfs = memfs_start_ex(Flags, FileInfoTimeout); | ||||
| @@ -1798,6 +1928,7 @@ void setvolinfo_test(void) | ||||
|  | ||||
| void info_tests(void) | ||||
| { | ||||
|     TEST(getfileattr_test); | ||||
|     TEST(getfileinfo_test); | ||||
|     TEST(getfileinfo_name_test); | ||||
|     TEST(setfileinfo_test); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user