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 //Pickup file for readability review. | |
| 8 | |
| 7 #include "chrome/installer/setup/setup_util.h" | 9 #include "chrome/installer/setup/setup_util.h" |
| 8 | 10 |
| 9 #include <windows.h> | 11 #include <windows.h> |
| 10 | 12 |
| 11 #include "base/file_util.h" | 13 #include "base/file_util.h" |
| 12 #include "base/logging.h" | 14 #include "base/logging.h" |
| 13 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 14 #include "chrome/installer/util/installer_state.h" | 16 #include "chrome/installer/util/installer_state.h" |
| 15 #include "chrome/installer/util/util_constants.h" | 17 #include "chrome/installer/util/util_constants.h" |
| 16 #include "courgette/courgette.h" | 18 #include "courgette/courgette.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 } | 83 } |
| 82 | 84 |
| 83 return (version_found ? max_version.release() : NULL); | 85 return (version_found ? max_version.release() : NULL); |
| 84 } | 86 } |
| 85 | 87 |
| 86 bool DeleteFileFromTempProcess(const FilePath& path, | 88 bool DeleteFileFromTempProcess(const FilePath& path, |
| 87 uint32 delay_before_delete_ms) { | 89 uint32 delay_before_delete_ms) { |
| 88 static const wchar_t kRunDll32Path[] = | 90 static const wchar_t kRunDll32Path[] = |
| 89 L"%SystemRoot%\\System32\\rundll32.exe"; | 91 L"%SystemRoot%\\System32\\rundll32.exe"; |
| 90 wchar_t rundll32[MAX_PATH]; | 92 wchar_t rundll32[MAX_PATH]; |
| 91 DWORD size = ExpandEnvironmentStrings(kRunDll32Path, rundll32, | 93 DWORD size = |
| 92 arraysize(rundll32)); | 94 ExpandEnvironmentStrings(kRunDll32Path, rundll32, arraysize(rundll32)); |
| 93 if (!size || size >= MAX_PATH) | 95 if (!size || size >= MAX_PATH) |
| 94 return false; | 96 return false; |
| 95 | 97 |
| 96 STARTUPINFO startup = { sizeof(STARTUPINFO) }; | 98 STARTUPINFO startup = { sizeof(STARTUPINFO) }; |
| 97 PROCESS_INFORMATION pi = {0}; | 99 PROCESS_INFORMATION pi = {0}; |
| 98 BOOL ok = ::CreateProcess(NULL, rundll32, NULL, NULL, FALSE, CREATE_SUSPENDED, | 100 BOOL ok = ::CreateProcess(NULL, rundll32, NULL, NULL, FALSE, CREATE_SUSPENDED, |
| 99 NULL, NULL, &startup, &pi); | 101 NULL, NULL, &startup, &pi); |
| 100 if (ok) { | 102 if (ok) { |
| 101 // We use the main thread of the new process to run: | 103 // We use the main thread of the new process to run: |
| 102 // Sleep(delay_before_delete_ms); | 104 // Sleep(delay_before_delete_ms); |
| 103 // DeleteFile(path); | 105 // DeleteFile(path); |
| 104 // ExitProcess(0); | 106 // ExitProcess(0); |
| 105 // This runs before the main routine of the process runs, so it doesn't | 107 // This runs before the main routine of the process runs, so it doesn't |
| 106 // matter much which executable we choose except that we don't want to | 108 // matter much which executable we choose except that we don't want to |
| 107 // use e.g. a console app that causes a window to be created. | 109 // use e.g. a console app that causes a window to be created. |
| 108 size = (path.value().length() + 1) * sizeof(path.value()[0]); | 110 size = (path.value().length() + 1) * sizeof(path.value()[0]); |
| 109 void* mem = ::VirtualAllocEx(pi.hProcess, NULL, size, MEM_COMMIT, | 111 void* mem = ::VirtualAllocEx(pi.hProcess, NULL, size, MEM_COMMIT, |
| 110 PAGE_READWRITE); | 112 PAGE_READWRITE); |
| 111 if (mem) { | 113 if (mem) { |
| 112 SIZE_T written = 0; | 114 SIZE_T written = 0; |
| 113 ::WriteProcessMemory(pi.hProcess, mem, path.value().c_str(), | 115 ::WriteProcessMemory( |
| 116 pi.hProcess, mem, path.value().c_str(), | |
| 114 (path.value().size() + 1) * sizeof(path.value()[0]), &written); | 117 (path.value().size() + 1) * sizeof(path.value()[0]), &written); |
| 115 HMODULE kernel32 = ::GetModuleHandle(L"kernel32.dll"); | 118 HMODULE kernel32 = ::GetModuleHandle(L"kernel32.dll"); |
| 116 PAPCFUNC sleep = reinterpret_cast<PAPCFUNC>( | 119 PAPCFUNC sleep = reinterpret_cast<PAPCFUNC>( |
| 117 ::GetProcAddress(kernel32, "Sleep")); | 120 ::GetProcAddress(kernel32, "Sleep")); |
| 118 PAPCFUNC delete_file = reinterpret_cast<PAPCFUNC>( | 121 PAPCFUNC delete_file = reinterpret_cast<PAPCFUNC>( |
| 119 ::GetProcAddress(kernel32, "DeleteFileW")); | 122 ::GetProcAddress(kernel32, "DeleteFileW")); |
| 120 PAPCFUNC exit_process = reinterpret_cast<PAPCFUNC>( | 123 PAPCFUNC exit_process = reinterpret_cast<PAPCFUNC>( |
| 121 ::GetProcAddress(kernel32, "ExitProcess")); | 124 ::GetProcAddress(kernel32, "ExitProcess")); |
| 122 if (!sleep || !delete_file || !exit_process) { | 125 if (!sleep || !delete_file || !exit_process) { |
| 123 NOTREACHED(); | 126 NOTREACHED(); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 142 | 145 |
| 143 string16 GetActiveSetupPath(BrowserDistribution* dist) { | 146 string16 GetActiveSetupPath(BrowserDistribution* dist) { |
| 144 static const wchar_t kInstalledComponentsPath[] = | 147 static const wchar_t kInstalledComponentsPath[] = |
| 145 L"Software\\Microsoft\\Active Setup\\Installed Components\\"; | 148 L"Software\\Microsoft\\Active Setup\\Installed Components\\"; |
| 146 return kInstalledComponentsPath + dist->GetAppGuid(); | 149 return kInstalledComponentsPath + dist->GetAppGuid(); |
| 147 } | 150 } |
| 148 | 151 |
| 149 ScopedTokenPrivilege::ScopedTokenPrivilege(const wchar_t* privilege_name) | 152 ScopedTokenPrivilege::ScopedTokenPrivilege(const wchar_t* privilege_name) |
| 150 : is_enabled_(false) { | 153 : is_enabled_(false) { |
| 151 if (!::OpenProcessToken(::GetCurrentProcess(), | 154 if (!::OpenProcessToken(::GetCurrentProcess(), |
| 152 TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, token_.Receive())) { | 155 TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, |
| 156 token_.Receive())) { | |
| 153 return; | 157 return; |
| 154 } | 158 } |
| 155 | 159 |
| 156 LUID privilege_luid; | 160 LUID privilege_luid; |
| 157 if (!::LookupPrivilegeValue(NULL, privilege_name, &privilege_luid)) { | 161 if (!::LookupPrivilegeValue(NULL, privilege_name, &privilege_luid)) { |
| 158 token_.Close(); | 162 token_.Close(); |
| 159 return; | 163 return; |
| 160 } | 164 } |
| 161 | 165 |
| 162 // Adjust the token's privileges to enable |privilege_name|. If this privilege | 166 // Adjust the token's privileges to enable |privilege_name|. If this privilege |
| 163 // was already enabled, |previous_privileges_|.PrivilegeCount will be set to 0 | 167 // was already enabled, |previous_privileges_|.PrivilegeCount will be set to 0 |
| 164 // and we then know not to disable this privilege upon destruction. | 168 // and we then know not to disable this privilege upon destruction. |
| 165 TOKEN_PRIVILEGES tp; | 169 TOKEN_PRIVILEGES tp; |
| 166 tp.PrivilegeCount = 1; | 170 tp.PrivilegeCount = 1; |
| 167 tp.Privileges[0].Luid = privilege_luid; | 171 tp.Privileges[0].Luid = privilege_luid; |
| 168 tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; | 172 tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; |
| 169 DWORD return_length; | 173 DWORD return_length; |
| 170 if (!::AdjustTokenPrivileges(token_, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), | 174 if (::AdjustTokenPrivileges(token_, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), |
|
dominich
2012/09/10 15:40:42
this might be more readable as:
is_enabled_ = ::A
gab
2012/09/10 19:14:05
Done.
| |
| 171 &previous_privileges_, &return_length)) { | 175 &previous_privileges_, &return_length)) { |
| 176 is_enabled_ = true; | |
| 177 } else { | |
| 172 token_.Close(); | 178 token_.Close(); |
| 173 } else { | |
| 174 is_enabled_ = true; | |
| 175 } | 179 } |
| 176 } | 180 } |
| 177 | 181 |
| 178 ScopedTokenPrivilege::~ScopedTokenPrivilege() { | 182 ScopedTokenPrivilege::~ScopedTokenPrivilege() { |
| 179 if (is_enabled_ && previous_privileges_.PrivilegeCount != 0) { | 183 if (is_enabled_ && previous_privileges_.PrivilegeCount != 0) { |
| 180 ::AdjustTokenPrivileges(token_, FALSE, &previous_privileges_, | 184 ::AdjustTokenPrivileges(token_, FALSE, &previous_privileges_, |
| 181 sizeof(TOKEN_PRIVILEGES), NULL, NULL); | 185 sizeof(TOKEN_PRIVILEGES), NULL, NULL); |
| 182 } | 186 } |
| 183 } | 187 } |
| 184 | 188 |
| 185 } // namespace installer | 189 } // namespace installer |
| OLD | NEW |