X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=src%2Fwin32_common.c;h=412421ea28ce1480cb56bcea651c2b6896e038e4;hb=aae154ad67444bc760bedff60bc60fd5b91b8ede;hp=abfe0a82610c476bcf143099ea4846b5c278e788;hpb=76a22e5ce6caa1f8985071d4316ab12b86da7f10;p=wimlib diff --git a/src/win32_common.c b/src/win32_common.c index abfe0a82..412421ea 100644 --- a/src/win32_common.c +++ b/src/win32_common.c @@ -371,28 +371,22 @@ win32_release_capture_and_apply_privileges(void) win32_modify_apply_privileges(false); } -HANDLE -win32_open_existing_file(const wchar_t *path, DWORD dwDesiredAccess) -{ - return CreateFile(path, - dwDesiredAccess, - FILE_SHARE_READ, - NULL, /* lpSecurityAttributes */ - OPEN_EXISTING, - FILE_FLAG_BACKUP_SEMANTICS | - FILE_FLAG_OPEN_REPARSE_POINT, - NULL /* hTemplateFile */); -} - /* Pointers to dynamically loaded functions */ -/* kernel32.dll: Vista and later */ -BOOL (WINAPI *func_CreateSymbolicLinkW)(const wchar_t *lpSymlinkFileName, - const wchar_t *lpTargetFileName, - DWORD dwFlags); - /* ntdll.dll */ +NTSTATUS (WINAPI *func_NtCreateFile)(PHANDLE FileHandle, + ACCESS_MASK DesiredAccess, + POBJECT_ATTRIBUTES ObjectAttributes, + PIO_STATUS_BLOCK IoStatusBlock, + PLARGE_INTEGER AllocationSize, + ULONG FileAttributes, + ULONG ShareAccess, + ULONG CreateDisposition, + ULONG CreateOptions, + PVOID EaBuffer, + ULONG EaLength); + NTSTATUS (WINAPI *func_NtOpenFile) (PHANDLE FileHandle, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes, @@ -410,6 +404,16 @@ NTSTATUS (WINAPI *func_NtReadFile) (HANDLE FileHandle, PLARGE_INTEGER ByteOffset, PULONG Key); +NTSTATUS (WINAPI *func_NtWriteFile) (HANDLE FileHandle, + HANDLE Event, + PIO_APC_ROUTINE ApcRoutine, + PVOID ApcContext, + PIO_STATUS_BLOCK IoStatusBlock, + PVOID Buffer, + ULONG Length, + PLARGE_INTEGER ByteOffset, + PULONG Key); + NTSTATUS (WINAPI *func_NtQueryInformationFile)(HANDLE FileHandle, PIO_STATUS_BLOCK IoStatusBlock, PVOID FileInformation, @@ -440,14 +444,43 @@ NTSTATUS (WINAPI *func_NtQueryVolumeInformationFile) (HANDLE FileHandle, ULONG Length, FS_INFORMATION_CLASS FsInformationClass); +NTSTATUS (WINAPI *func_NtSetInformationFile)(HANDLE FileHandle, + PIO_STATUS_BLOCK IoStatusBlock, + PVOID FileInformation, + ULONG Length, + FILE_INFORMATION_CLASS FileInformationClass); + NTSTATUS (WINAPI *func_NtSetSecurityObject)(HANDLE Handle, SECURITY_INFORMATION SecurityInformation, PSECURITY_DESCRIPTOR SecurityDescriptor); +NTSTATUS (WINAPI *func_NtFsControlFile) (HANDLE FileHandle, + HANDLE Event, + PIO_APC_ROUTINE ApcRoutine, + PVOID ApcContext, + PIO_STATUS_BLOCK IoStatusBlock, + ULONG FsControlCode, + PVOID InputBuffer, + ULONG InputBufferLength, + PVOID OutputBuffer, + ULONG OutputBufferLength); + NTSTATUS (WINAPI *func_NtClose) (HANDLE Handle); DWORD (WINAPI *func_RtlNtStatusToDosError)(NTSTATUS status); +BOOLEAN (WINAPI *func_RtlDosPathNameToNtPathName_U) + (IN PCWSTR DosName, + OUT PUNICODE_STRING NtName, + OUT PCWSTR *PartName, + OUT PRTL_RELATIVE_NAME_U RelativeName); + +NTSTATUS (WINAPI *func_RtlDosPathNameToNtPathName_U_WithStatus) + (IN PCWSTR DosName, + OUT PUNICODE_STRING NtName, + OUT PCWSTR *PartName, + OUT PRTL_RELATIVE_NAME_U RelativeName); + NTSTATUS (WINAPI *func_RtlCreateSystemVolumeInformationFolder) (PCUNICODE_STRING VolumeRootPath); @@ -485,24 +518,22 @@ struct dll_spec { struct dll_spec ntdll_spec = { .name = L"ntdll.dll", .syms = { + DLL_SYM(NtCreateFile, true), DLL_SYM(NtOpenFile, true), DLL_SYM(NtReadFile, true), + DLL_SYM(NtWriteFile, true), DLL_SYM(NtQueryInformationFile, true), DLL_SYM(NtQuerySecurityObject, true), DLL_SYM(NtQueryDirectoryFile, true), DLL_SYM(NtQueryVolumeInformationFile, true), + DLL_SYM(NtSetInformationFile, true), DLL_SYM(NtSetSecurityObject, true), + DLL_SYM(NtFsControlFile, true), DLL_SYM(NtClose, true), DLL_SYM(RtlNtStatusToDosError, true), DLL_SYM(RtlCreateSystemVolumeInformationFolder, false), - {NULL, NULL}, - }, -}; - -struct dll_spec kernel32_spec = { - .name = L"kernel32.dll", - .syms = { - DLL_SYM(CreateSymbolicLinkW, false), + DLL_SYM(RtlDosPathNameToNtPathName_U, true), + DLL_SYM(RtlDosPathNameToNtPathName_U_WithStatus, false), /* Not present on XP */ {NULL, NULL}, }, }; @@ -571,19 +602,12 @@ win32_global_init(int init_flags) /* Get Windows version information. */ GetVersionEx(&windows_version_info); - /* Try to dynamically load some functions. */ - ret = init_dll(&kernel32_spec); - if (ret) - goto out_drop_privs; - ret = init_dll(&ntdll_spec); if (ret) - goto out_cleanup_kernel32; + goto out_drop_privs; return 0; -out_cleanup_kernel32: - cleanup_dll(&kernel32_spec); out_drop_privs: win32_release_capture_and_apply_privileges(); return ret; @@ -595,8 +619,45 @@ win32_global_cleanup(void) if (acquired_privileges) win32_release_capture_and_apply_privileges(); - cleanup_dll(&kernel32_spec); cleanup_dll(&ntdll_spec); } +/* + * Translates a Win32-namespace path into an NT-namespace path. + * + * On success, returns 0. The NT-namespace path will be stored in the + * UNICODE_STRING structure pointed to by nt_path. nt_path->Buffer will be set + * to a new buffer that must later be freed with HeapFree(). (Really + * RtlHeapFree(), but HeapFree() seems to be the same thing.) + * + * On failure, returns WIMLIB_ERR_NOMEM or WIMLIB_ERR_INVALID_PARAM. + */ +int +win32_path_to_nt_path(const wchar_t *win32_path, UNICODE_STRING *nt_path) +{ + NTSTATUS status; + + if (func_RtlDosPathNameToNtPathName_U_WithStatus) { + status = (*func_RtlDosPathNameToNtPathName_U_WithStatus)(win32_path, + nt_path, + NULL, NULL); + } else { + if ((*func_RtlDosPathNameToNtPathName_U)(win32_path, nt_path, + NULL, NULL)) + status = STATUS_SUCCESS; + else + status = STATUS_NO_MEMORY; + } + + if (likely(NT_SUCCESS(status))) + return 0; + + if (status == STATUS_NO_MEMORY) + return WIMLIB_ERR_NOMEM; + + ERROR("\"%ls\": invalid path name (status=0x%08"PRIx32")", + win32_path, (u32)status); + return WIMLIB_ERR_INVALID_PARAM; +} + #endif /* __WIN32__ */