aboutsummaryrefslogtreecommitdiff
path: root/src/ext/Iis/ca/scaproperty.cpp
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2021-05-04 22:48:12 -0700
committerRob Mensching <rob@firegiant.com>2021-05-04 22:48:12 -0700
commit7c8e34de56b3348c5a421cd0cced183e1394c5c7 (patch)
treec2f17867b49e33e0833eae2e1841a00b009c1a15 /src/ext/Iis/ca/scaproperty.cpp
parentc5c87377d99beefe83a3470aab326d12bdf0f8a4 (diff)
downloadwix-7c8e34de56b3348c5a421cd0cced183e1394c5c7.tar.gz
wix-7c8e34de56b3348c5a421cd0cced183e1394c5c7.tar.bz2
wix-7c8e34de56b3348c5a421cd0cced183e1394c5c7.zip
Move Iis.wixext into ext
Diffstat (limited to 'src/ext/Iis/ca/scaproperty.cpp')
-rw-r--r--src/ext/Iis/ca/scaproperty.cpp252
1 files changed, 252 insertions, 0 deletions
diff --git a/src/ext/Iis/ca/scaproperty.cpp b/src/ext/Iis/ca/scaproperty.cpp
new file mode 100644
index 00000000..d0e0d8a4
--- /dev/null
+++ b/src/ext/Iis/ca/scaproperty.cpp
@@ -0,0 +1,252 @@
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/*------------------------------------------------------------------
6IIsProperty table:
7
8Property Component_ Attributes Value
9s72 s72 i4 s255
10------------------------------------------------------------------*/
11
12// sql queries
13enum ePropertyQuery { pqProperty = 1, pqComponent, pqAttributes, pqValue, pqInstalled, pqAction };
14
15
16// prototypes
17static HRESULT AddPropertyToList(
18 SCA_PROPERTY** ppspList
19 );
20
21
22// functions
23void ScaPropertyFreeList(
24 SCA_PROPERTY* pspList
25 )
26{
27 SCA_PROPERTY* pspDelete = pspList;
28 while (pspList)
29 {
30 pspDelete = pspList;
31 pspList = pspList->pspNext;
32
33 MemFree(pspDelete);
34 }
35}
36
37
38HRESULT ScaPropertyRead(
39 SCA_PROPERTY** ppspList,
40 __inout LPWSTR *ppwzCustomActionData
41 )
42{
43 HRESULT hr = S_OK;
44 MSIHANDLE hRec;
45
46 LPWSTR pwzData = NULL;
47 SCA_PROPERTY* pss;
48
49 WCA_WRAPQUERY_HANDLE hWrapQuery = NULL;
50
51 ExitOnNull(ppspList, hr, E_INVALIDARG, "Failed to read property, because no property to read was provided");
52
53 hr = WcaBeginUnwrapQuery(&hWrapQuery, ppwzCustomActionData);
54 ExitOnFailure(hr, "Failed to unwrap query for ScaAppPoolRead");
55
56 if (0 == WcaGetQueryRecords(hWrapQuery))
57 {
58 WcaLog(LOGMSG_VERBOSE, "Skipping ScaInstallProperty() - required table not present");
59 ExitFunction1(hr = S_FALSE);
60 }
61
62 // loop through all the Settings
63 while (S_OK == (hr = WcaFetchWrappedRecord(hWrapQuery, &hRec)))
64 {
65 hr = AddPropertyToList(ppspList);
66 ExitOnFailure(hr, "failed to add property to list");
67
68 pss = *ppspList;
69
70 hr = WcaGetRecordString(hRec, pqProperty, &pwzData);
71 ExitOnFailure(hr, "failed to get IIsProperty.Property");
72 hr = ::StringCchCopyW(pss->wzProperty, countof(pss->wzProperty), pwzData);
73 ExitOnFailure(hr, "failed to copy Property name: %ls", pwzData);
74
75 hr = WcaGetRecordString(hRec, pqValue, &pwzData);
76 ExitOnFailure(hr, "failed to get IIsProperty.Value");
77 hr = ::StringCchCopyW(pss->wzValue, countof(pss->wzValue), pwzData);
78 ExitOnFailure(hr, "failed to copy Property value: %ls", pwzData);
79
80 hr = WcaGetRecordInteger(hRec, pqAttributes, &pss->iAttributes);
81 ExitOnFailure(hr, "failed to get IIsProperty.Attributes");
82
83 hr = WcaGetRecordString(hRec, pqComponent, &pwzData);
84 ExitOnFailure(hr, "failed to get IIsProperty.Component");
85 hr = ::StringCchCopyW(pss->wzComponent, countof(pss->wzComponent), pwzData);
86 ExitOnFailure(hr, "failed to copy component name: %ls", pwzData);
87
88 hr = WcaGetRecordInteger(hRec, pqInstalled, (int *)&pss->isInstalled);
89 ExitOnFailure(hr, "Failed to get Component installed state for filter");
90
91 hr = WcaGetRecordInteger(hRec, pqAction, (int *)&pss->isAction);
92 ExitOnFailure(hr, "Failed to get Component action state for filter");
93 }
94
95 if (E_NOMOREITEMS == hr)
96 {
97 hr = S_OK;
98 }
99 ExitOnFailure(hr, "failure while processing IIsProperty table");
100
101LExit:
102 WcaFinishUnwrapQuery(hWrapQuery);
103
104 ReleaseStr(pwzData);
105
106 return hr;
107}
108
109
110HRESULT ScaPropertyInstall(
111 IMSAdminBase* piMetabase,
112 SCA_PROPERTY* pspList
113 )
114{
115 Assert(piMetabase);
116
117 HRESULT hr = S_OK;
118
119 for (SCA_PROPERTY* psp = pspList; psp; psp = psp->pspNext)
120 {
121 // if we are installing the web site
122 if (WcaIsInstalling(psp->isInstalled, psp->isAction))
123 {
124 hr = ScaWriteProperty(piMetabase, psp);
125 ExitOnFailure(hr, "failed to write Property '%ls' to metabase", psp->wzProperty);
126 }
127 }
128
129LExit:
130 return hr;
131}
132
133
134HRESULT ScaPropertyUninstall(
135 IMSAdminBase* piMetabase,
136 SCA_PROPERTY* pspList
137 )
138{
139 Assert(piMetabase);
140
141 HRESULT hr = S_OK;
142
143 for (SCA_PROPERTY* psp = pspList; psp; psp = psp->pspNext)
144 {
145 // if we are uninstalling the web site
146 if (WcaIsUninstalling(psp->isInstalled, psp->isAction))
147 {
148 hr = ScaRemoveProperty(piMetabase, psp);
149 ExitOnFailure(hr, "Failed to remove Property '%ls' from metabase", psp->wzProperty);
150 }
151 }
152
153LExit:
154 return hr;
155}
156
157
158HRESULT ScaWriteProperty(
159 IMSAdminBase* piMetabase,
160 SCA_PROPERTY* psp
161 )
162{
163 Assert(piMetabase);
164
165 HRESULT hr = S_OK;
166 DWORD dwValue;
167 LPWSTR wz = NULL;
168
169 ExitOnNull(psp, hr, E_INVALIDARG, "Failed to write property because no property to write was given");
170
171 //
172 // Figure out what setting we're writing and write it
173 //
174 if (0 == lstrcmpW(psp->wzProperty, wzIISPROPERTY_IIS5_ISOLATION_MODE))
175 {
176 dwValue = 1;
177 hr = ScaWriteMetabaseValue(piMetabase, L"/LM/W3SVC", NULL, MD_GLOBAL_STANDARD_APP_MODE_ENABLED, METADATA_NO_ATTRIBUTES, IIS_MD_UT_SERVER, DWORD_METADATA, (LPVOID)((DWORD_PTR)dwValue));
178 ExitOnFailure(hr, "failed to set IIs5IsolationMode");
179 }
180 else if (0 == lstrcmpW(psp->wzProperty, wzIISPROPERTY_MAX_GLOBAL_BANDWIDTH))
181 {
182 dwValue = wcstoul(psp->wzValue, &wz, 10) * 1024; // remember, the value shown is in kilobytes, the value saved is in bytes
183 hr = ScaWriteMetabaseValue(piMetabase, L"/LM/W3SVC", NULL, MD_MAX_GLOBAL_BANDWIDTH, METADATA_NO_ATTRIBUTES, IIS_MD_UT_SERVER, DWORD_METADATA, (LPVOID)((DWORD_PTR)dwValue));
184 ExitOnFailure(hr, "failed to set MaxGlobalBandwidth");
185 }
186 else if (0 == lstrcmpW(psp->wzProperty, wzIISPROPERTY_LOG_IN_UTF8))
187 {
188 dwValue = 1;
189 hr = ScaWriteMetabaseValue(piMetabase, L"/LM/W3SVC", NULL, MD_GLOBAL_LOG_IN_UTF_8, METADATA_NO_ATTRIBUTES, IIS_MD_UT_SERVER, DWORD_METADATA, (LPVOID)((DWORD_PTR)dwValue));
190 ExitOnFailure(hr, "failed to set LogInUTF8");
191 }
192 else if (0 == lstrcmpW(psp->wzProperty, wzIISPROPERTY_ETAG_CHANGENUMBER))
193 {
194 dwValue = wcstoul(psp->wzValue, &wz, 10);
195 hr = ScaWriteMetabaseValue(piMetabase, L"/LM/W3SVC", NULL, /*MD_ETAG_CHANGENUMBER*/ 2039, METADATA_INHERIT, IIS_MD_UT_SERVER, DWORD_METADATA, (LPVOID)((DWORD_PTR)dwValue));
196 ExitOnFailure(hr, "failed to set EtagChangenumber");
197 }
198LExit:
199 return hr;
200}
201
202
203HRESULT ScaRemoveProperty(
204 IMSAdminBase* piMetabase,
205 SCA_PROPERTY* psp
206 )
207{
208 Assert(piMetabase);
209
210 HRESULT hr = S_OK;
211 DWORD dwValue;
212
213 ExitOnNull(psp, hr, E_INVALIDARG, "Failed to remove property because no property to remove was given");
214
215 if (0 == lstrcmpW(psp->wzProperty, wzIISPROPERTY_IIS5_ISOLATION_MODE))
216 {
217 dwValue = 0;
218 hr = ScaWriteMetabaseValue(piMetabase, L"/LM/W3SVC", NULL, MD_GLOBAL_STANDARD_APP_MODE_ENABLED, METADATA_NO_ATTRIBUTES, IIS_MD_UT_SERVER, DWORD_METADATA, (LPVOID)((DWORD_PTR)dwValue));
219 ExitOnFailure(hr, "failed to clear IIs5IsolationMode");
220 }
221 else if (0 == lstrcmpW(psp->wzProperty, wzIISPROPERTY_MAX_GLOBAL_BANDWIDTH))
222 {
223 dwValue = 0xFFFFFFFF; // This unchecks the box
224 hr = ScaWriteMetabaseValue(piMetabase, L"/LM/W3SVC", NULL, MD_MAX_GLOBAL_BANDWIDTH, METADATA_NO_ATTRIBUTES , IIS_MD_UT_SERVER, DWORD_METADATA, (LPVOID)((DWORD_PTR)dwValue));
225 ExitOnFailure(hr, "failed to clear MaxGlobalBandwidth");
226 }
227 else if (0 == lstrcmpW(psp->wzProperty, wzIISPROPERTY_LOG_IN_UTF8))
228 {
229 dwValue = 0;
230 hr = ScaWriteMetabaseValue(piMetabase, L"/LM/W3SVC", NULL, MD_GLOBAL_LOG_IN_UTF_8, METADATA_NO_ATTRIBUTES, IIS_MD_UT_SERVER, DWORD_METADATA, (LPVOID)((DWORD_PTR)dwValue));
231 ExitOnFailure(hr, "failed to clear LogInUTF8");
232 }
233
234LExit:
235 return hr;
236}
237
238
239static HRESULT AddPropertyToList(
240 SCA_PROPERTY** ppspList
241 )
242{
243 HRESULT hr = S_OK;
244 SCA_PROPERTY* psp = static_cast<SCA_PROPERTY*>(MemAlloc(sizeof(SCA_PROPERTY), TRUE));
245 ExitOnNull(psp, hr, E_OUTOFMEMORY, "failed to allocate memory for new property list element");
246
247 psp->pspNext = *ppspList;
248 *ppspList = psp;
249
250LExit:
251 return hr;
252}