Chromium Code Reviews| Index: chrome/installer/setup/setup_util.cc |
| diff --git a/chrome/installer/setup/setup_util.cc b/chrome/installer/setup/setup_util.cc |
| index 340ede9f9ef251aee7858158f1433fb46509069f..fbea2bea77e2ad2e132123999bb47fc3c5c03e3b 100644 |
| --- a/chrome/installer/setup/setup_util.cc |
| +++ b/chrome/installer/setup/setup_util.cc |
| @@ -6,6 +6,8 @@ |
| #include "chrome/installer/setup/setup_util.h" |
| +#include <windows.h> |
| + |
| #include "base/file_util.h" |
| #include "base/logging.h" |
| #include "base/string_util.h" |
| @@ -138,4 +140,47 @@ bool DeleteFileFromTempProcess(const FilePath& path, |
| return ok != FALSE; |
| } |
| +string16 GetActiveSetupPath(BrowserDistribution* dist) { |
| + 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.
|
| + L"Software\\Microsoft\\Active Setup\\Installed Components\\"; |
| + return kInstalledComponentsPath + dist->GetAppGuid(); |
| +} |
| + |
| +ScopedTokenPrivilege::ScopedTokenPrivilege(const wchar_t* privilege_name) |
| + : 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.
|
| + if (!::OpenProcessToken(::GetCurrentProcess(), |
| + TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, token_.Receive())) { |
| + is_enabled_ = false; |
| + return; |
| + } |
| + |
| + LUID privilege_luid; |
| + if (!::LookupPrivilegeValue(NULL, privilege_name, &privilege_luid)) { |
| + is_enabled_ = false; |
| + token_.Close(); |
| + return; |
| + } |
| + |
| + // Adjust the token's privileges to enable |privilege_name|. If this privilege |
| + // was already enabled, |previous_privileges_|.PrivilegeCount will be set to 0 |
| + // and we then know not to disable this privilege upon destruction. |
| + TOKEN_PRIVILEGES tp; |
| + tp.PrivilegeCount = 1; |
| + tp.Privileges[0].Luid = privilege_luid; |
| + tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; |
| + DWORD return_length; |
| + if (!::AdjustTokenPrivileges(token_, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), |
| + &previous_privileges_, &return_length)) { |
| + is_enabled_ = false; |
| + token_.Close(); |
| + } |
|
tommi (sloooow) - chröme
2012/07/20 09:59:25
} else {
is_enabled_ = true;
}
gab
2012/07/20 14:45:47
Done.
|
| +} |
| + |
| +ScopedTokenPrivilege::~ScopedTokenPrivilege() { |
| + if (is_enabled_ && previous_privileges_.PrivilegeCount != 0) { |
| + ::AdjustTokenPrivileges(token_, FALSE, &previous_privileges_, |
| + sizeof(TOKEN_PRIVILEGES), NULL, NULL); |
| + } |
| +} |
| + |
| } // namespace installer |