Use the share disposition to detect the direction of a pipe.

svn path=/trunk/; revision=19021
This commit is contained in:
Hartmut Birr 2005-11-05 22:03:47 +00:00
parent 4af01faa3c
commit e087024bb5
3 changed files with 38 additions and 30 deletions

View file

@ -329,6 +329,14 @@ NpfsCreateNamedPipe(PDEVICE_OBJECT DeviceObject,
Irp->IoStatus.Information = 0; Irp->IoStatus.Information = 0;
if (!(IoStack->Parameters.CreatePipe.ShareAccess & (FILE_SHARE_READ|FILE_SHARE_WRITE)) ||
(IoStack->Parameters.CreatePipe.ShareAccess & ~(FILE_SHARE_READ|FILE_SHARE_WRITE)))
{
Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return STATUS_INVALID_PARAMETER;
}
Fcb = ExAllocatePool(NonPagedPool, sizeof(NPFS_FCB)); Fcb = ExAllocatePool(NonPagedPool, sizeof(NPFS_FCB));
if (Fcb == NULL) if (Fcb == NULL)
{ {
@ -411,12 +419,23 @@ NpfsCreateNamedPipe(PDEVICE_OBJECT DeviceObject,
Pipe->WriteMode = Buffer->ReadMode; Pipe->WriteMode = Buffer->ReadMode;
Pipe->ReadMode = Buffer->ReadMode; Pipe->ReadMode = Buffer->ReadMode;
Pipe->CompletionMode = Buffer->CompletionMode; Pipe->CompletionMode = Buffer->CompletionMode;
Pipe->PipeConfiguration = IoStack->Parameters.CreatePipe.Options & 0x3; switch (IoStack->Parameters.CreatePipe.ShareAccess & (FILE_SHARE_READ|FILE_SHARE_WRITE))
{
case FILE_SHARE_READ:
Pipe->PipeConfiguration = FILE_PIPE_OUTBOUND;
break;
case FILE_SHARE_WRITE:
Pipe->PipeConfiguration = FILE_PIPE_INBOUND;
break;
case FILE_SHARE_READ|FILE_SHARE_WRITE:
Pipe->PipeConfiguration = FILE_PIPE_FULL_DUPLEX;
break;
}
Pipe->MaximumInstances = Buffer->MaximumInstances; Pipe->MaximumInstances = Buffer->MaximumInstances;
Pipe->CurrentInstances = 0; Pipe->CurrentInstances = 0;
Pipe->TimeOut = Buffer->DefaultTimeout; Pipe->TimeOut = Buffer->DefaultTimeout;
if (!(IoStack->Parameters.CreatePipe.Options & FILE_PIPE_OUTBOUND) || if (!(Pipe->PipeConfiguration & FILE_PIPE_OUTBOUND) ||
IoStack->Parameters.CreatePipe.Options & FILE_PIPE_FULL_DUPLEX) Pipe->PipeConfiguration & FILE_PIPE_FULL_DUPLEX)
{ {
if (Buffer->InboundQuota == 0) if (Buffer->InboundQuota == 0)
{ {
@ -440,7 +459,7 @@ NpfsCreateNamedPipe(PDEVICE_OBJECT DeviceObject,
Pipe->InboundQuota = 0; Pipe->InboundQuota = 0;
} }
if (IoStack->Parameters.CreatePipe.Options & (FILE_PIPE_FULL_DUPLEX|FILE_PIPE_OUTBOUND)) if (Pipe->PipeConfiguration & (FILE_PIPE_FULL_DUPLEX|FILE_PIPE_OUTBOUND))
{ {
if (Buffer->OutboundQuota == 0) if (Buffer->OutboundQuota == 0)
{ {

View file

@ -123,27 +123,16 @@ CreateNamedPipeW(LPCWSTR lpName,
if (!(dwOpenMode & FILE_FLAG_OVERLAPPED)) if (!(dwOpenMode & FILE_FLAG_OVERLAPPED))
CreateOptions = CreateOptions | FILE_SYNCHRONOUS_IO_NONALERT; CreateOptions = CreateOptions | FILE_SYNCHRONOUS_IO_NONALERT;
switch (dwOpenMode & PIPE_ACCESS_DUPLEX) if (dwOpenMode & PIPE_ACCESS_OUTBOUND)
{ {
case PIPE_ACCESS_INBOUND: ShareAccess |= FILE_SHARE_READ;
CreateOptions |= FILE_PIPE_INBOUND; DesiredAccess |= GENERIC_WRITE;
ShareAccess |= FILE_SHARE_WRITE; }
DesiredAccess |= GENERIC_READ; if (dwOpenMode & PIPE_ACCESS_INBOUND)
break; {
ShareAccess |= FILE_SHARE_WRITE;
case PIPE_ACCESS_OUTBOUND: DesiredAccess |= GENERIC_READ;
CreateOptions |= FILE_PIPE_OUTBOUND; }
ShareAccess |= FILE_SHARE_READ;
DesiredAccess |= GENERIC_WRITE;
break;
case PIPE_ACCESS_DUPLEX:
CreateOptions |= FILE_PIPE_FULL_DUPLEX;
ShareAccess |= (FILE_SHARE_READ | FILE_SHARE_WRITE);
DesiredAccess |= (GENERIC_READ | GENERIC_WRITE);
break;
}
if (dwPipeMode & PIPE_TYPE_MESSAGE) if (dwPipeMode & PIPE_TYPE_MESSAGE)
WriteModeMessage = FILE_PIPE_MESSAGE_MODE; WriteModeMessage = FILE_PIPE_MESSAGE_MODE;
else else

View file

@ -41,11 +41,11 @@ BOOL STDCALL CreatePipe(PHANDLE hReadPipe,
ULONG Attributes; ULONG Attributes;
PSECURITY_DESCRIPTOR SecurityDescriptor = NULL; PSECURITY_DESCRIPTOR SecurityDescriptor = NULL;
DefaultTimeout.QuadPart = 300000000; /* 30 seconds */ DefaultTimeout.QuadPart = -300000000; /* 30 seconds */
PipeId = (ULONG)InterlockedIncrement((LONG*)&ProcessPipeId); PipeId = (ULONG)InterlockedIncrement((LONG*)&ProcessPipeId);
swprintf(Buffer, swprintf(Buffer,
L"\\Device\\NamedPipe\\Win32Pipes.%08x.%08x", L"\\\\.\\PIPE\\Win32Pipes.%08x.%08x",
NtCurrentTeb()->Cid.UniqueProcess, NtCurrentTeb()->Cid.UniqueProcess,
PipeId); PipeId);
RtlInitUnicodeString (&PipeName, RtlInitUnicodeString (&PipeName,
@ -73,7 +73,7 @@ BOOL STDCALL CreatePipe(PHANDLE hReadPipe,
FILE_GENERIC_READ |FILE_WRITE_ATTRIBUTES | SYNCHRONIZE, FILE_GENERIC_READ |FILE_WRITE_ATTRIBUTES | SYNCHRONIZE,
&ObjectAttributes, &ObjectAttributes,
&StatusBlock, &StatusBlock,
FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_SHARE_WRITE,
FILE_CREATE, FILE_CREATE,
FILE_SYNCHRONOUS_IO_NONALERT, FILE_SYNCHRONOUS_IO_NONALERT,
FALSE, FALSE,
@ -93,8 +93,8 @@ BOOL STDCALL CreatePipe(PHANDLE hReadPipe,
FILE_GENERIC_WRITE | SYNCHRONIZE, FILE_GENERIC_WRITE | SYNCHRONIZE,
&ObjectAttributes, &ObjectAttributes,
&StatusBlock, &StatusBlock,
FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_SHARE_READ,
FILE_SYNCHRONOUS_IO_NONALERT | FILE_NON_DIRECTORY_FILE); FILE_SYNCHRONOUS_IO_NONALERT);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
NtClose(ReadPipeHandle); NtClose(ReadPipeHandle);