OLD | NEW |
1 #include <Windows.h> | 1 #include <Windows.h> |
2 #include <Lmcons.h> | 2 #include <Lmcons.h> |
3 #include <Sddl.h> | 3 #include <Sddl.h> |
4 #include <aclapi.h> | 4 #include <aclapi.h> |
5 #include <strsafe.h> | 5 #include <strsafe.h> |
6 | 6 |
7 #include "AutoHandle.h" | 7 #include "AutoHandle.h" |
8 #include "Communication.h" | 8 #include "Communication.h" |
9 #include "Utils.h" | 9 #include "Utils.h" |
10 | 10 |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 Communication::PipeDisconnectedError::PipeDisconnectedError() | 170 Communication::PipeDisconnectedError::PipeDisconnectedError() |
171 : std::runtime_error("Pipe disconnected") | 171 : std::runtime_error("Pipe disconnected") |
172 { | 172 { |
173 } | 173 } |
174 | 174 |
175 Communication::Pipe::Pipe(const std::wstring& pipeName, Communication::Pipe::Mod
e mode) | 175 Communication::Pipe::Pipe(const std::wstring& pipeName, Communication::Pipe::Mod
e mode) |
176 { | 176 { |
177 pipe = INVALID_HANDLE_VALUE; | 177 pipe = INVALID_HANDLE_VALUE; |
178 if (mode == MODE_CREATE) | 178 if (mode == MODE_CREATE) |
179 { | 179 { |
180 | |
181 SECURITY_ATTRIBUTES securityAttributes = {}; | 180 SECURITY_ATTRIBUTES securityAttributes = {}; |
182 securityAttributes.nLength = sizeof(SECURITY_ATTRIBUTES); | 181 securityAttributes.nLength = sizeof(SECURITY_ATTRIBUTES); |
183 securityAttributes.bInheritHandle = TRUE; | 182 securityAttributes.bInheritHandle = TRUE; |
184 | 183 |
185 std::tr1::shared_ptr<SECURITY_DESCRIPTOR> sharedSecurityDescriptor; // Just
to simplify cleanup | 184 std::tr1::shared_ptr<SECURITY_DESCRIPTOR> sharedSecurityDescriptor; // Just
to simplify cleanup |
186 | 185 |
187 AutoHandle token; | 186 AutoHandle token; |
188 OpenProcessToken(GetCurrentProcess(), TOKEN_READ, token); | 187 OpenProcessToken(GetCurrentProcess(), TOKEN_READ, token); |
189 std::auto_ptr<SID> logonSid = GetLogonSid(token); | 188 |
190 // Create a SECURITY_DESCRIPTOR that has both Low Integrity and allows acces
s to all AppContainers | 189 if (IsWindowsVistaOrLater()) |
191 // This is needed since IE likes to jump out of Enhanced Protected Mode for
specific pages (bing.com) | 190 { |
192 std::auto_ptr<SECURITY_DESCRIPTOR> securityDescriptor = CreateSecurityDescri
ptor(logonSid.get()); | 191 std::auto_ptr<SID> logonSid = GetLogonSid(token); |
193 securityAttributes.lpSecurityDescriptor = securityDescriptor.release(); | 192 // Create a SECURITY_DESCRIPTOR that has both Low Integrity and allows acc
ess to all AppContainers |
194 sharedSecurityDescriptor.reset(static_cast<SECURITY_DESCRIPTOR*>(securityAtt
ributes.lpSecurityDescriptor)); | 193 // This is needed since IE likes to jump out of Enhanced Protected Mode fo
r specific pages (bing.com) |
| 194 std::auto_ptr<SECURITY_DESCRIPTOR> securityDescriptor = CreateSecurityDesc
riptor(logonSid.get()); |
| 195 securityAttributes.lpSecurityDescriptor = securityDescriptor.release(); |
| 196 sharedSecurityDescriptor.reset(static_cast<SECURITY_DESCRIPTOR*>(securityA
ttributes.lpSecurityDescriptor)); |
195 | 197 |
196 pipe = CreateNamedPipeW(pipeName.c_str(), PIPE_ACCESS_DUPLEX, PIPE_TYPE_MES
SAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, | 198 pipe = CreateNamedPipeW(pipeName.c_str(), PIPE_ACCESS_DUPLEX, PIPE_TYPE_M
ESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, |
197 PIPE_UNLIMITED_INSTANCES, bufferSize, bufferSize, 0, &securityAttributes); | 199 PIPE_UNLIMITED_INSTANCES, bufferSize, bufferSize, 0, &securityAttributes
); |
198 | 200 } |
| 201 else |
| 202 { |
| 203 pipe = CreateNamedPipeW(pipeName.c_str(), PIPE_ACCESS_DUPLEX, PIPE_TYPE_M
ESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, |
| 204 PIPE_UNLIMITED_INSTANCES, bufferSize, bufferSize, 0, &securityAttributes
); |
| 205 } |
199 } | 206 } |
200 else | 207 else |
201 { | 208 { |
202 pipe = CreateFileW(pipeName.c_str(), GENERIC_READ | GENERIC_WRITE, 0, 0, OPE
N_EXISTING, 0, 0); | 209 pipe = CreateFileW(pipeName.c_str(), GENERIC_READ | GENERIC_WRITE, 0, 0, OPE
N_EXISTING, 0, 0); |
203 if (pipe == INVALID_HANDLE_VALUE && GetLastError() == ERROR_PIPE_BUSY) | 210 if (pipe == INVALID_HANDLE_VALUE && GetLastError() == ERROR_PIPE_BUSY) |
204 { | 211 { |
205 if (!WaitNamedPipeW(pipeName.c_str(), 10000)) | 212 if (!WaitNamedPipeW(pipeName.c_str(), 10000)) |
206 throw PipeBusyError(); | 213 throw PipeBusyError(); |
207 | 214 |
208 pipe = CreateFileW(pipeName.c_str(), GENERIC_READ | GENERIC_WRITE, 0, 0, O
PEN_EXISTING, 0, 0); | 215 pipe = CreateFileW(pipeName.c_str(), GENERIC_READ | GENERIC_WRITE, 0, 0, O
PEN_EXISTING, 0, 0); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 return Communication::InputBuffer(stream.str()); | 265 return Communication::InputBuffer(stream.str()); |
259 } | 266 } |
260 | 267 |
261 void Communication::Pipe::WriteMessage(Communication::OutputBuffer& message) | 268 void Communication::Pipe::WriteMessage(Communication::OutputBuffer& message) |
262 { | 269 { |
263 DWORD bytesWritten; | 270 DWORD bytesWritten; |
264 std::string data = message.Get(); | 271 std::string data = message.Get(); |
265 if (!WriteFile(pipe, data.c_str(), static_cast<DWORD>(data.length()), &bytesWr
itten, 0)) | 272 if (!WriteFile(pipe, data.c_str(), static_cast<DWORD>(data.length()), &bytesWr
itten, 0)) |
266 throw std::runtime_error("Failed to write to pipe"); | 273 throw std::runtime_error("Failed to write to pipe"); |
267 } | 274 } |
OLD | NEW |