Skip to content

Commit 72f9bdd

Browse files
committed
Use GoogleUpdate.exe itself when elevating machine handoff installs
This CL stops copying the `metainstaller` to the versioned install directory, and instead uses `GoogleUpdate.exe` within the same secure `%programfiles%` directory for elevating a machine install. The `metainstaller` was previously needed for cross-install scenarios, i.e., a user installation `/handoff` doing a machine install, where elevating the entire `metainstaller` was safer. However, that scenario was only used by the ActiveX/plugin code, and is no longer in use.
1 parent 528e672 commit 72f9bdd

File tree

6 files changed

+21
-58
lines changed

6 files changed

+21
-58
lines changed

omaha/client/install.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,11 @@ HRESULT ElevateAndWait(const CString& cmd_line, DWORD* exit_code) {
247247
SafeCStringAppendFormat(&cmd_line_elevated, _T(" /%s"),
248248
kCmdLineInstallElevated);
249249

250-
HRESULT hr = goopdate_utils::StartElevatedMetainstaller(cmd_line_elevated,
251-
exit_code);
250+
HRESULT hr = goopdate_utils::StartElevatedSelfWithArgsAndWait(
251+
cmd_line_elevated, exit_code);
252252
if (FAILED(hr)) {
253-
OPT_LOG(LE, (_T("[Elevated metainstaller failed][%s][%#x]"), cmd_line, hr));
253+
OPT_LOG(LE,
254+
(_T("[Elevated GoogleUpdate.exe failed][%s][%#x]"), cmd_line, hr));
254255

255256
// TODO(omaha3): Report hr somehow. Was reported in extra code in Omaha 2.
256257
if (vista_util::IsUserNonElevatedAdmin()) {

omaha/common/goopdate_utils.cc

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -308,39 +308,29 @@ CString BuildGoogleUpdateServicesEnclosedPath(bool is_machine, bool use64bit) {
308308
return path;
309309
}
310310

311-
HRESULT StartElevatedMetainstaller(const TCHAR* args, DWORD* exit_code) {
311+
HRESULT StartElevatedSelfWithArgsAndWait(const TCHAR* args, DWORD* exit_code) {
312312
ASSERT1(args);
313313
ASSERT1(exit_code);
314-
CORE_LOG(L3, (_T("[StartElevatedMetainstaller]")));
315314

316-
CPath metainstaller_path(app_util::GetCurrentModuleDirectory());
317-
VERIFY1(metainstaller_path.Append(kOmahaMetainstallerFileName));
318-
if (!File::Exists(metainstaller_path)) {
319-
return GOOPDATE_E_METAINSTALLER_NOT_FOUND;
320-
}
315+
CORE_LOG(L3, (_T("[StartElevatedSelfWithArgsAndWait]")));
321316

322-
// In case the metainstaller has been tagged, append the /no_mi_tag switch
323-
// to the end of the command line to signal the MI to not append its tag.
324-
// The MI will remove the switch before launching the constant shell.
325-
// TODO(omaha): Once the ApplyTag library has been refactored to allow
326-
// removal/truncation of tags, remove the tag as part of setup (so that the
327-
// MI in the permanent install is always untagged) and eliminate this switch.
328-
CString new_args;
329-
SafeCStringFormat(&new_args, _T("%s /%s"), args, kCmdLineNoMetainstallerTag);
317+
// Get the process executable.
318+
const CString filename(app_util::GetModulePath(NULL));
330319

331-
// Launch metainstaller elevated and wait.
320+
// Launch self elevated and wait.
332321
*exit_code = 0;
333-
CORE_LOG(L3, (_T("[Elevating][%s][%s]"), metainstaller_path, new_args));
322+
CORE_LOG(L3, (_T("[Elevating][%s][%s]"), filename, args));
334323

335324
// According to the MSDN documentation for ::ShowWindow: "nCmdShow. This
336325
// parameter is ignored the first time an application calls ShowWindow, if
337326
// the program that launched the application provides a STARTUPINFO
338327
// structure.". We want to force showing the UI window. So we pass in
339328
// SW_SHOWNORMAL.
340-
HRESULT hr = vista_util::RunElevated(metainstaller_path,
341-
new_args,
342-
SW_SHOWNORMAL,
343-
exit_code);
329+
HRESULT hr =
330+
vista_util::RunElevated(filename,
331+
args,
332+
SW_SHOWNORMAL,
333+
exit_code);
344334
CORE_LOG(L3, (_T("[elevated instance exit code][%u]"), *exit_code));
345335

346336
if (FAILED(hr)) {

omaha/common/goopdate_utils.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,8 @@ HRESULT StartGoogleUpdateWithArgs(bool is_machine,
100100
// if we're running on a 64-bit OS.
101101
HRESULT StartCrashHandler(bool is_machine);
102102

103-
// Starts the metainstaller in the same directory as the current module in an
104-
// elevated mode using the "Runas" verb.
105-
HRESULT StartElevatedMetainstaller(const TCHAR* args, DWORD* exit_code);
103+
// Runs the current executable in an elevated mode using the "Runas" verb.
104+
HRESULT StartElevatedSelfWithArgsAndWait(const TCHAR* args, DWORD* exit_code);
106105

107106
// Registers security and sets the security values for the GoogleUpdate
108107
// process when running as a COM server.

omaha/setup/setup_files.cc

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -110,21 +110,6 @@ HRESULT SetupFiles::Install() {
110110
return hr;
111111
}
112112

113-
// Copy the metainstaller. Since the metainstaller is tagged, its file size
114-
// may vary; so, we always overwrite, even if it's the same version.
115-
// TODO(omaha): Once we refactor our tag management functions to be capable
116-
// of stripping the tag from a MI, change this so that we always copy over
117-
// an untagged metainstaller instead. Untagged metainstallers should always
118-
// be the same size.
119-
hr = CopyInstallFiles(metainstaller_files_, install_dir, true);
120-
if (FAILED(hr)) {
121-
OPT_LOG(LEVEL_ERROR, (_T("[Failed to copy metainstaller][0x%08x]"), hr));
122-
if (E_ACCESSDENIED == hr) {
123-
return GOOPDATE_E_ACCESSDENIED_COPYING_MI;
124-
}
125-
return hr;
126-
}
127-
128113
// Attempt to copy the optional files.
129114
hr = CopyInstallFiles(optional_files_, install_dir, should_over_install);
130115
if (FAILED(hr)) {
@@ -294,11 +279,9 @@ HRESULT SetupFiles::SaveShellForRollback(const CString& shell_install_path) {
294279
}
295280

296281
// The list of files below needs to be kept in sync with payload_files in
297-
// omaha_version_utils.py. The one exception is kOmahaMetainstallerFileName,
298-
// which is not part of the payload.
282+
// omaha_version_utils.py.
299283
HRESULT SetupFiles::BuildFileLists() {
300284
ASSERT1(core_program_files_.empty());
301-
ASSERT1(metainstaller_files_.empty());
302285
ASSERT1(optional_files_.empty());
303286

304287
core_program_files_.clear();
@@ -318,9 +301,6 @@ HRESULT SetupFiles::BuildFileLists() {
318301
core_program_files_.push_back(kPSFileNameMachine);
319302
core_program_files_.push_back(kPSFileNameMachine64);
320303

321-
metainstaller_files_.clear();
322-
metainstaller_files_.push_back(kOmahaMetainstallerFileName);
323-
324304
// If files are removed from this list, unit tests such as
325305
// ShouldInstall_SameVersionOptionalFileMissing may need to be updated.
326306
optional_files_.clear();

omaha/setup/setup_files.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ class SetupFiles {
8181
const bool is_machine_;
8282
CString saved_shell_path_; // Path of the previous shell saved for roll back.
8383
std::vector<CString> core_program_files_;
84-
std::vector<CString> metainstaller_files_;
8584
std::vector<CString> optional_files_;
8685

8786
int extra_code1_;

omaha/setup/setup_files_unittest.cc

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,14 @@ namespace {
3737
// Eventually use the original values in the if block.
3838
const int kNumberOfLanguageDlls = 55;
3939
const int kNumberOfCoreFiles = 10;
40-
const int kNumberOfMetainstallerFiles = 1;
4140
const int kNumberOfOptionalFiles = 2;
4241
const int kNumberOfInstalledRequiredFiles =
4342
kNumberOfLanguageDlls + kNumberOfCoreFiles;
4443
// FindFiles returns "." and ".." in addition to the actual files.
4544
const int kExtraFilesReturnedByFindFiles = 2;
46-
const int kExpectedFilesReturnedByFindFiles =
47-
kNumberOfInstalledRequiredFiles + kNumberOfMetainstallerFiles +
48-
kNumberOfOptionalFiles + kExtraFilesReturnedByFindFiles;
45+
const int kExpectedFilesReturnedByFindFiles = kNumberOfInstalledRequiredFiles +
46+
kNumberOfOptionalFiles +
47+
kExtraFilesReturnedByFindFiles;
4948

5049
const TCHAR kFutureVersionString[] = _T("9.8.7.6");
5150
const ULONGLONG kFutureVersion = 0x0009000800070006;
@@ -70,7 +69,6 @@ void CopyGoopdateFiles(const CString& omaha_path, const CString& version) {
7069
kOmahaShellFileName,
7170
kOmahaCOMRegisterShell64,
7271
kOmahaDllName,
73-
kOmahaMetainstallerFileName,
7472
kOmahaBrokerFileName,
7573
kOmahaOnDemandFileName,
7674
kPSFileNameMachine,
@@ -157,8 +155,6 @@ class SetupFilesTest : public testing::Test {
157155

158156
ASSERT_EQ(kNumberOfInstalledRequiredFiles,
159157
setup_files_->core_program_files_.size());
160-
ASSERT_EQ(kNumberOfMetainstallerFiles,
161-
setup_files_->metainstaller_files_.size());
162158
ASSERT_EQ(kNumberOfOptionalFiles, setup_files_->optional_files_.size());
163159

164160
DeleteDirectory(version_path);
@@ -198,8 +194,6 @@ class SetupFilesTest : public testing::Test {
198194
extra_files.find(kOmahaCoreFileName), extra_files.end());
199195
EXPECT_NE(
200196
extra_files.find(kOmahaOnDemandFileName), extra_files.end());
201-
EXPECT_NE(
202-
extra_files.find(kOmahaMetainstallerFileName), extra_files.end());
203197
EXPECT_NE(
204198
extra_files.find(kOmahaDllName), extra_files.end());
205199
EXPECT_NE(

0 commit comments

Comments
 (0)