diff options
author | Rob Mensching <rob@firegiant.com> | 2021-05-04 22:48:12 -0700 |
---|---|---|
committer | Rob Mensching <rob@firegiant.com> | 2021-05-04 22:48:12 -0700 |
commit | 7c8e34de56b3348c5a421cd0cced183e1394c5c7 (patch) | |
tree | c2f17867b49e33e0833eae2e1841a00b009c1a15 /src/ext/Iis/ca/scavdir7.cpp | |
parent | c5c87377d99beefe83a3470aab326d12bdf0f8a4 (diff) | |
download | wix-7c8e34de56b3348c5a421cd0cced183e1394c5c7.tar.gz wix-7c8e34de56b3348c5a421cd0cced183e1394c5c7.tar.bz2 wix-7c8e34de56b3348c5a421cd0cced183e1394c5c7.zip |
Move Iis.wixext into ext
Diffstat (limited to 'src/ext/Iis/ca/scavdir7.cpp')
-rw-r--r-- | src/ext/Iis/ca/scavdir7.cpp | 380 |
1 files changed, 380 insertions, 0 deletions
diff --git a/src/ext/Iis/ca/scavdir7.cpp b/src/ext/Iis/ca/scavdir7.cpp new file mode 100644 index 00000000..3f675357 --- /dev/null +++ b/src/ext/Iis/ca/scavdir7.cpp | |||
@@ -0,0 +1,380 @@ | |||
1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
2 | |||
3 | #include "precomp.h" | ||
4 | |||
5 | // prototypes | ||
6 | static HRESULT AddVirtualDirToList7( | ||
7 | __in SCA_VDIR7** psvdList | ||
8 | ); | ||
9 | |||
10 | |||
11 | HRESULT __stdcall ScaVirtualDirsRead7( | ||
12 | __in SCA_WEB7* pswList, | ||
13 | __in SCA_VDIR7** ppsvdList, | ||
14 | __in SCA_MIMEMAP** ppsmmList, | ||
15 | __in SCA_HTTP_HEADER** ppshhList, | ||
16 | __in SCA_WEB_ERROR** ppsweList, | ||
17 | __in WCA_WRAPQUERY_HANDLE hUserQuery, | ||
18 | __in WCA_WRAPQUERY_HANDLE /*hWebBaseQuery*/, | ||
19 | __in WCA_WRAPQUERY_HANDLE hWebDirPropQuery, | ||
20 | __in WCA_WRAPQUERY_HANDLE hWebAppQuery, | ||
21 | __in WCA_WRAPQUERY_HANDLE hWebAppExtQuery, | ||
22 | __inout LPWSTR *ppwzCustomActionData | ||
23 | ) | ||
24 | { | ||
25 | Assert(ppsvdList); | ||
26 | |||
27 | HRESULT hr = S_OK; | ||
28 | MSIHANDLE hRec; | ||
29 | |||
30 | SCA_VDIR7* pvdir = NULL; | ||
31 | LPWSTR pwzData = NULL; | ||
32 | WCA_WRAPQUERY_HANDLE hWrapQuery = NULL; | ||
33 | |||
34 | hr = WcaBeginUnwrapQuery(&hWrapQuery, ppwzCustomActionData); | ||
35 | ExitOnFailure(hr, "Failed to unwrap query for ScaAppPoolRead"); | ||
36 | |||
37 | if (0 == WcaGetQueryRecords(hWrapQuery)) | ||
38 | { | ||
39 | WcaLog(LOGMSG_VERBOSE, "Skipping ScaVirtualDirsRead() because IIsWebVirtualDir table not present"); | ||
40 | ExitFunction1(hr = S_FALSE); | ||
41 | } | ||
42 | |||
43 | // loop through all the vdirs | ||
44 | while (S_OK == (hr = WcaFetchWrappedRecord(hWrapQuery, &hRec))) | ||
45 | { | ||
46 | // Add this record's information into the list of things to process. | ||
47 | hr = AddVirtualDirToList7(ppsvdList); | ||
48 | ExitOnFailure(hr, "failed to add vdir to vdir list"); | ||
49 | |||
50 | pvdir = *ppsvdList; | ||
51 | |||
52 | // get the darwin information | ||
53 | hr = WcaGetRecordString(hRec, vdqComponent, &pwzData); | ||
54 | ExitOnFailure(hr, "failed to get IIsWebVirtualDir.Component"); | ||
55 | |||
56 | hr = WcaGetRecordInteger(hRec, vdqInstalled, (int *)&pvdir->isInstalled); | ||
57 | ExitOnFailure(hr, "Failed to get Component installed state for virtual dir"); | ||
58 | |||
59 | hr = WcaGetRecordInteger(hRec, vdqAction, (int *)&pvdir->isAction); | ||
60 | ExitOnFailure(hr, "Failed to get Component action state for virtual dir"); | ||
61 | |||
62 | // get vdir properties | ||
63 | hr = ::StringCchCopyW(pvdir->wzComponent, countof(pvdir->wzComponent), pwzData); | ||
64 | ExitOnFailure(hr, "failed to copy vdir component name: %ls", pwzData); | ||
65 | |||
66 | hr = WcaGetRecordString(hRec, vdqWeb, &pwzData); | ||
67 | ExitOnFailure(hr, "Failed to get Web for VirtualDir"); | ||
68 | |||
69 | hr = ScaWebsGetBase7(pswList, pwzData, pvdir->wzWebName , countof(pvdir->wzWebName)); | ||
70 | if (S_FALSE == hr) | ||
71 | { | ||
72 | hr = HRESULT_FROM_WIN32(ERROR_NOT_FOUND); | ||
73 | ExitOnFailure(hr, "Failed to get Web Base for VirtualDir"); | ||
74 | } | ||
75 | if (WcaIsUninstalling(pvdir->isInstalled, pvdir->isAction)) | ||
76 | { | ||
77 | // If we're uninstalling, ignore any failure to find the existing web | ||
78 | hr = S_OK; | ||
79 | } | ||
80 | |||
81 | hr = WcaGetRecordString(hRec, vdqAlias, &pwzData); | ||
82 | ExitOnFailure(hr, "Failed to get Alias for VirtualDir"); | ||
83 | |||
84 | hr = ::StringCchCopyW(pvdir->wzVDirRoot, countof(pvdir->wzVDirRoot), pwzData); | ||
85 | ExitOnFailure(hr, "Failed to set VDirRoot for VirtualDir"); | ||
86 | |||
87 | // get the vdir's directory | ||
88 | hr = WcaGetRecordString(hRec, vdqDirectory, &pwzData); | ||
89 | ExitOnFailure(hr, "Failed to get Directory for VirtualDir"); | ||
90 | |||
91 | // get the web's directory | ||
92 | if (INSTALLSTATE_SOURCE == pvdir->isAction) | ||
93 | { | ||
94 | hr = WcaGetRecordString(hRec, vdqSourcePath, &pwzData); | ||
95 | } | ||
96 | else | ||
97 | { | ||
98 | hr = WcaGetRecordString(hRec, vdqTargetPath, &pwzData); | ||
99 | } | ||
100 | ExitOnFailure(hr, "Failed to get Source/TargetPath for Directory"); | ||
101 | |||
102 | // remove trailing backslash(es) | ||
103 | while (lstrlenW(pwzData) > 0 && pwzData[lstrlenW(pwzData)-1] == L'\\') | ||
104 | { | ||
105 | pwzData[lstrlenW(pwzData)-1] = 0; | ||
106 | } | ||
107 | hr = ::StringCchCopyW(pvdir->wzDirectory, countof(pvdir->wzDirectory), pwzData); | ||
108 | ExitOnFailure(hr, "Failed to copy directory string to vdir object"); | ||
109 | |||
110 | // get the security information for this web | ||
111 | hr = WcaGetRecordString(hRec, vdqProperties, &pwzData); | ||
112 | ExitOnFailure(hr, "Failed to get web directory identifier for VirtualDir"); | ||
113 | if (*pwzData) | ||
114 | { | ||
115 | hr = ScaGetWebDirProperties(pwzData, hUserQuery, hWebDirPropQuery, &pvdir->swp); | ||
116 | ExitOnFailure(hr, "Failed to get web directory for VirtualDir"); | ||
117 | |||
118 | pvdir->fHasProperties = TRUE; | ||
119 | } | ||
120 | |||
121 | // get the application information for this web | ||
122 | hr = WcaGetRecordString(hRec, vdqApplication, &pwzData); | ||
123 | ExitOnFailure(hr, "Failed to get application identifier for VirtualDir"); | ||
124 | if (*pwzData) | ||
125 | { | ||
126 | hr = ScaGetWebApplication(NULL, pwzData, hWebAppQuery, hWebAppExtQuery, &pvdir->swapp); | ||
127 | ExitOnFailure(hr, "Failed to get application for VirtualDir"); | ||
128 | |||
129 | pvdir->fHasApplication = TRUE; | ||
130 | } | ||
131 | |||
132 | hr = WcaGetRecordString(hRec, vdqVDir, &pwzData); | ||
133 | ExitOnFailure(hr, "Failed to get VDir for VirtualDir"); | ||
134 | |||
135 | if (*pwzData && *ppsmmList) | ||
136 | { | ||
137 | hr = ScaGetMimeMap(mmptVDir, pwzData, ppsmmList, &pvdir->psmm); | ||
138 | ExitOnFailure(hr, "Failed to get mimemap for VirtualDir"); | ||
139 | } | ||
140 | |||
141 | if (*pwzData && *ppshhList) | ||
142 | { | ||
143 | hr = ScaGetHttpHeader(hhptVDir, pwzData, ppshhList, &pvdir->pshh); | ||
144 | ExitOnFailure(hr, "Failed to get custom HTTP headers for VirtualDir: %ls", pwzData); | ||
145 | } | ||
146 | |||
147 | if (*pwzData && *ppsweList) | ||
148 | { | ||
149 | hr = ScaGetWebError(weptVDir, pwzData, ppsweList, &pvdir->pswe); | ||
150 | ExitOnFailure(hr, "Failed to get custom web errors for VirtualDir: %ls", pwzData); | ||
151 | } | ||
152 | } | ||
153 | |||
154 | if (E_NOMOREITEMS == hr) | ||
155 | { | ||
156 | hr = S_OK; | ||
157 | } | ||
158 | ExitOnFailure(hr, "Failure while processing VirtualDirs"); | ||
159 | |||
160 | LExit: | ||
161 | WcaFinishUnwrapQuery(hWrapQuery); | ||
162 | |||
163 | ReleaseStr(pwzData); | ||
164 | |||
165 | return hr; | ||
166 | } | ||
167 | |||
168 | |||
169 | HRESULT ScaVirtualDirsInstall7( | ||
170 | __in SCA_VDIR7* psvdList, | ||
171 | __in SCA_APPPOOL * psapList | ||
172 | ) | ||
173 | { | ||
174 | HRESULT hr = S_OK; | ||
175 | SCA_VDIR7* psvd = psvdList; | ||
176 | LPWSTR wzPath = NULL; | ||
177 | WCHAR wzAppPoolName[MAX_PATH]; | ||
178 | while (psvd) | ||
179 | { | ||
180 | if (WcaIsInstalling(psvd->isInstalled, psvd->isAction)) | ||
181 | { | ||
182 | // First write all applications, this is necessary since vdirs must be nested under the applications. | ||
183 | if (psvd->fHasApplication) | ||
184 | { | ||
185 | //create the application for this vdir application | ||
186 | hr = ScaWriteConfigID(IIS_APPLICATION); | ||
187 | ExitOnFailure(hr, "Failed to write app ID"); | ||
188 | hr = ScaWriteConfigID(IIS_CREATE); | ||
189 | ExitOnFailure(hr, "Failed to write app action"); | ||
190 | #pragma prefast(suppress:26037, "Source string is null terminated - it is populated as target of ::StringCchCopyW") | ||
191 | hr = ScaWriteConfigString(psvd->wzWebName); //site name key | ||
192 | ExitOnFailure(hr, "Failed to write app web key"); | ||
193 | hr = StrAllocFormatted(&wzPath, L"/%s", psvd->wzVDirRoot); | ||
194 | ExitOnFailure(hr, "Failed to create app path"); | ||
195 | hr = ScaWriteConfigString(wzPath); // App Path | ||
196 | ExitOnFailure(hr, "Failed to write app path root "); | ||
197 | |||
198 | if (!*psvd->swapp.wzAppPool) | ||
199 | { | ||
200 | //This Application goes in default appPool | ||
201 | hr = ScaWriteConfigString(L""); // App Pool | ||
202 | } | ||
203 | else | ||
204 | { | ||
205 | //get apppool from WebApplication | ||
206 | #pragma prefast(suppress:26037, "Source string is null terminated - it is populated as target of ::StringCchCopyW") | ||
207 | hr = ScaFindAppPool7(psvd->swapp.wzAppPool, wzAppPoolName, countof(wzAppPoolName), psapList); | ||
208 | ExitOnFailure(hr, "Failed to read app pool from application"); | ||
209 | hr = ScaWriteConfigString(wzAppPoolName); // App Pool | ||
210 | ExitOnFailure(hr, "Failed to write appPool for vdir"); | ||
211 | |||
212 | } | ||
213 | } | ||
214 | } | ||
215 | |||
216 | psvd = psvd->psvdNext; | ||
217 | } | ||
218 | |||
219 | // Reset our linked list and write all the VDirs | ||
220 | psvd = psvdList; | ||
221 | while (psvd) | ||
222 | { | ||
223 | if (WcaIsInstalling(psvd->isInstalled, psvd->isAction)) | ||
224 | { | ||
225 | //create the Vdir | ||
226 | hr = ScaWriteConfigID(IIS_VDIR); | ||
227 | ExitOnFailure(hr, "Failed write VirDir ID") | ||
228 | hr = ScaWriteConfigID(IIS_CREATE); | ||
229 | ExitOnFailure(hr, "Failed write VirDir action") | ||
230 | #pragma prefast(suppress:26037, "Source string is null terminated - it is populated as target of ::StringCchCopyW") | ||
231 | hr = ScaWriteConfigString(psvd->wzWebName); //site name key | ||
232 | ExitOnFailure(hr, "Failed write VirDir web name"); | ||
233 | hr = StrAllocFormatted(&wzPath, L"/%s", psvd->wzVDirRoot); | ||
234 | ExitOnFailure(hr, "Failed to create vdir path"); | ||
235 | hr = ScaWriteConfigString(wzPath); //vdir path | ||
236 | ExitOnFailure(hr, "Failed write VirDir path") | ||
237 | #pragma prefast(suppress:26037, "Source string is null terminated - it is populated as target of ::StringCchCopyW") | ||
238 | hr = ScaWriteConfigString(psvd->wzDirectory); //physical dir | ||
239 | ExitOnFailure(hr, "Failed write VirDir dir"); | ||
240 | |||
241 | if (psvd->fHasProperties) | ||
242 | { | ||
243 | ScaWriteWebDirProperties7(psvd->wzWebName, psvd->wzVDirRoot, &psvd->swp); | ||
244 | ExitOnFailure(hr, "Failed to write directory properties for VirtualDir"); | ||
245 | } | ||
246 | |||
247 | if (psvd->fHasApplication) | ||
248 | { | ||
249 | hr = ScaWriteWebApplication7(psvd->wzWebName, psvd->wzVDirRoot, &psvd->swapp, psapList); | ||
250 | ExitOnFailure(hr, "Failed to write application for VirtualDir"); | ||
251 | } | ||
252 | |||
253 | if (psvd->psmm) | ||
254 | { | ||
255 | hr = ScaWriteMimeMap7(psvd->wzWebName, psvd->wzVDirRoot, psvd->psmm); | ||
256 | ExitOnFailure(hr, "Failed to write mimemap for VirtualDir"); | ||
257 | } | ||
258 | |||
259 | if (psvd->pshh) | ||
260 | { | ||
261 | hr = ScaWriteHttpHeader7(psvd->wzWebName, psvd->wzVDirRoot, psvd->pshh); | ||
262 | ExitOnFailure(hr, "Failed to write custom HTTP headers for VirtualDir"); | ||
263 | } | ||
264 | |||
265 | if (psvd->pswe) | ||
266 | { | ||
267 | hr = ScaWriteWebError7(psvd->wzWebName, psvd->wzVDirRoot, psvd->pswe); | ||
268 | ExitOnFailure(hr, "Failed to write custom web errors for VirtualDir"); | ||
269 | } | ||
270 | } | ||
271 | |||
272 | psvd = psvd->psvdNext; | ||
273 | } | ||
274 | |||
275 | LExit: | ||
276 | ReleaseStr(wzPath); | ||
277 | return hr; | ||
278 | } | ||
279 | |||
280 | |||
281 | HRESULT ScaVirtualDirsUninstall7( | ||
282 | __in SCA_VDIR7* psvdList | ||
283 | ) | ||
284 | { | ||
285 | |||
286 | HRESULT hr = S_OK; | ||
287 | SCA_VDIR7* psvd = psvdList; | ||
288 | LPWSTR wzPath = NULL; | ||
289 | |||
290 | while (psvd) | ||
291 | { | ||
292 | if (WcaIsUninstalling(psvd->isInstalled, psvd->isAction)) | ||
293 | { | ||
294 | //init path | ||
295 | hr = StrAllocFormatted(&wzPath, L"/%s", psvd->wzVDirRoot); | ||
296 | ExitOnFailure(hr, "Failed to create vdir path"); | ||
297 | |||
298 | if (psvd->fHasApplication) | ||
299 | { | ||
300 | //delete Application | ||
301 | hr = ScaWriteConfigID(IIS_APPLICATION); | ||
302 | ExitOnFailure(hr, "Failed to write app ID "); | ||
303 | hr = ScaWriteConfigID(IIS_DELETE); | ||
304 | ExitOnFailure(hr, "Failed to write delete app ID "); | ||
305 | #pragma prefast(suppress:26037, "Source string is null terminated - it is populated as target of ::StringCchCopyW") | ||
306 | hr = ScaWriteConfigString(psvd->wzWebName); //site name key | ||
307 | ExitOnFailure(hr, "Failed to write App site Name"); | ||
308 | #pragma prefast(suppress:26037, "Source string is null terminated - it is populated as target of ::StringCchCopyW") | ||
309 | hr = ScaWriteConfigString(wzPath); // App Path | ||
310 | ExitOnFailure(hr, "Failed to write app path root "); | ||
311 | hr = ScaWriteConfigString(L"NOP"); // App pool | ||
312 | ExitOnFailure(hr, "Failed to write app path app pool "); | ||
313 | } | ||
314 | else | ||
315 | { | ||
316 | //delete VDir | ||
317 | hr = ScaWriteConfigID(IIS_VDIR); | ||
318 | ExitOnFailure(hr, "Failed to write vDir ID "); | ||
319 | hr = ScaWriteConfigID(IIS_DELETE); | ||
320 | #pragma prefast(suppress:26037, "Source string is null terminated - it is populated as target of ::StringCchCopyW") | ||
321 | hr = ScaWriteConfigString(psvd->wzWebName); //site name key | ||
322 | ExitOnFailure(hr, "Failed to write App site Name"); | ||
323 | hr = ScaWriteConfigString(wzPath); // Vdir Path | ||
324 | ExitOnFailure(hr, "Failed to write app vdir "); | ||
325 | hr = ScaWriteConfigString(L"NOP"); // Phy Path | ||
326 | ExitOnFailure(hr, "Failed to write vdir path"); | ||
327 | } | ||
328 | |||
329 | ExitOnFailure(hr, "Failed to remove VirtualDir '%ls' from config", psvd->wzKey); | ||
330 | } | ||
331 | |||
332 | psvd = psvd->psvdNext; | ||
333 | } | ||
334 | |||
335 | LExit: | ||
336 | ReleaseStr(wzPath); | ||
337 | return hr; | ||
338 | } | ||
339 | |||
340 | |||
341 | void ScaVirtualDirsFreeList7( | ||
342 | __in SCA_VDIR7* psvdList | ||
343 | ) | ||
344 | { | ||
345 | SCA_VDIR7* psvdDelete = psvdList; | ||
346 | while (psvdList) | ||
347 | { | ||
348 | psvdDelete = psvdList; | ||
349 | psvdList = psvdList->psvdNext; | ||
350 | |||
351 | if (psvdDelete->psmm) | ||
352 | { | ||
353 | ScaMimeMapFreeList(psvdDelete->psmm); | ||
354 | } | ||
355 | |||
356 | if (psvdDelete->pswe) | ||
357 | { | ||
358 | ScaWebErrorFreeList(psvdDelete->pswe); | ||
359 | } | ||
360 | |||
361 | MemFree(psvdDelete); | ||
362 | } | ||
363 | } | ||
364 | |||
365 | |||
366 | static HRESULT AddVirtualDirToList7( | ||
367 | __in SCA_VDIR7** ppsvdList | ||
368 | ) | ||
369 | { | ||
370 | HRESULT hr = S_OK; | ||
371 | |||
372 | SCA_VDIR7* psvd = static_cast<SCA_VDIR7*>(MemAlloc(sizeof(SCA_VDIR7), TRUE)); | ||
373 | ExitOnNull(psvd, hr, E_OUTOFMEMORY, "failed to allocate memory for new vdir list element"); | ||
374 | |||
375 | psvd->psvdNext= *ppsvdList; | ||
376 | *ppsvdList = psvd; | ||
377 | |||
378 | LExit: | ||
379 | return hr; | ||
380 | } | ||