OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #include "chrome/installer/gcapi/gcapi.h" | 5 #include "chrome/installer/gcapi/gcapi.h" |
6 | 6 |
7 #include <atlbase.h> | 7 #include <atlbase.h> |
8 #include <atlcom.h> | 8 #include <atlcom.h> |
9 #include <windows.h> | 9 #include <windows.h> |
10 #include <sddl.h> | 10 #include <sddl.h> |
11 #define STRSAFE_NO_DEPRECATE | 11 #include <stdlib.h> |
12 #include <strsafe.h> | 12 #include <strsafe.h> |
13 #include <tlhelp32.h> | 13 #include <tlhelp32.h> |
14 | 14 |
15 #include <cstdlib> | |
16 | |
17 #include "google_update_idl.h" | 15 #include "google_update_idl.h" |
18 | 16 |
19 namespace { | 17 namespace { |
20 | 18 |
21 const wchar_t kChromeRegClientsKey[] = | 19 const wchar_t kChromeRegClientsKey[] = |
22 L"Software\\Google\\Update\\Clients\\" | 20 L"Software\\Google\\Update\\Clients\\" |
23 L"{8A69D345-D564-463c-AFF1-A69D9E530F96}"; | 21 L"{8A69D345-D564-463c-AFF1-A69D9E530F96}"; |
24 const wchar_t kChromeRegClientStateKey[] = | 22 const wchar_t kChromeRegClientStateKey[] = |
25 L"Software\\Google\\Update\\ClientState\\" | 23 L"Software\\Google\\Update\\ClientState\\" |
26 L"{8A69D345-D564-463c-AFF1-A69D9E530F96}"; | 24 L"{8A69D345-D564-463c-AFF1-A69D9E530F96}"; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 reinterpret_cast<LPDWORD>(size)) == ERROR_SUCCESS)) { | 149 reinterpret_cast<LPDWORD>(size)) == ERROR_SUCCESS)) { |
152 ::RegCloseKey(key); | 150 ::RegCloseKey(key); |
153 return true; | 151 return true; |
154 } | 152 } |
155 return false; | 153 return false; |
156 } | 154 } |
157 | 155 |
158 bool IsChromeInstalled(HKEY root_key) { | 156 bool IsChromeInstalled(HKEY root_key) { |
159 wchar_t version[64]; | 157 wchar_t version[64]; |
160 size_t size = _countof(version); | 158 size_t size = _countof(version); |
161 return ReadValueFromRegistry(root_key, kChromeRegClientsKey, | 159 if (ReadValueFromRegistry(root_key, kChromeRegClientsKey, kChromeRegVersion, |
162 kChromeRegVersion, version, &size); | 160 version, &size)) |
| 161 return true; |
| 162 return false; |
163 } | 163 } |
164 | 164 |
165 enum WindowsVersion { | 165 bool IsWinXPSp2OrLater(bool* is_vista_or_later) { |
166 VERSION_BELOW_XP_SP2, | 166 OSVERSIONINFOEX osviex = { sizeof(OSVERSIONINFOEX) }; |
167 VERSION_XP_SP2_UP_TO_VISTA, // "but not including" | 167 int r = ::GetVersionEx((LPOSVERSIONINFO)&osviex); |
168 VERSION_VISTA_OR_HIGHER, | 168 // If this failed we're on Win9X or a pre NT4SP6 OS. |
169 }; | 169 if (!r) |
170 WindowsVersion GetWindowsVersion() { | 170 return false; |
171 OSVERSIONINFOEX version_info = { sizeof version_info }; | |
172 GetVersionEx(reinterpret_cast<OSVERSIONINFO*>(&version_info)); | |
173 | 171 |
174 // Windows Vista is version 6.0. | 172 if (osviex.dwMajorVersion < 5) |
175 if (version_info.dwMajorVersion >= 6) | 173 return false; |
176 return VERSION_VISTA_OR_HIGHER; | |
177 | 174 |
178 // Windows XP is version 5.1. (5.2 is Windows Server 2003/XP Pro x64.) | 175 if (osviex.dwMajorVersion > 5) { |
179 if ((version_info.dwMajorVersion < 5) || (version_info.dwMinorVersion < 1)) | 176 *is_vista_or_later = true; |
180 return VERSION_BELOW_XP_SP2; | 177 return true; // way beyond Windows XP; |
| 178 } |
181 | 179 |
182 // For XP itself, we only support SP2 and above. | 180 if (osviex.dwMinorVersion >= 1 && osviex.wServicePackMajor >= 2) |
183 return ((version_info.dwMinorVersion > 1) || | 181 return true; // Windows XP SP2 or better. |
184 (version_info.wServicePackMajor >= 2)) ? | 182 |
185 VERSION_XP_SP2_UP_TO_VISTA : VERSION_BELOW_XP_SP2; | 183 return false; // Windows 2000, WinXP no Service Pack. |
186 } | 184 } |
187 | 185 |
188 // Note this function should not be called on old Windows versions where these | 186 // Note this function should not be called on old Windows versions where these |
189 // Windows API are not available. We always invoke this function after checking | 187 // Windows API are not available. We always invoke this function after checking |
190 // that current OS is Vista or later. | 188 // that current OS is Vista or later. |
191 bool VerifyAdminGroup() { | 189 bool VerifyAdminGroup() { |
192 SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY; | 190 SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY; |
193 PSID Group; | 191 PSID Group; |
194 BOOL check = ::AllocateAndInitializeSid(&NtAuthority, 2, | 192 BOOL check = ::AllocateAndInitializeSid(&NtAuthority, 2, |
195 SECURITY_BUILTIN_DOMAIN_RID, | 193 SECURITY_BUILTIN_DOMAIN_RID, |
(...skipping 29 matching lines...) Expand all Loading... |
225 RegDeleteKey(key, NULL); | 223 RegDeleteKey(key, NULL); |
226 | 224 |
227 RegCloseKey(key); | 225 RegCloseKey(key); |
228 } | 226 } |
229 | 227 |
230 return result; | 228 return result; |
231 } | 229 } |
232 | 230 |
233 bool IsRunningElevated() { | 231 bool IsRunningElevated() { |
234 // This method should be called only for Vista or later. | 232 // This method should be called only for Vista or later. |
235 if ((GetWindowsVersion() < VERSION_VISTA_OR_HIGHER) || | 233 bool is_vista_or_later = false; |
236 !VerifyAdminGroup()) | 234 IsWinXPSp2OrLater(&is_vista_or_later); |
| 235 if (!is_vista_or_later || !VerifyAdminGroup()) |
237 return false; | 236 return false; |
238 | 237 |
239 HANDLE process_token; | 238 HANDLE process_token; |
240 if (!::OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &process_token)) | 239 if (!::OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &process_token)) |
241 return false; | 240 return false; |
242 | 241 |
243 TOKEN_ELEVATION_TYPE elevation_type = TokenElevationTypeDefault; | 242 TOKEN_ELEVATION_TYPE elevation_type = TokenElevationTypeDefault; |
244 DWORD size_returned = 0; | 243 DWORD size_returned = 0; |
245 if (!::GetTokenInformation(process_token, TokenElevationType, | 244 if (!::GetTokenInformation(process_token, TokenElevationType, |
246 &elevation_type, sizeof(elevation_type), | 245 &elevation_type, sizeof(elevation_type), |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 ::CloseHandle(process_handle); | 280 ::CloseHandle(process_handle); |
282 return result; | 281 return result; |
283 } | 282 } |
284 } // namespace | 283 } // namespace |
285 | 284 |
286 #pragma comment(linker, "/EXPORT:GoogleChromeCompatibilityCheck=_GoogleChromeCom
patibilityCheck@8,PRIVATE") | 285 #pragma comment(linker, "/EXPORT:GoogleChromeCompatibilityCheck=_GoogleChromeCom
patibilityCheck@8,PRIVATE") |
287 DLLEXPORT BOOL __stdcall GoogleChromeCompatibilityCheck(BOOL set_flag, | 286 DLLEXPORT BOOL __stdcall GoogleChromeCompatibilityCheck(BOOL set_flag, |
288 DWORD *reasons) { | 287 DWORD *reasons) { |
289 DWORD local_reasons = 0; | 288 DWORD local_reasons = 0; |
290 | 289 |
291 WindowsVersion windows_version = GetWindowsVersion(); | 290 bool is_vista_or_later = false; |
292 // System requirements? | 291 // System requirements? |
293 if (windows_version == VERSION_BELOW_XP_SP2) | 292 if (!IsWinXPSp2OrLater(&is_vista_or_later)) |
294 local_reasons |= GCCC_ERROR_OSNOTSUPPORTED; | 293 local_reasons |= GCCC_ERROR_OSNOTSUPPORTED; |
295 | 294 |
296 if (IsChromeInstalled(HKEY_LOCAL_MACHINE)) | 295 if (IsChromeInstalled(HKEY_LOCAL_MACHINE)) |
297 local_reasons |= GCCC_ERROR_SYSTEMLEVELALREADYPRESENT; | 296 local_reasons |= GCCC_ERROR_SYSTEMLEVELALREADYPRESENT; |
298 | 297 |
299 if (IsChromeInstalled(HKEY_CURRENT_USER)) | 298 if (IsChromeInstalled(HKEY_CURRENT_USER)) |
300 local_reasons |= GCCC_ERROR_USERLEVELALREADYPRESENT; | 299 local_reasons |= GCCC_ERROR_USERLEVELALREADYPRESENT; |
301 | 300 |
302 if (!VerifyHKLMAccess(kChromeRegClientsKey)) { | 301 if (!VerifyHKLMAccess(kChromeRegClientsKey)) { |
303 local_reasons |= GCCC_ERROR_ACCESSDENIED; | 302 local_reasons |= GCCC_ERROR_ACCESSDENIED; |
304 } else if ((windows_version == VERSION_VISTA_OR_HIGHER) && | 303 } else if (is_vista_or_later && !VerifyAdminGroup()) { |
305 !VerifyAdminGroup()) { | |
306 // For Vista or later check for elevation since even for admin user we could | 304 // For Vista or later check for elevation since even for admin user we could |
307 // be running in non-elevated mode. We require integrity level High. | 305 // be running in non-elevated mode. We require integrity level High. |
308 local_reasons |= GCCC_ERROR_INTEGRITYLEVEL; | 306 local_reasons |= GCCC_ERROR_INTEGRITYLEVEL; |
309 } | 307 } |
310 | 308 |
311 // Then only check whether we can re-offer, if everything else is OK. | 309 // Then only check whether we can re-offer, if everything else is OK. |
312 if (local_reasons == 0 && !CanReOfferChrome(set_flag)) | 310 if (local_reasons == 0 && !CanReOfferChrome(set_flag)) |
313 local_reasons |= GCCC_ERROR_ALREADYOFFERED; | 311 local_reasons |= GCCC_ERROR_ALREADYOFFERED; |
314 | 312 |
315 // Done. Copy/return results. | 313 // Done. Copy/return results. |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 // This loop iterates through all of the top-level Windows named | 442 // This loop iterates through all of the top-level Windows named |
445 // Chrome_WindowImpl_0, and looks for the first one with any children. | 443 // Chrome_WindowImpl_0, and looks for the first one with any children. |
446 while (handle && !FindWindowEx(handle, NULL, L"Chrome_WindowImpl_0", NULL)) { | 444 while (handle && !FindWindowEx(handle, NULL, L"Chrome_WindowImpl_0", NULL)) { |
447 // Get the next top-level Chrome window. | 445 // Get the next top-level Chrome window. |
448 handle = FindWindowEx(NULL, handle, L"Chrome_WindowImpl_0", NULL); | 446 handle = FindWindowEx(NULL, handle, L"Chrome_WindowImpl_0", NULL); |
449 } | 447 } |
450 | 448 |
451 return (handle && | 449 return (handle && |
452 SetWindowPos(handle, 0, x, y, width, height, SWP_NOZORDER)); | 450 SetWindowPos(handle, 0, x, y, width, height, SWP_NOZORDER)); |
453 } | 451 } |
OLD | NEW |