OLD | NEW |
| (Empty) |
1 // Copyright 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 // Defines the Google Update 3 web broker. It defines a narrow set of interfaces | |
17 // to reduce the attack surface from low and medium integrity processes. | |
18 // The web broker used to be a COM elevation point as well, but that | |
19 // functionality has moved into the broker class factory. Note that since | |
20 // Update3Web is a COM service now, ::CoSetProxyBlanket must be called on any | |
21 // interfaces that need to impersonate. | |
22 | |
23 #ifndef OMAHA_GOOPDATE_UPDATE3WEB_H_ | |
24 #define OMAHA_GOOPDATE_UPDATE3WEB_H_ | |
25 | |
26 #include <windows.h> | |
27 #include <atlbase.h> | |
28 #include <atlcom.h> | |
29 #include "base/basictypes.h" | |
30 #include "goopdate/omaha3_idl.h" | |
31 #include "omaha/base/atlregmapex.h" | |
32 #include "omaha/base/constants.h" | |
33 #include "omaha/base/preprocessor_fun.h" | |
34 #include "omaha/common/const_goopdate.h" | |
35 #include "omaha/goopdate/com_proxy.h" | |
36 #include "omaha/goopdate/non_localized_resource.h" | |
37 | |
38 namespace omaha { | |
39 | |
40 #pragma warning(push) | |
41 // Construction of local static object is not thread-safe | |
42 #pragma warning(disable:4640) | |
43 | |
44 class ATL_NO_VTABLE Update3WebBase | |
45 : public CComObjectRootEx<CComObjectThreadModel>, | |
46 public IDispatchImpl<IGoogleUpdate3Web, | |
47 &__uuidof(IGoogleUpdate3Web), | |
48 &CAtlModule::m_libid, | |
49 kMajorTypeLibVersion, | |
50 kMinorTypeLibVersion>, | |
51 public IGoogleUpdate3WebSecurity, | |
52 public StdMarshalInfo { | |
53 public: | |
54 explicit Update3WebBase(bool is_machine) : StdMarshalInfo(is_machine), | |
55 is_machine_(is_machine) {} | |
56 | |
57 BEGIN_COM_MAP(Update3WebBase) | |
58 COM_INTERFACE_ENTRY(IDispatch) | |
59 COM_INTERFACE_ENTRY(IGoogleUpdate3Web) | |
60 COM_INTERFACE_ENTRY(IGoogleUpdate3WebSecurity) | |
61 COM_INTERFACE_ENTRY(IStdMarshalInfo) | |
62 END_COM_MAP() | |
63 | |
64 HRESULT FinalConstruct(); | |
65 | |
66 // IGoogleUpdate3Web | |
67 STDMETHOD(createAppBundleWeb)(IDispatch** app_bundle_web); | |
68 | |
69 // IGoogleUpdate3WebSecurity | |
70 STDMETHOD(setOriginURL)(BSTR origin_url); | |
71 | |
72 IGoogleUpdate3* omaha_server() const { return omaha_server_.p; } | |
73 HANDLE impersonation_token() const { | |
74 return impersonation_token_.GetHandle(); | |
75 } | |
76 HANDLE primary_token() const { return primary_token_.GetHandle(); } | |
77 bool is_machine_install() const { return is_machine_; } | |
78 CString origin_url() const { return origin_url_; } | |
79 | |
80 protected: | |
81 virtual ~Update3WebBase() {} | |
82 | |
83 private: | |
84 CComPtr<IGoogleUpdate3> omaha_server_; | |
85 CAccessToken impersonation_token_; | |
86 CAccessToken primary_token_; | |
87 bool is_machine_; | |
88 CString origin_url_; | |
89 | |
90 DISALLOW_COPY_AND_ASSIGN(Update3WebBase); | |
91 }; | |
92 | |
93 template <typename T> | |
94 class ATL_NO_VTABLE Update3Web | |
95 : public Update3WebBase, | |
96 public CComCoClass<Update3Web<T> > { | |
97 public: | |
98 Update3Web() : Update3WebBase(T::is_machine()) {} | |
99 | |
100 DECLARE_NOT_AGGREGATABLE(Update3Web); | |
101 DECLARE_REGISTRY_RESOURCEID_EX(T::registry_res_id()) | |
102 | |
103 BEGIN_REGISTRY_MAP() | |
104 REGMAP_ENTRY(_T("HKROOT"), T::hk_root()) | |
105 REGMAP_ENTRY(_T("VERSION"), _T("1.0")) | |
106 REGMAP_ENTRY(_T("PROGID"), T::prog_id()) | |
107 REGMAP_ENTRY(_T("DESCRIPTION"), _T("GoogleUpdate Update3Web")) | |
108 REGMAP_ENTRY(_T("CLSID"), T::class_id()) | |
109 REGMAP_MODULE2(_T("MODULE"), kOmahaOnDemandFileName) | |
110 REGMAP_ENTRY(_T("ICONRESID"), PP_STRINGIZE(IDI_ELEVATION_MONIKER_ICON)) | |
111 REGMAP_ENTRY(_T("STRINGRESID"), | |
112 PP_STRINGIZE(IDS_ELEVATION_MONIKER_DISPLAYNAME)) | |
113 END_REGISTRY_MAP() | |
114 | |
115 protected: | |
116 virtual ~Update3Web() {} | |
117 | |
118 private: | |
119 DISALLOW_COPY_AND_ASSIGN(Update3Web); | |
120 }; | |
121 | |
122 struct Update3WebModeUser { | |
123 static bool is_machine() { return false; } | |
124 static const TCHAR* const prog_id() { return kProgIDUpdate3WebUser; } | |
125 static GUID class_id() { return __uuidof(GoogleUpdate3WebUserClass); } | |
126 static UINT registry_res_id() { return IDR_LOCAL_SERVER_RGS; } | |
127 static const TCHAR* const hk_root() { return _T("HKCU"); } | |
128 }; | |
129 | |
130 struct Update3WebModeMachineFallback { | |
131 static bool is_machine() { return true; } | |
132 static const TCHAR* const prog_id() { | |
133 return kProgIDUpdate3WebMachineFallback; | |
134 } | |
135 static GUID class_id() { | |
136 return __uuidof(GoogleUpdate3WebMachineFallbackClass); | |
137 } | |
138 static UINT registry_res_id() { return IDR_LOCAL_SERVER_ELEVATION_RGS; } | |
139 static const TCHAR* const hk_root() { return _T("HKLM"); } | |
140 }; | |
141 | |
142 struct Update3WebModeService { | |
143 static bool is_machine() { return true; } | |
144 static const TCHAR* const prog_id() { return kProgIDUpdate3WebSvc; } | |
145 static GUID class_id() { return __uuidof(GoogleUpdate3WebServiceClass); } | |
146 static UINT registry_res_id() { return IDR_LOCAL_SERVICE_RGS; } | |
147 static const TCHAR* const hk_root() { return _T("HKLM"); } | |
148 }; | |
149 | |
150 typedef Update3Web<Update3WebModeUser> Update3WebUser; | |
151 typedef Update3Web<Update3WebModeMachineFallback> Update3WebMachineFallback; | |
152 typedef Update3Web<Update3WebModeService> Update3WebService; | |
153 | |
154 #pragma warning(pop) | |
155 | |
156 } // namespace omaha | |
157 | |
158 #endif // OMAHA_GOOPDATE_UPDATE3WEB_H_ | |
OLD | NEW |