2013-08-22 18:18:38 +04:00
|
|
|
|
2013-08-22 21:30:39 +04:00
|
|
|
#include <winpr/crt.h>
|
|
|
|
|
2013-08-22 18:18:38 +04:00
|
|
|
#include <winpr/nt.h>
|
|
|
|
|
2016-06-01 17:26:26 +03:00
|
|
|
#ifdef _WIN32
|
|
|
|
#define TESTFILE "\\??\\C:\\Documents and Settings\\All Users\\winpr_test_nt_create_file.txt"
|
|
|
|
#else
|
|
|
|
#define TESTFILE "/tmp/winpr_test_nt_create_file.txt"
|
|
|
|
#endif
|
|
|
|
|
2013-08-22 18:18:38 +04:00
|
|
|
int TestNtCreateFile(int argc, char* argv[])
|
|
|
|
{
|
2013-08-22 21:30:39 +04:00
|
|
|
HANDLE handle;
|
|
|
|
NTSTATUS ntstatus;
|
|
|
|
ULONG CreateOptions;
|
|
|
|
ANSI_STRING aString;
|
|
|
|
UNICODE_STRING uString;
|
2013-10-24 02:15:10 +04:00
|
|
|
ULONG CreateDisposition;
|
2013-08-22 21:30:39 +04:00
|
|
|
ACCESS_MASK DesiredAccess = 0;
|
|
|
|
OBJECT_ATTRIBUTES attributes;
|
|
|
|
IO_STATUS_BLOCK ioStatusBlock;
|
|
|
|
|
2016-06-01 17:26:26 +03:00
|
|
|
int eFailure = -1;
|
|
|
|
int eSuccess = 0;
|
|
|
|
|
|
|
|
#ifndef _WIN32
|
|
|
|
printf("Note: %s result may currently only be trusted on Win32\n", __FUNCTION__);
|
|
|
|
eFailure = eSuccess;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
_RtlInitAnsiString(&aString, TESTFILE);
|
|
|
|
|
|
|
|
ntstatus = _RtlAnsiStringToUnicodeString(&uString, &aString, TRUE);
|
|
|
|
if (ntstatus != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
printf("_RtlAnsiStringToUnicodeString failure: 0x%08X\n", ntstatus);
|
|
|
|
return eFailure;
|
|
|
|
}
|
2013-08-22 21:30:39 +04:00
|
|
|
|
2013-10-24 02:15:10 +04:00
|
|
|
handle = NULL;
|
|
|
|
ZeroMemory(&ioStatusBlock, sizeof(IO_STATUS_BLOCK));
|
|
|
|
|
2013-10-23 05:38:16 +04:00
|
|
|
_InitializeObjectAttributes(&attributes, &uString, 0, NULL, NULL);
|
2013-08-22 21:30:39 +04:00
|
|
|
|
|
|
|
DesiredAccess = GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE;
|
|
|
|
CreateOptions = FILE_DIRECTORY_FILE | FILE_WRITE_THROUGH;
|
2013-10-24 02:15:10 +04:00
|
|
|
CreateDisposition = FILE_OVERWRITE_IF;
|
|
|
|
|
|
|
|
ntstatus = _NtCreateFile(&handle, DesiredAccess, &attributes, &ioStatusBlock,
|
|
|
|
0, 0, CreateDisposition, CreateOptions, 0, 0, 0);
|
2013-08-22 21:30:39 +04:00
|
|
|
|
2013-10-24 02:15:10 +04:00
|
|
|
if (ntstatus != STATUS_SUCCESS)
|
|
|
|
{
|
2016-06-01 17:26:26 +03:00
|
|
|
printf("_NtCreateFile failure: 0x%08X\n", ntstatus);
|
|
|
|
return eFailure;
|
2013-10-24 02:15:10 +04:00
|
|
|
}
|
2013-10-23 04:47:29 +04:00
|
|
|
|
2013-10-23 05:38:16 +04:00
|
|
|
_RtlFreeUnicodeString(&uString);
|
2013-08-22 21:30:39 +04:00
|
|
|
|
2013-10-24 02:15:10 +04:00
|
|
|
ntstatus = _NtClose(handle);
|
|
|
|
|
|
|
|
if (ntstatus != STATUS_SUCCESS)
|
|
|
|
{
|
2016-06-01 17:26:26 +03:00
|
|
|
printf("_NtClose failure: 0x%08X\n", ntstatus);
|
|
|
|
return eFailure;
|
2013-10-24 02:15:10 +04:00
|
|
|
}
|
|
|
|
|
2016-06-01 17:26:26 +03:00
|
|
|
return eSuccess;
|
2013-08-22 18:18:38 +04:00
|
|
|
}
|