Chromium Code Reviews| 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 = | |
|
tommi (sloooow) - chröme
2012/07/20 09:59:25
static const wchar_t kInstalledComponentsPath[] =
gab
2012/07/20 14:45:47
Done.
| |
| 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_(true) { | |
|
tommi (sloooow) - chröme
2012/07/20 09:59:25
nit: initialize to false and just set to true when
gab
2012/07/20 14:45:47
Done.
| |
| 151 if (!::OpenProcessToken(::GetCurrentProcess(), | |
| 152 TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, token_.Receive())) { | |
| 153 is_enabled_ = false; | |
| 154 return; | |
| 155 } | |
| 156 | |
| 157 LUID privilege_luid; | |
| 158 if (!::LookupPrivilegeValue(NULL, privilege_name, &privilege_luid)) { | |
| 159 is_enabled_ = false; | |
| 160 token_.Close(); | |
| 161 return; | |
| 162 } | |
| 163 | |
| 164 // Adjust the token's privileges to enable |privilege_name|. If this privilege | |
| 165 // was already enabled, |previous_privileges_|.PrivilegeCount will be set to 0 | |
| 166 // and we then know not to disable this privilege upon destruction. | |
| 167 TOKEN_PRIVILEGES tp; | |
| 168 tp.PrivilegeCount = 1; | |
| 169 tp.Privileges[0].Luid = privilege_luid; | |
| 170 tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; | |
| 171 DWORD return_length; | |
| 172 if (!::AdjustTokenPrivileges(token_, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), | |
| 173 &previous_privileges_, &return_length)) { | |
| 174 is_enabled_ = false; | |
| 175 token_.Close(); | |
| 176 } | |
|
tommi (sloooow) - chröme
2012/07/20 09:59:25
} else {
is_enabled_ = true;
}
gab
2012/07/20 14:45:47
Done.
| |
| 177 } | |
| 178 | |
| 179 ScopedTokenPrivilege::~ScopedTokenPrivilege() { | |
| 180 if (is_enabled_ && previous_privileges_.PrivilegeCount != 0) { | |
| 181 ::AdjustTokenPrivileges(token_, FALSE, &previous_privileges_, | |
| 182 sizeof(TOKEN_PRIVILEGES), NULL, NULL); | |
| 183 } | |
| 184 } | |
| 185 | |
| 141 } // namespace installer | 186 } // namespace installer |
| OLD | NEW |