aboutsummaryrefslogtreecommitdiff
path: root/src/ext/Iis/ca/scaexecIIS7.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ext/Iis/ca/scaexecIIS7.cpp')
-rw-r--r--src/ext/Iis/ca/scaexecIIS7.cpp4205
1 files changed, 4205 insertions, 0 deletions
diff --git a/src/ext/Iis/ca/scaexecIIS7.cpp b/src/ext/Iis/ca/scaexecIIS7.cpp
new file mode 100644
index 00000000..108007a1
--- /dev/null
+++ b/src/ext/Iis/ca/scaexecIIS7.cpp
@@ -0,0 +1,4205 @@
1#pragma once
2// 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.
3
4
5#include "precomp.h"
6
7//local CAData action functions
8HRESULT IIS7Site(
9 __inout LPWSTR *ppwzCustomActionData,
10 __in IAppHostWritableAdminManager *pAdminMgr
11 );
12
13HRESULT IIS7Application(
14 __inout LPWSTR *ppwzCustomActionData,
15 __in IAppHostWritableAdminManager *pAdminMgr
16 );
17HRESULT IIS7VDir(
18 __inout LPWSTR *ppwzCustomActionData,
19 __in IAppHostWritableAdminManager *pAdminMgr
20 );
21HRESULT IIS7Binding(
22 __inout LPWSTR *ppwzCustomActionData,
23 __in IAppHostWritableAdminManager *pAdminMgr
24 );
25HRESULT IIS7AppPool(
26 __inout LPWSTR *ppwzCustomActionData,
27 __in IAppHostWritableAdminManager *pAdminMgr
28 );
29HRESULT IIS7AppExtension(
30 __inout LPWSTR *ppwzCustomActionData,
31 __in IAppHostWritableAdminManager *pAdminMgr
32 );
33HRESULT IIS7MimeMap(
34 __inout LPWSTR *ppwzCustomActionData,
35 __in IAppHostWritableAdminManager *pAdminMgr
36 );
37HRESULT IIS7DirProperties(
38 __inout LPWSTR *ppwzCustomActionData,
39 __in IAppHostWritableAdminManager *pAdminMgr
40 );
41HRESULT IIS7WebLog(
42 __inout LPWSTR *ppwzCustomActionData,
43 __in IAppHostWritableAdminManager *pAdminMgr
44 );
45HRESULT IIS7FilterGlobal(
46 __inout LPWSTR *ppwzCustomActionData,
47 __in IAppHostWritableAdminManager *pAdminMgr
48 );
49HRESULT IIS7FilterSite(
50 __inout LPWSTR *ppwzCustomActionData,
51 __in IAppHostWritableAdminManager *pAdminMgr
52 );
53HRESULT IIS7HttpHeader(
54 __inout LPWSTR *ppwzCustomActionData,
55 __in IAppHostWritableAdminManager *pAdminMgr
56 );
57HRESULT IIS7WebError(
58 __inout LPWSTR *ppwzCustomActionData,
59 __in IAppHostWritableAdminManager *pAdminMgr
60 );
61HRESULT IIS7WebSvcExt(
62 __inout LPWSTR *ppwzCustomActionData,
63 __in IAppHostWritableAdminManager *pAdminMgr
64 );
65HRESULT IIS7WebProperty(
66 __inout LPWSTR *ppwzCustomActionData,
67 __in IAppHostWritableAdminManager *pAdminMgr
68 );
69HRESULT IIS7WebDir(
70 __inout LPWSTR *ppwzCustomActionData,
71 __in IAppHostWritableAdminManager *pAdminMgr
72 );
73HRESULT IIS7AspProperty(
74 __inout LPWSTR *ppwzCustomActionData,
75 __in IAppHostWritableAdminManager *pAdminMgr
76 );
77HRESULT IIS7SslBinding(
78 __inout LPWSTR *ppwzCustomActionData,
79 __in IAppHostWritableAdminManager *pAdminMgr
80 );
81//local helper functions
82
83static HRESULT GetNextAvailableSiteId(
84 IAppHostWritableAdminManager *pAdminMgr,
85 DWORD *plSiteId
86 );
87static HRESULT GetSiteElement(
88 IAppHostWritableAdminManager *pAdminMgr,
89 LPCWSTR swSiteName,
90 IAppHostElement **pSiteElement,
91 BOOL* fFound
92 );
93static HRESULT GetApplicationElement(
94 IAppHostElement *pSiteElement,
95 LPCWSTR swAppPath,
96 IAppHostElement **pAppElement,
97 BOOL* fFound
98 );
99static HRESULT GetApplicationElementForVDir(
100 IAppHostElement *pSiteElement,
101 LPCWSTR swVDirPath,
102 IAppHostElement **ppAppElement,
103 LPCWSTR *ppwzVDirSubPath,
104 BOOL* fFound
105 );
106
107static HRESULT CreateApplication(
108 IAppHostElement *pSiteElement,
109 LPCWSTR swAppPath,
110 IAppHostElement **pAppElement
111 );
112static HRESULT DeleteApplication(
113 IAppHostElement *pSiteElement,
114 LPCWSTR swAppPath
115 );
116
117static HRESULT SetAppPool(
118 IAppHostElement *pAppElementpAppElement,
119 LPCWSTR pwzAppPool
120 );
121static HRESULT CreateVdir(
122 IAppHostElement *pAppElement,
123 LPCWSTR pwzVDirPath,
124 LPCWSTR pwzVDirPhyDir
125 );
126static HRESULT DeleteVdir(
127 IAppHostElement *pAppElement,
128 LPCWSTR pwzVDirPath
129 );
130
131static HRESULT CreateBinding(
132 IAppHostElement *pSiteElem,
133 LPCWSTR pwzProtocol,
134 LPCWSTR pwzInfo
135 );
136static HRESULT DeleteBinding(
137 IAppHostElement *pSiteElem,
138 LPCWSTR pwzProtocol,
139 LPCWSTR pwzInfo
140 );
141
142static HRESULT CreateSslBinding(
143 IAppHostElement *pSiteElem,
144 LPCWSTR pwzStoreName,
145 LPCWSTR pwzEncodedCertificateHash
146 );
147static HRESULT DeleteSslBinding(
148 IAppHostElement *pSiteElem,
149 LPCWSTR pwzStoreName,
150 LPCWSTR pwzEncodedCertificateHash
151 );
152
153static HRESULT CreateSite(
154 IAppHostElementCollection *pAdminMgr,
155 LPCWSTR swSiteName,
156 IAppHostElement **pSiteElement
157 );
158
159static HRESULT DeleteAppPool(
160 IAppHostWritableAdminManager *pAdminMgr,
161 LPCWSTR swAppPoolName
162 );
163static HRESULT CreateAppPool(
164 __inout LPWSTR *ppwzCustomActionData,
165 IAppHostWritableAdminManager *pAdminMgr,
166 LPCWSTR swAppPoolName
167 );
168
169static HRESULT SetDirPropAuthentications(
170 IAppHostWritableAdminManager *pAdminMgr,
171 LPCWSTR wcConfigPath,
172 DWORD dwData
173 );
174static HRESULT SetDirPropAuthProvider(
175 IAppHostWritableAdminManager *pAdminMgr,
176 LPCWSTR wszConfigPath,
177 __in LPWSTR wszData
178 );
179static HRESULT SetDirPropDefDoc(
180 IAppHostWritableAdminManager *pAdminMgr,
181 LPCWSTR wszConfigPath,
182 __in LPWSTR wszData
183 );
184
185static HRESULT ClearLocationTag(
186 IAppHostWritableAdminManager *pAdminMgr,
187 LPCWSTR swLocationPath
188 );
189
190static HRESULT CreateWebLog(
191 IAppHostElement *pSiteElem,
192 LPCWSTR pwzFormat
193 );
194
195static HRESULT CreateGlobalFilter(
196 __inout LPWSTR *ppwzCustomActionData,
197 IAppHostElement *pSection
198 );
199static HRESULT DeleteGlobalFilter(
200 __inout LPWSTR *ppwzCustomActionData,
201 IAppHostElement *pSection
202 );
203
204static HRESULT CreateSiteFilter(
205 __inout LPWSTR *ppwzCustomActionData,
206 IAppHostWritableAdminManager *pAdminMgr
207 );
208static HRESULT DeleteSiteFilter(
209 __inout LPWSTR *ppwzCustomActionData,
210 IAppHostWritableAdminManager *pAdminMgr
211 );
212
213static HRESULT DeleteCollectionElement(
214 __in IAppHostElementCollection *pCollection,
215 __in LPCWSTR pwzElementName,
216 __in LPCWSTR pwzAttributeName,
217 __in LPCWSTR pwzAttributeValue
218 );
219
220struct SCA_WEB_ERROR_SERVER
221{
222 int iErrorCode;
223 int iSubCode;
224 WCHAR wzFile[MAX_PATH];
225 WCHAR wzLangPath[MAX_PATH];
226 int iResponseMode;
227 SCA_WEB_ERROR_SERVER *psweNext;
228};
229static HRESULT AddWebErrorToList(
230 SCA_WEB_ERROR_SERVER** ppsweList
231 );
232static void ScaWebErrorFreeList7(
233 SCA_WEB_ERROR_SERVER *psweList
234 );
235static HRESULT PopulateHttpErrors(
236 IAppHostElement *pSection,
237 SCA_WEB_ERROR_SERVER **psweList
238 );
239static HRESULT GetErrorFromList(
240 const SCA_WEB_ERROR_SERVER & we,
241 SCA_WEB_ERROR_SERVER **ppsweList,
242 SCA_WEB_ERROR_SERVER **pswe,
243 BOOL *fFound
244 );
245
246static void ConvSecToHMS(
247 int Sec,
248 __out_ecount(cchDest) LPWSTR wcTime,
249 size_t cchDest
250 );
251static void ConvSecToDHMS(
252 unsigned int Sec,
253 __out_ecount(cchDest) LPWSTR wcTime,
254 size_t cchDest
255 );
256
257////////////////////////////////////////////////////////////////////
258// ScopeBSTR: Local helper class to construct & free BSTR from LPWSTR
259//
260/////////////////////////////////////////////////////////////////////
261class ScopeBSTR
262{
263public:
264 BSTR m_str;
265
266 ScopeBSTR()
267 {
268 m_str = NULL;
269 }
270
271 ScopeBSTR( __in LPCWSTR pSrc)
272 {
273 if (pSrc == NULL)
274 {
275 m_str = NULL;
276 }
277 else
278 {
279 m_str = ::SysAllocString(pSrc);
280
281 }
282 }
283
284 ~ScopeBSTR()
285 {
286 ::SysFreeString(m_str);
287 }
288
289 operator BSTR()
290 {
291 return m_str;
292 }
293};
294
295
296/********************************************************************
297 IIS7ConfigChanges - Start of IIS7 config changes
298
299 *******************************************************************/
300HRESULT IIS7ConfigChanges(MSIHANDLE /*hInstall*/, __inout LPWSTR pwzData)
301{
302 HRESULT hr = S_OK;
303 BOOL fInitializedCom = FALSE;
304
305 IAppHostWritableAdminManager *pAdminMgr = NULL;
306
307 LPWSTR pwz = NULL;
308 LPWSTR pwzLast = NULL;
309 LPWSTR pwzBackup = NULL;
310 DWORD cchData = lstrlenW(pwzData);
311 int iAction = -1;
312
313 int iRetryCount = 0;
314
315 hr = ::CoInitialize(NULL);
316 ExitOnFailure(hr, "Failed to initialize COM");
317 fInitializedCom = TRUE;
318
319 pwz = pwzLast = pwzData;
320
321 hr = StrAllocString(&pwzBackup, pwz, 0);
322 ExitOnFailure(hr, "Failed to backup custom action data");
323
324 while (S_OK == (hr = WcaReadIntegerFromCaData(&pwz, &iAction)))
325 {
326 if (NULL == pAdminMgr)
327 {
328 hr = ::CoCreateInstance( __uuidof(AppHostWritableAdminManager),
329 NULL,
330 CLSCTX_INPROC_SERVER,
331 __uuidof(IAppHostWritableAdminManager),
332 reinterpret_cast<void**> (&pAdminMgr));
333 ExitOnFailure(hr , "Failed to open AppHostWritableAdminManager to configure IIS7");
334 }
335
336 switch (iAction)
337 {
338 case IIS_SITE:
339 {
340#pragma prefast(suppress:26010, "This is a prefast issue - pAdminMgr is correctly allocated")
341 hr = IIS7Site(&pwz, pAdminMgr);
342 ExitOnFailure(hr, "Failed to configure IIS site.");
343 break;
344 }
345 case IIS_APPLICATION:
346 {
347#pragma prefast(suppress:26010, "This is a prefast issue - pAdminMgr is correctly allocated")
348 hr = IIS7Application(&pwz, pAdminMgr);
349 ExitOnFailure(hr, "Failed to configure IIS application.");
350 break;
351 }
352 case IIS_VDIR:
353 {
354#pragma prefast(suppress:26010, "This is a prefast issue - pAdminMgr is correctly allocated")
355 hr = IIS7VDir(&pwz, pAdminMgr);
356 ExitOnFailure(hr, "Failed to configure IIS VDir.");
357 break;
358 }
359 case IIS_BINDING:
360 {
361#pragma prefast(suppress:26010, "This is a prefast issue - pAdminMgr is correctly allocated")
362 hr = IIS7Binding(&pwz, pAdminMgr);
363 ExitOnFailure(hr, "Failed to configure IIS site binding.");
364 break;
365 }
366 case IIS_APPPOOL:
367 {
368#pragma prefast(suppress:26010, "This is a prefast issue - pAdminMgr is correctly allocated")
369 hr = IIS7AppPool(&pwz, pAdminMgr);
370 ExitOnFailure(hr, "Failed to configure IIS appPool.");
371 break;
372 }
373 case IIS_APPEXT_BEGIN:
374 {
375#pragma prefast(suppress:26010, "This is a prefast issue - pAdminMgr is correctly allocated")
376 hr = IIS7AppExtension(&pwz, pAdminMgr);
377 ExitOnFailure(hr, "Failed to configure IIS AppExtension.");
378 break;
379 }
380 case IIS_MIMEMAP_BEGIN:
381 {
382#pragma prefast(suppress:26010, "This is a prefast issue - pAdminMgr is correctly allocated")
383 hr = IIS7MimeMap(&pwz, pAdminMgr);
384 ExitOnFailure(hr, "Failed to configure IIS MimeMap.");
385 break;
386 }
387 case IIS_DIRPROP_BEGIN:
388 {
389#pragma prefast(suppress:26010, "This is a prefast issue - pAdminMgr is correctly allocated")
390 hr = IIS7DirProperties(&pwz, pAdminMgr);
391 ExitOnFailure(hr, "Failed to configure IIS DirProperties.");
392 break;
393 }
394 case IIS_WEBLOG:
395 {
396#pragma prefast(suppress:26010, "This is a prefast issue - pAdminMgr is correctly allocated")
397 hr = IIS7WebLog(&pwz, pAdminMgr);
398 ExitOnFailure(hr, "Failed to configure IIS WebLog.");
399 break;
400 }
401 case IIS_FILTER_GLOBAL_BEGIN:
402 {
403#pragma prefast(suppress:26010, "This is a prefast issue - pAdminMgr is correctly allocated")
404 hr = IIS7FilterGlobal(&pwz, pAdminMgr);
405 ExitOnFailure(hr, "Failed to configure IIS filter global.");
406 break;
407 }
408 case IIS_FILTER_BEGIN:
409 {
410#pragma prefast(suppress:26010, "This is a prefast issue - pAdminMgr is correctly allocated")
411 hr = IIS7FilterSite(&pwz, pAdminMgr);
412 ExitOnFailure(hr, "Failed to configure IIS Filter.");
413 break;
414 }
415 case IIS_HTTP_HEADER_BEGIN:
416 {
417#pragma prefast(suppress:26010, "This is a prefast issue - pAdminMgr is correctly allocated")
418 hr = IIS7HttpHeader(&pwz, pAdminMgr);
419 ExitOnFailure(hr, "Failed to configure IIS http Header.");
420 break;
421 }
422 case IIS_WEBERROR_BEGIN:
423 {
424#pragma prefast(suppress:26010, "This is a prefast issue - pAdminMgr is correctly allocated")
425 hr = IIS7WebError(&pwz, pAdminMgr);
426 ExitOnFailure(hr, "Failed to configure IIS http Errors.");
427 break;
428 }
429 case IIS_WEB_SVC_EXT:
430 {
431#pragma prefast(suppress:26010, "This is a prefast issue - pAdminMgr is correctly allocated")
432 hr = IIS7WebSvcExt(&pwz, pAdminMgr);
433 ExitOnFailure(hr, "Failed to configure IIS web svc ext.");
434 break;
435 }
436 case IIS_PROPERTY:
437 {
438#pragma prefast(suppress:26010, "This is a prefast issue - pAdminMgr is correctly allocated")
439 hr = IIS7WebProperty(&pwz, pAdminMgr);
440 ExitOnFailure(hr, "Failed to configure IIS web property.");
441 break;
442 }
443 case IIS_WEBDIR:
444 {
445#pragma prefast(suppress:26010, "This is a prefast issue - pAdminMgr is correctly allocated")
446 hr = IIS7WebDir(&pwz, pAdminMgr);
447 ExitOnFailure(hr, "Failed to configure IIS web directory.");
448 break;
449 }
450 case IIS_ASP_BEGIN:
451 {
452#pragma prefast(suppress:26010, "This is a prefast issue - pAdminMgr is correctly allocated")
453 hr = IIS7AspProperty(&pwz, pAdminMgr);
454 ExitOnFailure(hr, "Failed to configure IIS Asp property.");
455 break;
456 }
457 case IIS_SSL_BINDING:
458#pragma prefast(suppress:26010, "This is a prefast issue - pAdminMgr is correctly allocated")
459 hr = IIS7SslBinding(&pwz, pAdminMgr);
460 ExitOnFailure(hr, "Failed to configure IIS SSL binding.");
461 break;
462
463 default:
464 ExitOnFailure(hr = E_UNEXPECTED, "IIS7ConfigChanges: Unexpected IIS Config action specified: %d", iAction);
465 break;
466 }
467 if (S_OK == hr)
468 {
469 // commit config changes now to close out IIS Admin changes,
470 // the Rollback or Commit defered CAs will determine final commit status.
471 hr = pAdminMgr->CommitChanges();
472
473 // Our transaction may have been interrupted.
474 if (hr == HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION) || hr == HRESULT_FROM_WIN32(ERROR_TRANSACTIONAL_CONFLICT))
475 {
476 WcaLog(LOGMSG_VERBOSE, "Sharing violation or transactional conflict during attempt to save changes to applicationHost.config");
477 if (++iRetryCount > 30)
478 {
479 if (IDRETRY == WcaErrorMessage(msierrIISFailedCommitInUse, hr, INSTALLMESSAGE_ERROR | MB_RETRYCANCEL, 0))
480 {
481 iRetryCount = 0;
482 }
483 else
484 {
485 ExitOnFailure(hr, "Failed to Commit IIS Config Changes, in silent mode or user has chosen to cancel");
486 }
487 }
488
489 // Throw away the changes since IIS has no way to remove uncommited changes from an AdminManager.
490 ReleaseNullObject(pAdminMgr);
491
492 // Restore our CA data backup
493 pwz = pwzLast;
494 hr = ::StringCchCopyW(pwz, cchData - (pwz - pwzData) + 1, pwzBackup);
495 ExitOnFailure(hr , "Failed to restore custom action data backup");
496
497 }
498 else if (FAILED(hr))
499 {
500 ExitOnFailure(hr , "Failed to Commit IIS Config Changes");
501 }
502 else
503 {
504 // store a backup of CA data @ the last place that we successfully commited changes unless we are done.
505 if(NULL != pwz)
506 {
507 pwzLast = pwz;
508 hr = StrAllocString(&pwzBackup, pwz, 0);
509 ExitOnFailure(hr, "Failed to backup custom action data");
510 }
511 }
512 }
513 }
514 if (E_NOMOREITEMS == hr) // If there are no more items, all is well
515 {
516 hr = S_OK;
517 }
518LExit:
519 ReleaseObject(pAdminMgr);
520 ReleaseStr(pwzBackup);
521
522 if (fInitializedCom)
523 {
524 ::CoUninitialize();
525 }
526
527 return hr;
528}
529//-------------------------------------------------------------------------------------------------
530// IIS7AspProperty
531// Called by WriteIIS7ConfigChanges
532// Processes asp properties for WebApplication
533//
534//-------------------------------------------------------------------------------------------------
535
536HRESULT IIS7AspProperty(
537 __inout LPWSTR *ppwzCustomActionData,
538 __in IAppHostWritableAdminManager *pAdminMgr
539 )
540{
541 HRESULT hr = S_OK;
542
543 int iAction = -1;
544 int iData = 0;
545
546 LPWSTR pwzData = NULL;
547 LPWSTR pwzSiteName = NULL;
548 LPWSTR pwzPathName = NULL;
549 LPWSTR pwzLocationPath = NULL;
550 WCHAR wcTime[60];
551
552 IAppHostElement *pSection = NULL;
553 IAppHostElement *pElement = NULL;
554
555 //read web site key
556 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzSiteName);
557 ExitOnFailure(hr, "Failed read webDir webkey");
558
559 //read path key
560 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzPathName);
561 ExitOnFailure(hr, "Failed read webDir path");
562
563 //Construct Location path
564 hr = StrAllocFormatted(&pwzLocationPath, L"%s/%s", IIS_CONFIG_APPHOST_ROOT, pwzSiteName);
565 ExitOnFailure(hr, "failed to format webDir location");
566 //
567 //Do not append trailing '/' for default vDir
568 //
569 if (CSTR_EQUAL != ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, pwzPathName, -1, L"/", -1))
570 {
571 hr = StrAllocConcat(&pwzLocationPath, L"/", 0);
572 ExitOnFailure(hr, "failed to copy location WebDir '/'");
573 hr = StrAllocConcat(&pwzLocationPath, pwzPathName, 0);
574 ExitOnFailure(hr, "failed to copy location WebDir path");
575 }
576
577 //get asp section at config path location tag
578 hr = pAdminMgr->GetAdminSection( ScopeBSTR(IIS_CONFIG_ASP_SECTION), pwzLocationPath, &pSection);
579 ExitOnFailure(hr, "Failed get httpErrors section");
580
581 // Get action
582 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iAction);
583 ExitOnFailure(hr, "Failed to read property action");
584
585 while (IIS_ASP_END != iAction)
586 {
587 switch (iAction)
588 {
589 case IIS_ASP_SESSIONSTATE:
590 {
591 //system.webServer/asp /session | allowSessionState
592 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iData);
593 ExitOnFailure(hr, "Failed to read asp session state");
594 hr = pSection->GetElementByName(ScopeBSTR(IIS_CONFIG_SESSION), &pElement);
595 ExitOnFailure(hr, "Failed to get asp session element");
596 hr = Iis7PutPropertyBool( pElement, IIS_CONFIG_ALLOWSTATE, iData);
597 ExitOnFailure(hr, "Failed to put asp session value");
598 ReleaseNullObject(pElement);
599 break;
600 }
601 case IIS_ASP_SESSIONTIMEOUT:
602 {
603 //system.webServer/asp /session | timeout
604 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iData);
605 ExitOnFailure(hr, "Failed to read asp session timeout");
606 hr = pSection->GetElementByName(ScopeBSTR(IIS_CONFIG_SESSION), &pElement);
607 ExitOnFailure(hr, "Failed to get asp session timeout");
608 *wcTime = '\0';
609 ConvSecToHMS(iData * 60, wcTime, countof( wcTime));
610 hr = Iis7PutPropertyString( pElement, IIS_CONFIG_TIMEOUT, wcTime);
611 ExitOnFailure(hr, "Failed to put asp timeout value");
612 ReleaseNullObject(pElement);
613 break;
614 }
615 case IIS_ASP_BUFFER:
616 {
617 //system.webServer/asp | bufferingOn
618 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iData);
619 ExitOnFailure(hr, "Failed to read asp bufferingOn");
620 hr = Iis7PutPropertyBool( pSection, IIS_CONFIG_BUFFERING, iData);
621 ExitOnFailure(hr, "Failed to put asp bufferingOn value");
622 break;
623 }
624 case IIS_ASP_PARENTPATHS:
625 {
626 //system.webServer/asp | enableParentPaths
627 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iData);
628 ExitOnFailure(hr, "Failed to read asp ParentPaths");
629 hr = Iis7PutPropertyBool( pSection, IIS_CONFIG_PARENTPATHS, iData);
630 ExitOnFailure(hr, "Failed to put asp ParentPaths value");
631 break;
632 }
633 case IIS_ASP_SCRIPTLANG:
634 {
635 //system.webServer/asp | scriptLanguage
636 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzData);
637 ExitOnFailure(hr, "Failed to read asp scriptLanguage");
638 hr = Iis7PutPropertyString( pSection, IIS_CONFIG_SCRIPTLANG, pwzData);
639 ExitOnFailure(hr, "Failed to put asp scriptLanguage value");
640 break;
641 }
642 case IIS_ASP_SCRIPTTIMEOUT:
643 {
644 //system.webServer/asp /limits | scriptTimeout
645 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iData);
646 ExitOnFailure(hr, "Failed to read asp scriptTimeout");
647 hr = pSection->GetElementByName(ScopeBSTR(IIS_CONFIG_LIMITS), &pElement);
648 ExitOnFailure(hr, "Failed to get asp session element");
649 *wcTime = '\0';
650 ConvSecToHMS(iData, wcTime, countof( wcTime));
651 hr = Iis7PutPropertyString( pElement, IIS_CONFIG_SCRIPTTIMEOUT, wcTime);
652 ExitOnFailure(hr, "Failed to put asp scriptTimeout value");
653 ReleaseNullObject(pElement);
654 break;
655
656 }
657 case IIS_ASP_SCRIPTSERVERDEBUG:
658 {
659 //system.webServer/asp | appAllowDebugging
660 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iData);
661 ExitOnFailure(hr, "Failed to read asp appAllowDebugging");
662 hr = Iis7PutPropertyBool( pSection, IIS_CONFIG_ALLOWDEBUG, iData);
663 ExitOnFailure(hr, "Failed to put asp appAllowDebugging value");
664 break;
665 }
666 case IIS_ASP_SCRIPTCLIENTDEBUG:
667 {
668 //system.webServer/asp | appAllowClientDebug
669 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iData);
670 ExitOnFailure(hr, "Failed to read asp appAllowClientDebug");
671 hr = Iis7PutPropertyBool( pSection, IIS_CONFIG_ALLOWCLIENTDEBUG, iData);
672 ExitOnFailure(hr, "Failed to put asp appAllowClientDebug value");
673 break;
674 }
675 default:
676 {
677 ExitOnFailure(hr = E_UNEXPECTED, "Unexpected IIS Config action specified for asp properties");
678 break;
679 }
680 }
681 // Get next action
682 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iAction);
683 ExitOnFailure(hr, "Failed to read asp prop action");
684 }
685
686LExit:
687 ReleaseStr(pwzData);
688 ReleaseStr(pwzSiteName);
689 ReleaseStr(pwzPathName);
690 ReleaseStr(pwzLocationPath);
691 ReleaseObject(pSection);
692 ReleaseObject(pElement);
693
694 return hr;
695}
696
697//-------------------------------------------------------------------------------------------------
698// IIS7WebDir
699// Called by WriteIIS7ConfigChanges
700// Processes WebDir
701//
702//-------------------------------------------------------------------------------------------------
703HRESULT IIS7WebDir(
704 __inout LPWSTR *ppwzCustomActionData,
705 __in IAppHostWritableAdminManager *pAdminMgr
706 )
707{
708 HRESULT hr = S_OK;
709
710 int iAction = -1;
711
712 LPWSTR pwzSiteName = NULL;
713 LPWSTR pwzPathName = NULL;
714 LPWSTR pwzLocationPath = NULL;
715
716 // Get action
717 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iAction);
718 ExitOnFailure(hr, "Failed to read property action");
719
720 //read web site key
721 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzSiteName);
722 ExitOnFailure(hr, "Failed read webDir webkey");
723
724 //read path key
725 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzPathName);
726 ExitOnFailure(hr, "Failed read webDir path");
727
728 switch (iAction)
729 {
730 case IIS_CREATE:
731 {
732 //no action needed for create since WebDir has a
733 //WebDirProperties element that will create and populate
734 //location tag
735 break;
736 }
737 case IIS_DELETE:
738 {
739 //Construct Location path
740 hr = StrAllocString(&pwzLocationPath, pwzSiteName, 0);
741 ExitOnFailure(hr, "failed to copy location WebDir web name");
742 //
743 //Do not append trailing '/' for default vDir
744 //
745 if (CSTR_EQUAL != ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, pwzPathName, -1, L"/", -1))
746 {
747 hr = StrAllocConcat(&pwzLocationPath, L"/", 0);
748 ExitOnFailure(hr, "failed to copy location WebDir '/'");
749 hr = StrAllocConcat(&pwzLocationPath, pwzPathName, 0);
750 ExitOnFailure(hr, "failed to copy location WebDir path");
751 }
752 // and delete location tag for this application
753 hr = ClearLocationTag(pAdminMgr, pwzLocationPath);
754 ExitOnFailure(hr, "failed to clear location tag for %ls", pwzLocationPath)
755 break;
756 }
757 default:
758 {
759 ExitOnFailure(hr = E_UNEXPECTED, "Unexpected IIS Config action specified for WebDir");
760 break;
761 }
762 }
763LExit:
764 ReleaseStr(pwzSiteName);
765 ReleaseStr(pwzPathName);
766 ReleaseStr(pwzLocationPath);
767
768 return hr;
769}
770
771//-------------------------------------------------------------------------------------------------
772// IIS7WebProperty
773// Called by WriteIIS7ConfigChanges
774// Processes isapiCgiRestriction
775//
776//-------------------------------------------------------------------------------------------------
777HRESULT IIS7WebProperty(
778 __inout LPWSTR *ppwzCustomActionData,
779 __in IAppHostWritableAdminManager *pAdminMgr
780 )
781{
782 HRESULT hr = S_OK;
783
784 int iAction = -1;
785 int iData = 0;
786
787 IAppHostElement *pSection = NULL;
788
789 // Get action
790 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iAction);
791 ExitOnFailure(hr, "Failed to read property action");
792
793 switch (iAction)
794 {
795 case IIS_PROPERTY_MAXBAND:
796 {
797 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iData);
798 ExitOnFailure(hr, "Failed to read property max band");
799 //set value at system.applicationHost/webLimits | maxGlobalBandwidth
800 //Get IIS config section
801 hr = pAdminMgr->GetAdminSection(ScopeBSTR(IIS_CONFIG_WEBLIMITS_SECTION), ScopeBSTR(IIS_CONFIG_APPHOST_ROOT), &pSection);
802 ExitOnFailure(hr, "Failed get isapiCgiRestriction section");
803 if (!pSection)
804 {
805 hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
806 ExitOnFailure(hr, "Failed get isapiCgiRestriction section object");
807 }
808 hr = Iis7PutPropertyInteger(pSection, IIS_CONFIG_WEBLIMITS_MAXBAND, iData);
809
810 break;
811 }
812 case IIS_PROPERTY_LOGUTF8:
813 {
814 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iData);
815 ExitOnFailure(hr, "Failed to read property log");
816 //set value at system.applicationHost/log | logInUTF8
817 //Get IIS config section
818 hr = pAdminMgr->GetAdminSection(ScopeBSTR(IIS_CONFIG_LOG_SECTION), ScopeBSTR(IIS_CONFIG_APPHOST_ROOT), &pSection);
819 ExitOnFailure(hr, "Failed get isapiCgiRestriction section");
820 if (!pSection)
821 {
822 hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
823 ExitOnFailure(hr, "Failed get isapiCgiRestriction section object");
824 }
825 hr = Iis7PutPropertyBool(pSection, IIS_CONFIG_LOG_UTF8, iData);
826
827 break;
828 }
829 default:
830 {
831 ExitOnFailure(hr = E_UNEXPECTED, "Unexpected IIS Config action specified for Web Property");
832 break;
833 }
834 }
835
836LExit:
837 ReleaseObject(pSection);
838
839 return hr;
840}
841
842//-------------------------------------------------------------------------------------------------
843// IIS7WebSvcExt
844// Called by WriteIIS7ConfigChanges
845// Processes isapiCgiRestriction
846//
847//-------------------------------------------------------------------------------------------------
848HRESULT IIS7WebSvcExt(
849 __inout LPWSTR *ppwzCustomActionData,
850 __in IAppHostWritableAdminManager *pAdminMgr
851 )
852{
853 HRESULT hr = S_OK;
854
855 int iAction = -1;
856 int iData = 0;
857 BOOL fFound = FALSE;
858 LPWSTR pwzData = NULL;
859 LPWSTR pwzPath = NULL;
860
861 IAppHostElement *pSection = NULL;
862 IAppHostElement *pElement = NULL;
863 IAppHostElementCollection *pCollection = NULL;
864
865 // Get action
866 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iAction);
867 ExitOnFailure(hr, "Failed to read WebSvcExt action");
868
869 //get path
870 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzPath);
871 ExitOnFailure(hr, "Failed to read WebSvcExt key");
872
873 //Get IIS config section
874 hr = pAdminMgr->GetAdminSection(ScopeBSTR(IIS_CONFIG_RESTRICTION_SECTION), ScopeBSTR(IIS_CONFIG_APPHOST_ROOT), &pSection);
875 ExitOnFailure(hr, "Failed get isapiCgiRestriction section");
876 if (!pSection)
877 {
878 hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
879 ExitOnFailure(hr, "Failed get isapiCgiRestriction section object");
880 }
881 //get collection
882 hr = pSection->get_Collection(&pCollection);
883 ExitOnFailure(hr, "Failed get isapiCgiRestriction collection");
884
885 //find element
886 hr = Iis7FindAppHostElementPath(pCollection, IIS_CONFIG_ADD, IIS_CONFIG_PATH, pwzPath, &pElement, NULL);
887 ExitOnFailure(hr, "Failed get isapiCgiRestriction element");
888 fFound = (NULL != pElement);
889
890 switch (iAction)
891 {
892 case IIS_CREATE:
893 {
894 if (!fFound)
895 {
896 //create a restriction element
897 hr = pCollection->CreateNewElement(ScopeBSTR(IIS_CONFIG_ADD), &pElement);
898 ExitOnFailure(hr, "Failed create isapiCgiRestriction element");
899 //put path
900 hr = Iis7PutPropertyString(pElement, IIS_CONFIG_PATH, pwzPath);
901 ExitOnFailure(hr, "Failed set isapiCgiRestriction path property");
902 }
903 //update common properties
904
905 //update allowed
906 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iData);
907 ExitOnFailure(hr, "Failed to read WebSvcExt allowed");
908 hr = Iis7PutPropertyBool(pElement, IIS_CONFIG_ALLOWED, iData);
909 ExitOnFailure(hr, "Failed set isapiCgiRestriction allowed property");
910
911 //update groupId
912 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzData);
913 ExitOnFailure(hr, "Failed to read WebSvcExt group ID");
914 if (*pwzData)
915 {
916 hr = Iis7PutPropertyString(pElement, IIS_CONFIG_GROUPID, pwzData);
917 ExitOnFailure(hr, "Failed set isapiCgiRestriction groupId property");
918 }
919 //update description
920 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzData);
921 ExitOnFailure(hr, "Failed to read WebSvcExt description");
922 if (*pwzData)
923 {
924 hr = Iis7PutPropertyString(pElement, IIS_CONFIG_DESC, pwzData);
925 ExitOnFailure(hr, "Failed set isapiCgiRestriction description property");
926 }
927 // add element if new
928 if (!fFound)
929 {
930 hr = pCollection->AddElement(pElement);
931 ExitOnFailure(hr, "Failed add isapiCgiRestriction element");
932 }
933
934 break;
935 }
936 case IIS_DELETE:
937 {
938 hr = DeleteCollectionElement(pCollection, IIS_CONFIG_ADD, IIS_CONFIG_PATH, pwzPath);
939 ExitOnFailure(hr, "Failed delete isapiCgiRestriction element");
940 break;
941 }
942 default:
943 {
944 ExitOnFailure(hr = E_UNEXPECTED, "Unexpected IIS Config action specified for WebSvcExt");
945 break;
946 }
947 }
948
949LExit:
950 ReleaseStr(pwzPath);
951 ReleaseStr(pwzData);
952 ReleaseObject(pSection);
953 ReleaseObject(pElement);
954 ReleaseObject(pCollection);
955
956 return hr;
957
958}
959
960//-------------------------------------------------------------------------------------------------
961// IIS7WebError
962// Called by WriteIIS7ConfigChanges
963// Processes http header CA Data
964//
965//-------------------------------------------------------------------------------------------------
966
967HRESULT IIS7WebError(
968 __inout LPWSTR *ppwzCustomActionData,
969 __in IAppHostWritableAdminManager *pAdminMgr
970 )
971{
972 HRESULT hr = S_OK;
973 LPWSTR pwzConfigPath = NULL;
974 LPWSTR pwzSiteName = NULL;
975 LPWSTR pwzAppName = NULL;
976
977 IAppHostElement *pElement = NULL;
978 IAppHostElement *pSection = NULL;
979 IAppHostElementCollection *pCollection = NULL;
980
981 SCA_WEB_ERROR_SERVER *psweList = NULL;
982 SCA_WEB_ERROR_SERVER* pswe = NULL;
983 SCA_WEB_ERROR_SERVER we;
984 BOOL fFound = FALSE;
985
986 int iAction = -1;
987 LPWSTR pwzData = NULL;
988
989 //read web site key
990 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzSiteName);
991 ExitOnFailure(hr, "Failed read web error site name");
992
993 //read app key
994 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzAppName);
995 ExitOnFailure(hr, "Failed read web error app name");
996
997 //Construct config root path
998 hr = StrAllocFormatted(&pwzConfigPath, L"%s/%s", IIS_CONFIG_APPHOST_ROOT, pwzSiteName);
999 ExitOnFailure(hr, "failed to format web error config path");
1000
1001 if (CSTR_EQUAL != ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, pwzAppName, -1, L"/", -1))
1002 {
1003 hr = StrAllocConcat(&pwzConfigPath, L"/", 0);
1004 ExitOnFailure(hr, "failed to copy web error config path delim");
1005 hr = StrAllocConcat(&pwzConfigPath, pwzAppName, 0);
1006 ExitOnFailure(hr, "failed to app name to web error config path");
1007 }
1008
1009 //get httpErrors section at config path location tag
1010 hr = pAdminMgr->GetAdminSection(ScopeBSTR(IIS_CONFIG_HTTPERRORS_SECTION), pwzConfigPath, &pSection);
1011 ExitOnFailure(hr, "Failed get httpErrors section");
1012
1013 //get existing httpErrors list & clear collection
1014 hr = PopulateHttpErrors(pSection, &psweList);
1015 ExitOnFailure(hr, "Failed to read httpErrors list");
1016
1017 //get collection
1018 hr = pSection->get_Collection(&pCollection);
1019 ExitOnFailure(hr, "Failed get httpErrors collection");
1020
1021 DWORD cErrors = 0;
1022 hr = pCollection->get_Count(&cErrors);
1023
1024 // Get web error action
1025 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iAction);
1026 ExitOnFailure(hr, "Failed to read filter action");
1027 while (IIS_WEBERROR_END != iAction)
1028 {
1029 //Process property action
1030 if (IIS_WEBERROR == iAction)
1031 {
1032 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &(we.iErrorCode));
1033 ExitOnFailure(hr, "failed to get httpErrors ErrorCode");
1034
1035 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &(we.iSubCode));
1036 ExitOnFailure(hr, "failed to get httpErrors SubCode");
1037 //0 is the sub error code wild card for IIS6, change to -1 for IIS7
1038 if (we.iSubCode == 0)
1039 {
1040 we.iSubCode = -1;
1041 }
1042 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzData);
1043 ExitOnFailure(hr, "Failed to get httpErrors File");
1044 hr = ::StringCchCopyW(we.wzFile, countof(we.wzFile), pwzData);
1045 ExitOnFailure(hr, "Failed to copy httpErrors File");
1046
1047 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &(we.iResponseMode));
1048 ExitOnFailure(hr, "Failed to get httpErrors File code");
1049
1050 fFound = FALSE;
1051 hr = GetErrorFromList( we, &psweList, &pswe, &fFound);
1052 if (!fFound)
1053 {
1054 hr = AddWebErrorToList(&psweList);
1055 ExitOnFailure(hr, "failed to add web error to list");
1056 pswe = psweList;
1057 }
1058 else
1059 {
1060 //if overwriting existing http errors element then clear lang path
1061 hr = ::StringCchCopyW(pswe->wzLangPath, countof(pswe->wzLangPath), L"");
1062 ExitOnFailure(hr, "Failed to copy httpErrors lang path value");
1063 }
1064 pswe->iErrorCode = we.iErrorCode;
1065 pswe->iSubCode = we.iSubCode;
1066 hr = ::StringCchCopyW(pswe->wzFile, countof(pswe->wzFile), we.wzFile);
1067 ExitOnFailure(hr, "Failed to copy httpErrors File value");
1068 pswe->iResponseMode = we.iResponseMode;
1069
1070 }
1071 else
1072 {
1073 ExitOnFailure(hr = E_UNEXPECTED, "Unexpected IIS Config action specified for http header");
1074 }
1075
1076 // Get AppExt action
1077 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iAction);
1078 ExitOnFailure(hr, "Failed to read filter action");
1079 }
1080
1081 //No inheritance - put a clear in at this loc tag
1082 hr = pCollection->CreateNewElement(ScopeBSTR(IIS_CONFIG_CLEAR), &pElement);
1083 ExitOnFailure(hr, "Failed create httpErrors clear");
1084 hr = pCollection->AddElement(pElement);
1085 ExitOnFailure(hr, "Failed add httpErrors clear");
1086
1087 //now we have merged new, from MSI, http errors with global list
1088 //write this back out at location tag.
1089 // Loop through the HTTP headers
1090 for ( pswe = psweList; pswe; pswe = pswe->psweNext)
1091 {
1092 hr = pCollection->CreateNewElement(ScopeBSTR(IIS_CONFIG_ERROR), &pElement);
1093 ExitOnFailure(hr, "Failed create httpErrors element");
1094
1095 // status code
1096 hr = Iis7PutPropertyInteger(pElement, IIS_CONFIG_STATUSCODE, pswe->iErrorCode);
1097 ExitOnFailure(hr, "Failed set httpErrors code value");
1098
1099 //sub status
1100 hr = Iis7PutPropertyInteger(pElement, IIS_CONFIG_SUBSTATUS, pswe->iSubCode);
1101 ExitOnFailure(hr, "Failed set httpErrors sub code value");
1102
1103 //lang path
1104 hr = Iis7PutPropertyString(pElement, IIS_CONFIG_LANGPATH, pswe->wzLangPath);
1105 ExitOnFailure(hr, "Failed set httpErrors lang path value");
1106
1107 //path
1108 hr = Iis7PutPropertyString(pElement, IIS_CONFIG_PATH, pswe->wzFile);
1109 ExitOnFailure(hr, "Failed set httpErrors path value");
1110
1111 //response mode
1112 hr = Iis7PutPropertyInteger(pElement, IIS_CONFIG_RESPMODE, pswe->iResponseMode);
1113 ExitOnFailure(hr, "Failed set httpErrors resp mode value");
1114
1115 //add the element
1116 hr = pCollection->AddElement(pElement);
1117 ExitOnFailure(hr, "Failed add httpErrors element");
1118 ReleaseNullObject(pElement);
1119 }
1120
1121LExit:
1122 ScaWebErrorFreeList7(psweList);
1123
1124 ReleaseStr(pwzConfigPath);
1125 ReleaseStr(pwzSiteName);
1126 ReleaseStr(pwzAppName);
1127 ReleaseStr(pwzData);
1128 ReleaseObject(pElement);
1129 ReleaseObject(pSection);
1130 ReleaseObject(pCollection);
1131
1132 return hr;
1133}
1134
1135static HRESULT PopulateHttpErrors(IAppHostElement *pSection, SCA_WEB_ERROR_SERVER **ppsweList)
1136{
1137 HRESULT hr = S_OK;
1138
1139 IAppHostElement *pElement = NULL;
1140 IAppHostElementCollection *pCollection = NULL;
1141 IAppHostProperty *pProperty = NULL;
1142
1143 DWORD cErrors = 0;
1144 SCA_WEB_ERROR_SERVER *pswe = NULL;
1145
1146 VARIANT vPropValue;
1147 VARIANT vtIndex;
1148
1149 VariantInit(&vPropValue);
1150 VariantInit(&vtIndex);
1151
1152 hr = pSection->get_Collection(&pCollection);
1153 ExitOnFailure(hr, "Failed get httpErrors collection");
1154
1155 hr = pCollection->get_Count(&cErrors);
1156 ExitOnFailure(hr, "Failed get sites collection count");
1157
1158 vtIndex.vt = VT_UI4;
1159 for (DWORD i = 0; i < cErrors; ++i)
1160 {
1161 vtIndex.ulVal = i;
1162 hr = pCollection->get_Item(vtIndex , &pElement);
1163 ExitOnFailure(hr, "Failed get httpErrors collection item");
1164
1165 hr = AddWebErrorToList(ppsweList);
1166 ExitOnFailure(hr, "Failed add web error list item");
1167 pswe = *ppsweList;
1168
1169 //get all properties
1170 //
1171 // statusCode UINT
1172 // subStatusCode INT
1173 // prefixLanguageFilePath type="string"
1174 // path type="string"
1175 // responseMode type="enum" defaultValue="File">
1176 // <enum name="File" value="0" />
1177 // <enum name="ExecuteURL" value="1" />
1178 // <enum name="Redirect" value="2" />
1179
1180 // status code
1181 hr = pElement->GetPropertyByName(ScopeBSTR(IIS_CONFIG_STATUSCODE), &pProperty);
1182 ExitOnFailure(hr, "Failed get httpErrors code property");
1183 hr = pProperty->get_Value(&vPropValue);
1184 ExitOnFailure(hr, "Failed get httpErrors code value");
1185 pswe->iErrorCode = vPropValue.uintVal;
1186 ReleaseVariant(vPropValue);
1187
1188 //sub status
1189 hr = pElement->GetPropertyByName(ScopeBSTR(IIS_CONFIG_SUBSTATUS), &pProperty);
1190 ExitOnFailure(hr, "Failed get httpErrors sub code property");
1191 hr = pProperty->get_Value(&vPropValue);
1192 ExitOnFailure(hr, "Failed get httpErrors sub code value");
1193 pswe->iSubCode = vPropValue.intVal;
1194 ReleaseVariant(vPropValue);
1195
1196 //lang path
1197 hr = pElement->GetPropertyByName(ScopeBSTR(IIS_CONFIG_LANGPATH), &pProperty);
1198 ExitOnFailure(hr, "Failed get httpErrors lang path property");
1199 hr = pProperty->get_Value(&vPropValue);
1200 ExitOnFailure(hr, "Failed get httpErrors lang path value");
1201 hr = ::StringCchCopyW(pswe->wzLangPath, countof(pswe->wzLangPath), vPropValue.bstrVal);
1202 ExitOnFailure(hr, "Failed to copy httpErrors lang path");
1203 ReleaseVariant(vPropValue);
1204
1205 //path
1206 hr = pElement->GetPropertyByName(ScopeBSTR(IIS_CONFIG_PATH), &pProperty);
1207 ExitOnFailure(hr, "Failed get httpErrors path property");
1208 hr = pProperty->get_Value(&vPropValue);
1209 ExitOnFailure(hr, "Failed get httpErrors path value");
1210 hr = ::StringCchCopyW(pswe->wzFile, countof(pswe->wzFile), vPropValue.bstrVal);
1211 ExitOnFailure(hr, "Failed to copy httpErrors File");
1212 ReleaseVariant(vPropValue);
1213
1214 //response mode
1215 hr = pElement->GetPropertyByName(ScopeBSTR(IIS_CONFIG_RESPMODE), &pProperty);
1216 ExitOnFailure(hr, "Failed get httpErrors resp mode property");
1217 hr = pProperty->get_Value(&vPropValue);
1218 ExitOnFailure(hr, "Failed get httpErrors resp mode value");
1219 pswe->iResponseMode = vPropValue.intVal;
1220 ReleaseVariant(vPropValue);
1221
1222 ReleaseNullObject(pElement);
1223 ReleaseNullObject(pProperty);
1224 }
1225
1226 //remove the elements from connection so we can add back later
1227 hr = pCollection->Clear();
1228 ExitOnFailure(hr, "Failed clear httpErrors collection");
1229
1230LExit:
1231 ReleaseVariant(vPropValue);
1232 ReleaseObject(pProperty);
1233 ReleaseObject(pElement);
1234 ReleaseObject(pCollection);
1235
1236 return hr;
1237}
1238
1239static void ScaWebErrorFreeList7(SCA_WEB_ERROR_SERVER *psweList)
1240{
1241 SCA_WEB_ERROR_SERVER *psweDelete = psweList;
1242 while (psweList)
1243 {
1244 psweDelete = psweList;
1245 psweList = psweList->psweNext;
1246
1247 MemFree(psweDelete);
1248 }
1249}
1250static HRESULT AddWebErrorToList(SCA_WEB_ERROR_SERVER **ppsweList)
1251{
1252 HRESULT hr = S_OK;
1253
1254 SCA_WEB_ERROR_SERVER* pswe = static_cast<SCA_WEB_ERROR_SERVER*>(MemAlloc(sizeof(SCA_WEB_ERROR_SERVER), TRUE));
1255
1256 ExitOnNull(pswe, hr, E_OUTOFMEMORY, "failed to allocate memory for new web error list element");
1257
1258 pswe->psweNext = *ppsweList;
1259 *ppsweList = pswe;
1260
1261LExit:
1262 return hr;
1263}
1264static HRESULT GetErrorFromList( const SCA_WEB_ERROR_SERVER& we,
1265 SCA_WEB_ERROR_SERVER **ppsweList,
1266 SCA_WEB_ERROR_SERVER **ppswe,
1267 BOOL *fFound)
1268{
1269 HRESULT hr = S_OK;
1270
1271 *fFound = FALSE;
1272
1273 SCA_WEB_ERROR_SERVER *pswe;
1274
1275 for ( pswe = *ppsweList; pswe; pswe = pswe->psweNext)
1276 {
1277 if ((pswe->iErrorCode == we.iErrorCode) && (pswe->iSubCode == we.iSubCode))
1278 {
1279 *fFound = TRUE;
1280 *ppswe = pswe;
1281 break;
1282 }
1283 }
1284
1285 return hr;
1286}
1287
1288//-------------------------------------------------------------------------------------------------
1289// IIS7HttpHeader
1290// Called by WriteIIS7ConfigChanges
1291// Processes http header CA Data
1292//
1293//-------------------------------------------------------------------------------------------------
1294
1295HRESULT IIS7HttpHeader(
1296 __inout LPWSTR *ppwzCustomActionData,
1297 __in IAppHostWritableAdminManager *pAdminMgr
1298 )
1299{
1300 HRESULT hr = S_OK;
1301 LPWSTR pwzConfigPath = NULL;
1302 LPWSTR pwzSiteName = NULL;
1303 LPWSTR pwzAppName = NULL;
1304
1305 LPWSTR pwzHeaderName = NULL;
1306 LPWSTR pwzHeaderValue = NULL;
1307
1308 IAppHostElement *pElement = NULL;
1309 IAppHostElement *pSection = NULL;
1310 IAppHostElementCollection *pCollection = NULL;
1311 IAppHostElement *pElementHeaders = NULL;
1312
1313 int iAction = -1;
1314 BOOL fFound = FALSE;
1315
1316 //read web site key
1317 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzSiteName);
1318 ExitOnFailure(hr, "Failed read header web site name");
1319
1320 //read app key
1321 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzAppName);
1322 ExitOnFailure(hr, "Failed read header appkey");
1323
1324 //Construct config root path
1325 hr = StrAllocFormatted(&pwzConfigPath, L"%s/%s", IIS_CONFIG_APPHOST_ROOT, pwzSiteName);
1326 ExitOnFailure(hr, "failed to format web error config path");
1327
1328 if (CSTR_EQUAL != ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, pwzAppName, -1, L"/", -1))
1329 {
1330 hr = StrAllocConcat(&pwzConfigPath, L"/", 0);
1331 ExitOnFailure(hr, "failed to copy web error config path delim");
1332 hr = StrAllocConcat(&pwzConfigPath, pwzAppName, 0);
1333 ExitOnFailure(hr, "failed to app name to web error config path");
1334 }
1335
1336 //get admin handlers section at config path location tag
1337 hr = pAdminMgr->GetAdminSection(ScopeBSTR(IIS_CONFIG_HTTPPROTO_SECTION), pwzConfigPath, &pSection);
1338 ExitOnFailure(hr, "Failed get http protocol section");
1339
1340 hr = pSection->GetElementByName(ScopeBSTR(IIS_CONFIG_HEADERS), &pElementHeaders);
1341 ExitOnFailure(hr, "Failed get http customHeaders section");
1342
1343 hr = pElementHeaders->get_Collection(&pCollection);
1344 ExitOnFailure(hr, "Failed get http customHeaders collection");
1345
1346 // Get filter action
1347 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iAction);
1348 ExitOnFailure(hr, "Failed to read filter action");
1349 while (IIS_HTTP_HEADER_END != iAction)
1350 {
1351 //Process property action
1352 if (IIS_HTTP_HEADER == iAction)
1353 {
1354 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzHeaderName);
1355 ExitOnFailure(hr, "Fail to read httpHeader name");
1356
1357 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzHeaderValue);
1358 ExitOnFailure(hr, "Fail to read httpHeader value");
1359
1360 hr = Iis7FindAppHostElementString(pCollection, IIS_CONFIG_ADD, IIS_CONFIG_NAME, pwzHeaderName, &pElement, NULL);
1361 ExitOnFailure(hr, "Failed get isapiCgiRestriction element");
1362 fFound = (NULL != pElement);
1363
1364 if (!fFound)
1365 {
1366 //make a new element
1367 hr = pCollection->CreateNewElement(ScopeBSTR(IIS_CONFIG_ADD), &pElement);
1368 ExitOnFailure(hr, "Failed to create filter config element");
1369
1370 hr = Iis7PutPropertyString(pElement, IIS_CONFIG_NAME, pwzHeaderName);
1371 ExitOnFailure(hr, "Failed to set header name");
1372 }
1373
1374 hr = Iis7PutPropertyString(pElement, IIS_CONFIG_VALUE, pwzHeaderValue);
1375 ExitOnFailure(hr, "Failed to set header Value");
1376
1377 if (!fFound)
1378 {
1379 hr = pCollection->AddElement(pElement);
1380 ExitOnFailure(hr, "Failed add http header");
1381 }
1382
1383 }
1384 else
1385 {
1386 ExitOnFailure(hr = E_UNEXPECTED, "Unexpected IIS Config action specified for http header");
1387 }
1388
1389 // Get AppExt action
1390 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iAction);
1391 ExitOnFailure(hr, "Failed to read filter action");
1392 }
1393
1394LExit:
1395 ReleaseStr(pwzConfigPath);
1396 ReleaseStr(pwzSiteName);
1397 ReleaseStr(pwzAppName);
1398 ReleaseStr(pwzHeaderName);
1399 ReleaseStr(pwzHeaderValue);
1400 ReleaseObject(pElementHeaders);
1401 ReleaseObject(pElement);
1402 ReleaseObject(pSection);
1403 ReleaseObject(pCollection);
1404
1405 return hr;
1406}
1407
1408//-------------------------------------------------------------------------------------------------
1409// IIS7FilterGlobal
1410// Called by WriteIIS7ConfigChanges
1411// Processes Filter CA Data
1412//
1413//-------------------------------------------------------------------------------------------------
1414HRESULT IIS7FilterGlobal(
1415 __inout LPWSTR *ppwzCustomActionData,
1416 __in IAppHostWritableAdminManager *pAdminMgr
1417 )
1418{
1419 HRESULT hr = S_OK;
1420 int iAction = 0;
1421
1422 IAppHostElement *pSection = NULL;
1423
1424 hr = pAdminMgr->GetAdminSection(ScopeBSTR(IIS_CONFIG_ISAPI_SECTION), ScopeBSTR(IIS_CONFIG_APPHOST_ROOT), &pSection);
1425 ExitOnFailure(hr, "Failed get sites section");
1426
1427 if (!pSection)
1428 {
1429 hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
1430 ExitOnFailure(hr, "Failed get isapiFilters section object");
1431 }
1432
1433 // Get filter action
1434 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iAction);
1435 ExitOnFailure(hr, "Failed to read filter action");
1436
1437 while (IIS_FILTER_END != iAction)
1438 {
1439 //Process property action
1440 switch (iAction)
1441 {
1442 case IIS_FILTER :
1443 {
1444 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iAction);
1445 ExitOnFailure(hr, "Failed to read filter action");
1446
1447 if (iAction == IIS_CREATE)
1448 {
1449 hr = CreateGlobalFilter(ppwzCustomActionData, pSection);
1450 }
1451 else
1452 {
1453 hr = DeleteGlobalFilter(ppwzCustomActionData, pSection);
1454 }
1455 break;
1456 }
1457 default:
1458 {
1459 ExitOnFailure(hr = E_UNEXPECTED, "Unexpected IIS Config action specified for global filter");
1460 break;
1461 }
1462 }
1463 // Get AppExt action
1464 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iAction);
1465 ExitOnFailure(hr, "Failed to read filter action");
1466
1467 }
1468
1469LExit:
1470 ReleaseObject(pSection);
1471
1472 return hr;
1473}
1474
1475static HRESULT CreateGlobalFilter( __inout LPWSTR *ppwzCustomActionData, IAppHostElement *pSection)
1476{
1477 HRESULT hr = S_OK;
1478
1479 LPWSTR pwzFilterName = NULL;
1480 LPWSTR pwzSiteName = NULL;
1481 LPWSTR pwzFilterPath = NULL;
1482 int iLoadOrder = 0;
1483 DWORD cFilters = 0;
1484
1485 IAppHostElement *pElement = NULL;
1486 IAppHostElementCollection *pCollection = NULL;
1487
1488 hr = pSection->get_Collection(&pCollection);
1489 ExitOnFailure(hr, "Failed get filter collection");
1490
1491 hr = pCollection->get_Count(&cFilters);
1492 ExitOnFailure(hr, "Failed get filter collection count");
1493
1494 // Attempt to delete, we will we recreate with desired property values and order
1495 hr = DeleteCollectionElement(pCollection, IIS_CONFIG_FILTER, IIS_CONFIG_NAME, pwzFilterName);
1496 ExitOnFailure(hr, "Failed to delete filter");
1497
1498 //make a new element
1499 hr = pCollection->CreateNewElement(ScopeBSTR(IIS_CONFIG_FILTER), &pElement);
1500 ExitOnFailure(hr, "Failed to create filter config element");
1501
1502 //filter Name key
1503 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzFilterName);
1504 ExitOnFailure(hr, "Failed to read filter name");
1505 hr = Iis7PutPropertyString(pElement, IIS_CONFIG_NAME, pwzFilterName);
1506 ExitOnFailure(hr, "Failed to set filter name");
1507
1508 //web site name
1509 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzSiteName);
1510 ExitOnFailure(hr, "Failed to read filter site name");
1511
1512 // filter path
1513 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzFilterPath);
1514 ExitOnFailure(hr, "Failed to read filter path");
1515 hr = Iis7PutPropertyString(pElement,IIS_CONFIG_PATH, pwzFilterPath);
1516 ExitOnFailure(hr, "Failed to set filter path");
1517
1518 //filter load order
1519 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iLoadOrder);
1520 ExitOnFailure(hr, "Failed to read filter load order");
1521
1522 // put element in order in list
1523 int iPosition = -1;
1524 int icFilters = cFilters;
1525 switch (iLoadOrder)
1526 {
1527 case 0 :
1528 {
1529 iPosition = -1;
1530 break;
1531 }
1532 case -1 :
1533 {
1534 iPosition = icFilters;
1535 break;
1536 }
1537 case MSI_NULL_INTEGER :
1538 {
1539 iPosition = icFilters;
1540 break;
1541 }
1542 default:
1543 {
1544 if (iLoadOrder > icFilters)
1545 {
1546 iPosition = icFilters;
1547 }
1548 else
1549 {
1550 iPosition = iLoadOrder;
1551 }
1552 break;
1553 }
1554 }
1555 hr = pCollection->AddElement(pElement, iPosition);
1556 ExitOnFailure(hr, "Failed to add filter element");
1557
1558LExit:
1559 ReleaseStr(pwzFilterName);
1560 ReleaseStr(pwzSiteName);
1561 ReleaseStr(pwzFilterPath);
1562 ReleaseObject(pCollection);
1563 ReleaseObject(pElement);
1564
1565 return hr;
1566}
1567
1568static HRESULT DeleteGlobalFilter( __inout LPWSTR *ppwzCustomActionData, IAppHostElement *pSection)
1569{
1570 HRESULT hr = S_OK;
1571
1572 LPWSTR pwzFilterName = NULL;
1573 LPWSTR pwzSiteName = NULL;
1574
1575 IAppHostElementCollection *pCollection = NULL;
1576
1577 hr = pSection->get_Collection(&pCollection);
1578 ExitOnFailure(hr, "Failed get filter collection");
1579
1580 //filter Name key
1581 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzFilterName);
1582 ExitOnFailure(hr, "Failed to read filter name");
1583
1584 //web site name
1585 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzSiteName); // TODO: unused?
1586 ExitOnFailure(hr, "Failed to read filter site name");
1587
1588 DeleteCollectionElement(pCollection, IIS_CONFIG_FILTER, IIS_CONFIG_NAME, pwzFilterName);
1589 ExitOnFailure(hr, "Failed to delete filter %ls", pwzFilterName);
1590
1591LExit:
1592 ReleaseStr(pwzFilterName);
1593 ReleaseStr(pwzSiteName);
1594 ReleaseObject(pCollection);
1595
1596 return hr;
1597}
1598
1599//-------------------------------------------------------------------------------------------------
1600// IIS7FilterSite
1601// Called by WriteIIS7ConfigChanges
1602// Processes Filter CA Data
1603//
1604//-------------------------------------------------------------------------------------------------
1605HRESULT IIS7FilterSite(
1606 __inout LPWSTR *ppwzCustomActionData,
1607 __in IAppHostWritableAdminManager *pAdminMgr
1608 )
1609{
1610 HRESULT hr = S_OK;
1611 int iAction = 0;
1612
1613 // Get filter action
1614 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iAction);
1615 ExitOnFailure(hr, "Failed to read filter action");
1616
1617 while (IIS_FILTER_END != iAction)
1618 {
1619 //Process property action
1620 switch (iAction)
1621 {
1622 case IIS_FILTER :
1623 {
1624 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iAction);
1625 ExitOnFailure(hr, "Failed to read filter action");
1626
1627 if (iAction == IIS_CREATE)
1628 {
1629 hr = CreateSiteFilter(ppwzCustomActionData, pAdminMgr);
1630 }
1631 else
1632 {
1633 hr = DeleteSiteFilter(ppwzCustomActionData, pAdminMgr);
1634 }
1635 break;
1636 }
1637 default:
1638 {
1639 ExitOnFailure(hr = E_UNEXPECTED, "Unexpected IIS Config action specified for global filter");
1640 break;
1641 }
1642 }
1643
1644 // Get AppExt action
1645 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iAction);
1646 ExitOnFailure(hr, "Failed to read filter action");
1647 }
1648
1649LExit:
1650 return hr;
1651
1652}
1653
1654static HRESULT CreateSiteFilter(__inout LPWSTR *ppwzCustomActionData, IAppHostWritableAdminManager *pAdminMgr)
1655{
1656 HRESULT hr = S_OK;
1657 LPWSTR pwzFilterName = NULL;
1658 LPWSTR pwzSiteName = NULL;
1659 LPWSTR pwzFilterPath = NULL;
1660 LPWSTR pwzConfigPath = NULL;
1661 int iLoadOrder = 0;
1662 DWORD cFilters;
1663
1664 IAppHostElement *pElement = NULL;
1665 IAppHostElement *pSection = NULL;
1666 IAppHostElementCollection *pCollection = NULL;
1667
1668 //filter Name key
1669 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzFilterName);
1670 ExitOnFailure(hr, "Failed to read filter name");
1671
1672 //web site name
1673 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzSiteName);
1674 ExitOnFailure(hr, "Failed to read filter site name");
1675
1676 //Construct config root
1677 hr = StrAllocFormatted(&pwzConfigPath, L"%s/%s", IIS_CONFIG_APPHOST_ROOT, pwzSiteName);
1678 ExitOnFailure(hr, "failed to format filter config path");
1679
1680 //get admin isapiFilters section at config path location tag
1681 hr = pAdminMgr->GetAdminSection(ScopeBSTR(IIS_CONFIG_ISAPI_SECTION), pwzConfigPath, &pSection);
1682 ExitOnFailure(hr, "Failed get isapiFilters section");
1683
1684 hr = pSection->get_Collection(&pCollection);
1685 ExitOnFailure(hr, "Failed get filter collection");
1686
1687 hr = pCollection->get_Count(&cFilters);
1688 ExitOnFailure(hr, "Failed get filter collection count");
1689
1690 // Attempt to delete, we will we recreate with desired property values and order
1691 hr = DeleteCollectionElement(pCollection, IIS_CONFIG_FILTER, IIS_CONFIG_NAME, pwzFilterName);
1692 ExitOnFailure(hr, "Failed to delete filter");
1693
1694 //make a new element
1695 hr = pCollection->CreateNewElement(ScopeBSTR(IIS_CONFIG_FILTER), &pElement);
1696 ExitOnFailure(hr, "Failed to create filter config element");
1697
1698 hr = Iis7PutPropertyString(pElement,IIS_CONFIG_NAME, pwzFilterName);
1699 ExitOnFailure(hr, "Failed to set filter name");
1700
1701 // filter path
1702 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzFilterPath);
1703 ExitOnFailure(hr, "Failed to read filter path");
1704
1705 hr = Iis7PutPropertyString(pElement, IIS_CONFIG_PATH, pwzFilterPath);
1706 ExitOnFailure(hr, "Failed to set filter path");
1707
1708 //filter load order
1709 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iLoadOrder);
1710 ExitOnFailure(hr, "Failed to read filter load order");
1711
1712 // put element in order in list
1713 int iPosition = -1;
1714 int icFilters = cFilters;
1715 switch (iLoadOrder)
1716 {
1717 case 0 :
1718 {
1719 iPosition = -1;
1720 break;
1721 }
1722 case -1 :
1723 {
1724 iPosition = icFilters;
1725 break;
1726 }
1727 case MSI_NULL_INTEGER :
1728 {
1729 iPosition = icFilters;
1730 break;
1731 }
1732 default:
1733 {
1734 if (iLoadOrder > icFilters)
1735 {
1736 iPosition = icFilters;
1737 }
1738 else
1739 {
1740 iPosition = iLoadOrder;
1741 }
1742 break;
1743 }
1744 }
1745
1746 hr = pCollection->AddElement(pElement, iPosition);
1747 ExitOnFailure(hr, "Failed to add filter element");
1748
1749LExit:
1750 ReleaseStr(pwzFilterName);
1751 ReleaseStr(pwzSiteName);
1752 ReleaseStr(pwzFilterPath);
1753 ReleaseStr(pwzConfigPath);
1754 ReleaseObject(pElement);
1755 ReleaseObject(pSection);
1756 ReleaseObject(pCollection);
1757
1758 return hr;
1759}
1760
1761static HRESULT DeleteSiteFilter(__inout LPWSTR *ppwzCustomActionData, IAppHostWritableAdminManager *pAdminMgr)
1762{
1763 HRESULT hr = S_OK;
1764 LPWSTR pwzFilterName = NULL;
1765 LPWSTR pwzSiteName = NULL;
1766 LPWSTR pwzConfigPath = NULL;
1767
1768 IAppHostElement *pSection = NULL;
1769 IAppHostElementCollection *pCollection = NULL;
1770
1771 //filter Name key
1772 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzFilterName);
1773 ExitOnFailure(hr, "Failed to read filter name");
1774
1775 //web site name
1776 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzSiteName);
1777 ExitOnFailure(hr, "Failed to read filter site name");
1778
1779 //Construct config root
1780 hr = StrAllocFormatted(&pwzConfigPath, L"%s/%s", IIS_CONFIG_APPHOST_ROOT, pwzSiteName);
1781 ExitOnFailure(hr, "failed to format filter config path");
1782
1783 //get admin isapiFilters section at config path location tag
1784 hr = pAdminMgr->GetAdminSection(ScopeBSTR(IIS_CONFIG_ISAPI_SECTION), pwzConfigPath, &pSection);
1785 ExitOnFailure(hr, "Failed get isapiFilters section");
1786
1787 hr = pSection->get_Collection(&pCollection);
1788 ExitOnFailure(hr, "Failed get filter collection");
1789
1790 DeleteCollectionElement(pCollection, IIS_CONFIG_FILTER, IIS_CONFIG_NAME, pwzFilterName);
1791 ExitOnFailure(hr, "Failed to delete filter %ls", pwzFilterName);
1792
1793LExit:
1794 ReleaseStr(pwzFilterName);
1795 ReleaseStr(pwzSiteName);
1796 ReleaseStr(pwzConfigPath);
1797 ReleaseObject(pSection);
1798 ReleaseObject(pCollection);
1799
1800 return hr;
1801}
1802
1803//-------------------------------------------------------------------------------------------------
1804// IIS7Site
1805// Called by WriteIIS7ConfigChanges
1806// Processes WebSite CA Data
1807//
1808//-------------------------------------------------------------------------------------------------
1809HRESULT IIS7Site(
1810 __inout LPWSTR *ppwzCustomActionData,
1811 __in IAppHostWritableAdminManager *pAdminMgr)
1812{
1813 HRESULT hr = S_OK;
1814 int iAction = -1;
1815 int iData = 0;
1816 BOOL fFound = FALSE;
1817
1818 LPWSTR pwzSiteName = NULL;
1819 IAppHostElement *pSites = NULL;
1820 IAppHostElementCollection *pCollection = NULL;
1821 IAppHostElement *pSiteElem = NULL;
1822 IAppHostElement *pElement = NULL;
1823
1824 // Get site action
1825 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iAction);
1826 ExitOnFailure(hr, "Failed to read site action");
1827
1828 //get site name
1829 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzSiteName);
1830 ExitOnFailure(hr, "Failed to read site key");
1831
1832 //Get site if it exists
1833 hr = GetSiteElement(pAdminMgr, pwzSiteName, &pSiteElem, &fFound);
1834 ExitOnFailure(hr, "Failed to read sites from config");
1835
1836 hr = pAdminMgr->GetAdminSection(ScopeBSTR(IIS_CONFIG_SITES_SECTION), ScopeBSTR(IIS_CONFIG_APPHOST_ROOT), &pSites);
1837 ExitOnFailure(hr, "Failed get sites section");
1838 ExitOnNull(pSites, hr, ERROR_FILE_NOT_FOUND, "Failed get sites section object");
1839
1840 hr = pSites->get_Collection( &pCollection);
1841 ExitOnFailure(hr, "Failed get site collection");
1842 switch (iAction)
1843 {
1844 case IIS_DELETE :
1845 {
1846 if (fFound)
1847 {
1848 hr = DeleteCollectionElement(pCollection, IIS_CONFIG_SITE, IIS_CONFIG_NAME, pwzSiteName);
1849 ExitOnFailure(hr, "Failed to delete website");
1850 }
1851 ExitFunction();
1852 break;
1853 }
1854 case IIS_CREATE :
1855 {
1856 if (!fFound)
1857 {
1858 //Create the site
1859 hr = CreateSite(pCollection, pwzSiteName, &pSiteElem);
1860 ExitOnFailure(hr, "Failed to create site");
1861
1862 }
1863 }
1864 }
1865 //
1866 //Set other Site properties
1867 //
1868 //set site Id
1869 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iData);
1870 ExitOnFailure(hr, "Failed to read site Id");
1871 if (iData != MSI_NULL_INTEGER && -1 != iData)
1872 {
1873 hr = Iis7PutPropertyInteger(pSiteElem, IIS_CONFIG_SITE_ID, iData);
1874 ExitOnFailure(hr, "Failed set site Id data");
1875 }
1876 //Set Site AutoStart
1877 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iData);
1878 ExitOnFailure(hr, "Failed to read site autostart");
1879 if (MSI_NULL_INTEGER != iData)
1880 {
1881 hr = Iis7PutPropertyBool(pSiteElem, IIS_CONFIG_AUTOSTART, iData);
1882 ExitOnFailure(hr, "Failed set site config data");
1883 }
1884
1885 //Set Site Connection timeout
1886 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iData);
1887 ExitOnFailure(hr, "Failed to read site connection tomeout data");
1888 if (MSI_NULL_INTEGER != iData)
1889 {
1890 // get limits element, get connectionTimeout property
1891 hr = pSiteElem->GetElementByName(ScopeBSTR(IIS_CONFIG_LIMITS), &pElement);
1892 ExitOnFailure(hr, "Failed to read limits from config");
1893 //convert iData in seconds to timeSpan hh:mm:ss
1894 WCHAR wcTime[60];
1895 *wcTime = '\0';
1896 ConvSecToHMS( iData, wcTime, countof( wcTime));
1897
1898 hr = Iis7PutPropertyString(pElement, IIS_CONFIG_CONNECTTIMEOUT, wcTime);
1899 ExitOnFailure(hr, "IIS: failed set connection timeout config data");
1900 }
1901
1902LExit:
1903 ReleaseStr(pwzSiteName);
1904 ReleaseObject(pSites);
1905 ReleaseObject(pCollection);
1906 ReleaseObject(pSiteElem);
1907 ReleaseObject(pElement);
1908
1909 return hr;
1910}
1911//-------------------------------------------------------------------------------------------------
1912// IIS7Application
1913// Processes Application CA Data
1914//
1915//
1916//-------------------------------------------------------------------------------------------------
1917
1918HRESULT IIS7Application(
1919 __inout LPWSTR *ppwzCustomActionData,
1920 __in IAppHostWritableAdminManager *pAdminMgr)
1921{
1922 HRESULT hr = S_OK;
1923
1924 int iAction = -1;
1925 BOOL fSiteFound = FALSE;
1926 BOOL fAppFound = FALSE;
1927
1928 LPWSTR pwzSiteName = NULL;
1929 LPWSTR pwzAppPath = NULL;
1930 LPWSTR pwzAppPool = NULL;
1931 LPWSTR pwzLocationPath = NULL;
1932 IAppHostElement *pSiteElem = NULL;
1933 IAppHostElement *pAppElement = NULL;
1934 // Get Application action
1935 hr = WcaReadIntegerFromCaData( ppwzCustomActionData, &iAction);
1936 ExitOnFailure(hr, "Failed to read application action")
1937 //get site key name
1938 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzSiteName);
1939 ExitOnFailure(hr, "Failed to read app site key");
1940 //get application path
1941 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzAppPath);
1942 ExitOnFailure(hr, "Failed to read app path key");
1943 //get application Pool
1944 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzAppPool);
1945 ExitOnFailure(hr, "Failed to read app pool key");
1946
1947 //Get site if it exists
1948 hr = GetSiteElement(pAdminMgr, pwzSiteName, &pSiteElem, &fSiteFound);
1949 ExitOnFailure(hr, "Failed to read sites from config");
1950
1951 switch (iAction)
1952 {
1953 case IIS_CREATE :
1954 {
1955 if (fSiteFound)
1956 {
1957 //have site get application collection
1958 hr = GetApplicationElement(pSiteElem,
1959 pwzAppPath,
1960 &pAppElement,
1961 &fAppFound);
1962 ExitOnFailure(hr, "Error reading application from config");
1963
1964 if (!fAppFound)
1965 {
1966 //Create Application
1967 hr = CreateApplication(pSiteElem, pwzAppPath, &pAppElement);
1968 ExitOnFailure(hr, "Error creating application in config");
1969 }
1970 //Update application properties:
1971 //
1972 //Set appPool
1973 hr = SetAppPool(pAppElement, pwzAppPool);
1974 ExitOnFailure(hr, "Unable to set appPool for application");
1975 }
1976 else
1977 {
1978 hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
1979 ExitOnFailure(hr, "Site not found for create application");
1980 }
1981 break;
1982 }
1983 case IIS_DELETE :
1984 {
1985 if (fSiteFound)
1986 {
1987 //have site get application collection
1988 hr = GetApplicationElement( pSiteElem,
1989 pwzAppPath,
1990 &pAppElement,
1991 &fAppFound);
1992 ExitOnFailure(hr, "Error reading application from config")
1993 if (fAppFound)
1994 {
1995 //delete Application
1996 hr = DeleteApplication(pSiteElem, pwzAppPath);
1997 ExitOnFailure(hr, "Error deleating application from config")
1998 //Construct Location path
1999 // TODO: it seems odd that these are just
2000 // jammed together, need to determine if this requires a '\'
2001 hr = StrAllocString(&pwzLocationPath, pwzSiteName, 0);
2002 ExitOnFailure(hr, "failed to copy location config path web name");
2003 hr = StrAllocConcat(&pwzLocationPath, pwzAppPath, 0);
2004 ExitOnFailure(hr, "failed to copy location config path appPath ");
2005
2006 // and delete location tag for this application
2007 hr = ClearLocationTag(pAdminMgr, pwzLocationPath);
2008 ExitOnFailure(hr, "failed to clear location tag for %ls", pwzLocationPath);
2009 }
2010 }
2011 break;
2012 }
2013 default:
2014 ExitOnFailure(hr = E_UNEXPECTED, "Unexpected IIS Config action specified for Application");
2015 break;
2016 }
2017
2018LExit:
2019 ReleaseStr(pwzSiteName);
2020 ReleaseStr(pwzAppPath);
2021 ReleaseStr(pwzAppPool);
2022 ReleaseStr(pwzLocationPath);
2023 ReleaseObject(pSiteElem);
2024 ReleaseObject(pAppElement);
2025
2026 return hr;
2027}
2028//-------------------------------------------------------------------------------------------------
2029// IIS7VDir
2030// Processes VDir CA Data
2031//
2032//
2033//-------------------------------------------------------------------------------------------------
2034HRESULT IIS7VDir(
2035 __inout LPWSTR *ppwzCustomActionData,
2036 __in IAppHostWritableAdminManager *pAdminMgr)
2037{
2038 HRESULT hr = S_OK;
2039
2040 int iAction = -1;
2041 BOOL fSiteFound = FALSE;
2042 BOOL fAppFound = FALSE;
2043
2044 LPWSTR pwzSiteName = NULL;
2045 LPWSTR pwzVDirPath = NULL;
2046 LPWSTR pwzVDirPhyDir = NULL;
2047 LPCWSTR pwzVDirSubPath = NULL;
2048
2049 IAppHostElement *pSiteElem = NULL;
2050 IAppHostElement *pAppElement = NULL;
2051 IAppHostElementCollection *pElement = NULL;
2052
2053 // Get Application action
2054 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iAction);
2055 ExitOnFailure(hr, "Failed to read VDir action");
2056
2057 //get site key name
2058 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzSiteName);
2059 ExitOnFailure(hr, "Failed to read site key");
2060 //get VDir path
2061 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzVDirPath);
2062 ExitOnFailure(hr, "Failed to read VDir key");
2063 //get physical dir path
2064 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzVDirPhyDir);
2065 ExitOnFailure(hr, "Failed to read VDirPath key");
2066
2067 //Get site if it exists
2068 hr = GetSiteElement(pAdminMgr, pwzSiteName, &pSiteElem, &fSiteFound);
2069 ExitOnFailure(hr, "Failed to read sites from config");
2070
2071 if (IIS_CREATE == iAction)
2072 {
2073 if (fSiteFound)
2074 {
2075 //have site get application
2076 hr = GetApplicationElementForVDir( pSiteElem,
2077 pwzVDirPath,
2078 &pAppElement,
2079 &pwzVDirSubPath,
2080 &fAppFound);
2081 ExitOnFailure(hr, "Error reading application element from config");
2082
2083 if (!fAppFound)
2084 {
2085 // need application to add vDir
2086 hr = E_FILENOTFOUND;
2087 ExitOnFailure(hr, "Error application not found for create VDir");
2088 }
2089 //
2090 // create the virDir
2091 //
2092 hr = CreateVdir(pAppElement, pwzVDirSubPath, pwzVDirPhyDir);
2093 ExitOnFailure(hr, "Failed to create vdir for application");
2094 }
2095 else
2096 {
2097 hr = E_FILENOTFOUND;
2098 ExitOnFailure(hr, "IIS: site not found for create VDir");
2099 }
2100 }
2101 else if (IIS_DELETE == iAction)
2102 {
2103 if (fSiteFound)
2104 {
2105 //have site get application
2106 hr = GetApplicationElementForVDir( pSiteElem,
2107 pwzVDirPath,
2108 &pAppElement,
2109 &pwzVDirSubPath,
2110 &fAppFound);
2111 ExitOnFailure(hr, "Error reading application from config")
2112 if (fAppFound)
2113 {
2114 //delete vdir
2115 hr = DeleteVdir(pAppElement, pwzVDirSubPath);
2116 ExitOnFailure(hr, "Unable to delete vdir for application");
2117 }
2118 }
2119 }
2120
2121 LExit:
2122 ReleaseStr(pwzSiteName);
2123 ReleaseStr(pwzVDirPath);
2124 ReleaseStr(pwzVDirPhyDir);
2125 ReleaseObject(pSiteElem);
2126 ReleaseObject(pAppElement);
2127 ReleaseObject(pElement);
2128
2129 return hr;
2130}
2131
2132//-------------------------------------------------------------------------------------------------
2133// IIS7Binding
2134// Processes Bindings CA Data
2135//
2136//
2137//-------------------------------------------------------------------------------------------------
2138HRESULT IIS7Binding(
2139 __inout LPWSTR *ppwzCustomActionData,
2140 __in IAppHostWritableAdminManager *pAdminMgr)
2141{
2142 HRESULT hr = S_OK;
2143
2144 int iAction = -1;
2145 BOOL fSiteFound = FALSE;
2146
2147 LPWSTR pwzSiteName = NULL;
2148 LPWSTR pwzProtocol = NULL;
2149 LPWSTR pwzInfo = NULL;
2150
2151 IAppHostElement *pSiteElem = NULL;
2152
2153 // Get Application action
2154 hr = WcaReadIntegerFromCaData( ppwzCustomActionData, &iAction);
2155 ExitOnFailure(hr, "Failed to read binding action");
2156
2157 //get site key name
2158 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzSiteName);
2159 ExitOnFailure(hr, "Failed to read binding site name key");
2160
2161 //get binding protocol
2162 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzProtocol);
2163 ExitOnFailure(hr, "Failed to read binding protocol");
2164
2165 //get binding info
2166 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzInfo);
2167 ExitOnFailure(hr, "Failed to read binding info");
2168
2169 //Get site if it exists
2170 hr = GetSiteElement(pAdminMgr, pwzSiteName, &pSiteElem, &fSiteFound);
2171 ExitOnFailure(hr, "Failed to read sites from config");
2172
2173 if (IIS_CREATE == iAction)
2174 {
2175 if (fSiteFound)
2176 {
2177 //add binding
2178 hr = CreateBinding(pSiteElem, pwzProtocol, pwzInfo);
2179 ExitOnFailure(hr, "Failed to create site binding");
2180 }
2181 else
2182 {
2183 hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
2184 ExitOnFailure(hr, "Site not found for create binding");
2185 }
2186 }
2187 else if (IIS_DELETE == iAction)
2188 {
2189 if (fSiteFound)
2190 {
2191 //delete binding
2192 hr = DeleteBinding(pSiteElem, pwzProtocol, pwzInfo);
2193 ExitOnFailure(hr, "Failed to delete binding");
2194 }
2195 }
2196
2197 LExit:
2198 ReleaseStr(pwzSiteName);
2199 ReleaseStr(pwzProtocol);
2200 ReleaseStr(pwzInfo);
2201 ReleaseObject(pSiteElem);
2202
2203 return hr;
2204}
2205//-------------------------------------------------------------------------------------------------
2206// IIS7Binding
2207// Processes WebLog CA Data
2208//
2209//
2210//-------------------------------------------------------------------------------------------------
2211HRESULT IIS7WebLog(
2212 __inout LPWSTR *ppwzCustomActionData,
2213 __in IAppHostWritableAdminManager *pAdminMgr)
2214{
2215 HRESULT hr = S_OK;
2216
2217 BOOL fSiteFound = FALSE;
2218
2219 LPWSTR pwzSiteName = NULL;
2220 LPWSTR pwzLogFormat = NULL;
2221
2222 IAppHostElement *pSiteElem = NULL;
2223
2224 //get site key name
2225 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzSiteName);
2226 ExitOnFailure(hr, "Failed to read web log site name key");
2227
2228 //get log format
2229 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzLogFormat);
2230 ExitOnFailure(hr, "Failed to read web log protocol");
2231
2232 //Get site if it exists
2233 hr = GetSiteElement(pAdminMgr, pwzSiteName, &pSiteElem, &fSiteFound);
2234 ExitOnFailure(hr, "Failed to read web log sites from config");
2235
2236 if (fSiteFound)
2237 {
2238 //add log format
2239 hr = CreateWebLog(pSiteElem, pwzLogFormat);
2240 ExitOnFailure(hr, "Failed to create weblog file format");
2241 }
2242 else
2243 {
2244 hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
2245 ExitOnFailure(hr, "Site not found for create weblog file format");
2246 }
2247
2248 LExit:
2249 ReleaseStr(pwzSiteName);
2250 ReleaseStr(pwzLogFormat);
2251 ReleaseObject(pSiteElem);
2252
2253 return hr;
2254}
2255//-------------------------------------------------------------------------------------------------
2256// IIS7AppPool
2257// Processes AppPool CA Data
2258//
2259//
2260//-------------------------------------------------------------------------------------------------
2261HRESULT IIS7AppPool(
2262 __inout LPWSTR *ppwzCustomActionData,
2263 __in IAppHostWritableAdminManager *pAdminMgr
2264 )
2265{
2266 HRESULT hr = S_OK;
2267
2268 int iAction = -1;
2269
2270 LPWSTR pwzAppPoolName = NULL;
2271
2272 // Get AppPool action
2273 hr = WcaReadIntegerFromCaData( ppwzCustomActionData, &iAction);
2274 ExitOnFailure(hr, "Failed to read AppPool action");
2275
2276 //get appPool name
2277 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzAppPoolName);
2278 ExitOnFailure(hr, "Failed to read AppPool name key");
2279
2280 switch (iAction)
2281 {
2282 case IIS_CREATE :
2283 {
2284 hr = CreateAppPool(ppwzCustomActionData, pAdminMgr, pwzAppPoolName);
2285 break;
2286 }
2287 case IIS_DELETE:
2288 {
2289 hr = DeleteAppPool(pAdminMgr, pwzAppPoolName);
2290 break;
2291 }
2292 default:
2293 ExitOnFailure(hr = E_UNEXPECTED, "Unexpected IIS Config action specified for appPool");
2294 break;
2295 }
2296
2297LExit:
2298 ReleaseStr(pwzAppPoolName);
2299 return hr;
2300}
2301
2302//-------------------------------------------------------------------------------------------------
2303// IIS7AppExtension
2304// Processes AppExtension (config handlers) CA Data
2305//
2306//
2307//-------------------------------------------------------------------------------------------------
2308HRESULT IIS7AppExtension(
2309 __inout LPWSTR *ppwzCustomActionData,
2310 __in IAppHostWritableAdminManager *pAdminMgr)
2311{
2312 HRESULT hr = S_OK;
2313
2314 LPWSTR pwzWebName = NULL;
2315 LPWSTR pwzWebRoot = NULL;
2316 LPWSTR pwzData = NULL;
2317 LPWSTR pwzConfigPath = NULL;
2318 LPWSTR pwzHandlerName = NULL;
2319 LPWSTR pwzPath = NULL;
2320 int iAction = -1;
2321
2322 IAppHostElement *pSection = NULL;
2323 IAppHostElement *pElement = NULL;
2324 IAppHostElementCollection *pCollection = NULL;
2325
2326 BOOL fFound = FALSE;
2327 DWORD cHandlers = 1000;
2328
2329 //get web name
2330 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzWebName);
2331 ExitOnFailure(hr, "Failed to read appExt Web name key");
2332
2333 //get root name
2334 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzWebRoot);
2335 ExitOnFailure(hr, "Failed to read appExt Web name key");
2336
2337 //Construct config root
2338 hr = StrAllocFormatted(&pwzConfigPath, L"%s/%s", IIS_CONFIG_APPHOST_ROOT, pwzWebName);
2339 ExitOnFailure(hr, "failed to format appext config path");
2340 //
2341 //Do not append trailing '/' for default vDir
2342 //
2343 if (CSTR_EQUAL != ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, pwzWebRoot, -1, L"/", -1))
2344 {
2345 hr = StrAllocConcat(&pwzConfigPath, L"/", 0);
2346 ExitOnFailure(hr, "failed to copy appext config path delim");
2347 hr = StrAllocConcat(&pwzConfigPath, pwzWebRoot, 0);
2348 ExitOnFailure(hr, "failed to copy appext config path root name");
2349 }
2350 //get admin handlers section at config path location tag
2351 hr = pAdminMgr->GetAdminSection(ScopeBSTR(IIS_CONFIG_HANDLERS_SECTION), pwzConfigPath, &pSection);
2352 ExitOnFailure(hr, "Failed get appext section");
2353
2354 if (!pSection)
2355 {
2356 hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
2357 ExitOnFailure(hr, "Failed get appext section object");
2358 }
2359
2360 // Get AppExt action
2361 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iAction);
2362 ExitOnFailure(hr, "Failed to read appExt action");
2363
2364 hr = pSection->get_Collection(&pCollection);
2365 ExitOnFailure(hr, "Failed get handlers collection for appext");
2366
2367 while (IIS_APPEXT_END != iAction)
2368 {
2369 fFound = FALSE;
2370
2371 //Process property action
2372 switch (iAction)
2373 {
2374 case IIS_APPEXT :
2375 {
2376 // These IDs aren't really stable but this is stable enough to support repair since the MSI won't change
2377 hr = StrAllocFormatted(&pwzHandlerName, L"MsiCustom-%u", ++cHandlers);
2378 ExitOnFailure(hr, "Failed increment handler name");
2379
2380 hr = Iis7FindAppHostElementString(pCollection, IIS_CONFIG_ADD, IIS_CONFIG_NAME, pwzHandlerName, &pElement, NULL);
2381 ExitOnFailure(hr, "Failed to find mimemap extension");
2382
2383 fFound = (NULL != pElement);
2384 if (!fFound)
2385 {
2386 //create new handler element
2387 hr = pCollection->CreateNewElement(ScopeBSTR(IIS_CONFIG_ADD), &pElement);
2388 ExitOnFailure(hr, "Failed get create handler element for appext");
2389
2390 hr = Iis7PutPropertyString(pElement, IIS_CONFIG_NAME, pwzHandlerName);
2391 ExitOnFailure(hr, "Failed set appext name property");
2392 }
2393
2394 //BUGBUG: For compat we are assuming these are all ISAPI MODULES so we are
2395 //setting the modules property to IsapiModule.
2396 //Currently can't deal with handlers of different module types.
2397 hr = Iis7PutPropertyString(pElement, IIS_CONFIG_MODULES, L"IsapiModule");
2398 ExitOnFailure(hr, "Failed set site appExt path property");
2399
2400 //get extension (path)
2401 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzData);
2402 ExitOnFailure(hr, "Failed to read appExt extension");
2403 hr = StrAllocFormatted(&pwzPath, L"*.%s", pwzData);
2404 ExitOnFailure(hr, "Failed decorate appExt path");
2405 //put property
2406 hr = Iis7PutPropertyString(pElement, IIS_CONFIG_PATH, pwzPath);
2407 ExitOnFailure(hr, "Failed set site appExt path property");
2408
2409 //get executable
2410 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzData);
2411 ExitOnFailure(hr, "Failed to read appExt executable");
2412 //put property
2413 hr = Iis7PutPropertyString(pElement, IIS_CONFIG_EXECUTABLE, pwzData);
2414 ExitOnFailure(hr, "Failed set site appExt executable property");
2415
2416 //get verbs
2417 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzData);
2418 ExitOnFailure(hr, "Failed to read appExt verbs");
2419 //put property
2420 hr = Iis7PutPropertyString(pElement, IIS_CONFIG_VERBS, pwzData);
2421 ExitOnFailure(hr, "Failed set site appExt verbs property");
2422
2423 break;
2424 }
2425 default:
2426 {
2427 ExitOnFailure(hr = E_UNEXPECTED, "Unexpected IIS Config action specified for AppExt");
2428 break;
2429 }
2430 }
2431
2432 if (!fFound)
2433 {
2434 // put handler element at beginning of list
2435 hr = pCollection->AddElement(pElement, 0);
2436 ExitOnFailure(hr, "Failed add handler element for appext");
2437 }
2438
2439 ReleaseNullObject(pElement);
2440
2441 // Get AppExt action
2442 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iAction);
2443 ExitOnFailure(hr, "Failed to read AppPool Property action");
2444 }
2445
2446LExit:
2447 ReleaseStr(pwzWebName);
2448 ReleaseStr(pwzWebRoot);
2449 ReleaseStr(pwzData);
2450 ReleaseStr(pwzConfigPath);
2451 ReleaseStr(pwzHandlerName);
2452 ReleaseStr(pwzPath);
2453 ReleaseObject(pSection);
2454 ReleaseObject(pElement);
2455 ReleaseObject(pCollection);
2456
2457 return hr;
2458}
2459
2460//-------------------------------------------------------------------------------------------------
2461// IIS7MimeMap
2462// Processes Mime Map (config handlers) CA Data
2463//
2464//
2465//-------------------------------------------------------------------------------------------------
2466 HRESULT IIS7MimeMap(
2467 __inout LPWSTR *ppwzCustomActionData,
2468 __in IAppHostWritableAdminManager *pAdminMgr
2469 )
2470{
2471 HRESULT hr = S_OK;
2472 LPWSTR pwzConfigPath = NULL;
2473 LPWSTR pwzWebName = NULL;
2474 LPWSTR pwzWebRoot = NULL;
2475 LPWSTR pwzData = NULL;
2476 int iAction = -1;
2477
2478 IAppHostElement *pSection = NULL;
2479 IAppHostElement *pElement = NULL;
2480 IAppHostElementCollection *pCollection = NULL;
2481
2482 BOOL fFound = FALSE;
2483
2484 //get web name
2485 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzWebName);
2486 ExitOnFailure(hr, "Failed to read mime map Web name key");
2487
2488 //get vdir root name
2489 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzWebRoot);
2490 ExitOnFailure(hr, "Failed to read vdir root name key");
2491
2492 //Construct config root
2493 hr = StrAllocFormatted(&pwzConfigPath, L"%s/%s", IIS_CONFIG_APPHOST_ROOT, pwzWebName);
2494 ExitOnFailure(hr, "failed to format mime map config path web name");
2495 //
2496 //Do not append trailing '/' for default vDir
2497 //
2498 if (CSTR_EQUAL != ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, pwzWebRoot, -1, L"/", -1))
2499 {
2500 hr = StrAllocConcat(&pwzConfigPath, L"/", 0);
2501 ExitOnFailure(hr, "failed to copy appext config path delim");
2502 hr = StrAllocConcat(&pwzConfigPath, pwzWebRoot, 0);
2503 ExitOnFailure(hr, "failed to copy appext config path root name");
2504 }
2505
2506 //get admin section <staticContent> at config path location tag
2507 hr = pAdminMgr->GetAdminSection(ScopeBSTR(IIS_CONFIG_STATICCONTENT_SECTION), pwzConfigPath, &pSection);
2508 ExitOnFailure(hr, "Failed get staticContent section for mimemap");
2509
2510 if (!pSection)
2511 {
2512 hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
2513 ExitOnFailure(hr, "Failed get staticContent section object");
2514 }
2515
2516 // Get mimemap action
2517 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iAction);
2518 ExitOnFailure(hr, "Failed to read mimemap action");
2519
2520 hr = pSection->get_Collection(&pCollection);
2521 ExitOnFailure(hr, "Failed get staticContent collection for mimemap");
2522
2523 while (IIS_MIMEMAP_END != iAction)
2524 {
2525 //Process property action
2526 switch (iAction)
2527 {
2528 case IIS_MIMEMAP :
2529 {
2530 //get extension
2531 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzData);
2532 ExitOnFailure(hr, "Failed to read mimemap extension");
2533
2534 hr = Iis7FindAppHostElementString(pCollection, IIS_CONFIG_MIMEMAP, IIS_CONFIG_FILEEXT, pwzData, &pElement, NULL);
2535 ExitOnFailure(hr, "Failed to find mimemap extension");
2536 fFound = (NULL != pElement);
2537
2538 if (!fFound)
2539 {
2540 //create new mimeMap element
2541 hr = pCollection->CreateNewElement(ScopeBSTR(IIS_CONFIG_MIMEMAP), &pElement);
2542 ExitOnFailure(hr, "Failed get create MimeMap element");
2543 }
2544
2545 //put property
2546 hr = Iis7PutPropertyString(pElement, IIS_CONFIG_FILEEXT, pwzData);
2547 ExitOnFailure(hr, "Failed set mimemap extension property");
2548
2549 //get type
2550 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzData);
2551 ExitOnFailure(hr, "Failed to read mimemap type");
2552 //put property
2553 hr = Iis7PutPropertyString(pElement, IIS_CONFIG_MIMETYPE, pwzData);
2554 ExitOnFailure(hr, "Failed set mimemap type property");
2555
2556 break;
2557 }
2558 default:
2559 {
2560 ExitOnFailure(hr = E_UNEXPECTED, "Unexpected IIS Config action specified for mimeMap");
2561 break;
2562 }
2563 }
2564
2565 if (!fFound)
2566 {
2567 // put mimeMap element at beginning of list
2568 hr = pCollection->AddElement(pElement, -1);
2569 ExitOnFailure(hr, "Failed add mimemap");
2570 }
2571
2572 // Get AppExt action
2573 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iAction);
2574 ExitOnFailure(hr, "Failed to read mimemap action");
2575
2576 ReleaseNullObject(pElement);
2577 }
2578
2579LExit:
2580 ReleaseStr(pwzConfigPath);
2581 ReleaseStr(pwzWebName);
2582 ReleaseStr(pwzWebRoot);
2583 ReleaseStr(pwzData);
2584 ReleaseObject(pSection);
2585 ReleaseObject(pElement);
2586 ReleaseObject(pCollection);
2587
2588 return hr;
2589}
2590
2591//-------------------------------------------------------------------------------------------------
2592// IIS7DirProperties
2593// ProcessesVdir Properties CA Data
2594//
2595//
2596//-------------------------------------------------------------------------------------------------
2597HRESULT IIS7DirProperties(
2598 __inout LPWSTR *ppwzCustomActionData,
2599 __in IAppHostWritableAdminManager *pAdminMgr
2600 )
2601{
2602 HRESULT hr = S_OK;
2603 WCHAR wcTime[60];
2604 LPWSTR pwzConfigPath = NULL;
2605 LPWSTR pwzWebName = NULL;
2606 LPWSTR pwzWebRoot = NULL;
2607 LPWSTR pwzData = NULL;
2608 int iAction = -1;
2609 int iData = 0;
2610 DWORD dwData = 0;
2611
2612 IAppHostElement *pSection = NULL;
2613 IAppHostElement *pElement = NULL;
2614 IAppHostElementCollection *pCollection = NULL;
2615
2616 //get web name
2617 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzWebName);
2618 ExitOnFailure(hr, "Failed to read DirProp Web name key");
2619
2620 //get vdir root name
2621 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzWebRoot);
2622 ExitOnFailure(hr, "Failed to read DirProp Web name key");
2623
2624 //Construct config root
2625 hr = StrAllocFormatted(&pwzConfigPath, L"%s/%s", IIS_CONFIG_APPHOST_ROOT, pwzWebName);
2626 ExitOnFailure(hr, "failed to format mime map config path web name");
2627 //
2628 //Do not append trailing '/' for default vDir
2629 //
2630 if (CSTR_EQUAL != ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, pwzWebRoot, -1, L"/", -1))
2631 {
2632 hr = StrAllocConcat(&pwzConfigPath, L"/", 0);
2633 ExitOnFailure(hr, "failed to copy appext config path delim");
2634 hr = StrAllocConcat(&pwzConfigPath, pwzWebRoot, 0);
2635 ExitOnFailure(hr, "failed to copy appext config path root name");
2636 }
2637
2638 // Get DirProps action
2639 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iAction);
2640 ExitOnFailure(hr, "Failed to read DirProps action");
2641
2642 while (IIS_DIRPROP_END != iAction)
2643 {
2644 //Process property action
2645 switch (iAction)
2646 {
2647 case IIS_DIRPROP_ACCESS :
2648 {
2649 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iData);
2650 ExitOnFailure(hr, "Failed to read DirProps access");
2651 //iData contains bit flags for <handlers accessPolicy="">
2652 //no translation required
2653 //get admin section at config path location tag
2654 hr = pAdminMgr->GetAdminSection(ScopeBSTR(IIS_CONFIG_HANDLERS_SECTION), pwzConfigPath, &pSection);
2655 ExitOnFailure(hr, "Failed get handlers section for DirProp");
2656 if (!pSection)
2657 {
2658 hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
2659 ExitOnFailure(hr, "Failed get handlers section object for DirProps");
2660 }
2661 dwData = iData;
2662 hr = Iis7PutPropertyInteger( pSection, L"accessPolicy", dwData);
2663 ExitOnFailure(hr, "Failed set accessPolicy for DirProps");
2664 ReleaseNullObject(pSection);
2665 break;
2666 }
2667 case IIS_DIRPROP_USER :
2668 {
2669 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzData);
2670 ExitOnFailure(hr, "Failed to read DirProps user");
2671 hr = pAdminMgr->GetAdminSection(ScopeBSTR(L"system.webServer/security/authentication/anonymousAuthentication"), pwzConfigPath, &pSection);
2672 ExitOnFailure(hr, "Failed get AnonymousAuthentication section for DirProp");
2673 hr = Iis7PutPropertyString( pSection, IIS_CONFIG_USERNAME, pwzData);
2674 ExitOnFailure(hr, "Failed set accessPolicy for DirProps");
2675 ReleaseNullObject(pSection);
2676 break;
2677 }
2678 case IIS_DIRPROP_PWD :
2679 {
2680 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzData);
2681 ExitOnFailure(hr, "Failed to read DirProps pwd");
2682 hr = pAdminMgr->GetAdminSection(ScopeBSTR(L"system.webServer/security/authentication/anonymousAuthentication"), pwzConfigPath, &pSection);
2683 ExitOnFailure(hr, "Failed get AnonymousAuthentication section for DirProp");
2684 hr = Iis7PutPropertyString( pSection, IIS_CONFIG_PASSWORD, pwzData);
2685 ExitOnFailure(hr, "Failed set accessPolicy for DirProps");
2686 ReleaseNullObject(pSection);
2687 break;
2688 }
2689 case IIS_DIRPROP_DEFDOCS :
2690 {
2691 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzData);
2692 ExitOnFailure(hr, "Failed to read DirProps def doc");
2693 hr = SetDirPropDefDoc(pAdminMgr, pwzConfigPath, pwzData);
2694 ExitOnFailure(hr, "Failed to set DirProps Default Documents");
2695 break;
2696 }
2697 case IIS_DIRPROP_AUTH :
2698 {
2699 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iData);
2700 ExitOnFailure(hr, "Failed to read DirProps auth");
2701 //iData contains bit flags for /security/authentication/<...>
2702 // Anonymous = 1
2703 // Basic = 2
2704 // Windows = 4
2705 // Digest =16
2706 // Passport =64 *not supported
2707 //translation required from bit map to section
2708 // E.G security/authentication/windowsAuthentication [property enabled true|false]
2709 dwData= iData;
2710 hr = SetDirPropAuthentications(pAdminMgr, pwzConfigPath, dwData);
2711 ExitOnFailure(hr, "Failed set Authentication for DirProps");
2712 break;
2713 }
2714 case IIS_DIRPROP_SSLFLAGS :
2715 {
2716 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iData);
2717 ExitOnFailure(hr, "Failed to read DirProps sslFlags");
2718 //iData contains bit flags for /security/access sslFlags
2719 //no translation required
2720 hr = pAdminMgr->GetAdminSection(ScopeBSTR(L"system.webServer/security/access"), pwzConfigPath, &pSection);
2721 ExitOnFailure(hr, "Failed get security/access section for DirProp");
2722 dwData = iData;
2723 hr = Iis7PutPropertyInteger( pSection, L"sslFlags", dwData);
2724 ExitOnFailure(hr, "Failed set security/access for DirProps");
2725 ReleaseNullObject(pSection);
2726 break;
2727 }
2728 case IIS_DIRPROP_AUTHPROVID :
2729 {
2730 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzData);
2731 ExitOnFailure(hr, "Failed to read DirProps auth provider");
2732 hr = SetDirPropAuthProvider(pAdminMgr, pwzConfigPath, pwzData);
2733 ExitOnFailure(hr, "Failed to set DirProps auth provider");
2734 break;
2735 }
2736 case IIS_DIRPROP_ASPERROR:
2737 {
2738 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iData);
2739 ExitOnFailure(hr, "Failed to read DirProps aspDetailedError");
2740 hr = pAdminMgr->GetAdminSection(ScopeBSTR(IIS_CONFIG_ASP_SECTION), pwzConfigPath, &pSection);
2741 ExitOnFailure(hr, "Failed get asp section for DirProp");
2742 hr = Iis7PutPropertyBool(pSection, IIS_CONFIG_SCRIPTERROR, iData);
2743 ExitOnFailure(hr, "Failed to set DirProps aspDetailedError");
2744 ReleaseNullObject(pSection);
2745 break;
2746 }
2747 case IIS_DIRPROP_HTTPEXPIRES:
2748 {
2749 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzData);
2750 ExitOnFailure(hr, "Failed to read DirProps httpExpires provider");
2751 hr = pAdminMgr->GetAdminSection(ScopeBSTR(IIS_CONFIG_STATICCONTENT_SECTION), pwzConfigPath, &pSection);
2752 ExitOnFailure(hr, "Failed get staticContent section for DirProp");
2753 hr = pSection->GetElementByName(ScopeBSTR(IIS_CONFIG_CLIENTCACHE), &pElement);
2754 ExitOnFailure(hr, "Failed to get clientCache element");
2755 hr = Iis7PutPropertyString(pElement, IIS_CONFIG_HTTPEXPIRES, pwzData);
2756 ExitOnFailure(hr, "Failed to set clientCache httpExpires value");
2757 hr = Iis7PutPropertyString(pElement, IIS_CONFIG_CACHECONTROLMODE, IIS_CONFIG_USEEXPIRES);
2758 ExitOnFailure(hr, "Failed to set clientCache cacheControlMode value");
2759 ReleaseNullObject(pSection);
2760 ReleaseNullObject(pElement);
2761 break;
2762 }
2763 case IIS_DIRPROP_MAXAGE:
2764 {
2765 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iData);
2766 ExitOnFailure(hr, "Failed to read DirProps httpExpires provider");
2767 hr = pAdminMgr->GetAdminSection(ScopeBSTR(IIS_CONFIG_STATICCONTENT_SECTION), pwzConfigPath, &pSection);
2768 ExitOnFailure(hr, "Failed get staticContent section for DirProp");
2769 hr = pSection->GetElementByName(ScopeBSTR(IIS_CONFIG_CLIENTCACHE), &pElement);
2770 ExitOnFailure(hr, "Failed to get clientCache element");
2771 *wcTime = '\0';
2772 ConvSecToDHMS(iData, wcTime, countof(wcTime));
2773 hr = Iis7PutPropertyString(pElement, IIS_CONFIG_MAXAGE, wcTime);
2774 ExitOnFailure(hr, "Failed to set clientCache maxAge value");
2775 hr = Iis7PutPropertyString(pElement, IIS_CONFIG_CACHECONTROLMODE, IIS_CONFIG_USEMAXAGE);
2776 ExitOnFailure(hr, "Failed to set clientCache cacheControlMode value");
2777 ReleaseNullObject(pSection);
2778 ReleaseNullObject(pElement);
2779 break;
2780 }
2781 case IIS_DIRPROP_CACHECUST:
2782 {
2783 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzData);
2784 ExitOnFailure(hr, "Failed to read DirProps cacheControlCustom");
2785 hr = pAdminMgr->GetAdminSection(ScopeBSTR(IIS_CONFIG_STATICCONTENT_SECTION), pwzConfigPath, &pSection);
2786 ExitOnFailure(hr, "Failed get staticContent section for DirProp");
2787 hr = pSection->GetElementByName(ScopeBSTR(IIS_CONFIG_CLIENTCACHE), &pElement);
2788 ExitOnFailure(hr, "Failed to get clientCache element");
2789 hr = Iis7PutPropertyString(pElement, IIS_CONFIG_CACHECUST, pwzData);
2790 ExitOnFailure(hr, "Failed to set clientCache cacheControlCustom value");
2791 ReleaseNullObject(pSection);
2792 ReleaseNullObject(pElement);
2793 break;
2794 }
2795 case IIS_DIRPROP_NOCUSTERROR:
2796 {
2797 //no value, if have ID tag write clear to system.webServer/httpErrors
2798 //error collection
2799 hr = pAdminMgr->GetAdminSection(ScopeBSTR(IIS_CONFIG_HTTPERRORS_SECTION), pwzConfigPath, &pSection);
2800 ExitOnFailure(hr, "Failed get httperrors section for DirProp");
2801 hr = pSection->get_Collection(&pCollection);
2802 ExitOnFailure(hr, "Failed get error collection for DirProp");
2803 hr = pCollection->CreateNewElement(ScopeBSTR(IIS_CONFIG_CLEAR), &pElement);
2804 ExitOnFailure(hr, "Failed to create clear element for error collection for DirProp");
2805 hr = pCollection->AddElement(pElement);
2806 ExitOnFailure(hr, "Failed to add lear element for error collection for DirProp");
2807 ReleaseNullObject(pSection);
2808 ReleaseNullObject(pElement);
2809 break;
2810 }
2811 case IIS_DIRPROP_LOGVISITS:
2812 {
2813 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iData);
2814 ExitOnFailure(hr, "Failed to read DirProps logVisits");
2815 hr = pAdminMgr->GetAdminSection(ScopeBSTR(IIS_CONFIG_HTTPLOGGING_SECTION), pwzConfigPath, &pSection);
2816 ExitOnFailure(hr, "Failed get httpLogging section for DirProp");
2817 hr = Iis7PutPropertyBool(pSection, IIS_CONFIG_DONTLOG, iData);
2818 ExitOnFailure(hr, "Failed to set DirProps aspDetailedError");
2819 ReleaseNullObject(pSection);
2820 break;
2821 }
2822 default:
2823 {
2824 ExitOnFailure(hr = E_UNEXPECTED, "Unexpected IIS Config action specified for WebDirProperties");
2825 break;
2826 }
2827 }
2828
2829 // Get AppExt action
2830 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iAction);
2831 ExitOnFailure(hr, "Failed to read DirProps Property action");
2832 }
2833LExit:
2834 ReleaseStr(pwzConfigPath);
2835 ReleaseStr(pwzWebName);
2836 ReleaseStr(pwzWebRoot);
2837 ReleaseStr(pwzData);
2838 ReleaseObject(pSection);
2839 ReleaseObject(pElement);
2840 ReleaseObject(pCollection);
2841
2842 return hr;
2843}
2844
2845//-------------------------------------------------------------------------------------------------
2846// IIS7SslBinding
2847// ProcessesVdir Properties CA Data
2848//
2849//
2850//-------------------------------------------------------------------------------------------------
2851HRESULT IIS7SslBinding(
2852 __inout LPWSTR *ppwzCustomActionData,
2853 __in IAppHostWritableAdminManager *pAdminMgr
2854 )
2855{
2856 HRESULT hr = S_OK;
2857 int iAction = -1;
2858 BOOL fSiteFound = FALSE;
2859
2860 LPWSTR pwzSiteName = NULL;
2861 LPWSTR pwzStoreName = NULL;
2862 LPWSTR pwzEncodedCertificateHash = NULL;
2863
2864 IAppHostElement *pSiteElem = NULL;
2865
2866 // Get Application action
2867 hr = WcaReadIntegerFromCaData( ppwzCustomActionData, &iAction);
2868 ExitOnFailure(hr, "Failed to read binding action");
2869
2870 //get site key name
2871 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzSiteName);
2872 ExitOnFailure(hr, "Failed to read binding site name key");
2873
2874 //get binding protocol
2875 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzStoreName);
2876 ExitOnFailure(hr, "Failed to read binding protocol");
2877
2878 //get binding info
2879 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzEncodedCertificateHash);
2880 ExitOnFailure(hr, "Failed to read binding info");
2881
2882 //Get site if it exists
2883 hr = GetSiteElement(pAdminMgr, pwzSiteName, &pSiteElem, &fSiteFound);
2884 ExitOnFailure(hr, "Failed to read sites from config");
2885
2886 if (IIS_CREATE == iAction)
2887 {
2888 if (fSiteFound)
2889 {
2890 //add SSL cert to binding
2891 hr = CreateSslBinding(pSiteElem, pwzStoreName, pwzEncodedCertificateHash);
2892 ExitOnFailure(hr, "Failed to create site binding");
2893 }
2894 else
2895 {
2896 hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
2897 ExitOnFailure(hr, "Site not found for create binding");
2898 }
2899 }
2900 else if (IIS_DELETE == iAction)
2901 {
2902 if (fSiteFound)
2903 {
2904 //delete binding
2905 hr = DeleteSslBinding(pSiteElem, pwzStoreName, pwzEncodedCertificateHash);
2906 ExitOnFailure(hr, "Failed to delete binding");
2907 }
2908 }
2909
2910 LExit:
2911 ReleaseStr(pwzSiteName);
2912 ReleaseStr(pwzStoreName);
2913 ReleaseStr(pwzEncodedCertificateHash);
2914 ReleaseObject(pSiteElem);
2915
2916 return hr;
2917}
2918
2919//-------------------------------------------------------------------------------------------------
2920// Helper Functions
2921//
2922//
2923//
2924//-------------------------------------------------------------------------------------------------
2925
2926static HRESULT GetNextAvailableSiteId(
2927 IAppHostElementCollection *pCollection,
2928 DWORD *plSiteId
2929 )
2930{
2931 HRESULT hr = S_OK;
2932 IAppHostElement *pElement = NULL;
2933 IAppHostProperty *pProperty = NULL;
2934
2935 DWORD cSites;
2936 DWORD plNextAvailSite = 0;
2937 VARIANT vPropValue;
2938 VARIANT vtIndex;
2939
2940 VariantInit(&vPropValue);
2941 VariantInit(&vtIndex);
2942
2943 *plSiteId = 0;
2944
2945 hr = pCollection->get_Count(&cSites);
2946 ExitOnFailure(hr, "Failed get sites collection count");
2947
2948 vtIndex.vt = VT_UI4;
2949 for (DWORD i = 0; i < cSites; ++i)
2950 {
2951 vtIndex.ulVal = i;
2952 hr = pCollection->get_Item(vtIndex , &pElement);
2953 ExitOnFailure(hr, "Failed get sites collection item");
2954
2955 hr = pElement->GetPropertyByName(ScopeBSTR(IIS_CONFIG_ID), &pProperty);
2956 ExitOnFailure(hr, "Failed get site property");
2957
2958 hr = pProperty->get_Value(&vPropValue);
2959 ExitOnFailure(hr, "Failed get site property value");
2960
2961 *plSiteId = vPropValue.lVal;
2962 if (*plSiteId > plNextAvailSite)
2963 {
2964 plNextAvailSite = *plSiteId;
2965 }
2966 ReleaseNullObject(pElement);
2967 ReleaseNullObject(pProperty);
2968 }
2969 *plSiteId = ++plNextAvailSite;
2970
2971LExit:
2972 ReleaseVariant(vPropValue);
2973 ReleaseVariant(vtIndex);
2974
2975 ReleaseObject(pElement);
2976 ReleaseObject(pProperty);
2977
2978 return hr;
2979}
2980
2981static HRESULT GetSiteElement(
2982 IAppHostWritableAdminManager *pAdminMgr,
2983 LPCWSTR swSiteName,
2984 IAppHostElement **ppSiteElement,
2985 BOOL* fFound
2986 )
2987{
2988 HRESULT hr = S_OK;
2989 IAppHostElement *pSites = NULL;
2990 IAppHostElementCollection *pCollection = NULL;
2991
2992 *fFound = FALSE;
2993
2994 hr = pAdminMgr->GetAdminSection(ScopeBSTR(IIS_CONFIG_SITES_SECTION), ScopeBSTR(IIS_CONFIG_APPHOST_ROOT), &pSites);
2995 ExitOnFailure(hr, "Failed get sites section");
2996 ExitOnNull(pSites, hr, ERROR_FILE_NOT_FOUND, "Failed get sites section object");
2997
2998 hr = pSites->get_Collection(&pCollection);
2999 ExitOnFailure(hr, "Failed get sites collection");
3000
3001 hr = Iis7FindAppHostElementString(pCollection, IIS_CONFIG_SITE, IIS_CONFIG_NAME, swSiteName, ppSiteElement, NULL);
3002 ExitOnFailure(hr, "Failed to find site %ls", swSiteName);
3003
3004 *fFound = ppSiteElement != NULL && *ppSiteElement != NULL;
3005
3006LExit:
3007 ReleaseObject(pSites);
3008 ReleaseObject(pCollection);
3009
3010 return hr;
3011}
3012
3013static HRESULT GetApplicationElement( IAppHostElement *pSiteElement,
3014 LPCWSTR swAppPath,
3015 IAppHostElement **ppAppElement,
3016 BOOL* fFound)
3017{
3018 HRESULT hr = S_OK;
3019 IAppHostElementCollection *pCollection = NULL;
3020
3021 *fFound = FALSE;
3022
3023 hr = pSiteElement->get_Collection( &pCollection);
3024 ExitOnFailure(hr, "Failed get site app collection");
3025
3026 hr = Iis7FindAppHostElementString(pCollection, IIS_CONFIG_APPLICATION, IIS_CONFIG_PATH, swAppPath, ppAppElement, NULL);
3027 ExitOnFailure(hr, "Failed to find app %ls", swAppPath);
3028
3029 *fFound = ppAppElement != NULL && *ppAppElement != NULL;
3030
3031LExit:
3032 ReleaseObject(pCollection);
3033
3034 return hr;
3035}
3036
3037static HRESULT GetApplicationElementForVDir( IAppHostElement *pSiteElement,
3038 LPCWSTR pwzVDirPath,
3039 IAppHostElement **ppAppElement,
3040 LPCWSTR *ppwzVDirSubPath,
3041 BOOL* fFound)
3042{
3043 HRESULT hr = S_OK;
3044 IAppHostElementCollection *pCollection = NULL;
3045 LPWSTR pwzAppPath = NULL;
3046 *fFound = FALSE;
3047 *ppwzVDirSubPath = NULL;
3048
3049 hr = pSiteElement->get_Collection( &pCollection);
3050 ExitOnFailure(hr, "Failed get site app collection");
3051
3052 // Start with full path
3053 int iLastPathIndex = lstrlenW(pwzVDirPath) - 1;
3054 hr = StrAllocString(&pwzAppPath, pwzVDirPath, 0);
3055 ExitOnFailure(hr, "Failed allocate application path");
3056
3057 for (int iSubPathIndex = iLastPathIndex; (iSubPathIndex >= 0) && (!*fFound); --iSubPathIndex)
3058 {
3059 // We are looking at the full path, or at a directory boundary, or at the root
3060 if (iSubPathIndex == iLastPathIndex ||
3061 '/' == pwzAppPath[iSubPathIndex] ||
3062 0 == iSubPathIndex)
3063 {
3064 // break the path if needed
3065 if ('/' == pwzAppPath[iSubPathIndex])
3066 {
3067 pwzAppPath[iSubPathIndex] = '\0';
3068 }
3069
3070 // Special case for root path, need an empty app path
3071 LPCWSTR pwzAppSearchPath = 0 == iSubPathIndex ? L"/" : pwzAppPath;
3072
3073 // Try to find an app with the specified path
3074 hr = Iis7FindAppHostElementString(pCollection, IIS_CONFIG_APPLICATION, IIS_CONFIG_PATH, pwzAppSearchPath, ppAppElement, NULL);
3075 ExitOnFailure(hr, "Failed to search for app %ls", pwzAppSearchPath);
3076 *fFound = ppAppElement != NULL && *ppAppElement != NULL;
3077
3078 if (*fFound)
3079 {
3080 // set return value for sub path
3081 // special case for app path == vdir path, need an empty subpath.
3082 *ppwzVDirSubPath = (iSubPathIndex == iLastPathIndex) ? L"/" : pwzVDirPath + iSubPathIndex;
3083 }
3084 }
3085 }
3086
3087LExit:
3088 ReleaseObject(pCollection);
3089 ReleaseStr(pwzAppPath);
3090
3091 return hr;
3092}
3093
3094static HRESULT CreateSite(
3095 __in IAppHostElementCollection *pCollection,
3096 __in LPCWSTR swSiteName,
3097 __out IAppHostElement **pSiteElement
3098 )
3099{
3100 HRESULT hr = S_OK;
3101 IAppHostElement *pNewElement = NULL;
3102
3103 hr = pCollection->CreateNewElement(ScopeBSTR(IIS_CONFIG_SITE), &pNewElement);
3104 ExitOnFailure(hr, "Failed create site element");
3105
3106 hr = Iis7PutPropertyString(pNewElement, IIS_CONFIG_NAME, swSiteName);
3107 ExitOnFailure(hr, "Failed set site name property");
3108
3109 DWORD lSiteId = 0;
3110 hr = GetNextAvailableSiteId(pCollection, &lSiteId);
3111 ExitOnFailure(hr, "Failed get next site id");
3112
3113 Iis7PutPropertyInteger(pNewElement, IIS_CONFIG_ID, lSiteId);
3114 ExitOnFailure(hr, "Failed set site id property");
3115
3116 hr = pCollection->AddElement(pNewElement);
3117 ExitOnFailure(hr, "Failed add site element");
3118
3119 *pSiteElement = pNewElement;
3120 pNewElement = NULL;
3121
3122LExit:
3123 ReleaseObject(pNewElement);
3124
3125 return hr;
3126}
3127
3128static HRESULT CreateApplication(
3129 IAppHostElement *pSiteElement,
3130 LPCWSTR swAppPath,
3131 IAppHostElement **pAppElement
3132 )
3133{
3134 HRESULT hr = S_OK;
3135 IAppHostElement *pNewElement = NULL;
3136 IAppHostElementCollection *pCollection = NULL;
3137
3138 hr = pSiteElement->get_Collection(&pCollection);
3139 ExitOnFailure(hr, "Failed get application collection");
3140
3141 hr = pCollection->CreateNewElement(ScopeBSTR(IIS_CONFIG_APPLICATION), &pNewElement);
3142 ExitOnFailure(hr, "Failed get application element");
3143
3144 hr = Iis7PutPropertyString(pNewElement, IIS_CONFIG_PATH, swAppPath);
3145 ExitOnFailure(hr, "Failed set application path property");
3146
3147 hr = pCollection->AddElement(pNewElement);
3148 ExitOnFailure(hr, "Failed add application to collection");
3149
3150 *pAppElement = pNewElement;
3151 pNewElement = NULL;
3152
3153LExit:
3154 ReleaseObject(pCollection);
3155 ReleaseObject(pNewElement);
3156
3157 return hr;
3158}
3159
3160static HRESULT DeleteApplication(
3161 IAppHostElement *pSiteElement,
3162 LPCWSTR swAppPath
3163 )
3164{
3165 HRESULT hr = S_OK;
3166 IAppHostElementCollection *pCollection = NULL;
3167
3168 hr = pSiteElement->get_Collection(&pCollection);
3169 ExitOnFailure(hr, "Failed get application collection");
3170
3171 hr = DeleteCollectionElement(pCollection, IIS_CONFIG_APPLICATION, IIS_CONFIG_PATH, swAppPath);
3172 ExitOnFailure(hr, "Failed to delete website");
3173
3174LExit:
3175 ReleaseObject(pCollection);
3176
3177 return hr;
3178}
3179
3180static HRESULT SetAppPool(
3181 IAppHostElement *pAppElement,
3182 LPCWSTR pwzAppPool
3183 )
3184{
3185 HRESULT hr = S_OK;
3186
3187 if (*pwzAppPool != 0)
3188 {
3189 hr = Iis7PutPropertyString(pAppElement, IIS_CONFIG_APPPOOL, pwzAppPool);
3190 ExitOnFailure(hr, "Failed set application appPool property");
3191 }
3192LExit:
3193 return hr;
3194}
3195
3196static HRESULT CreateVdir(
3197 IAppHostElement *pAppElement,
3198 LPCWSTR pwzVDirPath,
3199 LPCWSTR pwzVDirPhyDir
3200 )
3201{
3202 HRESULT hr = S_OK;
3203 IAppHostElement *pElement = NULL;
3204 IAppHostElementCollection *pCollection = NULL;
3205 BOOL fFound;
3206
3207 hr = pAppElement->get_Collection(&pCollection);
3208 ExitOnFailure(hr, "Failed get application VDir collection");
3209
3210 hr = Iis7FindAppHostElementString(pCollection, IIS_CONFIG_VDIR, IIS_CONFIG_PATH, pwzVDirPath, &pElement, NULL);
3211 ExitOnFailure(hr, "Failed while finding virtualDir");
3212 fFound = (NULL != pElement);
3213
3214 if (!fFound)
3215 {
3216 hr = pCollection->CreateNewElement(ScopeBSTR(IIS_CONFIG_VDIR), &pElement);
3217 ExitOnFailure(hr, "Failed create application VDir collection");
3218
3219 hr = Iis7PutPropertyString(pElement, IIS_CONFIG_PATH, pwzVDirPath);
3220 ExitOnFailure(hr, "Failed set VDir path property");
3221 }
3222
3223 hr = Iis7PutPropertyString(pElement, IIS_CONFIG_PHYSPATH, pwzVDirPhyDir);
3224 ExitOnFailure(hr, "Failed set VDir phys path property");
3225
3226 if (!fFound)
3227 {
3228 hr = pCollection->AddElement(pElement);
3229 ExitOnFailure(hr, "Failed add application VDir element");
3230 }
3231
3232LExit:
3233 ReleaseObject(pCollection);
3234 ReleaseObject(pElement);
3235
3236 return hr;
3237}
3238
3239static HRESULT DeleteVdir(
3240 IAppHostElement *pAppElement,
3241 LPCWSTR pwzVDirPath
3242 )
3243{
3244 HRESULT hr = S_OK;
3245 IAppHostElementCollection *pCollection = NULL;
3246
3247 hr = pAppElement->get_Collection(&pCollection);
3248 ExitOnFailure(hr, "Failed get application VDir collection");
3249
3250 hr = DeleteCollectionElement(pCollection, IIS_CONFIG_VDIR, IIS_CONFIG_PATH, pwzVDirPath);
3251 ExitOnFailure(hr, "Failed to delete vdir");
3252
3253LExit:
3254 ReleaseObject(pCollection);
3255
3256 return hr;
3257}
3258
3259static HRESULT CreateBinding(
3260 IAppHostElement *pSiteElem,
3261 LPCWSTR pwzProtocol,
3262 LPCWSTR pwzInfo
3263 )
3264{
3265 HRESULT hr = S_OK;
3266 IAppHostChildElementCollection *pChildElems = NULL;
3267 IAppHostElement *pBindings = NULL;
3268 IAppHostElement *pBindingElement = NULL;
3269 IAppHostElementCollection *pCollection = NULL;
3270
3271 VARIANT vtProp;
3272
3273 VariantInit(&vtProp);
3274
3275 hr = pSiteElem->get_ChildElements(&pChildElems);
3276 ExitOnFailure(hr, "Failed get site child elements collection");
3277
3278 vtProp.vt = VT_BSTR;
3279 vtProp.bstrVal = ::SysAllocString(IIS_CONFIG_BINDINGS);
3280 hr = pChildElems->get_Item(vtProp, &pBindings);
3281 ExitOnFailure(hr, "Failed get bindings element");
3282 ReleaseVariant(vtProp);
3283
3284 hr = pBindings->get_Collection(&pCollection);
3285 ExitOnFailure(hr, "Failed get bindings collection");
3286
3287 hr = pCollection->CreateNewElement(ScopeBSTR(IIS_CONFIG_BINDING), &pBindingElement);
3288 ExitOnFailure(hr, "Failed get binding element");
3289
3290 hr = Iis7PutPropertyString(pBindingElement, IIS_CONFIG_PROTOCOL, pwzProtocol);
3291 ExitOnFailure(hr, "Failed set binding protocol property");
3292
3293 hr = Iis7PutPropertyString(pBindingElement, IIS_CONFIG_BINDINGINFO, pwzInfo);
3294 ExitOnFailure(hr, "Failed set binding information property");
3295
3296 hr = pCollection->AddElement(pBindingElement);
3297 if (hr == HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS))
3298 {
3299 //Eat this error. Binding is there and nothing to repair since
3300 //identity == protocol + info so all is OK
3301 hr = S_OK;
3302 }
3303 else
3304 {
3305 ExitOnFailure(hr, "Failed add binding to site");
3306 }
3307
3308LExit:
3309 ReleaseVariant(vtProp);
3310
3311 ReleaseObject(pCollection);
3312 ReleaseObject(pChildElems);
3313 ReleaseObject(pBindingElement);
3314 ReleaseObject(pBindings);
3315
3316 return hr;
3317}
3318static HRESULT CreateWebLog(
3319 IAppHostElement *pSiteElem,
3320 LPCWSTR pwzFormat
3321 )
3322{
3323 HRESULT hr = S_OK;
3324 IAppHostChildElementCollection *pChildElems = NULL;
3325 IAppHostElement *pLogFile = NULL;
3326
3327 VARIANT vtProp;
3328
3329 VariantInit(&vtProp);
3330
3331 hr = pSiteElem->get_ChildElements(&pChildElems);
3332 ExitOnFailure(hr, "Failed get site child elements collection");
3333
3334 vtProp.vt = VT_BSTR;
3335 vtProp.bstrVal = ::SysAllocString(IIS_CONFIG_WEBLOG);
3336 hr = pChildElems->get_Item(vtProp, &pLogFile);
3337 ExitOnFailure(hr, "Failed get logfile element");
3338 ReleaseVariant(vtProp);
3339
3340 if (CSTR_EQUAL != ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, pwzFormat, -1, L"none", -1))
3341 {
3342 hr = Iis7PutPropertyString(pLogFile, IIS_CONFIG_LOGFORMAT, pwzFormat);
3343 ExitOnFailure(hr, "Failed set logfile format property");
3344 hr = Iis7PutPropertyString(pLogFile, IIS_CONFIG_ENABLED, IIS_CONFIG_TRUE);
3345 ExitOnFailure(hr, "Failed set logfile enabled property");
3346 }
3347 else
3348 {
3349 hr = Iis7PutPropertyString(pLogFile, IIS_CONFIG_ENABLED, IIS_CONFIG_FALSE);
3350 ExitOnFailure(hr, "Failed set logfile enabled property");
3351 }
3352
3353LExit:
3354 ReleaseVariant(vtProp);
3355
3356 ReleaseObject(pLogFile);
3357 ReleaseObject(pChildElems);
3358
3359 return hr;
3360}
3361
3362static HRESULT DeleteBinding(
3363 IAppHostElement* /*pSiteElem*/,
3364 LPCWSTR /*pwzProtocol*/,
3365 LPCWSTR /*pwzInfo*/
3366 )
3367{
3368 HRESULT hr = S_OK;
3369 //
3370 //this isn't supported right now, we should support this for the SiteSearch scenario
3371 return hr;
3372}
3373
3374struct SCA_SSLBINDINGINFO
3375{
3376 IIS7_APPHOSTELEMENTCOMPARISON comparison;
3377 LPCWSTR pwzStoreName;
3378 LPCWSTR pwzEncodedCertificateHash;
3379 HRESULT hr;
3380};
3381
3382static BOOL AddSslCertificateToBindingCallback(IAppHostElement *pBindingElement, LPVOID pContext)
3383{
3384 HRESULT hr = S_OK;
3385 VARIANT vtProp;
3386 VariantInit(&vtProp);
3387 SCA_SSLBINDINGINFO* pBindingInfo = (SCA_SSLBINDINGINFO*)pContext;
3388 IAppHostMethodCollection *pAppHostMethodCollection = NULL;
3389 IAppHostMethod *pAddSslMethod = NULL;
3390 IAppHostMethodInstance *pAddSslMethodInstance = NULL;
3391 IAppHostElement *pAddSslInput = NULL;
3392 int iWsaError = 0;
3393 WSADATA wsaData = {};
3394 BOOL fWsaInitialized = FALSE;
3395
3396 // IIS's AddSslCertificate doesn't initialize WinSock on 2008 before using it to parse the IP
3397 // Initialize before calling to workaround the failure.
3398 iWsaError = WSAStartup(MAKEWORD(2, 2), &wsaData);
3399 if (0 != iWsaError)
3400 {
3401 ExitOnWin32Error(iWsaError, hr, "Failed to initialize WinSock");
3402 }
3403
3404 fWsaInitialized = TRUE;
3405
3406 if (Iis7IsMatchingAppHostElement(pBindingElement, &pBindingInfo->comparison))
3407 {
3408 hr = pBindingElement->get_Methods(&pAppHostMethodCollection);
3409 ExitOnFailure(hr, "failed to get binding method collection");
3410
3411 hr = Iis7FindAppHostMethod(pAppHostMethodCollection, L"AddSslCertificate", &pAddSslMethod, NULL);
3412 if (FAILED(hr))
3413 {
3414 WcaLog(LOGMSG_STANDARD, "The AddSslCertificate method is not supported by the binding element, SSL certificate will not be associated with the website");
3415 ExitFunction();
3416 }
3417
3418 pAddSslMethod->CreateInstance(&pAddSslMethodInstance);
3419 ExitOnFailure(hr, "failed to create an instance of AddSslCertificate method");
3420
3421 pAddSslMethodInstance->get_Input(&pAddSslInput);
3422 ExitOnFailure(hr, "failed to get input element of AddSslCertificate method");
3423
3424 Iis7PutPropertyString(pAddSslInput, IIS_CONFIG_CERTIFICATESTORENAME, pBindingInfo->pwzStoreName);
3425 ExitOnFailure(hr, "failed to set certificateStoreName input parameter of AddSslCertificate method");
3426
3427 Iis7PutPropertyString(pAddSslInput, IIS_CONFIG_CERTIFICATEHASH, pBindingInfo->pwzEncodedCertificateHash);
3428 ExitOnFailure(hr, "failed to set certificateHash input parameter of AddSslCertificate method");
3429
3430 hr = pAddSslMethodInstance->Execute();
3431 ExitOnFailure(hr, "failed to execute AddSslCertificate method");
3432 }
3433LExit:
3434 pBindingInfo->hr = hr;
3435 ReleaseObject(pAppHostMethodCollection);
3436 ReleaseObject(pAddSslMethod);
3437 ReleaseObject(pAddSslMethodInstance);
3438 ReleaseObject(pAddSslInput);
3439 if (fWsaInitialized)
3440 {
3441 WSACleanup();
3442 }
3443
3444 return FAILED(hr);
3445}
3446
3447static HRESULT CreateSslBinding( IAppHostElement *pSiteElem, LPCWSTR pwzStoreName, LPCWSTR pwzEncodedCertificateHash)
3448{
3449 HRESULT hr = S_OK;
3450 IAppHostChildElementCollection *pChildElems = NULL;
3451 IAppHostElement *pBindingsElement = NULL;
3452 IAppHostElementCollection *pBindingsCollection = NULL;
3453 SCA_SSLBINDINGINFO bindingInfo = {};
3454 VARIANT vtProp;
3455 VariantInit(&vtProp);
3456
3457 hr = pSiteElem->get_ChildElements(&pChildElems);
3458 ExitOnFailure(hr, "Failed get site child elements collection");
3459
3460 vtProp.vt = VT_BSTR;
3461 vtProp.bstrVal = ::SysAllocString(IIS_CONFIG_BINDINGS);
3462 hr = pChildElems->get_Item(vtProp, &pBindingsElement);
3463 ExitOnFailure(hr, "Failed get bindings element");
3464 ReleaseVariant(vtProp);
3465
3466 hr = pBindingsElement->get_Collection(&pBindingsCollection);
3467 ExitOnFailure(hr, "Failed get bindings collection");
3468
3469 bindingInfo.comparison.sczElementName = IIS_CONFIG_BINDING;
3470 bindingInfo.comparison.sczAttributeName = IIS_CONFIG_PROTOCOL;
3471 vtProp.vt = VT_BSTR;
3472 vtProp.bstrVal = ::SysAllocString(L"https");
3473 bindingInfo.comparison.pvAttributeValue = &vtProp;
3474 bindingInfo.pwzStoreName = pwzStoreName;
3475 bindingInfo.pwzEncodedCertificateHash = pwzEncodedCertificateHash;
3476
3477 // Our current IISWebSiteCertificates schema does not allow specification of the website binding
3478 // to associate the certificate with. For now just associate it with all secure bindings.
3479
3480 hr = Iis7EnumAppHostElements(pBindingsCollection, AddSslCertificateToBindingCallback, &bindingInfo, NULL, NULL);
3481 ExitOnFailure(hr, "Failed to enumerate bindings collection");
3482 hr = bindingInfo.hr;
3483 ExitOnFailure(hr, "Failed to add ssl binding");
3484
3485LExit:
3486 ReleaseVariant(vtProp);
3487
3488 ReleaseObject(pChildElems);
3489 ReleaseObject(pBindingsElement);
3490 ReleaseObject(pBindingsCollection);
3491
3492 return hr;
3493}
3494
3495static HRESULT DeleteSslBinding(
3496 IAppHostElement * /*pSiteElem*/,
3497 LPCWSTR /*pwzStoreName*/,
3498 LPCWSTR /*pwzEncodedCertificateHash*/
3499 )
3500{
3501 HRESULT hr = S_OK;
3502 //
3503 //this isn't supported right now, we should support this for the SiteSearch scenario
3504 return hr;
3505}
3506
3507static HRESULT DeleteAppPool( IAppHostWritableAdminManager *pAdminMgr,
3508 LPCWSTR swAppPoolName)
3509{
3510 HRESULT hr = S_OK;
3511 IAppHostElement *pAppPools = NULL;
3512 IAppHostElementCollection *pCollection = NULL;
3513
3514 hr = pAdminMgr->GetAdminSection(ScopeBSTR(IIS_CONFIG_APPPOOL_SECTION), ScopeBSTR(IIS_CONFIG_APPHOST_ROOT), &pAppPools);
3515 ExitOnFailure(hr, "Failed get AppPools section");
3516 ExitOnNull(pAppPools, hr, E_UNEXPECTED, "Failed get appPools section object");
3517
3518 hr = pAppPools->get_Collection( &pCollection);
3519 ExitOnFailure(hr, "Failed get AppPools collection");
3520
3521 hr = DeleteCollectionElement(pCollection, IIS_CONFIG_ADD, IIS_CONFIG_NAME, swAppPoolName);
3522 ExitOnFailure(hr, "Failed to delete app pool %ls", swAppPoolName);
3523
3524LExit:
3525 ReleaseObject(pAppPools);
3526 ReleaseObject(pCollection);
3527
3528 return hr;
3529}
3530
3531static HRESULT CreateAppPool(
3532 __inout LPWSTR *ppwzCustomActionData,
3533 IAppHostWritableAdminManager *pAdminMgr,
3534 LPCWSTR swAppPoolName
3535 )
3536{
3537 HRESULT hr = S_OK;
3538 IAppHostElement *pAppPools = NULL;
3539 IAppHostElement *pAppPoolElement = NULL;
3540 IAppHostElement *pElement = NULL;
3541 IAppHostElement *pElement2 = NULL;
3542 IAppHostElement *pElement3 = NULL;
3543 IAppHostElementCollection *pCollection = NULL;
3544 IAppHostElementCollection *pCollection2 = NULL;
3545 int iAction = -1;
3546 int iData = 0;
3547 LPWSTR pwzData = NULL;
3548 WCHAR wcData[512];
3549 WCHAR wcTime[60];
3550 BOOL fFound = FALSE;
3551
3552 hr = pAdminMgr->GetAdminSection(ScopeBSTR(IIS_CONFIG_APPPOOL_SECTION), ScopeBSTR(IIS_CONFIG_APPHOST_ROOT), &pAppPools);
3553 ExitOnFailure(hr, "Failed get AppPools section");
3554 ExitOnNull(pAppPools, hr, ERROR_FILE_NOT_FOUND, "Failed get AppPools section object");
3555
3556 hr = pAppPools->get_Collection( &pCollection);
3557 ExitOnFailure(hr, "Failed get AppPools collection");
3558
3559 hr = Iis7FindAppHostElementString(pCollection, IIS_CONFIG_ADD, IIS_CONFIG_NAME, swAppPoolName, &pAppPoolElement, NULL);
3560 ExitOnFailure(hr, "Failed find AppPool element");
3561 fFound = (NULL != pAppPoolElement);
3562
3563 if (!fFound)
3564 {
3565 hr = pCollection->CreateNewElement(ScopeBSTR(IIS_CONFIG_ADD), &pAppPoolElement);
3566 ExitOnFailure(hr, "Failed create AppPool element");
3567 }
3568
3569 hr = Iis7PutPropertyString(pAppPoolElement, IIS_CONFIG_NAME, swAppPoolName);
3570 ExitOnFailure(hr, "Failed set AppPool name property");
3571
3572 //For WiX II6 /ABO compat we will default managedPipelineMode="Classic"
3573 hr = Iis7PutPropertyString(pAppPoolElement, IIS_CONFIG_PIPELINEMODE, L"Classic");
3574 ExitOnFailure(hr, "Failed set AppPool managedPipelineMode property");
3575 //For WiX II6 /ABO compat we will be hardcoding autostart="true"
3576 hr = Iis7PutPropertyString(pAppPoolElement, IIS_CONFIG_APPPOOL_AUTO, L"true");
3577 ExitOnFailure(hr, "Failed set AppPool autoStart property");
3578
3579 if (!fFound)
3580 {
3581 hr = pCollection->AddElement(pAppPoolElement);
3582 ExitOnFailure(hr, "Failed to add appPool element");
3583 }
3584
3585 // Get AppPool Property action
3586 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iAction);
3587 ExitOnFailure(hr, "Failed to read AppPool Property action");
3588 while (IIS_APPPOOL_END != iAction)
3589 {
3590 //Process property action
3591 switch (iAction)
3592 {
3593 case IIS_APPPOOL_RECYCLE_MIN :
3594 {
3595 // /recycling / periodicRestart | time
3596 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iData);
3597 ExitOnFailure(hr, "Failed to read AppPool recycle min");
3598 hr = pAppPoolElement->GetElementByName(ScopeBSTR(IIS_CONFIG_RECYCLING), &pElement);
3599 ExitOnFailure(hr, "Failed to get AppPool recycling element");
3600 hr = pElement->GetElementByName(ScopeBSTR(IIS_CONFIG_PEROIDRESTART), &pElement2);
3601 ExitOnFailure(hr, "Failed to get AppPool periodicRestart element");
3602 *wcTime = '\0';
3603 ConvSecToHMS(iData * 60, wcTime, countof(wcTime));
3604 hr = Iis7PutPropertyString(pElement2, IIS_CONFIG_TIME, wcTime);
3605 ExitOnFailure(hr, "Failed to set AppPool periodicRestart time value");
3606 ReleaseNullObject(pElement);
3607 ReleaseNullObject(pElement2);
3608 break;
3609 }
3610 case IIS_APPPOOL_RECYCLE_REQ :
3611 {
3612 // /recycling / periodicRestart | requests
3613 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iData);
3614 ExitOnFailure(hr, "Failed to read AppPool recycle req");
3615 hr = pAppPoolElement->GetElementByName(ScopeBSTR(IIS_CONFIG_RECYCLING), &pElement);
3616 ExitOnFailure(hr, "Failed to get AppPool recycling element");
3617 hr = pElement->GetElementByName(ScopeBSTR(IIS_CONFIG_PEROIDRESTART), &pElement2);
3618 ExitOnFailure(hr, "Failed to get AppPool periodicRestart element");
3619 hr = Iis7PutPropertyInteger(pElement2, IIS_CONFIG_REQUESTS, iData);
3620 ExitOnFailure(hr, "Failed to set AppPool periodicRestart time value");
3621 ReleaseNullObject(pElement);
3622 ReleaseNullObject(pElement2);
3623 break;
3624 }
3625 case IIS_APPPOOL_RECYCLE_TIMES :
3626 {
3627 // /recycling / periodicRestart | schedule
3628 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzData);
3629 ExitOnFailure(hr, "Failed to read AppPool recycle times");
3630 hr = pAppPoolElement->GetElementByName(ScopeBSTR(IIS_CONFIG_RECYCLING), &pElement);
3631 ExitOnFailure(hr, "Failed to get AppPool recycling element");
3632 hr = pElement->GetElementByName(ScopeBSTR(IIS_CONFIG_PEROIDRESTART), &pElement2);
3633 ExitOnFailure(hr, "Failed to get AppPool periodicRestart element");
3634 hr = pElement2->GetElementByName(ScopeBSTR(IIS_CONFIG_SCHEDULE), &pElement3);
3635 ExitOnFailure(hr, "Failed to get AppPool schedule element");
3636 hr = pElement3->get_Collection(&pCollection2);
3637 ExitOnFailure(hr, "Failed to get AppPool schedule collection");
3638
3639 WCHAR wcDelim[] = L",";
3640 const WCHAR *wszToken = NULL;
3641 WCHAR *wszNextToken = NULL;
3642 wszToken = wcstok_s( pwzData, wcDelim, &wszNextToken);
3643
3644 while (wszToken)
3645 {
3646 *wcData = '\0';
3647 hr = ::StringCchCopyW(wcData, countof(wcData), wszToken);
3648 ExitOnFailure(hr, "failed to copy AppPool schedule");
3649 hr = ::StringCchCatW(wcData, countof(wcData), L":00");
3650 ExitOnFailure(hr, "failed to append AppPool schedule");
3651
3652 hr = pCollection2->CreateNewElement(ScopeBSTR(IIS_CONFIG_ADD), &pElement3);
3653 ExitOnFailure(hr, "Failed to create AppPool schedule element");
3654
3655 hr = Iis7PutPropertyString(pElement3, IIS_CONFIG_VALUE, wcData);
3656 ExitOnFailure(hr, "Failed to set AppPool schedule value");
3657
3658 hr = pCollection2->AddElement(pElement3);
3659 if (hr == HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS))
3660 {
3661 //Eat this error, recycle time already exists NBD
3662 hr = S_OK;
3663 }
3664 ExitOnFailure(hr, "Failed to add win auth providers element");
3665 ReleaseNullObject(pElement3);
3666 wszToken = wcstok_s( NULL, wcDelim, &wszNextToken);
3667 }
3668 ReleaseNullObject(pElement);
3669 ReleaseNullObject(pElement2);
3670 ReleaseNullObject(pElement3);
3671 ReleaseNullObject(pCollection2);
3672 break;
3673 }
3674 case IIS_APPPOOL_RECYCLE_VIRMEM :
3675 {
3676 // /recycling / periodicRestart | memory
3677 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iData);
3678 ExitOnFailure(hr, "Failed to read AppPool recycle vir memory");
3679 hr = pAppPoolElement->GetElementByName(ScopeBSTR(IIS_CONFIG_RECYCLING), &pElement);
3680 ExitOnFailure(hr, "Failed to get AppPool recycling element");
3681 hr = pElement->GetElementByName(ScopeBSTR(IIS_CONFIG_PEROIDRESTART), &pElement2);
3682 ExitOnFailure(hr, "Failed to get AppPool periodicRestart element");
3683 hr = Iis7PutPropertyInteger(pElement2, IIS_CONFIG_MEMORY, iData);
3684 ExitOnFailure(hr, "Failed to set AppPool periodicRestart memory");
3685 ReleaseNullObject(pElement);
3686 ReleaseNullObject(pElement2);
3687 break;
3688 }
3689 case IIS_APPPOOL_RECYCLE_PRIVMEM :
3690 {
3691 // /recycling / periodicRestart | privateMemory
3692 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iData);
3693 ExitOnFailure(hr, "Failed to read AppPool recycle priv mem");
3694 hr = pAppPoolElement->GetElementByName(ScopeBSTR(IIS_CONFIG_RECYCLING), &pElement);
3695 ExitOnFailure(hr, "Failed to get AppPool recycling element");
3696 hr = pElement->GetElementByName(ScopeBSTR(IIS_CONFIG_PEROIDRESTART), &pElement2);
3697 ExitOnFailure(hr, "Failed to get AppPool periodicRestart element");
3698 hr = Iis7PutPropertyInteger(pElement2, IIS_CONFIG_PRIVMEMORY, iData);
3699 ExitOnFailure(hr, "Failed to set AppPool periodicRestart private memory");
3700 ReleaseNullObject(pElement);
3701 ReleaseNullObject(pElement2);
3702 break;
3703 }
3704 case IIS_APPPOOL_RECYCLE_IDLTIMEOUT :
3705 {
3706 // /processModel | idleTimeout
3707 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iData);
3708 ExitOnFailure(hr, "Failed to read AppPool idle timeout");
3709 hr = pAppPoolElement->GetElementByName(ScopeBSTR(IIS_CONFIG_PROCESSMODEL), &pElement);
3710 ExitOnFailure(hr, "Failed to get AppPool processModel element");
3711 *wcTime = '\0';
3712 ConvSecToHMS(iData * 60, wcTime, countof(wcTime));
3713 hr = Iis7PutPropertyString(pElement, IIS_CONFIG_IDLETIMEOUT, wcTime);
3714 ExitOnFailure(hr, "Failed to set AppPool processModel idle timeout value");
3715 ReleaseNullObject(pElement);
3716 break;
3717 }
3718 case IIS_APPPOOL_RECYCLE_QUEUELIMIT :
3719 {
3720 // /applicationPools | queueLength
3721 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iData);
3722 ExitOnFailure(hr, "Failed to read AppPool recycle queue limit");
3723 hr = Iis7PutPropertyInteger(pAppPoolElement, IIS_CONFIG_QUEUELENGTH, iData);
3724 ExitOnFailure(hr, "Failed to set AppPool recycle queue limit value");
3725 break;
3726 }
3727 case IIS_APPPOOL_MAXPROCESS :
3728 {
3729 // /processModel | maxProcesses
3730 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iData);
3731 ExitOnFailure(hr, "Failed to read AppPool max processes");
3732 hr = pAppPoolElement->GetElementByName(ScopeBSTR(IIS_CONFIG_PROCESSMODEL), &pElement);
3733 ExitOnFailure(hr, "Failed to get AppPool processModel element");
3734 hr = Iis7PutPropertyInteger(pElement, IIS_CONFIG_MAXWRKPROCESSES, iData);
3735 ExitOnFailure(hr, "Failed to set AppPool processModel maxProcesses value");
3736 ReleaseNullObject(pElement);
3737 break;
3738 }
3739 case IIS_APPPOOL_IDENTITY :
3740 {
3741 //"LocalSystem" 0
3742 //"LocalService" 1
3743 //"NetworkService" 2
3744 //"SpecificUser" 3
3745 //"ApplicationPoolIdentity" 4
3746 // /processModel | identityType
3747 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iData);
3748 ExitOnFailure(hr, "Failed to read AppPool identity");
3749 hr = pAppPoolElement->GetElementByName(ScopeBSTR(IIS_CONFIG_PROCESSMODEL), &pElement);
3750 ExitOnFailure(hr, "Failed to get AppPool processModel element");
3751 if (iData == 0)
3752 {
3753 hr = Iis7PutPropertyString(pElement, IIS_CONFIG_IDENITITYTYPE, IIS_CONFIG_LOCALSYSTEM);
3754 }
3755 else if (iData == 1)
3756 {
3757 hr = Iis7PutPropertyString(pElement, IIS_CONFIG_IDENITITYTYPE, IIS_CONFIG_LOCALSERVICE);
3758 }
3759 else if (iData == 2)
3760 {
3761 hr = Iis7PutPropertyString(pElement, IIS_CONFIG_IDENITITYTYPE, IIS_CONFIG_NETWORKSERVICE);
3762 }
3763 else if (iData == 3)
3764 {
3765 hr = Iis7PutPropertyString(pElement, IIS_CONFIG_IDENITITYTYPE, IIS_CONFIG_SPECIFICUSER);
3766 }
3767 else if (iData == 4)
3768 {
3769 hr = Iis7PutPropertyString(pElement, IIS_CONFIG_IDENITITYTYPE, IIS_CONFIG_APPLICATIONPOOLIDENTITY);
3770 }
3771 ExitOnFailure(hr, "Failed to set AppPool processModel identityType value");
3772 ReleaseNullObject(pElement);
3773 break;
3774 }
3775 case IIS_APPPOOL_USER :
3776 {
3777 // /processModel | userName
3778 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzData);
3779 ExitOnFailure(hr, "Failed to read AppPool user");
3780 hr = pAppPoolElement->GetElementByName(ScopeBSTR(IIS_CONFIG_PROCESSMODEL), &pElement);
3781 ExitOnFailure(hr, "Failed to get AppPool processModel element");
3782 hr = Iis7PutPropertyString(pElement, IIS_CONFIG_USERNAME, pwzData);
3783 ExitOnFailure(hr, "Failed to set AppPool processModel username value");
3784 ReleaseNullObject(pElement);
3785 break;
3786 }
3787 case IIS_APPPOOL_PWD :
3788 {
3789 // /processModel | password
3790 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzData);
3791 ExitOnFailure(hr, "Failed to read AppPool pwd");
3792 hr = pAppPoolElement->GetElementByName(ScopeBSTR(IIS_CONFIG_PROCESSMODEL), &pElement);
3793 ExitOnFailure(hr, "Failed to get AppPool processModel element");
3794 hr = Iis7PutPropertyString(pElement, IIS_CONFIG_PASSWORD, pwzData);
3795 ExitOnFailure(hr, "Failed to set AppPool processModel password value");
3796 ReleaseNullObject(pElement);
3797 break;
3798 }
3799 case IIS_APPPOOL_RECYCLE_CPU_PCT:
3800 {
3801 // /cpu | limit
3802 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iData);
3803 ExitOnFailure(hr, "Failed to read cpu pct");
3804 hr = pAppPoolElement->GetElementByName(ScopeBSTR(IIS_CONFIG_CPU), &pElement);
3805 ExitOnFailure(hr, "Failed to get AppPool cpu element");
3806 // limit is maximum percentage of CPU time (in 1/1000ths of one percent)
3807 hr = Iis7PutPropertyInteger(pElement, IIS_CONFIG_LIMIT, iData * 1000);
3808 ExitOnFailure(hr, "Failed to set AppPool cpu limit");
3809 ReleaseNullObject(pElement);
3810 break;
3811 }
3812 case IIS_APPPOOL_RECYCLE_CPU_REFRESH:
3813 {
3814 // /cpu | resetInterval
3815 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iData);
3816 ExitOnFailure(hr, "Failed to read cpu refresh pwd");
3817 hr = pAppPoolElement->GetElementByName(ScopeBSTR(IIS_CONFIG_CPU), &pElement);
3818 ExitOnFailure(hr, "Failed to get AppPool cpu element");
3819 *wcTime = '\0';
3820 ConvSecToHMS(iData * 60, wcTime, countof(wcTime));
3821 hr = Iis7PutPropertyString(pElement, IIS_CONFIG_RESETINTERVAL, wcTime);
3822 ExitOnFailure(hr, "Failed to set AppPool cpu resetInterval value");
3823 ReleaseNullObject(pElement);
3824 break;
3825 }
3826 case IIS_APPPOOL_RECYCLE_CPU_ACTION:
3827 {
3828 // /cpu | action
3829 //"NoAction" 0
3830 //"KillW3wp" 1
3831 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iData);
3832 ExitOnFailure(hr, "Failed to read cpu action");
3833 hr = pAppPoolElement->GetElementByName(ScopeBSTR(IIS_CONFIG_CPU), &pElement);
3834 ExitOnFailure(hr, "Failed to get AppPool cpu element");
3835 if (iData)
3836 {
3837 hr = Iis7PutPropertyString(pElement, IIS_CONFIG_CPU_ACTION, IIS_CONFIG_KILLW3WP);
3838 }
3839 else
3840 {
3841 hr = Iis7PutPropertyString(pElement, IIS_CONFIG_CPU_ACTION, IIS_CONFIG_NOACTION);
3842 }
3843 ExitOnFailure(hr, "Failed to set AppPool cpu action value");
3844 ReleaseNullObject(pElement);
3845 break;
3846 }
3847 case IIS_APPPOOL_32BIT:
3848 {
3849 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iData);
3850 ExitOnFailure(hr, "Failed to read enable32BitAppOnWin64 value");
3851 // enable32BitAppOnWin64
3852 hr = Iis7PutPropertyBool(pAppPoolElement, IIS_CONFIG_ENABLE32, iData ? TRUE : FALSE);
3853 ExitOnFailure(hr, "Failed to set AppPool enable32BitAppOnWin64 value");
3854 break;
3855 }
3856 case IIS_APPPOOL_MANAGED_PIPELINE_MODE:
3857 {
3858 // managedPipelineMode
3859 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzData);
3860 ExitOnFailure(hr, "Failed to read AppPool managedRuntimeVersion");
3861 hr = Iis7PutPropertyString(pAppPoolElement, IIS_CONFIG_PIPELINEMODE, pwzData);
3862 ExitOnFailure(hr, "Failed set AppPool managedPipelineMode property");
3863 break;
3864 }
3865 case IIS_APPPOOL_MANAGED_RUNTIME_VERSION:
3866 {
3867 // managedRuntimeVersion
3868 hr = WcaReadStringFromCaData(ppwzCustomActionData, &pwzData);
3869 ExitOnFailure(hr, "Failed to read AppPool managedRuntimeVersion");
3870 hr = Iis7PutPropertyString(pAppPoolElement, IIS_CONFIG_MANAGEDRUNTIMEVERSION, pwzData);
3871 ExitOnFailure(hr, "Failed set AppPool managedRuntimeVersion property");
3872 break;
3873 }
3874
3875 default:
3876 ExitOnFailure(hr = E_UNEXPECTED, "Unexpected IIS Config action specified for AppPool");
3877 break;
3878
3879 }
3880 // Get AppPool property action
3881 hr = WcaReadIntegerFromCaData(ppwzCustomActionData, &iAction);
3882 ExitOnFailure(hr, "Failed to read AppPool Property action");
3883 }
3884
3885LExit:
3886 ReleaseObject(pAppPools);
3887 ReleaseObject(pCollection);
3888 ReleaseObject(pCollection2);
3889 ReleaseObject(pAppPoolElement);
3890 ReleaseObject(pElement);
3891 ReleaseObject(pElement2);
3892 ReleaseObject(pElement3);
3893
3894 return hr;
3895}
3896
3897static HRESULT SetDirPropAuthentications(IAppHostWritableAdminManager *pAdminMgr,
3898 LPCWSTR wszConfigPath,
3899 DWORD dwData)
3900{
3901 HRESULT hr = S_OK;
3902 IAppHostElement *pSection = NULL;
3903
3904 //dwData contains bit flags for /security/authentication/<...>
3905 // Anonymous = 1
3906 // Basic = 2
3907 // Windows = 4
3908 // Digest =16
3909 // Passport =64 *not supported
3910 //translation required from bit map to section name
3911 // E.G security/authentication/windowsAuthentication [property enabled true|false]
3912
3913 // AnonymousAuthentication = 1
3914 hr = pAdminMgr->GetAdminSection(ScopeBSTR(L"system.webServer/security/authentication/anonymousAuthentication"), ScopeBSTR(wszConfigPath), &pSection);
3915 ExitOnFailure(hr, "Failed get AnonymousAuthentication section for DirProp");
3916 if (!pSection)
3917 {
3918 hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
3919 ExitOnFailure(hr, "Failed get AnonymousAuthentication section object for DirProps");
3920 }
3921
3922 hr = Iis7PutPropertyBool(pSection, L"enabled", (BOOL)(dwData & 0x1));
3923 ExitOnFailure(hr, "Failed set AnonymousAuthentication enabled for DirProps");
3924 ReleaseNullObject(pSection);
3925
3926 // basicAuthentication = 2
3927 hr = pAdminMgr->GetAdminSection(ScopeBSTR(L"system.webServer/security/authentication/basicAuthentication"), ScopeBSTR(wszConfigPath), &pSection);
3928 ExitOnFailure(hr, "Failed get basicAuthentication section for DirProp");
3929 if (!pSection)
3930 {
3931 hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
3932 ExitOnFailure(hr, "Failed get basicAuthentication section object for DirProps");
3933 }
3934
3935 hr = Iis7PutPropertyBool(pSection, L"enabled", (BOOL)(dwData & 0x2));
3936 ExitOnFailure(hr, "Failed set basicAuthentication enabled for DirProps");
3937 ReleaseNullObject(pSection);
3938
3939 // WindowsAuthentication = 4
3940 hr = pAdminMgr->GetAdminSection(ScopeBSTR(L"system.webServer/security/authentication/windowsAuthentication"), ScopeBSTR(wszConfigPath), &pSection);
3941 ExitOnFailure(hr, "Failed get windowsAuthentication section for DirProp");
3942 if (!pSection)
3943 {
3944 hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
3945 ExitOnFailure(hr, "Failed get windowsAuthentication section object for DirProps");
3946 }
3947
3948 hr = Iis7PutPropertyBool(pSection, L"enabled", (BOOL)(dwData & 0x4));
3949 ExitOnFailure(hr, "Failed set windowsAuthentication enabled for DirProps");
3950 ReleaseNullObject(pSection);
3951
3952 // digestAuthentication = 16
3953 hr = pAdminMgr->GetAdminSection(ScopeBSTR(L"system.webServer/security/authentication/digestAuthentication"), ScopeBSTR(wszConfigPath), &pSection);
3954 ExitOnFailure(hr, "Failed get digestAuthentication section for DirProp");
3955 if (!pSection)
3956 {
3957 hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
3958 ExitOnFailure(hr, "Failed get digestAuthentication section object for DirProps");
3959 }
3960
3961 hr = Iis7PutPropertyBool(pSection, L"enabled", (BOOL)(dwData & 0x10));
3962 ExitOnFailure(hr, "Failed set digestAuthentication enabled for DirProps");
3963 ReleaseNullObject(pSection);
3964
3965LExit:
3966 ReleaseObject(pSection);
3967
3968 return hr;
3969}
3970
3971static HRESULT SetDirPropAuthProvider(IAppHostWritableAdminManager *pAdminMgr,
3972 LPCWSTR wszConfigPath,
3973 __in LPWSTR wszData)
3974{
3975 HRESULT hr = S_OK;
3976 IAppHostElement *pSection = NULL;
3977 IAppHostElement *pElement = NULL;
3978 IAppHostElement *pNewElement = NULL;
3979 IAppHostElementCollection *pCollection = NULL;
3980
3981 WCHAR wcDelim[] = L",";
3982 const WCHAR *wszToken = NULL;
3983 WCHAR *wszNextToken = NULL;
3984
3985 hr = pAdminMgr->GetAdminSection(ScopeBSTR(L"system.webServer/security/authentication/windowsAuthentication"), ScopeBSTR(wszConfigPath), &pSection);
3986 ExitOnFailure(hr, "Failed get windowsAuthentication section for DirProp providers");
3987
3988 hr = pSection->GetElementByName(ScopeBSTR(L"providers"), &pElement);
3989 ExitOnFailure(hr, "Failed get win auth providers section");
3990
3991 hr = pElement->get_Collection(&pCollection);
3992 ExitOnFailure(hr, "Failed get win auth providers collection");
3993
3994 hr = pCollection->Clear();
3995 ExitOnFailure(hr, "Failed to clear win auth providers collection");
3996
3997 //Clear out inherited items - add clear
3998 hr = pCollection->CreateNewElement(ScopeBSTR(IIS_CONFIG_CLEAR), &pNewElement);
3999 ExitOnFailure(hr, "Failed to create win auth providers clear element");
4000 hr = pCollection->AddElement(pNewElement);
4001 ExitOnFailure(hr, "Failed to add win auth providers clear element");
4002 ReleaseNullObject(pNewElement);
4003
4004 wszToken = wcstok_s( wszData, wcDelim, &wszNextToken);
4005 for (int i = 0; (wszToken); ++i)
4006 {
4007 hr = pCollection->CreateNewElement(ScopeBSTR(IIS_CONFIG_ADD), &pNewElement);
4008 ExitOnFailure(hr, "Failed to create win auth providers element");
4009
4010 hr = Iis7PutPropertyString( pNewElement, IIS_CONFIG_VALUE, wszToken);
4011 ExitOnFailure(hr, "Failed to set win auth providers value");
4012
4013 hr = pCollection->AddElement(pNewElement, i);
4014 ExitOnFailure(hr, "Failed to add win auth providers element");
4015 ReleaseNullObject(pNewElement);
4016
4017 wszToken = wcstok_s( NULL, wcDelim, &wszNextToken);
4018 }
4019
4020LExit:
4021 ReleaseObject(pSection);
4022 ReleaseObject(pCollection);
4023 ReleaseObject(pElement);
4024 ReleaseObject(pNewElement);
4025
4026 return hr;
4027}
4028
4029static HRESULT SetDirPropDefDoc(
4030 IAppHostWritableAdminManager *pAdminMgr,
4031 LPCWSTR wszConfigPath,
4032 __in LPWSTR wszData)
4033{
4034 HRESULT hr = S_OK;
4035 IAppHostElement *pSection = NULL;
4036 IAppHostElement *pElement = NULL;
4037 IAppHostElement *pNewElement = NULL;
4038 IAppHostElementCollection *pCollection = NULL;
4039
4040 WCHAR wcDelim[] = L",";
4041 const WCHAR *wszToken = NULL;
4042 WCHAR *wszNextToken = NULL;
4043
4044 hr = pAdminMgr->GetAdminSection(ScopeBSTR(IIS_CONFIG_DEFAULTDOC_SECTION), ScopeBSTR(wszConfigPath), &pSection);
4045 ExitOnFailure(hr, "Failed get defaultDocument section for DirProp");
4046
4047 hr = pSection->GetElementByName(ScopeBSTR(L"files"), &pElement);
4048 ExitOnFailure(hr, "Failed get win files section");
4049
4050 hr = pElement->get_Collection(&pCollection);
4051 ExitOnFailure(hr, "Failed get files collection");
4052
4053 hr = pCollection->Clear();
4054 ExitOnFailure(hr, "Failed clear files collection");
4055
4056 //Clear out inherited items - add clear
4057 hr = pCollection->CreateNewElement(ScopeBSTR(IIS_CONFIG_CLEAR), &pNewElement);
4058 ExitOnFailure(hr, "Failed to create files clear element");
4059 hr = pCollection->AddElement(pNewElement);
4060 ExitOnFailure(hr, "Failed to add files clear element");
4061
4062 wszToken = wcstok_s( wszData, wcDelim, &wszNextToken);
4063 for (int i = 0; (wszToken); ++i)
4064 {
4065 hr = pCollection->CreateNewElement(ScopeBSTR(IIS_CONFIG_ADD), &pNewElement);
4066 ExitOnFailure(hr, "Failed to create win auth providers element");
4067
4068 hr = Iis7PutPropertyString( pNewElement, IIS_CONFIG_VALUE, wszToken);
4069 ExitOnFailure(hr, "Failed to set win auth providers value");
4070
4071 hr = pCollection->AddElement(pNewElement, i);
4072 ExitOnFailure(hr, "Failed to add defaultDocument Files element");
4073 ReleaseNullObject(pNewElement);
4074
4075 wszToken = wcstok_s( NULL, wcDelim, &wszNextToken);
4076 }
4077
4078LExit:
4079 ReleaseObject(pSection);
4080 ReleaseObject(pCollection);
4081 ReleaseObject(pNewElement);
4082
4083 return hr;
4084}
4085
4086static HRESULT ClearLocationTag(
4087 IAppHostWritableAdminManager *pAdminMgr,
4088 LPCWSTR swLocationPath
4089 )
4090{
4091 HRESULT hr = S_OK;
4092 IAppHostConfigManager *pConfigMgr = NULL;
4093 IAppHostConfigFile *pConfigFile = NULL;
4094 IAppHostConfigLocationCollection *pLocationCollection = NULL;
4095 IAppHostConfigLocation *pLocation = NULL;
4096
4097 DWORD dwCount = 0;
4098 BSTR bstrLocationPath = NULL;
4099
4100 hr = pAdminMgr->get_ConfigManager(&pConfigMgr);
4101 ExitOnFailure(hr, "Failed to get IIS ConfigManager interface");
4102
4103 hr = pConfigMgr->GetConfigFile(ScopeBSTR(IIS_CONFIG_APPHOST_ROOT), &pConfigFile);
4104 ExitOnFailure(hr, "Failed to get IIS ConfigFile interface");
4105
4106 hr = pConfigFile->get_Locations(&pLocationCollection);
4107 ExitOnFailure(hr, "Failed to get IIS location tag collection");
4108
4109 hr = pLocationCollection->get_Count(&dwCount);
4110 ExitOnFailure(hr, "Failed to get IIS location collection count");
4111
4112 VARIANT vtIndex;
4113 vtIndex.vt = VT_UI4;
4114 for (DWORD i = 0; i < dwCount; ++i)
4115 {
4116 vtIndex.ulVal = i;
4117 hr = pLocationCollection->get_Item(vtIndex, &pLocation);
4118 ExitOnFailure(hr, "Failed to get IIS location collection count");
4119
4120 hr = pLocation->get_Path(&bstrLocationPath);
4121 if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, swLocationPath, -1, bstrLocationPath, -1))
4122 {
4123 hr = pLocationCollection->DeleteLocation(vtIndex);
4124 ExitOnFailure(hr, "Failed to delete IIS location tag %ls",swLocationPath);
4125 break;
4126 }
4127
4128 ReleaseNullObject(pLocation);
4129 ::SysFreeString(bstrLocationPath);
4130 bstrLocationPath = NULL;
4131 }
4132LExit:
4133 ReleaseObject(pConfigMgr);
4134 ReleaseObject(pConfigFile);
4135 ReleaseObject(pLocationCollection);
4136 ReleaseObject(pLocation);
4137 ReleaseBSTR(bstrLocationPath);
4138
4139 return hr;
4140
4141}
4142
4143static HRESULT DeleteCollectionElement(
4144 __in IAppHostElementCollection *pCollection,
4145 __in LPCWSTR pwzElementName,
4146 __in LPCWSTR pwzAttributeName,
4147 __in LPCWSTR pwzAttributeValue
4148 )
4149{
4150 HRESULT hr = S_OK;
4151
4152 DWORD dwIndex;
4153 VARIANT vtIndex;
4154 VariantInit(&vtIndex);
4155
4156 hr = Iis7FindAppHostElementString(pCollection, pwzElementName, pwzAttributeName, pwzAttributeValue, NULL, &dwIndex);
4157 ExitOnFailure(hr, "Failed while finding IAppHostElement %ls/@%ls=%ls", pwzElementName, pwzAttributeName, pwzAttributeValue);
4158
4159 if (MAXDWORD != dwIndex)
4160 {
4161 vtIndex.vt = VT_UI4;
4162 vtIndex.ulVal = dwIndex;
4163 hr = pCollection->DeleteElement(vtIndex);
4164 ExitOnFailure(hr, "Failed to delete IAppHostElement %ls/@%ls=%ls", pwzElementName, pwzAttributeName, pwzAttributeValue);
4165 }
4166 // else : nothing to do, already deleted
4167LExit:
4168 ReleaseVariant(vtIndex);
4169
4170 return hr;
4171}
4172static void ConvSecToHMS( int Sec, __out_ecount(cchDest) LPWSTR wcTime, size_t cchDest)
4173{
4174 int ZH, ZM, ZS = 0;
4175
4176 ZH = (Sec / 3600);
4177 Sec = Sec - ZH * 3600;
4178 ZM = (Sec / 60) ;
4179 Sec = Sec - ZM * 60;
4180 ZS = Sec ;
4181
4182 HRESULT hr = ::StringCchPrintfW(wcTime, cchDest, L"%02d:%02d:%02d", ZH, ZM, ZS);
4183 if (S_OK != hr)
4184 {
4185 *wcTime = '\0';
4186 }
4187}
4188static void ConvSecToDHMS( unsigned int Sec, __out_ecount(cchDest) LPWSTR wcTime, size_t cchDest)
4189{
4190 int ZD, ZH, ZM, ZS = 0;
4191
4192 ZD = Sec / 86400;
4193 Sec = Sec - ZD * 86400;
4194 ZH = (Sec / 3600);
4195 Sec = Sec - ZH * 3600;
4196 ZM = (Sec / 60) ;
4197 Sec = Sec - ZM * 60;
4198 ZS = Sec ;
4199
4200 HRESULT hr = ::StringCchPrintfW(wcTime, cchDest, L"%d.%02d:%02d:%02d", ZD, ZH, ZM, ZS);
4201 if (S_OK != hr)
4202 {
4203 *wcTime = '\0';
4204 }
4205}