diff options
Diffstat (limited to 'src/ext/Iis/ca/scawebdir7.cpp')
-rw-r--r-- | src/ext/Iis/ca/scawebdir7.cpp | 219 |
1 files changed, 219 insertions, 0 deletions
diff --git a/src/ext/Iis/ca/scawebdir7.cpp b/src/ext/Iis/ca/scawebdir7.cpp new file mode 100644 index 00000000..5ead0470 --- /dev/null +++ b/src/ext/Iis/ca/scawebdir7.cpp | |||
@@ -0,0 +1,219 @@ | |||
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 | // sql queries | ||
6 | static LPCWSTR vcsWebDirQuery7 = L"SELECT `Web_`, `WebDir`, `Component_`, `Path`, `DirProperties_`, `Application_`" | ||
7 | L"FROM `IIsWebDir`"; | ||
8 | |||
9 | enum eWebDirQuery { wdqWeb = 1, wdqWebDir, wdqComponent , wdqPath, wdqProperties, wdqApplication, wdqInstalled, wdqAction }; | ||
10 | |||
11 | // prototypes | ||
12 | static HRESULT AddWebDirToList(SCA_WEBDIR7** ppswdList); | ||
13 | |||
14 | |||
15 | UINT __stdcall ScaWebDirsRead7( | ||
16 | __in SCA_WEB7* pswList, | ||
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 | __out SCA_WEBDIR7** ppswdList | ||
24 | ) | ||
25 | { | ||
26 | HRESULT hr = S_OK; | ||
27 | MSIHANDLE hRec; | ||
28 | |||
29 | LPWSTR pwzData = NULL; | ||
30 | SCA_WEBDIR7* pswd; | ||
31 | WCA_WRAPQUERY_HANDLE hWrapQuery = NULL; | ||
32 | |||
33 | hr = WcaBeginUnwrapQuery(&hWrapQuery, ppwzCustomActionData); | ||
34 | ExitOnFailure(hr, "Failed to unwrap query for ScaWebDirsRead7"); | ||
35 | |||
36 | if (0 == WcaGetQueryRecords(hWrapQuery)) | ||
37 | { | ||
38 | WcaLog(LOGMSG_VERBOSE, "Skipping ScaInstallWebDirs7() because IIsWebDir table not present"); | ||
39 | ExitFunction1(hr = S_FALSE); | ||
40 | } | ||
41 | |||
42 | // loop through all the web directories | ||
43 | while (S_OK == (hr = WcaFetchWrappedRecord(hWrapQuery, &hRec))) | ||
44 | { | ||
45 | hr = AddWebDirToList(ppswdList); | ||
46 | ExitOnFailure(hr, "failed to add web dir to list"); | ||
47 | |||
48 | pswd = *ppswdList; | ||
49 | ExitOnNull(pswd, hr, E_INVALIDARG, "No web dir provided"); | ||
50 | |||
51 | // get component install state | ||
52 | hr = WcaGetRecordString(hRec, wdqComponent, &pwzData); | ||
53 | ExitOnFailure(hr, "Failed to get Component for WebDirs"); | ||
54 | hr = ::StringCchCopyW(pswd->wzComponent, countof(pswd->wzComponent), pwzData); | ||
55 | ExitOnFailure(hr, "Failed to copy component string to webdir object"); | ||
56 | |||
57 | hr = WcaGetRecordInteger(hRec, wdqInstalled, (int *)&pswd->isInstalled); | ||
58 | ExitOnFailure(hr, "Failed to get Component installed state for webdir"); | ||
59 | |||
60 | hr = WcaGetRecordInteger(hRec, wdqAction, (int *)&pswd->isAction); | ||
61 | ExitOnFailure(hr, "Failed to get Component action state for webdir"); | ||
62 | |||
63 | hr = WcaGetRecordString(hRec, wdqWeb, &pwzData); | ||
64 | ExitOnFailure(hr, "Failed to get Web for WebDir"); | ||
65 | |||
66 | // get the web key | ||
67 | hr = ScaWebsGetBase7(pswList, pwzData, pswd->wzWebSite, countof(pswd->wzWebSite)); | ||
68 | if (S_FALSE == hr) | ||
69 | { | ||
70 | hr = HRESULT_FROM_WIN32(ERROR_NOT_FOUND); | ||
71 | ExitOnFailure(hr, "Failed to get base of web for WebDir"); | ||
72 | } | ||
73 | ExitOnFailure(hr, "Failed to format webdir root string"); | ||
74 | |||
75 | hr = WcaGetRecordString(hRec, wdqPath, &pwzData); | ||
76 | ExitOnFailure(hr, "Failed to get Path for WebDir"); | ||
77 | |||
78 | hr = ::StringCchCopyW(pswd->wzPath, countof(pswd->wzPath), pwzData); | ||
79 | ExitOnFailure(hr, "Failed to copy path for WebDir"); | ||
80 | |||
81 | // get the directory properties for this web | ||
82 | hr = WcaGetRecordString(hRec, wdqProperties, &pwzData); | ||
83 | ExitOnFailure(hr, "Failed to get security identifier for WebDir"); | ||
84 | if (*pwzData) | ||
85 | { | ||
86 | hr = ScaGetWebDirProperties(pwzData, hUserQuery, hWebDirPropQuery, &pswd->swp); | ||
87 | ExitOnFailure(hr, "Failed to get properties for WebDir"); | ||
88 | |||
89 | pswd->fHasProperties = TRUE; | ||
90 | } | ||
91 | |||
92 | // get the application information for this web directory | ||
93 | hr = WcaGetRecordString(hRec, wdqApplication, &pwzData); | ||
94 | ExitOnFailure(hr, "Failed to get application identifier for WebDir"); | ||
95 | if (*pwzData) | ||
96 | { | ||
97 | hr = ScaGetWebApplication(NULL, pwzData, hWebAppQuery, hWebAppExtQuery, &pswd->swapp); | ||
98 | ExitOnFailure(hr, "Failed to get application for WebDir"); | ||
99 | |||
100 | pswd->fHasApplication = TRUE; | ||
101 | } | ||
102 | } | ||
103 | |||
104 | if (E_NOMOREITEMS == hr) | ||
105 | { | ||
106 | hr = S_OK; | ||
107 | } | ||
108 | ExitOnFailure(hr, "Failure while processing WebDirs"); | ||
109 | |||
110 | LExit: | ||
111 | WcaFinishUnwrapQuery(hWrapQuery); | ||
112 | |||
113 | ReleaseStr(pwzData); | ||
114 | |||
115 | return hr; | ||
116 | } | ||
117 | |||
118 | |||
119 | HRESULT ScaWebDirsInstall7(SCA_WEBDIR7* pswdList, SCA_APPPOOL * psapList) | ||
120 | { | ||
121 | HRESULT hr = S_OK; | ||
122 | SCA_WEBDIR7* pswd = pswdList; | ||
123 | |||
124 | while (pswd) | ||
125 | { | ||
126 | // if we are installing the web site | ||
127 | if (WcaIsInstalling(pswd->isInstalled, pswd->isAction)) | ||
128 | { | ||
129 | hr = ScaWriteConfigID(IIS_WEBDIR); | ||
130 | ExitOnFailure(hr, "Failed to write WebDir ID"); | ||
131 | |||
132 | hr = ScaWriteConfigID(IIS_CREATE); | ||
133 | ExitOnFailure(hr, "Failed to write WebDir action ID"); | ||
134 | |||
135 | hr = ScaWriteConfigString(pswd->wzWebSite); | ||
136 | ExitOnFailure(hr, "Failed to write WebDir site"); | ||
137 | |||
138 | hr = ScaWriteConfigString(pswd->wzPath); | ||
139 | ExitOnFailure(hr, "Failed to write WebDir path"); | ||
140 | |||
141 | // get the security information for this web | ||
142 | if (pswd->fHasProperties) | ||
143 | { | ||
144 | ScaWriteWebDirProperties7(pswd->wzWebSite, pswd->wzPath, &pswd->swp); | ||
145 | ExitOnFailure(hr, "Failed to write properties for WebDir"); | ||
146 | } | ||
147 | |||
148 | // get the application information for this web directory | ||
149 | if (pswd->fHasApplication) | ||
150 | { | ||
151 | hr = ScaWriteWebApplication7(pswd->wzWebSite, pswd->wzPath, &pswd->swapp, psapList); | ||
152 | ExitOnFailure(hr, "Failed to write application for WebDir"); | ||
153 | } | ||
154 | } | ||
155 | |||
156 | pswd = pswd->pswdNext; | ||
157 | } | ||
158 | |||
159 | LExit: | ||
160 | return hr; | ||
161 | } | ||
162 | |||
163 | |||
164 | HRESULT ScaWebDirsUninstall7(SCA_WEBDIR7* pswdList) | ||
165 | { | ||
166 | HRESULT hr = S_OK; | ||
167 | SCA_WEBDIR7* pswd = pswdList; | ||
168 | |||
169 | while (pswd) | ||
170 | { | ||
171 | if (WcaIsUninstalling(pswd->isInstalled, pswd->isAction)) | ||
172 | { | ||
173 | hr = ScaWriteConfigID(IIS_WEBDIR); | ||
174 | ExitOnFailure(hr, "Failed to write WebDir ID"); | ||
175 | |||
176 | hr = ScaWriteConfigID(IIS_DELETE); | ||
177 | ExitOnFailure(hr, "Failed to write WebDir action ID"); | ||
178 | |||
179 | hr = ScaWriteConfigString(pswd->wzWebSite); | ||
180 | ExitOnFailure(hr, "Failed to write WebDir site"); | ||
181 | |||
182 | hr = ScaWriteConfigString(pswd->wzPath); | ||
183 | ExitOnFailure(hr, "Failed to write WebDir path"); | ||
184 | } | ||
185 | |||
186 | pswd = pswd->pswdNext; | ||
187 | } | ||
188 | |||
189 | LExit: | ||
190 | return hr; | ||
191 | } | ||
192 | |||
193 | |||
194 | void ScaWebDirsFreeList7(SCA_WEBDIR7* pswdList) | ||
195 | { | ||
196 | SCA_WEBDIR7* pswdDelete = pswdList; | ||
197 | while (pswdList) | ||
198 | { | ||
199 | pswdDelete = pswdList; | ||
200 | pswdList = pswdList->pswdNext; | ||
201 | |||
202 | MemFree(pswdDelete); | ||
203 | } | ||
204 | } | ||
205 | |||
206 | |||
207 | static HRESULT AddWebDirToList(SCA_WEBDIR7** ppswdList) | ||
208 | { | ||
209 | HRESULT hr = S_OK; | ||
210 | |||
211 | SCA_WEBDIR7* pswd = static_cast<SCA_WEBDIR7*>(MemAlloc(sizeof(SCA_WEBDIR7), TRUE)); | ||
212 | ExitOnNull(pswd, hr, E_OUTOFMEMORY, "failed to allocate element for web dir list"); | ||
213 | |||
214 | pswd->pswdNext = *ppswdList; | ||
215 | *ppswdList = pswd; | ||
216 | |||
217 | LExit: | ||
218 | return hr; | ||
219 | } | ||