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 #include "chrome_frame/chrome_launcher.h" | 5 #include "chrome_frame/chrome_launcher.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <shellapi.h> | 8 #include <shellapi.h> |
9 #include <shlwapi.h> | 9 #include <shlwapi.h> |
10 | 10 |
| 11 #include "policy/policy_constants.h" |
| 12 |
11 // Herein lies stuff selectively stolen from Chrome. We don't pull it in | 13 // Herein lies stuff selectively stolen from Chrome. We don't pull it in |
12 // directly because all of it results in many things we don't want being | 14 // directly because all of it results in many things we don't want being |
13 // included as well. | 15 // included as well. |
14 namespace { | 16 namespace { |
15 | 17 |
16 // These are the switches we will allow (along with their values) in the | 18 // These are the switches we will allow (along with their values) in the |
17 // safe-for-Low-Integrity version of the Chrome command line. | 19 // safe-for-Low-Integrity version of the Chrome command line. |
18 // Including the chrome switch files pulls in a bunch of dependencies sadly, so | 20 // Including the chrome switch files pulls in a bunch of dependencies sadly, so |
19 // we redefine things here: | 21 // we redefine things here: |
20 const wchar_t* kAllowedSwitches[] = { | 22 const wchar_t* kAllowedSwitches[] = { |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 std::wstring trimmed_arg = TrimWhiteSpace(args[i]); | 135 std::wstring trimmed_arg = TrimWhiteSpace(args[i]); |
134 if (!IsValidArgument(trimmed_arg.c_str())) { | 136 if (!IsValidArgument(trimmed_arg.c_str())) { |
135 success = false; | 137 success = false; |
136 break; | 138 break; |
137 } | 139 } |
138 } | 140 } |
139 | 141 |
140 return success; | 142 return success; |
141 } | 143 } |
142 | 144 |
| 145 // Looks up optionally configured launch parameters for Chrome that may have |
| 146 // been set via group policy. |
| 147 void AppendAdditionalLaunchParameters(std::wstring* command_line) { |
| 148 static const HKEY kRootKeys[] = { |
| 149 HKEY_LOCAL_MACHINE, |
| 150 HKEY_CURRENT_USER |
| 151 }; |
| 152 |
| 153 std::wstring launch_params_value_name( |
| 154 &policy::key::kAdditionalLaunchParameters[0], |
| 155 &policy::key::kAdditionalLaunchParameters[ |
| 156 lstrlenA(policy::key::kAdditionalLaunchParameters)]); |
| 157 |
| 158 // Used for basic checks since CreateProcess doesn't support command lines |
| 159 // longer than 0x8000 characters. If we surpass that length, we do not add the |
| 160 // additional parameters. Because we need to add a space before the |
| 161 // extra parameters, we use 0x7fff and not 0x8000. |
| 162 const size_t kMaxChars = 0x7FFF - command_line->size(); |
| 163 HKEY key; |
| 164 LONG result; |
| 165 bool found = false; |
| 166 for (int i = 0; !found && i < arraysize(kRootKeys); ++i) { |
| 167 result = ::RegOpenKeyExW(kRootKeys[i], policy::kRegistryMandatorySubKey, 0, |
| 168 KEY_READ, &key); |
| 169 if (result == ERROR_SUCCESS) { |
| 170 DWORD size = 0; |
| 171 DWORD type = 0; |
| 172 result = RegQueryValueExW(key, launch_params_value_name.c_str(), |
| 173 0, &type, NULL, &size); |
| 174 if (result == ERROR_SUCCESS && type == REG_SZ && size > 0 && |
| 175 (size / sizeof(wchar_t)) < kMaxChars) { |
| 176 // This size includes any terminating null character or characters |
| 177 // unless the data was stored without them, so for safety we allocate |
| 178 // one extra char and zero out the buffer. |
| 179 wchar_t* value = new wchar_t[(size / sizeof(wchar_t)) + 1]; |
| 180 memset(value, 0, size + sizeof(wchar_t)); |
| 181 result = RegQueryValueExW(key, launch_params_value_name.c_str(), 0, |
| 182 &type, reinterpret_cast<BYTE*>(&value[0]), |
| 183 &size); |
| 184 if (result == ERROR_SUCCESS) { |
| 185 *command_line += L' '; |
| 186 *command_line += value; |
| 187 found = true; |
| 188 } |
| 189 delete [] value; |
| 190 } |
| 191 ::RegCloseKey(key); |
| 192 } |
| 193 } |
| 194 } |
| 195 |
143 bool SanitizeAndLaunchChrome(const wchar_t* command_line) { | 196 bool SanitizeAndLaunchChrome(const wchar_t* command_line) { |
144 bool success = false; | 197 bool success = false; |
145 if (IsValidCommandLine(command_line)) { | 198 if (IsValidCommandLine(command_line)) { |
146 std::wstring chrome_path; | 199 std::wstring chrome_path; |
147 if (GetChromeExecutablePath(&chrome_path)) { | 200 if (GetChromeExecutablePath(&chrome_path)) { |
148 const wchar_t* args = PathGetArgs(command_line); | 201 const wchar_t* args = PathGetArgs(command_line); |
149 | 202 |
150 // Build the command line string with the quoted path to chrome.exe. | 203 // Build the command line string with the quoted path to chrome.exe. |
151 std::wstring command_line; | 204 std::wstring command_line; |
152 command_line.reserve(chrome_path.size() + 2); | 205 command_line.reserve(chrome_path.size() + 2); |
153 command_line.append(1, L'\"').append(chrome_path).append(1, L'\"'); | 206 command_line.append(1, L'\"').append(chrome_path).append(1, L'\"'); |
154 | 207 |
155 if (args != NULL) { | 208 if (args != NULL) { |
156 command_line += L' '; | 209 command_line += L' '; |
157 command_line += args; | 210 command_line += args; |
158 } | 211 } |
159 | 212 |
| 213 // Append parameters that might be set by group policy. |
| 214 AppendAdditionalLaunchParameters(&command_line); |
| 215 |
160 STARTUPINFO startup_info = {0}; | 216 STARTUPINFO startup_info = {0}; |
161 startup_info.cb = sizeof(startup_info); | 217 startup_info.cb = sizeof(startup_info); |
162 startup_info.dwFlags = STARTF_USESHOWWINDOW; | 218 startup_info.dwFlags = STARTF_USESHOWWINDOW; |
163 startup_info.wShowWindow = SW_SHOW; | 219 startup_info.wShowWindow = SW_SHOW; |
164 PROCESS_INFORMATION process_info = {0}; | 220 PROCESS_INFORMATION process_info = {0}; |
165 if (CreateProcess(&chrome_path[0], &command_line[0], | 221 if (CreateProcess(&chrome_path[0], &command_line[0], |
166 NULL, NULL, FALSE, 0, NULL, NULL, | 222 NULL, NULL, FALSE, 0, NULL, NULL, |
167 &startup_info, &process_info)) { | 223 &startup_info, &process_info)) { |
168 // Close handles. | 224 // Close handles. |
169 CloseHandle(process_info.hThread); | 225 CloseHandle(process_info.hThread); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 if (PathFileExists(cur_path)) { | 259 if (PathFileExists(cur_path)) { |
204 *chrome_path = cur_path; | 260 *chrome_path = cur_path; |
205 success = true; | 261 success = true; |
206 } | 262 } |
207 } | 263 } |
208 | 264 |
209 return success; | 265 return success; |
210 } | 266 } |
211 | 267 |
212 } // namespace chrome_launcher | 268 } // namespace chrome_launcher |
OLD | NEW |