From 888812eaa058dd254e0fc02aa58138526ab55a21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Moreau?= Date: Tue, 22 Oct 2013 20:47:29 -0400 Subject: [PATCH] libwinpr-nt: stub more of the native file API --- winpr/libwinpr/handle/handle.h | 1 + winpr/libwinpr/nt/nt.c | 70 ++++++++++++++++++++++- winpr/libwinpr/nt/nt.h | 45 +++++++++++++++ winpr/libwinpr/nt/test/TestNtCreateFile.c | 6 +- 4 files changed, 117 insertions(+), 5 deletions(-) create mode 100644 winpr/libwinpr/nt/nt.h diff --git a/winpr/libwinpr/handle/handle.h b/winpr/libwinpr/handle/handle.h index a823801cf..201493a51 100644 --- a/winpr/libwinpr/handle/handle.h +++ b/winpr/libwinpr/handle/handle.h @@ -32,6 +32,7 @@ #define HANDLE_TYPE_NAMED_PIPE 7 #define HANDLE_TYPE_ANONYMOUS_PIPE 8 #define HANDLE_TYPE_ACCESS_TOKEN 9 +#define HANDLE_TYPE_FILE 10 #define WINPR_HANDLE_DEF() \ ULONG Type diff --git a/winpr/libwinpr/nt/nt.c b/winpr/libwinpr/nt/nt.c index dde4ff2b0..71f18073f 100644 --- a/winpr/libwinpr/nt/nt.c +++ b/winpr/libwinpr/nt/nt.c @@ -32,6 +32,8 @@ #ifndef _WIN32 +#include "nt.h" + #include #include @@ -202,7 +204,24 @@ NTSTATUS NtCreateFile(PHANDLE FileHandle, ACCESS_MASK DesiredAccess, PLARGE_INTEGER AllocationSize, ULONG FileAttributes, ULONG ShareAccess, ULONG CreateDisposition, ULONG CreateOptions, PVOID EaBuffer, ULONG EaLength) { - return 0; + WINPR_FILE* pFileHandle; + + pFileHandle = (WINPR_FILE*) malloc(sizeof(WINPR_FILE)); + + if (!pFileHandle) + return 0; + + ZeroMemory(pFileHandle, sizeof(WINPR_FILE)); + + pFileHandle->DesiredAccess = DesiredAccess; + pFileHandle->FileAttributes = FileAttributes; + pFileHandle->ShareAccess = ShareAccess; + pFileHandle->CreateDisposition = CreateDisposition; + pFileHandle->CreateOptions = CreateOptions; + + *((PULONG_PTR) FileHandle) = (ULONG_PTR) pFileHandle; + + return STATUS_SUCCESS; } /** @@ -214,7 +233,43 @@ NTSTATUS NtOpenFile(PHANDLE FileHandle, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes, PIO_STATUS_BLOCK IoStatusBlock, ULONG ShareAccess, ULONG OpenOptions) { - return 0; + WINPR_FILE* pFileHandle; + + pFileHandle = (WINPR_FILE*) malloc(sizeof(WINPR_FILE)); + + if (!pFileHandle) + return 0; + + ZeroMemory(pFileHandle, sizeof(WINPR_FILE)); + + pFileHandle->DesiredAccess = DesiredAccess; + pFileHandle->ShareAccess = ShareAccess; + + *((PULONG_PTR) FileHandle) = (ULONG_PTR) pFileHandle; + + return STATUS_SUCCESS; +} + +/** + * NtReadFile function: + * http://msdn.microsoft.com/en-us/library/windows/hardware/ff567072/ + */ + +NTSTATUS NtReadFile(HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, + PIO_STATUS_BLOCK IoStatusBlock, PVOID Buffer, ULONG Length, PLARGE_INTEGER ByteOffset, PULONG Key) +{ + return STATUS_SUCCESS; +} + +/** + * NtWriteFile function: + * http://msdn.microsoft.com/en-us/library/windows/hardware/ff567121/ + */ + +NTSTATUS NtWriteFile(HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, + PIO_STATUS_BLOCK IoStatusBlock, PVOID Buffer, ULONG Length, PLARGE_INTEGER ByteOffset, PULONG Key) +{ + return STATUS_SUCCESS; } /** @@ -237,7 +292,16 @@ NTSTATUS NtDeviceIoControlFile(HANDLE FileHandle, HANDLE Event, NTSTATUS NtClose(HANDLE Handle) { - return 0; + WINPR_FILE* pFileHandle; + + if (!Handle) + return 0; + + pFileHandle = (WINPR_FILE*) Handle; + + free(pFileHandle); + + return STATUS_SUCCESS; } /** diff --git a/winpr/libwinpr/nt/nt.h b/winpr/libwinpr/nt/nt.h new file mode 100644 index 000000000..52eda2f98 --- /dev/null +++ b/winpr/libwinpr/nt/nt.h @@ -0,0 +1,45 @@ +/** + * WinPR: Windows Portable Runtime + * Windows Native System Services + * + * Copyright 2013 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef WINPR_NT_PRIVATE_H +#define WINPR_NT_PRIVATE_H + +#ifndef _WIN32 + +#include + +#include "../handle/handle.h" + +struct winpr_file +{ + WINPR_HANDLE_DEF(); + + ACCESS_MASK DesiredAccess; + OBJECT_ATTRIBUTES ObjectAttributes; + ULONG FileAttributes; + ULONG ShareAccess; + ULONG CreateDisposition; + ULONG CreateOptions; +}; +typedef struct winpr_file WINPR_FILE; + +#endif + +#endif /* WINPR_NT_PRIVATE_H */ + diff --git a/winpr/libwinpr/nt/test/TestNtCreateFile.c b/winpr/libwinpr/nt/test/TestNtCreateFile.c index 8c1b9fdb5..72636449e 100644 --- a/winpr/libwinpr/nt/test/TestNtCreateFile.c +++ b/winpr/libwinpr/nt/test/TestNtCreateFile.c @@ -5,7 +5,8 @@ int TestNtCreateFile(int argc, char* argv[]) { -#if 0 +#ifndef _WIN32 + HANDLE handle; NTSTATUS ntstatus; ULONG CreateOptions; @@ -18,7 +19,7 @@ int TestNtCreateFile(int argc, char* argv[]) RtlInitAnsiString(&aString, "\\Device\\FreeRDP\\TEST"); RtlAnsiStringToUnicodeString(&uString, &aString, TRUE); - InitializeObjectAttributes(&attributes, NULL, 0, NULL, NULL); + InitializeObjectAttributes(&attributes, &uString, 0, NULL, NULL); DesiredAccess = GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE; CreateOptions = FILE_DIRECTORY_FILE | FILE_WRITE_THROUGH; @@ -26,6 +27,7 @@ int TestNtCreateFile(int argc, char* argv[]) ntstatus = NtCreateFile(&handle, DesiredAccess, &attributes, &ioStatusBlock, 0, 0, 0, CreateOptions, 0, 0, 0); RtlFreeUnicodeString(&uString); + #endif return 0;