aboutsummaryrefslogtreecommitdiff
path: root/src/ca/scafilter7.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ca/scafilter7.cpp')
-rw-r--r--src/ca/scafilter7.cpp284
1 files changed, 284 insertions, 0 deletions
diff --git a/src/ca/scafilter7.cpp b/src/ca/scafilter7.cpp
new file mode 100644
index 00000000..dda91c4d
--- /dev/null
+++ b/src/ca/scafilter7.cpp
@@ -0,0 +1,284 @@
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
5static HRESULT WriteFilter(const SCA_FILTER* psf);
6
7UINT __stdcall ScaFiltersRead7(
8 __in SCA_WEB7* pswList,
9 __in WCA_WRAPQUERY_HANDLE /*hWebBaseQuery*/,
10 __inout SCA_FILTER** ppsfList,
11 __inout LPWSTR *ppwzCustomActionData
12 )
13{
14 HRESULT hr = S_OK;
15 MSIHANDLE hRec;
16 INSTALLSTATE isInstalled = INSTALLSTATE_UNKNOWN;
17 INSTALLSTATE isAction = INSTALLSTATE_UNKNOWN;
18 SCA_FILTER* psf;
19
20 LPWSTR pwzData = NULL;
21 WCA_WRAPQUERY_HANDLE hWrapQuery = NULL;
22 hr = WcaBeginUnwrapQuery(&hWrapQuery, ppwzCustomActionData);
23 ExitOnFailure(hr, "Failed to unwrap query for ScaAppPoolRead");
24
25 if (0 == WcaGetQueryRecords(hWrapQuery))
26 {
27 WcaLog(LOGMSG_VERBOSE, "Skipping ScaFiltersRead() - no IIsFilter table");
28 ExitFunction1(hr = S_FALSE);
29 }
30
31 // loop through all the filters
32 while (S_OK == (hr = WcaFetchWrappedRecord(hWrapQuery, &hRec)))
33 {
34 // Get the Component first. If the component is not being modified during
35 // this transaction, skip processing this whole record.
36 // get the darwin information
37 hr = WcaGetRecordString(hRec, fqComponent, &pwzData);
38 ExitOnFailure(hr, "failed to get IIsFilter.Component");
39
40 hr = WcaGetRecordInteger(hRec, fqInstalled, (int *)&isInstalled);
41 ExitOnFailure(hr, "Failed to get Component installed state for IIs filter");
42
43 hr = WcaGetRecordInteger(hRec, fqAction, (int *)&isAction);
44 ExitOnFailure(hr, "Failed to get Component action state for IIs filter");
45
46 if (!WcaIsInstalling(isInstalled, isAction) &&
47 !WcaIsReInstalling(isInstalled, isAction) &&
48 !WcaIsUninstalling(isInstalled, isAction))
49 {
50 continue; // skip this record.
51 }
52
53 hr = AddFilterToList(ppsfList);
54 ExitOnFailure(hr, "failed to add filter to list");
55
56 psf = *ppsfList;
57
58 hr = ::StringCchCopyW(psf->wzComponent, countof(psf->wzComponent), pwzData);
59 ExitOnFailure(hr, "failed to copy component name: %ls", pwzData);
60
61 psf->isInstalled = isInstalled;
62 psf->isAction = isAction;
63
64 hr = WcaGetRecordString(hRec, fqWeb, &pwzData);
65 ExitOnFailure(hr, "Failed to get Web for VirtualDir");
66
67 if (*pwzData)
68 {
69 hr = ScaWebsGetBase7(pswList, pwzData, psf->wzFilterRoot, countof(psf->wzFilterRoot));
70 if (FAILED(hr))
71 {
72 WcaLog(LOGMSG_VERBOSE, "Could not find site for filter: %ls. Result 0x%x ", psf->wzFilterRoot, hr);
73 hr = S_OK;
74 }
75 }
76 else
77 {
78 hr = ::StringCchCopyW(psf->wzFilterRoot, countof(psf->wzFilterRoot), L"/");
79 ExitOnFailure(hr, "Failed to allocate global filter base string");
80 }
81
82 // filter Name key
83 hr = WcaGetRecordString(hRec, fqFilter, &pwzData);
84 ExitOnFailure(hr, "Failed to get Filter.Filter");
85 hr = ::StringCchCopyW(psf->wzKey, countof(psf->wzKey), pwzData);
86 ExitOnFailure(hr, "Failed to copy key string to filter object");
87
88 // filter path
89 hr = WcaGetRecordString(hRec, fqPath, &pwzData);
90 ExitOnFailure(hr, "Failed to get Filter.Path");
91 hr = ::StringCchCopyW(psf->wzPath, countof(psf->wzPath), pwzData);
92 ExitOnFailure(hr, "Failed to copy path string to filter object");
93
94 // filter description -- not supported in iis 7
95 hr = WcaGetRecordString(hRec, fqDescription, &pwzData);
96 ExitOnFailure(hr, "Failed to get Filter.Description");
97 hr = ::StringCchCopyW(psf->wzDescription, countof(psf->wzDescription), pwzData);
98 ExitOnFailure(hr, "Failed to copy description string to filter object");
99
100 // filter flags
101 //What are these
102 hr = WcaGetRecordInteger(hRec, fqFlags, &psf->iFlags);
103 ExitOnFailure(hr, "Failed to get Filter.Flags");
104
105 // filter load order
106 hr = WcaGetRecordInteger(hRec, fqLoadOrder, &psf->iLoadOrder);
107 ExitOnFailure(hr, "Failed to get Filter.LoadOrder");
108 }
109
110 if (E_NOMOREITEMS == hr)
111 {
112 hr = S_OK;
113 }
114 ExitOnFailure(hr, "Failure while processing filters");
115
116LExit:
117 WcaFinishUnwrapQuery(hWrapQuery);
118
119 ReleaseStr(pwzData);
120
121 return hr;
122}
123
124
125HRESULT ScaFiltersInstall7(
126 __in SCA_FILTER* psfList
127 )
128{
129 HRESULT hr = S_OK;
130 SCA_FILTER* psf = psfList;
131
132 if (!psf)
133 {
134 ExitFunction();
135 }
136 //write global filters
137 hr = ScaWriteConfigID(IIS_FILTER_GLOBAL_BEGIN);
138 ExitOnFailure(hr, "Failed to write filter begin ID");
139 while (psf)
140 {
141 if (WcaIsInstalling(psf->isInstalled, psf->isAction))
142 {
143 if (0 == wcscmp(psf->wzFilterRoot, L"/"))
144 {
145 hr = WriteFilter(psf);
146 }
147 }
148 psf = psf->psfNext;
149 }
150 hr = ScaWriteConfigID(IIS_FILTER_END);
151 ExitOnFailure(hr, "Failed to write filter ID");
152
153 psf = psfList;
154
155 //Write Web Site Filters
156 hr = ScaWriteConfigID(IIS_FILTER_BEGIN);
157 ExitOnFailure(hr, "Failed to write filter begin ID");
158 while (psf)
159 {
160 if (WcaIsInstalling(psf->isInstalled, psf->isAction))
161 {
162 if (0 != wcscmp(psf->wzFilterRoot, L"/"))
163 {
164 hr = WriteFilter(psf);
165 }
166 }
167 psf = psf->psfNext;
168 }
169 hr = ScaWriteConfigID(IIS_FILTER_END);
170 ExitOnFailure(hr, "Failed to write filter ID");
171
172LExit:
173
174 return hr;
175}
176static HRESULT WriteFilter(const SCA_FILTER* psf)
177{
178 HRESULT hr = S_OK;
179
180 hr = ScaWriteConfigID(IIS_FILTER);
181 ExitOnFailure(hr, "Failed to write filter begin ID");
182
183 hr = ScaWriteConfigID(IIS_CREATE);
184 ExitOnFailure(hr, "Failed to write filter create ID");
185
186 //filter Name key
187 hr = ScaWriteConfigString(psf->wzKey);
188 ExitOnFailure(hr, "Failed to write key name for filter '%ls'", psf->wzKey);
189
190 //web site name
191 hr = ScaWriteConfigString(psf->wzFilterRoot);
192 ExitOnFailure(hr, "Failed to write filter web root ");
193
194 // filter path
195 hr = ScaWriteConfigString(psf->wzPath);
196 ExitOnFailure(hr, "Failed to write Path for filter '%ls'", psf->wzKey);
197
198 //filter load order
199 hr = ScaWriteConfigInteger(psf->iLoadOrder);
200 ExitOnFailure(hr, "Failed to write load order for filter '%ls'", psf->wzKey);
201
202LExit:
203 return hr;
204}
205
206
207HRESULT ScaFiltersUninstall7(
208 __in SCA_FILTER* psfList
209 )
210{
211 HRESULT hr = S_OK;
212 SCA_FILTER* psf = psfList;
213
214 if (!psf)
215 {
216 ExitFunction1(hr = S_OK);
217 }
218
219 //Uninstall global filters
220 hr = ScaWriteConfigID(IIS_FILTER_GLOBAL_BEGIN);
221 ExitOnFailure(hr, "Failed to write filter begin ID");
222
223 while (psf)
224 {
225 if (WcaIsUninstalling(psf->isInstalled, psf->isAction))
226 {
227 if (0 == wcscmp(psf->wzFilterRoot, L"/"))
228 {
229 hr = ScaWriteConfigID(IIS_FILTER);
230 ExitOnFailure(hr, "Failed to write filter begin ID");
231
232 hr = ScaWriteConfigID(IIS_DELETE);
233 ExitOnFailure(hr, "Failed to write filter create ID");
234
235 //filter Name key
236 hr = ScaWriteConfigString(psf->wzKey);
237 ExitOnFailure(hr, "Failed to write key name for filter '%ls'", psf->wzKey);
238
239 //web site name
240 hr = ScaWriteConfigString(psf->wzFilterRoot);
241 ExitOnFailure(hr, "Failed to write filter web root ");
242
243 }
244 }
245 psf = psf->psfNext;
246 }
247
248 hr = ScaWriteConfigID(IIS_FILTER_END);
249 ExitOnFailure(hr, "Failed to write filter ID");
250
251 psf = psfList;
252
253 //Uninstall website filters
254 hr = ScaWriteConfigID(IIS_FILTER_BEGIN);
255 ExitOnFailure(hr, "Failed to write filter begin ID");
256 while (psf)
257 {
258 if (WcaIsUninstalling(psf->isInstalled, psf->isAction))
259 {
260 if (0 != wcscmp(psf->wzFilterRoot, L"/"))
261 {
262 hr = ScaWriteConfigID(IIS_FILTER);
263 ExitOnFailure(hr, "Failed to write filter begin ID");
264
265 hr = ScaWriteConfigID(IIS_DELETE);
266 ExitOnFailure(hr, "Failed to write filter create ID");
267
268 //filter Name key
269 hr = ScaWriteConfigString(psf->wzKey);
270 ExitOnFailure(hr, "Failed to write key name for filter '%ls'", psf->wzKey);
271
272 //web site name
273 hr = ScaWriteConfigString(psf->wzFilterRoot);
274 ExitOnFailure(hr, "Failed to write filter web root ");
275 }
276 }
277 psf = psf->psfNext;
278 }
279 hr = ScaWriteConfigID(IIS_FILTER_END);
280 ExitOnFailure(hr, "Failed to write filter ID");
281
282LExit:
283 return hr;
284}