aboutsummaryrefslogtreecommitdiff
path: root/src/ca/scafilter7.cpp
blob: dda91c4d832d966de4d9c98f7a52e8cb80ca9bef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
// 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.

#include "precomp.h"

static HRESULT WriteFilter(const SCA_FILTER* psf);

UINT __stdcall ScaFiltersRead7(
    __in SCA_WEB7* pswList,
    __in WCA_WRAPQUERY_HANDLE /*hWebBaseQuery*/,
    __inout SCA_FILTER** ppsfList,
    __inout LPWSTR *ppwzCustomActionData
    )
{
    HRESULT hr = S_OK;
    MSIHANDLE hRec;
    INSTALLSTATE isInstalled = INSTALLSTATE_UNKNOWN;
    INSTALLSTATE isAction = INSTALLSTATE_UNKNOWN;
    SCA_FILTER* psf;

    LPWSTR pwzData = NULL;
    WCA_WRAPQUERY_HANDLE hWrapQuery = NULL;
    hr = WcaBeginUnwrapQuery(&hWrapQuery, ppwzCustomActionData);
    ExitOnFailure(hr, "Failed to unwrap query for ScaAppPoolRead");

    if (0 == WcaGetQueryRecords(hWrapQuery))
    {
        WcaLog(LOGMSG_VERBOSE, "Skipping ScaFiltersRead() - no IIsFilter table");
        ExitFunction1(hr = S_FALSE);
    }

    // loop through all the filters
    while (S_OK == (hr = WcaFetchWrappedRecord(hWrapQuery, &hRec)))
    {
        // Get the Component first.  If the component is not being modified during
        // this transaction, skip processing this whole record.
        // get the darwin information
        hr = WcaGetRecordString(hRec, fqComponent, &pwzData);
        ExitOnFailure(hr, "failed to get IIsFilter.Component");

        hr = WcaGetRecordInteger(hRec, fqInstalled, (int *)&isInstalled);
        ExitOnFailure(hr, "Failed to get Component installed state for IIs filter");

        hr = WcaGetRecordInteger(hRec, fqAction, (int *)&isAction);
        ExitOnFailure(hr, "Failed to get Component action state for IIs filter");

        if (!WcaIsInstalling(isInstalled, isAction) &&
            !WcaIsReInstalling(isInstalled, isAction) &&
            !WcaIsUninstalling(isInstalled, isAction))
        {
            continue; // skip this record.
        }

        hr = AddFilterToList(ppsfList);
        ExitOnFailure(hr, "failed to add filter to list");

        psf = *ppsfList;

        hr = ::StringCchCopyW(psf->wzComponent, countof(psf->wzComponent), pwzData);
        ExitOnFailure(hr, "failed to copy component name: %ls", pwzData);

        psf->isInstalled = isInstalled;
        psf->isAction = isAction;

        hr = WcaGetRecordString(hRec, fqWeb, &pwzData);
        ExitOnFailure(hr, "Failed to get Web for VirtualDir");

        if (*pwzData)
        {
            hr = ScaWebsGetBase7(pswList, pwzData, psf->wzFilterRoot, countof(psf->wzFilterRoot));
            if (FAILED(hr))
            {
                WcaLog(LOGMSG_VERBOSE, "Could not find site for filter: %ls. Result 0x%x ", psf->wzFilterRoot, hr);
                hr = S_OK;
            }
        }
        else
        {
            hr = ::StringCchCopyW(psf->wzFilterRoot, countof(psf->wzFilterRoot), L"/");
            ExitOnFailure(hr, "Failed to allocate global filter base string");
        }

        // filter Name key
        hr = WcaGetRecordString(hRec, fqFilter, &pwzData);
        ExitOnFailure(hr, "Failed to get Filter.Filter");
        hr = ::StringCchCopyW(psf->wzKey, countof(psf->wzKey), pwzData);
        ExitOnFailure(hr, "Failed to copy key string to filter object");

        // filter path
        hr = WcaGetRecordString(hRec, fqPath, &pwzData);
        ExitOnFailure(hr, "Failed to get Filter.Path");
        hr = ::StringCchCopyW(psf->wzPath, countof(psf->wzPath), pwzData);
        ExitOnFailure(hr, "Failed to copy path string to filter object");

        // filter description -- not supported in iis 7
        hr = WcaGetRecordString(hRec, fqDescription, &pwzData);
        ExitOnFailure(hr, "Failed to get Filter.Description");
        hr = ::StringCchCopyW(psf->wzDescription, countof(psf->wzDescription), pwzData);
        ExitOnFailure(hr, "Failed to copy description string to filter object");

        // filter flags
        //What are these
        hr = WcaGetRecordInteger(hRec, fqFlags, &psf->iFlags);
        ExitOnFailure(hr, "Failed to get Filter.Flags");

        // filter load order
        hr = WcaGetRecordInteger(hRec, fqLoadOrder, &psf->iLoadOrder);
        ExitOnFailure(hr, "Failed to get Filter.LoadOrder");
    }

    if (E_NOMOREITEMS == hr)
    {
        hr = S_OK;
    }
    ExitOnFailure(hr, "Failure while processing filters");

LExit:
    WcaFinishUnwrapQuery(hWrapQuery);

    ReleaseStr(pwzData);

    return hr;
}


