Source code of Windows XP (NT5)
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.

1600 lines
41 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 = 5*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. Write the default IIS package info to metabase under key "/LM/W3SVC".
  209. Including
  210. IISPackageName
  211. IISPackageID
  212. WAMCLSID
  213. Parameter:
  214. szIISPackageName: [in] The Default IIS Package Name.
  215. szIISPackageID: [in] The IIS Package ID.
  216. szDefaultWAMCLSID: [in] The Default WAM CLSID.
  217. Return: HRESULT
  218. Side affect: Release pMetabase.
  219. ===================================================================*/
  220. HRESULT WamRegMetabaseConfig::MDUpdateIISDefault
  221. (
  222. IN LPCWSTR szIISPackageName,
  223. IN LPCWSTR szIISPackageID,
  224. IN LPCWSTR szDefaultWAMCLSID
  225. )
  226. {
  227. HRESULT hr = NOERROR;
  228. MDPropItem rgProp[IWMDP_MAX];
  229. DBG_ASSERT(szIISPackageName);
  230. DBG_ASSERT(szIISPackageID);
  231. DBG_ASSERT(szDefaultWAMCLSID);
  232. DBG_ASSERT(m_pMetabase != NULL);
  233. InitPropItemData(&rgProp[0]);
  234. // Update Package Name
  235. MDSetPropItem(&rgProp[0], IWMDP_PACKAGE_NAME, szIISPackageName);
  236. // Update Package ID
  237. MDSetPropItem(&rgProp[0], IWMDP_PACKAGEID, szIISPackageID);
  238. // Update DefaultWAMCLSID
  239. MDSetPropItem(&rgProp[0], IWMDP_WAMCLSID, szDefaultWAMCLSID);
  240. // Update APPRoot
  241. MDSetPropItem(&rgProp[0], IWMDP_ROOT, WamRegGlobal::g_szMDW3SVCRoot);
  242. //Update AppIsolated
  243. MDSetPropItem(&rgProp[0], IWMDP_ISOLATED, (DWORD)0);
  244. MDSetPropItem(&rgProp[0], IWMDP_LAST_OUTPROC_PID, L"");
  245. MDSetPropItem(&rgProp[0], IWMDP_FRIENDLY_NAME, L"");
  246. //
  247. // The default WAM Application is not inherited.
  248. // Set Metadata attributes to METADATA_NO_ATTRIBUTES
  249. // The allows us to have a way to turn the approot off, since this is above the
  250. // level of the server, every root dir of every server is part of application,
  251. // and there is no way to turn this off. Set the default application not inheritable,
  252. // we have a way to turn off the approot. People should have to mark an application in
  253. // order to run ASP & ISAPI.
  254. // UpdateMD at L"/LM/W3SVC/"
  255. //
  256. hr = UpdateMD(rgProp, METADATA_NO_ATTRIBUTES, WamRegGlobal::g_szMDAppPathPrefix, TRUE);
  257. // Removed AbortUpdateMD code. Why would we want to ensure that things
  258. // won't work now?
  259. return hr;
  260. }
  261. /*===================================================================
  262. AbortUpdateMD
  263. Abort the last update to the metabase, based on the info embeded in prgProp.
  264. Parameter:
  265. pMetabase a metabase pointer
  266. prgProp contains the info of updating a WAM properties in metabase.
  267. refer to the structure definition for more info.
  268. Return: HRESULT
  269. Side affect: Release pMetabase.
  270. ===================================================================*/
  271. HRESULT WamRegMetabaseConfig::AbortUpdateMD
  272. (
  273. IN MDPropItem* prgProp,
  274. IN LPCWSTR wszMetabasePath
  275. )
  276. {
  277. HRESULT hr = NOERROR;
  278. INT iItem = 0;
  279. METADATA_HANDLE hMetabase = NULL;
  280. DBG_ASSERT(m_pMetabase);
  281. DBG_ASSERT(prgProp);
  282. DBGPRINTF((DBG_CONTEXT, "WAMREG Abort Update metabase.\n"));
  283. //
  284. // Open Key
  285. //
  286. hr = m_pMetabase->OpenKey(METADATA_MASTER_ROOT_HANDLE, wszMetabasePath,
  287. METADATA_PERMISSION_WRITE, m_dwMDDefaultTimeOut, &hMetabase);
  288. if (SUCCEEDED(hr))
  289. {
  290. METADATA_RECORD recMetaData;
  291. //
  292. // Update WAM Application Metabase Properties.
  293. //
  294. for (iItem = 0; iItem < IWMDP_MAX; iItem ++)
  295. {
  296. if (prgProp[iItem].dwAction == EMD_SET)
  297. {
  298. if (prgProp[iItem].hrStatus == NOERROR)
  299. {
  300. hr = m_pMetabase->DeleteData(hMetabase, NULL, prgProp[iItem].dwMDIdentifier,
  301. prgProp[iItem].dwType);
  302. if (FAILED(hr) && hr != MD_ERROR_DATA_NOT_FOUND)
  303. {
  304. DBGPRINTF((DBG_CONTEXT, "Metabase Delete failed. Path = %S, id = %08x, error = %08x\n",
  305. wszMetabasePath,
  306. prgProp[iItem].dwMDIdentifier,
  307. hr));
  308. }
  309. }
  310. }
  311. }
  312. m_pMetabase->CloseKey(hMetabase);
  313. if (SUCCEEDED(hr))
  314. {
  315. hr = m_pMetabase->SaveData();
  316. if (hr == HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION))
  317. {
  318. hr = NOERROR;
  319. }
  320. }
  321. }
  322. else
  323. {
  324. DBGPRINTF((DBG_CONTEXT, "Failed to open metabase path %S, error = %08x\n",
  325. wszMetabasePath,
  326. hr));
  327. }
  328. return hr;
  329. }
  330. HRESULT WamRegMetabaseConfig::MDSetStringProperty
  331. (
  332. IN IMSAdminBase * pMetabaseIn,
  333. IN LPCWSTR szMetabasePath,
  334. IN DWORD dwMetabaseProperty,
  335. IN LPCWSTR szMetabaseValue,
  336. IN DWORD dwMDUserType /* = IIS_MD_UT_WAM */
  337. )
  338. /*===================================================================
  339. MDSetProperty
  340. Set a value of a property at the given path.
  341. Parameters:
  342. pMetabaseIn : [in] optional metabase interface
  343. szMetabasePath : [in] metabase key
  344. dwMetabaseProperty : [in] Property to set
  345. szMetabaseValue : [in] Value to set on property
  346. dwMDUserType : [in, optional] UserType to set on property
  347. Return: BOOL
  348. ===================================================================*/
  349. {
  350. HRESULT hr = S_OK;
  351. IMSAdminBase* pMetabase = NULL;
  352. METADATA_HANDLE hMetabase = NULL;
  353. METADATA_RECORD mdrData;
  354. ZeroMemory(&mdrData, sizeof(mdrData));
  355. DBG_ASSERT(szMetabasePath);
  356. if (pMetabaseIn)
  357. {
  358. pMetabase = pMetabaseIn;
  359. }
  360. else
  361. {
  362. pMetabase = m_pMetabase;
  363. }
  364. DBG_ASSERT(pMetabase);
  365. hr = pMetabase->OpenKey(METADATA_MASTER_ROOT_HANDLE,
  366. szMetabasePath,
  367. METADATA_PERMISSION_WRITE,
  368. m_dwMDDefaultTimeOut,
  369. &hMetabase);
  370. if (FAILED(hr))
  371. {
  372. goto done;
  373. }
  374. MD_SET_DATA_RECORD(&mdrData,
  375. dwMetabaseProperty,
  376. METADATA_NO_ATTRIBUTES,
  377. dwMDUserType,
  378. STRING_METADATA,
  379. (wcslen(szMetabaseValue)+1)*sizeof(WCHAR),
  380. szMetabaseValue);
  381. hr = pMetabase->SetData(hMetabase,
  382. L"/",
  383. &mdrData);
  384. if (FAILED(hr))
  385. {
  386. goto done;
  387. }
  388. hr = S_OK;
  389. done:
  390. if (pMetabase && hMetabase)
  391. {
  392. pMetabase->CloseKey(hMetabase);
  393. }
  394. return hr;
  395. }
  396. HRESULT WamRegMetabaseConfig::MDSetKeyType
  397. (
  398. IN IMSAdminBase * pMetabaseIn,
  399. IN LPCWSTR szMetabasePath,
  400. IN LPCWSTR szKeyType
  401. )
  402. {
  403. HRESULT hr = S_OK;
  404. IMSAdminBase* pMetabase = NULL;
  405. METADATA_HANDLE hMetabase = NULL;
  406. METADATA_RECORD mdrData;
  407. ZeroMemory(&mdrData, sizeof(mdrData));
  408. DBG_ASSERT(szMetabasePath);
  409. if (pMetabaseIn)
  410. {
  411. pMetabase = pMetabaseIn;
  412. }
  413. else
  414. {
  415. pMetabase = m_pMetabase;
  416. }
  417. DBG_ASSERT(pMetabase);
  418. hr = pMetabase->OpenKey(METADATA_MASTER_ROOT_HANDLE,
  419. szMetabasePath,
  420. METADATA_PERMISSION_WRITE,
  421. m_dwMDDefaultTimeOut,
  422. &hMetabase);
  423. if (FAILED(hr))
  424. {
  425. goto done;
  426. }
  427. MD_SET_DATA_RECORD(&mdrData,
  428. MD_KEY_TYPE,
  429. METADATA_NO_ATTRIBUTES,
  430. IIS_MD_UT_SERVER,
  431. STRING_METADATA,
  432. (wcslen(szKeyType)+1)*sizeof(WCHAR),
  433. szKeyType);
  434. hr = pMetabase->SetData(hMetabase,
  435. L"/",
  436. &mdrData);
  437. if (FAILED(hr))
  438. {
  439. goto done;
  440. }
  441. hr = S_OK;
  442. done:
  443. if (pMetabase && hMetabase)
  444. {
  445. pMetabase->CloseKey(hMetabase);
  446. }
  447. return hr;
  448. }
  449. HRESULT WamRegMetabaseConfig::MDDeleteKey
  450. (
  451. IN IMSAdminBase * pMetabaseIn,
  452. IN LPCWSTR szMetabasePath,
  453. IN LPCWSTR szKey
  454. )
  455. {
  456. HRESULT hr = S_OK;
  457. IMSAdminBase* pMetabase = NULL;
  458. METADATA_HANDLE hMetabase = NULL;
  459. DBG_ASSERT(szMetabasePath);
  460. DBG_ASSERT(szKey);
  461. if (pMetabaseIn)
  462. {
  463. pMetabase = pMetabaseIn;
  464. }
  465. else
  466. {
  467. pMetabase = m_pMetabase;
  468. }
  469. DBG_ASSERT(pMetabase);
  470. hr = pMetabase->OpenKey(METADATA_MASTER_ROOT_HANDLE,
  471. szMetabasePath,
  472. METADATA_PERMISSION_WRITE,
  473. m_dwMDDefaultTimeOut,
  474. &hMetabase);
  475. if (FAILED(hr))
  476. {
  477. goto done;
  478. }
  479. hr = pMetabase->DeleteKey(hMetabase,
  480. szKey);
  481. if (FAILED(hr))
  482. {
  483. goto done;
  484. }
  485. hr = S_OK;
  486. done:
  487. if (pMetabase && hMetabase)
  488. {
  489. pMetabase->CloseKey(hMetabase);
  490. }
  491. return hr;
  492. }
  493. BOOL WamRegMetabaseConfig::MDDoesPathExist
  494. (
  495. IN IMSAdminBase * pMetabaseIn,
  496. IN LPCWSTR szMetabasePath
  497. )
  498. /*===================================================================
  499. MDDoesPathExist
  500. Determine if a given path exists in the metabase
  501. Parameters:
  502. pMetabaseIn : [in] optional metabase interface
  503. szMetabasePath : [in] metabase key
  504. Return: BOOL
  505. ===================================================================*/
  506. {
  507. BOOL fRet = FALSE;
  508. HRESULT hr = S_OK;
  509. IMSAdminBase* pMetabase = NULL;
  510. METADATA_HANDLE hMetabase = NULL;
  511. DBG_ASSERT(szMetabasePath);
  512. if (pMetabaseIn)
  513. {
  514. pMetabase = pMetabaseIn;
  515. }
  516. else
  517. {
  518. pMetabase = m_pMetabase;
  519. }
  520. DBG_ASSERT(pMetabase);
  521. hr = pMetabase->OpenKey(METADATA_MASTER_ROOT_HANDLE,
  522. szMetabasePath,
  523. METADATA_PERMISSION_READ,
  524. m_dwMDDefaultTimeOut,
  525. &hMetabase);
  526. if (SUCCEEDED(hr))
  527. {
  528. fRet = TRUE;
  529. pMetabase->CloseKey(hMetabase);
  530. }
  531. else
  532. {
  533. fRet = FALSE;
  534. }
  535. return fRet;
  536. }
  537. /*===================================================================
  538. MDCreatePath
  539. Create a metabase path.(szMetabasePath)
  540. Parameter:
  541. szMetabasePath : [in] metabase key
  542. Return: HRESULT
  543. Note: fill in the pdwAppMode, memory buffer provided by the caller.
  544. ===================================================================*/
  545. HRESULT WamRegMetabaseConfig::MDCreatePath
  546. (
  547. IN IMSAdminBase *pMetabaseIn,
  548. IN LPCWSTR szMetabasePath
  549. )
  550. {
  551. HRESULT hr;
  552. IMSAdminBase *pMetabase = NULL;
  553. WCHAR *pwszApplicationPath = NULL;
  554. METADATA_HANDLE hMetabase = NULL;
  555. DBG_ASSERT(szMetabasePath);
  556. if (pMetabaseIn)
  557. {
  558. pMetabase = pMetabaseIn;
  559. }
  560. else
  561. {
  562. pMetabase = m_pMetabase;
  563. }
  564. if (_wcsnicmp(szMetabasePath, L"\\LM\\W3SVC\\", 10) == 0 ||
  565. _wcsnicmp(szMetabasePath, WamRegGlobal::g_szMDAppPathPrefix, WamRegGlobal::g_cchMDAppPathPrefix) == 0)
  566. {
  567. pwszApplicationPath = (WCHAR *)(szMetabasePath + 10);
  568. }
  569. else
  570. {
  571. hr = HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
  572. return hr;
  573. }
  574. // Open Key
  575. hr = pMetabase->OpenKey(METADATA_MASTER_ROOT_HANDLE, (LPCWSTR)WamRegGlobal::g_szMDAppPathPrefix,
  576. METADATA_PERMISSION_WRITE, m_dwMDDefaultTimeOut, &hMetabase);
  577. if (FAILED(hr))
  578. {
  579. DBGPRINTF((DBG_CONTEXT, "Failed to Open metabase key, path is /LM/W3SVC, hr = %08x\n",
  580. hr));
  581. }
  582. else
  583. {
  584. hr = pMetabase->AddKey(hMetabase, (LPCWSTR)pwszApplicationPath);
  585. if (FAILED(hr))
  586. {
  587. DBGPRINTF((DBG_CONTEXT, "Failed to AddKey to metabase, path is %S, hr = %08x\n",
  588. szMetabasePath,
  589. hr));
  590. }
  591. pMetabase->CloseKey(hMetabase);
  592. }
  593. return hr;
  594. }
  595. /*===================================================================
  596. MDGetDWORD
  597. Get a DWORD type property from Metabase Key(szMetabasePath)
  598. Parameter:
  599. szMetabasePath : [in] metabase key
  600. dwMDIdentifier : [in] indentifier
  601. Return: HRESULT
  602. ===================================================================*/
  603. HRESULT WamRegMetabaseConfig::MDGetDWORD
  604. (
  605. IN LPCWSTR szMetabasePath,
  606. IN DWORD dwMDIdentifier,
  607. OUT DWORD *pdwData
  608. )
  609. {
  610. HRESULT hr;
  611. METADATA_HANDLE hMetabase = NULL;
  612. METADATA_RECORD recMetaData;
  613. DWORD dwRequiredLen;
  614. IMSAdminBase *pMetabase = NULL;
  615. DBG_ASSERT(pdwData);
  616. DBG_ASSERT(szMetabasePath);
  617. pMetabase = m_pMetabase;
  618. // Open Key
  619. hr = pMetabase->OpenKey(METADATA_MASTER_ROOT_HANDLE, (LPCWSTR)szMetabasePath,
  620. METADATA_PERMISSION_READ, m_dwMDDefaultTimeOut, &hMetabase);
  621. if (SUCCEEDED(hr))
  622. {
  623. MD_SET_DATA_RECORD( &recMetaData, dwMDIdentifier, METADATA_NO_ATTRIBUTES,
  624. IIS_MD_UT_WAM, DWORD_METADATA, sizeof(DWORD), (unsigned char *)pdwData);
  625. hr = pMetabase->GetData(hMetabase, NULL, &recMetaData, &dwRequiredLen);
  626. if (FAILED(hr))
  627. {
  628. DBGPRINTF((DBG_CONTEXT, "Get MD_APP_ISOLATED failed on MD path %S, id %d, error = %08x\n",
  629. szMetabasePath,
  630. dwMDIdentifier,
  631. hr));
  632. }
  633. pMetabase->CloseKey(hMetabase);
  634. }
  635. return hr;
  636. }
  637. /*===================================================================
  638. MDSetAppState
  639. Set an application state. (i.e. If APPSTATE_PAUSE is set, then, the runtime
  640. W3SVC can not launch the application).
  641. Parameter:
  642. szMetabasePath : [in] metabase key
  643. dwState : App state to be set.
  644. Return: HRESULT
  645. ===================================================================*/
  646. HRESULT WamRegMetabaseConfig::MDSetAppState
  647. (
  648. IN LPCWSTR szMetabasePath,
  649. IN DWORD dwState
  650. )
  651. {
  652. METADATA_RECORD recMetaData;
  653. HRESULT hr;
  654. METADATA_HANDLE hMetabase;
  655. DBG_ASSERT(m_pMetabase);
  656. // Open Key
  657. hr = m_pMetabase->OpenKey(METADATA_MASTER_ROOT_HANDLE, (LPWSTR)szMetabasePath,
  658. METADATA_PERMISSION_WRITE, m_dwMDDefaultTimeOut, &hMetabase);
  659. if (SUCCEEDED(hr))
  660. {
  661. MD_SET_DATA_RECORD( &recMetaData, MD_APP_STATE, METADATA_INHERIT, IIS_MD_UT_WAM,
  662. DWORD_METADATA, sizeof(DWORD), (unsigned char *)&dwState);
  663. hr = m_pMetabase->SetData(hMetabase, NULL, &recMetaData);
  664. m_pMetabase->CloseKey(hMetabase);
  665. }
  666. return hr;
  667. }
  668. HRESULT WamRegMetabaseConfig::MDGetWAMCLSID
  669. (
  670. IN LPCWSTR szMetabasePath,
  671. IN OUT LPWSTR szWAMCLSID
  672. )
  673. {
  674. HRESULT hr;
  675. METADATA_HANDLE hMetabase = NULL;
  676. METADATA_RECORD recMetaData;
  677. DWORD dwRequiredLen;
  678. DBG_ASSERT(szWAMCLSID);
  679. DBG_ASSERT(szMetabasePath);
  680. szWAMCLSID[0] = NULL;
  681. // Open Key
  682. hr = m_pMetabase->OpenKey(METADATA_MASTER_ROOT_HANDLE, (LPWSTR)szMetabasePath,
  683. METADATA_PERMISSION_READ, m_dwMDDefaultTimeOut, &hMetabase);
  684. if (SUCCEEDED(hr))
  685. {
  686. MD_SET_DATA_RECORD( &recMetaData, MD_APP_WAM_CLSID, METADATA_NO_ATTRIBUTES, IIS_MD_UT_WAM,
  687. STRING_METADATA, uSizeCLSID*sizeof(WCHAR), (unsigned char *)szWAMCLSID);
  688. hr = m_pMetabase->GetData(hMetabase, NULL, &recMetaData, &dwRequiredLen);
  689. if (HRESULTTOWIN32(hr) == ERROR_INSUFFICIENT_BUFFER)
  690. {
  691. DBG_ASSERT(FALSE);
  692. }
  693. m_pMetabase->CloseKey(hMetabase);
  694. }
  695. return hr;
  696. }
  697. /*===================================================================
  698. MDGetIdentity
  699. Get pakcage Identity from Metabase Key(szMetabasePath) (WamUserName &
  700. WamPassword)
  701. Parameter:
  702. szIdentity: a string buffer for WamUserName.
  703. cbIdneity: size of the string buffer for szIdentity.
  704. szPwd: a string buffer for WamPassword.
  705. cbPwd: size of the string buffer for szPwd.
  706. Return: HRESULT
  707. ===================================================================*/
  708. HRESULT WamRegMetabaseConfig::MDGetIdentity
  709. (
  710. IN LPWSTR szIdentity,
  711. IN DWORD cbIdentity,
  712. IN LPWSTR szPwd,
  713. IN DWORD cbPwd
  714. )
  715. {
  716. HRESULT hr;
  717. METADATA_HANDLE hMetabase = NULL;
  718. METADATA_RECORD recMetaData;
  719. DWORD dwRequiredLen;
  720. DBG_ASSERT(szIdentity);
  721. szIdentity[0] = NULL;
  722. // Open Key
  723. hr = m_pMetabase->OpenKey(METADATA_MASTER_ROOT_HANDLE, (LPWSTR)WamRegGlobal::g_szMDAppPathPrefix,
  724. METADATA_PERMISSION_READ, m_dwMDDefaultTimeOut, &hMetabase);
  725. if (SUCCEEDED(hr))
  726. {
  727. // Get WAM user name
  728. MD_SET_DATA_RECORD( &recMetaData, MD_WAM_USER_NAME, METADATA_NO_ATTRIBUTES, IIS_MD_UT_WAM,
  729. STRING_METADATA, cbIdentity, (unsigned char *)szIdentity);
  730. hr = m_pMetabase->GetData(hMetabase, NULL, &recMetaData, &dwRequiredLen);
  731. if (HRESULTTOWIN32(hr) == ERROR_INSUFFICIENT_BUFFER)
  732. {
  733. DBGPRINTF((DBG_CONTEXT, "Insufficient buffer for WAM user name. Required size is %d\n",
  734. dwRequiredLen));
  735. DBG_ASSERT(FALSE);
  736. }
  737. // Get WAM user password
  738. MD_SET_DATA_RECORD( &recMetaData, MD_WAM_PWD, METADATA_NO_ATTRIBUTES, IIS_MD_UT_WAM,
  739. STRING_METADATA, cbPwd, (unsigned char *)szPwd);
  740. hr = m_pMetabase->GetData(hMetabase, NULL, &recMetaData, &dwRequiredLen);
  741. if (HRESULTTOWIN32(hr) == ERROR_INSUFFICIENT_BUFFER)
  742. {
  743. DBGPRINTF((DBG_CONTEXT, "Insufficient buffer for WAM user password. Required size is %d\n",
  744. dwRequiredLen));
  745. DBG_ASSERT(FALSE);
  746. }
  747. m_pMetabase->CloseKey(hMetabase);
  748. }
  749. return hr;
  750. }
  751. HRESULT
  752. WamRegMetabaseConfig::MDGetAppName
  753. (
  754. IN LPCWSTR szMetaPath,
  755. OUT LPWSTR * ppszAppName
  756. )
  757. /*++
  758. Function:
  759. Retrieve the MD_APP_PACKAGE_NAME from the metabase.
  760. Parameters:
  761. ppszAppName - value of MD_APP_PACKAGE_NAME allocated
  762. with new[] free with delete[]
  763. Return:
  764. {MD_APP_PACKAGE_NAME, STRING_METADATA, 0, EMD_NONE, E_FAIL},
  765. --*/
  766. {
  767. return MDGetStringAttribute(szMetaPath, MD_APP_PACKAGE_NAME, ppszAppName);
  768. }
  769. HRESULT
  770. WamRegMetabaseConfig::MDGetStringAttribute
  771. (
  772. IN LPCWSTR szMetaPath,
  773. DWORD dwMDIdentifier,
  774. OUT LPWSTR * ppszBuffer
  775. )
  776. {
  777. DBG_ASSERT( ppszBuffer );
  778. DBG_ASSERT( m_pMetabase );
  779. HRESULT hr = NOERROR;
  780. WCHAR * pwcMetaData = NULL;
  781. DWORD cbData = 0;
  782. METADATA_HANDLE hKey = NULL;
  783. METADATA_RECORD mdr;
  784. *ppszBuffer = NULL;
  785. hr = m_pMetabase->OpenKey(METADATA_MASTER_ROOT_HANDLE,
  786. szMetaPath,
  787. METADATA_PERMISSION_READ,
  788. m_dwMDDefaultTimeOut,
  789. &hKey);
  790. if( SUCCEEDED(hr) )
  791. {
  792. MD_SET_DATA_RECORD( &mdr,
  793. dwMDIdentifier,
  794. METADATA_INHERIT,
  795. IIS_MD_UT_WAM,
  796. STRING_METADATA,
  797. cbData,
  798. (LPBYTE)pwcMetaData
  799. );
  800. hr = m_pMetabase->GetData( hKey, NULL, &mdr, &cbData );
  801. if( HRESULTTOWIN32(hr) == ERROR_INSUFFICIENT_BUFFER )
  802. {
  803. pwcMetaData = new WCHAR[ cbData / sizeof(WCHAR) ];
  804. if( pwcMetaData != NULL )
  805. {
  806. mdr.pbMDData = (LPBYTE)pwcMetaData;
  807. mdr.dwMDDataLen = cbData;
  808. hr = m_pMetabase->GetData( hKey, NULL, &mdr, &cbData );
  809. }
  810. else
  811. {
  812. hr = E_OUTOFMEMORY;
  813. }
  814. }
  815. m_pMetabase->CloseKey( hKey );
  816. }
  817. //
  818. // Return AppName
  819. //
  820. if( SUCCEEDED(hr) )
  821. {
  822. DBG_ASSERT( pwcMetaData != NULL );
  823. *ppszBuffer = pwcMetaData;
  824. }
  825. else
  826. {
  827. DBG_ASSERT( *ppszBuffer == NULL );
  828. delete [] pwcMetaData;
  829. }
  830. return hr;
  831. }
  832. #ifdef _IIS_6_0
  833. HRESULT
  834. WamRegMetabaseConfig::MDGetAllSiteRoots
  835. (
  836. OUT LPWSTR * ppszBuffer
  837. )
  838. {
  839. DBG_ASSERT( m_pMetabase );
  840. DBG_ASSERT(ppszBuffer);
  841. *ppszBuffer = NULL;
  842. HRESULT hr = S_OK;
  843. METADATA_HANDLE hKey = NULL;
  844. DWORD dwEnumKeyIndex = 0;
  845. WCHAR szMDName[METADATA_MAX_NAME_LEN] = {0};
  846. MULTISZ mszSiteRoots;
  847. // Loop through all keys below /LM/W3SVC
  848. hr = m_pMetabase->EnumKeys(METADATA_MASTER_ROOT_HANDLE,
  849. L"/LM/W3SVC/",
  850. szMDName,
  851. dwEnumKeyIndex
  852. );
  853. while(SUCCEEDED(hr))
  854. {
  855. int i = _wtoi(szMDName);
  856. // if this is a site
  857. if(0 != i)
  858. {
  859. // have a valid site number
  860. WCHAR pTempBuf[METADATA_MAX_NAME_LEN] = {0};
  861. wcscpy(pTempBuf, L"/LM/W3SVC/");
  862. wcscat(pTempBuf, szMDName);
  863. wcscat(pTempBuf, L"/ROOT/");
  864. if (FALSE == mszSiteRoots.Append(pTempBuf))
  865. {
  866. hr = E_OUTOFMEMORY;
  867. goto done;
  868. }
  869. }
  870. dwEnumKeyIndex++;
  871. hr = m_pMetabase->EnumKeys(METADATA_MASTER_ROOT_HANDLE,
  872. L"/LM/W3SVC/",
  873. szMDName,
  874. dwEnumKeyIndex
  875. );
  876. }
  877. // data is in MULTISZ move to out buffer
  878. {
  879. UINT cchMulti = 0;
  880. DWORD dwBufferSize = 0;
  881. cchMulti = mszSiteRoots.QueryCCH();
  882. *ppszBuffer = new WCHAR[cchMulti];
  883. if (NULL == *ppszBuffer)
  884. {
  885. hr = E_OUTOFMEMORY;
  886. goto done;
  887. }
  888. dwBufferSize = cchMulti;
  889. mszSiteRoots.CopyToBuffer(*ppszBuffer, &dwBufferSize);
  890. }
  891. hr = S_OK;
  892. done:
  893. return hr;
  894. }
  895. #endif //_IIS_6_0
  896. /*===================================================================
  897. MDGetIdentity
  898. Get WAMCLSID, Wam PackageID, and fAppIsolated from a metabase path.
  899. Parameter:
  900. szMetabasepath : get info from this path.
  901. szWAMCLSID: buffer for WAMCLSID(fixed length buffer).
  902. szPackageID: buffer for Wam PackageID(fixed length buffer).
  903. fAppIsolated: if InProc(TRUE), do not retrieve szPackageID.
  904. Return: HRESULT
  905. ===================================================================*/
  906. HRESULT WamRegMetabaseConfig::MDGetIDs
  907. (
  908. IN LPCWSTR szMetabasePath,
  909. OUT LPWSTR szWAMCLSID,
  910. OUT LPWSTR szPackageID,
  911. IN DWORD dwAppMode
  912. )
  913. {
  914. HRESULT hr;
  915. METADATA_HANDLE hMetabase = NULL;
  916. METADATA_RECORD recMetaData;
  917. DWORD dwRequiredLen;
  918. DBG_ASSERT(m_pMetabase);
  919. DBG_ASSERT(szWAMCLSID);
  920. DBG_ASSERT(szPackageID);
  921. DBG_ASSERT(szMetabasePath);
  922. szPackageID[0] = NULL;
  923. szWAMCLSID[0] = NULL;
  924. // Open Key
  925. hr = m_pMetabase->OpenKey(METADATA_MASTER_ROOT_HANDLE, (LPWSTR)szMetabasePath,
  926. METADATA_PERMISSION_READ, m_dwMDDefaultTimeOut, &hMetabase);
  927. if (SUCCEEDED(hr))
  928. {
  929. MD_SET_DATA_RECORD( &recMetaData, MD_APP_WAM_CLSID, METADATA_NO_ATTRIBUTES, IIS_MD_UT_WAM,
  930. STRING_METADATA, uSizeCLSID*sizeof(WCHAR), (unsigned char *)szWAMCLSID);
  931. hr = m_pMetabase->GetData(hMetabase, NULL, &recMetaData, &dwRequiredLen);
  932. if (HRESULTTOWIN32(hr) == ERROR_INSUFFICIENT_BUFFER)
  933. {
  934. DBG_ASSERT(FALSE);
  935. }
  936. if (SUCCEEDED(hr))
  937. {
  938. if (dwAppMode == static_cast<DWORD>(eAppRunOutProcIsolated))
  939. {
  940. MD_SET_DATA_RECORD( &recMetaData, MD_APP_PACKAGE_ID, METADATA_NO_ATTRIBUTES, IIS_MD_UT_WAM,
  941. STRING_METADATA, uSizeCLSID*sizeof(WCHAR), (unsigned char *)szPackageID);
  942. hr = m_pMetabase->GetData(hMetabase, NULL, &recMetaData, &dwRequiredLen);
  943. if (HRESULTTOWIN32(hr) == ERROR_INSUFFICIENT_BUFFER)
  944. {
  945. DBG_ASSERT(FALSE);
  946. }
  947. }
  948. else if (dwAppMode == static_cast<DWORD>(eAppRunInProc))
  949. {
  950. wcsncpy(szPackageID, g_WamRegGlobal.g_szIISInProcPackageID, uSizeCLSID);
  951. }
  952. else
  953. {
  954. wcsncpy(szPackageID, g_WamRegGlobal.g_szIISOOPPoolPackageID, uSizeCLSID);
  955. }
  956. }
  957. m_pMetabase->CloseKey(hMetabase);
  958. }
  959. return hr;
  960. }
  961. /*===================================================================
  962. MDRemoveProperty
  963. Remove one MD property.
  964. Parameter:
  965. pwszMetabasePath
  966. dwIdentifier the MD indentifier to be removed.
  967. dwType the MD indietifier data type.
  968. Return: HRESULT
  969. ===================================================================*/
  970. HRESULT WamRegMetabaseConfig::MDRemoveProperty
  971. (
  972. IN LPCWSTR pwszMetabasePath,
  973. DWORD dwIdentifier,
  974. DWORD dwType
  975. )
  976. {
  977. METADATA_RECORD recMetaData;
  978. HRESULT hr;
  979. METADATA_HANDLE hMetabase;
  980. hr = m_pMetabase->OpenKey(METADATA_MASTER_ROOT_HANDLE, (LPWSTR)pwszMetabasePath,
  981. METADATA_PERMISSION_WRITE, m_dwMDDefaultTimeOut, &hMetabase);
  982. if (SUCCEEDED(hr))
  983. {
  984. hr = m_pMetabase->DeleteData(hMetabase, NULL, dwIdentifier, dwType);
  985. m_pMetabase->CloseKey(hMetabase);
  986. }
  987. return hr;
  988. }
  989. /*===================================================================
  990. MDGetLastOutProcPackageID
  991. Get LastOutProcPackageID from Metabase Key(szMetabasePath)
  992. Parameter:
  993. szMetabasePath : [in] metabase key
  994. szLastOutProcPackageID : [in] a pointer to LastOutProcPackageID buffer
  995. Return: HRESULT
  996. Note: fill in the LastOutProcPackageID, memory buffer provided by the caller.
  997. ===================================================================*/
  998. HRESULT WamRegMetabaseConfig::MDGetLastOutProcPackageID
  999. (
  1000. IN LPCWSTR szMetabasePath,
  1001. IN OUT LPWSTR szLastOutProcPackageID
  1002. )
  1003. {
  1004. HRESULT hr;
  1005. METADATA_HANDLE hMetabase = NULL;
  1006. METADATA_RECORD recMetaData;
  1007. DWORD dwRequiredLen;
  1008. DBG_ASSERT(szLastOutProcPackageID);
  1009. DBG_ASSERT(szMetabasePath);
  1010. szLastOutProcPackageID[0] = NULL;
  1011. // Open Key
  1012. hr = m_pMetabase->OpenKey(METADATA_MASTER_ROOT_HANDLE, (LPWSTR)szMetabasePath,
  1013. METADATA_PERMISSION_READ, m_dwMDDefaultTimeOut, &hMetabase);
  1014. if (SUCCEEDED(hr))
  1015. {
  1016. MD_SET_DATA_RECORD( &recMetaData, MD_APP_LAST_OUTPROC_PID, METADATA_NO_ATTRIBUTES, IIS_MD_UT_WAM,
  1017. STRING_METADATA, uSizeCLSID*sizeof(WCHAR), (unsigned char *)szLastOutProcPackageID);
  1018. hr = m_pMetabase->GetData(hMetabase, NULL, &recMetaData, &dwRequiredLen);
  1019. if (HRESULTTOWIN32(hr) == ERROR_INSUFFICIENT_BUFFER)
  1020. {
  1021. DBG_ASSERT(FALSE);
  1022. }
  1023. m_pMetabase->CloseKey(hMetabase);
  1024. }
  1025. return hr;
  1026. }
  1027. /*===================================================================
  1028. GetWebServerName
  1029. Look the WebServerName(ServerComment) property under the key (szMetabasePath).
  1030. Parameter:
  1031. None
  1032. Return: HRESULT
  1033. Note: fill in the szWebServerName, memory buffer provided by the caller.
  1034. ===================================================================*/
  1035. HRESULT WamRegMetabaseConfig::GetWebServerName
  1036. (
  1037. IN LPCWSTR wszMetabasePath,
  1038. IN OUT LPWSTR wszWebServerName,
  1039. IN UINT cBuffer
  1040. )
  1041. {
  1042. HRESULT hr;
  1043. METADATA_HANDLE hMetabase = NULL;
  1044. METADATA_RECORD recMetaData;
  1045. DWORD dwRequiredLen;
  1046. DBG_ASSERT(wszMetabasePath);
  1047. DBG_ASSERT(wszWebServerName);
  1048. // Open Key
  1049. hr = m_pMetabase->OpenKey( METADATA_MASTER_ROOT_HANDLE,
  1050. wszMetabasePath,
  1051. METADATA_PERMISSION_READ,
  1052. m_dwMDDefaultTimeOut,
  1053. &hMetabase
  1054. );
  1055. if (SUCCEEDED(hr))
  1056. {
  1057. MD_SET_DATA_RECORD( &recMetaData,
  1058. MD_SERVER_COMMENT,
  1059. METADATA_INHERIT,
  1060. IIS_MD_UT_SERVER,
  1061. STRING_METADATA,
  1062. cBuffer,
  1063. (unsigned char *)wszWebServerName
  1064. );
  1065. hr = m_pMetabase->GetData(hMetabase, L"", &recMetaData, &dwRequiredLen);
  1066. if (HRESULTTOWIN32(hr) == ERROR_INSUFFICIENT_BUFFER)
  1067. {
  1068. DBGPRINTF((DBG_CONTEXT, "Insuffcient buffer for WebServerName. Path = %S\n",
  1069. wszMetabasePath));
  1070. DBG_ASSERT(FALSE);
  1071. }
  1072. //
  1073. // If property MD_SERVER_COMMENT not found, null out the WebServerName.
  1074. //
  1075. if (hr == MD_ERROR_DATA_NOT_FOUND)
  1076. {
  1077. wszWebServerName[0] = L'\0';
  1078. hr = NOERROR;
  1079. }
  1080. if (FAILED(hr))
  1081. {
  1082. DBGPRINTF((DBG_CONTEXT, "Failed to read Metabase for WebServerName. Path = %S, error = %08x\n",
  1083. wszMetabasePath,
  1084. hr));
  1085. }
  1086. m_pMetabase->CloseKey(hMetabase);
  1087. }
  1088. else
  1089. {
  1090. DBGPRINTF((DBG_CONTEXT, "Failed to read Metabase for WebServerName. Path = %S, error = %08x\n",
  1091. wszMetabasePath,
  1092. hr));
  1093. }
  1094. return hr;
  1095. }
  1096. /*===================================================================
  1097. GetSignatureOnPath
  1098. Get an application signature(AppRoot & AppIsolated) on a metabase path.
  1099. Parameter:
  1100. pwszMetabasePath
  1101. pdwSignature
  1102. Return: HRESULT
  1103. Note: Signature is returned via pdwSignature.
  1104. ===================================================================*/
  1105. HRESULT WamRegMetabaseConfig::GetSignatureOnPath
  1106. (
  1107. IN LPCWSTR pwszMetabasePath,
  1108. OUT DWORD* pdwSignature
  1109. )
  1110. {
  1111. HRESULT hr = NOERROR;
  1112. WCHAR szWAMCLSID[uSizeCLSID];
  1113. WCHAR szPackageID[uSizeCLSID];
  1114. DWORD dwResult = 0;
  1115. DWORD cSize = 0;
  1116. DWORD dwAppMode = 0;
  1117. DBG_ASSERT(pwszMetabasePath);
  1118. hr = MDGetDWORD(pwszMetabasePath, MD_APP_ISOLATED, &dwAppMode);
  1119. if (SUCCEEDED(hr))
  1120. {
  1121. hr = MDGetIDs(pwszMetabasePath, szWAMCLSID, szPackageID, (BOOL)dwAppMode);
  1122. if (SUCCEEDED(hr))
  1123. {
  1124. cSize = wcslen(pwszMetabasePath);
  1125. dwResult = WamRegChkSum(pwszMetabasePath, cSize);
  1126. dwResult ^= WamRegChkSum(szWAMCLSID, uSizeCLSID);
  1127. if (dwAppMode == eAppRunOutProcIsolated)
  1128. {
  1129. dwResult ^= WamRegChkSum(szPackageID, uSizeCLSID);
  1130. }
  1131. }
  1132. }
  1133. if (SUCCEEDED(hr))
  1134. {
  1135. *pdwSignature = dwResult;
  1136. }
  1137. else
  1138. {
  1139. *pdwSignature = 0;
  1140. }
  1141. return NOERROR;
  1142. }
  1143. /*===================================================================
  1144. WamRegChkSum
  1145. Give a wchar string, calculate a chk sum.
  1146. Parameter:
  1147. pszKey wchar string
  1148. cchKey wcslen(of wchar ) string
  1149. Return: ChkSum.
  1150. ===================================================================*/
  1151. DWORD WamRegMetabaseConfig::WamRegChkSum
  1152. (
  1153. IN LPCWSTR pszKey,
  1154. IN DWORD cchKey
  1155. )
  1156. {
  1157. DWORD hash = 0, g;
  1158. while (*pszKey)
  1159. {
  1160. hash = (hash << 4) + *pszKey++;
  1161. if (g = hash & 0xf0000000)
  1162. {
  1163. hash ^= g >> 24;
  1164. }
  1165. hash &= ~g;
  1166. }
  1167. return hash;
  1168. }
  1169. /*===================================================================
  1170. MDGetPropPaths
  1171. Get an array of metabase paths that contains a specific property.
  1172. Parameter:
  1173. szMetabasePath
  1174. dwMDIdentifier
  1175. pBuffer a pointer to a buffer
  1176. pdwBufferSize contains actual buffer size allocated for pBuffer
  1177. Return:
  1178. HRESULT
  1179. Side Affect:
  1180. Allocate memory for return result use new. Caller needs to free pBuffer
  1181. use delete[].
  1182. ===================================================================*/
  1183. HRESULT WamRegMetabaseConfig::MDGetPropPaths
  1184. (
  1185. IN LPCWSTR szMetabasePath,
  1186. IN DWORD dwMDIdentifier,
  1187. OUT WCHAR** pBuffer,
  1188. OUT DWORD* pdwBufferSize
  1189. )
  1190. {
  1191. HRESULT hr = NOERROR;
  1192. METADATA_HANDLE hMetabase = NULL; // Metabase Handle
  1193. WCHAR wchTemp; // One char buffer, no real usage.
  1194. WCHAR *pTemp = &wchTemp; // Start with some buffer, otherwise,
  1195. // will get RPC_X_NULL_REF_POINTER
  1196. DWORD dwMDBufferSize = 0;
  1197. DWORD dwMDRequiredBufferSize = 0;
  1198. if (NULL != szMetabasePath)
  1199. {
  1200. // Open Key
  1201. hr = m_pMetabase->OpenKey(METADATA_MASTER_ROOT_HANDLE, (LPWSTR)szMetabasePath,
  1202. METADATA_PERMISSION_READ, m_dwMDDefaultTimeOut, &hMetabase);
  1203. }
  1204. else
  1205. {
  1206. hMetabase = METADATA_MASTER_ROOT_HANDLE;
  1207. }
  1208. if (SUCCEEDED(hr))
  1209. {
  1210. hr = m_pMetabase->GetDataPaths(hMetabase,
  1211. NULL,
  1212. dwMDIdentifier,
  1213. ALL_METADATA,
  1214. dwMDBufferSize,
  1215. pTemp,
  1216. &dwMDRequiredBufferSize);
  1217. if (HRESULTTOWIN32(hr) == ERROR_INSUFFICIENT_BUFFER)
  1218. {
  1219. if (dwMDRequiredBufferSize > 0)
  1220. {
  1221. pTemp = new WCHAR[dwMDRequiredBufferSize];
  1222. if (pTemp == NULL)
  1223. {
  1224. hr = E_OUTOFMEMORY;
  1225. DBGPRINTF((DBG_CONTEXT, "Out of memory. \n"));
  1226. }
  1227. else
  1228. {
  1229. dwMDBufferSize = dwMDRequiredBufferSize;
  1230. hr = m_pMetabase->GetDataPaths(hMetabase,
  1231. NULL,
  1232. dwMDIdentifier,
  1233. ALL_METADATA,
  1234. dwMDBufferSize,
  1235. (LPWSTR)pTemp,
  1236. &dwMDRequiredBufferSize);
  1237. if (FAILED(hr))
  1238. {
  1239. DBGPRINTF((DBG_CONTEXT, "GetDataPaths failed with identitifier %d, path %S, hr = %08x\n",
  1240. dwMDIdentifier,
  1241. szMetabasePath,
  1242. hr));
  1243. }
  1244. else
  1245. {
  1246. *pBuffer = pTemp;
  1247. *pdwBufferSize = dwMDBufferSize;
  1248. }
  1249. }
  1250. }
  1251. }
  1252. else
  1253. {
  1254. DBGPRINTF((DBG_CONTEXT, "GetDataPaths failed with identitifier %d, path %S, hr = %08x\n",
  1255. dwMDIdentifier,
  1256. szMetabasePath,
  1257. hr));
  1258. }
  1259. if (hMetabase)
  1260. {
  1261. m_pMetabase->CloseKey(hMetabase);
  1262. }
  1263. }
  1264. else
  1265. {
  1266. DBGPRINTF((DBG_CONTEXT, "Failed to open metabase path %S, hr = %08x\n",
  1267. szMetabasePath,
  1268. hr));
  1269. }
  1270. return hr;
  1271. }
  1272. /*===================================================================
  1273. HasAdminAccess
  1274. Determine if the user has appropriate access to the metabase. We'll
  1275. use the same, somewhat hacky, method of determining this that the UI
  1276. uses. Basically we set a dummy property in the MB that only an admin
  1277. has access to. MB will use the call context to validate this.
  1278. Parameter:
  1279. Return:
  1280. BOOL - True if user has admin access to the MB
  1281. Side Affect:
  1282. ===================================================================*/
  1283. BOOL WamRegMetabaseConfig::HasAdminAccess
  1284. (
  1285. VOID
  1286. )
  1287. {
  1288. HRESULT hr = NOERROR;
  1289. METADATA_HANDLE hMetabase = NULL;
  1290. DBG_ASSERT(m_pMetabase);
  1291. hr = m_pMetabase->OpenKey( METADATA_MASTER_ROOT_HANDLE,
  1292. WamRegGlobal::g_szMDW3SVCRoot,
  1293. METADATA_PERMISSION_WRITE,
  1294. m_dwMDDefaultTimeOut,
  1295. &hMetabase );
  1296. if( SUCCEEDED(hr) )
  1297. {
  1298. DWORD dwDummyValue = 0x1234;
  1299. METADATA_RECORD mdr;
  1300. MD_SET_DATA_RECORD( &mdr,
  1301. MD_ISM_ACCESS_CHECK,
  1302. METADATA_NO_ATTRIBUTES,
  1303. IIS_MD_UT_FILE,
  1304. DWORD_METADATA,
  1305. sizeof(DWORD),
  1306. &dwDummyValue );
  1307. hr = m_pMetabase->SetData( hMetabase, L"", &mdr );
  1308. DBG_REQUIRE( SUCCEEDED(m_pMetabase->CloseKey( hMetabase )) );
  1309. }
  1310. return SUCCEEDED(hr);
  1311. }