OLD | NEW |
| (Empty) |
1 // Copyright 2007-2010 Google Inc. | |
2 // | |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 // you may not use this file except in compliance with the License. | |
5 // You may obtain a copy of the License at | |
6 // | |
7 // http://www.apache.org/licenses/LICENSE-2.0 | |
8 // | |
9 // Unless required by applicable law or agreed to in writing, software | |
10 // distributed under the License is distributed on an "AS IS" BASIS, | |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 // See the License for the specific language governing permissions and | |
13 // limitations under the License. | |
14 // ======================================================================== | |
15 | |
16 #ifndef OMAHA_COMMON_GOOPDATE_UTILS_H_ | |
17 #define OMAHA_COMMON_GOOPDATE_UTILS_H_ | |
18 | |
19 #include <windows.h> | |
20 #include <atlpath.h> | |
21 #include <atlstr.h> | |
22 #include <map> | |
23 #include <vector> | |
24 // TODO(omaha3): Move all browser related functions into browser_utils or some | |
25 // similar file so we can avoid including browser_utils.h in this header. This | |
26 // is especially important because of the duplicate BrowserType definition. | |
27 #include "omaha/base/browser_utils.h" | |
28 | |
29 namespace omaha { | |
30 | |
31 class NetworkRequest; | |
32 class UpdateResponse; | |
33 struct NamedObjectAttributes; | |
34 | |
35 // Represents the Result of an attempt to terminate the browser. | |
36 struct TerminateBrowserResult { | |
37 TerminateBrowserResult() | |
38 : found(false), | |
39 could_terminate(false) { | |
40 } | |
41 | |
42 TerminateBrowserResult(bool f, bool terminate) | |
43 : found(f), | |
44 could_terminate(terminate) { | |
45 } | |
46 | |
47 bool found; | |
48 bool could_terminate; | |
49 }; | |
50 | |
51 namespace goopdate_utils { | |
52 | |
53 typedef HRESULT (*RegisterOrUnregisterFunction)(void* data, bool is_register); | |
54 | |
55 // Builds the directory of the Google Update executable. | |
56 CString BuildGoogleUpdateExeDir(bool is_machine); | |
57 | |
58 // Builds the path of the Google Update version found in the registry. The | |
59 // command line is of the form "<install location>\googleupdate.exe" | |
60 CString BuildGoogleUpdateExePath(bool is_machine); | |
61 | |
62 CString BuildGoogleUpdateServicesPath(bool is_machine); | |
63 | |
64 // Returns true if the currently executing binary is running from the | |
65 // Machine/User Goopdate directory, or a directory under it. | |
66 bool IsRunningFromOfficialGoopdateDir(bool is_machine); | |
67 | |
68 // If running the installed machine instance, returns HKLM. Else returns HKCU. | |
69 CString GetHKRoot(); | |
70 | |
71 // Starts an instance of the Google Update version found in the registry. | |
72 // Only use to start interactive processes because it uses ::ShellExecuteEx(). | |
73 // args can be NULL. | |
74 // process can be NULL. If not NULL, caller is responsible for closing handle. | |
75 HRESULT StartGoogleUpdateWithArgs(bool is_machine, | |
76 const TCHAR* args, | |
77 HANDLE* process); | |
78 | |
79 // Starts an instance of GoogleCrashHandler.exe. | |
80 HRESULT StartCrashHandler(bool is_machine); | |
81 | |
82 // Starts self in an elevated mode using the "Runas" verb. | |
83 HRESULT StartElevatedSelfWithArgsAndWait(const TCHAR* args, DWORD* exit_code); | |
84 | |
85 // Registers security and sets the security values for the GoogleUpdate | |
86 // process when running as a COM server. | |
87 HRESULT InitializeSecurity(); | |
88 | |
89 // GetProductName is temporary and must be removed after the TT release. | |
90 // Gets the product name for a app guid. | |
91 CString GetProductName(const CString& app_guid); | |
92 | |
93 // Returns true if it is a development or test machine. | |
94 bool IsTestSource(); | |
95 | |
96 HRESULT RedirectHKCR(bool is_machine); | |
97 | |
98 HRESULT RemoveRedirectHKCR(); | |
99 | |
100 HRESULT RegisterTypeLib(bool is_admin, | |
101 const CComBSTR& path, | |
102 ITypeLib* type_lib); | |
103 HRESULT UnRegisterTypeLib(bool is_admin, | |
104 const CComBSTR&, | |
105 ITypeLib* type_lib); | |
106 | |
107 HRESULT RegisterOrUnregisterModule(bool is_machine, | |
108 bool register_server, | |
109 RegisterOrUnregisterFunction registrar, | |
110 void* data); | |
111 | |
112 HRESULT RegisterOrUnregisterModuleWithTypelib( | |
113 bool is_machine, | |
114 bool register_server, | |
115 RegisterOrUnregisterFunction registrar, | |
116 void* data); | |
117 | |
118 // Registers the typelib that is passed in. | |
119 // Wrapper for the RegisterTypeLibForUser that is defined in the | |
120 // Vista oleaut32. Uses GetProcAddress to call into the method. | |
121 HRESULT RegisterTypeLibForUser(ITypeLib* lib, | |
122 OLECHAR* path, | |
123 OLECHAR* help_dir); | |
124 | |
125 // Unregisters the typelib that is passed in. | |
126 // Wrapper for the UnRegisterTypeLibForUser in Vista ole. Uses GetProcAddress | |
127 // to call into the real method. | |
128 HRESULT UnRegisterTypeLibForUser(REFGUID lib_id, | |
129 WORD major_ver_num, | |
130 WORD minor_ver_num, | |
131 LCID lcid, | |
132 SYSKIND syskind); | |
133 | |
134 CString GetCurrentVersionedName(bool is_machine, | |
135 const TCHAR* value_name, | |
136 const TCHAR* default_val); | |
137 | |
138 HRESULT CreateAndSetVersionedNameInRegistry(bool is_machine, | |
139 const TCHAR* prefix, | |
140 const TCHAR* value_name); | |
141 | |
142 // Returns the absolute path of the browser image. | |
143 HRESULT GetBrowserImagePathFromProcess(BrowserType type, | |
144 uint32 explorer_pid, | |
145 CString* path); | |
146 | |
147 // Terminates all browser processes for the current user. | |
148 HRESULT TerminateBrowserProcesses(BrowserType type, | |
149 TerminateBrowserResult* browser_res, | |
150 TerminateBrowserResult* default_res); | |
151 | |
152 // Terminates instances of all known browsers. Currently, the known browsers are | |
153 // Firefox, IE and Chrome. | |
154 HRESULT TerminateAllBrowsers(BrowserType type, | |
155 TerminateBrowserResult* browser_res, | |
156 TerminateBrowserResult* default_res); | |
157 | |
158 | |
159 // Converts from string to the BrowserType enum. | |
160 HRESULT ConvertStringToBrowserType(const CString& text, BrowserType* type); | |
161 | |
162 // Converts from BrowserType to string. | |
163 CString ConvertBrowserTypeToString(BrowserType type); | |
164 | |
165 // Returns the browser to restart. | |
166 bool GetBrowserToRestart(BrowserType type, | |
167 BrowserType default_type, | |
168 const TerminateBrowserResult& res, | |
169 const TerminateBrowserResult& def_res, | |
170 BrowserType* browser_type); | |
171 | |
172 // Obtains the OS version and service pack. | |
173 HRESULT GetOSInfo(CString* os_version, CString* service_pack); | |
174 | |
175 // Returns the install directory for the specified version. | |
176 CPath BuildInstallDirectory(bool is_machine, const CString& version); | |
177 | |
178 // Launches the command line. On Vista and later, for a machine install, this | |
179 // method will launch the process at medium/low integrity, by impersonating the | |
180 // medium integrity token of the active user. | |
181 HRESULT LaunchCmdLine(bool is_machine, const CString& cmd_line); | |
182 | |
183 // Launches the browser. On Vista and later, for a machine install, this method | |
184 // will launch the browser at medium/low integrity, by impersonating the medium | |
185 // integrity token of the active user. | |
186 HRESULT LaunchBrowser(bool is_machine, BrowserType type, const CString& url); | |
187 | |
188 // Gets a list of install worker processes relevant to user/machine instances. | |
189 HRESULT GetInstallWorkerProcesses(bool is_machine, | |
190 std::vector<uint32>* processes); | |
191 | |
192 // Creates a unique event name and stores it in the specified environment var. | |
193 HRESULT CreateUniqueEventInEnvironment(const CString& var_name, | |
194 bool is_machine, | |
195 HANDLE* unique_event); | |
196 | |
197 // Obtains a unique event name from specified environment var and opens it. | |
198 HRESULT OpenUniqueEventFromEnvironment(const CString& var_name, | |
199 bool is_machine, | |
200 HANDLE* unique_event); | |
201 | |
202 // Creates an event based on the provided attributes. | |
203 HRESULT CreateEvent(NamedObjectAttributes* event_attr, HANDLE* event_handle); | |
204 | |
205 HRESULT ReadNameValuePairsFromFile(const CString& file_path, | |
206 const CString& group_name, | |
207 std::map<CString, CString>* pairs); | |
208 | |
209 HRESULT WriteNameValuePairsToFile(const CString& file_path, | |
210 const CString& group_name, | |
211 const std::map<CString, CString>& pairs); | |
212 | |
213 // Returns true is any of the install workers is running. | |
214 bool IsAppInstallWorkerRunning(bool is_machine); | |
215 | |
216 // Returns whether the version is an "Omaha 2" version or later. | |
217 bool IsGoogleUpdate2OrLater(const CString& version); | |
218 | |
219 // Converts the installer_data value to UTF8. Then writes this UTF8 data | |
220 // prefixed with the UTF8 BOM of EF BB BF to a temp file. Returns the path to | |
221 // temp file that was created. The returned path will be quote-enclosed by | |
222 // EnclosePath(). | |
223 HRESULT WriteInstallerDataToTempFile(const CString& installer_data, | |
224 CString* installer_data_file_path); | |
225 | |
226 // TODO(omaha): Move these two to ua_internal.h. | |
227 // Returns true if a server update check is due. | |
228 bool ShouldCheckForUpdates(bool is_machine); | |
229 | |
230 // Updates LastChecked to now. Call after successful update check for all apps. | |
231 HRESULT UpdateLastChecked(bool is_machine); | |
232 | |
233 // Launches the /uninstall process. | |
234 HRESULT LaunchUninstallProcess(bool is_machine); | |
235 | |
236 // Returns a token that can be used to impersonate in the case of a | |
237 // machine process. The caller has ownership of the token that is returned and | |
238 // it must close the handle. The token corresponds to the primary token for | |
239 // the current or one of the logged on users but only if the caller is a | |
240 // machine process running as local system and not impersonated. | |
241 // This is a very specialized function,intended to be called by local system | |
242 // processes making network calls where the caller is not impersonated. | |
243 HANDLE GetImpersonationTokenForMachineProcess(bool is_machine); | |
244 | |
245 // Enables or disables Structured Exception Handler Overwrite Protection a.k.a | |
246 // SEHOP for machine Omaha. More information on SEHOP: http://goo.gl/1hfD. | |
247 HRESULT EnableSEHOP(bool enable); | |
248 | |
249 // Creates a user unique id and saves it in registry if the machine is not in | |
250 // the OEM install mode. | |
251 HRESULT CreateUserId(bool is_machine); | |
252 | |
253 // Deletes the user id from registry. | |
254 void DeleteUserId(bool is_machine); | |
255 | |
256 // Lazy creates (if necessary) and returns the user ID in registry if the | |
257 // machine is NOT in OEM install state and current user opts in usage stats. | |
258 // Otherwise deletes the user ID from the registry and returns empty string. | |
259 CString GetUserIdLazyInit(bool is_machine); | |
260 | |
261 } // namespace goopdate_utils | |
262 | |
263 } // namespace omaha | |
264 | |
265 #endif // OMAHA_COMMON_GOOPDATE_UTILS_H_ | |
OLD | NEW |