HRESULT ScaFiltersInstall7(
    __in SCA_FILTER* psfList
    )
{
    HRESULT hr = S_OK;
    SCA_FILTER* psf = psfList;

    if (!psf)
    {
        ExitFunction();
    }
    //write global filters
    hr = ScaWriteConfigID(IIS_FILTER_GLOBAL_BEGIN);
    ExitOnFailure(hr, "Failed to write filter begin ID");
    while (psf)
    {
        if (WcaIsInstalling(psf->isInstalled, psf->isAction))
        {
            if (0 == wcscmp(psf->wzFilterRoot, L"/"))
            {
                hr = WriteFilter(psf);
            }
        }
        psf = psf->psfNext;
    }
    hr = ScaWriteConfigID(IIS_FILTER_END);
    ExitOnFailure(hr, "Failed to write filter ID");

    psf = psfList;

    //Write Web Site Filters
    hr = ScaWriteConfigID(IIS_FILTER_BEGIN);
    ExitOnFailure(hr, "Failed to write filter begin ID");
    while (psf)
    {
        if (WcaIsInstalling(psf->isInstalled, psf->isAction))
        {
            if (0 != wcscmp(psf->wzFilterRoot, L"/"))
            {
                hr = WriteFilter(psf);
            }
        }
        psf = psf->psfNext;
    }
    hr = ScaWriteConfigID(IIS_FILTER_END);
    ExitOnFailure(hr, "Failed to write filter ID");

LExit:

    return hr;
}
static HRESULT WriteFilter(const SCA_FILTER* psf)
{
    HRESULT hr = S_OK;

    hr = ScaWriteConfigID(IIS_FILTER);
    ExitOnFailure(hr, "Failed to write filter begin ID");

    hr = ScaWriteConfigID(IIS_CREATE);
    ExitOnFailure(hr, "Failed to write filter create ID");

    //filter Name key
    hr = ScaWriteConfigString(psf->wzKey);
    ExitOnFailure(hr, "Failed to write key name for filter '%ls'", psf->wzKey);

    //web site name
    hr = ScaWriteConfigString(psf->wzFilterRoot);
    ExitOnFailure(hr, "Failed to write filter web root ");

    // filter path
    hr = ScaWriteConfigString(psf->wzPath);
    ExitOnFailure(hr, "Failed to write Path for filter '%ls'", psf->wzKey);

    //filter load order
    hr = ScaWriteConfigInteger(psf->iLoadOrder);
    ExitOnFailure(hr, "Failed to write load order for filter '%ls'", psf->wzKey);

LExit:
    return hr;
}


HRESULT ScaFiltersUninstall7(
    __in SCA_FILTER* psfList
    )
{
    HRESULT hr = S_OK;
    SCA_FILTER* psf = psfList;

    if (!psf)
    {
        ExitFunction1(hr = S_OK);
    }

    //Uninstall global filters
    hr = ScaWriteConfigID(IIS_FILTER_GLOBAL_BEGIN);
    ExitOnFailure(hr, "Failed to write filter begin ID");

    while (psf)
    {
        if (WcaIsUninstalling(psf->isInstalled, psf->isAction))
        {
            if (0 == wcscmp(psf->wzFilterRoot, L"/"))
            {
                hr = ScaWriteConfigID(IIS_FILTER);
                ExitOnFailure(hr, "Failed to write filter begin ID");

                hr = ScaWriteConfigID(IIS_DELETE);
                ExitOnFailure(hr, "Failed to write filter create ID");

                //filter Name key
                hr = ScaWriteConfigString(psf->wzKey);
                ExitOnFailure(hr, "Failed to write key name for filter '%ls'", psf->wzKey);

                //web site name
                hr = ScaWriteConfigString(psf->wzFilterRoot);
                ExitOnFailure(hr, "Failed to write filter web root ");

            }
        }
        psf = psf->psfNext;
    }

    hr = ScaWriteConfigID(IIS_FILTER_END);
    ExitOnFailure(hr, "Failed to write filter ID");

    psf = psfList;

    //Uninstall website filters
    hr = ScaWriteConfigID(IIS_FILTER_BEGIN);
    ExitOnFailure(hr, "Failed to write filter begin ID");
    while (psf)
    {
        if (WcaIsUninstalling(psf->isInstalled, psf->isAction))
        {
            if (0 != wcscmp(psf->wzFilterRoot, L"/"))
            {
                hr = ScaWriteConfigID(IIS_FILTER);
                ExitOnFailure(hr, "Failed to write filter begin ID");

                hr = ScaWriteConfigID(IIS_DELETE);
                ExitOnFailure(hr, "Failed to write filter create ID");

                //filter Name key
                hr = ScaWriteConfigString(psf->wzKey);
                ExitOnFailure(hr, "Failed to write key name for filter '%ls'", psf->wzKey);

                //web site name
                hr = ScaWriteConfigString(psf->wzFilterRoot);
                ExitOnFailure(hr, "Failed to write filter web root ");
            }
        }
        psf = psf->psfNext;
    }
    hr = ScaWriteConfigID(IIS_FILTER_END);
    ExitOnFailure(hr, "Failed to write filter ID");

LExit:
    return hr;
}