Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: src/shared/Communication.cpp

Issue 4859386648330240: Fix named pipe security on Windows XP (Closed)
Left Patch Set: Created June 16, 2014, 10:15 a.m.
Right Patch Set: Created June 26, 2014, 12:57 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/plugin/AdblockPlusClient.cpp ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 OpenProcessToken(GetCurrentProcess(), TOKEN_READ, token); 187 OpenProcessToken(GetCurrentProcess(), TOKEN_READ, token);
188 188
189 if (IsWindowsVistaOrLater()) 189 if (IsWindowsVistaOrLater())
190 { 190 {
191 std::auto_ptr<SID> logonSid = GetLogonSid(token); 191 std::auto_ptr<SID> logonSid = GetLogonSid(token);
192 // Create a SECURITY_DESCRIPTOR that has both Low Integrity and allows acc ess to all AppContainers 192 // Create a SECURITY_DESCRIPTOR that has both Low Integrity and allows acc ess to all AppContainers
193 // This is needed since IE likes to jump out of Enhanced Protected Mode fo r specific pages (bing.com) 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()); 194 std::auto_ptr<SECURITY_DESCRIPTOR> securityDescriptor = CreateSecurityDesc riptor(logonSid.get());
195 securityAttributes.lpSecurityDescriptor = securityDescriptor.release(); 195 securityAttributes.lpSecurityDescriptor = securityDescriptor.release();
196 sharedSecurityDescriptor.reset(static_cast<SECURITY_DESCRIPTOR*>(securityA ttributes.lpSecurityDescriptor)); 196 sharedSecurityDescriptor.reset(static_cast<SECURITY_DESCRIPTOR*>(securityA ttributes.lpSecurityDescriptor));
197 197 }
198 pipe = CreateNamedPipeW(pipeName.c_str(), PIPE_ACCESS_DUPLEX, PIPE_TYPE_M ESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, 198 pipe = CreateNamedPipeW(pipeName.c_str(), PIPE_ACCESS_DUPLEX, PIPE_TYPE_MES SAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT,
199 PIPE_UNLIMITED_INSTANCES, bufferSize, bufferSize, 0, &securityAttributes ); 199 PIPE_UNLIMITED_INSTANCES, bufferSize, bufferSize, 0, &securityAttributes);
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 );
Felix Dahlke 2014/06/24 12:25:05 This is the exact same "CreateNamedPipeW" done in
205 }
206 } 200 }
207 else 201 else
208 { 202 {
209 pipe = CreateFileW(pipeName.c_str(), GENERIC_READ | GENERIC_WRITE, 0, 0, OPE N_EXISTING, 0, 0); 203 pipe = CreateFileW(pipeName.c_str(), GENERIC_READ | GENERIC_WRITE, 0, 0, OPE N_EXISTING, 0, 0);
210 if (pipe == INVALID_HANDLE_VALUE && GetLastError() == ERROR_PIPE_BUSY) 204 if (pipe == INVALID_HANDLE_VALUE && GetLastError() == ERROR_PIPE_BUSY)
211 { 205 {
212 if (!WaitNamedPipeW(pipeName.c_str(), 10000)) 206 if (!WaitNamedPipeW(pipeName.c_str(), 10000))
213 throw PipeBusyError(); 207 throw PipeBusyError();
214 208
215 pipe = CreateFileW(pipeName.c_str(), GENERIC_READ | GENERIC_WRITE, 0, 0, O PEN_EXISTING, 0, 0); 209 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
265 return Communication::InputBuffer(stream.str()); 259 return Communication::InputBuffer(stream.str());
266 } 260 }
267 261
268 void Communication::Pipe::WriteMessage(Communication::OutputBuffer& message) 262 void Communication::Pipe::WriteMessage(Communication::OutputBuffer& message)
269 { 263 {
270 DWORD bytesWritten; 264 DWORD bytesWritten;
271 std::string data = message.Get(); 265 std::string data = message.Get();
272 if (!WriteFile(pipe, data.c_str(), static_cast<DWORD>(data.length()), &bytesWr itten, 0)) 266 if (!WriteFile(pipe, data.c_str(), static_cast<DWORD>(data.length()), &bytesWr itten, 0))
273 throw std::runtime_error("Failed to write to pipe"); 267 throw std::runtime_error("Failed to write to pipe");
274 } 268 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld