| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // | 4 // |
| 5 // This file declares util functions for setup project. | 5 // This file declares util functions for setup project. |
| 6 | 6 |
| 7 #include "chrome/installer/setup/setup_util.h" | 7 #include "chrome/installer/setup/setup_util.h" |
| 8 | 8 |
| 9 #include <windows.h> |
| 10 |
| 9 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 10 #include "base/logging.h" | 12 #include "base/logging.h" |
| 11 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 12 #include "chrome/installer/util/installer_state.h" | 14 #include "chrome/installer/util/installer_state.h" |
| 13 #include "chrome/installer/util/util_constants.h" | 15 #include "chrome/installer/util/util_constants.h" |
| 14 #include "courgette/courgette.h" | 16 #include "courgette/courgette.h" |
| 15 #include "third_party/bspatch/mbspatch.h" | 17 #include "third_party/bspatch/mbspatch.h" |
| 16 | 18 |
| 17 namespace installer { | 19 namespace installer { |
| 18 | 20 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 PLOG(ERROR) << "VirtualAllocEx"; | 133 PLOG(ERROR) << "VirtualAllocEx"; |
| 132 ::TerminateProcess(pi.hProcess, ~0); | 134 ::TerminateProcess(pi.hProcess, ~0); |
| 133 } | 135 } |
| 134 ::CloseHandle(pi.hThread); | 136 ::CloseHandle(pi.hThread); |
| 135 ::CloseHandle(pi.hProcess); | 137 ::CloseHandle(pi.hProcess); |
| 136 } | 138 } |
| 137 | 139 |
| 138 return ok != FALSE; | 140 return ok != FALSE; |
| 139 } | 141 } |
| 140 | 142 |
| 143 string16 GetActiveSetupPath(BrowserDistribution* dist) { |
| 144 static const wchar_t kInstalledComponentsPath[] = |
| 145 L"Software\\Microsoft\\Active Setup\\Installed Components\\"; |
| 146 return kInstalledComponentsPath + dist->GetAppGuid(); |
| 147 } |
| 148 |
| 149 ScopedTokenPrivilege::ScopedTokenPrivilege(const wchar_t* privilege_name) |
| 150 : is_enabled_(false) { |
| 151 if (!::OpenProcessToken(::GetCurrentProcess(), |
| 152 TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, token_.Receive())) { |
| 153 return; |
| 154 } |
| 155 |
| 156 LUID privilege_luid; |
| 157 if (!::LookupPrivilegeValue(NULL, privilege_name, &privilege_luid)) { |
| 158 token_.Close(); |
| 159 return; |
| 160 } |
| 161 |
| 162 // Adjust the token's privileges to enable |privilege_name|. If this privilege |
| 163 // was already enabled, |previous_privileges_|.PrivilegeCount will be set to 0 |
| 164 // and we then know not to disable this privilege upon destruction. |
| 165 TOKEN_PRIVILEGES tp; |
| 166 tp.PrivilegeCount = 1; |
| 167 tp.Privileges[0].Luid = privilege_luid; |
| 168 tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; |
| 169 DWORD return_length; |
| 170 if (!::AdjustTokenPrivileges(token_, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), |
| 171 &previous_privileges_, &return_length)) { |
| 172 token_.Close(); |
| 173 } else { |
| 174 is_enabled_ = true; |
| 175 } |
| 176 } |
| 177 |
| 178 ScopedTokenPrivilege::~ScopedTokenPrivilege() { |
| 179 if (is_enabled_ && previous_privileges_.PrivilegeCount != 0) { |
| 180 ::AdjustTokenPrivileges(token_, FALSE, &previous_privileges_, |
| 181 sizeof(TOKEN_PRIVILEGES), NULL, NULL); |
| 182 } |
| 183 } |
| 184 |
| 141 } // namespace installer | 185 } // namespace installer |
| OLD | NEW |