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.

1493 lines
40 KiB

  1. /*===================================================================
  2. Microsoft IIS
  3. Microsoft Confidential.
  4. Copyright 1997 Microsoft Corporation. All Rights Reserved.
  5. Component: WAMREG
  6. File: mdconfig.cpp
  7. interface to update/query WAM related properties in metabase.
  8. Owner: LeiJin
  9. Note:
  10. ===================================================================*/
  11. #include "common.h"
  12. #include "auxfunc.h"
  13. #include "iiscnfgp.h"
  14. #include "dbgutil.h"
  15. #include "multisz.hxx"
  16. // Time out for metabase = 5 seconds
  17. const DWORD WamRegMetabaseConfig::m_dwMDDefaultTimeOut = 30*1000;
  18. IMSAdminBaseW* WamRegMetabaseConfig::m_pMetabase = NULL;
  19. //
  20. // Please refer to MDPropItem for definition
  21. // Application properties that might be updated by WAMREG
  22. //
  23. const MDPropItem WamRegMetabaseConfig::m_rgMDPropTemplate[IWMDP_MAX] =
  24. {
  25. {MD_APP_ROOT, STRING_METADATA, 0, EMD_NONE, E_FAIL},
  26. {MD_APP_ISOLATED, DWORD_METADATA, 0, EMD_NONE, E_FAIL},
  27. {MD_APP_WAM_CLSID, STRING_METADATA, 0, EMD_NONE, E_FAIL},
  28. {MD_APP_PACKAGE_ID, STRING_METADATA, 0, EMD_NONE, E_FAIL},
  29. {MD_APP_PACKAGE_NAME, STRING_METADATA, 0, EMD_NONE, E_FAIL},
  30. {MD_APP_LAST_OUTPROC_PID, STRING_METADATA, 0, EMD_NONE, E_FAIL},
  31. {MD_APP_FRIENDLY_NAME, STRING_METADATA, 0, EMD_NONE, E_FAIL},
  32. {MD_APP_STATE, DWORD_METADATA, 0, EMD_NONE, E_FAIL},
  33. {MD_APP_OOP_RECOVER_LIMIT, DWORD_METADATA, 0, EMD_NONE, E_FAIL},
  34. {MD_APP_APPPOOL_ID, STRING_METADATA, 0, EMD_NONE, E_FAIL}
  35. };
  36. /*===================================================================
  37. InitPropItemData
  38. Init a metabase item list, prepare for metabase update.
  39. Parameter:
  40. pMDPropItem: pointer to MDPropItem which is set to the default values.
  41. Return: NONE
  42. ===================================================================*/
  43. VOID WamRegMetabaseConfig::InitPropItemData(IN OUT MDPropItem* pMDPropItem)
  44. {
  45. DBG_ASSERT(pMDPropItem != NULL);
  46. memcpy(pMDPropItem, (void *)m_rgMDPropTemplate, sizeof(m_rgMDPropTemplate));
  47. return;
  48. }
  49. /*===================================================================
  50. MetabaseInit
  51. Initialize Metabase, and obtain Metabase DCOM interface.
  52. Parameter:
  53. pMetabase: [out] Metabase DCOM interface pointer.
  54. Return: HRESULT
  55. Side affect: Create a Metabase object, and get interface pointer.
  56. ===================================================================*/
  57. HRESULT WamRegMetabaseConfig::MetabaseInit
  58. (
  59. )
  60. {
  61. HRESULT hr = NOERROR;
  62. m_pMetabase = (IMSAdminBase *)NULL;
  63. hr = CoCreateInstance(CLSID_MSAdminBase
  64. , NULL
  65. , CLSCTX_SERVER
  66. , IID_IMSAdminBase
  67. , (void**)&(m_pMetabase));
  68. if (FAILED(hr))
  69. goto LErrExit;
  70. return hr;
  71. LErrExit:
  72. RELEASE((m_pMetabase));
  73. return hr;
  74. }
  75. /*===================================================================
  76. MetabaseUnInit
  77. release a metabase interface.
  78. Parameter:
  79. pMetabase: [in/out] Metabase DCOM interface pointer.
  80. Return: HRESULT
  81. Side affect: Destroy a metabase object.
  82. ===================================================================*/
  83. HRESULT WamRegMetabaseConfig::MetabaseUnInit
  84. (
  85. VOID
  86. )
  87. {
  88. RELEASE((m_pMetabase));
  89. return NOERROR;
  90. }
  91. /*===================================================================
  92. UpdateMD
  93. Update a WAM application property in metabase.
  94. Parameter:
  95. pMetabase a metabase pointer
  96. prgProp contains the info of updating a WAM properties in metabase.
  97. refer to the structure definition for more info.
  98. dwMDAttributes allows caller specified INHERITABLE attribute.
  99. fSaveData perform a IMSAdminBase::SaveData, defaults to false
  100. Return: HRESULT
  101. Side affect: Release pMetabase.
  102. ===================================================================*/
  103. HRESULT WamRegMetabaseConfig::UpdateMD
  104. (
  105. IN MDPropItem* prgProp,
  106. IN DWORD dwMDAttributes,
  107. IN LPCWSTR wszMetabasePath,
  108. IN BOOL fSaveData
  109. )
  110. {
  111. HRESULT hr = NOERROR;
  112. INT iItem = 0;
  113. METADATA_HANDLE hMetabase = NULL;
  114. DBG_ASSERT(m_pMetabase);
  115. DBG_ASSERT(prgProp);
  116. DBG_ASSERT(wszMetabasePath);
  117. //
  118. // Open Key
  119. //
  120. hr = m_pMetabase->OpenKey(METADATA_MASTER_ROOT_HANDLE, wszMetabasePath,
  121. METADATA_PERMISSION_WRITE, m_dwMDDefaultTimeOut, &hMetabase);
  122. if (SUCCEEDED(hr))
  123. {
  124. METADATA_RECORD recMetaData;
  125. //
  126. // Update WAM Application Metabase Properties.
  127. //
  128. for (iItem = 0; iItem < IWMDP_MAX; iItem ++)
  129. {
  130. if (prgProp[iItem].dwAction == EMD_SET)
  131. {
  132. DWORD dwUserType = IIS_MD_UT_WAM;
  133. if (iItem == IWMDP_ROOT)
  134. {
  135. dwUserType = IIS_MD_UT_FILE;
  136. }
  137. if (prgProp[iItem].dwType == STRING_METADATA)
  138. {
  139. DBG_ASSERT(prgProp[iItem].pwstrVal);
  140. MD_SET_DATA_RECORD(&recMetaData,
  141. prgProp[iItem].dwMDIdentifier,
  142. dwMDAttributes,
  143. dwUserType,
  144. STRING_METADATA,
  145. (wcslen(prgProp[iItem].pwstrVal)+1)*sizeof(WCHAR),
  146. (unsigned char *)prgProp[iItem].pwstrVal);
  147. }
  148. else if (prgProp[iItem].dwType == DWORD_METADATA)
  149. {
  150. MD_SET_DATA_RECORD(&recMetaData,
  151. prgProp[iItem].dwMDIdentifier,
  152. dwMDAttributes,
  153. dwUserType,
  154. DWORD_METADATA,
  155. sizeof(DWORD),
  156. (unsigned char *)&(prgProp[iItem].dwVal));
  157. }
  158. else
  159. {
  160. DBGPRINTF((DBG_CONTEXT, "Unsupported data type by WAMREG.\n"));
  161. DBG_ASSERT(FALSE);
  162. }
  163. hr = m_pMetabase->SetData(hMetabase, NULL, &recMetaData);
  164. prgProp[iItem].hrStatus = hr;
  165. if (FAILED(hr))
  166. {
  167. DBGPRINTF((DBG_CONTEXT, "Metabase SetData failed. Path = %S, id = %08x, error = %08x\n",
  168. wszMetabasePath,
  169. prgProp[iItem].dwMDIdentifier,
  170. hr));
  171. break;
  172. }
  173. }
  174. if (prgProp[iItem].dwAction == EMD_DELETE)
  175. {
  176. hr = m_pMetabase->DeleteData(hMetabase, NULL, prgProp[iItem].dwMDIdentifier,
  177. prgProp[iItem].dwType);
  178. }
  179. }
  180. m_pMetabase->CloseKey(hMetabase);
  181. if (SUCCEEDED(hr) && fSaveData == TRUE)
  182. {
  183. hr = m_pMetabase->SaveData();
  184. if (hr == HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION))
  185. {
  186. hr = NOERROR;
  187. }
  188. if (FAILED(hr))
  189. {
  190. DBG_ASSERT((DBG_CONTEXT, "Failed to call metabase->SaveData, Application path = %S,"
  191. "hr = %08x\n",
  192. wszMetabasePath,
  193. hr));
  194. DBG_ASSERT(SUCCEEDED(hr));
  195. }
  196. }
  197. }
  198. else
  199. {
  200. DBGPRINTF((DBG_CONTEXT, "Failed to open metabase path %S, error = %08x\n",
  201. wszMetabasePath,
  202. hr));
  203. }
  204. return hr;
  205. }
  206. /*===================================================================
  207. MDUpdateIISDefault
  208. Formerly write the default IIS package info to metabase under key "/LM/W3SVC".
  209. In IIS6 this metadata is obsolete, so remove it all.
  210. Including
  211. IISPackageName
  212. IISPackageID
  213. WAMCLSID
  214. Parameter:
  215. Return: HRESULT
  216. ===================================================================*/
  217. HRESULT WamRegMetabaseConfig::MDUpdateIISDefault()
  218. {
  219. HRESULT hr = NOERROR;
  220. MDPropItem rgProp[IWMDP_MAX];
  221. DBG_ASSERT(m_pMetabase != NULL);
  222. InitPropItemData(&rgProp[0]);
  223. // Update Package Name
  224. MDDeletePropItem(&rgProp[0], IWMDP_PACKAGE_NAME);
  225. // Update Package ID
  226. MDDeletePropItem(&rgProp[0], IWMDP_PACKAGEID);
  227. // Update DefaultWAMCLSID
  228. MDDeletePropItem(&rgProp[0], IWMDP_WAMCLSID);
  229. // Update APPRoot
  230. MDDeletePropItem(&rgProp[0], IWMDP_ROOT);
  231. //Update AppIsolated
  232. MDDeletePropItem(&rgProp[0], IWMDP_ISOLATED);
  233. MDDeletePropItem(&rgProp[0], IWMDP_LAST_OUTPROC_PID);
  234. MDDeletePropItem(&rgProp[0], IWMDP_FRIENDLY_NAME);
  235. hr = UpdateMD(rgProp, METADATA_NO_ATTRIBUTES, WamRegGlobal::g_szMDAppPathPrefix, TRUE);
  236. return hr;
  237. }
  238. HRESULT WamRegMetabaseConfig::MDSetStringProperty
  239. (
  240. IN IMSAdminBase * pMetabaseIn,
  241. IN LPCWSTR szMetabasePath,
  242. IN DWORD dwMetabaseProperty,
  243. IN LPCWSTR szMetabaseValue,
  244. IN DWORD dwMDUserType, /* = IIS_MD_UT_WAM */
  245. IN DWORD dwMDAttributes /* = METADATA_NO_ATTRIBUTES */
  246. )
  247. /*===================================================================
  248. MDSetProperty
  249. Set a value of a property at the given path.
  250. Parameters:
  251. pMetabaseIn : [in] optional metabase interface
  252. szMetabasePath : [in] metabase key
  253. dwMetabaseProperty : [in] Property to set
  254. szMetabaseValue : [in] Value to set on property
  255. dwMDUserType : [in, optional] UserType to set on property
  256. Return: BOOL
  257. ===================================================================*/
  258. {
  259. HRESULT hr = S_OK;
  260. IMSAdminBase* pMetabase = NULL;
  261. METADATA_HANDLE hMetabase = NULL;
  262. METADATA_RECORD mdrData;
  263. ZeroMemory(&mdrData, sizeof(mdrData));
  264. DBG_ASSERT(szMetabasePath);
  265. if (pMetabaseIn)
  266. {
  267. pMetabase = pMetabaseIn;
  268. }
  269. else
  270. {
  271. pMetabase = m_pMetabase;
  272. }
  273. DBG_ASSERT(pMetabase);
  274. hr = pMetabase->OpenKey(METADATA_MASTER_ROOT_HANDLE,
  275. szMetabasePath,
  276. METADATA_PERMISSION_WRITE,
  277. m_dwMDDefaultTimeOut,
  278. &hMetabase);
  279. if (FAILED(hr))
  280. {
  281. goto done;
  282. }
  283. MD_SET_DATA_RECORD(&mdrData,
  284. dwMetabaseProperty,
  285. dwMDAttributes,
  286. dwMDUserType,
  287. STRING_METADATA,
  288. (wcslen(szMetabaseValue)+1)*sizeof(WCHAR),
  289. szMetabaseValue);
  290. hr = pMetabase->SetData(hMetabase,
  291. L"/",
  292. &mdrData);
  293. if (FAILED(hr))
  294. {
  295. goto done;
  296. }
  297. hr = S_OK;
  298. done:
  299. if (pMetabase && hMetabase)
  300. {
  301. pMetabase->CloseKey(hMetabase);
  302. }
  303. return hr;
  304. }
  305. HRESULT WamRegMetabaseConfig::MDSetKeyType
  306. (
  307. IN IMSAdminBase * pMetabaseIn,
  308. IN LPCWSTR szMetabasePath,
  309. IN LPCWSTR szKeyType
  310. )
  311. {
  312. HRESULT hr = S_OK;
  313. IMSAdminBase* pMetabase = NULL;
  314. METADATA_HANDLE hMetabase = NULL;
  315. METADATA_RECORD mdrData;
  316. ZeroMemory(&mdrData, sizeof(mdrData));
  317. DBG_ASSERT(szMetabasePath);
  318. if (pMetabaseIn)
  319. {
  320. pMetabase = pMetabaseIn;
  321. }
  322. else
  323. {
  324. pMetabase = m_pMetabase;
  325. }
  326. DBG_ASSERT(pMetabase);
  327. hr = pMetabase->OpenKey(METADATA_MASTER_ROOT_HANDLE,
  328. szMetabasePath,
  329. METADATA_PERMISSION_WRITE,
  330. m_dwMDDefaultTimeOut,
  331. &hMetabase);
  332. if (FAILED(hr))
  333. {
  334. goto done;
  335. }
  336. MD_SET_DATA_RECORD(&mdrData,
  337. MD_KEY_TYPE,
  338. METADATA_NO_ATTRIBUTES,
  339. IIS_MD_UT_SERVER,
  340. STRING_METADATA,
  341. (wcslen(szKeyType)+1)*sizeof(WCHAR),
  342. szKeyType);
  343. hr = pMetabase->SetData(hMetabase,
  344. L"/",
  345. &mdrData);
  346. if (FAILED(hr))
  347. {
  348. goto done;
  349. }
  350. hr = S_OK;
  351. done:
  352. if (pMetabase && hMetabase)
  353. {
  354. pMetabase->CloseKey(hMetabase);
  355. }
  356. return hr;
  357. }
  358. HRESULT WamRegMetabaseConfig::MDDeleteKey
  359. (
  360. IN IMSAdminBase * pMetabaseIn,
  361. IN LPCWSTR szMetabasePath,
  362. IN LPCWSTR szKey
  363. )
  364. {
  365. HRESULT hr = S_OK;
  366. IMSAdminBase* pMetabase = NULL;
  367. METADATA_HANDLE hMetabase = NULL;
  368. DBG_ASSERT(szMetabasePath);
  369. DBG_ASSERT(szKey);
  370. if (pMetabaseIn)
  371. {
  372. pMetabase = pMetabaseIn;
  373. }
  374. else
  375. {
  376. pMetabase = m_pMetabase;
  377. }
  378. DBG_ASSERT(pMetabase);
  379. hr = pMetabase->OpenKey(METADATA_MASTER_ROOT_HANDLE,
  380. szMetabasePath,
  381. METADATA_PERMISSION_WRITE,
  382. m_dwMDDefaultTimeOut,
  383. &hMetabase);
  384. if (FAILED(hr))
  385. {
  386. goto done;
  387. }
  388. hr = pMetabase->DeleteKey(hMetabase,
  389. szKey);
  390. if (FAILED(hr))
  391. {
  392. goto done;
  393. }
  394. hr = S_OK;
  395. done:
  396. if (pMetabase && hMetabase)
  397. {
  398. pMetabase->CloseKey(hMetabase);
  399. }
  400. return hr;
  401. }
  402. BOOL WamRegMetabaseConfig::MDDoesPathExist
  403. (
  404. IN IMSAdminBase * pMetabaseIn,
  405. IN LPCWSTR szMetabasePath
  406. )
  407. /*===================================================================
  408. MDDoesPathExist
  409. Determine if a given path exists in the metabase
  410. Parameters:
  411. pMetabaseIn : [in] optional metabase interface
  412. szMetabasePath : [in] metabase key
  413. Return: BOOL
  414. ===================================================================*/
  415. {
  416. BOOL fRet = FALSE;
  417. HRESULT hr = S_OK;
  418. IMSAdminBase* pMetabase = NULL;
  419. METADATA_HANDLE hMetabase = NULL;
  420. DBG_ASSERT(szMetabasePath);
  421. if (pMetabaseIn)
  422. {
  423. pMetabase = pMetabaseIn;
  424. }
  425. else
  426. {
  427. pMetabase = m_pMetabase;
  428. }
  429. DBG_ASSERT(pMetabase);
  430. hr = pMetabase->OpenKey(METADATA_MASTER_ROOT_HANDLE,
  431. szMetabasePath,
  432. METADATA_PERMISSION_READ,
  433. m_dwMDDefaultTimeOut,
  434. &hMetabase);
  435. if (SUCCEEDED(hr))
  436. {
  437. fRet = TRUE;
  438. pMetabase->CloseKey(hMetabase);
  439. }
  440. else
  441. {
  442. fRet = FALSE;
  443. }
  444. return fRet;
  445. }
  446. /*===================================================================
  447. MDCreatePath
  448. Create a metabase path.(szMetabasePath)
  449. Parameter:
  450. szMetabasePath : [in] metabase key
  451. Return: HRESULT
  452. Note: fill in the pdwAppMode, memory buffer provided by the caller.
  453. ===================================================================*/
  454. HRESULT WamRegMetabaseConfig::MDCreatePath
  455. (
  456. IN IMSAdminBase *pMetabaseIn,
  457. IN LPCWSTR szMetabasePath
  458. )
  459. {
  460. HRESULT hr;
  461. IMSAdminBase *pMetabase = NULL;
  462. WCHAR *pwszApplicationPath = NULL;
  463. METADATA_HANDLE hMetabase = NULL;
  464. DBG_ASSERT(szMetabasePath);
  465. if (pMetabaseIn)
  466. {
  467. pMetabase = pMetabaseIn;
  468. }
  469. else
  470. {
  471. pMetabase = m_pMetabase;
  472. }
  473. if (_wcsnicmp(szMetabasePath, L"\\LM\\W3SVC\\", 10) == 0 ||
  474. _wcsnicmp(szMetabasePath, WamRegGlobal::g_szMDAppPathPrefix, WamRegGlobal::g_cchMDAppPathPrefix) == 0)
  475. {
  476. pwszApplicationPath = (WCHAR *)(szMetabasePath + 10);
  477. }
  478. else
  479. {
  480. hr = HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
  481. return hr;
  482. }
  483. // Open Key
  484. hr = pMetabase->OpenKey(METADATA_MASTER_ROOT_HANDLE, (LPCWSTR)WamRegGlobal::g_szMDAppPathPrefix,
  485. METADATA_PERMISSION_WRITE, m_dwMDDefaultTimeOut, &hMetabase);
  486. if (FAILED(hr))
  487. {
  488. DBGPRINTF((DBG_CONTEXT, "Failed to Open metabase key, path is /LM/W3SVC, hr = %08x\n",
  489. hr));
  490. }
  491. else
  492. {
  493. hr = pMetabase->AddKey(hMetabase, (LPCWSTR)pwszApplicationPath);
  494. if (FAILED(hr))
  495. {
  496. DBGPRINTF((DBG_CONTEXT, "Failed to AddKey to metabase, path is %S, hr = %08x\n",
  497. szMetabasePath,
  498. hr));
  499. }
  500. pMetabase->CloseKey(hMetabase);
  501. }
  502. return hr;
  503. }
  504. /*===================================================================
  505. MDGetDWORD
  506. Get a DWORD type property from Metabase Key(szMetabasePath)
  507. Parameter:
  508. szMetabasePath : [in] metabase key
  509. dwMDIdentifier : [in] indentifier
  510. Return: HRESULT
  511. ===================================================================*/
  512. HRESULT WamRegMetabaseConfig::MDGetDWORD
  513. (
  514. IN LPCWSTR szMetabasePath,
  515. IN DWORD dwMDIdentifier,
  516. OUT DWORD *pdwData
  517. )
  518. {
  519. HRESULT hr;
  520. METADATA_HANDLE hMetabase = NULL;
  521. METADATA_RECORD recMetaData;
  522. DWORD dwRequiredLen;
  523. IMSAdminBase *pMetabase = NULL;
  524. DBG_ASSERT(pdwData);
  525. DBG_ASSERT(szMetabasePath);
  526. pMetabase = m_pMetabase;
  527. // Open Key
  528. hr = pMetabase->OpenKey(METADATA_MASTER_ROOT_HANDLE, (LPCWSTR)szMetabasePath,
  529. METADATA_PERMISSION_READ, m_dwMDDefaultTimeOut, &hMetabase);
  530. if (SUCCEEDED(hr))
  531. {
  532. MD_SET_DATA_RECORD( &recMetaData, dwMDIdentifier, METADATA_NO_ATTRIBUTES,
  533. IIS_MD_UT_WAM, DWORD_METADATA, sizeof(DWORD), (unsigned char *)pdwData);
  534. hr = pMetabase->GetData(hMetabase, NULL, &recMetaData, &dwRequiredLen);
  535. if (FAILED(hr))
  536. {
  537. DBGPRINTF((DBG_CONTEXT, "Get MD_APP_ISOLATED failed on MD path %S, id %d, error = %08x\n",
  538. szMetabasePath,
  539. dwMDIdentifier,
  540. hr));
  541. }
  542. pMetabase->CloseKey(hMetabase);
  543. }
  544. return hr;
  545. }
  546. /*===================================================================
  547. MDSetAppState
  548. Set an application state. (i.e. If APPSTATE_PAUSE is set, then, the runtime
  549. W3SVC can not launch the application).
  550. Parameter:
  551. szMetabasePath : [in] metabase key
  552. dwState : App state to be set.
  553. Return: HRESULT
  554. ===================================================================*/
  555. HRESULT WamRegMetabaseConfig::MDSetAppState
  556. (
  557. IN LPCWSTR szMetabasePath,
  558. IN DWORD dwState
  559. )
  560. {
  561. METADATA_RECORD recMetaData;
  562. HRESULT hr;
  563. METADATA_HANDLE hMetabase;
  564. DBG_ASSERT(m_pMetabase);
  565. // Open Key
  566. hr = m_pMetabase->OpenKey(METADATA_MASTER_ROOT_HANDLE, (LPWSTR)szMetabasePath,
  567. METADATA_PERMISSION_WRITE, m_dwMDDefaultTimeOut, &hMetabase);
  568. if (SUCCEEDED(hr))
  569. {
  570. MD_SET_DATA_RECORD( &recMetaData, MD_APP_STATE, METADATA_INHERIT, IIS_MD_UT_WAM,
  571. DWORD_METADATA, sizeof(DWORD), (unsigned char *)&dwState);
  572. hr = m_pMetabase->SetData(hMetabase, NULL, &recMetaData);
  573. m_pMetabase->CloseKey(hMetabase);
  574. }
  575. return hr;
  576. }
  577. HRESULT WamRegMetabaseConfig::MDGetWAMCLSID
  578. (
  579. IN LPCWSTR szMetabasePath,
  580. IN OUT LPWSTR szWAMCLSID
  581. )
  582. {
  583. HRESULT hr;
  584. METADATA_HANDLE hMetabase = NULL;
  585. METADATA_RECORD recMetaData;
  586. DWORD dwRequiredLen;
  587. DBG_ASSERT(szWAMCLSID);
  588. DBG_ASSERT(szMetabasePath);
  589. szWAMCLSID[0] = NULL;
  590. // Open Key
  591. hr = m_pMetabase->OpenKey(METADATA_MASTER_ROOT_HANDLE, (LPWSTR)szMetabasePath,
  592. METADATA_PERMISSION_READ, m_dwMDDefaultTimeOut, &hMetabase);
  593. if (SUCCEEDED(hr))
  594. {
  595. MD_SET_DATA_RECORD( &recMetaData, MD_APP_WAM_CLSID, METADATA_NO_ATTRIBUTES, IIS_MD_UT_WAM,
  596. STRING_METADATA, uSizeCLSID*sizeof(WCHAR), (unsigned char *)szWAMCLSID);
  597. hr = m_pMetabase->GetData(hMetabase, NULL, &recMetaData, &dwRequiredLen);
  598. if (HRESULTTOWIN32(hr) == ERROR_INSUFFICIENT_BUFFER)
  599. {
  600. DBG_ASSERT(FALSE);
  601. }
  602. m_pMetabase->CloseKey(hMetabase);
  603. }
  604. return hr;
  605. }
  606. /*===================================================================
  607. MDGetIdentity
  608. Get pakcage Identity from Metabase Key(szMetabasePath) (WamUserName &
  609. WamPassword)
  610. Parameter:
  611. szIdentity: a string buffer for WamUserName.
  612. cbIdneity: size of the string buffer for szIdentity.
  613. szPwd: a string buffer for WamPassword.
  614. cbPwd: size of the string buffer for szPwd.
  615. Return: HRESULT
  616. ===================================================================*/
  617. HRESULT WamRegMetabaseConfig::MDGetIdentity
  618. (
  619. IN LPWSTR szIdentity,
  620. IN DWORD cbIdentity,
  621. IN LPWSTR szPwd,
  622. IN DWORD cbPwd
  623. )
  624. {
  625. HRESULT hr;
  626. METADATA_HANDLE hMetabase = NULL;
  627. METADATA_RECORD recMetaData;
  628. DWORD dwRequiredLen;
  629. DBG_ASSERT(szIdentity);
  630. szIdentity[0] = NULL;
  631. // Open Key
  632. hr = m_pMetabase->OpenKey(METADATA_MASTER_ROOT_HANDLE, (LPWSTR)WamRegGlobal::g_szMDAppPathPrefix,
  633. METADATA_PERMISSION_READ, m_dwMDDefaultTimeOut, &hMetabase);
  634. if (SUCCEEDED(hr))
  635. {
  636. // Get WAM user name
  637. MD_SET_DATA_RECORD( &recMetaData, MD_WAM_USER_NAME, METADATA_NO_ATTRIBUTES, IIS_MD_UT_WAM,
  638. STRING_METADATA, cbIdentity, (unsigned char *)szIdentity);
  639. hr = m_pMetabase->GetData(hMetabase, NULL, &recMetaData, &dwRequiredLen);
  640. if (HRESULTTOWIN32(hr) == ERROR_INSUFFICIENT_BUFFER)
  641. {
  642. DBGPRINTF((DBG_CONTEXT, "Insufficient buffer for WAM user name. Required size is %d\n",
  643. dwRequiredLen));
  644. DBG_ASSERT(FALSE);
  645. }
  646. // Get WAM user password
  647. MD_SET_DATA_RECORD( &recMetaData, MD_WAM_PWD, METADATA_NO_ATTRIBUTES, IIS_MD_UT_WAM,
  648. STRING_METADATA, cbPwd, (unsigned char *)szPwd);
  649. hr = m_pMetabase->GetData(hMetabase, NULL, &recMetaData, &dwRequiredLen);
  650. if (HRESULTTOWIN32(hr) == ERROR_INSUFFICIENT_BUFFER)
  651. {
  652. DBGPRINTF((DBG_CONTEXT, "Insufficient buffer for WAM user password. Required size is %d\n",
  653. dwRequiredLen));
  654. DBG_ASSERT(FALSE);
  655. }
  656. m_pMetabase->CloseKey(hMetabase);
  657. }
  658. return hr;
  659. }
  660. HRESULT
  661. WamRegMetabaseConfig::MDGetAppName
  662. (
  663. IN LPCWSTR szMetaPath,
  664. OUT LPWSTR * ppszAppName
  665. )
  666. /*++
  667. Function:
  668. Retrieve the MD_APP_PACKAGE_NAME from the metabase.
  669. Parameters:
  670. ppszAppName - value of MD_APP_PACKAGE_NAME allocated
  671. with new[] free with delete[]
  672. Return:
  673. {MD_APP_PACKAGE_NAME, STRING_METADATA, 0, EMD_NONE, E_FAIL},
  674. --*/
  675. {
  676. return MDGetStringAttribute(szMetaPath, MD_APP_PACKAGE_NAME, ppszAppName);
  677. }
  678. HRESULT
  679. WamRegMetabaseConfig::MDGetStringAttribute
  680. (
  681. IN LPCWSTR szMetaPath,
  682. DWORD dwMDIdentifier,
  683. OUT LPWSTR * ppszBuffer
  684. )
  685. {
  686. DBG_ASSERT( ppszBuffer );
  687. DBG_ASSERT( m_pMetabase );
  688. HRESULT hr = NOERROR;
  689. WCHAR * pwcMetaData = NULL;
  690. DWORD cbData = 0;
  691. METADATA_HANDLE hKey = NULL;
  692. METADATA_RECORD mdr;
  693. *ppszBuffer = NULL;
  694. hr = m_pMetabase->OpenKey(METADATA_MASTER_ROOT_HANDLE,
  695. szMetaPath,
  696. METADATA_PERMISSION_READ,
  697. m_dwMDDefaultTimeOut,
  698. &hKey);
  699. if( SUCCEEDED(hr) )
  700. {
  701. MD_SET_DATA_RECORD( &mdr,
  702. dwMDIdentifier,
  703. METADATA_INHERIT,
  704. IIS_MD_UT_WAM,
  705. STRING_METADATA,
  706. cbData,
  707. (LPBYTE)pwcMetaData
  708. );
  709. hr = m_pMetabase->GetData( hKey, NULL, &mdr, &cbData );
  710. if( HRESULTTOWIN32(hr) == ERROR_INSUFFICIENT_BUFFER )
  711. {
  712. pwcMetaData = new WCHAR[ cbData / sizeof(WCHAR) ];
  713. if( pwcMetaData != NULL )
  714. {
  715. mdr.pbMDData = (LPBYTE)pwcMetaData;
  716. mdr.dwMDDataLen = cbData;
  717. hr = m_pMetabase->GetData( hKey, NULL, &mdr, &cbData );
  718. }
  719. else
  720. {
  721. hr = E_OUTOFMEMORY;
  722. }
  723. }
  724. m_pMetabase->CloseKey( hKey );
  725. }
  726. //
  727. // Return AppName
  728. //
  729. if( SUCCEEDED(hr) )
  730. {
  731. DBG_ASSERT( pwcMetaData != NULL );
  732. *ppszBuffer = pwcMetaData;
  733. }
  734. else
  735. {
  736. DBG_ASSERT( *ppszBuffer == NULL );
  737. delete [] pwcMetaData;
  738. }
  739. return hr;
  740. }
  741. #ifdef _IIS_6_0
  742. HRESULT
  743. WamRegMetabaseConfig::MDGetAllSiteRoots
  744. (
  745. OUT LPWSTR * ppszBuffer
  746. )
  747. {
  748. DBG_ASSERT( m_pMetabase );
  749. DBG_ASSERT(ppszBuffer);
  750. *ppszBuffer = NULL;
  751. HRESULT hr = S_OK;
  752. METADATA_HANDLE hKey = NULL;
  753. DWORD dwEnumKeyIndex = 0;
  754. WCHAR szMDName[METADATA_MAX_NAME_LEN] = {0};
  755. MULTISZ mszSiteRoots;
  756. // Loop through all keys below /LM/W3SVC
  757. hr = m_pMetabase->EnumKeys(METADATA_MASTER_ROOT_HANDLE,
  758. L"/LM/W3SVC/",
  759. szMDName,
  760. dwEnumKeyIndex
  761. );
  762. while(SUCCEEDED(hr))
  763. {
  764. int i = _wtoi(szMDName);
  765. // if this is a site
  766. if(0 != i)
  767. {
  768. // have a valid site number
  769. WCHAR pTempBuf[METADATA_MAX_NAME_LEN] = {0};
  770. wcscpy(pTempBuf, L"/LM/W3SVC/");
  771. wcscat(pTempBuf, szMDName);
  772. wcscat(pTempBuf, L"/ROOT/");
  773. if (FALSE == mszSiteRoots.Append(pTempBuf))
  774. {
  775. hr = E_OUTOFMEMORY;
  776. goto done;
  777. }
  778. }
  779. dwEnumKeyIndex++;
  780. hr = m_pMetabase->EnumKeys(METADATA_MASTER_ROOT_HANDLE,
  781. L"/LM/W3SVC/",
  782. szMDName,
  783. dwEnumKeyIndex
  784. );
  785. }
  786. // data is in MULTISZ move to out buffer
  787. {
  788. UINT cchMulti = 0;
  789. DWORD dwBufferSize = 0;
  790. cchMulti = mszSiteRoots.QueryCCH();
  791. *ppszBuffer = new WCHAR[cchMulti];
  792. if (NULL == *ppszBuffer)
  793. {
  794. hr = E_OUTOFMEMORY;
  795. goto done;
  796. }
  797. dwBufferSize = cchMulti;
  798. mszSiteRoots.CopyToBuffer(*ppszBuffer, &dwBufferSize);
  799. }
  800. hr = S_OK;
  801. done:
  802. return hr;
  803. }
  804. #endif //_IIS_6_0
  805. /*===================================================================
  806. MDGetIdentity
  807. Get WAMCLSID, Wam PackageID, and fAppIsolated from a metabase path.
  808. Parameter:
  809. szMetabasepath : get info from this path.
  810. szWAMCLSID: buffer for WAMCLSID(fixed length buffer).
  811. szPackageID: buffer for Wam PackageID(fixed length buffer).
  812. fAppIsolated: if InProc(TRUE), do not retrieve szPackageID.
  813. Return: HRESULT
  814. ===================================================================*/
  815. HRESULT WamRegMetabaseConfig::MDGetIDs
  816. (
  817. IN LPCWSTR szMetabasePath,
  818. OUT LPWSTR szWAMCLSID,
  819. OUT LPWSTR szPackageID,
  820. IN DWORD dwAppMode
  821. )
  822. {
  823. HRESULT hr;
  824. METADATA_HANDLE hMetabase = NULL;
  825. METADATA_RECORD recMetaData;
  826. DWORD dwRequiredLen;
  827. DBG_ASSERT(m_pMetabase);
  828. DBG_ASSERT(szWAMCLSID);
  829. DBG_ASSERT(szPackageID);
  830. DBG_ASSERT(szMetabasePath);
  831. szPackageID[0] = NULL;
  832. szWAMCLSID[0] = NULL;
  833. // Open Key
  834. hr = m_pMetabase->OpenKey(METADATA_MASTER_ROOT_HANDLE, (LPWSTR)szMetabasePath,
  835. METADATA_PERMISSION_READ, m_dwMDDefaultTimeOut, &hMetabase);
  836. if (SUCCEEDED(hr))
  837. {
  838. MD_SET_DATA_RECORD( &recMetaData, MD_APP_WAM_CLSID, METADATA_NO_ATTRIBUTES, IIS_MD_UT_WAM,
  839. STRING_METADATA, uSizeCLSID*sizeof(WCHAR), (unsigned char *)szWAMCLSID);
  840. hr = m_pMetabase->GetData(hMetabase, NULL, &recMetaData, &dwRequiredLen);
  841. if (HRESULTTOWIN32(hr) == ERROR_INSUFFICIENT_BUFFER)
  842. {
  843. DBG_ASSERT(FALSE);
  844. }
  845. if (SUCCEEDED(hr))
  846. {
  847. if (dwAppMode == static_cast<DWORD>(eAppRunOutProcIsolated))
  848. {
  849. MD_SET_DATA_RECORD( &recMetaData, MD_APP_PACKAGE_ID, METADATA_NO_ATTRIBUTES, IIS_MD_UT_WAM,
  850. STRING_METADATA, uSizeCLSID*sizeof(WCHAR), (unsigned char *)szPackageID);
  851. hr = m_pMetabase->GetData(hMetabase, NULL, &recMetaData, &dwRequiredLen);
  852. if (HRESULTTOWIN32(hr) == ERROR_INSUFFICIENT_BUFFER)
  853. {
  854. DBG_ASSERT(FALSE);
  855. }
  856. }
  857. else if (dwAppMode == static_cast<DWORD>(eAppRunInProc))
  858. {
  859. wcsncpy(szPackageID, g_WamRegGlobal.g_szIISInProcPackageID, uSizeCLSID);
  860. }
  861. else
  862. {
  863. wcsncpy(szPackageID, g_WamRegGlobal.g_szIISOOPPoolPackageID, uSizeCLSID);
  864. }
  865. }
  866. m_pMetabase->CloseKey(hMetabase);
  867. }
  868. return hr;
  869. }
  870. /*===================================================================
  871. MDRemoveProperty
  872. Remove one MD property.
  873. Parameter:
  874. pwszMetabasePath
  875. dwIdentifier the MD indentifier to be removed.
  876. dwType the MD indietifier data type.
  877. Return: HRESULT
  878. ===================================================================*/
  879. HRESULT WamRegMetabaseConfig::MDRemoveProperty
  880. (
  881. IN LPCWSTR pwszMetabasePath,
  882. DWORD dwIdentifier,
  883. DWORD dwType
  884. )
  885. {
  886. METADATA_RECORD recMetaData;
  887. HRESULT hr;
  888. METADATA_HANDLE hMetabase;
  889. hr = m_pMetabase->OpenKey(METADATA_MASTER_ROOT_HANDLE, (LPWSTR)pwszMetabasePath,
  890. METADATA_PERMISSION_WRITE, m_dwMDDefaultTimeOut, &hMetabase);
  891. if (SUCCEEDED(hr))
  892. {
  893. hr = m_pMetabase->DeleteData(hMetabase, NULL, dwIdentifier, dwType);
  894. m_pMetabase->CloseKey(hMetabase);
  895. }
  896. return hr;
  897. }
  898. /*===================================================================
  899. MDGetLastOutProcPackageID
  900. Get LastOutProcPackageID from Metabase Key(szMetabasePath)
  901. Parameter:
  902. szMetabasePath : [in] metabase key
  903. szLastOutProcPackageID : [in] a pointer to LastOutProcPackageID buffer
  904. Return: HRESULT
  905. Note: fill in the LastOutProcPackageID, memory buffer provided by the caller.
  906. ===================================================================*/
  907. HRESULT WamRegMetabaseConfig::MDGetLastOutProcPackageID
  908. (
  909. IN LPCWSTR szMetabasePath,
  910. IN OUT LPWSTR szLastOutProcPackageID
  911. )
  912. {
  913. HRESULT hr;
  914. METADATA_HANDLE hMetabase = NULL;
  915. METADATA_RECORD recMetaData;
  916. DWORD dwRequiredLen;
  917. DBG_ASSERT(szLastOutProcPackageID);
  918. DBG_ASSERT(szMetabasePath);
  919. szLastOutProcPackageID[0] = NULL;
  920. // Open Key
  921. hr = m_pMetabase->OpenKey(METADATA_MASTER_ROOT_HANDLE, (LPWSTR)szMetabasePath,
  922. METADATA_PERMISSION_READ, m_dwMDDefaultTimeOut, &hMetabase);
  923. if (SUCCEEDED(hr))
  924. {
  925. MD_SET_DATA_RECORD( &recMetaData, MD_APP_LAST_OUTPROC_PID, METADATA_NO_ATTRIBUTES, IIS_MD_UT_WAM,
  926. STRING_METADATA, uSizeCLSID*sizeof(WCHAR), (unsigned char *)szLastOutProcPackageID);
  927. hr = m_pMetabase->GetData(hMetabase, NULL, &recMetaData, &dwRequiredLen);
  928. if (HRESULTTOWIN32(hr) == ERROR_INSUFFICIENT_BUFFER)
  929. {
  930. DBG_ASSERT(FALSE);
  931. }
  932. m_pMetabase->CloseKey(hMetabase);
  933. }
  934. return hr;
  935. }
  936. /*===================================================================
  937. GetWebServerName
  938. Look the WebServerName(ServerComment) property under the key (szMetabasePath).
  939. Parameter:
  940. None
  941. Return: HRESULT
  942. Note: fill in the szWebServerName, memory buffer provided by the caller.
  943. ===================================================================*/
  944. HRESULT WamRegMetabaseConfig::GetWebServerName
  945. (
  946. IN LPCWSTR wszMetabasePath,
  947. IN OUT LPWSTR wszWebServerName,
  948. IN UINT cBuffer
  949. )
  950. {
  951. HRESULT hr;
  952. METADATA_HANDLE hMetabase = NULL;
  953. METADATA_RECORD recMetaData;
  954. DWORD dwRequiredLen;
  955. DBG_ASSERT(wszMetabasePath);
  956. DBG_ASSERT(wszWebServerName);
  957. // Open Key
  958. hr = m_pMetabase->OpenKey( METADATA_MASTER_ROOT_HANDLE,
  959. wszMetabasePath,
  960. METADATA_PERMISSION_READ,
  961. m_dwMDDefaultTimeOut,
  962. &hMetabase
  963. );
  964. if (SUCCEEDED(hr))
  965. {
  966. MD_SET_DATA_RECORD( &recMetaData,
  967. MD_SERVER_COMMENT,
  968. METADATA_INHERIT,
  969. IIS_MD_UT_SERVER,
  970. STRING_METADATA,
  971. cBuffer,
  972. (unsigned char *)wszWebServerName
  973. );
  974. hr = m_pMetabase->GetData(hMetabase, L"", &recMetaData, &dwRequiredLen);
  975. if (HRESULTTOWIN32(hr) == ERROR_INSUFFICIENT_BUFFER)
  976. {
  977. DBGPRINTF((DBG_CONTEXT, "Insuffcient buffer for WebServerName. Path = %S\n",
  978. wszMetabasePath));
  979. DBG_ASSERT(FALSE);
  980. }
  981. //
  982. // If property MD_SERVER_COMMENT not found, null out the WebServerName.
  983. //
  984. if (hr == MD_ERROR_DATA_NOT_FOUND)
  985. {
  986. wszWebServerName[0] = L'\0';
  987. hr = NOERROR;
  988. }
  989. if (FAILED(hr))
  990. {
  991. DBGPRINTF((DBG_CONTEXT, "Failed to read Metabase for WebServerName. Path = %S, error = %08x\n",
  992. wszMetabasePath,
  993. hr));
  994. }
  995. m_pMetabase->CloseKey(hMetabase);
  996. }
  997. else
  998. {
  999. DBGPRINTF((DBG_CONTEXT, "Failed to read Metabase for WebServerName. Path = %S, error = %08x\n",
  1000. wszMetabasePath,
  1001. hr));
  1002. }
  1003. return hr;
  1004. }
  1005. /*===================================================================
  1006. GetSignatureOnPath
  1007. Get an application signature(AppRoot & AppIsolated) on a metabase path.
  1008. Parameter:
  1009. pwszMetabasePath
  1010. pdwSignature
  1011. Return: HRESULT
  1012. Note: Signature is returned via pdwSignature.
  1013. ===================================================================*/
  1014. HRESULT WamRegMetabaseConfig::GetSignatureOnPath
  1015. (
  1016. IN LPCWSTR pwszMetabasePath,
  1017. OUT DWORD* pdwSignature
  1018. )
  1019. {
  1020. HRESULT hr = NOERROR;
  1021. WCHAR szWAMCLSID[uSizeCLSID];
  1022. WCHAR szPackageID[uSizeCLSID];
  1023. DWORD dwResult = 0;
  1024. DWORD cSize = 0;
  1025. DWORD dwAppMode = 0;
  1026. DBG_ASSERT(pwszMetabasePath);
  1027. hr = MDGetDWORD(pwszMetabasePath, MD_APP_ISOLATED, &dwAppMode);
  1028. if (SUCCEEDED(hr))
  1029. {
  1030. hr = MDGetIDs(pwszMetabasePath, szWAMCLSID, szPackageID, (BOOL)dwAppMode);
  1031. if (SUCCEEDED(hr))
  1032. {
  1033. cSize = wcslen(pwszMetabasePath);
  1034. dwResult = WamRegChkSum(pwszMetabasePath, cSize);
  1035. dwResult ^= WamRegChkSum(szWAMCLSID, uSizeCLSID);
  1036. if (dwAppMode == eAppRunOutProcIsolated)
  1037. {
  1038. dwResult ^= WamRegChkSum(szPackageID, uSizeCLSID);
  1039. }
  1040. }
  1041. }
  1042. if (SUCCEEDED(hr))
  1043. {
  1044. *pdwSignature = dwResult;
  1045. }
  1046. else
  1047. {
  1048. *pdwSignature = 0;
  1049. }
  1050. return NOERROR;
  1051. }
  1052. /*===================================================================
  1053. WamRegChkSum
  1054. Give a wchar string, calculate a chk sum.
  1055. Parameter:
  1056. pszKey wchar string
  1057. cchKey wcslen(of wchar ) string
  1058. Return: ChkSum.
  1059. ===================================================================*/
  1060. DWORD WamRegMetabaseConfig::WamRegChkSum
  1061. (
  1062. IN LPCWSTR pszKey,
  1063. IN DWORD cchKey
  1064. )
  1065. {
  1066. DWORD hash = 0, g;
  1067. while (*pszKey)
  1068. {
  1069. hash = (hash << 4) + *pszKey++;
  1070. if (g = hash & 0xf0000000)
  1071. {
  1072. hash ^= g >> 24;
  1073. }
  1074. hash &= ~g;
  1075. }
  1076. return hash;
  1077. }
  1078. /*===================================================================
  1079. MDGetPropPaths
  1080. Get an array of metabase paths that contains a specific property.
  1081. Parameter:
  1082. szMetabasePath
  1083. dwMDIdentifier
  1084. pBuffer a pointer to a buffer
  1085. pdwBufferSize contains actual buffer size allocated for pBuffer
  1086. Return:
  1087. HRESULT
  1088. Side Affect:
  1089. Allocate memory for return result use new. Caller needs to free pBuffer
  1090. use delete[].
  1091. ===================================================================*/
  1092. HRESULT WamRegMetabaseConfig::MDGetPropPaths
  1093. (
  1094. IN LPCWSTR szMetabasePath,
  1095. IN DWORD dwMDIdentifier,
  1096. OUT WCHAR** pBuffer,
  1097. OUT DWORD* pdwBufferSize
  1098. )
  1099. {
  1100. HRESULT hr = NOERROR;
  1101. METADATA_HANDLE hMetabase = NULL; // Metabase Handle
  1102. WCHAR wchTemp; // One char buffer, no real usage.
  1103. WCHAR *pTemp = &wchTemp; // Start with some buffer, otherwise,
  1104. // will get RPC_X_NULL_REF_POINTER
  1105. DWORD dwMDBufferSize = 0;
  1106. DWORD dwMDRequiredBufferSize = 0;
  1107. if (NULL != szMetabasePath)
  1108. {
  1109. // Open Key
  1110. hr = m_pMetabase->OpenKey(METADATA_MASTER_ROOT_HANDLE, (LPWSTR)szMetabasePath,
  1111. METADATA_PERMISSION_READ, m_dwMDDefaultTimeOut, &hMetabase);
  1112. }
  1113. else
  1114. {
  1115. hMetabase = METADATA_MASTER_ROOT_HANDLE;
  1116. }
  1117. if (SUCCEEDED(hr))
  1118. {
  1119. hr = m_pMetabase->GetDataPaths(hMetabase,
  1120. NULL,
  1121. dwMDIdentifier,
  1122. ALL_METADATA,
  1123. dwMDBufferSize,
  1124. pTemp,
  1125. &dwMDRequiredBufferSize);
  1126. if (HRESULTTOWIN32(hr) == ERROR_INSUFFICIENT_BUFFER)
  1127. {
  1128. if (dwMDRequiredBufferSize > 0)
  1129. {
  1130. pTemp = new WCHAR[dwMDRequiredBufferSize];
  1131. if (pTemp == NULL)
  1132. {
  1133. hr = E_OUTOFMEMORY;
  1134. DBGPRINTF((DBG_CONTEXT, "Out of memory. \n"));
  1135. }
  1136. else
  1137. {
  1138. dwMDBufferSize = dwMDRequiredBufferSize;
  1139. hr = m_pMetabase->GetDataPaths(hMetabase,
  1140. NULL,
  1141. dwMDIdentifier,
  1142. ALL_METADATA,
  1143. dwMDBufferSize,
  1144. (LPWSTR)pTemp,
  1145. &dwMDRequiredBufferSize);
  1146. if (FAILED(hr))
  1147. {
  1148. DBGPRINTF((DBG_CONTEXT, "GetDataPaths failed with identitifier %d, path %S, hr = %08x\n",
  1149. dwMDIdentifier,
  1150. szMetabasePath,
  1151. hr));
  1152. }
  1153. else
  1154. {
  1155. *pBuffer = pTemp;
  1156. *pdwBufferSize = dwMDBufferSize;
  1157. }
  1158. }
  1159. }
  1160. }
  1161. else
  1162. {
  1163. DBGPRINTF((DBG_CONTEXT, "GetDataPaths failed with identitifier %d, path %S, hr = %08x\n",
  1164. dwMDIdentifier,
  1165. szMetabasePath,
  1166. hr));
  1167. }
  1168. if (hMetabase)
  1169. {
  1170. m_pMetabase->CloseKey(hMetabase);
  1171. }
  1172. }
  1173. else
  1174. {
  1175. DBGPRINTF((DBG_CONTEXT, "Failed to open metabase path %S, hr = %08x\n",
  1176. szMetabasePath,
  1177. hr));
  1178. }
  1179. return hr;
  1180. }
  1181. /*===================================================================
  1182. HasAdminAccess
  1183. Determine if the user has appropriate access to the metabase. We'll
  1184. use the same, somewhat hacky, method of determining this that the UI
  1185. uses. Basically we set a dummy property in the MB that only an admin
  1186. has access to. MB will use the call context to validate this.
  1187. Parameter:
  1188. Return:
  1189. BOOL - True if user has admin access to the MB
  1190. Side Affect:
  1191. ===================================================================*/
  1192. BOOL WamRegMetabaseConfig::HasAdminAccess
  1193. (
  1194. VOID
  1195. )
  1196. {
  1197. HRESULT hr = NOERROR;
  1198. METADATA_HANDLE hMetabase = NULL;
  1199. DBG_ASSERT(m_pMetabase);
  1200. hr = m_pMetabase->OpenKey( METADATA_MASTER_ROOT_HANDLE,
  1201. WamRegGlobal::g_szMDW3SVCRoot,
  1202. METADATA_PERMISSION_WRITE,
  1203. m_dwMDDefaultTimeOut,
  1204. &hMetabase );
  1205. if( SUCCEEDED(hr) )
  1206. {
  1207. DWORD dwDummyValue = 0x1234;
  1208. METADATA_RECORD mdr;
  1209. MD_SET_DATA_RECORD( &mdr,
  1210. MD_ISM_ACCESS_CHECK,
  1211. METADATA_NO_ATTRIBUTES,
  1212. IIS_MD_UT_FILE,
  1213. DWORD_METADATA,
  1214. sizeof(DWORD),
  1215. &dwDummyValue );
  1216. hr = m_pMetabase->SetData( hMetabase, L"", &mdr );
  1217. DBG_REQUIRE( SUCCEEDED(m_pMetabase->CloseKey( hMetabase )) );
  1218. }
  1219. return SUCCEEDED(hr);
  1220. }