aboutsummaryrefslogtreecommitdiff
path: root/src/ext/Iis/ca/scawebprop.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ext/Iis/ca/scawebprop.cpp')
-rw-r--r--src/ext/Iis/ca/scawebprop.cpp301
1 files changed, 301 insertions, 0 deletions
diff --git a/src/ext/Iis/ca/scawebprop.cpp b/src/ext/Iis/ca/scawebprop.cpp
new file mode 100644
index 00000000..b5e38467
--- /dev/null
+++ b/src/ext/Iis/ca/scawebprop.cpp
@@ -0,0 +1,301 @@
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
6enum eWebDirPropertiesQuery { wpqProperties = 1, wpqAccess, wpqAuthorization, wpqUser, wpqControlledPassword, wpqLogVisits, wpqIndex, wpqDefaultDoc, wpqAspDetailedError, wpqHttpExp, wpqCCMaxAge, wpqCCCustom, wpqNoCustomError, wpqAccessSSLFlags, wpqAuthenticationProviders };
7
8HRESULT ScaGetWebDirProperties(
9 __in LPCWSTR wzProperties,
10 __in WCA_WRAPQUERY_HANDLE hUserQuery,
11 __in WCA_WRAPQUERY_HANDLE hWebDirPropQuery,
12 __inout SCA_WEB_PROPERTIES* pswp
13 )
14{
15 Assert(*wzProperties && pswp);
16
17 HRESULT hr = S_OK;
18 MSIHANDLE hRec;
19 LPWSTR pwzData = NULL;
20
21 ExitOnNull(wzProperties, hr, E_INVALIDARG, "Failed to get web directory properties because no properties were provided to get");
22
23 WcaFetchWrappedReset(hWebDirPropQuery);
24
25 hr = WcaFetchWrappedRecordWhereString(hWebDirPropQuery, 1, wzProperties, &hRec);
26 if (S_OK == hr)
27 {
28 hr = WcaGetRecordString(hRec, wpqProperties, &pwzData);
29 ExitOnFailure(hr, "Failed to get IIsWebDirProperties.DirProperties");
30 hr = ::StringCchCopyW(pswp->wzKey, countof(pswp->wzKey), pwzData);
31 ExitOnFailure(hr, "Failed to copy key string to webdirproperties object");
32
33 Assert(0 == lstrcmpW(pswp->wzKey, wzProperties));
34
35 hr = WcaGetRecordInteger(hRec, wpqAccess, &pswp->iAccess);
36 ExitOnFailure(hr, "Failed to get access value");
37
38 hr = WcaGetRecordInteger(hRec, wpqAuthorization, &pswp->iAuthorization);
39 ExitOnFailure(hr, "Failed to get authorization value");
40
41 // if allow anonymous users
42 if (S_OK == hr && pswp->iAuthorization & 1)
43 {
44 // if there is an anonymous user specified
45 hr = WcaGetRecordString(hRec, wpqUser, &pwzData);
46 ExitOnFailure(hr, "Failed to get AnonymousUser_");
47 if (pwzData && *pwzData)
48 {
49 hr = WcaGetRecordInteger(hRec, wpqControlledPassword, &pswp->fIIsControlledPassword);
50 ExitOnFailure(hr, "Failed to get IIsControlledPassword");
51 if (S_FALSE == hr)
52 {
53 pswp->fIIsControlledPassword = FALSE;
54 hr = S_OK;
55 }
56
57 hr = ScaGetUserDeferred(pwzData, hUserQuery, &pswp->scau);
58 ExitOnFailure(hr, "Failed to get User information for Web");
59
60 pswp->fHasUser = TRUE;
61 }
62 else
63 pswp->fHasUser = FALSE;
64 }
65
66 hr = WcaGetRecordInteger(hRec, wpqLogVisits, &pswp->fLogVisits);
67 ExitOnFailure(hr, "Failed to get IIsWebDirProperties.LogVisits");
68
69 hr = WcaGetRecordInteger(hRec, wpqIndex, &pswp->fIndex);
70 ExitOnFailure(hr, "Failed to get IIsWebDirProperties.Index");
71
72 hr = WcaGetRecordString(hRec, wpqDefaultDoc, &pwzData);
73 ExitOnFailure(hr, "Failed to get IIsWebDirProperties.DefaultDoc");
74 if (pwzData && *pwzData)
75 {
76 pswp->fHasDefaultDoc = TRUE;
77 if (0 == lstrcmpW(L"-", pwzData)) // remove any existing default documents by setting them blank
78 {
79 pswp->wzDefaultDoc[0] = L'\0';
80 }
81 else // set the default documents
82 {
83 hr = ::StringCchCopyW(pswp->wzDefaultDoc, countof(pswp->wzDefaultDoc), pwzData);
84 ExitOnFailure(hr, "Failed to copy default document string to webdirproperties object");
85 }
86 }
87 else
88 {
89 pswp->fHasDefaultDoc = FALSE;
90 }
91
92 hr = WcaGetRecordInteger(hRec, wpqAspDetailedError, &pswp->fAspDetailedError);
93 ExitOnFailure(hr, "Failed to get IIsWebDirProperties.AspDetailedError");
94
95 hr = WcaGetRecordString(hRec, wpqHttpExp, &pwzData);
96 ExitOnFailure(hr, "Failed to get IIsWebDirProperties.HttpExp");
97 if (pwzData && *pwzData)
98 {
99 pswp->fHasHttpExp = TRUE;
100 if (0 == lstrcmpW(L"-", pwzData)) // remove any existing default expiration settings by setting them blank
101 {
102 pswp->wzHttpExp[0] = L'\0';
103 }
104 else // set the expiration setting
105 {
106 hr = ::StringCchCopyW(pswp->wzHttpExp, countof(pswp->wzHttpExp), pwzData);
107 ExitOnFailure(hr, "Failed to copy http expiration string to webdirproperties object");
108 }
109 }
110 else
111 {
112 pswp->fHasHttpExp = FALSE;
113 }
114
115 hr = WcaGetRecordInteger(hRec, wpqCCMaxAge, &pswp->iCacheControlMaxAge);
116 ExitOnFailure(hr, "failed to get IIsWebDirProperties.CacheControlMaxAge");
117
118 hr = WcaGetRecordString(hRec, wpqCCCustom, &pwzData);
119 ExitOnFailure(hr, "Failed to get IIsWebDirProperties.CacheControlCustom");
120 if (pwzData && *pwzData)
121 {
122 pswp->fHasCacheControlCustom = TRUE;
123 if (0 == lstrcmpW(L"-", pwzData)) // remove any existing default cache control custom settings by setting them blank
124 {
125 pswp->wzCacheControlCustom[0] = L'\0';
126 }
127 else // set the custom cache control setting
128 {
129 hr = ::StringCchCopyW(pswp->wzCacheControlCustom, countof(pswp->wzCacheControlCustom), pwzData);
130 ExitOnFailure(hr, "Failed to copy cache control custom settings to webdirproperites object");
131 }
132 }
133 else
134 {
135 pswp->fHasCacheControlCustom = FALSE;
136 }
137
138 hr = WcaGetRecordInteger(hRec, wpqNoCustomError, &pswp->fNoCustomError);
139 ExitOnFailure(hr, "failed to get IIsWebDirProperties.NoCustomError");
140 if (MSI_NULL_INTEGER == pswp->fNoCustomError)
141 pswp->fNoCustomError = FALSE;
142
143 hr = WcaGetRecordInteger(hRec, wpqAccessSSLFlags, &pswp->iAccessSSLFlags);
144 ExitOnFailure(hr, "failed to get IIsWebDirProperties.AccessSSLFlags");
145
146 hr = WcaGetRecordString(hRec, wpqAuthenticationProviders, &pwzData);
147 ExitOnFailure(hr, "Failed to get IIsWebDirProperties.AuthenticationProviders");
148 if (pwzData && *pwzData)
149 {
150 hr = ::StringCchCopyW(pswp->wzAuthenticationProviders, countof(pswp->wzAuthenticationProviders), pwzData);
151 ExitOnFailure(hr, "Failed to copy authentication providers string to webdirproperties object");
152 }
153 else
154 {
155 pswp->wzAuthenticationProviders[0] = L'\0';
156 }
157 }
158 else if (E_NOMOREITEMS == hr)
159 {
160 WcaLog(LOGMSG_STANDARD, "Error: Cannot locate IIsWebDirProperties.DirProperties='%ls'", wzProperties);
161 hr = E_FAIL;
162 }
163 else
164 {
165 ExitOnFailure(hr, "Error getting appropriate webdirproperty");
166 }
167
168 // Let's check that there isn't more than one record found - if there is, throw an assert like WcaFetchSingleRecord() would
169 HRESULT hrTemp = WcaFetchWrappedRecordWhereString(hWebDirPropQuery, 1, wzProperties, &hRec);
170 if (SUCCEEDED(hrTemp))
171 {
172 AssertSz(E_NOMOREITEMS == hrTemp, "ScaGetWebDirProperties found more than one record");
173 }
174
175LExit:
176 ReleaseStr(pwzData);
177
178 return hr;
179}
180
181
182HRESULT ScaWriteWebDirProperties(
183 __in IMSAdminBase* piMetabase,
184 __in LPCWSTR wzRootOfWeb,
185 __inout SCA_WEB_PROPERTIES* pswp
186 )
187{
188 HRESULT hr = S_OK;
189 DWORD dw = 0;
190 WCHAR wz[METADATA_MAX_NAME_LEN + 1];
191
192 // write the access permissions to the metabase
193 if (MSI_NULL_INTEGER != pswp->iAccess)
194 {
195 hr = ScaWriteMetabaseValue(piMetabase, wzRootOfWeb, NULL, MD_ACCESS_PERM, METADATA_INHERIT, IIS_MD_UT_FILE, DWORD_METADATA, (LPVOID)((DWORD_PTR)pswp->iAccess));
196 ExitOnFailure(hr, "Failed to write access permissions for Web");
197 }
198
199 if (MSI_NULL_INTEGER != pswp->iAuthorization)
200 {
201 hr = ScaWriteMetabaseValue(piMetabase, wzRootOfWeb, NULL, MD_AUTHORIZATION, METADATA_INHERIT, IIS_MD_UT_FILE, DWORD_METADATA, (LPVOID)((DWORD_PTR)pswp->iAuthorization));
202 ExitOnFailure(hr, "Failed to write authorization for Web");
203 }
204
205 if (pswp->fHasUser)
206 {
207 Assert(pswp->scau.wzName);
208 // write the user name
209 if (*pswp->scau.wzDomain)
210 {
211 hr = ::StringCchPrintfW(wz, countof(wz), L"%s\\%s", pswp->scau.wzDomain, pswp->scau.wzName);
212 ExitOnFailure(hr, "Failed to format domain\\username string");
213 }
214 else
215 {
216 hr = ::StringCchCopyW(wz, countof(wz), pswp->scau.wzName);
217 ExitOnFailure(hr, "Failed to copy user name");
218 }
219 hr = ScaWriteMetabaseValue(piMetabase, wzRootOfWeb, NULL, MD_ANONYMOUS_USER_NAME, METADATA_INHERIT, IIS_MD_UT_FILE, STRING_METADATA, (LPVOID)wz);
220 ExitOnFailure(hr, "Failed to write anonymous user name for Web");
221
222 // write the password
223 hr = ScaWriteMetabaseValue(piMetabase, wzRootOfWeb, NULL, MD_ANONYMOUS_PWD, METADATA_INHERIT | METADATA_SECURE, IIS_MD_UT_FILE, STRING_METADATA, (LPVOID)pswp->scau.wzPassword);
224 ExitOnFailure(hr, "Failed to write anonymous user password for Web");
225
226 // store whether IIs controls password
227 dw = (pswp->fIIsControlledPassword) ? TRUE : FALSE;
228 hr = ScaWriteMetabaseValue(piMetabase, wzRootOfWeb, NULL, MD_ANONYMOUS_USE_SUBAUTH, METADATA_INHERIT, IIS_MD_UT_FILE, DWORD_METADATA, (LPVOID)((DWORD_PTR)dw));
229 ExitOnFailure(hr, "Failed to write if IIs controls user password for Web");
230 }
231
232 if (MSI_NULL_INTEGER != pswp->fLogVisits)
233 {
234 // The sense of this boolean value is reversed - it is "don't log", not "log visits."
235 dw = (pswp->fLogVisits) ? FALSE : TRUE;
236 hr = ScaWriteMetabaseValue(piMetabase, wzRootOfWeb, NULL, MD_DONT_LOG, METADATA_INHERIT, IIS_MD_UT_FILE, DWORD_METADATA, (LPVOID)((DWORD_PTR)dw));
237 ExitOnFailure(hr, "Failed to write authorization for Web");
238 }
239
240 if (MSI_NULL_INTEGER != pswp->fIndex)
241 {
242 dw = (pswp->fIndex) ? TRUE : FALSE;
243 hr = ScaWriteMetabaseValue(piMetabase, wzRootOfWeb, NULL, MD_IS_CONTENT_INDEXED, METADATA_INHERIT, IIS_MD_UT_FILE, DWORD_METADATA, (LPVOID)((DWORD_PTR)dw));
244 ExitOnFailure(hr, "Failed to write authorization for Web");
245 }
246
247 if (pswp->fHasDefaultDoc)
248 {
249 hr = ScaWriteMetabaseValue(piMetabase, wzRootOfWeb, NULL, MD_DEFAULT_LOAD_FILE, METADATA_INHERIT, IIS_MD_UT_FILE, STRING_METADATA, (LPVOID)pswp->wzDefaultDoc);
250 ExitOnFailure(hr, "Failed to write default documents for Web");
251 }
252
253 if (MSI_NULL_INTEGER != pswp->fAspDetailedError)
254 {
255 dw = (pswp->fAspDetailedError) ? TRUE : FALSE;
256 hr = ScaWriteMetabaseValue(piMetabase, wzRootOfWeb, NULL, MD_ASP_SCRIPTERRORSSENTTOBROWSER, METADATA_INHERIT, ASP_MD_UT_APP, DWORD_METADATA, (LPVOID)((DWORD_PTR)dw));
257 ExitOnFailure(hr, "Failed to write ASP script error for Web");
258 }
259
260 if (pswp->fHasHttpExp)
261 {
262 hr = ScaWriteMetabaseValue(piMetabase, wzRootOfWeb, NULL, MD_HTTP_EXPIRES, METADATA_INHERIT, IIS_MD_UT_FILE, STRING_METADATA, (LPVOID)pswp->wzHttpExp);
263 ExitOnFailure(hr, "Failed to write HTTP Expiration for Web");
264 }
265
266 if (MSI_NULL_INTEGER != pswp->iCacheControlMaxAge)
267 {
268 hr = ScaWriteMetabaseValue(piMetabase, wzRootOfWeb, NULL, MD_CC_MAX_AGE, METADATA_INHERIT, IIS_MD_UT_FILE, DWORD_METADATA, (LPVOID)((DWORD_PTR)pswp->iCacheControlMaxAge));
269 ExitOnFailure(hr, "Failed to write Cache Control Max Age for Web");
270 }
271
272 if (pswp->fHasCacheControlCustom)
273 {
274 hr = ScaWriteMetabaseValue(piMetabase, wzRootOfWeb, NULL, MD_CC_OTHER, METADATA_INHERIT, IIS_MD_UT_FILE, STRING_METADATA, (LPVOID)pswp->wzCacheControlCustom);
275 ExitOnFailure(hr, "Failed to write Cache Control Custom for Web");
276 }
277
278 if (pswp->fNoCustomError)
279 {
280 memset(wz, 0, sizeof(wz));
281 hr = ScaWriteMetabaseValue(piMetabase, wzRootOfWeb, NULL, MD_CUSTOM_ERROR, METADATA_INHERIT, IIS_MD_UT_FILE, MULTISZ_METADATA, wz);
282 ExitOnFailure(hr, "Failed to write Custom Error for Web");
283 }
284
285 if (MSI_NULL_INTEGER != pswp->iAccessSSLFlags)
286 {
287 hr = ScaWriteMetabaseValue(piMetabase, wzRootOfWeb, NULL, MD_SSL_ACCESS_PERM, METADATA_INHERIT, IIS_MD_UT_FILE, DWORD_METADATA, (LPVOID)((DWORD_PTR)pswp->iAccessSSLFlags));
288 ExitOnFailure(hr, "Failed to write AccessSSLFlags for Web");
289 }
290
291 if (*pswp->wzAuthenticationProviders)
292 {
293 hr = ::StringCchCopyW(wz, countof(wz), pswp->wzAuthenticationProviders);
294 ExitOnFailure(hr, "Failed to copy authentication providers string");
295 hr = ScaWriteMetabaseValue(piMetabase, wzRootOfWeb, NULL, MD_NTAUTHENTICATION_PROVIDERS, METADATA_INHERIT, IIS_MD_UT_FILE, STRING_METADATA, (LPVOID)wz);
296 ExitOnFailure(hr, "Failed to write AuthenticationProviders for Web");
297 }
298
299LExit:
300 return hr;
301}