diff options
Diffstat (limited to 'src/ext/Iis/ca/scawebappext.cpp')
-rw-r--r-- | src/ext/Iis/ca/scawebappext.cpp | 207 |
1 files changed, 207 insertions, 0 deletions
diff --git a/src/ext/Iis/ca/scawebappext.cpp b/src/ext/Iis/ca/scawebappext.cpp new file mode 100644 index 00000000..cf3b9dd3 --- /dev/null +++ b/src/ext/Iis/ca/scawebappext.cpp | |||
@@ -0,0 +1,207 @@ | |||
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 | enum eWebAppExtensionQuery { wappextqExtension = 1, wappextqVerbs, wappextqExecutable, wappextqAttributes, wappextqApplication }; | ||
6 | |||
7 | // prototypes for private helper functions | ||
8 | static HRESULT NewAppExt( | ||
9 | __out SCA_WEB_APPLICATION_EXTENSION** ppswappext | ||
10 | ); | ||
11 | static SCA_WEB_APPLICATION_EXTENSION* AddAppExtToList( | ||
12 | __in SCA_WEB_APPLICATION_EXTENSION* pswappextList, | ||
13 | __in SCA_WEB_APPLICATION_EXTENSION* pswappext | ||
14 | ); | ||
15 | |||
16 | |||
17 | |||
18 | HRESULT ScaWebAppExtensionsRead( | ||
19 | __in LPCWSTR wzApplication, | ||
20 | __in WCA_WRAPQUERY_HANDLE hWebAppExtQuery, | ||
21 | __inout SCA_WEB_APPLICATION_EXTENSION** ppswappextList | ||
22 | ) | ||
23 | { | ||
24 | HRESULT hr = S_OK; | ||
25 | MSIHANDLE hRec; | ||
26 | |||
27 | SCA_WEB_APPLICATION_EXTENSION* pswappext = NULL; | ||
28 | LPWSTR pwzData = NULL; | ||
29 | |||
30 | // Reset back to the first record | ||
31 | WcaFetchWrappedReset(hWebAppExtQuery); | ||
32 | |||
33 | // get the application extension information | ||
34 | while (S_OK == (hr = WcaFetchWrappedRecordWhereString(hWebAppExtQuery, wappextqApplication, wzApplication, &hRec))) | ||
35 | { | ||
36 | hr = NewAppExt(&pswappext); | ||
37 | ExitOnFailure(hr, "failed to create new web app extension"); | ||
38 | |||
39 | // get the extension | ||
40 | hr = WcaGetRecordString(hRec, wappextqExtension, &pwzData); | ||
41 | ExitOnFailure(hr, "Failed to get Web Application Extension"); | ||
42 | hr = ::StringCchCopyW(pswappext->wzExtension, countof(pswappext->wzExtension), pwzData); | ||
43 | ExitOnFailure(hr, "Failed to copy extension string to webappext object"); | ||
44 | |||
45 | // application extension verbs | ||
46 | hr = WcaGetRecordString(hRec, wappextqVerbs, &pwzData); | ||
47 | ExitOnFailure(hr, "Failed to get Verbs for Application: '%ls'", wzApplication); | ||
48 | hr = ::StringCchCopyW(pswappext->wzVerbs, countof(pswappext->wzVerbs), pwzData); | ||
49 | ExitOnFailure(hr, "Failed to copy verbs string to webappext object"); | ||
50 | |||
51 | // extension executeable | ||
52 | hr = WcaGetRecordString(hRec, wappextqExecutable, &pwzData); | ||
53 | ExitOnFailure(hr, "Failed to get Executable for Application: '%ls'", wzApplication); | ||
54 | hr = ::StringCchCopyW(pswappext->wzExecutable, countof(pswappext->wzExecutable), pwzData); | ||
55 | ExitOnFailure(hr, "Failed to copy executable string to webappext object"); | ||
56 | |||
57 | hr = WcaGetRecordInteger(hRec, wappextqAttributes, &pswappext->iAttributes); | ||
58 | if (S_FALSE == hr) | ||
59 | { | ||
60 | pswappext->iAttributes = 0; | ||
61 | hr = S_OK; | ||
62 | } | ||
63 | ExitOnFailure(hr, "Failed to get App isolation"); | ||
64 | |||
65 | *ppswappextList = AddAppExtToList(*ppswappextList, pswappext); | ||
66 | pswappext = NULL; // set the appext NULL so it doesn't accidentally get freed below | ||
67 | } | ||
68 | |||
69 | if (E_NOMOREITEMS == hr) | ||
70 | { | ||
71 | hr = S_OK; | ||
72 | } | ||
73 | |||
74 | LExit: | ||
75 | // if anything was left over after an error clean it all up | ||
76 | if (pswappext) | ||
77 | { | ||
78 | ScaWebAppExtensionsFreeList(pswappext); | ||
79 | } | ||
80 | |||
81 | ReleaseStr(pwzData); | ||
82 | |||
83 | return hr; | ||
84 | } | ||
85 | |||
86 | |||
87 | |||
88 | HRESULT ScaWebAppExtensionsWrite( | ||
89 | __in IMSAdminBase* piMetabase, | ||
90 | __in LPCWSTR wzRootOfWeb, | ||
91 | __in SCA_WEB_APPLICATION_EXTENSION* pswappextList | ||
92 | ) | ||
93 | { | ||
94 | HRESULT hr = S_OK; | ||
95 | |||
96 | LPWSTR wzAppExt = NULL; | ||
97 | DWORD cchAppExt; | ||
98 | WCHAR wzAppExtension[1024]; | ||
99 | WCHAR wzAppExtensions[65536]; | ||
100 | SCA_WEB_APPLICATION_EXTENSION* pswappext = NULL; | ||
101 | |||
102 | if (!pswappextList) | ||
103 | { | ||
104 | ExitFunction(); | ||
105 | } | ||
106 | |||
107 | ::ZeroMemory(wzAppExtensions, sizeof(wzAppExtensions)); | ||
108 | wzAppExt = wzAppExtensions; | ||
109 | cchAppExt = countof(wzAppExtensions); | ||
110 | pswappext = pswappextList; | ||
111 | |||
112 | while (pswappext) | ||
113 | { | ||
114 | // if all (represented by "*" or blank) | ||
115 | if (0 == lstrcmpW(pswappext->wzExtension, L"*") || 0 == lstrlenW(pswappext->wzExtension)) | ||
116 | { | ||
117 | hr = ::StringCchPrintfW(wzAppExtension, countof(wzAppExtension), L"*,%s,%d", pswappext->wzExecutable, pswappext->iAttributes); | ||
118 | ExitOnFailure(hr, "Failed to format *,executable,attributes string"); | ||
119 | } | ||
120 | else | ||
121 | { | ||
122 | hr = ::StringCchPrintfW(wzAppExtension, countof(wzAppExtension), L".%s,%s,%d", pswappext->wzExtension, pswappext->wzExecutable, pswappext->iAttributes); | ||
123 | ExitOnFailure(hr, "Failed to format extension,executable,attributes string"); | ||
124 | } | ||
125 | |||
126 | // if verbs were specified and not the keyword "all" | ||
127 | if (pswappext->wzVerbs[0] && CSTR_EQUAL != CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, pswappext->wzVerbs, -1, L"all", -1)) | ||
128 | { | ||
129 | hr = ::StringCchCatW(wzAppExtension, countof(wzAppExtension), L","); | ||
130 | ExitOnFailure(hr, "Failed to concatenate comma to app extension string"); | ||
131 | hr = ::StringCchCatW(wzAppExtension, countof(wzAppExtension), pswappext->wzVerbs); | ||
132 | ExitOnFailure(hr, "Failed to concatenate verb to app extension string"); | ||
133 | } | ||
134 | |||
135 | hr = ::StringCchCopyW(wzAppExt, cchAppExt, wzAppExtension); | ||
136 | ExitOnFailure(hr, "Failed to copy app extension string"); | ||
137 | wzAppExt += lstrlenW(wzAppExtension) + 1; | ||
138 | cchAppExt -= lstrlenW(wzAppExtension) + 1; | ||
139 | pswappext = pswappext->pswappextNext; | ||
140 | } | ||
141 | |||
142 | if (*wzAppExtensions) | ||
143 | { | ||
144 | hr = ScaWriteMetabaseValue(piMetabase, wzRootOfWeb, NULL, MD_SCRIPT_MAPS, METADATA_INHERIT, IIS_MD_UT_FILE, MULTISZ_METADATA, wzAppExtensions); | ||
145 | ExitOnFailure(hr, "Failed to write AppExtension: '%ls'", wzAppExtension); | ||
146 | } | ||
147 | |||
148 | LExit: | ||
149 | return hr; | ||
150 | } | ||
151 | |||
152 | |||
153 | void ScaWebAppExtensionsFreeList( | ||
154 | __in SCA_WEB_APPLICATION_EXTENSION* pswappextList | ||
155 | ) | ||
156 | { | ||
157 | SCA_WEB_APPLICATION_EXTENSION* pswappextDelete = pswappextList; | ||
158 | while (pswappextList) | ||
159 | { | ||
160 | pswappextDelete = pswappextList; | ||
161 | pswappextList = pswappextList->pswappextNext; | ||
162 | |||
163 | MemFree(pswappextDelete); | ||
164 | } | ||
165 | } | ||
166 | |||
167 | |||
168 | |||
169 | // private helper functions | ||
170 | |||
171 | static HRESULT NewAppExt( | ||
172 | __out SCA_WEB_APPLICATION_EXTENSION** ppswappext | ||
173 | ) | ||
174 | { | ||
175 | HRESULT hr = S_OK; | ||
176 | SCA_WEB_APPLICATION_EXTENSION* pswappext = static_cast<SCA_WEB_APPLICATION_EXTENSION*>(MemAlloc(sizeof(SCA_WEB_APPLICATION_EXTENSION), TRUE)); | ||
177 | ExitOnNull(pswappext, hr, E_OUTOFMEMORY, "failed to allocate memory for new web app ext element"); | ||
178 | |||
179 | *ppswappext = pswappext; | ||
180 | |||
181 | LExit: | ||
182 | return hr; | ||
183 | } | ||
184 | |||
185 | |||
186 | static SCA_WEB_APPLICATION_EXTENSION* AddAppExtToList( | ||
187 | __in SCA_WEB_APPLICATION_EXTENSION* pswappextList, | ||
188 | __in SCA_WEB_APPLICATION_EXTENSION* pswappext | ||
189 | ) | ||
190 | { | ||
191 | if (pswappextList) | ||
192 | { | ||
193 | SCA_WEB_APPLICATION_EXTENSION* pswappextT = pswappextList; | ||
194 | while (pswappextT->pswappextNext) | ||
195 | { | ||
196 | pswappextT = pswappextT->pswappextNext; | ||
197 | } | ||
198 | |||
199 | pswappextT->pswappextNext = pswappext; | ||
200 | } | ||
201 | else | ||
202 | { | ||
203 | pswappextList = pswappext; | ||
204 | } | ||
205 | |||
206 | return pswappextList; | ||
207 | } | ||