static void test_create_invalid(void) { IO_STATUS_BLOCK iosb; OBJECT_ATTRIBUTES attr; UNICODE_STRING name; LARGE_INTEGER timeout; NTSTATUS res; HANDLE handle, handle2; FILE_PIPE_LOCAL_INFORMATION info; pRtlInitUnicodeString(&name, testpipe_nt); attr.Length = sizeof(attr); attr.RootDirectory = 0; attr.ObjectName = &name; attr.Attributes = 0x40; /*case insensitive */ attr.SecurityDescriptor = NULL; attr.SecurityQualityOfService = NULL; timeout.QuadPart = -100000000000ll; /* create a pipe with FILE_OVERWRITE */ res = pNtCreateNamedPipeFile(&handle, FILE_READ_ATTRIBUTES | SYNCHRONIZE, &attr, &iosb, FILE_SHARE_READ, 4 /*FILE_OVERWRITE*/, 0, 1, 0, 0, 0xFFFFFFFF, 500, 500, &timeout); todo_wine ok(res == STATUS_INVALID_PARAMETER, "NtCreateNamedPipeFile returned %x\n", res); if (!res) CloseHandle(handle); /* create a pipe with FILE_OVERWRITE_IF */ res = pNtCreateNamedPipeFile(&handle, FILE_READ_ATTRIBUTES | SYNCHRONIZE, &attr, &iosb, FILE_SHARE_READ, 5 /*FILE_OVERWRITE_IF*/, 0, 1, 0, 0, 0xFFFFFFFF, 500, 500, &timeout); todo_wine ok(res == STATUS_INVALID_PARAMETER, "NtCreateNamedPipeFile returned %x\n", res); if (!res) CloseHandle(handle); /* create a pipe with sharing = 0 */ res = pNtCreateNamedPipeFile(&handle, FILE_READ_ATTRIBUTES | SYNCHRONIZE, &attr, &iosb, 0, 2 /*FILE_CREATE*/, 0, 1, 0, 0, 0xFFFFFFFF, 500, 500, &timeout); ok(res == STATUS_INVALID_PARAMETER, "NtCreateNamedPipeFile returned %x\n", res); if (!res) CloseHandle(handle); /* create a pipe without r/w access */ res = pNtCreateNamedPipeFile(&handle, SYNCHRONIZE, &attr, &iosb, FILE_SHARE_READ | FILE_SHARE_WRITE, 2 /*FILE_CREATE*/, 0, 1, 0, 0, 0xFFFFFFFF, 500, 500, &timeout); ok(!res, "NtCreateNamedPipeFile returned %x\n", res); res = pNtQueryInformationFile(handle, &iosb, &info, sizeof(info), (FILE_INFORMATION_CLASS)24); ok(res == STATUS_ACCESS_DENIED, "NtQueryInformationFile returned %x\n", res); /* test FILE_CREATE creation disposition */ res = pNtCreateNamedPipeFile(&handle2, SYNCHRONIZE, &attr, &iosb, FILE_SHARE_READ | FILE_SHARE_WRITE, 2 /*FILE_CREATE*/, 0, 1, 0, 0, 0xFFFFFFFF, 500, 500, &timeout); todo_wine ok(res == STATUS_ACCESS_DENIED, "NtCreateNamedPipeFile returned %x\n", res); if (!res) CloseHandle(handle2); CloseHandle(handle); }
static void test_namespace_pipe(void) { static const WCHAR buffer1[] = {'\\','?','?','\\','P','I','P','E','\\','t','e','s','t','\\','p','i','p','e',0}; static const WCHAR buffer2[] = {'\\','?','?','\\','P','I','P','E','\\','T','E','S','T','\\','P','I','P','E',0}; static const WCHAR buffer3[] = {'\\','?','?','\\','p','i','p','e','\\','t','e','s','t','\\','p','i','p','e',0}; static const WCHAR buffer4[] = {'\\','?','?','\\','p','i','p','e','\\','t','e','s','t',0}; OBJECT_ATTRIBUTES attr; UNICODE_STRING str; IO_STATUS_BLOCK iosb; NTSTATUS status; LARGE_INTEGER timeout; HANDLE pipe, h; timeout.QuadPart = -10000; pRtlInitUnicodeString(&str, buffer1); InitializeObjectAttributes(&attr, &str, 0, 0, NULL); status = pNtCreateNamedPipeFile(&pipe, GENERIC_READ|GENERIC_WRITE, &attr, &iosb, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_CREATE, FILE_PIPE_FULL_DUPLEX, FALSE, FALSE, FALSE, 1, 256, 256, &timeout); ok(status == STATUS_SUCCESS, "Failed to create NamedPipe(%08x)\n", status); status = pNtCreateNamedPipeFile(&pipe, GENERIC_READ|GENERIC_WRITE, &attr, &iosb, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_CREATE, FILE_PIPE_FULL_DUPLEX, FALSE, FALSE, FALSE, 1, 256, 256, &timeout); ok(status == STATUS_INSTANCE_NOT_AVAILABLE, "NtCreateNamedPipeFile should have failed with STATUS_INSTANCE_NOT_AVAILABLE got(%08x)\n", status); pRtlInitUnicodeString(&str, buffer2); InitializeObjectAttributes(&attr, &str, 0, 0, NULL); status = pNtCreateNamedPipeFile(&pipe, GENERIC_READ|GENERIC_WRITE, &attr, &iosb, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_CREATE, FILE_PIPE_FULL_DUPLEX, FALSE, FALSE, FALSE, 1, 256, 256, &timeout); ok(status == STATUS_INSTANCE_NOT_AVAILABLE, "NtCreateNamedPipeFile should have failed with STATUS_INSTANCE_NOT_AVAILABLE got(%08x)\n", status); h = CreateFileA("\\\\.\\pipe\\test\\pipe", GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 ); ok(h != INVALID_HANDLE_VALUE, "Failed to open NamedPipe (%u)\n", GetLastError()); pNtClose(h); pRtlInitUnicodeString(&str, buffer3); InitializeObjectAttributes(&attr, &str, 0, 0, NULL); status = pNtOpenFile(&h, GENERIC_READ, &attr, &iosb, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN); ok(status == STATUS_OBJECT_PATH_NOT_FOUND || status == STATUS_PIPE_NOT_AVAILABLE || status == STATUS_OBJECT_NAME_INVALID || /* vista */ status == STATUS_OBJECT_NAME_NOT_FOUND, /* win8 */ "NtOpenFile should have failed with STATUS_OBJECT_PATH_NOT_FOUND got(%08x)\n", status); pRtlInitUnicodeString(&str, buffer4); InitializeObjectAttributes(&attr, &str, OBJ_CASE_INSENSITIVE, 0, NULL); status = pNtOpenFile(&h, GENERIC_READ, &attr, &iosb, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN); ok(status == STATUS_OBJECT_NAME_NOT_FOUND || status == STATUS_OBJECT_NAME_INVALID, /* vista */ "NtOpenFile should have failed with STATUS_OBJECT_NAME_NOT_FOUND got(%08x)\n", status); pNtClose(pipe); }
static NTSTATUS create_pipe(PHANDLE handle, ULONG sharing, ULONG options) { IO_STATUS_BLOCK iosb; OBJECT_ATTRIBUTES attr; UNICODE_STRING name; LARGE_INTEGER timeout; NTSTATUS res; pRtlInitUnicodeString(&name, testpipe_nt); attr.Length = sizeof(attr); attr.RootDirectory = 0; attr.ObjectName = &name; attr.Attributes = 0x40; /*case insensitive */ attr.SecurityDescriptor = NULL; attr.SecurityQualityOfService = NULL; timeout.QuadPart = -100000000000ll; res = pNtCreateNamedPipeFile(handle, FILE_READ_ATTRIBUTES | SYNCHRONIZE, &attr, &iosb, sharing, 2 /*FILE_CREATE*/, options, 1, 0, 0, 0xFFFFFFFF, 500, 500, &timeout); return res; }
static void test_filepipeinfo(void) { IO_STATUS_BLOCK iosb; OBJECT_ATTRIBUTES attr; UNICODE_STRING name; LARGE_INTEGER timeout; HANDLE hServer, hClient; FILE_PIPE_INFORMATION fpi; NTSTATUS res; pRtlInitUnicodeString(&name, testpipe_nt); attr.Length = sizeof(attr); attr.RootDirectory = 0; attr.ObjectName = &name; attr.Attributes = 0x40; /* case insensitive */ attr.SecurityDescriptor = NULL; attr.SecurityQualityOfService = NULL; timeout.QuadPart = -100000000000ll; /* test with INVALID_HANDLE_VALUE */ res = pNtQueryInformationFile(INVALID_HANDLE_VALUE, &iosb, &fpi, sizeof(fpi), (FILE_INFORMATION_CLASS)23); ok(res == STATUS_OBJECT_TYPE_MISMATCH, "NtQueryInformationFile returned %x\n", res); fpi.ReadMode = 0; fpi.CompletionMode = 0; res = pNtSetInformationFile(INVALID_HANDLE_VALUE, &iosb, &fpi, sizeof(fpi), (FILE_INFORMATION_CLASS)23); ok(res == STATUS_OBJECT_TYPE_MISMATCH, "NtSetInformationFile returned %x\n", res); /* server end with read-only attributes */ res = pNtCreateNamedPipeFile(&hServer, FILE_READ_ATTRIBUTES | SYNCHRONIZE, &attr, &iosb, FILE_SHARE_READ | FILE_SHARE_WRITE, 2 /* FILE_CREATE */, 0, 0, 0, 1, 0xFFFFFFFF, 500, 500, &timeout); ok(!res, "NtCreateNamedPipeFile returned %x\n", res); check_pipe_handle_state(hServer, 0, 1); hClient = CreateFileW(testpipe, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0); ok(hClient != INVALID_HANDLE_VALUE, "can't open pipe, GetLastError: %x\n", GetLastError()); check_pipe_handle_state(hServer, 0, 1); check_pipe_handle_state(hClient, 0, 0); fpi.ReadMode = 0; fpi.CompletionMode = 0; res = pNtSetInformationFile(hServer, &iosb, &fpi, sizeof(fpi), (FILE_INFORMATION_CLASS)23); ok(res == STATUS_ACCESS_DENIED, "NtSetInformationFile returned %x\n", res); check_pipe_handle_state(hServer, 0, 1); check_pipe_handle_state(hClient, 0, 0); fpi.ReadMode = 1; /* invalid on a byte stream pipe */ fpi.CompletionMode = 1; res = pNtSetInformationFile(hServer, &iosb, &fpi, sizeof(fpi), (FILE_INFORMATION_CLASS)23); ok(res == STATUS_ACCESS_DENIED, "NtSetInformationFile returned %x\n", res); check_pipe_handle_state(hServer, 0, 1); check_pipe_handle_state(hClient, 0, 0); if (hClient != INVALID_HANDLE_VALUE) { fpi.ReadMode = 1; /* invalid on a byte stream pipe */ fpi.CompletionMode = 1; res = pNtSetInformationFile(hClient, &iosb, &fpi, sizeof(fpi), (FILE_INFORMATION_CLASS)23); ok(res == STATUS_INVALID_PARAMETER, "NtSetInformationFile returned %x\n", res); } check_pipe_handle_state(hServer, 0, 1); check_pipe_handle_state(hClient, 0, 0); if (hClient != INVALID_HANDLE_VALUE) { fpi.ReadMode = 0; fpi.CompletionMode = 1; res = pNtSetInformationFile(hClient, &iosb, &fpi, sizeof(fpi), (FILE_INFORMATION_CLASS)23); ok(!res, "NtSetInformationFile returned %x\n", res); } check_pipe_handle_state(hServer, 0, 1); check_pipe_handle_state(hClient, 0, 1); if (hClient != INVALID_HANDLE_VALUE) { fpi.ReadMode = 0; fpi.CompletionMode = 2; /* not in range 0-1 */ res = pNtSetInformationFile(hClient, &iosb, &fpi, sizeof(fpi), (FILE_INFORMATION_CLASS)23); ok(res == STATUS_INVALID_PARAMETER || broken(!res) /* < Vista */, "NtSetInformationFile returned %x\n", res); fpi.ReadMode = 2; /* not in range 0-1 */ fpi.CompletionMode = 0; res = pNtSetInformationFile(hClient, &iosb, &fpi, sizeof(fpi), (FILE_INFORMATION_CLASS)23); ok(res == STATUS_INVALID_PARAMETER || broken(!res) /* < Vista */, "NtSetInformationFile returned %x\n", res); } CloseHandle(hClient); check_pipe_handle_state(hServer, 0, 1); fpi.ReadMode = 0; fpi.CompletionMode = 0; res = pNtSetInformationFile(hServer, &iosb, &fpi, sizeof(fpi), (FILE_INFORMATION_CLASS)23); ok(res == STATUS_ACCESS_DENIED, "NtSetInformationFile returned %x\n", res); CloseHandle(hServer); /* message mode server with read/write attributes */ res = pNtCreateNamedPipeFile(&hServer, FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES | SYNCHRONIZE, &attr, &iosb, FILE_SHARE_READ | FILE_SHARE_WRITE, 2 /* FILE_CREATE */, 0, 1, 1, 0, 0xFFFFFFFF, 500, 500, &timeout); ok(!res, "NtCreateNamedPipeFile returned %x\n", res); check_pipe_handle_state(hServer, 1, 0); hClient = CreateFileW(testpipe, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0); ok(hClient != INVALID_HANDLE_VALUE, "can't open pipe, GetLastError: %x\n", GetLastError()); check_pipe_handle_state(hServer, 1, 0); check_pipe_handle_state(hClient, 0, 0); if (hClient != INVALID_HANDLE_VALUE) { fpi.ReadMode = 1; fpi.CompletionMode = 1; res = pNtSetInformationFile(hClient, &iosb, &fpi, sizeof(fpi), (FILE_INFORMATION_CLASS)23); ok(!res, "NtSetInformationFile returned %x\n", res); } check_pipe_handle_state(hServer, 1, 0); check_pipe_handle_state(hClient, 1, 1); fpi.ReadMode = 0; fpi.CompletionMode = 1; res = pNtSetInformationFile(hServer, &iosb, &fpi, sizeof(fpi), (FILE_INFORMATION_CLASS)23); ok(!res, "NtSetInformationFile returned %x\n", res); check_pipe_handle_state(hServer, 0, 1); check_pipe_handle_state(hClient, 1, 1); if (hClient != INVALID_HANDLE_VALUE) { fpi.ReadMode = 0; fpi.CompletionMode = 2; /* not in range 0-1 */ res = pNtSetInformationFile(hClient, &iosb, &fpi, sizeof(fpi), (FILE_INFORMATION_CLASS)23); ok(res == STATUS_INVALID_PARAMETER || broken(!res) /* < Vista */, "NtSetInformationFile returned %x\n", res); fpi.ReadMode = 2; /* not in range 0-1 */ fpi.CompletionMode = 0; res = pNtSetInformationFile(hClient, &iosb, &fpi, sizeof(fpi), (FILE_INFORMATION_CLASS)23); ok(res == STATUS_INVALID_PARAMETER || broken(!res) /* < Vista */, "NtSetInformationFile returned %x\n", res); } CloseHandle(hClient); check_pipe_handle_state(hServer, 0, 1); fpi.ReadMode = 1; fpi.CompletionMode = 0; res = pNtSetInformationFile(hServer, &iosb, &fpi, sizeof(fpi), (FILE_INFORMATION_CLASS)23); ok(!res, "NtSetInformationFile returned %x\n", res); check_pipe_handle_state(hServer, 1, 0); CloseHandle(hServer); }