| OLD | NEW |
| (Empty) |
| 1 // Copyright 2007-2009 Google Inc. | |
| 2 // | |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 // you may not use this file except in compliance with the License. | |
| 5 // You may obtain a copy of the License at | |
| 6 // | |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 // | |
| 9 // Unless required by applicable law or agreed to in writing, software | |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 // See the License for the specific language governing permissions and | |
| 13 // limitations under the License. | |
| 14 // ======================================================================== | |
| 15 // | |
| 16 // Not used at the moment. The idea is to use an external process, such as | |
| 17 // the web browser in cases where GoogleUpdate.exe is not able to connect | |
| 18 // directly for some reason. | |
| 19 // | |
| 20 // TODO(Omaha) - Better algorithm for finding IBrowserHttpRequest2 objects: | |
| 21 // We currently use shared memory. We have the high integrity process | |
| 22 // read from shared memory that the low integrity process writes to. We assume | |
| 23 // a common executable, IEXPLORE.exe, which is limiting, because in the future | |
| 24 // we could be embedded in multiple processes. | |
| 25 | |
| 26 // Another choice for detection will be more efficient overall. But it will | |
| 27 // entail some work: each IBrowserRequest will register itself with the ROT. | |
| 28 // It does this through a medium-integrity GoogleUpdate.exe. The high integrity | |
| 29 // process will then impersonate the explorer token, and then CoCreate | |
| 30 // GoogleUpdate.exe at medium integrity. Then the medium integrity GoogleUpdate | |
| 31 // can return an appropriate IBrowserRequest interface from the local ROT. | |
| 32 // | |
| 33 // This scheme is flexible enough that it can work regardless of which | |
| 34 // process the IBrowserRequest object(s) reside in. We could have a Firefox | |
| 35 // plugin, a Chrome-resident object, an object residing inside Google Talk, etc. | |
| 36 | |
| 37 #include "omaha/net/browser_request.h" | |
| 38 #include <atlbase.h> | |
| 39 #include <atlcom.h> | |
| 40 #include "omaha/base/logging.h" | |
| 41 #include "omaha/base/system.h" | |
| 42 #include "omaha/base/vista_utils.h" | |
| 43 #include "omaha/goopdate/google_update_proxy.h" | |
| 44 | |
| 45 namespace omaha { | |
| 46 | |
| 47 BrowserRequest::BrowserRequest() { | |
| 48 NET_LOG(L3, (_T("[BrowserRequest::BrowserRequest]"))); | |
| 49 user_agent_.Format(_T("%s;iexplore"), NetworkConfig::GetUserAgent()); | |
| 50 | |
| 51 #if 0 | |
| 52 if (!GetAvailableBrowserObjects()) { | |
| 53 NET_LOG(LW, (_T("[BrowserRequest: No Browser Objects Found.]"))); | |
| 54 } | |
| 55 #endif | |
| 56 } | |
| 57 | |
| 58 bool BrowserRequest::GetAvailableBrowserObjects() { | |
| 59 std::vector<uint32> pids; | |
| 60 HRESULT hr = vista::GetProcessPidsForActiveUserOrSession(kIExplore, &pids); | |
| 61 if (FAILED(hr)) { | |
| 62 NET_LOG(LE, (_T("[GetProcessPidsForActiveUserOrSession fail][0x%x]"), hr)); | |
| 63 return false; | |
| 64 } | |
| 65 | |
| 66 bool is_system = false; | |
| 67 hr = IsSystemProcess(&is_system); | |
| 68 if (FAILED(hr)) { | |
| 69 NET_LOG(LE, (_T("[IsSystemProcess failed][0x%x]"), hr)); | |
| 70 return false; | |
| 71 } | |
| 72 | |
| 73 CString shared_memory_prefix; | |
| 74 DWORD active_session = System::GetActiveSessionId(); | |
| 75 if (is_system && active_session != System::GetCurrentSessionId()) { | |
| 76 // The Session\\ syntax references a local object in a different session. | |
| 77 shared_memory_prefix.Format(_T("Session\\%d\\"), active_session); | |
| 78 } | |
| 79 shared_memory_prefix += kBrowserHttpRequestShareName; | |
| 80 | |
| 81 std::vector<uint32>::const_iterator iter = pids.begin(); | |
| 82 for (; iter != pids.end(); ++iter) { | |
| 83 uint32 pid = *iter; | |
| 84 CString shared_memory_name; | |
| 85 shared_memory_name = shared_memory_prefix; | |
| 86 shared_memory_name.AppendFormat(_T("%d"), pid); | |
| 87 SharedMemoryAttributes default_attributes(shared_memory_name, | |
| 88 CSecurityDesc()); | |
| 89 SharedMemoryProxy<IBrowserHttpRequest2, FakeGLock> proxy_read( | |
| 90 true, | |
| 91 &default_attributes); | |
| 92 CComPtr<IBrowserHttpRequest2> browser_http_request; | |
| 93 HRESULT hr = proxy_read.GetObject(&browser_http_request); | |
| 94 if (FAILED(hr) || !browser_http_request) { | |
| 95 NET_LOG(LW, (_T("[GetObject failed][%d][%d][0x%x]"), | |
| 96 pid, browser_http_request, hr)); | |
| 97 // Keep looking for more IBrowserHttpRequest2 objects. | |
| 98 continue; | |
| 99 } | |
| 100 | |
| 101 objects_.push_back(browser_http_request); | |
| 102 } | |
| 103 | |
| 104 return !objects_.empty(); | |
| 105 } | |
| 106 | |
| 107 HRESULT BrowserRequest::SendRequest(BSTR url, | |
| 108 BSTR post_data, | |
| 109 BSTR request_headers, | |
| 110 VARIANT response_headers_needed, | |
| 111 CComVariant* response_headers, | |
| 112 DWORD* response_code, | |
| 113 BSTR* cache_filename_bstr) { | |
| 114 NET_LOG(L3, (_T("[BrowserRequest::SendRequest]"))); | |
| 115 if (objects_.empty()) { | |
| 116 NET_LOG(LE, (_T("[SendRequest: No Browser Objects available.]"))); | |
| 117 return E_FAIL; | |
| 118 } | |
| 119 | |
| 120 BrowserObjects::const_iterator i = objects_.begin(); | |
| 121 HRESULT hr = E_UNEXPECTED; | |
| 122 CComBSTR cache_filename; | |
| 123 for (; i != objects_.end(); ++i) { | |
| 124 CComPtr<IBrowserHttpRequest2> browser_object(*i); | |
| 125 response_headers->Clear(); | |
| 126 *response_code = 0; | |
| 127 cache_filename.Empty(); | |
| 128 hr = browser_object->Send(url, | |
| 129 post_data, | |
| 130 request_headers, | |
| 131 response_headers_needed, | |
| 132 response_headers, | |
| 133 response_code, | |
| 134 &cache_filename); | |
| 135 NET_LOG(L3, (_T("[BrowserRequest::SendRequest][0x%x][%d][%s]"), | |
| 136 hr, *response_code, cache_filename)); | |
| 137 | |
| 138 if (!*response_code) { | |
| 139 continue; | |
| 140 } | |
| 141 | |
| 142 *cache_filename_bstr = cache_filename.Detach(); | |
| 143 return S_OK; | |
| 144 } | |
| 145 | |
| 146 return FAILED(hr) ? hr : E_UNEXPECTED; | |
| 147 } | |
| 148 | |
| 149 } // namespace omaha | |
| 150 | |
| OLD | NEW |