Use a new passive pipe state (0) to ensure that client ends don't connect to server ends in calls to WaitNamed Pipe().

svn path=/trunk/; revision=12402
This commit is contained in:
Eric Kohl
2004-12-30 12:34:27 +00:00
parent da6d4e37b3
commit 4801e8cc23
2 changed files with 40 additions and 12 deletions
+22 -9
View File
@@ -1,4 +1,4 @@
/* $Id: create.c,v 1.26 2004/12/23 23:58:44 ekohl Exp $
/* $Id: create.c,v 1.27 2004/12/30 12:34:26 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@@ -74,7 +74,7 @@ NpfsCreate(PDEVICE_OBJECT DeviceObject,
PFILE_OBJECT FileObject;
PNPFS_PIPE Pipe;
PNPFS_FCB ClientFcb;
PNPFS_FCB ServerFcb;
PNPFS_FCB ServerFcb = NULL;
PNPFS_DEVICE_EXTENSION DeviceExt;
ULONG Disposition;
@@ -89,6 +89,11 @@ NpfsCreate(PDEVICE_OBJECT DeviceObject,
Irp->IoStatus.Information = 0;
if (Disposition & FILE_OPEN)
{
DPRINT("NpfsCreate() open client end for special use!\n");
}
/*
* Step 1. Find the pipe we're trying to open.
*/
@@ -117,19 +122,27 @@ NpfsCreate(PDEVICE_OBJECT DeviceObject,
*/
KeLockMutex(&Pipe->FcbListLock);
ServerFcb = NpfsFindListeningServerInstance(Pipe);
if (ServerFcb == NULL)
if (!(Disposition & FILE_OPEN))
{
/* Not found, bail out with error for FILE_OPEN requests. */
DPRINT("No server fcb found!\n");
if (Disposition == FILE_OPEN)
ServerFcb = NpfsFindListeningServerInstance(Pipe);
if (ServerFcb == NULL)
{
/* Not found, bail out with error for FILE_OPEN requests. */
DPRINT("No listening server fcb found!\n");
KeUnlockMutex(&Pipe->FcbListLock);
Irp->IoStatus.Status = STATUS_PIPE_BUSY;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return STATUS_PIPE_BUSY;
}
}
else if (IsListEmpty(&Pipe->ServerFcbListHead))
{
DPRINT("No server fcb found!\n");
KeUnlockMutex(&Pipe->FcbListLock);
Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return STATUS_UNSUCCESSFUL;
}
/*
* Step 3. Create the client FCB.
@@ -147,7 +160,7 @@ NpfsCreate(PDEVICE_OBJECT DeviceObject,
ClientFcb->Pipe = Pipe;
ClientFcb->PipeEnd = FILE_PIPE_CLIENT_END;
ClientFcb->OtherSide = NULL;
ClientFcb->PipeState = FILE_PIPE_DISCONNECTED_STATE;
ClientFcb->PipeState = (Disposition & FILE_OPEN) ? 0 : FILE_PIPE_DISCONNECTED_STATE;
/* Initialize data list. */
if (Pipe->InboundQuota)
@@ -480,7 +493,7 @@ NpfsClose(
#endif
/*
* Signaling the write event. If is possible that an other
* thread waits of an empty buffer.
* thread waits for an empty buffer.
*/
KeSetEvent(&Fcb->OtherSide->Event, IO_NO_INCREMENT, FALSE);
}
+18 -3
View File
@@ -1,4 +1,4 @@
/* $Id: fsctrl.c,v 1.17 2004/12/23 12:38:16 ekohl Exp $
/* $Id: fsctrl.c,v 1.18 2004/12/30 12:34:27 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@@ -51,6 +51,16 @@ NpfsConnectPipe(PNPFS_FCB Fcb)
NPFS_FCB,
FcbListEntry);
if (ClientFcb->PipeState == 0)
{
/* found a passive (waiting) client fcb */
DPRINT("Passive (waiting) client fcb found -- wake the client\n");
KeSetEvent(&ClientFcb->ConnectEvent, IO_NO_INCREMENT, FALSE);
break;
}
#if 0
if (ClientFcb->PipeState == FILE_PIPE_LISTENING_STATE)
{
/* found a listening client fcb */
@@ -74,6 +84,7 @@ NpfsConnectPipe(PNPFS_FCB Fcb)
return STATUS_PIPE_CONNECTED;
}
#endif
current_entry = current_entry->Flink;
}
@@ -157,6 +168,12 @@ NpfsWaitPipe(PIRP Irp,
WaitPipe = (PNPFS_WAIT_PIPE)Irp->AssociatedIrp.SystemBuffer;
Pipe = Fcb->Pipe;
if (Fcb->PipeState != 0)
{
DPRINT("Pipe is not in passive (waiting) state!\n");
return STATUS_UNSUCCESSFUL;
}
/* search for listening server */
current_entry = Pipe->ServerFcbListHead.Flink;
while (current_entry != &Pipe->ServerFcbListHead)
@@ -177,8 +194,6 @@ NpfsWaitPipe(PIRP Irp,
}
/* no listening server fcb found -- wait for one */
Fcb->PipeState = FILE_PIPE_LISTENING_STATE;
Status = KeWaitForSingleObject(&Fcb->ConnectEvent,
UserRequest,
KernelMode,