Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

782 lines
20 KiB

  1. /*++
  2. Copyright (c) 2000-2001 Microsoft Corporation
  3. Module Name:
  4. SiteCreator.cpp
  5. Abstract:
  6. Implementation of:
  7. CSiteCreator
  8. The public methods are thread-safe.
  9. Author:
  10. Mohit Srivastava 21-Mar-2001
  11. Revision History:
  12. --*/
  13. #include "sitecreator.h"
  14. #include <iiscnfg.h>
  15. #include <iiscnfgp.h> // internal
  16. #include <hashfn.h>
  17. #include <limits.h>
  18. #include <mdmsg.h>
  19. #include "debug.h"
  20. //
  21. // consts
  22. //
  23. static const DWORD DW_MAX_SITEID = INT_MAX;
  24. static const DWORD DW_TIMEOUT = 30000;
  25. //
  26. // Number of ERROR_PATH_BUSY's before we give up
  27. //
  28. static const DWORD DW_NUM_TRIES = 1;
  29. static LPCWSTR WSZ_SLASH_ROOT = L"/root/";
  30. static LPCWSTR WSZ_SLASH_FILTERS = L"/filters/";
  31. static ULONG CCH_SLASH_ROOT = wcslen(WSZ_SLASH_ROOT);
  32. #define WSZ_PATH_W3SVC L"/LM/w3svc/"
  33. #define WSZ_PATH_MSFTPSVC L"/LM/msftpsvc/"
  34. #define WSZ_IISWEBSERVER L"IIsWebServer"
  35. #define WSZ_IISWEBVIRTUALDIR L"IIsWebVirtualDir"
  36. #define WSZ_IISFTPSERVER L"IIsFtpServer"
  37. #define WSZ_IISFTPVIRTUALDIR L"IIsFtpVirtualDir"
  38. #define WSZ_IISFILTERS L"IIsFilters"
  39. //
  40. // W3Svc
  41. //
  42. TService TServiceData::W3Svc =
  43. {
  44. SC_W3SVC,
  45. WSZ_PATH_W3SVC,
  46. sizeof(WSZ_PATH_W3SVC)/sizeof(WCHAR)-1,
  47. WSZ_IISWEBSERVER,
  48. sizeof(WSZ_IISWEBSERVER)/sizeof(WCHAR)-1,
  49. WSZ_IISWEBVIRTUALDIR,
  50. sizeof(WSZ_IISWEBVIRTUALDIR)/sizeof(WCHAR)-1
  51. };
  52. //
  53. // MSFtpSvc
  54. //
  55. TService TServiceData::MSFtpSvc =
  56. {
  57. SC_MSFTPSVC,
  58. WSZ_PATH_MSFTPSVC,
  59. sizeof(WSZ_PATH_MSFTPSVC)/sizeof(WCHAR)-1,
  60. WSZ_IISFTPSERVER,
  61. sizeof(WSZ_IISFTPSERVER)/sizeof(WCHAR)-1,
  62. WSZ_IISFTPVIRTUALDIR,
  63. sizeof(WSZ_IISFTPVIRTUALDIR)/sizeof(WCHAR)-1
  64. };
  65. //
  66. // Collection of supported services
  67. //
  68. TService* TServiceData::apService[] =
  69. {
  70. &W3Svc,
  71. &MSFtpSvc,
  72. NULL
  73. };
  74. //
  75. // public
  76. //
  77. CSiteCreator::CSiteCreator()
  78. {
  79. m_bInit = false;
  80. }
  81. CSiteCreator::CSiteCreator(
  82. IMSAdminBase* pIABase)
  83. {
  84. SC_ASSERT(pIABase != NULL);
  85. m_spIABase = pIABase;
  86. m_bInit = true;
  87. }
  88. CSiteCreator::~CSiteCreator()
  89. {
  90. }
  91. DWORD
  92. CSiteCreator::GetMajorVersion(METADATA_HANDLE hKey)
  93. {
  94. DWORD dwMajorVersion = 0;
  95. DWORD dwMDRequiredDataLen = 0;
  96. METADATA_RECORD mr;
  97. mr.dwMDIdentifier = MD_SERVER_VERSION_MAJOR;
  98. mr.dwMDAttributes = 0;
  99. mr.dwMDUserType = IIS_MD_UT_SERVER;
  100. mr.dwMDDataType = DWORD_METADATA;
  101. mr.dwMDDataLen = sizeof(dwMajorVersion);
  102. mr.pbMDData = reinterpret_cast<unsigned char *>(&dwMajorVersion);
  103. m_spIABase->GetData(hKey, L"Info", &mr, &dwMDRequiredDataLen);
  104. return dwMajorVersion;
  105. }
  106. HRESULT
  107. CSiteCreator::CreateNewSite2(
  108. /* [in] */ eSC_SUPPORTED_SERVICES eServiceId,
  109. /* [in] */ LPCWSTR wszServerComment,
  110. /* [in] */ LPCWSTR mszServerBindings,
  111. /* [in] */ LPCWSTR wszPathOfRootVirtualDir,
  112. /* [in] */ IIISApplicationAdmin* pIApplAdmin,
  113. /* [out] */ PDWORD pdwSiteId,
  114. /* [in] */ PDWORD pdwRequestedSiteId)
  115. {
  116. if( wszServerComment == NULL ||
  117. mszServerBindings == NULL ||
  118. wszPathOfRootVirtualDir == NULL ||
  119. pdwSiteId == NULL ||
  120. (m_bInit && m_spIABase == NULL) ) // means you used constructor incorrectly
  121. {
  122. return E_INVALIDARG;
  123. }
  124. HRESULT hr = InternalCreateNewSite(
  125. eServiceId,
  126. wszServerComment,
  127. mszServerBindings,
  128. wszPathOfRootVirtualDir,
  129. pIApplAdmin,
  130. pdwSiteId,
  131. pdwRequestedSiteId);
  132. return hr;
  133. }
  134. HRESULT
  135. CSiteCreator::CreateNewSite(
  136. /* [in] */ eSC_SUPPORTED_SERVICES eServiceId,
  137. /* [in] */ LPCWSTR wszServerComment,
  138. /* [out] */ PDWORD pdwSiteId,
  139. /* [in] */ PDWORD pdwRequestedSiteId)
  140. {
  141. if( wszServerComment == NULL ||
  142. pdwSiteId == NULL ||
  143. (m_bInit && m_spIABase == NULL) ) // means you used constructor incorrectly
  144. {
  145. return E_INVALIDARG;
  146. }
  147. return InternalCreateNewSite(
  148. eServiceId, wszServerComment, NULL, NULL, NULL, pdwSiteId, pdwRequestedSiteId);
  149. }
  150. //
  151. // private
  152. //
  153. HRESULT
  154. CSiteCreator::InternalCreateNewSite(
  155. eSC_SUPPORTED_SERVICES i_eServiceId,
  156. LPCWSTR i_wszServerComment,
  157. LPCWSTR i_mszServerBindings,
  158. LPCWSTR i_wszPathOfRootVirtualDir,
  159. IIISApplicationAdmin* i_pIApplAdmin,
  160. PDWORD o_pdwSiteId,
  161. PDWORD i_pdwRequestedSiteId)
  162. {
  163. SC_ASSERT(o_pdwSiteId);
  164. HRESULT hr = S_OK;
  165. METADATA_HANDLE hW3Svc = 0;
  166. bool bOpenHandle = false;
  167. DWORD dwSiteId = 0;
  168. WCHAR wszSiteId[20] = {0};
  169. if ((i_pdwRequestedSiteId) && (0 >= (LONG)(*i_pdwRequestedSiteId)))
  170. {
  171. return(E_INVALIDARG);
  172. }
  173. //
  174. // Lookup the service
  175. //
  176. TService** ppService = NULL;
  177. for(ppService = TServiceData::apService; *ppService != NULL; ppService++)
  178. {
  179. if((*ppService)->eId == i_eServiceId)
  180. {
  181. break;
  182. }
  183. }
  184. if(*ppService == NULL)
  185. {
  186. return E_INVALIDARG;
  187. }
  188. hr = InternalCreateNode(
  189. *ppService,
  190. (i_wszServerComment == NULL) ? L"" : i_wszServerComment,
  191. &hW3Svc,
  192. &dwSiteId,
  193. i_pdwRequestedSiteId);
  194. if(FAILED(hr))
  195. {
  196. return hr;
  197. }
  198. //
  199. // We now have an open metadata handle that must be closed.
  200. //
  201. bOpenHandle = true;
  202. //
  203. // w3svc/n/KeyType="IIsWebServer"
  204. //
  205. hr = InternalSetData(
  206. hW3Svc,
  207. _ultow(dwSiteId, wszSiteId, 10),
  208. MD_KEY_TYPE,
  209. (LPBYTE)(*ppService)->wszServerKeyType,
  210. ((*ppService)->cchServerKeyType + 1) * sizeof(WCHAR),
  211. METADATA_NO_ATTRIBUTES,
  212. STRING_METADATA,
  213. IIS_MD_UT_SERVER);
  214. if(FAILED(hr))
  215. {
  216. goto exit;
  217. }
  218. //
  219. // w3svc/n/ServerComment=i_wszServerComment
  220. //
  221. if(i_wszServerComment != NULL)
  222. {
  223. hr = InternalSetData(
  224. hW3Svc,
  225. wszSiteId,
  226. MD_SERVER_COMMENT,
  227. (LPBYTE)i_wszServerComment,
  228. (wcslen(i_wszServerComment) + 1) * sizeof(WCHAR),
  229. METADATA_INHERIT,
  230. STRING_METADATA,
  231. IIS_MD_UT_SERVER);
  232. if(FAILED(hr))
  233. {
  234. goto exit;
  235. }
  236. }
  237. //
  238. // w3svc/n/ServerBindings=i_mszServerBindings
  239. //
  240. if(i_mszServerBindings != NULL)
  241. {
  242. ULONG cEntriesCur = 0;
  243. ULONG cEntries = 0;
  244. do
  245. {
  246. cEntriesCur = wcslen(i_mszServerBindings + cEntries) + 1;
  247. cEntries += cEntriesCur;
  248. }
  249. while(cEntriesCur > 1);
  250. if(cEntries > 1)
  251. {
  252. hr = InternalSetData(
  253. hW3Svc,
  254. wszSiteId,
  255. MD_SERVER_BINDINGS,
  256. (LPBYTE)i_mszServerBindings,
  257. cEntries * sizeof(WCHAR),
  258. METADATA_NO_ATTRIBUTES,
  259. MULTISZ_METADATA,
  260. IIS_MD_UT_SERVER);
  261. if(FAILED(hr))
  262. {
  263. goto exit;
  264. }
  265. }
  266. }
  267. //
  268. // w3svc/n/AuthAnonymous
  269. //
  270. DWORD noAccess = 0;
  271. hr = InternalSetData(
  272. hW3Svc,
  273. wszSiteId,
  274. MD_AUTHORIZATION, // AuthFlags
  275. (LPBYTE)&noAccess,
  276. sizeof(DWORD),
  277. METADATA_INHERIT,
  278. DWORD_METADATA,
  279. IIS_MD_UT_FILE);
  280. if(FAILED(hr))
  281. {
  282. goto exit;
  283. }
  284. //
  285. // w3svc/n/Filters
  286. //
  287. if(i_eServiceId == SC_W3SVC)
  288. {
  289. if (GetMajorVersion(hW3Svc) >= 6)
  290. {
  291. SC_ASSERT((sizeof(wszSiteId)/sizeof(WCHAR) + CCH_SLASH_ROOT + 1) <= 30);
  292. WCHAR wszFiltersPath[30];
  293. wcscpy(wszFiltersPath, wszSiteId);
  294. wcscat(wszFiltersPath, WSZ_SLASH_FILTERS);
  295. hr = m_spIABase->AddKey(
  296. hW3Svc,
  297. wszFiltersPath);
  298. if(FAILED(hr))
  299. {
  300. goto exit;
  301. }
  302. //
  303. // w3svc/n/Filters/KeyType="IIsFilters"
  304. //
  305. WCHAR * wszFiltersNode = WSZ_IISFILTERS;
  306. hr = InternalSetData(
  307. hW3Svc,
  308. wszFiltersPath,
  309. MD_KEY_TYPE,
  310. (LPBYTE) wszFiltersNode,
  311. ((wcslen(wszFiltersNode) + 1) * sizeof(WCHAR)),
  312. METADATA_NO_ATTRIBUTES,
  313. STRING_METADATA,
  314. IIS_MD_UT_SERVER);
  315. if(FAILED(hr))
  316. {
  317. goto exit;
  318. }
  319. // Must set AdminAcl on Filters for iis6
  320. // BUG:692660
  321. hr = SetAdminACL(hW3Svc,wszFiltersPath);
  322. if(FAILED(hr))
  323. {
  324. //Trace(L"SetAdminACL:FAILED:hr=0x%x\r\n",hr);
  325. // if any failure happens while trying to set the AdminACL
  326. // forget it... just ignore the error, this is because
  327. // the AdminACL on Filters node is only for the UI
  328. // to display the filters being loaded correctly or not.
  329. //
  330. // We don't want to not let the user create a site just because
  331. // of this failure...
  332. //goto exit;
  333. }
  334. }
  335. }
  336. //
  337. // Create w3svc/n/root and associated properties only if i_wszPathOfRootVirtualDir
  338. // was specified.
  339. //
  340. if(i_wszPathOfRootVirtualDir != NULL)
  341. {
  342. //
  343. // w3svc/n/root
  344. //
  345. SC_ASSERT((sizeof(wszSiteId)/sizeof(WCHAR) + CCH_SLASH_ROOT + 1) <= 30);
  346. WCHAR wszVdirPath[30];
  347. wcscpy(wszVdirPath, wszSiteId);
  348. wcscat(wszVdirPath, WSZ_SLASH_ROOT);
  349. hr = m_spIABase->AddKey(
  350. hW3Svc,
  351. wszVdirPath);
  352. if(FAILED(hr))
  353. {
  354. goto exit;
  355. }
  356. //
  357. // w3svc/n/root/KeyType="IIsWebVirtualDir"
  358. //
  359. hr = InternalSetData(
  360. hW3Svc,
  361. wszVdirPath,
  362. MD_KEY_TYPE,
  363. (LPBYTE)(*ppService)->wszServerVDirKeyType,
  364. ((*ppService)->cchServerVDirKeyType + 1) * sizeof(WCHAR),
  365. METADATA_NO_ATTRIBUTES,
  366. STRING_METADATA,
  367. IIS_MD_UT_SERVER);
  368. if(FAILED(hr))
  369. {
  370. goto exit;
  371. }
  372. //
  373. // w3svc/n/root/Path=wszPathOfRootVirtualDir
  374. //
  375. hr = InternalSetData(
  376. hW3Svc,
  377. wszVdirPath,
  378. MD_VR_PATH,
  379. (LPBYTE)i_wszPathOfRootVirtualDir,
  380. (wcslen(i_wszPathOfRootVirtualDir) + 1) * sizeof(WCHAR),
  381. METADATA_INHERIT,
  382. STRING_METADATA,
  383. IIS_MD_UT_FILE);
  384. if(FAILED(hr))
  385. {
  386. goto exit;
  387. }
  388. //
  389. // w3svc/n/root/AppRoot="/LM/w3svc/n/root/"
  390. //
  391. if(i_eServiceId == SC_W3SVC && i_pIApplAdmin != NULL)
  392. {
  393. SC_ASSERT(((*ppService)->cchMDPath + sizeof(wszVdirPath)/sizeof(WCHAR) + 1) <= 50);
  394. WCHAR wszAppRoot[50];
  395. wcscpy(wszAppRoot, (*ppService)->wszMDPath);
  396. wcscat(wszAppRoot, wszVdirPath);
  397. m_spIABase->CloseKey(hW3Svc);
  398. bOpenHandle = false;
  399. hr = i_pIApplAdmin->CreateApplication(wszAppRoot, 2, NULL, FALSE);
  400. if(FAILED(hr))
  401. {
  402. // DBGPRINTF((DBG_CONTEXT, "[%s] CreateAppl failed, hr=0x%x\n", __FUNCTION__, hr));
  403. goto exit;
  404. }
  405. }
  406. }
  407. //
  408. // Set out parameters if everything succeeded
  409. //
  410. *o_pdwSiteId = dwSiteId;
  411. exit:
  412. if(bOpenHandle)
  413. {
  414. m_spIABase->CloseKey(hW3Svc);
  415. bOpenHandle = false;
  416. }
  417. return hr;
  418. }
  419. HRESULT
  420. CSiteCreator::InternalSetData(
  421. METADATA_HANDLE i_hMD,
  422. LPCWSTR i_wszPath,
  423. DWORD i_dwIdentifier,
  424. LPBYTE i_pData,
  425. DWORD i_dwNrBytes,
  426. DWORD i_dwAttributes,
  427. DWORD i_dwDataType,
  428. DWORD i_dwUserType
  429. )
  430. {
  431. HRESULT hr = S_OK;
  432. METADATA_RECORD mr;
  433. memset(&mr, 0, sizeof(METADATA_RECORD));
  434. mr.dwMDIdentifier = i_dwIdentifier;
  435. mr.pbMDData = i_pData;
  436. mr.dwMDDataLen = i_dwNrBytes;
  437. mr.dwMDAttributes = i_dwAttributes;
  438. mr.dwMDDataType = i_dwDataType;
  439. mr.dwMDUserType = i_dwUserType;
  440. hr = m_spIABase->SetData(
  441. i_hMD,
  442. i_wszPath,
  443. &mr);
  444. return hr;
  445. }
  446. HRESULT
  447. CSiteCreator::InternalCreateNode(
  448. TService* i_pService,
  449. LPCWSTR i_wszServerComment,
  450. PMETADATA_HANDLE o_phService,
  451. PDWORD o_pdwSiteId,
  452. const PDWORD i_pdwRequestedSiteId)
  453. {
  454. DWORD dwFalse = FALSE;
  455. METADATA_RECORD mr = {
  456. MD_SERVER_AUTOSTART,
  457. METADATA_INHERIT,
  458. IIS_MD_UT_SERVER,
  459. DWORD_METADATA,
  460. sizeof(DWORD),
  461. (unsigned char*)&dwFalse, // FALSE
  462. 0
  463. };
  464. HRESULT hr = InternalInitIfNecessary();
  465. if(FAILED(hr))
  466. {
  467. return hr;
  468. }
  469. SC_ASSERT(i_pService != NULL);
  470. SC_ASSERT(i_wszServerComment != NULL);
  471. SC_ASSERT(o_phService != NULL);
  472. SC_ASSERT(o_pdwSiteId != NULL);
  473. *o_pdwSiteId = 0;
  474. *o_phService = 0;
  475. DWORD idx = 0; // current index of for loop
  476. DWORD dwStart = -1; // starting index
  477. METADATA_HANDLE hService = 0;
  478. WCHAR wszSiteId[20] = {0};
  479. for(ULONG i = 0; i < DW_NUM_TRIES; i++)
  480. {
  481. hr = m_spIABase->OpenKey(
  482. METADATA_MASTER_ROOT_HANDLE,
  483. i_pService->wszMDPath,
  484. METADATA_PERMISSION_READ | METADATA_PERMISSION_WRITE,
  485. DW_TIMEOUT,
  486. &hService);
  487. if( hr == HRESULT_FROM_WIN32(ERROR_PATH_BUSY) )
  488. {
  489. continue;
  490. }
  491. else if( FAILED(hr) )
  492. {
  493. return hr;
  494. }
  495. else
  496. {
  497. break;
  498. }
  499. }
  500. if(FAILED(hr))
  501. {
  502. return hr;
  503. }
  504. if(i_pdwRequestedSiteId == NULL)
  505. {
  506. dwStart = ( HashFn::HashStringNoCase(i_wszServerComment) % DW_MAX_SITEID ) + 1;
  507. SC_ASSERT(dwStart != 0);
  508. SC_ASSERT(dwStart <= DW_MAX_SITEID);
  509. DWORD dwNrSitesTried = 0;
  510. for(idx = dwStart;
  511. dwNrSitesTried < DW_MAX_SITEID;
  512. dwNrSitesTried++, idx = (idx % DW_MAX_SITEID) + 1)
  513. {
  514. SC_ASSERT(idx != 0); // 0 is not a valid site id
  515. SC_ASSERT(idx <= DW_MAX_SITEID);
  516. hr = m_spIABase->AddKey(
  517. hService,
  518. _ultow(idx, wszSiteId, 10));
  519. if( hr == HRESULT_FROM_WIN32(ERROR_DUP_NAME) ||
  520. hr == HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS) )
  521. {
  522. continue;
  523. }
  524. else if(SUCCEEDED(hr))
  525. {
  526. break;
  527. }
  528. else
  529. {
  530. goto exit;
  531. }
  532. }
  533. if(FAILED(hr))
  534. {
  535. //
  536. // Tried everything, still failed!
  537. //
  538. goto exit;
  539. }
  540. }
  541. else
  542. {
  543. idx = *i_pdwRequestedSiteId;
  544. hr = m_spIABase->AddKey(
  545. hService,
  546. _ultow(idx, wszSiteId, 10));
  547. if(FAILED(hr))
  548. {
  549. goto exit;
  550. }
  551. }
  552. // Set ServerAutoStart = FALSE
  553. hr = m_spIABase->SetData(
  554. hService,
  555. _ultow(idx, wszSiteId, 10),
  556. &mr );
  557. if(FAILED(hr))
  558. {
  559. goto exit;
  560. }
  561. //
  562. // Set out parameters if everything succeeded
  563. //
  564. *o_pdwSiteId = idx;
  565. *o_phService = hService;
  566. exit:
  567. if(FAILED(hr))
  568. {
  569. m_spIABase->CloseKey(
  570. hService);
  571. }
  572. return hr;
  573. }
  574. HRESULT
  575. CSiteCreator::InternalInitIfNecessary()
  576. {
  577. HRESULT hr = S_OK;
  578. CSafeLock csSafe(m_SafeCritSec);
  579. if(m_bInit)
  580. {
  581. return hr;
  582. }
  583. hr = csSafe.Lock();
  584. hr = HRESULT_FROM_WIN32(hr);
  585. if(FAILED(hr))
  586. {
  587. return hr;
  588. }
  589. if(!m_bInit)
  590. {
  591. hr = CoCreateInstance(
  592. CLSID_MSAdminBase,
  593. NULL,
  594. CLSCTX_ALL,
  595. IID_IMSAdminBase,
  596. (void**)&m_spIABase);
  597. if(FAILED(hr))
  598. {
  599. m_bInit = false;
  600. }
  601. else
  602. {
  603. m_bInit = true;
  604. }
  605. }
  606. csSafe.Unlock();
  607. return hr;
  608. }
  609. HRESULT
  610. CSiteCreator::SetAdminACL(METADATA_HANDLE hW3Svc, LPCWSTR szKeyPath)
  611. {
  612. HRESULT hr = S_OK;
  613. METADATA_RECORD mr;
  614. LPBYTE pBuffer = NULL;
  615. DWORD dwBufferSize = 0;
  616. DWORD dwMDRequiredDataLen = 0;
  617. mr.dwMDIdentifier = MD_ADMIN_ACL;
  618. mr.dwMDAttributes = METADATA_NO_ATTRIBUTES;
  619. mr.dwMDUserType = ALL_METADATA;
  620. mr.dwMDDataType = BINARY_METADATA;
  621. mr.dwMDDataLen = dwBufferSize;
  622. mr.pbMDData = reinterpret_cast<unsigned char *>(pBuffer);
  623. hr = m_spIABase->GetData(
  624. hW3Svc,
  625. L"filters/",
  626. &mr,
  627. &dwBufferSize
  628. );
  629. if (FAILED(hr) && (hr != HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER)))
  630. {
  631. if (hr == MD_WARNING_PATH_NOT_FOUND || hr == MD_ERROR_DATA_NOT_FOUND)
  632. {
  633. // the filters node might not have an AdminAcl, if it doesn't
  634. // just return s_ok
  635. hr = S_OK;
  636. }
  637. goto SetAdminACL_Exit;
  638. }
  639. pBuffer = (LPBYTE) LocalAlloc(LPTR,dwBufferSize);
  640. if (!pBuffer)
  641. {
  642. hr = E_OUTOFMEMORY;
  643. goto SetAdminACL_Exit;
  644. }
  645. mr.dwMDIdentifier = MD_ADMIN_ACL;
  646. mr.dwMDAttributes = METADATA_NO_ATTRIBUTES;
  647. mr.dwMDUserType = ALL_METADATA;
  648. mr.dwMDDataType = BINARY_METADATA;
  649. mr.dwMDDataLen = dwBufferSize;
  650. mr.pbMDData = reinterpret_cast<unsigned char *>(pBuffer);
  651. hr = m_spIABase->GetData(
  652. hW3Svc,
  653. L"filters/",
  654. &mr,
  655. &dwMDRequiredDataLen
  656. );
  657. if (FAILED(hr))
  658. {
  659. if (hr == MD_WARNING_PATH_NOT_FOUND || hr == MD_ERROR_DATA_NOT_FOUND)
  660. {
  661. // the filters node might not have an AdminAcl, if it doesn't
  662. // just return s_ok
  663. hr = S_OK;
  664. }
  665. goto SetAdminACL_Exit;
  666. }
  667. // Default error if there is a problem from here on...
  668. hr = E_UNEXPECTED;
  669. if (mr.pbMDData && (mr.dwMDDataLen > 0))
  670. {
  671. // We have a AdminACL from the /w3svc/Filters Branch
  672. // lets write it to the new sites /w3svc/newsiteid/filters node.
  673. if (IsValidSecurityDescriptor(pBuffer))
  674. {
  675. hr = InternalSetData(hW3Svc,
  676. szKeyPath,
  677. MD_ADMIN_ACL,
  678. (LPBYTE) mr.pbMDData,
  679. mr.dwMDDataLen,
  680. METADATA_INHERIT | METADATA_SECURE | METADATA_REFERENCE,
  681. BINARY_METADATA,
  682. IIS_MD_UT_SERVER);
  683. }
  684. }
  685. SetAdminACL_Exit:
  686. if (pBuffer)
  687. {
  688. LocalFree(pBuffer);
  689. pBuffer = NULL;
  690. }
  691. return hr;
  692. }