[Box Backup-dev] COMMIT r243 - box/chris/win32/pipe-security/lib/win32
boxbackup-dev@fluffy.co.uk
boxbackup-dev@fluffy.co.uk
Thu, 15 Dec 2005 14:09:14 +0000 (GMT)
Author: chris
Date: 2005-12-15 14:09:10 +0000 (Thu, 15 Dec 2005)
New Revision: 243
Modified:
box/chris/win32/pipe-security/lib/win32/WinNamedPipeStream.cpp
Log:
* WinNamedPipeStream.cpp
- Put pipe into message mode on client side
- Attach a security descriptor on the server side to inherit security
from the parent process, which should be safe?
Modified: box/chris/win32/pipe-security/lib/win32/WinNamedPipeStream.cpp
===================================================================
--- box/chris/win32/pipe-security/lib/win32/WinNamedPipeStream.cpp 2005-12-15 13:52:55 UTC (rev 242)
+++ box/chris/win32/pipe-security/lib/win32/WinNamedPipeStream.cpp 2005-12-15 14:09:10 UTC (rev 243)
@@ -72,6 +72,11 @@
THROW_EXCEPTION(ServerException, SocketAlreadyOpen)
}
+ SECURITY_ATTRIBUTES Security;
+ Security.nLength = sizeof(SECURITY_ATTRIBUTES);
+ Security.lpSecurityDescriptor = NULL; // inherit from process
+ Security.bInheritHandle = FALSE; // don't pass to new processes
+
mSocketHandle = CreateNamedPipeW(
pName, // pipe name
PIPE_ACCESS_DUPLEX, // read/write access
@@ -82,7 +87,7 @@
4096, // output buffer size
4096, // input buffer size
NMPWAIT_USE_DEFAULT_WAIT, // client time-out
- NULL); // default security attribute
+ &Security); // use our security attributes
if (mSocketHandle == NULL)
{
@@ -137,9 +142,23 @@
{
::syslog(LOG_ERR, "Failed to connect to server's named pipe: "
"error %d", GetLastError());
+ CloseHandle(mSocketHandle);
+ mSocketHandle = NULL;
THROW_EXCEPTION(ServerException, SocketOpenError)
}
+ if (!SetNamedPipeHandleState(
+ mSocketHandle, // pipe handle
+ PIPE_READMODE_MESSAGE | // put this end into message mode
+ PIPE_WAIT, // put this end into blocking mode
+ NULL, // don't change the collection count
+ NULL)) // don't change the collect timeout
+ {
+ ::syslog(LOG_ERR, "Failed to put pipe into message mode: "
+ "error %d", GetLastError());
+ THROW_EXCEPTION(ServerException, SocketOpenError)
+ }
+
mReadClosed = FALSE;
mWriteClosed = FALSE;
mIsServer = FALSE; // just close the socket