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

Side by Side Diff: src/plugin/AdblockPlusClient.cpp

Issue 6505394822184960: Issue 1109 - Support notifications (Closed)
Patch Set: Created May 11, 2015, 10:01 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 11 matching lines...) Expand all
22 #include "PluginClientFactory.h" 22 #include "PluginClientFactory.h"
23 #include "PluginMutex.h" 23 #include "PluginMutex.h"
24 #include "PluginClass.h" 24 #include "PluginClass.h"
25 25
26 #include "AdblockPlusClient.h" 26 #include "AdblockPlusClient.h"
27 27
28 #include "../shared/Utils.h" 28 #include "../shared/Utils.h"
29 29
30 namespace 30 namespace
31 { 31 {
32 class ScopedProcessInformation : public PROCESS_INFORMATION {
33 public:
34 ScopedProcessInformation()
35 {
36 hProcess = hThread = 0;
37 dwProcessId = dwThreadId = 0;
38 }
39 ~ScopedProcessInformation()
40 {
41 if (hThread != nullptr)
42 {
43 CloseHandle(hThread);
44 }
45 if (hProcess != nullptr)
46 {
47 CloseHandle(hProcess);
48 }
49 }
50 };
51
32 void SpawnAdblockPlusEngine() 52 void SpawnAdblockPlusEngine()
33 { 53 {
34 std::wstring engineExecutablePath = GetDllDir() + L"AdblockPlusEngine.exe"; 54 std::wstring engineExecutablePath = GetDllDir() + L"AdblockPlusEngine.exe";
35 CString params = ToCString(L"AdblockPlusEngine.exe " + GetBrowserLanguage()) ; 55 std::wstring params = L"AdblockPlusEngine.exe " + GetBrowserLanguage();
36 56
37 STARTUPINFO startupInfo = {}; 57 STARTUPINFO startupInfo = {};
38 PROCESS_INFORMATION processInformation = {}; 58 ScopedProcessInformation processInformation;
39 59
40 HANDLE token; 60 // We need to break out from AppContainer. Launch with default security - re gistry entry will eat the user prompt
41 OpenProcessToken(GetCurrentProcess(), TOKEN_DUPLICATE | TOKEN_ADJUST_DEFAULT | TOKEN_QUERY | TOKEN_ASSIGN_PRIMARY, &token); 61 // See http://msdn.microsoft.com/en-us/library/bb250462(v=vs.85).aspx#wpm_el ebp
42 62 BOOL createProcRes = CreateProcessW(engineExecutablePath.c_str(), &params[0] ,
43 TOKEN_APPCONTAINER_INFORMATION *acs = NULL; 63 0, 0, false, 0, 0, 0, &startupInfo, &processInformation);
44 DWORD length = 0;
45
46 // Get AppContainer SID
47 if (!GetTokenInformation(token, TokenAppContainerSid, acs, 0, &length) && Ge tLastError() == ERROR_INSUFFICIENT_BUFFER)
48 {
49 acs = (TOKEN_APPCONTAINER_INFORMATION*) HeapAlloc(GetProcessHeap(), HEAP _ZERO_MEMORY, length);
50 if (acs != NULL)
51 {
52 GetTokenInformation(token, TokenAppContainerSid, acs, length, &length) ;
53 }
54 else
55 {
56 throw std::runtime_error("Out of memory");
57 }
58 }
59
60 BOOL createProcRes = 0;
61 // Running inside AppContainer or in Windows XP
62 if ((acs != NULL && acs->TokenAppContainer != NULL) || !IsWindowsVistaOrLate r())
63 {
64 // We need to break out from AppContainer. Launch with default security - registry entry will eat the user prompt
65 // See http://msdn.microsoft.com/en-us/library/bb250462(v=vs.85).aspx#wpm_ elebp
66 createProcRes = CreateProcessW(engineExecutablePath.c_str(), params.GetBuf fer(params.GetLength() + 1),
67 0, 0, false, 0, 0, 0, (STARTUPINFOW*)&startupInfo, &processInformation);
68 }
69 else
70 {
71 // Launch with Low Integrity explicitly
72 HANDLE newToken;
73 DuplicateTokenEx(token, 0, 0, SecurityImpersonation, TokenPrimary, &newTok en);
74
75 PSID integritySid = 0;
76 ConvertStringSidToSid(L"S-1-16-4096", &integritySid);
77 std::tr1::shared_ptr<SID> sharedIntegritySid(static_cast<SID*>(integritySi d), FreeSid); // Just to simplify cleanup
78
79 TOKEN_MANDATORY_LABEL tml = {};
80 tml.Label.Attributes = SE_GROUP_INTEGRITY;
81 tml.Label.Sid = integritySid;
82
83 // Set the process integrity level
84 SetTokenInformation(newToken, TokenIntegrityLevel, &tml, sizeof(tml));
85
86 STARTUPINFO startupInfo = {};
87 PROCESS_INFORMATION processInformation = {};
88
89 createProcRes = CreateProcessAsUserW(newToken, engineExecutablePath.c_str( ), params.GetBuffer(params.GetLength() + 1),
90 0, 0, false, 0, 0, 0, (STARTUPINFOW*)&startupInfo, &processInformation);
91 }
92
93 if (!createProcRes) 64 if (!createProcRes)
94 { 65 {
95 throw std::runtime_error("Failed to start Adblock Plus Engine"); 66 throw std::runtime_error("Failed to start Adblock Plus Engine");
96 } 67 }
97
98 CloseHandle(processInformation.hProcess);
99 CloseHandle(processInformation.hThread);
100 } 68 }
101 69
102 Communication::Pipe* OpenEnginePipe() 70 Communication::Pipe* OpenEnginePipe()
103 { 71 {
104 try 72 try
105 { 73 {
106 return new Communication::Pipe(Communication::pipeName, Communication::Pip e::MODE_CONNECT); 74 return new Communication::Pipe(Communication::pipeName, Communication::Pip e::MODE_CONNECT);
107 } 75 }
108 catch (Communication::PipeConnectionError e) 76 catch (Communication::PipeConnectionError e)
109 { 77 {
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 DEBUG_GENERAL("CompareVersions"); 530 DEBUG_GENERAL("CompareVersions");
563 Communication::OutputBuffer request; 531 Communication::OutputBuffer request;
564 request << Communication::PROC_COMPARE_VERSIONS << v1 << v2; 532 request << Communication::PROC_COMPARE_VERSIONS << v1 << v2;
565 Communication::InputBuffer response; 533 Communication::InputBuffer response;
566 if (!CallEngine(request, response)) 534 if (!CallEngine(request, response))
567 return 0; 535 return 0;
568 int result; 536 int result;
569 response >> result; 537 response >> result;
570 return result; 538 return result;
571 } 539 }
OLDNEW

Powered by Google App Engine
This is Rietveld