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-07 18:20:56 +03:00
|
|
|
int result = -1;
|
2016-06-01 17:26:26 +03:00
|
|
|
_RtlInitAnsiString(&aString, TESTFILE);
|
|
|
|
ntstatus = _RtlAnsiStringToUnicodeString(&uString, &aString, TRUE);
|
2017-11-15 11:11:12 +03:00
|
|
|
|
2016-06-01 17:26:26 +03:00
|
|
|
if (ntstatus != STATUS_SUCCESS)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
printf("_RtlAnsiStringToUnicodeString failure: 0x%08" PRIX32 "\n", ntstatus);
|
2016-06-07 18:20:56 +03:00
|
|
|
goto out;
|
2016-06-01 17:26:26 +03:00
|
|
|
}
|
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;
|
2019-11-06 17:24:51 +03:00
|
|
|
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)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
printf("_NtCreateFile failure: 0x%08" PRIX32 "\n", ntstatus);
|
2016-06-07 18:20:56 +03:00
|
|
|
goto out;
|
2013-10-24 02:15:10 +04:00
|
|
|
}
|
2013-10-23 04:47:29 +04:00
|
|
|
|
2013-10-24 02:15:10 +04:00
|
|
|
ntstatus = _NtClose(handle);
|
|
|
|
|
|
|
|
if (ntstatus != STATUS_SUCCESS)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
printf("_NtClose failure: 0x%08" PRIX32 "\n", ntstatus);
|
2016-06-07 18:20:56 +03:00
|
|
|
goto out;
|
2013-10-24 02:15:10 +04:00
|
|
|
}
|
|
|
|
|
2016-06-07 18:20:56 +03:00
|
|
|
result = 0;
|
|
|
|
out:
|
2017-11-15 11:11:12 +03:00
|
|
|
_RtlFreeUnicodeString(&uString);
|
2016-06-07 18:20:56 +03:00
|
|
|
#ifndef _WIN32
|
2017-11-15 11:11:12 +03:00
|
|
|
|
2016-06-07 18:20:56 +03:00
|
|
|
if (result == 0)
|
|
|
|
{
|
|
|
|
printf("%s: Error, this test is currently expected not to succeed on this platform.\n",
|
2017-11-15 11:11:12 +03:00
|
|
|
__FUNCTION__);
|
2016-06-07 18:20:56 +03:00
|
|
|
result = -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
printf("%s: This test is currently expected to fail on this platform.\n", __FUNCTION__);
|
2016-06-07 18:20:56 +03:00
|
|
|
result = 0;
|
|
|
|
}
|
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
#endif
|
2016-06-07 18:20:56 +03:00
|
|
|
return result;
|
2013-08-22 18:18:38 +04:00
|
|
|
}
|